diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-03-07 16:04:42 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-03-07 16:07:04 +0100 |
| commit | ff22231f8a2f3714df701fd7c12b07915adc15e9 (patch) | |
| tree | 58695f6bd62a9de54d58bc80cae07c4d40c7ad81 /shared/clear.s | |
| parent | 54d9231c26459e12bd2f164f01db2110794639c0 (diff) | |
| download | code.nes-ff22231f8a2f3714df701fd7c12b07915adc15e9.tar.gz code.nes-ff22231f8a2f3714df701fd7c12b07915adc15e9.zip | |
shared: Add utilities for clearing screens
These are quite mindless, but they are rather useful on simple examples
in which we don't care about performance and we just want to show
something on the screen.
For now this didn't matter much, but on real hardware I was able to
reproduce the same glitches as with emulators which randomized memory on
both the CPU memory and on the PPU. Hence, just allow some examples to
manually reset these regions and avoid silly graphical glitches.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'shared/clear.s')
| -rw-r--r-- | shared/clear.s | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/shared/clear.s b/shared/clear.s new file mode 100644 index 0000000..a099387 --- /dev/null +++ b/shared/clear.s @@ -0,0 +1,39 @@ +;; Clear the first nametable by resetting it to the default tile ID. This is a +;; rather drastic measure only to be done on examples that don't actually load +;; columns in "clever" ways, but they just want a clean slate. +.macro CLEAR_SCREEN + ldy #$20 + jsr clear_screen_y +.endmacro + +;; Clear the given two nametables. `ONE` and `OTHER` have to be the high byte +;; for each nametable to clear. For example, on an horizontal scrolling game: +;; `CLEAR_SCREENS $20, $24`. +.macro CLEAR_SCREENS ONE, OTHER + ldy #ONE + jsr clear_screen_y + + ldy #OTHER + jsr clear_screen_y +.endmacro + +;; Clear the nametable with the high byte as defined in the `y` register. +.proc clear_screen_y + bit $2002 + + ldx #$FF +@loop: + sty $2006 + stx $2006 + lda #$00 + sta $2007 + + dex + bne @loop + + iny + cpy #$24 + bne @loop + + rts +.endproc |
