]>
wirehaze git hosting - lifeboot.git/blob - lifeboot.asm
0e114d0a7a93aebfb29ace065599d1129d3fd84e
4 ; =============================================================================
6 ; settings --------------------------------------------------------------------
8 %
define DEAD
' ' ; char to represent a dead cell
9 %
define ALIVE
'#' ; char to represent an alive cell
10 %
define PRINT_COLOR
0x07 ; grey on black
11 %
define WAIT_DELAY
0x02 ; 0.131072 seconds
13 ; constants -------------------------------------------------------------------
17 %
define VGAPGSZ
(COLS
* ROWS
* 2)
19 ; memory layout ---------------------------------------------------------------
25 ; static variables ------------------------------------------------------------
27 %
define xss DAT
; xs() state (word)
28 %
define currvgapg DAT
+ 2 ; current vga page near pointer (word)
30 ; =============================================================================
32 ; entry point -----------------------------------------------------------------
34 ; initialize segment registers
46 ; clear direction flag
50 mov ch, 0x3f ; cursor start and options
51 mov ah, 0x01 ; set text-mode cursor shape
52 int 0x10 ; video services
56 int 0x1a ; system time
57 mov [xss
], dx ; cx:dx = number of clock ticks since midnight
59 ; initialize currvgapg
60 mov word [currvgapg
], VGAPGSZ
62 ; setup -----------------------------------------------------------------------
72 ; =============================================================================
74 ; functions -------------------------------------------------------------------
76 ; delay() - suspend program execution temporarily -----------------------------
82 mov cx, WAIT_DELAY
; cx:dx = interval in microseconds
90 ; vsync_wait() - wait for display to enter the next VBlank cycle --------------
96 mov dx, 0x3da ; input status #1 register
100 test al, 0x08 ; vertical retrace bit
110 ; xs() - xorshift pseudorandom number generator -------------------------------
113 ; [xss] = updated state
122 shl dx, 1 ; dx = xss << 1
123 xor bx, dx ; bx = xss ^ (xss << 1)
126 shr dx, 3 ; dx = xss' >> 3
127 xor bx, dx ; bx = xss' ^ (xss' >> 3)
130 shl dx, 10 ; dx = xss'' << 10
131 xor bx, dx ; bx = xss'' ^ (xss'' << 10)
136 ; init_grid() - initialize grid cells randomly --------------------------------
138 ; clobbers ax, bx, cx, dx, di
142 mov ah, PRINT_COLOR
; ah = color attribute
143 mov di, [currvgapg
] ; es:di -> grid start
144 mov cx, COLS
* ROWS
; for each cell
147 call xs
; [xss] = rand
148 mov al, DEAD
; al = DEAD (likely)
150 test word [xss
], 0b11
152 jnz .nz
; if ([xss] % 4 == 0)
153 mov al, ALIVE
; al = ALIVE
156 stosw ; [es:di] = ax ; di += 2
158 loop .write_cell
; } while (--cx)
162 ; flip_vga_page() - flip active display page ----------------------------------
170 xor word [currvgapg
], VGAPGSZ
; flip currvgapg
171 setnz al ; al = !(currvgapg == 0)
173 mov ah, 0x05 ; select active display page
174 int 0x10 ; video services
178 ; halt() - stop program execution ---------------------------------------------
182 cli ; disable interrupts
186 ; =============================================================================
188 times 510 - ($ - $$) db 0 ; fill remaining bytes with zeroes
189 dw 0xaa55 ; mbr magic byte