[comp.sys.handhelds] PONG for HP48SX

vervalin@AUSTIN.LOCKHEED.COM (Paul Vervalin) (10/13/90)

	OK folks here it is!  PONG for the HP48SX written in CHIP-48.
	Some things you should know before you start playing are...
	1)  This is my first attempt at programming in CHIP-48, so I 
	    know there are probably a few things that could have been
	    done better.
        2)  The game never ends.  It keeps score, but only up to 9 for
	    each player, then it will roll over to 0.  Sorry, its the
            only way I could think of to do it.  So, you have to play
            whoever gets to a number first, wins.
        3)  It is kind of slow, but then there are two paddles and ball
	    moving around all at once.
        4)  The player who got the last point gets the serve...
        5)  Keys 7 and 4 (on the HP48) control the up and down of the 
	    left player and the / and * keys control the up and down of
	    the right player.

	I think that's about it, so have fun!  
 
        You need ASC-> to convert it to the binary string that CHIP-48
	can read.

==============================cut here==================================
%%HP: T(3)A(D)F(.);
"C2A20DE100A600B6C0C6F3D6C046B156002A8EAD6BCD6DE600222D6610861006
080F510F70030021E17C71778096FF2AEE6D172A8EAD6BCD6D06100E1AB7EF06
400E1AB72006F1B820AD6B06C00E1AD7EF06D00E1AD72006F1D820CD6D2AEE6D
176848784906F3682016F17821640021C764F3216874F196FF740096106D1721
E2861036100807085B21E886FF36A00807085DF310216A16200851F31021EB08
51F31021CC0851F310216C06020F81222DE843222D66E33310661086FF331086
1021A197FF94EF96FF21CC97109420961006400F8121072A0FEF332F561F9246
B156004D5547502F924D5500EE0808080808080800000000004FD6"
==============================cut here==================================

This is a detailed breakdown of the game, sooooooo, if anybody wants to
make it better, or change it in some way, it might be a little easier.
Also, about half of the code was in some way extracted from the BRIX
program.  So, thanks to whoever wrote the original BRIX game.

Registers
---------
V0-V3  are scratch registers
V4     X coord. of score
V5     Y coord. of score
V6     X coord. of ball
V7     Y coord. of ball
V8     X direction of ball motion
V9     Y direction of ball motion
VA     X coord. of right player paddle
VB     Y coord. of right player paddle
VC     X coord. of left player paddle
VD     Y coord. of left player paddle
VE     Score
VF     collision detection

ADDRESS (all CHIP-48 programs start at 200 (hex) and increase by 2's)
--------------
  200      6A00  VA=00     set player A (left side) X coord.
           6B0C  VB=0C     set player A Y coord.
           6C3F  VC=3F     set player B (right side) X coord.
           6D0C  VD=0C     set player B Y coord.
           641B  V4=1b     set score X coord.
           6500  V5=00     set score Y coord.
           A2E8  I=***     get address of paddle sprite
           DAB6            draw paddle at location VA VB 6 bytes
           DCD6            draw paddle at location VC VD 6 bytes
           6E00  VE=00     set score to 00
           22D2  gosub *** Score:
           6601  V6=01     set X coord. of ball to 01
           6801  V8=01     set ball X direction to right
Big Loop:  6080  V0=80     set V0=delay before ball launch
           F015  DT=V0     set delay timer
DT loop:   F007  V0=DT     read delay timer into V0
           3000            skip next instruction if V0=00
           121E  jump ***  DT loop:
           C717  V7=**     set Y coord. to rand # AND 17 (0-23)
           7708  V7=V7+08  so Y coord. is (8-31)
           69FF  V9=FF     set ball Y direction to up
           A2EE  I=***     get address of ball sprite
           D671            draw ball at location V6 V7 1 byte
Padl loop: A2E8  I=***     get address of paddle sprite
           DAB6            draw paddle at location VA VB 6 bytes
           DCD6            draw paddle at location VC VD 6 bytes
           6001  V0=01     set V0 to KEY 1
           E0A1            skip next instruction if KEY in V0 is pressed
           7BFE  VB=VB+FE  subtract 2 from Y coord. of paddle A
           6004  V0=04     set V0 to KEY 4
           E0A1            skip next instruction if KEY in V0 is pressed
           7B02  VB=VB+02  add 2 to Y coord. of paddle A
           601F  V0=1F     set V0 to max Y coord.
           8B02  VB=VB&V0  AND VB with V0
           DAB6            draw paddle at location VA VB 6 bytes
           600C  V0=0C     set V0 to KEY C
           E0A1            skip next instruction if KEY in V0 is pressed
           7DFE  VD=VD+FE  subtract 2 from Y coord. of paddle B
           600D  V0=0D     set V0 to KEY D
           E0A1            skip next instruction if KEY in V0 is pressed 
           7D02  VD=VD+02  add 2 to Y coord. of paddle B
           601F  V0=1F     set V0 to max Y coord.
           8D02  VD=VD&V0  AND VD with V0
           DCD6            draw paddle at location VC VD 6 bytes
           A2EE  I=***     get address of ball sprite
           D671            draw ball at location V6 V7 1 byte
           8684  V6=V6+V8  move ball in X direction
           8794  V7=V7+V9  move ball in Y direction
           603F  V0=3F     set V0 to max X location
           8602  V6=V6&V0  AND V6 with V0
           611F  V1=1F     set V1 to max Y location
           8712  V7=V7&V0  AND V7 with V0
           4600            skip next instruction if ball not at left
           127C  jump ***  Leftside:  left side handler
           463F            skip next instruction if ball not at right
           1286  jump ***  Rightside: right side handler
Ball Loop: 471F            skip next instruction if ball not at bottom
           69FF  V9=FF     set Y direction to up
           4700            skip next instruction if ball not at top
           6901  V9=01     set Y direction to down
           D671            draw ball at location V6 V7 1 byte
           122E  jump ***  Padl loop:
Leftside:  6801  V8=01     set X direction to right
           6301  V3=01     set V2 to 1 in case left misses ball
           8070  V0=V7     set V0 to V7 Y coord. of ball
           80B5  V0=V0-VB  subtract position of paddle from ball
           128E  jump ***  Pad Coll:
Rightside: 68FF  V8=FF     set X direction to left
           630A  V3=0A     set V2 to 0A (10) in case right misses ball
           8070  V0=V7     set V0 to V7 Y coord. of ball
           80D5  V0=V0-VD  subtract position of paddle from ball
Pad Coll:  3F01            skip next instruction if ball not above paddle
           12A6  jump ***  Ball Lost:
           6102  V1=02     set V1 to 02
           8015  V0=V0-V1  subtract V1 from V0
           3F01            skip next instr. if ball not at top of paddle
           12BE  jump ***  Ball Top:
           8015  V0=V0-V1  subtract another 2 from V0
           3F01            skip next instr. if ball not at middle of paddle
           12CC  jump ***  Pad Hit:  Ball in middle of paddle
           8015  V0=V0-V1  subtract another 2 from V0
           3F01            skip next instr. if ball not at bottom of paddle
           12C6  jump ***  Ball Bot:
Ball Lost: 6020  V0=20     set lost ball beep delay
           F018            beep for lost ball
           22D2  gosub *** Score:  erase previous score
           8E34  VE=VE+V3  add 1 or 10 to score depending on V3
           22D2  gosub *** Score:  write new score
           663E  V6=3E     set ball X coord. to right side
           3301            skip next instr. if right player got point
           6601            set ball X coord. to left side
           68FF            set direction to left
           3301            skip next instr. if right player got point
           6801            set direction to right
           121A  jump ***  Big Loop:
Ball Top:  79FF  V9=V9+FF  subtract 1 from V9, ball Y direction
           49FE            skip next instr. if V9 != FE (-2)
           69FF  V9=FF     set V9=FF (-1)
           12CC  jump ***  Pad Hit:
Ball Bot:  7901  V9=V9+01  add 1 to V9, ball Y direction
           4902            skip next instr. if V9 != 02
           6901  V9=01     set V9=01
Pad Hit:   6004  V0=04     set beep for paddle hit
           F018  ST=V0     sound beep
           1270  jump ***  Ball Loop:
Score:     A2F0  I=***     get address of Score
           FE33
           F265
           F129
           641B
           6500
           D455
           7405
           F229
           D455
           00EE
Paddle:    8080
           8080
           8080
Ball:      8000
Score:     0000
           0000

                                                   _____        _______        
*********************************    HP48SX       / ___ \      /__    (\     
*                               * .----------.    ||   ||     /( _)  z) \   
* Paul Vervalin                 * |]]]]]]].-.|    ||___||    |. V__ (_ \/|   
*                               * |]]]]]]]| ||    \_____/    |   ( ) ) | |   
* vervalin@AUSTIN.LOCKHEED.COM  * |]]]]]]]| ||   .-------.   [   |/  (_/ |  
*                               * |]]]]]]]`-']---[ AMIGA ]__/ \  `.     /     
********************************* `----------'   `-------'     \_______/