Kamis, 23 Juni 2016

Contoh 14 (Coding) dan Gambarnya

#include <stdlib.h>
#include "screen.cpp"
#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 NULL 0x00 /* ASCII 0 */
#define TRUE 1
UCHAR *getString(Screen *scr, UCHAR *str, UCHAR max);
UCHAR *getPwdString(Screen *scr, UCHAR *pwd, UCHAR max);
int main(void)
{
Screen *layar = new Screen();
UCHAR *nama, nama2[16];
UCHAR *sandi, sandi2[21];
UCHAR kar = '*';
layar->setMode(0x03);
layar->setCursorPos(5, 9);
layar->writeString("Username:");
layar->setCursorPos(5, 19);
/* Memasukan username */
nama = getString(layar, nama2, 15);
layar->setCursorPos(6, 9);
layar->writeString("Password:");
layar->setCursorPos(6, 19);
/* Memasukan password */
sandi = getPwdString(layar, sandi2, 20);
layar->setCursorPos(8, 9);
layar->writeString("Selamat datang");
layar->setCursorPos(8, 24);
layar->writeString(nama);
layar->setCursorPos(9, 9);
layar->writeString("Password Anda adalah");
layar->setCursorPos(9, 30);
layar->writeString(sandi);
/* getKey */
asm mov ah, 0x00;
asm int KEY_INT;
delete layar; return EXIT_SUCCESS;
}
UCHAR *getString(Screen *scr, UCHAR *str, 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))
{
scr->getCursorPos(&y, &x);
scr->setCursorPos(y, --x);
scr->writeChar(KEY_SPACE);
*(str + i) = NULL; i--;
}
if ((key >= 32) && (key <= 126) && (i < max))
{
scr->getCursorPos(&y, &x);
scr->writeChar(key);
scr->setCursorPos(y, ++x);
*(str + i) = key; i++;
}
if ((key == KEY_TAB) && (i < max))
{
scr->getCursorPos(&y, &x);
scr->writeChar(KEY_SPACE);
scr->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 *getPwdString(Screen *scr, 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))
{
scr->getCursorPos(&y, &x);
scr->setCursorPos(y, --x);
scr->writeChar(KEY_SPACE);
*(pwd + i) = NULL; i--;
}
if ((key >= 32) && (key <= 126) && (i < max))
{
scr->getCursorPos(&y, &x);
scr->writeChar('*');
scr->setCursorPos(y, ++x);
*(pwd + i) = key; i++;
}
if ((key == KEY_TAB) && (i < max))
{
scr->getCursorPos(&y, &x);
scr->writeChar('*');
scr->setCursorPos(y, ++x);
*(pwd + i) = KEY_TAB; i++;
}
if (key == KEY_RETURN)
{
*(pwd + i) = NULL;
break;
}
if (i == max) *(pwd + i) = NULL;
}
return pwd;
}


Gambarnya Sebagai Berikut :



Penjelasannya :


Fungsi getPwdString pada program contoh14.cpp diatas adalah fungsi yang digunakan untuk memasukan string password. Perhatikanlah pada baris 129 dan 138! Pada baris 129 ketika ada karakter alphanumerik dan simbol yang diketikan maka yang akan ditampilkan adalah sebuah asteriks, demikian juga ketika tombol tab yang ditekan Perbedaan lain antara fungsi getString dan getPwdString adalah karakter tab akan tetap disimpan sebagai tab (ASCII 9) bukan sebagai spasi.

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