Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
supersonicAI
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
dmath010
supersonicAI
Commits
adbf1ba1
Commit
adbf1ba1
authored
6 years ago
by
Vicki Pfau
Browse files
Options
Downloads
Patches
Plain Diff
src: Redo Python memory API
parent
097e460a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
retro/data.py
+4
-0
4 additions, 0 deletions
retro/data.py
src/retro.cpp
+23
-25
23 additions, 25 deletions
src/retro.cpp
with
27 additions
and
25 deletions
retro/data.py
+
4
−
0
View file @
adbf1ba1
...
...
@@ -21,6 +21,10 @@ class GameData(GameDataGlue):
variables
=
self
.
list_variables
()
return
name
in
variables
@property
def
memory
(
self
):
return
super
(
GameData
,
self
).
memory
()
def
parse_smd
(
header
,
body
):
import
numpy
as
np
...
...
This diff is collapsed.
Click to expand it.
src/retro.cpp
+
23
−
25
View file @
adbf1ba1
...
...
@@ -110,32 +110,24 @@ struct PyRetroEmulator {
};
struct
PyMemoryView
{
Retro
::
MemoryView
<>
m_mem
;
PyMemoryView
(
py
::
array_t
<
uint8_t
>&
mem
)
{
m_mem
.
open
(
static_cast
<
void
*>
(
mem
.
mutable_data
()),
mem
.
size
());
m_mem
.
clone
();
Retro
::
AddressSpace
&
m_mem
;
PyMemoryView
(
Retro
::
AddressSpace
&
mem
)
:
m_mem
(
mem
)
{
}
int64_t
extract
(
size_t
address
,
const
string
&
type
,
py
::
list
ospec
)
{
MemoryOverlay
overlay
{
ospec
.
is_none
()
?
'='
:
static_cast
<
string
>
(
py
::
str
(
ospec
[
0
]))[
0
],
ospec
.
is_none
()
?
'='
:
static_cast
<
string
>
(
py
::
str
(
ospec
[
1
]))[
0
],
ospec
.
is_none
()
?
1
:
static_cast
<
size_t
>
(
py
::
int_
(
ospec
[
2
])),
};
return
DataType
(
type
)(
m_mem
.
offset
(
0
),
address
,
overlay
);
int64_t
extract
(
size_t
address
,
const
string
&
type
)
{
return
m_mem
[
Variable
{
type
,
address
}];
}
void
assign
(
size_t
address
,
const
string
&
type
,
int64_t
value
,
py
::
list
ospec
)
{
MemoryOverlay
overlay
{
ospec
.
is_none
()
?
'='
:
static_cast
<
string
>
(
py
::
str
(
ospec
[
0
]))[
0
],
ospec
.
is_none
()
?
'='
:
static_cast
<
string
>
(
py
::
str
(
ospec
[
1
]))[
0
],
ospec
.
is_none
()
?
1
:
static_cast
<
size_t
>
(
py
::
int_
(
ospec
[
2
])),
};
DataType
{
type
}(
m_mem
.
offset
(
0
),
address
,
overlay
)
=
value
;
void
assign
(
size_t
address
,
const
string
&
type
,
int64_t
value
)
{
m_mem
[
Variable
{
type
,
address
}]
=
value
;
}
py
::
array_t
<
uint8_t
>
data
()
{
return
py
::
array_t
<
uint8_t
>
(
m_mem
.
size
(),
&
m_mem
[
0
]);
void
setitem
(
py
::
dict
item
,
int64_t
value
)
{
return
assign
(
py
::
int_
(
item
[
"address"
]),
py
::
str
(
item
[
"type"
]),
value
);
}
int64_t
getitem
(
py
::
dict
item
)
{
return
extract
(
py
::
int_
(
item
[
"address"
]),
py
::
str
(
item
[
"type"
]));
}
};
...
...
@@ -233,6 +225,10 @@ struct PyGameData {
bool
isDone
()
const
{
return
m_scen
.
isDone
();
}
PyMemoryView
memory
()
{
return
PyMemoryView
(
m_data
.
addressSpace
());
}
};
void
PyRetroEmulator
::
configureData
(
PyGameData
&
data
)
{
...
...
@@ -320,10 +316,11 @@ PYBIND11_MODULE(_retro, m) {
.
def_static
(
"load_core_info"
,
&
PyRetroEmulator
::
loadCoreInfo
);
py
::
class_
<
PyMemoryView
>
(
m
,
"Memory"
)
.
def
(
py
::
init
<
py
::
array_t
<
uint8_t
>&>
())
.
def
(
"extract"
,
&
PyMemoryView
::
extract
,
py
::
arg
(
"address"
),
py
::
arg
(
"type"
),
py
::
arg
(
"overlay"
)
=
py
::
none
())
.
def
(
"assign"
,
&
PyMemoryView
::
assign
,
py
::
arg
(
"address"
),
py
::
arg
(
"type"
),
py
::
arg
(
"value"
),
py
::
arg
(
"overlay"
)
=
py
::
none
())
.
def
(
"data"
,
&
PyMemoryView
::
data
);
.
def
(
py
::
init
<
Retro
::
AddressSpace
&>
())
.
def
(
"extract"
,
&
PyMemoryView
::
extract
,
py
::
arg
(
"address"
),
py
::
arg
(
"type"
))
.
def
(
"assign"
,
&
PyMemoryView
::
assign
,
py
::
arg
(
"address"
),
py
::
arg
(
"type"
),
py
::
arg
(
"value"
))
.
def
(
"__setitem__"
,
&
PyMemoryView
::
setitem
,
py
::
arg
(
"item"
),
py
::
arg
(
"value"
))
.
def
(
"__getitem__"
,
&
PyMemoryView
::
getitem
,
py
::
arg
(
"item"
));
py
::
class_
<
PyGameData
>
(
m
,
"GameDataGlue"
)
.
def
(
py
::
init
<>
())
...
...
@@ -339,7 +336,8 @@ PYBIND11_MODULE(_retro, m) {
.
def
(
"remove_variable"
,
&
PyGameData
::
removeVariable
)
.
def
(
"list_variables"
,
&
PyGameData
::
listVariables
)
.
def
(
"current_reward"
,
&
PyGameData
::
currentReward
)
.
def
(
"is_done"
,
&
PyGameData
::
isDone
);
.
def
(
"is_done"
,
&
PyGameData
::
isDone
)
.
def
(
"memory"
,
&
PyGameData
::
memory
);
py
::
class_
<
PyMovie
>
(
m
,
"Movie"
)
.
def
(
py
::
init
<
py
::
str
,
bool
>
(),
py
::
arg
(
"path"
),
py
::
arg
(
"record"
)
=
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