Skip to content

Apple II 4. Compiling assembly code for the Apple II

StewBC edited this page Feb 18, 2020 · 3 revisions

Compiling assembly code for the Apple II

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.lib adds a needed library
  • -C apple2-asm.cfg uses a config file specifically set up for assembly programs
You now have an Apple II ready program, but it needs to go on a disk so it can be loaded in an emulator.

Making a disk

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.

Clone this wiki locally