Page 1 of 1
writeln() in pascal.
Posted: Sun Aug 30, 2009 7:38 am
by DeleteMe
how in the *beep* do i do this!
how do i run the simple code:
Code: Select all
begin
writeln('something ',12);
end;
i just can't firgure it out, because, when you look at the deasmbly of a normal executable, there are no "writeln", how i *beep* do i implement it. i also had looked at the rtl for linux but there is no "writeln". but i found out its some kind of file i write it to(stdin/stdout, so on...). can someone pleas tell me.
Re: writeln() in pascal.
Posted: Sun Aug 30, 2009 7:48 am
by Dex
You do not say realmode or pmode, in realmode you can use a bootloader like bootprog and by add CRT it mean it use bios instead of int 21h
Code: Select all
program Hello;
uses
crt;
begin
ClrScr;
Write('Hello world');
Readln;
end.
For pmode i have a pmode pascal OS you can see.
Re: writeln() in pascal.
Posted: Sun Aug 30, 2009 11:13 pm
by leledumbo
i just can't firgure it out, because, when you look at the deasmbly of a normal executable, there are no "writeln", how i *beep* do i implement it. i also had looked at the rtl for linux but there is no "writeln". but i found out its some kind of file i write it to(stdin/stdout, so on...). can someone pleas tell me.
Write(Ln) is not actually a routine, but a special command that will be mapped by the compiler to the correct procedure based on the type. For instance, if you have:
where i is an integer (default = smallint), you might end up with:
Code: Select all
...
fpc_write_text_pchar_as_array
...
fpc_write_text_smallint
...
You have to implement Do_* in sysfile.inc for your own OS (take one from other OSes and empty the procedure / function body).
*) The mechanism is actually compiler dependent, but since FPC is (likely) the only one capable for OSDeving, I explain how FPC implements it.
Re: writeln() in pascal.
Posted: Mon Aug 31, 2009 12:41 am
by DeleteMe
thanks! thats what i've needed
Re: writeln() in pascal.
Posted: Mon Aug 31, 2009 10:02 am
by Laksen
Here's a really simple implementation that implements all the basic functions for x86, without needing all the runtime checks that are in the fpc rtl code
Code: Select all
interface
...
type
PText = ^Text;
Function fpc_get_input:PText;compilerproc;
Function fpc_get_output:PText;compilerproc;
Procedure fpc_Write_End(var f:Text); compilerproc;
Procedure fpc_Writeln_End(var f:Text); compilerproc;
Procedure fpc_Write_Text_ShortStr(Len : Longint;var f : Text;const s : String); compilerproc;
Procedure fpc_Write_Text_Pchar_as_Array(Len : Longint;var f : Text;const s : array of char; zerobased: boolean = true); compilerproc;
Procedure fpc_Write_Text_PChar_As_Pointer(Len : Longint;var f : Text;p : PChar); compilerproc;
Procedure fpc_Write_Text_AnsiStr (Len : Longint; Var f : Text; const S : AnsiString); compilerproc;
Procedure fpc_Write_Text_Char(Len : Longint;var t : Text;c : Char); compilerproc;
Procedure fpc_Write_Text_SInt(Len : Longint;var t : Text;l : PtrInt); compilerproc;
Procedure fpc_Write_Text_UInt(Len : Longint;var t : Text;l : PtrUInt); compilerproc;
procedure fpc_write_text_qword(len : longint;var t : text;q : qword); compilerproc;
procedure fpc_write_text_int64(len : longint;var t : text;i : int64); compilerproc;
Procedure fpc_Write_Text_Boolean(Len : Longint;var t : Text;b : Boolean); compilerproc;
...
implementation
...
var x: longint = 0;
y: longint = 0;
procedure putchar(c: char);
begin
if c = #13 then
x := 0
else if c = #0 then
exit
else if c = #10 then
inc(y)
else if c = #9 then
inc(x, 8-(x mod 8))
else
begin
pchar($b8000+2*(x+y*80))^ := c;
inc(x);
end;
if x >= 80 then
begin
x := 0;
inc(y);
end;
while y >= 25 do
begin
move(pchar($b8000+160)^, pchar($b8000)^, 80*24*2);
fillword(pchar($b8000+24*160)^, 80, $720);
dec(y);
end;
end;
Function fpc_get_input:PText;compilerproc;
begin
result := nil;
end;
Function fpc_get_output:PText;compilerproc;
begin
result := nil;
end;
Procedure fpc_Write_End(var f:Text); compilerproc;
begin
end;
Procedure fpc_Writeln_End(var f:Text); compilerproc;
begin
putchar(#13);
putchar(#10);
end;
Procedure fpc_Write_Text_ShortStr(Len : Longint;var f : Text;const s : String); compilerproc;
var i: longint;
begin
for i := 1 to length(s) do
putchar(s[i]);
end;
Procedure fpc_Write_Text_Pchar_as_Array(Len : Longint;var f : Text;const s : array of char; zerobased: boolean = true); compilerproc;
var i: longint;
begin
if zerobased then
begin
for i := 0 to high(s) do
putchar(s[i]);
end
else
begin
for i := 1 to length(s) do
putchar(s[i]);
end;
end;
Procedure fpc_Write_Text_PChar_As_Pointer(Len : Longint;var f : Text;p : PChar); compilerproc;
begin
if p = nil then
exit;
while p^ <> #0 do
begin
putchar(p^);
inc(p);
end;
end;
Procedure fpc_Write_Text_AnsiStr (Len : Longint; Var f : Text; const S : AnsiString); compilerproc;
var i: longint;
begin
for i := 1 to length(s) do
putchar(s[i]);
end;
Procedure fpc_Write_Text_Char(Len : Longint;var t : Text;c : Char); compilerproc;
begin
putchar(c);
end;
Procedure fpc_Write_Text_SInt(Len : Longint;var t : Text;l : PtrInt); compilerproc;
begin
if l < 0 then
begin
write('-');
l := -l;
end;
fpc_Write_Text_UInt(len, t, l);
end;
Procedure fpc_Write_Text_UInt(Len : Longint;var t : Text;l : PtrUInt); compilerproc;
var buf: array[0..11] of char;
p: longint;
begin
if l = 0 then
putchar('0')
else
begin
p := high(buf);
buf[p] := #0;
while l > 0 do
begin
dec(p);
buf[p] := char((l mod 10)+byte('0'));
l := l div 10;
end;
write(pchar(@buf[p]));
end;
end;
procedure fpc_write_text_qword(len : longint;var t : text;q : qword); compilerproc;
var buf: array[0..19] of char;
p: longint;
begin
if q = 0 then
putchar('0')
else
begin
p := high(buf);
buf[p] := #0;
while q > 0 do
begin
dec(p);
buf[p] := char((q mod 10)+byte('0'));
q := q div 10;
end;
write(pchar(@buf[p]));
end;
end;
procedure fpc_write_text_int64(len : longint;var t : text;i : int64); compilerproc;
begin
if i < 0 then
begin
write('-');
i := -i;
end;
write(qword(i));
end;
Procedure fpc_Write_Text_Boolean(Len : Longint;var t : Text;b : Boolean); compilerproc;
begin
if b then
write('true')
else
write('false');
end;