Added acanline rendering. Fixed interrupts. Added XInput support
This commit is contained in:
@@ -38,74 +38,33 @@ namespace Core
|
||||
Cpu.Reset();
|
||||
}
|
||||
|
||||
public int StepMachine()
|
||||
{
|
||||
// 1. Tick the CPU
|
||||
int tStates = Cpu.Step();
|
||||
|
||||
// 2. Tell the VDP how much time just passed
|
||||
VideoProcessor.Update(tStates);
|
||||
|
||||
// 3. Trigger interrupts if the VDP hit scanline 192
|
||||
if (VideoProcessor.InterruptPending)
|
||||
{
|
||||
tStates += Cpu.RequestInterrupt();
|
||||
}
|
||||
|
||||
return tStates;
|
||||
}
|
||||
|
||||
|
||||
public void RunFrame()
|
||||
{
|
||||
long currentFrameTStates = 0;
|
||||
|
||||
while (currentFrameTStates < TStatesPerFrame)
|
||||
int tStatesThisFrame = 0;
|
||||
while (tStatesThisFrame < 59736) // Standard NTSC frame time
|
||||
{
|
||||
currentFrameTStates += StepMachine();
|
||||
string filePath = "captured_data.txt";
|
||||
// 1. Run one CPU instruction
|
||||
int cycles = Cpu.Step();
|
||||
tStatesThisFrame += cycles;
|
||||
|
||||
// Mock data to loop through
|
||||
//List<ushort> sensorReadings = new List<ushort> { Cpu.PC, Cpu.AF.Word, Cpu.BC.Word, Cpu.DE.Word, Cpu.HL.Word, Cpu.SP};
|
||||
//List<string> type = new List<string> {"PC: 0x", "AF: 0x", "BC: 0x", "DE: 0x", "HL: 0x", "SP: 0x" };
|
||||
// 2. Tell the VDP to catch up
|
||||
VideoProcessor.Update(cycles);
|
||||
|
||||
//try
|
||||
//{
|
||||
// // 2. Initialize StreamWriter within a 'using' block
|
||||
// // The 'true' parameter means "append" to the file. Use 'false' to overwrite.
|
||||
// using (StreamWriter writer = new StreamWriter(filePath, append: true))
|
||||
// {
|
||||
// foreach (int reading in sensorReadings)
|
||||
// {
|
||||
// string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
// 3. Check if the VDP is begging for attention!
|
||||
if (VideoProcessor.InterruptPending && Cpu.IFF1)
|
||||
{
|
||||
int intCycles = Cpu.RequestInterrupt();
|
||||
tStatesThisFrame += intCycles;
|
||||
VideoProcessor.Update(intCycles); // Keep VDP perfectly in sync
|
||||
}
|
||||
|
||||
// // 3. Construct your string and write it
|
||||
// foreach (string _type in type)
|
||||
// {
|
||||
// string line = $"{timestamp} | {_type} {reading}";
|
||||
// writer.WriteLine(line);
|
||||
// }
|
||||
|
||||
|
||||
// // Optional: Console feedback
|
||||
// //Console.WriteLine($"Logged: {line}");
|
||||
// }
|
||||
// }
|
||||
// // File is automatically closed and saved here
|
||||
|
||||
// //Console.WriteLine("Data capture complete.");
|
||||
//}
|
||||
//catch (IOException e)
|
||||
//{
|
||||
// Console.WriteLine($"An error occurred: {e.Message}");
|
||||
//}
|
||||
|
||||
// THE TRIPWIRE: Check the breakpoint after EVERY single instruction!
|
||||
// 4. THE RESTORED BREAKPOINT TRAP
|
||||
if (Breakpoint.HasValue && Cpu.PC == Breakpoint.Value)
|
||||
{
|
||||
break; // Abort the frame loop immediately!
|
||||
break; // Instantly abort the frame so the debugger can take over!
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user