61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using Core.Cpu;
|
|
using Core.Io;
|
|
using Core.Memory;
|
|
|
|
namespace Core
|
|
{
|
|
public class SmsMachine
|
|
{
|
|
public Z80 Cpu { get; private set; }
|
|
public SmsMemoryBus MemoryBus { get; private set; }
|
|
public SmsIoBus IoBus { 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();
|
|
Cpu = new Z80(MemoryBus, IoBus);
|
|
}
|
|
|
|
public void LoadCartridge(byte[] romData)
|
|
{
|
|
MemoryBus.LoadCartridge(romData);
|
|
Reset();
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
MemoryBus.CleanRAMData();
|
|
Cpu.Reset();
|
|
|
|
// We will reset the VDP and PSG here later!
|
|
}
|
|
|
|
public void RunFrame()
|
|
{
|
|
long currentFrameTStates = 0;
|
|
|
|
while (currentFrameTStates < TStatesPerFrame)
|
|
{
|
|
int tStates = Cpu.Step();
|
|
currentFrameTStates += tStates;
|
|
|
|
// --- FUTURE EXPANSION ---
|
|
// VideoProcessor.Update(tStates);
|
|
// AudioProcessor.Update(tStates);
|
|
|
|
// if (VideoProcessor.IsVBlanking && VideoProcessor.InterruptsEnabled)
|
|
// {
|
|
// Cpu.RequestInterrupt();
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
} |