Salam Sejahtera
untuk langkah pertama sebelum membuat kita harus buat project baru yang masih FRESH (kosong)
Langkah 1
1. Klik menu File pada menu bar, kemudian pilih dan klik menu New dan pilih menu Project,
2. Klik tombol Browse untuk menentukan nama file dan lokasi penyimpanan project
3. Ketikan nama project pada textbox File name dan klik tombol Open. Textbox Project Path
and Name pada jendela New Target akan berisi nama direktori dimana project disimpan dan
Target Name akan berisi nama project.
4. Pada listbox Target Type pilihlah Application (.exe).
5. Pada combo box Platform pilihlah DOS (Standard).
6. Pada combo box Target Model pilihlah Small.
7. Berilah tanda cek pada check box Class Library.
8. Pada radio button Math Support pilihlah sesuai dengan kondisi
9. Kosongkan semua check box pada pilihan Libraries.
10. Klik tombol OK untuk mulai membuat program.
maka akan muncul jendela New Target
jika sudah di buat projetnya selanjutnya kita mulai untuk menginput teks kedalam project.
LATIHAN 1
Membuat/Mencetak 1 huruf sesuai dengan ke inginan masing-masing
contoh codingannya :
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#define VIDEO_INT 0x10 // BIOS Video Interrupt
int main(void)
{
union REGS in, out; // Deklarasi variabel
in.h.ah = 0x09; // AH = 9 heksadesimal
in.h.al = 'J'; // AL = 4A heksadesimal, huruf J
in.h.bh = 0x00; // BH = 0, halaman video
in.h.bl = 0x07; // BL = 7, warna huruf dan dasar
in.h.ch = 0x00; // CH dan CL menentukan banyak
in.h.cl = 0x01; // huruf yang akan dicetak
clrscr();
int86(VIDEO_INT, &in, &out);
getch();
return EXIT_SUCCESS;
}
#include <dos.h>
#include <stdlib.h>
#define VIDEO_INT 0x10 // BIOS Video Interrupt
int main(void)
{
union REGS in, out; // Deklarasi variabel
in.h.ah = 0x09; // AH = 9 heksadesimal
in.h.al = 'J'; // AL = 4A heksadesimal, huruf J
in.h.bh = 0x00; // BH = 0, halaman video
in.h.bl = 0x07; // BL = 7, warna huruf dan dasar
in.h.ch = 0x00; // CH dan CL menentukan banyak
in.h.cl = 0x01; // huruf yang akan dicetak
clrscr();
int86(VIDEO_INT, &in, &out);
getch();
return EXIT_SUCCESS;
}
Pada latihan kedua kita akan mencoba memberi warna pada font dan huruf double
berikut contoh codingannya :
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#define VIDEO_INT 0x10 // BIOS Video Interrupt
int main(void)
{
clrscr();
asm mov ah, 0x09; // AH = 9 heks.
asm mov al, 0x4A; // AL = 4A heks., huruf J
asm mov bh, 0x00; // BH = 0 heks., halaman layar
asm mov bl, 0x03; // BL = 7 heks., warna huruf
asm mov ch, 0x00; // CH dan CL menentukan banyak
asm mov cl, 0x02; // huruf yang akan dicetak
asm int VIDEO_INT; // Interupsi BIOS 10h
getch();
return EXIT_SUCCESS;
}
Maka outputnya / hasilnya akan seperti ini
LATIHAN 3
Selanjutnya pada latihan ketiga ini kita akan mencoba mode video
apa itu mode video ??
Mode video adalah cara layar monitor menampilkan output, apakah output yang ditampilkan dalam bentuk matriks-matriks teks atau dalam bentuk picture element (pixel).
berikut contoh codingannya
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define VIDEO_INT 0x10 // Nomor interupsi 10h
#define UCHAR unsigned char
void setMode(UCHAR mode); // Deklarasi fungsi untuk
// mengubah mode video
int main(void)
{
printf("Please, push ENTER button to change mode\n");
getch();
setMode(0x04); // Ubah mode video
printf("Hexadecimal Mode\n"); // Informasi
printf("Push ENTER button back to normal mode");
getch();
setMode(0x02); // Kembali ke mode normal
printf("Normal Mode\n");
getch();
return EXIT_SUCCESS;
}
void setMode(UCHAR mode)
{
union REGS in, out; // Deklarasi variabel
in.h.ah = 0x00; // Register AH = 0
in.h.al = mode; // Register AL = mode
int86(VIDEO_INT, &in, &out); // Jalankan interupsi
return;
}
Hasil nya akan seperti ini
Mode vidio pertama
Mode vidio Kedua
Mode vidio Ketiga
pada kali ini kita menggunakan mode clearscreen yang dimana setiap halaman akan berpindah dan menghapus halaman sebelumnya..
LATIHAN 4
nah... pada latihan keempat ini akan memakai efek clearscreen. mari kita coba.
Berikut codingannya
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define VIDEO_INT 0x10 // Nomor interupsi 10h
#define UCHAR unsigned char
void setMode(UCHAR mode); // Deklarasi fungsi untuk
// mengubah mode video
int main(void)
{
printf("Please, push ENTER button to change mode\n");
getch();
clrscr();
setMode(0x01); // Ubah mode video
printf("Hexadecimal mode\n"); // Informasi
printf("Push ENTER button back to normal mode");
getch();
clrscr();
setMode(0x02); // Kembali ke mode normal
printf("Normal mode\n");
getch();
return EXIT_SUCCESS;
}
void setMode(UCHAR mode)
{
asm mov ah, 0x00; // Register AH = 0
asm mov al, mode; // Register AL = mode
asm or al, 0x80; // OR-kan dengan 80 heksadesimal
asm int VIDEO_INT; // Lakukan interupsi
return;
}
Hasilnya akan seperti ini
Mode vidio pertama
Mode video kedua
Mode video ketiga
LATIHAN 5
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define VIDEO_INT 0x10
void getMode(union REGS *reg);
int main(void)
{
union REGS layar;
getMode(&layar);
printf(" Informasi Layar Monitor\n\n");
printf("============================\n");
printf("Banyak kolom\t\t: %d\n", layar.h.ah);
printf("Nomor mode\t\t: %0x\n", layar.h.al);
printf("Halaman tampilan\t: %d\n", layar.h.bh);
getch();
return EXIT_SUCCESS;
}
void getMode(union REGS *reg)
{
union REGS *in;
in->h.ah = 0x4f;
int86(VIDEO_INT, in, reg);
return;
}
LATIHAN 6
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#define VIDEO_INT 0x10
#define UCHAR unsigned char
void getCursorPos(UCHAR *y, UCHAR *x);
void setCursorPos(UCHAR y, UCHAR x);
void writeChar(UCHAR letter, UCHAR attr);
int main(void)
{
UCHAR baris, kolom;
getCursorPos(&baris, &kolom); // Baca posisi kursur
writeChar('1', 0x04); // Cetak huruf 1
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('3', 0x06); // Cetak huruf 3
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('1', 0x02); // Cetak huruf 1
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('6', 0x01); // Cetak huruf 6
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('0', 0x03); // Cetak huruf 0
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('6', 0x07); // Cetak huruf 6
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('8', 0x09); // Cetak huruf 8
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('1', 0x05); // Cetak huruf 1
getch();
return EXIT_SUCCESS;
}
void getCursorPos(UCHAR *y, UCHAR *x) // Baca posisi
{ // kursor
UCHAR row, col;
asm mov ah, 0x03; // Register AH = 3 heksadesimal
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm int VIDEO_INT; // Lakukan interupsi
asm mov row, dh; // Salin register DH ke row
asm mov col, dl; // Salin register DL ke col
*y = row; *x = col; // Salin row ke y, col ke x
return;
}
void setCursorPos(UCHAR y, UCHAR x) // Memindahkan
{ // Posisi kursor
asm mov ah, 0x02; // Register AH = 3 heksadesimal
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm mov dh, y; // Register DH = letak baris
asm mov dl, x; // Register DL = letak kolom
asm int VIDEO_INT; // Lakukan interupsi
return;
}
void writeChar(UCHAR letter, UCHAR attr) // Mencetak
{ // huruf
asm mov ah, 0x09; // Register AH = 9 heksadesimal
asm mov al, letter; // Register AL = hurufnya
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm mov bl, attr; // Register BL = warna huruf
asm mov ch, 0x00; // Register CH dan CL menentukan
asm mov cl, 0x01; // banyak pencetakan
asm int VIDEO_INT; // Lakukan interupsi
return;
}
LATIHAN 7
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#define VIDEO_INT 0x10
#define UCHAR unsigned char
void getCursorPos(UCHAR *y, UCHAR *x);
void setCursorPos(UCHAR y, UCHAR x);
void writeChar(UCHAR letter, UCHAR attr);
void writeString(UCHAR *str, UCHAR attr);
int main(void)
{
UCHAR baris, kolom;
getCursorPos(&baris, &kolom); // Baca posisi kursor
writeChar('>>', 0x1f); // Cetak karakter >
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeString(" Jesthine Nesshal ", 0x5f);
getCursorPos(&baris, &kolom);
setCursorPos(baris, ++kolom);
writeChar('<<', 0x1f); // Cetak karakter <
setCursorPos(baris, ++kolom); // Pindahkan kursor
getch();
return EXIT_SUCCESS;
}
void getCursorPos(UCHAR *y, UCHAR *x) // Baca posisi
{ // kursor
UCHAR row, col;
asm mov ah, 0x03; // Register AH = 3 heksadesimal
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm int VIDEO_INT; // Lakukan interupsi
asm mov row, dh; // Salin register DH ke row
asm mov col, dl; // Salin register DL ke col
*y = row; *x = col; // Salin row ke y, col ke x
return;
}
void setCursorPos(UCHAR y, UCHAR x) // Memindahkan
{ // Posisi kursor
asm mov ah, 0x02; // Register AH = 3 heksadesimal
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm mov dh, y; // Register DH = letak baris
asm mov dl, x; // Register DL = letak kolom
asm int VIDEO_INT; // Lakukan interupsi
return;
}
void writeChar(UCHAR letter, UCHAR attr) // Mencetak
{ // huruf
asm mov ah, 0x09; // Register AH = 9 heksadesimal
asm mov al, letter; // Register AL = hurufnya
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm mov bl, attr; // Register BL = warna huruf
asm mov ch, 0x00; // Register CH dan CL menentukan
asm mov cl, 0x01; // banyak pencetakan
asm int VIDEO_INT; // Lakukan interupsi
return;
}
void writeString(UCHAR *str, UCHAR attr) // Mencetak
{ // string
UCHAR x, y;
getCursorPos(&y, &x); // Simpan posisi kursor
for (; *str != '\0'; str++) // Loop sampai ditemukan
{ // NULL
if (x > 79)
{ // Jika sudah sampai kolom
y++; x = 0; // ke-80, pindah baris dan
} // pindah ke kolom ke-1
setCursorPos(y, x++); // Pindahkan posisi kursor
writeChar(*str, attr); // Cetak per karakter
}
return;
}
LATIHAN 8
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define VIDEO_INT 0x10 // Nomor interupsi video
#define UCHAR unsigned char // Tipe data UCHAR
UCHAR getCharAttr(UCHAR *attr);
int main(void)
{
UCHAR huruf, warna;
clrscr(); // Bersihkan layar
gotoxy(10, 10); textcolor(9); // Warna karakter
textbackground(5); // Warna dasar karakter
cprintf(" Jesthine Nesshal "); // Cetak string
gotoxy(20, 10); // Pindah posisi kursor
huruf = getCharAttr(&warna); // Baca nilai karakter
// dan atributnya
gotoxy(1, 7);
printf("Karakter pada baris 5 kolom 13: %c\n", huruf);
printf("Warna\\Atribut dari karakter : %#x\n", warna);
getch();
return EXIT_SUCCESS;
}
UCHAR getCharAttr(UCHAR *attr) // Fungsi untuk membaca
{ // karakter dan atributnya
union REGS in, out; // pada posisi kursor
in.h.ah = 0x08; // AH = 8 heksadesimal
in.h.bh = 0x00; // BH = 0, halaman layar
int86(VIDEO_INT, &in, &out); // Lakukan interupsi
*attr = out.h.ah; // Salin nilai AH di attr
return out.h.al; // Kembalikan nilai AL
}
LATIHAN 9
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define VIDEO_INT 0x10
#define UCHAR unsigned char
void setMode(UCHAR mode);
void getCursorPos(UCHAR *y, UCHAR *x);
void setCursorPos(UCHAR y, UCHAR x);
void writeChar(UCHAR letter, UCHAR attr);
void writeString(UCHAR *str, UCHAR attr);
int main(void)
{
UCHAR baris, kolom;
UCHAR pilih;
setMode(3);
setCursorPos(4, 4); writeChar(3, 0x4);
setCursorPos(4, 74); writeChar(3, 0x4);
setCursorPos(20, 4); writeChar(3, 0x4);
setCursorPos(20, 74); writeChar(3, 0x4);
for (baris = 5; baris < 20; baris++)
{
setCursorPos(baris, 4); writeChar(3, 0x4);
setCursorPos(baris, 74); writeChar(3, 0x4);
}
for (kolom = 5; kolom < 74; kolom++)
{
setCursorPos(4, kolom); writeChar(3, 0x4);
setCursorPos(20, kolom); writeChar(3, 0x4);
}
setCursorPos(4, 5); writeChar(3, 0x4);
setCursorPos(4, 6);
writeString("Jesthine Nesshal 13160681", 0x7);
setCursorPos(4, 31); writeChar(3, 0x4);
for (baris = 20; baris < 20; baris++)
{
for (kolom = 20; kolom < 74; kolom++)
{
setCursorPos(baris, kolom);
writeChar(0x10, 0x1e);
}
}
setCursorPos(19, 47);
writeString("Akhiri program (Y/T)? [ ]", 0x7);
for (;;)
{
setCursorPos(19, 71);
pilih = getch();
writeChar(pilih, 0x1e);
if ((pilih == 'Y') || (pilih == 'y'))
break;
}
return EXIT_SUCCESS;
}
void setMode(UCHAR mode) // Mengubah mode
{ // tampilan layar
asm mov ah, 0x00; // Register AH = 0
asm mov al, mode; // Register AL = mode
asm int VIDEO_INT // Lakukan interupsi
return;
}
void getCursorPos(UCHAR *y, UCHAR *x) // Baca posisi 20
{ // kursor
UCHAR row, col;
asm mov ah, 0x03; // Register AH = 3 heksadesimal
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm int VIDEO_INT; // Lakukan interupsi
asm mov row, dh; // Salin register DH ke row
asm mov col, dl; // Salin register DL ke col
*y = row; *x = col; // Salin row ke y, col ke x
return;
}
void setCursorPos(UCHAR y, UCHAR x) // Memindahkan
{ // Posisi kursor
asm mov ah, 0x02; // Register AH = 3 heksadesimal
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm mov dh, y; // Register DH = letak baris
asm mov dl, x; // Register DL = letak kolom
asm int VIDEO_INT; // Lakukan interupsi
return;
}
void writeChar(UCHAR letter, UCHAR attr) // Mencetak
{ // huruf
asm mov ah, 0x09; // Register AH = 9 heksadesimal
asm mov al, letter; // Register AL = hurufnya
asm mov bh, 0x00; // Register BH = 0 heksadesimal
asm mov bl, attr; // Register BL = warna huruf
asm mov ch, 0x00; // Register CH dan CL menentukan
asm mov cl, 0x01; // banyak pencetakan
asm int VIDEO_INT; // Lakukan interupsi
return;
}
void writeString(UCHAR *str, UCHAR attr) // Mencetak
{ // string
UCHAR x, y;
getCursorPos(&y, &x); // Simpan posisi kursor
for (; *str != '\0'; str++) // Loop sampai ditemukan
{ // NULL
if (x > 79)
{ // Jika sudah sampai kolom
y++; x = 0; // ke-80, pindah baris dan
} // pindah ke kolom ke-1
setCursorPos(y, x++); // Pindahkan posisi kursor
writeChar(*str, attr); // Cetak per karakter
}
return;
}
Langkah pertama untuk memulai Contoh 10
buat dahulu screen cpp
buka borlan c++ lalu buka lembar baru dengan teks edit
lalu ketik
LATIHAN 10
/*
screen.cpp
Class library untuk operasi layar monitor.
Hak Cipta Pebi Yudha K.
April 2009
Disusun sebagai contoh program
Modul Praktikum Pemrograman C++ Lanjutan
AMIK BSI - Jakarta
*/
#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;
}
Berikut ini codingannya
#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("13160681");
layar->setAttribute(0xcf);
layar->setActivePage(1);
layar->writeString("Jesthine Nesshal");
for (i = 1; i < 11; i++)
{
j = i % 2;
layar->setVisualPage(j);
delay(1000);
}
delete layar;
return EXIT_SUCCESS;
}