commit 426c0aa63f980650c1cd27c578881d648bee084f
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Jan 7 14:59:37 2023 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Jan 7 14:59:37 2023 -0700
WIP- basics of custom font working
starting on refactor to replace sprite based font drawing
---
source/fontdata.h | 278 +++++++++++++++++++++++++++++++++++++++++++++-
source/graphics.cpp | 16 ++-
source/graphics.h | 2 +
source/printHelper.cpp | 37 +++++-
test/fontdatatests.cpp | 91 ++++++++++++++-
test/graphicstests.cpp | 10 +-
test/printHelperTests.cpp | 38 ++++++-
7 files changed, 460 insertions(+), 12 deletions(-)
diff --git a/source/fontdata.h b/source/fontdata.h
index a6f7f1a..39f7b5f 100644
--- a/source/fontdata.h
+++ b/source/fontdata.h
@@ -2,4 +2,280 @@
#include <string>
-std::string get_font_data();
\ No newline at end of file
+std::string get_font_data();
+
+const uint8_t defaultFontBinaryData[2048] = {
+// char 0 -- info about how to render font
+4, //0x5600 character width in pixels (can be more than 8, but only 8 pixels are drawn)
+8, //0x5601 character width for character 128 and above
+5, //0x5602 character height in pixels
+0, //0x5603 draw offset x
+0, //0x5604 draw offset y
+0, //0x5605 flags: 0x1 apply_size_adjustments 0x2: apply tabs relative to cursor home
+1, //0x5606 tab width in pixels (used only when alt font is drawn)
+0, //0x5607 unused
+
+//chars 1-15
+//The remaining 120 bytes are used to adjust the width and vertical offset of characters 16..255.
+//Each nibble (low nibbles first) describes the adjustments for one characters:
+//
+//bits 0x7: adjust character width by 0,1,2,3,-4,-3,-2,-1
+//bit 0x8: when set, draw the character one pixel higher (useful for latin accents)
+0, 0, 0, 0, 0, 0, 0, 0, // char 1
+0, 0, 0, 0, 0, 0, 0, 0, // char 2
+0, 0, 0, 0, 0, 0, 0, 0, // char 3
+0, 0, 0, 0, 0, 0, 0, 0, // char 4
+0, 0, 0, 0, 0, 0, 0, 0, // char 5
+0, 0, 0, 0, 0, 0, 0, 0, // char 6
+0, 0, 0, 0, 0, 0, 0, 0, // char 7
+0, 0, 0, 0, 0, 0, 0, 0, // char 8
+0, 0, 0, 0, 0, 0, 0, 0, // char 9
+0, 0, 0, 0, 0, 0, 0, 0, // char 10
+0, 0, 0, 0, 0, 0, 0, 0, // char 11
+0, 0, 0, 0, 0, 0, 0, 0, // char 12
+0, 0, 0, 0, 0, 0, 0, 0, // char 13
+0, 0, 0, 0, 0, 0, 0, 0, // char 14
+0, 0, 0, 0, 0, 0, 0, 0, // char 15
+
+//actual font data for chars 16-127 (each byte is a horizontal line)
+7, 7, 7, 7, 7, 0, 0, 0, // char 16
+0, 7, 7, 7, 0, 0, 0, 0, // char 17
+0, 7, 5, 7, 0, 0, 0, 0, // char 18
+0, 5, 2, 5, 0, 0, 0, 0, // char 19
+0, 5, 0, 5, 0, 0, 0, 0, // char 20
+0, 5, 5, 5, 0, 0, 0, 0, // char 21
+4, 6, 7, 6, 4, 0, 0, 0, // char 22
+1, 3, 7, 3, 1, 0, 0, 0, // char 23
+7, 1, 1, 1, 0, 0, 0, 0, // char 24
+0, 4, 4, 4, 7, 0, 0, 0, // char 25
+5, 7, 2, 7, 2, 0, 0, 0, // char 26
+0, 0, 2, 0, 0, 0, 0, 0, // char 27
+0, 0, 0, 1, 2, 0, 0, 0, // char 28
+0, 0, 0, 3, 3, 0, 0, 0, // char 29
+5, 5, 0, 0, 0, 0, 0, 0, // char 30
+2, 5, 2, 0, 0, 0, 0, 0, // char 31
+0, 0, 0, 0, 0, 0, 0, 0, // char 32
+2, 2, 2, 0, 2, 0, 0, 0, // char 33
+5, 5, 0, 0, 0, 0, 0, 0, // char 34
+5, 7, 5, 7, 5, 0, 0, 0, // char 35
+7, 3, 6, 7, 2, 0, 0, 0, // char 36
+5, 4, 2, 1, 5, 0, 0, 0, // char 37
+3, 3, 3, 5, 7, 0, 0, 0, // char 38
+2, 1, 0, 0, 0, 0, 0, 0, // char 39
+2, 1, 1, 1, 2, 0, 0, 0, // char 40
+2, 4, 4, 4, 2, 0, 0, 0, // char 41
+5, 2, 7, 2, 5, 0, 0, 0, // char 42
+0, 2, 7, 2, 0, 0, 0, 0, // char 43
+0, 0, 0, 2, 1, 0, 0, 0, // char 44
+0, 0, 7, 0, 0, 0, 0, 0, // char 45
+0, 0, 0, 0, 2, 0, 0, 0, // char 46
+4, 2, 2, 2, 1, 0, 0, 0, // char 47
+7, 5, 5, 5, 7, 0, 0, 0, // char 48
+3, 2, 2, 2, 7, 0, 0, 0, // char 49
+7, 4, 7, 1, 7, 0, 0, 0, // char 50
+7, 4, 6, 4, 7, 0, 0, 0, // char 51
+5, 5, 7, 4, 4, 0, 0, 0, // char 52
+7, 1, 7, 4, 7, 0, 0, 0, // char 53
+1, 1, 7, 5, 7, 0, 0, 0, // char 54
+7, 4, 4, 4, 4, 0, 0, 0, // char 55
+7, 5, 7, 5, 7, 0, 0, 0, // char 56
+7, 5, 7, 4, 4, 0, 0, 0, // char 57
+0, 2, 0, 2, 0, 0, 0, 0, // char 58
+0, 2, 0, 2, 1, 0, 0, 0, // char 59
+4, 2, 1, 2, 4, 0, 0, 0, // char 60
+0, 7, 0, 7, 0, 0, 0, 0, // char 61
+1, 2, 4, 2, 1, 0, 0, 0, // char 62
+7, 4, 6, 0, 2, 0, 0, 0, // char 63
+2, 5, 5, 1, 6, 0, 0, 0, // char 64
+0, 7, 5, 7, 5, 0, 0, 0, // char 65
+0, 3, 3, 5, 7, 0, 0, 0, // char 66
+0, 7, 1, 1, 7, 0, 0, 0, // char 67
+0, 3, 5, 5, 3, 0, 0, 0, // char 68
+0, 7, 3, 1, 7, 0, 0, 0, // char 69
+0, 7, 3, 1, 1, 0, 0, 0, // char 70
+0, 7, 1, 5, 7, 0, 0, 0, // char 71
+0, 5, 5, 7, 5, 0, 0, 0, // char 72
+0, 7, 2, 2, 7, 0, 0, 0, // char 73
+0, 7, 2, 2, 3, 0, 0, 0, // char 74
+0, 5, 3, 5, 5, 0, 0, 0, // char 75
+0, 1, 1, 1, 7, 0, 0, 0, // char 76
+0, 7, 7, 5, 5, 0, 0, 0, // char 77
+0, 3, 5, 5, 5, 0, 0, 0, // char 78
+0, 6, 5, 5, 3, 0, 0, 0, // char 79
+0, 7, 5, 7, 1, 0, 0, 0, // char 80
+0, 2, 5, 3, 6, 0, 0, 0, // char 81
+0, 7, 5, 3, 5, 0, 0, 0, // char 82
+0, 6, 1, 4, 3, 0, 0, 0, // char 83
+0, 7, 2, 2, 2, 0, 0, 0, // char 84
+0, 5, 5, 5, 6, 0, 0, 0, // char 85
+0, 5, 5, 7, 2, 0, 0, 0, // char 86
+0, 5, 5, 7, 7, 0, 0, 0, // char 87
+0, 5, 2, 5, 5, 0, 0, 0, // char 88
+0, 5, 7, 4, 7, 0, 0, 0, // char 89
+0, 7, 4, 1, 7, 0, 0, 0, // char 90
+3, 1, 1, 1, 3, 0, 0, 0, // char 91
+1, 2, 2, 2, 4, 0, 0, 0, // char 92
+6, 4, 4, 4, 6, 0, 0, 0, // char 93
+2, 5, 0, 0, 0, 0, 0, 0, // char 94
+0, 0, 0, 0, 7, 0, 0, 0, // char 95
+2, 4, 0, 0, 0, 0, 0, 0, // char 96
+7, 5, 7, 5, 5, 0, 0, 0, // char 97
+7, 5, 3, 5, 7, 0, 0, 0, // char 98
+6, 1, 1, 1, 6, 0, 0, 0, // char 99
+3, 5, 5, 5, 7, 0, 0, 0, // char 100
+7, 1, 3, 1, 7, 0, 0, 0, // char 101
+7, 1, 3, 1, 1, 0, 0, 0, // char 102
+6, 1, 1, 5, 7, 0, 0, 0, // char 103
+5, 5, 7, 5, 5, 0, 0, 0, // char 104
+7, 2, 2, 2, 7, 0, 0, 0, // char 105
+7, 2, 2, 2, 3, 0, 0, 0, // char 106
+5, 5, 3, 5, 5, 0, 0, 0, // char 107
+1, 1, 1, 1, 7, 0, 0, 0, // char 108
+7, 7, 5, 5, 5, 0, 0, 0, // char 109
+3, 5, 5, 5, 5, 0, 0, 0, // char 110
+6, 5, 5, 5, 3, 0, 0, 0, // char 111
+7, 5, 7, 1, 1, 0, 0, 0, // char 112
+2, 5, 5, 3, 6, 0, 0, 0, // char 113
+7, 5, 3, 5, 5, 0, 0, 0, // char 114
+6, 1, 7, 4, 3, 0, 0, 0, // char 115
+7, 2, 2, 2, 2, 0, 0, 0, // char 116
+5, 5, 5, 5, 6, 0, 0, 0, // char 117
+5, 5, 5, 7, 2, 0, 0, 0, // char 118
+5, 5, 5, 7, 7, 0, 0, 0, // char 119
+5, 5, 2, 5, 5, 0, 0, 0, // char 120
+5, 5, 7, 4, 7, 0, 0, 0, // char 121
+7, 4, 2, 1, 7, 0, 0, 0, // char 122
+6, 2, 3, 2, 6, 0, 0, 0, // char 123
+2, 2, 2, 2, 2, 0, 0, 0, // char 124
+3, 2, 6, 2, 3, 0, 0, 0, // char 125
+0, 4, 7, 1, 0, 0, 0, 0, // char 126
+0, 2, 5, 5, 7, 0, 0, 0, // char 127
+127, 127, 127, 127, 127, 0, 0, 0, // char 128
+85, 42, 85, 42, 85, 0, 0, 0, // char 129
+65, 127, 93, 93, 62, 0, 0, 0, // char 130
+62, 99, 99, 119, 62, 0, 0, 0, // char 131
+17, 68, 17, 68, 17, 0, 0, 0, // char 132
+4, 60, 28, 30, 16, 0, 0, 0, // char 133
+28, 46, 62, 62, 28, 0, 0, 0, // char 134
+54, 62, 62, 28, 8, 0, 0, 0, // char 135
+28, 54, 119, 54, 28, 0, 0, 0, // char 136
+28, 28, 62, 28, 20, 0, 0, 0, // char 137
+28, 62, 127, 42, 58, 0, 0, 0, // char 138
+62, 103, 99, 103, 62, 0, 0, 0, // char 139
+127, 93, 127, 65, 127, 0, 0, 0, // char 140
+56, 8, 8, 14, 14, 0, 0, 0, // char 141
+62, 99, 107, 99, 62, 0, 0, 0, // char 142
+8, 28, 62, 28, 8, 0, 0, 0, // char 143
+0, 0, 85, 0, 0, 0, 0, 0, // char 144
+62, 115, 99, 115, 62, 0, 0, 0, // char 145
+8, 28, 127, 62, 34, 0, 0, 0, // char 146
+62, 28, 8, 28, 62, 0, 0, 0, // char 147
+62, 119, 99, 99, 62, 0, 0, 0, // char 148
+0, 5, 82, 32, 0, 0, 0, 0, // char 149
+0, 17, 42, 68, 0, 0, 0, 0, // char 150
+62, 107, 119, 107, 62, 0, 0, 0, // char 151
+127, 0, 127, 0, 127, 0, 0, 0, // char 152
+85, 85, 85, 85, 85, 0, 0, 0, // char 153
+14, 4, 30, 45, 38, 0, 0, 0, // char 154
+1, 17, 33, 37, 2, 0, 0, 0, // char 155
+28, 0, 62, 32, 24, 0, 0, 0, // char 156
+8, 30, 8, 36, 26, 0, 0, 0, // char 157
+78, 4, 62, 69, 38, 0, 0, 0, // char 158
+34, 95, 18, 18, 10, 0, 0, 0, // char 159
+28, 62, 28, 2, 28, 0, 0, 0, // char 160
+48, 12, 2, 12, 48, 0, 0, 0, // char 161
+34, 122, 34, 34, 18, 0, 0, 0, // char 162
+14, 16, 0, 2, 60, 0, 0, 0, // char 163
+62, 8, 14, 1, 30, 0, 0, 0, // char 164
+2, 2, 2, 34, 28, 0, 0, 0, // char 165
+8, 62, 8, 12, 8, 0, 0, 0, // char 166
+18, 62, 18, 2, 28, 0, 0, 0, // char 167
+60, 16, 126, 8, 112, 0, 0, 0, // char 168
+4, 14, 52, 2, 114, 0, 0, 0, // char 169
+4, 63, 28, 48, 30, 0, 0, 0, // char 170
+60, 67, 64, 32, 24, 0, 0, 0, // char 171
+62, 16, 8, 8, 16, 0, 0, 0, // char 172
+8, 56, 4, 2, 60, 0, 0, 0, // char 173
+98, 15, 34, 57, 88, 0, 0, 0, // char 174
+122, 66, 2, 10, 114, 0, 0, 0, // char 175
+9, 62, 75, 109, 102, 0, 0, 0, // char 176
+50, 75, 70, 99, 98, 0, 0, 0, // char 177
+60, 74, 73, 73, 38, 0, 0, 0, // char 178
+18, 58, 18, 58, 90, 0, 0, 0, // char 179
+35, 98, 34, 34, 28, 0, 0, 0, // char 180
+12, 0, 8, 42, 77, 0, 0, 0, // char 181
+0, 12, 18, 33, 64, 0, 0, 0, // char 182
+61, 17, 61, 25, 109, 0, 0, 0, // char 183
+28, 62, 8, 30, 44, 0, 0, 0, // char 184
+6, 36, 126, 38, 16, 0, 0, 0, // char 185
+36, 78, 4, 70, 60, 0, 0, 0, // char 186
+10, 60, 90, 70, 48, 0, 0, 0, // char 187
+30, 4, 30, 68, 56, 0, 0, 0, // char 188
+36, 126, 100, 8, 8, 0, 0, 0, // char 189
+58, 86, 82, 48, 8, 0, 0, 0, // char 190
+8, 56, 8, 30, 38, 0, 0, 0, // char 191
+8, 2, 62, 32, 28, 0, 0, 0, // char 192
+2, 34, 34, 36, 16, 0, 0, 0, // char 193
+60, 16, 124, 114, 48, 0, 0, 0, // char 194
+4, 54, 44, 38, 100, 0, 0, 0, // char 195
+60, 16, 124, 66, 48, 0, 0, 0, // char 196
+50, 75, 70, 35, 18, 0, 0, 0, // char 197
+14, 100, 28, 40, 120, 0, 0, 0, // char 198
+2, 14, 18, 81, 49, 0, 0, 0, // char 199
+0, 0, 14, 16, 8, 0, 0, 0, // char 200
+0, 10, 31, 26, 4, 0, 0, 0, // char 201
+0, 4, 15, 21, 13, 0, 0, 0, // char 202
+0, 2, 14, 2, 29, 0, 0, 0, // char 203
+62, 32, 20, 4, 2, 0, 0, 0, // char 204
+48, 14, 8, 8, 8, 0, 0, 0, // char 205
+8, 62, 32, 16, 12, 0, 0, 0, // char 206
+28, 8, 8, 8, 62, 0, 0, 0, // char 207
+16, 126, 24, 22, 24, 0, 0, 0, // char 208
+4, 62, 36, 34, 50, 0, 0, 0, // char 209
+4, 30, 8, 62, 8, 0, 0, 0, // char 210
+4, 60, 34, 16, 8, 0, 0, 0, // char 211
+4, 124, 18, 16, 8, 0, 0, 0, // char 212
+62, 32, 32, 32, 62, 0, 0, 0, // char 213
+36, 126, 36, 32, 16, 0, 0, 0, // char 214
+8, 18, 4, 96, 28, 0, 0, 0, // char 215
+62, 32, 16, 24, 38, 0, 0, 0, // char 216
+4, 126, 36, 4, 56, 0, 0, 0, // char 217
+34, 36, 32, 16, 8, 0, 0, 0, // char 218
+124, 68, 82, 96, 16, 0, 0, 0, // char 219
+28, 8, 62, 8, 4, 0, 0, 0, // char 220
+74, 74, 32, 16, 12, 0, 0, 0, // char 221
+28, 0, 62, 8, 4, 0, 0, 0, // char 222
+4, 4, 28, 36, 4, 0, 0, 0, // char 223
+8, 62, 8, 8, 4, 0, 0, 0, // char 224
+0, 28, 0, 0, 62, 0, 0, 0, // char 225
+62, 32, 40, 48, 12, 0, 0, 0, // char 226
+8, 62, 32, 95, 8, 0, 0, 0, // char 227
+32, 32, 16, 8, 6, 0, 0, 0, // char 228
+16, 36, 36, 66, 66, 0, 0, 0, // char 229
+2, 50, 14, 2, 60, 0, 0, 0, // char 230
+62, 32, 32, 16, 12, 0, 0, 0, // char 231
+12, 18, 33, 64, 0, 0, 0, 0, // char 232
+8, 62, 8, 42, 77, 0, 0, 0, // char 233
+62, 32, 20, 8, 16, 0, 0, 0, // char 234
+60, 0, 62, 0, 30, 0, 0, 0, // char 235
+8, 4, 36, 98, 94, 0, 0, 0, // char 236
+64, 40, 16, 104, 6, 0, 0, 0, // char 237
+62, 8, 126, 8, 112, 0, 0, 0, // char 238
+116, 78, 36, 8, 8, 0, 0, 0, // char 239
+120, 64, 32, 32, 124, 0, 0, 0, // char 240
+30, 16, 62, 16, 30, 0, 0, 0, // char 241
+28, 0, 62, 32, 24, 0, 0, 0, // char 242
+36, 36, 36, 32, 24, 0, 0, 0, // char 243
+20, 20, 20, 84, 50, 0, 0, 0, // char 244
+2, 2, 2, 50, 14, 0, 0, 0, // char 245
+126, 66, 66, 66, 126, 0, 0, 0, // char 246
+62, 34, 32, 16, 8, 0, 0, 0, // char 247
+62, 32, 62, 32, 24, 0, 0, 0, // char 248
+1, 2, 16, 8, 7, 0, 0, 0, // char 249
+0, 21, 16, 8, 6, 0, 0, 0, // char 250
+0, 2, 31, 18, 4, 0, 0, 0, // char 251
+0, 0, 14, 8, 30, 0, 0, 0, // char 252
+0, 14, 30, 8, 14, 0, 0, 0, // char 253
+8, 4, 99, 16, 8, 0, 0, 0, // char 254
+8, 16, 99, 4, 8, 0, 0, 0, // char 255
+};
\ No newline at end of file
diff --git a/source/graphics.cpp b/source/graphics.cpp
index fc49b3b..80a58a4 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -1303,6 +1303,8 @@ int Graphics::drawCharacter(
uint8_t ch,
int x,
int y,
+ uint8_t fgColor,
+ uint8_t bgColor,
uint8_t printMode,
int forceCharWidth,
int forceCharHeight) {
@@ -1332,9 +1334,21 @@ int Graphics::drawCharacter(
int index = ch - 0x80;
extraCharWidth = 4;
copyStretchSpriteToScreen(fontSpriteData, (index % 16) * 8, (index / 16) * 8 + 56, 8, 5, x, y, (scrW + extraCharWidth), scrH, false, false, evenPxOnly);
-
+ }
+ }
+ else if ((printMode & PRINT_MODE_CUSTOM_FONT) == PRINT_MODE_CUSTOM_FONT) {
+ if (ch > 0x0f) {
+ drawCharacterFromBytes(
+ &(_memory->data[0x5600 + ch*8]),//get bytes from memory (0x5600)
+ x,
+ y,
+ fgColor,
+ bgColor,
+ printMode
+ );
}
+ return (ch < 0x80 ? _memory->data[0x5600] : _memory->data[0x5601]) - 4;
}
else{
if (ch >= 0x10 && ch < 0x80) {
diff --git a/source/graphics.h b/source/graphics.h
index c593c3e..b5e441e 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -113,6 +113,8 @@ class Graphics {
uint8_t ch,
int x,
int y,
+ uint8_t fgColor,
+ uint8_t bgColor,
uint8_t printMode = 0,
int forceCharWidth = -1,
int forceCharHeight = -1);
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 7fcb8d5..d3bfb7c 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -142,7 +142,15 @@ int print(std::string str, int x, int y, uint8_t c) {
ch = str[++n];
for(int i = 0; i < times; i++) {
//TODO: combine with other draw character call - fix missing bg? lineheight?
- x += charWidth + _ph_graphics->drawCharacter(ch, x, y, printMode, forceCharWidth, forceCharHeight);
+ x += charWidth + _ph_graphics->drawCharacter(
+ ch,
+ x,
+ y,
+ prevDrawPal[fgColor & 0x0f],
+ bgColor,
+ printMode,
+ forceCharWidth,
+ forceCharHeight);
}
}
else if (ch == 2) { // "\#{p0}" draw text on a solid background color
@@ -343,7 +351,15 @@ int print(std::string str, int x, int y, uint8_t c) {
int xOffset = (offset%4)-2;
int yOffset = (offset/4)-8;
- _ph_graphics->drawCharacter(toPrint, prevX + xOffset, prevY + yOffset, printMode, forceCharWidth, forceCharHeight);
+ _ph_graphics->drawCharacter(
+ toPrint,
+ prevX + xOffset,
+ prevY + yOffset,
+ prevDrawPal[fgColor & 0x0f],
+ bgColor,
+ printMode,
+ forceCharWidth,
+ forceCharHeight);
}
else if (ch == 12) { //"\f{p0}" draw text with this foreground color
uint8_t fgColChar = str[++n];
@@ -352,6 +368,12 @@ int print(std::string str, int x, int y, uint8_t c) {
//this is needed for legacy text drawing
_ph_mem->drawState.drawPaletteMap[7] = prevDrawPal[fgColor] & 0x0f;
}
+ else if (ch == 14) { //"\014" Turn on custom font stored at 0x5600
+ printMode |= PRINT_MODE_CUSTOM_FONT;
+ }
+ else if (ch == 15) { //"\015" Turn off custom font stored at 0x5600
+ printMode &= ~(PRINT_MODE_CUSTOM_FONT);
+ }
else if (ch == '\n') {
x = homeX;
lineHeight = lineHeight > 0 ? lineHeight : 6;
@@ -378,7 +400,16 @@ int print(std::string str, int x, int y, uint8_t c) {
}
prevX = x;
prevY = y;
- x += charWidth + _ph_graphics->drawCharacter(ch, x, y, printMode, forceCharWidth, forceCharHeight);
+ x += charWidth + _ph_graphics->drawCharacter(
+ ch,
+ x,
+ y,
+ prevDrawPal[fgColor & 0x0f],
+ bgColor,
+ printMode,
+ forceCharWidth,
+ forceCharHeight);
+
while (framesToPause > 0){
_ph_vm->vm_flip();
diff --git a/test/fontdatatests.cpp b/test/fontdatatests.cpp
index f17006c..33baedd 100644
--- a/test/fontdatatests.cpp
+++ b/test/fontdatatests.cpp
@@ -1,6 +1,95 @@
#include "doctest.h"
#include "../source/fontdata.h"
+#include "../source/stringToDataHelpers.h"
+#include "../source/nibblehelpers.h"
+
+#define BITMASK(n) (1U<<(n))
+
TEST_CASE("checking fontdata exists") {
CHECK(get_font_data().length() == 15995);
-}
\ No newline at end of file
+}
+
+TEST_CASE("checking defaultFontBinaryData exists") {
+ CHECK(defaultFontBinaryData[8*16] > 0);
+}
+
+/*
+//script to convert sprite sheet formatted font data to binary pico 8 font format
+TEST_CASE("convert font data") {
+ auto fontdata = get_font_data();
+ uint8_t fontSpriteData[128 * 64];
+ uint8_t defaultFontData[2048];
+
+ copy_string_to_sprite_memory(fontSpriteData, fontdata);
+
+
+ for(int ch = 0; ch < 256; ch++) {
+ //first 16 chars don't print
+ //TODO: fill in default width data
+ if (ch < 16) {
+ for(int j = 0; j < 8; j++) {
+ defaultFontData[(ch*8) + j] = 0;
+ }
+
+ continue;
+ }
+
+ if (ch >= 0x10) {
+ int index = ch - 0x10;
+ int width = 4;
+ int height = 5;
+ int sprX = (index % 16) * 8;
+ int sprY = (index / 16) * 8;
+
+ if (ch >= 0x80) {
+ index = ch - 0x80;
+ width = 8;
+ sprY = (index / 16) * 8 + 56;
+ }
+
+ //copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8, width, height, false, false);
+ //copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8 + 56, width, height, false, false);
+
+ //each char is 8x8 bitfield. default chars should only take up 4x5 (or 8x5 for wide chars)
+ //get the sprite index, then get the pixel nibble, and if its set set that bit to 1
+ //combine all 8 bits into a byte, and add it to the buffer, then do the same for the next line
+ for(int y = 0; y < 8; y++) {
+ uint8_t lineBitfield = 0;
+ if (y < height) {
+ for (int x = 0; x < width; x+=2) {
+ uint8_t bothPix = fontSpriteData[COMBINED_IDX(sprX + x, sprY + y)];
+
+ uint8_t lc = bothPix & 0x0f;
+ uint8_t rc = bothPix >> 4;
+
+ if (lc) {
+ lineBitfield |= BITMASK(x);
+ }
+ if (rc) {
+ lineBitfield |= BITMASK(x + 1);
+ }
+ }
+ }
+
+ defaultFontData[(ch*8) + y] = lineBitfield;
+ }
+ }
+
+
+ printf("finished converting font to binary data. printing\n\n");
+ printf("uint8_t defaultFontBinaryData[2048] = {\n");
+
+ for (int i = 0; i < 2048; i++) {
+ printf("%d, ", defaultFontData[i]);
+
+ if ((i + 1) % 8 == 0) {
+ printf("// char %d\n", i / 8);
+ }
+ }
+
+ printf("}\n\n");
+ printf("done printing\n\n");
+ }
+}
+*/
\ No newline at end of file
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index e3c3332..c73402a 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -2094,8 +2094,8 @@ TEST_CASE("graphics class behaves as expected") {
//emulate print("zo",8,0)
picoRam.drawState.drawPaletteMap[7] = 6;
- graphics->drawCharacter(122, 8, 0);
- graphics->drawCharacter(111, 12, 0);
+ graphics->drawCharacter(122, 8, 0, 6, 0);
+ graphics->drawCharacter(111, 12, 0, 6, 0);
picoRam.hwState.spriteSheetMemMapping = 0x60;
@@ -2360,9 +2360,9 @@ TEST_CASE("graphics class behaves as expected") {
//emulate print("\^x0\^y1▤a",10,10,9)
picoRam.drawState.drawPaletteMap[7] = 9;
- graphics->drawCharacter(152, 10, 10, 0, 0, 1);
+ graphics->drawCharacter(152, 10, 10, 9, 0, 0, 0, 1);
//the a should be invisible (0 width)
- graphics->drawCharacter(65, 10, 10, 0, 0, 1);
+ graphics->drawCharacter(65, 10, 10, 9, 0, 0, 0, 1);
std::vector<coloredPoint> expectedPoints = {
{9,10,0},
@@ -2393,7 +2393,7 @@ TEST_CASE("graphics class behaves as expected") {
//emulate print("\^x3\^y3a",10,10,9)
picoRam.drawState.drawPaletteMap[7] = 9;
- graphics->drawCharacter(97, 10, 10, 0, 3, 3);
+ graphics->drawCharacter(97, 10, 10, 9, 0, 0, 3, 3);
std::vector<coloredPoint> expectedPoints = {
{9,10,0},
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index a574da6..f2e20a8 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -752,7 +752,7 @@ TEST_CASE("Print helper functions") {
checkPoints(graphics, expectedPoints);
}
- SUBCASE("p8scii audio control code for decorating prev char (\\v)") {
+ SUBCASE("p8scii control code for decorating prev char (\\v)") {
graphics->cls();
print("\n:\x0b""b:", 0, 0);
@@ -767,6 +767,42 @@ TEST_CASE("Print helper functions") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("p8scii custom font control code (\\014 on and \\015 off)") {
+ graphics->cls();
+ memory->data[0x5600]= 8; //width
+ memory->data[0x5601]= 8; //width for chars > 127
+ memory->data[0x5602]= 8; //height
+ memory->data[0x5603]= 0;
+ memory->data[0x5604]= 0;
+
+ //char 16
+ memory->data[0x5680]= 1; //#_______
+ memory->data[0x5681] = 3; //##______
+ memory->data[0x5682] = 7; //###_____
+ memory->data[0x5683] = 15; //####____
+ memory->data[0x5684] = 31; //#####___
+ memory->data[0x5685] = 63; //######__
+ memory->data[0x5686] = 127; //#######_
+ memory->data[0x5687] = 255; //########
+
+ //print char 16 with custom font
+ print("\x0e""\x10""\x0f""", 0, 0);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {0, 0, 6}, {1, 0, 0},
+ {0, 1, 6}, {1, 1, 6}, {2, 1, 0},
+ {0, 2, 6}, {1, 2, 6}, {2, 2, 6}, {3, 2, 0},
+ {0, 3, 6}, {1, 3, 6}, {2, 3, 6}, {3, 3, 6}, {4, 3, 0},
+ {0, 4, 6}, {1, 4, 6}, {2, 4, 6}, {3, 4, 6}, {4, 4, 6}, {5, 4, 0},
+ {0, 5, 6}, {1, 5, 6}, {2, 5, 6}, {3, 5, 6}, {4, 5, 6}, {5, 5, 6}, {6, 5, 0},
+ {0, 6, 6}, {1, 6, 6}, {2, 6, 6}, {3, 6, 6}, {4, 6, 6}, {5, 6, 6}, {6, 6, 6}, {7, 6, 0},
+ {0, 7, 6}, {1, 7, 6}, {2, 7, 6}, {3, 7, 6}, {4, 7, 6}, {5, 7, 6}, {6, 7, 6}, {7, 7, 6}, {7, 8, 0},
+ {0, 8, 0}
+
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
delete stubHost;