home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 83 / asm / source / sos / bouncy.z80 next >
Encoding:
Text File  |  2001-07-01  |  4.0 KB  |  206 lines

  1. ;Dijpupon 1998
  2. ;Bouncy Ball v1.0
  3. ;June 17, 1998
  4.  
  5. .NOLIST
  6.  
  7. #define equ .EQU
  8. #define EQU .equ
  9. #define end .end
  10.  
  11. #include "ti83asm.inc"
  12. #include "tokens.inc"
  13. #include "sos.inc"
  14.  
  15. .LIST
  16.  
  17. ;~~~~~~~~~~ vars ~~~~~~~~~~
  18. #define    xc    8265h        ;x coordinate
  19. #define yc    8266h        ;y coordinate
  20. #define vert    8267h        ;vertical direction (0=up 1=down)
  21. #define horiz    8268h        ;horizontal direction (0=left 1=right)
  22.  
  23. .org     9327h
  24.     
  25. ;~~~~~~~~~~ THIS IS AN SOS PROGRAM! ~~~~~~~~~~
  26.     ccf                ; SOS program
  27.     jr    z,start_of_program    ; not detectable until INSTALL is run
  28.     .dw    sos_libraries-$9327    ; libraries
  29.     .dw    title            ; title to be displayed
  30.  
  31. ;~~~~~~~~~~ begin ~~~~~~~~~~
  32. start_of_program:
  33.     ld    b,80        ;upper bound
  34.     call    vector1        ;random
  35.     ld    (xc),a        ;store x-coord value
  36.     ld    b,49
  37.     call    vector1        ;random
  38.     ld    (yc),a        ;y-coord
  39.     ld    b,2
  40.     call    vector1        ;random
  41.     ld    (vert),a    ;vertical direction
  42.     ld    b,2
  43.     call    vector1        ;random
  44.     ld    (horiz),a    ;horizontal direction
  45.  
  46. ;~~~~~~~~~~ move ~~~~~~~~~~
  47. move:
  48.     call    draw_b        ;draw the ball
  49. move_l:
  50.     call    _grbufcpy_v    ;copy the buffer to the screen
  51.     call    _getK        ;\
  52.     call    _op2toop1    ; }get a key
  53.     call    _convop1    ;/
  54.     cp    22        ;[MODE]
  55.     call    z,waitkey    ;pressed?... pause
  56.     cp    45        ;[CLEAR]
  57.     ret    z        ;exit and return to SOS
  58.     call    draw_b        ;take away the ball
  59.     call    u_d        ;move up or down
  60.     call    l_r        ;move left or right
  61.     call    draw_b        ;draw the ball
  62.     jr    move_l        ;loop back
  63.  
  64. ;~~~~~~~~~~ up/down ~~~~~~~~~
  65. u_d:
  66.     ld    a,(yc)
  67.     ld    b,a        ;store y-coord in b
  68.     ld    a,(vert)    
  69.     cp    0        ;up
  70.     jr    nz,down        ;jump to "down:"
  71. up:
  72.     ld    a,b
  73.     cp    0        ;at the edge of the screen (graph buffer)
  74.     jr    nz,up_nch
  75.     inc    a        ;yc=yc+1
  76.     ld    (yc),a
  77.     ld    a,1        ;reverse direction (down)
  78.     ld    (vert),a
  79.     ret            ;return    
  80. up_nch:
  81.     dec    a        ;yc=yc-1
  82.     ld    (yc),a
  83.     ret            ;return
  84. down:
  85.     ld    a,b
  86.     cp    48        ;edge (this is determined by the dimensions of the sprite)
  87.     jr    nz,dw_nch
  88.     dec    a        ;yc=yc-1
  89.     ld    (yc),a
  90.     ld    a,0        ;reverse direction (up)
  91.     ld    (vert),a    
  92.     ret            ;return
  93. dw_nch:
  94.     inc    a
  95.     ld    (yc),a        ;yc=yc+1
  96.     ret            ;return
  97.  
  98. ;~~~~~~~~~~ left/right ~~~~~~~~~~~
  99. l_r:
  100.     ld    a,(xc)
  101.     ld    b,a        ;store x-coord in b
  102.     ld    a,(horiz)
  103.     cp    0        ;left
  104.     jr    nz,right    ;right
  105. left:
  106.     ld    a,b
  107.     cp    0        ;edge
  108.     jr    nz,l_nch
  109.     inc    a        ;xc=xc+1
  110.     ld    (xc),a
  111.     ld    a,1        ;reverse direction (right)
  112.     ld    (horiz),a
  113.     ret            ;return    
  114. l_nch:
  115.     dec    a        ;xc=xc-1
  116.     ld    (xc),a
  117.     ret            ;return
  118. right:
  119.     ld    a,b
  120.     cp    79        ;edge
  121.     jr    nz,r_nch
  122.     dec    a        ;xc=xc-1
  123.     ld    (xc),a
  124.     ld    a,0        ;reverse direction (left)
  125.     ld    (horiz),a
  126.     ret            ;return
  127. r_nch:
  128.     inc    a        ;xc=xc+1
  129.     ld    (xc),a
  130.     ret            ;return
  131.  
  132. ;~~~~~~~~~~ draw ball ~~~~~~~~~~
  133. draw_b:
  134.     ld    b,16        ;b = height
  135.     ld    a,(yc)
  136.     ld    l,a        ;l = y-coord
  137.     ld    a,(xc)        ;a = x-coord
  138.     ld    ix,ball_l    ;ix = upper left portion of ball
  139.     call    vector0        ;ZLIB XOR sprite routine
  140.     ld    b,16        ;b = height
  141.     ld    a,(yc)
  142.     ld    l,a        ;l = y-coord
  143.     ld    a,(xc)        ;a = x-coord
  144.     ld    c,8
  145.     add    a,c        ;this sprite is 8 pixels right from x-coord
  146.     ld    ix,ball_r    ;ix = upper right portion of ball
  147.     call    vector0        ;ZLIB XOR sprite routine
  148.     ret            ;return
  149.  
  150. ;~~~~~~~~~~ wait for a key ~~~~~~~~~~
  151. waitkey:
  152.     call    _getK        ;value returned in op2
  153.     call    _op2toop1    ;store op2 in op1
  154.     call    _convop1    ;a = op1
  155.     cp    0        ;no key pressed
  156.     jr    z,waitkey    ;keep looping until a key is pressed
  157.     ret            ;return
  158.  
  159. ;~~~~~~~~~~ text ~~~~~~~~~~
  160. title:    .db    "Bouncy Ball v1.0 by Dijpupon"
  161.     .db    0
  162.  
  163. ;~~~~~~~~~~ sprites ~~~~~~~~~~
  164. ball_l:
  165.     .db    %00000111    ;left side of ball
  166.     .db    %00011111
  167.     .db    %00111111
  168.     .db    %01111111
  169.     .db    %01111111
  170.     .db    %11111111
  171.     .db    %11111111
  172.     .db    %11111111
  173.     .db    %11111111
  174.     .db    %11111111
  175.     .db    %11111111
  176.     .db    %01111111
  177.     .db    %01111111
  178.     .db    %00111111
  179.     .db    %00011111
  180.     .db    %00000111
  181. ball_r
  182.     .db    %11100000    ;right side
  183.     .db    %11111000
  184.     .db    %11111100
  185.     .db    %11111110
  186.     .db    %11111110
  187.     .db    %11111111
  188.     .db    %11111111
  189.     .db    %11111111
  190.     .db    %11111111
  191.     .db    %11111111
  192.     .db    %11111111
  193.     .db    %11111110
  194.     .db    %11111110
  195.     .db    %11111100
  196.     .db    %11111000
  197.     .db    %11100000
  198.  
  199. ;~~~~~~~~~~ (libraries) ~~~~~~~~~~
  200. sos_libraries:
  201.     .db    "ZLIB",0,0,0,0,lib1,vec0    ; sprite
  202.     .db    "ZLIB",0,0,0,0,lib2,vec1    ; random
  203.     .db    $FF
  204.  
  205. .end
  206. END