Massive refactoring of all code + audio skeleton.

This should make it easier to find files and (in the future) split things
up into separate libraries.
It also changes around emulator initialization to make it a little more
difficult to do things out of order and a little more sensible as to when
real init work happens.
Also adding a skeleton audio system/driver and reworking CPU register
access to be more extensible.
This commit is contained in:
Ben Vanik
2013-10-23 20:42:24 -07:00
parent c996a4bbaf
commit b7ffd46319
182 changed files with 3919 additions and 3286 deletions

View File

@@ -0,0 +1,19 @@
/**
******************************************************************************
* 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_APU_APU_PRIVATE_H_
#define XENIA_APU_APU_PRIVATE_H_
#include <gflags/gflags.h>
DECLARE_string(apu);
#endif // XENIA_APU_APU_PRIVATE_H_

39
src/xenia/apu/apu.cc Normal file
View File

@@ -0,0 +1,39 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#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]");
#include <xenia/apu/nop/nop_apu.h>
AudioSystem* xe::apu::CreateNop(Emulator* emulator) {
return xe::apu::nop::Create(emulator);
}
AudioSystem* xe::apu::Create(Emulator* emulator) {
if (FLAGS_apu.compare("nop") == 0) {
return CreateNop(emulator);
} else {
// Create best available.
AudioSystem* best = NULL;
// Fallback to nop.
return CreateNop(emulator);
}
}

32
src/xenia/apu/apu.h Normal file
View File

@@ -0,0 +1,32 @@
/**
******************************************************************************
* 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_APU_APU_H_
#define XENIA_APU_APU_H_
#include <xenia/apu/audio_system.h>
XEDECLARECLASS1(xe, Emulator);
namespace xe {
namespace apu {
AudioSystem* Create(Emulator* emulator);
AudioSystem* CreateNop(Emulator* emulator);
} // namespace apu
} // namespace xe
#endif // XENIA_APU_APU_H_

View File

@@ -0,0 +1,23 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/apu/audio_driver.h>
using namespace xe;
using namespace xe::apu;
AudioDriver::AudioDriver(xe_memory_ref memory) {
memory_ = xe_memory_retain(memory);
}
AudioDriver::~AudioDriver() {
xe_memory_release(memory_);
}

View File

@@ -0,0 +1,39 @@
/**
******************************************************************************
* 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_APU_AUDIO_DRIVER_H_
#define XENIA_APU_AUDIO_DRIVER_H_
#include <xenia/core.h>
namespace xe {
namespace apu {
class AudioDriver {
public:
virtual ~AudioDriver();
xe_memory_ref memory() const { return memory_; }
virtual void Initialize() = 0;
protected:
AudioDriver(xe_memory_ref memory);
xe_memory_ref memory_;
};
} // namespace apu
} // namespace xe
#endif // XENIA_APU_AUDIO_DRIVER_H_

View File

@@ -0,0 +1,116 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/apu/audio_system.h>
#include <xenia/emulator.h>
#include <xenia/cpu/processor.h>
#include <xenia/apu/audio_driver.h>
using namespace xe;
using namespace xe::apu;
using namespace xe::cpu::ppc;
AudioSystem::AudioSystem(Emulator* emulator) :
emulator_(emulator),
thread_(0), running_(false), driver_(0) {
memory_ = xe_memory_retain(emulator->memory());
// Create the run loop used for any windows/etc.
// This must be done on the thread we create the driver.
run_loop_ = xe_run_loop_create();
}
AudioSystem::~AudioSystem() {
// TODO(benvanik): thread join.
running_ = false;
xe_thread_release(thread_);
xe_run_loop_release(run_loop_);
xe_memory_release(memory_);
}
X_STATUS AudioSystem::Setup() {
processor_ = emulator_->processor();
// Let the processor know we want register access callbacks.
RegisterAccessCallbacks callbacks;
callbacks.context = this;
callbacks.handles = (RegisterHandlesCallback)HandlesRegisterThunk;
callbacks.read = (RegisterReadCallback)ReadRegisterThunk;
callbacks.write = (RegisterWriteCallback)WriteRegisterThunk;
emulator_->processor()->AddRegisterAccessCallbacks(callbacks);
// Create worker thread.
// This will initialize the audio system.
// Init needs to happen there so that any thread-local stuff
// is created on the right thread.
running_ = true;
thread_ = xe_thread_create(
"AudioSystem",
(xe_thread_callback)ThreadStartThunk, this);
xe_thread_start(thread_);
return X_STATUS_SUCCESS;
}
void AudioSystem::ThreadStart() {
xe_run_loop_ref run_loop = xe_run_loop_retain(run_loop_);
// Initialize driver and ringbuffer.
Initialize();
XEASSERTNOTNULL(driver_);
// Main run loop.
while (running_) {
// Peek main run loop.
if (xe_run_loop_pump(run_loop)) {
break;
}
if (!running_) {
break;
}
// Pump worker.
//worker_->Pump();
// Pump audio system.
Pump();
}
running_ = false;
Shutdown();
xe_run_loop_release(run_loop);
// TODO(benvanik): call module API to kill?
}
void AudioSystem::Initialize() {
}
void AudioSystem::Shutdown() {
}
bool AudioSystem::HandlesRegister(uint32_t addr) {
return (addr & 0xFFFF0000) == 0x7FEA0000;
}
uint64_t AudioSystem::ReadRegister(uint32_t addr) {
uint32_t r = addr & 0xFFFF;
XELOGAPU("ReadRegister(%.4X)", r);
return 0;
}
void AudioSystem::WriteRegister(uint32_t addr, uint64_t value) {
uint32_t r = addr & 0xFFFF;
XELOGAPU("WriteRegister(%.4X, %.8X)", r, value);
}

View File

@@ -0,0 +1,82 @@
/**
******************************************************************************
* 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_APU_AUDIO_SYSTEM_H_
#define XENIA_APU_AUDIO_SYSTEM_H_
#include <xenia/core.h>
#include <xenia/xbox.h>
XEDECLARECLASS1(xe, Emulator);
XEDECLARECLASS2(xe, cpu, Processor);
namespace xe {
namespace apu {
class AudioDriver;
class AudioSystem {
public:
virtual ~AudioSystem();
Emulator* emulator() const { return emulator_; }
xe_memory_ref memory() const { return memory_; }
cpu::Processor* processor() const { return processor_; }
virtual X_STATUS Setup();
bool HandlesRegister(uint32_t addr);
virtual uint64_t ReadRegister(uint32_t addr);
virtual void WriteRegister(uint32_t addr, uint64_t value);
protected:
virtual void Initialize();
virtual void Pump() = 0;
virtual void Shutdown();
private:
static void ThreadStartThunk(AudioSystem* this_ptr) {
this_ptr->ThreadStart();
}
void ThreadStart();
static bool HandlesRegisterThunk(AudioSystem* as, uint32_t addr) {
return as->HandlesRegister(addr);
}
static uint64_t ReadRegisterThunk(AudioSystem* as, uint32_t addr) {
return as->ReadRegister(addr);
}
static void WriteRegisterThunk(AudioSystem* as, uint32_t addr,
uint64_t value) {
as->WriteRegister(addr, value);
}
protected:
AudioSystem(Emulator* emulator);
Emulator* emulator_;
xe_memory_ref memory_;
cpu::Processor* processor_;
xe_run_loop_ref run_loop_;
xe_thread_ref thread_;
bool running_;
AudioDriver* driver_;
};
} // namespace apu
} // namespace xe
#endif // XENIA_APU_AUDIO_SYSTEM_H_

View File

@@ -0,0 +1,31 @@
/**
******************************************************************************
* 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_APU_NOP_NOP_APU_PRIVATE_H_
#define XENIA_APU_NOP_NOP_APU_PRIVATE_H_
#include <xenia/core.h>
#include <xenia/apu/nop/nop_apu.h>
namespace xe {
namespace apu {
namespace nop {
} // namespace nop
} // namespace apu
} // namespace xe
#endif // XENIA_APU_NOP_NOP_APU_PRIVATE_H_

View File

@@ -0,0 +1,44 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/apu/nop/nop_apu.h>
#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() {
static bool has_initialized = false;
if (has_initialized) {
return;
}
has_initialized = true;
//
atexit(CleanupOnShutdown);
}
void CleanupOnShutdown() {
}
}
AudioSystem* xe::apu::nop::Create(Emulator* emulator) {
InitializeIfNeeded();
return new NopAudioSystem(emulator);
}

View File

@@ -0,0 +1,33 @@
/**
******************************************************************************
* 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_GPU_NOP_NOP_H_
#define XENIA_GPU_NOP_NOP_H_
#include <xenia/core.h>
XEDECLARECLASS1(xe, Emulator);
XEDECLARECLASS2(xe, apu, AudioSystem);
namespace xe {
namespace apu {
namespace nop {
AudioSystem* Create(Emulator* emulator);
} // namespace nop
} // namespace apu
} // namespace xe
#endif // XENIA_GPU_NOP_NOP_H_

View File

@@ -0,0 +1,28 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/apu/nop/nop_audio_driver.h>
#include <xenia/apu/apu-private.h>
using namespace xe;
using namespace xe::apu;
using namespace xe::apu::nop;
NopAudioDriver::NopAudioDriver(xe_memory_ref memory) :
AudioDriver(memory) {
}
NopAudioDriver::~NopAudioDriver() {
}
void NopAudioDriver::Initialize() {
}

View File

@@ -0,0 +1,40 @@
/**
******************************************************************************
* 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_APU_NOP_NOP_AUDIO_DRIVER_H_
#define XENIA_APU_NOP_NOP_AUDIO_DRIVER_H_
#include <xenia/core.h>
#include <xenia/apu/audio_driver.h>
#include <xenia/apu/nop/nop_apu-private.h>
namespace xe {
namespace apu {
namespace nop {
class NopAudioDriver : public AudioDriver {
public:
NopAudioDriver(xe_memory_ref memory);
virtual ~NopAudioDriver();
virtual void Initialize();
protected:
};
} // namespace nop
} // namespace apu
} // namespace xe
#endif // XENIA_APU_NOP_NOP_AUDIO_DRIVER_H_

View File

@@ -0,0 +1,40 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/apu/nop/nop_audio_system.h>
#include <xenia/apu/apu-private.h>
#include <xenia/apu/nop/nop_audio_driver.h>
using namespace xe;
using namespace xe::apu;
using namespace xe::apu::nop;
NopAudioSystem::NopAudioSystem(Emulator* emulator) :
AudioSystem(emulator) {
}
NopAudioSystem::~NopAudioSystem() {
}
void NopAudioSystem::Initialize() {
AudioSystem::Initialize();
XEASSERTNULL(driver_);
driver_ = new NopAudioDriver(memory_);
}
void NopAudioSystem::Pump() {
}
void NopAudioSystem::Shutdown() {
AudioSystem::Shutdown();
}

View File

@@ -0,0 +1,43 @@
/**
******************************************************************************
* 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_APU_NOP_NOP_AUDIO_SYSTEM_H_
#define XENIA_APU_NOP_NOP_AUDIO_SYSTEM_H_
#include <xenia/core.h>
#include <xenia/apu/audio_system.h>
#include <xenia/apu/nop/nop_apu-private.h>
namespace xe {
namespace apu {
namespace nop {
class NopAudioSystem : public AudioSystem {
public:
NopAudioSystem(Emulator* emulator);
virtual ~NopAudioSystem();
protected:
virtual void Initialize();
virtual void Pump();
virtual void Shutdown();
private:
};
} // namespace nop
} // namespace apu
} // namespace xe
#endif // XENIA_APU_NOP_NOP_AUDIO_SYSTEM_H_

View File

@@ -0,0 +1,12 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'nop_apu-private.h',
'nop_apu.cc',
'nop_apu.h',
'nop_audio_driver.cc',
'nop_audio_driver.h',
'nop_audio_system.cc',
'nop_audio_system.h',
],
}

View File

@@ -0,0 +1,23 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'apu-private.h',
'apu.cc',
'apu.h',
'audio_driver.cc',
'audio_driver.h',
'audio_system.cc',
'audio_system.h',
],
'includes': [
'nop/sources.gypi',
],
'conditions': [
['OS == "win"', {
'includes': [
],
}],
],
}