Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
boytacean
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
boytacean
Commits
6ffd97ce
Verified
Commit
6ffd97ce
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: added frame event trigger
parent
0563c1a5
No related branches found
No related tags found
1 merge request
!9
Version 0.4.0 🍾
Pipeline
#1366
passed
2 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/web/index.ts
+3
-2
3 additions, 2 deletions
examples/web/index.ts
examples/web/react/app.tsx
+28
-3
28 additions, 3 deletions
examples/web/react/app.tsx
with
31 additions
and
5 deletions
examples/web/index.ts
+
3
−
2
View file @
6ffd97ce
import
{
Emulator
,
PixelFormat
,
startApp
}
from
"
./react/app
"
;
import
{
Emulator
,
Observable
,
PixelFormat
,
startApp
}
from
"
./react/app
"
;
import
{
default
as
_wasm
,
GameBoy
,
PadKey
,
PpuMode
}
from
"
./lib/boytacean.js
"
;
import
info
from
"
./package.json
"
;
...
...
@@ -48,7 +48,7 @@ const ROM_PATH = require("../../res/roms/20y.gb");
* and "joins" all the elements together to bring input/output
* of the associated machine.
*/
class
GameboyEmulator
implements
Emulator
{
class
GameboyEmulator
extends
Observable
implements
Emulator
{
/**
* The Game Boy engine (probably coming from WASM) that
* is going to be used for the emulation.
...
...
@@ -218,6 +218,7 @@ class GameboyEmulator implements Emulator {
this
.
gameBoy
!
.
frame_buffer_eager
(),
PixelFormat
.
RGB
);
this
.
trigger
(
"
frame
"
);
lastFrame
=
this
.
gameBoy
!
.
ppu_frame
();
}
}
...
...
This diff is collapsed.
Click to expand it.
examples/web/react/app.tsx
+
28
−
3
View file @
6ffd97ce
...
...
@@ -22,12 +22,36 @@ import {
import
"
./app.css
"
;
export
type
Callback
<
T
>
=
(
owner
:
T
)
=>
void
;
/**
* Abstract class that implements the basic functionality
* part of the definition of the observable pattern.
*
* @see {@link https://en.wikipedia.org/wiki/Observer_pattern}
*/
export
class
Observable
{
private
events
:
Record
<
string
,
[
Callback
<
this
>
]
>
=
{};
bind
(
event
:
string
,
callback
:
Callback
<
this
>
)
{
const
callbacks
=
this
.
events
[
event
]
??
[];
if
(
callbacks
.
includes
(
callback
))
return
;
callbacks
.
push
(
callback
);
this
.
events
[
event
]
=
callbacks
;
}
trigger
(
event
:
string
)
{
const
callbacks
=
this
.
events
[
event
]
??
[];
callbacks
.
forEach
((
c
)
=>
c
(
this
));
}
}
/**
* Top level interface that declares the main abstract
* interface of an emulator structured entity.
* Should allow typical hardware operations to be performed.
*/
export
interface
Emulator
{
export
interface
Emulator
extends
Observable
{
getName
():
string
;
getVersion
():
string
;
getVersionUrl
():
string
;
...
...
@@ -80,9 +104,10 @@ export const App: FC<AppProps> = ({ emulator, backgrounds = ["264653"] }) => {
};
const
onDrawHandler
=
(
handler
:
DrawHandler
)
=>
{
if
(
intervalRef
.
current
)
return
;
intervalRef
.
current
=
setInterval
(()
=>
{
intervalRef
.
current
=
1
;
emulator
.
bind
(
"
frame
"
,
()
=>
{
handler
(
emulator
.
getImageBuffer
(),
PixelFormat
.
RGB
);
}
,
1000
);
});
};
useEffect
(()
=>
{
document
.
body
.
style
.
backgroundColor
=
`#
${
getBackground
()}
`
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment