📄 conio.c
字号:
/** conio.c ** ** Original Author: J Spencer Seidel ** Date: 10.16.99 ** ** Description: ** Contains various printing functions for use with ** kernel debugging. These routines are not ** optimized since we're only debugging :-) ** ** Revision History: ** First version ** ** 0.0.1 10.16.99 J Spencer Seidel ** 0.0.2 12.22.99 Guido de Jong ** ** This program is free software, you can redistribute it and/or ** modify it under the terms of the GNU General Public License ** as published by the Free Software Foundation; either version ** 2 of the License, or (at your option) any later version. ** ** This program is distributed in the hope that it will be ** useful, but WITHOUT ANY WARRANTY; without even the implied ** warranty or MERCHANTABILITY or FITNESS FOR A PARTICULAR ** PURPOSE. See the GNU General Public License for more ** details. ** ** You should have received a copy of the GNU General Public ** License along with this program; if not, write to the ** Free Software Foundation, Inc., 59 Temple Place, Suite 330, ** Boston, MA 02111-1307 USA ** *********************************************************Apostle OS**/#include <debug/conio.h>#include <stdarg.h>#include <string.h>#include <types.h>#define ROWS 25#define COLS 80#define VID_SIZE (ROWS*COLS)#define ROWSIZE 0xA0#define VID_PTR 0xB8000#define BLNK_MSK 0x7F#define BG_MSK 0x8F#define FG_MSK 0xF8#define INTSTY_MSK 0xF7#define DIG_INI 0x30 /* ASCII '0' */ #define TAB_SIZE 8// Attribute:// MSB LSB// 0 0 0 0 0 0 0 0// + +-+-+ + +-+-+// | | | |------> Foreground// | | |----------> Intensity// | |--------------> Background// |------------------> Blinkbyte gAttrib;struct cursor{ byteptr p; byte x,y;};struct cursor gCursor;// Local functionsvoid DebugClearToLine( void );void DebugResetCursor( void );void DebugScroll(int numlines);/* ConsoleInit * * Clears background to background color and sets background * and foreground colors. */void DebugConsoleInit( byte bg, byte fg ){ // Setup attribute byte gAttrib = 0x00; DebugSetBackground( bg ); DebugSetForeground( fg ); // Initialize cursor DebugResetCursor(); DebugClearScreen();}/* DebugClearScreen() * * Clears the screen to the background color */void DebugClearScreen(){ int i; char *p = gCursor.p; // reset gp DebugResetCursor(); // clear the screen to the background for( i=0; i<VID_SIZE; *p++=' ', *p++=gAttrib, i++ );}/* DebugClearToLine * * Clears to end of line and performs a * line feed */void DebugClearToLine( void ){ // Do a line feed while( gCursor.x < COLS ) { *gCursor.p++ = ' '; *gCursor.p++ = gAttrib; gCursor.x++; } // Set up x and y gCursor.x = 0; // May need to scroll a line if( ++gCursor.y > ROWS-1 ) { DebugScroll(1); gCursor.y = ROWS-1; gCursor.p = (char *)(VID_PTR + (ROWS-1)*ROWSIZE); }}/* DebugPutChar * * Writes a character to the current cursor location */void DebugPutChar( char c ){ *gCursor.p++ = c; *gCursor.p++ = gAttrib; gCursor.x++;}/* DebugSetBackground * * Sets background color */void DebugSetBackground( byte bg ){ //clear the current background gAttrib &= BG_MSK; //set the background gAttrib |= (bg << 4);}/* DebugSetForeground * * Sets foreground color */void DebugSetForeground( byte fg ){ //clear the current foreground gAttrib &= FG_MSK; //set the foreground gAttrib |= fg;}/* DebugSetBlink * * Sets blink bit */void DebugSetBlink( bool setBit ){ //clear the current blink bit gAttrib &= BLNK_MSK; //set it gAttrib |= ( setBit ? (0x1 << 7) : (0x0) );}/* DebugSetIntensity * * Sets intensity bit */void DebugSetIntensity( bool setBit ){ //clear the current intensity bit gAttrib &= INTSTY_MSK; //set it gAttrib |= ( setBit ? (0x1 << 3) : (0x0) );}/* DebugResetCursor * * Resets global video ptr to top of screen */void DebugResetCursor(){ gCursor.p = (byteptr)VID_PTR; gCursor.x = gCursor.y = 0;}/* DebugGotoXY * * Puts cursor at location x, y on screen */void DebugGotoXY( byte x, byte y ){ size_t offset = 2*((int)x*ROWS + (int)y*COLS); if( (x < COLS-1) && (y < ROWS-1) ) { gCursor.p = (byteptr)VID_PTR + offset; gCursor.x = x; gCursor.y = y; }}/* DebugGetX * * Returns current x position */byte DebugGetX( void ){ return gCursor.x;}/* DebugGetY * * Returns current y position */byte DebugGetY( void ){ return gCursor.y;}extern int vsprintf( char *buf, const char *fmt, va_list args );/* DebugPrintF * * Write a formatted string to the console. * This function performs basic interpreting of control characters. */void DebugPrintF( const char *fmt, ... ){ va_list args; char buf[256]; int i, j, n; va_start(args, fmt); n = vsprintf(buf, fmt, args); va_end(args); for (i = 0; i < n; i++) { switch (buf[i]) { case '\t': for (j = gCursor.x % TAB_SIZE; j < TAB_SIZE; j++) DebugPutChar(' '); break; case '\n': case '\r': DebugClearToLine(); break; default : DebugPutChar(buf[i]); } }}/* DebugScroll * * Scrolls the screen up one line at a time */void DebugScroll( int numlines ){ int i,j; char *dest, *src; for( i=0; i<numlines; i++ ) { for( j=1; j<ROWS; j++ ) { // Setup pointers src = (char *)(VID_PTR + j*ROWSIZE); memcpy( src - ROWSIZE, src, sizeof(byte)*ROWSIZE ); } // Clear last line dest = (char *)(VID_PTR + (ROWS-1)*ROWSIZE); for( j=0; j<COLS; j++ ) { *dest++ = ' '; *dest++ = gAttrib; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -