]>
wirehaze git hosting - lifeboot.git/blob - lifeboot.asm
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
38 ; setup -----------------------------------------------------------------------
44 int 0x1a ; system time
45 mov [XSS
], dx ; cx:dx = number of clock ticks since midnight
48 mov di, GRID
; es:di -> GRID
49 mov cx, COLS
* ROWS
; for each cell
52 call xs
; [XSS] = rand
53 mov al, DEAD
; al = DEAD (likely)
57 jnz .initgrid_nz
; if ([XSS] % 4 == 0)
58 mov al, ALIVE
; al = ALIVE
61 stosb ; [es:(di++)] = al
63 loop .initgrid
; } while (--cx)
69 ; functions -------------------------------------------------------------------
71 ; xs() - xorshift pseudorandom number generator -------------------------------
74 ; [XSS] = updated state
83 shl dx, 1 ; dx = xss << 1
84 xor bx, dx ; bx = xss ^ (xss << 1)
87 shr dx, 3 ; dx = xss' >> 3
88 xor bx, dx ; bx = xss' ^ (xss' >> 3)
91 shl dx, 10 ; dx = xss'' << 10
92 xor bx, dx ; bx = xss'' ^ (xss'' << 10)
97 ; print_grid() - print GRID cells to screen -----------------------------------
99 ; (*) this function expects ds = 0 when called and sets es = 0 before
100 ; returning. this is simpler because in the rest of the program we want the
101 ; segment registers to be zeroed anyway.
103 ; clobbers ax, cx, di, si
110 mov es, ax ; es:di -> VGA
111 mov si, GRID
; ds:si -> GRID
113 mov ah, PRINT_COLOR
; ah = color attribute
115 mov cx, COLS
* ROWS
; for each cell
119 lodsb ; al = [ds:(si++)]
120 stosw ; [es:di] = ax ; di += 2
122 loop .print_cell
; } while (--cx)
127 ; halt() - stop program execution ---------------------------------------------
131 cli ; disable interrupts
135 ; -----------------------------------------------------------------------------
137 times 510 - ($ - $$) db 0 ; fill remaining bytes with zeroes
138 dw 0xaa55 ; mbr magic byte