]>
wirehaze git hosting - lifeboot.git/blob - lifeboot.asm
f438c6069c9c25b110a8f2dc2f4b660c15dec224
10 %
define DEAD
' ' ; char to represent a dead cell
11 %
define ALIVE
'#' ; char to represent an alive cell
12 %
define PRINT_COLOR
0x07 ; grey on black
14 %
define GRID
ORG + 512 ; current cell grid (80 * 25 bytes)
15 %
define NEXT_GRID GRID
+ COLS
* ROWS
; next cell grid (80 * 25 bytes)
16 %
define XSS NEXT_GRID
+ COLS
* ROWS
; xs() state
18 ; entry point -----------------------------------------------------------------
20 ; initialize segment registers
30 ; clear direction flag
40 int 0x1a ; system time
41 mov [XSS
], dx ; cx:dx = number of clock ticks since midnight
43 ; setup -----------------------------------------------------------------------
52 ; functions -------------------------------------------------------------------
54 ; xs() - xorshift pseudorandom number generator -------------------------------
57 ; [XSS] = updated state
66 shl dx, 1 ; dx = xss << 1
67 xor bx, dx ; bx = xss ^ (xss << 1)
70 shr dx, 3 ; dx = xss' >> 3
71 xor bx, dx ; bx = xss' ^ (xss' >> 3)
74 shl dx, 10 ; dx = xss'' << 10
75 xor bx, dx ; bx = xss'' ^ (xss'' << 10)
80 ; init_grid() - initialize GRID cells with random values ----------------------
84 ; clobbers ax, bx, cx, dx, di
88 mov di, GRID
; es:di -> GRID
89 mov cx, COLS
* ROWS
; for each cell
92 call xs
; [XSS] = rand
93 mov al, DEAD
; al = DEAD (likely)
97 jnz .nz
; if ([XSS] % 4 == 0)
98 mov al, ALIVE
; al = ALIVE
101 stosb ; [es:(di++)] = al
103 loop .write_cell
; } while (--cx)
107 ; print_grid() - print GRID cells to screen -----------------------------------
109 ; (*) this function expects ds = 0 when called and sets es = 0 before
110 ; returning. this is simpler because in the rest of the program we want the
111 ; segment registers to be zeroed anyway.
113 ; clobbers ax, cx, di, si
120 mov es, ax ; es:di -> VGA
121 mov si, GRID
; ds:si -> GRID
123 mov ah, PRINT_COLOR
; ah = color attribute
125 mov cx, COLS
* ROWS
; for each cell
129 lodsb ; al = [ds:(si++)]
130 stosw ; [es:di] = ax ; di += 2
132 loop .print_cell
; } while (--cx)
137 ; halt() - stop program execution ---------------------------------------------
141 cli ; disable interrupts
145 ; -----------------------------------------------------------------------------
147 times 510 - ($ - $$) db 0 ; fill remaining bytes with zeroes
148 dw 0xaa55 ; mbr magic byte