RE:CODE - Converting BASIC games to 6502 assembly Article #1: Why, when, how and what...
Chatting to my good friend and coding mentor OldSkoolCoder the other day, we got onto the topic of the BASIC to assembly conversions I’ve been working on over the last six months or so.
I started them as a means to improve my 6502 coding knowledge, alongside following OldSkoolCoder’s youtube videos. At first I began converting programs from some of the type-in books in my collection, but later I decided to move on to a re-code of the much-maligned Cascade 50 Games collection.
I won’t go into the details of that collection as it is covered elsewhere on the internet (Here, Here, and Here, for example) but it is basically a collection of what seems like hastily thrown together games in BASIC. The games are often quite limited in playability and more often than not full of bugs. So what better challenge than to - at the very least - turn them into playable games?
So back to my chat with OldSkoolCoder, and he suggested that I document my thought process as I convert one of these BASIC games to assembly - which I agreed would be a good idea. It's a particularly good time to do this right now as I’ve developed an approach to the conversions over the last six months that allows me to get up and running fairly quickly.
The framework I’ve developed for this is based on one shared by Derek Morris in his excellent Retro Game Dev book. However, as my own style of coding has developed over the last six months, I’ve moved quite a bit away from Derek’s original framework, while retaining some of the core elements. That’s not to take anything away from Derek’s approach - it helped me get to where I am now - but we all have our own style of coding so I have adapted things to suit me. My approach may or may not make sense to you, depending on your own personal coding style, but I hope it will at least be helpful to anyone on the road to learning 6502.
When tackling these conversions my first target is to replicate the game as is in assembly language, and not worry too much about graphics or extending the functionality. Once I’ve replicated the original within my framework (fixing any bugs on the way) it becomes easier to start making adjustments and improvements to add more life to the game. Well, a little life at least!
To give you an example, here’s a recent conversion I did of Cassette 50 game #41: Derby Dash. The clip below shows the before (i.e. original BASIC version) and the after (assembly re-code). You can see I’ve already made a few tweaks - enhancing the graphics slightly, changing the title screen. These tweaks are simple enough once the framework is in place.
So, the next game I’ve decided to convert from the Cassette 50 collection is game #15: Downhill Ski Jump. This - believe it or not - is actually one of the better games on the cassette. It’s difficult and a bit unresponsive at times, but it has multiple levels, a decent enough basic premise, some custom chars and sprites, music and a few sound effects. That makes it gold standard in the world of the 50 Games Cassette.
And I will document my conversion process right here on this blog, trying to give a detailed understanding of the steps I am taking along the way. This series will no doubt extend over many weeks as I want to try and get as much of the detail down as I can, including any videos and screenshots. And I will share all code on Github as soon as it’s in a shareable state.
The plan for this series (so far) will be as follows:
Introduction to the game and a first play through
Breaking down the BASIC - a line by line examination of the program to understand variables, logic and gameplay
Setting up the conversion framework - I use CBM PRG Studio, but the code and approach should be fairly easy to adapt to other IDEs. I’ll also rip any sprites and chars from the original version and talk about how we’ll prepare these for use in our own game, including possible relocation.
The conversion - this will be in several parts as I take each part of the gameplay and convert it to an assembly language equivalent, testing as I go along.
Finally, once we have a working replica, I will start to look at some small improvements we can make to the original - additions to gameplay, improved chars and graphics, a nice title screen etc.
Hopefully there are people out there who will find this useful. And if at any point in this series you want to ask a question or want me to explain in more detail then please drop me a line on email or Twitter.