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
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 word [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