From 62966cf7418c73d68870a6f1adb87042a23c2471 Mon Sep 17 00:00:00 2001 From: Patrick Kingston Date: Fri, 13 Feb 2026 20:47:44 -0500 Subject: Get background rewriting/scroll working --- main.fab | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- nEs.cfg | 1 + nEs.nes | Bin 40976 -> 40976 bytes 3 files changed, 58 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 diff --git a/nEs.cfg b/nEs.cfg index cf96c4e..5712d83 100644 --- a/nEs.cfg +++ b/nEs.cfg @@ -1,4 +1,5 @@ mapper = NROM +mirroring = H nesfab-dir = ../nesfab/ input = main.fab input = lib/nes.fab diff --git a/nEs.nes b/nEs.nes index 500b066..f9ae3ed 100644 Binary files a/nEs.nes and b/nEs.nes differ -- cgit v1.2.3