]> wirehaze git hosting - lifeboot.git/commitdiff

wirehaze git hosting

modularize init_grid
authorphfr24 <phfr24@inf.ufpr.br>
Tue, 18 Nov 2025 01:09:40 +0000 (22:09 -0300)
committerphfr24 <phfr24@inf.ufpr.br>
Tue, 18 Nov 2025 01:09:40 +0000 (22:09 -0300)
lifeboot.asm

index 07d9c5a56e900f5b895e521b4e3a763bb6b782ae..278bf328a456e12193f8622867feb640975b5ab5 100644 (file)
@@ -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