home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
OMEGA2
/
OMSCREEN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-25
|
12KB
|
564 lines
//
// *************************************************************************
// * *
// * OMEGA C++ Windowing Class Library *
// * ================================= *
// * *
// * Copyright 1991,92 Tom Clancy *
// * Submitted to the public domain, April 1992 *
// * *
// *************************************************************************
// * *
// * Screen Class Methods (low level screen routines) *
// * *
// *************************************************************************
//
#include <dos.h>
#include <conio.h>
#include <mem.h>
#include <string.h>
#include "fastwrit.hpp"
#include "omscreen.hpp"
//
// oScreen Static Data Members
//
int sLen=25;
int sWid=80;
int Oldvmode=0;
int oScreen::vActive=FALSE;
unsigned vseg;
unsigned vofs;
unsigned vvseg;
unsigned vvofs;
extern int FWIDTH;
static int vidmodes[8][3] = {
0x3, 25, 80,
0x50, 30, 80,
0x51, 43, 80,
0x52, 60, 80,
0x53, 25,132,
0x58, 30,132,
0x59, 43,132,
0x5A, 60,132,
};
unsigned char boxstyles[2][6] = {
0xC4,0xB3,0xDA,0xBF,0xC0,0xD9,
0xCD,0xBA,0xC9,0xBB,0xC8,0xBC,
};
#define VIDEO 0x10
union REGS regs;
int video_mode(void) {
regs.h.ah=0x0f;
int86(VIDEO,®s,®s);
return regs.h.al;
}
void OMEGA_SETUP() {
//initmouse();
Oldvmode=video_mode();
if(Oldvmode==7) {
vseg=vvseg=0xB000;
vofs=vvofs=0;
}
else {
vseg=vvseg=0xB800;
vofs=vvofs=0;
}
FWIDTH=sWid*2;
}
oScreen::oScreen() {
FGcolor=WHITE;
BKcolor=BLACK;
Fillchar=32;
}
int oScreen::getscreenwid() {
return sWid;
}
int oScreen::getscreenlen() {
return sLen;
}
unsigned oScreen::getvvseg() {
return vvseg;
}
unsigned oScreen::getvvofs() {
return vvofs;
}
void oScreen::writeat(int x, int y, int fg, int bk, char *str) {
hidemouse();
fastwritestr(x,y,(char)fg,(char)bk,(char far *)str,vvseg,vvofs);
}
void oScreen::plainwriteat(int x, int y, char *str) {
hidemouse();
plainwritestr(x,y,(char far *)str,vvseg,vvofs);
}
void oScreen::chwriteat(int x, int y, int fg, int bk, unsigned char c) {
hidemouse();
fastwritech(x,y,(char)fg,(char)bk,c,vvseg,vvofs);
}
void oScreen::plainchwriteat(int x, int y, unsigned char c) {
hidemouse();
plainwritech(x,y,c,vvseg,vvofs);
}
void oScreen::writecenter(int y, int fg, int bk, char *str) {
writeat((sWid/2)-(strlen(str)/2),y,fg,bk,str);
}
void oScreen::writeshadow(int x, int y) {
hidemouse();
shadowchar(x,y,vvseg,vvofs);
}
void oScreen::writebetween(int y, int x1, int x2, int fg, int bk, char *str) {
int start, len;
start=x1;
len=strlen(str);
len=(x2-start-len) /2;
start=start+len+1;
writeat(start,y,fg,bk,str);
}
void oScreen::attribln(int y, int x1, int x2, int fg, int bk) {
hidemouse();
fastattrib(y,x1,x2,(char)fg,(char)bk,vvseg,vvofs);
}
void oScreen::fillarea(int x, int y, int x2, int y2, int fg, int bk, char c) {
register char i;
char *str;
str=new char[sWid+1];
setmem(str,sWid,c);
str[(x2-x)+1]='\0';
for(i=y; i<=y2; i++)
writeat(x,i,fg,bk,str);
delete str;
}
void oScreen::fillscreen(int fg, int bk, char c) {
fillarea(1,1,sWid,sLen,(char)fg,(char)bk,c);
}
void oScreen::clearline(int y, int fg, int bk) {
fillarea(1,y,getscreenwid(),y,fg,bk,32);
}
void oScreen::clearline(int y, int x1, int x2, int fg, int bk) {
fillarea(x1,y,x2,y,fg,bk,32);
}
void oScreen::attribarea(int x, int y, int x2, int y2, int fg, int bk) {
register int i;
for(i=y; i<=y2; i++)
attribln(i,x,x2,(char)fg,(char)bk);
}
void oScreen::attribscreen(int fg, int bk) {
attribarea(1,1,sWid,sLen,(char)fg,(char)bk);
}
void oScreen::clrscr() {
fillarea(1,1,sWid,sLen,FGcolor,BKcolor,Fillchar);
}
void oScreen::drawline(int y, int x1, int x2, int fg, int bk, int style) {
if(style<0 || style>1) style=1;
fillarea(x1,y,x2,y,fg,bk,boxstyles[style][vertbar]);
}
void oScreen::drawbox(int x, int y, int x2, int y2, int fg, int bk, int style) {
char *line = new char[(x2-x)+2];
memset(line,32,(x2-x)+2);
line[(x2-x)+1]='\0';
line[0]=boxstyles[style][horizbar];
line[x2-x]=boxstyles[style][horizbar];
drawline(y,x,x2,fg,bk,style);
chwriteat(x,y,fg,bk,boxstyles[style][upperleft]);
chwriteat(x2,y,fg,bk,boxstyles[style][upperright]);
register int i;
for(i=y+1; i<y2; i++)
writeat(x,i,fg,bk,line);
drawline(y2,x,x2,fg,bk,style);
chwriteat(x,y2,fg,bk,boxstyles[style][bottomleft]);
chwriteat(x2,y2,fg,bk,boxstyles[style][bottomright]);
delete line;
}
void oScreen::drawhollowbox(int x, int y, int x2, int y2, int fg, int bk, int style) {
char *line = new char[(x2-x)+2];
memset(line,32,(x2-x)+2);
line[(x2-x)+1]='\0';
line[0]=boxstyles[style][horizbar];
line[x2-x]=boxstyles[style][horizbar];
fillarea(x,y+1,x,y2-1,fg,bk,boxstyles[style][horizbar]);
fillarea(x2,y+1,x2,y2-1,fg,bk,boxstyles[style][horizbar]);
drawline(y,x,x2,fg,bk,style);
drawline(y2,x,x2,fg,bk,style);
chwriteat(x,y,fg,bk,boxstyles[style][upperleft]);
chwriteat(x2,y,fg,bk,boxstyles[style][upperright]);
chwriteat(x,y2,fg,bk,boxstyles[style][bottomleft]);
chwriteat(x2,y2,fg,bk,boxstyles[style][bottomright]);
delete line;
}
// Absolute screen writing functions
void oScreen::abswritecenter(int y, int fg, int bk, char *str) {
hidemouse();
fastwritestr((sWid/2)-(strlen(str)/2),y,(char)fg,(char)bk,str,vvseg,vvofs);
}
void oScreen::abswritebetween(int y, int x1, int x2, int fg, int bk, char *str) {
hidemouse();
int start, len;
start=x1;
len=strlen(str);
len=(x2-start-len) /2;
start=start+len+1;
fastwritestr(start,y,(char)fg,(char)bk,str,vvseg,vvofs);
}
void oScreen::absfillarea(int x, int y, int x2, int y2, int fg, int bk, char c) {
hidemouse();
register char i;
char *str;
str=new char[sWid+1];
setmem(str,sWid,c);
str[(x2-x)+1]='\0';
for(i=y; i<=y2; i++)
fastwritestr(x,i,(char)fg,(char)bk,str,vvseg,vvofs);
delete str;
}
void oScreen::absfillscreen(int fg, int bk, char c) {
absfillarea(1,1,sWid,sLen,(char)fg,(char)bk,c);
}
void oScreen::absclearline(int y, int fg, int bk) {
absfillarea(1,y,getscreenwid(),y,fg,bk,32);
}
void oScreen::absclearline(int y, int x1, int x2, int fg, int bk) {
absfillarea(x1,y,x2,y,fg,bk,32);
}
void oScreen::absattribarea(int x, int y, int x2, int y2, int fg, int bk) {
hidemouse();
register int i;
for(i=y; i<=y2; i++)
fastattrib(i,x,x2,(char)fg,(char)bk,vvseg,vvofs);
}
void oScreen::absattribscreen(int fg, int bk) {
absattribarea(1,1,sWid,sLen,(char)fg,(char)bk);
}
void oScreen::absclrscr() {
absfillarea(1,1,sWid,sLen,FGcolor,BKcolor,Fillchar);
}
void oScreen::absdrawline(int y, int x1, int x2, int fg, int bk, int style) {
hidemouse();
if(style<0 || style>1) style=1;
register char i;
char *str;
str=new char[sWid+1];
setmem(str,sWid,boxstyles[style][vertbar]);
str[(x2-x1)+1]='\0';
fastwritestr(x1,y,(char)fg,(char)bk,str,vvseg,vvofs);
delete str;
}
void oScreen::absdrawbox(int x, int y, int x2, int y2, int fg, int bk, int style) {
hidemouse();
char *line = new char[(x2-x)+2];
memset(line,32,(x2-x)+2);
line[(x2-x)+1]='\0';
line[0]=boxstyles[style][horizbar];
line[x2-x]=boxstyles[style][horizbar];
absdrawline(y,x,x2,fg,bk,style);
fastwritech(x,y,(char)fg,(char)bk,boxstyles[style][upperleft],vvseg,vvofs);
fastwritech(x2,y,(char)fg,(char)bk,boxstyles[style][upperright],vvseg,vvofs);
register int i;
for(i=y+1; i<y2; i++)
fastwritestr(x,i,(char)fg,(char)bk,line,vvseg,vvofs);
absdrawline(y2,x,x2,fg,bk,style);
fastwritech(x,y2,(char)fg,(char)bk,boxstyles[style][bottomleft],vvseg,vvofs);
fastwritech(x2,y2,(char)fg,(char)bk,boxstyles[style][bottomright],vvseg,vvofs);
delete line;
}
void oScreen::setvidmode(int m) {
if(m<0 || m>7) return;
regs.h.ah=0;
regs.h.al=vidmodes[m][0];
int86(VIDEO,®s,®s);
if(video_mode()==vidmodes[m][0]) {
sLen=vidmodes[m][1];
sWid=vidmodes[m][2];
FWIDTH=sWid*2;
}
else
restoreoldvmode();
}
int oScreen::setvga43() {
regs.h.ah=0x12;
regs.h.al=1;
regs.h.bl=0x30;
int86(VIDEO,®s,®s);
if(regs.x.ax==0x12) {
regs.h.ah=0;
regs.h.al=3;
int86(VIDEO,®s,®s);
sLen=43;
sWid=80;
FWIDTH=sWid*2;
return 1;
}
return 0;
}
int oScreen::setvga50() {
regs.h.ah=0x1A;
regs.h.al=0;
int86(VIDEO,®s,®s);
unsigned char look=regs.h.bl;
if(look==8) {
regs.x.ax=0x1112;
regs.h.bl=0x00;
int86(VIDEO,®s,®s);
sLen=50;
sWid=80;
FWIDTH=sWid*2;
return 1;
}
return 0;
}
void oScreen::restoreoldvmode() {
regs.h.ah=0;
regs.h.al=Oldvmode;
int86(VIDEO,®s,®s);
sLen=25;
sWid=80;
FWIDTH=sWid*2;
}
void oScreen::cursoron(void) {
regs.x.ax=0x100;
regs.x.cx=0x607;
int86(VIDEO,®s,®s);
}
void oScreen::cursoroff(void) {
regs.x.ax=0x100;
regs.x.cx=0x2000;
int86(VIDEO,®s,®s);
}
void oScreen::blockcursor(void) {
regs.h.ah=1;
regs.h.ch=0;
regs.h.cl=15;
int86(VIDEO,®s,®s);
}
void oScreen::linecursor(void) {
regs.h.ah=1;
regs.h.ch=6;
regs.h.cl=7;
int86(VIDEO,®s,®s);
}
void oScreen::movexy(int x, int y) {
regs.h.ah=2;
regs.h.bh=0;
regs.h.dh=y-1;
regs.h.dl=x-1;
int86(VIDEO,®s,®s);
}
void oScreen::wherexy(int &x, int &y) {
regs.h.ah=3;
regs.h.bh=0;
int86(VIDEO,®s,®s);
x=regs.h.dl;
y=regs.h.dh;
}
void oScreen::save_screen() {
hidemouse();
screenbuff=new char[sWid*sLen*2];
movedata(vvseg,vvofs,FP_SEG(screenbuff),FP_OFF(screenbuff),sWid*sLen*2);
}
void oScreen::show_screen() {
hidemouse();
if(screenbuff!=NULL)
movedata(FP_SEG(screenbuff),FP_OFF(screenbuff),vvseg,vvofs,sWid*sLen*2);
}
void oScreen::restore_screen() {
if(screenbuff!=NULL) {
show_screen();
delete screenbuff;
}
}
char *oScreen::save_image(int x, int y, int x2, int y2, image &im) {
register int i;
char *c;
im.len=y2-y+1;
im.wid=x2-x+1;
im.i=new char[im.len*im.wid*2];
c=im.i;
hidemouse();
for(i=y; i<=y2; i++) {
movedata(vvseg,vvofs+(((i-1)*FWIDTH)+(x-1)*2),FP_SEG(c),FP_OFF(c),im.wid*2);
c+=im.wid*2;
}
return im.i;
}
void oScreen::show_image(int x, int y, image im) {
register int i;
char *c;
c=im.i;
hidemouse();
for(i=y; i<y+im.len; i++) {
movedata(FP_SEG(c),FP_OFF(c),vvseg,vvofs+(((i-1)*FWIDTH)+(x-1)*2),im.wid*2);
c+=im.wid*2;
}
}
void oScreen::restore_image(int x, int y, image &im) {
if(im.i!=NULL) {
show_image(x,y,im);
delete im.i;
}
}
void oScreen::activate_virtual() {
hidemouse();
vscreen=new char[sWid*sLen*2];
if(vscreen) {
vActive=TRUE;
vvseg=FP_SEG(vscreen);
vvofs=FP_OFF(vscreen);
movedata(vseg,0,vvseg,vvofs,sWid*sLen*2);
}
}
void oScreen::deactivate_virtual() {
if(vActive) {
display_virtual();
delete vscreen;
vvseg=vseg;
vvofs=vofs;
vActive=FALSE;
}
}
void oScreen::display_virtual() {
hidemouse();
movedata(vvseg,vvofs,vseg,0,sWid*sLen*2);
}