diff --git a/unbricked/input/input.asm b/unbricked/input/input.asm deleted file mode 100644 index fc81de4b..00000000 --- a/unbricked/input/input.asm +++ /dev/null @@ -1,45 +0,0 @@ -; This is a simplified version of pads.z80 by PinoBatch for use in gb-asm-tutorial -; All labels are intentionally not exported to avoid confusing the reader with unfamiliar syntax. -; Once linking is introduced in part 3, a new, exported version of this file will be provided. - -SECTION "Input Variables", WRAM0 -wCurKeys: db -wNewKeys: db - -SECTION "UpdateKeys", ROM0 - -UpdateKeys: - ; Poll half the controller - ld a, JOYP_GET_BUTTONS - call .onenibble - ld b, a ; B7-4 = 1; B3-0 = unpressed buttons - - ; Poll the other half - ld a, JOYP_GET_CTRL_PAD - call .onenibble - swap a ; A3-0 = unpressed directions; A7-4 = 1 - xor a, b ; A = pressed buttons + directions - ld b, a ; B = pressed buttons + directions - - ; And release the controller - ld a, JOYP_GET_NONE - ldh [rJOYP], a - - ; Combine with previous wCurKeys to make wNewKeys - ld a, [wCurKeys] - xor a, b ; A = keys that changed state - and a, b ; A = keys that changed to pressed - ld [wNewKeys], a - ld a, b - ld [wCurKeys], a - ret - -.onenibble - ldh [rJOYP], a ; switch the key matrix - call .knownret ; burn 10 cycles calling a known ret - ldh a, [rJOYP] ; ignore value while waiting for the key matrix to settle - ldh a, [rJOYP] - ldh a, [rJOYP] ; this read counts - or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys -.knownret - ret diff --git a/unbricked/input/main.asm b/unbricked/input/main.asm index 8cf2fec5..ea8798ad 100644 --- a/unbricked/input/main.asm +++ b/unbricked/input/main.asm @@ -122,40 +122,40 @@ Right: ; ANCHOR: input-routine UpdateKeys: - ; Poll half the controller - ld a, JOYP_GET_BUTTONS - call .onenibble - ld b, a ; B7-4 = 1; B3-0 = unpressed buttons + ; Poll half the controller + ld a, JOYP_GET_BUTTONS + call .onenibble + ld b, a ; B7-4 = 1; B3-0 = unpressed buttons - ; Poll the other half - ld a, JOYP_GET_CTRL_PAD - call .onenibble - swap a ; A7-4 = unpressed directions; A3-0 = 1 - xor a, b ; A = pressed buttons + directions - ld b, a ; B = pressed buttons + directions + ; Poll the other half + ld a, JOYP_GET_CTRL_PAD + call .onenibble + swap a ; A7-4 = unpressed directions; A3-0 = 1 + xor a, b ; A = pressed buttons + directions + ld b, a ; B = pressed buttons + directions - ; And release the controller - ld a, JOYP_GET_NONE - ldh [rJOYP], a + ; And release the controller + ld a, JOYP_GET_NONE + ldh [rJOYP], a - ; Combine with previous wCurKeys to make wNewKeys - ld a, [wCurKeys] - xor a, b ; A = keys that changed state - and a, b ; A = keys that changed to pressed - ld [wNewKeys], a - ld a, b - ld [wCurKeys], a - ret + ; Combine with previous wCurKeys to make wNewKeys + ld a, [wCurKeys] + xor a, b ; A = keys that changed state + and a, b ; A = keys that changed to pressed + ld [wNewKeys], a + ld a, b + ld [wCurKeys], a + ret -.onenibble - ldh [rJOYP], a ; switch the key matrix - call .knownret ; burn 10 cycles calling a known ret - ldh a, [rJOYP] ; ignore value while waiting for the key matrix to settle - ldh a, [rJOYP] - ldh a, [rJOYP] ; this read counts - or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys -.knownret - ret + .onenibble + ldh [rJOYP], a ; switch the key matrix + call .knownret ; burn 10 cycles calling a known ret + ldh a, [rJOYP] ; ignore value while waiting for the key matrix to settle + ldh a, [rJOYP] + ldh a, [rJOYP] ; this read counts + or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys + .knownret + ret ; ANCHOR_END: input-routine ; ANCHOR: memcpy diff --git a/unbricked/title-screen/build.sh b/unbricked/title-screen/build.sh index 71cab60e..4205789a 100755 --- a/unbricked/title-screen/build.sh +++ b/unbricked/title-screen/build.sh @@ -1,6 +1,5 @@ #!/bin/sh rgbasm -o main.o main.asm -rgbasm -o input.o input.asm -rgblink -o unbricked.gb main.o input.o +rgblink -o unbricked.gb main.o rgbfix -v -p 0xFF unbricked.gb diff --git a/unbricked/title-screen/input.asm b/unbricked/title-screen/input.asm deleted file mode 100644 index 2013a818..00000000 --- a/unbricked/title-screen/input.asm +++ /dev/null @@ -1,47 +0,0 @@ -; This is a simplified version of pads.z80 by PinoBatch for use in gb-asm-tutorial -; All labels are intentionally not exported to avoid confusing the reader with unfamiliar syntax. -; Once linking is introduced in part 3, a new, exported version of this file will be provided. - -INCLUDE "hardware.inc" - -SECTION "Input Variables", WRAM0 -wCurKeys:: db -wNewKeys:: db - -SECTION "UpdateKeys", ROM0 - -UpdateKeys:: - ; Poll half the controller - ld a, JOYP_GET_BUTTONS - call .onenibble - ld b, a ; B7-4 = 1; B3-0 = unpressed buttons - - ; Poll the other half - ld a, JOYP_GET_CTRL_PAD - call .onenibble - swap a ; A3-0 = unpressed directions; A7-4 = 1 - xor a, b ; A = pressed buttons + directions - ld b, a ; B = pressed buttons + directions - - ; And release the controller - ld a, JOYP_GET_NONE - ldh [rJOYP], a - - ; Combine with previous wCurKeys to make wNewKeys - ld a, [wCurKeys] - xor a, b ; A = keys that changed state - and a, b ; A = keys that changed to pressed - ld [wNewKeys], a - ld a, b - ld [wCurKeys], a - ret - -.onenibble - ldh [rJOYP], a ; switch the key matrix - call .knownret ; burn 10 cycles calling a known ret - ldh a, [rJOYP] ; ignore value while waiting for the key matrix to settle - ldh a, [rJOYP] - ldh a, [rJOYP] ; this read counts - or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys -.knownret - ret diff --git a/unbricked/title-screen/main.asm b/unbricked/title-screen/main.asm index 184d9398..1f3077bd 100644 --- a/unbricked/title-screen/main.asm +++ b/unbricked/title-screen/main.asm @@ -115,6 +115,44 @@ Memcopy: ret ; ANCHOR_END: memcpy +; ANCHOR: input-routine +UpdateKeys: + ; Poll half the controller + ld a, JOYP_GET_BUTTONS + call .onenibble + ld b, a ; B7-4 = 1; B3-0 = unpressed buttons + + ; Poll the other half + ld a, JOYP_GET_CTRL_PAD + call .onenibble + swap a ; A7-4 = unpressed directions; A3-0 = 1 + xor a, b ; A = pressed buttons + directions + ld b, a ; B = pressed buttons + directions + + ; And release the controller + ld a, JOYP_GET_NONE + ldh [rJOYP], a + + ; Combine with previous wCurKeys to make wNewKeys + ld a, [wCurKeys] + xor a, b ; A = keys that changed state + and a, b ; A = keys that changed to pressed + ld [wNewKeys], a + ld a, b + ld [wCurKeys], a + ret + + .onenibble + ldh [rJOYP], a ; switch the key matrix + call .knownret ; burn 10 cycles calling a known ret + ldh a, [rJOYP] ; ignore value while waiting for the key matrix to settle + ldh a, [rJOYP] + ldh a, [rJOYP] ; this read counts + or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys + .knownret + ret +; ANCHOR_END: input-routine + Tiles: dw `33333333 dw `33333333 @@ -337,3 +375,9 @@ Unbricked_Title_Screen_Map_Begin: DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0 DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0 Unbricked_Title_Screen_Map_End: + +; ANCHOR: vars +SECTION "Input Variables", WRAM0 +wCurKeys: db +wNewKeys: db +; ANCHOR_END: vars