Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
text.h
Go to the documentation of this file.
1
2
3/*
4 * text.h
5 *
6* Created on: Feb 19, 2022
7 * Author: micahbly
8 */
9
10#ifndef LIB_TEXT_H_
11#define LIB_TEXT_H_
12
13
14/* about this library: TextDisplay
15 *
16 * This handles writing and reading information to/from the VICKY's text mode memory
17 *
18 *** things this library needs to be able to do
19 * work with either channel A or channel B
20 * clear / fill an entire screen of text characters
21 * clear / fill an entire screen of text attributes
22 * invert the colors of a screen
23 * clear / fill a smaller-than-screen rectangular area of text/attrs
24 * Draw a char to a specified x, y coord
25 * Get the currently displayed character at the specified coord
26 * Set the foreground and background colors at the specified coord
27 * Set the attribute value at the specified coord
28 * Get the attribute value at the specified coord
29 * Get the foreground or background color at the specified coord
30 * draw a line using "graphic" characters
31 * draw a box using "graphic" characters
32 * copy a full screen of text or attr from an off-screen buffer
33 * copy a full screen of text or attr TO an off-screen buffer
34 * copy a full screen of text and attr between channel A and B
35 * copy a rectangular area of text or attr TO/FROM an off-screen buffer
36 * display a string at a specified x, y coord (no wrap)
37 * display a pre-formatted string in a rectangular block on the screen, breaking on \n characters
38 * display a string in a rectangular block on the screen, with wrap
39 * display a string in a rectangular block on the screen, with wrap, taking a hook for a "display more" event, and scrolling text vertically up after hook func returns 'continue' (or exit, returning control to calling func, if hook returns 'stop')
40 * replace current text font with another, loading from specified ram loc.
41 */
42
43
44/*****************************************************************************/
45/* Includes */
46/*****************************************************************************/
47
48// project includes
49#include "general.h"
50
51// C includes
52#include <stdbool.h>
53
54// A2560 includes
55#include "a2560k.h"
56
57
58/*****************************************************************************/
59/* Macro Definitions */
60/*****************************************************************************/
61
62#define SCREEN_FOR_TEXT_ATTR true
63#define SCREEN_FOR_TEXT_CHAR false // param for functions with for_attr
64
65#define SCREEN_COPY_TO_SCREEN true // param for functions doing block copy to/from screen / off-screen buffer
66#define SCREEN_COPY_FROM_SCREEN false // param for functions doing block copy to/from screen / off-screen buffer
67
68// based on observations in f68 with names matched to ANSI colors
69// https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
70#define COLOR_BLACK (unsigned char)0x00
71#define COLOR_RED (unsigned char)0x01
72#define COLOR_GREEN (unsigned char)0x02
73#define COLOR_YELLOW (unsigned char)0x03
74#define COLOR_BLUE (unsigned char)0x04
75#define COLOR_MAGENTA (unsigned char)0x05
76#define COLOR_CYAN (unsigned char)0x06
77#define COLOR_WHITE (unsigned char)0x07
78#define COLOR_GRAY (unsigned char)0x08
79#define COLOR_BRIGHT_RED (unsigned char)0x09
80#define COLOR_BRIGHT_GREEN (unsigned char)0x0A
81#define COLOR_BRIGHT_YELLOW (unsigned char)0x0B
82#define COLOR_BRIGHT_BLUE (unsigned char)0x0C
83#define COLOR_BRIGHT_MAGENTA (unsigned char)0x0D
84#define COLOR_BRIGHT_CYAN (unsigned char)0x0E
85#define COLOR_BRIGHT_WHITE (unsigned char)0x0F
86
87// I believe foreground and background colors can be defined differently, but from testing on morfe, they seem to be the same at least by default.
88#define FG_COLOR_BLACK (unsigned char)0x00
89#define FG_COLOR_RED (unsigned char)0x01
90#define FG_COLOR_GREEN (unsigned char)0x02
91#define FG_COLOR_YELLOW (unsigned char)0x03
92#define FG_COLOR_BLUE (unsigned char)0x04
93#define FG_COLOR_MAGENTA (unsigned char)0x05
94#define FG_COLOR_CYAN (unsigned char)0x06
95#define FG_COLOR_WHITE (unsigned char)0x07
96#define FG_COLOR_GRAY (unsigned char)0x08
97#define FG_COLOR_BRIGHT_RED (unsigned char)0x09
98#define FG_COLOR_BRIGHT_GREEN (unsigned char)0x0A
99#define FG_COLOR_BRIGHT_YELLOW (unsigned char)0x0B
100#define FG_COLOR_BRIGHT_BLUE (unsigned char)0x0C
101#define FG_COLOR_BRIGHT_MAGENTA (unsigned char)0x0D
102#define FG_COLOR_BRIGHT_CYAN (unsigned char)0x0E
103#define FG_COLOR_BRIGHT_WHITE (unsigned char)0x0F
104
105#define BG_COLOR_BLACK (unsigned char)0x00
106#define BG_COLOR_RED (unsigned char)0x01
107#define BG_COLOR_GREEN (unsigned char)0x02
108#define BG_COLOR_YELLOW (unsigned char)0x03
109#define BG_COLOR_BLUE (unsigned char)0x04
110#define BG_COLOR_MAGENTA (unsigned char)0x05
111#define BG_COLOR_CYAN (unsigned char)0x06
112#define BG_COLOR_WHITE (unsigned char)0x07
113#define BG_COLOR_GRAY (unsigned char)0x08
114#define BG_COLOR_BRIGHT_RED (unsigned char)0x09
115#define BG_COLOR_BRIGHT_GREEN (unsigned char)0x0A
116#define BG_COLOR_BRIGHT_YELLOW (unsigned char)0x0B
117#define BG_COLOR_BRIGHT_BLUE (unsigned char)0x0C
118#define BG_COLOR_BRIGHT_MAGENTA (unsigned char)0x0D
119#define BG_COLOR_BRIGHT_CYAN (unsigned char)0x0E
120#define BG_COLOR_BRIGHT_WHITE (unsigned char)0x0F
121
122// update: the numbers shown in vicky2 file in morfe don't match up to what's shown on screen, at least with a2560 config. eg, 20/00/00 is not a super dark blue, it's some totally bright thing. need to spend some time mapping these out better. But since user configurable, will wait until real machine comes and I can make sure of what's in flash rom.
123
124
125
126/*****************************************************************************/
127/* Enumerations */
128/*****************************************************************************/
129
130typedef enum text_draw_choice
131{
132 CHAR_ONLY = 0,
133 ATTR_ONLY = 1,
134 CHAR_AND_ATTR = 2,
135} text_draw_choice;
136
137
138/*****************************************************************************/
139/* Structs */
140/*****************************************************************************/
141
142
143/*****************************************************************************/
144/* Global Variables */
145/*****************************************************************************/
146
147
148/*****************************************************************************/
149/* Public Function Prototypes */
150/*****************************************************************************/
151
152
153// ** NOTE: there is no destructor or constructor for this library, as it does not track any allocated memory.
154
155// **** WORD-WRAP UTILITIES *****
156
157// Find the next space, dash, or other word break character and return its position within the string. If none found before end of string or max len, returns -1.
158int16_t General_StrFindNextWordEnd(const char* the_string, int16_t max_search_len);
159
160// Find the next line break character and return its position within the string (+1: first char is '1'). If none found before end of string or max len, returns 0.
161int16_t General_StrFindNextLineBreak(const char* the_string, int16_t max_search_len);
162
175int16_t General_WrapAndTrimTextToFit(char** orig_string, char** formatted_string, int16_t max_chars_to_format, int16_t max_width, int16_t max_height, int16_t one_char_width, int16_t one_row_height, Font* the_font, int16_t (* measure_function)(Font*, char*, int16_t, int16_t, int16_t, int16_t*));
176
177
178// **** Block copy functions ****
179
184bool Text_CopyAttrMemToScreen(Screen* the_screen, char* the_source_buffer);
185
190bool Text_CopyAttrMemFromScreen(Screen* the_screen, char* the_target_buffer);
191
196bool Text_CopyCharMemToScreen(Screen* the_screen, char* the_source_buffer);
197
202bool Text_CopyCharMemFromScreen(Screen* the_screen, char* the_target_buffer);
203
210bool Text_CopyScreen(Screen* the_screen, char* the_buffer, bool to_screen, bool for_attr);
211
222bool Text_CopyMemBox(Screen* the_screen, char* the_buffer, int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool to_screen, bool for_attr);
223
224
225// **** Block fill functions ****
226
227
229void Text_ClearScreen(Screen* the_screen, uint8_t fore_color, uint8_t back_color);
230
236bool Text_FillAttrMemForeBack(Screen* the_screen, uint8_t fore_color, uint8_t back_color);
237
242bool Text_FillAttrMem(Screen* the_screen, uint8_t the_fill);
243
248bool Text_FillCharMem(Screen* the_screen, unsigned char the_fill);
249
262bool Text_FillBoxSlow(Screen* the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice);
263
274bool Text_FillBox(Screen* the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, unsigned char the_char, uint8_t fore_color, uint8_t back_color);
275
284bool Text_FillBoxCharOnly(Screen* the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, unsigned char the_char);
285
295bool Text_FillBoxAttrOnly(Screen* the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t fore_color, uint8_t back_color);
296
305bool Text_InvertBox(Screen* the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
306
307
308
309
310// **** FONT RELATED *****
311
312
317bool Text_UpdateFontData(Screen* the_screen, char* new_font_data);
318
324bool Text_ShowFontChars(Screen* the_screen, int16_t y);
325
326
327
328
329// **** Set char/attr functions *****
330
331
338bool Text_SetCharAtXY(Screen* the_screen, int16_t x, int16_t y, unsigned char the_char);
339
346bool Text_SetAttrAtXY(Screen* the_screen, int16_t x, int16_t y, uint8_t the_attribute_value);
347
355bool Text_SetColorAtXY(Screen* the_screen, int16_t x, int16_t y, uint8_t fore_color, uint8_t back_color);
356
365bool Text_SetCharAndColorAtXY(Screen* the_screen, int16_t x, int16_t y, unsigned char the_char, uint8_t fore_color, uint8_t back_color);
366
367
368
369
370// **** Get char/attr functions *****
371
372
378unsigned char Text_GetCharAtXY(Screen* the_screen, int16_t x, int16_t y);
379
385uint8_t Text_GetAttrAtXY(Screen* the_screen, int16_t x, int16_t y);
386
392uint8_t Text_GetForeColorAtXY(Screen* the_screen, int16_t x, int16_t y);
393
399uint8_t Text_GetBackColorAtXY(Screen* the_screen, int16_t x, int16_t y);
400
401
402
403// **** Drawing functions *****
404
405
416bool Text_DrawHLine(Screen* the_screen, int16_t x, int16_t y, int16_t the_line_len, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice);
417
429bool Text_DrawHLineSlow(Screen* the_screen, int16_t x, int16_t y, int16_t the_line_len, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice);
430
441bool Text_DrawVLine(Screen* the_screen, int16_t x, int16_t y, int16_t the_line_len, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice);
442
454bool Text_DrawBoxCoords(Screen* the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice);
455
465bool Text_DrawBoxCoordsFancy(Screen* the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t fore_color, uint8_t back_color);
466
478bool Text_DrawBox(Screen* the_screen, int16_t x, int16_t y, int16_t width, int16_t height, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice);
479
480
481
482// **** Draw string functions *****
483
484
495bool Text_DrawStringAtXY(Screen* the_screen, int16_t x, int16_t y, char* the_string, uint8_t fore_color, uint8_t back_color);
496
510char* Text_DrawStringInBox(Screen* the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, char* the_string, char** work_buffer, uint8_t fore_color, uint8_t back_color, bool (* continue_function)(void));
511
521int16_t Text_MeasureStringWidth(Font* the_font, char* the_string, int16_t num_chars, int16_t available_width, int16_t fixed_char_width, int16_t* measured_width);
522
523
524
525// **** Plotting functions ****
526
532char* Text_GetMemLocForXY(Screen* the_screen, int16_t x, int16_t y, bool for_attr);
533
535uint8_t Text_CalculateAttributeValue(uint8_t fore_color, uint8_t back_color);
536
537
538
539#endif /* LIB_TEXT_H_ */
This Font object is essentially the Mac "fontRecord" struct, with added pointers for the data tables.
Definition: font.h:71
Definition: a2560k.h:1375
bool Text_ShowFontChars(Screen *the_screen, int16_t y)
Test function to display all 256 font characters.
Definition: text.c:1211
bool Text_DrawStringAtXY(Screen *the_screen, int16_t x, int16_t y, char *the_string, uint8_t fore_color, uint8_t back_color)
Draw a string at a specified x, y coord, also setting the color attributes.
Definition: text.c:1890
bool Text_SetCharAndColorAtXY(Screen *the_screen, int16_t x, int16_t y, unsigned char the_char, uint8_t fore_color, uint8_t back_color)
Draw a char at a specified x, y coord, also setting the color attributes.
Definition: text.c:1336
bool Text_CopyMemBox(Screen *the_screen, char *the_buffer, int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool to_screen, bool for_attr)
Copy a rectangular area of text or attr to or from an off-screen buffer.
Definition: text.c:762
bool Text_DrawBoxCoords(Screen *the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice)
Draws a basic box based on 2 sets of coords, using the specified char and/or attribute for all cells.
Definition: text.c:1674
char * Text_DrawStringInBox(Screen *the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, char *the_string, char **work_buffer, uint8_t fore_color, uint8_t back_color, bool(*continue_function)(void))
Draw a string in a rectangular block on the screen, with wrap.
Definition: text.c:1953
bool Text_DrawHLine(Screen *the_screen, int16_t x, int16_t y, int16_t the_line_len, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice)
Draws a horizontal line from specified coords, for n characters, using the specified char and/or attr...
Definition: text.c:1506
unsigned char Text_GetCharAtXY(Screen *the_screen, int16_t x, int16_t y)
Get the char at a specified x, y coord.
Definition: text.c:1377
uint8_t Text_CalculateAttributeValue(uint8_t fore_color, uint8_t back_color)
Calculate the combined text attribute value for a given foreground/background combination.
Definition: text.c:2200
bool Text_DrawVLine(Screen *the_screen, int16_t x, int16_t y, int16_t the_line_len, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice)
Draws a vertical line from specified coords, for n characters, using the specified char and/or attrib...
Definition: text.c:1618
void Text_ClearScreen(Screen *the_screen, uint8_t fore_color, uint8_t back_color)
Clear the text screen and reset foreground and background colors.
Definition: text.c:838
bool Text_FillAttrMemForeBack(Screen *the_screen, uint8_t fore_color, uint8_t back_color)
Fill the entire attribute memory of the passed screen with the specified fore- and back-color.
Definition: text.c:862
bool Text_DrawBoxCoordsFancy(Screen *the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t fore_color, uint8_t back_color)
Draws a box based on 2 sets of coords, using the predetermined line and corner "graphics",...
Definition: text.c:1746
bool Text_CopyAttrMemFromScreen(Screen *the_screen, char *the_target_buffer)
Copy a full screen of text attributes to an off-screen buffer.
Definition: text.c:638
bool Text_DrawHLineSlow(Screen *the_screen, int16_t x, int16_t y, int16_t the_line_len, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice)
Draws a horizontal line from specified coords, for n characters, using the specified char and/or attr...
Definition: text.c:1563
bool Text_UpdateFontData(Screen *the_screen, char *new_font_data)
replace the current font data with the data at the passed memory buffer
Definition: text.c:1186
bool Text_SetAttrAtXY(Screen *the_screen, int16_t x, int16_t y, uint8_t the_attribute_value)
Set the attribute value at a specified x, y coord.
Definition: text.c:1280
bool Text_FillBoxAttrOnly(Screen *the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t fore_color, uint8_t back_color)
Fill attribute memory for a specific box area.
Definition: text.c:1070
bool Text_InvertBox(Screen *the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
Invert the colors of a rectangular block.
Definition: text.c:1121
uint8_t Text_GetBackColorAtXY(Screen *the_screen, int16_t x, int16_t y)
Get the background color at a specified x, y coord.
Definition: text.c:1466
bool Text_SetColorAtXY(Screen *the_screen, int16_t x, int16_t y, uint8_t fore_color, uint8_t back_color)
Set the attribute value at a specified x, y coord based on the foreground and background colors passe...
Definition: text.c:1310
uint8_t Text_GetAttrAtXY(Screen *the_screen, int16_t x, int16_t y)
Get the attribute value at a specified x, y coord.
Definition: text.c:1406
bool Text_FillBoxSlow(Screen *the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice)
Fill a box-shaped section of character and/or attribute memory This version uses char-by-char functio...
Definition: text.c:918
bool Text_CopyCharMemFromScreen(Screen *the_screen, char *the_target_buffer)
Copy a full screen of text to an off-screen buffer.
Definition: text.c:684
uint8_t Text_GetForeColorAtXY(Screen *the_screen, int16_t x, int16_t y)
Get the foreground color at a specified x, y coord.
Definition: text.c:1435
int16_t General_WrapAndTrimTextToFit(char **orig_string, char **formatted_string, int16_t max_chars_to_format, int16_t max_width, int16_t max_height, int16_t one_char_width, int16_t one_row_height, Font *the_font, int16_t(*measure_function)(Font *, char *, int16_t, int16_t, int16_t, int16_t *))
Format a string by wrapping and trimming to fit the passed width and height.
Definition: text.c:517
bool Text_SetCharAtXY(Screen *the_screen, int16_t x, int16_t y, unsigned char the_char)
Set a char at a specified x, y coord.
Definition: text.c:1251
bool Text_CopyScreen(Screen *the_screen, char *the_buffer, bool to_screen, bool for_attr)
Copy a full screen worth of EITHER text or attribute data to OR from an off-screen buffer.
Definition: text.c:710
bool Text_DrawBox(Screen *the_screen, int16_t x, int16_t y, int16_t width, int16_t height, unsigned char the_char, uint8_t fore_color, uint8_t back_color, text_draw_choice the_draw_choice)
Draws a basic box based on start coords and width/height, using the specified char and/or attribute f...
Definition: text.c:1828
int16_t Text_MeasureStringWidth(Font *the_font, char *the_string, int16_t num_chars, int16_t available_width, int16_t fixed_char_width, int16_t *measured_width)
Calculates how many characters of the passed string will fit into the passed pixel width.
Definition: text.c:2128
bool Text_CopyAttrMemToScreen(Screen *the_screen, char *the_source_buffer)
Copy a full screen of attr from an off-screen buffer.
Definition: text.c:615
bool Text_FillBox(Screen *the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, unsigned char the_char, uint8_t fore_color, uint8_t back_color)
Fill character and attribute memory for a specific box area.
Definition: text.c:972
bool Text_FillBoxCharOnly(Screen *the_screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, unsigned char the_char)
Fill character memory for a specific box area.
Definition: text.c:1023
bool Text_FillCharMem(Screen *the_screen, unsigned char the_fill)
Fill the entire character memory of the passed screen.
Definition: text.c:894
char * Text_GetMemLocForXY(Screen *the_screen, int16_t x, int16_t y, bool for_attr)
Calculate the VRAM location of the specified coordinate.
Definition: text.c:2176
bool Text_CopyCharMemToScreen(Screen *the_screen, char *the_source_buffer)
Copy a full screen of text from an off-screen buffer.
Definition: text.c:661
bool Text_FillAttrMem(Screen *the_screen, uint8_t the_fill)
Fill the entire attribute memory of the passed screen.
Definition: text.c:878