; Boot sector for PC-DOS version 1.00. Revised 05-7-81. ORG 7C00H JP INIT ; ; Length of BIOS and DOS in sectors ; SYSLEN: DW 20 ; ; Address of BIOS ; BIOSADR: DW 00H BIOSSEG: DW 60H ; ; Boot sector revision ; DB " 7-May-81" DS 32 ; ; Init boot loader ; INIT: ;Setup temp stack CLI ;Disable interrupts MOV AX,CS MOV DS,AX ;DS = CS MOV DX,0 MOV SS,DX ;SS = 0 MOV SP,7C00H ;SP = 7C00H STI ;Enable interrupts ;Setup segment registers MOV AX,[BIOSSEG] MOV DS,AX ;DS = BIOSSEG MOV ES,AX ;ES = BIOSSEG MOV DX,0 ;Drive 0 MOV AX,DX ;Function = reset disk system INT 13H ;Call disk BIOS service JC DSKERR CHKSYSLOOP: ;Wait until a system disk is inserted CALL CHECKSYS JC CHKSYSLOOP ;Load the first sector of the BIOS SEG CS MOV CX,[SYSLEN] ;Sectors to load PUSH CX ;Save it MOV BX,0 ;ES:BX = BIOSSEG:0000 XOR DX,DX ;Drive 0, head 0 MOV CX,8 ;Track 0, sector 8 MOV SI,1 ;1 sector will be read the first time PUSH SI ;Save it MOV AL,1 ;Read 1 sector READ: ;Reads some sectors to memory MOV AH,2 ;Function = disk read INT 13H ;Call disk BIOS service JC DSKERR POP SI ;Sectors read POP AX ;Sectors to read CALL INCDSTPTR ;Increment dest pointer SUB AX,SI ;Decrement sectors to read JZ BOOT ;All sectors read, boot it INC CH ;Next track MOV CL,1 ;Back to first sector MOV SI,8 ;8 sectors to read CMP AX,SI ;Compare sectors left with sectors to read JNB MORELEFT ;Sectors left >= sectors to read MOV SI,AX ;Just read the remaining ones JP READAGAIN MORELEFT: ;More sectors left than to read XCHG SI,AX ;Swap them READAGAIN: ;Reads the next group of sectors PUSH SI ;Save sectors left PUSH AX ;Save sectors to read JP READ BOOT: ;Finished loading, jump to BIOS SEG CS JMP L,[BIOSADR] ;Long jump to BIOS DSKERR: ;Disk read error, boot to ROM BASIC MOV SI,BOOTERRMSG ;Load boot error message MOV AX,LDBASIC ;Offset of INT 18H PUSH AX ;RET will return to BASIC PRINT: ;Sets page number to 0 before printing XOR BH,BH ;Page 0 PRINTCHR: ;Prints a string LODSB ;Fetch char AND AL,7FH ;Clear MSB, we used to set MSB for last ;char to terminate strings to save space, ;now we have moved to zero-terminated ;strings but we still need to handle MSB- ;terminated strings because ASM still sets ;MSB for strings JZ PRINTDONE PUSH SI ;Save SI MOV AH,0EH ;Function = write char MOV BX,7 ;Light gray and page number = 0 INT 10H ;Call video BIOS service POP SI ;Restore SI JP PRINTCHR PRINTDONE: RET ; ; Checks whether the current disk is a system disk ; CHECKSYS: MOV BX,0 ;ES:BX = BIOSSEG:0000 MOV CX,4 ;Track 0, sector 4 MOV AX,201H ;Function = disk read, sectors = 1 INT 13H ;Call disk BIOS service PUSH DS ;Save DS JC NOSYS ;Read error MOV AX,CS MOV DS,AX ;DS = CS MOV DI,0 ;Point to first char MOV CX,11 ;11 chars to convert to lower TOLOWER: ;Convert filenames to lower case SEG ES OR B,[DI],20H ;Convert entry 1 char to lower case SEG ES OR B,[DI+DOSENT],20H ;Convert entry 2 char to lower case INC DI ;Next char LOOP TOLOWER ;Compare first 2 directory entries MOV DI,0 ;Point to first entry MOV SI,BIOENTRY ;BIOS name MOV CX,11 ;11 chars to compare CLD ;Clear direction flag REPE CMPSB ;Compare the chars JNZ NOSYS ;Not IBMBIO.COM MOV DI,20H ;Point to second entry MOV SI,DOSENTRY ;DOS name MOV CX,11 ;Compare 11 chars REPE CMPSB ;Compare the chars JNZ NOSYS ;Not IBMDOS.COM POP DS ;Restore DS RET NOSYS: ;Not a system disk, prompt user to retry MOV SI,NOSYSMSG ;Load not system disk message CALL PRINT ;Print it MOV AH,0 ;Function = wait and read INT 16H ;Call keyboard BIOS service POP DS ;Restore DS STC ;Set CF (indicate error) RET ; ; Not a system disk error message ; NOSYSMSG: DB 13,10 DM "Non-System disk or disk error" DB 13,10 DM "Replace and strike any key when ready" DB 13,10,0 ; ; Code for loading ROM BASIC ; LDBASIC: INT 18H ; ; Boot failure message ; BOOTERRMSG: DB 13,10 DM "Disk Boot failure" DB 13,10,0 ; ; Increments the BX pointer by SI sectors ; INCDSTPTR: PUSH AX ;Save AX PUSH DX ;Save DX MOV AX,SI ;Sectors read MOV DI,200H ;Size of each sector MUL AX,DI ;Bytes read ADD BX,AX ;Add bytes read to BX POP DX ;Restore DX POP AX ;Restore AX RET ; ; Author ; DB "Robert O'Rear " ; ; BIOS name ; BIOENTRY: DM "ibmbio com0" ;"0" at the end so MSB won't be set ;for last char of the filename DOSENT: EQU 20H ;Location of the second dir entry ; ; DOS name ; DOSENTRY: DM "ibmdos com0" ;"0" at the end so MSB won't be set ;for last char of the filename DB 0C9H ;End of object code