From 78432f66d90a3893550b15f7dfce6997adaa3e9b Mon Sep 17 00:00:00 2001 From: MsK` Date: Mon, 29 Nov 2021 16:56:41 +0100 Subject: [PATCH] added constants to automata code, more readable --- Code/automata.asm | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/Code/automata.asm b/Code/automata.asm index a71a869..d4071e7 100644 --- a/Code/automata.asm +++ b/Code/automata.asm @@ -1,5 +1,12 @@ 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 ; 2x2 bytes per cell, bit ordering: ; ___ ___ @@ -9,11 +16,11 @@ INCLUDE "hardware.inc" ; bits 4, 5, 6 and 7 are not used EXPORT Buffer0 SECTION "Automata buffer 0", WRAM0, ALIGN[9] -Buffer0: ds 20 * 18 +Buffer0: ds BUFFER_SIZE EXPORT Buffer1 SECTION "Automata buffer 1", WRAM0, ALIGN[9] -Buffer1: ds 20 * 18 +Buffer1: ds BUFFER_SIZE EXPORT New, Old, Progress SECTION "Automata data", HRAM @@ -156,19 +163,19 @@ SECTION "Update Automata", ROM0 UpdateAutomata: .topleft ; 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 ld hl, Progress inc [hl] ; handle all cells in top row except corners - ld a, 18 + ld a, (TILE_WIDTH - 2) .top ld [XLoop], a ; 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 ld hl, Progress @@ -181,18 +188,18 @@ UpdateAutomata: ; handle top right corner .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 ld hl, Progress inc [hl] - ld a, 16 + ld a, (TILE_HEIGHT - 2) .leftcolumn ld [YLoop], a ; 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 ld hl, Progress @@ -203,7 +210,7 @@ UpdateAutomata: ld [XLoop], a ; 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 ld hl, Progress @@ -222,7 +229,7 @@ UpdateAutomata: ; handle last element in row .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 ld hl, Progress @@ -235,19 +242,19 @@ UpdateAutomata: ; handle bottom left element .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 ld hl, Progress inc [hl] ; handle all cells in bottom row except corners - ld a, 18 + ld a, TILE_WIDTH - 2 .bottom ld [XLoop], a ; 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 ld hl, Progress @@ -260,7 +267,7 @@ UpdateAutomata: ; handle last element .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 ld hl, Old @@ -306,4 +313,4 @@ InitAutomata: ldh [Rendered], a ldh [Video], a - ret \ No newline at end of file + ret