2

I've been tinkering with this C# code for about a week now (intended to be used with the COSMOS operating system). I'm attempting to enter into Mode X, and clear the screen to a certain desired color. What actually happens is I wind up with colored staggered vertical bars across the screen. In-between these bars is usually black or some other random color. Here is the code.

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);

        }

    }

}

Does anyone have any suggestions?? I'm stumped completely. I'm using the IBM manual as a reference as well as the osdev.org page.

Dave B.
  • 47
  • 6

0 Answers0