home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / forthmacs / !Forthmacs / lib / hexify < prev    next >
Encoding:
Text File  |  1994-07-08  |  1.5 KB  |  64 lines

  1. \ This program converts a binary file into a form suitable for downloading
  2. \ to a Data-IO prom programmer.  The format used is Intel Hex Format,
  3. \ which is select code 83 on the Data-IO.
  4. \ To use:
  5. \ % forth hexify.fth -s "hexify your-binary-file-name" >filename.hex
  6.  
  7. \ TODO: use new record formats to support >64K:
  8. \ : bb AAAA 02 SSSS dd dd dd dd ... cc          Address is (SSSS <  4) + AAAA
  9. \ : bb AAAA 04 HHHH dd dd dd dd ... cc          Address is (HHHH < 16) + AAAA
  10. \ The SSSS and HHHH portions of the address are "sticky", applying to
  11. \ subsequent (type 00) records.
  12.  
  13. hex
  14.  
  15. 10 constant bytes/line
  16. variable out-addr
  17. create line-buf 64 allot
  18. variable outfile
  19. variable checksum
  20. variable end-of-file?
  21.  
  22. : .2  (s u -- )  h# ff and n->l <# # # #> 2dup upper type  ;
  23. : .4  (s u -- )  n->l <# # # # # #> 2dup upper type  ;
  24.  
  25. : get-line
  26.    bytes/line 0 do h# ff line-buf i + c! loop
  27.    bytes/line 0  do
  28.       ifd @  fgetc  dup -1 =  if
  29.          drop  end-of-file? on  leave
  30.       else
  31.          line-buf i + c!
  32.       then
  33.    loop
  34. ;
  35. : put-line
  36.    bytes/line  checksum !
  37.    ." :"  bytes/line .2
  38.    out-addr @ 8 >> h# ff and checksum +!
  39.    out-addr @ h# ff and checksum +!
  40.    out-addr @ .4
  41.    ." 00"
  42.    bytes/line  0  do
  43.       line-buf i + c@
  44.       dup checksum +!
  45.       .2
  46.    loop
  47.    checksum @ ff and
  48.    100 swap -  .2
  49.    cr
  50.    bytes/line out-addr +!
  51. ;
  52. : (hexify ( -- )
  53.    end-of-file? off
  54.    0 out-addr !
  55.    begin
  56.       get-line  put-line
  57.       end-of-file? @
  58.    until
  59.    ." :00000001FF" cr
  60.    ifd @ close
  61. ;
  62. : hexify  ( "input-file-name" -- )  hex reading (hexify  ;
  63.