private byte ReadHardware(ushort addr) { addr &= 0xFF; switch (addr) { case 0: // PORT_LINK LinkPort.Update(); return((byte)((_romPageHighBit << 4) | (LinkState << 2) | LinkOutput)); case 1: // PORT_KEYBOARD: ////Console.WriteLine("read PORT_KEYBOARD"); return(ReadKeyboard()); case 2: // PORT_ROMPAGE return((byte)_romPageLow3Bits); case 3: // PORT_STATUS { // Console.WriteLine("read PORT_STATUS"); // Bits: // 0 - Set if ON key Interrupt generated // 1 - Update things (keyboard etc) // 2 - Unknown, but used // 3 - Set if ON key is up // 4-7 - Unknown return((byte)((_controller.IsPressed("ON") ? 0 : 8) | (TIM_1_int ? 2 : 0) | (ON_key_int ? 1 : 0))); } case 4: // PORT_INTCTRL // returns mirror of link port return((byte)((_romPageHighBit << 4) | (LinkState << 2) | LinkOutput)); case 16: // PORT_DISPCTRL // Console.WriteLine("read DISPCTRL"); break; case 17: // PORT_DISPDATA return(ReadDispData()); } return(0xFF); }
private void WriteHardware(ushort addr, byte value) { switch (addr) { case 0: // PORT_LINK _romPageHighBit = (value >> 4) & 1; _linkOutput = value & 3; if (LinkActive) { // Prevent rom calls from disturbing link port activity if (LinkActive && _cpu.RegisterPC < 0x4000) { return; } LinkPort.Update(); } break; case 1: // PORT_KEYBOARD: _lagged = false; _keyboardMask = value; ////Console.WriteLine("write PORT_KEYBOARD {0:X2}",value); break; case 2: // PORT_ROMPAGE _romPageLow3Bits = value & 0x7; break; case 3: // PORT_STATUS _maskOn = (byte)(value & 1); break; case 16: // PORT_DISPCTRL ////Console.WriteLine("write PORT_DISPCTRL {0}",value); WriteDispCtrl(value); break; case 17: // PORT_DISPDATA ////Console.WriteLine("write PORT_DISPDATA {0}",value); WriteDispData(value); break; } }
private byte ReadHardware(ushort addr) { switch (addr) { case 0: // PORT_LINK LinkPort.Update(); return((byte)((_romPageHighBit << 4) | (LinkState << 2) | LinkOutput)); case 1: // PORT_KEYBOARD: ////Console.WriteLine("read PORT_KEYBOARD"); return(ReadKeyboard()); case 2: // PORT_ROMPAGE return((byte)_romPageLow3Bits); case 3: // PORT_STATUS { // Console.WriteLine("read PORT_STATUS"); // Bits: // 0 - Set if ON key is down and ON key is trapped // 1 - Update things (keyboard etc) // 2 - Unknown, but used // 3 - Set if ON key is up // 4-7 - Unknown ////if (onPressed && maskOn) ret |= 1; ////if (!onPressed) ret |= 0x8; return((byte)((_controller.IsPressed("ON") ? _maskOn : 8) | (LinkActive ? 0 : 2))); } case 4: // PORT_INTCTRL ////Console.WriteLine("read PORT_INTCTRL"); return(0xFF); case 16: // PORT_DISPCTRL ////Console.WriteLine("read DISPCTRL"); break; case 17: // PORT_DISPDATA return(ReadDispData()); } return(0xFF); }
private void WriteHardware(ushort addr, byte value) { addr &= 0xFF; switch (addr) { case 0: // PORT_LINK _romPageHighBit = (value >> 4) & 1; _linkOutput = value & 3; if (LinkActive) { // Prevent rom calls from disturbing link port activity if (LinkActive && _cpu.RegPC < 0x4000) { return; } LinkPort.Update(); } break; case 1: // PORT_KEYBOARD: _lagged = false; _keyboardMask = value; ////Console.WriteLine("write PORT_KEYBOARD {0:X2}",value); break; case 2: // PORT_ROMPAGE _romPageLow3Bits = value & 0x7; break; case 3: // PORT_STATUS // controls ON key interrupts if ((value & 0x1) == 0) { ON_key_int = false; ON_key_int_EN = false; } else { ON_key_int_EN = true; } // controls first timer interrupts if ((value & 0x2) == 0) { TIM_1_int = false; TIM_1_int_EN = false; } else { TIM_1_int_EN = true; } // controls second timer, not yet implemented and unclear how to differentiate if ((value & 0x4) == 0) { } else { } // controls low power mode, not yet implemeneted if ((value & 0x8) == 0) { } else { } break; case 4: // PORT_INTCTRL // controls ON key interrupts TIM_frq = value & 6; TIM_mult = ((value & 0x10) == 0x10) ? 1800 : 1620; TIM_hit = (int)Math.Floor(6000000.0 / Math.Floor((double)TIM_mult / (2 * TIM_frq + 3))); // Bit 0 is some form of memory mapping // Bit 5 controls reset // Bit 6-7 controls battery power compare (not implemented, will always return full power) break; case 16: // PORT_DISPCTRL ////Console.WriteLine("write PORT_DISPCTRL {0}",value); WriteDispCtrl(value); break; case 17: // PORT_DISPDATA ////Console.WriteLine("write PORT_DISPDATA {0}",value); WriteDispData(value); break; } }