nesemu/ppu/tile_debugger.c

37 lines
1.6 KiB
C

//
// Created by william on 8/13/24.
//
#include "tile_debugger.h"
// Contains the patterns of every hexadecimal digit encoded as pattern data.
// The first dimension of the table represents a row in a tile.
byte hex_pattern_table[5][0x10] = {
{0b111, 0b001, 0b111, 0b111, 0b101, 0b111, 0b111, 0b111, 0b111, 0b111, 0b010, 0b111, 0b111, 0b110, 0b111, 0b111},
{0b101, 0b001, 0b001, 0b001, 0b101, 0b100, 0b100, 0b001, 0b101, 0b101, 0b101, 0b101, 0b100, 0b101, 0b100, 0b100},
{0b101, 0b001, 0b111, 0b111, 0b111, 0b111, 0b111, 0b010, 0b111, 0b111, 0b111, 0b110, 0b100, 0b101, 0b111, 0b110},
{0b101, 0b001, 0b100, 0b001, 0b001, 0b001, 0b101, 0b010, 0b101, 0b001, 0b101, 0b101, 0b100, 0b101, 0b100, 0b100},
{0b111, 0b001, 0b111, 0b111, 0b001, 0b111, 0b111, 0b010, 0b111, 0b001, 0b101, 0b111, 0b111, 0b110, 0b111, 0b100},
};
byte tile_debugger_encode_number_as_pattern(byte num, byte tile_fine_y) {
if (tile_fine_y == 6) {
return 0x7f; // On row 6, a full line is drawn to make it easier to separate tiles
} else if (tile_fine_y == 5 || tile_fine_y == 7) {
return 0;
}
// The first digit of the hex is encoded
byte remaining = num % 0x10;
byte encoded = hex_pattern_table[tile_fine_y][remaining];
if (num > 0xf) {
// If the number is greater than 0xF, we need a second digit
// We encode it, then add it 4 pixels to the left of the already encoded digit
byte tenths = num / 0x10;
byte tenths_encoded = hex_pattern_table[tile_fine_y][tenths];
encoded = (tenths_encoded << 4) | encoded;
}
return encoded;
}