Skip to content

Commit 6c0c574

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
Fixed gfx_SetCharData for NULL inputs (issue #619). Also added an extra example for gfx_SetCharData
1 parent 428b1a3 commit 6c0c574

File tree

3 files changed

+64
-31
lines changed

3 files changed

+64
-31
lines changed

examples/library_examples/graphx/text_custom/autotest.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
"key|enter",
1717
"hashWait|2",
1818
"key|enter",
19-
"hashWait|3"
19+
"hashWait|3",
20+
"key|enter",
21+
"hashWait|4",
22+
"key|enter",
23+
"hashWait|5"
2024
],
2125
"hashes":
2226
{
@@ -25,16 +29,30 @@
2529
"description": "Test custom font display",
2630
"start": "vram_start",
2731
"size": "vram_8_size",
28-
"expected_CRCs": [ "F717BF65" ]
32+
"expected_CRCs": [ "711E0ED5" ]
2933
},
3034
"2":
3135
{
32-
"description": "Test hidden font display",
36+
"description": "Before: ***",
3337
"start": "vram_start",
3438
"size": "vram_8_size",
35-
"expected_CRCs": [ "EDA09A59" ]
39+
"expected_CRCs": [ "1BD16129" ]
3640
},
3741
"3":
42+
{
43+
"description": "After: ***",
44+
"start": "vram_start",
45+
"size": "vram_8_size",
46+
"expected_CRCs": [ "B090D407" ]
47+
},
48+
"4":
49+
{
50+
"description": "Test hidden font display",
51+
"start": "vram_start",
52+
"size": "vram_8_size",
53+
"expected_CRCs": [ "0170C971" ]
54+
},
55+
"5":
3856
{
3957
"description": "Test program exit",
4058
"start": "vram_start",

examples/library_examples/graphx/text_custom/src/main.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ static unsigned char font8x8_spacing[128];
99

1010
int main(void)
1111
{
12-
int i;
13-
1412
/* Initialize graphics drawing */
1513
gfx_Begin();
1614

@@ -24,15 +22,30 @@ int main(void)
2422
/* Waits for a key */
2523
while (!os_GetCSC());
2624

25+
PrintCentered("Before: ***");
26+
27+
/* Waits for a key */
28+
while (!os_GetCSC());
29+
30+
/* Get a pointer to the character data for '*' by passing in NULL */
31+
unsigned char *char_ptr = gfx_SetCharData('*', NULL);
32+
33+
/* Invert the pixels of '*' */
34+
for (int i = 0; i < 8; i++) {
35+
char_ptr[i] = ~char_ptr[i];
36+
}
37+
38+
PrintCentered("After: ***");
39+
40+
/* Waits for a key */
41+
while (!os_GetCSC());
42+
2743
/* Change the font by shifting each character up 1 */
28-
for (i = 127; i > 0; --i)
44+
for (int i = 127; i > 0; --i)
2945
{
3046
gfx_SetCharData(i, &font8x8[(i - 1) * 8]);
3147
}
3248

33-
/* Clear old string */
34-
gfx_FillScreen(255);
35-
3649
/* Print with the changed font */
3750
PrintCentered("Uijt!tusjoh!xbt!ijeefo\"");
3851

@@ -48,9 +61,12 @@ int main(void)
4861
/* Prints a screen centered string */
4962
void PrintCentered(const char *str)
5063
{
51-
gfx_PrintStringXY(str,
52-
(GFX_LCD_WIDTH - gfx_GetStringWidth(str)) / 2,
53-
(GFX_LCD_HEIGHT - 8) / 2);
64+
/* Clear old string */
65+
gfx_FillScreen(255);
66+
67+
int x_center = (GFX_LCD_WIDTH - gfx_GetStringWidth(str)) / 2;
68+
int y_center = (GFX_LCD_HEIGHT - 8) / 2;
69+
gfx_PrintStringXY(str, x_center, y_center);
5470
}
5571

5672
static unsigned char font8x8_spacing[128] =
@@ -181,7 +197,7 @@ static unsigned char font8x8[128 * 8] =
181197
0x00, 0x00, 0x00, 0x7e, 0x46, 0x62, 0x62, 0x7e, // Char 111 (o)
182198
0x00, 0x00, 0x00, 0x7e, 0x46, 0x42, 0x7e, 0x60, // Char 112 (p)
183199
0x60, 0x00, 0x00, 0x7e, 0x46, 0x42, 0x7e, 0x02, // Char 113 (q)
184-
0x02, 0x00, 0x00, 0x7e, 0x46, 0x60, 0x60, 0x60, // Char 114 (r)
200+
0x00, 0x00, 0x00, 0x7e, 0x46, 0x60, 0x60, 0x60, // Char 114 (r)
185201
0x00, 0x00, 0x00, 0x7c, 0x40, 0x7c, 0x04, 0x7c, // Char 115 (s)
186202
0x00, 0x10, 0x10, 0x3c, 0x10, 0x10, 0x18, 0x1c, // Char 116 (t)
187203
0x00, 0x00, 0x00, 0x46, 0x46, 0x62, 0x62, 0x7e, // Char 117 (u)

src/graphx/graphx.asm

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4018,25 +4018,24 @@ gfx_SetCharData:
40184018
; arg0 : Pointer to character data; if null returns current data
40194019
; Returns:
40204020
; Pointer to character data if null, otherwise pointer to next character
4021-
ld iy,0
4022-
add iy,sp
4023-
ld hl,(iy+6) ; de -> custom character data
4024-
add hl,de
4025-
or a,a
4026-
sbc hl,de ; sets z flag if null
4021+
ld iy, 0
4022+
add iy, sp
4023+
sbc hl, hl ; ld hl, 0
4024+
ld de, (iy + 6) ; de -> custom_character_data
4025+
sbc hl, de ; sets z flag if NULL
4026+
add hl, de
4027+
ld l, (iy + 3) ; hl = index
4028+
add hl, hl
4029+
add hl, hl
4030+
add hl, hl
4031+
ld bc, (_TextData)
4032+
add hl, bc
4033+
; returns _TextData + (index * 8) if custom_character_data is NULL
40274034
ret z
4028-
ex de,hl
4029-
or a,a
4030-
sbc hl,hl
4031-
ld l,(iy+3) ; hl = index
4032-
add hl,hl
4033-
add hl,hl
4034-
add hl,hl
4035-
ld bc,(_TextData)
4036-
add hl,bc
4037-
ex de,hl
4038-
ld bc,8
4035+
ld bc, 8
4036+
ex de, hl
40394037
ldir
4038+
; returns custom_character_data + 8
40404039
ret
40414040

40424041
;-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)