     1                                  ;	SCCSID = @(#)dev.asm	1.2 85/07/23
     2                                  ;	SCCSID = @(#)dev.asm	1.2 85/07/23
     3                                  ;TITLE	DEV - Device call routines
     4                                  ;NAME	Dev
     5                                  ; Misc Routines to do 1-12 low level I/O and call devices
     6                                  ;
     7                                  ;   IOFUNC
     8                                  ;   DEVIOCALL
     9                                  ;   SETREAD
    10                                  ;   SETWRITE
    11                                  ;   DEVIOCALL2
    12                                  ;   DEV_OPEN_SFT
    13                                  ;   DEV_CLOSE_SFT
    14                                  ;   RW_SC
    15                                  ;   IN_SC
    16                                  ;   INVALIDATE_SC
    17                                  ;   VIRREAD
    18                                  ;   SC2BUF
    19                                  ;
    20                                  ;   Revision history:
    21                                  ;
    22                                  ;	A000  version 4.00     Jan. 1988
    23                                  ;	A010  disable change line for SHARE /NC
    24                                  
    25                                  ;
    26                                  ; get the appropriate segment definitions
    27                                  ;
    28                                  [list -]
    28          ******************       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
    30                                  
    31                                  [list +]
    32                                  section DOSCODECODE
    33                                  [list -]
    33          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    33          ******************       warning: out: BPB.INC... [-w+user]
    33          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    33          ******************       warning: out: DEVSYM.INC... [-w+user]
    33          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    41                                  
    42                                  	i_need	IOXAD,DWORD
    43                                  	i_need	IOSCNT,WORD
    44                                  	i_need	DEVIOBUF,4
    45                                  	i_need	IOCALL,BYTE
    46                                  	i_need	IOMED,BYTE
    47                                  	i_need	IORCHR,BYTE
    48                                  	i_need	CALLSCNT,WORD
    49                                  	i_need	DMAAdd,DWORD
    50                                  	i_need	CallDevAd,DWORD
    51                                  	i_need	CallXAD,DWORD
    52                                  	i_need	DPBHead,DWORD
    53                                  	i_need	ThisSFT,DWORD
    54                                  	i_need	ThisDPB,DWORD
    55                                  	i_need	DevCall,DWORD
    56                                  	i_need	VerFlg,BYTE
    57                                  	i_need	HIGH_SECTOR,WORD	       ;AN000;
    58                                  	i_need	CALLSSEC,WORD		       ;AN000;
    59                                  	i_need	CALLNEWSC,DWORD 	       ;AN000;
    60                                  	i_need	SC_CACHE_COUNT,WORD	       ;AN000;
    61                                  	i_need	SC_CACHE_PTR,DWORD	       ;AN000;
    62                                  	i_need	CURSC_SECTOR,WORD	       ;AN000;
    63                                  	i_need	SEQ_SECTOR,DWORD	       ;AN000;
    64                                  	i_need	SC_SECTOR_SIZE,WORD	       ;AN000;
    65                                  	i_need	CURSC_DRIVE,BYTE	       ;AN000;
    66                                  	i_need	SC_DRIVE,BYTE		       ;AN000;
    67                                  	i_need	SC_STATUS,WORD		       ;AN000;
    68                                  	i_need	SC_FLAG,BYTE		       ;AN000;
    69                                  	i_need	TEMP_VAR,WORD		       ;AN000;
    70                                  	i_need	TEMP_VAR2,WORD		       ;AN000;
    71                                  	i_need	InterChar,BYTE	;AN000; interim character flag 2/13/KK
    72                                  	i_need	InterCon,BYTE	;AN000; Console mode flag(1:interim mode) 2/13/KK
    73                                  	i_need	SaveCurFlg,BYTE ;AN000; Console out mode(1:print & don't adv cursor) 2 /13/KK
    74                                  	i_need	DDMOVE,BYTE	;AN000; flag for DWORD move
    75                                  	i_need	DOS34_FLAG,WORD ;AN000;
    76                                  	i_need	fshare,BYTE	;AN010; share flag
    77                                  
    78                                   assume nocheck, ss:DOSGROUP
    79                                  
    80                                  Break	<IOFUNC -- DO FUNCTION 1-12 I/O>
    81                                  
    82                                  ; Inputs:
    83                                  ;	DS:SI Points to SFT
    84                                  ;	AH is function code
    85                                  ;		= 0 Input
    86                                  ;		= 1 Input Status
    87                                  ;		= 2 Output
    88                                  ;		= 3 Output Status
    89                                  ;		= 4 Flush
    90                                  ;		= 5 Input Status - System WAIT invoked for K09 if no char
    91                                  ;				   present.
    92                                  ;	AL = character if output
    93                                  ; Function:
    94                                  ;	Perform indicated I/O to device or file
    95                                  ; Outputs:
    96                                  ;	AL is character if input
    97                                  ;	If a status call
    98                                  ;		zero set if not ready
    99                                  ;		zero reset if ready (character in AL for input status)
   100                                  ; For regular files:
   101                                  ;	Input Status
   102                                  ;		Gets character but restores position
   103                                  ;		Zero set on EOF
   104                                  ;	Input
   105                                  ;		Gets character advances position
   106                                  ;		Returns ^Z on EOF
   107                                  ;	Output Status
   108                                  ;		Always ready
   109                                  ; AX altered, all other registers preserved
   110                                  
   111                                  	procedure   IOFUNC,NEAR
   111          ******************       warning: proc IOFUNC... [-w+user]
   112                                  ASSUME	DS:NOTHING,ES:NOTHING
   113                                  
   114                                  	Assert	ISSFT,<DS,SI>,"IOFUNC"
   115 00000000 368C16[0200]            	MOV	WORD PTR [ss:IOXAD+2],SS
   116 00000005 36C706[0000][0000]      	MOV	WORD PTR [ss:IOXAD],OFFSET DEVIOBUF wrt DOSGROUP
   117 0000000C 36C706[0000]0100        	MOV	WORD PTR [ss:IOSCNT],1
   118 00000013 36A3[0000]              	MOV	WORD PTR [ss:DEVIOBUF],AX
   119 00000017 F744050080              	TEST	word [SI + sf_flags],sf_isnet
   120 0000001C 7403                    	JZ	IOTO22								;AN000;
   121 0000001E E9A000                  	JMP	IOTOFILE							;AN000;
   122                                  IOTO22:
   123 00000021 F744058000              	TEST	word [SI + sf_flags],devid_device
   124                                  IOTo33 equ IOTO33	; NASM port label
   125 00000026 7503                    	JNZ	IOTo33								;AN000;
   126 00000028 E99600                  	JMP	IOTOFILE							;AN000;
   127                                  IOTO33:
   128 0000002B E8(0000)                	invoke	save_world
   129 0000002E 8CDA                    	MOV	DX,DS
   130 00000030 8CD3                    	MOV	BX,SS
   131 00000032 8EDB                    	MOV	DS,BX
   132                                   assume ds:DOSGROUP
   133 00000034 8EC3                    	MOV	ES,BX
   134                                   assume es:DOSGROUP
   135 00000036 31DB                    	XOR	BX,BX
   136 00000038 80FC05                  	cmp	ah,5		    ; system wait enabled?
   137 0000003B 7504                    	jnz	no_sys_wait
   138 0000003D 81CB0004                	or	bx,0400H	    ; Set bit 10 in status word for driver
   139                                  				    ; It is up to device driver to carry out
   140                                  				    ; appropriate action.
   141                                  no_sys_wait:
   142 00000041 891E[0300]              	MOV	[IOCALL + REQSTAT],BX
   143 00000045 31DB                    	XOR	BX,BX
   144 00000047 881E[0000]              	MOV	BYTE PTR [IOMED],BL
   145                                  
   146                                  section DOSCODETABLE
   147                                  DEV001S equ DEV001s	; NASM port label
   148                                  Public DEV001S, DEV001E 		; Pathgen labels
   149                                  DEV001s:
   150                                  ;		length of packets
   151 00000000 160E160D0F0E            LenTab	DB	DRDWRHL, DRDNDHL, DRDWRHL, DSTATHL, DFLSHL, DRDNDHL
   152                                  
   153                                  ;		Error	Function
   154                                  
   155 00000006 8604                    CmdTab	DB	86h,	DEVRD		; 0 input
   156 00000008 8605                    	DB	86h,	DEVRDND 	; 1 input status
   157 0000000A 8708                    	DB	87h,	DEVWRT		; 2 output
   158 0000000C 870A                    	DB	87h,	DEVOST		; 3 output status
   159 0000000E 8607                    	DB	86h,	DEVIFL		; 4 input flush
   160 00000010 8605                    	DB	86H,	DEVRDND 	; 5 input status with system WAIT
   161                                  DEV001E:
   162                                  DOSCODETABLE	ENDS
   163                                  section DOSCODECODE
   164                                  
   165 0000004B 88E3                    	MOV	BL,AH			; get function
   166 0000004D 2E8AA7[0000]            	MOV	AH,[cs:LenTab + BX]
   167 00000052 D1E3                    	SHL	BX,1
   168 00000054 2E8B8F[0600]            	MOV	CX,WORD PTR [cs:CmdTab + BX]
   169                                  
   170 00000059 BB[0000]                	MOV	BX,OFFSET IOCALL wrt DOSGROUP
   171                                  
   172 0000005C 8826[0000]              	MOV	[IOCALL + REQLEN],AH
   173 00000060 882E[0200]              	MOV	[IOCALL + REQFUNC],CH
   174                                   %IF  DBCS				;AN000;
   175                                  ;----------------------------- Start of DBCS 2/13/KK
   176                                  	PUSH	CX			;AN000;
   177                                  	MOV	CL, [InterCon]		;AN000;
   178                                  	CMP	CH, DEVRD		;AN000; 0 input
   179                                  	JZ	SETIN			;AN000;
   180                                  	CMP	CH, DEVRDND		;AN000; 1(5) input status without(with) system WAIT
   181                                  	JZ	SETIN			;AN000;
   182                                  SaveCurflg equ SaveCurFlg	; NASM port label
   183                                  	MOV	CL, [SaveCurflg]	;AN000;
   184                                  	CMP	CH, DEVWRT		;AN000; 2 output
   185                                  	JZ	CHKERROUT		;AN000;
   186                                  	XOR	CL,CL			;AN000; else, do normal
   187                                  SETIN:					;AN000;
   188                                  IoMed equ IOMED	; NASM port label
   189                                  	MOV	BYTE PTR [IoMed], CL	;AN000; set interim I/O indication
   190                                  	POP	CX			;AN000;
   191                                  ;----------------------------- End of DBCS 2/13/KK
   192                                   %ENDIF					;AN000;
   193 00000064 8EDA                    	MOV	DS,DX
   194                                  ASSUME	DS:NOTHING
   195 00000066 E86701                  	CALL	DEVIOCALL
   196 00000069 368B3E[0300]            	MOV	DI,[ss:IOCALL + REQSTAT]
   197 0000006E F7C70080                	TEST	DI,STERR
   198 00000072 7520                    	JNZ	DevErr
   199                                  OkDevIO:
   200 00000074 8CD0                    	MOV	AX,SS
   201 00000076 8ED8                    	MOV	DS,AX
   202                                  	ASSUME	DS:DOSGroup
   203                                   %IF  DBCS			;AN000;
   204                                  	MOV	byte [InterChar],0	;AN000; reset interim character flag  2/13/KK
   205                                  	TEST	DI,Ddkey	;AN000; is this a dead key (interim char)? 2/13/KK
   206                                  	JZ	NotInterim	;AN000; no, flag already reset...	   2/13/KK
   207                                  	INC	byte [InterChar]	;AN000; yes, set flag for future	   2/13/KK
   208                                  NotInterim:			;AN000; 				   2/13/KK
   209                                   %ENDIF				;AN000;
   210 00000078 80FD05                  	CMP	CH,DEVRDND
   211 0000007B 7506                    	JNZ	DNODRD
   212 0000007D A0[0000]                	MOV	AL,BYTE PTR [IORCHR]
   213 00000080 A2[0000]                	MOV	[DEVIOBUF],AL
   214                                  
   215 00000083 8A26[0400]              DNODRD: MOV	AH,BYTE PTR [IOCALL + REQSTAT+1]
   216 00000087 F6D4                    	NOT	AH			; Zero = busy, not zero = ready
   217 00000089 80E402                  	AND	AH,STBUI >> 8
   218                                  
   219                                  QuickReturn:				;AN000; 2/13/KK
   220 0000008C E8(0000)                	invoke	restore_world
   221                                  ASSUME	DS:NOTHING
   222 0000008F 36A1[0000]              	MOV	AX,WORD PTR [ss:DEVIOBUF]
   223 00000093 C3                      	return
   224                                  
   225                                  ;IOTOFILEJ:
   226                                  ;	JMP	SHORT IOTOFILE
   227                                   %IF  DBCS				;AN000;
   228                                  ;------------------------------ Start of DBCS 2/13/KK
   229                                  CHKERROUT:				;AN000;
   230                                  	MOV	DS, DX			;AN000;
   231                                  	TEST	word [SI + sf_flags], devid_device_con_out	;AN000; output to console ?
   232                                  	JNZ	GOOD			;AN000; yes
   233                                  	CMP	CL, 01			;AN000; write interim ?
   234                                  	JNZ	GOOD			;AN000; no,
   235                                  	POP	CX			;AN000;
   236                                  	JMP	SHORT QuickReturn	;AN000; avoid writting interims to other than
   237                                  					;AN000; console device
   238                                  GOOD:					;AN000;
   239                                  	PUSH	SS			;AN000;
   240                                  	POP	DS			;AN000;
   241                                  	JMP	SETIN			;AN000;
   242                                  ;------------------------------ End of DBCS 2/13/KK
   243                                   %ENDIF					;AN000;
   244                                  DevErr:
   245                                  X25_Special equ X25_special	; NASM port equate
   246 00000094 36F706[0000]0008        	TEST	word [ss:DOS34_FLAG],X25_Special ;AN000; from disk.asm
   247 0000009B 740D                    	JZ	notx25			 ;AN000; no
   248 0000009D 50                      	PUSH	AX			 ;AN000; unknown command ?
   249 0000009E 89F8                    	MOV	AX,DI			 ;AN000;
   250 000000A0 83E003                  	AND	AX,error_I24_bad_command ;AN000;
   251 000000A3 3C03                    	CMP	AL,error_I24_bad_command ;AN000;
   252 000000A5 58                      	POP	AX			 ;AN000;
   253 000000A6 7502                    	JNZ	notx25			 ;AN000; no, then error
   254                                  okDevIO equ OkDevIO	; NASM port label
   255 000000A8 EBCA                    	JMP	okDevIO 		 ;AN000;
   256                                  notx25:
   257 000000AA 88CC                    	MOV	AH,CL
   258 000000AC E8(0000)                	invoke	CHARHARD
   259 000000AF 3C01                    	CMP	AL,1
   260 000000B1 7506                    	JNZ	NO_RETRY
   261 000000B3 E8(0000)                	invoke	restore_world
   262 000000B6 E947FF                  	JMP	IOFUNC
   263                                  
   264                                  NO_RETRY:
   265                                  ;   Know user must have wanted Ignore OR Fail.	Make sure device shows ready
   266                                  ;   so that DOS doesn't get caught in a status loop when user simply wants
   267                                  ;   to ignore the error.
   268 000000B9 368026[0400]FD          	AND	BYTE PTR [ss:IOCALL + REQSTAT+1], ~ (STBUI >> 8)
   269                                  OKDevIO equ OkDevIO	; NASM port label
   270 000000BF EBB3                    	JMP	OKDevIO
   271                                  
   272                                  IOTOFILE:
   273                                  ASSUME	DS:NOTHING
   274 000000C1 08E4                    	OR	AH,AH
   275 000000C3 7423                    	JZ	IOIN
   276 000000C5 FECC                    	DEC	AH
   277 000000C7 7405                    	JZ	IOIST
   278 000000C9 FECC                    	DEC	AH
   279 000000CB 7411                    	JZ	IOUT
   280 000000CD C3                      	return				; NON ZERO FLAG FOR OUTPUT STATUS
   281                                  
   282                                  IOIST:
   283 000000CE FF7415                  	PUSH	WORD PTR [SI + sf_position]   ; Save position
   284 000000D1 FF7417                  	PUSH	WORD PTR [SI + sf_position+2]
   285 000000D4 E81100                  	CALL	IOIN
   286 000000D7 8F4417                  	POP	WORD PTR [SI + sf_position+2] ; Restore position
   287 000000DA 8F4415                  	POP	WORD PTR [SI + sf_position]
   288 000000DD C3                      	return
   289                                  
   290                                  IOUT:
   291 000000DE E82700                  	CALL	SETXADDR
   292 000000E1 E8(0000)                	invoke	DOS_WRITE
   293 000000E4 E85400                  	CALL	RESTXADDR		; If you change this into a jmp don't
   294 000000E7 C3                      	return				; come crying to me when things don't
   295                                  					; work ARR
   296                                  
   297                                  IOIN:
   298 000000E8 E81D00                  	CALL	SETXADDR
   299 000000EB 36830E[0000]40          	OR	word [ss:DOS34_FLAG],Disable_EOF_I24   ;AN000;
   300 000000F1 E8(0000)                	invoke	DOS_READ
   301 000000F4 368326[0000]BF          	AND	word [ss:DOS34_FLAG],NO_Disable_EOF_I24   ;AN000;
   302 000000FA 09C9                    	OR	CX,CX			; Check EOF
   303 000000FC E83C00                  	CALL	RESTXADDR
   304 000000FF 36A0[0000]              	MOV	AL,[ss:DEVIOBUF]		; Get byte from trans addr
   305 00000103 75E2                    	retnz
   306 00000105 B01A                    	MOV	AL,1AH			; ^Z if no bytes
   307 00000107 C3                      	return
   308                                  
   309                                  SETXADDR:
   310 00000108 368F06[0000]            	POP	WORD PTR [ss:CALLSCNT]	; Return address
   311 0000010D E8(0000)                	invoke	save_world
   312                                  DMAADD equ DMAAdd	; NASM port label
   313 00000110 36FF36[0000]            	PUSH	WORD PTR [ss:DMAADD]	; Save Disk trans addr
   314 00000115 36FF36[0200]            	PUSH	WORD PTR [ss:DMAADD+2]
   315                                  THISSFT equ ThisSFT	; NASM port label
   316 0000011A 368C1E[0200]            	MOV	WORD PTR [ss:THISSFT+2],DS
   317 0000011F 161F                    	Context DS
   318 00000121 8936[0000]              	MOV	WORD PTR [THISSFT],SI	; Finish setting SFT pointer
   319 00000125 8B0E[0200]              	MOV	CX,WORD PTR [IOXAD+2]
   320 00000129 890E[0200]              	MOV	WORD PTR [DMAADD+2],CX
   321 0000012D 8B0E[0000]              	MOV	CX,WORD PTR [IOXAD]
   322 00000131 890E[0000]              	MOV	WORD PTR [DMAADD],CX	; Set byte trans addr
   323 00000135 8B0E[0000]              	MOV	CX,[IOSCNT]		; ioscnt specifies length of buffer
   324 00000139 EB0F                    	JMP	SHORT RESTRET		; RETURN ADDRESS
   325                                  
   326                                  RESTXADDR:
   327                                  	DOSAssume   CS,<DS>,"RestXAddr"
   328 0000013B 8F06[0000]              	POP	WORD PTR [CALLSCNT]	; Return address
   329 0000013F 8F06[0200]              	POP	WORD PTR [DMAADD+2]	; Restore Disk trans addr
   330 00000143 8F06[0000]              	POP	WORD PTR [DMAADD]
   331 00000147 E8(0000)                	invoke	restore_world
   332                                  ASSUME	DS:NOTHING
   333 0000014A 36FF26[0000]            RESTRET:JMP	WORD PTR [ss:CALLSCNT]	; Return address
   334                                  EndProc IOFUNC
   335                                  
   336                                  Break <DEV_OPEN_SFT, DEV_CLOSE_SFT - OPEN or CLOSE A DEVICE>
   337                                  
   338                                  ; Inputs:
   339                                  ;	ES:DI Points to SFT
   340                                  ; Function:
   341                                  ;	Issue an OPEN call to the correct device
   342                                  ; Outputs:
   343                                  ;	None
   344                                  ; ALL preserved
   345                                  
   346                                  	procedure   DEV_OPEN_SFT,NEAR
   346          ******************       warning: proc DEV_OPEN_SFT... [-w+user]
   347                                  ASSUME	DS:NOTHING,ES:NOTHING
   348                                  
   349                                  	Assert	ISSFT,<ES,DI>,"Dev_Open_SFT"
   350 0000014F E8(0000)                	invoke	Save_World
   351 00000152 B00D                    	MOV	AL,DEVOPN
   352 00000154 EB05                    	JMP	SHORT DO_OPCLS
   353                                  
   354                                  EndProc DEV_OPEN_SFT
   355                                  
   356                                  ; Inputs:
   357                                  ;	ES:DI Points to SFT
   358                                  ; Function:
   359                                  ;	Issue a CLOSE call to the correct device
   360                                  ; Outputs:
   361                                  ;	None
   362                                  ; ALL preserved
   363                                  
   364                                  	procedure   DEV_CLOSE_SFT,NEAR
   364          ******************       warning: proc DEV_CLOSE_SFT... [-w+user]
   365                                  ASSUME	DS:NOTHING,ES:NOTHING
   366                                  
   367                                  	Assert	ISSFT,<ES,DI>,"Dev_Close_SFT"
   368 00000156 E8(0000)                	invoke	Save_World
   369 00000159 B00E                    	MOV	AL,DEVCLS
   370                                  
   371                                  ;
   372                                  ; Main entry for device open and close.  AL contains the function requested.
   373                                  ; Subtlety:  if Sharing is NOT loaded then we do NOT issue open/close to block
   374                                  ; devices.  This allows networks to function but does NOT hang up with bogus
   375                                  ; change-line code.
   376                                  ;
   377                                  	entry	DO_OPCLS
   378                                  ;
   379                                  ; Is the SFT for the net?  If so, no action necessary.
   380                                  ;
   381 0000015B E8(0000)                	invoke	Test_IFS_Remote 						;AC000;
   382 0000015E 756C                    	JNZ	OPCLS_DONE		; NOP on net SFTs
   383 00000160 30E4                    	XOR	AH,AH			; Unit
   384 00000162 26F745058000            	TEST	word [ES:DI + sf_flags],devid_device
   385 00000168 26C47D07                	LES	DI,[ES:DI + sf_devptr]	; Get DPB or device
   386                                  Got_Dev_Addr equ GOT_DEV_ADDR	; NASM port label
   387 0000016C 7513                    	JNZ	Got_Dev_Addr
   388                                  ;
   389                                  ; We are about to call device open/close on a block driver.  If no sharing
   390                                  ; then just short circuit to done.
   391                                  ;
   392                                  ;;;;;	invoke	CheckShare
   393 0000016E 36803E[0000]01          	CMP	byte [ss:fshare],1		;AN010; /NC or no SHARE
   394                                  opCLs_Done equ OPCLS_DONE	; NASM port label
   395 00000174 7656                    	JBE	opCLs_Done		;AN010; yes
   396 00000176 268A6501                	MOV	AH,[ES:DI + dpb_UNIT]
   397 0000017A 268A0D                  	MOV	CL,[ES:DI + dpb_drive]
   398 0000017D 26C47D13                	LES	DI,[ES:DI + dpb_driver_addr]  ; Get device
   399                                  GOT_DEV_ADDR:				; ES:DI -> device
   400 00000181 26F745040008            	TEST	word [ES:DI + SDEVATT],DEVOPCL
   401 00000187 7443                    	JZ	OPCLS_DONE		; Device can't
   402 00000189 06                      	PUSH	ES
   403 0000018A 1F                      	POP	DS
   404                                   assume ds:nothing
   405 0000018B 89FE                    	MOV	SI,DI			; DS:SI -> device
   406                                  OPCLS_RETRY:
   407 0000018D 1607                    	Context ES
   408                                  DEVCALL equ DevCall	; NASM port label
   409 0000018F BF[0000]                	MOV	DI,OFFSET DEVCALL wrt DOSGROUP
   410 00000192 89FB                    	MOV	BX,DI
   411 00000194 50                      	PUSH	AX
   412 00000195 B00D                    	MOV	AL,DOPCLHL
   413 00000197 AA                      	STOSB				; Length
   414 00000198 58                      	POP	AX
   415 00000199 86E0                    	XCHG	AH,AL
   416 0000019B AA                      	STOSB				; Unit
   417 0000019C 86E0                    	XCHG	AH,AL
   418 0000019E AA                      	STOSB				; Command
   419 0000019F 26C7050000              	MOV	WORD PTR [ES:DI],0	; Status
   420 000001A4 50                      	PUSH	AX			; Save Unit,Command
   421 000001A5 E82B00                  	invoke	DEVIOCALL2
   422 000001A8 268B7F03                	MOV	DI,[ES:BX + REQSTAT]
   423 000001AC F7C70080                	TEST	DI,STERR
   424 000001B0 7419                    	JZ	OPCLS_DONEP		; No error
   425 000001B2 F744040080              	TEST	word [SI + SDEVATT],DEVTYP
   426 000001B7 7404                    	JZ	BLKDEV
   427 000001B9 B486                    	MOV	AH,86H			; Read error in data, Char dev
   428 000001BB EB04                    	JMP	SHORT HRDERR
   429                                  
   430                                  BLKDEV:
   431 000001BD 88C8                    	MOV	AL,CL			; Drive # in AL
   432 000001BF B406                    	MOV	AH,6			; Read error in data, Blk dev
   433                                  HRDERR:
   434 000001C1 E8(0000)                	invoke	CHARHARD
   435 000001C4 3C01                    	CMP	AL,1
   436 000001C6 7503                    	JNZ	OPCLS_DONEP		; IGNORE or FAIL
   437                                  					;  Note that FAIL is essentually IGNORED
   438 000001C8 58                      	POP	AX			; Get back Unit, Command
   439 000001C9 EBC2                    	JMP	OPCLS_RETRY
   440                                  
   441                                  OPCLS_DONEP:
   442 000001CB 58                      	POP	AX			; Clean stack
   443                                  OPCLS_DONE:
   444 000001CC E8(0000)                	invoke	Restore_World
   445 000001CF C3                      	return
   446                                  
   447                                  EndProc DEV_CLOSE_SFT
   448                                  
   449                                  Break	<DEVIOCALL, DEVIOCALL2 - CALL A DEVICE>
   450                                  
   451                                  ; Inputs:
   452                                  ;	DS:SI Points to device SFT
   453                                  ;	ES:BX Points to request data
   454                                  ; Function:
   455                                  ;	Call the device
   456                                  ; Outputs:
   457                                  ;	DS:SI -> Device driver
   458                                  ; DS:SI,AX destroyed, others preserved
   459                                  
   460                                  	procedure   DEVIOCALL,NEAR
   460          ******************       warning: proc DEVIOCALL... [-w+user]
   461                                  ASSUME	DS:NOTHING,ES:NOTHING
   462                                  
   463                                  	Assert	ISSFT,<DS,SI>,"DevIOCall"
   464 000001D0 C57407                  	LDS	SI,[SI + sf_devptr]
   465                                  
   466                                  	entry	DEVIOCALL2
   467                                  
   468 000001D3 E8(0000)                	EnterCrit   critDevice
   469                                  
   470                                  DevTyp equ DEVTYP	; NASM port equate
   471 000001D6 F744040080              	TEST	word [SI + SDEVATT],DevTyp    ;AN000; >32mb   block device ?
   472 000001DB 754F                    	JNZ	chardev2	       ;AN000; >32mb   no
   473 000001DD 26807F0204              	CMP	byte [ES:BX + REQFUNC],DEVRD  ;AN000; >32mb   read ?
   474 000001E2 740E                    	JZ	chkext		       ;AN000; >32mb   yes
   475 000001E4 26807F0208              	CMP	byte [ES:BX + REQFUNC],DEVWRT ;AN000; >32mb   write ?
   476 000001E9 7407                    	JZ	chkext		       ;AN000; >32mb   yes
   477 000001EB 26807F0209              	CMP	byte [ES:BX + REQFUNC],DEVWRTV;AN000; >32mb   write/verify ?
   478 000001F0 753A                    	JNZ	chardev2	       ;AN000; >32mb   no
   479                                  chkext:
   480 000001F2 E89C00                  	CALL	RW_SC		       ;AN000;LB. use secondary cache if there
   481 000001F5 7257                    	JC	dev_exit	       ;AN000;LB. done
   482                                  
   483 000001F7 F744040200              	TEST	word [SI + SDEVATT],EXTDRVR   ;AN000;>32mb   extended driver?
   484 000001FC 741E                    	JZ	chksector	       ;AN000;>32mb   no
   485 000001FE 26800708                	ADD	BYTE PTR [ES:BX],8     ;AN000;>32mb   make length to 30
   486 00000202 36A1[0000]              	MOV	AX,[ss:CALLSSEC]	       ;AN000;>32mb
   487 00000206 36C706[0000]FFFF        	MOV	word [ss:CALLSSEC],-1	       ;AN000;>32mb   old sector  =-1
   488 0000020D 36A3[0000]              	MOV	WORD PTR [ss:CALLNEWSC],AX   ;AN000;>32mb	 new sector  =
   489 00000211 36A1[0000]              	MOV	AX,[ss:HIGH_SECTOR]       ;AN000; >32mb   low sector,high sector
   490 00000215 36A3[0200]              	MOV	WORD PTR [ss:CALLNEWSC+2],AX  ;AN000; >32mb
   491 00000219 EB11                    	JMP	chardev2	       ;AN000; >32mb
   492 0000021B 90                      	nop	; identicalise
   493                                  chksector:			       ;AN000; >32mb
   494 0000021C 36833E[0000]00          	CMP	word [ss:HIGH_SECTOR],0        ;AN000; >32mb   if >32mb
   495 00000222 7408                    	JZ	chardev2	       ;AN000; >32mb   then fake error
   496                                  ERROR_I24_NOT_DOS_DISK equ error_I24_not_DOS_disk	; NASM port equate
   497 00000224 26C747030781            	MOV	word [ES:BX + REQSTAT],STERR+STDON+ERROR_I24_NOT_DOS_DISK  ;AN000; >32mb
   498 0000022A EB22                    	JMP	SHORT dev_exit	       ;AN000; >32mb
   499                                  
   500                                  chardev2:			       ;AN000;
   501                                  ; As above only DS:SI points to device header on entry, and DS:SI is preserved
   502 0000022C 8B4406                  	MOV	AX,[SI + SDEVSTRAT]
   503                                  CALLDEVAD equ CallDevAd	; NASM port label
   504 0000022F 36A3[0000]              	MOV	WORD PTR [ss:CALLDEVAD],AX
   505 00000233 368C1E[0200]            	MOV	WORD PTR [ss:CALLDEVAD+2],DS
   506 00000238 36FF1E[0000]            	CALL	far [ss:CALLDEVAD]
   507 0000023D 8B4408                  	MOV	AX,[SI + SDEVINT]
   508 00000240 36A3[0000]              	MOV	WORD PTR [ss:CALLDEVAD],AX
   509 00000244 36FF1E[0000]            	CALL	far [ss:CALLDEVAD]
   510 00000249 E85B00                  	CALL	VIRREAD 		;AN000;LB. move data from SC to buffer
   511 0000024C 72DE                    	JC	chardev2		;AN000;LB. bad sector or exceeds max sec
   512                                  dev_exit:
   513 0000024E E8(0000)                	LeaveCrit   critDevice
   514 00000251 C3                      	return
   515                                  EndProc DEVIOCALL
   516                                  
   517                                  Break	<SETREAD, SETWRITE -- SET UP HEADER BLOCK>
   518                                  
   519                                  ; Inputs:
   520                                  ;	DS:BX = Transfer Address
   521                                  ;	CX = Record Count
   522                                  ;	DX = Starting Record
   523                                  ;	AH = Media Byte
   524                                  ;	AL = Unit Code
   525                                  ; Function:
   526                                  ;	Set up the device call header at DEVCALL
   527                                  ; Output:
   528                                  ;	ES:BX Points to DEVCALL
   529                                  ; No other registers effected
   530                                  
   531                                  	procedure   SETREAD,NEAR
   531          ******************       warning: proc SETREAD... [-w+user]
   532                                  ASSUME	DS:NOTHING,ES:NOTHING
   533                                  
   534 00000252 57                      	PUSH	DI
   535 00000253 51                      	PUSH	CX
   536 00000254 50                      	PUSH	AX
   537 00000255 B104                    	MOV	CL,DEVRD
   538                                  SETCALLHEAD:
   539 00000257 B016                    	MOV	AL,DRDWRHL
   540 00000259 16                      	PUSH	SS
   541 0000025A 07                      	POP	ES
   542                                   assume es:DOSGROUP
   543 0000025B BF[0000]                	MOV	DI,OFFSET DEVCALL wrt DOSGROUP
   544 0000025E AA                      	STOSB				; length
   545 0000025F 58                      	POP	AX
   546 00000260 AA                      	STOSB				; Unit
   547 00000261 50                      	PUSH	AX
   548 00000262 88C8                    	MOV	AL,CL
   549 00000264 AA                      	STOSB				; Command code
   550 00000265 31C0                    	XOR	AX,AX
   551 00000267 AB                      	STOSW				; Status
   552 00000268 83C708                  	ADD	DI,8			; Skip link fields
   553 0000026B 58                      	POP	AX
   554 0000026C 86E0                    	XCHG	AH,AL
   555 0000026E AA                      	STOSB				; Media byte
   556 0000026F 86C4                    	XCHG	AL,AH
   557 00000271 50                      	PUSH	AX
   558 00000272 89D8                    	MOV	AX,BX
   559 00000274 AB                      	STOSW
   560 00000275 8CD8                    	MOV	AX,DS
   561 00000277 AB                      	STOSW				; Transfer addr
   562 00000278 59                      	POP	CX			; Real AX
   563 00000279 58                      	POP	AX			; Real CX
   564 0000027A AB                      	STOSW				; Count
   565 0000027B 92                      	XCHG	AX,DX			; AX=Real DX, DX=real CX, CX=real AX
   566 0000027C AB                      	STOSW				; Start
   567 0000027D 91                      	XCHG	AX,CX
   568 0000027E 87D1                    	XCHG	DX,CX
   569 00000280 5F                      	POP	DI
   570 00000281 BB[0000]                	MOV	BX,OFFSET DEVCALL wrt DOSGROUP
   571 00000284 C3                      	return
   572                                  
   573                                  	entry	SETWRITE
   574                                  ASSUME	DS:NOTHING,ES:NOTHING
   575                                  
   576                                  ; Inputs:
   577                                  ;	DS:BX = Transfer Address
   578                                  ;	CX = Record Count
   579                                  ;	DX = Starting Record
   580                                  ;	AH = Media Byte
   581                                  ;	AL = Unit Code
   582                                  ; Function:
   583                                  ;	Set up the device call header at DEVCALL
   584                                  ; Output:
   585                                  ;	ES:BX Points to DEVCALL
   586                                  ; No other registers effected
   587                                  
   588 00000285 57                      	PUSH	DI
   589 00000286 51                      	PUSH	CX
   590 00000287 50                      	PUSH	AX
   591 00000288 B108                    	MOV	CL,DEVWRT
   592                                  VERFLG equ VerFlg	; NASM port label
   593 0000028A 36020E[0000]            	ADD	CL,[ss:VERFLG]
   594 0000028F EBC6                    	JMP	SHORT SETCALLHEAD
   595                                  EndProc SETREAD
   596                                  
   597                                  
   598                                  Break	<RW_SC -- Read Write Secondary Cache>
   599                                  
   600                                  ; Inputs:
   601                                  ;	 [SC_CACHE_COUNT]= secondary cache count
   602                                  ;	 [SC_STATUS]= SC validity status
   603                                  ;	 [SEQ_SECTOR]= last sector read
   604                                  ; Function:
   605                                  ;	Read from or write through secondary cache
   606                                  ; Output:
   607                                  ;	ES:BX Points to DEVCALL
   608                                  ;	carry clear, I/O is not done
   609                                  ;		     [SC_FLAG]=1 if continuos sectors will be read
   610                                  ;	carry set, I/O is done
   611                                  
   612                                  
   613                                  	procedure   RW_SC,NEAR		;AN000;
   613          ******************       warning: proc RW_SC... [-w+user]
   614                                  ASSUME	DS:NOTHING,ES:NOTHING		;AN000;
   615                                  
   616                                  %ifndef BUF2
   617                                  	CMP	word [ss:SC_CACHE_COUNT],0	;AN000;LB. secondary cache exists?
   618                                  	JZ	scexit4 		;AN000;LB. no, do nothing
   619                                  	CMP	word [ss:CALLSCNT],1		;AN000;LB. sector count = 1 (buffer I/O)
   620                                  	JNZ	scexit4 		;AN000;LB. no, do nothing
   621                                  	PUSH	CX			    ;AN000;;LB.
   622                                  	PUSH	DX			    ;AN000;;LB. yes
   623                                  	PUSH	DS			    ;AN000;;LB. save registers
   624                                  	PUSH	SI			    ;AN000;;LB.
   625                                  	PUSH	ES			    ;AN000;;LB.
   626                                  	PUSH	DI			    ;AN000;;LB.
   627                                  	MOV	DX,WORD PTR [ss:CALLSSEC]	    ;AN000;;LB.  starting sector
   628                                  	CMP	BYTE PTR [ss:DEVCALL + REQFUNC],DEVRD ;AN000;LB. read ?		      ;AN000;
   629                                  	JZ	doread			;AN000;LB. yes				      ;AN000;
   630                                  	CALL	INVALIDATE_SC		    ;AN000;LB. invalidate SC		      ;AN000;
   631                                  	JMP	strict near scexit2 		    ;AN000;LB. back to normal		      ;AN000;
   632                                  %endif
   633                                  scexit4:				    ;AN000;				       ;AN000;
   634 00000291 F8                      	CLC				    ;AN000;LB. I/O not done yet 	  ;AN000;
   635 00000292 C3                      	return				    ;AN000;LB.				  ;AN000;
   636                                  %ifndef BUF2
   637                                  doread: 				    ;AN000;				       ;AN000;
   638                                  	CALL	SC2BUF			    ;AN000;LB. check if in SC		      ;AN000;
   639                                  	JC	readSC			    ;AN000;LB.					  ;AN000;
   640                                  	MOV	word [ss:DEVCALL + REQSTAT],STDON     ;AN000;LB. fake done and ok 	  ;AN000;
   641                                  	STC				    ;AN000;LB. set carry		  ;AN000;
   642                                  	JMP	saveseq 		    ;AN000;LB. save seq. sector #	  ;AN000;
   643                                  	nop	; identicalise
   644                                  readSC: 				    ;AN000;
   645                                  	MOV	AX,WORD PTR [ss:HIGH_SECTOR]   ;AN000;;LB. subtract sector num from
   646                                  	MOV	CX,WORD PTR [ss:CALLSSEC]	    ;AN000;;LB. saved sequential sector
   647                                  	SUB	CX,WORD PTR [ss:SEQ_SECTOR]    ;AN000;;LB. number
   648                                  	SBB	AX,WORD PTR [ss:SEQ_SECTOR+2]  ;AN000;;LB.
   649                                  	CMP	AX,0			    ;AN000;;LB. greater than 64K
   650                                  	JNZ	saveseq2		    ;AN000;;LB. yes,save seq. sector #
   651                                  chklow: 									;AN000;
   652                                  	CMP	CX,1			    ;AN000;;LB. <= 1
   653                                  	JA	saveseq2		    ;AN000;;LB. no, not sequential
   654                                  	MOV	word [ss:SC_STATUS],-1		    ;AN000;;LB. prsume all SC valid
   655                                  	MOV	AX,[ss:SC_CACHE_COUNT]	    ;AN000;;LB. yes, sequential
   656                                  	MOV	[ss:CALLSCNT],AX		    ;AN000;;LB. read continuous sectors
   657                                  readsr:
   658                                  CALLXAD equ CallXAD	; NASM port label
   659                                  	MOV	AX,WORD PTR [ss:CALLXAD+2]     ;AN000;;LB. save buffer addr
   660                                  	MOV	[ss:TEMP_VAR2],AX		    ;AN000;;LB. in temp vars
   661                                  	MOV	AX,WORD PTR [ss:CALLXAD]	    ;AN000;;LB.
   662                                  	MOV	[ss:TEMP_VAR],AX		    ;AN000;;LB.
   663                                  										;AN000;
   664                                  	MOV	AX,WORD PTR [ss:SC_CACHE_PTR]  ;AN000;LB. use SC cache addr as	      ;AN000;
   665                                  	MOV	WORD PTR [ss:CALLXAD],AX	    ;AN000;LB. transfer addr		      ;AN000;
   666                                  	MOV	AX,WORD PTR [ss:SC_CACHE_PTR+2]  ;AN000;LB.			      ;AN000;
   667                                  	MOV	WORD PTR [ss:CALLXAD+2],AX       ;AN000;LB.			      ;AN000;
   668                                  	MOV	byte [ss:SC_FLAG],1		      ;AN000;LB. flag it for later	      ;AN000;
   669                                  	MOV	AL,[ss:SC_DRIVE]		    ;AN000;;LB. current drive
   670                                  	MOV	[ss:CURSC_DRIVE],AL	    ;AN000;;LB. set current drive
   671                                  	MOV	AX,WORD PTR [ss:CALLSSEC]	    ;AN000;;LB. current sector
   672                                  	MOV	[ss:CURSC_SECTOR],AX	    ;AN000;;LB. set current sector
   673                                  	MOV	AX,WORD PTR [ss:HIGH_SECTOR]   ;AN000;;LB.
   674                                  	MOV	[ss:CURSC_SECTOR+2],AX	    ;AN000;;LB.
   675                                  saveseq2:				    ;AN000;
   676                                  	CLC				    ;AN000;LB. clear carry		      ;AN000;
   677                                  saveseq:				    ;AN000;				       ;AN000;
   678                                  	MOV	AX,[ss:HIGH_SECTOR]	    ;AN000;LB. save current sector #	  ;AN000;
   679                                  	MOV	WORD PTR [ss:SEQ_SECTOR+2],AX  ;AN000;LB. for access mode ref.	  ;AN000;
   680                                  	MOV	AX,[ss:CALLSSEC]		    ;AN000;LB.				  ;AN000;
   681                                  	MOV	WORD PTR [ss:SEQ_SECTOR],AX    ;AN000;LB.				  ;AN000;
   682                                  	JMP	scexit			    ;AN000;LB.				  ;AN000;
   683                                  	nop	; identicalise
   684                                  										;AN000;
   685                                  scexit2:				    ;AN000;LB.				      ;AN000;
   686                                  	CLC				    ;AN000;LB.	       clear carry	      ;AN000;
   687                                  scexit: 				    ;AN000;				       ;AN000;
   688                                  	POP	DI			    ;AN000;;LB.
   689                                  	POP	ES			    ;AN000;;LB. restore registers
   690                                  	POP	SI			    ;AN000;;LB.
   691                                  	POP	DS			    ;AN000;;LB.
   692                                  	POP	DX			    ;AN000;;LB.
   693                                  	POP	CX			    ;AN000;;LB.
   694                                  	return				    ;AN000;;LB.
   695                                  %endif
   696                                  										;AN000;
   697                                  EndProc RW_SC				    ;AN000;
   698                                  
   699                                  Break	<IN_SC -- check if in secondary cache>
   700                                  
   701                                  ; Inputs:  [SC_DRIVE]= requesting drive
   702                                  ;	   [CURSC_DRIVE]= current SC drive
   703                                  ;	   [CURSC_SECTOR] = starting scetor # of SC
   704                                  ;	   [SC_CACHE_COUNT] = SC count
   705                                  ;	   [HIGH_SECTOR]:DX= sector number
   706                                  ; Function:
   707                                  ;	Check if the sector is in secondary cache
   708                                  ; Output:
   709                                  ;	carry clear, in SC
   710                                  ;	   CX= the index in the secondary cache
   711                                  ;	carry set, not in SC
   712                                  ;
   713                                  
   714                                  	procedure   IN_SC,NEAR		    ;AN000;
   714          ******************       warning: proc IN_SC... [-w+user]
   715                                  ASSUME	DS:NOTHING,ES:NOTHING		    ;AN000;
   716                                  
   717                                  %ifndef BUF2
   718                                  	MOV	AL,[ss:SC_DRIVE]		    ;AN000;;LB. current drive
   719                                  	CMP	AL,[ss:CURSC_DRIVE]	    ;AN000;;LB. same as SC drive
   720                                  	JNZ	outrange2		    ;AN000;;LB. no
   721                                  	MOV	AX,WORD PTR [ss:HIGH_SECTOR]   ;AN000;;LB. subtract sector num from
   722                                  	MOV	CX,DX			    ;AN000;;LB. secondary starting sector
   723                                  	SUB	CX,WORD PTR [ss:CURSC_SECTOR]    ;AN000;;LB. number
   724                                  	SBB	AX,WORD PTR [ss:CURSC_SECTOR+2]  ;AN000;;LB.
   725                                  	CMP	AX,0			    ;AN000;;LB. greater than 64K
   726                                  	JNZ	outrange2		    ;AN000;;LB. yes
   727                                  	CMP	CX,[ss:SC_CACHE_COUNT]	    ;AN000;;LB. greater than SC count
   728                                  	JAE	outrange2		    ;AN000;;LB. yes
   729                                  	CLC				    ;AN000;;LB. clear carry
   730                                  	JMP	short inexit		    ;AN000;;LB. in SC
   731                                  outrange2:				    ;AN000;;LB. set carry
   732                                  %endif
   733 00000293 F9                      	STC				    ;AN000;;LB.
   734                                  inexit: 				    ;AN000;;LB.
   735 00000294 C3                      	return				    ;AN000;;LB.
   736                                  
   737                                  EndProc IN_SC				    ;AN000;
   738                                  
   739                                  Break	<INVALIDATE_SC - invalide secondary cache>
   740                                  
   741                                  ; Inputs:  [SC_DRIVE]= requesting drive
   742                                  ;	   [CURSC_DRIVE]= current SC drive
   743                                  ;	   [CURSC_SECTOR] = starting scetor # of SC
   744                                  ;	   [SC_CACHE_COUNT] = SC count
   745                                  ;	   [SC_STAUS] = SC status word
   746                                  ;	   [HIGH_SECTOR]:DX= sceotor number
   747                                  ;
   748                                  ; Function:
   749                                  ;	invalidate secondary cache if in there
   750                                  ; Output:
   751                                  ;	[SC_STATUS] is updated
   752                                  ;
   753                                  
   754                                  	procedure   INVALIDATE_SC,NEAR	    ;AN000;
   754          ******************       warning: proc INVALIDATE_SC... [-w+user]
   755                                  ASSUME	DS:NOTHING,ES:NOTHING		    ;AN000;
   756                                  
   757 00000295 E8FBFF                  	CALL	IN_SC			    ;AN000;;LB. in secondary cache
   758 00000298 720C                    	JC	outrange		    ;AN000;;LB. no
   759 0000029A B80100                  	MOV	AX,1			    ;AN000;;LB. invalidate the sector
   760 0000029D D3E0                    	SHL	AX,CL			    ;AN000;;LB. in the secondary cache
   761 0000029F F7D0                    	NOT	AX			    ;AN000;;LB.
   762 000002A1 362106[0000]            	AND	[ss:SC_STATUS],AX		    ;AN000;;LB. save the status
   763                                  outrange:				    ;AN000;;LB.
   764 000002A6 C3                      	return				    ;AN000;;LB.
   765                                  
   766                                  EndProc INVALIDATE_SC			    ;AN000;
   767                                  
   768                                  
   769                                  Break	<VIRREAD- virtually read data into buffer>
   770                                  
   771                                  ; Inputs:  SC_FLAG = 0 , no sectors were read into SC
   772                                  ;		     1, continous sectors were read into SC
   773                                  ; Function:
   774                                  ;	   Move data from SC to buffer
   775                                  ; Output:
   776                                  ;	 carry clear, data is moved to buffer
   777                                  ;	 carry set, bad sector or exceeds maximum sector
   778                                  ;	   SC_FLAG =0
   779                                  ;	   CALLSCNT=1
   780                                  ;	   SC_STATUS= -1 if succeeded
   781                                  ;		       0 if failed
   782                                  
   783                                  	procedure   VIRREAD,NEAR	    ;AN000;
   783          ******************       warning: proc VIRREAD... [-w+user]
   784                                  ASSUME	DS:NOTHING,ES:NOTHING		    ;AN000;
   785                                  
   786                                  %ifndef BUF2
   787                                  	CMP	byte [ss:SC_FLAG],0		    ;AN000;;LB.  from SC fill
   788                                  	JZ	sc2end			    ;AN000;;LB.  no
   789                                  	MOV	AX,[ss:TEMP_VAR2]		    ;AN000;;LB. restore buffer addr
   790                                  	MOV	WORD PTR [ss:CALLXAD+2],AX     ;AN000;;LB.
   791                                  	MOV	AX,[ss:TEMP_VAR]		    ;AN000;;LB.
   792                                  	MOV	WORD PTR [ss:CALLXAD],AX	    ;AN000;;LB.
   793                                  	MOV	byte [ss:SC_FLAG],0		    ;AN000;;LB.  reset sc_flag
   794                                  	MOV	word [ss:CALLSCNT],1		    ;AN000;;LB.  one sector transferred
   795                                  
   796                                  	TEST	word [ss:DEVCALL + REQSTAT],STERR     ;AN000;;LB.  error?
   797                                  	JNZ	scerror 		    ;AN000;;LB. yes
   798                                  	PUSH	DS			    ;AN000;;LB.
   799                                  	PUSH	SI			    ;AN000;;LB.
   800                                  	PUSH	ES			    ;AN000;;LB.
   801                                  	PUSH	DI			    ;AN000;;LB.
   802                                  	PUSH	DX			    ;AN000;;LB.
   803                                  	PUSH	CX			    ;AN000;;LB.
   804                                  	XOR	CX,CX			    ;AN000;;LB. we want first sector in SC
   805                                  	CALL	SC2BUF2 		    ;AN000;;LB. move data from SC to buffer
   806                                  	POP	CX			    ;AN000;;LB.
   807                                  	POP	DX			    ;AN000;;LB.
   808                                  	POP	DI			    ;AN000;;LB.
   809                                  	POP	ES			    ;AN000;;LB.
   810                                  	POP	SI			    ;AN000;;LB.
   811                                  	POP	DS			    ;AN000;;LB.
   812                                  	JMP	SHORT sc2end		    ;AN000;;LB. return
   813                                  
   814                                  scerror:				    ;AN000;
   815                                  	MOV	word [ss:CALLSCNT],1		    ;AN000;;LB. reset sector count to 1
   816                                  	MOV	word [ss:SC_STATUS],0		    ;AN000;;LB. invalidate all SC sectors
   817                                  	MOV	byte [ss:CURSC_DRIVE],-1	    ;AN000;;LB. invalidate drive
   818                                  	STC				    ;AN000;;LB. carry set
   819                                  	return				    ;AN000;;LB.
   820                                  
   821                                  %endif
   822                                  sc2end: 				    ;AN000;
   823 000002A7 F8                      	CLC				    ;AN000;;LB. carry clear
   824 000002A8 C3                      	return				    ;AN000;;LB.
   825                                  
   826                                  EndProc VIRREAD 			    ;AN000;
   827                                  
   828                                  Break	<SC2BUF- move data from SC to buffer>
   829                                  
   830                                  ; Inputs:  [SC_STATUS] = SC validity status
   831                                  ;	   [SC_SECTOR_SIZE] = request sector size
   832                                  ;	   [SC_CACHE_PTR] = pointer to SC
   833                                  ; Function:
   834                                  ;	   Move data from SC to buffer
   835                                  ; Output:
   836                                  ;	   carry clear, in SC  and data is moved
   837                                  ;	   carry set, not in SC and data is not moved
   838                                  
   839                                  	procedure   SC2BUF,NEAR 	    ;AN000;
   839          ******************       warning: proc SC2BUF... [-w+user]
   840                                  ASSUME	DS:NOTHING,ES:NOTHING		    ;AN000;
   841                                  
   842 000002A9 E8E7FF                  	CALL	IN_SC			    ;AN000;;LB. in secondary cache
   843                                  %ifndef BUF2
   844                                  	JC	noSC			    ;AN000;;LB. no
   845                                  	MOV	AX,1			    ;AN000;;LB. check if valid sector
   846                                  	SHL	AX,CL			    ;AN000;;LB. in the secondary cache
   847                                  	TEST	[ss:SC_STATUS],AX		    ;AN000;;LB.
   848                                  	JZ	noSC			    ;AN000;;LB. invalid
   849                                  entry SC2BUF2				    ;AN000;
   850                                  	MOV	AX,CX			    ;AN000;;LB. times index with
   851                                  	MUL	word [ss:SC_SECTOR_SIZE]	    ;AN000;;LB. sector size
   852                                  	ADD	AX,WORD PTR [ss:SC_CACHE_PTR]  ;AN000;;LB. add SC starting addr
   853                                  	ADC	DX,WORD PTR [ss:SC_CACHE_PTR+2];AN000;;LB.
   854                                  	MOV	DS,DX			    ;AN000;    ;LB. DS:SI-> SC sector addr
   855                                  	MOV	SI,AX			    ;AN000;    ;LB.
   856                                  	MOV	ES,WORD PTR [ss:CALLXAD+2]     ;AN000;    ;LB. ES:DI-> buffer addr
   857                                  	MOV	DI,WORD PTR [ss:CALLXAD]	    ;AN000;    ;LB.
   858                                  	MOV	CX,[ss:SC_SECTOR_SIZE]	    ;AN000;    ;LB. count= sector size
   859                                  	SHR	CX,1			    ;AN000;    ;LB. may use DWORD move for 386
   860                                  entry MOVWORDS				    ;AN000;
   861                                  	CMP	byte [ss:DDMOVE],0		    ;AN000;    ;LB. 386 ?
   862                                  	JZ	nodd			    ;AN000;    ;LB. no
   863                                  	SHR	CX,1			    ;AN000;    ;LB. words/2
   864                                  	DB	66H			    ;AN000;    ;LB. use double word move
   865                                  nodd:
   866                                  	REP	MOVSW			    ;AN000;    ;LB. move to buffer
   867                                  	CLC				    ;AN000;    ;LB. clear carry
   868                                  	return				    ;AN000;    ;LB. exit
   869                                  %endif
   870                                  noSC:					    ;AN000;
   871 000002AC F9                      	STC				    ;AN000;    ;LB. set carry
   872                                  sexit:					    ;AN000;
   873 000002AD C3                      	return				    ;AN000;    ;LB.
   874                                  
   875                                  EndProc SC2BUF
   876                                      END
   877                                  
   878                                  
