PONG2.SRC (9962B)
1 ; Note: this source has been modified by David WINTER on 17 SEP 1997 2 ; (only the syntax changed: it has been converted in CHIPPER) 3 ; 4 ; 99% of this source is taken from Paul Vervalin's PONG game. The only 5 ; changes are the position of the left paddle, and the vertical line on 6 ; the middle of the screen. This, to have a correct game under the MS-DOS 7 ; CHIP-8 emulator. Note that the modifications are quite archaic, as they 8 ; were hand-made (i.e: no assembler/disassembler). 9 ; 10 ; --------------------------------------------------------------------------- 11 ; 12 ; From: vervalin@AUSTIN.LOCKHEED.COM (Paul Vervalin) 13 ; 14 ; 15 ; OK folks here it is! PONG for the HP48SX written in CHIP-48. 16 ; Some things you should know before you start playing are... 17 ; 1) This is my first attempt at programming in CHIP-48, so I 18 ; know there are probably a few things that could have been 19 ; done better. 20 ; 2) The game never ends. It keeps score, but only up to 9 for 21 ; each player, then it will roll over to 0. Sorry, its the 22 ; only way I could think of to do it. So, you have to play 23 ; whoever gets to a number first, wins. 24 ; 3) It is kind of slow, but then there are two paddles and ball 25 ; moving around all at once. 26 ; 4) The player who got the last point gets the serve... 27 ; 5) Keys 7 and 4 (on the HP48) control the up and down of the 28 ; left player and the / and * keys control the up and down of 29 ; the right player. 30 ; 31 ; I think that's about it, so have fun! 32 ; 33 ; This is a detailed breakdown of the game, sooooooo, if anybody wants to 34 ; make it better, or change it in some way, it might be a little easier. 35 ; Also, about half of the code was in some way extracted from the BRIX 36 ; program. So, thanks to whoever wrote the original BRIX game. 37 ; 38 ; 39 ; Registers 40 ; --------- 41 ; V0-V3 are scratch registers 42 ; V4 X coord. of score 43 ; V5 Y coord. of score 44 ; V6 X coord. of ball 45 ; V7 Y coord. of ball 46 ; V8 X direction of ball motion 47 ; V9 Y direction of ball motion 48 ; VA X coord. of left player paddle 49 ; VB Y coord. of left player paddle 50 ; VC X coord. of right player paddle 51 ; VD Y coord. of right player paddle 52 ; VE Score 53 ; VF collision detection 54 55 56 option binary ; To assemble PONG for HP48 use, remove this option 57 58 59 CALL Middle ; Draws the vertical bar at center 60 61 LD VB, 12 ; Set left player Y coord. 62 LD VC, 63 ; Set right player X coord. 63 LD VD, 12 ; Set right player Y coord. 64 65 LD I, Paddle ; Get address of paddle sprite 66 DRW VA, VB, 6 ; Draw left paddle 67 DRW VC, VD, 6 ; Draw right paddle 68 69 LD VE, 0 ; Set score to 00 70 CALL Draw_Score ; Draw score 71 72 LD V6, 3 ; Set X coord. of ball to 3 73 LD V8, 2 ; Set ball X direction to right 74 75 76 Big_Loop: 77 78 LD V0, #60 ; Set V0=delay before ball launch 79 LD DT, V0 ; Set delay timer to V0 80 DT_loop: ; 81 LD V0, DT ; Read delay timer into V0 82 SE V0, 0 ; Skip next instruction if V0=0 83 JP DT_Loop ; Read again delay timer if not 0 84 85 RND V7, 23 ; Set Y coord. to rand # AND 23 (0...23) 86 ADD V7, 8 ; And adjust it to is 8...31 87 88 LD V9, #FF ; Set ball Y direction to up 89 LD I, Ball ; Get address of ball sprite 90 DRW V6, V7, 1 ; Draw ball 91 92 Padl_Loop: 93 LD I, Paddle ; Get address of paddle sprite 94 DRW VA, VB, 6 ; Draw left paddle 95 DRW VC, VD, 6 ; Draw right paddle 96 97 LD V0, 1 ; Set V0 to KEY 1 98 SKNP V0 ; Skip next instruction if KEY in 1 is not pressed 99 ADD VB, #FE ; Subtract 2 from Y coord. of left paddle 100 101 LD V0, 4 ; Set V0 to KEY 4 102 SKNP V0 ; Skip next instruction if KEY in 4 is not pressed 103 ADD VB, 2 ; Add 2 to Y coord. of left paddle 104 105 LD V0, 31 ; Set V0 to max Y coord. | These three lines are here to 106 AND VB, V0 ; AND VB with V0 | adjust the paddle position if 107 DRW VA, VB, 6 ; Draw left paddle | it is out of the screen 108 109 LD V0, #0C ; Set V0 to KEY C 110 SKNP V0 ; Skip next instruction if KEY in C is not pressed 111 ADD VD, #FE ; Subtract 2 from Y coord. of right paddle 112 113 LD V0, #0D ; Set V0 to KEY D 114 SKNP V0 ; Skip next instruction if KEY in D is not pressed 115 ADD VD, 2 ; Add 2 to Y coord. of right paddle 116 117 LD V0, 31 ; Set V0 to max Y coord. | These three lines are here to 118 AND VD, V0 ; AND VD with V0 | adjust the paddle position if 119 DRW VC, VD, 6 ; Draw right paddle | it is out of the screen 120 121 LD I, Ball ; Get address of ball sprite 122 DRW V6, V7, 1 ; Draw ball 123 124 ADD V6, V8 ; Compute next X coord of the ball 125 ADD V7, V9 ; Compute next Y coord of the ball 126 127 LD V0, 63 ; Set V0 to max X location 128 AND V6, V0 ; AND V6 with V0 129 130 LD V1, 31 ; Set V1 to max Y location 131 AND V7, V1 ; AND V7 with V1 132 133 SNE V6, 0 ; Skip next instruction if ball not at left 134 JP Left_Side ; 135 136 SNE V6, 63 ; Skip next instruction if ball not at right 137 JP Right_Side ; 138 139 Ball_Loop: 140 SNE V7, 31 ; Skip next instruction if ball not at bottom 141 LD V9, #FF ; Set Y direction to up 142 143 SNE V7, 0 ; Skip next instruction if ball not at top 144 LD V9, 1 ; Set Y direction to down 145 146 DRW V6, V7, 1 ; Draw ball 147 JP Padl_loop ; 148 149 Left_Side: 150 LD V8, 2 ; Set X direction to right 151 LD V3, 1 ; Set V3 to 1 in case left player misses ball 152 LD V0, V7 ; Set V0 to V7 Y coord. of ball 153 SUB V0, VB ; Subtract position of paddle from ball 154 JP Pad_Coll ; Check for collision 155 156 Right_Side: 157 LD V8, 254 ; Set X direction to left 158 LD V3, 10 ; Set V3 to 10 in case right player misses ball 159 LD V0, V7 ; Set V0 to V7 Y coord. of ball 160 SUB V0, VD ; Subtract position of paddle from ball 161 162 Pad_Coll: 163 SE VF, 1 ; Skip next instruction if ball not above paddle 164 JP Ball_Lost ; 165 166 LD V1, 2 ; Set V1 to 02 167 SUB V0, V1 ; Subtract V1 from V0 168 SE VF, 1 ; Skip next instr. if ball not at top of paddle 169 JP Ball_Top ; Ball at top of paddle 170 171 SUB V0, V1 ; Subtract another 2 from V0 172 SE VF, 1 ; Skip next instr. if ball not at middle of paddle 173 JP Pad_Hit ; Ball in middle of paddle 174 175 SUB V0, V1 ; Subtract another 2 from V0 176 SE VF, 1 ; Skip next instr. if ball not at bottom of paddle 177 JP Ball_Bot ; Ball at bottom of paddle 178 179 Ball_Lost: 180 LD V0, 32 ; Set lost ball beep delay 181 LD ST, V0 ; Beep for lost ball 182 183 CALL Draw_Score ; Erase previous score 184 ADD VE, V3 ; Add 1 or 10 to score depending on V3 185 CALL Draw_Score ; Write new score 186 187 LD V6, 62 ; Set ball X coord. to right side 188 SE V3, 1 ; Skip next instr. if right player got point 189 LD V6, 3 ; Set ball X coord. to left side 190 LD V8, #FE ; Set direction to left 191 SE V3, 1 ; Skip next instr. if right player got point 192 LD V8, 2 ; Set direction to right 193 JP Big_Loop ; 194 195 Ball_Top: 196 ADD V9, #FF ; Subtract 1 from V9, ball Y direction 197 SNE V9, #FE ; Skip next instr. if V9 != FE (-2) 198 LD V9, #FF ; Set V9=FF (-1) 199 JP Pad_Hit 200 201 Ball_Bot: 202 ADD V9, 1 ; Add 1 to V9, ball Y direction 203 SNE V9, 2 ; Skip next instr. if V9 != 02 204 LD V9, 1 ; Set V9=01 205 206 Pad_Hit: 207 LD V0, 4 ; Set beep for paddle hit 208 LD ST, V0 ; Sound beep 209 210 ADD V6, 1 ; 211 SNE V6, 64 ; 212 ADD V6, 254 ; 213 214 JP Ball_Loop 215 216 Draw_Score: 217 LD I, Score ; Get address of Score 218 LD B, VE ; Stores in memory BCD representation of VE 219 LD V2, [I] ; Reads V0...V2 in memory, so the score 220 LD F, V1 ; I points to hex char in V1, so the 1st score char 221 LD V4, #14 ; Set V4 to the X coord. to draw 1st score char 222 LD V5, 2 ; Set V5 to the Y coord. to draw 1st score char 223 DRW V4, V5, 5 ; Draw 8*5 sprite at (V4,V5) from M[I], so char V1 224 ADD V4, #15 ; Set X to the X coord. of 2nd score char 225 LD F, V2 ; I points to hex char in V2, so 2nd score char 226 DRW V4, V5, 5 ; Draw 8*5 sprite at (V4,V5) from M[I], so char V2 227 RET ; Return 228 229 Paddle: 230 DW #8080 231 DW #8080 232 DW #8080 233 234 Ball: 235 DW #8000 236 237 Score: 238 DW #0000 239 DW #0000 240 241 MiddleLine: 242 DW #C0C0 243 DW #C000 244 245 HorizLine: 246 DB #FF 247 248 Middle: 249 LD VB, 32 ; Set X coord. of middle line pixels 250 LD VC, 0 ; Set Y coord. of the first sprite to draw 251 LD I, MiddleLine ; I Points to the bitmap of the 6 pixels to draw 252 253 Draw_Middle: 254 DRW VB, VC, 4 ; Draw 4 pixels of the line 255 ADD VC, 4 ; Increments Y of the next 4 pixels sprite 256 SE VC, 32 ; End loop if last pixels drawn 257 JP Draw_Middle ; Else draw next pixels 258 259 LD VA, 0 ; Set VA to X location of horizontal lines 260 LD VB, 0 ; Set VB to Y location of upper horizontal line 261 LD VC, 31 ; Set VC to Y location of downer horizontal line 262 LD I, HorizLine ; I points on the bitmap of these lines... 263 264 Draw_Horiz: 265 DRW VA, VB, 1 ; Draw 8 pixels of the first horizontal line 266 DRW VA, VC, 1 ; Draw 8 pixels of the second horizontal line 267 ADD VA, 8 ; Increments Y of the next 8 pixels sprites 268 SE VA, 64 ; End loop if last pixels drawn 269 JP Draw_Horiz ; Else draw next pixels of the lines 270 271 LD I, MiddleLine ; I point again on the middle line sprite 272 LD VA, 0 ; Set player A (left side) X coord. 273 LD VB, 32 ; Set VB to first 2*1 sprite location of vertical line 274 DRW VB, VA, 1 ; Redraw this part which wad erased before... 275 276 RET ; Return to program start 277 ; VA must be set to 0, this has already been done.