From 56831200e76c337df70f25bb0a788d5d7e22071d Mon Sep 17 00:00:00 2001 From: milang Date: Fri, 20 Sep 2019 13:22:16 +0200 Subject: [PATCH] add fxcg compatibility Signed-off-by: milang --- .gitignore | 3 +- Makefile | 23 ++++++-- configure | 89 +++++++++++++++++++++++++++++++ liblog.c | 153 +++++++++++++++++++++++++++++++++++------------------ liblog.h | 5 +- 5 files changed, 215 insertions(+), 58 deletions(-) create mode 100755 configure diff --git a/.gitignore b/.gitignore index f3bb7be..63fb129 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +*.o +*.cfg *.a -build/ diff --git a/Makefile b/Makefile index 9e8ce90..58f8826 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,25 @@ +include Makefile.cfg + #! /usr/bin/make -f # liblog Makefile +ifeq "$(MODEL)" "" +$(error "Cannot determine choosed model") +endif + +ifeq "$(MODEL)" "fx" +modelflag := -DFX9860G +endif + +ifeq "$(MODEL)" "cg" +modelflag := -DFXCG50 +endif + + cflags := -m3 -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -Wall \ - -Wextra -Os -I . -DFX9860G + -Wextra -Os -I . $(modelflag) target ?= sh3eb-elf -lib := liblog.a +lib := liblog-$(MODEL).a header := liblog.h prefix := $(shell $(target)-gcc -print-search-dirs | grep install \ @@ -15,7 +30,7 @@ $(error "Cannot determine compiler install path") endif src := $(wildcard *.c) -obj := $(src:%=build/%.o) +obj := $(src:%=build-$(MODEL)/%.o) # Rules @@ -24,7 +39,7 @@ all: $(lib) $(lib): $(obj) $(target)-ar rcs $@ $^ -build/%.c.o: %.c | build/ +build-$(MODEL)/%.c.o: %.c | build-$(MODEL)/ $(target)-gcc -c $< -o $@ $(cflags) # Misc rules diff --git a/configure b/configure new file mode 100755 index 0000000..3994f7d --- /dev/null +++ b/configure @@ -0,0 +1,89 @@ +#! /bin/bash + +# +# Basic configuration +# + + + +output="Makefile.cfg" + +# +# Help screen +# + +help() +{ + cat << EOF + Configuration script for the log library. + Usage: $0 [options...] + + +Specified target : + + --fxcg50 + + --fx9680g + +If you don't send any option, fxcg50 is set as default + + + + + +EOF + exit 0 +} + +if [[ "$@" == "--help" ]]; then + help + exit 1 +fi + +# +# Parsing arguments +# + +model= + +fail=false +for arg; do case "$arg" in + -h | -? | --help) + help;; + + + --fx9860g) + model=fx;; + + --fxcg50) + model=cg;; + + *) + echo "error: unrecognized argument '$arg'"; + fail=true;; +esac; done + +# +# Checking mandatory arguments +# + +if $fail; then + echo "Oops ! Maybe a wrong option..." + exit 1 +fi + +# +# Output config +# + +output_config() +{ + echo -n "MODEL =" + echo -n " $(echo $model)" + + echo "" +} + +output_config > $output + +echo "Configuration saved in $output, ready to make!" diff --git a/liblog.c b/liblog.c index a4c1b41..07b0ee7 100644 --- a/liblog.c +++ b/liblog.c @@ -1,84 +1,135 @@ -#include "liblog.h" - -#define FX9860G +#include +#include #include -// Console avec autoscrolling -// equivalent des "Hello" de basic -static int debut=1; // ligne du haut -static int current=7; -static int cursor=0; -static char console [8][22]= +#include +#include +#include + +#ifdef FX9860G + +#define MAX_LENGHT 21 +#define WIDTH 8 + +#endif +#ifdef FXCG50 + +#define MAX_LENGHT 150 +#define WIDTH 17 + +#endif + +typedef struct log_line log_line; +typedef struct log_line { - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " " + void* previous; +#ifdef FXCG50 + char text[MAX_LENGHT]; +#endif +#ifdef FX9860G + char text[MAX_LENGHT]; +#endif + void* next; +} log_line; + + +static log_line first_line= +{ + 0, + "", + 0 }; -static void next_line() +static log_line* current_line=&first_line; + +static log_line* add_line() { - current ++; - debut ++; - if (debut==24) - debut-=8; - current %= 8; - cursor=0; + current_line->next = malloc(sizeof(log_line)); + log_line* previous = current_line; + current_line = current_line->next; + current_line->previous=previous; + current_line->next=0; + current_line->text[0]=' '; } -static void show_line(int l) +static void clear_log() { - dtext(1,1+8*l, &console[(current+l)%8][0], C_BLACK, C_NONE); + while (current_line->previous) + { + log_line* next=current_line->previous; + free(current_line); + current_line=next; + } } -static void set_character(char c) +static void show_line(const log_line* l, int y) +{ + dtext(1, y, &l->text[0], C_BLACK, C_NONE); +} + +static void set_character(char c, int x) { if (c=='\0' || c=='\n') { - console [current] [cursor] = '\0'; - next_line(); + current_line->text[x]= '\0'; + add_line(); } else { - console [current] [cursor] = c; - cursor++; + current_line->text[x] = c; } - if (cursor==21) - next_line(); } // log something -void ll_log(const char * txt) +void ll_send(const char * txt) { - // securite - debut %= 8; - current %= 8; - // fin securite - + add_line(); + char c=1; int i=0; - while (1) + int p=0; + while (c) { - char c=txt[i]; - set_character(c); + c=txt[i]; + set_character(c,p); + p++; + if (c=='\0' || c=='\n') + p=0; + if (p==MAX_LENGHT) + { + p=0; + add_line(); + } i++; - if (c=='\0') - break; } - - // securite - for (int t=0; t<8; t++) - console[t][21]='\0'; - // fin securite } -void ll_display_log() +void ll_display() { + dclear(C_WHITE); for (int i=0; i<8; i++) - show_line(i); + { +#ifdef FX9860G + show_line(current_line, 63 - 8*i); +#endif +#ifdef FXCG50 + show_line(current_line, 224 - 13*i); +#endif + current_line=current_line->previous; + if (!current_line) + break; + } dupdate(); } + +GNORETURN void ll_panic() +{ + ll_display(); + while (1) + getkey(); +} + +void ll_set_panic() +{ + gint_panic_set(ll_panic); +} diff --git a/liblog.h b/liblog.h index 730e36c..455ee68 100644 --- a/liblog.h +++ b/liblog.h @@ -2,11 +2,12 @@ #define LLOG // Display a message in the log stream -void ll_log(const char * txt); +void ll_send(const char * txt); // Puts the 8 last lines of the stream -void ll_display_log(); +void ll_display(); +void ll_set_panic(); #endif