Main Loop Tests

This commit is contained in:
Blue 2019-05-23 10:30:44 +02:00
parent 5a68c555a8
commit ff9f61671c

View file

@ -1,13 +1,25 @@
using System.Threading.Tasks;
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace ProjectPSX {
class ProjectPSX {
const int PSX_MHZ = 33868800;
private CPU cpu;
private BUS bus;
private Window window;
private long cycle;
private long counter;
Stopwatch watch = new Stopwatch();
public ProjectPSX(Window window) {
cpu = new CPU();
this.window = window;
bus = new BUS();
cpu = new CPU(bus);
bus.loadBios();
@ -19,10 +31,34 @@ namespace ProjectPSX {
}
public void EXECUTE() {
while (true) {
cpu.Run(bus);
bus.tick(2); //2 ticks per opcode
cpu.handleInterrupts(bus);
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
Thread.CurrentThread.Priority = ThreadPriority.Highest;
try {
while (true) {
if(cycle == 1) {
watch.Restart();
}
for(int i = 0; i < 50; i++) {
cpu.Run();
cpu.handleInterrupts();
counter++;
}
bus.tick(150); //2 ticks per opcode
if (counter >= PSX_MHZ) {
counter = 0;
cycle = 0;
window.Text = "ProjectPSX | Fps: " + (60 / ((float)watch.ElapsedMilliseconds / 1000)).ToString();
}
cycle++;
}
} catch(Exception e) {
Console.WriteLine(e.ToString());
}
}