Refactor FourCC magic uses
- Use new fourcc_t type - Improves compiler compatibility by removing multi chars
This commit is contained in:
parent
4daa3f5a52
commit
a86d7173e1
|
@ -223,7 +223,7 @@ void AudioSystem::UnregisterClient(size_t index) {
|
|||
}
|
||||
|
||||
bool AudioSystem::Save(ByteStream* stream) {
|
||||
stream->Write('XAUD');
|
||||
stream->Write(kAudioSaveSignature);
|
||||
|
||||
// Count the number of used clients first.
|
||||
// Any gaps should be handled gracefully.
|
||||
|
@ -251,7 +251,7 @@ bool AudioSystem::Save(ByteStream* stream) {
|
|||
}
|
||||
|
||||
bool AudioSystem::Restore(ByteStream* stream) {
|
||||
if (stream->Read<uint32_t>() != 'XAUD') {
|
||||
if (stream->Read<uint32_t>() != kAudioSaveSignature) {
|
||||
XELOGE("AudioSystem::Restore - Invalid magic value!");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
namespace xe {
|
||||
namespace apu {
|
||||
|
||||
constexpr fourcc_t kAudioSaveSignature = make_fourcc("XAUD");
|
||||
|
||||
class AudioDriver;
|
||||
class XmaDecoder;
|
||||
|
||||
|
|
|
@ -432,12 +432,12 @@ void Processor::LowerIrql(Irql old_value) {
|
|||
}
|
||||
|
||||
bool Processor::Save(ByteStream* stream) {
|
||||
stream->Write('PROC');
|
||||
stream->Write(kProcessorSaveSignature);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Processor::Restore(ByteStream* stream) {
|
||||
if (stream->Read<uint32_t>() != 'PROC') {
|
||||
if (stream->Read<uint32_t>() != kProcessorSaveSignature) {
|
||||
XELOGE("Processor::Restore - Invalid magic value!");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ DECLARE_bool(debug);
|
|||
namespace xe {
|
||||
namespace cpu {
|
||||
|
||||
constexpr fourcc_t kProcessorSaveSignature = make_fourcc("PROC");
|
||||
|
||||
class Breakpoint;
|
||||
class StackWalker;
|
||||
class XexModule;
|
||||
|
|
|
@ -899,9 +899,9 @@ bool XexModule::Load(const std::string_view name, const std::string_view path,
|
|||
const void* xex_addr, size_t xex_length) {
|
||||
auto src_header = reinterpret_cast<const xex2_header*>(xex_addr);
|
||||
|
||||
if (src_header->magic == 'XEX1') {
|
||||
if (src_header->magic == kXEX1Signature) {
|
||||
xex_format_ = kFormatXex1;
|
||||
} else if (src_header->magic == 'XEX2') {
|
||||
} else if (src_header->magic == kXEX2Signature) {
|
||||
xex_format_ = kFormatXex2;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -25,6 +25,10 @@ class KernelState;
|
|||
namespace xe {
|
||||
namespace cpu {
|
||||
|
||||
constexpr fourcc_t kXEX1Signature = make_fourcc("XEX1");
|
||||
constexpr fourcc_t kXEX2Signature = make_fourcc("XEX2");
|
||||
constexpr fourcc_t kElfSignature = make_fourcc(0x7F, 'E', 'L', 'F');
|
||||
|
||||
class Runtime;
|
||||
|
||||
class XexModule : public xe::cpu::Module {
|
||||
|
|
|
@ -420,7 +420,7 @@ bool Emulator::SaveToFile(const std::filesystem::path& path) {
|
|||
|
||||
// Save the emulator state to a file
|
||||
ByteStream stream(map->data(), map->size());
|
||||
stream.Write('XSAV');
|
||||
stream.Write(kEmulatorSaveSignature);
|
||||
stream.Write(title_id_.has_value());
|
||||
if (title_id_.has_value()) {
|
||||
stream.Write(title_id_.value());
|
||||
|
@ -454,7 +454,7 @@ bool Emulator::RestoreFromFile(const std::filesystem::path& path) {
|
|||
|
||||
auto lock = global_critical_region::AcquireDirect();
|
||||
ByteStream stream(map->data(), map->size());
|
||||
if (stream.Read<uint32_t>() != 'XSAV') {
|
||||
if (stream.Read<uint32_t>() != kEmulatorSaveSignature) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@ class Window;
|
|||
|
||||
namespace xe {
|
||||
|
||||
constexpr fourcc_t kEmulatorSaveSignature = make_fourcc("XSAV");
|
||||
|
||||
// The main type that runs the whole emulator.
|
||||
// This is responsible for initializing and managing all the various subsystems.
|
||||
class Emulator {
|
||||
|
|
|
@ -824,8 +824,8 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(RingBuffer* reader,
|
|||
// VdSwap will post this to tell us we need to swap the screen/fire an
|
||||
// interrupt.
|
||||
// 63 words here, but only the first has any data.
|
||||
uint32_t magic = reader->ReadAndSwap<uint32_t>();
|
||||
assert_true(magic == 'SWAP');
|
||||
uint32_t magic = reader->ReadAndSwap<fourcc_t>();
|
||||
assert_true(magic == kSwapSignature);
|
||||
|
||||
// TODO(benvanik): only swap frontbuffer ptr.
|
||||
uint32_t frontbuffer_ptr = reader->ReadAndSwap<uint32_t>();
|
||||
|
|
|
@ -30,7 +30,7 @@ void TextureDump(const TextureInfo& src, void* buffer, size_t length) {
|
|||
struct {
|
||||
uint32_t size;
|
||||
uint32_t flags;
|
||||
uint32_t fourcc;
|
||||
be<fourcc_t> fourcc;
|
||||
uint32_t rgb_bit_count;
|
||||
uint32_t r_bit_mask;
|
||||
uint32_t g_bit_mask;
|
||||
|
@ -59,17 +59,17 @@ void TextureDump(const TextureInfo& src, void* buffer, size_t length) {
|
|||
switch (src.format) {
|
||||
case xenos::TextureFormat::k_DXT1: {
|
||||
dds_header.pixel_format.flags = 0x4u;
|
||||
dds_header.pixel_format.fourcc = '1TXD';
|
||||
dds_header.pixel_format.fourcc = make_fourcc("DXT1");
|
||||
break;
|
||||
}
|
||||
case xenos::TextureFormat::k_DXT2_3: {
|
||||
dds_header.pixel_format.flags = 0x4u;
|
||||
dds_header.pixel_format.fourcc = '3TXD';
|
||||
dds_header.pixel_format.fourcc = make_fourcc("DXT3");
|
||||
break;
|
||||
}
|
||||
case xenos::TextureFormat::k_DXT4_5: {
|
||||
dds_header.pixel_format.flags = 0x4u;
|
||||
dds_header.pixel_format.fourcc = '5TXD';
|
||||
dds_header.pixel_format.fourcc = make_fourcc("DXT5");
|
||||
break;
|
||||
}
|
||||
case xenos::TextureFormat::k_8_8_8_8: {
|
||||
|
@ -100,7 +100,7 @@ void TextureDump(const TextureInfo& src, void* buffer, size_t length) {
|
|||
|
||||
FILE* handle = filesystem::OpenFile(path, "wb");
|
||||
if (handle) {
|
||||
const uint32_t signature = ' SDD';
|
||||
const char signature[4] = {'D', 'D', 'S', ' '};
|
||||
fwrite(&signature, sizeof(signature), 1, handle);
|
||||
fwrite(&dds_header, sizeof(dds_header), 1, handle);
|
||||
fwrite(buffer, 1, length, handle);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "xenia/base/assert.h"
|
||||
#include "xenia/base/byte_order.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/base/memory.h"
|
||||
#include "xenia/base/platform.h"
|
||||
|
||||
namespace xe {
|
||||
|
@ -27,6 +28,8 @@ namespace xenos {
|
|||
// in bit fields (registers are 32-bit, and the microcode consists of triples of
|
||||
// 32-bit words).
|
||||
|
||||
constexpr fourcc_t kSwapSignature = make_fourcc("SWAP");
|
||||
|
||||
enum class ShaderType : uint32_t {
|
||||
kVertex = 0,
|
||||
kPixel = 1,
|
||||
|
|
|
@ -758,7 +758,7 @@ void KernelState::CompleteOverlappedDeferredEx(
|
|||
|
||||
bool KernelState::Save(ByteStream* stream) {
|
||||
XELOGD("Serializing the kernel...");
|
||||
stream->Write('KRNL');
|
||||
stream->Write(kKernelSaveSignature);
|
||||
|
||||
// Save the object table
|
||||
object_table_.Save(stream);
|
||||
|
@ -828,7 +828,7 @@ bool KernelState::Save(ByteStream* stream) {
|
|||
|
||||
bool KernelState::Restore(ByteStream* stream) {
|
||||
// Check the magic value.
|
||||
if (stream->Read<uint32_t>() != 'KRNL') {
|
||||
if (stream->Read<uint32_t>() != kKernelSaveSignature) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ class Processor;
|
|||
namespace xe {
|
||||
namespace kernel {
|
||||
|
||||
constexpr fourcc_t kKernelSaveSignature = make_fourcc("KRNL");
|
||||
|
||||
class Dispatcher;
|
||||
class XHostThread;
|
||||
class KernelModule;
|
||||
|
|
|
@ -134,13 +134,15 @@ X_STATUS UserModule::LoadFromFile(const std::string_view path) {
|
|||
X_STATUS UserModule::LoadFromMemory(const void* addr, const size_t length) {
|
||||
auto processor = kernel_state()->processor();
|
||||
|
||||
auto magic = xe::load_and_swap<uint32_t>(addr);
|
||||
if (magic == 'XEX2' || magic == 'XEX1') {
|
||||
be<fourcc_t> magic;
|
||||
magic.value = xe::load<fourcc_t>(addr);
|
||||
if (magic == xe::cpu::kXEX2Signature || magic == xe::cpu::kXEX1Signature) {
|
||||
module_format_ = kModuleFormatXex;
|
||||
} else if (magic == 0x7F454C46 /* 0x7F 'ELF' */) {
|
||||
} else if (magic == xe::cpu::kElfSignature) {
|
||||
module_format_ = kModuleFormatElf;
|
||||
} else {
|
||||
auto magic16 = xe::load_and_swap<uint16_t>(addr);
|
||||
be<uint16_t> magic16;
|
||||
magic16.value = xe::load<uint16_t>(addr);
|
||||
if (magic16 == 0x4D5A) {
|
||||
XELOGE("XNA executables are not yet implemented");
|
||||
return X_STATUS_NOT_IMPLEMENTED;
|
||||
|
|
|
@ -13,9 +13,9 @@ namespace xe {
|
|||
namespace kernel {
|
||||
namespace util {
|
||||
|
||||
constexpr uint32_t kGameInfoExecMagic = 'EXEC';
|
||||
constexpr uint32_t kGameInfoCommMagic = 'COMM';
|
||||
constexpr uint32_t kGameInfoTitlMagic = 'TITL';
|
||||
constexpr fourcc_t kGameInfoExecSignature = make_fourcc("EXEC");
|
||||
constexpr fourcc_t kGameInfoCommSignature = make_fourcc("COMM");
|
||||
constexpr fourcc_t kGameInfoTitlSignature = make_fourcc("TITL");
|
||||
|
||||
GameInfoWrapper::GameInfoWrapper(const uint8_t* data, size_t data_size)
|
||||
: data_(data), data_size_(data_size) {
|
||||
|
@ -31,7 +31,7 @@ GameInfoWrapper::GameInfoWrapper(const uint8_t* data, size_t data_size)
|
|||
data_offset += sizeof(GameInfoBlockHeader);
|
||||
|
||||
switch (block_header->magic) {
|
||||
case kGameInfoExecMagic:
|
||||
case kGameInfoExecSignature:
|
||||
exec_.virtual_titleid =
|
||||
reinterpret_cast<const char*>(data_ + data_offset);
|
||||
data_offset += exec_.VirtualTitleIdLength + 1;
|
||||
|
@ -41,12 +41,12 @@ GameInfoWrapper::GameInfoWrapper(const uint8_t* data, size_t data_size)
|
|||
reinterpret_cast<const char*>(data_ + data_offset);
|
||||
data_offset += exec_.BuildDescriptionLength + 1;
|
||||
break;
|
||||
case kGameInfoCommMagic:
|
||||
case kGameInfoCommSignature:
|
||||
assert_true(block_header->block_size == sizeof(GameInfoBlockComm));
|
||||
comm_ = reinterpret_cast<const GameInfoBlockComm*>(data_ + data_offset);
|
||||
data_offset += block_header->block_size;
|
||||
break;
|
||||
case kGameInfoTitlMagic:
|
||||
case kGameInfoTitlSignature:
|
||||
assert_true(block_header->block_size == sizeof(GameInfoBlockTitl));
|
||||
titl_ = reinterpret_cast<const GameInfoBlockTitl*>(data_ + data_offset);
|
||||
data_offset += block_header->block_size;
|
||||
|
|
|
@ -13,9 +13,9 @@ namespace xe {
|
|||
namespace kernel {
|
||||
namespace util {
|
||||
|
||||
constexpr uint32_t kXdbfMagicXdbf = 'XDBF';
|
||||
constexpr uint32_t kXdbfMagicXstc = 'XSTC';
|
||||
constexpr uint32_t kXdbfMagicXstr = 'XSTR';
|
||||
constexpr fourcc_t kXdbfSignatureXdbf = make_fourcc("XDBF");
|
||||
constexpr fourcc_t kXdbfSignatureXstc = make_fourcc("XSTC");
|
||||
constexpr fourcc_t kXdbfSignatureXstr = make_fourcc("XSTR");
|
||||
|
||||
XdbfWrapper::XdbfWrapper(const uint8_t* data, size_t data_size)
|
||||
: data_(data), data_size_(data_size) {
|
||||
|
@ -28,7 +28,7 @@ XdbfWrapper::XdbfWrapper(const uint8_t* data, size_t data_size)
|
|||
|
||||
header_ = reinterpret_cast<const XbdfHeader*>(ptr);
|
||||
ptr += sizeof(XbdfHeader);
|
||||
if (header_->magic != kXdbfMagicXdbf) {
|
||||
if (header_->magic != kXdbfSignatureXdbf) {
|
||||
data_ = nullptr;
|
||||
return;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ std::string XdbfWrapper::GetStringTableEntry(XLanguage language,
|
|||
|
||||
auto xstr_head =
|
||||
reinterpret_cast<const XdbfXstrHeader*>(language_block.buffer);
|
||||
assert_true(xstr_head->magic == kXdbfMagicXstr);
|
||||
assert_true(xstr_head->magic == kXdbfSignatureXstr);
|
||||
assert_true(xstr_head->version == 1);
|
||||
|
||||
const uint8_t* ptr = language_block.buffer + sizeof(XdbfXstrHeader);
|
||||
|
@ -94,7 +94,7 @@ XLanguage XdbfGameData::default_language() const {
|
|||
return XLanguage::kEnglish;
|
||||
}
|
||||
auto xstc = reinterpret_cast<const XdbfXstc*>(block.buffer);
|
||||
assert_true(xstc->magic == kXdbfMagicXstc);
|
||||
assert_true(xstc->magic == kXdbfSignatureXstc);
|
||||
return static_cast<XLanguage>(static_cast<uint32_t>(xstc->default_language));
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ X_HRESULT XamApp::DispatchMessageSync(uint32_t message, uint32_t buffer_ptr,
|
|||
if (!e || !buffer || !extra) {
|
||||
return X_E_INVALIDARG;
|
||||
}
|
||||
assert_true(extra->magic == 'XEN\0');
|
||||
assert_true(extra->magic == kXObjSignature);
|
||||
if (data->buffer_size) {
|
||||
std::memset(buffer, 0, data->buffer_size);
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ dword_result_t XamContentAggregateCreateEnumerator(qword_t xuid,
|
|||
return result;
|
||||
}
|
||||
|
||||
extra->magic = 'XEN\0';
|
||||
extra->magic = kXObjSignature;
|
||||
extra->handle = e->handle();
|
||||
|
||||
if (!device_info || device_info->device_type == DeviceType::HDD) {
|
||||
|
|
|
@ -415,7 +415,7 @@ void VdSwap(lpvoid_t buffer_ptr, // ptr into primary ringbuffer
|
|||
dwords[offset++] = gpu_fetch.dword_5;
|
||||
|
||||
dwords[offset++] = xenos::MakePacketType3(xenos::PM4_XE_SWAP, 4);
|
||||
dwords[offset++] = 'SWAP';
|
||||
dwords[offset++] = xe::gpu::xenos::kSwapSignature;
|
||||
dwords[offset++] = frontbuffer_physical_address;
|
||||
|
||||
dwords[offset++] = *width;
|
||||
|
|
|
@ -71,7 +71,7 @@ uint32_t XModule::GetHandleFromHModule(void* hmodule) {
|
|||
bool XModule::Save(ByteStream* stream) {
|
||||
XELOGD("XModule {:08X} ({})", handle(), path());
|
||||
|
||||
stream->Write('XMOD');
|
||||
stream->Write(kModuleSaveSignature);
|
||||
|
||||
stream->Write(path());
|
||||
stream->Write(hmodule_ptr_);
|
||||
|
@ -85,7 +85,7 @@ bool XModule::Save(ByteStream* stream) {
|
|||
|
||||
object_ref<XModule> XModule::Restore(KernelState* kernel_state,
|
||||
ByteStream* stream) {
|
||||
if (stream->Read<uint32_t>() != 'XMOD') {
|
||||
if (stream->Read<uint32_t>() != kModuleSaveSignature) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
namespace xe {
|
||||
namespace kernel {
|
||||
|
||||
constexpr fourcc_t kModuleSaveSignature = make_fourcc("XMOD");
|
||||
|
||||
// https://www.nirsoft.net/kernel_struct/vista/LDR_DATA_TABLE_ENTRY.html
|
||||
// HMODULE points to this struct!
|
||||
struct X_LDR_DATA_TABLE_ENTRY {
|
||||
|
|
|
@ -381,7 +381,7 @@ object_ref<XObject> XObject::GetNativeObject(KernelState* kernel_state,
|
|||
as_type = header->type;
|
||||
}
|
||||
|
||||
if (header->wait_list_flink == 'XEN\0') {
|
||||
if (header->wait_list_flink == kXObjSignature) {
|
||||
// Already initialized.
|
||||
// TODO: assert if the type of the object != as_type
|
||||
uint32_t handle = header->wait_list_blink;
|
||||
|
|
|
@ -27,6 +27,8 @@ class Emulator;
|
|||
namespace xe {
|
||||
namespace kernel {
|
||||
|
||||
constexpr fourcc_t kXObjSignature = make_fourcc('X', 'E', 'N', '\0');
|
||||
|
||||
class KernelState;
|
||||
|
||||
template <typename T>
|
||||
|
@ -214,7 +216,7 @@ class XObject {
|
|||
|
||||
// Stash native pointer into X_DISPATCH_HEADER
|
||||
static void StashHandle(X_DISPATCH_HEADER* header, uint32_t handle) {
|
||||
header->wait_list_flink = 'XEN\0';
|
||||
header->wait_list_flink = kXObjSignature;
|
||||
header->wait_list_blink = handle;
|
||||
}
|
||||
|
||||
|
|
|
@ -915,7 +915,7 @@ bool XThread::Save(ByteStream* stream) {
|
|||
return false;
|
||||
}
|
||||
|
||||
stream->Write('THRD');
|
||||
stream->Write(kThreadSaveSignature);
|
||||
stream->Write(thread_name_);
|
||||
|
||||
ThreadSavedState state;
|
||||
|
@ -971,7 +971,7 @@ object_ref<XThread> XThread::Restore(KernelState* kernel_state,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (stream->Read<uint32_t>() != 'THRD') {
|
||||
if (stream->Read<uint32_t>() != kThreadSaveSignature) {
|
||||
XELOGE("Could not restore XThread - invalid magic!");
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
namespace xe {
|
||||
namespace kernel {
|
||||
|
||||
constexpr fourcc_t kThreadSaveSignature = make_fourcc("THRD");
|
||||
|
||||
class XEvent;
|
||||
|
||||
constexpr uint32_t X_CREATE_SUSPENDED = 0x00000001;
|
||||
|
|
Loading…
Reference in New Issue