More OpCodes - working towards ZEXALL perfection

This commit is contained in:
2026-04-22 22:38:53 +01:00
parent b50f7a79da
commit 02680cb92d
6 changed files with 364 additions and 38 deletions

View File

@@ -1285,6 +1285,16 @@ namespace Desktop
mnemonic = $"LD (IY{sign}{d}), L";
instructionLength = 3;
}
else if (fdOpcode == 0xE1)
{
mnemonic = "POP IY";
instructionLength = 2;
}
else if(fdOpcode == 0xE5)
{
mnemonic = "PUSH IY";
instructionLength = 2;
}
else
{
mnemonic = $"FD PREFIX UNKNOWN (0x{fdOpcode:X2})";

View File

@@ -42,6 +42,9 @@
resetToolStripMenuItem = new ToolStripMenuItem();
stepToolStripMenuItem = new ToolStripMenuItem();
resetToolStripMenuItem1 = new ToolStripMenuItem();
optionsToolStripMenuItem = new ToolStripMenuItem();
fastLoadingToolStripMenuItem = new ToolStripMenuItem();
runZEXDOCToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)picScreen).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
@@ -59,7 +62,7 @@
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(24, 24);
menuStrip1.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem, viewToolStripMenuItem, machineToolStripMenuItem });
menuStrip1.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem, viewToolStripMenuItem, machineToolStripMenuItem, optionsToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(5, 2, 0, 2);
@@ -151,6 +154,29 @@
resetToolStripMenuItem1.Text = "Reset";
resetToolStripMenuItem1.Click += btnReset_Click;
//
// optionsToolStripMenuItem
//
optionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { fastLoadingToolStripMenuItem, runZEXDOCToolStripMenuItem });
optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
optionsToolStripMenuItem.Size = new Size(75, 24);
optionsToolStripMenuItem.Text = "Options";
//
// fastLoadingToolStripMenuItem
//
fastLoadingToolStripMenuItem.Checked = true;
fastLoadingToolStripMenuItem.CheckState = CheckState.Checked;
fastLoadingToolStripMenuItem.Name = "fastLoadingToolStripMenuItem";
fastLoadingToolStripMenuItem.Size = new Size(224, 26);
fastLoadingToolStripMenuItem.Text = "Fast TAP Loading";
fastLoadingToolStripMenuItem.Click += fastLoadingToolStripMenuItem_Click;
//
// runZEXDOCToolStripMenuItem
//
runZEXDOCToolStripMenuItem.Name = "runZEXDOCToolStripMenuItem";
runZEXDOCToolStripMenuItem.Size = new Size(224, 26);
runZEXDOCToolStripMenuItem.Text = "Run ZEXDOC";
runZEXDOCToolStripMenuItem.Click += btnRunZexDoc_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
@@ -185,5 +211,8 @@
private ToolStripMenuItem resetToolStripMenuItem;
private ToolStripMenuItem stepToolStripMenuItem;
private ToolStripMenuItem resetToolStripMenuItem1;
private ToolStripMenuItem optionsToolStripMenuItem;
private ToolStripMenuItem fastLoadingToolStripMenuItem;
private ToolStripMenuItem runZEXDOCToolStripMenuItem;
}
}

View File

@@ -26,6 +26,7 @@ namespace Desktop
public double FramesPerSecond = 0;
public double TotalFrameTime = 0;
public double FrameTime = 0;
public bool exceptionRaised = false;
public Form1()
@@ -40,10 +41,10 @@ namespace Desktop
{
_baseTitle = this.Text;
_memoryBus = new MemoryBus();
_simpleIoBus = new IO_Bus();
_tapManager = new TapManager();
_simpleIoBus = new IO_Bus(_tapManager);
_ula = new ULA(_memoryBus, _simpleIoBus);
_beeper = new BeeperDevice();
_tapManager = new TapManager();
_memoryBus.CrapRAMData();
byte[] romData = RomLoader.Load("48.rom");
_memoryBus.LoadRom(romData);
@@ -92,13 +93,19 @@ namespace Desktop
continue;
}
long tStatesBefore = _cpu.TotalTStates;
// --- Execute Instruction ---
_cpu.Step();
int elapsedTStates = (int)(_cpu.TotalTStates - tStatesBefore);
_tapManager.Update(elapsedTStates);
//Process audio at the correct time
while (_cpu.TotalTStates >= (long)(audioSampleCount * 79.365))
{
_beeper.AddSample(_simpleIoBus.BeeperState);
bool finalAudioOutput = _simpleIoBus.BeeperState ^ _tapManager.EarBit;
_beeper.AddSample(finalAudioOutput);
audioSampleCount++;
}
@@ -119,7 +126,7 @@ namespace Desktop
this.Invoke((MethodInvoker)delegate
{
UpdateScreenBitmap();
this.Text = $"{_baseTitle} - FPS: {FramesPerSecond:F1}";
this.Text = $"{_baseTitle} - FPS: {FramesPerSecond:F1} - Fast Loading: {_cpu.EnableFastLoad.ToString()}";
});
TotalFrameCount++;
@@ -129,7 +136,7 @@ namespace Desktop
if (elapsedMs < targetTimeMs)
{
Thread.Sleep((int)(targetTimeMs - elapsedMs));
//Thread.Sleep((int)(targetTimeMs - elapsedMs));
}
TotalFrameTime += fpsStopwatch.Elapsed.TotalMilliseconds;
if (TotalFrameCount % 50 == 0)
@@ -150,6 +157,7 @@ namespace Desktop
this.Invoke((MethodInvoker)delegate
{
MessageBox.Show(ex.Message, "CPU Crash", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
});
@@ -188,6 +196,15 @@ namespace Desktop
}
_isPaused = false;
}
private void fastLoadingToolStripMenuItem_Click(object sender, EventArgs e)
{
// Toggle the checkmark UI
fastLoadingToolStripMenuItem.Checked = !fastLoadingToolStripMenuItem.Checked;
// Tell the CPU to enable or disable the ROM hijack
_cpu.EnableFastLoad = fastLoadingToolStripMenuItem.Checked;
}
private void openSNAToolStripMenuItem_Click(object sender, EventArgs e)
{
_isPaused = true;
@@ -203,6 +220,39 @@ namespace Desktop
_isPaused = false;
}
private void btnRunZexDoc_Click(object sender, EventArgs e)
{
_isPaused = true;
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Filter = "CP/M Binaries (*.com, *.bin)|*.com;*.bin";
if (ofd.ShowDialog() == DialogResult.OK)
{
byte[] zexdocBytes = System.IO.File.ReadAllBytes(ofd.FileName);
// 1. Wipe the RAM completely clean
_memoryBus.CleanRAMData();
// 2. Load ZEXDOC exactly at CP/M start address 0x0100
for (int i = 0; i < zexdocBytes.Length; i++)
{
_memoryBus.Write((ushort)(0x0100 + i), zexdocBytes[i]);
}
// 3. Configure the CPU for CP/M
_cpu.IsZexDocMode = true;
_cpu.PC = 0x0100; // Execution starts here
_cpu.SP = 0xFFFF; // Put the stack at the very top of memory
// 4. Fake a RET address at 0x0000 so the test terminates gracefully when finished
_memoryBus.Write(0x0000, 0xD3); // OUT (n), A (A fake halt sequence)
// Unpause and watch the Visual Studio Output window!
_isPaused = false;
}
}
}
private void btnRun_Click(object sender, EventArgs e) => _isPaused = false;
private void btnPause_Click(object sender, EventArgs e) => _isPaused = true;