read joypad in vbl so that inputs are more reactive
This commit is contained in:
@@ -2,11 +2,13 @@ INCLUDE "hardware.inc"
|
|||||||
|
|
||||||
Section "Joypad memory", HRAM
|
Section "Joypad memory", HRAM
|
||||||
; Bits 0..7 are A, B, Select, Start, Right, Left, Up, Down
|
; Bits 0..7 are A, B, Select, Start, Right, Left, Up, Down
|
||||||
JoypadDown: ds 1
|
|
||||||
JoypadPressed: ds 1
|
JoypadPressed: ds 1
|
||||||
|
JoypadWasPressed: ds 1
|
||||||
|
JoypadDown: ds 1
|
||||||
|
|
||||||
SECTION "Update joypad", ROM0
|
EXPORT ReadJoypad
|
||||||
UpdateJoypad:
|
SECTION "Read Joypad", ROM0
|
||||||
|
ReadJoypad:
|
||||||
; read directions
|
; read directions
|
||||||
ld a, P1F_5
|
ld a, P1F_5
|
||||||
ldh [rP1], a
|
ldh [rP1], a
|
||||||
@@ -26,28 +28,35 @@ UpdateJoypad:
|
|||||||
ldh a, [rP1]
|
ldh a, [rP1]
|
||||||
ldh a, [rP1]
|
ldh a, [rP1]
|
||||||
and a, $0F
|
and a, $0F
|
||||||
|
|
||||||
; merge directions and buttons
|
; merge directions and buttons
|
||||||
; complement so that active buttons read as 1
|
; complement so that active buttons read as 1
|
||||||
or a, b
|
or a, b
|
||||||
cpl
|
cpl
|
||||||
|
|
||||||
; backup all buttons in B
|
; store currently pressed buttons
|
||||||
ld b, a
|
ldh [JoypadPressed], a
|
||||||
|
|
||||||
; store just pressed buttons
|
; reset joypad
|
||||||
|
ld a, $30
|
||||||
|
ldh [rP1], a
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
SECTION "Update joypad", ROM0
|
||||||
|
UpdateJoypad:
|
||||||
|
; compute & store just pressed buttons
|
||||||
ldh a, [JoypadPressed]
|
ldh a, [JoypadPressed]
|
||||||
|
ld b, a
|
||||||
|
ldh a, [JoypadWasPressed]
|
||||||
cpl
|
cpl
|
||||||
and a, b
|
and a, b
|
||||||
ldh [JoypadDown], a
|
ldh [JoypadDown], a
|
||||||
|
|
||||||
; store currently pressed buttons
|
; update was pressed
|
||||||
ld a, b
|
ld a, b
|
||||||
ldh [JoypadPressed], a
|
ldh [JoypadWasPressed], a
|
||||||
|
|
||||||
; reset joypad
|
|
||||||
ld a, $30
|
|
||||||
ldh [rP1], a
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
Section "Edit memory", HRAM
|
Section "Edit memory", HRAM
|
||||||
@@ -64,6 +73,7 @@ InitEdit:
|
|||||||
xor a
|
xor a
|
||||||
ldh [JoypadDown], a
|
ldh [JoypadDown], a
|
||||||
ldh [JoypadPressed], a
|
ldh [JoypadPressed], a
|
||||||
|
ldh [JoypadWasPressed], a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,19 @@ Rendered: ds 2 ; progressing pointer in old buffer
|
|||||||
|
|
||||||
SECTION "V-Blank Interrupt Handler", ROM0[$40]
|
SECTION "V-Blank Interrupt Handler", ROM0[$40]
|
||||||
VBlankInterruptHandler:
|
VBlankInterruptHandler:
|
||||||
jr LCDStatInterruptHandler
|
; save registers
|
||||||
|
push af
|
||||||
|
push bc
|
||||||
|
call ReadJoypad
|
||||||
|
jr LCDStatInterruptHandler.start
|
||||||
|
|
||||||
SECTION "LCD Stat Interrupt Handler", ROM0[$48]
|
SECTION "LCD Stat Interrupt Handler", ROM0[$48]
|
||||||
LCDStatInterruptHandler:
|
LCDStatInterruptHandler:
|
||||||
; save registers
|
; save registers
|
||||||
push af
|
push af
|
||||||
push bc
|
push bc
|
||||||
|
|
||||||
|
.start
|
||||||
; check there are tiles to render
|
; check there are tiles to render
|
||||||
ldh a, [LinesLeft]
|
ldh a, [LinesLeft]
|
||||||
or a
|
or a
|
||||||
|
|||||||
Reference in New Issue
Block a user