Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ti83plus.inc"
- vid = plotsscreen
- .org $9D93 ;address to which TI-OS loads the program
- .db $BB,$6D ;identifies to TI-OS that this is an asm program
- #define bullseyex savesscreen ;defines bullseyex to savescreen
- #define bullseyey savesscreen+1 ;defines bullseyey to savescreen+1
- #define playerx savesscreen+2 ;defines playerx to savescreen+2
- #define playery savesscreen+3 ;defines playery to savescreen+3
- score = savesscreen+7 ;defines score to savescreen+7
- string_buffer = op1
- time = savesscreen+25 ;defines time to savescreen+25, allowing score to have room
- invertscreen = savesscreen+32 ;defines inverscreen to savescreen+32, allowing time to have room
- redraw =savesscreen+35 ;defines redraw to savescreen+35
- randData =savesscreen+36 ;defines randData to savescreen+36
- game =savesscreen+40
- bcall(_RunIndicOff) ;turn off the Run Indicator
- set textWrite,(iy+sGrFlags) ;set the flag for inverting the screen/call (InvertVid)
- xor a ;zero out a
- ld (playerx),a ;define playerx as zero
- ld (playery),a ;define playery as zero
- ld (invertscreen),a ;define invertscreen as zero, which means not to invert and one makes the flag set to invert
- ld hl,0 ;define h and l as zero
- ld (score),hl ;define score to what hl is (which is zero at this point)
- ld hl,1000 ;define hl as 10000
- ld (time),hl ;define time to what hl is (which is 10000 at this point)
- ld (game),sp
- Show:
- call ClearVid ;clear the buffer
- call Generate ;generate the location of the bullseye
- call BullsEyed ;draws the BullsEye
- call Output ;display text1 and text 2 "Time:" and "Score"
- ld a,(invertscreen) ;load what is in invertscreen into a
- cp 1 ;check to see if a is one
- call z,InvertVid ;if a is one, invert the screen
- ld a,0 ;define a as zero
- ld (redraw),a ;define redraw to what a is
- InArrow:
- call Crosshair ;draw the crosshair
- call FastCopy ;copy the buffer to screen
- call Crosshair ;Erase crosshair
- call Timer ;goes to Timer
- ld a,$FF ;reset key port
- out (1),a ;
- ld a,$FE ;
- out (1),a ;
- in a,(1) ;
- ld b,a ;
- bit 0,b ;check if the Down arrow is being pressed
- call z,MoveDown ;if Down arrow is being pressed, goto MoveDown
- bit 1,b ;check if the Left arrow is being pressed
- call z,MoveLeft ;If Left arrow is being pressed, goto MoveLeft
- bit 2,b ;
- call z,MoveRight ;
- bit 3,b ;
- call z,MoveUp ;
- ld a,$FF ;reset key port
- out (1),a ;
- ld a,$BF ;check group that contains second and delete
- out (1),a ;
- nop \ nop ;
- in a,(1) ;
- cp $7F ;check for delete key
- ret z ;if delete was pressed, goto GameOver
- cp $DF ;check for second key
- push af ;preserve af
- call z,PlayerShot ;if second was pressed, create a player shot
- pop af ;restore af
- cp $BF ;check if mode was pressed
- call z,Invert ;if so invert the screen
- ld bc,5 ;hault code to maintain speed
- dec bc ;"
- ld a,b ;"
- or c ;"
- jr nz,$-3 ;"
- ld a,(redraw) ;define a to what redraw contains
- or a ;check to see is it was zero
- jp z,InArrow ;if it was zero then return to the top of the loop
- jp Show ;if it was not, then go to Show
- Timer:
- ld hl,(time) ;load time into hl
- dec hl ;decrease hl
- ld a,h
- or l
- jp z,GameOver
- ld (time),hl ;load hl into Time
- call OutputTime ;update time
- ret ;return to previous loop
- MoveDown:
- ld a,(playery) ;load what is in playery into a
- cp 51 ;check if at bottom edge of screen, which would be pixel 51
- ret z ;if so, then return to the previous routine
- inc a ;increase a by one, which moves the crosshair down one pixel
- ld (playery),a ;load what is in a into playery
- ret ;return to the previous routine
- MoveUp:
- ld a,(playery) ;load what is in playery into a
- or a ;check if at top edge of screen, which would be zero
- ret z ;if so, then return to the previous routine
- dec a ;decrease a by one, which moves the crosshair up one pixel
- ld (playery),a ;load what is in a into playery
- ret ;return to the previous routine
- MoveLeft:
- ld a,(playerx) ;load what is in playerx into a
- or a ;check if at far left edge of screen, which would be zero
- ret z ;if so, then return to the previous routine
- dec a ;decrease a by one, which moves the crosshair left one pixel
- ld (playerx),a ;load what is in a into playerx
- ret ;return to the previous routine
- MoveRight:
- ld a,(playerx) ;load what is in playerx into a
- cp 89 ;check if at far right edge of screen, which would be pixel 89
- ret z ;if so, then return to the previous routine
- inc a ;increase a by one, which moves the crosshair right one pixel
- ld (playerx),a ;load what is in a into playerx
- ret ;return to the previous routine
- PlayerShot:
- di ;disable the inturupts
- ld a,$FF
- out (1),a
- ld a,$BF
- out (1),a
- in a,(1)
- bit 5,a
- jr z,PlayerShot ;wait until they let go of the keys
- ei ;enable the inturupts
- ld a,(playerx) ;load what playerx is into a
- sub 4 ;subtract four from a
- ld b,a ;load a into b
- ld a,(bullseyex) ;load what bullseyex is into a
- sub b ;subtract b from a
- call Abs
- ld e,a ;load a into e
- ld h,a ;load a into h
- call Multiply
- push hl
- ld a,(playery) ;load what playery is into a
- sub 4 ;subtract four from a
- ld b,a ;load a into b
- ld a,(bullseyey) ;load what bullseyey is into a
- sub b ;subtract b from a
- call Abs
- ld e,a ;load a into e
- ld h,a ;load a into h
- call Multiply
- pop de
- add hl,de
- ex de,hl
- call Sqrt
- ld b,a
- ld a,7
- cp b ;check to see if a equals b
- jp c,Missed ;if it does, then goto Missed
- ld hl,(score) ;load what score is into hl
- ld a,8 ;define a as eight
- sub b ;subtract b from a
- ld b,0 ;define b as zero
- ld c,a ;define a into c
- add hl,bc ;add bc and hl into hl
- ld (score),hl ;load hl into score
- ld a,1 ;define a as one
- ld (redraw),a ;define redraw as a
- ret ;return to previous routine
- Multiply:
- ld l,0
- ld d,0
- sla h ; optimised 1st iteration
- jr nc,$+3
- ld l,e
- add hl,hl ;unroll 7 times
- jr nc,$+3 ;...
- add hl,de ;...
- add hl,hl ;unroll 7 times
- jr nc,$+3 ;...
- add hl,de ;...
- add hl,hl ;unroll 7 times
- jr nc,$+3 ;...
- add hl,de ;...
- add hl,hl ;unroll 7 times
- jr nc,$+3 ;...
- add hl,de ;...
- add hl,hl ;unroll 7 times
- jr nc,$+3 ;...
- add hl,de ;...
- add hl,hl ;unroll 7 times
- jr nc,$+3 ;...
- add hl,de ;...
- add hl,hl ;unroll 7 times
- jr nc,$+3 ;...
- add hl,de ;...
- ret
- Abs:
- or a
- ret p
- neg
- ret
- Sqrt:
- ld hl,0
- ld c,l
- ld b,h
- ld a,8
- SqrtLoop:
- sla e
- rl d
- adc hl,hl
- sla e
- rl d
- adc hl,hl
- scf ;can be optimised
- rl c ;with SL1 instruction
- rl b
- sbc hl,bc
- jr nc,Sqrtaddbit
- add hl,bc
- dec c
- Sqrtaddbit:
- inc c
- res 0,c
- dec a
- jr nz,SqrtLoop
- ld a,c
- rr b
- rra
- ret
- Missed:
- ld hl,playerx ;give hl address of player_x
- ld a,(hl) ;load a player_x
- inc hl ;increment hl to player_y
- ld l,(hl) ;load l player_y
- ld b,6
- ld ix,BulletHole
- jp DrawImage
- BullsEyed:
- ld hl,bullseyex ;give hl address of player_x
- ld a,(hl) ;load a player_x
- inc hl ;increment hl to player_y
- ld l,(hl) ;load l player_y
- ld b,15
- ld c,2
- ld ix,BullsEye
- jp LargeSprite
- Crosshair:
- ld hl,playerx ;give hl address of player_x
- ld a,(hl) ;load a player_x
- inc hl ;increment hl to player_y
- ld l,(hl) ;load l player_y
- ld b,7
- ld ix,CrossHairSprite
- DrawImage:
- ld e,l
- ld h,$00
- ld d,h
- add hl,de
- add hl,de
- add hl,hl
- add hl,hl
- ld e,a
- and $07
- ld c,a
- srl e
- srl e
- srl e
- add hl,de
- ld de,vid
- add hl,de
- PutSpriteLoop1:
- ld d,(ix)
- ld e,$00
- ld a,c
- or a
- jr z,PutSpriteSkip1
- PutSpriteLoop2:
- srl d
- rr e
- dec a
- jr nz,PutSpriteLoop2
- PutSpriteSkip1:
- ld a,(hl)
- xor d
- ld (hl),a
- inc hl
- ld a,(hl)
- xor e
- ld (hl),a
- ld de,$0B
- add hl,de
- inc ix
- djnz PutSpriteLoop1
- ret
- ;draw a picture
- ;input: ix->sprite
- ;a=x
- ;l=y
- ;b=height (in pixels)
- ;c=width (in bytes, e.g. 2 would be 16)
- ;All registers are destroyed except bc', de', hl'
- LargeSprite:
- di
- ex af,af'
- ld a,c
- push af
- ex af,af'
- ld e,l
- ld h,$00
- ld d,h
- add hl,de
- add hl,de
- add hl,hl
- add hl,hl
- ld e,a
- and $07
- ld c,a
- srl e
- srl e
- srl e
- add hl,de
- ld de,vid
- add hl,de
- LargeSpriteLoop1:
- push hl
- LargeSpriteLoop2:
- ld d,(ix)
- ld e,$00
- ld a,c
- or a
- jr z,LargeSpriteSkip1
- LargeSpriteLoop3:
- srl d
- rr e
- dec a
- jr nz,LargeSpriteLoop3
- LargeSpriteSkip1:
- ld a,(hl)
- xor d
- ld (hl),a
- inc hl
- ld a,(hl)
- xor e
- ld (hl),a
- inc ix
- ex af,af'
- dec a
- push af
- ex af,af'
- pop af
- jr nz,LargeSpriteLoop2
- pop hl
- pop af
- push af
- ex af,af'
- ld de,$0C
- add hl,de
- djnz LargeSpriteLoop1
- pop af
- ret
- FastCopy:
- di
- ld a,$80
- out ($10),a
- ld hl,vid-12-(-(12*64)+1)
- ld a,$20
- ld c,a
- inc hl
- dec hl
- FastCopyAgain:
- ld b,64
- inc c
- ld de,-(12*64)+1
- out ($10),a
- add hl,de
- ld de,10
- FastCopyLoop:
- add hl,de
- inc hl
- inc hl
- inc de
- ld a,(hl)
- out ($11),a
- dec de
- djnz FastCopyLoop
- ld a,c
- cp $2B+1
- jr nz,FastCopyAgain
- ei
- ret
- ClearVid:
- ld bc,767 ;there are 768 bytes of video memory, we're doing one less
- ld hl,vid
- ld de,vid+1 ;the cause for the one less
- ld (hl),0 ;put a 0, then clear it
- ldir ;loads (hl) into (de) then decrements bc until it equals zero
- ret
- InvertCheck:
- ld a,1 ;load one into a
- ld (invertscreen),a ;load one into invertscreen
- jp InvertVid ;invert the buffer
- Invert:
- di ;disable inturupts
- ld a,$FF
- out (1),a ;reset keyport
- ld a,$BF ;check group that contains second and delete
- out (1),a
- in a,(1)
- cp $BF ;check to see if mode was pressed
- jr z,Invert ;loop back until mode is unpressed
- ei ;enable inturupts
- ld a,(invertscreen) ;load what is in invertscreen into a
- or a ;check to see if it is zero
- jp z,InvertCheck ;if it is zero goto InvertCheck
- xor a ;zero out a
- ld (invertscreen),a ;define invertscreen to zero
- jp nz,InvertVid ;reinvert the buffer, which would make it normal
- ld a,1 ;define a as one
- ld (redraw),a ;define redraw to what a is (which is one at this point)
- ret ;return to the previous routine
- InvertVid:
- ld bc,768 ;load the number 768 into bc
- ld hl,vid ;load the vid into hl
- Loop:
- ld a,(hl) ;load what hl contains into a
- cpl ;
- ld (hl),a ;hl to what a is
- inc hl ;increase hl by one
- dec bc ;decrease bc by one
- ld a,b ;define what b is into a
- or c ;check to see if c is zero
- jr nz,Loop ;if zero, then loop back to Loop
- ret ;return to previous routine when finished
- Generate:
- ld b,80 ;set the max bound on the x axes for the routine Random
- call Random ;randomize a x coordinate for the bullseye
- ld (bullseyex),a ;load what a is into bullseyex
- ld b,42 ;set the max bound on the y axes for the routine Random
- call Random ;randomize a y coordinate for the bullseye
- ld (bullseyey),a ;load what a is into bullseyey
- ret ;return to the previous routine
- ;Generate a random number
- ;input b=upper bound
- ;ouput a=answer 0<=a<b
- ;all registers are preserved except: af and bc
- Random:
- push hl
- push de
- ld hl,(randData) ;randData is not defined, since it will be random it can be anything
- ld a,r
- ld d,a
- ld e,(hl)
- add hl,de
- add a,l
- xor h
- ld (randData),hl
- sbc hl,hl
- ld e,a
- ld d,h
- RandomLoop:
- add hl,de
- djnz RandomLoop
- ld a,h
- pop de
- pop hl
- ret
- DispHL:
- ld a,0
- DispAHL:
- ld (pencol),de
- xor a
- call ConvertAHL
- ld hl,string_buffer
- bcall(_vputs)
- ret
- ConvertAHL:
- push hl
- ld hl,string_buffer
- ld (hl),0
- ld de,string_buffer+1
- ld bc,17
- ldir
- pop hl
- ld e,a
- Convertloop:
- push hl
- push de
- ld hl,string_buffer+14
- ld de,string_buffer+15
- ld bc,16
- lddr
- pop de
- pop hl
- ld d,10
- call Div24
- add a,'0'
- ld (string_buffer),a
- ld a,e
- or h
- or l
- jr nz,Convertloop
- ret
- Div24:
- xor a
- ld b,24
- Div24loop:
- add hl,hl ; unroll 24 times
- rl e ; ...
- rla ; ...
- cp d ; ...
- jr c,$+4 ; ...
- sub d ; ...
- inc l ; ...
- djnz Div24loop
- ret
- Output:
- ld hl,$3A00
- ld (PenCol),hl
- ld hl,Text1
- bcall(_VPutS)
- ld hl,$3A39
- ld (PenCol),hl
- ld hl,Text2
- bcall(_VPutS)
- ld hl,(score)
- ld d,58 ;y
- ld e,79 ;x
- call DispHL
- ret
- OutputTime:
- ld hl,(time)
- ld d,58
- ld e,18
- call DispHL
- ret
- GameOver:
- ld sp,(game)
- ret ;returns control to the system
- CrossHairSprite:
- .db $10,$10,$28,$C6,$28,$10,$10
- BulletHole:
- .db $00,$28,$54,$38,$54,$28
- BullsEye:
- .db $03,$80,$0C,$60,$10,$10,$23,$88,$44,$44,$48,$24,$91,$12,$92,$92
- .db $91,$12,$48,$24,$44,$44,$23,$88,$10,$10,$0C,$60,$03,$80,$00,$00
- Text1:
- .db "Time:",0
- Text2:
- .db "Score:",0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement