pokemon/graphic.cpp
Zack Buhman a56def6074 add font and text data
The original font is a bit of a mess, and includes many duplicate
characters.

I decided to reorganize the characters in a new set of glyphs, in
derivced/font.png.

This also includes very basic parsing for text data.
2023-07-30 03:09:20 +00:00

71 lines
2.3 KiB
C++

#include <cstdint>
#include "vdp2.h"
#include "coordinates.hpp"
#include "graphic.hpp"
#include "render_map.hpp"
struct dialog_border {
static constexpr uint8_t corner_top_left = 105;
static constexpr uint8_t corner_top_right = 106;
static constexpr uint8_t corner_bot_left = 107;
static constexpr uint8_t corner_bot_right = 108;
static constexpr uint8_t vertical_end_cap = 109;
static constexpr uint8_t vertical = 110;
static constexpr uint8_t horizontal = 111;
};
struct battle_border {
static constexpr uint8_t horizontal = 96;
static constexpr uint8_t corner_bot_right = 97;
static constexpr uint8_t arrow_right = 98;
static constexpr uint8_t vertical = 99;
static constexpr uint8_t corner_bot_left = 100;
static constexpr uint8_t three_dots = 101;
static constexpr uint8_t vertical_end_cap = 102;
static constexpr uint8_t level = 103;
static constexpr uint8_t arrow_left = 104;
};
static inline void put_char(const uint32_t base_pattern,
const int32_t x, const int32_t y,
const uint8_t c)
{
const int32_t ix = (0x2000 / 2)
+ ((cell_offset::y + y) * 64 + (cell_offset::x + x));
vdp2.vram.u16[ix] = ((base_pattern + c) & 0xfff) | PATTERN_NAME_TABLE_1WORD__PALETTE(1);
}
void draw_box_border(const uint32_t base_pattern,
const screen_t& top_left, const screen_t& bot_right)
{
// place corners
put_char(base_pattern, top_left.x, top_left.y, dialog_border::corner_top_left);
put_char(base_pattern, bot_right.x, top_left.y, dialog_border::corner_top_right);
put_char(base_pattern, bot_right.x, bot_right.y, dialog_border::corner_bot_right);
put_char(base_pattern, top_left.x, bot_right.y, dialog_border::corner_bot_left);
for (int32_t y = top_left.y + 1; y < bot_right.y; y++) {
// left vertical bar
put_char(base_pattern, top_left.x, y, dialog_border::vertical);
// right vertical bar
put_char(base_pattern, bot_right.x, y, dialog_border::vertical);
}
for (int32_t x = top_left.x + 1; x < bot_right.x; x++) {
// top horizontal bar
put_char(base_pattern, x, top_left.y, dialog_border::horizontal);
// bottom horizontal bar
put_char(base_pattern, x, bot_right.y, dialog_border::horizontal);
}
}
void dialog_t::draw(const uint32_t base_pattern)
{
draw_box_border(base_pattern, top_left, bottom_right);
}