Develop games for the cbm-64

10 min read

EASY 6502

David Bolton demonstrates how to develop games in 6502 for the Commodore 64 and run them on the Vice emulator in the 21st century!

Credit: https://skilldrick.github.io/easy6502

Last month, we looked at the 6502 assembly language and wrote a short program to sort numbers and run it on a web-based emulator. This time, the code will run on the Vice emulator, which is exactly like if you’re running it on a real CBM-64. To write programs for it, we have to do the following. 1. Write the 6502 source code. 2. Assemble it into a binary file. 3. Load the file into the Vice emulator and run it.

Writing 6502 code is easy enough [steady on now – ed] and you can use your favourite editor. For step two, though, we need a decent assembler and the one we’re using is xa65. You might find it easier if you edit the source files using VS Code. There are a few 6502 extensions for it, including assemblers and formatters. Enter 6502 in the extension box to see them. There’s also a VS65 debugger extension that works with Vice to let you visually debug it, but that wasn’t used here. For now, we’ll assemble the code from a terminal: $ dasm then xa65

Originally, this was written using the dasm (https://dasm-assembler.github.io) assembler. But after struggling with it for a few days, it turned out to have too many issues and the decision was made to switch over to xa65. Dasm had issues with label names and the final straw was seeing a jmp to a label be out by two bytes in the disassembled code, causing it to crash. This is why you should always inspect your 6502 machine code with a disassembler.

Some of this may be our fault, but xa65 worked without any fuss. You can find its man pages at https://bit.ly/lxf313jam and install it with:

$ sudo apt install xa65

Here’s a short program to test that we can both assemble code and run it in the Vice emulator. All it does is put characters on screen. You can see a list of CBM-64 character codes (aka PETSCII) at https://sta. c64.org/cbm64pet.html. Video memory in character mode runs from $0400 upwards – just place values in $0400, $401 and so on and they’ll appear on screen. The line * = $2000 is needed for all programs assembled with xa. It means the code is meant to be loaded at address $2000. Other assemblers have a different way of specifying the load address. ;

Test asm program * = $2000

SCNKEY = $FFE4

LDX #$10 LDA #$64