From ad830a7f81871e15f43d7255f7af5463d9dd0bc5 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 12 May 2025 21:20:33 +0200 Subject: reset: Do not zero out RAM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is usually done so the programmer can forget about initializing in the future, but it not only hides programming mistakes, but we are also resetting memory addresses which are never to be used by this simple game. Hence, just skip resetting RAM altogether. Last but not least, sprite initialization in `reset` code has also been optimized so instead of around 2000 cycles it takes half of that. This is done by only touching the first byte of the four bytes for a sprite in OAM, which is enough for hiding random sprites and the cost of extra `inx` instructions is far cheaper than all the extra `sta` to absolute address with X-index from the old code. Signed-off-by: Miquel Sabaté Solà --- src/vectors.s | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'src/vectors.s') diff --git a/src/vectors.s b/src/vectors.s index 559a59d..8928aaf 100644 --- a/src/vectors.s +++ b/src/vectors.s @@ -5,64 +5,54 @@ ;; Pretty standard reset function, nothing crazy. .proc reset + ;; Disable interrupts and decimal mode. sei cld + ;; Disable APU frame counter. ldx #$40 stx APU::FRAME_COUNTER + ;; Setup the stack. ldx #$FF txs + ;; Disable NMIs and the APU's DMC. inx stx PPU::CONTROL stx PPU::MASK stx APU::DMC + ;; First PPU wait. bit PPU::STATUS @vblankwait1: bit PPU::STATUS bpl @vblankwait1 - ldx #0 - lda #0 -@ram_reset_loop: - sta $000, x - sta $100, x - sta $300, x - sta $400, x - sta $500, x - sta $600, x - sta $700, x - inx - bne @ram_reset_loop - + ;; Reset all sprites by simply moving the Y coordinate out of screen. lda #$EF + ldx #0 @sprite_reset_loop: sta $200, x inx + inx + inx + inx bne @sprite_reset_loop + ;; DMA setup for sprite reset. lda #$00 sta OAM::ADDRESS lda #$02 sta OAM::DMA + ;; Second PPU wait. After that the PPU is stable. @vblankwait2: bit PPU::STATUS bpl @vblankwait2 - lda #$3F - sta PPU::ADDRESS - lda #$00 - sta PPU::ADDRESS - - lda #$0F - ldx #$20 -@palettes_reset_loop: - sta PPU::DATA - dex - bne @palettes_reset_loop + ;; NOTE: palettes are not initialized here as it's going to be one of the + ;; first things done on `main` code. jmp main .endproc -- cgit v1.2.3