Skip to content

Latest commit

 

History

History
155 lines (89 loc) · 10.6 KB

C64 Assembly Coding Guide.md

File metadata and controls

155 lines (89 loc) · 10.6 KB

C64 Assembly Coding Guide

Hi, I'm Spiro, aka @notawizard on Youtube and the fediverse and I would like to help you get started programming in assembly language for the Commodore 64.

This page doesn't cover everything (nothing ever could be), just what I know and have experience with, and tried to narrow down to a few good options without overloading you with everything. :)

I also haven't mentioned IDEs and editors as they are are personal choice (and subject to religious wars which I don't care to partake in). The cross assemblers I have included tend to be command line based and can often be tied into whatever editor/IDE you use. If command line scares you, then assembly will make you shit bricks, so you may as well save your sanity now and find a different hobby.

A quick note on the CPU architecture. The c64 uses a MOS 6510, which is 100% compatible with the 6502. All it added was a few I/O address pins which allowed the c64 to bank switch different portions of memory out (you'll find out more about this with the 64k of RAM having ROM and BASIC doubled up on top).

You will need to learn 6502 machine language and can use any source, whether it's for the c64 specifically, or Apple ][, NES, or Atari8.

Machine Language vs Assembly Language vs Machine Code

The terms are used interchangeably, but do actually have different meanings and I feel it's important for someone new to assembly to understand the distinction.

First off, "machine code" refers to the native hex or binary representations of the CPU's instructions. We don't use machine code. We use human readable opcodes like LDA, STA, JMP, etc, which we call mnemonics, and mnemonics and memory addresses (usually written in hex) are the building blocks of "machine language."

A short program in machine language might look like:

$C000	INC $D020
$C003	JMP $C000

The first column is the memory addresses (which you don't type in, but need to refer to where your branches will happen). The second and third columns are the machine language instructions.

Normally, you would use an "ML monitor" for entering machine language, such as SuperMon or from a freezer cartridge like Action Replay or using the one built into your emulator.

"Assembly language" refers to the extra luxuries that an assembler gives you on top of "machine language." For example, text labels, psuedo opcodes, the ability to do simple maths when referring to numbers, macros, and so on.

The same short program in assembly language might look like:

loop:
	INC $D020
	JMP loop

If you find a resource teaching you "assembly language" and they use the term properly, then you will have to use the same assembler that they use or you will need to know how to change it to the syntax your assembler uses.

Some things remain the same across assemblers, but many don't. Their own features made the selling points for why you should buy or use their assembler over anyone elses. :)

But more importantly, you should start with learning machine language on a monitor because it will give you the fundamental skills you will be using to debug your code when you move to an assembler.

It also means that you can look at code written for other assemblers and have a good understanding of what you need to change to get that code to work in your preferred assembler.

There are no shortcuts in learning assembly language. You can either waste your life looking for them, or you can pull your socks up and be productive. If you want the easy path to coding success, go learn a modern language like Python. But if you want to be a complete sadomasochist and learn to program to the bare metal on a 40 year old computer, then go all in baby!

;)

Start Here

This section will have a few links to the absolute fundamentals of the 6502/6510 architecture and are necessary pre-requisites for you to code in machine/assembly language on the c64.

Reference

Cross Platform Tools

These run on Linux, MacOS, and Windows.

Windows-only Tools

  • DirMaster - "DirMaster is a Windows-based GUI application designed to help Commodore enthusiasts explore and manage their disk image collections." (by Style)

Cross Development 6502 Assemblers

Most of these run on Linux, MacOS, and Windows.

  • KickAssembler - KickAssembler, cross platform, runs everywhere, written in Java, and has the best functionality I've ever seen in an assembler (by Mads Nielsen)
  • ACME - a cross assembler that has been developed since 1998 (by Marco Baye)
  • ACME docs - sourceforge makes it hard to find the actual files, so here's a direct link to the docs of the r323 trunk (olddevspeak for the latest code branch)
  • cc65 - includes a macro assembler, c compiler, linker, and other tools
  • xa65 - runs on Unix platforms (including MacOS) (by André Fachat, currently maintained by Cameron Kaiser)

Hardware

Some hardware useful for developing natively on your physical C=64.

  • SD2IEC - SD card interface for your 64
  • EasyFlash 3 - Install several cartridge images onto one cartridge. A lot of games are being converted to EasyFlash cart images these days.

Wikis & Infosites

  • 6502.org - a good resource for 6502 information
  • Codebase64 - democoding resources, a bit hit & miss
  • Replay Resources - Info about replay/freezer carts like Action Replay
  • c64 wiki - general c64 wiki with lots of good info and details on functions, BASIC commands, and more

Native C=64 Tools

  • Super Snapshot - A Canadian alternative to ActionReplay with, IMO a better machine language monitor and with very good documentation.
  • Turbo Assembler v5.2/FLT - TurboAss v5.2 as modified by Bacchus of FairLight for non REU machines. You will need Lynx to "dissolve" the file from a .lnx file to a .prg.
  • TurboMacroPro - a more advanced evolution of Turbo Assembler series with macro support. Also has a larger memory footprint, which is why I still prefer tass v5.2 above.

Web Tools

  • RetroPixels - Convert modern format images into C64 format (by Michel de Bree)
  • PETSCII Editor - web based tool to design PETSCII screens, charsets, and sprites
  • Spritemate - web based sprite editor

Tutorials

Books

  • Bombjack's c64/128 archive - A curated list of books, manuals, and magazines
  • Archive.org - All the books. Bombjack has them all easier to find and view, but if something is missing, or you're looking for a different version, chances are it'll be here.

My Recommendations

Software Repositories