     1                                  ; e forproc.sal= @(#)ibmfor.asm 1.28 85/10/15
     2                                  ;	name	OemFormatRoutines
     3                                  ;******************************************************************************
     4                                  ;AN001 - ???
     5                                  ;AN002 - D304 Modify Boot record structure for OS2		  11/09/87 J.K.
     6                                  ;******************************************************************************
     7                                  
     8                                  %include "forchng.mac"
     1                              <1> [list -]
   134                              <1> 
     9                                  debug	equ	0
    10                                  DEBUG	equ	0
    11                                  ;-------------------------------------------------------------------------------
    12                                  ; Public for debugging only
    13                                  
    14                                  	public	LastChanceToSaveIt
    15                                  	public	WriteBootSector
    16                                  	public	OemDone
    17                                  	public	WriteBogusDos
    18                                  	public	ConvertToOldDirectoryFormat
    19                                  	public	SetPartitionTable
    20                                  	public	ReadSector
    21                                  	public	WriteSector
    22                                  	public	SectorIO
    23                                  	public	GetVolumeId
    24                                  
    25                                  	public	customBPBs
    26                                  	public	NotSlashB
    27                                  	public	NotSingleSided
    28                                  	public	EndSwitchCheck
    29                                  	public	WeCanNotIgnoreThisError
    30                                  	public	HardDisk?
    31                                  	public	BogusDos
    32                                  	public	sys_mess_loop
    33                                  	public	end_sys_loop
    34                                  	public	DirectoryRead
    35                                  	public	wrtdir
    36                                  	public	DirectoryWritten
    37                                  	public	FCBforVolumeIdSearch
    38                                  	public	CopyVolumeId
    39                                  	public	CompareVolumeIds
    40                                  	public	BadVolumeId
    41                                  
    42                                  	public	boot2
    43                                  boot equ BOOT	; NASM port label
    44                                  	public	boot
    45                                  	public	scratchBuffer
    46                                  	public	biosFilename
    47                                  	public	dosFilename
    48                                  	public	oldDrive
    49                                  	public	oldVolumeId
    50                                  	public	Read_Write_Relative
    51                                  	public	Serial_Num_Low
    52                                  	public	Serial_Num_High
    53                                  	public	SizeMap
    54                                  
    55                                  	public	ptr_msgWhatIsVolumeId?
    56                                  
    57                                  	public	trackReadWritePacket
    58                                  
    59                                  	public	BPB81
    60                                  	public	BPB82
    61                                  	public	BPB91
    62                                  	public	BPB92
    63                                  
    64                                  ;-------------------------------------------------------------------------------
    65                                  
    66                                  section data public align=16 class=DATA
    67                                  ; (no prior section) ; data	ends
    68                                  
    69                                  section code public align=16 class=CODE
    70                                  	assume	cs:code,ds:data
    71                                  
    72                                  	Public	AccessDisk
    73                                  	public	LastChanceToSaveIt
    74                                  	public	OemDone
    75                                  	public	BiosFile
    76                                  	public	DosFile
    77                                  
    78                                  section data
    79                                  	extrn	AddToSystemSize:near
    80                                  	extrn	currentCylinder:word
    81                                  	extrn	currentHead:word
    82                                  	extrn	deviceParameters:byte
    83                                  	extrn	drive:byte
    84                                  	extrn	driveLetter:byte
    85                                  	extrn	fBigFAT:byte
    86                                  	extrn	inbuff:byte
    87                                  	extrn	switchmap:word
    88                                  	extrn	Old_Dir:byte
    89                                  	extrn	fLastChance:byte
    90                                  	extrn	Fatal_Error:Byte
    91                                  	extrn	Bios:Byte
    92                                  	extrn	Dos:Byte
    93                                  	extrn	Command:Byte
    94                                  
    95                                  	extrn	msgBad_T_N:byte
    96                                  	extrn	msgBadVolumeId:byte
    97                                  	extrn	msgBadPartitionTable:byte
    98                                  	extrn	msgBootWriteError:byte
    99                                  	extrn	msgDirectoryReadError:byte
   100                                  	extrn	msgDirectoryWriteError:byte
   101                                  	extrn	msgInvalidParameter:byte
   102                                  	extrn	msgIncompatibleParameters:byte
   103                                  	extrn	msgIncompatibleParametersForHardDisk:byte
   104                                  	extrn	msgParametersNotSupportedByDrive:byte
   105                                  	extrn	msgPartitionTableReadError:byte
   106                                  	extrn	msgPartitionTableWriteError:byte
   107                                  	extrn	msgWhatIsVolumeId?:byte
   108                                  	extrn	NumSectors:word, TrackCnt:word
   109                                  
   110                                  %IF	DEBUG
   111                                  	extrn	msgFormatBroken:byte
   112                                  %ENDIF
   113                                  
   114                                  section code	; data	ends
   115                                  
   116                                  	extrn	PrintString:near
   117                                  	extrn	std_printf:near
   118                                  	extrn	crlf:near
   119                                  	extrn	user_string:near
   120                                  	extrn	Read_Disk:near
   121                                  	extrn	Write_Disk:near
   122                                  
   123                                  
   124                                  ;-------------------------------------------------------------------------------
   125                                  ; Constants
   126                                  
   127                                  [list -]
   127          ******************       warning: out: ..filesize.inc [-w+user]
   127          ******************       warning: out: IOCTL.INC... [-w+user]
   127          ******************       warning: out: BPB.INC... [-w+user]
   127          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
   148                                  
   149                                  ;-------------------------------------------------------------------------------
   150                                  ; And this is the actual data
   151                                  section data
   152                                  
   153                                  Read_Write_Relative: ; NASM structure instance
   154                                  Relative_Sector_Buffer_size equ Relative_Sector_Buffer_struc_size	; NASM port equate
   155                                  istruc Relative_Sector_Buffer
   156 00000000 ??<rep Ah>              iend
   157                                  
   158                                  
   159                                  	%IF IBMCOPYRIGHT
   160                                  BiosFile db	"x:\IBMBIO.COM", 0
   161                                  DosFile db	"x:\IBMDOS.COM", 0
   162                                  	%ELSE
   163 0000000A 783A5C494F2E535953-     BiosFile db	"x:\IO.SYS", 0
   163 00000013 00                 
   164 00000014 783A5C4D53444F532E-     DosFile db	"x:\MSDOS.SYS", 0
   164 0000001D 53595300           
   165                                  	%ENDIF
   166                                  
   167 00000021 4E4F204E414D452020-     Dummy_Label db	"NO NAME    "
   167 0000002A 2020               
   168 0000002C 0B00                    Dummy_Label_Size dw  11 			;AN028
   169                                  
   170 0000002E 0000                    Serial_Num_Low dw 0				;				;AN000;
   171 00000030 0000                    Serial_Num_High dw 0				;				;AN000;
   172                                  
   173 00000032 00                      SizeMap db	0				;				;AN000;
   174                                  
   175                                  trackReadWritePacket: ; NASM structure instance
   176                                  A_TRACKREADWRITEPACKET_size equ A_TRACKREADWRITEPACKET_struc_size	; NASM port equate
   177                                  istruc A_TRACKREADWRITEPACKET
   178 00000033 ??<rep Dh>              iend
   179                                  
   180                                  
   181                                  ; BIOS parameter blocks for various media
   182                                  customBPBs label byte
   183                                  BPB92: ; NASM structure instance
   184                                  A_BPB_size equ A_BPB_struc_size	; NASM port equate
   185                                  istruc A_BPB
   186                                  at BPB_BYTESPERSECTOR
   187 00000040 0002                    	dw 512
   188                                  at BPB_SECTORSPERCLUSTER
   189 00000042 02                      	db 2
   190                                  at BPB_RESERVEDSECTORS
   191 00000043 0100                    	dw 1
   192                                  at BPB_NUMBEROFFATS
   193 00000045 02                      	db 2
   194                                  at BPB_ROOTENTRIES
   195 00000046 7000                    	dw 112
   196                                  at BPB_TOTALSECTORS
   197 00000048 D002                    	dw 2*9*40
   198                                  at BPB_MEDIADESCRIPTOR
   199 0000004A FD                      	db 0fdH
   200                                  at BPB_SECTORSPERFAT
   201 0000004B 0200                    	dw 2
   202                                  at BPB_SECTORSPERTRACK
   203 0000004D 0900                    	dw 9
   204                                  at BPB_HEADS
   205 0000004F 0200                    	dw 2
   206                                  at BPB_HIDDENSECTORS
   207 00000051 0000                    	dw 0
   208 00000053 0000                    	dw 0
   209                                  at BPB_BIGTOTALSECTORS
   210 00000055 0000                    	dw 0
   211 00000057 0000                    	dw 0
   212 00000059 ??<rep 6h>              iend
   213                                  BPB91: ; NASM structure instance
   214                                  istruc A_BPB
   215                                  at BPB_BYTESPERSECTOR
   216 0000005F 0002                    	dw 512
   217                                  at BPB_SECTORSPERCLUSTER
   218 00000061 01                      	db 1
   219                                  at BPB_RESERVEDSECTORS
   220 00000062 0100                    	dw 1
   221                                  at BPB_NUMBEROFFATS
   222 00000064 02                      	db 2
   223                                  at BPB_ROOTENTRIES
   224 00000065 4000                    	dw 64
   225                                  at BPB_TOTALSECTORS
   226 00000067 6801                    	dw 1*9*40
   227                                  at BPB_MEDIADESCRIPTOR
   228 00000069 FC                      	db 0fcH
   229                                  at BPB_SECTORSPERFAT
   230 0000006A 0200                    	dw 2
   231                                  at BPB_SECTORSPERTRACK
   232 0000006C 0900                    	dw 9
   233                                  at BPB_HEADS
   234 0000006E 0100                    	dw 1
   235                                  at BPB_HIDDENSECTORS
   236 00000070 0000                    	dw 0
   237 00000072 0000                    	dw 0
   238                                  at BPB_BIGTOTALSECTORS
   239 00000074 0000                    	dw 0
   240 00000076 0000                    	dw 0
   241 00000078 ??<rep 6h>              iend
   242                                  BPB82: ; NASM structure instance
   243                                  istruc A_BPB
   244                                  at BPB_BYTESPERSECTOR
   245 0000007E 0002                    	dw 512
   246                                  at BPB_SECTORSPERCLUSTER
   247 00000080 02                      	db 2
   248                                  at BPB_RESERVEDSECTORS
   249 00000081 0100                    	dw 1
   250                                  at BPB_NUMBEROFFATS
   251 00000083 02                      	db 2
   252                                  at BPB_ROOTENTRIES
   253 00000084 7000                    	dw 112
   254                                  at BPB_TOTALSECTORS
   255 00000086 8002                    	dw 2*8*40
   256                                  at BPB_MEDIADESCRIPTOR
   257 00000088 FF                      	db 0ffH
   258                                  at BPB_SECTORSPERFAT
   259 00000089 0100                    	dw 1
   260                                  at BPB_SECTORSPERTRACK
   261 0000008B 0800                    	dw 8
   262                                  at BPB_HEADS
   263 0000008D 0200                    	dw 2
   264                                  at BPB_HIDDENSECTORS
   265 0000008F 0000                    	dw 0
   266 00000091 0000                    	dw 0
   267                                  at BPB_BIGTOTALSECTORS
   268 00000093 0000                    	dw 0
   269 00000095 0000                    	dw 0
   270 00000097 ??<rep 6h>              iend
   271                                  BPB81: ; NASM structure instance
   272                                  istruc A_BPB
   273                                  at BPB_BYTESPERSECTOR
   274 0000009D 0002                    	dw 512
   275                                  at BPB_SECTORSPERCLUSTER
   276 0000009F 01                      	db 1
   277                                  at BPB_RESERVEDSECTORS
   278 000000A0 0100                    	dw 1
   279                                  at BPB_NUMBEROFFATS
   280 000000A2 02                      	db 2
   281                                  at BPB_ROOTENTRIES
   282 000000A3 4000                    	dw 64
   283                                  at BPB_TOTALSECTORS
   284 000000A5 4001                    	dw 1*8*40
   285                                  at BPB_MEDIADESCRIPTOR
   286 000000A7 FE                      	db 0feH
   287                                  at BPB_SECTORSPERFAT
   288 000000A8 0100                    	dw 1
   289                                  at BPB_SECTORSPERTRACK
   290 000000AA 0800                    	dw 8
   291                                  at BPB_HEADS
   292 000000AC 0100                    	dw 1
   293                                  at BPB_HIDDENSECTORS
   294 000000AE 0000                    	dw 0
   295 000000B0 0000                    	dw 0
   296                                  at BPB_BIGTOTALSECTORS
   297 000000B2 0000                    	dw 0
   298 000000B4 0000                    	dw 0
   299 000000B6 ??<rep 6h>              iend
   300                                  BPB720: ; NASM structure instance
   301                                  istruc A_BPB
   302                                  at BPB_BYTESPERSECTOR
   303 000000BC 0002                    	dw 512
   304                                  at BPB_SECTORSPERCLUSTER
   305 000000BE 02                      	db 2
   306                                  at BPB_RESERVEDSECTORS
   307 000000BF 0100                    	dw 1
   308                                  at BPB_NUMBEROFFATS
   309 000000C1 02                      	db 2
   310                                  at BPB_ROOTENTRIES
   311 000000C2 7000                    	dw 112
   312                                  at BPB_TOTALSECTORS
   313 000000C4 A005                    	dw 2*9*80
   314                                  at BPB_MEDIADESCRIPTOR
   315 000000C6 F9                      	db 0F9h
   316                                  at BPB_SECTORSPERFAT
   317 000000C7 0300                    	dw 3
   318                                  at BPB_SECTORSPERTRACK
   319 000000C9 0900                    	dw 9
   320                                  at BPB_HEADS
   321 000000CB 0200                    	dw 2
   322                                  at BPB_HIDDENSECTORS
   323 000000CD 0000                    	dw 0
   324 000000CF 0000                    	dw 0
   325                                  at BPB_BIGTOTALSECTORS
   326 000000D1 0000                    	dw 0
   327 000000D3 0000                    	dw 0
   328 000000D5 ??<rep 6h>              iend
   329                                  
   330                                  
   331                                  
   332                                  boot2:
   333                                  	%include "boot11.mac"
     1 000000DB EB27900800140000    <1> 	db	0EBH,027H,090H,008H,000H,014H,000H,000H
     2 000000E3 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
     3 000000EB 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
     4 000000F3 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
     5 000000FB 00000000000000CD    <1> 	db	000H,000H,000H,000H,000H,000H,000H,0CDH
     6 00000103 19FA8CC88ED833D2    <1> 	db	019H,0FAH,08CH,0C8H,08EH,0D8H,033H,0D2H
     7 0000010B 8ED2BC007CFBB860    <1> 	db	08EH,0D2H,0BCH,000H,07CH,0FBH,0B8H,060H
     8 00000113 008ED88EC033D28B    <1> 	db	000H,08EH,0D8H,08EH,0C0H,033H,0D2H,08BH
     9 0000011B C2CD137269E88500    <1> 	db	0C2H,0CDH,013H,072H,069H,0E8H,085H,000H
    10 00000123 72DD2E833E037C08    <1> 	db	072H,0DDH,02EH,083H,03EH,003H,07CH,008H
    11 0000012B 74062EC606647D02    <1> 	db	074H,006H,02EH,0C6H,006H,064H,07DH,002H
    12 00000133 BB00002E8B0E037C    <1> 	db	0BBH,000H,000H,02EH,08BH,00EH,003H,07CH
    13 0000013B 51B0092AC1B4008B    <1> 	db	051H,0B0H,009H,02AH,0C1H,0B4H,000H,08BH
    14 00000143 F05633D233C08AC5    <1> 	db	0F0H,056H,033H,0D2H,033H,0C0H,08AH,0C5H
    15 0000014B 2EF636647D8AE88A    <1> 	db	02EH,0F6H,036H,064H,07DH,08AH,0E8H,08AH
    16 00000153 F48BC6B402CD1372    <1> 	db	0F4H,08BH,0C6H,0B4H,002H,0CDH,013H,072H
    17 0000015B 2D5E592E2936057C    <1> 	db	02DH,05EH,059H,02EH,029H,036H,005H,07CH
    18 00000163 741F8BC62EF72665    <1> 	db	074H,01FH,08BH,0C6H,02EH,0F7H,026H,065H
    19 0000016B 7D03D8FEC5B10151    <1> 	db	07DH,003H,0D8H,0FEH,0C5H,0B1H,001H,051H
    20 00000173 BE08002E3B36057C    <1> 	db	0BEH,008H,000H,02EH,03BH,036H,005H,07CH
    21 0000017B 7C052E8B36057CEB    <1> 	db	07CH,005H,02EH,08BH,036H,005H,07CH,0EBH
    22 00000183 C0EA00006000BE67    <1> 	db	0C0H,0EAH,000H,000H,060H,000H,0BEH,067H
    23 0000018B 7DE80200EBFE32FF    <1> 	db	07DH,0E8H,002H,000H,0EBH,0FEH,032H,0FFH
    24 00000193 2EAC247F740B56B4    <1> 	db	02EH,0ACH,024H,07FH,074H,00BH,056H,0B4H
    25 0000019B 0EBB0700CD105EEB    <1> 	db	00EH,0BBH,007H,000H,0CDH,010H,05EH,0EBH
    26 000001A3 EFC3E933FFBB0000    <1> 	db	0EFH,0C3H,0E9H,033H,0FFH,0BBH,000H,000H
    27 000001AB B90400B80102CD13    <1> 	db	0B9H,004H,000H,0B8H,001H,002H,0CDH,013H
    28 000001B3 1E72338CC88ED8BF    <1> 	db	01EH,072H,033H,08CH,0C8H,08EH,0D8H,0BFH
    29 000001BB 0000B90B0026800D    <1> 	db	000H,000H,0B9H,00BH,000H,026H,080H,00DH
    30 000001C3 2026804D202047E2    <1> 	db	020H,026H,080H,04DH,020H,020H,047H,0E2H
    31 000001CB F4BF0000BE8B7DB9    <1> 	db	0F4H,0BFH,000H,000H,0BEH,08BH,07DH,0B9H
    32 000001D3 0B00FCF3A6750FBF    <1> 	db	00BH,000H,0FCH,0F3H,0A6H,075H,00FH,0BFH
    33 000001DB 2000BE977DB90B00    <1> 	db	020H,000H,0BEH,097H,07DH,0B9H,00BH,000H
    34 000001E3 F3A675021FC3BE1B    <1> 	db	0F3H,0A6H,075H,002H,01FH,0C3H,0BEH,01BH
    35 000001EB 7DE8A2FFB400CD16    <1> 	db	07DH,0E8H,0A2H,0FFH,0B4H,000H,0CDH,016H
    36 000001F3 1FF9C30D0A4E6F6E    <1> 	db	01FH,0F9H,0C3H,00DH,00AH,04EH,06FH,06EH
    37 000001FB 2D53797374656D20    <1> 	db	02DH,053H,079H,073H,074H,065H,06DH,020H
    38 00000203 6469736B206F7220    <1> 	db	064H,069H,073H,06BH,020H,06FH,072H,020H
    39 0000020B 6469736B20657272    <1> 	db	064H,069H,073H,06BH,020H,065H,072H,072H
    40 00000213 6F720D0A5265706C    <1> 	db	06FH,072H,00DH,00AH,052H,065H,070H,06CH
    41 0000021B 61636520616E6420    <1> 	db	061H,063H,065H,020H,061H,06EH,064H,020H
    42 00000223 737472696B652061    <1> 	db	073H,074H,072H,069H,06BH,065H,020H,061H
    43 0000022B 6E79206B65792077    <1> 	db	06EH,079H,020H,06BH,065H,079H,020H,077H
    44 00000233 68656E2072656164    <1> 	db	068H,065H,06EH,020H,072H,065H,061H,064H
    45 0000023B 790D0A000100020D    <1> 	db	079H,00DH,00AH,000H,001H,000H,002H,00DH
    46 00000243 0A4469736B20426F    <1> 	db	00AH,044H,069H,073H,06BH,020H,042H,06FH
    47 0000024B 6F74206661696C75    <1> 	db	06FH,074H,020H,066H,061H,069H,06CH,075H
    48 00000253 72650D0A004D6963    <1> 	db	072H,065H,00DH,00AH,000H,04DH,069H,063H
    49 0000025B 726F736F66742C49    <1> 	db	072H,06FH,073H,06FH,066H,074H,02CH,049H
    50 00000263 6E632069626D6269    <1> 	db	06EH,063H,020H,069H,062H,06DH,062H,069H
    51 0000026B 6F2020636F6D3069    <1> 	db	06FH,020H,020H,063H,06FH,06DH,030H,069H
    52 00000273 626D646F73202063    <1> 	db	062H,06DH,064H,06FH,073H,020H,020H,063H
    53 0000027B 6F6D3005C606772F    <1> 	db	06FH,06DH,030H,005H,0C6H,006H,077H,02FH
    54 00000283 FF837EFC00750B80    <1> 	db	0FFH,083H,07EH,0FCH,000H,075H,00BH,080H
    55 0000028B 7EF73B7505C60676    <1> 	db	07EH,0F7H,03BH,075H,005H,0C6H,006H,076H
    56 00000293 2FFF89EC5DCA0400    <1> 	db	02FH,0FFH,089H,0ECH,05DH,0CAH,004H,000H
    57 0000029B 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
    58 000002A3 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
    59 000002AB 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
    60 000002B3 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
    61 000002BB 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
    62 000002C3 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
    63 000002CB 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
    64 000002D3 0000000000000000    <1> 	db	000H,000H,000H,000H,000H,000H,000H,000H
   334                                  	db	512 - ($ - boot2) dup(?)
   335                                  REORG2	LABEL	BYTE
   336                                  
   337                                  
   338                                  %include "bootform.mac"
     1                              <1> 	%warning out: BOOTFORM.INC...
     1          ******************  <1>  warning: out: BOOTFORM.INC... [-w+user]
     2                              <1> ;****************************************************************************
     3                              <1> ;AN000; - Structure of the Extended IBMBOOT record for DOS -. J.K.
     4                              <1> ;AN001; - D304 Include PHYDRV, CURHD to the header structure	 11/09/87 J.K.
     5                              <1> ;****************************************************************************
     6                              <1> 
     7                              <1> BOOT_SIZE		 EQU	 512
     8                              <1> EXT_BOOT_SIGNATURE	 EQU	 41		;Extended boot signature
     9                              <1> ;
    10                              <1> EXT_BPB_INFO		STRUC
    11 00000000 ????                <1> EBPB_BYTESPERSECTOR	 DW	 ?
    12 00000002 ??                  <1> EBPB_SECTORSPERCLUSTER	 DB	 ?
    13 00000003 ????                <1> EBPB_RESERVEDSECTORS	 DW	 ?
    14 00000005 ??                  <1> EBPB_NUMBEROFFATS	 DB	 ?
    15 00000006 ????                <1> EBPB_ROOTENTRIES	 DW	 ?
    16 00000008 ????                <1> EBPB_TOTALSECTORS	 DW	 ?
    17 0000000A ??                  <1> EBPB_MEDIADESCRIPTOR	 DB	 ?
    18 0000000B ????                <1> EBPB_SECTORSPERFAT	 DW	 ?
    19 0000000D ????                <1> EBPB_SECTORSPERTRACK	 DW	 ?
    20 0000000F ????                <1> EBPB_HEADS		 DW	 ?
    21 00000011 ????????            <1> EBPB_HIDDENSECTOR	 DD	 ?
    22 00000015 ????????            <1> EBPB_BIGTOTALSECTORS	 DD	 ?
    23                              <1> EXT_BPB_INFO		ENDS
    24                              <1> ;
    25                              <1> ;AN001; EXT_PHYDRV, EXT_CURHD included in the header for OS2.
    26                              <1> EXT_IBMBOOT_HEADER	STRUC
    27 00000000 ??????              <1> EXT_BOOT_JUMP		DB	3 DUP (?)
    28 00000003 ????????????????    <1> EXT_BOOT_OEM		DB	8 DUP (?)
    29 0000000B <res 19h>           <1> EXT_BOOT_BPB		DB	EXT_BPB_INFO_struc_size dup (?)
    30 00000024 ??                  <1> EXT_PHYDRV		DB	? ; 80h
    31 00000025 ??                  <1> EXT_CURHD		DB	? ; 0
    32 00000026 ??                  <1> EXT_BOOT_SIG		DB	? ; EXT_BOOT_SIGNATURE
    33 00000027 ????????            <1> EXT_BOOT_SERIAL 	DD	?
    34 0000002B <res Bh>            <1> EXT_BOOT_VOL_LABEL	DB	11 DUP (?)
    35 00000036 ????????????????    <1> EXT_SYSTEM_ID		DB	8  DUP (?)
    36                              <1> EXT_IBMBOOT_HEADER	ENDS
    37                              <1> ;
    38                              <1> labelsize BOOT_SIGNATURE, word, (BOOT_SIZE-2)
    39                              <1> 
    40                              <1> ;
    41                              <1> ;J.K. This is the number of sectors (of size 512 bytes) that will cover
    42                              <1> ;the size of IBMLOAD program.  IBMBOOT program has to at least read this
    43                              <1> ;many sectors, and these sectors should be the first cluster and consecutive.
    44                              <1> ;Make sure IBMBOOT program uses the same value as this.
    45                              <1> IBMLOADSIZE	equ	3	;Number of sectors IBMBOOT program should read in.
    46                              <1> 
    47                              <1> 
   339                                  
   340                                  
   341                                  BOOT	LABEL	BYTE
   342                                  	%include "boot.mac"
     1 000002DB EB3C904D53444F53    <1> 	db	0EBH,03CH,090H,04DH,053H,044H,04FH,053H
     2 000002E3 342E300002080100    <1> 	db	034H,02EH,030H,000H,002H,008H,001H,000H
     3 000002EB 0200020351F80800    <1> 	db	002H,000H,002H,003H,051H,0F8H,008H,000H
     4 000002F3 1100040001000000    <1> 	db	011H,000H,004H,000H,001H,000H,000H,000H
     5 000002FB 0000000080002900    <1> 	db	000H,000H,000H,000H,080H,000H,029H,000H
     6 00000303 0000004E4F204E41    <1> 	db	000H,000H,000H,04EH,04FH,020H,04EH,041H
     7 0000030B 4D45202020204641    <1> 	db	04DH,045H,020H,020H,020H,020H,046H,041H
     8 00000313 543132202020FA33    <1> 	db	054H,031H,032H,020H,020H,020H,0FAH,033H
     9 0000031B C08ED0BC007C1607    <1> 	db	0C0H,08EH,0D0H,0BCH,000H,07CH,016H,007H
    10 00000323 BB780036C5371E56    <1> 	db	0BBH,078H,000H,036H,0C5H,037H,01EH,056H
    11 0000032B 1653BF3E7CB90B00    <1> 	db	016H,053H,0BFH,03EH,07CH,0B9H,00BH,000H
    12 00000333 FCF3A4061FC645FE    <1> 	db	0FCH,0F3H,0A4H,006H,01FH,0C6H,045H,0FEH
    13 0000033B 0F8B0E187C884DF9    <1> 	db	00FH,08BH,00EH,018H,07CH,088H,04DH,0F9H
    14 00000343 894702C7073E7CFB    <1> 	db	089H,047H,002H,0C7H,007H,03EH,07CH,0FBH
    15 0000034B CD13727C33C03906    <1> 	db	0CDH,013H,072H,07CH,033H,0C0H,039H,006H
    16 00000353 137C74088B0E137C    <1> 	db	013H,07CH,074H,008H,08BH,00EH,013H,07CH
    17 0000035B 890E207CA0107CF7    <1> 	db	089H,00EH,020H,07CH,0A0H,010H,07CH,0F7H
    18 00000363 26167C03061C7C13    <1> 	db	026H,016H,07CH,003H,006H,01CH,07CH,013H
    19 0000036B 161E7C03060E7C83    <1> 	db	016H,01EH,07CH,003H,006H,00EH,07CH,083H
    20 00000373 D200A3507C891652    <1> 	db	0D2H,000H,0A3H,050H,07CH,089H,016H,052H
    21 0000037B 7CA3497C89164B7C    <1> 	db	07CH,0A3H,049H,07CH,089H,016H,04BH,07CH
    22 00000383 B82000F726117C8B    <1> 	db	0B8H,020H,000H,0F7H,026H,011H,07CH,08BH
    23 0000038B 1E0B7C03C348F7F3    <1> 	db	01EH,00BH,07CH,003H,0C3H,048H,0F7H,0F3H
    24 00000393 0106497C83164B7C    <1> 	db	001H,006H,049H,07CH,083H,016H,04BH,07CH
    25 0000039B 00BB00058B16527C    <1> 	db	000H,0BBH,000H,005H,08BH,016H,052H,07CH
    26 000003A3 A1507CE887007220    <1> 	db	0A1H,050H,07CH,0E8H,087H,000H,072H,020H
    27 000003AB B001E8A10072198B    <1> 	db	0B0H,001H,0E8H,0A1H,000H,072H,019H,08BH
    28 000003B3 FBB90B00BEDB7DF3    <1> 	db	0FBH,0B9H,00BH,000H,0BEH,0DBH,07DH,0F3H
    29 000003BB A6750D8D7F20BEE6    <1> 	db	0A6H,075H,00DH,08DH,07FH,020H,0BEH,0E6H
    30 000003C3 7DB90B00F3A67418    <1> 	db	07DH,0B9H,00BH,000H,0F3H,0A6H,074H,018H
    31 000003CB BE937DE8510032E4    <1> 	db	0BEH,093H,07DH,0E8H,051H,000H,032H,0E4H
    32 000003D3 CD165E1F8F048F44    <1> 	db	0CDH,016H,05EH,01FH,08FH,004H,08FH,044H
    33 000003DB 02CD19585858EBE8    <1> 	db	002H,0CDH,019H,058H,058H,058H,0EBH,0E8H
    34 000003E3 BB0007B90300A149    <1> 	db	0BBH,000H,007H,0B9H,003H,000H,0A1H,049H
    35 000003EB 7C8B164B7C505251    <1> 	db	07CH,08BH,016H,04BH,07CH,050H,052H,051H
    36 000003F3 E83A0072E6B001E8    <1> 	db	0E8H,03AH,000H,072H,0E6H,0B0H,001H,0E8H
    37 000003FB 5400595A5872C905    <1> 	db	054H,000H,059H,05AH,058H,072H,0C9H,005H
    38 00000403 010083D200031E0B    <1> 	db	001H,000H,083H,0D2H,000H,003H,01EH,00BH
    39 0000040B 7CE2E28A2E157C8A    <1> 	db	07CH,0E2H,0E2H,08AH,02EH,015H,07CH,08AH
    40 00000413 16247C8B1E497CA1    <1> 	db	016H,024H,07CH,08BH,01EH,049H,07CH,0A1H
    41 0000041B 4B7CEA00007000AC    <1> 	db	04BH,07CH,0EAH,000H,000H,070H,000H,0ACH
    42 00000423 0AC07429B40EBB07    <1> 	db	00AH,0C0H,074H,029H,0B4H,00EH,0BBH,007H
    43 0000042B 00CD10EBF23B1618    <1> 	db	000H,0CDH,010H,0EBH,0F2H,03BH,016H,018H
    44 00000433 7C7319F736187CFE    <1> 	db	07CH,073H,019H,0F7H,036H,018H,07CH,0FEH
    45 0000043B C288164F7C33D2F7    <1> 	db	0C2H,088H,016H,04FH,07CH,033H,0D2H,0F7H
    46 00000443 361A7C8816257CA3    <1> 	db	036H,01AH,07CH,088H,016H,025H,07CH,0A3H
    47 0000044B 4D7CF8C3F9C3B402    <1> 	db	04DH,07CH,0F8H,0C3H,0F9H,0C3H,0B4H,002H
    48 00000453 8B164D7CB106D2E6    <1> 	db	08BH,016H,04DH,07CH,0B1H,006H,0D2H,0E6H
    49 0000045B 0A364F7C8BCA86E9    <1> 	db	00AH,036H,04FH,07CH,08BH,0CAH,086H,0E9H
    50 00000463 8A16247C8A36257C    <1> 	db	08AH,016H,024H,07CH,08AH,036H,025H,07CH
    51 0000046B CD13C30D0A4E6F6E    <1> 	db	0CDH,013H,0C3H,00DH,00AH,04EH,06FH,06EH
    52 00000473 2D53797374656D20    <1> 	db	02DH,053H,079H,073H,074H,065H,06DH,020H
    53 0000047B 6469736B206F7220    <1> 	db	064H,069H,073H,06BH,020H,06FH,072H,020H
    54 00000483 6469736B20657272    <1> 	db	064H,069H,073H,06BH,020H,065H,072H,072H
    55 0000048B 6F720D0A5265706C    <1> 	db	06FH,072H,00DH,00AH,052H,065H,070H,06CH
    56 00000493 61636520616E6420    <1> 	db	061H,063H,065H,020H,061H,06EH,064H,020H
    57 0000049B 707265737320616E    <1> 	db	070H,072H,065H,073H,073H,020H,061H,06EH
    58 000004A3 79206B6579207768    <1> 	db	079H,020H,06BH,065H,079H,020H,077H,068H
    59 000004AB 656E207265616479    <1> 	db	065H,06EH,020H,072H,065H,061H,064H,079H
    60 000004B3 0D0A00494F202020    <1> 	db	00DH,00AH,000H,049H,04FH,020H,020H,020H
    61 000004BB 2020205359534D53    <1> 	db	020H,020H,020H,053H,059H,053H,04DH,053H
    62 000004C3 444F532020205359    <1> 	db	044H,04FH,053H,020H,020H,020H,053H,059H
    63 000004CB 5300000000000000    <1> 	db	053H,000H,000H,000H,000H,000H,000H,000H
    64 000004D3 00000000000055AA    <1> 	db	000H,000H,000H,000H,000H,000H,055H,0AAH
   343                                  
   344 000004DB <res 200h>              scratchBuffer db 512 dup(?)
   345                                  
   346 000006DB [0000]                  ptr_msgWhatIsVolumeId? dw offset msgWhatIsVolumeId?
   347 000006DD [0000]                  	dw	offset driveLetter
   348                                  
   349                                  
   350 000006DF 4641543132202020        FAT12_String db "FAT12   "
   351 000006E7 4641543136202020        FAT16_String db "FAT16   "
   352                                  
   353                                  Media_ID_Buffer: ; NASM structure instance
   354                                  Media_ID_size equ Media_ID_struc_size	; NASM port equate
   355                                  istruc Media_ID
   356 000006EF ??<rep 6h>20-           at Media_ID_Volume_Label,	times 11 db 32
   356 000006EF <rep Bh>           
   357 00000700 20<rep 8h>              at Media_ID_File_System,	times 8 db 32
   358                                  iend
   359                                  
   360                                  
   361                                  section code	; data	ends
   362                                  ;-------------------------------------------------------------------------------
   363                                  ; AccessDisk:
   364                                  ;    Called whenever a different disk is about to be accessed
   365                                  ;
   366                                  ;    Input:
   367                                  ;	al - drive letter (0=A, 1=B, ...)
   368                                  ;
   369                                  ;    Output:
   370                                  ;	none
   371                                  AccessDisk proc near
   372                                  
   373 00000000 50                      	push	ax				; save drive letter
   374 00000001 88C3                    	mov	bl,al				; Set up GENERIC IOCTL REQUEST preamble
   375 00000003 FEC3                    	inc	bl
   376                                  IOCTL equ IOCtl	; NASM port equate
   377 00000005 B80F44                  	mov	ax,(IOCTL << 8) + Set_Drv_Owner ; IOCTL function
   378 00000008 CD21                    	int	21h
   379 0000000A 58                      	pop	ax
   380 0000000B C3                      	return
   381                                  
   382                                  AccessDisk endp
   383                                  
   384                                  ;-------------------------------------------------------------------------------
   385                                  ;    CheckSwitches:
   386                                  ;	Check switches against device parameters
   387                                  ;	Use switches to modify device parameters
   388                                  ;
   389                                  ;    Input:
   390                                  ;	deviceParameters
   391                                  ;
   392                                  ;    Output:
   393                                  ;	deviceParameters may be modified
   394                                  ;	Carry set if error
   395                                  ;
   396                                  ;
   397                                  ;  /B <> /S
   398                                  ;  /B/8 <> /V
   399                                  ;  /1 or /8 <> /T/N
   400                                  ;
   401                                  
   402                                  
   403                                  CHeckSwitches equ CheckSwitches	; NASM port label
   404                                  Public	CHeckSwitches
   405                                  CheckSwitches proc near
   406                                  
   407                                  
   408                                  ; Disallow /C
   409                                  						;lea	 dx, msgInvalidParameter					 ;AC000;
   410 0000000C F706[0000]0800          	test	word [switchmap], SWITCH_C
   411 00000012 7408                    	jz	CheckExcl
   412 00000014 BA[0000]E8(0000)        	Message msgInvalidParameter		;AC000;
   413                                  SwitchError:
   414                                  						;call	 PrintString							 ;AC000;
   415 0000001A F9                      	stc
   416 0000001B C3                      	ret
   417                                  
   418                                  CheckExcl:
   419                                  
   420                                  SwitchMap equ switchmap	; NASM port label
   421                                  Switch_F equ SWITCH_F	; NASM port equate
   422 0000001C F706[0000]0010          	test	word [SwitchMap],Switch_F		;Specify size?			;AN001;
   423                                  ;	$IF	NZ				;Yes				;AN001;
   424 00000022 7418                    	JZ DD_IF1
   425                                  Switch_1 equ SWITCH_1	; NASM port equate
   426                                  Switch_8 equ SWITCH_8	; NASM port equate
   427                                  Switch_4 equ SWITCH_4	; NASM port equate
   428                                  Switch_N equ SWITCH_N	; NASM port equate
   429                                  Switch_T equ SWITCH_T	; NASM port equate
   430 00000024 F706[0000]F001          	   test    word [SwitchMap],(Switch_1+Switch_8+Switch_4+Switch_N+Switch_T) ;AN001;
   431                                  ;	   $IF	   NZ				;/F replaces above switches	;AN001;
   432 0000002A 740D                    	   JZ DD_IF2
   433 0000002C BA[0000]E8(0000)        	      Message msgIncompatibleParameters ;Print error			;AN001;
   434                                  Yes equ YES	; NASM port equate
   435 00000032 C606[0000]FF            	      mov     byte [Fatal_Error],Yes		;Force exit			;AN001;
   436                                  ;	   $ELSE				;				;AN001;
   437 00000037 EB03                    	   JMP SHORT DD_EN2
   438                                  DD_IF2:
   439 00000039 E84E02                  	      call    Size_To_Switch		;Go set switches based		;AN001;
   440                                  ;	   $ENDIF				; on the size			;AN001;
   441                                  DD_EN2:
   442                                  ;	$ENDIF					;				;AN001;
   443                                  DD_IF1:
   444 0000003C 803E[0000]00            	cmp	byte [Fatal_Error],NO			;				;AN007;
   445                                  ;	$IF	E				;				;AN007;
   446 00000041 7506                    	JNE DD_IF6
   447 00000043 E87707                  	   call    Check_Switch_8_B		;				;ac007
   448 00000046 E84D03                  	   call    Check_T_N
   449                                  ;	$ENDIF					;				;AN009;
   450                                  DD_IF6:
   451 00000049 803E[0000]FF            	cmp	byte [Fatal_Error],Yes 		;				;AN007;
   452 0000004E 7502                    	jne	ExclChkDone			;				;AN007;
   453 00000050 F9                      	stc					;				;AN007;
   454 00000051 C3                      	ret					;				;AN007;
   455                                  
   456                                  ExclChkDone:
   457                                  ; Patch the boot sector so that the boot strap loader knows what disk to
   458                                  ; boot from
   459                                  ;	 mov	 Boot.Boot_PhyDrv, 00H		 ;AC000;
   460                                  Boot equ BOOT	; NASM port label
   461 00000052 C606[FF02]00            	mov	byte [Boot + EXT_PHYDRV], 00H		;AN00?;
   462                                  
   463                                  DP_DeviceType equ DP_DEVICETYPE	; NASM port equate
   464 00000057 803E[0100]05            	cmp	byte [deviceParameters + DP_DeviceType], DEV_HARDDISK
   465 0000005C 755F                    	jne	CheckFor5InchDrives
   466                                  
   467                                  ; Formatting a hard disk so we must repatch the boot sector
   468                                  ;	 mov	 Boot.Boot_PhyDrv, 80H		 ;AC000;
   469 0000005E C606[FF02]80            	mov	byte [Boot + EXT_PHYDRV], 80H		;AN00?;
   470                                  SWITCH_Select equ SWITCH_SELECT	; NASM port equate
   471                                  Switch_B equ SWITCH_B	; NASM port equate
   472 00000063 F706[0000]FCF1          	test	word [switchmap], ~ (SWITCH_S | SWITCH_V | SWITCH_Select | SWITCH_AUTOTEST | Switch_B) ;AN007;
   473 00000069 7408                    	jz	SwitchesOkForHardDisk
   474                                  
   475 0000006B BA[0000]E8(0000)        	Message msgIncompatibleParametersForHardDisk ;			     ;AC000;
   476 00000071 F9                      	stc
   477 00000072 C3                      	ret
   478                                  
   479                                  ; Before checking the Volume Id we need to verify that a valid one exists
   480                                  ; We assume that unless a valid boot sector exists on the target disk, no
   481                                  ; valid Volume Id can exist.
   482                                  
   483                                  SwitchesOkForHardDisk:
   484 00000073 505351521E              	SaveReg <ax,bx,cx,dx,ds>
   485 00000078 A0[0000]                	mov	al,[drive]
   486                                  LogBootSect equ LOGBOOTSECT	; NASM port equate
   487 0000007B B90100                  	mov	cx,LogBootSect
   488 0000007E 31D2                    	xor	dx,dx
   489 00000080 8D1E[DB04]              	lea	bx,[scratchBuffer]		; ScratchBuffer := Absolute_Read_Disk(
   490                                  						;INT	 25h				 ;		      Logical_sec_1 )
   491                                  
   492                                  						;Assume Dir for vol ID exists in 1st 32mb of partition
   493                                  
   494 00000084 C706[0200]0000          	mov	word [Read_Write_Relative + Start_Sector_High],0
   495 0000008A E8(0000)                	call	Read_Disk			;				;AC000;
   496                                  						;	on the stack. We throw them away
   497                                  
   498 0000008D 7307                    	jnc	CheckSignature
   499 0000008F F9                      	stc
   500 00000090 1F5A595B58              	RestoreReg <ds,dx,cx,bx,ax>
   501 00000095 C3                      	ret
   502                                  
   503                                  CheckSignature: 				; IF (Boot.Boot_Signature != aa55)
   504                                  
   505                                  ScratchBuffer equ scratchBuffer	; NASM port label
   506 00000096 A1[D906]                	mov	ax, word ptr [ScratchBuffer + Boot_Signature] ;AC000;
   507 00000099 3D55AA                  	cmp	ax, 0aa55h			;Find a valid boot record?
   508 0000009C 1F5A595B58              	RestoreReg <ds,dx,cx,bx,ax>
   509 000000A1 F8                      	clc					;No, so no need to check label
   510                                  ;	$IF	Z				;No further checking needed	;AC000;
   511 000000A2 750E                    	JNZ DD_IF8
   512 000000A4 F706[0000]000C          	   test    word [SwitchMap],(SWITCH_Select | SWITCH_AUTOTEST) ;Should we prompt for vol label?;AN000;
   513                                  ;	   $IF	   Z				;Yes, if /Select not entered	;AN000;
   514 000000AA 7505                    	   JNZ DD_IF9
   515 000000AC E8A906                  	      call    CheckVolumeId		;Go ask user for vol label	;     ;
   516                                  ;	   $ELSE				;/Select entered		;AN000;
   517 000000AF EB01                    	   JMP SHORT DD_EN9
   518                                  DD_IF9:
   519 000000B1 F8                      	      clc				;CLC indicates passed label test;AN000;
   520                                  ;	   $ENDIF				; for the return		;AN000;
   521                                  DD_EN9:
   522                                  ;	$ENDIF
   523                                  DD_IF8:
   524 000000B2 C3                      	return
   525                                  
   526                                  Incomp_Message: 				;an000; fix PTM 809
   527                                  
   528 000000B3 BA[0000]E8(0000)        	Message msgIncompatibleParameters	;an000; print incompatible parms
   529 000000B9 F9                      	stc					;an000; signal error
   530 000000BA C3                      	return					;an000; return to caller
   531                                  
   532                                  Print_And_Return:
   533                                  						;call	 PrintString			 ;				 ;AC000;
   534 000000BB F9                      	stc
   535 000000BC C3                      	return
   536                                  
   537                                  
   538                                  CheckFor5InchDrives:
   539                                  
   540                                  						;If drive type is anything other than 48 or 96, then only /V/S/H/N/T allowed
   541 000000BD 803E[0100]01            	cmp	byte [deviceParameters + DP_DeviceType],DEV_5INCH96TPI
   542 000000C2 7422                    	je	Got96
   543                                  
   544 000000C4 803E[0100]00            	cmp	byte [deviceParameters + DP_DeviceType],DEV_5INCH
   545 000000C9 7435                    	je	Got48
   546                                  
   547 000000CB 31C0                    	xor	ax,ax								;an000; dms;clear reg
   548                                  Switch_V equ SWITCH_V	; NASM port equate
   549                                  Switch_S equ SWITCH_S	; NASM port equate
   550 000000CD 0D3302                  	or	ax,(Switch_V | Switch_S | Switch_N | Switch_T | Switch_B)	;an000; dms;set up switch mask
   551                                  Switch_Backup equ SWITCH_BACKUP	; NASM port equate
   552                                  Switch_Select equ SWITCH_SELECT	; NASM port equate
   553                                  Switch_Autotest equ SWITCH_AUTOTEST	; NASM port equate
   554 000000D0 0D040C                  	or	ax,(Switch_Backup | Switch_Select | Switch_Autotest)		;an000; dms;
   555                                  %IF ShipDisk
   556                                  Switch_Z equ SWITCH_Z	; NASM port equate
   557                                  	or	ax,Switch_Z							;an000; dms;
   558                                  %ENDIF
   559 000000D3 F7D0                    	not	ax								;an000; dms;
   560 000000D5 8506[0000]              	test	[switchmap],ax							;an000; dms;invalid switch?
   561 000000D9 7408                    	jz	Goto_Got_BPB1							;an000;dms;continue format
   562 000000DB BA[0000]E8(0000)        	Message msgParametersNotSupportedByDrive ;			 ;AC000;
   563 000000E1 EBD8                    	jmp	short Print_And_Return
   564                                  
   565                                  Goto_Got_BPB1:
   566 000000E3 EB6D                    	jmp	Goto_Got_BPB
   567 000000E5 90                      	nop	; identicalise
   568                                  						; We have a 96tpi floppy drive
   569                                  						; /4 allows just about all switches however, /1 requires /4
   570                                  Got96:
   571                                  ;;;DMS;;test	switchmap, SWITCH_8		;an000; If /8 we have an error
   572                                  ;;;DMS;;jnz	Incomp_message			;an000; tell user error
   573                                  
   574 000000E6 F706[0000]8000          	test	word [switchmap], SWITCH_4
   575 000000EC 752C                    	jnz	CheckForInterestingSwitches	;If /4 check /N/T/V/S
   576                                  
   577 000000EE F706[0000]4000          	test	word [switchmap], SWITCH_1		;If /1 and /4 check others
   578 000000F4 740A                    	jz	Got48
   579                                  
   580                                  						;If only /1 with no /4, see if /N/T
   581 000000F6 F706[0000]3000          	test	word [SwitchMap],(Switch_N | Switch_T)
   582 000000FC 751C                    	jnz	CheckForInterestingSwitches
   583                                  
   584                                  Incomp_message equ Incomp_Message	; NASM port label
   585 000000FE EBB3                    	jmp	Incomp_message			;an000; tell user error occurred
   586                                  
   587                                  Got48:
   588                                  						;Ignore /4 for non-96tpi 5 1/4" drives
   589 00000100 8126[0000]7FFF          	and	word [switchmap], ~ SWITCH_4
   590                                  
   591                                  						;Ignore /1 if drive has only one head and not /8
   592                                  BPB_Heads equ BPB_HEADS	; NASM port equate
   593 00000106 833E[1600]01            	cmp	word [deviceParameters + DP_BPB + BPB_Heads], 1
   594 0000010B 770D                    	ja	CheckForInterestingSwitches
   595 0000010D F706[0000]0001          	test	word [switchmap], SWITCH_8
   596 00000113 7405                    	jz	CheckForInterestingSwitches
   597 00000115 8326[0000]BF            	and	word [switchmap], ~ SWITCH_1
   598                                  
   599                                  						;Are any interesting switches set?
   600                                  CheckForInterestingSwitches:
   601 0000011A F706[0000]F8F1          	test	word [switchmap], ~ (SWITCH_V | SWITCH_S | Switch_Backup | SWITCH_SELECT | SWITCH_AUTOTEST | Switch_B)
   602 00000120 7433                    	jz	Goto_EndSwitchCheck		;No, everything ok
   603                                  
   604                                  						;At this point there are switches other than /v/s/h
   605 00000122 F706[0000]3000          	test	word [SwitchMap],(SWITCH_N | SWITCH_T)
   606 00000128 7455                    	jz	Use_48tpi			;Not /n/t, so must be /b/1/8/4
   607                                  
   608                                  						;We've got /N/T, see if there are others
   609 0000012A F706[0000]C8F3          	test	word [SwitchMap], ~ (SWITCH_N | SWITCH_T | SWITCH_V | SWITCH_S | Switch_Backup | SWITCH_SELECT | SWITCH_AUTOTEST)
   610 00000130 7426                    	jz	NT_Compatible			;Nope, all is well
   611                                  
   612                                  						;If 96tpi drive and /1 exists with /N/T, then okay, otherwise error
   613 00000132 803E[0100]01            	cmp	byte [deviceParameters + DP_DeviceType],DEV_5INCH96TPI
   614 00000137 7510                    	jne	Bad_NT_Combo
   615                                  
   616 00000139 F706[0000]8DFF          	test	word [SwitchMap], ~ (SWITCH_1 | SWITCH_N | SWITCH_T | SWITCH_V)
   617 0000013F 7508                    	jnz	Bad_NT_Combo
   618 00000141 F706[0000]FAF3          	test	word [SwitchMap], ~ (SWITCH_S | Switch_Backup | SWITCH_SELECT | Switch_Autotest)
   619 00000147 7409                    	jz	Goto_Got_BPB
   620                                  
   621                                  Bad_NT_Combo:
   622 00000149 BA[0000]E8(0000)        	Message msgIncompatibleParameters	;				;AC000;
   623 0000014F E969FF                  	jmp	Print_And_Return
   624                                  
   625                                  Goto_Got_BPB:
   626                                  Got_BPB_Ok equ Got_BPB_OK	; NASM port label
   627 00000152 EB76                    	jmp	Got_BPB_Ok			;Sleazy, but je won't reach it
   628 00000154 90                      	nop	; identicalise
   629                                  
   630                                  Goto_EndSwitchCheck:
   631 00000155 E93001                  	jmp	EndSwitchCheck
   632                                  						;There is a problem with /N/T in that IBMBIO will default to a BPB with the
   633                                  						;media byte set to F0 (other) if the /N/T combo is used for the format. This
   634                                  						;will cause problems if we are creating a media that has an assigned media
   635                                  						;byte, i.e. 160,180,320,360, or 720k media using /N/T. To avoid this problem,
   636                                  						;if we detect a /N/T combo that would correspond to one of these medias, then
   637                                  						; we will set things up using the /4/1/8 switches instead of the /N/T
   638                                  						; MT - 7/17/86 PTR 33D0110
   639                                  
   640                                  						; Combo's that we look for - 96tpi drive @ /T:40, /N:9
   641                                  						;			     96tpi drive @ /T:40, /N:8
   642                                  						;
   643                                  						; Look for this combo after we set everything up with the /T/N routine
   644                                  						;			     1.44 drive  @ /T:80, /N:9
   645                                  
   646                                  NT_Compatible:
   647 00000158 803E[0100]01            	cmp	byte [deviceParameters + DP_DeviceType],DEV_5INCH96TPI
   648 0000015D 75F3                    	jne	Goto_Got_BPB
   649                                  
   650 0000015F 833E[0000]28            	cmp	word [TrackCnt],40			;Look for 40 tracks
   651 00000164 7564                    	jne	Got_BPB_Ok
   652                                  
   653 00000166 833E[0000]09            	cmp	word [NumSectors],9			;9 sectors?
   654 0000016B 740D                    	je	Found_48tpi_Type
   655                                  
   656 0000016D 833E[0000]08            	cmp	word [NumSectors],8			;8 sectors?
   657 00000172 75DE                    	jne	Goto_Got_BPB			;Nope, different type, let it go thru
   658                                  
   659 00000174 810E[0000]0001          	or	word [SwitchMap],SWITCH_8		;Yes, turn on /8 switch
   660                                  
   661                                  Found_48tpi_Type:
   662 0000017A 8326[0000]CF            	and	word [SwitchMap],~ (SWITCH_N | SWITCH_T) ;Turn off /T/N
   663                                  
   664                                  ;******End PTR fix
   665                                  
   666                                  ; if we have a 96 tpi drive then we will be using it in 48 tpi mode
   667                                  Use_48tpi:
   668 0000017F 803E[0100]01            	cmp	byte [deviceParameters + DP_DeviceType], DEV_5INCH96TPI
   669 00000184 750B                    	jne	Not96tpi
   670                                  
   671                                  DP_MediaType equ DP_MEDIATYPE	; NASM port equate
   672 00000186 C606[0600]01            	mov	byte [deviceParameters + DP_MediaType], 1
   673                                  DP_Cylinders equ DP_CYLINDERS	; NASM port equate
   674 0000018B C706[0400]2800          	mov	word [deviceParameters + DP_Cylinders], 40
   675                                  Not96tpi:
   676                                  
   677                                  ; Since we know we are formatting in 48 tpi mode turn on /4 switch
   678                                  ; (We use this info in LastChanceToSaveIt)
   679 00000191 810E[0000]8000          	or	word [switchmap], SWITCH_4
   680                                  
   681                                  ; At this point we know that we will require a special BPB
   682                                  ; It will be one of:
   683                                  ;    0) 9 track 2 sides - if no switches
   684                                  ;    1) 9 track 1 side	- if only /1 specified
   685                                  ;    2) 8 track 2 sides - if only /8 specified
   686                                  ;    3) 8 track 1 side	- if /8 and /1 specified
   687                                  ;
   688                                  Get_BPBs:
   689                                  ; ax is used to keep track of which of the above BPB's we want
   690 00000197 31C0                    	xor	ax, ax
   691                                  
   692                                  NotSlashB:
   693                                  
   694 00000199 F706[0000]4000          	test	word [switchmap], SWITCH_1
   695 0000019F 7403                    	jz	NotSingleSided
   696 000001A1 83C001                  	add	ax, 1
   697                                  NotSingleSided:
   698                                  
   699 000001A4 F706[0000]0001          	test	word [switchmap], SWITCH_8
   700 000001AA 7408                    	jz	Not8SectorsPerTrack
   701 000001AC 83C002                  	add	ax, 2
   702                                  ; /8 implies Old_Dir = TRUE
   703 000001AF C606[0000]FF            	mov	byte [Old_Dir],TRUE
   703          ******************       warning: byte data exceeds bounds [-w+number-overflow]
   704                                  Not8SectorsPerTrack:
   705                                  
   706                                  ; Ok now we know which BPB to use so lets move it to the device parameters
   707                                  
   708                                  a_BPB_struc_size equ A_BPB_struc_size	; NASM port equate
   709 000001B4 BB1F00                  	mov	bx, a_BPB_struc_size
   710 000001B7 F7E3                    	mul	bx
   711                                  CustomBPBs equ customBPBs	; NASM port label
   712 000001B9 8D36[4000]              	lea	si, [CustomBPBs]
   713 000001BD 01C6                    	add	si, ax
   714 000001BF 8D3E[0700]              	lea	di, [deviceParameters + DP_BPB]
   715 000001C3 B91F00                  	mov	cx, a_BPB_struc_size
   716 000001C6 1E                      	push	ds
   717 000001C7 07                      	pop	es
   718 000001C8 F2A4                    	repnz	movsb
   719                                  
   720                                  ;*****************************************************************
   721                                  ;*  /N/T DCR stuff.  Possible flaw exists if we are dealing with a
   722                                  ;*  HardDisk. If they support the  "custom format" features for
   723                                  ;*  Harddisks too, then CheckForInterestingSwitches should
   724                                  ;*  consider /n/t UNinteresting, and instead of returning
   725                                  ;*  after setting up the custom BPB we fall through and do our
   726                                  ;*  Harddisk Check.
   727                                  Got_BPB_OK:
   728 000001CA F706[0000]3000          	test	word [switchmap],SWITCH_N+SWITCH_T
   729 000001D0 7503                    	jnz	Setup_Stuff
   730 000001D2 E9B300                  	jmp	EndSwitchCheck
   731                                  Setup_Stuff:
   732                                  ; Set up NumSectors and SectorsPerTrack entries correctly
   733 000001D5 F706[0000]2000          	test	word [switchmap],SWITCH_N
   734 000001DB 7408                    	jz	No_Custom_Seclim
   735 000001DD A1[0000]                	mov	ax,word ptr [NumSectors]
   736                                  DeviceParameters equ deviceParameters	; NASM port label
   737                                  BPB_SectorsPerTrack equ BPB_SECTORSPERTRACK	; NASM port equate
   738 000001E0 A3[1400]                	mov	[DeviceParameters + DP_BPB + BPB_SectorsPerTrack],ax
   739 000001E3 EB06                    	jmp	short Handle_Cyln
   740                                  No_Custom_Seclim:
   741 000001E5 A1[1400]                	mov	ax,[deviceParameters + DP_BPB + BPB_SectorsPerTrack]
   742 000001E8 A3[0000]                	mov	[NumSectors],ax
   743                                  
   744                                  Handle_Cyln:
   745 000001EB F706[0000]1000          	test	word [switchmap],SWITCH_T
   746 000001F1 7408                    	jz	No_Custom_Cyln
   747                                  ; Set up TrackCnt and Cylinders entries correctly
   748 000001F3 A1[0000]                	mov	ax,[TrackCnt]
   749 000001F6 A3[0400]                	mov	[DeviceParameters + DP_Cylinders],ax
   750 000001F9 EB06                    	jmp	short Check_720
   751                                  No_Custom_Cyln:
   752 000001FB A1[0400]                	mov	ax,[DeviceParameters + DP_Cylinders]
   753 000001FE A3[0000]                	mov	[TrackCnt],ax
   754                                  
   755                                  ;****PTM P868  - Always making 3 1/2 media byte 0F0h. If 720, then set to
   756                                  ;		 0F9h and use the DOS 3.20 BPB. Should check all drives
   757                                  ;		 at this point (Make sure not 5 inch just for future
   758                                  ;		 protection)
   759                                  ;		 We will use the known BPB info for 720 3 1/2 diskettes for
   760                                  ;		 this special case. All other new diskette media will use the
   761                                  ;		 calculations that follow Calc_Total for BPB info.
   762                                  ; Fix MT  11/12/86
   763                                  
   764                                  Check_720:
   765                                  
   766 00000201 803E[0100]01            	cmp	byte [deviceParameters + DP_DeviceType],DEV_5INCH96TPI
   767 00000206 7434                    	je	Calc_Total
   768                                  
   769 00000208 803E[0100]00            	cmp	byte [deviceParameters + DP_DeviceType],DEV_5INCH
   770 0000020D 742D                    	je	Calc_Total
   771                                  
   772 0000020F 833E[0000]50            	cmp	word [TrackCnt],80
   773 00000214 7526                    	jne	Calc_Total
   774                                  
   775 00000216 833E[0000]09            	cmp	word [NumSectors],9
   776 0000021B 751F                    	jne	Calc_Total
   777                                  
   778                                  ; At this point we know we have a 3 1/2 720kb diskette to format. Use the
   779                                  ; built in BPB rather than the one handed to us by DOS, because the DOS one
   780                                  ; will be based on the default for that drive, and it can be different from
   781                                  ; what we used in DOS 3.20 for the 720's. Short sighted on our part to use
   782                                  ; 0F9h as the media byte, should have use 0F0h (OTHER) and then we wouldn't
   783                                  ; have this problem.
   784                                  
   785 0000021D 1E06565751              	SaveReg <ds,es,si,di,cx>
   786                                  
   787                                  
   788 00000222 B9[ssss]                	mov	cx,data			;Setup seg regs, just in case they ain't!
   789 00000225 8ED9                    	mov	ds,cx
   790 00000227 8EC1                    	mov	es,cx
   791                                  
   792 00000229 BE[BC00]                	mov	si,offset BPB720		;Copy the BPB!
   793 0000022C BF[0700]                	mov	di,offset deviceParameters + DP_BPB
   794 0000022F B91F00                  	mov	cx,a_BPB_struc_size
   795 00000232 F3A4                    	rep	movsb
   796 00000234 595F5E071F              	RestoreReg <cx,di,si,es,ds>
   797 00000239 EB4D                    	jmp	EndSwitchCheck
   798 0000023B 90                      	nop	; identicalise
   799                                  
   800                                  ;End PTM P868 fix ****************************************
   801                                  
   802                                  Calc_Total:
   803 0000023C A1[0000]                	mov	ax,[NumSectors]
   804 0000023F 8B1E[1600]              	mov	bx,[DeviceParameters + DP_BPB + BPB_Heads]
   805 00000243 F6E3                    	mul	bl				; AX = # of sectors * # of heads
   806 00000245 F726[0000]              	mul	word [TrackCnt]			; DX:AX = Total Sectors
   807 00000249 09D2                    	or	dx,dx
   808 0000024B 7505                    	jnz	Got_BigTotalSectors
   809                                  BPB_TotalSectors equ BPB_TOTALSECTORS	; NASM port equate
   810 0000024D A3[0F00]                	mov	[DeviceParameters + DP_BPB + BPB_TotalSectors],ax
   811 00000250 EB0F                    	jmp	short Set_BPB
   812                                  Got_BigTotalSectors:
   813                                  BPB_BigTotalSectors equ BPB_BIGTOTALSECTORS	; NASM port equate
   814 00000252 A3[1C00]                	mov	[DeviceParameters + DP_BPB + BPB_BigTotalSectors],ax
   815 00000255 8916[1E00]              	mov	[DeviceParameters + DP_BPB + BPB_BigTotalSectors+2],dx
   816 00000259 52                      	push	dx				; preserve dx for further use
   817 0000025A 31D2                    	xor	dx,dx
   818 0000025C 8916[0F00]              	mov	[DeviceParameters + DP_BPB + BPB_TotalSectors],dx
   819 00000260 5A                      	pop	dx
   820                                  
   821                                  Set_BPB:
   822                                  ; We calculate the number of sectors required in a FAT. This is done as:
   823                                  ; # of FAT Sectors = TotalSectors / SectorsPerCluster * # of bytes in FAT to
   824                                  ; represent one cluster (i.e. 3/2) / BytesPerSector (i.e. 512)
   825 00000261 31DB                    	xor	bx,bx
   826                                  BPB_SectorsPerCluster equ BPB_SECTORSPERCLUSTER	; NASM port equate
   827 00000263 8A1E[0900]              	mov	bl,[DeviceParameters + DP_BPB + BPB_SectorsPerCluster]
   828 00000267 F7F3                    	div	bx				; DX:AX contains # of clusters
   829                                  ; now multiply by 3/2
   830 00000269 BB0300                  	mov	bx,3
   831 0000026C F7E3                    	mul	bx
   832 0000026E BB0200                  	mov	bx,2
   833 00000271 F7F3                    	div	bx
   834 00000273 31D2                    	xor	dx,dx				; throw away modulo
   835                                  ; now divide by 512
   836 00000275 BB0002                  	mov	bx,512
   837 00000278 F7F3                    	div	bx
   838                                  ; dx:ax contains number of FAT sectors necessary
   839 0000027A 40                      	inc	ax				; Go one higher
   840                                  BPB_SectorsPerFAT equ BPB_SECTORSPERFAT	; NASM port equate
   841 0000027B A3[1200]                	mov	[DeviceParameters + DP_BPB + BPB_SectorsPerFAT],ax
   842 0000027E C606[0600]00            	mov	byte [DeviceParameters + DP_MediaType],0
   843                                  BPB_MediaDescriptor equ BPB_MEDIADESCRIPTOR	; NASM port equate
   844 00000283 C606[1100]F0            	mov	byte [DeviceParameters + DP_BPB + BPB_MediaDescriptor],Custom_Media
   845                                  
   846                                  
   847                                  EndSwitchCheck:
   848 00000288 F8                      	clc
   849 00000289 C3                      	return
   850                                  
   851                                  CheckSwitches endp
   852                                  
   853                                  ;*****************************************************************************
   854                                  ;Routine name: Size_To_Switch
   855                                  ;*****************************************************************************
   856                                  ;
   857                                  ;Description: Given the SizeMap field as input indicating the SIZE= value
   858                                  ;	      entered, validate that the specified size is valid for the
   859                                  ;	      drive, and if so, turn on the appropriate data fields and
   860                                  ;	      switches that would be turned on by the equivilent command line
   861                                  ;	      using only switchs. All defined DOS 4.00 sizes are hardcoded,
   862                                  ;	      in case a drive type of other is encountered that doesn't
   863                                  ;	      qualify as a DOS 4.00 defined drive. Exit with error message if
   864                                  ;	      unsupported drive. The switches will be setup for the CheckSwitches
   865                                  ;	      routine to sort out, using existing switch matrix logic.
   866                                  ;
   867                                  ;Called Procedures: Low_Density_Drive
   868                                  ;		    High_Capacity_Drive
   869                                  ;		    720k_Drives
   870                                  ;		    Other_Drives
   871                                  ;
   872                                  ;Change History: Created	8/1/87	       MT
   873                                  ;
   874                                  ;Input: SizeMap
   875                                  ;	Fatal_Error = NO
   876                                  ;
   877                                  ;Output: Fatal_Error = YES/NO
   878                                  ;	 SwitchMap = appropriate Switch_?? values turned on
   879                                  ;	 TrackCnt, NumSectors set if Switch_T,Switch_N turned on
   880                                  ;*****************************************************************************
   881                                  
   882                                  
   883                                  Procedure Size_To_Switch
   884                                  
   885 0000028A 803E[3200]00            	cmp	byte [SizeMap],0			;Are there sizes entered?	 ;AN001;
   886                                  ;	$IF	NE				;Yes				;AN001;
   887 0000028F 744A                    	JE DD_IF13
   888 00000291 803E[0100]05            	   cmp	   byte [deviceParameters + DP_DeviceType],DEV_HARDDISK ;AN000;		;AN001;
   889                                  ;	   $IF	   E				;No size for fixed disk 	;AN001;
   890 00000296 7508                    	   JNE DD_IF14
   891 00000298 BA[0000]E8(0000)        	      Message msgIncompatibleParametersForHardDisk ;			;AN001;
   892                                  ;	   $ELSE				;Diskette, see what type	;AN001;
   893 0000029E EB3B                    	   JMP SHORT DD_EN14
   894                                  DD_IF14:
   895 000002A0 803E[0100]00            	      cmp     byte [deviceParameters + DP_DeviceType],DEV_5INCH ;	;AN001;
   896                                  ;	      $IF     E 			;Found 180/360k drive		;AN001;
   897 000002A5 7505                    	      JNE DD_IF16
   898 000002A7 E87000                  		 call	 Low_Density_Drive	;Go set switches		;AN001;
   899                                  ;	      $ELSE				;Check for 96TPI		;AN001;
   900 000002AA EB2F                    	      JMP SHORT DD_EN16
   901                                  DD_IF16:
   902 000002AC 803E[0100]01            		 cmp	 byte [deviceParameters + DP_DeviceType],DEV_5INCH96TPI ;AN001; ;
   903                                  ;		 $IF	 E			;Found it			;AN001;
   904 000002B1 7505                    		 JNE DD_IF18
   905 000002B3 E84500                  		    call    High_Capacity_Drive ;				;AN001;
   906                                  ;		 $ELSE				;				;AN001;
   907 000002B6 EB23                    		 JMP SHORT DD_EN18
   908                                  DD_IF18:
   909 000002B8 803E[0100]02            		    cmp     byte [deviceParameters + DP_DeviceType],DEV_3INCH720KB ;AN0001;
   910                                  ;		    $IF     E			;Found 720k drive		;AN001;
   911 000002BD 7505                    		    JNE DD_IF20
   912 000002BF E89100                  		       call    Small_Drives	;				;AN001;
   913                                  ;		    $ELSE			;				;AN001;
   914 000002C2 EB17                    		    JMP SHORT DD_EN20
   915                                  DD_IF20:
   916 000002C4 803E[0100]07            		       cmp     byte [deviceParameters + DP_DeviceType],DEV_OTHER ;AN001;
   917                                  ;		       $IF     E		;Must be 1.44mb 		;AN001;
   918 000002C9 7505                    		       JNE DD_IF22
   919 000002CB E89200                  			  call	  Other_Drives	;				;AN001;
   920                                  ;		       $ELSE			;				;AN001;
   921 000002CE EB0B                    		       JMP SHORT DD_EN22
   922                                  DD_IF22:
   923 000002D0 BA[0000]E8(0000)        			  Message msgParametersNotSupportedByDrive ;		;AN001;
   924 000002D6 C606[0000]FF            			  mov	  byte [Fatal_Error],Yes ;				;AN001;
   925                                  ;		       $ENDIF			;				;AN001;
   926                                  DD_EN22:
   927                                  ;		    $ENDIF			;				;AN001;
   928                                  DD_EN20:
   929                                  ;		 $ENDIF 			;				;AN001;
   930                                  DD_EN18:
   931                                  ;	      $ENDIF				;				;AN001;
   932                                  DD_EN16:
   933                                  ;	   $ENDIF				;				;AN001;
   934                                  DD_EN14:
   935                                  ;	$ENDIF					;				;AN001;
   936                                  DD_IF13:
   937 000002DB 803E[0000]FF            	cmp	byte [Fatal_Error],Yes 		;				;AN001;
   938                                  ;	$IF	E				;				;AN001;
   939 000002E0 7506                    	JNE DD_IF30
   940 000002E2 BA[0000]E8(0000)        	   Message msgIncompatibleParameters	;				;AN001;
   941                                  ;	$ENDIF					;				;AN001;
   942                                  DD_IF30:
   943                                  
   944 000002E8 803E[0100]05            	cmp	byte [deviceParameters + DP_DeviceType],DEV_HARDDISK			;an001;
   945                                  ;	$if	e								;an001;
   946 000002ED 7505                    	JNE DD_IF32
   947 000002EF C606[0000]FF            		mov	byte [Fatal_Error],Yes 					;an001;
   948                                  ;	$endif									;an001;
   949                                  DD_IF32:
   950                                  
   951 000002F4 8126[0000]FFEF          	and	word [SwitchMap],~ Switch_F		;Turn off /F so doesn't effect  ;AN001;
   952 000002FA C3                      	ret					; following logic		;AN001;
   953                                  
   954                                  Size_To_Switch endp
   955                                  
   956                                  ;*****************************************************************************
   957                                  ;Routine name: High_Capacity_Drive
   958                                  ;*****************************************************************************
   959                                  ;
   960                                  ;Description: See if 1.2mb diskette, or one of the other 5 1/4 sizes. Turn
   961                                  ;	      on /4 if 360k or lower
   962                                  ;
   963                                  ;Called Procedures: Low_Density_Drive
   964                                  ;
   965                                  ;Change History: Created	8/1/87	       MT
   966                                  ;
   967                                  ;Input: SizeMap
   968                                  ;	Fatal_Error = NO
   969                                  ;
   970                                  ;Output: Fatal_Error = YES/NO
   971                                  ;	 SwitchMap = Switch_4 if 360k or lowere
   972                                  ;*****************************************************************************
   973                                  
   974                                  Procedure High_Capacity_Drive			;
   975                                  
   976 000002FB F606[3200]20            	test	byte [SizeMap],Size_1200		;1.2mb diskette?		 ;AN001;
   977                                  ;	$IF	Z				;Nope				;AN001;
   978 00000300 7517                    	JNZ DD_IF34
   979 00000302 E81500                  	   call    Low_Density_Drive		;Check for /4 valid types	;AN001;
   980                                  No equ NO	; NASM port equate
   981 00000305 803E[0000]00            	   cmp	   byte [Fatal_Error], No		;Find 160/180/320/360k? 	;AN001;
   982                                  ;	   $IF	   E				;Yes				;AN001;
   983 0000030A 7508                    	   JNE DD_IF35
   984 0000030C 810E[0000]8000          	      or      word [SwitchMap],Switch_4	;Turn on /4 switch		;AN001;
   985                                  ;	   $ELSE				;Did not find valid size	;AN001;
   986 00000312 EB05                    	   JMP SHORT DD_EN35
   987                                  DD_IF35:
   988 00000314 C606[0000]FF            	      mov     byte [Fatal_Error],Yes		;Indicate invalid device	;AN001;
   989                                  ;	   $ENDIF				;				;AN001;
   990                                  DD_EN35:
   991                                  ;	$ENDIF					;				;AN001;
   992                                  DD_IF34:
   993 00000319 C3                      	ret					;				;AN001;
   994                                  
   995                                  High_Capacity_Drive endp
   996                                  
   997                                  ;*****************************************************************************
   998                                  ;Routine name: Low_Density_Drive
   999                                  ;*****************************************************************************
  1000                                  ;
  1001                                  ;Description: See if 360k diskete or one of the other 5 1/4 sizes. Turn
  1002                                  ;	      on the /1/8 switch to match sizes
  1003                                  ;
  1004                                  ;Called Procedures: Low_Density_Drive
  1005                                  ;
  1006                                  ;Change History: Created	8/1/87	       MT
  1007                                  ;
  1008                                  ;Input: SizeMap
  1009                                  ;	Fatal_Error = NO
  1010                                  ;
  1011                                  ;Output: Fatal_Error = YES/NO
  1012                                  ;	 SwitchMap = Switch_1, Switch_8 to define size
  1013                                  ;
  1014                                  ;	360k = No switch
  1015                                  ;	320k = Switch_8
  1016                                  ;	180k = Switch_1
  1017                                  ;	160k = Switch_1 + Switch_8
  1018                                  ;*****************************************************************************
  1019                                  
  1020                                  
  1021                                  Procedure Low_Density_Drive			;				;AN000;
  1022                                  						;
  1023 0000031A F606[3200]01            	test	byte [SizeMap],Size_160		;				 ;AN001;
  1024                                  ;	$IF	NZ				;				;AN001;
  1025 0000031F 7408                    	JZ DD_IF39
  1026 00000321 810E[0000]4001          	   or	   word [SwitchMap],Switch_1+Switch_8	;				;AN001;
  1027                                  ;	$ELSE					;				;AN001;
  1028 00000327 EB29                    	JMP SHORT DD_EN39
  1029                                  DD_IF39:
  1030 00000329 F606[3200]02            	   test    byte [SizeMap],Size_180		;				 ;AN001;
  1031                                  ;	   $IF	   NZ				;				;AN001;
  1032 0000032E 7407                    	   JZ DD_IF41
  1033 00000330 830E[0000]40            	      or      word [SwitchMap],Switch_1	;				;AN001;
  1034                                  ;	   $ELSE				;				;AN001;
  1035 00000335 EB1B                    	   JMP SHORT DD_EN41
  1036                                  DD_IF41:
  1037 00000337 F606[3200]04            	      test    byte [SizeMap],Size_320		;				 ;AN001;
  1038                                  ;	      $IF     NZ			;				;AN001;
  1039 0000033C 7408                    	      JZ DD_IF43
  1040 0000033E 810E[0000]0001          		 or	 word [SwitchMap],Switch_8	;				;AN001;
  1041                                  ;	      $ELSE				;				;AN001;
  1042 00000344 EB0C                    	      JMP SHORT DD_EN43
  1043                                  DD_IF43:
  1044 00000346 F606[3200]08            		 test	 byte [SizeMap],Size_360	;				 ;AN001;
  1045                                  ;		 $IF	 Z			;None of the above, not valid	;AN001;
  1046 0000034B 7505                    		 JNZ DD_IF45
  1047 0000034D C606[0000]FF            		    mov     byte [Fatal_Error],Yes	;				;AN001;
  1048                                  ;		 $ENDIF 			;				;AN001;
  1049                                  DD_IF45:
  1050                                  ;	      $ENDIF				;				;AN001;
  1051                                  DD_EN43:
  1052                                  ;	   $ENDIF				;				;AN001;
  1053                                  DD_EN41:
  1054                                  ;	$ENDIF					;				;AN001;
  1055                                  DD_EN39:
  1056 00000352 C3                      	ret					;				;AN001;
  1057                                  
  1058                                  Low_Density_Drive endp
  1059                                  
  1060                                  ;*****************************************************************************
  1061                                  ;Routine name: Small_Drives
  1062                                  ;*****************************************************************************
  1063                                  ;
  1064                                  ;Description: See if 720k media in 720 drive, set up /T/N if so, otherwise
  1065                                  ;	      error
  1066                                  ;
  1067                                  ;Called Procedures: None
  1068                                  ;
  1069                                  ;Change History: Created	8/1/87	       MT
  1070                                  ;
  1071                                  ;Input: SizeMap
  1072                                  ;	Fatal_Error = NO
  1073                                  ;
  1074                                  ;Output: Fatal_Error = YES/NO
  1075                                  ;	 SwitchMap
  1076                                  ;	 TrackCnt
  1077                                  ;	 NumSectors
  1078                                  ;	720k = /T:80 /N:9
  1079                                  ;*****************************************************************************
  1080                                  
  1081                                  Procedure Small_Drives				;				;AN000;
  1082                                  
  1083 00000353 F606[3200]10            	test	byte [SizeMap],Size_720		;Ask for 720k?			 ;AN001;
  1084                                  ;	$IF	Z				;Nope, thats all drive can do	;AN001;
  1085 00000358 7505                    	JNZ DD_IF50
  1086 0000035A C606[0000]FF            	   mov	   byte [Fatal_Error],Yes		;Indicate error 		;AN001;
  1087                                  ;	$ENDIF					;				;AN001;
  1088                                  DD_IF50:
  1089 0000035F C3                      	ret					;				;AN001;
  1090                                  
  1091                                  Small_Drives endp
  1092                                  
  1093                                  
  1094                                  ;*****************************************************************************
  1095                                  ;Routine name: Other_Drives
  1096                                  ;*****************************************************************************
  1097                                  ;
  1098                                  ;Description: See if 1.44 media or 720k media, setup /t/n, otherwise error
  1099                                  ;
  1100                                  ;Called Procedures: Small_Drives
  1101                                  ;
  1102                                  ;Change History: Created	8/1/87	       MT
  1103                                  ;
  1104                                  ;Input: SizeMap
  1105                                  ;	Fatal_Error = NO
  1106                                  ;
  1107                                  ;Output: Fatal_Error = YES/NO
  1108                                  ;	 SwitchMap
  1109                                  ;	 TrackCnt
  1110                                  ;	 NumSectors
  1111                                  ;	720k = /T:80 /N:9
  1112                                  ;*****************************************************************************
  1113                                  
  1114                                  Procedure Other_Drives				;				;AN001;
  1115                                  
  1116 00000360 F606[3200]40            	test	byte [SizeMap],Size_1440		;Ask for 1.44mb diskette?	 ;AN001;
  1117                                  ;	$IF	Z				;Nope				;AN001;
  1118 00000365 751D                    	JNZ DD_IF52
  1119 00000367 E8E9FF                  	   call    Small_Drives 		;See if 720k		       ;AN001;
  1120 0000036A 803E[0000]00            	   cmp	   byte [Fatal_Error],No		;Fatal_error=Yes if not 	;AN001;
  1121                                  ;	   $IF	   E				;Got 720k			;AN001;
  1122 0000036F 7511                    	   JNE DD_IF53
  1123 00000371 830E[0000]30            	      or      word [SwitchMap],Switch_T+Switch_N ;Turn on /T:80 /N:9		;AN001;
  1124 00000376 C706[0000]5000          	      mov     word [TrackCnt],80		;				;AN001;
  1125 0000037C C706[0000]0900          	      mov     word [NumSectors],9		;				;AN001;
  1126                                  ;	   $ENDIF				;				;AN001;
  1127                                  DD_IF53:
  1128                                  ;	$ELSE					;Asked for 1.44mb		;AN001;
  1129 00000382 EB11                    	JMP SHORT DD_EN52
  1130                                  DD_IF52:
  1131 00000384 830E[0000]30            	   or	   word [SwitchMap],Switch_T+Switch_N	;Turn on /T:80 /N:18;		;AN001;
  1132 00000389 C706[0000]5000          	   mov	   word [TrackCnt],80			;This will protect SIZE=1440	;AN001;
  1133 0000038F C706[0000]1200          	   mov	   word [NumSectors],18		; from non-standard drives with ;AN001;
  1134                                  ;	$ENDIF					; type of 'other'		;AN001;
  1135                                  DD_EN52:
  1136 00000395 C3                      	ret					;				;AN001;
  1137                                  
  1138                                  Other_Drives endp
  1139                                  
  1140                                  
  1141                                  ;*****************************************************************************
  1142                                  ;Routine name:Check_T_N
  1143                                  ;*****************************************************************************
  1144                                  ;
  1145                                  ;Description: Make sure than if /T is entered, /N is also entered
  1146                                  ;
  1147                                  ;Called Procedures:  None
  1148                                  ;
  1149                                  ;Change History: Created	8/23/87  MT
  1150                                  ;
  1151                                  ;Input: SizeMap
  1152                                  ;	Fatal_Error = NO
  1153                                  ;
  1154                                  ;Output: Fatal_Error = YES/NO
  1155                                  ;*****************************************************************************
  1156                                  
  1157                                  Procedure Check_T_N
  1158                                  
  1159 00000396 F706[0000]2000          	test	word [SwitchMap],Switch_N		;Make sure /T entered if /N	;AN009;
  1160                                  ;	$IF	NZ,AND				;				;AN009;
  1161 0000039C 7415                    	JZ DD_IF57
  1162 0000039E F706[0000]1000          	test	word [SwitchMap],Switch_T		;				;AN009;
  1163                                  ;	$IF	Z				;				;AN009;
  1164 000003A4 750D                    	JNZ DD_IF57
  1165 000003A6 BA[0000]E8(0000)        	   Message msgBad_T_N			;It wasn't, so barf             ;AN009;
  1166 000003AC C606[0000]FF            	   mov	   byte [Fatal_Error],Yes		;Indicate error 		;AN009;
  1167                                  ;	$ELSE					;				;AN009;
  1168 000003B1 EB1B                    	JMP SHORT DD_EN57
  1169                                  DD_IF57:
  1170 000003B3 F706[0000]1000          	   test    word [SwitchMap],Switch_T		;Make sure /N entered if /T	;AN009;
  1171                                  ;	   $IF	   NZ,AND			;				;AN009;
  1172 000003B9 7413                    	   JZ DD_IF59
  1173 000003BB F706[0000]2000          	   test    word [SwitchMap],Switch_N		;				;AN009;
  1174                                  ;	   $IF	   Z				;It wasn't, so also barf        ;AN009;
  1175 000003C1 750B                    	   JNZ DD_IF59
  1176 000003C3 BA[0000]E8(0000)        	      Message msgBad_T_N		;				;AN009;
  1177 000003C9 C606[0000]FF            	      mov     byte [Fatal_Error],Yes		;Indicate error 		;AN009;
  1178                                  ;	   $ENDIF				;				;AN009;
  1179                                  DD_IF59:
  1180                                  ;	$ENDIF					;				;AN009;
  1181                                  DD_EN57:
  1182 000003CE C3                      	ret
  1183                                  
  1184                                  Check_T_N endp
  1185                                  
  1186                                  
  1187                                  
  1188                                  ;-------------------------------------------------------------------------------
  1189                                  ;    LastChanceToSaveIt:
  1190                                  ;	This routine is called when an error is detected in DiskFormat.
  1191                                  ;	If it returns with carry not set then DiskFormat is restarted.
  1192                                  ;	It gives the oem one last chance to try formatting differently.
  1193                                  ;	fLastChance gets set Then to prevent multiple prompts from being
  1194                                  ;	issued for the same diskette.
  1195                                  ;
  1196                                  ;	Algorithm:
  1197                                  ;		IF (error_loc == Track_0_Head_1) &
  1198                                  ;			  ( Device_type < 96TPI )
  1199                                  ;		   THEN
  1200                                  ;			fLastChance  := TRUE
  1201                                  ;			try formatting 48TPI_Single_Sided
  1202                                  ;		   ELSE return ERROR
  1203                                  ;
  1204                                  LastChanceToSaveIt proc near
  1205                                  
  1206 000003CF 833E[0000]00            	cmp	word [currentCylinder], 0
  1207 000003D4 751D                    	jne	WeCanNotIgnoreThisError
  1208 000003D6 833E[0000]01            	cmp	word [currentHead], 1
  1209 000003DB 7516                    	jne	WeCanNotIgnoreThisError
  1210                                  
  1211 000003DD 803E[0100]00            	cmp	byte [deviceParameters + DP_DeviceType], DEV_5INCH
  1212 000003E2 770F                    	ja	WeCanNotIgnoreThisError
  1213                                  
  1214 000003E4 C606[0000]FF            	mov	byte [fLastChance], TRUE
  1214          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  1215                                  
  1216 000003E9 830E[0000]40            	or	word [switchmap], SWITCH_1
  1217 000003EE E81BFC                  	call	CheckSwitches
  1218 000003F1 F8                      	clc
  1219 000003F2 C3                      	ret
  1220                                  
  1221                                  WeCanNotIgnoreThisError:
  1222 000003F3 F9                      	stc
  1223 000003F4 C3                      	ret
  1224                                  
  1225                                  LastChanceToSaveIt endp
  1226                                  
  1227                                  ;-------------------------------------------------------------------------------
  1228                                  
  1229                                  
  1230                                  ;*****************************************************************************
  1231                                  ;Routine name WriteBootSector
  1232                                  ;*****************************************************************************
  1233                                  ;
  1234                                  ;DescriptioN: Copy EBPB information to boot record provided by Get recommended
  1235                                  ;	      BPB, write out boot record, error
  1236                                  ;	      if can write it, then fill in new fields (id, etc..). The volume
  1237                                  ;	      label will not be added at this time, but will be set by the
  1238                                  ;	      create volume label call later.
  1239                                  ;
  1240                                  ;Called Procedures: Message (macro)
  1241                                  ;
  1242                                  ;Change History: Created	4/20/87 	MT
  1243                                  ;
  1244                                  ;Input: DeviceParameters.DP_BPB
  1245                                  ;
  1246                                  ;Output: CY clear if ok
  1247                                  ;	 CY set if error writing boot or media_id info
  1248                                  ;
  1249                                  ;Psuedocode
  1250                                  ;----------
  1251                                  ;
  1252                                  ;	Copy recommended EBPB information to canned boot record
  1253                                  ;	Write boot record out (INT 26h)
  1254                                  ;	IF error
  1255                                  ;	   Display boot error message
  1256                                  ;	   stc
  1257                                  ;	ELSE
  1258                                  ;	   Compute serial id and put into field (CALL Create_Serial_ID)
  1259                                  ;	   Point at 'FAT_12' string for file system type
  1260                                  ;	   IF fBIGFat	 ;16 bit FAT
  1261                                  ;	      Point at 'FAT_16' for file system type
  1262                                  ;	   ENDIF
  1263                                  ;	   Copy file system string into media_id field
  1264                                  ;	   Write info to boot (INT 21h AX=440Dh, CX=0843h SET MEDIA_ID)
  1265                                  ;	   IF error (CY set)
  1266                                  ;	      Display boot error message
  1267                                  ;	      stc
  1268                                  ;	   ELSE
  1269                                  ;	      clc
  1270                                  ;	   ENDIF
  1271                                  ;	ENDIF
  1272                                  ;	ret
  1273                                  ;*****************************************************************************
  1274                                  
  1275                                  Procedure WriteBootSector			;				;AN000;
  1276                                  
  1277 000003F5 8D36[0700]              	lea	si, [deviceParameters + DP_BPB]	;Copy EBPB to the boot record	;
  1278 000003F9 8D3E[E602]              	lea	di, [Boot + EXT_BOOT_BPB]		;  "  " 	"  "		;AC000:
  1279 000003FD B91900                  	mov	cx, EXT_BPB_INFO_struc_size		;  "  " 	"  "		;AC000:
  1280 00000400 1E                      	push	ds				;Set ES=DS (data segment)	;     ;
  1281 00000401 07                      	pop	es				;  "  " 	"  "		;     ;
  1282 00000402 F2A4                    	repnz	movsb				;Do the copy			;     ;
  1283                                  						;Write out the boot record	;     ;
  1284 00000404 A0[0000]                	mov	al, [drive]			;Get drive letter		;     ;
  1285 00000407 B90100                  	mov	cx, 1				;Specify 1 sector		;     ;
  1286 0000040A 31D2                    	xor	dx, dx				;Logical sector 0		;     ;
  1287 0000040C 8D1E[DB02]              	lea	bx, [boot]			;Point at boot record		;     ;
  1288                                  ;Boot record in 1st 32mb of partition
  1289 00000410 C706[0200]0000          	mov	word [Read_Write_Relative + Start_Sector_High],0 ;			;AN000;
  1290 00000416 E8(0000)                	call	Write_Disk			;				;AC000;
  1291                                  ;	$IF	C				;Error on write 		;AC000;
  1292 00000419 7309                    	JNC DD_IF62
  1293 0000041B BA[0000]E8(0000)        	   Message msgBootWriteError		;Print error			;     ;
  1294 00000421 F9                      	   stc					;CY=1 means error		;     ;
  1295                                  ;	$ELSE					;Good write of boot record!	;AN000;
  1296 00000422 EB4A                    	JMP SHORT DD_EN62
  1297                                  DD_IF62:
  1298 00000424 8B0E[2C00]              	   mov	   cx,[Dummy_Label_Size]		;Put in dummy volume label size ;ac026;ac028;
  1299 00000428 8D36[2100]              	   lea	   si,[Dummy_Label]		;  "  "       "  "		;AN000;
  1300 0000042C 8D3E[F506]              	   lea	   di,[Media_ID_Buffer + Media_ID_Volume_Label]  ;	"  "	   "  " ;AN000;
  1301 00000430 F3A4                    	   rep	   movsb			;  "  "       "  "		;AN000;
  1302 00000432 E83A00                  	   call    Create_Serial_ID		;Go create unique ID number	;AN000;
  1303 00000435 8D36[DF06]              	   lea	   si,[FAT12_String]		;Assume 12 bit FAT		;AN000;
  1304 00000439 803E[0000]FF            	   cmp	   byte [fBigFAT],TRUE 		;Is it? 			;AN000;
  1304          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  1305                                  ;	   $IF	   E				;Not if fBigFat is set....	;AN000;
  1306 0000043E 7504                    	   JNE DD_IF64
  1307 00000440 8D36[E706]              	      lea     si,[FAT16_String]		;Got 16 bit FAT 		;AN000;
  1308                                  ;	   $ENDIF				;				;AN000;
  1309                                  DD_IF64:
  1310                                  						;Copy file system string	;     ;
  1311 00000444 B90800                  	   mov	   cx,8 			; to buffer			;AN000;
  1312 00000447 8D3E[0007]              	   lea	   di,[Media_ID_Buffer + Media_ID_File_System] ;	 "  "		;AN000;
  1313 0000044B F2A4                    	   repnz   movsb			;    "   "	  "  "		;AN000;
  1314                                  Generic_IOCtl equ GENERIC_IOCTL	; NASM port equate
  1315 0000044D B00D                    	   mov	   al,Generic_IOCtl		;Generic IOCtl call		;AN000;
  1316                                  Drive equ drive	; NASM port label
  1317 0000044F 8A1E[0000]              	   mov	   bl,[Drive]			;Get drive			;AN000;
  1318 00000453 FEC3                    	   inc	   bl				;Make it 1 based		;AN000;
  1319 00000455 30FF                    	   xor	   bh,bh			;Set bh=0			;AN000;
  1320                                  RawIO equ RAWIO	; NASM port equate
  1321 00000457 B508                    	   mov	   ch,RawIO			;Set Media ID call		;AN000;
  1322                                  Set_Media_ID equ SET_MEDIA_ID	; NASM port equate
  1323 00000459 B146                    	   mov	   cl,Set_Media_ID
  1324 0000045B BA[EF06]                	   mov	   dx,offset Media_ID_Buffer	;Point at buffer		;AN000;
  1325 0000045E B444CD21                	   DOS_Call IOCtl			;Do function call		;AN000;
  1326                                  ;	   $IF	   C				;Error ? (Write or old boot rec);AN000;
  1327 00000462 7309                    	   JNC DD_IF66
  1328 00000464 BA[0000]E8(0000)        	      Message msgBootWriteError 	;Indicate we couldn't write it  ;AN000;
  1329 0000046A F9                      	      stc				;CY=1 for error return		;AN000;
  1330                                  ;	   $ELSE				;Set Media ID okay		;AN000;
  1331 0000046B EB01                    	   JMP SHORT DD_EN66
  1332                                  DD_IF66:
  1333 0000046D F8                      	      clc				;CY=0 for good return		;AN000;
  1334                                  ;	   $ENDIF				;				;AN000;
  1335                                  DD_EN66:
  1336                                  ;	$ENDIF					;				;AN000;
  1337                                  DD_EN62:
  1338 0000046E C3                      	ret					;				;AN000;
  1339                                  
  1340                                  WriteBootSector endp				;				;AN000;
  1341                                  
  1342                                  
  1343                                  ;*****************************************************************************
  1344                                  ;Routine name Create_Serial_ID
  1345                                  ;*****************************************************************************
  1346                                  ;
  1347                                  ;DescriptioN&gml Create unique 32 bit serial number by getting current date and
  1348                                  ;	      time and then scrambling it around.
  1349                                  ;
  1350                                  ;Called Procedures: Message (macro)
  1351                                  ;
  1352                                  ;Change History&gml Created	   4/20/87	   MT
  1353                                  ;
  1354                                  ;Input&gml None
  1355                                  ;
  1356                                  ;Output&gml Media_ID_Buffer.Serial_Number = set
  1357                                  ;	    AX,CX,DX destroyed
  1358                                  ;	    Serial_Num_Low/High = Serial number generated
  1359                                  ;
  1360                                  ;Psuedocode
  1361                                  ;----------
  1362                                  ;
  1363                                  ;	Get date (INT 21h, AH=2Bh)
  1364                                  ;	Get time (INT 21h, AH=2Ch)
  1365                                  ;	Serial_ID+0 = DX reg date + DX reg time
  1366                                  ;	Serial_ID+2 = CX reg date + CX reg time
  1367                                  ;	Serial_Num_Low = Serial_ID+2
  1368                                  ;	Serial_Num_High = Serial_ID+0
  1369                                  ;	ret
  1370                                  ;*****************************************************************************
  1371                                  
  1372                                  Procedure Create_Serial_ID			;				;AN000;
  1373                                  
  1374 0000046F B42ACD21                	DOS_Call Get_Date			;Get date from DOS		;AN000;
  1375 00000473 51                      	push	cx				;Save results			;AN000;
  1376 00000474 52                      	push	dx				;				;AN000;
  1377 00000475 B42CCD21                	DOS_Call Get_Time			;Get_Time			;AN000;
  1378 00000479 89D0                    	mov	ax,dx				;Scramble it			;AN000;
  1379 0000047B 5A                      	pop	dx				;				;AN000;
  1380 0000047C 01D0                    	add	ax,dx				;				;AN000;
  1381 0000047E A3[F306]                	mov	word ptr [Media_ID_Buffer + Media_ID_Serial_Number+2],ax ;		;AC004;
  1382 00000481 A3[2E00]                	mov	[Serial_Num_Low],ax		;				;AN000;
  1383 00000484 89C8                    	mov	ax,cx				;				;AN000;
  1384 00000486 59                      	pop	cx				;				;AN000;
  1385 00000487 01C8                    	add	ax,cx				;				;AN000;
  1386 00000489 A3[F106]                	mov	word ptr [Media_ID_Buffer + Media_ID_Serial_Number],ax ;		;AC004;
  1387 0000048C A3[3000]                	mov	[Serial_Num_High],ax		;				;AN000;
  1388 0000048F C3                      	ret					;				;AN000;
  1389                                  
  1390                                  Create_Serial_ID endp				;				;AN000;
  1391                                  
  1392                                  ;-------------------------------------------------------------------------------
  1393                                  
  1394                                  ; OemDone:
  1395                                  ;
  1396                                  OemDone proc	near
  1397                                  
  1398                                  ; if /b write out a fake dos & bios
  1399 00000490 F706[0000]0002          	test	word [switchmap], SWITCH_B
  1400 00000496 7406                    	jz	Switch8?
  1401 00000498 E88200                  	call	WriteBogusDos
  1402 0000049B 7301C3                  	retc
  1403                                  
  1404                                  Switch8?:
  1405 0000049E F706[0000]0001          	test	word [switchmap], SWITCH_8
  1406 000004A4 7405                    	jz	HardDisk?
  1407 000004A6 E8E300                  	call	ConvertToOldDirectoryFormat
  1408 000004A9 72F2                    	retc
  1409                                  
  1410                                  HardDisk?:
  1411 000004AB 803E[0100]05            	cmp	byte [deviceParameters + DP_DeviceType], DEV_HARDDISK
  1412 000004B0 F8                      	clc
  1413 000004B1 75EA                    	retnz
  1414 000004B3 E85901                  	call	SetPartitionTable
  1415                                  
  1416 000004B6 C3                      	return
  1417                                  
  1418                                  OemDone endp
  1419                                  
  1420                                  ;------------------------------------------------------------------------------
  1421                                  
  1422                                  section data
  1423                                  
  1424                                  	%if IBMCOPYRIGHT
  1425                                  biosFilename db "x:\ibmbio.com",0
  1426                                  dosFilename db	"x:\ibmdos.com",0
  1427                                  	%else
  1428 00000708 783A5C696F2E737973-     biosFilename db "x:\io.sys",0
  1428 00000711 00                 
  1429 00000712 783A5C6D73646F732E-     dosFilename db	"x:\msdos.sys",0
  1429 0000071B 73797300           
  1430                                  	%endif
  1431                                  
  1432                                  section code	; data	ends
  1433                                  
  1434                                  ; simple code to stuff bogus dos in old-style diskette.
  1435                                  
  1436                                  BogusDos:
  1437 000004B7 0E                      	push	cs
  1438 000004B8 1F                      	pop	ds
  1439 000004B9 B020                    	mov	al,20h
  1440 000004BB E620                    	out	20h,al				; turn on the timer so the disk motor
  1441 000004BD BE1E00                  	mov	si,mesofs			; shuts off
  1442 000004C0 90                      	nop	; identicalise
  1443                                  sys_mess_loop:
  1444 000004C1 AC                      	lodsb
  1445                                  %if IBMCOPYRIGHT
  1446                                  end_sys_loop:
  1447                                  %endif
  1448 000004C2 08C0                    	or	al,al
  1449 000004C4 7409                    	jz	end_sys_loop
  1450 000004C6 B40E                    	mov	ah,14
  1451 000004C8 BB0700                  	mov	bx,7
  1452 000004CB CD10                    	int	16
  1453 000004CD EBF2                    	jmp	sys_mess_loop
  1454                                  %ifn IBMCOPYRIGHT
  1455                                  end_sys_loop:
  1456 000004CF 30E4                    	xor	ah, ah				; get next char function
  1457 000004D1 CD16                    	int	16h				; call keyboard services
  1458 000004D3 CD19                    	int	19h				; reboot
  1459                                  %endif
  1460                                  
  1461                                  ;=== Push trace listing source: boot.cl1
  1462                                  	%include "boot.cl1" ; NASM included file
     1                              <1> ; boot.cl1 
     2                              <1> 
     3                              <1> 
     4                              <1> ;_______________________
     5                              <1> 
     6 000004D5 0D0A4E6F6E2D537973- <1> SYSMSG DB    13,10,"Non-System disk or disk error",13,10
     6 000004DE 74656D206469736B20- <1>
     6 000004E7 6F72206469736B2065- <1>
     6 000004F0 72726F720D0A        <1>
     7 000004F6 5265706C6163652061- <1> 	DB   	"Replace and press any key when ready",13,10,0
     7 000004FF 6E6420707265737320- <1>
     7 00000508 616E79206B65792077- <1>
     7 00000511 68656E207265616479- <1>
     7 0000051A 0D0A00              <1>
  1463                                  ;=== Pop trace listing source
  1464                                  sysmsg equ SYSMSG	; NASM port label
  1465                                  mesofs	equ	sysmsg - BogusDos
  1466                                  
  1467                                  WriteBogusDos proc near
  1468                                  
  1469 0000051D A0[0000]                	mov	al,[driveLetter]
  1470 00000520 A2[0807]                	mov	[biosFilename],al
  1471 00000523 A2[1207]                	mov	[dosFilename],al
  1472                                  ATTR_HIDDEN equ attr_hidden	; NASM port equate
  1473                                  ATTR_SYSTEM equ attr_system	; NASM port equate
  1474 00000526 B90600                  	mov	cx, ATTR_HIDDEN | ATTR_SYSTEM
  1475 00000529 8D16[0807]              	lea	dx, [biosFilename]
  1476                                  CREAT equ Creat	; NASM port equate
  1477 0000052D B43C                    	mov	ah,CREAT
  1478 0000052F CD21                    	int	21h
  1479 00000531 89C3                    	mov	bx,ax
  1480 00000533 B9B888                  	mov	cx, BIOS_SIZE
  1481 00000536 1E                      	push	ds
  1482 00000537 0E                      	push	cs
  1483 00000538 1F                      	pop	ds
  1484                                  	assume	ds:code
  1485 00000539 8D16[B704]              	lea	dx, [BogusDos]
  1486                                  WRITE equ Write	; NASM port equate
  1487 0000053D B440                    	mov	ah,WRITE
  1488 0000053F CD21                    	int	21h
  1489 00000541 1F                      	pop	ds
  1490                                  	assume	ds:data
  1491                                  CLOSE equ Close	; NASM port equate
  1492 00000542 B43E                    	mov	ah,CLOSE
  1493 00000544 CD21                    	int	21h
  1494 00000546 B90600                  	mov	cx, ATTR_HIDDEN | ATTR_SYSTEM
  1495 00000549 8D16[1207]              	lea	dx, [dosFilename]
  1496 0000054D B43C                    	mov	ah,CREAT
  1497 0000054F CD21                    	int	21h
  1498 00000551 89C3                    	mov	bx,ax
  1499 00000553 B98890                  	mov	cx, DOS_SIZE
  1500 00000556 8D16[B704]              	lea	dx, [BogusDos]
  1501 0000055A B440                    	mov	ah,WRITE
  1502 0000055C CD21                    	int	21h
  1503 0000055E B43E                    	mov	ah,CLOSE
  1504 00000560 CD21                    	int	21h
  1505                                  ; Comunicate system size to the main format program
  1506                                  DOS equ Dos	; NASM port label
  1507                                  FileSizeInBytes equ fileSizeInBytes	; NASM port equate
  1508 00000562 C706[0400]8890          	mov	word [DOS + FileSizeInBytes],DOS_SIZE				;an000; dms;get size of DOS
  1509 00000568 C706[0600]0000          	mov	word [DOS + FileSizeInBytes+2],00h				;an000; dms;
  1510                                  
  1511 0000056E 31D2                    	xor	dx,dx
  1512 00000570 B88890                  	mov	ax,DOS_SIZE
  1513 00000573 E8(0000)                	call	AddToSystemSize
  1514                                  
  1515 00000576 C706[0400]B888          	mov	word [Bios + FileSizeInBytes],BIOS_SIZE 			;an000; dms;get size of BIOS
  1516 0000057C C706[0600]0000          	mov	word [Bios + FileSizeInBytes+2],00h				;an000; dms;
  1517                                  
  1518 00000582 31D2                    	xor	dx,dx
  1519 00000584 B8B888                  	mov	ax,BIOS_SIZE
  1520 00000587 E8(0000)                	call	AddToSystemSize
  1521                                  
  1522 0000058A F8                      	clc
  1523 0000058B C3                      	return
  1524                                  
  1525                                  WriteBogusDos endp
  1526                                  
  1527                                  ;-------------------------------------------------------------------------------
  1528                                  
  1529                                  ConvertToOldDirectoryFormat proc near
  1530                                  
  1531                                  ;
  1532                                  ; convert to 1.1 directory
  1533                                  ;
  1534 0000058C A0[0000]                	mov	al,[drive]			; Get 1st sector of directory
  1535 0000058F B90100                  	mov	cx,1				; 1.1 directory always starts on
  1536 00000592 BA0300                  	mov	dx,3				; sector 3
  1537 00000595 8D1E[DB04]              	lea	bx,[scratchBuffer]
  1538                                  ;Root Directory always in 1st 32mb of partition
  1539 00000599 C706[0200]0000          	mov	word [Read_Write_Relative + Start_Sector_High],0 ;		       ;AN000;
  1540 0000059F E8(0000)                	call	Read_Disk			;				;AC000;
  1541 000005A2 7308                    	jnc	DirectoryRead
  1542 000005A4 BA[0000]E8(0000)        	Message msgDirectoryReadError		;				;AC000;
  1543 000005AA F9                      	stc
  1544 000005AB C3                      	ret
  1545                                  DirectoryRead:
  1546                                  
  1547                                  ; fix attribute of ibmbio and ibmdos
  1548 000005AC 8D1E[DB04]              	lea	bx,[scratchBuffer]
  1549 000005B0 C6470B06                	mov	byte ptr [bx + dir_attr], ATTR_HIDDEN | ATTR_SYSTEM
  1550 000005B4 83C320                  	add	bx, dir_entry_struc_size
  1551 000005B7 C6470B06                	mov	byte ptr [bx + dir_attr], ATTR_HIDDEN | ATTR_SYSTEM
  1552                                  
  1553                                  wrtdir:
  1554 000005BB A0[0000]                	mov	al,[drive]			; write out the directory
  1555 000005BE 98                      	cbw
  1556 000005BF B90100                  	mov	cx,1
  1557 000005C2 BA0300                  	mov	dx,3
  1558 000005C5 8D1E[DB04]              	lea	bx,[scratchBuffer]
  1559                                  ;Root Directory always in 1st 32mb of partition
  1560 000005C9 C706[0200]0000          	mov	word [Read_Write_Relative + Start_Sector_High],0 ;		       ;AN000;
  1561 000005CF E8(0000)                	call	Write_Disk			;				;AC000;
  1562 000005D2 7308                    	jnc	DirectoryWritten
  1563 000005D4 BA[0000]E8(0000)        	Message msgDirectoryWriteError		;				;AC000;
  1564 000005DA F9                      	stc
  1565 000005DB C3                      	ret
  1566                                  DirectoryWritten:
  1567                                  
  1568 000005DC F706[0000]0100          	test	word [switchmap], SWITCH_S		; Was system requested?
  1569 000005E2 75A7                    	retnz					; yes, don't write old boot sector
  1570 000005E4 A0[0000]                	mov	al,[drive]
  1571 000005E7 98                      	cbw
  1572 000005E8 BB[DB00]                	mov	bx,offset boot2 		; no,  write old boot sector
  1573 000005EB 833E[1600]01            	cmp	word [deviceParameters + DP_BPB + BPB_Heads], 1
  1574 000005F0 7405                    	je	bootset8
  1575 000005F2 C747030301              	mov	word ptr [bx+3],0103h		; start address for double sided drives
  1576                                  bootset8:
  1577 000005F7 B90100                  	mov	cx,1
  1578 000005FA 31D2                    	xor	dx,dx
  1579                                  ;Boot record in 1st 32mb of partition
  1580 000005FC C706[0200]0000          	mov	word [Read_Write_Relative + Start_Sector_High],0 ;		       ;AN000;
  1581 00000602 E8(0000)                	call	Write_Disk			;				;AC000;
  1582 00000605 7384                    	retnc
  1583                                  
  1584 00000607 BA[0000]E8(0000)        	Message msgBootWriteError		;				;AC000;
  1585 0000060D F9                      	stc
  1586 0000060E C3                      	ret
  1587                                  
  1588                                  ConvertToOldDirectoryFormat endp
  1589                                  
  1590                                  ;-------------------------------------------------------------------------------
  1591                                  
  1592                                  a_PartitionTableEntry struc
  1593 00000000 ??                      BootInd db	?
  1594 00000001 ??                      BegHead db	?
  1595 00000002 ??                      BegSector db	?
  1596 00000003 ??                      BegCylinder db	?
  1597 00000004 ??                      SysInd	db	?
  1598 00000005 ??                      EndHead db	?
  1599 00000006 ??                      EndSector db	?
  1600 00000007 ??                      EndCylinder db	?
  1601 00000008 ????????                RelSec	dd	?
  1602 0000000C ????????                CSec	dd	?
  1603                                  a_PartitionTableEntry ends
  1604                                  
  1605                                  ; structure of the IBM hard disk boot sector:
  1606                                  IBMBoot STRUC
  1607 00000000 <res 1BEh>              	db	512 - (4*a_PartitionTableEntry_struc_size + 2) dup(?)
  1608 000001BE <res 40h>               PartitionTable db 4*a_PartitionTableEntry_struc_size dup(?)
  1609 000001FE ????                    Signature dw	?
  1610                                  IBMBoot ENDS
  1611                                  
  1612                                  
  1613                                  ;*****************************************************************************
  1614                                  ;Routine name: SetPartitionTable
  1615                                  ;*****************************************************************************
  1616                                  ;
  1617                                  ;Description: Find location for DOS partition in partition table, get the
  1618                                  ;	      correct system indicator byte, and write it out. If can not
  1619                                  ;	      read/write boot record or can't find DOS partition, display
  1620                                  ;	      error
  1621                                  ;
  1622                                  ;Called Procedures: Message (macro)
  1623                                  ;		    Determine_Partition_Type
  1624                                  ;		    ReadSector
  1625                                  ;		    WriteSector
  1626                                  ;
  1627                                  ;Change History: Created	4/20/87 	MT
  1628                                  ;
  1629                                  ;Input: None
  1630                                  ;
  1631                                  ;Output: CY set if error
  1632                                  ;
  1633                                  ;Psuedocode
  1634                                  ;----------
  1635                                  ;
  1636                                  ;	Read the partition table (Call ReadSector)
  1637                                  ;	IF ok
  1638                                  ;	   IF boot signature of 55AAh
  1639                                  ;	       Point at system partition table
  1640                                  ;	       SEARCH
  1641                                  ;		  Assume DOS found
  1642                                  ;		  IF System_Indicator <> 1,AND
  1643                                  ;		  IF System_Indicator <> 4,AND
  1644                                  ;		  IF System_Indicator <> 6
  1645                                  ;		    STC   (DOS not found)
  1646                                  ;		  ELSE
  1647                                  ;		    CLC
  1648                                  ;		  ENDIF
  1649                                  ;	       EXITIF DOS found (CLC)
  1650                                  ;		  CALL Determine_Partition_Type
  1651                                  ;		  Write the partition table (CALL WriteSector)
  1652                                  ;		  IF error
  1653                                  ;		     Display boot write error message
  1654                                  ;		     stc
  1655                                  ;		  ELSE
  1656                                  ;		     clc
  1657                                  ;		  ENDIF
  1658                                  ;	       ORELSE
  1659                                  ;		  Point at next partition entry (add 16 to partition table ptr)
  1660                                  ;	       ENDLOOP if checked all 4 partition entries
  1661                                  ;		  Display Bad partition table message
  1662                                  ;		  stc
  1663                                  ;	       ENDSRCH
  1664                                  ;	   ELSE invalid boot record
  1665                                  ;	      Display Bad partition table message
  1666                                  ;	      stc
  1667                                  ;	   ENDIF
  1668                                  ;	ELSE error
  1669                                  ;	   Display Partition table error
  1670                                  ;	   stc
  1671                                  ;	ENDIF
  1672                                  ;	ret
  1673                                  ;*****************************************************************************
  1674                                  
  1675                                  Procedure SetPartitionTable			;				;AN000;
  1676                                  
  1677 0000060F 31C0                    	xor	ax, ax				;Head				;AC000;
  1678 00000611 31DB                    	xor	bx, bx				;Cylinder			;AC000;
  1679 00000613 31C9                    	xor	cx, cx				;Sector 			;AC000;
  1680 00000615 8D16[DB00]              	lea	dx, [boot2]			;Never use 1.x boot on hardfile,;     ;
  1681 00000619 E8C800                  	call	ReadSector			;this will use space as buffer	;     ;
  1682                                  ;	$IF	NC				;If read okay			;AN000;
  1683 0000061C 7260                    	JC DD_IF70
  1684                                  Boot2 equ boot2	; NASM port label
  1685 0000061E 813E[D902]55AA          	   cmp	   word [Boot2 + Boot_Signature],Boot_ID ;				;AC000;
  1686                                  ;	   $IF	   E				;Does signature match?		;AN000;
  1687 00000624 754F                    	   JNE DD_IF71
  1688 00000626 8D1E[9902]              	      lea     bx, [boot2 + PartitionTable]	;Yes, point at partition table	;AN000;
  1689                                  ;	      $SEARCH				;Look for DOS partition 	;AN000;
  1690                                  DD_DO72:
  1691                                  sysind equ SysInd	; NASM port equate
  1692 0000062A 807F0401                		 cmp	 byte [bx + sysind],FAT12_File_System ;			;AC000;
  1693                                  ;		 $IF	 NE,AND 		;				;AN000;
  1694 0000062E 740F                    		 JE DD_IF73
  1695 00000630 807F0404                		 cmp	 byte [bx + sysind],FAT16_File_System ;		     ;AC000;
  1696                                  ;		 $IF	 NE,AND 		;				;AN000;
  1697 00000634 7409                    		 JE DD_IF73
  1698 00000636 807F0406                		 cmp	 byte [bx + sysind],New_File_System ;			  ;AC000;
  1699                                  ;		 $IF	 NE			;				;AN000;
  1700 0000063A 7403                    		 JE DD_IF73
  1701 0000063C F9                      		    stc 			;We didn't find partition       ;AN000;
  1702                                  ;		 $ELSE				;				;AN000;
  1703 0000063D EB01                    		 JMP SHORT DD_EN73
  1704                                  DD_IF73:
  1705 0000063F F8                      		    clc 			;Indicate found partition	;AN000;
  1706                                  ;		 $ENDIF 			;				;AN000;
  1707                                  DD_EN73:
  1708                                  ;	      $EXITIF NC			;Get correct id for it		;AN000;
  1709 00000640 7221                    	      JC DD_IF72
  1710 00000642 E84100                  		 CALL	 Determine_Partition_Type ;				;AN000;
  1711 00000645 B80000                  		 mov	 ax, 0			;Head				;     ;
  1712 00000648 BB0000                  		 mov	 bx, 0			;Cylinder			;     ;
  1713 0000064B B90000                  		 mov	 cx, 0			;Sector 			;     ;
  1714 0000064E 8D16[DB00]              		 lea	 dx, [boot2]		;				;     ;
  1715 00000652 E89A00                  		 call	 WriteSector		;Write out partition table	;     ;
  1716                                  ;		 $IF	 C			;Error writing boot record	;AN000;
  1717 00000655 7309                    		 JNC DD_IF77
  1718 00000657 BA[0000]E8(0000)        		    MESSAGE msgPartitionTableWriteError ;			;AC000;
  1719 0000065D F9                      		    stc 			;Set CY to indicate error	;     ;
  1720                                  ;		 $ELSE				;				;AN000;
  1721 0000065E EB01                    		 JMP SHORT DD_EN77
  1722                                  DD_IF77:
  1723 00000660 F8                      		    clc 			;No error means no CY		;     ;
  1724                                  ;		 $ENDIF 			;				;AN000;
  1725                                  DD_EN77:
  1726                                  ;	      $ORELSE				;				;AN000;
  1727 00000661 EB10                    	      JMP SHORT DD_SR72
  1728                                  DD_IF72:
  1729 00000663 83C310                  		 add	 bx,a_PartitionTableEntry_struc_size ;			;     ;
  1730 00000666 81FB[D902]              		 cmp	 bx,(offset Boot2 + PartitionTable)+4*a_PartitionTableEntry_struc_size ;     ;
  1731                                  ;	      $ENDLOOP				;Checked all 4 partition entries;AN000;
  1732 0000066A EBBE                    	      JMP SHORT DD_DO72
  1733 0000066C BA[0000]E8(0000)        		 MESSAGE msgBadPartitionTable	;Tell user bad table		;AC000;
  1734 00000672 F9                      		 stc				;Set CY for exit		;     ;
  1735                                  ;	      $ENDSRCH				;				;AN000;
  1736                                  DD_SR72:
  1737                                  ;	   $ELSE				;Invalid boot record		;AN000;
  1738 00000673 EB07                    	   JMP SHORT DD_EN71
  1739                                  DD_IF71:
  1740 00000675 BA[0000]E8(0000)        	      MESSAGE msgBadPartitionTable	;				;AC000;
  1741 0000067B F9                      	      stc				;Set CY for error return	;     ;
  1742                                  ;	   $ENDIF				;				;AN000;
  1743                                  DD_EN71:
  1744                                  ;	$ELSE					;Couldn't read boot record      ;AN000;
  1745 0000067C EB07                    	JMP SHORT DD_EN70
  1746                                  DD_IF70:
  1747 0000067E BA[0000]E8(0000)        	   MESSAGE msgPartitionTableReadError	;				;AC000;
  1748 00000684 F9                      	   stc					;Set CY for error return	;     ;
  1749                                  ;	$ENDIF					;				;AN000;
  1750                                  DD_EN70:
  1751 00000685 C3                      	ret					;				;     ;
  1752                                  
  1753                                  SetPartitionTable endp				;				;AN000;
  1754                                  
  1755                                  ;*****************************************************************************
  1756                                  ;Routine name: Determine_Partition_Type
  1757                                  ;*****************************************************************************
  1758                                  ;
  1759                                  ;DescriptioN: Set the system indicator field to its correct value as
  1760                                  ;	      determined by the following rules:
  1761                                  ;
  1762                                  ;	     - Set SysInd = 01h if partition or logical drive size is < 10mb
  1763                                  ;	       and completely contained within the first 32mb of DASD.
  1764                                  ;	     - Set SysInd = 04h if partition or logical drive size is >10mb,
  1765                                  ;	       <32mb, and completely contained within the first 32mb of DASD
  1766                                  ;	     - Set SysInd to 06h if partition or logical drive size is > 32mb,
  1767                                  ;
  1768                                  ;Called Procedures: Message (macro)
  1769                                  ;
  1770                                  ;Change History: Created	3/18/87 	MT
  1771                                  ;
  1772                                  ;Input: BX has offset of partition table entry
  1773                                  ;	fBigFAT = TRUE if 16bit FAT
  1774                                  ;
  1775                                  ;Output: BX.SysInd = correct partition system indicator value (1,4,6)
  1776                                  ;
  1777                                  ;Psuedocode
  1778                                  ;----------
  1779                                  ;	Add partition start location to length of partition
  1780                                  ;	IF end > 32mb
  1781                                  ;	   BX.SysInd = 6
  1782                                  ;	ELSE
  1783                                  ;	   IF fBigFat
  1784                                  ;	      BX.SysInd = 4
  1785                                  ;	   ELSE
  1786                                  ;	      BX.SysInd = 1
  1787                                  ;	   ENDIF
  1788                                  ;	ret
  1789                                  ;*****************************************************************************
  1790                                  
  1791                                  Procedure Determine_Partition_Type						;AN000;
  1792                                  
  1793                                  Csec equ CSec	; NASM port equate
  1794 00000686 8B570E                  	mov	dx,word ptr [bx + Csec + 2] 					;an000; dms;Get high word of sector count
  1795 00000689 83FA00                  	cmp	dx,0								;AN000;    ;> 32Mb?
  1796                                  ;	$IF	NE								;AN000;    ;yes
  1797 0000068C 7406                    	JE DD_IF87
  1798 0000068E C6470406                		mov	byte [BX + SysInd],New_File_System				;AN000;    ;type 6
  1799                                  ;	$ELSE									;AN000;
  1800 00000692 EB2C                    	JMP SHORT DD_EN87
  1801                                  DD_IF87:
  1802 00000694 E82A00                  		call	Calc_Total_Sectors_For_Partition			;an000; dms;returns DX:AX total sectors
  1803                                  BPB_HiddenSectors equ BPB_HIDDENSECTORS	; NASM port equate
  1804 00000697 833E[1A00]00            		cmp	word [DeviceParameters + DP_BPB + BPB_HiddenSectors + +2],0 	;an000; dms;> 32Mb?
  1805                                  ;		$if	ne							;an000; dms;yes
  1806 0000069C 7406                    		JE DD_IF89
  1807 0000069E C6470406                			mov	byte [bx + SysInd],New_File_System			;an000; dms; type 6
  1808                                  ;		$else								;an000; dms;
  1809 000006A2 EB1C                    		JMP SHORT DD_EN89
  1810                                  DD_IF89:
  1811 000006A4 83FA00                  			cmp	dx,0						;an000; dms; partition > 32 Mb?
  1812                                  ;			$if	ne						;an000; dms; yes
  1813 000006A7 7406                    			JE DD_IF91
  1814 000006A9 C6470406                				mov  byte [bx + SysInd],New_File_System		;an000; dms; type 6
  1815                                  ;			$else							;an000; dms; < 32 Mb partition
  1816 000006AD EB11                    			JMP SHORT DD_EN91
  1817                                  DD_IF91:
  1818                                  fBigFat equ fBigFAT	; NASM port label
  1819                                  True equ TRUE	; NASM port equate
  1820 000006AF 803E[0000]FF            				cmp	byte [fBigFat],True				;an000;    ;16 bit FAT
  1820          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  1821                                  ;				$IF	E					;AC000;    ;yes
  1822 000006B4 7506                    				JNE DD_IF93
  1823 000006B6 C6470404                					mov	byte [BX + SysInd],FAT16_File_System	;an000;    ;type 4
  1824                                  ;				$ELSE						;an000;    ;12 bit FAT
  1825 000006BA EB04                    				JMP SHORT DD_EN93
  1826                                  DD_IF93:
  1827 000006BC C6470401                					mov	byte [bx + SysInd],FAT12_File_System	;an000;    ;type 1
  1828                                  ;				$ENDIF						;AN000;
  1829                                  DD_EN93:
  1830                                  ;			$ENDIF							;an000;
  1831                                  DD_EN91:
  1832                                  ;		$ENDIF								;an000;
  1833                                  DD_EN89:
  1834                                  ;	$endif									;an000;
  1835                                  DD_EN87:
  1836 000006C0 C3                      	ret									;an000;
  1837                                  
  1838                                  Determine_Partition_Type endp			;				;AN000;
  1839                                  
  1840                                  
  1841                                  ;=========================================================================
  1842                                  ; Calc_Total_Sectors_For_Partition	: This routine determines the
  1843                                  ;					  total number of sectors within
  1844                                  ;					  this partition.
  1845                                  ;
  1846                                  ;	Inputs	: DeviceParameters
  1847                                  ;
  1848                                  ;	Outputs : DX:AX - Double word partition size
  1849                                  ;=========================================================================
  1850                                  
  1851                                  Procedure Calc_Total_Sectors_For_Partition					;an000; dms;
  1852                                  
  1853 000006C1 A1[1800]                	mov	ax,word ptr [DeviceParameters + DP_BPB + BPB_HiddenSectors + +0]	;an000; dms; low word
  1854 000006C4 8B16[1A00]              	mov	dx,word ptr [DeviceParameters + DP_BPB + BPB_HiddenSectors + +2]	;an000; dms; high word
  1855 000006C8 833E[0F00]00            	cmp	word [DeviceParameters + DP_BPB + BPB_TotalSectors],0			;an000; dms; extended BPB?
  1856                                  ;	$if	e								;an000; dms; yes
  1857 000006CD 750D                    	JNE DD_IF99
  1858 000006CF 0306[1C00]              		add	ax,word ptr [DeviceParameters + DP_BPB + BPB_BigTotalSectors + +0]   ;an000; dms; add in low word
  1859 000006D3 83D200                  		adc	dx,0							;an000; dms; pick up carry if any
  1860 000006D6 0316[1E00]              		add	dx,word ptr [DeviceParameters + DP_BPB + BPB_BigTotalSectors + +2]   ;an000; dms; add in high word
  1861                                  ;	$else									;an000; dms; standard BPB
  1862 000006DA EB07                    	JMP SHORT DD_EN99
  1863                                  DD_IF99:
  1864 000006DC 0306[0F00]              		add	ax,word ptr [DeviceParameters + DP_BPB + BPB_TotalSectors]	;an000; dms; add in total sector count
  1865 000006E0 83D200                  		adc	dx,0							;an000; dms; pick up carry if any
  1866                                  ;	$endif									;an000; dms;
  1867                                  DD_EN99:
  1868                                  
  1869 000006E3 C3                      	ret
  1870                                  
  1871                                  Calc_Total_Sectors_For_Partition	endp
  1872                                  
  1873                                  
  1874                                  ;-------------------------------------------------------------------------------
  1875                                  ; ReadSector:
  1876                                  ;    Read one sector
  1877                                  ;
  1878                                  ;    Input:
  1879                                  ;	ax - head
  1880                                  ;	bx - cylinder
  1881                                  ;	cx - sector
  1882                                  ;	dx - transfer address
  1883                                  
  1884                                  ReadSector proc near
  1885                                  
  1886                                  TrackReadWritePacket equ trackReadWritePacket	; NASM port label
  1887                                  TRWP_FirstSector equ TRWP_FIRSTSECTOR	; NASM port equate
  1888 000006E4 890E[3800]              	mov	[TrackReadWritePacket + TRWP_FirstSector], cx
  1889 000006E8 B96108                  	mov	cx,(RAWIO << 8) | READ_TRACK
  1890 000006EB E80C00                  	call	SectorIO
  1891 000006EE C3                      	return
  1892                                  
  1893                                  ReadSector endp
  1894                                  
  1895                                  ;-------------------------------------------------------------------------------
  1896                                  ; WriteSector:
  1897                                  ;    Write one sector
  1898                                  ;
  1899                                  ;    Input:
  1900                                  ;	ax - head
  1901                                  ;	bx - cylinder
  1902                                  ;	cx - sector
  1903                                  ;	dx - transfer address
  1904                                  
  1905                                  WriteSector proc near
  1906                                  
  1907 000006EF 890E[3800]              	mov	[TrackReadWritePacket + TRWP_FirstSector], cx
  1908 000006F3 B94108                  	mov	cx,(RAWIO << 8) | WRITE_TRACK
  1909 000006F6 E80100                  	call	SectorIO
  1910 000006F9 C3                      	return
  1911                                  
  1912                                  WriteSector endp
  1913                                  
  1914                                  ;-------------------------------------------------------------------------------
  1915                                  ; SectorIO:
  1916                                  ;    Read/Write one sector
  1917                                  ;
  1918                                  ;    Input:
  1919                                  ;	ax - head
  1920                                  ;	bx - cylinder
  1921                                  ;	cx - (RAWIO shl 8) or READ_TRACK
  1922                                  ;	   - (RAWIO shl 8) or WRITE_TRACK
  1923                                  ;	dx - transfer address
  1924                                  
  1925                                  SectorIO proc	near
  1926                                  
  1927                                  TRWP_Head equ TRWP_HEAD	; NASM port equate
  1928 000006FA A3[3400]                	mov	[TrackReadWritePacket + TRWP_Head], ax
  1929                                  TRWP_Cylinder equ TRWP_CYLINDER	; NASM port equate
  1930 000006FD 891E[3600]              	mov	[TrackReadWritePacket + TRWP_Cylinder], bx
  1931                                  TRWP_TransferAddress equ TRWP_TRANSFERADDRESS	; NASM port equate
  1932 00000701 8916[3C00]              	mov	WORD PTR [TrackReadWritePacket + TRWP_TransferAddress], dx
  1933 00000705 8C1E[3E00]              	mov	WORD PTR [TrackReadWritePacket + TRWP_TransferAddress + 2], ds
  1934                                  TRWP_SectorsToReadWrite equ TRWP_SECTORSTOREADWRITE	; NASM port equate
  1935 00000709 C706[3A00]0100          	mov	word [TrackReadWritePacket + TRWP_SectorsToReadWrite], 1
  1936                                  
  1937 0000070F 8A1E[0000]              	mov	bl, [drive]
  1938 00000713 FEC3                    	inc	bl
  1939 00000715 B80D44                  	mov	ax, (IOCTL << 8) | GENERIC_IOCTL
  1940 00000718 8D16[3300]              	lea	dx, [trackReadWritePacket]
  1941 0000071C CD21                    	int	21H
  1942 0000071E C3                      	return
  1943                                  
  1944                                  SectorIO endp
  1945                                  
  1946                                  ;-------------------------------------------------------------------------------
  1947                                  
  1948                                  section data
  1949                                  
  1950 0000071F ??                      oldDrive db	?
  1951                                  
  1952 00000720 FF                      FCBforVolumeIdSearch db 0ffH
  1953 00000721 0000000000              	db	5 dup(0)
  1954 00000726 08                      	db	08H
  1955 00000727 00                      	db	0
  1956 00000728 3F3F3F3F3F3F3F3F3F-     	db	"???????????"
  1956 00000731 3F3F               
  1957 00000733 000000000000000000-     	db	40 DUP(0)
  1957 0000073C 000000000000000000-
  1957 00000745 000000000000000000-
  1957 0000074E 000000000000000000-
  1957 00000757 00000000           
  1958                                  
  1959                                  section code	; data	ends
  1960                                  
  1961                                  GetVolumeId proc near
  1962                                  ; Input:
  1963                                  ;    dl = drive
  1964                                  ;    di = name buffer
  1965                                  
  1966                                  ; Save current drive
  1967 0000071F B419                    	mov	ah,19H
  1968 00000721 CD21                    	int	21H
  1969 00000723 A2[1F07]                	mov	[oldDrive], al
  1970                                  
  1971                                  ; Change current drive to the drive that has the volume id we want
  1972 00000726 B40E                    	mov	ah, 0eH
  1973 00000728 CD21                    	int	21H
  1974                                  
  1975                                  ; Search for the volume id
  1976 0000072A B411                    	mov	ah, 11H
  1977 0000072C 8D16[2007]              	lea	dx, [FCBforVolumeIdSearch]
  1978 00000730 CD21                    	int	21H
  1979 00000732 50                      	push	ax
  1980                                  
  1981                                  ; Restore current drive
  1982 00000733 B40E                    	mov	ah, 0eH
  1983 00000735 8A16[1F07]              	mov	dl,[oldDrive]
  1984 00000739 CD21                    	int	21H
  1985                                  
  1986                                  ; Did the search succeed?
  1987 0000073B 58                      	pop	ax
  1988 0000073C 08C0                    	or	al,al
  1989 0000073E 7402                    	jz	CopyVolumeId
  1990 00000740 F9                      	stc
  1991 00000741 C3                      	ret
  1992                                  
  1993                                  CopyVolumeId:
  1994                                  ; Find out where the FCB for the located volume id was put
  1995 00000742 B42F                    	mov	ah,2fH
  1996 00000744 CD21                    	int	21H
  1997                                  
  1998                                  ; Copy the Volume Id
  1999 00000746 89DE                    	mov	si, bx
  2000 00000748 83C608                  	add	si, 8
  2001 0000074B 06                      	push	es
  2002 0000074C 1E                      	push	ds
  2003 0000074D 07                      	pop	es
  2004 0000074E 1F                      	pop	ds
  2005 0000074F B90B00                  	mov	cx, 11
  2006 00000752 F3A4                    	rep	movsb
  2007 00000754 06                      	push	es
  2008 00000755 1F                      	pop	ds
  2009                                  
  2010 00000756 F8                      	clc
  2011 00000757 C3                      	ret
  2012                                  
  2013                                  GetVolumeId endp
  2014                                  
  2015                                  section data
  2016 0000075B 000000000000000000-     oldVolumeId db	11 dup(0)
  2016 00000764 0000               
  2017                                  section code	; data	ends
  2018                                  
  2019                                  CheckVolumeId proc near
  2020                                  
  2021                                  ; Get the volume id that's on the disk
  2022 00000758 8D3E[5B07]              	lea	di, [oldVolumeId]
  2023 0000075C 8A16[0000]              	mov	dl, [drive]
  2024 00000760 E8BCFF                  	call	GetVolumeId
  2025 00000763 7302                    	jnc	Ask_User			;Did we find one?
  2026 00000765 F8                      	clc					;No, return with no error
  2027 00000766 C3                      	ret
  2028                                  
  2029                                  ; Ask the user to enter the volume id that he/she thinks is on the disk
  2030                                  ; (first blank out the input buffer)
  2031                                  Ask_User:
  2032                                  
  2033 00000767 BA[0000]E8(0000)        	Message msgWhatIsVolumeId?		;				;AC000;
  2034                                  						;lea	 dx, ptr_msgWhatIsVolumeId?
  2035                                  						;call	 std_printf
  2036 0000076D E8(0000)                	call	user_string
  2037 00000770 E8(0000)                	call	crlf
  2038                                  
  2039                                  ; If the user just pressed ENTER, then there must be no label
  2040 00000773 803E[0100]00            	cmp	byte [inbuff+1], 0
  2041 00000778 7508                    	jne	CompareVolumeIds
  2042 0000077A 803E[5B07]00            	cmp	byte [oldVolumeId], 0
  2043 0000077F 7534                    	jne	BadVolumeId
  2044 00000781 C3                      	ret
  2045                                  
  2046                                  CompareVolumeIds:
  2047                                  ; pad the reponse with blanks
  2048                                  ; The buffer is big enough so just add 11 blanks to what the user typed in
  2049 00000782 1E                      	push	ds
  2050 00000783 07                      	pop	es
  2051 00000784 B90B00                  	mov	cx, Label_Length		;AC000;
  2052 00000787 31DB                    	xor	bx,bx
  2053 00000789 8A1E[0100]              	mov	bl, [inbuff + 1]
  2054 0000078D 8D3E[0200]              	lea	di, [inbuff + 2]
  2055 00000791 01DF                    	add	di, bx
  2056 00000793 B020                    	mov	al, ' '
  2057 00000795 F3AA                    	rep	stosb
  2058                                  ; Make the reply all uppercase
  2059                                  Inbuff equ inbuff	; NASM port label
  2060                                  ASCIIZ_End equ Asciiz_End	; NASM port equate
  2061 00000797 C606[0D00]00            	mov	byte [Inbuff+2+Label_Length],ASCIIZ_End ;Make string ASCIIZ	 ;AN000;
  2062 0000079C BA[0200]                	mov	dx, offset inbuff + 2		;Start of buffer		;AC000;
  2063 0000079F B022                    	mov	al,22h				;Capitalize asciiz		;AC000;
  2064 000007A1 B465CD21                	DOS_Call GetExtCntry			;Do it				;AC000;
  2065                                  
  2066                                  ; Now compare what the user specified with what is really out there
  2067 000007A5 B90B00                  	mov	cx, Label_Length		;				;AC000;
  2068 000007A8 8D36[0200]              	lea	si, [inbuff + 2]
  2069 000007AC 8D3E[5B07]              	lea	di, [oldVolumeId]
  2070 000007B0 F3A6                    	repe	cmpsb
  2071 000007B2 7501                    	jne	BadVolumeId
  2072 000007B4 C3                      	ret
  2073                                  
  2074                                  BadVolumeId:
  2075                                  msgBadVolumeID equ msgBadVolumeId	; NASM port label
  2076 000007B5 BA[0000]E8(0000)        	Message msgBadVolumeID			;				;AC000;
  2077 000007BB F9                      	stc
  2078 000007BC C3                      	ret
  2079                                  
  2080                                  CheckVolumeId endp
  2081                                  
  2082                                  
  2083                                  Check_Switch_8_B	proc	near
  2084                                  
  2085 000007BD F706[0000]0002          	   test    word [SwitchMap], SWITCH_B		;/8/B <> /V because		;AC007;
  2086                                  ;	   $IF	   NZ,AND			; old directory type		;AC007;
  2087 000007C3 741D                    	   JZ DD_IF102
  2088 000007C5 F706[0000]0001          	   test    word [SwitchMap], Switch_8		; used which didn't support     ;AC007;
  2089                                  ;	   $IF	   NZ,AND			; volume labels.		;AC007;
  2090 000007CB 7415                    	   JZ DD_IF102
  2091 000007CD F706[0000]0200          	   test    word [SwitchMap], SWITCH_V		;				;AC007;
  2092                                  ;	   $IF	   NZ				;				;AC007;
  2093 000007D3 740D                    	   JZ DD_IF102
  2094 000007D5 BA[0000]E8(0000)        	      Message msgIncompatibleParameters ;Tell user			;AC007;
  2095 000007DB C606[0000]FF            	      mov     byte [Fatal_Error],Yes		;Bad stuff			;AC007;
  2096                                  ;	   $ELSE				;No problem so far		;AC007;
  2097 000007E0 EB65                    	   JMP SHORT DD_EN102
  2098                                  DD_IF102:
  2099 000007E2 F706[0000]0002          	      test    word [SwitchMap], Switch_B	;Can't reserve space and        ;AC007;
  2100                                  ;	      $IF     NZ,AND			; install sys files at the	;AC007;
  2101 000007E8 7415                    	      JZ DD_IF104
  2102 000007EA F706[0000]0100          	      test    word [SwitchMap], Switch_S	; same time.			;AC007;
  2103                                  ;	      $IF     NZ			; No /S/B			;AC007;
  2104 000007F0 740D                    	      JZ DD_IF104
  2105 000007F2 BA[0000]E8(0000)        		 Message msgIncompatibleParameters ;Tell user			;AC007;
  2106 000007F8 C606[0000]FF            		 mov	 byte [Fatal_Error],Yes	;Bad stuff			;AC007;
  2107                                  ;	       $ELSE				 ;Still okay			 ;AC007;
  2108 000007FD EB48                    	       JMP SHORT DD_EN104
  2109                                  DD_IF104:
  2110 000007FF F706[0000]4000          		  test	  word [SwitchMap],Switch_1	 ;/1/8/4 not okay with /N/T	 ;AC007;
  2111                                  ;		  $IF	  NZ,OR 		 ;				 ;AC007;
  2112 00000805 7510                    		  JNZ DD_LL106
  2113 00000807 F706[0000]0001          		  test	  word [SwitchMap],Switch_8	 ;				 ;AC007;
  2114                                  ;		  $IF	  NZ,OR 		 ;				 ;AC007;
  2115 0000080D 7508                    		  JNZ DD_LL106
  2116 0000080F F706[0000]8000          		  test	  word [SwitchMap],Switch_4	 ;				 ;AC007;
  2117                                  ;		  $IF	  NZ			 ;				 ;AC007;
  2118 00000815 7430                    		  JZ DD_IF106
  2119                                  DD_LL106:
  2120 00000817 F706[0000]3000          		     test    word [SwitchMap],(Switch_T | Switch_N) ; 		 ;AC007;
  2121                                  ;		     $IF     NZ 		 ;Found /T/N <> /1/8		 ;AC007;
  2122 0000081D 740D                    		     JZ DD_IF107
  2123 0000081F BA[0000]E8(0000)        			Message msgIncompatibleParameters ;Tell user		 ;AC007;
  2124 00000825 C606[0000]FF            			mov	byte [Fatal_Error],Yes  ;Bad stuff			 ;AC007;
  2125                                  ;		     $ELSE			 ;				 ;ac007;
  2126 0000082A EB1B                    		     JMP SHORT DD_EN107
  2127                                  DD_IF107:
  2128 0000082C F706[0000]0200          			test	word [SwitchMap],Switch_V				 ;ac007;
  2129                                  ;			$IF	NZ,AND						 ;ac007;
  2130 00000832 7413                    			JZ DD_IF109
  2131 00000834 F706[0000]0001          			test	word [SwitchMap],Switch_8				 ;ac007;
  2132                                  ;			$IF	NZ						 ;ac007;
  2133 0000083A 740B                    			JZ DD_IF109
  2134 0000083C BA[0000]E8(0000)        				Message msgIncompatibleParameters		 ;ac007;
  2135 00000842 C606[0000]FF            				mov	byte [Fatal_Error],Yes 			 ;ac007;
  2136                                  ;			$ENDIF							 ;ac007;
  2137                                  DD_IF109:
  2138                                  ;		     $ENDIF			 ;				 ;AC007;
  2139                                  DD_EN107:
  2140                                  ;		  $ENDIF			 ;				 ;AC007;
  2141                                  DD_IF106:
  2142                                  ;	       $ENDIF				 ;				 ;AC007;
  2143                                  DD_EN104:
  2144                                  ;	    $ENDIF				 ;				 ;AC007;
  2145                                  DD_EN102:
  2146 00000847 C3                      	    ret
  2147                                  
  2148                                  Check_Switch_8_B	endp
  2149                                  
  2150                                  
  2151                                  ; (no prior section) ; code	ends
  2152                                  	end
  2153                                  
