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
669e7565
Verified
Commit
669e7565
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: better structure of instruction execution
parent
eaf6e9b2
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
+1
-1
1 addition, 1 deletion
examples/sdl/src/main.rs
src/cpu.rs
+27
-8
27 additions, 8 deletions
src/cpu.rs
src/mmu.rs
+1
-1
1 addition, 1 deletion
src/mmu.rs
with
29 additions
and
10 deletions
examples/sdl/src/main.rs
+
1
−
1
View file @
669e7565
...
@@ -79,7 +79,7 @@ fn main() {
...
@@ -79,7 +79,7 @@ fn main() {
let
mut
counter
=
0
;
let
mut
counter
=
0
;
'main
:
loop
{
'main
:
loop
{
if
counter
>=
7000000
{
if
counter
>=
7000000
00
{
break
;
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/cpu.rs
+
27
−
8
View file @
669e7565
...
@@ -26,7 +26,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
...
@@ -26,7 +26,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
inc_de
,
8
,
"INC DE"
),
(
inc_de
,
8
,
"INC DE"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !
"
),
(
dec_d
,
4
,
"DEC D
"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
rla
,
4
,
"RLA"
),
(
rla
,
4
,
"RLA"
),
(
jr_i8
,
12
,
"JR i8"
),
(
jr_i8
,
12
,
"JR i8"
),
...
@@ -157,7 +157,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
...
@@ -157,7 +157,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
// 0x9 opcodes
// 0x9 opcodes
(
noimpl
,
4
,
"! UNIMP !
"
),
(
sub_a_b
,
4
,
"SUB A, B
"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"! UNIMP !"
),
...
@@ -527,10 +527,16 @@ impl Cpu {
...
@@ -527,10 +527,16 @@ impl Cpu {
let
(
instruction_fn
,
instruction_time
,
instruction_str
)
=
instruction
;
let
(
instruction_fn
,
instruction_time
,
instruction_str
)
=
instruction
;
println!
(
if
*
instruction_str
==
"! UNIMP !"
{
"{}
\t
(0x{:02x})
\t
${:04x} {}"
,
println!
(
instruction_str
,
opcode
,
pc
,
is_prefix
"{}
\t
(0x{:02x})
\t
${:04x} {}"
,
);
instruction_str
,
opcode
,
pc
,
is_prefix
);
}
if
pc
==
0x0080
{
println!
(
"GOING TO PLAY BOOT SOUND"
);
}
instruction_fn
(
self
);
instruction_fn
(
self
);
self
.ticks
=
self
.ticks
.wrapping_add
(
*
instruction_time
as
u32
);
self
.ticks
=
self
.ticks
.wrapping_add
(
*
instruction_time
as
u32
);
...
@@ -802,6 +808,16 @@ fn inc_de(cpu: &mut Cpu) {
...
@@ -802,6 +808,16 @@ fn inc_de(cpu: &mut Cpu) {
cpu
.set_de
(
cpu
.de
()
.wrapping_add
(
1
));
cpu
.set_de
(
cpu
.de
()
.wrapping_add
(
1
));
}
}
fn
dec_d
(
cpu
:
&
mut
Cpu
)
{
let
value
=
cpu
.d
.wrapping_sub
(
1
);
cpu
.set_sub
(
true
);
cpu
.set_zero
(
value
==
0
);
cpu
.set_half_carry
((
value
&
0xf
)
==
0xf
);
cpu
.d
=
value
;
}
fn
rla
(
cpu
:
&
mut
Cpu
)
{
fn
rla
(
cpu
:
&
mut
Cpu
)
{
let
carry
=
cpu
.get_carry
();
let
carry
=
cpu
.get_carry
();
...
@@ -942,6 +958,10 @@ fn ld_a_h(cpu: &mut Cpu) {
...
@@ -942,6 +958,10 @@ fn ld_a_h(cpu: &mut Cpu) {
cpu
.a
=
cpu
.h
;
cpu
.a
=
cpu
.h
;
}
}
fn
sub_a_b
(
cpu
:
&
mut
Cpu
)
{
cpu
.a
=
sub_set_flags
(
cpu
,
cpu
.a
,
cpu
.b
);
}
fn
xor_a_a
(
cpu
:
&
mut
Cpu
)
{
fn
xor_a_a
(
cpu
:
&
mut
Cpu
)
{
cpu
.a
^=
cpu
.a
;
cpu
.a
^=
cpu
.a
;
...
@@ -1041,12 +1061,11 @@ fn bit_h(cpu: &mut Cpu, bit: u8) {
...
@@ -1041,12 +1061,11 @@ fn bit_h(cpu: &mut Cpu, bit: u8) {
}
}
fn
sub_set_flags
(
cpu
:
&
mut
Cpu
,
x
:
u8
,
y
:
u8
)
->
u8
{
fn
sub_set_flags
(
cpu
:
&
mut
Cpu
,
x
:
u8
,
y
:
u8
)
->
u8
{
//
C
heck for borrow using 32bit arithmetics
//
c
heck
s
for borrow using 32bit arithmetics
let
x
=
x
as
u32
;
let
x
=
x
as
u32
;
let
y
=
y
as
u32
;
let
y
=
y
as
u32
;
let
value
=
x
.wrapping_sub
(
y
);
let
value
=
x
.wrapping_sub
(
y
);
let
value_b
=
value
as
u8
;
let
value_b
=
value
as
u8
;
cpu
.set_sub
(
true
);
cpu
.set_sub
(
true
);
...
...
This diff is collapsed.
Click to expand it.
src/mmu.rs
+
1
−
1
View file @
669e7565
...
@@ -148,7 +148,7 @@ impl Mmu {
...
@@ -148,7 +148,7 @@ impl Mmu {
self
.ppu
.write
(
addr
,
value
);
self
.ppu
.write
(
addr
,
value
);
}
}
_
=>
{
_
=>
{
println!
(
"Writing to
U
nknown IO control 0x{:04x}"
,
addr
);
println!
(
"Writing to
u
nknown IO control 0x{:04x}"
,
addr
);
}
}
}
}
}
}
...
...
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