add correct makefile for fxengine as lib

This commit is contained in:
milang 2019-08-28 15:29:06 +02:00
parent b12d64f45d
commit 0a1a3d090f
No known key found for this signature in database
GPG Key ID: D287C9D6C33D9035
13 changed files with 369 additions and 0 deletions

45
Makefile Normal file
View File

@ -0,0 +1,45 @@
# fxengine makefile
# fxengine needs gint (@Lephenixnoir)
target ?= sh3eb-elf
cflags := -m3 -mb -D FX9860G -ffreestanding -nostdlib -fstrict-volatile-bitfields -Wall \
-Wextra -Os -I .
lib := libfxengine.a
header := include/
prefix := $(shell $(target)-gcc -print-search-dirs | grep install \
| sed 's/install: //')
ifeq "$(prefix)" ""
$(error "Can't find install directory")
endif
src := $(shell find src -name '*.c')
obj := $(src:%=build/%.o)
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)
%/:
mkdir -p $@
install:
sh3eb-elf-ar -t $(lib)
cp $(lib) $(prefix)
cp -r $(header) $(prefix)include/fxengine

Binary file not shown.

Binary file not shown.

Binary file not shown.

27
include/event/keyboard.h Normal file
View File

@ -0,0 +1,27 @@
#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

@ -0,0 +1,17 @@
#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

@ -0,0 +1,61 @@
#ifndef RENDER_TRANSLATE_H
#define RENDER_TRANSLATE_H
#include <stdint.h>
#include <fxengine/render/parameters.h>
/* FE_position:
notion de point dans l'espace simple */
typedef struct FE_integer_position FE_integer_position;
struct FE_integer_position
{
int32_t x,
y,
z;
};
typedef struct FE_floating_position FE_floating_position;
struct FE_floating_position
{
double x,
y,
z;
};
/* FE_point:
notion de point dans l'espace destiné à etre utilisé dans l'affichage */
typedef struct FE_integer_point FE_integer_point;
struct FE_integer_point
{
FE_integer_position real,
translated;
};
// applique la matrice de rotation et les deltas sur les coordonnées d'un point
void render_translate(FE_integer_point * point);
// change la matrice de rotation et les deltas pour le cycle à venir
void render_set(const double dh, const double dv, const double roulis, const FE_integer_position * camera);
// constantes mathématiques
extern const double pi, pi2, pi_sur_2;
// fonctions mathématiques
double modulo_2pi(double a);
double cos(double angle);
double sin(const double angle);
#endif

21
include/render/zbuffer.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef RENDER_ZBUFFER
#define RENDER_ZBUFFER
#include <fxengine/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

BIN
libfxengine.a Normal file

Binary file not shown.

33
src/event/keyboard.c Normal file
View File

@ -0,0 +1,33 @@
#include <fxengine/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;
}

123
src/render/translate.c Normal file
View File

@ -0,0 +1,123 @@
#include <fxengine/render/translate.h>
#include <gint/std/stdlib.h>
#include <gint/std/string.h>
const double pi = 3.141592653589793238462643383279;
const double pi2 = pi * 2;
const double pi_sur_2 = pi / 2;
static double reducted_cos(const double a)
{
double u= 1.0;
const double a2 = a * a;
for(int32_t p = 15; p>=1; p -= 2)
u = 1 - a2 / (p * p + p) * u;
return u;
}
// return a with -pi<=a<pi
double modulo_2pi(double a)
{
while (a<=-pi)
a += pi2;
while (a>pi)
a -= pi2;
return a;
}
static double cos_recursive(double angle)
{
if (angle<0)
return cos_recursive(-angle);
if (angle>=pi_sur_2)
return -reducted_cos(angle - pi);
return reducted_cos(angle); // OK
}
double cos(double angle)
{
angle = modulo_2pi(angle);
return cos_recursive(angle);
}
double sin(double angle)
{
return cos(angle - pi_sur_2);
}
#define sgn(x) (x>=0?x:-x)
static double matrice[3][3]=
{
{0,0,0},
{0,0,0},
{0,0,0}
};
static FE_integer_position delta;
void render_translate(FE_integer_point * point)
{
static FE_integer_position temp;
temp.x = point->real.x - delta.x;
temp.y = point->real.y - delta.y;
temp.z = point->real.z - delta.z;
point->translated.x = (double)(matrice[0][0]*(double)temp.x + matrice[0][1]*(double)temp.y + matrice[0][2]*(double)temp.z);
point->translated.z = (double)(matrice[1][0]*(double)temp.x + matrice[1][1]*(double)temp.y + matrice[1][2]*(double)temp.z);
point->translated.y = (double)(matrice[2][0]*(double)temp.x + matrice[2][1]*(double)temp.y + matrice[2][2]*(double)temp.z);
//point->translated.x*=10;
//point->translated.y*=10;
point->translated.x*=64;
point->translated.y*=64;
if (point->translated.z>0)
{
point->translated.x/=point->translated.z;
point->translated.y/=point->translated.z;
}
else
{
point->translated.x*=32768*sgn(point->translated.z);
point->translated.y*=32768*sgn(point->translated.z);
}
//(point->translated.x*1024)/point->translated.z;
//(point->translated.y*1024)/point->translated.z;
point->translated.x+=render_x_mid;
point->translated.y+=render_y_mid;
}
void render_set(const double dh, const double dv, const double roulis, const FE_integer_position * camera)
{
const double A=cos(dv);
const double B=sin(dv);
const double C=cos(roulis);
const double D=sin(roulis);
const double E=cos(dh);
const double F=sin(dh);
// raccourcis
const double AD=A*D, BD=B*D;
matrice[0][0]=C*E;
matrice[0][1]=-C*F;
matrice[0][2]=D;
matrice[1][0]=BD*E+A*F;
matrice[1][1]=-BD*F+A*E;
matrice[1][2]=-B*C;
matrice[2][0]=-AD*E+B*F;
matrice[2][1]=AD*F+B*E;
matrice[2][2]=A*C;
// assigner delta
memcpy(&delta, camera, sizeof(FE_integer_position));
}

42
src/render/zbuffer.c Normal file
View File

@ -0,0 +1,42 @@
#include <fxengine/render/zbuffer.h>
#include <fxengine/render/parameters.h>
#include <stdbool.h>
#include <gint/display.h>
#include <gint/std/stdio.h>
#include <gint/std/stdlib.h>
#include <gint/keyboard.h>
#include <gint/defs/attributes.h>
static const int size_uint32 = render_width * render_height;
static const int size_char = size_uint32 * sizeof(uint32_t);
// zbuffer et clear val sont 32B alignés pour ajouter éventuellement le DMA
static int32_t *zbuffer = (void *)0x88080000 - ((size_char / 32) * 32 + 1);
GALIGNED(32) GSECTION(".rodata") static const int32_t clearval[8]={render_max_dist,render_max_dist,render_max_dist,render_max_dist,render_max_dist,render_max_dist,render_max_dist,render_max_dist};
void render_zbuffer_clear()
{
uint32_t indice = 0;
for (indice = 0; indice < size_uint32; indice ++)
zbuffer[indice] = render_max_dist;
}
bool render_zbuffer_set_px(uint32_t x, uint32_t y, uint32_t dist)
{
const int indice = x * render_height + y;
if (zbuffer[indice]>dist && dist>=render_min_dist && dist<=render_max_dist)
{
zbuffer[indice] = dist;
return true;
}
return false;
}

BIN
unused temp.tar.xz Normal file

Binary file not shown.