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/jetpac.s | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/jetpac.s') diff --git a/src/jetpac.s b/src/jetpac.s index 65b5d11..10f6df3 100644 --- a/src/jetpac.s +++ b/src/jetpac.s @@ -45,9 +45,17 @@ .include "vectors.s" .proc main - ;; Disable the PPU. + ;; Disable the PPU and zero out variables which shadow PPU registers. lda #0 sta PPU::MASK + sta PPU::zp_mask + sta PPU::zp_control + + ;; Initialize other global variables which the rest of the game assume to + ;; have zero as their initial values. + sta Globals::zp_flags + sta Joypad::zp_buttons1 + sta Joypad::zp_buttons2 ;; Initialize the assets for the game. jsr Assets::init -- cgit v1.2.3