: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 fread MOV AH 0x3f # POP BX ( fp ) POP DX ( buffer ) POP CX ( length ) INT 0x21 # MOV t& fcount @+ AX ( save number of bytes read ) NEXT :ASM fwrite MOV AH 0x40 # POP BX ( fp ) POP DX ( buffer ) POP CX ( length ) INT 0x21 # MOV t& fcount @+ AX ( save number of bytes written ) NEXT -1 CONST EOF 0 VAR, fbuffer :t fgetc ( fp -- c ) 1 fbuffer