Got main system and VDP working! There is a display!
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using Core.Cpu;
|
||||
using Core.Io;
|
||||
using Core.Memory;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Core
|
||||
{
|
||||
@@ -9,18 +12,17 @@ namespace Core
|
||||
public Z80 Cpu { get; private set; }
|
||||
public SmsMemoryBus MemoryBus { get; private set; }
|
||||
public SmsIoBus IoBus { get; private set; }
|
||||
public Core.Video.SmsVdp VideoProcessor { get; private set; }
|
||||
public ushort? Breakpoint { get; set; } = null;
|
||||
|
||||
// NTSC SMS T-States per frame
|
||||
public const int TStatesPerFrame = 59736;
|
||||
public long TotalFrameCount { get; private set; } = 0;
|
||||
public double FramesPerSecond { get; private set; } = 0;
|
||||
public double FrameTime { get; private set; } = 0;
|
||||
|
||||
public SmsMachine()
|
||||
{
|
||||
MemoryBus = new SmsMemoryBus();
|
||||
IoBus = new SmsIoBus();
|
||||
VideoProcessor = new Core.Video.SmsVdp();
|
||||
IoBus = new SmsIoBus { VideoProcessor = this.VideoProcessor };
|
||||
Cpu = new Z80(MemoryBus, IoBus);
|
||||
}
|
||||
|
||||
@@ -34,8 +36,23 @@ namespace Core
|
||||
{
|
||||
MemoryBus.CleanRAMData();
|
||||
Cpu.Reset();
|
||||
}
|
||||
|
||||
// We will reset the VDP and PSG here later!
|
||||
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()
|
||||
@@ -44,18 +61,51 @@ namespace Core
|
||||
|
||||
while (currentFrameTStates < TStatesPerFrame)
|
||||
{
|
||||
int tStates = Cpu.Step();
|
||||
currentFrameTStates += tStates;
|
||||
currentFrameTStates += StepMachine();
|
||||
string filePath = "captured_data.txt";
|
||||
|
||||
// --- FUTURE EXPANSION ---
|
||||
// VideoProcessor.Update(tStates);
|
||||
// AudioProcessor.Update(tStates);
|
||||
// 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" };
|
||||
|
||||
// if (VideoProcessor.IsVBlanking && VideoProcessor.InterruptsEnabled)
|
||||
// {
|
||||
// Cpu.RequestInterrupt();
|
||||
// }
|
||||
//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. 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!
|
||||
if (Breakpoint.HasValue && Cpu.PC == Breakpoint.Value)
|
||||
{
|
||||
break; // Abort the frame loop immediately!
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user