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
43d663fd
Verified
Commit
43d663fd
authored
7 months ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: more abstract write operations
parent
f188cabc
No related branches found
No related tags found
1 merge request
!59
`StateComponent` creation and implementation
Pipeline
#5068
failed
6 months ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
crates/common/src/data.rs
+19
-1
19 additions, 1 deletion
crates/common/src/data.rs
src/timer.rs
+11
-11
11 additions, 11 deletions
src/timer.rs
with
30 additions
and
12 deletions
crates/common/src/data.rs
+
19
−
1
View file @
43d663fd
use
std
::{
io
::{
Cursor
,
Read
},
io
::{
Cursor
,
Read
,
Write
},
mem
::
size_of
,
};
use
crate
::
error
::
Error
;
#[inline(always)]
pub
fn
write_u8
(
data
:
&
mut
Cursor
<
Vec
<
u8
>>
,
value
:
u8
)
->
Result
<
(),
Error
>
{
data
.write_all
(
&
value
.to_le_bytes
())
?
;
Ok
(())
}
#[inline(always)]
pub
fn
write_u16
(
data
:
&
mut
Cursor
<
Vec
<
u8
>>
,
value
:
u16
)
->
Result
<
(),
Error
>
{
data
.write_all
(
&
value
.to_le_bytes
())
?
;
Ok
(())
}
#[inline(always)]
pub
fn
write_u32
(
data
:
&
mut
Cursor
<
Vec
<
u8
>>
,
value
:
u32
)
->
Result
<
(),
Error
>
{
data
.write_all
(
&
value
.to_le_bytes
())
?
;
Ok
(())
}
#[inline(always)]
pub
fn
read_u8
(
data
:
&
mut
Cursor
<&
[
u8
]
>
)
->
Result
<
u8
,
Error
>
{
let
mut
buffer
=
[
0x00
;
size_of
::
<
u8
>
()];
...
...
This diff is collapsed.
Click to expand it.
src/timer.rs
+
11
−
11
View file @
43d663fd
//! Timer functions and structures.
use
std
::
io
::
{
Cursor
,
Write
}
;
use
std
::
io
::
Cursor
;
use
boytacean_common
::{
data
::{
read_u16
,
read_u8
},
data
::{
read_u16
,
read_u8
,
write_u16
,
write_u8
},
error
::
Error
,
};
...
...
@@ -173,15 +173,15 @@ impl BusComponent for Timer {
impl
StateComponent
for
Timer
{
fn
state
(
&
self
)
->
Result
<
Vec
<
u8
>
,
Error
>
{
let
mut
cursor
=
Cursor
::
new
(
vec!
[]);
cursor
.write
(
&
self
.div
.to_le_bytes
()
)
?
;
cursor
.write
(
&
self
.tima
.to_le_bytes
()
)
?
;
cursor
.write
(
&
self
.tma
.to_le_bytes
()
)
?
;
cursor
.write
(
&
self
.tac
.to_le_bytes
()
)
?
;
cursor
.write
(
&
self
.div_clock
.to_le_bytes
()
)
?
;
cursor
.write
(
&
self
.tima_clock
.to_le_bytes
()
)
?
;
cursor
.write
(
&
(
self
.tima_enabled
as
u8
)
.to_le_bytes
())
?
;
cursor
.write
(
&
self
.tima_ratio
.to_le_bytes
()
)
?
;
cursor
.write
(
&
(
self
.int_tima
as
u8
)
.to_le_bytes
())
?
;
write_u8
(
&
mut
cursor
,
self
.div
)
?
;
write_u8
(
&
mut
cursor
,
self
.tima
)
?
;
write_u8
(
&
mut
cursor
,
self
.tma
)
?
;
write_u8
(
&
mut
cursor
,
self
.tac
)
?
;
write_u16
(
&
mut
cursor
,
self
.div_clock
)
?
;
write_u16
(
&
mut
cursor
,
self
.tima_clock
)
?
;
write_u8
(
&
mut
cursor
,
self
.tima_enabled
as
u8
)
?
;
write_u16
(
&
mut
cursor
,
self
.tima_ratio
)
?
;
write_u8
(
&
mut
cursor
,
self
.int_tima
as
u8
)
?
;
Ok
(
cursor
.into_inner
())
}
...
...
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