remove nonstandard type aliases

This commit is contained in:
scawful
2025-01-19 20:16:40 -05:00
parent fa33be3463
commit 809282edad
35 changed files with 367 additions and 357 deletions

View File

@@ -9,13 +9,8 @@
#include <memory>
#include "absl/status/status.h"
#include "app/core/constants.h"
#include "app/gfx/snes_palette.h"
#define SDL_RETURN_IF_ERROR() \
if (SDL_GetError() != nullptr) { \
return absl::InternalError(SDL_GetError()); \
}
#include "util/macro.h"
namespace yaze {
namespace gfx {
@@ -218,7 +213,8 @@ Bitmap::Bitmap(int width, int height, int depth, int data_size) {
Create(width, height, depth, std::vector<uint8_t>(data_size, 0));
}
void Bitmap::Initialize(int width, int height, int depth, std::span<uint8_t>& data) {
void Bitmap::Initialize(int width, int height, int depth,
std::span<uint8_t> &data) {
width_ = width;
height_ = height;
depth_ = depth;
@@ -259,7 +255,8 @@ void Bitmap::Create(int width, int height, int depth, int format,
GetSnesPixelFormat(format)),
SDL_Surface_Deleter{}};
if (surface_ == nullptr) {
SDL_Log("Bitmap::Create.SDL_CreateRGBSurfaceWithFormat failed: %s\n", SDL_GetError());
SDL_Log("Bitmap::Create.SDL_CreateRGBSurfaceWithFormat failed: %s\n",
SDL_GetError());
active_ = false;
return;
}
@@ -293,7 +290,8 @@ void Bitmap::CreateTexture(SDL_Renderer *renderer) {
SDL_TEXTUREACCESS_STREAMING, width_, height_),
SDL_Texture_Deleter{}};
if (texture_ == nullptr) {
SDL_Log("Bitmap::CreateTexture.SDL_CreateTextureFromSurface failed: %s\n", SDL_GetError());
SDL_Log("Bitmap::CreateTexture.SDL_CreateTextureFromSurface failed: %s\n",
SDL_GetError());
}
texture_pixels = data_.data();
@@ -301,7 +299,8 @@ void Bitmap::CreateTexture(SDL_Renderer *renderer) {
SDL_ConvertSurfaceFormat(surface_.get(), SDL_PIXELFORMAT_ARGB8888, 0),
SDL_Surface_Deleter{}};
if (converted_surface_ == nullptr) {
SDL_Log("Bitmap::CreateTexture.SDL_ConvertSurfaceFormat failed: %s\n", SDL_GetError());
SDL_Log("Bitmap::CreateTexture.SDL_ConvertSurfaceFormat failed: %s\n",
SDL_GetError());
return;
}

View File

@@ -7,9 +7,9 @@
#include <memory>
#include "absl/status/status.h"
#include "app/core/constants.h"
#include "app/core/platform/sdl_deleter.h"
#include "app/gfx/snes_palette.h"
#include "util/macro.h"
namespace yaze {
@@ -91,10 +91,10 @@ class Bitmap {
void SaveSurfaceToFile(std::string_view filename);
void Initialize(int width, int height, int depth, std::span<uint8_t>& data);
void Initialize(int width, int height, int depth, std::span<uint8_t> &data);
void Create(int width, int height, int depth, int data_size) {
Create(width, height, depth, std::vector<uint8_t>(data_size, 0));
Create(width, height, depth, std::vector<uint8_t>(data_size, 0));
}
void Create(int width, int height, int depth, std::span<uint8_t> data);
void Create(int width, int height, int depth,
@@ -133,7 +133,7 @@ class Bitmap {
void Get16x16Tile(int tile_x, int tile_y, std::vector<uint8_t> &tile_data,
int &tile_data_offset);
void WriteToPixel(int position, uchar value) {
void WriteToPixel(int position, uint8_t value) {
if (pixel_data_ == nullptr) {
pixel_data_ = data_.data();
}

View File

@@ -6,8 +6,8 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/core/constants.h"
#include "app/rom.h"
#include "util/macro.h"
#define DEBUG_LOG(msg) std::cout << msg << std::endl
@@ -174,7 +174,7 @@ std::vector<uint8_t> HyruleMagicDecompress(uint8_t const* src, int* const size,
unsigned short c, d;
for (;;) {
// retrieve a uchar from the buffer.
// retrieve a uint8_t from the buffer.
a = *(src++);
// end the decompression routine if we encounter 0xff.
@@ -320,10 +320,10 @@ void PrintCompressionChain(const CompressionPiecePointer& chain_head) {
}
}
void CheckByteRepeat(const uchar* rom_data, DataSizeArray& data_size_taken,
void CheckByteRepeat(const uint8_t* rom_data, DataSizeArray& data_size_taken,
CommandArgumentArray& cmd_args, uint& src_data_pos,
const uint last_pos) {
uint pos = src_data_pos;
const unsigned int last_pos) {
unsigned int pos = src_data_pos;
char byte_to_repeat = rom_data[pos];
while (pos <= last_pos && rom_data[pos] == byte_to_repeat) {
data_size_taken[kCommandByteFill]++;
@@ -332,12 +332,12 @@ void CheckByteRepeat(const uchar* rom_data, DataSizeArray& data_size_taken,
cmd_args[kCommandByteFill][0] = byte_to_repeat;
}
void CheckWordRepeat(const uchar* rom_data, DataSizeArray& data_size_taken,
void CheckWordRepeat(const uint8_t* rom_data, DataSizeArray& data_size_taken,
CommandArgumentArray& cmd_args, uint& src_data_pos,
const uint last_pos) {
const unsigned int last_pos) {
if (src_data_pos + 2 <= last_pos &&
rom_data[src_data_pos] != rom_data[src_data_pos + 1]) {
uint pos = src_data_pos;
unsigned int pos = src_data_pos;
char byte1 = rom_data[pos];
char byte2 = rom_data[pos + 1];
pos += 2;
@@ -354,10 +354,10 @@ void CheckWordRepeat(const uchar* rom_data, DataSizeArray& data_size_taken,
}
}
void CheckIncByte(const uchar* rom_data, DataSizeArray& data_size_taken,
void CheckIncByte(const uint8_t* rom_data, DataSizeArray& data_size_taken,
CommandArgumentArray& cmd_args, uint& src_data_pos,
const uint last_pos) {
uint pos = src_data_pos;
const unsigned int last_pos) {
unsigned int pos = src_data_pos;
char byte = rom_data[pos];
pos++;
data_size_taken[kCommandIncreasingFill] = 1;
@@ -370,14 +370,14 @@ void CheckIncByte(const uchar* rom_data, DataSizeArray& data_size_taken,
cmd_args[kCommandIncreasingFill][0] = rom_data[src_data_pos];
}
void CheckIntraCopy(const uchar* rom_data, DataSizeArray& data_size_taken,
void CheckIntraCopy(const uint8_t* rom_data, DataSizeArray& data_size_taken,
CommandArgumentArray& cmd_args, uint& src_data_pos,
const uint last_pos, uint start) {
const unsigned int last_pos, unsigned int start) {
if (src_data_pos != start) {
uint searching_pos = start;
uint current_pos_u = src_data_pos;
uint copied_size = 0;
uint search_start = start;
unsigned int searching_pos = start;
unsigned int current_pos_u = src_data_pos;
unsigned int copied_size = 0;
unsigned int search_start = start;
while (searching_pos < src_data_pos && current_pos_u <= last_pos) {
while (rom_data[current_pos_u] != rom_data[searching_pos] &&
@@ -409,8 +409,8 @@ void CheckIntraCopy(const uchar* rom_data, DataSizeArray& data_size_taken,
void ValidateForByteGain(const DataSizeArray& data_size_taken,
const CommandSizeArray& cmd_size, uint& max_win,
uint& cmd_with_max) {
for (uint cmd_i = 1; cmd_i < 5; cmd_i++) {
uint cmd_size_taken = data_size_taken[cmd_i];
for (unsigned int cmd_i = 1; cmd_i < 5; cmd_i++) {
unsigned int cmd_size_taken = data_size_taken[cmd_i];
// TODO(@scawful): Replace conditional with table of command sizes
// "Table that is even with copy but all other cmd are 2"
auto table_check =
@@ -424,7 +424,7 @@ void ValidateForByteGain(const DataSizeArray& data_size_taken,
}
}
void CompressionCommandAlternative(const uchar* rom_data,
void CompressionCommandAlternative(const uint8_t* rom_data,
CompressionPiecePointer& compressed_chain,
const CommandSizeArray& cmd_size,
const CommandArgumentArray& cmd_args,
@@ -459,9 +459,9 @@ void CompressionCommandAlternative(const uchar* rom_data,
comp_accumulator = 0;
}
void CheckByteRepeatV2(const uchar* data, uint& src_pos, const uint last_pos,
void CheckByteRepeatV2(const uint8_t* data, uint& src_pos, const unsigned int last_pos,
CompressionCommand& cmd) {
uint i = 0;
unsigned int i = 0;
while (src_pos + i < last_pos && data[src_pos] == data[src_pos + i]) {
++i;
}
@@ -469,10 +469,10 @@ void CheckByteRepeatV2(const uchar* data, uint& src_pos, const uint last_pos,
cmd.arguments[kCommandByteFill][0] = data[src_pos];
}
void CheckWordRepeatV2(const uchar* data, uint& src_pos, const uint last_pos,
void CheckWordRepeatV2(const uint8_t* data, uint& src_pos, const unsigned int last_pos,
CompressionCommand& cmd) {
if (src_pos + 2 <= last_pos && data[src_pos] != data[src_pos + 1]) {
uint pos = src_pos;
unsigned int pos = src_pos;
char byte1 = data[pos];
char byte2 = data[pos + 1];
pos += 2;
@@ -489,9 +489,9 @@ void CheckWordRepeatV2(const uchar* data, uint& src_pos, const uint last_pos,
}
}
void CheckIncByteV2(const uchar* rom_data, uint& src_data_pos,
const uint last_pos, CompressionCommand& cmd) {
uint pos = src_data_pos;
void CheckIncByteV2(const uint8_t* rom_data, uint& src_data_pos,
const unsigned int last_pos, CompressionCommand& cmd) {
unsigned int pos = src_data_pos;
char byte = rom_data[pos];
pos++;
cmd.data_size[kCommandIncreasingFill] = 1;
@@ -504,14 +504,14 @@ void CheckIncByteV2(const uchar* rom_data, uint& src_data_pos,
cmd.arguments[kCommandIncreasingFill][0] = rom_data[src_data_pos];
}
void CheckIntraCopyV2(const uchar* rom_data, uint& src_data_pos,
const uint last_pos, uint start,
void CheckIntraCopyV2(const uint8_t* rom_data, uint& src_data_pos,
const unsigned int last_pos, unsigned int start,
CompressionCommand& cmd) {
if (src_data_pos != start) {
uint searching_pos = start;
uint current_pos_u = src_data_pos;
uint copied_size = 0;
uint search_start = start;
unsigned int searching_pos = start;
unsigned int current_pos_u = src_data_pos;
unsigned int copied_size = 0;
unsigned int search_start = start;
while (searching_pos < src_data_pos && current_pos_u <= last_pos) {
while (rom_data[current_pos_u] != rom_data[searching_pos] &&
@@ -544,8 +544,8 @@ const std::array<int, 5> kCommandSizes = {1, 2, 2, 2, 3};
// TODO(@scawful): TEST ME
void ValidateForByteGainV2(const CompressionCommand& cmd, uint& max_win,
uint& cmd_with_max) {
for (uint cmd_i = 1; cmd_i < 5; cmd_i++) {
uint cmd_size_taken = cmd.data_size[cmd_i];
for (unsigned int cmd_i = 1; cmd_i < 5; cmd_i++) {
unsigned int cmd_size_taken = cmd.data_size[cmd_i];
// Check if the command size exceeds the maximum win and the size in the
// command sizes table, except for the repeating bytes command when the size
// taken is 3
@@ -558,7 +558,7 @@ void ValidateForByteGainV2(const CompressionCommand& cmd, uint& max_win,
}
}
void CompressionCommandAlternativeV2(const uchar* rom_data,
void CompressionCommandAlternativeV2(const uint8_t* rom_data,
const CompressionCommand& cmd,
CompressionPiecePointer& compressed_chain,
uint& src_data_pos, uint& comp_accumulator,
@@ -593,7 +593,7 @@ void CompressionCommandAlternativeV2(const uchar* rom_data,
}
void AddAlternativeCompressionCommand(
const uchar* rom_data, CompressionPiecePointer& compressed_chain,
const uint8_t* rom_data, CompressionPiecePointer& compressed_chain,
const CompressionCommand& command, uint& source_data_position,
uint& uncompressed_data_size, uint& best_command, uint& best_command_gain) {
std::cout << "- Identified a gain from command: " << best_command
@@ -642,7 +642,7 @@ void AddAlternativeCompressionCommand(
absl::StatusOr<CompressionPiecePointer> SplitCompressionPiece(
CompressionPiecePointer& piece, int mode) {
CompressionPiecePointer new_piece;
uint length_left = piece->length - kMaxLengthCompression;
unsigned int length_left = piece->length - kMaxLengthCompression;
piece->length = kMaxLengthCompression;
switch (piece->command) {
@@ -670,7 +670,7 @@ absl::StatusOr<CompressionPiecePointer> SplitCompressionPiece(
}
case kCommandRepeatingBytes: {
piece->argument_length = kMaxLengthCompression;
uint offset = piece->argument[0] + (piece->argument[1] << 8);
unsigned int offset = piece->argument[0] + (piece->argument[1] << 8);
new_piece = std::make_shared<CompressionPiece>(
piece->command, length_left, piece->argument, piece->argument_length);
if (mode == kNintendoMode2) {
@@ -694,7 +694,7 @@ absl::StatusOr<CompressionPiecePointer> SplitCompressionPiece(
std::vector<uint8_t> CreateCompressionString(CompressionPiecePointer& start,
int mode) {
uint pos = 0;
unsigned int pos = 0;
auto piece = start;
std::vector<uint8_t> output;
@@ -704,7 +704,8 @@ std::vector<uint8_t> CreateCompressionString(CompressionPiecePointer& start,
pos++;
} else {
if (piece->length <= kMaxLengthCompression) {
output.push_back(kCompressionStringMod | ((uchar)piece->command << 2) |
output.push_back(kCompressionStringMod |
((uint8_t)piece->command << 2) |
(((piece->length - 1) & 0xFF00) >> 8));
pos++;
printf("Building extended header : cmd: %d, length: %d - %02X\n",
@@ -777,7 +778,7 @@ CompressionPiecePointer MergeCopy(CompressionPiecePointer& start) {
if (piece->command == kCommandDirectCopy && piece->next != nullptr &&
piece->next->command == kCommandDirectCopy &&
piece->length + piece->next->length <= kMaxLengthCompression) {
uint previous_length = piece->length;
unsigned int previous_length = piece->length;
piece->length = piece->length + piece->next->length;
for (int i = 0; i < piece->next->argument_length; ++i) {
@@ -795,7 +796,7 @@ CompressionPiecePointer MergeCopy(CompressionPiecePointer& start) {
return start;
}
absl::StatusOr<std::vector<uint8_t>> CompressV2(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> CompressV2(const uint8_t* data,
const int start,
const int length, int mode,
bool check) {
@@ -814,9 +815,9 @@ absl::StatusOr<std::vector<uint8_t>> CompressV2(const uchar* data,
/*cmd_size*/ {0, 1, 2, 1, 2},
/*data_size*/ {0, 0, 0, 0, 0}};
uint src_pos = start;
uint last_pos = start + length - 1;
uint comp_accumulator = 0; // Used when skipping using copy
unsigned int src_pos = start;
unsigned int last_pos = start + length - 1;
unsigned int comp_accumulator = 0; // Used when skipping using copy
while (true) {
current_cmd.data_size.fill({});
@@ -827,8 +828,8 @@ absl::StatusOr<std::vector<uint8_t>> CompressV2(const uchar* data,
CheckIncByteV2(data, src_pos, last_pos, current_cmd);
CheckIntraCopyV2(data, src_pos, last_pos, start, current_cmd);
uint max_win = 2;
uint cmd_with_max = kCommandDirectCopy;
unsigned int max_win = 2;
unsigned int cmd_with_max = kCommandDirectCopy;
ValidateForByteGain(current_cmd.data_size, current_cmd.cmd_size, max_win,
cmd_with_max);
// ValidateForByteGainV2(current_cmd, max_win, cmd_with_max);
@@ -871,13 +872,13 @@ absl::StatusOr<std::vector<uint8_t>> CompressV2(const uchar* data,
return CreateCompressionString(compressed_chain_start->next, mode);
}
absl::StatusOr<std::vector<uint8_t>> CompressGraphics(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> CompressGraphics(const uint8_t* data,
const int pos,
const int length) {
return CompressV2(data, pos, length, kNintendoMode2);
}
absl::StatusOr<std::vector<uint8_t>> CompressOverworld(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> CompressOverworld(const uint8_t* data,
const int pos,
const int length) {
return CompressV2(data, pos, length, kNintendoMode1);
@@ -889,7 +890,7 @@ absl::StatusOr<std::vector<uint8_t>> CompressOverworld(
}
void CheckByteRepeatV3(CompressionContext& context) {
uint pos = context.src_pos;
unsigned int pos = context.src_pos;
// Ensure the sequence does not start with an uncompressable byte
if (pos == 0 || context.data[pos - 1] != context.data[pos]) {
@@ -910,7 +911,7 @@ void CheckByteRepeatV3(CompressionContext& context) {
void CheckWordRepeatV3(CompressionContext& context) {
if (context.src_pos + 1 <= context.last_pos) { // Changed the condition here
uint pos = context.src_pos;
unsigned int pos = context.src_pos;
char byte1 = context.data[pos];
char byte2 = context.data[pos + 1];
pos += 2;
@@ -935,7 +936,7 @@ void CheckWordRepeatV3(CompressionContext& context) {
}
void CheckIncByteV3(CompressionContext& context) {
uint pos = context.src_pos;
unsigned int pos = context.src_pos;
uint8_t byte = context.data[pos];
pos++;
context.current_cmd.data_size[kCommandIncreasingFill] = 1;
@@ -974,8 +975,8 @@ void CheckIntraCopyV3(CompressionContext& context) {
// beginning
if (context.src_pos > 0 &&
context.src_pos + window_size <= context.data.size()) {
uint max_copied_size = 0;
uint best_search_start = 0;
unsigned int max_copied_size = 0;
unsigned int best_search_start = 0;
// Slide the window over the source data
for (int win_pos = 1; win_pos < window_size && win_pos < context.src_pos;
@@ -991,7 +992,7 @@ void CheckIntraCopyV3(CompressionContext& context) {
if (found_pos != search_end) {
// Check the entire length of the match
uint len = 0;
unsigned int len = 0;
while (context.src_pos + len < context.data.size() &&
context.data[context.src_pos + len] == *(found_pos + len)) {
len++;
@@ -1047,8 +1048,8 @@ void DetermineBestCompression(CompressionContext& context) {
// Start with the default scenario.
context.cmd_with_max = kCommandDirectCopy;
for (uint cmd_i = 1; cmd_i < 5; cmd_i++) {
uint cmd_size_taken = context.current_cmd.data_size[cmd_i];
for (unsigned int cmd_i = 1; cmd_i < 5; cmd_i++) {
unsigned int cmd_size_taken = context.current_cmd.data_size[cmd_i];
int net_savings = cmd_size_taken - context.current_cmd.cmd_size[cmd_i];
// Skip commands that aren't efficient.
@@ -1193,7 +1194,7 @@ absl::Status ValidateCompressionResultV3(const CompressionContext& context) {
absl::StatusOr<CompressionPiece> SplitCompressionPieceV3(
CompressionPiece& piece, int mode) {
CompressionPiece new_piece;
uint length_left = piece.length - kMaxLengthCompression;
unsigned int length_left = piece.length - kMaxLengthCompression;
piece.length = kMaxLengthCompression;
switch (piece.command) {
@@ -1220,7 +1221,7 @@ absl::StatusOr<CompressionPiece> SplitCompressionPieceV3(
}
case kCommandRepeatingBytes: {
piece.argument_length = kMaxLengthCompression;
uint offset = piece.argument[0] + (piece.argument[1] << 8);
unsigned int offset = piece.argument[0] + (piece.argument[1] << 8);
new_piece = CompressionPiece(piece.command, length_left, piece.argument,
piece.argument_length);
if (mode == kNintendoMode2) {
@@ -1242,7 +1243,7 @@ absl::StatusOr<CompressionPiece> SplitCompressionPieceV3(
}
void FinalizeCompression(CompressionContext& context) {
uint pos = 0;
unsigned int pos = 0;
for (CompressionPiece& piece : context.compression_pieces) {
if (piece.length <= kMaxLengthNormalHeader) { // Normal Header
@@ -1252,7 +1253,7 @@ void FinalizeCompression(CompressionContext& context) {
} else {
if (piece.length <= kMaxLengthCompression) {
context.compression_string.push_back(
kCompressionStringMod | ((uchar)piece.command << 2) |
kCompressionStringMod | ((uint8_t)piece.command << 2) |
(((piece.length - 1) & 0xFF00) >> 8));
pos++;
std::cout << "Building extended header : cmd: " << piece.command
@@ -1340,7 +1341,7 @@ absl::StatusOr<std::vector<uint8_t>> CompressV3(
context.compressed_data.end());
}
std::string SetBuffer(const uchar* data, int src_pos, int comp_accumulator) {
std::string SetBuffer(const uint8_t* data, int src_pos, int comp_accumulator) {
std::string buffer;
for (int i = 0; i < comp_accumulator; ++i) {
buffer.push_back(data[i + src_pos - comp_accumulator]);
@@ -1357,7 +1358,7 @@ std::string SetBuffer(const std::vector<uint8_t>& data, int src_pos,
return buffer;
}
void memfill(const uchar* data, std::vector<uint8_t>& buffer, int buffer_pos,
void memfill(const uint8_t* data, std::vector<uint8_t>& buffer, int buffer_pos,
int offset, int length) {
auto a = data[offset];
auto b = data[offset + 1];
@@ -1367,17 +1368,18 @@ void memfill(const uchar* data, std::vector<uint8_t>& buffer, int buffer_pos,
}
}
absl::StatusOr<std::vector<uint8_t>> DecompressV2(const uchar* data, int offset,
int size, int mode) {
absl::StatusOr<std::vector<uint8_t>> DecompressV2(const uint8_t* data,
int offset, int size,
int mode) {
if (size == 0) {
return std::vector<uint8_t>();
}
std::vector<uint8_t> buffer(size, 0);
uint length = 0;
uint buffer_pos = 0;
uchar command = 0;
uchar header = data[offset];
unsigned int length = 0;
unsigned int buffer_pos = 0;
uint8_t command = 0;
uint8_t header = data[offset];
while (header != kSnesByteMax) {
if ((header & kExpandedMod) == kExpandedMod) {
@@ -1418,8 +1420,8 @@ absl::StatusOr<std::vector<uint8_t>> DecompressV2(const uchar* data, int offset,
offset += 1; // Advance 1 byte in the ROM
} break;
case kCommandRepeatingBytes: {
ushort s1 = ((data[offset + 1] & kSnesByteMax) << 8);
ushort s2 = (data[offset] & kSnesByteMax);
uint16_t s1 = ((data[offset + 1] & kSnesByteMax) << 8);
uint16_t s2 = (data[offset] & kSnesByteMax);
int addr = (s1 | s2);
if (mode == kNintendoMode1) { // Reversed byte order for
// overworld maps
@@ -1454,12 +1456,12 @@ absl::StatusOr<std::vector<uint8_t>> DecompressV2(const uchar* data, int offset,
return buffer;
}
absl::StatusOr<std::vector<uint8_t>> DecompressGraphics(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> DecompressGraphics(const uint8_t* data,
int pos, int size) {
return DecompressV2(data, pos, size, kNintendoMode2);
}
absl::StatusOr<std::vector<uint8_t>> DecompressOverworld(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> DecompressOverworld(const uint8_t* data,
int pos, int size) {
return DecompressV2(data, pos, size, kNintendoMode1);
}

View File

@@ -1,13 +1,14 @@
#ifndef YAZE_APP_GFX_COMPRESSION_H
#define YAZE_APP_GFX_COMPRESSION_H
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/core/constants.h"
#include "util/macro.h"
#define BUILD_HEADER(command, length) (command << 5) + (length - 1)
@@ -94,27 +95,27 @@ void PrintCompressionChain(const CompressionPiecePointer& chain_head);
// Compression V1
void CheckByteRepeat(const uchar* rom_data, DataSizeArray& data_size_taken,
void CheckByteRepeat(const uint8_t* rom_data, DataSizeArray& data_size_taken,
CommandArgumentArray& cmd_args, uint& src_data_pos,
const uint last_pos);
const unsigned int last_pos);
void CheckWordRepeat(const uchar* rom_data, DataSizeArray& data_size_taken,
void CheckWordRepeat(const uint8_t* rom_data, DataSizeArray& data_size_taken,
CommandArgumentArray& cmd_args, uint& src_data_pos,
const uint last_pos);
const unsigned int last_pos);
void CheckIncByte(const uchar* rom_data, DataSizeArray& data_size_taken,
void CheckIncByte(const uint8_t* rom_data, DataSizeArray& data_size_taken,
CommandArgumentArray& cmd_args, uint& src_data_pos,
const uint last_pos);
const unsigned int last_pos);
void CheckIntraCopy(const uchar* rom_data, DataSizeArray& data_size_taken,
void CheckIntraCopy(const uint8_t* rom_data, DataSizeArray& data_size_taken,
CommandArgumentArray& cmd_args, uint& src_data_pos,
const uint last_pos, uint start);
const unsigned int last_pos, unsigned int start);
void ValidateForByteGain(const DataSizeArray& data_size_taken,
const CommandSizeArray& cmd_size, uint& max_win,
uint& cmd_with_max);
void CompressionCommandAlternative(const uchar* rom_data,
void CompressionCommandAlternative(const uint8_t* rom_data,
CompressionPiecePointer& compressed_chain,
const CommandSizeArray& cmd_size,
const CommandArgumentArray& cmd_args,
@@ -123,22 +124,22 @@ void CompressionCommandAlternative(const uchar* rom_data,
// Compression V2
void CheckByteRepeatV2(const uchar* data, uint& src_pos, const uint last_pos,
void CheckByteRepeatV2(const uint8_t* data, uint& src_pos, const unsigned int last_pos,
CompressionCommand& cmd);
void CheckWordRepeatV2(const uchar* data, uint& src_pos, const uint last_pos,
void CheckWordRepeatV2(const uint8_t* data, uint& src_pos, const unsigned int last_pos,
CompressionCommand& cmd);
void CheckIncByteV2(const uchar* data, uint& src_pos, const uint last_pos,
void CheckIncByteV2(const uint8_t* data, uint& src_pos, const unsigned int last_pos,
CompressionCommand& cmd);
void CheckIntraCopyV2(const uchar* data, uint& src_pos, const uint last_pos,
uint start, CompressionCommand& cmd);
void CheckIntraCopyV2(const uint8_t* data, uint& src_pos, const unsigned int last_pos,
unsigned int start, CompressionCommand& cmd);
void ValidateForByteGainV2(const CompressionCommand& cmd, uint& max_win,
uint& cmd_with_max);
void CompressionCommandAlternativeV2(const uchar* data,
void CompressionCommandAlternativeV2(const uint8_t* data,
const CompressionCommand& cmd,
CompressionPiecePointer& compressed_chain,
uint& src_pos, uint& comp_accumulator,
@@ -148,15 +149,15 @@ void CompressionCommandAlternativeV2(const uchar* data,
* @brief Compresses a buffer of data using the LC_LZ2 algorithm.
* \deprecated Use HyruleMagicDecompress instead.
*/
absl::StatusOr<std::vector<uint8_t>> CompressV2(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> CompressV2(const uint8_t* data,
const int start,
const int length, int mode = 1,
bool check = false);
absl::StatusOr<std::vector<uint8_t>> CompressGraphics(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> CompressGraphics(const uint8_t* data,
const int pos,
const int length);
absl::StatusOr<std::vector<uint8_t>> CompressOverworld(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> CompressOverworld(const uint8_t* data,
const int pos,
const int length);
absl::StatusOr<std::vector<uint8_t>> CompressOverworld(
@@ -178,12 +179,12 @@ struct CompressionContext {
std::vector<uint8_t> compressed_data;
std::vector<CompressionPiece> compression_pieces;
std::vector<uint8_t> compression_string;
uint src_pos;
uint last_pos;
uint start;
uint comp_accumulator = 0;
uint cmd_with_max = kCommandDirectCopy;
uint max_win = 0;
unsigned int src_pos;
unsigned int last_pos;
unsigned int start;
unsigned int comp_accumulator = 0;
unsigned int cmd_with_max = kCommandDirectCopy;
unsigned int max_win = 0;
CompressionCommand current_cmd = {};
int mode;
@@ -227,8 +228,8 @@ absl::StatusOr<std::vector<uint8_t>> CompressV3(
std::string SetBuffer(const std::vector<uint8_t>& data, int src_pos,
int comp_accumulator);
std::string SetBuffer(const uchar* data, int src_pos, int comp_accumulator);
void memfill(const uchar* data, std::vector<uint8_t>& buffer, int buffer_pos,
std::string SetBuffer(const uint8_t* data, int src_pos, int comp_accumulator);
void memfill(const uint8_t* data, std::vector<uint8_t>& buffer, int buffer_pos,
int offset, int length);
/**
@@ -236,12 +237,12 @@ void memfill(const uchar* data, std::vector<uint8_t>& buffer, int buffer_pos,
* @note Works well for graphics but not overworld data. Prefer Hyrule Magic
* routines for overworld data.
*/
absl::StatusOr<std::vector<uint8_t>> DecompressV2(const uchar* data, int offset,
int size = 0x800,
absl::StatusOr<std::vector<uint8_t>> DecompressV2(const uint8_t* data,
int offset, int size = 0x800,
int mode = 1);
absl::StatusOr<std::vector<uint8_t>> DecompressGraphics(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> DecompressGraphics(const uint8_t* data,
int pos, int size);
absl::StatusOr<std::vector<uint8_t>> DecompressOverworld(const uchar* data,
absl::StatusOr<std::vector<uint8_t>> DecompressOverworld(const uint8_t* data,
int pos, int size);
absl::StatusOr<std::vector<uint8_t>> DecompressOverworld(
const std::vector<uint8_t> data, int pos, int size);

View File

@@ -8,8 +8,8 @@
#include <vector>
#include "absl/status/status.h"
#include "app/core/constants.h"
#include "app/gfx/snes_tile.h"
#include "util/macro.h"
namespace yaze {
namespace gfx {
@@ -90,11 +90,11 @@ absl::Status LoadScr(std::string_view filename, uint8_t input_value,
i += 2) {
auto b1_pos = (i - (input_value * 0x400));
map_data[b1_pos] = gfx::TileInfoToShort(
gfx::GetTilesInfo((ushort)scr_data[md + (i * 2)]));
gfx::GetTilesInfo((uint16_t)scr_data[md + (i * 2)]));
auto b2_pos = (i - (input_value * 0x400) + 1);
map_data[b2_pos] = gfx::TileInfoToShort(
gfx::GetTilesInfo((ushort)scr_data[md + (i * 2) + 2]));
gfx::GetTilesInfo((uint16_t)scr_data[md + (i * 2) + 2]));
}
// 0x900
@@ -111,7 +111,7 @@ absl::Status LoadScr(std::string_view filename, uint8_t input_value,
for (int i = 0; i < 0x1000 - offset; i++) {
map_data[i] = gfx::TileInfoToShort(
gfx::GetTilesInfo((ushort)scr_data[((i + offset) * 2)]));
gfx::GetTilesInfo((uint16_t)scr_data[((i + offset) * 2)]));
}
}
return absl::OkStatus();
@@ -144,9 +144,9 @@ absl::Status DrawScrWithCgx(uint8_t bpp, std::vector<uint8_t>& map_data,
if (bpp != 8) {
map_bitmap_data[index] =
(uchar)((pixel & 0xFF) + t.palette_ * 16);
(uint8_t)((pixel & 0xFF) + t.palette_ * 16);
} else {
map_bitmap_data[index] = (uchar)(pixel & 0xFF);
map_bitmap_data[index] = (uint8_t)(pixel & 0xFF);
}
}
}

View File

@@ -10,9 +10,9 @@
#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/core/constants.h"
#include "app/gfx/snes_color.h"
#include "imgui/imgui.h"
#include "util/macro.h"
namespace yaze {
namespace gfx {
@@ -224,8 +224,8 @@ SnesPalette::SnesPalette(char *data) {
assert((sizeof(data) % 4 == 0) && (sizeof(data) <= 32));
for (unsigned i = 0; i < sizeof(data); i += 2) {
SnesColor col;
col.set_snes(static_cast<uchar>(data[i + 1]) << 8);
col.set_snes(col.snes() | static_cast<uchar>(data[i]));
col.set_snes(static_cast<uint8_t>(data[i + 1]) << 8);
col.set_snes(col.snes() | static_cast<uint8_t>(data[i]));
snes_color mColor = ConvertSnesToRgb(col.snes());
col.set_rgb(ImVec4(mColor.red, mColor.green, mColor.blue, 1.f));
colors.push_back(col);
@@ -271,7 +271,7 @@ SnesPalette ReadPaletteFromRom(int offset, int num_colors, const uint8_t *rom) {
std::vector<gfx::SnesColor> colors(num_colors);
while (color_offset < num_colors) {
short color = (ushort)((rom[offset + 1]) << 8) | rom[offset];
short color = (uint16_t)((rom[offset + 1]) << 8) | rom[offset];
snes_color new_color;
new_color.red = (color & 0x1F) * 8;
new_color.green = ((color >> 5) & 0x1F) * 8;

View File

@@ -9,10 +9,10 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/core/constants.h"
#include "app/gfx/snes_color.h"
#include "imgui/imgui.h"
#include "snes_color.h"
#include "util/macro.h"
namespace yaze {
namespace gfx {

View File

@@ -5,22 +5,22 @@
#include <stdexcept>
#include <vector>
#include "app/core/constants.h"
#include "util/macro.h"
namespace yaze {
namespace gfx {
// Bit set for object priority
constexpr ushort TilePriorityBit = 0x2000;
constexpr uint16_t TilePriorityBit = 0x2000;
// Bit set for object hflip
constexpr ushort TileHFlipBit = 0x4000;
constexpr uint16_t TileHFlipBit = 0x4000;
// Bit set for object vflip
constexpr ushort TileVFlipBit = 0x8000;
constexpr uint16_t TileVFlipBit = 0x8000;
// Bits used for tile name
constexpr ushort TileNameMask = 0x03FF;
constexpr uint16_t TileNameMask = 0x03FF;
snes_tile8 UnpackBppTile(const std::vector<uint8_t>& data,
const uint32_t offset, const uint32_t bpp) {