The Commodore 64 Game Screen
Although, the Commodore 64C Game Marathon video does not discuss this, I wanted to start up by explaining how the screen works. If you look closer at the Commodore 64 screen you will discover it is made up of small tiny dots. These are known as pixels. Pixels represent the screen display in a matrix of 8×8 characters. That’s 8 character’s in height, and 8 character wide. Each pixel can be turned on or off and displayed in any 16 colors. The only except though is that only 4 colors can be occupied for each matrix (block).
Commodore 64 Character Base ROM
The screen display stores the data contained there in what is known as the Character Base ROM. Since this character set is protected in ROM (Read Only Memory), in order to write to it so we can change the characters, we have to transfer the data from ROM to RAM.
This is accomplished by copying the data contained there in memory back to a safe place in the Commodore 64’s memory. In my Commodore 64C Game Marathon program, it is actually utilizing a machine language subroutine to take care of this.
Please note, this is also possible in Commodore 64 Basic using a FOR/NEXT loop, but it is very slow and the best performance is done by speaking directly in the Commodore 64’s native language, also known as Assembly Language. Be sure to check out my other website programmermind to learn even more about the machine language.
Since this is a ‘Basic’ tutorial, at this time I won’t disassemble the code that manages to move the character set data from ROM to RAM. However, it a later tutorial, I do plan on showing how this was done.
Commodore 64 Program Explanation
To stay consistent with the Commodore 64C Game Marathon series in session, I have placed the regular variables in the program as seen and defined below in line 35. Variables like these are commonly found in older RPG (Role Playing Games) to track statistics of the player and game progress in general.
35 SS=320:DX=250:IN=200:SK=1:PO=1:KN=3:EX=15
SS = 320 – Strength of Player
DX = 250 – Dexterity of Player
IN = 200 – Intelligence of Player
SK = 1 – Skill of Player
PO = 1 – Potions carried by Player
KN = 1 – Knowledge of Player
EX = 1 – Experience of Player
After this we have to set up an area of memory for our Commodore 64C Game Marathon example that will handle the data for our map. So line 45 creates what is known as “dimensioning a string’. I have set aside 32 bytes to hold memory for the string statements contained later in the program.
45 DIM M$(32)
In line 50 the screen is cleared, a string variable called NM$ hold text for the word ‘SOLDIER’, a second string variable for RN$ holds text for ‘OFFICER’, and a third string variable for MT$ holds text for the word ‘NONE’. These are listed below and an explanation is provided.
50 PRINT”{clear screen}”:NM$=”SOLDIER”:RN$=”OFFICER”:MT$=”NONE”
NM$ = This tracks the type of character we start with. So we begin the game off with the character as a Soldier.
RN$ = This assigns a specific rank for our Commodore 64C Game Marathon character. In the beginning the rank is an OFFICER, but can be upgraded as skills improve and enemies are defeated.
MT$ = This is our Threat Meter. It starts off as ‘NONE’, but will be replaced with the monster’s name in range as we come into contact with various arch rivals in the adventure.
Position Commodore 64C Game Marathon Text
Next we assign a string variable for PP$. This works by evaluating each character in this variable when it is used with a PRINT statement. I am using this to position the text to the right of the character game map. The ‘S’ will place the cursor at the top of the screen. Then the 3 ‘Q’ values will move the cursor down three lines. Then we use 32 values for ‘]’ to move the character over to the right 32 times. Since this is utilizing a move it does not erase any characters already contained on the screen.
52 PP$=”SQQQ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]”
Next we jump to line 9000, then line 1000, and next line 6000. The GOSUB will return back the same line and read the following statement proceeding the ‘:’ character. Let’s examine these lines below as listed in the Commodore 64C Game Marathon program.
60 GOSUB9000:GOSUB1000:GOSUB6000
Within lines 9000-9070 we are writing our game data statistics to disk and returning back to line 60
9000 OPEN2,8,2,”@0:ROLEDATA,S,W”
9010 PRINT#2,NM$:PRINT#2,RN$
9020 PRINT#2,SS:PRINT#2,DX
9030 PRINT#2,IN:PRINT#2,SK
9040 PRINT#2,PO:PRINT#2,KN
9050 PRINT#2,EX
9060 CLOSE2
9070 RETURN
The next GOSUB 1000 wil jump to line 1000. First it defines screen colors, multicolor characters, and resets the multicolor mode in line 1000.
1000 POKE53280,0:POKE53281,0:POKE53282,2:POKE53283,7:POKE53270,200
Then in LINE 1010 it uses a FOR/NEXT statement to setup an area in memory to write data to the Commodore 64C Game Marathon memory for our routine, which will move the character set from ROM to RAM. Then it peforms the move with the command SYS 49152 from the starting address.
Line 1020 reads the DATA, and continues to append the values in memory until it encounters a value set to -1 and then it will exit back to line 60.
Commodore 64 Screen Character Data
Essentially this READ is reading the DATA statements starting at line 2040 and occupying them in specific pockets in memory that will write new data to our character set. This is what allows us to recreate our our screen display for the Commodore 64C Game Marathon game. This statement will locate our PET ASCII character for the ‘#’ and change the data contained there to create the wall character seen on the screen map display.
2050 DATA35,251,251,251,0,191,191,191,0
Finally line 1040 keeps the READ going in a loop until all the 57 values (0 to 57) have been accounted for.
1010 FORX=0TO57:READDT:POKE49152+X,DT:NEXT:SYS49152
1020 READA:IFA=-1THENRETURN
1030 FORX=0TO7:READD:POKE12288+A*8+X,D:NEXT
1040 GOTO1020
Finally I have listed out all the character data below for your reference.
2040 DATA0,0,1,7,7,28,28,124,124
2045 DATA31,60,102,110,110,96,98,60,0
2050 DATA35,251,251,251,0,191,191,191,0
2060 DATA36,0,60,123,238,91,190,107,20
2070 DATA37,69,80,81,84,85,21,20,81
2080 DATA38,20,20,20,20,85,20,20,20
2090 DATA39,28,28,24,28,28,62,62,62
2100 DATA40,94,93,28,20,20,20,52,38
2110 DATA41,243,196,15,60,48,195,207,15
2120 DATA42,0,20,16,68,4,80,4,0
2130 DATA43,4,4,85,92,28,68,0,81
2140 DATA44,4,0,65,0,4,64,0,17
3000 DATA-1
Now I show the PET ASCII character assigned and each were changed into.
2040 0 = @ : Currently unused
2045 31 = (arrow) : Currently unused
2050 35 = # : Changes into a wall character
2060 36 = $ : Top character of the tree
2070 37 = % : Bottom half of the tree (trunk)
2080 38 = & : Sword character
2090 39 = ‘ : Top half of the man at the Rest Manor
2100 40 = ( : Bottom half of the man at the Rest Manor
2110 41 = ) : River character
2120 42 = * : Scattered stones
2130 43 = + : Background of wall in Rest Manor
2140 44 = , : Scattered stones around tree trunk
The string data contained in lines 6000 forward read in the game character map that is seen on the screen display.
6000 M$(1)=”U###########################
#I”
6010 M$(2)=”#####V.V++++,#+++,++++V.V###
##
6020 M$(3)=”####VV+’++,,,#++++++,+++VV##
##
6030 M$(4)=”##++++ ( +++,#+++++++++++LLL
##
6040 M$(5)=”## # JK JK LL
##
6050 M$(6)=”## # L
##
6060 M$(7)=”## ###############
##
6070 M$(8)=”##### Q Q ####
##
6080 M$(9)=”##rest# ##UCI
##
6090 M$(10)=”#manor## ####T
H##
6200 M$(11)=”#########################T
H##
6210 M$(12)=”T $$$ $$$ $$$
H
6220 M$(13)=”T $$$ % % %
H
6230 M$(14)=”T %
H
6240 M$(15)=”T $$$ $$$ , $$$ $$$
H
6250 M$(16)=”T % , % % %
H
6260 M$(17)=”T $$$ ** $$$ $$$
H
6270 M$(18)=”T ** % * *, % * %
H
6280 M$(19)=”T ,+, + + + ,
H
6290 M$(20)=”T
H
6280 M$(19)=”T ,+, + + + ,
H
6290 M$(20)=”T
H
6300 M$(21)=”T)))))))))))*))))))))*)))))
))H
6310 M$(22)=”T))))))*)))))))),))))))))))
))H
6320 M$(23)=”J##########################
##K
7000 RETURN
Scanning a Commodore 64 String Array
After this lines 80-92 will read through the data string array M$ and search for certain characters to plant the graphics seen on the screen. The MID$ stands for ‘middle string’ and looks at the data contained within the variable found there so you can extract data from it. I am also using this to change color values as seen on line 88.
80 form=1to23:forl=1to30
81 ms$=mid$(m$(m),l,1)
82 poke646,10
84 ifms$=”%”thenpoke646,10
85 ifms$=”$”thenpoke646,13
86 ifms$=”)”thenpoke646,14
87 ifms$=”+”thenpoke646,8
88 ifms$=”‘”orms$=”(“thenpoke646,13
89 if asc(ms$)>64 and asc(ms$)<91 then p
oke646,1
90 printms$;
92 next:print:next
The following lines below print the game statistics that are seen to the right of the character map. Finally the Commodore 64C Game Marathon is suspended at line 902 to keep the display on the screen.
95 poke646,1:printpp$”dx:”dx:printpp$”qi
n:”in
96 printpp$”qqsk:”sk:printpp$”qqqpo:”po
97 printpp$”qqqkn:”kn
98 printpp$”qqqqqeload”:printpp$”qqqqqqe
save”
99 printpp$”qqqqqqqqqfight”
100 printpp$”qqqqqqqqqqspeak”
105 printpp$”qqqqqqqqqqqeat”
106 printpp$”qqqqqqqqqqqqlook”
107 printpp$”qqqqqqqqqqqqqq#######
108 printpp$”qqqqqqqqqqqqqqq%%%%%%%
109 printpp$”qqqqqqqqqqqqqqqqthreat:”
110 printpp$”qqqqqqqqqqqqqqqqq”tab(2)mt$
120 printpp$”qqqqqqqqqqqqqqqqqqq%%%%%%%
130 printpp$”qqqqqqqqqqqqqqqqqq%%%%%%%
140 printpp$”qqqqqqqqqqqqqqqqqqq#######
141 print”s”
902 goto 902
Get Connected!
Come and join our community. Expand your network and get to know new people!
No posts found.
No posts found.
Nothing more to show.