aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basics/flicker.s3
-rw-r--r--fx/blink.s3
-rw-r--r--scroll/roulette.s5
-rw-r--r--shared/clear.s39
4 files changed, 50 insertions, 0 deletions
diff --git a/basics/flicker.s b/basics/flicker.s
index 234c8a1..8db03e8 100644
--- a/basics/flicker.s
+++ b/basics/flicker.s
@@ -21,8 +21,11 @@
.segment "CODE"
.include "../shared/diskun.s"
+.include "../shared/clear.s"
.proc main
+ CLEAR_SCREEN
+
jsr Diskun::init_palettes
jsr init_sprites
diff --git a/fx/blink.s b/fx/blink.s
index 4fdaa6b..fb63ffd 100644
--- a/fx/blink.s
+++ b/fx/blink.s
@@ -122,6 +122,7 @@
;;; player around.
.segment "FIXED"
.include "../shared/diskun.s"
+.include "../shared/clear.s"
;;; NOTE: the main bulk of this example. Comments only for the parts which are
;;; specific to this example.
@@ -252,6 +253,8 @@ reset:
lda #4
sta Vars::last_bank
+ CLEAR_SCREEN
+
jsr Diskun::init_palettes
jsr init_sprites
diff --git a/scroll/roulette.s b/scroll/roulette.s
index 4b13c22..aca7d72 100644
--- a/scroll/roulette.s
+++ b/scroll/roulette.s
@@ -107,6 +107,7 @@
;;; player around.
.segment "FIXED"
.include "../shared/diskun.s"
+.include "../shared/clear.s"
;;; NOTE: the main bulk of this example. Comments only for the parts which are
;;; specific to this example.
@@ -201,6 +202,10 @@ reset:
;; The main function is used here only for further initialization purposes.
.proc main
+ ;; Clear both screens to avoid funky business, as we are not doing anything
+ ;; specially clever here.
+ CLEAR_SCREENS $20, $24
+
;; Initialize both the palettes and the nametables.
jsr Diskun::init_palettes
jsr init_nametables
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