     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	1
     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 -]
    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                                   wlcalc word_shr_4?disksector
   275                                   wlcalc word_pass_1_seg_DOSENTRY?disksector
   276 00000004 [0000]                  Init_BootSeg:	dw DiskSector		; seg addr of buffer for reading boot record
   277                                  					; ! must be aligned to paragraph boundary
   278 00000006 00                      FakeFloppyDrv:	db 0			; If 1, then No diskette drives in the system.
   279 00000007 00                      FBIGFAT:	db 0			; FLAGS FOR DRIVE
   280                                  
   281                                  	evenb
   282                                  BDS_diskette_template:
   283 00000008 FFFFFFFF                	dw	-1, -1			;LINK TO NEXT STRUCTURE
   284 0000000C 00                      	DB	0			;INT 13 DRIVE NUMBER
   285 0000000D 00                      	DB	0			;LOGICAL DRIVE LETTER
   286 0000000E 0002                    	DW	512			;PHYSICAL SECTOR SIZE IN BYTES
   287 00000010 FF                      	DB	-1			;SECTORS/ALLOCATION UNIT
   288 00000011 0100                    	DW	1			;RESERVED SECTORS FOR DOS
   289 00000013 02                      	DB	2			;NO. ALLOCATION TABLES
   290 00000014 4000                    	DW	64			;NUMBER DIRECTORY ENTRIES
   291 00000016 6801                    	DW	9*40			;NUMBER SECTORS (AT 512 BYTES EA.)
   292 00000018 00                      	DB	00000000B		;MEDIA DESCRIPTOR, INITIALLY 00H.
   293 00000019 0200                    	DW	2			;NUMBER OF FAT SECTORS
   294 0000001B 0900                    	DW	9			;SECTOR LIMIT
   295 0000001D 0100                    	DW	1			;HEAD LIMIT
   296 0000001F 0000                    	DW	0			;HIDDEN SECTOR COUNT (low word)
   297 00000021 0000                    	dw	0			;J.K. Hidden sector (high)
   298 00000023 0000                    	dw	0			;J.K. Number sectors (low)
   299 00000025 0000                    	dw	0			;J.K. Number sectors (high)
   300 00000027 00                      	DB	0			; TRUE => LARGE FATS
   301 00000028 0000                    	DW	0			;OPEN REF. COUNT
   302                                  
   303 0000002A 03                      	DB	3			;FORM FACTOR
   304 0000002B 2000                    	DW	0020H			;VARIOUS FLAGS
   305                                  ;	DB	9 DUP (0)		;RESERVED FOR FUTURE USE
   306 0000002D 2800                    	DW	40			; NUMBER OF CYLINDERS
   307                                  ; RECOMMENDED BPB FOR DRIVE.
   308 0000002F 0002                    	DW	512			;BYTES PER SECTOR
   309 00000031 01                      	DB	1			;SECTORS/ALLOCATION UNIT
   310 00000032 0100                    	DW	1			;RESERVED SECTORS FOR DOS
   311 00000034 02                      	DB	2			;NO. ALLOCATION TABLES
   312 00000035 E000                    	DW	0E0H			;NUMBER DIRECTORY ENTRIES
   313 00000037 6801                    	DW	9*40			;NUMBER SECTORS (AT 512 BYTES EA.)
   314 00000039 F0                      	DB	0F0H			;MEDIA DESCRIPTOR, INITIALLY F0H.
   315 0000003A 0200                    	DW	2			;NUMBER OF FAT SECTORS
   316 0000003C 0900                    	DW	9			;SECTOR LIMIT
   317 0000003E 0200                    	DW	2			;HEAD LIMIT
   318 00000040 0000                    	DW	0			;HIDDEN SECTOR COUNT(low)
   319 00000042 0000                    	dw	0			;J.K. Hidden sector count (high)
   320 00000044 0000                    	dw	0			;J.K. Number sectors (low)
   321 00000046 0000                    	dw	0			;J.K. Number sectors (high)
   322 00000048 ????????????            	DB	6 DUP (?)
   323 0000004E FF                      	DB	-1			;LAST TRACK ACCESSED ON THIS DRIVE
   324 0000004F FFFF                    	DW	-1			;KEEP THESE TWO CONTIGUOUS (?)
   325 00000051 FFFF                    	DW	-1
   326 00000053 4E4F204E414D452020-     	DB	"NO NAME    ",0         ;VOLUME ID FOR THIS DISK
   326 0000005C 202000             
   327 0000005F 00000000                	dd	0	     ;Current volume serial number from Boot record
   328 00000063 464154313220202000      	db	"FAT12   ",0 ;Current file system id from Boot record
   329                                  
   330                                  	evenb
   331                                  ; THE FOLLOWING TWO BYTES ARE USED TO SAVE THE INFO RETURNED BY INT 13, AH = 8
   332                                  ; CALL TO DETERMINE DRIVE PARAMETERS.
   333 0000006C 0200                    NUM_HEADS dw	2			; NUMBER OF HEADS RETURNED BY ROM
   334 0000006E 09                      SEC_TRK   DB	9			; SEC/TRK RETURNED BY ROM
   335 0000006F 28                      NUM_CYLN  DB	40			; NUMBER OF CYLINDERS RETURNED BY ROM
   336                                  
   337                                  
   338                                  EXT_BOOT_SIG_OFF equ 11+BPB_TYPE_struc_size ;AN000; 3 byte jmp+8 byte OEM +extended bpb
   339                                  
   340                                  
   341                                  	EVENB
   342 00000070 0002000140000000        DISKTABLE DW	512,	0100H,	64,	0
   343 00000078 0008010270000000        	DW	2048,	0201H,	112,	0
   344 00000080 0020020400010000        	DW	8192,	0402H,	256,	0
   345 00000088 A87F030800020000        	DW	32680,	0803H,	512,	0      ;Warning !!! Old values
   346                                  ;	DW	20740,	0803H,	 512,	0	;PTM P892 J.K. 12/3/86 DOS 3.3 will use this.
   347                                  						;J.K.3/16/87 P54 Return back to old value for compatibility.!!!
   348 00000090 FFFF041000040000        	DW	65535,	1004H,	1024,	0
   349                                  
   350                                  ;DISKTABLE2 DW	 32680,  0803H,  512,	 0	;Warning !!! Old values  ;J.K.3/16/87 P54 Return to old value!!!
   351                                  ;DISKTABLE2 DW	 20740,  0803H,  512,	 0	 ;PTM p892 J.K. 12/3/86 DOS 3.3 will use this.
   352                                  ;	 DW	 65535,  0402H,  512,	 FBIG
   353                                  ;AN000;
   354                                  ;DISKTABLE2 dw	 0, 32680, 0803h, 512, 0	 ;table with the assumption of the
   355                                  ;	    dw	2h, 0000h, 0402h, 512, FBIG	 ;total fat size <= 64KB.
   356                                  ;	    dw	4h, 0000h, 0803h, 512, FBIG	 ;-This will cover upto 134 MB
   357                                  ;	    dw	8h, 0000h, 1004h, 512, FBIG	 ;-This will cover upto 268 MB
   358                                  ;	    dw 10h, 0000h, 2005h, 512, FBIG	 ;-This will cover upto 536 MB
   359                                  
   360                                  ;AN004 Default DiskTable under the assumption of Total FAT size <= 128 KB, and
   361                                  ;	the maxium size of FAT entry = 16 Bit.
   362 00000098 0000A87F0308000200-     DiskTable2  dw	 0, 32680, 0803h, 512, 0	;For compatibility.
   362 000000A1 00                 
   363 000000A2 040000000204000240-     	    dw	4h, 0000h, 0402h, 512, FBIG	;Covers upto 134 MB media.
   363 000000AB 00                 
   364 000000AC 080000000308000240-     	    dw	8h, 0000h, 0803h, 512, FBIG	;	upto 268 MB
   364 000000B5 00                 
   365 000000B6 100000000410000240-     	    dw 10h, 0000h, 1004h, 512, FBIG	;	upto 536 MB
   365 000000BF 00                 
   366 000000C0 200000000520000240-     	    dw 20h, 0000h, 2005h, 512, FBIG	;	upto 1072 MB
   366 000000C9 00                 
   367 000000CA 400000000640000240-     	    dw 40h, 0000h, 4006h, 512, FBIG	;	upto 2144 MB
   367 000000D3 00                 
   368 000000D4 800000000780000240-     	    dw 80h, 0000h, 8007h, 512, FBIG	;	upto 4288 MB...
   368 000000DD 00                 
   369                                  
   370                                  	align 2, db 0
   371 000000DE [E000]                  Mini_BPB_ptr	dw	DSKDRVS		;temporary variable used to save the
   372                                  					;Mini Disk BPB pointer address in DskDrvs.
   373 000000E0 0000<rep 20h>           DSKDRVS	times 32 dw 0
   374                                  .end:
   375 00000120 0000                    	dw 0				; allow overflowing entry
   376                                  
   377                                  
   378                                  usesection DOSENTRYINIT
   379                                  
   380 00000001 30312F31302F383400      BIOS_DATE DB	'01/10/84',0     ;This is used for checking AT ROM BIOS date.
   381                                  
   382                                  
   383                                  usesection SYSINITTRAIL
   384                                  
   385                                  ; THE FOLLOWING ARE THE RECOMMENDED BPBS FOR THE MEDIA THAT WE KNOW OF SO
   386                                  ; FAR.
   387                                  
   388                                  ; 48 TPI DISKETTES
   389                                  	EVENB
   390 00000122 0002                    BPB48T	DW	512
   391 00000124 02                      	DB	2
   392 00000125 0100                    	DW	1
   393 00000127 02                      	DB	2
   394 00000128 7000                    	DW	112
   395 0000012A D002                    	DW	2*9*40
   396 0000012C FD                      	DB	0FDH
   397 0000012D 0200                    	DW	2
   398 0000012F 0900                    	DW	9
   399 00000131 0200                    	DW	2
   400 00000133 0000                    	DW	0
   401 00000135 0000                    	dw	0		;AN000;  hidden sector High
   402 00000137 00000000                	dd	0		;AN000;  extended total sectors
   403                                  
   404                                  ; 96TPI DISKETTES
   405 0000013B 00                      	EVENB
   406 0000013C 0002                    BPB96T	DW	512
   407 0000013E 01                      	DB	1
   408 0000013F 0100                    	DW	1
   409 00000141 02                      	DB	2
   410 00000142 E000                    	DW	224
   411 00000144 6009                    	DW	2*15*80
   412 00000146 F9                      	DB	0F9H
   413 00000147 0700                    	DW	7
   414 00000149 0F00                    	DW	15
   415 0000014B 0200                    	DW	2
   416 0000014D 0000                    	DW	0
   417 0000014F 0000                    	dw	0		;AN000;  hidden sector High
   418 00000151 00000000                	dd	0		;AN000;  extended total sectors
   419                                  
   420                                  BPBSIZ	equ	$-BPB96T
   421                                  
   422                                  ; 3 1/2 INCH DISKETTE BPB
   423                                  
   424 00000155 00                      	EVENB
   425 00000156 0002                    BPB35	DW	512
   426 00000158 02                      	DB	2
   427 00000159 0100                    	DW	1			; DOUBLE SIDED WITH 9 SEC/TRK
   428 0000015B 02                      	DB	2
   429 0000015C 7000                    	DW	70h
   430 0000015E A005                    	DW	2*9*80
   431 00000160 F9                      	DB	0F9H
   432 00000161 0300                    	DW	3
   433 00000163 0900                    	DW	9
   434 00000165 0200                    	DW	2
   435 00000167 0000                    	DW	0
   436 00000169 0000                    	dw	0		;AN000;  hidden sector High
   437 0000016B 00000000                	dd	0		;AN000;  extended total sectors
   438                                  
   439 0000016F 00                      	EVENB
   440 00000170 [2201]                  BPBTABLE DW	BPB48T			; 48TPI DRIVES
   441 00000172 [3C01]                  	DW	BPB96T			; 96TPI DRIVES
   442 00000174 [5601]                  	DW	BPB35			; 3.5" DRIVES
   443                                  					;DW	 BPB48T 	     ; NOT USED - 8" DRIVES
   444                                  					;DW	 BPB48T 	     ; NOT USED - 8" DRIVES
   445                                  					;DW	 BPB48T 	     ; NOT USED - HARD FILES
   446                                  					;DW	 BPB48T 	     ; NOT USED - TAPE DRIVES
   447                                  					;DW	 BPB48T 	     ; NOT USED - OTHER
   448                                  
   449                                  	usesection DOSENTRYINIT
   450                                  
   451                                  %if 0
   452                                  	align 2, db 0
   453                                  PATCHTABLE LABEL BYTE
   454                                  	DW	10,MEDIA_PATCH
   455                                  	DW	3,GETBP1_PATCH
   456                                  	DW	3,SET_PATCH
   457                                  	DW	3,DISKIO_PATCH
   458                                  	DW	3,DSKERR_PATCH
   459                                  	DW	3,DSKERR_LBA_PATCH
   460                                  	DW	3,CHANGED_PATCH
   461                                  	DW	3,INIT_PATCH
   462                                  	DW	0
   463                                  %endif
   464                                  
   465                                  	ASSUME	DS:NOTHING,ES:NOTHING
   466                                  
   467                                  		; INP:	from lkernpl
   468                                  		;	cx:di -> lCFG block passed from drkernpl or inicomp
   469                                  		;	dl = load unit
   470                                  		;	ds:bp = ss:bp -> load partition boot sector with (E)BPB
   471                                  	PUBLIC	INIT
   472                                  INIT	PROC	NEAR
   473                                  	MESSAGE FTESTINIT,<"IBMBIO",CR,LF>
   474 0000000A FA                      	CLI
   475                                   assume ds:nothing, es:nothing, ss:nothing
   476                                  
   477                                  		; Get lCFG items to use later.
   478 0000000B 8EC1                    	mov es, cx
   479                                   assume es:nothing
   480 0000000D 268A4514                	mov al, byte [es:di + LCFG_CheckDebugger]
   481 00000011 2EA2[0000]              	mov byte [cs:checkdebugger], al
   482 00000015 26FF7515                	push word [es:di + LCFG_Verbose]
   483 00000019 26FF7516                	push word [es:di + LCFG_ScanMode]
   484 0000001D 26FF751A                	push word [es:di + LCFG_HaltFlag]
   485                                  
   486                                  		; init pointers needed by relocation (i13 etc)
   487 00000021 31C0                    	xor ax, ax
   488 00000023 8ED8                    	mov ds, ax
   489                                   assume ds:IVT
   490 00000025 B8[ssss]                	mov ax, DOSSTART
   491 00000028 A3C600                  	mov word [31h * 4 + 2], ax
   492 0000002B 8ED8                    	mov ds, ax
   493                                   assume ds:DOSGROUP
   494 0000002D C706[0000][ssss]        	mov word [dosdata_to_doscode], DOSCODEGROUP
   495 00000033 8F06[0000]              	pop word [haltflags]
   496 00000037 B8[ssss]                	mov ax, DOSENTRY
   497 0000003A 8ED8                    	mov ds, ax
   498                                   assume ds:DOSENTRYGROUP
   499                                  %if _RELOCATEDOSCODE
   500                                   extern ..@dosentry_doscode_segment
   501 0000003C C706[0000][ssss]        	mov word [..@dosentry_doscode_segment], DOSCODEGROUP
   502                                  %endif
   503                                  
   504                                  
   505                                   extern sysinit_bootdrive_hidden, sysinit_bootdrive_unit
   506                                  
   507                                  init_bootdrive:
   508 00000042 B8[ssss]                	mov ax, SYSINITSEG
   509 00000045 8EC0                    	mov es, ax			; modified to use ax
   510                                  					;  (preserve dl = load unit)
   511                                   assume es:SYSINITGROUP
   512 00000047 268F06[0000]            	pop word [es:load_mode]
   513                                   extern verbose_mode
   514 0000004C 268F06[0000]            	pop word [es:verbose_mode]
   515                                  
   516 00000051 8B461E                  	mov ax, word [bp + bsBPB + bpbHiddenSectors + 2]
   517 00000054 26A3[0200]              	mov word [es:sysinit_bootdrive_hidden + 2], ax
   518 00000058 8B461C                  	mov ax, word [bp + bsBPB + bpbHiddenSectors]
   519 0000005B 26A3[0000]              	mov word [es:sysinit_bootdrive_hidden], ax
   520 0000005F 268816[0000]            	mov byte [es:sysinit_bootdrive_unit], dl
   521                                  
   522                                  
   523                                   extern kernelcommandline
   524                                   extern kernelcommandline.end
   525                                   extern commandnames
   526                                  
   527                                  		; copied from ecm contribution to FreeDOS kernel.asm
   528                                  initialise_command_line_buffer:
   529 00000064 89E0                    	mov ax, sp			; ax = original sp
   530 00000066 16                      	push ss
   531 00000067 1F                      	pop ds
   532                                   assume ds:nothing
   533 00000068 89EE                    	mov si, bp			; ds:si = original ss:bp
   534                                  
   535                                  		; Note that the kernel command line buffer in
   536                                  		;  the init data segment is pre-initialised to
   537                                  		;  hold 0x00 0xFF in the first two bytes. This
   538                                  		;  is used to indicate no command line present,
   539                                  		;  as opposed to an empty command line which
   540                                  		;  will hold 0x00 0x00.
   541                                  		; If any of the branches to .none are taken then
   542                                  		;  the buffer is not modified so it retains the
   543                                  		;  0x00 0xFF contents.
   544 0000006A 81FE1401                	cmp si, - lsvCommandLine.start	; buffer fits below ss:bp ?
   545 0000006E 7222                    	jb .none			; no -->
   546 00000070 817CEC434C              	cmp word [si + lsvCommandLine.signature], lsvclSignature
   547                                  					; signature passed to us ?
   548 00000075 751B                    	jne .none			; no -->
   549 00000077 8DB4ECFE                	lea si, [si + lsvCommandLine.start]
   550                                  					; -> command line buffer
   551 0000007B 39F0                    	cmp ax, si			; stack top starts below-or-equal buffer ?
   552 0000007D 7713                    	ja .none			; no -->
   553 0000007F BF[0000]                	mov di, kernelcommandline	; our buffer
   554 00000082 B9FF00                  	mov cx, lsvclBufferLength - 1
   555 00000085 31C0                    	xor ax, ax
   556 00000087 57                      	push di
   557 00000088 F3A4                    	rep movsb		; copy up to 255 bytes
   558 0000008A AA                      	stosb			; truncate
   559 0000008B 5F                      	pop di
   560 0000008C B501                    	mov ch, 1		; cx = 256
   561 0000008E F2AE                    	repne scasb		; scan for terminator
   562 00000090 F3AA                    	rep stosb		; clear remainder of buffer
   563                                  				; (make sure we do not have 0x00 0xFF
   564                                  				;  even if the command line given is
   565                                  				;  actually the empty string)
   566                                  .none:
   567                                  
   568                                  
   569                                  init_cmdline_terminators:
   570 00000092 06                      	push es
   571 00000093 1F                      	pop ds
   572                                   assume ds:SYSINITGROUP
   573                                  
   574 00000094 BF[0000]                	mov di, kernelcommandline
   575 00000097 89FE                    	mov si, di
   576 00000099 B90001                  	mov cx, 256
   577 0000009C 31C0                    	xor ax, ax
   578 0000009E F2AE                    	repne scasb
   579 000000A0 4F                      	dec di
   580 000000A1 893E[0000]              	mov word [kernelcommandline.end], di
   581 000000A5 89F7                    	mov di, si		; -> start
   582 000000A7 56                      	push si
   583                                  @@:
   584 000000A8 3B36[0000]              	cmp si, word [kernelcommandline.end]
   585 000000AC 7314                    	jae @F
   586 000000AE AC                      	lodsb			; get text
   587 000000AF AA                      	stosb			; store text
   588 000000B0 3C3B                    	cmp al, ';'		; was semicolon ?
   589 000000B2 75F4                    	jne @B			; no, loop -->
   590 000000B4 803C3B                  	cmp byte [si], ';'	; escaped ?
   591 000000B7 7406                    	je .escapesemicolon	; yes -->
   592 000000B9 C645FF00                	mov byte [di - 1], 0	; no, treat as terminator
   593 000000BD EBE9                    	jmp @B
   594                                  
   595                                  .escapesemicolon:
   596 000000BF 46                      	inc si			; -> past next semicolon
   597 000000C0 EBE6                    	jmp @B
   598                                  
   599                                  @@:
   600 000000C2 A4                      	movsb			; copy the NUL
   601 000000C3 4F                      	dec di			; -> at the NUL
   602 000000C4 893E[0000]              	mov word [kernelcommandline.end], di
   603                                  				; update the end offset (<= before)
   604 000000C8 5E                      	pop si
   605                                  
   606                                  parse_config:
   607                                  .loopcommand:
   608 000000C9 A8                      	db __TEST_IMM8		; skip inc
   609                                  @@:
   610 000000CA 46                      	inc si
   611 000000CB 803C20                  	cmp byte [si], 32
   612 000000CE 74FA                    	je @B
   613 000000D0 803C09                  	cmp byte [si], 9
   614 000000D3 74F5                    	je @B
   615                                  
   616 000000D5 803C00                  	cmp byte [si], 0	; empty ?
   617 000000D8 7503E9A100              	je .donename		; yes -->
   618                                  
   619 000000DD BF[0000]                	mov di, commandnames
   620                                  .loopname:
   621 000000E0 8B05                    	mov ax, [di]
   622 000000E2 40                      	inc ax
   623 000000E3 7435                    	jz .unknownname
   624 000000E5 AF                      	scasw			; skip function pointer field
   625 000000E6 AF                      	scasw			; skip content field
   626 000000E7 56                      	push si
   627 000000E8 50                      	push ax
   628 000000E9 57                      	push di
   629 000000EA 8B3D                    	mov di, [di]
   630                                  .comparename:
   631 000000EC AC                      	lodsb
   632 000000ED 3C00                    	cmp al, 0
   633 000000EF 7423                    	je .next
   634 000000F1 3C61                    	cmp al, 'a'
   635 000000F3 7206                    	jb @F
   636 000000F5 3C7A                    	cmp al, 'z'
   637 000000F7 7702                    	ja @F
   638 000000F9 2C20                    	sub al, 20h
   639                                  @@:
   640 000000FB AE                      	scasb
   641 000000FC 7516                    	jne .next
   642 000000FE 803D00                  	cmp byte [di], 0
   643 00000101 75E9                    	jne .comparename
   644 00000103 AC                      	lodsb
   645 00000104 3C00                    	cmp al, 0
   646 00000106 7458                    	je .found
   647 00000108 3C20                    	cmp al, 32
   648 0000010A 7454                    	je .found
   649 0000010C 3C09                    	cmp al, 9
   650 0000010E 7450                    	je .found
   651 00000110 3C3D                    	cmp al, '='
   652 00000112 744C                    	je .found
   653                                  .next:
   654 00000114 5F                      	pop di
   655 00000115 58                      	pop ax
   656 00000116 5E                      	pop si
   657 00000117 AF                      	scasw			; skip name field
   658 00000118 EBC6                    	jmp .loopname
   659                                  
   660                                  .unknownname:
   661 0000011A 56                      	push si
   662                                  
   663                                  extern unknown_command
   664 0000011B BE[0000]                	mov si, unknown_command
   665 0000011E BB0700                  	mov bx, 7
   666 00000121 A9                      	db __TEST_IMM16		; skip int
   667                                  @@:
   668 00000122 CD10                    	int 10h
   669 00000124 AC                      	lodsb
   670 00000125 B40E                    	mov ah, 0Eh
   671 00000127 84C0                    	test al, al
   672 00000129 75F7                    	jnz @B
   673 0000012B 5E                      	pop si
   674 0000012C 56                      	push si
   675                                  @@:
   676 0000012D AC                      	lodsb
   677 0000012E 3C09                    	cmp al, 9
   678 00000130 74FB                    	je @B
   679 00000132 3C20                    	cmp al, 32
   680 00000134 74F7                    	je @B
   681 00000136 4E                      	dec si
   682 00000137 A9                      	db __TEST_IMM16		; skip int
   683                                  @@:
   684 00000138 CD10                    	int 10h
   685 0000013A AC                      	lodsb
   686 0000013B B40E                    	mov ah, 0Eh
   687 0000013D 84C0                    	test al, al
   688 0000013F 740C                    	jz @F
   689 00000141 3C20                    	cmp al, 32
   690 00000143 7204                    	jb .ctrl
   691 00000145 3C7F                    	cmp al, 127
   692 00000147 72EF                    	jb @B
   693                                  .ctrl:
   694 00000149 B02E                    	mov al, '.'
   695 0000014B EBEB                    	jmp @B
   696                                  @@:
   697 0000014D 5E                      	pop si
   698 0000014E B8220E                  	mov ax, 0E00h + '"'
   699 00000151 CD10                    	int 10h
   700 00000153 B80D0E                  	mov ax, 0E00h + 13
   701 00000156 CD10                    	int 10h
   702 00000158 B80A0E                  	mov ax, 0E00h + 10
   703 0000015B CD10                    	int 10h
   704 0000015D EB1F                    	jmp .donename
   705                                  
   706                                  @@:
   707 0000015F AC                      	lodsb
   708                                  .found:
   709 00000160 3C20                    	cmp al, 32
   710 00000162 74FB                    	je @B
   711 00000164 3C09                    	cmp al, 9
   712 00000166 74F7                    	je @B
   713 00000168 3C3D                    	cmp al, '='
   714 0000016A 7501                    	jne @FF
   715                                  @@:
   716 0000016C AC                      	lodsb
   717                                  @@:
   718 0000016D 3C20                    	cmp al, 32
   719 0000016F 74FB                    	je @BB
   720 00000171 3C09                    	cmp al, 9
   721 00000173 74F7                    	je @BB
   722                                  
   723 00000175 4E                      	dec si			; -> content
   724 00000176 5F                      	pop di
   725 00000177 8975FE                  	mov word [di - 2], si
   726 0000017A 58                      	pop ax
   727                                  		; INP:	si -> past an optional equals sign and blanks
   728                                  		;	di -> -> command name
   729                                  		; CHG:	ax, si, di, cx, bx, dx, bp
   730                                  		; STT:	ds = es => SYSINIT
   731                                  		;	cs => DOSENTRY
   732 0000017B FFD0                    	call ax
   733 0000017D 5E                      	pop si
   734                                  .donename:
   735                                  @@:
   736 0000017E AC                      	lodsb
   737 0000017F 3C00                    	cmp al, 0
   738 00000181 75FB                    	jne @B
   739 00000183 3B36[0000]              	cmp si, word [kernelcommandline.end]
   740 00000187 7703E93DFF              	jbe .loopcommand		; (ZR means an empty command at end)
   741                                  
   742                                  
   743                                  init_orig13:
   744 0000018C 31C0                    	XOR	AX,AX
   745 0000018E 8ED8                    	MOV	DS,AX
   746                                   assume ds:IVT
   747 00000190 B500                    	mov ch, 0
   748                                  
   749                                  ;
   750                                  ; PRESERVE ORIGINAL INT 13 VECTOR
   751                                  ;   WE NEED TO SAVE INT13 IN TWO PLACES IN CASE WE ARE RUNNING ON AN AT.
   752                                  ; ON ATS WE INSTALL THE IBM SUPPLIED ROM_BIOS PATCH DISK.OBJ WHICH HOOKS
   753                                  ; INT13 AHEAD OF ORIG13.  SINCE INT19 MUST UNHOOK INT13 TO POINT TO THE
   754                                  ; ROM INT13 ROUTINE, WE MUST HAVE THAT ROM ADDRESS ALSO STORED AWAY.
   755                                  ;
   756 00000192 A14C00                  	MOV	AX,[13H*4]
   757 00000195 2EA3[0000]              	MOV	WORD PTR [cs:ORIG13],AX
   758 00000199 A14E00                  	MOV	AX,[13H*4+2]
   759 0000019C 2EA3[0200]              	MOV	WORD PTR [cs:ORIG13+2],AX
   760                                  
   761                                  init_irt:
   762                                   extern InterruptRestorationTable
   763 000001A0 0E                      	push cs
   764 000001A1 07                      	pop es			; => IRT
   765                                   assume es:DOSENTRYGROUP
   766 000001A2 FC                      	cld
   767 000001A3 BE[0000]                	mov si, InterruptRestorationTable	; access with es
   768                                  .:
   769 000001A6 31C0                    	xor ax, ax
   770 000001A8 26AC                    	es lodsb
   771 000001AA 3CFF                    	cmp al, -1
   772 000001AC 740D                    	je .done
   773 000001AE 97                      	xchg di, ax		; di = interrupt number
   774 000001AF 01FF                    	add di, di
   775 000001B1 01FF                    	add di, di		; ds:di -> interrupt vector
   776 000001B3 87F7                    	xchg si, di		; es:di -> IRT, ds:si -> vector
   777 000001B5 A5                      	movsw
   778 000001B6 A5                      	movsw
   779 000001B7 87F7                    	xchg si, di
   780 000001B9 EBEB                    	jmp .
   781                                  .done:
   782                                  
   783                                  ;
   784                                  ; SET UP INT 13 FOR NEW ACTION
   785                                  ;
   786                                  extern msdisk_i13
   787 000001BB C7064C00[0000]          	MOV	WORD PTR [13H*4],OFFSET msdisk_i13
   788 000001C1 8C0E4E00                	MOV	[13H*4+2],CS
   789                                  
   790                                  ;
   791                                  ; SET UP INT 19 FOR NEW ACTION
   792                                  ;
   793                                  extern i19
   794 000001C5 C7066400[0000]          	MOV	WORD PTR [19H*4],OFFSET i19
   795 000001CB 8C0E6600                	MOV	[19H*4+2],CS
   796 000001CF FB                      	STI
   797 000001D0 CD11                    	INT	11H			;GET EQUIPMENT STATUS
   798                                  ;J.K.6/24/87 We have to support a system that does not have any diskette
   799                                  ;drives but only hardfiles.  This system will IPL from the hardfile.
   800                                  ;If the equipment flag bit 0 is 1, then the system has diskette drive(s).
   801                                  ;Otherwise, the system only have hardfiles.
   802                                  ;Important thing is that still, for compatibility reason, the drive letter
   803                                  ;for the hardfile start from "C".  So, we still need to allocate dummy BDS
   804                                  ;drive A and driver B.	In SYSINIT time, we are going to set CDS table entry
   805                                  ;of DPB pointer for these drives to 0, so any user attempt to access this
   806                                  ;drives will get "Invalid drive letter ..." message.  We are going to
   807                                  ;establish "FAKEFLOPPYDRV" flag.  ***SYSINIT module should call INT 11h to check
   808                                  ;if there are any diskette drivers in the system or not.!!!***
   809                                  
   810                                  ;SB34INIT001**************************************************************
   811                                  ;SB	check the register returned by the equipment determination interrupt
   812                                  ;SB	we have to handle the case of no diskettes in the system by faking
   813                                  ;SB	two dummy drives.
   814                                  ;SB	if the register indicates that we do have floppy drives we don't need
   815                                  ;SB	to do anything special.
   816                                  ;SB	if the register indicates that we don't have any floppy drives then
   817                                  ;SB	what we need to do is set the FakeFloppyDrv variable, change the 
   818                                  ;SB	register to say that we do have floppy drives and then go to execute
   819                                  ;SB	the code which starts at NOTSINGLE.  This is because we can skip the
   820                                  ;SB	code given below which tries to find if there are one or two drives
   821                                  ;SB	since we already know about this.  6 LOCS
   822                                  
   823 000001D2 A801                    	test	al, 1
   824 000001D4 750C                    	jnz	DO_FLOPPY
   825 000001D6 B8[ssss]                	mov	ax, SYSINITSEG
   826 000001D9 8ED8                    	mov	ds, ax
   827                                   assume ds:SYSINITGROUP
   828 000001DB B001                    	mov	al, 1			; set to indicate 2 floppies 
   829 000001DD A2[0600]                	mov	[FakeFloppyDrv], al	; fake floppy
   830 000001E0 EB10                    	jmp	short NOTSINGLE
   831                                  
   832                                  DO_FLOPPY:
   833                                  
   834                                  ;SB34INIT001**************************************************************
   835                                     ;
   836                                     ; Determine if there are one or two diskette drives in system
   837                                     ;
   838 000001E2 D0C0                    	ROL	AL,1			;PUT BITS 6 & 7 INTO BITS 0 & 1
   839 000001E4 D0C0                    	ROL	AL,1
   840 000001E6 2403                    	AND	al, 3			;ONLY LOOK AT BITS 0 & 1
   841 000001E8 7508                    	JNZ	NOTSINGLE		;ZERO MEANS SINGLE DRIVE SYSTEM
   842 000001EA 40                      	INC	AX			;PRETEND IT'S A TWO DRIVE SYSTEM
   843 000001EB E80A05                  	call dosentry_init_get_ds_dosbiodata
   844                                   assume ds:DOSGROUP
   845 000001EE FE06[0000]              	INC	byte [SINGLE]		;REMEMBER THIS
   846                                  NOTSINGLE:
   847 000001F2 0E                      	push cs
   848 000001F3 1F                      	pop ds
   849                                   assume ds:DOSENTRYGROUP
   850                                  
   851 000001F4 40                      	INC	AX			;AX HAS NUMBER OF DRIVES, 2-4
   852                                  					;IS ALSO 0 INDEXED BOOT DRIVE IF WE
   853                                  					;  BOOTED OFF HARD FILE
   854 000001F5 88C1                    	MOV	CL,AL			;CH IS FAT ID, CL # FLOPPIES
   855 000001F7 F6C280                  	TEST	DL,80H			;BOOT FROM FLOPPY ?
   856 000001FA 7502                    	JNZ	GOTHRD			;NO.
   857 000001FC 31C0                    	XOR	AX,AX			;INDICATE BOOT FROM DRIVE A
   858                                  GOTHRD:
   859                                  ;
   860                                  ;   AX = 0-BASED DRIVE WE BOOTED FROM
   861                                  ;   CL = NUMBER OF FLOPPIES INCLUDING FAKE ONE
   862                                  ;   CH = MEDIA BYTE
   863                                  ;
   864                                  	MESSAGE FTESTINIT,<"INIT",CR,LF>
   865 000001FE 31D2                    	XOR	DX,DX
   866                                  
   867 00000200 51                      	PUSH	CX			;SAVE NUMBER OF FLOPPIES AND MEDIA BYTE
   868 00000201 88EC                    	MOV	AH,CH			;SAVE FAT ID TO AH
   869 00000203 50                      	PUSH	AX			;SAVE BOOT DRIVE NUMBER, AND MEDIA BYTE
   870                                  ;J.K. Let Model_byte, Secondary_Model_Byte be set here!!!
   871                                  ;SB33020******************************************************************
   872 00000204 F9                      	stc
   873 00000205 B4C0                    	mov	ah,0c0h 		; return system environment    ;SB;3.30
   874 00000207 CD15                    	int	15h			; call ROM-Bios routine        ;SB;3.30
   875                                  ;SB33020******************************************************************
   876 00000209 E8EC04                  	call dosentry_init_get_ds_dosbiodata
   877                                   assume ds:DOSGROUP
   878 0000020C 7214                    	jc	No_Rom_System_Conf	; just use Model_Byte
   879 0000020E 84E4                    	test	ah, ah			; double check
   880 00000210 7510                    	jnz	No_Rom_System_Conf
   881 00000212 268A4702                	mov	al, [ES:BX + bios_SD_modelbyte] ;get the model byte
   882 00000216 A2[0000]                	mov	[Model_Byte], al
   883 00000219 268A4703                	mov	al, [ES:BX + bios_SD_scnd_modelbyte] ;secondary model byte
   884 0000021D A2[0000]                	mov	[Secondary_Model_Byte], al
   885 00000220 EB0C                    	jmp	short Turn_Timer_On
   886                                  No_Rom_System_Conf:
   887 00000222 BEFFFF                  	MOV	SI,0FFFFH		;MJB001
   888 00000225 8EC6                    	MOV	ES,SI			;MJB001
   889                                   assume es:nothing
   890 00000227 26A00E00                	MOV	AL,[ES:0EH]		; GET MODEL BYTE ARR 2.41
   891                                  MODEL_BYTE equ Model_Byte	; NASM port label
   892 0000022B A2[0000]                	MOV	[MODEL_BYTE],AL	      ; SAVE MODEL BYTE ARR 2.41
   893                                  Turn_Timer_On:
   894 0000022E B020                    	MOV	AL,EOI
   895 00000230 E620                    	OUT	AKPORT,AL		;TURN ON THE TIMER
   896                                  
   897                                  ;     NOP out the double word MOV instruction in MSDISK, if
   898                                  ;     this is not a 386 machine...
   899                                  	Get_CPU_Type			; macro to determine cpu type
    10 00000232 9C                  <1>  pushf
    11 00000233 53                  <1>  push bx
    12 00000234 31DB                <1>  xor bx, bx
    13                              <1> 
    14 00000236 31C0                <1>  xor ax,ax
    15 00000238 50                  <1>  push ax
    16 00000239 9D                  <1>  popf
    17 0000023A 9C                  <1>  pushf
    18 0000023B 58                  <1>  pop ax
    19 0000023C 2500F0              <1>  and ax,0F000h
    20 0000023F 3D00F0              <1>  cmp ax,0F000h
    21 00000242 740E                <1>  je %%cpu_8086
    22                              <1> 
    23 00000244 B800F0              <1>  mov ax,0F000h
    24 00000247 50                  <1>  push ax
    25 00000248 9D                  <1>  popf
    26 00000249 9C                  <1>  pushf
    27 0000024A 58                  <1>  pop ax
    28 0000024B 2500F0              <1>  and ax,0F000h
    29 0000024E 7401                <1>  jz %%cpu_286
    30                              <1> 
    31                              <1> %%cpu_386:
    32 00000250 43                  <1>  inc bx
    33                              <1> %%cpu_286:
    34 00000251 43                  <1>  inc bx
    35                              <1> %%cpu_8086:
    36 00000252 89D8                <1>  mov ax, bx
    37 00000254 5B                  <1>  pop bx
    38 00000255 9D                  <1>  popf
   900 00000256 3C02                    	cmp	al, 2			; is it a 386?
   901 00000258 7504                    	jne	Skip_Patch_DoubleWordMov; no: skip the patch
   902                                  
   903                                  Patch_DoubleWordMov:
   904                                   extern dosbiodata_have_386
   905 0000025A F616[0000]              	not byte [dosbiodata_have_386]	; = 0FFh
   906                                  Skip_Patch_DoubleWordMov:
   907                                  	MESSAGE FTESTINIT,<"COM DEVICES",CR,LF>
   908                                  ;SB33IN1*********************************************************
   909                                  
   910 0000025E BE[0000]                	mov	si,offset COM4DEV 
   911 00000261 E8C004                  	call	AUX_INIT
   912 00000264 BE[0000]                	mov	si,offset COM3DEV
   913 00000267 E8BA04                  	call	AUX_INIT
   914                                  ;SB33IN1*********************************************************
   915 0000026A BE[0000]                	MOV	SI,OFFSET COM2DEV
   916 0000026D E8B404                  	CALL	AUX_INIT		;INIT COM2
   917 00000270 BE[0000]                	MOV	SI,OFFSET COM1DEV
   918 00000273 E8AE04                  	CALL	AUX_INIT		;INIT COM1
   919                                  
   920                                  	MESSAGE FTESTINIT,<"LPT DEVICES",CR,LF>
   921 00000276 BE[0000]                	MOV	SI,OFFSET LPT3DEV
   922 00000279 E8A004                  	CALL	PRINT_INIT		;INIT LPT3
   923 0000027C BE[0000]                	MOV	SI,OFFSET LPT2DEV
   924 0000027F E89A04                  	CALL	PRINT_INIT		;INIT LPT2
   925 00000282 BE[0000]                	MOV	SI,OFFSET LPT1DEV
   926 00000285 E89404                  	CALL	PRINT_INIT		;INIT LPT1
   927                                  
   928 00000288 31D2                    	XOR	DX,DX
   929 0000028A 8EDA                    	MOV	DS,DX			;TO INITIALIZE PRINT SCREEN VECTOR
   930 0000028C 8EC2                    	MOV	ES,DX
   931                                   assume ds:IVT, es:IVT
   932                                  
   933 0000028E 31C0                    	XOR	AX,AX
   934 00000290 BF3405                  	MOV	DI,INITSPOT
   935 00000293 AB                      	STOSW				;INIT FOUR BYTES TO 0
   936 00000294 AB                      	STOSW
   937                                  
   938 00000295 8CC8                    	MOV	AX,CS			;FETCH SEGMENT
   939                                  
   940                                  extern i1B
   941 00000297 C7066C00[0000]          	MOV	WORD [BRKADR], i1B	;BREAK ENTRY POINT
   942 0000029D A36E00                  	MOV	[BRKADR+2],AX		;VECTOR FOR BREAK
   943                                  
   944                                  ;*********************************************** ARR 2.15
   945                                  ; SINCE WE'RE FIRST IN SYSTEM, NO NEED TO CHAIN THIS.
   946                                  ;	CLI				; ARR 2.15 DON'T GET BLOWN
   947                                  ;	MOV	DS:WORD PTR TIMADR,OFFSET TIMER ; ARR 2.15 TIMER ENTRY POINT
   948                                  ;	MOV	DS:TIMADR+2,AX		; ARR 2.15 VECTOR FOR TIMER
   949                                  ;	STI
   950                                  ;*********************************************** ARR 2.15
   951                                  
   952                                  ; BAS DEBUG
   953                                  extern i29
   954 000002A0 C706A400[0000]          	MOV	WORD [CHROUT*4], i29
   955 000002A6 A3A600                  	MOV	WORD PTR [CHROUT*4+2],AX
   956                                  
   957                                  extern entry_iret
   958                                  	MESSAGE FTESTINIT,<"INTERRUPT VECTORS",CR,LF>
   959 000002A9 BB[0000]                	MOV	BX, entry_iret		;WILL INITIALIZE REST OF INTERRUPTS
   960                                  
   961 000002AC BF1000                  	mov di, 4 * 4
   962                                  
   963 000002AF 50                      	push ax				; preserve segment
   964 000002B0 53                      	push bx				; preserve offset
   965                                  debugger_check:
   966 000002B1 2EA0[0000]              	mov al, byte [cs:checkdebugger]
   967 000002B5 A804                    	test al, LCFG_DBG_ONLY_VALID
   968 000002B7 740E                    	jz @F
   969                                  		; ds => IVT
   970 000002B9 833E0C00FF              	cmp word [3 * 4], -1
   971 000002BE 7420                    	je .nocheck
   972 000002C0 833E0E0000              	cmp word [3 * 4 + 2], 0
   973 000002C5 7419                    	je .nocheck
   974                                  @@:
   975 000002C7 A808                    	test al, LCFG_DBG_ONLY_IISP
   976 000002C9 7411                    	jz @F
   977                                  		; ds => IVT
   978 000002CB C41E0C00                	les bx, [3 * 4]			; es:bx -> int 3 handler
   979                                   assume es:nothing
   980 000002CF 83FBEE                  	cmp bx, -18			; valid ? (could tear word access ?)
   981 000002D2 770C                    	ja .nocheck			; no, cannot be a valid IISP header -->
   982 000002D4 26817F064B42            	cmp word [es:bx + 6], "KB"	; signature present ?
   983 000002DA 7504                    	jne .nocheck			; no -->
   984                                  @@:
   985 000002DC A801                    	test al, LCFG_DBG_CHECK
   986 000002DE 7508                    	jnz .check
   987                                  .nocheck:
   988 000002E0 2EC606[EF02]90          	mov byte [cs:.patch], 90h	; do not check
   989 000002E6 EB00                    	jmp @F				; (flush queue for the SMC)
   990                                  @@:
   991                                  .check:
   992 000002E8 1E                      	push ds
   993 000002E9 07                      	pop es
   994                                   assume es:IVT
   995 000002EA A802                    	test al, LCFG_DBG_ASSUME	; (NC)
   996 000002EC 7401                    	jz .runint3			; if to assume off --> (NC)
   997 000002EE F9                      	stc				; assume on (CY)
   998                                  .runint3:
   999 000002EF CC                      .patch:	int3				; SMC: patched to NOP if not to run int3
  1000 000002F0 7211                    	jc debugger_detected
  1001                                  
  1002                                  debugger_disabled:
  1003 000002F2 BF0400                  	mov di, 4 * 1
  1004 000002F5 5B                      	pop bx
  1005 000002F6 58                      	pop ax				; = segment
  1006                                  
  1007 000002F7 93                      	XCHG	AX,BX
  1008 000002F8 AB                      	STOSW				;LOCATION 4
  1009 000002F9 93                      	XCHG	AX,BX
  1010 000002FA AB                      	STOSW				;INT 1		;LOCATION 6
  1011 000002FB 83C704                  	ADD	DI,4
  1012 000002FE 93                      	XCHG	AX,BX
  1013 000002FF AB                      	STOSW				;LOCATION 12
  1014 00000300 93                      	XCHG	AX,BX
  1015 00000301 AB                      	STOSW				;INT 3		;LOCATION 14
  1016                                  
  1017 00000302 A9                      	db 0A9h				; test ax, imm16 (skip pop, pop)
  1018                                  debugger_detected:
  1019 00000303 5B                      	pop bx
  1020 00000304 58                      	pop ax
  1021 00000305 93                      	XCHG	AX,BX
  1022 00000306 AB                      	STOSW				;LOCATION 16
  1023 00000307 93                      	XCHG	AX,BX
  1024 00000308 AB                      	STOSW				;INT 4		;LOCATION 18
  1025                                  
  1026 00000309 89160005                	MOV	WORD PTR [500H],DX	;SET PRINT SCREEN & BREAK =0
  1027 0000030D 89160405                	MOV	WORD PTR [LSTDRV],DX	;CLEAN OUT LAST DRIVE SPEC
  1028                                  
  1029                                  	MESSAGE FTESTINIT,<"DISK PARAMETER TABLE",CR,LF>
  1030                                  
  1031                                  		; lDOS: our sector and initial loader do not relocate
  1032                                  		;	 the DPT so do it here instead. this code used
  1033                                  		;	 to be commented out.
  1034 00000311 C5367800                	lds si, [DSKADR]		; DS:SI -> CURRENT TABLE  ARR 2.41
  1035                                   assume ds:nothing
  1036 00000315 BF2205                  	MOV	DI,SEC9			; ES:DI -> NEW TABLE	  ARR 2.41
  1037 00000318 57                      	push di
  1038 00000319 B90B00                  	MOV	CX,DISK_PARMS_struc_size;			  ARR 2.41
  1039 0000031C F3A4                    	REP	MOVSB			; COPY TABLE		  ARR 2.41
  1040 0000031E 06                      	PUSH	ES			;			  ARR 2.41
  1041 0000031F 1F                      	POP	DS			; DS = 0		  ARR 2.41
  1042                                   assume ds:IVT
  1043                                  
  1044 00000320 8F067800                	pop	WORD PTR [DSKADR]	;			  ARR 2.41
  1045 00000324 8C1E7A00                	MOV	WORD PTR [DSKADR+2],DS	; POINT DISK PARM VECTOR TO NEW TABLE
  1046                                  					;			  ARR 2.41
  1047                                  ;SB34INIT002******************************************************************
  1048                                  ;SB	We need to initalise the cs:MotorStartup variable from the disk 
  1049                                  ;SB	parameter table at SEC9.  The offsets in this table are defined in
  1050                                  ;SB	the DISK_PARMS struc in MSDSKPRM.INC.  2 LOCS
  1051                                  
  1052 00000328 A02C05                  	mov	al,[SEC9 + DISK_MOTOR_STRT]
  1053 0000032B E8D203                  	call dosentry_init_get_es_dosbiodata
  1054                                   assume es:DOSGROUP
  1055                                  MotorStartup equ MOTORSTARTUP	; NASM port label
  1056 0000032E 26A2[0000]              	mov	[es:MotorStartup],al
  1057                                  ;SB34INIT002******************************************************************
  1058 00000332 26803E[0000]FD          	CMP	byte [es:MODEL_BYTE],0FDH       ; IS THIS AN OLD ROM?	ARR 2.41
  1059 00000338 720B                    	JB	NO_DIDDLE		; NO			  ARR 2.41
  1060 0000033A C7062B050F02            	MOV	WORD [(SEC9 + DISK_HEAD_STTL)],0200H+NORMSETTLE
  1061                                  					; SET HEAD SETTLE AND MOTOR START
  1062                                  					; ON PC-1 PC-2 PC-XT HAL0 ARR 2.41
  1063 00000340 C6062205DF              	MOV	byte [(SEC9 + DISK_SPECIFY_1)],0DFH
  1064                                  					; SET 1ST SPECIFY BYTE
  1065                                  					; ON PC-1 PC-2 PC-XT HAL0 ARR 2.41
  1066                                  NO_DIDDLE:				;			  ARR 2.41
  1067 00000345 CD12                    	INT	12H			;GET MEMORY SIZE--1K BLOCKS IN AX
  1068 00000347 B106                    	MOV	CL,6
  1069 00000349 D3E0                    	SHL	AX,CL			;CONVERT TO 16-BYTE BLOCKS(SEGMENT NO.)
  1070 0000034B 59                      	POP	CX			; RETREIVE BOOT DRIVE NUMBER, AND FAT ID
  1071                                  		; cl = boot drive, 0 = A:
  1072 0000034C BA[ssss]                	MOV	DX,SYSINITSEG
  1073 0000034F 8EDA                    	MOV	DS,DX
  1074                                  
  1075                                  	ASSUME	DS:SYSINITGROUP
  1076                                  
  1077 00000351 A3[0000]                	MOV	[MEMORY_SIZE],AX
  1078 00000354 41                      	INC	cx
  1079 00000355 880E[0000]              	MOV	[DEFAULT_DRIVE],CL	;SAVE DEFAULT DRIVE SPEC
  1080                                  
  1081 00000359 31C9                    	xor	cx,cx
  1082                                  
  1083                                  ; IMPORTANT: SOME OLD IBM HARDWARE GENERATES SPURIOUS INT F'S DUE TO BOGUS
  1084                                  ; PRINTER CARDS.  WE INITIALIZE THIS VALUE TO POINT TO AN IRET ONLY IF
  1085                                  
  1086                                  ; 1) THE ORIGINAL SEGMENT POINTS TO STORAGE INSIDE VALID RAM.
  1087                                  
  1088                                  ; 2) THE ORIGINAL SEGMENT IS 0F000:XXXX
  1089                                  
  1090                                  ; THESES ARE CAPRICIOUS REQUESTS FROM OUR OEM FOR REASONS BEHIND THEM, READ
  1091                                  ; THE DCR'S FOR THE IBM DOS 3.2 PROJECT.
  1092                                  
  1093 0000035B 8EC1                    	MOV	es,cx			; cx := SEGMENT FOR INT 15
  1094                                   assume es:IVT
  1095 0000035D 26A13E00                	MOV	AX,WORD PTR [es:(0FH*4+2)]
  1096                                  
  1097 00000361 3B06[0000]              	CMP	AX,[MEMORY_SIZE]	; CONDITION 1
  1098 00000365 7605                    	Jbe	RESETINTF
  1099                                  
  1100 00000367 3D00F0                  	CMP	AX,0F000H		; CONDITION 2
  1101 0000036A 750C                    	JNE	KEEPINTF
  1102                                  
  1103                                  RESETINTF:
  1104 0000036C 26C7063C00[0000]        	MOV	WORD PTR [es:0FH*4], entry_iret
  1105 00000373 268C0E3E00              	MOV	WORD PTR [es:0FH*4+2],CS
  1106                                  KEEPINTF:
  1107                                  
  1108                                  ; END IMPORTANT
  1109                                  
  1110                                  ;SB34INIT003****************************************************************
  1111                                  ;SB We will check if the system has IBM extended key board by
  1112                                  ;SB looking at a byte at 40:96.  If bit 4 is set, then extended key board
  1113                                  ;SB is installed, and we are going to set KEYRD_Func to 10h, KEYSTS_Func to 11h
  1114                                  ;SB for the extended keyboard function. Use cx as the temporary register. 8 LOCS
  1115                                  
  1116 00000378 26F606960410            	test byte [es:0496h], 0001_0000b	; get keyboard flag
  1117                                  
  1118 0000037E E87703                  	call dosentry_init_get_ds_dosbiodata
  1119                                   assume ds:DOSGROUP
  1120 00000381 1E                      	PUSH	ds
  1121 00000382 07                      	POP	ES
  1122                                   assume es:DOSGROUP
  1123                                  
  1124 00000383 7406                    	jz	ORG_KEY				; orginal keyboard
  1125                                  KEYRD_func equ KEYRD_Func	; NASM port label
  1126                                  KEYSTS_func equ KEYSTS_Func	; NASM port label
  1127 00000385 C706[0000]1011          	mov	word [KEYRD_func], 11_10h	; change for extended keyboard functions
  1128                                  		; KEYSTS_Func is directly behind KEYRD_Func
  1129                                  ORG_KEY:
  1130                                  
  1131                                  ;SB34INIT003****************************************************************
  1132                                  
  1133                                  ;**************************************************************
  1134                                  ;	WILL INITIALIZE THE NUMBER OF DRIVES
  1135                                  ;	AFTER THE EQUIPMENT CALL (INT 11H) BITS 6&7 WILL TELL
  1136                                  ;	THE INDICATIONS ARE AS FOLLOWS:
  1137                                  ;
  1138                                  ;	BITS	7	6	DRIVES
  1139                                  ;		0	0	1
  1140                                  ;		0	1	2
  1141                                  ;		1	0	3
  1142                                  ;		1	1	4
  1143                                  ;**************************************************************
  1144                                  
  1145 0000038B E8AA03                  	call	CMOS_Clock_Read     ;Before doing anythig else if CMOS clock exists,
  1146                                  				    ;then set the system time according to that.
  1147                                  				    ;Also, reset the cmos clock rate.
  1148                                  
  1149                                  	MESSAGE FTESTINIT,<"DISK DEVICES",CR,LF>
  1150                                  
  1151 0000038E 58                      	POP	AX			;NUMBER OF FLOPPIES AND FAT ID
  1152 0000038F 30E4                    	XOR	AH,AH			; CHUCK FAT ID BYTE
  1153 00000391 2EA2[0000]              	MOV	[cs:DRVMAX],AL	      ;AND SET INITIAL NUMBER OF DRIVES
  1154                                  	MESSAGE FTESTINIT,<"BEFORE INT 13",CR,LF>
  1155                                  
  1156                                  determine_fhave96:
  1157 00000395 BA[ssss]                	mov dx, SYSINITSEG
  1158 00000398 8EDA                    	mov ds, dx
  1159                                   assume ds:SYSINITGROUP
  1160 0000039A 31D2                    	xor dx, dx			; dl = unit 0
  1161 0000039C 803E[0600]01            	cmp byte [FakeFloppyDrv],1
  1162 000003A1 0E                      	push cs
  1163 000003A2 1F                      	pop ds
  1164                                   assume ds:DOSENTRYGROUP
  1165 000003A3 741D                    	je .none
  1166                                  
  1167                                  .LOOP_DRIVE:
  1168 000003A5 3A16[0000]              	CMP	DL,[DRVMAX]
  1169 000003A9 7317                    	jae	.done
  1170                                  
  1171                                  ; CHECK FOR CHANGELINE SUPPORT ON DRIVE
  1172                                  ;SB33023********************************************************************
  1173 000003AB B415                    	mov	AH, 15h      ;SB	; set command to get DASD type
  1174 000003AD F9                      	stc
  1175 000003AE CD13                    	int	13h	     ;SB	; call ROM-BIOS
  1176                                  ;SB33023********************************************************************
  1177 000003B0 7205                    	JC	.NEXTDRIVE
  1178 000003B2 80FC02                  	CMP	AH,02			; CHECK FOR PRESENCE OF CHANGELINE
  1179 000003B5 7403                    	je .have96
  1180                                  
  1181                                  .NEXTDRIVE:
  1182 000003B7 42                      	INC	dx
  1183 000003B8 EBEB                    	JMP	.LOOP_DRIVE
  1184                                  
  1185                                  ; WE HAVE A DRIVE WITH CHANGE LINE SUPPORT.
  1186                                  ; shortcut to the end of the loop, ignoring any additional units
  1187                                  ;  that may also have change line support.
  1188                                  .have96:
  1189 000003BA E83B03                  	call dosentry_init_get_ds_dosbiodata
  1190                                   assume ds:DOSGROUP
  1191 000003BD C606[0000]01            	mov byte [FHAVE96], 1		; REMEMBER THAT WE HAVE 96TPI DISKS
  1192                                  
  1193                                  .DONE_DRIVES:
  1194                                  .done:
  1195                                  .none:
  1196                                  	; proceeds to STATIC_CONFIGURE
  1197                                  
  1198                                  
  1199                                  usesection SYSINITTRAIL
  1200                                  
  1201                                  alloc_upb:
  1202                                   assume ds:nothing, es:nothing, ss:nothing
  1203 00000176 50                      	push ax
  1204 00000177 53                      	push bx
  1205 00000178 51                      	push cx
  1206 00000179 2EC43E[0000]            	les di, [cs:nextupb]
  1207 0000017E 8CC0                    	mov ax, es
  1208 00000180 85C0                    	test ax, ax
  1209 00000182 741F                    	jz .alloc
  1210 00000184 83C764                  	add di, BDSM_type_struc_size
  1211 00000187 2E893E[0000]            	mov word [cs:nextupb], di	; -> next UPB
  1212 0000018C B104                    	mov cl, 4
  1213 0000018E 8D5D73                  	lea bx, [di + BDSM_type_struc_size + 15]
  1214                                  					; -> behind next UPB, round up
  1215 00000191 2E3B1E[0000]            	cmp bx, word [cs:nextupb]
  1216 00000196 7208                    	jb mem_err_j
  1217 00000198 D3EB                    	shr bx, cl			; to paragraphs
  1218 0000019A B44A                    	mov ah, 4Ah
  1219 0000019C CD21                    	int 21h				; resize
  1220 0000019E 7312                    	jnc @F
  1221                                  mem_err_j: equ $
  1222                                   extern MEM_ERR
  1223 000001A0 E9(0000)                	jmp MEM_ERR
  1224                                  
  1225                                  .alloc:
  1226 000001A3 B448                    	mov ah, 48h
  1227 000001A5 BB0700                  	mov bx, paras(BDSM_type_struc_size)
  1228 000001A8 CD21                    	int 21h
  1229 000001AA 72F4                    	jc mem_err_j
  1230 000001AC 8EC0                    	mov es, ax
  1231                                   assume es:nothing
  1232 000001AE 2EA3[0200]              	mov word [cs:nextupb + 2], ax
  1233                                  @@:
  1234 000001B2 59                      	pop cx
  1235 000001B3 5B                      	pop bx
  1236 000001B4 58                      	pop ax
  1237 000001B5 C3                      	retn
  1238                                  
  1239                                  
  1240                                  	global INITUPB
  1241                                  INITUPB:
  1242                                  
  1243                                  ;SB33021********************************************************************
  1244 000001B6 B280                    	mov	DL, 80h     ;SB 	; tell rom bios to look at hard drives
  1245 000001B8 B408                    	mov	AH, 8h	    ;SB 	; set command to get drive parameter
  1246 000001BA F9                      	stc
  1247 000001BB CD13                    	int	13h	    ;SB 	; call ROM-BIOS to get number of drives
  1248                                  
  1249                                  	assume es:nothing
  1250                                  ;SB33021********************************************************************
  1251 000001BD 7205                    	JC	ENDDRV			;CARRY INDICATES OLD ROM, SO NO HARDFILE
  1252 000001BF 2E8816[0000]            	MOV	[cs:HNUM],DL
  1253                                  ENDDRV:
  1254                                  	MESSAGE FTESTINIT,<"SETTING UP BDSS",CR,LF>
  1255                                  
  1256                                  ;
  1257                                  ; SCAN THE LIST OF DRIVES TO DETERMINE THEIR TYPE.  WE HAVE THREE FLAVORS OF
  1258                                  ; DISKETTE DRIVES:
  1259                                  ;
  1260                                  ;   48TPI DRIVES    WE DO NOTHING SPECIAL FOR THEM
  1261                                  ;   96TPI DRIVES    MARK THE FACT THAT THEY HAVE CHANGELINE SUPPORT.
  1262                                  ;   3 1/4 DRIVES    MARK CHANGELINE SUPPORT AND SMALL.
  1263                                  ;
  1264                                  ; THE FOLLOWING CODE USES REGISTERS FOR CERTAIN VALUES:
  1265                                  ;   DL - PHYSICAL DRIVE
  1266                                  ;   DS:DI - POINTS TO CURRENT BDS
  1267                                  ;   CX - FLAG BITS FOR BDS
  1268                                  ;   DH - FORM FACTOR FOR THE DRIVE (1 - 48TPI, 2 - 96TPI, 3 - 3.5" MEDIUM)
  1269                                  ;
  1270 000001C4 30D2                    	XOR	DL,DL			; START OUT WITH DRIVE 0.
  1271                                  
  1272 000001C6 E8D207                  	call sysinit_get_ds_dosbiodata
  1273                                   assume ds:DOSGROUP
  1274 000001C9 C606[0000]09            	MOV	byte [EOT],9
  1275                                  ;J.K.6/24/87 Check if the system has no physical diskette drives.
  1276                                  ;J.K. If it is, then we don't have to set BDS tables.  But since we
  1277                                  ;J.K. pretend that we have 2 floppies, we are going to reserve two
  1278                                  ;J.K. BDS tables for the fake drive A, and B. and set the end of link
  1279                                  ;J.K. pointer.
  1280                                  
  1281                                  ;SB34INIT004*********************************************************
  1282                                  ;SB	Check to see if we are faking floppy drives.  If not we don't 
  1283                                  ;SB	do anything special.  If we are faking floppy drives we need
  1284                                  ;SB	to set aside two BDSs for the two fake floppy drives.  We 
  1285                                  ;SB	don't need to initalise any fields though. So starting at START_BDS
  1286                                  ;SB	use the link field in the BDS structure to go to the second BDS
  1287                                  ;SB	in the list and initalise it's link field to -1 to set the end of
  1288                                  ;SB	the list.  Then jump to the routine at DoHard to allocate/initialise
  1289                                  ;SB     the BDS for HardDrives.
  1290                                  
  1291 000001CE 2E803E[0600]01          	cmp	byte [cs:FakeFloppyDrv],1
  1292 000001D4 7533                    	jnz	LOOP_DRIVE		; system has floppy
  1293                                  link equ LINK	; NASM port equate
  1294 000001D6 E89DFF                  	call alloc_upb
  1295 000001D9 0E                      	push cs
  1296 000001DA 1F                      	pop ds
  1297                                   assume ds:SYSINITGROUP
  1298 000001DB BE[0800]                	mov si, BDS_diskette_template	; access with ds
  1299 000001DE B96400                  	mov cx, BDS_TYPE_struc_size
  1300 000001E1 57                      	push di
  1301 000001E2 F3A4                    	rep movsb
  1302 000001E4 06                      	push es
  1303 000001E5 1F                      	pop ds
  1304                                   assume ds:nothing, es:nothing
  1305 000001E6 5F                      	pop di
  1306 000001E7 C6450500                	mov byte [di + DRIVELET], 0
  1307 000001EB E8530C                  	call Install_BDSM_and_set_bpb
  1308                                  
  1309 000001EE E885FF                  	call alloc_upb
  1310 000001F1 0E                      	push cs
  1311 000001F2 1F                      	pop ds
  1312                                   assume ds:SYSINITGROUP
  1313 000001F3 BE[0800]                	mov si, BDS_diskette_template	; access with ds
  1314 000001F6 B96400                  	mov cx, BDS_TYPE_struc_size
  1315 000001F9 57                      	push di
  1316 000001FA F3A4                    	rep movsb
  1317 000001FC 06                      	push es
  1318 000001FD 1F                      	pop ds
  1319                                   assume ds:nothing, es:nothing
  1320 000001FE 5F                      	pop di
  1321 000001FF C6450501                	mov byte [di + DRIVELET], 1
  1322 00000203 E83B0C                  	call Install_BDSM_and_set_bpb
  1323                                  
  1324                                  DoHard equ DOHARD	; NASM port label
  1325 00000206 E93001                  	jmp	DoHard			; allocate/initialise BDS for HardDrives
  1326                                  ;SB34INIT004*********************************************************
  1327                                  
  1328                                  LOOP_DRIVE:
  1329 00000209 E89707                  	call sysinit_get_ds_dosentry	; DRVMAX in DOSENTRY
  1330                                   assume ds:DOSENTRYGROUP
  1331 0000020C 3A16[0000]              	CMP	DL,[DRVMAX]
  1332 00000210 7203E92401              	jae	DONE_DRIVES
  1333                                  
  1334 00000215 E85EFF                  	call alloc_upb
  1335 00000218 0E                      	push cs
  1336 00000219 1F                      	pop ds
  1337                                   assume ds:SYSINITGROUP
  1338 0000021A BE[0800]                	mov si, BDS_diskette_template	; access with ds
  1339 0000021D B96400                  	mov cx, BDS_TYPE_struc_size
  1340 00000220 57                      	push di
  1341 00000221 F3A4                    	rep movsb
  1342 00000223 5F                      	pop di
  1343                                  	; XOR	CX,CX			; ZERO ALL FLAGS (cx already zero)
  1344                                  
  1345 00000224 B600                    	MOV	DH,FF48TPI		; SET FORM FACTOR TO 48 TPI
  1346 00000226 C606[6F00]28            	MOV	byte [NUM_CYLN],40	      ; 40 TRACKS PER SIDE
  1347                                  
  1348 0000022B 1E                      	PUSH	DS
  1349 0000022C 57                      	PUSH	DI
  1350 0000022D 52                      	PUSH	DX
  1351 0000022E 51                      	PUSH	CX
  1352                                  
  1353                                  ;SB33022********************************************************************
  1354 0000022F B408                    	MOV	AH, 8h			;GET DRIVE PARAMETERS	       ;SB;3.30
  1355 00000231 F9                      	stc
  1356 00000232 CD13                    	INT	13h			;CALL ROM-BIOS		       ;SB;3.30
  1357                                  ;SB33022********************************************************************
  1358 00000234 726F                    	jc	NOPARMSFROMROM		; GOT AN OLD ROM
  1359                                  
  1360                                  ;J.K. 10/9/86 If CMOS is bad, it gives ES,AX,BX,CX,DH,DI=0. CY=0.
  1361                                  ;In this case, we are going to put bogus informations to BDS table.
  1362                                  ;We are going to set CH=39,CL=9,DH=1 to avoid divide overflow when
  1363                                  ;they are calculated at the later time.  This is just for the Diagnostic
  1364                                  ;Diskette which need MSBIO,MSDOS to boot up before it sets CMOS.
  1365                                  ;This should only happen with drive B.
  1366                                  
  1367 00000236 80FD00                  	CMP	CH,0			; if ch=0, then cl,dh=0 too.
  1368 00000239 7506                    	JNE	PFR_OK
  1369 0000023B B527                    	MOV	CH,39			; ROM gave wrong info.
  1370 0000023D B109                    	MOV	CL,9			; Let's default to 360K.
  1371 0000023F B601                    	MOV	DH,1
  1372                                  PFR_OK:
  1373 00000241 FEC5                    	INC	CH			; MAKE NUMBER OF CYLINDERS 1-BASED
  1374 00000243 8836[6C00]              	MOV	byte ptr [NUM_HEADS],DH	; SAVE PARMS RETURNED BY ROM
  1375 00000247 FF06[6C00]              	inc	word ptr [NUM_HEADS]	; MAKE NUMBER OF HEADS 1-BASED
  1376 0000024B 80E13F                  	AND	CL,00111111B		; EXTRACT SECTORS/TRACK
  1377 0000024E 880E[6E00]              	MOV	[SEC_TRK],CL
  1378 00000252 882E[6F00]              	MOV	[NUM_CYLN],CH	      ; ASSUME LESS THAN 256 CYLINDERS!!
  1379                                  
  1380 00000256 E84207                  	call sysinit_get_ds_dosbiodata
  1381                                   assume ds:DOSGROUP
  1382                                  ; MAKE SURE THAT EOT CONTAINS THE MAX NUMBER OF SEC/TRK IN SYSTEM OF FLOPPIES
  1383 00000259 3A0E[0000]              	CMP	CL,[EOT]			; MAY SET CARRY
  1384 0000025D 7604                    	JBE	EOT_OK
  1385 0000025F 880E[0000]              	MOV	[EOT],CL
  1386                                  EOT_OK:
  1387 00000263 59                      	POP	CX
  1388 00000264 5A                      	POP	DX
  1389 00000265 5F                      	POP	DI
  1390 00000266 1F                      	POP	DS
  1391                                   assume ds:SYSINITGROUP
  1392                                  
  1393                                  ; CHECK FOR CHANGELINE SUPPORT ON DRIVE
  1394                                  ;SB33023********************************************************************
  1395 00000267 B415                    	mov	AH, 15h      ;SB	; set command to get DASD type
  1396 00000269 F9                      	stc
  1397 0000026A CD13                    	int	13h	     ;SB	; call ROM-BIOS
  1398                                  ;SB33023********************************************************************
  1399 0000026C 7208                    	JC	CHANGELINE_DONE
  1400 0000026E 80FC02                  	CMP	AH,02			; CHECK FOR PRESENCE OF CHANGELINE
  1401 00000271 7503                    	JNE	CHANGELINE_DONE
  1402                                  ;
  1403                                  ; WE HAVE A DRIVE WITH CHANGE LINE SUPPORT.
  1404                                  ;
  1405                                  	MESSAGE FTESTINIT,<"96TPI DEVICES",CR,LF>
  1406                                  
  1407 00000273 80C902                  	OR	CL,FCHANGELINE		; SIGNAL TYPE
  1408                                  ;
  1409                                  ; WE NOW TRY TO SET UP THE FORM FACTOR FOR THE TYPES OF MEDIA THAT WE KNOW
  1410                                  ; AND CAN RECOGNISE. FOR THE REST, WE SET THE FORM FACTOR AS "OTHER".
  1411                                  ;
  1412                                  CHANGELINE_DONE:
  1413 00000276 0E                      	push cs
  1414 00000277 1F                      	pop ds
  1415                                   assume ds:SYSINITGROUP
  1416                                  ; 40 CYLINDERS AND 9 OR LESS SEC/TRK, TREAT AS 48 TPI MEDIUM.
  1417 00000278 803E[6F00]28            	CMP	byte [NUM_CYLN],40
  1418 0000027D 750B                    	JNZ	TRY_80
  1419 0000027F 803E[6E00]09            	CMP	byte [SEC_TRK],9
  1420 00000284 761D                    	JBE	GOT_FF			; dh = FF48TPI -->
  1421                                  GOTOTHER:
  1422 00000286 B607                    	MOV	DH,FFOTHER		; WE HAVE A "STRANGE" MEDIUM
  1423 00000288 EB19                    	JMP	SHORT GOT_FF
  1424                                  
  1425                                  ;
  1426                                  ; 80 CYLINDERS AND 9 SECTORS/TRACK => 720 KB DEVICE
  1427                                  ; 80 CYLINDERS AND 15 SEC/TRK => 96 TPI MEDIUM
  1428                                  ;
  1429                                  TRY_80:
  1430 0000028A B601                    	MOV	DH,FF96TPI		; in case it is 96 TPI
  1431 0000028C 803E[6F00]50            	CMP	byte [NUM_CYLN],80
  1432 00000291 75F3                    	JNZ	GOTOTHER		; resets dh
  1433 00000293 803E[6E00]0F            	CMP	byte [SEC_TRK],15
  1434 00000298 7409                    	JZ	GOT_FF			; (dh = FF96TPI)
  1435 0000029A 803E[6E00]09            	CMP	byte [SEC_TRK],9
  1436 0000029F 75E5                    	JNZ	GOTOTHER		; resets dh
  1437 000002A1 B602                    	MOV	DH,FFSMALL		; reset dh
  1438                                  GOT_FF:
  1439 000002A3 EB28                    	JMP	SHORT NEXTDRIVE
  1440                                  
  1441                                  ; WE HAVE AN OLD ROM, SO WE EITHER HAVE A 48TPI OR 96TPI DRIVE. IF THE DRIVE
  1442                                  ; HAS CHANGELINE, WE ASSUEM IT IS A 96TPI, OTHERWISE WE TREAT IT AS A 48TPI.
  1443                                  
  1444                                  NOPARMSFROMROM:
  1445 000002A5 59                      	POP	CX
  1446 000002A6 5A                      	POP	DX
  1447 000002A7 5F                      	POP	DI
  1448 000002A8 1F                      	POP	DS
  1449                                   assume ds:SYSINITGROUP
  1450                                  
  1451                                  ;SB33024****************************************************************
  1452 000002A9 B415                    	MOV	AH, 15h 		; SET COMMAND TO GET DASD TYPE ;SB;3.30
  1453 000002AB F9                      	stc
  1454 000002AC CD13                    	INT	13h			; CALL ROM-BIOS 	       ;SB;3.30
  1455                                  ;SB33024****************************************************************
  1456 000002AE 721D                    	JC	NEXTDRIVE
  1457 000002B0 80FC02                  	CMP	AH,2			; IS THERE CHANGELINE?
  1458 000002B3 7518                    	JNZ	NEXTDRIVE
  1459 000002B5 80C902                  	OR	CL,FCHANGELINE
  1460 000002B8 C606[6F00]50            	MOV	byte [NUM_CYLN],80
  1461 000002BD B601                    	MOV	DH,FF96TPI
  1462 000002BF B00F                    	MOV	AL,15			; SET EOT IF NECESSARY
  1463                                  
  1464 000002C1 E8D706                  	call sysinit_get_ds_dosbiodata
  1465                                   assume ds:DOSGROUP
  1466 000002C4 3A06[0000]              	CMP	AL, [EOT]
  1467 000002C8 7603                    	JBE	EOT_OK2
  1468 000002CA A2[0000]                	MOV	[EOT],AL
  1469                                  EOT_OK2:
  1470                                  
  1471                                  NEXTDRIVE:
  1472 000002CD 80C920                  	OR	CL,FI_OWN_PHYSICAL	; SET THIS TRUE FOR ALL DRIVES
  1473 000002D0 88D7                    	MOV	BH,DL			;SAVE INT13 DRIVE NUMBER
  1474                                  
  1475                                  ; WE NEED TO DO SPECIAL THINGS IF WE HAVE A SINGLE DRIVE SYSTEM AND ARE SETTING
  1476                                  ; UP A LOGICAL DRIVE. IT NEEDS TO HAVE THE SAME INT13 DRIVE NUMBER AS ITS
  1477                                  ; COUNTERPART, BUT THE NEXT DRIVE LETTER. ALSO RESET OWNERSHIP FLAG.
  1478                                  ; WE DETECT THE PRESENCE OF THIS SITUATION BY EXAMINING THE FLAG SINGLE FOR THE
  1479                                  ; VALUE 2.
  1480                                  
  1481 000002D2 E8C606                  	call sysinit_get_ds_dosbiodata
  1482                                   assume ds:DOSGROUP
  1483 000002D5 803E[0000]02            	CMP	byte [SINGLE],2
  1484 000002DA 7505                    	JNZ	NOT_SPECIAL
  1485 000002DC FECF                    	DEC	BH			; INT13 DRIVE NUMBER SAME FOR LOGICAL DRIVE
  1486 000002DE 80F120                  	XOR	CL,FI_OWN_PHYSICAL	; RESET OWNERSHIP FLAG FOR LOGICAL DRIVE
  1487                                  NOT_SPECIAL:
  1488                                  ; THE VALUES THAT WE PUT IN FOR RHDLIM AND RSECLIM WILL ONLY REMAIN IF THE
  1489                                  ; FORM FACTOR IS OF TYPE "FFOTHER".
  1490 000002E1 2E8E1E[0200]            	mov ds, word [cs:nextupb + 2]
  1491                                   assume ds:UPB
  1492 000002E6 2EA1[6C00]              	MOV	ax, [cs:NUM_HEADS]
  1493 000002EA 894536                  	MOV	WORD PTR [DI + RHDLIM],AX
  1494 000002ED 2EA0[6E00]              	MOV	AL,[cs:SEC_TRK]
  1495 000002F1 894534                  	MOV	WORD PTR [DI + RSECLIM],AX
  1496 000002F4 894D23                  	MOV	WORD PTR [DI + FLAGS],CX
  1497 000002F7 887522                  	MOV	BYTE PTR [DI + FORMFACTOR],DH
  1498 000002FA 885505                  	MOV	BYTE PTR [DI + DRIVELET],DL
  1499 000002FD 887D04                  	MOV	BYTE PTR [DI + DRIVENUM],BH
  1500 00000300 2E8A1E[6F00]            	MOV	BL,BYTE PTR [cs:NUM_CYLN]
  1501 00000305 885D25                  	MOV	BYTE PTR [DI + CCYLN],BL	; ONLY THE L.S. BYTE IS SET HERE
  1502 00000308 E8360B                  	call Install_BDSM_and_set_bpb
  1503 0000030B E89E06                  	call sysinit_get_es_dosbiodata
  1504                                   assume es:DOSGROUP
  1505 0000030E 26803E[0000]01          	CMP	byte [es:SINGLE],1		; SPECIAL CASE FOR SINGLE DRIVE SYSTEM
  1506 00000314 751F                    	JNZ	NO_SINGLE
  1507                                  	MESSAGE FTESTINIT,<"SINGLE DRIVE SYSTEM",CR,LF>
  1508 00000316 26FE06[0000]            	inc	byte [es:SINGLE]		; DON'T LOSE INFO THAT WE HAVE SINGLE SYSTEM
  1509 0000031B 83C910                  	OR	CX,FI_AM_MULT
  1510 0000031E 094D23                  	OR	WORD PTR [DI + FLAGS],CX
  1511 00000321 42                      	inc dx
  1512                                  
  1513 00000322 E851FE                  	call alloc_upb
  1514 00000325 0E                      	push cs
  1515 00000326 1F                      	pop ds
  1516                                   assume ds:SYSINITGROUP, es:UPB
  1517 00000327 BE[0800]                	mov si, BDS_diskette_template	; access with ds
  1518 0000032A 51                      	push cx
  1519 0000032B B96400                  	mov cx, BDS_TYPE_struc_size
  1520 0000032E 57                      	push di
  1521 0000032F F3A4                    	rep movsb
  1522 00000331 5F                      	pop di				; di -> next UPB
  1523 00000332 59                      	pop cx
  1524 00000333 EB98                    	JMP	SHORT NEXTDRIVE 	; USE SAME INFO FOR BDS A PREVIOUS
  1525                                  NO_SINGLE:
  1526 00000335 42                      	inc dx
  1527 00000336 E9D0FE                  	JMP	LOOP_DRIVE
  1528                                  
  1529                                  DONE_DRIVES:
  1530                                  
  1531                                  ; SET UP ALL THE HARD DRIVES IN THE SYSTEM
  1532                                  
  1533                                  DOHARD:
  1534                                   assume ds:nothing, es:nothing, ss:nothing
  1535                                  
  1536                                  extern partition_table, partition_table.end
  1537                                  extern load_mode, load_scan_flags, load_partition_cycle
  1538                                  extern load_current_partition, load_unit, load_amount_units
  1539                                  extern next_block_device_unit
  1540                                  
  1541 00000339 0E                      	push cs
  1542 0000033A 1F                      	pop ds
  1543                                   assume ds:SYSINITGROUP
  1544 0000033B A0[0000]                	mov al, [HARDNUM]
  1545 0000033E A2[0000]                	mov [next_block_device_unit], al
  1546 00000341 E82F00                  	call .init
  1547                                  
  1548 00000344 F606[0100]80            	testopt [load_mode], mode_dlasort_zero
  1549 00000349 7434                    	jz .once
  1550                                  
  1551 0000034B BB[0205]                	mov bx, scan_priority_primary
  1552 0000034E E81400                  	call .pass
  1553 00000351 BB[8005]                	mov bx, scan_early_primary
  1554 00000354 E80E00                  	call .pass
  1555 00000357 BB[A103]                	mov bx, scan_logical_ignore_lba_if
  1556 0000035A E80800                  	call .pass
  1557 0000035D BB[0208]                	mov bx, scan_subsequent_primary
  1558 00000360 E80200                  	call .pass
  1559 00000363 EB39                    	jmp .done
  1560                                  
  1561                                  
  1562                                  .pass:
  1563                                  .passloop:
  1564 00000365 E87900                  	call nextunit
  1565 00000368 7209                    	jc .passdone
  1566                                  
  1567 0000036A 53                      	push bx
  1568 0000036B B9[F009]                	mov cx, .each
  1569 0000036E FFD3                    	call bx
  1570 00000370 5B                      	pop bx
  1571 00000371 EBF2                    	jmp .passloop
  1572                                  
  1573                                  .passdone:
  1574                                  .init:
  1575 00000373 C606[0000]7F            	mov byte [load_unit], 7Fh
  1576 00000378 A0[0000]                	mov al, byte [HNUM]
  1577 0000037B A2[0000]                	mov byte [load_amount_units], al
  1578 0000037E C3                      	retn
  1579                                  
  1580                                  
  1581                                  .once:
  1582 0000037F E85F00                  	call nextunit
  1583 00000382 721A                    	jc .done
  1584                                  
  1585 00000384 B9[F009]                	mov cx, .each
  1586 00000387 E87801                  	call scan_priority_primary
  1587 0000038A B9[F009]                	mov cx, .each
  1588 0000038D E8F001                  	call scan_early_primary
  1589 00000390 B9[F009]                	mov cx, .each
  1590 00000393 E80B00                  	call scan_logical_ignore_lba_if
  1591 00000396 B9[F009]                	mov cx, .each
  1592 00000399 E86604                  	call scan_subsequent_primary
  1593 0000039C EBE1                    	jmp .once
  1594                                  
  1595                                  .each equ handle_each_partition
  1596                                  
  1597                                  .done:
  1598 0000039E E9BC00                  	jmp hdd_done
  1599                                  
  1600                                  
  1601                                  scan_logical_ignore_lba_if:
  1602 000003A1 F606[2400]04            	testopt [BDS_harddisk_template + FLAGS], F_LBA
  1603 000003A6 7403E97102              	jnz scan_logical
  1604 000003AB FF36[0000]              	push word [load_mode]
  1605 000003AF 8026[0000]F3            	clropt [load_mode], mode_first_type_ext15
  1606 000003B4 800E[0000]04            	setopt [load_mode], mode_ignore_ext15
  1607 000003B9 E86002                  	call scan_logical
  1608 000003BC 8F06[0000]              	pop word [load_mode]
  1609 000003C0 C3                      	retn
  1610                                  
  1611                                  
  1612                                  scanptab_error:
  1613                                  bootcmd:
  1614                                  .fail_read:
  1615 000003C1 0E                      	 push cs
  1616 000003C2 07                      	 pop es
  1617                                   assume es:SYSINITGROUP
  1618 000003C3 BF[020F]                	mov di, msg.bootfail_read_errorcode
  1619 000003C6 88E0                    	mov al, ah
  1620                                  extern hexbyte
  1621 000003C8 E8(0000)                	call hexbyte
  1622 000003CB BA[D50E]                	mov dx, msg.bootfail_read
  1623                                  .fail:
  1624 000003CE 0E                      	 push cs
  1625 000003CF 07                      	 pop es
  1626                                   assume es:SYSINITGROUP
  1627 000003D0 0E                      	 push cs
  1628 000003D1 1F                      	 pop ds
  1629                                   assume ds:SYSINITGROUP
  1630 000003D2 52                      	push dx
  1631 000003D3 BA[C80E]                	mov dx, msg.bootfail
  1632                                  extern init2_disp_msg_asciz_cs_dx
  1633 000003D6 E8(0000)                	call init2_disp_msg_asciz_cs_dx
  1634 000003D9 5A                      	pop dx
  1635 000003DA E8(0000)                	call init2_disp_msg_asciz_cs_dx
  1636 000003DD 89EC                    	mov sp, bp			; abort pass
  1637 000003DF 5D                      	pop bp
  1638 000003E0 C3                      	retn
  1639                                  
  1640                                  
  1641                                  		; INP:	load_amount_units = remaining amount units
  1642                                  		;	load_unit = prior unit
  1643                                  		; OUT:	CY if units exhausted
  1644                                  		;	NC if another unit follows,
  1645                                  		;	 load_unit = next unit to process
  1646                                  		;	 ds:di -> UPB template,
  1647                                  		;	  with CHS geometry and LBA flag setup
  1648                                  		; CHG:	ax, cx, dx, di, es
  1649                                  		; STT:	ds = cs
  1650                                  nextunit:
  1651                                  .loop:
  1652 000003E1 FE06[0000]              	inc byte [load_unit]
  1653                                  
  1654 000003E5 31C0                    	xor ax, ax
  1655 000003E7 A3[0000]                	mov word [load_partition_cycle], ax
  1656                                  
  1657 000003EA 803E[0000]01            	cmp byte [load_amount_units], 1
  1658 000003EF 720E                    	jb .ret			; CY if branching
  1659 000003F1 8A16[0000]              	mov dl, byte [load_unit]
  1660 000003F5 E80E00                  	call query_geometry_upb
  1661 000003F8 FE0E[0000]              	dec byte [load_amount_units]
  1662 000003FC 72E3                    	jc .loop		; just skip unit if error -->
  1663 000003FE F8                      	clc			; NC
  1664                                  .ret:
  1665 000003FF C3                      	retn
  1666                                  
  1667                                  
  1668                                  upb_reset:
  1669 00000400 C606[0700]00            	mov byte [FBIGFAT], 0		; ASSUME 12 BIT FAT
  1670 00000405 C3                      	retn
  1671                                  
  1672                                  
  1673                                  		; INP:	dl = unit number
  1674                                  		; OUT:	CY if error getting geometry
  1675                                  		;	NC if success
  1676                                  		;	ds:di -> UPB template
  1677                                  		; STT:	ds = cs
  1678                                  		; CHG:	ax, cx, dx, di, es
  1679                                  query_geometry_upb:
  1680                                   assume ds:SYSINITGROUP, es:nothing, ss:nothing
  1681                                  extern BDS_harddisk_template
  1682 00000406 BF[0000]                	mov di, BDS_harddisk_template
  1683 00000409 E8F4FF                  	call upb_reset
  1684 0000040C 885504                  	mov byte [di + DRIVENUM], dl
  1685 0000040F 53                      	push bx
  1686 00000410 C745232100              	mov word [di + FLAGS], FI_OWN_PHYSICAL | FNON_REMOVABLE
  1687                                  					; F_LBA clear
  1688 00000415 E8FE08                  	call detectlba
  1689 00000418 7204                    	jc .no_lba
  1690 0000041A 804D2404                	setopt [di + FLAGS], F_LBA	; set flag
  1691                                  .no_lba:
  1692 0000041E C6452205                	mov byte [di + FORMFACTOR], FFHARDFILE
  1693                                  
  1694 00000422 57                      	push di
  1695 00000423 B408                    	mov ah, 08h			; set command to get drive parameters
  1696 00000425 F9                      	stc
  1697 00000426 CD13                    	int 13h				; call rom-bios disk routine
  1698 00000428 5F                      	pop di
  1699                                  ; DH IS NUMBER OF HEADS-1
  1700                                  ; DL IS NUMBER OF HARD DISKS ATTACHED
  1701                                  ; LOW 6 BITS OF CL IS SECTORS/TRACK
  1702                                  ; HIGH 2 BITS OF CL WITH CH ARE MAX # OF CYLINDERS
  1703 00000429 86F2                    	xchg dh, dl			; dl = maximum head
  1704 0000042B B600                    	mov dh, 0			; dx = maximum head (preserve CF !)
  1705 0000042D 42                      	inc dx				; GET NUMBER OF HEADS (preserve CF !)
  1706 0000042E 895515                  	mov word [di + HDLIM], dx
  1707 00000431 5B                      	pop bx
  1708 00000432 7206                    	jc .ret				; CARRY HERE MEANS NO HARD DISK
  1709 00000434 80E13F                  	and cl, 3Fh			; EXTRACT NUMBER OF SECTORS/TRACK
  1710                                  					; (NC)
  1711 00000437 884D13                  	mov byte [di + SECLIM], cl
  1712                                  .ret:
  1713 0000043A C3                      	retn
  1714                                  
  1715                                  
  1716                                  		; INP:	al = partition type
  1717                                  		; OUT:	CY or NZ or both if not a known type
  1718                                  		;	NC, ZR if known type we can access
  1719                                  		; STT:	ds = cs
  1720                                  load_is_known:
  1721                                   assume ds:SYSINITGROUP, es:nothing, ss:nothing
  1722 0000043B 3C01                    	cmp al, ptFAT12
  1723 0000043D 741C                    	je .isknown		; ZR if branches
  1724 0000043F 3C04                    	cmp al, ptFAT16_16BIT_CHS
  1725 00000441 7418                    	je .isknown		; ZR if branches
  1726 00000443 3C06                    	cmp al, ptFAT16_CHS
  1727 00000445 7414                    	je .isknown		; ZR if branches
  1728 00000447 3C0E                    	cmp al, ptFAT16
  1729 00000449 7510                    	jne .notknown		; NZ if branches
  1730                                  .isknown_lba:
  1731 0000044B F606[2400]04            	testopt [BDS_harddisk_template + FLAGS], F_LBA
  1732 00000450 7407                    	jz .discard
  1733 00000452 F606[0100]40            	testopt [load_mode], mode_disable_lba
  1734 00000457 7402                    	jz .isknown		; ZR if branches
  1735                                  .discard:
  1736 00000459 F9                      	stc
  1737 0000045A C3                      	retn
  1738                                  
  1739                                  .isknown:
  1740                                  .notknown:
  1741 0000045B F8                      	clc
  1742 0000045C C3                      	retn
  1743                                  
  1744                                  
  1745                                  hdd_done:
  1746                                   assume ds:SYSINITGROUP, es:nothing
  1747 0000045D A0[0000]                	mov al, byte [next_block_device_unit]
  1748 00000460 E84005                  	call sysinit_get_ds_dosentry	; DRVMAX in DOSENTRY
  1749                                   assume ds:DOSENTRYGROUP
  1750 00000463 A2[0000]                	MOV	[DRVMAX],AL
  1751                                  
  1752                                  ; END OF DRIVE INITIALIZATION.
  1753                                  
  1754 00000466 E81109                  	CALL	SETDRVPARMS
  1755                                  
  1756                                  write_dskdrvs_upb:
  1757 00000469 0E                      	push cs
  1758 0000046A 1F                      	pop ds
  1759                                   assume ds:SYSINITGROUP
  1760 0000046B C43E[0000]              	les di, [nextupb]
  1761                                   assume es:UPB
  1762 0000046F 8CC0                    	mov ax, es
  1763 00000471 85C0                    	test ax, ax
  1764 00000473 745D                    	jz .done
  1765 00000475 83C765                  	add di, BDSM_type_struc_size + 1; -> behind last UPB
  1766 00000478 722C                    	jc .mem_err_j
  1767 0000047A 83E7FE                  	and di, ~1			; round to word boundary
  1768 0000047D BE[E000]                	mov si, DSKDRVS
  1769 00000480 8B1E[DE00]              	mov bx, [Mini_BPB_ptr]
  1770 00000484 29F3                    	sub bx, si
  1771 00000486 89D9                    	mov cx, bx
  1772 00000488 01FB                    	add bx, di
  1773 0000048A 721A                    	jc .mem_err_j
  1774 0000048C 83C30F                  	add bx, 15			; -> behind wanted list
  1775 0000048F 7215                    	jc .mem_err_j
  1776 00000491 3B1E[0000]              	cmp bx, word [nextupb]
  1777 00000495 7303E906FD              	jb mem_err_j
  1778 0000049A 51                      	push cx
  1779 0000049B B104                    	mov cl, 4
  1780 0000049D D3EB                    	shr bx, cl			; to paragraphs
  1781 0000049F 59                      	pop cx
  1782 000004A0 B44A                    	mov ah, 4Ah
  1783 000004A2 CD21                    	int 21h				; resize
  1784 000004A4 7303                    	jnc @F
  1785                                  .mem_err_j:
  1786 000004A6 E9F7FC                  	jmp mem_err_j
  1787                                  @@:
  1788 000004A9 D1E9                    	shr cx, 1
  1789 000004AB 57                      	push di
  1790 000004AC F3A5                    	rep movsw
  1791 000004AE E8EA04                  	call sysinit_get_ds_dosbiodata
  1792                                   assume ds:DOSGROUP
  1793                                   extern dskdrvs_indirect
  1794 000004B1 8C06[0200]              	mov word [dskdrvs_indirect + 2], es
  1795 000004B5 8F06[0000]              	pop word [dskdrvs_indirect]
  1796                                  
  1797 000004B9 8CC0                    	mov ax, es
  1798 000004BB 48                      	dec ax
  1799 000004BC 8EC0                    	mov es, ax
  1800                                   assume es:MCB
  1801 000004BE 26C70601000800          	mov word [es:arena_owner], 8
  1802                                  				; init owner
  1803 000004C5 BF0500                  	mov di, arena_reserved
  1804 000004C8 0E                      	 push cs
  1805 000004C9 1F                      	 pop ds
  1806                                   assume ds:SYSINITGROUP
  1807 000004CA BE[D304]                	mov si, upb_smcb
  1808 000004CD B90B00                  	mov cx, 3 + 8
  1809 000004D0 F3A4                    	rep movsb		; init name and type
  1810                                  
  1811                                  .done:
  1812 000004D2 C3                      	retn
  1813                                  
  1814                                  upb_smcb:
  1815 000004D3 000000                  	db 0,0,0
  1816 000004D6 5300                    	db "S",0		; name "S"
  1817 000004D8 09                      	db 9			; type S_UPB
  1818 000004D9 00<rep 5h>              	times 5 db 0
  1819                                  
  1820                                  
  1821                                  		; INP:	dx:ax = first sector
  1822                                  		;	bx:0 -> buffer
  1823                                  		; OUT:	es = input bx
  1824                                  		;	dx:ax = incremented
  1825                                  		;	bx => after read data
  1826                                  		; CHG:	-
  1827                                  		; STT:	ds = cs
  1828                                  read_ae_512_bytes:
  1829                                   assume ds:SYSINITGROUP
  1830 000004DE 52                      	push dx
  1831 000004DF 50                      	push ax
  1832 000004E0 53                      	push bx
  1833 000004E1 51                      	push cx
  1834 000004E2 8EC3                    	mov es, bx
  1835                                   assume es:nothing
  1836 000004E4 31DB                    	xor bx, bx		; es:bx -> buffer
  1837 000004E6 B90102                  	mov cx, 0201h		; cx = function code and count
  1838 000004E9 57                      	push di
  1839 000004EA BF[0000]                	mov di, BDS_harddisk_template
  1840                                  				; ds:di -> template
  1841 000004ED E8F207                  	call readsector_flag
  1842 000004F0 5F                      	pop di
  1843 000004F1 7303E9CBFE              	jc scanptab_error
  1844 000004F6 59                      	pop cx
  1845 000004F7 5B                      	pop bx
  1846 000004F8 58                      	pop ax
  1847 000004F9 5A                      	pop dx
  1848 000004FA 83C320                  	add bx, paras(512)
  1849 000004FD 40                      	inc ax
  1850 000004FE 7501                    	jnz .
  1851 00000500 42                      	inc dx
  1852                                  .:
  1853 00000501 C3                      	retn
  1854                                  
  1855                                  
  1856                                  overridedef DEBUG4, 0
  1857                                  %define _SCANPTAB_PREFIX
  1858                                  %define _SCANPTAB_DEBUG4_PREFIX
  1859                                  %assign _PARTITION_TABLE_IN_CS 1
  1860                                  %define _BASE bp
  1861                                  %assign _SPT_ELD 0
  1862                                  %assign _MODE 1
  1863                                  %assign _SPT_MULTIPASS 1
  1864                                  %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 00000502 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 00000507 55                  <1> 	push bp
    91                              <1> %ifidn _BASE, ss:bx
    92                              <1> 	mov bx, sp
    93                              <1> %elifidn _BASE, bp
    94 00000508 89E5                <1> 	mov bp, sp
    95                              <1> %endif
    96 0000050A 31FF                <1> 	xor di, di
    97 0000050C 57                  <1> 	push di		; [_BASE+di-2]
    98 0000050D 57                  <1> 	push di		; [_BASE+di-4]
    99 0000050E 57                  <1> 	push di		; [_BASE+di-6]
   100 0000050F 57                  <1> 	push di		; [_BASE+di-8]
   101                              <1> %if _MODE
   102 00000510 893E[0000]          <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], di
   103                              <1> sptinternal
   104                              <1> %endif
   105                              <1> 
   106 00000514 803E[0000]80        <1> sptrel	cmp byte [ %[_SCANPTAB_PREFIX]load_unit], 80h
   107                              <1> sptinternal -3
   108 00000519 7326                <1> 	jae @F
   109                              <1> 
   110 0000051B 57                  <1> 	push di
   111 0000051C 51                  <1> 	push cx
   112                              <1> %if _PARTITION_TABLE_IN_CS
   113 0000051D 0E                  <1> 	 push cs
   114                              <1> %else
   115                              <1> 	 push ss
   116                              <1> %endif
   117 0000051E 07                  <1> 	 pop es
   118                              <1>  assume es:SYSINITGROUP
   119 0000051F BF[0000]            <1> sptrel	mov di, %[_SCANPTAB_PREFIX]partition_table
   120                              <1> sptinternal
   121 00000522 31C0                <1> 	xor ax, ax
   122 00000524 B92000              <1> 	mov cx, (4 * 16) >> 1
   123 00000527 F3AB                <1> 	rep stosw			; initialise fake partition table
   124 00000529 59                  <1> 	pop cx
   125 0000052A 5F                  <1> 	pop di
   126 0000052B BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   127                              <1> sptinternal
   128                              <1> 					; -> fake PARTINFO
   129 0000052E 26C60480            <1> 	mov byte [es:si + piBoot], 80h	; fake primary active
   130 00000532 26C64404FF          <1> 	mov byte [es:si + piType], 0FFh	; fake a type
   131 00000537 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 0000053C FFD1                <1> 	call cx
   134                              <1> 
   135 0000053E E90302              <1> 	jmp %[_SCANPTAB_PREFIX]scan_logical.end
   136                              <1> 
   137                              <1> 
   138                              <1> @@:
   139                              <1>  %if _SPT_MULTIPASS
   140 00000541 F606[0100]04        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   141                              <1> sptinternal -3			; active primary first ?
   142 00000546 7434                <1> 	jz .end
   143                              <1>  %endif
   144                              <1> 
   145 00000548 31C0                <1> 	xor ax, ax
   146 0000054A 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 0000054C 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 0000054F BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   153                              <1> sptinternal
   154 00000552 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 00000556 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   171                              <1> sptinternal
   172 0000055A 268A4404            <1> 	mov al, byte [es:si + piType]
   173 0000055E 3C00                <1> 	cmp al, 0
   174 00000560 7411                <1> 	je .loop_active_primary_skip
   175 00000562 26803C00            <1> 	cmp byte [es:si + piBoot], 0
   176 00000566 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 00000568 E8D0FE              <1> 	call %[_SCANPTAB_PREFIX]load_is_known
   183 0000056B 7206                <1> 	jc .loop_active_primary_skip
   184 0000056D 7504                <1> 	jnz .loop_active_primary_skip
   185                              <1> 
   186 0000056F FFD1                <1> 	call cx			; es:si -> partition table entry
   187                              <1> 				; byte [load_current_partition] = which
   188 00000571 EB09                <1> 	jmp .active_done
   189                              <1> 
   190                              <1> .loop_active_primary_skip:
   191 00000573 83C610              <1> 	add si, 16
   192 00000576 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   193                              <1> sptinternal
   194 0000057A 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 0000057C 89EC                <1> 	mov sp, bp		; restore sp
   201 0000057E 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 0000057F C3                  <1> 	retn			; and bye
   207                              <1> 
   208                              <1> 
   209                              <1> %[_SCANPTAB_PREFIX]scan_early_primary:
   210 00000580 8326[0000]00        <1> sptrel	and word [ %[_SCANPTAB_PREFIX]load_partition_cycle], 0
   211                              <1> sptinternal -3
   212                              <1> 
   213 00000585 55                  <1> 	push bp
   214                              <1> %ifidn _BASE, ss:bx
   215                              <1> 	mov bx, sp
   216                              <1> %elifidn _BASE, bp
   217 00000586 89E5                <1> 	mov bp, sp
   218                              <1> %endif
   219 00000588 31FF                <1> 	xor di, di
   220 0000058A 57                  <1> 	push di		; [_BASE+di-2]
   221 0000058B 57                  <1> 	push di		; [_BASE+di-4]
   222 0000058C 57                  <1> 	push di		; [_BASE+di-6]
   223 0000058D 57                  <1> 	push di		; [_BASE+di-8]
   224 0000058E 31C0                <1> 	xor ax, ax
   225 00000590 31D2                <1> 	xor dx, dx
   226                              <1> 
   227                              <1> %if _MODE
   228 00000592 A3[0000]            <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], ax
   229                              <1> sptinternal
   230                              <1> %endif
   231                              <1> 
   232 00000595 E81C03              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.first
   233 00000598 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 0000059C BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   244                              <1> sptinternal
   245                              <1> 
   246                              <1> 
   247 0000059F F606[0100]04        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   248                              <1> sptinternal -3			; active primary first ?
   249 000005A4 7437                <1> 	jz .active_ignored
   250                              <1> 
   251                              <1> .loop_active_skip:
   252                              <1> 
   253 000005A6 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   254                              <1> sptinternal
   255 000005AA 268A4404            <1> 	mov al, byte [es:si + piType]
   256 000005AE 3C00                <1> 	cmp al, 0
   257 000005B0 741A                <1> 	je .loop_active_skip_skip
   258 000005B2 26803C00            <1> 	cmp byte [es:si + piBoot], 0
   259 000005B6 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 000005B8 E880FE              <1> 	call %[_SCANPTAB_PREFIX]load_is_known
   266 000005BB 720F                <1> 	jc .loop_active_skip_skip
   267 000005BD 750D                <1> 	jnz .loop_active_skip_skip
   268 000005BF A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   269                              <1> sptinternal
   270 000005C2 A2[0100]            <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   271                              <1> sptinternal
   272 000005C5 800E[0000]20        <1> sptrel	setopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   273                              <1> sptinternal -3			; mark as had a primary partition yet
   274 000005CA EB09                <1> 	jmp .active_skip_done
   275                              <1> 
   276                              <1> .loop_active_skip_skip:
   277 000005CC 83C610              <1> 	add si, 16
   278 000005CF 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   279                              <1> sptinternal
   280 000005D3 72D1                <1> 	jb .loop_active_skip
   281                              <1> 
   282                              <1> .active_skip_done:
   283 000005D5 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   284                              <1> sptinternal
   285 000005D8 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 000005DD FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   293                              <1> sptinternal
   294 000005E1 26807C0400          <1> 	cmp byte [es:si + piType], 0
   295 000005E6 7427                <1> 	je .loop_primary_skip
   296                              <1> 
   297                              <1> %if _MODE
   298 000005E8 F606[0100]04        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   299                              <1> sptinternal -3			; active primary first ?
   300 000005ED 7409                <1> 	jz @F			; no -->
   301 000005EF A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   302                              <1> sptinternal
   303 000005F2 3806[0100]          <1> sptrel	cmp byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   304                              <1> sptinternal
   305 000005F6 7417                <1> 	je .ignoreprimary
   306                              <1> @@:
   307                              <1> 
   308 000005F8 F606[0000]20        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   309                              <1> sptinternal -3			; had a primary partition yet ?
   310 000005FD 740E                <1> 	jz .callprimary		; no, accept it -->
   311 000005FF F606[0100]01        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_primary
   312                              <1> sptinternal -3			; ignore subsequent primary ?
   313 00000604 7509                <1> 	jnz .ignoreprimary	; yes, ignore it -->
   314 00000606 F606[0100]08        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_subsequent_primary_after
   315                              <1> sptinternal -3			; subsequent after ?
   316 0000060B 7502                <1> 	jnz .ignoreprimary
   317                              <1> .callprimary:
   318                              <1> %endif
   319 0000060D 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 0000060F 83C610              <1> 	add si, 16
   324 00000612 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   325                              <1> sptinternal
   326 00000616 72C5                <1> 	jb .loop_primary_parts
   327                              <1> 
   328                              <1> %if _SPT_MULTIPASS
   329                              <1> .end:
   330                              <1> %ifidn _BASE, bp
   331 00000618 89EC                <1> 	mov sp, bp		; restore sp
   332 0000061A 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 0000061B C3                  <1> 	retn			; and bye
   338                              <1> 
   339                              <1> 
   340                              <1> %[_SCANPTAB_PREFIX]scan_logical:
   341 0000061C 55                  <1> 	push bp
   342                              <1> %ifidn _BASE, ss:bx
   343                              <1> 	mov bx, sp
   344                              <1> %elifidn _BASE, bp
   345 0000061D 89E5                <1> 	mov bp, sp
   346                              <1> %endif
   347 0000061F 31FF                <1> 	xor di, di
   348 00000621 57                  <1> 	push di		; [_BASE+di-2]
   349 00000622 57                  <1> 	push di		; [_BASE+di-4]
   350 00000623 57                  <1> 	push di		; [_BASE+di-6]
   351 00000624 57                  <1> 	push di		; [_BASE+di-8]
   352                              <1> 
   353 00000625 31C0                <1> 	xor ax, ax
   354 00000627 31D2                <1> 	xor dx, dx
   355                              <1> %if _MODE
   356 00000629 A3[0000]            <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], ax
   357                              <1> sptinternal
   358                              <1> %endif
   359 0000062C A3[0000]            <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_partition_cycle], ax
   360                              <1> sptinternal
   361 0000062F E88202              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.first
   362 00000632 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 00000637 F606[0100]02        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_traditional_order_logical
   378                              <1> sptinternal -3
   379 0000063C 7451                <1> 	jz .nottraditional
   380                              <1> 
   381 0000063E BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   382                              <1> sptinternal
   383                              <1> .loop_traditional:
   384 00000641 FF06[0000]          <1> sptrel	inc word [ %[_SCANPTAB_PREFIX]load_partition_cycle]
   385                              <1> sptinternal
   386 00000645 7503E9AB01          <1> 	jz .got_partition_cycle
   387                              <1> 
   388 0000064A 268A4404            <1> 	mov al, [es:si + piType]
   389                              <1> 
   390                              <1> %ifidn _BASE, bp
   391 0000064E 31DB                <1> 	xor bx, bx
   392                              <1> %endif
   393 00000650 84C0                <1> 	test al, al
   394 00000652 742D                <1> 	jz .next_traditional
   395 00000654 3C0F                <1> 	cmp al, 0Fh		; extended partition (LBA aware) ?
   396 00000656 7429                <1> 	je .next_traditional	; yes -->
   397 00000658 247F                <1> 	and al, ~80h		; extended partition Linux (85h) ?
   398 0000065A 3C05                <1> 	cmp al, 05h		;  or extended partition DOS (05h) ?
   399 0000065C 7423                <1> 	je .next_traditional	; yes -->
   400                              <1> 
   401                              <1> %ifidn _BASE, bp
   402 0000065E 395BFE              <1> 	cmp word [_BASE+di-2], bx
   403 00000661 7505                <1> 	jne .logical_traditional
   404 00000663 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 00000666 7419                <1> 	je .next_traditional
   411                              <1> .logical_traditional:
   412                              <1> 
   413                              <1> %if _MODE
   414 00000668 F606[0000]20        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   415                              <1> sptinternal -3			; had a logical partition yet ?
   416 0000066D 7407                <1> 	jz .calllogicaltrad	; no, accept it -->
   417 0000066F F606[0000]80        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_logical
   418                              <1> sptinternal -3			; ignore subsequent logical ?
   419 00000674 750B                <1> 	jnz .ignorelogicaltrad	; yes, ignore it -->
   420                              <1> .calllogicaltrad:
   421                              <1> %endif
   422                              <1> 
   423 00000676 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   424                              <1> sptinternal
   425 0000067A 7503E97C01          <1> 	jz .error_too_many_partitions
   426 0000067F 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 00000681 83C610              <1> 	add si, 16		; -> next partition table entry
   432 00000684 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   433                              <1> sptinternal			; was last?
   434 00000688 72B7                <1> 	jb .loop_traditional	; no, loop -->
   435                              <1> 
   436 0000068A 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 0000068F BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   443                              <1> sptinternal
   444                              <1> .loop:
   445 00000692 FF06[0000]          <1> sptrel	inc word [ %[_SCANPTAB_PREFIX]load_partition_cycle]
   446                              <1> sptinternal
   447 00000696 7503E95A01          <1> 	jz .got_partition_cycle
   448                              <1> 
   449 0000069B 268A4404            <1> 	mov al, [es:si + piType]
   450                              <1> 
   451                              <1> %ifidn _BASE, bp
   452 0000069F 31DB                <1> 	xor bx, bx
   453                              <1> %endif
   454 000006A1 84C0                <1> 	test al, al
   455 000006A3 7503E98C00          <1> 	jz .next
   456                              <1> %if _MODE
   457                              <1> %ifidn _BASE, bp
   458 000006A8 395BFE              <1> 	cmp word [_BASE+di-2], bx
   459 000006AB 754B                <1> 	jne .allextended
   460 000006AD 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 000006B0 7546                <1> 	jne .allextended
   467                              <1> 
   468 000006B2 8A26[0000]          <1> sptrel	mov ah, [ %[_SCANPTAB_PREFIX]load_mode ]
   469                              <1> sptinternal
   470 000006B6 3C05                <1> 	cmp al, 5
   471 000006B8 7410                <1> 	je .check
   472 000006BA D0EC                <1> 	shr ah, 1
   473 000006BC D0EC                <1> 	shr ah, 1
   474 000006BE 3C0F                <1> 	cmp al, 15
   475 000006C0 7408                <1> 	je .check
   476 000006C2 D0EC                <1> 	shr ah, 1
   477 000006C4 D0EC                <1> 	shr ah, 1
   478 000006C6 3C85                <1> 	cmp al, 85h
   479 000006C8 7546                <1> 	jne .notextended
   480                              <1> .check:
   481 000006CA 8026[0000]EF        <1> sptrel	clropt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 16
   482                              <1> sptinternal -3			; new outermost extended
   483                              <1> 
   484 000006CF F6C403              <1> 	test ah, 11b
   485 000006D2 7474                <1> 	jz .push		; if it is 00b = all, always accept -->
   486 000006D4 F6C402              <1> 	test ah, 10b		; if prior is NZ but this is zero
   487 000006D7 745B                <1> 	jz .ignoreextended	;  then we have 01b, always ignore -->
   488 000006D9 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 000006DC B401                <1> 	mov ah, 1		; flag 1 for 10b
   491 000006DE 740C                <1> 	jz @F			; if ZR, we have 10b, accept first of all types with 10b
   492                              <1> .firsttype:
   493 000006E0 B402                <1> 	mov ah, 2		; flag 2 for 11b type 5
   494 000006E2 3C0F                <1> 	cmp al, 15
   495 000006E4 7206                <1> 	jb @F
   496 000006E6 B404                <1> 	mov ah, 4		; flag 4 for 11b type 15
   497 000006E8 7402                <1> 	je @F
   498 000006EA B408                <1> 	mov ah, 8		; flag 8 for 11b type 85h
   499                              <1> @@:
   500 000006EC 8426[0000]          <1> sptrel	test byte [ %[_SCANPTAB_PREFIX]load_scan_flags ], ah
   501                              <1> sptinternal			; seen one of those before ?
   502 000006F0 7542                <1> 	jnz .ignoreextended	; yes, ignore -->
   503 000006F2 0826[0000]          <1> sptrel	or byte [ %[_SCANPTAB_PREFIX]load_scan_flags ], ah
   504                              <1> sptinternal			; no, note seen it now
   505 000006F6 EB50                <1> 	jmp .push		; and process extended partition -->
   506                              <1> %endif
   507                              <1> 
   508                              <1> .allextended:
   509                              <1> %if _MODE
   510 000006F8 F606[0000]40        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_nested
   511                              <1> sptinternal -3
   512 000006FD 7407                <1> 	jz @F
   513 000006FF F606[0000]10        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 16
   514                              <1> sptinternal -3
   515 00000704 752E                <1> 	jnz .ignoreextended
   516                              <1> @@:
   517                              <1> %endif
   518 00000706 3C0F                <1> 	cmp al, 0Fh		; extended partition (LBA aware) ?
   519 00000708 743E                <1> 	je .push		; yes -->
   520 0000070A 247F                <1> 	and al, ~80h		; extended partition Linux (85h) ?
   521 0000070C 3C05                <1> 	cmp al, 05h		;  or extended partition DOS (05h) ?
   522 0000070E 7438                <1> 	je .push		; yes -->
   523                              <1> .notextended:
   524                              <1> 
   525                              <1> %ifidn _BASE, bp
   526 00000710 395BFE              <1> 	cmp word [_BASE+di-2], bx
   527 00000713 7505                <1> 	jne .logical
   528 00000715 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 00000718 741A                <1> 	je .next
   535                              <1> .logical:
   536                              <1> 
   537                              <1> %if _MODE
   538 0000071A F606[0000]20        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   539                              <1> sptinternal -3			; had a logical partition yet ?
   540 0000071F 7408                <1> 	jz .calllogical		; no, accept it -->
   541 00000721 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 00000727 750B                <1> 	jnz .ignorelogical	; yes, ignore it -->
   545                              <1> .calllogical:
   546                              <1> %endif
   547                              <1> 
   548 00000729 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   549                              <1> sptinternal
   550 0000072D 7503E9C900          <1> 	jz .error_too_many_partitions
   551 00000732 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 00000734 83C610              <1> 	add si, 16		; -> next partition table entry
   558 00000737 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   559                              <1> sptinternal			; was last?
   560 0000073B 7303E952FF          <1> 	jb .loop		; no, loop -->
   561 00000740 85FF                <1> 	test di, di		; still some on stack?
   562 00000742 756A                <1> 	jnz .pop		; yes, pop
   563                              <1> .end:
   564                              <1> %ifidn _BASE, bp
   565 00000744 89EC                <1> 	mov sp, bp		; restore sp
   566 00000746 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 00000747 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 00000748 56                  <1> 	push si
   618                              <1> .push_check_empty_next:
   619 00000749 83C610              <1> 	add si, 16		; -> next
   620 0000074C 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   621                              <1> sptinternal			; at end?
   622 00000750 7203E98400          <1> 	jae .replace		; yes, no other partitions found, replace -->
   623 00000755 26807C0400          <1> 	cmp byte [es:si + piType], 0	; is this a partition?
   624 0000075A 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 0000075C 31C0                <1> 	xor ax, ax		; sentinel 0 = accept more logicals
   633                              <1> 
   634 0000075E F606[0100]02        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_traditional_order_logical
   635                              <1> sptinternal -3
   636 00000763 750E                <1> 	jnz .traditionalsentinel
   637 00000765 F606[0000]20        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   638                              <1> sptinternal -3			; had a logical partition in this table ?
   639 0000076A 7409                <1> 	jz @F			; no, no need to reset -->
   640 0000076C F606[0000]80        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_logical
   641                              <1> sptinternal -3			; ignore subsequent logical ?
   642 00000771 7402                <1> 	jz @F			; no -->
   643                              <1> .traditionalsentinel:
   644 00000773 B040                <1> 	mov al, 64		; sentinel 64 = no more logicals
   645                              <1> @@:
   646 00000775 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 0000077A 5E                  <1> 	pop si			; restore -> partition table entry
   651                              <1> %if _MODE
   652 0000077B 26FF7408            <1> 	push word [es:si + piStart]
   653 0000077F 268B540A            <1> 	mov dx, word [es:si + piStart + 2]	; get extended partition offset
   654 00000783 01C6                <1> 	add si, ax		; now -> behind partition_table if sentinel set
   655 00000785 58                  <1> 	pop ax
   656                              <1> %endif
   657 00000786 56                  <1> 	push si			; stored at word [_BASE+di-10]
   658 00000787 83EF0A              <1> 	sub di, 10
   659 0000078A FF7308              <1> 	push word [_BASE+di+10-2]
   660 0000078D 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 00000790 0343FC              <1> 	add ax, word [_BASE+di-4]
   666 00000793 1353FE              <1> 	adc dx, word [_BASE+di-2]	; add in root to get absolute sector number
   667                              <1> 
   668 00000796 52                  <1> 	push dx
   669 00000797 50                  <1> 	push ax			; new base
   670                              <1> 
   671                              <1> .replace_common:
   672                              <1> %ifidn _BASE, bp
   673 00000798 395BFE              <1> 	cmp word [_BASE+di-2], bx	; have a (nonzero) root?
   674 0000079B 750B                <1> 	jne .have_root
   675 0000079D 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 000007A0 7506                <1> 	jne .have_root		; yes -->
   682                              <1> 
   683 000007A2 8953FE              <1> 	mov word [_BASE+di-2], dx
   684 000007A5 8943FC              <1> 	mov word [_BASE+di-4], ax	; set root
   685                              <1> .have_root:
   686                              <1> 
   687 000007A8 E80901              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.first
   688 000007AB 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 000007AE 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 000007B3 83C70A              <1> 	add di, 10
   701 000007B6 83C408              <1> 	add sp, 8
   702 000007B9 5E                  <1> 	pop si
   703                              <1> 
   704                              <1> %if _MODE
   705 000007BA 8026[0000]DF        <1> sptrel	clropt [ %[_SCANPTAB_PREFIX]load_scan_flags ], 32
   706                              <1> sptinternal -3			; accept a logical partition in this table
   707 000007BF 81FE[4000]          <1> sptrel	cmp si, 64 + %[_SCANPTAB_PREFIX]partition_table
   708                              <1> sptinternal			; sentinel set ?
   709 000007C3 7208                <1> 	jb @F			; no -->
   710 000007C5 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 000007CA 83EE40              <1> 	sub si, 64		; undo sentinel addition
   713                              <1> @@:
   714                              <1> %endif
   715 000007CD 8B43F8              <1> 	mov ax, word [_BASE+di-8]
   716 000007D0 8B53FA              <1> 	mov dx, word [_BASE+di-6]
   717 000007D3 E8DE00              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.reload
   718 000007D6 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 000007D9 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 000007DE 5E                  <1> 	pop si				; (discard)
   729                              <1> .replace_no_pop:
   730 000007DF 268B4408            <1> 	mov ax, word [es:si + piStart]
   731 000007E3 268B540A            <1> 	mov dx, word [es:si + piStart + 2]	; get extended partition offset
   732 000007E7 0343FC              <1> 	add ax, word [_BASE+di - 4]
   733 000007EA 1353FE              <1> 	adc dx, word [_BASE+di - 2]	; add in root
   734 000007ED 8943F8              <1> 	mov word [_BASE+di - 8], ax
   735 000007F0 8953FA              <1> 	mov word [_BASE+di - 6], dx	; set base
   736                              <1> 
   737 000007F3 EBA3                <1> 	jmp .replace_common
   738                              <1> 
   739                              <1> 
   740                              <1> %if _BOOTCMD_FAIL_ERROR
   741                              <1> .got_partition_cycle:
   742 000007F5 BA[A30F]            <1> sptrel	mov dx, msg.boot_partition_cycle_error
   743                              <1> sptinternal
   744 000007F8 E9D3FB              <1> 	jmp bootcmd.fail
   745                              <1> 
   746                              <1> .error_too_many_partitions:
   747 000007FB BA[800F]            <1> sptrel	mov dx, msg.boot_too_many_partitions_error
   748                              <1> sptinternal
   749 000007FE E9CDFB              <1> 	jmp bootcmd.fail
   750                              <1> %endif
   751                              <1> 
   752                              <1> 
   753                              <1> %if _MODE
   754                              <1> @@:
   755 00000801 C3                  <1> 	retn
   756                              <1> 
   757                              <1> scan_subsequent_primary:
   758 00000802 F606[0100]01        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_ignore_subsequent_primary
   759                              <1> sptinternal -3			; ignore subsequent primary ?
   760 00000807 75F8                <1> 	jnz @B			; yes -->
   761 00000809 F606[0100]08        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_subsequent_primary_after
   762                              <1> sptinternal -3			; subsequent after ?
   763 0000080E 74F1                <1> 	jz @B			; no -->
   764                              <1> 
   765 00000810 55                  <1> 	push bp
   766                              <1> %ifidn _BASE, ss:bx
   767                              <1> 	mov bx, sp
   768                              <1> %elifidn _BASE, bp
   769 00000811 89E5                <1> 	mov bp, sp
   770                              <1> %endif
   771 00000813 31FF                <1> 	xor di, di
   772 00000815 57                  <1> 	push di		; [_BASE+di-2]
   773 00000816 57                  <1> 	push di		; [_BASE+di-4]
   774 00000817 57                  <1> 	push di		; [_BASE+di-6]
   775 00000818 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 00000819 31C0                <1> 	xor ax, ax
   783 0000081B 31D2                <1> 	xor dx, dx
   784                              <1> 
   785                              <1> %if _SPT_MULTIPASS
   786 0000081D A3[0000]            <1> sptrel	mov word [ %[_SCANPTAB_PREFIX]load_scan_flags ], ax
   787                              <1> sptinternal
   788                              <1> %endif
   789                              <1> 
   790 00000820 E89100              <1> 	call %[_SCANPTAB_PREFIX]read_partition_table.reload
   791                              <1> 				; (re)read MBR
   792 00000823 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   793                              <1> sptinternal
   794 00000826 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 0000082A F606[0100]04        <1> sptrel	testopt [ %[_SCANPTAB_PREFIX]load_mode ], mode_active_priority
   802                              <1> sptinternal -3			; active primary first ?
   803 0000082F 742A                <1> 	jz .detect_lowest
   804                              <1> 
   805                              <1> .loop_active_skip:
   806                              <1> 
   807 00000831 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   808                              <1> sptinternal
   809 00000835 268A4404            <1> 	mov al, byte [es:si + piType]
   810 00000839 3C00                <1> 	cmp al, 0
   811 0000083B 7415                <1> 	je .loop_active_skip_skip
   812 0000083D 26803C00            <1> 	cmp byte [es:si + piBoot], 0
   813 00000841 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 00000843 E8F5FB              <1> 	call %[_SCANPTAB_PREFIX]load_is_known
   820 00000846 720A                <1> 	jc .loop_active_skip_skip
   821 00000848 7508                <1> 	jnz .loop_active_skip_skip
   822 0000084A A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   823                              <1> sptinternal
   824 0000084D A2[0100]            <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   825                              <1> sptinternal
   826 00000850 EB37                <1> 	jmp .active_skip_done
   827                              <1> 
   828                              <1> .loop_active_skip_skip:
   829 00000852 83C610              <1> 	add si, 16
   830 00000855 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   831                              <1> sptinternal
   832 00000859 72D6                <1> 	jb .loop_active_skip
   833                              <1> 
   834                              <1> .detect_lowest:
   835 0000085B BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   836                              <1> sptinternal
   837 0000085E C606[0000]00        <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_current_partition], 0
   838                              <1> sptinternal -3
   839                              <1> 
   840                              <1> .loop_lowest:
   841 00000863 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   842                              <1> sptinternal
   843 00000867 268A4404            <1> 	mov al, byte [es:si + piType]
   844 0000086B 3C00                <1> 	cmp al, 0
   845 0000086D 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 0000086F E8C9FB              <1> 	call %[_SCANPTAB_PREFIX]load_is_known
   852 00000872 720A                <1> 	jc .loop_lowest_skip_skip
   853 00000874 7508                <1> 	jnz .loop_lowest_skip_skip
   854 00000876 A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   855                              <1> sptinternal
   856 00000879 A2[0100]            <1> sptrel	mov byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   857                              <1> sptinternal
   858 0000087C EB0B                <1> 	jmp .lowest_skip_done
   859                              <1> 
   860                              <1> .loop_lowest_skip_skip:
   861 0000087E 83C610              <1> 	add si, 16
   862 00000881 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   863                              <1> sptinternal
   864 00000885 72DC                <1> 	jb .loop_lowest
   865 00000887 EB27                <1> 	jmp .end		; none found
   866                              <1> 
   867                              <1> .lowest_skip_done:
   868                              <1> .active_skip_done:
   869 00000889 BE[0000]            <1> sptrel	mov si, %[_SCANPTAB_PREFIX]partition_table
   870                              <1> sptinternal
   871 0000088C 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 00000891 FE06[0000]          <1> sptrel	inc byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   876                              <1> sptinternal
   877 00000895 26807C0400          <1> 	cmp byte [es:si + piType], 0
   878 0000089A 740B                <1> 	je .loop_primary_skip
   879                              <1> 
   880                              <1> %if _MODE
   881 0000089C A0[0000]            <1> sptrel	mov al, byte [ %[_SCANPTAB_PREFIX]load_current_partition]
   882                              <1> sptinternal
   883 0000089F 3806[0100]          <1> sptrel	cmp byte [ %[_SCANPTAB_PREFIX]load_scan_flags + 1], al
   884                              <1> sptinternal
   885 000008A3 7402                <1> 	je .ignoreprimary
   886                              <1> %endif
   887 000008A5 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 000008A7 83C610              <1> 	add si, 16
   892 000008AA 81FE[0000]          <1> sptrel	cmp si, strict word %[_SCANPTAB_PREFIX]partition_table.end
   893                              <1> sptinternal
   894 000008AE 72E1                <1> 	jb .loop_primary_parts
   895                              <1> 
   896                              <1> .end:
   897                              <1> %ifidn _BASE, bp
   898 000008B0 89EC                <1> 	mov sp, bp		; restore sp
   899 000008B2 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 000008B3 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 000008B4 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 000008B5 8B1E[0400]          <1> 	mov bx, word [auxbuff_segorsel]	; bx => auxbuff
   938                              <1> %else
   939                              <1> 	mov bx, word [bp + ldSectorSeg]
   940                              <1> %endif
   941 000008B9 E822FC              <1> 	call %[_SCANPTAB_PREFIX]read_ae_512_bytes
   942                              <1>  assume es:nothing
   943 000008BC 5B                  <1> 	pop bx
   944 000008BD 26813EFE0155AA      <1> 	cmp word [es:510], 0AA55h
   945 000008C4 7518                <1> 	jne .signature_fail
   946 000008C6 1E                  <1> 	 push ds
   947 000008C7 57                  <1> 	 push di
   948 000008C8 56                  <1> 	 push si
   949 000008C9 51                  <1> 	 push cx
   950 000008CA 06                  <1> 	push es
   951 000008CB 1F                  <1> 	pop ds
   952                              <1>  assume ds:nothing
   953 000008CC BEBE01              <1> 	mov si, 510 - 4*16		; ds:si -> partition table in sectorseg
   954                              <1> %if _PARTITION_TABLE_IN_CS
   955 000008CF 0E                  <1> 	push cs
   956                              <1> %else
   957                              <1> 	push ss
   958                              <1> %endif
   959 000008D0 07                  <1> 	pop es
   960                              <1>  assume es:SYSINITGROUP
   961 000008D1 BF[0000]            <1> sptrel	mov di, %[_SCANPTAB_PREFIX]partition_table
   962                              <1> sptinternal				; es:di -> cs:%[_SCANPTAB_PREFIX]partition_table
   963 000008D4 B92000              <1> 	mov cx, 4*16 / 2
   964 000008D7 F3A5                <1> 	rep movsw
   965 000008D9 59                  <1> 	 pop cx
   966 000008DA 5E                  <1> 	 pop si
   967 000008DB 5F                  <1> 	 pop di
   968 000008DC 1F                  <1> 	 pop ds
   969                              <1>  assume ds:SYSINITGROUP
   970 000008DD C3                  <1> 	retn
   971                              <1> 
   972                              <1> 
   973                              <1> %if _BOOTCMD_FAIL_ERROR
   974                              <1> .signature_fail:
   975 000008DE BA[4C0F]            <1> sptrel	mov dx, msg.bootfail_sig_parttable
   976                              <1> sptinternal
   977 000008E1 E9EAFA              <1> 	jmp bootcmd.fail
   978                              <1> %endif
  1865                                  resetdef DEBUG4
  1866                                  
  1867                                  
  1868                                  usesection DOSENTRYINIT
  1869                                  
  1870                                  ;J.K. 9/24/86 We now decide, based on the configurations available so far, what
  1871                                  ;code or data we need to keep as a stay resident code.	The following table
  1872                                  ;shows the configurations under consideration.	They are listed in the order
  1873                                  ;of their current position memory.
  1874                                  ;Configuration will be done in two ways:
  1875                                  ;First, we are going to set "Static configuration".  Static configuration will
  1876                                  ;consider from basic configuration to ENDOF96TPI configuration.  The result
  1877                                  ;of static configuration will be the address the Dynamic configuration will
  1878                                  ;use to start with.
  1879                                  ;Secondly, "Dynamic cofiguration" will be performed.  Dynamic configuration
  1880                                  ;involves possible relocation of CODE or DATA.	Dynamic configuration routine
  1881                                  ;will take care of BDSM tables and AT ROM Fix module thru K09 suspend/resume
  1882                                  ;code individually.  After these operation, FINAL_DOS_LOCATION will be set.
  1883                                  ;This will be the place SYSINIT routine will relocate MSDOS module for good.
  1884                                  ;
  1885                                  ;   1.	 BASIC CONFIGURATION FOR IBMBIO (EndFloppy, EndSwap)
  1886                                  ;   2.	 ENDONEHARD
  1887                                  ;   3.	 ENDTWOHARD
  1888                                  ;   4.	 END96TPI	;a system that supports "Change Line Error"
  1889                                  ;   5.	 End of BDSM	;BDSM tables for mini disks.
  1890                                  ;   6.	 ENDATROM	;Some of AT ROM fix module.
  1891                                  ;   7.	 ENDCMOSCLOCKSET;Supporting program for CMOS clock write.
  1892                                  ;   8.	 ENDK09 	;K09 CMOS Clock module to handle SUSPEND/RESUME operation.
  1893                                  ;
  1894                                  ; lDOS: Only END96TPI and ENDATROM are still used of all these.
  1895                                  ;  END96TPI and ENDFLOPPY are equal now, so only the first one
  1896                                  ;  is still used. (END96TPI is in ms96tpi.nas included by
  1897                                  ;  msbio2.nas, which aligns to a paragraph boundary before
  1898                                  ;  mshard.nas's IBM_DISK_IO. The latter is the start of the
  1899                                  ;  "AT ROM fix module" that ends at ENDATROM.)
  1900                                  ; Update lDOS 2025 September: Instead of END96TPI now the label
  1901                                  ;  DOSENTRY_INIT_START is used (in mshard.nas).
  1902                                  ; The UPBs (aka BDS tables) are handled later by INITUPB (in
  1903                                  ;  SYSINIT segment, source in this file) and are allocated
  1904                                  ;  using an S MCB as the DOS is already available then. (The
  1905                                  ;  UPBs are relocated into HMA, UMA, or LMA later.)
  1906                                  ; The CMOS and K09 code is now in the DOSCODE segment, except
  1907                                  ;  for the i6C entrypoint (in entry.asm).
  1908                                  
  1909                                  ;J.K. 9/24/86.
  1910                                  
  1911                                  STATIC_CONFIGURE:
  1912                                   assume ds:nothing, es:nothing, ss:nothing
  1913                                   extern DOSENTRY_INIT_START
  1914 000003C2 B8[0000]                	mov	ax, DOSENTRY_INIT_START
  1915 000003C5 E83003                  	call dosentry_init_get_ds_dosbiodata
  1916                                   assume ds:DOSGROUP
  1917                                  fHave96 equ FHAVE96	; NASM port label
  1918 000003C8 803E[0000]00            	cmp	byte [fHave96], 0		;Is change line support there?
  1919                                  Config96 equ CONFIG96	; NASM port label
  1920 000003CD 7502                    	jnz	Config96		;Yes.
  1921                                  
  1922                                  Basic_Floppy:
  1923                                  	; mov	ax, offset ENDFLOPPY
  1924                                  		; ldos: do leave DOSENTRY data up to END96TPI resident
  1925                                  		; ldos: ENDFLOPPY equals END96TPI now that the code
  1926                                  		;  has been moved out of the DOSENTRY section.
  1927                                  Dynamic_Configure equ DYNAMIC_CONFIGURE	; NASM port label
  1928 000003CF EB24                    	jmp	Dynamic_Configure	;static configuration is done!
  1929                                  
  1930                                  ;
  1931                                  ; KEEP THE 96TPI CODE
  1932                                  ;
  1933                                  CONFIG96:
  1934                                  ;
  1935                                  ; SAVE OLD INT 13 VECTOR
  1936                                  ;
  1937 000003D1 0E                      	push cs
  1938 000003D2 1F                      	pop ds
  1939                                   assume ds:DOSENTRYGROUP
  1940 000003D3 1E                      	push ds
  1941 000003D4 07                      	pop es
  1942                                   assume ds:DOSENTRYGROUP, es:DOSENTRYGROUP
  1943                                  
  1944 000003D5 50                      	PUSH	AX
  1945 000003D6 1E                      	PUSH	DS
  1946 000003D7 31C0                    	XOR	AX,AX
  1947 000003D9 8ED8                    	MOV	DS,AX
  1948                                   assume ds:IVT
  1949                                  
  1950 000003DB A14C00                  	MOV	AX,[4 * 13H]
  1951 000003DE 26A3[0000]              	MOV	WORD PTR [es:REAL13],AX
  1952 000003E2 A14E00                  	MOV	AX,[4 * 13H+2]
  1953 000003E5 26A3[0200]              	MOV	WORD PTR [es:REAL13+2],AX
  1954                                  ;
  1955                                  ; INSERT NEW VECTOR
  1956                                  ;
  1957                                  extern ms96tpi_i13
  1958 000003E9 C7064C00[0000]          	MOV	WORD PTR [4 * 13H],OFFSET ms96tpi_i13
  1959 000003EF 8C064E00                	MOV	[4 * 13H + 2], es
  1960                                  
  1961 000003F3 1F                      	POP	DS
  1962                                   assume ds:DOSENTRYGROUP
  1963 000003F4 58                      	POP	AX
  1964                                  
  1965                                  DYNAMIC_CONFIGURE:
  1966 000003F5 1E                      	push ds
  1967 000003F6 07                      	pop es
  1968                                   assume es:DOSENTRYGROUP
  1969 000003F7 FC                      	cld					;clear direction
  1970                                  
  1971                                  CheckATROM:
  1972 000003F8 E80D03                  	call	Get_Para_Offset			;For dynamic allocation, we are
  1973                                  						;going to use offset address that
  1974                                  						;is in paragraph boundary.
  1975                                  
  1976                                  
  1977 000003FB E8FA02                  	call dosentry_init_get_ds_dosbiodata
  1978                                   assume ds:DOSGROUP
  1979 000003FE 803E[0000]FC            	cmp	byte [Model_Byte], 0FCh		;AT ?
  1980 00000403 753F                    	jnz	CheckCMOSClock
  1981                                  
  1982 00000405 50                      	push ax
  1983 00000406 B280                    	mov	DL, 80h			; tell rom bios to look at hard drives
  1984 00000408 B408                    	mov	AH, 8h			; set command to get drive parameter
  1985 0000040A F9                      	stc
  1986 0000040B CD13                    	int	13h			; call ROM-BIOS to get number of drives
  1987 0000040D 58                      	pop ax
  1988 0000040E 7234                    	jc	CheckCMOSClock
  1989 00000410 84D2                    	test dl, dl			; No hard file?
  1990 00000412 7430                    	jz	CheckCMOSClock
  1991                                  
  1992 00000414 BE00F0                  	mov	si, 0F000h
  1993 00000417 8EC6                    	mov	es, si			       ;ES -> BIOS segment
  1994                                  	assume	es:nothing		       ;
  1995 00000419 0E                      	push cs
  1996 0000041A 1F                      	pop ds
  1997                                   assume ds:DOSENTRYGROUP
  1998 0000041B BE[0100]                	mov	si, offset BIOS_DATE	       ;
  1999 0000041E BFF5FF                  	mov	di, 0FFF5H		       ;ROM BIOS string is at F000:FFF5
  2000                                  Cmpbyte:				       ;Only patch ROM for bios dated 01/10/84
  2001 00000421 A6                      	cmpsb				       ;
  2002 00000422 7520                    	jnz	CheckCMOSClock		       ;
  2003 00000424 807CFF00                	cmp	byte ptr [si-1],0	       ;
  2004 00000428 75F7                    	jnz	Cmpbyte 		       ;
  2005                                  SetRomCode:				       ;Now we have to install ROM fix
  2006                                  					       ;AX is the address to move.
  2007 0000042A 1E                      	push ds
  2008 0000042B 07                      	pop es
  2009                                   assume es:DOSENTRYGROUP
  2010                                  
  2011 0000042C A3[0000]                	mov	word ptr [ORIG13], ax
  2012 0000042F 8C1E[0200]              	mov	word ptr [ORIG13+2], ds		;set new ROM bios int 13 vector
  2013 00000433 B9[0000]                	mov	cx, offset ENDATROM
  2014 00000436 BE[0000]                	mov	si, offset IBM_DISK_IO
  2015 00000439 29F1                    	sub	cx, si				;size of AT ROM FIX module
  2016 0000043B 89C7                    	mov	di, ax				;destination
  2017 0000043D F3A4                    	rep	movsb				;relocate it
  2018 0000043F 89F8                    	mov	ax, di				;new ending address
  2019 00000441 E8C402                  	call	Get_Para_Offset 		;in AX
  2020                                  
  2021                                  CheckCMOSClock:
  2022 00000444 0E                      	push cs
  2023 00000445 1F                      	pop ds
  2024                                   assume ds:DOSENTRYGROUP
  2025 00000446 1E                      	push	ds
  2026 00000447 07                      	pop	es				;set ES to CODE seg
  2027                                   assume ds:DOSENTRYGROUP, es:DOSENTRYGROUP
  2028                                  
  2029                                  CheckK09:
  2030                                  ;SB33025****************************************************************
  2031 00000448 50                      	push	ax			;save ax		     ;SB  ;3.30*
  2032 00000449 06                      	push es
  2033                                  
  2034 0000044A B4C0                    	mov ah, 0C0h
  2035 0000044C F9                      	stc
  2036 0000044D CD15                    	int 15h
  2037                                   assume es:nothing
  2038 0000044F 7210                    	jc .no_k09_if_CY
  2039 00000451 26F6470508              	test byte [es:bx + 5], 1 << 3
  2040 00000456 F9                      	stc
  2041 00000457 7408                    	jz .no_k09_if_CY
  2042                                  
  2043 00000459 B80041                  	mov	ax,4100h		;Q: is it a K09 	     ;SB  ;3.30*
  2044 0000045C B300                    	mov	bl,0			;			     ;SB  ;3.30*
  2045 0000045E F9                      	stc
  2046 0000045F CD15                    	int	15h			;			     ;SB  ;3.30*
  2047                                  ;SB33025****************************************************************
  2048                                  .no_k09_if_CY:
  2049 00000461 07                      	pop es
  2050                                   assume es:DOSENTRYGROUP
  2051 00000462 58                      	pop	ax
  2052 00000463 721A                    	jc	CONFIGDONE
  2053                                  
  2054 00000465 50                      	push	ax
  2055 00000466 1E                      	push	ds
  2056 00000467 E88E02                  	call dosentry_init_get_ds_dosbiodata
  2057                                   assume ds:DOSGROUP
  2058                                  fHaveK09 equ FHAVEK09	; NASM port label
  2059 0000046A C606[0000]01            	mov	byte [fHaveK09], 1			;remember we have a K09 type
  2060 0000046F 31C0                    	xor	ax,ax
  2061 00000471 8ED8                    	mov	ds, ax
  2062                                   assume ds:IVT
  2063                                  
  2064                                   extern i6C
  2065 00000473 C706B001[0000]          	mov	word ptr [4 * 6Ch], i6C	;new INT 6Ch handler
  2066 00000479 8C0EB201                	mov	[4 * 6Ch +2], cs
  2067                                  
  2068 0000047D 1F                      	pop	ds
  2069                                   assume ds:DOSENTRYGROUP
  2070 0000047E 58                      	pop	ax				;restore the ending address
  2071                                  
  2072                                  ; SET UP CONFIG STUFF FOR SYSINIT
  2073                                  
  2074                                  CONFIGDONE:			;AX is final ending address of MSBIO.
  2075 0000047F BA[ssss]                	MOV	DX,SYSINITSEG
  2076 00000482 8EDA                    	MOV	DS,DX
  2077                                   assume ds:SYSINITGROUP
  2078                                  
  2079                                  	; SUB	AX,OFFSET START$	; (zero)
  2080 00000484 83C00F                  	ADD	AX,15
  2081 00000487 D1D8                    	RCR	AX,1
  2082 00000489 D1E8                    	SHR	AX, 1
  2083 0000048B D1E8                    	SHR	AX, 1
  2084 0000048D D1E8                    	SHR	AX, 1
  2085 0000048F 05[ssss]                	add ax, DOSENTRY
  2086 00000492 A3[0000]                	MOV	[behind_dosentry_segment], AX
  2087 00000495 2EA0[0000]              	mov al, [cs:DRVMAX]
  2088 00000499 A2[0000]                	mov [HARDNUM], al		; REMEMBER WHICH DRIVE IS HARD DISK
  2089                                  
  2090                                  	MESSAGE FTESTINIT,<"FINAL DOS LOCATION IS ">
  2091                                  	MNUM	FTESTINIT,FINAL_DOS_LOCATION
  2092                                  	MESSAGE FTESTINIT,<CR,LF>
  2093 0000049C 0E                      	PUSH	CS
  2094 0000049D 1F                      	POP	DS
  2095                                  
  2096                                   assume ds:DOSENTRYGROUP, es:nothing
  2097                                  
  2098                                  %if 0
  2099                                  call_purge_96tpi:
  2100                                  	CMP	BYTE [FHAVE96],0
  2101                                  	JNZ	.no
  2102                                  	CALL	PURGE_96TPI		;MJB001 ELIMINATE CALLS TO 96TPI HOOHAH
  2103                                  .no
  2104                                  %endif
  2105                                  
  2106                                  relocate_sysinit_and_early_dos:
  2107                                  	MESSAGE FTESTINIT,<"SYSINIT",CR,LF>
  2108                                  	ZWAIT
  2109                                  	MESSAGE FTESTINIT,<"ON TO SYSINIT...",CR,LF>
  2110                                  
  2111                                  extern SYSSIZE, afterdosdatalabel, afterdoscodelabel, doscode_start, doscode_mcb
  2112                                  
  2113 0000049E B8[1F00]                	MOV AX, SYSSIZE + 16 + 15 wrt SYSINITSEG
  2114                                   wlcalc word_shr_4?syssize, equ $ - 2
  2115 000004A1 91                      	xchg cx, ax
  2116                                  %if _RELOCATEDOSCODE
  2117 000004A2 B8[0F00]                	mov ax, afterdoscodelabel + 15 wrt DOSCODEGROUP
  2118                                   wlcalc word_shr_4?codesize, equ $ - 2
  2119                                  %else
  2120                                  	xor ax, ax
  2121                                  %endif
  2122                                  
  2123 000004A5 BB[ssss]                	mov bx, SYSINITSEG
  2124 000004A8 8EDB                    	mov ds, bx
  2125                                   assume ds:SYSINITGROUP
  2126 000004AA 8B16[0000]              	mov dx, [MEMORY_SIZE]
  2127 000004AE 29CA                    	sub dx, cx			; => SYSINIT destination
  2128 000004B0 722A                    	jc .oom
  2129 000004B2 83EA18                  	sub dx, paras(SYSINITSTACK)	; leave stack buffer
  2130 000004B5 7225                    	jc .oom
  2131 000004B7 89D6                    	mov si, dx
  2132 000004B9 83EA01                  	sub dx, 1			; leave buffer for first UMCB,
  2133                                  					;  => SYSINIT MCB destination
  2134 000004BC 761E                    	jbe .oom
  2135 000004BE 29C2                    	sub dx, ax			; => early DOSCODE destination
  2136 000004C0 89D7                    	mov di, dx
  2137 000004C2 7218                    	jc .oom
  2138 000004C4 01C1                    	add cx, ax
  2139                                  
  2140 000004C6 B8[0F00]                	mov ax, afterdosdatalabel + 15 wrt DOSSTART
  2141                                   wlcalc word_shr_4?datasize, equ $ - 2
  2142 000004C9 29C2                    	sub dx, ax			; => early DOSDATA destination
  2143 000004CB 720F                    	jc .oom
  2144 000004CD 52                      	push dx
  2145 000004CE 83EA01                  	sub dx, 1			; => DOSDATA S MCB
  2146 000004D1 7209                    	jc .oom
  2147 000004D3 01C1                    	add cx, ax
  2148 000004D5 41                      	inc cx
  2149                                  
  2150                                  		; Note: This check is only valid if there is no
  2151                                  		;  data to still be used between the relocate
  2152                                  		;  block and the end of the DOSENTRY section.
  2153                                  		; This is now true with DOSDATA being relocated.
  2154 000004D6 81FA[BA05]              	cmp dx, strict word end_of_dosentry_init_late + 15
  2155                                   wlcalc word_shr_4?entrysize, equ $ - 2
  2156                                   wlcalc word_pass_1_seg_DOSENTRY?entrysize, equ $ - 2
  2157 000004DA 7316                    	jae @F
  2158                                  
  2159                                  .oom:
  2160                                  dosentry_init_oom:
  2161 000004DC BE[AB05]                	mov si, dosentry_init_msg.oom	; access with cs
  2162 000004DF B40E                    	mov ah, 0Eh
  2163 000004E1 BB0700                  	mov bx, 7
  2164 000004E4 A9                      	db __TEST_IMM16			; skip int
  2165                                  .msgloop:
  2166 000004E5 CD10                    	int 10h
  2167 000004E7 2EAC                    	cs lodsb
  2168 000004E9 84C0                    	test al, al
  2169 000004EB 75F8                    	jnz .msgloop
  2170                                  .halt:
  2171 000004ED CC                      	int3
  2172 000004EE FB                      	sti
  2173 000004EF F4                      	hlt
  2174 000004F0 EBFB                    	jmp .halt
  2175                                  
  2176                                  @@:
  2177 000004F2 5D                      	pop bp
  2178 000004F3 FA                      	cli
  2179                                  	align 2, nop
  2180                                  .stack:
  2181 000004F4 0E                      	push cs
  2182 000004F5 17                      	pop ss
  2183 000004F6 BC[F404]                	mov sp, .stack
  2184                                   assume ss:DOSENTRYGROUP
  2185                                  %if (.stack - INIT) < 512
  2186                                   %error Too small DOSENTRY init stack
  2187                                  %endif
  2188 000004F9 B8[ssss]                	mov ax, DOSDATAMCB
  2189 000004FC E82000                  	call dosentry_init_movp
  2190                                  
  2191 000004FF 31C0                    	xor ax, ax
  2192 00000501 8ED8                    	mov ds, ax
  2193                                   assume ds:IVT
  2194 00000503 95                      	xchg ax, bp
  2195 00000504 A3C600                  	mov word [31h * 4 + 2], ax	; init => DOSDATA
  2196                                  %if _RELOCATEDOSCODE
  2197 00000507 8ED8                    	mov ds, ax
  2198                                   assume ds:DOSGROUP
  2199 00000509 893E[0000]              	mov word [dosdata_to_doscode], di
  2200 0000050D B8[ssss]                	mov ax, DOSENTRY
  2201 00000510 8ED8                    	mov ds, ax
  2202                                   assume ds:DOSENTRYGROUP
  2203                                   extern ..@dosentry_doscode_segment
  2204 00000512 893E[0000]              	mov word [..@dosentry_doscode_segment], di
  2205                                  %endif
  2206 00000516 FB                      	sti
  2207                                  
  2208                                   extern GOINIT
  2209 00000517 89D1                    	mov cx, dx			; => DOSDATA S MCB
  2210 00000519 B8[0000]                	mov ax, GOINIT
  2211 0000051C 56                      	push si
  2212 0000051D 50                      	push ax
  2213 0000051E CB                      	retf
  2214                                  
  2215                                  INIT	ENDP
  2216                                  
  2217                                  
  2218                                  		; Move paragraphs
  2219                                  		;
  2220                                  		; INP:	ax:0-> source
  2221                                  		;	dx:0-> destination
  2222                                  		;	cx = number of paragraphs
  2223                                  		; CHG:	-
  2224                                  		; Note:	Doesn't work correctly on HMA; doesn't always wrap to LMA either.
  2225                                  		;	Do not provide a wrapped/HMA source or destination!
  2226                                  dosentry_init_movp:
  2227                                   assume ds:nothing, es:nothing, ss:nothing
  2228 0000051F 51                      	push cx
  2229 00000520 1E                      	push ds
  2230 00000521 56                      	push si
  2231 00000522 06                      	push es
  2232 00000523 57                      	push di
  2233                                  
  2234 00000524 39D0                    	cmp ax, dx		; source above destination ?
  2235 00000526 770A                    	ja .up			; yes, move up (forwards) -->
  2236 00000528 747B                    	je .return		; same, no need to move -->
  2237 0000052A 50                      	push ax
  2238 0000052B 01C8                    	add ax, cx		; (expected not to carry)
  2239 0000052D 39D0                    	cmp ax, dx		; end of source is above destination ?
  2240 0000052F 58                      	pop ax
  2241 00000530 7730                    	ja .down		; yes, move from top down -->
  2242                                  	; Here, the end of source is below-or-equal the destination,
  2243                                  	;  so they do not overlap. In this case we prefer moving up.
  2244                                  
  2245                                  .up:
  2246 00000532 50                      	push ax
  2247 00000533 52                      	push dx
  2248                                  .uploop:
  2249 00000534 8ED8                    	mov ds, ax
  2250 00000536 8EC2                    	mov es, dx
  2251                                   assume ds:nothing, es:nothing
  2252 00000538 31FF                    	xor di, di
  2253 0000053A 31F6                    	xor si, si		; -> start of segment
  2254 0000053C 81E90010                	sub cx, 1000h		; 64 KiB left ?
  2255 00000540 7610                    	jbe .uplast		; no -->
  2256 00000542 51                      	push cx
  2257 00000543 B90080                  	mov cx, 10000h /2
  2258 00000546 F3A5                    	rep movsw		; move 64 KiB
  2259 00000548 59                      	pop cx
  2260 00000549 050010                  	add ax, 1000h
  2261 0000054C 81C20010                	add dx, 1000h		; -> next segment
  2262 00000550 EBE2                    	jmp short .uploop	; proceed for more -->
  2263                                  .uplast:
  2264 00000552 81C10010                	add cx, 1000h		; restore counter
  2265 00000556 D1E1                    	shl cx, 1
  2266 00000558 D1E1                    	shl cx, 1
  2267 0000055A D1E1                    	shl cx, 1		; *8, paragraphs to words
  2268 0000055C F3A5                    	rep movsw		; move last part
  2269 0000055E 5A                      	pop dx
  2270 0000055F 58                      	pop ax
  2271 00000560 EB43                    	jmp short .return
  2272                                  
  2273                                  .down:
  2274 00000562 FD                      	std			; _AMD_ERRATUM_109_WORKAROUND as below
  2275                                  .dnloop:
  2276 00000563 81E90010                	sub cx, 1000h		; 64 KiB left ?
  2277 00000567 761A                    	jbe .dnlast		; no -->
  2278 00000569 50                      	push ax
  2279 0000056A 52                      	push dx
  2280 0000056B 01C8                    	add ax, cx
  2281 0000056D 01CA                    	add dx, cx
  2282 0000056F 8ED8                    	mov ds, ax		; -> 64 KiB not yet moved
  2283 00000571 8EC2                    	mov es, dx
  2284                                   assume ds:nothing, es:nothing
  2285 00000573 5A                      	pop dx
  2286 00000574 58                      	pop ax
  2287 00000575 BFFEFF                  	mov di, -2
  2288 00000578 89FE                    	mov si, di		; moved from last word down
  2289 0000057A 51                      	push cx
  2290 0000057B B90080                  	mov cx, 10000h /2
  2291 0000057E F3A5                    	rep movsw		; move 64 KiB
  2292 00000580 59                      	pop cx
  2293 00000581 EBE0                    	jmp short .dnloop	; proceed for more -->
  2294                                  .dnlast:
  2295 00000583 81C10010                	add cx, 1000h		; restore counter
  2296 00000587 D1E1                    	shl cx, 1
  2297 00000589 D1E1                    	shl cx, 1
  2298 0000058B D1E1                    	shl cx, 1		; *8, paragraphs to words
  2299 0000058D 89CF                    	mov di, cx
  2300 0000058F 4F                      	dec di
  2301 00000590 D1E7                    	shl di, 1		; words to offset, -> last word
  2302 00000592 89FE                    	mov si, di
  2303 00000594 8ED8                    	mov ds, ax
  2304 00000596 8EC2                    	mov es, dx		; first segment correct
  2305                                   assume ds:nothing, es:nothing
  2306                                  
  2307                                  
  2308                                  	numdef AMD_ERRATUM_109_WORKAROUND, 1
  2309                                  %if 0
  2310                                  
  2311                                  Jack R. Ellis pointed out this erratum:
  2312                                  
  2313                                  Quoting from https://www.amd.com/system/files/TechDocs/25759.pdf page 69:
  2314                                  
  2315                                  109   Certain Reverse REP MOVS May Produce Unpredictable Behavior
  2316                                  
  2317                                  Description
  2318                                  
  2319                                  In certain situations a REP MOVS instruction may lead to
  2320                                  incorrect results. An incorrect address size, data size
  2321                                  or source operand segment may be used or a succeeding
  2322                                  instruction may be skipped. This may occur under the
  2323                                  following conditions:
  2324                                  
  2325                                  * EFLAGS.DF=1 (the string is being moved in the reverse direction).
  2326                                  
  2327                                  * The number of items being moved (RCX) is between 1 and 20.
  2328                                  
  2329                                  * The REP MOVS instruction is preceded by some microcoded instruction
  2330                                    that has not completely retired by the time the REP MOVS begins
  2331                                    execution. The set of such instructions includes BOUND, CLI, LDS,
  2332                                    LES, LFS, LGS, LSS, IDIV, and most microcoded x87 instructions.
  2333                                  
  2334                                  Potential Effect on System
  2335                                  
  2336                                  Incorrect results may be produced or the system may hang.
  2337                                  
  2338                                  Suggested Workaround
  2339                                  
  2340                                  Contact your AMD representative for information on a BIOS update.
  2341                                  
  2342                                  %endif
  2343                                  
  2344                                  %if _AMD_ERRATUM_109_WORKAROUND
  2345 00000598 E308                    	jcxz @FF
  2346 0000059A 83F914                  	cmp cx, 20
  2347 0000059D 7703                    	ja @FF
  2348                                  @@:
  2349 0000059F A5                      	movsw
  2350 000005A0 E2FD                    	loop @B
  2351                                  @@:
  2352                                  %endif
  2353 000005A2 F3A5                    	rep movsw		; move first part
  2354 000005A4 FC                      	cld
  2355                                  .return:
  2356 000005A5 5F                      	pop di
  2357 000005A6 07                      	pop es
  2358                                   assume es:nothing
  2359 000005A7 5E                      	pop si
  2360 000005A8 1F                      	pop ds
  2361                                   assume ds:nothing
  2362 000005A9 59                      	pop cx
  2363 000005AA C3                      	retn
  2364                                  
  2365                                  end_of_dosentry_init_late:
  2366                                  
  2367                                  dosentry_init_msg:
  2368 000005AB 6C444F53206C6F6164-     .oom:	asciz "lDOS load error: Out of memory for SYSINIT relocation.",13,10
  2368 000005B4 206572726F723A204F-
  2368 000005BD 7574206F66206D656D-
  2368 000005C6 6F727920666F722053-
  2368 000005CF 5953494E4954207265-
  2368 000005D8 6C6F636174696F6E2E-
  2368 000005E1 0D0A00             
  2369                                  
  2370                                  
  2371                                   global cmdline_noop, cmdline_checkdebugger, cmdline_verbose, cmdline_scanmode
  2372                                   global cmdline_haltflag
  2373                                  cmdline_noop:
  2374 000005E4 C3                      	retn
  2375                                  
  2376                                  
  2377                                  cmdline_error:
  2378                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2379                                   extern invalid_number
  2380 000005E5 BE[0000]                	mov si, invalid_number
  2381 000005E8 BB0700                  	mov bx, 7
  2382 000005EB A9                      	db __TEST_IMM16		; skip int
  2383                                  @@:
  2384 000005EC CD10                    	int 10h
  2385 000005EE AC                      	lodsb
  2386 000005EF B40E                    	mov ah, 0Eh
  2387 000005F1 84C0                    	test al, al
  2388 000005F3 75F7                    	jnz @B
  2389 000005F5 3E8B7600                	mov si, word [ds:bp]	; -> command name
  2390 000005F9 A9                      	db __TEST_IMM16		; skip int
  2391                                  @@:
  2392 000005FA CD10                    	int 10h
  2393 000005FC AC                      	lodsb
  2394 000005FD B40E                    	mov ah, 0Eh
  2395 000005FF 84C0                    	test al, al
  2396 00000601 75F7                    	jnz @B
  2397                                  @@:
  2398 00000603 B8220E                  	mov ax, 0E00h + '"'
  2399 00000606 CD10                    	int 10h
  2400 00000608 B80D0E                  	mov ax, 0E00h + 13
  2401 0000060B CD10                    	int 10h
  2402 0000060D B80A0E                  	mov ax, 0E00h + 10
  2403 00000610 CD10                    	int 10h
  2404 00000612 C3                      	retn
  2405                                  
  2406                                  
  2407                                  		; INP:	ds:si -> after number
  2408                                  		; OUT:	ZR if NUL reached
  2409                                  		;	NZ if not NUL,
  2410                                  		;	 ds:si -> first non-blank, non-comma, non-NUL
  2411                                  		;	 al = byte [ds:si]
  2412                                  cmdline_next:
  2413                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2414                                  .:
  2415 00000613 AC                      	lodsb
  2416 00000614 3C20                    	cmp al, 32
  2417 00000616 74FB                    	je .
  2418 00000618 3C09                    	cmp al, 9
  2419 0000061A 74F7                    	je .
  2420 0000061C 3C2C                    	cmp al, ','
  2421 0000061E 74F3                    	je .
  2422 00000620 4E                      	dec si
  2423 00000621 84C0                    	test al, al
  2424 00000623 C3                      	retn
  2425                                  
  2426                                  
  2427                                  		; INP:	si -> past an optional equals sign and blanks
  2428                                  		;	di -> -> command name
  2429                                  		; CHG:	ax, si, di, cx, bx, dx, bp
  2430                                  		; STT:	ds = es => SYSINIT
  2431                                  		;	cs => DOSENTRY
  2432                                  cmdline_checkdebugger:
  2433                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2434 00000624 89FD                    	mov bp, di
  2435                                  .loop:
  2436 00000626 E8B000                  	call parsenumber
  2437 00000629 72BA                    	jc cmdline_error
  2438 0000062B 84F6                    	test dh, dh
  2439 0000062D 75B6                    	jnz cmdline_error
  2440 0000062F 80FB01                  	cmp bl, 1
  2441 00000632 7209                    	jb .or
  2442 00000634 740E                    	je .clr
  2443                                  .replace:
  2444 00000636 2E8816[0000]            	mov byte [cs:checkdebugger], dl
  2445 0000063B EB0E                    	jmp .next
  2446                                  
  2447                                  .or:
  2448 0000063D 2E0816[0000]            	or byte [cs:checkdebugger], dl
  2449 00000642 EB07                    	jmp .next
  2450                                  
  2451                                  .clr:
  2452 00000644 F6D2                    	not dl
  2453 00000646 2E2016[0000]            	and byte [cs:checkdebugger], dl
  2454                                  .next:
  2455 0000064B E8C5FF                  	call cmdline_next
  2456 0000064E 75D6                    	jnz .loop
  2457 00000650 C3                      	retn
  2458                                  
  2459                                  
  2460                                  		; INP:	si -> past an optional equals sign and blanks
  2461                                  		;	di -> -> command name
  2462                                  		; CHG:	ax, si, di, cx, bx, dx, bp
  2463                                  		; STT:	ds = es => SYSINIT
  2464                                  		;	cs => DOSENTRY
  2465                                  cmdline_verbose:
  2466                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2467 00000651 89FD                    	mov bp, di
  2468                                  .loop:
  2469 00000653 E88300                  	call parsenumber
  2470 00000656 728D                    	jc cmdline_error
  2471 00000658 84F6                    	test dh, dh
  2472 0000065A 7589                    	jnz cmdline_error
  2473 0000065C 80FB01                  	cmp bl, 1
  2474 0000065F 7208                    	jb .or
  2475 00000661 740C                    	je .clr
  2476                                  .replace:
  2477 00000663 8816[0000]              	mov byte [verbose_mode], dl
  2478 00000667 EB0C                    	jmp .next
  2479                                  
  2480                                  .or:
  2481 00000669 0816[0000]              	or byte [verbose_mode], dl
  2482 0000066D EB06                    	jmp .next
  2483                                  
  2484                                  .clr:
  2485 0000066F F6D2                    	not dl
  2486 00000671 2016[0000]              	and byte [verbose_mode], dl
  2487                                  .next:
  2488 00000675 E89BFF                  	call cmdline_next
  2489 00000678 75D9                    	jnz .loop
  2490 0000067A C3                      	retn
  2491                                  
  2492                                  
  2493                                  cmdline_scanmode:
  2494                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2495 0000067B 89FD                    	mov bp, di
  2496                                  .loop:
  2497                                   extern sysinit_cmdline_scanmode_keyword
  2498 0000067D 9A[0000][ssss]          	call far sysinit_cmdline_scanmode_keyword
  2499                                  					; ! call far into unrelocated SYSINIT
  2500 00000682 730F                    	jnc .replace
  2501 00000684 E85200                  	call parsenumber
  2502 00000687 7303E959FF              	jc cmdline_error
  2503 0000068C 80FB01                  	cmp bl, 1
  2504 0000068F 7208                    	jb .or
  2505 00000691 740C                    	je .clr
  2506                                  .replace:
  2507 00000693 8916[0000]              	mov word [load_mode], dx
  2508 00000697 EB0C                    	jmp .next
  2509                                  
  2510                                  .or:
  2511 00000699 0916[0000]              	or word [load_mode], dx
  2512 0000069D EB06                    	jmp .next
  2513                                  
  2514                                  .clr:
  2515 0000069F F7D2                    	not dx
  2516 000006A1 2116[0000]              	and word [load_mode], dx
  2517                                  .next:
  2518 000006A5 E86BFF                  	call cmdline_next
  2519 000006A8 75D3                    	jnz .loop
  2520 000006AA C3                      	retn
  2521                                  
  2522                                  
  2523                                  		; INP:	si -> past an optional equals sign and blanks
  2524                                  		;	di -> -> command name
  2525                                  		; CHG:	ax, si, di, cx, bx, dx, bp
  2526                                  		; STT:	ds = es => SYSINIT
  2527                                  		;	cs => DOSENTRY
  2528                                  cmdline_haltflag:
  2529                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2530 000006AB 89FD                    	mov bp, di
  2531                                  .loop:
  2532 000006AD E82900                  	call parsenumber
  2533 000006B0 7303E930FF              	jc cmdline_error
  2534 000006B5 E84000                  	call dosentry_init_get_ds_dosdata
  2535                                   assume ds:DOSGROUP
  2536 000006B8 80FB01                  	cmp bl, 1
  2537 000006BB 7208                    	jb .or
  2538 000006BD 740C                    	je .clr
  2539                                  .replace:
  2540 000006BF 8916[0000]              	mov word [haltflags], dx
  2541 000006C3 EB0C                    	jmp .next
  2542                                  
  2543                                  .or:
  2544 000006C5 0916[0000]              	or word [haltflags], dx
  2545 000006C9 EB06                    	jmp .next
  2546                                  
  2547                                  .clr:
  2548 000006CB F7D2                    	not dx
  2549 000006CD 2116[0000]              	and word [haltflags], dx
  2550                                  .next:
  2551 000006D1 06                      	push es
  2552 000006D2 1F                      	pop ds
  2553                                   assume ds:SYSINITGROUP
  2554 000006D3 E83DFF                  	call cmdline_next
  2555 000006D6 75D5                    	jnz .loop
  2556 000006D8 C3                      	retn
  2557                                  
  2558                                  
  2559                                  		; INP:	si -> number input text
  2560                                  		; OUT:	NC if success,
  2561                                  		;	 dx = number
  2562                                  		;	 bl = 0 if +, 1 if -, 2 else
  2563                                  parsenumber:
  2564 000006D9 31DB                    	xor bx, bx
  2565 000006DB AC                      	lodsb
  2566 000006DC 3C2B                    	cmp al, '+'
  2567 000006DE 7407                    	je @F
  2568 000006E0 43                      	inc bx
  2569 000006E1 3C2D                    	cmp al, '-'
  2570 000006E3 7402                    	je @F
  2571 000006E5 43                      	inc bx
  2572 000006E6 4E                      	dec si
  2573                                  @@:
  2574                                   extern ldos_getnum_far
  2575 000006E7 9A[0000][ssss]          	call far ldos_getnum_far
  2576 000006EC C3                      	retn
  2577                                  
  2578                                  
  2579                                  usesection SYSINITTRAIL
  2580                                  
  2581                                  		; INP:	si -> number input text
  2582                                  		; OUT:	CY if error
  2583                                  		;	NC if success,
  2584                                  		;	 dx = number
  2585                                   global ldos_getnum
  2586                                  ldos_getnum:
  2587 000008E4 B90A00                  	mov cx, 10
  2588                                  .before:
  2589 000008E7 AC                      	lodsb
  2590 000008E8 3C20                    	cmp al, 32
  2591 000008EA 74FB                    	je .before
  2592 000008EC 3C09                    	cmp al, 9
  2593 000008EE 74F7                    	je .before
  2594 000008F0 3C3D                    	cmp al, '='
  2595 000008F2 74F3                    	je .before
  2596 000008F4 3C3A                    	cmp al, ':'
  2597 000008F6 74EF                    	je .before
  2598 000008F8 4E                      	dec si
  2599 000008F9 89F7                    	mov di, si		; di -> first digit
  2600                                  .preloop:
  2601 000008FB AC                      	lodsb
  2602 000008FC 3C5F                    	cmp al, '_'
  2603 000008FE 74FB                    	je .preloop
  2604 00000900 E88D00                  	call capitalise
  2605 00000903 3C30                    	cmp al, '0'
  2606 00000905 750A                    	jne .not0
  2607 00000907 80F90A                  	cmp cl, 10		; base changed to hex?
  2608 0000090A 7522                    	jne .hexit		;  then it's a hexit -->
  2609 0000090C 80CD01                  	or ch, 1
  2610 0000090F EBEA                    	jmp .preloop
  2611                                  .not0:
  2612 00000911 3C48                    	cmp al, 'H'
  2613 00000913 7404                    	je .h
  2614 00000915 3C58                    	cmp al, 'X'
  2615 00000917 7510                    	jne .notx
  2616                                  .h:
  2617 00000919 F6C502                  	test ch, 2		; hexits before ?
  2618 0000091C 7502                    	jnz .gotsome
  2619 0000091E 89F7                    	mov di, si
  2620                                  .gotsome:
  2621 00000920 80F90A                  	cmp cl, 10		; multiple h/x ?
  2622 00000923 7540                    	jne .bad		; reject -->
  2623 00000925 B110                    	mov cl, 16
  2624 00000927 EBD2                    	jmp .preloop
  2625                                  .notx:
  2626 00000929 E84D00                  	call ishex
  2627 0000092C 7205                    	jc .preend
  2628                                  .hexit:
  2629 0000092E 80CD02                  	or ch, 2		; note hexit
  2630 00000931 EBC8                    	jmp .preloop
  2631                                  
  2632                                  .preend:
  2633 00000933 84ED                    	test ch, ch
  2634 00000935 742E                    	jz .bad
  2635 00000937 4E                      	dec si
  2636 00000938 F6C502                  	test ch, 2
  2637 0000093B 7406                    	jz .onlyzero
  2638 0000093D 39F7                    	cmp di, si
  2639 0000093F 7424                    	je .bad
  2640 00000941 89FE                    	mov si, di
  2641                                  .onlyzero:
  2642 00000943 B500                    	mov ch, 0
  2643 00000945 31FF                    	xor di, di
  2644                                  
  2645                                  .loop:
  2646 00000947 AC                      	lodsb
  2647 00000948 3C5F                    	cmp al, '_'
  2648 0000094A 74FB                    	je .loop
  2649 0000094C E82A00                  	call ishex
  2650 0000094F 7216                    	jc .end
  2651 00000951 38C8                    	cmp al, cl
  2652 00000953 7310                    	jae .bad
  2653 00000955 97                      	xchg di, ax
  2654 00000956 F7E1                    	mul cx
  2655 00000958 97                      	xchg di, ax
  2656 00000959 85D2                    	test dx, dx
  2657 0000095B 7508                    	jnz .bad
  2658 0000095D B400                    	mov ah, 0
  2659 0000095F 01C7                    	add di, ax
  2660 00000961 7202                    	jc .bad
  2661 00000963 EBE2                    	jmp .loop
  2662                                  
  2663                                  .bad:
  2664 00000965 F9                      	stc
  2665 00000966 C3                      	retn
  2666                                  
  2667                                  .end:
  2668 00000967 4E                      	dec si
  2669                                  .endloop:
  2670 00000968 AC                      	lodsb
  2671 00000969 E82400                  	call capitalise
  2672 0000096C 3C58                    	cmp al, 'X'
  2673 0000096E 74F8                    	je .endloop
  2674 00000970 3C48                    	cmp al, 'H'
  2675 00000972 74F4                    	je .endloop
  2676 00000974 4E                      	dec si
  2677 00000975 89FA                    	mov dx, di
  2678 00000977 F8                      	clc
  2679 00000978 C3                      	retn
  2680                                  
  2681                                  
  2682                                  ishex:
  2683 00000979 E81400                  	call capitalise
  2684 0000097C 2C30                    	sub al, '0'
  2685 0000097E 720F                    	jc .ret
  2686 00000980 3C0A                    	cmp al, 10
  2687 00000982 720A                    	jb .ret_cmc
  2688 00000984 2C07                    	sub al, 'A' - ('9' + 1)
  2689 00000986 7207                    	jc .ret
  2690 00000988 3C0A                    	cmp al, 10
  2691 0000098A 7203                    	jb .ret
  2692 0000098C 3C10                    	cmp al, 16
  2693                                  .ret_cmc:
  2694 0000098E F5                      	cmc
  2695                                  .ret:
  2696 0000098F C3                      	retn
  2697                                  
  2698                                  
  2699                                  capitalise:
  2700 00000990 3C61                    	cmp al, 'a'
  2701 00000992 7206                    	jb .gotcap
  2702 00000994 3C7A                    	cmp al, 'z'
  2703 00000996 7702                    	ja .gotcap
  2704 00000998 3420                    	xor al, 'A' ^ 'a'
  2705                                  .gotcap:
  2706 0000099A C3                      	retn
  2707                                  
  2708                                  
  2709                                  usesection DOSENTRYINIT
  2710                                  
  2711                                  dosentry_init_getdosdata:
  2712                                   assume ds:nothing, es:nothing, ss:nothing
  2713 000006ED 1E                      	push ds
  2714 000006EE B80000                  	mov ax, 0
  2715 000006F1 8ED8                    	mov ds, ax
  2716                                   assume ds:IVT
  2717 000006F3 A1C600                  	mov ax, [31h * 4 + 2]
  2718 000006F6 1F                      	pop ds
  2719                                   assume ds:nothing
  2720 000006F7 C3                      	retn
  2721                                  
  2722                                  dosentry_init_get_ds_dosdata:
  2723                                  dosentry_init_get_ds_dosbiodata:
  2724                                   assume ds:nothing, es:nothing, ss:nothing
  2725 000006F8 50                      	push ax
  2726 000006F9 E8F1FF                  	call dosentry_init_getdosdata
  2727 000006FC 8ED8                    	mov ds, ax
  2728                                   assume ds:DOSGROUP
  2729 000006FE 58                      	pop ax
  2730 000006FF C3                      	retn
  2731                                  
  2732                                  dosentry_init_get_es_dosbiodata:
  2733                                   assume ds:nothing, es:nothing, ss:nothing
  2734 00000700 50                      	push ax
  2735 00000701 E8E9FF                  	call dosentry_init_getdosdata
  2736 00000704 8EC0                    	mov es, ax
  2737                                   assume es:DOSGROUP
  2738 00000706 58                      	pop ax
  2739 00000707 C3                      	retn
  2740                                  
  2741                                  
  2742                                  ;****************************
  2743                                  
  2744                                  Get_Para_Offset proc	near
  2745                                   assume ds:nothing, es:nothing, ss:nothing
  2746                                  ;in:  AX - offset value
  2747                                  ;out: AX - offset value adjusted for the next paragraph boundary.
  2748 00000708 83C00F                  	add	ax, 15		;make a paragraph
  2749 0000070B D1D8                    	rcr	ax, 1
  2750 0000070D D1E8                    	shr	ax, 1
  2751 0000070F D1E8                    	shr	ax, 1
  2752 00000711 D1E8                    	shr	ax, 1
  2753 00000713 D1E0                    	shl	ax, 1		;now, make it back to offset value
  2754 00000715 D1E0                    	shl	ax, 1
  2755 00000717 D1E0                    	shl	ax, 1
  2756 00000719 D1E0                    	shl	ax, 1
  2757 0000071B C3                      	ret
  2758                                  Get_Para_Offset endp
  2759                                  
  2760                                  ;AN004; Don't need this procedure. Get_FAT_Sector replace this.
  2761                                  ;	READ A FAT SECTOR INTO FAT LOCATION
  2762                                  ;GETFAT  PROC	 NEAR
  2763                                  ;	 XOR	 DI,DI			 ; OFFSET
  2764                                  ;	 MOV	 DX,1			 ; RELATIVE SECTOR (1ST SECTOR OF FAT)
  2765                                  ;	 MOV	 CX,FATLEN		 ; READ ENTIRE FAT.
  2766                                  ;	 MOV	 AX,FATLOC		 ;
  2767                                  ;	 MOV	 ES,AX			 ; LOCATION TO READ
  2768                                  ;	 MOV	 AX,DRVFAT	       ; AH FAT ID BYTE, AL DRIVE
  2769                                  ;	 JMP	 DISKRD
  2770                                  ;GETFAT  ENDP
  2771                                  
  2772                                  
  2773                                  usesection SYSINITTRAIL
  2774                                  
  2775                                   extern allocate_temporary_block, alloc_init
  2776                                   extern sysinit_getdosdata
  2777                                  
  2778                                   global sysinit_get_ds_dosbiodata
  2779                                   global sysinit_get_ds_dosentry
  2780                                  sysinit_get_ds_dosbiodata:
  2781                                   assume ds:nothing, es:nothing, ss:nothing
  2782 0000099B 50                      	push ax
  2783 0000099C E8(0000)                	call sysinit_getdosdata
  2784 0000099F 8ED8                    	mov ds, ax
  2785                                   assume ds:DOSGROUP
  2786 000009A1 58                      	pop ax
  2787 000009A2 C3                      	retn
  2788                                  
  2789                                  sysinit_get_ds_dosentry:
  2790                                   assume ds:nothing, es:nothing, ss:nothing
  2791 000009A3 2E8E1E[AA09]            	mov ds, word [cs:.segment]
  2792                                   assume ds:DOSENTRYGROUP
  2793 000009A8 C3                      	retn
  2794                                  
  2795 000009A9 00                      	align 2, db 0
  2796 000009AA [ssss]                  .segment:	dw DOSENTRY
  2797                                  
  2798                                   global sysinit_get_es_dosbiodata
  2799                                   global sysinit_get_es_dosentry
  2800                                  sysinit_get_es_dosbiodata:
  2801                                   assume ds:nothing, es:nothing, ss:nothing
  2802 000009AC 50                      	push ax
  2803 000009AD E8(0000)                	call sysinit_getdosdata
  2804 000009B0 8EC0                    	mov es, ax
  2805                                   assume es:DOSGROUP
  2806 000009B2 58                      	pop ax
  2807 000009B3 C3                      	retn
  2808                                  
  2809                                  sysinit_get_es_dosentry:
  2810                                   assume ds:nothing, es:nothing, ss:nothing
  2811 000009B4 2E8E06[AA09]            	mov es, word [cs:sysinit_get_ds_dosentry.segment]
  2812                                   assume es:DOSENTRYGROUP
  2813 000009B9 C3                      	retn
  2814                                  
  2815                                  extern dosdata_to_doscode
  2816                                  
  2817                                  get_ds_biocode:
  2818                                   assume ds:nothing, es:nothing, ss:nothing
  2819 000009BA 2E8E1E[C809]            	mov ds, word [cs:.value]
  2820                                   assume ds:IVT
  2821 000009BF 8E1EC600                	mov ds, word [31h * 4 + 2]
  2822                                   assume ds:DOSGROUP
  2823 000009C3 8E1E[0000]              	mov ds, word [dosdata_to_doscode]
  2824                                   assume ds:DOSCODEGROUP
  2825 000009C7 C3                      	retn
  2826                                  
  2827                                  	align 2, nop
  2828 000009C8 0000                    .value:	dw 0
  2829                                  
  2830                                  extern biocode_retf
  2831                                  
  2832                                  %imacro neartransfer 1.nolist
  2833                                  	extern %1
  2834                                  	call transfer_sysinitseg_to_biocode
  2835                                  	jmp strict short %%skip
  2836                                  	dw %1
  2837                                  %%skip:
  2838                                  %endmacro
  2839                                  
  2840                                  transfer_sysinitseg_to_biocode:		; near call ip: in_ip_out_cs
  2841                                   assume ds:nothing, es:nothing, ss:nothing
  2842 000009CA 50                      	push ax				; in_ax_out_ip
  2843 000009CB B8[0000]                	mov ax, biocode_retf
  2844 000009CE 50                      	push ax				; out_retf
  2845 000009CF 50                      	push ax				; out_destination + 2
  2846 000009D0 50                      	push ax				; out_destination + 0
  2847                                  	lframe 0
  2848                                  	lpar word, in_ip_out_cs
  2849                                  	lpar word, in_ax_out_ip
  2850                                  	lpar word, out_retf
  2851                                  	lpar dword, out_destination
  2852 000009D1 5589E5                  	lenter
  2853 000009D4 1E                      	push ds
  2854 000009D5 56                      	push si
  2855 000009D6 8CCE                    	mov si, cs			; si = cs
  2856 000009D8 87760A                  	xchg si, word [bp + ?in_ip_out_cs]
  2857                                  					; set cs, get ip
  2858 000009DB 56                      	push si				; preserve ip for later
  2859 000009DC AD                      	lodsw				; skip jmp short
  2860 000009DD 2EAD                    	cs lodsw			; get destination
  2861 000009DF 894602                  	mov word [bp + ?out_destination + 0], ax
  2862                                  					; set destination
  2863 000009E2 E8D5FF                  	call get_ds_biocode		; ds => BIOCODE
  2864                                   assume ds:DOSCODEGROUP
  2865 000009E5 8C5E04                  	mov word [bp + ?out_destination + 2], ds
  2866                                  					; => BIOCODE
  2867 000009E8 58                      	pop ax
  2868 000009E9 874608                  	xchg ax, word [bp + ?in_ax_out_ip]
  2869                                  					; ax = original ax, set out ip
  2870 000009EC 5E                      	pop si
  2871 000009ED 1F                      	pop ds
  2872                                   assume ds:nothing
  2873 000009EE 5D                      	lleave
  2874 000009EF CB                      	retf
  2875                                  
  2876                                  
  2877                                  
  2878                                  		; INP:	es:si -> partition table entry,
  2879                                  		;	 si = load_partition_table .. load_partition_table+48,
  2880                                  		;	 es = cs
  2881                                  		;	bp + di -> above part table metadata,
  2882                                  		;	 dwo [bp + di - 4] = root (outermost extended position)
  2883                                  		;	 dwo [bp + di - 8] = base (current table position)
  2884                                  		; CHG:	ax, bx, (cx), dx
  2885                                  handle_each_partition:
  2886                                   assume es:SYSINITGROUP, ds:SYSINITGROUP
  2887 000009F0 268A4404                	mov al, byte [es:si + piType]
  2888 000009F4 E844FA                  	call load_is_known
  2889 000009F7 7202                    	jc .discard
  2890 000009F9 7401                    	jz @F
  2891                                  
  2892                                  .discard:
  2893 000009FB C3                      	retn
  2894                                  
  2895                                  @@:
  2896 000009FC 51                      	push cx
  2897 000009FD 57                      	push di
  2898 000009FE 55                      	push bp
  2899 000009FF 56                      	push si
  2900 00000A00 06                      	push es
  2901                                  
  2902 00000A01 800E[0000]20            	setopt [load_scan_flags], 32	; a logical or primary partition found
  2903                                  		; Hmm. If we reject the partition later, then we
  2904                                  		;  still have set this flag here. But, that matches
  2905                                  		;  what lMS-DOS did before (invalid partition stops
  2906                                  		;  the scan in current MBR/EPBR). So it stays so.
  2907                                  
  2908 00000A06 8B43F8                  	mov ax, [bp + di - 8]
  2909 00000A09 8B53FA                  	mov dx, [bp + di - 6]		; base (current table position)
  2910 00000A0C 26034408                	add ax, [es:si + 8]
  2911 00000A10 2613540A                	adc dx, [es:si + 8 + 2]		; add offset to logical partition
  2912 00000A14 8A0E[0400]              	mov cl, [BDS_harddisk_template + DRIVENUM]
  2913                                  
  2914 00000A18 E880FF                  	call sysinit_get_ds_dosbiodata
  2915                                   assume ds:DOSGROUP
  2916 00000A1B C53E[0000]              	lds	di, [Start_BDS]
  2917                                   assume ds:nothing
  2918                                  @@:
  2919 00000A1F 83FFFF                  	cmp di, -1
  2920 00000A22 743A                    	je .notduplicate
  2921 00000A24 384D04                  	cmp byte [di + DRIVENUM], cl
  2922 00000A27 750A                    	jne @F
  2923 00000A29 394517                  	cmp word [di + HIDSEC_L], ax
  2924 00000A2C 7505                    	jne @F
  2925 00000A2E 395519                  	cmp word [di + HIDSEC_H], dx
  2926 00000A31 7404                    	je .duplicate
  2927                                  @@:
  2928 00000A33 C53D                    	lds di, [di + LINK]
  2929                                   assume ds:nothing
  2930 00000A35 EBE8                    	jmp @BB
  2931                                  
  2932                                  .duplicate:
  2933 00000A37 0E                      	push cs
  2934 00000A38 1F                      	pop ds
  2935                                   assume ds:SYSINITGROUP
  2936 00000A39 0E                      	push cs
  2937 00000A3A 07                      	pop es
  2938                                   assume es:SYSINITGROUP
  2939                                  
  2940 00000A3B BF[430F]                	mov di, msg.duplicate_hidden_l
  2941                                  extern hexword
  2942 00000A3E E8(0000)                	call hexword
  2943 00000A41 92                      	xchg ax, dx
  2944 00000A42 BF[3E0F]                	mov di, msg.duplicate_hidden_h
  2945 00000A45 E8(0000)                	call hexword
  2946 00000A48 91                      	xchg ax, cx
  2947 00000A49 BF[320F]                	mov di, msg.duplicate_unit
  2948 00000A4C E8(0000)                	call hexbyte
  2949                                  
  2950 00000A4F BA[C80E]                	mov dx, msg.bootfail
  2951 00000A52 E8(0000)                	call init2_disp_msg_asciz_cs_dx
  2952 00000A55 BA[0A0F]                	mov dx, msg.duplicate
  2953 00000A58 E8(0000)                	call init2_disp_msg_asciz_cs_dx
  2954 00000A5B E96D02                  	jmp partition_reject
  2955                                  
  2956                                  
  2957                                  .notduplicate:
  2958 00000A5E 0E                      	push cs
  2959 00000A5F 1F                      	pop ds
  2960                                   assume ds:SYSINITGROUP
  2961 00000A60 BF[0000]                	mov di, BDS_harddisk_template
  2962                                  					; Hidden sectors (based on EPBR)
  2963 00000A63 894517                  	mov [di + HIDSEC_L], ax		;   BPB->HIDSECCT = P->PARTITIONBEGIN;
  2964 00000A66 895519                  	mov [di + HIDSEC_H], dx
  2965 00000A69 A0[0000]                	mov al, [next_block_device_unit]
  2966 00000A6C 884505                  	mov [di + DRIVELET], al
  2967                                  
  2968                                  
  2969                                  ;   SETHARD - GENERATE BPB FOR A VARIABLE SIZED HARD FILE.  IBM HAS A
  2970                                  ;   PARTITIONED HARD FILE; WE MUST READ PHYSICAL SECTOR 0 TO DETERMINE WHERE
  2971                                  ;   OUR OWN LOGICAL SECTORS START.  WE ALSO READ IN OUR BOOT SECTOR TO
  2972                                  ;   DETERMINE VERSION NUMBER
  2973                                  
  2974                                  ;   INPUTS:	DL IS ROM DRIVE NUMBER (80 OR 81)
  2975                                  ;		DS:DI POINTS TO BDS
  2976                                  ;   OUTPUTS:	CARRY CLEAR -> BPB IS FILLED IN
  2977                                  ;		CARRY SET   -> BPB IS LEFT UNINITIALIZED DUE TO ERROR
  2978                                  
  2979                                   assume ds:SYSINITGROUP, es:nothing, ss:nothing
  2980                                  				; Note: Partitiontype 6 means either
  2981                                  				;1).the partition has not been formatted yet, or
  2982                                  				;2).(# of sectors before the partition +
  2983                                  				;    # of sectors in this partition) > word boundary
  2984                                  				;	i.e., needs 32 bit sector calculation, or
  2985                                  				;3).the partition is not a FAT file system.
  2986                                  
  2987                                  ;J.K.  Until we get the real logical boot record and get the bpb,
  2988                                  ;DRVLIM_H,DRVLIM_L will be used instead of DRVLIM for the convenience of
  2989                                  ;the computation.
  2990                                  ;At the end of this procedure, if a BPB information is gotten from
  2991                                  ;the valid boot record, then we are going to use those BPB information
  2992                                  ;without change.
  2993                                  ;Otherwise, if (hidden sectors + total sectors) <= a word, then
  2994                                  ;we will move DRVLIM_L to DRVLIM and zero out DRVLIM_L entry to make
  2995                                  ;it a conventional BPB format.
  2996                                  
  2997 00000A6F 268B440C                	mov ax, word [es:si + piLength]		; # of sectors (Low)
  2998 00000A73 268B540E                	mov dx, word [es:si + piLength + 2]	;AN000; # of sectors (High)
  2999 00000A77 89551D                  	mov	word ptr [di + DRVLIM_H], dx
  3000 00000A7A 89451B                  	mov	word ptr [di + DRVLIM_L], ax ;   BPB->MAXSEC = P->PARTITIONLENGTH;
  3001 00000A7D 85D2                    	test dx, dx
  3002 00000A7F 7508                    	jnz OKDrive_Cont
  3003 00000A81 83F840                  	cmp ax, 64			;   IF (P->PARTITIONLENGTH < 64)
  3004 00000A84 7303E94202              	jb partition_reject		;	RETURN -1;
  3005                                  
  3006                                  OKDrive_Cont:				;AN000;
  3007                                  
  3008 00000A89 034517                  	add ax, [di + HIDSEC_L]
  3009 00000A8C 135519                  	adc dx, [di + HIDSEC_H]		; dx:ax = sector after partition
  3010                                  Okdrive equ OKDRIVE	; NASM port label
  3011 00000A8F 730B                    	jnc Okdrive
  3012 00000A91 89C1                    	mov cx, ax
  3013 00000A93 09D1                    	or cx, dx
  3014 00000A95 7405                            jz Okdrive
  3015                                  	  MESSAGE FTESTHARD,<"PARTITION INVALID",CR,LF>
  3016 00000A97 800E[0700]80            	or byte [FBIGFAT], FTOOBIG
  3017                                  OKDRIVE:
  3018                                  
  3019 00000A9C F6452404                	testopt [di + FLAGS], F_LBA
  3020 00000AA0 7512                    	jnz okdrive_lba
  3021                                  
  3022 00000AA2 83E801                  	sub ax, 1
  3023 00000AA5 83DA00                  	sbb dx, 0			; dx:ax = last sector of partition
  3024 00000AA8 E81FFFEB02[0000]        	neartransfer lbatochs		; convert to CHS
  3025 00000AAF 7303E91702              	jc partition_reject		; if CHS overflow -->
  3026                                  
  3027                                  okdrive_lba:
  3028                                  
  3029 00000AB4 8B5519                  	mov	dx,[di + HIDSEC_H]
  3030 00000AB7 8B4517                  	mov	ax,[di + HIDSEC_L]	; BOOT SECTOR NUMBER
  3031                                  
  3032                                  
  3033                                  ;J.K. For convenience, we are going to read the logical boot sector
  3034                                  ;into cs:DiskSector area.
  3035                                  
  3036                                  ;SB34INIT009*************************************************************
  3037                                  ;SB  Read in boot sector using BIOS disk interrupt.  The buffer where it
  3038                                  ;SB  is to be read in is cs:Disksector.
  3039 00000ABA E8F7FE                  	call sysinit_get_es_dosentry	; DISKSECTOR in DOSENTRY
  3040                                   assume es:DOSENTRYGROUP
  3041 00000ABD BB[0000]                	mov	bx,offset DiskSector	; access with es
  3042 00000AC0 B90102                  	mov	cx,0201h	; read, one sector
  3043 00000AC3 E81C02                  	call readsector_flag
  3044 00000AC6 7303E90002              	jc partition_reject		;AN000; Exceeds the limit of Int 13h
  3045                                  ;SB34INIT009*************************************************************
  3046                                  
  3047 00000ACB E86A03                  	call have_bpb
  3048 00000ACE 7309                    	jnc @F
  3049                                   assume ds:SYSINITGROUP
  3050                                  extern BADBLOCK
  3051 00000AD0 BA[0000]                	MOV	DX,OFFSET BADBLOCK
  3052                                  extern PRINT
  3053 00000AD3 E8(0000)                	call PRINT
  3054 00000AD6 E9F201                  	jmp partition_reject
  3055                                  @@:
  3056                                  
  3057 00000AD9 06                      	push es
  3058                                  		; At this point we're sure to set up the drive.
  3059                                  		;  So, copy over the template to the next UPB.
  3060 00000ADA FE06[0000]              	inc byte [next_block_device_unit]
  3061                                  					; remember which DOS drive is next
  3062 00000ADE 89FE                    	mov si, di
  3063 00000AE0 E893F6                  	call alloc_upb			; (will halt system on error)
  3064                                   assume es:UPB
  3065 00000AE3 B96400                  	mov cx, BDS_TYPE_struc_size
  3066 00000AE6 57                      	push di
  3067 00000AE7 F3A4                    	rep movsb
  3068 00000AE9 5F                      	pop di				; di -> next UPB
  3069 00000AEA 06                      	 push es
  3070 00000AEB 1F                      	 pop ds				; ds:di -> UPB
  3071                                   assume ds:UPB
  3072 00000AEC E85203                  	call Install_BDSM_and_set_bpb	; INSTALL BDS INTO LINKED LIST
  3073 00000AEF 07                      	pop es
  3074                                   assume es:DOSENTRYGROUP
  3075                                  
  3076                                  
  3077                                  ; cs:Disksec contains THE BOOT SECTOR.	IN THEORY, (HA HA) THE BPB IN THIS THING
  3078                                  ; IS CORRECT.  WE CAN, THEREFORE, SUCK OUT ALL THE RELEVANT STATISTICS ON THE
  3079                                  ; MEDIA IF WE RECOGNIZE THE VERSION NUMBER.
  3080                                  
  3081                                  ; look for a signature for msdos...
  3082 00000AF0 26817F034D53            	cmp	word ptr [es:bx+3], "M" + ("S" << 8)
  3083 00000AF6 750F                    	jne	notmssig
  3084 00000AF8 26817F05444F            	cmp	word ptr [es:bx+5], "D" + ("O" << 8)
  3085 00000AFE 7507                    	jne	notmssig
  3086 00000B00 26807F0753              	cmp	byte ptr [es:bx+7], "S"
  3087 00000B05 7420                    	je	sigfound
  3088                                  ; ...or perhaps pcdos...
  3089                                  notmssig:
  3090 00000B07 26817F034942            	CMP	WORD PTR [es:bx+3], "I" + ("B" << 8)
  3091 00000B0D 7508                    	jne	notibmsig
  3092 00000B0F 26817F054D20            	CMP	WORD PTR [es:bx+5], "M" + (" " << 8)
  3093 00000B15 7410                    	je	sigfound
  3094                                  
  3095                                  notibmsig:
  3096 00000B17 26817F034F53            	CMP	WORD PTR [es:bx+3], "O" + ("S" << 8)
  3097 00000B1D 751D                    	jne	acceptbpb
  3098 00000B1F 26817F053220            	CMP	WORD PTR [es:bx+5], "2" + (" " << 8)
  3099 00000B25 7515                    	jne	acceptbpb	; ecm: not MSDOS nor IBM nor OS/2, accept BPB -->
  3100                                  
  3101                                  sigfound:			; signature was found, now check version
  3102                                  
  3103                                  check3point0:
  3104                                  Cover_Fdisk_Bug equ Cover_FDISK_Bug	; NASM port label
  3105 00000B27 E81302                  	call	Cover_Fdisk_Bug 		;AN010;
  3106                                  		; ecm: only reject "MSDOS3.0" or "IBM  3.0"
  3107 00000B2A 26817F08332E            	CMP	WORD PTR [es:bx+8],"3" + ("." << 8)
  3108 00000B30 750A                    	jne	acceptbpb
  3109 00000B32 26807F0A30              	cmp	byte ptr [es:bx+10],"0"         ;do not trust 3.0 boot record. But still legal J.K. 4/15/86
  3110 00000B37 7503                    	jne	acceptbpb			;AN012; if version >= 3.1, then O.K.
  3111 00000B39 E9BB00                  	jmp	unknown3point0
  3112                                  acceptbpb:
  3113                                  COPYBPB:
  3114                                  ; WE HAVE A VALID BOOT SECTOR. USE THE BPB IN IT TO BUILD THE
  3115                                  ; BPB IN BIOS. IT IS ASSUMED THAT ONLY SECPERCLUS, CDIR, AND
  3116                                  ; CSECFAT NEED TO BE SET (ALL OTHER VALUES IN ALREADY). FBIGFAT
  3117                                  ; IS ALSO SET.
  3118                                  
  3119                                  ;If it is non FAT based system, then just copy the BPB from the BOOT sector
  3120                                  ;into the BPB in BDS table, and also set the Boot serial number, Volume id,
  3121                                  ;and System ID according to the Boot record.
  3122                                  ;For the non_FAT system, don't need to set the other value. So just
  3123                                  ;do GOODRET.- J.K.
  3124                                  
  3125 00000B3C 26803E[0000]29          	cmp	byte [es:Ext_Boot_Sig], EXT_BOOT_SIGNATURE ;AN000;
  3126 00000B42 7528                    	jne	COPYBPB_FAT		;AN000; Conventional Fat system
  3127 00000B44 26803E[0000]00          	cmp	byte [es:NumberOfFats], 0	;AN000; If (# of FAT <> 0) then
  3128 00000B4A 7520                    	jne	COPYBPB_FAT		;AN000;   a Fat system.
  3129                                  ;J.K. Non Fat based media.
  3130 00000B4C 57                      	push	di			;AN000; Sav Reg.
  3131 00000B4D 1E                      	push	ds			;AN000;
  3132 00000B4E 06                      	push es
  3133                                  
  3134 00000B4F 1E                      	push	ds			;AN000;
  3135 00000B50 07                      	pop	es			;AN000; now es:di -> bds
  3136                                   assume es:UPB
  3137 00000B51 E84FFE                  	call sysinit_get_ds_dosentry	; DISKSECTOR in DOSENTRY
  3138                                   assume ds:DOSENTRYGROUP
  3139 00000B54 BE[0000]                	mov	si, offset Bpb_In_Sector ;AN000; ds:si -> BPB in Boot ; access with ds
  3140 00000B57 83C706                  	add	di, BYTEPERSEC		;AN000; es:di -> BPB in BDS
  3141 00000B5A B91900                  	mov	cx, BPB_TYPE_struc_size	;AN000;
  3142 00000B5D F3A4                    	rep	movsb			;AN000;
  3143                                  
  3144 00000B5F 07                      	pop es
  3145                                   assume es:DOSENTRYGROUP
  3146 00000B60 1F                      	pop	ds			;AN000; Restore Reg.
  3147                                   assume ds:UPB
  3148 00000B61 5F                      	pop	di			;AN000;
  3149 00000B62 E865FEEB02[0000]        	neartransfer Mov_Media_IDs	;AN000; Set Volume id, SystemId, Serial.
  3150                                  init_GoodRet equ init_GOODRET	; NASM port label
  3151 00000B69 E94201                  	jmp	init_GoodRet
  3152                                  
  3153                                  COPYBPB_FAT:				;AN000;  Fat system
  3154 00000B6C 31D2                    	xor	dx,dx			;AN000;
  3155 00000B6E BE[0000]                	mov	si, offset Bpb_In_Sector ;AN000;  es:bx -> bpb in boot ; access with es
  3156 00000B71 268B4408                	mov	ax, [es:si + SECNUM]	;AN000;  total sectors
  3157 00000B75 85C0                    	test ax, ax			;AN000; double word sector number?
  3158 00000B77 7508                    	jnz	Fat_Big_Small		;AN000;  No. Conventional BPB.
  3159 00000B79 268B4415                	mov	ax, word ptr [es:si + SECNUM_L] ;AN000; Use double word
  3160 00000B7D 268B5417                	mov	dx, word ptr [es:si + SECNUM_H] ;AN000;
  3161                                  
  3162                                  Fat_Big_Small:				 ;AN000; Determine Fat entry size.
  3163                                  ;At this moment DX;AX = Total sector number
  3164 00000B81 268B5C03                	mov bx, [es:si + RESNUM]
  3165 00000B85 895D09                  	mov [di + RESSEC], bx
  3166 00000B88 29D8                    	sub	ax,bx			;AN000; Subtract # reserved
  3167 00000B8A 83DA00                  	sbb	dx,0			;AN000;
  3168 00000B8D 268B5C0B                	mov	bx, [es:si + FATSIZE]	;AN000;  BX = Sectors/Fat
  3169 00000B91 895D11                  	mov	[di + CSECFAT],bx 	;AN000;  Set in BDS BPB
  3170 00000B94 31C9                    	xor cx, cx
  3171 00000B96 268A4C05                	mov cl, [es:si + FATNUM]
  3172 00000B9A 884D0B                  	mov [di + CFAT], cl
  3173 00000B9D E307                    	jcxz .none
  3174                                  .loop:
  3175 00000B9F 29D8                    	sub	ax,bx			;AN000; Subtract # fat sectors
  3176 00000BA1 83DA00                  	sbb	dx,0			;AN000;
  3177 00000BA4 E2F9                    	loop .loop
  3178                                  .none:
  3179 00000BA6 268B5C06                	mov	bx, [es:si + DIRNUM]	;AN000;  # root entries
  3180                                  cDIR equ CDIR	; NASM port equate
  3181 00000BAA 895D0C                  	mov	[di + cDIR],bx		;AN000;  Set in BDS BPB
  3182                                  
  3183 00000BAD B104                    	MOV	CL,4
  3184 00000BAF D3EB                    	shr	bx,cl			;AN000;  Div by 16 ents/sector
  3185 00000BB1 29D8                    	sub	ax,bx			;AN000;  sub # dir sectors
  3186 00000BB3 83DA00                  	sbb	dx,0			;AN000;
  3187                                  					;AN000; DX;AX now contains the # of data sectors
  3188 00000BB6 268A4C02                	MOV	CL, [es:si + SECALL]	; SECTORS PER CLUSTER
  3189 00000BBA 49                      	dec cx
  3190 00000BBB B500                    	mov ch, 0
  3191 00000BBD 41                      	inc cx				; translate EDR-DOS 0 to 256
  3192 00000BBE 884D08                  	MOV	[DI + SECPERCLUS],CL	; SET IN BIOS BPB (truncated)
  3193                                  ;	 XOR	 DX,DX
  3194                                  ;	 MOV	 CH,DH
  3195                                  	MNUM	FTESTHARD,CX
  3196                                  	MESSAGE FTESTHARD,<" SECPERCLUS",CR,LF>
  3197                                  ;J.K. 3/16/87 P54 Returning back to old logic for compatibility reason.
  3198                                  ;So, use the old logic again that once had been commented out!!!!!!!!!!!!
  3199                                  ;Old logic to determine FAT Entry Size J.K. 12/3/86
  3200 00000BC1 E8E8FD                  	call sysinit_get_es_dosbiodata
  3201                                   assume es:DOSGROUP
  3202 00000BC4 50                      	push	ax			;AN000;
  3203 00000BC5 92                      	xchg	ax, dx			; ax = high word, clobber dx
  3204 00000BC6 31D2                    	xor	dx,dx			;AN000;
  3205 00000BC8 F7F1                    	div	cx			;AN000; cx = sectors per cluster
  3206 00000BCA 26A3[0000]              	mov	[es:Temp_H],ax		;AN000;
  3207 00000BCE 58                      	pop	ax			;AN000;
  3208 00000BCF F7F1                    	DIV	CX			;AN000;  [Temp_H];AX NOW CONTAINS THE # CLUSTERS.
  3209 00000BD1 26833E[0000]00          	cmp	word [es:Temp_H],0		;AN000;
  3210 00000BD7 7715                    	ja	TooBig_Ret		;AN000;  Too big cluster number
  3211 00000BD9 3DF60F                  	CMP	AX,4096-10		; IS THIS 16-BIT FAT?
  3212 00000BDC 7206                    	JB	CopyMediaID		; NO, small FAT
  3213 00000BDE 2E800E[0700]40          	OR	byte [cs:FBIGFAT],FBIG	; 16 BIT FAT
  3214                                  ;End of Old logic
  3215                                  CopyMediaID:
  3216 00000BE4 E8E3FDEB02[0000]        	neartransfer Mov_Media_IDs	;AN000; Copy Filesys_ID, Volume label,
  3217                                  					;and Volume serial to BDS table, if extended
  3218                                  					;boot record.
  3219 00000BEB E99F00                  	JMP	Massage_bpb		;AN000; Now final check for BPB info. and return.
  3220                                  
  3221                                  TooBig_Ret:				;AN000;
  3222 00000BEE 2E800E[0700]80          	OR	byte [cs:FBIGFAT],FTOOBIG
  3223 00000BF4 E9B700                  	JMP	init_GOODRET		;AN000; Still drive letter is assigned
  3224                                  					;AN000; But useless. To big for
  3225                                  					;AN000; current PC DOS FAT file system
  3226                                  ; UNKNOWN:
  3227                                  ;	or	[di].FLAGS, UNFORMATTED_MEDIA	;AN005; Set unformatted media flag.
  3228                                  	; preceeding line commented out 10/88 by MRW--  The boot signature
  3229                                  	;   may not be recognizable, but we should TRY and read it anyway.
  3230                                  						;AN006;
  3231                                  						;AN008; For the time being, allow it.
  3232                                  						;AN009; Now implemented again
  3233                                  ; Unknown3_0:				;AN012;Skip setting UNFORMATTED_MEDIA bit
  3234                                  unknown3point0:
  3235                                   assume es:DOSENTRYGROUP
  3236                                  	MESSAGE FTESTHARD,<"UNKNOWN HARD MEDIA. ASSUMING 3.0.",CR,LF>
  3237 00000BF7 8B551D                  	mov	dx, [di + DRVLIM_H]	;AN000;
  3238 00000BFA 8B451B                  	mov	ax, [di + DRVLIM_L]	;AN000;
  3239                                  DISKTABLE2 equ DiskTable2	; NASM port label
  3240 00000BFD BE[9800]                	MOV	SI,OFFSET DISKTABLE2	; access with cs
  3241                                  .SCAN:
  3242                                  ;	 CMP	 AX,[SI]
  3243                                  ;	 JBE	 GOTPARM
  3244                                  ;	 ADD	 SI,4 * 2
  3245                                  
  3246 00000C00 2E3B14                  	cmp	dx, word ptr [cs:si]	;AN000;
  3247                                  GotParm equ GOTPARM	; NASM port label
  3248 00000C03 720D                    	jb	GotParm 		;AN000;
  3249 00000C05 7706                    	ja	.Scan_Next		;AN000;
  3250 00000C07 2E3B4402                	cmp	ax, word ptr [cs:si+2]	;AN000;
  3251 00000C0B 7605                    	jbe	GotParm 		;AN000;
  3252                                  .Scan_Next:				;AN000;
  3253 00000C0D 83C60A                  	add	si, 5 * 2		;AN000;
  3254 00000C10 EBEE                    	JMP	.SCAN			;AN000;  Covers upto 512 MB media
  3255                                  GOTPARM:
  3256                                  ;	 MOV	 CL,BYTE PTR [SI+6]
  3257 00000C12 2E8A4C08                	mov	cl,byte ptr [cs:si+8]	;AN000;  Fat size for FBIGFAT flag
  3258 00000C16 2E080E[0700]            	OR	[cs:FBIGFAT],CL
  3259                                  ;	 MOV	 CX,[SI+2]
  3260                                  ;	 MOV	 DX,[SI+4]
  3261 00000C1B 2E8B4C04                	mov	cx, word ptr [cs:SI+4]	;AN000;
  3262 00000C1F 2E8B5406                	mov	dx, word ptr [cs:SI+6]	;AN000;
  3263                                  
  3264                                  ;	DX = NUMBER OF DIR ENTRIES,
  3265                                  ;	CH = NUMBER OF SECTORS PER CLUSTER
  3266                                  ;	CL = LOG BASE 2 OF CH
  3267                                  
  3268                                  ;	NOW CALCULATE SIZE OF FAT TABLE
  3269                                  
  3270                                  	MNUM	FTESTHARD,AX
  3271                                  	MESSAGE FTESTHARD,<" SECTORS ">
  3272                                  	MNUM	FTESTHARD,DX
  3273                                  	MESSAGE FTESTHARD,<" DIRECTORY ENTRIES ">
  3274                                  	MNUM	FTESTHARD,CX
  3275                                  	MESSAGE FTESTHARD,<" SECPERCLUS|CLUSSHIFT">
  3276                                  
  3277 00000C23 89550C                  	MOV	WORD PTR [CDIR + DI],DX	;SAVE NUMBER OF DIR ENTRIES
  3278                                  
  3279                                  ;Now, CX = SecPerClus|Clusshift
  3280                                  ;     [DI.CDIR] = number of directory entries.
  3281                                  
  3282 00000C26 8B551D                  	mov	dx, [di + DRVLIM_H]	;AN000;
  3283 00000C29 8B451B                  	mov	ax, [di + DRVLIM_L]	;AN000;
  3284 00000C2C 886D08                  	MOV	BYTE PTR [SECPERCLUS + DI],CH ;SAVE SECTORS PER CLUSTER
  3285 00000C2F 2EF606[0700]40          	TEST	byte [cs:FBIGFAT],FBIG		;   IF (FBIGFAT)
  3286 00000C35 751E                    	JNZ	DOBIG			;	GOTO DOBIG;
  3287                                  	 MESSAGE FTESTHARD,<" SMALL FAT",CR,LF>
  3288                                  ;J.K. We don't need to change "small fat" logic since it is gauranteed
  3289                                  ;that double word total sector will not use 12 bit fat (unless
  3290                                  ;it's sectors/cluster >= 16 which will never be in this case.)
  3291                                  ;So in this case we assume DX = 0 !!!.
  3292                                  
  3293 00000C37 31DB                    	XOR	BX,BX
  3294 00000C39 88EB                    	MOV	BL,CH
  3295 00000C3B 4B                      	DEC	BX
  3296 00000C3C 01C3                    	ADD	BX,AX			;AN000;  DX=0
  3297 00000C3E D3EB                    	SHR	BX,CL			;   BX = 1+(BPB->MAXSEC+SECPERCLUS-1)/
  3298 00000C40 43                      	INC	BX			;	    SECPERCLUS
  3299 00000C41 80E3FE                  	AND	BL,11111110B		;   BX &= ~1; (=NUMBER OF CLUSTERS)
  3300 00000C44 89DE                    	MOV	SI,BX
  3301 00000C46 D1EB                    	SHR	BX,1
  3302 00000C48 01F3                    	ADD	BX,SI
  3303 00000C4A 81C3FF01                	ADD	BX,511			;   BX += 511 + BX/2
  3304 00000C4E D0EF                    	SHR	BH,1			;   BH >>= 1; (=BX/512)
  3305 00000C50 887D11                  	MOV	BYTE PTR [DI + CSECFAT],BH ;SAVE NUMBER OF FAT SECTORS
  3306                                  Massage_BPB equ Massage_bpb	; NASM port label
  3307 00000C53 EB38                    	JMP	SHORT Massage_BPB
  3308                                  DOBIG:
  3309                                  ;J.K. For BIGFAT we do need to extend this logic to 32 bit sector calculation.
  3310                                  	  MESSAGE FTESTHARD,<" BIG FAT",CR,LF>
  3311 00000C55 B104                    	MOV	CL,4			; 16 (2^4) DIRECTORY ENTRIES PER SECTOR
  3312 00000C57 52                      	push	dx			;AN000; Save total sectors (high)
  3313 00000C58 8B550C                  	mov	dx,[CDIR + DI]		;AN000;
  3314 00000C5B D3EA                    	SHR	DX,CL			; CSECDIR = CDIR / 16;
  3315 00000C5D 29D0                    	SUB	AX,DX			; DX;AX -= CSECDIR; DX;AX -= CSECRESERVED;
  3316 00000C5F 5A                      	pop	dx			;AN000;
  3317 00000C60 83DA00                  	SBB	dx,0			;AN000;
  3318                                  ;	 DEC	 AX			 ; AX = T - R - D
  3319 00000C63 83E801                  	SUB	ax,1			;AN000; DX;AX = T - R - D
  3320 00000C66 83DA00                  	SBB	dx,0			;AN000;
  3321 00000C69 B302                    	MOV	BL,2
  3322 00000C6B 8A7D08                  	MOV	BH,[SECPERCLUS + DI]	; BX = 256 * SECPERCLUS + 2
  3323                                  ;	 XOR	 DX,DX
  3324                                  ;J.K. I don't understand why to add BX here!!!
  3325 00000C6E 01D8                    	ADD	AX,BX			; AX = T-R-D+256*SPC+2
  3326 00000C70 83D200                  	ADC	DX,0
  3327 00000C73 83E801                  	SUB	AX,1			; AX = T-R-D+256*SPC+1
  3328 00000C76 83DA00                  	SBB	DX,0
  3329                                  ;J.K. Assuming DX in the table will never be bigger than BX.
  3330 00000C79 F7F3                    	DIV	BX			; CSECFAT = CEIL((TOTAL-DIR-RES)/
  3331                                  					;		 (256*SECPERCLUS+2));
  3332 00000C7B 894511                  	MOV	WORD PTR [DI + CSECFAT],AX ; NUMBER OF FAT SECTORS
  3333                                  ;J.K. Now, set the default FileSys_ID, Volume label, Serial number
  3334 00000C7E 2E8A1E[0700]            	MOV	BL,[cs:FBIGFAT]
  3335 00000C83 885D1F                  	MOV	[DI + FATSIZ],BL		; SET SIZE OF FAT ON MEDIA
  3336 00000C86 E841FDEB02[0000]        	neartransfer Clear_IDs		;AN000;
  3337                                  
  3338                                  ;J.K. At this point, in BPB of BDS table, DRVLIM_H,DRVLIM_L which were
  3339                                  ;set according to the partition information. We are going to
  3340                                  ;see if (hidden sectors + total sectors) > a word.  If it is true,
  3341                                  ;then no change.  Otherwise, DRVLIM_L will be moved to DRVLIM
  3342                                  ;and DRVLIM_L will be set to 0.
  3343                                  ;We don't do this for the bpb information from the boot record. We
  3344                                  ;are not going to change the BPB information from the boot record.
  3345                                  Massage_bpb:				;AN000;
  3346                                   assume es:nothing
  3347 00000C8D 8B551D                  	mov	dx, [di + DRVLIM_H]	;AN000;
  3348 00000C90 8B451B                  	mov	ax, [di + DRVLIM_L]	;AN000;
  3349 00000C93 83FA00                  	cmp	dx,0			;AN000; Double word total sector?
  3350 00000C96 7716                    	ja	init_GOODRET		;AN000; don't have to change it.
  3351 00000C98 837D1900                	cmp	word [di + HIDSEC_H], 0	;AN000;
  3352 00000C9C 7710                    	ja	init_GOODRET		;AN000; don't have to change it.
  3353 00000C9E 034517                  	add	ax, [di + HIDSEC_L]	;AN000;
  3354 00000CA1 720B                    	jc	init_GOODRET		;AN000; bigger than a word boundary
  3355 00000CA3 8B451B                  	mov	ax, [di + DRVLIM_L]	;AN000;
  3356 00000CA6 89450E                  	mov	[di + DRVLIM], ax 	;AN000;
  3357 00000CA9 C7451B0000              	mov	word [di + DRVLIM_L], 0	;AN000;
  3358                                  init_GOODRET:
  3359 00000CAE 837D1D00                	cmp	word [di + DRVLIM_H], 0	;AN014; Big media?
  3360 00000CB2 760F                    	jbe	Not_BigMedia		;AN014; No.
  3361 00000CB4 06                      	push	es			;AN014;
  3362 00000CB5 50                      	push	ax			;AN014;
  3363 00000CB6 B8[ssss]                	mov	ax, SYSINITSEG		;AN014;
  3364 00000CB9 8EC0                    	mov	es, ax			;AN014;
  3365                                   assume es:SYSINITGROUP
  3366 00000CBB 26C606[0000]01          	mov	byte [es:Big_Media_Flag], 1	;AN014; Set the flag in SYSINITSEG.
  3367 00000CC1 58                      	pop	ax			;AN014;
  3368 00000CC2 07                      	pop	es			;AN014;
  3369                                   assume es:nothing
  3370                                  Not_BigMedia:				;AN014;
  3371 00000CC3 2E8A1E[0700]            	MOV	BL,[cs:FBIGFAT]
  3372 00000CC8 885D1F                  	MOV	[DI + FATSIZ],BL		; SET SIZE OF FAT ON MEDIA
  3373                                  
  3374                                  partition_reject:
  3375 00000CCB 0E                      	 push cs
  3376 00000CCC 1F                      	 pop ds
  3377                                   assume ds:SYSINITGROUP
  3378 00000CCD E830F7                  	call upb_reset
  3379 00000CD0 07                      	pop es
  3380                                   assume es:SYSINITGROUP
  3381 00000CD1 5E                      	pop si
  3382 00000CD2 5D                      	pop bp
  3383 00000CD3 5F                      	pop di
  3384 00000CD4 59                      	pop cx
  3385 00000CD5 C3                      	retn
  3386                                  
  3387                                  
  3388                                  		; INP:	es:bx -> transfer address
  3389                                  		;	cl = count
  3390                                  		;	ch = 02h (function code for read CHS)
  3391                                  		;	dx:ax = sector number
  3392                                  		;	ds:di -> UPB
  3393                                  		; CHG:	ax, cx, dx
  3394                                  		; OUT:	CY if error,
  3395                                  		;	 ah = error code
  3396                                  		;	NC if success
  3397                                  readsector_detect:
  3398                                   assume ds:UPB, es:nothing, ss:nothing
  3399 00000CD6 51                      	push cx
  3400 00000CD7 52                      	push dx
  3401 00000CD8 8A5504                  	mov dl, byte ptr [di + DRIVENUM]
  3402 00000CDB E83800                  	call detectlba
  3403 00000CDE 5A                      	pop dx
  3404 00000CDF 59                      	pop cx
  3405 00000CE0 EB08                    	jmp readsector_NC_LBA
  3406                                  
  3407                                  readsector_flag:
  3408                                   assume ds:UPB, es:nothing, ss:nothing
  3409 00000CE2 F745230004              	test word ptr [di + FLAGS], F_LBA
  3410 00000CE7 7501                    	jnz readsector_NC_LBA		; --> (NC)
  3411 00000CE9 F9                      	stc
  3412                                  
  3413                                  readsector_NC_LBA:
  3414 00000CEA 1E                      	push ds
  3415 00000CEB 56                      	push si
  3416 00000CEC 720D                    	jc readsector_chs
  3417                                  readsector_lba:
  3418 00000CEE FF7504                  	push word ptr [di + DRIVENUM]
  3419 00000CF1 E8D6FCEB02[0000]        	neartransfer lba_packet_setup
  3420                                   assume ds:DOSGROUP
  3421 00000CF8 5A                      	pop dx				; dl = unit
  3422 00000CF9 EB12                    	jmp readsector_common
  3423                                  
  3424                                  readsector_chs:
  3425 00000CFB 51                      	push cx
  3426 00000CFC E8CBFCEB02[0000]        	neartransfer lbatochs
  3427 00000D03 58                      	pop ax
  3428 00000D04 720C                    	jc readsector_ret_ah
  3429 00000D06 E8C1FCEB02[0000]        	neartransfer chstotuple
  3430                                  
  3431                                  readsector_common:
  3432 00000D0D CD13                    	int 13h
  3433                                  readsector_ret:
  3434 00000D0F 5E                      	pop si
  3435 00000D10 1F                      	pop ds
  3436                                   assume ds:UPB
  3437 00000D11 C3                      	retn
  3438                                  
  3439                                  readsector_ret_ah:
  3440 00000D12 B404                    	mov ah, 04h			; sector not found
  3441 00000D14 EBF9                    	jmp readsector_ret
  3442                                  
  3443                                  
  3444                                  		; INP:	dl = unit number
  3445                                  		; OUT:	CY no LBA
  3446                                  		;	NC LBA
  3447                                  		; CHG:	cx
  3448                                  detectlba:
  3449                                   assume ds:nothing, es:nothing, ss:nothing
  3450 00000D16 50                      	push ax
  3451 00000D17 53                      	push bx
  3452 00000D18 52                      	push dx
  3453 00000D19 1E                      	push ds
  3454                                  
  3455 00000D1A B84000                  	mov ax, 40h
  3456 00000D1D 8ED8                    	mov ds, ax
  3457                                   assume ds:nothing
  3458                                  ; Setting ds = 40h is a Book8088 bugfix, refer to
  3459                                  ;  http://www.bttr-software.de/forum/forum_entry.php?id=21061
  3460                                  
  3461 00000D1F B80041                  	mov ax, 4100h
  3462 00000D22 BBAA55                  	mov bx, 55AAh
  3463 00000D25 31C9                    	xor cx, cx
  3464 00000D27 30F6                    	xor dh, dh
  3465 00000D29 F9                      	stc
  3466 00000D2A CD13                    	int 13h
  3467 00000D2C 1F                      	pop ds
  3468                                   assume ds:nothing
  3469 00000D2D 720A                    	jc detectlba_ret		; --> CY
  3470 00000D2F 81FB55AA                	cmp bx, 0AA55h
  3471 00000D33 F9                      	stc				; CY
  3472 00000D34 7503                    	jne detectlba_ret
  3473 00000D36 D1E9                    	shr cx, 1			; CY if have LBA access functions
  3474 00000D38 F5                      	cmc				; NC if have
  3475                                  detectlba_ret:
  3476 00000D39 5A                      	pop dx
  3477 00000D3A 5B                      	pop bx
  3478 00000D3B 58                      	pop ax
  3479 00000D3C C3                      	ret
  3480                                  
  3481                                  
  3482                                  Cover_FDISK_Bug		proc			      ;AN010;
  3483                                   assume ds:UPB, es:DOSENTRYGROUP, ss:nothing
  3484                                  ;FDISK of PC DOS 3.3 and below, OS2 1.0 has a bug.  The maximum number of
  3485                                  ;sector that can be handled by PC DOS 3.3 ibmbio should be 0FFFFh.
  3486                                  ;Instead, sometimes FDISK use 10000h to calculate the maximum number.
  3487                                  ;So, we are going to check that if SECNUM + Hidden sector = 10000h
  3488                                  ;then subtrack 1 from SECNUM.
  3489 00000D3D 50                      	push	ax				      ;AN010;
  3490 00000D3E 52                      	push	dx				      ;AN010;
  3491 00000D3F 56                      	push	si				      ;AN010;
  3492 00000D40 26803E[0000]29          	cmp	byte [es:Ext_Boot_Sig], EXT_BOOT_SIGNATURE ;AN010;
  3493 00000D46 742E                    	je	CFB_Retit			      ;AN010;if extended BPB, then >= PC DOS 4.00
  3494 00000D48 26817F073130            	cmp	word ptr [es:bx+7], ("0" << 8) + "1"   ;AN011; OS2 1.0 ? = IBM 10.0
  3495 00000D4E 7507                    	jne	CFB_Chk_SECNUM			      ;AN010;
  3496 00000D50 26807F0A30              	cmp	byte ptr [es:bx+10], "0"              ;AN010;
  3497 00000D55 751F                    	jne	CFB_Retit			      ;AN010;
  3498                                  CFB_Chk_SECNUM:					      ;AN010;
  3499                                  BPB_In_Sector equ Bpb_In_Sector	; NASM port label
  3500 00000D57 BE[0000]                	mov	si, offset BPB_In_Sector	      ;AN010;
  3501 00000D5A 26837C0800              	cmp	word [es:si + SECNUM], 0		      ;AN010;Just to make sure.
  3502 00000D5F 7415                    	je	CFB_Retit			      ;AN010;
  3503 00000D61 268B4408                	mov	ax, [es:si + SECNUM]		      ;AN010;
  3504 00000D65 26034411                	add	ax, [es:si + HIDDEN_L]		      ;AN010;
  3505 00000D69 730B                    	jnc	CFB_Retit			      ;AN010;
  3506 00000D6B 85C0                    	test	ax, ax				      ;AN010;if carry set and AX=0?
  3507 00000D6D 7507                    	jnz	CFB_Retit			      ;AN010;
  3508 00000D6F 26FF4C08                	dec	word [es:si + SECNUM]			      ;AN010;  then decrease SECNUM by 1.
  3509 00000D73 FF4D1B                  	dec	word [di + DRVLIM_L]			      ;AN010;
  3510                                  CFB_Retit:					      ;AN010;
  3511 00000D76 5E                      	pop	si				      ;AN010;
  3512 00000D77 5A                      	pop	dx				      ;AN010;
  3513 00000D78 58                      	pop	ax				      ;AN010;
  3514 00000D79 C3                      	ret					      ;AN010;
  3515                                  Cover_FDISK_Bug		endp			      ;AN010;
  3516                                  
  3517                                  
  3518                                  ; SETDRVPARMS SETS UP THE RECOMMENDED BPB IN EACH BDS IN THE SYSTEM BASED ON
  3519                                  ; THE FORM FACTOR. IT IS ASSUMED THAT THE BPBS FOR THE VARIOUS FORM FACTORS
  3520                                  ; ARE PRESENT IN THE BPBTABLE. FOR HARD FILES, THE RECOMMENDED BPB IS THE SAME
  3521                                  ; AS THE BPB ON THE DRIVE.
  3522                                  
  3523                                  ; NO ATTEMPT IS MADE TO PRESERVE REGISTERS SINCE WE ARE GOING TO JUMP TO
  3524                                  ; SYSINIT STRAIGHT AFTER THIS ROUTINE.
  3525                                  
  3526                                  SETDRVPARMS PROC NEAR
  3527                                   assume ds:nothing, es:nothing, ss:nothing
  3528                                  	MESSAGE FTESTINIT,<"SETTING DRIVE PARAMETERS",CR,LF>
  3529 00000D7A 31DB                    	XOR	BX,BX
  3530 00000D7C E82DFC                  	call sysinit_get_es_dosbiodata
  3531                                   assume es:DOSGROUP
  3532 00000D7F 26C43E[0000]            	LES	DI,[es:START_BDS] ; GET FIRST BDS IN LIST
  3533                                   assume es:UPB
  3534                                  NEXT_BDS:
  3535 00000D84 83FFFF                  	CMP	DI,-1
  3536 00000D87 7501                    	JNZ	DO_SETP
  3537                                  DONE_SETPARMS:
  3538 00000D89 C3                      	RET
  3539                                  
  3540                                  DO_SETP:
  3541                                   assume es:UPB
  3542 00000D8A 06                      	PUSH	ES
  3543 00000D8B 57                      	PUSH	DI			; PRESERVE POINTER TO BDS
  3544 00000D8C 268A5D22                	MOV	BL,[ES:DI + FORMFACTOR]
  3545 00000D90 80FB05                  	CMP	BL,FFHARDFILE
  3546 00000D93 7541                    	JNZ	NOTHARDFF
  3547                                  
  3548 00000D95 31D2                    	xor	dx,dx			;AN000;
  3549 00000D97 268B450E                	MOV	AX,[ES:DI + DRVLIM]
  3550 00000D9B 85C0                    	test ax, ax			;AN000;
  3551 00000D9D 7508                    	jnz	GET_cCYL		;AN000;
  3552 00000D9F 268B551D                	mov	dx,[es:di + DRVLIM_H]	;AN000; Use Double word sector number
  3553 00000DA3 268B451B                	MOV	AX,[ES:DI + DRVLIM_L]	;AN000;
  3554                                  GET_cCYL:
  3555 00000DA7 52                      	push	dx			;AN000;
  3556 00000DA8 50                      	PUSH	AX
  3557 00000DA9 268B4515                	MOV	AX,WORD PTR [ES:DI + HDLIM]
  3558 00000DAD 26F76513                	MUL	WORD PTR [ES:DI + SECLIM] ;Assume Sectorsp per cyl. < 64K.
  3559 00000DB1 89C1                    	MOV	CX,AX			; CX HAS # SECTORS PER CYLINDER
  3560 00000DB3 58                      	POP	AX			;
  3561 00000DB4 5A                      	pop	dx			;AN000; Restore drvlim.
  3562 00000DB5 50                      	push	ax			;AN000;
  3563 00000DB6 92                      	xchg	ax, dx			; ax = high word, clobber dx
  3564 00000DB7 31D2                    	xor	dx,dx			;AN000;
  3565 00000DB9 F7F1                    	div	cx			;AN000;
  3566 00000DBB 1E                      	push ds
  3567 00000DBC E8DCFB                  	call sysinit_get_ds_dosbiodata
  3568                                   assume ds:DOSGROUP
  3569 00000DBF A3[0000]                	mov	[Temp_H],ax		;AN000; AX be 0 here.
  3570 00000DC2 1F                      	pop ds
  3571                                   assume ds:nothing
  3572 00000DC3 58                      	pop	ax			;AN000;
  3573 00000DC4 F7F1                    	DIV	CX			; DIV #SEC BY SEC/CYL TO GET # CYL.
  3574 00000DC6 09D2                    	OR	DX,DX
  3575 00000DC8 7401                    	JZ	NO_CYL_RND		; CAME OUT EVEN
  3576 00000DCA 40                      	INC	AX			; ROUND UP
  3577                                  NO_CYL_RND:
  3578 00000DCB 26894525                	MOV	[ES:DI + CCYLN],AX
  3579                                  	MESSAGE FTESTINIT,<"CCYLN ">
  3580                                  	MNUM	FTESTINIT,AX
  3581                                  	MESSAGE FTESTINIT,<CR,LF>
  3582 00000DCF 06                      	PUSH	ES
  3583 00000DD0 1F                      	POP	DS
  3584                                   assume ds:UPB
  3585 00000DD1 8D7506                  	LEA	SI,[DI + BYTEPERSEC]	; DS:SI -> BPB FOR HARD FILE
  3586 00000DD4 EB3B                    	JMP	SHORT SET_RECBPB
  3587                                  
  3588                                  NOTHARDFF:
  3589                                  ;J.K. We don't use the extended BPB for a floppy.
  3590                                  ;J.K.6/24/87
  3591                                  
  3592                                  ;SB34INIT007******************************************************************
  3593                                  ;SB	If Fake floppy drive variable is set then we don't have to handle this
  3594                                  ;SB	BDS.  We can just go and deal with the next BDS at label Go_To_Next_BDS.
  3595                                  
  3596 00000DD6 2E803E[0600]01          	cmp	byte [cs:FakeFloppyDrv],1
  3597                                  Go_To_Next_BDS equ GO_TO_NEXT_BDS	; NASM port label
  3598 00000DDC 743B                    	jz	Go_To_Next_BDS
  3599                                  ;SB34INIT007******************************************************************
  3600                                  
  3601 00000DDE 80FB07                  	CMP	BL,FFOTHER		; SPECIAL CASE "OTHER" TYPE OF MEDIUM
  3602 00000DE1 7526                    	JNZ	NOT_PROCESS_OTHER
  3603                                  PROCESS_OTHER:
  3604 00000DE3 268B4525                	MOV	AX,[es:DI + CCYLN]
  3605 00000DE7 26F76536                	mul word [es:DI + RHDLIM]
  3606 00000DEB 26F76534                	mul word [es:DI + RSECLIM]
  3607 00000DEF 2689452F                	MOV	[es:DI + RDRVLIM],AX 	; HAVE THE TOTAL NUMBER OF SECTORS
  3608 00000DF3 48                      	DEC	AX
  3609                                  
  3610                                  ;J.K. Old logic was...
  3611                                  ;	 MOV	 BX,515
  3612                                  ;	 DIV	 BX
  3613                                  ;	 OR	 DX,DX
  3614                                  ;	 JZ	 NO_ROUND_UP
  3615                                  ;	 INC	 AX			 ; ROUND UP NUMBER OF FAT SECTORS
  3616                                  
  3617                                  ;J.K. New logic to get the sectors/fat area.
  3618                                  					;Fat entry is assumed to be 1.5 bytes!!!
  3619 00000DF4 BB0300                  	mov	bx, 3
  3620 00000DF7 F7E3                    	mul	bx
  3621 00000DF9 4B                      	dec bx				; = 2
  3622 00000DFA F7F3                    	div	bx
  3623 00000DFC 31D2                    	xor	dx, dx
  3624 00000DFE 86DF                    	xchg bl, bh			; bh = 2, bl = 0, bx = 512
  3625 00000E00 F7F3                    	div	bx
  3626 00000E02 40                      	inc	ax
  3627                                  
  3628                                  NO_ROUND_UP:
  3629 00000E03 26894532                	MOV	[es:DI + RCSECFAT],AX
  3630 00000E07 EB10                    	JMP	SHORT GO_TO_NEXT_BDS
  3631                                  NOT_PROCESS_OTHER:
  3632 00000E09 D1E3                    	SHL	BX,1			; BX IS WORD INDEX INTO TABLE OF BPBS
  3633 00000E0B 0E                      	push cs
  3634 00000E0C 1F                      	pop ds
  3635                                   assume ds:SYSINITGROUP
  3636 00000E0D 8BB7[7001]              	MOV	SI,WORD PTR [BPBTABLE + BX]	; GET ADDRESS OF BPB ; access with ds
  3637                                  SET_RECBPB:
  3638 00000E11 8D7D27                  	LEA	DI,[DI + RBYTEPERSEC]	; ES:DI -> RECBPB
  3639 00000E14 B91900                  	MOV	CX,BPBSIZ
  3640 00000E17 F3A4                    	REP	MOVSB			; MOVE BPBSIZ BYTES
  3641                                  GO_TO_NEXT_BDS:
  3642 00000E19 5F                      	POP	DI
  3643 00000E1A 07                      	POP	ES			; RESTORE POINTER TO BDS
  3644                                   assume es:UPB
  3645 00000E1B 26C43D                  	les di, [ES:DI + LINK]
  3646 00000E1E E963FF                  	JMP	NEXT_BDS
  3647                                  
  3648                                  SETDRVPARMS ENDP
  3649                                  
  3650                                  
  3651                                  usesection DOSENTRYINIT
  3652                                  
  3653                                  ;
  3654                                  ; SI POINTS TO DEVICE HEADER
  3655                                  ; J.K. 4/22/86 - print_init, aux_init is modified to eliminate the self-modifying
  3656                                  ; J.K. code.
  3657                                  
  3658                                  PRINT_INIT:
  3659                                  Get_device_number equ GET_DEVICE_NUMBER	; NASM port label
  3660 0000071C E80F00                  	call	Get_device_number
  3661                                  ;SB33028*****************************************************************
  3662 0000071F B401                    	mov	ah,1			;initalize printer port        ;SB;3.30
  3663 00000721 CD17                    	int	17h			;call ROM-Bios routine	       ;SB;3.30
  3664                                  ;SB33028*****************************************************************
  3665 00000723 C3                      	ret
  3666                                  
  3667                                  AUX_INIT:
  3668 00000724 E80700                  	call	Get_device_number
  3669                                  ;SB33028*****************************************************************
  3670 00000727 B0A3                    	mov	al,RSINIT		;2400,N,1,8 (MSEQU.INC)       ;SB ;3.30*
  3671 00000729 B400                    	mov	ah,0			;initalize AUX port	      ;SB ;3.30*
  3672 0000072B CD14                    	int	14h			;call ROM-Bios routine	      ;SB ;3.30*
  3673                                  ;SB33028*****************************************************************
  3674 0000072D C3                      	ret
  3675                                  
  3676                                  GET_DEVICE_NUMBER:
  3677                                  ;SI -> device header
  3678 0000072E 2E8A440D                	MOV	AL,[CS:SI+13]		;GET DEVICE NUMBER FROM THE NAME
  3679 00000732 2C31                    	SUB	AL,"1"
  3680 00000734 98                      	CBW
  3681 00000735 89C2                    	MOV	DX,AX
  3682 00000737 C3                      	RET
  3683                                  
  3684                                  %if 0
  3685                                  ;
  3686                                  ;   PURGE_96TPI NOP'S CALLS TO 96TPI SUPPORT.
  3687                                  ;
  3688                                  PURGE_96TPI PROC NEAR			;MJB001
  3689                                  	PUSH	DS
  3690                                  	PUSH	ES
  3691                                  
  3692                                  	PUSH	CS			;MJB001
  3693                                  	POP	ES			;MJB001
  3694                                  	PUSH	CS			;MJB001
  3695                                  	POP	DS			;MJB001
  3696                                  	; ASSUME	DS:BIOCODE,ES:BIOCODE
  3697                                  
  3698                                  	MOV	SI,OFFSET PATCHTABLE
  3699                                  PATCHLOOP:
  3700                                  	LODSW
  3701                                  	MOV	CX,AX
  3702                                  	JCXZ	PATCHDONE
  3703                                  	LODSW
  3704                                  	MOV	DI,AX
  3705                                  	MOV	AL,90H
  3706                                  	REP	STOSB
  3707                                  	JMP	PATCHLOOP
  3708                                  
  3709                                  PATCHDONE:
  3710                                  ;**************NOT NEEDED ANY MORE***********************
  3711                                  ;	MOV	DI,OFFSET FORMAT_PATCH	     ; ARR 2.42
  3712                                  ;	MOV	AL,CS:INST_FAR_RET
  3713                                  ;	STOSB
  3714                                  ;********************************************************
  3715                                  	MOV	DI,OFFSET TABLE_PATCH	; ARR 2.42
  3716                                  	MOV	AX,OFFSET EXIT
  3717                                  	STOSW
  3718                                  	STOSW
  3719                                  
  3720                                  	POP	ES
  3721                                  	POP	DS
  3722                                  	RET				;MJB001
  3723                                  PURGE_96TPI ENDP
  3724                                  %endif
  3725                                  
  3726                                  
  3727                                  usesection SYSINITTRAIL
  3728                                  
  3729                                  set_bpb:
  3730 00000E21 56                      	push si
  3731 00000E22 53                      	push	bx			; now, set the DskDrvs pointer to BPB info
  3732 00000E23 2E8B1E[DE00]            	mov	bx, [cs:Mini_BPB_ptr]
  3733 00000E28 8D7506                  	lea	si, [di + BYTEPERSEC]	; points to BPB of BDSM
  3734 00000E2B 2E8937                  	mov	[cs:bx], si
  3735 00000E2E 43                      	inc bx
  3736 00000E2F 43                      	inc bx
  3737 00000E30 2E891E[DE00]            	mov word [cs:Mini_BPB_ptr], bx	; advance to the next address
  3738 00000E35 5B                      	pop	bx
  3739 00000E36 5E                      	pop si
  3740 00000E37 C3                      	retn
  3741                                  
  3742                                  have_bpb:
  3743 00000E38 2E813E[DE00][2001]      	cmp word [cs:Mini_BPB_ptr], DSKDRVS.end
  3744                                  					; CY if valid to append another
  3745 00000E3F F5                      	cmc				; NC if valid
  3746 00000E40 C3                      	retn
  3747                                  
  3748                                  
  3749                                  ;
  3750                                  ;Install BDSM installs a BDSM (pointed by DS:DI) into the end of the current
  3751                                  ;linked list of BDS.
  3752                                  ;Also, set the current BDSM pointer segment to DS.
  3753                                  ;At entry: DS:DI -> BDSM
  3754                                  ;
  3755                                  Install_BDSM_and_set_bpb:
  3756                                   assume ds:UPB, es:nothing, ss:nothing
  3757 00000E41 E8DDFF                  	call set_bpb
  3758                                  Install_BDSM:
  3759                                   assume ds:UPB, es:nothing, ss:nothing
  3760 00000E44 50                      	push	ax
  3761 00000E45 56                      	push	si
  3762 00000E46 06                      	push	es
  3763                                  
  3764                                   extern sysinit_have_bootdrive_preliminary
  3765                                   extern sysinit_have_bootdrive_exact
  3766 00000E47 2ED006[0000]            	rol byte [cs:sysinit_have_bootdrive_exact], 1
  3767 00000E4C 7242                    	jc .skip
  3768                                  
  3769 00000E4E F6452310                	testopt [di + FLAGS], FI_AM_MULT
  3770 00000E52 7406                    	jz @F
  3771 00000E54 F6452320                	testopt [di + FLAGS], FI_OWN_PHYSICAL
  3772 00000E58 7436                    	jz .skip
  3773                                  @@:
  3774 00000E5A 2EA0[0000]              	mov al, [cs:sysinit_bootdrive_unit]
  3775 00000E5E 3A4504                  	cmp al, [di + DRIVENUM]
  3776 00000E61 752D                    	jne .skip
  3777 00000E63 2EA1[0000]              	mov ax, [cs:sysinit_bootdrive_hidden]
  3778 00000E67 3B4517                  	cmp ax, [di + HIDSEC_L]
  3779 00000E6A 7510                    	jne .prelim
  3780 00000E6C 2EA1[0200]              	mov ax, [cs:sysinit_bootdrive_hidden + 2]
  3781 00000E70 3B4519                  	cmp ax, [di + HIDSEC_H]
  3782 00000E73 7507                    	jne .prelim
  3783 00000E75 2EF616[0000]            	not byte [cs:sysinit_have_bootdrive_exact]
  3784 00000E7A EB0C                    	jmp .save
  3785                                  
  3786                                  .prelim:
  3787 00000E7C 2ED006[0000]            	rol byte [cs:sysinit_have_bootdrive_preliminary], 1
  3788 00000E81 720D                    	jc .skip
  3789 00000E83 2EF616[0000]            	not byte [cs:sysinit_have_bootdrive_preliminary]
  3790                                  .save:
  3791 00000E88 8A4505                  	mov al, [di + DRIVELET]
  3792 00000E8B 40                      	inc ax
  3793 00000E8C 2EA2[0000]              	mov byte [cs:DEFAULT_DRIVE], al
  3794                                  .done:
  3795                                  .skip:
  3796                                  
  3797 00000E90 B8FFFF                  	mov ax, -1
  3798 00000E93 894502                  	mov word ptr [di + LINK + 2], ax
  3799 00000E96 8905                    	mov word ptr [di + LINK], ax	; make sure it is a null ptr.
  3800                                  
  3801 00000E98 E811FB                  	call sysinit_get_es_dosbiodata
  3802                                   assume es:DOSGROUP
  3803                                  Start_BDS equ START_BDS	; NASM port label
  3804 00000E9B 26C436[0000]            	les	si, [es:Start_BDS]	;start of the beginning of list
  3805                                   assume es:UPB
  3806 00000EA0 39C6                    	cmp si, ax
  3807 00000EA2 750F                    	jne I_BDSM_Next
  3808 00000EA4 E805FB                  	call sysinit_get_es_dosbiodata
  3809                                   assume es:DOSGROUP
  3810 00000EA7 26893E[0000]            	mov word [es:Start_BDS], di
  3811 00000EAC 268C1E[0200]            	mov word [es:Start_BDS + 2], ds
  3812 00000EB1 EB11                    	jmp I_BDSM_ret
  3813                                  
  3814                                  I_BDSM_Next:
  3815                                   assume es:UPB
  3816 00000EB3 263904                  	cmp	word ptr [es:si + LINK], ax	;end of the list?
  3817 00000EB6 7405                    	je	I_BDSM_New
  3818 00000EB8 26C434                  	les	si, [es:si + LINK]
  3819 00000EBB EBF6                    	jmp	short I_BDSM_Next
  3820                                  I_BDSM_New:
  3821 00000EBD 268C5C02                	mov	word ptr [es:si + LINK + 2], ds
  3822 00000EC1 26893C                  	mov	word ptr [es:si + LINK], di
  3823                                  
  3824                                  I_BDSM_ret:
  3825 00000EC4 07                      	pop	es
  3826                                   assume es:nothing
  3827 00000EC5 5E                      	pop	si
  3828 00000EC6 58                      	pop	ax
  3829 00000EC7 C3                      	ret
  3830                                  
  3831                                  ;***The following code is not needed any more.	Don't show any
  3832                                  ;***messages to be compatible with the behavior of IBMBIO.COM.
  3833                                  ;;Show the message "Mini disk installed ..."
  3834                                  ;;This routine uses WRMSG procedure which will call OUTCHR.
  3835                                  ;Show_Installed_Mini:
  3836                                  ;	 push	 ax
  3837                                  ;	 push	 bx
  3838                                  ;	 push	 ds
  3839                                  ;
  3840                                  ;	 mov	 al, MiniNum		 ;logical drive number
  3841                                  ;	 add	 al, Drv_Letter_Base	 ;='A'
  3842                                  ;	 mov	 Mini_Drv_Let, al
  3843                                  ;	 mov	 si, offset Installed_Mini
  3844                                  ;	 call	 WRMSG
  3845                                  ;
  3846                                  ;	 pop	 ds
  3847                                  ;	 pop	 bx
  3848                                  ;	 pop	 ax
  3849                                  ;	 ret
  3850                                  ;**End of mini disk initialization**	;J.K. 4/7/86
  3851                                  
  3852                                  msg:
  3853 00000EC8 426F6F74206572726F-     .bootfail:			asciz "Boot error: "
  3853 00000ED1 723A2000           
  3854 00000ED5 52656164696E672070-     .bootfail_read:			db "Reading partition table sector failed (error "
  3854 00000EDE 6172746974696F6E20-
  3854 00000EE7 7461626C6520736563-
  3854 00000EF0 746F72206661696C65-
  3854 00000EF9 6420286572726F7220 
  3855 00000F02 5F5F68292E0D0A00        .bootfail_read_errorcode:	asciz "__h).",13,10
  3856 00000F0A 4475706C6963617465-     .duplicate:			db "Duplicate partition login attempt, unit="
  3856 00000F13 20706172746974696F-
  3856 00000F1C 6E206C6F67696E2061-
  3856 00000F25 7474656D70742C2075-
  3856 00000F2E 6E69743D           
  3857 00000F32 2D2D682C2068696464-     .duplicate_unit:		db "--h, hidden="
  3857 00000F3B 656E3D             
  3858 00000F3E 2D2D2D2D5F              .duplicate_hidden_h:		db "----_"
  3859 00000F43 2D2D2D2D682E0D0A00      .duplicate_hidden_l:		asciz "----h.",13,10
  3860 00000F4C 506172746974696F6E-     .bootfail_sig_parttable:	ascii "Partition table signature missing"
  3860 00000F55 207461626C65207369-
  3860 00000F5E 676E6174757265206D-
  3860 00000F67 697373696E67       
  3861 00000F6D 20286973206E6F7420-     				asciz " (is not AA55h).",13,10
  3861 00000F76 4141353568292E0D0A-
  3861 00000F7F 00                 
  3862 00000F80 546F6F206D616E7920-     .boot_too_many_partitions_error:asciz "Too many partitions (or a loop).",13,10
  3862 00000F89 706172746974696F6E-
  3862 00000F92 7320286F722061206C-
  3862 00000F9B 6F6F70292E0D0A00   
  3863 00000FA3 506172746974696F6E-     .boot_partition_cycle_error:	asciz "Partition table cycle detected.",13,10
  3863 00000FAC 207461626C65206379-
  3863 00000FB5 636C65206465746563-
  3863 00000FBE 7465642E0D0A00     
  3864                                  
  3865                                  
  3866                                  	usesection DOSENTRYINIT
  3867                                  
  3868                                  CMOS_Clock_Read proc	near
  3869                                  ; IN ORDER TO DETERMINE IF THERE IS A CLOCK PRESENT IN THE SYSTEM, THE FOLLOWING
  3870                                  ; NEEDS TO BE DONE.
  3871 00000738 1E                      	push ds
  3872 00000739 E8BCFF                  	call dosentry_init_get_ds_dosbiodata
  3873                                   assume ds:DOSGROUP, es:nothing, ss:nothing
  3874 0000073C 50                      	PUSH	AX
  3875 0000073D 51                      	PUSH	CX
  3876 0000073E 52                      	PUSH	DX
  3877 0000073F 55                      	PUSH	BP
  3878                                  
  3879 00000740 31ED                    	XOR	BP,BP
  3880                                  LOOP_CLOCK:
  3881 00000742 31C9                    	XOR	CX,CX
  3882 00000744 31D2                    	XOR	DX,DX
  3883                                  ;SB33030********************************************************************
  3884 00000746 B402                    	MOV	AH,2			;READ REAL TIME CLOCK	      ;SB ;3.30
  3885 00000748 CD1A                    	INT	1Ah			;CALL ROM-BIOS ROUTINE	      ;SB ;3.30
  3886                                  ;SB33030********************************************************************
  3887 0000074A 83F900                  	CMP	CX,0
  3888 0000074D 7512                    	JNZ	CLOCK_PRESENT
  3889                                  
  3890 0000074F 83FA00                  	CMP	DX,0
  3891 00000752 750D                    	JNZ	CLOCK_PRESENT
  3892                                  
  3893 00000754 83FD01                  	CMP	BP,1			; READ AGAIN AFTER A SLIGHT DELAY, IN CASE CLOCK
  3894 00000757 741C                    	JZ	NO_READDATE		; WAS AT ZERO SETTING.
  3895                                  
  3896 00000759 45                      	INC	BP			; ONLY PERFORM DELAY ONCE.
  3897 0000075A B90040                  	MOV	CX,4000H
  3898                                  DELAY:
  3899 0000075D E2FE                    	LOOP	DELAY
  3900 0000075F EBE1                    	JMP	LOOP_CLOCK
  3901                                  
  3902                                  CLOCK_PRESENT:
  3903 00000761 C606[0000]01            	mov	byte [HaveCMOSClock], 1	;J.K. Set the flag for cmos clock
  3904                                  
  3905 00000766 E82E00                  	call	CMOSCK			;J.K. Reset CMOS clock rate that may be
  3906                                  					;possibly destroyed by CP DOS and POST routine did not
  3907                                  					;restore that.
  3908                                  
  3909 00000769 56                      	PUSH	SI
  3910                                  	MESSAGE FTESTINIT,<"CLOCK DEVICE",CR,LF>
  3911 0000076A 0E                      	push cs
  3912 0000076B E80D00                  	call transfer_read_real_date	;MJB002 READ REAL-TIME CLOCK FOR DATE
  3913                                  
  3914 0000076E FA                      	CLI				;MJB002
  3915 0000076F 8936[0000]              	MOV	[DAYCNT],SI	      ;MJB002 SET SYSTEM DATE
  3916 00000773 FB                      	STI				;MJB002
  3917 00000774 5E                      	POP	SI			;MJB002
  3918                                  NO_READDATE:
  3919 00000775 5D                      	POP	BP
  3920 00000776 5A                      	POP	DX
  3921 00000777 59                      	POP	CX
  3922 00000778 58                      	POP	AX
  3923 00000779 1F                      	pop ds
  3924                                   assume ds:nothing
  3925 0000077A C3                      	RET
  3926                                  
  3927                                  		; INP:	dword [ss:sp] = far return address
  3928                                  transfer_read_real_date:
  3929                                   assume ds:nothing, es:nothing, ss:nothing
  3930 0000077B 50                      	push ax
  3931 0000077C 50                      	push ax
  3932 0000077D B8[D800]                	mov ax, near_read_real_date
  3933 00000780 50                      	push ax
  3934                                  	lframe 0
  3935                                  	lpar word, orig_ax_near_ret		; original ax
  3936                                  	lpar word, transfer_segment
  3937                                  	lpar word, transfer_offset		; already initialised
  3938 00000781 5589E5                  	lenter
  3939 00000784 1E                      	push ds
  3940 00000785 E870FF                  	call dosentry_init_get_ds_dosdata
  3941                                   assume ds:DOSGROUP
  3942 00000788 A1[0000]                	mov ax, word [dosdata_to_doscode]
  3943 0000078B 1F                      	pop ds
  3944                                   assume ds:nothing
  3945 0000078C 894604                  	mov word [bp + ?transfer_segment], ax
  3946                                   extern biocode_retf
  3947 0000078F B8[0000]                	mov ax, biocode_retf
  3948 00000792 874606                  	xchg ax, word [bp + ?orig_ax_near_ret]
  3949 00000795 5D                      	lleave
  3950 00000796 CB                      	retf
  3951                                  
  3952                                  
  3953                                  CMOS_Clock_Read endp
  3954                                  ;
  3955                                  ;J.K. 10/28/86
  3956                                  ;J.K. THE FOLLOWING CODE IS WRITTEN BY JACK GULLEY IN ENGINEERING GROUP.
  3957                                  ;J.K. CP DOS IS CHANGING CMOS CLOCK RATE FOR ITS OWN PURPOSES AND IF THE
  3958                                  ;J.K. USE COLD BOOT THE SYSTEM TO USE PC DOS WHILE RUNNING CP DOS, THE CMOS
  3959                                  ;J.K. CLOCK RATE ARE STILL SLOW WHICH SLOW DOWN DISK OPERATIONS OF PC DOS
  3960                                  ;J.K. WHICH USES CMOS CLOCK.  PC DOS IS PUT THIS CODE IN MSINIT TO FIX THIS
  3961                                  ;J.K. PROBLEM AT THE REQUEST OF CP DOS.
  3962                                  ;J.K. THE PROGRAM IS MODIFIED TO BE RUN ON MSINIT. Equates are defined in CMOSEQU.INC.
  3963                                  ;J.K. This program will be called by CMOS_Clock_Read procedure.
  3964                                  ;
  3965                                  ;  The following code CMOSCK is used to insure that the CMOS has not
  3966                                  ;	had its rate controls left in an invalid state on older AT's.
  3967                                  ;
  3968                                  ;	It checks for an AT model byte "FC" with a submodel type of
  3969                                  ;	00, 01, 02, 03 or 06 and resets the periodic interrupt rate
  3970                                  ;	bits incase POST has not done it.  This initilization routine
  3971                                  ;	is only needed once when DOS loads.  It should be ran as soon
  3972                                  ;	as possible to prevent slow diskette access.
  3973                                  ;
  3974                                  ;	This code exposes one to DOS clearing CMOS setup done by a
  3975                                  ;	resident program that hides and re-boots the system.
  3976                                  ;
  3977                                  CMOSCK	PROC	NEAR			;	CHECK AND RESET RTC RATE BITS
  3978                                   assume ds:DOSGROUP, es:nothing
  3979                                  
  3980                                  ;Model byte and Submodel byte were already determined in MSINIT.
  3981 00000797 50                      	push	ax
  3982                                  Model_byte equ Model_Byte	; NASM port label
  3983 00000798 803E[0000]FC            	cmp	byte [Model_byte], 0FCh	;check for PC-AT model byte
  3984                                  					 ;	 EXIT IF NOT "FC" FOR A PC-AT
  3985 0000079D 7523                    	JNE	CMOSCK9 		; Exit if not an AT model
  3986                                  
  3987 0000079F 803E[0000]06            	CMP	byte [Secondary_Model_Byte],06H  ; Is it 06 for the industral AT
  3988 000007A4 7407                    	JE	CMOSCK4 		; Go reset CMOS periodic rate if 06
  3989 000007A6 803E[0000]04            	CMP	byte [Secondary_Model_Byte],04H  ; Is it 00, 01, 02, or 03
  3990 000007AB 7315                    	JNB	CMOSCK9 		; EXIT if problem fixed by POST
  3991                                  					;J.K. Also,Secondary_model_byte = 0 when AH=0c0h, int 15h failed.
  3992                                  CMOSCK4:				;	RESET THE CMOS PERIODIC RATE
  3993                                  					;  Model=FC submodel=00,01,02,03 or 06
  3994                                  ;SB33IN2***********************************************************************
  3995                                  
  3996 000007AD B08A                    	mov	al,CMOS_REG_A | NMI	;NMI disabled on return
  3997 000007AF B426                    	mov	ah,00100110b		;Set divider & rate selection
  3998 000007B1 E83000                  	call	CMOS_WRITE
  3999                                  
  4000                                  ;SB33IN2***********************************************************************
  4001                                  
  4002                                  					;	CLEAR SET,PIE,AIE,UIE AND SQWE
  4003 000007B4 B08B                    	mov	al,CMOS_REG_B | NMI	;NMI disabled on return
  4004 000007B6 E80B00                  	call	CMOS_READ
  4005 000007B9 2407                    	and	al,00000111b		;clear SET,PIE,AIE,UIE,SQWE
  4006 000007BB 88C4                    	mov	ah,al
  4007 000007BD B00B                    	mov	al,CMOS_REG_B		;NMI enabled on return
  4008 000007BF E82200                  	call	CMOS_WRITE
  4009                                  
  4010                                  ;SB33IN3***********************************************************************
  4011                                  
  4012                                  CMOSCK9:				;	EXIT ROUTINE
  4013 000007C2 58                      	pop	ax
  4014 000007C3 C3                      	RET				; RETurn to caller
  4015                                  					;  Flags modifyied
  4016                                  CMOSCK	ENDP
  4017                                  ;PAGE
  4018                                  ;--- CMOS_READ -----------------------------------------------------------------
  4019                                  ;		READ BYTE FROM CMOS SYSTEM CLOCK CONFIGURATION TABLE	       :
  4020                                  ;									       :
  4021                                  ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE READ				       :
  4022                                  ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
  4023                                  ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO READ		       :
  4024                                  ;									       :
  4025                                  ; OUTPUT: (AL)	VALUE AT LOCATION (AL) MOVED INTO (AL).  IF BIT 7 OF (AL) WAS  :
  4026                                  ;		ON THEN NMI LEFT DISABLED.  DURING THE CMOS READ BOTH NMI AND  :
  4027                                  ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
  4028                                  ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
  4029                                  ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
  4030                                  ;		ONLY THE (AL) REGISTER AND THE NMI STATE IS CHANGED.	       :
  4031                                  ;-------------------------------------------------------------------------------
  4032                                  
  4033                                  CMOS_READ	PROC	NEAR		;	READ LOCATION (AL) INTO (AL)
  4034                                   assume es:nothing,ds:nothing
  4035 000007C4 9C                      	PUSHF				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
  4036                                  ;SB33IN4********************************************************************
  4037                                  
  4038 000007C5 FA                      	cli
  4039 000007C6 53                      	push	bx
  4040 000007C7 50                      	push	ax			;save user NMI state
  4041 000007C8 0C80                    	or	al,NMI			;disable NMI for us
  4042 000007CA E670                    	out	CMOS_PORT,al
  4043 000007CC 90                      	nop				;undocumented delay needed
  4044 000007CD E471                    	in	al,CMOS_DATA		;get data value
  4045                                  
  4046                                  	 ;set NMI state to user specified 
  4047 000007CF 89C3                    	mov	bx,ax			;save data value
  4048 000007D1 58                      	pop	ax			;get user NMI
  4049 000007D2 2480                    	and	al,NMI
  4050 000007D4 0C0F                    	or	al,CMOS_SHUT_DOWN
  4051 000007D6 E670                    	out	CMOS_PORT,al
  4052 000007D8 90                      	nop
  4053 000007D9 E471                    	in	al,CMOS_DATA
  4054                                  
  4055 000007DB 89D8                    	mov	ax,bx			;data value
  4056 000007DD 5B                      	pop	bx
  4057                                  
  4058                                  ;SB33IN4********************************************************************
  4059 000007DE 0E                      	PUSH	CS			; *PLACE CODE SEGMENT IN STACK AND
  4060 000007DF E80100                  	CALL	CMOS_POPF		; *HANDLE POPF FOR B- LEVEL 80286
  4061 000007E2 C3                      	RET				; RETURN WITH FLAGS RESTORED
  4062                                  
  4063                                  CMOS_READ	ENDP
  4064                                  
  4065                                  CMOS_POPF	PROC	NEAR		;	POPF FOR LEVEL B- PARTS
  4066 000007E3 CF                      	IRET				; RETURN FAR AND RESTORE FLAGS
  4067                                  
  4068                                  CMOS_POPF	ENDP
  4069                                  
  4070                                  ;--- CMOS_WRITE ----------------------------------------------------------------
  4071                                  ;		WRITE BYTE TO CMOS SYSTEM CLOCK CONFIGURATION TABLE	       :
  4072                                  ;									       :
  4073                                  ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE WRITTEN TO			       :
  4074                                  ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
  4075                                  ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO WRITE		       :
  4076                                  ;	 (AH)=	NEW VALUE TO BE PLACED IN THE ADDRESSED TABLE LOCATION	       :
  4077                                  ;									       :
  4078                                  ; OUTPUT:	VALUE IN (AH) PLACED IN LOCATION (AL) WITH NMI LEFT DISABLED   :
  4079                                  ;		IF BIT 7 OF (AL) IS ON.  DURING THE CMOS UPDATE BOTH NMI AND   :
  4080                                  ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
  4081                                  ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
  4082                                  ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
  4083                                  ;		ONLY THE CMOS LOCATION AND THE NMI STATE IS CHANGED.	       :
  4084                                  ;-------------------------------------------------------------------------------
  4085                                  
  4086                                  CMOS_WRITE	PROC	NEAR		;	WRITE (AH) TO LOCATION (AL)
  4087                                   assume es:nothing,ds:nothing
  4088 000007E4 9C                      	PUSHF				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
  4089 000007E5 50                      	PUSH	AX			; SAVE WORK REGISTER VALUES
  4090                                  
  4091 000007E6 FA                      	cli
  4092 000007E7 50                      	push	ax			;save user NMI state
  4093 000007E8 0C80                    	or	al,NMI			;disable NMI for us
  4094 000007EA E670                    	out	CMOS_PORT,al
  4095 000007EC 90                      	nop
  4096 000007ED 88E0                    	mov	al,ah
  4097 000007EF E671                    	out	CMOS_DATA,al		;write data
  4098                                  
  4099                                  	 ;set NMI state to user specified 
  4100 000007F1 58                      	pop	ax 			;get user NMI
  4101 000007F2 2480                    	and	al,NMI
  4102 000007F4 0C0F                    	or	al,CMOS_SHUT_DOWN
  4103 000007F6 E670                    	out	CMOS_PORT,al
  4104 000007F8 90                      	nop
  4105 000007F9 E471                    	in	al,CMOS_DATA
  4106                                  
  4107                                  ;SB33IN5********************************************************************
  4108 000007FB 58                      	POP	AX			; RESTORE WORK REGISTERS
  4109 000007FC 0E                      	PUSH	CS			; *PLACE CODE SEGMENT IN STACK AND
  4110 000007FD E8E3FF                  	CALL	CMOS_POPF		; *HANDLE POPF FOR B- LEVEL 80286
  4111 00000800 C3                      	RET
  4112                                  
  4113                                  CMOS_WRITE	ENDP
  4114                                  ;
  4115                                  
  4116                                  %assign NUMBER_DOSENTRY_INIT_DISCARD $ - end_of_dosentry_init_late
  4117                                  %warning DOSENTRY discard size NUMBER_DOSENTRY_INIT_DISCARD
  4117          ******************       warning: DOSENTRY discard size 598 [-w+user]
  4118                                  %if NUMBER_DOSENTRY_INIT_DISCARD < SYSINITSTACK + 64
  4119                                  	; 64 is for the first UMCB and a small safety margin
  4120                                   %assign NUMBER_SYSINITSTACK SYSINITSTACK + 64
  4121                                   %error DOSENTRY discard size NUMBER_DOSENTRY_INIT_DISCARD smaller than NUMBER_SYSINITSTACK
  4122                                  %endif
  4123                                  
  4124                                  
  4125                                  END$:
  4126                                  ; (no prior section) ; CODE	ENDS
  4127                                  	END
  4128                                  
  4129                                  
