Runtime error support added

This commit is contained in:
Владислав Джавадов 2021-01-05 07:28:59 +03:00
parent 0fa5d17830
commit 5343d74f97
4 changed files with 106 additions and 14 deletions

View File

@ -3,9 +3,6 @@ program CharMap;
uses
CRT;
const
HexDigits: array[$0..$F] of KolibriChar = '0123456789ABCDEF';
var
CharLine: array[$0..$F] of KolibriChar;
Line, Ch: Byte;

View File

@ -531,8 +531,8 @@ const
{62.8} function WritePCIByte(Bus, Device, Func, Reg: Byte; Data: Byte): LongWord; stdcall;
{62.9} function WritePCIWord(Bus, Device, Func, Reg: Byte; Data: Word): LongWord; stdcall;
{62.10} function WritePCILongWord(Bus, Device, Func, Reg: Byte; Data: LongWord): LongWord; stdcall;
{63.1} procedure DebugWrite(Data: Byte); stdcall;
{63.2} function DebugRead(var Data: Byte): LongWord; stdcall;
{63.1} procedure DebugWrite(Data: KolibriChar); stdcall;
{63.2} function DebugRead(var Data: KolibriChar): Boolean; stdcall;
{64} function ReallocAppMemory(Count: LongWord): LongInt; stdcall;
{65} procedure DrawImageEx(const Image; Left, Top: LongInt; Width, Height, BPP: LongWord; Palette: Pointer; Padding: LongWord); stdcall;
{66.1} procedure SetKeyboardInputMode(Mode: LongWord); stdcall;
@ -2326,7 +2326,7 @@ asm
pop ebx
end;
procedure DebugWrite(Data: Byte); stdcall;
procedure DebugWrite(Data: KolibriChar); stdcall;
asm
push ebx
mov eax, 63
@ -2336,7 +2336,7 @@ asm
pop ebx
end;
function DebugRead(var Data: Byte): LongWord; stdcall;
function DebugRead(var Data: KolibriChar): Boolean; stdcall;
asm
push ebx
mov eax, 63
@ -2344,7 +2344,8 @@ asm
int $40
mov ecx, Data
mov [ecx], al
mov eax, ebx
cmp bl, 2 // kernel bug workaround
setne al
pop ebx
end;

View File

@ -137,8 +137,12 @@ type
procedure _Halt0;
procedure _HandleFinally;
procedure _Run0Error;
procedure _RunError(ErrorCode: Byte);
procedure _StartExe(InitTable: PPackageInfo);
procedure ErrorMessage(Msg: PKolibriChar; Count: Integer);
var
Default8087CW: Word = $1332; // for Extended type
@ -185,6 +189,8 @@ procedure _WriteString(var T: TTextRec; const S: ShortString; Width: LongInt);
procedure _WriteLString(var T: TTextRec; const S: KolibriString; Width: LongInt);
procedure _WriteLn(var T: TTextRec);
const
HexDigits: array[$0..$F] of KolibriChar = '0123456789ABCDEF';
var
AppPath, CmdLine: PKolibriChar;
@ -237,11 +243,6 @@ uses
var
InitContext: TInitContext;
procedure _HandleFinally;
asm
MOV EAX, 1
end;
procedure InitUnits;
var
Idx: Integer;
@ -294,6 +295,99 @@ asm
INT $40
end;
procedure _HandleFinally;
asm
MOV EAX, 1
end;
procedure _Run0Error;
asm
XOR EAX, EAX
JMP _RunError
end;
procedure _RunError(ErrorCode: Byte);
const
Msg: array[0..28] of KolibriChar = 'Runtime error 000 at 00000000';
asm
MOV EDX, $20202020
MOV CL, 10
XOR CH, CH
@@next10:
XOR AH, AH
DIV CL
SHL EDX, 8
MOV DL, AH
ADD DL, '0'
INC CH
OR AL, AL
JNZ @@next10
MOV EAX, offset Msg[14]
MOV [EAX], EDX
MOVZX ECX, CH
MOV EDX, [EAX+3] // ' at '
ADD EAX, ECX
MOV [EAX], EDX
MOV EBX, EAX // volatile
MOV CL, 4
ADD EBX, ECX
@@next16:
MOV CH, CL
DEC CL
SHL CL, 3
MOV EAX, [ESP]
ROR EAX, CL
AND EAX, $0F
MOV DH, [EAX+HexDigits]
MOV EAX, [ESP]
ROR EAX, CL
MOVZX EAX, AL
SHR EAX, 4
MOV DL, [EAX+HexDigits]
MOV [EBX], DX
INC EBX
INC EBX
MOVZX ECX, CH
LOOP @@next16
MOV EAX, offset Msg
MOV EDX, EBX
SUB EDX, EAX
CALL ErrorMessage
JMP _Halt0
end;
procedure ErrorMessage(Msg: PKolibriChar; Count: Integer);
asm
PUSH EBX
PUSH ESI
MOV ESI, EAX
ADD EDX, EAX
MOV EAX, 63
MOV EBX, 1
@@loop:
CMP ESI, EDX
JE @@exit
MOV CL, [ESI]
INT $40
INC ESI
JMP @@loop
@@exit:
MOV CL, 10
INT $40
POP ESI
POP EBX
end;
function Get8087CW: Word;
asm
PUSH 0

View File

@ -1,6 +1,6 @@
Copyright © 2017-2019 0CodErr
Copyright © 2020 0CodErr, Nikolay Burshtyn (aka amber8706), Vladislav Javadov (aka Freeman)
Copyright © 2020-2021 0CodErr, Nikolay Burshtyn (aka amber8706), Vladislav Javadov (aka Freeman)
All rights reserved.