Basic loader for Commodore 64 assembly programs


When you compile an assembly language program for the C64, to run it you need to type the SYS command followed by the starting location of your program in memory.

To make it easier for the user to run your program without having to know the starting memory location, you can add a small basic program to the start of your program, so all the user has to type is the RUN command.

The assembly source can contain a little extra code that encodes the following BASIC line.

10 SYS 4096

 

Each of the bytes in the loader program can be easily tailored to meet your requirements. So after inserting the disk which contains your program, the program can be loaded and run with the following commands:

LOAD “*”,8,1
RUN

The loader portion is just made up of a small number of bytes placed at the beginning of the assembly source code

*=$0801
.byte $0C,$08,$0A,$00,$9E,$20,$34,$30,$39,$36,$00,$00,$00

In the simple example the real assembly code begins at address $1000. The test program simply changes the screen border colour to show that is actually running.

Complile, assemble and then load the output PRG on to a disk. Then you just LOAD and RUN it.

;loader.prg
; test program changes border colours when run

; LOAD “*”,8,1
; RUN

; basic loader program
;10 SYS 4096; $0801 = 2049

*=$0801
; $0C $08 = $080C 2-byte pointer to the next line of BASIC code
; $0A = 10; 2-byte line number low byte ($000A = 10)
; $00 = 0 ; 2-byte line number high bye
; $9E = SYS BASIC token
; $20 = [space]
; $34 = “4” , $30 = “0”, $39 = “9”, $36 = “6” (ASCII encoded numbers for decimal starting address)
; $0 = end of line
; $00 $00 = 2-byte pointer to the next line of BASIC code ($0000 = end of program)

.byte $0C,$08,$0A,$00,$9E,$20,$34,$30,$39,$36,$00,$00,$00

; real start of program $1000 = 4096
*=$1000; change border colour
loop inc $d020
jmp loop

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s