cool-bun-demo/screen.c

79 lines
1.9 KiB
C

#include "screen.h"
#include "types.h"
#include <clib/exec_protos.h>
#include <exec/memory.h>
/**
* Includes double buffer space
*/
#define TOTAL_SCREEN_SETUP_SIZE(s) ((s->width / 8) * s->height * s->bitplanes * 2)
/**
* Stores internal allocation details in screenSetup.
* Sets current
*/
void allocateDoubleBufferedScreenMemory(
struct ScreenDefinition *screenDefinition,
struct ActiveScreenBufferDetails *activeScreenBufferDetails,
uint16_t width,
uint16_t height,
uint8_t bitplanes
) {
unsigned char *memory;
screenDefinition->width = width;
screenDefinition->height = height;
screenDefinition->bitplanes = bitplanes;
memory = (unsigned char *)AllocMem(
TOTAL_SCREEN_SETUP_SIZE(screenDefinition),
MEMF_CLEAR | MEMF_CHIP
);
screenDefinition->memoryStart = memory;
screenDefinition->byteWidth = width / 8;
// memory is not interleaved
screenDefinition->nextBitplaneAdvance = screenDefinition->byteWidth * height;
screenDefinition->nextBufferAdvance = screenDefinition->nextBitplaneAdvance * bitplanes;
setActiveScreenBuffer(screenDefinition, activeScreenBufferDetails, 0);
}
void teardownScreen(
struct ScreenDefinition *screenDefinition
) {
FreeMem(
screenDefinition->memoryStart,
TOTAL_SCREEN_SETUP_SIZE(screenDefinition)
);
}
void setActiveScreenBuffer(
struct ScreenDefinition *screenDefinition,
struct ActiveScreenBufferDetails *currentScreen,
short int buffer
) {
int plane;
currentScreen->currentBuffer = buffer;
for (plane = 0; plane < screenDefinition->bitplanes; ++plane) {
currentScreen->planes[plane] = screenDefinition->memoryStart +
buffer * screenDefinition->nextBufferAdvance +
plane * screenDefinition->nextBitplaneAdvance;
}
}
void swapCurrentScreenBuffer(
struct ScreenDefinition *screenDefinition,
struct ActiveScreenBufferDetails *currentScreen
) {
setActiveScreenBuffer(
screenDefinition,
currentScreen,
1 - currentScreen->currentBuffer
);
}