Skip to content

Commit

Permalink
Release 0.5.4.1
Browse files Browse the repository at this point in the history
---------------
Fixed a bug in the SBC when using a 16-bit accumulator.
Removed the "Open Hex File (w/o Zeroing)" - the option was confusing.
Removed the silly blue border around the GPU control.
Fixed loading of breakpoints with the Foenix XML file.
  • Loading branch information
dtremblay committed Jan 7, 2021
1 parent f20575d commit f312739
Show file tree
Hide file tree
Showing 11 changed files with 5,555 additions and 5,545 deletions.
46 changes: 46 additions & 0 deletions FoenixIDETester/CpuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,51 @@ public void TestOverflowSBC9()
Assert.IsTrue(cpu.Flags.Carry, "Carry should be true");
Assert.IsTrue(cpu.Flags.oVerflow, "Overflow should be true");
}

/**
* Error reported by Phil
* CLC
* XCE
* REP #$30
*
* SEC
* LDA #$AA
* SBC #$78
*
* Carry should be set
*/
[TestMethod]
public void TestOverflowSBC10()
{
ClearCarry();
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.XCE_Implied);
cpu.ExecuteNext();
Assert.IsFalse(cpu.Flags.Emulation);
Assert.IsTrue(cpu.Flags.Carry);

// REP #$30
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.REP_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x30);
cpu.ExecuteNext();

Assert.AreEqual(2, cpu.A.Width);
Assert.AreEqual(2, cpu.X.Width);

// SEC
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SEC_Implied);

// LDA #$AA
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.LDA_Immediate);
MemMgr.RAM.WriteWord(cpu.PC + 1, 0xAA);
cpu.ExecuteNext();

MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SBC_Immediate);
MemMgr.RAM.WriteWord(cpu.PC + 1, 0x78);
cpu.ExecuteNext();

Assert.AreEqual(0x32, cpu.A.Value);
Assert.IsTrue(cpu.Flags.Carry, "Carry should be true");
Assert.IsFalse(cpu.Flags.oVerflow, "Overflow should be false");
}
}
}
45 changes: 9 additions & 36 deletions Main/FoenixSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class FoenixSystem
{
public MemoryManager MemMgr = null;
public Processor.CPU CPU = null;
public Gpu gpu = null;

public ResourceChecker Resources;
public Processor.Breakpoints Breakpoints = new Processor.Breakpoints();
Expand All @@ -25,9 +24,8 @@ public class FoenixSystem
public SortedList<int, WatchedMemory> WatchList = new SortedList<int, WatchedMemory>();
private string LoadedKernel;

public FoenixSystem(Gpu gpu, BoardVersion version, string DefaultKernel)
public FoenixSystem(BoardVersion version, string DefaultKernel)
{
this.gpu = gpu;
boardVersion = version;

int memSize = MemoryMap.RAM_SIZE;
Expand Down Expand Up @@ -72,18 +70,12 @@ public FoenixSystem(Gpu gpu, BoardVersion version, string DefaultKernel)

// Assign memory variables used by other processes
CPU = new CPU(MemMgr);
CPU.SimulatorCommand += CPU_SimulatorCommand;
gpu.VRAM = MemMgr.VIDEO;
gpu.RAM = MemMgr.RAM;
gpu.VICKY = MemMgr.VICKY;

MemMgr.VDMA.setVideoRam(MemMgr.VIDEO);
MemMgr.VDMA.setSystemRam(MemMgr.RAM);

// Load the kernel.hex if present
ResetCPU(true, DefaultKernel);

// This fontset is loaded just in case the kernel doesn't provide one.
gpu.LoadFontSet("Foenix", @"Resources\Bm437_PhoenixEGA_8x8.bin", 0, CharacterSet.CharTypeCodes.ASCII_PET, CharacterSet.SizeCodes.Size8x8);
ResetCPU(DefaultKernel);

// Write bytes $9F in the joystick registers to mean that they are not installed.
MemMgr.WriteWord(0xAFE800, 0x9F9F);
Expand All @@ -93,18 +85,6 @@ public FoenixSystem(Gpu gpu, BoardVersion version, string DefaultKernel)
MemMgr.TIMER2.TimerInterruptDelegate += TimerEvent2;
}

private void CPU_SimulatorCommand(int EventID)
{
switch (EventID)
{
case SimulatorCommands.RefreshDisplay:
gpu.BlinkingCounter = Gpu.BLINK_RATE;
break;
default:
break;
}
}

private void TimerEvent0()
{
byte mask = MemMgr.ReadByte(MemoryLocations.MemoryMap.INT_MASK_REG0);
Expand Down Expand Up @@ -151,16 +131,14 @@ public void SetVersion(BoardVersion rev)
boardVersion = rev;
}
// return true if the CPU was reset and the program was loaded
public bool ResetCPU(bool ResetMemory, string kernelFilename)
public bool ResetCPU(string kernelFilename)
{
if (CPU != null)
{
CPU.DebugPause = true;
//CPU.Halt();
}

gpu.Refresh();

if (kernelFilename != null)
{
LoadedKernel = kernelFilename;
Expand All @@ -182,19 +160,15 @@ public bool ResetCPU(bool ResetMemory, string kernelFilename)
}
else
{
if (ResetMemory)
{
this.ResetMemory();
}
LoadedKernel = HexFile.Load(MemMgr.RAM, LoadedKernel, BasePageAddress, out _, out _);
if (LoadedKernel != null)
{
if (ResetMemory)
if (lstFile == null)
{
lstFile = new ListFile(LoadedKernel);
}
else
{
{
// TODO: This results in lines of code to be shown in incorrect order - Fix
ListFile tempList = new ListFile(LoadedKernel);
foreach (DebugLine line in tempList.Lines.Values)
Expand All @@ -204,14 +178,13 @@ public bool ResetCPU(bool ResetMemory, string kernelFilename)
lstFile.Lines.Remove(line.PC);
}
lstFile.Lines.Add(line.PC, line);
for (int i=1; i < line.commandLength; i++)
for (int i = 1; i < line.commandLength; i++)
{
if (lstFile.Lines.ContainsKey(line.PC+i))
if (lstFile.Lines.ContainsKey(line.PC + i))
{
lstFile.Lines.Remove(line.PC+i);
lstFile.Lines.Remove(line.PC + i);
}
}

}
}
}
Expand Down
10 changes: 9 additions & 1 deletion Main/Processor/Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,15 @@ public void ExecuteSBC(byte instruction, AddressModes addressMode, int signature
nv = cpu.A.Value - val - 1 + cpu.Flags.CarryBit;

cpu.Flags.Carry = (nv >= 0 && nv <= cpu.A.MaxUnsigned);
cpu.Flags.oVerflow = ((cpu.A.Value ^ nv) & ((256 - val) ^ nv) & 0x80) != 0;
if (cpu.A.Width == 1)
{
cpu.Flags.oVerflow = ((cpu.A.Value ^ nv) & ((256 - val) ^ nv) & 0x80) != 0;
}
else
{
cpu.Flags.oVerflow = ((cpu.A.Value ^ nv) & ((65536 - val) ^ nv) & 0x8000) != 0;
}

cpu.Flags.SetNZ(nv, cpu.A.Width);

cpu.A.Value = nv;
Expand Down
4 changes: 2 additions & 2 deletions Main/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.4.0")]
[assembly: AssemblyFileVersion("0.5.4.0")]
[assembly: AssemblyVersion("0.5.4.1")]
[assembly: AssemblyFileVersion("0.5.4.1")]
29 changes: 29 additions & 0 deletions Main/UI/CPUWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public void SetKernel(FoenixSystem kernel)
MemoryLimit = kernel.MemMgr.RAM.Length;
registerDisplay1.CPU = kernel.CPU;
knl_breakpoints = kernel.Breakpoints;
if (knl_breakpoints.Count > 0)
{
BPLabel.Text = knl_breakpoints.Count.ToString() + " BP";
// Update the combo
foreach (KeyValuePair<int, string> kvp in knl_breakpoints)
{
BPCombo.Items.Add(kvp.Value);
UpdateDebugLines(kvp.Key, true);
}
}
else
{
BPLabel.Text = "Breakpoint";
}

UpdateQueue();
int pc = kernel.CPU.PC;
DebugLine line = GetExecutionInstruction(pc);
Expand Down Expand Up @@ -608,6 +623,20 @@ public void ExecuteStep()
(BreakOnIRQCheckBox.Checked && (kernel.CPU.Pins.GetInterruptPinActive && InterruptMatchesCheckboxes()) )
)
{
if (kernel.CPU.CurrentOpcode.Value == 0)
{
if (lastLine.InvokeRequired)
{
lastLine.Invoke((MethodInvoker)delegate
{
lastLine.Text = "BRK OpCode read";
});
}
else
{
lastLine.Text = "BRK OpCode read";
}
}
if (UpdateTraceTimer.Enabled || kernel.CPU.CurrentOpcode.Value == 0)
{
UpdateTraceTimer.Enabled = false;
Expand Down
Loading

0 comments on commit f312739

Please sign in to comment.