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
7e1db05f
Verified
Commit
7e1db05f
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: more instructions
parent
30e2a631
No related branches found
No related tags found
No related merge requests found
Pipeline
#858
passed
2 years ago
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/sdl/src/main.rs
+2
-1
2 additions, 1 deletion
examples/sdl/src/main.rs
src/gb.rs
+1
-1
1 addition, 1 deletion
src/gb.rs
src/inst.rs
+32
-2
32 additions, 2 deletions
src/inst.rs
with
35 additions
and
4 deletions
examples/sdl/src/main.rs
+
2
−
1
View file @
7e1db05f
...
...
@@ -81,7 +81,8 @@ fn main() {
let
mut
game_boy
=
GameBoy
::
new
();
game_boy
.load_boot_dmg
();
//game_boy.load_rom_file("../../res/roms/firstwhite.gb");
game_boy
.load_rom_file
(
"../../res/roms/opus5.gb"
);
//game_boy.load_rom_file("../../res/roms/opus5.gb");
game_boy
.load_rom_file
(
"../../res/roms/ld_r_r.gb"
);
let
mut
counter
=
0
;
...
...
This diff is collapsed.
Click to expand it.
src/gb.rs
+
1
−
1
View file @
7e1db05f
use
crate
::{
cpu
::
Cpu
,
data
::{
SGB
_BOOT
,
DMG
_BOOT
},
data
::{
DMG
_BOOT
,
SGB
_BOOT
},
mmu
::
Mmu
,
ppu
::{
Ppu
,
FRAME_BUFFER_SIZE
},
util
::
read_file
,
...
...
This diff is collapsed.
Click to expand it.
src/inst.rs
+
32
−
2
View file @
7e1db05f
...
...
@@ -214,13 +214,13 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(
push_bc
,
16
,
"PUSH BC"
),
(
add_a_u8
,
8
,
"ADD A, u8"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
noimpl
,
4
,
"
! UNIMP !
"
),
(
ret_z
,
8
,
"
RET Z
"
),
(
ret
,
16
,
"RET"
),
(
jp_z_u16
,
12
,
"JP Z, u16"
),
(
noimpl
,
4
,
"! UNIMP !"
),
(
call_z_u16
,
12
,
"CALL Z, u16"
),
(
call_u16
,
24
,
"CALL u16"
),
(
noimpl
,
4
,
"
! UNIMP !
"
),
(
adc_a_u8
,
8
,
"
ADC A, u8
"
),
(
rst_08h
,
16
,
"RST 08h"
),
// 0xd opcodes
(
ret_nc
,
8
,
"RET NC"
),
...
...
@@ -1206,6 +1206,15 @@ fn add_a_u8(cpu: &mut Cpu) {
cpu
.a
=
add_set_flags
(
cpu
,
cpu
.a
,
byte
);
}
fn
ret_z
(
cpu
:
&
mut
Cpu
)
{
if
!
cpu
.get_zero
()
{
return
;
}
cpu
.pc
=
cpu
.pop_word
();
cpu
.ticks
=
cpu
.ticks
.wrapping_add
(
12
);
}
fn
ret
(
cpu
:
&
mut
Cpu
)
{
cpu
.pc
=
cpu
.pop_word
();
}
...
...
@@ -1239,6 +1248,11 @@ fn call_u16(cpu: &mut Cpu) {
cpu
.pc
=
word
;
}
fn
adc_a_u8
(
cpu
:
&
mut
Cpu
)
{
let
byte
=
cpu
.read_u8
();
cpu
.a
=
add_carry_set_flags
(
cpu
,
cpu
.a
,
byte
);
}
fn
rst_08h
(
cpu
:
&
mut
Cpu
)
{
rst
(
cpu
,
0x0008
);
}
...
...
@@ -1499,6 +1513,22 @@ fn add_set_flags(cpu: &mut Cpu, first: u8, second: u8) -> u8 {
result_b
}
fn
add_carry_set_flags
(
cpu
:
&
mut
Cpu
,
first
:
u8
,
second
:
u8
)
->
u8
{
let
first
=
first
as
u32
;
let
second
=
second
as
u32
;
let
carry
=
cpu
.get_carry
()
as
u32
;
let
result
=
first
.wrapping_add
(
second
)
.wrapping_add
(
carry
);
let
result_b
=
result
as
u8
;
cpu
.set_sub
(
false
);
cpu
.set_zero
(
result_b
==
0
);
cpu
.set_half_carry
((
first
^
second
^
result
)
&
0x10
==
0x10
);
cpu
.set_carry
(
result
&
0x100
==
0x100
);
result_b
}
fn
sub_set_flags
(
cpu
:
&
mut
Cpu
,
first
:
u8
,
second
:
u8
)
->
u8
{
let
first
=
first
as
u32
;
let
second
=
second
as
u32
;
...
...
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