diff --git a/src/xenia/apu/audio_system.cc b/src/xenia/apu/audio_system.cc index 1273c4b2a..aa9eb8dac 100644 --- a/src/xenia/apu/audio_system.cc +++ b/src/xenia/apu/audio_system.cc @@ -11,6 +11,7 @@ #include #include +#include #include @@ -44,6 +45,14 @@ X_STATUS AudioSystem::Setup() { callbacks.write = (RegisterWriteCallback)WriteRegisterThunk; emulator_->processor()->AddRegisterAccessCallbacks(callbacks); + // Setup worker thread state. This lets us make calls into guest code. + thread_state_ = new XenonThreadState( + emulator_->processor()->runtime(), 0, 16 * 1024, 0); + thread_state_->set_name("Audio Worker"); + thread_block_ = (uint32_t)memory_->HeapAlloc( + 0, 2048, alloy::MEMORY_FLAG_ZERO); + thread_state_->context()->r[13] = thread_block_; + // Create worker thread. // This will initialize the audio system. // Init needs to happen there so that any thread-local stuff @@ -82,8 +91,8 @@ void AudioSystem::ThreadStart() { auto clients = clients_; xe_mutex_unlock(lock_); for (auto it = clients.begin(); it != clients.end(); ++it) { - processor->ExecuteInterrupt( - 0, it->callback, it->wrapped_callback_arg, 0); + processor->Execute( + thread_state_, it->callback, it->wrapped_callback_arg, 0); } //worker_->Pump(); Sleep(1000); @@ -110,6 +119,9 @@ void AudioSystem::Shutdown() { xe_thread_join(thread_); xe_thread_release(thread_); + delete thread_state_; + memory()->HeapFree(thread_block_, 0); + xe_run_loop_release(run_loop_); } diff --git a/src/xenia/apu/audio_system.h b/src/xenia/apu/audio_system.h index e3f756691..c4e87f046 100644 --- a/src/xenia/apu/audio_system.h +++ b/src/xenia/apu/audio_system.h @@ -16,6 +16,7 @@ XEDECLARECLASS1(xe, Emulator); XEDECLARECLASS2(xe, cpu, Processor); +XEDECLARECLASS2(xe, cpu, XenonThreadState); namespace xe { @@ -72,6 +73,8 @@ protected: xe_run_loop_ref run_loop_; xe_thread_ref thread_; + cpu::XenonThreadState* thread_state_; + uint32_t thread_block_; bool running_; xe_mutex_t* lock_; diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index 0ae8d0854..b292a9e14 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -133,6 +133,7 @@ int Processor::Setup() { interrupt_thread_lock_ = xe_mutex_alloc(10000); interrupt_thread_state_ = new XenonThreadState( runtime_, 0, 16 * 1024, 0); + interrupt_thread_state_->set_name("Interrupt"); interrupt_thread_block_ = memory_->HeapAlloc( 0, 2048, MEMORY_FLAG_ZERO); interrupt_thread_state_->context()->r[13] = interrupt_thread_block_;