From 74b1003ab8abad2f8220de4f2f18a3b118f23f01 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 10 Dec 2025 14:41:35 +0100 Subject: Adapt the code to play well with nasm's asan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The address sanitizer from nasm provides quite a few goodies, so let's adapt the code more to it to benefit from those. Signed-off-by: Miquel Sabaté Solà --- include/apu.s | 4 ++-- include/globals.s | 10 +++++----- include/joypad.s | 10 +++++----- include/oam.s | 19 ++++++++++--------- include/ppu.s | 12 ++++++------ 5 files changed, 28 insertions(+), 27 deletions(-) (limited to 'include') diff --git a/include/apu.s b/include/apu.s index 65d9876..bb0319f 100644 --- a/include/apu.s +++ b/include/apu.s @@ -1,4 +1,4 @@ .scope APU - DMC = $4010 - FRAME_COUNTER = $4017 + m_dmc = $4010 + m_frame_counter = $4017 .endscope diff --git a/include/globals.s b/include/globals.s index 842de34..f9777e5 100644 --- a/include/globals.s +++ b/include/globals.s @@ -6,17 +6,17 @@ ;; Argument values reserved passing arguments to functions in memory. zp_arg0 = $00 zp_arg1 = $01 - zp_arg2 = $02 - zp_arg3 = $03 - zp_arg4 = $04 + ;; zp_arg2 = $02 + ;; zp_arg3 = $03 + ;; zp_arg4 = $04 ;;; ;; Random values that can be used inside of functions for temporary values ;; so `zp_argX` variables are not overwritten as often. zp_tmp0 = $05 zp_tmp1 = $06 - zp_tmp2 = $07 - zp_tmp3 = $08 + ;; zp_tmp2 = $07 + ;; zp_tmp3 = $08 ;;; ;; Reserve a byte of memory for preserving indices on memory. This is needed diff --git a/include/joypad.s b/include/joypad.s index 141877f..f7268e8 100644 --- a/include/joypad.s +++ b/include/joypad.s @@ -10,8 +10,8 @@ BUTTON_RIGHT = 1 << 0 ;; Port addresses for controllers. - JOYPAD1 = $4016 - JOYPAD2 = $4017 + m_joypad1 = $4016 + ;; m_joypad2 = $4017 ;; After running a `read_*` function these two variables will contain the ;; given result. @@ -49,14 +49,14 @@ .proc unsafe_read_x ;; Start the latch process. lda #$01 - sta Joypad::JOYPAD1 + sta Joypad::m_joypad1 sta Joypad::zp_buttons1, x ; Bit as a guard for the loop below. lsr - sta Joypad::JOYPAD1 + sta Joypad::m_joypad1 ;; Now the joypad is ready to accept reads. @loop: - lda Joypad::JOYPAD1, x + lda Joypad::m_joypad1, x and #%00000011 ; Ignore bits other than controller. cmp #$01 ; Set carry if and only if nonzero. rol Joypad::zp_buttons1, x ; Carry -> bit 0; bit 7 -> Carry diff --git a/include/oam.s b/include/oam.s index 22935b2..a73494d 100644 --- a/include/oam.s +++ b/include/oam.s @@ -1,11 +1,12 @@ .scope OAM - ADDRESS = $2003 - DMA = $4014 -.endscope + ;; Region in internal RAM where sprites are being allocated for later use in + ;; the DMA process. The entire page is reserved, as there are 64 sprites x 4 + ;; bytes each = 256 bytes in total. + m_sprites = $200 ; asan:reserve $100 + + ;;; + ;; Actual addresses from OAM space. -.macro OAM_WRITE_SPRITES - lda #$00 - sta OAM::ADDR - lda #$02 - sta OAM::DMA -.endmacro + m_address = $2003 + m_dma = $4014 +.endscope diff --git a/include/ppu.s b/include/ppu.s index a9c0ed2..7882809 100644 --- a/include/ppu.s +++ b/include/ppu.s @@ -1,10 +1,10 @@ .scope PPU - CONTROL = $2000 - MASK = $2001 - STATUS = $2002 - SCROLL = $2005 - ADDRESS = $2006 - DATA = $2007 + m_control = $2000 + m_mask = $2001 + m_status = $2002 + m_scroll = $2005 + m_address = $2006 + m_data = $2007 ;; Shadow for the PPU::CONTROL value. Touch this value instead of accessing ;; the PPU register directly. -- cgit v1.2.3