Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
chip-ahoyto
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
chip-ahoyto
Commits
4b80e173
Verified
Commit
4b80e173
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: support for rom name
parent
1f3be783
No related branches found
No related tags found
No related merge requests found
Pipeline
#605
passed
2 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/sdl/src/main.rs
+13
-5
13 additions, 5 deletions
examples/sdl/src/main.rs
with
13 additions
and
5 deletions
examples/sdl/src/main.rs
+
13
−
5
View file @
4b80e173
...
@@ -84,7 +84,6 @@ impl BeepCallback {
...
@@ -84,7 +84,6 @@ impl BeepCallback {
pub
struct
State
{
pub
struct
State
{
system
:
Chip8
,
system
:
Chip8
,
rom_loaded
:
bool
,
logic_frequency
:
u32
,
logic_frequency
:
u32
,
visual_frequency
:
u32
,
visual_frequency
:
u32
,
idle_frequency
:
u32
,
idle_frequency
:
u32
,
...
@@ -96,6 +95,8 @@ pub struct State {
...
@@ -96,6 +95,8 @@ pub struct State {
pixel_color
:
[
u8
;
3
],
pixel_color
:
[
u8
;
3
],
pixel_color_index
:
u32
,
pixel_color_index
:
u32
,
title
:
String
,
title
:
String
,
rom_name
:
String
,
rom_loaded
:
bool
,
diagnostics
:
bool
,
diagnostics
:
bool
,
}
}
...
@@ -110,7 +111,6 @@ fn main() {
...
@@ -110,7 +111,6 @@ fn main() {
// is going to logically represent the CHIP-8
// is going to logically represent the CHIP-8
let
mut
state
=
State
{
let
mut
state
=
State
{
system
:
Chip8
::
new
(),
system
:
Chip8
::
new
(),
rom_loaded
:
false
,
logic_frequency
:
LOGIC_HZ
,
logic_frequency
:
LOGIC_HZ
,
visual_frequency
:
VISUAL_HZ
,
visual_frequency
:
VISUAL_HZ
,
idle_frequency
:
IDLE_HZ
,
idle_frequency
:
IDLE_HZ
,
...
@@ -122,6 +122,8 @@ fn main() {
...
@@ -122,6 +122,8 @@ fn main() {
pixel_color
:
COLORS
[
0
],
pixel_color
:
COLORS
[
0
],
pixel_color_index
:
0
,
pixel_color_index
:
0
,
title
:
String
::
from
(
TITLE_INITIAL
),
title
:
String
::
from
(
TITLE_INITIAL
),
rom_name
:
String
::
from
(
"unloaded"
),
rom_loaded
:
false
,
diagnostics
:
false
,
diagnostics
:
false
,
};
};
...
@@ -204,6 +206,10 @@ fn main() {
...
@@ -204,6 +206,10 @@ fn main() {
.unwrap
();
.unwrap
();
'main
:
loop
{
'main
:
loop
{
if
state
.timer_frequency
<
state
.visual_frequency
{
panic!
(
"timer frequency must be higher or equal to visual frequency"
)
}
while
let
Some
(
event
)
=
event_pump
.poll_event
()
{
while
let
Some
(
event
)
=
event_pump
.poll_event
()
{
match
event
{
match
event
{
Event
::
Quit
{
..
}
=>
break
'main
,
Event
::
Quit
{
..
}
=>
break
'main
,
...
@@ -256,14 +262,15 @@ fn main() {
...
@@ -256,14 +262,15 @@ fn main() {
Event
::
DropFile
{
filename
,
..
}
=>
{
Event
::
DropFile
{
filename
,
..
}
=>
{
let
rom
=
read_file
(
&
filename
);
let
rom
=
read_file
(
&
filename
);
let
filebas
e
=
Path
::
new
(
&
filename
)
.file_name
()
.unwrap
()
.to_str
()
.unwrap
();
let
rom_nam
e
=
Path
::
new
(
&
filename
)
.file_name
()
.unwrap
()
.to_str
()
.unwrap
();
state
.system
.reset_hard
();
state
.system
.reset_hard
();
state
.system
.load_rom
(
&
rom
);
state
.system
.load_rom
(
&
rom
);
state
.rom_name
=
String
::
from
(
rom_name
);
state
.rom_loaded
=
true
;
state
.rom_loaded
=
true
;
state
.set_title
(
&
format!
(
"{} [Currently playing: {}]"
,
TITLE
,
filebas
e
));
state
.set_title
(
&
format!
(
"{} [Currently playing: {}]"
,
TITLE
,
rom_nam
e
));
None
None
}
}
...
@@ -373,7 +380,8 @@ fn main() {
...
@@ -373,7 +380,8 @@ fn main() {
let
mut
y
=
12
;
let
mut
y
=
12
;
let
padding
=
2
;
let
padding
=
2
;
let
text
=
format!
(
let
text
=
format!
(
"Frequency: {} Hz
\n
Display: {} fps
\n
PC: 0x{:04x}
\n
SP: 0x{:04x}"
,
"ROM: {}
\n
Frequency: {} Hz
\n
Display: {} fps
\n
PC: 0x{:04x}
\n
SP: 0x{:04x}"
,
state
.rom_name
,
state
.logic_frequency
,
state
.logic_frequency
,
state
.visual_frequency
,
state
.visual_frequency
,
state
.system
.pc
(),
state
.system
.pc
(),
...
...
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