     1                                  ;page   84,132
     2                                  ;	SCCSID = @(#)format.asm 1.26 85/10/20
     3                                  ;	SCCSID = @(#)format.asm 1.26 85/10/20
     4                                  ;***************************************************************
     5                                  ;
     6                                  ;	86-DOS FORMAT DISK UTILITY
     7                                  ;
     8                                  ;	This routine formats a new disk,clears the FAT and DIRECTORY then
     9                                  ;	optionally copies the SYSTEM and COMMAND.COM to this new disk
    10                                  ;
    11                                  ;	SYNTAX: FORMAT	[drive + /switch1 + /switch2]...[/switch16]
    12                                  ;
    13                                  ;	Regardless of the drive designator , the user will be prompted to
    14                                  ;	insert the diskette to be formatted.
    15                                  ;
    16                                  ;***************************************************************
    17                                  
    18                                  ;	    5/12/82 ARR Mod to ask for volume ID
    19                                  ;	    5/19/82 ARR Fixed rounding bug in CLUSCAL:
    20                                  ;   REV 1.5
    21                                  ;	    Added rev number message
    22                                  ;	    Added dir attribute to DELALL FCB
    23                                  ;   REV 2.00
    24                                  ;	    Redone for 2.0
    25                                  ;   REV 2.10
    26                                  ;	    5/1/83 ARR Re-do to transfer system on small memory systems
    27                                  ;   REV 2.20
    28                                  ;	    6/17/83 system size re-initialization bug -- mjb001
    29                                  ;   Rev 2.25
    30                                  ;	    8/31/83 16-bit fat insertion
    31                                  ;   Rev 2.26
    32                                  ;	    11/2/83 MZ fix signed compare problems for bad sectors
    33                                  ;   Rev 2.27
    34                                  ;	    11/8/83 EE current directories are always saved and restored
    35                                  ;   Rev 2.28
    36                                  ;	    11/9/83 NP Printf and changed to an .EXE file
    37                                  ;   Rev 2.29
    38                                  ;	    11/11/83 ARR Fixed ASSIGN detection to use NameTrans call to see
    39                                  ;			if drive letter remapped. No longer IBM only
    40                                  ;   Rev 2.30
    41                                  ;	    11/13/83 ARR SS does NOT = CS, so all use of BP needs CS override
    42                                  ;   Rev 2.31
    43                                  ;	    12/27/83 ARR REP STOSB instruction at Clean: changed to be
    44                                  ;			sure ES = CS.
    45                                  
    46                                  
    47                                  
    48                                  
    49                                  section code public align=16 class=CODE
    50                                  ; (no prior section) ; code	ends
    51                                  
    52                                  
    53                                  
    54                                  section data public align=16 class=DATA
    55                                  ; (no prior section) ; data	ends
    56                                  
    57                                  section End_Of_Memory public align=16 class=BUFFERS
    58                                  ; (no prior section) ; End_Of_Memory ends
    59                                  
    60                                  
    61                                  section code
    62                                  
    63                                  	assume	cs:code,ds:nothing,es:nothing
    64                                  
    65                                  ;-------------------------------------------------------------------------------
    66                                  ; Define as public for debugging
    67                                  
    68                                  ; procedures
    69                                  	public	GetSize
    70                                  	public	AddToSystemSize
    71                                  	public	Phase1Initialisation
    72                                  	public	SetStartSector
    73                                  	public	SetfBigFat
    74                                  	public	Phase2Initialisation
    75                                  	public	DiskFormat
    76                                  	public	BadSector
    77                                  	public	DisplayCurrentTrack
    78                                  	public	WriteFileSystem
    79                                  	public	Done
    80                                  	public	CurrentLogicalSector
    81                                  	public	PrintErrorAbort
    82                                  	public	GetDeviceParameters
    83                                  	public	SetDeviceParameters
    84                                  	public	Multiply_32_Bits
    85                                  
    86                                  	public	START
    87                                  	public	FatAllocated
    88                                  	public	MEMERRJ
    89                                  	public	MEM_OK
    90                                  	public	RDFRST
    91                                  	public	NEEDSYS
    92                                  	public	INITCALL
    93                                  	public	SWITCHCHK
    94                                  	public	SYSLOOP
    95                                  	public	FRMTPROB
    96                                  	public	GETTRK
    97                                  	public	TRKFND
    98                                  	public	CLRTEST
    99                                  	public	CMPTRKS
   100                                  	public	BadClus
   101                                  ;	public	DoBig
   102                                  ;	public	DoSet
   103                                  	public	DRTFAT
   104                                  	public	CLEARED
   105                                  	public	LOUSE
   106                                  	public	LOUSEP
   107                                  	public	FATWRT
   108                                  	public	SYSOK
   109                                  	public	STATUS
   110                                  	public	REPORTC
   111                                  	public	ONCLUS
   112                                  	public	MORE
   113                                  	public	FEXIT
   114                                  	public	SYSPRM
   115                                  	public	fexitJ
   116                                  	public	DoPrompt
   117                                  	public	TARGPRM
   118                                  	public	IsRemovable
   119                                  	public	CheckRemove
   120                                  	public	IsRemove
   121                                  	public	NotRemove
   122                                  	public	DSKPRM
   123                                  	public	GOPRNIT
   124                                  	public	crlf
   125                                  	public	PrintString
   126                                  	public	std_printf
   127                                  	public	READDOS
   128                                  	public	RDFILS
   129                                  	public	FILESDONE
   130                                  	public	CLSALL
   131                                  	public	GOTBIOS
   132                                  	public	GOTDOS
   133                                  	public	CLSALLJ
   134                                  	public	GOTCOM
   135                                  	public	WRITEDOS
   136                                  	public	GOTALLBIO
   137                                  	public	BIOSDONE
   138                                  	public	GOTNDOS
   139                                  	public	PARTDOS
   140                                  	public	GOTALLDOS
   141                                  	public	DOSDONE
   142                                  	public	PARTCOM
   143                                  	public	GOTALLCOM
   144                                  	public	COMDONE
   145                                  	public	MAKEFIL
   146                                  	public	CheckMany
   147                                  	public	CLOSETARG
   148                                  	public	IOLOOP
   149                                  	public	GOTTARG
   150                                  	public	GSYS
   151                                  	public	TESTSYS
   152                                  	public	GETOFFS
   153                                  ;	public	TESTSYSDISK		; dcl 8/23/86
   154                                  	public	SETBIOS
   155                                  	public	BIOSCLS
   156                                  	public	SETBIOSSIZ
   157                                  	public	DOSOPNOK
   158                                  	public	DOSCLS
   159                                  	public	SETDOSSIZ
   160                                  	public	GotComHand
   161                                  	public	COMCLS
   162                                  	public	SETCOMSIZ
   163                                  	public	GETFSIZ
   164                                  	public	READFILE
   165                                  	public	WRITEFILE
   166                                  	public	FILIO
   167                                  	public	NORMIO
   168                                  	public	IORETP
   169                                  	public	IORET
   170                                  	public	NORMALIZE
   171                                  	public	GotDeviceParameters
   172                                  	public	LoadSectorTable
   173                                  	public	NotBigTotalSectors
   174                                  	public	NotBig
   175                                  	public	FormatLoop
   176                                  	public	FormatDone
   177                                  	public	ContinueFormat
   178                                  	public	ReportBadTrack
   179                                  	public	NoMoreTracks
   180                                  	public	WriteDIRloop
   181                                  	public	Main_Routine
   182                                  	public	ControlC_Handler
   183                                  
   184                                  ; bytes
   185                                  	public	fBigFat
   186                                  	public	formatError
   187                                  	public	ROOTSTR
   188                                  	public	DBLFLG
   189                                  DRIVE equ drive	; NASM port label
   190                                  	public	DRIVE
   191                                  	public	FILSTAT
   192                                  	public	USERDIRS
   193                                  	public	VOLFCB
   194                                  	public	VOLNAM
   195                                  	public	TRANSRC
   196                                  	public	TRANDST
   197                                  	public	INBUFF
   198                                  	public	driveLetter
   199                                  	public	systemDriveLetter
   200                                  	public	CommandFile
   201                                  	public	ExitStatus
   202                                  VolDrive equ VOLDRIVE	; NASM port label
   203                                  	public	VolDrive
   204                                  	public	DelFCB
   205                                  DelDrive equ DelDRIVE	; NASM port label
   206                                  	public	DelDrive
   207                                  
   208                                  ; words
   209                                  	public	startSector
   210                                  	public	fatSpace
   211                                  	public	firstHead
   212                                  	public	firstCylinder
   213                                  	public	tracksLeft
   214                                  	public	tracksPerDisk
   215                                  	public	sectorsInRootDirectory
   216                                  	public	directorySector
   217                                  	public	printStringPointer
   218                                  	public	MSTART
   219                                  	public	MSIZE
   220                                  	public	TempHandle
   221                                  	public	BEGSEG
   222                                  	public	SWITCHMAP
   223                                  	public	SWITCHCOPY
   224                                  	public	FAT
   225                                  	public	CLUSSIZ
   226                                  	public	SECSIZ
   227                                  	public	SYSTRKS
   228                                  	public	SECTORS
   229                                  	public	currentHead
   230                                  	public	currentCylinder
   231                                  	public	PercentComplete
   232                                  	public	Formatted_Tracks_High
   233                                  	public	Formatted_Tracks_Low
   234                                  
   235                                  ; other
   236                                  	public	deviceParameters
   237                                  	public	Disk_Access
   238                                  	public	formatPacket
   239                                  ;-------------------------------------------------------------------------------
   240                                  
   241                                  section data
   242                                  	extrn	msgAssignedDrive:byte
   243                                  	extrn	msgBadDosVersion:byte
   244                                  	extrn	msgDirectoryWriteError:byte
   245                                  	extrn	msgFormatComplete:byte
   246                                  	extrn	msgFormatNotSupported:byte
   247                                  	extrn	msgFATwriteError:byte
   248                                  	extrn	msgInvalidDeviceParameters:byte
   249                                  	extrn	msgLabelPrompt:byte
   250                                  	extrn	msgNeedDrive:byte
   251                                  	extrn	msgNoSystemFiles:byte
   252                                  	extrn	msgNetDrive:byte
   253                                  	extrn	msgInsertDisk:byte
   254                                  	extrn	msgHardDiskWarning:byte
   255                                  	extrn	msgSystemTransfered:byte
   256                                  	extrn	msgFormatAnother?:byte
   257                                  	extrn	msgBadCharacters:byte
   258                                  	extrn	msgBadDrive:byte
   259                                  	extrn	msgInvalidParameter:byte
   260                                  	extrn	msgParametersNotSupported:byte
   261                                  	extrn	msgReInsertDisk:byte
   262                                  	extrn	msgInsertDosDisk:byte
   263                                  	extrn	msgFormatFailure:byte
   264                                  	extrn	ContinueMsg:Byte
   265                                  	extrn	msgNotSystemDisk:byte
   266                                  	extrn	msgDiskUnusable:byte
   267                                  	extrn	msgOutOfMemory:byte
   268                                  	extrn	msgCurrentTrack:byte
   269                                  	extrn	msgWriteProtected:byte
   270                                  	extrn	msgInterrupt:byte
   271                                  	extrn	msgCRLF:byte
   272                                  	extrn	Fatal_Error:Byte
   273                                  	extrn	Read_Write_Relative:Byte
   274                                  	extrn	PSP_Segment:Word
   275                                  	extrn	Parse_Error_Msg:Byte
   276                                  	extrn	Extended_Error_Msg:Byte
   277                                  	extrn	MsgVerify:Byte
   278                                  
   279                                  section code	; data	ends
   280                                  
   281                                  
   282                                  debug	equ	0
   283                                  	[list -]
   283          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
   283          ******************       warning: out: BPB.INC... [-w+user]
   283          ******************       warning: out: IOCTL.INC... [-w+user]
   283          ******************       warning: out: BPB.INC... [-w+user]
   283          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
   300                                  
   301                                  
   302                                  ;-------------------------------------------------------------------------------
   303                                  ; And this is the actual data
   304                                  
   305                                  section data
   306                                  	public	deviceParameters
   307                                  	public	bios
   308                                  	public	dos
   309                                  	public	command
   310                                  	public	FAT_Flag
   311                                  
   312 00000000 00                      validSavedDeviceParameters db 0
   313                                  savedDeviceParameters: ; NASM structure instance
   314                                  A_DEVICEPARAMETERS_size equ A_DEVICEPARAMETERS_struc_size	; NASM port equate
   315                                  istruc A_DEVICEPARAMETERS
   316 00000001 ??<rep 124h>            iend
   317                                  deviceParameters: ; NASM structure instance
   318                                  istruc A_DEVICEPARAMETERS
   319 00000125 ??<rep 124h>            iend
   320                                  
   321                                  Disk_Access: ; NASM structure instance
   322                                  A_DISKACCESS_CONTROL_size equ A_DISKACCESS_CONTROL_struc_size	; NASM port equate
   323                                  istruc A_DISKACCESS_CONTROL
   324 00000249 ??<rep 2h>              iend
   325                                  
   326                                  formatPacket: ; NASM structure instance
   327                                  A_FORMATPACKET_size equ A_FORMATPACKET_struc_size	; NASM port equate
   328                                  istruc A_FORMATPACKET
   329 0000024B ??<rep 5h>0100          at FP_TRACKCOUNT, dw 1
   330                                  iend
   331                                  RWPacket: ; NASM structure instance
   332                                  A_TRACKREADWRITEPACKET_size equ A_TRACKREADWRITEPACKET_struc_size	; NASM port equate
   333                                  istruc A_TRACKREADWRITEPACKET
   334 00000252 ??<rep Dh>              iend
   335 0000025F 000000000000000000-     RW_TRF_Area	db    512     dup(0)
   335 00000268 000000000000000000-
   335 00000271 000000000000000000-
   335 0000027A 000000000000000000-
   335 00000283 000000000000000000-
   335 0000028C 000000000000000000-
   335 00000295 000000000000000000-
   335 0000029E 000000000000000000-
   335 000002A7 000000000000000000-
   335 000002B0 000000000000000000-
   335 000002B9 000000000000000000-
   335 000002C2 000000000000000000-
   335 000002CB 000000000000000000-
   335 000002D4 000000000000000000-
   335 000002DD 000000000000000000-
   335 000002E6 000000000000000000-
   335 000002EF 000000000000000000-
   335 000002F8 000000000000000000-
   335 00000301 000000000000000000-
   335 0000030A 000000000000000000-
   335 00000313 000000000000000000-
   335 0000031C 000000000000000000-
   335 00000325 000000000000000000-
   335 0000032E 000000000000000000-
   335 00000337 000000000000000000-
   335 00000340 000000000000000000-
   335 00000349 000000000000000000-
   335 00000352 000000000000000000-
   335 0000035B 000000000000000000-
   335 00000364 000000000000000000-
   335 0000036D 000000000000000000-
   335 00000376 000000000000000000-
   335 0000037F 000000000000000000-
   335 00000388 000000000000000000-
   335 00000391 000000000000000000-
   335 0000039A 000000000000000000-
   335 000003A3 000000000000000000-
   335 000003AC 000000000000000000-
   335 000003B5 000000000000000000-
   335 000003BE 000000000000000000-
   335 000003C7 000000000000000000-
   335 000003D0 000000000000000000-
   335 000003D9 000000000000000000-
   335 000003E2 000000000000000000-
   335 000003EB 000000000000000000-
   335 000003F4 000000000000000000-
   335 000003FD 000000000000000000-
   335 00000406 000000000000000000-
   335 0000040F 000000000000000000-
   335 00000418 000000000000000000-
   335 00000421 000000000000000000-
   335 0000042A 000000000000000000-
   335 00000433 000000000000000000-
   335 0000043C 000000000000000000-
   335 00000445 000000000000000000-
   335 0000044E 000000000000000000-
   335 00000457 0000000000000000   
   336                                  
   337 0000045F ????                    startSector dw	?
   338 00000461 ????????                fatSpace dd	?
   339 00000465 00                      fBigFat db	FALSE
   340                                  
   341 00000466 ????                    firstHead dw	?
   342 00000468 ????                    firstCylinder dw ?
   343 0000046A ????                    tracksLeft dw	?
   344 0000046C ????                    tracksPerDisk dw ?
   345                                  
   346 0000046E 0000                    Formatted_Tracks_Low dw 0
   347 00000470 0000                    Formatted_Tracks_High dw 0
   348                                  
   349                                  
   350                                  public	NumSectors ,TrackCnt
   351 00000472 FFFF                    NumSectors dw	0FFFFh
   352 00000474 FFFF                    TrackCnt dw	0FFFFh
   353 00000476 FFFF                    PercentComplete dw 0FFFFh			;Init non-zero so msg will display first time
   354                                  
   355                                  public	Old_Dir
   356 00000478 00                      Old_Dir db	FALSE
   357                                  
   358                                  public	fLastChance
   359 00000479 00                      fLastChance db	FALSE				; Flags reinvocation from
   360                                  						;   LastChanceToSaveIt. Used by DSKPRM
   361                                  
   362 0000047A ????                    sectorsInRootDirectory dw ?
   363                                  
   364 0000047C 00000000                directorySector dd 0
   365                                  
   366 00000480 00                      formatError db	0
   367                                  
   368 00000481 0000                    printStringPointer dw 0
   369                                  
   370                                  ; Exit status defines
   371 00000483 00                      ExitStatus		db	0
   372                                  ExitOK			equ	0
   373                                  ExitCtrlC		equ	3
   374                                  ExitFatal		equ	4
   375                                  ExitNo			equ	5
   376                                  ExitDriveNotReady	equ	6						;an017; dms;drive not ready error
   377                                  ExitWriteProtect	equ	7						;an017; dms;write protect error
   378                                  
   379 00000484 ??                      ROOTSTR DB	?
   380 00000485 3A5C00                  	DB	":\",0
   381 00000488 00                      DBLFLG	DB	0				;Initialize flags to zero
   382 00000489 ????????                IOCNT	DD	?
   383 0000048D ????                    MSTART	DW	?				; Start of sys file buffer (para#)
   384 0000048F ????                    MSIZE	DW	?				; Size of above in paragraphs
   385 00000491 ????                    TempHandle DW	?
   386 00000493 ??                      FILSTAT DB	?				; In memory status of files
   387                                  						; XXXXXX00B BIOS not in
   388                                  						; XXXXXX01B BIOS partly in
   389                                  						; XXXXXX10B BIOS all in
   390                                  						; XXXX00XXB DOS not in
   391                                  						; XXXX01XXB DOS partly in
   392                                  						; XXXX10XXB DOS all in
   393                                  						; XX00XXXXB COMMAND not in
   394                                  						; XX01XXXXB COMMAND partly in
   395                                  						; XX10XXXXB COMMAND all in
   396                                  
   397 00000494 <res 46h>               USERDIRS DB	DIRSTRLEN+3 DUP(?)		; Storage for users current directory
   398                                  
   399 000004DA 0000                    Paras_Per_Fat	dw	0000h			;an000;holds fat para count
   400 000004DC 0000                    Fat_Init_Value	dw	0000h			;an000;initializes the FAT
   401                                  
   402                                  bios: ; NASM structure instance
   403                                  a_FileStructure_size equ a_FileStructure_struc_size	; NASM port equate
   404                                  istruc a_FileStructure
   405 000004DE ??<rep 12h>             iend
   406                                  BiosAttributes EQU attr_hidden + attr_system + attr_read_only
   407                                  
   408                                  dos: ; NASM structure instance
   409                                  istruc a_FileStructure
   410 000004F0 ??<rep 12h>             iend
   411                                  DosAttributes EQU attr_hidden + attr_system + attr_read_only
   412                                  
   413                                  command: ; NASM structure instance
   414                                  istruc a_FileStructure
   415 00000502 ??<rep 12h>             iend
   416                                  CommandAttributes EQU 0
   417 00000514 583A5C434F4D4D414E-     CommandFile DB	"X:\COMMAND.COM",0
   417 0000051D 442E434F4D00       
   418 00000523 000000000000000000-     CommandFile_Buffer	DB	127	dup(0)	;an000;allow room for copy
   418 0000052C 000000000000000000-
   418 00000535 000000000000000000-
   418 0000053E 000000000000000000-
   418 00000547 000000000000000000-
   418 00000550 000000000000000000-
   418 00000559 000000000000000000-
   418 00000562 000000000000000000-
   418 0000056B 000000000000000000-
   418 00000574 000000000000000000-
   418 0000057D 000000000000000000-
   418 00000586 000000000000000000-
   418 0000058F 000000000000000000-
   418 00000598 000000000000000000-
   418 000005A1 00                 
   419                                  
   420 000005A2 434F4D4D414E442E43-     Command_Com		DB	"COMMAND.COM",0
   420 000005AB 4F4D00             
   421                                  
   422 000005AE FF000000000008          VOLFCB	DB	-1,0,0,0,0,0,8
   423 000005B5 00                      VOLDRIVE DB	0
   424 000005B6 202020202020202020-     VOLNAM	DB	"           "
   424 000005BF 2020               
   425 000005C1 08                      	DB	8
   426 000005C2 <res 1Ah>               	DB	26 DUP(?)
   427                                  
   428 000005DC FF000000000008          DelFCB	DB	-1,0,0,0,0,0,8
   429 000005E3 00                      DelDRIVE DB	0
   430 000005E4 3F3F3F3F3F3F3F3F3F-     DelNAM	DB	"???????????"
   430 000005ED 3F3F               
   431 000005EF 08                      	DB	8
   432 000005F0 <res 1Ah>               	DB	26 DUP(?)
   433                                  
   434 0000060A 413A434F4E0000          TRANSRC DB	"A:CON",0,0			; Device so we don't hit the drive
   435 00000611 413A5C000000000000-     TRANDST DB	"A:\",0,0,0,0,0,0,0,0,0,0
   435 0000061A 00000000           
   436                                  
   437 0000061E ????                    BEGSEG	DW	?
   438 00000620 ????                    SWITCHMAP DW	?
   439 00000622 ????                    SWITCHCOPY DW	?
   440 00000624 ????                    FAT	DW	?
   441 00000626 ????                    	DW	?
   442 00000628 ????                    CLUSSIZ DW	?
   443 0000062A ????                    SECSIZ	DW	?
   444 0000062C ????                    SYSTRKS DW	?
   445 0000062E ????                    SECTORS DW	?
   446 00000630 5000                    INBUFF	DB	80,0
   447 00000632 <res 50h>               	DB	80 DUP(?)
   448                                  
   449                                  
   450 00000682 00                      drive	db	0
   451 00000683 78                      driveLetter db	"x"
   452 00000684 78                      systemDriveLetter db "x"
   453                                  
   454 00000685 ????????                CTRL_BREAK_VECTOR	dd	?		;ac010; dms;Holds CTRL-Break
   455                                  						;	    vector
   456                                  
   457 00000689 ????????                Command_Path	dd	?			;an011; dms;hold pointer to
   458                                  						;	    COMMAND's path
   459                                  
   460 0000068D 434F4D535045433D00      Comspec_ID	db	"COMSPEC=",00		;an011; dms;Comspec target
   461                                  
   462                                  
   463 00000696 ????                    Environ_Segment dw	?			;an011; dms;hold segment of
   464                                  						;	    environ. vector
   465                                  ;======== Disk Table ========== 		;an012; dms;
   466                                  ;Used if NumberOfFATs in BPB
   467                                  ;is 0.
   468                                  
   469 00000698 0000A87F0308000200-     DiskTable	dw	0,	32680,	0803h,	512,	0
   469 000006A1 00                 
   470 000006A2 0400000002040002FF-     		dw	4h,	0000h,	0402h,	512,	Fbig
   470 000006AB 00                 
   471 000006AC 0800000003080002FF-     		dw	8h,	0000h,	0803h,	512,	Fbig
   471 000006B5 00                 
   472 000006B6 1000000004100002FF-     		dw	10h,	0000h,	1004h,	512,	Fbig
   472 000006BF 00                 
   473 000006C0 2000000005200002FF-     		dw	20h,	0000h,	2005h,	512,	Fbig
   473 000006C9 00                 
   474                                  
   475                                  public		Org_AX				;an000; dms;make it known
   476 000006CA ????                    Org_AX		dw	?			;an000; dms;AX on entry
   477                                  
   478 000006CC ????                    Cluster_Boundary_Adj_Factor	dw	?	;an000; dms;
   479 000006CE ????                    Cluster_Boundary_SPT_Count	dw	?	;an000; dms;
   480                                  False equ FALSE	; NASM port equate
   481 000006D0 00                      Cluster_Boundary_Flag		db	False	;an000; dms;
   482 000006D1 ????                    Cluster_Boundary_Buffer_Seg	dw	?	;an000; dms;
   483                                  
   484 000006D3 ????                    Relative_Sector_Low		dw	?	;an000; dms;
   485 000006D5 ????                    Relative_Sector_High		dw	?	;an000; dms;
   486                                  
   487 000006D7 ??                      FAT_Flag			db	?	;an000; dms;
   488 000006D8 ????                    Tracks_To_Format		dw	?	;an015; dms;
   489 000006DA ????                    Track_Count			dw	?	;an015; dms;
   490 000006DC 00                      Format_End			db	FALSE	;an015; dms;
   491                                  
   492                                  public Msg_Allocation_Unit_Val
   493                                  
   494 000006DD ????????                Msg_Allocation_Unit_Val 	dd	?	;an019; dms;
   495                                  
   496                                  
   497                                  section code	; data	ends
   498                                  
   499                                  ;For FORPROC and FORMES modules
   500                                  
   501                                  secsiz equ SECSIZ	; NASM port label
   502                                  clussiz equ CLUSSIZ	; NASM port label
   503                                  inbuff equ INBUFF	; NASM port label
   504                                  
   505                                  	PUBLIC	crlf,std_printf
   506                                  
   507                                  switchmap equ SWITCHMAP	; NASM port label
   508                                  	public	driveLetter,fatSpace
   509                                  	public	fBigFat, PrintString,currentHead,currentCylinder
   510                                  	extrn	CheckSwitches:near,LastChanceToSaveIt:near
   511                                  	extrn	Volid:near
   512                                  	extrn	WriteBootSector:near,OemDone:near
   513                                  	extrn	AccessDisk:near
   514                                  	extrn	Main_Init:near
   515                                  	extrn	Read_Disk:near
   516                                  	extrn	Write_Disk:near
   517                                  
   518                                  section data
   519                                  	extrn	BiosFile:byte,DosFile:byte
   520                                  section code	; data	ends
   521                                  
   522                                  ;For FORPROC module
   523                                  
   524                                  	EXTRN	FormatAnother?:near,Yes?:near,REPORT:NEAR,USER_STRING:NEAR
   525                                  section data
   526                                  	extrn	syssiz:dword,biosiz:dword
   527                                  section code	; data	ends
   528                                  
   529                                  DOSVER_LOW EQU	0300H+20
   530                                  DOSVER_HIGH EQU 0300H+20
   531                                  
   532                                  RECLEN	EQU	fcb_RECSIZ+7
   533                                  RR	EQU	fcb_RR+7
   534                                  
   535                                  PSP_Environ	equ	2ch			;an011; dms;location of
   536                                  						;	    environ. segment
   537                                  						;	    in PSP
   538                                  
   539                                  Fbig	equ	0ffh				;an000; dms;flag for big FAT
   540                                  
   541                                  ..start:
   542                                  START:
   543 00000000 31DB                    	xor	bx,bx				;				;AN000;
   544 00000002 53                      	push	bx				;				;AN000;
   545 00000003 50B8[ssss]8ED81E07-     	Set_Data_Segment			;				;AC000;
   545 0000000B 58                 
   546 0000000C A3[CA06]                	mov	[Org_AX],ax			;an000; dms;save ax on entry
   547 0000000F E9(0000)                	jmp	Main_Init			;				;AC000;
   548                                  
   549                                  
   550                                  Main_Routine:					;				;AN000;
   551                                  ; Set memory requirements
   552 00000012 8B1E[0000]              	mov	bx,[PSP_Segment]			;Shrink to free space for FAT	;AC000;
   553 00000016 8EC3                    	mov	es,bx				;				;AC000;
   554 00000018 BB[ssss]                	mov	bx,End_Of_Memory		;				;AC000;
   555 0000001B 2B1E[0000]              	sub	bx,[PSP_Segment]			;				;AC000;
   556 0000001F B44ACD21                	DOS_Call Setblock			;				;AC000;
   557                                  
   558 00000023 E8E011                  	call	Get_Disk_Access 						;an014; dms;
   559                                  DAC_Access_Flag equ DAC_ACCESS_FLAG	; NASM port equate
   560 00000026 803E[4A02]FF            	cmp	byte [Disk_Access + DAC_Access_Flag],0ffh				;an014; dms;is access already allowed?
   561                                  ;	$if	ne								;an014; dms;no, don't change status
   562 0000002B 740C                    	JE DD_IF1
   563 0000002D 8D16[4902]              		lea	dx,[Disk_Access]						;an014; dms;point to parm block
   564 00000031 C606[4A02]01            		mov	byte [Disk_Access + DAC_Access_Flag],01h 			;an014; dms;signal disk access
   565 00000036 E8A711                  		call	Set_Disk_Access_On_Off					;an014;dms;allow disk access
   566                                  ;	$endif									;an014; dms;
   567                                  DD_IF1:
   568                                  
   569 00000039 E86109                  	CALL	Phase1Initialisation
   570 0000003C 7317                    	jnc	FatAllocated
   571                                  
   572 0000003E BA[0000]E8(0000)        	Message msgFormatFailure		;				;AC000;
   573                                  Fexit equ FEXIT	; NASM port label
   574 00000044 E9E402                  	jmp	Fexit
   575                                  
   576                                  MEMERR:
   577 00000047 B8[ssss]                	mov	ax, data
   578 0000004A 8ED8                    	mov	ds, ax
   579 0000004C BA[0000]E8(0000)        	Message msgOutOfMemory			;				;AC000;
   580                                  						;call	 PrintString
   581 00000052 E9D602                  	JMP	FEXIT
   582                                  
   583                                  FatAllocated:
   584                                  
   585 00000055 F706[2006]0100          	TEST	word [SWITCHMAP],SWITCH_S
   586 0000005B 7436                    	JZ	INITCALL
   587 0000005D BBFFFF                  	MOV	BX,0FFFFH
   588                                  ALLOC equ Alloc	; NASM port equate
   589 00000060 B448                    	MOV	AH,ALLOC
   590 00000062 CD21                    	INT	21H
   591 00000064 09DB                    	OR	BX,BX
   592 00000066 740A                    	JZ	MEMERRJ 			;No memory
   593 00000068 891E[8F04]              	MOV	[MSIZE],BX
   594 0000006C B448                    	MOV	AH,ALLOC
   595 0000006E CD21                    	INT	21H
   596 00000070 7302                    	JNC	MEM_OK
   597                                  MEMERRJ:
   598 00000072 EBD3                    	JMP	MEMERR				;No memory
   599                                  
   600                                  MEM_OK:
   601 00000074 A3[8D04]                	MOV	[MSTART],AX
   602                                  
   603                                  RDFRST:
   604 00000077 C706[E004]0000          	mov	word [bios + fileSizeInParagraphs],0	;mjb001 initialize file size
   605 0000007D C706[F204]0000          	mov	word [dos + fileSizeInParagraphs],0	;mjb001 ...
   606 00000083 C706[0405]0000          	mov	word [command + fileSizeInParagraphs],0	;mjb001 ...
   607 00000089 E8B903                  	CALL	READDOS 			;Read BIOS and DOS
   608 0000008C 7305                    	JNC	INITCALL			;OK -- read next file
   609                                  NEEDSYS:
   610 0000008E E8C702                  	CALL	SYSPRM				;Prompt for system disk
   611 00000091 EBE4                    	JMP	RDFRST				;Try again
   612                                  
   613                                  INITCALL:
   614 00000093 E80C0A                  	CALL	Phase2Initialisation
   615                                  
   616                                  SWITCHCHK:
   617 00000096 8B16[2006]              	MOV	DX,[SWITCHMAP]
   618 0000009A 8916[2206]              	MOV	[SWITCHCOPY],DX
   619                                  
   620                                  SYSLOOP:
   621                                  	;Must intialize for each iteration
   622                                  
   623                                  SYSSIZ equ syssiz	; NASM port label
   624 0000009E C706[0000]0000          	MOV	WORD [SYSSIZ],0
   625 000000A4 C706[0200]0000          	MOV	WORD [SYSSIZ+2],0
   626 000000AA C606[8804]00            	MOV	BYTE [DBLFLG],0
   627 000000AF C606[8304]00            	mov	byte [ExitStatus], ExitOK
   628 000000B4 8B16[2206]              	MOV	DX,[SWITCHCOPY]
   629 000000B8 8916[2006]              	MOV	[SWITCHMAP],DX			;Restore original Switches
   630                                  ; DiskFormat will handle call for new disk
   631                                  DISKFORMAT equ DiskFormat	; NASM port label
   632 000000BC E86B0A                  	CALL	DISKFORMAT			;Format the disk
   633 000000BF 7318                    	JNC	GETTRK
   634                                  FRMTPROB:
   635                                  
   636                                  SwitchMap equ SWITCHMAP	; NASM port label
   637                                  Switch_Select equ SWITCH_SELECT	; NASM port equate
   638 000000C1 F706[2006]0004          	test	word [SwitchMap],Switch_Select 					;an017; dms;SELECT option?
   639                                  ;	$if	z								;an017; dms;no - display message
   640 000000C7 750B                    	JNZ DD_IF3
   641 000000C9 BA[0000]E8(0000)        		Message msgFormatFailure		;			;AC000;
   642 000000CF C606[8304]04            		mov	byte [ExitStatus], ExitFatal					;an017; dms;
   643                                  ;	$endif									;an017; dms;
   644                                  DD_IF3:
   645 000000D4 E82602                  	CALL	MORE				;See if more disks to format
   646 000000D7 EBC5                    	JMP	SHORT SYSLOOP
   647                                  
   648                                  ;Mark any bad sectors in the FATs
   649                                  ;And keep track of how many bytes there are in bad sectors
   650                                  
   651                                  GETTRK:
   652                                  BADSECTOR equ BadSector	; NASM port label
   653 000000D9 E8530B                  	CALL	BADSECTOR			;Do bad track fix-up
   654 000000DC 72E3                    	JC	FRMTPROB			;Had an error in Formatting - can't recover
   655 000000DE 83F800                  	CMP	AX,0				;Are we finished?
   656 000000E1 7503                    	JNZ	TRKFND				;No - check error conditions
   657 000000E3 E91101                  	JMP	DRTFAT				;Yes
   658                                  TRKFND:
   659 000000E6 8B1E[D506]              	mov	bx,word ptr [Relative_Sector_High] ;get the high word of the sector ;an000; dms;
   660 000000EA 09DB                    	OR	BX,BX
   661 000000EC 7512                    	JNZ	CLRTEST
   662 000000EE 8B1E[D306]              	mov	bx,word ptr [Relative_Sector_Low] ;get the high word of the sector ;an000; dms;
   663                                  STARTSECTOR equ startSector	; NASM port label
   664 000000F2 3B1E[5F04]              	CMP	BX,[STARTSECTOR]			;Are any sectors in the system area bad?
   665 000000F6 7308                    	JAE	CLRTEST				; MZ 2.26 unsigned compare
   666 000000F8 BA[0000]E8(0000)        	Message msgDiskUnusable 		;				;AC000;
   667 000000FE EBC1                    	JMP	FRMTPROB			;Bad disk -- try again
   668                                  CLRTEST:
   669 00000100 A3[2E06]                	MOV	[SECTORS],AX			;Save the number of sectors on the track
   670 00000103 F706[2006]0100          	TEST	word [SWITCHMAP],SWITCH_S		;If system requested calculate size
   671 00000109 7462                    	JZ	BAD100
   672 0000010B 803E[8804]00            	CMP	BYTE [DBLFLG],0		;Have we already calculated System space?
   673 00000110 752D                    	JNZ	CMPTRKS 			;Yes -- all ready for the compare
   674 00000112 FE06[8804]              	INC	BYTE [DBLFLG] 		;No -- set the flag
   675                                  GETBIOSIZE equ GetBioSize	; NASM port label
   676 00000116 E89501                  	CALL	GETBIOSIZE			; Get the size of the BIOS
   677 00000119 8B16[0200]              	MOV	DX,WORD PTR [SYSSIZ+2]
   678 0000011D A1[0000]                	MOV	AX,WORD PTR [SYSSIZ]
   679                                  BIOSIZ equ biosiz	; NASM port label
   680 00000120 8916[0200]              	MOV	WORD PTR [BIOSIZ+2],DX
   681 00000124 A3[0000]                	MOV	WORD PTR [BIOSIZ],AX
   682                                  GETDOSSIZE equ GetDosSize	; NASM port label
   683 00000127 E88F01                  	CALL	GETDOSSIZE
   684                                  GETCMDSIZE equ GetCmdSize	; NASM port label
   685 0000012A E89701                  	CALL	GETCMDSIZE
   686 0000012D 8B16[0200]              	MOV	DX,WORD PTR [BIOSIZ+2]
   687 00000131 A1[0000]                	MOV	AX,WORD PTR [BIOSIZ]
   688                                  BPB_BytesPerSector equ BPB_BYTESPERSECTOR	; NASM port equate
   689 00000134 F736[2C01]              	DIV	word [deviceParameters + DP_BPB + BPB_BytesPerSector]
   690 00000138 0306[5F04]              	ADD	AX,[STARTSECTOR]
   691 0000013C A3[2C06]                	MOV	[SYSTRKS],AX			;Space FAT,Dir,and system files require
   692                                  CMPTRKS:
   693 0000013F 8B1E[D506]              	mov	bx,word ptr [Relative_Sector_High] ;get the high word of the sector ;an000; dms;
   694 00000143 09DB                    	OR	BX,BX
   695 00000145 7526                    	JNZ	BAD100
   696 00000147 8B1E[D306]              	mov	bx,word ptr [Relative_Sector_Low] ;get the low word of the sector ;an000; dms;
   697 0000014B 3B1E[2C06]              	CMP	BX,[SYSTRKS]
   698 0000014F 771C                    	JA	BAD100				; MZ 2.26 unsigned compare
   699 00000151 C606[8304]04            	mov	byte [ExitStatus], ExitFatal
   700 00000156 BA[0000]E8(0000)        	Message msgNotSystemDisk		;				;AC000;
   701 0000015C 8326[2006]FE            	AND	word [SWITCHMAP],~ SWITCH_S		;Turn off system transfer switch
   702 00000161 C706[0200]0000          	MOV	WORD [SYSSIZ+2],0		;No system to transfer
   703 00000167 C706[0000]0000          	MOV	WORD [SYSSIZ],0		;No system to transfer
   704                                  BAD100:
   705                                  
   706                                  DP_DeviceType equ DP_DEVICETYPE	; NASM port equate
   707 0000016D 803E[2601]05            	CMP	byte [deviceParameters + DP_DeviceType], DEV_HARDDISK			;an000; dms;hard disk?
   708                                  ;	$if	e								;an000; dms; yes
   709 00000172 7505                    	JNE DD_IF5
   710 00000174 E8700F                  		call	Get_Bad_Sector_Hard					;an000; dms;see if a sector is bad
   711                                  ;	$else									;an000; dms;floppy disk
   712 00000177 EB03                    	JMP SHORT DD_EN5
   713                                  DD_IF5:
   714 00000179 E80F10                  		call	Get_Bad_Sector_Floppy					;an000; dms;mark entire track bad
   715                                  ;	$endif									;an000; dms;
   716                                  DD_EN5:
   717                                  
   718 0000017C E95AFF                  	JMP	GETTRK
   719                                  
   720                                  ;   Inputs:	BX = Cluster number
   721                                  ;   Outputs:	The given cluster is marked as invalid
   722                                  ;		Zero flag is set if the cluster was already marked bad
   723                                  ;   Registers modified: DX,SI
   724                                  ;   No other registers affected
   725                                  
   726                                  ;=========================================================================
   727                                  ; BADCLUS	:	Marks off a bad cluster in the FAT
   728                                  ;			If a cluster has already been marked bad it
   729                                  ;			will return with ZR.
   730                                  ;
   731                                  ;	Inputs	:	DX:AX - Cluster Number
   732                                  ;
   733                                  ;	Outputs :	Cluster is marked invalid
   734                                  ;			ZR set if cluster already marked bad
   735                                  ;=========================================================================
   736                                  
   737                                  BadClus 	proc		near		;an000; mark bad clusters
   738                                  
   739 0000017F 57                      	push	di				;an000; save affected regs
   740 00000180 50                      	push	ax
   741 00000181 53                      	push	bx
   742 00000182 51                      	push	cx
   743 00000183 52                      	push	dx
   744 00000184 06                      	push	es
   745                                  
   746 00000185 8E06[6304]              	mov	es, word ptr [fatSpace + 2]	;an005; obtain seg of FAT
   747 00000189 803E[6504]FF            	CMP	byte [fBigFat],TRUE			;an005; 16 bit fat?
   747          ******************       warning: byte data exceeds bounds [-w+number-overflow]
   748                                  ;	$if	ne				;an005; no - 12-bit fat
   749 0000018E 7438                    	JE DD_IF8
   750 00000190 50                      		push	ax			;an000; save ax - contains low cluster number
   751 00000191 89D6                    		mov	si,dx			;an000; pick up high word of cluster
   752 00000193 89C7                    		mov	di,ax			;an000; pick up low word of cluster
   753 00000195 B90200                  		mov	cx,2			;an000; divide by 2
   754 00000198 E8440D                  		call	Divide_32_Bits		;an000; 32 bit divide
   755                                  
   756 0000019B 01F8                    		add	ax,di			;an000; add in low word of result
   757 0000019D 11F2                    		adc	dx,si			;an000; pick up low word carry
   758                                  						;cluster = cluster * 1.5
   759                                  fatspace equ fatSpace	; NASM port label
   760 0000019F 0306[6104]              		add	ax,word ptr [fatspace]	;an005; add 0
   761 000001A3 83D200                  		adc	dx,0			;an000; pick up carry
   762                                  
   763 000001A6 89D3                    		mov	bx,dx			;an000; get high word for adjust
   764 000001A8 8CC1                    		mov	cx,es			;an005; place seg in ax
   765 000001AA E87F11                  		call	BadClus_Address_Adjust	;an000; adjust segment offset
   766 000001AD 8EC1                    		mov	es,cx			;an000; new segment
   767 000001AF 89C6                    		mov	si,ax			;an000; new offset
   768                                  
   769 000001B1 BAF70F                  		MOV	DX,0FF7h		;an005; bad cluster flag
   770 000001B4 B8FF0F                  		MOV	AX,0FFFh		;an005; mask value
   771                                  
   772 000001B7 59                      		pop	cx			;an000; restore ax in cx - low cluster number
   773 000001B8 F7C10100                		test	cx,1			;an000; is old clus num odd?
   774                                  ;		$if	nz			;an005; yes
   775 000001BC 7408                    		JZ DD_IF9
   776 000001BE B104                    			mov	cl,4		;an005; set shift count
   777 000001C0 D3E0                    			SHL	AX,cl		;an005; get only 12 bits - fff0
   778 000001C2 B104                    			mov	cl,4		;an005; set shift count
   779 000001C4 D3E2                    			SHL	DX,cl		;an005; get 12 bits	 - ff70
   780                                  ;		$endif				;an005;
   781                                  DD_IF9:
   782                                  ;	$else					;an005; 16-bit fats here
   783 000001C6 EB19                    	JMP SHORT DD_EN8
   784                                  DD_IF8:
   785 000001C8 31F6                    	       xor     si,si			;an005; clear si
   786 000001CA 89D3                    	       mov     bx,dx			;an000; get high word for multiply
   787 000001CC B90200                  	       mov     cx,2			;an000; multiply by 2
   788 000001CF E8D60C                  	       call    Multiply_32_Bits 	;an000; 32 bit multiply
   789                                  						;	due to 2 bytes per
   790                                  						;	FAT cell.  This gives
   791                                  						;	us an offset into the
   792                                  						;	FAT.
   793                                  
   794 000001D2 8CC1                    	       mov     cx,es			;an005; place seg in cx
   795 000001D4 E85511                  	       call    BadClus_Address_Adjust	;an000; adjust segment:offset
   796 000001D7 8EC1                    	       mov     es,cx			;an000; new segment
   797 000001D9 89C6                    	       mov     si,ax			;an000; new offset
   798                                  
   799 000001DB BAF7FF                  	       MOV     DX,0FFF7h		;an005; bad cluster value
   800 000001DE B8FFFF                  	       MOV     AX,0FFFFh		;an005; mask value
   801                                  ;	$endif
   802                                  DD_EN8:
   803                                  
   804 000001E1 268B0C                  	MOV	CX,[es:SI]			;an005; get contents of fat cell
   805 000001E4 21C1                    	AND	CX,AX				;an005; make it 12 or 16 bit
   806                                  						;	depending on value in AX
   807 000001E6 F7D0                    	NOT	AX				;an005; set AX to 0
   808 000001E8 262104                  	AND	[es:SI],AX			;an005; clear FAT entry
   809 000001EB 260914                  	OR	[es:SI],DX			;an005; flag it a bad cluster
   810 000001EE 39CA                    	CMP	DX,CX				;   return op == badval;
   811                                  
   812 000001F0 07                      	pop	es
   813 000001F1 5A                      	pop	dx
   814 000001F2 59                      	pop	cx
   815 000001F3 5B                      	pop	bx
   816 000001F4 58                      	pop	ax
   817 000001F5 5F                      	pop	di
   818 000001F6 C3                      	return
   819                                  
   820                                  badclus 	endp
   821                                  
   822                                  DRTFAT:
   823 000001F7 F706[2006]0100          	TEST	word [SWITCHMAP],SWITCH_S		;If system requested, calculate size
   824 000001FD 740E                    	JZ	CLEARED
   825 000001FF 803E[8804]00            	CMP	BYTE [DBLFLG],0		;Have we already calculated System space?
   826 00000204 7507                    	JNZ	CLEARED 			;Yes
   827 00000206 FE06[8804]              	INC	BYTE [DBLFLG] 		;No -- set the flag
   828                                  GETSIZE equ GetSize	; NASM port label
   829 0000020A E89700                  	CALL	GETSIZE 			;Calculate the system size
   830                                  CLEARED:
   831 0000020D E8190D                  	call	Ctrl_Break_Save 		;ac010; dms;save CTRL-Break
   832 00000210 E82A0D                  	call	Set_Ctrl_Break
   833 00000213 E8580B                  	CALL	WriteFileSystem
   834                                  
   835 00000216 730F                    	JNC	FATWRT
   836                                  
   837                                  
   838                                  LOUSE:
   839                                  
   840 00000218 E8350D                  	call	Reset_Ctrl_Break		;ac010; dms;restore CTRL-Break
   841 0000021B BA[0000]E8(0000)        	Message msgDiskUnusable 		;				;AC000;
   842 00000221 E99DFE                  	JMP	FRMTPROB
   843                                  
   844                                  LOUSEP:
   845 00000224 1F                      	POP	DS
   846 00000225 EBF1                    	JMP	LOUSE
   847                                  
   848                                  FATWRT:
   849                                  
   850 00000227 1E                      	PUSH	DS
   851 00000228 8A16[8206]              	MOV	DL,[DRIVE]
   852 0000022C FEC2                    	INC	DL
   853                                  GET_DPB equ Get_DPB	; NASM port equate
   854 0000022E B432                    	MOV	AH,GET_DPB
   855 00000230 CD21                    	INT	21H
   856 00000232 3CFF                    	CMP	AL,-1
   857 00000234 74EE                    	JZ	LOUSEP				;Something BAD has happened
   858 00000236 C7471D0000              	MOV	word [BX + dpb_next_free],0		; Reset allocation to start of disk
   859 0000023B C7471FFFFF              	MOV	word [BX + dpb_free_cnt],-1		; Force free space to be computed
   860 00000240 1F                      	POP	DS
   861 00000241 F706[2006]0100          	TEST	word [SWITCHMAP],SWITCH_S		;System desired
   862 00000247 742D                    	JZ	STATUS
   863 00000249 A0[8206]                	mov	al, [drive]
   864 0000024C E8(0000)                	call	AccessDisk			; note what is current logical drive
   865 0000024F E84F03                  	CALL	WRITEDOS			;Write the BIOS & DOS
   866 00000252 7314                    	JNC	SYSOK
   867 00000254 BA[0000]E8(0000)        	Message msgNotSystemDisk		;				;AC000;
   868 0000025A C706[0200]0000          	MOV	WORD [SYSSIZ+2],0		;No system transfered
   869 00000260 C706[0000]0000          	MOV	WORD [SYSSIZ],0		;No system transfered
   870 00000266 EB0E                    	JMP	SHORT STATUS
   871                                  
   872                                  SYSOK:
   873                                  
   874                                  
   875 00000268 F706[2006]000C          	test	word [SwitchMap],(Switch_Select | SWITCH_AUTOTEST) ;Don't display if EXEC'd by     ;AN000;
   876                                  ;	$IF	Z				; Select			;AN000;
   877 0000026E 7506                    	JNZ DD_IF13
   878 00000270 BA[0000]E8(0000)        	   Message msgSystemTransfered		;				;AC000;
   879                                  ;	$ENDIF					;AN000;
   880                                  DD_IF13:
   881                                  STATUS:
   882                                  
   883 00000276 E8D70C                  	call	Reset_Ctrl_Break		;ac010; dms;restore CTRL-Break
   884                                  
   885                                  CRLF equ crlf	; NASM port label
   886 00000279 E8C201                  	CALL	CRLF
   887                                  
   888                                  
   889                                  
   890                                  
   891                                  DISK_RESET equ Disk_Reset	; NASM port equate
   892 0000027C B40D                    	MOV	AH,DISK_RESET
   893 0000027E CD21                    	INT	21H
   894                                  DONE equ Done	; NASM port label
   895 00000280 E8FB0B                  	CALL	DONE				;Final call to OEM module
   896 00000283 7303                    	JNC	REPORTC
   897 00000285 E939FE                  	JMP	FRMTPROB			;Report an error
   898                                  
   899                                  REPORTC:
   900                                  
   901                                  ;
   902                                  ;TEMP FIX for /AUTOTEST
   903                                  ;
   904                                  Switch_Autotest equ SWITCH_AUTOTEST	; NASM port equate
   905                                  Switch_8 equ SWITCH_8	; NASM port equate
   906 00000288 F706[2006]0009          	test	word [SwitchMap],(Switch_Autotest | Switch_8)       ;TEMP
   907                                  ;	$IF	Z
   908 0000028E 7503                    	JNZ DD_IF15
   909                                  VOLID equ Volid	; NASM port label
   910 00000290 E8(0000)                	   CALL    VOLID
   911                                  ;	$ENDIF
   912                                  DD_IF15:
   913 00000293 F706[2006]000C          	test	word [SwitchMap],(Switch_Select | SWITCH_AUTOTEST) ;Need to shut down the report? ;AN000;
   914                                  ;	$IF	Z				;If exec'd by Select, we do     ;AN000;
   915 00000299 7503                    	JNZ DD_IF17
   916 0000029B E8(0000)                	   CALL    REPORT			;Print report
   917                                  ;	$ENDIF					;				;AN000;
   918                                  DD_IF17:
   919 0000029E E85C00                  	CALL	MORE				;See if more disks to format
   920 000002A1 E9FAFD                  	JMP	SYSLOOP 			;If we returned from MORE then continue
   921                                  
   922                                  ;******************************************
   923                                  ; Calculate the size in bytes of the system rounded up to sector and
   924                                  ;   cluster boundries, Answer in SYSSIZ
   925                                  
   926                                  GetSize proc	near
   927 000002A4 E80700                  	call	GetBioSize
   928 000002A7 E80F00                  	call	GetDosSize
   929 000002AA E81700                  	call	GetCmdSize
   930 000002AD C3                      	return
   931                                  GetSize endp
   932                                  
   933                                  GetBioSize proc near
   934 000002AE A1[E204]                	MOV	AX,WORD PTR [bios + fileSizeInBytes]
   935 000002B1 8B16[E404]              	MOV	DX,WORD PTR [bios + fileSizeInBytes+2]
   936 000002B5 E81700                  	CALL	AddToSystemSize
   937 000002B8 C3                      	return
   938                                  GetBioSize endp
   939                                  
   940                                  GetDosSize proc near
   941 000002B9 A1[F404]                	MOV	AX,WORD PTR [dos + fileSizeInBytes]
   942 000002BC 8B16[F604]              	MOV	DX,WORD PTR [dos + fileSizeInBytes+2]
   943 000002C0 E80C00                  	CALL	AddToSystemSize
   944 000002C3 C3                      	return
   945                                  GetDosSize endp
   946                                  
   947                                  GetCmdSize proc near
   948 000002C4 A1[0605]                	MOV	AX,WORD PTR [command + fileSizeInBytes]
   949 000002C7 8B16[0805]              	MOV	DX,WORD PTR [command + fileSizeInBytes+2]
   950 000002CB E80100                  	call	AddToSystemSize
   951 000002CE C3                      	return
   952                                  GetCmdSize endp
   953                                  
   954                                  ;Calculate the number of sectors used for the system
   955                                  PUBLIC	AddToSystemSize
   956                                  AddToSystemSize proc near
   957 000002CF 53                      	push	bx
   958 000002D0 F736[2C01]              	DIV	word [deviceParameters + DP_BPB + BPB_BytesPerSector]
   959 000002D4 09D2                    	OR	DX,DX
   960 000002D6 7401                    	JZ	FNDSIZ0
   961 000002D8 40                      	INC	AX				; Round up to next sector
   962                                  FNDSIZ0:
   963 000002D9 50                      	PUSH	AX
   964 000002DA 31D2                    	XOR	DX,DX
   965 000002DC 31DB                    	xor	bx,bx
   966                                  BPB_SectorsPerCluster equ BPB_SECTORSPERCLUSTER	; NASM port equate
   967 000002DE 8A1E[2E01]              	mov	bl, [deviceParameters + DP_BPB + BPB_SectorsPerCluster]
   968 000002E2 F7F3                    	div	bx
   969 000002E4 58                      	POP	AX
   970 000002E5 09D2                    	OR	DX,DX
   971 000002E7 7406                    	JZ	ONCLUS
   972 000002E9 29DA                    	SUB	DX, bx
   973 000002EB F7DA                    	NEG	DX
   974 000002ED 01D0                    	ADD	AX,DX				; Round up sector count to cluster
   975                                  						;	boundry
   976                                  ONCLUS:
   977 000002EF F726[2C01]              	MUL	word [deviceParameters + DP_BPB + BPB_BytesPerSector]
   978 000002F3 0106[0000]              	ADD	WORD PTR [SYSSIZ],AX
   979 000002F7 1116[0200]              	ADC	WORD PTR [SYSSIZ+2],DX
   980 000002FB 5B                      	pop	bx
   981 000002FC C3                      	return
   982                                  AddToSystemSize endp
   983                                  
   984                                  MORE:
   985                                  
   986 000002FD C706[6E04]0000          	mov	word [Formatted_Tracks_Low],0		;Reinit the track counter	;AN000;
   987 00000303 C706[7004]0000          	mov	word [Formatted_Tracks_High],0 	; in case of another format	;AN000;
   988 00000309 F706[2006]000C          	test	word [SwitchMap],(Switch_Select | SWITCH_AUTOTEST) ;Don't display if EXEC'd  by ;AN000;
   989 0000030F 7528                    	jnz	ExitProgram			; Select			;AN000;
   990                                  
   991 00000311 803E[2601]05            	CMP	byte [deviceParameters + DP_DeviceType], DEV_HARDDISK
   992 00000316 7421                    	je	ExitProgram
   993                                  SWITCH_Select equ SWITCH_SELECT	; NASM port equate
   994 00000318 F706[2006]000C          	test	word [SwitchMap],(SWITCH_Select | SWITCH_AUTOTEST) ;If exec'd from select, then;AN000;
   995 0000031E 7519                    	jnz	ExitProgram			; don't give user choice        ;AN000;
   996 00000320 E8(0000)                	CALL	FormatAnother?			;Get yes or no response
   997 00000323 7214                    	JC	ExitProgram
   998 00000325 E81601                  	CALL	CRLF
   999 00000328 E91301                  	JMP	CRLF
  1000                                  
  1001                                  
  1002                                  FEXIT:
  1003 0000032B 50B8[ssss]8ED81E07-     	Set_Data_Segment			;Make sure have addressability	;AN000;
  1003 00000333 58                 
  1004 00000334 C606[8304]04            	mov	byte [ExitStatus],ExitFatal
  1005                                  
  1006                                  ExitProgram:
  1007 00000339 F606[0000]FF            	test	byte [validSavedDeviceParameters], 0ffH
  1008 0000033E 740C                    	jz	DoNotRestoreDeviceParameters
  1009                                  DP_SpecialFunctions equ DP_SPECIALFUNCTIONS	; NASM port equate
  1010 00000340 C606[0100]04            	mov	byte [savedDeviceParameters + DP_SpecialFunctions], TRACKLAYOUT_IS_GOOD
  1011 00000345 8D16[0100]              	lea	dx, [savedDeviceParameters]
  1012 00000349 E8C007                  	call	SetDeviceParameters
  1013                                  DoNotRestoreDeviceParameters:
  1014                                  
  1015 0000034C E8A30F                  	call	Format_Access_Wrap_Up		;determine access status	;an000; dms;determine access status
  1016 0000034F A0[8304]                	mov	al,[ExitStatus]			;Get Errorlevel 		;AN000;
  1017 00000352 B44CCD21                	DOS_Call Exit				;Exit program			;AN000;
  1018 00000356 CD20                    	int	20h				;If other exit fails		;AN000;
  1019                                  
  1020                                  ; Prompt the user for a system diskette in the default drive
  1021                                  SYSPRM:
  1022                                  GET_DEFAULT_DRIVE equ Get_Default_Drive	; NASM port equate
  1023 00000358 B419                    	MOV	AH,GET_DEFAULT_DRIVE		;Will find out the default drive
  1024 0000035A CD21                    	INT	21H				;Default now in AL
  1025 0000035C 88C3                    	MOV	BL,AL
  1026 0000035E FEC3                    	INC	BL				; A = 1
  1027 00000360 0441                    	ADD	AL,41H				;Now in Ascii
  1028 00000362 A2[8406]                	MOV	[systemDriveLetter],AL		;Text now ok
  1029 00000365 E85700                  	CALL	IsRemovable
  1030 00000368 731E                    	JNC	DoPrompt
  1031                                  ;
  1032                                  ; Media is non-removable. Switch sys disk to drive A.  Check, though, to see
  1033                                  ; if drive A is removable too.
  1034                                  ;
  1035 0000036A B041                    	MOV	AL,"A"
  1036 0000036C A2[8406]                	MOV	BYTE PTR [systemDriveLetter],AL
  1037 0000036F A2[0000]                	MOV	[BiosFile],AL
  1038 00000372 A2[0000]                	MOV	[DosFile],AL
  1039 00000375 A2[1405]                	MOV	[CommandFile],AL
  1040 00000378 BB0100                  	MOV	BX,1
  1041 0000037B E84100                  	CALL	IsRemovable
  1042 0000037E 7308                    	JNC	DoPrompt
  1043 00000380 BA[0000]E8(0000)        	Message msgNoSystemFiles		;				;AC000;
  1044                                  fexitJ:
  1045 00000386 EBA3                    	JMP	FEXIT
  1046                                  
  1047                                  DoPrompt:
  1048 00000388 A0[8406]                	mov	al, [systemDriveLetter]
  1049 0000038B 2C41                    	sub	al, 'A'
  1050 0000038D E8(0000)                	call	AccessDisk
  1051                                  msgInsertDOSDisk equ msgInsertDosDisk	; NASM port label
  1052 00000390 BA[0000]E8(0000)        	Message msgInsertDOSDisk		;				;AC000;
  1053 00000396 BA[0000]E8(0000)        	Message ContinueMsg
  1054                                  						;lea	 dx, ptr_msgInsertDosDisk
  1055                                  						;CALL	 std_printf		 ;Print first line
  1056 0000039C E8(0000)                	CALL	USER_STRING			;Wait for a key
  1057 0000039F E89C00                  	CALL	CRLF
  1058 000003A2 E89900                  	call	crlf
  1059 000003A5 C3                      	return
  1060                                  
  1061                                  TARGPRM:
  1062 000003A6 A0[8206]                	mov	al, [drive]
  1063 000003A9 E8(0000)                	call	AccessDisk
  1064                                  MsgInsertDisk equ msgInsertDisk	; NASM port label
  1065 000003AC BA[0000]E8(0000)        	Message MsgInsertDisk			;				;AC000;
  1066 000003B2 BA[0000]E8(0000)        	Message ContinueMsg			;
  1067                                  						;lea	 DX, ptr_msgInsertDisk
  1068                                  						;CALL	 std_printf		 ;Print first line
  1069 000003B8 E8(0000)                	CALL	USER_STRING			;Wait for a key
  1070 000003BB E88000                  	CALL	CRLF
  1071 000003BE C3                      	return
  1072                                  
  1073                                  ;
  1074                                  ; Determine if the drive indicated in BX is removable or not.
  1075                                  ;
  1076                                  ;   Inputs:	BX has drive (0=def, 1=A)
  1077                                  ;   Outputs:	Carry clear
  1078                                  ;		    Removable
  1079                                  ;		Carry set
  1080                                  ;		    not removable
  1081                                  ;   Registers modified: none
  1082                                  
  1083                                  IsRemovable:
  1084 000003BF 50                      	SaveReg <AX>
  1085                                  IOCTL equ IOCtl	; NASM port equate
  1086 000003C0 B80844                  	MOV	AX,(IOCTL << 8) | 8		; Rem media check
  1087 000003C3 CD21                    	INT	21H
  1088 000003C5 7310                    	JNC	CheckRemove
  1089 000003C7 B80944                  	MOV	AX,(IOCTL << 8) + 9		; Is it a NET drive?
  1090 000003CA CD21                    	INT	21h
  1091 000003CC 7211                    	JC	NotRemove			; Yipe, say non-removable
  1092 000003CE F7C20010                	TEST	DX,1000h
  1093 000003D2 750B                    	JNZ	NotRemove			; Is NET drive, say non-removeable
  1094 000003D4 EB06                    	JMP	IsRemove			; Is local, say removable
  1095 000003D6 90                      	nop	; identicalise
  1096                                  CheckRemove:
  1097 000003D7 A90100                  	TEST	AX,1
  1098 000003DA 7503                    	JNZ	NotRemove
  1099                                  IsRemove:
  1100 000003DC F8                      	CLC
  1101 000003DD 58                      	RestoreReg <AX>
  1102 000003DE C3                      	return
  1103                                  NotRemove:
  1104 000003DF F9                      	STC
  1105 000003E0 58                      	RestoreReg <AX>
  1106 000003E1 C3                      	return
  1107                                  
  1108                                  
  1109                                  ; DiSKPRoMpt:
  1110                                  ;
  1111                                  ;	This routine prompts for the insertion of the correct diskette
  1112                                  ;  into the Target drive, UNLESS we are being re-entrantly invoked
  1113                                  ;  from LastChanceToSaveIt.  If the target is a Hardisk we issue a
  1114                                  ;  warning message.
  1115                                  ;
  1116                                  ;	INPUTS:
  1117                                  ;		deviceParameters.DP_DeviceType
  1118                                  ;		fLastChance
  1119                                  ;
  1120                                  ;	OUTPUTS:
  1121                                  ;		Prompt string
  1122                                  ;		fLastChance	:= FALSE
  1123                                  ;
  1124                                  ;	Registers affected:
  1125                                  ;				Flags
  1126                                  ;
  1127                                  DSKPRM:
  1128 000003E2 803E[7904]FF            	CMP	byte [fLastChance],TRUE
  1128          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  1129 000003E7 743C                    	JE	PrmptRet
  1130                                  
  1131 000003E9 803E[2601]05            	CMP	byte [deviceParameters + DP_DeviceType], DEV_HARDDISK
  1132                                  goprnit equ GOPRNIT	; NASM port label
  1133 000003EE 751A                    	jne	goprnit
  1134 000003F0 BA[0000]E8(0000)        	Message msgHardDiskWarning		;				;AC000;
  1135                                  						;lea	 dx, ptr_msgHardDiskWarning
  1136                                  						;call	 std_printf
  1137 000003F6 E8(0000)                	CALL	Yes?
  1138 000003F9 7308                    	jnc	OkToFormatHardDisk
  1139 000003FB C606[8304]05            	mov	byte [ExitStatus], ExitNo
  1140 00000400 E936FF                  	jmp	ExitProgram
  1141                                  
  1142                                  OkToFormatHardDisk:
  1143 00000403 E83800                  	CALL	CRLF
  1144 00000406 E83500                  	CALL	CRLF
  1145 00000409 C3                      	return
  1146                                  
  1147                                  GOPRNIT:
  1148 0000040A A0[8206]                	mov	al, [drive]
  1149 0000040D E8(0000)                	call	AccessDisk
  1150 00000410 BA[0000]E8(0000)        	Message msgInsertDisk			;				;AC000;
  1151 00000416 BA[0000]E8(0000)        	Message ContinueMsg			;
  1152                                  						;lea	 dx,ptr_msgInsertDisk
  1153                                  						;CALL	 std_printf
  1154 0000041C E8(0000)                	CALL	USER_STRING			;Wait for any key
  1155 0000041F E81C00                  	CALL	CRLF
  1156 00000422 E81900                  	CALL	CRLF
  1157                                  
  1158                                  PrmptRet:
  1159 00000425 C606[7904]00            	mov	byte [fLastChance], FALSE
  1160 0000042A C3                      	return
  1161                                  
  1162                                  
  1163                                  ;-------------------------------------------------------------------------------
  1164                                  
  1165                                  ControlC_Handler:
  1166 0000042B B8[ssss]                	mov	ax, data
  1167 0000042E 8ED8                    	mov	ds, ax
  1168 00000430 BA[0000]E8(0000)        	Message msgInterrupt			;				;AC000;
  1169 00000436 C606[8304]03            	mov	byte [ExitStatus], ExitCtrlC
  1170 0000043B E9FBFE                  	jmp	ExitProgram
  1171                                  
  1172                                  
  1173                                  crlf:
  1174                                  						;lea	 dx, msgCRLF
  1175 0000043E BA[0000]                	mov	dx,offset msgCRLF		;CR,LF added to message 	;AC000;
  1176                                  PrintString:
  1177                                  						;mov	 printStringPointer, dx
  1178                                  						;lea	 dx, PrintStringPointer
  1179                                  
  1180                                  std_printf:
  1181                                  						;push	 dx
  1182                                  						;call	 printf
  1183 00000441 E8(0000)                	call	Display_Interface		;				;AC000;
  1184 00000444 C3                      	return
  1185                                  
  1186                                  ;-------------------------------------------------------------------------------
  1187                                  
  1188                                  
  1189                                  ;****************************************
  1190                                  ;Copy IO.SYS, MSDOS.SYS and COMMAND.COM into data area.
  1191                                  ; Carry set if problems
  1192                                  
  1193                                  READDOS:
  1194 00000445 50                      	push	ax				;save regs			;an025; dms;
  1195 00000446 53                      	push	bx				;				;an025; dms;
  1196 00000447 06                      	push	es				;				;an025; dms;
  1197                                  
  1198 00000448 B452                    	mov	ah,Get_In_Vars			;Find out boot drive		;an025; dms;
  1199 0000044A CD21                    	int	21h				;				;an025; dms;
  1200                                  SysI_Boot_Drive equ SYSI_BOOT_DRIVE	; NASM port equate
  1201 0000044C 268A4743                	mov	al,byte ptr [es:bx + SysI_Boot_Drive] ;get 1 based drive ID	;an025; dms;
  1202 00000450 0440                    	add	al,40h				;Make it ASCII			;an025; dms;
  1203 00000452 A2[0000]                	mov	[BiosFile],al			;Stuff it in file specs.	;an025; dms;
  1204 00000455 A2[0000]                	mov	[DosFile],al			;				;an025; dms;
  1205 00000458 A2[1405]                	mov	[CommandFile],al		;				;an025; dms;
  1206                                  
  1207 0000045B 07                      	pop	es				;restore regs			;an025; dms;
  1208 0000045C 5B                      	pop	bx				;				;an025; dms;
  1209 0000045D 58                      	pop	ax				;				;an025; dms;
  1210                                  
  1211 0000045E E8A603                  	call	Get_BIOS			; dcl 8/23/86
  1212 00000461 7301                    	JNC	RDFILS
  1213 00000463 C3                      	return
  1214                                  
  1215                                  RDFILS:
  1216 00000464 C606[9304]00            	MOV	BYTE PTR [FILSTAT],0
  1217 00000469 8B1E[DE04]              	MOV	BX,[bios + fileHandle]
  1218 0000046D A1[8D04]                	MOV	AX,[MSTART]
  1219 00000470 89C2                    	MOV	DX,AX
  1220 00000472 0316[8F04]              	ADD	DX,[MSIZE]			; CX first bad para
  1221 00000476 A3[EA04]                	MOV	[bios + fileStartSegment],AX
  1222 00000479 8B0E[E004]              	MOV	CX,[bios + fileSizeInParagraphs]
  1223 0000047D 01C8                    	ADD	AX,CX
  1224 0000047F 39D0                    	CMP	AX,DX
  1225 00000481 7630                    	JBE	GOTBIOS
  1226 00000483 C606[9304]01            	MOV	BYTE PTR [FILSTAT],00000001B	; Got part of BIOS
  1227 00000488 8B36[8F04]              	MOV	SI,[MSIZE]
  1228 0000048C 31FF                    	XOR	DI,DI
  1229 0000048E E8E204                  	CALL	DISIX4
  1230 00000491 1E                      	push	ds
  1231 00000492 8E1E[EA04]              	MOV	DS,[bios + fileStartSegment]
  1232                                  	assume	ds:nothing
  1233 00000496 E86404                  	CALL	READFILE
  1234 00000499 1F                      	pop	ds
  1235                                  	assume	ds:data
  1236 0000049A 7211                    	JC	CLSALL
  1237 0000049C 31D2                    	XOR	DX,DX
  1238 0000049E 89D1                    	MOV	CX,DX
  1239                                  LSEEK equ LSeek	; NASM port equate
  1240 000004A0 B80142                  	MOV	AX,(LSEEK << 8) | 1
  1241 000004A3 CD21                    	INT	21H
  1242 000004A5 A3[E604]                	MOV	WORD PTR [bios + fileOffset],AX
  1243 000004A8 8916[E804]              	MOV	WORD PTR [bios + fileOffset+2],DX
  1244                                  FILESDONE:
  1245 000004AC F8                      	CLC
  1246                                  CLSALL:
  1247 000004AD 9C                      	PUSHF
  1248                                  ;	CALL	COMCLS			; dcl 8/23/86
  1249 000004AE E81604                  	call	FILE_CLS			; dcl 8/23/86
  1250 000004B1 9D                      	POPF
  1251 000004B2 C3                      	return
  1252                                  
  1253                                  GOTBIOS:
  1254 000004B3 C606[9304]02            	MOV	BYTE PTR [FILSTAT],00000010B	; Got all of BIOS
  1255 000004B8 06                      	push	es
  1256 000004B9 C436[E204]              	LES	SI,[bios + fileSizeInBytes]
  1257 000004BD 8CC7                    	MOV	DI,ES
  1258 000004BF 07                      	pop	es
  1259 000004C0 1E                      	push	ds
  1260 000004C1 8E1E[EA04]              	MOV	DS,[bios + fileStartSegment]
  1261                                  	assume	ds:nothing
  1262 000004C5 E83504                  	CALL	READFILE
  1263 000004C8 1F                      	pop	ds
  1264                                  	assume	ds:data
  1265 000004C9 72E2                    	JC	CLSALL
  1266                                  
  1267 000004CB 50                      	push	ax				; dcl 8/23/86
  1268 000004CC 52                      	push	dx				; dcl 8/23/86
  1269                                  File_Cls equ FILE_CLS	; NASM port label
  1270 000004CD E8F703                  	call	File_Cls			; dcl 8/23/86
  1271 000004D0 E87403                  	call	Get_DOS 			; dcl 8/23/86
  1272 000004D3 5A                      	pop	dx				; dcl 8/23/86
  1273 000004D4 58                      	pop	ax				; dcl 8/23/86
  1274                                  
  1275 000004D5 7301                    	JNC	Found_IBMDOS			;mt 12/8/86 P894
  1276 000004D7 C3                      	return					;mt 12/8/86
  1277                                  
  1278                                  Found_IBMDOS:					;mt 12/8/86
  1279                                  
  1280 000004D8 8B1E[F004]              	MOV	BX,[dos + fileHandle]
  1281 000004DC A3[FC04]                	MOV	[dos + fileStartSegment],AX
  1282 000004DF 39D0                    	CMP	AX,DX				; No room left?
  1283 000004E1 74CA                    	JZ	CLSALL				; Yes
  1284 000004E3 8B0E[F204]              	MOV	CX,[dos + fileSizeInParagraphs]
  1285 000004E7 01C8                    	ADD	AX,CX
  1286 000004E9 39D0                    	CMP	AX,DX
  1287 000004EB 762D                    	JBE	GOTDOS
  1288 000004ED 800E[9304]04            	OR	BYTE PTR [FILSTAT],00000100B	; Got part of DOS
  1289 000004F2 2B16[FC04]              	SUB	DX,[dos + fileStartSegment]
  1290 000004F6 89D6                    	MOV	SI,DX
  1291 000004F8 31FF                    	XOR	DI,DI
  1292 000004FA E87604                  	CALL	DISIX4
  1293 000004FD 1E                      	push	ds
  1294 000004FE 8E1E[FC04]              	MOV	DS,[dos + fileStartSegment]
  1295                                  	assume	ds:nothing
  1296 00000502 E8F803                  	CALL	READFILE
  1297 00000505 1F                      	pop	ds
  1298                                  	assume	ds:data
  1299 00000506 72A5                    	JC	CLSALL
  1300 00000508 31D2                    	XOR	DX,DX
  1301 0000050A 89D1                    	MOV	CX,DX
  1302 0000050C B80142                  	MOV	AX,(LSEEK << 8) | 1
  1303 0000050F CD21                    	INT	21H
  1304 00000511 A3[F804]                	MOV	WORD PTR [dos + fileOffset],AX
  1305 00000514 8916[FA04]              	MOV	WORD PTR [dos + fileOffset+2],DX
  1306 00000518 EB92                    	JMP	FILESDONE
  1307                                  
  1308                                  GOTDOS:
  1309 0000051A 800E[9304]08            	OR	BYTE PTR [FILSTAT],00001000B	; Got all of DOS
  1310 0000051F 06                      	push	es
  1311 00000520 C436[F404]              	LES	SI,[dos + fileSizeInBytes]
  1312 00000524 8CC7                    	MOV	DI,ES
  1313 00000526 07                      	pop	es
  1314 00000527 1E                      	push	ds
  1315 00000528 8E1E[FC04]              	MOV	DS,[dos + fileStartSegment]
  1316                                  	assume	ds:nothing
  1317 0000052C E8CE03                  	CALL	READFILE
  1318 0000052F 1F                      	pop	ds
  1319                                  	assume	ds:data
  1320                                  
  1321                                  NOTCLSALL equ NotCLSALL	; NASM port label
  1322 00000530 7303                    CLSALLJ: JNC	NOTCLSALL			;PTM P894  mt 12/8/86
  1323                                  clsall equ CLSALL	; NASM port label
  1324 00000532 E978FF                  	jmp	clsall				;
  1325                                  
  1326                                  NotCLSALL:
  1327 00000535 50                      	push	ax				; dcl 8/23/86
  1328                                  
  1329 00000536 52                      	push	dx				; dcl 8/23/86
  1330                                  File_cls equ FILE_CLS	; NASM port label
  1331 00000537 E88D03                  	call	File_cls			; dcl 8/23/86
  1332 0000053A E82C0A                  	call	Get_Command_Path		;ac011; dms; get path of
  1333                                  						;	     COMMAND.COM
  1334 0000053D E84703                  	call	Get_COMMAND			;ac011; dms; Point to COMMAND
  1335                                  						;	     and read it
  1336 00000540 5A                      	pop	dx				; dcl 8/23/86
  1337 00000541 58                      	pop	ax				; dcl 8/23/86
  1338                                  
  1339 00000542 7301                    	JNC	Found_COMMAND			;mt 12/8/86 P894
  1340 00000544 C3                      	return					;mt 12/8/86
  1341                                  
  1342                                  Found_COMMAND:					;mt 12/8/86
  1343 00000545 8B1E[0205]              	MOV	BX,[command + fileHandle]
  1344 00000549 A3[0E05]                	MOV	[command + fileStartSegment],AX
  1345 0000054C 39D0                    	CMP	AX,DX				; No room left?
  1346 0000054E 74E0                    	JZ	CLSALLJ 			; Yes
  1347 00000550 8B0E[0405]              	MOV	CX,[command + fileSizeInParagraphs]
  1348 00000554 01C8                    	ADD	AX,CX
  1349 00000556 39D0                    	CMP	AX,DX
  1350 00000558 762E                    	JBE	GOTCOM
  1351 0000055A 800E[9304]10            	OR	BYTE PTR [FILSTAT],00010000B	; Got part of COMMAND
  1352 0000055F 2B16[0E05]              	SUB	DX,[command + fileStartSegment]
  1353 00000563 89D6                    	MOV	SI,DX
  1354 00000565 31FF                    	XOR	DI,DI
  1355 00000567 E80904                  	CALL	DISIX4
  1356 0000056A 1E                      	push	ds
  1357 0000056B 8E1E[0E05]              	MOV	DS,[command + fileStartSegment]
  1358                                  	assume	ds:nothing
  1359 0000056F E88B03                  	CALL	READFILE
  1360 00000572 1F                      	pop	ds
  1361                                  	assume	ds:data
  1362 00000573 72BB                    	JC	CLSALLJ
  1363 00000575 31D2                    	XOR	DX,DX
  1364 00000577 89D1                    	MOV	CX,DX
  1365 00000579 B80142                  	MOV	AX,(LSEEK << 8) | 1
  1366 0000057C CD21                    	INT	21H
  1367 0000057E A3[0A05]                	MOV	WORD PTR [command + fileOffset],AX
  1368 00000581 8916[0C05]              	MOV	WORD PTR [command + fileOffset+2],DX
  1369 00000585 E924FF                  	JMP	FILESDONE
  1370                                  
  1371                                  GOTCOM:
  1372 00000588 800E[9304]20            	OR	BYTE PTR [FILSTAT],00100000B	; Got all of COMMAND
  1373 0000058D 06                      	push	es
  1374 0000058E C436[0605]              	LES	SI,[command + fileSizeInBytes]
  1375 00000592 8CC7                    	MOV	DI,ES
  1376 00000594 07                      	pop	es
  1377 00000595 1E                      	push	ds
  1378 00000596 8E1E[0E05]              	MOV	DS,[command + fileStartSegment]
  1379                                  	assume	ds:nothing
  1380 0000059A E86003                  	CALL	READFILE
  1381 0000059D 1F                      	pop	ds
  1382                                  	assume	ds:data
  1383 0000059E E90CFF                  	JMP	CLSALL
  1384                                  
  1385                                  ;**************************************************
  1386                                  ;Write BIOS DOS COMMAND to the newly formatted disk.
  1387                                  
  1388                                  ASSUME	DS:DATA
  1389                                  WRITEDOS:
  1390 000005A1 B90700                  	MOV	CX,BiosAttributes
  1391 000005A4 BA[0000]                	MOV	DX,OFFSET BiosFile
  1392 000005A7 06                      	push	es
  1393 000005A8 C436[E204]              	LES	SI,[bios + fileSizeInBytes]
  1394 000005AC 8CC7                    	MOV	DI,ES
  1395 000005AE 07                      	pop	es
  1396 000005AF E84201                  	CALL	MAKEFIL
  1397 000005B2 7290                    	retc
  1398                                  
  1399 000005B4 891E[9104]              	MOV	[TempHandle],BX
  1400 000005B8 F606[9304]02            	TEST	BYTE [FILSTAT],00000010B
  1401 000005BD 7520                    	JNZ	GOTALLBIO
  1402 000005BF E84502                  	call	Get_BIOS			; dcl 8/23/86
  1403 000005C2 7301                    	jnc	Got_WBIOS			;mt 12/8/86  P894
  1404 000005C4 C3                      	ret
  1405                                  
  1406                                  Got_WBIOS:
  1407                                  
  1408 000005C5 06                      	push	es
  1409 000005C6 C436[E604]              	LES	SI,[bios + fileOffset]
  1410 000005CA 8CC7                    	MOV	DI,ES
  1411 000005CC 07                      	pop	es
  1412 000005CD 8936[8904]              	MOV	WORD PTR [IOCNT],SI
  1413 000005D1 893E[8B04]              	MOV	WORD PTR [IOCNT+2],DI
  1414 000005D5 BD[DE04]                	MOV	BP,OFFSET bios
  1415 000005D8 E87701                  	CALL	GOTTARG
  1416 000005DB 72D5                    	retc
  1417 000005DD EB11                    	JMP	SHORT BIOSDONE
  1418                                  
  1419                                  GOTALLBIO:
  1420 000005DF 06                      	push	es
  1421 000005E0 C436[E204]              	LES	SI,[bios + fileSizeInBytes]
  1422 000005E4 8CC7                    	MOV	DI,ES
  1423 000005E6 07                      	pop	es
  1424 000005E7 1E                      	push	ds
  1425 000005E8 8E1E[EA04]              	MOV	DS,[bios + fileStartSegment]
  1426                                  	assume	ds:nothing
  1427 000005EC E81B03                  	CALL	WRITEFILE
  1428 000005EF 1F                      	pop	ds
  1429                                  	assume	ds:data
  1430                                  BIOSDONE:
  1431 000005F0 8B1E[9104]              	MOV	BX,[TempHandle]
  1432 000005F4 8B0E[EE04]              	MOV	CX,[bios + fileTime]
  1433 000005F8 8B16[EC04]              	MOV	DX,[bios + fileDate]
  1434 000005FC E83901                  	CALL	CLOSETARG
  1435 000005FF B90700                  	MOV	CX,DosAttributes
  1436 00000602 BA[0000]                	MOV	DX,OFFSET DosFile
  1437 00000605 06                      	push	es
  1438 00000606 C436[F404]              	LES	SI,[dos + fileSizeInBytes]
  1439 0000060A 8CC7                    	MOV	DI,ES
  1440 0000060C 07                      	pop	es
  1441 0000060D E8E400                  	CALL	MAKEFIL
  1442 00000610 72C9                    	retc
  1443                                  
  1444                                  GOTNDOS:
  1445 00000612 891E[9104]              	MOV	[TempHandle],BX
  1446 00000616 F606[9304]08            	TEST	BYTE [FILSTAT],00001000B
  1447 0000061B 753A                    	JNZ	GOTALLDOS
  1448 0000061D E82702                  	call	Get_DOS 			; dcl 8/23/86
  1449 00000620 7301                    	jnc	Got_WDOS			;mt 12/8/86  P894
  1450 00000622 C3                      	ret
  1451                                  
  1452                                  Got_WDOS:
  1453 00000623 BD[F004]                	MOV	BP,OFFSET dos
  1454 00000626 F606[9304]04            	TEST	BYTE [FILSTAT],00000100B
  1455 0000062B 7513                    	JNZ	PARTDOS
  1456 0000062D C706[F804]0000          	MOV	WORD PTR [dos + fileOffset],0
  1457 00000633 C706[FA04]0000          	MOV	WORD PTR [dos + fileOffset+2],0
  1458 00000639 E84201                  	CALL	GETSYS3
  1459 0000063C 72D2                    	retc
  1460 0000063E EB28                    	JMP	SHORT DOSDONE
  1461                                  
  1462                                  PARTDOS:
  1463 00000640 06                      	push	es
  1464 00000641 C436[F804]              	LES	SI,[dos + fileOffset]
  1465 00000645 8CC7                    	MOV	DI,ES
  1466 00000647 07                      	pop	es
  1467 00000648 8936[8904]              	MOV	WORD PTR [IOCNT],SI
  1468 0000064C 893E[8B04]              	MOV	WORD PTR [IOCNT+2],DI
  1469 00000650 E8FF00                  	CALL	GOTTARG
  1470 00000653 72E7                    	retc
  1471 00000655 EB11                    	JMP	SHORT DOSDONE
  1472                                  
  1473                                  GOTALLDOS:
  1474 00000657 06                      	push	es
  1475 00000658 C436[F404]              	LES	SI,[dos + fileSizeInBytes]
  1476 0000065C 8CC7                    	MOV	DI,ES
  1477 0000065E 07                      	pop	es
  1478 0000065F 1E                      	push	ds
  1479 00000660 8E1E[FC04]              	MOV	DS,[dos + fileStartSegment]
  1480                                  	assume	ds:nothing
  1481 00000664 E8A302                  	CALL	WRITEFILE
  1482 00000667 1F                      	pop	ds
  1483                                  	assume	ds:data
  1484                                  DOSDONE:
  1485 00000668 8B1E[9104]              	MOV	BX,[TempHandle]
  1486 0000066C 8B0E[0005]              	MOV	CX,[dos + fileTime]
  1487 00000670 8B16[FE04]              	MOV	DX,[dos + fileDate]
  1488 00000674 E8C100                  	CALL	CLOSETARG
  1489 00000677 B90000                  	MOV	CX,CommandAttributes
  1490 0000067A E86809                  	call	Command_Root			;an011; dms;adjust path for
  1491                                  						;COMMAND.COM creation
  1492 0000067D BA[1405]                	MOV	DX,OFFSET CommandFile
  1493 00000680 06                      	push	es
  1494 00000681 C436[0605]              	LES	SI,[command + fileSizeInBytes]
  1495 00000685 8CC7                    	MOV	DI,ES
  1496 00000687 07                      	pop	es
  1497 00000688 E86900                  	CALL	MAKEFIL
  1498 0000068B 72C6                    	retc
  1499                                  
  1500 0000068D 891E[9104]              	MOV	[TempHandle],BX
  1501 00000691 F606[9304]20            	TEST	BYTE [FILSTAT],00100000B
  1502 00000696 753A                    	JNZ	GOTALLCOM
  1503 00000698 E8EC01                  	call	Get_COMMAND			; dcl 8/23/86
  1504 0000069B 7301                    	jnc	Got_WCOM			;mt 12/8/86  P894
  1505 0000069D C3                      	ret
  1506                                  
  1507                                  Got_WCOM:
  1508 0000069E BD[0205]                	MOV	BP,OFFSET command
  1509 000006A1 F606[9304]10            	TEST	BYTE [FILSTAT],00010000B
  1510 000006A6 7513                    	JNZ	PARTCOM
  1511 000006A8 C706[0A05]0000          	MOV	WORD PTR [command + fileOffset],0
  1512 000006AE C706[0C05]0000          	MOV	WORD PTR [command + fileOffset+2],0
  1513 000006B4 E8C700                  	CALL	GETSYS3
  1514 000006B7 72D2                    	retc
  1515 000006B9 EB28                    	JMP	SHORT COMDONE
  1516                                  
  1517                                  PARTCOM:
  1518 000006BB 06                      	push	es
  1519 000006BC C436[0A05]              	LES	SI,[command + fileOffset]
  1520 000006C0 8CC7                    	MOV	DI,ES
  1521 000006C2 07                      	pop	es
  1522 000006C3 8936[8904]              	MOV	WORD PTR [IOCNT],SI
  1523 000006C7 893E[8B04]              	MOV	WORD PTR [IOCNT+2],DI
  1524 000006CB E88400                  	CALL	GOTTARG
  1525 000006CE 72E7                    	retc
  1526 000006D0 EB11                    	JMP	SHORT COMDONE
  1527                                  
  1528                                  GOTALLCOM:
  1529 000006D2 06                      	push	es
  1530 000006D3 C436[0605]              	LES	SI,[command + fileSizeInBytes]
  1531 000006D7 8CC7                    	MOV	DI,ES
  1532 000006D9 07                      	pop	es
  1533 000006DA 1E                      	push	ds
  1534 000006DB 8E1E[0E05]              	MOV	DS,[command + fileStartSegment]
  1535                                  	assume	ds:nothing
  1536 000006DF E82802                  	CALL	WRITEFILE
  1537 000006E2 1F                      	pop	ds
  1538                                  	assume	ds:data
  1539                                  COMDONE:
  1540 000006E3 8B1E[9104]              	MOV	BX,[TempHandle]
  1541 000006E7 8B0E[1205]              	MOV	CX,[command + fileTime]
  1542 000006EB 8B16[1005]              	MOV	DX,[command + fileDate]
  1543 000006EF E84600                  	CALL	CLOSETARG
  1544                                  ;****************************************************************
  1545                                  ; I don't see the need for the following code!! - RS 3.20
  1546                                  ;	CMP	BYTE PTR [FILSTAT],00101010B
  1547                                  ;	JZ	NOREDOS
  1548                                  ;RDFRST2:
  1549                                  ;	CALL	READDOS 		; Start back with BIOS
  1550                                  ;	JNC	NOREDOS
  1551                                  ;	CALL	SYSPRM			;Prompt for system disk
  1552                                  ;	JMP	RDFRST2 		;Try again
  1553                                  ;NOREDOS:
  1554                                  ;****************************************************************
  1555 000006F2 F8                      	CLC
  1556 000006F3 C3                      	return
  1557                                  
  1558                                  ;*********************************************
  1559                                  ; Create a file on target disk
  1560                                  ; CX = attributes, DX points to name
  1561                                  ; DI:SI is size file is to have
  1562                                  ;
  1563                                  ;   There is a bug in DOS 2.00 and 2.01 having to do with writes
  1564                                  ;   from the end of memory. In order to circumvent it this routine
  1565                                  ;   must create files with the length in DI:SI
  1566                                  ;
  1567                                  ; On return BX is handle, carry set if problem
  1568                                  
  1569                                  MAKEFIL:
  1570 000006F4 89D3                    	MOV	BX,DX
  1571 000006F6 FF37                    	PUSH	WORD PTR [BX]
  1572                                  DriveLetter equ driveLetter	; NASM port label
  1573 000006F8 A0[8306]                	MOV	AL,[DriveLetter]
  1574 000006FB 8807                    	MOV	[BX],AL
  1575                                  CREAT equ Creat	; NASM port equate
  1576 000006FD B43C                    	MOV	AH,CREAT
  1577 000006FF CD21                    	INT	21H
  1578 00000701 8F07                    	POP	WORD PTR [BX]
  1579 00000703 89C3                    	MOV	BX,AX
  1580 00000705 7219                    	JC	CheckMany
  1581 00000707 89F9                    	MOV	CX,DI
  1582 00000709 89F2                    	MOV	DX,SI
  1583 0000070B B80042                  	MOV	AX,LSEEK << 8
  1584 0000070E CD21                    	INT	21H				; Seek to eventual EOF
  1585 00000710 31C9                    	XOR	CX,CX
  1586                                  WRITE equ Write	; NASM port equate
  1587 00000712 B440                    	MOV	AH,WRITE
  1588 00000714 CD21                    	INT	21H				; Set size of file to position
  1589 00000716 31C9                    	XOR	CX,CX
  1590 00000718 89CA                    	MOV	DX,CX
  1591 0000071A B80042                  	MOV	AX,LSEEK << 8
  1592 0000071D CD21                    	INT	21H				; Seek back to start
  1593 0000071F C3                      	return
  1594                                  
  1595                                  ;
  1596                                  ; Examine error code in AX to see if it is too-many-open-files.
  1597                                  ; If it is, we abort right here. Otherwise we return.
  1598                                  ;
  1599                                  CheckMany:
  1600 00000720 83F804                  	CMP	AX,error_too_many_open_files
  1601 00000723 75FA                    	retnz
  1602 00000725 1EBA[ssss]8EDAA3-       	Extended_Message			;				;AC006;
  1602 0000072C [0000]BA[0000]E8-  
  1602 00000732 (0000)1F           
  1603 00000735 E9F3FB                  	JMP	FEXIT
  1604                                  
  1605                                  ;*********************************************
  1606                                  ; Close a file on the target disk
  1607                                  ; CX/DX is time/date, BX is handle
  1608                                  
  1609                                  CLOSETARG:
  1610                                  FILE_TIMES equ File_Times	; NASM port equate
  1611 00000738 B80157                  	MOV	AX,(FILE_TIMES << 8) | 1
  1612 0000073B CD21                    	INT	21H
  1613                                  CLOSE equ Close	; NASM port equate
  1614 0000073D B43E                    	MOV	AH,CLOSE
  1615 0000073F CD21                    	INT	21H
  1616 00000741 C3                      	return
  1617                                  
  1618                                  ;****************************************
  1619                                  ; Transfer system files
  1620                                  ; BP points to data structure for file involved
  1621                                  ; offset is set to current amount read in
  1622                                  ; Start set to start of file in buffer
  1623                                  ; TempHandle is handle to write to on target
  1624                                  
  1625                                  IOLOOP:
  1626 00000742 A0[8406]                	MOV	AL,[systemDriveLetter]
  1627 00000745 3A06[8306]              	CMP	AL,[DriveLetter]
  1628 00000749 7507                    	JNZ	GOTTARG
  1629 0000074B B40D                    	MOV	AH,DISK_RESET
  1630 0000074D CD21                    	INT	21H
  1631 0000074F E854FC                  	CALL	TARGPRM 			;Get target disk
  1632                                  
  1633                                  GOTTARG:
  1634                                  ASSUME	DS:DATA
  1635                                  ;Enter here if some of file is already in buffer, IOCNT must be set
  1636                                  ; to size already in buffer.
  1637 00000752 8B1E[9104]              	MOV	BX,[TempHandle]
  1638 00000756 8B36[8904]              	MOV	SI,WORD PTR [IOCNT]
  1639 0000075A 8B3E[8B04]              	MOV	DI,WORD PTR [IOCNT+2]
  1640 0000075E 1E                      	push	ds
  1641 0000075F 3E8E5E0C                	MOV	DS,[ds:BP + fileStartSegment]
  1642                                  	assume	ds:nothing
  1643 00000763 E8A401                  	CALL	WRITEFILE			; Write next part
  1644 00000766 1F                      	pop	ds
  1645                                  	assume	ds:data
  1646 00000767 72D8                    	retc
  1647                                  
  1648 00000769 06                      	push	es
  1649 0000076A 3EC44608                	LES	AX,[ds:BP + fileOffset]
  1650 0000076E 3E3B4604                	CMP	AX,WORD PTR [ds:BP + fileSizeInBytes]
  1651 00000772 750A                    	JNZ	GETSYS3
  1652 00000774 8CC0                    	MOV	AX,ES
  1653 00000776 3E3B4606                	CMP	AX,WORD PTR [ds:BP + fileSizeInBytes+2]
  1654 0000077A 7502                    	JNZ	GETSYS3
  1655 0000077C 07                      	pop	es
  1656 0000077D C3                      	return					; Carry clear from CMP
  1657                                  
  1658                                  GETSYS3:
  1659                                  ;Enter here if none of file is in buffer
  1660 0000077E 07                      	pop	es
  1661 0000077F B40D                    	MOV	AH,DISK_RESET
  1662 00000781 CD21                    	INT	21H
  1663 00000783 A1[8D04]                	MOV	AX,[MSTART]			;Furthur IO done starting here
  1664 00000786 3E89460C                	MOV	[ds:BP + fileStartSegment],AX	;point to start of buffer
  1665 0000078A A0[8406]                	MOV	AL,[systemDriveLetter]		;see if we have system disk
  1666 0000078D 3A06[8306]              	CMP	AL,[DriveLetter]
  1667 00000791 7507                    	JNZ	TESTSYS
  1668                                  GSYS:
  1669 00000793 B40D                    	MOV	AH,DISK_RESET
  1670 00000795 CD21                    	INT	21H
  1671 00000797 E8BEFB                  	CALL	SYSPRM				;Prompt for system disk
  1672                                  TESTSYS:
  1673                                  ;	CALL	TESTSYSDISK			; dcl 8/23/86
  1674 0000079A 72F7                    	JC	GSYS
  1675 0000079C 3E8B5E00                	MOV	BX,word ptr [DS:BP + fileHandle]	; CS over ARR 2.30
  1676 000007A0 06                      	push	es
  1677 000007A1 3EC45608                	LES	DX,[DS:BP + fileOffset] ; CS over ARR 2.30
  1678 000007A5 8CC1                    	MOV	CX,ES
  1679 000007A7 07                      	pop	es
  1680 000007A8 52                      	PUSH	DX
  1681 000007A9 B80042                  	MOV	AX,LSEEK << 8
  1682 000007AC CD21                    	INT	21H
  1683 000007AE 5A                      	POP	DX
  1684 000007AF 06                      	push	es
  1685 000007B0 3EC47604                	LES	SI,[DS:BP + fileSizeInBytes] ; CS over ARR 2.30
  1686 000007B4 8CC7                    	MOV	DI,ES				;put high word in di
  1687 000007B6 07                      	pop	es
  1688 000007B7 29D6                    	SUB	SI,DX				;get low word value
  1689 000007B9 19CF                    	SBB	DI,CX				; DI:SI is #bytes to go
  1690 000007BB 57                      	PUSH	DI
  1691 000007BC 56                      	PUSH	SI
  1692 000007BD 83C60F                  	ADD	SI,15				;round up 1 para
  1693 000007C0 83D700                  	ADC	DI,0				;pick up carry
  1694 000007C3 E8B701                  	CALL	DISID4				;div 16 to get para count
  1695 000007C6 89F0                    	MOV	AX,SI				;put para count in ax
  1696 000007C8 5E                      	POP	SI				;restore bytes remaining
  1697 000007C9 5F                      	POP	DI				;restore bytes remaining
  1698 000007CA 3B06[8F04]              	CMP	AX,[MSIZE]			;enough memory to read remainder?
  1699 000007CE 7609                    	JBE	GOTSIZ2 			;yes
  1700 000007D0 8B36[8F04]              	MOV	SI,[MSIZE]
  1701 000007D4 31FF                    	XOR	DI,DI
  1702 000007D6 E89A01                  	CALL	DISIX4
  1703                                  GOTSIZ2:
  1704 000007D9 8936[8904]              	MOV	WORD PTR [IOCNT],SI		;save byte count for read
  1705 000007DD 893E[8B04]              	MOV	WORD PTR [IOCNT+2],DI
  1706 000007E1 1E                      	push	ds
  1707 000007E2 8E1E[8D04]              	MOV	DS,[MSTART]
  1708                                  	assume	ds:nothing
  1709 000007E6 E81401                  	CALL	READFILE
  1710 000007E9 1F                      	pop	ds
  1711                                  	assume	ds:data
  1712 000007EA 7305                    	JNC	GETOFFS
  1713 000007EC E8BEFC                  	CALL	CLSALL
  1714 000007EF EBA2                    	JMP	GSYS
  1715                                  GETOFFS:
  1716 000007F1 31D2                    	XOR	DX,DX				;clear dx
  1717 000007F3 89D1                    	MOV	CX,DX				;clear cx
  1718 000007F5 B80142                  	MOV	AX,(LSEEK << 8) | 1
  1719 000007F8 CD21                    	INT	21H
  1720 000007FA 3E894608                	MOV	WORD PTR [DS:BP + fileOffset],AX	; CS over ARR 2.30
  1721 000007FE 3E89560A                	MOV	WORD PTR [DS:BP + fileOffset+2],DX ; CS over ARR 2.30
  1722                                  ;;;;;;	CALL	CLSALL
  1723 00000802 E93DFF                  	JMP	IOLOOP
  1724                                  
  1725                                  ;*************************************************
  1726                                  ; Test to see if correct system disk. Open handles
  1727                                  
  1728                                  CRET12:
  1729 00000805 F9                      	STC
  1730 00000806 C3                      	return
  1731                                  
  1732                                  ;TESTSYSDISK:					; dcl 8/23/86
  1733                                  Get_BIOS:					; dcl 8/23/86
  1734                                  OPEN equ Open	; NASM port equate
  1735 00000807 B8003D                  	MOV	AX,OPEN << 8
  1736 0000080A BA[0000]                	MOV	DX,OFFSET BiosFile
  1737 0000080D CD21                    	INT	21H
  1738 0000080F 7303                    	JNC	SETBIOS
  1739                                  ;	call	CheckMany			; dcl 8/23/86
  1740 00000811 E90CFF                  	jmp	CheckMany			; dcl 8/23/86
  1741                                  
  1742                                  SETBIOS:
  1743                                  Bios equ bios	; NASM port label
  1744 00000814 A3[DE04]                	MOV	[Bios + fileHandle],AX
  1745 00000817 89C3                    	MOV	BX,AX
  1746 00000819 E8B000                  	CALL	GETFSIZ
  1747 0000081C 833E[E004]00            	CMP	word [bios + fileSizeInParagraphs],0
  1748 00000821 740F                    	JZ	SETBIOSSIZ
  1749 00000823 3906[E004]              	CMP	[bios + fileSizeInParagraphs],AX
  1750 00000827 7409                    	JZ	SETBIOSSIZ
  1751                                  BIOSCLS:
  1752 00000829 B43E                    	MOV	AH,CLOSE
  1753 0000082B 8B1E[DE04]              	MOV	BX,[Bios + fileHandle]
  1754 0000082F CD21                    	INT	21H
  1755                                  ;	JMP	CRET12		       ; dcl 8/23/86
  1756 00000831 C3                      	ret
  1757                                  
  1758                                  SETBIOSSIZ:
  1759 00000832 A3[E004]                	MOV	[bios + fileSizeInParagraphs],AX
  1760 00000835 8936[E204]              	MOV	WORD PTR [bios + fileSizeInBytes],SI
  1761 00000839 893E[E404]              	MOV	WORD PTR [bios + fileSizeInBytes+2],DI
  1762 0000083D 8916[EC04]              	MOV	[bios + fileDate],DX
  1763 00000841 890E[EE04]              	MOV	[bios + fileTime],CX
  1764 00000845 F8                      	clc
  1765 00000846 C3                      	ret					; dcl 8/23/86
  1766                                  
  1767                                  Get_DOS:					; dcl 8/23/86
  1768 00000847 B8003D                  	MOV	AX,OPEN << 8
  1769 0000084A BA[0000]                	MOV	DX,OFFSET DosFile
  1770 0000084D CD21                    	INT	21H
  1771 0000084F 7303                    	JNC	DOSOPNOK
  1772                                  ;	call	CheckMany			; dcl 8/23/86
  1773                                  ;	JMP	BIOSCLS 			; dcl 8/23/86  Checkmany no ret.
  1774 00000851 E9CCFE                  	jmp	CheckMany			; dcl 8/23/86
  1775                                  
  1776                                  DOSOPNOK:
  1777 00000854 A3[F004]                	MOV	[dos + fileHandle],AX
  1778 00000857 89C3                    	MOV	BX,AX
  1779 00000859 E87000                  	CALL	GETFSIZ
  1780 0000085C 833E[F204]00            	CMP	word [dos + fileSizeInParagraphs],0
  1781 00000861 740F                    	JZ	SETDOSSIZ
  1782 00000863 3906[F204]              	CMP	[dos + fileSizeInParagraphs],AX
  1783 00000867 7409                    	JZ	SETDOSSIZ
  1784                                  
  1785                                  DOSCLS:
  1786 00000869 B43E                    	MOV	AH,CLOSE
  1787 0000086B 8B1E[F004]              	MOV	BX,[dos + fileHandle]
  1788 0000086F CD21                    	INT	21H
  1789                                  ;	JMP	BIOSCLS 		; dcl 8/23/86
  1790 00000871 C3                      	ret					; dcl 8/23/86
  1791                                  
  1792                                  SETDOSSIZ:
  1793 00000872 A3[F204]                	MOV	[dos + fileSizeInParagraphs],AX
  1794 00000875 8936[F404]              	MOV	WORD PTR [dos + fileSizeInBytes],SI
  1795 00000879 893E[F604]              	MOV	WORD PTR [dos + fileSizeInBytes+2],DI
  1796 0000087D 8916[FE04]              	MOV	[dos + fileDate],DX
  1797 00000881 890E[0005]              	MOV	[dos + fileTime],CX
  1798 00000885 F8                      	clc
  1799 00000886 C3                      	ret					; dcl 8/23/86
  1800                                  
  1801                                  
  1802                                  
  1803                                  Get_COMMAND:
  1804 00000887 B8003D                  	MOV	AX,OPEN << 8
  1805 0000088A BA[1405]                	MOV	DX,OFFSET CommandFile
  1806 0000088D CD21                    	INT	21H
  1807 0000088F 7303                    	JNC	GotComHand
  1808                                  ;	call	CheckMany		; dcl 8/23/86
  1809                                  ;	JMP	DosCls			; dcl 8/23/86
  1810                                  Checkmany equ CheckMany	; NASM port label
  1811 00000891 E98CFE                  	jmp	Checkmany			; dcl 8/23/86
  1812                                  
  1813                                  GotComHand:
  1814 00000894 A3[0205]                	MOV	[command + fileHandle],AX
  1815 00000897 89C3                    	MOV	BX,AX
  1816 00000899 E83000                  	CALL	GETFSIZ
  1817 0000089C 833E[0405]00            	CMP	word [command + fileSizeInParagraphs],0
  1818 000008A1 740F                    	JZ	SETCOMSIZ
  1819 000008A3 3906[0405]              	CMP	[command + fileSizeInParagraphs],AX
  1820 000008A7 7409                    	JZ	SETCOMSIZ
  1821                                  COMCLS:
  1822 000008A9 B43E                    	MOV	AH,CLOSE
  1823 000008AB 8B1E[0205]              	MOV	BX,[command + fileHandle]
  1824 000008AF CD21                    	INT	21H
  1825                                  ;	JMP	DOSCLS			; dcl 8/23/86
  1826 000008B1 C3                      	ret					; dcl 8/23/86
  1827                                  
  1828                                  SETCOMSIZ:
  1829 000008B2 A3[0405]                	MOV	[command + fileSizeInParagraphs],AX
  1830 000008B5 8936[0605]              	MOV	WORD PTR [command + fileSizeInBytes],SI
  1831 000008B9 893E[0805]              	MOV	WORD PTR [command + fileSizeInBytes+2],DI
  1832 000008BD 8916[1005]              	MOV	[command + fileDate],DX
  1833 000008C1 890E[1205]              	MOV	[command + fileTime],CX
  1834 000008C5 F8                      	CLC
  1835 000008C6 C3                      	return
  1836                                  
  1837                                  FILE_CLS:					; dcl 8/23/86
  1838 000008C7 B43E                    	MOV	AH,CLOSE			; dcl 8/23/86
  1839 000008C9 CD21                    	INT	21H				; dcl 8/23/86
  1840 000008CB C3                      	ret					; dcl 8/23/86
  1841                                  
  1842                                  ;*******************************************
  1843                                  ; Handle in BX, return file size in para in AX
  1844                                  ; File size in bytes DI:SI, file date in DX, file
  1845                                  ; time in CX.
  1846                                  
  1847                                  GETFSIZ:
  1848 000008CC B80242                  	MOV	AX,(LSEEK << 8) | 2
  1849 000008CF 31C9                    	XOR	CX,CX
  1850 000008D1 89CA                    	MOV	DX,CX
  1851 000008D3 CD21                    	INT	21H
  1852 000008D5 89C6                    	MOV	SI,AX
  1853 000008D7 89D7                    	MOV	DI,DX
  1854 000008D9 83C00F                  	ADD	AX,15				; Para round up
  1855 000008DC 83D200                  	ADC	DX,0
  1856 000008DF 83E20F                  	AND	DX,0FH				; If the file is larger than this it
  1857                                  						; is bigger than the 8086 address
  1858                                  						; space!
  1859 000008E2 B10C                    	MOV	CL,12
  1860 000008E4 D3E2                    	SHL	DX,CL
  1861 000008E6 B104                    	MOV	CL,4
  1862 000008E8 D3E8                    	SHR	AX,CL
  1863 000008EA 09D0                    	OR	AX,DX
  1864 000008EC 50                      	PUSH	AX
  1865 000008ED B80042                  	MOV	AX,LSEEK << 8
  1866 000008F0 31C9                    	XOR	CX,CX
  1867 000008F2 89CA                    	MOV	DX,CX
  1868 000008F4 CD21                    	INT	21H
  1869 000008F6 B80057                  	MOV	AX,FILE_TIMES << 8
  1870 000008F9 CD21                    	INT	21H
  1871 000008FB 58                      	POP	AX
  1872 000008FC C3                      	return
  1873                                  
  1874                                  ;********************************************
  1875                                  ; Read/Write file
  1876                                  ;	DS:0 is Xaddr
  1877                                  ;	DI:SI is byte count to I/O
  1878                                  ;	BX is handle
  1879                                  ; Carry set if screw up
  1880                                  ;
  1881                                  ; I/O SI bytes
  1882                                  ; I/O 64K - 1 bytes DI times
  1883                                  ; I/O DI bytes
  1884                                  
  1885                                  
  1886                                  READFILE:
  1887                                  ; Must preserve AX,DX
  1888 000008FD 50                      	PUSH	AX
  1889 000008FE 52                      	PUSH	DX
  1890 000008FF 55                      	PUSH	BP
  1891                                  READ equ Read	; NASM port equate
  1892 00000900 BD003F                  	MOV	BP,READ << 8
  1893 00000903 E80D00                  	CALL	FILIO
  1894 00000906 5D                      	POP	BP
  1895 00000907 5A                      	POP	DX
  1896 00000908 58                      	POP	AX
  1897 00000909 C3                      	return
  1898                                  
  1899                                  WRITEFILE:
  1900 0000090A 55                      	PUSH	BP
  1901 0000090B BD0040                  	MOV	BP,WRITE << 8
  1902 0000090E E80200                  	CALL	FILIO
  1903 00000911 5D                      	POP	BP
  1904 00000912 C3                      	return
  1905                                  
  1906                                  FILIO:
  1907 00000913 31D2                    	XOR	DX,DX
  1908 00000915 89F1                    	MOV	CX,SI
  1909 00000917 E30F                    	JCXZ	K64IO
  1910 00000919 89E8                    	MOV	AX,BP
  1911 0000091B CD21                    	INT	21H
  1912 0000091D 72F3                    	retc
  1913 0000091F 01C2                    	ADD	DX,AX
  1914 00000921 39C8                    	CMP	AX,CX				; If not =, AX<CX, carry set.
  1915 00000923 75ED                    	retnz
  1916 00000925 E85F00                  	CALL	NORMALIZE
  1917                                  K64IO:
  1918 00000928 F8                      	CLC
  1919 00000929 89F9                    	MOV	CX,DI
  1920 0000092B E345                    	JCXZ	IORET
  1921 0000092D 89E8                    	MOV	AX,BP
  1922 0000092F CD21                    	INT	21H
  1923 00000931 72DF                    	retc
  1924 00000933 01C2                    	ADD	DX,AX
  1925 00000935 39C8                    	CMP	AX,CX				; If not =, AX<CX, carry set.
  1926 00000937 75D9                    	retnz
  1927 00000939 E84B00                  	CALL	NORMALIZE
  1928 0000093C 89F9                    	MOV	CX,DI
  1929                                  K64M1:
  1930 0000093E 51                      	PUSH	CX
  1931 0000093F 31C0                    	XOR	AX,AX
  1932 00000941 09D2                    	OR	DX,DX
  1933 00000943 7414                    	JZ	NORMIO
  1934 00000945 B91000                  	MOV	CX,10H
  1935 00000948 29D1                    	SUB	CX,DX
  1936 0000094A 89E8                    	MOV	AX,BP
  1937 0000094C CD21                    	INT	21H
  1938 0000094E 7221                    	JC	IORETP
  1939 00000950 01C2                    	ADD	DX,AX
  1940 00000952 39C8                    	CMP	AX,CX				; If not =, AX<CX, carry set.
  1941 00000954 751B                    	JNZ	IORETP
  1942 00000956 E82E00                  	CALL	NORMALIZE
  1943                                  NORMIO:
  1944 00000959 B9FFFF                  	MOV	CX,0FFFFH
  1945 0000095C 29C1                    	SUB	CX,AX
  1946 0000095E 89E8                    	MOV	AX,BP
  1947 00000960 CD21                    	INT	21H
  1948 00000962 720D                    	JC	IORETP
  1949 00000964 01C2                    	ADD	DX,AX
  1950 00000966 39C8                    	CMP	AX,CX				; If not =, AX<CX, carry set.
  1951 00000968 7507                    	JNZ	IORETP
  1952 0000096A E81A00                  	CALL	NORMALIZE			; Clears carry
  1953 0000096D 59                      	POP	CX
  1954 0000096E E2CE                    	LOOP	K64M1
  1955 00000970 51                      	PUSH	CX
  1956                                  IORETP:
  1957 00000971 59                      	POP	CX
  1958                                  IORET:
  1959 00000972 C3                      	return
  1960                                  
  1961                                  
  1962                                  ;*********************************
  1963                                  ; Shift DI:SI left 4 bits
  1964                                  DISIX4:
  1965 00000973 B90400                  	MOV	CX,4
  1966                                  SH32:
  1967 00000976 D1E6                    	SHL	SI,1
  1968 00000978 D1D7                    	RCL	DI,1
  1969 0000097A E2FA                    	LOOP	SH32
  1970 0000097C C3                      	return
  1971                                  
  1972                                  ;*********************************
  1973                                  ; Shift DI:SI right 4 bits
  1974                                  DISID4:
  1975 0000097D B90400                  	MOV	CX,4
  1976                                  SH32B:
  1977 00000980 D1EF                    	SHR	DI,1
  1978 00000982 D1DE                    	RCR	SI,1
  1979 00000984 E2FA                    	LOOP	SH32B
  1980 00000986 C3                      	return
  1981                                  
  1982                                  ;********************************
  1983                                  ; Normalize DS:DX
  1984                                  
  1985                                  NORMALIZE:
  1986 00000987 52                      	PUSH	DX
  1987 00000988 50                      	PUSH	AX
  1988 00000989 D1EA                    	SHR	DX,1
  1989 0000098B D1EA                    	SHR	DX,1
  1990 0000098D D1EA                    	SHR	DX,1
  1991 0000098F D1EA                    	SHR	DX,1
  1992 00000991 8CD8                    	MOV	AX,DS
  1993 00000993 01D0                    	ADD	AX,DX
  1994 00000995 8ED8                    	MOV	DS,AX
  1995 00000997 58                      	POP	AX
  1996 00000998 5A                      	POP	DX
  1997 00000999 83E20F                  	AND	DX,0FH				; Clears carry
  1998 0000099C C3                      	return
  1999                                  
  2000                                  ;-------------------------------------------------------------------------------
  2001                                  ; Phase1Initialisation:
  2002                                  ;    This routine MUST set up fatSpace, and fBigFat
  2003                                  ;    It also does most of the other initialisation
  2004                                  ;
  2005                                  ;    Algorithm:
  2006                                  ;	Open a handle for accessing the drive
  2007                                  ;	Get device parameters
  2008                                  ;	save device parameters for exit
  2009                                  ;	Check switches against parameters
  2010                                  ;	Use switches to modify device parameters
  2011                                  ;	directorySector = malloc( Bytes Per Sector )
  2012                                  ;	fatSpace = malloc( Bytes Per Sector * Sectors Per Fat )
  2013                                  ;	Calculate start sector (first sector not used by DOS)
  2014                                  ;	fBigFat = (((Total Sectors - StartSector)/Sectors Per Cluster) >= 4086)
  2015                                  ;
  2016                                  Phase1Initialisation proc near
  2017                                  
  2018                                  ; Get device parameters
  2019 0000099D 8D16[2501]              	lea	dx, [deviceParameters]
  2020 000009A1 C606[2501]00            	mov	byte [deviceParameters + DP_SpecialFunctions], 0
  2021 000009A6 E87201                  	call	GetDeviceParameters
  2022 000009A9 7309                    	jnc	GotDeviceParameters
  2023 000009AB BA[0000]E8(0000)        	Message msgFormatNotSupported		;				;AC000;
  2024                                  						;lea	 dx, ptr_msgFormatNotSupported
  2025                                  						;call	 std_printf
  2026                                  fexit equ FEXIT	; NASM port label
  2027 000009B1 E977F9                  	jmp	fexit
  2028                                  GotDeviceParameters:
  2029                                  
  2030                                  ; Save the device parameters for when we exit
  2031 000009B4 8D36[2501]              	lea	si, [deviceParameters]
  2032 000009B8 8D3E[0100]              	lea	di, [savedDeviceParameters]
  2033                                  a_DeviceParameters_struc_size equ A_DEVICEPARAMETERS_struc_size	; NASM port equate
  2034 000009BC B92401                  	mov	cx, a_DeviceParameters_struc_size
  2035 000009BF 1E                      	push	ds
  2036 000009C0 07                      	pop	es
  2037 000009C1 F3A4                    	rep	movsb
  2038                                  
  2039                                  ; Ensure that there is a valid number of sectors in the track table
  2040                                  DP_TrackTableEntries equ DP_TRACKTABLEENTRIES	; NASM port equate
  2041 000009C3 C706[2700]0000          	mov	word [savedDeviceParameters + DP_TrackTableEntries], 0
  2042 000009C9 C606[0000]01            	mov	byte [validSavedDeviceParameters], 1
  2043                                  
  2044                                  ; Initialise this to zero to know if CheckSwitches defined the track layout
  2045 000009CE C706[4B01]0000          	mov	word [deviceParameters + DP_TrackTableEntries], 0
  2046                                  
  2047 000009D4 E82D06                  	call	Set_BPB_Info				;an000; dms; Check to see if we are on
  2048                                  							; FAT system.  If not set BPB to proper
  2049                                  							; values for format.
  2050                                  SetMTsupp:
  2051                                  
  2052                                  ; Check switches against parameters and use switches to modify device parameters
  2053 000009D7 E8(0000)                	call	CheckSwitches
  2054 000009DA 72C0                    	retc
  2055                                  
  2056                                  DeviceParameters equ deviceParameters	; NASM port label
  2057                                  %IF ShipDisk
  2058                                  
  2059                                  Switch_Z equ SWITCH_Z	; NASM port equate
  2060                                  	test	word [SwitchMap],Switch_Z						;an000; dms;1 sector/cluster disk?
  2061                                  ;	$if	nz								;an000; dms;yes
  2062                                  	JZ DD_IF19
  2063                                  		mov	byte [DeviceParameters + DP_BPB + BPB_SectorsPerCluster],01h	;an000; dms;set BPB accordingly
  2064                                  Calc_Small_Fat equ Calc_Small_FAT	; NASM port label
  2065                                  		call	Calc_Small_Fat						;an000; dms;calc FAT size
  2066                                  ;	$endif									;an000; dms;
  2067                                  DD_IF19:
  2068                                  
  2069                                  %ENDIF
  2070                                  
  2071                                  
  2072 000009DC 833E[4B01]00            	cmp	word [deviceParameters + DP_TrackTableEntries], 0
  2073 000009E1 751A                    	jne	TrackLayoutSet			; There is a good track layout
  2074                                  
  2075                                  ; Store sector table info
  2076                                  BPB_SectorsPerTrack equ BPB_SECTORSPERTRACK	; NASM port equate
  2077 000009E3 8B0E[3901]              	mov	cx, [deviceParameters + DP_BPB + BPB_SectorsPerTrack]
  2078 000009E7 890E[4B01]              	mov	[deviceParameters + DP_TrackTableEntries], cx
  2079 000009EB B80100                  	mov	ax, 1
  2080                                  BPB_bytesPerSector equ BPB_BYTESPERSECTOR	; NASM port equate
  2081 000009EE 8B1E[2C01]              	mov	bx, [deviceParameters + DP_BPB + BPB_bytesPerSector]
  2082                                  DP_SectorTable equ DP_SECTORTABLE	; NASM port equate
  2083 000009F2 8D3E[4D01]              	lea	di, [deviceParameters + DP_SectorTable]
  2084                                  LoadSectorTable:
  2085 000009F6 AB                      	stosw
  2086 000009F7 93                      	xchg	ax, bx
  2087 000009F8 AB                      	stosw
  2088 000009F9 93                      	xchg	ax, bx
  2089 000009FA 40                      	inc	ax
  2090 000009FB E2F9                    	loop	LoadSectorTable
  2091                                  TrackLayoutSet:
  2092                                  
  2093                                  ;
  2094                                  ; directorySector = malloc( Bytes Per Sector )
  2095                                  ;
  2096 000009FD 8B1E[2C01]              	mov	bx, [deviceParameters + DP_BPB + BPB_BytesPerSector]
  2097 00000A01 83C30F                  	add	bx, 0fH
  2098 00000A04 D1EB                    	shr	bx, 1
  2099 00000A06 D1EB                    	shr	bx, 1
  2100 00000A08 D1EB                    	shr	bx, 1
  2101 00000A0A D1EB                    	shr	bx, 1
  2102 00000A0C B448                    	mov	ah, Alloc
  2103 00000A0E CD21                    	int	21H
  2104 00000A10 728A                    	retc
  2105 00000A12 A3[7E04]                	mov	word ptr [directorySector+2], ax
  2106 00000A15 31C0                    	xor	ax,ax
  2107 00000A17 A3[7C04]                	mov	word ptr [directorySector], ax
  2108                                  
  2109                                  ;
  2110                                  ; fatSpace = malloc( Bytes Per Sector * Sectors Per FAT )
  2111                                  ;
  2112 00000A1A A1[2C01]                	mov	ax, [deviceParameters + DP_BPB + BPB_BytesPerSector]
  2113 00000A1D 83C00F                  	add	ax, 0fH
  2114 00000A20 D1E8                    	shr	ax, 1
  2115 00000A22 D1E8                    	shr	ax, 1
  2116 00000A24 D1E8                    	shr	ax, 1
  2117 00000A26 D1E8                    	shr	ax, 1
  2118                                  BPB_SectorsPerFAT equ BPB_SECTORSPERFAT	; NASM port equate
  2119 00000A28 F726[3701]              	mul	word [deviceParameters + DP_BPB + BPB_SectorsPerFAT]
  2120 00000A2C A3[DA04]                	mov	[Paras_Per_Fat],ax				;AN005;128k FAT
  2121 00000A2F 89C3                    	mov	bx,ax
  2122 00000A31 B448                    	mov	ah,Alloc
  2123 00000A33 CD21                    	int	21H
  2124 00000A35 72D9                    	retc
  2125 00000A37 A3[6304]                	mov	word ptr [fatSpace+2],ax
  2126 00000A3A 31C0                    	xor	ax,ax
  2127 00000A3C A3[6104]                	mov	word ptr [fatSpace],ax
  2128                                  
  2129 00000A3F E80500                  	call	SetStartSector
  2130 00000A42 E82B00                  	call	SetfBigFat
  2131                                  
  2132 00000A45 F8                      	clc
  2133 00000A46 C3                      	return
  2134                                  
  2135                                  Phase1Initialisation endp
  2136                                  
  2137                                  ;-------------------------------------------------------------------------------
  2138                                  
  2139                                  SetStartSector proc near
  2140                                  
  2141                                  ; startSector = number of reserved sectors
  2142                                  ;	 + number of FAT Sectors	( Number of FATS * Sectors Per FAT )
  2143                                  ;	 + number of directory sectors	( 32* Root Entries / bytes Per Sector )
  2144                                  ;					( above is rounded up )
  2145                                  
  2146                                  ; Calculate the number of directory sectors
  2147                                  BPB_RootEntries equ BPB_ROOTENTRIES	; NASM port equate
  2148 00000A47 A1[3201]                	mov	ax, [deviceParameters + DP_BPB + BPB_RootEntries]
  2149 00000A4A BB2000                  	mov	bx, dir_entry_struc_size
  2150 00000A4D F7E3                    	mul	bx
  2151 00000A4F 0306[2C01]              	add	ax, [deviceParameters + DP_BPB + BPB_bytesPerSector]
  2152 00000A53 48                      	dec	ax
  2153 00000A54 31D2                    	xor	dx,dx
  2154 00000A56 F736[2C01]              	div	word [deviceParameters + DP_BPB + BPB_bytesPerSector]
  2155 00000A5A A3[7A04]                	mov	[sectorsInRootDirectory],ax
  2156 00000A5D A3[5F04]                	mov	[startSector], ax
  2157                                  
  2158                                  ; Calculate the number of FAT sectors
  2159 00000A60 A1[3701]                	mov	ax, [deviceParameters + DP_BPB + BPB_SectorsPerFAT]
  2160                                  BPB_numberOfFATs equ BPB_NUMBEROFFATS	; NASM port equate
  2161 00000A63 F626[3101]              	mul	byte [deviceParameters + DP_BPB + BPB_numberOfFATs]
  2162                                  ; Add in the number of boot sectors
  2163                                  BPB_ReservedSectors equ BPB_RESERVEDSECTORS	; NASM port equate
  2164 00000A67 0306[2F01]              	add	ax, [deviceParameters + DP_BPB + BPB_ReservedSectors]
  2165 00000A6B 0106[5F04]              	add	[startSector], ax
  2166                                  
  2167 00000A6F C3                      	return
  2168                                  
  2169                                  SetStartSector endp
  2170                                  
  2171                                  ;-------------------------------------------------------------------------------
  2172                                  
  2173                                  SetfBigFat proc near
  2174                                  ;
  2175                                  ; fBigFat = ( ( (Total Sectors - Start Sector) / Sectors Per Cluster) >= 4086 )
  2176                                  ;
  2177                                  BPB_BigTotalSectors equ BPB_BIGTOTALSECTORS	; NASM port equate
  2178 00000A70 833E[4301]00            	cmp	word [deviceParameters + DP_BPB + BPB_BigTotalSectors+2],0 ; > 32mb part?	;AN000;
  2179                                  ;	$IF	NE				;Yes, big FAT	;AC000;
  2180 00000A75 7407                    	JE DD_IF21
  2181 00000A77 C606[6504]FF            	   mov	   byte [fBigFat], TRUE		;Set flag	;AN000;
  2181          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  2182                                  ;	$ELSE					;Nope, < 32,b	 ;AC000;
  2183 00000A7C EB23                    	JMP SHORT DD_EN21
  2184                                  DD_IF21:
  2185 00000A7E A1[4101]                	   mov	   ax,[deviceParameters + DP_BPB + BPB_BigTotalSectors] ;Assume this used ;AN000;
  2186 00000A81 83F800                  	   cmp	   ax,0 			;Was this field used?		 ;AN000;
  2187                                  ;	   $IF	   E				;Nope, use the other sector field;AN000;
  2188 00000A84 7503                    	   JNE DD_IF23
  2189                                  BPB_TotalSectors equ BPB_TOTALSECTORS	; NASM port equate
  2190 00000A86 A1[3401]                	      mov     ax, [deviceParameters + DP_BPB + BPB_TotalSectors] ;		      ;AC000;
  2191                                  						;** Fix for PTM PCDOS P51
  2192                                  ;	   $ENDIF				;				;AN000;
  2193                                  DD_IF23:
  2194 00000A89 2B06[5F04]              	   sub	   ax,[startSector]		;Get sectors in data area
  2195 00000A8D 31D2                    	   xor	   dx,dx
  2196 00000A8F 31DB                    	   xor	   bx,bx
  2197                                  BPB_sectorsPerCluster equ BPB_SECTORSPERCLUSTER	; NASM port equate
  2198 00000A91 8A1E[2E01]              	   mov	   bl,[deviceParameters + DP_BPB + BPB_sectorsPerCluster]
  2199 00000A95 F7F3                    	   div	   bx				;Get total clusters
  2200 00000A97 3DF60F                  	   cmp	   ax,BIG_FAT_THRESHOLD 	;Is clusters >= 4086?
  2201                                  ;	   $IF	   AE
  2202 00000A9A 7205                    	   JNAE DD_IF25
  2203                                  fBigFAT equ fBigFat	; NASM port label
  2204 00000A9C C606[6504]FF            	      mov     byte [fBigFAT],TRUE		;16 bit FAT if >=4096
  2204          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  2205                                  						;** END fix for PTM PCDOS P51
  2206                                  ;	   $ENDIF
  2207                                  DD_IF25:
  2208                                  ;	$ENDIF
  2209                                  DD_EN21:
  2210 00000AA1 C3                      	return
  2211                                  
  2212                                  SetfBigFat endp
  2213                                  
  2214                                  ;-------------------------------------------------------------------------------
  2215                                  ;
  2216                                  ;    Phase2Initialisation:
  2217                                  ;	Use device parameters to build information that will be
  2218                                  ;	required for each format
  2219                                  ;
  2220                                  ;    Algorithm:
  2221                                  ;	Calculate first head/cylinder to format
  2222                                  ;	Calculate number of tracks to format
  2223                                  ;	Calculate the total bytes on the disk and save for later printout
  2224                                  ;	First initialise the directory buffer
  2225                                  ;
  2226                                  Phase2Initialisation proc near
  2227                                  
  2228                                  ; Calculate first track/head to format (round up - kludge)
  2229                                  BPB_HiddenSectors equ BPB_HIDDENSECTORS	; NASM port equate
  2230 00000AA2 A1[3D01]                	mov	ax, [deviceParameters + DP_BPB + BPB_HiddenSectors]
  2231 00000AA5 8B16[3F01]              	mov	dx, [deviceParameters + DP_BPB + BPB_HiddenSectors + 2]
  2232 00000AA9 0306[3901]              	add	ax, [deviceParameters + DP_BPB + BPB_SectorsPerTrack]
  2233 00000AAD 83D200                  	adc	dx, 0
  2234 00000AB0 48                      	dec	ax
  2235 00000AB1 83DA00                  	sbb	dx, 0
  2236 00000AB4 F736[3901]              	div	word [deviceParameters + DP_BPB + BPB_SectorsPerTrack]
  2237 00000AB8 31D2                    	xor	dx,dx
  2238                                  BPB_Heads equ BPB_HEADS	; NASM port equate
  2239 00000ABA F736[3B01]              	div	word [deviceParameters + DP_BPB + BPB_Heads]
  2240 00000ABE A3[6804]                	mov	[firstCylinder], ax
  2241 00000AC1 8916[6604]              	mov	[firstHead], dx
  2242                                  
  2243                                  ; Calculate the total number of tracks to be formatted (round down - kludge)
  2244 00000AC5 A1[3401]                	mov	ax, [deviceParameters + DP_BPB + BPB_TotalSectors]
  2245 00000AC8 31D2                    	xor	dx,dx
  2246                                  ; if (TotalSectors == 0) then use BigTotalSectors
  2247 00000ACA 09C0                    	or	ax,ax
  2248 00000ACC 7507                    	jnz	NotBigTotalSectors
  2249 00000ACE A1[4101]                	mov	ax, [deviceParameters + DP_BPB + BPB_BigTotalSectors]
  2250 00000AD1 8B16[4301]              	mov	dx, [deviceParameters + DP_BPB + BPB_BigTotalSectors + 2]
  2251                                  
  2252                                  NotBigTotalSectors:
  2253 00000AD5 F736[3901]              	div	word [deviceParameters + DP_BPB + BPB_SectorsPerTrack]
  2254 00000AD9 A3[6C04]                	mov	[tracksPerDisk], ax
  2255                                  
  2256                                  ; Initialise the directory buffer
  2257                                  ; Clear out the Directory Sector before any information is inserted.
  2258 00000ADC 8B0E[2C01]              	mov	cx, [deviceParameters + DP_BPB + BPB_BytesPerSector]
  2259 00000AE0 C43E[7C04]              	les	di, [directorySector]
  2260 00000AE4 31C0                    	xor	ax,ax
  2261 00000AE6 F3AA                    	rep	stosb
  2262                                  
  2263 00000AE8 A1[2C01]                	mov	ax, [deviceParameters + DP_BPB + BPB_BytesPerSector]
  2264 00000AEB 31D2                    	xor	dx, dx
  2265 00000AED BB2000                  	mov	bx, dir_entry_struc_size
  2266 00000AF0 F7F3                    	div	bx
  2267 00000AF2 89C1                    	mov	cx, ax
  2268                                  
  2269 00000AF4 C41E[7C04]              	les	bx, [directorySector]
  2270                                  ; If Old_Dir = TRUE then put the first letter of each directory entry must be 0E5H
  2271 00000AF8 30C0                    	xor	al, al
  2272                                  old_Dir equ Old_Dir	; NASM port label
  2273 00000AFA 803E[7804]FF            	cmp	byte [old_Dir], TRUE
  2273          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  2274 00000AFF 7502                    	jne	StickE5
  2275 00000B01 B0E5                    	mov	al, 0e5H
  2276                                  StickE5:
  2277 00000B03 268807                  	mov	[es:bx], al
  2278 00000B06 83C320                  	add	bx, dir_entry_struc_size
  2279                                  stickE5 equ StickE5	; NASM port label
  2280 00000B09 E2F8                    	loop	stickE5
  2281                                  
  2282 00000B0B C3                      	ret
  2283                                  
  2284                                  Phase2Initialisation endp
  2285                                  
  2286                                  ;-------------------------------------------------------------------------------
  2287                                  ;
  2288                                  ;   SetDeviceParameters:
  2289                                  ;      Set the device parameters
  2290                                  ;
  2291                                  ;   Input:
  2292                                  ;      drive
  2293                                  ;      dx - pointer to device parameters
  2294                                  ;
  2295                                  SetDeviceParameters proc near
  2296                                  
  2297 00000B0C B80D44                  	mov	ax, (IOCTL << 8) | GENERIC_IOCTL
  2298 00000B0F 8A1E[8206]              	mov	bl, [drive]
  2299 00000B13 FEC3                    	inc	bl
  2300 00000B15 B94008                  	mov	cx, (RAWIO << 8) | SET_DEVICE_PARAMETERS
  2301 00000B18 CD21                    	int	21H
  2302 00000B1A C3                      	return
  2303                                  
  2304                                  SetDeviceParameters endp
  2305                                  
  2306                                  ;-------------------------------------------------------------------------------
  2307                                  ;
  2308                                  ;   GetDeviceParameters:
  2309                                  ;      Get the device parameters
  2310                                  ;
  2311                                  ;   Input:
  2312                                  ;      drive
  2313                                  ;      dx - pointer to device parameters
  2314                                  ;
  2315                                  GetDeviceParameters proc near
  2316                                  
  2317 00000B1B B80D44                  	mov	ax, (IOCTL << 8) | GENERIC_IOCTL
  2318 00000B1E 8A1E[8206]              	mov	bl, [drive]
  2319 00000B22 FEC3                    	inc	bl
  2320 00000B24 B96008                  	mov	cx, (RAWIO << 8) | GET_DEVICE_PARAMETERS
  2321 00000B27 CD21                    	int	21H
  2322 00000B29 C3                      	return
  2323                                  
  2324                                  GetDeviceParameters endp
  2325                                  
  2326                                  ;-------------------------------------------------------------------------------
  2327                                  ;
  2328                                  ;    DiskFormat:
  2329                                  ;	Format the tracks on the disk
  2330                                  ;	Since we do our SetDeviceParameters here, we also need to
  2331                                  ;	detect the legality of /N /T if present and abort with errors
  2332                                  ;	if not.
  2333                                  ;	This routine stops as soon as it encounters a bad track
  2334                                  ;	Then BadSector is called to report the bad track, and it continues
  2335                                  ;	the format
  2336                                  ;
  2337                                  ;    Algorithm:
  2338                                  ;	Initialise in memory FAT
  2339                                  ;	current track = first
  2340                                  ;	while not done
  2341                                  ;	   if format track fails
  2342                                  ;	      DiskFormatErrors = true
  2343                                  ;	      return
  2344                                  ;	   next track
  2345                                  
  2346                                  DiskFormat proc near
  2347                                  
  2348                                  
  2349                                  ;
  2350                                  ; Initialise fatSpace
  2351                                  ;
  2352                                  
  2353                                  
  2354 00000B2A 06                      	push	es
  2355                                  
  2356 00000B2B E8C803                  	call	Fat_Init			;an000; initialize the FAT
  2357                                  
  2358 00000B2E 8B3E[6304]              	mov	di, word ptr [fatspace+2] 	;an000; get segment of FAT
  2359 00000B32 8EC7                    	mov	es, di				;an000; place it in es
  2360 00000B34 8B3E[6104]              	mov	di, word ptr [fatSpace]		;Should be 0
  2361                                  BPB_MediaDescriptor equ BPB_MEDIADESCRIPTOR	; NASM port equate
  2362 00000B38 A0[3601]                	mov	al, [deviceParameters + DP_BPB + BPB_MediaDescriptor]
  2363 00000B3B B4FF                    	mov	ah, 0ffH
  2364 00000B3D AB                      	stosw
  2365 00000B3E B8FF00                  	mov	ax, 00ffH
  2366 00000B41 F606[6504]FF            	test	byte [fBigFat], TRUE
  2366          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  2367 00000B46 7403                    	jz	NotBig
  2368 00000B48 B8FFFF                  	mov	ax, 0ffffH
  2369 00000B4B AB                      NotBig: stosw
  2370 00000B4C 07                      	pop	es
  2371                                  
  2372                                  ; don't bother to do the formatting if /c was given
  2373 00000B4D F706[2006]0800          	test	word [switchmap], SWITCH_C
  2374 00000B53 7403                    	jz	Keep_Going
  2375 00000B55 E9D000                  	jmp	FormatDone			;FormatDone is to far away
  2376                                  
  2377                                  Keep_Going:
  2378                                  foofoo	equ	INSTALL_FAKE_BPB | TRACKLAYOUT_IS_GOOD
  2379 00000B58 C606[2501]05            	mov	byte [deviceParameters + DP_SpecialFunctions], foofoo
  2380 00000B5D 8D16[2501]              	lea	dx, [deviceParameters]
  2381                                  
  2382 00000B61 E8A8FF                  	call	SetDeviceParameters
  2383                                  
  2384 00000B64 E84007                  	call	Cluster_Buffer_Allocate 					;an000; dms;get room for retry buffer
  2385                                  
  2386 00000B67 E8F508                  	call	Prompt_User_For_Disk						;an016; dms;
  2387                                  
  2388                                  switch_8 equ SWITCH_8	; NASM port equate
  2389 00000B6A F706[2006]0001          	test	word [switchmap],switch_8		; DCL 5/12/86 avoid Naples AH=18h
  2390                                  stdBpB equ StdBPB	; NASM port label
  2391 00000B70 7561                    	jnz	stdBpB				; lackof support for 8 sectors/track
  2392                                  
  2393                                  						; DCL 5/12/86
  2394                                  						; Always do the STATUS_FOR_FORMAT test, as we don't know if the machine
  2395                                  						; has this support.  For 3.2 /N: & /T: were not documented & therefore
  2396                                  						; not fully supported thru the ROM of Aquarius & Naples & Royal Palm
  2397                                  
  2398                                  						;test	 SwitchMap, SWITCH_N or SWITCH_T	 ; IF ( /N or /T ) ;; DCL 5/12/86
  2399                                  						;jz	 StdBPB
  2400                                  						;   THEN check if
  2401                                  						;     supported
  2402                                  FP_SpecialFunctions equ FP_SPECIALFUNCTIONS	; NASM port equate
  2403 00000B72 C606[4B02]01            	mov	byte [formatPacket + FP_SpecialFunctions], STATUS_FOR_FORMAT
  2404 00000B77 B80D44                  	mov	ax, (IOCTL << 8) | GENERIC_IOCTL
  2405 00000B7A 8A1E[8206]              	mov	bl, [drive]
  2406 00000B7E FEC3                    	inc	bl
  2407 00000B80 B94208                  	mov	cx, (RAWIO << 8) | FORMAT_TRACK
  2408 00000B83 8D16[4B02]              	lea	dx, [formatPacket]
  2409 00000B87 CD21                    	int	21H
  2410                                  						; switch ( FormatStatusCall)
  2411                                  
  2412                                  						;cmp	 FormatPacket.FP_SpecialFunctions, Format_No_ROM_Support
  2413                                  						;jb	 NTSupported			 ; 0 returned from IBMBIO
  2414                                  						;ja	 IllegalComb			 ; 2 returned - ROM Support
  2415                                  						;   Illegal Combination!
  2416                                  FormatPacket equ formatPacket	; NASM port label
  2417 00000B89 803E[4B02]00            	cmp	byte [FormatPacket + FP_SpecialFunctions],0
  2418 00000B8E 7443                    	je	NTSupported
  2419 00000B90 803E[4B02]02            	cmp	byte [FormatPacket + FP_SpecialFunctions],2
  2420                                  ;	$IF	E				;				;AC000;
  2421 00000B95 750D                    	JNE DD_IF28
  2422 00000B97 BA[0000]E8(0000)        	   Message msgInvalidParameter		;				;AC000;
  2423                                  Yes equ YES	; NASM port equate
  2424 00000B9D C606[0000]FF            	   mov	   byte [Fatal_Error],Yes		;Indicate quittin'type err!     ;AN000;
  2425                                  ;	$ELSE					;				;     ;
  2426 00000BA2 EB25                    	JMP SHORT DD_EN28
  2427                                  DD_IF28:
  2428 00000BA4 803E[4B02]03            	   cmp	   byte [FormatPacket + FP_SpecialFunctions],3 ; 			   ;	 ;
  2429                                  ;	   $IF	   E				;				;AC000;
  2430 00000BA9 750B                    	   JNE DD_IF30
  2431                                  Error_Not_Ready equ error_not_ready	; NASM port equate
  2432 00000BAB B81500                  		   mov	   ax,Error_Not_Ready	;flag not ready 		;an000;dms;
  2433 00000BAE E82601                  		   call    CheckError		; set error level		;an017; dms;
  2434                                  FrmtProb equ FRMTPROB	; NASM port label
  2435 00000BB1 E90DF5                  		   jmp	   FrmtProb		; exit program			;an017; dms;
  2436                                  ;	   $ELSE				; DCL No ROM support is okay	;     ;
  2437 00000BB4 EB13                    	   JMP SHORT DD_EN30
  2438                                  DD_IF30:
  2439                                  						; except for /N: & /T:		;     ;
  2440 00000BB6 F706[2006]3000          	      test    word [SwitchMap], SWITCH_N | SWITCH_T ; DCL 5/12/86		      ;     ;
  2441                                  ;	      $IF     NZ			;				;AC000;
  2442 00000BBC 740B                    	      JZ DD_IF32
  2443 00000BBE BA[0000]E8(0000)        		 Message msgParametersNotSupported ;				   ;AC000;
  2444 00000BC4 C606[0000]FF            		 mov	 byte [Fatal_Error],Yes	;Indicate quittin'type err!     ;AN000;
  2445                                  ;	      $ENDIF				;				;AN000;
  2446                                  DD_IF32:
  2447                                  ;	   $ENDIF				;				;AN000;
  2448                                  DD_EN30:
  2449                                  ;	$ENDIF					;				;AN000;
  2450                                  DD_EN28:
  2451 00000BC9 803E[0000]FF            	cmp	byte [Fatal_Error],Yes 		;				;AN000;
  2452 00000BCE 7503                    	jne	StdBPB				;				;AN000;
  2453 00000BD0 E958F7                  	jmp	Fexit
  2454                                  ;
  2455                                  ; We have the support to carry out the FORMAT
  2456                                  ;
  2457                                  NTSupported:
  2458                                  StdBPB:
  2459                                  						;call	 DSKPRM 		 ; prompt user for disk ;; DCL 5/12/86
  2460 00000BD3 C606[4B02]00            	mov	byte [FormatPacket + FP_SpecialFunctions], 0
  2461 00000BD8 A1[6604]                	mov	ax, [firstHead]
  2462                                  FP_Head equ FP_HEAD	; NASM port equate
  2463 00000BDB A3[4C02]                	mov	[formatPacket + FP_Head], ax
  2464 00000BDE A1[6804]                	mov	ax, [firstCylinder]
  2465                                  FP_Cylinder equ FP_CYLINDER	; NASM port equate
  2466 00000BE1 A3[4E02]                	mov	[formatPacket + FP_Cylinder], ax
  2467 00000BE4 8B0E[6C04]              	mov	cx, [tracksPerDisk]
  2468 00000BE8 890E[6A04]              	mov	[tracksLeft], cx
  2469 00000BEC C606[DC06]00            	mov	byte [Format_End],False						;an015; dms;flag not at end of format
  2470 00000BF1 E8EC07                  	call	Calc_Max_Tracks_To_Format					;an015; dms;max track count for FormatTrack call
  2471                                  FormatLoop:
  2472 00000BF4 E81F08                  	call	Format_Loop							;an015; dms;Format until CY occurs
  2473                                  
  2474                                  True equ TRUE	; NASM port equate
  2475 00000BF7 803E[DC06]FF            	cmp	byte [Format_End],True 						;an015; dms;End of Format?
  2475          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  2476                                  ;	$if	e								;an015; dms;yes
  2477 00000BFC 7508                    	JNE DD_IF36
  2478                                  FormatError equ formatError	; NASM port label
  2479 00000BFE C606[8004]00            		mov	byte [FormatError],0						;an015; dms;signal good format
  2480 00000C03 F8                      		clc								;an015; dms;clear CY
  2481                                  ;	$else									;an015; dms;bad format
  2482 00000C04 EB21                    	JMP SHORT DD_EN36
  2483                                  DD_IF36:
  2484 00000C06 E8CE00                  		call	CheckError						;an015; dms;determine type of error
  2485                                  ;		$if	nc							;an015; dms;
  2486 00000C09 721C                    		JC DD_IF38
  2487 00000C0B E8(0000)                			call	LastChanceToSaveIt				;an015; dms;acceptable error?
  2488                                  ;			$if	c						;an015; dms;yes
  2489 00000C0E 7308                    			JNC DD_IF39
  2490 00000C10 C606[8004]01            				mov	byte [FormatError],1				;an015; dms;signal error type
  2491 00000C15 F8                      				clc						;an015; dms;clear CY
  2492                                  ;			$else							;an015; dms;not acceptable error
  2493 00000C16 EB0F                    			JMP SHORT DD_EN39
  2494                                  DD_IF39:
  2495 00000C18 E82CFE                  				call	SetStartSector				;an015; dms;start from scratch
  2496                                  SetFBigFat equ SetfBigFat	; NASM port label
  2497 00000C1B E852FE                  				call	SetFBigFat				;an015; dms;
  2498 00000C1E 50                      				push	ax					;an015; dms;
  2499 00000C1F E880FE                  				call	Phase2Initialisation			;an015; dms;
  2500 00000C22 F8                      				clc						;an015; dms;
  2501 00000C23 58                      				pop	ax					;an015; dms;
  2502 00000C24 E903FF                  				jmp	DiskFormat				;an015; dms;try again
  2503                                  ;			$endif							;an015; dms;
  2504                                  DD_EN39:
  2505                                  ;		$endif								;an015; dms;
  2506                                  DD_IF38:
  2507                                  ;	$endif									;an015; dms;
  2508                                  DD_EN36:
  2509 00000C27 C3                      	return
  2510                                  
  2511                                  FormatDone:
  2512 00000C28 C606[8004]00            	mov	byte [FormatError],0
  2513 00000C2D F8                      	clc
  2514 00000C2E C3                      	return
  2515                                  
  2516                                  DiskFormat endp
  2517                                  
  2518                                  
  2519                                  ;-------------------------------------------------------------------------------
  2520                                  ;
  2521                                  ;    BadSector:
  2522                                  ;	Reports the bad sectors.
  2523                                  ;	Reports the track where DiskFormat stopped.
  2524                                  ;	From then on it formats until it reaches a bad track, or end,
  2525                                  ;	and reports that.
  2526                                  ;
  2527                                  ;    Output:
  2528                                  ;	Carry: set --> fatal error
  2529                                  ;	if Carry not set
  2530                                  ;	   ax - The number of consecutive bad sectors encountered
  2531                                  ;		ax == 0 --> no more bad sectors
  2532                                  ;	   bx - The logical sector number of the first bad sector
  2533                                  ;
  2534                                  ;    Algorithm:
  2535                                  ;	if DiskFormatErrors
  2536                                  ;	   DiskFormatErrors = false
  2537                                  ;	   return current track
  2538                                  ;	else
  2539                                  ;	   next track
  2540                                  ;	   while not done
  2541                                  ;	      if format track fails
  2542                                  ;		 return current track
  2543                                  ;	      next track
  2544                                  ;	   return 0
  2545                                  
  2546                                  BadSector proc	near
  2547                                  
  2548                                  
  2549                                  ; don't bother to do the formatting if /c was given
  2550 00000C2F F706[2006]0800          	test	word [switchmap], SWITCH_C
  2551 00000C35 7545                    	jnz	NoMoreTracks
  2552                                  
  2553 00000C37 F606[8004]FF            	test	byte [formatError], 0ffH
  2554 00000C3C 7408                    	jz	ContinueFormat
  2555 00000C3E C606[8004]00            	mov	byte [formatError], 0
  2556 00000C43 EB2F                    	jmp	ReportBadTrack
  2557 00000C45 90                      	nop	; identicalise
  2558                                  
  2559                                  ContinueFormat:
  2560 00000C46 E80908                  	call	Adj_Track_Count 						;an015; dms;decrease track counter
  2561 00000C49 E8FC06                  	call	NextTrack							;an015; dms;adjust head and cylinder
  2562 00000C4C 803E[DC06]FF            	cmp	byte [Format_End],True 						;an015; dms;end of format?
  2562          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  2563                                  ;	$if	ne								;an015; dms;no
  2564 00000C51 741D                    	JE DD_IF44
  2565 00000C53 E8C007                  		call	Format_Loop						;an015; dms;format until CY
  2566 00000C56 803E[DC06]FF            		cmp	byte [Format_End],True 					;an015; dms;end of format?
  2566          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  2567                                  ;		$if	ne							;an015; dms;no
  2568 00000C5B 740E                    		JE DD_IF45
  2569 00000C5D E87700                  			call	CheckError					;an015; dms;must be error - which error?
  2570                                  ;			$if	nc						;an015; dms;non-fatal error?
  2571 00000C60 7207                    			JC DD_IF46
  2572 00000C62 E81D02                  				call	CurrentLogicalSector			;an015; dms;yes - get position
  2573 00000C65 A1[3901]                				mov	ax,[DeviceParameters + DP_BPB + BPB_SectorsPerTrack]	;an015; dms; set track size
  2574 00000C68 F8                      				clc						;an015; dms;signal O.K. to continue
  2575                                  ;			$endif							;an015; dms;
  2576                                  DD_IF46:
  2577                                  ;		$else								;an015; dms;
  2578 00000C69 EB03                    		JMP SHORT DD_EN45
  2579                                  DD_IF45:
  2580 00000C6B EB0F                    			jmp	NoMoreTracks					;an015; dms;end of format
  2581 00000C6D 90                      	nop	; identicalise
  2582                                  ;		$endif								;an015; dms;
  2583                                  DD_EN45:
  2584                                  ;	$else									;an015; dms;
  2585 00000C6E EB03                    	JMP SHORT DD_EN44
  2586                                  DD_IF44:
  2587 00000C70 EB0A                    		jmp	NoMoreTracks						;an015; dms;end of format
  2588 00000C72 90                      	nop	; identicalise
  2589                                  ;	$endif									;an015; dms;
  2590                                  DD_EN44:
  2591 00000C73 C3                      	return									;an015; dms;
  2592                                  
  2593                                  ReportBadTrack:
  2594 00000C74 E80B02                  	call	CurrentLogicalSector
  2595 00000C77 A1[3901]                	mov	ax, [deviceParameters + DP_BPB + BPB_SectorsPerTrack]
  2596 00000C7A F8                      	clc
  2597 00000C7B C3                      	return
  2598                                  
  2599                                  NoMoreTracks:
  2600 00000C7C F706[2006]000C          	test	word [SwitchMap],(Switch_Select | SWITCH_AUTOTEST) ;Don't display done msg;AN000;
  2601                                  ;	$IF	Z				; if EXEC'd by SELECT           ;AN000;
  2602 00000C82 7506                    	JNZ DD_IF52
  2603 00000C84 BA[0000]E8(0000)        	   Message msgFormatComplete		;				;AC000;
  2604                                  ;	$ENDIF					;				;AN000;
  2605                                  DD_IF52:
  2606 00000C8A B80000                  	mov	ax, 0
  2607 00000C8D F8                      	clc
  2608 00000C8E C3                      	return
  2609                                  
  2610                                  BadSector endp
  2611                                  
  2612                                  
  2613                                  
  2614                                  ;-------------------------------------------------------------------------------
  2615                                  
  2616                                  section data
  2617                                  
  2618                                  ;ptr_msgCurrentTrack dw offset msgCurrentTrack
  2619 000006E1 0000                    currentHead dw	0
  2620 000006E3 0000                    currentCylinder dw 0
  2621                                  
  2622                                  section code	; data	ends
  2623                                  
  2624                                  ;=========================================================================
  2625                                  ; Calc_Current_Head_Cyl : Obtain the current head and cylinder of the
  2626                                  ;			  track being formatted.
  2627                                  ;
  2628                                  ;	Inputs: FP_Cylinder	- Cylinder of track being formatted
  2629                                  ;		FP_Head 	- Head of track being formatted
  2630                                  ;=========================================================================
  2631                                  
  2632                                  Procedure Calc_Current_Head_Cyl 						;an000; dms;
  2633                                  
  2634 00000C8F 51                      	push	cx								;an000; dms;save cx
  2635 00000C90 8B0E[4E02]              	mov	cx,[FormatPacket + FP_Cylinder]					;an000; dms;get current cylinder
  2636                                  CurrentCylinder equ currentCylinder	; NASM port label
  2637 00000C94 890E[E306]              	mov	[CurrentCylinder],cx						;an000; dms;put into variable
  2638 00000C98 8B0E[4C02]              	mov	cx,[FormatPacket + FP_Head] 					;an000; dms;get current head
  2639                                  CurrentHead equ currentHead	; NASM port label
  2640 00000C9C 890E[E106]              	mov	[CurrentHead],cx							;an000; dms;put into variable
  2641 00000CA0 59                      	pop	cx								;an000; dms;restore cx
  2642 00000CA1 C3                      	ret									;an000; dms;
  2643                                  
  2644                                  Calc_Current_Head_Cyl	endp							;an000; dms;
  2645                                  
  2646                                  
  2647                                  DisplayCurrentTrack proc near
  2648                                  
  2649 00000CA2 52                      	push	dx				;				;AN000;
  2650 00000CA3 51                      	push	cx				;				;AN000;
  2651 00000CA4 50                      	push	ax				;an015; dms;
  2652                                  
  2653 00000CA5 A1[D806]                	mov	ax,[Tracks_To_Format]		;an015; dms;get track count
  2654                                  
  2655 00000CA8 0106[6E04]              	add	[Formatted_Tracks_Low],ax 	;Indicate formatted a track	;AN000;
  2656 00000CAC 8316[7004]00            	adc	word [Formatted_Tracks_High],0 	;				;AN000;
  2657 00000CB1 A1[6E04]                	mov	ax,[Formatted_Tracks_Low] 	;				;AN000;
  2658 00000CB4 8B1E[7004]              	mov	bx,[Formatted_Tracks_High]	;				;AN000;
  2659 00000CB8 B96400                  	mov	cx,100				;Make integer calc for div	;AN000;
  2660 00000CBB E8EA01                  	call	Multiply_32_Bits		; BX:AX = (Cyl * Head *100)	;AN000;
  2661 00000CBE 89DA                    	mov	dx,bx				;Set up divide			;AN000;
  2662                                  TracksPerDisk equ tracksPerDisk	; NASM port label
  2663 00000CC0 F736[6C04]              	div	word [TracksPerDisk]			;% = (Cyl * Head *100)/ # tracks;AN000;
  2664 00000CC4 3B06[7604]              	cmp	ax,[PercentComplete]		;Only print message when change ;AN000;
  2665                                  ;	$IF	NE				;To avoid excess cursor splat	;AN000;
  2666 00000CC8 7409                    	JE DD_IF54
  2667 00000CCA A3[7604]                	   mov	   [PercentComplete],ax		;Save it if changed		;AN000;
  2668 00000CCD BA[0000]E8(0000)        	   Message msgCurrentTrack		;				;AC000;
  2669                                  ;	$ENDIF					;
  2670                                  DD_IF54:
  2671 00000CD3 58                      	pop	ax				;an015; dms;
  2672 00000CD4 59                      	pop	cx				;Restore register		;AN000;
  2673 00000CD5 5A                      	pop	dx				;				;AN000;
  2674 00000CD6 C3                      	return
  2675                                  
  2676                                  DisplayCurrentTrack endp
  2677                                  
  2678                                  
  2679                                  ;-------------------------------------------------------------------------------
  2680                                  ;    CheckError:
  2681                                  ;	Input:
  2682                                  ;	   ax - extended error code
  2683                                  ;	Ouput:
  2684                                  ;	   carry set if error is fatal
  2685                                  ;	   Message printed if Not Ready or Write Protect
  2686                                  ;
  2687                                  CheckError proc near
  2688 00000CD7 83F813                  	cmp	ax, error_write_protect
  2689 00000CDA 7430                    	je	WriteProtectError
  2690 00000CDC 83F815                  	cmp	ax, error_not_ready
  2691 00000CDF 7458                    	je	NotReadyError
  2692 00000CE1 833E[E306]00            	cmp	word [currentCylinder], 0
  2693 00000CE6 7507                    	jne	CheckRealErrors
  2694 00000CE8 833E[E106]00            	cmp	word [currentHead], 0
  2695 00000CED 7477                    	je	BadTrackZero
  2696                                  
  2697                                  CheckRealErrors:
  2698 00000CEF 83F817                  	cmp	ax, error_CRC
  2699 00000CF2 7416                    	je	JustABadTrack
  2700 00000CF4 83F81B                  	cmp	ax, error_sector_not_found
  2701 00000CF7 7411                    	je	JustABadTrack
  2702 00000CF9 83F81D                  	cmp	ax, error_write_fault
  2703 00000CFC 740C                    	je	JustABadTrack
  2704 00000CFE 83F81E                  	cmp	ax, error_read_fault
  2705 00000D01 7407                    	je	JustABadTrack
  2706 00000D03 83F81F                  	cmp	ax, error_gen_failure
  2707 00000D06 7402                    	je	JustABadTrack
  2708                                  
  2709 00000D08 F9                      	stc
  2710 00000D09 C3                      	ret
  2711                                  
  2712                                  JustABadTrack:
  2713 00000D0A F8                      	clc
  2714 00000D0B C3                      	ret
  2715                                  
  2716                                  WriteProtectError:
  2717                                  
  2718                                  Switch_SELECT equ SWITCH_SELECT	; NASM port equate
  2719 00000D0C F706[2006]0004          	test	word [SwitchMap],Switch_SELECT 					;an017; dms;SELECT option?
  2720                                  ;	$if	z								;an017; dms;no - display messages
  2721 00000D12 751E                    	JNZ DD_IF56
  2722 00000D14 BA[0000]E8(0000)        		Message  msgCRLF			;			;AC006;
  2723 00000D1A BA[0000]E8(0000)        		Message  msgCRLF			;			;AC006;
  2724 00000D20 1EBA[ssss]8EDAA3-       		Extended_Message			;			;AC006;
  2724 00000D27 [0000]BA[0000]E8-  
  2724 00000D2D (0000)1F           
  2725                                  ;	$else									;an017; dms;yes - set error level
  2726 00000D30 EB05                    	JMP SHORT DD_EN56
  2727                                  DD_IF56:
  2728 00000D32 C606[8304]07            		mov	byte [ExitStatus],ExitWriteProtect				;an017; dms;signal write protect error
  2729                                  ;	$endif									;an017; dms;
  2730                                  DD_EN56:
  2731                                  
  2732 00000D37 F9                      	stc									;an017; dms;signal fatal error
  2733 00000D38 C3                      	ret									;an017; dms;return to caller
  2734                                  
  2735                                  NotReadyError:
  2736 00000D39 F706[2006]0004          	test	word [SwitchMap],Switch_SELECT 					;an017; dms; SELECT option?
  2737                                  ;	$if	z								;an017; dms; no - display messages
  2738 00000D3F 751E                    	JNZ DD_IF59
  2739 00000D41 BA[0000]E8(0000)        		Message  msgCRLF			;			;AC006;
  2740 00000D47 BA[0000]E8(0000)        		Message  msgCRLF			;			;AC006;
  2741 00000D4D 1EBA[ssss]8EDAA3-       		Extended_Message			;			;AC006;
  2741 00000D54 [0000]BA[0000]E8-  
  2741 00000D5A (0000)1F           
  2742                                  ;	$else									;an017; dms;yes - set error level
  2743 00000D5D EB05                    	JMP SHORT DD_EN59
  2744                                  DD_IF59:
  2745 00000D5F C606[8304]06            		mov	byte [ExitStatus],ExitDriveNotReady				;an017; dms;signal drive not ready
  2746                                  ;	$endif									;an017; dms;
  2747                                  DD_EN59:
  2748 00000D64 F9                      	stc
  2749 00000D65 C3                      	ret
  2750                                  
  2751                                  
  2752                                  BadTrackZero:
  2753 00000D66 BA[0000]E8(0000)        	Message msgDiskUnusable 		;				;AC000;
  2754 00000D6C F9                      	stc
  2755 00000D6D C3                      	ret
  2756                                  
  2757                                  CheckError endp
  2758                                  
  2759                                  ;-------------------------------------------------------------------------------
  2760                                  ;    WriteFileSystem:
  2761                                  ;	Write the boot sector and FATs out to disk
  2762                                  ;	Clear the directory sectors to zero
  2763                                  ;
  2764                                  
  2765                                  WriteFileSystem proc near
  2766                                  
  2767                                  
  2768 00000D6E E8(0000)                	call	WriteBootSector
  2769 00000D71 7301C3                  	retc
  2770                                  
  2771 00000D74 50B8[ssss]8ED81E07-     	Set_Data_Segment			;Set DS,ES = DATA		;AN000;
  2771 00000D7C 58                 
  2772                                  ; Write out each of the FATs
  2773 00000D7D 1E                      	push	ds				;ac005; dms;save ds
  2774 00000D7E 31C9                    	xor	cx, cx
  2775 00000D80 268A0E[3101]            	mov	cl, [es:deviceParameters + DP_BPB + BPB_numberOfFATs] ;		;AC000;
  2776 00000D85 268B16[2F01]            	mov	dx, [es:deviceParameters + DP_BPB + BPB_ReservedSectors] ;		;AC000;
  2777 00000D8A 26A0[8206]              	mov	al, [es:drive]			;				;AC000;
  2778                                  FatSpace equ fatSpace	; NASM port label
  2779 00000D8E 268B1E[6304]            	mov	bx,word ptr [es:FatSpace+2]	;Get segment of memory Fat	;AC000;
  2780 00000D93 8EDB                    	mov	ds,bx				;				;AN000;
  2781 00000D95 268B1E[6104]            	mov	bx,word ptr [es:FatSpace] 	;				;AN000;
  2782                                  
  2783 00000D9A 89DE                    	mov	si,bx				;ac005; dms;set up for add. calc
  2784                                  SEG_ADJ equ seg_adj	; NASM port label
  2785 00000D9C E8C200                  	call	SEG_ADJ 			;ac005; dms;get adjusted seg:off
  2786 00000D9F 89F3                    	mov	bx,si				;ac005; dms;get new off
  2787                                  	assume	ds:nothing,es:data		;				;AN000;
  2788                                  
  2789                                  ;	$do					;ac005; dms;while FATS > 0
  2790                                  DD_DO62:
  2791 00000DA1 83F900                  		cmp	cx,00			;ac005; dms;FATS remaining?
  2792                                  ;		$leave	e			;ac005; dms;no
  2793 00000DA4 741E                    		JE DD_EN62
  2794 00000DA6 53                      		push	bx			;ac005; dms;save FAT offset
  2795 00000DA7 1E                      		push	ds			;ac005; dms;save FAT segment
  2796 00000DA8 51                      		push	cx			;ac005; dms;save FAT count
  2797 00000DA9 52                      		push	dx			;ac005; dms;reserved FAT sector
  2798                                  WRITE_FAT equ write_fat	; NASM port label
  2799 00000DAA E87F00                  		call	WRITE_FAT		;ac005; dms;write the FAT
  2800 00000DAD 5A                      		pop	dx			;ac005; dms;get 1st. FAT sector
  2801 00000DAE 59                      		pop	cx			;ac005; dms;get FAT count
  2802 00000DAF 1F                      		pop	ds			;ac005; dms;restore FAT segment
  2803 00000DB0 5B                      		pop	bx			;ac005; dms;restore FAT offset
  2804                                  ;		$if	c			;ac005; dms;an error occurred
  2805 00000DB1 7309                    		JNC DD_IF64
  2806 00000DB3 BA[0000]E8(0000)        			Message msgFATwriteError;ac005; dms;say why failed
  2807 00000DB9 E96FF5                  			jmp	FEXIT		;ac005; dms;exit format
  2808                                  ;		$endif				;ac005; dms;
  2809                                  DD_IF64:
  2810 00000DBC 260316[3701]            		add	dx, [es:deviceParameters + DP_BPB + BPB_SectorsPerFAT] ;		;AC000;
  2811 00000DC1 49                      		dec	cx			;ac005; dms;decrease FAT count
  2812                                  ;	$enddo					;ac005; dms;
  2813 00000DC2 EBDD                    	JMP SHORT DD_DO62
  2814                                  DD_EN62:
  2815                                  
  2816 00000DC4 1F                      	pop	ds				;ac005; dms;restore ds
  2817                                  	assume	ds:data 			;ac005; dms;
  2818                                  
  2819                                  
  2820                                  ; Clear the directory
  2821                                  
  2822                                  ; Now write the initialised directory sectors out to disk
  2823 00000DC5 26A1[3701]              	mov	ax, [es:deviceParameters + DP_BPB + BPB_SectorsPerFAT] ;		;AC000;
  2824 00000DC9 31D2                    	xor	dx,dx
  2825 00000DCB 53                      	push	bx								;an000; dms;save bx
  2826 00000DCC 31DB                    	xor	bx,bx								;an000; dms;clear bx
  2827                                  BPB_NumberOfFATs equ BPB_NUMBEROFFATS	; NASM port equate
  2828 00000DCE 268A1E[3101]            	mov	bl,[es:DeviceParameters + DP_BPB + BPB_NumberOfFATs]			;an000; dms;get FAT count
  2829 00000DD3 F7E3                    	mul	bx								;an000; dms;get total FAT sectors
  2830 00000DD5 5B                      	pop	bx								;an000; dms;restore bx
  2831                                  
  2832 00000DD6 268B16[2F01]            	mov	dx, [es:deviceParameters + DP_BPB + BPB_ReservedSectors] ;		;AC000;
  2833 00000DDB 01C2                    	add	dx, ax
  2834 00000DDD 268B0E[7A04]            	mov	cx, [es:sectorsInRootDirectory]	;				  ;AC000;
  2835                                  WriteDIRloop:
  2836 00000DE2 51                      	push	cx
  2837 00000DE3 52                      	push	dx
  2838 00000DE4 26A0[8206]              	mov	al, [es:drive]			;				;AC000;
  2839 00000DE8 B90100                  	mov	cx, 1
  2840 00000DEB 26C51E[7C04]            	lds	bx, [es:directorySector]		;				;AC000;
  2841                                  
  2842                                  	assume	ds:nothing,es:data		;				;AN000;
  2843                                  
  2844                                  ;Assume dir is alway contined in first 32mb of partition
  2845                                  
  2846 00000DF0 26C706[0200]0000        	mov	word [es:Read_Write_Relative + Start_Sector_High],0 ;			;AC000;
  2847 00000DF7 E8(0000)                	Call	Write_Disk			;				;AN000;
  2848 00000DFA 7309                    	jnc	Dir_OK				;				;AC000;
  2849 00000DFC BA[0000]E8(0000)        	Message msgDirectoryWriteError		;				;AC000;
  2850                                  FExit equ FEXIT	; NASM port label
  2851 00000E02 E926F5                  	jmp	FExit				;				;AN000;
  2852                                  Dir_OK: 					;				;AN000;
  2853 00000E05 5A                      	pop	dx
  2854 00000E06 83C201                  	add	dx, 1
  2855 00000E09 59                      	pop	cx
  2856                                  WriteDIRLoop equ WriteDIRloop	; NASM port label
  2857 00000E0A E2D6                    	loop	WriteDIRLoop
  2858                                  
  2859 00000E0C 50B8[ssss]8ED81E07-     	Set_Data_Segment			;Set DS to DATA segment 	;AN000;
  2859 00000E14 58                 
  2860                                  ; Ok, we can tell the device driver that we are finished formatting
  2861 00000E15 C706[2700]0000          	mov	word [savedDeviceParameters + DP_TrackTableEntries], 0
  2862 00000E1B C606[0100]04            	mov	byte [savedDeviceParameters + DP_SpecialFunctions], TRACKLAYOUT_IS_GOOD
  2863 00000E20 8D16[0100]              	lea	dx, [savedDeviceParameters]
  2864 00000E24 E8E5FC                  	call	SetDeviceParameters
  2865                                  
  2866 00000E27 B40D                    	MOV	AH,DISK_RESET			; Flush any directories in
  2867 00000E29 CD21                    	INT	21H				; buffers
  2868                                  
  2869 00000E2B C3                      	return
  2870                                  
  2871                                  
  2872                                  WriteFileSystem endp
  2873                                  
  2874                                  ;=========================================================================
  2875                                  ; WRITE_FAT	:	This routine writes the logical sector count requested.
  2876                                  ;			It will write a maximum of 40h sectors.  If more
  2877                                  ;			than 40h exists it will continue looping until
  2878                                  ;			all sectors have been written.
  2879                                  ;
  2880                                  ;	Inputs	:	AL - Drive letter
  2881                                  ;			DS:BX - Segment:offset of transfer address
  2882                                  ;			CX - Sector count
  2883                                  ;			DX - 1st. sector
  2884                                  ;
  2885                                  ;	Outputs :	Logical sectors written
  2886                                  ;=========================================================================
  2887                                  
  2888                                  procedure	write_fat
  2889                                  
  2890 00000E2C 268B0E[3701]            	mov	cx, [es:deviceParameters + DP_BPB + BPB_SectorsPerFAT] ;		;AC000;
  2891                                  
  2892                                  ;	$do					;an000;while sectors left
  2893                                  DD_DO67:
  2894 00000E31 83F900                  		cmp	cx,00h			;an000;any sectors?
  2895                                  ;		$leave	e			;an000;no
  2896 00000E34 742A                    		JE DD_EN67
  2897                                  
  2898 00000E36 83F940                  		cmp	cx,40h
  2899                                  ;		$if	a			;an000;yes
  2900 00000E39 761C                    		JNA DD_IF69
  2901 00000E3B 51                      			push	cx		;an000;save cx
  2902 00000E3C B94000                  			mov	cx,40h
  2903 00000E3F 50                      			push	ax		;an000;save ax
  2904                                  write_disk equ Write_Disk	; NASM port label
  2905 00000E40 E8(0000)                			call	write_disk	;an000;write it
  2906 00000E43 58                      			pop	ax		;an000;restore ax
  2907 00000E44 59                      			pop	cx		;an000;restore cx
  2908 00000E45 7219                    			jc	Write_Exit	;an000;exit if fail
  2909 00000E47 BE0080                  			mov	si,8000h
  2910 00000E4A E81400                  			call	seg_adj 	;an000;adjust segment
  2911 00000E4D 89F3                    			mov	bx,si		;an000;new offset
  2912 00000E4F 83C240                  			add	dx,40h
  2913 00000E52 83E940                  			sub	cx,40h
  2914                                  ;		$else				;an000;< 64k
  2915 00000E55 EB07                    		JMP SHORT DD_EN69
  2916                                  DD_IF69:
  2917 00000E57 50                      			push	ax		;an000;save ax
  2918 00000E58 E8(0000)                			call	write_disk	;an000;write it
  2919 00000E5B 58                      			pop	ax		;an000;restore ax
  2920 00000E5C 31C9                    			xor	cx,cx		;an000;set cx to 0 - last read
  2921                                  ;		$endif
  2922                                  DD_EN69:
  2923                                  ;	$enddo
  2924 00000E5E EBD1                    	JMP SHORT DD_DO67
  2925                                  DD_EN67:
  2926                                  
  2927                                  	Write_Exit:
  2928                                  
  2929 00000E60 C3                      	ret
  2930                                  
  2931                                  write_fat	endp
  2932                                  
  2933                                  ;=========================================================================
  2934                                  ; SEG_ADJ	:	This routine adjusts the segment:offset to prevent
  2935                                  ;			address wrap.
  2936                                  ;
  2937                                  ;	Inputs	:	SI - Offset to adjust segment with
  2938                                  ;			DS - Segment to be adjusted
  2939                                  ;
  2940                                  ;	Outputs :	SI - New offset
  2941                                  ;			DS - Adjusted segment
  2942                                  ;=========================================================================
  2943                                  
  2944                                  procedure	seg_adj
  2945                                  
  2946 00000E61 50                      	push	ax
  2947 00000E62 51                      	push	cx
  2948 00000E63 52                      	push	dx
  2949 00000E64 89F0                    	mov	ax,si				;an000;get offset
  2950 00000E66 BB1000                  	mov	bx,0010h			;an000;16
  2951 00000E69 31D2                    	xor	dx,dx				;an000;clear dx
  2952 00000E6B F7F3                    	div	bx				;an000;get para count
  2953                                  ;	$if	c				;an000;overflow?
  2954 00000E6D 7303                    	JNC DD_IF73
  2955 00000E6F 83D300                  		adc	bx,0			;an000;pick it up
  2956                                  ;	$endif					;an000;
  2957                                  DD_IF73:
  2958 00000E72 8CDB                    	mov	bx,ds				;an000;get seg
  2959 00000E74 01C3                    	add	bx,ax				;an000;adjust for paras
  2960 00000E76 8EDB                    	mov	ds,bx				;an000;save new seg
  2961 00000E78 89D6                    	mov	si,dx				;an000;new offset
  2962 00000E7A 5A                      	pop	dx
  2963 00000E7B 59                      	pop	cx
  2964 00000E7C 58                      	pop	ax
  2965 00000E7D C3                      	ret
  2966                                  
  2967                                  seg_adj 	endp
  2968                                  
  2969                                  ;-------------------------------------------------------------------------------
  2970                                  ;	format is done... so clean up the disk!
  2971                                  ;
  2972                                  Done	proc	near
  2973                                  
  2974                                  
  2975 00000E7E E8(0000)                	call	OemDone
  2976 00000E81 C3                      	return
  2977                                  
  2978                                  Done	endp
  2979                                  
  2980                                  ;-------------------------------------------------------------------------------
  2981                                  ;    CurrentLogicalSector:
  2982                                  ;	Get the current logical sector number
  2983                                  ;
  2984                                  ;    Input:
  2985                                  ;	current track = tracksPerDisk - tracksLeft
  2986                                  ;	SectorsPerTrack
  2987                                  ;
  2988                                  ;    Output:
  2989                                  ;	BX = logical sector number of the first sector in the track we
  2990                                  ;	     just tried to format
  2991                                  ;
  2992                                  CurrentLogicalSector proc near
  2993                                  
  2994 00000E82 50                      	push	ax								;an000; dms;save regs
  2995 00000E83 53                      	push	bx								;an000; dms;
  2996 00000E84 52                      	push	dx								;an000; dms;
  2997                                  
  2998 00000E85 A1[6C04]                	mov	ax, [tracksPerDisk]
  2999 00000E88 2B06[6A04]              	sub	ax, [tracksLeft]
  3000 00000E8C 31D2                    	xor	dx,dx								;an000; dms;clear dx
  3001 00000E8E F726[3901]              	mul	word [deviceParameters + DP_BPB + BPB_SectorsPerTrack]
  3002 00000E92 8916[D506]              	mov	word ptr [Relative_Sector_High],dx				;an000; dms;save high word of sector #
  3003 00000E96 A3[D306]                	mov	word ptr [Relative_Sector_Low],ax 				;an000; dms;save low word of sector #
  3004                                  
  3005 00000E99 5A                      	pop	dx								;an000; dms;restore regs
  3006 00000E9A 5B                      	pop	bx								;an000; dms;
  3007 00000E9B 58                      	pop	ax								;an000; dms;
  3008                                  
  3009 00000E9C C3                      	return
  3010                                  
  3011                                  CurrentLogicalSector endp
  3012                                  
  3013                                  ;-------------------------------------------------------------------------------
  3014                                  ;    PrintErrorAbort:
  3015                                  ;	Print an error message and abort
  3016                                  ;
  3017                                  ;    Input:
  3018                                  ;	dx - Pointer to error message string
  3019                                  ;
  3020                                  PrintErrorAbort proc near
  3021                                  
  3022 00000E9D 52                      	push	dx
  3023 00000E9E E89DF5                  	call	crlf
  3024 00000EA1 5A                      	pop	dx
  3025 00000EA2 E89CF5                  	call	PrintString
  3026                                  
  3027 00000EA5 E983F4                  	jmp	fexit
  3028                                  
  3029                                  PrintErrorAbort endp
  3030                                  
  3031                                  
  3032                                  
  3033                                  
  3034                                  ;*****************************************************************************
  3035                                  ;Routine name: Multiply_32_Bits
  3036                                  ;*****************************************************************************
  3037                                  ;
  3038                                  ;Description: A real sleazy 32 bit x 16 bit multiply routine. Works by adding
  3039                                  ;	      the 32 bit number to itself for each power of 2 contained in the
  3040                                  ;	      16 bit number. Whenever a bit that is set in the multiplier (CX)
  3041                                  ;	      gets shifted to the bit 0 spot, it means that that amount has
  3042                                  ;	      been multiplied so far, and it should be added into the total
  3043                                  ;	      value. Take the example CX = 12 (1100). Using the associative
  3044                                  ;	      rule, this is the same as CX = 8+4 (1000 + 0100). The
  3045                                  ;	      multiply is done on this principle - whenever a bit that is set
  3046                                  ;	      is shifted down to the bit 0 location, the value in BX:AX is
  3047                                  ;	      added to the running total in DI:SI. The multiply is continued
  3048                                  ;	      until CX = 0. The routine will exit with CY set if overflow
  3049                                  ;	      occurs.
  3050                                  ;
  3051                                  ;
  3052                                  ;Called Procedures: None
  3053                                  ;
  3054                                  ;Change History: Created	7/23/87 	MT
  3055                                  ;
  3056                                  ;Input: BX:AX = 32 bit number to be multiplied
  3057                                  ;	CX = 16 bit number to be multiplied. (Must be even number)
  3058                                  ;
  3059                                  ;Output: BX:AX = output.
  3060                                  ;	 CY set if overflow
  3061                                  ;
  3062                                  ;Psuedocode
  3063                                  ;----------
  3064                                  ;
  3065                                  ;	Point at ControlC_Handler routine
  3066                                  ;	Set interrupt handler (INT 21h, AX=2523h)
  3067                                  ;	ret
  3068                                  ;*****************************************************************************
  3069                                  
  3070                                  Public Multiply_32_Bits
  3071                                  Multiply_32_Bits proc				;				;AN000;
  3072                                  
  3073 00000EA8 57                      	push	di				;				;AN000;
  3074 00000EA9 56                      	push	si				;				;AN000;
  3075 00000EAA 31FF                    	xor	di,di				;Init result to zero
  3076 00000EAC 31F6                    	xor	si,si				;
  3077 00000EAE 83F900                  	cmp	cx,0				;Multiply by 0? 		;AN000;
  3078                                  ;	$IF	NE				;Keep going if not		;AN000;
  3079 00000EB1 7425                    	JE DD_IF75
  3080                                  ;	   $DO					;This works by adding the result;AN000;
  3081                                  DD_DO76:
  3082 00000EB3 F7C10100                	      test    cx,1			;Need to add in sum of this bit?;AN000;
  3083                                  ;	      $IF     NZ			;Yes				;AN000;
  3084 00000EB7 7406                    	      JZ DD_IF77
  3085 00000EB9 01C6                    		 add	 si,ax			;Add in the total so far for	;AN000;
  3086 00000EBB 11DF                    		 adc	 di,bx			; this bit multiplier (CY oflow);AN000;
  3087                                  ;	      $ELSE				;Don't split multiplier         ;AN000;
  3088 00000EBD EB01                    	      JMP SHORT DD_EN77
  3089                                  DD_IF77:
  3090 00000EBF F8                      		 clc				;Force non exit 		;AN000;
  3091                                  ;	      $ENDIF				;				;AN000;
  3092                                  DD_EN77:
  3093                                  ;	   $LEAVE  C				;Leave on overflow		;AN000;
  3094 00000EC0 720D                    	   JC DD_EN76
  3095 00000EC2 D1E9                    	      shr     cx,1			;See if need to multiply value	;AN000;
  3096 00000EC4 83F900                  	      cmp     cx,0			;by 2				;AN000;
  3097                                  ;	   $LEAVE  E				;Done if cx shifted down to zero;AN000;
  3098 00000EC7 7406                    	   JE DD_EN76
  3099 00000EC9 01C0                    	      add     ax,ax			;Each time cx is shifted, add	;AN000;
  3100 00000ECB 11DB                    	      adc     bx,bx			;value to itself (Multiply * 2) ;AN000;
  3101                                  ;	   $ENDDO  C				;CY set on overflow		;AN000;
  3102 00000ECD 73E4                    	   JNC DD_DO76
  3103                                  DD_EN76:
  3104                                  ;	   $IF	   NC				;If no overflow, add in DI:SI	;AN000;
  3105 00000ECF 7205                    	   JC DD_IF83
  3106 00000ED1 89F0                    	      mov     ax,si			; which contains the original	;AN000;
  3107 00000ED3 89FB                    	      mov     bx,di			; value if odd, 0 if even. This ;AN000;
  3108 00000ED5 F8                      	      clc				;Set no overflow flag		;AN000;
  3109                                  ;	   $ENDIF				;				;AN000;
  3110                                  DD_IF83:
  3111                                  ;	$ELSE					;
  3112 00000ED6 EB04                    	JMP SHORT DD_EN75
  3113                                  DD_IF75:
  3114 00000ED8 31C0                    	   xor	   ax,ax			;
  3115 00000EDA 31DB                    	   xor	   bx,bx			;
  3116                                  ;	$ENDIF					;Multiply by 0			;AN000;
  3117                                  DD_EN75:
  3118 00000EDC 5E                      	pop	si				;				;AN000;
  3119 00000EDD 5F                      	pop	di				;				;AN000;
  3120 00000EDE C3                      	ret					;				;AN000;
  3121                                  
  3122                                  Multiply_32_Bits endp
  3123                                  
  3124                                  
  3125                                  ;=========================================================================
  3126                                  ; Divide_32_Bits	- This routine will perform 32bit division
  3127                                  ;
  3128                                  ;	Inputs	: SI:DI - value to be divided
  3129                                  ;		  CX	- divisor
  3130                                  ;
  3131                                  ;	Outputs : SI:DI - result
  3132                                  ;		  CX	- remainder
  3133                                  ;=========================================================================
  3134                                  
  3135                                  Procedure Divide_32_Bits							;an000; dms;
  3136                                  
  3137 00000EDF 50                      	push	ax								;an000; dms;save regs
  3138 00000EE0 53                      	push	bx								;an000; dms;
  3139 00000EE1 52                      	push	dx								;an000; dms;
  3140                                  
  3141 00000EE2 31D2                    	xor	dx,dx								;an000; dms;clear dx
  3142 00000EE4 89F0                    	mov	ax,si								;an000; dms;get high word
  3143 00000EE6 F7F1                    	div	cx								;an000; dms;get high word result
  3144 00000EE8 89C6                    	mov	si,ax								;an000; dms;save high word result
  3145                                  
  3146 00000EEA 89F8                    	mov	ax,di								;an000; dms;get low word
  3147 00000EEC F7F1                    	div	cx								;an000; dms;get low word result
  3148 00000EEE 89C7                    	mov	di,ax								;an000; dms;save low word result
  3149 00000EF0 89D1                    	mov	cx,dx								;an000; dms;pick up remainder
  3150                                  
  3151 00000EF2 5A                      	pop	dx								;an000; dms;restore regs
  3152 00000EF3 5B                      	pop	bx								;an000; dms;
  3153 00000EF4 58                      	pop	ax								;an000; dms;
  3154                                  
  3155 00000EF5 C3                      	ret									;an000; dms;
  3156                                  
  3157                                  Divide_32_Bits	endp								;an000; dms;
  3158                                  
  3159                                  
  3160                                  
  3161                                  
  3162                                  ;=========================================================================
  3163                                  ; FAT_INIT:		This routine initializes the FAT based on the
  3164                                  ;			number of paragraphs.
  3165                                  ;
  3166                                  ;
  3167                                  ; input - fatspace
  3168                                  ;	  fatspace+2
  3169                                  ;	  paras_per_fat
  3170                                  ;	  fat_init_value
  3171                                  ; output - fat space is initialized
  3172                                  ;
  3173                                  ;=========================================================================
  3174                                  Public		Fat_Init
  3175                                  Fat_Init	proc	near
  3176                                  
  3177 00000EF6 06                      	push	es
  3178 00000EF7 57                      	push	di
  3179 00000EF8 50                      	push	ax
  3180 00000EF9 53                      	push	bx
  3181 00000EFA 51                      	push	cx
  3182 00000EFB 8B3E[6304]              	mov	di, word ptr [FatSpace+2] 	;Get segment of Fat space	;AC000;
  3183 00000EFF 8EC7                    	mov	es,di				;				;AN000;
  3184 00000F01 8B3E[6104]              	mov	di, word ptr [FatSpace]		;				;AN000;
  3185 00000F05 8B1E[DA04]              	mov	bx,[Paras_Per_Fat]		;an000;get number of paras
  3186                                  fat_init_value equ Fat_Init_Value	; NASM port label
  3187 00000F09 A1[DC04]                	mov	ax,[fat_init_value]		;an000;
  3188 00000F0C 52                      	push	dx				;an000;save bx
  3189 00000F0D 8CC2                    	mov	dx,es				;an000;grab es into dx
  3190                                  ;	$do
  3191                                  DD_DO87:
  3192 00000F0F 83FB00                  		cmp	bx,0			;an000;do while bx not = 0
  3193                                  ;		$leave	e			;an000;exit if 0
  3194 00000F12 740D                    		JE DD_EN87
  3195 00000F14 B91000                  		mov	cx,10h			;an000;word move of paragraph
  3196 00000F17 F3AA                    		rep	stosb			;an000;move the data to FAT
  3197 00000F19 31FF                    		xor	di,di			;an000;offset always init to 0
  3198 00000F1B 42                      		inc	dx			;an000;next paragraph
  3199 00000F1C 8EC2                    		mov	es,dx			;an000;put next para in es
  3200 00000F1E 4B                      		dec	bx			;an000;loop iteration counter
  3201                                  ;	$enddo					;an000;
  3202 00000F1F EBEE                    	JMP SHORT DD_DO87
  3203                                  DD_EN87:
  3204 00000F21 5A                      	pop	dx				;an000;
  3205 00000F22 59                      	pop	cx				;an000;
  3206 00000F23 5B                      	pop	bx				;an000;
  3207 00000F24 58                      	pop	ax				;an000;
  3208 00000F25 5F                      	pop	di				;an000;
  3209 00000F26 07                      	pop	es				;an000;
  3210                                  
  3211 00000F27 C3                      	ret					;an000;
  3212                                  
  3213                                  Fat_Init	endp				;an000;
  3214                                  
  3215                                  
  3216                                  ;=========================================================================
  3217                                  ; Ctrl_Break_Write	: This routine takes the control break request
  3218                                  ;			  an returns.  In essence, it disables the CTRL-BREAK.
  3219                                  ;			  This routine is used during the writing of the
  3220                                  ;			  FAT, DIR, and SYSTEM.
  3221                                  ;=========================================================================
  3222                                  
  3223                                  Ctrl_Break_Write:				;ac010; dms;
  3224                                  
  3225 00000F28 CF                      	iret					;ac010; dms;return to caller
  3226                                  
  3227                                  
  3228                                  ;=========================================================================
  3229                                  ; Ctrl_Break_Save	: This routine gets the current vector of
  3230                                  ;			  INT 23h and saves it in CTRL_BREAK_VECTOR.
  3231                                  ;
  3232                                  ;	Inputs	: none
  3233                                  ;
  3234                                  ;	Outputs : CTRL_BREAK_VECTOR - holds address of INT 23h routine
  3235                                  ;=========================================================================
  3236                                  
  3237                                  Ctrl_Break_Save 	proc	near		;ac010; dms;
  3238                                  
  3239 00000F29 06                      	push	es				;ac010; dms;save es
  3240 00000F2A 53                      	push	bx				;ac010; dms;save bx
  3241 00000F2B 50                      	push	ax				;ac010; dms;save ax
  3242                                  
  3243 00000F2C B82335                  	mov	ax,3523h			;ac010; dms;get CTRL-BREAK
  3244                                  						;	    interrupt vector
  3245 00000F2F CD21                    	int	21h				;ac010; dms;
  3246                                  
  3247                                  Ctrl_Break_Vector equ CTRL_BREAK_VECTOR	; NASM port label
  3248 00000F31 891E[8506]              	mov	word ptr [Ctrl_Break_Vector],bx	;ac010; dms;get vector offset
  3249 00000F35 8C06[8706]              	mov	word ptr [Ctrl_Break_Vector+2],es ;ac010; dms;get vector segment
  3250                                  
  3251 00000F39 58                      	pop	ax				;ac010; dms;restore ax
  3252 00000F3A 5B                      	pop	bx				;ac010; dms;restore bx
  3253 00000F3B 07                      	pop	es				;ac010; dms;restore es
  3254                                  
  3255 00000F3C C3                      	ret					;ac010; dms;
  3256                                  
  3257                                  
  3258                                  Ctrl_Break_Save 	endp			;ac010; dms;
  3259                                  
  3260                                  
  3261                                  ;=========================================================================
  3262                                  ; Set_Ctrl_Break	: This routine sets the CTRL-Break vector to one
  3263                                  ;			  defined by the user.
  3264                                  ;
  3265                                  ;	Inputs	: none
  3266                                  ;
  3267                                  ;	Outputs : CTRL_BREAK_VECTOR - holds address of INT 23h routine
  3268                                  ;=========================================================================
  3269                                  
  3270                                  Set_Ctrl_Break		proc	near		;ac010; dms;
  3271                                  
  3272 00000F3D 1E                      	push	ds				;ac010; dms;save ds
  3273 00000F3E 50                      	push	ax				;ac010; dms;save ax
  3274 00000F3F 53                      	push	bx				;ac010; dms;save bx
  3275 00000F40 52                      	push	dx				;ac010; dms;save dx
  3276                                  
  3277 00000F41 0E                      	push	cs				;ac010; dms;swap cs with ds
  3278 00000F42 1F                      	pop	ds				;an000; dms;point to code seg
  3279                                  
  3280 00000F43 BA[280F]                	mov	dx,offset Ctrl_Break_Write	;ac010; dms;get interrupt vec.
  3281 00000F46 B82325                  	mov	ax,2523h			;ac010; dms;set CTRL-BREAK
  3282                                  						;	    interrupt vector
  3283 00000F49 CD21                    	int	21h				;ac010; dms;
  3284                                  
  3285 00000F4B 5A                      	pop	dx				;ac010; dms;restore dx
  3286 00000F4C 5B                      	pop	bx				;ac010; dms;restore bx
  3287 00000F4D 58                      	pop	ax				;ac010; dms;restore ax
  3288 00000F4E 1F                      	pop	ds				;ac010; dms;restore ds
  3289                                  
  3290 00000F4F C3                      	ret					;ac010; dms;
  3291                                  
  3292                                  
  3293                                  Set_Ctrl_Break		endp			;ac010; dms;
  3294                                  
  3295                                  
  3296                                  ;=========================================================================
  3297                                  ; Reset_Ctrl_Break	: This routine resets the CTRL-Break vector to that
  3298                                  ;			  originally defined.
  3299                                  ;
  3300                                  ;	Inputs	: CTRL_BREAK_VECTOR - holds address of INT 23h routine
  3301                                  ;
  3302                                  ;	Outputs : none
  3303                                  ;=========================================================================
  3304                                  
  3305                                  Reset_Ctrl_Break	proc	near		;ac010; dms;
  3306                                  
  3307 00000F50 1E                      	push	ds				;ac010; dms;save ds
  3308 00000F51 50                      	push	ax				;ac010; dms;save ax
  3309 00000F52 53                      	push	bx				;ac010; dms;save bx
  3310 00000F53 52                      	push	dx				;ac010; dms;save ds
  3311                                  
  3312 00000F54 A1[8706]                	mov	ax,word ptr [Ctrl_Break_Vector+2] ;ac010; dms;get seg. of vector
  3313 00000F57 8B1E[8506]              	mov	bx,word ptr [Ctrl_Break_Vector]	;ac010; dms;get off. of vector
  3314 00000F5B 8ED8                    	mov	ds,ax				;ac010; dms;get seg.
  3315 00000F5D 89DA                    	mov	dx,bx				;ac010; dms;get off.
  3316 00000F5F B82325                  	mov	ax,2523h			;ac010; dms;set CTRL-BREAK
  3317                                  						;	    interrupt vector
  3318 00000F62 CD21                    	int	21h				;ac010; dms;
  3319                                  
  3320 00000F64 5A                      	pop	dx				;ac010; dms;restore dx
  3321 00000F65 5B                      	pop	bx				;ac010; dms;restore bx
  3322 00000F66 58                      	pop	ax				;ac010; dms;restore ax
  3323 00000F67 1F                      	pop	ds				;ac010; dms;restore ds
  3324                                  
  3325 00000F68 C3                      	ret					;ac010; dms;
  3326                                  
  3327                                  
  3328                                  Reset_Ctrl_Break	endp			;ac010; dms;
  3329                                  
  3330                                  ;=========================================================================
  3331                                  ; Get_Command_Path		: This routine finds the path where
  3332                                  ;				  COMMAND.COM resides based on the
  3333                                  ;				  environmental vector.  Once the
  3334                                  ;				  path is found it is copied to
  3335                                  ;				  CommandFile.
  3336                                  ;
  3337                                  ;	Inputs	: Exec_Block.Segment_Env - Segment of environmental vector
  3338                                  ;		  Comspec_ID		 - "COMSPEC="
  3339                                  ;
  3340                                  ;	Outputs : CommandFile		 - Holds path to COMMAND.COM
  3341                                  ;=========================================================================
  3342                                  
  3343                                  Procedure	Get_Command_Path		;an011; dms;
  3344                                  
  3345 00000F69 1E                      	push	ds				;an011; dms;save ds
  3346 00000F6A 06                      	push	es				;an011; dms;save es
  3347                                  
  3348 00000F6B 50B8[ssss]8ED81E07-     	Set_Data_Segment			;an011; dms; DS,ES = Data
  3348 00000F73 58                 
  3349 00000F74 E84F00                  	call	Get_PSP_Parms			;an011; dms; gets PSP info.
  3350 00000F77 FC                      	cld					;an011; dms; clear direction
  3351 00000F78 26A1[9606]              	mov	ax,[es:Environ_Segment]		;an011; dms; get seg. of
  3352                                  						;	     environ. vector
  3353 00000F7C 8ED8                    	mov	ds,ax				;an011; dms; put it in DS
  3354                                  	assume	ds:nothing			;an011; dms;
  3355 00000F7E 31F6                    	xor	si,si				;an011; dms; clear si
  3356 00000F80 89F3                    	mov	bx,si				;an011; dms; save si
  3357 00000F82 BF[8D06]                	mov	di,offset Comspec_ID		;an011; dms; point to target
  3358 00000F85 B97F00                  	mov	cx,127				;an011; dms; loop 127 times
  3359                                  ;	$do					;an011; dms; while cx not 0
  3360                                  DD_DO90:
  3361                                  						;	     and target not found
  3362 00000F88 83F900                  		cmp	cx,00h			;an011; dms; end of env.?
  3363                                  ;		$leave	e			;an011; dms; yes
  3364 00000F8B 7436                    		JE DD_EN90
  3365                                  
  3366 00000F8D 51                      		push	cx			;an011; dms; save cx
  3367 00000F8E B90800                  		mov	cx,0008h		;an011; dms; loop 8 times
  3368 00000F91 F3A6                    		repe	cmpsb			;an011; dms; "COMSPEC=" ?
  3369 00000F93 59                      		pop	cx			;an011; dms; restore cx
  3370                                  ;		$if	z			;an011; dms; yes
  3371 00000F94 751D                    		JNZ DD_IF92
  3372 00000F96 57                      			push	di		;an011; dms; save di
  3373 00000F97 BF[1405]                			mov	di,offset CommandFile   ;an011; dms
  3374 00000F9A AC                      			lodsb			;an011; dms; priming read
  3375 00000F9B 88C2                    			mov	dl,al		;an011; dms; prepare for capitalization
  3376 00000F9D E83802                  			call	Cap_Char	;an011; dms; capitalize character in DL
  3377 00000FA0 263A16[1405]            			cmp	dl,[es:CommandFile]  ;an011; dms;COMSPEC same as default drive?
  3378                                  ;			$if	e		;an000; dms; yes
  3379 00000FA5 7508                    			JNE DD_IF93
  3380                                  ;				$do		;an011; dms; while AL not = 0
  3381                                  DD_DO94:
  3382 00000FA7 3C00                    				    cmp  al,00h ;an011; dms; at end?
  3383                                  ;				    $leave  e	;an011; dms; yes
  3384 00000FA9 7404                    				    JE DD_EN94
  3385 00000FAB AA                      				    stosb	;an011; dms; save it
  3386 00000FAC AC                      				    lodsb	;an011; dms; get character
  3387                                  ;				$enddo
  3388 00000FAD EBF8                    				JMP SHORT DD_DO94
  3389                                  DD_EN94:
  3390                                  ;			$endif			;an011; dms;
  3391                                  DD_IF93:
  3392 00000FAF 5F                      			pop	di		;an011; dms; restore di
  3393 00000FB0 B9FFFF                  			mov	cx,0ffffh	;an011; dms; flag target found
  3394                                  ;		$endif				;an011; dms;
  3395                                  DD_IF92:
  3396                                  
  3397 00000FB3 83F9FF                  		cmp	cx,0ffffh		;an011; dms; target found?
  3398                                  ;		$leave	e			;an011; dms; yes
  3399 00000FB6 740B                    		JE DD_EN90
  3400                                  
  3401 00000FB8 BF[8D06]                		mov	di,offset Comspec_ID	;an011; dms; point to target
  3402 00000FBB 89DE                    		mov	si,bx			;an011; dms; restore si
  3403 00000FBD 46                      		inc	si			;an011; dms; point to next byte
  3404 00000FBE 89F3                    		mov	bx,si			;an011; dms; save si
  3405                                  
  3406 00000FC0 49                      		dec	cx			;an011; dms; decrease counter
  3407                                  ;	$enddo					;an011; dms;
  3408 00000FC1 EBC5                    	JMP SHORT DD_DO90
  3409                                  DD_EN90:
  3410                                  
  3411 00000FC3 07                      	pop	es				;an011; dms; restore es
  3412 00000FC4 1F                      	pop	ds				;an011; dms; restore ds
  3413                                  
  3414 00000FC5 C3                      	ret					;an011; dms;
  3415                                  
  3416                                  Get_Command_Path	endp			;an011; dms;
  3417                                  
  3418                                  
  3419                                  ;
  3420                                  ;****************************************************************************
  3421                                  ; Get_PSP_Parms
  3422                                  ;****************************************************************************
  3423                                  ;
  3424                                  ;
  3425                                  ;
  3426                                  ;
  3427                                  
  3428                                  Procedure Get_PSP_Parms 			;				;AC000;
  3429                                  
  3430 00000FC6 50B8[ssss]8ED81E07-     	Set_Data_Segment
  3430 00000FCE 58                 
  3431 00000FCF A1[0000]                	mov	ax,[PSP_Segment]			;Get segment of PSP		;AN000;
  3432 00000FD2 8ED8                    	mov	ds,ax				;  "  "    "  " 		;AN000;
  3433                                  						;     ;
  3434                                  	assume	ds:nothing
  3435                                  						;Setup segment of Environment string, get from PSP			    ;	  ;
  3436                                  
  3437 00000FD4 A12C00                  	mov	ax,[PSP_Environ]		;				;     ;
  3438 00000FD7 26A3[9606]              	mov	[es:Environ_Segment],ax		;				;     ;
  3439 00000FDB 50B8[ssss]8ED81E07-     	Set_Data_Segment
  3439 00000FE3 58                 
  3440 00000FE4 C3                      	ret					;				;     ;
  3441                                  
  3442                                  
  3443                                  Get_PSP_Parms endp				;				;AN000;
  3444                                  
  3445                                  
  3446                                  ;=========================================================================
  3447                                  ; Command_Root	:	This routine sets up CommandFile so that the
  3448                                  ;			COMMAND.COM will be written to the root.
  3449                                  ;			It does this by copying at offset 3 of CommandFile
  3450                                  ;			the literal COMMAND.COM.  This effectively
  3451                                  ;			overrides the original path, but maintains the
  3452                                  ;			drive letter that is to be written to.
  3453                                  ;
  3454                                  ;	Inputs	:	CommandFile - Holds full path to default COMMAND.COM
  3455                                  ;	Outputs :	CommandFile - Holds modified path to new COMMAND.COM
  3456                                  ;				      on target drive.
  3457                                  ;=========================================================================
  3458                                  
  3459                                  Procedure	Command_Root			;an011; dms;
  3460                                  
  3461 00000FE5 1E                      	push	ds				;an011; dms; save ds
  3462 00000FE6 06                      	push	es				;an011; dms; save es
  3463 00000FE7 57                      	push	di				;an011; dms; save di
  3464 00000FE8 56                      	push	si				;an011; dms; save si
  3465 00000FE9 51                      	push	cx				;an011; dms; save cx
  3466 00000FEA 50B8[ssss]8ED81E07-     	Set_Data_Segment			;an011;
  3466 00000FF2 58                 
  3467                                  
  3468 00000FF3 BF[1705]                	mov	di,offset CommandFile+3 	;an011; dms; point to path
  3469                                  						;	     past drive spec
  3470 00000FF6 BE[A205]                	mov	si,offset Command_Com		;an011; dms; holds the literal
  3471                                  						;	     COMMAND.COM
  3472 00000FF9 B90C00                  	mov	cx,000ch			;an011; dms; len. of literal
  3473 00000FFC F3A4                    	rep	movsb				;an011; dms; move it
  3474                                  
  3475 00000FFE 59                      	pop	cx				;an011; dms; restore cx
  3476 00000FFF 5E                      	pop	si				;an011; dms; restore si
  3477 00001000 5F                      	pop	di				;an011; dms; restore di
  3478 00001001 07                      	pop	es				;an011; dms; restore es
  3479 00001002 1F                      	pop	ds				;an011; dms; restore ds
  3480                                  
  3481 00001003 C3                      	ret					;an011; dms;
  3482                                  
  3483                                  Command_Root	endp				;an011; dms;
  3484                                  
  3485                                  
  3486                                  ;=========================================================================
  3487                                  ; Set_BPB_Info	:	When we have a FAT count of 0, we must calculate
  3488                                  ;			certain parts of the BPB.  The following code
  3489                                  ;			will do just that.
  3490                                  ;
  3491                                  ;	Inputs	: DeviceParameters
  3492                                  ;
  3493                                  ;	Outputs : BPB information
  3494                                  ;=========================================================================
  3495                                  
  3496                                  Procedure Set_BPB_Info								;an012; dms;calc new BPB
  3497                                  
  3498 00001004 50B8[ssss]8ED81E07-     	Set_Data_Segment							;an012; dms;set up addressibility
  3498 0000100C 58                 
  3499                                  BPB_NumberOfFats equ BPB_NUMBEROFFATS	; NASM port equate
  3500 0000100D 803E[3101]00            	cmp	byte [DeviceParameters + DP_BPB + BPB_NumberOfFats],00h			;an012; dms;see if we have 0 FATS specified
  3501                                  ;	$if	e								;an012; dms;yes, 0 FATS specified
  3502 00001012 7532                    	JNE DD_IF101
  3503 00001014 E83000                  		call	Scan_Disk_Table 					;an012; dms;access disk table
  3504 00001017 8A5C08                  		mov	bl,byte ptr [si+8]					;an012; dms;get FAT type
  3505 0000101A 8B4C04                  		mov	cx,word ptr [si+4]					;an012; dms;get sectors/cluster
  3506 0000101D 8B5406                  		mov	dx,word ptr [si+6]					;an012; dms;number of entries for the root DIR
  3507                                  
  3508 00001020 8916[3201]              		mov	[DeviceParameters + DP_BPB + BPB_RootEntries],dx		;an012; dms;save root entries
  3509 00001024 882E[2E01]              		mov	[DeviceParameters + DP_BPB + BPB_SectorsPerCluster],ch	;an012; dms;save sectors/cluster
  3510 00001028 C706[2C01]0002          		mov	word [DeviceParameters + DP_BPB + BPB_BytesPerSector],0200h	;an012; dms;save bytes/sector
  3511 0000102E C706[2F01]0100          		mov	word [DeviceParameters + DP_BPB + BPB_ReservedSectors],0001h	;an012; dms;save reserved sectors
  3512 00001034 C606[3101]02            		mov	byte [DeviceParameters + DP_BPB + BPB_NumberOfFats],02h		;an012; dms;FAT count
  3513                                  
  3514                                  FBIG equ Fbig	; NASM port equate
  3515 00001039 80FBFF                  		cmp	bl,FBIG 						;an012; dms;Big FAT?
  3516                                  ;		$if	e							;an012; dms;yes
  3517 0000103C 7505                    		JNE DD_IF102
  3518 0000103E E83000                  			call	Calc_Big_FAT					;an012; dms;calc big FAT info
  3519                                  ;		$else								;an012; dms;
  3520 00001041 EB03                    		JMP SHORT DD_EN102
  3521                                  DD_IF102:
  3522 00001043 E86D00                  			call	Calc_Small_FAT					;an012; dms;calc small FAT info
  3523                                  ;		$endif								;an012; dms;
  3524                                  DD_EN102:
  3525                                  ;	$endif									;an012; dms;
  3526                                  DD_IF101:
  3527                                  
  3528 00001046 C3                      	ret									;an012; dms;
  3529                                  
  3530                                  Set_BPB_Info	endp								;an012; dms;
  3531                                  
  3532                                  
  3533                                  
  3534                                  ;=========================================================================
  3535                                  ; Scan_Disk_Table	: Scans the table containing information on
  3536                                  ;			  the disk's attributes.  When it finds the
  3537                                  ;			  applicable data, it returns a pointer in
  3538                                  ;			  DS:SI for reference by the calling proc.
  3539                                  ;
  3540                                  ;	Inputs	: DiskTable - Contains data about disk types
  3541                                  ;
  3542                                  ;	Outputs : DS:SI     - Points to applicable disk data
  3543                                  ;=========================================================================
  3544                                  
  3545                                  Procedure Scan_Disk_Table							;an012; dms;
  3546                                  
  3547 00001047 833E[3401]00            	cmp	word [DeviceParameters + DP_BPB + BPB_TotalSectors],00h			;an012; dms;small disk?
  3548                                  ;	$if	ne								;an012; dms;yes
  3549 0000104C 7408                    	JE DD_IF106
  3550 0000104E BA0000                  		mov	dx,00h							;an012; dms;set high to 0
  3551 00001051 A1[3401]                		mov	ax,word ptr [DeviceParameters + DP_BPB + BPB_TotalSectors]	;an012; dms;get sector count
  3552                                  ;	$else									;an012; dms;
  3553 00001054 EB07                    	JMP SHORT DD_EN106
  3554                                  DD_IF106:
  3555 00001056 8B16[4301]              		mov	dx,word ptr [DeviceParameters + DP_BPB + BPB_BigTotalSectors + +2]	;an012; dms;get high count
  3556 0000105A A1[4101]                		mov	ax,word ptr [DeviceParameters + DP_BPB + BPB_BigTotalSectors + +0]	;an012; dms;get low count
  3557                                  ;	$endif									;an012; dms;
  3558                                  DD_EN106:
  3559                                  
  3560 0000105D BE[9806]                	mov	si,offset DiskTable						;an012; dms;point to disk data
  3561                                  Scan:
  3562                                  
  3563 00001060 3B14                    	cmp	dx,word ptr [si]						;an012; dms;below?
  3564 00001062 720C                    	jb	Scan_Disk_Table_Exit						;an012; dms;yes, exit
  3565 00001064 7705                    	ja	Scan_Next							;an012; dms;no, continue
  3566 00001066 3B4402                  	cmp	ax,word ptr [si+2]						;an012; dms;below or equal?
  3567 00001069 7605                    	jbe	Scan_Disk_Table_Exit						;an012; dms;yes, exit
  3568                                  
  3569                                  Scan_Next:
  3570                                  
  3571 0000106B 83C60A                  	add	si,5*2								;an012; dms;adjust pointer
  3572 0000106E EBF0                    	jmp	Scan								;an012; dms;continue scan
  3573                                  
  3574                                  Scan_Disk_Table_Exit:
  3575                                  
  3576 00001070 C3                      	ret									;an012; dms;
  3577                                  
  3578                                  Scan_Disk_Table endp								;an012; dms;
  3579                                  
  3580                                  
  3581                                  
  3582                                  ;=========================================================================
  3583                                  ; Calc_Big_FAT	:	Calculates the sectors per FAT for a 16 bit FAT.
  3584                                  ;
  3585                                  ;	Inputs	: DeviceParameters.DP_BPB.BPB_BigTotalSectors	or
  3586                                  ;		  DeviceParameters.DP_BPB.BPB_TotalSectors
  3587                                  ;
  3588                                  ;	Outputs : DeviceParameters.DP_BPB.BPB_SectorsPerFat
  3589                                  ;=========================================================================
  3590                                  
  3591                                  Procedure Calc_Big_FAT								;an012; dms;
  3592                                  
  3593 00001071 833E[3401]00            	cmp	word [DeviceParameters + DP_BPB + BPB_TotalSectors],00h			;an012; dms;small disk?
  3594                                  ;	$if	ne								;an012; dms;yes
  3595 00001076 7408                    	JE DD_IF109
  3596 00001078 BA0000                  		mov	dx,00h							;an012; dms;set high to 0
  3597 0000107B A1[3401]                		mov	ax,word ptr [DeviceParameters + DP_BPB + BPB_TotalSectors]	;an012; dms;get sector count
  3598                                  ;	$else									;an012; dms;
  3599 0000107E EB07                    	JMP SHORT DD_EN109
  3600                                  DD_IF109:
  3601 00001080 8B16[4301]              		mov	dx,word ptr [DeviceParameters + DP_BPB + BPB_BigTotalSectors + +2]	;an012; dms;get high count
  3602 00001084 A1[4101]                		mov	ax,word ptr [DeviceParameters + DP_BPB + BPB_BigTotalSectors + +0]	;an012; dms;get low count
  3603                                  ;	$endif									;an012; dms;
  3604                                  DD_EN109:
  3605                                  
  3606 00001087 B104                    	mov	cl,04h								;an012; dms;16 DIR entries per sector
  3607 00001089 52                      	push	dx								;an012; dms;save total sectors (high)
  3608 0000108A 8B16[3201]              	mov	dx,[DeviceParameters + DP_BPB + BPB_RootEntries]			;an012; dms;get root entry count
  3609 0000108E D3EA                    	shr	dx,cl								;an012; dms;divide by 16
  3610 00001090 29D0                    	sub	ax,dx								;an012; dms;
  3611 00001092 5A                      	pop	dx								;an012; dms;restore dx
  3612 00001093 83DA00                  	sbb	dx,0								;an012; dms;
  3613 00001096 83E801                  	sub	ax,1								;an012; dms;AX = T - R - D
  3614 00001099 83DA00                  	sbb	dx,0								;an012; dms;
  3615 0000109C B302                    	mov	bl,02h								;an012; dms;
  3616 0000109E 8A3E[2E01]              	mov	bh,[DeviceParameters + DP_BPB + BPB_SectorsPerCluster]		;an012; dms;get sectors per cluster
  3617 000010A2 01D8                    	add	ax,bx								;an012; dms;AX = T-R-D+256*SPC+2
  3618 000010A4 83D200                  	adc	dx,0								;an012; dms;
  3619 000010A7 83E801                  	sub	ax,1								;an012; dms;AX = T-R-D+256*SPC+1
  3620 000010AA 83DA00                  	sbb	dx,0								;an012; dms;
  3621 000010AD F7F3                    	div	bx								;an012; dms; sec/FAT = CEIL((TOTAL-DIR-RES)/
  3622                                  										;			    (256*SECPERCLUS+2)
  3623 000010AF A3[3701]                	mov	word ptr [DeviceParameters + DP_BPB + BPB_SectorsPerFAT],ax		;an012; dms;Sectors/cluster
  3624 000010B2 C3                      	ret									;an012; dms;
  3625                                  
  3626                                  Calc_Big_FAT	endp								;an012; dms;
  3627                                  
  3628                                  
  3629                                  ;=========================================================================
  3630                                  ; Calc_Small_FAT:	Calculates the sectors per FAT for a 12 bit FAT.
  3631                                  ;
  3632                                  ;	Inputs	: DeviceParameters.DP_BPB.BPB_BigTotalSectors	or
  3633                                  ;		  DeviceParameters.DP_BPB.BPB_TotalSectors
  3634                                  ;
  3635                                  ;	Outputs : DeviceParameters.DP_BPB.BPB_SectorsPerFat
  3636                                  ;=========================================================================
  3637                                  
  3638                                  Procedure Calc_Small_FAT							;an012; dms;
  3639                                  
  3640 000010B3 833E[3401]00            	cmp	word [DeviceParameters + DP_BPB + BPB_TotalSectors],00h			;an012; dms;small disk?
  3641                                  ;	$if	ne								;an012; dms;yes
  3642 000010B8 7408                    	JE DD_IF112
  3643 000010BA BA0000                  		mov	dx,00h							;an012; dms;set high to 0
  3644 000010BD A1[3401]                		mov	ax,word ptr [DeviceParameters + DP_BPB + BPB_TotalSectors]	;an012; dms;get sector count
  3645                                  ;	$else									;an012; dms;
  3646 000010C0 EB07                    	JMP SHORT DD_EN112
  3647                                  DD_IF112:
  3648 000010C2 8B16[4301]              		mov	dx,word ptr [DeviceParameters + DP_BPB + BPB_BigTotalSectors + +2]	;an012; dms;get high count
  3649 000010C6 A1[4101]                		mov	ax,word ptr [DeviceParameters + DP_BPB + BPB_BigTotalSectors + +0]	;an012; dms;get low count
  3650                                  ;	$endif									;an012; dms;
  3651                                  DD_EN112:
  3652                                  
  3653 000010C9 31DB                    	xor	bx,bx								;an012; dms;clear bx
  3654 000010CB 8A1E[2E01]              	mov	bl,[DeviceParameters + DP_BPB + BPB_SectorsPerCluster]		;an012; dms;get sectors/cluster
  3655 000010CF F7F3                    	div	bx								;an012; dms;
  3656                                  ; now multiply by 3/2
  3657 000010D1 BB0300                  	mov	bx,3								;an012; dms;
  3658 000010D4 F7E3                    	mul	bx								;an012; dms;div by log 2 of sectors/cluster
  3659 000010D6 BB0200                  	mov	bx,2								;an012; dms;
  3660 000010D9 F7F3                    	div	bx								;an012; dms;
  3661 000010DB 31D2                    	xor	dx,dx								;an012; dms;
  3662                                  ; now divide by 512
  3663 000010DD BB0002                  	mov	bx,512								;an012; dms;
  3664 000010E0 F7F3                    	div	bx								;an012; dms;
  3665 000010E2 40                      	inc	ax								;an012; dms;
  3666                                  ; dx:ax contains number of FAT sectors necessary
  3667 000010E3 A3[3701]                	mov	[DeviceParameters + DP_BPB + BPB_SectorsPerFAT],ax			;an012; dms;save sectors/FAT
  3668 000010E6 C3                      	ret									;an012; dms;
  3669                                  
  3670                                  Calc_Small_FAT	endp								;an012; dms;
  3671                                  
  3672                                  ;=========================================================================
  3673                                  ; Get_Bad_Sector_Hard	: Determine the bad sector.
  3674                                  ;
  3675                                  ;	Inputs	: Head of failing track
  3676                                  ;		  Cylinder of failing track
  3677                                  ;		  Relative_Sector_Low		- 1st. sector in track
  3678                                  ;		  Relative_Sector_High
  3679                                  ;
  3680                                  ;		  Cluster_Boundary_Adj_Factor	- The number of sectors
  3681                                  ;						  that are to be read
  3682                                  ;						  at one time.
  3683                                  ;		  Cluster_Boundary_SPT_Count	- Used by Calc_Cluster_Boundary
  3684                                  ;						  to track how many sectors
  3685                                  ;						  have been read.
  3686                                  ;		  Cluster_Boundary_Flag 	- True (Use cluster buffer)
  3687                                  ;						- False (Use internal buffer)
  3688                                  ;		  Cluster_Boundary_Buffer_Seg	- Segment of buffer
  3689                                  ;
  3690                                  ;	Outputs : Marked cluster as bad
  3691                                  ;=========================================================================
  3692                                  
  3693                                  Procedure Get_Bad_Sector_Hard							;an000; dms;
  3694                                  
  3695 000010E7 51                      	push	cx								;an000; dms;save cx
  3696 000010E8 B90100                  	mov	cx,0001h							;an000; dms;set counter to start at 1
  3697 000010EB C706[CE06]0000          	mov	word [Cluster_Boundary_SPT_Count],00h					;an000; dms;clear sector counter
  3698 000010F1 C706[CC06]0100          	mov	word [Cluster_Boundary_Adj_Factor],01h 				;an000; dms;default value
  3699                                  ;	$do									;an000; dms;while sectors left
  3700                                  DD_DO115:
  3701 000010F7 3B0E[3901]              		cmp	cx,[DeviceParameters + DP_BPB + BPB_SectorsPerTrack]		;an000; dms;at end?
  3702                                  ;		$leave	a							;an000; dms;yes,exit
  3703 000010FB 775F                    		JA DD_EN115
  3704 000010FD 51                      		push	cx							;an000; dms;save cx
  3705                                  
  3706 000010FE 803E[D006]FF            		cmp	byte [Cluster_Boundary_Flag],True				;an000; dms;full buffer there?
  3706          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  3707                                  ;		$if	e							;an000; dms;yes
  3708 00001103 7511                    		JNE DD_IF117
  3709 00001105 E83401                  			call	Calc_Cluster_Boundary				;an000; dms;see if on boundary
  3710 00001108 A1[D106]                			mov	ax,[Cluster_Boundary_Buffer_Seg]
  3711                                  TRWP_TransferAddress equ TRWP_TRANSFERADDRESS	; NASM port equate
  3712 0000110B C706[5B02]0000          			mov	word ptr [RWPacket + TRWP_TransferAddress + 0],0	;an000; dms;point to transfer area
  3713 00001111 A3[5D02]                			mov	word ptr [RWPacket + TRWP_TransferAddress + 2],ax	;an000; dms;
  3714                                  ;		$else								;an000; dms;default to internal buffer
  3715 00001114 EB0A                    		JMP SHORT DD_EN117
  3716                                  DD_IF117:
  3717 00001116 C706[5B02][5F02]        			mov	word ptr [RWPacket + TRWP_TransferAddress + 0],offset RW_TRF_Area  ;an000; dms;point to transfer area
  3718 0000111C 8C1E[5D02]              			mov	word ptr [RWPacket + TRWP_TransferAddress + 2],DS	;an000; dms;
  3719                                  ;		$endif								;an000; dms;
  3720                                  DD_EN117:
  3721                                  
  3722 00001120 E83B00                  		call	Verify_Structure_Set_Up 				;an019; dms; set up verify vars
  3723                                  
  3724 00001123 B80D44                  		mov	ax,(IOCTL << 8) | GENERIC_IOCTL			;an000; dms;
  3725 00001126 31DB                    		xor	bx,bx							;an000; dms;clear bx
  3726 00001128 8A1E[8206]              		mov	bl,[drive]						;an000; dms;get drive
  3727 0000112C FEC3                    		inc	bl							;an000; dms;adjust it
  3728 0000112E B96108                  		mov	cx,(IOC_DC << 8) | READ_TRACK 			;an000; dms;read track
  3729 00001131 8D16[5202]              		lea	dx,[RWPacket]						;an000; dms;point to parms
  3730 00001135 CD21                    		int	21h							;an000; dms;
  3731                                  
  3732 00001137 59                      		pop	cx							;an000; dms;restore cx
  3733                                  
  3734 00001138 51                      		push	cx							;an000; dms;save cx
  3735                                  
  3736                                  ;		$if	c							;an000; dms;an error occurred
  3737 00001139 7306                    		JNC DD_IF120
  3738 0000113B E86C00                  			call	Calc_Cluster_Position				;an000; dms;determine which cluster
  3739 0000113E E83EF0                  			call	BadClus 					;an000; dms;mark the cluster as bad
  3740                                  ;		$endif								;an000; dms;
  3741                                  DD_IF120:
  3742                                  
  3743 00001141 59                      		pop	cx							;an000; dms;restore cx
  3744                                  
  3745 00001142 030E[CC06]              		add	cx,[Cluster_Boundary_Adj_Factor]				;an000; dms;adjust loop counter
  3746 00001146 A1[CC06]                		mov	ax,[Cluster_Boundary_Adj_Factor]				;an000; dms;get adjustment factor
  3747 00001149 31D2                    		xor	dx,dx							;an000; dms;clear dx
  3748 0000114B 0306[D306]              		add	ax,[Relative_Sector_Low]					;an000; dms;add in low word
  3749 0000114F 1316[D506]              		adc	dx,[Relative_Sector_High] 				;an000; dms;pick up carry in high word
  3750 00001153 A3[D306]                		mov	[Relative_Sector_Low],ax					;an000; dms;save low word
  3751 00001156 8916[D506]              		mov	[Relative_Sector_High],dx 				;an000; dms;save high word
  3752                                  
  3753                                  
  3754                                  ;	$enddo									;an000; dms;
  3755 0000115A EB9B                    	JMP SHORT DD_DO115
  3756                                  DD_EN115:
  3757                                  
  3758 0000115C 59                      	pop	cx								;an000; dms;restore cx
  3759                                  
  3760 0000115D C3                      	ret									;an000; dms;
  3761                                  
  3762                                  Get_Bad_Sector_Hard	endp							;an000; dms;
  3763                                  
  3764                                  
  3765                                  ;=========================================================================
  3766                                  ; Verify_Structure_Set_Up	: Set up the fields for the Read IOCTL
  3767                                  ;				  to verify the sectors in a failing
  3768                                  ;				  track.  Also, it displays the
  3769                                  ;				  message notifying the user of the
  3770                                  ;				  sectors it is verifying.
  3771                                  ;=========================================================================
  3772                                  
  3773                                  Procedure	Verify_Structure_Set_Up 					;an019; dms;set up verify structure
  3774                                  
  3775                                  TRWP_SpecialFunctions equ TRWP_SPECIALFUNCTIONS	; NASM port equate
  3776 0000115E C606[5202]00            	mov	byte [RWPacket + TRWP_SpecialFunctions],00h				;an000; dms;reset special functions
  3777                                  
  3778 00001163 A1[4C02]                	mov	ax,[FormatPacket + FP_Head] 					;an000; dms;get current head
  3779                                  TRWP_Head equ TRWP_HEAD	; NASM port equate
  3780 00001166 A3[5302]                	mov	[RWPacket + TRWP_Head],ax						;an000; dms;get current head
  3781                                  
  3782 00001169 A1[4E02]                	mov	ax,[FormatPacket + FP_Cylinder]					;an000; dms;get current cylinder
  3783                                  TRWP_Cylinder equ TRWP_CYLINDER	; NASM port equate
  3784 0000116C A3[5502]                	mov	[RWPacket + TRWP_Cylinder],ax					;an000; dms;get current cylinder
  3785                                  
  3786 0000116F 49                      	dec	cx								;an000; dms;make sector 0 based
  3787                                  TRWP_FirstSector equ TRWP_FIRSTSECTOR	; NASM port equate
  3788 00001170 890E[5702]              	mov	[RWPacket + TRWP_FirstSector],cx					;an000; dms;get sector to read
  3789                                  
  3790 00001174 A1[CC06]                	mov	ax,[Cluster_Boundary_Adj_Factor]					;an000; dms;get # of sectors to read
  3791                                  TRWP_SectorsToReadWrite equ TRWP_SECTORSTOREADWRITE	; NASM port equate
  3792 00001177 A3[5902]                	mov	[RWPacket + TRWP_SectorsToReadWrite],ax				;an000; dms;read only # sector(s)
  3793                                  
  3794 0000117A E82D00                  	call	Calc_Cluster_Position						;an019; dms;determine cluster number
  3795 0000117D 8916[DF06]              	mov	word ptr [Msg_Allocation_Unit_Val + +2],dx 			;an019; dms;save high word of cluster
  3796 00001181 A3[DD06]                	mov	word ptr [Msg_Allocation_Unit_Val + +0],ax 			;an019; dms;save low word of cluster
  3797 00001184 BA[0000]E8(0000)        	message MsgVerify
  3798                                  
  3799 0000118A C3                      	ret
  3800                                  
  3801                                  Verify_Structure_Set_Up endp							;an019; dms;
  3802                                  
  3803                                  
  3804                                  ;=========================================================================
  3805                                  ; Get_Bad_Sector_Floppy : This routine marks an entire track as bad
  3806                                  ;			  since it is a floppy disk.
  3807                                  ;
  3808                                  ;	Inputs	: Relative_Sector_Low	- first sector
  3809                                  ;
  3810                                  ;	Outputs : FAT marked with bad sectors
  3811                                  ;=========================================================================
  3812                                  
  3813                                  Procedure Get_Bad_Sector_Floppy 						;an000; dms;
  3814                                  
  3815 0000118B 53                      	push	bx								;an000; dms;save regs
  3816 0000118C 51                      	push	cx								;an000; dms;
  3817                                  
  3818 0000118D 8B0E[3901]              	mov	cx,[DeviceParameters + DP_BPB + BPB_SectorsPerTrack]			;an000; dms;get sectors/track
  3819                                  ;	$do									;an000; dms;while sectors left
  3820                                  DD_DO123:
  3821 00001191 83F900                  		cmp	cx,00							;an000; dms;at end
  3822                                  ;		$leave	e							;an000; dms;yes
  3823 00001194 7411                    		JE DD_EN123
  3824 00001196 53                      		push	bx							;an000; dms;save bx we destroy it
  3825 00001197 51                      		push	cx							;an000; dms;save cx we destroy it
  3826 00001198 E80F00                  		call	Calc_Cluster_Position					;an000; dms;get cluster position
  3827 0000119B E8E1EF                  		call	BadClus 						;an000; dms;mark it as bad
  3828 0000119E 59                      		pop	cx							;an000; dms;restore regs
  3829 0000119F 5B                      		pop	bx							;an000; dms;
  3830 000011A0 49                      		dec	cx							;an000; dms;decrease loop counter
  3831 000011A1 FF06[D306]              		inc	word [Relative_Sector_Low]					;an000; dms;next sector
  3832                                  ;	$enddo									;an000; dms;
  3833 000011A5 EBEA                    	JMP SHORT DD_DO123
  3834                                  DD_EN123:
  3835                                  
  3836 000011A7 59                      	pop	cx								;an000; dms;restore regs
  3837 000011A8 5B                      	pop	bx								;an000; dms;
  3838                                  
  3839 000011A9 C3                      	ret									;an000; dms;
  3840                                  
  3841                                  Get_Bad_Sector_Floppy	endp							;an000; dms;
  3842                                  
  3843                                  
  3844                                  ;=========================================================================
  3845                                  ; Calc_Cluster_Position : This routine calculates which cluster the
  3846                                  ;			  failing sector falls in.
  3847                                  ;
  3848                                  ;	Inputs	: Relative_Sector_High	- high word of sector position
  3849                                  ;		  Relative_Sector_Low	- low word of sector position
  3850                                  ;
  3851                                  ;	Outputs : DX:AX - Cluster position
  3852                                  ;=========================================================================
  3853                                  Procedure Calc_Cluster_Position 						;an000; dms;
  3854                                  
  3855 000011AA 51                      	push	cx								;an000; dms;save regs
  3856 000011AB 57                      	push	di								;an000; dms;
  3857 000011AC 56                      	push	si								;an000; dms;
  3858                                  
  3859 000011AD 31D2                    	xor	dx,dx								;an000; dms;clear high word
  3860 000011AF 8B16[D506]              	mov	dx,word ptr [Relative_Sector_High]				;an000; dms;get the high sector word
  3861 000011B3 A1[D306]                	mov	ax,word ptr [Relative_Sector_Low] 				;an000; dms;get the low sector word
  3862                                  StartSector equ startSector	; NASM port label
  3863 000011B6 2B06[5F04]              	sub	ax,[StartSector]							;an000; dms;get relative sector #
  3864 000011BA 83DA00                  	sbb	dx,0								;an000; dms;pick up borrow
  3865                                  
  3866 000011BD 89D6                    	mov	si,dx								;an000; dms;get high word
  3867 000011BF 89C7                    	mov	di,ax								;an000; dms;get low word
  3868 000011C1 31C9                    	xor	cx,cx								;an000; dms;clear cx
  3869 000011C3 8A0E[2E01]              	mov	cl,[DeviceParameters + DP_BPB + BPB_SectorsPerCluster]		;an000; dms;get sectors/cluster
  3870 000011C7 E815FD                  	call	Divide_32_Bits							;an000; dms;32 bit division
  3871                                  
  3872 000011CA 89F2                    	mov	dx,si								;an000; dms;get high word of result
  3873 000011CC 89F8                    	mov	ax,di								;an000; dms;get low word of result
  3874 000011CE 83C002                  	add	ax,2								;an000; dms;adjust for cluster bias
  3875 000011D1 83D200                  	adc	dx,0								;an000; dms;pick up carry
  3876                                  
  3877 000011D4 5E                      	pop	si								;an000; dms;restore regs
  3878 000011D5 5F                      	pop	di								;an000; dms;
  3879 000011D6 59                      	pop	cx								;an000; dms;
  3880                                  
  3881 000011D7 C3                      	ret									;an000 ;dms;
  3882                                  
  3883                                  Calc_Cluster_Position	endp							;an000; dms;
  3884                                  
  3885                                  
  3886                                  ;=========================================================================
  3887                                  ; Cap_Char	: This routine will capitalize the character passed in
  3888                                  ;		  DL.
  3889                                  ;
  3890                                  ;	Inputs	: DL - Character to be capitalized
  3891                                  ;
  3892                                  ;	Outputs : DL - Capitalized character
  3893                                  ;=========================================================================
  3894                                  
  3895                                  Procedure Cap_Char								;an011; dms;
  3896                                  
  3897 000011D8 50                      	push	ax								;an011; dms;save ax
  3898 000011D9 B82065                  	mov	ax,6520h							;an011; dms;capitalize character
  3899 000011DC CD21                    	int	21h								;an011; dms;
  3900 000011DE 58                      	pop	ax								;an011; dms;restore ax
  3901 000011DF C3                      	ret									;an011; dms;
  3902                                  
  3903                                  Cap_Char	endp								;an011; dms;
  3904                                  
  3905                                  ;=========================================================================
  3906                                  ; Set_Disk_Access_On_Off: This routine will either turn access on or off
  3907                                  ;			  to a disk depending on the contents of the
  3908                                  ;			  buffer passed in DX.
  3909                                  ;
  3910                                  ;	Inputs	: DX - pointer to buffer
  3911                                  ;
  3912                                  ;=========================================================================
  3913                                  
  3914                                  Procedure Set_Disk_Access_On_Off						;an014; dms;
  3915                                  
  3916 000011E0 50                      	push	ax								;an014; dms;save regs
  3917 000011E1 53                      	push	bx								;an014; dms;
  3918 000011E2 51                      	push	cx								;an014; dms;
  3919 000011E3 52                      	push	dx								;an014; dms;
  3920                                  
  3921 000011E4 31DB                    	xor	bx,bx								;an014; dms;clear bx
  3922                                  Drive equ drive	; NASM port label
  3923 000011E6 8A1E[8206]              	mov	bl,[Drive]							;an014; dms;get driver number
  3924 000011EA FEC3                    	inc	bl								;an014; dms;make it 1 based
  3925 000011EC E8D0F1                  	call	IsRemovable							;an014; dms;see if removable media
  3926                                  ;	$if	c								;an014; dms;not removable
  3927 000011EF 7310                    	JNC DD_IF126
  3928                                  Generic_IOCTL equ GENERIC_IOCTL	; NASM port equate
  3929 000011F1 B80D44                  		mov	ax,(IOCTL << 8) | Generic_IOCTL			;an014; dms;generic ioctl
  3930 000011F4 31DB                    		xor	bx,bx							;an014; dms;clear bx
  3931 000011F6 8A1E[8206]              		mov	bl,[Drive]						;an014; dms;get drive letter
  3932 000011FA FEC3                    		inc	bl							;an014; dms;make it 1 based
  3933                                  Set_Access_Flag equ SET_ACCESS_FLAG	; NASM port equate
  3934 000011FC B94708                  		mov	cx,(RAWIO << 8) | Set_Access_Flag			;an014; dms;allow access to disk
  3935 000011FF CD21                    		int	21h							;an014; dms;
  3936                                  ;	$endif									;an014; dms;
  3937                                  DD_IF126:
  3938                                  
  3939 00001201 5A                      	pop	dx								;an014; dms;restore regs
  3940 00001202 59                      	pop	cx								;an014; dms;
  3941 00001203 5B                      	pop	bx								;an014; dms;
  3942 00001204 58                      	pop	ax								;an014; dms;
  3943                                  
  3944 00001205 C3                      	ret									;an014; dms;
  3945                                  
  3946                                  Set_Disk_Access_On_Off	endp							;an014; dms;
  3947                                  
  3948                                  
  3949                                  ;=========================================================================
  3950                                  ; Get_Disk_Access	: This routine will determine the access state of
  3951                                  ;			  the disk.
  3952                                  ;
  3953                                  ;	Inputs	: DX - pointer to buffer
  3954                                  ;	Outputs : Disk_Access.DAC_Access_Flag - 0ffh signals access allowed
  3955                                  ;						to the disk previously.
  3956                                  ;
  3957                                  ;=========================================================================
  3958                                  
  3959                                  Procedure Get_Disk_Access							;an014; dms;
  3960                                  
  3961 00001206 50                      	push	ax								;an014; dms;save regs
  3962 00001207 53                      	push	bx								;an014; dms;
  3963 00001208 51                      	push	cx								;an014; dms;
  3964 00001209 52                      	push	dx								;an014; dms;
  3965                                  
  3966 0000120A 31DB                    	xor	bx,bx								;an014; dms;clear bx
  3967 0000120C 8A1E[8206]              	mov	bl,[Drive]							;an014; dms;get driver number
  3968 00001210 FEC3                    	inc	bl								;an014; dms;make it 1 based
  3969 00001212 E8AAF1                  	call	IsRemovable							;an014; dms;see if removable media
  3970                                  ;	$if	c								;an014; dms;not removable
  3971 00001215 7320                    	JNC DD_IF128
  3972 00001217 B80D44                  		mov	ax,(IOCTL << 8) | Generic_IOCTL			;an014; dms;generic ioctl
  3973 0000121A 31DB                    		xor	bx,bx							;an014; dms;clear bx
  3974 0000121C 8A1E[8206]              		mov	bl,[Drive]						;an014; dms;get drive letter
  3975 00001220 FEC3                    		inc	bl							;an014; dms;make it 1 based
  3976                                  Get_Access_Flag equ GET_ACCESS_FLAG	; NASM port equate
  3977 00001222 B96708                  		mov	cx,(RAWIO << 8) | Get_Access_Flag			;an014; dms;determine disk access
  3978 00001225 8D16[4902]              		lea	dx,[Disk_Access]						;an014; dms;point to parm list
  3979 00001229 CD21                    		int	21h							;an014; dms;
  3980 0000122B 803E[4A02]01            		cmp	byte [Disk_Access + DAC_Access_Flag],01h 			;an014; dms;access is currently allowed?
  3981                                  ;		$if	e							;an014; dms;yes
  3982 00001230 7505                    		JNE DD_IF129
  3983 00001232 C606[4A02]FF            			mov	byte [Disk_Access + DAC_Access_Flag],0ffh		;an014; dms;signal access is currently allowed
  3984                                  ;		$endif								;an014; dms;
  3985                                  DD_IF129:
  3986                                  ;	$endif									;an014; dms;
  3987                                  DD_IF128:
  3988                                  
  3989 00001237 5A                      	pop	dx								;an014; dms;restore regs
  3990 00001238 59                      	pop	cx								;an014; dms;
  3991 00001239 5B                      	pop	bx								;an014; dms;
  3992 0000123A 58                      	pop	ax								;an014; dms;
  3993                                  
  3994 0000123B C3                      	ret									;an014; dms;
  3995                                  
  3996                                  Get_Disk_Access 	endp							;an014; dms;
  3997                                  
  3998                                  ;=========================================================================
  3999                                  ; Calc_Cluster_Boundary : This routine will determine where, within a
  4000                                  ;			  cluster, a sector resides.
  4001                                  ;
  4002                                  ;	Inputs	: Relative_Sector_Low		- Sector
  4003                                  ;		  Relative_Sector_High
  4004                                  ;
  4005                                  ;	Outputs : Cluster_Boundary_Adj_Factor	- The number of sectors
  4006                                  ;						  remaining in the cluster.
  4007                                  ;		  Cluster_Boundary_SPT_Count	- The count of sectors
  4008                                  ;						  having been accessed for
  4009                                  ;						  a track.
  4010                                  ;=========================================================================
  4011                                  
  4012                                  Procedure Calc_Cluster_Boundary 						;an000; dms;
  4013                                  
  4014 0000123C 50                      	push	ax								;an000; dms;save regs
  4015 0000123D 53                      	push	bx								;an000; dms;
  4016 0000123E 51                      	push	cx								;an000; dms;
  4017 0000123F 52                      	push	dx								;an000; dms;
  4018 00001240 56                      	push	si								;an000; dms;
  4019 00001241 57                      	push	di								;an000; dms;
  4020                                  
  4021 00001242 31D2                    	xor	dx,dx								;an000; dms;clear high word
  4022 00001244 8B16[D506]              	mov	dx,word ptr [Relative_Sector_High]				;an000; dms;get the high sector word
  4023 00001248 A1[D306]                	mov	ax,word ptr [Relative_Sector_Low] 				;an000; dms;get the low sector word
  4024 0000124B 2B06[5F04]              	sub	ax,[StartSector]							;an000; dms;get relative sector #
  4025 0000124F 83DA00                  	sbb	dx,0								;an000; dms;pick up borrow
  4026                                  
  4027 00001252 89D6                    	mov	si,dx								;an000; dms;get high word
  4028 00001254 89C7                    	mov	di,ax								;an000; dms;get low word
  4029 00001256 31C9                    	xor	cx,cx								;an000; dms;clear cx
  4030 00001258 8A0E[2E01]              	mov	cl,[DeviceParameters + DP_BPB + BPB_SectorsPerCluster]		;an000; dms;get sectors/cluster
  4031 0000125C E880FC                  	call	Divide_32_Bits							;an000; dms;32 bit division
  4032                                  
  4033 0000125F 09C9                    	or	cx,cx								;an000; dms;see if remainder exists
  4034                                  ;	$if	nz								;an000; dms;remainder exists
  4035 00001261 740E                    	JZ DD_IF132
  4036 00001263 31DB                    		xor	bx,bx							;an021; dms;
  4037 00001265 8A1E[2E01]              		mov	bl,[DeviceParameters + DP_BPB + BPB_SectorsPerCluster]	;an021; dms;get sectors/cluster
  4038 00001269 29CB                    		sub	bx,cx							;an021; dms;get number of sectors to read
  4039 0000126B 891E[CC06]              		mov	[Cluster_Boundary_Adj_Factor],bx				;ac021; dms;remainder = sector count
  4040                                  ;	$else									;an000; dms;no remainder
  4041 0000126F EB0A                    	JMP SHORT DD_EN132
  4042                                  DD_IF132:
  4043 00001271 31DB                    		xor	bx,bx							;an000; dms;clear bx
  4044 00001273 8A1E[2E01]              		mov	bl,[DeviceParameters + DP_BPB + BPB_SectorsPerCluster]	;an000; dms;get sectors/cluster
  4045 00001277 891E[CC06]              		mov	[Cluster_Boundary_Adj_Factor],bx				;an000; dms;get sectors/cluster
  4046                                  ;	$endif									;an000; dms;
  4047                                  DD_EN132:
  4048                                  
  4049 0000127B A1[CE06]                	mov	ax,[Cluster_Boundary_SPT_Count]					;an000; dms;get current sector count
  4050 0000127E 31D2                    	xor	dx,dx								;an000; dms;clear high word
  4051 00001280 0306[CC06]              	add	ax,[Cluster_Boundary_Adj_Factor]					;an000; dms;get next sector count
  4052 00001284 3B06[3901]              	cmp	ax,[DeviceParameters + DP_BPB + BPB_SectorsPerTrack]			;an000; dms;exceeded sectors/track?
  4053                                  ;	$if	a								;an000; dms;yes
  4054 00001288 760A                    	JNA DD_IF135
  4055 0000128A A1[3901]                		mov	ax,[DeviceParameters + DP_BPB + BPB_SectorsPerTrack]		;an000; dms;only use difference
  4056 0000128D 2B06[CE06]              		sub	ax,[Cluster_Boundary_SPT_Count]				;an000; dms;get next sector count
  4057 00001291 A3[CC06]                		mov	[Cluster_Boundary_Adj_Factor],ax				;an000; dms;
  4058                                  ;	$endif									;an000; dms;
  4059                                  DD_IF135:
  4060                                  
  4061 00001294 A1[CE06]                	mov	ax,[Cluster_Boundary_SPT_Count]					;an000; dms;get sector count
  4062 00001297 31D2                    	xor	dx,dx								;an000; dms;clear high word
  4063 00001299 0306[CC06]              	add	ax,[Cluster_Boundary_Adj_Factor]					;an000; dms;get new sector count
  4064 0000129D A3[CE06]                	mov	[Cluster_Boundary_SPT_Count],ax					;an000; dms;save it
  4065                                  
  4066 000012A0 5F                      	pop	di								;an000; dms;restore regs
  4067 000012A1 5E                      	pop	si								;an000; dms;
  4068 000012A2 5A                      	pop	dx								;an000; dms;restore regs
  4069 000012A3 59                      	pop	cx								;an000; dms;
  4070 000012A4 5B                      	pop	bx								;an000; dms;
  4071 000012A5 58                      	pop	ax								;an000; dms;
  4072                                  
  4073 000012A6 C3                      	ret									;an000; dms;
  4074                                  
  4075                                  Calc_Cluster_Boundary	endp							;an000; dms;
  4076                                  
  4077                                  ;=========================================================================
  4078                                  ; Cluster_Buffer_Allocate	: This routine will allocate a buffer
  4079                                  ;				  based on a cluster's size.  If enough
  4080                                  ;				  space does not exist, a cluster will
  4081                                  ;				  be redefined to a smaller size for
  4082                                  ;				  purposes of sector retries.
  4083                                  ;
  4084                                  ;	Inputs	: DeviceParameters.DP_BPB.BPB_BytesPerSector
  4085                                  ;		  DeviceParameters.DP_BPB.BPB_SectorsPerCluster
  4086                                  ;
  4087                                  ;	Outputs : Cluster_Boundary_Flag 	- True (space available)
  4088                                  ;						  False(not enough space)
  4089                                  ;		  Cluster_Boundary_Buffer_Seg	- Pointer to buffer
  4090                                  ;=========================================================================
  4091                                  
  4092                                  Procedure Cluster_Buffer_Allocate						;an000; dms;
  4093                                  
  4094 000012A7 50                      	push	ax								;an000; dms;save regs
  4095 000012A8 53                      	push	bx								;an000; dms;
  4096 000012A9 51                      	push	cx								;an000; dms;
  4097 000012AA 52                      	push	dx								;an000; dms;
  4098                                  
  4099 000012AB B80048                  	mov	ax,(Alloc << 8)						;an000; dms;allocate memory
  4100 000012AE BBFFFF                  	mov	bx,0ffffh							;an000; dms;get available memory
  4101 000012B1 CD21                    	int	21h								;an000; dms;
  4102                                  
  4103 000012B3 A1[2C01]                	mov	ax,[DeviceParameters + DP_BPB + BPB_BytesPerSector]			;an000; dms;get bytes/sector
  4104 000012B6 31D2                    	xor	dx,dx								;an000; dms;clear high word
  4105 000012B8 31C9                    	xor	cx,cx								;an000; dms;clear cx
  4106 000012BA 8A0E[2E01]              	mov	cl,[DeviceParameters + DP_BPB + BPB_SectorsPerCluster]		;an000; dms;get sector count
  4107 000012BE F7E1                    	mul	cx								;an000; dms;get total byte count
  4108 000012C0 B104                    	mov	cl,4								;an000; dms;set up shift count
  4109 000012C2 D3E8                    	shr	ax,cl								;an000; dms;divide by 16
  4110 000012C4 40                      	inc	ax								;an000; dms;round up
  4111                                  
  4112 000012C5 39C3                    	cmp	bx,ax								;an000; dms;enough room
  4113                                  ;	$if	a								;an000; dms;yes
  4114 000012C7 7611                    	JNA DD_IF137
  4115 000012C9 89C3                    		mov	bx,ax							;an000; dms;allocate needed memory
  4116 000012CB B80048                  		mov	ax,(Alloc << 8)					;an000; dms;
  4117 000012CE CD21                    		int	21h							;an000; dms;
  4118 000012D0 A3[D106]                		mov	[Cluster_Boundary_Buffer_Seg],ax				;an000; dms;save pointer to buffer
  4119 000012D3 C606[D006]FF            		mov	byte [Cluster_Boundary_Flag],True				;an000; dms;signal space available
  4119          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  4120                                  ;	$else									;an000; dms;not enough room
  4121 000012D8 EB05                    	JMP SHORT DD_EN137
  4122                                  DD_IF137:
  4123 000012DA C606[D006]00            		mov	byte [Cluster_Boundary_Flag],False				;an000; dms;signal not enough space
  4124                                  ;	$endif									;an000; dms;
  4125                                  DD_EN137:
  4126                                  
  4127 000012DF 5A                      	pop	dx								;an000; dms;restore regs
  4128 000012E0 59                      	pop	cx								;an000; dms;
  4129 000012E1 5B                      	pop	bx								;an000; dms;
  4130 000012E2 58                      	pop	ax								;an000; dms;
  4131                                  
  4132 000012E3 C3                      	ret									;an000; dms;
  4133                                  
  4134                                  Cluster_Buffer_Allocate endp							;an000; dms;
  4135                                  
  4136                                  
  4137                                  ;=========================================================================
  4138                                  ; Set_CDS_Off			- This routine disallows access to a
  4139                                  ;				  disk if a format fails on a non-FAT
  4140                                  ;				  formatted disk.
  4141                                  ;
  4142                                  ;=========================================================================
  4143                                  
  4144                                  Procedure Set_CDS_Off								;an000; dms;
  4145                                  
  4146 000012E4 50                      	push	ax								;an000; dms;save regs
  4147 000012E5 52                      	push	dx								;an000; dms;
  4148                                  
  4149 000012E6 B8085F                  	mov	ax,5f08h							;an000; dms;reset CDS
  4150 000012E9 8A16[8206]              	mov	dl,[Drive]							;an000; dms;drive to reset
  4151 000012ED CD21                    	int	21h								;an000; dms;
  4152                                  
  4153 000012EF 5A                      	pop	dx								;an000; dms;restore regs
  4154 000012F0 58                      	pop	ax								;an000; dms;
  4155                                  
  4156 000012F1 C3                      	ret									;an000; dms;
  4157                                  
  4158                                  Set_CDS_Off	endp								;an000; dms;
  4159                                  
  4160                                  
  4161                                  ;=========================================================================
  4162                                  ; Format_Access_Wrap_Up 	- This routine determines whether or
  4163                                  ;				  not access should be allowed to the
  4164                                  ;				  disk based on the exit status of
  4165                                  ;				  format.
  4166                                  ;
  4167                                  ;=========================================================================
  4168                                  
  4169                                  Procedure Format_Access_Wrap_Up 						;an000; dms;
  4170                                  
  4171 000012F2 803E[4A02]FF            	cmp	byte [Disk_Access + DAC_Access_Flag],0ffh				;an015; dms;access prev. allowed?
  4172                                  ;	$if	ne								;an015; dms;no
  4173 000012F7 7421                    	JE DD_IF140
  4174 000012F9 803E[8304]00            		cmp	byte [ExitStatus],ExitOK					;an015; dms;good exit?
  4175                                  ;	       $if     ne							;an015; dms;no
  4176 000012FE 740E                    	       JE DD_IF141
  4177 00001300 8D16[4902]              		       lea     dx,[Disk_Access]					;an015; dms;point to parm block
  4178 00001304 C606[4A02]00            		       mov     byte [Disk_Access + DAC_Access_Flag],00h			;an015; dms;signal no disk access
  4179 00001309 E8D4FE                  		       call    Set_Disk_Access_On_Off				;an015; dms;don't allow disk access
  4180                                  ;	       $else								;an015; dms;bad exit
  4181 0000130C EB0C                    	       JMP SHORT DD_EN141
  4182                                  DD_IF141:
  4183 0000130E 8D16[4902]              		       lea     dx,[Disk_Access]					;an015; dms;point to parm block
  4184 00001312 C606[4A02]01            		       mov     byte [Disk_Access + DAC_Access_Flag],01h			;an015; dms;signal disk access
  4185 00001317 E8C6FE                  		       call    Set_Disk_Access_On_Off				;an015; dms;allow disk access
  4186                                  ;	       $endif								;an015; dms;
  4187                                  DD_EN141:
  4188                                  ;	$endif									;an015; dms;
  4189                                  DD_IF140:
  4190                                  
  4191                                  No equ NO	; NASM port equate
  4192 0000131A 803E[D706]00            	cmp	byte [FAT_Flag],No							;an012; dms;non-FAT format?
  4193                                  ;	$if	e								;an012; dms;yes
  4194 0000131F 750A                    	JNE DD_IF145
  4195 00001321 803E[8304]00            		cmp	byte [ExitStatus],ExitOK					;an012; dms;good exit?
  4196                                  ;		$if	ne							;an012; dms;no
  4197 00001326 7403                    		JE DD_IF146
  4198 00001328 E8B9FF                  			call	Set_CDS_Off					;an012; dms;disallow FAT access
  4199                                  ;		$endif								;an012; dms;
  4200                                  DD_IF146:
  4201                                  ;	$endif									;an012; dms;
  4202                                  DD_IF145:
  4203                                  
  4204 0000132B C3                      	ret									;an000; dms;
  4205                                  
  4206                                  Format_Access_Wrap_Up	endp							;an000; dms;
  4207                                  
  4208                                  ;=========================================================================
  4209                                  ; BadClus_Address_Adjust	- This routine adjusts the segment and
  4210                                  ;				  offset to provide addressibility into
  4211                                  ;				  the FAT table.
  4212                                  ;
  4213                                  ;	Inputs	: bx	- high word to adjust segment for
  4214                                  ;		  ax	- low word to adjust segment for
  4215                                  ;		  cx	- segment to be adjusted
  4216                                  ;
  4217                                  ;	Outputs : cx	- new segment value
  4218                                  ;		  ax	- new offset value
  4219                                  ;=========================================================================
  4220                                  
  4221                                  Procedure BadClus_Address_Adjust						;an000; dms;
  4222                                  
  4223 0000132C 53                      	push	bx								;an000; save regs
  4224 0000132D 52                      	push	dx								;an000;
  4225 0000132E 57                      	push	di								;an000;
  4226 0000132F 56                      	push	si								;an000;
  4227                                  
  4228 00001330 89CA                    	mov	dx,cx								;an000; save segment value
  4229 00001332 89DE                    	mov	si,bx								;an000; get high word for divide
  4230 00001334 89C7                    	mov	di,ax								;an000; get low word for divide
  4231 00001336 31C9                    	xor	cx,cx								;an000; clear cx
  4232 00001338 B110                    	mov	cl,Paragraph_Size						;an000; divide by 16
  4233 0000133A E8A2FB                  	call	Divide_32_Bits							;an000; perform division
  4234                                  
  4235 0000133D 01FA                    	add	dx,di								;an000; adjust segment for result
  4236 0000133F 89C8                    	mov	ax,cx								;an000; pick up the remainder
  4237 00001341 89D1                    	mov	cx,dx								;an000; pass back new segment
  4238                                  
  4239 00001343 5E                      	pop	si								;an000; restore regs
  4240 00001344 5F                      	pop	di								;an000;
  4241 00001345 5A                      	pop	dx								;an000;
  4242 00001346 5B                      	pop	bx								;an000;
  4243                                  
  4244 00001347 C3                      	ret									;an000; dms;
  4245                                  
  4246                                  BadClus_Address_Adjust	endp							;an000; dms;
  4247                                  
  4248                                  
  4249                                  
  4250                                  ;=========================================================================
  4251                                  ; NextTrack	: This routine determines the next track to be
  4252                                  ;		  formatted.
  4253                                  ;
  4254                                  ;	Inputs	: TracksLeft		- # of tracks remaining
  4255                                  ;		  Tracks_To_Format	- # of tracks to format in 1 call
  4256                                  ;		  FP_Head		- disk head
  4257                                  ;		  FP_Cylinder		- disk cylinder
  4258                                  ;
  4259                                  ;	Outputs : TracksLeft		- # of tracks remaining
  4260                                  ;		  FP_Head		- disk head
  4261                                  ;		  FP_Cylinder		- disk cylinder
  4262                                  ;		  CY			- no tracks left to format
  4263                                  ;		  NC			- tracks left to format
  4264                                  ;=========================================================================
  4265                                  
  4266                                  Procedure NextTrack								;an015; dms;
  4267                                  
  4268                                  
  4269                                  TracksLeft equ tracksLeft	; NASM port label
  4270 00001348 833E[6A04]00            	cmp	word [TracksLeft],00							;an015; dms;end of format?
  4271                                  ;	$if	e								;an015; dms;yes
  4272 0000134D 7508                    	JNE DD_IF149
  4273 0000134F F9                      		stc								;an015; dms;signal end of format
  4274 00001350 C606[DC06]FF            		mov	byte [Format_End],True
  4274          ******************       warning: byte data exceeds bounds [-w+number-overflow]
  4275                                  ;	$else
  4276 00001355 EB2B                    	JMP SHORT DD_EN149
  4277                                  DD_IF149:
  4278 00001357 8B0E[D806]              		mov	cx,[Tracks_To_Format]					;an015; dms;get max track count for call
  4279                                  ;		$do								;an015; dms;while tracks remain
  4280                                  DD_DO151:
  4281 0000135B 833E[6A04]00            			cmp	word [TracksLeft],00					;an015; dms;end of format?
  4282                                  ;			$leave	e						;an015; dms;yes
  4283 00001360 741F                    			JE DD_EN151
  4284 00001362 83F900                  			cmp	cx,00						;an015; dms;end of head/cyl. adjustment?
  4285                                  ;			$leave	e						;an015; dms;yes
  4286 00001365 741A                    			JE DD_EN151
  4287 00001367 FF06[4C02]              			inc	word [FormatPacket + FP_Head]				;an015; dms;next head
  4288 0000136B A1[4C02]                			mov	ax,[FormatPacket + FP_Head] 			;an015; dms;get head for comp
  4289 0000136E 3B06[3B01]              			cmp	ax,[DeviceParameters + DP_BPB + BPB_Heads]		;an015; dms;exceeded head count?
  4290                                  ;			$if	e						;an015; dms;yes
  4291 00001372 750A                    			JNE DD_IF154
  4292 00001374 C706[4C02]0000          				mov	word [FormatPacket + FP_Head],00 		;an015; dms;reinit. head
  4293 0000137A FF06[4E02]              				inc	word [FormatPacket + FP_Cylinder]		;an015; dms;next cylinder
  4294                                  ;			$endif							;an015; dms;
  4295                                  DD_IF154:
  4296                                  
  4297 0000137E 49                      			dec	cx						;an015; dms;decrease counter
  4298                                  ;		$enddo								;an015; dms;
  4299 0000137F EBDA                    		JMP SHORT DD_DO151
  4300                                  DD_EN151:
  4301                                  
  4302 00001381 F8                      		clc								;an015; dms;clear CY
  4303                                  ;	$endif									;an015; dms;
  4304                                  DD_EN149:
  4305                                  
  4306 00001382 C3                      	ret									;an015; dms;
  4307                                  
  4308                                  NextTrack	endp								;an015; dms;
  4309                                  
  4310                                  ;=========================================================================
  4311                                  ; Determine_Format_Type : This routine determines the type of format
  4312                                  ;			  that is to occur based on the media type.
  4313                                  ;
  4314                                  ;	Inputs	: Dev_HardDisk		- Media type (harddisk)
  4315                                  ;		  Multi_Track_Format	- EQU 02h
  4316                                  ;		  Single_Track_Format	- EQU 00h
  4317                                  ;
  4318                                  ;	Outputs : FP_SpecialFunctions	- Set appropriately for single
  4319                                  ;					  or multi track format
  4320                                  ;=========================================================================
  4321                                  
  4322                                  Procedure Determine_Format_Type 						;an015; dms;
  4323                                  
  4324                                  Dev_HardDisk equ DEV_HARDDISK	; NASM port equate
  4325 00001383 803E[2601]05            	cmp	byte [DeviceParameters + DP_DeviceType],Dev_HardDisk			;an015; dms;harddisk?
  4326                                  ;	$if	e								;an015; dms;yes
  4327 00001388 7507                    	JNE DD_IF158
  4328 0000138A C606[4B02]02            		mov	byte [FormatPacket + FP_SpecialFunctions],Multi_Track_Format	;an015; dms;set for multi track format
  4329                                  ;	$else									;an015; dms;
  4330 0000138F EB05                    	JMP SHORT DD_EN158
  4331                                  DD_IF158:
  4332 00001391 C606[4B02]00            		mov	byte [FormatPacket + FP_SpecialFunctions],Single_Track_Format	;an015; dms;set for single track format
  4333                                  ;	$endif									;an015; dms;
  4334                                  DD_EN158:
  4335 00001396 C3                      	ret									;an015; dms;
  4336                                  
  4337                                  Determine_Format_Type	endp							;an015; dms;
  4338                                  
  4339                                  
  4340                                  ;=========================================================================
  4341                                  ; FormatTrack		: This routine performs multi track or single
  4342                                  ;			  track formatting based on the state of the
  4343                                  ;			  SpecialFunctions byte.
  4344                                  ;
  4345                                  ;	Inputs	: Tracks_To_Format	- # of tracks to format in 1 call
  4346                                  ;		  FormatPacket		- Parms for IOCTL call
  4347                                  ;
  4348                                  ;	Outputs : NC			- formatted track(s)
  4349                                  ;		  CY			- error in format
  4350                                  ;		  AX			- extended error on CY
  4351                                  ;=========================================================================
  4352                                  
  4353                                  Procedure FormatTrack								;an015; dms;
  4354                                  
  4355 00001397 B80D44                  	mov	ax,(IOCTL << 8) | Generic_IOCTL				;an015; dms;Generic IOCTL
  4356 0000139A 8A1E[8206]              	mov	bl,[drive]							;an015; dms;get drive number
  4357 0000139E FEC3                    	inc	bl								;an015; dms;make it 1 based
  4358                                  RawIO equ RAWIO	; NASM port equate
  4359                                  Format_Track equ FORMAT_TRACK	; NASM port equate
  4360 000013A0 B94208                  	mov	cx,(RawIO << 8) | Format_Track				;an015; dms;Format track(s)
  4361 000013A3 8B16[D806]              	mov	dx,[Tracks_To_Format]						;an015; dms;get track count
  4362                                  FP_TrackCount equ FP_TRACKCOUNT	; NASM port equate
  4363 000013A7 8916[5002]              	mov	[FormatPacket + FP_TrackCount],dx					;an015; dms;put count in parms list
  4364 000013AB 8D16[4B02]              	lea	dx,[FormatPacket] 						;an015; dms;ptr to parms
  4365 000013AF CD21                    	int	21h								;an015; dms;
  4366                                  
  4367                                  ;	$if	c								;an015; dms;error?
  4368 000013B1 7307                    	JNC DD_IF161
  4369 000013B3 B459                    		mov	ah,59h							;an015; dms;get extended error
  4370 000013B5 31DB                    		xor	bx,bx							;an015; dms;clear bx
  4371 000013B7 CD21                    		int	21h							;an015; dms;
  4372 000013B9 F9                      		stc								;an015; dms;flag an error
  4373                                  ;	$endif									;an015; dms;
  4374                                  DD_IF161:
  4375                                  
  4376 000013BA C3                      	ret									;an015; dms;
  4377                                  
  4378                                  FormatTrack	endp								;an015; dms;
  4379                                  
  4380                                  
  4381                                  ;=========================================================================
  4382                                  ; Determine_Track_Count 	: This routine determines the number of
  4383                                  ;				  tracks to be formatted, based on whether
  4384                                  ;				  or not we have a hard disk.  If we have
  4385                                  ;				  a hard disk we can use multi-track
  4386                                  ;				  format/verify, otherwise we use the
  4387                                  ;				  single track format/verify.
  4388                                  ;
  4389                                  ;	Inputs	: Device_Type			- Media type
  4390                                  ;
  4391                                  ;	Outputs : Tracks_To_Format		- Max. number of tracks
  4392                                  ;						  to be formatted in one
  4393                                  ;						  call
  4394                                  ;=========================================================================
  4395                                  
  4396                                  Procedure Determine_Track_Count 						;an015; dms;
  4397                                  
  4398 000013BB 803E[2601]05            	cmp	byte [DeviceParameters + DP_DeviceType],Dev_HardDisk			;an015; dms;harddisk?
  4399                                  ;	$if	e								;an015; dms;yes
  4400 000013C0 7505                    	JNE DD_IF163
  4401 000013C2 E80900                  		call	Calc_Track_Count					;an015; dms;calc Tracks_To_Format
  4402                                  ;	$else									;an015; dms;removable media
  4403 000013C5 EB06                    	JMP SHORT DD_EN163
  4404                                  DD_IF163:
  4405 000013C7 C706[D806]0100          		mov	word [Tracks_To_Format],0001h					;an015; dms;default to 1 track
  4406                                  ;	$endif									;an015; dms;
  4407                                  DD_EN163:
  4408                                  
  4409 000013CD C3                      	ret									;an015; dms;
  4410                                  
  4411                                  Determine_Track_Count	endp							;an015;dms;
  4412                                  
  4413                                  
  4414                                  ;=========================================================================
  4415                                  ; Calc_Track_Count	: This routine determines if we have enough tracks
  4416                                  ;			  remaining to use the max. number of tracks
  4417                                  ;			  in the FormatTrack call.  If the tracks remaining
  4418                                  ;			  to be formatted is less that the max. number of
  4419                                  ;			  allowable tracks for the call, the max. number
  4420                                  ;			  of allowable tracks is set to the remaining track
  4421                                  ;			  count.
  4422                                  ;
  4423                                  ;	Inputs	: Track_Count - Max. number of allowable tracks to be
  4424                                  ;				formatted in 1 FormatTrack call.
  4425                                  ;		  TracksLeft  - Track count of remaining tracks to be
  4426                                  ;				formatted.
  4427                                  ;
  4428                                  ;	Outputs : Tracks_To_Format - Count of the tracks to be formatted
  4429                                  ;				     in the next FormatTrack call.
  4430                                  ;
  4431                                  ;
  4432                                  ;=========================================================================
  4433                                  
  4434                                  Procedure Calc_Track_Count							;an015; dms;
  4435                                  
  4436 000013CE 50                      	push	ax								;an015; dms;save regs
  4437 000013CF A1[DA06]                	mov	ax,[Track_Count]							;an015; dms;max bytes to format
  4438 000013D2 3B06[6A04]              	cmp	ax,[TracksLeft]							;an015; dms;too many tracks?
  4439                                  ;	$if	a								;an015; dms;yes
  4440 000013D6 7603                    	JNA DD_IF166
  4441 000013D8 A1[6A04]                		mov	ax,[TracksLeft]						;an015; dms;format remaining tracks
  4442                                  ;	$endif									;an015; dms;
  4443                                  DD_IF166:
  4444 000013DB A3[D806]                	mov	[Tracks_To_Format],ax						;an015; dms;save track count
  4445                                  
  4446 000013DE 58                      	pop	ax								;an015; dms;
  4447                                  
  4448 000013DF C3                      	ret									;an015; dms;
  4449                                  
  4450                                  Calc_Track_Count	endp							;an015; dms;
  4451                                  
  4452                                  ;=========================================================================
  4453                                  ; Calc_Max_Tracks_To_Format	: This routine determines the maximum
  4454                                  ;				  number of tracks to format at 1 time.
  4455                                  ;
  4456                                  ;	Inputs	: DeviceParameters - SectorsPerTrack
  4457                                  ;				     BytesPerSector
  4458                                  ;
  4459                                  ;	Outputs : Track_Count	   - Max. # of tracks to format in 1 call
  4460                                  ;				     to FormatTrack
  4461                                  ;=========================================================================
  4462                                  
  4463                                  Procedure Calc_Max_Tracks_To_Format
  4464                                  
  4465 000013E0 50                      	push	ax								;an015; dms;save regs
  4466 000013E1 53                      	push	bx								;an015; dms;
  4467 000013E2 52                      	push	dx								;an015; dms;
  4468                                  
  4469 000013E3 A1[3901]                	mov	ax,[DeviceParameters + DP_BPB + BPB_SectorsPerTrack]			;an015; dms;get sectors per track
  4470 000013E6 8B1E[2C01]              	mov	bx,[DeviceParameters + DP_BPB + BPB_BytesPerSector]			;an015; dms;get byte count
  4471 000013EA 31D2                    	xor	dx,dx								;an015; dms;clear dx
  4472 000013EC F7E3                    	mul	bx								;an015; dms;get total byte count
  4473 000013EE 89C3                    	mov	bx,ax								;an015; dms;put count in bx
  4474 000013F0 B8FFFF                  	mov	ax,Max_Format_Size						;an015; dms;max bytes to format
  4475 000013F3 F7F3                    	div	bx								;an015; dms;get track count
  4476 000013F5 A3[DA06]                	mov	[Track_Count],ax
  4477                                  
  4478 000013F8 5A                      	pop	dx								;an015; dms;
  4479 000013F9 5B                      	pop	bx								;an015; dms;
  4480 000013FA 58                      	pop	ax								;an015; dms;
  4481                                  
  4482 000013FB C3                      	ret
  4483                                  
  4484                                  Calc_Max_Tracks_To_Format	endp
  4485                                  
  4486                                  
  4487                                  
  4488                                  
  4489                                  
  4490                                  ;=========================================================================
  4491                                  ; Format_Track_Retry	: This routine performs the retry logic for
  4492                                  ;			  the format multi-track.  It will retry each track
  4493                                  ;			  until the failing track is encountered through
  4494                                  ;			  a CY condition.
  4495                                  ;
  4496                                  ;	Inputs	: none
  4497                                  ;
  4498                                  ;	Outputs : CY - indicates either a failing track or end of format
  4499                                  ;
  4500                                  ;
  4501                                  ;=========================================================================
  4502                                  
  4503                                  Procedure Format_Track_Retry
  4504                                  
  4505 000013FC F8                      	clc									;an022; dms; clear existing CY
  4506 000013FD C706[D806]0100          	mov	word [Tracks_To_Format],1						;an015; dms; only format 1 track
  4507                                  ;	$do									;an015; dms; while we have good tracks
  4508                                  DD_DO168:
  4509                                  ;		$leave	c							;an015; dms; exit on bad track
  4510 00001403 7210                    		JC DD_EN168
  4511 00001405 E88FFF                  		call	FormatTrack						;an015; dms; format the track
  4512                                  ;		$if	nc							;an015; dms;error?
  4513 00001408 7209                    		JC DD_IF170
  4514 0000140A E895F8                  			call	DisplayCurrentTrack				;an022; dms;adjust percent counter
  4515 0000140D E84200                  			call	Adj_Track_Count
  4516 00001410 E835FF                  			call	NextTrack					;an015; dms;calc next track
  4517                                  ;		$endif								;an015; dms;
  4518                                  DD_IF170:
  4519                                  ;	$enddo									;an015; dms;
  4520 00001413 EBEE                    	JMP SHORT DD_DO168
  4521                                  DD_EN168:
  4522                                  
  4523 00001415 C3                      	ret									;an015; dms;
  4524                                  
  4525                                  Format_Track_Retry	endp							;an015; dms;
  4526                                  
  4527                                  ;=========================================================================
  4528                                  ; Format_Loop			: This routine provides the main template
  4529                                  ;				  for the formatting of a disk.  A disk
  4530                                  ;				  will be formatted as long as there are
  4531                                  ;				  tracks remaining to be formatted.
  4532                                  ;				  This routine can be exited on a carry
  4533                                  ;				  condition; i.e., bad track, last track, etc.
  4534                                  ;
  4535                                  ;	Inputs	: none
  4536                                  ;
  4537                                  ;	Outputs : CY - Set on exit from this routine
  4538                                  ;		  AX - Possible error condition code
  4539                                  ;=========================================================================
  4540                                  
  4541                                  Procedure Format_Loop								;an015; dms;
  4542                                  
  4543 00001416 F8                      	clc									;an015; dms;initialize to NC
  4544                                  ;	$do									;an015; dms;while NC
  4545                                  DD_DO173:
  4546                                  ;		$leave	c							;an015; dms;exit on CY
  4547 00001417 7238                    		JC DD_EN173
  4548 00001419 E873F8                  		call	Calc_Current_Head_Cyl					;an015; dms;head and cylinder calc.
  4549 0000141C E864FF                  		call	Determine_Format_Type					;an015; dms;floppy/hard media?
  4550 0000141F E899FF                  		call	Determine_Track_Count					;an015; dms;how many tracks?
  4551 00001422 E872FF                  		call	FormatTrack						;an015; dms;format track(s)
  4552                                  ;		$if	c							;an015; dms;formattrack failed
  4553 00001425 730F                    		JNC DD_IF175
  4554 00001427 9C                      			pushf							;an015; dms;save flags
  4555 00001428 803E[2601]05            			cmp	byte [DeviceParameters + DP_DeviceType],Dev_HardDisk	;an015; dms;harddisk?
  4556                                  ;			$if	e						;an015; dms;yes
  4557 0000142D 7506                    			JNE DD_IF176
  4558 0000142F 9D                      				popf						;an015; dms;restore flags
  4559 00001430 E8C9FF                  				call	Format_Track_Retry			;an015; dms;find failing track
  4560                                  ;			$else							;an015; dms;
  4561 00001433 EB01                    			JMP SHORT DD_EN176
  4562                                  DD_IF176:
  4563 00001435 9D                      				popf						;an015; dms;restore flags
  4564                                  ;			$endif							;an015; dms;
  4565                                  DD_EN176:
  4566                                  ;		$endif								;an015; dms;
  4567                                  DD_IF175:
  4568                                  
  4569                                  ;		$if	c							;an015; dms;format error?
  4570 00001436 730C                    		JNC DD_IF180
  4571 00001438 9C                      			pushf							;an015; dms;yes - save flags
  4572 00001439 50                      			push	ax						;an015; dms;save return code
  4573 0000143A E8B2F8                  			call	CheckRealErrors 				;an015; dms;check error type
  4574                                  ;			$if	nc						;an015; dms;if non-fatal
  4575 0000143D 7203                    			JC DD_IF181
  4576 0000143F E860F8                  				call	DisplayCurrentTrack			;an015; dms;display % formatted
  4577                                  ;			$endif							;an015; dms;
  4578                                  DD_IF181:
  4579 00001442 58                      			pop	ax						;an015; dms;restore regs
  4580 00001443 9D                      			popf							;an015; dms;
  4581                                  ;		$endif								;an015; dms;
  4582                                  DD_IF180:
  4583                                  
  4584                                  ;		$leave	c							;an015; dms;exit on CY
  4585 00001444 720B                    		JC DD_EN173
  4586                                  
  4587 00001446 E859F8                  		call	DisplayCurrentTrack					;an015; dms;tell how much formatted
  4588 00001449 E80600                  		call	Adj_Track_Count 					;an015; dms;decrease track counter
  4589 0000144C E8F9FE                  		call	NextTrack						;an015; dms;adjust head and cylinder
  4590                                  ;	$enddo									;an015; dms;
  4591 0000144F EBC6                    	JMP SHORT DD_DO173
  4592                                  DD_EN173:
  4593 00001451 C3                      	ret									;an015; dms;
  4594                                  
  4595                                  Format_Loop	endp								;an015; dms;
  4596                                  
  4597                                  ;=========================================================================
  4598                                  ; Adj_Track_Count	: This routine adjusts the track count by the
  4599                                  ;			  number of tracks that have been formatted
  4600                                  ;			  in one FormatTrack call.
  4601                                  ;
  4602                                  ;	Inputs	: TracksLeft	- # of tracks remaining to be formatted
  4603                                  ;		  Tracks_To_Format - Tracks formatted in 1 call
  4604                                  ;
  4605                                  ;	Outputs : TracksLeft	- # of tracks remaining to be formatted
  4606                                  ;=========================================================================
  4607                                  
  4608                                  Procedure Adj_Track_Count							;an015; dms;
  4609                                  
  4610 00001452 50                      	push	ax								;an015; dms; save regs
  4611 00001453 A1[6A04]                	mov	ax,[TracksLeft]							;an015; dms; get tracks remaining
  4612 00001456 2B06[D806]              	sub	ax,[Tracks_To_Format]						;an015; dms; subtract amount formatted
  4613 0000145A A3[6A04]                	mov	[TracksLeft],ax							;an015; dms; save new tracks remaining value
  4614 0000145D 58                      	pop	ax								;an015; dms; restore regs
  4615 0000145E C3                      	ret									;an015; dms;
  4616                                  
  4617                                  Adj_Track_Count endp								;an015; dms;
  4618                                  
  4619                                  ;=========================================================================
  4620                                  ; Prompt_User_For_Disk		: This routine prompts the user for the
  4621                                  ;				  disk to be formatted.  An appropriate
  4622                                  ;				  message is chosen based on the type
  4623                                  ;				  of switch entered.  If the /SELECT
  4624                                  ;				  switch is entered, the disk prompt is
  4625                                  ;				  issued through the INT 2fh services
  4626                                  ;				  provided by SELECT.
  4627                                  ;
  4628                                  ;	Inputs	: Switchmap	- Switches chosen for format
  4629                                  ;
  4630                                  ;	Outputs : Message printed as appropriate.
  4631                                  ;=========================================================================
  4632                                  
  4633                                  Procedure Prompt_User_For_Disk							;an016;dms;
  4634                                  
  4635 0000145F 50                      	push	ax								;an016;dms;save ax
  4636                                  SWITCH_Backup equ SWITCH_BACKUP	; NASM port equate
  4637 00001460 F706[2006]040C          	test	word [switchmap], (SWITCH_Backup | SWITCH_Select | SWITCH_AUTOTEST) ;Suppress prompt?	       ;AC000;
  4638                                  ;	$IF	Z				;					      ;AC000;
  4639 00001466 7503                    	JNZ DD_IF186
  4640 00001468 E877EF                  	   call    DSKPRM			; prompt user for disk
  4641                                  ;	$ENDIF					;					      ;AC000;
  4642                                  DD_IF186:
  4643                                  
  4644 0000146B F706[2006]0004          	test	word [switchmap], (Switch_Select)					;an016;dms;/SELECT requested?
  4645                                  ;	$if	nz								;an016;dms;yes
  4646 00001471 740B                    	JZ DD_IF188
  4647 00001473 A0[8206]                		mov	al, [drive]						;an016;dms;get drive to access for format
  4648 00001476 E8(0000)                		call	AccessDisk						;an016;dms;access the disk
  4649 00001479 B8C1AD                  		mov	ax,Select_Disk_Message					;an016;dms;display disk prompt
  4650 0000147C CD2F                    		int	2fh							;an016;dms;  through INT 2fh services
  4651                                  ;	$endif									;an016;dms;
  4652                                  DD_IF188:
  4653 0000147E 58                      	pop	ax								;an016;dms;restore ax
  4654                                  
  4655 0000147F C3                      	ret									;an016;dms;
  4656                                  
  4657                                  Prompt_User_For_Disk	endp							;an016;dms;
  4658                                  
  4659                                  
  4660                                  ; (no prior section) ; code	ends
  4661                                  	END	START
  4662                                  
