The basics In this first part of the tutorial we will create a simple Hello World program to run on the Commodore 64. This will cover: How to make programs run on a Commodore 64 Writing simple code with labels Numeric and string data Invoking the assembler
A note on numeric notation Throughout these tutorials, I will be using a lot of both decimal and hexadecimal notation. Hex numbers will have a dollar sign in front of them. Thus, 100 = \$64, and \$100 = 256.
Producing Commodore 64 programs Commodore 64 programs are stored in the PRG format on disk. Some emulators (such as CCS64 or VICE) can run PRG programs directly; others need them to be transferred to a D64 image first. The PRG format is ludicrously simple. It has two bytes of header data: This is a little-endian number indicating the starting address. The rest of the file is a single continuous chunk of data loaded into memory, starting at that address. BASIC memory starts at memory location 2048, and that's probably where we'll want to start. Well, not quite. We want our program to be callable from BASIC, so we should have a BASIC program at the start. We guess the size of a simple one line BASIC program to be about 16 bytes. Thus, we start our program at memory location 2064 (\$0810), and the BASIC program looks like this: 10 SYS 2064 We SAVE this program to a file, then study it in a debugger. It's 15 bytes long: 1070:0100 01 08 0C 08 0A 00 9E 20-32 30 36 34 00 00 00 The first two bytes are the memory location: \$0801. The rest of the data breaks down as follows: BASIC program breakdown Memory Locations Value \$0801-\$08022-byte pointer to the next line of BASIC code (\$080C).\$0803-\$08042-byte line number (\$000A = 10).\$0805Byte code for the SYS command.\$0806-\$080AThe rest of the line, which is just the string 2064.\$080BNull byte, terminating the line.\$080C-\$080D2-byte pointer to the next line of BASIC code (\$0000 = end of program).