joypad in its own file + optionally skip intro by compiling with DIRECT_TO_GAME
This commit is contained in:
@@ -1,64 +1,5 @@
|
|||||||
INCLUDE "hardware.inc"
|
INCLUDE "hardware.inc"
|
||||||
|
|
||||||
Section "Joypad memory", HRAM
|
|
||||||
; Bits 0..7 are A, B, Select, Start, Right, Left, Up, Down
|
|
||||||
JoypadPressed: ds 1
|
|
||||||
JoypadWasPressed: ds 1
|
|
||||||
JoypadDown: ds 1
|
|
||||||
|
|
||||||
EXPORT ReadJoypad
|
|
||||||
SECTION "Read Joypad", ROM0
|
|
||||||
ReadJoypad:
|
|
||||||
; read directions
|
|
||||||
ld a, P1F_5
|
|
||||||
ldh [rP1], a
|
|
||||||
ldh a, [rP1]
|
|
||||||
ldh a, [rP1]
|
|
||||||
ldh a, [rP1]
|
|
||||||
ldh a, [rP1]
|
|
||||||
and a, $0F
|
|
||||||
swap a ; move into high nibble
|
|
||||||
ld b, a
|
|
||||||
|
|
||||||
; read buttons
|
|
||||||
ld a, P1F_4
|
|
||||||
ldh [rP1], a
|
|
||||||
ldh a, [rP1]
|
|
||||||
ldh a, [rP1]
|
|
||||||
ldh a, [rP1]
|
|
||||||
ldh a, [rP1]
|
|
||||||
and a, $0F
|
|
||||||
|
|
||||||
; merge directions and buttons
|
|
||||||
; complement so that active buttons read as 1
|
|
||||||
or a, b
|
|
||||||
cpl
|
|
||||||
|
|
||||||
; store currently pressed buttons
|
|
||||||
ldh [JoypadPressed], a
|
|
||||||
|
|
||||||
; reset joypad
|
|
||||||
ld a, $30
|
|
||||||
ldh [rP1], a
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
SECTION "Update joypad", ROM0
|
|
||||||
UpdateJoypad:
|
|
||||||
; compute & store just pressed buttons
|
|
||||||
ldh a, [JoypadPressed]
|
|
||||||
ld b, a
|
|
||||||
ldh a, [JoypadWasPressed]
|
|
||||||
cpl
|
|
||||||
and a, b
|
|
||||||
ldh [JoypadDown], a
|
|
||||||
|
|
||||||
; update was pressed
|
|
||||||
ld a, b
|
|
||||||
ldh [JoypadWasPressed], a
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
Section "Edit memory", HRAM
|
Section "Edit memory", HRAM
|
||||||
SelectX: ds 1
|
SelectX: ds 1
|
||||||
SelectY: ds 1
|
SelectY: ds 1
|
||||||
@@ -70,10 +11,6 @@ InitEdit:
|
|||||||
ldh [SelectX], a
|
ldh [SelectX], a
|
||||||
ld a, 18
|
ld a, 18
|
||||||
ldh [SelectY], a
|
ldh [SelectY], a
|
||||||
xor a
|
|
||||||
ldh [JoypadDown], a
|
|
||||||
ldh [JoypadPressed], a
|
|
||||||
ldh [JoypadWasPressed], a
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
69
Code/joypad.asm
Normal file
69
Code/joypad.asm
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
INCLUDE "hardware.inc"
|
||||||
|
|
||||||
|
Section "Joypad memory", HRAM
|
||||||
|
; Bits 0..7 are A, B, Select, Start, Right, Left, Up, Down
|
||||||
|
JoypadPressed: ds 1
|
||||||
|
JoypadWasPressed: ds 1
|
||||||
|
JoypadDown: ds 1
|
||||||
|
|
||||||
|
EXPORT ReadJoypad
|
||||||
|
SECTION "Read Joypad", ROM0
|
||||||
|
ReadJoypad:
|
||||||
|
; read directions
|
||||||
|
ld a, P1F_5
|
||||||
|
ldh [rP1], a
|
||||||
|
ldh a, [rP1]
|
||||||
|
ldh a, [rP1]
|
||||||
|
ldh a, [rP1]
|
||||||
|
ldh a, [rP1]
|
||||||
|
and a, $0F
|
||||||
|
swap a ; move into high nibble
|
||||||
|
ld b, a
|
||||||
|
|
||||||
|
; read buttons
|
||||||
|
ld a, P1F_4
|
||||||
|
ldh [rP1], a
|
||||||
|
ldh a, [rP1]
|
||||||
|
ldh a, [rP1]
|
||||||
|
ldh a, [rP1]
|
||||||
|
ldh a, [rP1]
|
||||||
|
and a, $0F
|
||||||
|
|
||||||
|
; merge directions and buttons
|
||||||
|
; complement so that active buttons read as 1
|
||||||
|
or a, b
|
||||||
|
cpl
|
||||||
|
|
||||||
|
; store currently pressed buttons
|
||||||
|
ldh [JoypadPressed], a
|
||||||
|
|
||||||
|
; reset joypad
|
||||||
|
ld a, $30
|
||||||
|
ldh [rP1], a
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
SECTION "Update joypad", ROM0
|
||||||
|
UpdateJoypad:
|
||||||
|
; compute & store just pressed buttons
|
||||||
|
ldh a, [JoypadPressed]
|
||||||
|
ld b, a
|
||||||
|
ldh a, [JoypadWasPressed]
|
||||||
|
cpl
|
||||||
|
and a, b
|
||||||
|
ldh [JoypadDown], a
|
||||||
|
|
||||||
|
; update was pressed
|
||||||
|
ld a, b
|
||||||
|
ldh [JoypadWasPressed], a
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
EXPORT InitJoypad
|
||||||
|
SECTION "Init joypad", ROM0
|
||||||
|
InitJoypad:
|
||||||
|
xor a
|
||||||
|
ldh [JoypadDown], a
|
||||||
|
ldh [JoypadPressed], a
|
||||||
|
ldh [JoypadWasPressed], a
|
||||||
|
ret
|
||||||
@@ -20,7 +20,9 @@ Start:
|
|||||||
xor a
|
xor a
|
||||||
ldh [rIF], a
|
ldh [rIF], a
|
||||||
|
|
||||||
|
IF !DEF(DIRECT_TO_GAME)
|
||||||
call ScrollNintendoOut
|
call ScrollNintendoOut
|
||||||
|
ENDC
|
||||||
|
|
||||||
; disable screen
|
; disable screen
|
||||||
halt
|
halt
|
||||||
@@ -68,6 +70,7 @@ Start:
|
|||||||
ld bc, 20 * 18
|
ld bc, 20 * 18
|
||||||
call MemoryCopy
|
call MemoryCopy
|
||||||
|
|
||||||
|
call InitJoypad
|
||||||
call InitAutomata
|
call InitAutomata
|
||||||
call InitEdit
|
call InitEdit
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user