static void WaitUntilReady() { // implement timeout for situations like this... while ((IO.ReadByte(IO.Port.KB_controller_commands) & 0x02) != 0) { ; } }
public static byte Read(Address address) { Asm.CLI(); IO.WriteByte(IO.Port.RTC_CommandPort, (byte)(0x80 | (byte)address)); Asm.NOP(); Asm.NOP(); Asm.NOP(); byte result = IO.ReadByte(IO.Port.RTC_DataPort); Asm.STI(); return(result); }
public static void Setup() { byte mask1, mask2; // save masks mask1 = IO.ReadByte(IO.Port.Master_PIC_DataPort); mask2 = IO.ReadByte(IO.Port.Slave_PIC_DataPort); // Remap the IRQ IO.WriteByte(IO.Port.Master_PIC_CommandPort, MasterICW1); IO.Delay(); IO.WriteByte(IO.Port.Master_PIC_DataPort, MasterIRQBase); IO.Delay(); IO.WriteByte(IO.Port.Master_PIC_DataPort, MasterICW3); IO.Delay(); IO.WriteByte(IO.Port.Master_PIC_DataPort, MasterICW4); IO.Delay(); IO.WriteByte(IO.Port.Slave_PIC_CommandPort, SlaveICW1); IO.Delay(); IO.WriteByte(IO.Port.Slave_PIC_DataPort, SlaveIRQBase); IO.Delay(); IO.WriteByte(IO.Port.Slave_PIC_DataPort, SlaveICW3); IO.Delay(); IO.WriteByte(IO.Port.Slave_PIC_DataPort, SlaveICW4); IO.Delay(); // restore saved masks. IO.WriteByte(IO.Port.Master_PIC_DataPort, mask1); IO.WriteByte(IO.Port.Slave_PIC_DataPort, mask2); DisableAllIRQs(); }
static void SendCommand(KeyboardCommands command) { KeyboardMessages message = KeyboardMessages.Acknowledge; do { IO.WriteByte(IO.Port.KB_data_port, (byte)command); // Wait for acknowledge and receieve it WaitUntilReady(); message = (KeyboardMessages)IO.ReadByte(IO.Port.KB_data_port); if (message == KeyboardMessages.Request_Resend) { continue; } else if (message == KeyboardMessages.Acknowledge) { return; } else if (message == KeyboardMessages.Unknown1) // This was the cause of the caps issue. { return; } else if (message == KeyboardMessages.Unknown2) // This was the cause of the caps issue in qemu. { capsLock = capsLock ^ capsLockReleased; capsLockReleased = true; return; } else { TextMode.WriteByte((byte)message); //Diagnostics.Error ("ADC.X86.Keyboard.SendCommand(): unhandled message"); return; } } while (message != KeyboardMessages.Acknowledge); }
/// <summary> /// Reboot the system. /// We can reset the system, oddly enough, through the keyboard IO port /// </summary> public static void Reboot() { // Disable interrupts Asm.CLI(); // Clear all keyboard buffers (output and command buffers) byte temp; do { temp = IO.ReadByte(IO.Port.KB_controller_commands); if ((temp & 0x01) != 0) { IO.ReadByte(IO.Port.KB_data_port); // Empty keyboard buffer } } while ((temp & 0x02) != 0); // Reset the system IO.WriteByte(IO.Port.KB_controller_commands, 0xFE); // Halt the system (in case reset didn't work) Asm.HLT(); }
/// <summary> /// ADC portion of the TextMode class setup. For X86, this function /// first locates the addresses of CRT controllers using color (EGA/CGA) /// or alternatively monochrome (MDA) display standards. Finally it /// determines the width and height of the text buffer. /// </summary> /// <reference>http://www.cknow.com/refs/VideoDisplayStandards.html</reference> public static void Setup() { // Find CRT controller addresses if ((IO.ReadByte(IO.Port.EGA_graphics_1_position_register) & 1) == 1) { // CGA/EGA color text mode CRT_index_register = IO.Port.CGA_CRT_index_register; CRT_data_register = IO.Port.CGA_CRT_data_register; // HACK!! videoMemory.address = (byte *)0xB8000; videoMemory.length = 0x4000; // CGA has 16kb video memory //videoMemory = Architecture.ResourceManager.RequestMemoryMap(0xB8000, 0x4000); // ideally we'd poll how much video memory // we can use, but we can't so we're // being conservative and only use 16kb. bytePerChar = 2; colorMode = true; haveBuffer = true; } else { // MDA monochrome text mode CRT_index_register = IO.Port.MDA_CRT_index_register; CRT_data_register = IO.Port.MDA_CRT_data_register; // HACK!! videoMemory.address = (byte *)0xB0000; videoMemory.length = 0x1000; // MDA has 16kb video memory //videoMemory = Architecture.ResourceManager.RequestMemoryMap(0xB0000, 0x1000); bytePerChar = 1; colorMode = false; haveBuffer = false; } // read the width width = HardwareCommand(CRT_Indices.horizontal_displayed) + 1; // this returns a funny number... what am i doing wrong here? //height = HardwareCommand(CRT_Indices.vertical_displayed) + 1; height = 25; scanline = (uint)(width * bytePerChar); if (haveBuffer) { bufferHeight = (int)( videoMemory.Length / scanline) - 1; } else { bufferHeight = height; } bufferSize = (uint)bufferHeight * scanline; readY = 0; writeY = 0; for (int x = 0; x < EntryModule.MaxTextAttributeSlots; x++) { savedAttributes [x] = 0xFF; } }
private static int HardwareCommand(CRT_Indices index) { IO.WriteByte(CRT_index_register, (byte)index); return(IO.ReadByte(CRT_data_register)); }
static unsafe void KeyboardHandler(IDT.ISRData data) { // Read from the keyboard's data buffer byte input; uint scancode; bool pressed; input = IO.ReadByte(IO.Port.KB_data_port); /* XXX: why is this commented out? * * if (input == KeyboardMessages.Too_Many_Keys || * input == KeyboardMessages.Keyboard_Error) * { * // TODO: do something usefull here.. * return; * } * */ if (input == 0xe0) { input = IO.ReadByte(IO.Port.KB_data_port); scancode = (uint)((input & 0x7F) >> 8) | 0xe0; pressed = (input & 0x80) == 0; } else if (input == 0xe1) { input = IO.ReadByte(IO.Port.KB_data_port); scancode = (uint)(input & 0x7F); pressed = (input & 0x80) == 0; return; } else { scancode = (uint)(input & 0x7F); pressed = (input & 0x80) == 0; } if (scancode == (uint)Keys.CapsLock) // CapsLock { if (pressed) { if (capsLockReleased) { capsLock = !capsLock; } capsLockReleased = false; SetLEDs(); } else { capsLockReleased = true; } return; } else if (scancode == (uint)Keys.NumLock) // NumLock { if (pressed) { if (numLockReleased) { numLock = !numLock; } numLockReleased = false; SetLEDs(); } else { numLockReleased = true; } return; } else if (scancode == (uint)Keys.ScrollLock) // ScrollLock { if (pressed) { if (scrollLockReleased) { scrollLock = !scrollLock; } scrollLockReleased = false; SetLEDs(); } else { scrollLockReleased = true; } return; } else if (scancode == (uint)Keys.LeftControl) // left control { leftControl = pressed; return; } else if (scancode == (uint)Keys.LeftShift) // left shift { leftShift = pressed; return; } else if (scancode == (uint)Keys.LeftAlt) // left alt { leftAlt = pressed; return; } else if (scancode == (uint)Keys.RightAlt) // right alt { rightAlt = pressed; return; } else if (scancode == (uint)Keys.RightControl) // right control { rightControl = pressed; return; } else if (scancode == (uint)Keys.RightShift) // right shift { rightShift = pressed; return; } if (pressed) { for (int x = 0; x < EntryModule.MaxEventHandlers; ++x) { if (keyDownEvent [x] == 0) { continue; } MemoryUtil.Call(keyDownEvent [x], scancode); } } else { for (int x = 0; x < EntryModule.MaxEventHandlers; ++x) { if (keyUpEvent [x] == 0) { continue; } MemoryUtil.Call(keyUpEvent [x], scancode); } } }