( Image saver and restorer for autobooting Rob Chapman Jul 11, 2000 ) ( When working with the onboard flash, you are limited to using each location ( only once. When there are no locations left to use, you must erase all ( and download the kernel again. So for development of programs that are ( to be rebootable with all the saved words, you must watch where you put ( the words in flash. This file give such support and also automatically ( puts all your words in flash as they are compiled. You download this file ( and then your software you want to save and then at the end you type in ( ' startupword INSTALL ( Example: : HI ." Hello world" QUIT ; ' HI INSTALL ( upon rebooting, you will get 'Hello world' greeting and then be in Forth ( command line mode with the words you saved. Or ( if you don't want any startup word, then you just type in SAVE and when ( you reset you will come up in MaxForth with all your words there. This ( also includes the fix for FL! in MaxForth V5.0L ( ==== Image and properties ==== ) HERE CONSTANT sys-end R0 CONSTANT sys-start sys-end sys-start - CONSTANT sys-size ( 0 Image components and offsets ) ( + 0 A44A - just run and return ( + 2 RESTORE - must point to saved image of restore ( + 4 main startup word stored by INSTALL ( + 6 copy of RAM locations in system ( + 6 + sys-size length of image ( + 8 + sys-size image of code HEX ( ==== Startup services ==== ) ( ==== Find empty space in Flash ROM ==== ) : FLAUTO ( -- a ) 0 F000 FDP @ 3FF + FC00 AND DO I @ FFFF = IF DROP I LEAVE THEN 400 +LOOP DUP 0= IF CR ." Flash is full." CR ELSE DUP U. THEN ; FLAUTO UNDO CONSTANT FL-START ( start of flash: where to save to sys-end CONSTANT RAM-START ( where to save from : -AUTOSTART 0 FL-START FLC! ; ( turn off autostart flag ) : FL+ FL-START + ; : FL! ( n \ a -- ) OVER >< OVER FLC! 1+ FLC! ; ( fix FL! bug for -ves ) : RESTORE ( can't call nonexistant words so [ ] LITERAL is used [ 6 FL+ ] LITERAL ( start of system image ) [ sys-start ] LITERAL ( start of system variables ) [ sys-size ] LITERAL CMOVE ( restore system RAM image [ sys-size 8 + FL+ ] LITERAL ( start of dict image ) [ RAM-START ] LITERAL ( start of dict spaceÊÊÊÊÊÊ [ sys-size 6 + FL+ ] LITERAL @Ê ?DUP IF CMOVE ( restore dictionary image to RAM ) ELSE 2DROP THEN [ 4 FL+ ] LITERAL @ EXECUTE ; ( run main program : SAVE A44A FL-START FL! ( fire once autostart flag for startup ) ['] RESTORE CFA 2 FL+ FL! ( restoration vector ) ['] TASK CFA 4 FL+ FL! ( null vector ) sys-start 6 FL+ sys-size FLMOVE ( save system variables ) RAM-START sys-size 8 + FL+ HERE RAM-START - ( src \ dst \ siz ) DUP sys-size 6 + FL+ FL!Ê ?DUP IF FLMOVE ( save length & dictionary ) ELSE 2DROP THEN ; : INSTALL ( a -- ) SAVE CFA 4 FL+ FL! ;