📄 console.cpp
字号:
/*
* Copyright (C) 2004, Thejesh AP. All rights reserved.
*/
#include <sys\types.h>
#include <stdlib.h>
#include <string.h>
#include <fs\devmgr.h>
#include <drivers\console.h>
//#include <drivers\keyboard.h>
extern device_manager _dev_mgr;
console::console(char* name):driver(name)
{
row = col = 0;
base = (ushort*) 0xb8000;
attr = WHITE;
int err;
if((err = _dev_mgr.register_driver(1,this->name,0,console_main))<0)
{
*this<<"register driver ERROR: "<<this->name<<" "<<err<<endl;
return;
}
clrscr();
*this<<"Console driver succesfully registered [name] = "<<this->name<<endl;
}
console::~console()
{
int err;
if((err = _dev_mgr.deregister_driver(this->name))<0)
{
*this<<"deregister driver ERROR: "<<this->name<<" "<<err<<endl;
return;
}
}
console& console::operator<<(char* _s)
{
while(*_s)
{
byte newline = 0;
byte bs = 0;
if(col >= 80 || *_s == '\n')
{
row += 80;
col = 0;
newline = (*_s=='\n');
}
if(row >= 80*25) scroll();
switch(*_s)
{
case '\t': col += 8;break;
case '\b': col -= 1;
if(col == -1)
{
row -= 80;
col = 79;
}
if(row < 0)
{
row = col = 0;
}
*_s=' ';bs=1;
default : if(!newline) base[row+col] = *_s|attr;
if(!bs && !newline) col++;
}
update_cursor();
_s++;
}
return *this;
}
console& console::operator<<(uchar _c)
{
byte newline = 0;
byte bs = 0;
if(col >= 80 || _c == '\n')
{
row += 80;
col = 0;
newline = (_c=='\n');
}
if(row >= 80*25) scroll();
switch(_c)
{
case '\t': col += 8;break;
case '\b': col -= 1;
if(col == -1)
{
row -= 80;
col = 79;
}
if(row < 0)
{
row = col = 0;
}
_c=' ';bs=1;
default : if(!newline) base[row+col] = _c|attr;
if(!bs && !newline) col++;
}
update_cursor();
return *this;
}
console& console::operator<<(uint _i)
{
if(_i == 0) return *this<<'0';
char arr[40];
int i = 0;
while(_i > 0)
{
arr[i++] = _i % 10;
_i = _i / 10;
}
i--;
while(i >= 0) *this<<(uchar)(arr[i--]+'0');
return *this;
}
void console::update_cursor()
{
ushort pos = row + col;
outportb(0x3d4,0x0f);
outportb(0x3d5,pos & 0xff);
outportb(0x3d4,0x0e);
outportb(0x3d5,(pos>>8) & 0xff);
}
void console::scroll()
{
memmove(base,base+80,80*24*2);
memset_w(base+80*24,(' '|0x0700),80);
row = 80*24;
col = 0;
}
void console::dispnum(uint num,int base)
{
char arr[20];
int i = 0;
if(num == 0) //if num=0, display 0 & return
{
*this<<'0';
return;
}
while(num > 0) //store individual nums in array
{
arr[i++] = num % base;
num = num / base;
}
i--;
while(i >= 0) //display nums stored in array
{
if(arr[i] > 9)
arr[i] = arr[i] + 7; //for hex nums exceeding 9
*this<<(char)(arr[i--] + '0');
}
}
console _console_obj("console");
int console_main(void* req)
{
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -