diff --git a/src/console.pas b/src/console.pas index a9d3cdc0..cb619c82 100644 --- a/src/console.pas +++ b/src/console.pas @@ -45,8 +45,16 @@ type EVENT_FOCUS, EVENT_LOSE_FOCUS ); - - + { Properties pertaining to the raw screen matrix. } + TConsoleProperties = record + Default_Attribute : uint32; //< Attribute (Colors) to use when no override defined. + Width : uint32; + Height : uint32; + BitsPerPixel : uint8; + MAX_CELL_X : uint32; + MAX_CELL_Y : uint32; + end; + PConsoleProperties = ^TConsoleProperties; {! Default Buffer Specific } @@ -808,20 +816,20 @@ procedure setWindowColors(colors : uint32); } function getWindowColorPtr : puint32; +function getMaxCellW : uint32; +function getMaxCellH : uint32; +function getConsoleProperties : PConsoleProperties; + const MAX_WINDOWS = 255; //< Maximum number of Windows open. DefaultWND = 0; //< The Window assigned for output when no Window is specified. (Default). implementation + uses lmemorymanager, strings, keyboard, serial, terminal; type - { Properties pertaining to the raw screen matrix. } - TConsoleProperties = record - Default_Attribute : uint32; //< Attribute (Colors) to use when no override defined. - end; - { Unrasterized representation of a character. } TCharacter = bitpacked record Character : Char; //< ASCII Character @@ -844,7 +852,6 @@ type { Pointer to 2D Unrasterized Matrix } P2DVideoMemory = ^T2DVideoMemory; - TMouseCoord = record X : sint32; Y : sint32; @@ -937,6 +944,21 @@ var MouseCursorEnabled : Boolean = true; OpenTerminal : Boolean = false; +function getMaxCellW : uint32; +begin + getMaxCellW:= Console_Properties.MAX_CELL_X; +end; + +function getMaxCellH : uint32; +begin + getMaxCellH:= Console_Properties.MAX_CELL_Y; +end; + +function getConsoleProperties : PConsoleProperties; +begin + getConsoleProperties:= PConsoleProperties(@Console_Properties); +end; + function getWindowColorPtr : puint32; begin getWindowColorPtr:= @Window_Border.Attributes; @@ -1092,8 +1114,8 @@ var begin Window:= WindowManager.Windows[WND]; if Window <> nil then begin - while x > 159 do dec(x); - while y > 63 do dec(y); + while x > Console_Properties.MAX_CELL_X-1 do dec(x); + while y > Console_Properties.MAX_CELL_Y-1 do dec(y); Window^.Cursor.x:= x; Window^.Cursor.y:= y; end; @@ -1112,19 +1134,19 @@ begin if Window^.Border then begin if nx < 2 then nx:= 2; if ny < 1 then ny:= 1; - while (nx + Window^.WND_W + 2) > 159 do begin + while (nx + Window^.WND_W + 2) > Console_Properties.MAX_CELL_X do begin dec(nx); end; - while (ny + Window^.WND_H + 1) > 63 do begin + while (ny + Window^.WND_H + 1) > Console_Properties.MAX_CELL_Y do begin dec(ny); end; end else begin if nx < 0 then nx:= 0; if ny < 0 then ny:= 0; - while (nx + Window^.WND_W) > 159 do begin + while (nx + Window^.WND_W) > Console_Properties.MAX_CELL_X do begin dec(nx); end; - while (ny + Window^.WND_H) > 63 do begin + while (ny + Window^.WND_H) > Console_Properties.MAX_CELL_Y do begin dec(ny); end; end; @@ -1198,6 +1220,9 @@ begin end; end; +//If Packet.x_sign then Packet.x_movement:= sint16(Packet.x_movement OR $FF00); + //If Packet.y_sign then Packet.y_movement:= sint16(Packet.y_movement OR $FF00); + procedure forceQuitAll; var i : uint32; @@ -1288,8 +1313,8 @@ begin mouse_dirt.BottomRight.y:= (MY div 16) + 2; if mouse_dirt.TopLeft.x < 0 then mouse_dirt.TopLeft.x:= 0; if mouse_dirt.TopLeft.y < 0 then mouse_dirt.TopLeft.y:= 0; - if mouse_dirt.BottomRight.x > 159 then mouse_dirt.BottomRight.x:= 159; - if mouse_dirt.BottomRight.y > 63 then mouse_dirt.BottomRight.y:= 63; + if mouse_dirt.BottomRight.x > Console_Properties.MAX_CELL_X then mouse_dirt.BottomRight.x:= Console_Properties.MAX_CELL_X; + if mouse_dirt.BottomRight.y > Console_Properties.MAX_CELL_Y then mouse_dirt.BottomRight.y:= Console_Properties.MAX_CELL_Y; MouseDrawActive:= false; end; @@ -1306,8 +1331,8 @@ begin end; drawMouse; end; - for y:=0 to 63 do begin - for x:=0 to 159 do begin + for y:=0 to Console_Properties.MAX_CELL_Y do begin + for x:=0 to Console_Properties.MAX_CELL_X do begin if (Console_Matrix[y][x].character <> Console_Real[y][x].character) or (Console_Matrix[y][x].attributes <> Console_Real[y][x].attributes) then begin OutputChar(Console_Matrix[y][x].Character, x, y, Console_Matrix[y][x].Attributes SHR 16, Console_Matrix[y][x].Attributes AND $FFFF); Console_Real[y][x]:= Console_Matrix[y][x]; @@ -1341,8 +1366,8 @@ begin end; { Clear the Console_Matrix } - for y:=0 to 63 do begin - for x:=0 to 159 do begin + for y:=0 to Console_Properties.MAX_CELL_Y do begin + for x:=0 to Console_Properties.MAX_CELL_X do begin Console_Matrix[y][x]:= Default_Char; end; end; @@ -1392,9 +1417,9 @@ begin end; end; for y:=WindowManager.Windows[WindowManager.Z_Order[w]]^.WND_Y to WindowManager.Windows[WindowManager.Z_Order[w]]^.WND_Y + WindowManager.Windows[WindowManager.Z_Order[w]]^.WND_H do begin - if y > 63 then break; + if y > Console_Properties.MAX_CELL_Y then break; for x:=WindowManager.Windows[WindowManager.Z_Order[w]]^.WND_X to WindowManager.Windows[WindowManager.Z_Order[w]]^.WND_X + WindowManager.Windows[WindowManager.Z_Order[w]]^.WND_W do begin - if x > 159 then break; + if x > Console_Properties.MAX_CELL_X then break; Console_Matrix[y][x]:= WindowManager.Windows[WindowManager.Z_Order[w]]^.buffer[y - WindowManager.Windows[WindowManager.Z_Order[w]]^.WND_Y][x - WindowManager.Windows[WindowManager.Z_Order[w]]^.WND_X]; WindowTitleMask[y][x]:= 0; WindowMask[y][x]:= WindowManager.Z_Order[w]; @@ -1537,8 +1562,8 @@ begin WND^.WND_NAME:= 'Asuro'; WND^.WND_X:= 0; WND^.WND_Y:= 0; - WND^.WND_W:= 159; - WND^.WND_H:= 63; + WND^.WND_W:= Console_Properties.MAX_CELL_X; + WND^.WND_H:= Console_Properties.MAX_CELL_Y; WND^.Cursor.x:= 0; WND^.Cursor.y:= 0; WND^.visible:= true; @@ -1567,7 +1592,7 @@ var begin if not ready then exit; dest:= puint16(multibootinfo^.framebuffer_addr); - dest:= dest + (y * 1280) + x; + dest:= dest + (y * Console_Properties.Width) + x; getPixel:= dest^; end; @@ -1578,7 +1603,7 @@ var begin if not ready then exit; dest:= puint16(multibootinfo^.framebuffer_addr); - dest:= dest + (y * 1280) + x; + dest:= dest + (y * Console_Properties.Width) + x; dest^:= color; end; @@ -1590,7 +1615,7 @@ var begin if not ready then exit; dest:= puint16(multibootinfo^.framebuffer_addr); - dest:= dest + (y * 1280) + x; + dest:= dest + (y * Console_Properties.Width) + x; dest32:= puint32(dest); getPixel32:= dest32[0]; end; @@ -1603,7 +1628,7 @@ var begin if not ready then exit; dest:= puint16(multibootinfo^.framebuffer_addr); - dest:= dest + (y * 1280) + x; + dest:= dest + (y * Console_Properties.Width) + x; dest32:= puint32(dest); dest32[0]:= pixel; end; @@ -1616,7 +1641,7 @@ var begin if not ready then exit; dest:= puint16(multibootinfo^.framebuffer_addr); - dest:= dest + (y * 1280) + x; + dest:= dest + (y * Console_Properties.Width) + x; dest64:= puint64(dest); getPixel64:= dest64^; end; @@ -1629,7 +1654,7 @@ var begin if not ready then exit; dest:= puint16(multibootinfo^.framebuffer_addr); - dest:= dest + (y * 1280) + x; + dest:= dest + (y * Console_Properties.Width) + x; dest64:= puint64(dest); dest64^:= pixel; end; @@ -1648,13 +1673,13 @@ begin mask:= puint32(@Std_Mask[uint32(c) * (16 * 8)]); dest:= puint16(multibootinfo^.framebuffer_addr); //dest:= puint16(windowmanager.getBuffer(0)); - dest:= dest + (y * 1280) + x; + dest:= dest + (y * Console_Properties.Width) + x; dest32:= puint32(dest); for i:=0 to 15 do begin - dest32[(i*640)+0]:= (dest32[(i*640)+0] AND NOT(mask[(i*4)+0])) OR (fgcolor32 AND mask[(i*4)+0]); - dest32[(i*640)+1]:= (dest32[(i*640)+1] AND NOT(mask[(i*4)+1])) OR (fgcolor32 AND mask[(i*4)+1]); - dest32[(i*640)+2]:= (dest32[(i*640)+2] AND NOT(mask[(i*4)+2])) OR (fgcolor32 AND mask[(i*4)+2]); - dest32[(i*640)+3]:= (dest32[(i*640)+3] AND NOT(mask[(i*4)+3])) OR (fgcolor32 AND mask[(i*4)+3]); + dest32[(i*(Console_Properties.Width div 2))+0]:= (dest32[(i*(Console_Properties.Width div 2))+0] AND NOT(mask[(i*4)+0])) OR (fgcolor32 AND mask[(i*4)+0]); + dest32[(i*(Console_Properties.Width div 2))+1]:= (dest32[(i*(Console_Properties.Width div 2))+1] AND NOT(mask[(i*4)+1])) OR (fgcolor32 AND mask[(i*4)+1]); + dest32[(i*(Console_Properties.Width div 2))+2]:= (dest32[(i*(Console_Properties.Width div 2))+2] AND NOT(mask[(i*4)+2])) OR (fgcolor32 AND mask[(i*4)+2]); + dest32[(i*(Console_Properties.Width div 2))+3]:= (dest32[(i*(Console_Properties.Width div 2))+3] AND NOT(mask[(i*4)+3])) OR (fgcolor32 AND mask[(i*4)+3]); end; //windowmanager.redraw; end; @@ -1673,13 +1698,13 @@ begin mask:= puint32(@Std_Mask[uint32(c) * (16 * 8)]); dest:= puint16(multibootinfo^.framebuffer_addr); //dest:= puint16(windowmanager.getBuffer(0)); - dest:= dest + (y*(1280 * 16)) + (x * 8); + dest:= dest + (y*(Console_Properties.Width * 16)) + (x * 8); dest32:= puint32(dest); for i:=0 to 15 do begin - dest32[(i*640)+0]:= (dest32[(i*640)+0] AND NOT(mask[(i*4)+0])) OR (fgcolor32 AND mask[(i*4)+0]); - dest32[(i*640)+1]:= (dest32[(i*640)+1] AND NOT(mask[(i*4)+1])) OR (fgcolor32 AND mask[(i*4)+1]); - dest32[(i*640)+2]:= (dest32[(i*640)+2] AND NOT(mask[(i*4)+2])) OR (fgcolor32 AND mask[(i*4)+2]); - dest32[(i*640)+3]:= (dest32[(i*640)+3] AND NOT(mask[(i*4)+3])) OR (fgcolor32 AND mask[(i*4)+3]); + dest32[(i*(Console_Properties.Width div 2))+0]:= (dest32[(i*(Console_Properties.Width div 2))+0] AND NOT(mask[(i*4)+0])) OR (fgcolor32 AND mask[(i*4)+0]); + dest32[(i*(Console_Properties.Width div 2))+1]:= (dest32[(i*(Console_Properties.Width div 2))+1] AND NOT(mask[(i*4)+1])) OR (fgcolor32 AND mask[(i*4)+1]); + dest32[(i*(Console_Properties.Width div 2))+2]:= (dest32[(i*(Console_Properties.Width div 2))+2] AND NOT(mask[(i*4)+2])) OR (fgcolor32 AND mask[(i*4)+2]); + dest32[(i*(Console_Properties.Width div 2))+3]:= (dest32[(i*(Console_Properties.Width div 2))+3] AND NOT(mask[(i*4)+3])) OR (fgcolor32 AND mask[(i*4)+3]); end; //windowmanager.redraw; end; @@ -1699,13 +1724,13 @@ begin mask:= puint32(@Std_Mask[uint32(c) * (16 * 8)]); dest:= puint16(multibootinfo^.framebuffer_addr); //dest:= puint16(windowmanager.getBuffer(0)); - dest:= dest + (y*(1280 * 16)) + (x * 8); + dest:= dest + (y*(Console_Properties.Width * 16)) + (x * 8); dest32:= puint32(dest); for i:=0 to 15 do begin - dest32[(i*640)+0]:= (bgcolor32 AND NOT(mask[(i*4)+0])) OR (fgcolor32 AND mask[(i*4)+0]); - dest32[(i*640)+1]:= (bgcolor32 AND NOT(mask[(i*4)+1])) OR (fgcolor32 AND mask[(i*4)+1]); - dest32[(i*640)+2]:= (bgcolor32 AND NOT(mask[(i*4)+2])) OR (fgcolor32 AND mask[(i*4)+2]); - dest32[(i*640)+3]:= (bgcolor32 AND NOT(mask[(i*4)+3])) OR (fgcolor32 AND mask[(i*4)+3]); + dest32[(i*(Console_Properties.Width div 2))+0]:= (bgcolor32 AND NOT(mask[(i*4)+0])) OR (fgcolor32 AND mask[(i*4)+0]); + dest32[(i*(Console_Properties.Width div 2))+1]:= (bgcolor32 AND NOT(mask[(i*4)+1])) OR (fgcolor32 AND mask[(i*4)+1]); + dest32[(i*(Console_Properties.Width div 2))+2]:= (bgcolor32 AND NOT(mask[(i*4)+2])) OR (fgcolor32 AND mask[(i*4)+2]); + dest32[(i*(Console_Properties.Width div 2))+3]:= (bgcolor32 AND NOT(mask[(i*4)+3])) OR (fgcolor32 AND mask[(i*4)+3]); end; //windowmanager.redraw; end; @@ -1738,6 +1763,14 @@ var Begin fb:= puint32(uint32(multibootinfo^.framebuffer_addr)); + Console_Properties.Width:= multibootinfo^.framebuffer_width; + Console_Properties.Height:= multibootinfo^.framebuffer_height; + Console_Properties.BitsPerPixel:= multibootinfo^.framebuffer_bpp; + Console_Properties.MAX_CELL_X:= (Console_Properties.Width div 8) - 1; + Console_Properties.MAX_CELL_Y:= (Console_Properties.Height div 16) - 1; + If Console_Properties.BitsPerPixel <> 16 then while true do begin + + end; kpalloc(uint32(fb)); keyboard.hook(@keyhook); initWindows; @@ -1754,8 +1787,8 @@ var begin if WindowManager.Windows[DefaultWND] <> nil then begin - for y:=0 to 63 do begin - for x:=0 to 159 do begin + for y:=0 to Console_Properties.MAX_CELL_Y do begin + for x:=0 to Console_Properties.MAX_CELL_X do begin WindowManager.Windows[DefaultWND]^.Buffer[y][x].Character:= ' '; WindowManager.Windows[DefaultWND]^.Buffer[y][x].Attributes:= Console_Properties.Default_Attribute; WindowManager.Windows[DefaultWND]^.row_dirty[y]:= true; @@ -2211,8 +2244,8 @@ var begin if WindowManager.Windows[WND] <> nil then begin - for y:=0 to 63 do begin - for x:=0 to 159 do begin + for y:=0 to Console_Properties.MAX_CELL_Y do begin + for x:=0 to Console_Properties.MAX_CELL_X do begin WindowManager.Windows[WND]^.Buffer[y][x].Character:= ' '; WindowManager.Windows[WND]^.Buffer[y][x].Attributes:= Console_Properties.Default_Attribute; WindowManager.Windows[WND]^.row_dirty[y]:= true; @@ -2235,8 +2268,8 @@ var begin if WindowManager.Windows[WND] <> nil then begin - for y:=0 to 63 do begin - for x:=0 to 159 do begin + for y:=0 to Console_Properties.MAX_CELL_Y do begin + for x:=0 to Console_Properties.MAX_CELL_X do begin WindowManager.Windows[WND]^.Buffer[y][x].Character:= ' '; WindowManager.Windows[WND]^.Buffer[y][x].Attributes:= attributes; WindowManager.Windows[WND]^.row_dirty[y]:= true; diff --git a/src/driver/hid/mouse.pas b/src/driver/hid/mouse.pas index e306aa03..2041cc48 100644 --- a/src/driver/hid/mouse.pas +++ b/src/driver/hid/mouse.pas @@ -147,15 +147,17 @@ begin Packet.LMB_Down:= (f AND %00000001) = %00000001; Packet.x_overflow:= (f AND $40) = $40; Packet.y_overflow:= (f AND $80) = $80; - Packet.x_movement:= Mouse_Byte[1] - ((f SHL 4) AND $100); - Packet.y_movement:= Mouse_Byte[2] - ((f SHL 3) AND $100); + Packet.x_movement:= Mouse_Byte[1];// - ((f SHL 4) AND $100); + Packet.y_movement:= Mouse_Byte[2];// - ((f SHL 3) AND $100); + If Packet.x_sign then Packet.x_movement:= sint16(Packet.x_movement OR $FF00); + If Packet.y_sign then Packet.y_movement:= sint16(Packet.y_movement OR $FF00); if not(Packet.x_overflow) and not(Packet.y_overflow) then begin Current.x:= Current.x + Packet.x_movement; Current.y:= Current.y - Packet.y_movement; if Current.x < 0 then Current.x:= 0; if Current.y < 0 then Current.y:= 0; - if Current.x > 1272 then Current.x:= 1272; - if Current.y > 1015 then Current.y:= 1015; + if Current.x > (Console.getConsoleProperties^.Width-8) then Current.x:= (Console.getConsoleProperties^.Width-8); + if Current.y > (Console.getConsoleProperties^.Height-8) then Current.y:= (Console.getConsoleProperties^.Height-8); end; Cycle:= 0; if Packet.LMB_Down then begin diff --git a/src/include/hashmap.pas b/src/include/hashmap.pas new file mode 100644 index 00000000..37491cbe --- /dev/null +++ b/src/include/hashmap.pas @@ -0,0 +1,212 @@ +unit hashmap; + +interface + +uses + md5, util, strings, lmemorymanager, console; + +type + DPHashItem = ^PHashItem; + PHashItem = ^THashItem; + THashItem = record + Next : PHashItem; + Key : pchar; + Data : void; + end; + PHashMap = ^THashMap; + THashMap = record + Size : uint32; + Table : DPHashItem; + end; + +function new(size : uint32) : PHashMap; +procedure add(map : PHashMap; key : pchar; value : void); +function get(map : PHashMap; key : pchar) : void; +procedure delete(map : PHashMap; key : pchar); +procedure deleteAndFree(map : PHashMap; key : pchar); +procedure printMap(map : PHashMap); + +implementation + +function hashIndex(size : uint32; key : pchar) : uint32; +var + KeyLength : uint32; + Hash : PMD5Digest; + Hash128 : puint128; + Hash32 : uint32; + +begin + KeyLength:= StringSize(key); + Hash:= MD5Buffer(puint8(key), KeyLength); + Hash128:= puint128(Hash); + Hash32:= MD5To32(Hash128); + hashIndex:= Hash32 mod size; + kfree(void(Hash)); +end; + +function newItem : PHashItem; +begin + newItem:= PHashItem(kalloc(sizeof(THashItem))); + newItem^.Next:= nil; + newItem^.Key:= nil; + newItem^.Data:= nil; +end; + +procedure add(map : PHashMap; key : pchar; value : void); +var + Idx : uint32; + Item : PHashItem; + nItem : PHashItem; + +begin + if (map <> nil) and (key <> nil) then begin + Idx:= hashIndex(map^.size, key); + if map^.Table[Idx] = nil then begin + Item:= newItem; + Item^.Next:= nil; + map^.Table[Idx]:= Item; + end else begin + //Collision + Item:= map^.Table[Idx]; + while not StringEquals(Item^.key, key) do begin + if Item^.Next <> nil then begin + Item:= Item^.Next; + end else begin + nItem:= newItem(); + Item^.Next:= nItem; + Item:= nItem; + Item^.Next:= nil; + break; + end; + end; + end; + if Item^.Key = nil then Item^.Key:= stringCopy(key); + Item^.Data:= value; + end; +end; + +function get(map : PHashMap; key : pchar) : void; +var + Idx : uint32; + Item : PHashItem; + +begin + get:= nil; + if (map <> nil) and (key <> nil) then begin + Idx:= hashIndex(map^.size, key); + Item:= map^.table[Idx]; + if Item = nil then exit; + while not StringEquals(Item^.key, key) do begin + Item:= Item^.Next; + if Item = nil then break; + end; + if Item <> nil then get:= Item^.Data; + end; +end; + +function new(size : uint32) : PHashMap; +var + Map : PHashMap; + i : uint32; + +begin + Map:= PHashMap(kalloc(sizeof(THashMap))); + Map^.size:= size; + Map^.Table:= DPHashItem(Kalloc(sizeof(PHashItem) * Size)); + for i:=0 to size-1 do begin + Map^.Table[i]:= nil; + end; + new:= Map; +end; + +procedure deleteAndFree(map : PHashMap; key : pchar); +var + Idx : uint32; + Item : PHashItem; + Prev : PHashItem; + +begin + Prev:= nil; + if (map <> nil) and (key <> nil) then begin + Idx:= hashIndex(map^.size, key); + Item:= map^.table[Idx]; + while not StringEquals(Item^.key, key) do begin + Prev:= Item; + Item:= Item^.Next; + if Item = nil then break; + end; + if Item <> nil then begin + If Prev <> nil then Prev^.Next:= Item^.Next; + If Prev = nil then begin + if Item^.Next <> nil then + map^.table[Idx]:= Item^.Next + else + map^.table[Idx]:= nil; + end; + kfree(void(Item^.Key)); + kfree(void(Item^.Data)); + kfree(void(Item)); + end; + end; +end; + +procedure delete(map : PHashMap; key : pchar); +var + Idx : uint32; + Item : PHashItem; + Prev : PHashItem; + +begin + Prev:= nil; + if (map <> nil) and (key <> nil) then begin + Idx:= hashIndex(map^.size, key); + Item:= map^.table[Idx]; + while not StringEquals(Item^.key, key) do begin + Prev:= Item; + Item:= Item^.Next; + if Item = nil then break; + end; + if Item <> nil then begin + If Prev <> nil then Prev^.Next:= Item^.Next; + If Prev = nil then begin + if Item^.Next <> nil then + map^.table[Idx]:= Item^.Next + else + map^.table[Idx]:= nil; + end; + kfree(void(Item^.Key)); + kfree(void(Item)); + end; + end; +end; + +procedure printMap(map : PHashMap); +var + i,c : uint32; + item : PHashItem; + +begin + for i:=0 to map^.Size-1 do begin + if map^.table[i] <> nil then begin + writestring('Map['); + writeint(i); + writestring(']->(0)="'); + writestring(map^.table[i]^.key); + writestring('"'); + item:= map^.table[i]^.next; + c:=1; + while item <> nil do begin + writestring('->('); + writeint(c); + writestring(')="'); + writestring(item^.key); + writestring('"'); + inc(c); + item:= item^.next; + end; + writestringln(' '); + end; + end; +end; + +end. \ No newline at end of file diff --git a/src/include/md5.pas b/src/include/md5.pas index e3b92fac..21dcd902 100644 --- a/src/include/md5.pas +++ b/src/include/md5.pas @@ -39,6 +39,8 @@ procedure MD5Update(context : PMD5Context; buffer : PuInt8; bufferLen : uInt32); function MD5Final(context : PMD5Context) : PMD5Digest; function MD5Buffer(buffer : PuInt8; bufferLen : uInt32) : PMD5Digest; +function MD5To32(Input : PuInt128) : uint32; + implementation procedure Invert(Source : PuInt8; Dest : PuInt32; Count : uInt32); @@ -234,4 +236,13 @@ begin kfree(void(context)); end; +function MD5To32(Input : PuInt128) : uint32; +var + MD5To64 : uint64; + i : uint8; + +begin + MD5To32:= Input^.DWords[0] xor Input^.DWords[1] xor Input^.DWords[2] xor Input^.DWords[3]; +end; + end. \ No newline at end of file diff --git a/src/include/multiboot.pas b/src/include/multiboot.pas index bfd1e11d..777542a0 100644 --- a/src/include/multiboot.pas +++ b/src/include/multiboot.pas @@ -43,7 +43,7 @@ type vbe_interface_seg : uint16; vbe_interface_off : uint16; vbe_interface_len : uint16; - framebuffer_addr : uint64; + framebuffer_addr : uint64; framebuffer_pitch : uint32; framebuffer_width : uint32; framebuffer_height: uint32; diff --git a/src/include/system.pas b/src/include/system.pas index 0a2d980a..e08cae77 100644 --- a/src/include/system.pas +++ b/src/include/system.pas @@ -28,6 +28,22 @@ type uInt16 = WORD; uInt32 = DWORD; uInt64 = QWORD; + uint128 = packed record + case Integer of + 0: ( + Hi : uint64; + Lo : uint64; + ); + 1: ( + DWords : array [0..3] of uint32; + ); + 2: ( + Words : array [0..7] of uint16; + ); + 3: ( + Bytes : array [0..15] of uint8; + ); + end; sInt8 = shortint; sInt16 = smallint; @@ -42,6 +58,7 @@ type PuInt16 = ^uInt16; PuInt32 = ^uInt32; PuInt64 = ^uInt64; + PuInt128 = ^uint128; PsInt8 = ^sInt8; PsInt16 = ^sInt16; diff --git a/src/kernel.pas b/src/kernel.pas index c9f17e77..1621420d 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -40,7 +40,8 @@ uses md5, base64, rand, - terminal; + terminal, + hashmap; procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; @@ -77,6 +78,20 @@ begin pop_trace; end; +procedure myUserLandFunction; +var + i : uint32; + +begin + i:=0; + while true do begin + i:=i+1; + asm + MOV EAX, i + end; + end; +end; + procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; [public, alias: 'kmain']; var c : uint8; @@ -92,6 +107,9 @@ var test : puint8; fb : puint16; l : PLinkedListBase; + ulf : pointer; + + HM : PHashMap; begin { Serial Init } @@ -223,6 +241,67 @@ begin rand.srand((getDateTime.Seconds SHR 24) OR (getDateTime.Minutes SHR 16) OR (getDateTime.Hours SHR 8) OR (getDateTime.Day)); tracer.push_trace('kmain.TICK'); + + + HM:= hashmap.new(10000); + hashmap.add(HM, 'testificate', void(1)); + hashmap.add(HM, 'asuro', void(10)); + hashmap.add(HM, 'myfirstos', void(100)); + hashmap.add(HM, 'potato', void(1000)); + hashmap.add(HM, 'cellary', void(10000)); + hashmap.add(HM, 'gigglewiggle', void(100000)); + hashmap.add(HM, 'cuntwank', void(20)); + hashmap.add(HM, 'topkekness', void(200)); + hashmap.add(HM, 'fluffybanana', void(2000)); + hashmap.add(HM, 'ilikecheese', void(20000)); + hashmap.add(HM, 'Tracer', void(200000)); + hashmap.add(HM, 'Genji', void(2000000)); + hashmap.add(HM, 'Winston', void(30)); + hashmap.add(HM, 'D.Va', void(300)); + hashmap.add(HM, 'Soldier76', void(3000)); + hashmap.add(HM, 'Brigitte', void(3000)); + hashmap.add(HM, 'Pharah', void(30000)); + hashmap.add(HM, 'Reinhardt', void(300000)); + hashmap.add(HM, 'Orisa', void(30000000)); + hashmap.add(HM, 'Mercy', void(3000000000)); + hashmap.add(HM, 'Hamster', void(40)); + hashmap.add(HM, 'Ana', void(400)); + hashmap.add(HM, 'Lucio', void(4000)); + hashmap.add(HM, 'Mei', void(40000)); + hashmap.add(HM, 'Teemo', void(400000)); + hashmap.add(HM, 'Vayne', void(4000000)); + hashmap.add(HM, 'Munzo', void(40000000)); + hashmap.add(HM, 'fasafafsdfsd', void(50)); + hashmap.add(HM, 'Zarfdasafdsfadsfdsafadsfdasya', void(500)); + hashmap.add(HM, 'Zafadfadsfadsfadsfdsarya', void(5000)); + hashmap.add(HM, 'afdsafdadfsfda', void(500000)); + hashmap.add(HM, '4rrelkjhrewrewkoy', void(5000000)); + hashmap.add(HM, 'Laptop', void(50000000)); + hashmap.add(HM, 'Salmon', void(500000000)); + hashmap.add(HM, 'OnionBurger', void(60)); + + hashmap.printmap(HM); + + writeintln(uint32(hashmap.get(HM, 'Ana'))); + + // Testing getting into userspace + // ulf:= Pointer(@myUserLandFunction); + // asm + // MOV AX, $23 + // MOV DS, AX + // MOV ES, AX + // MOV FS, AX + // MOV GS, AX + + // MOV EAX, ESP + // PUSH $23 + // PUSH EAX + // PUSHF + // PUSH $1B + // PUSH ulf; + // iret; + // end; + while true do begin tracer.push_trace('kmain.RedrawWindows'); console.redrawWindows; diff --git a/src/prog/md5sum.pas b/src/prog/md5sum.pas index 2d8bbdb2..496ef839 100644 --- a/src/prog/md5sum.pas +++ b/src/prog/md5sum.pas @@ -20,6 +20,11 @@ var wordlen : uint32; MD5_Hash : PMD5Digest; i : uint32; + MD5_128 : puint128; + Result : uint64; + Result32 : uint32; + Modulo : uint64; + begin md5word:= getParam(0, Params); diff --git a/src/prog/shell.pas b/src/prog/shell.pas index cd9a41ee..c5a3e60f 100644 --- a/src/prog/shell.pas +++ b/src/prog/shell.pas @@ -63,7 +63,7 @@ begin end; end; - console.setCursorPosWND(150, 0, TaskBarHandle); + console.setCursorPosWND(Console.getMaxCellW() - 9, 0, TaskBarHandle); if DateTime.Hours < 10 then writeIntExWND(0, Takbar_Colors, TaskBarHandle); writeIntExWND(DateTime.Hours, Takbar_Colors, TaskBarHandle); writeStringExWND(':', Takbar_Colors, TaskBarHandle); @@ -96,32 +96,32 @@ begin clearWNDEx(DesktopHandle, Desktop_Colors); if not(StringEquals(asuro.RELEASE, 'r')) then begin versionSize:= StringSize(asuro.VERSION) + StringSize('Asuro v'); - versionDrawX:= 157 - versionSize; - setCursorPosWND(versionDrawX, 60, DesktopHandle); + versionDrawX:= Console.getMaxCellW() - 2 - versionSize; + setCursorPosWND(versionDrawX, Console.getMaxCellH() - 4, DesktopHandle); writestringExWND('ASURO v', Desktop_Colors, DesktopHandle); writestringExWND(asuro.VERSION, Desktop_Colors, DesktopHandle); if StringEquals(asuro.RELEASE, 'rc') then begin releaseSize:= StringSize('RELEASE CANDIDATE'); - releaseDrawX:= 157 - (versionSize div 2) - (releaseSize div 2); - setCursorPosWND(releaseDrawX, 61, DesktopHandle); + releaseDrawX:= Console.getMaxCellW() - 2 - (versionSize div 2) - (releaseSize div 2); + setCursorPosWND(releaseDrawX, Console.getMaxCellH() - 3, DesktopHandle); writeStringExWND('RELEASE CANDIDATE', Desktop_Colors, DesktopHandle); end; if StringEquals(asuro.RELEASE, 'ia') then begin releaseSize:= StringSize('INTERNAL ALPHA'); - releaseDrawX:= 157 - (versionSize div 2) - (releaseSize div 2); - setCursorPosWND(releaseDrawX, 61, DesktopHandle); + releaseDrawX:= Console.getMaxCellW() - 2 - (versionSize div 2) - (releaseSize div 2); + setCursorPosWND(releaseDrawX, Console.getMaxCellH() - 3, DesktopHandle); writeStringExWND('INTERNAL ALPHA', Desktop_Colors, DesktopHandle); end; if StringEquals(asuro.RELEASE, 'a') then begin releaseSize:= StringSize('ALPHA'); - releaseDrawX:= 157 - (versionSize div 2) - (releaseSize div 2); - setCursorPosWND(releaseDrawX, 61, DesktopHandle); + releaseDrawX:= Console.getMaxCellW() - 2 - (versionSize div 2) - (releaseSize div 2); + setCursorPosWND(releaseDrawX, Console.getMaxCellH() - 3, DesktopHandle); writeStringExWND('ALPHA', Desktop_Colors, DesktopHandle); end; if StringEquals(asuro.RELEASE, 'b') then begin releaseSize:= StringSize('BETA'); - releaseDrawX:= 157 - (versionSize div 2) - (releaseSize div 2); - setCursorPosWND(releaseDrawX, 61, DesktopHandle); + releaseDrawX:= Console.getMaxCellW() - 2 - (versionSize div 2) - (releaseSize div 2); + setCursorPosWND(releaseDrawX, Console.getMaxCellH() - 3, DesktopHandle); writeStringExWND('BETA', Desktop_Colors, DesktopHandle); end; end; @@ -210,9 +210,9 @@ begin Desktop_Colors:= console.combinecolors($FFFF, $34DB); tracer.push_trace('shell.init.4'); - DesktopHandle:= Console.newWindow(0, 0, 159, 63, 'DESKTOP'); + DesktopHandle:= Console.newWindow(0, 0, Console.getMaxCellW(), Console.getMaxCellH(), 'DESKTOP'); tracer.push_trace('shell.init.5'); - TaskBarHandle:= Console.newWindow(0, 63, 159, 1, 'SHELL'); + TaskBarHandle:= Console.newWindow(0, Console.getMaxCellH(), Console.getMaxCellW(), 1, 'SHELL'); tracer.push_trace('shell.init.6'); console.bordersEnabled(TaskBarHandle, false); diff --git a/src/prog/vbeinfo.pas b/src/prog/vbeinfo.pas new file mode 100644 index 00000000..f56d0f76 --- /dev/null +++ b/src/prog/vbeinfo.pas @@ -0,0 +1,41 @@ +{ + Prog->vbeinfo - Print out vbeinfo (VESA VGA). + + @author(Kieron Morris ) +} +unit vbeinfo; + +interface + +uses + console, terminal, keyboard, util, strings, tracer, md5; + +procedure init(); + +implementation + +procedure run(Params : PParamList); +var + ConProp : PConsoleProperties; + +begin + ConProp:= getConsoleProperties(); + writestringWND('Pixel Width: ', getTerminalHWND); + writeintlnWND(ConProp^.Width, getTerminalHWND); + writestringWND('Pixel Height: ', getTerminalHWND); + writeintlnWND(ConProp^.Height, getTerminalHWND); + writestringWND('Bits Per Pixel: ', getTerminalHWND); + writeintlnWND(ConProp^.BitsPerPixel, getTerminalHWND); + writestringWND('Cell Width: ', getTerminalHWND); + writeintlnWND(ConProp^.MAX_CELL_X, getTerminalHWND); + writestringWND('Cell Height: ', getTerminalHWND); + writeintlnWND(ConProp^.MAX_CELL_Y, getTerminalHWND); +end; + +procedure init(); +begin + tracer.push_trace('vbeinfo.init'); + terminal.registerCommand('VBEINFO', @Run, 'Print out vbeinfo (VESA VGA).'); +end; + +end. \ No newline at end of file diff --git a/src/progmanager.pas b/src/progmanager.pas index 9cc28b89..ff8b2cf6 100644 --- a/src/progmanager.pas +++ b/src/progmanager.pas @@ -7,7 +7,7 @@ uses //progs base64_prog, md5sum, shell, terminal, edit, vmstate, vmlog, netlog, themer, - memview, udpcat, dhclient; + memview, udpcat, dhclient, vbeinfo; procedure init(); @@ -37,6 +37,7 @@ begin base64_prog.init(); tracer.push_trace('progmanager.dhclient.init'); dhclient.init(); + vbeinfo.init(); tracer.push_trace('progmanager.terminal.init'); terminal.run(); diff --git a/src/stub/stub.asm b/src/stub/stub.asm index 4c695127..53ea9f7e 100644 --- a/src/stub/stub.asm +++ b/src/stub/stub.asm @@ -63,8 +63,8 @@ dd 0 dd 0 dd 0 dd 0 -dd 1280 dd 1024 +dd 768 dd 16 ;