From 91c63997e16be4041cd382b42f0a08dcb9173789 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 23 Jan 2025 14:00:22 +0100 Subject: Move macros globally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- space/include/joypad.s | 44 ++++++++++++++++++++++---------------------- 1 file 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 -- cgit v1.2.3