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
de242f03
Verified
Commit
de242f03
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: better support for trait
parent
591db06a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#626
passed
2 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/benchmark/src/main.rs
+1
-1
1 addition, 1 deletion
examples/benchmark/src/main.rs
examples/sdl/src/main.rs
+24
-8
24 additions, 8 deletions
examples/sdl/src/main.rs
with
25 additions
and
9 deletions
examples/benchmark/src/main.rs
+
1
−
1
View file @
de242f03
...
@@ -6,7 +6,7 @@ use time::Instant;
...
@@ -6,7 +6,7 @@ use time::Instant;
const
CYCLE_COUNT
:
u64
=
5_000_000_000
;
const
CYCLE_COUNT
:
u64
=
5_000_000_000
;
fn
main
()
{
fn
main
()
{
let
chips
:
Vec
<
Box
<
dyn
Chip8
>
>
=
vec!
[
Box
::
new
(
Chip8Classic
::
new
()),
Box
::
new
(
Chip8Neo
::
new
())];
let
chips
:
[
Box
<
dyn
Chip8
>
;
2
]
=
[
Box
::
new
(
Chip8Classic
::
new
()),
Box
::
new
(
Chip8Neo
::
new
())];
let
rom_path
=
"./resources/pong.ch8"
;
let
rom_path
=
"./resources/pong.ch8"
;
let
rom
=
read_file
(
rom_path
);
let
rom
=
read_file
(
rom_path
);
...
...
This diff is collapsed.
Click to expand it.
examples/sdl/src/main.rs
+
24
−
8
View file @
de242f03
...
@@ -7,7 +7,7 @@ use sdl2::{
...
@@ -7,7 +7,7 @@ use sdl2::{
keyboard
::
Keycode
,
pixels
::
Color
,
pixels
::
PixelFormatEnum
,
rect
::
Rect
,
render
::
TextureQuery
,
keyboard
::
Keycode
,
pixels
::
Color
,
pixels
::
PixelFormatEnum
,
rect
::
Rect
,
render
::
TextureQuery
,
surface
::
Surface
,
ttf
::
Hinting
,
surface
::
Surface
,
ttf
::
Hinting
,
};
};
use
std
::
path
::
Path
;
use
std
::
{
env
::
args
,
path
::
Path
}
;
// handle the annoying Rect i32
// handle the annoying Rect i32
macro_rules!
rect
(
macro_rules!
rect
(
...
@@ -84,7 +84,7 @@ impl BeepCallback {
...
@@ -84,7 +84,7 @@ impl BeepCallback {
}
}
pub
struct
State
{
pub
struct
State
{
system
:
Chip8
Neo
,
system
:
Box
<
dyn
Chip8
>
,
logic_frequency
:
u32
,
logic_frequency
:
u32
,
visual_frequency
:
u32
,
visual_frequency
:
u32
,
idle_frequency
:
u32
,
idle_frequency
:
u32
,
...
@@ -95,7 +95,7 @@ pub struct State {
...
@@ -95,7 +95,7 @@ pub struct State {
beep_ticks
:
u32
,
beep_ticks
:
u32
,
pixel_color
:
[
u8
;
3
],
pixel_color
:
[
u8
;
3
],
diag_color
:
[
u8
;
3
],
diag_color
:
[
u8
;
3
],
pixel_color_index
:
u
32
,
pixel_color_index
:
u
size
,
title
:
String
,
title
:
String
,
rom_name
:
String
,
rom_name
:
String
,
rom_loaded
:
bool
,
rom_loaded
:
bool
,
...
@@ -109,10 +109,26 @@ impl State {
...
@@ -109,10 +109,26 @@ impl State {
}
}
fn
main
()
{
fn
main
()
{
let
system
:
Box
<
dyn
Chip8
>
;
// uses the command line arguments to create the proper
// engine for the processing
let
args
:
Vec
<
String
>
=
args
()
.collect
();
if
args
.len
()
>
1
{
let
engine
=
&
args
[
1
];
match
engine
.as_str
()
{
"neo"
=>
system
=
Box
::
new
(
Chip8Neo
::
new
()),
"classic"
=>
system
=
Box
::
new
(
Chip8Classic
::
new
()),
_
=>
panic!
(
"invalid system engine name '{}'"
,
engine
),
}
}
else
{
system
=
Box
::
new
(
Chip8Neo
::
new
());
}
// builds the CHIP-8 machine, this is the instance that
// builds the CHIP-8 machine, this is the instance that
// 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
:
Chip8Neo
::
new
()
,
system
:
system
,
logic_frequency
:
LOGIC_HZ
,
logic_frequency
:
LOGIC_HZ
,
visual_frequency
:
VISUAL_HZ
,
visual_frequency
:
VISUAL_HZ
,
idle_frequency
:
IDLE_HZ
,
idle_frequency
:
IDLE_HZ
,
...
@@ -250,10 +266,10 @@ fn main() {
...
@@ -250,10 +266,10 @@ fn main() {
keycode
:
Some
(
Keycode
::
P
),
keycode
:
Some
(
Keycode
::
P
),
..
..
}
=>
{
}
=>
{
state
.pixel_color_index
=
(
state
.pixel_color_index
+
1
)
%
COLORS
.len
()
as
u
32
;
state
.pixel_color_index
=
(
state
.pixel_color_index
+
1
)
%
COLORS
.len
()
as
u
size
;
state
.pixel_color
=
COLORS
[
state
.pixel_color_index
as
usize
];
state
.pixel_color
=
COLORS
[
state
.pixel_color_index
];
let
diag_color_index
=
(
state
.pixel_color_index
+
1
)
%
COLORS
.len
()
as
u
32
;
let
diag_color_index
=
(
state
.pixel_color_index
+
1
)
%
COLORS
.len
()
as
u
size
;
state
.diag_color
=
COLORS
[
diag_color_index
as
usize
];
state
.diag_color
=
COLORS
[
diag_color_index
];
None
None
}
}
...
...
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