[nostalgia/core] Add color 16 functions

This commit is contained in:
Gary Talent 2020-03-29 13:35:23 -05:00
parent a81582d3cd
commit 11cb4d5a44
2 changed files with 28 additions and 3 deletions

View File

@ -164,15 +164,15 @@ uint8_t blue32(Color32 c) noexcept {
uint8_t red32(Color16 c) noexcept {
return ((c & 0b0000000000011111) >> 0) * 8;
return red16(c) * 8;
}
uint8_t green32(Color16 c) noexcept {
return ((c & 0b0000001111100000) >> 5) * 8;
return green16(c) * 8;
}
uint8_t blue32(Color16 c) noexcept {
return ((c & 0b0111110000000000) >> 10) * 8;
return blue16(c) * 8;
}
void puts(Context *ctx, int column, int row, const char *str) {
@ -181,4 +181,9 @@ void puts(Context *ctx, int column, int row, const char *str) {
}
}
static_assert(color16(0, 31, 0, 0) == 992);
static_assert(color16(16, 31, 0, 0) == 1008);
static_assert(color16(16, 31, 8, 0) == 9200);
static_assert(color16(16, 31, 8, 1) == 41968);
}

View File

@ -83,12 +83,32 @@ ox::Error model(T *io, NostalgiaGraphic *ng) {
[[nodiscard]] uint8_t blue32(Color16 c) noexcept;
[[nodiscard]] constexpr Color16 color16(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
return r | (g << 5) | (b << 10) | (a << 15);
}
[[nodiscard]] uint8_t red32(Color32 c) noexcept;
[[nodiscard]] uint8_t green32(Color32 c) noexcept;
[[nodiscard]] uint8_t blue32(Color32 c) noexcept;
[[nodiscard]] constexpr uint8_t red16(Color16 c) noexcept {
return c & 0b0000000000011111;
}
[[nodiscard]] constexpr uint8_t green16(Color16 c) noexcept {
return (c & 0b0000001111100000) >> 5;
}
[[nodiscard]] constexpr uint8_t blue16(Color16 c) noexcept {
return (c & 0b0111110000000000) >> 10;
}
[[nodiscard]] constexpr uint8_t alpha16(Color16 c) noexcept {
return c >> 15;
}
void puts(Context *ctx, int column, int row, const char *str);
void setTile(Context *ctx, int layer, int column, int row, uint8_t tile);