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
d2c32c9d
Verified
Commit
d2c32c9d
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: added joypad int
parent
74b14bc6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Window drawing support 🪟
Pipeline
#979
passed
2 years ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cpu.rs
+21
-0
21 additions, 0 deletions
src/cpu.rs
src/mmu.rs
+4
-1
4 additions, 1 deletion
src/mmu.rs
src/pad.rs
+30
-12
30 additions, 12 deletions
src/pad.rs
with
55 additions
and
13 deletions
src/cpu.rs
+
21
−
0
View file @
d2c32c9d
...
...
@@ -90,6 +90,7 @@ impl Cpu {
if
((
self
.mmu.ie
&
0x01
==
0x01
)
&&
self
.mmu
.ppu
()
.int_vblank
())
||
((
self
.mmu.ie
&
0x02
==
0x02
)
&&
self
.mmu
.ppu
()
.int_stat
())
||
((
self
.mmu.ie
&
0x04
==
0x04
)
&&
self
.mmu
.timer
()
.int_tima
())
||
((
self
.mmu.ie
&
0x10
==
0x10
)
&&
self
.mmu
.pad
()
.int_pad
())
{
self
.halted
=
false
;
}
...
...
@@ -154,6 +155,26 @@ impl Cpu {
self
.halted
=
false
;
}
return
20
;
}
// @todo aggregate the handling of these interrupts
else
if
(
self
.mmu.ie
&
0x10
==
0x10
)
&&
self
.mmu
.pad
()
.int_pad
()
{
debugln!
(
"Going to run JoyPad interrupt handler (0x60)"
);
self
.disable_int
();
self
.push_word
(
pc
);
self
.pc
=
0x60
;
// acknowledges that the pad interrupt has been
// properly handled
self
.mmu
.pad
()
.ack_pad
();
// in case the CPU is currently halted waiting
// for an interrupt, releases it
if
self
.halted
{
self
.halted
=
false
;
}
return
20
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/mmu.rs
+
4
−
1
View file @
d2c32c9d
...
...
@@ -110,7 +110,9 @@ impl Mmu {
0xf00
=>
match
addr
&
0x00ff
{
0x0f
=>
{
let
value
=
if
self
.ppu
.int_vblank
()
{
0x01
}
else
{
0x00
}
|
if
self
.timer
.int_tima
()
{
0x04
}
else
{
0x00
};
|
if
self
.ppu
.int_stat
()
{
0x02
}
else
{
0x00
}
|
if
self
.timer
.int_tima
()
{
0x04
}
else
{
0x00
}
|
if
self
.pad
.int_pad
()
{
0x10
}
else
{
0x00
};
value
}
0x80
..=
0xfe
=>
self
.ppu.hram
[(
addr
&
0x007f
)
as
usize
],
...
...
@@ -181,6 +183,7 @@ impl Mmu {
self
.ppu
.set_int_vblank
(
value
&
0x01
==
0x01
);
self
.ppu
.set_int_stat
(
value
&
0x02
==
0x02
);
self
.timer
.set_int_tima
(
value
&
0x04
==
0x04
);
self
.pad
.set_int_pad
(
value
&
0x10
==
0x10
);
}
0x80
..=
0xfe
=>
self
.ppu.hram
[(
addr
&
0x007f
)
as
usize
]
=
value
,
0xff
=>
self
.ie
=
value
,
...
...
This diff is collapsed.
Click to expand it.
src/pad.rs
+
30
−
12
View file @
d2c32c9d
#[cfg(feature
=
"wasm"
)]
use
wasm_bindgen
::
prelude
::
*
;
pub
struct
Pad
{
down
:
bool
,
up
:
bool
,
left
:
bool
,
right
:
bool
,
start
:
bool
,
select
:
bool
,
b
:
bool
,
a
:
bool
,
selection
:
PadSelection
,
}
#[derive(Clone,
Copy,
PartialEq)]
pub
enum
PadSelection
{
Action
,
...
...
@@ -31,6 +19,19 @@ pub enum PadKey {
B
,
}
pub
struct
Pad
{
down
:
bool
,
up
:
bool
,
left
:
bool
,
right
:
bool
,
start
:
bool
,
select
:
bool
,
b
:
bool
,
a
:
bool
,
selection
:
PadSelection
,
int_pad
:
bool
}
impl
Pad
{
pub
fn
new
()
->
Self
{
Self
{
...
...
@@ -43,6 +44,7 @@ impl Pad {
b
:
false
,
a
:
false
,
selection
:
PadSelection
::
Action
,
int_pad
:
false
,
}
}
...
...
@@ -103,6 +105,10 @@ impl Pad {
PadKey
::
A
=>
self
.a
=
true
,
PadKey
::
B
=>
self
.b
=
true
,
}
// signals that a JoyPad interrupt is pending to be
// handled as a key pressed has been done
self
.int_pad
=
true
;
}
pub
fn
key_lift
(
&
mut
self
,
key
:
PadKey
)
{
...
...
@@ -117,4 +123,16 @@ impl Pad {
PadKey
::
B
=>
self
.b
=
false
,
}
}
pub
fn
int_pad
(
&
self
)
->
bool
{
self
.int_pad
}
pub
fn
set_int_pad
(
&
mut
self
,
value
:
bool
)
{
self
.int_pad
=
value
;
}
pub
fn
ack_pad
(
&
mut
self
)
{
self
.set_int_pad
(
false
);
}
}
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