⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 go.c

📁 dos下pos机程序 连接sybase数据库 使用Microsoft c7 编译
💻 C
📖 第 1 页 / 共 3 页
字号:
int CurX, CurY; //当前点的位置
void Line(int sx, int sy, int ex, int ey, unsigned char LC, int LW, int WMODE, unsigned char LS)
{
    long kx, ky, r;
    int TLW, Con = 0;
    int x = 0, y = 0, k = 1, m = 1, j;
    CurX = ex,CurY = ey;
    if (sy == ey)
    {
        if (sx > ex)
        {
            TLW = sx,sx = ex,ex = TLW;
        }
        Line0(sx, sy, ex, LC, LW, WMODE, LS);
    }
    else if (sx == ex)
    {
        if (sy > ey)
        {
            TLW = sy,sy = ey,ey = TLW;
        }
        TLW = LW;
        LW = ey - sy + 1;
        Line0(sx, sy, ex, LC, LW, WMODE, LS);
        LW = TLW;
    }
    else
    {
        kx = ex - sx + 1,ky = ey - sy + 1;
        r = kx * kx + ky * ky;
        j = (labs(ky) > labs(kx)) ? 1 : 0;
        if (sx > ex)
        {
            k = -k;
        }
        if (sy > ey)
        {
            m = -m;
        }
        while (r >= x * (long) x + y * (long) y)
        {
            if (j)
            {
                x = (int) (y * kx / ky);
            }
            else
            {
                y = (int) (x * ky / kx);
            }
            if ((LS >> (7 - Con % 8)) & 1)
            {
                Line0(sx + x, sy + y, sx + x, LC, LW, WMODE, LS);
            }
            if (j)
            {
                y += m;
            }
            else
            {
                x += k;
            }
        }
    }
}

//画点
void Point(int sx, int sy, unsigned char Pco)
{
    Line0(sx, sy, sx, Pco, 1, COPY_PUT, 0xff);
}

//画矩形
//sx,sy,ex,sy-坐标
//Co-填冲颜色,Type-填冲类型
void DrawBar(int sx, int sy, int ex, int ey, unsigned char Co, unsigned char Type)
{
    int i;
    unsigned char CCo[2],LStyle;
    if (Type == 0xff)  // 实线填充
    {
        Line0(sx, sy, ex, Co, ey - sy + 1, COPY_PUT, 0xff);
    }  // ey-sy+1=线的宽度
    else            // 非实线填冲
    {
        CCo[0] = (unsigned char) (Co & 0xf);
        CCo[1] = (unsigned char) ((Co >> 4) & 0xf);
        LStyle = Type;
        for (i = 0; i <= ey - sy; i++)
        {
            Line0(sx, sy + i, ex, CCo[0], 1, COPY_PUT, LStyle);
            LStyle = (unsigned char) ~LStyle;
            Line0(sx, sy + i, ex, CCo[1], 1, COPY_PUT, LStyle);
        }
    }
}
//

void DrawBarEx(int sx, int sy, int ex, int ey, unsigned char Co, unsigned char Type, int WMODE)
{
    int i;
    for (i = 0; i <= ey - sy; i++)
    {
        Line0(sx, sy + i, ex, Co, 1, WMODE, Type);
        Type = (unsigned char) ~Type;
    }
}

//画矩形
//sx,sy,ex,ey-坐标
//FC-左上线颜色,BC-右下线颜色
void Rectangle(int sx, int sy, int ex, int ey, unsigned char FC, unsigned char BC)
{
    Line0(sx, sy, ex, FC, 1, COPY_PUT, 0xff);     //上线
    Line(sx, sy, sx, ey, FC, 1, COPY_PUT, 0xff);   //左线
    Line0(sx, ey, ex, BC, 1, COPY_PUT, 0xff);     //下线
    Line(ex, sy, ex, ey, BC, 1, COPY_PUT, 0xff);   //右线
}

void RRectangle(int sx, int sy, int ex, int ey, unsigned char FC, unsigned char BC)
{
    Line0(sx + 1, sy, ex - 1, FC, 1, COPY_PUT, 0xff);     //上线
    Line(sx, sy + 1, sx, ey - 1, FC, 1, COPY_PUT, 0xff);   //左线
    Line0(sx + 1, ey, ex - 1, BC, 1, COPY_PUT, 0xff);     //下线
    Line(ex, sy + 1, ex, ey - 1, BC, 1, COPY_PUT, 0xff);   //右线
}

//画填冲矩形
void RectangleFill(int sx, int sy, int ex, int ey, unsigned char FC, unsigned char BC, unsigned char FillColor, unsigned char FillStyle)
{
    DrawBar(sx, sy, ex, ey, FillColor, FillStyle);
    Rectangle(sx, sy, ex, ey, FC, BC);
}

//显示有3D效果的矩形
void DrawBar3d(int sx, int sy, int ex, int ey, unsigned char FC, unsigned char FS, unsigned char BC, unsigned char BS, int Size, unsigned char C1, unsigned char C2)
{
    if (Size)
    {
        DrawBar(ex, sy + Size, ex + Size, ey + Size, BC, BS);
        DrawBar(sx + Size, ey, ex + Size, ey + Size, BC, BS);
    }
    RectangleFill(sx, sy, ex, ey, C1, C2, FC, FS);
}

//显示园型
void Circel(int x, int y, int R, unsigned char Co, unsigned char Li, int Att)
{
    int Di, Xi, Yi;
    Di = 3 - 2 * R;
    Xi = 0,Yi = R;
    do
    {
        Di = (Di < 0) ? Di + (Xi << 2) + 6 : Di + ((Xi - Yi) << 2) + 10;
        Xi = Xi + 1;
        Yi = (Di < 0) ? Yi : Yi - 1;
        if (Att)
        {
            Line0(x - Xi, y - Yi, x + Xi, Co, 1, COPY_PUT, 0xff);
            Line0(x - Xi, y + Yi, x + Xi, Co, 1, COPY_PUT, 0xff);
        }
        else
        {
            Point(x + Xi, y - Yi, Co);
            Point(x - Xi, y - Yi, Co);
            Point(x + Xi, y + Yi, Co);
            Point(x - Xi, y + Yi, Co);
        }
    }
    while (Xi <= Yi);
    Xi = R,Yi = 0;
    Di = 3 - (R << 2);
    do
    {
        Di = (Di < 0) ? Di + (Yi << 2) + 6 : Di + ((Yi - Xi) << 2) + 10;
        Yi = Yi + 1;
        Xi = (Di < 0) ? Xi : Xi - 1;
        if (Att)
        {
            Line0(x - Xi, y - Yi, x + Xi, Co, 1, COPY_PUT, 0xff);
            Line0(x - Xi, y + Yi, x + Xi, Co, 1, COPY_PUT, 0xff);
        }
        else
        {
            Point(x + Xi, y - Yi, Co);
            Point(x - Xi, y - Yi, Co);
            Point(x + Xi, y + Yi, Co);
            Point(x - Xi, y + Yi, Co);
        }
    }
    while (Xi >= Yi);
    if (Att)
    {
        Line0(x - R, y, x + R, Co, 1, COPY_PUT, 0xff);
    }
    else
    {
        Point(x - R, y, Co);
        Point(x + R, y, Co);
    }
}

/*屏幕图形处理函数 保存,恢复*/
/*定义变量*/
_segment videoseg = 0xa000;  //可见段
_segment videosegex = 0xaa00;       //不可见段
int _nCount = 0;                  //计数
int WinWidth[5], WinHeight[5];     //保存的宽和高
unsigned _nOff[5] =
{
    0
};                     //偏移地址
unsigned char _based(videoseg) * seeseg = 0;
unsigned char _based(videoseg) * seesegt = 0;
unsigned char _based(videosegex) * seesegex = 0;
int SaveMark = 0;
//

void SetGraph(int Att)
{
    if (Att)
    {
        outp(0x3ce, 5);
        outp(0x3cf, 0x1);
        outp(0x3ce, 8);
        outp(0x3cf, 0);
        outp(0x3c4, 2);
        outp(0x3cf, 0xf);
    }
    else
    {
        _asm
        {
            mov dx,0x3ce    //  outportb(0x3ce,5);
            mov al,0x5
            out dx,al
            mov dx,0x3cf    //  outportb(0x3cf,0x1);
            mov al,0x1
            out dx,al
            mov dx,0x3ce    //  outportb(0x3ce,8);
            mov al,0x8
            out dx,al
            mov dx,0xcf     //  outportb(0x3cf,0);
            mov al,0x0
            out dx,al
            mov dx,0x3c4    //  outportb(0x3c4,2);
            mov al,0x2
            out dx,al
            mov dx,0x3cf    //  outportb(0x3cf,0xf);
            mov al,0xf
            out dx,al
        }
    }
}

void RestoreGraph(int Att)
{
    if (Att)
    {
        outp(0x3ce, 5);
        outp(0x3cf, 0);
    }
    else
    {
        outp(0x3ce, 5);
        outp(0x3cf, 0);
    }
}

void GetImage(int x1, int y, int hd1, int vd1)
{
    int i, j, x;
    unsigned yoff;
    x = x1 / 8;
    yoff = 0;
    yoff = _nOff[_nCount];

    //  printf("yoff1=%d,_nCount1=%d\n",yoff,_nCount);
    //  getchar();

    WinWidth[_nCount] = (hd1 - x1) / 8 + 1;
    WinHeight[_nCount] = vd1;
    SetGraph(1);
    for (j = y; j <= WinHeight[_nCount]; j++)
    {
        for (i = 0; i < WinWidth[_nCount]; i++)
        {
            seeseg = (unsigned char _based(videoseg) * )(j * 80 + x + i);            //计算地址
            seesegex = (unsigned char _based(videosegex) * )yoff;
            *seesegex = *seeseg;
            yoff++;
        }
    }
    _nCount++;
    _nOff[_nCount] = yoff;
    RestoreGraph(1);
}

void PutImage(int x1, int y)
{
    int j, i, x;
    unsigned yoff;
    x = x1 / 8;
    _nCount--;
    yoff = _nOff[_nCount];
    SetGraph(1);
    for (j = y; j <= WinHeight[_nCount]; j++)
    {
        for (i = 0; i < WinWidth[_nCount]; i++)
        {
            seeseg = (unsigned char _based(videoseg) * )(j * 80 + x + i);            //计算地址
            seesegex = (unsigned char _based(videosegex) * )yoff;              //
            *seeseg = *seesegex;
            yoff++;
        }
    }
    RestoreGraph(1);
}

//滚屏函数
void MoveScreen(unsigned sx1, unsigned sy1, unsigned sx2, unsigned sy2, unsigned tx, unsigned ty)
{
    unsigned SOff,TOff;
    unsigned Hd,Wd;
    short Mark;
    SOff = sy1 * 80 + sx1 / 8;
    TOff = ty * 80 + tx / 8;
    Hd = (sx2 - sx1) / 8 + 1;
    Wd = sy2 - sy1 + 1;
    if (tx == sx1 && ty == sy1)
    {
        return;
    }  //不用滚屏
    if (tx <= sx1)
    {
        if (ty <= sy1)
        {
            Mark = 1;
        }   /*左上*/
        else
        {
            Mark = 2;
        }   /*左下*/
    }
    else
    {
        if (ty <= sy1)
        {
            Mark = 3;
        }   /*右上*/
        else
        {
            Mark = 4;
        }   /*右下*/
    }
    SetGraph(0);
    switch (Mark)
    {
    case 1:
        _asm
        {
            push   ds
            push   es
            mov    ax,0xa000
            mov    ds,ax
            mov    es,ax
            mov    bx,0
        }
        Next1:
        _asm
        {
            mov    cx,Hd
            mov    si,SOff
            mov    di,TOff
            mov    al,80
            mul    bx
            add    si,ax
            add    di,ax
            cld
            rep    movsb
            mov    ax,Hd
            inc    bx
            cmp    bx,Wd
            jnz    Next1
            pop    es
            pop    ds
        }
        break;
    case 2:
        _asm
        {
            push   ds
            push   es
            mov    ax,0xa000
            mov    ds,ax
            mov    es,ax
            mov    bx,Wd
        }
        Next2:
        _asm
        {
            mov    cx,Hd
            mov    si,SOff
            mov    di,TOff
            mov    al,80
            mul    bx
            sub    ax,80
            add    si,ax
            add    di,ax
            cld
            rep    movsb
            mov    ax,Hd
            dec    bx
            cmp    bx,0
            jnz    Next2
            pop    es
            pop    ds
        }
        break;
    case 3:
        break;
    case 4:
        break;
    }
    RestoreGraph(0);
}

/*              第三部分:显示汉字函数                */
unsigned FontSeg, FontOff;                    //字模缓冲地址
unsigned char far FONT_BUF[32];                  //字模缓冲区
int Cowx, Liney;                              //列间距和行间距
unsigned char FontColor;                     //当前字符颜色
int FWriteMode;                              //当前显示方式
int FontCurX = 0, FontCurY = 0;                       //光标位置
unsigned char FontBuffer[2000];              //
unsigned char FontBufferCal[650];
unsigned char CancelBuffer[250];

//  初始化字符显示参数
unsigned StrToInt(char *str)
{
    unsigned Result = 0,k = 1,j;
    int i, l;
    l = (int) strlen(str);
    for (i = l - 1; i >= 0; i--)
    {
        switch (str[i])
        {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            j = str[i] - '0';
            break;
        case 'A':
        case 'B':
        case 'C':
        case 'D':
        case 'E':
        case 'F':
            j = (str[i] - 'A') + 10;
        }
        Result += j * k;
        k *= 16;
    }
    return Result;
}

void InitFont(void)
{
    char value[15], valueex[7];
    FILE *fhz16;

    fhz16 = fopen("digi.dat", "rb");
    fseek(fhz16, 0, SEEK_SET);
    fread(FontBuffer, 1, 1692, fhz16); //读取字库,lyy changed
    fclose(fhz16);

    fhz16 = fopen("cal.dat", "rb");
    fseek(fhz16, 0, SEEK_SET);
    fread(FontBufferCal, 1, 637, fhz16); //读取字库
    fclose(fhz16);

    fhz16 = fopen("Cancel.dat", "rb");
    fseek(fhz16, 0, SEEK_SET);
    fread(CancelBuffer, 1, 200, fhz16); //读取字库
    fclose(fhz16);

    //取地址,由于FP_SEG,FP_OFF在MC6.0失效,才出了下面叟主意
    sprintf(value, "%Fp", FONT_BUF);
    uf_strmid(valueex, value, 0, 4);
    FontSeg = StrToInt(valueex);
    uf_strmid(valueex, value, 5, 4);
    FontOff = StrToInt(valueex);

    FontColor = 0xff;
    FWriteMode = COPY_PUT;
    Cowx = 8,Liney = 18;
}

/* 读取汉字字模 TextFont-汉字或字符 */
int ReadFont(unsigned char *TextFont)
{
    /*  long addr;
      int k=1;
      if(!fhz16) return -1;
      if(!fasc16) return -2;
      if(TextFont[0]>=0xa0)                      //是汉字

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -