open watcom学习记录之——图形模式上画点阵显示字符

open watcom学习记录之——图形模式下画点阵显示字符
C/C++ code
#define xy 640*480
#define color1 0xffff
#define color2 0xf800
#define pixel_size 2
#define lattice_x 8
#define lattice_y 8
#define word_x0 3
#define word_y0 3
#define row_word_count 640/lattice_x
#define sys_mem_pointer_base 0x200000
main()
{
char text_test[]={0,1,2,3,4,5,6,7,8,9,0xa,0xb,0xc,0xd,0xe,0xf,1,1,1};
char *file_point=0x400000;

unsigned short int word_sz_i=0;
int file_size,file_point_i=0,word_xy=0,word_x,word_y,*sys_mem_pointer=sys_mem_pointer_base,sys_mem_pointer_i=0;
int word_point_xy,word_sz_x_i,word_sz_y_i;
unsigned short int *p=(short *)0xc0000000,*pmhc=(short *)0x300000;

char word_bit_i=0x80,word_sz[]=
{
/*0*/
0x7e,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0x7e,
/*1*/
0x18,0x38,0x58,0x18,0x18,0x18,0x18,0xff,
/*2*/
0xfc,0x03,0x03,0x7e,0xc0,0xc0,0xc0,0xff,
/*3*/
0Xfe,0x03,0x03,0x7e,0x07,0x03,0x03,0xfe,
/*4*/
0x0c,0x1d,0x3c,0x6c,0x6c,0xff,0x0c,0x0c,
/*5*/
0xff,0xc0,0xc0,0xfe,0x03,0x03,0x03,0xfe,
/*6*/
0x3e,0xc0,0xc0,0xfe,0xc3,0xc3,0xc3,0x3c,
/*7*/
0x7f,0x03,0x06,0x06,0x0c,0x0c,0x18,0x18,
/*8*/
0x7e,0xc3,0xc3,0x7e,0xc3,0xc3,0xc3,0x7e,
/*9*/
0x3c,0xc3,0xc3,0xc3,0x7f,0x03,0x03,0x7e,
/*a*/
0x7e,0x03,0x03,0x7f,0xc3,0xc3,0xc3,0x7f,
/*b*/
0xc0,0xc0,0xfe,0xc3,0xc3,0xc3,0xc3,0xfe,
/*c*/
0x00,0x3e,0x60,0x60,0x60,0x60,0x60,0x3e,
/*d*/
0x03,0x03,0x7f,0xc3,0xc3,0xc3,0xc3,0x7f,
/*e*/
0x00,0x3e,0x63,0x63,0x7e,0x60,0x60,0x3e,
/*f*/
0x00,0x1e,0x30,0x30,0xfe,0x30,0x30,0x30
};

memcpy(file_point,text_test,sizeof(text_test));
sys_mem_pointer[sys_mem_pointer_i++]=(int)pmhc+xy*pixel_size;
sys_mem_pointer[sys_mem_pointer_i++]=(int)pmhc;
sys_mem_pointer[sys_mem_pointer_i++]=(int)pmhc+xy*pixel_size;

_asm{
        pushad
        mov ax,0x4f02;/*4F02H VESA*/
        mov bx,0x4111;/*111----640*480-64K(5:6:5),110------640*480-32K(1:5:5:5)*/
        int 0x10
        popad
        }
        
memset(pmhc,0xf,xy*pixel_size);
memcpy(p,pmhc,xy*pixel_size);

word_x=word_x0;
word_y=word_y0;
word_xy=word_y*row_word_count;
word_point_xy=word_xy*lattice_x*lattice_y+word_x*lattice_x;
file_size=sizeof(text_test);

while(file_point_i<file_size)
{
word_sz_i=file_point[file_point_i++]*8;
for (word_sz_y_i=0;word_sz_y_i<8;word_sz_y_i++)
{
 while(word_bit_i>=0x01)
 {
  if(word_bit_i&word_sz[word_sz_i])
  {p[word_point_xy]=color2;}
 word_point_xy++;
 word_bit_i=word_bit_i>>1;
 }
 word_bit_i=0x80;
 word_sz_i++;
 word_point_xy=word_point_xy+640-8;
}
word_point_xy=word_point_xy-640*8+8+2;
}
getch();
        _asm
        {
        mov ax,3
        int 0x10
        }
return 0;
}



------解决方案--------------------
看不明白,谁来帮帮忙吧!
------解决方案--------------------
仅供参考
C/C++ code
#include <mem.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
const unsigned char bit[8]={128,64,32,16,8,4,2,1};
//--------------------
void dis(xoff,code)
    unsigned int xoff,code;
{
    unsigned char *buffer;
    FILE *hzk;
    unsigned long offset;
    unsigned int q,w;
    int x,y,width;

    buffer=calloc(32,1);
    if ((code&0xFF00)!=0) {
        w=(code&0x00FF)-0xA1;
        q=((code>>8)&0x00FF)-0xA1;
        offset=q*0x5E+w;
        offset*=32;
        if ((hzk=fopen("HZK16","rb"))==NULL) {
            closegraph();
            printf("Can not open HZK16\r\n");
            exit(1);
        }
        fseek(hzk,offset,SEEK_SET);
        fread(buffer,1,32,hzk);
        fclose(hzk);
        width=2;
    }
    else {
        if ((hzk=fopen("ASC16","rb"))==NULL) {
            closegraph();
            printf("Can not open ASC16\r\n");
            exit(1);
        }
        offset=code*16;
        fseek(hzk,offset,SEEK_SET);
        fread(buffer,1,16,hzk);
        fclose(hzk);
        width=1;
    }
    for (y=0;y<16;y++) for (x=0;x<8*width;x++) {
        if (buffer[y*width+x/8]&bit[x%8]) putpixel(xoff+x,y,15);
    }
    free(buffer);
}
//--------------------
void display(p)
    unsigned char *p;
{

  int i;
  unsigned int qw;

  i=0;
  while (1) {
    if (p[i]==0x0D||p[i]==0x1A) break;
    if (p[i]>0xA0) {
        qw=((unsigned int)p[i]<<8)|((unsigned int)p[i+1]&0x00FF);
        dis(8*i,qw);
        i+=2;
    }
    else {
        qw=(unsigned int)p[i]&0x00FF;
        dis(8*i,qw);
        i++;
    }
  }

}
//--------------------
void main()
{
    int gdriver = DETECT, gmode, errorcode;
    long fl;
    FILE *hz;
    unsigned char *p;

    initgraph(&gdriver, &gmode, "c:\\borlandc\\bgi");
    errorcode = graphresult();
    if (errorcode != grOk) {
       printf("Graphics error: %s\n", grapherrormsg(errorcode));
       exit(1);
    }
    hz=fopen("hz","rb");
    fseek(hz,0,SEEK_END);
    fl=ftell(hz);
    p=calloc((int)fl,sizeof(unsigned char));
    rewind(hz);
    fread(p,1,(int)fl,hz);
    fclose(hz);
    display(p);
    free(p);
    getch();
    closegraph();
}