-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCpu.java
More file actions
105 lines (78 loc) · 1.75 KB
/
Cpu.java
File metadata and controls
105 lines (78 loc) · 1.75 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.Random;
/**
* Represents the CPU and memory state of the CHIP-8 emulator.
*/
public class Cpu {
/** Main memory (4KB) */
private final short[] memory = new short[4096];
/** Registers V0 through VF */
private final short[] v = new short[16];
/** Index register I */
private short i;
/** Delay Timer and Sound Timer registers */
private short dt, st;
/** Program Counter */
private short pc;
/** Stack for subroutine addresses */
private final short[] stack = new short[16];
/** Stack pointer */
private short sp;
/** Random number generator for opcode CXKK */
private final Random rnd = new Random();
/** Screen memory (64x32 pixels) */
private final short[] screen = new short[2048];
// Getters and Setters for fields accessed by ProcessingUnit
public short[] getMemory() {
return memory;
}
public short[] getV() {
return v;
}
public short getI() {
return i;
}
public void setI(short i) {
this.i = i;
}
public short getDt() {
return dt;
}
public void setDt(short dt) {
this.dt = dt;
}
public short getSt() {
return st;
}
public void setSt(short st) {
this.st = st;
}
public short getPc() {
return pc;
}
public void setPc(short pc) {
this.pc = pc;
}
public short[] getStack() {
return stack;
}
public short getSp() {
return sp;
}
public void setSp(short sp) {
this.sp = sp;
}
public Random getRnd() {
return rnd;
}
public short[] getScreen() {
return screen;
}
/**
* Dumps the current memory state to the log (using JCL or similar).
* Note: Per user rules, avoiding System.out.println.
*/
public void dumpMemory() {
// Implementation for logging would go here if a logger was defined.
// For now, keeping it commented or using a future-proof placeholder.
}
}