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
Merge requests
!36
Support for Python
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Support for Python
joamag/python
into
master
Overview
0
Commits
42
Pipelines
37
Changes
1
Merged
João Magalhães
requested to merge
joamag/python
into
master
1 year ago
Overview
0
Commits
42
Pipelines
37
Changes
1
Expand
Related to
#36
1
0
1
1
Merge request reports
Viewing commit
a96ddf4e
Prev
Next
Show latest version
1 file
+
2
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Verified
a96ddf4e
chore: simple refactor
· a96ddf4e
João Magalhães
authored
1 year ago
src/py.rs
0 → 100644
+
131
−
0
Options
use
pyo3
::{
prelude
::
*
,
types
::
PyBytes
};
use
crate
::{
gb
::{
GameBoy
as
GameBoyBase
,
GameBoyMode
},
info
::
Info
,
ppu
::{
PaletteInfo
,
DISPLAY_HEIGHT
,
DISPLAY_WIDTH
},
};
#[pyclass]
struct
GameBoy
{
system
:
GameBoyBase
,
}
#[pymethods]
impl
GameBoy
{
#[new]
fn
new
(
mode
:
u8
)
->
Self
{
Self
{
system
:
GameBoyBase
::
new
(
Some
(
GameBoyMode
::
from_u8
(
mode
))),
}
}
pub
fn
reset
(
&
mut
self
)
{
self
.system
.reset
();
}
pub
fn
boot
(
&
mut
self
)
{
self
.system
.boot
();
}
pub
fn
load
(
&
mut
self
,
boot
:
bool
)
{
self
.system
.load
(
boot
);
}
pub
fn
load_rom
(
&
mut
self
,
data
:
&
[
u8
])
{
self
.system
.load_rom
(
data
,
None
);
}
pub
fn
load_rom_file
(
&
mut
self
,
path
:
&
str
)
{
self
.system
.load_rom_file
(
path
,
None
);
}
pub
fn
clock
(
&
mut
self
)
->
u16
{
self
.system
.clock
()
}
pub
fn
clock_m
(
&
mut
self
,
count
:
usize
)
->
u16
{
self
.system
.clock_m
(
count
)
}
pub
fn
clocks
(
&
mut
self
,
count
:
usize
)
->
u64
{
self
.system
.clocks
(
count
)
}
pub
fn
next_frame
(
&
mut
self
)
->
u32
{
self
.system
.next_frame
()
}
pub
fn
frame_buffer
(
&
mut
self
,
py
:
Python
)
->
PyObject
{
let
pybytes
=
PyBytes
::
new
(
py
,
self
.system
.frame_buffer
());
pybytes
.into
()
}
pub
fn
set_palette_colors
(
&
mut
self
,
colors_hex
:
&
str
)
{
let
palette
=
PaletteInfo
::
from_colors_hex
(
"default"
,
colors_hex
);
self
.system
.ppu
()
.set_palette_colors
(
palette
.colors
());
}
pub
fn
ppu_enabled
(
&
self
)
->
bool
{
self
.system
.ppu_enabled
()
}
pub
fn
set_ppu_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.system
.set_ppu_enabled
(
value
);
}
pub
fn
apu_enabled
(
&
self
)
->
bool
{
self
.system
.apu_enabled
()
}
pub
fn
set_apu_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.system
.set_apu_enabled
(
value
);
}
pub
fn
dma_enabled
(
&
self
)
->
bool
{
self
.system
.dma_enabled
()
}
pub
fn
set_dma_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.system
.set_dma_enabled
(
value
);
}
pub
fn
timer_enabled
(
&
self
)
->
bool
{
self
.system
.timer_enabled
()
}
pub
fn
set_timer_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.system
.set_timer_enabled
(
value
);
}
pub
fn
serial_enabled
(
&
self
)
->
bool
{
self
.system
.serial_enabled
()
}
pub
fn
set_serial_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.system
.set_serial_enabled
(
value
);
}
pub
fn
rom_title
(
&
self
)
->
String
{
self
.system
.rom_i
()
.title
()
}
pub
fn
version
(
&
self
)
->
String
{
Info
::
version
()
}
pub
fn
clock_freq_s
(
&
self
)
->
String
{
self
.system
.clock_freq_s
()
}
}
#[pymodule]
fn
boytacean
(
_py
:
Python
,
module
:
&
PyModule
)
->
PyResult
<
()
>
{
module
.add_class
::
<
GameBoy
>
()
?
;
module
.add
(
"DISPLAY_WIDTH"
,
DISPLAY_WIDTH
)
?
;
module
.add
(
"DISPLAY_HEIGHT"
,
DISPLAY_HEIGHT
)
?
;
module
.add
(
"CPU_FREQ"
,
GameBoyBase
::
CPU_FREQ
)
?
;
module
.add
(
"VISUAL_FREQ"
,
GameBoyBase
::
VISUAL_FREQ
)
?
;
module
.add
(
"LCD_CYCLES"
,
GameBoyBase
::
LCD_CYCLES
)
?
;
Ok
(())
}
Loading