PDA

View Full Version : یه مشکل در گرافیک



mascom
دوشنبه 07 شهریور 1384, 01:12 صبح
چرا مود گرافیکی IBM8514HI در تابع initgraph (سی تحت داس)کار نمیکنه؟اگه کسی علت رو می دونه لطفا یه مددی برسونه ما رو.

آرش_‍C++
پنج شنبه 10 شهریور 1384, 07:51 صبح
// ARGraph.h
#ifndef __ARGRAPH

#define __ARGRAPH


#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

void setsvga(int);
void setpixel( int, int, unsigned char ) ;
void initgraph();
void closegraph();
void line(int,int,int,int,int);


void initgraph()
{
setsvga ( 0x101 ) ;
}

void closegraph()
{
setsvga ( 0x003 ) ;
}

void setsvga ( int m )
{
asm{
mov ax,0x4f02
mov bx,m
int 16
}
}

void set_vesa_seg ( int bank_number )
{
asm{
mov ax,0x4F05
mov bx,0
mov dx,bank_number
int 16;
}
}

unsigned short sp_curr_vesa_seg = 0xffff ;
const unsigned long sp_seg_size = 0xffff + 1L ;
unsigned short sp_vesa_seg,sp_vesa_offset ;
unsigned long sp_offset ;

void inline setpixel(int x, int y, unsigned char color )
{
if(color!=255&&!(x<0||y<0||x>=640||y>=480))
{
sp_offset = ( ( unsigned long ) y * ( unsigned long ) 640 + ( unsigned long ) x ) ;
sp_vesa_seg = (unsigned short) (sp_offset / sp_seg_size) ;
sp_vesa_offset = (unsigned short) (sp_offset % sp_seg_size) ;
if ( sp_vesa_seg != sp_curr_vesa_seg )
{
set_vesa_seg ( sp_vesa_seg ) ;
sp_curr_vesa_seg = sp_vesa_seg ;
}
pokeb ( 0xA000, ( unsigned ) sp_vesa_offset, color ) ;
}
}

int getpixel( int x, int y)
{
if(x<0||y<0||x>=640||y>=480)
return 0;
sp_offset = ( ( unsigned long ) y * ( unsigned long ) 640 + ( unsigned long ) x ) ;
sp_vesa_seg = (unsigned short) (sp_offset / sp_seg_size) ;
sp_vesa_offset = (unsigned short) (sp_offset % sp_seg_size) ;
if ( sp_vesa_seg != sp_curr_vesa_seg )
{
set_vesa_seg ( sp_vesa_seg ) ;
sp_curr_vesa_seg = sp_vesa_seg ;
}
return peekb ( 0xA000, ( unsigned ) sp_vesa_offset) ;
}
void line(int x1,int y1,int x2,int y2,int color)
{
register int t,dis;
int xe=0,ye=0,dx,dy;
int ix,iy;
dx=x2-x1;
dy=y2-y1;
if(dx>0)
ix=1;
else if(!dx)
ix=0;
else
ix=-1;
if(dy>0)
iy=1;
else if(!dy)
iy=0;
else
iy=-1;
dx=abs(dx);
dy=abs(dy);
if(dx>dy)
dis=dx;
else
dis=dy;
for(t=0;t<dis+1;t++)
{
setpixel(x1,y1,color);
xe+=dx;
ye+=dy;
if(xe>dis)
{
xe-=dis;
x1+=ix;
}
if(ye>dis)
{
ye-=dis;
y1+=iy;
}
}// end for
setpixel(x2,y2,color);
}
void box(int x1,int y1,int x2,int y2,int color)
{
line(x1,y1,x1,y2,color);
line(x1,y2,x2,y2,color);
line(x2,y2,x2,y1,color);
line(x2,y1,x1,y1,color);
}
#endif