8

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

BRIX.SRC (7654B)


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