Moved the XMA decoder out of AudioSystem and into its own world (plus minor code cleanup in the process).

This commit is contained in:
gibbed
2015-06-21 02:25:24 -05:00
parent 736dba5aca
commit 021b5a3d17
13 changed files with 858 additions and 732 deletions

114
src/xenia/apu/xma_decoder.h Normal file
View File

@@ -0,0 +1,114 @@
/**
******************************************************************************
* 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_XMA_DECODER_H_
#define XENIA_APU_XMA_DECODER_H_
#include <atomic>
#include <mutex>
#include <queue>
#include "xenia/emulator.h"
#include "xenia/xbox.h"
#include "xenia/apu/xma_context.h"
namespace xe {
namespace kernel {
class XHostThread;
} // namespace kernel
} // namespace xe
namespace xe {
namespace apu {
struct XMA_CONTEXT_DATA;
class XmaDecoder {
public:
XmaDecoder(Emulator* emulator);
virtual ~XmaDecoder();
Emulator* emulator() const { return emulator_; }
Memory* memory() const { return memory_; }
cpu::Processor* processor() const { return processor_; }
virtual X_STATUS Setup();
virtual void Shutdown();
uint32_t context_array_ptr() const {
return registers_.context_array_ptr;
}
uint32_t AllocateContext();
void ReleaseContext(uint32_t guest_ptr);
bool BlockOnContext(uint32_t guest_ptr, bool poll);
virtual uint64_t ReadRegister(uint32_t addr);
virtual void WriteRegister(uint32_t addr, uint64_t value);
protected:
virtual void Initialize();
private:
void WorkerThreadMain();
void ProcessContext(XmaContext& context, XMA_CONTEXT_DATA& data);
int PreparePacket(XmaContext& context, XMA_CONTEXT_DATA& data);
static uint64_t MMIOReadRegisterThunk(void* ppc_context, XmaDecoder* as,
uint32_t addr) {
return as->ReadRegister(addr);
}
static void MMIOWriteRegisterThunk(void* ppc_context, XmaDecoder* as,
uint32_t addr, uint64_t value) {
as->WriteRegister(addr, value);
}
protected:
Emulator* emulator_;
Memory* memory_;
cpu::Processor* processor_;
std::atomic<bool> worker_running_;
kernel::object_ref<kernel::XHostThread> worker_thread_;
xe::threading::Fence worker_fence_;
xe::mutex lock_;
// Stored little endian, accessed through 0x7FEA....
union {
struct {
union {
struct {
uint8_t ignored0[0x1800];
// 1800h; points to guest-space physical block of 320 contexts.
uint32_t context_array_ptr;
};
struct {
uint8_t ignored1[0x1818];
// 1818h; current context ID.
uint32_t current_context;
// 181Ch; next context ID to process.
uint32_t next_context;
};
};
} registers_;
uint32_t register_file_[0xFFFF / 4];
};
static const uint32_t kContextCount = 320;
XmaContext context_array_[kContextCount];
std::vector<uint32_t> xma_context_free_list_;
std::vector<uint32_t> xma_context_used_list_; // XMA contexts in use
};
} // namespace apu
} // namespace xe
#endif // XENIA_APU_XMA_DECODER_H_