home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
tcom
/
debugger
/
hexstuff.seq
< prev
next >
Wrap
Text File
|
1990-09-11
|
2KB
|
52 lines
\ HEXSTUFF.SEQ read in a HEX file
anew hexwords
decimal
2variable FLEN
-1 value lastshow
: 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 download it to the target
stash \ hide away the line pointers
nbyte \ byte count
nbyte 256 * nbyte + \ address
2 +!> sadr -2 +!> scnt \ skip next byte
swap 0 ?do nbyte over i + tc! loop \ move bytes into target
drop ; \ ( ignore the checksum )
: read-in ( -- ) \ read the HEX file and download to target
cr ." Downloading " 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 ;
: download ( | -- ) \ open the .HEX file next on the command line
\ and load it into a target
seqhandle hclose drop
read-only open
read-in \ read and download
seqhandle hclose drop
;