initial commit

This commit is contained in:
Sylvain PILLOT 2022-09-06 13:03:33 +02:00
commit 4e022826e6
8 changed files with 192 additions and 0 deletions

13
.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
# Build files
/build-fx
/build-cg
/*.g1a
/*.g3a
# Python bytecode
__pycache__/
# Common IDE files
*.sublime-project
*.sublime-workspace
.vscode

34
CMakeLists.txt Normal file
View File

@ -0,0 +1,34 @@
# Configure with [fxsdk build-fx] or [fxsdk build-cg], which provide the
# toolchain file and module path of the fxSDK
cmake_minimum_required(VERSION 3.15)
project(MyAddin)
include(GenerateG1A)
include(GenerateG3A)
include(Fxconv)
find_package(Gint 2.9 REQUIRED)
set(SOURCES
src/main.c
# ...
)
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
set(ASSETS
# ...
)
set(ASSETS_cg
assets-cg/ConsoleFont.png
# ...
)
fxconv_declare_assets(${ASSETS} ${ASSETS_cg} WITH_METADATA)
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
target_compile_options(myaddin PRIVATE -Wall -Wextra -Os)
target_link_libraries(myaddin Gint::Gint)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
generate_g3a(TARGET myaddin OUTPUT "Console.g3a"
NAME "Console" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
endif()

0
README.md Normal file
View File

BIN
assets-cg/ConsoleFont.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -0,0 +1,9 @@
ConsoleFont.png:
type: font
name: font88
charset: 256chars
grid.size: 8x8
grid.padding: 1
proportional: true
height: 8

BIN
assets-cg/icon-sel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
assets-cg/icon-uns.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

136
src/main.c Normal file
View File

@ -0,0 +1,136 @@
#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;
}