FlashForth: for PIC and Atmega Wiki
Brought to you by:
oh2aun
Utility word collection by Pete Zawasky
-util marker -util decimal ram \ Clear PAD and free RAM up to start of FLASH \ : clr_ram ( -- ) pad pfl pad - $00 fill ; clr_ram \ Define PAD space to establish start of free RAM 32 allot \ FORGET can only adjust the FLASH DP. \ Allotted EEPROM or RAM will not be reclaimed. \ : forget ( <name> -- ) bl word latest @ (f) 0= ?abort? c>n 2- dup @ 0= ?abort? dup flash dp ! @ latest ! ram ; : u.r- ( u +n -- ) \ display u unsigned in field of +n \ with leading zeros and no trailing space 0 swap <# 1- for # next #s #> type ; : .mem ( -- ) \ print current memory locations base @ hex cr ." flash " flash here #4 u.r cr ." eeprom " eeprom here #4 u.r cr ." ram " ram here #4 u.r space base ! ; : <= ( n1 n2 -- flag ) - 1- 0< ; \ leave true flag if n1 less than or equal to n2 : ?dup ( x -- 0 | x x ) dup if dup then ; : pick ( xu ... x0 u -- xu ... x0 xu) 2* 2+ sp@ swap - @ ; : ? ( addr -- ) \ print unsigned contents at addr 2 spaces @ u. ; \ in the current base : c? ( addr -- ) \ print byte contents at addr 2 spaces c@ . ; \ in the current base : c?% ( addr -- ) \ print byte contents at addr 2 spaces base @ swap \ in binary c@ 8 bin u.r base ! ; : ?% ( addr -- ) \ print contents at addr 2 spaces base @ swap \ in binary @ 16 bin u.r base ! ; \ Compile a word which creates n cell indexed arrays. \ compile-time n array <name> where n is size of array \ run-time i <name> where i is the array index \ and i is zero based (0...n-1) : array ( n -- ) create cells allot does> ( i -- 'cell ) swap cells + ; \ Compile a word which creates n indexed character arrays. \ compile-time n carray <name> where n is size of array \ run-time i <name> where i is the array index \ and i is zero based (0...n-1) : carray ( n -- ) create allot does> ( i -- 'char ) + ; \ Create a 20 character array in eeprom called CALIBRATE. \ eeprom \ decimal 20 carray calibrate \ ram \ Display the contents of program space in FLASH memory, \ given the starting address and length. \ For the dsPIC30F, program space addr range is $1000 to $fbff, \ (See p30f_481pzef_config.inc). \ Displays in hex notation and printable ASCII. \ idump expects base to be hex. \ \ Instruction Dump. \ addr range is $1000 to $fbff. \ +n is the number of instructions to dump. \ : idump ( addr +n -- ) swap $fffe and \ start on even address swap $8 u/ ?dup 0= \ always print at least 1 row if 1 then \ number of rows to print for cr dup 4 u.r- [char] : emit space \ display row starting addr $8 \ number of instructions per row for \ print 1 row of program space dup cf@ 2 u.r- 4 u.r 2+ \ fetch 24 bits from flash and print next $10 - \ wind back the addr $8 \ number of instructions for \ print ASCII dup cf@ swap drop over c@+ swap c@ rot 3 \ 3 bytes at a time for dup bl $7f within 0= if drop [char] . then \ non-printable character emit next 2+ next next drop cr ; \ Create an execution table with n entries. \ Each entry consists of 'nn' cell sized comparison value \ and 'an' the address of the corresponding word to be executed. \ At least two entries must be provided, the last one being the \ default action. \ \ Jump Table (from Haskell) \ Example: \ \ JUMP_TABLE do.key \ control H | bkspace \ control Q | quit \ HEX 2B | escape DECIMAL \ DEFAULT| chrout \ Useage: \ do.key ( n -- ) \ enter with n=code-to-match on TOS \ \ Create a jump table. \ : JUMP_TABLE ( -- ) \ compile an execution table ( m -- ) \ execute a word corresponding to m create [ flash ] here 0 , \ initial test_cnt stored at pfa \ ( addr -- ) does> \ ( m addr -- ) dup @ \ ( m a cnt -- ) for cell+ 2dup @ = \ ( m a flag -- ) if \ a match was found nip cell+ @ex \ execute the matched word rdrop exit \ and exit then cell+ \ ( m a -- ) point to next nn to test next nip cell+ @ex ; \ execute the default word \ Use the words | and default| to fill jump table. \ : | ( addr m -- addr ) , ' , \ store m (match) and cfa in table 1 over +! ; \ increment test_cnt at pfa : default| ( addr -- ) drop ' , ; \ store default word cfa in table ram hex
Here is a file containing words that I have found helpful when using FF4.8.
Last edit: Pete Zawasky 2013-10-07
Dictionary of FlashForth 4.81 on dsPIC 30, 33 and PIC 24
A cleaned up version...