aboutsummaryrefslogtreecommitdiff
path: root/main.fab
diff options
context:
space:
mode:
authorPatrick Kingston <patrick@pkingston.xyz>2026-02-13 20:47:44 -0500
committerPatrick Kingston <patrick@pkingston.xyz>2026-02-13 20:47:44 -0500
commit62966cf7418c73d68870a6f1adb87042a23c2471 (patch)
tree7a3c4d12d1c710f313d257d264eb606905581e4c /main.fab
parent80a1f6aa01bcff47bbe6c4273233997da0d3c271 (diff)
Get background rewriting/scroll working
Diffstat (limited to 'main.fab')
-rw-r--r--main.fab60
1 files changed, 57 insertions, 3 deletions
diff --git a/main.fab b/main.fab
index ebbb2a4..8624f9d 100644
--- a/main.fab
+++ b/main.fab
@@ -1,19 +1,73 @@
-fn load_level()
+vars
+ U[8] buf // A buffer that can store the current and next row
+ U row_a = 0 // We swap back and forth between these two offsets for each row
+ U row_b = 4
+ UU drawing_row_offset = 0// Use this to track which row we're drawing
+ U current_rule = %00011110
+ U next_cell = 0
+
+fn init_screen()
ppu_reset_addr($2000)
- for UU i = 0; i < 1024; i += 1
+ // Set background tiles
+ for UU i = 0; i < 960; i += 1
{PPUDATA}(1)
+ U i = 0
+ // Set attributes for background
+ for i = 0; i < 64; i+= 1
+ {PPUDATA}(%00011011)
+
+ // Init the buffers to 0
+ for i = 0; i < 8; i += 1
+ buf[i] = 0
+
+fn calc_and_upload_next_row()
+ // "scroll" to the row we're at
+ UU row_start = $2000
+ row_start += (drawing_row_offset * 32)
+ ppu_reset_addr(row_start)
+
+ for UU i = 0; i < 32; i += 1
+ //next_cell = 0 //get_next_gen(i)
+ {PPUDATA}(next_cell)
+
+ drawing_row_offset += 1
+
+ if drawing_row_offset == 30
+ drawing_row_offset = 0
+ if next_cell
+ next_cell = 0
+ else
+ next_cell = 1
+
+nmi main_nmi()
+ ppu_upload_oam_poll_pads(0)
+
+ calc_and_upload_next_row()
+
+ // Turn on rendering sprites and bg
+ {PPUMASK}(PPUMASK_ON | PPUMASK_NO_CLIP)
+
+ ppu_reset_scroll(0, 0)
+
+
mode main()
+: nmi main_nmi
// Set the palette:
palette = example_palette
ppu_upload_palette()
// Load the background
- {PPUMASK}(PPUMASK_BG_ON | PPUMASK_NO_CLIP)
+ init_screen()
+
+ // Turn the NMI on
+ {PPUCTRL}(PPUCTRL_NMI_ON)
// Loop forever:
while true
+ update_pads()
+ nmi
// Define the tileset (commonly called CHR):
chrrom