Skip to content

Commit

Permalink
16 bit IO (IN, OUT)
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed Feb 26, 2025
1 parent fa17270 commit d40603a
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 49 deletions.
18 changes: 9 additions & 9 deletions CGA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ public override bool HasAddress(uint addr)
return false;
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
Log.DoLog($"CGA::IO_Write {port:X4} {value:X2}", true);
Log.DoLog($"CGA::IO_Write {port:X4} {value:X4}", true);

if (port == 0x3d4 || port == 0x3d6 || port == 0x3d0 || port == 0x3d2)
_m6845_reg = value;
_m6845_reg = (byte)value;
else if (port == 0x3d5 || port == 0x3d7 || port == 0x3d1 || port == 0x3d3)
{
_m6845.Write(_m6845_reg, value);
_m6845.Write(_m6845_reg, (byte)value);
_display_address = (uint)(_m6845.Read(12) << 8) | _m6845.Read(13);
Log.DoLog($"Set base address to {_display_address:X04}", true);
Redraw();
}
else if (port == 0x3d8)
{
if (_graphics_mode != value)
if (_graphics_mode != (byte)value)
{
if ((value & 2) == 2) // graphics 320x200
{
Expand Down Expand Up @@ -146,14 +146,14 @@ public override bool IO_Write(ushort port, byte value)
_gf.height = font_descr.height * 25;
}
_gf.rgb_pixels = new byte[_gf.width * _gf.height * 3];
_graphics_mode = value;
Log.DoLog($"CGA mode is now {value:X02} ({_cga_mode}), {_gf.width}x{_gf.height}", true);
_graphics_mode = (byte)value;
Log.DoLog($"CGA mode is now {value:X04} ({_cga_mode}), {_gf.width}x{_gf.height}", true);
Redraw();
}
}
else if (port == 0x3d9)
{
_color_configuration = value;
_color_configuration = (byte)value;
Log.DoLog($"CGA color configuration: {_color_configuration:X02}", true);
}
else
Expand All @@ -164,7 +164,7 @@ public override bool IO_Write(ushort port, byte value)
return false;
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
Log.DoLog("CGA::IO_Read", true);

Expand Down
4 changes: 2 additions & 2 deletions Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ abstract class Device
public abstract String GetName();

public abstract void RegisterDevice(Dictionary <ushort, Device> mappings);
public abstract bool IO_Write(ushort port, byte value);
public abstract (byte, bool) IO_Read(ushort port);
public abstract bool IO_Write(ushort port, ushort value);
public abstract (ushort, bool) IO_Read(ushort port);

public int GetWaitStateCycles()
{
Expand Down
4 changes: 2 additions & 2 deletions Display.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void SyncClock(int clock)

public abstract override bool HasAddress(uint addr);

public abstract override bool IO_Write(ushort port, byte value);
public abstract override bool IO_Write(ushort port, ushort value);

protected bool IsHsync()
{
Expand All @@ -107,7 +107,7 @@ protected bool IsHsync()
return hsync;
}

public abstract override (byte, bool) IO_Read(ushort port);
public abstract override (ushort, bool) IO_Read(ushort port);

protected void EmulateTextDisplay(uint x, uint y, byte character, byte attributes)
{
Expand Down
2 changes: 1 addition & 1 deletion IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public bool Out(ushort addr, ushort value)
else
{
if (_io_map.ContainsKey(addr))
return _io_map[addr].IO_Write(addr, (byte)value);
return _io_map[addr].IO_Write(addr, value);
}

#if DEBUG
Expand Down
6 changes: 3 additions & 3 deletions MDA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public override bool HasAddress(uint addr)
return addr >= 0xb0000 && addr < 0xb8000;
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
Log.DoLog($"MDA::IO_Write {port:X4} {value:X2}", true);
Log.DoLog($"MDA::IO_Write {port:X4} {value:X4}", true);

return false;
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
byte rc = 0;

Expand Down
6 changes: 3 additions & 3 deletions MIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public override void RegisterDevice(Dictionary <ushort, Device> mappings)
mappings[0x0331] = this;
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
if (port == 0x331)
return (0, false);

return (0xaa, false);
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
// maybe buffer upto the expected byte-count first?
if (port == 0x330)
Expand All @@ -51,7 +51,7 @@ public override bool IO_Write(ushort port, byte value)

if (_buffer_offset < _buffer.Length)
{
_buffer[_buffer_offset++] = value;
_buffer[_buffer_offset++] = (byte)value;
}

if (_buffer_offset == _buffer.Length)
Expand Down
9 changes: 3 additions & 6 deletions PPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ internal class PPI : Device
{
private byte _control = 0;
private bool _dipswitches_high = false;
private byte [] _cache = new byte[4];
private Keyboard _kb = null;

public PPI(Keyboard kb)
Expand All @@ -28,7 +27,7 @@ public override void RegisterDevice(Dictionary <ushort, Device> mappings)
mappings[0x0063] = this;
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
Log.DoLog($"PPI::IO_Read: {port:X4}", true);

Expand All @@ -45,12 +44,10 @@ public override (byte, bool) IO_Read(ushort port)
return _kb.IO_Read(port);
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
Log.DoLog($"PPI::IO_Write: {port:X4} {value:X2}", true);

_cache[port - 0x0060] = value;

if (port == 0x0061)
{
if ((_control & 4) == 4) // dipswitches selection
Expand All @@ -62,7 +59,7 @@ public override bool IO_Write(ushort port, byte value)
}
else if (port == 0x0063)
{
_control = value;
_control = (byte)value;
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions RTC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private byte ToBCD(int v)
return (byte)((d1 << 4) | d2);
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
byte rc = 0xff;

Expand Down Expand Up @@ -85,15 +85,15 @@ public override (byte, bool) IO_Read(ushort port)
return (rc, false);
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
Log.DoLog($"RTC OUT {port:X04}, value {value:X02} (index: {_cmos_ram_index:X02})");

if (port == 0x070 || port == 0x240 || port == 0x2c0)
_cmos_ram_index = (byte)(value & 127);
else
{
_ram[_cmos_ram_index] = value;
_ram[_cmos_ram_index] = (byte)value;
}

return false;
Expand Down
14 changes: 9 additions & 5 deletions XTIDE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class XTIDE : Device
private ushort _cylinder_count = 614;
private ushort _head_count = 4;
private ushort _sectors_per_track = 17;
private byte[] _registers = new byte[8];
private ushort[] _registers = new ushort[8];

public XTIDE(List<string> disk_filenames)
{
Expand Down Expand Up @@ -272,12 +272,12 @@ private void ResetStatusRegister()
SetDRDY();
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
int register = (port - 0x300) / 2;
string name = _io_names[register];

byte rc = 0xee;
ushort rc = 0xee;

if (port == 0x300) // Data register
{
Expand Down Expand Up @@ -318,7 +318,7 @@ private void StoreSectorBuffer()
}
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
int register = (port - 0x300) / 2;
string name = _io_names[register];
Expand All @@ -330,7 +330,11 @@ public override bool IO_Write(ushort port, byte value)
{
if (_sector_buffer_offset < _sector_buffer.Length)
{
_sector_buffer[_sector_buffer_offset++] = value;
_sector_buffer[_sector_buffer_offset++] = (byte)value; // FIXME
if (value > 255)
Log.DoLog($"XT-IDE DATAREGISTER GREP {_sector_buffer_offset-1}: {value:X04}");
else
Log.DoLog($"XT-IDE DATAREGISTER {_sector_buffer_offset-1}: {value:X04}");
}
else if (_target_drive != 255)
{
Expand Down
8 changes: 4 additions & 4 deletions floppy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ internal enum DataState { NotSet, WaitCmd, HaveData, WantData }

class FloppyDisk : Device
{
private byte [] _registers = new byte[8];
private ushort [] _registers = new ushort[8];
private i8237 _dma_controller = null;
protected int _irq_nr = 6;
private bool _dma = false;
Expand Down Expand Up @@ -110,7 +110,7 @@ public bool FifoExpectsData()
return _data_state == DataState.WantData;
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
int bytes_left = _data == null ? 0 : (_data.Length - _data_offset);
Log.DoLog($"Floppy-IN {_io_names[port - 0x3f0]}: {port:X4} {_data_state}, bytes left: {bytes_left}", true);
Expand Down Expand Up @@ -280,7 +280,7 @@ public void DumpReply()
#endif
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
if (_data_state == DataState.WantData || _data_state == DataState.HaveData)
Log.DoLog($"Floppy-OUT {_io_names[port - 0x3f0]}: {port:X4} {value:X2} {_data_state} cmd:{_data[0]:X} data left:{_data.Length - _data_offset}", true);
Expand Down Expand Up @@ -382,7 +382,7 @@ public override bool IO_Write(ushort port, byte value)
return false;
}

_data[_data_offset++] = value;
_data[_data_offset++] = (byte)value; // FIXME
if (_data_offset == _data.Length)
{
if (_data[0] == 0x06) // READ DATA
Expand Down
12 changes: 6 additions & 6 deletions i8253.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void RegisterDevice(Dictionary <ushort, Device> mappings)
mappings[0x0043] = this;
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
if (port == 0x0040)
return (GetCounter(0), _timers[0].is_pending);
Expand All @@ -61,16 +61,16 @@ public override (byte, bool) IO_Read(ushort port)
return (0xaa, false);
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
if (port == 0x0040)
LatchCounter(0, value);
LatchCounter(0, (byte)value);
else if (port == 0x0041)
LatchCounter(1, value);
LatchCounter(1, (byte)value);
else if (port == 0x0042)
LatchCounter(2, value);
LatchCounter(2, (byte)value);
else if (port == 0x0043)
Command(value);
Command((byte)value);

return _timers[0].is_pending || _timers[1].is_pending || _timers[2].is_pending;
}
Expand Down
10 changes: 5 additions & 5 deletions keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ public override void RegisterDevice(Dictionary <ushort, Device> mappings)
// see PPI
}

public override bool IO_Write(ushort port, byte value)
public override bool IO_Write(ushort port, ushort value)
{
if (port == 0x0061)
{
_0x61_bits = value;
_0x61_bits = (byte)value;

if ((value & 0x40) == 0x00)
{
Log.DoLog($"Keyboard::IO_Write: clock low ({value:X2})");
Log.DoLog($"Keyboard::IO_Write: clock low ({value:X4})");
_clock_low = true;
}
else if (_clock_low)
{
_clock_low = false;

Log.DoLog($"Keyboard::IO_Write: reset triggered; clock high ({value:X2})");
Log.DoLog($"Keyboard::IO_Write: reset triggered; clock high ({value:X4})");
_keyboard_buffer_lock.WaitOne();
_keyboard_buffer.Clear();
_keyboard_buffer.Enqueue(0xaa); // power on reset reply
Expand All @@ -70,7 +70,7 @@ public override bool IO_Write(ushort port, byte value)
return false;
}

public override (byte, bool) IO_Read(ushort port)
public override (ushort, bool) IO_Read(ushort port)
{
if (port == 0x60)
{
Expand Down

0 comments on commit d40603a

Please sign in to comment.