Console Updates:
- Added Colors as Enum. - Added Attribute Forming Function (Foreground + Background = Attribute). - Added Console Properties. - Added Default Attribute to Console Properties. - Created standard screen functions with an ex variant to specify/override default attr. - Started work on Caret/Cursor (re-)positioning. Util: - Added endianness conversion and various utils. git-svn-id: https://spexeah.com:8443/svn/Asuro@8 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
6208fac551
commit
e28d63ede3
153
src/console.pas
153
src/console.pas
@ -2,18 +2,49 @@ unit console;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
type
|
||||||
|
TColor = ( Black = $0,
|
||||||
|
Blue = $1,
|
||||||
|
Green = $2,
|
||||||
|
Aqua = $3,
|
||||||
|
Red = $4,
|
||||||
|
Purple = $5,
|
||||||
|
Yellow = $6,
|
||||||
|
White = $7,
|
||||||
|
Gray = $8,
|
||||||
|
lBlue = $9,
|
||||||
|
lGreen = $A,
|
||||||
|
lAqua = $B,
|
||||||
|
lRed = $C,
|
||||||
|
lPurple = $D,
|
||||||
|
lYellow = $E,
|
||||||
|
lWhite = $F );
|
||||||
|
|
||||||
procedure console_init();
|
procedure console_init();
|
||||||
procedure console_clear();
|
procedure console_clear();
|
||||||
|
procedure console_setdefaultattribute(attribute : char);
|
||||||
|
|
||||||
procedure console_writechar(character : char; attributes : char);
|
procedure console_writechar(character : char);
|
||||||
procedure console_writestring(str: PChar; attributes : char);
|
procedure console_writestring(str: PChar);
|
||||||
procedure console_writeint(i: Integer; attributes : char);
|
procedure console_writeint(i: Integer);
|
||||||
procedure console_writedword(i: DWORD; attributes : char);
|
procedure console_writeword(i: DWORD);
|
||||||
|
|
||||||
procedure console_writecharln(character : char; attributes : char);
|
procedure console_writecharln(character : char);
|
||||||
procedure console_writestringln(str: PChar; attributes : char);
|
procedure console_writestringln(str: PChar);
|
||||||
procedure console_writeintln(i: Integer; attributes : char);
|
procedure console_writeintln(i: Integer);
|
||||||
procedure console_writedwordln(i: DWORD; attributes : char);
|
procedure console_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 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);
|
||||||
|
|
||||||
|
function console_combinecolors(Foreground, Background : TColor) : char;
|
||||||
|
|
||||||
procedure _console_increment_x();
|
procedure _console_increment_x();
|
||||||
procedure _console_increment_y();
|
procedure _console_increment_y();
|
||||||
@ -24,6 +55,10 @@ procedure _console_newline();
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TConsoleProperties = record
|
||||||
|
Default_Attribute : Char;
|
||||||
|
end;
|
||||||
|
|
||||||
TCharacter = bitpacked record
|
TCharacter = bitpacked record
|
||||||
Character : Char;
|
Character : Char;
|
||||||
Attributes : Char;
|
Attributes : Char;
|
||||||
@ -42,12 +77,14 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
|
Console_Properties : TConsoleProperties;
|
||||||
Console_Memory : PVideoMemory = PVideoMemory($b8000);
|
Console_Memory : PVideoMemory = PVideoMemory($b8000);
|
||||||
Console_Matrix : P2DVideoMemory = P2DVideoMemory($b8000);
|
Console_Matrix : P2DVideoMemory = P2DVideoMemory($b8000);
|
||||||
Console_Cursor : TCoord;
|
Console_Cursor : TCoord;
|
||||||
|
|
||||||
procedure console_init(); [public, alias: 'console_init'];
|
procedure console_init(); [public, alias: 'console_init'];
|
||||||
Begin
|
Begin
|
||||||
|
Console_Properties.Default_Attribute:= console_combinecolors(White, Black);
|
||||||
console_clear();
|
console_clear();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -58,34 +95,79 @@ var
|
|||||||
begin
|
begin
|
||||||
for x:=0 to 79 do begin
|
for x:=0 to 79 do begin
|
||||||
for y:=0 to 24 do begin
|
for y:=0 to 24 do begin
|
||||||
Console_Matrix^[y][x].Character:=#0;
|
Console_Matrix^[y][x].Character:= #0;
|
||||||
Console_Matrix^[y][x].Attributes:=#7;
|
Console_Matrix^[y][x].Attributes:= Console_Properties.Default_Attribute;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Console_Cursor.X:= 0;
|
Console_Cursor.X:= 0;
|
||||||
Console_Cursor.Y:= 0;
|
Console_Cursor.Y:= 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure console_writechar(character: char; attributes: char); [public, alias: 'console_writechar'];
|
procedure console_setdefaultattribute(attribute: char); [public, alias: 'console_setdefaultattribute'];
|
||||||
|
begin
|
||||||
|
Console_Properties.Default_Attribute:= attribute;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writechar(character: char); [public, alias: 'console_writechar'];
|
||||||
|
begin
|
||||||
|
console_writecharex(character, Console_Properties.Default_Attribute);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writestring(str: PChar); [public, alias: 'console_writestring'];
|
||||||
|
begin
|
||||||
|
console_writestringex(str, Console_Properties.Default_Attribute);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writeint(i: Integer); [public, alias: 'console_writeint'];
|
||||||
|
begin
|
||||||
|
console_writeintex(i, Console_Properties.Default_Attribute);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writeword(i: DWORD); [public, alias: 'console_writeword'];
|
||||||
|
begin
|
||||||
|
console_writewordex(i, Console_Properties.Default_Attribute);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writecharln(character: char); [public, alias: 'console_writecharln'];
|
||||||
|
begin
|
||||||
|
console_writecharlnex(character, Console_Properties.Default_Attribute);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writestringln(str: PChar); [public, alias: 'console_writestringln'];
|
||||||
|
begin
|
||||||
|
console_writestringlnex(str, Console_Properties.Default_Attribute);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writeintln(i: Integer); [public, alias: 'console_writeintln'];
|
||||||
|
begin
|
||||||
|
console_writeintlnex(i, Console_Properties.Default_Attribute);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writewordln(i: DWORD); [public, alias: 'console_writewordln'];
|
||||||
|
begin
|
||||||
|
console_writewordlnex(i, Console_Properties.Default_Attribute);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure console_writecharex(character: char; attributes: char); [public, alias: 'console_writecharex'];
|
||||||
begin
|
begin
|
||||||
Console_Matrix^[Console_Cursor.Y][Console_Cursor.X].Character:= character;
|
Console_Matrix^[Console_Cursor.Y][Console_Cursor.X].Character:= character;
|
||||||
Console_Matrix^[Console_Cursor.Y][Console_Cursor.X].Attributes:= attributes;
|
Console_Matrix^[Console_Cursor.Y][Console_Cursor.X].Attributes:= attributes;
|
||||||
_console_safeincrement_x();
|
_console_safeincrement_x();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure console_writestring(str: PChar; attributes: char); [public, alias: 'console_writestring'];
|
procedure console_writestringex(str: PChar; attributes: char); [public, alias: 'console_writestringex'];
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
i:= 0;
|
i:= 0;
|
||||||
while (str[i] <> #0) do begin
|
while (str[i] <> #0) do begin
|
||||||
console_writechar(str[i], attributes);
|
console_writecharex(str[i], attributes);
|
||||||
i:=i+1;
|
i:=i+1;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure console_writeint(i: Integer; attributes : char); [public, alias: 'console_writeint'];
|
procedure console_writeintex(i: Integer; attributes : char); [public, alias: 'console_writeintex'];
|
||||||
var
|
var
|
||||||
buffer: array [0..11] of Char;
|
buffer: array [0..11] of Char;
|
||||||
str: PChar;
|
str: PChar;
|
||||||
@ -110,10 +192,10 @@ begin
|
|||||||
Dec(str);
|
Dec(str);
|
||||||
str^ := '-';
|
str^ := '-';
|
||||||
end;
|
end;
|
||||||
console_writestring(str, attributes);
|
console_writestringex(str, attributes);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure console_writedword(i: DWORD; attributes : char); [public, alias: 'console_writedword'];
|
procedure console_writewordex(i: DWORD; attributes : char); [public, alias: 'console_writedwordex'];
|
||||||
var
|
var
|
||||||
buffer: array [0..11] of Char;
|
buffer: array [0..11] of Char;
|
||||||
str: PChar;
|
str: PChar;
|
||||||
@ -128,37 +210,54 @@ begin
|
|||||||
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);
|
console_writestringex(@Buffer[0], attributes);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure console_writecharln(character: char; attributes: char); [public, alias: 'console_writecharln'];
|
procedure console_writecharlnex(character: char; attributes: char); [public, alias: 'console_writecharlnex'];
|
||||||
begin
|
begin
|
||||||
console_writechar(character, attributes);
|
console_writecharex(character, attributes);
|
||||||
_console_safeincrement_y();
|
_console_safeincrement_y();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure console_writestringln(str: PChar; attributes: char); [public, alias: 'console_writestringln'];
|
procedure console_writestringlnex(str: PChar; attributes: char); [public, alias: 'console_writestringlnex'];
|
||||||
begin
|
begin
|
||||||
console_writestring(str, attributes);
|
console_writestringex(str, attributes);
|
||||||
_console_safeincrement_y();
|
_console_safeincrement_y();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure console_writeintln(i: Integer; attributes: char); [public, alias: 'console_writeintln'];
|
procedure console_writeintlnex(i: Integer; attributes: char); [public, alias: 'console_writeintlnex'];
|
||||||
begin
|
begin
|
||||||
console_writeint(i, attributes);
|
console_writeintex(i, attributes);
|
||||||
_console_safeincrement_y();
|
_console_safeincrement_y();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure console_writedwordln(i: DWORD; attributes: char); [public, alias: 'console_writedwordln'];
|
procedure console_writewordlnex(i: DWORD; attributes: char); [public, alias: 'console_writewordlnex'];
|
||||||
begin
|
begin
|
||||||
console_writedword(i, attributes);
|
console_writewordex(i, attributes);
|
||||||
_console_safeincrement_y();
|
_console_safeincrement_y();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function console_combinecolors(Foreground, Background: TColor): char; [public, alias: 'console_combinecolors'];
|
||||||
|
begin
|
||||||
|
console_combinecolors:= char(((ord(Background) shl 4) or ord(Foreground)));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure _console_update_cursor(); [public, alias: '_console_update_cursor'];
|
||||||
|
begin
|
||||||
|
{asm
|
||||||
|
MOV AH, $02
|
||||||
|
MOV BH, $00
|
||||||
|
MOV DH, Console_Cursor.Y
|
||||||
|
MOV DL, Console_Cursor.X
|
||||||
|
INT $10
|
||||||
|
end; }
|
||||||
|
end;
|
||||||
|
|
||||||
procedure _console_increment_x(); [public, alias: '_console_increment_x'];
|
procedure _console_increment_x(); [public, alias: '_console_increment_x'];
|
||||||
begin
|
begin
|
||||||
Console_Cursor.X:= Console_Cursor.X+1;
|
Console_Cursor.X:= Console_Cursor.X+1;
|
||||||
If Console_Cursor.X > 79 then Console_Cursor.X:= 0;
|
If Console_Cursor.X > 79 then Console_Cursor.X:= 0;
|
||||||
|
_console_update_cursor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure _console_increment_y(); [public, alias: '_console_increment_y'];
|
procedure _console_increment_y(); [public, alias: '_console_increment_y'];
|
||||||
@ -168,6 +267,7 @@ begin
|
|||||||
_console_newline();
|
_console_newline();
|
||||||
Console_Cursor.Y:= 24;
|
Console_Cursor.Y:= 24;
|
||||||
end;
|
end;
|
||||||
|
_console_update_cursor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure _console_safeincrement_x(); [public, alias: '_console_safeincrement_x'];
|
procedure _console_safeincrement_x(); [public, alias: '_console_safeincrement_x'];
|
||||||
@ -176,6 +276,7 @@ begin
|
|||||||
If Console_Cursor.X > 79 then begin
|
If Console_Cursor.X > 79 then begin
|
||||||
_console_safeincrement_y();
|
_console_safeincrement_y();
|
||||||
end;
|
end;
|
||||||
|
_console_update_cursor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure _console_safeincrement_y(); [public, alias: '_console_safeincrement_y'];
|
procedure _console_safeincrement_y(); [public, alias: '_console_safeincrement_y'];
|
||||||
@ -186,6 +287,7 @@ begin
|
|||||||
Console_Cursor.Y:= 24;
|
Console_Cursor.Y:= 24;
|
||||||
end;
|
end;
|
||||||
Console_Cursor.X:= 0;
|
Console_Cursor.X:= 0;
|
||||||
|
_console_update_cursor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure _console_newline(); [public, alias: '_console_newline'];
|
procedure _console_newline(); [public, alias: '_console_newline'];
|
||||||
@ -202,6 +304,7 @@ begin
|
|||||||
Console_Matrix^[24][x].Character:= #0;
|
Console_Matrix^[24][x].Character:= #0;
|
||||||
Console_Matrix^[24][x].Attributes:= #7;
|
Console_Matrix^[24][x].Attributes:= #7;
|
||||||
end;
|
end;
|
||||||
|
_console_update_cursor
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -4,7 +4,8 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
multiboot,
|
multiboot,
|
||||||
console;
|
console,
|
||||||
|
util;
|
||||||
|
|
||||||
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall;
|
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall;
|
||||||
|
|
||||||
@ -13,28 +14,30 @@ 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
|
||||||
console_init();
|
console_init();
|
||||||
console_writestringln('Asuro Booting...', #7);
|
console_writestringln('Asuro Booting...');
|
||||||
if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin
|
if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin
|
||||||
console_writestringln('Multiboot Compliant Boot-Loader Needed!', #7);
|
console_setdefaultattribute(console_combinecolors(Red, Black));
|
||||||
console_writestringln('HALTING', #7);
|
console_writestringln('Multiboot Compliant Boot-Loader Needed!');
|
||||||
|
console_writestringln('HALTING');
|
||||||
asm
|
asm
|
||||||
cli
|
cli
|
||||||
hlt
|
hlt
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
console_writestringln('Asuro Booted Correctly!', #7);
|
console_setdefaultattribute(console_combinecolors(Green, Black));
|
||||||
console_writestring('Lower Memory = ', #7);
|
console_writestringln('Asuro Booted Correctly!');
|
||||||
console_writeint(mbinfo^.mem_lower, #7);
|
console_writestring('Lower Memory = ');
|
||||||
console_writestringln('KB', #7);
|
console_writeint(mbinfo^.mem_lower);
|
||||||
console_writestring('Higher Memory = ', #7);
|
console_writestringln('KB');
|
||||||
console_writeint(mbinfo^.mem_upper, #7);
|
console_writestring('Higher Memory = ');
|
||||||
console_writestringln('KB', #7);
|
console_writeint(mbinfo^.mem_upper);
|
||||||
console_writestring('Total Memory = ', #7);
|
console_writestringln('KB');
|
||||||
console_writeint(((mbinfo^.mem_upper + 1000) div 1024) +1, #7);
|
console_writestring('Total Memory = ');
|
||||||
console_writestringln('MB', #7);
|
console_writeint(((mbinfo^.mem_upper + 1000) div 1024) +1);
|
||||||
|
console_writestringln('MB');
|
||||||
asm
|
asm
|
||||||
@loop:
|
cli
|
||||||
jmp @loop
|
hlt
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
26
src/util.pas
Normal file
26
src/util.pas
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
unit util;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
function util_hi(b : byte) : byte;
|
||||||
|
function util_lo(b : byte) : byte;
|
||||||
|
function util_switchendian(b : byte) : byte;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
function util_hi(b : byte) : byte; [public, alias: 'util_hi'];
|
||||||
|
begin
|
||||||
|
util_hi:= (b AND $F0) SHR 4;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function util_lo(b : byte) : byte; [public, alias: 'util_lo'];
|
||||||
|
begin
|
||||||
|
util_lo:= b AND $0F;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function util_switchendian(b : byte) : byte; [public, alias: 'util_switchendian'];
|
||||||
|
begin
|
||||||
|
util_switchendian:= (util_lo(b) SHL 4) OR util_hi(b);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
Loading…
x
Reference in New Issue
Block a user