home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / afrobnc.asm next >
Encoding:
Assembly Source File  |  2001-07-01  |  29.0 KB  |  755 lines

  1. ; Sean Smith
  2. ; AFROsoft Programming Division
  3. ; AFROAGE:            2 years and still growing
  4. ; AFROSIZE:            Easily past 11 Inches
  5. ; DATE:                Saturday, 09 September, 2000 17:14:06
  6. ; PRGM PURPOSE:        Present a simple pong game, with ample comments
  7. ; TYPE:                Game/Tutorial
  8. ;                    Covers Direct Input
  9. ;                    Goes over GameFlow process
  10. ; GAME LEVEL:        New players, to Pong Experts
  11. ; SOURCE TUTORIAL:    People who grasp simple register usage
  12. ;                    People who can already write text to the screen
  13. ;                    People who want a simple game to look at.
  14.  
  15. #include "ti86asm.inc"
  16.  
  17. .org _asm_exec_ram
  18.  
  19.     nop
  20.     jp ProgStart
  21.     .dw 0
  22.     .dw ShellTitle
  23.  
  24. ShellTitle:
  25.     .db "AFROSoft BounceBalls",0
  26.  
  27. ProgStart:
  28.     call 4AB1h        ; turn off the run indic.
  29.     call _clrLCD    ; clear the LCD screen
  30.  
  31.     xor a            ; sets a to zero, faster and smaller than
  32.                     ; ld a,0
  33.  
  34.     ld (score),a    ; set our score to zero
  35.  
  36.     ld (_penRow), a    ; because a is still zero...
  37.     ld (_penCol), a ; we are using it to set the row and column
  38.  
  39.     ld hl,Intro        ; loads the information at the label Intro into hl
  40.     call _vputs        ; calls _vputs, displays the info in hl at _penRow, _penCol
  41.  
  42. TitleScreen:        ; our "get-how-hard-we-want-it loop"
  43.                      
  44.                         
  45.     ld a,%10111111    ; we are using direct input. Bit 6 is set so we can
  46.                     ; check for the menu keys (the FKeys)
  47.  
  48.     out (1),a        ; send our quere to the port
  49.     in a,(1)        ; read our quere from the port
  50.  
  51.     cp %10111111,a    ; did the exit key get pressed?
  52.     jp z,ExitMe        ; if so, we jump to the end.
  53.  
  54.     cp %11101111,a    ; did the F1 key get pressed?
  55.     jp z,F1            ; if so, we jump to the label F1
  56.  
  57.     cp %11110111,a    ; ditto, with F2
  58.     jp z,F2            ; ditto, with F2
  59.  
  60.     cp %11111011,a    ; ditto, with F3
  61.     jp z,F3            ; ditto, with F3
  62.  
  63.     cp %11111101,a    ; ditto, with F4
  64.     jp z,F4            ; ditto, with F4
  65.  
  66.     cp %11111110    ; ditto, with F5
  67.     jp z,F5            ; ditto, with F5
  68.  
  69.     jp nz,TitleScreen    ; If none of the desired  keys were pressed, we 
  70.                         ; jump back to the top of our loop.
  71.  
  72. F1:    ld a,55            ; Hard is the value we use to set how hard
  73.     ld (Hard),a        ; the game is. What it actually is, is the
  74.     jp Start        ; value that is used in a loop later to set
  75.                     ; how fast the game goes.
  76. F2:
  77.     ld a,40            ; because we cannot directly load 40 into (Hard),
  78.     ld (Hard),a        ; we 'indirectly' give it that value, by loading
  79.     jp Start        ; 40 into the a register, then the a register
  80.                     ; into (Hard).
  81.  
  82. F3: ld a,25            ; Person A: Knock knock
  83.     ld (Hard),a        ;
  84.     jp Start        ; Person B: Who's there?
  85.     
  86. F4: ld a,10            ; Person A: Tanya Harding
  87.     ld (Hard),a        ;
  88.     jp Start        ; Person B: Tanya Harding W..
  89.  
  90. F5:    ld a,5            ; Person A interrupts, and hits Person
  91.     ld (Hard),a        ; B in the back of the leg with a steel 
  92.     jp Start        ; pipe :)
  93.  
  94. Start:                ; Begin out main loop
  95.                     ;
  96.                     ; Here, we will be doing the normal stuff
  97.                     ; that a game does.
  98.                     ;
  99.                     ; a. get input from the user
  100.                     ; b. store input from the user
  101.                     ; c. calculate game data (e.x a ball moving)
  102.                     ; d. evaluate game data
  103.                     ; e. draw graphics
  104.                     ; f. check to see if the game is over.
  105. ;Ball Setup    
  106.     ld a,2            ; ballX is a value used to keep track of the pong
  107.     ld (ballX),a    ; ball's X coordinate
  108.     ld a,10
  109.     ld (ballY),a    ; ballY obviously holds the ball's Y coord.
  110.  
  111.     ld a,(ballX)    ; we are loading 2 temporary values here: the balls
  112.     ld (tmpX),a        ; x and y values. We do this, because we will need to
  113.     ld a,(ballY)    ; erase the old ball later, and put a new one at a 
  114.     ld (tmpY),a        ; different location on the screen.
  115.  
  116.   
  117.                     ; In pong games, the ball can move in 4 directions:
  118.                     ; up and left, up and right
  119.                     ; down and left, down and right
  120.                     ;
  121.                     ; we use the values ballUD and ballLR to keep track of 
  122.                     ; witch direction the ball is moving
  123.     
  124.                     ; I am making it so that: the ball starts out going in 
  125.                     ; a specific direction (up and left). Some people would
  126.                     ; randomize the values here. Fell free to skip this next
  127.                     ; area.
  128.  
  129. ; randomize code: uncomment the next lines, and delete from
  130. ; [ld a,1] to [ld (ballLR),a]
  131.  
  132. ;--------------------------------------------------------------------------------;
  133. ;--------------------------------------------------------------------------------;
  134. ;
  135. ;    call _random    ; generates a random number (either 0 or 1) and stores it
  136. ;                    ; in the special memory crap area called op1.
  137. ;
  138. ;    call _convop1    ; converts an integral value out of op1. it stores it in the
  139. ;                    ; 24 bit-ish register AHL. because our number is only going
  140. ;                    ; to be 1 or 0, then the registers A and H can be disregarded.
  141. ;                    ; l has our random number... I hope :)
  142. ;
  143. ;    ld a,l            ; now the register a has our random number.
  144. ;    ld (ballUD),a 
  145. ;
  146. ;    call _random    ; i'm sure there is a more efficent way of doing this...
  147. ;    call _convop1    ; but who cares, its my code! muahahaahaha!
  148. ;
  149. ;    ld a,l
  150. ;    ld (ballLR),a
  151. ;
  152. ;                    ; I hope this works, you know I'm not going to take the time
  153. ;                    ; to see if it actually compiles. gya hah. huzzah!
  154. ;
  155. ;--------------------------------------------------------------------------------;
  156. ;--------------------------------------------------------------------------------;
  157.  
  158. ; back to our normal program
  159.  
  160.     ld a,1            ; if ballUD has the value of 0, the ball is moving up
  161.     ld (ballUD),a     ; so, if ballUD has the value of 1, the ball is moving down
  162.  
  163.     xor a            ; again, remember than any number xor'd itself = zero
  164.  
  165.     ld (ballLR),a   ; if ballLR has 0, we move the ball left. Obviously then, if
  166.                     ; ballLR has the value of 1, we move the ball right.
  167.  
  168.     ld a,2            ; _curRow and _curCol are both equated in the header file.
  169.     ld (_curRow),a  ; they set where text goes when using the call _puts, _putc,
  170.     ld a,10            ; or _putps. remember, these 'take' whats in hl, and displays
  171.     ld (_curCol),a    ; them in a fixed width font on the home screen.
  172.  
  173.     ld hl, ball        ; note that ball is a null terminated (,0) string at the bottom
  174.     call _puts      ; puts our ball at (2, 10).
  175. ; End Ball Setup
  176.  
  177. ; Paddle Setup
  178.  
  179.     ld a,7            ; we are practicly doing the same thing as we did up above 
  180.     ld (padX),a        ; padX and padY are the X and Y coords of our paddle. 
  181.     ld a,4            ; we are just loading their values up for later, when we want
  182.     ld (padY),a        ; to move our paddle around
  183.  
  184.     ld a, (padX)    ; If you couldnt figure it out, this part is loading up 
  185.     ld (tmpPadX),a    ; our temp paddle values. When we finally decide to move the 
  186.     ld a, (padY)    ; paddle around, we will want to clear where it was last.
  187.     ld (tmpPadY),a
  188.  
  189.     ld a,7            ; I hate boy's who sing 'bout krombie n fitch...
  190.     ld (_curRow),a    ; their music really makes me sick
  191.     ld a,4            ; and I think it's lame when they sing about the summer time...
  192.     ld (_curCol),a    ; the summer time...
  193.  
  194.     ld hl, Pad        ; Pad is our paddle.
  195.     call _puts        ; put that baby down
  196.  
  197. ; End Paddle Setup
  198.  
  199.     call _getkey    ; we have this call here to just sit around and wait for a 
  200.                     ; keypress, so our user won't be startled by the beginning
  201.                     ; of the game.
  202.                 
  203.                     ; at this point in the program, we have a screen that looks
  204.                     ; like this:
  205.                     ; +-------------------------------------------+
  206.                     ; |BounceBall!        F1=Easy ... F5=Diffucult| (small text)
  207.                     ; |      _                                    |
  208.                     ; |     (_)                                   |
  209.                     ; |                                           |
  210.                     ; |                                           |
  211.                     ; |                                           |
  212.                     ; |                                           |           
  213.                     ; |     -======-                              |
  214.                     ; +-------------------------------------------+
  215.                     ;
  216.                     ; pretty cheezy, eh?
  217.                     ;
  218.  
  219.  
  220. getKeyPress:
  221.                     ; Here we go, more direct input. I didn't go into too much detail 
  222.                     ; earlier, because I didn't feel like it. Here we go:
  223.                     ;
  224.                     ; dInput is the best way to get keypresses. Its faster than _getky and
  225.                     ; _getkey. It also can be nicer on the batteries. we use dInput
  226.                     ; by accessing the ports on the ti-86. Thanks Assembley Studio 86, for 
  227.                     ; this wonderful chart:
  228.                     ;
  229.                     ;     7        6        5        4        3        2        1        0
  230.                     ; 6    MORE    EXIT    2nd        F1        F2        F3        F4        F5
  231.                     ; 5    ALPHA    GRAPH    LOG        LN        x▓        ,        STO        &&&&&
  232.                     ; 4    x-VAR    TABLE    SIN        EE        7        4        1        0
  233.                     ; 3    DEL        PRGM    COS        (        8        5        2        .
  234.                     ; 2    &&&&&    CUSTOM    TAN        )        9        6        3        (-)
  235.                     ; 1    &&&&&    CLEAR    ^        ≈        ╫        -        +        ENTER
  236.                     ; 0    &&&&&    &&&&&    &&&&&    &&&&&    UP        RIGHT    LEFT    DOWN
  237.                     ;
  238.                     ; note: &&&&& means that there is no key occupied by that section
  239.                     ;
  240.                     ; to use dInput, first we decide what row(s) we want to use. We pick
  241.                     ; the row number, turn off the corresponding bit in the number %11111111
  242.                     ; and send it to port 1.
  243.                     ; 
  244.                     ; e.x. I want to read in row 5, witch has alpha, graph, log, ln, ect...
  245.                     ; so i set the 5th bit in the number to %1111111 to zero (if you don't 
  246.                     ; know, the bytes are in this order %76543210), witch would be %11011111.
  247.                     ; 
  248.                     ; I would load up %11011111 into the register a, then send it out to the 
  249.                     ; port. when I read in from that port, a will be magicly changed, based on
  250.                     ; what key is pressed. when we read in from the port, and the alpha key
  251.                     ; is pressed, then a will read %01111111 !!! Look at alpha on our chart.
  252.                     ; it is in column 7! so the 7th bit is turned off! wow.
  253.                     ;
  254.  
  255.     ld a,%10111110    ; We have here bit 0 and bit 6 set. We can do this because, if you look,
  256.                     ; there are empty spots in the bit 0 row. to be precise, column 7-4
  257.                     ; have no key set to them. So, we can activate another row (in this case
  258.                     ; row 6, because it has a key we want that lays between column 7-4 (the    
  259.                     ; exit key, witch is in column 6.)
  260.  
  261.     out (1),a        ; send our quere (our rows to look at) to the port
  262.     in a,(1)        ; read our quere (what key(s) are being pressed) from the port
  263.  
  264.                     ; because we merged two rows (because the 0 row has open spaces,
  265.                     ; we now have a new column, that looks like this:
  266.                     
  267.                     ;----------------------------------------------------------------
  268.                     ;          part of row 6        |        part of row 0 
  269.                     ;----------------------------------------------------------------
  270.                     ;     7        6        5        4    |    3        2        1        0
  271.                     ;     MORE    EXIT    2nd        F1    |    UP        RIGHT    LEFT    DOWN
  272.                     ;----------------------------------------------------------------
  273.                     ;----------------------------------------------------------------
  274.                     
  275.                     ; a has the value of the key being pressed, because we used in a,(1).
  276.                     ; so, we can use the cp statment to see what key is being pressed.
  277.                     ; 
  278.                     ; If you want to really be elite, you could use the bit statment.
  279.                     ; e.x. 
  280.                     ;        bit 6
  281.                     ;        jp z,exitWasJustPressed
  282.                     ; 
  283.  
  284.  
  285.  
  286.  
  287.     cp %10111111,a    ; was the exit key pressed?
  288.     jp z,ExitMe        ; then we quit out of the game.
  289.  
  290.     cp %11111011,a    ; was the right key pressed?
  291.     jp z,kpRight    ; then we jump to the right key pressed label
  292.  
  293.     cp %11111101,a    ; was the left key pressed?
  294.     jp z,kpLeft        ; then we stick our left side in, we stick our left side out...
  295.  
  296.     jp nz,BallStuff ; no keys were pressed (nz) OR keys were pressed, and now we are ready 
  297.                     ; to move the ball around.
  298.  
  299. kpLeft:                ; this area handles the movement of the paddle
  300.                     ; the user pressed left to come here.
  301.  
  302.     ld a,(padY)        ; we load up the last stored Y coord of the paddle into a
  303.     cp 0            ; is our paddle at the rightmost side? (shaddup oldskoo progr's.
  304.                     ; everyone OLD knows that there are better ways to do cp 0. Let the
  305.                     ; new coder get jiggy with cp 0. Yea yea, I know I used xor a ;p)
  306.  
  307.     jp z,LeftStuff    ; if our paddle was at the leftmost side, then dont move it left
  308.                     ; any more.
  309.  
  310.     dec a            ; our paddle isn't at 0, so we can move it left more. so we dec
  311.     ld (padY),a        ; it's Y value, and reload it into padY
  312.  
  313. LeftStuff:    jp BallStuff    ; Ok. we are here because either:
  314.                              ; a. the left value changed, or 
  315.                             ; b. it didn't
  316.                             ;
  317.                             ; in either case, we now go do stuff with the ball. So
  318.                             ; we jump to BallStuff
  319.  
  320. kpRight:                    ; the exact same as above, yet the user pressed right.
  321.     ld a,(padY)                ; load up the Y value            ;    If you believe
  322.     cp 14                    ; check if it is too far        ;    the western sun
  323.     jp z,RightStuff            ; if so, dont increase it        ;    is falling down
  324.                             ;                                ;    on everyone...
  325.     inc a                    ; if not, increase Y and        ;
  326.     ld (padY),a                ; store it back in padY            ;    FOTL, NARRYAN, 1997
  327.  
  328. RightStuff: jp BallStuff    ; Ok. we are here because either:
  329.                              ; a. the right value changed, or 
  330.                             ; b. it didn't
  331.                             ;
  332.                             ; in either case, we now go do stuff with the ball. So
  333.                             ; we jump to BallStuff    
  334.     
  335. BallStuff:                    ; whooho, we finally get to move the ball around! yah.
  336.                             ; Just to give you a rundown at this point of what we have done:
  337.                             ; 
  338.                             ; We have set up our game screen
  339.                             ; We set up the values needed for our game
  340.                             ; We have taken in user input
  341.                             ; We have evaluated user input, and stored values.
  342.                             ;
  343.                             ; hmm, what else do we have to do? Hint, hint:
  344.                             ;
  345.                             ; c. calculate game data (e.x a ball moving)
  346.                             ; d. evaluate game data (collision detection)
  347.                             ; e. draw graphics (paddle and bal)
  348.                             ; f. check to see if the game is over. (duh)
  349.  
  350.  
  351.                             ; remember way back when, at the beginning of the game, we had the 
  352.                             ; user press a F1-F5 key? What did that do again? I did tell you.
  353. ; Begin Speed Control        ; We will be using hard to calculate how fast our game goes.
  354.  
  355.     ld a,(Hard)                ; load a up with our hard value. note that it was a number ;p
  356.     ld b,a                    ; load a into b, or effectivly loading (Hard) into b.
  357. loop:                        ; begin a loop
  358.     halt                    ; this command halts the cpu for a moment. 
  359.     djnz loop                ; Decrement B, and jump if not zero. it basicly does this
  360.                             ;
  361. ; End Speed Control            ; e.x. 
  362.                             ; 
  363.                             ; B = 10
  364.                             ; LOOP:
  365.                             ;         HALT
  366.                             ;         B := B - 1 
  367.                             ; If B is not equal to 0 then go back to LOOP
  368.                             ; If B is equal to 0 then exit LOOP
  369.  
  370.  
  371.     ld a,(ballX)            ; we need to backup the X and Y values of the ball, so
  372.     ld (tmpX),a                ; we can erase them later, once we have NEW X and Y values.
  373.     ld a,(ballY)
  374.     ld (tmpY),a
  375.  
  376. ;update the ball here, no matter if they press a key or not
  377.  
  378.     ld a, (ballUD)        ; load a with the ball up/down direction value
  379.     cp 0                ; is the ball moving up?
  380.     jp nz, balldown     ; if not, the it has to be moving down. Jump to ball down area
  381.  
  382. ballup:                    ; we are here because the ball is moving up, and we need to make
  383.                         ; sure that it doesn't go too far up.
  384.     
  385.     ld a, (ballX)        ; our ball's x value.
  386.     cp 1                ; is the ball at the top of the screen?
  387.     jp z, nosubX        ; If so, don't decrease its X value. Because it's at the top, we need
  388.                         ; to bounce it off the ceiling, and reset it's flag, to tell it to
  389.                         ; go down.
  390.  
  391.                         ; because we didn't jump, that means that the ball can be moved up.
  392.     ld a,(ballX)        ; load up the ball's X value
  393.     sub 1                ; Obviously, decrease the distance from the top (the X value.)
  394.     ld (ballX),a        ; re-store the ball's X value
  395.  
  396.     jp leftRight        ; because we sucessfully moved the ball up at this point, we need
  397.                         ; to decide if we move the ball left or right.
  398.  
  399. nosubX:                    ; we jumped here because the ball is at the top of the screen, and we
  400.                         ; need to tell it to bounce, and go the other way. this is simply done
  401.                         ; by changing the value of ballUD (remember, ballUD tells the ball
  402.                         ; witch direction it needs to go!)
  403.  
  404.                         ; remember, if ballUD has 0 in it, go up. If it has 1, go down.
  405.     ld a,1                ; load a with 1, because we want to move the ball up.
  406.     ld (ballUD),a        ; store the value of a into the up down direction flag.
  407.  
  408.     ld a,(ballX)        ; get the ball's X value
  409.     add a,1                ; we add 1 to it, because the ball is going down, not up
  410.     ld (ballX),a        ; save our balls new X value
  411.     jp leftRight        ; the ball is going the right way up and dow now, so we need to jump
  412.                         ; to the area that handles left and right motion
  413.  
  414. balldown:                ; we are here because the ballUD flag told us that the ball was moving
  415.                         ; down, and not up. So, we need to see if: The ball is at the bottom.
  416.                         ; if it is not, we need to add one to the ball's X value. If it is 
  417.                         ; then we need to do three important things.
  418.                         ; 
  419.                          ; check to see if the ball hit the paddle
  420.                         ;     if not, game over d00d!
  421.                         ;   if so, we need to increase their score!
  422.  
  423.  
  424.     ld a, (ballX)        ; load a with the ball's X value        
  425.     cp 6                ; is the ball at the bottom of the screen?
  426.     jp z, noaddX        ; If it is, jump to noaddX, and check if we need to either add points
  427.                         ; or call a game over.
  428.                         ;
  429.                         ; if it isn't, we can safely move the ball down a bit.
  430.  
  431.  
  432. ;ball not at the bottom of the screen
  433.  
  434.     ld a,(ballX)        ; the balls x value
  435.     add a,1                ; increase it (witch will move it down a square)
  436.     ld (ballX),a        ; resave the ball's X value
  437.     jp leftRight        ; ok, we sucessfully changed its up/down motion, now we need to 
  438.                         ; do something about the left and right motion.
  439. ;end ball not...
  440.  
  441. noaddX:                    ; the ball is at the bottom of the screen, so dont add to the x val.
  442.                         ; We need to check if it comes in contact with the paddle.
  443.                         ; if it does, bounce ball (reset the up/down flag, add to the score,
  444.                         ; and check for left/right motion). If it does not come in contact with
  445.                         ; the paddle, then its game over for the user. We jump to the end, and
  446.                         ; tell them their score.
  447.  
  448.  
  449.                         ; We know the ball's X value, because it is right above the paddle.
  450.                         ; now we need to see if if: 
  451.                         ; [pad's left side] <= [ball] <= [pad's right side]
  452.  
  453.     ld a, (ballY)        ; load the ball's Y value, to check it.
  454.     ld c,a                ; load a into c, effectively moving (ballY into c)
  455.     ld a, (padY)        ; load the paddle's Y value into a, so we can do a compare between them
  456.  
  457.     cp c                ; we are comparing the ball to the pad now.
  458.     jp m, next1            ; if the ball's Y value is greater than the pad, go to next step
  459.     jp z, next1            ; if the ball's Y value is equal to the pad, go to the next step
  460.     jp p, ExitMe        ; if the ball's Y value is less than the pad's, go to the end.
  461.     jp nz, ExitMe        ; just in case, if we get this far, lets go to the end anyway
  462.  
  463. next1:                    ; at this point, we know that the ball is at least
  464.                         ;
  465.                         ; [pad's left side] <= [ball].
  466.                         ;
  467.                         ; we check to see if: 
  468.                         ;
  469.                         ;                      [ball] <= [pad's right side]
  470.  
  471.  
  472.     add a,4                ; the paddle is 5 'squares' long. a has the location of the first
  473.                         ; square, so we add 4 to account for the rest of the paddle.
  474.  
  475.     cp c                ; again, compare the ball's Y value to the paddle
  476.     jp z, bounceup        ; ok. returned zero, so that means the ball hit the right side, thus
  477.                         ; meeting the condition of [pL] <= [B] <=[pR]
  478.  
  479.     jp p, bounceup        ; ok. returned a positive number. that means the ball's Y value is less
  480.                         ; than the right side's Y value, thus meeting the condition of 
  481.                         ; [pL] <= [B] <=[pR]
  482.  
  483.     jp m, ExitMe        ; it didn't meet any of the conditions, so we are outta here!
  484.  
  485.  
  486. bounceup:                ; Ok, we are here because we jumped here. We jumped here because
  487.                         ; the ball met the conditions needed to bouce back up. Since it hit
  488.                         ; the paddle, we need to make it go flying back out, increase the users
  489.                         ; score, and go on to show the ball and the paddle. 
  490.  
  491.     xor a                ; a=0
  492.     ld (ballUD),a        ; put 0 into the Ball Up Down Flag, witch directs us to move the ball
  493.                         ; up (U=0, D=1) next time around.
  494.  
  495.     ld a,(score)        ; open up our score.
  496.     add a,1                ; add a point
  497.     ld (score),a        ; store the score.
  498.  
  499.     jp showball            ; go update all the graphics.
  500.  
  501.  
  502. leftRight:                ; We are here because the ball sucessfully moved either up a space, or
  503.                         ; down a space. Because the ball must move either left or right also, we
  504.                         ; now go check to see what way the ball will go.
  505.  
  506.     ld a, (ballLR)        ; load the "ball-goes-left-or-right flag value into a"
  507.     cp 0                ; 0=left, 1 = right. is the ball going left?
  508.     jp nz, ballright    ; if nz, that means the ball is going right.
  509.  
  510. ballLeft:                ; time to move the ball left, unless it is next to the wall. in that
  511.                         ; case, we need to reset its left-right directional flag, so it will 
  512.                         ; move right next time around.
  513.     
  514.     ld a, (ballY)        ; load the ball's Y value into a.
  515.     cp 1                ; is the ball at the left of the screen?
  516.     jp z, nosubY         ; if so, jump to nosubY. if not, move it left.
  517.  
  518.                         ; the ball is not at the left of the screen
  519.                         ; we need to move the ball left a space.
  520. ; ball left mover
  521.  
  522.     ld a,(ballY)        ; load the ball's Y value AGAIN
  523.     sub 1                ; decrease it by one, to move it left
  524.     ld (ballY),a        ; save the Y value AGAIN
  525.     jp showball            ; ok, we have sucessfully moved it either up and left, or down
  526.                         ; and left. its time to show that. So we jump to showball.
  527. ;end  ball left mover
  528.  
  529.  
  530. nosubY:                    ; the ball is at the left of the screen    
  531.                         ; so we need to reset the left-right flag
  532.                         ; to move the ball right next cycle
  533.  
  534.     ld a,1                ; load the right flag value(0=L, 1=R)
  535.     ld (ballLR),a        ; set the right motion flag.
  536.     jp showball            ; we have sucessfully moved up or down, and bounced off the left wall.
  537.                         ; because we are now moving right, we need to show that. Lets go update
  538.                         ; the screen.
  539.  
  540. ballright:                ; we jumped here because the ballLR flag was set to 1. So, we need to
  541.                         ; check the ball's Y position, see if it is too far right, if so, then
  542.                         ; reset the flag to make it bounce. If not, then we increase the Y val.
  543.                           
  544.     ld a, (ballY)        ; monkies always look
  545.     cp 18                ; is the ball at the far right of the screen?
  546.     jp z, noaddY         ; jump if it is. go on if it isn't.
  547.  
  548.  
  549.                         ; the ball is not at the bottom of the screen
  550.                         ; we need to move the ball down a space.
  551. ; ball right mover
  552.  
  553.     ld a,(ballY)        ; apes always say it.
  554.     add a,1                ; increase the Y value
  555.     ld (ballY),a        ; re-store the Y value from a
  556.  
  557.     jp showball            ; ok, so we have sucessfully moved up or down, and moved it right.
  558.                         ; now it is time for us to update the graphics
  559. ; end ball right mover
  560.  
  561. noaddY:                    ; we jumped here because the ball is at the right of the screen
  562.                         ; and needs to be bounced off the wall. So, lets reset that flag!
  563.     xor a                ; a=0
  564.     ld (ballLR),a        ; we set the ballLR directional flag with 0, because we are bouncing
  565.                         ; it off the right wall, and it needs to go left now. L=0. R=1 
  566.     jp showball            ; Ok, so we have either moved up or down sucessfully, and also bounced
  567.                         ; off the right wall. now we need to update the graphics.
  568.  
  569. showball:                ; WHOOHOO! we are amost done! Well, When I say We, I mean me. By the way
  570.                         ; Do you know what I hate about school? It's the smell! ;p
  571.                         ;
  572.                         ; Ok, we have come far. Lets look at our original todo list.
  573.                         ;
  574.                         ; CHECK a. get input from the user
  575.                         ; CHECK b. store input from the user
  576.                         ; CHECK c. calculate game data (e.x a ball moving)
  577.                         ; CHECK d. evaluate game data
  578.                         ; BZZZZ e. draw graphics
  579.                         ; CHECK f. check to see if the game is over.
  580.                         ; 
  581.                         ; what do we have left to do in our game loop? I'm sorry, the correct
  582.                         ; answer is letter E. We have done all of these calculations, all this
  583.                         ; bounds checking, and quite frankly, It is time to give the user some
  584.                         ; eye candy. Here's the easy part. All we need to do is show a few 
  585.                         ; graphics, based on the values we recieved earlier. What values, you 
  586.                         ; ask? Well, all we need to show is: the pad w/ its x and y vals, and
  587.                         ; the ball with it's x and y vals. Along with this, we need to use
  588.                         ; the temp x and y vals we have accumulated so far to erase anything old
  589.  
  590. ; clearing ball
  591.     ld a,(tmpX)            ; load up the ball's old X value
  592.     ld (_curRow),a        ; load that x value into curRow
  593.     ld a,(tmpY)            ; load up the ball's old Y value
  594.     ld (_curCol),a        ; they're magically delicious, but I like 'em too
  595.     ld hl, blnk            ; load hl with the stuff at blnk (blank ball)
  596.     call _puts            ; clear that old ball!
  597. ; end clearing ball.
  598.  
  599. ; new ball                ; we have the old gone, so bring in the new stuff.
  600.     ld a,(ballX)        ; load up the most recent X value
  601.     ld (_curRow),a        ; put it into the row
  602.     ld a,(ballY)        ; load up the most recent Y value
  603.     ld (_curCol),a        ; put it into the col
  604.     ld hl, ball            ; load the new ball
  605.     call _puts            ; show the new ball
  606. ;end new ball
  607.  
  608. ;copy ball current to temp    ; next time around, we will have a new x and y, so we will want
  609.                             ; to clear the old one.
  610.     ld a,(ballX)            ; load the current X into a
  611.     ld (tmpX),a                ; ... into temporary
  612.     ld a,(ballY)            ; load the current Y into a
  613.     ld (tmpY),a                ; ... into temporary
  614. ;end copy current ball to tmp
  615.  
  616.  
  617. ; clearing pad                ; just like with the ball, we clear the old paddle
  618.     ld a,(tmpPadX)            ; By now, I hope that you have figured out that padX never changes
  619.     ld (_curRow),a            ; but we still have it there, just in case I change the game.
  620.     ld a,(tmpPadY)            ; If I wanted to free some space up, I could always remove it.
  621.     sub 1                    ; for our blank pad
  622.     ld (_curCol),a            ; but space isn't my first issue here.
  623.     ld hl, Padblnk
  624.     call _puts
  625. ; end clearing pad
  626.  
  627. ; load new pad                ; noting new, nothing special
  628.     ld a,(padY)                ; same old, same old
  629.     ld (_curCol),a            ; exactly the same as above
  630.     ld a,(padX)                ; so why don't I add some ansi art?
  631.     ld (_curRow),a            ; or is it ascii?
  632.     ld hl, Pad                ;        _,_
  633.     call _puts                ;  <^> <{';'}> <^> S U P E R 
  634. ; end load new pad            ;    \\__,/\/\,__// A S M 
  635. ; copy current pad to temp..;     '---|S|---'   M A N
  636.     ld a, (padY)            ;       /' '\      
  637.     ld (tmpPadY),a            ;      / /-\ \     or... Sam USA, Per. MN
  638.     ld a, (padX)            ;    _/ /---\ \_  (Wait, I don't live in Per, MN. Oh well.)
  639.     ld (tmpPadX),a            ;   |__/     \__|  how about Samper Us, man!
  640. ; end copy current pad to temp pad            (possibly holding your tounge, while saying
  641.                             ;                   sample us, man!)
  642.  
  643.     jp getKeyPress             ; Its time to lather, rinse, and repeat, until either the user
  644.                             ; presses the exit key, or the user screws up and drops the ball.
  645.  
  646.  
  647. ExitMe:                        ; We jumped here because either our user sucks at pong, or
  648.                             ; they got tired of the cheezy graphics. At any rate, we need
  649.                             ; to print out their high score, give some props to me, and get out.
  650.  
  651.     call _clrScrn            ; not only clears the screen, but cleans in those hard to reach
  652.     call _clrLCD            ; places.
  653.  
  654. printscores:                ; We want the user to know how much they suc... I mean rule, so here
  655.                             ; is where we can do that.
  656.  
  657.     xor a                    ; curRow, curCol, both at 0.
  658.     ld (_curRow), a
  659.     ld (_curCol), a
  660.  
  661.     ld hl, gmvr                ; load up the gameover message.
  662.     call _puts                ; print that bad boy out.
  663.  
  664.     ld a,2                    ; next up is...
  665.     ld (_curRow), a            ; the you scored message
  666.     xor a                    ; xor a = ld a,0
  667.     ld (_curCol), a            ; foo
  668.  
  669.     ld hl,msg                ; "Your score is: "
  670.     call _puts                ; send out that mean sucka.
  671.  
  672.     ld hl,0000h                ; We are clearing the 16 bit register pair, so we can get
  673.                             ; the score, and print it out.
  674.  
  675.     ld a, (score)            ; We load the score into a.
  676.     ld l,a                    ; we move it into l, or the lower half of the 16 bit register
  677.                             ; hl
  678.  
  679.     xor a                    ;load 0 into a, for next thing...
  680.  
  681.     call _dispAHL            ; _dispAHL displays the value of the 24 bit register, AHL. It puts
  682.                             ; it on the screen, and advances the cursor. When using this, we
  683.                             ; need to make sure that the values we have are the values we want.
  684.                             ; for instance, any values in the a register, h register, or l
  685.                             ; register will affect output. So, here is what we have done
  686.                             ; (lets say our score is 5.)
  687.                             ; AHL: %????????,????????,???????? = ?
  688.                             ; ld hl, 000h
  689.                             ; AHL: %????????,00000000,00000000 = ?
  690.                             ; ld a, (score)
  691.                             ; AHL: %00000101,00000000,00000000 = 327680, not 5
  692.                             ; ld l,a
  693.                             ; AHL: %00000101,00000000,00000101 = 327685, not 5
  694.                             ; xor a
  695.                             ; AHL: %00000000,00000000,00000101 = 5, BINGO!
  696.                             
  697.  
  698.     ld a,4                    ; go down to row 4
  699.     ld (_curRow), a            
  700.     xor a                    ; column 0
  701.     ld (_curCol), a
  702.  
  703.     ld hl,me                ; load hl with my name
  704.     call _puts                ; give me maddd props
  705.  
  706.  
  707.     ld a,5                    ; next row
  708.     ld (_curRow), a
  709.     xor a                    ; same column
  710.     ld (_curCol), a
  711.  
  712.     ld hl,email                ; flash my email
  713.     call _puts                ; super duper maddd props
  714.     
  715.     ld a,6
  716.     ld (_curRow),a
  717.     xor a
  718.     ld (_curCol),a
  719.     ld hl,quitmsg
  720.     call _puts 
  721.  
  722. press:
  723.     call _getkey            ; Wait for user to press any key.
  724.     cp 006h
  725.     jr nz,press
  726.     
  727.     ld a,7                    ; move the curRow down two, so it doesnt overwrite my email
  728.     ld (_curRow), a            
  729.     
  730.     call 4AADh                ; re-enable the run indic.
  731.     ret                        ; return to "where we were" before prgm exec.
  732. Intro:        .db "BounceBall!        F1=Easy ... F5=Diffucult",0
  733. msg:        .db "Your score is: ",0
  734. gmvr:        .db "Game Over!",0
  735. me:            .db "Sean Smith",0
  736. email:        .db "afrosean@hotmail.com",0
  737. quitmsg:    .db "enter to exit.",0
  738. ball:        .db "O",0        
  739. blnk:        .db " ",0
  740. Pad:        .db "-===-",0
  741. Padblnk:    .db "       ",0
  742. ballX:        .db 0            ; 8 bit variables... ball x
  743. ballY:        .db 0            ; ball y
  744. tmpX:        .db 0            ; temp ball x value
  745. tmpY:        .db 0            ; temp ball y value
  746. ballUD        .db 0            ; ball up down directional flag
  747. ballLR        .db 0            ; ball left right directional flag
  748. padX:        .db 0            ; paddle x value
  749. padY:        .db 0            ; paddle y value
  750. tmpPadX:    .db 0            ; temp paddle x value
  751. tmpPadY:    .db 0            ; temp paddle y value
  752. Hard:        .db 0            ; speed control (really a loop value)
  753. score:        .db 0            ; stores score
  754.     .end                    ; goodbye