diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3bb7be --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.a +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9e8ce90 --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +#! /usr/bin/make -f +# liblog Makefile + +cflags := -m3 -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -Wall \ + -Wextra -Os -I . -DFX9860G +target ?= sh3eb-elf +lib := liblog.a +header := liblog.h + +prefix := $(shell $(target)-gcc -print-search-dirs | grep install \ + | sed 's/install: //') + +ifeq "$(prefix)" "" +$(error "Cannot determine compiler install path") +endif + +src := $(wildcard *.c) +obj := $(src:%=build/%.o) + +# Rules + +all: $(lib) + +$(lib): $(obj) + $(target)-ar rcs $@ $^ + +build/%.c.o: %.c | build/ + $(target)-gcc -c $< -o $@ $(cflags) + +# Misc rules + +clean: + @ rm -rf build +distclean: clean + @ rm -f $(lib) + +%/: + mkdir -p $@ + +.PRECIOUS: %/ + +# Install + +install: + cp $(lib) $(prefix) + cp $(header) $(prefix)/include diff --git a/README.md b/README.md index 269905f..aca6c31 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,48 @@ # liblog -Une lib de log simple d'utilisation nécéssitant gint. \ No newline at end of file +Une lib de log simple d'utilisation nécéssitant gint. +L'utilisation est archi simple ! On envoie une chaine de caractères et c'est tout ! + +On peut si besoin afficher ce log en cas d'erreur, ou simplement pour consulter l'état d'éxécution du programme à un moment donné. + +## Installation + +Il vous suffit de vous placer dans ce dossier et taper dans un terminal +``` sh +make +make install || sudo make install +``` + +## Utilisation + +### Configurer le projet + +Dans le fichier project.cfg du projet, modifier la ligne suivante +``` sh +LDFLAGS = +``` +Il suffit d'ajouter 2 nouveaux flags, comme ça +``` sh +LDFLAGS = -llog -lgint-fx +``` + +### Dans le code source + +D'abord, il faut inclure le header de liblog +``` C +#include +``` + +#### Écrire dans le log +``` C +ll_log("Votre message de débug"); +``` + +#### Afficher le log + +Afficher le log peut être utile pour le débug, notamment en cas d'exception. +Il suffira de taper la commande suivante : +``` C +ll_display(); +// getkey(); si vous voulez mettre le programme en pause pour lire +``` diff --git a/liblog.c b/liblog.c new file mode 100644 index 0000000..a4c1b41 --- /dev/null +++ b/liblog.c @@ -0,0 +1,84 @@ +#include "liblog.h" + +#define FX9860G +#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]= +{ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " " +}; + +static void next_line() +{ + current ++; + debut ++; + if (debut==24) + debut-=8; + current %= 8; + cursor=0; +} + +static void show_line(int l) +{ + dtext(1,1+8*l, &console[(current+l)%8][0], C_BLACK, C_NONE); +} + +static void set_character(char c) +{ + + if (c=='\0' || c=='\n') + { + console [current] [cursor] = '\0'; + next_line(); + } + else + { + console [current] [cursor] = c; + cursor++; + } + if (cursor==21) + next_line(); +} + +// log something +void ll_log(const char * txt) +{ + // securite + debut %= 8; + current %= 8; + // fin securite + + int i=0; + while (1) + { + char c=txt[i]; + set_character(c); + i++; + if (c=='\0') + break; + } + + // securite + for (int t=0; t<8; t++) + console[t][21]='\0'; + // fin securite +} + +void ll_display_log() +{ + dclear(C_WHITE); + for (int i=0; i<8; i++) + show_line(i); + dupdate(); +} diff --git a/liblog.h b/liblog.h new file mode 100644 index 0000000..c7759c6 --- /dev/null +++ b/liblog.h @@ -0,0 +1,9 @@ +#ifndef LLOG +#define LLOG + +void ll_log(const char * txt); +void ll_display_log(); + + + +#endif