11 changed files with 304 additions and 77 deletions
Binary file not shown.
@ -1 +1,66 @@ |
|||
controller.asm |
|||
SECTION "ram_controller", WRAM0 |
|||
controller_curkeys: ds 1 |
|||
controller_newkeys: ds 1 |
|||
|
|||
SECTION "Controller", ROM0 |
|||
|
|||
InitController: |
|||
ld a, 0 |
|||
ld [controller_curkeys], a |
|||
ld [controller_newkeys], a |
|||
ret |
|||
|
|||
; Controller reading ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|||
|
|||
; This controller reading routine is optimized for size. |
|||
; It stores currently pressed keys in controller_curkeys (1=pressed) and |
|||
; keys newly pressed since last read in controller_newkeys, with the same |
|||
; nibble ordering as the Game Boy Advance. |
|||
; 76543210 |
|||
; |||||||+- A |
|||
; ||||||+-- B |
|||
; |||||+--- Select |
|||
; ||||+---- Start |
|||
; |||+----- Right |
|||
; ||+------ Left |
|||
; |+------- Up |
|||
; +-------- Down |
|||
; R |
|||
; L (just kidding) |
|||
|
|||
UpdateController: |
|||
; Poll half the controller |
|||
ld a,P1F_4 |
|||
call .onenibble |
|||
ld b,a ; B7-4 = 1; B3-0 = unpressed buttons |
|||
|
|||
; Poll the other half |
|||
ld a,P1F_5 |
|||
call .onenibble |
|||
swap a ; A3-0 = unpressed directions; A7-4 = 1 |
|||
xor b ; A = pressed buttons + directions |
|||
ld b,a ; B = pressed buttons + directions |
|||
|
|||
; And release the controller |
|||
ld a,P1F_N |
|||
ld [rP1],a |
|||
|
|||
; Combine with previous controller_curkeys to make controller_newkeys |
|||
ld a, [controller_curkeys] |
|||
xor b ; A = keys that changed state |
|||
and b ; A = keys that changed to pressed |
|||
ld [controller_newkeys], a |
|||
ld a,b |
|||
ld [controller_curkeys], a |
|||
ret |
|||
|
|||
.onenibble: |
|||
ldh [rP1],a ; switch the key matrix |
|||
ldh a,[rP1] ; ignore value while waiting for the key matrix to settle |
|||
ldh a,[rP1] |
|||
ldh a,[rP1] |
|||
ldh a,[rP1] |
|||
ldh a,[rP1] |
|||
ldh a,[rP1] ; the actual read |
|||
or $F0 ; A7-4 = 1; A3-0 = unpressed keys |
|||
ret |
|||
|
Binary file not shown.
Binary file not shown.
@ -1,26 +1,43 @@ |
|||
; File generated by rgblink |
|||
|
|||
00:0200 textwriter_map |
|||
00:131D DrawActiveText.drawletter |
|||
00:1331 DrawActiveText.checkNewline |
|||
00:1353 DrawActiveText.continue |
|||
00:1347 DrawActiveText.checkRepeatOnce |
|||
00:12D3 StartText |
|||
00:12F1 DrawActiveText |
|||
00:12D7 ClearWindow |
|||
00:132E DrawActiveText.afterLoading |
|||
00:1348 DrawActiveText.checkPausing |
|||
00:1344 DrawActiveText.closingAll |
|||
00:136E DrawActiveText.checkDelay |
|||
00:135E DrawActiveText.continuingNextLine |
|||
00:137D DrawActiveText.delayFinished |
|||
00:139C DrawActiveText.drawletter |
|||
00:13AE DrawActiveText.checkContinuing |
|||
00:13D8 DrawActiveText.continue |
|||
00:13BA DrawActiveText.checkNewline |
|||
00:13CE DrawActiveText.checkRepeatOnce |
|||
00:12EA StartText |
|||
00:1313 DrawActiveText |
|||
00:1280 InitWindow |
|||
00:0037 GameLoop.mainloop |
|||
00:0031 GameLoop |
|||
00:0000 HelloWorldStr |
|||
00:0029 Memfill |
|||
00:002E WaitVBlank |
|||
00:0020 Memcpy |
|||
00:0029 Memfill.repeatFill |
|||
00:0029 UpdateController.onenibble |
|||
00:0009 UpdateController |
|||
00:0000 InitController |
|||
00:016C GameLoop.mainloop |
|||
00:0166 GameLoop |
|||
00:00BB HelloWorldStr |
|||
00:0159 Memfill |
|||
00:0163 WaitVBlank |
|||
00:0150 Memcpy |
|||
00:0159 Memfill.repeatFill |
|||
00:015E Memfill16.repeatFill |
|||
00:015E Memfill16 |
|||
00:0061 Start |
|||
00:0280 Page1 |
|||
00:1280 Page1End |
|||
00:C005 textwriter_curdelay |
|||
00:C002 textwriter_curletter |
|||
00:C003 textwriter_posx |
|||
00:C004 textwriter_posy |
|||
00:C006 textwriter_active |
|||
00:C002 textwriter_posx |
|||
00:C003 textwriter_posy |
|||
00:C007 textwriter_ending |
|||
00:C008 textwriter_pausing |
|||
00:C005 textwriter_active |
|||
00:C004 textwriter_curdelay |
|||
00:C006 textwriter_starting |
|||
00:C000 textwriter_curtext |
|||
00:C00A controller_newkeys |
|||
00:C009 controller_curkeys |
|||
|
Loading…
Reference in new issue