diff --git a/src/xenia/apu/audio_system.cc b/src/xenia/apu/audio_system.cc index 67bf34ae3..c137a4853 100644 --- a/src/xenia/apu/audio_system.cc +++ b/src/xenia/apu/audio_system.cc @@ -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() != 'XAUD') { + if (stream->Read() != kAudioSaveSignature) { XELOGE("AudioSystem::Restore - Invalid magic value!"); return false; } diff --git a/src/xenia/apu/audio_system.h b/src/xenia/apu/audio_system.h index 014a1dc8d..db6a29d37 100644 --- a/src/xenia/apu/audio_system.h +++ b/src/xenia/apu/audio_system.h @@ -23,6 +23,8 @@ namespace xe { namespace apu { +constexpr fourcc_t kAudioSaveSignature = make_fourcc("XAUD"); + class AudioDriver; class XmaDecoder; diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index 95b016d17..6aae55a6c 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -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() != 'PROC') { + if (stream->Read() != kProcessorSaveSignature) { XELOGE("Processor::Restore - Invalid magic value!"); return false; } diff --git a/src/xenia/cpu/processor.h b/src/xenia/cpu/processor.h index eb395fb56..2a004548c 100644 --- a/src/xenia/cpu/processor.h +++ b/src/xenia/cpu/processor.h @@ -34,6 +34,8 @@ DECLARE_bool(debug); namespace xe { namespace cpu { +constexpr fourcc_t kProcessorSaveSignature = make_fourcc("PROC"); + class Breakpoint; class StackWalker; class XexModule; diff --git a/src/xenia/cpu/xex_module.cc b/src/xenia/cpu/xex_module.cc index a9a1fd83c..8caeec5af 100644 --- a/src/xenia/cpu/xex_module.cc +++ b/src/xenia/cpu/xex_module.cc @@ -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(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; diff --git a/src/xenia/cpu/xex_module.h b/src/xenia/cpu/xex_module.h index 135eaf167..9834a675f 100644 --- a/src/xenia/cpu/xex_module.h +++ b/src/xenia/cpu/xex_module.h @@ -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 { diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index 4ee98cc24..36a56c946 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -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() != 'XSAV') { + if (stream.Read() != kEmulatorSaveSignature) { return false; } diff --git a/src/xenia/emulator.h b/src/xenia/emulator.h index 3b410e889..cd86e1f81 100644 --- a/src/xenia/emulator.h +++ b/src/xenia/emulator.h @@ -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 { diff --git a/src/xenia/gpu/command_processor.cc b/src/xenia/gpu/command_processor.cc index b424e1687..d0ac7757e 100644 --- a/src/xenia/gpu/command_processor.cc +++ b/src/xenia/gpu/command_processor.cc @@ -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(); - assert_true(magic == 'SWAP'); + uint32_t magic = reader->ReadAndSwap(); + assert_true(magic == kSwapSignature); // TODO(benvanik): only swap frontbuffer ptr. uint32_t frontbuffer_ptr = reader->ReadAndSwap(); diff --git a/src/xenia/gpu/texture_dump.cc b/src/xenia/gpu/texture_dump.cc index a8e0692b5..d105d3cbf 100644 --- a/src/xenia/gpu/texture_dump.cc +++ b/src/xenia/gpu/texture_dump.cc @@ -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; 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); diff --git a/src/xenia/gpu/xenos.h b/src/xenia/gpu/xenos.h index 24d7a9a98..34784662a 100644 --- a/src/xenia/gpu/xenos.h +++ b/src/xenia/gpu/xenos.h @@ -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, diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index a482b2ca4..c0d2e3d20 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -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() != 'KRNL') { + if (stream->Read() != kKernelSaveSignature) { return false; } diff --git a/src/xenia/kernel/kernel_state.h b/src/xenia/kernel/kernel_state.h index 2b4187a07..796d2dada 100644 --- a/src/xenia/kernel/kernel_state.h +++ b/src/xenia/kernel/kernel_state.h @@ -41,6 +41,8 @@ class Processor; namespace xe { namespace kernel { +constexpr fourcc_t kKernelSaveSignature = make_fourcc("KRNL"); + class Dispatcher; class XHostThread; class KernelModule; diff --git a/src/xenia/kernel/user_module.cc b/src/xenia/kernel/user_module.cc index dc007991b..a85a919c6 100644 --- a/src/xenia/kernel/user_module.cc +++ b/src/xenia/kernel/user_module.cc @@ -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(addr); - if (magic == 'XEX2' || magic == 'XEX1') { + be magic; + magic.value = xe::load(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(addr); + be magic16; + magic16.value = xe::load(addr); if (magic16 == 0x4D5A) { XELOGE("XNA executables are not yet implemented"); return X_STATUS_NOT_IMPLEMENTED; diff --git a/src/xenia/kernel/util/gameinfo_utils.cc b/src/xenia/kernel/util/gameinfo_utils.cc index aabd4f0d0..b69c2e63f 100644 --- a/src/xenia/kernel/util/gameinfo_utils.cc +++ b/src/xenia/kernel/util/gameinfo_utils.cc @@ -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(data_ + data_offset); data_offset += exec_.VirtualTitleIdLength + 1; @@ -41,12 +41,12 @@ GameInfoWrapper::GameInfoWrapper(const uint8_t* data, size_t data_size) reinterpret_cast(data_ + data_offset); data_offset += exec_.BuildDescriptionLength + 1; break; - case kGameInfoCommMagic: + case kGameInfoCommSignature: assert_true(block_header->block_size == sizeof(GameInfoBlockComm)); comm_ = reinterpret_cast(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(data_ + data_offset); data_offset += block_header->block_size; diff --git a/src/xenia/kernel/util/xdbf_utils.cc b/src/xenia/kernel/util/xdbf_utils.cc index 4e8c83ea3..c5e6fd217 100644 --- a/src/xenia/kernel/util/xdbf_utils.cc +++ b/src/xenia/kernel/util/xdbf_utils.cc @@ -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(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(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(block.buffer); - assert_true(xstc->magic == kXdbfMagicXstc); + assert_true(xstc->magic == kXdbfSignatureXstc); return static_cast(static_cast(xstc->default_language)); } diff --git a/src/xenia/kernel/xam/apps/xam_app.cc b/src/xenia/kernel/xam/apps/xam_app.cc index 29ec86717..a565a49ac 100644 --- a/src/xenia/kernel/xam/apps/xam_app.cc +++ b/src/xenia/kernel/xam/apps/xam_app.cc @@ -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); } diff --git a/src/xenia/kernel/xam/xam_content_aggregate.cc b/src/xenia/kernel/xam/xam_content_aggregate.cc index 79a025c28..39f4bb2b5 100644 --- a/src/xenia/kernel/xam/xam_content_aggregate.cc +++ b/src/xenia/kernel/xam/xam_content_aggregate.cc @@ -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) { diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc index de2ff6761..e05415570 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc @@ -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; diff --git a/src/xenia/kernel/xmodule.cc b/src/xenia/kernel/xmodule.cc index 06510cfee..5807fbc88 100644 --- a/src/xenia/kernel/xmodule.cc +++ b/src/xenia/kernel/xmodule.cc @@ -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::Restore(KernelState* kernel_state, ByteStream* stream) { - if (stream->Read() != 'XMOD') { + if (stream->Read() != kModuleSaveSignature) { return nullptr; } diff --git a/src/xenia/kernel/xmodule.h b/src/xenia/kernel/xmodule.h index 8b558681a..0a937a73b 100644 --- a/src/xenia/kernel/xmodule.h +++ b/src/xenia/kernel/xmodule.h @@ -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 { diff --git a/src/xenia/kernel/xobject.cc b/src/xenia/kernel/xobject.cc index 3675a1bce..4909dbaa1 100644 --- a/src/xenia/kernel/xobject.cc +++ b/src/xenia/kernel/xobject.cc @@ -381,7 +381,7 @@ object_ref 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; diff --git a/src/xenia/kernel/xobject.h b/src/xenia/kernel/xobject.h index 163b6afe4..aaf11c881 100644 --- a/src/xenia/kernel/xobject.h +++ b/src/xenia/kernel/xobject.h @@ -27,6 +27,8 @@ class Emulator; namespace xe { namespace kernel { +constexpr fourcc_t kXObjSignature = make_fourcc('X', 'E', 'N', '\0'); + class KernelState; template @@ -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; } diff --git a/src/xenia/kernel/xthread.cc b/src/xenia/kernel/xthread.cc index 46f1ef961..8776b43dc 100644 --- a/src/xenia/kernel/xthread.cc +++ b/src/xenia/kernel/xthread.cc @@ -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::Restore(KernelState* kernel_state, return nullptr; } - if (stream->Read() != 'THRD') { + if (stream->Read() != kThreadSaveSignature) { XELOGE("Could not restore XThread - invalid magic!"); return nullptr; } diff --git a/src/xenia/kernel/xthread.h b/src/xenia/kernel/xthread.h index 78a6591a1..045769bda 100644 --- a/src/xenia/kernel/xthread.h +++ b/src/xenia/kernel/xthread.h @@ -25,6 +25,8 @@ namespace xe { namespace kernel { +constexpr fourcc_t kThreadSaveSignature = make_fourcc("THRD"); + class XEvent; constexpr uint32_t X_CREATE_SUSPENDED = 0x00000001;