More OpCodes - working towards ZEXALL perfection
This commit is contained in:
@@ -5,37 +5,47 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
namespace Core.Io
|
||||
{
|
||||
public class IO_Bus
|
||||
{
|
||||
{
|
||||
public byte BorderColorIndex { get; private set; } = 7;
|
||||
public bool BeeperState { get; private set; } = false;
|
||||
public byte[] KeyboardRows = new byte[8] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
TapManager _tapManager = new TapManager();
|
||||
|
||||
public byte ReadPort(ushort portAddress)
|
||||
{
|
||||
// The Spectrum ULA responds to any even port address (where the lowest bit is 0)
|
||||
if ((portAddress & 0x01) == 0)
|
||||
public IO_Bus(TapManager tapManager)
|
||||
{
|
||||
byte highByte = (byte)(portAddress >> 8); // The B register!
|
||||
byte result = 0xFF; // Start assuming no keys are pressed
|
||||
|
||||
// The ROM pulls a specific bit low (0) in the high byte to request a row.
|
||||
// Sometimes it pulls multiple bits low to scan multiple rows at once, so we AND the results.
|
||||
if ((highByte & 0x01) == 0) result &= KeyboardRows[0]; // 0xFE: CAPS, Z, X, C, V
|
||||
if ((highByte & 0x02) == 0) result &= KeyboardRows[1]; // 0xFD: A, S, D, F, G
|
||||
if ((highByte & 0x04) == 0) result &= KeyboardRows[2]; // 0xFB: Q, W, E, R, T
|
||||
if ((highByte & 0x08) == 0) result &= KeyboardRows[3]; // 0xF7: 1, 2, 3, 4, 5
|
||||
if ((highByte & 0x10) == 0) result &= KeyboardRows[4]; // 0xEF: 0, 9, 8, 7, 6
|
||||
if ((highByte & 0x20) == 0) result &= KeyboardRows[5]; // 0xDF: P, O, I, U, Y
|
||||
if ((highByte & 0x40) == 0) result &= KeyboardRows[6]; // 0xBF: ENTER, L, K, J, H
|
||||
if ((highByte & 0x80) == 0) result &= KeyboardRows[7]; // 0x7F: SPACE, SYM, M, N, B
|
||||
|
||||
// The top 3 bits (5, 6, 7) are unused by the keyboard and usually return 1 on a real Spectrum
|
||||
return (byte)(result | 0xE0);
|
||||
_tapManager = tapManager;
|
||||
}
|
||||
|
||||
// Return 0xFF for unhandled ports
|
||||
return 0xFF;
|
||||
}
|
||||
public byte ReadPort(ushort portAddress)
|
||||
{
|
||||
// The Spectrum ULA responds to any even port address (where the lowest bit is 0)
|
||||
if ((portAddress & 0x01) == 0)
|
||||
{
|
||||
byte highByte = (byte)(portAddress >> 8); // The B register!
|
||||
byte result = 0xFF; // Start assuming no keys are pressed
|
||||
|
||||
// The ROM pulls a specific bit low (0) in the high byte to request a row.
|
||||
// Sometimes it pulls multiple bits low to scan multiple rows at once, so we AND the results.
|
||||
if ((highByte & 0x01) == 0) result &= KeyboardRows[0]; // 0xFE: CAPS, Z, X, C, V
|
||||
if ((highByte & 0x02) == 0) result &= KeyboardRows[1]; // 0xFD: A, S, D, F, G
|
||||
if ((highByte & 0x04) == 0) result &= KeyboardRows[2]; // 0xFB: Q, W, E, R, T
|
||||
if ((highByte & 0x08) == 0) result &= KeyboardRows[3]; // 0xF7: 1, 2, 3, 4, 5
|
||||
if ((highByte & 0x10) == 0) result &= KeyboardRows[4]; // 0xEF: 0, 9, 8, 7, 6
|
||||
if ((highByte & 0x20) == 0) result &= KeyboardRows[5]; // 0xDF: P, O, I, U, Y
|
||||
if ((highByte & 0x40) == 0) result &= KeyboardRows[6]; // 0xBF: ENTER, L, K, J, H
|
||||
if ((highByte & 0x80) == 0) result &= KeyboardRows[7]; // 0x7F: SPACE, SYM, M, N, B
|
||||
if (_tapManager.EarBit) result |= 0x40; // Set Bit 6 high
|
||||
else result &= 0xBF; // Set Bit 6 low
|
||||
|
||||
|
||||
//return result;
|
||||
// The top 3 bits (5, 6, 7) are unused by the keyboard and usually return 1 on a real Spectrum
|
||||
return (byte)(result | 0xE0);
|
||||
}
|
||||
|
||||
// Return 0xFF for unhandled ports
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
public void WritePort(ushort portAddress, byte portValue)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user