From 0aefffacb5cb08202f7ba53b6e3b9a7303b1d66e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 23 Jan 2025 13:57:45 +0100 Subject: Use custom configurations everywhere MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moreover, I have introduced a linker configuration for MMC1 as well, so to properly implement the `basics/persist.s` example. Signed-off-by: Miquel Sabaté Solà --- basics/flicker.s | 1 - basics/input.s | 3 +-- basics/persist.s | 24 ++++++++++++++++-------- basics/sprite.s | 28 ++++++++++++++++------------ 4 files changed, 33 insertions(+), 23 deletions(-) (limited to 'basics') diff --git a/basics/flicker.s b/basics/flicker.s index 34fc312..25f1d33 100644 --- a/basics/flicker.s +++ b/basics/flicker.s @@ -18,7 +18,6 @@ .segment "CHARS" .incbin "../assets/diskun.chr" -.segment "STARTUP" .segment "CODE" .include "../shared/diskun.s" diff --git a/basics/input.s b/basics/input.s index 6918487..b773fd7 100644 --- a/basics/input.s +++ b/basics/input.s @@ -32,8 +32,6 @@ .addr reset .addr irq -.segment "STARTUP" - .segment "CODE" nmi: @@ -173,3 +171,4 @@ pressed: .endproc .segment "CHARS" +.byte $00 diff --git a/basics/persist.s b/basics/persist.s index 430654f..3e7c439 100644 --- a/basics/persist.s +++ b/basics/persist.s @@ -11,10 +11,9 @@ ;; Last but not least, all of this is done thanks to the MMC1 chip. Thus, this ;; file is also a minimalistic example on how to configure it, even if it ;; doesn't take full advantage of it (e.g. we are not doing any bank switching). -;; Because of this, note that we are not using a proper linker configuration for -;; it (I'm using cc65's default, which is tailored for NROM chips). Thus, bank -;; switching will actually never work under this setup. Bank switching is -;; covered through other examples like `basics/unrom.s`. +;; A base configuration for this chip can be found in `config/mmc1.cfg`. For +;; better grasping bank switching though refer to other examples like +;; `basics/unrom.s`. .segment "HEADER" .byte 'N', 'E', 'S', $1A @@ -36,9 +35,12 @@ .addr reset .addr irq -.segment "STARTUP" -.segment "CODE" +;; Unused. This is the swappable PRG-ROM bank as per `config/mmc1.cfg`. +.segment "BANK0" +.byte $00 +;; This is the fixed PRG-ROM bank as per `config/mmc1.cfg`. +.segment "BANK1" ;; Unused nmi: @@ -65,7 +67,7 @@ reset: ;; point to any address range of $8000-$FFFF. If you want to be sure about ;; it, you can simply do: `lda #%10000000` and then `sta $8000`. This will ;; ensure that the chip is reset. That being said, a micro-optimization can - ;; be performed by taking advantage that the "CODE" segment resides above + ;; be performed by taking advantage that the "BANK1" segment resides above ;; address $8000. Then, you can use the `inc` instruction which first writes ;; the old value before the incremented one. All having thus the same effect ;; but saving 2 bytes. I know it's somewhat obfuscated and it's done for @@ -164,4 +166,10 @@ reset_mmc1: @loop: jmp @loop -.segment "CHARS" +;; Unused +.segment "CHR0" +.byte $00 + +;; Unused +.segment "CHR1" +.byte $00 diff --git a/basics/sprite.s b/basics/sprite.s index 34f9dba..1fa55ad 100644 --- a/basics/sprite.s +++ b/basics/sprite.s @@ -70,18 +70,20 @@ .addr irq ;;; -;; Required by the default linker configuration. Theoretically there should be a -;; semantical difference between this section and "CODE", but as for the linker -;; goes, there is no difference and everything will be put sequentially on the -;; resulting binary. Hence, if you want (and as I do here), you can leave this -;; empty (so to make the default configuration of the linker happy), and put -;; everything into the "CODE" segment. In fact, according to the Famicom Party -;; Book (https://famicom.party/book/04-hardwareoverview/), the "STARTUP" section -;; is only used by C programs compiled down into 6502 assembly, so it might not -;; be even relevant for us (and in fact said book actually removes this segment -;; in its linker configuration down the road). +;; The "STARTUP" segment is required by the default linker configuration. +;; Theoretically there should be a semantical difference between this section +;; and "CODE", but as for the linker goes, there is no difference and everything +;; will be put sequentially on the resulting binary. Hence, if you want, you can +;; leave this empty (so to make the default configuration of the linker happy), +;; and put everything into the "CODE" segment. In fact, according to the Famicom +;; Party Book (https://famicom.party/book/04-hardwareoverview/), the "STARTUP" +;; section is only used by C programs compiled down into 6502 assembly, so it +;; might not be even relevant for assembly programmers (and in fact said book +;; actually removes this segment in its linker configuration down the road). +;; This is also removed by the configuration provided in `config/nrom.cfg`, +;; which is the one being used in the end for this example. ;;; -.segment "STARTUP" +;; .segment "STARTUP" .segment "CODE" @@ -143,7 +145,9 @@ reset: ;;; ;; NOTE: If you are using a mapper which needs some special configuration, ;; now it would be a good time set it up. I am not using a special mapper, - ;; so there's nothing from me to do here. + ;; so there's nothing from me to do here. Refer to other examples like + ;; `basics/persist.s` on how some chips such as MMC1 are set up at this + ;; point. ;;; ;; At this point, we have to wait for the PPU to stabilize. This is -- cgit v1.2.3