8

a CHIP-8 emulator
Log | Files | Refs | README

BREAKOUT.SRC (7834B)


      1 ; This variant of BRIX, calles BREAKOUT, has larger bricks,
      2 ; making a wall like the BREAKOUT game on the Atari 2600.
      3 ; The only difference with brix is the brick sprite.
      4 ;
      5 ; Note: source of BRIX has been modified by David WINTER on 17 SEP 1997
      6 ;       (only the syntax changed: it has been converted in CHIPPER)
      7 ;
      8 ; The source could be optimized to save some bytes, but I didn't wanted
      9 ; to modify it since there is no specific interest in this.
     10 ;
     11 ; NOTE THAT THE ORIGINAL SOURCE HAD SEVERAL ERRORS !!!
     12 ;
     13 ; ------------------------------------------------------
     14 ;
     15 ; Author: vervalin@AUSTIN.LOCKHEED.COM (Paul Vervalin)
     16 ;
     17 ;   register          contents
     18 ; ------------------------------------------------------
     19 ;    V0        scratch
     20 ;    V1        scratch
     21 ;    V2        scratch
     22 ;    V3        X coordinate of score
     23 ;    V4        Y coordinate of score
     24 ;    V5        bricks hit counter
     25 ;    V6        ball X coordinate
     26 ;    V7        ball Y coordinate
     27 ;    V8        ball X direction
     28 ;    V9        ball Y direction
     29 ;    VA        X coordinate when generating bricks
     30 ;    VB        Y coordinate when generating bricks
     31 ;    VC        paddle X coordinate
     32 ;    VD        paddle Y coordinate
     33 ;    VE        ball counter
     34 ;    VF        collision detect
     35 
     36 option binary  ; If you compile for HP48 use, remove this line
     37 
     38 
     39 
     40     LD  VE, 5   ; Set number of balls to 5
     41     LD  V5, 0   ; Initial number of hit bricks is 0
     42     LD  VB, 6   ; Set Y position of first brick to draw
     43 
     44 Draw_Bricks:
     45     LD  VA, 0   ; Set X position of first brick to draw
     46 
     47 Draw_Brick_Row:
     48     LD  I, Brick    ; I points on the brick sprite
     49     DRW VA, VB, 1   ; Draw brick
     50     ADD VA, 4       ; Move along X to next brick location
     51     SE  VA, 64      ; If location wrapped goto next row
     52     JP  Draw_Brick_Row ; Otherwise draw another
     53 
     54     ADD VB, 2       ; Move down Y to next row
     55     SE  VB, #12     ; If all rows drawn, continue on
     56 
     57     JP  Draw_Bricks ; Otherwise draw next row
     58 
     59     LD  VC, 32      ; Set X location of paddle
     60     LD  VD, 31      ; Set Y location of paddle
     61     LD  I,  Paddle  ; Get address of paddle sprite
     62     DRW VC, VD, 1   ; Draw paddle
     63 
     64     CALL Draw_Score ; Call subroutine to draw score
     65 
     66     LD  V0, 0     ; Set X coord of balls remaining
     67     LD  V1, 0     ; Set Y coord of balls remaining
     68     LD  I,  Balls ; I points on balls sprite
     69     DRW V0, V1, 1 ; Draw 4 of the five balls
     70     ADD V0, 8     ; Set X location of the 5th ball sprite
     71     LD  I,  Ball  ; I points on ball sprite
     72     DRW V0, V1, 1 ; Draw 5th ball
     73 
     74 Play:
     75     LD  V0, #40 ; Set V0 for delay
     76     LD  DT, V0  ; Set delay timer
     77 Wait:
     78     LD  V0, DT  ; Check status of delay timer
     79     SE  V0, 0   ; Skip next if delay timer is 0
     80     JP  Wait    ; Check again
     81 
     82     RND V6, #0F ; Get random coord for ball start
     83     LD  V7, 30  ; Set Y coord of ball start
     84     LD  V8, 1   ; Set X direction to RIGHT
     85     LD  V9, #FF ; Set Y direction to UP
     86 
     87     LD  I,  Ball  ; I points on single ball sprite
     88     DRW V6, V7, 1 ; Draw ball
     89 
     90 Loop:
     91     LD  I, Paddle ; Get address of paddle sprite
     92     DRW VC, VD, 1 ; Draw paddle at loc. VC VD
     93 
     94     LD  V0, 04  ; Set V0 to key 4
     95     SKNP V0     ; Skip next if key V0 not pressed
     96     ADD VC, #FE ; Move paddle two pixels left
     97 
     98     LD  V0, 06  ; Set V0 to key 6
     99     SKNP V0     ; Skip next if key V0 not pressed
    100     ADD VC, 2   ; Move paddle two pixels right
    101 
    102     LD  V0, #3F ; Set V0 right edge of screen
    103     AND VC, V0  ; Wrap paddle around if needed
    104     DRW VC, VD, 1 ; Draw paddle
    105 
    106     LD  I,  Ball   ; Get address of ball sprite
    107     DRW V6, V7, 1  ; Draw ball
    108     ADD V6, V8     ; Move ball in X direction by V8
    109     ADD V7, V9     ; Move ball in Y direction by V9
    110 
    111     LD  V0, 63  ; Set highest X coord.
    112     AND V6, V0  ; AND ball X pos. with V0
    113 
    114     LD  V1, 31  ; Set highest Y coord
    115     AND V7, V1  ; AND ball Y pos. with V1
    116 
    117     SNE V7, 31  ; If ball not at bottom, skip
    118     JP  Bottom  ; Else check for paddle pos
    119 
    120 
    121 Check_Paddle:
    122     SNE V6, 0   ; If ball not at left side, skip
    123     LD  V8, 1   ; Set X direction to RIGHT
    124 
    125     SNE V6, 63  ; If ball not at right side, skip
    126     LD  V8, #FF ; Set X direction to LEFT
    127 
    128     SNE V7, 0   ; If ball not at top, skip
    129     LD  V9, 1   ; Set Y direction to DOWN
    130 
    131     DRW V6, V7, 1 ; Draw ball
    132     SE  VF, 1     ; If there was a collision, skip
    133     JP  Brick_Untouched
    134 
    135     SNE V7, 31  ; If ball not at bottom skip
    136     JP  Brick_Untouched
    137 
    138     LD  V0, 5   ; Set V0 for 5 lines at screen top
    139     SUB V0, V7  ; Check if ball was in this region
    140     SE  VF, 0   ; If it was not then skip
    141     JP  Brick_Untouched
    142 
    143     LD  V0, 1   ; There was a collision
    144     LD  ST, V0  ; So beep
    145 
    146     LD  V0, V6  ; Get X coord of ball
    147     LD  V1, #FC ; Compute postion of the brick
    148     AND V0, V1  ; which was hit
    149 
    150     LD  I, Brick    ; I points on brick sprite
    151     DRW V0, V7, 1   ; Erase brick sprite by drawing
    152     LD  V0, #FE     ; reverse the Y direction of the
    153     XOR V9, V0      ; ball sprite
    154 
    155     CALL Draw_Score ; Call subroutine to draw score
    156     ADD V5, 1       ; Increments bricks hit counter by one
    157     CALL Draw_Score ; Call subroutine to draw score
    158 
    159     SNE V5, 96   ; If all bricks have not been hit, skip
    160     JP  Over     ; Else game ends, so stop
    161 
    162 
    163 Brick_Untouched:
    164     JP  Loop
    165 
    166 Bottom:
    167     LD  V9, #FF ; Ball is at bottom, so set direction to UP
    168     LD  V0, V6  ; Get X location of ball
    169     SUB V0, VC  ; Intersect with paddle
    170     SE  VF, 1   ; If intersect then skip
    171     JP  Ball_Lost
    172 
    173     LD  V1, 2       ;
    174     SUB V0, V1      ; This portion calculates
    175     SE  VF, 1       ; the direction where the
    176     JP  Go_Left     ; ball will bounce,
    177     SUB V0, V1      ; depending on the position
    178     SE  VF, 1       ; of the ball on the paddle,
    179     JP  Paddle_Beep ; and the direction it had
    180     SUB V0, V1      ; before hiting the paddle.
    181     SE  VF, 1       ;
    182     JP  Go_Right    ;
    183 
    184 
    185 Ball_Lost:
    186     LD  V0, 32 ; Set beep delay
    187     LD  ST, V0 ; Beep for lost ball
    188 
    189     LD  I, Ball ; I points on ball sprite
    190     ADD VE, #FF ; Remove 1 from balls counter
    191     LD  V0, VE  ; Set V0 to ball counter
    192 
    193     ADD V0, V0    ; Compute location of ball to erase
    194     LD  V1, 0     ; Set Y location of top line
    195     DRW V0, V1, 1 ; Erase ball from remaining
    196     SE  VE, 0     ; If no balls remain, skip
    197     JP  Play      ; Prepare for a new ball to play
    198 
    199 
    200 Over:
    201     JP Over
    202 
    203 
    204 Go_Left:
    205     ADD V8, #FF ; Make ball go LEFT
    206     SNE V8, #FE ; If ball was not going left, skip
    207     LD  V8, #FF  ; Make it go LEFT by 1 not 2
    208     JP  Paddle_Beep
    209 
    210 
    211 Go_Right:
    212     ADD V8, 1   ; Make ball go right
    213     SNE V8, 2   ; If ball was not going right, skip
    214     LD  V8,1    ; Make it go RIGHT by 1 not 2
    215 
    216 
    217 Paddle_Beep:
    218     LD  V0, 4        ; Set beep time for paddle hit
    219     LD  ST, V0       ; Turn on beeper
    220     LD  V9, #FF      ; Set ball direction to UP
    221     JP  Check_Paddle ; Then, continue playing and check for paddle move
    222 
    223 
    224 Draw_Score:
    225     LD  I, Score    ; Set address to BCD score location
    226     LD  B, V5       ; Store BCD of score
    227     LD  V2, [I]     ; Read BCD of score in V0...V2
    228     LD  F, V1       ; Get font for tens value from V1
    229     LD  V3, 55      ; Set X location of score tens place
    230     LD  V4, 0       ; Set Y location of score
    231     DRW V3, V4, 5   ; Draw tens place score #
    232     ADD V3, 5       ; Set X location of score ones place
    233     LD  F, V2       ; Get font for ones value from V2
    234     DRW V3, V4, 5   ; Draw ones place score #
    235     RET             ; Return
    236 
    237 
    238 Brick:
    239     DW #F000 ; Brick sprite
    240 
    241 
    242 Ball:
    243     DW #8000 ; Ball sprite
    244 
    245 
    246 Paddle:
    247     DW #FC00 ; Paddle sprite
    248 
    249 
    250 Balls:
    251     DW #AA00 ; Balls remaining sprite
    252 
    253 
    254 Score:
    255     DW #0000 ; Score storage
    256     DW #0000 ;