我一直在修改这个 C# 代码大约一个星期(打算与 COSMOS 操作系统一起使用)。我正在尝试进入模式 X,并将屏幕清除为某种所需的颜色。实际发生的情况是我在屏幕上出现了彩色交错的垂直条。在这些条之间通常是黑色或其他一些随机颜色。这是代码。
using System;
using Cosmos.Core;
namespace HardwareCore
{
// This VGA driver is intended to be used with the COSMOS operating system.
public class DirectHI
{
public static void Test()
{
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
}
public static void VGAGraphicsTest()
{
IOPort MiscellaniousOutRegRead = new IOPort(0x3CC);
IOPort MiscellaniousOutRegWrite = new IOPort(0x3C2);
IOPort SequencerAddress = new IOPort(0x3C4);
IOPort SequencerData = new IOPort(0x3C5);
IOPort CRTCIndex = new IOPort(0x3D4);
IOPort CRTCData = new IOPort(0x3D5);
IOPort AttributesWrite = new IOPort(0x3C0);
IOPort AttributesDataRead = new IOPort(0x3C1);
IOPort ResetVCToIndex = new IOPort(0x3DA);
IOPort GraphicsRegsAddress = new IOPort(0x3CE);
IOPort GraphicsRegsData = new IOPort(0x3CF);
MemoryBlock VGA = new MemoryBlock(0xA0000, 128000);
//Hold sequencer in an async reset
SequencerAddress.Byte = 0x00;
SequencerData.Byte = 0x02;
//Set Miscelanious output register
MiscellaniousOutRegWrite.Byte = 0xE3;
//Hold sequencer in an async reset
SequencerAddress.Byte = 0x00;
SequencerData.Byte = 0x02;
//Set Clocking Mode Register
SequencerAddress.Byte = 0x01;
SequencerData.Byte = 0x01;
//Set Sequencer Memory Mode
SequencerAddress.Byte = 0x04;
SequencerData.Byte = 0x06;
//Unlock CRTC Registers
CRTCIndex.Byte = 0x11;
CRTCData.Byte = 0x00;
//Enable the 4 Color Planes
byte temp = ResetVCToIndex.Byte;
AttributesWrite.Byte = 0x12;
AttributesWrite.Byte = 0x0F;
//setup graphics mode
temp = ResetVCToIndex.Byte;
AttributesWrite.Byte = 0x10;
AttributesWrite.Byte = 0x41;
GraphicsRegsAddress.Byte = 0x05;
GraphicsRegsData.Byte = 0x40;
//Set Miscelanious Graphics Register
GraphicsRegsAddress.Byte = 0x06;
GraphicsRegsData.Byte = 0x05;
//Setup CRTC
CRTCIndex.Byte = 0x17;
CRTCData.Byte = 0xE3;
//Set the overeflow register
CRTCIndex.Byte = 0x08;
CRTCData.Byte = 0x3E;
//Unlock Sequencer
SequencerAddress.Byte = 0x00;
SequencerData.Byte = 0x03;
//clear screen!
for (uint i = 0; i < 128000; i++)
{
VGA[i] = (byte)(6 & 0xFF);
}
}
}
有没有人有什么建议??我完全被难住了。我使用 IBM 手册作为参考以及 osdev.org 页面。