Because some times, I just don't have anything better to do

RetroChallenge #3, part 3, Changes…


After going over the code of the old Aliens game, I started reorganizing it a bit.
For this, I set up an emulator to “Print to a text file”, and then listed the program to the “printer”.
After some Copy-Pasting (and line number changing), I moved the lines that create the graphics to the end of the code. This way, the main loop ended up between the 10th and 30th line, instead of around the 80th to 100th. This already makes it faster because of the way the infamous GOTO command works.
While doing this, I noticed that I was initializing some variables that are never used, and that there was provision for up to 50 aliens in one level!
I don’t think that fixing that gave me any extra speed, but at least there is no waste of memory as before.
Then, for the hardest part.
The lines in main loop had to be rearranged to have all the graphics drawn in the graphics page that is not being displayed. Then, copy that page to the one in the screen, do the math, delete the sprites that are going to move in the first page, and loop back to drawing the sprites.
I think I kind of sorted that out in a decent way, but there might still be room for improvement.
Then came code compacting.
Again, in Notepad++, I started looking at lines that could be crammed into a single one.
For example:

420 PR=1
430 COLOR 1
440 PMODE 4,1
450 LINE(Q*8,Z*8)-(Q*8+8,Z*8+8),PSET,BF
460 PMODE 4,5:SCREEN 1,0
470 PLAY”O4;L8;C;L16O3BL32AL8GL16FL8ED”
480 S=S+25
490 RETURN
Became
420 PR=1:COLOR1:PMODE 4,1:LINE(Q*8,Z*8)-(Q*8+8,Z*8+8),PSET,BF:PMODE 4,5:SCREEN 1,0:PLAY”O4;L8;C;L16O3BL32AL8GL16FL8ED”:S=S+25:RETURN

The risk here is that you may delete a line that is referenced in a GOTO or GOSUB, That is why I always keep a backup of “uncompacted” listing, in case I need to figure out where something used to be.
After all looks good, I take the file into a disk image using either IMGTOOL from MAME or with Toolsheed
With this, the program went from 132 lines to 100.
At this point, code was probably as neat and fast as I would get it without a major rewrite, and that was not the goal.
The flicker is, of course, gone. But sometimes, when more than 2 aliens move at the same time, you can tell that it is slowing down. Perhaps I should change it to have only one alien move in each cycle?
I’ll move on, make some minor changes to the look of the game, and then come back to that thought.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s