cool-bun-demo/screen.c

79 lines
1.9 KiB
C
Raw Permalink Normal View History

2024-05-02 16:52:06 +00:00
#include "screen.h"
#include "types.h"
#include <clib/exec_protos.h>
#include <exec/memory.h>
2024-05-28 12:02:28 +00:00
/**
* 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,
2024-05-28 12:02:28 +00:00
uint16_t width,
uint16_t height,
uint8_t bitplanes
) {
unsigned char *memory;
screenDefinition->width = width;
screenDefinition->height = height;
screenDefinition->bitplanes = bitplanes;
2024-05-28 12:02:28 +00:00
memory = (unsigned char *)AllocMem(
TOTAL_SCREEN_SETUP_SIZE(screenDefinition),
2024-05-02 16:52:06 +00:00
MEMF_CLEAR | MEMF_CHIP
);
screenDefinition->memoryStart = memory;
screenDefinition->byteWidth = width / 8;
2024-05-28 12:02:28 +00:00
// memory is not interleaved
screenDefinition->nextBitplaneAdvance = screenDefinition->byteWidth * height;
screenDefinition->nextBufferAdvance = screenDefinition->nextBitplaneAdvance * bitplanes;
setActiveScreenBuffer(screenDefinition, activeScreenBufferDetails, 0);
2024-05-02 16:52:06 +00:00
}
2024-05-28 12:02:28 +00:00
void teardownScreen(
struct ScreenDefinition *screenDefinition
2024-05-28 12:02:28 +00:00
) {
2024-05-02 16:52:06 +00:00
FreeMem(
screenDefinition->memoryStart,
TOTAL_SCREEN_SETUP_SIZE(screenDefinition)
2024-05-02 16:52:06 +00:00
);
}
void setActiveScreenBuffer(
struct ScreenDefinition *screenDefinition,
struct ActiveScreenBufferDetails *currentScreen,
2024-05-28 12:02:28 +00:00
short int buffer
2024-05-02 16:52:06 +00:00
) {
2024-05-28 12:02:28 +00:00
int plane;
currentScreen->currentBuffer = buffer;
for (plane = 0; plane < screenDefinition->bitplanes; ++plane) {
currentScreen->planes[plane] = screenDefinition->memoryStart +
buffer * screenDefinition->nextBufferAdvance +
plane * screenDefinition->nextBitplaneAdvance;
2024-05-28 12:02:28 +00:00
}
2024-05-02 16:52:06 +00:00
}
2024-05-28 12:02:28 +00:00
2024-06-01 11:42:11 +00:00
void swapCurrentScreenBuffer(
struct ScreenDefinition *screenDefinition,
struct ActiveScreenBufferDetails *currentScreen
2024-06-01 11:42:11 +00:00
) {
setActiveScreenBuffer(
screenDefinition,
currentScreen,
1 - currentScreen->currentBuffer
);
2024-05-28 12:02:28 +00:00
}