我的学习之旅(17)console.h和console.c

来源:互联网 发布:seo和sem区别 编辑:程序博客网 时间:2024/06/04 18:32

console打印的思想基本参考linux0.1

console.h的源代码:

#ifndef __CONSOLE_H__#define __CONSOLE_H__#define COLOR_VGA_MODE/*不检查显卡模式,强制写死*/#ifdef COLOR_VGA_MODE#define  DISP_BASE_ADDR 0xB8000       /* 0xB8000=VGA基地址 ,彩色模式*/#define  DISP_END_ADDR  0xba000      #define  DISP_MAX_X         80       /* 每行80个字符*/#define  DISP_MAX_Y         25       /* 1屏最大有25行*/#define  BYTES_FOR_ONE_LINE (DISP_MAX_X <<1)#define  REG_PORT       0x3d4      /*显示寄存器索引控制端口地址*/#define VALUE_PORT    0x3d5  /*数据寄存器端口地址*/#endifvoid console_init(void);void console_write(void *tty, char *buf );void clear_screen(unsigned color);inline void set_cursor(unsigned char flag);inline void gotoxy(unsigned int new_x,unsigned int new_y);#endif

console.c的源代码:

#include <system.h>#include <io.h>#include <tty.h>#include <console.h>#include <printk.h>//屏幕大小static unsigned long g_screen_top = 0;//第几行,默认是第0行static unsigned long g_screen_bottom = DISP_MAX_Y;//第几行,默认是第25行//字符坐标static unsigned long g_x = 1; //x坐标 static unsigned long g_y = 1; //y坐标//光标static unsigned long g_position = DISP_BASE_ADDR; // 记录当前光标在显示内存中的位置//屏幕位置static unsigned long g_screen_origin = DISP_BASE_ADDR; //记录屏幕在显示内存中的起始位置static unsigned long g_screen_end = DISP_BASE_ADDR + BYTES_FOR_ONE_LINE*DISP_MAX_Y; //记录屏幕在显示内存中的结束位置static unsigned char g_color = DISP_FG_WHITE + DISP_BG_BLACK; /*DISP_BASE_ADDRg_screen_origin  +--------------------+                            |g_screen_top                  |                            |x,y 相对于屏幕     |                            |                                        |                            |                                        |                            |                                        |                            +--------------------+  <---- g_screen_end                            |g_screen_bottom             |                            |                                         |                            +--------------------+DISP_END_ADDR*/
0 0
原创粉丝点击