Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
retro8
Commits
e5868b96
Commit
e5868b96
authored
Dec 22, 2019
by
Jack
Browse files
added implementation for printing special Pico-8 glyphs
parent
ebc6f970
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/vm/gfx.h
View file @
e5868b96
...
...
@@ -194,6 +194,7 @@ namespace retro8
public:
Font
()
{
}
inline
const
sequential_sprite_t
*
glyph
(
char
c
)
const
{
return
c
<
128
?
&
glyphs
[
c
]
:
nullptr
;
}
inline
const
sequential_sprite_t
*
specialGlyph
(
size_t
i
)
const
{
return
&
glyphs
[
128
+
i
];
}
void
load
(
SDL_Surface
*
surface
);
};
...
...
src/vm/machine.cpp
View file @
e5868b96
...
...
@@ -267,21 +267,57 @@ void Machine::sspr(coord_t sx, coord_t sy, coord_t sw, coord_t sh, coord_t dx, c
// TODO: add support for strange characters like symbols
void
Machine
::
print
(
const
std
::
string
&
string
,
coord_t
x
,
coord_t
y
,
color_t
color
)
{
for
(
const
auto
c
:
string
)
struct
SpecialGlyph
{
const
auto
sprite
=
_font
.
glyph
(
c
);
std
::
vector
<
uint8_t
>
encoding
;
size_t
index
;
};
static
const
std
::
array
<
SpecialGlyph
,
6
>
SpecialGlyphs
=
{
{
{
{
0xe2
,
0xac
,
0x87
,
0xef
,
0xb8
,
0x8f
},
3
},
// down arrow
{
{
0xe2
,
0xac
,
0x86
,
0xef
,
0xb8
,
0x8f
},
20
},
// up arrow
{
{
0xe2
,
0xac
,
0x85
,
0xef
,
0xb8
,
0x8f
},
11
},
// left arrow
{
{
0xe2
,
0x9e
,
0xa1
,
0xef
,
0xb8
,
0x8f
},
17
},
// right arrow
{
{
0xf0
,
0x9f
,
0x85
,
0xbe
,
0xef
,
0xb8
,
0x8f
},
14
},
// o button
{
{
0xe2
,
0x9d
,
0x8e
},
23
},
// x button
}
};
static
const
std
::
array
<
uint8_t
,
2
>
Prefixes
=
{
0xe2
,
0xf0
};
for
(
size_t
i
=
0
;
i
<
string
.
length
();
++
i
)
{
auto
c
=
string
[
i
];
const
bool
isSpecial
=
std
::
find
(
Prefixes
.
begin
(),
Prefixes
.
end
(),
c
)
!=
Prefixes
.
end
();
auto
specialGlyph
=
std
::
find_if
(
SpecialGlyphs
.
begin
(),
SpecialGlyphs
.
end
(),
[
&
string
,
&
i
](
const
SpecialGlyph
&
glyph
)
{
return
string
.
size
()
>
i
+
glyph
.
encoding
.
size
()
&&
memcmp
(
&
string
[
i
],
&
glyph
.
encoding
[
0
],
glyph
.
encoding
.
size
())
==
0
;
//TODO: memcpy is not best design ever
});
const
gfx
::
sequential_sprite_t
*
sprite
=
nullptr
;
coord_t
width
=
gfx
::
GLYPH_WIDTH
;
if
(
specialGlyph
!=
SpecialGlyphs
.
end
())
{
sprite
=
_font
.
specialGlyph
(
specialGlyph
->
index
);
width
=
8
;
i
+=
specialGlyph
->
encoding
.
size
()
-
1
;
}
else
sprite
=
_font
.
glyph
(
c
);
if
(
sprite
)
{
for
(
coord_t
ty
=
0
;
ty
<
gfx
::
GLYPH_HEIGHT
;
++
ty
)
for
(
coord_t
tx
=
0
;
tx
<
gfx
::
GLYPH_WIDTH
;
++
tx
)
for
(
coord_t
tx
=
0
;
tx
<
width
;
++
tx
)
{
color_t
fcolor
=
sprite
->
get
(
tx
,
ty
);
if
(
fcolor
!=
0
)
pset
(
x
+
tx
,
y
+
ty
,
color
);
}
x
+=
4
;
x
+=
width
;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment