initial commit

This commit is contained in:
Babz 2021-08-31 15:52:53 +02:00
commit fd81a6a1f5
37 changed files with 315 additions and 0 deletions

10
.clang-format Normal file
View File

@ -0,0 +1,10 @@
---
BasedOnStyle: LLVM
AlignEscapedNewlines: Left
ColumnLimit: '130'
IndentWidth: '4'
NamespaceIndentation: All
SpacesInParentheses: 'false'
TabWidth: '4'
...

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.vscode/
build-cg/
*.g1a
*.g3a

86
CMakeLists.txt Normal file
View File

@ -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()

BIN
assets-cg/example.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

11
assets-cg/fxconv-metadata.txt Executable file
View File

@ -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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
assets-cg/icon-sel.png.bak Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
assets-cg/icon-uns.png.bak Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
assets-cg/uf5x7/U+0020.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets-cg/uf5x7/U+00A0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
assets-cg/uf5x7/U+0100.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
assets-cg/uf5x7/U+0370.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
assets-cg/uf5x7/U+0400.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
assets-cg/uf5x7/U+16A0.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
assets-cg/uf5x7/U+2010.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets-cg/uf5x7/U+2070.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

BIN
assets-cg/uf5x7/U+20A0.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

BIN
assets-cg/uf5x7/U+2160.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

BIN
assets-cg/uf5x7/U+2190.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
assets-cg/uf5x7/U+2200.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
assets-cg/uf5x7/U+2440.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

BIN
assets-cg/uf5x7/U+25A0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
assets-cg/uf5x7/U+2800.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
assets-cg/uf5x7/U+3000.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

BIN
assets-cg/uf5x7/U+3040.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
assets-cg/uf5x7/U+30A0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
assets-cg/uf5x7/extra.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
assets-fx/example.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

3
assets-fx/fxconv-metadata.txt Executable file
View File

@ -0,0 +1,3 @@
example.png:
type: bopti-image
name: img_example

BIN
assets-fx/icon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

14
makefile Normal file
View File

@ -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

BIN
src/.main.c.swp Executable file

Binary file not shown.

20
src/.vscode/c_cpp_properties.json vendored Normal file
View File

@ -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
}

68
src/main.c Normal file
View File

@ -0,0 +1,68 @@
#include <gint/keyboard.h>
#include <gint/timer.h>
#include "term.h"
#include <gint/display.h>
#include <stdio.h>
#include <string.h>
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;
}

89
src/term.c Normal file
View File

@ -0,0 +1,89 @@
#include "term.h"
#include <gint/display.h>
#include <stdio.h>
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();
}

10
src/term.h Normal file
View File

@ -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