added constants to automata code, more readable

This commit is contained in:
2021-11-29 16:56:41 +01:00
parent 0cff33d046
commit 78432f66d9

View File

@@ -1,5 +1,12 @@
INCLUDE "hardware.inc" INCLUDE "hardware.inc"
CELLS_WIDTH = 40
CELLS_HEIGHT = 36
CELLS_PER_TILE = 2
TILE_WIDTH = CELLS_WIDTH / CELLS_PER_TILE
TILE_HEIGHT = CELLS_HEIGHT / CELLS_PER_TILE
BUFFER_SIZE = TILE_WIDTH * TILE_HEIGHT
; automata buffers with 4 cells per byte ; automata buffers with 4 cells per byte
; 2x2 bytes per cell, bit ordering: ; 2x2 bytes per cell, bit ordering:
; ___ ___ ; ___ ___
@@ -9,11 +16,11 @@ INCLUDE "hardware.inc"
; bits 4, 5, 6 and 7 are not used ; bits 4, 5, 6 and 7 are not used
EXPORT Buffer0 EXPORT Buffer0
SECTION "Automata buffer 0", WRAM0, ALIGN[9] SECTION "Automata buffer 0", WRAM0, ALIGN[9]
Buffer0: ds 20 * 18 Buffer0: ds BUFFER_SIZE
EXPORT Buffer1 EXPORT Buffer1
SECTION "Automata buffer 1", WRAM0, ALIGN[9] SECTION "Automata buffer 1", WRAM0, ALIGN[9]
Buffer1: ds 20 * 18 Buffer1: ds BUFFER_SIZE
EXPORT New, Old, Progress EXPORT New, Old, Progress
SECTION "Automata data", HRAM SECTION "Automata data", HRAM
@@ -156,19 +163,19 @@ SECTION "Update Automata", ROM0
UpdateAutomata: UpdateAutomata:
.topleft .topleft
; handle top left corner ; handle top left corner
ConwayGroup 1, 21, 20, 39, 19, 359, 340, 341 ConwayGroup 1, (TILE_WIDTH + 1), TILE_WIDTH, (2 * TILE_WIDTH - 1), (TILE_WIDTH - 1), (BUFFER_SIZE - 1), (BUFFER_SIZE - TILE_WIDTH), (BUFFER_SIZE - TILE_WIDTH + 1)
; advance to next cell in top row ; advance to next cell in top row
ld hl, Progress ld hl, Progress
inc [hl] inc [hl]
; handle all cells in top row except corners ; handle all cells in top row except corners
ld a, 18 ld a, (TILE_WIDTH - 2)
.top .top
ld [XLoop], a ld [XLoop], a
; handle top row cell ; handle top row cell
ConwayGroup 1, 21, 20, 19, -1, 339, 340, 341 ConwayGroup 1, (TILE_WIDTH + 1), TILE_WIDTH, (TILE_WIDTH - 1), -1, (BUFFER_SIZE - TILE_WIDTH - 1), (BUFFER_SIZE - TILE_WIDTH), (BUFFER_SIZE - TILE_WIDTH + 1)
; advance to next cell in top row ; advance to next cell in top row
ld hl, Progress ld hl, Progress
@@ -181,18 +188,18 @@ UpdateAutomata:
; handle top right corner ; handle top right corner
.topright .topright
ConwayGroup -19, 1, 20, 19, -1, 339, 340, 321 ConwayGroup (-TILE_WIDTH + 1), 1, TILE_WIDTH, (TILE_WIDTH - 1), -1, (BUFFER_SIZE - TILE_WIDTH - 1), (BUFFER_SIZE - TILE_WIDTH), (BUFFER_SIZE - 2 * TILE_WIDTH + 1)
; advance pointers to next row ; advance pointers to next row
ld hl, Progress ld hl, Progress
inc [hl] inc [hl]
ld a, 16 ld a, (TILE_HEIGHT - 2)
.leftcolumn .leftcolumn
ld [YLoop], a ld [YLoop], a
; handle first element in row ; handle first element in row
ConwayGroup 1, 21, 20, 39, 19, -1, -20, -19 ConwayGroup 1, (TILE_WIDTH + 1), TILE_WIDTH, (2 * TILE_WIDTH - 1), (TILE_WIDTH - 1), -1, (-TILE_WIDTH), (-TILE_WIDTH + 1)
; advance to next cell ; advance to next cell
ld hl, Progress ld hl, Progress
@@ -203,7 +210,7 @@ UpdateAutomata:
ld [XLoop], a ld [XLoop], a
; handle element inside row ; handle element inside row
ConwayGroup 1, 21, 20, 19, -1, -21, -20, -19 ConwayGroup 1, (TILE_WIDTH + 1), TILE_WIDTH, (TILE_WIDTH - 1), -1, (-TILE_WIDTH - 1), (-TILE_WIDTH), (-TILE_WIDTH + 1)
; advance to next cell ; advance to next cell
ld hl, Progress ld hl, Progress
@@ -222,7 +229,7 @@ UpdateAutomata:
; handle last element in row ; handle last element in row
.rightcolumn .rightcolumn
ConwayGroup -19, 1, 20, 19, -1, -21, -20, -39 ConwayGroup (-TILE_WIDTH + 1), 1, TILE_WIDTH, (TILE_WIDTH - 1), -1, (-TILE_WIDTH - 1), -TILE_WIDTH, (-2 * TILE_WIDTH + 1)
; advance to next row ; advance to next row
ld hl, Progress ld hl, Progress
@@ -235,19 +242,19 @@ UpdateAutomata:
; handle bottom left element ; handle bottom left element
.bottomleft .bottomleft
ConwayGroup 1, -339, -340, -321, 19, -1, -20, -19 ConwayGroup 1, (-BUFFER_SIZE + TILE_WIDTH + 1), (-BUFFER_SIZE + TILE_WIDTH), (-BUFFER_SIZE + 2 * TILE_WIDTH - 1), (TILE_WIDTH - 1), -1, (-TILE_WIDTH), (-TILE_WIDTH + 1)
; advance to next cell in bottom row ; advance to next cell in bottom row
ld hl, Progress ld hl, Progress
inc [hl] inc [hl]
; handle all cells in bottom row except corners ; handle all cells in bottom row except corners
ld a, 18 ld a, TILE_WIDTH - 2
.bottom .bottom
ld [XLoop], a ld [XLoop], a
; handle top row cell ; handle top row cell
ConwayGroup 1, -339, -340, -341, -1, -21, -20, -19 ConwayGroup 1, (-BUFFER_SIZE + TILE_WIDTH + 1), (-BUFFER_SIZE + TILE_WIDTH), (-BUFFER_SIZE + TILE_WIDTH - 1), -1, (-TILE_WIDTH - 1), (-TILE_WIDTH), (-TILE_WIDTH + 1)
; advance to next cell in top row ; advance to next cell in top row
ld hl, Progress ld hl, Progress
@@ -260,7 +267,7 @@ UpdateAutomata:
; handle last element ; handle last element
.bottomright .bottomright
ConwayGroup -19, -359, -340, -341, -1, -21, -20, -39 ConwayGroup (-TILE_WIDTH + 1), (-BUFFER_SIZE + 1), (-BUFFER_SIZE + TILE_WIDTH), (-BUFFER_SIZE + TILE_WIDTH - 1), -1, (-TILE_WIDTH - 1), (-TILE_WIDTH), (-2 * TILE_WIDTH + 1)
; move buffer address back to beginning ; move buffer address back to beginning
ld hl, Old ld hl, Old
@@ -306,4 +313,4 @@ InitAutomata:
ldh [Rendered], a ldh [Rendered], a
ldh [Video], a ldh [Video], a
ret ret