What better way to keep busy while having a bacterial throat and nose infection than to play around with an old programming language? So I created a simple screensaver today that should give you a warm old school computer feeling while you are not busy working at the computer. The program should run fine on the C64 and with minimal modifications on other computers supporting Commodore/Microsoft Basic.
Please find the ASCII and PRG file of the source code at https://github.com/jklingel/Screensaver. There is also a readme file for more explanations on how the code works. Feel free to modify and improve!
If you are technically interested in how the software works… The heart of the program (of version 1.2) looks like this, using an attempt to move to the right as an example:
- If you reached the rightmost screen column already, remember that moving right is not possible and return:
IF (LO+1)/40=INT((LO+1)/40)THEN MV(4)=1:RETURN
- If the next cell to the right has been already visited, remember that moving right is not possible and return:
IF PEEK(S+LO+1)=CH THEN MV(4)=1:RETURN
- If you are moving into a dead end, remember that moving right is not possible and return. A dead end is defined by having a visited cell up, down, and two steps ahead. It almost feels like machine learning 🙂 This command line needed the spaces removed as I reached the maximum of 80 characters. I added them here for readability:
IF PEEK(S+LO-39)=CH AND PEEK(S+LO+41)=CH AND PEEK(S+LO+2) THEN MV(4)=1:RETURN
- Set the location pointer one step to the right, print the character in the screen cell, increment the „cells visited“ counter, delete the „I cannot move“ array, and return:
FOR I=1TO4:MV(I)=0:NEXT I
Eine Antwort auf „Screensaver in Commodore BASIC V2.0“
I just committed a new version 1.1 to GitHub that contains valuable advice from Alex Johnson of the Facebook Commodore 64/128 Programming group. Basically he said:
1) Don´t use the command LET
2) Eliminate spaces where possible (I left many in so that the code is more readable for me)
3) Keep the variable names only one or two characters long and explain them somewhere (I did so at the end of the program)
4) The array named „V“ of version 1.0 is not needed, as one can peek the content of a screen memory cell instead (bummer, this was a beginner mistake I made).