137 lines
3.0 KiB
C
137 lines
3.0 KiB
C
#include <gint/display.h>
|
|
#include <gint/keyboard.h>
|
|
|
|
extern font_t font88;
|
|
|
|
#define MAX_X_GLYPHS 49
|
|
#define MAX_Y_GLYPHS 28
|
|
#define MAX_LINE_HISTORY 100
|
|
|
|
|
|
typedef struct
|
|
{
|
|
char myChar;
|
|
char myColor;
|
|
} ConsoleGlyph;
|
|
|
|
ConsoleGlyph myConsoleScreen[MAX_X_GLYPHS * (MAX_Y_GLYPHS + MAX_LINE_HISTORY)] = {0};
|
|
|
|
ConsoleGlyph *visibleScreen;
|
|
uint8_t CursorX = 0;
|
|
uint8_t CursorY = 0;
|
|
uint8_t ScrollLineValue = 0;
|
|
|
|
void InitConsole( void )
|
|
{
|
|
visibleScreen = myConsoleScreen;
|
|
}
|
|
|
|
void ScrollToLine( uint8_t targetLine )
|
|
{
|
|
if (targetLine < MAX_LINE_HISTORY )
|
|
{
|
|
ScrollLineValue = targetLine;
|
|
visibleScreen = &myConsoleScreen[MAX_X_GLYPHS*targetLine];
|
|
}
|
|
}
|
|
|
|
void PrintChar( uint8_t X, uint8_t Y, char c, char color )
|
|
{
|
|
if(X<MAX_X_GLYPHS && Y<MAX_Y_GLYPHS)
|
|
{
|
|
visibleScreen[MAX_X_GLYPHS*Y+X].myChar = c;
|
|
visibleScreen[MAX_X_GLYPHS*Y+X].myColor = color;
|
|
}
|
|
}
|
|
|
|
void PrintString( uint8_t X, uint8_t Y, char *str, char color )
|
|
{
|
|
if(X<MAX_X_GLYPHS && Y<MAX_Y_GLYPHS && str[0]!=0 && str!=NULL)
|
|
{
|
|
char temp;
|
|
uint8_t i = 0;
|
|
uint8_t Xi = X;
|
|
uint8_t Yi = Y;
|
|
|
|
for(;;)
|
|
{
|
|
temp = str[i];
|
|
|
|
if (Xi>=MAX_X_GLYPHS)
|
|
{
|
|
Xi -= MAX_X_GLYPHS;
|
|
Yi++;
|
|
}
|
|
|
|
visibleScreen[MAX_X_GLYPHS*Yi+Xi].myChar = temp;
|
|
visibleScreen[MAX_X_GLYPHS*Yi+Xi].myColor = color;
|
|
|
|
i++;
|
|
if(str[i]==0) break;
|
|
|
|
Xi++;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void RenderConsole( void )
|
|
{
|
|
uint16_t colorGint;
|
|
|
|
ConsoleGlyph *tempGlyph; //= &visibleScreen[MAX_X_GLYPHS*y+x];
|
|
|
|
for(int y=0; y<MAX_Y_GLYPHS; y++)
|
|
for(int x=0; x<MAX_X_GLYPHS; x++)
|
|
{
|
|
tempGlyph = &visibleScreen[MAX_X_GLYPHS*y+x];
|
|
if(tempGlyph->myChar != 0x00)
|
|
{
|
|
if(tempGlyph->myColor == 0) colorGint = C_BLACK;
|
|
else if(tempGlyph->myColor == 1) colorGint = C_BLUE;
|
|
else if(tempGlyph->myColor == 2) colorGint = C_RED;
|
|
else if(tempGlyph->myColor == 3) colorGint = C_GREEN;
|
|
else if(tempGlyph->myColor == 4) colorGint = C_WHITE;
|
|
else colorGint = C_BLACK;
|
|
|
|
dprint(2+x*8, y*8, colorGint, "%lc", tempGlyph->myChar );
|
|
}
|
|
}
|
|
|
|
dupdate();
|
|
}
|
|
|
|
|
|
int main(void)
|
|
{
|
|
dfont(&font88);
|
|
dclear(C_WHITE);
|
|
|
|
/*
|
|
unsigned char temp = 0;
|
|
|
|
for(int y=0; y<MAX_Y_GLYPHS; y++)
|
|
for(int x=0; x<MAX_X_GLYPHS; x++)
|
|
{
|
|
dprint(2+x*8, y*8, C_BLACK, "%lc", temp );
|
|
|
|
temp++;
|
|
temp=temp % 0xFF;
|
|
}
|
|
|
|
dupdate();
|
|
*/
|
|
|
|
char maChaine[] = "Testing long chain of characters with length superior to the width of the screen console and hence needing rendering over several lines on the screen. I enjoy so much long chains. It looks like I enjoy speaking !!!";
|
|
|
|
InitConsole();
|
|
PrintChar( 10, 10, '0', 3 );
|
|
PrintString( 11, 11, maChaine, 2 );
|
|
RenderConsole();
|
|
|
|
|
|
getkey();
|
|
return 1;
|
|
}
|