aka: "ca65 for stand-alone Apple assembly projects"
Since all the cool kids are using cross-assemblers these days I figured I would get with the times and stop hand-assembling everything. (Hey it was good enough for Woz and Integer Basic! :)
I've put together a demo and bash shell script to automate these steps:
https://github.com/Michaelangel007/cc65/tree/master/apple2
What src2dsk.sh does:
* assemble a barebones.s file, producing barebones.o
* link it, producing barebones.bin
* use a2tools to copy it onto a DOS 3.3 disk, called BAREBONES
This lets you use cc65 without all the C library crap! Here are the steps involved that others might find interesting:
1. I used a dead simple linker script called: apple2bin.cfg
- - - 8< - - -
MEMORY {
RAM: start = $1000, size = $8E00, file = %O;
}
SEGMENTS {
CODE: load = RAM, type = ro;
DATA: load = RAM, type = rw;
BSS: load = RAM, type = rw;
}
- - - 8< - - -
2. Since we're not using any of the cc65 libraries, ld65 won't generate the 4-byte header for us. We need to do this manually, but this is trivial. Stick this at the top of your .s file to generate the 4-byte header for DOS 3.3
- - - 8< - - -
; 4 byte header for DOS 3.3 files
.word $1000 ; define 2 bytes, must match org
.word __END__ - * ; define 2 bytes, total size in bytes
.org $1000 ; .org must come after header else offsets are wrong
... your code ...
__END__:
- - - 8< - - -
3. Runs the assembler with:
ca65 --cpu 65c02 -o foo.o foo.s
4. Runs the linker with:
ld65 -C apple2bin.cfg -o foo.bin foo.o
5. We can verify the binary is truely barbones!
hexdump -C barebones.bin
00000000 00 10 1d 00 a2 00 bd 11 10 09 80 20 ed fd e8 bd |........... ....|
00000010 11 10 d0 f5 60 48 65 6c 6c 6f 2c 20 77 6f 72 6c |....`Hello, worl|
00000020 64 21 00 |d!.|
00000023
6. I used a2tools to copy the foo.bin onto foo.dsk with the filename FOO. I used awk to capitalize the filename, a2rm to delete the old binary off the .DSK, and a2in to "instal"" the new binary onto the .DKS.
A2FILE=`echo "${1}" | awk '{print toupper($0)}'`
a2rm ${1}.DSK ${A2FILE}
a2in -r b ${1}.DSK ${A2FILE} ${BIN}
7. You'll need to mount the (updated) disk in your favorite emulator but you're good to go !
I ran into one cc65 bug with version ca65 V2.15. Apparently the macro to is broken when setting the high bit -- it doesn't update the last 4 bytes of the string. I wasted enough time automating the whole assemble+link+copy that I didn't feel like tracking down what was broken with ca65.
Anyways, all the stuff is in my repo:
* apple2bin.cfg
* barebones.dsk
* barebones.s
* src2dsk.sh
https://github.com/Michaelangel007/cc65/tree/master/apple2
Enjoy!
Michael