PONG.SRC (8301B)
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 ; The source could be optimized to save some bytes, but I didn't wanted 5 ; to modify it since there is no specific interest in this. 6 ; 7 ; NOTE THAT THE ORIGINAL SOURCE HAD SEVERAL ERRORS !!! 8 ; 9 ; --------------------------------------------------------------------------- 10 ; 11 ; From: vervalin@AUSTIN.LOCKHEED.COM (Paul Vervalin) 12 ; 13 ; 14 ; OK folks here it is! PONG for the HP48SX written in CHIP-48. 15 ; Some things you should know before you start playing are... 16 ; 1) This is my first attempt at programming in CHIP-48, so I 17 ; know there are probably a few things that could have been 18 ; done better. 19 ; 2) The game never ends. It keeps score, but only up to 9 for 20 ; each player, then it will roll over to 0. Sorry, its the 21 ; only way I could think of to do it. So, you have to play 22 ; whoever gets to a number first, wins. 23 ; 3) It is kind of slow, but then there are two paddles and ball 24 ; moving around all at once. 25 ; 4) The player who got the last point gets the serve... 26 ; 5) Keys 7 and 4 (on the HP48) control the up and down of the 27 ; left player and the / and * keys control the up and down of 28 ; the right player. 29 ; 30 ; I think that's about it, so have fun! 31 ; 32 ; This is a detailed breakdown of the game, sooooooo, if anybody wants to 33 ; make it better, or change it in some way, it might be a little easier. 34 ; Also, about half of the code was in some way extracted from the BRIX 35 ; program. So, thanks to whoever wrote the original BRIX game. 36 ; 37 ; 38 ; Registers 39 ; --------- 40 ; V0-V3 are scratch registers 41 ; V4 X coord. of score 42 ; V5 Y coord. of score 43 ; V6 X coord. of ball 44 ; V7 Y coord. of ball 45 ; V8 X direction of ball motion 46 ; V9 Y direction of ball motion 47 ; VA X coord. of left player paddle 48 ; VB Y coord. of left player paddle 49 ; VC X coord. of right player paddle 50 ; VD Y coord. of right player paddle 51 ; VE Score 52 ; VF collision detection 53 54 55 option binary ; To assemble PONG for HP48 use, remove this option 56 57 58 LD VA, 2 ; Set left player X coord. 59 LD VB, 12 ; Set left player Y coord. 60 LD VC, 63 ; Set right player X coord. 61 LD VD, 12 ; Set right player Y coord. 62 63 LD I, Paddle ; Get address of paddle sprite 64 DRW VA, VB, 6 ; Draw left paddle 65 DRW VC, VD, 6 ; Draw right paddle 66 67 LD VE, 0 ; Set score to 00 68 CALL Draw_Score ; Draw score 69 70 LD V6, 3 ; Set X coord. of ball to 3 71 LD V8, 2 ; Set ball X direction to right 72 73 74 Big_Loop: 75 76 LD V0, #60 ; Set V0=delay before ball launch 77 LD DT, V0 ; Set delay timer to V0 78 DT_loop: ; 79 LD V0, DT ; Read delay timer into V0 80 SE V0, 0 ; Skip next instruction if V0=0 81 JP DT_Loop ; Read again delay timer if not 0 82 83 RND V7, 23 ; Set Y coord. to rand # AND 23 (0...23) 84 ADD V7, 8 ; And adjust it to is 8...31 85 86 LD V9, #FF ; Set ball Y direction to up 87 LD I, Ball ; Get address of ball sprite 88 DRW V6, V7, 1 ; Draw ball 89 90 Padl_Loop: 91 LD I, Paddle ; Get address of paddle sprite 92 DRW VA, VB, 6 ; Draw left paddle 93 DRW VC, VD, 6 ; Draw right paddle 94 95 LD V0, 1 ; Set V0 to KEY 1 96 SKNP V0 ; Skip next instruction if KEY in 1 is not pressed 97 ADD VB, #FE ; Subtract 2 from Y coord. of left paddle 98 99 LD V0, 4 ; Set V0 to KEY 4 100 SKNP V0 ; Skip next instruction if KEY in 4 is not pressed 101 ADD VB, 2 ; Add 2 to Y coord. of left paddle 102 103 LD V0, 31 ; Set V0 to max Y coord. | These three lines are here to 104 AND VB, V0 ; AND VB with V0 | adjust the paddle position if 105 DRW VA, VB, 6 ; Draw left paddle | it is out of the screen 106 107 LD V0, #0C ; Set V0 to KEY C 108 SKNP V0 ; Skip next instruction if KEY in C is not pressed 109 ADD VD, #FE ; Subtract 2 from Y coord. of right paddle 110 111 LD V0, #0D ; Set V0 to KEY D 112 SKNP V0 ; Skip next instruction if KEY in D is not pressed 113 ADD VD, 2 ; Add 2 to Y coord. of right paddle 114 115 LD V0, 31 ; Set V0 to max Y coord. | These three lines are here to 116 AND VD, V0 ; AND VD with V0 | adjust the paddle position if 117 DRW VC, VD, 6 ; Draw right paddle | it is out of the screen 118 119 LD I, Ball ; Get address of ball sprite 120 DRW V6, V7, 1 ; Draw ball 121 122 ADD V6, V8 ; Compute next X coord of the ball 123 ADD V7, V9 ; Compute next Y coord of the ball 124 125 LD V0, 63 ; Set V0 to max X location 126 AND V6, V0 ; AND V6 with V0 127 128 LD V1, 31 ; Set V1 to max Y location 129 AND V7, V1 ; AND V7 with V1 130 131 SNE V6, 2 ; Skip next instruction if ball not at left 132 JP Left_Side ; 133 134 SNE V6, 63 ; Skip next instruction if ball not at right 135 JP Right_Side ; 136 137 Ball_Loop: 138 SNE V7, 31 ; Skip next instruction if ball not at bottom 139 LD V9, #FF ; Set Y direction to up 140 141 SNE V7, 0 ; Skip next instruction if ball not at top 142 LD V9, 1 ; Set Y direction to down 143 144 DRW V6, V7, 1 ; Draw ball 145 JP Padl_loop ; 146 147 Left_Side: 148 LD V8, 2 ; Set X direction to right 149 LD V3, 1 ; Set V3 to 1 in case left player misses ball 150 LD V0, V7 ; Set V0 to V7 Y coord. of ball 151 SUB V0, VB ; Subtract position of paddle from ball 152 JP Pad_Coll ; Check for collision 153 154 Right_Side: 155 LD V8, 254 ; Set X direction to left 156 LD V3, 10 ; Set V3 to 10 in case right player misses ball 157 LD V0, V7 ; Set V0 to V7 Y coord. of ball 158 SUB V0, VD ; Subtract position of paddle from ball 159 160 Pad_Coll: 161 SE VF, 1 ; Skip next instruction if ball not above paddle 162 JP Ball_Lost ; 163 164 LD V1, 2 ; Set V1 to 02 165 SUB V0, V1 ; Subtract V1 from V0 166 SE VF, 1 ; Skip next instr. if ball not at top of paddle 167 JP Ball_Top ; Ball at top of paddle 168 169 SUB V0, V1 ; Subtract another 2 from V0 170 SE VF, 1 ; Skip next instr. if ball not at middle of paddle 171 JP Pad_Hit ; Ball in middle of paddle 172 173 SUB V0, V1 ; Subtract another 2 from V0 174 SE VF, 1 ; Skip next instr. if ball not at bottom of paddle 175 JP Ball_Bot ; Ball at bottom of paddle 176 177 Ball_Lost: 178 LD V0, 32 ; Set lost ball beep delay 179 LD ST, V0 ; Beep for lost ball 180 181 CALL Draw_Score ; Erase previous score 182 ADD VE, V3 ; Add 1 or 10 to score depending on V3 183 CALL Draw_Score ; Write new score 184 185 LD V6, 62 ; Set ball X coord. to right side 186 SE V3, 1 ; Skip next instr. if right player got point 187 LD V6, 3 ; Set ball X coord. to left side 188 LD V8, #FE ; Set direction to left 189 SE V3, 1 ; Skip next instr. if right player got point 190 LD V8, 2 ; Set direction to right 191 JP Big_Loop ; 192 193 Ball_Top: 194 ADD V9, #FF ; Subtract 1 from V9, ball Y direction 195 SNE V9, #FE ; Skip next instr. if V9 != FE (-2) 196 LD V9, #FF ; Set V9=FF (-1) 197 JP Pad_Hit 198 199 Ball_Bot: 200 ADD V9, 1 ; Add 1 to V9, ball Y direction 201 SNE V9, 2 ; Skip next instr. if V9 != 02 202 LD V9, 1 ; Set V9=01 203 204 Pad_Hit: 205 LD V0, 4 ; Set beep for paddle hit 206 LD ST, V0 ; Sound beep 207 208 ADD V6, 1 ; 209 SNE V6, 64 ; 210 ADD V6, 254 ; 211 212 JP Ball_Loop 213 214 Draw_Score: 215 LD I, Score ; Get address of Score 216 LD B, VE ; Stores in memory BCD representation of VE 217 LD V2, [I] ; Reads V0...V2 in memory, so the score 218 LD F, V1 ; I points to hex char in V1, so the 1st score char 219 LD V4, #14 ; Set V4 to the X coord. to draw 1st score char 220 LD V5, 0 ; Set V5 to the Y coord. to draw 1st score char 221 DRW V4, V5, 5 ; Draw 8*5 sprite at (V4,V5) from M[I], so char V1 222 ADD V4, #15 ; Set X to the X coord. of 2nd score char 223 LD F, V2 ; I points to hex char in V2, so 2nd score char 224 DRW V4, V5, 5 ; Draw 8*5 sprite at (V4,V5) from M[I], so char V2 225 RET ; Return 226 227 Paddle: 228 DW #8080 229 DW #8080 230 DW #8080 231 232 Ball: 233 DW #8000 234 235 Score: 236 DW #0000 237 DW #0000