38 const uint8_t* tiledata,
int indexoffset) {
41 int tile_x = (tile.
id_ % 16) * 8;
42 int tile_y = (tile.
id_ / 16) * 8;
45 static int debug_count = 0;
46 if (debug_count < 4 && (tile.
id_ == 0xEC || tile.
id_ == 0xED || tile.
id_ == 0xFC || tile.
id_ == 0xFD)) {
47 LOG_DEBUG(
"[DrawTile]",
"Floor tile 0x%02X at sheet pos (%d,%d), palette=%d, mirror=(%d,%d)",
49 LOG_DEBUG(
"[DrawTile]",
"First row (8 pixels): ");
50 for (
int i = 0; i < 8; i++) {
51 int src_index = tile_y * 128 + (tile_x + i);
52 LOG_DEBUG(
"[DrawTile]",
"%d ", tiledata[src_index]);
54 LOG_DEBUG(
"[DrawTile]",
"Second row (8 pixels): ");
55 for (
int i = 0; i < 8; i++) {
56 int src_index = (tile_y + 1) * 128 + (tile_x + i);
57 LOG_DEBUG(
"[DrawTile]",
"%d ", tiledata[src_index]);
65 uint8_t clamped_palette = tile.
palette_ & 0x0F;
66 if (clamped_palette > 10) {
67 clamped_palette = clamped_palette % 11;
71 uint8_t palette_offset = (uint8_t)(clamped_palette * 8);
74 for (
int py = 0; py < 8; py++) {
75 for (
int px = 0; px < 8; px++) {
81 int src_index = (tile_y + src_y) * 128 + (tile_x + src_x);
82 uint8_t pixel_index = tiledata[src_index];
86 if (pixel_index == 0) {
89 uint8_t final_color = pixel_index + palette_offset;
90 int dest_index = indexoffset + (py *
width_) + px;
91 canvas[dest_index] = final_color;
99 if ((
int)
buffer_.size() < tiles_w * tiles_h) {
100 buffer_.resize(tiles_w * tiles_h);
111 int skipped_count = 0;
112 for (
int yy = 0; yy < tiles_h; yy++) {
113 for (
int xx = 0; xx < tiles_w; xx++) {
114 uint16_t word =
buffer_[xx + yy * tiles_w];
117 if (word == 0xFFFF) {
132 if (tile.id_ >= 0xEC && tile.id_ <= 0xFD) {
140 int tile_offset = (yy * 8 *
width_) + (xx * 8);
155 int tile_address,
int tile_address_floor,
156 uint8_t floor_graphics) {
159 LOG_DEBUG(
"[DrawFloor]",
"Creating bitmap: %dx%d, active=%d, width=%d",
162 LOG_DEBUG(
"[DrawFloor]",
"After Create: active=%d, width=%d, height=%d",
165 LOG_DEBUG(
"[DrawFloor]",
"Bitmap already exists: active=%d, width=%d, height=%d",
169 auto f = (uint8_t)(floor_graphics << 4);
173 rom_data[tile_address + f + 1]);
175 rom_data[tile_address + f + 3]);
177 rom_data[tile_address + f + 5]);
179 rom_data[tile_address + f + 7]);
182 rom_data[tile_address_floor + f + 1]);
183 gfx::TileInfo floorTile6(rom_data[tile_address_floor + f + 2],
184 rom_data[tile_address_floor + f + 3]);
185 gfx::TileInfo floorTile7(rom_data[tile_address_floor + f + 4],
186 rom_data[tile_address_floor + f + 5]);
187 gfx::TileInfo floorTile8(rom_data[tile_address_floor + f + 6],
188 rom_data[tile_address_floor + f + 7]);
203 for (
int xx = 0; xx < 16; xx++) {
204 for (
int yy = 0; yy < 32; yy++) {
206 SetTileAt((xx * 4) + 1, (yy * 2), word2);
207 SetTileAt((xx * 4) + 2, (yy * 2), word3);
208 SetTileAt((xx * 4) + 3, (yy * 2), word4);
210 SetTileAt((xx * 4), (yy * 2) + 1, word5);
211 SetTileAt((xx * 4) + 1, (yy * 2) + 1, word6);
212 SetTileAt((xx * 4) + 2, (yy * 2) + 1, word7);
213 SetTileAt((xx * 4) + 3, (yy * 2) + 1, word8);
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.