Skip to content

Commit

Permalink
Simplify i/o port handling in Z80 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianConlon committed Jan 27, 2025
1 parent a15cff4 commit e8d770c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Z80/Z80.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ private void ExecuteED(int x, int y, int z, int p, int q)
this.Bus.Address.Assign(this.BC);
this.MEMPTR.Assign(this.Bus.Address);
this.MEMPTR.Word++;
_ = this.ReadPort();
this.ReadPort();
if (y != 6)
{
this.R(y, AccessLevel.WriteOnly) = this.Bus.Data; // IN r[y],(C)
Expand Down Expand Up @@ -1443,7 +1443,8 @@ private void ExecuteOther(int x, int y, int z, int p, int q)
this.WritePort(this.FetchByte());
break;
case 3: // IN A,(n)
this.A = this.ReadPort(this.FetchByte());
this.ReadPort(this.FetchByte());
this.A = this.Bus.Data;
break;
case 4: // EX (SP),HL
this.XHTL(this.HL2());
Expand Down Expand Up @@ -2018,7 +2019,7 @@ private void BlockIn(Register16 source, Register16 destination)
this.Bus.Address.Assign(source);
this.MEMPTR.Assign(this.Bus.Address);
this.Tick();
_ = this.ReadPort();
this.ReadPort();
this.Tick(3);
this.MemoryWrite(destination);
source.High = this.Decrement(source.High);
Expand Down Expand Up @@ -2158,23 +2159,22 @@ private void WritePort()
this.RaiseIORQ();
}

private byte ReadPort(byte port)
private void ReadPort(byte port)
{
this.Bus.Address.Assign(port, this.Bus.Data = this.A);
this.MEMPTR.Assign(this.Bus.Address);
++this.MEMPTR.Low;
return this.ReadPort();
this.ReadPort();
}

private byte ReadPort()
private void ReadPort()
{
this.Tick();
this.LowerIORQ();
this.LowerRD();
var returned = this.Bus.Data = this._ports.Read(this.Bus.Address.Low);
this.Bus.Data = this._ports.Read(this.Bus.Address.Low);
this.RaiseRD();
this.RaiseIORQ();
return returned;
}
}
}

0 comments on commit e8d770c

Please sign in to comment.