There is another starfield program on this site, I know because I wrote it and posted it somewhere. It is true 3D using a vector3D struct.
Here is some help with your problem. Asm blocks can be placed within braces instead of placing _asm or asm in front of every line.
Here is a small mode 13h VGA unit to get you started
Code:
//16 bit typedefs
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;
#define FALSE 0
#define TRUE 1
#define XYTOMEM(x,y) ((y<<8)+(y<<6)+x)
struct tagVGA
{
BYTE far *Screen;
BYTE far *Buffer;
BYTE far *Surface;
int BufferMode;
}VGA;
void SetMode(WORD mode);
void Pset(WORD x,WORD y,BYTE color);
void SetBufferMode(WORD newmode=TRUE);
void Flip(void);
void CLS(BYTE color);
void Line(WORD x,WORD y,WORD x2,WORD y2,BYTE color);
void SetMode(WORD mode)
{
asm {
mov ax,[mode]
int 10h
}
VGA.BufferMode=FALSE;
VGA.Screen=(BYTE far*)MK_FP(0xa000,0);
VGA.Buffer=new BYTE[64000L];
VGA.Surface=VGA.Screen;
}
void Pset(WORD x,WORD y,BYTE color)
{
VGA.Surface[XYTOMEM(x,y)]=color;
}
void SetBufferMode(WORD newmode)
{
switch(newmode)
{
case TRUE: VGA.Surface=VGA.Buffer;break;
case FALSE: VGA.Surface=VGA.Screen;break;
default: VGA.Surface=VGA.Screen;break;
}
}
void Flip(void)
{
//Does not check for screen refresh
BYTE far *Screen=VGA.Surface;
BYTE far *Buffer=VGA.Buffer;
asm {
push si
push di
push ds
les di,[Screen]
lds si,[Buffer]
mov cx,07D00h
rep movsw
pop ds
pop di
pop si
}
}
void CLS(BYTE color)
{
BYTE far *Surface=VGA.Surface;
asm {
les di,[Surface]
mov al,[color]
mov ah,[color]
mov cx,07D00h
rep stosb
}
}
void Line(WORD x,WORD y,WORD x2,WORD y2,BYTE color)
{
int eterm=0;
int diffx=x2-x;
int diffy=y2-y;
int yunit=320;
int xunit=1;
WORD offset=XYTOMEM(x,y);
int length=0;
if (diffx<0)
{
xunit=-xunit;
diffx=-diffx;
}
if (diffy<0)
{
yunit=-yunit;
diffy=-diffy;
}
if (diffx>diffy)
{
length=diffx+1;
for (int i=0;i<length;i++)
{
VGA.Surface[offset]=color;
offset+=xunit;
eterm+=diffx;
if (eterm>diffy)
{
eterm-=diffy;
offset+=yunit;
}
}
}
else
{
length=diffy+1;
for (i=0;i<length;i++)
{
VGA.Surface[offset]=color;
offset+=yunit;
eterm+=diffy;
if (eterm>0)
{
eterm-=diffx;
offset+=xunit;
}
}
}
}
If the line drawing algo does not work right then PM me - I coded this from memory and I always mess the line algo up.
Test the lines like this:
//Blue line from top left to center
Line(0,0,160,100,1);
//Red line from top right to center
Line(319,0,160,100,4);
//Green line from bottom left to center
Line(0,199,160,100,2);
//Yellow line from bottom right to center
Line(319,199,160,100,14);
If these lines are not right then the algo is messed up either on the x axis or the y.
Again, PM me if you have any probs.