7 boot_driveno equ 7b00h ; 1 byte
8 stage2_size equ stage2_end - stage2_start
13 %macro floppy_motor_off 0
16 jnz %%end ; skip if high bit is set (i.e. it's not a floppy)
33 mov [boot_driveno], dl
35 ; load the rest of the code at 7e00
39 mov ah, 2 ; read sectors call
40 mov al, (stage2_size + 511) / 512 ; num sectors
41 mov cx, 2 ; ch: cylinder, cl: sector
43 mov dl, [boot_driveno]
45 floppy_motor_off ; turn off floppy motor (if dl is < 80h)
46 jnc stage2_start ; loaded successfully, jump to it
48 ; failed to load second sector
55 ; expects string ptr in ax
68 str_load_fail db "Failed to load second stage!",0
69 str_booting db "Booting system... ",0
70 str_bootfail db "failed!",0
76 ; start of the second stage
90 ; blank out the existing boot signature to really see if a boot sector
91 ; gets loaded correctly
95 ; load from BOOT_DEV into 7c00h and jump
97 mov ax, 0201h ; ah: call 2 (read sectors), al: count = 1
98 mov cx, 1 ; ch: cylinder 0, cl: sector 1
99 mov dx, BOOT_DEV ; dh: head 0, dl: boot device number
101 floppy_motor_off ; turn floppy motor off (if dl < 80h)
103 jc .fail ; BIOS will set the carry flag on failure
106 jnz .fail ; fail if what we loaded is not a valid boot sect
114 jmp 7c00h ; all checks passed, jump there
116 .fail: mov ax, str_bootfail
123 ; splash screen effect
128 ; setup ramdac colormap
142 cmp bx, 768 ; 256 * 3
157 ; precalculate spawn points
159 mov ds, ax ; decompressed image -> ds:bx
163 mov es, ax ; spawn_pos table segment -> es:dx
177 ; update num_spawn_pos
180 mov [num_spawn_pos], edx
182 mov ax, framebuf >> 4
183 mov fs, ax ; fs will point to the off-screen framebuffer
190 div dword [num_spawn_pos] ; edx <- rand % num_spawn_pos
191 mov bx, [es:edx * 2] ; grab one of the spawn positions
193 ; animate the spawn position
197 movsx ax, byte [bp + sintab]
201 mov byte [fs:bx], 0xff ; plot a pixel there
205 ; blur the screen upwards
207 mov ds, ax ; let's use ds for this to avoid long instructions
208 xor bx, bx ; use: pointer
209 xor ax, ax ; use: pixel accum
210 xor dx, dx ; use: second pixel
232 ; wait until the start of vblank
265 ; decode RLE from ds:si to es:di, cx: number of decoded bytes (0 means 65536)
266 ; - high bit set for the repetition count, followed by a value byte to
267 ; be repeated N times
268 ; - high bit not set for raw data that should be copied directly
272 mov bl, 1 ; default to "copy once" for raw values
273 test al, 0x80 ; test the high bit to see if it's a count or a raw value
275 ; it's a count, clear the high bit, and read the next byte for the value
280 .copy: mov [es:di], al
282 dec cx ; decrement decoded bytes counter
283 jz .end ; as soon as it reaches 0, bail
306 randmul dd 1103515245
317 imgrle: incbin "nuclear.rle"
320 pal: incbin "fire.pal"