diff --git a/Makefile b/Makefile index 36f0451..6c3de0b 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ target ?= sh3eb-elf cflags := -m3 -mb -D FX9860G -ffreestanding -nostdlib -fstrict-volatile-bitfields -Wall \ - -Wextra -Os -I . + -Wextra -Os -Iinclude -I . lib := libfxengine.a header := include/ @@ -31,15 +31,19 @@ build/%.c.o: %.c @ mkdir -p $(dir $@) $(target)-gcc -c $< -o $@ $(cflags) -clear: +clean: @ rm -rf build @ rm -f $(lib) %/: mkdir -p $@ +reinstall: + @ make clean + @ make + @ make install install: sh3eb-elf-ar -t $(lib) cp $(lib) $(prefix) - cp -r $(header) $(prefix)include/fxengine \ No newline at end of file + cp -r $(header) $(prefix)/include/fxengine diff --git a/build/src/render/zbuffer.c.o b/build/src/render/zbuffer.c.o index cc01f0e..94e41bf 100644 Binary files a/build/src/render/zbuffer.c.o and b/build/src/render/zbuffer.c.o differ diff --git a/include/render/bitmap.h b/include/render/bitmap.h index a5afb4b..b65d66c 100644 --- a/include/render/bitmap.h +++ b/include/render/bitmap.h @@ -5,46 +5,47 @@ 0 dans layout -> transparent 1 dans layout -> 1 dans color -> noir 0 dans color -> blanc */ - -struct bitmap_rich_8 +/** bitmap rich type +* @warning Monochrome only ! +* transparency is in the layout +*/ +struct bitmap_rich { - uint32_t size_px_x; // largeur en pixels - uint32_t size_px_y; // hauteur en pixels - uint32_t size_o_y; // taille en octets d'une rangée + uint32_t size_px_x; + uint32_t size_px_y; + uint32_t size_o_y; - uint8_t * color; // bitmap monochrome - uint8_t * layout; // transparence + uint32_t * color; + uint32_t * layout; }; -typedef struct bitmap_rich_16 bitmap_rich_16; +typedef struct bitmap_rich bitmap_rich; -struct bitmap_rich_16 -{ - uint32_t size_px_x; - uint32_t size_px_y; - uint32_t size_o_y; +/** get the color of pixel from rich bitmap +* @return the color coded in a unsigned char : +* if (color >> 1) +* switch (color%2) +* { +* case 0: +* // WHITE +* break; +* case 1: +* // BLACK +* } +* else +* // TRANSPARENT +* @param the bitmap +* @param x coordinate +* @param y coordinate +*/ +inline uint8_t bitmap_get_pixel_r(const bitmap_rich * bmp, uint32_t x, uint32_t y); - uint16_t * color; - uint16_t * layout; -}; -typedef struct bitmap_rich_16 bitmap_rich_16; - -struct bitmap_rich_32 -{ - uint32_t size_px_x; - uint32_t size_px_y; - uint32_t size_o_y; - - uint32_t * color; - uint32_t * layout; -}; -typedef struct bitmap_rich_32 bitmap_rich_32; +/** display a pixel from rich bitmap +* // TRANSPARENT +* @param the bitmap +* @param x coordinate +* @param 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); -/* bitmap_get_color_(int x, int y) - returns a color coded in 2 bytes - byte 7 -> layout (visible, invisible) - byte 6 -> color (N || B) */ -inline uint8_t bitmap_get_color_8(const bitmap_rich_8 * bmp,uint32_t x, uint32_t y); -inline uint8_t bitmap_get_color_16(const bitmap_rich_16 * bmp,uint32_t x, uint32_t y); -inline uint8_t bitmap_get_color_32(const bitmap_rich_32 * bmp,uint32_t x, uint32_t y); \ No newline at end of file diff --git a/libfxengine.a b/libfxengine.a index bc44935..259779f 100644 Binary files a/libfxengine.a and b/libfxengine.a differ diff --git a/src/render/bitmap.c b/src/render/bitmap.c index 8fb688a..f953449 100644 --- a/src/render/bitmap.c +++ b/src/render/bitmap.c @@ -1,28 +1,22 @@ -#include +#include +#include -inline uint8_t bitmap_get_color_8(const bitmap_rich_8 * bmp, uint32_t x, uint32_t y) +inline uint8_t bitmap_get_pixel_r(const bitmap_rich * bmp, uint32_t x, uint32_t y) { - if (x >= bmp->size_px_x || y >= bmp->size_px_y) - const uint32_t indice = y * bmp.size_o_y + x >> 3; - const uint32_t numero_bit = 7 - x % 8; + if (x >= bmp->size_px_x || y >= bmp->size_px_y) + return 0; - return ( bmp.layout[indice] | 1 << numero_bit ) << 1 + ( bmp.color[indice] | 1 << numero_bit ); + const uint32_t indice = y * bmp->size_o_y + x >> 5; + + const uint32_t numero_bit = 31 - x % 32; + + return ( bmp->layout[indice] | 1 << numero_bit ) << 1 + ( bmp->color[indice] | 1 << numero_bit ); } -inline uint8_t bitmap_get_color_16(const bitmap_rich_16 * bmp, uint32_t x, uint32_t y) -{ - if (x >= bmp->size_px_x || y >= bmp->size_px_y) - const uint32_t indice = y * bmp.size_o_y + x >> 4; - const uint32_t numero_bit = 15 - x % 16; - return ( bmp.layout[indice] | 1 << numero_bit ) << 1 + ( bmp.color[indice] | 1 << numero_bit ); +void bitmap_display_pixel_r(const bitmap_rich * bmp, uint32_t bmp_x, uint32_t bmp_y, uint32_t x, uint32_t y) +{ + uint8_t color = bitmap_get_pixel_r(bmp, bmp_x, bmp_y); + if (color >> 1) + dpixel(x, y, 3 * (color % 2)); } - -inline uint8_t bitmap_get_color_32(const bitmap_rich_32 * bmp, uint32_t x, uint32_t y) -{ - if (x >= bmp->size_px_x || y >= bmp->size_px_y) - const uint32_t indice = y * bmp.size_o_y + x >> 5; - const uint32_t numero_bit = 31 - x % 32; - - return ( bmp.layout[indice] | 1 << numero_bit ) << 1 + ( bmp.color[indice] | 1 << numero_bit ); -} \ No newline at end of file