Skip to content
Snippets Groups Projects
Verified Commit 62b4fc96 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

refactor: removed more dead code and allowed

engine switching
parent 7da32e19
No related branches found
No related tags found
1 merge request!9Version 0.4.0 🍾
Pipeline #1400 passed
...@@ -18,70 +18,13 @@ ...@@ -18,70 +18,13 @@
<div class="side-left"> <div class="side-left">
</div> </div>
<div class="side-right"> <div class="side-right">
<div class="separator"></div> <div id="separator-narrative" class="separator"></div>
<div id="section-narrative" class="section">
<p>This is a <a href="https://en.wikipedia.org/wiki/Game_Boy" target="_blank">Game Boy</a> emulator built using
the <a href="https://www.rust-lang.org" target="_blank">Rust Programming Language</a> and is running
inside this browser with the help of <a href="https://webassembly.org/" target="_blank">WebAssembly</a>.
</p>
<p>You can check the source code of it at <a href="https://gitlab.stage.hive.pt/joamag/boytacean"
target="_blank">GitLab</a>.</p>
<p>TIP: Drag and Drop ROM files to the Browser to load the ROM.</p>
</div>
<div id="separator-narrative" class="separator"></div>
<div id="section-keyboard" class="section" style="display: none;">
<div id="keyboard" class="keyboard">
<div class="keyboard-line">
<span class="key">1</span>
<span class="key">2</span>
<span class="key">3</span>
<span class="key">4</span>
</div>
<div class="keyboard-line">
<span class="key">Q</span>
<span class="key">W</span>
<span class="key">E</span>
<span class="key">R</span>
</div>
<div class="keyboard-line">
<span class="key">A</span>
<span class="key">S</span>
<span class="key">D</span>
<span class="key">F</span>
</div>
<div class="keyboard-line">
<span class="key">Z</span>
<span class="key">X</span>
<span class="key">C</span>
<span class="key">V</span>
</div>
</div>
</div>
<div id="separator-keyboard" class="separator" style="display: none;"></div>
<div id="section-debug" class="section" style="display: none;"> <div id="section-debug" class="section" style="display: none;">
<div id="debug" class="debug"> <div id="debug" class="debug">
<canvas id="canvas-tiles" class="canvas-tiles" width="128" height="192"></canvas> <canvas id="canvas-tiles" class="canvas-tiles" width="128" height="192"></canvas>
</div> </div>
</div> </div>
<div id="separator-debug" class="separator" style="display: none;"></div> <div id="separator-debug" class="separator" style="display: none;"></div>
<div id="section-diag" class="section">
<dl class="diag">
<dt>Engine</dt>
<dd id="engine" class="button simple">-</dd>
<dt>ROM</dt>
<dd id="rom-name">-</dd>
<dt>ROM Size</dt>
<dd><span id="rom-size">-</span> bytes</dd>
<dt>CPU Frequency</dt>
<dd>
<span id="logic-frequency-minus" class="button simple">-</span>
<span id="logic-frequency">-</span> Hz
<span id="logic-frequency-plus" class="button simple">+</span></dd>
<dt>Framerate</dt>
<dd><span id="fps-count">-</span> fps</dd>
</dl>
</div>
<div id="separator-diag" class="separator"></div>
<div class="section"> <div class="section">
<div class="button-area"> <div class="button-area">
<span id="button-pause" class="button simple border padded"> <span id="button-pause" class="button simple border padded">
......
...@@ -422,29 +422,6 @@ class GameboyEmulator extends Observable implements Emulator { ...@@ -422,29 +422,6 @@ class GameboyEmulator extends Observable implements Emulator {
} }
registerButtons() { registerButtons() {
const engine = document.getElementById("engine")!;
engine.addEventListener("click", () => {
const name = this.engine === "neo" ? "classic" : "neo";
this.boot({ engine: name });
this.trigger("message", {
text: `Game Boy running in engine "${name.toUpperCase()}" from now on!`
});
});
const logicFrequencyPlus = document.getElementById(
"logic-frequency-plus"
)!;
logicFrequencyPlus.addEventListener("click", () => {
this.logicFrequency = this.logicFrequency + FREQUENCY_DELTA;
});
const logicFrequencyMinus = document.getElementById(
"logic-frequency-minus"
)!;
logicFrequencyMinus.addEventListener("click", () => {
this.logicFrequency = this.logicFrequency - FREQUENCY_DELTA;
});
const buttonPause = document.getElementById("button-pause")!; const buttonPause = document.getElementById("button-pause")!;
buttonPause.addEventListener("click", () => { buttonPause.addEventListener("click", () => {
this.toggleRunning(); this.toggleRunning();
......
...@@ -146,6 +146,15 @@ export interface Emulator extends ObservableI { ...@@ -146,6 +146,15 @@ export interface Emulator extends ObservableI {
* re-loads the ROM that is currently set in the emulator. * re-loads the ROM that is currently set in the emulator.
*/ */
reset(): void; reset(): void;
/**
* Boot (or reboots) the emulator according to the provided
* set of options.
*
* @param options The options that are going to be used for
* the booting operation of the emulator.
*/
boot(options: any): void;
} }
/** /**
...@@ -299,6 +308,10 @@ export const App: FC<AppProps> = ({ emulator, backgrounds = ["264653"] }) => { ...@@ -299,6 +308,10 @@ export const App: FC<AppProps> = ({ emulator, backgrounds = ["264653"] }) => {
const onThemeClick = () => { const onThemeClick = () => {
setBackgroundIndex((backgroundIndex + 1) % backgrounds.length); setBackgroundIndex((backgroundIndex + 1) % backgrounds.length);
}; };
const onEngineChange = (engine: string) => {
emulator.boot({ engine: engine.toLowerCase() });
showToast(`Game Boy running in engine "${engine}" from now on!`);
};
const onMinimize = () => { const onMinimize = () => {
setFullscreen(!fullscreen); setFullscreen(!fullscreen);
}; };
...@@ -438,6 +451,30 @@ export const App: FC<AppProps> = ({ emulator, backgrounds = ["264653"] }) => { ...@@ -438,6 +451,30 @@ export const App: FC<AppProps> = ({ emulator, backgrounds = ["264653"] }) => {
/> />
</ButtonContainer> </ButtonContainer>
<Info> <Info>
<Pair
key="button-engine"
name={"Engine"}
valueNode={
<ButtonSwitch
options={["NEO", "CLASSIC"]}
size={"large"}
style={["simple"]}
onChange={onEngineChange}
/>
}
/>
<Pair
key="button-frequency"
name={"CPU Frequency"}
valueNode={
<ButtonIncrement
value={200}
delta={100}
min={0}
suffix={"Hz"}
/>
}
/>
<Pair <Pair
key="rom" key="rom"
name={"ROM"} name={"ROM"}
...@@ -462,30 +499,6 @@ export const App: FC<AppProps> = ({ emulator, backgrounds = ["264653"] }) => { ...@@ -462,30 +499,6 @@ export const App: FC<AppProps> = ({ emulator, backgrounds = ["264653"] }) => {
name={"Framerate"} name={"Framerate"}
value={`${framerate} fps`} value={`${framerate} fps`}
/> />
<Pair
key="button-tobias"
name={"Button Increment"}
valueNode={
<ButtonIncrement
value={200}
delta={100}
min={0}
suffix={"Hz"}
/>
}
/>
<Pair
key="button-cpu"
name={"Button Switch"}
valueNode={
<ButtonSwitch
options={["NEO", "CLASSIC"]}
size={"large"}
style={["simple"]}
onChange={(v) => alert(v)}
/>
}
/>
</Info> </Info>
</Section> </Section>
</PanelSplit> </PanelSplit>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment