aboutsummaryrefslogtreecommitdiff
path: root/main.fab
diff options
context:
space:
mode:
Diffstat (limited to 'main.fab')
-rw-r--r--main.fab126
1 files changed, 108 insertions, 18 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<asd>")
data /titlescreen