Maya Grab [Day 5] – First lines of code

After all preparations I’ve finally wrote some code. It’s just bunch of remarks (comments) and code organization things like I described three days ago. I’ve put all code segments together and at previously specified line numbers. For every code segment (data initialization, main game loop, subroutines, interpreter… etc) I took some time to think about the steps between two lines of code; remember, it’s not easy to shift code up and down in BASIC. I hope I’ve left enough space between lines for adding or modifying the code later.

I’m very satisfied how I’ve organized everything, I’m a huge fan of clean code (who isn’t). But what’s bothering me now is this article I’ve found here. It’s about optimizations in BASIC how to save memory and gain speed; clean but fast code can’t be easily achieved. I have to avoid jumping to code and subroutines at higher lines; failed, I’m already planning to use everything until line 63999. I have to put as many commands in one line as possible; failed, I plan to use max. 39 characters per line for easy code reading (the C64 supports 80 characters which is two lines, with some tricks you can pack even more). I have to remove spaces between commands; failed, I find such code hard to read. I have to remove the comments; failed, I’ve already have more than 300 lines of comments only, and the program still doesn’t do a single thing. I guess I’ll have to see during development how the game is performing and then try to do little optimizations which hopefully won’t hurt much.

Now comes the interesting part… I’ve decided, at the end of each coding day, to include the current source code and some statistics. It’s going to be very interesting to see how the game is making progress. And now the big surprise; the game is already over 4kb and I haven’t done a thing. In machine code only the last “END” command would be compiled, and the game would be probably 10 bytes long. Cool to know, what’s going to be removed first if I run out of memory.

Program size: 4672 bytes, on disk 4826 bytes or 19 blocks
Free BASIC memory: 34239 bytes
Used BASIC commands: REM, END

Source code

* * * * *