mirror of
https://github.com/BluestormDNA/ProjectPSX.git
synced 2025-04-02 10:52:34 -04:00
Main Loop Tests
This commit is contained in:
parent
5a68c555a8
commit
ff9f61671c
1 changed files with 42 additions and 6 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue