]>
wirehaze git hosting - lifeboot.git/blob - lifeboot.asm
f1545209a35feff333e53ab7ab1eadf0af8b45bf
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
13 %
define WAIT_DELAY
0x02 ; 0.131072 seconds
15 %
define GRID
ORG + 512 ; current cell grid (80 * 25 bytes)
16 %
define NEXT_GRID GRID
+ COLS
* ROWS
; next cell grid (80 * 25 bytes)
17 %
define XSS NEXT_GRID
+ COLS
* ROWS
; xs() state
19 ; entry point -----------------------------------------------------------------
21 ; 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 -----------------------------------------------------------------------
53 ; functions -------------------------------------------------------------------
55 ; delay() - suspend program execution temporarily -----------------------------
61 mov cx, WAIT_DELAY
; cx:dx = interval in microseconds
69 ; xs() - xorshift pseudorandom number generator -------------------------------
72 ; [XSS] = updated state
81 shl dx, 1 ; dx = xss << 1
82 xor bx, dx ; bx = xss ^ (xss << 1)
85 shr dx, 3 ; dx = xss' >> 3
86 xor bx, dx ; bx = xss' ^ (xss' >> 3)
89 shl dx, 10 ; dx = xss'' << 10
90 xor bx, dx ; bx = xss'' ^ (xss'' << 10)
95 ; init_grid() - initialize GRID cells with random values ----------------------
99 ; clobbers al, bx, cx, dx, di
103 mov di, GRID
; es:di -> GRID
104 mov cx, COLS
* ROWS
; for each cell
107 call xs
; [XSS] = rand
108 mov al, DEAD
; al = DEAD (likely)
110 test word [XSS
], 0b11
112 jnz .nz
; if ([XSS] % 4 == 0)
113 mov al, ALIVE
; al = ALIVE
116 stosb ; [es:(di++)] = al
118 loop .write_cell
; } while (--cx)
122 ; print_grid() - print GRID cells to screen -----------------------------------
124 ; (*) this function expects ds = 0 when called and sets es = 0 before
125 ; returning. this is simpler because in the rest of the program we want the
126 ; segment registers to be zeroed anyway.
128 ; clobbers ax, cx, di, si
132 les di, [farptr
.vga_start
] ; es:di -> VGA
133 mov si, GRID
; ds:si -> GRID
135 mov ah, PRINT_COLOR
; ah = color attribute
137 mov cx, COLS
* ROWS
; for each cell
141 lodsb ; al = [ds:(si++)]
142 stosw ; [es:di] = ax ; di += 2
144 loop .print_cell
; } while (--cx)
149 ; halt() - stop program execution ---------------------------------------------
153 cli ; disable interrupts
157 ; data ------------------------------------------------------------------------
159 farptr: ; offset, segment
161 dw 0 ; take advantage of next dw 0
166 times 510 - ($ - $$) db 0 ; fill remaining bytes with zeroes
167 dw 0xaa55 ; mbr magic byte