aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-23 14:00:22 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-02-04 22:00:06 +0100
commit91c63997e16be4041cd382b42f0a08dcb9173789 (patch)
tree0d672200a77c5ba17ed2f358084806fe071bc894
parent772ae5e0ba662ca0b75b51d29cf09f57e57f5d5a (diff)
downloadcode.nes-91c63997e16be4041cd382b42f0a08dcb9173789.tar.gz
code.nes-91c63997e16be4041cd382b42f0a08dcb9173789.zip
Move macros globally
It's a pity that cl65 allows macros to be written inside of scopes while their usage is only possible from the global scope. Hence, by allowing programmers to write macros inside of scopes, it feels like 'cc65' is actually lying to programmers. 'nasm' double downs on this by simply refusing to assemble such a case, which is the sensible thing to do if it's not allowed anyways. Long story short, macro statements have to be written in the global scope and so this commit moves the READ_CONTROLLER one from the `space` example globally. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
-rw-r--r--space/include/joypad.s44
1 files changed, 22 insertions, 22 deletions
diff --git a/space/include/joypad.s b/space/include/joypad.s
index 8711c28..365a7a8 100644
--- a/space/include/joypad.s
+++ b/space/include/joypad.s
@@ -7,6 +7,28 @@
;; the bitmask of the buttons that are pressed from each controller.
;;;
+;; READ_CONTROLLER reads the input from the controller mapped into the given
+;; port, and saves the state into the given `buttons` address.
+;; Implementation taken from NESHacker's example of smb3-like movement.
+.macro READ_CONTROLLER port, buttons
+ lda Joypad::m_inv_buttons
+ tay
+ lda #1
+ sta port
+ sta Joypad::m_inv_buttons
+ lsr
+ sta port
+:
+ lda port
+ lsr
+ rol Joypad::m_inv_buttons
+ bcc :-
+ tya
+ eor Joypad::m_inv_buttons
+ and Joypad::m_inv_buttons
+ sta buttons
+.endmacro
+
.scope Joypad
;; Button masks.
BUTTON_A = 1 << 7
@@ -31,28 +53,6 @@
m_buttons1 = $22
m_buttons2 = $23
- ;; READ_CONTROLLER reads the input from the controller mapped into the given
- ;; port, and saves the state into the given `buttons` address.
- ;; Implementation taken from NESHacker's example of smb3-like movement.
- .macro READ_CONTROLLER port, buttons
- lda m_inv_buttons
- tay
- lda #1
- sta port
- sta m_inv_buttons
- lsr
- sta port
- :
- lda port
- lsr
- rol m_inv_buttons
- bcc :-
- tya
- eor m_inv_buttons
- and m_inv_buttons
- sta buttons
- .endmacro
-
;; read sets the values for m_buttons1 and m_buttons2 as read from both
;; controllers.
.proc read