| |
#include <stream.hpp>
#include <dos.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
typedef unsigned char byte;
typedef unsigned short word;
void set256Mode();
void setTextMode();
void putPixel(int x, int y, byte color);
void putPixelSlow(int x, int y, byte color);
int sgn(int num);
void drawLine(int x1, int y1, int x2, int y2, byte color);
void drawCircle(int x,int y, int R, byte color);
byte far *VGA = (byte *)MK_FP(0xA000,0);
main() {
int x,y;
set256Mode();
cout << "Hello\n";
printf("VGA Pointer Address - 0x%X,\nVGA Point TO - 0x%X,\nwith the value - %d",&VGA,VGA,*VGA);
getch();
}
void drawCircle(int x,int y, int R, byte color) {
float n = 0, invr = 1 / (float)R;
int dx = 0, dy = R - 1;
word dxoffset, dyoffset, offset = (y << 8) + (y << 6) + x;
while (dx <= dy) {
dxoffset = (dx << 8) + (dx << 6);
dyoffset = (dy << 8) + (dy << 6);
VGA[offset + dy - dxoffset] = color;
VGA[offset + dx - dyoffset] = color;
VGA[offset - dy - dxoffset] = color;
VGA[offset - dx - dyoffset] = color;
VGA[offset - dy + dxoffset] = color;
VGA[offset - dx + dyoffset] = color;
VGA[offset + dy + dxoffset] = color;
VGA[offset + dx + dyoffset] = color;
dx++;
n += invr;
dy = R * sin (acos(n));
}
}
void drawLine(int x1, int y1, int x2, int y2, byte color) {
int i,dx,dy,sdx,sdy,x,y,px,py;
dx = x2 - x1;
dy = y2 - y1;
sdx = sgn(dx);
sdy = sgn(dy);
dx = abs(dx);
dy = abs(dy);
x = dy << 1;
y = dx << 1;
px = x1;
py = y1;
putPixelSlow(px,py,color);
if (dx >= dy) {
for (i = 0; i < dx; i++) {
y += dy;
if (y >= dx) {
y -= dx;
py += sdy;
}
px += sdx;
putPixel(px,py,color);
}
} else {
for (i = 0; i < dy; i++) {
x += dx;
if (x >= dy) {
x -= dy;
px += sdx;
}
py += sdy;
putPixel(px,py,color);
}
}
}
int sgn(int num) {
if (num > 0) return(1);
else if (num < 0) return(-1);
else return(0);
}
void set256Mode() {
REGS ireg;
ireg.x.ax = 0x13;
int86(0x10,&ireg,&ireg);
}
void setTextMode() {
REGS ireg;
ireg.x.ax = 0x03;
int86(0x10,&ireg,&ireg);
}
void putPixel(int x, int y, byte color) {
VGA[(y<<8) + (y<<6) + x] = color;
}
void putPixelSlow(int x, int y, byte color) {
REGS ireg;
ireg.h.ah = 0x0c;
ireg.h.al = color;
ireg.x.cx = x;
ireg.x.dx = y;
int86(0x10,&ireg,&ireg);
} |