256 Colors
256 Colors
//
// Name: About 256 Colors in Dos with 80
// 0*600 resolution Using CPP/C
// Description:This program as header cl
// ass will able you to use graphics output
// quality of 600*800 solution with 256 col
// or
//this mode is satisfatory to identify any image.
//this mode generally not provided by Turbo C++ Compiler
//Some function are also provided for the
// By: Shyam Sunder Verma
//
// Assumes:It must be used only with MsD
// OS. Because some convention I have made
// regarding to memory model of program ***
// * Use it on WIN98 not on WinXP
//(if you want then on XP use only 640*480 resolution check function InitGraph()
for more details......)
//
// Side Effects:If used on WIN XP it wil
// l cause monitor to run out of frequency
//
//This code is copyrighted and has// limited warranties.Please see http://
// www.Planet-Source-Code.com/vb/scripts/Sh
// owCode.asp?txtCodeId=8603&lngWId=3//for details.//***********************
***************
//
// =====================================
// =====
// ==============Author=================
// =====
// =====================================
// =====
// SHYAM SUNDER VERMA
// Information Technology
// Final Year (MLV Textile Institute) Ra
// jasthan University
// [email protected]@yahoo.com
//
// Homepage : "http://www.geocities.com/
// ssv445 "
//It have some intresting stuff on C and
// C++
//======================================
// =============
//============== Introduction ==========
// ============
//======================================
// =============
// This program as header class will abl
// e you to use graphics
// output quality of 600*800 resolution
// with 256 color
// This mode is satisfatory to identify
// any image.
// This mode generally not provided by T
// urbo C++ Compiler
// Some function are also provided for t
// he
//======================================
// =============
//============== Pre-caution ===========
// ===========
//======================================
// =============
// It must be used only with MsDOS. Beca
// use some convention
// I have made regarding to memory model
// of program
// **** Use it on WIN98 not on WinXP
// (if you want then on XP use only 640*
// 480 resolution
// check function InitGraph() for more d
// etails......)
//======================================
// =============
//=================Description==========
// =============
//======================================
// =============
// The program have three classes
// 1 VDU
// 2 Color
// 3 Box with one LineStyle class
// use these classes as
// VDU for display any char at any pos w
// ith any color---
// (a)putChar(int row,int column ,char c
// h, ClassColor colorOfChar=DefaultColor)
// (b)putString (int r,int c,char *ch,Cl
// assColor clr=DefaultColor)
// (c)putLong(int r,int c,long ch,ClassC
// olor clr=DefaultColor)
// (d)putDouble (int r,int c,double ch,C
// lassColor clr=DefaultColor)
// (e)changeColor (int r, int c,ClassCol
// or clr) --> It changes color of any p
// osition
// use Color class for
// (a)SetColor(unsigned char fg,unsigned
// char bg ,unsigned char bl);
// (b)SetColor(ClassColor cc1);
// (c)MakeColor(unsigned char fg,unsigne
// d char bg ,unsigned char bl);
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define round(a) ((int)(a+0.5))
#define MINX 0
#define MINY 0
#define MAXX 799
#define MAXY 599
#define MAXX1 800
#define MAXY1 600
#include<iostream.h>
void drawline(int xa, int ya, int xb, int yb);
const int MIDX=400,MIDY=300;
int CentreX=400;
int CentreY=300;
char huge Timg[MAXX][MAXY];
unsigned char huge ColorLUT[768];
union REGS in, out,reg ;
struct SREGS inreg ;
// ----pellate setting
typedef unsigned int Word;
typedef unsigned char Byte;
typedef struct
{
Byte Red, Grn, Blu;
}RGB;
class sColor
{
typedef RGB PaletteRegister[255];
PaletteRegister Color,colorP;
void ClearPalette(PaletteRegister Color)
{
Word i;
for(i=0; i<=255; i++)
{
Color[i].Red=0;
Color[i].Grn=0;
Color[i].Blu=0;
}
}
void SetPalette(PaletteRegister Hue)
{
reg.x.ax=0x1012;
segread(&inreg);
inreg.es=inreg.ds;
reg.x.bx=0;reg.x.cx=256;
reg.x.dx=(int)&Hue[0];
int86x(0x10,&in,&out,&inreg);
}
void InitPalette(PaletteRegister Color)
{
Word i=0;
int r,g,b;
for(r=0;r<6;r++)
for(g=0;g<6;g++)
for(b=0;b<6;b++)
{
Color[i].Red=r*51;
Color[i].Grn=g*51;
Color[i].Blu=b*51;
i++;
}
}
}; //--------------------------------------
// -------------
class CGBase
{
private:
int gd,gm,gr;
union REGS i, o,reg;
struct SREGS inreg;
int fc,bc;
void setsvga ( int m )
{
i.x.ax = 0x4f02 ;
i.x.bx = m ;
int86 ( 16, &i, &o ) ;
};
void set_vesa_seg ( int bank_number )
{
union REGS i, o ;
i.x.ax = 0x4F05 ;
i.x.bx = 0 ;
i.x.dx = bank_number ;
int86 ( 16, &i, &o ) ;
};
void putpixel ( int x, int y, unsigned char colo
r )
{
unsigned short curr_vesa_seg = 0xffff ;
unsigned short vesa_seg,vesa_offset ;
unsigned long seg_size = 0xffff + 1L ;
unsigned long offset ;
offset = ( ( unsigned long ) y * ( unsigned lon
g ) (MAXX+1) + ( unsigned long ) x ) ;
vesa_seg = offset / seg_size ;
vesa_offset = offset % seg_size ;
if ( vesa_seg != curr_vesa_seg )
{
set_vesa_seg ( vesa_seg ) ;
curr_vesa_seg = vesa_seg ;
}
pokeb ( 0xA000, ( unsigned ) vesa_offse
t, color) ;
};
void line(int xa, int ya, int xb, int yb
,int c)
{
int dx=xb-xa,dy=yb-ya,steps,k;
float xi,yi,x=xa,y=ya;
if(abs(dx) > abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xi=dx/(float)steps;
yi=dy/(float)steps;
putpixel(round(x),round(y),c);
for(k=0;k<steps;k++)
{
x+=xi;
y+=yi;
putpixel(round(x
),round(y),fc);
}
};
void InitGraph()
{
setsvga ( 0x103) ;// ***
fro Win XP use 0x101 for 640*480*256
InitPalette(colorP);
SetPalette(colorP);
// 103 for 800*600*256
};
void FinishGraph()
{
setsvga (0x03) ;
};
void Reset()
{
FinishGr
aph();
InitGrap
h();
Boundary
(1);
Axis(2);
} ;
public:
CGBase()
{
InitGrap
h();
ClearPor
t();
ClearPor
t();
Axis(GRE
EN);
fc=1;
bc=0;
}
void put
Image(int left,int top,int right,int bot)
{
unsigne
d short curr_vesa_seg = 0xffff ;
unsigne
d short vesa_seg,vesa_offset ;
unsigne
d long seg_size = 0xffff + 1L ;
unsigne
d long offset ;
int t;
if(left
>right)
{
t=left;
left=right;
right=t;
}
if(top>bot)
{
t=bot;
bot=top;
top=t;
}
char color;
for(int x=left ; x<=right;x++)
for(int y=top ; y<=bot;y++)
{
color=Timg[x][y];
offset = ( ( unsigned long ) y * ( unsigned long ) (MAXX+1) + ( unsigned long )
x ) ;
vesa_seg = offset / seg_size ;
vesa_offset = offset % seg_size ;
if ( vesa_seg != curr_vesa_seg )
{
set_vesa_seg ( vesa_seg ) ;
curr_vesa_seg = vesa_seg ;
}
pokeb ( 0xA000, ( unsigned ) vesa_offset, color ) ;
}
};
~CGBase()
{
FinishGraph();
};
void ClearPort()
{
for( int i=0;i<MAXX;i++)
for(int j=0;j<MAXY;j++)
Timg[i][j]=0;
putImage(MINX,MINY,MAXX,MAXY);
} ;
void PutPixel(int x, int y , int c ,int rx=CentreX,int ry=Centre
Y)
{
if( (rx+x)<MAXX &&(rx+x)>MINX && (ry-y)<MAXY &&(
ry-y)>MINY )
putpixel(rx+x,ry-y,c);
};
void Axis(int c)
{
LineAbs(CentreX,MINY,CentreX,MAXY,c);
LineAbs(MINX,CentreY,MAXX,CentreY,c);
} ;
void Boundary(int c)
{
RectangleAbs(MINX,MINY,MAXX,MAXY,c);
};
void LineAbs(int x1,int y1,int x2,int y2,int c=WHITE)
{
SetColor(c);
line(x1,y1,x2,y2,c);
} ;
void RectangleAbs(int x1,int y1,int x2,int y2,in
t c=WHITE)
{
SetColor(c);
Line(x1,y1,x1,y2,c);
Line(x1,y2,x2,y2,c);
Line(x2,y2,x2,y1,c);
Line(x2,y1,x1,y1,c);
};
// line according to coordinates
void Line(int x1,int y1,int x2,int y2,in
t c)
{
SetColor(c);
line(x1+CentreX,CentreY-y1,x2+Ce
ntreX,CentreY-y2,c);
} ;
void Circle(int xCenter, int yCenter, int radius,unsigned char color=WHITE)
{
float x=0;
float y=radius;
float p=1-radius;//p=(x+1)^2+(y-1/2)^2-r^2
while(x <= y)
{
PutPixel(xCenter+x, yCenter+y, color);
PutPixel(xCenter-x, yCenter+y, color);
PutPixel(xCenter+x, yCenter-y, color);
PutPixel(xCenter-x, yCenter-y, color);
PutPixel(xCenter+y, yCenter+x, color);
PutPixel(xCenter-y, yCenter+x, color);
PutPixel(xCenter+y, yCenter-x, color);
PutPixel(xCenter-y, yCenter-x, color);
x+=1;
if(p < 0)
p = p + 2 * (x + 1) - 1; //x=x+1,y=y
else
{
y--;
p = p + 2 * (x - y) + 1; //x=x+1,y=y-1
}
}
};
void Rectangle(int x1,int y1,int x2,int y2,int c )
{
SetColor(c);
RectangleAbs(x1+CentreX,CentreY-y1,x2+CentreX,CentreY-y2,c);
} ;
void SetColor(unsigned int c)
{
fc=c;
};
void SetBkColor(unsigned int c)
{
bc=c;
} ;
};
{
int i=0,j=0,k=0,c=0;
getch();
CGBase g;
for(i=0;i<=275;i++)
{
g.Circle(0,0,i,i);
}
getch();
}
}