You are currently viewing the Australia version of the site.
Would you like to switch to your local site?
13 MIN READ TIME

EASY 6502

Develop games for the CBM-64

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

OUR EXPERT

David Bolton used to write Commodore 64 games for a living back in the mists of time, and taught himself Z80 by writing a 6502 assembler in Z80.

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.

Part two!

Don’t miss next issue, subscribe on page 16!

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. ;

Unlock this article and much more with
You can enjoy:
Enjoy this edition in full
Instant access to 600+ titles
Thousands of back issues
No contract or commitment
Try for $1.48
SUBSCRIBE NOW
30 day trial, then just $14.99 / month. Cancel anytime. New subscribers only.


Learn more
Pocketmags Plus
Pocketmags Plus

This article is from...


View Issues
Linux Format
April 2024
VIEW IN STORE

Other Articles in this Issue


LINUX FORMAT
LINUX FORMAT
The #1 open source mag
WELCOME
MEET THE TEAM
LINUX FORMAT
Back to basics
For anyone looking to learn the basics of
REGULARS AT A GLANCE
Newsdesk
New Mozilla CEO to double down on Firefox
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mailserver
WRITE TO US Do you have a burning
HotPicks
THE BEST NE W OPEN SOURCE SOF T WARE ON THE PL ANET
MICROSOFT INVASION!
When an immovable penguin meets an unstoppable corporation, always bet on the penguin…
REVIEWS
GeForce RTX 4070 Super
Jarred Walton considers what’s so super about mid-cycle updates.
Linux Mint 21.3
Nate Drake keeps things Minty fresh with this incredibly intuitive and powerful Linux distro. Be sure to add some spices.
AV Linux MXE-23.1
Nate Drake puts his ear to the ground to hear the latest version of AV Linux, Enlightenment, rumbling into town.
Solus 4.5 Resilience
Nate Drake’s Irish eyes are smiling at this latest offering from Solus, with improvements to the desktop and under the hood.
SDesk 2024.01.26
Nate Drake discovers the new kid on the block, SDesk, including shiny toys such as Wayland and a brand new browser.
ROUNDUP
Retrogaming distros
WE COMPARE TONS OF STUFF SO YOU DON’ T HAVE TO!
The verdict
Retrogaming distros
Hacker’s toolkit
After an extended break, alleged hacker Jonni Bidwell emerges from the shadows to teach you the noble art and keep you out of trouble.
Pi USER
Raspberry Pi supports T Level students
“What’s a T Level?” we hear you ask. Don’t worry, we didn’t know either…
MX Linux 23.1 Pi
Les Pounder spends all day tinkering with Raspberry Pis and the latest MX Linux has got him in a spin.
NVMe Base Pi 5
Everyone, says Les Pounder, is based, especially regarding Pimoroni!
Scare your enemies with a Pi prank box
Yes, Les Pounder is very scary, but buying OEP3W amplifiers from AliExpress is worse. He wonders what pranks he can pull with them…
Enhance your Pi-vacy
A man who likes to keep himself to himself, Christian Cawley explains how to keep online activity private when using a Raspberry Pi.
IN DEPTH
THE PAW-FECT DISTRO
Nick Peers can hardly ‘container’ himself after taking the Puppy Linux developer’s new distro for a good run off the lead.
TUTORIALS
Parallel compression
Parallel processing, the computing equivalent of juggling, as Shashank Sharma calls it, can be used to perform everyday tasks to save time.
Get more from your virtual machines
VIRTUALBOX
What’s in a filesystem?
EXT4 Credit: https://ext4.wiki.kernel.org
Moving rooms and sharing your game
ADVENTURE GAME STUDIO Credit: www.adventuregamestudio.co.uk
Fix LEDs with some coded CAD models
OPENSCAD Credit: http://openscad.org
Take the Rust-based kernel for a test run
MAESTRO Credit: https://github.com/llenotre
ADMINISTERIA
Disk management
Stuart Burns isn’t boring, he’s essential – just like looking after your disks
The Pi 5 as a mini server
A sysadmin’s perspective on setting up and running a new Raspberry Pi 5 for Docker and beyond.
Yodeck
Jonas P DeMuro dusts off his Raspberry Pi so he can take a quick overview of this digital signage service.
Hostinger
James Capell is just the guy to try out a web host that’s easy enough for your granny to use.
Framework
Three years on, the DIY laptop concept has come of age. 
Framework Laptop 16
Slapping parts together, Dave James takes this modular laptop with upgradable GPU for a spin. 
CODING ACADEMY
Revealing the shell behind the shell
In the last iteration of the shell, Ferenc Deák managed to reveal the password for his home computer…
Chat
X
Pocketmags Support