Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using xa65 assembler to create Commodore 64 .prg

I am trying to learn 6510 assembly and since I am running Debian xa65 is the assembler I want to use.

I have so far written a piece of code that looks like so:

*=$0801
.byte $0c, $08, $0a, $00, $9e, $20
.byte $34, $30, $39, $36, $00, $00
.byte $00

*=$1000
INC 53280
INC 53281
JMP $1000

Now, the first .byte section are suposed to "autostart" the program once loaded. This is something I found from a tutorial and as far as I can understand it will only run SYS 4096 making the CPU start executing the code at address $1000

The rest of the code should simply start flickering the outer and inner border of the C64 and repeat forever.

When assembling this I simply run the following:

xa test.s -o test.prg

and then I try to load test.prg into VICE to test it. with LOAD "TEST.PRG",8,1: and even if the file loads it does not autostart, nothing happens if i type RUN: and the same if I type LIST: - the only result is the famous READY. and the cursor flashing very happily like usual.

I tried to remove the autostart stuff and assembled only the code starting from *=$1000 but I got the same results. Trying to start with SYS 4096 also results in READY and nothing more.

I am sure I am not using the xa assembler right, but I can't figure out how I do create a proper PRG file for the C64 to use. What am I doing wrong?

like image 957
Waxhead Avatar asked Jan 31 '15 10:01

Waxhead


2 Answers

I was trying to figure out how to make xa65 pad its output when I came across your question and have since learned how it works. Here's what I've found.

As jester said, your code won't be at $1000 since setting the PC doesn't perform any padding. Padding is supported in xa65 using the .dsb directive, but a number of bytes must be specified for the directive rather than just an address like some assemblers' .org directive allows. Since the assembler allows for simple arithmetic, the number of bytes is given by <desired address> - PC.

Adding the missing .prg address header and changing your second PC change to a padding directive results in output that behaves as expected. However, this still doesn't make it autostart. LOAD "TEST.PRG",8,1: and RUN does work, though.

.byte $01, $08 ; Load this .prg into $0801

*=$0801
.byte $0c, $08, $0a, $00, $9e, $20
.byte $34, $30, $39, $36, $00, $00
.byte $00

.dsb $1000 - * ; Pad with zeroes from PC to $1000

INC 53280
INC 53281
JMP $1000

FWIW, how to use the padding method wasn't immediately obvious in xa65's documentation (to me, at least).

like image 175
William Rogers Avatar answered Oct 05 '22 08:10

William Rogers


As far as I remember, $0801 was the start address of basic programs and that doesn't autostart anything. To autostart, you had to play tricks.

Just assemble for $1000 and start your program using sys 4096. A frequently used area for assembly helpers was $c000 (sys 49152) as that doesn't interfere with normal basic programs.


I am not familiar with xa65 but according to my tests it does not pad the file if you assign to *. As such, the code you expect to be at $1000 isn't going to be there, in fact it's just after the previous block. Also, c64 prg format expects a start address on the first two bytes which xa64 doesn't seem to fill in either. I have managed to get this to work:

*=$0FFE
.byte $00, $10
INC 53280
INC 53281
JMP $1000

Start with sys 4096.

PS: VICE has built-in monitor (machine level debugger).

like image 29
Jester Avatar answered Oct 05 '22 08:10

Jester