📄 system_lib.cpp
字号:
#include "system_lib.h"
#include "system_invoke.h"
#include "system.h"
/* 下面的定义结构都是系统库所用的,而不是外部程序用的 */
/* 定义色彩枚举变量 */
enum enum_pyos_Color{ clBlack = 0 , clBlue , clGreen , clCyan , clRed , clMagenta , clBrown , clWhite } ;
/* 定义显卡所用数据结构 */
struct struct_pyos_VideoItem{
unsigned char Char ; // 字符
enum_pyos_Color FrontColor : 3 ;
bool AddLight : 1 ;
enum_pyos_Color BackColor : 3 ;
bool Flash : 1 ;
} ;
unsigned int class_pyos_SystemLib_Video::cursor_x_pos = 0 ;
unsigned int class_pyos_SystemLib_Video::cursor_y_pos = 0 ;
/* 此函数是系统函数,真正处理系统调用 */
void class_pyos_SystemLib_Video::Print( int x_pos , int y_pos , char ch , char style )
{
if( x_pos >= 0 ){ // 如果是 < 0 就表示在当前位置处打印
cursor_x_pos = x_pos ;
}
if( y_pos >= 0 ){
cursor_y_pos = y_pos ;
}
switch( ch ){
case '\n' : // 回车符
cursor_x_pos = 0 ;
++cursor_y_pos ;
break ;
default : //可打印字符
/* 通过光标位置,计算偏移量 */
unsigned short offset = cursor_y_pos * 80 + cursor_x_pos ;
/* 显示字符 */
char* video = ( char* )0xb8000 + offset * 2 ; // 因为一个字符占两上字节,所以偏移量要 *2
*video++ = ch ;
*video = style ;
// 移动光标到下一位置
++cursor_x_pos ;
break ;
}
/* 重新设置光标位置 */
SetCursor( cursor_x_pos , cursor_y_pos ) ;
}
void class_pyos_SystemLib_Video::SetCursor( int x_pos , int y_pos )
{
cursor_x_pos = x_pos ;
cursor_y_pos = y_pos ;
/* 控制列数不超过 80,因为一行显示80例 (0~79) */
while( cursor_x_pos > 79 ){
++cursor_y_pos ;
cursor_x_pos -= 80 ;
}
/* 控制行数不超过 25,因为一页显示25行 (0~24) */
while( cursor_y_pos > 24 ){
--cursor_y_pos ;
Scroll() ; // 屏幕上滚一屏
}
/* 设定光标位置 */
unsigned short offset = cursor_y_pos * 80 + cursor_x_pos ;
class_pyos_System::ToPort( 0x3d4 , 14 ) ;
class_pyos_System::ToPort( 0x3d5 , ( unsigned char )( offset >> 8 ) ) ;
class_pyos_System::ToPort( 0x3d4 , 15 ) ;
class_pyos_System::ToPort( 0x3d5 , ( unsigned char )offset ) ;
}
void class_pyos_SystemLib_Video::Scroll()
{
struct_pyos_VideoItem* videomem = ( struct_pyos_VideoItem* )0xB8000 ;
for( int loop = 0 ; loop < 80 * 24 ; ++loop ){
// 让上一行 = 下一行的
*videomem = *( videomem + 80 ) ; // 一行 80 列
++videomem ;
}
/* 清空最后一行 */
struct_pyos_VideoItem item ;
item.Char = 0 ;
item.AddLight = false ;
item.BackColor = clBlack ;
item.FrontColor = clWhite ;
for( int loop = 0 ; loop < 80 ; ++loop ){
*videomem++ = item ;
}
/* 设定光标在最后一行 */
SetCursor( 0 , 24 ) ;
}
void class_pyos_SystemLib_Video::Clear()
{
/* 设置前景色与背景色 */
struct_pyos_VideoItem item ;
item.Char = 0 ;
item.FrontColor = clWhite ;
item.BackColor = clBlack ;
item.Flash = false ;
item.AddLight = false ;
struct_pyos_VideoItem* videomem = ( struct_pyos_VideoItem* )0xB8000 ;
int loop ;
for( loop = 0 ; loop < 80 * 25 ; ++loop ){
*videomem++ = item ;
}
// 重新设置光标
SetCursor( 0 , 0 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -