--- /dev/null
+\r
+#include "core.h"\r
+\r
+uchar VGA_CRTController_ReadRegister(uchar regno)\r
+{\r
+ IO_Out8(VGA_CRTC_R_NUMBER, regno);\r
+ return IO_In8(VGA_CRTC_R_DATA);\r
+}\r
+\r
+void VGA_CRTController_WriteRegister(uchar regno, uchar data)\r
+{\r
+ IO_Out8(VGA_CRTC_R_NUMBER, regno);\r
+ IO_Out8(VGA_CRTC_R_DATA, data);\r
+ return;\r
+}\r
+\r
+void TextMode_Write_TextRAM(ushort index, uchar data)\r
+{\r
+ uchar *textram;\r
+\r
+ textram = (uchar *)VGA_TEXTMODE_ADR;\r
+\r
+ if(index < 80 * 25 * 2){\r
+ textram[index] = data;\r
+ }\r
+ return;\r
+}\r
+\r
+void TextMode_Put_Character_Absolute(uchar c, col_text col, ushort location)\r
+{\r
+ TextMode_Write_TextRAM(location * 2 + 0, c);\r
+ TextMode_Write_TextRAM(location * 2 + 1, (uchar)col);\r
+ return;\r
+}\r
+\r
+void TextMode_Put_String_Absolute(const uchar s[], col_text col, uint x, uint y)\r
+{\r
+ ushort location;\r
+ uint i;\r
+\r
+ for(i = 0; s[i] != 0x00; i++){\r
+\r
+ }\r
+\r
+ if((x + i - 1) >= 80 || y >= 25){\r
+ return;\r
+ }\r
+\r
+ location = (y * 80) + x;\r
+\r
+ for(i = 0; s[i] != 0x00; i++){\r
+ TextMode_Put_Character_Absolute(s[i], col, location + i);\r
+ }\r
+ return;\r
+}\r
+\r
+void TextMode_Clear_Screen(void)\r
+{\r
+ uint i;\r
+\r
+ for(i = 0; i < 80 * 25; i++){\r
+ TextMode_Put_Character_Absolute(' ', white, i);\r
+ }\r
+\r
+ TextMode_Set_CursorLocation(0);\r
+\r
+ return;\r
+}\r
+\r
+ushort TextMode_Get_CursorLocation(void)\r
+{\r
+ ushort location;\r
+\r
+ location = VGA_CRTController_ReadRegister(VGA_CRTC_R_CURSOR_LOCATION_HIGH);\r
+\r
+ location = location << 8;\r
+\r
+ location |= VGA_CRTController_ReadRegister(VGA_CRTC_R_CURSOR_LOCATION_LOW);\r
+\r
+ return location;\r
+}\r
+\r
+void TextMode_Set_CursorLocation(ushort location)\r
+{\r
+ VGA_CRTController_WriteRegister(VGA_CRTC_R_CURSOR_LOCATION_HIGH, location >> 8);\r
+ VGA_CRTController_WriteRegister(VGA_CRTC_R_CURSOR_LOCATION_LOW, location & 0x00ff);\r
+\r
+ return;\r
+}\r
+\r
+void TextMode_Put_Character(uchar c, col_text col)\r
+{\r
+ ushort location;\r
+\r
+ location = TextMode_Get_CursorLocation();\r
+ if(c == '\n'){\r
+ if(80 * 24 <= location && location < 80 * 25){\r
+ TextMode_Newline();\r
+ TextMode_Set_CursorLocation(24 * 80);\r
+ } else{\r
+ TextMode_Set_CursorLocation(((location / 80) + 1) * 80);\r
+ }\r
+ } else if(c == '\t'){\r
+ TextMode_Set_CursorLocation(((location >> 2) << 2) + 4);\r
+ } else{\r
+ TextMode_Put_Character_Absolute(c, col, location);\r
+ TextMode_Set_CursorLocation(location + 1);\r
+ }\r
+ return;\r
+}\r
+\r
+void TextMode_Newline(void)\r
+{\r
+ uint *textram;\r
+ uint i;\r
+\r
+ textram = (uint *)VGA_TEXTMODE_ADR;\r
+\r
+ for(i = 0; i < 80 * 24 * 2 / 4; i++){\r
+ textram[i] = textram[i + 80 * 2 / 4];\r
+ }\r
+\r
+ for(i = 0; i < 80; i++){\r
+ TextMode_Put_Character_Absolute(' ', white, (80 * 24) + i);\r
+ }\r
+\r
+ return;\r
+}\r
+\r
+void TextMode_Put_String(const uchar s[], col_text col)\r
+{\r
+ for(; *s != 0x00; s++){\r
+ TextMode_Put_Character(*s, col);\r
+ }\r
+ return;\r
+}\r