add fxcg compatibility

Signed-off-by: milang <milan.garnier@orange.fr>
This commit is contained in:
milang 2019-09-20 13:22:16 +02:00
parent c9c6c17587
commit 56831200e7
5 changed files with 215 additions and 58 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.o
*.cfg
*.a
build/

View File

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

89
configure vendored Executable file
View File

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

153
liblog.c
View File

@ -1,84 +1,135 @@
#include "liblog.h"
#define FX9860G
#include <gint/exc.h>
#include <gint/keyboard.h>
#include <gint/display.h>
// 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 <gint/std/stdlib.h>
#include <gint/defs/attributes.h>
#include <liblog.h>
#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,
"<Log beginning>",
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);
}

View File

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