BORLAND C ++
Contoh
1-2 :
#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 = 'E';
// AL = 41 heksadesimal, huruf A
in.h.bh = 0x00;
// BH = 0, halaman video
in.h.bl = 0x09;
// BL = 9, warna huruf dan dasar
in.h.ch = 0x00;
// CH dan CL menentukan banyak
in.h.cl = 0x05;
// huruf yang akan dicetak
clrscr();
int86(VIDEO_INT, &in, &out);
getch();
return EXIT_SUCCESS;
]
Contoh 3-4:
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define VIDEO_INT 0x10 //Nonor Interupsi 10h
#define UCHAR unsigned char
void setMode(UCHAR mode); //Deklarasi Fungsi untuk
//Mengubah mode
VIDEO
int main(void)
{
printf("Tekan
ENTER untuk mengubah gerakan. . .\n");
getch();
setMode(0x20); //Ubah mode video
printf("Mode 02 heksadesimal.\n"); // Informasi
printf("Tekan Enter Untuk Kembali Ke Gerakan Normal.
. .");
getch();
setMode(0x20); // Kembali ke mode normal
printf("*Gerakan Normal*\n");
getch();
return EXIT_SUCCESS;
}
void setMode(UCHAR mode)
{
union REGS in, out; // Deklarasi variabel
in.h.ah = 0x09; // Register AH = 0
in.h.al = mode; // Register AL = mode
int86(VIDEO_INT, &in, &out); // Jalankan interupsi
return;
}
Contoh 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\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 = 0x19;
int86(VIDEO_INT, in, reg);
return;
}
Contoh 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', 0x6f); // Cetak huruf 1
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('3', 0x6f); // Cetak huruf 3
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('1', 0x6f); // Cetak huruf 1
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('6', 0x6f); // Cetak huruf 6
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('1', 0x6f); // Cetak huruf 1
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('1', 0x6f); // Cetak huruf 1
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('3', 0x6f); // Cetak huruf 3
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeChar('9', 0x6f); // Cetak huruf 9
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;
}
Contoh 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('>', 0x5f); // Cetak karakter >
setCursorPos(baris, ++kolom); // Pindahkan kursor
writeString(" 13161139 ", 0x9f);
getCursorPos(&baris, &kolom);
setCursorPos(baris, ++kolom);
writeChar('<', 0x5f); // 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;
}
Contoh 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(20); // Warna karakter
textbackground(1); // Warna dasar karakter
cprintf(" ENRIQUE GERARD "); // Cetak string
gotoxy(11, 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
}
Contoh 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(213, 0x17);
setCursorPos(4, 74); writeChar(184, 0x17);
setCursorPos(20, 4); writeChar(192, 0x17);
setCursorPos(20, 74); writeChar(217, 0x17);
for (baris = 5; baris < 20; baris++)
{
setCursorPos(baris, 4); writeChar(179, 0x17);
setCursorPos(baris, 74); writeChar(179, 0x17);
}
for (kolom = 5; kolom < 74; kolom++)
{
setCursorPos(4, kolom); writeChar(205, 0x17);
setCursorPos(20, kolom); writeChar(196, 0x17);
}
setCursorPos(4, 5); writeChar(181, 0x17);
setCursorPos(4, 6);
writeString("ENRIKO GERARDIUS 13161139", 0x8f);
setCursorPos(4, 55); writeChar(198, 0x17);
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)? [ ]", 0x5e);
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;
}
Contoh 10:
#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("13161139");
layar->setAttribute(0xcf);
layar->setActivePage(1);
layar->writeString("Enriko Gerardius");
for (i = 1; i < 11; i++)
{
j = i % 2;
layar->setVisualPage(j);
delay(2000);
}
Tidak ada komentar:
Posting Komentar