📄 rxdossft.asm
字号:
_SFTReadFile:
Entry 2
darg _bufPtr
def _readCount, cx
ddef _sftpointer, es, di
defbytes _diskAccess, sizeDISKACCESS
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; is file redirected to a device ?
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
test word ptr es:[ sftDevInfo ][ di ], sftIsDevice
jz _SFTReadFile_14 ; if file -->
xor cx, cx ; actually read
test word ptr es:[ sftDevInfo ][ di ], sftEof ; is it end of file ?
jnz _SFTReadFile_12 ; if end of file -->
push word ptr es:[ sftDCB. _segment ][ di ]
push word ptr es:[ sftDCB. _pointer ][ di ]
mov cx, word ptr [ _readCount ][ bp ]
getdarg es, di, _bufPtr
call devCharReadLine ; read till cr or eof.
jnz _SFTReadFile_10 ; if not end of file -->
getdarg es, di, _sftpointer
or word ptr es:[ sftDevInfo ][ di ], sftEof ; set end of file flag
_SFTReadFile_10:
getdarg es, di, _bufPtr
cmp cx, word ptr [ _readCount ][ bp ] ; at maximum buffer ?
jge _SFTReadFile_12 ; yes -->
add di, cx ; add cr/ lf
mov al, ControlM
stosb ; store cr
inc cx ; adjust return count
cmp cx, word ptr [ _readCount ][ bp ] ; at maximum buffer ?
jge _SFTReadFile_12 ; yes -->
mov al, ControlJ
stosb ; store cr
inc cx
_SFTReadFile_12:
or cx, cx
jmp _SFTReadFile_36
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; is file read from stdin ?
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SFTReadFile_14:
test word ptr es:[ sftDevInfo ][ di ], sftIsDevice
jz _SFTReadFile_20 ; if file -->
test word ptr es:[ sftDevInfo ][ di ], sftIsstdin
jz _SFTReadFile_20 ; if file -->
push word ptr es:[ _bufPtr. _segment ][ di ]
push word ptr es:[ _bufPtr. _pointer ][ di ] ; buffer address
call _SFTReadLine ; read line
jmp _SFTReadFile_36
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; initialize disk access block
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SFTReadFile_20:
or cx, cx ; reading any ?
jz _SFTReadFile_34 ; if length is zero -->
lea bx, _diskAccess [ bp ] ; build access control block
call buildAccessRef ; ...from sft
mov ax, word ptr es:[ sftDevInfo ][ di ] ; get drive number
call insureSFTSameVolume ; insure same volume
jc _SFTReadFile_36 ; read aborted -->
xor cx, cx ; bytes read (none yet )
lea bx, _diskAccess [ bp ] ; build access control block
getdarg es, di, _sftpointer ; restore sft pointer
mov ax, word ptr es:[ sftFileSize. _low ][ di ]
mov dx, word ptr es:[ sftFileSize. _high ][ di ]
sub ax, word ptr es:[ sftFilePosition. _low ][ di ]
sbb dx, word ptr es:[ sftFilePosition. _high ][ di ]
jc _SFTReadFile_34 ; if past end of file -->
mov cx, word ptr _readCount [ bp ] ; count: cx
or dx, dx ; more than 65k of file left ?
jnz _SFTReadFile_26 ; ok to continue reading -->
cmp ax, cx ; enough space to absorb read ?
jnc _SFTReadFile_26 ; ok to continue reading -->
mov cx, ax ; max read just to end of file
or cx, cx ; if zero, no need to read
jz _SFTReadFile_34
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; if stdin, read line even if from a file
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SFTReadFile_26:
mov ax, word ptr es:[ sftFileSize. _low ][ di ]
mov dx, word ptr es:[ sftFileSize. _high ][ di ]
mov word ptr ss:[ diskAcFileSize. _low ][ bx ], ax
mov word ptr ss:[ diskAcFileSize. _high ][ bx ], dx
mov ax, word ptr es:[ sftFilePosition. _low ][ di ]
mov dx, word ptr es:[ sftFilePosition. _high ][ di ]
mov word ptr ss:[ diskAcPosition. _low ][ bx ], ax
mov word ptr ss:[ diskAcPosition. _high ][ bx ], dx
getdarg es, di, _bufPtr ; buffer es: di
call readLogicalBuffer ; Access buffer: ds: bx
getdarg es, di, _sftPointer ; restore pointer to sft buffer
add word ptr es:[ sftFilePosition. _low ][ di ], cx
adc word ptr es:[ sftFilePosition. _high ][ di ], 0000
mov dx, word ptr ss:[ diskAcCurCluster ][ bx ]
mov word ptr es:[ sftCurCluster ][ di ], dx
call _computeRelativeCluster
_SFTReadFile_34:
clc
_SFTReadFile_36:
mov ax, cx ; return count
Return
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Read Line From SFT ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Input: ;
; cx max bytes to read ;
; es:di sft pointer ;
; stack buffer address ;
; ;
; Output: ;
; cx bytes actually read ;
; zr means end of file or wrong address ;
;...............................................................;
_SFTReadLine:
Entry 2
darg _bufPtr
def _readMax, cx
def _readActual, 0000
ddef _sftpointer, es, di
defbytes _diskAccess, sizeDISKACCESS
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; is file redirected to a device
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
test word ptr es:[ sftDevInfo ][ di ], sftIsDevice
jz _SFTReadLine_14 ; if file -->
test word ptr es:[ sftDevInfo ][ di ], sftEof
jz _SFTReadLine_36 ; if at end of file -->
push word ptr es:[ sftDCB. _segment ][ di ]
push word ptr es:[ sftDCB. _pointer ][ di ]
mov cx, word ptr [ _readMax ][ bp ]
getdarg es, di, _bufPtr
call devCharReadLine ; read till cr or eof.
jnz _SFTReadLine_10 ; if not end of file -->
getdarg es, di, _sftpointer
or word ptr es:[ sftDevInfo ][ di ], sftEof ; set end of file flag
_SFTReadLine_10:
getdarg es, di, _bufPtr
cmp cx, word ptr [ _readMax ][ bp ] ; at maximum buffer ?
jge _SFTReadLine_12 ; yes -->
add di, cx ; add cr/ lf
mov al, ControlM
stosb ; store cr
inc cx ; adjust return count
_SFTReadLine_12:
jmp _SFTReadLine_36
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; initialize disk access block
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SFTReadLine_14:
or cx, cx ; reading any ?
jz _SFTReadLine_34 ; if length is zero -->
lea bx, _diskAccess [ bp ] ; build access control block
call buildAccessRef ; ...from sft
mov ax, word ptr es:[ sftFileSize. _low ][ di ]
mov dx, word ptr es:[ sftFileSize. _high ][ di ]
mov word ptr ss:[ diskAcFileSize. _low ][ bx ], ax
mov word ptr ss:[ diskAcFileSize. _high ][ bx ], dx
mov ax, word ptr es:[ sftFilePosition. _low ][ di ]
mov dx, word ptr es:[ sftFilePosition. _high ][ di ]
mov word ptr ss:[ diskAcPosition. _low ][ bx ], ax
mov word ptr ss:[ diskAcPosition. _high ][ bx ], dx
getdarg es, di, _bufPtr ; buffer es: di
mov cx, word ptr [ _readMax ][ bp ] ; max bytes to read
call readLine ; read line
getdarg es, di, _sftpointer
mov word ptr es:[ sftFilePosition. _low ][ di ], ax
mov word ptr es:[ sftFilePosition. _high ][ di ], dx
mov dx, word ptr ss:[ diskAcCurCluster ][ bx ]
mov word ptr es:[ sftCurCluster ][ di ], dx
call _computeRelativeCluster
_SFTReadLine_34:
clc
_SFTReadLine_36:
mov ax, cx ; return count
Return
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Write To SFT ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Input: ;
; es:di sft pointer ;
; cx bytes to write ;
; stack buffer address ;
; ;
; Output: ;
; cx bytes actually written ;
; cy end of available disk space reached ;
;...............................................................;
_SFTWriteFile:
Entry 2
darg _bufPtr
def _actuallyWritten, 0000
def _writeCount, cx
ddef _sftpointer, es, di
defbytes _diskAccess, sizeDISKACCESS
defbytes _expandedBuffer, 128
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; is file redirected to stdout device
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
test word ptr es:[ sftDevInfo ][ di ], sftIsDevice
ifz _SFTWriteFile_36 ; if file -->
test word ptr es:[ sftDevInfo ][ di ], sftIsstdout
ifz _SFTWriteFile_36 ; no -->
or cx, cx ; none to write ?
ifz _SFTWriteFile_36 ; special case -->
getdarg es, di, _bufPtr ; get buffer address
lea si, offset [ _expandedBuffer ][ bp ]
lea dx, offset [ _expandedBuffer + 128 - 7][ bp ]
_SFTWriteFile_06:
mov al, byte ptr es:[ di ] ; get character
mov byte ptr ss:[ si ], al ; store character
inc si ; advance pointer
cmp al, ControlI ; tab character ?
jnz _SFTWriteFile_08 ; no, go see what it is -->
mov al, 8
mov ah, byte ptr [ _RxDOS_TabPosition ] ; current tab position
and ah, 7 ; tab offset
sub al, ah ; bytes to offset
add byte ptr [ _RxDOS_TabPosition ], al ; advance position
cbw ; 16 bit offset
dec si ; account
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -