Wednesday, February 15, 2017

Retro Programming in Commodore BASIC 2.0 - Part 1

Overview
It's amazing how much rust your programming skills can get for a specific machine and a specific language.  I've been programming Java professionally for about 10 years now, and am going back to my roots to rediscover the simplicity of programming for a machine with only 64k of RAM and direct access to the hardware ... no BIOS, no heavy GUI, just me and the machine.

And it's awesome!

The Program
A game.  That's about as far as I've gotten.  I'm writing this by the seat of my pants, so I'm just going to code.  I know I need screen routines and movement routines, but beyond that, I'm hashing out the details as I go.

Here's what I have so far:

It's not much.  Here's the breakdown:

Lines 10-30 are test code for the subroutines starting at line 10000:
Line 10 clears the screen, sets the cursor color to cyan, and sets the background color and border to blue.
Line 20 calls the subroutine at 10010 to put a ball character at (15, 5) on the screen in white.
Line 25 calls the subroutine at 10010 to put a ball character at (0,0) on the screen in yellow.
Line 30 is a keypress loop to hold up execution.

Line 9999 ends the program before the subroutines can be reached.  This prevents a program that doesn't exit before then from accidentally slipping into the first subroutine.

Line 10000 is just a comment.

Line 10010 contains the first subroutine.  Using 1024 as the start of screen RAM and 55296 as the start of screen color RAM, it uses the values in SX and SY to calculate the positions in screen and screen color RAM for the requested item to be displayed, and POKEs the character code and color code (CH and CO) into screen and screen color RAM.  There is no error checking; values outside of the valid ranges of 0<=SX<=39, 0<=SY<=24, 0<=CH<=255, and 0<=CO<=255 will result in an error or in the case of SX and SY, possibly lock up the computer or corrupt the program.

Next Step
Next, I'll be adding movement routines, first based on cursor keys and then based on joystick.

No comments:

Post a Comment