- Joined: 15 Feb 2016
- Posts: 19
|
Noobish controller logic problem
Posted: Fri Dec 01, 2017 7:35 pm
|
I've been puzzling over this one for a few days now. I haven't been able to get any response from the controller. What's frustrating is I have been able to make this work with other projects I've tinkered with. Unfortunately, when tidying up my code, I must have changed something or missed some important detail. There is a chance that a bug is hidden somewhere else but I'm hoping there is a flaw with my movement logic and someone can point out the obvious for me...!
I suspect the sprite table loader works just fine, because I've been able to put in coordinates and graphics and I have no problems there.
I know the ControllerState variable is working because I can see it change in the memory editor when I press the keys, yet no change to the sprite itself.
Thanks for your time!
;Called in my main loop just before WaitForVBlank
;No diagonal movement
Control:
ld a, (ControllerState) ;%11111110
and JoyUp ;%00000001
jr z, ShipUp
ld a, (ControllerState)
and JoyDown
jr z, ShipDown
ld a, (ControllerState)
and JoyLeft
jr z, ShipLeft
ld a, (ControllerState)
and JoyRight
jr z, ShipRight
jp DoneMove
ShipUp:
ld a, Up
ld (ShipDirection), a
ld a, (MainSpriteY)
sbc a, 2
ld (MainSpriteY), a
jr DoneMove
ShipDown:
ld a, Down
ld (ShipDirection), a
ld a, (MainSpriteY)
add a, 2
ld (MainSpriteY), a
jr DoneMove
ShipLeft:
ld a, Up
ld (ShipDirection), a
ld a, (MainSpriteX)
sbc a, 2
ld (MainSpriteX), a
jr DoneMove
ShipRight:
ld a, Down
ld (ShipDirection), a
ld a, (MainSpriteX)
add a, 2
ld (MainSpriteX), a
jr DoneMove
DoneMove:
ret
SATLoader:
ld b, $31 ;Number of sprites
ld hl, $00
ld de, MainSpriteY
SATVerticalLoop:
ld a, l
out (VDPControlPort),a
ld a,$40 | $3f
out (VDPControlPort),a
ld a, (de)
out (VDPDataPort),a
inc de
inc hl
djnz SATVerticalLoop
ld b, $31 ;Number of sprites
ld hl, $80
ld de, MainSpriteY
SATHorizontalLoop:
ld a, l
out (VDPControlPort),a
ld a,$40 | $3f
out (VDPControlPort),a
ld a, (de)
out (VDPDataPort),a
inc de
inc hl
inc hl
djnz SATHorizontalLoop
ld b, $31 ;Number of sprites
ld hl, $81
ld de, 0
SATTilesLoop:
ld a, l
out (VDPControlPort),a
ld a,$40 | $3f
out (VDPControlPort),a
ld a, e
out (VDPDataPort),a
inc de
inc hl
inc hl
djnz SATTilesLoop
;Terminator
ld a, 32
out (VDPControlPort),a
ld a,$40 | $3f
out (VDPControlPort),a
ld a, $d0
out (VDPDataPort),a
[/code]
|