Inspired by a script I found on github (https://github.com/RC2014Z80/RC2014/blob/master/ROMs/hexload/bin2bas2.py) I decided to make my own script and make it more useful to my own use case. (its nothing new and mainly here as my own aide-mémoire)
Having a 64KB ram system there are a few differences to a system just running with 32KB (so you’ll have to change things around a little if you have a 32KB system)
The heart of the project is a very simple Makefile
.PRECIOUS: %.bin %.bas : %.bin ./bin2bas.py $< $(BASE) > $@ @cat $(@) %.bin : %.asm ./z80asm $< -o $@
Because its an inferred chain of rules (all 2 of them!) make will delete intermediates for you, unless you tell it they are precious, sometimes the binary can be handy…
You can set an optional BASE environment value which tells the basic code where to poke your data, if BASE is unset then it defaults to 0xFC00 (because how could you ever need more space!)
Initially I just had the bin2bas script outputting poke statements, but I noticed something odd, it seems to take basic less time to evaluate the entry of a basic line than it does to evaulate and run a statement like poke.
In a simple test I have written just about the smallest example that actually shows a machine code routine doing something
DEINT: equ 0x0a07 ABPASS: equ 0x117d org 0xFc00 call DEINT ld a,e ld b,d jp ABPASS
Basic has a number of useful routines DEINT takes the value passed by the basic USR command and places it in DE, returning a 16 bit number is just a question of placing the value in registers A and B and calling ABPASS. Looking at the source for basic I’m reasonably sure that its intended you should jump to ABPASS and it takes care of returning to basic for you. I have intentionally swapped the registers around a to e instead of a to d so that when the code is called with a value like 4660 (0x1234) the return will be easily recognised, as its printed out as a hex value, so we see 0x1234 going in and 0x3412 as the output.
Taking a quick look at the output you paste into the terminal
10 DATA 205, 7, 10, 123, 66, 195, 125, 17, 20 FOR A=-1024 TO -1016 30 READ D : POKE A,D 40 NEXT A 50 POKE 8264,195 60 POKE 8265,0 70 POKE 8266,252 80 PRINT HEX$(USR(4660))
the main thing you need to change for a 32KB system is the address where you poke the USR jump
In the Python code the above will produce the base address you need, I don’t know on 32kb systems if you supply the basic memory top address as an absolute address or relative from the start of memoy (0x8000) …
You can find the files here but you will have to modify the makefile to point to your own assembler of choice.