commit fd81a6a1f53ee9dc9310c2c39462fcb2f1ace506 Author: Babz Date: Tue Aug 31 15:52:53 2021 +0200 initial commit diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d7775ef --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +--- +BasedOnStyle: LLVM +AlignEscapedNewlines: Left +ColumnLimit: '130' +IndentWidth: '4' +NamespaceIndentation: All +SpacesInParentheses: 'false' +TabWidth: '4' + +... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e97b1a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vscode/ +build-cg/ +*.g1a +*.g3a \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fe915fa --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,86 @@ +# 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.18) +# replace this with your project's name +project(unshell C) + +include(GenerateG1A) +include(GenerateG3A) +include(Fxconv) +find_package(Gint 2.5 REQUIRED) + +# include directories, put your .h files in those folders +include_directories(include) + +# source files +set(SOURCES + src/main.c + src/term.c + # ... +) +# shared assets +set(ASSETS + # ... +) +# fx-9860G-only assets (monochrome) +set(ASSETS_fx + assets-fx/example.png + # ... +) +# fx-CG-50-only assets (polychrome) +set(ASSETS_cg + assets-cg/example.png + assets-cg/uf5x7 + # ... +) + +# Compile flags +set(FLAGS + # C standard, other values: c89, c99 + -std=c11 + + # general warnings + -Wall -Wextra -pedantic + + # enable this flag to stop compilation on warnings + #-Werror + + # specific warnings + # variable shadowing + -Wshadow + # switch/case safety + -Wswitch-default -Wswitch-enum + # unreachable code, bad 99% of the time + -Wunreachable-code + # prototypes warnings + -Wstrict-prototypes -Wmissing-prototypes + # function declaration + -Werror-implicit-function-declaration + + # optimisation level + # -Os: like -O2 without space-expensive optimizations + # -O2: good speed/size tradeoff + # -O3: gotta go fast + -Os +) + +fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA) + +add_executable(Main ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}}) +target_compile_options(Main PRIVATE ${FLAGS}) +target_link_libraries(Main Gint::Gint) + +if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) + generate_g1a( + TARGET Main + OUTPUT "${PROJECT_NAME}.g1a" + NAME "${PROJECT_NAME}" + ICON assets-fx/icon.png) +elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) + generate_g3a( + TARGET Main + OUTPUT "${PROJECT_NAME}.g3a" + NAME "${PROJECT_NAME}" + ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) +endif() diff --git a/assets-cg/example.png b/assets-cg/example.png new file mode 100755 index 0000000..8826800 Binary files /dev/null and b/assets-cg/example.png differ diff --git a/assets-cg/fxconv-metadata.txt b/assets-cg/fxconv-metadata.txt new file mode 100755 index 0000000..2d79a56 --- /dev/null +++ b/assets-cg/fxconv-metadata.txt @@ -0,0 +1,11 @@ +example.png: + type: bopti-image + name: img_example + +uf5x7: + type: font + name: uf5x7 + charset: unicode + grid.size: 5x7 + grid.padding: 1 + \ No newline at end of file diff --git a/assets-cg/icon-sel.png b/assets-cg/icon-sel.png new file mode 100755 index 0000000..7137b50 Binary files /dev/null and b/assets-cg/icon-sel.png differ diff --git a/assets-cg/icon-sel.png.bak b/assets-cg/icon-sel.png.bak new file mode 100755 index 0000000..7137b50 Binary files /dev/null and b/assets-cg/icon-sel.png.bak differ diff --git a/assets-cg/icon-uns.png b/assets-cg/icon-uns.png new file mode 100755 index 0000000..3c99f62 Binary files /dev/null and b/assets-cg/icon-uns.png differ diff --git a/assets-cg/icon-uns.png.bak b/assets-cg/icon-uns.png.bak new file mode 100755 index 0000000..3c99f62 Binary files /dev/null and b/assets-cg/icon-uns.png.bak differ diff --git a/assets-cg/uf5x7/U+0020.png b/assets-cg/uf5x7/U+0020.png new file mode 100644 index 0000000..45168db Binary files /dev/null and b/assets-cg/uf5x7/U+0020.png differ diff --git a/assets-cg/uf5x7/U+00A0.png b/assets-cg/uf5x7/U+00A0.png new file mode 100644 index 0000000..7c962fc Binary files /dev/null and b/assets-cg/uf5x7/U+00A0.png differ diff --git a/assets-cg/uf5x7/U+0100.png b/assets-cg/uf5x7/U+0100.png new file mode 100644 index 0000000..b360215 Binary files /dev/null and b/assets-cg/uf5x7/U+0100.png differ diff --git a/assets-cg/uf5x7/U+0370.png b/assets-cg/uf5x7/U+0370.png new file mode 100644 index 0000000..68a59a1 Binary files /dev/null and b/assets-cg/uf5x7/U+0370.png differ diff --git a/assets-cg/uf5x7/U+0400.png b/assets-cg/uf5x7/U+0400.png new file mode 100644 index 0000000..9afbaa5 Binary files /dev/null and b/assets-cg/uf5x7/U+0400.png differ diff --git a/assets-cg/uf5x7/U+16A0.png b/assets-cg/uf5x7/U+16A0.png new file mode 100755 index 0000000..3d515e2 Binary files /dev/null and b/assets-cg/uf5x7/U+16A0.png differ diff --git a/assets-cg/uf5x7/U+2010.png b/assets-cg/uf5x7/U+2010.png new file mode 100644 index 0000000..7467317 Binary files /dev/null and b/assets-cg/uf5x7/U+2010.png differ diff --git a/assets-cg/uf5x7/U+2070.png b/assets-cg/uf5x7/U+2070.png new file mode 100644 index 0000000..0402019 Binary files /dev/null and b/assets-cg/uf5x7/U+2070.png differ diff --git a/assets-cg/uf5x7/U+20A0.png b/assets-cg/uf5x7/U+20A0.png new file mode 100755 index 0000000..3e86140 Binary files /dev/null and b/assets-cg/uf5x7/U+20A0.png differ diff --git a/assets-cg/uf5x7/U+2160.png b/assets-cg/uf5x7/U+2160.png new file mode 100644 index 0000000..a2abcf3 Binary files /dev/null and b/assets-cg/uf5x7/U+2160.png differ diff --git a/assets-cg/uf5x7/U+2190.png b/assets-cg/uf5x7/U+2190.png new file mode 100644 index 0000000..c9b3406 Binary files /dev/null and b/assets-cg/uf5x7/U+2190.png differ diff --git a/assets-cg/uf5x7/U+2200.png b/assets-cg/uf5x7/U+2200.png new file mode 100644 index 0000000..759ddb4 Binary files /dev/null and b/assets-cg/uf5x7/U+2200.png differ diff --git a/assets-cg/uf5x7/U+2440.png b/assets-cg/uf5x7/U+2440.png new file mode 100755 index 0000000..664a478 Binary files /dev/null and b/assets-cg/uf5x7/U+2440.png differ diff --git a/assets-cg/uf5x7/U+25A0.png b/assets-cg/uf5x7/U+25A0.png new file mode 100644 index 0000000..6f771db Binary files /dev/null and b/assets-cg/uf5x7/U+25A0.png differ diff --git a/assets-cg/uf5x7/U+2800.png b/assets-cg/uf5x7/U+2800.png new file mode 100644 index 0000000..863c85b Binary files /dev/null and b/assets-cg/uf5x7/U+2800.png differ diff --git a/assets-cg/uf5x7/U+3000.png b/assets-cg/uf5x7/U+3000.png new file mode 100755 index 0000000..54d003d Binary files /dev/null and b/assets-cg/uf5x7/U+3000.png differ diff --git a/assets-cg/uf5x7/U+3040.png b/assets-cg/uf5x7/U+3040.png new file mode 100644 index 0000000..32c303c Binary files /dev/null and b/assets-cg/uf5x7/U+3040.png differ diff --git a/assets-cg/uf5x7/U+30A0.png b/assets-cg/uf5x7/U+30A0.png new file mode 100644 index 0000000..4f74a3f Binary files /dev/null and b/assets-cg/uf5x7/U+30A0.png differ diff --git a/assets-cg/uf5x7/extra.png b/assets-cg/uf5x7/extra.png new file mode 100644 index 0000000..897c900 Binary files /dev/null and b/assets-cg/uf5x7/extra.png differ diff --git a/assets-fx/example.png b/assets-fx/example.png new file mode 100755 index 0000000..b26ba9a Binary files /dev/null and b/assets-fx/example.png differ diff --git a/assets-fx/fxconv-metadata.txt b/assets-fx/fxconv-metadata.txt new file mode 100755 index 0000000..d435d5f --- /dev/null +++ b/assets-fx/fxconv-metadata.txt @@ -0,0 +1,3 @@ +example.png: + type: bopti-image + name: img_example diff --git a/assets-fx/icon.png b/assets-fx/icon.png new file mode 100755 index 0000000..c92f12a Binary files /dev/null and b/assets-fx/icon.png differ diff --git a/makefile b/makefile new file mode 100644 index 0000000..0c81bc5 --- /dev/null +++ b/makefile @@ -0,0 +1,14 @@ +all: + fxsdk build-cg + fxlink -s -w60 -f 'mass_storage;series_cg' *.g3a + +clean: + rm -rf *.g1a *.g3a build/ build-fx/ build-cg/ + +format: + find src/ -name *.[c,h] -exec clang-format --verbose -i {} \; + +# aliases +build: all +rebuild: clean build +tidy: format \ No newline at end of file diff --git a/src/.main.c.swp b/src/.main.c.swp new file mode 100755 index 0000000..a18bbad Binary files /dev/null and b/src/.main.c.swp differ diff --git a/src/.vscode/c_cpp_properties.json b/src/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b8772b7 --- /dev/null +++ b/src/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/home/adraenwan/.local/share/giteapc/**" + ], + "defines": [], + "compilerPath": "/usr/bin/clang++", + "cStandard": "c11", + "cppStandard": "c++11", + "intelliSenseMode": "linux-clang-x64", + "browse": { + "path": [] + } + } + ], + "version": 4 +} \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..b7aa5da --- /dev/null +++ b/src/main.c @@ -0,0 +1,68 @@ +#include +#include + +#include "term.h" +#include + +#include +#include + +static char *LOREM_IPSUM = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vitae purus dolor. Praesent in ex tempus, auctor velit at, " + "vulputate sapien. Aenean semper, dui vitae iaculis mattis, odio libero aliquet elit, nec tempor nisl turpis vel arcu. " + "Vestibulum eleifend maximus enim at sollicitudin. Nulla eu commodo justo. Ut vitae pellentesque erat. Duis magna nisl, " + "eleifend ac massa at, blandit sollicitudin ipsum. Interdum et malesuada fames ac ante ipsum primis in faucibus. " + "Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut at libero in turpis porttitor " + "viverra. Ut eu pellentesque purus. Vestibulum aliquet facilisis ante, eget volutpat metus. Cras semper lacus ac mauris " + "imperdiet, vel egestas est luctus. Aliquam elit enim, dignissim nec enim vel, consequat ullamcorper libero. Pellentesque at " + "iaculis lctus. Praesent sed velit at tellus hendrerit mattis eu nec velit. Phasellus eu quam nec nisi mattis elementum quis " + "nec enim. Nulla efficitur turpis id tempus ultricies. Pellentesque semper lacinia mi vitae feugiat. Vestibulum leo nisi, " + "pretium quis felis non, mattis varius risus. " + "Suspendisse porttitor purus lacinia ante euismod, ut eleifend massa fermentum. Proin pretium elementum massa, at efficitur " + "risus iaculis sed. Nulla nec elit posuere, ultrices arcu at, porttitor turpis. Nulla purus tellus, interdum vel venenatis " + "a, tristique sed sapien. Donec at lacus dui. Cras vel nulla quis est suscipit semper quis ut risus. Ut tristique tempor " + "varius. " + "Donec dignissim ullamcorper tortor, nec pharetra velit venenatis sit amet. Sed maximus accumsan risus, sit amet " + "pellentesque sapien bibendum vel. Sed vel odio at mauris sagittis elementum viverra a diam. Vivamus turpis risus, semper ut " + "nulla at, efficitur viverra nulla. Nunc eget est imperdiet, consectetur mi a, hendrerit dui. Proin ut urna hendrerit justo " + "mollis tincidunt. Vestibulum ac commodo metus. Praesent nec mi a libero varius faucibus eleifend iaculis ligula. Phasellus " + "sed purus magna. Suspendisse sed nisl purus. Duis commodo pellentesque tempor. Quisque varius accumsan nunc. " + "Aliquam sodales cursus magna ac varius. Cras id enim eu neque euismod egestas quis eu lectus. Sed condimentum convallis " + "aliquam. Fusce leo elit, consectetur ac molestie in, dapibus et tortor. Nulla sapien purus, tempor sed lacus in, pretium " + "luctus libero. Aliquam pretium dapibus ligula, ac vestibulum nisi sollicitudin at. Mauris eu leo laoreet arcu viverra " + "lacinia."; + +static volatile int key_poll_timeout; +static int tick_ctr = 0; +static int callback_keypoll(void) { + key_poll_timeout = 0; + return TIMER_STOP; +} + +char statusbar_up[UNS_TERM_COLS + 1]; +char statusbar_down[UNS_TERM_COLS + 1]; + +int main(void) { + const int timer = timer_configure(TIMER_ANY, 64, GINT_CALL(callback_keypoll)); + + while (1) { + // set green bar + for (int i = 0; i < UNS_TERM_COLS; i++) + tgrid_sets(0, i, C_BLACK, C_GREEN, " "); + + // then add acutal text + sprintf(statusbar_up, "↑Aa %d", tick_ctr); + tgrid_sets(0, 0, C_BLACK, C_GREEN, statusbar_up); + + tgrid_sets(1, 0, C_WHITE, C_BLACK, LOREM_IPSUM); + tgrid_display(); + + key_poll_timeout = 1; + timer_start(timer); + key_event_t kev = getkey_opt(GETKEY_DEFAULT, &key_poll_timeout); + if (kev.type != KEYEV_NONE) + tick_ctr++; + } + + return 1; +} \ No newline at end of file diff --git a/src/term.c b/src/term.c new file mode 100644 index 0000000..73bec89 --- /dev/null +++ b/src/term.c @@ -0,0 +1,89 @@ +#include "term.h" + +#include +#include + +extern font_t uf5x7; + +struct tcell { + char chr[4]; + int fg; + int bg; +}; + +static struct tcell tgrid[UNS_TERM_ROWS][UNS_TERM_COLS]; + +static void tgrid_set(int row, int col, int fg, int bg, char c[4]) { + tgrid[row][col].chr[0] = c[0]; + tgrid[row][col].chr[1] = c[1]; + tgrid[row][col].chr[2] = c[2]; + tgrid[row][col].chr[3] = c[3]; + tgrid[row][col].fg = fg; + tgrid[row][col].bg = bg; +} + +void tgrid_sets(int row, int col, int fg, int bg, const char *s) { + int _row = row; + int _col = col; + + for (int i = 0; s[i] != '\0';) { + if (_col >= UNS_TERM_COLS) { + _col = col; + _row++; + } + + // boundary check + if (_row >= UNS_TERM_ROWS) + return; + + // detech utf-8 char length + unsigned char lb = s[i]; + int charlen = 0; + if ((lb & 0x80) == 0) // lead bit is zero, must be a single ascii + charlen = 1; + else if ((lb & 0xE0) == 0xC0) // 110x xxxx + charlen = 2; + else if ((lb & 0xF0) == 0xE0) // 1110 xxxx + charlen = 3; + else if ((lb & 0xF8) == 0xF0) // 1111 0xxx + charlen = 4; + + char unichar[4] = ""; + for (int j = 0; j < charlen; j++) + unichar[j] = s[i + j]; + + tgrid_set(_row, _col, fg, bg, unichar); + + _col++; + i += charlen; + } +} + +void tgrid_display(void) { + dclear(C_BLACK); + dfont(&uf5x7); + + int y = 3; + for (int row = 0; row < UNS_TERM_ROWS; row++) { + int x = 2; + for (int col = 0; col < UNS_TERM_COLS; col++) { + struct tcell cell = tgrid[row][col]; + + char buf[5]; + buf[0] = cell.chr[0]; + buf[1] = cell.chr[1]; + buf[2] = cell.chr[2]; + buf[3] = cell.chr[3]; + buf[4] = '0'; + + drect(x - 1, y - 1, x + 6, y + 8, cell.bg); + dtext_opt(x, y, cell.fg, C_NONE, DTEXT_LEFT, DTEXT_TOP, (char *)&buf, -1); + + x += 1 + 5; + } + + y += 1 + 7 + 2; + } + + dupdate(); +} \ No newline at end of file diff --git a/src/term.h b/src/term.h new file mode 100644 index 0000000..c8603f3 --- /dev/null +++ b/src/term.h @@ -0,0 +1,10 @@ +#ifndef UNS_TERM_H +#define UNS_TERM_H + +#define UNS_TERM_ROWS 22 +#define UNS_TERM_COLS 65 + +void tgrid_sets(int row, int col, int fg, int bg, const char *s); +void tgrid_display(void); + +#endif // #ifndef UNS_TERM_H \ No newline at end of file