256色漢字顯示程序

字號:

/*
    CC256.C -- 256色漢字顯示程序
    */
    #include "dos.h"
    #include "stdio.h"
    #include "conio.h"
    FILE *fp;
    void OpenLIB(void);
    void CC256(int, int, int, char *Str);
    void ErrMsg();
    void InitScr();
    void RstScr();
    void PutPoint(int x, int y, int Color);
    void Quit();
    int main(void)
    {
    char *Str = "謝謝您使用本書";
    OpenLIB();
    InitScr();
    CC256(70, 80, 2, Str);
    getch();
    Quit();
    return 0;
    }
    void InitScr()
    {
    union REGS In;
    In.x.ax = 0x13; /*進入13H模式 */
    int86(0x10, &In, &In);
    }
    void RstScr()
    {
    union REGS In;
    In.x.ax = 0x03; /* 退出13H模式 */
    int86(0x10, &In, &In);
    }
    void OpenLIB(void) /* 打開24點陣微軟雅黑字庫 */
    {
    if ((fp = fopen("c:\\ucdos\\clib24s", "rb")) == NULL) ErrMsg();
    }
    void CC256(int x, int y, int Wid, char *Str)
    {
    unsigned Zcode, Bcode; /* 區(qū)碼, 位碼 */
    int i, j, k, Rec, Color;
    long Len;
    char Buf[72];
    while (*Str) /* 直到字串顯示完 */
    {
    if ((*Str & 0x80) && (*(Str+1) &0x80)) /* 是漢字 */
    {
    Zcode = (*Str-0xa1) & 0x07f; /* 區(qū)碼 */
    Bcode = (*(Str+1)-0xa1) & 0x07f; /* 位碼 */
    Rec = Zcode*94+Bcode; /* 記錄號 */
    Len = Rec*72L; /* 在字庫中位置 */
    fseek(fp, Len, SEEK_SET);
    fread (Buf, 1, 72, fp); /* 72字節(jié) */
    for (i = 0; i < 24; i++)
    for (j = 0; j < 3; j++)
    for (k = 0; k < 8; k++)
    if (Buf[i*3+j] >> (7-k) & 1)
    {
    Color = y+j*8+k-46;
    PutPoint(x+i, y+j*8+k, Color);
    }
    x = x+24+Wid;
    Str += 2;
    }
    }
    return;
    }
    /* 直接寫視頻緩沖區(qū) */
    void PutPoint(int x, int y, int Color) /* 畫點函數(shù) */
    {
    char far *p;
    p = (char far *) (0x0a0000000L);
    * (x+y*320+p) = Color;
    }
    void Quit()
    {
    RstScr();
    fcloseall();
    }
    void ErrMsg()
    {
    printf("Open LIB File Error!"); 
    getch();
    Quit();
    }