Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;global variables & constants
- speed = 1 ;speed
- intX = 255 - 24 ;x is leftSprite
- intY = 30+20 ;Y is bottomSprite
- x0 = $D000
- y0 = $D001
- xMSB = $D010
- dRight = 88-23 ;343-255 = 88 - 23 x collision threshold with msb set - sprite width
- cRight = dRight-speed ;final x collision threshold one frame before
- cLeft = 24+speed ; same
- cTop = 30 ;y collision
- cBottom = 229 ; same
- dx .byte speed
- dy .byte speed
- temp .byte 0
- inter .word ?
- * = $1000
- start
- ;init sprite & isr vector
- lda #1
- sta $d015
- lda #intX
- sta x0
- lda #intY
- sta y0
- lda $314
- sta inter
- lda $315
- sta inter+1
- sei
- lda #<main_loop
- sta $314
- lda #>main_loop
- sta $315
- cli
- rts
- ;update sprites
- main_loop
- lda x0
- ldx dx
- ldy xMSB
- cpx #128 ;direction check
- bcs goingL
- goingR
- cpy #1
- beq msbSetR
- cmp #256 - speed ;256 is for overflow - speed is for a frame before that speed is intended always > 0
- bcc endC ;just update
- lda #1
- sta xMSB
- endC clc
- adc dx
- sta x0
- ;jmp (inter)
- yUpdate
- lda y0
- ldy dy
- cpy #128 ;direction check
- bcs goingU
- goingD
- cmp #cBottom - speed
- bcc endCY ;just update
- sec
- sbc #cBottom
- sta temp
- lda #cBottom
- sec
- sbc temp
- sta y0
- ldx #-speed
- stx dy
- endCY clc
- adc dy
- sta y0
- jmp (inter) ;back to isr
- goingL
- cpy #1
- beq msbSetL
- ; if MSB is not set
- cmp #cLeft
- bcs endC ;just update
- sta temp
- lda #cLeft
- sec
- sbc temp
- sta temp
- lda #cLeft
- clc
- adc temp
- ldx #speed ;invert direction
- stx dx
- jmp (inter)
- msbSetR
- cmp #cRight + speed
- bcc endC
- sec
- sbc #cRight
- sta temp
- lda #dRight
- sec
- sbc temp
- sta x0
- lda #-speed
- sta dx
- lda x0
- jEndC jmp endC
- wrapR
- sec
- sbc #cRight
- sta temp
- lda #speed
- sec
- sbc temp
- clc
- adc #cRight
- sta x0
- lda #-speed
- sta dx
- jmp (inter)
- goingU
- cmp #cTop + 20 + speed + 1 ; +1 for bcs
- bcs endCY ;just update
- sta temp
- lda #cTop + 20
- sec
- sbc temp
- sta temp
- lda #cTop+20
- clc
- adc temp
- sta y0
- ldx #speed
- stx dy
- jmp endCY
- msbSetL
- cmp #speed + 1 ;check if we need to clear MSB, + 1 for bcs
- bcs jEndC ;trampoline to endC, just update
- sta temp
- lda speed
- sec
- sbc temp
- lda #0
- sta xMSB
- jmp endC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement