From 7d8b00721649f62f419bc28b59f1e92e5ed7762f Mon Sep 17 00:00:00 2001 From: milang Date: Sat, 31 Aug 2019 19:22:59 +0200 Subject: [PATCH] set final makefile and correct some bugs --- Makefile | 169 +++++++++++++++++++++++++++++------- include/event/keyboard.h | 27 ------ include/render/bitmap.h | 84 ------------------ include/render/parameters.h | 17 ---- include/render/translate.h | 103 ---------------------- include/render/zbuffer.h | 21 ----- libfxengine.a | Bin 10040 -> 9768 bytes src/event/keyboard.c | 33 ------- src/render/bitmap.c | 2 +- src/render/translate.c | 2 +- src/render/zbuffer.c | 4 +- 11 files changed, 141 insertions(+), 321 deletions(-) delete mode 100644 include/event/keyboard.h delete mode 100644 include/render/bitmap.h delete mode 100644 include/render/parameters.h delete mode 100644 include/render/translate.h delete mode 100644 include/render/zbuffer.h delete mode 100644 src/event/keyboard.c diff --git a/Makefile b/Makefile index a2cbdd7..02e3cbb 100644 --- a/Makefile +++ b/Makefile @@ -1,46 +1,151 @@ -# fxengine makefile -# fxengine needs gint (@Lephenixnoir) +target=fx9860g -target ?= sh3eb-elf +CONFIG.TARGET = fx +CONFIG.TARGET.LONG = fx9860g +PREFIX = /usr/lib/gcc/sh3eb-elf/9.1.0/ +toolchain = sh3eb-elf +CONFIG.MACROS = -DFX9860G -cflags := -m3 -mb -D FX9860G -ffreestanding -nostdlib -fstrict-volatile-bitfields -Wall \ - -Wextra -Os -Iinclude -I . +machine := -m3 -mb -lib := libfxengine.a -header := include/ -prefix := $(shell $(target)-gcc -print-search-dirs | grep install \ - | sed 's/install: //') +# 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) +sflags := $(CONFIG.MACROS) +dflags = -MMD -MT $@ -MF $(@:.o=.d) -MP +arflags := -ifeq "$(prefix)" "" -$(error "Can't find install directory") + +# Target file +target := libfxengine.a + +# Automatic names for object and dependency files +src2obj = $(1:../src/%=src/%).o +src2dep = $(1:../src/%=src/%).d + +# Source files +src := $(shell find src \ + -name '*.[csS]' -print) +src_obj := $(foreach s,$(src),$(call src2obj,$s)) + + +# All object files +obj := $(src_obj) $(spe_obj) + + +# +# Toolchain +# + +gcc = $(toolchain)-gcc +as = $(toolchain)-as +ld = $(toolchain)-ld +ar = $(toolchain)-ar +objcopy = $(toolchain)-objcopy + + +# +# Version management +# + +# Version symbol is obtained by using the last commit hash on 7 nibbles +version_hash = 0x0$(shell git rev-parse --short HEAD) + + +# +# Build rules +# + +all: $(target) + +$(target): $(obj) + $(call cmd_l,ar,$@) $(ar) rcs $(arflags) $@ $^ + +# Assembler sources +src/%.s.o: src/%.s src/%.s.d + @ mkdir -p $(dir $@) + $(call cmd_b,as,$*.s) $(gcc) -c $< -o $@ $(sflags) +src/%.S.o: src/%.S src/%.S.d + @ mkdir -p $(dir $@) + $(call cmd_b,as,$*.S) $(gcc) -c $< -o $@ $(sflags) + +# C sources +src/%.c.o: src/%.c src/%.c.d + @ mkdir -p $(dir $@) + $(call cmd_b,gcc,$*.c) $(gcc) -c $< -o $@ $(dflags) $(cflags) + +# Version symbol. ld generates a .stack section for unknown reasons; I remove +# it in the linker script. +version.o: ../.git/HEAD + @ mkdir -p $(dir $@) + @ echo "_FXENGINE_VERSION = $(version_hash);" > $@.txt + $(call cmd_b,ld,$@) $(ld) -r -R $@.txt -o $@ + +# +# Cleaning +# + +clean: + @ rm -rf src version.o{,txt} +distclean: clean + @ rm -rf Makefile $(CONFIG) $(target) + +# +# Installing +# + +m644 := -m 644 + +# Disable -m on Mac OS +ifeq "$(shell uname)" "Darwin" +m644 := endif -src := $(shell find src -name '*.c') +install: $(target) + install -d $(PREFIX) + install $(target) $(m644) $(PREFIX) + cp -r include/fxengine $(PREFIX)/include -obj := $(src:%=build/%.o) +uninstall: + rm -f $(PREFIX)/$(target) + rm -rf $(PREFIX)/include/fxengine +# +# Utilities +# -all: $(lib) - -$(lib): $(obj) - $(target)-ar rcs $@ $^ - - -build/%.c.o: %.c - @ mkdir -p $(dir $@) - $(target)-gcc -c $< -o $@ $(cflags) - -clear: - @ rm -rf build - @ rm -f $(lib) - +# Directories: make conveniently leaves a '/' at the end of $(dir ...) %/: - mkdir -p $@ + @ mkdir -p $@ +# Don't try to unlink directories once they're built (that wouldn't work =p) +.PRECIOUS: %/ + +# Dependency information +-include $(shell [ -d src ] && find src -name *.d) +src/%.d: ; +.PRECIOUS: src/%.d + +.PHONY: all clean distclean + +# Do not output full commands by default +VERBOSE ?= + + + + + + + + + + + + + + + -install: - sh3eb-elf-ar -t $(lib) - cp $(lib) $(prefix) - cp -r $(header) $(prefix)/include/fxengine diff --git a/include/event/keyboard.h b/include/event/keyboard.h deleted file mode 100644 index e910d92..0000000 --- a/include/event/keyboard.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef FE_KEYBOARD -#define FE_KEYBOARD - -#include -#include -#include - -/* FE_keyboard: gestion evenementielle du clavier - on peut assigner des callbacks à certains evènements définis dans gint - les arguments envoyés sont le code de la touche en question (event.key) - le type d'evenement (event.type) - void (*callback)(void) - la fonction à exécuter en cas de pression sur une touche - la fonction reload est appelée à la demande de l'utilisateur et appelle tous les callbacks dans l'ordre */ - -typedef void (*callback)(void); - -void event_keyboard_set_key(uint32_t matrix_code, uint32_t ev_type, callback function); - -// reload all key events and call callbacks -void event_keyboard_reload(); - -//void event_keyboard_start(); - -//void event_keyboard_stop(); - -#endif \ No newline at end of file diff --git a/include/render/bitmap.h b/include/render/bitmap.h deleted file mode 100644 index 6dd8b89..0000000 --- a/include/render/bitmap.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef RENDER_BITMAP -#define RENDER_BITMAP - -#include -#include - -/** - * @brief bitmap rich type - * transparency is in the layout - * @warning Monochrome only ! - */ -struct bitmap_rich -{ - uint32_t size_px_x; - uint32_t size_px_y; - uint32_t size_o_y; - - uint32_t * color; - bool color_dynamic; - uint32_t * layout; - bool layout_dynamic; -}; -typedef struct bitmap_rich bitmap_rich; - - -/** - * @brief { function_description } - * - * @param[in] size_px_x The width in px - * @param[in] size_px_y The height in px - * @param color color origin - * @param[in] copy_color if you want to make a copy, or only to make a link - * @param layout layout origin -> can be set as 0 if it isn't needed - * @param[in] copy_layout if you want to make a copy, or to make a link - * - * @return a rich bitmap, ready to use ! - */ -bitmap_rich* bitmap_new_rich(uint32_t size_px_x, uint32_t size_px_y, uint32_t* color, bool copy_color, - uint32_t *layout, bool copy_layout); - -/** - * @brief delete a rich bitmap created with bitmap_new_rich() - * - * @param bmp The bitmap to delete - */ -void bitmap_delete_rich(bitmap_rich* bmp); - - -/** - * @brief get the color of pixel from rich bitmap - * - * @param[in] bmp The bitmap - * @param[in] x The bitmap x coordinate (in pixels) - * @param[in] y The bitmap y coordinate (in pixels) - * - * @return the color coded in a unsigned char : - * if (color >> 1) - * switch (color%2) - * { - * case 0: - * // WHITE - * break; - * case 1: - * // BLACK - * } - * else - */ -uint8_t bitmap_get_pixel_r(const bitmap_rich * bmp, uint32_t x, uint32_t y); - - -/** - * @brief display a specific rich bitmap pixel on the screen - * - * @param[in] bmp The bitmap - * @param[in] bmp_x The bitmap x coordinate (in pixels) - * @param[in] bmp_y The bitmap y coordinate (in pixels) - * @param[in] x screen : x coordinate - * @param[in] y screen : y coordinate - */ -void bitmap_display_pixel_r(const bitmap_rich * bmp, uint32_t bmp_x, uint32_t bmp_y, uint32_t x, uint32_t y); - - - -#endif diff --git a/include/render/parameters.h b/include/render/parameters.h deleted file mode 100644 index 02cb5bd..0000000 --- a/include/render/parameters.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef RENDER_PARAM -#define RENDER_PARAM - - -// Render param - -#define render_width 128 -#define render_height 64 -#define render_x_mid ((render_width - 1) / 2) // depends on screen width -#define render_y_mid ((render_height - 1) / 2) - -#define render_max_dist 3000 -#define render_min_dist 1 - - - -#endif \ No newline at end of file diff --git a/include/render/translate.h b/include/render/translate.h deleted file mode 100644 index 9db18d0..0000000 --- a/include/render/translate.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef RENDER_TRANSLATE_H -#define RENDER_TRANSLATE_H - -#include -#include - -/** - * @brief this struct is a point in 3d, which has coords save as uint32_t - * this is the recommended type for high performance rendering, because the sh3eb-elf architecture is 32 bits - */ -struct render_integer_position -{ - int32_t x, - y, - z; -}; -typedef struct render_integer_position render_integer_position; - -/** - * @brief this struct is a point in 3d, which has coords save as double - * it is not recommended to use it for high performances rendering, because of the sh3eb-elf architecture, which does not support natively floating calculation - */ -struct render_floating_position -{ - double x, - y, - z; -}; -typedef struct render_floating_position render_floating_position; - - -/** - * @brief This is a point which is used for 3d translations and rendering - * integer mode is the best solution to increase perfs, and that's why I didn't have implemented te floating_points yet. - */ -struct render_integer_point -{ - render_integer_position real; - render_integer_position translated; -}; - -typedef struct render_integer_point render_integer_point; - - -// applique la matrice de rotation et les deltas sur les coordonnées d'un point - -/** - * @brief This function rotates and applies perspective on an integer point - * - * @param point The point which needs to be translated - */ -void render_translate(render_integer_point * point); - - - -/** - * @brief Sets up the translation matrices for a new rendering cycle - * There is no need to call this function if you have already called render_update() - * - * @param[in] dh Camera's horizontal direction (rad) - * @param[in] dv Camera's vertical direction (rad) - * @param[in] roulis Optionnal rotation around the middle of the screen - * @param[in] camera The camera's coordinates, as an integer position - */ -void render_set(const double dh, const double dv, const double roulis, const render_integer_position * camera); - - - -/** - * mathematics constants - */ -extern const double pi, pi2, pi_sur_2; - - -/** - * @brief Sets up an angle mesure between -pi and +pi - * - * @param[in] a the angle (rad) - * - * @return angle mesure which respect the following contraint : - * -pi <= angle <= pi - */ -double modulo_2pi(double a); - -/** - * @brief Homemade cosinus implementation, which is faster than casio provided cosinus function - * - * @param[in] angle The angle (rad) - * - * @return cos angle - */ -double cos(double angle); - -/** - * @brief Homemade sinus implementation, which is faster than casio provided sinus function - * - * @param[in] angle The angle (rad) - * - * @return sin angle - */ -double sin(const double angle); - -#endif diff --git a/include/render/zbuffer.h b/include/render/zbuffer.h deleted file mode 100644 index bd535c5..0000000 --- a/include/render/zbuffer.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef RENDER_ZBUFFER -#define RENDER_ZBUFFER - -#include -#include - -/** FE_zbuffer_clear - * effacer le z buffer pour un nouveau cycle de dessin - * TODO : ajouter effacement avec le DMA Controller pour les modèles ayant un processeur SH4-A -**/ -void render_zbuffer_clear(); - -#include -/** FE_zbuffer_set_dist - * change la distance d'un pixel du zbuffer - * retourne true si il faut dessiner le pixel - * retourne false si le pixel est déjà existant -**/ -bool render_zbuffer_set_px(uint32_t x, uint32_t y, uint32_t dist); // if you are allowed to draw the pixel on vram - -#endif diff --git a/libfxengine.a b/libfxengine.a index 031336058967765b373d6288a91989de72bb8ac8..ce81c2c083fa34be34c84919a3c8e23b6543d0a3 100644 GIT binary patch delta 1059 zcmZ9LO-vI(7>3{NcDF4{p5GF zG>B0HbkKP4z{zkh@u!LQz=1>#9*ALYC>K;vFGfy{CMGzu?J9JV*?Hb?-uY(t`?7`e z%Y*YRLhs40aCku(7oF>XbN%IFgcHMBkW2}U`S08UU-IOqgfT(Tw(>u!-be>r#uL2} z4_R^r`?ysAJi6%y=jbxQ~lTZBFJ~Y!X+ZO3$gIzkSQR!hUGds?F zd|9uMc~g@;K$ZD$)Y)uhzK(ysZD+u;K~qSGewFe}?5Esb$DB#A zslMS{N*<9@N@qloH#|{k2dXE{KkVE=OzJVKt;2G7<{rG$s+-dET}lJAcB$NFcomi_ zB$f`X?t*UJYL;kD9vEr3t>{zCz?dktUg3fj zhFFEZNcNO>WX+e)^aItbeROb9Kx-xAGeC_VKL^z6JP6oyrfs$Be1TrC^Q8lv0AxL$ z1nP7i1?nkh=w09+1BUVj{{*PgdFg*#SOgl%ae?|9b*BC%ovGiU^D_M}b$$l8b$$W3 zbY4LXT6D1rw34~Dj6ql*XCFi>TAJpz;)7r)MfxCEyIAs6iVxZc(d;5cMX`)oCLnr`n;VJ$G((uBw)>)*w0&m=N(tjJZ_T|tW z<<{zCsp6kps01c+eUp2AmEbAsHL;ii_g$CHir>3x(&(;YDh_4UPISU;J^(5_v>zZJp$bf%l;lNl9ho|SK4$mK%UpTVJo=8MO zwp|C@b}suF2RzJt+!Sz;>0PvqGk7Ja0_;%zBAphx??>)f%z zmzy1ns?vv?o@4itR3IDdYFjt^HX7V){IK0)F_+B@^VSJUnhnNQOmjnf`{o|)gB#=8 zC)(w?XSA=h>)P!iH5;m#-I$_3M>5kRA4O*hcxhb02Lj$$QD0kMv2mgBU@0Y9> z?yEPoFGm%%Rtq&?K2}V)6Uqg4_4Aq?eD_ zML;~XHEU#eyMgR$(Nk=_?;3kL;&$27b%lOmR)8JN$s%t7?GB#+Ivjo<=yZ4q@Hu=2 z@H@;0N_6<6M|cGYIPvp9(BTU}h_h)INInI+nj5YgfZ#Bn>^6t*K8#C01KrKI#QkB1 zxj*7C_eUMR$NwV^-v@dfUPlZ)O(BcGPKP~!x_QUs9m~mt_bRV(kQcgj!(_dA!#V|y gi^-Jz(W5C@KFDhXyOyM~ha;Kc7c4=3XA@HBKd`p#5dZ)H diff --git a/src/event/keyboard.c b/src/event/keyboard.c deleted file mode 100644 index 44bf412..0000000 --- a/src/event/keyboard.c +++ /dev/null @@ -1,33 +0,0 @@ -#include - -static callback callbacks[3][6][10]={0}; - -static inline uint32_t get_x(const uint32_t matrix_code) -{ - return (matrix_code-1) % 0x10; -} - -static inline uint32_t get_y(const uint32_t matrix_code) -{ - return (matrix_code-1) / 0x10; -} - -void FE_keyboard_reload() -{ - key_event_t event; - while (1) - { - event=pollevent(); - event.type--; - if (event.type==-1) - break; - callback action = callbacks[event.type][get_x(event.key)][get_y(event.key)]; - if (action) - action(); - } -} - -void FE_keyboard_set_key(uint32_t matrix_code, uint32_t ev_type, callback function) -{ - callbacks[ev_type-1][get_x(matrix_code)][get_y(matrix_code)]=function; -} diff --git a/src/render/bitmap.c b/src/render/bitmap.c index dfaf837..3a86cbd 100644 --- a/src/render/bitmap.c +++ b/src/render/bitmap.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/src/render/translate.c b/src/render/translate.c index 62c8d8f..7d9d75c 100644 --- a/src/render/translate.c +++ b/src/render/translate.c @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/render/zbuffer.c b/src/render/zbuffer.c index 2e31328..e186483 100644 --- a/src/render/zbuffer.c +++ b/src/render/zbuffer.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include