Keyboard Driver Started/Hex output added

- Added writehexex/writehexlnex/writehexln/writehex
- Started work on the keyboard driver, polling PS2 line for keystate.

git-svn-id: https://spexeah.com:8443/svn/Asuro@16 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
kieron
2017-02-13 16:35:36 +00:00
parent 11e85d0edb
commit a4ed035c93
15 changed files with 150 additions and 3 deletions

View File

@ -1,4 +1,4 @@
unit BIOS_DATA_AREA;
unit bios_data_area;
interface

View File

@ -4,7 +4,7 @@ interface
uses
util,
BIOS_DATA_AREA;
bios_data_area;
type
TColor = ( Black = $0,
@ -32,21 +32,25 @@ procedure writechar(character : char);
procedure writestring(str: PChar);
procedure writeint(i: Integer);
procedure writeword(i: DWORD);
procedure writehex(i: DWORD);
procedure writecharln(character : char);
procedure writestringln(str: PChar);
procedure writeintln(i: Integer);
procedure writewordln(i: DWORD);
procedure writehexln(i: DWORD);
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 writehexex(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);
procedure writehexlnex(i: DWORD; attributes : char);
function combinecolors(Foreground, Background : TColor) : char;
@ -159,6 +163,68 @@ begin
console._safeincrement_x();
end;
procedure writehexex(i : dword; attributes: char); [public, alias: 'console_writehexex'];
var
Hex : Array[0..7] of Byte;
Res : DWORD;
Rem : DWORD;
c : Integer;
begin
for c:=0 to 7 do begin
Hex[c]:= 255;
end;
c:=0;
Res:= i;
Rem:= Res mod 16;
while Res > 0 do begin
Hex[c]:= Rem;
Res:= Res div 16;
Rem:= Res mod 16;
c:=c+1;
end;
writestringex('0x', attributes);
for c:=7 downto 0 do begin
if Hex[c] <> 255 then begin
case Hex[c] of
0:writecharex('0', attributes);
1:writecharex('1', attributes);
2:writecharex('2', attributes);
3:writecharex('3', attributes);
4:writecharex('4', attributes);
5:writecharex('5', attributes);
6:writecharex('6', attributes);
7:writecharex('7', attributes);
8:writecharex('8', attributes);
9:writecharex('9', attributes);
10:writecharex('A', attributes);
11:writecharex('B', attributes);
12:writecharex('C', attributes);
13:writecharex('D', attributes);
14:writecharex('E', attributes);
15:writecharex('F', attributes);
else writecharex('?', attributes);
end;
end;
end;
end;
procedure writehex(i : dword); [public, alias: 'console_writehex'];
begin
console.writehexex(i, Console_Properties.Default_Attribute);
end;
procedure writehexlnex(i : dword; attributes : char);
begin
console.writehexex(i, attributes);
console._safeincrement_y();
end;
procedure writehexln(i : dword);
begin
writehexlnex(i, Console_Properties.Default_Attribute);
end;
procedure writestringex(str: PChar; attributes: char); [public, alias: 'console_writestringex'];
var
i : integer;

View File

@ -6,13 +6,17 @@ uses
multiboot,
util,
console,
BIOS_DATA_AREA;
bios_data_area,
keyboard;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall;
implementation
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall; [public, alias: 'kmain'];
var
c : byte;
begin
console.init();
console.writestringln('Booting Asuro...');
@ -37,6 +41,10 @@ begin
console.writeint(((mbinfo^.mem_upper + 1000) div 1024) +1);
console.writestringln('MB');
console.setdefaultattribute(console.combinecolors(lYellow, Black));
while true do begin
c:= keyboard.get_scancode;
console.writehexln(c);
end;
util.halt_and_catch_fire;
end;

31
src/keyboard.pas Normal file
View File

@ -0,0 +1,31 @@
unit keyboard;
{$ASMMODE intel}
interface
uses
util;
function get_scancode() : byte;
implementation
function get_scancode() : byte; [public, alias: 'get_scancode'];
var
c : byte;
begin
c:= 0;
while true do begin
if inb($60) <> c then begin
c:= inb($60);
if c > 0 then begin
get_scancode:= c;
exit;
end;
end;
end;
end;
end.

View File

@ -11,6 +11,9 @@ procedure outb(port : word; val : byte);
procedure outw(port : word; val : word);
procedure outl(port : word; val : longword);
procedure halt_and_catch_fire();
function inb(port : word) : byte;
function inw(port : word) : word;
function inl(port : word) : dword;
implementation
@ -76,4 +79,43 @@ begin
end;
end;
function inl(port : word) : dword; [public, alias: 'inl'];
begin
asm
PUSH EAX
PUSH EDX
MOV DX, port
IN EAX, DX
MOV inl, EAX
POP EDX
POP EAX
end;
end;
function inw(port : word) : word; [public, alias: 'inw'];
begin
asm
PUSH EAX
PUSH EDX
MOV DX, port
IN AX, DX
MOV inw, AX
POP EDX
POP EAX
end;
end;
function inb(port : word) : byte; [public, alias: 'inb'];
begin
asm
PUSH EAX
PUSH EDX
MOV DX, port
IN AL, DX
MOV inb, AL
POP EDX
POP EAX
end;
end;
end.