Monday, 27 February 2012

In Which We Describe The Tools


I've talked about the toolchain needed for 6502 development before, so this is really just a summary description of how my setup works. The one major difference now compared to when I wrote that post I linked to is that I switched from using Crimson Editor to Notepad++, principally because N++ is being supported and updated regularly, whereas Crimson hasn't seen any significant revision for some time. In terms of functionality I think N++ has the edge anyway. Try both and see which you prefer.

The process of writing 6502 code, assembling it, and then squirting the binary to VICE is pretty simple:
  1. Write some 6502 code in Notepad++ and save it
  2. Invoke DASM on the source file
  3. Invoke VICE with the name of the binary
  4. Test and repeat
Writing raw assembly mnemonics for the 6502 CPU isn't for the faint-hearted, but equally it can be accomplished with not much more than a little effort, background reading, and patience. Sourcecode typically looks like this:


DASM is a command-line macro assembler that turns 6502 sourcecode into binary data that the CPU eats. It's a little temperamental about some things (it doesn't like the undocumented opcodes, and is fussy about which column the EQU directive has to appear in, for example) but on the whole is pretty-much the best 6502 cross-assembler for the PC out there. A typical commandline invocation might look like this:


Getting the resultant binary into VICE is either really simple, or a little complicated. If you're writing a program to run on a VIC-20, you ask DASM to save the binary as a Format 1 file with a '.prg' extension, and just drag 'n' drop the file into the VICE window. VICE then loads it into the VIC emulation, and you run it like any other VIC program. However, I'm re-writing the ROM for the computer, so DASM has to be told to produce a Format 3 file with a '.bin' extension, and this 16KB ROM binary then has to be split into two 8K ROMs (one called 'basic' and the other 'kernal') which VICE is then told to use instead of the standard Commodore ROM images when it starts up.

VICE itself is a package comprised of a variety of emulators for Commodore machines, including 'XVIC' which is the VIC-20 emulator. It's a Windows application, and has a virtually cycle-perfect simulation of the 6502 CPU, 6560/1 VIC chip (NTSC / PAL), the 6522 VIAs used for I/O, and more bells and whistles for drive and cartridge emulation than you'll ever need. It looks like this:


I've written a tiny command file which runs DASM on my sourcecode, splits the binary into two 8K chunks, and invokes VICE with them. Testing and debugging the code is then a quick cycle of saving the source and running the batch file to see how it looks. It's quick and easy, which makes iterative development a piece of cake.

No comments:

Post a Comment