nesemu/ppu/tile_debugger.c

37 lines
1.6 KiB
C
Raw Permalink Normal View History

2024-08-13 21:49:48 -04:00
//
// Created by william on 8/13/24.
//
#include "tile_debugger.h"
2024-08-17 17:38:15 -04:00
// 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, 0b110, 0b111, 0b110, 0b111, 0b111},
2024-08-17 17:38:15 -04:00
{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, 0b110, 0b111, 0b110, 0b111, 0b100},
2024-08-17 17:38:15 -04:00
};
2024-08-13 21:49:48 -04:00
2024-08-17 17:38:15 -04:00
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;
2024-08-13 21:49:48 -04:00
}