home *** CD-ROM | disk | FTP | other *** search
- \\ HEXSAVE.SEQ save target image as a HEX file
-
- {
-
- ONLY FORTH ALSO COMPILER ALSO FORTH DEFINITIONS
-
-
- 0 value grabcnt
- : grab ( n -- ) \ grab n and add to string at pad
- grabcnt pad + c! incr> grabcnt ;
- : grab" ( a n -- ) \ grab string length n from a and add to string at pad
- pad grabcnt + swap dup +!> grabcnt cmove ;
- : g# ( n -- a c ) \ number conversion to 2 digit ASCII
- 0 <# # # #> ;
-
- : write-hexline ( -- ) \ write one line from pad to the HEX file
- pad grabcnt
- ( line-addr line-len ) dup>r
- targethndl hwrite r> - \ write a line of CODE in HEX
- if 0 " Error while saving CODE to HEX file."
- "errmsg2 abort
- then ;
-
- 0 value target-addr
- 0 value seg-length
- 0 value cksum
-
- : build-hexline ( -- )
- base @ >r hex
- off> grabcnt \ build HEX line at pad
- off> cksum
- " :" grab" \ start with a :
- seg-length 16 min g# grab" \ byte count for this line
- target-addr split g# grab" g# grab" \ target address
- " 00" grab" \ two 0's
- 16 0 DO
- seg-code target-addr c@L \ get a code byte
- dup +!> cksum \ add to checksum
- g# grab" \ put in hex line
- incr> target-addr \ next image address
- decr> seg-length
- seg-length 0= ?leave
- LOOP
- cksum negate $0ff and g# grab" \ put in the checksum
- 13 grab 10 grab \ put in an end-of-line
- r> base !
- write-hexline ;
-
-
- : SAVE-HEX \ write the contents of the hex file
- base @ >r hex
- segments
- begin @ dup while \ for each segment
- dup 2+ @ \ get segment start
- dup !> target-addr dup 6 u.r
- over 4 + @ \ get segment end
- swap - \ make segment length (S start length )
- dup !> seg-length dup 8 u.r
- 0 ?do build-hexline 16 +loop \ write the segment
- cr
- repeat
- drop
- off> grabcnt
- " :00000001FF" grab" 13 grab 10 grab \ add ending line
- write-hexline
- r> base ! ;
-
- : %save-image.hex ( | -- )
- [compiler]
- seqhandle image.name $>handle " HEX" ">$ image.name $>ext
- ?cerrors ?exit
- #unres
- if cr ." \3 Image not saved \0, some symbols \2 UNRESOLVED! "
- cr here-t code-start -
- here-d data-start - + 5 .r ." Bytes compiled"
- else image.name targethndl $>handle
- targethndl hcreate \ make image.hex
- if 0 " Error while creating HEX file." "errmsg2
- abort
- then
- cr cr ." Created HEX file."
- data-seg-fix \ adjust HERE-T and fix
- \ DATA segment alignment
- dp-set \ set targets DP
- cr ." Segments"
- cr ." Address Length" cr
- SAVE-HEX
-
- then cr ;
-
- ' %SAVE-IMAGE.HEX IS SAVE-IMAGE.COM
-
- }
-
- : write-to-index ( n a -- ) \ write one byte to the index file
- 2drop ;
-
- : write-segment ( -- ) \ write up to 100 bytes of a segment to the index file
- target-addr 10 *d symhndl movepointer
- pad 1000 symhndl hread
- 0<> if pad 7 + \ point to code place in index file image
- 100 0 DO
- seg-code target-addr c@L \ get a code byte
- over c! \ put it in the index file
- incr> target-addr \ next image address
- decr> seg-length
- 10 +
- seg-length 0= ?leave
- LOOP
- drop
- then
- pad 1000 symhndl hwrite drop
- ;
-
-
- : SAVE-INC \ write the image into the index file
- cr ." Writing into index file" cr
- segments
- begin @ dup while \ for each segment
- dup 2+ @ \ get segment start
- dup !> target-addr dup 6 u.r
- over 4 + @ \ get segment end
- swap - \ make segment length (S start length )
- dup 8 u.r
- dup !> seg-length
- 0 ?do write-segment 100 +loop \ write the segment
- cr
- repeat
- drop
- ;
-
-