RSS

screen.cpp

18 Jun

#define UCHAR unsigned char
#define VIDEO_INT 0x10

class Screen
{
private:
UCHAR mode, row, col;
UCHAR rownum, colnum;
UCHAR active_page, visual_page;
UCHAR attribute;

public:
Screen(void);
Screen(UCHAR mode);

~Screen(void); 

void setMode(UCHAR mode);
UCHAR getMode(void);

void setCursorPos(UCHAR y, UCHAR x);
void getCursorPos(UCHAR *y, UCHAR *x);

void writeChar(UCHAR letter);
void writeString(UCHAR *str);

void setAttribute(UCHAR attr);
UCHAR getCharAttr(UCHAR *attr);

void setActivePage(UCHAR page);
UCHAR getActivePage(void);

void setVisualPage(UCHAR page);
UCHAR getVisualPage(void);

void cls(void);
};

Screen::Screen(void)
{
UCHAR mode;

this->row = 0;
this->col = 0;

this->mode = mode = 0x03;

this->rownum = 25;
this->colnum = 80;

this->active_page = 0;
this->visual_page = 0;

this->attribute = 7;

asm mov ah, 0x00;
asm mov al, mode;
asm or al, 0x80;
asm int VIDEO_INT;

return;
}

Screen::Screen(UCHAR mode)
{
this->setMode(mode);
return;
}

Screen::~Screen(void)
{
return;
}

void Screen::setMode(UCHAR mode)
{
this->mode = mode;

this->active_page = 0;
this->visual_page = 0;

this->rownum = 25;

switch(mode)
{
case 0x00 :
case 0x01 : this->colnum = 40;
break;
case 0x02 :
case 0x03 :
case 0x07 : this->colnum = 80;
break;
default : this->colnum = 0;
break;
}

asm mov ah, 0x00;
asm mov al, mode;
asm or al, 0x80;
asm int VIDEO_INT;

return;
}

UCHAR Screen::getMode(void)
{
return this->mode;
}

void Screen::setCursorPos(UCHAR y, UCHAR x)
{
UCHAR page = this->active_page;

if((y > this->rownum) ||
(x > this->colnum))
y = x = 0;

this->row = y;
this->col = x;

asm mov ah, 0x02;
asm mov bh, page;
asm mov dh, y;
asm mov dl, x;
asm int VIDEO_INT;

return;
}

void Screen::getCursorPos(UCHAR *y, UCHAR *x)
{
*y = this->row;
*x = this->col;

return;
}

void Screen::writeChar(UCHAR letter)
{
UCHAR page = this->active_page;
UCHAR attr = this->attribute;

asm mov ah, 0x09;
asm mov al, letter;
asm mov bh, page;
asm mov bl, attr;
asm mov ch, 0x00;
asm mov cl, 0x01;
asm int VIDEO_INT;

return;
}

void Screen::writeString(UCHAR *str)
{
for(; *str != ”; str++)
{
if(this->col > this->colnum)
{
this->row++;
this->col = 0;
}

this->setCursorPos(this->row, ++this->col);
this->writeChar(*str);
}
return;
}

void Screen::setAttribute(UCHAR attr)
{
this->attribute = attr;
return;
}

UCHAR Screen::getCharAttr(UCHAR *attr)
{
UCHAR page = this->active_page;
UCHAR letter, attribute;

asm mov ah, 0x08;
asm mov bh, page;
asm int VIDEO_INT;
asm mov attribute, ah;
asm mov letter, al;

this->attribute = *attr = attribute;

return letter;
}

void Screen::setActivePage(UCHAR page)
{
this->active_page = page;
return;
}

UCHAR Screen::getActivePage(void)
{
return this->active_page;
}

void Screen::setVisualPage(UCHAR page)
{
if(page > 0) page = 0;

this->visual_page = page;

asm mov ah, 0x05;
asm mov al, page;
asm int VIDEO_INT;
return;
}

UCHAR Screen::getVisualPage(void)
{
return this->visual_page;
}

void Screen::cls(void)
{
UCHAR mode = this->mode;

this->row = 0;
this->col = 0;

asm mov ah, 0x00;
asm mov al, mode;
asm int VIDEO_INT;

return;
}

 
Leave a comment

Posted by on June 18, 2011 in C ++, Computer

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: