aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bb.edn4
-rw-r--r--main.fab132
-rw-r--r--nEs.cfg1
-rw-r--r--nEs.nesbin40976 -> 40976 bytes
-rw-r--r--nEslabels.mlb47
5 files changed, 149 insertions, 35 deletions
diff --git a/bb.edn b/bb.edn
index 2411642..7fbc336 100644
--- a/bb.edn
+++ b/bb.edn
@@ -2,7 +2,9 @@
:tasks
{build
{:doc "Builds the nesfab project"
- :task (shell "../nesfab/nesfab nEs.cfg")}
+ :task (do
+ (shell "rm nEslabels.mlb")
+ (shell "../nesfab/nesfab nEs.cfg"))}
watch
{:doc "Automatically build the nesfab project on file writes"
:requires ([pod.babashka.fswatcher :as fw])
diff --git a/main.fab b/main.fab
index 8624f9d..a47ec27 100644
--- a/main.fab
+++ b/main.fab
@@ -1,54 +1,118 @@
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[64] buf // A buffer that can store the current and next row
+ U curr_gen = 0 // Swap these offsets back and forth per generation
+ U next_gen = 32
+ 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)
+ // Scroll to attributes
+ ppu_reset_addr($2000 + 960)
+ // Set attributes for background
+ for U i = 0; i < 64; i+= 1
+ {PPUDATA}(%11111111)
- // Set background tiles
- for UU i = 0; i < 960; i += 1
- {PPUDATA}(1)
+ //// Init the buffers to 0
+ //for i = 0; i < 64; i += 1
+ // buf[i] = 0
- U i = 0
- // Set attributes for background
- for i = 0; i < 64; i+= 1
- {PPUDATA}(%00011011)
+ // Init the buffer to zero
+ buf = U[64]()
+ // Add an initial cell
+ buf[16] = 1
- // 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)
+fn assemble_code(U left, U middle, U right) U
+ U out = %00000000
+ out |= left << 2
+ out |= middle << 1
+ out |= right
+ return out
- for UU i = 0; i < 32; i += 1
- //next_cell = 0 //get_next_gen(i)
- {PPUDATA}(next_cell)
+fn calc_next_cell(U left, U middle, U right) U
+ U code = assemble_code(left, middle, right)
+ ct U mask7 = %10000000
+ ct U mask6 = %01000000
+ ct U mask5 = %00100000
+ ct U mask4 = %00010000
+ ct U mask3 = %00001000
+ ct U mask2 = %00000100
+ ct U mask1 = %00000010
+ ct U mask0 = %00000001
+ switch code
+ case %00000111
+ return (current_rule & mask7) >> 7
+ case %00000110
+ return (current_rule & mask6) >> 6
+ case %00000101
+ return (current_rule & mask5) >> 5
+ case %00000100
+ return (current_rule & mask4) >> 4
+ case %00000011
+ return (current_rule & mask3) >> 3
+ case %00000010
+ return (current_rule & mask2) >> 2
+ case %00000001
+ return (current_rule & mask1) >> 1
+ case %00000000
+ return (current_rule & mask0) >> 0
- drawing_row_offset += 1
+fn calc_and_advance_gen()
+ // Calculate the next row's values
+ U left_ind = 0
+ U right_ind = 0
+ U left_cell = 0
+ U mid_cell = 0
+ U right_cell = 0
+ U next_cell = 0
+ for U i = 0; i < 32; i += 1
+ // Calculate indices for left and right of cell
+ if i == 0
+ left_ind = 31
+ else
+ left_ind = i - 1
+ if i == 31
+ right_ind = 0
+ else
+ right_ind = i + 1
+ // Get left and right of cell
+ left_cell = buf[curr_gen + left_ind]
+ mid_cell = buf[curr_gen + i]
+ right_cell = buf[curr_gen + right_ind]
+ // Calc next cell
+ next_cell = calc_next_cell(left_cell, mid_cell, right_cell)
+ // Set next cell
+ buf[next_gen + i] = next_cell
+ // Advance next generation
+ if curr_gen == 0
+ curr_gen = 32
+ next_gen = 0
+ else
+ curr_gen = 0
+ next_gen = 32
+
+ // advance drawing row offset, looping back to top
+ 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)
+fn upload_curr_gen()
+ // "scroll" to the row we're at
+ UU row_start = $2000
+ row_start += (drawing_row_offset * 32)
+ ppu_reset_addr(row_start)
+ for U i = 0; i < 32; i += 1 //32 columns
+ //next_cell = 0 //get_next_gen(i)
+ {PPUDATA}(buf[i+curr_gen])
- calc_and_upload_next_row()
+nmi main_nmi()
// Turn on rendering sprites and bg
{PPUMASK}(PPUMASK_ON | PPUMASK_NO_CLIP)
+ upload_curr_gen()
+
ppu_reset_scroll(0, 0)
@@ -58,7 +122,7 @@ mode main()
palette = example_palette
ppu_upload_palette()
- // Load the background
+ // Initialize the screen
init_screen()
// Turn the NMI on
@@ -66,8 +130,8 @@ mode main()
// Loop forever:
while true
- update_pads()
nmi
+ calc_and_advance_gen()
// Define the tileset (commonly called CHR):
chrrom
diff --git a/nEs.cfg b/nEs.cfg
index 5712d83..7f191a1 100644
--- a/nEs.cfg
+++ b/nEs.cfg
@@ -4,3 +4,4 @@ nesfab-dir = ../nesfab/
input = main.fab
input = lib/nes.fab
output = nEs.nes
+mlb = nEslabels.mlb
diff --git a/nEs.nes b/nEs.nes
index f9ae3ed..2893029 100644
--- a/nEs.nes
+++ b/nEs.nes
Binary files differ
diff --git a/nEslabels.mlb b/nEslabels.mlb
new file mode 100644
index 0000000..8098217
--- /dev/null
+++ b/nEslabels.mlb
@@ -0,0 +1,47 @@
+NesPrgRom:000631:calc_next_cell@0_0:
+NesPrgRom:00052C:calc_and_advance_gen@0_0:
+NesPrgRom:000535:calc_and_advance_gen@0_0_entry:
+NesPrgRom:0005B6:main_nmi@0_1:
+NesPrgRom:0004A7:main@0_0:
+NesPrgRom:000230:ppu_upload_palette@0_0:
+NesPrgRom:007FFA-007FFF:runtime_vectors@0_0:
+NesPrgRom:00011C-00012F:runtime_nmi@0_1:
+NesPrgRom:000130-000137:runtime_nmi_exit@0_1:
+NesPrgRom:000139-000147:runtime_wait_nmi@0_0:
+NesPrgRom:00022A-00022B:runtime_nmi_lo_table@0_0:
+NesPrgRom:00022C-00022D:runtime_nmi_hi_table@0_0:
+NesPrgRom:00022E-00022F:runtime_nmi_bank_table@0_0:
+NesPrgRom:000138-000138:runtime_irq@0_2:
+NesPrgRom:000138-000138:runtime_irq_exit@0_2:
+NesPrgRom:000148-00014D:runtime_reset@0_0:
+NesPrgRom:00014E-000150:runtime_jmp_indirect@0_0:
+NesPrgRom:000151-000153:runtime_jmp_indirect@0_1:
+NesPrgRom:000154-000156:runtime_jmp_indirect@0_2:
+NesPrgRom:000000-0000FF:runtime_iota@0_0:
+NesPrgRom:000157-00019C:runtime_mul8@0_0:
+NesPrgRom:00019D-0001E2:runtime_mul8@0_1:
+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:031F:buf@0:
+R:000F:curr_gen@0:
+R:000D:next_gen@0:
+R:0010:drawing_row_offset@0:
+R:0011:drawing_row_offset@1:
+R:000E:current_rule@0:
+R:0200:oam@0:
+R:0319:pads@0:
+R:031B:pads@1:
+R:031D:pads@2:
+R:0012:raw_pads@0:
+R:0300:palette@0:
+R:0001:runtime_ptr_temp@0:
+R:0003:runtime_ptr_temp@1:
+R:0005:runtime_ptr_temp@2:
+R:0007:runtime_nmi_index@0:
+R:0008:runtime_nmi_saved_x@0:
+R:0009:runtime_nmi_saved_y@0:
+R:000A:runtime_nmi_counter@0:
+R:000B:runtime_nmi_ready@0:
+R:000C:runtime_system@0: