2019-09-20 13:22:16 +02:00
|
|
|
#include <gint/exc.h>
|
|
|
|
#include <gint/keyboard.h>
|
2019-09-18 17:44:47 +02:00
|
|
|
#include <gint/display.h>
|
2019-09-20 13:22:16 +02:00
|
|
|
#include <gint/std/stdlib.h>
|
2019-09-21 12:48:06 +02:00
|
|
|
#include <gint/std/stdio.h>
|
2019-09-20 13:22:16 +02:00
|
|
|
#include <gint/defs/attributes.h>
|
|
|
|
#include <liblog.h>
|
2019-09-21 12:48:06 +02:00
|
|
|
#include <stdint.h>
|
2019-09-20 13:22:16 +02:00
|
|
|
|
|
|
|
#ifdef FX9860G
|
|
|
|
|
2019-09-21 12:48:06 +02:00
|
|
|
#define MAX_LENGHT 22
|
2019-09-20 13:22:16 +02:00
|
|
|
#define WIDTH 8
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#ifdef FXCG50
|
|
|
|
|
2019-09-21 12:48:06 +02:00
|
|
|
#define MAX_LENGHT 132
|
2019-09-20 13:22:16 +02:00
|
|
|
#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;
|
2019-09-21 12:48:06 +02:00
|
|
|
int cursor;
|
2019-09-20 13:22:16 +02:00
|
|
|
} log_line;
|
|
|
|
|
|
|
|
|
|
|
|
static log_line first_line=
|
2019-09-18 17:44:47 +02:00
|
|
|
{
|
2019-09-20 13:22:16 +02:00
|
|
|
0,
|
2019-10-01 19:30:42 +02:00
|
|
|
"You are at the top !",
|
2019-09-21 12:48:06 +02:00
|
|
|
0,
|
2019-09-20 13:22:16 +02:00
|
|
|
0
|
2019-09-18 17:44:47 +02:00
|
|
|
};
|
2019-09-20 13:22:16 +02:00
|
|
|
static log_line* current_line=&first_line;
|
|
|
|
|
2019-10-01 19:30:42 +02:00
|
|
|
/// Change the following line to custom ram weight
|
|
|
|
static int number_max_messages=2048; // 1Ko max
|
2019-09-28 14:28:05 +02:00
|
|
|
|
|
|
|
|
2019-10-01 19:30:42 +02:00
|
|
|
static int number_messages=0;
|
|
|
|
|
|
|
|
static int state=1;
|
|
|
|
|
2019-09-28 14:28:05 +02:00
|
|
|
void ll_set_state(int s)
|
|
|
|
{
|
|
|
|
state = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ll_get_state()
|
|
|
|
{
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2019-10-01 19:30:42 +02:00
|
|
|
static log_line* cut_line()
|
2019-09-20 13:22:16 +02:00
|
|
|
{
|
2019-10-01 19:30:42 +02:00
|
|
|
log_line* maillon = first_line.next;
|
|
|
|
log_line* maillon_suivant = maillon->next;
|
|
|
|
|
|
|
|
first_line.next=maillon_suivant;
|
|
|
|
maillon_suivant->previous=&first_line;
|
|
|
|
|
|
|
|
return maillon;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void link_line(log_line* line)
|
|
|
|
{
|
|
|
|
current_line->next=line;
|
|
|
|
line->previous=current_line;
|
|
|
|
current_line=line;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_line(log_line* line)
|
|
|
|
{
|
|
|
|
line->next=0;
|
|
|
|
line->cursor=0;
|
2019-09-21 12:48:06 +02:00
|
|
|
for (int i=0; i<MAX_LENGHT; i++)
|
|
|
|
current_line->text[i]='\0';
|
2019-10-01 19:30:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static log_line* add_line()
|
|
|
|
{
|
|
|
|
int malloc_fail=0;
|
|
|
|
|
|
|
|
log_line* line;
|
|
|
|
|
|
|
|
int test=(number_messages*sizeof(log_line)>=number_max_messages);
|
|
|
|
if (!test)
|
|
|
|
{
|
|
|
|
number_messages++;
|
|
|
|
line = malloc(sizeof(log_line));
|
|
|
|
if (0==line)
|
|
|
|
malloc_fail=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test || malloc_fail) // fail du malloc ou dépassement de la limite de ram imposée lors du build
|
|
|
|
line=cut_line();
|
|
|
|
|
|
|
|
link_line(line);
|
|
|
|
clear_line(line);
|
2019-09-21 12:48:06 +02:00
|
|
|
return current_line;
|
2019-10-01 19:30:42 +02:00
|
|
|
|
2019-09-20 13:22:16 +02:00
|
|
|
}
|
|
|
|
|
2019-09-21 12:48:06 +02:00
|
|
|
void ll_clear()
|
2019-09-18 17:44:47 +02:00
|
|
|
{
|
2019-10-01 19:30:42 +02:00
|
|
|
number_messages=0;
|
2019-09-20 13:22:16 +02:00
|
|
|
while (current_line->previous)
|
|
|
|
{
|
|
|
|
log_line* next=current_line->previous;
|
|
|
|
free(current_line);
|
|
|
|
current_line=next;
|
|
|
|
}
|
2019-09-21 12:48:06 +02:00
|
|
|
current_line->next=0;
|
|
|
|
current_line->cursor=0;
|
|
|
|
for (int i=0; i<MAX_LENGHT; i++)
|
|
|
|
current_line->text[i]='\0';
|
2019-09-18 17:44:47 +02:00
|
|
|
}
|
|
|
|
|
2019-10-01 19:30:42 +02:00
|
|
|
|
2019-09-18 17:44:47 +02:00
|
|
|
|
2019-09-21 12:48:06 +02:00
|
|
|
static void append_character(char c)
|
2019-09-18 17:44:47 +02:00
|
|
|
{
|
2019-10-01 19:30:42 +02:00
|
|
|
if (current_line==&first_line)
|
|
|
|
add_line();
|
2019-09-21 12:48:06 +02:00
|
|
|
if (c=='\n')
|
2019-09-18 17:44:47 +02:00
|
|
|
{
|
2019-09-29 18:30:29 +02:00
|
|
|
current_line->text[current_line->cursor] = '\0';
|
2019-09-20 13:22:16 +02:00
|
|
|
add_line();
|
2019-09-29 18:30:29 +02:00
|
|
|
return;
|
2019-09-18 17:44:47 +02:00
|
|
|
}
|
2019-09-29 18:30:29 +02:00
|
|
|
current_line->text[current_line->cursor] = c;
|
|
|
|
if (c!='\0')
|
2019-09-18 17:44:47 +02:00
|
|
|
{
|
2019-09-21 12:48:06 +02:00
|
|
|
current_line->cursor ++;
|
2019-09-29 18:30:29 +02:00
|
|
|
|
|
|
|
|
2019-09-28 14:28:05 +02:00
|
|
|
if (current_line->cursor == MAX_LENGHT-1)
|
|
|
|
add_line();
|
2019-09-29 18:30:29 +02:00
|
|
|
//current_line->text[current_line->cursor] = '\0';
|
2019-09-21 12:48:06 +02:00
|
|
|
#ifdef FXCG50
|
2019-09-29 18:30:29 +02:00
|
|
|
else if (dsize(¤t_line->text[0])>396-7)
|
2019-09-28 14:28:05 +02:00
|
|
|
{
|
|
|
|
add_line();
|
2019-09-18 17:44:47 +02:00
|
|
|
}
|
2019-09-28 14:28:05 +02:00
|
|
|
#endif
|
2019-09-29 18:30:29 +02:00
|
|
|
}
|
2019-09-18 17:44:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// log something
|
2019-09-20 13:22:16 +02:00
|
|
|
void ll_send(const char * txt)
|
2019-09-18 17:44:47 +02:00
|
|
|
{
|
2019-09-28 14:28:05 +02:00
|
|
|
if (state)
|
2019-09-18 17:44:47 +02:00
|
|
|
{
|
2019-09-28 14:28:05 +02:00
|
|
|
char c=1;
|
|
|
|
int i=0;
|
2019-09-29 18:30:29 +02:00
|
|
|
while (c!='\0')
|
2019-09-28 14:28:05 +02:00
|
|
|
{
|
|
|
|
c=txt[i];
|
|
|
|
append_character(c);
|
|
|
|
i++;
|
|
|
|
}
|
2019-09-18 17:44:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 19:30:42 +02:00
|
|
|
static void show_line(const log_line* l, int y)
|
|
|
|
{
|
|
|
|
dtext(1, y, &l->text[0], C_BLACK, C_NONE);
|
|
|
|
}
|
|
|
|
|
2019-09-20 13:43:21 +02:00
|
|
|
void ll_display_custom(log_line* line)
|
2019-09-18 17:44:47 +02:00
|
|
|
{
|
2019-09-21 12:48:06 +02:00
|
|
|
dfont(NULL);
|
2019-09-18 17:44:47 +02:00
|
|
|
dclear(C_WHITE);
|
|
|
|
for (int i=0; i<8; i++)
|
2019-09-20 13:22:16 +02:00
|
|
|
{
|
|
|
|
#ifdef FX9860G
|
2019-09-20 13:43:21 +02:00
|
|
|
show_line(line, 63 - 8*(i+1));
|
2019-09-20 13:22:16 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FXCG50
|
2019-09-20 13:43:21 +02:00
|
|
|
show_line(line, 224 - 13*(i+1));
|
2019-09-20 13:22:16 +02:00
|
|
|
#endif
|
2019-09-20 13:43:21 +02:00
|
|
|
line=line->previous;
|
|
|
|
if (!line)
|
2019-09-20 13:22:16 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-10-01 19:30:42 +02:00
|
|
|
dupdate_noint();
|
2019-09-18 17:44:47 +02:00
|
|
|
}
|
2019-09-20 13:22:16 +02:00
|
|
|
|
2019-09-20 13:43:21 +02:00
|
|
|
|
2019-10-01 19:30:42 +02:00
|
|
|
|
|
|
|
|
2019-09-20 13:43:21 +02:00
|
|
|
void ll_display()
|
|
|
|
{
|
|
|
|
ll_display_custom(current_line);
|
|
|
|
}
|
|
|
|
|
2019-09-21 12:48:06 +02:00
|
|
|
void ll_pause()
|
|
|
|
{
|
2019-10-01 19:30:42 +02:00
|
|
|
dclear(C_WHITE);
|
2019-09-21 12:48:06 +02:00
|
|
|
log_line* line=current_line;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
ll_display_custom(line);
|
|
|
|
int key = getkey().key;
|
|
|
|
if (key==KEY_UP)
|
|
|
|
{
|
|
|
|
log_line* linet=line->previous;
|
|
|
|
if (linet)
|
|
|
|
line=linet;
|
|
|
|
}
|
|
|
|
if (key==KEY_DOWN)
|
|
|
|
{
|
|
|
|
log_line* linet=line->next;
|
|
|
|
if (linet)
|
|
|
|
line=linet;
|
|
|
|
}
|
|
|
|
if (key==KEY_EXIT)
|
2019-09-29 18:30:29 +02:00
|
|
|
break;
|
2019-09-21 12:48:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-20 13:43:21 +02:00
|
|
|
|
2019-09-21 12:48:06 +02:00
|
|
|
GNORETURN void ll_panic(uint32_t code)
|
2019-09-20 13:22:16 +02:00
|
|
|
{
|
2019-09-21 12:48:06 +02:00
|
|
|
char str[10];
|
2019-09-28 14:28:05 +02:00
|
|
|
sprintf(str, "\nException !\n>> LogState=%d\n>> ErrCode=%d", state, code);
|
|
|
|
ll_set_state(1);
|
2019-09-21 12:48:06 +02:00
|
|
|
ll_send(str);
|
2019-09-20 13:22:16 +02:00
|
|
|
while (1)
|
2019-09-28 14:28:05 +02:00
|
|
|
ll_pause();
|
2019-09-20 13:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ll_set_panic()
|
|
|
|
{
|
|
|
|
gint_panic_set(ll_panic);
|
|
|
|
}
|