⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video.cpp

📁 保护模式下8259A芯片编程及中断处理探究
💻 CPP
字号:
#include "video.h"
#include "system.h"

class_pyos_Position class_pyos_Video::CursorCurrentPosition ;
enum_pyos_Color class_pyos_Video::BackColor ;
enum_pyos_Color class_pyos_Video::FrontColor ;

/* 初始化视屏 */
void class_pyos_Video::Init()
{
  /* 清屏 */
  ClearScreen() ;
}
/* 设定光标位置函数 */
void class_pyos_Video::SetCursorPosition( unsigned short x , unsigned short y )
{
  /* 控制列数不超过 80,因为一行显示80例 (0~79) */
  while( x > 79 ){
    ++y ;
    x -= 80 ;
  } 

  CursorCurrentPosition.X = x ;
  CursorCurrentPosition.Y = y ;
  SetCursorPosition() ;
}
/* 设定光标位置函数 */
void class_pyos_Video::SetCursorPosition()
{
  unsigned short offset = CursorCurrentPosition.Y * 80 + CursorCurrentPosition.X ;
  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_Video::PrintMessage( char msg , enum_pyos_Color front_color , enum_pyos_Color back_color )
{
  unsigned char color = GetLogicalColorFromFrontColorAndBackColor( front_color , back_color ) ;  
  /* 通过光标位置,计算偏移量 */
  unsigned short offset = CursorCurrentPosition.Y * 8 + CursorCurrentPosition.X ;
  /* 显示字符 */
  unsigned char *video = ( unsigned char * )0xb8000 + offset * 2 ;
  *video++ = msg ;
  *video = color ;
  /* 重新设置光标位置 */
  SetCursorPosition( CursorCurrentPosition.X + 1 , CursorCurrentPosition.Y ) ;
}
/* 打印字符信息 */
void class_pyos_Video::PrintMessage( char* msg , enum_pyos_Color front_color , enum_pyos_Color back_color )
{
  while( *msg ){
     PrintMessage( *msg , front_color , back_color ) ;
     msg++ ;
  }
}
/* 清屏 */
void class_pyos_Video::ClearScreen()
{
  /* 设置前景色与背景色 */
  FrontColor = clWhite ;
  BackColor = clBlack ;
  unsigned char color = GetLogicalColorFromFrontColorAndBackColor( FrontColor , BackColor ) ;
  unsigned char* videomem = ( unsigned char* )0xB8000 ;
  int loop ;
  for( loop = 0 ; loop < 80 * 25 ; ++loop ){
    *videomem++ = 0 ;
    *videomem++ = color ;
  }
  SetCursorPosition( 0 , 0 ) ;
}
/* 从逻辑色彩到物理色彩的转换 */
unsigned char class_pyos_Video::GetLogicalColorFromFrontColorAndBackColor( enum_pyos_Color front_color , enum_pyos_Color back_color )
{
  return ( back_color << 4 | front_color ) ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -