[comp.sys.handhelds] BRIX decoded

vervalin@AUSTIN.LOCKHEED.COM (Paul Vervalin) (09/15/90)

Below is a detailed description of the BRIX game that is run with the CHIP48
interpreter.  I hope this helps others when writing programs using CHIP48.
All of this is hand typed so please forgive me if there are any typos. 
Happy programming!!
 
  register          contents
------------------------------------------------------
    V0        scratch
    V1        scratch
    V2        scratch
    V3        X coordinate of score
    V4        Y coordinate of score
    V5        bricks hit counter
    V6        ball X coordinate
    V7        ball Y coordinate
    V8        ball X direction
    V9        ball Y direction
    VA        X coordinate when generating bricks
    VB        Y coordinate when generating bricks
    VC        paddle X coordinate
    VD        paddle Y coordinate
    VE        ball counter
    VF        collision detect

address  instruction  code                      comment
--------------------------------------------------------------------------------
  200      6E05      VE=05                     set # balls to 5
  202      6500      V5=00                     init. bricks hit to zero
  204      6B06      VB=06                     set Y position of first brick
  206      6A00      VA=00                     set X position of first brick
  208      A30C      I=30C                     set address of brick sprite
  20A      DAB1      DRAW VA VB 1 BYTE         draw brick sprite at loc. VA VB
  20C      7A04      VA=VA+4                   move along X to next brick loc.
  20E      3A04      IF VA=4 SKIP NEXT         if location wrapped goto next row
  210      1208      JUMP 208                  otherwise draw another
  212      7B02      VB=VB+2                   move down Y to next row
  214      3B12      IF VB=12 SKIP NEXT        if all rows drawn continue on
  216      1206      JUMP 206                  otherwise draw next row
  218      6C20      VC=20                     set X coordinate of paddle
  21A      6D1F      VD=1F                     set Y coordinate of paddle
  21C      A310      I=310                     get address of paddle sprite
  21E      DCD1      DRAW VC VD 1 BYTE         draw paddle at loc. VC VD
  220      22F6      GOSUB 2F6                 call subr. to output score   
  222      6000      V0=00                     set X coord of balls remaining
  224      6100      V1=00                     set Y coord of balls remaining
  226      A312      I=312                     get address of balls sprite
  228      D011      DRAW V0 V1 1 BYTE         draw 4 of the five balls
  22A      7008      V0=V0+8                   set X to loc. of 5th ball sprite
  22C      A30E      I=30E                     get address of single ball sprite
  22E      D011      DRAW V0 V1 1 BYTE         draw 5th ball
  230      6040      V0=40                     set V0 to 40 for delay
  232      F015      DELAY TIMER = V0          set delay timer
  234      F007      V0 = DELAY TIMER          check status of delay timer
  236      3000      IF V0=00 SKIP NEXT        if delay timer zero continue
  238      1234      JUMP 234                  otherwise go check status again
  23A      C60F      V6=RANDOM AND 0F          get random X coord for ball start
  23C      671E      V7=1E                     set Y coord of ball start
  23E      6801      V8=01                     set X direction to the right
  240      69FF      V9=FF                     set Y direction to up
  242      A30E      I=30E                     get address of ball sprite
  244      D671      DRAW V6 V7 1 BYTE         draw ball at loc V6 V7
  246      A310      I=310                     get address of paddle sprite
  248      DCD1      DRAW VC VD 1 BYTE         draw paddle at loc. VC VD
  24A      6004      V0=04                     set V0 to 04 for key number
  24C      E0A1      IF KEY V0 NOT PRESSED SKIP NEXT 
  24E      7CFE      VC=VC+FE                  set X coord to 2 to the left
  250      6006      V0=06                     set V0 to 06 for key number
  252      E0A1      IF KEY V0 NOT PRESSED SKIP NEXT
  254      7C02      VC=VC+2                   set X coord to 2 to the right
  256      603F      V0=3F                     set V0 right edge of screen
  258      8C02      VC=VC AND V0              wrap paddle around if needed
  25A      DCD1      DRAW VC VD 1 BYTE         draw paddle at loc. VC VD
  25C      A30E      I=30E                     get address of ball sprite
  25E      D671      DRAW V6 V7 1 BYTE         display ball at loc. V6 V7
  260      8684      V6=V6+V8                  move ball in X direction by V8
  262      8794      V7=V7+V9                  move ball in Y direction by V8
  264      603F      V0=3F                     set highest X coord.
  266      8602      V6=V6 AND V0              AND ball X pos. with V0
  268      611F      V1=1F                     set highest Y coord
  26A      8712      V7=V7 AND V1              AND ball Y pos. with V1
  26C      471F      IF V7 != 1F SKIP NEXT     if ball not at bottom skip
  26E      12AC      JUMP 2AC                  otherwise jump to 2AC
  270      4600      IF V6 != 00 SKIP NEXT     if ball not at left side, skip
  272      6801      V8=01                     else set X direction to right
  274      463F      IF V6 != 3F SKIP NEXT     if ball not at right side, skip
  276      68FF      V8=FF                     else set X direction to left
  278      4700      IF V7 != 00 SKIP NEXT     if ball not at top, skip
  27A      6901      V9=01                     else set Y direction down
  27C      D671      DRAW V6 V7 1 BYTE         draw ball at loc. V6 V7
  27E      3F01      IF VF = 1 SKIP NEXT       if there was a collision skip
  280      12AA      JUMP 2AA                  otherwise jump to 2AA
  282      471F      IF V7 != 1F SKIP NEXT     if ball not at bottom skip
  284      12AA      JUMP 2AA                  otherwise jump to 2AA
  286      6005      V0=05                     set V0 for 5 lines at screen top
  288      8075      V0=V0-V7                  check if ball was in this region
  28A      3F00      IF VF = 00 SKIP NEXT      if it was not then skip
  28C      12AA      JUMP 2AA                  otherwise jump to 2AA
  28E      6001      V0=01                     there was a collision
  290      F018      SOUND TIMER = V0          so beep
  292      8060      V0=V6                     get X coord of ball
  294      61FC      V1=FC                     compute postion of the brick
  296      8012      V0=V0 AND V1              that was hit
  298      A30C      I=30C                     get address of brick sprite
  29A      D071      DRAW V0 V7 1 BYTE         erase brick sprite by drawing
  29C      60FE      V0=FE                     reverse the Y direction of the
  29E      8903      V1=V1 XOR V0              ball sprite
  2A0      22F6      GOSUB 2F6                 call subr. to update score
  2A2      7501      V5=V5+1                   incr. bricks hit counter by one
  2A4      22F6      GOSUB 2F6                 call subr. to update score
  2A6      4560      IF V5 = 60 SKIP NEXT      if all bricks have been hit, skip
  2A8      12DE      JUMP 2DE                  else infinite loop (game over)
  2AA      1246      JUMP 246                  goto address 246
  2AC      69FF      V9=FF                     ball at bottom so set direct. up
  2AE      8060      V0=V6                     get X coord. of ball
  2B0      80C5      V0=V0-VC                  intersect with paddle
  2B2      3F01      IF VF = 01 SKIP NEXT      if intersect then skip
  2B4      12CA      JUMP 2CA                  otherwise goto 2CA
  2B6      6102      V1=02                     |
  2B8      8015      V0=V0-V1                  |
  2BA      3F01      IF VF = 1 SKIP NEXT       |
  2BC      12E0      JUMP 2E0                  |
  2BE      8015      V0=V0-V1                  | this portion determines the
  2C0      3F01      IF VF = 1 SKIP NEXT       | direction that the ball should
  2C2      12EE      JUMP 2EE                  | bounce.
  2C4      8015      V0=V0-V1                  |
  2C6      3F01      IF VF = 1 SKIP NEXT       |
  2C8      12E8      JUMP 2E8                  |
  2CA      6020      V0=20                     set beep delay      
  2CC      F018      SOUND TIMER = V0          beep for lost ball
  2CE      A30E      I=30E                     get addres for ball sprite
  2D0      7EFF      VE=VE+FF                  remove one from ball count
  2D2      80E0      V0=VE                     set V0 to ball count
  2D4      8004      V0=V0+V0                  compute location of ball to erase
  2D6      6100      V1=00                     set Y coord. to top line
  2D8      D011      DRAW V0 V1 1 BYTE         erase ball from remaining
  2DA      3E00      IF VE = 00 SKIP NEXT      if no balls remain, skip
  2DC      1230      JUMP 230                  otherwise goto 230
  2DE      12DE      JUMP 2DE                  jump to end of game
  2E0      78FF      V8=V8+FF                  make ball go left
  2E2      48FE      IF V8 != FE SKIP NEXT     if ball was not going left, skip
  2E4      68FF      V8=FF                     else make it go left by 1 not 2
  2E6      12EE      JUMP 2EE                  goto paddle beep
  2E8      7801      V8=V8+1                   make ball go right
  2EA      4802      IF V8 != 2 SKIP NEXT      if ball was not going right, skip
  2EC      6801      V8=01                     else make it go right by 1 not 2
  2EE      6004      V0=04                     set beep time for paddle hit
  2F0      F018      SOUND TIMER = V0          turn on beep
  2F2      69FF      V9=FF                     set ball direction to up
  2F4      1270      JUMP 270                  goto 270
  2F6      A314      I=314                     set address to BCD score location
  2F8      F533      STORE BCD OF V5 IN I..I+2 store BCD of score
  2FA      F265      READ FROM I..I(V2) 
  2FC      F129      I=5 BYTE SPRITE CHAR IN V1  get font for tens value from V1
  2FE      6337      V3=37                     set X coord. of score tens place
  300      6400      V4=00                     set Y coord of score
  302      D345      DRAW V3 V4 5 BYTES        draw tens place score #
  304      7305      V3=V3+5                   set X coord. of score ones place
  306      F229      I=5 BYTE SPRITE CHAR IN V2  get font for ones value from V2
  308      D345      DRAW V3 V4 5 BYTES        draw ones place score #
  30A      00EE      RETURN 
  30C      E000                                brick sprite 
  30E      8000                                ball sprite 
  310      FC00                                paddle sprite 
  312      AA00                                balls remaining sprite 
  314      0000                                score storage 
  316      0000                                score storage  
                                                   _____        _______        
*********************************    HP48SX       / ___ \      /__    (\     
*                               * .----------.    ||   ||     /( _)  z) \   
* Paul Vervalin                 * |]]]]]]].-.|    ||___||    |. V__ (_ \/|   
*                               * |]]]]]]]| ||    \_____/    |   ( ) ) | |   
* vervalin@AUSTIN.LOCKHEED.COM  * |]]]]]]]| ||   .-------.   [   |/  (_/ |  
*                               * |]]]]]]]`-']---[ AMIGA ]__/ \  `.     /     
********************************* `----------'   `-------'     \_______/