wok view BootProg/stuff/boot16.asm @ rev 25454

oldrunner: add apple2 keys mapping
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Sep 22 07:58:57 2022 +0000 (19 months ago)
parents ec9531d04de1
children d4a851cd7f09
line source
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; ;;
3 ;; "BootProg" Loader v 1.5 by Alexey Frunze (c) 2000-2015 ;;
4 ;; 2-clause BSD license. ;;
5 ;; ;;
6 ;; ;;
7 ;; How to Compile: ;;
8 ;; ~~~~~~~~~~~~~~~ ;;
9 ;; nasm boot16.asm -f bin -o boot16.bin ;;
10 ;; ;;
11 ;; ;;
12 ;; Features: ;;
13 ;; ~~~~~~~~~ ;;
14 ;; - FAT12 and FAT16 supported using BIOS int 13h function 42h or 02h. ;;
15 ;; ;;
16 ;; - Loads a 16-bit executable file in the MS-DOS .COM or .EXE format ;;
17 ;; from the root directory of a disk and transfers control to it ;;
18 ;; (the "ProgramName" variable holds the name of the file to be loaded) ;;
19 ;; Its maximum size can be up to 635KB without Extended BIOS Data area. ;;
20 ;; ;;
21 ;; - Prints an error if the file isn't found or couldn't be read ;;
22 ;; ("File not found" or "Read error") ;;
23 ;; and waits for a key to be pressed, then executes the Int 19h ;;
24 ;; instruction and lets the BIOS continue bootstrap. ;;
25 ;; ;;
26 ;; - cpu 8086 is supported ;;
27 ;; ;;
28 ;; ;;
29 ;; Known Bugs: ;;
30 ;; ~~~~~~~~~~~ ;;
31 ;; - All bugs are fixed as far as I know. The boot sector has been tested ;;
32 ;; on the following types of diskettes (FAT12): ;;
33 ;; - 360KB 5"25 ;;
34 ;; - 1.2MB 5"25 ;;
35 ;; - 1.44MB 3"5 ;;
36 ;; on my HDD (FAT16). ;;
37 ;; ;;
38 ;; ;;
39 ;; Memory Layout: ;;
40 ;; ~~~~~~~~~~~~~~ ;;
41 ;; The diagram below shows the typical memory layout. The actual location ;;
42 ;; of the boot sector and its stack may be lower than A0000H if the BIOS ;;
43 ;; reserves memory for its Extended BIOS Data Area just below A0000H and ;;
44 ;; reports less than 640 KB of RAM via its Int 12H function. ;;
45 ;; ;;
46 ;; physical address ;;
47 ;; +------------------------+ 00000H ;;
48 ;; | Interrupt Vector Table | ;;
49 ;; +------------------------+ 00400H ;;
50 ;; | BIOS Data Area | ;;
51 ;; +------------------------+ 00500H ;;
52 ;; | PrtScr Status / Unused | ;;
53 ;; +------------------------+ 00600H ;;
54 ;; | Loaded Image | ;;
55 ;; +------------------------+ nnnnnH ;;
56 ;; | Available Memory | ;;
57 ;; +------------------------+ A0000H - 512 - 3KB ;;
58 ;; | Boot Sector | ;;
59 ;; +------------------------+ A0000H - 3KB ;;
60 ;; | 3KB Boot Stack | ;;
61 ;; +------------------------+ A0000H ;;
62 ;; | Video RAM | ;;
63 ;; ;;
64 ;; ;;
65 ;; Boot Image Startup (register values): ;;
66 ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;;
67 ;; ax = 0ffffh (both FCB in the PSP don't have a valid drive identifier), ;;
68 ;; bx = 0, dl = BIOS boot drive number (e.g. 0, 80H) ;;
69 ;; cs:ip = program entry point ;;
70 ;; ss:sp = program stack (don't confuse with boot sector's stack) ;;
71 ;; COM program defaults: cs = ds = es = ss = 50h, sp = 0, ip = 100h ;;
72 ;; EXE program defaults: ds = es = EXE data - 10h (fake MS-DOS psp), ;;
73 ;; cs:ip and ss:sp depends on EXE header ;;
74 ;; Magic numbers: ;;
75 ;; si = 16381 (prime number 2**14-3) ;;
76 ;; di = 32749 (prime number 2**15-19) ;;
77 ;; bp = 65521 (prime number 2**16-15) ;;
78 ;; The magic numbers let the program know whether it has been loaded by ;;
79 ;; this boot sector or by MS-DOS, which may be handy for universal, bare- ;;
80 ;; metal and MS-DOS programs. ;;
81 ;; The command line contains no arguments. ;;
82 ;; ;;
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85 %define bx(label) bx+label-boot
86 %define si(label) si+label-boot
87 NullEntryCheck equ 1 ; +3 bytes
88 ReadRetry equ 1 ; +9 bytes
89 LBAsupport equ 1 ; +16 bytes
90 Over2GB equ 1 ; +5 bytes
91 GeometryCheck equ 1 ; +18 bytes
93 [BITS 16]
94 [CPU 8086]
96 ImageLoadSeg equ 60h
97 StackSize equ 3072 ; Stack + cluster list
99 [SECTION .text]
100 [ORG 0]
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 ;; Boot sector starts here ;;
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106 boot:
107 DriveNumber:
108 jmp short start ; MS-DOS/Windows checks for this jump
109 nop
110 bsOemName DB "BootProg" ; 0x03
112 ;;;;;;;;;;;;;;;;;;;;;
113 ;; BPB starts here ;;
114 ;;;;;;;;;;;;;;;;;;;;;
116 bpbBytesPerSector DW 0 ; 0x0B
117 bpbSectorsPerCluster DB 0 ; 0x0D
118 bpbReservedSectors DW 0 ; 0x0E
119 bpbNumberOfFATs DB 0 ; 0x10
120 bpbRootEntries DW 0 ; 0x11
121 bpbTotalSectors DW 0 ; 0x13
122 bpbMedia DB 0 ; 0x15
123 bpbSectorsPerFAT DW 0 ; 0x16
124 bpbSectorsPerTrack DW 0 ; 0x18
125 bpbHeadsPerCylinder DW 0 ; 0x1A
126 bpbHiddenSectors DD 0 ; 0x1C
127 bpbTotalSectorsBig DD 0 ; 0x20
129 ;;;;;;;;;;;;;;;;;;;
130 ;; BPB ends here ;;
131 ;;;;;;;;;;;;;;;;;;;
133 bsDriveNumber DB 0 ; 0x24
134 bsUnused DB 0 ; 0x25
135 bsExtBootSignature DB 0 ; 0x26
136 bsSerialNumber DD 0 ; 0x27
137 bsVolumeLabel DB "NO NAME " ; 0x2B
138 bsFileSystem DB "FAT12 " ; 0x36
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141 ;; Boot sector code starts here ;;
142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144 start:
145 cld
147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
148 ;; How much RAM is there? ;;
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151 int 12h ; get conventional memory size (in KBs)
152 mov cx, 106h
153 shl ax, cl ; and convert it to 16-byte paragraphs
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
156 ;; Reserve memory for the boot sector and its stack ;;
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 sub ax, (512+StackSize) /16 ; reserve bytes for the code and the stack
160 mov es, ax ; cs:0 = ds:0 = ss:0 -> top - 512 - StackSize
161 mov ss, ax
162 mov sp, 512+StackSize ; bytes 0-511 are reserved for the boot code
164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
165 ;; Copy ourselves to top of memory ;;
166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168 mov si, 7C00h
169 xor di, di
170 mov ds, di
171 push es
172 mov [si(DriveNumber)], dx ; store BIOS boot drive number
173 rep movsw ; move 512 bytes (+ 12)
175 ;;;;;;;;;;;;;;;;;;;;;;
176 ;; Jump to the copy ;;
177 ;;;;;;;;;;;;;;;;;;;;;;
179 mov cl, byte main
180 push cx
181 retf
183 main:
184 %if ImageLoadSeg != main-boot
185 %if ImageLoadSeg >= 100h
186 mov cx, ImageLoadSeg
187 %else
188 mov cl, ImageLoadSeg
189 %endif
190 %endif
191 push cx
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;
194 ;; Get drive parameters ;;
195 ;; Update heads count ;;
196 ;; for current BIOS ;;
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;
199 %if GeometryCheck != 0
200 mov ah, 8
201 int 13h ; may destroy SI,BP, and DS registers
202 %endif
203 ; update AX,BL,CX,DX,DI, and ES registers
204 push cs
205 pop ds
206 xor bx, bx
208 %if GeometryCheck != 0
209 and cx, byte 3Fh
210 cmp [bx(bpbSectorsPerTrack)], cx
211 jne BadParams ; verify updated and validity
212 mov al, dh
213 inc ax
214 mov [bpbHeadsPerCylinder], ax
215 BadParams:
216 %endif
218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
219 ;; Load FAT (FAT12: 6KB max, FAT16: 128KB max) ;;
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
222 pop es ; ImageLoadSeg
223 push es
225 mul bx ; dx:ax = 0 = LBA (LBA are relative to FAT)
226 mov cx, word [bx(bpbSectorsPerFAT)]
228 call ReadCXSectors ; read fat and clear ax & cx; bp = SectorsPerFAT
230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
231 ;; load the root directory in ;;
232 ;; its entirety (16KB max) ;;
233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
235 mov al, 32
237 mul word [bx(bpbRootEntries)]
238 div word [bx(bpbBytesPerSector)]
239 xchg ax, cx ; cx = root directory size in sectors, clear ax
241 mov al, [bpbNumberOfFATs]
242 mul bp ; [bx(bpbSectorsPerFAT)], set by ReadCXSectors
244 push es
245 call ReadCXSectors ; read root directory; clear ax, cx & di; bp = first data sector
246 pop es
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
249 ;; Look for the COM/EXE file to load and run ;;
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
252 ; es:di -> root entries array
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
255 ;; Looks for the file/dir ProgramName ;;
256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257 ;; Input: ES:DI -> root directory array ;;
258 ;; Output: SI = cluster number ;;
259 ;; AX = file sector count ;;
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262 FindNameCycle:
263 push di
264 mov cl, NameLength
265 mov si, ProgramName ; ds:si -> program name
266 repe cmpsb
267 pop di
268 je FindNameFound
269 %if NullEntryCheck != 0
270 scasb
271 je FindNameFailed ; end of root directory (NULL entry found)
272 add di, byte 31
273 %else
274 add di, byte 32
275 %endif
276 dec word [bx(bpbRootEntries)]
277 jnz FindNameCycle ; next root entry
279 FindNameFailed:
280 call Error
281 db "File not found."
283 FindNameFound:
284 push si
285 mov si, [es:di+1Ah] ; si = cluster no.
286 les ax, [es:di+1Ch] ; file size
287 mov dx, es
288 div word [bx(bpbBytesPerSector)]
289 cmp bx, dx ; sector aligned ?
290 adc ax, bx ; file last sector
291 pop di ; di = ClusterList
293 pop es ; ImageLoadSeg
294 push ax
296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
297 ;; build cluster list ;;
298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
299 ;; Input: ES:0 -> FAT ;;
300 ;; SI = first cluster ;;
301 ;; DI = cluster list :;
302 ;; CH = 0 ;;
303 ;; Output: SI = cluster list ;;
304 ;; CH = 0 ;;
305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
307 FAT12 equ 1
308 FAT16 equ 1
309 TINYFAT16 equ 1
310 push di ; up to 2 * 635K / BytesPerCluster = 2540 bytes
311 %if FAT12 == 1
312 %if TINYFAT16 == 0 && FAT16 == 1
313 mov cl, 12
314 %else
315 mov cl, 4
316 %endif
317 %endif
318 ClusterLoop:
319 mov [di], si
320 add si, si ; si = cluster * 2
321 %if FAT16 == 1
322 mov ax, es ; ax = FAT segment = ImageLoadSeg
323 jnc First64k
324 mov ah, (1000h+ImageLoadSeg)>>8 ; adjust segment for 2nd part of FAT16
325 First64k:
326 %if FAT12 == 1
327 mov dx, 0FFF8h
328 %if TINYFAT16 == 1
329 test [bx(bsFileSystem+4)], cl ; FAT12 or FAT16 ? clear C
330 %else
331 cmp [bx(bpbSectorsPerFAT)], cx ; 1..12 = FAT12, 16..256 = FAT16
332 %endif
333 jne ReadClusterFat16
334 mov dh, 0Fh
335 %endif
336 %endif
337 %if FAT12 == 1
338 add si, [di]
339 shr si, 1 ; si = cluster * 3 / 2
340 %endif
341 %if FAT16 == 1
342 ReadClusterFat16:
343 push ds
344 mov ds, ax
345 lodsw ; ax = next cluster
346 pop ds
347 %else
348 es lodsw
349 %endif
350 %if FAT12 == 1
351 jnc ReadClusterEven
352 %if TINYFAT16 == 0 && FAT16 == 1
353 rol ax, cl
354 %else
355 shr ax, cl
356 %endif
357 ReadClusterEven:
358 scasw ; di += 2
359 %if FAT16 == 1
360 and ah, dh ; mask cluster value
361 cmp ax, dx
362 %else
363 and ah, 0Fh ; mask cluster value
364 cmp ax, 0FF8h
365 %endif
366 %else
367 scasw ; di += 2
368 cmp ax, 0FFF8h
369 %endif
370 xchg ax, si
371 jc ClusterLoop
372 pop si
373 pop di ; file size in sectors
375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376 ;; Load the entire file ;;
377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
378 ;; Input: ES:0 -> buffer ;;
379 ;; SI = cluster list ;;
380 ;; DI = file sectors ;;
381 ;; CH = 0 ;;
382 ;; BP = 1st data sec ;;
383 ;; Output: BP:0 -> buffer ;;
384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
386 push es
388 ReadClusters:
389 lodsw
390 dec ax
391 dec ax
393 mov cl, [bx(bpbSectorsPerCluster)] ; 1..128
394 mul cx ; cx = sector count (ch = 0)
396 add ax, bp ; LBA for cluster data
397 adc dx, bx ; dx:ax = LBA
399 call ReadSector ; clear ax, restore dx
401 jne ReadClusters
403 pop bp ; ImageLoadSeg
405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
406 ;; Type detection, .COM or .EXE? ;;
407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 mov ds, bp ; bp=ds=seg the file is loaded to
411 add bp, [bx+08h] ; bp = image base
412 mov di, [bx+18h] ; di = reloc table pointer
414 cmp word [bx], 5A4Dh ; "MZ" signature?
415 je RelocateEXE ; yes, it's an EXE program
417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
418 ;; Setup and run a .COM program ;;
419 ;; Set CS=DS=ES=SS SP=0 IP=100h ;;
420 ;; AX=0ffffh BX=0 DX=drive and ;;
421 ;; cmdline=void ;;
422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
424 mov di, 100h ; ip
425 mov bp, ImageLoadSeg-10h ; "org 100h" stuff :)
426 mov ss, bp
427 xor sp, sp
428 push bp ; cs, ds and es
429 jmp short Run
431 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
432 ;; Relocate, setup and run a .EXE program ;;
433 ;; Set CS:IP, SS:SP, DS, ES and AX according ;;
434 ;; to wiki.osdev.org/MZ#Initial_Program_State ;;
435 ;; AX=0ffffh BX=0 DX=drive cmdline=void ;;
436 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
438 ReloCycle:
439 add [di+2], bp ; item seg (abs)
440 les si, [di] ; si = item ofs, es = item seg
441 add [es:si], bp ; fixup
442 scasw ; di += 2
443 scasw ; point to next entry
445 RelocateEXE:
446 dec word [bx+06h] ; reloc items, 32768 max (128KB table)
447 jns ReloCycle
448 ; PSP don't have a valid drive identifier
449 les si, [bx+0Eh]
450 add si, bp
451 mov ss, si ; ss for EXE
452 mov sp, es ; sp for EXE
454 lea si, [bp-10h] ; ds and es both point to the segment
455 push si ; containing the PSP structure
457 add bp, [bx+16h] ; cs for EXE
458 mov di, [bx+14h] ; ip for EXE
459 Run:
460 pop ds
461 push bp
462 push di
463 push ds
464 pop es
465 mov [80h], ax ; clear cmdline
466 dec ax ; both FCB in the PSP don't have a valid drive identifier
468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
469 ;; Set the magic numbers so the program knows that it ;;
470 ;; has been loaded by this bootsector and not by MS-DOS ;;
471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
472 mov si, 16381 ; prime number 2**14-3
473 mov di, 32749 ; prime number 2**15-19
474 mov bp, 65521 ; prime number 2**16-15
476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
477 ;; All done, transfer control to the program now ;;
478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
479 retf
481 ReadCXSectors:
482 mov bp, cx
483 add bp, ax ; adjust LBA for cluster data
485 mov di, cx ; no file size limit
487 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
488 ;; Reads sectors using BIOS Int 13h ;;
489 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
490 ;; Input: DX:AX = LBA relative to FAT ;;
491 ;; BX = 0 ;;
492 ;; CX = sector count ;;
493 ;; DI = file sectors ;;
494 ;; ES:BX -> buffer address ;;
495 ;; Output: ES:BX -> next address ;;
496 ;; BX = 0 ;;
497 ;; CX or DI = 0 ;;
498 ;; DL = drive number ;;
499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
501 ReadSector:
502 add ax, [bx(bpbHiddenSectors)]
503 adc dx, [bx(bpbHiddenSectors)+2]
504 add ax, [bx(bpbReservedSectors)]
506 push si
507 ReadSectorNext:
508 adc dx, bx
509 push di
510 push cx
512 %if LBAsupport != 0
513 push bx
514 push bx
515 %endif
516 push dx ; 32-bit LBA: up to 2TB
517 push ax
518 push es
519 %if ReadRetry != 0 || LBAsupport != 0
520 mov di, 16 ; packet size byte = 16, reserved byte = 0
521 %endif
522 %if LBAsupport != 0
523 push bx
524 inc bx ; sector count word = 1
525 push bx
526 dec bx
527 push di
528 %endif
530 %if Over2GB != 0
531 xchg ax, cx ; save low LBA
532 xchg ax, dx ; get high LBA
533 cwd ; clear dx (LBA offset <1TB)
534 idiv word [bx(bpbSectorsPerTrack)] ; up to 8GB disks
536 xchg ax, cx ; restore low LBA, save high LBA / SPT
537 %else
538 xor cx, cx ; up to 2GB disks otherwise divide error interrupt !
539 %endif
540 idiv word [bx(bpbSectorsPerTrack)]
541 ; ax = LBA / SPT
542 ; dx = LBA % SPT = sector - 1
543 inc dx
545 xchg cx, dx ; restore high LBA / SPT, save sector no.
546 idiv word [bx(bpbHeadsPerCylinder)]
547 ; ax = (LBA / SPT) / HPC = cylinder
548 ; dx = (LBA / SPT) % HPC = head
549 mov ch, al
550 ; ch = LSB 0...7 of cylinder no.
551 mov al, 64
552 mul ah
553 or cl, al
554 ; cl = MSB 8...9 of cylinder no. + sector no.
555 mov dh, dl
556 ; dh = head no.
558 ReadSectorRetry:
559 mov dl, [bx(DriveNumber)]
560 ; dl = drive no.
561 mov si, sp
562 %if LBAsupport != 0
563 mov ah, 42h ; ah = 42h = extended read function no.
564 int 13h ; extended read sectors (DL, DS:SI)
565 jnc ReadSectorNextSegment
566 %endif
568 mov ax, 201h ; al = sector count = 1
569 ; ah = 2 = read function no.
570 int 13h ; read sectors (AL, CX, DX, ES:BX)
572 jnc ReadSectorNextSegment
573 %if ReadRetry != 0
574 cbw ; ah = 0 = reset function
575 int 13h ; reset drive (DL)
577 dec di
578 jnz ReadSectorRetry ; extra attempt
579 %endif
581 call Error
582 db "Read error."
584 ReadSectorNextSegment:
586 %if LBAsupport != 0
587 pop ax ; al = 16
588 mul byte [bx(bpbBytesPerSector)+1] ; = (bpbBytesPerSector/256)*16
589 pop cx ; sector count = 1
590 pop bx
591 add [si+6], ax ; adjust segment for next sector
592 %else
593 mov al, 16
594 mul byte [bx(bpbBytesPerSector)+1] ; = (bpbBytesPerSector/256)*16
595 add [si], ax ; adjust segment for next sector
596 %endif
597 pop es ; es:0 updated
598 pop ax
599 pop dx
600 %if LBAsupport != 0
601 pop di
602 pop di
603 add ax, cx ; adjust LBA for next sector
604 %else
605 add ax, 1 ; adjust LBA for next sector
606 %endif
608 pop cx ; cluster sectors to read
609 pop di ; file sectors to read
610 dec di ; keep C
611 loopne ReadSectorNext ; until cluster sector count or file sector count is reached
612 pop si
613 mov ax, bx ; clear ax
614 mov dx, [bx(DriveNumber)] ; pass the BIOS boot drive to Run or Error
616 ret
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
619 ;; Fill free space with zeroes ;;
620 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
622 times (512-13-20-($-$$)) db 0
624 ;;;;;;;;;;;;;;;;;;;;;;;;;;
625 ;; Error Messaging Code ;;
626 ;;;;;;;;;;;;;;;;;;;;;;;;;;
628 Error:
629 pop si
631 PutStr:
632 mov ah, 0Eh
633 mov bl, 7
634 lodsb
635 int 10h
636 cmp al, "."
637 jne PutStr
639 cbw
640 int 16h ; wait for a key...
641 int 19h ; bootstrap
643 Stop:
644 hlt
645 jmp short Stop
647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
648 ;; Name of the file to load and run ;;
649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
651 ProgramName db "STARTUP BIN" ; name and extension each must be
652 times (510-($-$$)) db ' ' ; padded with spaces (11 bytes total)
653 NameLength equ $-ProgramName
655 ;;;;;;;;;;;;;;;;;;;;;;;;;;
656 ;; End of the sector ID ;;
657 ;;;;;;;;;;;;;;;;;;;;;;;;;;
659 ClusterList dw 0AA55h ; BIOS checks for this ID