Skip to content

Instantly share code, notes, and snippets.

@JettMonstersGoBoom
Created December 18, 2020 00:31
Show Gist options
  • Save JettMonstersGoBoom/8de74c46416814beea58d55bb7093d7c to your computer and use it in GitHub Desktop.
Save JettMonstersGoBoom/8de74c46416814beea58d55bb7093d7c to your computer and use it in GitHub Desktop.
Sprite Sprite Collision tester
.file [name="collision.prg", segments="CODE"]
.segment ZP [start=$02]
spr_spr: .byte 0
.segment CODE [start=$0801]
.segment CODE
BasicUpstart2(Start)
// Our code
Start:
{
sei
lda #$ff
sta $d015
// copy garbage to sprites for random placement
ldx #$00
spritePos:
lda $e000,x
sta $d000,x
inx
cpx #$10
bne spritePos
waitloop:
lda $d012
cmp #$f3
bne waitloop
// joy
lda #$01
sta $d020
jsr JoyStick.Poll
// move sprites
lda #$05
sta $d020
lda #$00
sta $d01e
clc
lda $d000
adc JoyStick.dx
sta $d000
clc
lda $d001
adc JoyStick.dy
sta $d001
// grab collision
lda $d01e
sta spr_spr
sta $d020
jmp waitloop
}
JoyStick:
{
.segment ZP
dx: .word 0
dy: .byte 0
bt: .byte 0
.segment CODE
Poll:
{
lda #$00
sta dx+1
lda $dc00 // get input from port 2 only
ldy #0 // this routine reads and decodes the
ldx #0 // joystick/firebutton input data in
lsr // the accumulator. this least significant
bcs djr0 // 5 bits contain the switch closure
dey // information. if a switch is closed then it
djr0:
lsr // produces a zero bit. if a switch is open then
bcs djr1 // it produces a one bit. The joystick dir-
iny // ections are right, left, forward, backward
djr1:
lsr // bit3=right, bit2=left, bit1=backward,
bcs djr2 // bit0=forward and bit4=fire button.
dex // at rts time dx and dy contain 2's compliment
djr2:
lsr // direction numbers i.e. $ff=-1, $00=0, $01=1.
bcs djr3 // dx=1 (move right), dx=-1 (move left),
inx // dx=0 (no x change). dy=-1 (move up screen),
djr3:
lsr // dy=0 (move down screen), dy=0 (no y change).
stx dx // the forward joystick position corresponds
sty dy // to move up the screen and the backward
cpx #$ff
bne pos
stx dx+1
pos:
sta bt
rts // position to move down screen.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment