#define MOUSE_INT 0x33
#define MOUSE_READY 0xff
#define MOUSE_NOT_READY 0x00
#define MOUSE_SUCCESS 0x1f
#define MOUSE_FAILURE 0xff
#define MOUSE_LEFT_CLICK 0x01
#define MOUSE_RIGHT_CLICK 0x02
#define MOUSE_LEFT_BUTTON 0x00
#define MOUSE_RIGHT_BUTTON 0x01
#define UCHAR unsigned char
#define USHORT unsigned short int
class Mouse
{
private:
UCHAR button;
UCHAR isReady;
UCHAR clickMode;
USHORT x, y;
/* Mengetahui posisi koordinat pointer mouse */
void getMousePos(void);
public:
Mouse(void); /* Konstruktor default */
~Mouse(void); /* Destruktor default */
UCHAR getState(void);
UCHAR getNumButton(void);
UCHAR disableMouse(void);
void enableMouse(void);
/* Mendeteksi penekanan tombol mouse */
USHORT getButtonClick(UCHAR btn, USHORT maxclick);
/* Mendeteksi pelepasan tombol mouse */
USHORT getButtonRelease(UCHAR btn, USHORT maxrel);
/* Mengetahui klik kiri atau klik kanan setelah */
/* fungsi getMousePos dijalankan */
UCHAR getClickMode(void);
USHORT getX(void);
USHORT getY(void);
void hideMouse(void);
void showMouse(void);
/*Memindahkan pointer mouse di posisi tertentu */
void setMousePos(USHORT row, USHORT col);
/*Membatasi posisi koordinat mouse di layar */
void setMouseRegion(USHORT y1, USHORT x1,
USHORT y2, USHORT x2);
};
Mouse::Mouse(void)
{
UCHAR state, button;
asm mov ah, 0x00;
asm mov al, 0x00;
asm int MOUSE_INT;
asm mov state, al;
asm mov button, bl;
this->isReady = state;
this->button = button;
return;
}
Mouse::~Mouse(void)
{
return;
}
UCHAR Mouse::getState(void)
{
return this->isReady;
}
UCHAR Mouse::getNumButton(void)
{
return this->button;
}
UCHAR Mouse::disableMouse(void)
{
UCHAR state;
asm mov ah, 0x00;
asm mov al, 0x1f;
asm int MOUSE_INT;
asm mov state, al;
return state;
}
void Mouse::enableMouse(void)
{
asm mov ax, 0x0020;
asm int MOUSE_INT;
return;
}
USHORT Mouse::getButtonClick(UCHAR btn, USHORT maxclick)
{
USHORT click, nclick, x, y;
click = nclick = x = y = 0;
while (nclick < maxclick)
{
asm mov ah, 0x00;
asm mov al, 0x05;
asm mov bh, 0x00;
asm mov bl, btn;
asm int MOUSE_INT;
asm mov click, bx;
asm mov x, cx;
asm mov y, dx;
nclick += click;
}
this->y = y; this->x = x;
return click;
}
USHORT Mouse::getButtonRelease(UCHAR btn, USHORT maxrel)
{
USHORT rel, nrel, x, y;
rel = nrel = x = y = 0;
while (nrel < maxrel)
{
asm mov ah, 0x00;
asm mov al, 0x06;
asm mov bh, 0x00;
asm mov bl, btn;
asm int MOUSE_INT;
asm mov rel, bx;
asm mov x, cx;
asm mov y, dx;
nrel += rel;
}
this->y = y; this->x = x;
return rel;
}
void Mouse::getMousePos(void)
{
USHORT x, y;
UCHAR cmode;
asm mov ax, 0x0003; /* AH= 0, AL= 3, AX = 3 */
asm int MOUSE_INT;
asm mov x, cx;
asm mov y, dx;
asm mov cmode, bl;
this->y = y;
this->x = x;
this->clickMode = cmode;
return;
}
UCHAR Mouse::getClickMode(void)
{
this->getMousePos();
return this->clickMode;
}
USHORT Mouse::getX(void)
{
return this->x;
}
USHORT Mouse::getY(void)
{
return this->y;
}
void Mouse::hideMouse(void)
{
asm mov ax, 0x0002; /* AH = 0, AL = 2, AX = 2 */
asm int MOUSE_INT;
return;
}
void Mouse::setMousePos(USHORT row, USHORT col)
{
asm mov ax, 0x0004; /* AH = 0, AL = 4, AX = 4 */
asm mov cx, col;
asm mov dx, row;
asm int MOUSE_INT;
return;
}
void Mouse::setMouseRegion(USHORT y1, USHORT x1, USHORT y2, USHORT x2)
{
asm mov ax, 0x0007;
asm mov cx, x1;
asm mov dx, x2;
asm int MOUSE_INT;
asm mov ax, 0x0008;
asm mov cx, y1;
asm mov dx, y2;
asm int MOUSE_INT;
return;
}
void Mouse::showMouse(void)
{
asm mov ax, 0x0001;
asm int MOUSE_INT;
return;
}
#define MOUSE_READY 0xff
#define MOUSE_NOT_READY 0x00
#define MOUSE_SUCCESS 0x1f
#define MOUSE_FAILURE 0xff
#define MOUSE_LEFT_CLICK 0x01
#define MOUSE_RIGHT_CLICK 0x02
#define MOUSE_LEFT_BUTTON 0x00
#define MOUSE_RIGHT_BUTTON 0x01
#define UCHAR unsigned char
#define USHORT unsigned short int
class Mouse
{
private:
UCHAR button;
UCHAR isReady;
UCHAR clickMode;
USHORT x, y;
/* Mengetahui posisi koordinat pointer mouse */
void getMousePos(void);
public:
Mouse(void); /* Konstruktor default */
~Mouse(void); /* Destruktor default */
UCHAR getState(void);
UCHAR getNumButton(void);
UCHAR disableMouse(void);
void enableMouse(void);
/* Mendeteksi penekanan tombol mouse */
USHORT getButtonClick(UCHAR btn, USHORT maxclick);
/* Mendeteksi pelepasan tombol mouse */
USHORT getButtonRelease(UCHAR btn, USHORT maxrel);
/* Mengetahui klik kiri atau klik kanan setelah */
/* fungsi getMousePos dijalankan */
UCHAR getClickMode(void);
USHORT getX(void);
USHORT getY(void);
void hideMouse(void);
void showMouse(void);
/*Memindahkan pointer mouse di posisi tertentu */
void setMousePos(USHORT row, USHORT col);
/*Membatasi posisi koordinat mouse di layar */
void setMouseRegion(USHORT y1, USHORT x1,
USHORT y2, USHORT x2);
};
Mouse::Mouse(void)
{
UCHAR state, button;
asm mov ah, 0x00;
asm mov al, 0x00;
asm int MOUSE_INT;
asm mov state, al;
asm mov button, bl;
this->isReady = state;
this->button = button;
return;
}
Mouse::~Mouse(void)
{
return;
}
UCHAR Mouse::getState(void)
{
return this->isReady;
}
UCHAR Mouse::getNumButton(void)
{
return this->button;
}
UCHAR Mouse::disableMouse(void)
{
UCHAR state;
asm mov ah, 0x00;
asm mov al, 0x1f;
asm int MOUSE_INT;
asm mov state, al;
return state;
}
void Mouse::enableMouse(void)
{
asm mov ax, 0x0020;
asm int MOUSE_INT;
return;
}
USHORT Mouse::getButtonClick(UCHAR btn, USHORT maxclick)
{
USHORT click, nclick, x, y;
click = nclick = x = y = 0;
while (nclick < maxclick)
{
asm mov ah, 0x00;
asm mov al, 0x05;
asm mov bh, 0x00;
asm mov bl, btn;
asm int MOUSE_INT;
asm mov click, bx;
asm mov x, cx;
asm mov y, dx;
nclick += click;
}
this->y = y; this->x = x;
return click;
}
USHORT Mouse::getButtonRelease(UCHAR btn, USHORT maxrel)
{
USHORT rel, nrel, x, y;
rel = nrel = x = y = 0;
while (nrel < maxrel)
{
asm mov ah, 0x00;
asm mov al, 0x06;
asm mov bh, 0x00;
asm mov bl, btn;
asm int MOUSE_INT;
asm mov rel, bx;
asm mov x, cx;
asm mov y, dx;
nrel += rel;
}
this->y = y; this->x = x;
return rel;
}
void Mouse::getMousePos(void)
{
USHORT x, y;
UCHAR cmode;
asm mov ax, 0x0003; /* AH= 0, AL= 3, AX = 3 */
asm int MOUSE_INT;
asm mov x, cx;
asm mov y, dx;
asm mov cmode, bl;
this->y = y;
this->x = x;
this->clickMode = cmode;
return;
}
UCHAR Mouse::getClickMode(void)
{
this->getMousePos();
return this->clickMode;
}
USHORT Mouse::getX(void)
{
return this->x;
}
USHORT Mouse::getY(void)
{
return this->y;
}
void Mouse::hideMouse(void)
{
asm mov ax, 0x0002; /* AH = 0, AL = 2, AX = 2 */
asm int MOUSE_INT;
return;
}
void Mouse::setMousePos(USHORT row, USHORT col)
{
asm mov ax, 0x0004; /* AH = 0, AL = 4, AX = 4 */
asm mov cx, col;
asm mov dx, row;
asm int MOUSE_INT;
return;
}
void Mouse::setMouseRegion(USHORT y1, USHORT x1, USHORT y2, USHORT x2)
{
asm mov ax, 0x0007;
asm mov cx, x1;
asm mov dx, x2;
asm int MOUSE_INT;
asm mov ax, 0x0008;
asm mov cx, y1;
asm mov dx, y2;
asm int MOUSE_INT;
return;
}
void Mouse::showMouse(void)
{
asm mov ax, 0x0001;
asm int MOUSE_INT;
return;
}
#define KEY_INT 0x16 /* Nomor interupsi keyboard*/
#define KEY_BACKSPACE 0x08
#define KEY_RETURN 0x0d
#define KEY_TAB 0x09
#define KEY_SPACE 0x20
#define STATE_RSHIFT 0x01
#define STATE_LSHIFT 0x02
#define STATE_CTRL 0x04
#define STATE_ALT 0x08
#define STATE_SCROLL 0x10
#define STATE_NUM 0x20
#define STATE_CAPS 0x40
#define STATE_INS 0x80
#define NULL 0
#define TRUE 1
class Keyboard
{
private:
Screen *screen;
public:
Keyboard(Screen *scr);/* Konstruktor default */
~Keyboard(void); /* Destruktor default */
UCHAR getKey(void);
UCHAR getSpecialKey(void);
UCHAR *getString(UCHAR *str, UCHAR max);
UCHAR *getPwdString(UCHAR *pwd, UCHAR max);
UCHAR getKeyState(UCHAR key);
void hideCursor(void);
void showCursor(void);
};
Keyboard::Keyboard(Screen *scr)
{
this->screen = scr;
return;
}
Keyboard::~Keyboard(void)
{
return;
}
UCHAR Keyboard::getKey(void)
{
UCHAR key;
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;
return key;
}
UCHAR Keyboard::getSpecialKey(void)
{
UCHAR key;
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, ah;
return key;
}
UCHAR *Keyboard::getString(UCHAR *str, UCHAR max)
{
UCHAR key = 0;
UCHAR i, x, y;
i = 0;
while (TRUE)
{
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;
if ((key == KEY_BACKSPACE) && (i > 0))
{
this->screen->getCursorPos(&y, &x);
this->screen->setCursorPos(y, --x);
this->screen->writeChar(KEY_SPACE);
*(str + i) = NULL;
i--;
}
if ((key >= 32) && (key <= 126) && (i < max))
{
this->screen->getCursorPos(&y, &x);
this->screen->writeChar(key);
this->screen->setCursorPos(y, ++x);
*(str + i) = key; i++;
}
if ((key == KEY_TAB) && (i < max))
{
this->screen->getCursorPos(&y, &x);
this->screen->writeChar(KEY_SPACE);
this->screen->setCursorPos(y, ++x);
*(str + i) = KEY_SPACE; i++;
}
if (key == KEY_RETURN)
{
*(str + i) = NULL;
break;
}
if (i == max) *(str + i) = NULL;
}
return str;
}
UCHAR *Keyboard::getPwdString(UCHAR *pwd, UCHAR max)
{
UCHAR key, i, x, y;
key = i = 0;
while (TRUE)
{
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;
if ((key == KEY_BACKSPACE) && (i > 0))
{
this->screen->getCursorPos(&y, &x);
this->screen->setCursorPos(y, --x);
this->screen->writeChar(KEY_SPACE);
*(pwd + i) = NULL; i--;
}
if ((key >= 32) && (key <= 126) && (i < max))
{
this->screen->getCursorPos(&y, &x);
this->screen->writeChar('*');
this->screen->setCursorPos(y, ++x);
*(pwd + i) = key; i++;
}
if ((key == KEY_TAB) && (i < max))
{
this->screen->getCursorPos(&y, &x);
this->screen->writeChar('*');
this->screen->setCursorPos(y, ++x);
*(pwd + i) = KEY_SPACE; i++;
}
if (key == KEY_RETURN)
{
*(pwd + i) = NULL;
break;
}
if (i == max) *(pwd + i) = NULL;
}
return pwd;
}
UCHAR Keyboard::getKeyState(UCHAR key)
{
UCHAR state;
asm mov ah, 0x02;
asm int KEY_INT;
asm and al, key;
asm mov state, al;
return state;
}
void Keyboard::hideCursor(void)
{
asm mov ah, 0x01;
asm mov ch, 0x20;
asm mov cl, 0x00;
asm int VIDEO_INT;
return;
}
void Keyboard::showCursor(void)
{
asm mov ah, 0x01;
asm mov ch, 0x06;
asm mov cl, 0x07;
asm int VIDEO_INT;
return;
}
#define KEY_BACKSPACE 0x08
#define KEY_RETURN 0x0d
#define KEY_TAB 0x09
#define KEY_SPACE 0x20
#define STATE_RSHIFT 0x01
#define STATE_LSHIFT 0x02
#define STATE_CTRL 0x04
#define STATE_ALT 0x08
#define STATE_SCROLL 0x10
#define STATE_NUM 0x20
#define STATE_CAPS 0x40
#define STATE_INS 0x80
#define NULL 0
#define TRUE 1
class Keyboard
{
private:
Screen *screen;
public:
Keyboard(Screen *scr);/* Konstruktor default */
~Keyboard(void); /* Destruktor default */
UCHAR getKey(void);
UCHAR getSpecialKey(void);
UCHAR *getString(UCHAR *str, UCHAR max);
UCHAR *getPwdString(UCHAR *pwd, UCHAR max);
UCHAR getKeyState(UCHAR key);
void hideCursor(void);
void showCursor(void);
};
Keyboard::Keyboard(Screen *scr)
{
this->screen = scr;
return;
}
Keyboard::~Keyboard(void)
{
return;
}
UCHAR Keyboard::getKey(void)
{
UCHAR key;
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;
return key;
}
UCHAR Keyboard::getSpecialKey(void)
{
UCHAR key;
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, ah;
return key;
}
UCHAR *Keyboard::getString(UCHAR *str, UCHAR max)
{
UCHAR key = 0;
UCHAR i, x, y;
i = 0;
while (TRUE)
{
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;
if ((key == KEY_BACKSPACE) && (i > 0))
{
this->screen->getCursorPos(&y, &x);
this->screen->setCursorPos(y, --x);
this->screen->writeChar(KEY_SPACE);
*(str + i) = NULL;
i--;
}
if ((key >= 32) && (key <= 126) && (i < max))
{
this->screen->getCursorPos(&y, &x);
this->screen->writeChar(key);
this->screen->setCursorPos(y, ++x);
*(str + i) = key; i++;
}
if ((key == KEY_TAB) && (i < max))
{
this->screen->getCursorPos(&y, &x);
this->screen->writeChar(KEY_SPACE);
this->screen->setCursorPos(y, ++x);
*(str + i) = KEY_SPACE; i++;
}
if (key == KEY_RETURN)
{
*(str + i) = NULL;
break;
}
if (i == max) *(str + i) = NULL;
}
return str;
}
UCHAR *Keyboard::getPwdString(UCHAR *pwd, UCHAR max)
{
UCHAR key, i, x, y;
key = i = 0;
while (TRUE)
{
asm mov ah, 0x00;
asm int KEY_INT;
asm mov key, al;
if ((key == KEY_BACKSPACE) && (i > 0))
{
this->screen->getCursorPos(&y, &x);
this->screen->setCursorPos(y, --x);
this->screen->writeChar(KEY_SPACE);
*(pwd + i) = NULL; i--;
}
if ((key >= 32) && (key <= 126) && (i < max))
{
this->screen->getCursorPos(&y, &x);
this->screen->writeChar('*');
this->screen->setCursorPos(y, ++x);
*(pwd + i) = key; i++;
}
if ((key == KEY_TAB) && (i < max))
{
this->screen->getCursorPos(&y, &x);
this->screen->writeChar('*');
this->screen->setCursorPos(y, ++x);
*(pwd + i) = KEY_SPACE; i++;
}
if (key == KEY_RETURN)
{
*(pwd + i) = NULL;
break;
}
if (i == max) *(pwd + i) = NULL;
}
return pwd;
}
UCHAR Keyboard::getKeyState(UCHAR key)
{
UCHAR state;
asm mov ah, 0x02;
asm int KEY_INT;
asm and al, key;
asm mov state, al;
return state;
}
void Keyboard::hideCursor(void)
{
asm mov ah, 0x01;
asm mov ch, 0x20;
asm mov cl, 0x00;
asm int VIDEO_INT;
return;
}
void Keyboard::showCursor(void)
{
asm mov ah, 0x01;
asm mov ch, 0x06;
asm mov cl, 0x07;
asm int VIDEO_INT;
return;
}
#define UCHAR unsigned char
#define VIDEO_INT 0x16
class Screen
{
private:
UCHAR mode, row, col;
UCHAR rownum, colnum;
UCHAR active_page, visual_page;
UCHAR attribute;
public:
Screen(void); // Konstruktor default
Screen(UCHAR mode);
~Screen(void); // Desktruktor default
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 != '\0'; str++)
{
if (this->col > this->colnum)
{
this->row++;
this->col = 0;
}
this->setCursorPos(this->row, this->col);
this->writeChar(*str);
this->col++;
}
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 > 7) 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;
}
#define VIDEO_INT 0x16
class Screen
{
private:
UCHAR mode, row, col;
UCHAR rownum, colnum;
UCHAR active_page, visual_page;
UCHAR attribute;
public:
Screen(void); // Konstruktor default
Screen(UCHAR mode);
~Screen(void); // Desktruktor default
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 != '\0'; str++)
{
if (this->col > this->colnum)
{
this->row++;
this->col = 0;
}
this->setCursorPos(this->row, this->col);
this->writeChar(*str);
this->col++;
}
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 > 7) 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;
}
#include <math.h>
#include <stdlib.h>
#include "screen.cpp"
#include "keyboard.cpp"
int main(void)
{
Screen *layar = new Screen();
Keyboard *tombol = new Keyboard(layar);
unsigned long int tb, hb, jb;
UCHAR *str, str2[16];
UCHAR key='0';
layar->setMode(0x03);
layar->setCursorPos(5, 14);
layar->writeString("Struk Belanja Toko Albani's");
layar->setCursorPos(7, 14);
layar->writeString("Harga Barang = Rp. ");
layar->setCursorPos(7, 38);
str = tombol->getString(str2, 10);
hb = atoi(str);
layar->setCursorPos(8, 14);
layar->writeString("Jumlah Beli = ");
layar->setCursorPos(8, 38);
str = tombol->getString(str2, 10);
jb = atoi(str);
tb = hb * jb;
gcvt(tb, 10, str2);
layar->setCursorPos(9, 14);
layar->writeString("Total Belanja= Rp. ");
layar->setCursorPos(9, 38);
layar->writeString(str2);
layar->setCursorPos(11,14);
layar->writeString("Berapa Jumlah huruf Alphabet ? ");
layar->setCursorPos(13,14);
layar->writeString("[A] 24");
layar->setCursorPos(15,14);
layar->writeString("[B] 26");
layar->setCursorPos(17,14);
layar->writeString("Jawaban Anda : [...]");
tombol->hideCursor();
key = tombol->getKey();
switch (key)
{
case'a':layar->writeString("Salah, jawaban yang benar adalah B !");
tombol->getKey();
delete tombol;
delete layar;
exit(EXIT_FAILURE);
case'b':layar->writeString("Selamat, Anda benar!");
tombol->getKey();
delete tombol;
delete layar;
exit(EXIT_SUCCESS);
default:layar->writeString("Pilihlah A atau B! ");
}
layar->setCursorPos(17, 30);
layar->writeChar(key);
layar->setCursorPos(20, 14);
layar->writeString("Tekan SHIFT ...");
tombol->hideCursor();
while (TRUE)
{
if ((tombol->getKeyState(STATE_RSHIFT)) ||
(tombol->getKeyState(STATE_LSHIFT)))
break;
}
delete layar;
delete tombol;
return EXIT_SUCCESS;
}