Browse Source

Rewrote scratchpad function to work more as I envisioned it:

sequential calls will pass on a variable to each other that gets updated with the new offset position in the scratch buffer.
tess_experiment
Nico de Poel 3 years ago
parent
commit
79f1e52d1e
  1. 16
      memory.c
  2. 7
      memory.h
  3. 4
      world.c

16
memory.c

@ -7,23 +7,17 @@ static char primbuff[2][PRIMBUFLEN]; // Primitive buffer, just a raw buffer of b
static char *nextpri;
static char *primbuff_bounds;
static char* const scratch_start = (char*)0x1F800000;
static char *scratch = scratch_start;
char* const scratchpad = (char*)0x1F800000;
void mem_scratch_reset()
{
scratch = scratch_start;
}
void *mem_scratch(unsigned short size)
void *mem_scratch(char **scratch_offset, unsigned short size)
{
#if _DEBUG
if (scratch + size > scratch_start + 1024)
if (*scratch_offset + size > scratchpad + 1024)
return NULL;
#endif
void *result = scratch;
scratch += size;
void *result = *scratch_offset;
*scratch_offset += size;
return result;
}

7
memory.h

@ -1,15 +1,16 @@
#ifndef __MEMORY_H__
#define __MEMORY_H__
extern char* const scratchpad; // Starting address of scratchpad memory
/**
* @brief Allocate memory in the fast scratchpad RAM buffer.
*
* @param scratch_offset Pointer to a variable holding the current offset position in scratch memory.
* @param size The number of bytes to allocate. Be aware that the scratchpad memory only has 1024 bytes available.
* @return Pointer to the allocated buffer in scratchpad memory.
*/
void *mem_scratch(unsigned short size);
void mem_scratch_reset();
void *mem_scratch(char **scratch_offset, unsigned short size);
/**
* @brief Allocate a single primitive in the primitive buffer.

4
world.c

@ -46,8 +46,8 @@ void world_draw(const world_t *world)
gte_SetRotMatrix(&vp_matrix);
gte_SetTransMatrix(&vp_matrix);
mem_scratch_reset();
SVECTOR *vecs = mem_scratch(sizeof(SVECTOR) * 3);
char *scratch = scratchpad;
SVECTOR *vecs = (SVECTOR*)mem_scratch(&scratch, sizeof(SVECTOR) * 3);
for (int faceIdx = 0; faceIdx < world->header->numFaces; ++faceIdx)
{

Loading…
Cancel
Save