📄 cgascr.cc.svn-base
字号:
/* $Id: cgascr.cc,v 1.4 2002/10/15 11:42:22 gal Exp $ *//*****************************************************************************//* Betriebssysteme *//*---------------------------------------------------------------------------*//* *//* C G A _ S C R E E N *//* *//*---------------------------------------------------------------------------*//* Mit Hilfe dieser Klasse kann man auf den Bildschirm des PCs zugreifen. *//* Der Zugriff erfolgt direkt auf der Hardwareebene, d.h. ueber den Bild- *//* schirmspeicher bzw. die I/O-Ports der Grafikkarte. *//*****************************************************************************/#include "machine/cgascr.h"#include "machine/io_port.h"#include "object/o_stream.h"CGA_Screen::CGA_Screen() : m_screen((char*)0xb8000), m_index(0x3d4), m_data(0x3d5), m_curX(0), m_curY(0), m_color(CGA_Screen::CGA_Attrib::fg_white | CGA_Screen::CGA_Attrib::bg_black | CGA_Screen::CGA_Attrib::noblink){} CGA_Screen::CGA_Screen(CGA_Screen &scr) : m_screen((char*)0xb8000), m_index(0x3d4), m_data(0x3d5), m_curX(scr.m_curX), m_curY(scr.m_curY), m_color(scr.m_color){}CGA_Screen::~CGA_Screen(){}void CGA_Screen::show (int x, int y, char c, unsigned char attrib){ int idx = offset(x, y); if(idx < 0) return; m_screen[idx] = c; m_screen[idx+1] = attrib;}void CGA_Screen::setpos (int x, int y){ int pos = offset(x, y); if(pos < 0) return; pos /= 2; m_index.outb(14); m_data.outb((pos >> 8) & 0xFF ); m_index.outb(15); m_data.outb(pos & 0xFF); m_curX = x; m_curY = y;}void CGA_Screen::getpos (int &x, int &y){ unsigned int offset = 0; m_index.outb(14); offset |= ( (m_data.inb() & 0xFF) << 8 ); m_index.outb(15); offset |= ( m_data.inb() & 0xFF ); x = m_curX = offset % CGA_Attrib::screen_width; y = m_curY = offset / CGA_Attrib::screen_width;}void CGA_Screen::print (char* text, int length, unsigned char attrib){ unsigned int len = (unsigned int)length; for(unsigned int i = 0; i < len; i++) print(text[i], attrib);}void CGA_Screen::print (char c, unsigned char attrib){ if(c != '\n') { show(m_curX, m_curY, c, attrib); incpos(); } else { println(); }}void CGA_Screen::println (){ m_curX = CGA_Attrib::screen_width - 1; incpos();}void CGA_Screen::incpos(){ m_curX++; if(m_curX >= CGA_Attrib::screen_width) { m_curX = 0; m_curY++; if(m_curY >= CGA_Attrib::screen_height) { scroll(m_curY + 1 - CGA_Attrib::screen_height); m_curY = CGA_Attrib::screen_height - 1; } } setpos(m_curX, m_curY);}void CGA_Screen::decpos(){ m_curX--; if(m_curX < 0) { m_curX = 0; m_curY--; if(m_curY < 0) m_curY = 0; } setpos(m_curX, m_curY);}void CGA_Screen::scroll(int line){ int totalOffset = CGA_Attrib::screen_width * CGA_Attrib::screen_height * 2 * sizeof(char); if(line <= 0) { return; } else if(line >= CGA_Attrib::screen_height) { for(unsigned int head = 0; (int)head < totalOffset; head++) m_screen[head] = 0; } else { for(unsigned int head = 0, tail = offset(0, line); (int)tail < totalOffset; head++, tail++) m_screen[head] = m_screen[tail]; for(unsigned int tail = offset(0, CGA_Attrib::screen_height - line); (int)tail < totalOffset; tail++) m_screen[tail] = 0; }}int CGA_Screen::offset (int x, int y) const{ if (x < 0 || y < 0 || x >= CGA_Attrib::screen_width || y >= CGA_Attrib::screen_height) return -1; else return (y * CGA_Attrib::screen_width + x) * 2 * sizeof(char);}void CGA_Screen::clear(){ scroll(CGA_Attrib::screen_height); setpos(0, 0);}void CGA_Screen::goto_head(){ m_curX = 0; setpos(m_curX, m_curY);}void CGA_Screen::goto_end(){ m_curX = CGA_Screen::CGA_Attrib::screen_width - 1; setpos(m_curX, m_curY);}void CGA_Screen::set_fg_color(int color){ m_color = (m_color & ~0xf) | (color & 0xf);}void CGA_Screen::set_bg_color(int color){ m_color = (m_color & ~0x70) | (color & 0x70);}void CGA_Screen::set_blink(bool on){ m_color = on ? (m_color | 0x80) : (m_color & ~0x80);}void CGA_Screen::set_color(int color){ m_color = color & 0xff;}int CGA_Screen::get_fg_color(){ return m_color & 0xf;}int CGA_Screen::get_bg_color(){ return m_color & 0x70;}bool CGA_Screen::is_blink(){ return m_color & 0x80;}int CGA_Screen::get_color(){ return m_color & 0xff;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -