dialer/file.jrt

94 lines
1.7 KiB
Plaintext
Executable File

:ASM overwrite
MOV AH 0x3c #
XOR CX CX ( non-system, non-hidden )
POP DX ( filename ptr )
INT 0x21 #
PUSH AX
NEXT
:ASM open
MOV AH 0x3d #
MOV AL 2 # ( read/write access, allow child inheritance )
POP DX ( filename ptr )
INT 0x21 #
PUSH AX
NEXT
:ASM openself ( -- fp )
MOV AX 0x2c @+ ( fetch environment segment )
OR AX AX
JZ 1 @> ( we're in a target .com and there is no "self" - abort with 0 )
MOV ES AX
XOR DI DI
XOR AX AX
0 :> ( search for two zeroes in a row )
SCASB
JNZ 0 <@
SCASB
JNZ 0 <@
SCASW ( consume the 0x0001. DI is now a pointer to the filename )
MOV DX DI
PUSH DS
MOV AX ES
MOV DS AX
MOV AH 0x3d #
MOV AL 2 # ( read/write access, allow child inheritance )
INT 0x21 #
POP DS
1 <:
PUSH AX
NEXT
:ASM close
MOV AH 0x3e #
POP BX
INT 0x21 #
NEXT
:ASM seekto ( loc fp -- )
XOR AX AX
XOR CX CX
MOV AH 0x42 #
POP BX
POP DX
INT 0x21 #
NEXT
0 VAR, fcount
:ASM farfread
POP DS ( seg )
0 :>
MOV AH 0x3f #
POP BX ( fp )
POP DX ( buffer )
POP CX ( length )
INT 0x21 #
MOV BX CS
MOV DS BX
MOV t& fcount @+ AX ( save number of bytes read )
NEXT
DEF fread 0 L<@ w>t
:ASM farfwrite
POP DS ( seg )
0 :>
MOV AH 0x40 #
POP BX ( fp )
POP DX ( buffer )
POP CX ( length )
INT 0x21 #
MOV BX CS
MOV DS BX
MOV t& fcount @+ AX ( save number of bytes written )
NEXT
DEF fwrite 0 L<@ w>t
-1 CONST EOF
0 VAR, fbuffer
:t fgetc ( fp -- c )
1 fbuffer <rot fread fbuffer ub@
fcount @ not BZ_ [ patchpt ] drop EOF [ patch!t ] ;
:t fputc ( c fp -- ) swap fbuffer b! 1 fbuffer <rot fwrite ;