+xor bx, dx ; bx = xss'' ^ (xss'' << 10)
+mov [xss], bx
+
+ret
+
+; init_grid() - initialize grid cells randomly --------------------------------
+
+; clobbers ax, bx, cx, dx, di
+
+init_grid:
+
+mov ah, PRINT_COLOR ; ah = color attribute
+mov di, [currvgapg] ; es:di -> grid start
+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:
+ stosw ; [es:di] = ax ; di += 2
+
+ loop .write_cell ; } while (--cx)
+
+ret
+
+; flip_vga_page() - flip active display page ----------------------------------
+
+; clobbers ax, dx
+
+flip_vga_page:
+
+call vsync_wait
+
+xor word [currvgapg], VGAPGSZ ; flip currvgapg
+setnz al ; al = !(currvgapg == 0)
+
+mov ah, 0x05 ; select active display page
+int 0x10 ; video services