Added the APU Class and wired it all up ready for the maths

This commit is contained in:
2026-05-14 21:27:05 +01:00
parent 708c1ba458
commit cafcf625ad
6 changed files with 549 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
using Core.Cpu;
using Core.Io;
using Core.Memory;
using Core.Video;
using Core.Audio;
using System;
using System.IO;
using System.Collections.Generic;
@@ -12,7 +14,8 @@ 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 SmsVdp VideoProcessor { get; private set; }
public SmsApu AudioProcessor { get; private set; }
public ushort? Breakpoint { get; set; } = null;
// NTSC SMS T-States per frame
@@ -21,8 +24,9 @@ namespace Core
public SmsMachine()
{
MemoryBus = new SmsMemoryBus();
VideoProcessor = new Core.Video.SmsVdp();
IoBus = new SmsIoBus { VideoProcessor = this.VideoProcessor };
VideoProcessor = new SmsVdp();
AudioProcessor = new SmsApu();
IoBus = new SmsIoBus { VideoProcessor = this.VideoProcessor, AudioProcessor = this.AudioProcessor };
Cpu = new Z80(MemoryBus, IoBus);
}
@@ -50,13 +54,15 @@ namespace Core
// 2. Tell the VDP to catch up
VideoProcessor.Update(cycles);
AudioProcessor.Update(cycles);
// 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
VideoProcessor.Update(intCycles);
AudioProcessor.Update(intCycles);
}
// 4. THE RESTORED BREAKPOINT TRAP