VolksForth

Make a HEX file for upload
Login

How to make a hex dump file to upload VolksForth to the Apple 1

Python version (contributed by William R Sowerbutts)

#!/usr/bin/env python

import sys

def out(x):
    sys.stdout.write(x)

addr = 0x1000

first = True
for byte in sys.stdin.read():
    if addr % 16 == 0:
        if not first:
            out("\n")
        first = False
        out("%04x:" % addr)
    out(" %02x" % ord(byte))
    addr += 1
out("\n")

Forth Version

( forth version of the mkhex tool                     )
( creates a hex file to load into the Apple 1 monitor )
( usage: gforth mkhex.fs > f6502.hex                  )

: read-image ( file-id -- addr size )
  dup file-size drop d>s              ( file-id size ) 
  dup allocate drop dup >r            ( file-id size addr )
  swap rot read-file drop r> swap     ( addr size )
;

: find-end ( end-addr -- new-end-addr )
  begin dup @ 0= while 1- repeat 
;

: dump16 ( addr len -- )
  over + swap ?do I c@ 3 .r loop ;

: dump-hex ( end begin -- )
  hex ." 1000:" 
  do I $10 dump16 cr ." :" $10 +loop
;

S" f6502.com" r/o open-file drop read-image 
over + find-end cr swap dump-hex

bye

REXX (OS/2) Version

/* rexx */

PARSE ARG infile outfile

rc = Stream(infile,"C", "OPEN READ")
rc = Stream(outfile,"C", "OPEN WRITE")

numchars = Chars(infile)
SAY numchars "Bytes to convert"

rc = Charout(outfile,"1000: ")
x = 0
DO u = 1 TO numchars
   c = CharIn(infile)
   rc = CharOut(outfile,C2X(c) || " ")
   x = x + 1
   IF x = 32 THEN DO
     x = 0
     rc = LineOut(outfile,' ')
     rc = CharOut(outfile,": ")
   END
END

rc = Stream(infile,"C", "CLOSE")
rc = Stream(outfile,"C", "CLOSE")

RETURN