Newer
Older
import React, { FC, useEffect, useState } from "react";
import { ButtonSwitch, Info, Pair } from "emukit";
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
import { AudioGB } from "../audio-gb/audio-gb";
import { RegistersGB } from "../registers-gb/registers-gb";
import { TilesGB } from "../tiles-gb/tiles-gb";
import { GameboyEmulator } from "../../../ts";
import "./debug.css";
type EmulatorProps = {
emulator: GameboyEmulator;
};
export const DebugVideo: FC<EmulatorProps> = ({ emulator }) => {
return (
<>
{emulator.getTile && (
<div
style={{
display: "inline-block",
verticalAlign: "top",
marginRight: 32,
width: 256
}}
>
<h3>VRAM Tiles</h3>
<TilesGB
getTile={(index) =>
emulator.getTile
? emulator.getTile(index)
: new Uint8Array()
}
tileCount={384}
width={"100%"}
contentBox={false}
/>
</div>
)}
<div
style={{
display: "inline-block",
verticalAlign: "top"
}}
>
<h3>Registers</h3>
<RegistersGB getRegisters={() => emulator.registers} />
</div>
</>
);
};
export const DebugAudio: FC<EmulatorProps> = ({ emulator }) => {
return (
<>
<div
style={{
display: "inline-block",
verticalAlign: "top"
}}
>
<h3>Audio Waveform</h3>
<AudioGB getAudioOutput={() => emulator.audioOutput} />
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
export const DebugSettings: FC<EmulatorProps> = ({ emulator }) => {
return (
<>
<DebugSettingsContent emulator={emulator}></DebugSettingsContent>
</>
);
};
const DebugSettingsContent: FC<EmulatorProps> = ({ emulator }) => {
const [updated, setUpdated] = useState(Date.now());
useEffect(() => {
const onAudioState = () => {
setUpdated(Date.now());
};
emulator.bind("audio-state", onAudioState);
return () => {
emulator.unbind("audio-state", onAudioState);
};
}, []);
const onPpuChange = (option: string) => {
emulator.instance?.set_ppu_enabled(option === "on");
};
const onApuChange = (option: string) => {
emulator.instance?.set_apu_enabled(option === "on");
};
const onTimerChange = (option: string) => {
emulator.instance?.set_timer_enabled(option === "on");
};
const onSerialChange = (option: string) => {
emulator.instance?.set_serial_enabled(option === "on");
};
return (
<Info key={updated}>
<Pair
name={"PPU"}
valueNode={
<ButtonSwitch
options={["on", "off"]}
value={emulator.instance?.ppu_enabled() ? "on" : "off"}
uppercase={true}
size={"large"}
style={["simple"]}
onChange={onPpuChange}
/>
}
/>
<Pair
name={"APU"}
valueNode={
<ButtonSwitch
options={["on", "off"]}
value={emulator.instance?.apu_enabled() ? "on" : "off"}
uppercase={true}
size={"large"}
style={["simple"]}
onChange={onApuChange}
/>
}
/>
<Pair
name={"Timer"}
valueNode={
<ButtonSwitch
options={["on", "off"]}
value={
emulator.instance?.timer_enabled() ? "on" : "off"
}
uppercase={true}
size={"large"}
style={["simple"]}
onChange={onTimerChange}
/>
}
/>
<Pair
name={"Serial"}
valueNode={
<ButtonSwitch
options={["on", "off"]}
value={
emulator.instance?.serial_enabled() ? "on" : "off"
}
uppercase={true}
size={"large"}
style={["simple"]}
onChange={onSerialChange}
/>
}
/>
</Info>
);
};