Last active
March 1, 2021 07:49
-
-
Save wheremyfoodat/c1876ae86e0648d420db6ece293c78ed to your computer and use it in GitHub Desktop.
Tetris evil joypad code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; This is the code in Tetris which infinitely resets if you return 0 from the joypad register | |
Evil: ; CODE XREF: sub_20C+E9↓j | |
ROM:02C4 call pollJOYP ; stores inverted joypad state into 0xFF80 (upper nibble = dpad, low nibble = buttons) | |
ROM:02C7 call sub_2F8 | |
ROM:02CA call sub_7FF0 | |
ROM:02CD ld a, [$FF80] ; read the joypad state that pollJOYP previously cached | |
ROM:02CF and $F ; only keep the buttons, dump the dpad | |
ROM:02D1 cp $F ; see if all buttons are pressed | |
ROM:02D3 jp z, reset ; if yes reset lmfao | |
ROM:29A6 ; =============== S U B R O U T I N E ======================================= | |
pollJOYP: ; CODE XREF: sub_20C:Evil↑p | |
ROM:29A6 ld a, $20 ; ' ' ; enable dpad | |
ROM:29A8 ld [rJOYP], a | |
ROM:29AA ld a, [rJOYP] ; poll it | |
ROM:29AC ld a, [rJOYP] ; poll it harder | |
ROM:29AE ld a, [rJOYP] ; poll it harder harder | |
ROM:29B0 ld a, [rJOYP] ; poll it harder harder harder | |
ROM:29B2 cpl ; invert so that pressed buttons = 1 | |
ROM:29B3 and $F ; ignore misc bits | |
ROM:29B5 swap a ; store the dpad in the upper nibble of a, then cache it into b | |
ROM:29B7 ld b, a | |
ROM:29B8 ld a, $10 ; enable buttons | |
ROM:29BA ld [rJOYP], a | |
ROM:29BC ld a, [rJOYP] ; poll them even harder | |
ROM:29BE ld a, [rJOYP] ; haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarder | |
ROM:29C0 ld a, [rJOYP] | |
ROM:29C2 ld a, [rJOYP] | |
ROM:29C4 ld a, [rJOYP] | |
ROM:29C6 ld a, [rJOYP] | |
ROM:29C8 ld a, [rJOYP] | |
ROM:29CA ld a, [rJOYP] | |
ROM:29CC ld a, [rJOYP] | |
ROM:29CE ld a, [rJOYP] | |
ROM:29D0 cpl ; invert so that pressed buttons = 1 | |
ROM:29D1 and $F ; ignore misc bits | |
ROM:29D3 or b ; a's upper nibble now corresponds to the dpad, and the lower nibble corresponds to the buttons | |
ROM:29D4 ld c, a ; cache pad into c | |
ROM:29D5 ld a, [$FF80] | |
ROM:29D7 xor c | |
ROM:29D8 and c | |
ROM:29D9 ld [$FF81], a | |
ROM:29DB ld a, c ; restore pad into a | |
ROM:29DC ld [$FF80], a ; store pad into 0xFF80 | |
ROM:29DE ld a, $30 ; '0' ; disable both pad config bits | |
ROM:29E0 ld [rJOYP], a | |
ROM:29E2 ret | |
ROM:29E2 ; End of function pollJOYP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment