📄 dkstmt.asm
字号:
TITLE DKSTMT - Disk I/O Interfaces
page 56,132
;***
;DKSTMT - Disk I/O Interfaces
;
; Copyright <C> 1986, Microsoft Corporation
;
;Purpose:
; This module contains disk I/O interfaces for BASIC statements.
;
; This module came from iodisk.asm, which had been split into three
; modules, -- diskio.asm, dkopen.asm and fileio.asm. Diskio.asm
; contains all drivers for disk I/O except disk open and close.
; Disk open is in dkopen.asm. This module contains interfaces for
; file I/O statements.
;
;BASIC Syntax mapping to included runtime entry points:
;
;- FILES Statement:
;
; FILES Statement:
;
; FILES [filespec]
; |
; B$FILS
;
;- KILL Statement:
;
; KILL filespec
; |
; B$KILL
;
;- LOCK Statement:
;
; LOCK [#]filenum [{, record} | [start] TO end]
; |
; B$LOCK
;
;- NAME Statement:
;
; NAME oldname AS newname
; |
; B$NAME
;
;- RESET Statement:
;
; RESET
; |
; B$REST
;
;- UNLOCK Statement:
;
; UNLOCK [#]filenum [{, record} | [start] TO end]
; |
; B$LOCK
;
;******************************************************************************
INCLUDE switch.inc
INCLUDE rmacros.inc ;Runtime Macro Defintions
;Code segmetns
useSeg DK_TEXT
useSeg ER_TEXT
useSeg NH_TEXT
useSeg RT_TEXT
;Data segments
useSeg CONST
useSeg _DATA
useSeg _BSS
INCLUDE seg.inc
INCLUDE ascii.inc
INCLUDE baslibma.inc
INCLUDE devdef.inc
INCLUDE files.inc
INCLUDE idmac.inc
INCLUDE messages.inc
INCLUDE rtps.inc
INCLUDE string.inc
SUBTTL local constant definitions
page
sBegin CONST
externB b$EightSpaces ; buffer of 8 spaces
staticB DirStr,"<DIR> "
sEnd CONST
sBegin _DATA
sEnd _DATA
sBegin _BSS
externB b$PATHNAM ; defined in GWINI.ASM
externB b$Buf2 ; defined in GWINI.ASM
b$PATHNAM2 EQU b$Buf2
externW b$PN_NAME
sEnd _BSS
SUBTTL code externals
page
sBegin DK_TEXT
externNP B$GET_PATHNAME
externNP B$GET_CUR_DIR
externFP B$PSI4
externNP B$PUTS
externNP B$OUTCNT
externNP B$$WCHT
externNP B$$TCR
externNP B$TTY_GPOS
externNP B$TTY_GWID
externNP B$CLOSF
externNP B$CHKFOPEN
externNP B$DOS3CHECK ;check for >= DOS 3.00
externNP B$MUL32
sEnd DK_TEXT
sBegin NH_TEXT
externNP B$STDALCTMP
externNP B$LHFDBLOC
sEnd NH_TEXT
sBegin ER_TEXT
externNP B$PUTNUM ; output message
externNP B$ERR_FC
externNP B$ERR_BFN
externNP B$ERR_BRN
externNP B$ERR_FAE
externNP B$ERR_FNF
externNP B$ERR_IFN
externNP B$ERR_ACD
externNP B$ERR_FWP
externNP B$ERR_AFE
externNP B$ERR_PNF
externNP B$ERR_RAD
sEnd ER_TEXT
sBegin RT_TEXT
sEnd RT_TEXT
PAGE
assumes CS,DK_TEXT
sBegin DK_TEXT
;***
;B$KILL - KILL filename
;
;Purpose:
;
;Entry:
; fname = filename sdesc
;
;Exit:
;
;Uses:
; Per convention
;
;Exceptions:
; B$ERR_FNF -- for file not found
; B$ERR_ACD -- for access denied
; B$ERR_FAO -- for file already open
;
;******************************************************************************
cProc B$KILL,<FAR,PUBLIC>,<SI,DI,ES>
parmSD fname
cbegin
PUSH DS ; set ES=DS for string operations
POP ES
MOV BX,fname ; get *sd of filename
MOV DI,OFFSET DGROUP:b$PATHNAM ; Where to put the pathname
CALL B$GET_PATHNAME ; generate pathname, checking for errors
; sets ES = DS
CALL B$STDALCTMP ;delete temporaries
CALL SearchNoDir ; find first file, or give "file not found"
KILL_NEXT:
; DI --> pointer to processed filename
PUSH DI ; save pathname buffer address
MOV DI,b$PN_NAME ; DI = address past last "\" in pathname
; (filename.ext field of pathname)
mov si,offset dgroup:b$PATHNAM2+30 ; Where dos put the filename
; store name into the name field of pathname
dkk22:
lodsb ;get a byte from the filename
stosb ;store it into the pathname
or al,al ;end ?
jnz dkk22 ;no
pop di ;--> pathname
CALL B$CHKFOPEN ; Check for conflict with open files
; (doesn't return if error)
; delete the link
mov dx,di ; DX = address of pathname to delete
CALLOS unlink,,,,dx
JB KILL_ERR ; give proper error message
CALLOS FINDN ;find next
JNB KILL_NEXT ; found next, continue
cEnd
KILL_ERR:
CMP AX,ERRACD ;test if access error
JNE ERFNF ; if not, then KILL defaults to file not
; found error
JMP B$ERR_ACD ;treat as access error
ERFNF:
JMP B$ERR_FNF ; File not found
;***
; B$NAME - Name statement
;
;Purpose:
; Rename a file
;
;Entry:
; oldname = Name of existing file
; newname = name to change to
;
;Exit:
;
;Uses:
; Per convention
;
;Exceptions:
; B$ERR_FAE if newname already exists.
;
;******************************************************************************
cProc B$NAME,<FAR,PUBLIC>,<ES,SI,DI>
parmSD oldname
parmSD newname
cBegin
PUSH DS ; set ES=DS
POP ES
GetpSD BX,newname
MOV DI,OFFSET DGROUP:b$PATHNAM2
CALL NAME_COMMON ; do common processing for second name
GetpSD BX,oldname ; source pathname sdesc
MOV DI,OFFSET DGROUP:b$PATHNAM
CALL NAME_COMMON ; do common processing for first name
MOV DX,OFFSET DGROUP:b$PATHNAM ;source
MOV DI,OFFSET DGROUP:b$PATHNAM2 ;destination
CALLOS RENAME
JC NAME_ERR
cEnd
NAME_ERR:
CMP AL,ERRFNF ; file not found?
JE ERFNF ; brif so
CMP AL,ERRPNF ; path not found?
JE ERPNF ; brif so
CMP AL,ERRACD ; access denied?
JE ERFAE ; brif so -- File already exists
CMP AL,ERRNSD ; not same device?
JE ERRAD ; brif so -- Rename across disks
; default to Illegal function call error
; for NAME if not one of the above.
ERFC:
JMP B$ERR_FC ; Illegal function call
ERFAE:
JMP B$ERR_FAE ; File already exists
ERPNF:
JMP B$ERR_PNF ; Path not found
ERRAD:
JMP B$ERR_RAD ; Rename across disks
ERBFN:
JMP B$ERR_BFN ; Bad file name
ERCFNF2:
JMP SHORT ERFNF ; give "file not found" error
;***
; NAME_COMMON - common processing. Added as part of [14].
;
;Purpose:
; Common processing for each filename of B$NAME.
;
; Algorithm:
; call B$GET_PATHNAME
; if (wildcards in filename) then error
; deallocate the string temp
; if (file already open) then error
;
;Entry:
; DI = *space for pathname
; BX = pointer to user-specified filename string descriptor
;
;Exit:
; DI = *processed pathname
; CX = length of pathname (including null byte)
;
;Uses:
; per convention
;
;Preserves:
;
;Exceptions:
; B$ERR_BFN -- for bad file name
; B$ERR_FAO -- for file already open
;
;******************************************************************************
NAME_COMMON:
CALL B$GET_PATHNAME ; Scan file name
; sets ES = DS
cCall B$STDALCTMP ; deallocate string temp
TEST AL,FN_WILD ; wildcards in filename?
JNZ ERBFN ; brif so -- error
; [DI] = processed pathname
; [CX] = number of bytes in pathname
JMP B$CHKFOPEN ; check for file already open and return
; (doesn't return if error)
;***
; Search/SearchNoDir - search for file
;
;Purpose:
; Search for files
;Entry:
; b$PATHNAM has pathname to search for
;Exit:
; Conditions after DOS search function:
; b$PATHNAM2 has directory entry for first matching file
; DX -> b$PATHNAM
; ZF ==> file found, NZ ==> error
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -