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
72303cfa
Verified
Commit
72303cfa
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: initial implementation of chip8 neo
parent
d2b66e9c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Working version of the neo implementation 🥳
Pipeline
#608
passed
2 years ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/benchmark/src/main.rs
+5
-2
5 additions, 2 deletions
examples/benchmark/src/main.rs
examples/sdl/src/main.rs
+4
-3
4 additions, 3 deletions
examples/sdl/src/main.rs
src/chip8_neo.rs
+65
-5
65 additions, 5 deletions
src/chip8_neo.rs
with
74 additions
and
10 deletions
examples/benchmark/src/main.rs
+
5
−
2
View file @
72303cfa
...
...
@@ -18,7 +18,7 @@ fn benchmark_chip8() {
println!
(
"[Chip8] Running {} cycles for {}"
,
cycles
,
rom_path
);
for
_
in
0
..
CYCLE_COUNT
{
chip8
.
ti
ck
();
chip8
.
clo
ck
();
}
let
duration_s
=
instant
.elapsed
()
.as_seconds_f32
();
...
...
@@ -33,8 +33,11 @@ fn benchmark_chip8() {
fn
benchmark_chip8_neo
()
{
let
rom_path
=
"./resources/pong.ch8"
;
let
rom
=
read_file
(
rom_path
);
let
mut
chip8
=
Chip8Neo
::
new
();
chip8
.reset_hard
();
chip8
.load_rom
(
&
rom
);
let
instant
=
Instant
::
now
();
...
...
@@ -43,7 +46,7 @@ fn benchmark_chip8_neo() {
println!
(
"[Chip8Neo] Running {} cycles for {}"
,
cycles
,
rom_path
);
for
_
in
0
..
CYCLE_COUNT
{
chip8
.
ti
ck
();
chip8
.
clo
ck
();
}
let
duration_s
=
instant
.elapsed
()
.as_seconds_f32
();
...
...
This diff is collapsed.
Click to expand it.
examples/sdl/src/main.rs
+
4
−
3
View file @
72303cfa
use
chip_ahoyto
::{
chip8
::
Chip8
,
chip8
::
SCREEN_PIXEL_HEIGHT
,
chip8
::
SCREEN_PIXEL_WIDTH
,
util
::
read_file
,
chip8
::
Chip8
,
chip8
::
SCREEN_PIXEL_HEIGHT
,
chip8
::
SCREEN_PIXEL_WIDTH
,
chip8_neo
::
Chip8Neo
,
util
::
read_file
,
};
use
sdl2
::{
audio
::
AudioCallback
,
audio
::
AudioSpecDesired
,
event
::
Event
,
image
::
LoadSurface
,
...
...
@@ -83,7 +84,7 @@ impl BeepCallback {
}
pub
struct
State
{
system
:
Chip8
,
system
:
Chip8
Neo
,
logic_frequency
:
u32
,
visual_frequency
:
u32
,
idle_frequency
:
u32
,
...
...
@@ -110,7 +111,7 @@ fn main() {
// builds the CHIP-8 machine, this is the instance that
// is going to logically represent the CHIP-8
let
mut
state
=
State
{
system
:
Chip8
::
new
(),
system
:
Chip8
Neo
::
new
(),
logic_frequency
:
LOGIC_HZ
,
visual_frequency
:
VISUAL_HZ
,
idle_frequency
:
IDLE_HZ
,
...
...
This diff is collapsed.
Click to expand it.
src/chip8_neo.rs
+
65
−
5
View file @
72303cfa
...
...
@@ -58,7 +58,28 @@ impl Chip8Neo {
chip8
}
pub
fn
tick
(
&
mut
self
)
{
pub
fn
reset
(
&
mut
self
)
{
self
.vram
=
[
0u8
;
DISPLAY_WIDTH
*
DISPLAY_HEIGHT
];
self
.stack
=
[
0u16
;
STACK_SIZE
];
self
.registers
=
[
0u8
;
REGISTERS_SIZE
];
self
.pc
=
ROM_START
as
u16
;
self
.i
=
0x0
;
self
.sp
=
0x0
;
self
.dt
=
0x0
;
self
.st
=
0x0
;
self
.load_default_font
();
}
pub
fn
reset_hard
(
&
mut
self
)
{
self
.ram
=
[
0u8
;
RAM_SIZE
];
self
.reset
();
}
pub
fn
pixels
(
&
self
)
->
Vec
<
u8
>
{
self
.vram
.to_vec
()
}
pub
fn
clock
(
&
mut
self
)
{
// fetches the current instruction and increments
// the PC (program counter) accordingly
let
instruction
=
...
...
@@ -67,7 +88,9 @@ impl Chip8Neo {
let
opcode
=
instruction
&
0xf000
;
let
address
=
instruction
&
0x0fff
;
let
nibble
=
((
instruction
&
0x0f00
)
>>
8
)
as
u8
;
let
first_nibble
=
((
instruction
&
0x0f00
)
>>
8
)
as
u8
;
let
second_nibble
=
((
instruction
&
0x00f0
)
>>
4
)
as
u8
;
let
third_nibble
=
(
instruction
&
0x000f
)
as
u8
;
let
byte
=
(
instruction
&
0x00ff
)
as
u8
;
match
opcode
{
...
...
@@ -76,17 +99,54 @@ impl Chip8Neo {
_
=>
println!
(
"unimplemented instruction"
),
},
0x1000
=>
self
.pc
=
address
,
0x6000
=>
{
self
.registers
[
nibble
as
usize
]
=
byte
;
0x6000
=>
self
.registers
[
first_nibble
as
usize
]
=
byte
,
0x7000
=>
self
.registers
[
first_nibble
as
usize
]
+=
byte
,
0xa000
=>
self
.i
=
address
,
0xd000
=>
{
let
mut
x
=
self
.registers
[
first_nibble
as
usize
];
let
mut
y
=
self
.registers
[
second_nibble
as
usize
];
let
mut
offset
=
0
;
for
i
in
0
..
third_nibble
{
y
=
(
y
+
i
)
%
DISPLAY_HEIGHT
as
u8
;
for
j
in
0
..
8
{
x
=
(
x
+
j
)
%
DISPLAY_WIDTH
as
u8
;
let
pixel
=
self
.ram
[(
self
.i
+
offset
)
as
usize
];
self
.vram
[(
y
*
DISPLAY_WIDTH
as
u8
+
x
)
as
usize
]
=
pixel
;
offset
+=
1
;
}
}
}
_
=>
println!
(
"unimplemented instruction"
),
_
=>
println!
(
"unimplemented opcode {}, instruction {}"
,
opcode
,
instruction
),
}
}
pub
fn
clock_dt
(
&
mut
self
)
{}
pub
fn
clock_st
(
&
mut
self
)
{}
pub
fn
key_press
(
&
mut
self
,
key
:
u8
)
{}
pub
fn
key_lift
(
&
mut
self
,
key
:
u8
)
{}
pub
fn
load_rom
(
&
mut
self
,
rom
:
&
[
u8
])
{
self
.ram
[
ROM_START
..
ROM_START
+
rom
.len
()]
.clone_from_slice
(
&
rom
);
}
pub
fn
beep
(
&
self
)
->
bool
{
false
}
pub
fn
pc
(
&
self
)
->
u16
{
self
.pc
}
pub
fn
sp
(
&
self
)
->
u8
{
self
.sp
}
fn
load_font
(
&
mut
self
,
position
:
usize
,
font_set
:
&
[
u8
])
{
self
.ram
[
position
..
position
+
font_set
.len
()]
.clone_from_slice
(
&
font_set
);
}
...
...
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