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 38c0230..7843cfd 100644 Binary files a/libfxengine.a and b/libfxengine.a differ 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)