2023-02-02 23:18:04 -06:00
|
|
|
import React, { useCallback, useEffect, useRef } from 'react'
|
|
|
|
|
import { WasmCPU, Display } from '../pkg/vweb.js'
|
2023-02-01 20:31:06 -06:00
|
|
|
|
|
|
|
|
export default function({}) {
|
|
|
|
|
const canvas = useRef(null)
|
2023-02-02 23:18:04 -06:00
|
|
|
const cpu = useRef(new WasmCPU())
|
|
|
|
|
const ctx = useRef(null)
|
|
|
|
|
const display = useRef(null)
|
|
|
|
|
const request = useRef(null)
|
|
|
|
|
|
2023-02-02 23:55:42 -06:00
|
|
|
const blah = useRef(0)
|
|
|
|
|
|
2023-02-02 23:18:04 -06:00
|
|
|
const drawFrame = useCallback(() => {
|
2023-02-02 23:55:42 -06:00
|
|
|
for(let n = 0; n < 160 * 120; n++) {
|
|
|
|
|
cpu.current.poke(0x10000 + n, Math.random() * 256)
|
|
|
|
|
}
|
2023-02-02 23:18:04 -06:00
|
|
|
display.current.draw(cpu.current, ctx.current)
|
|
|
|
|
request.current = requestAnimationFrame(drawFrame)
|
|
|
|
|
}, [])
|
2023-02-01 20:31:06 -06:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-02-02 23:55:42 -06:00
|
|
|
cpu.current.poke(16 + 0, 3)
|
|
|
|
|
cpu.current.poke24(16 + 10, 160) // Set the virtual h / w
|
|
|
|
|
cpu.current.poke24(16 + 13, 120)
|
2023-02-02 23:18:04 -06:00
|
|
|
ctx.current = canvas.current.getContext('2d')
|
|
|
|
|
display.current = new Display()
|
|
|
|
|
request.current = requestAnimationFrame(drawFrame)
|
|
|
|
|
return () => cancelAnimationFrame(request.current)
|
2023-02-01 20:31:06 -06:00
|
|
|
}, [canvas.current])
|
2023-02-02 23:18:04 -06:00
|
|
|
|
2023-02-01 20:31:06 -06:00
|
|
|
return (
|
|
|
|
|
<canvas ref={canvas} width={640} height={480}></canvas>
|
|
|
|
|
)
|
|
|
|
|
}
|