VBRIX.SRC (12578B)
1 ; **************************************************************************** 2 ; **************************************************************************** 3 ; *** Vertical Brix v1.0 (C) Paul Robson 1996 *** 4 ; **************************************************************************** 5 ; **************************************************************************** 6 7 ; **************************************************************************** 8 ; 9 ; r7 lives 10 ; r8 score 11 ; r9 bat y 12 ; ra,rb location of ball 13 ; rc,rd direction of ball 14 ; re Number of brix remaining in wall 15 ; 16 ; **************************************************************************** 17 18 TopLine:equ 0 ; top line of breakout 19 BottomLine:equ 31 ; bottom line of breakout 20 LeftSide:equ 0 ; left side of game area 21 RightSide:equ 63 ; right side of game area 22 BrickX:equ 34 ; brick start 23 BrickXCt:equ 7 ; number of bricks across , x 24 BrickYCt:equ 10 ; and y 25 BatX: equ 2 ; bat x position 26 Sound: equ 1 ; 1 sound,0 nosound 27 KeyUp: equ 1 ; up key 28 KeyDown:equ 4 ; down key 29 KeyStart:equ 7 ; start key 30 31 cls 32 jsr Title 33 wstart: 34 mov v0,KeyStart ; wait for start 35 skpr v0 36 jmp wstart 37 38 begin: mov r8,0 ; score = 0 39 mov r7,3 ; lives = 3 40 jsr DrawBorder 41 jsr InitBat 42 jsr InitBall 43 jsr DrawBricks 44 jsr DrawScore 45 jsr DrawLives 46 key v0 47 loop: jsr MoveBat 48 jsr MoveBat 49 jsr MoveBall 50 jsr Collide 51 skeq ra,0 52 jmp loop 53 54 mov rc,1 ; ball back out 55 jsr DrawLives ; dec lives 56 add r7,-1 57 jsr DrawLives 58 59 mov r0,120 ; wait 2 secs 60 sdelay r0 61 wait: gdelay r0 62 skeq r0,0 63 jmp wait 64 65 skeq r7,0 66 jmp loop 67 jsr DrawLives ; erase lives,we've finished 68 69 mov r0,KeyStart 70 skpr r0 71 jmp .-2 72 jmp begin 73 halt 74 75 ; **************************************************************************** 76 ; *** initialise the bat *** 77 ; **************************************************************************** 78 InitBat:mov r9,16 79 mov v0,BatX 80 mvi BatSpr 81 sprite v0,v9,5 82 rts 83 BatSpr: db $10000000 84 db $10000000 85 db $10000000 86 db $10000000 87 db $10000000 88 ; **************************************************************************** 89 ; *** move the bat *** 90 ; **************************************************************************** 91 MoveBat:mov r0,KeyUp 92 skup r0 93 jmp MoveUp 94 mov r0,KeyDown 95 skup r0 96 jmp MoveDown 97 rts 98 99 MoveUp: mov r0,r9 ; move it up 100 add r0,-1 101 skne r0,TopLine 102 rts 103 jmp MoveIt 104 MoveDown: 105 mov r0,r9 ; move it down 106 add r0,1 107 skne r0,BottomLine-4 108 rts 109 jmp MoveIt 110 MoveIt: mov r1,BatX ; redraw the graphic 111 mvi BatSpr 112 sprite r1,r9,5 113 sprite r1,r0,5 114 mov r9,r0 ; do the move 115 rts 116 117 ; **************************************************************************** 118 ; *** has the bat hit the ball *** 119 ; **************************************************************************** 120 Collide:mov v0,va ; va (x) must be batx 121 add v0,-2 122 skeq v0,0 123 rts 124 mov v0,vb ; v0 = bally-baty 125 sub v0,v9 126 skne vf,0 ; if bally < baty exit 127 rts 128 mov v1,v0 ; if v0 >= 5 exit 129 mov v2,5 130 sub v1,v2 131 skeq vf,0 132 rts 133 mvi dirtab ; get the new y direction 134 adi v0 ; out of the table 135 ldr v0-v0 136 mov vd,v0 137 138 skne vb,TopLine+1 139 mov vd,1 140 skne vb,BottomLine-1 141 mov vd,-1 142 143 mov rc,1 ; bounce back out 144 mov r0,10*sound 145 ssound r0 146 rts 147 dirtab: db -1,-1,0,1,1 148 ; **************************************************************************** 149 ; *** initialise the ball register *** 150 ; **************************************************************************** 151 InitBall: 152 random vb,BottomLine-TopLine-1 153 add rb,TopLine+1 154 mov va,4 155 mov vc,1 156 mov vd,1 157 mvi Pixel 158 sprite va,vb,1 159 rts 160 ; **************************************************************************** 161 ; *** move the ball,bouncing off the walls *** 162 ; *** destroys v0,v1,v2,v3,v4 *** 163 ; **************************************************************************** 164 MoveBall: 165 mov v0,va ; save position in va,vb 166 mov v1,vb 167 add va,vc ; work out new position 168 add vb,vd 169 mvi Pixel 170 skne vb,TopLine+1 ; bounce off the walls 171 mov vd,1 172 skne vb,BottomLine-1 173 mov vd,-1 174 skne va,RightSide-1 175 mov vc,-1 176 177 skne va,0 ; DEBUGGING,NO LOSS OF BALL 178 mov vc,1 179 180 sprite v0,v1,1 ; Draw the ball,delete old ball 181 sprite va,vb,1 182 skne vf,0 ; ball has hit something - stop 183 rts 184 mov v0,va ; if hit the bat,pass ! 185 mov v1,brickx-1 ; if < brickx forget it ! 186 sub v0,v1 187 skne vf,0 188 rts 189 mov v0,va ; ball position in v0,v1 190 mov v1,vb 191 add v0,-brickx ; convert to ball coordinate 192 add v1,-topline-1 193 mov v2,-1 ; v2,v3 will be the ball location 194 mov v3,-1 ; in logical coordinates. 195 mov v4,3 196 div3x: add v2,1 ; divide v0 by 3 197 sub v0,v4 198 skeq vf,0 199 jmp div3x 200 div3y: add v3,1 201 sub v1,v4 202 skeq vf,0 203 jmp div3y 204 mov v0,v2 ; v0,v1 contain the ball coords (log) 205 mov v1,v3 206 add v0,v2 ; convert them to physical coords 207 add r0,r2 208 add v1,v3 209 add v1,v3 210 add v0,BrickX 211 add v1,TopLine+1 212 mvi Brick ; erase the brick 213 sprite v0,v1,3 214 add ve,-1 ; decrement bricks remaining counter 215 mov v0,0 ; bounce the ball 216 rsb vc,v0 ; xi = -xi 217 mov r0,2*sound 218 ssound r0 219 jsr DrawScore ; increment the score 220 add v8,1 221 jsr DrawScore 222 skeq ve,0 ; cleared the wall ? 223 rts 224 jsr DrawBricks ; redraw it 225 rts 226 227 ; **************************************************************************** 228 ; *** Draw the border *** 229 ; *** destroys r0,r1,r2,i *** 230 ; **************************************************************************** 231 DrawBorder: 232 cls ; start with a clear screen 233 mov v0,LeftSide ; (r0,r1) and (r0,r2) are start pos 234 mov v1,TopLine ; of the horizontal lines 235 mov v2,BottomLine 236 mvi Pixel 237 DBLoop: sprite v0,v1,1 ; draw the vertical lines 238 sprite v0,v2,1 239 add v0,1 240 skeq v0,RightSide 241 jmp DBLoop 242 DBLoop2:sprite v0,v1,1 ; draw the horizontal lines 243 add v1,1 244 skeq v1,BottomLine+1 245 jmp DBLoop2 246 rts 247 Pixel: db $10000000 ; pixel used for drawing walls. 248 ; **************************************************************************** 249 ; *** redraw all the bricks *** 250 ; *** destroys r0,r1,r2,r3,i *** 251 ; **************************************************************************** 252 DrawBricks: 253 mov v1,TopLine+1 254 mov v3,BrickYCt 255 mvi Brick 256 DBXLoop:mov v0,BrickX 257 mov v2,BrickXCt 258 DBXLp2: sprite v0,v1,3 259 add v0,3 260 add v2,-1 261 skeq v2,0 262 jmp DBXLp2 263 add v1,3 264 add v3,-1 265 skeq v3,0 266 jmp DBXLoop 267 mov ve,BrickXCt*BrickYCt 268 rts 269 Brick: db $11100000 270 db $10100000 271 db $11100000 272 ; **************************************************************************** 273 ; *** Draw the score (in r8) *** 274 ; **************************************************************************** 275 DrawScore: 276 mvi Temp 277 bcd v8 278 ldr v0-v2 279 mov v3,3 280 mov v4,TopLine+2 281 font v0 282 sprite v3,v4,5 283 add v3,5 284 font v1 285 sprite v3,v4,5 286 add v3,5 287 font v2 288 sprite v3,v4,5 289 rts 290 Temp: dw 0,0,0 291 ; **************************************************************************** 292 ; *** draw the number of lives *** 293 ; **************************************************************************** 294 DrawLives: 295 mov r0,20 296 mov r1,TopLine+2 297 font r7 298 sprite r0,r1,5 299 rts 300 ; **************************************************************************** 301 ; *** draw the title *** 302 ; **************************************************************************** 303 Title: mov r0,10 304 mov r1,12 305 mov r2,9 306 mov r3,5 307 mvi TitleSpr 308 TtlLoop:sprite r0,r1,5 309 adi r3 310 add r0,5 311 add r2,-1 312 skeq r2,0 313 jmp TtlLoop 314 rts 315 TitleSpr: 316 db $10010000 317 db $10010000 318 db $10010000 319 db $10010000 320 db $01100000 321 322 db $11100000 323 db $10010000 324 db $11100000 325 db $10010000 326 db $11100000 327 328 db $11100000 329 db $10010000 330 db $11100000 331 db $10010000 332 db $10010000 333 334 335 db $00100000 336 db $00100000 337 db $00100000 338 db $00100000 339 db $00100000 340 341 db $10010000 342 db $10010000 343 db $01100000 344 db $10010000 345 db $10010000 346 347 db $00000000 348 db $00000000 349 db $01100000 350 db $00000000 351 db $00000000 352 353 db $11110000 354 db $10010000 355 db $11110000 356 db $10000000 357 db $10000000 358 359 db $11110000 360 db $10000000 361 db $11110000 362 db $00010000 363 db $11110000 364 365 db $11100000 366 db $10010000 367 db $11100000 368 db $10010000 369 db $10010000 370 371