Apple II 4. Compiling assembly code for the Apple II - cc65/wiki GitHub Wiki
Save the following program as spkr.asm
.include "apple2.inc"
SPEAKER = $C030
.segment "CODE"
.proc main
lda #0
sta $50
bit KBDSTRB
loop:
lda KBD
asl
bcc :+
bit KBDSTRB
jsr $BF00
.byte $65
.addr * + 2
.byte 4
.byte 0
.word 0000
.byte 0
.word 0000
:
dec $50
bne loop
lda SPEAKER
jmp loop
.endproc
This program will simply hum the speaker till a key is pressed and will then quit back to ProDOS.
Compile the program to spkr.apple2 using the following command line:
cl65 -t apple2 -u __EXEHDR__ spkr.asm apple2.lib -o spkr.apple2 -C apple2-asm.cfg
The differences with the “C” program are:
-
-u __EXEHDR__adds a needed header -
apple2.libadds a needed library -
-C apple2-asm.cfguses a config file specifically set up for assembly programs
Follow the instructions from Prepare a disk for your program but replace the word hello with the word spkr.
Run the program and you should hear the speaker hum, till you press a key when the program quits, and you are back in the file selector at ProDOS.