Skip to content

Commit

Permalink
Change frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
choffmann committed Jan 2, 2024
1 parent 0843abd commit b0dfce9
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 33 deletions.
45 changes: 26 additions & 19 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gameboy-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"rsw": "rsw"
},
"dependencies": {
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@fontsource/roboto": "^5.0.8",
"@mui/icons-material": "^5.15.2",
"@mui/material": "^5.15.2",
Expand Down
36 changes: 31 additions & 5 deletions gameboy-web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {useEffect, useState} from "react";
import init, {load_boot_rom, CPU} from "gameboy-wasm";
import init, {CPU} from "gameboy-wasm";
import {Box, CircularProgress, Container} from "@mui/material";
import ControlCenter from "./components/ControlCenter.tsx";


function App() {
Expand All @@ -9,17 +11,41 @@ function App() {
init().then(() => setReady(true))
}, [])

const handleButton = () => {
const handlePlay = () => {
const cpu = new CPU();
const cpuAsJson = cpu.to_json();
const memory = cpuAsJson.memory;
const register = cpuAsJson.register;
console.log("CPU", cpuAsJson)
console.log("Registers", register)
console.log("Memory", memory)
}

const LoadingCircle = () => {
return (
<Box sx={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)"
}}>
<CircularProgress/>
</Box>
)
}

const OnReady = () => {
return (
<>
<ControlCenter onPlay={handlePlay}/>
</>
)
}

return (
<button disabled={!ready} onClick={() => handleButton()}>
Run
</button>
<Container>
{ready ? <OnReady/> : <LoadingCircle/>}
</Container>
)
}

Expand Down
27 changes: 27 additions & 0 deletions gameboy-web/src/components/ControlCenter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {ToggleButton, ToggleButtonGroup} from "@mui/material";
import {BugReport, PlayArrow, SkipNext} from "@mui/icons-material";

export interface ControlCenterProps {
onPlay: () => void
}

const ControlCenter = (props: ControlCenterProps) => {
return (
<>
<ToggleButtonGroup
>
<ToggleButton value="play" onClick={() => props.onPlay()}>
<PlayArrow/>
</ToggleButton>
<ToggleButton value="debug">
<BugReport/>
</ToggleButton>
<ToggleButton value="next" disabled>
<SkipNext/>
</ToggleButton>
</ToggleButtonGroup>
</>
)
}

export default ControlCenter
4 changes: 0 additions & 4 deletions gameboy-web/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
Expand Down
Loading

0 comments on commit b0dfce9

Please sign in to comment.