set final makefile and correct some bugs

This commit is contained in:
milang 2019-08-31 19:22:59 +02:00
parent 8dc08f4141
commit 7d8b007216
No known key found for this signature in database
GPG Key ID: D287C9D6C33D9035
11 changed files with 141 additions and 321 deletions

169
Makefile
View File

@ -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

View File

@ -1,27 +0,0 @@
#ifndef FE_KEYBOARD
#define FE_KEYBOARD
#include <gint/keyboard.h>
#include <gint/keycodes.h>
#include <stdint.h>
/* 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

View File

@ -1,84 +0,0 @@
#ifndef RENDER_BITMAP
#define RENDER_BITMAP
#include <stdint.h>
#include <stdbool.h>
/**
* @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

View File

@ -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

View File

@ -1,103 +0,0 @@
#ifndef RENDER_TRANSLATE_H
#define RENDER_TRANSLATE_H
#include <stdint.h>
#include <render/parameters.h>
/**
* @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

View File

@ -1,21 +0,0 @@
#ifndef RENDER_ZBUFFER
#define RENDER_ZBUFFER
#include <render/parameters.h>
#include <stdint.h>
/** 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 <stdbool.h>
/** 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

Binary file not shown.

View File

@ -1,33 +0,0 @@
#include <event/keyboard.h>
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;
}

View File

@ -1,5 +1,5 @@
#include <gint/display.h>
#include <render/bitmap.h>
#include <fxengine/render/bitmap.h>
#include <gint/std/string.h>
#include <gint/std/stdlib.h>

View File

@ -1,4 +1,4 @@
#include <render/translate.h>
#include <fxengine/render/translate.h>
#include <gint/std/stdlib.h>
#include <gint/std/string.h>

View File

@ -1,5 +1,5 @@
#include <render/zbuffer.h>
#include <render/parameters.h>
#include <fxengine/render/zbuffer.h>
#include <fxengine/render/parameters.h>
#include <stdbool.h>
#include <stdint.h>