From: phfr24 Date: Tue, 18 Nov 2025 01:09:40 +0000 (-0300) Subject: modularize init_grid X-Git-Url: https://git.wirehaze.ovh/lifeboot.git/commitdiff_plain/77ca36691072482fee62722117cd364912f2ffbf?ds=inline modularize init_grid --- diff --git a/lifeboot.asm b/lifeboot.asm index 07d9c5a..278bf32 100644 --- a/lifeboot.asm +++ b/lifeboot.asm @@ -35,33 +35,16 @@ mov ch, 0x3f mov ah, 0x01 int 0x10 -; setup ----------------------------------------------------------------------- - -setup: - ; initialize xss mov ah, 0x00 ; get int 0x1a ; system time mov [XSS], dx ; cx:dx = number of clock ticks since midnight -; initialize grid -mov di, GRID ; es:di -> GRID -mov cx, COLS * ROWS ; for each cell - -.initgrid: ; do { - call xs ; [XSS] = rand - mov al, DEAD ; al = DEAD (likely) - - test [XSS], 0b11 - - jnz .initgrid_nz ; if ([XSS] % 4 == 0) - mov al, ALIVE ; al = ALIVE - -.initgrid_nz: - stosb ; [es:(di++)] = al +; setup ----------------------------------------------------------------------- - loop .initgrid ; } while (--cx) +setup: +call init_grid call print_grid jmp halt @@ -94,6 +77,33 @@ mov [XSS], bx ret +; init_grid() - initialize GRID cells with random values ---------------------- + +; (*) expects es = 0. + +; clobbers ax, bx, cx, dx, di + +init_grid: + +mov di, GRID ; es:di -> GRID +mov cx, COLS * ROWS ; for each cell + +.write_cell: ; do { + call xs ; [XSS] = rand + mov al, DEAD ; al = DEAD (likely) + + test [XSS], 0b11 + + jnz .nz ; if ([XSS] % 4 == 0) + mov al, ALIVE ; al = ALIVE + +.nz: + stosb ; [es:(di++)] = al + + loop .write_cell ; } while (--cx) + +ret + ; print_grid() - print GRID cells to screen ----------------------------------- ; (*) this function expects ds = 0 when called and sets es = 0 before