turbo-pascal-assembly

0364 Reset/Rewrite Function

Subroutine for Turbo Pascal’s:

File must already be associated with a filename using the Assign(File, Filename) prior.

SYS0364: MOV DX,fmInput
SYS0367: JMP 0371

Entry point for Reset(File).

SYS0369: MOV DX,fmOutput
SYS036C: JMP 0371

Entry point for Rewrite(File).

SYS036E: MOV DX,fmInOut

Entry point for typed and untyped files.

SYS0371: PUSH BP
SYS0372: MOV BP,SP

Upon entering this subroutine from any of the entrypoints: fmInput, fmInput, fmInput, and saving BP, the stack looks like this:

Index Contents
BP Old BP value
BP+02 Return Address (OFFSET)
SP+04 Return Address (SEGMENT)
BP+06 Pointer to File/Text Record Data (OFFSET)
BP+08 Pointer to File/Text Record Data (SEGMENT)
SYS0374: LES DI,[BP+06]

Loads the pointer to the File into ES:DI.

SYS0377: ES:
SYS0378: MOV AX,[DI:Mode]

Loads Mode int AX.

SYS037B: CMP AX,fmInput
SYS037E: JZ 0392

Checks if File was opened using Reset().

SYS0380: CMP AX,fmOutput
SYS0383: JZ 0392

Checks if File was opened using Rewrite().

SYS0385: CMP AX,fmClosed
SYS0388: JZ 039A

Check if File was closed.

SYS038A: MOV WORD PTR [InOutRes],0066
SYS0390: JMP 03B6

Exit with an error 66h/102: File not assigned.

SYS0392: PUSH DX

Save Mode in DX on to the stack.

SYS0393: PUSH ES
SYS0394: PUSH DI
SYS0395: PUSH CS
SYS0396: CALL 03BE

Call SYS:03BE Reset()/Rewrite() and pushing the pointer to File onto the stack.

SYS0399: POP DX

Recover Mode from the stack to in DX.

SYS039A: XOR AX,AX

Clears AX.

SYS039C: ES:
SYS039D: MOV [DI:Mode],DX

Set Mode in File.

SYS03A0: ES:
SYS03A1: MOV [DI+08],AX

Resets buffer to the beginning.

SYS03A4: ES:
SYS03A5: MOV [DI+0A],AX

Resets the number of characters in the buffer to 0 (Empty).

SYS03A8: MOV BX,0010
SYS03AB: CALL 03FA

Open File with a call to its BX = 0010 OpenFunc() using SYS:03FA I/O Function Dispatcher.

SYS03AE: JZ 03B6

Return on succes.

SYS03B0: ES:
SYS03B1: MOV WORD PTR [DI:Mode],fmClosed

Mark the file as fmClosed on error.

SYS03B6: POP BP
SYS03B7: RETF 0004

Return and pop-off parameters from the stack.

See also: Text File Type, File Modes, SYS:03BA Reset/Rewrite Function (II), SYS:03FA I/O Function Dispatcher, or go back