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
28bf8179
Verified
Commit
28bf8179
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: new instructions
parent
593a20cb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/sdl/src/main.rs
+3
-0
3 additions, 0 deletions
examples/sdl/src/main.rs
src/cpu.rs
+72
-2
72 additions, 2 deletions
src/cpu.rs
src/gb.rs
+4
-0
4 additions, 0 deletions
src/gb.rs
with
79 additions
and
2 deletions
examples/sdl/src/main.rs
+
3
−
0
View file @
28bf8179
...
...
@@ -6,5 +6,8 @@ fn main() {
for
_
in
0
..
40000
{
game_boy
.clock
();
if
game_boy
.cpu
()
.pc
()
>=
0x0016
{
break
;
}
}
}
This diff is collapsed.
Click to expand it.
src/cpu.rs
+
72
−
2
View file @
28bf8179
...
...
@@ -2,7 +2,7 @@ use crate::mmu::Mmu;
pub
const
PREFIX
:
u8
=
0xcb
;
pub
const
INSTRUCTIONS
:
[(
fn
(
&
mut
Cpu
),
u8
,
&
'static
str
);
2
08
]
=
[
pub
const
INSTRUCTIONS
:
[(
fn
(
&
mut
Cpu
),
u8
,
&
'static
str
);
2
56
]
=
[
// 0x0 opcodes
(
nop
,
4
,
"NOP"
),
(
ld_bc_u16
,
12
,
"LD BC, u16"
),
...
...
@@ -16,7 +16,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 208] = [
(
add_hl_bc
,
8
,
"ADD HL, BC"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"
NOP
"
),
(
inc_c
,
4
,
"
INC C
"
),
(
nop
,
4
,
"NOP"
),
(
ld_c_u8
,
8
,
"LD C, u8"
),
(
nop
,
4
,
"NOP"
),
...
...
@@ -224,6 +224,57 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 208] = [
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
// 0xd opcodes
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
// 0xe opcodes
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
ld_mff00c_a
,
8
,
"LD [FF00+C], A"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
// 0xf opcodes
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
(
nop
,
4
,
"NOP"
),
];
pub
const
BITWISE
:
[(
fn
(
&
mut
Cpu
),
u8
,
&
'static
str
);
176
]
=
[
...
...
@@ -486,6 +537,11 @@ impl Cpu {
&
mut
self
.mmu
}
#[inline(always)]
pub
fn
pc
(
&
self
)
->
u16
{
self
.pc
}
#[inline(always)]
fn
af
(
&
self
)
->
u16
{
(
self
.a
as
u16
)
<<
8
|
self
.f
()
as
u16
...
...
@@ -660,6 +716,16 @@ fn add_hl_bc(cpu: &mut Cpu) {
cpu
.set_hl
(
value
);
}
fn
inc_c
(
cpu
:
&
mut
Cpu
)
{
let
value
=
cpu
.c
.wrapping_add
(
1
);
cpu
.set_sub
(
false
);
cpu
.set_zero
(
value
==
0
);
cpu
.set_half_carry
((
value
&
0xf
)
==
0xf
);
cpu
.c
=
value
;
}
fn
ld_c_u8
(
cpu
:
&
mut
Cpu
)
{
let
byte
=
cpu
.read_u8
();
cpu
.c
=
byte
;
...
...
@@ -704,6 +770,10 @@ fn xor_a_a(cpu: &mut Cpu) {
cpu
.set_carry
(
false
);
}
fn
ld_mff00c_a
(
cpu
:
&
mut
Cpu
)
{
cpu
.mmu
.write
((
0xff0c
+
cpu
.c
as
u16
),
cpu
.a
);
}
fn
bit_7_h
(
cpu
:
&
mut
Cpu
)
{
bit_h
(
cpu
,
7
);
}
...
...
This diff is collapsed.
Click to expand it.
src/gb.rs
+
4
−
0
View file @
28bf8179
...
...
@@ -20,6 +20,10 @@ impl GameBoy {
self
.cpu
.clock
()
}
pub
fn
cpu
(
&
self
)
->
&
Cpu
{
&
self
.cpu
}
pub
fn
load_boot
(
&
mut
self
,
path
:
&
str
)
{
let
data
=
read_file
(
path
);
self
.cpu
.mmu
()
.write_buffer
(
0x0000
,
&
data
);
...
...
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