-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleUse.java
More file actions
75 lines (59 loc) · 2.33 KB
/
ExampleUse.java
File metadata and controls
75 lines (59 loc) · 2.33 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package chip8;
/**
* Created by RYZEN on 14.04.2018.
*/
public class ExampleUse {
public static void main(String[] args) {
ExampleUse use = new ExampleUse();
use.setup();
}
public void setup() {
final CHIP8 chip = new CHIP8(); //create chip instance
//load program into chip memory
byte[] program_bytes = new byte[1]; //= file.readBytes(); or whatever what suits your needs
chip.load(program_bytes);
//run chip emulation on other thread
Thread chip_thread = new Thread(new Runnable() {
@Override
public void run() {
final float UPS = 500; //500 steps each second of emulation
final float sleep_time = 1f / UPS * 1000f; //calculate period from frequency (in milis thats why * 1000) so we know for how long thread must sleep each frame
while(true) {
chip.emulationStep();
try {
Thread.sleep((long) sleep_time);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
chip_thread.start();
//setup keyboard input
/**
* pseudo code
*
* if(keyPressed('A'))
* chip.getKeyboard().justSet(10, 1); //key 10, pressed
*
* if(keyReleased('A'))
* chip.getKeyboard().justSet(10, 0);
*/
//somewhere in render method
/**
* render method somewhere in your code, just if pixel val if true we have to draw square somewhere f.e. as letter in console or white rect on screen using opengl
float tile_size_x = 16;
float tile_size_y = tile_size_x;
for (int i = 0; i < chip.getGFX().getPixelsBuffer().length; i++) {
for (int j = 0; j < chip.getGFX().getPixelsBuffer()[0].length; j++) {
boolean pixel = chip.getGFX().getPixelsBuffer()[i][(chip.getGFX().getPixelsBuffer()[0].length - 1) - j];
if (pixel)
drawSquare(i * tile_size_x, j * tile_size_y, tile_size_x, tile_size_y); //drawSquare(x, y, w, h)
}
}
*/
//on app exit
chip.shutoff();
chip_thread.interrupt();
}
}