我写的东西,Dos的,实现800 * 600 的文字和绘图
#include "dos.h"
#include "mem.h"
#include "fcntl.h"
#include "io.h"
void put_256pixel(int x,int y,unsigned char color);
void set_mode ( int m );
void set_page ( int bank_number );
void init256();
void close256();
void bar(int x1,int y1,int x2,int y2,unsigned char color);
void puts256(unsigned char *s,int x,int y,int color)
{
char th,tw,i,j,mat[32]={0},canput;
unsigned char *p,*ROM;
struct REGPACK reg;
reg.r_ax=0x1130;
reg.r_bx=0x0600;
intr(0x10,&reg);
ROM=(unsigned char*)MK_FP(reg.r_es,reg.r_bp); /*获得ROM字符集首址*/
while(*s!=0)
{
tw=8;
th=16;
p=ROM+(*s)*16;
memcpy(mat,p,16); /* 16 bytes every character */
s=s+1;
for(j=0;j<th;j++)
for(i=0;i<tw;i++)
{
canput=((mat[j]>>(7-i))&1);
if(canput)
put_256pixel(i+x+2,y+j,color);
}
x=x+8;
} /*end while*/
}
void set_mode ( int m )
{ union REGS i, o ;
i.x.ax = 0x4f02 ;
i.x.bx = m ;
int86 ( 16, &i, &o ) ;
}
void set_page ( int bank_number ) /* change the current page to Blank_number */
{ union REGS i, o ;
i.x.ax = 0x4F05 ;
i.x.bx = 0 ;
i.x.dx = bank_number ;
int86 ( 16, &i, &o ) ;
}
void init256() /* set mode to 800x600 256*/
{
set_mode(0x103);
}
void close256()
{
set_mode(0x03);
}
void bar(int x1,int y1,int x2,int y2,unsigned char color)
{
register int j,i,n[8]={736,672,608,544,480,416,352,288};
register char page_new,page_old;
register char page_end,lastpage,*p=MK_FP(0xa000,0000);
register char buffer[800];
long position;
page_old=8;
memset(buffer,color,800);
for(j=y1;j<=y2;j++) /* j is line number */
{ position=800L*j+x1;
page_new=position/65536;
page_end=(800L*j+x2)/65536;
if(page_new!=page_old)
{ set_page(page_new);
page_old=page_new;
}
if(page_new!=page_end) /*处理显示行跨页*/
{ memcpy(p+position%65536,buffer,n[page_new]-x1);
set_page(page_new+1);
memcpy(p,buffer,x2-n[page_new]+1);
}
else memcpy(p+position%65536,buffer,x2-x1+1);
}
}
void put_256pixel( int x, int y, unsigned char color )
{
static 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 long ) 800 + ( unsigned long ) x ) ;
vesa_seg = offset / seg_size ;
vesa_offset = offset % seg_size ;
if ( vesa_seg != curr_vesa_seg )
{ set_page ( vesa_seg ) ;
curr_vesa_seg = vesa_seg ;
}
pokeb ( 0xa000, ( unsigned ) vesa_offset, color ) ;
}
void rectangle256(int x1,int y1,int x2,int y2,unsigned color)
{ bar(x1,y1,x2,y1,color);
bar(x1,y1,x1,y2,color);
bar(x2,y1,x2,y2,color);
bar(x1,y2,x2,y2,color);
}
int main()
{ int i,j;
unsigned char color=10;
char num[4];
init256();
rectangle256(80,80,500,500,10);
puts256("When I was yong I'd listen to the radio!",100,100,10);
bar(100,118,450,118,10);
puts256("**** haha ha ha waint ,alkdslLASDFS!",100,200,13);
bar(100,218,450,218,13);
puts256("司马",100,300,4);
bar(100,318,450,318,4);
puts256("To Be Continued!",100,400,12);
bar(100,418,450,418,12);
getch();
close256();
return 0;
}