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

📄 mode15k.c

📁 用来将电脑连接到电视荧幕, 并以15Khz输出的源码, 请只用在支援15Khz的荧幕上, 以免伤害荧幕
💻 C
📖 第 1 页 / 共 2 页
字号:
            cp->HSStart = cp->HDisp + 8;
            cp->HSEnd  -= (d0 - cp->HSStart);
        }else{
            cp->HSStart = cp->HSStart + center_x;
            cp->HSEnd   = cp->HSEnd   + center_x;
        }
    }else{
        if((cp->HSEnd + center_x) > (cp->HTotal - 16)){
            d0 = cp->HSEnd;
            cp->HSEnd    = cp->HTotal - 16;
            cp->HSStart += (cp->HSEnd - d0);
        }else{
            cp->HSEnd   = cp->HSEnd   + center_x;
            cp->HSStart = cp->HSStart + center_x;
        }
    }

    if(center_y < 0){
        if((cp->VSStart + center_y) < (cp->VDisp + 1)){
            d0 = cp->VSStart;
            cp->VSStart = cp->VDisp + 1;
            cp->VSEnd  -= (d0 - cp->VSStart);
        }else{
            cp->VSStart = cp->VSStart + center_y;
            cp->VSEnd   = cp->VSEnd   + center_y;
        }
    }else{
        if((cp->VSEnd + center_y) > (cp->VTotal - 2)){
            d0 = cp->VSEnd;
            cp->VSEnd    = cp->VTotal - 2;
            cp->VSStart += (cp->VSEnd - d0);
        }else{
            cp->VSEnd   = cp->VSEnd   + center_y;
            cp->VSStart = cp->VSStart + center_y;
        }
    }
}




long CalcDotclock(long Vert001Hz, int HTotal, int VTotal, int interlace)
{
        double f0;

        f0 = (double)VTotal;
        if(interlace != 0){
                f0 += 0.5;
        }
        f0 = f0 * (double)HTotal;
        f0 = f0 * (double)Vert001Hz;
        f0 = f0 / 100.0;

        return (long)f0;
}

long CalcHorizontalHz(long dotclockHz, int HTotal)
{
        return dotclockHz / HTotal;
}

long CalcVert001Hz(long dotclockHz, int HTotal, int VTotal, int interlace)
{
        double f0;

        f0 = (double)VTotal;
        if(interlace != 0){
                f0 += 0.5;
        }
        f0 = f0 * (double)HTotal;
        f0 = (double)dotclockHz / f0;
        f0 = f0 * 100.0;

        return (long)f0;
}

void SetHVPolarity(int HPolar, int VPolar)
{
        BYTE d0;

        if(HPolar != 0) HPolar = 1;
        if(VPolar != 0) VPolar = 1;

        d0 = _inb(0x3CC);
        d0 = d0 & 0x3F;
        d0 = d0 | (VPolar << 7) | (HPolar << 6);
        _outb(0x3C2, d0);
}

DWORD BitMov(DWORD dstdata, int dstbitpos, DWORD srcdata, int srcbitpos)
{
        DWORD d0;
        DWORD d1;

        d1 = srcdata >> srcbitpos;
        d1 = d1 & 1;
        d0 = dstdata & (~(1 << dstbitpos));
        d1 = d1 << dstbitpos;
        d0 = d0 | d1;

        return d0;
}

void SetSeqReg(BYTE __idx, BYTE data)
{
        _outb(0x3c4, __idx);
        _outb(0x3c5, data);
}

BYTE GetSeqReg(BYTE __idx)
{
        BYTE d0;

        _outb(0x3c4, __idx);
        d0 = _inb(0x3c5);
        return d0;
}

BYTE GetAtrbData(BYTE __idx)
{
        _inb(0x3da);
        _outb(0x3c0, __idx | (1 << 5));
        return _inb(0x3c1);
}

void SetAtrbData(BYTE __idx, BYTE data)
{
        _inb(0x3da);
        _outb(0x3c0, __idx | 0x20);
        _outb(0x3c0, data);
}

int GetCrtcAddress(void)
{
    if((_inb(0x3CC) & 0x01) == 0)
        return 0x3B4;
    else
        return 0x3D4;
}

void SetCrtcReg(BYTE __idx, BYTE data)
{
    _outb(GetCrtcAddress(),    __idx);
    _outb(GetCrtcAddress() + 1, data);
}

BYTE GetCrtcReg(BYTE __idx)
{
    BYTE d0;

    _outb(GetCrtcAddress(), __idx);
    d0 = _inb(GetCrtcAddress() + 1);
    return d0;
}


int GetSeqDivider(void)
{
        int d0;

        d0      = (GetSeqReg(0x01) & 0x08) >>3;
        d0      = d0 + 1;
        return d0;
}

void _outb(unsigned int edx, BYTE al)
{
        outportb(edx, al);
}

BYTE _inb(unsigned int edx)
{
        return inportb(edx);
}

void _outw(unsigned int edx, WORD ax)
{
        outport(edx, ax);
}
WORD _inw(unsigned int edx)
{
        return inport(edx);
}

void _outl(unsigned int edx, DWORD eax)
{
        outportl(edx, eax);
}

DWORD _inl(unsigned int edx)
{
        return inportl(edx);
}

void DisableGenerateSignal(void)
{
        int d0;

        d0 = GetCrtcReg(0x17);
        d0 = d0 & 0x7F;
        SetCrtcReg(0x17, d0);

}

void EnableGenerateSignal(void)
{
        BYTE d0;

        d0 = GetCrtcReg(0x17);
        d0 = d0 | 0x80;
        SetCrtcReg(0x17, d0);
}

void SetSeqDiv(int div)
{
    if(div == 2)
        div = 1;
    else
        div = 0;
    SetSeqReg(0x01, BitMov(GetSeqReg(0x01), 3, div, 0));
}

void Set25MHz(void)
{
    BYTE d0;

    d0 = _inb(0x3CC);
    d0 = BitMov(d0, 2, 0, 0);
    d0 = BitMov(d0, 3, 0, 0);
    _outb(0x3C2, d0);               /*  25MHz (640 mode) */
    SetSeqDiv(1);
}

void Set28MHz(void)
{
    BYTE d0;

    d0 = _inb(0x3CC);
    d0 = BitMov(d0, 2, 1, 0);
    d0 = BitMov(d0, 3, 0, 0);
    _outb(0x3C2, d0);               /* 28MHz (720 mode) */
    SetSeqDiv(1);
}

void Set12MHz(void)
{
    BYTE d0;

    d0 = _inb(0x3CC);
    d0 = BitMov(d0, 2, 0, 0);
    d0 = BitMov(d0, 3, 0, 0);
    _outb(0x3C2, d0);                                   /* 25MHz (640 mode) */
    SetSeqDiv(2);
}

void Set14MHz(void)
{
    BYTE d0;

    d0 = _inb(0x3CC);
    d0 = BitMov(d0, 2, 1, 0);
    d0 = BitMov(d0, 3, 0, 0);
    _outb(0x3C2, d0);                                   /* 28MHz (720 mode) */
    SetSeqDiv(2);
}


void SetTextHeight(int height)
{
    BYTE d0;

    height = (height - 1) & 0x1F;
    d0  = GetCrtcReg(0x09) & ~0x1F;
    d0 |= height;
    SetCrtcReg(0x09, d0);
}

int GetTextHeight(void)
{
    return (int)((GetCrtcReg(0x09) & 0x1F) + 1);
}

void SetTextWidth(int width)
{
    int flag;

    if(width == 8)
        flag = 1;
    else
        flag = 0;
    SetSeqReg(0x01, (GetSeqReg(0x01) & 0xFE) | flag);
}

int GetTextWidth(void)
{
    int d0;

    d0 = 8;
    if( (GetSeqReg(0x01) & 0x01) == 0 )
        d0 = 9;
    return d0;
}

BYTE GetVGABytesPerLine(void)
{
    return GetCrtcReg(0x13);
}

void SetVGABytesPerLine(BYTE d0)
{
    SetCrtcReg(0x13, d0);
}


static void SetDoubleScan(int flag)
{
    if(flag == 0){
        SetCrtcReg(0x09, BitMov(GetCrtcReg(0x09), 7, 0, 0));
    }else{
        SetCrtcReg(0x09, BitMov(GetCrtcReg(0x09), 7, 1, 0));
    }
}

⌨️ 快捷键说明

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