#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;
}
0 komentar:
Posting Komentar