5 boot_driveno equ 7b00h ; 1 byte
6 stage2_size equ stage2_end - stage2_start
20 mov [boot_driveno], dl
22 ; load the rest of the code at 7e00
26 mov ah, 2 ; read sectors LBA call
27 mov al, (stage2_size + 511) / 512 ; num sectors
28 mov cx, 2 ; ch: cylinder, cl: sector
30 mov dl, [boot_driveno]
32 jnc stage2_start ; loaded successfully, jump to it
34 ; failed to load second sector
41 ; expects string ptr in ax
54 str_load_fail db "Failed to load second stage!",0
55 str_booting db "Booting ...",0
61 ; start of the second stage
76 ; splash screen effect
81 ; setup ramdac colormap
110 ; precalculate spawn points
112 mov ds, ax ; decompressed image -> ds:bx
116 mov es, ax ; spawn_pos table segment -> es:dx
130 ; update num_spawn_pos
133 mov [num_spawn_pos], edx
135 mov ax, framebuf >> 4
136 mov fs, ax ; fs will point to the off-screen framebuffer
140 mov cx, spawn_rate ; spawn 10 points per frame
143 div dword [num_spawn_pos] ; edx <- rand % num_spawn_pos
144 mov bx, [es:edx * 2] ; grab one of the spawn positions
145 mov byte [fs:bx], 1 ; plot a pixel there
149 ; wait until the start of vblank
180 ; decode RLE from ds:si to es:di, cx: number of decoded bytes (0 means 65536)
181 ; - high bit set for the repetition count, followed by a value byte to
182 ; be repeated N times
183 ; - high bit not set for raw data that should be copied directly
187 mov bl, 1 ; default to "copy once" for raw values
188 test al, 0x80 ; test the high bit to see if it's a count or a raw value
190 ; it's a count, clear the high bit, and read the next byte for the value
195 .copy: mov [es:di], al
197 dec cx ; decrement decoded bytes counter
198 jz .end ; as soon as it reaches 0, bail
221 randmul dd 1103515245
229 imgrle: incbin "nuclear.rle"
232 pal: incbin "fire.pal"