Console Refactoring.
git-svn-id: https://spexeah.com:8443/svn/Asuro@6 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
ca2e904cf6
commit
815d1b8199
BIN
bin/kernel.bin
BIN
bin/kernel.bin
Binary file not shown.
Binary file not shown.
BIN
lib/console.o
BIN
lib/console.o
Binary file not shown.
BIN
lib/console.ppu
BIN
lib/console.ppu
Binary file not shown.
BIN
lib/kernel.o
BIN
lib/kernel.o
Binary file not shown.
BIN
lib/kernel.ppu
BIN
lib/kernel.ppu
Binary file not shown.
Binary file not shown.
BIN
lib/libpkernel.a
BIN
lib/libpkernel.a
Binary file not shown.
232
src/console.pas
232
src/console.pas
@ -15,16 +15,24 @@ unit console;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
var
|
procedure console_init();
|
||||||
xpos: Integer = 0;
|
procedure console_clear();
|
||||||
ypos: Integer = 0;
|
|
||||||
|
|
||||||
procedure ktest();
|
procedure console_writechar(character : char; attributes : char);
|
||||||
procedure kclearscreen();
|
procedure console_writestring(str: PChar; attributes : char);
|
||||||
procedure kwritechr(c: Char);
|
procedure console_writeint(i: Integer; attributes : char);
|
||||||
procedure kwritestr(s: PChar);
|
procedure console_writedword(i: DWORD; attributes : char);
|
||||||
procedure kwriteint(i: Integer);
|
|
||||||
procedure kwritedword(i: DWORD);
|
procedure console_writecharln(character : char; attributes : char);
|
||||||
|
procedure console_writestringln(str: PChar; attributes : char);
|
||||||
|
procedure console_writeintln(i: Integer; attributes : char);
|
||||||
|
procedure console_writedwordln(i: DWORD; attributes : char);
|
||||||
|
|
||||||
|
procedure _console_increment_x();
|
||||||
|
procedure _console_increment_y();
|
||||||
|
procedure _console_safeincrement_y();
|
||||||
|
procedure _console_safeincrement_x();
|
||||||
|
procedure _console_newline();
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -41,79 +49,56 @@ type
|
|||||||
T2DVideoMemory = Array[0..24] of Array[0..79] of TCharacter;
|
T2DVideoMemory = Array[0..24] of Array[0..79] of TCharacter;
|
||||||
P2DVideoMemory = ^T2DVideoMemory;
|
P2DVideoMemory = ^T2DVideoMemory;
|
||||||
|
|
||||||
|
TCoord = record
|
||||||
|
X : Byte;
|
||||||
|
Y : Byte;
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
vidmem : PChar = PChar($b8000);
|
Console_Memory : PVideoMemory = PVideoMemory($b8000);
|
||||||
memory : PVideoMemory = PVideoMemory($b8000);
|
Console_Matrix : P2DVideoMemory = P2DVideoMemory($b8000);
|
||||||
mem2d : P2DVideoMemory = P2DVideoMemory($b8000);
|
Console_Cursor : TCoord;
|
||||||
|
|
||||||
|
procedure console_init(); [public, alias: 'console_init'];
|
||||||
|
Begin
|
||||||
|
console_clear();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_clear(); [public, alias: 'console_clear'];
|
||||||
|
var
|
||||||
|
x,y: Byte;
|
||||||
|
|
||||||
procedure ktest(); [public, alias: 'ktest'];
|
|
||||||
begin
|
begin
|
||||||
memory^[0].Attributes:= #7;
|
for x:=0 to 79 do begin
|
||||||
memory^[0].Character:= 'T';
|
for y:=0 to 24 do begin
|
||||||
mem2d^[1][0].Attributes:=#7;
|
Console_Matrix^[y][x].Character:=#0;
|
||||||
mem2d^[1][0].Character:='E';
|
Console_Matrix^[y][x].Attributes:=#7;
|
||||||
while true do begin
|
end;
|
||||||
|
end;
|
||||||
|
Console_Cursor.X:= 0;
|
||||||
|
Console_Cursor.Y:= 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writechar(character: char; attributes: char); [public, alias: 'console_writechar'];
|
||||||
|
begin
|
||||||
|
Console_Matrix^[Console_Cursor.Y][Console_Cursor.X].Character:= character;
|
||||||
|
Console_Matrix^[Console_Cursor.Y][Console_Cursor.X].Attributes:= attributes;
|
||||||
|
_console_safeincrement_x();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writestring(str: PChar; attributes: char); [public, alias: 'console_writestring'];
|
||||||
|
var
|
||||||
|
i : integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
i:= 0;
|
||||||
|
while (str[i] <> #0) do begin
|
||||||
|
console_writechar(str[i], attributes);
|
||||||
|
i:=i+1;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure kclearscreen(); [public, alias: 'kclearscreen'];
|
procedure console_writeint(i: Integer; attributes : char); [public, alias: 'console_writeint'];
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
for i := 0 to 3999 do
|
|
||||||
vidmem[i] := #0;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure kwritechr(c: Char); [public, alias: 'kwritechr'];
|
|
||||||
var
|
|
||||||
offset: Integer;
|
|
||||||
begin
|
|
||||||
if (ypos > 24) then
|
|
||||||
ypos := 0;
|
|
||||||
|
|
||||||
if (xpos > 79) then
|
|
||||||
xpos := 0;
|
|
||||||
|
|
||||||
offset := (xpos shl 1) + (ypos * 160);
|
|
||||||
vidmem[offset] := c;
|
|
||||||
offset += 1;
|
|
||||||
vidmem[offset] := #7;
|
|
||||||
offset += 1;
|
|
||||||
|
|
||||||
xpos := (offset mod 160);
|
|
||||||
ypos := (offset - xpos) div 160;
|
|
||||||
xpos := xpos shr 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure kwritestr(s: PChar); [public, alias: 'kwritestr'];
|
|
||||||
var
|
|
||||||
offset, i: Integer;
|
|
||||||
begin
|
|
||||||
if (ypos > 24) then
|
|
||||||
ypos := 0;
|
|
||||||
|
|
||||||
if (xpos > 79) then
|
|
||||||
xpos := 0;
|
|
||||||
|
|
||||||
offset := (xpos shl 1) + (ypos * 160);
|
|
||||||
i := 0;
|
|
||||||
|
|
||||||
while (s[i] <> Char($0)) do
|
|
||||||
begin
|
|
||||||
vidmem[offset] := s[i];
|
|
||||||
offset += 1;
|
|
||||||
vidmem[offset] := #7;
|
|
||||||
offset += 1;
|
|
||||||
i += 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
xpos := (offset mod 160);
|
|
||||||
ypos := (offset - xpos) div 160;
|
|
||||||
xpos := xpos shr 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure kwriteint(i: Integer); [public, alias: 'kwriteint'];
|
|
||||||
var
|
var
|
||||||
buffer: array [0..11] of Char;
|
buffer: array [0..11] of Char;
|
||||||
str: PChar;
|
str: PChar;
|
||||||
@ -122,53 +107,114 @@ var
|
|||||||
begin
|
begin
|
||||||
str := @buffer[11];
|
str := @buffer[11];
|
||||||
str^ := #0;
|
str^ := #0;
|
||||||
|
if (i < 0) then begin
|
||||||
if (i < 0) then
|
|
||||||
begin
|
|
||||||
digit := -i;
|
digit := -i;
|
||||||
minus := True;
|
minus := True;
|
||||||
end
|
end else begin
|
||||||
else
|
|
||||||
begin
|
|
||||||
digit := i;
|
digit := i;
|
||||||
minus := False;
|
minus := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
Dec(str);
|
Dec(str);
|
||||||
str^ := Char((digit mod 10) + Byte('0'));
|
str^ := Char((digit mod 10) + Byte('0'));
|
||||||
digit := digit div 10;
|
digit := digit div 10;
|
||||||
until (digit = 0);
|
until (digit = 0);
|
||||||
|
if (minus) then begin
|
||||||
if (minus) then
|
|
||||||
begin
|
|
||||||
Dec(str);
|
Dec(str);
|
||||||
str^ := '-';
|
str^ := '-';
|
||||||
end;
|
end;
|
||||||
|
console_writestring(str, attributes);
|
||||||
kwritestr(str);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure kwritedword(i: DWORD); [public, alias: 'kwritedword'];
|
procedure console_writedword(i: DWORD; attributes : char); [public, alias: 'console_writedword'];
|
||||||
var
|
var
|
||||||
buffer: array [0..11] of Char;
|
buffer: array [0..11] of Char;
|
||||||
str: PChar;
|
str: PChar;
|
||||||
digit: DWORD;
|
digit: DWORD;
|
||||||
begin
|
begin
|
||||||
for digit := 0 to 10 do
|
for digit := 0 to 10 do buffer[digit] := '0';
|
||||||
buffer[digit] := '0';
|
|
||||||
|
|
||||||
str := @buffer[11];
|
str := @buffer[11];
|
||||||
str^ := #0;
|
str^ := #0;
|
||||||
|
|
||||||
digit := i;
|
digit := i;
|
||||||
repeat
|
repeat
|
||||||
Dec(str);
|
Dec(str);
|
||||||
str^ := Char((digit mod 10) + Byte('0'));
|
str^ := Char((digit mod 10) + Byte('0'));
|
||||||
digit := digit div 10;
|
digit := digit div 10;
|
||||||
until (digit = 0);
|
until (digit = 0);
|
||||||
|
console_writestring(@Buffer[0], attributes);
|
||||||
|
end;
|
||||||
|
|
||||||
kwritestr(@Buffer[0]);
|
procedure console_writecharln(character: char; attributes: char); [public, alias: 'console_writecharln'];
|
||||||
|
begin
|
||||||
|
console_writechar(character, attributes);
|
||||||
|
_console_safeincrement_y();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writestringln(str: PChar; attributes: char); [public, alias: 'console_writestringln'];
|
||||||
|
begin
|
||||||
|
console_writestring(str, attributes);
|
||||||
|
_console_safeincrement_y();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writeintln(i: Integer; attributes: char); [public, alias: 'console_writeintln'];
|
||||||
|
begin
|
||||||
|
console_writeint(i, attributes);
|
||||||
|
_console_safeincrement_y();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writedwordln(i: DWORD; attributes: char); [public, alias: 'console_writedwordln'];
|
||||||
|
begin
|
||||||
|
console_writedword(i, attributes);
|
||||||
|
_console_safeincrement_y();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure _console_increment_x(); [public, alias: '_console_increment_x'];
|
||||||
|
begin
|
||||||
|
Console_Cursor.X:= Console_Cursor.X+1;
|
||||||
|
If Console_Cursor.X > 79 then Console_Cursor.X:= 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure _console_increment_y(); [public, alias: '_console_increment_y'];
|
||||||
|
begin
|
||||||
|
Console_Cursor.Y:= Console_Cursor.Y+1;
|
||||||
|
If Console_Cursor.Y > 24 then begin
|
||||||
|
_console_newline();
|
||||||
|
Console_Cursor.Y:= 24;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure _console_safeincrement_x(); [public, alias: '_console_safeincrement_x'];
|
||||||
|
begin
|
||||||
|
Console_Cursor.X:= Console_Cursor.X+1;
|
||||||
|
If Console_Cursor.X > 79 then begin
|
||||||
|
_console_safeincrement_y();
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure _console_safeincrement_y(); [public, alias: '_console_safeincrement_y'];
|
||||||
|
begin
|
||||||
|
Console_Cursor.Y:= Console_Cursor.Y+1;
|
||||||
|
If Console_Cursor.Y > 24 then begin
|
||||||
|
_console_newline();
|
||||||
|
Console_Cursor.Y:= 24;
|
||||||
|
end;
|
||||||
|
Console_Cursor.X:= 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure _console_newline(); [public, alias: '_console_newline'];
|
||||||
|
var
|
||||||
|
x, y : byte;
|
||||||
|
|
||||||
|
begin
|
||||||
|
for x:=0 to 79 do begin
|
||||||
|
for y:=0 to 23 do begin
|
||||||
|
Console_Matrix^[y][x]:= Console_Matrix^[y+1][x];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
for x:=0 to 79 do begin
|
||||||
|
Console_Matrix^[24][x].Character:= #0;
|
||||||
|
Console_Matrix^[24][x].Attributes:= #7;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -25,44 +25,26 @@ implementation
|
|||||||
|
|
||||||
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall; [public, alias: 'kmain'];
|
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall; [public, alias: 'kmain'];
|
||||||
begin
|
begin
|
||||||
kclearscreen();
|
console_init();
|
||||||
ktest();
|
console_writestringln('Asuro Booting...', #7);
|
||||||
kwritestr('FUCK YOU!');
|
if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin
|
||||||
kwritestr('Freepascal barebone OS booted!');
|
console_writestringln('Multiboot Compliant Boot-Loader Needed!', #7);
|
||||||
xpos := 0;
|
console_writestringln('HALTING', #7);
|
||||||
ypos += 1;
|
|
||||||
|
|
||||||
if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then
|
|
||||||
begin
|
|
||||||
kwritestr('Halting system, a multiboot-compliant boot loader needed!');
|
|
||||||
asm
|
asm
|
||||||
cli
|
cli
|
||||||
hlt
|
hlt
|
||||||
end;
|
end;
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
kwritestr('Booted by a multiboot-compliant boot loader!');
|
|
||||||
xpos := 0;
|
|
||||||
ypos += 2;
|
|
||||||
kwritestr('Multiboot information:');
|
|
||||||
xpos := 0;
|
|
||||||
ypos += 2;
|
|
||||||
kwritestr(' Lower memory = ');
|
|
||||||
kwriteint(mbinfo^.mem_lower);
|
|
||||||
kwritestr('KB');
|
|
||||||
xpos := 0;
|
|
||||||
ypos += 1;
|
|
||||||
kwritestr(' Higher memory = ');
|
|
||||||
kwriteint(mbinfo^.mem_upper);
|
|
||||||
kwritestr('KB');
|
|
||||||
xpos := 0;
|
|
||||||
ypos += 1;
|
|
||||||
kwritestr(' Total memory = ');
|
|
||||||
kwriteint(((mbinfo^.mem_upper + 1000) div 1024) +1);
|
|
||||||
kwritestr('MB');
|
|
||||||
end;
|
end;
|
||||||
|
console_writestringln('Asuro Booted Correctly!', #7);
|
||||||
|
console_writestring('Lower Memory = ', #7);
|
||||||
|
console_writeint(mbinfo^.mem_lower, #7);
|
||||||
|
console_writestringln('KB', #7);
|
||||||
|
console_writestring('Higher Memory = ', #7);
|
||||||
|
console_writeint(mbinfo^.mem_upper, #7);
|
||||||
|
console_writestringln('KB', #7);
|
||||||
|
console_writestring('Total Memory = ', #7);
|
||||||
|
console_writeint(((mbinfo^.mem_upper + 1000) div 1024) +1, #7);
|
||||||
|
console_writestringln('MB', #7);
|
||||||
asm
|
asm
|
||||||
@loop:
|
@loop:
|
||||||
jmp @loop
|
jmp @loop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user