1 #include <stdint.h>
2 #include <stdbool.h>
3 #include <string.h>
4 #include "pt2_header.h"
5 #include "pt2_helpers.h"
6 #include "pt2_tables.h"
7 #include "pt2_visuals.h"
8 #include "pt2_structs.h"
9 #include "pt2_bmp.h"
10 
charOut(uint32_t xPos,uint32_t yPos,char ch,uint32_t color)11 void charOut(uint32_t xPos, uint32_t yPos, char ch, uint32_t color)
12 {
13 	const uint8_t *srcPtr;
14 	uint32_t *dstPtr;
15 
16 	if (ch == '\0' || ch == ' ')
17 		return;
18 
19 	int32_t h = FONT_CHAR_H;
20 	if (ch == 5 || ch == 6) // arrow up/down has 1 more scanline
21 		h++;
22 
23 	srcPtr = &fontBMP[(ch & 0x7F) << 3];
24 	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
25 
26 	for (int32_t y = 0; y < h; y++)
27 	{
28 		for (int32_t x = 0; x < FONT_CHAR_W; x++)
29 		{
30 			if (srcPtr[x])
31 				dstPtr[x] = color;
32 		}
33 
34 		srcPtr += 127*FONT_CHAR_W;
35 		dstPtr += SCREEN_W;
36 	}
37 }
38 
charOut2(uint32_t xPos,uint32_t yPos,char ch)39 void charOut2(uint32_t xPos, uint32_t yPos, char ch) // for static GUI text
40 {
41 	const uint8_t *srcPtr;
42 	uint32_t *dstPtr;
43 
44 	if (ch == '\0' || ch == ' ')
45 		return;
46 
47 	int32_t h = FONT_CHAR_H;
48 	if (ch == 5 || ch == 6) // arrow up/down has 1 more scanline
49 		h++;
50 
51 	srcPtr = &fontBMP[(ch & 0x7F) << 3];
52 	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
53 
54 	const uint32_t fgColor = video.palette[PAL_BORDER];
55 	const uint32_t bgColor = video.palette[PAL_GENBKG2];
56 
57 	for (int32_t y = 0; y < h; y++)
58 	{
59 		for (int32_t x = 0; x < FONT_CHAR_W; x++)
60 		{
61 			if (srcPtr[x])
62 			{
63 				dstPtr[x+(SCREEN_W+1)] = bgColor;
64 				dstPtr[x] = fgColor;
65 			}
66 		}
67 
68 		srcPtr += 127*FONT_CHAR_W;
69 		dstPtr += SCREEN_W;
70 	}
71 }
72 
charOutBg(uint32_t xPos,uint32_t yPos,char ch,uint32_t fgColor,uint32_t bgColor)73 void charOutBg(uint32_t xPos, uint32_t yPos, char ch, uint32_t fgColor, uint32_t bgColor)
74 {
75 	const uint8_t *srcPtr;
76 	uint32_t *dstPtr, colors[2];
77 
78 	if (ch == '\0')
79 		return;
80 
81 	int32_t h = FONT_CHAR_H;
82 	if (ch == 5 || ch == 6) // arrow up/down has 1 more scanline
83 		h++;
84 
85 	srcPtr = &fontBMP[(ch & 0x7F) << 3];
86 	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
87 
88 	colors[0] = bgColor;
89 	colors[1] = fgColor;
90 
91 	for (int32_t y = 0; y < h; y++)
92 	{
93 		for (int32_t x = 0; x < FONT_CHAR_W; x++)
94 			dstPtr[x] = colors[srcPtr[x]];
95 
96 		srcPtr += 127*FONT_CHAR_W;
97 		dstPtr += SCREEN_W;
98 	}
99 }
100 
charOutBig(uint32_t xPos,uint32_t yPos,char ch,uint32_t color)101 void charOutBig(uint32_t xPos, uint32_t yPos, char ch, uint32_t color)
102 {
103 	const uint8_t *srcPtr;
104 	uint32_t *dstPtr1, *dstPtr2;
105 
106 	if (ch == '\0' || ch == ' ')
107 		return;
108 
109 	int32_t h = FONT_CHAR_H;
110 	if (ch == 5 || ch == 6) // arrow up/down has 1 more scanline
111 		h++;
112 
113 	srcPtr = &fontBMP[(ch & 0x7F) << 3];
114 	dstPtr1 = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
115 	dstPtr2 = dstPtr1 + SCREEN_W;
116 
117 	for (int32_t y = 0; y < h; y++)
118 	{
119 		for (int32_t x = 0; x < FONT_CHAR_W; x++)
120 		{
121 			if (srcPtr[x])
122 			{
123 				dstPtr1[x] = color;
124 				dstPtr2[x] = color;
125 			}
126 		}
127 
128 		srcPtr += 127*FONT_CHAR_W;
129 		dstPtr1 += SCREEN_W*2;
130 		dstPtr2 += SCREEN_W*2;
131 	}
132 }
133 
charOutBigBg(uint32_t xPos,uint32_t yPos,char ch,uint32_t fgColor,uint32_t bgColor)134 void charOutBigBg(uint32_t xPos, uint32_t yPos, char ch, uint32_t fgColor, uint32_t bgColor)
135 {
136 	const uint8_t *srcPtr;
137 	uint32_t *dstPtr1, *dstPtr2, colors[2];
138 
139 	if (ch == '\0')
140 		return;
141 
142 	srcPtr = &fontBMP[(ch & 0x7F) << 3];
143 	dstPtr1 = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
144 	dstPtr2 = dstPtr1 + SCREEN_W;
145 
146 	colors[0] = bgColor;
147 	colors[1] = fgColor;
148 
149 	for (int32_t y = 0; y < FONT_CHAR_H; y++)
150 	{
151 		for (int32_t x = 0; x < FONT_CHAR_W; x++)
152 		{
153 			const uint32_t pixel = colors[srcPtr[x]];
154 			dstPtr1[x] = pixel;
155 			dstPtr2[x] = pixel;
156 		}
157 
158 		srcPtr += 127*FONT_CHAR_W;
159 		dstPtr1 += SCREEN_W*2;
160 		dstPtr2 += SCREEN_W*2;
161 	}
162 }
163 
textOut(uint32_t xPos,uint32_t yPos,const char * text,uint32_t color)164 void textOut(uint32_t xPos, uint32_t yPos, const char *text, uint32_t color)
165 {
166 	assert(text != NULL);
167 
168 	uint32_t x = xPos;
169 	while (*text != '\0')
170 	{
171 		charOut(x, yPos, *text++, color);
172 		x += FONT_CHAR_W;
173 	}
174 }
175 
textOutN(uint32_t xPos,uint32_t yPos,const char * text,uint32_t n,uint32_t color)176 void textOutN(uint32_t xPos, uint32_t yPos, const char *text, uint32_t n, uint32_t color)
177 {
178 	assert(text != NULL);
179 
180 	uint32_t x = xPos;
181 	uint32_t i = 0;
182 
183 	while (*text != '\0' && i++ < n)
184 	{
185 		charOut(x, yPos, *text++, color);
186 		x += FONT_CHAR_W;
187 	}
188 }
189 
textOut2(uint32_t xPos,uint32_t yPos,const char * text)190 void textOut2(uint32_t xPos, uint32_t yPos, const char *text) // for static GUI text
191 {
192 	assert(text != NULL);
193 
194 	uint32_t x = xPos;
195 	while (*text != '\0')
196 	{
197 		charOut2(x, yPos, *text++);
198 		x += FONT_CHAR_W-1;
199 	}
200 }
201 
textOutTight(uint32_t xPos,uint32_t yPos,const char * text,uint32_t color)202 void textOutTight(uint32_t xPos, uint32_t yPos, const char *text, uint32_t color)
203 {
204 	assert(text != NULL);
205 
206 	uint32_t x = xPos;
207 	while (*text != '\0')
208 	{
209 		charOut(x, yPos, *text++, color);
210 		x += FONT_CHAR_W-1;
211 	}
212 }
213 
textOutTightN(uint32_t xPos,uint32_t yPos,const char * text,uint32_t n,uint32_t color)214 void textOutTightN(uint32_t xPos, uint32_t yPos, const char *text, uint32_t n, uint32_t color)
215 {
216 	assert(text != NULL);
217 
218 	uint32_t x = xPos;
219 	uint32_t i = 0;
220 
221 	while (*text != '\0' && i++ < n)
222 	{
223 		charOut(x, yPos, *text++, color);
224 		x += FONT_CHAR_W-1;
225 	}
226 }
227 
textOutBg(uint32_t xPos,uint32_t yPos,const char * text,uint32_t fgColor,uint32_t bgColor)228 void textOutBg(uint32_t xPos, uint32_t yPos, const char *text, uint32_t fgColor, uint32_t bgColor)
229 {
230 	assert(text != NULL);
231 
232 	uint32_t x = xPos;
233 	while (*text != '\0')
234 	{
235 		charOutBg(x, yPos, *text++, fgColor, bgColor);
236 		x += FONT_CHAR_W;
237 	}
238 }
239 
textOutBig(uint32_t xPos,uint32_t yPos,const char * text,uint32_t color)240 void textOutBig(uint32_t xPos, uint32_t yPos, const char *text, uint32_t color)
241 {
242 	assert(text != NULL);
243 
244 	uint32_t x = xPos;
245 	while (*text != '\0')
246 	{
247 		charOutBig(x, yPos, *text++, color);
248 		x += FONT_CHAR_W;
249 	}
250 }
251 
textOutBigBg(uint32_t xPos,uint32_t yPos,const char * text,uint32_t fgColor,uint32_t bgColor)252 void textOutBigBg(uint32_t xPos, uint32_t yPos, const char *text, uint32_t fgColor, uint32_t bgColor)
253 {
254 	assert(text != NULL);
255 
256 	uint32_t x = xPos;
257 	while (*text != '\0')
258 	{
259 		charOutBigBg(x, yPos, *text++, fgColor, bgColor);
260 		x += FONT_CHAR_W;
261 	}
262 }
263 
printTwoDecimals(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)264 void printTwoDecimals(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
265 {
266 	if (value == 0)
267 	{
268 		textOut(x, y, "00", fontColor);
269 	}
270 	else
271 	{
272 		if (value > 99)
273 			value = 99;
274 
275 		charOut(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor); value /= 10;
276 		charOut(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor);
277 	}
278 }
279 
printTwoDecimalsBig(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)280 void printTwoDecimalsBig(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
281 {
282 	if (value == 0)
283 	{
284 		textOutBig(x, y, "00", fontColor);
285 	}
286 	else
287 	{
288 		if (value > 99)
289 			value = 99;
290 
291 		charOutBig(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor); value /= 10;
292 		charOutBig(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor);
293 	}
294 }
295 
printThreeDecimals(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)296 void printThreeDecimals(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
297 {
298 	if (value == 0)
299 	{
300 		textOut(x, y, "000", fontColor);
301 	}
302 	else
303 	{
304 		if (value > 999)
305 			value = 999;
306 
307 		charOut(x + (FONT_CHAR_W * 2), y, '0' + (value % 10), fontColor); value /= 10;
308 		charOut(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor); value /= 10;
309 		charOut(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor);
310 	}
311 }
312 
printFourDecimals(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)313 void printFourDecimals(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
314 {
315 	if (value == 0)
316 	{
317 		textOut(x, y, "0000", fontColor);
318 	}
319 	else
320 	{
321 		if (value > 9999)
322 			value = 9999;
323 
324 		charOut(x + (FONT_CHAR_W * 3), y, '0' + (value % 10), fontColor); value /= 10;
325 		charOut(x + (FONT_CHAR_W * 2), y, '0' + (value % 10), fontColor); value /= 10;
326 		charOut(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor); value /= 10;
327 		charOut(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor);
328 	}
329 }
330 
printFiveDecimals(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)331 void printFiveDecimals(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
332 {
333 	if (value == 0)
334 	{
335 		textOut(x, y, "00000", fontColor);
336 	}
337 	else
338 	{
339 		if (value > 99999)
340 			value = 99999;
341 
342 		charOut(x + (FONT_CHAR_W * 4), y, '0' + (value % 10), fontColor); value /= 10;
343 		charOut(x + (FONT_CHAR_W * 3), y, '0' + (value % 10), fontColor); value /= 10;
344 		charOut(x + (FONT_CHAR_W * 2), y, '0' + (value % 10), fontColor); value /= 10;
345 		charOut(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor); value /= 10;
346 		charOut(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor);
347 	}
348 }
349 
350 // this one is used for module size and sampler screen display length (zeroes are padded with space)
printSixDecimals(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)351 void printSixDecimals(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
352 {
353 	char numberText[7];
354 	uint8_t i;
355 
356 	if (value == 0)
357 	{
358 		textOut(x, y, "     0", fontColor);
359 	}
360 	else
361 	{
362 		if (value > 999999)
363 			value = 999999;
364 
365 		numberText[6] = 0;
366 		numberText[5] = '0' + (value % 10); value /= 10;
367 		numberText[4] = '0' + (value % 10); value /= 10;
368 		numberText[3] = '0' + (value % 10); value /= 10;
369 		numberText[2] = '0' + (value % 10); value /= 10;
370 		numberText[1] = '0' + (value % 10); value /= 10;
371 		numberText[0] = '0' + (value % 10);
372 
373 		i = 0;
374 		while (numberText[i] == '0')
375 			numberText[i++] = ' ';
376 
377 		textOut(x, y, numberText, fontColor);
378 	}
379 }
380 
printOneHex(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)381 void printOneHex(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
382 {
383 	charOut(x, y, hexTable[value & 15], fontColor);
384 }
385 
printOneHexBig(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)386 void printOneHexBig(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
387 {
388 	charOutBig(x, y, hexTable[value & 15], fontColor);
389 }
390 
printTwoHex(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)391 void printTwoHex(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
392 {
393 	if (value == 0)
394 	{
395 		textOut(x, y, "00", fontColor);
396 	}
397 	else
398 	{
399 		value &= 0xFF;
400 
401 		charOut(x + (FONT_CHAR_W * 0), y, hexTable[value >> 4], fontColor);
402 		charOut(x + (FONT_CHAR_W * 1), y, hexTable[value & 15], fontColor);
403 	}
404 }
405 
printTwoHexBig(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)406 void printTwoHexBig(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
407 {
408 	if (value == 0)
409 	{
410 		textOutBig(x, y, "00", fontColor);
411 	}
412 	else
413 	{
414 		value &= 0xFF;
415 
416 		charOutBig(x + (FONT_CHAR_W * 0), y, hexTable[value >> 4], fontColor);
417 		charOutBig(x + (FONT_CHAR_W * 1), y, hexTable[value & 15], fontColor);
418 	}
419 }
420 
printThreeHex(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)421 void printThreeHex(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
422 {
423 	if (value == 0)
424 	{
425 		textOut(x, y, "000", fontColor);
426 	}
427 	else
428 	{
429 		value &= 0xFFF;
430 
431 		charOut(x + (FONT_CHAR_W * 0), y, hexTable[value >> 8], fontColor);
432 		charOut(x + (FONT_CHAR_W * 1), y, hexTable[(value & (15 << 4)) >> 4], fontColor);
433 		charOut(x + (FONT_CHAR_W * 2), y, hexTable[value & 15], fontColor);
434 	}
435 }
436 
printFourHex(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)437 void printFourHex(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
438 {
439 	if (value == 0)
440 	{
441 		textOut(x, y, "0000", fontColor);
442 	}
443 	else
444 	{
445 		value &= 0xFFFF;
446 
447 		charOut(x + (FONT_CHAR_W * 0), y, hexTable[value >> 12], fontColor);
448 		charOut(x + (FONT_CHAR_W * 1), y, hexTable[(value & (15 << 8)) >> 8], fontColor);
449 		charOut(x + (FONT_CHAR_W * 2), y, hexTable[(value & (15 << 4)) >> 4], fontColor);
450 		charOut(x + (FONT_CHAR_W * 3), y, hexTable[value & 15], fontColor);
451 	}
452 }
453 
printFiveHex(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor)454 void printFiveHex(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor)
455 {
456 	if (value == 0)
457 	{
458 		textOut(x, y, "00000", fontColor);
459 	}
460 	else
461 	{
462 		value &= 0xFFFFF;
463 
464 		charOut(x + (FONT_CHAR_W * 0), y, hexTable[value  >> 16], fontColor);
465 		charOut(x + (FONT_CHAR_W * 1), y, hexTable[(value & (15 << 12)) >> 12], fontColor);
466 		charOut(x + (FONT_CHAR_W * 2), y, hexTable[(value & (15 << 8)) >> 8], fontColor);
467 		charOut(x + (FONT_CHAR_W * 3), y, hexTable[(value & (15 << 4)) >> 4], fontColor);
468 		charOut(x + (FONT_CHAR_W * 4), y, hexTable[value & 15], fontColor);
469 	}
470 }
471 
printTwoDecimalsBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)472 void printTwoDecimalsBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
473 {
474 	if (value == 0)
475 	{
476 		textOutBg(x, y, "00", fontColor, backColor);
477 	}
478 	else
479 	{
480 		if (value > 99)
481 			value = 99;
482 
483 		charOutBg(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor, backColor); value /= 10;
484 		charOutBg(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor, backColor);
485 	}
486 }
487 
printTwoDecimalsBigBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)488 void printTwoDecimalsBigBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
489 {
490 	if (value == 0)
491 	{
492 		textOutBigBg(x, y, "00", fontColor, backColor);
493 	}
494 	else
495 	{
496 		if (value > 99)
497 			value = 99;
498 
499 		charOutBigBg(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor, backColor); value /= 10;
500 		charOutBigBg(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor, backColor);
501 	}
502 }
503 
printThreeDecimalsBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)504 void printThreeDecimalsBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
505 {
506 	if (value == 0)
507 	{
508 		textOutBg(x, y, "000", fontColor, backColor);
509 	}
510 	else
511 	{
512 		if (value > 999)
513 			value = 999;
514 
515 		charOutBg(x + (FONT_CHAR_W * 2), y, '0' + (value % 10), fontColor, backColor); value /= 10;
516 		charOutBg(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor, backColor); value /= 10;
517 		charOutBg(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor, backColor);
518 	}
519 }
520 
printFourDecimalsBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)521 void printFourDecimalsBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
522 {
523 	if (value == 0)
524 	{
525 		textOutBg(x, y, "0000", fontColor, backColor);
526 	}
527 	else
528 	{
529 		if (value > 9999)
530 			value = 9999;
531 
532 		charOutBg(x + (FONT_CHAR_W * 3), y, '0' + (value % 10), fontColor, backColor); value /= 10;
533 		charOutBg(x + (FONT_CHAR_W * 2), y, '0' + (value % 10), fontColor, backColor); value /= 10;
534 		charOutBg(x + (FONT_CHAR_W * 1), y, '0' + (value % 10), fontColor, backColor); value /= 10;
535 		charOutBg(x + (FONT_CHAR_W * 0), y, '0' + (value % 10), fontColor, backColor);
536 	}
537 }
538 
539 // this one is used for "DISP:" in the sampler screen (zeroes are padded with space)
printFiveDecimalsBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)540 void printFiveDecimalsBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
541 {
542 	char numberText[6];
543 	uint8_t i;
544 
545 	if (value == 0)
546 	{
547 		textOutBg(x, y, "    0", fontColor, backColor);
548 	}
549 	else
550 	{
551 		if (value > 99999)
552 			value = 99999;
553 
554 		numberText[5] = 0;
555 		numberText[4] = '0' + (value % 10); value /= 10;
556 		numberText[3] = '0' + (value % 10); value /= 10;
557 		numberText[2] = '0' + (value % 10); value /= 10;
558 		numberText[1] = '0' + (value % 10); value /= 10;
559 		numberText[0] = '0' + (value % 10);
560 
561 		i = 0;
562 		while (numberText[i] == '0')
563 			numberText[i++] = ' ';
564 
565 		textOutBg(x, y, numberText, fontColor, backColor);
566 	}
567 }
568 
569 // this one is used for module size (zeroes are padded with space)
printSixDecimalsBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)570 void printSixDecimalsBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
571 {
572 	char numberText[7];
573 	uint8_t i;
574 
575 	if (value == 0)
576 	{
577 		textOutBg(x, y, "     0", fontColor, backColor);
578 	}
579 	else
580 	{
581 		if (value > 999999)
582 			value = 999999;
583 
584 		numberText[6] = 0;
585 		numberText[5] = '0' + (value % 10); value /= 10;
586 		numberText[4] = '0' + (value % 10); value /= 10;
587 		numberText[3] = '0' + (value % 10); value /= 10;
588 		numberText[2] = '0' + (value % 10); value /= 10;
589 		numberText[1] = '0' + (value % 10); value /= 10;
590 		numberText[0] = '0' + (value % 10);
591 
592 		i = 0;
593 		while (numberText[i] == '0')
594 			numberText[i++] = ' ';
595 
596 		textOutBg(x, y, numberText, fontColor, backColor);
597 	}
598 }
599 
printOneHexBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)600 void printOneHexBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
601 {
602 	charOutBg(x, y, hexTable[value & 0xF], fontColor, backColor);
603 }
604 
printOneHexBigBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)605 void printOneHexBigBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
606 {
607 	charOutBigBg(x, y, hexTable[value & 0xF], fontColor, backColor);
608 }
609 
printTwoHexBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)610 void printTwoHexBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
611 {
612 	if (value == 0)
613 	{
614 		textOutBg(x, y, "00", fontColor, backColor);
615 	}
616 	else
617 	{
618 		value &= 0xFF;
619 
620 		charOutBg(x + (FONT_CHAR_W * 0), y, hexTable[value >> 4], fontColor, backColor);
621 		charOutBg(x + (FONT_CHAR_W * 1), y, hexTable[value & 15], fontColor, backColor);
622 	}
623 }
624 
printTwoHexBigBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)625 void printTwoHexBigBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
626 {
627 	if (value == 0)
628 	{
629 		textOutBigBg(x, y, "00", fontColor, backColor);
630 	}
631 	else
632 	{
633 		value &= 0xFF;
634 
635 		charOutBigBg(x + (FONT_CHAR_W * 0), y, hexTable[value >> 4], fontColor, backColor);
636 		charOutBigBg(x + (FONT_CHAR_W * 1), y, hexTable[value & 15], fontColor, backColor);
637 	}
638 }
639 
printThreeHexBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)640 void printThreeHexBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
641 {
642 	if (value == 0)
643 	{
644 		textOutBg(x, y, "000", fontColor, backColor);
645 	}
646 	else
647 	{
648 		value &= 0xFFF;
649 
650 		charOutBg(x + (FONT_CHAR_W * 0), y, hexTable[value >> 8], fontColor, backColor);
651 		charOutBg(x + (FONT_CHAR_W * 1), y, hexTable[(value & (15 << 4)) >> 4], fontColor, backColor);
652 		charOutBg(x + (FONT_CHAR_W * 2), y, hexTable[value & 15], fontColor, backColor);
653 	}
654 }
655 
printFourHexBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)656 void printFourHexBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
657 {
658 	if (value == 0)
659 	{
660 		textOutBg(x, y, "0000", fontColor, backColor);
661 	}
662 	else
663 	{
664 		value &= 0xFFFF;
665 
666 		charOutBg(x + (FONT_CHAR_W * 0), y, hexTable[value >> 12], fontColor, backColor);
667 		charOutBg(x + (FONT_CHAR_W * 1), y, hexTable[(value & (15 << 8)) >> 8], fontColor, backColor);
668 		charOutBg(x + (FONT_CHAR_W * 2), y, hexTable[(value & (15 << 4)) >> 4], fontColor, backColor);
669 		charOutBg(x + (FONT_CHAR_W * 3), y, hexTable[value & 15], fontColor, backColor);
670 	}
671 }
672 
printFiveHexBg(uint32_t x,uint32_t y,uint32_t value,uint32_t fontColor,uint32_t backColor)673 void printFiveHexBg(uint32_t x, uint32_t y, uint32_t value, uint32_t fontColor, uint32_t backColor)
674 {
675 	if (value == 0)
676 	{
677 		textOutBg(x, y, "00000", fontColor, backColor);
678 	}
679 	else
680 	{
681 		value &= 0xFFFFF;
682 
683 		charOutBg(x + (FONT_CHAR_W * 0), y, hexTable[value >> 16], fontColor, backColor);
684 		charOutBg(x + (FONT_CHAR_W * 1), y, hexTable[(value & (15 << 12)) >> 12], fontColor, backColor);
685 		charOutBg(x + (FONT_CHAR_W * 2), y, hexTable[(value & (15 << 8)) >> 8], fontColor, backColor);
686 		charOutBg(x + (FONT_CHAR_W * 3), y, hexTable[(value & (15 << 4)) >> 4], fontColor, backColor);
687 		charOutBg(x + (FONT_CHAR_W * 4), y, hexTable[value & 15], fontColor, backColor);
688 	}
689 }
690 
setPrevStatusMessage(void)691 void setPrevStatusMessage(void)
692 {
693 	strcpy(ui.statusMessage, ui.prevStatusMessage);
694 	ui.updateStatusText = true;
695 }
696 
setStatusMessage(const char * msg,bool carry)697 void setStatusMessage(const char *msg, bool carry)
698 {
699 	assert(msg != NULL);
700 
701 	if (carry)
702 		strcpy(ui.prevStatusMessage, msg);
703 
704 	strcpy(ui.statusMessage, msg);
705 	ui.updateStatusText = true;
706 }
707 
displayMsg(const char * msg)708 void displayMsg(const char *msg)
709 {
710 	assert(msg != NULL);
711 
712 	editor.errorMsgActive = true;
713 	editor.errorMsgBlock = false;
714 	editor.errorMsgCounter = 0;
715 
716 	if (*msg != '\0')
717 		setStatusMessage(msg, NO_CARRY);
718 }
719 
displayErrorMsg(const char * msg)720 void displayErrorMsg(const char *msg)
721 {
722 	assert(msg != NULL);
723 
724 	editor.errorMsgActive = true;
725 	editor.errorMsgBlock = true;
726 	editor.errorMsgCounter = 0;
727 
728 	if (*msg != '\0')
729 		setStatusMessage(msg, NO_CARRY);
730 
731 	setErrPointer();
732 }
733