From f795a2fc8dfad9edec25eb39502f6464dc68c12a Mon Sep 17 00:00:00 2001 From: Daniel Thornburgh Date: Thu, 8 Dec 2022 14:23:05 -0800 Subject: [PATCH] [NFC] Use .zeropage directive throughout SDK. --- mos-platform/atari8/CMakeLists.txt | 1 + mos-platform/atari8/init-stack.S | 6 +- mos-platform/commodore/CMakeLists.txt | 1 + mos-platform/commodore/cbm_k_iobase.s | 24 +- mos-platform/commodore/cbm_k_load.s | 20 +- mos-platform/commodore/cbm_k_save.s | 31 +- mos-platform/commodore/cbm_k_setlfs.s | 20 +- mos-platform/commodore/cbm_k_setnam.s | 42 +-- mos-platform/common/CMakeLists.txt | 1 + mos-platform/common/asminc/CMakeLists.txt | 3 + mos-platform/common/asminc/imag.inc | 4 + mos-platform/common/c/CMakeLists.txt | 1 + mos-platform/common/c/setjmp.S | 74 ++--- mos-platform/common/crt0/CMakeLists.txt | 1 + mos-platform/common/crt0/init-stack.S | 6 +- mos-platform/dodo/CMakeLists.txt | 2 + mos-platform/dodo/api.s | 88 +++--- mos-platform/dodo/crt0.s | 2 + mos-platform/nes-mmc1/CMakeLists.txt | 1 + mos-platform/nes-mmc1/bank.s | 51 +-- mos-platform/nes-mmc3/CMakeLists.txt | 1 + mos-platform/nes-mmc3/bank.s | 50 +-- mos-platform/nes-mmc3/irq.s | 14 +- mos-platform/nes-mmc3/reset-banked-mode-1.s | 4 +- mos-platform/nes/famitone2/CMakeLists.txt | 2 + mos-platform/nes/famitone2/famitone2.s | 12 +- mos-platform/nes/famitone2/fixed-wrappers.s | 42 +-- .../nes/famitone2/music-bank-wrappers.s | 10 +- mos-platform/nes/famitone2/music-bank.s | 29 +- .../nes/famitone2/sounds-bank-wrappers.s | 10 +- mos-platform/nes/famitone2/sounds-bank.s | 26 +- mos-platform/nes/nesdoug/CMakeLists.txt | 1 + mos-platform/nes/nesdoug/nesdoug.s | 292 +++++++++--------- mos-platform/nes/nesdoug/padlib.s | 19 +- mos-platform/nes/nesdoug/zaplib.s | 11 +- mos-platform/nes/neslib/CMakeLists.txt | 4 + mos-platform/nes/neslib/neslib.inc | 4 + mos-platform/nes/neslib/neslib.s | 238 +++++++------- mos-platform/nes/neslib/ntsc.inc | 1 + mos-platform/nes/neslib/ntsc.s | 13 +- mos-platform/nes/neslib/rand.s | 20 +- 41 files changed, 634 insertions(+), 548 deletions(-) create mode 100644 mos-platform/common/asminc/CMakeLists.txt create mode 100644 mos-platform/common/asminc/imag.inc create mode 100644 mos-platform/nes/neslib/neslib.inc create mode 100644 mos-platform/nes/neslib/ntsc.inc diff --git a/mos-platform/atari8/CMakeLists.txt b/mos-platform/atari8/CMakeLists.txt index 1d49a802d..4275eb6b5 100644 --- a/mos-platform/atari8/CMakeLists.txt +++ b/mos-platform/atari8/CMakeLists.txt @@ -28,6 +28,7 @@ merge_libraries(atari8-crt0 common-zero-bss common-exit-return ) +target_link_libraries(atari8-crt0 PRIVATE common-asminc) add_platform_library(atari8-c abort.c diff --git a/mos-platform/atari8/init-stack.S b/mos-platform/atari8/init-stack.S index 134fc04e9..675d2be98 100644 --- a/mos-platform/atari8/init-stack.S +++ b/mos-platform/atari8/init-stack.S @@ -1,9 +1,11 @@ +.include "imag.inc" + .global __do_init_stack ; Initialize soft stack pointer to MEMTOP .section .init.100,"axR",@progbits __do_init_stack: lda $2e5 - sta mos8(__rc0) + sta __rc0 lda $2e6 - sta mos8(__rc1) + sta __rc1 diff --git a/mos-platform/commodore/CMakeLists.txt b/mos-platform/commodore/CMakeLists.txt index f88c101b9..7ca73492f 100644 --- a/mos-platform/commodore/CMakeLists.txt +++ b/mos-platform/commodore/CMakeLists.txt @@ -57,3 +57,4 @@ add_platform_library(commodore-c # unneccessarily. It can also be called in an interrupt. set_property(SOURCE abort.c PROPERTY COMPILE_OPTIONS -fno-lto -fno-static-stack) target_include_directories(commodore-c BEFORE PUBLIC .) +target_link_libraries(commodore-c PRIVATE common-asminc) diff --git a/mos-platform/commodore/cbm_k_iobase.s b/mos-platform/commodore/cbm_k_iobase.s index 597cc3fc1..f5ed0726b 100644 --- a/mos-platform/commodore/cbm_k_iobase.s +++ b/mos-platform/commodore/cbm_k_iobase.s @@ -1,12 +1,14 @@ -.text - -; -; unsigned cbm_k_iobase (void); -; -.global cbm_k_iobase - jsr __IOBASE - txa - sty __rc2 - ldx __rc2 - rts +.include "imag.inc" + +.text + +; +; unsigned cbm_k_iobase (void); +; +.global cbm_k_iobase + jsr __IOBASE + txa + sty __rc2 + ldx __rc2 + rts \ No newline at end of file diff --git a/mos-platform/commodore/cbm_k_load.s b/mos-platform/commodore/cbm_k_load.s index df70189a8..58bd9bb77 100644 --- a/mos-platform/commodore/cbm_k_load.s +++ b/mos-platform/commodore/cbm_k_load.s @@ -1,9 +1,11 @@ -.text - -; -; unsigned int cbm_k_load(unsigned char flag, unsigned addr); -; -.global cbm_k_load -cbm_k_load: - ldy __rc2 - jmp __LOAD +.include "imag.inc" + +.text + +; +; unsigned int cbm_k_load(unsigned char flag, unsigned addr); +; +.global cbm_k_load +cbm_k_load: + ldy __rc2 + jmp __LOAD diff --git a/mos-platform/commodore/cbm_k_save.s b/mos-platform/commodore/cbm_k_save.s index 0209b1787..cea0c542a 100644 --- a/mos-platform/commodore/cbm_k_save.s +++ b/mos-platform/commodore/cbm_k_save.s @@ -1,17 +1,14 @@ -.text - -__rs1 = __rc2 -__rs2 = __rc4 - -; -; unsigned char cbm_k_save(unsigned int start, unsigned int end); -; -.global cbm_k_save -cbm_k_save: - sta __rs2 - stx __rs2 + 1 - ldx __rc2 - ldy __rc2 + 1 - lda #__rs2 - jmp __SAVE - +.include "imag.inc" +.text + +; +; unsigned char cbm_k_save(unsigned int start, unsigned int end); +; +.global cbm_k_save +cbm_k_save: + sta __rc4 + stx __rc5 + ldx __rc2 + ldy __rc3 + lda #__rc4 + jmp __SAVE diff --git a/mos-platform/commodore/cbm_k_setlfs.s b/mos-platform/commodore/cbm_k_setlfs.s index 6fc62f4c6..8e827c8ae 100644 --- a/mos-platform/commodore/cbm_k_setlfs.s +++ b/mos-platform/commodore/cbm_k_setlfs.s @@ -1,9 +1,11 @@ -.text - -; -; void cbm_k_setlfs (unsigned char LFN, unsigned char DEV, unsigned char SA); -; -.global cbm_k_setlfs -cbm_k_setlfs: - ldy __rc2 - jmp __SETLFS +.include "imag.inc" + +.text + +; +; void cbm_k_setlfs (unsigned char LFN, unsigned char DEV, unsigned char SA); +; +.global cbm_k_setlfs +cbm_k_setlfs: + ldy __rc2 + jmp __SETLFS diff --git a/mos-platform/commodore/cbm_k_setnam.s b/mos-platform/commodore/cbm_k_setnam.s index dd35e7d50..8e09be6bc 100644 --- a/mos-platform/commodore/cbm_k_setnam.s +++ b/mos-platform/commodore/cbm_k_setnam.s @@ -1,21 +1,21 @@ -.text - -__rs1 = __rc2 - -; -; void cbm_k_setnam (const char* Name); -; -.global cbm_k_setnam -cbm_k_setnam: - lda __rs1 - pha - lda __rs1 + 1 - pha - jsr strlen - sta __rc2 - pla - tay - pla - tax - lda __rc2 - jmp __SETNAM +.include "imag.inc" + +.text + +; +; void cbm_k_setnam (const char* Name); +; +.global cbm_k_setnam +cbm_k_setnam: + lda __rc2 + pha + lda __rc3 + pha + jsr strlen + sta __rc2 + pla + tay + pla + tax + lda __rc2 + jmp __SETNAM diff --git a/mos-platform/common/CMakeLists.txt b/mos-platform/common/CMakeLists.txt index 14a52c9db..8a63f7c52 100644 --- a/mos-platform/common/CMakeLists.txt +++ b/mos-platform/common/CMakeLists.txt @@ -10,6 +10,7 @@ install(DIRECTORY ${INCLUDE_DIR}/ TYPE INCLUDE) # Math library; just a stub for now. add_platform_library(common-m) +add_subdirectory(asminc) add_subdirectory(crt0) add_subdirectory(crt) add_subdirectory(c) diff --git a/mos-platform/common/asminc/CMakeLists.txt b/mos-platform/common/asminc/CMakeLists.txt new file mode 100644 index 000000000..b3d3505b9 --- /dev/null +++ b/mos-platform/common/asminc/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(common-asminc INTERFACE) +target_include_directories(common-asminc BEFORE INTERFACE .) +install(FILES imag.inc DESTINATION ${ASMINCDIR}) diff --git a/mos-platform/common/asminc/imag.inc b/mos-platform/common/asminc/imag.inc new file mode 100644 index 000000000..f9349cef7 --- /dev/null +++ b/mos-platform/common/asminc/imag.inc @@ -0,0 +1,4 @@ +.zeropage __rc0, __rc1, __rc2, __rc3, __rc4, __rc5, __rc6, __rc7, __rc8, __rc9 +.zeropage __rc10, __rc11, __rc12, __rc13, __rc14, __rc15, __rc16, __rc17, __rc18 +.zeropage __rc19, __rc20, __rc21, __rc22, __rc23, __rc24, __rc25, __rc26, __rc27 +.zeropage __rc28, __rc29, __rc30, __rc31 diff --git a/mos-platform/common/c/CMakeLists.txt b/mos-platform/common/c/CMakeLists.txt index 79d1e340a..21cef3a5b 100644 --- a/mos-platform/common/c/CMakeLists.txt +++ b/mos-platform/common/c/CMakeLists.txt @@ -34,3 +34,4 @@ set_property(SOURCE printf.c PROPERTY COMPILE_DEFINITIONS PRINTF_DISABLE_SUPPORT_EXPONENTIAL ) target_include_directories(common-c SYSTEM BEFORE PUBLIC ${INCLUDE_DIR}) +target_link_libraries(common-c PRIVATE common-asminc) diff --git a/mos-platform/common/c/setjmp.S b/mos-platform/common/c/setjmp.S index 16a5e3a75..ecf980957 100644 --- a/mos-platform/common/c/setjmp.S +++ b/mos-platform/common/c/setjmp.S @@ -1,3 +1,5 @@ +.include "imag.inc" + .section .text.setjmp .global setjmp setjmp: @@ -16,54 +18,54 @@ setjmp: sta (__rc2),y ; Save soft stack pointer - lda mos8(__rc0) + lda __rc0 iny sta (__rc2),y - lda mos8(__rc1) + lda __rc1 iny sta (__rc2),y ; Save CSRs - lda mos8(__rc18) + lda __rc18 iny sta (__rc2),y - lda mos8(__rc19) + lda __rc19 iny sta (__rc2),y - lda mos8(__rc20) + lda __rc20 iny sta (__rc2),y - lda mos8(__rc21) + lda __rc21 iny sta (__rc2),y - lda mos8(__rc22) + lda __rc22 iny sta (__rc2),y - lda mos8(__rc23) + lda __rc23 iny sta (__rc2),y - lda mos8(__rc24) + lda __rc24 iny sta (__rc2),y - lda mos8(__rc25) + lda __rc25 iny sta (__rc2),y - lda mos8(__rc26) + lda __rc26 iny sta (__rc2),y - lda mos8(__rc27) + lda __rc27 iny sta (__rc2),y - lda mos8(__rc28) + lda __rc28 iny sta (__rc2),y - lda mos8(__rc29) + lda __rc29 iny sta (__rc2),y - lda mos8(__rc30) + lda __rc30 iny sta (__rc2),y - lda mos8(__rc31) + lda __rc31 iny sta (__rc2),y @@ -76,60 +78,60 @@ setjmp: .global longjmp longjmp: ; Save return value - sta mos8(__rc16) - stx mos8(__rc17) + sta __rc16 + stx __rc17 ; Restore CSRs ldy #18 lda (__rc2),y - sta mos8(__rc31) + sta __rc31 dey lda (__rc2),y - sta mos8(__rc30) + sta __rc30 dey lda (__rc2),y - sta mos8(__rc29) + sta __rc29 dey lda (__rc2),y - sta mos8(__rc28) + sta __rc28 dey lda (__rc2),y - sta mos8(__rc27) + sta __rc27 dey lda (__rc2),y - sta mos8(__rc26) + sta __rc26 dey lda (__rc2),y - sta mos8(__rc25) + sta __rc25 dey lda (__rc2),y - sta mos8(__rc24) + sta __rc24 dey lda (__rc2),y - sta mos8(__rc23) + sta __rc23 dey lda (__rc2),y - sta mos8(__rc22) + sta __rc22 dey lda (__rc2),y - sta mos8(__rc21) + sta __rc21 dey lda (__rc2),y - sta mos8(__rc20) + sta __rc20 dey lda (__rc2),y - sta mos8(__rc19) + sta __rc19 dey lda (__rc2),y - sta mos8(__rc18) + sta __rc18 ; Restore soft stack pointer dey lda (__rc2),y - sta mos8(__rc1) + sta __rc1 dey lda (__rc2),y - sta mos8(__rc0) + sta __rc0 ; Restore hard stack pointer dey @@ -146,7 +148,7 @@ longjmp: sta $101,x ; Restore return value - lda mos8(__rc16) - ldx mos8(__rc17) + lda __rc16 + ldx __rc17 rts diff --git a/mos-platform/common/crt0/CMakeLists.txt b/mos-platform/common/crt0/CMakeLists.txt index cd27ef058..088990cb4 100644 --- a/mos-platform/common/crt0/CMakeLists.txt +++ b/mos-platform/common/crt0/CMakeLists.txt @@ -35,5 +35,6 @@ merge_libraries(common-copy-data common-copy-zp-data) # Initialize the soft stack pointer to __stack. add_platform_library(common-init-stack init-stack.S) +target_link_libraries(common-init-stack PRIVATE common-asminc) add_subdirectory(exit) diff --git a/mos-platform/common/crt0/init-stack.S b/mos-platform/common/crt0/init-stack.S index d3e007e14..fd5507e74 100644 --- a/mos-platform/common/crt0/init-stack.S +++ b/mos-platform/common/crt0/init-stack.S @@ -1,9 +1,11 @@ +.include "imag.inc" + .global __do_init_stack ; Initialze soft stack pointer from __stack symbol. .section .init.100,"axR",@progbits __do_init_stack: lda #mos16lo(__stack) - sta mos8(__rc0) + sta __rc0 lda #mos16hi(__stack) - sta mos8(__rc1) + sta __rc1 diff --git a/mos-platform/dodo/CMakeLists.txt b/mos-platform/dodo/CMakeLists.txt index 938eb9bb2..264492528 100644 --- a/mos-platform/dodo/CMakeLists.txt +++ b/mos-platform/dodo/CMakeLists.txt @@ -7,6 +7,7 @@ endif() install(FILES api.h TYPE INCLUDE) add_platform_object_file(dodo-crt0-o crt0.o crt0.s) +target_link_libraries(dodo-crt0-o PRIVATE common-asminc) add_platform_library(dodo-crt0) merge_libraries(dodo-crt0 @@ -20,6 +21,7 @@ add_platform_library(dodo-c api.s) merge_libraries(dodo-c common-c ) +target_link_libraries(dodo-c PRIVATE common-asminc) target_include_directories(dodo-c SYSTEM BEFORE PUBLIC .) target_compile_options(dodo-c PUBLIC -mcpu=mos65c02) diff --git a/mos-platform/dodo/api.s b/mos-platform/dodo/api.s index 2e08bc4c2..30c0ff8df 100644 --- a/mos-platform/dodo/api.s +++ b/mos-platform/dodo/api.s @@ -1,35 +1,37 @@ + .include "imag.inc" + .text .section .text.pusha,"ax",@progbits pusha: - ldy mos8(__rc0) + ldy __rc0 beq .L1 - dec mos8(__rc0) + dec __rc0 ldy #0 - sta (mos8(__rc0)), y + sta (__rc0), y rts .L1: - dec mos8(__rc1) - dec mos8(__rc0) - sta (mos8(__rc0)), y + dec __rc1 + dec __rc0 + sta (__rc0), y rts .section .text.pushax,"ax",@progbits pushax: pha - lda mos8(__rc0) + lda __rc0 sec sbc #2 - sta mos8(__rc0) + sta __rc0 bcs .L2 - dec mos8(__rc1) + dec __rc1 .L2: ldy #1 txa - sta (mos8(__rc0)), y + sta (__rc0), y pla dey - sta (mos8(__rc0)), y + sta (__rc0), y rts .section .text.DRAW_SPRITE,"ax",@progbits @@ -39,20 +41,20 @@ DRAW_SPRITE: ; @DRAW_SPRITE ; %bb.0: phx pha - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax pla jsr pusha pla jsr pusha - lda mos8(__rc4) + lda __rc4 jsr pusha - lda mos8(__rc5) + lda __rc5 jsr pusha - lda mos8(__rc6) + lda __rc6 jsr pusha - lda mos8(__rc7) + lda __rc7 jsr pusha lda #0 jmp ($FFF8) @@ -77,9 +79,9 @@ CLEAR_SPRITE: ; @CLEAR_SPRITE jsr pusha txa jsr pusha - lda mos8(__rc2) + lda __rc2 jsr pusha - lda mos8(__rc3) + lda __rc3 jsr pusha lda #2 jmp ($FFF8) @@ -94,7 +96,7 @@ SET_PIXEL: ; @SET_PIXEL jsr pusha txa jsr pusha - lda mos8(__rc2) + lda __rc2 jsr pusha lda #3 jmp ($FFF8) @@ -109,11 +111,11 @@ DRAW_LINE: ; @DRAW_LINE jsr pusha txa jsr pusha - lda mos8(__rc2) + lda __rc2 jsr pusha - lda mos8(__rc3) + lda __rc3 jsr pusha - lda mos8(__rc4) + lda __rc4 jsr pusha lda #4 jmp ($FFF8) @@ -166,8 +168,8 @@ WAIT: ; @WAIT .type LOAD_MUSIC,@function LOAD_MUSIC: ; @LOAD_MUSIC ; %bb.0: - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax lda #9 jmp ($FFF8) @@ -179,8 +181,8 @@ LOAD_MUSIC: ; @LOAD_MUSIC .type PLAY_EFFECT,@function PLAY_EFFECT: ; @PLAY_EFFECT ; %bb.0: - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax lda #1 jsr pusha @@ -194,8 +196,8 @@ PLAY_EFFECT: ; @PLAY_EFFECT .type PLAY_EFFECT_ONCE,@function PLAY_EFFECT_ONCE: ; @PLAY_EFFECT_ONCE ; %bb.0: - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax lda #0 jsr pusha @@ -252,18 +254,18 @@ COPY_BACKGROUND: ; @COPY_BACKGROUND ; %bb.0: phx pha - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax pla jsr pusha pla jsr pusha - lda mos8(__rc4) + lda __rc4 jsr pusha - lda mos8(__rc5) + lda __rc5 jsr pusha - lda mos8(__rc6) + lda __rc6 jsr pusha lda #15 jmp ($FFF8) @@ -275,8 +277,8 @@ COPY_BACKGROUND: ; @COPY_BACKGROUND .type DRAW_STRING,@function DRAW_STRING: ; @DRAW_STRING ; %bb.0: - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax lda #16 jmp ($FFF8) @@ -324,8 +326,8 @@ GET_PIXEL: ; @GET_PIXEL .type GET_VERSION,@function GET_VERSION: ; @GET_VERSION ; %bb.0: - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax lda #20 jmp ($FFF8) @@ -343,7 +345,7 @@ CHECK_VERSION: ; @CHECK_VERSION jsr pusha txa jsr pusha - lda mos8(__rc2) + lda __rc2 jsr pusha lda #21 jmp ($FFF8) @@ -352,8 +354,8 @@ CHECK_VERSION: ; @CHECK_VERSION ; -- End function LOAD_PERSISTENT: ; @LOAD_PERSISTENT ; %bb.0: - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax lda #22 jmp ($FFF8) @@ -365,8 +367,8 @@ LOAD_PERSISTENT: ; @LOAD_PERSISTENT .type SAVE_PERSISTENT,@function SAVE_PERSISTENT: ; @SAVE_PERSISTENT ; %bb.0: - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 jsr pushax lda #23 jmp ($FFF8) diff --git a/mos-platform/dodo/crt0.s b/mos-platform/dodo/crt0.s index a5c786aa4..caa6c402a 100644 --- a/mos-platform/dodo/crt0.s +++ b/mos-platform/dodo/crt0.s @@ -1,3 +1,5 @@ +.include "imag.inc" + .section .init.400,"axR",@progbits ; make sure flags are in a sane state cld diff --git a/mos-platform/nes-mmc1/CMakeLists.txt b/mos-platform/nes-mmc1/CMakeLists.txt index b2cbe25fd..217876896 100644 --- a/mos-platform/nes-mmc1/CMakeLists.txt +++ b/mos-platform/nes-mmc1/CMakeLists.txt @@ -28,3 +28,4 @@ add_platform_object_file(nes-mmc1-init-prg-ram-0-o add_platform_library(nes-mmc1-c bank.c bank.s) merge_libraries(nes-mmc1-c common-c) +target_link_libraries(nes-mmc1-c PRIVATE common-asminc) diff --git a/mos-platform/nes-mmc1/bank.s b/mos-platform/nes-mmc1/bank.s index 05ecab778..a0c9daf7a 100644 --- a/mos-platform/nes-mmc1/bank.s +++ b/mos-platform/nes-mmc1/bank.s @@ -24,6 +24,11 @@ ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ; SOFTWARE. +.include "imag.inc" + +.zeropage _PRG_BANK, _CHR_BANK0, _CHR_BANK1, _MMC1_CTRL_NMI, _CHR_BANK0_CUR +.zeropage _CHR_BANK1_CUR, _MMC1_CTRL_CUR, _IN_PROGRESS + MMC1_CTRL = $8000 MMC1_CHR0 = $a000 MMC1_CHR1 = $c000 @@ -45,40 +50,40 @@ MMC1_PRG = $e000 .globl bank_nmi bank_nmi: inc __reset_mmc1_byte - lda mos8(_CHR_BANK0) - sta mos8(_CHR_BANK0_CUR) + lda _CHR_BANK0 + sta _CHR_BANK0_CUR mmc1_register_write MMC1_CHR0 - lda mos8(_CHR_BANK1) - sta mos8(_CHR_BANK1_CUR) + lda _CHR_BANK1 + sta _CHR_BANK1_CUR mmc1_register_write MMC1_CHR1 - lda mos8(_MMC1_CTRL_NMI) - sta mos8(_MMC1_CTRL_CUR) + lda _MMC1_CTRL_NMI + sta _MMC1_CTRL_CUR mmc1_register_write MMC1_CTRL lda #0 - sta mos8(_IN_PROGRESS) + sta _IN_PROGRESS rts .section .text.set_chr_bank_0,"ax",@progbits .weak set_chr_bank_0 set_chr_bank_0: - sta mos8(_CHR_BANK0) + sta _CHR_BANK0 rts .section .text.set_chr_bank_1,"ax",@progbits .weak set_chr_bank_1 set_chr_bank_1: - sta mos8(_CHR_BANK1) + sta _CHR_BANK1 rts .section .text.set_mirroring,"ax",@progbits .weak set_mirroring set_mirroring: and #0b11 - sta mos8(__rc2) - lda mos8(_MMC1_CTRL_NMI) + sta __rc2 + lda _MMC1_CTRL_NMI and #0b11100 - ora mos8(__rc2) - sta mos8(_MMC1_CTRL_NMI) + ora __rc2 + sta _MMC1_CTRL_NMI rts .section .text.get_prg_bank,"ax",@progbits @@ -86,7 +91,7 @@ set_mirroring: .weak get_prg_bank __get_prg_bank: get_prg_bank: - lda mos8(_PRG_BANK) + lda _PRG_BANK rts .section .text.set_prg_bank,"ax",@progbits @@ -98,13 +103,13 @@ set_prg_bank: .Lset: inc __reset_mmc1_byte ldx #1 - stx mos8(_IN_PROGRESS) + stx _IN_PROGRESS mmc1_register_write MMC1_PRG - ldx mos8(_IN_PROGRESS) + ldx _IN_PROGRESS beq .Lretry dex - stx mos8(_IN_PROGRESS) - sty mos8(_PRG_BANK) + stx _IN_PROGRESS + sty _PRG_BANK rts .Lretry: tya @@ -116,14 +121,14 @@ set_prg_bank: .weak banked_call banked_call: tay - lda mos8(_PRG_BANK) + lda _PRG_BANK pha tya jsr __set_prg_bank - lda mos8(__rc2) - sta mos8(__rc18) - lda mos8(__rc3) - sta mos8(__rc19) + lda __rc2 + sta __rc18 + lda __rc3 + sta __rc19 jsr __call_indir pla jsr __set_prg_bank diff --git a/mos-platform/nes-mmc3/CMakeLists.txt b/mos-platform/nes-mmc3/CMakeLists.txt index 6748348a4..d463aee44 100644 --- a/mos-platform/nes-mmc3/CMakeLists.txt +++ b/mos-platform/nes-mmc3/CMakeLists.txt @@ -26,3 +26,4 @@ add_platform_object_file(nes-mmc3-reset-banked-mode-1-o reset-banked-mode-1.o re add_platform_library(nes-mmc3-c bank.c bank.s irq.c irq.s) target_include_directories(nes-mmc3-c PRIVATE ../nes) merge_libraries(nes-mmc3-c common-c) +target_link_libraries(nes-mmc3-c PRIVATE common-asminc) diff --git a/mos-platform/nes-mmc3/bank.s b/mos-platform/nes-mmc3/bank.s index 124c7d304..abd61fe0f 100644 --- a/mos-platform/nes-mmc3/bank.s +++ b/mos-platform/nes-mmc3/bank.s @@ -1,3 +1,7 @@ +.include "imag.inc" + +.zeropage _bank_select_hi, _in_progress, _prg_8000, _prg_a000 + .section .text.set_prg_bank,"ax",@progbits .globl __set_prg_bank .weak set_prg_bank @@ -22,10 +26,10 @@ get_prg_bank: and #$e0 ; Zero non-bank bits. cmp #$a0 bne .Lget_8000 - lda mos8(__prg_a000) + lda __prg_a000 rts .Lget_8000: - lda mos8(__prg_8000) + lda __prg_8000 rts .section .text.set_prg_8000,"ax",@progbits @@ -33,10 +37,10 @@ get_prg_bank: .weak set_prg_8000 __set_prg_8000: set_prg_8000: - sta mos8(__prg_8000) + sta __prg_8000 tax lda #0b110 - ora mos8(__bank_select_hi) + ora __bank_select_hi jmp __set_reg_retry .section .text.set_prg_a000,"ax",@progbits @@ -44,28 +48,28 @@ set_prg_8000: .weak set_prg_a000 __set_prg_a000: set_prg_a000: - sta mos8(__prg_a000) + sta __prg_a000 tax lda #0b111 - ora mos8(__bank_select_hi) + ora __bank_select_hi jmp __set_reg_retry .section .text.set_reg_retry,"ax",@progbits __set_reg_retry: - inc mos8(__in_progress) + inc __in_progress sta $8000 stx $8001 - lda mos8(__in_progress) + lda __in_progress beq __set_reg_retry lda #0 - sta mos8(__in_progress) + sta __in_progress rts .section .text.banked_call,"ax",@progbits .weak banked_call banked_call: tay - lda mos8(__rc3) + lda __rc3 and #$e0 ; Zero non-bank bits. cmp #$a0 bne .Lcall_8000 @@ -80,14 +84,14 @@ banked_call: __banked_call_8000: banked_call_8000: tay - lda mos8(__prg_8000) + lda __prg_8000 pha tya jsr __set_prg_8000 - lda mos8(__rc2) - sta mos8(__rc18) - lda mos8(__rc3) - sta mos8(__rc19) + lda __rc2 + sta __rc18 + lda __rc3 + sta __rc19 jsr __call_indir pla jsr __set_prg_8000 @@ -98,14 +102,14 @@ banked_call_8000: __banked_call_a000: banked_call_a000: tay - lda mos8(__prg_a000) + lda __prg_a000 pha tya jsr __set_prg_a000 - lda mos8(__rc2) - sta mos8(__rc18) - lda mos8(__rc3) - sta mos8(__rc19) + lda __rc2 + sta __rc18 + lda __rc3 + sta __rc19 jsr __call_indir pla jsr __set_prg_a000 @@ -116,15 +120,15 @@ banked_call_a000: .globl __set_chr_bank set_chr_bank: __set_chr_bank: - ora mos8(__bank_select_hi) + ora __bank_select_hi sta $8000 stx $8001 lda #0 - sta mos8(__in_progress) + sta __in_progress rts .section .text.set_chr_bank_retry,"ax",@progbits .weak set_chr_bank_retry set_chr_bank_retry: - ora mos8(__bank_select_hi) + ora __bank_select_hi jmp __set_reg_retry diff --git a/mos-platform/nes-mmc3/irq.s b/mos-platform/nes-mmc3/irq.s index 1b2150d30..bb21f2433 100644 --- a/mos-platform/nes-mmc3/irq.s +++ b/mos-platform/nes-mmc3/irq.s @@ -26,6 +26,8 @@ .include "nes.inc" +.zeropage __irq_ptr, __irq_index, __irq_done + .section .init.100,"axR",@progbits lda #$40 sta APU_PAD2 @@ -39,8 +41,8 @@ .globl __bank_nmi __bank_nmi: lda #0 - sta mos8(__irq_index) - sta mos8(__irq_done) + sta __irq_index + sta __irq_done jsr irq_parser rts @@ -94,7 +96,7 @@ irq: .section .text.irq_parser,"ax",@progbits irq_parser: - ldy mos8(__irq_index) + ldy __irq_index ; ldx #0 .Lloop: lda (__irq_ptr), y ; get value from array @@ -169,13 +171,13 @@ irq_parser: .Lscanline: jsr set_scanline_count ;this terminates the set - sty mos8(__irq_index) + sty __irq_index rts .Lexit: - sta mos8(__irq_done) ;value 0xff + sta __irq_done ;value 0xff dey ; undo the previous iny, keep it pointed to ff - sty mos8(__irq_index) + sty __irq_index rts set_scanline_count: diff --git a/mos-platform/nes-mmc3/reset-banked-mode-1.s b/mos-platform/nes-mmc3/reset-banked-mode-1.s index 925a2df47..009d20f96 100644 --- a/mos-platform/nes-mmc3/reset-banked-mode-1.s +++ b/mos-platform/nes-mmc3/reset-banked-mode-1.s @@ -1,3 +1,5 @@ +.zeropage __bank_select_hi + .section .reset,"ax",@progbits .globl _reset _reset: @@ -8,4 +10,4 @@ _reset: .section .init.250,"axR",@progbits lda #$40 - sta mos8(__bank_select_hi) + sta __bank_select_hi diff --git a/mos-platform/nes/famitone2/CMakeLists.txt b/mos-platform/nes/famitone2/CMakeLists.txt index 7eadd6cca..08bf603de 100644 --- a/mos-platform/nes/famitone2/CMakeLists.txt +++ b/mos-platform/nes/famitone2/CMakeLists.txt @@ -9,9 +9,11 @@ add_platform_library(nes-famitone2 sounds-bank.s ) target_include_directories(nes-famitone2 PRIVATE .) +target_link_libraries(nes-famitone2 PRIVATE common-asminc nes-neslib-asminc) add_platform_library(nes-ft2-fixed-wrappers fixed-wrappers.s music-bank-wrappers.s sounds-bank-wrappers.s ) +target_link_libraries(nes-ft2-fixed-wrappers PRIVATE common-asminc) diff --git a/mos-platform/nes/famitone2/famitone2.s b/mos-platform/nes/famitone2/famitone2.s index 4491776db..4afdb14f7 100644 --- a/mos-platform/nes/famitone2/famitone2.s +++ b/mos-platform/nes/famitone2/famitone2.s @@ -1,5 +1,7 @@ ;FamiTone2 v1.12 +.include "imag.inc" +.include "ntsc.inc" .include "config.s" ;zero page variables @@ -314,9 +316,9 @@ FamiToneInit: music_init: __music_init: jsr __unbank_music - ldx mos8(__rc2) - ldy mos8(__rc3) - lda mos8(NTSC_MODE) + ldx __rc2 + ldy __rc3 + lda NTSC_MODE jmp FamiToneInit ;------------------------------------------------------------------------------ @@ -1120,8 +1122,8 @@ _FT2SamplePlay: sounds_init: __sounds_init: jsr __unbank_sounds - ldx mos8(__rc2) - ldy mos8(__rc3) + ldx __rc2 + ldy __rc3 FamiToneSfxInit: stx obj2 R (obj2 x + width) - lda mos8(__rc8) ;X 2 + lda __rc8 ;X 2 clc - adc mos8(__rc9) ;width 2 - cmp mos8(__rc6) ;X 1 + adc __rc9 ;width 2 + cmp __rc6 ;X 1 bcc .Lno ;repeat process with y ldy #1 lda (__rc2),y - sta mos8(__rc6) ;Y 1 + sta __rc6 ;Y 1 lda (__rc4), y - sta mos8(__rc8) ;Y 2 + sta __rc8 ;Y 2 iny iny lda (__rc2),y - sta mos8(__rc7) ;height1 + sta __rc7 ;height1 lda (__rc4), y - sta mos8(__rc9) ;height2 + sta __rc9 ;height2 ;see if they are colliding y ;first check if obj1 Bottom (obj1 y + height) < obj2 Top - lda mos8(__rc6) ;Y 1 + lda __rc6 ;Y 1 clc - adc mos8(__rc7) ;height 1 - cmp mos8(__rc8) ;Y 2 + adc __rc7 ;height 1 + cmp __rc8 ;Y 2 bcc .Lno ;now check if obj1 Top > obj2 Bottom (obj2 y + height) - lda mos8(__rc8) ;Y 2 + lda __rc8 ;Y 2 clc - adc mos8(__rc9) ;height 2 - cmp mos8(__rc6) ;Y 1 + adc __rc9 ;height 2 + cmp __rc6 ;Y 1 bcc .Lno @@ -196,46 +200,46 @@ check_collision: .globl pal_fade_to pal_fade_to: tay - lda mos8(__rc20) + lda __rc20 pha - lda mos8(__rc21) + lda __rc21 pha - stx mos8(__rc20) ;to - sty mos8(__rc21) ;from + stx __rc20 ;to + sty __rc21 ;from jmp .Lcheck_equal .Lfade_loop: lda #4 jsr delay ;wait 4 frames - lda mos8(__rc21) ;from - cmp mos8(__rc20) ;to + lda __rc21 ;from + cmp __rc20 ;to bcs .Lmore .Lless: clc adc #1 - sta mos8(__rc21) ;from + sta __rc21 ;from jsr pal_bright jmp .Lcheck_equal .Lmore: sec sbc #1 - sta mos8(__rc21) ;from + sta __rc21 ;from jsr pal_bright .Lcheck_equal: - lda mos8(__rc21) - cmp mos8(__rc20) + lda __rc21 + cmp __rc20 bne .Lfade_loop .Ldone: jsr ppu_wait_nmi ;do 1 final, make sure the last change goes pla - sta mos8(__rc21) + sta __rc21 pla - sta mos8(__rc20) + sta __rc20 rts @@ -245,10 +249,10 @@ pal_fade_to: .section .text.add_scroll_y,"ax",@progbits .globl add_scroll_y add_scroll_y: - stx mos8(__rc3) - ldx mos8(__rc2) + stx __rc3 + ldx __rc2 clc - adc mos8(__rc3) + adc __rc3 bcs .Ladd_scroll_y_adjust cmp #$f0 bcs .Ladd_scroll_y_adjust @@ -271,11 +275,11 @@ sub_scroll_y: bcc .Lok ldx #$00 .Lok: - sta mos8(__rc3) + sta __rc3 txa - ldx mos8(__rc2) + ldx __rc2 sec - sbc mos8(__rc3) + sbc __rc3 bcc .Lsub_scroll_y_adjust rts @@ -291,32 +295,32 @@ sub_scroll_y: .section .text.get_ppu_addr,"ax",@progbits .globl get_ppu_addr get_ppu_addr: - sta mos8(__rc3) - lda mos8(__rc2) + sta __rc3 + lda __rc2 and #$f8 ;y bits ldy #0 - sty mos8(__rc4) + sty __rc4 asl a - rol mos8(__rc4) + rol __rc4 asl a - rol mos8(__rc4) - sta mos8(__rc5) + rol __rc4 + sta __rc5 txa ;x bits lsr a lsr a lsr a - ora mos8(__rc5) - sta mos8(__rc5) + ora __rc5 + sta __rc5 - lda mos8(__rc3) ;nt 0-3 + lda __rc3 ;nt 0-3 and #3 asl a asl a ora #$20 - ora mos8(__rc4) + ora __rc4 tax - lda mos8(__rc5) + lda __rc5 rts @@ -326,29 +330,29 @@ get_ppu_addr: .section .text.get_at_addr,"ax",@progbits .globl get_at_addr get_at_addr: - sta mos8(__rc3) - lda mos8(__rc2) + sta __rc3 + lda __rc2 and #$e0 - sta mos8(__rc4) + sta __rc4 txa and #$e0 lsr a lsr a lsr a - ora mos8(__rc4) + ora __rc4 lsr a lsr a ora #$c0 - sta mos8(__rc4) + sta __rc4 - lda mos8(__rc3) + lda __rc3 and #3 asl a asl a ora #$23 tax - lda mos8(__rc4) + lda __rc4 rts @@ -358,17 +362,17 @@ get_at_addr: .section .text.buffer_4_mt,"ax",@progbits .globl buffer_4_mt buffer_4_mt: - sta mos8(__rc3) - lda mos8(__rc2) + sta __rc3 + lda __rc2 ;a is the index into the data, get 4 metatiles and #$ee ;sanitize, x and y should be even tay lda (DATA_PTR), y - sta mos8(__rc6) + sta __rc6 iny lda (DATA_PTR), y - sta mos8(__rc7) + sta __rc7 tya clc adc #15 @@ -376,31 +380,31 @@ buffer_4_mt: bcs .Lskip tay lda (DATA_PTR), y - sta mos8(__rc8) + sta __rc8 iny lda (DATA_PTR), y - sta mos8(__rc9) + sta __rc9 .Lskip: ;metatiles are in _rc6 - rc9 now - lda mos8(__rc3) + lda __rc3 and #$9c ;sanitize, should be top left - sta mos8(__rc11) - stx mos8(__rc12) ;save for later, ppu_address + sta __rc11 + stx __rc12 ;save for later, ppu_address - sta mos8(__rc4) + sta __rc4 txa ora #$40 ;NT_UPD_HORZ - sta mos8(__rc5) + sta __rc5 ;buffer the ppu_address lda #0 - sta mos8(__rc10) ;loop count, index to the metatiles - ldx mos8(VRAM_INDEX) + sta __rc10 ;loop count, index to the metatiles + ldx VRAM_INDEX .Lbuffer_4_mt_loop: - lda mos8(__rc4) ;low byte + lda __rc4 ;low byte sta VRAM_BUF+1, x - lda mos8(__rc5) ;high byte + lda __rc5 ;high byte sta VRAM_BUF,x jsr .Lsub1 ;adds $20 to the address for next time @@ -424,13 +428,13 @@ buffer_4_mt: jsr .Lsub4 ;get attrib bits, shift into place ;same, but for right side - lda mos8(__rc4) ;low byte ppu address, again + lda __rc4 ;low byte ppu address, again sta VRAM_BUF+8,x - lda mos8(__rc5) ;high byte + lda __rc5 ;high byte sta VRAM_BUF+7,x jsr .Lsub1 - inc mos8(__rc10) ;count and index + inc __rc10 ;count and index jsr .Lsub2 lda (META_PTR), y sta VRAM_BUF+5,x ; buffer the 4 tiles @@ -453,8 +457,8 @@ buffer_4_mt: jsr .Lsub3 ;check if lowest y on screen, skip the la bne .Lloop_done - inc mos8(__rc10) - ldy mos8(__rc10) + inc __rc10 + ldy __rc10 cpy #4 bcc .Lbuffer_4_mt_loop @@ -466,85 +470,85 @@ buffer_4_mt: ;first, shift the bits to get an attribute address ;we stored the original at TEMP+7,8, 8 is high byte ;a bunch of bit shifting to get 3 bits from x and 3 y - lsr mos8(__rc12) ;high byte - ror mos8(__rc11) - lsr mos8(__rc12) - ror mos8(__rc11) - lda mos8(__rc11) + lsr __rc12 ;high byte + ror __rc11 + lsr __rc12 + ror __rc11 + lda __rc11 pha ;save and #7 ;just the x bits - sta mos8(__rc4) + sta __rc4 pla lsr a ;just the y bits lsr a and #$f8 ora #$c0 - ora mos8(__rc4) - sta mos8(__rc4) ;low byte + ora __rc4 + sta __rc4 ;low byte ;now high byte - lda mos8(__rc12) + lda __rc12 asl a asl a ora #$23 - sta mos8(__rc5) ;high byte, and the low byte is in TEMP + sta __rc5 ;high byte, and the low byte is in TEMP ;finally, push it all to the vram_buffer as a single byte - lda mos8(__rc5) ;high byte + lda __rc5 ;high byte sta VRAM_BUF,x inx - lda mos8(__rc4) ;low byte + lda __rc4 ;low byte sta VRAM_BUF,x inx - lda mos8(__rc14) + lda __rc14 sta VRAM_BUF,x inx lda #$ff ;=NT_UPD_EOF sta VRAM_BUF,x - stx mos8(VRAM_INDEX) + stx VRAM_INDEX rts .Lsub1: ;add $20 is a 1 down on the screen tay ;high byte - lda mos8(__rc4) + lda __rc4 clc adc #$20 - sta mos8(__rc4) + sta __rc4 bcc .Lsub1b iny .Lsub1b: - sty mos8(__rc5) + sty __rc5 rts .Lsub2: ;get the next metatile offset - ldy mos8(__rc10) - lda mos8(__rc6), y ;metatile + ldy __rc10 + lda __rc6, y ;metatile ;multiply by 5 - sta mos8(__rc13) + sta __rc13 asl a asl a ;x4 = 4 bytes per clc - adc mos8(__rc13) + adc __rc13 tay rts .Lsub3: ;check make sure we're not at the lowest y and overflowing ldy #0 ;x is forbidden - lda mos8(__rc12) ;high byte + lda __rc12 ;high byte and #$03 cmp #$03 bne .Lnot_overflow - lda mos8(__rc11) + lda __rc11 cmp #$80 ;last row of mt bcc .Lnot_overflow iny - lsr mos8(__rc14) ;make sure the attrib bits in correct position - lsr mos8(__rc14) - lsr mos8(__rc14) - lsr mos8(__rc14) + lsr __rc14 ;make sure the attrib bits in correct position + lsr __rc14 + lsr __rc14 + lsr __rc14 .Lnot_overflow: tya ;set flag rts @@ -555,9 +559,9 @@ buffer_4_mt: lda (META_PTR), y ;5th byte = attribute and #3 ;just need 2 bits ror a ;bit to carry - ror mos8(__rc14) ;shift carry in + ror __rc14 ;shift carry in ror a ;bit to carry - ror mos8(__rc14) ;roll the a.t. bits in the high 2 bits + ror __rc14 ;roll the a.t. bits in the high 2 bits rts @@ -568,19 +572,19 @@ buffer_4_mt: .globl buffer_1_mt buffer_1_mt: and #$de ;sanitize, should be even x and y - sta mos8(__rc4) + sta __rc4 txa ora #$40 ;NT_UPD_HORZ - sta mos8(__rc5) + sta __rc5 - ldx mos8(VRAM_INDEX) - lda mos8(__rc4) ;ppu address + ldx VRAM_INDEX + lda __rc4 ;ppu address sta VRAM_BUF+1,x clc adc #$20 ;shouldn't be rollover sta VRAM_BUF+6,x - lda mos8(__rc5) + lda __rc5 sta VRAM_BUF,x sta VRAM_BUF+5,x @@ -588,11 +592,11 @@ buffer_1_mt: sta VRAM_BUF+2,x sta VRAM_BUF+7,x - lda mos8(__rc2) ;which metatile + lda __rc2 ;which metatile asl a asl a clc - adc mos8(__rc2) ;multiply 5 + adc __rc2 ;multiply 5 tay lda (META_PTR), y ;tile sta VRAM_BUF+3,x @@ -609,7 +613,7 @@ buffer_1_mt: txa clc adc #10 - sta mos8(VRAM_INDEX) + sta VRAM_INDEX tax lda #$ff ;=NT_UPD_EOF sta VRAM_BUF,x @@ -627,35 +631,35 @@ xy_split: ;X to $2005 ;Low byte of nametable address to $2006, which is ((Y & $F8) << 2) | (X >> 3) - sta mos8(__rc4) ;x low - stx mos8(__rc5) + sta __rc4 ;x low + stx __rc5 ;push to stack in reverse order - lda mos8(__rc2) ;low y + lda __rc2 ;low y and #$f8 asl a asl a - sta mos8(__rc6) - lda mos8(__rc4) ;low x + sta __rc6 + lda __rc4 ;low x lsr a lsr a lsr a - ora mos8(__rc6) + ora __rc6 pha - lda mos8(__rc4) ;low x + lda __rc4 ;low x pha - lda mos8(__rc2) ;low y + lda __rc2 ;low y pha - lda mos8(__rc3) ;y high + lda __rc3 ;y high and #$01 asl a - sta mos8(__rc6) - lda mos8(__rc5) ;x high + sta __rc6 + lda __rc5 ;x high and #$01 - ora mos8(__rc6) + ora __rc6 asl a asl a pha @@ -687,7 +691,7 @@ xy_split: .section .text.gray_line,"ax",@progbits .globl gray_line gray_line: - lda mos8(PPUMASK_VAR) + lda PPUMASK_VAR and #$1f ;no color emphasis bits ora #1 ;yes gray bit sta PPUMASK @@ -697,7 +701,7 @@ gray_line: dex bne .Lloop - lda mos8(PPUMASK_VAR) + lda PPUMASK_VAR and #$1e ;no gray bit ora #$e0 ;all color emphasis bits sta PPUMASK @@ -707,6 +711,6 @@ gray_line: dex bne .Lloop2 - lda mos8(PPUMASK_VAR) ;normal + lda PPUMASK_VAR ;normal sta PPUMASK rts diff --git a/mos-platform/nes/nesdoug/padlib.s b/mos-platform/nes/nesdoug/padlib.s index cf51ef554..e13146063 100644 --- a/mos-platform/nes/nesdoug/padlib.s +++ b/mos-platform/nes/nesdoug/padlib.s @@ -3,6 +3,7 @@ .include "nes.inc" +.include "imag.inc" ;from NESDEV WIKI @@ -37,34 +38,34 @@ read_powerpad: and #$18 asl a asl a - sta mos8(__rc2), x ;0110 0000 + sta __rc2, x ;0110 0000 lda APU_PAD1,y and #$18 - ora mos8(__rc2), x + ora __rc2, x asl a - sta mos8(__rc2), x ;1111 0000 + sta __rc2, x ;1111 0000 lda APU_PAD1,y and #$18 lsr a - ora mos8(__rc2), x - sta mos8(__rc2), x ;1111 1100 + ora __rc2, x + sta __rc2, x ;1111 1100 lda APU_PAD1,y and #$18 lsr a lsr a lsr a - ora mos8(__rc2), x - sta mos8(__rc2), x ;1111 1111 + ora __rc2, x + sta __rc2, x ;1111 1111 dex beq .Lloop .Lexit: - lda mos8(__rc2) - ldx mos8(__rc3) + lda __rc2 + ldx __rc3 rts diff --git a/mos-platform/nes/nesdoug/zaplib.s b/mos-platform/nes/nesdoug/zaplib.s index ddbfcaee2..2db591340 100644 --- a/mos-platform/nes/nesdoug/zaplib.s +++ b/mos-platform/nes/nesdoug/zaplib.s @@ -2,6 +2,7 @@ ;NES zapper gun code .include "nes.inc" +.include "imag.inc" ;from NESDEV WIKI ;7 bit 0 @@ -87,16 +88,16 @@ zap_read: .globl zap_read2 zap_read2: ldx #0 - stx mos8(__rc2) + stx __rc2 asl a - rol mos8(__rc2) + rol __rc2 asl a - rol mos8(__rc2) + rol __rc2 tax beq .Lzero ;x is not zero, will exit early, add 1 - inc mos8(__rc2) + inc __rc2 .Lzero: ldy #1 .Lzap_read2_loop: @@ -113,7 +114,7 @@ zap_read2: dex bne .Lzap_read2_loop - dec mos8(__rc2) + dec __rc2 bmi .Lzap_read2_hit_no ;if started zero, rolled to ff, exit bne .Lzap_read2_loop ;positive, but above zero diff --git a/mos-platform/nes/neslib/CMakeLists.txt b/mos-platform/nes/neslib/CMakeLists.txt index 90ef97aed..b5bd9c94b 100644 --- a/mos-platform/nes/neslib/CMakeLists.txt +++ b/mos-platform/nes/neslib/CMakeLists.txt @@ -1,5 +1,8 @@ install(FILES neslib.h TYPE INCLUDE) +add_library(nes-neslib-asminc INTERFACE) +target_include_directories(nes-neslib-asminc INTERFACE .) + add_platform_library(nes-neslib neslib.c neslib.s @@ -8,3 +11,4 @@ add_platform_library(nes-neslib rand.c rand.s) target_include_directories(nes-neslib BEFORE PUBLIC ..) +target_link_libraries(nes-neslib PRIVATE common-asminc nes-neslib-asminc) diff --git a/mos-platform/nes/neslib/neslib.inc b/mos-platform/nes/neslib/neslib.inc new file mode 100644 index 000000000..ae2e40c0f --- /dev/null +++ b/mos-platform/nes/neslib/neslib.inc @@ -0,0 +1,4 @@ +.zeropage FRAME_CNT1, FRAME_CNT2, VRAM_UPDATE, NAME_UPD_ADR, NAME_UPD_ENABLE +.zeropage PAL_UPDATE, PAL_BG_PTR, PAL_SPR_PTR, SCROLL_X, SCROLL_Y, SCROLL_X1 +.zeropage SCROLL_Y1, PAD_STATE, PAD_STATEP, PAD_STATET, PPUCTRL_VAR +.zeropage PPUCTRL_VAR1, PPUMASK_VAR, SPRID diff --git a/mos-platform/nes/neslib/neslib.s b/mos-platform/nes/neslib/neslib.s index 71cdbc92f..31ba41b59 100644 --- a/mos-platform/nes/neslib/neslib.s +++ b/mos-platform/nes/neslib/neslib.s @@ -10,7 +10,11 @@ ;minor change %%, added ldx #0 to functions returning char ;removed sprid from c functions to speed them up + +.include "imag.inc" .include "nes.inc" +.include "neslib.inc" +.include "ntsc.inc" ; Reserve space at beginning of RAM for OAM buffer. .section .noinit.oam_buf,"a",@nobits @@ -71,10 +75,10 @@ clearVRAM: jsr oam_clear lda #0b10000000 - sta mos8(PPUCTRL_VAR) + sta PPUCTRL_VAR sta PPUCTRL ;enable NMI lda #0b00000110 - sta mos8(PPUMASK_VAR) + sta PPUMASK_VAR lda #0 sta PPUSCROLL @@ -86,31 +90,31 @@ clearVRAM: .section .text.neslib_nmi,"ax",@progbits .globl neslib_nmi neslib_nmi: - lda mos8(PPUMASK_VAR) ;if rendering is disabled, do not access the VRAM at all + lda PPUMASK_VAR ;if rendering is disabled, do not access the VRAM at all and #0b00011000 bne .LrenderingOn jmp .LskipAll .LrenderingOn: - lda mos8(VRAM_UPDATE) ;is the frame complete? + lda VRAM_UPDATE ;is the frame complete? bne .LdoUpdate jmp .LskipAll ;skipUpd .LdoUpdate: lda #0 - sta mos8(VRAM_UPDATE) + sta VRAM_UPDATE lda #>OAM_BUF ;update OAM sta OAMDMA - lda mos8(PAL_UPDATE) ;update palette if needed + lda PAL_UPDATE ;update palette if needed bne .LupdPal jmp .LupdVRAM .LupdPal: ldx #0 - stx mos8(PAL_UPDATE) + stx PAL_UPDATE lda #$3f sta PPUADDR @@ -147,7 +151,7 @@ neslib_nmi: .LupdVRAM: - lda mos8(NAME_UPD_ENABLE) + lda NAME_UPD_ENABLE beq .LskipUpd jsr flush_vram_update2 @@ -158,26 +162,26 @@ neslib_nmi: sta PPUADDR sta PPUADDR - lda mos8(SCROLL_X) + lda SCROLL_X sta PPUSCROLL - lda mos8(SCROLL_Y) + lda SCROLL_Y sta PPUSCROLL - lda mos8(PPUCTRL_VAR) + lda PPUCTRL_VAR sta PPUCTRL .LskipAll: - lda mos8(PPUMASK_VAR) + lda PPUMASK_VAR sta PPUMASK - inc mos8(FRAME_CNT1) - inc mos8(FRAME_CNT2) - lda mos8(FRAME_CNT2) + inc FRAME_CNT1 + inc FRAME_CNT2 + lda FRAME_CNT2 cmp #6 bne .LskipNtsc lda #0 - sta mos8(FRAME_CNT2) + sta FRAME_CNT2 .LskipNtsc: rts @@ -191,7 +195,7 @@ pal_all: .Lpal_copy: - sta mos8(__rc4) + sta __rc4 ldy #$00 @@ -201,10 +205,10 @@ pal_all: sta PAL_BUF,x inx iny - dec mos8(__rc4) + dec __rc4 bne 0b - inc mos8(PAL_UPDATE) + inc PAL_UPDATE rts @@ -246,7 +250,7 @@ pal_clear: inx cpx #$20 bne 0b - stx mos8(PAL_UPDATE) + stx PAL_UPDATE rts @@ -257,7 +261,7 @@ pal_clear: oam_clear: ldx #0 - stx mos8(SPRID) ; automatically sets sprid to zero + stx SPRID ; automatically sets sprid to zero lda #$ff 0: sta OAM_BUF,x @@ -280,11 +284,11 @@ oam_size: asl a asl a and #$20 - sta mos8(__rc2) - lda mos8(PPUCTRL_VAR) + sta __rc2 + lda PPUCTRL_VAR and #$df - ora mos8(__rc2) - sta mos8(PPUCTRL_VAR) + ora __rc2 + sta PPUCTRL_VAR rts @@ -295,23 +299,23 @@ oam_size: .section .text.oam_spr,"ax",@progbits .globl oam_spr oam_spr: - ldy mos8(SPRID) + ldy SPRID sta OAM_BUF+3,y txa sta OAM_BUF+0,y - lda mos8(__rc2) + lda __rc2 sta OAM_BUF+1,y - lda mos8(__rc3) + lda __rc3 sta OAM_BUF+2,y iny iny iny iny - sty mos8(SPRID) + sty SPRID rts @@ -322,9 +326,9 @@ oam_spr: .globl oam_meta_spr oam_meta_spr: - sta mos8(__rc4) - stx mos8(__rc5) - ldx mos8(SPRID) + sta __rc4 + stx __rc5 + ldx SPRID ldy #0 1: lda (__rc2),y ;x offset @@ -332,12 +336,12 @@ oam_meta_spr: beq 2f iny clc - adc mos8(__rc4) + adc __rc4 sta OAM_BUF+3,x lda (__rc2),y ;y offset iny clc - adc mos8(__rc5) + adc __rc5 sta OAM_BUF+0,x lda (__rc2),y ;tile iny @@ -351,7 +355,7 @@ oam_meta_spr: inx jmp 1b 2: - stx mos8(SPRID) + stx SPRID rts @@ -374,7 +378,7 @@ oam_hide_rest: inx bne 0b ;x is zero - stx mos8(SPRID) + stx SPRID rts @@ -385,19 +389,19 @@ oam_hide_rest: ppu_wait_frame: lda #1 - sta mos8(VRAM_UPDATE) - lda mos8(FRAME_CNT1) + sta VRAM_UPDATE + lda FRAME_CNT1 0: - cmp mos8(FRAME_CNT1) + cmp FRAME_CNT1 beq 0b - lda mos8(NTSC_MODE) + lda NTSC_MODE beq 2f 1: - lda mos8(FRAME_CNT2) + lda FRAME_CNT2 cmp #5 beq 1b @@ -413,11 +417,11 @@ ppu_wait_frame: ppu_wait_nmi: lda #1 - sta mos8(VRAM_UPDATE) - lda mos8(FRAME_CNT1) + sta VRAM_UPDATE + lda FRAME_CNT1 0: - cmp mos8(FRAME_CNT1) + cmp FRAME_CNT1 beq 0b rts @@ -427,29 +431,29 @@ ppu_wait_nmi: .section .text.vram_unrle,"ax",@progbits .globl vram_unrle vram_unrle: - ldy mos8(__rc2) + ldy __rc2 lda #0 - sta mos8(__rc2) + sta __rc2 lda (__rc2),y - sta mos8(__rc4) + sta __rc4 iny bne 1f - inc mos8(__rc3) + inc __rc3 1: lda (__rc2),y iny bne 11f - inc mos8(__rc3) + inc __rc3 11: - cmp mos8(__rc4) + cmp __rc4 beq 2f sta PPUDATA - sta mos8(__rc5) + sta __rc5 bne 1b 2: @@ -458,12 +462,12 @@ vram_unrle: beq 4f iny bne 21f - inc mos8(__rc3) + inc __rc3 21: tax - lda mos8(__rc5) + lda __rc5 3: @@ -482,34 +486,34 @@ vram_unrle: .section .text.scroll,"ax",@progbits .globl scroll scroll: - sta mos8(SCROLL_X) - lda mos8(__rc3) + sta SCROLL_X + lda __rc3 bne 1f - lda mos8(__rc2) + lda __rc2 cmp #240 bcs 1f - sta mos8(SCROLL_Y) + sta SCROLL_Y lda #0 - sta mos8(__rc2) + sta __rc2 beq 2f ;bra 1: sec - lda mos8(__rc2) + lda __rc2 sbc #240 - sta mos8(SCROLL_Y) + sta SCROLL_Y lda #2 - sta mos8(__rc2) + sta __rc2 2: txa and #$01 - ora mos8(__rc2) - sta mos8(__rc2) - lda mos8(PPUCTRL_VAR) + ora __rc2 + sta __rc2 + lda PPUCTRL_VAR and #$fc - ora mos8(__rc2) - sta mos8(PPUCTRL_VAR) + ora __rc2 + sta PPUCTRL_VAR rts @@ -523,11 +527,11 @@ split: tay txa and #$01 - sta mos8(__rc2) - lda mos8(PPUCTRL_VAR) + sta __rc2 + lda PPUCTRL_VAR and #$fc - ora mos8(__rc2) - sta mos8(__rc2) + ora __rc2 + sta __rc2 3: @@ -542,7 +546,7 @@ split: sty PPUSCROLL lda #0 sta PPUSCROLL - lda mos8(__rc2) + lda __rc2 sta PPUCTRL rts @@ -558,11 +562,11 @@ bank_spr: asl a asl a asl a - sta mos8(__rc2) - lda mos8(PPUCTRL_VAR) + sta __rc2 + lda PPUCTRL_VAR and #0b11110111 - ora mos8(__rc2) - sta mos8(PPUCTRL_VAR) + ora __rc2 + sta PPUCTRL_VAR rts @@ -578,11 +582,11 @@ bank_bg: asl a asl a asl a - sta mos8(__rc2) - lda mos8(PPUCTRL_VAR) + sta __rc2 + lda PPUCTRL_VAR and #0b11101111 - ora mos8(__rc2) - sta mos8(PPUCTRL_VAR) + ora __rc2 + sta PPUCTRL_VAR rts @@ -593,8 +597,8 @@ bank_bg: .globl vram_read vram_read: - sta mos8(__rc4) - stx mos8(__rc5) + sta __rc4 + stx __rc5 lda PPUDATA @@ -604,21 +608,21 @@ vram_read: lda PPUDATA sta (__rc2),y - inc mos8(__rc2) + inc __rc2 bne 2f - inc mos8(__rc3) + inc __rc3 2: - lda mos8(__rc4) + lda __rc4 bne 3f - dec mos8(__rc5) + dec __rc5 3: - dec mos8(__rc4) - lda mos8(__rc4) - ora mos8(__rc5) + dec __rc4 + lda __rc4 + ora __rc5 bne 1b rts @@ -630,8 +634,8 @@ vram_read: .globl vram_write vram_write: - sta mos8(__rc4) - stx mos8(__rc5) + sta __rc4 + stx __rc5 ldy #0 @@ -639,21 +643,21 @@ vram_write: lda (__rc2),y sta PPUDATA - inc mos8(__rc2) + inc __rc2 bne 2f - inc mos8(__rc3) + inc __rc3 2: - lda mos8(__rc4) + lda __rc4 bne 3f - dec mos8(__rc5) + dec __rc5 3: - dec mos8(__rc4) - lda mos8(__rc4) - ora mos8(__rc5) + dec __rc4 + lda __rc4 + ora __rc5 bne 1b rts @@ -672,7 +676,7 @@ pad_poll: lda #1 sta APU_PAD1 - sta mos8(__rc2),x + sta __rc2,x lda #0 sta APU_PAD1 @@ -680,18 +684,18 @@ pad_poll: lda APU_PAD1,y lsr a - rol mos8(__rc2),x + rol __rc2,x bcc .LpadPollLoop dex bne .LpadPollPort - lda mos8(__rc3) - cmp mos8(__rc4) + lda __rc3 + cmp __rc4 beq .Ldone - cmp mos8(__rc5) + cmp __rc5 beq .Ldone - lda mos8(__rc4) + lda __rc4 .Ldone: sta PAD_STATE,y @@ -710,10 +714,10 @@ pad_poll: .section .text.flush_vram_update,"ax",@progbits .globl flush_vram_update flush_vram_update: - lda mos8(__rc2) - sta mos8(NAME_UPD_ADR+0) - lda mos8(__rc3) - sta mos8(NAME_UPD_ADR+1) + lda __rc2 + sta NAME_UPD_ADR+0 + lda __rc3 + sta NAME_UPD_ADR+1 .globl flush_vram_update2 flush_vram_update2: ;minor changes % @@ -738,7 +742,7 @@ flush_vram_update2: ;minor changes % .LupdNotSeq: tax - lda mos8(PPUCTRL_VAR) + lda PPUCTRL_VAR cpx #$80 ;is it a horizontal or vertical sequence? bcc .LupdHorzSeq cpx #$ff ;is it end of the update? @@ -775,7 +779,7 @@ flush_vram_update2: ;minor changes % dex bne .LupdNameLoop - lda mos8(PPUCTRL_VAR) + lda PPUCTRL_VAR sta PPUCTRL jmp .LupdName @@ -795,8 +799,8 @@ __post_vram_update: .globl vram_fill vram_fill: - stx mos8(__rc3) - ldx mos8(__rc2) + stx __rc3 + ldx __rc2 beq 2f ldx #0 @@ -805,12 +809,12 @@ vram_fill: sta PPUDATA dex bne 1b - dec mos8(__rc2) + dec __rc2 bne 1b 2: - ldx mos8(__rc3) + ldx __rc3 beq 4f 3: @@ -837,11 +841,11 @@ vram_inc: 1: - sta mos8(__rc2) - lda mos8(PPUCTRL_VAR) + sta __rc2 + lda PPUCTRL_VAR and #$fb - ora mos8(__rc3) - sta mos8(PPUCTRL_VAR) + ora __rc3 + sta PPUCTRL_VAR sta PPUCTRL rts diff --git a/mos-platform/nes/neslib/ntsc.inc b/mos-platform/nes/neslib/ntsc.inc new file mode 100644 index 000000000..5309f73c1 --- /dev/null +++ b/mos-platform/nes/neslib/ntsc.inc @@ -0,0 +1 @@ +.zeropage NTSC_MODE diff --git a/mos-platform/nes/neslib/ntsc.s b/mos-platform/nes/neslib/ntsc.s index e99074c74..c4780a529 100644 --- a/mos-platform/nes/neslib/ntsc.s +++ b/mos-platform/nes/neslib/ntsc.s @@ -1,12 +1,15 @@ +.include "imag.inc" .include "nes.inc" +.include "ntsc.inc" +.include "neslib.inc" .section .init.275,"axR",@progbits .globl __do_init_ntsc_mode __do_init_ntsc_mode: waitSync3: - lda mos8(FRAME_CNT1) + lda FRAME_CNT1 1: - cmp mos8(FRAME_CNT1) + cmp FRAME_CNT1 beq 1b detectNTSC: @@ -20,13 +23,13 @@ detectNTSC: lda PPUSTATUS and #$80 - sta mos8(NTSC_MODE) + sta NTSC_MODE jsr ppu_off lda #0 - sta mos8(__rc2) - sta mos8(__rc3) + sta __rc2 + sta __rc3 jsr set_vram_update lda #0 diff --git a/mos-platform/nes/neslib/rand.s b/mos-platform/nes/neslib/rand.s index f2ec06131..0fdae8c8a 100644 --- a/mos-platform/nes/neslib/rand.s +++ b/mos-platform/nes/neslib/rand.s @@ -1,7 +1,9 @@ + .include "neslib.inc" + .section .init.270,"axR",@progbits lda #$fd - sta mos8(RAND_SEED) - sta mos8(RAND_SEED+1) + sta RAND_SEED + sta RAND_SEED+1 ;unsigned char rand8(void); .section .text.rand8,"ax",@progbits @@ -11,33 +13,33 @@ rand1: - lda mos8(RAND_SEED) + lda RAND_SEED asl a bcc 1f eor #$cf 1: - sta mos8(RAND_SEED) + sta RAND_SEED rts rand2: - lda mos8(RAND_SEED+1) + lda RAND_SEED+1 asl a bcc 1f eor #$d7 1: - sta mos8(RAND_SEED+1) + sta RAND_SEED+1 rts rand8: jsr rand1 jsr rand2 - adc mos8(RAND_SEED) + adc RAND_SEED rts @@ -59,8 +61,8 @@ rand16: .globl set_rand set_rand: - sta mos8(RAND_SEED) - stx mos8(RAND_SEED+1) + sta RAND_SEED + stx RAND_SEED+1 rts