home *** CD-ROM | disk | FTP | other *** search
- \\ HEXCOM.SEQ read in a HEX file and convert it to a .COM
- ─────────────────────────────────────────────────────────────────────────────
- $Header:$
- ─────────────────────────────────────────────────────────────────────────────
- This program reads in an Intel-HEX format file with extension .HEX
- It creates a .COM file with the same name as the .HEX file.
-
- This program is used as follows e.g.
- hexcom - hexcom LCDT
- i.e. LCDT.HEX is converted to LCDT.COM
-
- ─────────────────────────────────────────────────────────────────────────────
- $Log:$
- ─────────────────────────────────────────────────────────────────────────────
- {
- anew hexwords
- decimal
- 2variable FLEN
- -1 value lastshow
- $2000 value ROMaddr \ lowest address in .COM image
- 0 value topaddr
-
- : hex># ( h -- n ) \ convert hex digit to a number
- dup '9' > if $37 - else '0' - then ;
- 0 value sadr
- 0 value scnt
- : stash ( a c -- ) \ hide away the pointer and count of the line string
- \ but first skip over the :
- 1- !> scnt 1+ !> sadr ;
- : nbyte ( -- n ) \ get the next byte from the HEX line stash'ed
- sadr c@ hex># 16 * incr> sadr decr> scnt
- sadr c@ hex># + incr> sadr decr> scnt ;
-
- : line<hex ( a c -- ) \ convert a hex line and
- \ load it to the target image at pad
- stash \ hide away the line pointers
- nbyte \ byte count
- nbyte 256 * nbyte + \ address of a byte in the target
- ROMaddr - \ offset for ROM start address
- 2dup + topaddr max !> topaddr \ record highest target address
- pad + \ address of a byte in the image at pad
- 2 +!> sadr -2 +!> scnt \ skip next byte
- swap 0 ?do nbyte
- over i + c! \ move bytes into target image
- loop
- \ ( ignore the checksum )
- drop ;
-
-
- : read-in ( -- ) \ read the HEX file and download to target
- cr ." Reading " seqhandle count type
- seqhandle endfile FLEN 2!
- 0 0 seqhandle movepointer ibreset \ reset to beginning of file
- begin
- lineread count ( a+1 c ) \ read a line
- dup FLEN 2@ rot 0 d-
- lastshow 0<
- if at? 2over 7 d.r at 2 =: lastshow then decr> lastshow
- FLEN 2! \ show bytes remaining
- 2dup 0<> swap 1+ @ $3030 <> and while
- over c@ ':' = if line<hex else 2drop then \ download line
- repeat
- 2drop 7 spaces cr ;
-
-
- : hexcom ( -- ) \ read the .HEX file
- \ and translate it into a target image in a .com file
- off> topaddr
- seqhandle hclose drop
- bl word seqhandle $>handle
- " hex" ">$ seqhandle $>ext
- read-only seqhandle hopen abort" cannot open .HEX file"
- read-in \ read and make image for high bytes
- seqhandle hclose drop
- " COM" ">$ seqhandle $>ext \ make .com image file
- seqhandle hcreate abort" cannot create .COM"
- pad topaddr 1+ 2* seqhandle hwrite
- topaddr 1+ 2* - .
- bye
- \ cr ." enter BYE to exit" cr
- ;
-
- save-exe hexcom
-
-