joeylib2/examples/spacetaxi/stCels.c
2026-09-07 15:46:23 -05:00

79 lines
3.3 KiB
C

// Space Taxi -- the cel bank definition + the shared cel expansion.
// See stCels.h. Ordered exactly as stRenderPrewarm built the cels: the
// cab set (flying, wreck and the intro decorations) and passenger set in
// multicolour at the constant level colours (cab/passenger 6, shared
// $D025/$D026 = 2/7), the flame set in multicolour colour 7, then the
// hires intro star in colour 7.
#include "stCels.h"
// mc0/mc1 are the level-wide multicolour registers, constant across all
// 24 screens and the title (verified from the level headers): 2 and 7.
#define MC0 0x02u
#define MC1 0x07u
#define CAB 0x06u // cab and passenger per-sprite colour
#define FLM 0x07u // flame / star colour
const StCelDefT kStCels[] = {
// Cab: flying (gear up/down x left/right), wreck cels, intro cabs.
{ 0xC0, CAB, 1u, MC0, MC1 }, { 0xC1, CAB, 1u, MC0, MC1 },
{ 0xDC, CAB, 1u, MC0, MC1 }, { 0xDD, CAB, 1u, MC0, MC1 },
{ 0xCC, CAB, 1u, MC0, MC1 }, { 0xCD, CAB, 1u, MC0, MC1 },
{ 0xCE, CAB, 1u, MC0, MC1 }, { 0xCF, CAB, 1u, MC0, MC1 },
{ 0xD0, CAB, 1u, MC0, MC1 }, { 0xD1, CAB, 1u, MC0, MC1 },
{ 0xE2, CAB, 1u, MC0, MC1 }, { 0xE3, CAB, 1u, MC0, MC1 },
{ 0xE4, CAB, 1u, MC0, MC1 }, { 0xE5, CAB, 1u, MC0, MC1 },
{ 0xE6, CAB, 1u, MC0, MC1 }, { 0xE7, CAB, 1u, MC0, MC1 },
{ 0xE8, CAB, 1u, MC0, MC1 },
// Passenger: walk cels and the boarding cel.
{ 0xC2, CAB, 1u, MC0, MC1 }, { 0xC3, CAB, 1u, MC0, MC1 },
{ 0xC4, CAB, 1u, MC0, MC1 }, { 0xC5, CAB, 1u, MC0, MC1 },
{ 0xC6, CAB, 1u, MC0, MC1 }, { 0xC7, CAB, 1u, MC0, MC1 },
{ 0xC8, CAB, 1u, MC0, MC1 }, { 0xC9, CAB, 1u, MC0, MC1 },
{ 0xCA, CAB, 1u, MC0, MC1 }, { 0xCB, CAB, 1u, MC0, MC1 },
{ 0xD9, CAB, 1u, MC0, MC1 },
// Flame (exhaust) cels, colour 7.
{ 0xD8, FLM, 1u, MC0, MC1 }, { 0xD4, FLM, 1u, MC0, MC1 },
{ 0xD5, FLM, 1u, MC0, MC1 }, { 0xD2, FLM, 1u, MC0, MC1 },
{ 0xD1, FLM, 1u, MC0, MC1 }, { 0xD7, FLM, 1u, MC0, MC1 },
{ 0xD3, FLM, 1u, MC0, MC1 }, { 0xD6, FLM, 1u, MC0, MC1 },
// Intro star, hires colour 7.
{ 0xDA, FLM, 0u, 0u, 0u },
};
const uint16_t kStCelCount = (uint16_t)(sizeof(kStCels) / sizeof(kStCels[0]));
void stCelBlob(const uint8_t *bm, uint8_t multi, uint8_t color, uint8_t mc0, uint8_t mc1, uint8_t *out) {
uint8_t pal[4];
uint8_t tx;
uint8_t ty;
uint8_t row;
uint8_t k;
pal[0] = 0u;
pal[1] = mc0;
pal[2] = color;
pal[3] = mc1;
for (ty = 0u; ty < ST_CEL_TILES; ty++) {
for (tx = 0u; tx < ST_CEL_TILES; tx++) {
uint8_t *tile = &out[(ty * ST_CEL_TILES + tx) * 32u];
for (row = 0u; row < 8u; row++) {
uint8_t y = (uint8_t)(ty * 8u + row);
uint8_t *p = &tile[row * 4u];
uint8_t b = 0u;
if (bm != 0 && y < ST_CEL_ROWS) {
b = bm[y * 3u + tx];
}
for (k = 0u; k < 4u; k++) {
uint8_t pair = (uint8_t)((b >> (6u - k * 2u)) & 3u);
if (multi != 0u) {
p[k] = (uint8_t)((pal[pair] << 4) | pal[pair]);
} else {
p[k] = (uint8_t)((((pair & 2u) != 0u) ? (uint8_t)(color << 4) : 0u) | (((pair & 1u) != 0u) ? color : 0u));
}
}
}
}
}
}