1v13d/src/FxEngine/zbuffer.c

101 lines
2.4 KiB
C
Raw Normal View History

2019-07-21 20:14:54 +02:00
#include "zbuffer.h"
2019-08-16 15:27:15 +02:00
2019-08-17 14:09:45 +02:00
#include <stdint.h>
2019-07-21 20:14:54 +02:00
#include <stdbool.h>
2019-07-23 15:52:20 +02:00
#include <gint/display.h>
#include <gint/std/stdio.h>
#include <gint/std/stdlib.h>
#include <gint/keyboard.h>
2019-08-17 17:47:05 +02:00
#include <gint/dma.h>
2019-08-17 17:50:53 +02:00
#include <gint/hardware.h>
2019-08-19 12:10:06 +02:00
/* size_uint32
taille du zbuffer exprimée en uint32_t
utile pour l'effacement du zbuffer sur sh3 */
static const uint32_t size_int32 = FE_ZB_SIZE_X*FE_ZB_SIZE_Y;
2019-08-19 12:10:06 +02:00
/* size_char
taille du zbuffer exprimée en octets
utile pour malloc */
static const uint32_t size_char = size_int32*sizeof(int32_t);
2019-08-16 15:27:15 +02:00
/* size_char
taille du zbuffer exprimée en octets
utile pour le DMA */
static const uint32_t size_blocks = size_char/32;
2019-08-19 12:10:06 +02:00
/* en attente de reponse
static int32_t address[size_uint32];
*/
2019-08-16 15:27:15 +02:00
/** address
* addresse du zbuffer
**/
2019-08-17 14:09:45 +02:00
static int32_t* address=0;
2019-08-17 20:07:04 +02:00
static int32_t* clearval=0;
2019-08-17 18:23:41 +02:00
2019-08-17 19:48:41 +02:00
#define ALIGN 32
static void* buffer_malloc(uint_fast16_t size)
2019-08-17 18:23:41 +02:00
{
void *mem = malloc(size+ALIGN+sizeof(void*));
void **ptr = (void**)((uintptr_t)(mem+ALIGN+sizeof(void*)) & ~(ALIGN-1));
ptr[-1] = mem;
return ptr;
}
static void buffer_free(void *ptr)
2019-08-17 18:23:41 +02:00
{
free(((void**)ptr)[-1]);
}
2019-07-21 20:14:54 +02:00
void FE_zbuffer_clear()
{
2019-08-17 17:47:05 +02:00
if (address==0)
{
2019-08-17 18:25:30 +02:00
address = buffer_malloc(size_char);
2019-08-17 20:07:04 +02:00
clearval= buffer_malloc(32);
if (address==0||clearval==0) // cas de figure où il n'y a plus assez de RAM
2019-08-17 17:47:05 +02:00
{
dclear(C_WHITE);
dtext(1, 1, "Not enough RAM...", C_BLACK, C_NONE);
dupdate();
while (1==1)
getkey();
}
2019-08-19 12:10:06 +02:00
clearval[0]=3000; clearval[1]=3000; clearval[2]=3000; clearval[3]=3000; clearval[4]=3000; clearval[5]=3000; clearval[6]=3000; clearval[7]=3000;
2019-08-17 17:47:05 +02:00
}
// TODO déterminer le type d'effacement
if (isSH3())
2019-08-17 18:14:36 +02:00
{ // effacement CPU
uint_fast16_t indice;
2019-08-19 12:10:06 +02:00
for (indice = 0; indice < size_int32; indice ++)
address[indice] = clearval[0];
2019-08-17 17:47:05 +02:00
}
else
2019-08-17 18:14:36 +02:00
{ // effacement DMA
dma_transfer(0, DMA_32B, size_blocks, &clearval, DMA_FIXED, address, DMA_INC);
2019-08-17 17:47:05 +02:00
}
2019-07-21 20:14:54 +02:00
}
2019-08-17 17:57:44 +02:00
void FE_start_rendering()
{
if (!isSH3())
dma_transfer_wait(0);
2019-08-17 17:57:44 +02:00
}
2019-08-17 14:09:45 +02:00
bool FE_zbuffer_set_dist(int32_t x, int32_t y, int32_t dist)
2019-07-21 20:14:54 +02:00
{
2019-08-17 17:47:05 +02:00
x %= FE_ZB_SIZE_X;
y %= FE_ZB_SIZE_Y;
const uint32_t indice = x * 64 + y;
if (address[indice]>dist && dist>0)
{
address[indice] = dist;
return true;
}
else
return false;
2019-08-17 14:09:45 +02:00
}