Handle endianness on sub-word CPU reads (fixes garbled text on test ROMs).

- Added SD opcode for running some test ROMs.
- Quit the debugger when the N64 is powered off.
master
Nabile Rahmani 2018-11-29 04:39:23 +01:00
parent 585645d791
commit 48924bdfba
3 changed files with 10 additions and 4 deletions

View File

@ -61,7 +61,9 @@
/// <summary>Load Byte.</summary>
LB = 0b100000,
/// <summary>Branch On Greater Than Zero.</summary>
BGTZ = 0b000111
BGTZ = 0b000111,
/// <summary>Store Doubleword.</summary>
SD = 0b111111
}
}
}

View File

@ -165,6 +165,7 @@ namespace DotN64.CPU
[Instruction.From(OpCode.J)] = i => Jump((PC & ~((ulong)(1 << 28) - 1)) | (i.Target << 2)),
[Instruction.From(OpCode.LB)] = i => Load(i, AccessSize.Byte),
[Instruction.From(OpCode.BGTZ)] = i => Branch(i, (rs, rt) => rs > 0),
[Instruction.From(OpCode.SD)] = i => Store(i, AccessSize.DoubleWord),
[Instruction.From(SpecialOpCode.ADD)] = i => GPR[i.RD] = (ulong)((int)GPR[i.RS] + (int)GPR[i.RT]),
[Instruction.From(SpecialOpCode.JR)] = i => Jump(GPR[i.RS]),
[Instruction.From(SpecialOpCode.SRL)] = i => GPR[i.RD] = (ulong)(int)((uint)GPR[i.RT] >> i.SA),
@ -326,9 +327,11 @@ namespace DotN64.CPU
switch (size)
{
case AccessSize.Byte:
return (byte)ReadSysAD(physicalAddress);
physicalAddress &= ~0b11u;
return (byte)(ReadSysAD(physicalAddress) >> (((int)address & 0b11 ^ -(int)CP0.Config.BE) << 3));
case AccessSize.HalfWord:
return (ushort)ReadSysAD(physicalAddress);
physicalAddress &= ~0b11u;
return (ushort)(ReadSysAD(physicalAddress) >> (((int)address & 0b11 ^ (-(int)CP0.Config.BE << 1)) << 3));
case AccessSize.Word:
return ReadSysAD(physicalAddress);
case AccessSize.DoubleWord:

View File

@ -39,6 +39,7 @@ namespace DotN64.Diagnostics
[VR4300.Instruction.From(VR4300.OpCode.LW)] = InstructionFormat.I,
[VR4300.Instruction.From(VR4300.OpCode.ORI)] = InstructionFormat.I,
[VR4300.Instruction.From(VR4300.OpCode.SB)] = InstructionFormat.I,
[VR4300.Instruction.From(VR4300.OpCode.SD)] = InstructionFormat.I,
[VR4300.Instruction.From(VR4300.OpCode.SH)] = InstructionFormat.I,
[VR4300.Instruction.From(VR4300.OpCode.SLTI)] = InstructionFormat.I,
[VR4300.Instruction.From(VR4300.OpCode.SLTIU)] = InstructionFormat.I,
@ -296,7 +297,7 @@ namespace DotN64.Diagnostics
{
DebuggerStatus = debug ? Status.Debugging : Status.Running;
while (DebuggerStatus != Status.Stopped)
while (DebuggerStatus != Status.Stopped && nintendo64.Power == Switch.On)
{
switch (DebuggerStatus)
{