-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmulator.java
36 lines (31 loc) · 1.07 KB
/
Emulator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.awt.*;
import javax.swing.*;
public class Emulator{
static Chip8GUIunit window = new Chip8GUIunit();
static Chip8 cpu;
public static void main(String[] args) throws InterruptedException{
cpu = new Chip8(window);
//emulation loop
while(true){
//cpu locking mechanism for op_FX0A
if(window.key_update_flag){
cpu.cpu_lock = false;
//if last called opcode is op_FX0A
cpu.registers[cpu.save_x] = window.latest_key;
}
window.key_update_flag = false;
if(!cpu.cpu_lock){
//emulate a single cycle
cpu.emulateCycle();
//check draw flag if graphics need to be updated
if(cpu.draw_flag){
cpu.draw_flag = false;
window.update_screen(cpu.screen_data);
}
//update key presses
cpu.key_state = window.key_state;
}
Thread.sleep(3);
}
}
}