Cleanup/Refactoring.
git-svn-id: https://spexeah.com:8443/svn/Asuro@14 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
d6460dcf61
commit
81363a9c57
BIN
bin/kernel.bin
BIN
bin/kernel.bin
Binary file not shown.
Binary file not shown.
BIN
lib/BIOS_DATA_AREA.ppu
Normal file
BIN
lib/BIOS_DATA_AREA.ppu
Normal file
Binary file not shown.
BIN
lib/bda.ppu
BIN
lib/bda.ppu
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.
BIN
lib/util.ppu
BIN
lib/util.ppu
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
unit bda;
|
||||
unit BIOS_DATA_AREA;
|
||||
|
||||
interface
|
||||
|
||||
@ -25,6 +25,9 @@ type
|
||||
end;
|
||||
PBDA = ^TBDA;
|
||||
|
||||
const
|
||||
BDA : PBDA = PBDA($0400);
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
167
src/console.pas
167
src/console.pas
@ -3,7 +3,8 @@ unit console;
|
||||
interface
|
||||
|
||||
uses
|
||||
util, bda;
|
||||
util,
|
||||
BIOS_DATA_AREA;
|
||||
|
||||
type
|
||||
TColor = ( Black = $0,
|
||||
@ -23,37 +24,37 @@ type
|
||||
lYellow = $E,
|
||||
lWhite = $F );
|
||||
|
||||
procedure console_init();
|
||||
procedure console_clear();
|
||||
procedure console_setdefaultattribute(attribute : char);
|
||||
procedure init();
|
||||
procedure clear();
|
||||
procedure setdefaultattribute(attribute : char);
|
||||
|
||||
procedure console_writechar(character : char);
|
||||
procedure console_writestring(str: PChar);
|
||||
procedure console_writeint(i: Integer);
|
||||
procedure console_writeword(i: DWORD);
|
||||
procedure writechar(character : char);
|
||||
procedure writestring(str: PChar);
|
||||
procedure writeint(i: Integer);
|
||||
procedure writeword(i: DWORD);
|
||||
|
||||
procedure console_writecharln(character : char);
|
||||
procedure console_writestringln(str: PChar);
|
||||
procedure console_writeintln(i: Integer);
|
||||
procedure console_writewordln(i: DWORD);
|
||||
procedure writecharln(character : char);
|
||||
procedure writestringln(str: PChar);
|
||||
procedure writeintln(i: Integer);
|
||||
procedure writewordln(i: DWORD);
|
||||
|
||||
procedure console_writecharex(character : char; attributes : char);
|
||||
procedure console_writestringex(str: PChar; attributes : char);
|
||||
procedure console_writeintex(i: Integer; attributes : char);
|
||||
procedure console_writewordex(i: DWORD; attributes : char);
|
||||
procedure writecharex(character : char; attributes : char);
|
||||
procedure writestringex(str: PChar; attributes : char);
|
||||
procedure writeintex(i: Integer; attributes : char);
|
||||
procedure writewordex(i: DWORD; attributes : char);
|
||||
|
||||
procedure console_writecharlnex(character : char; attributes : char);
|
||||
procedure console_writestringlnex(str: PChar; attributes : char);
|
||||
procedure console_writeintlnex(i: Integer; attributes : char);
|
||||
procedure console_writewordlnex(i: DWORD; attributes : char);
|
||||
procedure writecharlnex(character : char; attributes : char);
|
||||
procedure writestringlnex(str: PChar; attributes : char);
|
||||
procedure writeintlnex(i: Integer; attributes : char);
|
||||
procedure writewordlnex(i: DWORD; attributes : char);
|
||||
|
||||
function console_combinecolors(Foreground, Background : TColor) : char;
|
||||
function combinecolors(Foreground, Background : TColor) : char;
|
||||
|
||||
procedure _console_increment_x();
|
||||
procedure _console_increment_y();
|
||||
procedure _console_safeincrement_y();
|
||||
procedure _console_safeincrement_x();
|
||||
procedure _console_newline();
|
||||
procedure _increment_x();
|
||||
procedure _increment_y();
|
||||
procedure _safeincrement_y();
|
||||
procedure _safeincrement_x();
|
||||
procedure _newline();
|
||||
|
||||
implementation
|
||||
|
||||
@ -85,13 +86,13 @@ var
|
||||
Console_Matrix : P2DVideoMemory = P2DVideoMemory($b8000);
|
||||
Console_Cursor : TCoord;
|
||||
|
||||
procedure console_init(); [public, alias: 'console_init'];
|
||||
procedure init(); [public, alias: 'console_init'];
|
||||
Begin
|
||||
Console_Properties.Default_Attribute:= console_combinecolors(White, Black);
|
||||
console_clear();
|
||||
Console_Properties.Default_Attribute:= console.combinecolors(White, Black);
|
||||
console.clear();
|
||||
end;
|
||||
|
||||
procedure console_clear(); [public, alias: 'console_clear'];
|
||||
procedure clear(); [public, alias: 'console_clear'];
|
||||
var
|
||||
x,y: Byte;
|
||||
|
||||
@ -106,71 +107,71 @@ begin
|
||||
Console_Cursor.Y:= 0;
|
||||
end;
|
||||
|
||||
procedure console_setdefaultattribute(attribute: char); [public, alias: 'console_setdefaultattribute'];
|
||||
procedure setdefaultattribute(attribute: char); [public, alias: 'console_setdefaultattribute'];
|
||||
begin
|
||||
Console_Properties.Default_Attribute:= attribute;
|
||||
end;
|
||||
|
||||
procedure console_writechar(character: char); [public, alias: 'console_writechar'];
|
||||
procedure writechar(character: char); [public, alias: 'console_writechar'];
|
||||
begin
|
||||
console_writecharex(character, Console_Properties.Default_Attribute);
|
||||
console.writecharex(character, Console_Properties.Default_Attribute);
|
||||
end;
|
||||
|
||||
procedure console_writestring(str: PChar); [public, alias: 'console_writestring'];
|
||||
procedure writestring(str: PChar); [public, alias: 'console_writestring'];
|
||||
begin
|
||||
console_writestringex(str, Console_Properties.Default_Attribute);
|
||||
console.writestringex(str, Console_Properties.Default_Attribute);
|
||||
end;
|
||||
|
||||
procedure console_writeint(i: Integer); [public, alias: 'console_writeint'];
|
||||
procedure writeint(i: Integer); [public, alias: 'console_writeint'];
|
||||
begin
|
||||
console_writeintex(i, Console_Properties.Default_Attribute);
|
||||
console.writeintex(i, Console_Properties.Default_Attribute);
|
||||
end;
|
||||
|
||||
procedure console_writeword(i: DWORD); [public, alias: 'console_writeword'];
|
||||
procedure writeword(i: DWORD); [public, alias: 'console_writeword'];
|
||||
begin
|
||||
console_writewordex(i, Console_Properties.Default_Attribute);
|
||||
console.writewordex(i, Console_Properties.Default_Attribute);
|
||||
end;
|
||||
|
||||
procedure console_writecharln(character: char); [public, alias: 'console_writecharln'];
|
||||
procedure writecharln(character: char); [public, alias: 'console_writecharln'];
|
||||
begin
|
||||
console_writecharlnex(character, Console_Properties.Default_Attribute);
|
||||
console.writecharlnex(character, Console_Properties.Default_Attribute);
|
||||
end;
|
||||
|
||||
procedure console_writestringln(str: PChar); [public, alias: 'console_writestringln'];
|
||||
procedure writestringln(str: PChar); [public, alias: 'console_writestringln'];
|
||||
begin
|
||||
console_writestringlnex(str, Console_Properties.Default_Attribute);
|
||||
console.writestringlnex(str, Console_Properties.Default_Attribute);
|
||||
end;
|
||||
|
||||
procedure console_writeintln(i: Integer); [public, alias: 'console_writeintln'];
|
||||
procedure writeintln(i: Integer); [public, alias: 'console_writeintln'];
|
||||
begin
|
||||
console_writeintlnex(i, Console_Properties.Default_Attribute);
|
||||
console.writeintlnex(i, Console_Properties.Default_Attribute);
|
||||
end;
|
||||
|
||||
procedure console_writewordln(i: DWORD); [public, alias: 'console_writewordln'];
|
||||
procedure writewordln(i: DWORD); [public, alias: 'console_writewordln'];
|
||||
begin
|
||||
console_writewordlnex(i, Console_Properties.Default_Attribute);
|
||||
console.writewordlnex(i, Console_Properties.Default_Attribute);
|
||||
end;
|
||||
|
||||
procedure console_writecharex(character: char; attributes: char); [public, alias: 'console_writecharex'];
|
||||
procedure writecharex(character: char; attributes: char); [public, alias: 'console_writecharex'];
|
||||
begin
|
||||
Console_Matrix^[Console_Cursor.Y][Console_Cursor.X].Character:= character;
|
||||
Console_Matrix^[Console_Cursor.Y][Console_Cursor.X].Attributes:= attributes;
|
||||
_console_safeincrement_x();
|
||||
console._safeincrement_x();
|
||||
end;
|
||||
|
||||
procedure console_writestringex(str: PChar; attributes: char); [public, alias: 'console_writestringex'];
|
||||
procedure writestringex(str: PChar; attributes: char); [public, alias: 'console_writestringex'];
|
||||
var
|
||||
i : integer;
|
||||
|
||||
begin
|
||||
i:= 0;
|
||||
while (str[i] <> #0) do begin
|
||||
console_writecharex(str[i], attributes);
|
||||
console.writecharex(str[i], attributes);
|
||||
i:=i+1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure console_writeintex(i: Integer; attributes : char); [public, alias: 'console_writeintex'];
|
||||
procedure writeintex(i: Integer; attributes : char); [public, alias: 'console_writeintex'];
|
||||
var
|
||||
buffer: array [0..11] of Char;
|
||||
str: PChar;
|
||||
@ -195,10 +196,10 @@ begin
|
||||
Dec(str);
|
||||
str^ := '-';
|
||||
end;
|
||||
console_writestringex(str, attributes);
|
||||
console.writestringex(str, attributes);
|
||||
end;
|
||||
|
||||
procedure console_writewordex(i: DWORD; attributes : char); [public, alias: 'console_writedwordex'];
|
||||
procedure writewordex(i: DWORD; attributes : char); [public, alias: 'console_writedwordex'];
|
||||
var
|
||||
buffer: array [0..11] of Char;
|
||||
str: PChar;
|
||||
@ -213,39 +214,39 @@ begin
|
||||
str^ := Char((digit mod 10) + Byte('0'));
|
||||
digit := digit div 10;
|
||||
until (digit = 0);
|
||||
console_writestringex(@Buffer[0], attributes);
|
||||
console.writestringex(@Buffer[0], attributes);
|
||||
end;
|
||||
|
||||
procedure console_writecharlnex(character: char; attributes: char); [public, alias: 'console_writecharlnex'];
|
||||
procedure writecharlnex(character: char; attributes: char); [public, alias: 'console_writecharlnex'];
|
||||
begin
|
||||
console_writecharex(character, attributes);
|
||||
_console_safeincrement_y();
|
||||
console.writecharex(character, attributes);
|
||||
console._safeincrement_y();
|
||||
end;
|
||||
|
||||
procedure console_writestringlnex(str: PChar; attributes: char); [public, alias: 'console_writestringlnex'];
|
||||
procedure writestringlnex(str: PChar; attributes: char); [public, alias: 'console_writestringlnex'];
|
||||
begin
|
||||
console_writestringex(str, attributes);
|
||||
_console_safeincrement_y();
|
||||
console.writestringex(str, attributes);
|
||||
console._safeincrement_y();
|
||||
end;
|
||||
|
||||
procedure console_writeintlnex(i: Integer; attributes: char); [public, alias: 'console_writeintlnex'];
|
||||
procedure writeintlnex(i: Integer; attributes: char); [public, alias: 'console_writeintlnex'];
|
||||
begin
|
||||
console_writeintex(i, attributes);
|
||||
_console_safeincrement_y();
|
||||
console.writeintex(i, attributes);
|
||||
console._safeincrement_y();
|
||||
end;
|
||||
|
||||
procedure console_writewordlnex(i: DWORD; attributes: char); [public, alias: 'console_writewordlnex'];
|
||||
procedure writewordlnex(i: DWORD; attributes: char); [public, alias: 'console_writewordlnex'];
|
||||
begin
|
||||
console_writewordex(i, attributes);
|
||||
_console_safeincrement_y();
|
||||
console.writewordex(i, attributes);
|
||||
console._safeincrement_y();
|
||||
end;
|
||||
|
||||
function console_combinecolors(Foreground, Background: TColor): char; [public, alias: 'console_combinecolors'];
|
||||
function combinecolors(Foreground, Background: TColor): char; [public, alias: 'console_combinecolors'];
|
||||
begin
|
||||
console_combinecolors:= char(((ord(Background) shl 4) or ord(Foreground)));
|
||||
combinecolors:= char(((ord(Background) shl 4) or ord(Foreground)));
|
||||
end;
|
||||
|
||||
procedure _console_update_cursor(); [public, alias: '_console_update_cursor'];
|
||||
procedure _update_cursor(); [public, alias: '_console_update_cursor'];
|
||||
var
|
||||
pos : word;
|
||||
b : byte;
|
||||
@ -260,44 +261,44 @@ begin
|
||||
outb($3D5, b);
|
||||
end;
|
||||
|
||||
procedure _console_increment_x(); [public, alias: '_console_increment_x'];
|
||||
procedure _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;
|
||||
_console_update_cursor;
|
||||
console._update_cursor;
|
||||
end;
|
||||
|
||||
procedure _console_increment_y(); [public, alias: '_console_increment_y'];
|
||||
procedure _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._newline();
|
||||
Console_Cursor.Y:= 24;
|
||||
end;
|
||||
_console_update_cursor;
|
||||
console._update_cursor;
|
||||
end;
|
||||
|
||||
procedure _console_safeincrement_x(); [public, alias: '_console_safeincrement_x'];
|
||||
procedure _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();
|
||||
console._safeincrement_y();
|
||||
end;
|
||||
_console_update_cursor;
|
||||
console._update_cursor;
|
||||
end;
|
||||
|
||||
procedure _console_safeincrement_y(); [public, alias: '_console_safeincrement_y'];
|
||||
procedure _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._newline();
|
||||
Console_Cursor.Y:= 24;
|
||||
end;
|
||||
Console_Cursor.X:= 0;
|
||||
_console_update_cursor;
|
||||
console._update_cursor;
|
||||
end;
|
||||
|
||||
procedure _console_newline(); [public, alias: '_console_newline'];
|
||||
procedure _newline(); [public, alias: '_console_newline'];
|
||||
var
|
||||
x, y : byte;
|
||||
|
||||
@ -311,7 +312,7 @@ begin
|
||||
Console_Matrix^[24][x].Character:= #0;
|
||||
Console_Matrix^[24][x].Attributes:= #7;
|
||||
end;
|
||||
_console_update_cursor
|
||||
console._update_cursor
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -3,50 +3,41 @@ unit kernel;
|
||||
interface
|
||||
|
||||
uses
|
||||
multiboot,
|
||||
console,
|
||||
bda;
|
||||
multiboot,
|
||||
util,
|
||||
console,
|
||||
BIOS_DATA_AREA;
|
||||
|
||||
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall;
|
||||
|
||||
implementation
|
||||
|
||||
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall; [public, alias: 'kmain'];
|
||||
var
|
||||
_bda : PBDA;
|
||||
|
||||
begin
|
||||
_bda:= PBDA($0400);
|
||||
console_init();
|
||||
console_writestringln('Booting Asuro...');
|
||||
console.init();
|
||||
console.writestringln('Booting Asuro...');
|
||||
if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin
|
||||
console_setdefaultattribute(console_combinecolors(Red, Black));
|
||||
console_writestringln('Multiboot Compliant Boot-Loader Needed!');
|
||||
console_writestringln('HALTING');
|
||||
asm
|
||||
cli
|
||||
hlt
|
||||
end;
|
||||
end;
|
||||
console_clear();
|
||||
console_setdefaultattribute(console_combinecolors(Green, Black));
|
||||
console_writestringln('Asuro Booted Correctly!');
|
||||
console_writestringln('');
|
||||
console_setdefaultattribute(console_combinecolors(White, Black));
|
||||
console_writestring('Lower Memory = ');
|
||||
console_writeint(mbinfo^.mem_lower);
|
||||
console_writestringln('KB');
|
||||
console_writestring('Higher Memory = ');
|
||||
console_writeint(mbinfo^.mem_upper);
|
||||
console_writestringln('KB');
|
||||
console_writestring('Total Memory = ');
|
||||
console_writeint(((mbinfo^.mem_upper + 1000) div 1024) +1);
|
||||
console_writestringln('MB');
|
||||
console_setdefaultattribute(console_combinecolors(lYellow, Black));
|
||||
asm
|
||||
cli
|
||||
hlt
|
||||
console.setdefaultattribute(console.combinecolors(Red, Black));
|
||||
console.writestringln('Multiboot Compliant Boot-Loader Needed!');
|
||||
console.writestringln('HALTING');
|
||||
util.halt_and_catch_fire;
|
||||
end;
|
||||
console.clear();
|
||||
console.setdefaultattribute(console.combinecolors(Green, Black));
|
||||
console.writestringln('Asuro Booted Correctly!');
|
||||
console.writestringln('');
|
||||
console.setdefaultattribute(console.combinecolors(White, Black));
|
||||
console.writestring('Lower Memory = ');
|
||||
console.writeint(mbinfo^.mem_lower);
|
||||
console.writestringln('KB');
|
||||
console.writestring('Higher Memory = ');
|
||||
console.writeint(mbinfo^.mem_upper);
|
||||
console.writestringln('KB');
|
||||
console.writestring('Total Memory = ');
|
||||
console.writeint(((mbinfo^.mem_upper + 1000) div 1024) +1);
|
||||
console.writestringln('MB');
|
||||
console.setdefaultattribute(console.combinecolors(lYellow, Black));
|
||||
util.halt_and_catch_fire;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
27
src/util.pas
27
src/util.pas
@ -4,28 +4,29 @@ unit util;
|
||||
|
||||
interface
|
||||
|
||||
function util_hi(b : byte) : byte;
|
||||
function util_lo(b : byte) : byte;
|
||||
function util_switchendian(b : byte) : byte;
|
||||
function hi(b : byte) : byte;
|
||||
function lo(b : byte) : byte;
|
||||
function switchendian(b : byte) : byte;
|
||||
procedure outb(port : word; val : byte);
|
||||
procedure outw(port : word; val : word);
|
||||
procedure outl(port : word; val : longword);
|
||||
procedure halt_and_catch_fire();
|
||||
|
||||
implementation
|
||||
|
||||
function util_hi(b : byte) : byte; [public, alias: 'util_hi'];
|
||||
function hi(b : byte) : byte; [public, alias: 'util_hi'];
|
||||
begin
|
||||
util_hi:= (b AND $F0) SHR 4;
|
||||
hi:= (b AND $F0) SHR 4;
|
||||
end;
|
||||
|
||||
function util_lo(b : byte) : byte; [public, alias: 'util_lo'];
|
||||
function lo(b : byte) : byte; [public, alias: 'util_lo'];
|
||||
begin
|
||||
util_lo:= b AND $0F;
|
||||
lo:= b AND $0F;
|
||||
end;
|
||||
|
||||
function util_switchendian(b : byte) : byte; [public, alias: 'util_switchendian'];
|
||||
function switchendian(b : byte) : byte; [public, alias: 'util_switchendian'];
|
||||
begin
|
||||
util_switchendian:= (util_lo(b) SHL 4) OR util_hi(b);
|
||||
switchendian:= (lo(b) SHL 4) OR hi(b);
|
||||
end;
|
||||
|
||||
procedure outl(port : word; val : longword); [public, alias: 'outl'];
|
||||
@ -67,4 +68,12 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure halt_and_catch_fire(); [public, alias: 'halt_and_catch_fire'];
|
||||
begin
|
||||
asm
|
||||
cli
|
||||
hlt
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
x
Reference in New Issue
Block a user