]>
wirehaze git hosting - lifeboot.git/blob - lifeboot.asm
8b530f9f378b143a6be628fb119e7692505e95c3
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
33 ; clear screen ----------------------------------------------------------------
45 mov ax, (PRINT_COLOR
<< 8) | DEAD
47 rep stosw ; fill cx words at es:di with ax
49 ; setup -----------------------------------------------------------------------
55 int 0x1a ; system time
56 mov [XSS
], dx ; cx:dx = number of clock ticks since midnight
59 mov cx, COLS
* ROWS
; for each cell
62 mov di, GRID
; es:di -> GRID
65 call xs
; [XSS] = rand
66 mov al, DEAD
; al = DEAD (likely)
70 jnz .initgrid_nz
; if ([XSS] % 4 == 0)
71 mov al, ALIVE
; al = ALIVE
74 stosb ; [es:(di++)] = al
76 loop .initgrid
; } while (--cx)
80 ; functions -------------------------------------------------------------------
82 ; xs() - xorshift pseudorandom number generator -------------------------------
85 ; [XSS] = updated state
94 shl dx, 1 ; dx = xss << 1
95 xor bx, dx ; bx = xss ^ (xss << 1)
98 shr dx, 3 ; dx = xss' >> 3
99 xor bx, dx ; bx = xss' ^ (xss' >> 3)
102 shl dx, 10 ; dx = xss'' << 10
103 xor bx, dx ; bx = xss'' ^ (xss'' << 10)
108 ; errors ----------------------------------------------------------------------
113 ; print the error message string in si and halt
114 ; note: we assume es = VGA_SEG and ds = 0
119 ; es:di = video memory
120 ; ds:si = error message
122 ; ah = color attribute
125 lodsb ; al = [ds:si], si += 1
126 or al, al ; on null terminator,
128 stosw ; [es:di] = ax, di += 2
132 cli ; disable interrupts
136 ; data ------------------------------------------------------------------------
142 times 510 - ($ - $$) db 0 ; fill remaining bytes with zeroes
143 dw 0xaa55 ; mbr magic byte