Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rust-card10
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Astro
rust-card10
Commits
a0d9692d
Commit
a0d9692d
authored
5 years ago
by
Astro
Browse files
Options
Downloads
Patches
Plain Diff
add support for selecting fonts
parent
f6a86600
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
card10-l0dable/src/display.rs
+34
-0
34 additions, 0 deletions
card10-l0dable/src/display.rs
card10-l0dable/src/lib.rs
+1
-1
1 addition, 1 deletion
card10-l0dable/src/lib.rs
rkanoid/src/main.rs
+4
-4
4 additions, 4 deletions
rkanoid/src/main.rs
with
39 additions
and
5 deletions
card10-l0dable/src/display.rs
+
34
−
0
View file @
a0d9692d
...
@@ -75,6 +75,15 @@ pub enum FillStyle {
...
@@ -75,6 +75,15 @@ pub enum FillStyle {
pub
struct
Display
;
pub
struct
Display
;
#[repr(u8)]
pub
enum
Font
{
Font8
=
disp_font_name_DISP_FONT8
as
u8
,
Font12
=
disp_font_name_DISP_FONT12
as
u8
,
Font16
=
disp_font_name_DISP_FONT16
as
u8
,
Font20
=
disp_font_name_DISP_FONT20
as
u8
,
Font24
=
disp_font_name_DISP_FONT24
as
u8
,
}
impl
Display
{
impl
Display
{
pub
const
W
:
u16
=
160
;
pub
const
W
:
u16
=
160
;
pub
const
H
:
u16
=
80
;
pub
const
H
:
u16
=
80
;
...
@@ -107,6 +116,13 @@ impl Display {
...
@@ -107,6 +116,13 @@ impl Display {
}
}
}
}
/// s must be 0-terminated
pub
fn
print_adv
(
&
self
,
font
:
Font
,
x
:
u16
,
y
:
u16
,
s
:
&
[
u8
],
fg
:
Color
,
bg
:
Color
)
{
unsafe
{
epic_disp_print_adv
(
font
as
u8
,
x
,
y
,
s
.as_ptr
(),
fg
.0
,
bg
.0
);
}
}
pub
fn
pixel
(
&
self
,
x
:
u16
,
y
:
u16
,
color
:
Color
)
{
pub
fn
pixel
(
&
self
,
x
:
u16
,
y
:
u16
,
color
:
Color
)
{
unsafe
{
unsafe
{
epic_disp_pixel
(
x
,
y
,
color
.0
);
epic_disp_pixel
(
x
,
y
,
color
.0
);
...
@@ -186,3 +202,21 @@ macro_rules! display {
...
@@ -186,3 +202,21 @@ macro_rules! display {
$disp
.print
(
$x
,
$y
,
s
.as_bytes
(),
$fg
,
$bg
);
$disp
.print
(
$x
,
$y
,
s
.as_bytes
(),
$fg
,
$bg
);
});
});
}
}
/// Requires `card10_alloc::init()` and `extern crate alloc;`
#[macro_export]
macro_rules!
display_adv
{
(
$disp
:
expr
,
$font
:
tt
,
$x
:
expr
,
$y
:
expr
,
$fg
:
expr
,
$bg
:
expr
,
$fmt
:
expr
)
=>
({
use
alloc
::
format
;
use
card10_l0dable
::
Font
;
let
s
=
format!
(
concat!
(
$fmt
,
"
\0
"
));
$disp
.print_adv
(
Font
::
$font
,
$x
,
$y
,
s
.as_bytes
(),
$fg
,
$bg
);
});
(
$disp
:
expr
,
$font
:
tt
,
$x
:
expr
,
$y
:
expr
,
$fg
:
expr
,
$bg
:
expr
,
$fmt
:
expr
,
$
(
$arg
:
tt
)
*
)
=>
({
use
alloc
::
format
;
let
s
=
format!
(
concat!
(
$fmt
,
"
\0
"
),
$
(
$arg
)
*
);
$disp
.print_adv
(
Font
::
$font
,
$x
,
$y
,
s
.as_bytes
(),
$fg
,
$bg
);
});
}
This diff is collapsed.
Click to expand it.
card10-l0dable/src/lib.rs
+
1
−
1
View file @
a0d9692d
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
mod
os
;
mod
os
;
pub
use
os
::
*
;
pub
use
os
::
*
;
mod
display
;
mod
display
;
pub
use
display
::{
Color
,
Display
,
FillStyle
,
LineStyle
};
pub
use
display
::{
Color
,
Display
,
Font
,
FillStyle
,
LineStyle
};
mod
buttons
;
mod
buttons
;
pub
mod
framebuffer
;
pub
mod
framebuffer
;
pub
use
buttons
::
Buttons
;
pub
use
buttons
::
Buttons
;
...
...
This diff is collapsed.
Click to expand it.
rkanoid/src/main.rs
+
4
−
4
View file @
a0d9692d
...
@@ -292,10 +292,10 @@ fn game(level: u16, mut score: u32) -> GameResult {
...
@@ -292,10 +292,10 @@ fn game(level: u16, mut score: u32) -> GameResult {
fn
title_screen
()
{
fn
title_screen
()
{
let
display
=
Display
::
open
();
let
display
=
Display
::
open
();
display
.clear
(
Color
::
red
());
display
.clear
(
Color
::
red
());
display!
(
display
,
3
0
,
1
5
,
Color
::
white
(),
Color
::
red
(),
"Rkanoid"
);
display
_adv
!
(
display
,
Font24
,
Display
::
W
/
2
-
6
0
,
1
4
,
Color
::
white
(),
Color
::
red
(),
"Rkanoid"
);
display!
(
display
,
30
,
3
0
,
Color
::
white
(),
Color
::
red
(),
"in Rust"
);
display
_adv
!
(
display
,
Font20
,
Display
::
W
/
2
-
49
,
4
0
,
Color
::
white
(),
Color
::
red
(),
"in Rust"
);
display!
(
display
,
20
,
45
,
Color
::
white
(),
Color
::
red
(),
"by Astro"
);
display
_adv
!
(
display
,
Font16
,
Display
::
W
/
2
-
44
,
64
,
Color
::
white
(),
Color
::
red
(),
"by Astro"
);
display!
(
display
,
Display
::
W
-
2
*
Display
::
FONT_W
,
Display
::
H
-
Display
::
FONT_H
,
Color
::
yellow
(),
Color
::
blue
(),
"Go"
);
display!
(
display
,
Display
::
W
-
2
*
Display
::
FONT_W
,
Display
::
H
-
Display
::
FONT_H
+
3
,
Color
::
yellow
(),
Color
::
blue
(),
"Go"
);
display
.update
();
display
.update
();
while
!
Buttons
::
read
()
.right_bottom
()
{}
while
!
Buttons
::
read
()
.right_bottom
()
{}
}
}
...
...
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