Press enter to see results or esc to cancel.

Processing System Procedures

All Turbo Pascal system procedures are processed by this function. Each system procedure has a processing function with optional parameter which is used when two or more procedures share the same processing function. Processing function returns the offset to intermediate code subroutine.

Type TSystemProcedure = Record
                          Proc: Function: Word;
                          ProcParameter: Word;
                        end;

Const stProcedures: Array [$00..$2B] of TSystemProcedure = (
        (Proc: Proc_New;                  ProcParameter: 0),
        (Proc: Proc_Write_Writeln;        ProcParameter: SysProc_WriteEnd),
        (Proc: Proc_Write_Writeln;        ProcParameter: SysProc_WriteLine),
        (Proc: Proc_Read_Readln;          ProcParameter: SysProc_ReadEnd),
        (Proc: Proc_Read_Readln;          ProcParameter: SysProc_ReadLine),
        (Proc: Proc_Dispose;              ProcParameter: 0),
        (Proc: Proc_Mark_Release;         ProcParameter: SysProc_MarkPtr),
        (Proc: Proc_Mark_Release;         ProcParameter: SysProc_ReleasePtr),
        (Proc: Proc_Insert;               ProcParameter: 0),
        (Proc: Proc_Delete;               ProcParameter: 0),
        (Proc: Proc_Assign;               ProcParameter: 0),
        (Proc: Proc_Reset_Rewrite;        ProcParameter: SysProc_ResetFile),
        (Proc: Proc_Reset_Rewrite;        ProcParameter: SysProc_RewriteFile),
        (Proc: Proc_Close;                ProcParameter: 0),
        (Proc: Proc_Seek;                 ProcParameter: 0),
        (Proc: Proc_Erase;                ProcParameter: 0),
        (Proc: Proc_Rename;               ProcParameter: 0),
        (Proc: Proc_Halt_RunError;        ProcParameter: SysProc_HaltTurbo),
        (Proc: Proc_BREAK_CONTINUE_Exit;  ProcParameter: Ofs (LastJumpToProgramBlockExit)),
        (Proc: Proc_GetMem;               ProcParameter: 0),
        (Proc: Proc_FreeMem;              ProcParameter: 0),
        (Proc: Proc_Truncate;             ProcParameter: 0),
        (Proc: Proc_FillChar;             ProcParameter: 0),
        (Proc: Proc_Move;                 ProcParameter: 0),
        (Proc: Proc_Randomize;            ProcParameter: 0),
        (Proc: Proc_Str;                  ProcParameter: 0),
        (Proc: Proc_Val;                  ProcParameter: 0),
        (Proc: Proc_GetDir;               ProcParameter: 0),
        (Proc: Proc_ChDir_MkDir_RmDir;    ProcParameter: SysProc_DirSet),
        (Proc: Proc_ChDir_MkDir_RmDir;    ProcParameter: SysProc_DirCreate),
        (Proc: Proc_ChDir_MkDir_RmDir;    ProcParameter: SysProc_DirRemove),
        (Proc: Proc_Append_Flush;         ProcParameter: SysProc_AppendText),
        (Proc: Proc_Append_Flush;         ProcParameter: SysProc_FlushText),
        (Proc: Proc_Inc_Dec;              ProcParameter: $00),
        (Proc: Proc_Inc_Dec;              ProcParameter: $28),
        (Proc: Proc_BlockRead_BlockWrite; ProcParameter: SysProc_ReadBlock),
        (Proc: Proc_BlockRead_BlockWrite; ProcParameter: SysProc_WriteBlock),
        (Proc: Proc_SetTextBuf;           ProcParameter: 0),
        (Proc: Proc_Halt_RunError;        ProcParameter: SysProc_HaltError),
        (Proc: Proc_Fail;                 ProcParameter: 0),
        (Proc: Proc_BREAK_CONTINUE_Exit;  ProcParameter: Ofs (LastJumpOutOfBlock)),
        (Proc: Proc_BREAK_CONTINUE_Exit;  ProcParameter: Ofs (LastJumpToNextBlockIteration)),
        (Proc: Proc_Include_Exclude;      ProcParameter: Include),
        (Proc: Proc_Include_Exclude;      ProcParameter: Exclude));

This function processes system procedures. The parameter is saved to allow recursion.

Function SystemProcedure (ProcNumber: Word): Word;
Var SavedParameter: Word;
begin
  SavedParameter := ProcParameter;
  ProcParameter := stProcedures [ProcNumber].ProcParameter;
  SystemProcedure := stProcedures [ProcNumber].Proc;

  If ProcParameter = $FFFF then Halt (1);

  ProcParameter := SavedParameter;
end;