unique_ptr'ing things and removing some XECLEANUP.
This commit is contained in:
parent
244e8a8745
commit
c59d053404
|
@ -10,22 +10,16 @@
|
|||
#include <xenia/apu/apu.h>
|
||||
#include <xenia/apu/apu-private.h>
|
||||
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::apu;
|
||||
|
||||
|
||||
DEFINE_string(apu, "any",
|
||||
"Audio system. Use: [any, nop, xaudio2]");
|
||||
|
||||
DEFINE_string(apu, "any", "Audio system. Use: [any, nop, xaudio2]");
|
||||
|
||||
#include <xenia/apu/nop/nop_apu.h>
|
||||
AudioSystem* xe::apu::CreateNop(Emulator* emulator) {
|
||||
std::unique_ptr<AudioSystem> xe::apu::CreateNop(Emulator* emulator) {
|
||||
return xe::apu::nop::Create(emulator);
|
||||
}
|
||||
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
#include <xenia/apu/xaudio2/xaudio2_apu.h>
|
||||
AudioSystem* xe::apu::CreateXAudio2(Emulator* emulator) {
|
||||
|
@ -33,17 +27,16 @@ AudioSystem* xe::apu::CreateXAudio2(Emulator* emulator) {
|
|||
}
|
||||
#endif // WIN32
|
||||
|
||||
AudioSystem* xe::apu::Create(Emulator* emulator) {
|
||||
std::unique_ptr<AudioSystem> xe::apu::Create(Emulator* emulator) {
|
||||
if (FLAGS_apu.compare("nop") == 0) {
|
||||
return CreateNop(emulator);
|
||||
#if XE_PLATFORM_WIN32
|
||||
}
|
||||
else if (FLAGS_apu.compare("xaudio2") == 0) {
|
||||
} else if (FLAGS_apu.compare("xaudio2") == 0) {
|
||||
return CreateXAudio2(emulator);
|
||||
#endif // WIN32
|
||||
} else {
|
||||
// Create best available.
|
||||
AudioSystem* best = NULL;
|
||||
std::unique_ptr<AudioSystem> best;
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
best = CreateXAudio2(emulator);
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef XENIA_APU_APU_H_
|
||||
#define XENIA_APU_APU_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/apu/audio_system.h>
|
||||
|
||||
namespace xe {
|
||||
|
@ -19,12 +21,12 @@ class Emulator;
|
|||
namespace xe {
|
||||
namespace apu {
|
||||
|
||||
AudioSystem* Create(Emulator* emulator);
|
||||
std::unique_ptr<AudioSystem> Create(Emulator* emulator);
|
||||
|
||||
AudioSystem* CreateNop(Emulator* emulator);
|
||||
std::unique_ptr<AudioSystem> CreateNop(Emulator* emulator);
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
AudioSystem* CreateXAudio2(Emulator* emulator);
|
||||
std::unique_ptr<AudioSystem> CreateXAudio2(Emulator* emulator);
|
||||
#endif // WIN32
|
||||
|
||||
} // namespace apu
|
||||
|
|
|
@ -11,34 +11,30 @@
|
|||
|
||||
#include <xenia/apu/nop/nop_audio_system.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::apu;
|
||||
using namespace xe::apu::nop;
|
||||
|
||||
|
||||
namespace {
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
void CleanupOnShutdown() {
|
||||
}
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
}
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
}
|
||||
|
||||
AudioSystem* xe::apu::nop::Create(Emulator* emulator) {
|
||||
std::unique_ptr<AudioSystem> xe::apu::nop::Create(Emulator* emulator) {
|
||||
InitializeIfNeeded();
|
||||
return new NopAudioSystem(emulator);
|
||||
return std::make_unique<NopAudioSystem>(emulator);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef XENIA_APU_NOP_NOP_APU_H_
|
||||
#define XENIA_APU_NOP_NOP_APU_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
namespace xe {
|
||||
|
@ -21,7 +23,7 @@ namespace apu {
|
|||
class AudioSystem;
|
||||
namespace nop {
|
||||
|
||||
AudioSystem* Create(Emulator* emulator);
|
||||
std::unique_ptr<AudioSystem> Create(Emulator* emulator);
|
||||
|
||||
} // namespace nop
|
||||
} // namespace apu
|
||||
|
|
|
@ -11,34 +11,30 @@
|
|||
|
||||
#include <xenia/apu/xaudio2/xaudio2_audio_system.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::apu;
|
||||
using namespace xe::apu::xaudio2;
|
||||
|
||||
|
||||
namespace {
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
void CleanupOnShutdown() {
|
||||
}
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
}
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
}
|
||||
|
||||
AudioSystem* xe::apu::xaudio2::Create(Emulator* emulator) {
|
||||
std::unique_ptr<AudioSystem> xe::apu::xaudio2::Create(Emulator* emulator) {
|
||||
InitializeIfNeeded();
|
||||
return new XAudio2AudioSystem(emulator);
|
||||
return std::make_unique<XAudio2AudioSystem>(emulator);
|
||||
}
|
||||
|
|
|
@ -10,24 +10,23 @@
|
|||
#ifndef XENIA_APU_XAUDIO2_XAUDIO2_APU_H_
|
||||
#define XENIA_APU_XAUDIO2_XAUDIO2_APU_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
|
||||
XEDECLARECLASS1(xe, Emulator);
|
||||
XEDECLARECLASS2(xe, apu, AudioSystem);
|
||||
|
||||
namespace xe {
|
||||
class Emulator;
|
||||
} // namespace xe
|
||||
|
||||
namespace xe {
|
||||
namespace apu {
|
||||
class AudioSystem;
|
||||
namespace xaudio2 {
|
||||
|
||||
|
||||
AudioSystem* Create(Emulator* emulator);
|
||||
|
||||
std::unique_ptr<AudioSystem> Create(Emulator* emulator);
|
||||
|
||||
} // namespace xaudio2
|
||||
} // namespace apu
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_APU_XAUDIO2_XAUDIO2_APU_H_
|
||||
|
|
|
@ -18,6 +18,5 @@
|
|||
|
||||
#include <xenia/logging.h>
|
||||
#include <xenia/profiling.h>
|
||||
#include <xenia/types.h>
|
||||
|
||||
#endif // XENIA_COMMON_H_
|
||||
|
|
|
@ -17,4 +17,15 @@
|
|||
#include <xenia/core/socket.h>
|
||||
#include <xenia/memory.h>
|
||||
|
||||
// TODO(benvanik): remove.
|
||||
#define XEFAIL() goto XECLEANUP
|
||||
#define XEEXPECTZERO(expr) \
|
||||
if ((expr) != 0) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
#define XEEXPECTNOTNULL(expr) \
|
||||
if ((expr) == NULL) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
|
||||
#endif // XENIA_CORE_H_
|
||||
|
|
|
@ -33,18 +33,7 @@ using namespace xe::kernel::fs;
|
|||
using namespace xe::ui;
|
||||
|
||||
Emulator::Emulator(const std::wstring& command_line)
|
||||
: command_line_(command_line),
|
||||
main_window_(0),
|
||||
memory_(0),
|
||||
processor_(0),
|
||||
audio_system_(0),
|
||||
graphics_system_(0),
|
||||
input_system_(0),
|
||||
export_resolver_(0),
|
||||
file_system_(0),
|
||||
kernel_state_(0),
|
||||
xam_(0),
|
||||
xboxkrnl_(0) {}
|
||||
: command_line_(command_line) {}
|
||||
|
||||
Emulator::~Emulator() {
|
||||
// Note that we delete things in the reverse order they were initialized.
|
||||
|
@ -60,23 +49,23 @@ Emulator::~Emulator() {
|
|||
|
||||
debug_agent_.reset();
|
||||
|
||||
delete xam_;
|
||||
delete xboxkrnl_;
|
||||
delete kernel_state_;
|
||||
xam_.reset();
|
||||
xboxkrnl_.reset();
|
||||
kernel_state_.reset();
|
||||
|
||||
delete file_system_;
|
||||
file_system_.reset();
|
||||
|
||||
delete input_system_;
|
||||
input_system_.reset();
|
||||
|
||||
// Give the systems time to shutdown before we delete them.
|
||||
graphics_system_->Shutdown();
|
||||
audio_system_->Shutdown();
|
||||
delete graphics_system_;
|
||||
delete audio_system_;
|
||||
graphics_system_.reset();
|
||||
audio_system_.reset();
|
||||
|
||||
delete processor_;
|
||||
processor_.reset();
|
||||
|
||||
delete export_resolver_;
|
||||
export_resolver_.reset();
|
||||
}
|
||||
|
||||
X_STATUS Emulator::Setup() {
|
||||
|
@ -84,63 +73,71 @@ X_STATUS Emulator::Setup() {
|
|||
|
||||
debug_agent_.reset(new DebugAgent(this));
|
||||
result = debug_agent_->Initialize();
|
||||
XEEXPECTZERO(result);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Create memory system first, as it is required for other systems.
|
||||
memory_ = new Memory();
|
||||
XEEXPECTNOTNULL(memory_);
|
||||
memory_ = std::make_unique<Memory>();
|
||||
result = memory_->Initialize();
|
||||
XEEXPECTZERO(result);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
memory_->set_trace_base(debug_agent_->trace_base());
|
||||
|
||||
// Shared export resolver used to attach and query for HLE exports.
|
||||
export_resolver_ = new ExportResolver();
|
||||
XEEXPECTNOTNULL(export_resolver_);
|
||||
export_resolver_ = std::make_unique<ExportResolver>();
|
||||
|
||||
// Initialize the CPU.
|
||||
processor_ = new Processor(this);
|
||||
XEEXPECTNOTNULL(processor_);
|
||||
processor_ = std::make_unique<Processor>(this);
|
||||
|
||||
// Initialize the APU.
|
||||
audio_system_ = xe::apu::Create(this);
|
||||
XEEXPECTNOTNULL(audio_system_);
|
||||
audio_system_ = std::move(xe::apu::Create(this));
|
||||
if (!audio_system_) {
|
||||
return X_STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Initialize the GPU.
|
||||
graphics_system_ = xe::gpu::Create(this);
|
||||
XEEXPECTNOTNULL(graphics_system_);
|
||||
graphics_system_ = std::move(xe::gpu::Create(this));
|
||||
if (!graphics_system_) {
|
||||
return X_STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Initialize the HID.
|
||||
input_system_ = xe::hid::Create(this);
|
||||
XEEXPECTNOTNULL(input_system_);
|
||||
input_system_ = std::move(xe::hid::Create(this));
|
||||
if (!input_system_) {
|
||||
return X_STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Setup the core components.
|
||||
result = processor_->Setup();
|
||||
XEEXPECTZERO(result);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = audio_system_->Setup();
|
||||
XEEXPECTZERO(result);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = graphics_system_->Setup();
|
||||
XEEXPECTZERO(result);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = input_system_->Setup();
|
||||
XEEXPECTZERO(result);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Bring up the virtual filesystem used by the kernel.
|
||||
file_system_ = new FileSystem();
|
||||
XEEXPECTNOTNULL(file_system_);
|
||||
file_system_ = std::make_unique<FileSystem>();
|
||||
|
||||
// Shared kernel state.
|
||||
kernel_state_ = new KernelState(this);
|
||||
XEEXPECTNOTNULL(kernel_state_);
|
||||
kernel_state_ = std::make_unique<KernelState>(this);
|
||||
|
||||
// HLE kernel modules.
|
||||
xboxkrnl_ = new XboxkrnlModule(this, kernel_state_);
|
||||
XEEXPECTNOTNULL(xboxkrnl_);
|
||||
xam_ = new XamModule(this, kernel_state_);
|
||||
XEEXPECTNOTNULL(xam_);
|
||||
xboxkrnl_ = std::make_unique<XboxkrnlModule>(this, kernel_state_);
|
||||
xam_ = std::make_unique<XamModule>(this, kernel_state_);
|
||||
|
||||
return result;
|
||||
|
||||
XECLEANUP:
|
||||
return result;
|
||||
}
|
||||
|
||||
void Emulator::set_main_window(Window* window) {
|
||||
|
|
|
@ -54,20 +54,22 @@ class Emulator {
|
|||
ui::Window* main_window() const { return main_window_; }
|
||||
void set_main_window(ui::Window* window);
|
||||
|
||||
Memory* memory() const { return memory_; }
|
||||
Memory* memory() const { return memory_.get(); }
|
||||
|
||||
DebugAgent* debug_agent() const { return debug_agent_.get(); }
|
||||
|
||||
cpu::Processor* processor() const { return processor_; }
|
||||
apu::AudioSystem* audio_system() const { return audio_system_; }
|
||||
gpu::GraphicsSystem* graphics_system() const { return graphics_system_; }
|
||||
hid::InputSystem* input_system() const { return input_system_; }
|
||||
cpu::Processor* processor() const { return processor_.get(); }
|
||||
apu::AudioSystem* audio_system() const { return audio_system_.get(); }
|
||||
gpu::GraphicsSystem* graphics_system() const {
|
||||
return graphics_system_.get();
|
||||
}
|
||||
hid::InputSystem* input_system() const { return input_system_.get(); }
|
||||
|
||||
ExportResolver* export_resolver() const { return export_resolver_; }
|
||||
kernel::fs::FileSystem* file_system() const { return file_system_; }
|
||||
ExportResolver* export_resolver() const { return export_resolver_.get(); }
|
||||
kernel::fs::FileSystem* file_system() const { return file_system_.get(); }
|
||||
|
||||
kernel::XboxkrnlModule* xboxkrnl() const { return xboxkrnl_; }
|
||||
kernel::XamModule* xam() const { return xam_; }
|
||||
kernel::XboxkrnlModule* xboxkrnl() const { return xboxkrnl_.get(); }
|
||||
kernel::XamModule* xam() const { return xam_.get(); }
|
||||
|
||||
X_STATUS Setup();
|
||||
|
||||
|
@ -82,23 +84,24 @@ class Emulator {
|
|||
|
||||
std::wstring command_line_;
|
||||
|
||||
// TODO(benvanik): remove from here?
|
||||
ui::Window* main_window_;
|
||||
|
||||
Memory* memory_;
|
||||
std::unique_ptr<Memory> memory_;
|
||||
|
||||
std::unique_ptr<DebugAgent> debug_agent_;
|
||||
|
||||
cpu::Processor* processor_;
|
||||
apu::AudioSystem* audio_system_;
|
||||
gpu::GraphicsSystem* graphics_system_;
|
||||
hid::InputSystem* input_system_;
|
||||
std::unique_ptr<cpu::Processor> processor_;
|
||||
std::unique_ptr<apu::AudioSystem> audio_system_;
|
||||
std::unique_ptr<gpu::GraphicsSystem> graphics_system_;
|
||||
std::unique_ptr<hid::InputSystem> input_system_;
|
||||
|
||||
ExportResolver* export_resolver_;
|
||||
kernel::fs::FileSystem* file_system_;
|
||||
std::unique_ptr<ExportResolver> export_resolver_;
|
||||
std::unique_ptr<kernel::fs::FileSystem> file_system_;
|
||||
|
||||
kernel::KernelState* kernel_state_;
|
||||
kernel::XamModule* xam_;
|
||||
kernel::XboxkrnlModule* xboxkrnl_;
|
||||
std::unique_ptr<kernel::KernelState> kernel_state_;
|
||||
std::unique_ptr<kernel::XamModule> xam_;
|
||||
std::unique_ptr<kernel::XboxkrnlModule> xboxkrnl_;
|
||||
};
|
||||
|
||||
} // namespace xe
|
||||
|
|
|
@ -11,34 +11,30 @@
|
|||
|
||||
#include <xenia/gpu/d3d11/d3d11_graphics_system.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::gpu;
|
||||
using namespace xe::gpu::d3d11;
|
||||
|
||||
|
||||
namespace {
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
void CleanupOnShutdown() {
|
||||
}
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
}
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
}
|
||||
|
||||
GraphicsSystem* xe::gpu::d3d11::Create(Emulator* emulator) {
|
||||
std::unique_ptr<GraphicsSystem> xe::gpu::d3d11::Create(Emulator* emulator) {
|
||||
InitializeIfNeeded();
|
||||
return new D3D11GraphicsSystem(emulator);
|
||||
return std::make_unique<D3D11GraphicsSystem>(emulator);
|
||||
}
|
||||
|
|
|
@ -10,24 +10,23 @@
|
|||
#ifndef XENIA_GPU_D3D11_D3D11_GPU_H_
|
||||
#define XENIA_GPU_D3D11_D3D11_GPU_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
|
||||
XEDECLARECLASS1(xe, Emulator);
|
||||
XEDECLARECLASS2(xe, gpu, GraphicsSystem);
|
||||
|
||||
namespace xe {
|
||||
class Emulator;
|
||||
} // namespace xe
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
class GraphicsSystem;
|
||||
namespace d3d11 {
|
||||
|
||||
|
||||
GraphicsSystem* Create(Emulator* emulator);
|
||||
|
||||
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
|
||||
|
||||
} // namespace d3d11
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_GPU_D3D11_D3D11_GPU_H_
|
||||
|
|
|
@ -10,37 +10,28 @@
|
|||
#include <xenia/gpu/gpu.h>
|
||||
#include <xenia/gpu/gpu-private.h>
|
||||
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::gpu;
|
||||
|
||||
DEFINE_string(gpu, "any", "Graphics system. Use: [any, nop, d3d11]");
|
||||
|
||||
DEFINE_string(gpu, "any",
|
||||
"Graphics system. Use: [any, nop, d3d11]");
|
||||
|
||||
|
||||
DEFINE_bool(trace_ring_buffer, false,
|
||||
"Trace GPU ring buffer packets.");
|
||||
DEFINE_bool(trace_ring_buffer, false, "Trace GPU ring buffer packets.");
|
||||
DEFINE_string(dump_shaders, "",
|
||||
"Path to write GPU shaders to as they are compiled.");
|
||||
|
||||
"Path to write GPU shaders to as they are compiled.");
|
||||
|
||||
#include <xenia/gpu/nop/nop_gpu.h>
|
||||
GraphicsSystem* xe::gpu::CreateNop(Emulator* emulator) {
|
||||
std::unique_ptr<GraphicsSystem> xe::gpu::CreateNop(Emulator* emulator) {
|
||||
return xe::gpu::nop::Create(emulator);
|
||||
}
|
||||
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
#include <xenia/gpu/d3d11/d3d11_gpu.h>
|
||||
GraphicsSystem* xe::gpu::CreateD3D11(Emulator* emulator) {
|
||||
std::unique_ptr<GraphicsSystem> xe::gpu::CreateD3D11(Emulator* emulator) {
|
||||
return xe::gpu::d3d11::Create(emulator);
|
||||
}
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
GraphicsSystem* xe::gpu::Create(Emulator* emulator) {
|
||||
std::unique_ptr<GraphicsSystem> xe::gpu::Create(Emulator* emulator) {
|
||||
if (FLAGS_gpu.compare("nop") == 0) {
|
||||
return CreateNop(emulator);
|
||||
#if XE_PLATFORM_WIN32
|
||||
|
@ -49,7 +40,7 @@ GraphicsSystem* xe::gpu::Create(Emulator* emulator) {
|
|||
#endif // WIN32
|
||||
} else {
|
||||
// Create best available.
|
||||
GraphicsSystem* best = NULL;
|
||||
std::unique_ptr<GraphicsSystem> best;
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
best = CreateD3D11(emulator);
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef XENIA_GPU_GPU_H_
|
||||
#define XENIA_GPU_GPU_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/gpu/graphics_system.h>
|
||||
|
||||
namespace xe {
|
||||
|
@ -19,12 +21,12 @@ class Emulator;
|
|||
namespace xe {
|
||||
namespace gpu {
|
||||
|
||||
GraphicsSystem* Create(Emulator* emulator);
|
||||
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
|
||||
|
||||
GraphicsSystem* CreateNop(Emulator* emulator);
|
||||
std::unique_ptr<GraphicsSystem> CreateNop(Emulator* emulator);
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
GraphicsSystem* CreateD3D11(Emulator* emulator);
|
||||
std::unique_ptr<GraphicsSystem> CreateD3D11(Emulator* emulator);
|
||||
#endif // WIN32
|
||||
|
||||
} // namespace gpu
|
||||
|
|
|
@ -11,34 +11,30 @@
|
|||
|
||||
#include <xenia/gpu/nop/nop_graphics_system.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::gpu;
|
||||
using namespace xe::gpu::nop;
|
||||
|
||||
|
||||
namespace {
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
void CleanupOnShutdown() {
|
||||
}
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
}
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
}
|
||||
|
||||
GraphicsSystem* xe::gpu::nop::Create(Emulator* emulator) {
|
||||
std::unique_ptr<GraphicsSystem> xe::gpu::nop::Create(Emulator* emulator) {
|
||||
InitializeIfNeeded();
|
||||
return new NopGraphicsSystem(emulator);
|
||||
return std::make_unique<NopGraphicsSystem>(emulator);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef XENIA_GPU_NOP_NOP_GPU_H_
|
||||
#define XENIA_GPU_NOP_NOP_GPU_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
namespace xe {
|
||||
|
@ -21,7 +23,7 @@ namespace gpu {
|
|||
class GraphicsSystem;
|
||||
namespace nop {
|
||||
|
||||
GraphicsSystem* Create(Emulator* emulator);
|
||||
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
|
||||
|
||||
} // namespace nop
|
||||
} // namespace gpu
|
||||
|
|
|
@ -10,15 +10,10 @@
|
|||
#include <xenia/hid/hid.h>
|
||||
#include <xenia/hid/hid-private.h>
|
||||
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
|
||||
|
||||
DEFINE_string(hid, "any",
|
||||
"Input system. Use: [any, nop, winkey, xinput]");
|
||||
|
||||
DEFINE_string(hid, "any", "Input system. Use: [any, nop, winkey, xinput]");
|
||||
|
||||
#include <xenia/hid/nop/nop_hid.h>
|
||||
#if XE_PLATFORM_WIN32
|
||||
|
@ -26,41 +21,40 @@ DEFINE_string(hid, "any",
|
|||
#include <xenia/hid/xinput/xinput_hid.h>
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
InputSystem* xe::hid::Create(Emulator* emulator) {
|
||||
//return xe::hid::nop::Create(emulator);
|
||||
InputSystem* input_system = new InputSystem(emulator);
|
||||
std::unique_ptr<InputSystem> xe::hid::Create(Emulator* emulator) {
|
||||
std::unique_ptr<InputSystem> input_system =
|
||||
std::make_unique<InputSystem>(emulator);
|
||||
|
||||
if (FLAGS_hid.compare("nop") == 0) {
|
||||
input_system->AddDriver(xe::hid::nop::Create(input_system));
|
||||
input_system->AddDriver(xe::hid::nop::Create(input_system.get()));
|
||||
#if XE_PLATFORM_WIN32
|
||||
} else if (FLAGS_hid.compare("winkey") == 0) {
|
||||
input_system->AddDriver(xe::hid::winkey::Create(input_system));
|
||||
input_system->AddDriver(xe::hid::winkey::Create(input_system.get()));
|
||||
} else if (FLAGS_hid.compare("xinput") == 0) {
|
||||
input_system->AddDriver(xe::hid::xinput::Create(input_system));
|
||||
input_system->AddDriver(xe::hid::xinput::Create(input_system.get()));
|
||||
#endif // WIN32
|
||||
} else {
|
||||
// Create all available.
|
||||
bool any_created = false;
|
||||
|
||||
// NOTE: in any mode we create as many as we can, falling back to nop.
|
||||
// NOTE: in any mode we create as many as we can, falling back to nop.
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
InputDriver* xinput_driver = xe::hid::xinput::Create(input_system);
|
||||
auto xinput_driver = xe::hid::xinput::Create(input_system.get());
|
||||
if (xinput_driver) {
|
||||
input_system->AddDriver(xinput_driver);
|
||||
input_system->AddDriver(std::move(xinput_driver));
|
||||
any_created = true;
|
||||
}
|
||||
InputDriver* winkey_driver = xe::hid::winkey::Create(input_system);
|
||||
auto winkey_driver = xe::hid::winkey::Create(input_system.get());
|
||||
if (winkey_driver) {
|
||||
input_system->AddDriver(winkey_driver);
|
||||
input_system->AddDriver(std::move(winkey_driver));
|
||||
any_created = true;
|
||||
}
|
||||
#endif // WIN32
|
||||
|
||||
// Fallback to nop if none created.
|
||||
if (!any_created) {
|
||||
input_system->AddDriver(xe::hid::nop::Create(input_system));
|
||||
input_system->AddDriver(xe::hid::nop::Create(input_system.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef XENIA_HID_HID_H_
|
||||
#define XENIA_HID_HID_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/hid/input_system.h>
|
||||
|
||||
namespace xe {
|
||||
|
@ -19,7 +21,7 @@ class Emulator;
|
|||
namespace xe {
|
||||
namespace hid {
|
||||
|
||||
InputSystem* Create(Emulator* emulator);
|
||||
std::unique_ptr<InputSystem> Create(Emulator* emulator);
|
||||
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
|
|
@ -32,9 +32,9 @@ void InitializeIfNeeded() {
|
|||
|
||||
void CleanupOnShutdown() {}
|
||||
|
||||
InputDriver* xe::hid::nop::Create(InputSystem* input_system) {
|
||||
std::unique_ptr<InputDriver> Create(InputSystem* input_system) {
|
||||
InitializeIfNeeded();
|
||||
return new NopInputDriver(input_system);
|
||||
return std::make_unique<NopInputDriver>(input_system);
|
||||
}
|
||||
|
||||
} // namespace nop
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef XENIA_HID_NOP_NOP_HID_H_
|
||||
#define XENIA_HID_NOP_NOP_HID_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
namespace xe {
|
||||
|
@ -18,7 +20,7 @@ class InputDriver;
|
|||
class InputSystem;
|
||||
namespace nop {
|
||||
|
||||
InputDriver* Create(InputSystem* input_system);
|
||||
std::unique_ptr<InputDriver> Create(InputSystem* input_system);
|
||||
|
||||
} // namespace nop
|
||||
} // namespace hid
|
||||
|
|
|
@ -32,9 +32,9 @@ void InitializeIfNeeded() {
|
|||
|
||||
void CleanupOnShutdown() {}
|
||||
|
||||
InputDriver* xe::hid::winkey::Create(InputSystem* input_system) {
|
||||
std::unique_ptr<InputDriver> Create(InputSystem* input_system) {
|
||||
InitializeIfNeeded();
|
||||
return new WinKeyInputDriver(input_system);
|
||||
return std::make_unique<WinKeyInputDriver>(input_system);
|
||||
}
|
||||
|
||||
} // namespace winkey
|
||||
|
|
|
@ -10,16 +10,17 @@
|
|||
#ifndef XENIA_HID_WINKEY_WINKEY_HID_H_
|
||||
#define XENIA_HID_WINKEY_WINKEY_HID_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
#include <memory>
|
||||
|
||||
XEDECLARECLASS2(xe, hid, InputDriver);
|
||||
XEDECLARECLASS2(xe, hid, InputSystem);
|
||||
#include <xenia/core.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
class InputDriver;
|
||||
class InputSystem;
|
||||
namespace winkey {
|
||||
|
||||
InputDriver* Create(InputSystem* input_system);
|
||||
std::unique_ptr<InputDriver> Create(InputSystem* input_system);
|
||||
|
||||
} // namespace winkey
|
||||
} // namespace hid
|
||||
|
|
|
@ -32,9 +32,9 @@ void InitializeIfNeeded() {
|
|||
|
||||
void CleanupOnShutdown() {}
|
||||
|
||||
InputDriver* xe::hid::xinput::Create(InputSystem* input_system) {
|
||||
std::unique_ptr<InputDriver> Create(InputSystem* input_system) {
|
||||
InitializeIfNeeded();
|
||||
return new XInputInputDriver(input_system);
|
||||
return std::make_unique<XInputInputDriver>(input_system);
|
||||
}
|
||||
|
||||
} // namespace xinput
|
||||
|
|
|
@ -10,16 +10,17 @@
|
|||
#ifndef XENIA_HID_XINPUT_XINPUT_HID_H_
|
||||
#define XENIA_HID_XINPUT_XINPUT_HID_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
#include <memory>
|
||||
|
||||
XEDECLARECLASS2(xe, hid, InputDriver);
|
||||
XEDECLARECLASS2(xe, hid, InputSystem);
|
||||
#include <xenia/core.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
class InputDriver;
|
||||
class InputSystem;
|
||||
namespace xinput {
|
||||
|
||||
InputDriver* Create(InputSystem* input_system);
|
||||
std::unique_ptr<InputDriver> Create(InputSystem* input_system);
|
||||
|
||||
} // namespace xinput
|
||||
} // namespace hid
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef XENIA_KERNEL_FS_DEVICE_H_
|
||||
#define XENIA_KERNEL_FS_DEVICE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
@ -26,7 +27,7 @@ class Device {
|
|||
|
||||
const std::string& path() const { return path_; }
|
||||
|
||||
virtual Entry* ResolvePath(const char* path) = 0;
|
||||
virtual std::unique_ptr<Entry> ResolvePath(const char* path) = 0;
|
||||
|
||||
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) = 0;
|
||||
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
|
||||
|
|
|
@ -42,7 +42,7 @@ int DiscImageDevice::Init() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
Entry* DiscImageDevice::ResolvePath(const char* path) {
|
||||
std::unique_ptr<Entry> DiscImageDevice::ResolvePath(const char* path) {
|
||||
// The filesystem will have stripped our prefix off already, so the path will
|
||||
// be in the form:
|
||||
// some\PATH.foo
|
||||
|
@ -64,7 +64,8 @@ Entry* DiscImageDevice::ResolvePath(const char* path) {
|
|||
Entry::Type type = gdfx_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY
|
||||
? Entry::Type::DIRECTORY
|
||||
: Entry::Type::FILE;
|
||||
return new DiscImageEntry(type, this, path, mmap_.get(), gdfx_entry);
|
||||
return std::make_unique<DiscImageEntry>(type, this, path, mmap_.get(),
|
||||
gdfx_entry);
|
||||
}
|
||||
|
||||
X_STATUS DiscImageDevice::QueryVolume(XVolumeInfo* out_info, size_t length) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class DiscImageDevice : public Device {
|
|||
|
||||
int Init();
|
||||
|
||||
Entry* ResolvePath(const char* path) override;
|
||||
std::unique_ptr<Entry> ResolvePath(const char* path) override;
|
||||
|
||||
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
|
||||
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
|
||||
|
|
|
@ -96,23 +96,22 @@ X_STATUS DiscImageEntry::QueryDirectory(XDirectoryInfo* out_info, size_t length,
|
|||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
MemoryMapping* DiscImageEntry::CreateMemoryMapping(Mode map_mode,
|
||||
const size_t offset,
|
||||
const size_t length) {
|
||||
std::unique_ptr<MemoryMapping> DiscImageEntry::CreateMemoryMapping(
|
||||
Mode map_mode, const size_t offset, const size_t length) {
|
||||
if (map_mode != Mode::READ) {
|
||||
// Only allow reads.
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t real_offset = gdfx_entry_->offset + offset;
|
||||
size_t real_length =
|
||||
length ? std::min(length, gdfx_entry_->size) : gdfx_entry_->size;
|
||||
return new DiscImageMemoryMapping(mmap_->data() + real_offset, real_length,
|
||||
mmap_);
|
||||
return std::make_unique<DiscImageMemoryMapping>(mmap_->data() + real_offset,
|
||||
real_length, mmap_);
|
||||
}
|
||||
|
||||
X_STATUS DiscImageEntry::Open(KernelState* kernel_state, Mode mode,
|
||||
bool async, XFile** out_file) {
|
||||
X_STATUS DiscImageEntry::Open(KernelState* kernel_state, Mode mode, bool async,
|
||||
XFile** out_file) {
|
||||
*out_file = new DiscImageFile(kernel_state, mode, this);
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -37,11 +37,11 @@ class DiscImageEntry : public Entry {
|
|||
const char* file_name, bool restart);
|
||||
|
||||
virtual bool can_map() { return true; }
|
||||
virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset,
|
||||
const size_t length);
|
||||
virtual std::unique_ptr<MemoryMapping> CreateMemoryMapping(
|
||||
Mode map_mode, const size_t offset, const size_t length);
|
||||
|
||||
virtual X_STATUS Open(KernelState* kernel_state, Mode mode,
|
||||
bool async, XFile** out_file);
|
||||
virtual X_STATUS Open(KernelState* kernel_state, Mode mode, bool async,
|
||||
XFile** out_file);
|
||||
|
||||
private:
|
||||
poly::MappedMemory* mmap_;
|
||||
|
|
|
@ -22,7 +22,7 @@ HostPathDevice::HostPathDevice(const std::string& path,
|
|||
|
||||
HostPathDevice::~HostPathDevice() {}
|
||||
|
||||
Entry* HostPathDevice::ResolvePath(const char* path) {
|
||||
std::unique_ptr<Entry> HostPathDevice::ResolvePath(const char* path) {
|
||||
// The filesystem will have stripped our prefix off already, so the path will
|
||||
// be in the form:
|
||||
// some\PATH.foo
|
||||
|
@ -38,8 +38,7 @@ Entry* HostPathDevice::ResolvePath(const char* path) {
|
|||
// TODO(benvanik): switch based on type
|
||||
|
||||
auto type = Entry::Type::FILE;
|
||||
HostPathEntry* entry = new HostPathEntry(type, this, path, full_path);
|
||||
return entry;
|
||||
return std::make_unique<HostPathEntry>(type, this, path, full_path);
|
||||
}
|
||||
|
||||
// TODO(gibbed): call into HostPathDevice?
|
||||
|
|
|
@ -25,7 +25,7 @@ class HostPathDevice : public Device {
|
|||
HostPathDevice(const std::string& path, const std::wstring& local_path);
|
||||
~HostPathDevice() override;
|
||||
|
||||
Entry* ResolvePath(const char* path) override;
|
||||
std::unique_ptr<Entry> ResolvePath(const char* path) override;
|
||||
|
||||
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
|
||||
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
|
||||
|
|
|
@ -121,9 +121,8 @@ X_STATUS HostPathEntry::QueryDirectory(XDirectoryInfo* out_info, size_t length,
|
|||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
MemoryMapping* HostPathEntry::CreateMemoryMapping(Mode map_mode,
|
||||
const size_t offset,
|
||||
const size_t length) {
|
||||
std::unique_ptr<MemoryMapping> HostPathEntry::CreateMemoryMapping(
|
||||
Mode map_mode, const size_t offset, const size_t length) {
|
||||
auto mmap = poly::MappedMemory::Open(
|
||||
local_path_,
|
||||
map_mode == Mode::READ ? poly::MappedMemory::Mode::READ
|
||||
|
@ -133,13 +132,11 @@ MemoryMapping* HostPathEntry::CreateMemoryMapping(Mode map_mode,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
HostPathMemoryMapping* lfmm = new HostPathMemoryMapping(std::move(mmap));
|
||||
|
||||
return lfmm;
|
||||
return std::make_unique<HostPathMemoryMapping>(std::move(mmap));
|
||||
}
|
||||
|
||||
X_STATUS HostPathEntry::Open(KernelState* kernel_state, Mode mode,
|
||||
bool async, XFile** out_file) {
|
||||
X_STATUS HostPathEntry::Open(KernelState* kernel_state, Mode mode, bool async,
|
||||
XFile** out_file) {
|
||||
DWORD desired_access =
|
||||
mode == Mode::READ ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
|
||||
DWORD share_mode = FILE_SHARE_READ;
|
||||
|
|
|
@ -31,8 +31,8 @@ class HostPathEntry : public Entry {
|
|||
const char* file_name, bool restart);
|
||||
|
||||
virtual bool can_map() { return true; }
|
||||
virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset,
|
||||
const size_t length);
|
||||
virtual std::unique_ptr<MemoryMapping> CreateMemoryMapping(
|
||||
Mode map_mode, const size_t offset, const size_t length);
|
||||
|
||||
virtual X_STATUS Open(KernelState* kernel_state, Mode mode, bool async,
|
||||
XFile** out_file);
|
||||
|
|
|
@ -42,7 +42,7 @@ int STFSContainerDevice::Init() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
Entry* STFSContainerDevice::ResolvePath(const char* path) {
|
||||
std::unique_ptr<Entry> STFSContainerDevice::ResolvePath(const char* path) {
|
||||
// The filesystem will have stripped our prefix off already, so the path will
|
||||
// be in the form:
|
||||
// some\PATH.foo
|
||||
|
@ -64,7 +64,8 @@ Entry* STFSContainerDevice::ResolvePath(const char* path) {
|
|||
Entry::Type type = stfs_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY
|
||||
? Entry::Type::DIRECTORY
|
||||
: Entry::Type::FILE;
|
||||
return new STFSContainerEntry(type, this, path, mmap_.get(), stfs_entry);
|
||||
return std::make_unique<STFSContainerEntry>(type, this, path, mmap_.get(),
|
||||
stfs_entry);
|
||||
}
|
||||
|
||||
X_STATUS STFSContainerDevice::QueryVolume(XVolumeInfo* out_info,
|
||||
|
|
|
@ -31,7 +31,7 @@ class STFSContainerDevice : public Device {
|
|||
|
||||
int Init();
|
||||
|
||||
Entry* ResolvePath(const char* path) override;
|
||||
std::unique_ptr<Entry> ResolvePath(const char* path) override;
|
||||
|
||||
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
|
||||
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef XENIA_KERNEL_FS_ENTRY_H_
|
||||
#define XENIA_KERNEL_FS_ENTRY_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
@ -72,8 +73,8 @@ class Entry {
|
|||
|
||||
virtual bool can_map() { return false; }
|
||||
|
||||
virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset,
|
||||
const size_t length) {
|
||||
virtual std::unique_ptr<MemoryMapping> CreateMemoryMapping(
|
||||
Mode map_mode, const size_t offset, const size_t length) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ int FileSystem::DeleteSymbolicLink(const std::string& path) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
Entry* FileSystem::ResolvePath(const std::string& path) {
|
||||
std::unique_ptr<Entry> FileSystem::ResolvePath(const std::string& path) {
|
||||
// Strip off prefix and pass to device.
|
||||
// e.g., d:\some\PATH.foo -> some\PATH.foo
|
||||
// Support both symlinks and device specifiers, like:
|
||||
|
@ -173,7 +173,7 @@ Entry* FileSystem::ResolvePath(const std::string& path) {
|
|||
}
|
||||
|
||||
XELOGE("ResolvePath(%s) failed - no root found", path.c_str());
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace fs
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef XENIA_KERNEL_FS_FILESYSTEM_H_
|
||||
#define XENIA_KERNEL_FS_FILESYSTEM_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
@ -50,7 +51,7 @@ class FileSystem {
|
|||
int CreateSymbolicLink(const std::string& path, const std::string& target);
|
||||
int DeleteSymbolicLink(const std::string& path);
|
||||
|
||||
Entry* ResolvePath(const std::string& path);
|
||||
std::unique_ptr<Entry> ResolvePath(const std::string& path);
|
||||
|
||||
private:
|
||||
std::vector<Device*> devices_;
|
||||
|
|
|
@ -33,41 +33,33 @@ const xe_xex2_header_t* XUserModule::xex_header() {
|
|||
X_STATUS XUserModule::LoadFromFile(const char* path) {
|
||||
X_STATUS result = X_STATUS_UNSUCCESSFUL;
|
||||
XFile* file = NULL;
|
||||
uint8_t* buffer = 0;
|
||||
|
||||
// Resolve the file to open.
|
||||
// TODO(benvanik): make this code shared?
|
||||
fs::Entry* fs_entry = kernel_state()->file_system()->ResolvePath(path);
|
||||
auto fs_entry = kernel_state()->file_system()->ResolvePath(path);
|
||||
if (!fs_entry) {
|
||||
XELOGE("File not found: %s", path);
|
||||
result = X_STATUS_NO_SUCH_FILE;
|
||||
XEFAIL();
|
||||
return X_STATUS_NO_SUCH_FILE;
|
||||
}
|
||||
if (fs_entry->type() != fs::Entry::Type::FILE) {
|
||||
XELOGE("Invalid file type: %s", path);
|
||||
result = X_STATUS_NO_SUCH_FILE;
|
||||
XEFAIL();
|
||||
return X_STATUS_NO_SUCH_FILE;
|
||||
}
|
||||
|
||||
// If the FS supports mapping, map the file in and load from that.
|
||||
if (fs_entry->can_map()) {
|
||||
// Map.
|
||||
fs::MemoryMapping* mmap =
|
||||
fs_entry->CreateMemoryMapping(fs::Mode::READ, 0, 0);
|
||||
auto mmap = fs_entry->CreateMemoryMapping(fs::Mode::READ, 0, 0);
|
||||
XEEXPECTNOTNULL(mmap);
|
||||
|
||||
// Load the module.
|
||||
result = LoadFromMemory(mmap->address(), mmap->length());
|
||||
|
||||
// Unmap memory and cleanup.
|
||||
delete mmap;
|
||||
} else {
|
||||
XFileInfo file_info;
|
||||
result = fs_entry->QueryInfo(&file_info);
|
||||
XEEXPECTZERO(result);
|
||||
|
||||
size_t buffer_length = file_info.file_length;
|
||||
buffer = (uint8_t*)malloc(buffer_length);
|
||||
std::vector<uint8_t> buffer(file_info.file_length);
|
||||
|
||||
// Open file for reading.
|
||||
result = fs_entry->Open(kernel_state(), fs::Mode::READ, false, &file);
|
||||
|
@ -76,21 +68,17 @@ X_STATUS XUserModule::LoadFromFile(const char* path) {
|
|||
// Read entire file into memory.
|
||||
// Ugh.
|
||||
size_t bytes_read = 0;
|
||||
result = file->Read(buffer, buffer_length, 0, &bytes_read);
|
||||
result = file->Read(buffer.data(), buffer.size(), 0, &bytes_read);
|
||||
XEEXPECTZERO(result);
|
||||
|
||||
// Load the module.
|
||||
result = LoadFromMemory(buffer, bytes_read);
|
||||
result = LoadFromMemory(buffer.data(), bytes_read);
|
||||
}
|
||||
|
||||
XECLEANUP:
|
||||
if (buffer) {
|
||||
free(buffer);
|
||||
}
|
||||
if (file) {
|
||||
file->Release();
|
||||
}
|
||||
delete fs_entry;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ SHIM_CALL NtCreateFile_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
uint32_t handle;
|
||||
|
||||
FileSystem* fs = state->file_system();
|
||||
Entry* entry;
|
||||
std::unique_ptr<Entry> entry;
|
||||
|
||||
XFile* root_file = NULL;
|
||||
if (attrs.root_directory != 0xFFFFFFFD && // ObDosDevices
|
||||
|
@ -93,10 +93,10 @@ SHIM_CALL NtCreateFile_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
|
||||
auto root_path = root_file->absolute_path();
|
||||
auto target_path = root_path + object_name;
|
||||
entry = fs->ResolvePath(target_path);
|
||||
entry = std::move(fs->ResolvePath(target_path));
|
||||
} else {
|
||||
// Resolve the file using the virtual file system.
|
||||
entry = fs->ResolvePath(object_name);
|
||||
entry = std::move(fs->ResolvePath(object_name));
|
||||
}
|
||||
|
||||
auto mode =
|
||||
|
@ -169,7 +169,7 @@ SHIM_CALL NtOpenFile_shim(PPCContext* ppc_state, KernelState* state) {
|
|||
|
||||
// Resolve the file using the virtual file system.
|
||||
FileSystem* fs = state->file_system();
|
||||
Entry* entry = fs->ResolvePath(object_name);
|
||||
auto entry = fs->ResolvePath(object_name);
|
||||
XFile* file = NULL;
|
||||
if (entry && entry->type() == Entry::Type::FILE) {
|
||||
// Open the file.
|
||||
|
@ -480,7 +480,7 @@ SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_state,
|
|||
|
||||
// Resolve the file using the virtual file system.
|
||||
FileSystem* fs = state->file_system();
|
||||
Entry* entry = fs->ResolvePath(object_name);
|
||||
auto entry = fs->ResolvePath(object_name);
|
||||
if (entry && entry->type() == Entry::Type::FILE) {
|
||||
// Found.
|
||||
XFileInfo file_info;
|
||||
|
|
|
@ -147,7 +147,6 @@ int Memory::Initialize() {
|
|||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = 1;
|
||||
|
||||
// Create main page file-backed mapping. This is all reserved but
|
||||
// uncommitted (so it shouldn't expand page file).
|
||||
|
@ -165,7 +164,7 @@ int Memory::Initialize() {
|
|||
if (!mapping_) {
|
||||
XELOGE("Unable to reserve the 4gb guest address space.");
|
||||
assert_not_null(mapping_);
|
||||
XEFAIL();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Attempt to create our views. This may fail at the first address
|
||||
|
@ -181,7 +180,7 @@ int Memory::Initialize() {
|
|||
if (!mapping_base_) {
|
||||
XELOGE("Unable to find a continuous block in the 64bit address space.");
|
||||
assert_always();
|
||||
XEFAIL();
|
||||
return 1;
|
||||
}
|
||||
membase_ = mapping_base_;
|
||||
|
||||
|
@ -200,7 +199,7 @@ int Memory::Initialize() {
|
|||
if (!mmio_handler_) {
|
||||
XELOGE("Unable to install MMIO handlers");
|
||||
assert_always();
|
||||
XEFAIL();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Allocate dirty page table.
|
||||
|
@ -210,9 +209,6 @@ int Memory::Initialize() {
|
|||
X_MEM_COMMIT, 16 * 1024);
|
||||
|
||||
return 0;
|
||||
|
||||
XECLEANUP:
|
||||
return result;
|
||||
}
|
||||
|
||||
const static struct {
|
||||
|
@ -243,13 +239,13 @@ int Memory::MapViews(uint8_t* mapping_base) {
|
|||
PROT_NONE, MAP_SHARED | MAP_FIXED, mapping_,
|
||||
map_info[n].target_address));
|
||||
#endif // XE_PLATFORM_WIN32
|
||||
XEEXPECTNOTNULL(views_.all_views[n]);
|
||||
if (!views_.all_views[n]) {
|
||||
// Failed, so bail and try again.
|
||||
UnmapViews();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
XECLEANUP:
|
||||
UnmapViews();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Memory::UnmapViews() {
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
'memory.h',
|
||||
'profiling.cc',
|
||||
'profiling.h',
|
||||
'types.h',
|
||||
'xbox.h',
|
||||
],
|
||||
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_TYPES_H_
|
||||
#define XENIA_TYPES_H_
|
||||
|
||||
#define XEFAIL() goto XECLEANUP
|
||||
#define XEEXPECT(expr) \
|
||||
if (!(expr)) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
#define XEEXPECTTRUE(expr) \
|
||||
if (!(expr)) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
#define XEEXPECTFALSE(expr) \
|
||||
if ((expr)) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
#define XEEXPECTZERO(expr) \
|
||||
if ((expr) != 0) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
#define XEEXPECTNOTZERO(expr) \
|
||||
if ((expr) == 0) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
#define XEEXPECTNULL(expr) \
|
||||
if ((expr) != NULL) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
#define XEEXPECTNOTNULL(expr) \
|
||||
if ((expr) == NULL) { \
|
||||
goto XECLEANUP; \
|
||||
}
|
||||
|
||||
#endif // XENIA_TYPES_H_
|
Loading…
Reference in New Issue