     1                                  ;	PAGE	,132			;
     2                                  	%warning out: ...MSINIT.ASM
     2          ******************       warning: out: ...MSINIT.ASM [-w+user]
     3                                  ;=======================================================
     4                                  ;REVISION HISTORY:
     5                                  ;AN000; - NEW Version 4.00. J.K.
     6                                  ;AC000; - Modified Line 4.00. J.K.
     7                                  ;ANxxx; - PTMyyy
     8                                  ;==============================================================================
     9                                  ;AN001; P87 Set the value of MOTOR START TIME Variable		    6/25/87 J.K.
    10                                  ;AN002; P40 Boot from the system with no floppy diskette drives     6/26/87 J.K.
    11                                  ;AN003; D9  Double Word MOV instruction for 386 based machine	    7/1/87  J.K.
    12                                  ;AN004; D64 Extend DOS 3.3 FAT tables to 64 K entries.		    7/8/87  J.K.
    13                                  ;AN005; D113 Disable I/O access to unformatted media		    9/03/87 J.K.
    14                                  ;AN006; p941 D113 does not implemented properly.		    9/11/87 J.K.
    15                                  ;AN007; p969 Should Honor OS2 boot record.			    9/11/87 J.K.
    16                                  ;AN008; p985 Allow I/O access to unformtted media		    9/14/87 J.K.
    17                                  ;AN009; p1535 Disallow I/O access to unformtted media		   10/15/87 J.K.
    18                                  ;AN010; p2349 Cover DOS 3.3 and below FDISK bug 		   11/10/87 J.K.
    19                                  ;AN011; P2431 OS2 boot record version number is at offset 7 (not 8)11/12/87 J.K.
    20                                  ;AN012; P2900 DOS 4.0 does not recognize 3.0 formatted media	   12/18/87 J.K.
    21                                  ;AN013; P3409 Extended keyboard not recognized			   02/05/88 J.K.
    22                                  ;AN014; D486 Share installation for big media			   02/23/88 J.K.
    23                                  ;AN015; P3929 Boot record buffer overlaps MSBIO code		   03/18/88 J.K.
    24                                  ;==============================================================================
    25                                  
    26                                  	itest equ 0
    27                                  
    28                                  	%include "entryseg.nas"
     1                              <1> 
     2                              <1> %ifndef ENTRYSEGNAS
     3                              <1> %define ENTRYSEGNAS 1
     4                              <1> 
     5                              <1> %include "lmacros3.mac"
     1                              <2> [list -]
     1          ******************  <2>  warning: redefining multi-line macro `struc' [-w+pp-macro-redef-multi]
    14                              <3> [list -]
    14                              <2> [list -]
     6                              <1> %include "entrysw.mac"
     1                              <2> 
     2                              <2> %ifndef __ENTRYSW_MAC__
     3                              <2>  %assign __ENTRYSW_MAC__ 1
     4                              <2> 
     5                              <2> %assign _DOSCODEHMA		1
     6                              <2> %assign _RELOCATEDOSCODE	0
     7                              <2> 
     8                              <2> 		; Write a label "%1" (only if DOSCODE isn't relocated) and
     9                              <2> 		; "relocated%1" (always).
    10                              <2> 	%imacro relocated 1-2.nolist
    11                              <2> %ifnidni %2, device
    12                              <2>  %ifnidni %2, amis
    13                              <2>   %ifn _RELOCATEDOSCODE
    14                              <2> %1:
    15                              <2> 	global %1
    16                              <2>   %endif
    17                              <2>  %endif
    18                              <2> %endif
    19                              <2> relocated%1:				; always used for local labels
    20                              <2> 	global relocated%1
    21                              <2> 	%endmacro
    22                              <2> 
    23                              <2> %if _RELOCATEDOSCODE
    24                              <2> DOSENTRYADJUSTSEGMENT equ 60h - 26h
    25                              <2> %else
    26                              <2> DOSENTRYADJUSTSEGMENT equ 0
    27                              <2> %endif
    28                              <2> DOSENTRYADJUSTOFFSET equ DOSENTRYADJUSTSEGMENT * 16
    29                              <2> 
    30                              <2> DOSENTRYDEVICEBASE equ 10h
    31                              <2> 
    32                              <2> %endif
     7                              <1> [list -]
    23                              <1>  %define DOSENTRYGROUP DOSCODEGROUP
    24                              <1>  [list -]
    39                              <1> usesection DOSENTRY
    40                              <1> 
    41                              <1> %endif
    29                                  	%include "dcodeseg.nas"
     1                              <1> 
     2                              <1> %ifndef DCODESEGNAS
     3                              <1> %assign DCODESEGNAS 1
     4                              <1> 
     5                              <1> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <1> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <1> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <1> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <1> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <1> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <1> 
    12                              <1> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <1>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <1> %endif
    15                              <1> 
    16                              <1> %endif
    30                                  	%include "lmacros3.mac"
     1                              <1> [list -]
    31                                  
    32                                  addsection DOSSTART, align=16 PUBLIC class=DOSSTART
    33                                  ; (no prior section) ; DOSSTART		ENDS
    34                                  
    35                                  addsection AFTERDOSDATA, align=16 class=AFTERDOSDATA
    36                                  ; (no prior section) ; AFTERDOSDATA	ENDS
    37                                  
    38                                  	%include "lstruct.mac"
     1                              <1> [list -]
    13                              <1> [list -]
    39                                  	%include "sysinisw.mac"
     1                              <1> 
     2                              <1> SYSINITSTACK equ 256+128
    40                                  	%include "msgroup.mac"	;DEFINE CODE SEGMENT
     1                              <1> EVBOUND equ 1  ;THIS VALUE BEING 0 DOES NO BOUNDARY ALLIGNMENT, VALUE 1	  ;3.30
     2                              <1> 	     ; ALIGNS TO EVEN						  ;3.30
     3                              <1> 
     4                              <1> ; NASM original macros
     5                              <1> 
     6                              <1> %include "dcodeseg.nas"
     1                              <2> 
     2                              <2> %ifndef DCODESEGNAS
     3                              <2> %assign DCODESEGNAS 1
     4                              <2> 
     5                              <2> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <2> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <2> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <2> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <2> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <2> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <2> 
    12                              <2> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <2>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <2> %endif
    15                              <2> 
    16                              <2> %endif
     7                              <1> 
     8                              <1> 	%if EVBOUND	;;IF EVEN (WORD) ALLIGNMENT IS REQUESTED,	  ;3.30
     9                              <1> 
    10                              <1> %imacro EVENB 0.nolist
    11                              <1> 	EVEN	;;ADJUST TO EVEN BOUNDARY
    12                              <1> %endmacro
    13                              <1> 
    14                              <1> %imacro ODD 0.nolist
    15                              <1> %if (($ - $$) % 2) == 0
    16                              <1> 	db ?
    17                              <1> %endif
    18                              <1> %endmacro
    19                              <1> 
    20                              <1> 	%else	;;SINCE EVEN ALLIGNMENT IS NOT DESIRED, JUST USE BYTE ALLI;3.30 GNMENT
    21                              <1> 
    22                              <1> %imacro EVENB 0.nolist
    23                              <1> ;;REQUEST FOR WORD ALLIGNMENT DOES NOTHING				  ;3.30
    24                              <1> %endmacro
    25                              <1> 
    26                              <1> %imacro ODD 0.nolist
    27                              <1> ;;REQUEST FOR ODD ALLIGNMENT DOES NOTHING				  ;3.30
    28                              <1> %endmacro
    29                              <1> 
    30                              <1> 	%endif								  ;3.30
    31                              <1> 
    32                              <1> %imacro CODE_SEGMENT 0.nolist
    33                              <1> 	section BIOCODE
    34                              <1> %endmacro
    35                              <1> 
    36                              <1> ; end of NASM original macros
    37                              <1> 
    38                              <1> 	CODE_SEGMENT							  ;3.30
    39                              <1> 	ASSUME	CS:BIOCODE 						  ;3.30
    40                              <1> 									  ;3.30
    41                                  
    42                                  	addsection BIOCODE
    43                                  	usesection DOSENTRYINIT
    44                                  
    45                                  	%include "msdskpr.mac"
     1                              <1> ; The following structure defines the disk parameter table
     2                              <1> ; pointed to by Interrupt vector 1EH (location 0:78H)
     3                              <1> 
     4                              <1> DISK_PARMS	STRUC
     5 00000000 ??                  <1> DISK_SPECIFY_1	DB	?
     6 00000001 ??                  <1> DISK_SPECIFY_2	DB	?
     7 00000002 ??                  <1> DISK_MOTOR_WAIT DB	?	; Wait till motor off
     8 00000003 ??                  <1> DISK_SECTOR_SIZ DB	?	; Bytes/Sector (2 = 512)
     9 00000004 ??                  <1> DISK_EOT	DB	?	; Sectors per track (MAX)
    10 00000005 ??                  <1> DISK_RW_GAP	DB	?	; Read Write Gap
    11 00000006 ??                  <1> DISK_DTL	DB	?
    12 00000007 ??                  <1> DISK_FORMT_GAP	DB	?	; Format Gap Length
    13 00000008 ??                  <1> DISK_FILL	DB	?	; Format Fill Byte
    14 00000009 ??                  <1> DISK_HEAD_STTL	DB	?	; Head Settle Time (MSec)
    15 0000000A ??                  <1> DISK_MOTOR_STRT DB	?	; Motor start delay
    16                              <1> DISK_PARMS	ENDS
    17                              <1> 
    18                              <1> ROMStatus	equ	1
    19                              <1> ROMRead 	equ	2
    20                              <1> ROMWrite	equ	3
    21                              <1> ROMVerify	equ	4
    22                              <1> ROMFormat	equ	5
    46                                  	%include "msequ.mac"
     1                              <1> %warning out: MSEQU.INC...
     1          ******************  <1>  warning: out: MSEQU.INC... [-w+user]
     2                              <1> ;==============================================================================
     3                              <1> 
     4                              <1> FTOOBIG 	EQU	80H
     5                              <1> FBIG		EQU	40H
     6                              <1> ROMSTATUS	EQU	1
     7                              <1> ROMREAD 	EQU	2
     8                              <1> ROMWRITE	EQU	3
     9                              <1> ROMVERIFY	EQU	4
    10                              <1> ROMFORMAT	EQU	5
    11                              <1> VID_SIZE	EQU 12
    12                              <1> 
    13                              <1> %include "msbds.mac"    ; VARIOUS EQUATES FOR BDS
     1                              <2> 
     2                              <2> %warning out: MSBDS.INC...
     2          ******************  <2>  warning: out: MSBDS.INC... [-w+user]
     3                              <2> ;	SCCSID = @(#)IBMBDS.ASM 1.9 85/09/16
     4                              <2> ;==============================================================================
     5                              <2> ;REVISION HISTORY:
     6                              <2> ;AN000 - New for DOS Version 4.00 - J.K.
     7                              <2> ;AC000 - Changed for DOS Version 4.00 - J.K.
     8                              <2> ;AN00x - PTM number for DOS Version 4.00 - J.K.
     9                              <2> ;==============================================================================
    10                              <2> ;AN001; D113 Disable I/O access to unformatted media		    9/03/87 J.K.
    11                              <2> ;==============================================================================
    12                              <2> 
    13                              <2> ; VALUES FOR VARIOUS FLAGS IN BDS.FLAGS.
    14                              <2> 
    15                              <2> FNON_REMOVABLE	    EQU     01H 	;FOR NON-REMOVABLE MEDIA
    16                              <2> FCHANGELINE	    EQU     02H 	;IF CHANGELINE SUPPORTED ON DRIVE
    17                              <2> RETURN_FAKE_BPB     EQU     04H 	; WHEN SET, DON'T DO A BUILD BPB
    18                              <2> 					; JUST RETURN THE FAKE ONE
    19                              <2> GOOD_TRACKLAYOUT    EQU     08H 	; THE TRACK LAYOUT HAS NO FUNNY SECTORS
    20                              <2> ; FCHANGED_BY_FORMAT  EQU	    08H
    21                              <2> FI_AM_MULT	    EQU     10H 	;IF MORE THAN ONE LOGICAL FOR THIS PHYSICAL
    22                              <2> FI_OWN_PHYSICAL     EQU     20H 	;SIGNIFY LOGICAL OWNER OF THIS PHYSICAL
    23                              <2> FCHANGED	    EQU     40H 	;INDICATES MEDIA CHANGED
    24                              <2> SET_DASD_TRUE	    EQU     80H 	; SET DASD BEFORE NEXT FORMAT
    25                              <2> FCHANGED_BY_FORMAT  EQU    100H 	;MEDIA CHANGED BY FORMAT
    26                              <2> UNFORMATTED_MEDIA   EQU    200H 	;AN001; Fixed disk only
    27                              <2> F_LBA		equ	400h		; LBA supported
    28                              <2> 
    29                              <2> LBAPACKETSTRUC struc
    30 00000000 ????                <2> lpSize		dw ?
    31 00000002 ????                <2> lpCount		dw ?
    32 00000004 ????????            <2> lpBuffer	dd ?
    33 00000008 ????????????????    <2> lpSector	dd ?,?
    34                              <2> LBAPACKETSTRUC ends
    35                              <2> 
    36                              <2> ;
    37                              <2> ; VARIOUS FORM FACTORS TO DESCRIBE MEDIA
    38                              <2> ;
    39                              <2> FF48TPI 	    EQU     0
    40                              <2> FF96TPI 	    EQU     1
    41                              <2> FFSMALL 	    EQU     2
    42                              <2> FFHARDFILE	    EQU     5
    43                              <2> FFOTHER 	    EQU     7
    44                              <2> 
    45                              <2> BDS_TYPE	STRUC
    46 00000000 ????????            <2> LINK		DD		?	; LINK TO NEXT BDS
    47 00000004 ??                  <2> DRIVENUM	DB		?	; INT 13 DRIVE NUMBER
    48 00000005 ??                  <2> DRIVELET	DB		?	; DOS DRIVE NUMBER
    49 00000006 ????                <2> BYTEPERSEC	DW		?	; NUMBER OF BYTES/SEC
    50 00000008 ??                  <2> SECPERCLUS	DB		?	; SEC PER ALLOCATION UNIT
    51 00000009 ????                <2> RESSEC		DW		?	; NUMBER OF RESERVED SECTORS
    52 0000000B ??                  <2> CFAT		DB		?	; NUMBER OF FATS
    53 0000000C ????                <2> CDIR		DW		?	; NUMBER OF DIRECTORY ENTRIES
    54 0000000E ????                <2> DRVLIM		DW		?	; NUMBER OF SECTORS ON MEDIUM
    55 00000010 ??                  <2> MEDIAD		DB		?	; MEDIA DESCRIPTOR BYTE
    56 00000011 ????                <2> CSECFAT 	DW		?	; NUMBER OF SECTORS/FAT
    57 00000013 ????                <2> SECLIM		DW		?	; SECTORS PER TRACK
    58 00000015 ????                <2> HDLIM		DW		?	; MAX NUMBER OF HEADS
    59 00000017 ????                <2> HIDSEC_L	DW		?	; NUMBER OF HIDDEN SECTORS
    60 00000019 ????                <2> HIDSEC_H	dw		? ;0	;J.K.87
    61 0000001B ????                <2> DRVLIM_L	dw		? ;0	;J.K.87
    62 0000001D ????                <2> DRVLIM_H	dw		? ;0	;J.K.87
    63 0000001F ??                  <2> FATSIZ		DB		?	; FLAGS...
    64 00000020 ????                <2> OPCNT		DW		?	; OPEN REF. COUNT
    65 00000022 ??                  <2> FORMFACTOR	DB		?	; FORM FACTOR INDEX
    66 00000023 ????                <2> FLAGS		DW		?	; VARIOUS FLAGS
    67 00000025 ????                <2> CCYLN		DW		?	; MAX NUMBER OF CYLINDERS
    68 00000027 ????                <2> RBYTEPERSEC	DW		?	; RECOMMENDED BPB
    69 00000029 ??                  <2> RSECPERCLUS	DB		?
    70 0000002A ????                <2> RRESSEC 	DW		?
    71 0000002C ??                  <2> RCFAT		DB		?
    72 0000002D ????                <2> RCDIR		DW		?
    73 0000002F ????                <2> RDRVLIM 	DW		?
    74 00000031 ??                  <2> RMEDIAD 	DB		?
    75 00000032 ????                <2> RCSECFAT	DW		?
    76 00000034 ????                <2> RSECLIM 	DW		?
    77 00000036 ????                <2> RHDLIM		DW		?
    78 00000038 ????                <2> RHIDSEC_L	DW		?
    79 0000003A ????                <2> RHIDSEC_H	DW		? ;0	;J.K.87
    80 0000003C ????                <2> RDRVLIM_L	dw		? ;0	;J.K.87
    81 0000003E ????                <2> RDRVLIM_H	dw		? ;0	;J.K.87
    82 00000040 ????????????        <2> RESERVE 	DB		6 DUP (?)	; RESERVED FOR FUTURE
    83 00000046 ??                  <2> TRACK		DB		?	; LAST TRACK ACCESSED ON DRIVE
    84 00000047 ????                <2> TIM_LO		DW		?	; TIME OF LAST ACCESS. KEEP
    85 00000049 ????                <2> TIM_HI		DW		?	; THESE CONTIGUOUS.
    86 0000004B <res Ch>            <2> VOLID		DB		12 DUP (?)	; VOLUME ID OF MEDIUM
    87 00000057 ????????            <2> VOL_SERIAL	dd	? ;0	  ;J.K.87 Current volume serial number from Boot record
    88 0000005B <res 9h>            <2> FILESYS_Id	db	9 dup (?) ;(0) ;J.K.87 Current file system id from Boot record
    89                              <2> BDS_TYPE	ENDS
    90                              <2> 
    91                              <2> BPBSIZE     equ	TRACK - RBYTEPERSEC ; SIZE IN BYTES OF RECBPB AREA IN THE BDS
    92                              <2> 
    93                              <2> 
    94                              <2> ;*********************************************************************
    95                              <2> ;	BDS structure for mini disk - J.K. 4/7/86
    96                              <2> ;*********************************************************************
    97                              <2> 
    98                              <2> BDSM_type	struc
    99 00000000 ????                <2> mlink		DW	? ;-1			;Link to next structure
   100 00000002 ????                <2> 		DW	?
   101 00000004 ??                  <2> mdriveNum	DB	? ;80			;Int 13 Drive Number
   102 00000005 ??                  <2> mdriveLet	DB	? ;3			;Logical Drive Number
   103 00000006 ????                <2> mBytePerSec	DW	? ;512
   104 00000008 ??                  <2> mSecPerClus	DB	? ;1			;Sectors/allocation unit
   105 00000009 ????                <2> mRESSEC 	DW	? ;1			;Reserved sectors for DOS
   106 0000000B ??                  <2> mcFAT		DB	? ;2			;No. of allocation tables
   107 0000000C ????                <2> mcDIR		DW	? ;16			;Number of directory entries
   108 0000000E ????                <2> mDRVLIM 	DW	? ;0			;Number of sectors (at 512 bytes each)
   109 00000010 ??                  <2> mMediad 	DB	? ;11111000B		;Media descriptor
   110 00000011 ????                <2> mcSecFat	DW	? ;1			;Number of FAT sectors
   111 00000013 ????                <2> mSECLIM 	DW	? ;0			;Sector limit
   112 00000015 ????                <2> mHDLIM		DW	? ;0			;Head limit
   113 00000017 ????                <2> mHIDSEC_L	DW	? ;0			;Hidden sector count
   114 00000019 ????                <2> mHidsec_H	dw	? ;0			;J.K.87
   115 0000001B ????                <2> mDrvlim_L	dw	? ;0			;J.K.87
   116 0000001D ????                <2> mDrvlim_H	dw	? ;0			;J.K.87
   117 0000001F ??                  <2> mFatSiz 	DB	? ;0			;TRUE => bigfat
   118 00000020 ????                <2> mOPCNT		DW	? ;0			;Open Ref. Count
   119 00000022 ??                  <2> mFormFactor	DB	? ;3			;Form Factor
   120 00000023 ????                <2> mFLAGS		DW	? ;0020H		;Various Flags
   121 00000025 ????                <2> mcCyln		dw	? ;40			;max number of cylinders
   122 00000027 <res 1Fh>           <2> mRecBPB 	db	31 dup (?) ;(0)		;Recommended BPB for drive
   123 00000046 ??                  <2> mTrack		db	? ;-1
   124 00000047 ????                <2> IsMini		dw	? ;1			;Overlapping TIM_LOH
   125 00000049 ????                <2> Hidden_Trks	dw	? ;0			;Overlapping TIM_HIH
   126 0000004B <res Bh>            <2> mVOLID		DB	11 dup (?) ;"NO NAME    "           ;Volume ID for this disk
   127 00000056 ??                  <2> 		DB	? ;0			;ASCIZII for "NO NAME    "
   128 00000057 ????????            <2> mVol_Serial	dd	? ;0	   ;Current volume serial number from Boot record
   129 0000005B ????????????????    <2> mFileSys_Id	db	8 dup (?) ;"FAT12   " ;Current file system id from Boot record
   130 00000063 ??                  <2> 		db	? ;0
   131                              <2> 
   132                              <2> BDSM_type	ENDS
   133                              <2> ;******************************************************************************
   134                              <2> Max_mini_dsk_num equ 23	      ;J.K. 4/7/86 - max # of mini disk ibmbio can support
   135                              <2> ;
   136                              <2> 
    14                              <1> 
    15                              <1> ;AN000; Extended BPB structure.
    16                              <1> BPB_TYPE STRUC
    17 00000000 ????                <1> SECSIZE DW	?
    18 00000002 ??                  <1> SECALL	DB	?
    19 00000003 ????                <1> RESNUM	DW	?
    20 00000005 ??                  <1> FATNUM	DB	?
    21 00000006 ????                <1> DIRNUM	DW	?
    22 00000008 ????                <1> SECNUM	DW	?
    23 0000000A ??                  <1> FATID	DB	?
    24 0000000B ????                <1> FATSIZE DW	?
    25 0000000D ????                <1> SLIM	DW	?
    26 0000000F ????                <1> HLIM	DW	?
    27 00000011 ????                <1> HIDDEN_L  DW	  ?
    28 00000013 ????                <1> HIDDEN_H  dw	  ? ;0			;J.K.
    29 00000015 ????                <1> SECNUM_L  dw	  ? ;0			;J.K.
    30 00000017 ????                <1> SECNUM_H  dw	  ? ;0			;J.K.
    31                              <1> BPB_TYPE ENDS
    32                              <1> 
    33                              <1> ;;;;;;;;;;;
    34                              <1> BOOT_SERIAL_SIZE	equ	4	;J.K.
    35                              <1> BOOT_VOLUME_LABEL_SIZE	equ	11	;J.K.
    36                              <1> BOOT_SYSTEM_ID_SIZE	equ	8	;J.K.
    37                              <1> EXT_BOOT_SIGNATURE	equ	41	;J.K.
    38                              <1> RSINIT equ 0A3H		      ;RS232 INITIALIZATION
    39                              <1> 			      ;9600 BAUD:NO PARITY:1 STOP:8 BIT WORD
    40                              <1> LF equ 10			      ;LINE FEED
    41                              <1> CR equ 13			      ;CARRIAGE RETURN
    42                              <1> BACKSP equ 8		      ;BACKSPACE
    43                              <1> BRKADR equ 1BH * 4		      ;006C  1BH BREAK VECTOR ADDRESS
    44                              <1> TIMADR equ 1CH * 4		      ;0070  1CH TIMER INTERRUPT
    45                              <1> DSKADR equ 1EH * 4		      ;ADDRESS OF PTR TO DISK PARAMETERS
    46                              <1> SEC9 equ 522H		      ;ADDRESS OF DISK PARAMETERS
    47                              <1> HEADSETTLE equ SEC9+9	      ; ARR 2.20 ADDRESS OF HEAD SETTLE TIME
    48                              <1> NORMSETTLE equ 15		      ; ARR 2.20 NORMAL HEAD SETTLE
    49                              <1> SPEEDSETTLE equ 0		      ; ARR 2.20 SPEED UP SETTLE TIME
    50                              <1> INITSPOT equ 534H		      ; ARR IBM WANTS 4 ZEROS HERE
    51                              <1> AKPORT equ 20H
    52                              <1> EOI equ 20H
    53                              <1> CMDLEN	equ	    0			    ;LENGTH OF THIS COMMAND
    54                              <1> UNIT	equ	    1			    ;SUB UNIT SPECIFIER
    55                              <1> CMD	equ	    2			    ;COMMAND CODE
    56                              <1> STATUS	equ	    3			    ;STATUS
    57                              <1> MEDIA	equ	    13			    ;MEDIA DESCRIPTOR
    58                              <1> TRANS	equ	    14			    ;TRANSFER ADDRESS
    59                              <1> COUNT	equ	    18			    ;COUNT OF BLOCKS OR CHARACTERS
    60                              <1> START	equ	    20			    ;FIRST BLOCK TO TRANSFER
    61                              <1> EXTRA	equ	    22			    ;USUALLY A POINTER TO VOL ID FOR ERROR 15
    62                              <1> CHROUT	equ	    29H
    63                              <1> MAXERR	equ	     5
    64                              <1> LSTDRV	equ	     504H
    65                              <1> 
    66                              <1> NOTBUSYSTATUS	equ	10000000B	    ; NOT BUSY
    67                              <1> ACKSTATUS	equ	01000000B	    ; ACKNOWLEDGE (FOR WHAT?)
    68                              <1> NOPAPERSTATUS	equ	00100000B	    ; NO MORE PAPER
    69                              <1> SELECTEDSTATUS	equ	00010000B	    ; THE PRINTER SAID IT WAS SELECTED
    70                              <1> IOERRSTATUS	equ	00001000B	    ; SOME KINDA ERROR
    71                              <1> RESERVED	equ	00000110B	    ; NOPS
    72                              <1> TIMEOUTSTATUS	equ	00000001B	    ; TIME OUT.
    73                              <1> ERROR_UNKNOWN_MEDIA   equ 7		    ; FOR USE IN BUILD BPB CALL
    74                              <1> 
    75                              <1> PATHGEN 	equ	1
    47                                  	%include "msmacro.mac"
     1                              <1> 
     2                              <1> %include "dcodeseg.nas"
     1                              <2> 
     2                              <2> %ifndef DCODESEGNAS
     3                              <2> %assign DCODESEGNAS 1
     4                              <2> 
     5                              <2> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <2> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <2> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <2> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <2> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <2> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <2> 
    12                              <2> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <2>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <2> %endif
    15                              <2> 
    16                              <2> %endif
     3                              <1> section BIOCODE
     4                              <1> 
     5                              <1> ;
     6                              <1> ; This file contains three macros used in debugging the system.  If the
     7                              <1> ; variable "itest" (in msbio.asm) is nonzero code is included in the
     8                              <1> ; modules to print debugging messages.	The level of debugging is controlled
     9                              <1> ; by the value of the variable fTestBits in msbio.asm.	Specific bits in
    10                              <1> ; the variable determine which messages to print.  The equ's below tell
    11                              <1> ; which bits control which funcitons.  For example the fifth bit
    12                              <1> ; cooresponds to disk activity (see fTestDisk equ below).
    13                              <1> ;
    14                              <1> ;   The macros in the file are:
    15                              <1> ;
    16                              <1> ;	message    Prints an ascii string on the screen.
    17                              <1> ;		   Example usage:
    18                              <1> ;
    19                              <1> ;		      message fTestDisk, <"Start Disk Write", CR, LF>
    20                              <1> ;		      message fTestINIT, <"Begin BDS initialization">
    21                              <1> ;
    22                              <1> ;
    23                              <1> ;	MNUM	   Print the value in a register or memory location on
    24                              <1> ;		   the screen. Value is displayed in hex.
    25                              <1> ;		   Usage:
    26                              <1> ;		      MNUM  bitpattern, valueLocation
    27                              <1> ;
    28                              <1> ;		   valueLocation is typically a regester:
    29                              <1> ;
    30                              <1> ;		      mnum  fTestCom, AX
    31                              <1> ;		      mnum  fTestDisk, DX
    32                              <1> ;
    33                              <1> ;		   ValueLocation can also be a memory location:
    34                              <1> ;
    35                              <1> ;		      mnum  fTestINIT, Final_Dos_Location
    36                              <1> ;
    37                              <1> ;		   If no valueLocation is given the macro defaults to
    38                              <1> ;		   the BX register.
    39                              <1> ;
    40                              <1> ;	ZWAIT	    Stops the program until any key is pressed.
    41                              <1> ;
    42                              <1> ;
    43                              <1> ;	The three macros preserve all register values.	If "test" is zero
    44                              <1> ;	defined during assembly then the  marco produce no code.
    45                              <1> ;
    46                              <1> 
    47                              <1> 	%IF	itest							  ;3.30
    48                              <1> 		EXTRN	MSGOUT:NEAR,MSGNUM:NEAR 			  ;3.30
    49                              <1> 	    EXTRN   NUMBUF:BYTE,DIGITS:BYTE,FTESTBITS:WORD		  ;3.30
    50                              <1> 		EXTRN	DUMPBYTES:NEAR,OUTCHAR:NEAR,HEX_TO_ASCII:NEAR	  ;3.30
    51                              <1> 
    52                              <1> 
    53                              <1> fTestALL    equ     1111111111111111b	; watch everything
    54                              <1> fTestHARD   equ     0000000000000001b	; watch hard disk initialization
    55                              <1> fTest96     equ     0000000000000010b	; watch 96 tpi activity
    56                              <1> FTEST13     EQU     0000000000000100B	; WATCH INT 13 ACTIVITY 	  ;3.30
    57                              <1> FTESTCOM    EQU     0000000000001000B	; WATCH PACKET ACTIVITY 	  ;3.30
    58                              <1> FTESTINIT   EQU     0000000000010000B	; WATCH INITIALIZATION MESSAGES   ;3.30
    59                              <1> FTESTDISK   EQU     0000000000100000B	; WATCH DISK DEVICE DRIVER CALLS  ;3.30
    60                              <1> FTESTCON    EQU     0000000001000000B	; WATCH SYSTEM WAIT ACTIVITY IN CO;3.30 NSOLE
    61                              <1> FtestClock  equ     0000000010000000b	; wathc clock device  5/2/86  ;3.30
    62                              <1> 
    63                              <1> ; NASM original macros
    64                              <1> 
    65                              <1> ;
    66                              <1> ; message macro -- see above for description
    67                              <1> ;
    68                              <1> 
    69                              <1> %unimacro stripangles 2+.nolist
    70                              <1> 
    71                              <1> %imacro stripangles 2+.nolist
    72                              <1> %defstr %%param %2
    73                              <1> %rep 16
    74                              <1>  %substr %%opening %%param 1
    75                              <1>  %ifidn %%opening, '<'
    76                              <1>   %substr %%param %%param 2,-1
    77                              <1>  %endif
    78                              <1> %endrep
    79                              <1> %rep 16
    80                              <1>  %strlen %%length %%param
    81                              <1>  %substr %%closing %%param %%length
    82                              <1>  %ifidn %%closing, '>'
    83                              <1>   %substr %%param %%param 1,-2
    84                              <1>  %endif
    85                              <1> %endrep
    86                              <1> %deftok %%token %%param
    87                              <1> %1 %%token
    88                              <1> %endmacro
    89                              <1> 
    90                              <1> %imacro MESSAGE 2+
    91                              <1> 	jmp short %%b
    92                              <1> %%a:
    93                              <1> 	stripangles db, %2
    94                              <1> 	db 0
    95                              <1> %%b:	push	SI
    96                              <1> 	push	AX
    97                              <1> 	mov	AX, %1
    98                              <1> 	mov	SI, OFFSET %%a
    99                              <1> 	call	MSGOUT
   100                              <1> 	pop	AX
   101                              <1> 	pop	SI
   102                              <1> %endmacro
   103                              <1> 
   104                              <1> 
   105                              <1> ;
   106                              <1> ; mnum macro -- see above for description
   107                              <1> ;
   108                              <1> 
   109                              <1> %imacro MNum 1-2
   110                              <1> 	push	AX
   111                              <1> %ifempty %2
   112                              <1> 	mov	AX,%1
   113                              <1> 	call	MSGNUM
   114                              <1> %else
   115                              <1> 	push	BX
   116                              <1> 	mov	BX,%2
   117                              <1> 	mov	AX,%1
   118                              <1> 	call	MSGNUM
   119                              <1> 	pop	BX
   120                              <1> %endif
   121                              <1> 	pop	AX
   122                              <1> %endmacro
   123                              <1> 
   124                              <1> 
   125                              <1> ;
   126                              <1> ; zwait macro -- see above for description
   127                              <1> ;
   128                              <1> 
   129                              <1> %imacro ZWAIT 0
   130                              <1> 	Message fTestALL,<"? ">
   131                              <1> 	CALL	ZWAITrtn
   132                              <1> %endmacro
   133                              <1> 
   134                              <1> ZWAITrtn:
   135                              <1> 	pushf				; save the flags
   136                              <1> 	push	AX			; preserve AX
   137                              <1> 	xor	AH, AH			; set command to get character ;3.30*
   138                              <1> 	int	16h			; call rom keyboard routine    ;3.30*
   139                              <1> 	pop	AX			; restore AX
   140                              <1> 	popf				; restore the flags
   141                              <1> 	ret
   142                              <1> 
   143                              <1> ;Dump_byte dumps the memory contents in hex. 				  ;3.30
   144                              <1> ;DUMPOFFLABEL should be a label or a variable defined in DUMPSEG.	  ;3.30
   145                              <1> %imacro DUMP_BYTE 3
   146                              <1> 	push	es							  ;3.30
   147                              <1> 	PUSH	DS							  ;3.30
   148                              <1> 	PUSH	SI							  ;3.30
   149                              <1> 	PUSH	CX							  ;3.30
   150                              <1> 									  ;3.30
   151                              <1> 	MOV	CX, %1							  ;3.30
   152                              <1> 	MOV	DS, CX							  ;3.30
   153                              <1> 	MOV	SI, OFFSET %2						  ;3.30
   154                              <1> 	MOV	CX, %3							  ;3.30
   155                              <1> 	call	dumpbytes						  ;3.30
   156                              <1> 									  ;3.30
   157                              <1> 	POP	CX							  ;3.30
   158                              <1> 	POP	SI							  ;3.30
   159                              <1> 	POP	DS							  ;3.30
   160                              <1> 	pop	es							  ;3.30
   161                              <1> %endmacro								  ;3.30
   162                              <1> 									  ;3.30
   163                              <1> ;Dump_Byte_Reg dumps the memory contents in hex. -  4/9/86		  ;3.30
   164                              <1> ;DUMPOFFREG should be a register contains the offset value in DUMPSEG.	  ;3.30
   165                              <1> %imacro DUMP_BYTE_REG 3
   166                              <1> DUMP_BYTE_REG	MACRO	DUMPSEG, DUMPOFFREG, BYTELENGTH 		  ;3.30
   167                              <1> 	push	es							  ;3.30
   168                              <1> 	PUSH	DS							  ;3.30
   169                              <1> 	PUSH	SI							  ;3.30
   170                              <1> 	PUSH	CX							  ;3.30
   171                              <1> 									  ;3.30
   172                              <1> 	MOV	CX, %1							  ;3.30
   173                              <1> 	MOV	DS, CX							  ;3.30
   174                              <1> 	MOV	SI, %2							  ;3.30
   175                              <1> 	MOV	CX, %3							  ;3.30
   176                              <1> 	call	dumpbytes						  ;3.30
   177                              <1> 									  ;3.30
   178                              <1> 	POP	CX							  ;3.30
   179                              <1> 	POP	SI							  ;3.30
   180                              <1> 	POP	DS							  ;3.30
   181                              <1> 	pop	es							  ;3.30
   182                              <1> %endmacro								  ;3.30
   183                              <1> 
   184                              <1> %else
   185                              <1> 		; if test is not defined then make macro into null statements
   186                              <1> %imacro Message 0-1+.nolist
   187                              <1> %endmacro
   188                              <1> 
   189                              <1> %imacro MNUM 0-1+.nolist
   190                              <1> %endmacro
   191                              <1> 
   192                              <1> %imacro ZWAIT 0-1+.nolist
   193                              <1> %endmacro
   194                              <1> 
   195                              <1> %imacro DUMP_BYTE 0-1+.nolist
   196                              <1> %endmacro
   197                              <1> 
   198                              <1> %imacro DUMP_BYTE_REG 0-1+.nolist
   199                              <1> %endmacro
   200                              <1> 
   201                              <1> %endif
   202                              <1> 
   203                              <1> %unimacro PATHSTART 2
   204                              <1> %unimacro PATHEND 2
   205                              <1> 
   206                              <1> %imacro PATHSTART 2
   207                              <1> 	%IF	PATHGEN							  ;3.30
   208                              <1> 	    PUBLIC  %2%1S,%2%1E						  ;3.30
   209                              <1> 	    %2%1S LABEL	 BYTE						  ;3.30
   210                              <1> 	%ENDIF								  ;3.30
   211                              <1> %endmacro								  ;3.30
   212                              <1> 									  ;3.30
   213                              <1> %imacro PATHEND 2
   214                              <1> 	%IF	PATHGEN							  ;3.30
   215                              <1> 	    %2%1E LABEL	 BYTE						  ;3.30
   216                              <1> 	%ENDIF								  ;3.30
   217                              <1> %endmacro								  ;3.30
    48                                  	%include "msextrn.mac"
     1                              <1> 
     2                              <1> section BIOCODE
     3                              <1>  assume cs:BIOCODE
     4                              <1> ;	SCCSID = @(#)IBMEXTRN.ASM	1.11 85/11/18
     5                              <1> ;This is for IBMINIT module.
     6                              <1> ;=======================================================
     7                              <1> ;REVISION HISTORY:
     8                              <1> ;AN000; - NEW Version 4.00. J.K.
     9                              <1> ;AC000; - Modified Line 4.00. J.K.
    10                              <1> ;ANxxx; - PTMyyy
    11                              <1> ;==============================================================================
    12                              <1> ;AN001; D486 SHARE installation for large media 		   2/23/88 J.K.
    13                              <1> ;==============================================================================
    14                              <1> 
    15                              <1> 	extern biocode_get_ds_dosentry, biocode_get_es_dosentry
    16                              <1> 	extern dosbiocode_get_ds_dosentry, dosbiocode_get_es_dosentry
    17                              <1> 	extern biocode_get_ds_dosbiodata, biocode_get_es_dosbiodata
    18                              <1> 	EXTRN	ORIG13:DWORD,ORIG19:DWORD
    19                              <1> 	EXTRN	COM2DEV:WORD,COM1DEV:WORD
    20                              <1> 	EXTRN	COM4DEV:WORD,COM3DEV:WORD
    21                              <1> 	EXTRN	LPT3DEV:WORD,LPT2DEV:WORD,LPT1DEV:WORD
    22                              <1> 	EXTRN	HARDDRV:BYTE,HARDNUM:BYTE,DRVMAX:BYTE,HDSKTAB:WORD
    23                              <1> 	EXTRN	DSKDRVS:WORD,HNUM:BYTE,EOT:BYTE,FHAVE96:BYTE
    24                              <1> 	EXTRN	REAL13:DWORD,DAYCNT:WORD,CONHEADER:WORD
    25                              <1> 	EXTRN	TWOHARD:BYTE,INT_2F_NEXT:DWORD
    26                              <1> 	EXTRN	BDSH:WORD,BDSX:WORD,START_BDS:WORD
    27                              <1> 	EXTRN	FHAVEK09:BYTE, NEW_ROM:BYTE
    28                              <1> 	EXTRN	SINGLE:BYTE
    29                              <1> 	EXTRN	BDSMs:BYTE		;for Mini Disk -J.K. 4/7/86
    30                              <1> 	EXTRN	HaveCMOSClock:byte	;set by IBMINIT. Used by IBMCLOCK.ASM
    31                              <1> 	EXTRN	BinToBCD:word		;set by IBMINIT. Used by IBMCLOCK.ASM
    32                              <1> 	EXTRN	DaycntToDay:word	;set by IBMINIT. Used by IBMCLOCK.ASM
    33                              <1> 	EXTRN	OLD13:DWORD
    34                              <1> 	extrn	Temp_H:word		;J.K. For 32 bit calculation. IBMDISK
    35                              <1> 	extrn	Start_Sec_H:word	;J.K.  IBMDISK.
    36                              <1> 	extrn	KEYRD_Func:byte 	;J.K. For IBMCON. Defined in IBMBDATA.
    37                              <1> 	extrn	KEYSTS_Func:byte	;J.K. For IBMCON. Defined in IBMBDATA.
    38                              <1> 	extrn	DiskSector:byte 	;J.K. IBMBDATA
    39                              <1> 	extrn	Bpb_In_Sector:word	;J.K. IBMBDATA
    40                              <1> 	extrn	SecPerClusInSector:Byte ;J.K. IBMBDATA
    41                              <1> 	extrn	NumberOfFats:byte	;J.K. IBMBDATA
    42                              <1> 	extrn	MediaByte:byte		;J.K. IBMBDATA
    43                              <1> 	extrn	Ext_Boot_Sig:Byte	;J.K. IBMBDATA
    44                              <1> 	extrn	Boot_Serial_L:Word	;J.K. IBMBDATA
    45                              <1> 	extrn	Boot_Serial_H:Word	;J.K. IBMBDATA
    46                              <1> 	extrn	Boot_Volume_Label:Byte	;J.K. IBMBDATA
    47                              <1> 	extrn	Boot_System_ID:Byte	;J.K. IBMBDATA
    48                              <1> 	extrn	Fat_12_ID:Byte		;J.K. IBMDISK
    49                              <1> 	extrn	Fat_16_ID:Byte		;J.K. IBMDISK
    50                              <1> 	extrn	lbapacket:byte
    51                              <1> 	extrn	Vol_No_Name:Byte	;J.K. IBMDISK
    52                              <1> 	extrn	MOTORSTARTUP:Byte	;J.K. IBMBDATA
    53                              <1> 	extrn	DoubleWordMov:Byte	;J.K. IBMDISK
    54                              <1> 	extrn	Model_Byte:Byte 	;J.K. IBMBIO2
    55                              <1> 	extrn	Secondary_Model_Byte:Byte ;J.K. IBMBIO2
    56                              <1> 
    57                              <1> 	%IF     itest
    58                              <1> 	    EXTRN   NUMBUF:BYTE,DIGITS:BYTE,FTESTBITS:WORD
    59                              <1> 	%ENDIF
    60                              <1> 
    61                              <1> 	EXTRN	START$:NEAR,ERROUT:NEAR,BLOCK13:FAR,INT19:FAR
    62                              <1> 	EXTRN	INTRET:NEAR,HDRIVE:NEAR,DRIVEX:NEAR,INT13:FAR,CBREAK:NEAR,OUTCHR:NEAR
    63                              <1> 	EXTRN	DISKRD:NEAR,MEDIA_PATCH:NEAR,GETBP1_PATCH:NEAR
    64                              <1> 	EXTRN	SET_PATCH:NEAR,DISKIO_PATCH:NEAR,DSKERR:NEAR,INIT_PATCH:NEAR
    65                              <1> 	extern DSKERR_PATCH
    66                              <1> 	EXTRN	TABLE_PATCH:NEAR,EXIT:NEAR,CHANGED_PATCH:NEAR
    67                              <1> 	EXTRN	ERRIN:NEAR,GETBP:NEAR,SWPDSK:NEAR
    68                              <1> 	EXTRN	OUTCHR:NEAR,WRMSG:NEAR,TIME_TO_TICKS:NEAR
    69                              <1> 	EXTRN	INT2F_DISK:NEAR,INSTALL_BDS:NEAR,SETDRIVE:NEAR
    70                              <1> 	extrn	Mov_Media_IDs:Near			;J.K.
    71                              <1> 	extrn	Clear_IDs:Near				;J.K.
    72                              <1> 	%IF     itest
    73                              <1> 	    EXTRN   MSGNUM:NEAR,MSGOUT:NEAR,dumpbytes:near,hex_to_ascii:near
    74                              <1> 	    EXTRN   outchar:near
    75                              <1> 	%ENDIF
    76                              <1> 	extrn	lbatochs:near, chstotuple:near
    77                              <1> 	extrn	lba_packet_setup:near
    78                              <1> 
    79                              <1> 	EXTRN	behind_dosentry_segment:WORD
    80                              <1> 	EXTRN	DEVICE_LIST:DWORD
    81                              <1> 	EXTRN	MEMORY_SIZE:WORD
    82                              <1> 	EXTRN	DEFAULT_DRIVE:BYTE
    83                              <1> 	EXTRN	BUFFERS:WORD
    84                              <1> 	EXTRN	SYSINIT:FAR
    85                              <1> 	extrn	Big_Media_Flag:Byte		;AN001;
    86                              <1> 
    87                              <1> ; END OF DISK MODULES FOR CONFIGURATION
    88                              <1> 
    89                              <1> 	EXTRN	END96TPI:BYTE
    90                              <1> 	EXTRN	ENDTWOHARD:BYTE
    91                              <1> 	EXTRN	ENDONEHARD:BYTE
    92                              <1> 	EXTRN	ENDSWAP:BYTE
    93                              <1> 	EXTRN	ENDFLOPPY:BYTE
    94                              <1> 
    95                              <1> ; IBM FIXED UP AT ROM
    96                              <1> 
    97                              <1> 	EXTRN	IBM_DISK_IO:FAR
    49                                  	%include "biostruc.mac"
     1                              <1> %warning out: BIOSTRUC.INC...
     1          ******************  <1>  warning: out: BIOSTRUC.INC... [-w+user]
     2                              <1> ;	SCCSID = @(#)BIOSTRUC.INC 1.0 86/09/30
     3                              <1> ; ROM BIOS CALL PACKET STRUCTURES
     4                              <1> 
     5                              <1> ;*******************************
     6                              <1> ;System Service call ( Int 15h )
     7                              <1> ;*******************************
     8                              <1> ;Function AH = 0C0h, Return system configuration
     9                              <1> ;For PC and PCJR on return:
    10                              <1> ;	(AH)	= 80h
    11                              <1> ;	(CY)	= 1
    12                              <1> ;For PCXT, PC PORTABLE and PCAT on return:
    13                              <1> ;	(AH)	= 86h
    14                              <1> ;	(CY)	= 1
    15                              <1> ;For all others:
    16                              <1> ;	(AH)	= 0
    17                              <1> ;	(CY)	= 0
    18                              <1> ;	(ES:BX) = pointer to system descriptor vector in ROS
    19                              <1> ; System descriptor :
    20                              <1> ;	DW	xxxx		length of descriptor in bytes,
    21                              <1> ;				minimum length = 8
    22                              <1> ;	DB	xx		model byte
    23                              <1> ;				0FFh	= PC
    24                              <1> ;				0FEh	= PC/XT, Portable
    25                              <1> ;				0FDh	= PC/JR
    26                              <1> ;				0FCh	= PC/AT, 6Mhz PC/AT,
    27                              <1> ;					  6Mhz PC/AT running coprocessor(?),
    28                              <1> ;					  PS/2 Model 50, 50 z
    29                              <1> ;				0FAh	= PS/2 Model 25, 30
    30                              <1> ;				0F9h	= PC Convertible
    31                              <1> ;				0F8h	= PS/2 Model 80
    32                              <1> ;				0F7h	= Nova
    33                              <1> ;				0E0 thru 0EFh = reserved
    34                              <1> ;
    35                              <1> ;	DB	xx		secondary model byte
    36                              <1> ;				000h	= PC1
    37                              <1> ;				000h	= PC/XT, Portable
    38                              <1> ;				000h	= PC/JR
    39                              <1> ;				000h	= PC/AT
    40                              <1> ;				001h	= 6Mhz PC/AT
    41                              <1> ;				003h	= 6Mhz PC/AT running coprocessor(?)
    42                              <1> ;				004h	= PS/2 Model 50, 50z
    43                              <1> ;				001h	= PS/2 Model 25
    44                              <1> ;				000h	= PC Convertible
    45                              <1> ;				000h	= PS/2 Model 80
    46                              <1> ;				000h	= Nova
    47                              <1> ;
    48                              <1> ;	DB	xx		bios revision level
    49                              <1> ;				00 for first release, subsequent release
    50                              <1> ;				of code with same model byte and
    51                              <1> ;				secondary model byte require revison level
    52                              <1> ;				to increase by one.
    53                              <1> ;
    54                              <1> ;	DB	xx		feature information byte 1
    55                              <1> ;				X0000000 = 1, bios use DMA channel 3
    56                              <1> ;					 = 0, DMA channel 3 not used
    57                              <1> ;
    58                              <1> ;				0X000000 = 1, 2nd Interrupt chip present
    59                              <1> ;					 = 0, 2nd Interrupt chip not present
    60                              <1> ;
    61                              <1> ;				00X00000 = 1, Real Time Clock present
    62                              <1> ;					 = 0, Real Time Clock not present
    63                              <1> ;
    64                              <1> ;				000X0000 = 1, Keyboard escape sequence(INT15h)
    65                              <1> ;						called in keyboard interrupt
    66                              <1> ;						(Int 09h).
    67                              <1> ;					 = 0, Keyboard escape sequence not
    68                              <1> ;						called.
    69                              <1> ;				0000XXXX reserved
    70                              <1> ;
    71                              <1> ;	DB	xx		feature information byte 2 - reserved
    72                              <1> ;
    73                              <1> ;	DB	xx		feature information byte 2 - reserved
    74                              <1> ;
    75                              <1> ;	DB	xx		feature information byte 2 - reserved
    76                              <1> ;
    77                              <1> ;	DB	xx		feature information byte 2 - reserved
    78                              <1> ;
    79                              <1> 
    80                              <1> BIOS_SYSTEM_DESCRIPTOR	struc
    81 00000000 ????                <1> bios_SD_leng		dw	?
    82 00000002 ??                  <1> bios_SD_modelbyte	db	?
    83 00000003 ??                  <1> bios_SD_scnd_modelbyte	db	?
    84 00000004 ??                  <1> 			db	?
    85 00000005 ??                  <1> bios_SD_featurebyte1	db	?
    86 00000006 ????????            <1> 			db   4 dup (?)
    87                              <1> BIOS_SYSTEM_DESCRIPTOR ends
    88                              <1> 
    89                              <1> ;FeatureByte1	bit map equates
    90                              <1> DMAchannel3		equ 10000000b
    91                              <1> ScndIntController	equ 01000000b
    92                              <1> RealTimeClock		equ 00100000b
    93                              <1> KeyEscapeSeq		equ 00010000b
    94                              <1> ;
    95                              <1> ;Model Byte
    96                              <1> MDL_PC1 	EQU	0FFH
    97                              <1> MDL_XT		EQU	0FEH
    98                              <1> MDL_JR		EQU	0FDH
    99                              <1> MDL_AT		EQU	0FCH
   100                              <1> MDL_CONVERT	EQU	0F9H
   101                              <1> 
   102                              <1> mdl_ps2_30	equ	0fah
   103                              <1> mdl_ps2_80	equ	0f8h
    50                                  	%include "cmosequ.mac"
     1                              <1> 							 ;;Rev 3.30 Modification
     2                              <1> ;Equates for CMOS.							   
     3                              <1> 									  
     4                              <1> ;----------------------------------------				  
     5                              <1> ;	CMOS EQUATES FOR THIS SYSTEM	:				  
     6                              <1> ;------------------------------------------------------------------------------- 
     7                              <1> CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT	 
     8                              <1> CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT 	 
     9                              <1> NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK - 	 
    10                              <1> 					;  HIGH BIT OF CMOS LOCATION ADDRESS	 
    11                              <1> 										 
    12                              <1> ;---------- CMOS TABLE LOCATION ADDRESS'S ## ----------------------------------- 
    13                              <1> CMOS_SECONDS	EQU	000H		; SECONDS				 
    14                              <1> CMOS_SEC_ALARM	EQU	001H		; SECONDS ALARM  ## NOTE:  ALL LOCATIONS 
    15                              <1> CMOS_MINUTES	EQU	002H		; MINUTES	      | IN THE CMOS AREA 
    16                              <1> CMOS_MIN_ALARM	EQU	003H		; MINUTES ALARM       | ARE IBM USE ONLY 
    17                              <1> CMOS_HOURS	EQU	004H		; HOURS 	      | AND  SUBJECT  TO 
    18                              <1> CMOS_HR_ALARM	EQU	005H		; HOURS ALARM	      | CHANGE. ONLY THE 
    19                              <1> CMOS_DAY_WEEK	EQU	006H		; DAY OF THE WEEK     | POST & BIOS CODE 
    20                              <1> CMOS_DAY_MONTH	EQU	007H		; DAY OF THE MONTH    | SHOULD	DIRECTLY 
    21                              <1> CMOS_MONTH	EQU	008H		; MONTH 	      | ACCESS LOCATIONS 
    22                              <1> CMOS_YEAR	EQU	009H		; YEAR (TWO DIGITS)   | IN CMOS STORAGE. 
    23                              <1> CMOS_REG_A	EQU	00AH		; STATUS REGISTER A   '----------------- 
    24                              <1> CMOS_REG_B	EQU	00BH		; STATUS REGISTER B  ALARM		 
    25                              <1> CMOS_REG_C	EQU	00CH		; STATUS REGISTER C  FLAGS		 
    26                              <1> CMOS_REG_D	EQU	00DH		; STATUS REGISTER D  BATTERY		 
    27                              <1> CMOS_DIAG	EQU	00EH		; POST DIAGNOSTIC STATUS RESULTS BYTE	 
    28                              <1> CMOS_SHUT_DOWN	EQU	00FH		; SHUTDOWN STATUS COMMAND BYTE		 
    29                              <1> CMOS_DISKETTE	EQU	010H		; DISKETTE DRIVE TYPE BYTE	      ;  
    30                              <1> ;		EQU	011H		; - RESERVED			      ;C 
    31                              <1> CMOS_DISK	EQU	012H		; FIXED DISK TYPE BYTE		      ;H 
    32                              <1> ;		EQU	013H		; - RESERVED			      ;E 
    33                              <1> CMOS_EQUIP	EQU	014H		; EQUIPMENT WORD LOW BYTE	      ;C 
    34                              <1> CMOS_B_M_S_LO	EQU	015H		; BASE MEMORY SIZE - LOW BYTE (X1024) ;K 
    35                              <1> CMOS_B_M_S_HI	EQU	016H		; BASE MEMORY SIZE - HIGH BYTE	      ;S 
    36                              <1> CMOS_E_M_S_LO	EQU	017H		; EXPANSION MEMORY SIZE - LOW BYTE    ;U 
    37                              <1> CMOS_E_M_S_HI	EQU	018H		; EXPANSION MEMORY SIZE - HIGH BYTE   ;M 
    38                              <1> CMOS_DISK_1	EQU	019H		; FIXED DISK TYPE - DRIVE C EXTENSION ;E 
    39                              <1> CMOS_DISK_2	EQU	01AH		; FIXED DISK TYPE - DRIVE D EXTENSION ;D 
    40                              <1> ;		EQU	01BH		; - 1BH THROUGH 2DH - RESERVED	      ;  
    41                              <1> CMOS_CKSUM_HI	EQU	02EH		; CMOS CHECKSUM - HIGH BYTE	      ;* 
    42                              <1> CMOS_CKSUM_LO	EQU	02FH		; CMOS CHECKSUM - LOW BYTE	      ;* 
    43                              <1> CMOS_U_M_S_LO	EQU	030H		; USABLE MEMORY ABOVE 1 MEG - LOW BYTE	 
    44                              <1> CMOS_U_M_S_HI	EQU	031H		; USABLE MEMORY ABOVE 1 MEG - HIGH BYTE  
    45                              <1> CMOS_CENTURY	EQU	032H		; DATE CENTURY BYTE (BCD)		 
    46                              <1> CMOS_INFO128	EQU	033H		; 128KB INFORMATION STATUS FLAG BYTE	 
    47                              <1> ;		EQU	034H		; - 34H THROUGH 3FH - RESERVED		 
    48                              <1> ;										 
    49                              <1> 							;;End of Modification									 
    50                              <1> 
    51                                  	%include "cputype.mac"
     1                              <1> ; Note: this must be a macro, and not a subroutine in the BIOS since
     2                              <1> ; 	it is called from both CODE and SYSINITSEG.
     3                              <1> ;
     4                              <1> ;------GET_CPU_TYPE------------------------------------------------------------May, 88 by MW
     5                              <1> ;  Returns: AX = 0 if 8086 or 8088
     6                              <1> ;              = 1 if 80286
     7                              <1> ;              = 2 if 80386
     8                              <1> ;
     9                              <1> %macro Get_CPU_Type 0
    10                              <1> 	pushf
    11                              <1> 	push	bx			; preserve bx
    12                              <1> 	xor	bx, bx			; init bx to zero
    13                              <1> 
    14                              <1> 	xor	ax,ax			; 0000 into AX
    15                              <1> 	push	ax			; put it on the stack...
    16                              <1> 	popf				; ...then shove it into the flags
    17                              <1> 	pushf				; get it back out of the flags...
    18                              <1> 	pop	ax			; ...and into ax
    19                              <1> 	and	ax,0F000h		; mask off high four bits
    20                              <1> 	cmp	ax,0F000h		; was it all 1's?
    21                              <1> 	je	%%cpu_8086		; aye; it's an 8086 or 8088
    22                              <1> 
    23                              <1> 	mov	ax,0F000h		; now try to set the high four bits..
    24                              <1> 	push	ax
    25                              <1> 	popf
    26                              <1> 	pushf
    27                              <1> 	pop	ax			; ...and see what happens
    28                              <1> 	and	ax,0F000h		; any high bits set ?
    29                              <1> 	jz	%%cpu_286		; nay; it's an 80286
    30                              <1> 
    31                              <1> %%cpu_386:				; bx starts as zero
    32                              <1> 	inc	bx			; inc twice if 386
    33                              <1> %%cpu_286:				; just inc once if 286
    34                              <1> 	inc	bx
    35                              <1> %%cpu_8086:				; don't inc at all if 086
    36                              <1> 	mov	ax, bx			; put CPU type value in ax
    37                              <1> 	pop	bx			; restore original bx
    38                              <1> 	popf
    39                              <1> %endmacro
    52                                  	%include "arena.mac"
     1                              <1> ;	SCCSID = @(#)arena.asm	1.1 85/04/09
     2                              <1> ;BREAK <Memory arena structure>
     3                              <1> 
     4                              <1> ;----+----+----+----+----+----+----+----+----+----+----+----+----+----+----;
     5                              <1> ;	     C	A  V  E  A  T	  P  R	O  G  R  A  M  M  E  R		   ;
     6                              <1> ;									   ;
     7                              <1> ;
     8                              <1> ; arena item
     9                              <1> ;
    10                              <1> arena	STRUC
    11 00000000 ??                  <1> arena_signature     DB	?		; 4D for valid item, 5A for last item
    12 00000001 ????                <1> arena_owner	    DW	?		; owner of arena item
    13 00000003 ????                <1> arena_size	    DW	?		; size in paragraphs of item
    14 00000005 ??????              <1> arena_reserved	    DB	3 DUP(?)	; reserved
    15 00000008 ????????????????    <1> arena_name	    DB	8 DUP(?)	; owner file name
    16                              <1> arena	ENDS
    17                              <1> 
    18                              <1> ;
    19                              <1> ; CAUTION: The routines in ALLOC.ASM rely on the fact that arena_signature
    20                              <1> ; and arena_owner_system are all equal to zero and are contained in DI.  Change
    21                              <1> ; them and change ALLOC.ASM.
    22                              <1> 
    23                              <1> arena_owner_system  EQU 0		; free block indication
    24                              <1> 
    25                              <1> arena_signature_normal	EQU 4Dh 	; valid signature, not end of arena
    26                              <1> arena_signature_end	EQU 5Ah 	; valid signature, last block in arena
    27                              <1> ;									   ;
    28                              <1> ;	     C	A  V  E  A  T	  P  R	O  G  R  A  M  M  E  R		   ;
    29                              <1> ;----+----+----+----+----+----+----+----+----+----+----+----+----+----+----;
    30                              <1> 
    53                                  	%include "codesw.mac"
     1                              <1> DOSCODE_HMA_SEGMENT equ 0FFFEh
     2                              <1> 	; address DOSCODE at this segment when in HMA
     3                              <1> DOSCODE_HMA_start_at equ (10000h - DOSCODE_HMA_SEGMENT) * 10h
     4                              <1> 	; offset from DOSCODE offset 0 to address 10_0000h
     5                              <1> DOSCODE_HMA_OFFSET equ DOSCODE_HMA_start_at + 30h
     6                              <1> 	; 50h = 20h ROM-BIOS, 20h VDISK header, 10h HMCB
    54                                  	%include "haltflag.mac"
     1                              <1> 
     2                              <1> ; Public Domain
     3                              <1> 
     4                              <1> flag_no_halt_tagcrash	equ 1
     5                              <1> flag_no_halt_mcb	equ 2
     6                              <1> flag_no_halt_hmcb	equ 4
     7                              <1> flag_no_halt_hmcb_free	equ 8
    55                                   global flag_no_halt_tagcrash, flag_no_halt_mcb
    56                                   global flag_no_halt_hmcb, flag_no_halt_hmcb_free
    57                                   extern haltflags
    58                                  
    59                                  	usesection DOSENTRYINIT
    60                                  
    61                                  		; For lDOS lCFG block
    62                                  LCFG_CheckDebugger	equ 20
    63                                  LCFG_Verbose		equ 21
    64                                  LCFG_ScanMode		equ 22
    65                                  LCFG_HaltFlag		equ 26
    66                                  LCFG_DBG_CHECK		equ 1		; flag: check debugger present, run int3
    67                                  LCFG_DBG_ASSUME		equ 2		; flag: default to assume debugger present
    68                                  LCFG_DBG_ONLY_VALID	equ 4
    69                                  LCFG_DBG_ONLY_IISP	equ 8
    70                                  ; For the FreeDOS kernel the CONFIG block CheckDebugger value is
    71                                  ;  as yet used as an ordinal: < 1, == 1, or > 1. However, we use
    72                                  ;  ours here as 8 independent flags that can be set individually.
    73                                  
    74                                  ; THE FOLLOWING LABEL DEFINES THE END OF THE AT ROM PATCH.  THIS IS USED AT
    75                                  ; CONFIGURATION TIME.
    76                                  ;J.K. 10/2/86 Warning!!! This code will be dynamically relocated by MSINIT.
    77                                  
    78                                  	PUBLIC	ENDATROM		;NOT REFERENCES EXTERNALLY, BUT
    79                                  					; JUST TO CAUSE ENTRY IN LINK MAP
    80                                  ENDATROM LABEL	BYTE
    81                                  
    82                                  
    83                                  usesection BIOCODE
    84                                  
    85                                  ;CMOS Clock setting support routines used by MSCLOCK.
    86                                  
    87                                  	EXTRN	base_century:byte
    88                                  	EXTRN	base_year:byte
    89                                  	EXTRN	month_tab:byte
    90                                  
    91                                  	public	near_daycnt_to_day	;J.K. 4/30/86 for real time clock support
    92                                  near_daycnt_to_day	proc	near	;J.K. 4/30/86 for real time clock support
    93                                  ;Entry: [DAYCNT] = number of days since 1-1-80
    94                                  ;Return: CH - centry in BCD, CL - year in BCD, DH - month in BCD, DL - day in BCD
    95                                  
    96                                   assume ds:nothing, es:nothing, ss:nothing
    97 00000000 1E                      	push ds
    98 00000001 E8(0000)                	call biocode_get_ds_dosbiodata
    99                                   assume ds:DOSGROUP
   100                                  
   101                                  daycnt equ DAYCNT	; NASM port label
   102 00000004 FF36[0000]              	push	word [daycnt]		;save daycnt
   103 00000008 813E[0000]891C          	cmp	word [daycnt], (365*20+(20/4)) ;# of days from 1-1-1980 to 1-1-2000
   104 0000000E 730C                    	jae	century20
   105 00000010 C606[0000]13            	mov	byte [base_century], 19
   106 00000015 C606[0000]50            	mov	byte [base_year], 80
   107 0000001A EB10                    	jmp	years
   108                                  century20:				;20th century
   109 0000001C C606[0000]14            	mov	byte [base_century], 20
   110 00000021 C606[0000]00            	mov	byte [base_year], 0
   111 00000026 812E[0000]891C          	sub	word [daycnt], (365*20+(20/4)) ;adjust daycnt
   112                                  years:
   113 0000002C 31D2                    	xor	dx, dx
   114 0000002E A1[0000]                	mov	ax, [daycnt]
   115 00000031 BBB505                  	mov	bx, (366+365*3) 	;# of days in a Leap year block
   116 00000034 F7F3                    	div	bx			;AX = # of leap block, DX = daycnt
   117 00000036 8916[0000]              	mov	[daycnt], dx		;save daycnt left
   118                                  ;	or	ah, ah			;ax should be less than 256
   119                                  ;	jz	OK1
   120                                  ;	 jmp	 Erroroccur
   121                                  ;OK1:
   122 0000003A B304                    	mov	bl,4
   123 0000003C F6E3                    	mul	bl			;AX = # of years. Less than 100 years!
   124 0000003E 0006[0000]              	add	[base_year], al		;So, ah = 0. Adjust year accordingly.
   125 00000042 FF06[0000]              	inc	word [daycnt]			;set daycnt to 1 base
   126 00000046 813E[0000]6E01          	cmp	word [daycnt], 366		;the daycnt here is the remainder of the leap year block.
   127 0000004C 7621                    	jbe	Leapyear		;So, it should within 366+355+355+355 days.
   128 0000004E FE06[0000]              	inc	byte [base_year]		;First if daycnt <= 366, then leap year
   129 00000052 812E[0000]6E01          	sub	word [daycnt], 366		;else daycnt--, base_year++;
   130                                  					;And the next three years are regular years.
   131 00000058 B90300                  	mov	cx, 3
   132                                  Regularyear:
   133 0000005B 813E[0000]6D01          	cmp	word [daycnt], 365		;for(i=1; i>3 or daycnt <=365;i++)
   134                                  YearDone equ Yeardone	; NASM port label
   135 00000061 7611                    	jbe	YearDone		;{if (daycnt > 365)
   136 00000063 FE06[0000]              	inc	byte [base_year]		;  { daycnt -= 365
   137 00000067 812E[0000]6D01          	sub	word [daycnt], 365		;  }
   138                                  regularyear equ Regularyear	; NASM port label
   139 0000006D E2EC                    	loop	regularyear		;}
   140                                  ;	 jmp	 Erroroccur		 ;cannot come to here
   141                                  Leapyear:
   142 0000006F C606[0100]1D            	mov	byte [month_tab+1],29 ;leap year. change the month table.
   143                                  Yeardone:
   144 00000074 31DB                    	xor	bx,bx
   145 00000076 31D2                    	xor	dx,dx
   146 00000078 A1[0000]                	mov	ax, [daycnt]
   147 0000007B BE[0000]                	mov	si, offset month_tab
   148 0000007E B90C00                  	mov	cx, 12
   149                                  Months:
   150 00000081 FEC3                    	inc	bl			;
   151 00000083 8A14                    	mov	dl, byte ptr [si]	;compare daycnt for each month until fits
   152 00000085 39D0                    	cmp	ax, dx			;dh=0.
   153 00000087 7605                    	jbe	Month_done
   154 00000089 46                      	inc	si			;next month
   155 0000008A 29D0                    	sub	ax, dx			;adjust daycnt
   156 0000008C E2F3                    	loop	Months
   157                                  ;	 jmp	 Erroroccur
   158                                  Month_done:
   159 0000008E C606[0100]1C            	mov	byte [month_tab+1], 28 ;restore month table value
   160 00000093 88DA                    	mov	dl, bl
   161 00000095 8A36[0000]              	mov	dh, [base_year]
   162 00000099 8A0E[0000]              	mov	cl, [base_century]	;now, al=day, dl=month,dh=year,cl=century
   163 0000009D E81700                  	call	near_bin_to_bcd		; convert "day" to bcd
   164 000000A0 86D0                    	xchg	dl, al			;dl = bcd day, al = month
   165 000000A2 E81200                  	call	near_bin_to_bcd
   166 000000A5 86F0                    	xchg	dh, al			;dh = bcd month, al = year
   167 000000A7 E80D00                  	call	near_bin_to_bcd
   168 000000AA 86C8                    	xchg	cl, al			;cl = bcd year, al = century
   169 000000AC E80800                  	call	near_bin_to_bcd
   170 000000AF 88C5                    	mov	ch, al			;ch = bcd century
   171 000000B1 8F06[0000]              	pop	word [daycnt]		;restore original value
   172 000000B5 1F                      	pop ds
   173                                   assume ds:nothing
   174 000000B6 C3                      	ret
   175                                  near_daycnt_to_day	endp
   176                                  
   177                                  	public	near_bin_to_bcd
   178                                  near_bin_to_bcd	proc	near		;J.K. 4/30/86 for real time clock support
   179                                  ;Convert a binary input in AL (less than 63h or 99 decimal)
   180                                  ;into a bcd value in AL.  AH destroyed.
   181 000000B7 51                      	push	cx
   182 000000B8 30E4                    	xor	ah, ah
   183 000000BA B10A                    	mov	cl, 10
   184 000000BC F6F1                    	div	cl		;al - high digit for bcd, ah - low digit for bcd
   185 000000BE B104                    	mov	cl, 4
   186 000000C0 D2E0                    	shl	al, cl		;mov the high digit to high nibble
   187 000000C2 08E0                    	or	al, ah
   188 000000C4 59                      	pop	cx
   189 000000C5 C3                      	ret
   190                                  near_bin_to_bcd	endp
   191                                  
   192                                  	EXTRN  BIN_DATE_TIME:BYTE
   193                                  	EXTRN  MONTH_TABLE:WORD
   194                                  	EXTRN  DAYCNT2:WORD
   195                                  	EXTRN  FEB29:BYTE
   196                                  	EXTRN  TimeToTicks:Word 	;indirect intra-segment call address
   197                                  
   198                                  ;
   199                                  ; THE K09 REQUIRES THE ROUTINES FOR READING THE CLOCK BECAUSE OF THE SUSPEND/
   200                                  ; RESUME FACILITY. THE SYSTEM CLOCK NEEDS TO BE RESET AFTER RESUME.
   201                                  ;
   202                                  
   203                                  ; THE FOLLOWING ROUTINE IS EXECUTED AT RESUME TIME WHEN THE SYSTEM
   204                                  ; POWERED ON AFTER SUSPENSION. IT READS THE REAL TIME CLOCK AND
   205                                  ; RESETS THE SYSTEM TIME AND DATE, AND THEN IRETS.
   206                                  
   207                                  relocated i6C
   208                                  INT6C	PROC	FAR
   209                                   assume ds:nothing, es:nothing, ss:nothing
   210 000000C6 E8(0000)                	call biocode_get_ds_dosbiodata
   211                                   assume ds:DOSGROUP
   212                                  
   213 000000C9 E80C00                  	CALL	near_read_real_date	; GET THE DATE FROM THE CLOCK
   214 000000CC 8936[0000]              	MOV	[DAYCNT],SI		; UPDATE DOS COPY OF DATE
   215 000000D0 E8BC00                  	CALL	near_read_real_time	; GET THE TIME FROM THE RTC
   216                                  ;SB33019***************************************************************
   217 000000D3 B401                    	MOV	AH, 01h 		; COMMAND TO SET THE TIME      ;SB;3.30
   218 000000D5 CD1A                    	INT	1Ah			; CALL ROM-BIOS TIME ROUTINE   ;SB;3.30
   219                                  ;SB33019***************************************************************
   220 000000D7 CF                      	iret
   221                                  
   222                                  INT6C	ENDP
   223                                  
   224                                  
   225                                  ;=== Push trace listing source: readcloc.nas
   226                                  	%include "readcloc.nas" ; NASM included file
     1                              <1> ;	SCCSID = @(#)readclock.asm	1.2 85/07/25
     2                              <1> ;************************************************************************
     3                              <1> ;
     4                              <1> ;   read_real_date reads real-time clock for date and returns the number
     5                              <1> ;   of days elapsed since 1-1-80 in si
     6                              <1> ;
     7                              <1> 		; INP:	ds => DOSBIODATA
     8                              <1> near_read_real_date: 		;mjb002
     9                              <1>  assume ds:DOSGROUP, es:nothing, ss:nothing
    10 000000D8 50                  <1> 	PUSH	AX
    11 000000D9 51                  <1> 	PUSH	CX
    12 000000DA 52                  <1> 	PUSH	DX
    13 000000DB 30E4                <1> 	XOR	AH,AH			; throw away clock roll over  ;3.30*
    14 000000DD CD1A                <1> 	INT	1AH						      ;3.30*
    15 000000DF 5A                  <1> 	POP	DX
    16 000000E0 59                  <1> 	POP	CX
    17 000000E1 58                  <1> 	POP	AX
    18                              <1> 
    19 000000E2 50                  <1> 	PUSH	AX
    20 000000E3 53                  <1> 	PUSH	BX
    21 000000E4 51                  <1> 	PUSH	CX
    22 000000E5 52                  <1> 	PUSH	DX
    23 000000E6 C706[0000]0100      <1> 	MOV	word [DAYCNT2],1	 ;MJB002 REAL TIME CLOCK ERROR FLAG (+1 DA;3.30Y)
    24 000000EC B404                <1> 	mov	ah,4		;mjb002 read date function code       ;3.30*
    25 000000EE CD1A                <1> 	int	1ah		;mjb002 read real-time clock	      ;3.30*
    26 000000F0 7303                <1> 	jnc	.read_ok	;mjb002 jmp success
    27 000000F2 E98B00              <1> 	jmp	r_d_ret		;mjb002 jmp error
    28                              <1> .read_ok:			;mjb002 ******* get bcd values in binary *****
    29                              <1> bin_date_time equ BIN_DATE_TIME	; NASM port label
    30 000000F5 882E[0000]          <1> 	mov	byte ptr [bin_date_time+0],ch  ;mjb002 store as hex value
    31 000000F9 880E[0100]          <1> 	mov	byte ptr [bin_date_time+1],cl  ;mjb002 ...
    32 000000FD 8836[0200]          <1> 	mov	byte ptr [bin_date_time+2],dh  ;mjb002 ...
    33 00000101 8816[0300]          <1> 	mov	byte ptr [bin_date_time+3],dl  ;mjb002 ...
    34 00000105 C706[0000]0200      <1> 	MOV	word [DAYCNT2],2	 ;MJB002 READ OF R-T CLOCK SUCCESSFUL	  ;3.30
    35 0000010B E84B01              <1> 	call	bcd_verify	;mjb002 verify bcd values in range
    36 0000010E 7270                <1> 	jc	r_d_ret 	;mjb002 jmp some value out of range
    37 00000110 C706[0000]0300      <1> 	MOV	word [DAYCNT2],3	 ;MJB002 READ OF R-T CLOCK SUCCESSFUL	  ;3.30
    38 00000116 E8E900              <1> 	call	date_verify	;mjb002 verify date values in range
    39 00000119 7265                <1> 	jc	r_d_ret 	;mjb002 jmp some value out of range
    40 0000011B C706[0000]0000      <1> 	MOV	word [DAYCNT2],0	 ;MJB002 VERIFY SUCCESSFUL		  ;3.30;3.30
    41 00000121 E8A300              <1> 	call	in_bin		;mjb002 convert date to binary
    42                              <1> 				;mjb002 ******* years since 1-1-80 *********
    43 00000124 A0[0100]            <1> 	mov	al,byte ptr [bin_date_time+1]  ;mjb002 get years into century
    44 00000127 98                  <1> 	cbw				     ;mjb002
    45 00000128 803E[0000]14        <1> 	cmp	byte [bin_date_time+0],20  ;mjb002 20th century?
    46 0000012D 7503                <1> 	jnz	century_19		     ;mjb002 jmp no
    47 0000012F 83C064              <1> 	add	ax,100		;mjb002 add in a century
    48                              <1> century_19:			;mjb002
    49 00000132 83E850              <1> 	sub	ax,80		;mjb002 subtract off 1-1-80
    50 00000135 B104                <1> 	mov	cl,4		;mjb002 leap year every 4
    51 00000137 F6F1                <1> 	div	cl		;mjb002 al= # leap year blocks, ah= remainder
    52 00000139 88E3                <1> 	mov	bl,ah		;mjb002 save odd years
    53 0000013B 98                  <1> 	cbw			;mjb002 zero ah
    54 0000013C B9B505              <1> 	mov	cx,366+3*365	;mjb002 # of days in leap year blocks
    55 0000013F F7E1                <1> 	mul	cx		;mjb002 dx:ax is result
    56 00000141 A3[0000]            <1> 	MOV	[DAYCNT2],AX	 ;MJB002 SAVE COUNT OF DAYS		  ;3.30
    57 00000144 88D8                <1> 	mov	al,bl		;mjb002 get odd years count
    58 00000146 98                  <1> 	cbw			;mjb002
    59 00000147 09C0                <1> 	or	ax,ax		;mjb002 is ax= 0?
    60 00000149 740B                <1> 	jz	leap_year	;mjb002 jmp if none
    61 0000014B B96D01              <1> 	mov	cx,365		;mjb002 days in year
    62 0000014E F7E1                <1> 	mul	cx		;mjb002 dx:ax is result
    63 00000150 0106[0000]          <1> 	ADD	[DAYCNT2],AX	 ;MJB002 ADD ON DAYS IN ODD YEARS	  ;3.30
    64 00000154 EB07                <1> 	jmp	short leap_adjustment	;mjb002 account for leap year
    65                              <1> leap_year:			;mjb002 possibly account for a leap day
    66 00000156 803E[0200]02        <1> 	cmp	byte [bin_date_time+2],2   ;mjb002 is month february
    67 0000015B 7604                <1> 	jbe	no_leap_adjustment  ;mjb002 jan or feb. no leap day yet.
    68                              <1> leap_adjustment:		;mjb002 account for leap day
    69 0000015D FF06[0000]          <1> 	INC	word [DAYCNT2]	 ;MJB002 ...				  ;3.30
    70                              <1> no_leap_adjustment:		;mjb002 ******* get days of month *******
    71 00000161 8A0E[0300]          <1> 	mov	cl,byte ptr [bin_date_time+3]    ;mjb002 ...
    72 00000165 30ED                <1> 	xor	ch,ch		;mjb002
    73 00000167 49                  <1> 	dec	cx		;mjb002 because of offset from day 1, not day 0
    74 00000168 010E[0000]          <1> 	ADD	[DAYCNT2],CX	 ;MJB002 ******* GET DAYS IN MONTHS PRECEE;3.30DING *****
    75 0000016C 8A0E[0200]          <1> 	mov	cl,byte ptr [bin_date_time+2]   ;mjb002 get month
    76 00000170 30ED                <1> 	xor	ch,ch		;mjb002
    77 00000172 49                  <1> 	dec	cx		;mjb002 january starts at offset 0
    78 00000173 D1E1                <1> 	shl	cx,1		;mjb002 word offset
    79                              <1> month_table equ MONTH_TABLE	; NASM port label
    80 00000175 BE[0000]            <1> 	mov	si,offset month_table	;mjb002 beginning of month_table
    81 00000178 01CE                <1> 	add	si,cx		;mjb002 point into month table
    82 0000017A 8B04                <1> 	mov	ax,word ptr [si];mjb002 get # days in previous months
    83 0000017C 0106[0000]          <1> 	ADD	[DAYCNT2],AX	 ;MJB002 ...				  ;3.30
    84                              <1> r_d_ret:			;mjb002
    85 00000180 8B36[0000]          <1> 	MOV	SI,[DAYCNT2]	 ;MJB002 RESULT IN SI			  ;3.30
    86 00000184 5A                  <1> 	POP	DX
    87 00000185 59                  <1> 	POP	CX
    88 00000186 5B                  <1> 	POP	BX
    89 00000187 58                  <1> 	POP	AX
    90 00000188 C3                  <1> 	ret			;mjb002
    91                              <1> 
    92                              <1> r_t_retj:
    93 00000189 31C9                <1> 	xor	cx,cx
    94 0000018B 31D2                <1> 	xor	dx,dx
    95 0000018D EB37                <1> 	jmp	r_t_ret
    96                              <1> ;
    97                              <1> ; Read_Real_Time reads the time from the RTC. on exit, it has the number of
    98                              <1> ; ticks (at 18.2 ticks per sec.) in CX:DX.
    99                              <1> ;
   100                              <1> near_read_real_time:
   101                              <1>  assume ds:DOSGROUP, es:nothing, ss:nothing
   102 0000018F B402                <1> 	mov	ah,2						      ;3.30*
   103 00000191 CD1A                <1> 	int	1AH						      ;3.30*
   104 00000193 72F4                <1> 	jc	r_t_retj
   105                              <1> oktime:
   106 00000195 882E[0000]          <1> 	mov	byte ptr [bin_date_time],ch	; hours
   107 00000199 880E[0100]          <1> 	mov	byte ptr [bin_date_time+1],cl	; minutes
   108 0000019D 8836[0200]          <1> 	mov	byte ptr [bin_date_time+2],dh	; seconds
   109 000001A1 C606[0300]00        <1> 	mov	byte [bin_date_time+3],0	; unused for time
   110 000001A6 E8B000              <1> 	call	bcd_verify
   111 000001A9 72DE                <1> 	jc	r_t_retj
   112 000001AB E89200              <1> 	call	time_verify
   113 000001AE 72D9                <1> 	jc	r_t_retj
   114 000001B0 E81400              <1> 	call	in_bin
   115 000001B3 8A2E[0000]          <1> 	MOV	ch,byte ptr [bin_date_time]
   116 000001B7 8A0E[0100]          <1> 	MOV	cl,byte ptr [bin_date_time+1]
   117 000001BB 8A36[0200]          <1> 	MOV	dh,byte PTR [bin_date_time+2]
   118 000001BF 8A16[0300]          <1> 	MOV	dl,byte PTR [bin_date_time+3]
   119                              <1> 	message ftestinit,<"Read Time   ">
   120                              <1> 	mnum	ftestinit,cx
   121                              <1> 	message ftestinit,<"  ">
   122                              <1> 	mnum	ftestinit,dx
   123                              <1> 	message ftestinit,<cr,lf>
   124                              <1> ; get time in ticks in CX:DX
   125                              <1>  extern near_time_to_ticks
   126 000001C3 E8(0000)            <1> 	CALL	near_time_to_ticks	;3.30
   127                              <1> 	message ftestinit,<"Conv Time   ">
   128                              <1> 	mnum	ftestinit,cx
   129                              <1> 	message ftestinit,<"  ">
   130                              <1> 	mnum	ftestinit,dx
   131                              <1> 	message ftestinit,<cr,lf>
   132                              <1> r_t_ret:
   133 000001C6 C3                  <1> 	ret
   134                              <1> 
   135                              <1> ;
   136                              <1> ;   in_bin converts bin_date_time values from bcd to bin
   137                              <1> ;
   138                              <1> in_bin: 				     ;mjb002
   139                              <1>  assume ds:DOSGROUP, es:nothing, ss:nothing
   140 000001C7 A0[0000]            <1> 	mov	al,byte ptr [bin_date_time+0]  ; century or hours
   141 000001CA E81F00              <1> 	call	bcd_to_bin		     ; ...
   142 000001CD A2[0000]            <1> 	mov	byte ptr [bin_date_time+0],al  ;
   143 000001D0 A0[0100]            <1> 	mov	al,byte ptr [bin_date_time+1]  ; years or minutes
   144 000001D3 E81600              <1> 	call	bcd_to_bin		     ; ...
   145 000001D6 A2[0100]            <1> 	mov	byte ptr [bin_date_time+1],al  ;
   146 000001D9 A0[0200]            <1> 	mov	al,byte ptr [bin_date_time+2]  ; months or seconds
   147 000001DC E80D00              <1> 	call	bcd_to_bin		     ; ...
   148 000001DF A2[0200]            <1> 	mov	byte ptr [bin_date_time+2],al  ;
   149 000001E2 A0[0300]            <1> 	mov	al,byte ptr [bin_date_time+3]  ; days (not used for time)
   150 000001E5 E80400              <1> 	call	bcd_to_bin		     ; ...
   151 000001E8 A2[0300]            <1> 	mov	byte ptr [bin_date_time+3],al  ;
   152 000001EB C3                  <1> 	ret				     ;
   153                              <1> ;
   154                              <1> ;   bcd_to_bin converts two bcd nibbles in al (value <= 99.) to
   155                              <1> ;   a binary representation in al
   156                              <1> ;   ah is destroyed
   157                              <1> ;
   158                              <1> bcd_to_bin:			;mjb002
   159                              <1>  assume ds:nothing, es:nothing, ss:nothing
   160 000001EC 88C4                <1> 	mov	ah,al		;mjb002 copy bcd number to ah
   161 000001EE 250FF0              <1> 	and	ax,0f00fh	;mjb002 clear unwanted nibbles
   162 000001F1 88C3                <1> 	mov	bl,al		;mjb002 save units place
   163 000001F3 86E0                <1> 	xchg	ah,al		;mjb002 10's place to al
   164 000001F5 30E4                <1> 	xor	ah,ah		;mjb002 ah not wanted
   165 000001F7 B104                <1> 	mov	cl,4		;mjb002 shift count
   166 000001F9 D3E8                <1> 	shr	ax,cl		;mjb004 swap nibbles
   167 000001FB B10A                <1> 	mov	cl,10		;mjb002 convert al to ...
   168 000001FD F6E1                <1> 	mul	cl		;mjb002 ... its binary value
   169 000001FF 00D8                <1> 	add	al,bl		;mjb002 add in units
   170 00000201 C3                  <1> 	ret			;mjb002
   227                                  ;=== Pop trace listing source
   228                                  ;=== Push trace listing source: clocksub.nas
   229                                  	%include "clocksub.nas" ; NASM included file
     1                              <1> ;
     2                              <1> ;   date_verify loosely checks bcd date values to be in range in bin_date_time
     3                              <1> ;
     4                              <1> date_verify:				    ;
     5                              <1> assume	ds:DOSGROUP,es:nothing,ss:nothing
     6 00000202 803E[0000]20        <1> 	cmp	byte [bin_date_time+0],20h  ; century check
     7 00000207 7735                <1> 	ja	date_error		    ; jmp error
     8 00000209 740E                <1> 	jz	century_20		    ; jmp in 20th century
     9 0000020B 803E[0000]19        <1> 	cmp	byte [bin_date_time+0],19h  ; century check
    10 00000210 722C                <1> 	jb	date_error		    ; jmp error
    11 00000212 803E[0100]80        <1> 	cmp	byte [bin_date_time+1],80h  ; year check
    12 00000217 7225                <1> 	jb	date_error		    ; jmp error
    13                              <1> century_20:				    ;
    14 00000219 803E[0100]99        <1> 	cmp	byte [bin_date_time+1],99h  ; year check
    15 0000021E 771E                <1> 	ja	date_error		    ; jmp error
    16 00000220 803E[0200]12        <1> 	cmp	byte [bin_date_time+2],12h  ; month check
    17 00000225 7717                <1> 	ja	date_error		    ; jmp error
    18 00000227 803E[0200]00        <1> 	cmp	byte [bin_date_time+2],00h  ; month check
    19 0000022C 7610                <1> 	jbe	date_error		    ; jmp error
    20 0000022E 803E[0300]31        <1> 	cmp	byte [bin_date_time+3],31h  ; day check
    21 00000233 7709                <1> 	ja	date_error		    ; jmp error
    22 00000235 803E[0300]00        <1> 	cmp	byte [bin_date_time+3],00h  ; day check
    23 0000023A 7602                <1> 	jbe	date_error		    ; jmp error
    24 0000023C F8                  <1> 	clc				    ; set success flag
    25 0000023D C3                  <1> 	ret				    ;
    26                              <1> date_error:				    ;
    27 0000023E F9                  <1> 	stc				    ; set error flag
    28 0000023F C3                  <1> 	ret				    ;
    29                              <1> 
    30                              <1> ;
    31                              <1> ; time_verify very loosely checks bcd date values to be in range in bin_date_time
    32                              <1> ;
    33                              <1> time_verify:
    34                              <1> assume	ds:DOSGROUP,es:nothing,ss:nothing
    35 00000240 803E[0000]24        <1> 	cmp	byte [bin_date_time+0],24H
    36 00000245 7710                <1> 	ja	time_error
    37 00000247 803E[0100]59        <1> 	cmp	byte [bin_date_time+1],59H
    38 0000024C 7709                <1> 	ja	time_error
    39 0000024E 803E[0200]59        <1> 	cmp	byte [bin_date_time+2],59H
    40 00000253 7702                <1> 	ja	time_error
    41 00000255 F8                  <1> 	clc
    42 00000256 C3                  <1> 	ret
    43                              <1> time_error:
    44 00000257 F9                  <1> 	stc
    45 00000258 C3                  <1> 	ret
    46                              <1> 
    47                              <1> ;
    48                              <1> ;   bcd_verify checks values in bin_date_time to be valid
    49                              <1> ;   bcd numerals.  carry set if any nibble out of range
    50                              <1> ;
    51                              <1> bcd_verify:			;
    52                              <1> assume	ds:DOSGROUP,es:nothing,ss:nothing
    53 00000259 B90400              <1> 	mov	cx,4		; 4 bytes to check
    54 0000025C BB[0000]            <1> 	mov	bx,offset bin_date_time	; access with ds
    55                              <1> bv_loop:			;
    56 0000025F 8A07                <1> 	mov	al,[bx] 	; get a bcd number (0..99)
    57 00000261 88C4                <1> 	mov	ah,al		;
    58 00000263 250FF0              <1> 	and	ax,0f00fh	; 10's place in high ah, 1's in al
    59 00000266 3C0A                <1> 	cmp	al,10		; is 1's place in range?
    60 00000268 7716                <1> 	ja	bv_error	; jmp out of range
    61 0000026A D0EC                <1> 	shr	ah,1		; swap nibbles
    62 0000026C D0EC                <1> 	shr	ah,1		; ...
    63 0000026E D0EC                <1> 	shr	ah,1		; ...
    64 00000270 D0EC                <1> 	shr	ah,1		; ...
    65 00000272 80E40F              <1> 	and	ah,0fh		; get rid of any erroneous bits
    66 00000275 80FC0A              <1> 	cmp	ah,10		; is 10's place in range
    67 00000278 7706                <1> 	ja	bv_error	; jmp out of range
    68 0000027A 43                  <1> 	inc	bx		; next byte
    69 0000027B 49                  <1> 	dec	cx		;
    70 0000027C 75E1                <1> 	jnz	bv_loop 	;
    71 0000027E F8                  <1> 	clc			; set success flag
    72 0000027F C3                  <1> 	ret			;
    73                              <1> bv_error:			;
    74 00000280 F9                  <1> 	stc			; set error flag
    75 00000281 C3                  <1> 	ret			;
    76                              <1> ;
    77                              <1> ; Dos 3.30 - The real time clock structures were moved to msbio2.asm
    78                              <1> ;
   230                                  ;=== Pop trace listing source
   231                                  
   232                                  
   233                                  	usesection DOSENTRYINIT
   234                                  
   235                                  ;*********************************************************
   236                                  ;	SYSTEM INITIALIZATION
   237                                  ;
   238                                  ;	THE ENTRY CONDITIONS ARE ESTABLISHED BY THE BOOTSTRAP
   239                                  ;	LOADER AND ARE CONSIDERED UNKNOWN. THE FOLLOWING JOBS
   240                                  ;	WILL BE PERFORMED BY THIS MODULE:
   241                                  ;
   242                                  ;	1.	ALL DEVICE INITIALIZATION IS PERFORMED
   243                                  ;	2.	A LOCAL STACK IS SET UP AND DS:SI ARE SET
   244                                  ;		TO POINT TO AN INITIALIZATION TABLE. THEN
   245                                  ;		AN INTER-SEGMENT CALL IS MADE TO THE FIRST
   246                                  ;		BYTE OF THE DOS
   247                                  ;	3.	ONCE THE DOS RETURNS FROM THIS CALL THE DS
   248                                  ;		REGISTER HAS BEEN SET UP TO POINT TO THE START
   249                                  ;		OF FREE MEMORY. THE INITIALIZATION WILL THEN
   250                                  ;		LOAD THE COMMAND PROGRAM INTO THIS AREA
   251                                  ;		BEGINNING AT 100 HEX AND TRANSFER CONTROL TO
   252                                  ;		THIS PROGRAM.
   253                                  ;
   254                                  ;********************************************************
   255                                  
   256                                  ; FIRST LOCATION OF FREEABLE SPACE (?)
   257                                  ; This is the same offset in DOSENTRY as ENDATROM.
   258                                  	EVENB
   259 00000000 00                      checkdebugger:	db 0
   260                                  
   261                                  addsection DOSDATAMCB, PUBLIC class=DOSDATAMCB align=16
   262                                  addsection SYSINITMCB, PUBLIC class=SYSINITMCB align=16
   263                                  addsection SYSINITSEG, PUBLIC class=INIT
   264                                  addsection SYSINITTRAIL, PUBLIC class=INIT align=2
   265                                  addsection SYSINITLAST, PUBLIC class=INIT align=2
   266                                  
   267                                  group SYSINITGROUP SYSINITSEG SYSINITTRAIL SYSINITLAST
   268                                  
   269                                  usesection SYSINITTRAIL
   270                                  
   271                                  	align 2, db 0
   272 00000000 00000000                nextupb:	dd 0
   273                                  auxbuff_segorsel:
   274 00000004 ????                    Init_BootSeg:	dw ?			; seg addr of buffer for reading boot record
   275 00000006 00                      FakeFloppyDrv:	db 0			; If 1, then No diskette drives in the system.
   276 00000007 00                      FBIGFAT:	db 0			; FLAGS FOR DRIVE
   277                                  
   278                                  	evenb
   279                                  BDS_diskette_template:
   280 00000008 FFFFFFFF                	dw	-1, -1			;LINK TO NEXT STRUCTURE
   281 0000000C 00                      	DB	0			;INT 13 DRIVE NUMBER
   282 0000000D 00                      	DB	0			;LOGICAL DRIVE LETTER
   283 0000000E 0002                    	DW	512			;PHYSICAL SECTOR SIZE IN BYTES
   284 00000010 FF                      	DB	-1			;SECTORS/ALLOCATION UNIT
   285 00000011 0100                    	DW	1			;RESERVED SECTORS FOR DOS
   286 00000013 02                      	DB	2			;NO. ALLOCATION TABLES
   287 00000014 4000                    	DW	64			;NUMBER DIRECTORY ENTRIES
   288 00000016 6801                    	DW	9*40			;NUMBER SECTORS (AT 512 BYTES EA.)
   289 00000018 00                      	DB	00000000B		;MEDIA DESCRIPTOR, INITIALLY 00H.
   290 00000019 0200                    	DW	2			;NUMBER OF FAT SECTORS
   291 0000001B 0900                    	DW	9			;SECTOR LIMIT
   292 0000001D 0100                    	DW	1			;HEAD LIMIT
   293 0000001F 0000                    	DW	0			;HIDDEN SECTOR COUNT (low word)
   294 00000021 0000                    	dw	0			;J.K. Hidden sector (high)
   295 00000023 0000                    	dw	0			;J.K. Number sectors (low)
   296 00000025 0000                    	dw	0			;J.K. Number sectors (high)
   297 00000027 00                      	DB	0			; TRUE => LARGE FATS
   298 00000028 0000                    	DW	0			;OPEN REF. COUNT
   299                                  
   300 0000002A 03                      	DB	3			;FORM FACTOR
   301 0000002B 2000                    	DW	0020H			;VARIOUS FLAGS
   302                                  ;	DB	9 DUP (0)		;RESERVED FOR FUTURE USE
   303 0000002D 2800                    	DW	40			; NUMBER OF CYLINDERS
   304                                  ; RECOMMENDED BPB FOR DRIVE.
   305 0000002F 0002                    	DW	512			;BYTES PER SECTOR
   306 00000031 01                      	DB	1			;SECTORS/ALLOCATION UNIT
   307 00000032 0100                    	DW	1			;RESERVED SECTORS FOR DOS
   308 00000034 02                      	DB	2			;NO. ALLOCATION TABLES
   309 00000035 E000                    	DW	0E0H			;NUMBER DIRECTORY ENTRIES
   310 00000037 6801                    	DW	9*40			;NUMBER SECTORS (AT 512 BYTES EA.)
   311 00000039 F0                      	DB	0F0H			;MEDIA DESCRIPTOR, INITIALLY F0H.
   312 0000003A 0200                    	DW	2			;NUMBER OF FAT SECTORS
   313 0000003C 0900                    	DW	9			;SECTOR LIMIT
   314 0000003E 0200                    	DW	2			;HEAD LIMIT
   315 00000040 0000                    	DW	0			;HIDDEN SECTOR COUNT(low)
   316 00000042 0000                    	dw	0			;J.K. Hidden sector count (high)
   317 00000044 0000                    	dw	0			;J.K. Number sectors (low)
   318 00000046 0000                    	dw	0			;J.K. Number sectors (high)
   319 00000048 ????????????            	DB	6 DUP (?)
   320 0000004E FF                      	DB	-1			;LAST TRACK ACCESSED ON THIS DRIVE
   321 0000004F FFFF                    	DW	-1			;KEEP THESE TWO CONTIGUOUS (?)
   322 00000051 FFFF                    	DW	-1
   323 00000053 4E4F204E414D452020-     	DB	"NO NAME    ",0         ;VOLUME ID FOR THIS DISK
   323 0000005C 202000             
   324 0000005F 00000000                	dd	0	     ;Current volume serial number from Boot record
   325 00000063 464154313220202000      	db	"FAT12   ",0 ;Current file system id from Boot record
   326                                  
   327                                  	evenb
   328                                  ; THE FOLLOWING TWO BYTES ARE USED TO SAVE THE INFO RETURNED BY INT 13, AH = 8
   329                                  ; CALL TO DETERMINE DRIVE PARAMETERS.
   330 0000006C 0200                    NUM_HEADS dw	2			; NUMBER OF HEADS RETURNED BY ROM
   331 0000006E 09                      SEC_TRK   DB	9			; SEC/TRK RETURNED BY ROM
   332 0000006F 28                      NUM_CYLN  DB	40			; NUMBER OF CYLINDERS RETURNED BY ROM
   333                                  
   334                                  
   335                                  EXT_BOOT_SIG_OFF equ 11+BPB_TYPE_struc_size ;AN000; 3 byte jmp+8 byte OEM +extended bpb
   336                                  
   337                                  
   338                                  	EVENB
   339 00000070 0002000140000000        DISKTABLE DW	512,	0100H,	64,	0
   340 00000078 0008010270000000        	DW	2048,	0201H,	112,	0
   341 00000080 0020020400010000        	DW	8192,	0402H,	256,	0
   342 00000088 A87F030800020000        	DW	32680,	0803H,	512,	0      ;Warning !!! Old values
   343                                  ;	DW	20740,	0803H,	 512,	0	;PTM P892 J.K. 12/3/86 DOS 3.3 will use this.
   344                                  						;J.K.3/16/87 P54 Return back to old value for compatibility.!!!
   345 00000090 FFFF041000040000        	DW	65535,	1004H,	1024,	0
   346                                  
   347                                  ;DISKTABLE2 DW	 32680,  0803H,  512,	 0	;Warning !!! Old values  ;J.K.3/16/87 P54 Return to old value!!!
   348                                  ;DISKTABLE2 DW	 20740,  0803H,  512,	 0	 ;PTM p892 J.K. 12/3/86 DOS 3.3 will use this.
   349                                  ;	 DW	 65535,  0402H,  512,	 FBIG
   350                                  ;AN000;
   351                                  ;DISKTABLE2 dw	 0, 32680, 0803h, 512, 0	 ;table with the assumption of the
   352                                  ;	    dw	2h, 0000h, 0402h, 512, FBIG	 ;total fat size <= 64KB.
   353                                  ;	    dw	4h, 0000h, 0803h, 512, FBIG	 ;-This will cover upto 134 MB
   354                                  ;	    dw	8h, 0000h, 1004h, 512, FBIG	 ;-This will cover upto 268 MB
   355                                  ;	    dw 10h, 0000h, 2005h, 512, FBIG	 ;-This will cover upto 536 MB
   356                                  
   357                                  ;AN004 Default DiskTable under the assumption of Total FAT size <= 128 KB, and
   358                                  ;	the maxium size of FAT entry = 16 Bit.
   359 00000098 0000A87F0308000200-     DiskTable2  dw	 0, 32680, 0803h, 512, 0	;For compatibility.
   359 000000A1 00                 
   360 000000A2 040000000204000240-     	    dw	4h, 0000h, 0402h, 512, FBIG	;Covers upto 134 MB media.
   360 000000AB 00                 
   361 000000AC 080000000308000240-     	    dw	8h, 0000h, 0803h, 512, FBIG	;	upto 268 MB
   361 000000B5 00                 
   362 000000B6 100000000410000240-     	    dw 10h, 0000h, 1004h, 512, FBIG	;	upto 536 MB
   362 000000BF 00                 
   363 000000C0 200000000520000240-     	    dw 20h, 0000h, 2005h, 512, FBIG	;	upto 1072 MB
   363 000000C9 00                 
   364 000000CA 400000000640000240-     	    dw 40h, 0000h, 4006h, 512, FBIG	;	upto 2144 MB
   364 000000D3 00                 
   365 000000D4 800000000780000240-     	    dw 80h, 0000h, 8007h, 512, FBIG	;	upto 4288 MB...
   365 000000DD 00                 
   366                                  
   367                                  	align 2, db 0
   368 000000DE [E000]                  Mini_BPB_ptr	dw	DSKDRVS		;temporary variable used to save the
   369                                  					;Mini Disk BPB pointer address in DskDrvs.
   370 000000E0 0000<rep 20h>           DSKDRVS	times 32 dw 0
   371                                  .end:
   372 00000120 0000                    	dw 0				; allow overflowing entry
   373                                  
   374                                  
   375                                  usesection DOSENTRYINIT
   376                                  
   377 00000001 30312F31302F383400      BIOS_DATE DB	'01/10/84',0     ;This is used for checking AT ROM BIOS date.
   378                                  
   379                                  
   380                                  usesection SYSINITTRAIL
   381                                  
   382                                  ; THE FOLLOWING ARE THE RECOMMENDED BPBS FOR THE MEDIA THAT WE KNOW OF SO
   383                                  ; FAR.
   384                                  
   385                                  ; 48 TPI DISKETTES
   386                                  	EVENB
   387 00000122 0002                    BPB48T	DW	512
   388 00000124 02                      	DB	2
   389 00000125 0100                    	DW	1
   390 00000127 02                      	DB	2
   391 00000128 7000                    	DW	112
   392 0000012A D002                    	DW	2*9*40
   393 0000012C FD                      	DB	0FDH
   394 0000012D 0200                    	DW	2
   395 0000012F 0900                    	DW	9
   396 00000131 0200                    	DW	2
   397 00000133 0000                    	DW	0
   398 00000135 0000                    	dw	0		;AN000;  hidden sector High
   399 00000137 00000000                	dd	0		;AN000;  extended total sectors
   400                                  
   401                                  ; 96TPI DISKETTES
   402 0000013B 00                      	EVENB
   403 0000013C 0002                    BPB96T	DW	512
   404 0000013E 01                      	DB	1
   405 0000013F 0100                    	DW	1
   406 00000141 02                      	DB	2
   407 00000142 E000                    	DW	224
   408 00000144 6009                    	DW	2*15*80
   409 00000146 F9                      	DB	0F9H
   410 00000147 0700                    	DW	7
   411 00000149 0F00                    	DW	15
   412 0000014B 0200                    	DW	2
   413 0000014D 0000                    	DW	0
   414 0000014F 0000                    	dw	0		;AN000;  hidden sector High
   415 00000151 00000000                	dd	0		;AN000;  extended total sectors
   416                                  
   417                                  BPBSIZ	equ	$-BPB96T
   418                                  
   419                                  ; 3 1/2 INCH DISKETTE BPB
   420                                  
   421 00000155 00                      	EVENB
   422 00000156 0002                    BPB35	DW	512
   423 00000158 02                      	DB	2
   424 00000159 0100                    	DW	1			; DOUBLE SIDED WITH 9 SEC/TRK
   425 0000015B 02                      	DB	2
   426 0000015C 7000                    	DW	70h
   427 0000015E A005                    	DW	2*9*80
   428 00000160 F9                      	DB	0F9H
   429 00000161 0300                    	DW	3
   430 00000163 0900                    	DW	9
   431 00000165 0200                    	DW	2
   432 00000167 0000                    	DW	0
   433 00000169 0000                    	dw	0		;AN000;  hidden sector High
   434 0000016B 00000000                	dd	0		;AN000;  extended total sectors
   435                                  
   436 0000016F 00                      	EVENB
   437 00000170 [2201]                  BPBTABLE DW	BPB48T			; 48TPI DRIVES
   438 00000172 [3C01]                  	DW	BPB96T			; 96TPI DRIVES
   439 00000174 [5601]                  	DW	BPB35			; 3.5" DRIVES
   440                                  					;DW	 BPB48T 	     ; NOT USED - 8" DRIVES
   441                                  					;DW	 BPB48T 	     ; NOT USED - 8" DRIVES
   442                                  					;DW	 BPB48T 	     ; NOT USED - HARD FILES
   443                                  					;DW	 BPB48T 	     ; NOT USED - TAPE DRIVES
   444                                  					;DW	 BPB48T 	     ; NOT USED - OTHER
   445                                  
   446                                  	usesection DOSENTRYINIT
   447                                  
   448                                  %if 0
   449                                  	align 2, db 0
   450                                  PATCHTABLE LABEL BYTE
   451                                  	DW	10,MEDIA_PATCH
   452                                  	DW	3,GETBP1_PATCH
   453                                  	DW	3,SET_PATCH
   454                                  	DW	3,DISKIO_PATCH
   455                                  	DW	3,DSKERR_PATCH
   456                                  	DW	3,DSKERR_LBA_PATCH
   457                                  	DW	3,CHANGED_PATCH
   458                                  	DW	3,INIT_PATCH
   459                                  	DW	0
   460                                  %endif
   461                                  
   462                                  	ASSUME	DS:NOTHING,ES:NOTHING
   463                                  
   464                                  		; INP:	from lkernpl
   465                                  		;	cx:di -> lCFG block passed from drkernpl or inicomp
   466                                  		;	dl = load unit
   467                                  		;	ds:bp = ss:bp -> load partition boot sector with (E)BPB
   468                                  	PUBLIC	INIT
   469                                  INIT	PROC	NEAR
   470                                  	MESSAGE FTESTINIT,<"IBMBIO",CR,LF>
   471 0000000A FA                      	CLI
   472                                   assume ds:nothing, es:nothing, ss:nothing
   473                                  
   474                                  		; Get lCFG items to use later.
   475 0000000B 8EC1                    	mov es, cx
   476                                   assume es:nothing
   477 0000000D 268A4514                	mov al, byte [es:di + LCFG_CheckDebugger]
   478 00000011 2EA2[0000]              	mov byte [cs:checkdebugger], al
   479 00000015 26FF7515                	push word [es:di + LCFG_Verbose]
   480 00000019 26FF7516                	push word [es:di + LCFG_ScanMode]
   481 0000001D 26FF751A                	push word [es:di + LCFG_HaltFlag]
   482                                  
   483                                  		; init pointers needed by relocation (i13 etc)
   484 00000021 31C0                    	xor ax, ax
   485 00000023 8ED8                    	mov ds, ax
   486                                   assume ds:IVT
   487 00000025 B8[ssss]                	mov ax, DOSSTART
   488 00000028 A3C600                  	mov word [31h * 4 + 2], ax
   489 0000002B 8ED8                    	mov ds, ax
   490                                   assume ds:DOSGROUP
   491 0000002D C706[0000][ssss]        	mov word [dosdata_to_doscode], DOSCODEGROUP
   492 00000033 8F06[0000]              	pop word [haltflags]
   493 00000037 B8[ssss]                	mov ax, DOSENTRY
   494 0000003A 8ED8                    	mov ds, ax
   495                                   assume ds:DOSENTRYGROUP
   496                                  %if _RELOCATEDOSCODE
   497                                   extern ..@dosentry_doscode_segment
   498                                  	mov word [..@dosentry_doscode_segment], DOSCODEGROUP
   499                                  %endif
   500                                  
   501                                  
   502                                   extern sysinit_bootdrive_hidden, sysinit_bootdrive_unit
   503                                  
   504                                  init_bootdrive:
   505 0000003C B8[ssss]                	mov ax, SYSINITSEG
   506 0000003F 8EC0                    	mov es, ax			; modified to use ax
   507                                  					;  (preserve dl = load unit)
   508                                   assume es:SYSINITGROUP
   509 00000041 268F06[0000]            	pop word [es:load_mode]
   510                                   extern verbose_mode
   511 00000046 268F06[0000]            	pop word [es:verbose_mode]
   512                                  
   513 0000004B 8B461E                  	mov ax, word [bp + bsBPB + bpbHiddenSectors + 2]
   514 0000004E 26A3[0200]              	mov word [es:sysinit_bootdrive_hidden + 2], ax
   515 00000052 8B461C                  	mov ax, word [bp + bsBPB + bpbHiddenSectors]
   516 00000055 26A3[0000]              	mov word [es:sysinit_bootdrive_hidden], ax
   517 00000059 268816[0000]            	mov byte [es:sysinit_bootdrive_unit], dl
   518                                  
   519                                  
   520                                   extern kernelcommandline
   521                                   extern kernelcommandline.end
   522                                   extern commandnames
   523                                  
   524                                  		; copied from ecm contribution to FreeDOS kernel.asm
   525                                  initialise_command_line_buffer:
   526 0000005E 89E0                    	mov ax, sp			; ax = original sp
   527 00000060 16                      	push ss
   528 00000061 1F                      	pop ds
   529                                   assume ds:nothing
   530 00000062 89EE                    	mov si, bp			; ds:si = original ss:bp
   531                                  
   532                                  		; Note that the kernel command line buffer in
   533                                  		;  the init data segment is pre-initialised to
   534                                  		;  hold 0x00 0xFF in the first two bytes. This
   535                                  		;  is used to indicate no command line present,
   536                                  		;  as opposed to an empty command line which
   537                                  		;  will hold 0x00 0x00.
   538                                  		; If any of the branches to .none are taken then
   539                                  		;  the buffer is not modified so it retains the
   540                                  		;  0x00 0xFF contents.
   541 00000064 81FE1401                	cmp si, - lsvCommandLine.start	; buffer fits below ss:bp ?
   542 00000068 7222                    	jb .none			; no -->
   543 0000006A 817CEC434C              	cmp word [si + lsvCommandLine.signature], lsvclSignature
   544                                  					; signature passed to us ?
   545 0000006F 751B                    	jne .none			; no -->
   546 00000071 8DB4ECFE                	lea si, [si + lsvCommandLine.start]
   547                                  					; -> command line buffer
   548 00000075 39F0                    	cmp ax, si			; stack top starts below-or-equal buffer ?
   549 00000077 7713                    	ja .none			; no -->
   550 00000079 BF[0000]                	mov di, kernelcommandline	; our buffer
   551 0000007C B9FF00                  	mov cx, lsvclBufferLength - 1
   552 0000007F 31C0                    	xor ax, ax
   553 00000081 57                      	push di
   554 00000082 F3A4                    	rep movsb		; copy up to 255 bytes
   555 00000084 AA                      	stosb			; truncate
   556 00000085 5F                      	pop di
   557 00000086 B501                    	mov ch, 1		; cx = 256
   558 00000088 F2AE                    	repne scasb		; scan for terminator
   559 0000008A F3AA                    	rep stosb		; clear remainder of buffer
   560                                  				; (make sure we do not have 0x00 0xFF
   561                                  				;  even if the command line given is
   562                                  				;  actually the empty string)
   563                                  .none:
   564                                  
   565                                  
   566                                  init_cmdline_terminators:
   567 0000008C 06                      	push es
   568 0000008D 1F                      	pop ds
   569                                   assume ds:SYSINITGROUP
   570                                  
   571 0000008E BF[0000]                	mov di, kernelcommandline
   572 00000091 89FE                    	mov si, di
   573 00000093 B90001                  	mov cx, 256
   574 00000096 31C0                    	xor ax, ax
   575 00000098 F2AE                    	repne scasb
   576 0000009A 4F                      	dec di
   577 0000009B 893E[0000]              	mov word [kernelcommandline.end], di
   578 0000009F 89F7                    	mov di, si		; -> start
   579 000000A1 56                      	push si
   580                                  @@:
   581 000000A2 3B36[0000]              	cmp si, word [kernelcommandline.end]
   582 000000A6 7314                    	jae @F
   583 000000A8 AC                      	lodsb			; get text
   584 000000A9 AA                      	stosb			; store text
   585 000000AA 3C3B                    	cmp al, ';'		; was semicolon ?
   586 000000AC 75F4                    	jne @B			; no, loop -->
   587 000000AE 803C3B                  	cmp byte [si], ';'	; escaped ?
   588 000000B1 7406                    	je .escapesemicolon	; yes -->
   589 000000B3 C645FF00                	mov byte [di - 1], 0	; no, treat as terminator
   590 000000B7 EBE9                    	jmp @B
   591                                  
   592                                  .escapesemicolon:
   593 000000B9 46                      	inc si			; -> past next semicolon
   594 000000BA EBE6                    	jmp @B
   595                                  
   596                                  @@:
   597 000000BC A4                      	movsb			; copy the NUL
   598 000000BD 4F                      	dec di			; -> at the NUL
   599 000000BE 893E[0000]              	mov word [kernelcommandline.end], di
   600                                  				; update the end offset (<= before)
   601 000000C2 5E                      	pop si
   602                                  
   603                                  parse_config:
   604                                  .loopcommand:
   605 000000C3 A8                      	db __TEST_IMM8		; skip inc
   606                                  @@:
   607 000000C4 46                      	inc si
   608 000000C5 803C20                  	cmp byte [si], 32
   609 000000C8 74FA                    	je @B
   610 000000CA 803C09                  	cmp byte [si], 9
   611 000000CD 74F5                    	je @B
   612                                  
   613 000000CF 803C00                  	cmp byte [si], 0	; empty ?
   614 000000D2 7503E9A100              	je .donename		; yes -->
   615                                  
   616 000000D7 BF[0000]                	mov di, commandnames
   617                                  .loopname:
   618 000000DA 8B05                    	mov ax, [di]
   619 000000DC 40                      	inc ax
   620 000000DD 7435                    	jz .unknownname
   621 000000DF AF                      	scasw			; skip function pointer field
   622 000000E0 AF                      	scasw			; skip content field
   623 000000E1 56                      	push si
   624 000000E2 50                      	push ax
   625 000000E3 57                      	push di
   626 000000E4 8B3D                    	mov di, [di]
   627                                  .comparename:
   628 000000E6 AC                      	lodsb
   629 000000E7 3C00                    	cmp al, 0
   630 000000E9 7423                    	je .next
   631 000000EB 3C61                    	cmp al, 'a'
   632 000000ED 7206                    	jb @F
   633 000000EF 3C7A                    	cmp al, 'z'
   634 000000F1 7702                    	ja @F
   635 000000F3 2C20                    	sub al, 20h
   636                                  @@:
   637 000000F5 AE                      	scasb
   638 000000F6 7516                    	jne .next
   639 000000F8 803D00                  	cmp byte [di], 0
   640 000000FB 75E9                    	jne .comparename
   641 000000FD AC                      	lodsb
   642 000000FE 3C00                    	cmp al, 0
   643 00000100 7458                    	je .found
   644 00000102 3C20                    	cmp al, 32
   645 00000104 7454                    	je .found
   646 00000106 3C09                    	cmp al, 9
   647 00000108 7450                    	je .found
   648 0000010A 3C3D                    	cmp al, '='
   649 0000010C 744C                    	je .found
   650                                  .next:
   651 0000010E 5F                      	pop di
   652 0000010F 58                      	pop ax
   653 00000110 5E                      	pop si
   654 00000111 AF                      	scasw			; skip name field
   655 00000112 EBC6                    	jmp .loopname
   656                                  
   657                                  .unknownname:
   658 00000114 56                      	push si
   659                                  
   660                                  extern unknown_command
   661 00000115 BE[0000]                	mov si, unknown_command
   662 00000118 BB0700                  	mov bx, 7
   663 0000011B A9                      	db __TEST_IMM16		; skip int
   664                                  @@:
   665 0000011C CD10                    	int 10h
   666 0000011E AC                      	lodsb
   667 0000011F B40E                    	mov ah, 0Eh
   668 00000121 84C0                    	test al, al
   669 00000123 75F7                    	jnz @B
   670 00000125 5E                      	pop si
   671 00000126 56                      	push si
   672                                  @@:
   673 00000127 AC                      	lodsb
   674 00000128 3C09                    	cmp al, 9
   675 0000012A 74FB                    	je @B
   676 0000012C 3C20                    	cmp al, 32
   677 0000012E 74F7                    	je @B
   678 00000130 4E                      	dec si
   679 00000131 A9                      	db __TEST_IMM16		; skip int
   680                                  @@:
   681 00000132 CD10                    	int 10h
   682 00000134 AC                      	lodsb
   683 00000135 B40E                    	mov ah, 0Eh
   684 00000137 84C0                    	test al, al
   685 00000139 740C                    	jz @F
   686 0000013B 3C20                    	cmp al, 32
   687 0000013D 7204                    	jb .ctrl
   688 0000013F 3C7F                    	cmp al, 127
   689 00000141 72EF                    	jb @B
   690                                  .ctrl:
   691 00000143 B02E                    	mov al, '.'
   692 00000145 EBEB                    	jmp @B
   693                                  @@:
   694 00000147 5E                      	pop si
   695 00000148 B8220E                  	mov ax, 0E00h + '"'
   696 0000014B CD10                    	int 10h
   697 0000014D B80D0E                  	mov ax, 0E00h + 13
   698 00000150 CD10                    	int 10h
   699 00000152 B80A0E                  	mov ax, 0E00h + 10
   700 00000155 CD10                    	int 10h
   701 00000157 EB1F                    	jmp .donename
   702                                  
   703                                  @@:
   704 00000159 AC                      	lodsb
   705                                  .found:
   706 0000015A 3C20                    	cmp al, 32
   707 0000015C 74FB                    	je @B
   708 0000015E 3C09                    	cmp al, 9
   709 00000160 74F7                    	je @B
   710 00000162 3C3D                    	cmp al, '='
   711 00000164 7501                    	jne @FF
   712                                  @@:
   713 00000166 AC                      	lodsb
   714                                  @@:
   715 00000167 3C20                    	cmp al, 32
   716 00000169 74FB                    	je @BB
   717 0000016B 3C09                    	cmp al, 9
   718 0000016D 74F7                    	je @BB
   719                                  
   720 0000016F 4E                      	dec si			; -> content
   721 00000170 5F                      	pop di
   722 00000171 8975FE                  	mov word [di - 2], si
   723 00000174 58                      	pop ax
   724                                  		; INP:	si -> past an optional equals sign and blanks
   725                                  		;	di -> -> command name
   726                                  		; CHG:	ax, si, di, cx, bx, dx, bp
   727                                  		; STT:	ds = es => SYSINIT
   728                                  		;	cs => DOSENTRY
   729 00000175 FFD0                    	call ax
   730 00000177 5E                      	pop si
   731                                  .donename:
   732                                  @@:
   733 00000178 AC                      	lodsb
   734 00000179 3C00                    	cmp al, 0
   735 0000017B 75FB                    	jne @B
   736 0000017D 3B36[0000]              	cmp si, word [kernelcommandline.end]
   737 00000181 7703E93DFF              	jbe .loopcommand		; (ZR means an empty command at end)
   738                                  
   739                                  
   740                                  init_orig13:
   741 00000186 31C0                    	XOR	AX,AX
   742 00000188 8ED8                    	MOV	DS,AX
   743                                   assume ds:IVT
   744 0000018A B500                    	mov ch, 0
   745                                  
   746                                  ;
   747                                  ; PRESERVE ORIGINAL INT 13 VECTOR
   748                                  ;   WE NEED TO SAVE INT13 IN TWO PLACES IN CASE WE ARE RUNNING ON AN AT.
   749                                  ; ON ATS WE INSTALL THE IBM SUPPLIED ROM_BIOS PATCH DISK.OBJ WHICH HOOKS
   750                                  ; INT13 AHEAD OF ORIG13.  SINCE INT19 MUST UNHOOK INT13 TO POINT TO THE
   751                                  ; ROM INT13 ROUTINE, WE MUST HAVE THAT ROM ADDRESS ALSO STORED AWAY.
   752                                  ;
   753 0000018C A14C00                  	MOV	AX,[13H*4]
   754 0000018F 2EA3[0000]              	MOV	WORD PTR [cs:ORIG13],AX
   755 00000193 A14E00                  	MOV	AX,[13H*4+2]
   756 00000196 2EA3[0200]              	MOV	WORD PTR [cs:ORIG13+2],AX
   757                                  
   758                                  init_irt:
   759                                   extern InterruptRestorationTable
   760 0000019A 0E                      	push cs
   761 0000019B 07                      	pop es			; => IRT
   762                                   assume es:DOSENTRYGROUP
   763 0000019C FC                      	cld
   764 0000019D BE[0000]                	mov si, InterruptRestorationTable	; access with es
   765                                  .:
   766 000001A0 31C0                    	xor ax, ax
   767 000001A2 26AC                    	es lodsb
   768 000001A4 3CFF                    	cmp al, -1
   769 000001A6 740D                    	je .done
   770 000001A8 97                      	xchg di, ax		; di = interrupt number
   771 000001A9 01FF                    	add di, di
   772 000001AB 01FF                    	add di, di		; ds:di -> interrupt vector
   773 000001AD 87F7                    	xchg si, di		; es:di -> IRT, ds:si -> vector
   774 000001AF A5                      	movsw
   775 000001B0 A5                      	movsw
   776 000001B1 87F7                    	xchg si, di
   777 000001B3 EBEB                    	jmp .
   778                                  .done:
   779                                  
   780                                  ;
   781                                  ; SET UP INT 13 FOR NEW ACTION
   782                                  ;
   783                                  extern msdisk_i13
   784 000001B5 C7064C00[0000]          	MOV	WORD PTR [13H*4],OFFSET msdisk_i13
   785 000001BB 8C0E4E00                	MOV	[13H*4+2],CS
   786                                  
   787                                  ;
   788                                  ; SET UP INT 19 FOR NEW ACTION
   789                                  ;
   790                                  extern i19
   791 000001BF C7066400[0000]          	MOV	WORD PTR [19H*4],OFFSET i19
   792 000001C5 8C0E6600                	MOV	[19H*4+2],CS
   793 000001C9 FB                      	STI
   794 000001CA CD11                    	INT	11H			;GET EQUIPMENT STATUS
   795                                  ;J.K.6/24/87 We have to support a system that does not have any diskette
   796                                  ;drives but only hardfiles.  This system will IPL from the hardfile.
   797                                  ;If the equipment flag bit 0 is 1, then the system has diskette drive(s).
   798                                  ;Otherwise, the system only have hardfiles.
   799                                  ;Important thing is that still, for compatibility reason, the drive letter
   800                                  ;for the hardfile start from "C".  So, we still need to allocate dummy BDS
   801                                  ;drive A and driver B.	In SYSINIT time, we are going to set CDS table entry
   802                                  ;of DPB pointer for these drives to 0, so any user attempt to access this
   803                                  ;drives will get "Invalid drive letter ..." message.  We are going to
   804                                  ;establish "FAKEFLOPPYDRV" flag.  ***SYSINIT module should call INT 11h to check
   805                                  ;if there are any diskette drivers in the system or not.!!!***
   806                                  
   807                                  ;SB34INIT001**************************************************************
   808                                  ;SB	check the register returned by the equipment determination interrupt
   809                                  ;SB	we have to handle the case of no diskettes in the system by faking
   810                                  ;SB	two dummy drives.
   811                                  ;SB	if the register indicates that we do have floppy drives we don't need
   812                                  ;SB	to do anything special.
   813                                  ;SB	if the register indicates that we don't have any floppy drives then
   814                                  ;SB	what we need to do is set the FakeFloppyDrv variable, change the 
   815                                  ;SB	register to say that we do have floppy drives and then go to execute
   816                                  ;SB	the code which starts at NOTSINGLE.  This is because we can skip the
   817                                  ;SB	code given below which tries to find if there are one or two drives
   818                                  ;SB	since we already know about this.  6 LOCS
   819                                  
   820 000001CC A801                    	test	al, 1
   821 000001CE 750C                    	jnz	DO_FLOPPY
   822 000001D0 B8[ssss]                	mov	ax, SYSINITSEG
   823 000001D3 8ED8                    	mov	ds, ax
   824                                   assume ds:SYSINITGROUP
   825 000001D5 B001                    	mov	al, 1			; set to indicate 2 floppies 
   826 000001D7 A2[0600]                	mov	[FakeFloppyDrv], al	; fake floppy
   827 000001DA EB10                    	jmp	short NOTSINGLE
   828                                  
   829                                  DO_FLOPPY:
   830                                  
   831                                  ;SB34INIT001**************************************************************
   832                                     ;
   833                                     ; Determine if there are one or two diskette drives in system
   834                                     ;
   835 000001DC D0C0                    	ROL	AL,1			;PUT BITS 6 & 7 INTO BITS 0 & 1
   836 000001DE D0C0                    	ROL	AL,1
   837 000001E0 2403                    	AND	al, 3			;ONLY LOOK AT BITS 0 & 1
   838 000001E2 7508                    	JNZ	NOTSINGLE		;ZERO MEANS SINGLE DRIVE SYSTEM
   839 000001E4 40                      	INC	AX			;PRETEND IT'S A TWO DRIVE SYSTEM
   840 000001E5 E82705                  	call dosentry_init_get_ds_dosbiodata
   841                                   assume ds:DOSGROUP
   842 000001E8 FE06[0000]              	INC	byte [SINGLE]		;REMEMBER THIS
   843                                  NOTSINGLE:
   844 000001EC 0E                      	push cs
   845 000001ED 1F                      	pop ds
   846                                   assume ds:DOSENTRYGROUP
   847                                  
   848 000001EE 40                      	INC	AX			;AX HAS NUMBER OF DRIVES, 2-4
   849                                  					;IS ALSO 0 INDEXED BOOT DRIVE IF WE
   850                                  					;  BOOTED OFF HARD FILE
   851 000001EF 88C1                    	MOV	CL,AL			;CH IS FAT ID, CL # FLOPPIES
   852 000001F1 F6C280                  	TEST	DL,80H			;BOOT FROM FLOPPY ?
   853 000001F4 7502                    	JNZ	GOTHRD			;NO.
   854 000001F6 31C0                    	XOR	AX,AX			;INDICATE BOOT FROM DRIVE A
   855                                  GOTHRD:
   856                                  ;
   857                                  ;   AX = 0-BASED DRIVE WE BOOTED FROM
   858                                  ;   CL = NUMBER OF FLOPPIES INCLUDING FAKE ONE
   859                                  ;   CH = MEDIA BYTE
   860                                  ;
   861                                  	MESSAGE FTESTINIT,<"INIT",CR,LF>
   862 000001F8 31D2                    	XOR	DX,DX
   863                                  
   864 000001FA 51                      	PUSH	CX			;SAVE NUMBER OF FLOPPIES AND MEDIA BYTE
   865 000001FB 88EC                    	MOV	AH,CH			;SAVE FAT ID TO AH
   866 000001FD 50                      	PUSH	AX			;SAVE BOOT DRIVE NUMBER, AND MEDIA BYTE
   867                                  ;J.K. Let Model_byte, Secondary_Model_Byte be set here!!!
   868                                  ;SB33020******************************************************************
   869 000001FE F9                      	stc
   870 000001FF B4C0                    	mov	ah,0c0h 		; return system environment    ;SB;3.30
   871 00000201 CD15                    	int	15h			; call ROM-Bios routine        ;SB;3.30
   872                                  ;SB33020******************************************************************
   873 00000203 E80905                  	call dosentry_init_get_ds_dosbiodata
   874                                   assume ds:DOSGROUP
   875 00000206 7214                    	jc	No_Rom_System_Conf	; just use Model_Byte
   876 00000208 84E4                    	test	ah, ah			; double check
   877 0000020A 7510                    	jnz	No_Rom_System_Conf
   878 0000020C 268A4702                	mov	al, [ES:BX + bios_SD_modelbyte] ;get the model byte
   879 00000210 A2[0000]                	mov	[Model_Byte], al
   880 00000213 268A4703                	mov	al, [ES:BX + bios_SD_scnd_modelbyte] ;secondary model byte
   881 00000217 A2[0000]                	mov	[Secondary_Model_Byte], al
   882 0000021A EB0C                    	jmp	short Turn_Timer_On
   883                                  No_Rom_System_Conf:
   884 0000021C BEFFFF                  	MOV	SI,0FFFFH		;MJB001
   885 0000021F 8EC6                    	MOV	ES,SI			;MJB001
   886                                   assume es:nothing
   887 00000221 26A00E00                	MOV	AL,[ES:0EH]		; GET MODEL BYTE ARR 2.41
   888                                  MODEL_BYTE equ Model_Byte	; NASM port label
   889 00000225 A2[0000]                	MOV	[MODEL_BYTE],AL	      ; SAVE MODEL BYTE ARR 2.41
   890                                  Turn_Timer_On:
   891 00000228 B020                    	MOV	AL,EOI
   892 0000022A E620                    	OUT	AKPORT,AL		;TURN ON THE TIMER
   893                                  
   894                                  ;     NOP out the double word MOV instruction in MSDISK, if
   895                                  ;     this is not a 386 machine...
   896                                  	Get_CPU_Type			; macro to determine cpu type
    10 0000022C 9C                  <1>  pushf
    11 0000022D 53                  <1>  push bx
    12 0000022E 31DB                <1>  xor bx, bx
    13                              <1> 
    14 00000230 31C0                <1>  xor ax,ax
    15 00000232 50                  <1>  push ax
    16 00000233 9D                  <1>  popf
    17 00000234 9C                  <1>  pushf
    18 00000235 58                  <1>  pop ax
    19 00000236 2500F0              <1>  and ax,0F000h
    20 00000239 3D00F0              <1>  cmp ax,0F000h
    21 0000023C 740E                <1>  je %%cpu_8086
    22                              <1> 
    23 0000023E B800F0              <1>  mov ax,0F000h
    24 00000241 50                  <1>  push ax
    25 00000242 9D                  <1>  popf
    26 00000243 9C                  <1>  pushf
    27 00000244 58                  <1>  pop ax
    28 00000245 2500F0              <1>  and ax,0F000h
    29 00000248 7401                <1>  jz %%cpu_286
    30                              <1> 
    31                              <1> %%cpu_386:
    32 0000024A 43                  <1>  inc bx
    33                              <1> %%cpu_286:
    34 0000024B 43                  <1>  inc bx
    35                              <1> %%cpu_8086:
    36 0000024C 89D8                <1>  mov ax, bx
    37 0000024E 5B                  <1>  pop bx
    38 0000024F 9D                  <1>  popf
   897 00000250 3C02                    	cmp	al, 2			; is it a 386?
   898 00000252 7504                    	jne	Skip_Patch_DoubleWordMov; no: skip the patch
   899                                  
   900                                  Patch_DoubleWordMov:
   901                                   extern dosbiodata_have_386
   902 00000254 F616[0000]              	not byte [dosbiodata_have_386]	; = 0FFh
   903                                  Skip_Patch_DoubleWordMov:
   904                                  	MESSAGE FTESTINIT,<"COM DEVICES",CR,LF>
   905                                  ;SB33IN1*********************************************************
   906                                  
   907 00000258 BE[0000]                	mov	si,offset COM4DEV 
   908 0000025B E8DD04                  	call	AUX_INIT
   909 0000025E BE[0000]                	mov	si,offset COM3DEV
   910 00000261 E8D704                  	call	AUX_INIT
   911                                  ;SB33IN1*********************************************************
   912 00000264 BE[0000]                	MOV	SI,OFFSET COM2DEV
   913 00000267 E8D104                  	CALL	AUX_INIT		;INIT COM2
   914 0000026A BE[0000]                	MOV	SI,OFFSET COM1DEV
   915 0000026D E8CB04                  	CALL	AUX_INIT		;INIT COM1
   916                                  
   917                                  	MESSAGE FTESTINIT,<"LPT DEVICES",CR,LF>
   918 00000270 BE[0000]                	MOV	SI,OFFSET LPT3DEV
   919 00000273 E8BD04                  	CALL	PRINT_INIT		;INIT LPT3
   920 00000276 BE[0000]                	MOV	SI,OFFSET LPT2DEV
   921 00000279 E8B704                  	CALL	PRINT_INIT		;INIT LPT2
   922 0000027C BE[0000]                	MOV	SI,OFFSET LPT1DEV
   923 0000027F E8B104                  	CALL	PRINT_INIT		;INIT LPT1
   924                                  
   925 00000282 31D2                    	XOR	DX,DX
   926 00000284 8EDA                    	MOV	DS,DX			;TO INITIALIZE PRINT SCREEN VECTOR
   927 00000286 8EC2                    	MOV	ES,DX
   928                                   assume ds:IVT, es:IVT
   929                                  
   930 00000288 31C0                    	XOR	AX,AX
   931 0000028A BF3405                  	MOV	DI,INITSPOT
   932 0000028D AB                      	STOSW				;INIT FOUR BYTES TO 0
   933 0000028E AB                      	STOSW
   934                                  
   935 0000028F 8CC8                    	MOV	AX,CS			;FETCH SEGMENT
   936                                  
   937                                  extern i1B
   938 00000291 C7066C00[0000]          	MOV	WORD [BRKADR], i1B	;BREAK ENTRY POINT
   939 00000297 A36E00                  	MOV	[BRKADR+2],AX		;VECTOR FOR BREAK
   940                                  
   941                                  ;*********************************************** ARR 2.15
   942                                  ; SINCE WE'RE FIRST IN SYSTEM, NO NEED TO CHAIN THIS.
   943                                  ;	CLI				; ARR 2.15 DON'T GET BLOWN
   944                                  ;	MOV	DS:WORD PTR TIMADR,OFFSET TIMER ; ARR 2.15 TIMER ENTRY POINT
   945                                  ;	MOV	DS:TIMADR+2,AX		; ARR 2.15 VECTOR FOR TIMER
   946                                  ;	STI
   947                                  ;*********************************************** ARR 2.15
   948                                  
   949                                  ; BAS DEBUG
   950                                  extern i29
   951 0000029A C706A400[0000]          	MOV	WORD [CHROUT*4], i29
   952 000002A0 A3A600                  	MOV	WORD PTR [CHROUT*4+2],AX
   953                                  
   954                                  extern entry_iret
   955                                  	MESSAGE FTESTINIT,<"INTERRUPT VECTORS",CR,LF>
   956 000002A3 BB[0000]                	MOV	BX, entry_iret		;WILL INITIALIZE REST OF INTERRUPTS
   957                                  
   958 000002A6 BF1000                  	mov di, 4 * 4
   959                                  
   960 000002A9 50                      	push ax				; preserve segment
   961 000002AA 53                      	push bx				; preserve offset
   962                                  debugger_check:
   963 000002AB 2EA0[0000]              	mov al, byte [cs:checkdebugger]
   964 000002AF A804                    	test al, LCFG_DBG_ONLY_VALID
   965 000002B1 740E                    	jz @F
   966                                  		; ds => IVT
   967 000002B3 833E0C00FF              	cmp word [3 * 4], -1
   968 000002B8 7420                    	je .nocheck
   969 000002BA 833E0E0000              	cmp word [3 * 4 + 2], 0
   970 000002BF 7419                    	je .nocheck
   971                                  @@:
   972 000002C1 A808                    	test al, LCFG_DBG_ONLY_IISP
   973 000002C3 7411                    	jz @F
   974                                  		; ds => IVT
   975 000002C5 C41E0C00                	les bx, [3 * 4]			; es:bx -> int 3 handler
   976                                   assume es:nothing
   977 000002C9 83FBEE                  	cmp bx, -18			; valid ? (could tear word access ?)
   978 000002CC 770C                    	ja .nocheck			; no, cannot be a valid IISP header -->
   979 000002CE 26817F064B42            	cmp word [es:bx + 6], "KB"	; signature present ?
   980 000002D4 7504                    	jne .nocheck			; no -->
   981                                  @@:
   982 000002D6 A801                    	test al, LCFG_DBG_CHECK
   983 000002D8 7508                    	jnz .check
   984                                  .nocheck:
   985 000002DA 2EC606[E902]90          	mov byte [cs:.patch], 90h	; do not check
   986 000002E0 EB00                    	jmp @F				; (flush queue for the SMC)
   987                                  @@:
   988                                  .check:
   989 000002E2 1E                      	push ds
   990 000002E3 07                      	pop es
   991                                   assume es:IVT
   992 000002E4 A802                    	test al, LCFG_DBG_ASSUME	; (NC)
   993 000002E6 7401                    	jz .runint3			; if to assume off --> (NC)
   994 000002E8 F9                      	stc				; assume on (CY)
   995                                  .runint3:
   996 000002E9 CC                      .patch:	int3				; SMC: patched to NOP if not to run int3
   997 000002EA 7211                    	jc debugger_detected
   998                                  
   999                                  debugger_disabled:
  1000 000002EC BF0400                  	mov di, 4 * 1
  1001 000002EF 5B                      	pop bx
  1002 000002F0 58                      	pop ax				; = segment
  1003                                  
  1004 000002F1 93                      	XCHG	AX,BX
  1005 000002F2 AB                      	STOSW				;LOCATION 4
  1006 000002F3 93                      	XCHG	AX,BX
  1007 000002F4 AB                      	STOSW				;INT 1		;LOCATION 6
  1008 000002F5 83C704                  	ADD	DI,4
  1009 000002F8 93                      	XCHG	AX,BX
  1010 000002F9 AB                      	STOSW				;LOCATION 12
  1011 000002FA 93                      	XCHG	AX,BX
  1012 000002FB AB                      	STOSW				;INT 3		;LOCATION 14
  1013                                  
  1014 000002FC A9                      	db 0A9h				; test ax, imm16 (skip pop, pop)
  1015                                  debugger_detected:
  1016 000002FD 5B                      	pop bx
  1017 000002FE 58                      	pop ax
  1018 000002FF 93                      	XCHG	AX,BX
  1019 00000300 AB                      	STOSW				;LOCATION 16
  1020 00000301 93                      	XCHG	AX,BX
  1021 00000302 AB                      	STOSW				;INT 4		;LOCATION 18
  1022                                  
  1023 00000303 89160005                	MOV	WORD PTR [500H],DX	;SET PRINT SCREEN & BREAK =0
  1024 00000307 89160405                	MOV	WORD PTR [LSTDRV],DX	;CLEAN OUT LAST DRIVE SPEC
  1025                                  
  1026                                  	MESSAGE FTESTINIT,<"DISK PARAMETER TABLE",CR,LF>
  1027                                  
  1028                                  		; lDOS: our sector and initial loader do not relocate
  1029                                  		;	 the DPT so do it here instead. this code used
  1030                                  		;	 to be commented out.
  1031 0000030B C5367800                	lds si, [DSKADR]		; DS:SI -> CURRENT TABLE  ARR 2.41
  1032                                   assume ds:nothing
  1033 0000030F BF2205                  	MOV	DI,SEC9			; ES:DI -> NEW TABLE	  ARR 2.41
  1034 00000312 57                      	push di
  1035 00000313 B90B00                  	MOV	CX,DISK_PARMS_struc_size;			  ARR 2.41
  1036 00000316 F3A4                    	REP	MOVSB			; COPY TABLE		  ARR 2.41
  1037 00000318 06                      	PUSH	ES			;			  ARR 2.41
  1038 00000319 1F                      	POP	DS			; DS = 0		  ARR 2.41
  1039                                   assume ds:IVT
  1040                                  
  1041 0000031A 8F067800                	pop	WORD PTR [DSKADR]	;			  ARR 2.41
  1042 0000031E 8C1E7A00                	MOV	WORD PTR [DSKADR+2],DS	; POINT DISK PARM VECTOR TO NEW TABLE
  1043                                  					;			  ARR 2.41
  1044                                  ;SB34INIT002******************************************************************
  1045                                  ;SB	We need to initalise the cs:MotorStartup variable from the disk 
  1046                                  ;SB	parameter table at SEC9.  The offsets in this table are defined in
  1047                                  ;SB	the DISK_PARMS struc in MSDSKPRM.INC.  2 LOCS
  1048                                  
  1049 00000322 A02C05                  	mov	al,[SEC9 + DISK_MOTOR_STRT]
  1050 00000325 E8EF03                  	call dosentry_init_get_es_dosbiodata
  1051                                   assume es:DOSGROUP
  1052                                  MotorStartup equ MOTORSTARTUP	; NASM port label
  1053 00000328 26A2[0000]              	mov	[es:MotorStartup],al
  1054                                  ;SB34INIT002******************************************************************
  1055 0000032C 26803E[0000]FD          	CMP	byte [es:MODEL_BYTE],0FDH       ; IS THIS AN OLD ROM?	ARR 2.41
  1056 00000332 720B                    	JB	NO_DIDDLE		; NO			  ARR 2.41
  1057 00000334 C7062B050F02            	MOV	WORD [(SEC9 + DISK_HEAD_STTL)],0200H+NORMSETTLE
  1058                                  					; SET HEAD SETTLE AND MOTOR START
  1059                                  					; ON PC-1 PC-2 PC-XT HAL0 ARR 2.41
  1060 0000033A C6062205DF              	MOV	byte [(SEC9 + DISK_SPECIFY_1)],0DFH
  1061                                  					; SET 1ST SPECIFY BYTE
  1062                                  					; ON PC-1 PC-2 PC-XT HAL0 ARR 2.41
  1063                                  NO_DIDDLE:				;			  ARR 2.41
  1064 0000033F CD12                    	INT	12H			;GET MEMORY SIZE--1K BLOCKS IN AX
  1065 00000341 B106                    	MOV	CL,6
  1066 00000343 D3E0                    	SHL	AX,CL			;CONVERT TO 16-BYTE BLOCKS(SEGMENT NO.)
  1067 00000345 59                      	POP	CX			; RETREIVE BOOT DRIVE NUMBER, AND FAT ID
  1068                                  		; cl = boot drive, 0 = A:
  1069 00000346 BA[ssss]                	MOV	DX,SYSINITSEG
  1070 00000349 8EDA                    	MOV	DS,DX
  1071                                  
  1072                                  	ASSUME	DS:SYSINITGROUP
  1073                                  
  1074 0000034B A3[0000]                	MOV	[MEMORY_SIZE],AX
  1075 0000034E 41                      	INC	cx
  1076 0000034F 880E[0000]              	MOV	[DEFAULT_DRIVE],CL	;SAVE DEFAULT DRIVE SPEC
  1077                                  
  1078 00000353 31C9                    	xor	cx,cx
  1079                                  
  1080                                  ; IMPORTANT: SOME OLD IBM HARDWARE GENERATES SPURIOUS INT F'S DUE TO BOGUS
  1081                                  ; PRINTER CARDS.  WE INITIALIZE THIS VALUE TO POINT TO AN IRET ONLY IF
  1082                                  
  1083                                  ; 1) THE ORIGINAL SEGMENT POINTS TO STORAGE INSIDE VALID RAM.
  1084                                  
  1085                                  ; 2) THE ORIGINAL SEGMENT IS 0F000:XXXX
  1086                                  
  1087                                  ; THESES ARE CAPRICIOUS REQUESTS FROM OUR OEM FOR REASONS BEHIND THEM, READ
  1088                                  ; THE DCR'S FOR THE IBM DOS 3.2 PROJECT.
  1089                                  
  1090 00000355 8EC1                    	MOV	es,cx			; cx := SEGMENT FOR INT 15
  1091                                   assume es:IVT
  1092 00000357 26A13E00                	MOV	AX,WORD PTR [es:(0FH*4+2)]
  1093                                  
  1094 0000035B 3B06[0000]              	CMP	AX,[MEMORY_SIZE]	; CONDITION 1
  1095 0000035F 7605                    	Jbe	RESETINTF
  1096                                  
  1097 00000361 3D00F0                  	CMP	AX,0F000H		; CONDITION 2
  1098 00000364 750C                    	JNE	KEEPINTF
  1099                                  
  1100                                  RESETINTF:
  1101 00000366 26C7063C00[0000]        	MOV	WORD PTR [es:0FH*4], entry_iret
  1102 0000036D 268C0E3E00              	MOV	WORD PTR [es:0FH*4+2],CS
  1103                                  KEEPINTF:
  1104                                  
  1105                                  ; END IMPORTANT
  1106                                  
  1107                                  ;SB34INIT003****************************************************************
  1108                                  ;SB We will check if the system has IBM extended key board by
  1109                                  ;SB looking at a byte at 40:96.  If bit 4 is set, then extended key board
  1110                                  ;SB is installed, and we are going to set KEYRD_Func to 10h, KEYSTS_Func to 11h
  1111                                  ;SB for the extended keyboard function. Use cx as the temporary register. 8 LOCS
  1112                                  
  1113 00000372 26F606960410            	test byte [es:0496h], 0001_0000b	; get keyboard flag
  1114                                  
  1115 00000378 E89403                  	call dosentry_init_get_ds_dosbiodata
  1116                                   assume ds:DOSGROUP
  1117 0000037B 1E                      	PUSH	ds
  1118 0000037C 07                      	POP	ES
  1119                                   assume es:DOSGROUP
  1120                                  
  1121 0000037D 7406                    	jz	ORG_KEY				; orginal keyboard
  1122                                  KEYRD_func equ KEYRD_Func	; NASM port label
  1123                                  KEYSTS_func equ KEYSTS_Func	; NASM port label
  1124 0000037F C706[0000]1011          	mov	word [KEYRD_func], 11_10h	; change for extended keyboard functions
  1125                                  		; KEYSTS_Func is directly behind KEYRD_Func
  1126                                  ORG_KEY:
  1127                                  
  1128                                  ;SB34INIT003****************************************************************
  1129                                  
  1130                                  ;**************************************************************
  1131                                  ;	WILL INITIALIZE THE NUMBER OF DRIVES
  1132                                  ;	AFTER THE EQUIPMENT CALL (INT 11H) BITS 6&7 WILL TELL
  1133                                  ;	THE INDICATIONS ARE AS FOLLOWS:
  1134                                  ;
  1135                                  ;	BITS	7	6	DRIVES
  1136                                  ;		0	0	1
  1137                                  ;		0	1	2
  1138                                  ;		1	0	3
  1139                                  ;		1	1	4
  1140                                  ;**************************************************************
  1141                                  
  1142 00000385 E8C703                  	call	CMOS_Clock_Read     ;Before doing anythig else if CMOS clock exists,
  1143                                  				    ;then set the system time according to that.
  1144                                  				    ;Also, reset the cmos clock rate.
  1145                                  
  1146                                  	MESSAGE FTESTINIT,<"DISK DEVICES",CR,LF>
  1147                                  
  1148 00000388 58                      	POP	AX			;NUMBER OF FLOPPIES AND FAT ID
  1149 00000389 30E4                    	XOR	AH,AH			; CHUCK FAT ID BYTE
  1150 0000038B 2EA2[0000]              	MOV	[cs:DRVMAX],AL	      ;AND SET INITIAL NUMBER OF DRIVES
  1151                                  	MESSAGE FTESTINIT,<"BEFORE INT 13",CR,LF>
  1152                                  
  1153                                  determine_fhave96:
  1154 0000038F BA[ssss]                	mov dx, SYSINITSEG
  1155 00000392 8EDA                    	mov ds, dx
  1156                                   assume ds:SYSINITGROUP
  1157 00000394 31D2                    	xor dx, dx			; dl = unit 0
  1158 00000396 803E[0600]01            	cmp byte [FakeFloppyDrv],1
  1159 0000039B 0E                      	push cs
  1160 0000039C 1F                      	pop ds
  1161                                   assume ds:DOSENTRYGROUP
  1162 0000039D 741D                    	je .none
  1163                                  
  1164                                  .LOOP_DRIVE:
  1165 0000039F 3A16[0000]              	CMP	DL,[DRVMAX]
  1166 000003A3 7317                    	jae	.done
  1167                                  
  1168                                  ; CHECK FOR CHANGELINE SUPPORT ON DRIVE
  1169                                  ;SB33023********************************************************************
  1170 000003A5 B415                    	mov	AH, 15h      ;SB	; set command to get DASD type
  1171 000003A7 F9                      	stc
  1172 000003A8 CD13                    	int	13h	     ;SB	; call ROM-BIOS
  1173                                  ;SB33023********************************************************************
  1174 000003AA 7205                    	JC	.NEXTDRIVE
  1175 000003AC 80FC02                  	CMP	AH,02			; CHECK FOR PRESENCE OF CHANGELINE
  1176 000003AF 7403                    	je .have96
  1177                                  
  1178                                  .NEXTDRIVE:
  1179 000003B1 42                      	INC	dx
  1180 000003B2 EBEB                    	JMP	.LOOP_DRIVE
  1181                                  
  1182                                  ; WE HAVE A DRIVE WITH CHANGE LINE SUPPORT.
  1183                                  ; shortcut to the end of the loop, ignoring any additional units
  1184                                  ;  that may also have change line support.
  1185                                  .have96:
  1186 000003B4 E85803                  	call dosentry_init_get_ds_dosbiodata
  1187                                   assume ds:DOSGROUP
  1188 000003B7 C606[0000]01            	mov byte [FHAVE96], 1		; REMEMBER THAT WE HAVE 96TPI DISKS
  1189                                  
  1190                                  .DONE_DRIVES:
  1191                                  .done:
  1192                                  .none:
  1193                                  	; proceeds to STATIC_CONFIGURE
  1194                                  
  1195                                  
  1196                                  usesection SYSINITTRAIL
  1197                                  
  1198                                  alloc_upb:
  1199                                   assume ds:nothing, es:nothing, ss:nothing
  1200 00000176 50                      	push ax
  1201 00000177 53                      	push bx
  1202 00000178 51                      	push cx
  1203 00000179 2EC43E[0000]            	les di, [cs:nextupb]
  1204 0000017E 8CC0                    	mov ax, es
  1205 00000180 85C0                    	test ax, ax
  1206 00000182 741F                    	jz .alloc
  1207 00000184 83C764                  	add di, BDSM_type_struc_size
  1208 00000187 2E893E[0000]            	mov word [cs:nextupb], di	; -> next UPB
  1209 0000018C B104                    	mov cl, 4
  1210 0000018E 8D5D73                  	lea bx, [di + BDSM_type_struc_size + 15]
  1211                                  					; -> behind next UPB, round up
  1212 00000191 2E3B1E[0000]            	cmp bx, word [cs:nextupb]
  1213 00000196 7208                    	jb mem_err_j
  1214 00000198 D3EB                    	shr bx, cl			; to paragraphs
  1215 0000019A B44A                    	mov ah, 4Ah
  1216 0000019C CD21                    	int 21h				; resize
  1217 0000019E 7312                    	jnc @F
  1218                                  mem_err_j: equ $
  1219                                   extern MEM_ERR
  1220 000001A0 E9(0000)                	jmp MEM_ERR
  1221                                  
  1222                                  .alloc:
  1223 000001A3 B448                    	mov ah, 48h
  1224 000001A5 BB0700                  	mov bx, paras(BDSM_type_struc_size)
  1225 000001A8 CD21                    	int 21h
  1226 000001AA 72F4                    	jc mem_err_j
  1227 000001AC 8EC0                    	mov es, ax
  1228                                   assume es:nothing
  1229 000001AE 2EA3[0200]              	mov word [cs:nextupb + 2], ax
  1230                                  @@:
  1231 000001B2 59                      	pop cx
  1232 000001B3 5B                      	pop bx
  1233 000001B4 58                      	pop ax
  1234 000001B5 C3                      	retn
  1235                                  
  1236                                  
  1237                                  	global INITUPB
  1238                                  INITUPB:
  1239                                  
  1240                                  ;SB33021********************************************************************
  1241 000001B6 B280                    	mov	DL, 80h     ;SB 	; tell rom bios to look at hard drives
  1242 000001B8 B408                    	mov	AH, 8h	    ;SB 	; set command to get drive parameter
  1243 000001BA F9                      	stc
  1244 000001BB CD13                    	int	13h	    ;SB 	; call ROM-BIOS to get number of drives
  1245                                  
  1246                                  	assume es:nothing
  1247                                  ;SB33021********************************************************************
  1248 000001BD 7205                    	JC	ENDDRV			;CARRY INDICATES OLD ROM, SO NO HARDFILE
  1249 000001BF 2E8816[0000]            	MOV	[cs:HNUM],DL
  1250                                  ENDDRV:
  1251                                  	MESSAGE FTESTINIT,<"SETTING UP BDSS",CR,LF>
  1252                                  
  1253                                  ;
  1254                                  ; SCAN THE LIST OF DRIVES TO DETERMINE THEIR TYPE.  WE HAVE THREE FLAVORS OF
  1255                                  ; DISKETTE DRIVES:
  1256                                  ;
  1257                                  ;   48TPI DRIVES    WE DO NOTHING SPECIAL FOR THEM
  1258                                  ;   96TPI DRIVES    MARK THE FACT THAT THEY HAVE CHANGELINE SUPPORT.
  1259                                  ;   3 1/4 DRIVES    MARK CHANGELINE SUPPORT AND SMALL.
  1260                                  ;
  1261                                  ; THE FOLLOWING CODE USES REGISTERS FOR CERTAIN VALUES:
  1262                                  ;   DL - PHYSICAL DRIVE
  1263                                  ;   DS:DI - POINTS TO CURRENT BDS
  1264                                  ;   CX - FLAG BITS FOR BDS
  1265                                  ;   DH - FORM FACTOR FOR THE DRIVE (1 - 48TPI, 2 - 96TPI, 3 - 3.5" MEDIUM)
  1266                                  ;
  1267 000001C4 30D2                    	XOR	DL,DL			; START OUT WITH DRIVE 0.
  1268                                  
  1269 000001C6 E8DF07                  	call sysinit_get_ds_dosbiodata
  1270                                   assume ds:DOSGROUP
  1271 000001C9 C606[0000]09            	MOV	byte [EOT],9
  1272                                  ;J.K.6/24/87 Check if the system has no physical diskette drives.
  1273                                  ;J.K. If it is, then we don't have to set BDS tables.  But since we
  1274                                  ;J.K. pretend that we have 2 floppies, we are going to reserve two
  1275                                  ;J.K. BDS tables for the fake drive A, and B. and set the end of link
  1276                                  ;J.K. pointer.
  1277                                  
  1278                                  ;SB34INIT004*********************************************************
  1279                                  ;SB	Check to see if we are faking floppy drives.  If not we don't 
  1280                                  ;SB	do anything special.  If we are faking floppy drives we need
  1281                                  ;SB	to set aside two BDSs for the two fake floppy drives.  We 
  1282                                  ;SB	don't need to initalise any fields though. So starting at START_BDS
  1283                                  ;SB	use the link field in the BDS structure to go to the second BDS
  1284                                  ;SB	in the list and initalise it's link field to -1 to set the end of
  1285                                  ;SB	the list.  Then jump to the routine at DoHard to allocate/initialise
  1286                                  ;SB     the BDS for HardDrives.
  1287                                  
  1288 000001CE 2E803E[0600]01          	cmp	byte [cs:FakeFloppyDrv],1
  1289 000001D4 7533                    	jnz	LOOP_DRIVE		; system has floppy
  1290                                  link equ LINK	; NASM port equate
  1291 000001D6 E89DFF                  	call alloc_upb
  1292 000001D9 0E                      	push cs
  1293 000001DA 1F                      	pop ds
  1294                                   assume ds:SYSINITGROUP
  1295 000001DB BE[0800]                	mov si, BDS_diskette_template	; access with ds
  1296 000001DE B96400                  	mov cx, BDS_TYPE_struc_size
  1297 000001E1 57                      	push di
  1298 000001E2 F3A4                    	rep movsb
  1299 000001E4 06                      	push es
  1300 000001E5 1F                      	pop ds
  1301                                   assume ds:nothing, es:nothing
  1302 000001E6 5F                      	pop di
  1303 000001E7 C6450500                	mov byte [di + DRIVELET], 0
  1304 000001EB E85F0C                  	call Install_BDSM_and_set_bpb
  1305                                  
  1306 000001EE E885FF                  	call alloc_upb
  1307 000001F1 0E                      	push cs
  1308 000001F2 1F                      	pop ds
  1309                                   assume ds:SYSINITGROUP
  1310 000001F3 BE[0800]                	mov si, BDS_diskette_template	; access with ds
  1311 000001F6 B96400                  	mov cx, BDS_TYPE_struc_size
  1312 000001F9 57                      	push di
  1313 000001FA F3A4                    	rep movsb
  1314 000001FC 06                      	push es
  1315 000001FD 1F                      	pop ds
  1316                                   assume ds:nothing, es:nothing
  1317 000001FE 5F                      	pop di
  1318 000001FF C6450501                	mov byte [di + DRIVELET], 1
  1319 00000203 E8470C                  	call Install_BDSM_and_set_bpb
  1320                                  
  1321                                  DoHard equ DOHARD	; NASM port label
  1322 00000206 E93001                  	jmp	DoHard			; allocate/initialise BDS for HardDrives
  1323                                  ;SB34INIT004*********************************************************
  1324                                  
  1325                                  LOOP_DRIVE:
  1326 00000209 E8A407                  	call sysinit_get_ds_dosentry	; DRVMAX in DOSENTRY
  1327                                   assume ds:DOSENTRYGROUP
  1328 0000020C 3A16[0000]              	CMP	DL,[DRVMAX]
  1329 00000210 7203E92401              	jae	DONE_DRIVES
  1330                                  
  1331 00000215 E85EFF                  	call alloc_upb
  1332 00000218 0E                      	push cs
  1333 00000219 1F                      	pop ds
  1334                                   assume ds:SYSINITGROUP
  1335 0000021A BE[0800]                	mov si, BDS_diskette_template	; access with ds
  1336 0000021D B96400                  	mov cx, BDS_TYPE_struc_size
  1337 00000220 57                      	push di
  1338 00000221 F3A4                    	rep movsb
  1339 00000223 5F                      	pop di
  1340                                  	; XOR	CX,CX			; ZERO ALL FLAGS (cx already zero)
  1341                                  
  1342 00000224 B600                    	MOV	DH,FF48TPI		; SET FORM FACTOR TO 48 TPI
  1343 00000226 C606[6F00]28            	MOV	byte [NUM_CYLN],40	      ; 40 TRACKS PER SIDE
  1344                                  
  1345 0000022B 1E                      	PUSH	DS
  1346 0000022C 57                      	PUSH	DI
  1347 0000022D 52                      	PUSH	DX
  1348 0000022E 51                      	PUSH	CX
  1349                                  
  1350                                  ;SB33022********************************************************************
  1351 0000022F B408                    	MOV	AH, 8h			;GET DRIVE PARAMETERS	       ;SB;3.30
  1352 00000231 F9                      	stc
  1353 00000232 CD13                    	INT	13h			;CALL ROM-BIOS		       ;SB;3.30
  1354                                  ;SB33022********************************************************************
  1355 00000234 726F                    	jc	NOPARMSFROMROM		; GOT AN OLD ROM
  1356                                  
  1357                                  ;J.K. 10/9/86 If CMOS is bad, it gives ES,AX,BX,CX,DH,DI=0. CY=0.
  1358                                  ;In this case, we are going to put bogus informations to BDS table.
  1359                                  ;We are going to set CH=39,CL=9,DH=1 to avoid divide overflow when
  1360                                  ;they are calculated at the later time.  This is just for the Diagnostic
  1361                                  ;Diskette which need MSBIO,MSDOS to boot up before it sets CMOS.
  1362                                  ;This should only happen with drive B.
  1363                                  
  1364 00000236 80FD00                  	CMP	CH,0			; if ch=0, then cl,dh=0 too.
  1365 00000239 7506                    	JNE	PFR_OK
  1366 0000023B B527                    	MOV	CH,39			; ROM gave wrong info.
  1367 0000023D B109                    	MOV	CL,9			; Let's default to 360K.
  1368 0000023F B601                    	MOV	DH,1
  1369                                  PFR_OK:
  1370 00000241 FEC5                    	INC	CH			; MAKE NUMBER OF CYLINDERS 1-BASED
  1371 00000243 8836[6C00]              	MOV	byte ptr [NUM_HEADS],DH	; SAVE PARMS RETURNED BY ROM
  1372 00000247 FF06[6C00]              	inc	word ptr [NUM_HEADS]	; MAKE NUMBER OF HEADS 1-BASED
  1373 0000024B 80E13F                  	AND	CL,00111111B		; EXTRACT SECTORS/TRACK
  1374 0000024E 880E[6E00]              	MOV	[SEC_TRK],CL
  1375 00000252 882E[6F00]              	MOV	[NUM_CYLN],CH	      ; ASSUME LESS THAN 256 CYLINDERS!!
  1376                                  
  1377 00000256 E84F07                  	call sysinit_get_ds_dosbiodata
  1378                                   assume ds:DOSGROUP
  1379                                  ; MAKE SURE THAT EOT CONTAINS THE MAX NUMBER OF SEC/TRK IN SYSTEM OF FLOPPIES
  1380 00000259 3A0E[0000]              	CMP	CL,[EOT]			; MAY SET CARRY
  1381 0000025D 7604                    	JBE	EOT_OK
  1382 0000025F 880E[0000]              	MOV	[EOT],CL
  1383                                  EOT_OK:
  1384 00000263 59                      	POP	CX
  1385 00000264 5A                      	POP	DX
  1386 00000265 5F                      	POP	DI
  1387 00000266 1F                      	POP	DS
  1388                                   assume ds:SYSINITGROUP
  1389                                  
  1390                                  ; CHECK FOR CHANGELINE SUPPORT ON DRIVE
  1391                                  ;SB33023********************************************************************
  1392 00000267 B415                    	mov	AH, 15h      ;SB	; set command to get DASD type
  1393 00000269 F9                      	stc
  1394 0000026A CD13                    	int	13h	     ;SB	; call ROM-BIOS
  1395                                  ;SB33023********************************************************************
  1396 0000026C 7208                    	JC	CHANGELINE_DONE
  1397 0000026E 80FC02                  	CMP	AH,02			; CHECK FOR PRESENCE OF CHANGELINE
  1398 00000271 7503                    	JNE	CHANGELINE_DONE
  1399                                  ;
  1400                                  ; WE HAVE A DRIVE WITH CHANGE LINE SUPPORT.
  1401                                  ;
  1402                                  	MESSAGE FTESTINIT,<"96TPI DEVICES",CR,LF>
  1403                                  
  1404 00000273 80C902                  	OR	CL,FCHANGELINE		; SIGNAL TYPE
  1405                                  ;
  1406                                  ; WE NOW TRY TO SET UP THE FORM FACTOR FOR THE TYPES OF MEDIA THAT WE KNOW
  1407                                  ; AND CAN RECOGNISE. FOR THE REST, WE SET THE FORM FACTOR AS "OTHER".
  1408                                  ;
  1409                                  CHANGELINE_DONE:
  1410 00000276 0E                      	push cs
  1411 00000277 1F                      	pop ds
  1412                                   assume ds:SYSINITGROUP
  1413                                  ; 40 CYLINDERS AND 9 OR LESS SEC/TRK, TREAT AS 48 TPI MEDIUM.
  1414 00000278 803E[6F00]28            	CMP	byte [NUM_CYLN],40
  1415 0000027D 750B                    	JNZ	TRY_80
  1416 0000027F 803E[6E00]09            	CMP	byte [SEC_TRK],9
  1417 00000284 761D                    	JBE	GOT_FF			; dh = FF48TPI -->
  1418                                  GOTOTHER:
  1419 00000286 B607                    	MOV	DH,FFOTHER		; WE HAVE A "STRANGE" MEDIUM
  1420 00000288 EB19                    	JMP	SHORT GOT_FF
  1421                                  
  1422                                  ;
  1423                                  ; 80 CYLINDERS AND 9 SECTORS/TRACK => 720 KB DEVICE
  1424                                  ; 80 CYLINDERS AND 15 SEC/TRK => 96 TPI MEDIUM
  1425                                  ;
  1426                                  TRY_80:
  1427 0000028A B601                    	MOV	DH,FF96TPI		; in case it is 96 TPI
  1428 0000028C 803E[6F00]50            	CMP	byte [NUM_CYLN],80
  1429 00000291 75F3                    	JNZ	GOTOTHER		; resets dh
  1430 00000293 803E[6E00]0F            	CMP	byte [SEC_TRK],15
  1431 00000298 7409                    	JZ	GOT_FF			; (dh = FF96TPI)
  1432 0000029A 803E[6E00]09            	CMP	byte [SEC_TRK],9
  1433 0000029F 75E5                    	JNZ	GOTOTHER		; resets dh
  1434 000002A1 B602                    	MOV	DH,FFSMALL		; reset dh
  1435                                  GOT_FF:
  1436 000002A3 EB28                    	JMP	SHORT NEXTDRIVE
  1437                                  
  1438                                  ; WE HAVE AN OLD ROM, SO WE EITHER HAVE A 48TPI OR 96TPI DRIVE. IF THE DRIVE
  1439                                  ; HAS CHANGELINE, WE ASSUEM IT IS A 96TPI, OTHERWISE WE TREAT IT AS A 48TPI.
  1440                                  
  1441                                  NOPARMSFROMROM:
  1442 000002A5 59                      	POP	CX
  1443 000002A6 5A                      	POP	DX
  1444 000002A7 5F                      	POP	DI
  1445 000002A8 1F                      	POP	DS
  1446                                   assume ds:SYSINITGROUP
  1447                                  
  1448                                  ;SB33024****************************************************************
  1449 000002A9 B415                    	MOV	AH, 15h 		; SET COMMAND TO GET DASD TYPE ;SB;3.30
  1450 000002AB F9                      	stc
  1451 000002AC CD13                    	INT	13h			; CALL ROM-BIOS 	       ;SB;3.30
  1452                                  ;SB33024****************************************************************
  1453 000002AE 721D                    	JC	NEXTDRIVE
  1454 000002B0 80FC02                  	CMP	AH,2			; IS THERE CHANGELINE?
  1455 000002B3 7518                    	JNZ	NEXTDRIVE
  1456 000002B5 80C902                  	OR	CL,FCHANGELINE
  1457 000002B8 C606[6F00]50            	MOV	byte [NUM_CYLN],80
  1458 000002BD B601                    	MOV	DH,FF96TPI
  1459 000002BF B00F                    	MOV	AL,15			; SET EOT IF NECESSARY
  1460                                  
  1461 000002C1 E8E406                  	call sysinit_get_ds_dosbiodata
  1462                                   assume ds:DOSGROUP
  1463 000002C4 3A06[0000]              	CMP	AL, [EOT]
  1464 000002C8 7603                    	JBE	EOT_OK2
  1465 000002CA A2[0000]                	MOV	[EOT],AL
  1466                                  EOT_OK2:
  1467                                  
  1468                                  NEXTDRIVE:
  1469 000002CD 80C920                  	OR	CL,FI_OWN_PHYSICAL	; SET THIS TRUE FOR ALL DRIVES
  1470 000002D0 88D7                    	MOV	BH,DL			;SAVE INT13 DRIVE NUMBER
  1471                                  
  1472                                  ; WE NEED TO DO SPECIAL THINGS IF WE HAVE A SINGLE DRIVE SYSTEM AND ARE SETTING
  1473                                  ; UP A LOGICAL DRIVE. IT NEEDS TO HAVE THE SAME INT13 DRIVE NUMBER AS ITS
  1474                                  ; COUNTERPART, BUT THE NEXT DRIVE LETTER. ALSO RESET OWNERSHIP FLAG.
  1475                                  ; WE DETECT THE PRESENCE OF THIS SITUATION BY EXAMINING THE FLAG SINGLE FOR THE
  1476                                  ; VALUE 2.
  1477                                  
  1478 000002D2 E8D306                  	call sysinit_get_ds_dosbiodata
  1479                                   assume ds:DOSGROUP
  1480 000002D5 803E[0000]02            	CMP	byte [SINGLE],2
  1481 000002DA 7505                    	JNZ	NOT_SPECIAL
  1482 000002DC FECF                    	DEC	BH			; INT13 DRIVE NUMBER SAME FOR LOGICAL DRIVE
  1483 000002DE 80F120                  	XOR	CL,FI_OWN_PHYSICAL	; RESET OWNERSHIP FLAG FOR LOGICAL DRIVE
  1484                                  NOT_SPECIAL:
  1485                                  ; THE VALUES THAT WE PUT IN FOR RHDLIM AND RSECLIM WILL ONLY REMAIN IF THE
  1486                                  ; FORM FACTOR IS OF TYPE "FFOTHER".
  1487 000002E1 2E8E1E[0200]            	mov ds, word [cs:nextupb + 2]
  1488                                   assume ds:UPB
  1489 000002E6 2EA1[6C00]              	MOV	ax, [cs:NUM_HEADS]
  1490 000002EA 894536                  	MOV	WORD PTR [DI + RHDLIM],AX
  1491 000002ED 2EA0[6E00]              	MOV	AL,[cs:SEC_TRK]
  1492 000002F1 894534                  	MOV	WORD PTR [DI + RSECLIM],AX
  1493 000002F4 894D23                  	MOV	WORD PTR [DI + FLAGS],CX
  1494 000002F7 887522                  	MOV	BYTE PTR [DI + FORMFACTOR],DH
  1495 000002FA 885505                  	MOV	BYTE PTR [DI + DRIVELET],DL
  1496 000002FD 887D04                  	MOV	BYTE PTR [DI + DRIVENUM],BH
  1497 00000300 2E8A1E[6F00]            	MOV	BL,BYTE PTR [cs:NUM_CYLN]
  1498 00000305 885D25                  	MOV	BYTE PTR [DI + CCYLN],BL	; ONLY THE L.S. BYTE IS SET HERE
  1499 00000308 E8420B                  	call Install_BDSM_and_set_bpb
  1500 0000030B E8AA06                  	call sysinit_get_es_dosbiodata
  1501                                   assume es:DOSGROUP
  1502 0000030E 26803E[0000]01          	CMP	byte [es:SINGLE],1		; SPECIAL CASE FOR SINGLE DRIVE SYSTEM
  1503 00000314 751F                    	JNZ	NO_SINGLE
  1504                                  	MESSAGE FTESTINIT,<"SINGLE DRIVE SYSTEM",CR,LF>
  1505 00000316 26FE06[0000]            	inc	byte [es:SINGLE]		; DON'T LOSE INFO THAT WE HAVE SINGLE SYSTEM
  1506 0000031B 83C910                  	OR	CX,FI_AM_MULT
  1507 0000031E 094D23                  	OR	WORD PTR [DI + FLAGS],CX
  1508 00000321 42                      	inc dx
  1509                                  
  1510 00000322 E851FE                  	call alloc_upb
  1511 00000325 0E                      	push cs
  1512 00000326 1F                      	pop ds
  1513                                   assume ds:SYSINITGROUP, es:UPB
  1514 00000327 BE[0800]                	mov si, BDS_diskette_template	; access with ds
  1515 0000032A 51                      	push cx
  1516 0000032B B96400                  	mov cx, BDS_TYPE_struc_size
  1517 0000032E 57                      	push di
  1518 0000032F F3A4                    	rep movsb
  1519 00000331 5F                      	pop di				; di -> next UPB
  1520 00000332 59                      	pop cx
  1521 00000333 EB98                    	JMP	SHORT NEXTDRIVE 	; USE SAME INFO FOR BDS A PREVIOUS
  1522                                  NO_SINGLE:
  1523 00000335 42                      	inc dx
  1524 00000336 E9D0FE                  	JMP	LOOP_DRIVE
  1525                                  
  1526                                  DONE_DRIVES:
  1527                                  
  1528                                  ; SET UP ALL THE HARD DRIVES IN THE SYSTEM
  1529                                  
  1530                                  DOHARD:
  1531                                   assume ds:nothing, es:nothing, ss:nothing
  1532                                  
  1533                                  extern partition_table, partition_table.end
  1534                                  extern load_mode, load_scan_flags, load_partition_cycle
  1535                                  extern load_current_partition, load_unit, load_amount_units
  1536                                  extern next_block_device_unit
  1537                                  
  1538 00000339 0E                      	push cs
  1539 0000033A 1F                      	pop ds
  1540                                   assume ds:SYSINITGROUP
  1541 0000033B B8[0000]                	mov ax, DiskSector		; ! must be aligned to paragraph boundary
  1542 0000033E B104                    	mov cl, 4
  1543 00000340 D3E8                    	shr ax, cl
  1544 00000342 05[ssss]                	add ax, DOSENTRY
  1545 00000345 A3[0400]                	mov word [Init_BootSeg], ax
  1546 00000348 A0[0000]                	mov al, [HARDNUM]
  1547 0000034B A2[0000]                	mov [next_block_device_unit], al
  1548 0000034E E82F00                  	call .init
  1549                                  
  1550 00000351 F606[0100]80            	testopt [load_mode], mode_dlasort_zero
  1551 00000356 7434                    	jz .once
  1552                                  
  1553 00000358 BB[0F05]                	mov bx, scan_priority_primary
  1554 0000035B E81400                  	call .pass
  1555 0000035E BB[8D05]                	mov bx, scan_early_primary
  1556 00000361 E80E00                  	call .pass
  1557 00000364 BB[AE03]                	mov bx, scan_logical_ignore_lba_if
  1558 00000367 E80800                  	call .pass
  1559 0000036A BB[0F08]                	mov bx, scan_subsequent_primary
  1560 0000036D E80200                  	call .pass
  1561 00000370 EB39                    	jmp .done
  1562                                  
  1563                                  
  1564                                  .pass:
  1565                                  .passloop:
  1566 00000372 E87900                  	call nextunit
  1567 00000375 7209                    	jc .passdone
  1568                                  
  1569 00000377 53                      	push bx
  1570 00000378 B9[FC09]                	mov cx, .each
  1571 0000037B FFD3                    	call bx
  1572 0000037D 5B                      	pop bx
  1573 0000037E EBF2                    	jmp .passloop
  1574                                  
  1575                                  .passdone:
  1576                                  .init:
  1577 00000380 C606[0000]7F            	mov byte [load_unit], 7Fh
  1578 00000385 A0[0000]                	mov al, byte [HNUM]
  1579 00000388 A2[0000]                	mov byte [load_amount_units], al
  1580 0000038B C3                      	retn
  1581                                  
  1582                                  
  1583                                  .once:
  1584 0000038C E85F00                  	call nextunit
  1585 0000038F 721A                    	jc .done
  1586                                  
  1587 00000391 B9[FC09]                	mov cx, .each
  1588 00000394 E87801                  	call scan_priority_primary
  1589 00000397 B9[FC09]                	mov cx, .each
  1590 0000039A E8F001                  	call scan_early_primary
  1591 0000039D B9[FC09]                	mov cx, .each
  1592 000003A0 E80B00                  	call scan_logical_ignore_lba_if
  1593 000003A3 B9[FC09]                	mov cx, .each
  1594 000003A6 E86604                  	call scan_subsequent_primary
  1595 000003A9 EBE1                    	jmp .once
  1596                                  
  1597                                  .each equ handle_each_partition
  1598                                  
  1599                                  .done:
  1600 000003AB E9BC00                  	jmp hdd_done
  1601                                  
  1602                                  
  1603                                  scan_logical_ignore_lba_if:
  1604 000003AE F606[2400]04            	testopt [BDS_harddisk_template + FLAGS], F_LBA
  1605 000003B3 7403E97102              	jnz scan_logical
  1606 000003B8 FF36[0000]              	push word [load_mode]
  1607 000003BC 8026[0000]F3            	clropt [load_mode], mode_first_type_ext15
  1608 000003C1 800E[0000]04            	setopt [load_mode], mode_ignore_ext15
  1609 000003C6 E86002                  	call scan_logical
  1610 000003C9 8F06[0000]              	pop word [load_mode]
  1611 000003CD C3                      	retn
  1612                                  
  1613                                  
  1614                                  scanptab_error:
  1615                                  bootcmd:
  1616                                  .fail_read:
  1617 000003CE 0E                      	 push cs
  1618 000003CF 07                      	 pop es
  1619                                   assume es:SYSINITGROUP
  1620 000003D0 BF[0E0F]                	mov di, msg.bootfail_read_errorcode
  1621 000003D3 88E0                    	mov al, ah
  1622                                  extern hexbyte
  1623 000003D5 E8(0000)                	call hexbyte
  1624 000003D8 BA[E10E]                	mov dx, msg.bootfail_read
  1625                                  .fail:
  1626 000003DB 0E                      	 push cs
  1627 000003DC 07                      	 pop es
  1628                                   assume es:SYSINITGROUP
  1629 000003DD 0E                      	 push cs
  1630 000003DE 1F                      	 pop ds
  1631                                   assume ds:SYSINITGROUP
  1632 000003DF 52                      	push dx
  1633 000003E0 BA[D40E]                	mov dx, msg.bootfail
  1634                                  extern init2_disp_msg_asciz_cs_dx
  1635 000003E3 E8(0000)                	call init2_disp_msg_asciz_cs_dx
  1636 000003E6 5A                      	pop dx
  1637 000003E7 E8(0000)                	call init2_disp_msg_asciz_cs_dx
  1638 000003EA 89EC                    	mov sp, bp			; abort pass
  1639 000003EC 5D                      	pop bp
  1640 000003ED C3                      	retn
  1641                                  
  1642                                  
  1643                                  		; INP:	load_amount_units = remaining amount units
  1644                                  		;	load_unit = prior unit
  1645                                  		; OUT:	CY if units exhausted
  1646                                  		;	NC if another unit follows,
  1647                                  		;	 load_unit = next unit to process
  1648                                  		;	 ds:di -> UPB template,
  1649                                  		;	  with CHS geometry and LBA flag setup
  1650                                  		; CHG:	ax, cx, dx, di, es
  1651                                  		; STT:	ds = cs
  1652                                  nextunit:
  1653                                  .loop:
  1654 000003EE FE06[0000]              	inc byte [load_unit]
  1655                                  
  1656 000003F2 31C0                    	xor ax, ax
  1657 000003F4 A3[0000]                	mov word [load_partition_cycle], ax
  1658                                  
  1659 000003F7 803E[0000]01            	cmp byte [load_amount_units], 1
  1660 000003FC 720E                    	jb .ret			; CY if branching
  1661 000003FE 8A16[0000]              	mov dl, byte [load_unit]
  1662 00000402 E80E00                  	call query_geometry_upb
  1663 00000405 FE0E[0000]              	dec byte [load_amount_units]
  1664 00000409 72E3                    	jc .loop		; just skip unit if error -->
  1665 0000040B F8                      	clc			; NC
  1666                                  .ret:
  1667 0000040C C3                      	retn
  1668                                  
  1669                                  
  1670                                  upb_reset:
  1671 0000040D C606[0700]00            	mov byte [FBIGFAT], 0		; ASSUME 12 BIT FAT
  1672 00000412 C3                      	retn
  1673                                  
  1674                                  
  1675                                  		; INP:	dl = unit number
  1676                                  		; OUT:	CY if error getting geometry
  1677                                  		;	NC if success
  1678                                  		;	ds:di -> UPB template
  1679                                  		; STT:	ds = cs
  1680                                  		; CHG:	ax, cx, dx, di, es
  1681                                  query_geometry_upb:
  1682                                   assume ds:SYSINITGROUP, es:nothing, ss:nothing
  1683                                  extern BDS_harddisk_template
  1684 00000413 BF[0000]                	mov di, BDS_harddisk_template
  1685 00000416 E8F4FF                  	call upb_reset
  1686 00000419 885504                  	mov byte [di + DRIVENUM], dl
  1687 0000041C 53                      	push bx
  1688 0000041D C745232100              	mov word [di + FLAGS], FI_OWN_PHYSICAL | FNON_REMOVABLE
  1689                                  					; F_LBA clear
  1690 00000422 E8FD08                  	call detectlba
  1691 00000425 7204                    	jc .no_lba
  1692 00000427 804D2404                	setopt [di + FLAGS], F_LBA	; set flag
  1693                                  .no_lba:
  1694 0000042B C6452205                	mov byte [di + FORMFACTOR], FFHARDFILE
  1695                                  
  1696 0000042F 57                      	push di
  1697 00000430 B408                    	mov ah, 08h			; set command to get drive parameters
  1698 00000432 F9                      	stc
  1699 00000433 CD13                    	int 13h				; call rom-bios disk routine
  1700 00000435 5F                      	pop di
  1701                                  ; DH IS NUMBER OF HEADS-1
  1702                                  ; DL IS NUMBER OF HARD DISKS ATTACHED
  1703                                  ; LOW 6 BITS OF CL IS SECTORS/TRACK
  1704                                  ; HIGH 2 BITS OF CL WITH CH ARE MAX # OF CYLINDERS
  1705 00000436 86F2                    	xchg dh, dl			; dl = maximum head
  1706 00000438 B600                    	mov dh, 0			; dx = maximum head (preserve CF !)
  1707 0000043A 42                      	inc dx				; GET NUMBER OF HEADS (preserve CF !)
  1708 0000043B 895515                  	mov word [di + HDLIM], dx
  1709 0000043E 5B                      	pop bx
  1710 0000043F 7206                    	jc .ret				; CARRY HERE MEANS NO HARD DISK
  1711 00000441 80E13F                  	and cl, 3Fh			; EXTRACT NUMBER OF SECTORS/TRACK
  1712                                  					; (NC)
  1713 00000444 884D13                  	mov byte [di + SECLIM], cl
  1714                                  .ret:
  1715 00000447 C3                      	retn
  1716                                  
  1717                                  
  1718                                  		; INP:	al = partition type
  1719                                  		; OUT:	CY or NZ or both if not a known type
  1720                                  		;	NC, ZR if known type we can access
  1721                                  		; STT:	ds = cs
  1722                                  load_is_known:
  1723                                   assume ds:SYSINITGROUP, es:nothing, ss:nothing
  1724 00000448 3C01                    	cmp al, ptFAT12
  1725 0000044A 741C                    	je .isknown		; ZR if branches
  1726 0000044C 3C04                    	cmp al, ptFAT16_16BIT_CHS
  1727 0000044E 7418                    	je .isknown		; ZR if branches
  1728 00000450 3C06                    	cmp al, ptFAT16_CHS
  1729 00000452 7414                    	je .isknown		; ZR if branches
  1730 00000454 3C0E                    	cmp al, ptFAT16
  1731 00000456 7510                    	jne .notknown		; NZ if branches
  1732                                  .isknown_lba:
  1733 00000458 F606[2400]04            	testopt [BDS_harddisk_template + FLAGS], F_LBA
  1734 0000045D 7407                    	jz .discard
  1735 0000045F F606[0100]40            	testopt [load_mode], mode_disable_lba
  1736 00000464 7402                    	jz .isknown		; ZR if branches
  1737                                  .discard:
  1738 00000466 F9                      	stc
  1739 00000467 C3                      	retn
  1740                                  
  1741                                  .isknown:
  1742                                  .notknown:
  1743 00000468 F8                      	clc
  1744 00000469 C3                      	retn
  1745                                  
  1746                                  
  1747                                  hdd_done:
  1748                                   assume ds:SYSINITGROUP, es:nothing
  1749 0000046A A0[0000]                	mov al, byte [next_block_device_unit]
  1750 0000046D E84005                  	call sysinit_get_ds_dosentry	; DRVMAX in DOSENTRY
  1751                                   assume ds:DOSENTRYGROUP
  1752 00000470 A2[0000]                	MOV	[DRVMAX],AL
  1753                                  
  1754                                  ; END OF DRIVE INITIALIZATION.
  1755                                  
  1756 00000473 E81009                  	CALL	SETDRVPARMS
  1757                                  
  1758                                  write_dskdrvs_upb:
  1759 00000476 0E                      	push cs
  1760 00000477 1F                      	pop ds
  1761                                   assume ds:SYSINITGROUP
  1762 00000478 C43E[0000]              	les di, [nextupb]
  1763                                   assume es:UPB
  1764 0000047C 8CC0                    	mov ax, es
  1765 0000047E 85C0                    	test ax, ax
  1766 00000480 745D                    	jz .done
  1767 00000482 83C765                  	add di, BDSM_type_struc_size + 1; -> behind last UPB
  1768 00000485 722C                    	jc .mem_err_j
  1769 00000487 83E7FE                  	and di, ~1			; round to word boundary
  1770 0000048A BE[E000]                	mov si, DSKDRVS
  1771 0000048D 8B1E[DE00]              	mov bx, [Mini_BPB_ptr]
  1772 00000491 29F3                    	sub bx, si
  1773 00000493 89D9                    	mov cx, bx
  1774 00000495 01FB                    	add bx, di
  1775 00000497 721A                    	jc .mem_err_j
  1776 00000499 83C30F                  	add bx, 15			; -> behind wanted list
  1777 0000049C 7215                    	jc .mem_err_j
  1778 0000049E 3B1E[0000]              	cmp bx, word [nextupb]
  1779 000004A2 7303E9F9FC              	jb mem_err_j
  1780 000004A7 51                      	push cx
  1781 000004A8 B104                    	mov cl, 4
  1782 000004AA D3EB                    	shr bx, cl			; to paragraphs
  1783 000004AC 59                      	pop cx
  1784 000004AD B44A                    	mov ah, 4Ah
  1785 000004AF CD21                    	int 21h				; resize
  1786 000004B1 7303                    	jnc @F
  1787                                  .mem_err_j:
  1788 000004B3 E9EAFC                  	jmp mem_err_j
  1789                                  @@:
  1790 000004B6 D1E9                    	shr cx, 1
  1791 000004B8 57                      	push di
  1792 000004B9 F3A5                    	rep movsw
  1793 000004BB E8EA04                  	call sysinit_get_ds_dosbiodata
  1794                                   assume ds:DOSGROUP
  1795                                   extern dskdrvs_indirect
  1796 000004BE 8C06[0200]              	mov word [dskdrvs_indirect + 2], es
  1797 000004C2 8F06[0000]              	pop word [dskdrvs_indirect]
  1798                                  
  1799 000004C6 8CC0                    	mov ax, es
  1800 000004C8 48                      	dec ax
  1801 000004C9 8EC0                    	mov es, ax
  1802                                   assume es:MCB
  1803 000004CB 26C70601000800          	mov word [es:arena_owner], 8
  1804                                  				; init owner
  1805 000004D2 BF0500                  	mov di, arena_reserved
  1806 000004D5 0E                      	 push cs
  1807 000004D6 1F                      	 pop ds
  1808                                   assume ds:SYSINITGROUP
  1809 000004D7 BE[E004]                	mov si, upb_smcb
  1810 000004DA B90B00                  	mov cx, 3 + 8
  1811 000004DD F3A4                    	rep movsb		; init name and type
  1812                                  
  1813                                  .done:
  1814 000004DF C3                      	retn
  1815                                  
  1816                                  upb_smcb:
  1817 000004E0 000000                  	db 0,0,0
  1818 000004E3 5300                    	db "S",0		; name "S"
  1819 000004E5 09                      	db 9			; type S_UPB
  1820 000004E6 00<rep 5h>              	times 5 db 0
  1821                                  
  1822                                  
  1823                                  		; INP:	dx:ax = first sector
  1824                                  		;	bx:0 -> buffer
  1825                                  		; OUT:	es = input bx
  1826                                  		;	dx:ax = incremented
  1827                                  		;	bx => after read data
  1828                                  		; CHG:	-
  1829                                  		; STT:	ds = cs
  1830                                  read_ae_512_bytes:
  1831                                   assume ds:SYSINITGROUP
  1832 000004EB 52                      	push dx
  1833 000004EC 50                      	push ax
  1834 000004ED 53                      	push bx
  1835 000004EE 51                      	push cx
  1836 000004EF 8EC3                    	mov es, bx
  1837                                   assume es:nothing
  1838 000004F1 31DB                    	xor bx, bx		; es:bx -> buffer
  1839 000004F3 B90102                  	mov cx, 0201h		; cx = function code and count
  1840 000004F6 57                      	push di
  1841 000004F7 BF[0000]                	mov di, BDS_harddisk_template
  1842                                  				; ds:di -> template
  1843 000004FA E8F107                  	call readsector_flag
  1844 000004FD 5F                      	pop di
  1845 000004FE 7303E9CBFE              	jc scanptab_error
  1846 00000503 59                      	pop cx
  1847 00000504 5B                      	pop bx
  1848 00000505 58                      	pop ax
  1849 00000506 5A                      	pop dx
  1850 00000507 83C320                  	add bx, paras(512)
  1851 0000050A 40                      	inc ax
  1852 0000050B 7501                    	jnz .
  1853 0000050D 42                      	inc dx
  1854                                  .:
  1855 0000050E C3                      	retn
  1856                                  
  1857                                  
  1858                                  overridedef DEBUG4, 0
  1859                                  %define _SCANPTAB_PREFIX
  1860                                  %define _SCANPTAB_DEBUG4_PREFIX
  1861                                  %assign _PARTITION_TABLE_IN_CS 1
  1862                                  %define _BASE bp
  1863                                  %assign _SPT_ELD 0
  1864                                  %assign _MODE 1
  1865                                  %assign _SPT_MULTIPASS 1
  1866                                  %include "scanptab.asm"
     1                              <1> 
     2                              <1> %if 0
     3                              <1> 
     4                              <1> scanptab - Scan partition table
     5                              <1>  2019, 2025 by E. C. Masloch
     6                              <1> 
     7                              <1> Usage of the works is permitted provided that this
     8                              <1> instrument is retained with the works, so that any entity
     9                              <1> that uses the works is notified of this instrument.
    10                              <1> 
    11                              <1> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <1> 
    13                              <1> %endif
    14                              <1> 
    15                              <1> 	; _SCANPTAB_PREFIX = prefix for our variables and functions
    16                              <1> 	; _SCANPTAB_DEBUG4_PREFIX = prefix for d4 function calls
    17                              <1> 	numdef PARTITION_TABLE_IN_CS, 1
    18                              <1> 	numdef BOOTCMD_FAIL_ERROR, 1
    19                              <1> 	numdef SPT_ELD, 0
    20                              <1> 	numdef SPT_MULTIPASS, 0
    21                              <1> %if _SPT_ELD
    22                              <1>  %define sptrel reloc
    23                              <1>  %define sptinternal internaldatarelocation
    24                              <1>  %define sptexternal linkdatarelocation
    25                              <1> 	numdef MODE, 1
    26                              <1> %else
    27                              <1>  %define sptrel
    28                              <1>  %define sptinternal comment
    29                              <1>  %define sptexternal comment
    30                              <1> 	numdef MODE, 0
    31                              <1> %endif
    32                              <1> 	gendef BASE, ss:bx
    33                              <1> %ifidn _BASE, ss:bx
    34                              <1> %elifidn _BASE, bp
    35                              <1> %else
    36                              <1>  %error Invalid base
    37                              <1> %endif
    38                              <1> 
    39                              <1> %if _MODE
    40                              <1>  %include "scanptab.mac"
     1                              <2> 
     2                              <2> %if 0
     3                              <2> 
     4                              <2> scanptab - Scan partition table (macros)
     5                              <2>  2019, 2025 by E. C. Masloch
     6                              <2> 
     7                              <2> Usage of the works is permitted provided that this
     8                              <2> instrument is retained with the works, so that any entity
     9                              <2> that uses the works is notified of this instrument.
    10                              <2> 
    11                              <2> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <2> 
    13                              <2> %endif
    14                              <2> 
    15                              <2> mode_all_ext5			equ 00b
    16                              <2> mode_ignore_ext5		equ 01b
    17                              <2> mode_first_ext5			equ 10b
    18                              <2> mode_first_type_ext5		equ 11b
    19                              <2> 
    20                              <2> mode_all_ext15			equ 00b << 2
    21                              <2> mode_ignore_ext15		equ 01b << 2
    22                              <2> mode_first_ext15		equ 10b << 2
    23                              <2> mode_first_type_ext15		equ 11b << 2
    24                              <2> 
    25                              <2> mode_all_ext85			equ 00b << 4
    26                              <2> mode_ignore_ext85		equ 01b << 4
    27                              <2> mode_first_ext85		equ 10b << 4
    28                              <2> mode_first_type_ext85		equ 11b << 4
    29                              <2> 
    30                              <2> mode_ignore_subsequent_nested	equ            1_00_00_00b
    31                              <2> mode_ignore_subsequent_logical	equ           10_00_00_00b
    32                              <2> mode_ignore_subsequent_primary	equ          100_00_00_00b
    33                              <2> mode_traditional_order_logical	equ         1000_00_00_00b
    34                              <2> mode_active_priority		equ       1_0000_00_00_00b
    35                              <2> mode_subsequent_primary_after	equ      10_0000_00_00_00b
    36                              <2> mode_disable_fat32		equ 00_1000_0000_00_00_00b
    37                              <2> mode_disable_lba		equ 01_0000_0000_00_00_00b
    38                              <2> mode_dlasort_zero		equ 10_0000_0000_00_00_00b
    41                              <1> %endif
    42                              <1> 
    43                              <1> 
    44                              <1> 		; INP:	byte [%load_unit] = unit to scan
    45                              <1> 		;	cx = function to call for each partition
    46                              <1> 		; OUT:	function called for each partition
    47                              <1> 		; CHG:	di, si, ax, bx, (cx), dx, es
    48                              <1> 		; STT:	ds => data segment (used for %load_* variables, unless bp-based)
    49                              <1> 		;
    50                              <1> 		; Note:	Calls %read_partition_table (in this module),
    51                              <1> 		;	 which calls %read_ae_512_bytes, which calls
    52                              <1> 		;	 read_sector. The read_sector base must be
    53                              <1> 		;	 zero and the geometry must be initialised.
    54                              <1> 
    55                              <1> 		; Function in cx is called with:
    56                              <1> 		; INP:	es:si -> partition table entry,
    57                              <1> 		;	 si = %partition_table .. %partition_table+48,
    58                              <1> 		;	 es = ss (if not _PARTITION_TABLE_IN_CS)
    59                              <1> 		;	 es = cs (if _PARTITION_TABLE_IN_CS)
    60                              <1> 		;	byte [%load_current_partition] = partition number,
    61                              <1> 		;	 0 for diskette (unpartitioned),
    62                              <1> 		;	 1 to 4 for primary partitions,
    63                              <1> 		;	 5+ for logical partitions
    64                              <1> 		;	_BASE + di -> above part table metadata,
    65                              <1> 		;	 dword [_BASE + di - 4] = root (outermost extended position)
    66                              <1> 		;	 dword [_BASE + di - 8] = base (current table position)
    67                              <1> 		;	 dword [es:si + piStart] = local partition start
    68                              <1> 		;	 base + local start = absolute partition start
    69                              <1> 		;	_BASE -> bp value (dummy if _BASE is not bp),
    70                              <1> 		;		near return address of scan_partitions
    71                              <1> 		; CHG:	ax, (cx), dx, bx (unless part of _BASE)
    72                              <1> 		; STT:	ds => data segment (used for load_* variables, unless bp-based)
    73                              <1> 		; Note:	preserves (cx), si, di, ds, es, (bp), _BASE
    74                              <1> 		;
    75                              <1> 		; Note:	If the function returns to scan_partitions,
    76                              <1> 		;	 cx must be left as the function to call for
    77                              <1> 		;	 subsequent partitions afterwards.
    78                              <1> 		; Note:	May load sp from _BASE then pop bp then return
    79                              <1> 		;	 near if the scan should stop after the call.
    80                              <1> %if _SPT_MULTIPASS
    81                              <1> %[_SCANPTAB_PREFIX]scan_priority_primary:
    82                              <1> %else
    83                              <1> %[_SCANPTAB_PREFIX]scan_partitions:
    84                              <1> %endif
    85 0000050F 8326[0000]00        <1> sptrel	and word [ %[_SCANPTAB_PREFIX]load_partition_cycle], 0
    86                              <1> sptinternal -3
    87                              <1> d4	call %[_SCANPTAB_DEBUG4_PREFIX]d4message
    88                              <1> d4	asciz "In scan_partitions",13,10
    89                              <1> 
    90 00000514 55                  <1> 	push bp
    91                              <1> %ifidn _BASE, ss:bx
    92                              <1> 	mov bx, sp
    93                              <1> %elifidn _BASE, bp
    94 00000515 89E5                <1> 	mov bp, sp
    95                              <1> %endif
    96 00000517 31FF                <1> 	xor di, di
    97 00000519 57                  <1> 	push di		; [_BASE+di-2]
    98 0000051A 57                  <1> 	push di		; [_BASE+di-4]
    99 0000051B 57                  <1> 	push di		; [_BASE+di-6]
   100 0000051C 57                  <1> 	push di		; [_BASE+di-8]
   101                              <1> %if _MODE
   102 0000051D 893E[0000]          <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], di
   103                              <1> sptinternal
   104                              <1> %endif
   105                              <1> 
   106 00000521 803E[0000]80        <1> sptrel	cmp byte [ %[_SCANPTAB_PREFIX]load_unit], 80h
   107                              <1> sptinternal -3
   108 00000526 7326                <1> 	jae @F
   109                              <1> 
   110 00000528 57                  <1> 	push di
   111 00000529 51                  <1> 	push cx
   112                              <1> %if _PARTITION_TABLE_IN_CS
   113 0000052A 0E                  <1> 	 push cs
   114                              <1> %else
   115                              <1> 	 push ss
   116                              <1> %endif
   117 0000052B 07                  <1> 	 pop es
   118                              <1>  assume es:SYSINITGROUP
   119 0000052C BF[0000]            <1> sptrel	mov di, %[_SCANPTAB_PREFIX]partition_table
   120                              <1> sptinternal
   121 0000052F 31C0                <1> 	xor ax, ax
   122 00000531 B92000              <1> 	mov cx, (4 * 16) >> 1
   123 00000534 F3AB                <1> 	rep stosw			; initialise fake partition table
   124 00000536 59                  <1> 	pop cx
   125 00000537 5F                  <1> 	pop di
   126 00000538 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   127                              <1> sptinternal
   128                              <1> 					; -> fake PARTINFO
   129 0000053B 26C60480            <1> 	mov byte [es:si + piBoot], 80h	; fake primary active
   130 0000053F 26C64404FF          <1> 	mov byte [es:si + piType], 0FFh	; fake a type
   131 00000544 C606[0000]00        <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], 0	; special: 0 = diskette
   132                              <1> sptinternal -3				; piLength is 0, too
   133 00000549 FFD1                <1> 	call cx
   134                              <1> 
   135 0000054B E90302              <1> 	jmp %[_SCANPTAB_PREFIX]scan_logical.end
   136                              <1> 
   137                              <1> 
   138                              <1> @@:
   139                              <1>  %if _SPT_MULTIPASS
   140 0000054E F606[0100]04        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   141                              <1> sptinternal -3			; active primary first ?
   142 00000553 7434                <1> 	jz .end
   143                              <1>  %endif
   144                              <1> 
   145 00000555 31C0                <1> 	xor ax, ax
   146 00000557 31D2                <1> 	xor dx, dx
   147                              <1> d4	call %[_SCANPTAB_DEBUG4_PREFIX]d4message
   148                              <1> d4	asciz "In scan_partitions (before first call to read_partition_table)",13,10
   149 00000559 E86503              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.first
   150                              <1> d4	call %[_SCANPTAB_DEBUG4_PREFIX]d4message
   151                              <1> d4	asciz "In scan_partitions (after first call to read_partition_table)",13,10
   152 0000055C BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   153                              <1> sptinternal
   154 0000055F 8816[0000]          <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], dl	; = 0
   155                              <1> sptinternal
   156                              <1> %if _SPT_ELD
   157                              <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_current_extended_and_is], dx	; = 0
   158                              <1> sptinternal
   159                              <1> %endif
   160                              <1> 
   161                              <1> %if _MODE
   162                              <1>  %ifn _SPT_MULTIPASS
   163                              <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   164                              <1> sptinternal -3			; active primary first ?
   165                              <1> 	jz .active_ignored
   166                              <1>  %endif
   167                              <1> 
   168                              <1> .loop_active_primary:
   169                              <1> 
   170 00000563 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   171                              <1> sptinternal
   172 00000567 268A4404            <1> 	mov al, byte [es:si + piType]
   173 0000056B 3C00                <1> 	cmp al, 0
   174 0000056D 7411                <1> 	je .loop_active_primary_skip
   175 0000056F 26803C00            <1> 	cmp byte [es:si + piBoot], 0
   176 00000573 740B                <1> 	je .loop_active_primary_skip
   177                              <1> 
   178                              <1> 		; INP:	al = partition type
   179                              <1> 		; OUT:	CY if an LBA or FAT32 type that's disabled
   180                              <1> 		;	NC, ZR if known type we can access
   181                              <1> 		;	NC, NZ if unknown type
   182 00000575 E8D0FE              <1> 	call %[_SCANPTAB_PREFIX]load_is_known
   183 00000578 7206                <1> 	jc .loop_active_primary_skip
   184 0000057A 7504                <1> 	jnz .loop_active_primary_skip
   185                              <1> 
   186 0000057C FFD1                <1> 	call cx			; es:si -> partition table entry
   187                              <1> 				; byte [load_current_partition] = which
   188 0000057E EB09                <1> 	jmp .active_done
   189                              <1> 
   190                              <1> .loop_active_primary_skip:
   191 00000580 83C610              <1> 	add si, 16
   192 00000583 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   193                              <1> sptinternal
   194 00000587 72DA                <1> 	jb .loop_active_primary
   195                              <1> 
   196                              <1> .active_done:
   197                              <1> %if _SPT_MULTIPASS
   198                              <1> .end:
   199                              <1> %ifidn _BASE, bp
   200 00000589 89EC                <1> 	mov sp, bp		; restore sp
   201 0000058B 5D                  <1> 	pop bp
   202                              <1> %else
   203                              <1> 	mov sp, bx		; restore sp
   204                              <1> 	pop ax			; (discard dummy bp value)
   205                              <1> %endif
   206 0000058C C3                  <1> 	retn			; and bye
   207                              <1> 
   208                              <1> 
   209                              <1> %[_SCANPTAB_PREFIX]scan_early_primary:
   210 0000058D 8326[0000]00        <1> sptrel	and word [ %[_SCANPTAB_PREFIX]load_partition_cycle], 0
   211                              <1> sptinternal -3
   212                              <1> 
   213 00000592 55                  <1> 	push bp
   214                              <1> %ifidn _BASE, ss:bx
   215                              <1> 	mov bx, sp
   216                              <1> %elifidn _BASE, bp
   217 00000593 89E5                <1> 	mov bp, sp
   218                              <1> %endif
   219 00000595 31FF                <1> 	xor di, di
   220 00000597 57                  <1> 	push di		; [_BASE+di-2]
   221 00000598 57                  <1> 	push di		; [_BASE+di-4]
   222 00000599 57                  <1> 	push di		; [_BASE+di-6]
   223 0000059A 57                  <1> 	push di		; [_BASE+di-8]
   224 0000059B 31C0                <1> 	xor ax, ax
   225 0000059D 31D2                <1> 	xor dx, dx
   226                              <1> 
   227                              <1> %if _MODE
   228 0000059F A3[0000]            <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], ax
   229                              <1> sptinternal
   230                              <1> %endif
   231                              <1> 
   232 000005A2 E81C03              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.first
   233 000005A5 8816[0000]          <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], dl	; = 0
   234                              <1> sptinternal
   235                              <1> %if _SPT_ELD
   236                              <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_current_extended_and_is], dx	; = 0
   237                              <1> sptinternal
   238                              <1> %endif
   239                              <1> %else
   240                              <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], 0
   241                              <1> sptinternal -3
   242                              <1> %endif
   243 000005A9 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   244                              <1> sptinternal
   245                              <1> 
   246                              <1> 
   247 000005AC F606[0100]04        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   248                              <1> sptinternal -3			; active primary first ?
   249 000005B1 7437                <1> 	jz .active_ignored
   250                              <1> 
   251                              <1> .loop_active_skip:
   252                              <1> 
   253 000005B3 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   254                              <1> sptinternal
   255 000005B7 268A4404            <1> 	mov al, byte [es:si + piType]
   256 000005BB 3C00                <1> 	cmp al, 0
   257 000005BD 741A                <1> 	je .loop_active_skip_skip
   258 000005BF 26803C00            <1> 	cmp byte [es:si + piBoot], 0
   259 000005C3 7414                <1> 	je .loop_active_skip_skip
   260                              <1> 
   261                              <1> 		; INP:	al = partition type
   262                              <1> 		; OUT:	CY if an LBA or FAT32 type that's disabled
   263                              <1> 		;	NC, ZR if known type we can access
   264                              <1> 		;	NC, NZ if unknown type
   265 000005C5 E880FE              <1> 	call %[_SCANPTAB_PREFIX]load_is_known
   266 000005C8 720F                <1> 	jc .loop_active_skip_skip
   267 000005CA 750D                <1> 	jnz .loop_active_skip_skip
   268 000005CC A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   269                              <1> sptinternal
   270 000005CF A2[0100]            <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   271                              <1> sptinternal
   272 000005D2 800E[0000]20        <1> sptrel	setopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   273                              <1> sptinternal -3			; mark as had a primary partition yet
   274 000005D7 EB09                <1> 	jmp .active_skip_done
   275                              <1> 
   276                              <1> .loop_active_skip_skip:
   277 000005D9 83C610              <1> 	add si, 16
   278 000005DC 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   279                              <1> sptinternal
   280 000005E0 72D1                <1> 	jb .loop_active_skip
   281                              <1> 
   282                              <1> .active_skip_done:
   283 000005E2 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   284                              <1> sptinternal
   285 000005E5 C606[0000]00        <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], 0
   286                              <1> sptinternal -3
   287                              <1> 
   288                              <1> %endif
   289                              <1> 
   290                              <1> .active_ignored:
   291                              <1> .loop_primary_parts:
   292 000005EA FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   293                              <1> sptinternal
   294 000005EE 26807C0400          <1> 	cmp byte [es:si + piType], 0
   295 000005F3 7427                <1> 	je .loop_primary_skip
   296                              <1> 
   297                              <1> %if _MODE
   298 000005F5 F606[0100]04        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   299                              <1> sptinternal -3			; active primary first ?
   300 000005FA 7409                <1> 	jz @F			; no -->
   301 000005FC A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   302                              <1> sptinternal
   303 000005FF 3806[0100]          <1> sptrel	cmp byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   304                              <1> sptinternal
   305 00000603 7417                <1> 	je .ignoreprimary
   306                              <1> @@:
   307                              <1> 
   308 00000605 F606[0000]20        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   309                              <1> sptinternal -3			; had a primary partition yet ?
   310 0000060A 740E                <1> 	jz .callprimary		; no, accept it -->
   311 0000060C F606[0100]01        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_primary
   312                              <1> sptinternal -3			; ignore subsequent primary ?
   313 00000611 7509                <1> 	jnz .ignoreprimary	; yes, ignore it -->
   314 00000613 F606[0100]08        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_subsequent_primary_after
   315                              <1> sptinternal -3			; subsequent after ?
   316 00000618 7502                <1> 	jnz .ignoreprimary
   317                              <1> .callprimary:
   318                              <1> %endif
   319 0000061A FFD1                <1> 	call cx			; es:si -> partition table entry
   320                              <1> 				; byte [load_current_partition] = which
   321                              <1> .ignoreprimary:
   322                              <1> .loop_primary_skip:
   323 0000061C 83C610              <1> 	add si, 16
   324 0000061F 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   325                              <1> sptinternal
   326 00000623 72C5                <1> 	jb .loop_primary_parts
   327                              <1> 
   328                              <1> %if _SPT_MULTIPASS
   329                              <1> .end:
   330                              <1> %ifidn _BASE, bp
   331 00000625 89EC                <1> 	mov sp, bp		; restore sp
   332 00000627 5D                  <1> 	pop bp
   333                              <1> %else
   334                              <1> 	mov sp, bx		; restore sp
   335                              <1> 	pop ax			; (discard dummy bp value)
   336                              <1> %endif
   337 00000628 C3                  <1> 	retn			; and bye
   338                              <1> 
   339                              <1> 
   340                              <1> %[_SCANPTAB_PREFIX]scan_logical:
   341 00000629 55                  <1> 	push bp
   342                              <1> %ifidn _BASE, ss:bx
   343                              <1> 	mov bx, sp
   344                              <1> %elifidn _BASE, bp
   345 0000062A 89E5                <1> 	mov bp, sp
   346                              <1> %endif
   347 0000062C 31FF                <1> 	xor di, di
   348 0000062E 57                  <1> 	push di		; [_BASE+di-2]
   349 0000062F 57                  <1> 	push di		; [_BASE+di-4]
   350 00000630 57                  <1> 	push di		; [_BASE+di-6]
   351 00000631 57                  <1> 	push di		; [_BASE+di-8]
   352                              <1> 
   353 00000632 31C0                <1> 	xor ax, ax
   354 00000634 31D2                <1> 	xor dx, dx
   355                              <1> %if _MODE
   356 00000636 A3[0000]            <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], ax
   357                              <1> sptinternal
   358                              <1> %endif
   359 00000639 A3[0000]            <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_partition_cycle], ax
   360                              <1> sptinternal
   361 0000063C E88202              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.first
   362 0000063F C606[0000]04        <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], 4
   363                              <1> sptinternal -3
   364                              <1> %if _SPT_ELD
   365                              <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_current_extended_and_is], dx	; = 0
   366                              <1> sptinternal
   367                              <1> %endif
   368                              <1> %else
   369                              <1> 
   370                              <1> %[_SCANPTAB_PREFIX]scan_logical:
   371                              <1> %endif
   372                              <1> .:
   373                              <1> d4	call %[_SCANPTAB_DEBUG4_PREFIX]d4message
   374                              <1> d4	asciz "In scan_logical.",13,10
   375                              <1> 
   376                              <1> %if _MODE
   377 00000644 F606[0100]02        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_traditional_order_logical
   378                              <1> sptinternal -3
   379 00000649 7451                <1> 	jz .nottraditional
   380                              <1> 
   381 0000064B BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   382                              <1> sptinternal
   383                              <1> .loop_traditional:
   384 0000064E FF06[0000]          <1> sptrel	inc word [ %[_SCANPTAB_PREFIX]load_partition_cycle]
   385                              <1> sptinternal
   386 00000652 7503E9AB01          <1> 	jz .got_partition_cycle
   387                              <1> 
   388 00000657 268A4404            <1> 	mov al, [es:si + piType]
   389                              <1> 
   390                              <1> %ifidn _BASE, bp
   391 0000065B 31DB                <1> 	xor bx, bx
   392                              <1> %endif
   393 0000065D 84C0                <1> 	test al, al
   394 0000065F 742D                <1> 	jz .next_traditional
   395 00000661 3C0F                <1> 	cmp al, 0Fh		; extended partition (LBA aware) ?
   396 00000663 7429                <1> 	je .next_traditional	; yes -->
   397 00000665 247F                <1> 	and al, ~80h		; extended partition Linux (85h) ?
   398 00000667 3C05                <1> 	cmp al, 05h		;  or extended partition DOS (05h) ?
   399 00000669 7423                <1> 	je .next_traditional	; yes -->
   400                              <1> 
   401                              <1> %ifidn _BASE, bp
   402 0000066B 395BFE              <1> 	cmp word [_BASE+di-2], bx
   403 0000066E 7505                <1> 	jne .logical_traditional
   404 00000670 395BFC              <1> 	cmp word [_BASE+di-4], bx
   405                              <1> %else
   406                              <1> 	cmp word [_BASE+di-2], 0
   407                              <1> 	jne .logical_traditional
   408                              <1> 	cmp word [_BASE+di-4], 0
   409                              <1> %endif
   410 00000673 7419                <1> 	je .next_traditional
   411                              <1> .logical_traditional:
   412                              <1> 
   413                              <1> %if _MODE
   414 00000675 F606[0000]20        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   415                              <1> sptinternal -3			; had a logical partition yet ?
   416 0000067A 7407                <1> 	jz .calllogicaltrad	; no, accept it -->
   417 0000067C F606[0000]80        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_logical
   418                              <1> sptinternal -3			; ignore subsequent logical ?
   419 00000681 750B                <1> 	jnz .ignorelogicaltrad	; yes, ignore it -->
   420                              <1> .calllogicaltrad:
   421                              <1> %endif
   422                              <1> 
   423 00000683 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   424                              <1> sptinternal
   425 00000687 7503E97C01          <1> 	jz .error_too_many_partitions
   426 0000068C FFD1                <1> 	call cx			; (sets load_scan_flags & 32 if recognised)
   427                              <1> 		; CHG: ax, (cx), dx, bx if _BASE = bp
   428                              <1> 		; preserve: (cx), si, di, ds, es, bx if _BASE = ss:bx
   429                              <1> .ignorelogicaltrad:
   430                              <1> .next_traditional:
   431 0000068E 83C610              <1> 	add si, 16		; -> next partition table entry
   432 00000691 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   433                              <1> sptinternal			; was last?
   434 00000695 72B7                <1> 	jb .loop_traditional	; no, loop -->
   435                              <1> 
   436 00000697 800E[0000]20        <1> sptrel	setopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   437                              <1> sptinternal -3			; mark as had logical
   438                              <1> 
   439                              <1> .nottraditional:
   440                              <1> %endif
   441                              <1> 
   442 0000069C BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   443                              <1> sptinternal
   444                              <1> .loop:
   445 0000069F FF06[0000]          <1> sptrel	inc word [ %[_SCANPTAB_PREFIX]load_partition_cycle]
   446                              <1> sptinternal
   447 000006A3 7503E95A01          <1> 	jz .got_partition_cycle
   448                              <1> 
   449 000006A8 268A4404            <1> 	mov al, [es:si + piType]
   450                              <1> 
   451                              <1> %ifidn _BASE, bp
   452 000006AC 31DB                <1> 	xor bx, bx
   453                              <1> %endif
   454 000006AE 84C0                <1> 	test al, al
   455 000006B0 7503E98C00          <1> 	jz .next
   456                              <1> %if _MODE
   457                              <1> %ifidn _BASE, bp
   458 000006B5 395BFE              <1> 	cmp word [_BASE+di-2], bx
   459 000006B8 754B                <1> 	jne .allextended
   460 000006BA 395BFC              <1> 	cmp word [_BASE+di-4], bx
   461                              <1> %else
   462                              <1> 	cmp word [_BASE+di-2], 0
   463                              <1> 	jne .allextended
   464                              <1> 	cmp word [_BASE+di-4], 0
   465                              <1> %endif
   466 000006BD 7546                <1> 	jne .allextended
   467                              <1> 
   468 000006BF 8A26[0000]          <1> sptrel	mov ah, [ %[_SCANPTAB_PREFIX]load_mode ]
   469                              <1> sptinternal
   470 000006C3 3C05                <1> 	cmp al, 5
   471 000006C5 7410                <1> 	je .check
   472 000006C7 D0EC                <1> 	shr ah, 1
   473 000006C9 D0EC                <1> 	shr ah, 1
   474 000006CB 3C0F                <1> 	cmp al, 15
   475 000006CD 7408                <1> 	je .check
   476 000006CF D0EC                <1> 	shr ah, 1
   477 000006D1 D0EC                <1> 	shr ah, 1
   478 000006D3 3C85                <1> 	cmp al, 85h
   479 000006D5 7546                <1> 	jne .notextended
   480                              <1> .check:
   481 000006D7 8026[0000]EF        <1> sptrel	clropt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 16
   482                              <1> sptinternal -3			; new outermost extended
   483                              <1> 
   484 000006DC F6C403              <1> 	test ah, 11b
   485 000006DF 7474                <1> 	jz .push		; if it is 00b = all, always accept -->
   486 000006E1 F6C402              <1> 	test ah, 10b		; if prior is NZ but this is zero
   487 000006E4 745B                <1> 	jz .ignoreextended	;  then we have 01b, always ignore -->
   488 000006E6 F6C401              <1> 	test ah, 01b		; if prior is NZ and this is NZ,
   489                              <1> 	; jnz .firsttype	;  then we have 11b, accept first of type
   490 000006E9 B401                <1> 	mov ah, 1		; flag 1 for 10b
   491 000006EB 740C                <1> 	jz @F			; if ZR, we have 10b, accept first of all types with 10b
   492                              <1> .firsttype:
   493 000006ED B402                <1> 	mov ah, 2		; flag 2 for 11b type 5
   494 000006EF 3C0F                <1> 	cmp al, 15
   495 000006F1 7206                <1> 	jb @F
   496 000006F3 B404                <1> 	mov ah, 4		; flag 4 for 11b type 15
   497 000006F5 7402                <1> 	je @F
   498 000006F7 B408                <1> 	mov ah, 8		; flag 8 for 11b type 85h
   499                              <1> @@:
   500 000006F9 8426[0000]          <1> sptrel	test byte [ %[_SCANPTAB_PREFIX]load_scan_flags ], ah
   501                              <1> sptinternal			; seen one of those before ?
   502 000006FD 7542                <1> 	jnz .ignoreextended	; yes, ignore -->
   503 000006FF 0826[0000]          <1> sptrel	or byte [ %[_SCANPTAB_PREFIX]load_scan_flags ], ah
   504                              <1> sptinternal			; no, note seen it now
   505 00000703 EB50                <1> 	jmp .push		; and process extended partition -->
   506                              <1> %endif
   507                              <1> 
   508                              <1> .allextended:
   509                              <1> %if _MODE
   510 00000705 F606[0000]40        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_nested
   511                              <1> sptinternal -3
   512 0000070A 7407                <1> 	jz @F
   513 0000070C F606[0000]10        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 16
   514                              <1> sptinternal -3
   515 00000711 752E                <1> 	jnz .ignoreextended
   516                              <1> @@:
   517                              <1> %endif
   518 00000713 3C0F                <1> 	cmp al, 0Fh		; extended partition (LBA aware) ?
   519 00000715 743E                <1> 	je .push		; yes -->
   520 00000717 247F                <1> 	and al, ~80h		; extended partition Linux (85h) ?
   521 00000719 3C05                <1> 	cmp al, 05h		;  or extended partition DOS (05h) ?
   522 0000071B 7438                <1> 	je .push		; yes -->
   523                              <1> .notextended:
   524                              <1> 
   525                              <1> %ifidn _BASE, bp
   526 0000071D 395BFE              <1> 	cmp word [_BASE+di-2], bx
   527 00000720 7505                <1> 	jne .logical
   528 00000722 395BFC              <1> 	cmp word [_BASE+di-4], bx
   529                              <1> %else
   530                              <1> 	cmp word [_BASE+di-2], 0
   531                              <1> 	jne .logical
   532                              <1> 	cmp word [_BASE+di-4], 0
   533                              <1> %endif
   534 00000725 741A                <1> 	je .next
   535                              <1> .logical:
   536                              <1> 
   537                              <1> %if _MODE
   538 00000727 F606[0000]20        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   539                              <1> sptinternal -3			; had a logical partition yet ?
   540 0000072C 7408                <1> 	jz .calllogical		; no, accept it -->
   541 0000072E F706[0000]8002      <1> sptrel	test word [ %[_SCANPTAB_PREFIX]load_mode ], strict word 		mode_ignore_subsequent_logical | mode_traditional_order_logical
   543                              <1> sptinternal -4			; ignore subsequent logical or post-trad run ?
   544 00000734 750B                <1> 	jnz .ignorelogical	; yes, ignore it -->
   545                              <1> .calllogical:
   546                              <1> %endif
   547                              <1> 
   548 00000736 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   549                              <1> sptinternal
   550 0000073A 7503E9C900          <1> 	jz .error_too_many_partitions
   551 0000073F FFD1                <1> 	call cx			; (sets load_scan_flags & 32 if recognised)
   552                              <1> 		; CHG: ax, (cx), dx, bx if _BASE = bp
   553                              <1> 		; preserve: (cx), si, di, ds, es, bx if _BASE = ss:bx
   554                              <1> .ignorelogical:
   555                              <1> .ignoreextended:
   556                              <1> .next:
   557 00000741 83C610              <1> 	add si, 16		; -> next partition table entry
   558 00000744 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   559                              <1> sptinternal			; was last?
   560 00000748 7303E952FF          <1> 	jb .loop		; no, loop -->
   561 0000074D 85FF                <1> 	test di, di		; still some on stack?
   562 0000074F 756A                <1> 	jnz .pop		; yes, pop
   563                              <1> .end:
   564                              <1> %ifidn _BASE, bp
   565 00000751 89EC                <1> 	mov sp, bp		; restore sp
   566 00000753 5D                  <1> 	pop bp
   567                              <1> %else
   568                              <1> 	mov sp, bx		; restore sp
   569                              <1> 	pop ax			; (discard dummy bp value)
   570                              <1> %endif
   571                              <1> %if _MODE && ! _SPT_MULTIPASS
   572                              <1> 	jmp scan_subsequent_primary
   573                              <1> %else
   574 00000754 C3                  <1> 	retn			; and bye
   575                              <1> %endif
   576                              <1> 
   577                              <1> 
   578                              <1> .push:
   579                              <1> d4	call %[_SCANPTAB_DEBUG4_PREFIX]d4message
   580                              <1> d4	asciz "In scan_logical.push",13,10
   581                              <1> 
   582                              <1> %if _SPT_ELD
   583                              <1> sptrel	rol byte [ %[_SCANPTAB_PREFIX]extended], 1
   584                              <1> sptinternal
   585                              <1> 	jnc @F
   586                              <1> sptrel	not byte [ %[_SCANPTAB_PREFIX]load_is_extended]
   587                              <1> sptinternal
   588                              <1> 
   589                              <1> 	push si
   590                              <1> 	sub di, 10			; address temporary root and base
   591                              <1> 	push word [_BASE+di+10-2]
   592                              <1> 	push word [_BASE+di+10-4]	; copy root as root
   593                              <1> 	push word [_BASE+di+10-2]
   594                              <1> 	push word [_BASE+di+10-4]	; copy root as base
   595                              <1> 		; Extended partitions always have LBA start values
   596                              <1> 		;  relative to the outermost extended partition.
   597                              <1> 		;  Therefore the "root" must be used as base for
   598                              <1> 		;  this call to always get the expected address
   599                              <1> 		;  from dword [bp - di - 8] + dword [es:si + 8].
   600                              <1> 
   601                              <1> 	call cx
   602                              <1> 
   603                              <1> 	add sp, 8			; discard temporary root and base
   604                              <1> 	add di, 10			; point back to prior root and base
   605                              <1> 	pop si				; undo last part of the stack frame
   606                              <1> 
   607                              <1> sptrel	not byte [ %[_SCANPTAB_PREFIX]load_is_extended]
   608                              <1> sptinternal
   609                              <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_extended]
   610                              <1> sptinternal
   611                              <1> %ifidn _BASE, bp
   612                              <1> 	xor bx, bx
   613                              <1> %endif
   614                              <1> @@:
   615                              <1> %endif
   616                              <1> 
   617 00000755 56                  <1> 	push si
   618                              <1> .push_check_empty_next:
   619 00000756 83C610              <1> 	add si, 16		; -> next
   620 00000759 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   621                              <1> sptinternal			; at end?
   622 0000075D 7203E98400          <1> 	jae .replace		; yes, no other partitions found, replace -->
   623 00000762 26807C0400          <1> 	cmp byte [es:si + piType], 0	; is this a partition?
   624 00000767 74ED                <1> 	je .push_check_empty_next	; no, check next -->
   625                              <1> 				; found a partition after this, do push
   626                              <1> 				; (possibly logical or another extended)
   627                              <1> .push_check_is_not_empty:
   628                              <1> d4	call %[_SCANPTAB_DEBUG4_PREFIX]d4message
   629                              <1> d4	asciz "In scan_logical.push_check_is_not_empty",13,10
   630                              <1> 
   631                              <1> %if _MODE
   632 00000769 31C0                <1> 	xor ax, ax		; sentinel 0 = accept more logicals
   633                              <1> 
   634 0000076B F606[0100]02        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_traditional_order_logical
   635                              <1> sptinternal -3
   636 00000770 750E                <1> 	jnz .traditionalsentinel
   637 00000772 F606[0000]20        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   638                              <1> sptinternal -3			; had a logical partition in this table ?
   639 00000777 7409                <1> 	jz @F			; no, no need to reset -->
   640 00000779 F606[0000]80        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_logical
   641                              <1> sptinternal -3			; ignore subsequent logical ?
   642 0000077E 7402                <1> 	jz @F			; no -->
   643                              <1> .traditionalsentinel:
   644 00000780 B040                <1> 	mov al, 64		; sentinel 64 = no more logicals
   645                              <1> @@:
   646 00000782 8026[0000]DF        <1> sptrel	clropt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   647                              <1> sptinternal -3			; accept a logical partition in next table
   648                              <1> %endif
   649                              <1> 
   650 00000787 5E                  <1> 	pop si			; restore -> partition table entry
   651                              <1> %if _MODE
   652 00000788 26FF7408            <1> 	push word [es:si + piStart]
   653 0000078C 268B540A            <1> 	mov dx, word [es:si + piStart + 2]	; get extended partition offset
   654 00000790 01C6                <1> 	add si, ax		; now -> behind partition_table if sentinel set
   655 00000792 58                  <1> 	pop ax
   656                              <1> %endif
   657 00000793 56                  <1> 	push si			; stored at word [_BASE+di-10]
   658 00000794 83EF0A              <1> 	sub di, 10
   659 00000797 FF7308              <1> 	push word [_BASE+di+10-2]
   660 0000079A FF7306              <1> 	push word [_BASE+di+10-4]	; copy root
   661                              <1> %ifn _MODE
   662                              <1> 	mov ax, word [es:si + piStart]
   663                              <1> 	mov dx, word [es:si + piStart + 2]	; get extended partition offset
   664                              <1> %endif
   665 0000079D 0343FC              <1> 	add ax, word [_BASE+di-4]
   666 000007A0 1353FE              <1> 	adc dx, word [_BASE+di-2]	; add in root to get absolute sector number
   667                              <1> 
   668 000007A3 52                  <1> 	push dx
   669 000007A4 50                  <1> 	push ax			; new base
   670                              <1> 
   671                              <1> .replace_common:
   672                              <1> %ifidn _BASE, bp
   673 000007A5 395BFE              <1> 	cmp word [_BASE+di-2], bx	; have a (nonzero) root?
   674 000007A8 750B                <1> 	jne .have_root
   675 000007AA 395BFC              <1> 	cmp word [_BASE+di-4], bx
   676                              <1> %else
   677                              <1> 	cmp word [_BASE+di-2], 0	; have a (nonzero) root?
   678                              <1> 	jne .have_root
   679                              <1> 	cmp word [_BASE+di-4], 0
   680                              <1> %endif
   681 000007AD 7506                <1> 	jne .have_root		; yes -->
   682                              <1> 
   683 000007AF 8953FE              <1> 	mov word [_BASE+di-2], dx
   684 000007B2 8943FC              <1> 	mov word [_BASE+di-4], ax	; set root
   685                              <1> .have_root:
   686                              <1> 
   687 000007B5 E80901              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.first
   688 000007B8 E989FE              <1> 	jmp .
   689                              <1> 
   690                              <1> .pop:
   691                              <1> d4	call %[_SCANPTAB_DEBUG4_PREFIX]d4message
   692                              <1> d4	asciz "In scan_logical.pop",13,10
   693                              <1> 
   694                              <1> %if _MODE
   695 000007BB 800E[0000]10        <1> sptrel	setopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 16
   696                              <1> sptinternal -3			; remember we found a nested extended partition
   697                              <1> 				;  so we can ignore others in the same outermost
   698                              <1> %endif
   699                              <1> 
   700 000007C0 83C70A              <1> 	add di, 10
   701 000007C3 83C408              <1> 	add sp, 8
   702 000007C6 5E                  <1> 	pop si
   703                              <1> 
   704                              <1> %if _MODE
   705 000007C7 8026[0000]DF        <1> sptrel	clropt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   706                              <1> sptinternal -3			; accept a logical partition in this table
   707 000007CC 81FE[4000]          <1> sptrel	cmp si, 64 + %[_SCANPTAB_PREFIX]partition_table
   708                              <1> sptinternal			; sentinel set ?
   709 000007D0 7208                <1> 	jb @F			; no -->
   710 000007D2 800E[0000]20        <1> sptrel	setopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   711                              <1> sptinternal -3			; do not accept a logical partition in this table
   712 000007D7 83EE40              <1> 	sub si, 64		; undo sentinel addition
   713                              <1> @@:
   714                              <1> %endif
   715 000007DA 8B43F8              <1> 	mov ax, word [_BASE+di-8]
   716 000007DD 8B53FA              <1> 	mov dx, word [_BASE+di-6]
   717 000007E0 E8DE00              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.reload
   718 000007E3 E95BFF              <1> 	jmp .next
   719                              <1> 
   720                              <1> .replace:
   721                              <1> d4	call %[_SCANPTAB_DEBUG4_PREFIX]d4message
   722                              <1> d4	asciz "In scan_logical.replace",13,10
   723                              <1> %if _MODE
   724 000007E6 8026[0000]DF        <1> sptrel	clropt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   725                              <1> sptinternal -3			; accept a logical partition in next table
   726                              <1> %endif
   727                              <1> 
   728 000007EB 5E                  <1> 	pop si				; (discard)
   729                              <1> .replace_no_pop:
   730 000007EC 268B4408            <1> 	mov ax, word [es:si + piStart]
   731 000007F0 268B540A            <1> 	mov dx, word [es:si + piStart + 2]	; get extended partition offset
   732 000007F4 0343FC              <1> 	add ax, word [_BASE+di - 4]
   733 000007F7 1353FE              <1> 	adc dx, word [_BASE+di - 2]	; add in root
   734 000007FA 8943F8              <1> 	mov word [_BASE+di - 8], ax
   735 000007FD 8953FA              <1> 	mov word [_BASE+di - 6], dx	; set base
   736                              <1> 
   737 00000800 EBA3                <1> 	jmp .replace_common
   738                              <1> 
   739                              <1> 
   740                              <1> %if _BOOTCMD_FAIL_ERROR
   741                              <1> .got_partition_cycle:
   742 00000802 BA[AF0F]            <1> sptrel	mov dx, msg.boot_partition_cycle_error
   743                              <1> sptinternal
   744 00000805 E9D3FB              <1> 	jmp bootcmd.fail
   745                              <1> 
   746                              <1> .error_too_many_partitions:
   747 00000808 BA[8C0F]            <1> sptrel	mov dx, msg.boot_too_many_partitions_error
   748                              <1> sptinternal
   749 0000080B E9CDFB              <1> 	jmp bootcmd.fail
   750                              <1> %endif
   751                              <1> 
   752                              <1> 
   753                              <1> %if _MODE
   754                              <1> @@:
   755 0000080E C3                  <1> 	retn
   756                              <1> 
   757                              <1> scan_subsequent_primary:
   758 0000080F F606[0100]01        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_primary
   759                              <1> sptinternal -3			; ignore subsequent primary ?
   760 00000814 75F8                <1> 	jnz @B			; yes -->
   761 00000816 F606[0100]08        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_subsequent_primary_after
   762                              <1> sptinternal -3			; subsequent after ?
   763 0000081B 74F1                <1> 	jz @B			; no -->
   764                              <1> 
   765 0000081D 55                  <1> 	push bp
   766                              <1> %ifidn _BASE, ss:bx
   767                              <1> 	mov bx, sp
   768                              <1> %elifidn _BASE, bp
   769 0000081E 89E5                <1> 	mov bp, sp
   770                              <1> %endif
   771 00000820 31FF                <1> 	xor di, di
   772 00000822 57                  <1> 	push di		; [_BASE+di-2]
   773 00000823 57                  <1> 	push di		; [_BASE+di-4]
   774 00000824 57                  <1> 	push di		; [_BASE+di-6]
   775 00000825 57                  <1> 	push di		; [_BASE+di-8]
   776                              <1> 
   777                              <1> %if ! _SPT_MULTIPASS
   778                              <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], di
   779                              <1> sptinternal
   780                              <1> %endif
   781                              <1> 
   782 00000826 31C0                <1> 	xor ax, ax
   783 00000828 31D2                <1> 	xor dx, dx
   784                              <1> 
   785                              <1> %if _SPT_MULTIPASS
   786 0000082A A3[0000]            <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], ax
   787                              <1> sptinternal
   788                              <1> %endif
   789                              <1> 
   790 0000082D E89100              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.reload
   791                              <1> 				; (re)read MBR
   792 00000830 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   793                              <1> sptinternal
   794 00000833 8816[0000]          <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], dl	; = 0
   795                              <1> sptinternal
   796                              <1> %if _SPT_ELD
   797                              <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_current_extended_and_is], dx	; = 0
   798                              <1> sptinternal
   799                              <1> %endif
   800                              <1> 
   801 00000837 F606[0100]04        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   802                              <1> sptinternal -3			; active primary first ?
   803 0000083C 742A                <1> 	jz .detect_lowest
   804                              <1> 
   805                              <1> .loop_active_skip:
   806                              <1> 
   807 0000083E FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   808                              <1> sptinternal
   809 00000842 268A4404            <1> 	mov al, byte [es:si + piType]
   810 00000846 3C00                <1> 	cmp al, 0
   811 00000848 7415                <1> 	je .loop_active_skip_skip
   812 0000084A 26803C00            <1> 	cmp byte [es:si + piBoot], 0
   813 0000084E 740F                <1> 	je .loop_active_skip_skip
   814                              <1> 
   815                              <1> 		; INP:	al = partition type
   816                              <1> 		; OUT:	CY if an LBA or FAT32 type that's disabled
   817                              <1> 		;	NC, ZR if known type we can access
   818                              <1> 		;	NC, NZ if unknown type
   819 00000850 E8F5FB              <1> 	call %[_SCANPTAB_PREFIX]load_is_known
   820 00000853 720A                <1> 	jc .loop_active_skip_skip
   821 00000855 7508                <1> 	jnz .loop_active_skip_skip
   822 00000857 A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   823                              <1> sptinternal
   824 0000085A A2[0100]            <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   825                              <1> sptinternal
   826 0000085D EB37                <1> 	jmp .active_skip_done
   827                              <1> 
   828                              <1> .loop_active_skip_skip:
   829 0000085F 83C610              <1> 	add si, 16
   830 00000862 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   831                              <1> sptinternal
   832 00000866 72D6                <1> 	jb .loop_active_skip
   833                              <1> 
   834                              <1> .detect_lowest:
   835 00000868 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   836                              <1> sptinternal
   837 0000086B C606[0000]00        <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], 0
   838                              <1> sptinternal -3
   839                              <1> 
   840                              <1> .loop_lowest:
   841 00000870 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   842                              <1> sptinternal
   843 00000874 268A4404            <1> 	mov al, byte [es:si + piType]
   844 00000878 3C00                <1> 	cmp al, 0
   845 0000087A 740F                <1> 	je .loop_lowest_skip_skip
   846                              <1> 
   847                              <1> 		; INP:	al = partition type
   848                              <1> 		; OUT:	CY if an LBA or FAT32 type that's disabled
   849                              <1> 		;	NC, ZR if known type we can access
   850                              <1> 		;	NC, NZ if unknown type
   851 0000087C E8C9FB              <1> 	call %[_SCANPTAB_PREFIX]load_is_known
   852 0000087F 720A                <1> 	jc .loop_lowest_skip_skip
   853 00000881 7508                <1> 	jnz .loop_lowest_skip_skip
   854 00000883 A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   855                              <1> sptinternal
   856 00000886 A2[0100]            <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   857                              <1> sptinternal
   858 00000889 EB0B                <1> 	jmp .lowest_skip_done
   859                              <1> 
   860                              <1> .loop_lowest_skip_skip:
   861 0000088B 83C610              <1> 	add si, 16
   862 0000088E 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   863                              <1> sptinternal
   864 00000892 72DC                <1> 	jb .loop_lowest
   865 00000894 EB27                <1> 	jmp .end		; none found
   866                              <1> 
   867                              <1> .lowest_skip_done:
   868                              <1> .active_skip_done:
   869 00000896 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   870                              <1> sptinternal
   871 00000899 C606[0000]00        <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], 0
   872                              <1> sptinternal -3
   873                              <1> 
   874                              <1> .loop_primary_parts:
   875 0000089E FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   876                              <1> sptinternal
   877 000008A2 26807C0400          <1> 	cmp byte [es:si + piType], 0
   878 000008A7 740B                <1> 	je .loop_primary_skip
   879                              <1> 
   880                              <1> %if _MODE
   881 000008A9 A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   882                              <1> sptinternal
   883 000008AC 3806[0100]          <1> sptrel	cmp byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   884                              <1> sptinternal
   885 000008B0 7402                <1> 	je .ignoreprimary
   886                              <1> %endif
   887 000008B2 FFD1                <1> 	call cx			; es:si -> partition table entry
   888                              <1> 				; byte [load_current_partition] = which
   889                              <1> .ignoreprimary:
   890                              <1> .loop_primary_skip:
   891 000008B4 83C610              <1> 	add si, 16
   892 000008B7 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   893                              <1> sptinternal
   894 000008BB 72E1                <1> 	jb .loop_primary_parts
   895                              <1> 
   896                              <1> .end:
   897                              <1> %ifidn _BASE, bp
   898 000008BD 89EC                <1> 	mov sp, bp		; restore sp
   899 000008BF 5D                  <1> 	pop bp
   900                              <1> %else
   901                              <1> 	mov sp, bx		; restore sp
   902                              <1> 	pop ax			; (discard dummy bp value)
   903                              <1> %endif
   904 000008C0 C3                  <1> 	retn
   905                              <1> %endif
   906                              <1> 
   907                              <1> 
   908                              <1> 		; if _PARTITION_TABLE_IN_CS:
   909                              <1> 		; INP:  dx:ax = partition table sector to read
   910                              <1> 		; CHG:	ax, dx
   911                              <1> 		; OUT:  es = cs
   912                              <1> 		;       64 bytes [es:partition_table] = partition table
   913                              <1> 		;       does not return if error
   914                              <1> 
   915                              <1> 		; else:
   916                              <1> 		; INP:  dx:ax = partition table sector to read
   917                              <1> 		; CHG:	ax, dx
   918                              <1> 		; OUT:  es = ss
   919                              <1> 		;       64 bytes [es:partition_table] = partition table
   920                              <1> 		;       does not return if error
   921                              <1> %[_SCANPTAB_PREFIX]read_partition_table:
   922                              <1> %if _SPT_ELD
   923                              <1> .first:
   924                              <1> 	db __TEST_IMM8			; NC, skip stc
   925                              <1> .reload:
   926                              <1> 	stc
   927                              <1> %else
   928                              <1> .first:
   929                              <1> .reload:
   930                              <1> %endif
   931                              <1> 
   932 000008C1 53                  <1> 	push bx
   933                              <1> %if _SPT_ELD
   934                              <1> sptrel	mov bx, word [buffersegment]
   935                              <1> sptinternal
   936                              <1> %elifidn _BASE, bp
   937 000008C2 8B1E[0400]          <1> 	mov bx, word [auxbuff_segorsel]	; bx => auxbuff
   938                              <1> %else
   939                              <1> 	mov bx, word [bp + ldSectorSeg]
   940                              <1> %endif
   941 000008C6 E822FC              <1> 	call %[_SCANPTAB_PREFIX]read_ae_512_bytes
   942                              <1>  assume es:nothing
   943 000008C9 5B                  <1> 	pop bx
   944 000008CA 26813EFE0155AA      <1> 	cmp word [es:510], 0AA55h
   945 000008D1 7518                <1> 	jne .signature_fail
   946 000008D3 1E                  <1> 	 push ds
   947 000008D4 57                  <1> 	 push di
   948 000008D5 56                  <1> 	 push si
   949 000008D6 51                  <1> 	 push cx
   950 000008D7 06                  <1> 	push es
   951 000008D8 1F                  <1> 	pop ds
   952                              <1>  assume ds:nothing
   953 000008D9 BEBE01              <1> 	mov si, 510 - 4*16		; ds:si -> partition table in sectorseg
   954                              <1> %if _PARTITION_TABLE_IN_CS
   955 000008DC 0E                  <1> 	push cs
   956                              <1> %else
   957                              <1> 	push ss
   958                              <1> %endif
   959 000008DD 07                  <1> 	pop es
   960                              <1>  assume es:SYSINITGROUP
   961 000008DE BF[0000]            <1> sptrel	mov di, %[_SCANPTAB_PREFIX]partition_table
   962                              <1> sptinternal				; es:di -> cs:%[_SCANPTAB_PREFIX]partition_table
   963 000008E1 B92000              <1> 	mov cx, 4*16 / 2
   964 000008E4 F3A5                <1> 	rep movsw
   965 000008E6 59                  <1> 	 pop cx
   966 000008E7 5E                  <1> 	 pop si
   967 000008E8 5F                  <1> 	 pop di
   968 000008E9 1F                  <1> 	 pop ds
   969                              <1>  assume ds:SYSINITGROUP
   970 000008EA C3                  <1> 	retn
   971                              <1> 
   972                              <1> 
   973                              <1> %if _BOOTCMD_FAIL_ERROR
   974                              <1> .signature_fail:
   975 000008EB BA[580F]            <1> sptrel	mov dx, msg.bootfail_sig_parttable
   976                              <1> sptinternal
   977 000008EE E9EAFA              <1> 	jmp bootcmd.fail
   978                              <1> %endif
  1867                                  resetdef DEBUG4
  1868                                  
  1869                                  
  1870                                  usesection DOSENTRYINIT
  1871                                  
  1872                                  ;J.K. 9/24/86 We now decide, based on the configurations available so far, what
  1873                                  ;code or data we need to keep as a stay resident code.	The following table
  1874                                  ;shows the configurations under consideration.	They are listed in the order
  1875                                  ;of their current position memory.
  1876                                  ;Configuration will be done in two ways:
  1877                                  ;First, we are going to set "Static configuration".  Static configuration will
  1878                                  ;consider from basic configuration to ENDOF96TPI configuration.  The result
  1879                                  ;of static configuration will be the address the Dynamic configuration will
  1880                                  ;use to start with.
  1881                                  ;Secondly, "Dynamic cofiguration" will be performed.  Dynamic configuration
  1882                                  ;involves possible relocation of CODE or DATA.	Dynamic configuration routine
  1883                                  ;will take care of BDSM tables and AT ROM Fix module thru K09 suspend/resume
  1884                                  ;code individually.  After these operation, FINAL_DOS_LOCATION will be set.
  1885                                  ;This will be the place SYSINIT routine will relocate MSDOS module for good.
  1886                                  ;
  1887                                  ;   1.	 BASIC CONFIGURATION FOR IBMBIO (EndFloppy, EndSwap)
  1888                                  ;   2.	 ENDONEHARD
  1889                                  ;   3.	 ENDTWOHARD
  1890                                  ;   4.	 END96TPI	;a system that supports "Change Line Error"
  1891                                  ;   5.	 End of BDSM	;BDSM tables for mini disks.
  1892                                  ;   6.	 ENDATROM	;Some of AT ROM fix module.
  1893                                  ;   7.	 ENDCMOSCLOCKSET;Supporting program for CMOS clock write.
  1894                                  ;   8.	 ENDK09 	;K09 CMOS Clock module to handle SUSPEND/RESUME operation.
  1895                                  ;
  1896                                  ; lDOS: Only END96TPI and ENDATROM are still used of all these.
  1897                                  ;  END96TPI and ENDFLOPPY are equal now, so only the first one
  1898                                  ;  is still used. (END96TPI is in ms96tpi.nas included by
  1899                                  ;  msbio2.nas, which aligns to a paragraph boundary before
  1900                                  ;  mshard.nas's IBM_DISK_IO. The latter is the start of the
  1901                                  ;  "AT ROM fix module" that ends at ENDATROM.)
  1902                                  ; Update lDOS 2025 September: Instead of END96TPI now the label
  1903                                  ;  DOSENTRY_INIT_START is used (in mshard.nas).
  1904                                  ; The UPBs (aka BDS tables) are handled later by INITUPB (in
  1905                                  ;  SYSINIT segment, source in this file) and are allocated
  1906                                  ;  using an S MCB as the DOS is already available then. (The
  1907                                  ;  UPBs are relocated into HMA, UMA, or LMA later.)
  1908                                  ; The CMOS and K09 code is now in the DOSCODE segment, except
  1909                                  ;  for the i6C entrypoint (in entry.asm).
  1910                                  
  1911                                  ;J.K. 9/24/86.
  1912                                  
  1913                                  STATIC_CONFIGURE:
  1914                                   assume ds:nothing, es:nothing, ss:nothing
  1915                                   extern DOSENTRY_INIT_START
  1916 000003BC B8[0000]                	mov	ax, DOSENTRY_INIT_START
  1917 000003BF E84D03                  	call dosentry_init_get_ds_dosbiodata
  1918                                   assume ds:DOSGROUP
  1919                                  fHave96 equ FHAVE96	; NASM port label
  1920 000003C2 803E[0000]00            	cmp	byte [fHave96], 0		;Is change line support there?
  1921                                  Config96 equ CONFIG96	; NASM port label
  1922 000003C7 7502                    	jnz	Config96		;Yes.
  1923                                  
  1924                                  Basic_Floppy:
  1925                                  	; mov	ax, offset ENDFLOPPY
  1926                                  		; ldos: do leave DOSENTRY data up to END96TPI resident
  1927                                  		; ldos: ENDFLOPPY equals END96TPI now that the code
  1928                                  		;  has been moved out of the DOSENTRY section.
  1929                                  Dynamic_Configure equ DYNAMIC_CONFIGURE	; NASM port label
  1930 000003C9 EB24                    	jmp	Dynamic_Configure	;static configuration is done!
  1931                                  
  1932                                  ;
  1933                                  ; KEEP THE 96TPI CODE
  1934                                  ;
  1935                                  CONFIG96:
  1936                                  ;
  1937                                  ; SAVE OLD INT 13 VECTOR
  1938                                  ;
  1939 000003CB 0E                      	push cs
  1940 000003CC 1F                      	pop ds
  1941                                   assume ds:DOSENTRYGROUP
  1942 000003CD 1E                      	push ds
  1943 000003CE 07                      	pop es
  1944                                   assume ds:DOSENTRYGROUP, es:DOSENTRYGROUP
  1945                                  
  1946 000003CF 50                      	PUSH	AX
  1947 000003D0 1E                      	PUSH	DS
  1948 000003D1 31C0                    	XOR	AX,AX
  1949 000003D3 8ED8                    	MOV	DS,AX
  1950                                   assume ds:IVT
  1951                                  
  1952 000003D5 A14C00                  	MOV	AX,[4 * 13H]
  1953 000003D8 26A3[0000]              	MOV	WORD PTR [es:REAL13],AX
  1954 000003DC A14E00                  	MOV	AX,[4 * 13H+2]
  1955 000003DF 26A3[0200]              	MOV	WORD PTR [es:REAL13+2],AX
  1956                                  ;
  1957                                  ; INSERT NEW VECTOR
  1958                                  ;
  1959                                  extern ms96tpi_i13
  1960 000003E3 C7064C00[0000]          	MOV	WORD PTR [4 * 13H],OFFSET ms96tpi_i13
  1961 000003E9 8C064E00                	MOV	[4 * 13H + 2], es
  1962                                  
  1963 000003ED 1F                      	POP	DS
  1964                                   assume ds:DOSENTRYGROUP
  1965 000003EE 58                      	POP	AX
  1966                                  
  1967                                  DYNAMIC_CONFIGURE:
  1968 000003EF 1E                      	push ds
  1969 000003F0 07                      	pop es
  1970                                   assume es:DOSENTRYGROUP
  1971 000003F1 FC                      	cld					;clear direction
  1972                                  
  1973                                  CheckATROM:
  1974 000003F2 E82A03                  	call	Get_Para_Offset			;For dynamic allocation, we are
  1975                                  						;going to use offset address that
  1976                                  						;is in paragraph boundary.
  1977                                  
  1978                                  
  1979 000003F5 E81703                  	call dosentry_init_get_ds_dosbiodata
  1980                                   assume ds:DOSGROUP
  1981 000003F8 803E[0000]FC            	cmp	byte [Model_Byte], 0FCh		;AT ?
  1982 000003FD 753F                    	jnz	CheckCMOSClock
  1983                                  
  1984 000003FF 50                      	push ax
  1985 00000400 B280                    	mov	DL, 80h			; tell rom bios to look at hard drives
  1986 00000402 B408                    	mov	AH, 8h			; set command to get drive parameter
  1987 00000404 F9                      	stc
  1988 00000405 CD13                    	int	13h			; call ROM-BIOS to get number of drives
  1989 00000407 58                      	pop ax
  1990 00000408 7234                    	jc	CheckCMOSClock
  1991 0000040A 84D2                    	test dl, dl			; No hard file?
  1992 0000040C 7430                    	jz	CheckCMOSClock
  1993                                  
  1994 0000040E BE00F0                  	mov	si, 0F000h
  1995 00000411 8EC6                    	mov	es, si			       ;ES -> BIOS segment
  1996                                  	assume	es:nothing		       ;
  1997 00000413 0E                      	push cs
  1998 00000414 1F                      	pop ds
  1999                                   assume ds:DOSENTRYGROUP
  2000 00000415 BE[0100]                	mov	si, offset BIOS_DATE	       ;
  2001 00000418 BFF5FF                  	mov	di, 0FFF5H		       ;ROM BIOS string is at F000:FFF5
  2002                                  Cmpbyte:				       ;Only patch ROM for bios dated 01/10/84
  2003 0000041B A6                      	cmpsb				       ;
  2004 0000041C 7520                    	jnz	CheckCMOSClock		       ;
  2005 0000041E 807CFF00                	cmp	byte ptr [si-1],0	       ;
  2006 00000422 75F7                    	jnz	Cmpbyte 		       ;
  2007                                  SetRomCode:				       ;Now we have to install ROM fix
  2008                                  					       ;AX is the address to move.
  2009 00000424 1E                      	push ds
  2010 00000425 07                      	pop es
  2011                                   assume es:DOSENTRYGROUP
  2012                                  
  2013 00000426 A3[0000]                	mov	word ptr [ORIG13], ax
  2014 00000429 8C1E[0200]              	mov	word ptr [ORIG13+2], ds		;set new ROM bios int 13 vector
  2015 0000042D B9[0000]                	mov	cx, offset ENDATROM
  2016 00000430 BE[0000]                	mov	si, offset IBM_DISK_IO
  2017 00000433 29F1                    	sub	cx, si				;size of AT ROM FIX module
  2018 00000435 89C7                    	mov	di, ax				;destination
  2019 00000437 F3A4                    	rep	movsb				;relocate it
  2020 00000439 89F8                    	mov	ax, di				;new ending address
  2021 0000043B E8E102                  	call	Get_Para_Offset 		;in AX
  2022                                  
  2023                                  CheckCMOSClock:
  2024 0000043E 0E                      	push cs
  2025 0000043F 1F                      	pop ds
  2026                                   assume ds:DOSENTRYGROUP
  2027 00000440 1E                      	push	ds
  2028 00000441 07                      	pop	es				;set ES to CODE seg
  2029                                   assume ds:DOSENTRYGROUP, es:DOSENTRYGROUP
  2030                                  
  2031                                  CheckK09:
  2032                                  ;SB33025****************************************************************
  2033 00000442 50                      	push	ax			;save ax		     ;SB  ;3.30*
  2034 00000443 06                      	push es
  2035                                  
  2036 00000444 B4C0                    	mov ah, 0C0h
  2037 00000446 F9                      	stc
  2038 00000447 CD15                    	int 15h
  2039                                   assume es:nothing
  2040 00000449 7210                    	jc .no_k09_if_CY
  2041 0000044B 26F6470508              	test byte [es:bx + 5], 1 << 3
  2042 00000450 F9                      	stc
  2043 00000451 7408                    	jz .no_k09_if_CY
  2044                                  
  2045 00000453 B80041                  	mov	ax,4100h		;Q: is it a K09 	     ;SB  ;3.30*
  2046 00000456 B300                    	mov	bl,0			;			     ;SB  ;3.30*
  2047 00000458 F9                      	stc
  2048 00000459 CD15                    	int	15h			;			     ;SB  ;3.30*
  2049                                  ;SB33025****************************************************************
  2050                                  .no_k09_if_CY:
  2051 0000045B 07                      	pop es
  2052                                   assume es:DOSENTRYGROUP
  2053 0000045C 58                      	pop	ax
  2054 0000045D 721A                    	jc	CONFIGDONE
  2055                                  
  2056 0000045F 50                      	push	ax
  2057 00000460 1E                      	push	ds
  2058 00000461 E8AB02                  	call dosentry_init_get_ds_dosbiodata
  2059                                   assume ds:DOSGROUP
  2060                                  fHaveK09 equ FHAVEK09	; NASM port label
  2061 00000464 C606[0000]01            	mov	byte [fHaveK09], 1			;remember we have a K09 type
  2062 00000469 31C0                    	xor	ax,ax
  2063 0000046B 8ED8                    	mov	ds, ax
  2064                                   assume ds:IVT
  2065                                  
  2066                                   extern i6C
  2067 0000046D C706B001[C600]          	mov	word ptr [4 * 6Ch], i6C	;new INT 6Ch handler
  2068 00000473 8C0EB201                	mov	[4 * 6Ch +2], cs
  2069                                  
  2070 00000477 1F                      	pop	ds
  2071                                   assume ds:DOSENTRYGROUP
  2072 00000478 58                      	pop	ax				;restore the ending address
  2073                                  
  2074                                  ; SET UP CONFIG STUFF FOR SYSINIT
  2075                                  
  2076                                  CONFIGDONE:			;AX is final ending address of MSBIO.
  2077 00000479 BA[ssss]                	MOV	DX,SYSINITSEG
  2078 0000047C 8EDA                    	MOV	DS,DX
  2079                                   assume ds:SYSINITGROUP
  2080                                  
  2081                                  	; SUB	AX,OFFSET START$	; (zero)
  2082 0000047E 83C00F                  	ADD	AX,15
  2083 00000481 D1D8                    	RCR	AX,1
  2084 00000483 D1E8                    	SHR	AX, 1
  2085 00000485 D1E8                    	SHR	AX, 1
  2086 00000487 D1E8                    	SHR	AX, 1
  2087 00000489 05[ssss]                	add ax, DOSENTRY
  2088 0000048C A3[0000]                	MOV	[behind_dosentry_segment], AX
  2089 0000048F 2EA0[0000]              	mov al, [cs:DRVMAX]
  2090 00000493 A2[0000]                	mov [HARDNUM], al		; REMEMBER WHICH DRIVE IS HARD DISK
  2091                                  
  2092                                  	MESSAGE FTESTINIT,<"FINAL DOS LOCATION IS ">
  2093                                  	MNUM	FTESTINIT,FINAL_DOS_LOCATION
  2094                                  	MESSAGE FTESTINIT,<CR,LF>
  2095 00000496 0E                      	PUSH	CS
  2096 00000497 1F                      	POP	DS
  2097                                  
  2098                                   assume ds:DOSENTRYGROUP, es:nothing
  2099                                  
  2100                                  %if 0
  2101                                  call_purge_96tpi:
  2102                                  	CMP	BYTE [FHAVE96],0
  2103                                  	JNZ	.no
  2104                                  	CALL	PURGE_96TPI		;MJB001 ELIMINATE CALLS TO 96TPI HOOHAH
  2105                                  .no
  2106                                  %endif
  2107                                  
  2108                                  relocate_sysinit_and_early_dos:
  2109                                  	MESSAGE FTESTINIT,<"SYSINIT",CR,LF>
  2110                                  	ZWAIT
  2111                                  	MESSAGE FTESTINIT,<"ON TO SYSINIT...",CR,LF>
  2112                                  
  2113                                  extern SYSSIZE, afterdosdatalabel, afterdoscodelabel, doscode_start, doscode_mcb
  2114                                  
  2115 00000498 BB[ssss]                	mov bx, SYSINITMCB
  2116 0000049B 8EDB                    	mov ds, bx
  2117                                   assume ds:nothing
  2118 0000049D B104                    	mov cl, 4
  2119 0000049F D32E0300                	shr word [mcbSize], cl		; make paragraphs
  2120 000004A3 BB[ssss]                	mov bx, DOSDATAMCB
  2121 000004A6 8EDB                    	mov ds, bx
  2122                                   assume ds:nothing
  2123 000004A8 D32E0300                	shr word [mcbSize], cl		; make paragraphs
  2124                                  %if _RELOCATEDOSCODE
  2125                                  	mov bx, DOSCODEGROUP
  2126                                  	mov ds, bx
  2127                                   assume ds:DOSCODEGROUP
  2128                                  	shr word [doscode_mcb + mcbSize], cl
  2129                                  					; make paragraphs
  2130                                  %endif
  2131                                  
  2132 000004AC B8[1000]                	MOV AX, SYSSIZE + 16 wrt SYSINITSEG
  2133 000004AF E87800                  	call dosentry_init_ParaRound
  2134 000004B2 91                      	xchg cx, ax
  2135                                  %if _RELOCATEDOSCODE
  2136                                  	mov ax, afterdoscodelabel wrt DOSCODEGROUP
  2137                                  	call dosentry_init_ParaRound
  2138                                  %else
  2139 000004B3 31C0                    	xor ax, ax
  2140                                  %endif
  2141                                  
  2142 000004B5 BB[ssss]                	mov bx, SYSINITSEG
  2143 000004B8 8EDB                    	mov ds, bx
  2144                                   assume ds:SYSINITGROUP
  2145 000004BA 8B16[0000]              	mov dx, [MEMORY_SIZE]
  2146 000004BE 29CA                    	sub dx, cx			; => SYSINIT destination
  2147 000004C0 7234                    	jc .oom
  2148 000004C2 83EA18                  	sub dx, paras(SYSINITSTACK)	; leave stack buffer
  2149 000004C5 722F                    	jc .oom
  2150 000004C7 89D6                    	mov si, dx
  2151 000004C9 83EA01                  	sub dx, 1			; leave buffer for first UMCB,
  2152                                  					;  => SYSINIT MCB destination
  2153 000004CC 7628                    	jbe .oom
  2154 000004CE 29C2                    	sub dx, ax			; => early DOSCODE destination
  2155 000004D0 89D7                    	mov di, dx
  2156 000004D2 7222                    	jc .oom
  2157 000004D4 01C1                    	add cx, ax
  2158                                  
  2159 000004D6 B8[0000]                	mov ax, afterdosdatalabel wrt DOSSTART
  2160 000004D9 E84E00                  	call dosentry_init_ParaRound
  2161 000004DC 29C2                    	sub dx, ax			; => early DOSDATA destination
  2162 000004DE 7216                    	jc .oom
  2163 000004E0 52                      	push dx
  2164 000004E1 83EA01                  	sub dx, 1			; => DOSDATA S MCB
  2165 000004E4 7210                    	jc .oom
  2166 000004E6 01C1                    	add cx, ax
  2167 000004E8 41                      	inc cx
  2168                                  
  2169                                  		; Note: This check is only valid if there is no
  2170                                  		;  data to still be used between the relocate
  2171                                  		;  block and the end of the DOSENTRY section.
  2172                                  		; This is now true with DOSDATA being relocated.
  2173 000004E9 B8[C205]                	mov ax, end_of_dosentry_init_late
  2174 000004EC E83B00                  	call dosentry_init_ParaRound
  2175 000004EF 05[ssss]                	add ax, DOSENTRY
  2176 000004F2 39C2                    	cmp dx, ax
  2177 000004F4 7316                    	jae @F
  2178                                  
  2179                                  .oom:
  2180                                  dosentry_init_oom:
  2181 000004F6 BE[C205]                	mov si, dosentry_init_msg.oom	; access with cs
  2182 000004F9 B40E                    	mov ah, 0Eh
  2183 000004FB BB0700                  	mov bx, 7
  2184 000004FE A9                      	db __TEST_IMM16			; skip int
  2185                                  .msgloop:
  2186 000004FF CD10                    	int 10h
  2187 00000501 2EAC                    	cs lodsb
  2188 00000503 84C0                    	test al, al
  2189 00000505 75F8                    	jnz .msgloop
  2190                                  .halt:
  2191 00000507 CC                      	int3
  2192 00000508 FB                      	sti
  2193 00000509 F4                      	hlt
  2194 0000050A EBFB                    	jmp .halt
  2195                                  
  2196                                  @@:
  2197 0000050C 5D                      	pop bp
  2198 0000050D FA                      	cli
  2199                                  	align 2, nop
  2200                                  .stack:
  2201 0000050E 0E                      	push cs
  2202 0000050F 17                      	pop ss
  2203 00000510 BC[0E05]                	mov sp, .stack
  2204                                   assume ss:DOSENTRYGROUP
  2205                                  %if (.stack - INIT) < 512
  2206                                   %error Too small DOSENTRY init stack
  2207                                  %endif
  2208 00000513 B8[ssss]                	mov ax, DOSDATAMCB
  2209 00000516 E81D00                  	call dosentry_init_movp
  2210                                  
  2211 00000519 31C0                    	xor ax, ax
  2212 0000051B 8ED8                    	mov ds, ax
  2213                                   assume ds:IVT
  2214 0000051D 95                      	xchg ax, bp
  2215 0000051E A3C600                  	mov word [31h * 4 + 2], ax	; init => DOSDATA
  2216                                  %if _RELOCATEDOSCODE
  2217                                  	mov ds, ax
  2218                                   assume ds:DOSGROUP
  2219                                  	mov word [dosdata_to_doscode], di
  2220                                  	mov ax, DOSENTRY
  2221                                  	mov ds, ax
  2222                                   assume ds:DOSENTRYGROUP
  2223                                   extern ..@dosentry_doscode_segment
  2224                                  	mov word [..@dosentry_doscode_segment], di
  2225                                  %endif
  2226 00000521 FB                      	sti
  2227                                  
  2228                                   extern GOINIT
  2229 00000522 89D1                    	mov cx, dx			; => DOSDATA S MCB
  2230 00000524 B8[0000]                	mov ax, GOINIT
  2231 00000527 56                      	push si
  2232 00000528 50                      	push ax
  2233 00000529 CB                      	retf
  2234                                  
  2235                                  INIT	ENDP
  2236                                  
  2237                                  
  2238                                  dosentry_init_ParaRound:
  2239                                   assume ds:nothing, es:nothing, ss:nothing
  2240 0000052A 83C00F                  	ADD	AX,15
  2241 0000052D D1D8                    	RCR	AX,1
  2242 0000052F D1E8                    	SHR	AX,1
  2243 00000531 D1E8                    	SHR	AX,1
  2244 00000533 D1E8                    	SHR	AX,1
  2245 00000535 C3                      	retn
  2246                                  
  2247                                  
  2248                                  		; Move paragraphs
  2249                                  		;
  2250                                  		; INP:	ax:0-> source
  2251                                  		;	dx:0-> destination
  2252                                  		;	cx = number of paragraphs
  2253                                  		; CHG:	-
  2254                                  		; Note:	Doesn't work correctly on HMA; doesn't always wrap to LMA either.
  2255                                  		;	Do not provide a wrapped/HMA source or destination!
  2256                                  dosentry_init_movp:
  2257                                   assume ds:nothing, es:nothing, ss:nothing
  2258 00000536 51                      	push cx
  2259 00000537 1E                      	push ds
  2260 00000538 56                      	push si
  2261 00000539 06                      	push es
  2262 0000053A 57                      	push di
  2263                                  
  2264 0000053B 39D0                    	cmp ax, dx		; source above destination ?
  2265 0000053D 770A                    	ja .up			; yes, move up (forwards) -->
  2266 0000053F 747B                    	je .return		; same, no need to move -->
  2267 00000541 50                      	push ax
  2268 00000542 01C8                    	add ax, cx		; (expected not to carry)
  2269 00000544 39D0                    	cmp ax, dx		; end of source is above destination ?
  2270 00000546 58                      	pop ax
  2271 00000547 7730                    	ja .down		; yes, move from top down -->
  2272                                  	; Here, the end of source is below-or-equal the destination,
  2273                                  	;  so they do not overlap. In this case we prefer moving up.
  2274                                  
  2275                                  .up:
  2276 00000549 50                      	push ax
  2277 0000054A 52                      	push dx
  2278                                  .uploop:
  2279 0000054B 8ED8                    	mov ds, ax
  2280 0000054D 8EC2                    	mov es, dx
  2281                                   assume ds:nothing, es:nothing
  2282 0000054F 31FF                    	xor di, di
  2283 00000551 31F6                    	xor si, si		; -> start of segment
  2284 00000553 81E90010                	sub cx, 1000h		; 64 KiB left ?
  2285 00000557 7610                    	jbe .uplast		; no -->
  2286 00000559 51                      	push cx
  2287 0000055A B90080                  	mov cx, 10000h /2
  2288 0000055D F3A5                    	rep movsw		; move 64 KiB
  2289 0000055F 59                      	pop cx
  2290 00000560 050010                  	add ax, 1000h
  2291 00000563 81C20010                	add dx, 1000h		; -> next segment
  2292 00000567 EBE2                    	jmp short .uploop	; proceed for more -->
  2293                                  .uplast:
  2294 00000569 81C10010                	add cx, 1000h		; restore counter
  2295 0000056D D1E1                    	shl cx, 1
  2296 0000056F D1E1                    	shl cx, 1
  2297 00000571 D1E1                    	shl cx, 1		; *8, paragraphs to words
  2298 00000573 F3A5                    	rep movsw		; move last part
  2299 00000575 5A                      	pop dx
  2300 00000576 58                      	pop ax
  2301 00000577 EB43                    	jmp short .return
  2302                                  
  2303                                  .down:
  2304 00000579 FD                      	std			; _AMD_ERRATUM_109_WORKAROUND as below
  2305                                  .dnloop:
  2306 0000057A 81E90010                	sub cx, 1000h		; 64 KiB left ?
  2307 0000057E 761A                    	jbe .dnlast		; no -->
  2308 00000580 50                      	push ax
  2309 00000581 52                      	push dx
  2310 00000582 01C8                    	add ax, cx
  2311 00000584 01CA                    	add dx, cx
  2312 00000586 8ED8                    	mov ds, ax		; -> 64 KiB not yet moved
  2313 00000588 8EC2                    	mov es, dx
  2314                                   assume ds:nothing, es:nothing
  2315 0000058A 5A                      	pop dx
  2316 0000058B 58                      	pop ax
  2317 0000058C BFFEFF                  	mov di, -2
  2318 0000058F 89FE                    	mov si, di		; moved from last word down
  2319 00000591 51                      	push cx
  2320 00000592 B90080                  	mov cx, 10000h /2
  2321 00000595 F3A5                    	rep movsw		; move 64 KiB
  2322 00000597 59                      	pop cx
  2323 00000598 EBE0                    	jmp short .dnloop	; proceed for more -->
  2324                                  .dnlast:
  2325 0000059A 81C10010                	add cx, 1000h		; restore counter
  2326 0000059E D1E1                    	shl cx, 1
  2327 000005A0 D1E1                    	shl cx, 1
  2328 000005A2 D1E1                    	shl cx, 1		; *8, paragraphs to words
  2329 000005A4 89CF                    	mov di, cx
  2330 000005A6 4F                      	dec di
  2331 000005A7 D1E7                    	shl di, 1		; words to offset, -> last word
  2332 000005A9 89FE                    	mov si, di
  2333 000005AB 8ED8                    	mov ds, ax
  2334 000005AD 8EC2                    	mov es, dx		; first segment correct
  2335                                   assume ds:nothing, es:nothing
  2336                                  
  2337                                  
  2338                                  	numdef AMD_ERRATUM_109_WORKAROUND, 1
  2339                                  %if 0
  2340                                  
  2341                                  Jack R. Ellis pointed out this erratum:
  2342                                  
  2343                                  Quoting from https://www.amd.com/system/files/TechDocs/25759.pdf page 69:
  2344                                  
  2345                                  109   Certain Reverse REP MOVS May Produce Unpredictable Behavior
  2346                                  
  2347                                  Description
  2348                                  
  2349                                  In certain situations a REP MOVS instruction may lead to
  2350                                  incorrect results. An incorrect address size, data size
  2351                                  or source operand segment may be used or a succeeding
  2352                                  instruction may be skipped. This may occur under the
  2353                                  following conditions:
  2354                                  
  2355                                  * EFLAGS.DF=1 (the string is being moved in the reverse direction).
  2356                                  
  2357                                  * The number of items being moved (RCX) is between 1 and 20.
  2358                                  
  2359                                  * The REP MOVS instruction is preceded by some microcoded instruction
  2360                                    that has not completely retired by the time the REP MOVS begins
  2361                                    execution. The set of such instructions includes BOUND, CLI, LDS,
  2362                                    LES, LFS, LGS, LSS, IDIV, and most microcoded x87 instructions.
  2363                                  
  2364                                  Potential Effect on System
  2365                                  
  2366                                  Incorrect results may be produced or the system may hang.
  2367                                  
  2368                                  Suggested Workaround
  2369                                  
  2370                                  Contact your AMD representative for information on a BIOS update.
  2371                                  
  2372                                  %endif
  2373                                  
  2374                                  %if _AMD_ERRATUM_109_WORKAROUND
  2375 000005AF E308                    	jcxz @FF
  2376 000005B1 83F914                  	cmp cx, 20
  2377 000005B4 7703                    	ja @FF
  2378                                  @@:
  2379 000005B6 A5                      	movsw
  2380 000005B7 E2FD                    	loop @B
  2381                                  @@:
  2382                                  %endif
  2383 000005B9 F3A5                    	rep movsw		; move first part
  2384 000005BB FC                      	cld
  2385                                  .return:
  2386 000005BC 5F                      	pop di
  2387 000005BD 07                      	pop es
  2388                                   assume es:nothing
  2389 000005BE 5E                      	pop si
  2390 000005BF 1F                      	pop ds
  2391                                   assume ds:nothing
  2392 000005C0 59                      	pop cx
  2393 000005C1 C3                      	retn
  2394                                  
  2395                                  end_of_dosentry_init_late:
  2396                                  
  2397                                  dosentry_init_msg:
  2398 000005C2 6C444F53206C6F6164-     .oom:	asciz "lDOS load error: Out of memory for SYSINIT relocation.",13,10
  2398 000005CB 206572726F723A204F-
  2398 000005D4 7574206F66206D656D-
  2398 000005DD 6F727920666F722053-
  2398 000005E6 5953494E4954207265-
  2398 000005EF 6C6F636174696F6E2E-
  2398 000005F8 0D0A00             
  2399                                  
  2400                                  
  2401                                   global cmdline_noop, cmdline_checkdebugger, cmdline_verbose, cmdline_scanmode
  2402                                   global cmdline_haltflag
  2403                                  cmdline_noop:
  2404 000005FB C3                      	retn
  2405                                  
  2406                                  
  2407                                  cmdline_error:
  2408                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2409                                   extern invalid_number
  2410 000005FC BE[0000]                	mov si, invalid_number
  2411 000005FF BB0700                  	mov bx, 7
  2412 00000602 A9                      	db __TEST_IMM16		; skip int
  2413                                  @@:
  2414 00000603 CD10                    	int 10h
  2415 00000605 AC                      	lodsb
  2416 00000606 B40E                    	mov ah, 0Eh
  2417 00000608 84C0                    	test al, al
  2418 0000060A 75F7                    	jnz @B
  2419 0000060C 3E8B7600                	mov si, word [ds:bp]	; -> command name
  2420 00000610 A9                      	db __TEST_IMM16		; skip int
  2421                                  @@:
  2422 00000611 CD10                    	int 10h
  2423 00000613 AC                      	lodsb
  2424 00000614 B40E                    	mov ah, 0Eh
  2425 00000616 84C0                    	test al, al
  2426 00000618 75F7                    	jnz @B
  2427                                  @@:
  2428 0000061A B8220E                  	mov ax, 0E00h + '"'
  2429 0000061D CD10                    	int 10h
  2430 0000061F B80D0E                  	mov ax, 0E00h + 13
  2431 00000622 CD10                    	int 10h
  2432 00000624 B80A0E                  	mov ax, 0E00h + 10
  2433 00000627 CD10                    	int 10h
  2434 00000629 C3                      	retn
  2435                                  
  2436                                  
  2437                                  		; INP:	ds:si -> after number
  2438                                  		; OUT:	ZR if NUL reached
  2439                                  		;	NZ if not NUL,
  2440                                  		;	 ds:si -> first non-blank, non-comma, non-NUL
  2441                                  		;	 al = byte [ds:si]
  2442                                  cmdline_next:
  2443                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2444                                  .:
  2445 0000062A AC                      	lodsb
  2446 0000062B 3C20                    	cmp al, 32
  2447 0000062D 74FB                    	je .
  2448 0000062F 3C09                    	cmp al, 9
  2449 00000631 74F7                    	je .
  2450 00000633 3C2C                    	cmp al, ','
  2451 00000635 74F3                    	je .
  2452 00000637 4E                      	dec si
  2453 00000638 84C0                    	test al, al
  2454 0000063A C3                      	retn
  2455                                  
  2456                                  
  2457                                  		; INP:	si -> past an optional equals sign and blanks
  2458                                  		;	di -> -> command name
  2459                                  		; CHG:	ax, si, di, cx, bx, dx, bp
  2460                                  		; STT:	ds = es => SYSINIT
  2461                                  		;	cs => DOSENTRY
  2462                                  cmdline_checkdebugger:
  2463                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2464 0000063B 89FD                    	mov bp, di
  2465                                  .loop:
  2466 0000063D E8B000                  	call parsenumber
  2467 00000640 72BA                    	jc cmdline_error
  2468 00000642 84F6                    	test dh, dh
  2469 00000644 75B6                    	jnz cmdline_error
  2470 00000646 80FB01                  	cmp bl, 1
  2471 00000649 7209                    	jb .or
  2472 0000064B 740E                    	je .clr
  2473                                  .replace:
  2474 0000064D 2E8816[0000]            	mov byte [cs:checkdebugger], dl
  2475 00000652 EB0E                    	jmp .next
  2476                                  
  2477                                  .or:
  2478 00000654 2E0816[0000]            	or byte [cs:checkdebugger], dl
  2479 00000659 EB07                    	jmp .next
  2480                                  
  2481                                  .clr:
  2482 0000065B F6D2                    	not dl
  2483 0000065D 2E2016[0000]            	and byte [cs:checkdebugger], dl
  2484                                  .next:
  2485 00000662 E8C5FF                  	call cmdline_next
  2486 00000665 75D6                    	jnz .loop
  2487 00000667 C3                      	retn
  2488                                  
  2489                                  
  2490                                  		; INP:	si -> past an optional equals sign and blanks
  2491                                  		;	di -> -> command name
  2492                                  		; CHG:	ax, si, di, cx, bx, dx, bp
  2493                                  		; STT:	ds = es => SYSINIT
  2494                                  		;	cs => DOSENTRY
  2495                                  cmdline_verbose:
  2496                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2497 00000668 89FD                    	mov bp, di
  2498                                  .loop:
  2499 0000066A E88300                  	call parsenumber
  2500 0000066D 728D                    	jc cmdline_error
  2501 0000066F 84F6                    	test dh, dh
  2502 00000671 7589                    	jnz cmdline_error
  2503 00000673 80FB01                  	cmp bl, 1
  2504 00000676 7208                    	jb .or
  2505 00000678 740C                    	je .clr
  2506                                  .replace:
  2507 0000067A 8816[0000]              	mov byte [verbose_mode], dl
  2508 0000067E EB0C                    	jmp .next
  2509                                  
  2510                                  .or:
  2511 00000680 0816[0000]              	or byte [verbose_mode], dl
  2512 00000684 EB06                    	jmp .next
  2513                                  
  2514                                  .clr:
  2515 00000686 F6D2                    	not dl
  2516 00000688 2016[0000]              	and byte [verbose_mode], dl
  2517                                  .next:
  2518 0000068C E89BFF                  	call cmdline_next
  2519 0000068F 75D9                    	jnz .loop
  2520 00000691 C3                      	retn
  2521                                  
  2522                                  
  2523                                  cmdline_scanmode:
  2524                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2525 00000692 89FD                    	mov bp, di
  2526                                  .loop:
  2527                                   extern sysinit_cmdline_scanmode_keyword
  2528 00000694 9A[0000][ssss]          	call far sysinit_cmdline_scanmode_keyword
  2529                                  					; ! call far into unrelocated SYSINIT
  2530 00000699 730F                    	jnc .replace
  2531 0000069B E85200                  	call parsenumber
  2532 0000069E 7303E959FF              	jc cmdline_error
  2533 000006A3 80FB01                  	cmp bl, 1
  2534 000006A6 7208                    	jb .or
  2535 000006A8 740C                    	je .clr
  2536                                  .replace:
  2537 000006AA 8916[0000]              	mov word [load_mode], dx
  2538 000006AE EB0C                    	jmp .next
  2539                                  
  2540                                  .or:
  2541 000006B0 0916[0000]              	or word [load_mode], dx
  2542 000006B4 EB06                    	jmp .next
  2543                                  
  2544                                  .clr:
  2545 000006B6 F7D2                    	not dx
  2546 000006B8 2116[0000]              	and word [load_mode], dx
  2547                                  .next:
  2548 000006BC E86BFF                  	call cmdline_next
  2549 000006BF 75D3                    	jnz .loop
  2550 000006C1 C3                      	retn
  2551                                  
  2552                                  
  2553                                  		; INP:	si -> past an optional equals sign and blanks
  2554                                  		;	di -> -> command name
  2555                                  		; CHG:	ax, si, di, cx, bx, dx, bp
  2556                                  		; STT:	ds = es => SYSINIT
  2557                                  		;	cs => DOSENTRY
  2558                                  cmdline_haltflag:
  2559                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2560 000006C2 89FD                    	mov bp, di
  2561                                  .loop:
  2562 000006C4 E82900                  	call parsenumber
  2563 000006C7 7303E930FF              	jc cmdline_error
  2564 000006CC E84000                  	call dosentry_init_get_ds_dosdata
  2565                                   assume ds:DOSGROUP
  2566 000006CF 80FB01                  	cmp bl, 1
  2567 000006D2 7208                    	jb .or
  2568 000006D4 740C                    	je .clr
  2569                                  .replace:
  2570 000006D6 8916[0000]              	mov word [haltflags], dx
  2571 000006DA EB0C                    	jmp .next
  2572                                  
  2573                                  .or:
  2574 000006DC 0916[0000]              	or word [haltflags], dx
  2575 000006E0 EB06                    	jmp .next
  2576                                  
  2577                                  .clr:
  2578 000006E2 F7D2                    	not dx
  2579 000006E4 2116[0000]              	and word [haltflags], dx
  2580                                  .next:
  2581 000006E8 06                      	push es
  2582 000006E9 1F                      	pop ds
  2583                                   assume ds:SYSINITGROUP
  2584 000006EA E83DFF                  	call cmdline_next
  2585 000006ED 75D5                    	jnz .loop
  2586 000006EF C3                      	retn
  2587                                  
  2588                                  
  2589                                  		; INP:	si -> number input text
  2590                                  		; OUT:	NC if success,
  2591                                  		;	 dx = number
  2592                                  		;	 bl = 0 if +, 1 if -, 2 else
  2593                                  parsenumber:
  2594 000006F0 31DB                    	xor bx, bx
  2595 000006F2 AC                      	lodsb
  2596 000006F3 3C2B                    	cmp al, '+'
  2597 000006F5 7407                    	je @F
  2598 000006F7 43                      	inc bx
  2599 000006F8 3C2D                    	cmp al, '-'
  2600 000006FA 7402                    	je @F
  2601 000006FC 43                      	inc bx
  2602 000006FD 4E                      	dec si
  2603                                  @@:
  2604                                   extern ldos_getnum_far
  2605 000006FE 9A[0000][ssss]          	call far ldos_getnum_far
  2606 00000703 C3                      	retn
  2607                                  
  2608                                  
  2609                                  usesection SYSINITTRAIL
  2610                                  
  2611                                  		; INP:	si -> number input text
  2612                                  		; OUT:	CY if error
  2613                                  		;	NC if success,
  2614                                  		;	 dx = number
  2615                                   global ldos_getnum
  2616                                  ldos_getnum:
  2617 000008F1 B90A00                  	mov cx, 10
  2618                                  .before:
  2619 000008F4 AC                      	lodsb
  2620 000008F5 3C20                    	cmp al, 32
  2621 000008F7 74FB                    	je .before
  2622 000008F9 3C09                    	cmp al, 9
  2623 000008FB 74F7                    	je .before
  2624 000008FD 3C3D                    	cmp al, '='
  2625 000008FF 74F3                    	je .before
  2626 00000901 3C3A                    	cmp al, ':'
  2627 00000903 74EF                    	je .before
  2628 00000905 4E                      	dec si
  2629 00000906 89F7                    	mov di, si		; di -> first digit
  2630                                  .preloop:
  2631 00000908 AC                      	lodsb
  2632 00000909 3C5F                    	cmp al, '_'
  2633 0000090B 74FB                    	je .preloop
  2634 0000090D E88D00                  	call capitalise
  2635 00000910 3C30                    	cmp al, '0'
  2636 00000912 750A                    	jne .not0
  2637 00000914 80F90A                  	cmp cl, 10		; base changed to hex?
  2638 00000917 7522                    	jne .hexit		;  then it's a hexit -->
  2639 00000919 80CD01                  	or ch, 1
  2640 0000091C EBEA                    	jmp .preloop
  2641                                  .not0:
  2642 0000091E 3C48                    	cmp al, 'H'
  2643 00000920 7404                    	je .h
  2644 00000922 3C58                    	cmp al, 'X'
  2645 00000924 7510                    	jne .notx
  2646                                  .h:
  2647 00000926 F6C502                  	test ch, 2		; hexits before ?
  2648 00000929 7502                    	jnz .gotsome
  2649 0000092B 89F7                    	mov di, si
  2650                                  .gotsome:
  2651 0000092D 80F90A                  	cmp cl, 10		; multiple h/x ?
  2652 00000930 7540                    	jne .bad		; reject -->
  2653 00000932 B110                    	mov cl, 16
  2654 00000934 EBD2                    	jmp .preloop
  2655                                  .notx:
  2656 00000936 E84D00                  	call ishex
  2657 00000939 7205                    	jc .preend
  2658                                  .hexit:
  2659 0000093B 80CD02                  	or ch, 2		; note hexit
  2660 0000093E EBC8                    	jmp .preloop
  2661                                  
  2662                                  .preend:
  2663 00000940 84ED                    	test ch, ch
  2664 00000942 742E                    	jz .bad
  2665 00000944 4E                      	dec si
  2666 00000945 F6C502                  	test ch, 2
  2667 00000948 7406                    	jz .onlyzero
  2668 0000094A 39F7                    	cmp di, si
  2669 0000094C 7424                    	je .bad
  2670 0000094E 89FE                    	mov si, di
  2671                                  .onlyzero:
  2672 00000950 B500                    	mov ch, 0
  2673 00000952 31FF                    	xor di, di
  2674                                  
  2675                                  .loop:
  2676 00000954 AC                      	lodsb
  2677 00000955 3C5F                    	cmp al, '_'
  2678 00000957 74FB                    	je .loop
  2679 00000959 E82A00                  	call ishex
  2680 0000095C 7216                    	jc .end
  2681 0000095E 38C8                    	cmp al, cl
  2682 00000960 7310                    	jae .bad
  2683 00000962 97                      	xchg di, ax
  2684 00000963 F7E1                    	mul cx
  2685 00000965 97                      	xchg di, ax
  2686 00000966 85D2                    	test dx, dx
  2687 00000968 7508                    	jnz .bad
  2688 0000096A B400                    	mov ah, 0
  2689 0000096C 01C7                    	add di, ax
  2690 0000096E 7202                    	jc .bad
  2691 00000970 EBE2                    	jmp .loop
  2692                                  
  2693                                  .bad:
  2694 00000972 F9                      	stc
  2695 00000973 C3                      	retn
  2696                                  
  2697                                  .end:
  2698 00000974 4E                      	dec si
  2699                                  .endloop:
  2700 00000975 AC                      	lodsb
  2701 00000976 E82400                  	call capitalise
  2702 00000979 3C58                    	cmp al, 'X'
  2703 0000097B 74F8                    	je .endloop
  2704 0000097D 3C48                    	cmp al, 'H'
  2705 0000097F 74F4                    	je .endloop
  2706 00000981 4E                      	dec si
  2707 00000982 89FA                    	mov dx, di
  2708 00000984 F8                      	clc
  2709 00000985 C3                      	retn
  2710                                  
  2711                                  
  2712                                  ishex:
  2713 00000986 E81400                  	call capitalise
  2714 00000989 2C30                    	sub al, '0'
  2715 0000098B 720F                    	jc .ret
  2716 0000098D 3C0A                    	cmp al, 10
  2717 0000098F 720A                    	jb .ret_cmc
  2718 00000991 2C07                    	sub al, 'A' - ('9' + 1)
  2719 00000993 7207                    	jc .ret
  2720 00000995 3C0A                    	cmp al, 10
  2721 00000997 7203                    	jb .ret
  2722 00000999 3C10                    	cmp al, 16
  2723                                  .ret_cmc:
  2724 0000099B F5                      	cmc
  2725                                  .ret:
  2726 0000099C C3                      	retn
  2727                                  
  2728                                  
  2729                                  capitalise:
  2730 0000099D 3C61                    	cmp al, 'a'
  2731 0000099F 7206                    	jb .gotcap
  2732 000009A1 3C7A                    	cmp al, 'z'
  2733 000009A3 7702                    	ja .gotcap
  2734 000009A5 3420                    	xor al, 'A' ^ 'a'
  2735                                  .gotcap:
  2736 000009A7 C3                      	retn
  2737                                  
  2738                                  
  2739                                  usesection DOSENTRYINIT
  2740                                  
  2741                                  dosentry_init_getdosdata:
  2742                                   assume ds:nothing, es:nothing, ss:nothing
  2743 00000704 1E                      	push ds
  2744 00000705 B80000                  	mov ax, 0
  2745 00000708 8ED8                    	mov ds, ax
  2746                                   assume ds:IVT
  2747 0000070A A1C600                  	mov ax, [31h * 4 + 2]
  2748 0000070D 1F                      	pop ds
  2749                                   assume ds:nothing
  2750 0000070E C3                      	retn
  2751                                  
  2752                                  dosentry_init_get_ds_dosdata:
  2753                                  dosentry_init_get_ds_dosbiodata:
  2754                                   assume ds:nothing, es:nothing, ss:nothing
  2755 0000070F 50                      	push ax
  2756 00000710 E8F1FF                  	call dosentry_init_getdosdata
  2757 00000713 8ED8                    	mov ds, ax
  2758                                   assume ds:DOSGROUP
  2759 00000715 58                      	pop ax
  2760 00000716 C3                      	retn
  2761                                  
  2762                                  dosentry_init_get_es_dosbiodata:
  2763                                   assume ds:nothing, es:nothing, ss:nothing
  2764 00000717 50                      	push ax
  2765 00000718 E8E9FF                  	call dosentry_init_getdosdata
  2766 0000071B 8EC0                    	mov es, ax
  2767                                   assume es:DOSGROUP
  2768 0000071D 58                      	pop ax
  2769 0000071E C3                      	retn
  2770                                  
  2771                                  
  2772                                  ;****************************
  2773                                  
  2774                                  Get_Para_Offset proc	near
  2775                                   assume ds:nothing, es:nothing, ss:nothing
  2776                                  ;in:  AX - offset value
  2777                                  ;out: AX - offset value adjusted for the next paragraph boundary.
  2778 0000071F 83C00F                  	add	ax, 15		;make a paragraph
  2779 00000722 D1D8                    	rcr	ax, 1
  2780 00000724 D1E8                    	shr	ax, 1
  2781 00000726 D1E8                    	shr	ax, 1
  2782 00000728 D1E8                    	shr	ax, 1
  2783 0000072A D1E0                    	shl	ax, 1		;now, make it back to offset value
  2784 0000072C D1E0                    	shl	ax, 1
  2785 0000072E D1E0                    	shl	ax, 1
  2786 00000730 D1E0                    	shl	ax, 1
  2787 00000732 C3                      	ret
  2788                                  Get_Para_Offset endp
  2789                                  
  2790                                  ;AN004; Don't need this procedure. Get_FAT_Sector replace this.
  2791                                  ;	READ A FAT SECTOR INTO FAT LOCATION
  2792                                  ;GETFAT  PROC	 NEAR
  2793                                  ;	 XOR	 DI,DI			 ; OFFSET
  2794                                  ;	 MOV	 DX,1			 ; RELATIVE SECTOR (1ST SECTOR OF FAT)
  2795                                  ;	 MOV	 CX,FATLEN		 ; READ ENTIRE FAT.
  2796                                  ;	 MOV	 AX,FATLOC		 ;
  2797                                  ;	 MOV	 ES,AX			 ; LOCATION TO READ
  2798                                  ;	 MOV	 AX,DRVFAT	       ; AH FAT ID BYTE, AL DRIVE
  2799                                  ;	 JMP	 DISKRD
  2800                                  ;GETFAT  ENDP
  2801                                  
  2802                                  
  2803                                  usesection SYSINITTRAIL
  2804                                  
  2805                                   extern allocate_temporary_block, alloc_init
  2806                                   extern sysinit_getdosdata
  2807                                  
  2808                                   global sysinit_get_ds_dosbiodata
  2809                                   global sysinit_get_ds_dosentry
  2810                                  sysinit_get_ds_dosbiodata:
  2811                                   assume ds:nothing, es:nothing, ss:nothing
  2812 000009A8 50                      	push ax
  2813 000009A9 E8(0000)                	call sysinit_getdosdata
  2814 000009AC 8ED8                    	mov ds, ax
  2815                                   assume ds:DOSGROUP
  2816 000009AE 58                      	pop ax
  2817 000009AF C3                      	retn
  2818                                  
  2819                                  sysinit_get_ds_dosentry:
  2820                                   assume ds:nothing, es:nothing, ss:nothing
  2821 000009B0 2E8E1E[B609]            	mov ds, word [cs:.segment]
  2822                                   assume ds:DOSENTRYGROUP
  2823 000009B5 C3                      	retn
  2824                                  
  2825                                  	align 2, db 0
  2826 000009B6 [ssss]                  .segment:	dw DOSENTRY
  2827                                  
  2828                                   global sysinit_get_es_dosbiodata
  2829                                   global sysinit_get_es_dosentry
  2830                                  sysinit_get_es_dosbiodata:
  2831                                   assume ds:nothing, es:nothing, ss:nothing
  2832 000009B8 50                      	push ax
  2833 000009B9 E8(0000)                	call sysinit_getdosdata
  2834 000009BC 8EC0                    	mov es, ax
  2835                                   assume es:DOSGROUP
  2836 000009BE 58                      	pop ax
  2837 000009BF C3                      	retn
  2838                                  
  2839                                  sysinit_get_es_dosentry:
  2840                                   assume ds:nothing, es:nothing, ss:nothing
  2841 000009C0 2E8E06[B609]            	mov es, word [cs:sysinit_get_ds_dosentry.segment]
  2842                                   assume es:DOSENTRYGROUP
  2843 000009C5 C3                      	retn
  2844                                  
  2845                                  extern dosdata_to_doscode
  2846                                  
  2847                                  get_ds_biocode:
  2848                                   assume ds:nothing, es:nothing, ss:nothing
  2849 000009C6 2E8E1E[D409]            	mov ds, word [cs:.value]
  2850                                   assume ds:IVT
  2851 000009CB 8E1EC600                	mov ds, word [31h * 4 + 2]
  2852                                   assume ds:DOSGROUP
  2853 000009CF 8E1E[0000]              	mov ds, word [dosdata_to_doscode]
  2854                                   assume ds:DOSCODEGROUP
  2855 000009D3 C3                      	retn
  2856                                  
  2857                                  	align 2, nop
  2858 000009D4 0000                    .value:	dw 0
  2859                                  
  2860                                  extern biocode_retf
  2861                                  
  2862                                  %imacro neartransfer 1.nolist
  2863                                  	extern %1
  2864                                  	call transfer_sysinitseg_to_biocode
  2865                                  	jmp strict short %%skip
  2866                                  	dw %1
  2867                                  %%skip:
  2868                                  %endmacro
  2869                                  
  2870                                  transfer_sysinitseg_to_biocode:		; near call ip: in_ip_out_cs
  2871                                   assume ds:nothing, es:nothing, ss:nothing
  2872 000009D6 50                      	push ax				; in_ax_out_ip
  2873 000009D7 B8[0000]                	mov ax, biocode_retf
  2874 000009DA 50                      	push ax				; out_retf
  2875 000009DB 50                      	push ax				; out_destination + 2
  2876 000009DC 50                      	push ax				; out_destination + 0
  2877                                  	lframe 0
  2878                                  	lpar word, in_ip_out_cs
  2879                                  	lpar word, in_ax_out_ip
  2880                                  	lpar word, out_retf
  2881                                  	lpar dword, out_destination
  2882 000009DD 5589E5                  	lenter
  2883 000009E0 1E                      	push ds
  2884 000009E1 56                      	push si
  2885 000009E2 8CCE                    	mov si, cs			; si = cs
  2886 000009E4 87760A                  	xchg si, word [bp + ?in_ip_out_cs]
  2887                                  					; set cs, get ip
  2888 000009E7 56                      	push si				; preserve ip for later
  2889 000009E8 AD                      	lodsw				; skip jmp short
  2890 000009E9 2EAD                    	cs lodsw			; get destination
  2891 000009EB 894602                  	mov word [bp + ?out_destination + 0], ax
  2892                                  					; set destination
  2893 000009EE E8D5FF                  	call get_ds_biocode		; ds => BIOCODE
  2894                                   assume ds:DOSCODEGROUP
  2895 000009F1 8C5E04                  	mov word [bp + ?out_destination + 2], ds
  2896                                  					; => BIOCODE
  2897 000009F4 58                      	pop ax
  2898 000009F5 874608                  	xchg ax, word [bp + ?in_ax_out_ip]
  2899                                  					; ax = original ax, set out ip
  2900 000009F8 5E                      	pop si
  2901 000009F9 1F                      	pop ds
  2902                                   assume ds:nothing
  2903 000009FA 5D                      	lleave
  2904 000009FB CB                      	retf
  2905                                  
  2906                                  
  2907                                  
  2908                                  		; INP:	es:si -> partition table entry,
  2909                                  		;	 si = load_partition_table .. load_partition_table+48,
  2910                                  		;	 es = cs
  2911                                  		;	bp + di -> above part table metadata,
  2912                                  		;	 dwo [bp + di - 4] = root (outermost extended position)
  2913                                  		;	 dwo [bp + di - 8] = base (current table position)
  2914                                  		; CHG:	ax, bx, (cx), dx
  2915                                  handle_each_partition:
  2916                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2917 000009FC 268A4404                	mov al, byte [es:si + piType]
  2918 00000A00 E845FA                  	call load_is_known
  2919 00000A03 7202                    	jc .discard
  2920 00000A05 7401                    	jz @F
  2921                                  
  2922                                  .discard:
  2923 00000A07 C3                      	retn
  2924                                  
  2925                                  @@:
  2926 00000A08 51                      	push cx
  2927 00000A09 57                      	push di
  2928 00000A0A 55                      	push bp
  2929 00000A0B 56                      	push si
  2930 00000A0C 06                      	push es
  2931                                  
  2932 00000A0D 800E[0000]20            	setopt [load_scan_flags], 32	; a logical or primary partition found
  2933                                  		; Hmm. If we reject the partition later, then we
  2934                                  		;  still have set this flag here. But, that matches
  2935                                  		;  what lMS-DOS did before (invalid partition stops
  2936                                  		;  the scan in current MBR/EPBR). So it stays so.
  2937                                  
  2938 00000A12 8B43F8                  	mov ax, [bp + di - 8]
  2939 00000A15 8B53FA                  	mov dx, [bp + di - 6]		; base (current table position)
  2940 00000A18 26034408                	add ax, [es:si + 8]
  2941 00000A1C 2613540A                	adc dx, [es:si + 8 + 2]		; add offset to logical partition
  2942 00000A20 8A0E[0400]              	mov cl, [BDS_harddisk_template + DRIVENUM]
  2943                                  
  2944 00000A24 E881FF                  	call sysinit_get_ds_dosbiodata
  2945                                   assume ds:DOSGROUP
  2946 00000A27 C53E[0000]              	lds	di, [Start_BDS]
  2947                                   assume ds:nothing
  2948                                  @@:
  2949 00000A2B 83FFFF                  	cmp di, -1
  2950 00000A2E 743A                    	je .notduplicate
  2951 00000A30 384D04                  	cmp byte [di + DRIVENUM], cl
  2952 00000A33 750A                    	jne @F
  2953 00000A35 394517                  	cmp word [di + HIDSEC_L], ax
  2954 00000A38 7505                    	jne @F
  2955 00000A3A 395519                  	cmp word [di + HIDSEC_H], dx
  2956 00000A3D 7404                    	je .duplicate
  2957                                  @@:
  2958 00000A3F C53D                    	lds di, [di + LINK]
  2959                                   assume ds:nothing
  2960 00000A41 EBE8                    	jmp @BB
  2961                                  
  2962                                  .duplicate:
  2963 00000A43 0E                      	push cs
  2964 00000A44 1F                      	pop ds
  2965                                   assume ds:SYSINITGROUP
  2966 00000A45 0E                      	push cs
  2967 00000A46 07                      	pop es
  2968                                   assume es:SYSINITGROUP
  2969                                  
  2970 00000A47 BF[4F0F]                	mov di, msg.duplicate_hidden_l
  2971                                  extern hexword
  2972 00000A4A E8(0000)                	call hexword
  2973 00000A4D 92                      	xchg ax, dx
  2974 00000A4E BF[4A0F]                	mov di, msg.duplicate_hidden_h
  2975 00000A51 E8(0000)                	call hexword
  2976 00000A54 91                      	xchg ax, cx
  2977 00000A55 BF[3E0F]                	mov di, msg.duplicate_unit
  2978 00000A58 E8(0000)                	call hexbyte
  2979                                  
  2980 00000A5B BA[D40E]                	mov dx, msg.bootfail
  2981 00000A5E E8(0000)                	call init2_disp_msg_asciz_cs_dx
  2982 00000A61 BA[160F]                	mov dx, msg.duplicate
  2983 00000A64 E8(0000)                	call init2_disp_msg_asciz_cs_dx
  2984 00000A67 E96D02                  	jmp partition_reject
  2985                                  
  2986                                  
  2987                                  .notduplicate:
  2988 00000A6A 0E                      	push cs
  2989 00000A6B 1F                      	pop ds
  2990                                   assume ds:SYSINITGROUP
  2991 00000A6C BF[0000]                	mov di, BDS_harddisk_template
  2992                                  					; Hidden sectors (based on EPBR)
  2993 00000A6F 894517                  	mov [di + HIDSEC_L], ax		;   BPB->HIDSECCT = P->PARTITIONBEGIN;
  2994 00000A72 895519                  	mov [di + HIDSEC_H], dx
  2995 00000A75 A0[0000]                	mov al, [next_block_device_unit]
  2996 00000A78 884505                  	mov [di + DRIVELET], al
  2997                                  
  2998                                  
  2999                                  ;   SETHARD - GENERATE BPB FOR A VARIABLE SIZED HARD FILE.  IBM HAS A
  3000                                  ;   PARTITIONED HARD FILE; WE MUST READ PHYSICAL SECTOR 0 TO DETERMINE WHERE
  3001                                  ;   OUR OWN LOGICAL SECTORS START.  WE ALSO READ IN OUR BOOT SECTOR TO
  3002                                  ;   DETERMINE VERSION NUMBER
  3003                                  
  3004                                  ;   INPUTS:	DL IS ROM DRIVE NUMBER (80 OR 81)
  3005                                  ;		DS:DI POINTS TO BDS
  3006                                  ;   OUTPUTS:	CARRY CLEAR -> BPB IS FILLED IN
  3007                                  ;		CARRY SET   -> BPB IS LEFT UNINITIALIZED DUE TO ERROR
  3008                                  
  3009                                   assume ds:SYSINITGROUP, es:nothing, ss:nothing
  3010                                  				; Note: Partitiontype 6 means either
  3011                                  				;1).the partition has not been formatted yet, or
  3012                                  				;2).(# of sectors before the partition +
  3013                                  				;    # of sectors in this partition) > word boundary
  3014                                  				;	i.e., needs 32 bit sector calculation, or
  3015                                  				;3).the partition is not a FAT file system.
  3016                                  
  3017                                  ;J.K.  Until we get the real logical boot record and get the bpb,
  3018                                  ;DRVLIM_H,DRVLIM_L will be used instead of DRVLIM for the convenience of
  3019                                  ;the computation.
  3020                                  ;At the end of this procedure, if a BPB information is gotten from
  3021                                  ;the valid boot record, then we are going to use those BPB information
  3022                                  ;without change.
  3023                                  ;Otherwise, if (hidden sectors + total sectors) <= a word, then
  3024                                  ;we will move DRVLIM_L to DRVLIM and zero out DRVLIM_L entry to make
  3025                                  ;it a conventional BPB format.
  3026                                  
  3027 00000A7B 268B440C                	mov ax, word [es:si + piLength]		; # of sectors (Low)
  3028 00000A7F 268B540E                	mov dx, word [es:si + piLength + 2]	;AN000; # of sectors (High)
  3029 00000A83 89551D                  	mov	word ptr [di + DRVLIM_H], dx
  3030 00000A86 89451B                  	mov	word ptr [di + DRVLIM_L], ax ;   BPB->MAXSEC = P->PARTITIONLENGTH;
  3031 00000A89 85D2                    	test dx, dx
  3032 00000A8B 7508                    	jnz OKDrive_Cont
  3033 00000A8D 83F840                  	cmp ax, 64			;   IF (P->PARTITIONLENGTH < 64)
  3034 00000A90 7303E94202              	jb partition_reject		;	RETURN -1;
  3035                                  
  3036                                  OKDrive_Cont:				;AN000;
  3037                                  
  3038 00000A95 034517                  	add ax, [di + HIDSEC_L]
  3039 00000A98 135519                  	adc dx, [di + HIDSEC_H]		; dx:ax = sector after partition
  3040                                  Okdrive equ OKDRIVE	; NASM port label
  3041 00000A9B 730B                    	jnc Okdrive
  3042 00000A9D 89C1                    	mov cx, ax
  3043 00000A9F 09D1                    	or cx, dx
  3044 00000AA1 7405                            jz Okdrive
  3045                                  	  MESSAGE FTESTHARD,<"PARTITION INVALID",CR,LF>
  3046 00000AA3 800E[0700]80            	or byte [FBIGFAT], FTOOBIG
  3047                                  OKDRIVE:
  3048                                  
  3049 00000AA8 F6452404                	testopt [di + FLAGS], F_LBA
  3050 00000AAC 7512                    	jnz okdrive_lba
  3051                                  
  3052 00000AAE 83E801                  	sub ax, 1
  3053 00000AB1 83DA00                  	sbb dx, 0			; dx:ax = last sector of partition
  3054 00000AB4 E81FFFEB02[0000]        	neartransfer lbatochs		; convert to CHS
  3055 00000ABB 7303E91702              	jc partition_reject		; if CHS overflow -->
  3056                                  
  3057                                  okdrive_lba:
  3058                                  
  3059 00000AC0 8B5519                  	mov	dx,[di + HIDSEC_H]
  3060 00000AC3 8B4517                  	mov	ax,[di + HIDSEC_L]	; BOOT SECTOR NUMBER
  3061                                  
  3062                                  
  3063                                  ;J.K. For convenience, we are going to read the logical boot sector
  3064                                  ;into cs:DiskSector area.
  3065                                  
  3066                                  ;SB34INIT009*************************************************************
  3067                                  ;SB  Read in boot sector using BIOS disk interrupt.  The buffer where it
  3068                                  ;SB  is to be read in is cs:Disksector.
  3069 00000AC6 E8F7FE                  	call sysinit_get_es_dosentry	; DISKSECTOR in DOSENTRY
  3070                                   assume es:DOSENTRYGROUP
  3071 00000AC9 BB[0000]                	mov	bx,offset DiskSector	; access with es
  3072 00000ACC B90102                  	mov	cx,0201h	; read, one sector
  3073 00000ACF E81C02                  	call readsector_flag
  3074 00000AD2 7303E90002              	jc partition_reject		;AN000; Exceeds the limit of Int 13h
  3075                                  ;SB34INIT009*************************************************************
  3076                                  
  3077 00000AD7 E86A03                  	call have_bpb
  3078 00000ADA 7309                    	jnc @F
  3079                                   assume ds:SYSINITGROUP
  3080                                  extern BADBLOCK
  3081 00000ADC BA[0000]                	MOV	DX,OFFSET BADBLOCK
  3082                                  extern PRINT
  3083 00000ADF E8(0000)                	call PRINT
  3084 00000AE2 E9F201                  	jmp partition_reject
  3085                                  @@:
  3086                                  
  3087 00000AE5 06                      	push es
  3088                                  		; At this point we're sure to set up the drive.
  3089                                  		;  So, copy over the template to the next UPB.
  3090 00000AE6 FE06[0000]              	inc byte [next_block_device_unit]
  3091                                  					; remember which DOS drive is next
  3092 00000AEA 89FE                    	mov si, di
  3093 00000AEC E887F6                  	call alloc_upb			; (will halt system on error)
  3094                                   assume es:UPB
  3095 00000AEF B96400                  	mov cx, BDS_TYPE_struc_size
  3096 00000AF2 57                      	push di
  3097 00000AF3 F3A4                    	rep movsb
  3098 00000AF5 5F                      	pop di				; di -> next UPB
  3099 00000AF6 06                      	 push es
  3100 00000AF7 1F                      	 pop ds				; ds:di -> UPB
  3101                                   assume ds:UPB
  3102 00000AF8 E85203                  	call Install_BDSM_and_set_bpb	; INSTALL BDS INTO LINKED LIST
  3103 00000AFB 07                      	pop es
  3104                                   assume es:DOSENTRYGROUP
  3105                                  
  3106                                  
  3107                                  ; cs:Disksec contains THE BOOT SECTOR.	IN THEORY, (HA HA) THE BPB IN THIS THING
  3108                                  ; IS CORRECT.  WE CAN, THEREFORE, SUCK OUT ALL THE RELEVANT STATISTICS ON THE
  3109                                  ; MEDIA IF WE RECOGNIZE THE VERSION NUMBER.
  3110                                  
  3111                                  ; look for a signature for msdos...
  3112 00000AFC 26817F034D53            	cmp	word ptr [es:bx+3], "M" + ("S" << 8)
  3113 00000B02 750F                    	jne	notmssig
  3114 00000B04 26817F05444F            	cmp	word ptr [es:bx+5], "D" + ("O" << 8)
  3115 00000B0A 7507                    	jne	notmssig
  3116 00000B0C 26807F0753              	cmp	byte ptr [es:bx+7], "S"
  3117 00000B11 7420                    	je	sigfound
  3118                                  ; ...or perhaps pcdos...
  3119                                  notmssig:
  3120 00000B13 26817F034942            	CMP	WORD PTR [es:bx+3], "I" + ("B" << 8)
  3121 00000B19 7508                    	jne	notibmsig
  3122 00000B1B 26817F054D20            	CMP	WORD PTR [es:bx+5], "M" + (" " << 8)
  3123 00000B21 7410                    	je	sigfound
  3124                                  
  3125                                  notibmsig:
  3126 00000B23 26817F034F53            	CMP	WORD PTR [es:bx+3], "O" + ("S" << 8)
  3127 00000B29 751D                    	jne	acceptbpb
  3128 00000B2B 26817F053220            	CMP	WORD PTR [es:bx+5], "2" + (" " << 8)
  3129 00000B31 7515                    	jne	acceptbpb	; ecm: not MSDOS nor IBM nor OS/2, accept BPB -->
  3130                                  
  3131                                  sigfound:			; signature was found, now check version
  3132                                  
  3133                                  check3point0:
  3134                                  Cover_Fdisk_Bug equ Cover_FDISK_Bug	; NASM port label
  3135 00000B33 E81302                  	call	Cover_Fdisk_Bug 		;AN010;
  3136                                  		; ecm: only reject "MSDOS3.0" or "IBM  3.0"
  3137 00000B36 26817F08332E            	CMP	WORD PTR [es:bx+8],"3" + ("." << 8)
  3138 00000B3C 750A                    	jne	acceptbpb
  3139 00000B3E 26807F0A30              	cmp	byte ptr [es:bx+10],"0"         ;do not trust 3.0 boot record. But still legal J.K. 4/15/86
  3140 00000B43 7503                    	jne	acceptbpb			;AN012; if version >= 3.1, then O.K.
  3141 00000B45 E9BB00                  	jmp	unknown3point0
  3142                                  acceptbpb:
  3143                                  COPYBPB:
  3144                                  ; WE HAVE A VALID BOOT SECTOR. USE THE BPB IN IT TO BUILD THE
  3145                                  ; BPB IN BIOS. IT IS ASSUMED THAT ONLY SECPERCLUS, CDIR, AND
  3146                                  ; CSECFAT NEED TO BE SET (ALL OTHER VALUES IN ALREADY). FBIGFAT
  3147                                  ; IS ALSO SET.
  3148                                  
  3149                                  ;If it is non FAT based system, then just copy the BPB from the BOOT sector
  3150                                  ;into the BPB in BDS table, and also set the Boot serial number, Volume id,
  3151                                  ;and System ID according to the Boot record.
  3152                                  ;For the non_FAT system, don't need to set the other value. So just
  3153                                  ;do GOODRET.- J.K.
  3154                                  
  3155 00000B48 26803E[0000]29          	cmp	byte [es:Ext_Boot_Sig], EXT_BOOT_SIGNATURE ;AN000;
  3156 00000B4E 7528                    	jne	COPYBPB_FAT		;AN000; Conventional Fat system
  3157 00000B50 26803E[0000]00          	cmp	byte [es:NumberOfFats], 0	;AN000; If (# of FAT <> 0) then
  3158 00000B56 7520                    	jne	COPYBPB_FAT		;AN000;   a Fat system.
  3159                                  ;J.K. Non Fat based media.
  3160 00000B58 57                      	push	di			;AN000; Sav Reg.
  3161 00000B59 1E                      	push	ds			;AN000;
  3162 00000B5A 06                      	push es
  3163                                  
  3164 00000B5B 1E                      	push	ds			;AN000;
  3165 00000B5C 07                      	pop	es			;AN000; now es:di -> bds
  3166                                   assume es:UPB
  3167 00000B5D E850FE                  	call sysinit_get_ds_dosentry	; DISKSECTOR in DOSENTRY
  3168                                   assume ds:DOSENTRYGROUP
  3169 00000B60 BE[0000]                	mov	si, offset Bpb_In_Sector ;AN000; ds:si -> BPB in Boot ; access with ds
  3170 00000B63 83C706                  	add	di, BYTEPERSEC		;AN000; es:di -> BPB in BDS
  3171 00000B66 B91900                  	mov	cx, BPB_TYPE_struc_size	;AN000;
  3172 00000B69 F3A4                    	rep	movsb			;AN000;
  3173                                  
  3174 00000B6B 07                      	pop es
  3175                                   assume es:DOSENTRYGROUP
  3176 00000B6C 1F                      	pop	ds			;AN000; Restore Reg.
  3177                                   assume ds:UPB
  3178 00000B6D 5F                      	pop	di			;AN000;
  3179 00000B6E E865FEEB02[0000]        	neartransfer Mov_Media_IDs	;AN000; Set Volume id, SystemId, Serial.
  3180                                  init_GoodRet equ init_GOODRET	; NASM port label
  3181 00000B75 E94201                  	jmp	init_GoodRet
  3182                                  
  3183                                  COPYBPB_FAT:				;AN000;  Fat system
  3184 00000B78 31D2                    	xor	dx,dx			;AN000;
  3185 00000B7A BE[0000]                	mov	si, offset Bpb_In_Sector ;AN000;  es:bx -> bpb in boot ; access with es
  3186 00000B7D 268B4408                	mov	ax, [es:si + SECNUM]	;AN000;  total sectors
  3187 00000B81 85C0                    	test ax, ax			;AN000; double word sector number?
  3188 00000B83 7508                    	jnz	Fat_Big_Small		;AN000;  No. Conventional BPB.
  3189 00000B85 268B4415                	mov	ax, word ptr [es:si + SECNUM_L] ;AN000; Use double word
  3190 00000B89 268B5417                	mov	dx, word ptr [es:si + SECNUM_H] ;AN000;
  3191                                  
  3192                                  Fat_Big_Small:				 ;AN000; Determine Fat entry size.
  3193                                  ;At this moment DX;AX = Total sector number
  3194 00000B8D 268B5C03                	mov bx, [es:si + RESNUM]
  3195 00000B91 895D09                  	mov [di + RESSEC], bx
  3196 00000B94 29D8                    	sub	ax,bx			;AN000; Subtract # reserved
  3197 00000B96 83DA00                  	sbb	dx,0			;AN000;
  3198 00000B99 268B5C0B                	mov	bx, [es:si + FATSIZE]	;AN000;  BX = Sectors/Fat
  3199 00000B9D 895D11                  	mov	[di + CSECFAT],bx 	;AN000;  Set in BDS BPB
  3200 00000BA0 31C9                    	xor cx, cx
  3201 00000BA2 268A4C05                	mov cl, [es:si + FATNUM]
  3202 00000BA6 884D0B                  	mov [di + CFAT], cl
  3203 00000BA9 E307                    	jcxz .none
  3204                                  .loop:
  3205 00000BAB 29D8                    	sub	ax,bx			;AN000; Subtract # fat sectors
  3206 00000BAD 83DA00                  	sbb	dx,0			;AN000;
  3207 00000BB0 E2F9                    	loop .loop
  3208                                  .none:
  3209 00000BB2 268B5C06                	mov	bx, [es:si + DIRNUM]	;AN000;  # root entries
  3210                                  cDIR equ CDIR	; NASM port equate
  3211 00000BB6 895D0C                  	mov	[di + cDIR],bx		;AN000;  Set in BDS BPB
  3212                                  
  3213 00000BB9 B104                    	MOV	CL,4
  3214 00000BBB D3EB                    	shr	bx,cl			;AN000;  Div by 16 ents/sector
  3215 00000BBD 29D8                    	sub	ax,bx			;AN000;  sub # dir sectors
  3216 00000BBF 83DA00                  	sbb	dx,0			;AN000;
  3217                                  					;AN000; DX;AX now contains the # of data sectors
  3218 00000BC2 268A4C02                	MOV	CL, [es:si + SECALL]	; SECTORS PER CLUSTER
  3219 00000BC6 49                      	dec cx
  3220 00000BC7 B500                    	mov ch, 0
  3221 00000BC9 41                      	inc cx				; translate EDR-DOS 0 to 256
  3222 00000BCA 884D08                  	MOV	[DI + SECPERCLUS],CL	; SET IN BIOS BPB (truncated)
  3223                                  ;	 XOR	 DX,DX
  3224                                  ;	 MOV	 CH,DH
  3225                                  	MNUM	FTESTHARD,CX
  3226                                  	MESSAGE FTESTHARD,<" SECPERCLUS",CR,LF>
  3227                                  ;J.K. 3/16/87 P54 Returning back to old logic for compatibility reason.
  3228                                  ;So, use the old logic again that once had been commented out!!!!!!!!!!!!
  3229                                  ;Old logic to determine FAT Entry Size J.K. 12/3/86
  3230 00000BCD E8E8FD                  	call sysinit_get_es_dosbiodata
  3231                                   assume es:DOSGROUP
  3232 00000BD0 50                      	push	ax			;AN000;
  3233 00000BD1 92                      	xchg	ax, dx			; ax = high word, clobber dx
  3234 00000BD2 31D2                    	xor	dx,dx			;AN000;
  3235 00000BD4 F7F1                    	div	cx			;AN000; cx = sectors per cluster
  3236 00000BD6 26A3[0000]              	mov	[es:Temp_H],ax		;AN000;
  3237 00000BDA 58                      	pop	ax			;AN000;
  3238 00000BDB F7F1                    	DIV	CX			;AN000;  [Temp_H];AX NOW CONTAINS THE # CLUSTERS.
  3239 00000BDD 26833E[0000]00          	cmp	word [es:Temp_H],0		;AN000;
  3240 00000BE3 7715                    	ja	TooBig_Ret		;AN000;  Too big cluster number
  3241 00000BE5 3DF60F                  	CMP	AX,4096-10		; IS THIS 16-BIT FAT?
  3242 00000BE8 7206                    	JB	CopyMediaID		; NO, small FAT
  3243 00000BEA 2E800E[0700]40          	OR	byte [cs:FBIGFAT],FBIG	; 16 BIT FAT
  3244                                  ;End of Old logic
  3245                                  CopyMediaID:
  3246 00000BF0 E8E3FDEB02[0000]        	neartransfer Mov_Media_IDs	;AN000; Copy Filesys_ID, Volume label,
  3247                                  					;and Volume serial to BDS table, if extended
  3248                                  					;boot record.
  3249 00000BF7 E99F00                  	JMP	Massage_bpb		;AN000; Now final check for BPB info. and return.
  3250                                  
  3251                                  TooBig_Ret:				;AN000;
  3252 00000BFA 2E800E[0700]80          	OR	byte [cs:FBIGFAT],FTOOBIG
  3253 00000C00 E9B700                  	JMP	init_GOODRET		;AN000; Still drive letter is assigned
  3254                                  					;AN000; But useless. To big for
  3255                                  					;AN000; current PC DOS FAT file system
  3256                                  ; UNKNOWN:
  3257                                  ;	or	[di].FLAGS, UNFORMATTED_MEDIA	;AN005; Set unformatted media flag.
  3258                                  	; preceeding line commented out 10/88 by MRW--  The boot signature
  3259                                  	;   may not be recognizable, but we should TRY and read it anyway.
  3260                                  						;AN006;
  3261                                  						;AN008; For the time being, allow it.
  3262                                  						;AN009; Now implemented again
  3263                                  ; Unknown3_0:				;AN012;Skip setting UNFORMATTED_MEDIA bit
  3264                                  unknown3point0:
  3265                                   assume es:DOSENTRYGROUP
  3266                                  	MESSAGE FTESTHARD,<"UNKNOWN HARD MEDIA. ASSUMING 3.0.",CR,LF>
  3267 00000C03 8B551D                  	mov	dx, [di + DRVLIM_H]	;AN000;
  3268 00000C06 8B451B                  	mov	ax, [di + DRVLIM_L]	;AN000;
  3269                                  DISKTABLE2 equ DiskTable2	; NASM port label
  3270 00000C09 BE[9800]                	MOV	SI,OFFSET DISKTABLE2	; access with cs
  3271                                  .SCAN:
  3272                                  ;	 CMP	 AX,[SI]
  3273                                  ;	 JBE	 GOTPARM
  3274                                  ;	 ADD	 SI,4 * 2
  3275                                  
  3276 00000C0C 2E3B14                  	cmp	dx, word ptr [cs:si]	;AN000;
  3277                                  GotParm equ GOTPARM	; NASM port label
  3278 00000C0F 720D                    	jb	GotParm 		;AN000;
  3279 00000C11 7706                    	ja	.Scan_Next		;AN000;
  3280 00000C13 2E3B4402                	cmp	ax, word ptr [cs:si+2]	;AN000;
  3281 00000C17 7605                    	jbe	GotParm 		;AN000;
  3282                                  .Scan_Next:				;AN000;
  3283 00000C19 83C60A                  	add	si, 5 * 2		;AN000;
  3284 00000C1C EBEE                    	JMP	.SCAN			;AN000;  Covers upto 512 MB media
  3285                                  GOTPARM:
  3286                                  ;	 MOV	 CL,BYTE PTR [SI+6]
  3287 00000C1E 2E8A4C08                	mov	cl,byte ptr [cs:si+8]	;AN000;  Fat size for FBIGFAT flag
  3288 00000C22 2E080E[0700]            	OR	[cs:FBIGFAT],CL
  3289                                  ;	 MOV	 CX,[SI+2]
  3290                                  ;	 MOV	 DX,[SI+4]
  3291 00000C27 2E8B4C04                	mov	cx, word ptr [cs:SI+4]	;AN000;
  3292 00000C2B 2E8B5406                	mov	dx, word ptr [cs:SI+6]	;AN000;
  3293                                  
  3294                                  ;	DX = NUMBER OF DIR ENTRIES,
  3295                                  ;	CH = NUMBER OF SECTORS PER CLUSTER
  3296                                  ;	CL = LOG BASE 2 OF CH
  3297                                  
  3298                                  ;	NOW CALCULATE SIZE OF FAT TABLE
  3299                                  
  3300                                  	MNUM	FTESTHARD,AX
  3301                                  	MESSAGE FTESTHARD,<" SECTORS ">
  3302                                  	MNUM	FTESTHARD,DX
  3303                                  	MESSAGE FTESTHARD,<" DIRECTORY ENTRIES ">
  3304                                  	MNUM	FTESTHARD,CX
  3305                                  	MESSAGE FTESTHARD,<" SECPERCLUS|CLUSSHIFT">
  3306                                  
  3307 00000C2F 89550C                  	MOV	WORD PTR [CDIR + DI],DX	;SAVE NUMBER OF DIR ENTRIES
  3308                                  
  3309                                  ;Now, CX = SecPerClus|Clusshift
  3310                                  ;     [DI.CDIR] = number of directory entries.
  3311                                  
  3312 00000C32 8B551D                  	mov	dx, [di + DRVLIM_H]	;AN000;
  3313 00000C35 8B451B                  	mov	ax, [di + DRVLIM_L]	;AN000;
  3314 00000C38 886D08                  	MOV	BYTE PTR [SECPERCLUS + DI],CH ;SAVE SECTORS PER CLUSTER
  3315 00000C3B 2EF606[0700]40          	TEST	byte [cs:FBIGFAT],FBIG		;   IF (FBIGFAT)
  3316 00000C41 751E                    	JNZ	DOBIG			;	GOTO DOBIG;
  3317                                  	 MESSAGE FTESTHARD,<" SMALL FAT",CR,LF>
  3318                                  ;J.K. We don't need to change "small fat" logic since it is gauranteed
  3319                                  ;that double word total sector will not use 12 bit fat (unless
  3320                                  ;it's sectors/cluster >= 16 which will never be in this case.)
  3321                                  ;So in this case we assume DX = 0 !!!.
  3322                                  
  3323 00000C43 31DB                    	XOR	BX,BX
  3324 00000C45 88EB                    	MOV	BL,CH
  3325 00000C47 4B                      	DEC	BX
  3326 00000C48 01C3                    	ADD	BX,AX			;AN000;  DX=0
  3327 00000C4A D3EB                    	SHR	BX,CL			;   BX = 1+(BPB->MAXSEC+SECPERCLUS-1)/
  3328 00000C4C 43                      	INC	BX			;	    SECPERCLUS
  3329 00000C4D 80E3FE                  	AND	BL,11111110B		;   BX &= ~1; (=NUMBER OF CLUSTERS)
  3330 00000C50 89DE                    	MOV	SI,BX
  3331 00000C52 D1EB                    	SHR	BX,1
  3332 00000C54 01F3                    	ADD	BX,SI
  3333 00000C56 81C3FF01                	ADD	BX,511			;   BX += 511 + BX/2
  3334 00000C5A D0EF                    	SHR	BH,1			;   BH >>= 1; (=BX/512)
  3335 00000C5C 887D11                  	MOV	BYTE PTR [DI + CSECFAT],BH ;SAVE NUMBER OF FAT SECTORS
  3336                                  Massage_BPB equ Massage_bpb	; NASM port label
  3337 00000C5F EB38                    	JMP	SHORT Massage_BPB
  3338                                  DOBIG:
  3339                                  ;J.K. For BIGFAT we do need to extend this logic to 32 bit sector calculation.
  3340                                  	  MESSAGE FTESTHARD,<" BIG FAT",CR,LF>
  3341 00000C61 B104                    	MOV	CL,4			; 16 (2^4) DIRECTORY ENTRIES PER SECTOR
  3342 00000C63 52                      	push	dx			;AN000; Save total sectors (high)
  3343 00000C64 8B550C                  	mov	dx,[CDIR + DI]		;AN000;
  3344 00000C67 D3EA                    	SHR	DX,CL			; CSECDIR = CDIR / 16;
  3345 00000C69 29D0                    	SUB	AX,DX			; DX;AX -= CSECDIR; DX;AX -= CSECRESERVED;
  3346 00000C6B 5A                      	pop	dx			;AN000;
  3347 00000C6C 83DA00                  	SBB	dx,0			;AN000;
  3348                                  ;	 DEC	 AX			 ; AX = T - R - D
  3349 00000C6F 83E801                  	SUB	ax,1			;AN000; DX;AX = T - R - D
  3350 00000C72 83DA00                  	SBB	dx,0			;AN000;
  3351 00000C75 B302                    	MOV	BL,2
  3352 00000C77 8A7D08                  	MOV	BH,[SECPERCLUS + DI]	; BX = 256 * SECPERCLUS + 2
  3353                                  ;	 XOR	 DX,DX
  3354                                  ;J.K. I don't understand why to add BX here!!!
  3355 00000C7A 01D8                    	ADD	AX,BX			; AX = T-R-D+256*SPC+2
  3356 00000C7C 83D200                  	ADC	DX,0
  3357 00000C7F 83E801                  	SUB	AX,1			; AX = T-R-D+256*SPC+1
  3358 00000C82 83DA00                  	SBB	DX,0
  3359                                  ;J.K. Assuming DX in the table will never be bigger than BX.
  3360 00000C85 F7F3                    	DIV	BX			; CSECFAT = CEIL((TOTAL-DIR-RES)/
  3361                                  					;		 (256*SECPERCLUS+2));
  3362 00000C87 894511                  	MOV	WORD PTR [DI + CSECFAT],AX ; NUMBER OF FAT SECTORS
  3363                                  ;J.K. Now, set the default FileSys_ID, Volume label, Serial number
  3364 00000C8A 2E8A1E[0700]            	MOV	BL,[cs:FBIGFAT]
  3365 00000C8F 885D1F                  	MOV	[DI + FATSIZ],BL		; SET SIZE OF FAT ON MEDIA
  3366 00000C92 E841FDEB02[0000]        	neartransfer Clear_IDs		;AN000;
  3367                                  
  3368                                  ;J.K. At this point, in BPB of BDS table, DRVLIM_H,DRVLIM_L which were
  3369                                  ;set according to the partition information. We are going to
  3370                                  ;see if (hidden sectors + total sectors) > a word.  If it is true,
  3371                                  ;then no change.  Otherwise, DRVLIM_L will be moved to DRVLIM
  3372                                  ;and DRVLIM_L will be set to 0.
  3373                                  ;We don't do this for the bpb information from the boot record. We
  3374                                  ;are not going to change the BPB information from the boot record.
  3375                                  Massage_bpb:				;AN000;
  3376                                   assume es:nothing
  3377 00000C99 8B551D                  	mov	dx, [di + DRVLIM_H]	;AN000;
  3378 00000C9C 8B451B                  	mov	ax, [di + DRVLIM_L]	;AN000;
  3379 00000C9F 83FA00                  	cmp	dx,0			;AN000; Double word total sector?
  3380 00000CA2 7716                    	ja	init_GOODRET		;AN000; don't have to change it.
  3381 00000CA4 837D1900                	cmp	word [di + HIDSEC_H], 0	;AN000;
  3382 00000CA8 7710                    	ja	init_GOODRET		;AN000; don't have to change it.
  3383 00000CAA 034517                  	add	ax, [di + HIDSEC_L]	;AN000;
  3384 00000CAD 720B                    	jc	init_GOODRET		;AN000; bigger than a word boundary
  3385 00000CAF 8B451B                  	mov	ax, [di + DRVLIM_L]	;AN000;
  3386 00000CB2 89450E                  	mov	[di + DRVLIM], ax 	;AN000;
  3387 00000CB5 C7451B0000              	mov	word [di + DRVLIM_L], 0	;AN000;
  3388                                  init_GOODRET:
  3389 00000CBA 837D1D00                	cmp	word [di + DRVLIM_H], 0	;AN014; Big media?
  3390 00000CBE 760F                    	jbe	Not_BigMedia		;AN014; No.
  3391 00000CC0 06                      	push	es			;AN014;
  3392 00000CC1 50                      	push	ax			;AN014;
  3393 00000CC2 B8[ssss]                	mov	ax, SYSINITSEG		;AN014;
  3394 00000CC5 8EC0                    	mov	es, ax			;AN014;
  3395                                   assume es:SYSINITGROUP
  3396 00000CC7 26C606[0000]01          	mov	byte [es:Big_Media_Flag], 1	;AN014; Set the flag in SYSINITSEG.
  3397 00000CCD 58                      	pop	ax			;AN014;
  3398 00000CCE 07                      	pop	es			;AN014;
  3399                                   assume es:nothing
  3400                                  Not_BigMedia:				;AN014;
  3401 00000CCF 2E8A1E[0700]            	MOV	BL,[cs:FBIGFAT]
  3402 00000CD4 885D1F                  	MOV	[DI + FATSIZ],BL		; SET SIZE OF FAT ON MEDIA
  3403                                  
  3404                                  partition_reject:
  3405 00000CD7 0E                      	 push cs
  3406 00000CD8 1F                      	 pop ds
  3407                                   assume ds:SYSINITGROUP
  3408 00000CD9 E831F7                  	call upb_reset
  3409 00000CDC 07                      	pop es
  3410                                   assume es:SYSINITGROUP
  3411 00000CDD 5E                      	pop si
  3412 00000CDE 5D                      	pop bp
  3413 00000CDF 5F                      	pop di
  3414 00000CE0 59                      	pop cx
  3415 00000CE1 C3                      	retn
  3416                                  
  3417                                  
  3418                                  		; INP:	es:bx -> transfer address
  3419                                  		;	cl = count
  3420                                  		;	ch = 02h (function code for read CHS)
  3421                                  		;	dx:ax = sector number
  3422                                  		;	ds:di -> UPB
  3423                                  		; CHG:	ax, cx, dx
  3424                                  		; OUT:	CY if error,
  3425                                  		;	 ah = error code
  3426                                  		;	NC if success
  3427                                  readsector_detect:
  3428                                   assume ds:UPB, es:nothing, ss:nothing
  3429 00000CE2 51                      	push cx
  3430 00000CE3 52                      	push dx
  3431 00000CE4 8A5504                  	mov dl, byte ptr [di + DRIVENUM]
  3432 00000CE7 E83800                  	call detectlba
  3433 00000CEA 5A                      	pop dx
  3434 00000CEB 59                      	pop cx
  3435 00000CEC EB08                    	jmp readsector_NC_LBA
  3436                                  
  3437                                  readsector_flag:
  3438                                   assume ds:UPB, es:nothing, ss:nothing
  3439 00000CEE F745230004              	test word ptr [di + FLAGS], F_LBA
  3440 00000CF3 7501                    	jnz readsector_NC_LBA		; --> (NC)
  3441 00000CF5 F9                      	stc
  3442                                  
  3443                                  readsector_NC_LBA:
  3444 00000CF6 1E                      	push ds
  3445 00000CF7 56                      	push si
  3446 00000CF8 720D                    	jc readsector_chs
  3447                                  readsector_lba:
  3448 00000CFA FF7504                  	push word ptr [di + DRIVENUM]
  3449 00000CFD E8D6FCEB02[0000]        	neartransfer lba_packet_setup
  3450                                   assume ds:DOSGROUP
  3451 00000D04 5A                      	pop dx				; dl = unit
  3452 00000D05 EB12                    	jmp readsector_common
  3453                                  
  3454                                  readsector_chs:
  3455 00000D07 51                      	push cx
  3456 00000D08 E8CBFCEB02[0000]        	neartransfer lbatochs
  3457 00000D0F 58                      	pop ax
  3458 00000D10 720C                    	jc readsector_ret_ah
  3459 00000D12 E8C1FCEB02[0000]        	neartransfer chstotuple
  3460                                  
  3461                                  readsector_common:
  3462 00000D19 CD13                    	int 13h
  3463                                  readsector_ret:
  3464 00000D1B 5E                      	pop si
  3465 00000D1C 1F                      	pop ds
  3466                                   assume ds:UPB
  3467 00000D1D C3                      	retn
  3468                                  
  3469                                  readsector_ret_ah:
  3470 00000D1E B404                    	mov ah, 04h			; sector not found
  3471 00000D20 EBF9                    	jmp readsector_ret
  3472                                  
  3473                                  
  3474                                  		; INP:	dl = unit number
  3475                                  		; OUT:	CY no LBA
  3476                                  		;	NC LBA
  3477                                  		; CHG:	cx
  3478                                  detectlba:
  3479                                   assume ds:nothing, es:nothing, ss:nothing
  3480 00000D22 50                      	push ax
  3481 00000D23 53                      	push bx
  3482 00000D24 52                      	push dx
  3483 00000D25 1E                      	push ds
  3484                                  
  3485 00000D26 B84000                  	mov ax, 40h
  3486 00000D29 8ED8                    	mov ds, ax
  3487                                   assume ds:nothing
  3488                                  ; Setting ds = 40h is a Book8088 bugfix, refer to
  3489                                  ;  http://www.bttr-software.de/forum/forum_entry.php?id=21061
  3490                                  
  3491 00000D2B B80041                  	mov ax, 4100h
  3492 00000D2E BBAA55                  	mov bx, 55AAh
  3493 00000D31 31C9                    	xor cx, cx
  3494 00000D33 30F6                    	xor dh, dh
  3495 00000D35 F9                      	stc
  3496 00000D36 CD13                    	int 13h
  3497 00000D38 1F                      	pop ds
  3498                                   assume ds:nothing
  3499 00000D39 720A                    	jc detectlba_ret		; --> CY
  3500 00000D3B 81FB55AA                	cmp bx, 0AA55h
  3501 00000D3F F9                      	stc				; CY
  3502 00000D40 7503                    	jne detectlba_ret
  3503 00000D42 D1E9                    	shr cx, 1			; CY if have LBA access functions
  3504 00000D44 F5                      	cmc				; NC if have
  3505                                  detectlba_ret:
  3506 00000D45 5A                      	pop dx
  3507 00000D46 5B                      	pop bx
  3508 00000D47 58                      	pop ax
  3509 00000D48 C3                      	ret
  3510                                  
  3511                                  
  3512                                  Cover_FDISK_Bug		proc			      ;AN010;
  3513                                   assume ds:UPB, es:DOSENTRYGROUP, ss:nothing
  3514                                  ;FDISK of PC DOS 3.3 and below, OS2 1.0 has a bug.  The maximum number of
  3515                                  ;sector that can be handled by PC DOS 3.3 ibmbio should be 0FFFFh.
  3516                                  ;Instead, sometimes FDISK use 10000h to calculate the maximum number.
  3517                                  ;So, we are going to check that if SECNUM + Hidden sector = 10000h
  3518                                  ;then subtrack 1 from SECNUM.
  3519 00000D49 50                      	push	ax				      ;AN010;
  3520 00000D4A 52                      	push	dx				      ;AN010;
  3521 00000D4B 56                      	push	si				      ;AN010;
  3522 00000D4C 26803E[0000]29          	cmp	byte [es:Ext_Boot_Sig], EXT_BOOT_SIGNATURE ;AN010;
  3523 00000D52 742E                    	je	CFB_Retit			      ;AN010;if extended BPB, then >= PC DOS 4.00
  3524 00000D54 26817F073130            	cmp	word ptr [es:bx+7], ("0" << 8) + "1"   ;AN011; OS2 1.0 ? = IBM 10.0
  3525 00000D5A 7507                    	jne	CFB_Chk_SECNUM			      ;AN010;
  3526 00000D5C 26807F0A30              	cmp	byte ptr [es:bx+10], "0"              ;AN010;
  3527 00000D61 751F                    	jne	CFB_Retit			      ;AN010;
  3528                                  CFB_Chk_SECNUM:					      ;AN010;
  3529                                  BPB_In_Sector equ Bpb_In_Sector	; NASM port label
  3530 00000D63 BE[0000]                	mov	si, offset BPB_In_Sector	      ;AN010;
  3531 00000D66 26837C0800              	cmp	word [es:si + SECNUM], 0		      ;AN010;Just to make sure.
  3532 00000D6B 7415                    	je	CFB_Retit			      ;AN010;
  3533 00000D6D 268B4408                	mov	ax, [es:si + SECNUM]		      ;AN010;
  3534 00000D71 26034411                	add	ax, [es:si + HIDDEN_L]		      ;AN010;
  3535 00000D75 730B                    	jnc	CFB_Retit			      ;AN010;
  3536 00000D77 85C0                    	test	ax, ax				      ;AN010;if carry set and AX=0?
  3537 00000D79 7507                    	jnz	CFB_Retit			      ;AN010;
  3538 00000D7B 26FF4C08                	dec	word [es:si + SECNUM]			      ;AN010;  then decrease SECNUM by 1.
  3539 00000D7F FF4D1B                  	dec	word [di + DRVLIM_L]			      ;AN010;
  3540                                  CFB_Retit:					      ;AN010;
  3541 00000D82 5E                      	pop	si				      ;AN010;
  3542 00000D83 5A                      	pop	dx				      ;AN010;
  3543 00000D84 58                      	pop	ax				      ;AN010;
  3544 00000D85 C3                      	ret					      ;AN010;
  3545                                  Cover_FDISK_Bug		endp			      ;AN010;
  3546                                  
  3547                                  
  3548                                  ; SETDRVPARMS SETS UP THE RECOMMENDED BPB IN EACH BDS IN THE SYSTEM BASED ON
  3549                                  ; THE FORM FACTOR. IT IS ASSUMED THAT THE BPBS FOR THE VARIOUS FORM FACTORS
  3550                                  ; ARE PRESENT IN THE BPBTABLE. FOR HARD FILES, THE RECOMMENDED BPB IS THE SAME
  3551                                  ; AS THE BPB ON THE DRIVE.
  3552                                  
  3553                                  ; NO ATTEMPT IS MADE TO PRESERVE REGISTERS SINCE WE ARE GOING TO JUMP TO
  3554                                  ; SYSINIT STRAIGHT AFTER THIS ROUTINE.
  3555                                  
  3556                                  SETDRVPARMS PROC NEAR
  3557                                   assume ds:nothing, es:nothing, ss:nothing
  3558                                  	MESSAGE FTESTINIT,<"SETTING DRIVE PARAMETERS",CR,LF>
  3559 00000D86 31DB                    	XOR	BX,BX
  3560 00000D88 E82DFC                  	call sysinit_get_es_dosbiodata
  3561                                   assume es:DOSGROUP
  3562 00000D8B 26C43E[0000]            	LES	DI,[es:START_BDS] ; GET FIRST BDS IN LIST
  3563                                   assume es:UPB
  3564                                  NEXT_BDS:
  3565 00000D90 83FFFF                  	CMP	DI,-1
  3566 00000D93 7501                    	JNZ	DO_SETP
  3567                                  DONE_SETPARMS:
  3568 00000D95 C3                      	RET
  3569                                  
  3570                                  DO_SETP:
  3571                                   assume es:UPB
  3572 00000D96 06                      	PUSH	ES
  3573 00000D97 57                      	PUSH	DI			; PRESERVE POINTER TO BDS
  3574 00000D98 268A5D22                	MOV	BL,[ES:DI + FORMFACTOR]
  3575 00000D9C 80FB05                  	CMP	BL,FFHARDFILE
  3576 00000D9F 7541                    	JNZ	NOTHARDFF
  3577                                  
  3578 00000DA1 31D2                    	xor	dx,dx			;AN000;
  3579 00000DA3 268B450E                	MOV	AX,[ES:DI + DRVLIM]
  3580 00000DA7 85C0                    	test ax, ax			;AN000;
  3581 00000DA9 7508                    	jnz	GET_cCYL		;AN000;
  3582 00000DAB 268B551D                	mov	dx,[es:di + DRVLIM_H]	;AN000; Use Double word sector number
  3583 00000DAF 268B451B                	MOV	AX,[ES:DI + DRVLIM_L]	;AN000;
  3584                                  GET_cCYL:
  3585 00000DB3 52                      	push	dx			;AN000;
  3586 00000DB4 50                      	PUSH	AX
  3587 00000DB5 268B4515                	MOV	AX,WORD PTR [ES:DI + HDLIM]
  3588 00000DB9 26F76513                	MUL	WORD PTR [ES:DI + SECLIM] ;Assume Sectorsp per cyl. < 64K.
  3589 00000DBD 89C1                    	MOV	CX,AX			; CX HAS # SECTORS PER CYLINDER
  3590 00000DBF 58                      	POP	AX			;
  3591 00000DC0 5A                      	pop	dx			;AN000; Restore drvlim.
  3592 00000DC1 50                      	push	ax			;AN000;
  3593 00000DC2 92                      	xchg	ax, dx			; ax = high word, clobber dx
  3594 00000DC3 31D2                    	xor	dx,dx			;AN000;
  3595 00000DC5 F7F1                    	div	cx			;AN000;
  3596 00000DC7 1E                      	push ds
  3597 00000DC8 E8DDFB                  	call sysinit_get_ds_dosbiodata
  3598                                   assume ds:DOSGROUP
  3599 00000DCB A3[0000]                	mov	[Temp_H],ax		;AN000; AX be 0 here.
  3600 00000DCE 1F                      	pop ds
  3601                                   assume ds:nothing
  3602 00000DCF 58                      	pop	ax			;AN000;
  3603 00000DD0 F7F1                    	DIV	CX			; DIV #SEC BY SEC/CYL TO GET # CYL.
  3604 00000DD2 09D2                    	OR	DX,DX
  3605 00000DD4 7401                    	JZ	NO_CYL_RND		; CAME OUT EVEN
  3606 00000DD6 40                      	INC	AX			; ROUND UP
  3607                                  NO_CYL_RND:
  3608 00000DD7 26894525                	MOV	[ES:DI + CCYLN],AX
  3609                                  	MESSAGE FTESTINIT,<"CCYLN ">
  3610                                  	MNUM	FTESTINIT,AX
  3611                                  	MESSAGE FTESTINIT,<CR,LF>
  3612 00000DDB 06                      	PUSH	ES
  3613 00000DDC 1F                      	POP	DS
  3614                                   assume ds:UPB
  3615 00000DDD 8D7506                  	LEA	SI,[DI + BYTEPERSEC]	; DS:SI -> BPB FOR HARD FILE
  3616 00000DE0 EB3B                    	JMP	SHORT SET_RECBPB
  3617                                  
  3618                                  NOTHARDFF:
  3619                                  ;J.K. We don't use the extended BPB for a floppy.
  3620                                  ;J.K.6/24/87
  3621                                  
  3622                                  ;SB34INIT007******************************************************************
  3623                                  ;SB	If Fake floppy drive variable is set then we don't have to handle this
  3624                                  ;SB	BDS.  We can just go and deal with the next BDS at label Go_To_Next_BDS.
  3625                                  
  3626 00000DE2 2E803E[0600]01          	cmp	byte [cs:FakeFloppyDrv],1
  3627                                  Go_To_Next_BDS equ GO_TO_NEXT_BDS	; NASM port label
  3628 00000DE8 743B                    	jz	Go_To_Next_BDS
  3629                                  ;SB34INIT007******************************************************************
  3630                                  
  3631 00000DEA 80FB07                  	CMP	BL,FFOTHER		; SPECIAL CASE "OTHER" TYPE OF MEDIUM
  3632 00000DED 7526                    	JNZ	NOT_PROCESS_OTHER
  3633                                  PROCESS_OTHER:
  3634 00000DEF 268B4525                	MOV	AX,[es:DI + CCYLN]
  3635 00000DF3 26F76536                	mul word [es:DI + RHDLIM]
  3636 00000DF7 26F76534                	mul word [es:DI + RSECLIM]
  3637 00000DFB 2689452F                	MOV	[es:DI + RDRVLIM],AX 	; HAVE THE TOTAL NUMBER OF SECTORS
  3638 00000DFF 48                      	DEC	AX
  3639                                  
  3640                                  ;J.K. Old logic was...
  3641                                  ;	 MOV	 BX,515
  3642                                  ;	 DIV	 BX
  3643                                  ;	 OR	 DX,DX
  3644                                  ;	 JZ	 NO_ROUND_UP
  3645                                  ;	 INC	 AX			 ; ROUND UP NUMBER OF FAT SECTORS
  3646                                  
  3647                                  ;J.K. New logic to get the sectors/fat area.
  3648                                  					;Fat entry is assumed to be 1.5 bytes!!!
  3649 00000E00 BB0300                  	mov	bx, 3
  3650 00000E03 F7E3                    	mul	bx
  3651 00000E05 4B                      	dec bx				; = 2
  3652 00000E06 F7F3                    	div	bx
  3653 00000E08 31D2                    	xor	dx, dx
  3654 00000E0A 86DF                    	xchg bl, bh			; bh = 2, bl = 0, bx = 512
  3655 00000E0C F7F3                    	div	bx
  3656 00000E0E 40                      	inc	ax
  3657                                  
  3658                                  NO_ROUND_UP:
  3659 00000E0F 26894532                	MOV	[es:DI + RCSECFAT],AX
  3660 00000E13 EB10                    	JMP	SHORT GO_TO_NEXT_BDS
  3661                                  NOT_PROCESS_OTHER:
  3662 00000E15 D1E3                    	SHL	BX,1			; BX IS WORD INDEX INTO TABLE OF BPBS
  3663 00000E17 0E                      	push cs
  3664 00000E18 1F                      	pop ds
  3665                                   assume ds:SYSINITGROUP
  3666 00000E19 8BB7[7001]              	MOV	SI,WORD PTR [BPBTABLE + BX]	; GET ADDRESS OF BPB ; access with ds
  3667                                  SET_RECBPB:
  3668 00000E1D 8D7D27                  	LEA	DI,[DI + RBYTEPERSEC]	; ES:DI -> RECBPB
  3669 00000E20 B91900                  	MOV	CX,BPBSIZ
  3670 00000E23 F3A4                    	REP	MOVSB			; MOVE BPBSIZ BYTES
  3671                                  GO_TO_NEXT_BDS:
  3672 00000E25 5F                      	POP	DI
  3673 00000E26 07                      	POP	ES			; RESTORE POINTER TO BDS
  3674                                   assume es:UPB
  3675 00000E27 26C43D                  	les di, [ES:DI + LINK]
  3676 00000E2A E963FF                  	JMP	NEXT_BDS
  3677                                  
  3678                                  SETDRVPARMS ENDP
  3679                                  
  3680                                  
  3681                                  usesection DOSENTRYINIT
  3682                                  
  3683                                  ;
  3684                                  ; SI POINTS TO DEVICE HEADER
  3685                                  ; J.K. 4/22/86 - print_init, aux_init is modified to eliminate the self-modifying
  3686                                  ; J.K. code.
  3687                                  
  3688                                  PRINT_INIT:
  3689                                  Get_device_number equ GET_DEVICE_NUMBER	; NASM port label
  3690 00000733 E80F00                  	call	Get_device_number
  3691                                  ;SB33028*****************************************************************
  3692 00000736 B401                    	mov	ah,1			;initalize printer port        ;SB;3.30
  3693 00000738 CD17                    	int	17h			;call ROM-Bios routine	       ;SB;3.30
  3694                                  ;SB33028*****************************************************************
  3695 0000073A C3                      	ret
  3696                                  
  3697                                  AUX_INIT:
  3698 0000073B E80700                  	call	Get_device_number
  3699                                  ;SB33028*****************************************************************
  3700 0000073E B0A3                    	mov	al,RSINIT		;2400,N,1,8 (MSEQU.INC)       ;SB ;3.30*
  3701 00000740 B400                    	mov	ah,0			;initalize AUX port	      ;SB ;3.30*
  3702 00000742 CD14                    	int	14h			;call ROM-Bios routine	      ;SB ;3.30*
  3703                                  ;SB33028*****************************************************************
  3704 00000744 C3                      	ret
  3705                                  
  3706                                  GET_DEVICE_NUMBER:
  3707                                  ;SI -> device header
  3708 00000745 2E8A440D                	MOV	AL,[CS:SI+13]		;GET DEVICE NUMBER FROM THE NAME
  3709 00000749 2C31                    	SUB	AL,"1"
  3710 0000074B 98                      	CBW
  3711 0000074C 89C2                    	MOV	DX,AX
  3712 0000074E C3                      	RET
  3713                                  
  3714                                  %if 0
  3715                                  ;
  3716                                  ;   PURGE_96TPI NOP'S CALLS TO 96TPI SUPPORT.
  3717                                  ;
  3718                                  PURGE_96TPI PROC NEAR			;MJB001
  3719                                  	PUSH	DS
  3720                                  	PUSH	ES
  3721                                  
  3722                                  	PUSH	CS			;MJB001
  3723                                  	POP	ES			;MJB001
  3724                                  	PUSH	CS			;MJB001
  3725                                  	POP	DS			;MJB001
  3726                                  	; ASSUME	DS:BIOCODE,ES:BIOCODE
  3727                                  
  3728                                  	MOV	SI,OFFSET PATCHTABLE
  3729                                  PATCHLOOP:
  3730                                  	LODSW
  3731                                  	MOV	CX,AX
  3732                                  	JCXZ	PATCHDONE
  3733                                  	LODSW
  3734                                  	MOV	DI,AX
  3735                                  	MOV	AL,90H
  3736                                  	REP	STOSB
  3737                                  	JMP	PATCHLOOP
  3738                                  
  3739                                  PATCHDONE:
  3740                                  ;**************NOT NEEDED ANY MORE***********************
  3741                                  ;	MOV	DI,OFFSET FORMAT_PATCH	     ; ARR 2.42
  3742                                  ;	MOV	AL,CS:INST_FAR_RET
  3743                                  ;	STOSB
  3744                                  ;********************************************************
  3745                                  	MOV	DI,OFFSET TABLE_PATCH	; ARR 2.42
  3746                                  	MOV	AX,OFFSET EXIT
  3747                                  	STOSW
  3748                                  	STOSW
  3749                                  
  3750                                  	POP	ES
  3751                                  	POP	DS
  3752                                  	RET				;MJB001
  3753                                  PURGE_96TPI ENDP
  3754                                  %endif
  3755                                  
  3756                                  
  3757                                  usesection SYSINITTRAIL
  3758                                  
  3759                                  set_bpb:
  3760 00000E2D 56                      	push si
  3761 00000E2E 53                      	push	bx			; now, set the DskDrvs pointer to BPB info
  3762 00000E2F 2E8B1E[DE00]            	mov	bx, [cs:Mini_BPB_ptr]
  3763 00000E34 8D7506                  	lea	si, [di + BYTEPERSEC]	; points to BPB of BDSM
  3764 00000E37 2E8937                  	mov	[cs:bx], si
  3765 00000E3A 43                      	inc bx
  3766 00000E3B 43                      	inc bx
  3767 00000E3C 2E891E[DE00]            	mov word [cs:Mini_BPB_ptr], bx	; advance to the next address
  3768 00000E41 5B                      	pop	bx
  3769 00000E42 5E                      	pop si
  3770 00000E43 C3                      	retn
  3771                                  
  3772                                  have_bpb:
  3773 00000E44 2E813E[DE00][2001]      	cmp word [cs:Mini_BPB_ptr], DSKDRVS.end
  3774                                  					; CY if valid to append another
  3775 00000E4B F5                      	cmc				; NC if valid
  3776 00000E4C C3                      	retn
  3777                                  
  3778                                  
  3779                                  ;
  3780                                  ;Install BDSM installs a BDSM (pointed by DS:DI) into the end of the current
  3781                                  ;linked list of BDS.
  3782                                  ;Also, set the current BDSM pointer segment to DS.
  3783                                  ;At entry: DS:DI -> BDSM
  3784                                  ;
  3785                                  Install_BDSM_and_set_bpb:
  3786                                   assume ds:UPB, es:nothing, ss:nothing
  3787 00000E4D E8DDFF                  	call set_bpb
  3788                                  Install_BDSM:
  3789                                   assume ds:UPB, es:nothing, ss:nothing
  3790 00000E50 50                      	push	ax
  3791 00000E51 56                      	push	si
  3792 00000E52 06                      	push	es
  3793                                  
  3794                                   extern sysinit_have_bootdrive_preliminary
  3795                                   extern sysinit_have_bootdrive_exact
  3796 00000E53 2ED006[0000]            	rol byte [cs:sysinit_have_bootdrive_exact], 1
  3797 00000E58 7242                    	jc .skip
  3798                                  
  3799 00000E5A F6452310                	testopt [di + FLAGS], FI_AM_MULT
  3800 00000E5E 7406                    	jz @F
  3801 00000E60 F6452320                	testopt [di + FLAGS], FI_OWN_PHYSICAL
  3802 00000E64 7436                    	jz .skip
  3803                                  @@:
  3804 00000E66 2EA0[0000]              	mov al, [cs:sysinit_bootdrive_unit]
  3805 00000E6A 3A4504                  	cmp al, [di + DRIVENUM]
  3806 00000E6D 752D                    	jne .skip
  3807 00000E6F 2EA1[0000]              	mov ax, [cs:sysinit_bootdrive_hidden]
  3808 00000E73 3B4517                  	cmp ax, [di + HIDSEC_L]
  3809 00000E76 7510                    	jne .prelim
  3810 00000E78 2EA1[0200]              	mov ax, [cs:sysinit_bootdrive_hidden + 2]
  3811 00000E7C 3B4519                  	cmp ax, [di + HIDSEC_H]
  3812 00000E7F 7507                    	jne .prelim
  3813 00000E81 2EF616[0000]            	not byte [cs:sysinit_have_bootdrive_exact]
  3814 00000E86 EB0C                    	jmp .save
  3815                                  
  3816                                  .prelim:
  3817 00000E88 2ED006[0000]            	rol byte [cs:sysinit_have_bootdrive_preliminary], 1
  3818 00000E8D 720D                    	jc .skip
  3819 00000E8F 2EF616[0000]            	not byte [cs:sysinit_have_bootdrive_preliminary]
  3820                                  .save:
  3821 00000E94 8A4505                  	mov al, [di + DRIVELET]
  3822 00000E97 40                      	inc ax
  3823 00000E98 2EA2[0000]              	mov byte [cs:DEFAULT_DRIVE], al
  3824                                  .done:
  3825                                  .skip:
  3826                                  
  3827 00000E9C B8FFFF                  	mov ax, -1
  3828 00000E9F 894502                  	mov word ptr [di + LINK + 2], ax
  3829 00000EA2 8905                    	mov word ptr [di + LINK], ax	; make sure it is a null ptr.
  3830                                  
  3831 00000EA4 E811FB                  	call sysinit_get_es_dosbiodata
  3832                                   assume es:DOSGROUP
  3833                                  Start_BDS equ START_BDS	; NASM port label
  3834 00000EA7 26C436[0000]            	les	si, [es:Start_BDS]	;start of the beginning of list
  3835                                   assume es:UPB
  3836 00000EAC 39C6                    	cmp si, ax
  3837 00000EAE 750F                    	jne I_BDSM_Next
  3838 00000EB0 E805FB                  	call sysinit_get_es_dosbiodata
  3839                                   assume es:DOSGROUP
  3840 00000EB3 26893E[0000]            	mov word [es:Start_BDS], di
  3841 00000EB8 268C1E[0200]            	mov word [es:Start_BDS + 2], ds
  3842 00000EBD EB11                    	jmp I_BDSM_ret
  3843                                  
  3844                                  I_BDSM_Next:
  3845                                   assume es:UPB
  3846 00000EBF 263904                  	cmp	word ptr [es:si + LINK], ax	;end of the list?
  3847 00000EC2 7405                    	je	I_BDSM_New
  3848 00000EC4 26C434                  	les	si, [es:si + LINK]
  3849 00000EC7 EBF6                    	jmp	short I_BDSM_Next
  3850                                  I_BDSM_New:
  3851 00000EC9 268C5C02                	mov	word ptr [es:si + LINK + 2], ds
  3852 00000ECD 26893C                  	mov	word ptr [es:si + LINK], di
  3853                                  
  3854                                  I_BDSM_ret:
  3855 00000ED0 07                      	pop	es
  3856                                   assume es:nothing
  3857 00000ED1 5E                      	pop	si
  3858 00000ED2 58                      	pop	ax
  3859 00000ED3 C3                      	ret
  3860                                  
  3861                                  ;***The following code is not needed any more.	Don't show any
  3862                                  ;***messages to be compatible with the behavior of IBMBIO.COM.
  3863                                  ;;Show the message "Mini disk installed ..."
  3864                                  ;;This routine uses WRMSG procedure which will call OUTCHR.
  3865                                  ;Show_Installed_Mini:
  3866                                  ;	 push	 ax
  3867                                  ;	 push	 bx
  3868                                  ;	 push	 ds
  3869                                  ;
  3870                                  ;	 mov	 al, MiniNum		 ;logical drive number
  3871                                  ;	 add	 al, Drv_Letter_Base	 ;='A'
  3872                                  ;	 mov	 Mini_Drv_Let, al
  3873                                  ;	 mov	 si, offset Installed_Mini
  3874                                  ;	 call	 WRMSG
  3875                                  ;
  3876                                  ;	 pop	 ds
  3877                                  ;	 pop	 bx
  3878                                  ;	 pop	 ax
  3879                                  ;	 ret
  3880                                  ;**End of mini disk initialization**	;J.K. 4/7/86
  3881                                  
  3882                                  msg:
  3883 00000ED4 426F6F74206572726F-     .bootfail:			asciz "Boot error: "
  3883 00000EDD 723A2000           
  3884 00000EE1 52656164696E672070-     .bootfail_read:			db "Reading partition table sector failed (error "
  3884 00000EEA 6172746974696F6E20-
  3884 00000EF3 7461626C6520736563-
  3884 00000EFC 746F72206661696C65-
  3884 00000F05 6420286572726F7220 
  3885 00000F0E 5F5F68292E0D0A00        .bootfail_read_errorcode:	asciz "__h).",13,10
  3886 00000F16 4475706C6963617465-     .duplicate:			db "Duplicate partition login attempt, unit="
  3886 00000F1F 20706172746974696F-
  3886 00000F28 6E206C6F67696E2061-
  3886 00000F31 7474656D70742C2075-
  3886 00000F3A 6E69743D           
  3887 00000F3E 2D2D682C2068696464-     .duplicate_unit:		db "--h, hidden="
  3887 00000F47 656E3D             
  3888 00000F4A 2D2D2D2D5F              .duplicate_hidden_h:		db "----_"
  3889 00000F4F 2D2D2D2D682E0D0A00      .duplicate_hidden_l:		asciz "----h.",13,10
  3890 00000F58 506172746974696F6E-     .bootfail_sig_parttable:	ascii "Partition table signature missing"
  3890 00000F61 207461626C65207369-
  3890 00000F6A 676E6174757265206D-
  3890 00000F73 697373696E67       
  3891 00000F79 20286973206E6F7420-     				asciz " (is not AA55h).",13,10
  3891 00000F82 4141353568292E0D0A-
  3891 00000F8B 00                 
  3892 00000F8C 546F6F206D616E7920-     .boot_too_many_partitions_error:asciz "Too many partitions (or a loop).",13,10
  3892 00000F95 706172746974696F6E-
  3892 00000F9E 7320286F722061206C-
  3892 00000FA7 6F6F70292E0D0A00   
  3893 00000FAF 506172746974696F6E-     .boot_partition_cycle_error:	asciz "Partition table cycle detected.",13,10
  3893 00000FB8 207461626C65206379-
  3893 00000FC1 636C65206465746563-
  3893 00000FCA 7465642E0D0A00     
  3894                                  
  3895                                  
  3896                                  	usesection DOSENTRYINIT
  3897                                  
  3898                                  CMOS_Clock_Read proc	near
  3899                                  ; IN ORDER TO DETERMINE IF THERE IS A CLOCK PRESENT IN THE SYSTEM, THE FOLLOWING
  3900                                  ; NEEDS TO BE DONE.
  3901 0000074F 1E                      	push ds
  3902 00000750 E8BCFF                  	call dosentry_init_get_ds_dosbiodata
  3903                                   assume ds:DOSGROUP, es:nothing, ss:nothing
  3904 00000753 50                      	PUSH	AX
  3905 00000754 51                      	PUSH	CX
  3906 00000755 52                      	PUSH	DX
  3907 00000756 55                      	PUSH	BP
  3908                                  
  3909 00000757 31ED                    	XOR	BP,BP
  3910                                  LOOP_CLOCK:
  3911 00000759 31C9                    	XOR	CX,CX
  3912 0000075B 31D2                    	XOR	DX,DX
  3913                                  ;SB33030********************************************************************
  3914 0000075D B402                    	MOV	AH,2			;READ REAL TIME CLOCK	      ;SB ;3.30
  3915 0000075F CD1A                    	INT	1Ah			;CALL ROM-BIOS ROUTINE	      ;SB ;3.30
  3916                                  ;SB33030********************************************************************
  3917 00000761 83F900                  	CMP	CX,0
  3918 00000764 7512                    	JNZ	CLOCK_PRESENT
  3919                                  
  3920 00000766 83FA00                  	CMP	DX,0
  3921 00000769 750D                    	JNZ	CLOCK_PRESENT
  3922                                  
  3923 0000076B 83FD01                  	CMP	BP,1			; READ AGAIN AFTER A SLIGHT DELAY, IN CASE CLOCK
  3924 0000076E 741C                    	JZ	NO_READDATE		; WAS AT ZERO SETTING.
  3925                                  
  3926 00000770 45                      	INC	BP			; ONLY PERFORM DELAY ONCE.
  3927 00000771 B90040                  	MOV	CX,4000H
  3928                                  DELAY:
  3929 00000774 E2FE                    	LOOP	DELAY
  3930 00000776 EBE1                    	JMP	LOOP_CLOCK
  3931                                  
  3932                                  CLOCK_PRESENT:
  3933 00000778 C606[0000]01            	mov	byte [HaveCMOSClock], 1	;J.K. Set the flag for cmos clock
  3934                                  
  3935 0000077D E82E00                  	call	CMOSCK			;J.K. Reset CMOS clock rate that may be
  3936                                  					;possibly destroyed by CP DOS and POST routine did not
  3937                                  					;restore that.
  3938                                  
  3939 00000780 56                      	PUSH	SI
  3940                                  	MESSAGE FTESTINIT,<"CLOCK DEVICE",CR,LF>
  3941 00000781 0E                      	push cs
  3942 00000782 E80D00                  	call transfer_read_real_date	;MJB002 READ REAL-TIME CLOCK FOR DATE
  3943                                  
  3944 00000785 FA                      	CLI				;MJB002
  3945 00000786 8936[0000]              	MOV	[DAYCNT],SI	      ;MJB002 SET SYSTEM DATE
  3946 0000078A FB                      	STI				;MJB002
  3947 0000078B 5E                      	POP	SI			;MJB002
  3948                                  NO_READDATE:
  3949 0000078C 5D                      	POP	BP
  3950 0000078D 5A                      	POP	DX
  3951 0000078E 59                      	POP	CX
  3952 0000078F 58                      	POP	AX
  3953 00000790 1F                      	pop ds
  3954                                   assume ds:nothing
  3955 00000791 C3                      	RET
  3956                                  
  3957                                  		; INP:	dword [ss:sp] = far return address
  3958                                  transfer_read_real_date:
  3959                                   assume ds:nothing, es:nothing, ss:nothing
  3960 00000792 50                      	push ax
  3961 00000793 50                      	push ax
  3962 00000794 B8[D800]                	mov ax, near_read_real_date
  3963 00000797 50                      	push ax
  3964                                  	lframe 0
  3965                                  	lpar word, orig_ax_near_ret		; original ax
  3966                                  	lpar word, transfer_segment
  3967                                  	lpar word, transfer_offset		; already initialised
  3968 00000798 5589E5                  	lenter
  3969 0000079B 1E                      	push ds
  3970 0000079C E870FF                  	call dosentry_init_get_ds_dosdata
  3971                                   assume ds:DOSGROUP
  3972 0000079F A1[0000]                	mov ax, word [dosdata_to_doscode]
  3973 000007A2 1F                      	pop ds
  3974                                   assume ds:nothing
  3975 000007A3 894604                  	mov word [bp + ?transfer_segment], ax
  3976                                   extern biocode_retf
  3977 000007A6 B8[0000]                	mov ax, biocode_retf
  3978 000007A9 874606                  	xchg ax, word [bp + ?orig_ax_near_ret]
  3979 000007AC 5D                      	lleave
  3980 000007AD CB                      	retf
  3981                                  
  3982                                  
  3983                                  CMOS_Clock_Read endp
  3984                                  ;
  3985                                  ;J.K. 10/28/86
  3986                                  ;J.K. THE FOLLOWING CODE IS WRITTEN BY JACK GULLEY IN ENGINEERING GROUP.
  3987                                  ;J.K. CP DOS IS CHANGING CMOS CLOCK RATE FOR ITS OWN PURPOSES AND IF THE
  3988                                  ;J.K. USE COLD BOOT THE SYSTEM TO USE PC DOS WHILE RUNNING CP DOS, THE CMOS
  3989                                  ;J.K. CLOCK RATE ARE STILL SLOW WHICH SLOW DOWN DISK OPERATIONS OF PC DOS
  3990                                  ;J.K. WHICH USES CMOS CLOCK.  PC DOS IS PUT THIS CODE IN MSINIT TO FIX THIS
  3991                                  ;J.K. PROBLEM AT THE REQUEST OF CP DOS.
  3992                                  ;J.K. THE PROGRAM IS MODIFIED TO BE RUN ON MSINIT. Equates are defined in CMOSEQU.INC.
  3993                                  ;J.K. This program will be called by CMOS_Clock_Read procedure.
  3994                                  ;
  3995                                  ;  The following code CMOSCK is used to insure that the CMOS has not
  3996                                  ;	had its rate controls left in an invalid state on older AT's.
  3997                                  ;
  3998                                  ;	It checks for an AT model byte "FC" with a submodel type of
  3999                                  ;	00, 01, 02, 03 or 06 and resets the periodic interrupt rate
  4000                                  ;	bits incase POST has not done it.  This initilization routine
  4001                                  ;	is only needed once when DOS loads.  It should be ran as soon
  4002                                  ;	as possible to prevent slow diskette access.
  4003                                  ;
  4004                                  ;	This code exposes one to DOS clearing CMOS setup done by a
  4005                                  ;	resident program that hides and re-boots the system.
  4006                                  ;
  4007                                  CMOSCK	PROC	NEAR			;	CHECK AND RESET RTC RATE BITS
  4008                                   assume ds:DOSGROUP, es:nothing
  4009                                  
  4010                                  ;Model byte and Submodel byte were already determined in MSINIT.
  4011 000007AE 50                      	push	ax
  4012                                  Model_byte equ Model_Byte	; NASM port label
  4013 000007AF 803E[0000]FC            	cmp	byte [Model_byte], 0FCh	;check for PC-AT model byte
  4014                                  					 ;	 EXIT IF NOT "FC" FOR A PC-AT
  4015 000007B4 7523                    	JNE	CMOSCK9 		; Exit if not an AT model
  4016                                  
  4017 000007B6 803E[0000]06            	CMP	byte [Secondary_Model_Byte],06H  ; Is it 06 for the industral AT
  4018 000007BB 7407                    	JE	CMOSCK4 		; Go reset CMOS periodic rate if 06
  4019 000007BD 803E[0000]04            	CMP	byte [Secondary_Model_Byte],04H  ; Is it 00, 01, 02, or 03
  4020 000007C2 7315                    	JNB	CMOSCK9 		; EXIT if problem fixed by POST
  4021                                  					;J.K. Also,Secondary_model_byte = 0 when AH=0c0h, int 15h failed.
  4022                                  CMOSCK4:				;	RESET THE CMOS PERIODIC RATE
  4023                                  					;  Model=FC submodel=00,01,02,03 or 06
  4024                                  ;SB33IN2***********************************************************************
  4025                                  
  4026 000007C4 B08A                    	mov	al,CMOS_REG_A | NMI	;NMI disabled on return
  4027 000007C6 B426                    	mov	ah,00100110b		;Set divider & rate selection
  4028 000007C8 E83000                  	call	CMOS_WRITE
  4029                                  
  4030                                  ;SB33IN2***********************************************************************
  4031                                  
  4032                                  					;	CLEAR SET,PIE,AIE,UIE AND SQWE
  4033 000007CB B08B                    	mov	al,CMOS_REG_B | NMI	;NMI disabled on return
  4034 000007CD E80B00                  	call	CMOS_READ
  4035 000007D0 2407                    	and	al,00000111b		;clear SET,PIE,AIE,UIE,SQWE
  4036 000007D2 88C4                    	mov	ah,al
  4037 000007D4 B00B                    	mov	al,CMOS_REG_B		;NMI enabled on return
  4038 000007D6 E82200                  	call	CMOS_WRITE
  4039                                  
  4040                                  ;SB33IN3***********************************************************************
  4041                                  
  4042                                  CMOSCK9:				;	EXIT ROUTINE
  4043 000007D9 58                      	pop	ax
  4044 000007DA C3                      	RET				; RETurn to caller
  4045                                  					;  Flags modifyied
  4046                                  CMOSCK	ENDP
  4047                                  ;PAGE
  4048                                  ;--- CMOS_READ -----------------------------------------------------------------
  4049                                  ;		READ BYTE FROM CMOS SYSTEM CLOCK CONFIGURATION TABLE	       :
  4050                                  ;									       :
  4051                                  ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE READ				       :
  4052                                  ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
  4053                                  ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO READ		       :
  4054                                  ;									       :
  4055                                  ; OUTPUT: (AL)	VALUE AT LOCATION (AL) MOVED INTO (AL).  IF BIT 7 OF (AL) WAS  :
  4056                                  ;		ON THEN NMI LEFT DISABLED.  DURING THE CMOS READ BOTH NMI AND  :
  4057                                  ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
  4058                                  ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
  4059                                  ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
  4060                                  ;		ONLY THE (AL) REGISTER AND THE NMI STATE IS CHANGED.	       :
  4061                                  ;-------------------------------------------------------------------------------
  4062                                  
  4063                                  CMOS_READ	PROC	NEAR		;	READ LOCATION (AL) INTO (AL)
  4064                                   assume es:nothing,ds:nothing
  4065 000007DB 9C                      	PUSHF				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
  4066                                  ;SB33IN4********************************************************************
  4067                                  
  4068 000007DC FA                      	cli
  4069 000007DD 53                      	push	bx
  4070 000007DE 50                      	push	ax			;save user NMI state
  4071 000007DF 0C80                    	or	al,NMI			;disable NMI for us
  4072 000007E1 E670                    	out	CMOS_PORT,al
  4073 000007E3 90                      	nop				;undocumented delay needed
  4074 000007E4 E471                    	in	al,CMOS_DATA		;get data value
  4075                                  
  4076                                  	 ;set NMI state to user specified 
  4077 000007E6 89C3                    	mov	bx,ax			;save data value
  4078 000007E8 58                      	pop	ax			;get user NMI
  4079 000007E9 2480                    	and	al,NMI
  4080 000007EB 0C0F                    	or	al,CMOS_SHUT_DOWN
  4081 000007ED E670                    	out	CMOS_PORT,al
  4082 000007EF 90                      	nop
  4083 000007F0 E471                    	in	al,CMOS_DATA
  4084                                  
  4085 000007F2 89D8                    	mov	ax,bx			;data value
  4086 000007F4 5B                      	pop	bx
  4087                                  
  4088                                  ;SB33IN4********************************************************************
  4089 000007F5 0E                      	PUSH	CS			; *PLACE CODE SEGMENT IN STACK AND
  4090 000007F6 E80100                  	CALL	CMOS_POPF		; *HANDLE POPF FOR B- LEVEL 80286
  4091 000007F9 C3                      	RET				; RETURN WITH FLAGS RESTORED
  4092                                  
  4093                                  CMOS_READ	ENDP
  4094                                  
  4095                                  CMOS_POPF	PROC	NEAR		;	POPF FOR LEVEL B- PARTS
  4096 000007FA CF                      	IRET				; RETURN FAR AND RESTORE FLAGS
  4097                                  
  4098                                  CMOS_POPF	ENDP
  4099                                  
  4100                                  ;--- CMOS_WRITE ----------------------------------------------------------------
  4101                                  ;		WRITE BYTE TO CMOS SYSTEM CLOCK CONFIGURATION TABLE	       :
  4102                                  ;									       :
  4103                                  ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE WRITTEN TO			       :
  4104                                  ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
  4105                                  ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO WRITE		       :
  4106                                  ;	 (AH)=	NEW VALUE TO BE PLACED IN THE ADDRESSED TABLE LOCATION	       :
  4107                                  ;									       :
  4108                                  ; OUTPUT:	VALUE IN (AH) PLACED IN LOCATION (AL) WITH NMI LEFT DISABLED   :
  4109                                  ;		IF BIT 7 OF (AL) IS ON.  DURING THE CMOS UPDATE BOTH NMI AND   :
  4110                                  ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
  4111                                  ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
  4112                                  ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
  4113                                  ;		ONLY THE CMOS LOCATION AND THE NMI STATE IS CHANGED.	       :
  4114                                  ;-------------------------------------------------------------------------------
  4115                                  
  4116                                  CMOS_WRITE	PROC	NEAR		;	WRITE (AH) TO LOCATION (AL)
  4117                                   assume es:nothing,ds:nothing
  4118 000007FB 9C                      	PUSHF				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
  4119 000007FC 50                      	PUSH	AX			; SAVE WORK REGISTER VALUES
  4120                                  
  4121 000007FD FA                      	cli
  4122 000007FE 50                      	push	ax			;save user NMI state
  4123 000007FF 0C80                    	or	al,NMI			;disable NMI for us
  4124 00000801 E670                    	out	CMOS_PORT,al
  4125 00000803 90                      	nop
  4126 00000804 88E0                    	mov	al,ah
  4127 00000806 E671                    	out	CMOS_DATA,al		;write data
  4128                                  
  4129                                  	 ;set NMI state to user specified 
  4130 00000808 58                      	pop	ax 			;get user NMI
  4131 00000809 2480                    	and	al,NMI
  4132 0000080B 0C0F                    	or	al,CMOS_SHUT_DOWN
  4133 0000080D E670                    	out	CMOS_PORT,al
  4134 0000080F 90                      	nop
  4135 00000810 E471                    	in	al,CMOS_DATA
  4136                                  
  4137                                  ;SB33IN5********************************************************************
  4138 00000812 58                      	POP	AX			; RESTORE WORK REGISTERS
  4139 00000813 0E                      	PUSH	CS			; *PLACE CODE SEGMENT IN STACK AND
  4140 00000814 E8E3FF                  	CALL	CMOS_POPF		; *HANDLE POPF FOR B- LEVEL 80286
  4141 00000817 C3                      	RET
  4142                                  
  4143                                  CMOS_WRITE	ENDP
  4144                                  ;
  4145                                  
  4146                                  %assign NUMBER_DOSENTRY_INIT_DISCARD $ - end_of_dosentry_init_late
  4147                                  %warning DOSENTRY discard size NUMBER_DOSENTRY_INIT_DISCARD
  4147          ******************       warning: DOSENTRY discard size 598 [-w+user]
  4148                                  %if NUMBER_DOSENTRY_INIT_DISCARD < SYSINITSTACK + 64
  4149                                  	; 64 is for the first UMCB and a small safety margin
  4150                                   %assign NUMBER_SYSINITSTACK SYSINITSTACK + 64
  4151                                   %error DOSENTRY discard size NUMBER_DOSENTRY_INIT_DISCARD smaller than NUMBER_SYSINITSTACK
  4152                                  %endif
  4153                                  
  4154                                  
  4155                                  END$:
  4156                                  ; (no prior section) ; CODE	ENDS
  4157                                  	END
  4158                                  
  4159                                  
