//----------------------------------------------------------------------------//
//Code By Ekrem KOCAK
//
[email protected]//Kirsehir 2006
//----------------------------------------------------------------------------//
program create_kernel;
{$APPTYPE CONSOLE}
const
Black = 0;
Blue = 1;
Green = 2;
Cyan = 3;
Red = 4;
Magenta = 5;
Brown = 6;
LightGray = 7;
DarkGray = 8;
LightBlue = 9;
LightGreen = 10;
LightCyan = 11;
LightRed = 12;
LightMagenta = 13;
Yellow = 14;
White = 15;
const
WIDTH = 80;
HEIGHT = 25 ;
type
Tmultiboot_hdr=packed record
magic:cardinal;
flags:cardinal;
checksum:cardinal;
header_addr:cardinal;
load_addr:cardinal;
load_end_addr:cardinal;
bss_end_addr:cardinal;
entry_addr:cardinal;
mode_type:cardinal;
width:cardinal;
height:cardinal;
depth:cardinal;
end;
//------------- Kernel Code Begin --------------------------
procedure main;stdcall;forward;
procedure loader;stdcall;
begin
asm
cli
call main
hlt
end;
end;
{$include Console.inc}
//Video bellek b?lgesini g?steren i?aret?i
function screen:pchar;stdcall;
begin
result:=pchar($B8000);
end;
function Key():PChar;stdcall;
begin
Result:='#01234567890*-#0qwertyuıopğü#0asdfghjklşi,#0zxcvbnmöç.'
end;
function MakeColor(FG, BG: Byte ):Char;
begin
result := Char(FG or BG shl 4);
end;
procedure Cls(); stdcall;
var
i: integer;
begin
i:=0;
while i< 80 * 25 * 2 do
begin
Screen[i]:=' ';
Screen[i+1]:= MakeColor(Blue,Blue);
inc(i,2);
end;
end;
procedure WriteChar(X, Y: integer; text:Char;Color:Byte); stdcall;
var
address: Word;
begin
address:= X*2 + Y * 160;
Screen[address]:= text;
Screen[address+1]:= MakeColor(Color,Blue);
end;
procedure WriteStr(X, Y: integer;Text : PCHAR; Color:Byte); stdcall;
var
address: Word;
i: integer;
begin
i:=0;
repeat
address:= X*2 + Y * 160;
Screen[address]:= (text[i]);
Screen[address+1]:= MakeColor(Color,Blue);
inc(x);
i:=i + 1;
until text[i] = #0
end;
function Keyboard():Integer;stdcall;
var
ScanCode :byte;
DScanCode:byte;
begin
while(true) do
begin
Scancode := ReadPortB($60);
if(ScanCode < 100) and (ScanCode <> dScanCode) then
begin
case ScanCode of
28:begin // ENTER
WriteStr(0,0,'ENTER',White);
end;
57:begin // SPACE
WriteStr(0,0,'SPACE',White);
end;
14:begin // BACKSPACE
WriteStr(0,0,'BACKSPACE',White);
end;
else
begin // CHAR
WriteChar(1,1,Key[ScanCode],White);
end;
end;
end; //if
dScanCode := ScanCode;
end; //while
end;
procedure Main(); stdcall;
var
str:string[15];
begin
str:='EKREM KOCAK';
Cls();
WriteChar(1,1,char($87),yellow);
WriteStr(5,5, 'ayhan',White);
Keyboard();
end;
procedure Loader_End(); begin end;
//------------- Kernel Code End --------------------------
var
multiboot_hdr:Tmultiboot_hdr;
size,fsize:cardinal;
buf,fnc:pointer;
image_base,image_size:integer;
entry_addr:integer;
f:file;
begin
assignfile(f,'kernel.bin');
rewrite(f,1);
//Project > Options... > Packages Tab > Runtime packages group box > Build witg runtime packages check box true
//Project > Options... > Linker Tab > Memory sizes group box > Image Base
image_base:=$00400000;
entry_addr:=cardinal(@loader)-cardinal(image_base);
size:=entry_addr-sizeof(multiboot_hdr);
fsize:=cardinal(@loader_end)-cardinal(@loader);
image_size:=size+$1000;
fillchar(multiboot_hdr,sizeof(multiboot_hdr),0);
multiboot_hdr.magic:=($1BADB002);
multiboot_hdr.flags:=(1 shl 16) ;
multiboot_hdr.checksum:=cardinal(-multiboot_hdr.magic-multiboot_hdr.flags);
multiboot_hdr.header_addr:=image_base;
multiboot_hdr.load_addr:=image_base;
multiboot_hdr.load_end_addr:=cardinal(image_base+image_size);
multiboot_hdr.bss_end_addr:=cardinal(image_base+image_size);
multiboot_hdr.entry_addr:=cardinal(image_base+entry_addr);
multiboot_hdr.mode_type:=0;
multiboot_hdr.width:=0;
multiboot_hdr.height:=0;
multiboot_hdr.depth:=0;
blockwrite(f,multiboot_hdr,sizeof(multiboot_hdr));
getmem(buf,size);
fillchar(buf^,size,0);
blockwrite(f,buf^,size);
freemem(buf);
fnc:=@loader;
getmem(buf,$1000-fsize);
fillchar(buf^,$1000-fsize,0);
blockwrite(f,fnc^,fsize);
blockwrite(f,buf^,$1000-fsize);
freemem(buf);
closefile(f);
end.