From 7e5a61054b6429da963c332cadfe2181c38d0158 Mon Sep 17 00:00:00 2001 From: milang Date: Thu, 19 Sep 2019 21:07:16 +0200 Subject: [PATCH] add debug options improve makefile hunting bugs --- Makefile | 2 +- configure | 54 ++++++++++++----- include/fxengine/fxengine.h | 20 +++++++ include/fxengine/triangle.h | 9 +-- libfxengine.a | Bin 17736 -> 19612 bytes src/fxengine.c | 112 ++++++++++++++++++++++++++++++++++++ src/space.c | 33 +++++++---- src/triangle.c | 35 ----------- src/zbuffer.c | 14 ++--- 9 files changed, 203 insertions(+), 76 deletions(-) create mode 100644 include/fxengine/fxengine.h create mode 100644 src/fxengine.c diff --git a/Makefile b/Makefile index 9b6eeab..3afddce 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ machine := -m3 -mb # Compiler flags, assembler flags, dependency generation, archiving cflags := $(machine) -ffreestanding -nostdlib -Wall -Wextra -std=c11 -Os \ -fstrict-volatile-bitfields -I include $(CONFIG.MACROS) \ - $(CONFIG.CFLAGS) $(PROFILING) + $(CONFIG.CFLAGS) $(FLAGS) sflags := $(CONFIG.MACROS) dflags = -MMD -MT $@ -MF $(@:.o=.d) -MP arflags := diff --git a/configure b/configure index be39aa3..1d5c900 100755 --- a/configure +++ b/configure @@ -15,21 +15,35 @@ output="Makefile.cfg" help() { cat << EOF -Configuration script for the fxengine library. -Usage: $0 [options...] - -You should build out-of-tree by creating a build directory and configuring from -there. + Configuration script for the fxengine library. + Usage: $0 [options...] -Build option: +Specified target : - --enable-profiling + --fxcg50 + --fx9680g + +If you don't send any option, fx9860g is set as default +* Note fxcg50 is not really supported now, but maybe someday it would happen ! + + + +Optional dependencies : + + --libprof By default, profiling is disabled, tht means you will not have access to fps. :( - This option enables fps count, but you need to have libprof (by Lephenixnoir) installed + --liblog + If you want more advanced debug options, you can add this to add a virtual stream used for + logging debug informations + You need tou have liblog (by me) installed + + + + EOF exit 0 @@ -44,7 +58,9 @@ fi # Parsing arguments # -add_cflags= +target=-DFX9860G +libprof= +liblog= fail=false for arg; do case "$arg" in @@ -52,8 +68,17 @@ for arg; do case "$arg" in help;; - --enable-profiling) - add_cflags=-DUSE_LIBPROF;; + --libprof) + libprof=-DUSE_LIBPROF;; + + --liblog) + liblog=-DUSE_LIBLOG;; + + --fx9860g) + target=-DFX9860G;; + + --fxcg50) + target=-DFXCG50;; *) echo "error: unrecognized argument '$arg'"; @@ -76,8 +101,11 @@ fi output_config() { - echo -n "PROFILING =" - echo -n " $(echo $add_cflags)" + echo -n "FLAGS =" + echo -n " $(echo $target)" + echo -n " $(echo $libprof)" + echo -n " $(echo $liblog)" + echo "" } diff --git a/include/fxengine/fxengine.h b/include/fxengine/fxengine.h new file mode 100644 index 0000000..e652ccd --- /dev/null +++ b/include/fxengine/fxengine.h @@ -0,0 +1,20 @@ +#ifndef FE_FXENGINE +#define FE_FXENGINE + +#include + +/** + * @brief Clears zbuffer, counts fps and log settings + * + * @param[in] libprof_channel The libprof channel to be used to count_fps + * if you don't use libprof channel, (default), you send what you want, + * it doesn't matters ;) + */ +void fe_update(const uint32_t libprof_channel); + +/* updates and clears vram, than calls fe_update */ +void fe_display(const uint32_t libprof_channel); + +void fe_custom_panic(); + +#endif diff --git a/include/fxengine/triangle.h b/include/fxengine/triangle.h index 4a6ef52..ccfdac5 100644 --- a/include/fxengine/triangle.h +++ b/include/fxengine/triangle.h @@ -35,14 +35,7 @@ typedef struct fe_triangle fe_triangle; */ void fe_display_triangle(const fe_triangle * face); -/** - * @brief Clears vram, zbuffer - * - * @param[in] libprof_channel The libprof channel to be used to count_fps - * if you don't use libprof channel, (default), you send what you want, - * it doesn't matters ;) - */ -void fe_render_update(const uint32_t libprof_channel); + diff --git a/libfxengine.a b/libfxengine.a index 38c023083bed2ac1d89121145c8e02f6693e3a57..7843cfd062de5fd8f577a1443d289825b696ec22 100644 GIT binary patch delta 3246 zcmai0eQZ&@{9AKlzcczoy4IG?1Vx~KSI;sq-dJ$_&o=g;JC5r z!Y1uyWuoo04w_55w$K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|go@u<&^RpM@{bt zv|T`4Dw8W-Cw>eb#G4pD*iz9!7vC^w5Z5v13(F!M6NYg`4lxn8{1I8)ASzOrtq#c* Q8rgp0@0Q?Dh>H4u0eFKU;s5{u diff --git a/src/fxengine.c b/src/fxengine.c new file mode 100644 index 0000000..af23b5c --- /dev/null +++ b/src/fxengine.c @@ -0,0 +1,112 @@ +#include +#include + +#include +#include + +#include +#include + + +#ifdef USE_LIBPROF + +#include + +#endif + + +#ifdef USE_LIBLOG + +#include + +GNORETURN void system_error(uint32_t code) +{ + ll_display_log(); + while(1) + getkey(); +} + +#endif + +void fe_custom_panic() +{ + +#ifdef USE_LIBLOG + gint_panic_set(system_error); +#endif + +} + + +#ifdef USE_LIBPROF +static uint32_t frame_interval_min=1000000; +static uint32_t frame_interval_max=1; +static uint32_t fps=0; +#endif + + + + +int32_t fe_get_fps() +{ +#ifdef USE_LIBPROF + return fps; +#else + return -1; +#endif +} + + +void fe_display(const uint32_t libprof_channel) +{ + fe_update(libprof_channel); + + dupdate(); + +#ifdef USE_LIBLOG + ll_log("VRAM contents sent."); +#endif + dclear(C_WHITE); + +#ifdef USE_LIBLOG + ll_log("VRAM cleared."); +#endif +} + + +void fe_update(const uint32_t libprof_channel) +{ + ///dupdate(); +#ifdef USE_LIBPROF + // gestion du temps avec libprof + if (prof_elapsed) + { + prof_leave(libprof_channel); + uint32_t frame_interval = prof_time(libprof_channel); + //sleep_us(0, MINIMUM_FRAME_DELAY-frame_interval); + if (frame_intervalframe_interval_max) + frame_interval_max = frame_interval; + fps=1000000/frame_interval; + } + else + { + prof_init(libprof_channel+1, 0); + } + //dupdate(); + prof_clear(libprof_channel); + prof_enter(libprof_channel); +#endif + fe_zbuffer_clear(); + +#ifdef USE_LIBLOG + char fps_str[10]; + sprintf(fps_str, ">> FPS = %d", fps); + ll_log(fps_str); +#else + ll_log(">> FPS not available"); +#endif + //dclear(C_WHITE); +} + diff --git a/src/space.c b/src/space.c index 60c1224..966c372 100644 --- a/src/space.c +++ b/src/space.c @@ -2,8 +2,13 @@ #include #include +#include #include +#ifdef USE_LIBLOG +#include +#endif + double fe_matrix[3][3]= { {0,0,0}, @@ -15,7 +20,7 @@ fe_ipoint fe_translate_delta; static double reducted_cos(const double a) { double u= 1.0; - const double a2 = a * a; + const double a2 = a * a; for(int32_t p = 17; p>=1; p -= 2) u = 1 - a2 / (p * p + p) * u; return u; @@ -25,10 +30,10 @@ static double reducted_cos(const double a) double fe_modulo_2pi(double a) { while (a<=-pi) - a += pi2; - while (a>pi) - a -= pi2; - return a; + a += pi2; + while (a>pi) + a -= pi2; + return a; } double fe_cos(double angle) @@ -52,9 +57,9 @@ double fe_sin(double angle) void fe_vertex_translate(fe_ivertex * v) { static fe_ipoint temp; - temp.x = v->real.x - fe_translate_delta.x; - temp.y = v->real.y - fe_translate_delta.y; - temp.z = v->real.z - fe_translate_delta.z; + temp.x = 64*(v->real.x - fe_translate_delta.x); + temp.y = 64*(v->real.y - fe_translate_delta.y); + temp.z = 64*(v->real.z - fe_translate_delta.z); v->translated.x = (double)(fe_matrix[0][0]*(double)temp.x + fe_matrix[0][1]*(double)temp.y + fe_matrix[0][2]*(double)temp.z); v->translated.z = (double)(fe_matrix[1][0]*(double)temp.x + fe_matrix[1][1]*(double)temp.y + fe_matrix[1][2]*(double)temp.z); @@ -62,8 +67,7 @@ void fe_vertex_translate(fe_ivertex * v) //v->translated.x*=10; //v->translated.y*=10; - v->translated.x*=64; - v->translated.y*=64; + v->translated.z/=64; if (v->translated.z>0) { v->translated.x/=v->translated.z; @@ -79,6 +83,15 @@ void fe_vertex_translate(fe_ivertex * v) v->translated.x+=fe_x_mid; v->translated.y+=fe_y_mid; + + #ifdef USE_LIBLOG + char str[50]; + sprintf(str, "Vrtx X:%d Y:%d Z:%d", + v->translated.x, + v->translated.y, + v->translated.z); + ll_log(str); + #endif } diff --git a/src/triangle.c b/src/triangle.c index 2160461..c21ca01 100644 --- a/src/triangle.c +++ b/src/triangle.c @@ -10,41 +10,6 @@ #include #include -#ifdef USE_LIBPROF - static uint32_t frame_interval_min=1000000; - static uint32_t frame_interval_max=1; -#endif - -void fe_render_update(const uint32_t libprof_channel) -{ - dupdate(); -#ifdef USE_LIBPROF - // gestion du temps avec libprof - if (prof_elapsed) - { - prof_leave(libprof_channel); - uint32_t frame_interval = prof_time(libprof_channel); - //sleep_us(0, MINIMUM_FRAME_DELAY-frame_interval); - if (frame_intervalframe_interval_max) - frame_interval_max = frame_interval; - } - else - { - prof_init(libprof_channel+1, 0); - } - //dupdate(); - prof_clear(libprof_channel); - prof_enter(libprof_channel); -#endif - fe_zbuffer_clear(); - - ///fe_set(dh, dv, roulis, camera); - - dclear(C_WHITE); -} - /** * @brief Orientation of the face * diff --git a/src/zbuffer.c b/src/zbuffer.c index 39fe285..282b2e4 100644 --- a/src/zbuffer.c +++ b/src/zbuffer.c @@ -28,15 +28,11 @@ extern void dma_memset(void *dst, uint32_t l, size_t size); void fe_zbuffer_clear() { uint32_t indice = 0; -/* - if (isSH3()) -*/ - for (indice = 0; indice < size_uint32; indice ++) - zbuffer[indice] = fe_max_dist; -/* - else - dma_memset(zbuffer, fe_max_dist, size_char); -*/ + for (indice = 0; indice < size_uint32; indice ++) + zbuffer[indice] = fe_max_dist; +#ifdef USE_LIBLOG + ll_log(">> ZBuffer cleared."); +#endif } bool fe_zbuffer_set_px(const uint32_t x, const uint32_t y, const uint32_t dist)