Skip to content

Commit

Permalink
Release 0.7.0.15
Browse files Browse the repository at this point in the history
----------------
Fixed issues with TileEditor not writing to the tileset address.
Fixed asset loader issues with palettes in F256 mode.
Added second joystick - now A and B are available from menu.
Fixed issue with virtual joystick not accepting multiple buttons/key states.
Fixed issue with CPU window breaking for incorrect IRQ.
Second attempt at fixing BCD subtractions.  The carry flag wasn't correct before.
  • Loading branch information
Daniel Tremblay committed Nov 10, 2024
1 parent f2fb052 commit d6d4c73
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 214 deletions.
124 changes: 121 additions & 3 deletions FoenixIDETester/CpuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public void CheckLargInx()
cpu.ExecuteNext();

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

cpu.X.Value = 0xFFFF;
Assert.AreEqual(0xFFFF, cpu.X.Value);
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.INX_Implied);
Expand Down Expand Up @@ -438,7 +438,7 @@ public void CheckContentOfBIsValid()
/**
* Bug reported by @Minstrel Dragon on Discord
*
* I'll perform the test in 6502 mode
* I'll perform the test in 6502 mode - Decimal Subtraction
*
* sed
* sec
Expand All @@ -448,7 +448,7 @@ public void CheckContentOfBIsValid()
* A register should contain #$94
*/
[TestMethod]
public void SubstractNegative()
public void SubstractBCDNegative()
{
ClearCarry();
// SED - switch to decimal
Expand All @@ -471,8 +471,126 @@ public void SubstractNegative()

// The result should be #$94
Assert.AreEqual(0x94, cpu.A.Value);
}

/**
* Bug reported by @Minstrel Dragon on Discord
*
* I'll perform the test in 6502 mode - Decimal Subtraction
* Need double byte to perform $200 - 1 = $199
*
*/
[TestMethod]
public void SubstractBCDWord200minus1()
{
ClearCarry();
// SED - switch to decimal
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SED_Implied);
cpu.ExecuteNext();

// SEC - set the carry bit
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SEC_Implied);
cpu.ExecuteNext();

// LDA #0
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.LDA_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x0);
cpu.ExecuteNext();

// SBC #1
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SBC_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x1);
cpu.ExecuteNext();

// The result should be #2
Assert.AreEqual(0x99, cpu.A.Value);
Assert.IsFalse(cpu.Flags.Carry);

// So the carry should be forwarded to the next SBC operation
// LDA #2
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.LDA_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x2);
cpu.ExecuteNext();

// SBC #0
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SBC_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x0);
cpu.ExecuteNext();
// The result should be #2
Assert.AreEqual(0x1, cpu.A.Value);
}
/**
* Bug reported by @Minstrel Dragon on Discord
*
* I'll perform the test in 6502 mode - Decimal Subtraction
* Need double byte to perform $100 - 1 = $99
*
*/
[TestMethod]
public void SubstractBCDWord100minus1()
{
ClearCarry();
// SED - switch to decimal
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SED_Implied);
cpu.ExecuteNext();

// SEC - set the carry bit
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SEC_Implied);
cpu.ExecuteNext();

// LDA #0
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.LDA_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x0);
cpu.ExecuteNext();

// SBC #1
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SBC_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x1);
cpu.ExecuteNext();

// The result should be #2
Assert.AreEqual(0x99, cpu.A.Value);
Assert.IsFalse(cpu.Flags.Carry);

// So the carry should be forwarded to the next SBC operation
// LDA #1
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.LDA_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x1);
cpu.ExecuteNext();

// SBC #0
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SBC_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x0);
cpu.ExecuteNext();
// The result should be #2
Assert.AreEqual(0x0, cpu.A.Value);
}

[TestMethod]
public void SubstractBCD55minus23()
{
ClearCarry();
// SED - switch to decimal
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SED_Implied);
cpu.ExecuteNext();

// SEC - set the carry bit
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SEC_Implied);
cpu.ExecuteNext();

// LDA #55
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.LDA_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x55);
cpu.ExecuteNext();

// SBC #23
MemMgr.RAM.WriteByte(cpu.PC, OpcodeList.SBC_Immediate);
MemMgr.RAM.WriteByte(cpu.PC + 1, 0x23);
cpu.ExecuteNext();

// The result should be #2
Assert.AreEqual(0x32, cpu.A.Value);
Assert.IsTrue(cpu.Flags.Carry);
}
}
}
15 changes: 11 additions & 4 deletions Main/Processor/Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,16 +1017,24 @@ public void ExecuteSBC(byte instruction, AddressModes addressMode, int signature
if (val < cpu.A.Value)
{
nv = HexVal(BCDVal(cpu.A.Value) - BCDVal(val + 1) + cpu.Flags.CarryBit);
cpu.Flags.Carry = true; // hack!
}
else
{
nv = HexVal(0x64 + BCDVal(cpu.A.Value) - BCDVal(val + 1) + cpu.Flags.CarryBit);
if (cpu.A.Width == 1)
{
nv = HexVal(100 + BCDVal(cpu.A.Value) - BCDVal(val + 1) + cpu.Flags.CarryBit);
}
else
{
nv = HexVal(10000 + BCDVal(cpu.A.Value) - BCDVal(val + 1) + cpu.Flags.CarryBit);
}
cpu.Flags.Carry = false; // hack!
}
}
else
{
nv = cpu.A.Value - val - 1 + cpu.Flags.CarryBit;

if (cpu.A.Width == 1)
{
cpu.Flags.oVerflow = ((cpu.A.Value ^ nv) & ((0x100 - val - 1 + cpu.Flags.CarryBit) ^ nv) & 0x80) != 0;
Expand All @@ -1035,10 +1043,9 @@ public void ExecuteSBC(byte instruction, AddressModes addressMode, int signature
{
cpu.Flags.oVerflow = ((cpu.A.Value ^ nv) & ((0x10000 - val - 1 + cpu.Flags.CarryBit) ^ nv) & 0x8000) != 0;
}
cpu.Flags.Carry = (nv >= 0 && nv <= cpu.A.MaxUnsigned);
}
cpu.Flags.Carry = (nv >= 0 && nv <= cpu.A.MaxUnsigned);
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.7.0.14")]
[assembly: AssemblyFileVersion("0.7.0.14")]
[assembly: AssemblyVersion("0.7.0.15")]
[assembly: AssemblyFileVersion("0.7.0.15")]
9 changes: 8 additions & 1 deletion Main/UI/AssetDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ private void AssetGrid_CellClick(object sender, DataGridViewCellEventArgs e)

FileStream dataFile = File.Create(saveDlg.FileName, 0x800, FileOptions.SequentialScan);
byte[] buffer = new byte[res.Length];
kernel_ref.MemMgr.CopyIntoBuffer(res.StartAddress, res.Length, buffer);
if (res.FileType == ResourceType.lut && kernel_ref.MemMgr.MMU != null)
{
kernel_ref.MemMgr.VICKY.CopyIntoBuffer(res.StartAddress, res.Length, buffer);
}
else
{
kernel_ref.MemMgr.CopyIntoBuffer(res.StartAddress, res.Length, buffer);
}
dataFile.Write(buffer, 0, res.Length);
dataFile.Close();

Expand Down
37 changes: 33 additions & 4 deletions Main/UI/AssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public partial class AssetLoader : Form
public int topLeftPixelColor = 0;
private bool isF256;
private Display.Gpu GpuRef;
private int F256_LUT_STORE = 0x7_0000;

public AssetLoader()
{
Expand Down Expand Up @@ -116,7 +115,16 @@ private void BrowseFileButton_Click(object sender, EventArgs e)
FileTypesCombo.SelectedIndex = 6;
LUTCombo.SelectedIndex = 0;
LUTCombo.Enabled = true;
LoadAddressTextBox.Text = "AF:2000";
if (isF256)
{

LoadAddressTextBox.Text = "00:3000";
}
else
{
LoadAddressTextBox.Text = "AF:2000";
}

}
else if (".tlm".Equals(ExtLabel.Text.ToLower()))
{
Expand Down Expand Up @@ -285,6 +293,27 @@ private void StoreButton_Click(object sender, EventArgs e)
}
}
break;
case ".pal":
// Read the file as raw
byte[] colorData = File.ReadAllBytes(FileNameTextBox.Text);
// Check if there's a resource conflict
res.Length = colorData.Length;
if (ResChecker.Add(res))
{
if (isF256)
{
MemMgrRef.VICKY.CopyBuffer(colorData, 0, destAddress, colorData.Length);
}
else
{
MemMgrRef.CopyBuffer(colorData, 0, destAddress, colorData.Length);
}
}
else
{
res.Length = -1;
}
break;
default:
// Read the file as raw
byte[] data = File.ReadAllBytes(FileNameTextBox.Text);
Expand Down Expand Up @@ -549,15 +578,15 @@ private unsafe void ConvertBitmapToRaw(Bitmap bitmap, ResourceChecker.Resource r
if (!gray)
{
// Check if a LUT matching our index is present in the Resources, if so don't do anything.
Resource resLut = ResChecker.Find(ResourceType.lut, isF256? lutBaseAddress + F256_LUT_STORE - 0x3000 : lutBaseAddress + MemoryLocations.MemoryMap.VICKY_BASE_ADDR);
Resource resLut = ResChecker.Find(ResourceType.lut, isF256? lutBaseAddress : lutBaseAddress + MemoryLocations.MemoryMap.VICKY_BASE_ADDR);
if (resLut == null)
{
Resource lutPlaceholder = new Resource
{
Length = 0x400,
FileType = ResourceType.lut,
Name = "Generated LUT",
StartAddress = isF256 ? lutBaseAddress + F256_LUT_STORE - 0x3000 : lutBaseAddress + MemoryLocations.MemoryMap.VICKY_BASE_ADDR
StartAddress = isF256 ? lutBaseAddress : lutBaseAddress + MemoryLocations.MemoryMap.VICKY_BASE_ADDR
};
ResChecker.Add(lutPlaceholder);
}
Expand Down
Loading

0 comments on commit d6d4c73

Please sign in to comment.