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
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], 0xff ; plot a pixel there
149 ; blur the screen upwards
151 mov ds, ax ; let's use ds for this to avoid long instructions
152 xor bx, bx ; use: pointer
153 xor ax, ax ; use: pixel accum
154 xor dx, dx ; use: second pixel
166 ; wait until the start of vblank
197 ; decode RLE from ds:si to es:di, cx: number of decoded bytes (0 means 65536)
198 ; - high bit set for the repetition count, followed by a value byte to
199 ; be repeated N times
200 ; - high bit not set for raw data that should be copied directly
204 mov bl, 1 ; default to "copy once" for raw values
205 test al, 0x80 ; test the high bit to see if it's a count or a raw value
207 ; it's a count, clear the high bit, and read the next byte for the value
212 .copy: mov [es:di], al
214 dec cx ; decrement decoded bytes counter
215 jz .end ; as soon as it reaches 0, bail
238 randmul dd 1103515245
246 imgrle: incbin "nuclear.rle"
249 pal: incbin "fire.pal"