Apples And Oranges


I hadn't written a single line of 6502/65C02/65816 assembly code since about 1996, but sometimes it's fun to see how rusty we aren't, even with age.

Last night, some discussion about Apple IIGS emulators led me to boot up a couple of them, and consider what it would take to develop for them, given a couple factors:

1. There should be no editing of source code inside the emulator. I love TextMate and I kinda shiver at the idea of editing code inside an emulator. Especially when you consider the modern convenience of...

2. Source code control. CVS and SVN are at our fingertips, why wouldn't we want to use them? We can't really have them inside an Apple IIGS emulator.

So I decided on the strategy of editing the code on the Mac with TextMate, assembling it with 'asl', exporting the output to a file on a .2MG disk, and finally booting an emulator to execute it off the .2MG. Apparently, this is do-able.

Figure 1: Source Listing

; this is a first test

                cpu     65c02

                org     $2000

putc            =       $FDED

                ldx     #0
loop1:          lda     outstr1,x
                beq     return
                ora     #$80
                jsr     putc
                bra     loop1
return:         rts

outstr1:        byt     "this is an interesting test."
                byt     00

(Note, 65C02 mode is used here because I hadn't bothered to look through the manual to discover the commands 'ASSUME M:1' and 'ASSUME X:1' which would have caused the assembler to emit code for the 65816 in 8-bit mode, which was my desired target. I nonetheless enjoy the 'bra' instruction, hence 65C02 instead of plain 6502)

I named this file 'test1.asm', and was able to assemble it with:

% asl test1.asm

.. Leaving me with a test1.p file, which had some extra headers and padding, stripped off with the asl utility 'p2bin' thus:

% p2bin -r 8192-9000 test1.p test1.bin

Note the '-r 8192-9000' is necessary because I chose to originate at $2000 and for some reason someone thought it'd be helpful to pad $2000 bytes at the beginning. The file test1.bin was then verified with 'hexdump' to resemble the desired code.

From here, I exported the test1.bin file to a ProDOS 8 formatted, bootable, 800K disk image with "ADFS Carbon." I don't like this step because it isn't CLI-oriented, and to make a repeatable development step out of this, I'd probably have to make scripts based on the (perl) CPAN ProDOS image manipulation modules.

(Update 4/14/2007: I did later refine this to be Makefile-based and use AppleII::ProDOS from CPAN to emit emulator-ready, ProDOS-formatted disk images just by typing 'make'. I also tracked down the NoiseTracker Player Module source and various other goodies. When I realized I was only hours away from being able to release the next Le Demo IIGS Cliche, I stopped cold, for reasons of good taste. I will not continue this project, because whatever 1993 was, it was enough.)

So then, I fired up Sweet16, mounted up that .2MG, and zing:

Figure 2: Finally Some Output


There we are, my first Apple II program in about 11 years. In all likelihood, it will be at least another 11 before the next one. But for now, my curiosity's satisfied.