     1                                  ;	SCCSID = @(#)disk3.asm	1.3 85/07/26
     2                                  ;	SCCSID = @(#)disk3.asm	1.3 85/07/26
     3                                  ;TITLE	DISK3 - Disk utility routines
     4                                  ;NAME	Disk3
     5                                  ; Low level Read and write routines for local SFT I/O on files and devs
     6                                  ;
     7                                  ;   DISKWRITE
     8                                  ;   WRTERR
     9                                  ;
    10                                  ;   Revision history:
    11                                  ;
    12                                  ;    AN000 version 4.00 Jan. 1988
    13                                  ;
    14                                  
    15                                  ;
    16                                  ; get the appropriate segment definitions
    17                                  ;
    18                                  [list -]
    18          ******************       warning: redefining multi-line macro `struc' [-w+pp-macro-redef-multi]
    14                              <4> [list -]
    14                              <3> [list -]
     3                              <2> 
     4                              <2> addsection DOSSTART, align=16 PUBLIC class=DOSSTART
     5                              <2> ; (no prior section) ; DOSSTART		ENDS
     6                              <2> 
     7                              <2> addsection DOSSTARTJUMP, align=1 PUBLIC class=START
     8                              <2> ; (no prior section) ; DOSSTARTJUMP		ENDS
     9                              <2> 
    10                              <2> addsection CONSTANTS, align=2 PUBLIC class=CONST
    11                              <2> ; (no prior section) ; CONSTANTS	ENDS
    12                              <2> 
    13                              <2> addsection DATA, align=2 PUBLIC class=DATA
    14                              <2> ; (no prior section) ; DATA		ENDS
    15                              <2> 
    16                              <2> addsection TABLE, align=2 PUBLIC class=TABLE
    17                              <2> ; (no prior section) ; TABLE		ENDS
    18                              <2> 
    19                              <2> addsection DOSDATATABLE, align=2 PUBLIC class=DOSDATACODE
    20                              <2> ; (no prior section) ; DOSDATATABLE		ENDS
    21                              <2> 
    22                              <2> addsection DOSDATACODE, align=1 PUBLIC class=DOSDATACODE
    23                              <2> ; (no prior section) ; DOSDATACODE		ENDS
    24                              <2> 
    25                              <2> addsection DOSBIODATA, align=2 PUBLIC class=DOSBIODATA
    26                              <2> 
    27                              <2> addsection LAST, align=16 PUBLIC class=LAST
    28                              <2> ; (no prior section) ; LAST		ENDS
    29                              <2> 
    30                              <2> group DOSGROUP DOSSTART DOSSTARTJUMP CONSTANTS DATA TABLE DOSDATATABLE DOSDATACODE DOSBIODATA LAST
     8                              <1> 
     9                              <1> %include "dcodeseg.nas"
     1                              <2> 
     2                              <2> %ifndef DCODESEGNAS
     3                              <2> %assign DCODESEGNAS 1
     4                              <2> 
     5                              <2> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <2> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <2> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <2> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <2> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <2> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <2> 
    12                              <2> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <2>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <2> %endif
    15                              <2> 
    16                              <2> %endif
    10                              <1> 
    11                              <1> section LAST
    12                              <1> ; (no prior section) ; LAST		ENDS
    20                                  
    21                                  [list +]
    22                                  section DOSCODECODE
    23                                  [list -]
    23          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    23          ******************       warning: out: BPB.INC... [-w+user]
    23          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    23          ******************       warning: out: DEVSYM.INC... [-w+user]
    23          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    31                                  
    32                                  %iassign Installed TRUE
    33                                  
    34                                  	i_need	THISSFT,DWORD
    35                                  	i_need	DMAADD,DWORD
    36                                  	i_need	SecClusPos,BYTE
    37                                  	i_need	ClusNum,WORD
    38                                  	i_need	Trans,BYTE
    39                                  	i_need	BytPos,4
    40                                  	i_need	SecPos,DWORD		  ;F.C. >32mb	;AN000;
    41                                  	i_need	BytSecPos,WORD
    42                                  	i_need	BytCnt1,WORD
    43                                  	i_need	BytCnt2,WORD
    44                                  	i_need	SecCnt_DOS,WORD
    45                                  	i_need	ThisDPB,DWORD
    46                                  	i_need	LastPos,WORD
    47                                  	i_need	ValSec,WORD		  ;F.C. >32mb	       ;AN000;
    48                                  	i_need	GrowCnt,DWORD
    49                                  	i_need	ALLOWED,BYTE
    50                                  	I_need	JShare,DWORD
    51                                  	I_need	FSeek_drive,BYTE	  ; DOS 4.00	       ;AN000;
    52                                  	I_need	FSeek_firclus,WORD	  ; DOS 4.00	       ;AN000;
    53                                  	I_need	FSeek_logclus,WORD	  ; DOS 4.00	       ;AN000;
    54                                  	I_need	HIGH_SECTOR,WORD	  ;F.C. >32mb	       ;AN000;
    55                                  	I_need	HIGH_SECTOR_TEMP,WORD	  ;F.C. >32mb	       ;AN000;
    56                                  	I_need	EXTERR,WORD			   ; DOS 4.00   ;AN000;
    57                                  	I_need	EXTERR_LOCUS,BYTE		   ; DOS 4.00   ;AN000;
    58                                  	I_need	EXTERR_ACTION,BYTE		   ; DOS 4.00   ;AN000;
    59                                  	I_need	EXTERR_CLASS,BYTE		   ; DOS 4.00   ;AN000;
    60                                  	I_need	EXITHOLD,DWORD			   ; DOS 4.00   ;AN000;
    61                                  	I_need	DISK_FULL,BYTE			   ; DOS 4.00   ;AN000;
    62                                  	I_need	SC_DRIVE,BYTE			   ; DOS 4.00   ;AN000;
    63                                  	I_need	SC_CACHE_COUNT,WORD		   ; DOS 4.00   ;AN000;
    64                                  	I_need	ThisDRV,BYTE			   ; DOS 4.00   ;AN000;
    65                                  	I_need	User_In_AX,WORD 		   ; DOS 4.00   ;AN000;
    66                                  	I_need	DOS34_FLAG,WORD 		   ; DOS 4.00   ;AN000;
    67                                  	I_need	FIRST_BUFF_ADDR,WORD		   ; DOS 4.00   ;AN000;
    68                                  
    69                                  %ifndef BUF2
    70                                  %IF	BUFFERFLAG
    71                                  	EXTRN	SAVE_MAP:NEAR
    72                                  	EXTRN	RESTORE_MAP:NEAR
    73                                  	EXTRN	SAVE_USER_MAP:NEAR
    74                                  	EXTRN	RESTORE_USER_MAP:NEAR
    75                                  	i_need	BUF_EMS_SAFE_FLAG,BYTE
    76                                  	i_need	BUF_EMS_MODE,BYTE
    77                                  %ENDIF
    78                                  %else
    79                                  	i_need	BUFFHEAD,dword
    80                                  %endif
    81                                  	
    82                                  
    83                                   assume nocheck, ss:DOSGROUP
    84                                  
    85                                  Break	<DISKWRITE -- PERFORM USER DISK WRITE>
    86                                  
    87                                  ; Inputs:
    88                                  ;	Outputs of SETUP
    89                                  ; Function:
    90                                  ;	Perform disk write
    91                                  ; Outputs:
    92                                  ;    Carry clear
    93                                  ;	CX = No. of bytes read
    94                                  ;	ES:DI point to SFT
    95                                  ;	SFT offset and cluster pointers updated
    96                                  ;    Carry set
    97                                  ;	CX = 0
    98                                  ;	ES:DI point to SFT
    99                                  ;	AX has error code
   100                                  
   101                                  	procedure   DISKWRITE,NEAR
   101          ******************       warning: proc DISKWRITE... [-w+user]
   102                                  	DOSAssume   CS,<DS>,"DiskWrite"
   103                                  	ASSUME	ES:NOTHING
   104                                  
   105                                  	Assert	ISSFT,<ES,DI>,"DiskWrite"
   106 00000000 26FF750B                	PUSH	word [ES:DI + sf_firclus]	  ; set up 1st cluster # for FastSeek
   107 00000004 8F06[0000]              	POP	word [FSeek_firclus]
   108                                  
   109 00000008 E8(0000)                	invoke	CHECK_WRITE_LOCK	  ;IFS. check write lock		 ;AN000;
   110 0000000B 7304                    	JNC	WRITE_OK		  ;IFS. lock check ok			 ;AN000;
   111 0000000D C3                      	return
   112                                  
   113                                  WRTEOFJ:
   114 0000000E E93A02                  	JMP	WRTEOF
   115                                  
   116                                  WRITE_OK:
   117 00000011 26816505BFBF            	AND	word [ES:DI + sf_flags],~ (sf_close_nodate | devid_file_clean)
   118                                  				; Mark file as dirty, clear no date on close
   119                                  THISDPB equ ThisDPB	; NASM port label
   120 00000017 C42E[0000]              	LES	BP,[THISDPB]
   121                                  	Assert	ISDPB,<ES,BP>,"DiskWrite/WriteOk"
   122 0000001B 268A4600                	MOV	AL,[ES:BP + dpb_drive]   ; set up drive # for FastSeek
   123 0000001F A2[0000]                	MOV	[FSeek_drive],AL       ; 11/5/86 DOS 4.00
   124                                  
   125 00000022 E8(0000)                	invoke	BREAKDOWN
   126                                  BYTPOS equ BytPos	; NASM port label
   127 00000025 A1[0000]                	MOV	AX,WORD PTR [BYTPOS]
   128 00000028 8B16[0200]              	MOV	DX,WORD PTR [BYTPOS+2]
   129 0000002C E3E0                    	JCXZ	WRTEOFJ 		;Make the file length = sf_position
   130 0000002E 01C8                    	ADD	AX,CX
   131 00000030 83D200                  	ADC	DX,0			; AX:DX=byte after last byte accessed
   132                                  ;
   133                                  ; Make sure divide won't overflow
   134                                  ;
   135 00000033 268B5E02                	MOV	BX,[ES:BP + dpb_sector_size]
   136                                  ;	CMP	DX,BX			;F.C. >32mb  16 bit sector check	;AN000;
   137                                  ;	JAE	WrtErr			;F.C. >32mb				;AN000;
   138                                  
   139 00000037 E8A402                  	CALL	DIV32			;F.C. perform 32 bit divide		;AN000;
   140 0000003A 89C3                    	MOV	BX,AX			; Save last full sector
   141 0000003C 09D2                    	OR	DX,DX
   142 0000003E 7508                    	JNZ	CALCLUS
   143 00000040 83E801                  	SUB	AX,1			; AX must be zero base indexed		;AC000;
   144 00000043 831E[0000]00            	SBB	word [HIGH_SECTOR],0 	;F.C. >32mb				;AN000;
   145                                  CALCLUS:
   146 00000048 FF36[0000]              	PUSH	word [HIGH_SECTOR]		;F.C. >32mb				;AN000;
   147 0000004C E89E02                  	CALL	SHR32			;F.C. >32mb				;AN000;
   148 0000004F 8F06[0000]              	POP	word [HIGH_SECTOR]		;F.C. >32mb				;AN000;
   149                                  
   150                                  ;	SHR	AX,CL			; Last cluster to be accessed
   151 00000053 50                      	PUSH	AX
   152 00000054 52                      	PUSH	DX			; Save the size of the "tail"
   153 00000055 06                      	PUSH	ES
   154 00000056 C43E[0000]              	LES	DI,[THISSFT]
   155                                   assume es:nothing
   156                                  	Assert	ISSFT,<ES,DI>,"DiskWrite/CalClus"
   157 0000005A 268B4511                	MOV	AX,WORD PTR [ES:DI + sf_size]
   158 0000005E 268B5513                	MOV	DX,WORD PTR [ES:DI + sf_size+2]
   159 00000062 07                      	POP	ES
   160                                   assume es:DPB
   161                                  
   162                                  
   163 00000063 50                      	PUSH	AX			;F.C. >32mb				;AN000;
   164 00000064 89D0                    	MOV	AX,DX			;F.C. >32mb				;AN000;
   165 00000066 31D2                    	XOR	DX,DX			;F.C. >32mb				;AN000;
   166 00000068 26F77602                	DIV	word [ES:BP + dpb_sector_size] ;F.C. >32mb				;AN000;
   167 0000006C A3[0000]                	MOV	[HIGH_SECTOR_TEMP],AX	;F.C. >32mb				;AN000;
   168 0000006F 58                      	POP	AX			;F.C. >32mb				;AN000;
   169                                  
   170 00000070 26F77602                	DIV	word [ES:BP + dpb_sector_size]
   171 00000074 89C1                    	MOV	CX,AX		; Save last full sector of current file
   172 00000076 09D2                    	OR	DX,DX
   173 00000078 7408                    	JZ	NORNDUP
   174 0000007A 83C001                  	ADD	AX,1		; Round up if any remainder			;AC000;
   175 0000007D 8316[0000]00            	ADC	word [HIGH_SECTOR_TEMP],0	;F.C. >32mb				;AN000;
   176                                  NORNDUP:
   177 00000082 FF36[0000]              	PUSH	word [HIGH_SECTOR_TEMP]	;F.C. >32mb				;AN000;
   178                                  VALSEC equ ValSec	; NASM port label
   179 00000086 8F06[0200]              	POP	WORD PTR [VALSEC+2]	;F.C. >32mb				;AN000;
   180 0000008A A3[0000]                	MOV	WORD PTR [VALSEC],AX  ;Number of sectors that have been written
   181 0000008D 31C0                    	XOR	AX,AX
   182                                  GROWCNT equ GrowCnt	; NASM port label
   183 0000008F A3[0000]                	MOV	WORD PTR [GROWCNT],AX
   184 00000092 A3[0200]                	MOV	WORD PTR [GROWCNT+2],AX
   185 00000095 58                      	POP	AX
   186                                  
   187 00000096 8B3E[0000]              	MOV	DI,[HIGH_SECTOR]	;F.C. >32mb				;AN000;
   188 0000009A 3B3E[0000]              	CMP	DI,[HIGH_SECTOR_TEMP]	;F.C. >32mb				;AN000;
   189 0000009E 7277                    	JB	NOGROW			;F.C. >32mb				;AN000;
   190 000000A0 7409                    	JZ	lowsec			;F.C. >32mb				;AN000;
   191 000000A2 29CB                    	SUB	BX,CX			;F.C. >32mb				;AN000;
   192 000000A4 1B3E[0000]              	SBB	DI,[HIGH_SECTOR_TEMP]	;F.C. >32mb di:bx no. of sectors	;AN000;
   193 000000A8 EB0A                    	JMP	yesgrow 		;F.C. >32mb				;AN000;
   194 000000AA 90                      	nop	; identicalise
   195                                  lowsec:
   196 000000AB BF0000                  	MOV	DI,0		;F.C. >32mb
   197 000000AE 29CB                    	SUB	BX,CX		; Number of full sectors
   198 000000B0 7265                    	JB	NOGROW
   199 000000B2 7456                    	JZ	TESTTAIL
   200                                  yesgrow:
   201 000000B4 89D1                    	MOV	CX,DX
   202 000000B6 93                      	XCHG	AX,BX
   203 000000B7 26F76602                	MUL	word [ES:BP + dpb_sector_size]  ; Bytes of full sector growth
   204 000000BB 8916[0000]              	MOV	[HIGH_SECTOR],DX	 ;F.C. >32mb save dx			;AN000;
   205 000000BF A3[0000]                	MOV	[HIGH_SECTOR_TEMP],AX	 ;F.C. >32mb save ax			;AN000;
   206 000000C2 89F8                    	MOV	AX,DI			 ;F.C. >32mb				;AN000;
   207 000000C4 26F76602                	MUL	word [ES:BP + dpb_sector_size]  ;F.C. >32mb do higher word multiply	;AN000;
   208 000000C8 0306[0000]              	ADD	AX,[HIGH_SECTOR]	 ;F.C. >32mb add lower value		;AN000;
   209 000000CC 89C2                    	MOV	DX,AX			 ;F.C. >32mb DX:AX is the result of	;AN000;
   210 000000CE A1[0000]                	MOV	AX,[HIGH_SECTOR_TEMP]	 ;F.C. >32mb a 32 bit multiply		;AN000;
   211                                  
   212 000000D1 29C8                    	SUB	AX,CX		; Take off current "tail"
   213 000000D3 83DA00                  	SBB	DX,0		; 32-bit extension
   214 000000D6 01D8                    	ADD	AX,BX		; Add on new "tail"
   215 000000D8 83D200                  	ADC	DX,0		; ripple tim's head off
   216 000000DB EB33                    	JMP	SHORT SETGRW
   217                                  HAVSTART:
   218                                  ;int 3
   219 000000DD 89C1                    	MOV	CX,AX
   220 000000DF E8(0000)                	invoke	SKPCLP
   221 000000E2 E320                    	JCXZ	DOWRTJ
   222                                  ;;; 11/5/86 FastSeek
   223 000000E4 8916[0000]              	MOV	[FSeek_logclus],DX   ; delete EOF (FFFFH)
   224 000000E8 FF06[0000]              	INC	word [FSeek_logclus]
   225 000000EC E8(0000)                	invoke	FastSeek_Truncate    ;
   226                                  ;;; 11/5/86 FastSeek
   227 000000EF E8(0000)                	invoke	ALLOCATE
   228 000000F2 7310                    	JNC	DOWRTJ
   229                                  
   230                                  	entry	WRTERR
   231                                  	DOSAssume   CS,<DS>,"DiskWrite/WrtErr"
   232                                  	ASSUME	ES:NOTHING
   233                                  
   234 000000F4 B40F                    	MOV	AH,0FH				;MS. write/data/fail/abort	;AN000;
   235                                   entry WRTERR22
   236                                  THISDRV equ ThisDRV	; NASM port label
   237 000000F6 A0[0000]                	MOV	AL,[THISDRV]			;MS.				;AN000;
   238 000000F9 E80302                  	CALL	File_Handle_Fail_Error	;MS. issue disk full I24
   239 000000FC B90000                  	MOV	CX,0			;No bytes transferred
   240                                  ;	XOR	CX,CX			; will be deleted
   241 000000FF C43E[0000]              	LES	DI,[THISSFT]
   242                                  	Assert	ISSFT,<ES,DI>,"DiskWrite/WrtErr"
   243                                  ;	CLC
   244 00000103 C3                      	return
   245                                  
   246 00000104 EB66                    DOWRTJ: JMP	DOWRT
   247 00000106 90                      	nop	; identicalise
   248                                  
   249                                  ACC_ERRWJ:
   250 00000107 E93E01                  	JMP	SET_ACC_ERRW
   251                                  
   252                                  TESTTAIL:
   253 0000010A 29D0                    	SUB	AX,DX
   254 0000010C 7609                    	JBE	NOGROW
   255 0000010E 31D2                    	XOR	DX,DX
   256                                  SETGRW:
   257 00000110 A3[0000]                	MOV	WORD PTR [GROWCNT],AX
   258 00000113 8916[0200]              	MOV	WORD PTR [GROWCNT+2],DX
   259                                  NOGROW:
   260 00000117 58                      	POP	AX
   261                                  CLUSNUM equ ClusNum	; NASM port label
   262 00000118 8B0E[0000]              	MOV	CX,[CLUSNUM]	; First cluster accessed
   263 0000011C E8(0000)                	invoke	FNDCLUS
   264 0000011F 72E6                    	JC	ACC_ERRWJ
   265 00000121 891E[0000]              	MOV	[CLUSNUM],BX
   266                                  LASTPOS equ LastPos	; NASM port label
   267 00000125 8916[0000]              	MOV	[LASTPOS],DX
   268                                  ;;; 11/5/86 FastSeek
   269 00000129 A3[0000]                	MOV	[FSeek_logclus],AX    ; set up last position
   270 0000012C 29D0                    	SUB	AX,DX		; Last cluster minus current cluster
   271 0000012E 743C                    	JZ	DOWRT		; If we have last clus, we must have first
   272 00000130 E3AB                    	JCXZ	HAVSTART	; See if no more data
   273 00000132 51                      	PUSH	CX		; No. of clusters short of first
   274 00000133 89C1                    	MOV	CX,AX
   275                                  
   276                                  ;;; 11/5/86 FastSeek
   277 00000135 833E[0000]00            	CMP	word [CLUSNUM],0	      ;FS. null file				;AN000;
   278 0000013A 740B                    	JZ	NULL_FILE	      ;FS. yes					;AN000;
   279 0000013C 8916[0000]              	MOV	[FSeek_logclus],DX    ;FS. delete EOF (FFFFH)			;AN000;
   280 00000140 FF06[0000]              	INC	word [FSeek_logclus]       ;FS.					;AN000;
   281 00000144 E8(0000)                	invoke	FastSeek_Truncate     ;FS.					;AN000;
   282                                  NULL_FILE:
   283                                  ;;; 11/5/86 FastSeek
   284 00000147 E8(0000)                	invoke	ALLOCATE
   285 0000014A 58                      	POP	AX
   286 0000014B 72A7                    	JC	WRTERR
   287 0000014D 89C1                    	MOV	CX,AX
   288 0000014F 8B16[0000]              	MOV	DX,[LASTPOS]
   289 00000153 42                      	INC	DX
   290 00000154 49                      	DEC	CX
   291 00000155 740D                    	JZ	NOSKIP
   292                                  ;;; 11/5/86 FastSeek
   293 00000157 8916[0000]              	MOV	[FSeek_logclus],DX    ;
   294 0000015B 010E[0000]              	ADD	[FSeek_logclus],CX    ; set up last position
   295 0000015F E8(0000)                	invoke	SKPCLP
   296 00000162 72A3                    	JC	ACC_ERRWJ
   297                                  NOSKIP:
   298 00000164 891E[0000]              	MOV	[CLUSNUM],BX
   299 00000168 8916[0000]              	MOV	[LASTPOS],DX
   300                                  DOWRT:
   301                                  BYTCNT1 equ BytCnt1	; NASM port label
   302 0000016C 833E[0000]00            	CMP	word [BYTCNT1],0
   303 00000171 7409                    	JZ	WRTMID
   304 00000173 8B1E[0000]              	MOV	BX,[CLUSNUM]
   305 00000177 E8(0000)                	invoke	BUFWRT
   306 0000017A 728B                    	JC	ACC_ERRWJ
   307                                  WRTMID:
   308                                  SECCNT_DOS equ SecCnt_DOS	; NASM port label
   309 0000017C A1[0000]                	MOV	AX,[SECCNT_DOS]
   310 0000017F 09C0                    	OR	AX,AX
   311 00000181 7503                    	JNZ	havemid
   312 00000183 E98500                  	JMP	WRTLAST
   313                                  havemid:
   314                                  SECPOS equ SecPos	; NASM port label
   315 00000186 0106[0000]              	ADD	WORD PTR [SECPOS],AX
   316 0000018A 8316[0200]00            	ADC	WORD PTR [SECPOS+2],0	 ;F.C. >32mb				;AN000;
   317 0000018F E8(0000)                	invoke	NEXTSEC
   318 00000192 7303                    	JNC	gotok
   319 00000194 E970FF                  	JMP	ACC_ERRWJ
   320                                  gotok:
   321                                  TRANS equ Trans	; NASM port label
   322 00000197 C606[0000]01            	MOV	BYTE PTR [TRANS],1	 ; A transfer is taking place
   323                                  SECCLUSPOS equ SecClusPos	; NASM port label
   324 0000019C 8A16[0000]              	MOV	DL,[SECCLUSPOS]
   325 000001A0 8B1E[0000]              	MOV	BX,[CLUSNUM]
   326 000001A4 8B0E[0000]              	MOV	CX,[SECCNT_DOS]
   327                                  WRTLP:
   328 000001A8 E8(0000)                	invoke	OPTIMIZE
   329 000001AB 7303                    	JNC	wokok
   330 000001AD E957FF                  	JMP	ACC_ERRWJ
   331                                  wokok:
   332 000001B0 57                      	PUSH	DI
   333 000001B1 50                      	PUSH	AX
   334 000001B2 52                      	PUSH	DX
   335 000001B3 53                      	PUSH	BX
   336                                  	Assert	ISDPB,<ES,BP>,"DiskWrite/WrtLp"
   337 000001B4 268A4600                	MOV	AL,[ES:BP + dpb_drive]
   338 000001B8 A2[0000]                	MOV	[SC_DRIVE],AL		  ;LB. save it for INVALIDATE_SC	;AN000;
   339 000001BB 51                      	PUSH	CX			  ;LB.					;AN000;
   340 000001BC FF36[0000]              	PUSH	word [HIGH_SECTOR]		  ;LB.					;AN000;
   341                                  %ifndef BUF2
   342                                  SCANNEXT:				  ;LB.					;AN000;
   343                                  	invoke	GETCURHEAD		  ;LB.					;AN000;
   344                                  %else
   345 000001C0 36C53E[0000]            	lds di, [ss:BUFFHEAD]
   346                                  %endif
   347                                  ASSUME	DS:NOTHING
   348                                  NEXTBUFF:			; Search for buffers
   349                                  %ifndef BUF2
   350                                  	CMP	word [ss:SC_CACHE_COUNT],0	    ;LB. SC support ?			;AN000;
   351                                  	JZ	nosc			    ;LB. no				;AN000;
   352                                  	PUSH	AX			    ;LB. save reg			;AN000;
   353                                  	PUSH	CX			    ;LB. save reg			;AN000;
   354                                  	PUSH	DX			    ;LB. save reg			;AN000;
   355                                  	invoke	INVALIDATE_SC		    ;LB. invalidate SC			;AN000;
   356                                  	POP	DX			    ;LB. save reg			;AN000;
   357                                  	POP	CX			    ;LB. save reg			;AN000;
   358                                  	POP	AX			    ;LB. save reg			;AN000;
   359                                  nosc:
   360                                  %endif
   361 000001C5 E8AE01                  	CALL	BUFF_RANGE_CHECK	    ;F.C. >32mb 			;AN000;
   362 000001C8 7305                    	JNC	inrange2		    ;F.C. >32mb 			;AN000;
   363                                  %ifdef BUF2
   364 000001CA C53D                    	lds di, [di + NEXTBUF]
   365                                  %else
   366                                  	mov	DI,[DI + buf_next]	    ;LB. get next buffer 1/19/88	;AN000;
   367                                  %endif
   368 000001CC EB12                    	JMP	DONEXTBUFF		    ;LB.				;AN000;
   369 000001CE 90                      	nop	; identicalise
   370                                  inrange2:
   371 000001CF F6450540                	TEST	byte [DI + buf_flags],buf_dirty    ;LB. if dirty			;AN000;
   372 000001D3 7403                    	JZ	not_dirty		    ;LB.				;AN000;
   373 000001D5 E8(0000)                	invoke	DEC_DIRTY_COUNT 	    ;LB. then decrement dirty count	;AN000;
   374                                  not_dirty:
   375                                  %ifdef BUF2
   376 000001D8 C74504FF00              	MOV	WORD PTR [DI + BUFDRV], 00FFH
   377                                  					; Free the buffer, it is being over written
   378                                  %else
   379                                  	MOV	WORD PTR [DI + buf_ID], 00FFH	  ; Free the buffer, it is being over written
   380                                  %endif
   381 000001DD E8(0000)                	invoke	SCANPLACE
   382                                  DONEXTBUFF:
   383                                  %ifdef BUF2
   384 000001E0 83FFFF                  	cmp di, -1
   385                                  %else
   386                                  	CMP	DI,[ss:FIRST_BUFF_ADDR]	  ;LB. end of chain			;AN000;
   387                                  %endif
   388 000001E3 75E0                    	JNZ	NEXTBUFF		  ;LB. no				;AN000;
   389                                  %ifndef BUF2
   390                                  	ADD	DX,1			  ;LB. next sector number		;AN000;
   391                                  	ADC	word [ss:HIGH_SECTOR],0 	  ;LB.					;AN000;
   392                                  	LOOP	SCANNEXT		  ;LB. check again			;AN000;
   393                                  %endif
   394 000001E5 368F06[0000]            	POP	word [ss:HIGH_SECTOR]		  ;LB.					;AN000;
   395 000001EA 59                      	POP	CX			  ;LB. get count back			;AN000;
   396                                  
   397 000001EB 5B                      	POP	BX
   398 000001EC 5A                      	POP	DX
   399 000001ED 368E1E[0200]            	MOV	DS,WORD PTR [ss:DMAADD+2]
   400                                   assume ds:nothing
   401                                  allowed_RETRY equ Allowed_RETRY	; NASM port equate
   402                                  allowed_FAIL equ Allowed_FAIL	; NASM port equate
   403                                  allowed_IGNORE equ Allowed_IGNORE	; NASM port equate
   404 000001F2 36C606[0000]38          	MOV	byte [ss:ALLOWED],allowed_RETRY + allowed_FAIL + allowed_IGNORE
   405                                  
   406                                  %ifndef BUF2
   407                                  %IF	BUFFERFLAG
   408                                  	pushf
   409                                  	cmp	byte [ss:BUF_EMS_MODE], -1
   410                                  	je	safe_write	
   411                                  save_map equ SAVE_MAP	; NASM port label
   412                                  	call	save_map
   413                                  restore_user_map equ RESTORE_USER_MAP	; NASM port label
   414                                  	call	restore_user_map
   415                                  safe_write:
   416                                  	popf
   417                                  %ENDIF	
   418                                  %endif
   419                                  
   420 000001F8 E8(0000)                	invoke	DWRITE
   421                                  
   422                                  %ifndef BUF2
   423                                  %IF	BUFFERFLAG
   424                                  	pushf
   425                                  	cmp	byte [ss:BUF_EMS_MODE], -1
   426                                  	je	safe_map	
   427                                  save_user_map equ SAVE_USER_MAP	; NASM port label
   428                                  	call	save_user_map
   429                                  restore_map equ RESTORE_MAP	; NASM port label
   430                                  	call	restore_map
   431                                  safe_map:
   432                                  	popf
   433                                  %ENDIF
   434                                  %endif
   435                                  
   436 000001FB 59                      	POP	CX
   437 000001FC 5B                      	POP	BX
   438 000001FD 161F                    	Context DS
   439 000001FF 7247                    	JC	SET_ACC_ERRW
   440 00000201 E308                    	JCXZ	WRTLAST
   441 00000203 B200                    	MOV	DL,0
   442 00000205 FF06[0000]              	INC	word [LASTPOS]	; We'll be using next cluster
   443 00000209 EB9D                    	JMP	WRTLP
   444                                  
   445                                  WRTLAST:
   446                                  BYTCNT2 equ BytCnt2	; NASM port label
   447 0000020B A1[0000]                	MOV	AX,[BYTCNT2]
   448 0000020E 09C0                    	OR	AX,AX
   449 00000210 7413                    	JZ	FINWRT
   450 00000212 A3[0000]                	MOV	[BYTCNT1],AX
   451 00000215 E8(0000)                	invoke	NEXTSEC
   452 00000218 722E                    	JC	SET_ACC_ERRW
   453                                  BYTSECPOS equ BytSecPos	; NASM port label
   454 0000021A C706[0000]0000          	MOV	word [BYTSECPOS],0
   455 00000220 E8(0000)                	invoke	BUFWRT
   456 00000223 7223                    	JC	SET_ACC_ERRW
   457                                  FINWRT:
   458 00000225 C43E[0000]              	LES	DI,[THISSFT]
   459                                  	Assert	ISSFT,<ES,DI>,"DiskWrite/FinWrt"
   460 00000229 A1[0000]                	MOV	AX,WORD PTR [GROWCNT]
   461 0000022C 8B0E[0200]              	MOV	CX,WORD PTR [GROWCNT+2]
   462 00000230 09C0                    	OR	AX,AX
   463                                  UPDATE_size equ Update_size	; NASM port label
   464 00000232 7502                    	JNZ	UPDATE_size
   465 00000234 E30F                    	JCXZ	SAMSIZ
   466                                  Update_size:
   467 00000236 26014511                	ADD	WORD PTR [ES:DI + sf_size],AX
   468 0000023A 26114D13                	ADC	WORD PTR [ES:DI + sf_size+2],CX
   469                                  ;
   470                                  ; Make sure that all other SFT's see this growth also.
   471                                  ;
   472 0000023E B80100                  	MOV	AX,1
   473                                  %if installed
   474 00000241 FF1E[3800]              	call	far [JShare + 14 * 4]
   475                                  %else
   476                                  	Call	ShSU
   477                                  %endif
   478                                  SAMSIZ:
   479 00000245 E9(0000)                	transfer SETCLUS		  ; ES:DI already points to SFT
   480                                  
   481                                  SET_ACC_ERRW:
   482 00000248 E9(0000)                	transfer SET_ACC_ERR_DS
   483                                  
   484                                  WRTEOF:
   485 0000024B 89C1                    	MOV	CX,AX
   486 0000024D 09D1                    	OR	CX,DX
   487 0000024F 7452                    	JZ	KILLFIL
   488 00000251 83E801                  	SUB	AX,1
   489 00000254 83DA00                  	SBB	DX,0
   490                                  
   491 00000257 53                      	PUSH	BX
   492 00000258 268B5E02                	MOV	BX,[ES:BP + dpb_sector_size]    ;F.C. >32mb			;AN000;
   493 0000025C E87F00                  	CALL	DIV32			      ;F.C. >32mb			;AN000;
   494 0000025F 5B                      	POP	BX			      ;F.C. >32mb			;AN000;
   495 00000260 E88A00                  	CALL	SHR32			      ;F.C. >32mb			;AN000;
   496                                  
   497                                  
   498                                  ;	SHR	AX,CL
   499 00000263 89C1                    	MOV	CX,AX
   500 00000265 E8(0000)                	invoke	FNDCLUS
   501                                  SET_ACC_ERRWJ2:
   502 00000268 72DE                    	JC	SET_ACC_ERRW
   503                                  ;;; 11/5/86 FastSeek
   504 0000026A 8916[0000]              	MOV	[FSeek_logclus],DX    ; truncate clusters starting from DX
   505 0000026E E8(0000)                	invoke	FastSeek_Truncate
   506                                  ;;; 11/5/86 FastSeek
   507 00000271 E326                    	JCXZ	RELFILE
   508 00000273 E8(0000)                	invoke	ALLOCATE
   509 00000276 721E                    	JC	WRTERRJ 	     ;;;;;;;;; disk full
   510                                  UPDATE:
   511 00000278 C43E[0000]              	LES	DI,[THISSFT]
   512                                  	Assert	ISSFT,<ES,DI>,"DiskWrite/update"
   513 0000027C A1[0000]                	MOV	AX,WORD PTR [BYTPOS]
   514 0000027F 26894511                	MOV	WORD PTR [ES:DI + sf_size],AX
   515 00000283 A1[0200]                	MOV	AX,WORD PTR [BYTPOS+2]
   516 00000286 26894513                	MOV	WORD PTR [ES:DI + sf_size+2],AX
   517                                  ;
   518                                  ; Make sure that all other SFT's see this growth also.
   519                                  ;
   520 0000028A B80200                  	MOV	AX,2
   521                                  %if installed
   522 0000028D FF1E[3800]              	Call	far [JShare + 14 * 4]
   523                                  %else
   524                                  	Call	ShSU
   525                                  %endif
   526 00000291 31C9                    	XOR	CX,CX
   527 00000293 E9(0000)                	transfer ADDREC
   528                                  
   529 00000296 E95BFE                  WRTERRJ: JMP	 WRTERR
   530                                  ;;;;;;;;;;;;;;;; 7/18/86
   531                                  ;;;;;;;;;;;;;;;;;
   532                                  RELFILE:
   533 00000299 BAFFFF                  	MOV	DX,0FFFFH
   534 0000029C E8(0000)                	invoke	RELBLKS
   535                                  Set_Acc_ERRWJJ:
   536 0000029F 72C7                    	JC	SET_ACC_ERRWJ2
   537 000002A1 EBD5                    	JMP	SHORT UPDATE
   538                                  
   539                                  KILLFIL:
   540 000002A3 31DB                    	XOR	BX,BX
   541 000002A5 06                      	PUSH	ES
   542 000002A6 C43E[0000]              	LES	DI,[THISSFT]
   543                                   assume es:nothing
   544                                  	Assert	ISSFT,<ES,DI>,"DiskWrite/KillFil"
   545 000002AA 26895D19                	MOV	[ES:DI + sf_cluspos],BX
   546 000002AE 26895D35                	MOV	[ES:DI + sf_lstclus],BX
   547 000002B2 26875D0B                	XCHG	BX,[ES:DI + sf_firclus]
   548 000002B6 07                      	POP	ES
   549                                   assume es:nothing
   550                                  ;; 11/5/86 FastSeek
   551 000002B7 E8(0000)                	invoke	Delete_FSeek   ; delete fastseek entry
   552                                  
   553 000002BA 09DB                    	OR	BX,BX
   554                                  UPDATEJ equ UpDateJ	; NASM port label
   555 000002BC 741E                    	JZ	UPDATEJ
   556                                  ;; 10/23/86 FastOpen update
   557 000002BE 06                      	PUSH	ES		; since first cluster # is 0
   558 000002BF 55                      	PUSH	BP		; we must delete the old cache entry
   559 000002C0 50                      	PUSH	AX
   560 000002C1 51                      	PUSH	CX
   561 000002C2 52                      	PUSH	DX
   562 000002C3 C42E[0000]              	LES	BP,[THISDPB]		 ; get current DPB
   563                                   assume es:DPB
   564 000002C7 268A5600                	MOV	DL,[ES:BP + dpb_drive]	 ; get current drive
   565 000002CB 89D9                    	MOV	CX,BX			 ; first cluster #
   566 000002CD B402                    	MOV	AH,2			 ; delete cache entry by drive:firclus
   567 000002CF E8(0000)                	invoke	FastOpen_Update 	 ; call fastopen
   568 000002D2 5A                      	POP	DX
   569 000002D3 59                      	POP	CX
   570 000002D4 58                      	POP	AX
   571 000002D5 5D                      	POP	BP
   572 000002D6 07                      	POP	ES
   573                                   assume es:nothing
   574                                  ;; 10/23/86 FastOpen update
   575                                  
   576 000002D7 E8(0000)                	invoke	RELEASE
   577                                  SET_ACC_ERRWJJ equ Set_Acc_ERRWJJ	; NASM port label
   578 000002DA 72C3                    	JC	SET_ACC_ERRWJJ
   579                                  UpDateJ:
   580 000002DC EB9A                    	JMP	UPDATE
   581                                  EndProc DISKWRITE
   582                                  
   583                                  
   584                                  
   585                                  Break	<DIV32 -- PERFORM 32 BIT DIVIDE>
   586                                  
   587                                  ; Inputs:
   588                                  ;	DX:AX = 32 bit dividend   BX= divisor
   589                                  ; Function:
   590                                  ;	Perform 32 bit division
   591                                  ; Outputs:
   592                                  ;	[HIGH_SECTOR]:AX = quotiend , DX= remainder
   593                                  
   594                                  	procedure   DIV32,NEAR
   594          ******************       warning: proc DIV32... [-w+user]
   595                                  	ASSUME	DS:NOTHING,ES:NOTHING
   596                                  
   597                                  
   598 000002DE 50                      	PUSH	AX			;F.C. >32mb				;AN000;
   599 000002DF 89D0                    	MOV	AX,DX			;F.C. >32mb				;AN000;
   600 000002E1 31D2                    	XOR	DX,DX			;F.C. >32mb				;AN000;
   601 000002E3 F7F3                    	DIV	BX			;F.C. >32mb				;AN000;
   602 000002E5 36A3[0000]              	MOV	[ss:HIGH_SECTOR],AX	;F.C. >32mb				;AN000;
   603 000002E9 58                      	POP	AX			;F.C. >32mb				;AN000;
   604                                  
   605                                  
   606 000002EA F7F3                    	DIV	BX			; AX=last sector accessed
   607 000002EC C3                      	return
   608                                  
   609                                  EndProc DIV32
   610                                  
   611                                  Break	<SHR32 -- PERFORM 32 BIT SHIFT RIGHT>
   612                                  
   613                                  ; Inputs:
   614                                  ;	[HIGH_SECTOR]:AX = 32 bit sector number
   615                                  ; Function:
   616                                  ;	Perform 32 bit shift right
   617                                  ; Outputs:
   618                                  ;	AX= cluster number
   619                                  
   620                                  	procedure   SHR32,NEAR
   620          ******************       warning: proc SHR32... [-w+user]
   621                                  	ASSUME	DS:NOTHING,ES:NOTHING
   622                                  
   623 000002ED 31C9                    	xor cx, cx
   624 000002EF 268A4E05                	MOV	CL,[ES:BP + dpb_cluster_shift]
   625                                  entry ROTASHFT				;F.C. >32mb				;AN000;
   626 000002F3 E309                    	jcxz	norota			;F.C. >32mb				;AN000;
   627                                  ROTASHFT2:
   628 000002F5 36D12E[0000]            	shr	word [ss:HIGH_SECTOR],1 	;F.C. >32mb				;AN000;
   629 000002FA D1D8                    	RCR	AX,1			;F.C. >32mb				;AN000;
   630 000002FC E2F7                    	LOOP	ROTASHFT2		;F.C. >32mb:				;AN000;
   631                                  norota:
   632 000002FE C3                      	return
   633                                  
   634                                  EndProc SHR32
   635                                  
   636                                  
   637                                  ; Issue File Handle Fail INT 24 Critical Error
   638                                  ; Input: Disk_Full=0  ok
   639                                  ;		   1  disk full or EOF
   640                                  ; Function: issue critical error for disk full or EOF error
   641                                  ;
   642                                  ; OutPut: carry clear , no I24
   643                                  ;	  carry set, fail from I24
   644                                  
   645                                  procedure File_Handle_Fail_Error,NEAR						;AN000;
   645          ******************       warning: proc File_Handle_Fail_Error... [-w+user]
   646                                  	ASSUME	ES:NOTHING,DS:NOTHING						;AN000;
   647                                  										;AN000;
   648 000002FF 36803E[0000]00          	CMP	byte [ss:DISK_FULL],0	 ;MS. disk full or EOF				;AN000;
   649 00000305 746D                    	JZ	Fexit		 ;MS. no					;AN000;
   650 00000307 36F706[0000]4000        	TEST	word [ss:DOS34_FLAG],Disable_EOF_I24   ;MS. check input status ?	;AN000;
   651 0000030E 7564                    	JNZ	Fexit		 ;MS. yes					;AN000;
   652                                  										;AN000;
   653 00000310 36C43E[0000]            	LES	DI,[ss:THISSFT]	 ;MS. get current SFT				;AN000;
   654                                  ;	LES	DI,[ES:DI.sf_DEVPTR];MS. get device header			;AN000;
   655 00000315 26F745050001            	TEST	word [ES:DI + sf_flags],Handle_Fail_I24  ;MS. gen I24 ?		;AN000;
   656 0000031B 7457                    	JZ	Fexit		 ;MS. no					;AN000;
   657 0000031D 1E                      	PUSH	DS		 ;MS. save DS					;AN000;
   658 0000031E F6C401                  	TEST	AH,1				;MS. READ ?			;AN000;
   659 00000321 7409                    	JZ	readeof 			;MS. yes			;AN000;
   660                                  error_Handle_Disk_Full equ error_handle_Disk_Full	; NASM port equate
   661 00000323 36C706[0000]2700        	MOV	word [ss:EXTERR],error_Handle_Disk_Full ;MS. set extended error 	;AN000;
   662 0000032A EB07                    	JMP	SHORT errset			;MS. set extended error 	;AN000;
   663                                  readeof:
   664                                  error_Handle_EOF equ error_handle_EOF	; NASM port equate
   665 0000032C 36C706[0000]2600        	MOV	word [ss:EXTERR],error_Handle_EOF	;MS. set extended error 	;AN000;
   666                                  errset:
   667 00000333 36C606[0000]01          	MOV	byte [ss:EXTERR_CLASS],errCLASS_OutRes	;MS. set class			;AN000;
   668 00000339 36C606[0000]04          	MOV	byte [ss:EXTERR_ACTION],errACT_Abort	;MS. set action 		;AN000;
   669 0000033F 36C606[0000]01          	MOV	byte [ss:EXTERR_LOCUS],errLOC_Unk	;MS. set locus			;AN000;
   670 00000345 368C06[0200]            	MOV	word ptr [ss:EXITHOLD + 2],ES	;MS. save es:bp in exithold	;AN000;
   671 0000034A 36892E[0000]            	MOV	word ptr [ss:EXITHOLD],BP		;MS.				;AN000;
   672 0000034F 26F745058000            	TEST	word [ES:DI + sf_flags],devid_device	  ;MS. device  ?		;AN000;
   673 00000355 7509                    	JNZ	chardev2			  ;MS. yes			;AN000;
   674                                  sf_DEVPTR equ sf_devptr	; NASM port equate
   675 00000357 26C57507                	LDS	SI,[ES:DI + sf_DEVPTR]		  ;MS. get dpb			;AN000;
   676 0000035B C57413                  	LDS	SI,[SI + dpb_driver_addr] 	  ;MS. get drive device haeder	;AN000;
   677 0000035E EB04                    	JMP	SHORT doi24			  ;MS. gen I24 ?		;AN000;
   678                                  chardev2:
   679 00000360 26C57507                	LDS	SI,[ES:DI + sf_DEVPTR]		  ;MS. get chr dev header	;AN000;
   680                                  doi24:
   681 00000364 8CDD                    	MOV	BP,DS				  ;MS. bp:si -> device header	;AN000;
   682 00000366 BF0C00                  	MOV	DI,error_I24_gen_failure	;MS. general error		;AN000;
   683 00000369 E8(0000)                	invoke	NET_I24_ENTRY			;MS. issue I24			;AN000;
   684 0000036C F9                      	STC					;MS. must be fail		;AN000;
   685 0000036D 1F                      	POP	DS				;MS. restore DS 		;AN000;
   686                                   assume ds:nothing
   687 0000036E 36A1[0000]              	MOV	AX,[ss:EXTERR]			;MS. set error			;AN000;
   688 00000372 EB01                    	JMP	SHORT Fend			;MS. exit			;AN000;
   689                                  Fexit:										;AN000;
   690 00000374 F8                      	CLC					;MS. clear carry		;AN000;
   691                                  Fend:										;AN000;
   692 00000375 C3                      	return					;MS.				;AN000;
   693                                  										;AN000;
   694                                  EndProc File_Handle_Fail_Error							;AN000;
   695                                  
   696                                  
   697                                  Break	<BUFF_RANGE_CHECK- buffer range checkink>
   698                                  
   699                                  ; Inputs:
   700                                  ;	DS:DI -> buffer. AL= drive #
   701                                  ;	[HIGH_SECTOR]:DX = sector #
   702                                  ; Function:
   703                                  ;	check if sector is in the buffer
   704                                  ; Outputs:
   705                                  ;	carry clear= in the range
   706                                  ;	      set  = not in the range
   707                                  
   708                                  	procedure   BUFF_RANGE_CHECK,NEAR
   708          ******************       warning: proc BUFF_RANGE_CHECK... [-w+user]
   709                                  	ASSUME	DS:NOTHING,ES:NOTHING
   710                                  
   711 00000376 395508                  	CMP	WORD PTR [DI + buf_sector],DX					;AN000;
   712 00000379 750F                    	JNZ	DONEXTBUFF2	; not this sector	   ;F.C. >32mb		;AN000;
   713 0000037B 368B36[0000]            	MOV	SI,[ss:HIGH_SECTOR]			   ;F.C. >32mb		;AN000;
   714 00000380 39750A                  	CMP	WORD PTR [DI + buf_sector+2],SI		   ;F.C. >32mb		;AN000;
   715 00000383 7505                    	JNZ	DONEXTBUFF2	; Not for this drive
   716 00000385 3A4504                  	CMP	AL,[DI + buf_ID]
   717 00000388 7401                    	JZ	secfound	; Buffer has the sector 			;AN000;
   718                                  DONEXTBUFF2:
   719 0000038A F9                      	STC
   720                                  secfound:
   721 0000038B C3                      	return
   722                                  
   723                                  EndProc BUFF_RANGE_CHECK
   724                                  
   725                                      END
   726                                  
   727                                  
