Rabu, 29 Juni 2016

Contoh Keyboard.cpp (Coding)

#define KEY_INT 0x16 /* Nomor interupsi keyboard */
#define KEY_BACKSPACE 0x08 /* Tombol Backspace */
#define KEY_RETURN 0x0d /* Tombol Enter */
#define KEY_TAB 0x09 /* Tombol Tab */
#define KEY_SPACE 0x20 /* Tombol spasi */
#define STATE_RSHIFT 0x01 /* Status Shift Kanan */
#define STATE_LSHIFT 0x02 /* Status Shift Kiri */
#define STATE_CTRL 0x04 /* Status CTRL */
#define STATE_ALT 0x08 /* Status ALT */
#define STATE_SCROLL 0x10 /* Status Scroll Lock */
#define STATE_NUM 0x20 /* Status Num Lock */
#define STATE_CAPS 0x40 /* Status Caps Lock */
#define STATE_INS 0x80 /* Status INS */
#define NULL 0 /* ASCII 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; /* Register AH = 0 */
asm int KEY_INT; /* Lakukan interupsi */
asm mov key, al; /* Salin nilai register AH ke key */
return key;
}
UCHAR Keyboard::getSpecialKey(void)
{
UCHAR key;
asm mov ah, 0x00; /* Register AH = 0 */
asm int KEY_INT; /* Lakukan interupsi 16 heksadesimal */
asm mov key, ah; /* Salin nilai di AH ke variabel key */
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_TAB; 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; /* Register AH = 2 */
asm int KEY_INT; /* Lakukan interupsi 16 heksadesimal */
asm and al, key; /* AND-kan register AL sesuai tombol */
asm mov state, al; /* Salin nilai register AL ke state */
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

Posting Lebih Baru Posting Lama Beranda

Diberdayakan oleh Blogger.

Facebook

Popular Posts

Formulir Kontak

Nama

Email *

Pesan *

Subscribe Here

Ad Home

Random Posts

Recent Posts

Recent

Header Ads

Popular Posts

Flickr

Newsletter

Subscribe Our Newsletter

Enter your email address below to subscribe to our newsletter.

Ad Banner

About Us

Random Posts

Popular Posts

 

Followers

 

Social Share Icons

Templates by Nano Yulianto | CSS3 by David Walsh | Powered by {N}Code & Blogger