Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "ti83plus.inc"
  2. vid = plotsscreen
  3. .org $9D93                      ;address to which TI-OS loads the program
  4. .db $BB,$6D                     ;identifies to TI-OS that this is an asm program
  5. #define bullseyex savesscreen   ;defines bullseyex to savescreen
  6. #define bullseyey savesscreen+1 ;defines bullseyey to savescreen+1
  7. #define playerx savesscreen+2   ;defines playerx to savescreen+2
  8. #define playery savesscreen+3   ;defines playery to savescreen+3
  9. score = savesscreen+7           ;defines score to savescreen+7
  10. string_buffer = op1            
  11. time = savesscreen+25           ;defines time to savescreen+25, allowing score to have room
  12. invertscreen = savesscreen+32   ;defines inverscreen to savescreen+32, allowing time to have room
  13. redraw  =savesscreen+35         ;defines redraw to savescreen+35
  14. randData    =savesscreen+36     ;defines randData to savescreen+36
  15. game =savesscreen+40
  16.  
  17.     bcall(_RunIndicOff)         ;turn off the Run Indicator
  18.     set textWrite,(iy+sGrFlags) ;set the flag for inverting the screen/call (InvertVid)
  19.     xor a                       ;zero out a
  20.     ld (playerx),a              ;define playerx as zero
  21.     ld (playery),a              ;define playery as zero
  22.     ld (invertscreen),a         ;define invertscreen as zero, which means not to invert and one makes the flag set to invert
  23.     ld hl,0                     ;define h and l as zero
  24.     ld (score),hl               ;define score to what hl is (which is zero at this point)
  25.     ld hl,1000                  ;define hl as 10000
  26.     ld (time),hl                ;define time to what hl is (which is 10000 at this point)
  27.     ld (game),sp
  28. Show:
  29.     call ClearVid               ;clear the buffer
  30.     call Generate               ;generate the location of the bullseye
  31.     call BullsEyed              ;draws the BullsEye
  32.     call Output                 ;display text1 and text 2 "Time:" and "Score"
  33.     ld a,(invertscreen)         ;load what is in invertscreen into a
  34.     cp 1                        ;check to see if a is one
  35.     call z,InvertVid            ;if a is one, invert the screen
  36.     ld a,0                      ;define a as zero
  37.     ld (redraw),a               ;define redraw to what a is
  38. InArrow:
  39.     call Crosshair              ;draw the crosshair
  40.     call FastCopy               ;copy the buffer to screen
  41.     call Crosshair              ;Erase crosshair
  42.     call Timer                  ;goes to Timer
  43.     ld a,$FF                    ;reset key port
  44.     out (1),a                   ;
  45.     ld a,$FE                    ;
  46.     out (1),a                   ;
  47.     in a,(1)                    ;
  48.     ld b,a                      ;
  49.     bit 0,b                     ;check if the Down arrow is being pressed
  50.     call z,MoveDown             ;if Down arrow is being pressed, goto MoveDown
  51.     bit 1,b                     ;check if the Left arrow is being pressed
  52.     call z,MoveLeft             ;If Left arrow is being pressed, goto MoveLeft
  53.     bit 2,b                     ;
  54.     call z,MoveRight            ;
  55.     bit 3,b                     ;
  56.     call z,MoveUp               ;
  57.     ld a,$FF                    ;reset key port
  58.     out (1),a                   ;
  59.     ld a,$BF                    ;check group that contains second and delete
  60.     out (1),a                   ;
  61.     nop \ nop                   ;
  62.     in a,(1)                    ;
  63.     cp $7F                      ;check for delete key
  64.     ret z               ;if delete was pressed, goto GameOver
  65.     cp $DF                      ;check for second key
  66.     push af                     ;preserve af
  67.     call z,PlayerShot           ;if second was pressed, create a player shot
  68.     pop af                      ;restore af
  69.     cp $BF                      ;check if mode was pressed
  70.     call z,Invert               ;if so invert the screen
  71.     ld bc,5                     ;hault code to maintain speed
  72.     dec bc                      ;"
  73.     ld a,b                      ;"
  74.     or c                        ;"
  75.     jr nz,$-3                   ;"
  76.     ld a,(redraw)               ;define a to what redraw contains
  77.     or a                        ;check to see is it was zero
  78.     jp z,InArrow                ;if it was zero then return to the top of the loop
  79.     jp Show                     ;if it was not, then go to Show
  80.  
  81. Timer:
  82.     ld hl,(time)                ;load time into hl
  83.     dec hl                      ;decrease hl
  84.     ld a,h
  85.     or l
  86.     jp z,GameOver
  87.     ld (time),hl                ;load hl into Time
  88.     call OutputTime             ;update time
  89.     ret                         ;return to previous loop
  90.  
  91. MoveDown:
  92.     ld a,(playery)              ;load what is in playery into a
  93.     cp 51                       ;check if at bottom edge of screen, which would be pixel 51
  94.     ret z                       ;if so, then return to the previous routine
  95.     inc a                       ;increase a by one, which moves the crosshair down one pixel
  96.     ld (playery),a              ;load what is in a into playery
  97.     ret                         ;return to the previous routine
  98.  
  99. MoveUp:
  100.     ld a,(playery)              ;load what is in playery into a
  101.     or a                        ;check if at top edge of screen, which would be zero
  102.     ret z                       ;if so, then return to the previous routine
  103.     dec a                       ;decrease a by one, which moves the crosshair up one pixel
  104.     ld (playery),a              ;load what is in a into playery
  105.     ret                         ;return to the previous routine
  106.  
  107. MoveLeft:
  108.     ld a,(playerx)              ;load what is in playerx into a
  109.     or a                        ;check if at far left edge of screen, which would be zero
  110.     ret z                       ;if so, then return to the previous routine
  111.     dec a                       ;decrease a by one, which moves the crosshair left one pixel
  112.     ld (playerx),a              ;load what is in a into playerx
  113.     ret                         ;return to the previous routine
  114.  
  115. MoveRight:
  116.     ld a,(playerx)              ;load what is in playerx into a
  117.     cp 89                       ;check if at far right edge of screen, which would be pixel 89
  118.     ret z                       ;if so, then return to the previous routine
  119.     inc a                       ;increase a by one, which moves the crosshair right one pixel
  120.     ld (playerx),a              ;load what is in a into playerx
  121.     ret                         ;return to the previous routine
  122.  
  123. PlayerShot:
  124.     di                          ;disable the inturupts
  125.     ld a,$FF
  126.     out (1),a
  127.     ld a,$BF
  128.     out (1),a
  129.     in a,(1)
  130.     bit 5,a
  131.     jr z,PlayerShot             ;wait until they let go of the keys
  132.     ei                          ;enable the inturupts
  133.     ld a,(playerx)              ;load what playerx is into a
  134.     sub 4                       ;subtract four from a
  135.     ld b,a                      ;load a into b
  136.     ld a,(bullseyex)            ;load what bullseyex is into a
  137.     sub b                       ;subtract b from a
  138.     call Abs
  139.     ld e,a                      ;load a into e
  140.     ld h,a                      ;load a into h
  141.     call Multiply
  142.     push hl
  143.     ld a,(playery)              ;load what playery is into a
  144.     sub 4                       ;subtract four from a
  145.     ld b,a                      ;load a into b
  146.     ld a,(bullseyey)            ;load what bullseyey is into a
  147.     sub b                       ;subtract b from a
  148.     call Abs
  149.     ld e,a                      ;load a into e
  150.     ld h,a                      ;load a into h
  151.     call Multiply
  152.     pop de
  153.     add hl,de
  154.     ex de,hl
  155.     call Sqrt
  156.     ld b,a
  157.     ld a,7
  158.     cp b                        ;check to see if a equals b
  159.     jp c,Missed                 ;if it does, then goto Missed
  160.     ld hl,(score)               ;load what score is into hl
  161.     ld a,8                      ;define a as eight
  162.     sub b                       ;subtract b from a
  163.     ld b,0                      ;define b as zero
  164.     ld c,a                      ;define a into c
  165.     add hl,bc                   ;add bc and hl into hl
  166.     ld (score),hl               ;load hl into score
  167.     ld a,1                      ;define a as one
  168.     ld (redraw),a               ;define redraw as a
  169.     ret                         ;return to previous routine
  170.  
  171. Multiply:
  172.     ld l,0
  173.     ld d,0
  174.     sla h                       ; optimised 1st iteration
  175.     jr nc,$+3
  176.     ld l,e
  177.     add hl,hl                   ;unroll 7 times
  178.     jr nc,$+3                   ;...
  179.     add hl,de                   ;...
  180.     add hl,hl                   ;unroll 7 times
  181.     jr nc,$+3                   ;...
  182.     add hl,de                   ;...
  183.     add hl,hl                   ;unroll 7 times
  184.     jr nc,$+3                   ;...
  185.     add hl,de                   ;...
  186.     add hl,hl                   ;unroll 7 times
  187.     jr nc,$+3                   ;...
  188.     add hl,de                   ;...
  189.     add hl,hl                   ;unroll 7 times
  190.     jr nc,$+3                   ;...
  191.     add hl,de                   ;...
  192.     add hl,hl                   ;unroll 7 times
  193.     jr nc,$+3                   ;...
  194.     add hl,de                   ;...
  195.     add hl,hl                   ;unroll 7 times
  196.     jr nc,$+3                   ;...
  197.     add hl,de                   ;...
  198.     ret
  199.  
  200. Abs:
  201.     or a
  202.     ret p
  203.     neg
  204.     ret
  205.  
  206. Sqrt:
  207.     ld hl,0
  208.     ld c,l
  209.     ld b,h
  210.     ld a,8
  211. SqrtLoop:
  212.     sla e
  213.     rl d
  214.     adc hl,hl
  215.     sla e
  216.     rl d
  217.     adc hl,hl
  218.     scf                         ;can be optimised
  219.     rl c                        ;with SL1 instruction
  220.     rl b
  221.     sbc hl,bc
  222.     jr nc,Sqrtaddbit
  223.     add hl,bc
  224.     dec c
  225. Sqrtaddbit:
  226.     inc c
  227.     res 0,c
  228.     dec a
  229.     jr nz,SqrtLoop
  230.     ld a,c
  231.     rr b
  232.     rra
  233.     ret
  234.  
  235. Missed:
  236.     ld hl,playerx               ;give hl address of player_x
  237.     ld a,(hl)                   ;load a player_x
  238.     inc hl                      ;increment hl to player_y
  239.     ld l,(hl)                   ;load l player_y
  240.     ld b,6
  241.     ld ix,BulletHole
  242.     jp DrawImage
  243.  
  244. BullsEyed:
  245.     ld hl,bullseyex             ;give hl address of player_x
  246.     ld a,(hl)                   ;load a player_x
  247.     inc hl                      ;increment hl to player_y
  248.     ld l,(hl)                   ;load l player_y
  249.     ld b,15
  250.     ld c,2
  251.     ld ix,BullsEye
  252.     jp LargeSprite
  253.  
  254. Crosshair:
  255.     ld hl,playerx               ;give hl address of player_x
  256.     ld a,(hl)                   ;load a player_x
  257.     inc hl                      ;increment hl to player_y
  258.     ld l,(hl)                   ;load l player_y
  259.     ld b,7
  260.     ld ix,CrossHairSprite
  261.  
  262. DrawImage:
  263.     ld e,l
  264.     ld h,$00
  265.     ld d,h
  266.     add hl,de
  267.     add hl,de
  268.     add hl,hl
  269.     add hl,hl
  270.     ld e,a
  271.     and $07
  272.     ld c,a
  273.     srl e
  274.     srl e
  275.     srl e
  276.     add hl,de
  277.     ld de,vid
  278.     add hl,de
  279. PutSpriteLoop1:
  280.     ld d,(ix)
  281.     ld e,$00
  282.     ld a,c
  283.     or a
  284.     jr z,PutSpriteSkip1
  285. PutSpriteLoop2:
  286.     srl d
  287.     rr e
  288.     dec a
  289.     jr nz,PutSpriteLoop2
  290. PutSpriteSkip1:
  291.     ld a,(hl)
  292.     xor d
  293.     ld (hl),a
  294.     inc hl
  295.     ld a,(hl)
  296.     xor e
  297.     ld (hl),a
  298.     ld de,$0B
  299.     add hl,de
  300.     inc ix
  301.     djnz PutSpriteLoop1
  302.     ret
  303.  
  304. ;draw a picture
  305. ;input: ix->sprite
  306. ;a=x
  307. ;l=y
  308. ;b=height (in pixels)
  309. ;c=width (in bytes, e.g. 2 would be 16)
  310. ;All registers are destroyed except bc', de', hl'
  311. LargeSprite:
  312.     di
  313.     ex af,af'
  314.     ld a,c
  315.     push af
  316.     ex af,af'
  317.     ld e,l
  318.     ld h,$00
  319.     ld d,h
  320.     add hl,de
  321.     add hl,de
  322.     add hl,hl
  323.     add hl,hl
  324.     ld e,a
  325.     and $07
  326.     ld c,a
  327.     srl e
  328.     srl e
  329.     srl e
  330.     add hl,de
  331.     ld de,vid
  332.     add hl,de
  333. LargeSpriteLoop1:
  334.     push hl
  335. LargeSpriteLoop2:
  336.     ld d,(ix)
  337.     ld e,$00
  338.     ld a,c
  339.     or a
  340.     jr z,LargeSpriteSkip1
  341. LargeSpriteLoop3:
  342.     srl d
  343.     rr e
  344.     dec a
  345.     jr nz,LargeSpriteLoop3
  346. LargeSpriteSkip1:
  347.     ld a,(hl)
  348.     xor d
  349.     ld (hl),a
  350.     inc hl
  351.     ld a,(hl)
  352.     xor e
  353.     ld (hl),a
  354.     inc ix
  355.     ex af,af'
  356.     dec a
  357.     push af
  358.     ex af,af'
  359.     pop af
  360.     jr nz,LargeSpriteLoop2
  361.     pop hl
  362.     pop af
  363.     push af
  364.     ex af,af'
  365.     ld de,$0C
  366.     add hl,de
  367.     djnz LargeSpriteLoop1
  368.     pop af
  369.     ret
  370.  
  371. FastCopy:
  372.     di
  373.     ld a,$80
  374.     out ($10),a
  375.     ld hl,vid-12-(-(12*64)+1)
  376.     ld a,$20
  377.     ld c,a
  378.     inc hl
  379.     dec hl
  380. FastCopyAgain:
  381.     ld b,64
  382.     inc c
  383.     ld de,-(12*64)+1
  384.     out ($10),a
  385.     add hl,de
  386.     ld de,10
  387. FastCopyLoop:
  388.     add hl,de
  389.     inc hl
  390.     inc hl
  391.     inc de
  392.     ld a,(hl)
  393.     out ($11),a
  394.     dec de
  395.     djnz FastCopyLoop
  396.     ld a,c
  397.     cp $2B+1
  398.     jr nz,FastCopyAgain
  399.     ei
  400.     ret
  401.  
  402. ClearVid:
  403.     ld bc,767                   ;there are 768 bytes of video memory, we're doing one less
  404.     ld hl,vid
  405.     ld de,vid+1                 ;the cause for the one less
  406.     ld (hl),0                   ;put a 0, then clear it
  407.     ldir                        ;loads (hl) into (de) then decrements bc until it equals zero
  408.     ret
  409.  
  410. InvertCheck:
  411.     ld a,1                      ;load one into a
  412.     ld (invertscreen),a         ;load one into invertscreen
  413.     jp InvertVid                ;invert the buffer
  414.  
  415. Invert:
  416.     di                          ;disable inturupts
  417.     ld a,$FF
  418.     out (1),a                   ;reset keyport
  419.     ld a,$BF                    ;check group that contains second and delete
  420.     out (1),a
  421.     in a,(1)
  422.     cp $BF                      ;check to see if mode was pressed
  423.     jr z,Invert                 ;loop back until mode is unpressed
  424.     ei                          ;enable inturupts
  425.     ld a,(invertscreen)         ;load what is in invertscreen into a
  426.     or a                        ;check to see if it is zero
  427.     jp z,InvertCheck            ;if it is zero goto InvertCheck
  428.     xor a                       ;zero out a
  429.     ld (invertscreen),a         ;define invertscreen to zero
  430.     jp nz,InvertVid             ;reinvert the buffer, which would make it normal
  431.     ld a,1                      ;define a as one
  432.     ld (redraw),a               ;define redraw to what a is (which is one at this point)
  433.     ret                         ;return to the previous routine
  434.    
  435. InvertVid:
  436.     ld bc,768                   ;load the number 768 into bc
  437.     ld hl,vid                   ;load the vid into hl
  438. Loop:
  439.     ld a,(hl)                   ;load what hl contains into a
  440.     cpl ;
  441.     ld (hl),a                   ;hl to what a is
  442.     inc hl                      ;increase hl by one
  443.     dec bc                      ;decrease bc by one
  444.     ld a,b                      ;define what b is into a
  445.     or c                        ;check to see if c is zero
  446.     jr nz,Loop                  ;if zero, then loop back to Loop
  447.     ret                         ;return to previous routine when finished
  448.  
  449. Generate:
  450.     ld b,80                     ;set the max bound on the x axes for the routine Random
  451.     call Random                 ;randomize a x coordinate for the bullseye
  452.     ld (bullseyex),a            ;load what a is into bullseyex
  453.     ld b,42                     ;set the max bound on the y axes for the routine Random
  454.     call Random                 ;randomize a y coordinate for the bullseye
  455.     ld (bullseyey),a            ;load what a is into bullseyey
  456.     ret                         ;return to the previous routine
  457.  
  458. ;Generate a random number
  459. ;input b=upper bound
  460. ;ouput a=answer 0<=a<b
  461. ;all registers are preserved except: af and bc
  462. Random:
  463.     push hl
  464.     push de
  465.     ld hl,(randData)            ;randData is not defined, since it will be random it can be anything
  466.     ld a,r
  467.     ld d,a
  468.     ld e,(hl)
  469.     add hl,de
  470.     add a,l
  471.     xor h
  472.     ld (randData),hl
  473.     sbc hl,hl
  474.     ld e,a
  475.     ld d,h
  476. RandomLoop:
  477.     add hl,de
  478.     djnz RandomLoop
  479.     ld a,h
  480.     pop de
  481.     pop hl
  482.     ret
  483.  
  484. DispHL:
  485.     ld a,0
  486. DispAHL:
  487.     ld (pencol),de
  488.     xor a
  489.     call ConvertAHL
  490.     ld hl,string_buffer
  491.     bcall(_vputs)
  492.     ret
  493. ConvertAHL:
  494.     push hl
  495.     ld hl,string_buffer
  496.     ld (hl),0
  497.     ld de,string_buffer+1
  498.     ld bc,17
  499.     ldir
  500.     pop hl
  501.     ld e,a
  502. Convertloop:
  503.     push hl
  504.     push de
  505.     ld hl,string_buffer+14
  506.     ld de,string_buffer+15
  507.     ld bc,16
  508.     lddr
  509.     pop de
  510.     pop hl
  511.     ld d,10
  512.     call Div24
  513.     add a,'0'
  514.     ld (string_buffer),a
  515.     ld a,e
  516.     or h
  517.     or l
  518.     jr nz,Convertloop
  519.     ret
  520. Div24:
  521.     xor a
  522.     ld b,24
  523. Div24loop:
  524.     add     hl,hl          ; unroll 24 times
  525.     rl     e          ; ...
  526.     rla               ; ...
  527.     cp     d          ; ...
  528.     jr     c,$+4          ; ...
  529.     sub     d          ; ...
  530.     inc     l          ; ...
  531.     djnz Div24loop
  532.     ret
  533.  
  534. Output:
  535.     ld hl,$3A00
  536.     ld (PenCol),hl
  537.     ld hl,Text1
  538.     bcall(_VPutS)
  539.     ld hl,$3A39
  540.     ld (PenCol),hl
  541.     ld hl,Text2
  542.     bcall(_VPutS)
  543.     ld hl,(score)
  544.     ld d,58 ;y
  545.     ld e,79 ;x
  546.     call DispHL
  547.     ret
  548.    
  549. OutputTime:
  550.     ld hl,(time)
  551.     ld d,58
  552.     ld e,18
  553.     call DispHL
  554.     ret
  555.    
  556. GameOver:
  557.     ld sp,(game)
  558.     ret                     ;returns control to the system
  559.  
  560. CrossHairSprite:
  561.     .db $10,$10,$28,$C6,$28,$10,$10
  562.  
  563. BulletHole:
  564.     .db $00,$28,$54,$38,$54,$28
  565.  
  566. BullsEye:
  567.     .db $03,$80,$0C,$60,$10,$10,$23,$88,$44,$44,$48,$24,$91,$12,$92,$92
  568.     .db $91,$12,$48,$24,$44,$44,$23,$88,$10,$10,$0C,$60,$03,$80,$00,$00
  569.  
  570. Text1:
  571.     .db "Time:",0
  572.  
  573. Text2:
  574.     .db "Score:",0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement