Contoh 10

Contoh cpp 10

screen.cpp

#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);   // Konstruktor default
Screen(UCHAR mode);
~Screen(void);  // Destruktor 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);

};  // Akhir prototype class Screen
Screen::Screen(void)  // Konstruktor default.
{                     // Menset layar pada
UCHAR mode;         // mode 25 baris dan
                    // 80 kolom, warna huruf
this->row = 0;      // abu-abu dan latar
this->col = 0;      // hitam, 16 warna.

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)  // Konstruktur
{                           // dengan
this->setMode(mode);      // parameter mode
                        // layar.
return;
}
Screen::~Screen(void)  // Destruktor default.
{                      // Tidak melakukan
return;              // apapun.
}

void Screen::setMode(UCHAR mode) // Memilih
{                                // mode
this->mode = mode;             // layar.
this->active_page = 0;
this->visual_page = 0;
this->rownum = 25;
switch (mode)  // Menentukan banyak kolom
{              // berdasarkan nomor 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)  // Mengetahui
{  // mode layar.
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;        // Menentukan posisi
this->col = x;        // kursor.
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;     // Mengetahui posisi
*x = this->col;     // kursor.

return;
}

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

asm mov ah, 0x09;     // Menuliskan satu
asm mov al, letter;   // karakter dan
asm mov bh, page;     // atributnya
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++;       // Mencetak rangkaian
this->col = 0;     // karakter (string).
}

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

return;
}

void Screen::setAttribute(UCHAR attr)
{
this->attribute = attr;   // Mengubah warna
                        // huruf dan warna
return;                   // latar.
}

UCHAR Screen::getCharAttr(UCHAR *attr)
{
UCHAR page = this->active_page;
UCHAR letter, attribute;
asm mov ah, 0x08;    // Mengetahui
asm mov bh, page;        // karakter dan
asm int VIDEO_INT;       // atributnya pada
asm mov attribute, ah;   // posisi kursor.
asm mov letter, al;

this->attribute = *attr = attribute;

return letter;
}

void Screen::setActivePage(UCHAR page)
{
this->active_page = page;  // Menentukan
                            // halaman aktif.
return;
}

UCHAR Screen::getActivePage(void)
{                          // Mengetahui

return this->active_page;  // halaman aktif.
}

void Screen::setVisualPage(UCHAR page)
{
if (page > 7) page = 0;
this->visual_page = page;
asm mov ah, 0x05;    // Menentukan halaman
asm mov al, page;    // yang ditampilkan.
asm int VIDEO_INT;

return;
}

UCHAR Screen::getVisualPage(void)
{                            // Mengetahui
return this->visual_page;  // halaman yang
}                           // ditampilkan.

void Screen::cls(void)
{                           // Membersihkan
UCHAR mode = this->mode;  // tampilan layar
                        // serta
this->row = 0;            // memposisikan
this->col = 0; // kursor di 0, 0.

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

return;
}

latihan10.cpp

#include <dos.h>
#include <stdlib.h>
#include "screen.cpp" // Header screen.cpp

int main(void)
{
UCHAR i, j;
Screen *layar = new Screen();

layar->setAttribute(0x9f);
layar->setActivePage(0);
layar->writeString("13160482");
layar->setAttribute(0xcf);
layar->setActivePage(1);
layar->writeString("Danu Bradenli");

for (i = 1; i < 11; i++)
{
j = i % 2;
layar->setVisualPage(j);
delay(2000);
}

delete layar;
return EXIT_SUCCESS;
}

Output



Komentar