From e8d1438d09f0a52eb76500170510c193e6331ed8 Mon Sep 17 00:00:00 2001 From: Patrick Kingston Date: Sat, 14 Feb 2026 23:03:18 -0500 Subject: Use rule and init from settings --- main.fab | 126 +++++++++++++++++++++++++++++++++++++++++++++++++--------- nEs.nes | Bin 40976 -> 40976 bytes nEslabels.mlb | 48 ++++++++++++---------- 3 files changed, 134 insertions(+), 40 deletions(-) diff --git a/main.fab b/main.fab index dcf985c..607ebb5 100644 --- a/main.fab +++ b/main.fab @@ -6,17 +6,15 @@ vars /ecavars U current_rule = %01001001 fn init_eca_state() - // Scroll to attributes - ppu_reset_addr($2000 + 960) - // Set attributes for background - for U i = 0; i < 64; i+= 1 - {PPUDATA}(%11111111) - - // Init the buffer to zero - buf = U[64]() - // Add an initial cell - buf[16] = 1 + {PPUMASK}(~PPUMASK_ON) + // Clear display and set attributes + ppu_reset_addr($2000) + for UU i = 0; i < 1024; i += 1 + {PPUDATA}(%00000000) + // Reset drawing row offset + drawing_row_offset = 0 + {PPUMASK}(PPUMASK_ON) fn assemble_code(U left, U middle, U right) U U out = %00000000 @@ -107,10 +105,10 @@ nmi eca_nmi() // Turn on rendering sprites and bg ppu_upload_oam_poll_pads(0) - {PPUMASK}(PPUMASK_ON | PPUMASK_NO_CLIP) - upload_curr_gen() + {PPUMASK}(PPUMASK_BG_ON | PPUMASK_NO_CLIP) + ppu_reset_scroll(0, 0) // Main mode for running the ECA @@ -171,19 +169,111 @@ vars /settings_vars U slow_counter = 0 U editing_rule = 1 // Start off editing the rule U rule_pos = 0 // Start off on highest bit - U generation_pos = 0 + U init_pos = 0 U cursor_x = 0 U cursor_y = 0 U cursor_frame = 0 U loaded = 0 + U should_update_tile = 0 + U tile_to_update = 0 + U zero = 71 + U one = 72 + +fn upload_cursor() + // Our stack index into OAM: + U i = 0 + + // Push a sprite: + set_oam_x(i, cursor_x) // x-position + set_oam_y(i, cursor_y - 1) // y-position + set_oam_p(i, $49 + cursor_frame) // tile + set_oam_a(i, 0) // options + i += 4 + + // Clear the remainder of OAM + hide_oam(i) + +fn update_cursor() + if slow_counter == 0 + cursor_frame += 1 + if cursor_frame == 8 + cursor_frame = 0 + + if pads[0].pressed & BUTTON_UP + editing_rule = 1 + else if pads[0].pressed & BUTTON_DOWN + editing_rule = 0 + + if editing_rule + if pads[0].pressed & BUTTON_LEFT + if rule_pos == 0 + rule_pos = 8 // loop back around + rule_pos -= 1 + else if pads[0].pressed & BUTTON_RIGHT + rule_pos += 1 + if rule_pos == 8 + rule_pos = 0 // loop back around + + if pads[0].pressed & BUTTON_A + U mask = U(1) << (7 - rule_pos) + current_rule ^= mask + if current_rule & mask + tile_to_update = one + else + tile_to_update = zero + should_update_tile = 1 + + // Find the cursor position + cursor_x = 5 + cursor_y = 8 + if rule_pos > 3 + cursor_x += 7 * (rule_pos - 4) + cursor_y += 3 + else + cursor_x += 7 * rule_pos + + // Scale it + cursor_x <<= 3 + cursor_y <<= 3 + else + if pads[0].pressed & BUTTON_LEFT + if init_pos == 0 + init_pos = 32 // loop back around + init_pos -= 1 + else if pads[0].pressed & BUTTON_RIGHT + init_pos += 1 + if init_pos == 32 + init_pos = 0 // loop back around + + if pads[0].pressed & BUTTON_A + U tile = buf[curr_gen + init_pos] + if tile // Not sure if I can just do buf[curr_gen + init_pos] = !tile + buf[curr_gen + init_pos] = 0 + tile_to_update = zero + else + buf[curr_gen + init_pos] = 1 + tile_to_update = one + + should_update_tile = 1 + + cursor_x = init_pos << 3 // Uses the whole row + cursor_y = 160 nmi settings_nmi() // Turn on rendering sprites and bg ppu_upload_oam_poll_pads(0) + if should_update_tile + ppu_reset_addr($2000 + (UU(cursor_x) >> 3) + ((UU(cursor_y) & %11111000) << 2)) + {PPUDATA}(tile_to_update) + should_update_tile = 0 + if loaded {PPUMASK}(PPUMASK_ON | PPUMASK_NO_CLIP) + slow_counter += 1 + if slow_counter == 4 // Slow counter "ticks" every 4 frames + slow_counter = 0 ppu_reset_scroll(0, 0) mode settings() @@ -207,18 +297,18 @@ mode settings() {PPUMASK}(PPUMASK_ON) - // Set the init to the current generation and set the rule to the current rule - // TODO ^ - + buf = U[64]() // Reset the buffer to all 0s while true nmi update_pads() - //update_cursor() - //upload_cursor() + update_cursor() + upload_cursor() if pads[0].released & BUTTON_START goto mode eca_main() : preserves /ecavars + + charmap titlemap(".#-=N!@~E$%^S&*(C)_+A{}|12345678qwertyuiop") data /titlescreen diff --git a/nEs.nes b/nEs.nes index c915bf2..f88b32a 100644 Binary files a/nEs.nes and b/nEs.nes differ diff --git a/nEslabels.mlb b/nEslabels.mlb index dab4ef8..29e3e6a 100644 --- a/nEslabels.mlb +++ b/nEslabels.mlb @@ -1,17 +1,18 @@ -NesPrgRom:001015:calc_next_cell@0_0: -NesPrgRom:000E88:calc_and_advance_gen@0_0: -NesPrgRom:000E91:calc_and_advance_gen@0_0_entry: -NesPrgRom:000F12:eca_nmi@0_1: -NesPrgRom:000F94:eca_main@0_0: -NesPrgRom:0010B7:settings_nmi@0_1: +NesPrgRom:001202:calc_next_cell@0_0: +NesPrgRom:001088:calc_and_advance_gen@0_0: +NesPrgRom:001091:calc_and_advance_gen@0_0_entry: +NesPrgRom:001112:eca_nmi@0_1: +NesPrgRom:000F05:eca_main@0_0: +NesPrgRom:000C50:update_cursor@0_0: +NesPrgRom:001194:settings_nmi@0_1: NesPrgRom:00076D:settings@0_0: -NesPrgRom:000CCE:main_nmi@0_1: -NesPrgRom:000CD1:main_nmi@0_1_entry: +NesPrgRom:000E61:main_nmi@0_1: +NesPrgRom:000E64:main_nmi@0_1_entry: NesPrgRom:000279:main@0_0: NesPrgRom:000238:ppu_upload_oam_poll_pads@0_1: -NesPrgRom:001082:update_pads@0_0: -NesPrgRom:000C15:ppu_upload_palette@0_0: -NesPrgRom:000855-000C14:settingschars@0_0: +NesPrgRom:00126F:update_pads@0_0: +NesPrgRom:000DA8:ppu_upload_palette@0_0: +NesPrgRom:000890-000C4F:settingschars@0_0: NesPrgRom:00038D-00076C:title@0_0: NesPrgRom:007FFA-007FFF:runtime_vectors@0_0: NesPrgRom:00011C-00012F:runtime_nmi@0_1: @@ -33,26 +34,29 @@ NesPrgRom:0001E3-000228:runtime_mul8@0_2: NesPrgRom:000100-00010F:runtime_shl4_table@0_0: NesPrgRom:000110-000117:runtime_shl5_table@0_0: NesPrgRom:000118-00011B:runtime_shl6_table@0_0: -R:0326:buf@0: +R:031F:buf@0: R:000D:curr_gen@0: R:0010:next_gen@0: R:000E:drawing_row_offset@0: R:000F:drawing_row_offset@1: R:0011:current_rule@0: -R:031F:slow_counter@0: -R:0325:editing_rule@0: -R:0320:rule_pos@0: -R:0321:generation_pos@0: -R:0322:cursor_x@0: -R:0323:cursor_y@0: -R:0324:cursor_frame@0: -R:0014:loaded@0__wipeline@0: -R:0015:wipeline@1: +R:0012:slow_counter@0__wipeline@0: +R:001D:editing_rule@0: +R:0013:rule_pos@0__wipeline@1: +R:0014:init_pos@0: +R:0015:cursor_x@0: +R:0016:cursor_y@0: +R:0017:cursor_frame@0: +R:0018:loaded@0: +R:0019:should_update_tile@0: +R:001A:tile_to_update@0: +R:001E:zero@0: +R:001F:one@0: R:0200:oam@0: R:0319:pads@0: R:031B:pads@1: R:031D:pads@2: -R:0012:raw_pads@0: +R:001B:raw_pads@0: R:0300:palette@0: R:0001:runtime_ptr_temp@0: R:0003:runtime_ptr_temp@1: -- cgit v1.2.3