cool-bun-demo/screen.c

75 lines
1.7 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)
void setupScreen(
struct ScreenSetup *screenSetup,
uint16_t width,
uint16_t height,
uint8_t bitplanes
) {
unsigned char *memory;
screenSetup->width = width;
screenSetup->height = height;
screenSetup->bitplanes = bitplanes;
memory = (unsigned char *)AllocMem(
2024-05-02 16:52:06 +00:00
TOTAL_SCREEN_SETUP_SIZE(screenSetup),
MEMF_CLEAR | MEMF_CHIP
);
screenSetup->memoryStart = memory;
2024-05-28 12:02:28 +00:00
screenSetup->byteWidth = width / 8;
// memory is not interleaved
screenSetup->nextBitplaneAdvance = screenSetup->byteWidth * height;
screenSetup->nextBufferAdvance = screenSetup->nextBitplaneAdvance * bitplanes;
2024-05-02 16:52:06 +00:00
}
2024-05-28 12:02:28 +00:00
void teardownScreen(
struct ScreenSetup *screenSetup
) {
2024-05-02 16:52:06 +00:00
FreeMem(
screenSetup->memoryStart,
TOTAL_SCREEN_SETUP_SIZE(screenSetup)
);
}
2024-05-28 12:02:28 +00:00
void setCurrentScreen(
2024-05-02 16:52:06 +00:00
struct ScreenSetup *screenSetup,
2024-05-28 12:02:28 +00:00
struct CurrentScreen *currentScreen,
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 < screenSetup->bitplanes; ++plane) {
currentScreen->planes[plane] = screenSetup->memoryStart +
buffer * screenSetup->nextBufferAdvance +
plane * screenSetup->nextBitplaneAdvance;
}
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(
2024-05-28 12:02:28 +00:00
struct ScreenSetup *screenSetup,
struct CurrentScreen *currentScreen
) {
2024-06-01 11:42:11 +00:00
setCurrentScreen(screenSetup, currentScreen, 1 - currentScreen->currentBuffer);
}
2024-05-28 12:02:28 +00:00
2024-06-01 11:42:11 +00:00
void setupInitialCurrentScreen(
struct ScreenSetup *screenSetup,
struct CurrentScreen *currentScreen
) {
2024-05-28 12:02:28 +00:00
setCurrentScreen(screenSetup, currentScreen, 0);
}