57 lines
1.2 KiB
C
57 lines
1.2 KiB
C
// Scanline control byte (SCB) accessors.
|
|
//
|
|
// Each scanline holds one uint8_t SCB value in range 0..15 selecting
|
|
// which of the 16 palettes that scanline uses at display time.
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "joey/palette.h"
|
|
#include "surfaceInternal.h"
|
|
|
|
// ----- Public API (alphabetical) -----
|
|
|
|
uint8_t scbGet(const SurfaceT *s, uint16_t line) {
|
|
if (s == NULL || line >= SURFACE_HEIGHT) {
|
|
return 0;
|
|
}
|
|
return s->scb[line];
|
|
}
|
|
|
|
|
|
void scbSet(SurfaceT *s, uint16_t line, uint8_t paletteIndex) {
|
|
if (s == NULL || line >= SURFACE_HEIGHT) {
|
|
return;
|
|
}
|
|
if (paletteIndex >= SURFACE_PALETTE_COUNT) {
|
|
return;
|
|
}
|
|
s->scb[line] = paletteIndex;
|
|
}
|
|
|
|
|
|
void scbSetRange(SurfaceT *s, uint16_t firstLine, uint16_t lastLine, uint8_t paletteIndex) {
|
|
uint16_t line;
|
|
uint16_t last;
|
|
|
|
if (s == NULL) {
|
|
return;
|
|
}
|
|
if (paletteIndex >= SURFACE_PALETTE_COUNT) {
|
|
return;
|
|
}
|
|
if (firstLine >= SURFACE_HEIGHT) {
|
|
return;
|
|
}
|
|
|
|
last = lastLine;
|
|
if (last >= SURFACE_HEIGHT) {
|
|
last = SURFACE_HEIGHT - 1;
|
|
}
|
|
if (last < firstLine) {
|
|
return;
|
|
}
|
|
|
|
for (line = firstLine; line <= last; line++) {
|
|
s->scb[line] = paletteIndex;
|
|
}
|
|
}
|