diff --git a/Utilities/SMutex.cpp b/Utilities/SMutex.cpp index 1803095f9d..efee7801f2 100644 --- a/Utilities/SMutex.cpp +++ b/Utilities/SMutex.cpp @@ -1,6 +1,4 @@ #include -#include "Utilities/Log.h" -#include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/CPU/CPUThread.h" diff --git a/Utilities/Thread.h b/Utilities/Thread.h index b2b7637265..83401da110 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -5,7 +5,7 @@ #include #include #include -#include +//#include static std::thread::id main_thread; diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index 507e589b51..6cc990b777 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -6,6 +6,7 @@ #include "Emu/System.h" #include "Emu/DbgCommand.h" +#include "CPUDecoder.h" #include "CPUThread.h" CPUThread* GetCurrentCPUThread() diff --git a/rpcs3/Emu/CPU/CPUThread.h b/rpcs3/Emu/CPU/CPUThread.h index 2a8ea78f2c..e827ca77f2 100644 --- a/rpcs3/Emu/CPU/CPUThread.h +++ b/rpcs3/Emu/CPU/CPUThread.h @@ -1,5 +1,4 @@ #pragma once -#include "Emu/CPU/CPUDecoder.h" enum CPUThreadType :unsigned char { @@ -20,6 +19,8 @@ enum CPUThreadStatus CPUThread_Step, }; +class CPUDecoder; + class CPUThread : public ThreadBase { protected: diff --git a/rpcs3/Emu/Cell/PPCThread.h b/rpcs3/Emu/Cell/PPCThread.h index e5dd118a9e..e0fbd5888c 100644 --- a/rpcs3/Emu/Cell/PPCThread.h +++ b/rpcs3/Emu/Cell/PPCThread.h @@ -1,5 +1,4 @@ #pragma once - #include "Emu/CPU/CPUThread.h" class PPCThread : public CPUThread diff --git a/rpcs3/Emu/Cell/SPURSManager.cpp b/rpcs3/Emu/Cell/SPURSManager.cpp index ab61442cb9..2e547dce37 100644 --- a/rpcs3/Emu/Cell/SPURSManager.cpp +++ b/rpcs3/Emu/Cell/SPURSManager.cpp @@ -1,7 +1,51 @@ #include "stdafx.h" -#include "SPURSManager.h" #include "Emu/Memory/Memory.h" +#include "SPURSManager.h" + +SPURSManagerAttribute::SPURSManagerAttribute(int nSpus, int spuPriority, int ppuPriority, bool exitIfNoWork) +{ + this->nSpus = nSpus; + this->spuThreadGroupPriority = spuPriority; + this->ppuThreadPriority = ppuPriority; + this->exitIfNoWork = exitIfNoWork; + + memset(this->namePrefix, 0, CELL_SPURS_NAME_MAX_LENGTH + 1); + this->threadGroupType = 0; + this->container = 0; +} + +int SPURSManagerAttribute::_setNamePrefix(const char *name, u32 size) +{ + strncpy(this->namePrefix, name, size); + this->namePrefix[0] = 0; + return 0; +} + +int SPURSManagerAttribute::_setSpuThreadGroupType(int type) +{ + this->threadGroupType = type; + return 0; +} + +int SPURSManagerAttribute::_setMemoryContainerForSpuThread(u32 container) +{ + this->container = container; + return 0; +} + +SPURSManagerEventFlag::SPURSManagerEventFlag(u32 flagClearMode, u32 flagDirection) +{ + this->flagClearMode = flagClearMode; + this->flagDirection = flagDirection; +} + +SPURSManagerTasksetAttribute::SPURSManagerTasksetAttribute(u64 args, mem8_t priority, u32 maxContention) +{ + this->args = args; + this->maxContention = maxContention; +} + SPURSManager::SPURSManager(SPURSManagerAttribute *attr) { this->attr = attr; @@ -26,4 +70,4 @@ SPURSManagerTaskset::SPURSManagerTaskset(u32 address, SPURSManagerTasksetAttribu { this->tattr = tattr; this->address = address; -} +} \ No newline at end of file diff --git a/rpcs3/Emu/Cell/SPURSManager.h b/rpcs3/Emu/Cell/SPURSManager.h index ff7a2b7ff5..210eda74cc 100644 --- a/rpcs3/Emu/Cell/SPURSManager.h +++ b/rpcs3/Emu/Cell/SPURSManager.h @@ -1,85 +1,18 @@ #pragma once -#include "Emu/Memory/Memory.h" - -// SPURS defines. -enum SPURSKernelInterfaces -{ - CELL_SPURS_MAX_SPU = 8, - CELL_SPURS_MAX_WORKLOAD = 16, - CELL_SPURS_MAX_WORKLOAD2 = 32, - CELL_SPURS_MAX_PRIORITY = 16, - CELL_SPURS_NAME_MAX_LENGTH = 15, - CELL_SPURS_SIZE = 4096, - CELL_SPURS_SIZE2 = 8192, - CELL_SPURS_ALIGN = 128, - CELL_SPURS_ATTRIBUTE_SIZE = 512, - CELL_SPURS_ATTRIBUTE_ALIGN = 8, - CELL_SPURS_INTERRUPT_VECTOR = 0x0, - CELL_SPURS_LOCK_LINE = 0x80, - CELL_SPURS_KERNEL_DMA_TAG_ID = 31, -}; - -enum RangeofEventQueuePortNumbers -{ - CELL_SPURS_STATIC_PORT_RANGE_BOTTOM = 15, - CELL_SPURS_DYNAMIC_PORT_RANGE_TOP = 16, - CELL_SPURS_DYNAMIC_PORT_RANGE_BOTTOM = 63, -}; - -enum SPURSTraceTypes -{ - CELL_SPURS_TRACE_TAG_LOAD = 0x2a, - CELL_SPURS_TRACE_TAG_MAP = 0x2b, - CELL_SPURS_TRACE_TAG_START = 0x2c, - CELL_SPURS_TRACE_TAG_STOP = 0x2d, - CELL_SPURS_TRACE_TAG_USER = 0x2e, - CELL_SPURS_TRACE_TAG_GUID = 0x2f, -}; - -// SPURS task defines. -enum TaskConstants -{ - CELL_SPURS_MAX_TASK = 128, - CELL_SPURS_TASK_TOP = 0x3000, - CELL_SPURS_TASK_BOTTOM = 0x40000, - CELL_SPURS_MAX_TASK_NAME_LENGTH = 32, -}; +#include "Emu/SysCalls/Modules/cellSpurs.h" // Internal class to shape a SPURS attribute. class SPURSManagerAttribute { public: - SPURSManagerAttribute(int nSpus, int spuPriority, int ppuPriority, bool exitIfNoWork) - { - this->nSpus = nSpus; - this->spuThreadGroupPriority = spuPriority; - this->ppuThreadPriority = ppuPriority; - this->exitIfNoWork = exitIfNoWork; + SPURSManagerAttribute(int nSpus, int spuPriority, int ppuPriority, bool exitIfNoWork); - memset(this->namePrefix, 0, CELL_SPURS_NAME_MAX_LENGTH + 1); - this->threadGroupType = 0; - this->container = 0; - } + int _setNamePrefix(const char *name, u32 size); - int _setNamePrefix(const char *name, u32 size) - { - strncpy(this->namePrefix, name, size); - this->namePrefix[0] = 0; - return 0; - } + int _setSpuThreadGroupType(int type); - int _setSpuThreadGroupType(int type) - { - this->threadGroupType = type; - return 0; - } - - int _setMemoryContainerForSpuThread(u32 container) - { - this->container = container; - return 0; - } + int _setMemoryContainerForSpuThread(u32 container); protected: be_t nSpus; @@ -94,11 +27,7 @@ protected: class SPURSManagerEventFlag { public: - SPURSManagerEventFlag(u32 flagClearMode, u32 flagDirection) - { - this->flagClearMode = flagClearMode; - this->flagDirection = flagDirection; - } + SPURSManagerEventFlag(u32 flagClearMode, u32 flagDirection); u32 _getDirection() { @@ -118,11 +47,7 @@ protected: class SPURSManagerTasksetAttribute { public: - SPURSManagerTasksetAttribute(u64 args, mem8_t priority, u32 maxContention) - { - this->args = args; - this->maxContention = maxContention; - } + SPURSManagerTasksetAttribute(u64 args, mem8_t priority, u32 maxContention); protected: be_t args; diff --git a/rpcs3/Emu/Event.cpp b/rpcs3/Emu/Event.cpp index d5065e2a98..5dce5b6884 100644 --- a/rpcs3/Emu/Event.cpp +++ b/rpcs3/Emu/Event.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" +//#include "Emu/System.h" #include "Event.h" void EventManager::Init() diff --git a/rpcs3/Emu/SysCalls/Callback.cpp b/rpcs3/Emu/SysCalls/Callback.cpp index 69fa0e8033..f3af71d9b8 100644 --- a/rpcs3/Emu/SysCalls/Callback.cpp +++ b/rpcs3/Emu/SysCalls/Callback.cpp @@ -2,10 +2,9 @@ #include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Callback.h" - #include "Emu/Cell/PPUThread.h" -#include "Emu/Cell/PPCThread.h" + +#include "Callback.h" Callback::Callback(u32 slot, u64 addr) : m_addr(addr) diff --git a/rpcs3/Emu/SysCalls/Modules.cpp b/rpcs3/Emu/SysCalls/Modules.cpp index 60427fc380..64d1bda99d 100644 --- a/rpcs3/Emu/SysCalls/Modules.cpp +++ b/rpcs3/Emu/SysCalls/Modules.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" #include "Emu/SysCalls/Static.h" @@ -175,6 +174,11 @@ bool Module::CheckID(u32 id, ID*& _id) const return Emu.GetIdManager().CheckID(id) && (_id = &Emu.GetIdManager().GetID(id))->m_name == GetName(); } +bool Module::RemoveId(u32 id) +{ + return Emu.GetIdManager().RemoveID(id); +} + IdManager& Module::GetIdManager() const { return Emu.GetIdManager(); diff --git a/rpcs3/Emu/SysCalls/Modules.h b/rpcs3/Emu/SysCalls/Modules.h index 722fadaafd..9472d235dd 100644 --- a/rpcs3/Emu/SysCalls/Modules.h +++ b/rpcs3/Emu/SysCalls/Modules.h @@ -114,6 +114,8 @@ public: return GetIdManager().GetNewID(GetName(), data, type); } + bool RemoveId(u32 id); + template __forceinline void AddFunc(u32 id, T func); template __forceinline void AddFunc(const char* name, T func); template __forceinline void AddFuncSub(const char group[8], const u64 ops[], const char* name, T func); diff --git a/rpcs3/Emu/SysCalls/Modules/SC_Keyboard.cpp b/rpcs3/Emu/SysCalls/Modules/SC_Keyboard.cpp index c71dac97ad..8f529f6e17 100644 --- a/rpcs3/Emu/SysCalls/Modules/SC_Keyboard.cpp +++ b/rpcs3/Emu/SysCalls/Modules/SC_Keyboard.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "Emu/Io/Keyboard.h" extern Module *sys_io; diff --git a/rpcs3/Emu/SysCalls/Modules/SC_Mouse.cpp b/rpcs3/Emu/SysCalls/Modules/SC_Mouse.cpp index b4cee94fdb..99648ea32c 100644 --- a/rpcs3/Emu/SysCalls/Modules/SC_Mouse.cpp +++ b/rpcs3/Emu/SysCalls/Modules/SC_Mouse.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "Emu/Io/Mouse.h" extern Module *sys_io; diff --git a/rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp b/rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp index 14a80c0660..c04cd67a01 100644 --- a/rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp +++ b/rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "Emu/Io/Pad.h" extern Module *sys_io; diff --git a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp index 4203a77338..1e1b661111 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp @@ -1,9 +1,7 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" -#include "cellPamf.h" extern std::mutex g_mutex_avcodec_open2; @@ -14,12 +12,77 @@ extern "C" #include "libswresample/swresample.h" } +#include "cellPamf.h" #include "cellAdec.h" //void cellAdec_init(); //Module cellAdec(0x0006, cellAdec_init); Module *cellAdec = nullptr; +AudioDecoder::AudioDecoder(AudioCodecType type, u32 addr, u32 size, u32 func, u32 arg) + : type(type) + , memAddr(addr) + , memSize(size) + , memBias(0) + , cbFunc(func) + , cbArg(arg) + , adecCb(nullptr) + , is_running(false) + , is_finished(false) + , just_started(false) + , just_finished(false) + , ctx(nullptr) + , fmt(nullptr) +{ + AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_ATRAC3P); + if (!codec) + { + cellAdec->Error("AudioDecoder(): avcodec_find_decoder(ATRAC3P) failed"); + Emu.Pause(); + return; + } + fmt = avformat_alloc_context(); + if (!fmt) + { + cellAdec->Error("AudioDecoder(): avformat_alloc_context failed"); + Emu.Pause(); + return; + } + io_buf = (u8*)av_malloc(4096); + fmt->pb = avio_alloc_context(io_buf, 4096, 0, this, adecRead, NULL, NULL); + if (!fmt->pb) + { + cellAdec->Error("AudioDecoder(): avio_alloc_context failed"); + Emu.Pause(); + return; + } +} + +AudioDecoder::~AudioDecoder() +{ + // TODO: check finalization + if (ctx) + { + for (u32 i = frames.GetCount() - 1; ~i; i--) + { + AdecFrame& af = frames.Peek(i); + av_frame_unref(af.data); + av_frame_free(&af.data); + } + avcodec_close(ctx); + avformat_close_input(&fmt); + } + if (fmt) + { + if (io_buf) + { + av_free(io_buf); + } + if (fmt->pb) av_free(fmt->pb); + avformat_free_context(fmt); + } +} + int adecRawRead(void* opaque, u8* buf, int buf_size) { AudioDecoder& adec = *(AudioDecoder*)opaque; @@ -33,7 +96,7 @@ next: { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "adecRawRead(): aborted"); + cellAdec->Warning("adecRawRead(): aborted"); return 0; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -65,7 +128,7 @@ next: } break; default: - LOG_ERROR(HLE, "adecRawRead(): sequence error (task %d)", adec.job.Peek().type); + cellAdec->Error("adecRawRead(): sequence error (task %d)", adec.job.Peek().type); return -1; } @@ -100,7 +163,7 @@ int adecRead(void* opaque, u8* buf, int buf_size) { if (buf_size < (int)adec.reader.rem_size) { - LOG_ERROR(HLE, "adecRead(): too small buf_size (rem_size = %d, buf_size = %d)", adec.reader.rem_size, buf_size); + cellAdec->Error("adecRead(): too small buf_size (rem_size = %d, buf_size = %d)", adec.reader.rem_size, buf_size); Emu.Pause(); return 0; } @@ -120,7 +183,7 @@ int adecRead(void* opaque, u8* buf, int buf_size) if (adecRawRead(opaque, header, 8) < 8) break; if (header[0] != 0x0f || header[1] != 0xd0) { - LOG_ERROR(HLE, "adecRead(): 0x0FD0 header not found"); + cellAdec->Error("adecRead(): 0x0FD0 header not found"); Emu.Pause(); return -1; } @@ -130,7 +193,7 @@ int adecRead(void* opaque, u8* buf, int buf_size) OMAHeader oma(1 /* atrac3p id */, header[2], header[3]); if (buf_size < sizeof(oma) + 8) { - LOG_ERROR(HLE, "adecRead(): OMAHeader writing failed"); + cellAdec->Error("adecRead(): OMAHeader writing failed"); Emu.Pause(); return 0; } @@ -187,7 +250,7 @@ u32 adecOpen(AudioDecoder* data) thread t("Audio Decoder[" + std::to_string(adec_id) + "] Thread", [&]() { - LOG_NOTICE(HLE, "Audio Decoder thread started"); + cellAdec->Notice("Audio Decoder thread started"); AdecTask& task = adec.task; @@ -218,288 +281,288 @@ u32 adecOpen(AudioDecoder* data) switch (task.type) { case adecStartSeq: - { - // TODO: reset data - LOG_WARNING(HLE, "adecStartSeq:"); + { + // TODO: reset data + cellAdec->Warning("adecStartSeq:"); - adec.reader.addr = 0; - adec.reader.size = 0; - adec.reader.init = false; - if (adec.reader.rem) free(adec.reader.rem); - adec.reader.rem = nullptr; - adec.reader.rem_size = 0; - adec.is_running = true; - adec.just_started = true; - } - break; + adec.reader.addr = 0; + adec.reader.size = 0; + adec.reader.init = false; + if (adec.reader.rem) free(adec.reader.rem); + adec.reader.rem = nullptr; + adec.reader.rem_size = 0; + adec.is_running = true; + adec.just_started = true; + } + break; case adecEndSeq: - { - // TODO: finalize - LOG_WARNING(HLE, "adecEndSeq:"); + { + // TODO: finalize + cellAdec->Warning("adecEndSeq:"); - /*Callback cb; - cb.SetAddr(adec.cbFunc); - cb.Handle(adec.id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, adec.cbArg); - cb.Branch(true); // ???*/ - adec.adecCb->ExecAsCallback(adec.cbFunc, true, adec.id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, adec.cbArg); + /*Callback cb; + cb.SetAddr(adec.cbFunc); + cb.Handle(adec.id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, adec.cbArg); + cb.Branch(true); // ???*/ + adec.adecCb->ExecAsCallback(adec.cbFunc, true, adec.id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, adec.cbArg); - adec.is_running = false; - adec.just_finished = true; - } - break; + adec.is_running = false; + adec.just_finished = true; + } + break; case adecDecodeAu: + { + int err = 0; + + adec.reader.addr = task.au.addr; + adec.reader.size = task.au.size; + //LOG_NOTICE(HLE, "Audio AU: size = 0x%x, pts = 0x%llx", task.au.size, task.au.pts); + + if (adec.just_started) { - int err = 0; + adec.first_pts = task.au.pts; + adec.last_pts = task.au.pts - 0x10000; // hack + } - adec.reader.addr = task.au.addr; - adec.reader.size = task.au.size; - //LOG_NOTICE(HLE, "Audio AU: size = 0x%x, pts = 0x%llx", task.au.size, task.au.pts); - - if (adec.just_started) + struct AVPacketHolder : AVPacket + { + AVPacketHolder(u32 size) { - adec.first_pts = task.au.pts; - adec.last_pts = task.au.pts - 0x10000; // hack + av_init_packet(this); + + if (size) + { + data = (u8*)av_calloc(1, size + FF_INPUT_BUFFER_PADDING_SIZE); + this->size = size + FF_INPUT_BUFFER_PADDING_SIZE; + } + else + { + data = NULL; + size = 0; + } } - struct AVPacketHolder : AVPacket + ~AVPacketHolder() { - AVPacketHolder(u32 size) - { - av_init_packet(this); + av_free(data); + //av_free_packet(this); + } - if (size) - { - data = (u8*)av_calloc(1, size + FF_INPUT_BUFFER_PADDING_SIZE); - this->size = size + FF_INPUT_BUFFER_PADDING_SIZE; - } - else - { - data = NULL; - size = 0; - } - } + } au(0); - ~AVPacketHolder() - { - av_free(data); - //av_free_packet(this); - } + /*{ + wxFile dump; + dump.Open(wxString::Format("audio pts-0x%llx.dump", task.au.pts), wxFile::write); + u8* buf = (u8*)malloc(task.au.size); + if (Memory.CopyToReal(buf, task.au.addr, task.au.size)) dump.Write(buf, task.au.size); + free(buf); + dump.Close(); + }*/ - } au(0); + if (adec.just_started && adec.just_finished) + { + avcodec_flush_buffers(adec.ctx); + adec.reader.init = true; + adec.just_finished = false; + adec.just_started = false; + } + else if (adec.just_started) // deferred initialization + { + err = avformat_open_input(&adec.fmt, NULL, av_find_input_format("oma"), NULL); + if (err) + { + cellAdec->Error("adecDecodeAu: avformat_open_input() failed"); + Emu.Pause(); + break; + } + AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_ATRAC3P); // ??? + if (!codec) + { + cellAdec->Error("adecDecodeAu: avcodec_find_decoder() failed"); + Emu.Pause(); + break; + } + //err = avformat_find_stream_info(adec.fmt, NULL); + //if (err) + //{ + // cellAdec->Error("adecDecodeAu: avformat_find_stream_info() failed"); + // Emu.Pause(); + // break; + //} + //if (!adec.fmt->nb_streams) + //{ + // cellAdec->Error("adecDecodeAu: no stream found"); + // Emu.Pause(); + // break; + //} + if (!avformat_new_stream(adec.fmt, codec)) + { + cellAdec->Error("adecDecodeAu: avformat_new_stream() failed"); + Emu.Pause(); + break; + } + adec.ctx = adec.fmt->streams[0]->codec; // TODO: check data - /*{ - wxFile dump; - dump.Open(wxString::Format("audio pts-0x%llx.dump", task.au.pts), wxFile::write); - u8* buf = (u8*)malloc(task.au.size); - if (Memory.CopyToReal(buf, task.au.addr, task.au.size)) dump.Write(buf, task.au.size); - free(buf); - dump.Close(); + AVDictionary* opts = nullptr; + av_dict_set(&opts, "refcounted_frames", "1", 0); + { + std::lock_guard lock(g_mutex_avcodec_open2); + // not multithread-safe (???) + err = avcodec_open2(adec.ctx, codec, &opts); + } + if (err) + { + cellAdec->Error("adecDecodeAu: avcodec_open2() failed"); + Emu.Pause(); + break; + } + adec.just_started = false; + } + + bool last_frame = false; + + while (true) + { + if (Emu.IsStopped()) + { + cellAdec->Warning("adecDecodeAu: aborted"); + return; + } + + /*if (!adec.ctx) // fake + { + AdecFrame frame; + frame.pts = task.au.pts; + frame.auAddr = task.au.addr; + frame.auSize = task.au.size; + frame.userdata = task.au.userdata; + frame.size = 4096; + frame.data = nullptr; + adec.frames.Push(frame); + + adec.adecCb->ExecAsCallback(adec.cbFunc, false, adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg); + + break; }*/ - if (adec.just_started && adec.just_finished) + last_frame = av_read_frame(adec.fmt, &au) < 0; + if (last_frame) { - avcodec_flush_buffers(adec.ctx); - adec.reader.init = true; - adec.just_finished = false; - adec.just_started = false; - } - else if (adec.just_started) // deferred initialization - { - err = avformat_open_input(&adec.fmt, NULL, av_find_input_format("oma"), NULL); - if (err) - { - LOG_ERROR(HLE, "adecDecodeAu: avformat_open_input() failed"); - Emu.Pause(); - break; - } - AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_ATRAC3P); // ??? - if (!codec) - { - LOG_ERROR(HLE, "adecDecodeAu: avcodec_find_decoder() failed"); - Emu.Pause(); - break; - } - /*err = avformat_find_stream_info(adec.fmt, NULL); - if (err) - { - LOG_ERROR(HLE, "adecDecodeAu: avformat_find_stream_info() failed"); - Emu.Pause(); - break; - } - if (!adec.fmt->nb_streams) - { - LOG_ERROR(HLE, "adecDecodeAu: no stream found"); - Emu.Pause(); - break; - }*/ - if (!avformat_new_stream(adec.fmt, codec)) - { - LOG_ERROR(HLE, "adecDecodeAu: avformat_new_stream() failed"); - Emu.Pause(); - break; - } - adec.ctx = adec.fmt->streams[0]->codec; // TODO: check data - - AVDictionary* opts = nullptr; - av_dict_set(&opts, "refcounted_frames", "1", 0); - { - std::lock_guard lock(g_mutex_avcodec_open2); - // not multithread-safe (???) - err = avcodec_open2(adec.ctx, codec, &opts); - } - if (err) - { - LOG_ERROR(HLE, "adecDecodeAu: avcodec_open2() failed"); - Emu.Pause(); - break; - } - adec.just_started = false; + //break; + av_free(au.data); + au.data = NULL; + au.size = 0; } - bool last_frame = false; - - while (true) + struct AdecFrameHolder : AdecFrame { - if (Emu.IsStopped()) + AdecFrameHolder() { - LOG_WARNING(HLE, "adecDecodeAu: aborted"); - return; + data = av_frame_alloc(); } - /*if (!adec.ctx) // fake + ~AdecFrameHolder() { - AdecFrame frame; - frame.pts = task.au.pts; - frame.auAddr = task.au.addr; - frame.auSize = task.au.size; - frame.userdata = task.au.userdata; - frame.size = 4096; - frame.data = nullptr; - adec.frames.Push(frame); + if (data) + { + av_frame_unref(data); + av_frame_free(&data); + } + } - adec.adecCb->ExecAsCallback(adec.cbFunc, false, adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg); + } frame; + if (!frame.data) + { + cellAdec->Error("adecDecodeAu: av_frame_alloc() failed"); + Emu.Pause(); + break; + } + + int got_frame = 0; + + int decode = avcodec_decode_audio4(adec.ctx, frame.data, &got_frame, &au); + + if (decode <= 0) + { + if (!last_frame && decode < 0) + { + cellAdec->Error("adecDecodeAu: AU decoding error(0x%x)", decode); + } + if (!got_frame && adec.reader.size == 0) break; + } + + if (got_frame) + { + u64 ts = av_frame_get_best_effort_timestamp(frame.data); + if (ts != AV_NOPTS_VALUE) + { + frame.pts = ts/* - adec.first_pts*/; + adec.last_pts = frame.pts; + } + else + { + adec.last_pts += ((u64)frame.data->nb_samples) * 90000 / 48000; + frame.pts = adec.last_pts; + } + //frame.pts = adec.last_pts; + //adec.last_pts += ((u64)frame.data->nb_samples) * 90000 / 48000; // ??? + frame.auAddr = task.au.addr; + frame.auSize = task.au.size; + frame.userdata = task.au.userdata; + frame.size = frame.data->nb_samples * frame.data->channels * sizeof(float); + + if (frame.data->format != AV_SAMPLE_FMT_FLTP) + { + cellAdec->Error("adecDecodeaAu: unsupported frame format(%d)", frame.data->format); + Emu.Pause(); break; - }*/ - - last_frame = av_read_frame(adec.fmt, &au) < 0; - if (last_frame) - { - //break; - av_free(au.data); - au.data = NULL; - au.size = 0; } - - struct AdecFrameHolder : AdecFrame + if (frame.data->channels != 2) { - AdecFrameHolder() - { - data = av_frame_alloc(); - } - - ~AdecFrameHolder() - { - if (data) - { - av_frame_unref(data); - av_frame_free(&data); - } - } - - } frame; - - if (!frame.data) - { - LOG_ERROR(HLE, "adecDecodeAu: av_frame_alloc() failed"); + cellAdec->Error("adecDecodeAu: unsupported channel count (%d)", frame.data->channels); Emu.Pause(); break; } - int got_frame = 0; + //LOG_NOTICE(HLE, "got audio frame (pts=0x%llx, nb_samples=%d, ch=%d, sample_rate=%d, nbps=%d)", + //frame.pts, frame.data->nb_samples, frame.data->channels, frame.data->sample_rate, + //av_get_bytes_per_sample((AVSampleFormat)frame.data->format)); - int decode = avcodec_decode_audio4(adec.ctx, frame.data, &got_frame, &au); + adec.frames.Push(frame); + frame.data = nullptr; // to prevent destruction - if (decode <= 0) - { - if (!last_frame && decode < 0) - { - LOG_ERROR(HLE, "adecDecodeAu: AU decoding error(0x%x)", decode); - } - if (!got_frame && adec.reader.size == 0) break; - } - - if (got_frame) - { - u64 ts = av_frame_get_best_effort_timestamp(frame.data); - if (ts != AV_NOPTS_VALUE) - { - frame.pts = ts/* - adec.first_pts*/; - adec.last_pts = frame.pts; - } - else - { - adec.last_pts += ((u64)frame.data->nb_samples) * 90000 / 48000; - frame.pts = adec.last_pts; - } - //frame.pts = adec.last_pts; - //adec.last_pts += ((u64)frame.data->nb_samples) * 90000 / 48000; // ??? - frame.auAddr = task.au.addr; - frame.auSize = task.au.size; - frame.userdata = task.au.userdata; - frame.size = frame.data->nb_samples * frame.data->channels * sizeof(float); - - if (frame.data->format != AV_SAMPLE_FMT_FLTP) - { - LOG_ERROR(HLE, "adecDecodeaAu: unsupported frame format(%d)", frame.data->format); - Emu.Pause(); - break; - } - if (frame.data->channels != 2) - { - LOG_ERROR(HLE, "adecDecodeAu: unsupported channel count (%d)", frame.data->channels); - Emu.Pause(); - break; - } - - //LOG_NOTICE(HLE, "got audio frame (pts=0x%llx, nb_samples=%d, ch=%d, sample_rate=%d, nbps=%d)", - //frame.pts, frame.data->nb_samples, frame.data->channels, frame.data->sample_rate, - //av_get_bytes_per_sample((AVSampleFormat)frame.data->format)); - - adec.frames.Push(frame); - frame.data = nullptr; // to prevent destruction - - /*Callback cb; - cb.SetAddr(adec.cbFunc); - cb.Handle(adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg); - cb.Branch(false);*/ - adec.adecCb->ExecAsCallback(adec.cbFunc, false, adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg); - } + /*Callback cb; + cb.SetAddr(adec.cbFunc); + cb.Handle(adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg); + cb.Branch(false);*/ + adec.adecCb->ExecAsCallback(adec.cbFunc, false, adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg); } - - /*Callback cb; - cb.SetAddr(adec.cbFunc); - cb.Handle(adec.id, CELL_ADEC_MSG_TYPE_AUDONE, task.au.auInfo_addr, adec.cbArg); - cb.Branch(false);*/ - adec.adecCb->ExecAsCallback(adec.cbFunc, false, adec.id, CELL_ADEC_MSG_TYPE_AUDONE, task.au.auInfo_addr, adec.cbArg); } - break; + + /*Callback cb; + cb.SetAddr(adec.cbFunc); + cb.Handle(adec.id, CELL_ADEC_MSG_TYPE_AUDONE, task.au.auInfo_addr, adec.cbArg); + cb.Branch(false);*/ + adec.adecCb->ExecAsCallback(adec.cbFunc, false, adec.id, CELL_ADEC_MSG_TYPE_AUDONE, task.au.auInfo_addr, adec.cbArg); + } + break; case adecClose: - { - adec.is_finished = true; - LOG_NOTICE(HLE, "Audio Decoder thread ended"); - return; - } + { + adec.is_finished = true; + cellAdec->Notice("Audio Decoder thread ended"); + return; + } default: - LOG_ERROR(HLE, "Audio Decoder thread error: unknown task(%d)", task.type); + cellAdec->Error("Audio Decoder thread error: unknown task(%d)", task.type); } } adec.is_finished = true; - LOG_WARNING(HLE, "Audio Decoder thread aborted"); + cellAdec->Warning("Audio Decoder thread aborted"); }); t.detach(); @@ -511,8 +574,8 @@ bool adecCheckType(AudioCodecType type) { switch (type) { - case CELL_ADEC_TYPE_ATRACX: LOG_NOTICE(HLE, "adecCheckType: ATRAC3plus"); break; - case CELL_ADEC_TYPE_ATRACX_2CH: LOG_NOTICE(HLE, "adecCheckType: ATRAC3plus 2ch"); break; + case CELL_ADEC_TYPE_ATRACX: cellAdec->Notice("adecCheckType: ATRAC3plus"); break; + case CELL_ADEC_TYPE_ATRACX_2CH: cellAdec->Notice("adecCheckType: ATRAC3plus 2ch"); break; case CELL_ADEC_TYPE_ATRACX_6CH: case CELL_ADEC_TYPE_ATRACX_8CH: @@ -587,7 +650,7 @@ int cellAdecClose(u32 handle) { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellAdecClose(%d) aborted", handle); + cellAdec->Warning("cellAdecClose(%d) aborted", handle); break; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -751,15 +814,15 @@ int cellAdecGetPcmItem(u32 handle, mem32_t pcmItem_ptr) void cellAdec_init() { - cellAdec->AddFunc(0x7e4a4a49, cellAdecQueryAttr); - cellAdec->AddFunc(0xd00a6988, cellAdecOpen); - cellAdec->AddFunc(0x8b5551a4, cellAdecOpenEx); - cellAdec->AddFunc(0x847d2380, cellAdecClose); - cellAdec->AddFunc(0x487b613e, cellAdecStartSeq); - cellAdec->AddFunc(0xe2ea549b, cellAdecEndSeq); - cellAdec->AddFunc(0x1529e506, cellAdecDecodeAu); - cellAdec->AddFunc(0x97ff2af1, cellAdecGetPcm); - cellAdec->AddFunc(0xbd75f78b, cellAdecGetPcmItem); + REG_FUNC(cellAdec, cellAdecQueryAttr); + REG_FUNC(cellAdec, cellAdecOpen); + REG_FUNC(cellAdec, cellAdecOpenEx); + REG_FUNC(cellAdec, cellAdecClose); + REG_FUNC(cellAdec, cellAdecStartSeq); + REG_FUNC(cellAdec, cellAdecEndSeq); + REG_FUNC(cellAdec, cellAdecDecodeAu); + REG_FUNC(cellAdec, cellAdecGetPcm); + REG_FUNC(cellAdec, cellAdecGetPcmItem); av_register_all(); avcodec_register_all(); diff --git a/rpcs3/Emu/SysCalls/Modules/cellAdec.h b/rpcs3/Emu/SysCalls/Modules/cellAdec.h index 108844f22c..a72c126094 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAdec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellAdec.h @@ -1117,67 +1117,7 @@ public: CPUThread* adecCb; - AudioDecoder(AudioCodecType type, u32 addr, u32 size, u32 func, u32 arg) - : type(type) - , memAddr(addr) - , memSize(size) - , memBias(0) - , cbFunc(func) - , cbArg(arg) - , adecCb(nullptr) - , is_running(false) - , is_finished(false) - , just_started(false) - , just_finished(false) - , ctx(nullptr) - , fmt(nullptr) - { - AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_ATRAC3P); - if (!codec) - { - LOG_ERROR(HLE, "AudioDecoder(): avcodec_find_decoder(ATRAC3P) failed"); - Emu.Pause(); - return; - } - fmt = avformat_alloc_context(); - if (!fmt) - { - LOG_ERROR(HLE, "AudioDecoder(): avformat_alloc_context failed"); - Emu.Pause(); - return; - } - io_buf = (u8*)av_malloc(4096); - fmt->pb = avio_alloc_context(io_buf, 4096, 0, this, adecRead, NULL, NULL); - if (!fmt->pb) - { - LOG_ERROR(HLE, "AudioDecoder(): avio_alloc_context failed"); - Emu.Pause(); - return; - } - } + AudioDecoder(AudioCodecType type, u32 addr, u32 size, u32 func, u32 arg); - ~AudioDecoder() - { - // TODO: check finalization - if (ctx) - { - for (u32 i = frames.GetCount() - 1; ~i; i--) - { - AdecFrame& af = frames.Peek(i); - av_frame_unref(af.data); - av_frame_free(&af.data); - } - avcodec_close(ctx); - avformat_close_input(&fmt); - } - if (fmt) - { - if (io_buf) - { - av_free(io_buf); - } - if (fmt->pb) av_free(fmt->pb); - avformat_free_context(fmt); - } - } + ~AudioDecoder(); }; diff --git a/rpcs3/Emu/SysCalls/Modules/cellAtrac.cpp b/rpcs3/Emu/SysCalls/Modules/cellAtrac.cpp index ddc1c1bf56..7967075062 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAtrac.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAtrac.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/SysCalls/Modules.h" diff --git a/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp b/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp index f9239b7f81..b370717eb3 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp @@ -1,15 +1,15 @@ #include "stdafx.h" -#include "rpcs3/Ini.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + +#include "rpcs3/Ini.h" #include "Utilities/SQueue.h" #include "Emu/Event.h" #include "Emu/SysCalls/lv2/sys_time.h" -#include "Emu/Audio/cellAudio.h" -#include "Emu/Audio/AudioManager.h" +//#include "Emu/Audio/AudioManager.h" #include "Emu/Audio/AudioDumper.h" +#include "Emu/Audio/cellAudio.h" //void cellAudio_init(); //Module cellAudio(0x0011, cellAudio_init); @@ -52,11 +52,11 @@ int cellAudioInit() if (do_dump && !m_dump.Init()) { - LOG_ERROR(HLE, "cellAudioInit(): AudioDumper::Init() failed"); + cellAudio->Error("cellAudioInit(): AudioDumper::Init() failed"); return; } - LOG_NOTICE(HLE, "Audio thread started"); + cellAudio->Notice("Audio thread started"); if (Ini.AudioDumpToFile.GetValue()) m_dump.WriteHeader(); @@ -137,7 +137,7 @@ int cellAudioInit() { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "Audio thread aborted"); + cellAudio->Warning("Audio thread aborted"); goto abort; } @@ -417,7 +417,7 @@ int cellAudioInit() { if (m_dump.WriteData(&buf8ch, sizeof(buf8ch)) != sizeof(buf8ch)) // write file data { - LOG_ERROR(HLE, "cellAudioInit(): AudioDumper::WriteData() failed"); + cellAudio->Error("cellAudioInit(): AudioDumper::WriteData() failed"); goto abort; } } @@ -425,13 +425,13 @@ int cellAudioInit() { if (m_dump.WriteData(&buf2ch, sizeof(buf2ch)) != sizeof(buf2ch)) // write file data { - LOG_ERROR(HLE, "cellAudioInit(): AudioDumper::WriteData() failed"); + cellAudio->Error("cellAudioInit(): AudioDumper::WriteData() failed"); goto abort; } } else { - LOG_ERROR(HLE, "cellAudioInit(): unknown AudioDumper::GetCh() value (%d)", m_dump.GetCh()); + cellAudio->Error("cellAudioInit(): unknown AudioDumper::GetCh() value (%d)", m_dump.GetCh()); goto abort; } } @@ -439,7 +439,7 @@ int cellAudioInit() //LOG_NOTICE(HLE, "Audio perf: start=%d (access=%d, AddData=%d, events=%d, dump=%d)", //stamp0 - m_config.start_time, stamp1 - stamp0, stamp2 - stamp1, stamp3 - stamp2, get_system_time() - stamp3); } - LOG_NOTICE(HLE, "Audio thread ended"); + cellAudio->Notice("Audio thread ended"); abort: queue.Push(nullptr); queue_float.Push(nullptr); @@ -471,7 +471,7 @@ abort: { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellAudioInit() aborted"); + cellAudio->Warning("cellAudioInit() aborted"); return CELL_OK; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -496,7 +496,7 @@ int cellAudioQuit() std::this_thread::sleep_for(std::chrono::milliseconds(1)); if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellAudioQuit(): aborted"); + cellAudio->Warning("cellAudioQuit(): aborted"); return CELL_OK; } } diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp index e1bb563179..8b99c8098b 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp @@ -1,9 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" + #include "cellPamf.h" #include "cellDmux.h" @@ -11,6 +10,300 @@ //Module cellDmux(0x0007, cellDmux_init); Module *cellDmux = nullptr; +PesHeader::PesHeader(DemuxerStream& stream) + : pts(0xffffffffffffffffull) + , dts(0xffffffffffffffffull) + , size(0) + , new_au(false) +{ + u16 header; + stream.get(header); + stream.get(size); + if (size) + { + u8 empty = 0; + u8 v; + while (true) + { + stream.get(v); + if (v != 0xFF) break; // skip padding bytes + empty++; + if (empty == size) return; + }; + + if ((v & 0xF0) == 0x20 && (size - empty) >= 5) // pts only + { + new_au = true; + pts = stream.get_ts(v); + stream.skip(size - empty - 5); + } + else + { + new_au = true; + if ((v & 0xF0) != 0x30 || (size - empty) < 10) + { + cellDmux->Error("PesHeader(): pts not found"); + Emu.Pause(); + } + pts = stream.get_ts(v); + stream.get(v); + if ((v & 0xF0) != 0x10) + { + cellDmux->Error("PesHeader(): dts not found"); + Emu.Pause(); + } + dts = stream.get_ts(v); + stream.skip(size - empty - 10); + } + } +} + +bool ElementaryStream::is_full() +{ + if (released < put_count) + { + u32 first = entries.Peek(); + if (first >= put) + { + return (first - put) < GetMaxAU(); + } + else + { + // probably, always false + return (put + GetMaxAU()) > (memAddr + memSize); + } + } + else + { + return false; + } +} + +const u32 ElementaryStream::GetMaxAU() const +{ + return (fidMajor == 0xbd) ? 4096 : 640 * 1024 + 128; // TODO +} + +u32 ElementaryStream::freespace() +{ + if (size > GetMaxAU()) + { + cellDmux->Error("es::freespace(): last_size too big (size=0x%x, max_au=0x%x)", size, GetMaxAU()); + Emu.Pause(); + return 0; + } + return GetMaxAU() - size; +} + +bool ElementaryStream::hasunseen() +{ + std::lock_guard lock(m_mutex); + return peek_count < put_count; +} + +bool ElementaryStream::hasdata() +{ + std::lock_guard lock(m_mutex); + return size != 0; +} + +bool ElementaryStream::isfull() +{ + std::lock_guard lock(m_mutex); + return is_full(); +} + +void ElementaryStream::finish(DemuxerStream& stream) // not multithread-safe +{ + u32 addr; + { + std::lock_guard lock(m_mutex); + //if (fidMajor != 0xbd) LOG_NOTICE(HLE, ">>> es::finish(): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", peek, first, put, size); + + addr = put; + /*if (!first) + { + first = put; + } + if (!peek) + { + peek = put; + }*/ + + mem_ptr_t info(put); + //if (fidMajor != 0xbd) LOG_WARNING(HLE, "es::finish(): (%s) size = 0x%x, info_addr=0x%x, pts = 0x%x", + //wxString(fidMajor == 0xbd ? "ATRAC3P Audio" : "Video AVC").wx_str(), + //(u32)info->auSize, put, (u32)info->ptsLower); + + u32 new_addr = a128(put + 128 + size); + put = ((new_addr + GetMaxAU()) > (memAddr + memSize)) + ? memAddr : new_addr; + + size = 0; + + put_count++; + //if (fidMajor != 0xbd) LOG_NOTICE(HLE, "<<< es::finish(): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", peek, first, put, size); + } + if (!entries.Push(addr)) + { + cellDmux->Error("es::finish() aborted (no space)"); + } +} + +void ElementaryStream::push(DemuxerStream& stream, u32 sz, PesHeader& pes) +{ + std::lock_guard lock(m_mutex); + + if (is_full()) + { + cellDmux->Error("es::push(): buffer is full"); + Emu.Pause(); + return; + } + + u32 data_addr = put + 128 + size; + size += sz; + memcpy(Memory + data_addr, Memory + stream.addr, sz); + stream.skip(sz); + + mem_ptr_t info(put); + info->auAddr = put + 128; + info->auSize = size; + if (pes.new_au) + { + info->dts.lower = (u32)pes.dts; + info->dts.upper = (u32)(pes.dts >> 32); + info->pts.lower = (u32)pes.pts; + info->pts.upper = (u32)(pes.pts >> 32); + info->isRap = false; // TODO: set valid value + info->reserved = 0; + info->userData = stream.userdata; + } + + mem_ptr_t tail(put + sizeof(CellDmuxAuInfoEx)); + tail->reserved1 = 0; + + mem_ptr_t inf(put + 64); + inf->auAddr = put + 128; + inf->auSize = size; + if (pes.new_au) + { + inf->dtsLower = (u32)pes.dts; + inf->dtsUpper = (u32)(pes.dts >> 32); + inf->ptsLower = (u32)pes.pts; + inf->ptsUpper = (u32)(pes.pts >> 32); + inf->auMaxSize = 0; // ????? + inf->userData = stream.userdata; + } +} + +bool ElementaryStream::release() +{ + std::lock_guard lock(m_mutex); + //if (fidMajor != 0xbd) LOG_NOTICE(HLE, ">>> es::release(): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", peek, first, put, size); + if (released >= put_count) + { + cellDmux->Error("es::release(): buffer is empty"); + return false; + } + + u32 addr = entries.Peek(); + + mem_ptr_t info(addr); + //if (fidMajor != 0xbd) LOG_WARNING(HLE, "es::release(): (%s) size = 0x%x, info = 0x%x, pts = 0x%x", + //wxString(fidMajor == 0xbd ? "ATRAC3P Audio" : "Video AVC").wx_str(), (u32)info->auSize, first, (u32)info->ptsLower); + + if (released >= peek_count) + { + cellDmux->Error("es::release(): buffer has not been seen yet"); + return false; + } + + /*u32 new_addr = a128(info.GetAddr() + 128 + info->auSize); + + if (new_addr == put) + { + first = 0; + } + else if ((new_addr + GetMaxAU()) > (memAddr + memSize)) + { + first = memAddr; + } + else + { + first = new_addr; + }*/ + + released++; + if (!entries.Pop(addr)) + { + cellDmux->Error("es::release(): entries.Pop() aborted (no entries found)"); + return false; + } + //if (fidMajor != 0xbd) LOG_NOTICE(HLE, "<<< es::release(): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", peek, first, put, size); + return true; +} + +bool ElementaryStream::peek(u32& out_data, bool no_ex, u32& out_spec, bool update_index) +{ + std::lock_guard lock(m_mutex); + //if (fidMajor != 0xbd) LOG_NOTICE(HLE, ">>> es::peek(%sAu%s): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", wxString(update_index ? "Get" : "Peek").wx_str(), + //wxString(no_ex ? "" : "Ex").wx_str(), peek, first, put, size); + if (peek_count >= put_count) return false; + + if (peek_count < released) + { + cellDmux->Error("es::peek(): sequence error: peek_count < released (peek_count=%d, released=%d)", peek_count, released); + Emu.Pause(); + return false; + } + + u32 addr = entries.Peek(peek_count - released); + mem_ptr_t info(addr); + //if (fidMajor != 0xbd) LOG_WARNING(HLE, "es::peek(%sAu(Ex)): (%s) size = 0x%x, info = 0x%x, pts = 0x%x", + //wxString(update_index ? "Get" : "Peek").wx_str(), + //wxString(fidMajor == 0xbd ? "ATRAC3P Audio" : "Video AVC").wx_str(), (u32)info->auSize, peek, (u32)info->ptsLower); + + out_data = addr; + out_spec = out_data + sizeof(CellDmuxAuInfoEx); + if (no_ex) out_data += 64; + + if (update_index) + { + /*u32 new_addr = a128(peek + 128 + info->auSize); + if (new_addr == put) + { + peek = 0; + } + else if ((new_addr + GetMaxAU()) > (memAddr + memSize)) + { + peek = memAddr; + } + else + { + peek = new_addr; + }*/ + peek_count++; + } + + //if (fidMajor != 0xbd) LOG_NOTICE(HLE, "<<< es::peek(%sAu%s): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", wxString(update_index ? "Get" : "Peek").wx_str(), + //wxString(no_ex ? "" : "Ex").wx_str(), peek, first, put, size); + return true; +} + +void ElementaryStream::reset() +{ + std::lock_guard lock(m_mutex); + //first = 0; + //peek = 0; + put = memAddr; + size = 0; + entries.Clear(); + put_count = 0; + released = 0; + peek_count = 0; +} + void dmuxQueryAttr(u32 info_addr /* may be 0 */, mem_ptr_t attr) { attr->demuxerVerLower = 0x280000; // TODO: check values @@ -44,7 +337,7 @@ u32 dmuxOpen(Demuxer* data) thread t("Demuxer[" + std::to_string(dmux_id) + "] Thread", [&]() { - LOG_NOTICE(HLE, "Demuxer thread started (mem=0x%x, size=0x%x, cb=0x%x, arg=0x%x)", dmux.memAddr, dmux.memSize, dmux.cbFunc, dmux.cbArg); + cellDmux->Notice("Demuxer thread started (mem=0x%x, size=0x%x, cb=0x%x, arg=0x%x)", dmux.memAddr, dmux.memSize, dmux.cbFunc, dmux.cbArg); DemuxerTask task; DemuxerStream stream; @@ -131,7 +424,7 @@ u32 dmuxOpen(Demuxer* data) if (!pes.new_au) // temporarily { - LOG_ERROR(HLE, "No pts info found"); + cellDmux->Error("No pts info found"); } // read additional header: @@ -261,7 +554,7 @@ u32 dmuxOpen(Demuxer* data) case 0x1dc: case 0x1dd: case 0x1de: case 0x1df: { // unknown - LOG_WARNING(HLE, "Unknown MPEG stream found"); + cellDmux->Warning("Unknown MPEG stream found"); stream.skip(4); stream.get(len); stream.skip(len); @@ -270,7 +563,7 @@ u32 dmuxOpen(Demuxer* data) case USER_DATA_START_CODE: { - LOG_ERROR(HLE, "USER_DATA_START_CODE found"); + cellDmux->Error("USER_DATA_START_CODE found"); return; } @@ -297,7 +590,7 @@ u32 dmuxOpen(Demuxer* data) { if (task.stream.discontinuity) { - LOG_WARNING(HLE, "dmuxSetStream (beginning)"); + cellDmux->Warning("dmuxSetStream (beginning)"); for (u32 i = 0; i < 192; i++) { if (esALL[i]) @@ -311,7 +604,7 @@ u32 dmuxOpen(Demuxer* data) if (updates_count != updates_signaled) { - LOG_ERROR(HLE, "dmuxSetStream: stream update inconsistency (input=%d, signaled=%d)", updates_count, updates_signaled); + cellDmux->Error("dmuxSetStream: stream update inconsistency (input=%d, signaled=%d)", updates_count, updates_signaled); return; } @@ -350,7 +643,7 @@ u32 dmuxOpen(Demuxer* data) case dmuxClose: { dmux.is_finished = true; - LOG_NOTICE(HLE, "Demuxer thread ended"); + cellDmux->Notice("Demuxer thread ended"); return; } @@ -374,7 +667,7 @@ u32 dmuxOpen(Demuxer* data) } else { - LOG_WARNING(HLE, "dmuxEnableEs: (TODO) unsupported filter (0x%x, 0x%x, 0x%x, 0x%x)", es.fidMajor, es.fidMinor, es.sup1, es.sup2); + cellDmux->Warning("dmuxEnableEs: (TODO) unsupported filter (0x%x, 0x%x, 0x%x, 0x%x)", es.fidMajor, es.fidMinor, es.sup1, es.sup2); } es.dmux = &dmux; } @@ -385,7 +678,7 @@ u32 dmuxOpen(Demuxer* data) ElementaryStream& es = *task.es.es_ptr; if (es.dmux != &dmux) { - LOG_WARNING(HLE, "dmuxDisableEs: invalid elementary stream"); + cellDmux->Warning("dmuxDisableEs: invalid elementary stream"); break; } for (u32 i = 0; i < 192; i++) @@ -443,11 +736,11 @@ u32 dmuxOpen(Demuxer* data) break; default: - LOG_ERROR(HLE, "Demuxer thread error: unknown task(%d)", task.type); + cellDmux->Error("Demuxer thread error: unknown task(%d)", task.type); return; } } - LOG_WARNING(HLE, "Demuxer thread aborted"); + cellDmux->Warning("Demuxer thread aborted"); }); t.detach(); @@ -551,7 +844,7 @@ int cellDmuxClose(u32 demuxerHandle) { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellDmuxClose(%d) aborted", demuxerHandle); + cellDmux->Warning("cellDmuxClose(%d) aborted", demuxerHandle); return CELL_OK; } @@ -578,7 +871,7 @@ int cellDmuxSetStream(u32 demuxerHandle, const u32 streamAddress, u32 streamSize { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellDmuxSetStream(%d) aborted (waiting)", demuxerHandle); + cellDmux->Warning("cellDmuxSetStream(%d) aborted (waiting)", demuxerHandle); return CELL_OK; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -597,12 +890,12 @@ int cellDmuxSetStream(u32 demuxerHandle, const u32 streamAddress, u32 streamSize u32 addr; if (!dmux->fbSetStream.Pop(addr)) { - LOG_WARNING(HLE, "cellDmuxSetStream(%d) aborted (fbSetStream.Pop())", demuxerHandle); + cellDmux->Warning("cellDmuxSetStream(%d) aborted (fbSetStream.Pop())", demuxerHandle); return CELL_OK; } if (addr != info.addr) { - LOG_ERROR(HLE, "cellDmuxSetStream(%d): wrong stream queued (right=0x%x, queued=0x%x)", demuxerHandle, info.addr, addr); + cellDmux->Error("cellDmuxSetStream(%d): wrong stream queued (right=0x%x, queued=0x%x)", demuxerHandle, info.addr, addr); Emu.Pause(); } return CELL_OK; @@ -638,12 +931,12 @@ int cellDmuxResetStreamAndWaitDone(u32 demuxerHandle) u32 addr; if (!dmux->fbSetStream.Pop(addr)) { - LOG_WARNING(HLE, "cellDmuxResetStreamAndWaitDone(%d) aborted (fbSetStream.Pop())", demuxerHandle); + cellDmux->Warning("cellDmuxResetStreamAndWaitDone(%d) aborted (fbSetStream.Pop())", demuxerHandle); return CELL_OK; } if (addr != 0) { - LOG_ERROR(HLE, "cellDmuxResetStreamAndWaitDone(%d): wrong stream queued (0x%x)", demuxerHandle, addr); + cellDmux->Error("cellDmuxResetStreamAndWaitDone(%d): wrong stream queued (0x%x)", demuxerHandle, addr); Emu.Pause(); } return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.h b/rpcs3/Emu/SysCalls/Modules/cellDmux.h index db6e39b5c8..cd0e5c6af7 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.h +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.h @@ -362,53 +362,7 @@ struct PesHeader u8 size; bool new_au; - PesHeader(DemuxerStream& stream) - : pts(0xffffffffffffffff) - , dts(0xffffffffffffffff) - , size(0) - , new_au(false) - { - u16 header; - stream.get(header); - stream.get(size); - if (size) - { - u8 empty = 0; - u8 v; - while (true) - { - stream.get(v); - if (v != 0xFF) break; // skip padding bytes - empty++; - if (empty == size) return; - }; - - if ((v & 0xF0) == 0x20 && (size - empty) >= 5) // pts only - { - new_au = true; - pts = stream.get_ts(v); - stream.skip(size - empty - 5); - } - else - { - new_au = true; - if ((v & 0xF0) != 0x30 || (size - empty) < 10) - { - LOG_ERROR(HLE, "PesHeader(): pts not found"); - Emu.Pause(); - } - pts = stream.get_ts(v); - stream.get(v); - if ((v & 0xF0) != 0x10) - { - LOG_ERROR(HLE, "PesHeader(): dts not found"); - Emu.Pause(); - } - dts = stream.get_ts(v); - stream.skip(size - empty - 10); - } - } - } + PesHeader(DemuxerStream& stream); }; class ElementaryStream; @@ -493,26 +447,7 @@ class ElementaryStream //u32 first; // AU that will be released //u32 peek; // AU that will be obtained by GetAu(Ex)/PeekAu(Ex) - bool is_full() - { - if (released < put_count) - { - u32 first = entries.Peek(); - if (first >= put) - { - return (first - put) < GetMaxAU(); - } - else - { - // probably, always false - return (put + GetMaxAU()) > (memAddr + memSize); - } - } - else - { - return false; - } - } + bool is_full(); public: Demuxer* dmux; @@ -548,228 +483,23 @@ public: { } - const u32 GetMaxAU() const - { - return (fidMajor == 0xbd) ? 4096 : 640 * 1024 + 128; // TODO - } + const u32 GetMaxAU() const; - u32 freespace() - { - if (size > GetMaxAU()) - { - LOG_ERROR(HLE, "es::freespace(): last_size too big (size=0x%x, max_au=0x%x)", size, GetMaxAU()); - Emu.Pause(); - return 0; - } - return GetMaxAU() - size; - } + u32 freespace(); - bool hasunseen() - { - std::lock_guard lock(m_mutex); - return peek_count < put_count; - } + bool hasunseen(); - bool hasdata() - { - std::lock_guard lock(m_mutex); - return size; - } + bool hasdata(); - bool isfull() - { - std::lock_guard lock(m_mutex); - return is_full(); - } + bool isfull(); - void finish(DemuxerStream& stream) // not multithread-safe - { - u32 addr; - { - std::lock_guard lock(m_mutex); - //if (fidMajor != 0xbd) LOG_NOTICE(HLE, ">>> es::finish(): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", peek, first, put, size); + void finish(DemuxerStream& stream); - addr = put; - /*if (!first) - { - first = put; - } - if (!peek) - { - peek = put; - }*/ + void push(DemuxerStream& stream, u32 sz, PesHeader& pes); - mem_ptr_t info(put); - //if (fidMajor != 0xbd) LOG_WARNING(HLE, "es::finish(): (%s) size = 0x%x, info_addr=0x%x, pts = 0x%x", - //wxString(fidMajor == 0xbd ? "ATRAC3P Audio" : "Video AVC").wx_str(), - //(u32)info->auSize, put, (u32)info->ptsLower); + bool release(); - u32 new_addr = a128(put + 128 + size); - put = ((new_addr + GetMaxAU()) > (memAddr + memSize)) - ? memAddr : new_addr; + bool peek(u32& out_data, bool no_ex, u32& out_spec, bool update_index); - size = 0; - - put_count++; - //if (fidMajor != 0xbd) LOG_NOTICE(HLE, "<<< es::finish(): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", peek, first, put, size); - } - if (!entries.Push(addr)) - { - LOG_ERROR(HLE, "es::finish() aborted (no space)"); - } - } - - void push(DemuxerStream& stream, u32 sz, PesHeader& pes) - { - std::lock_guard lock(m_mutex); - - if (is_full()) - { - LOG_ERROR(HLE, "es::push(): buffer is full"); - Emu.Pause(); - return; - } - - u32 data_addr = put + 128 + size; - size += sz; - memcpy(Memory + data_addr, Memory + stream.addr, sz); - stream.skip(sz); - - mem_ptr_t info(put); - info->auAddr = put + 128; - info->auSize = size; - if (pes.new_au) - { - info->dts.lower = (u32)pes.dts; - info->dts.upper = (u32)(pes.dts >> 32); - info->pts.lower = (u32)pes.pts; - info->pts.upper = (u32)(pes.pts >> 32); - info->isRap = false; // TODO: set valid value - info->reserved = 0; - info->userData = stream.userdata; - } - - mem_ptr_t tail(put + sizeof(CellDmuxAuInfoEx)); - tail->reserved1 = 0; - - mem_ptr_t inf(put + 64); - inf->auAddr = put + 128; - inf->auSize = size; - if (pes.new_au) - { - inf->dtsLower = (u32)pes.dts; - inf->dtsUpper = (u32)(pes.dts >> 32); - inf->ptsLower = (u32)pes.pts; - inf->ptsUpper = (u32)(pes.pts >> 32); - inf->auMaxSize = 0; // ????? - inf->userData = stream.userdata; - } - } - - bool release() - { - std::lock_guard lock(m_mutex); - //if (fidMajor != 0xbd) LOG_NOTICE(HLE, ">>> es::release(): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", peek, first, put, size); - if (released >= put_count) - { - LOG_ERROR(HLE, "es::release(): buffer is empty"); - return false; - } - - u32 addr = entries.Peek(); - - mem_ptr_t info(addr); - //if (fidMajor != 0xbd) LOG_WARNING(HLE, "es::release(): (%s) size = 0x%x, info = 0x%x, pts = 0x%x", - //wxString(fidMajor == 0xbd ? "ATRAC3P Audio" : "Video AVC").wx_str(), (u32)info->auSize, first, (u32)info->ptsLower); - - if (released >= peek_count) - { - LOG_ERROR(HLE, "es::release(): buffer has not been seen yet"); - return false; - } - - /*u32 new_addr = a128(info.GetAddr() + 128 + info->auSize); - - if (new_addr == put) - { - first = 0; - } - else if ((new_addr + GetMaxAU()) > (memAddr + memSize)) - { - first = memAddr; - } - else - { - first = new_addr; - }*/ - - released++; - if (!entries.Pop(addr)) - { - LOG_ERROR(HLE, "es::release(): entries.Pop() aborted (no entries found)"); - return false; - } - //if (fidMajor != 0xbd) LOG_NOTICE(HLE, "<<< es::release(): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", peek, first, put, size); - return true; - } - - bool peek(u32& out_data, bool no_ex, u32& out_spec, bool update_index) - { - std::lock_guard lock(m_mutex); - //if (fidMajor != 0xbd) LOG_NOTICE(HLE, ">>> es::peek(%sAu%s): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", wxString(update_index ? "Get" : "Peek").wx_str(), - //wxString(no_ex ? "" : "Ex").wx_str(), peek, first, put, size); - if (peek_count >= put_count) return false; - - if (peek_count < released) - { - LOG_ERROR(HLE, "es::peek(): sequence error: peek_count < released (peek_count=%d, released=%d)", peek_count, released); - Emu.Pause(); - return false; - } - - u32 addr = entries.Peek(peek_count - released); - mem_ptr_t info(addr); - //if (fidMajor != 0xbd) LOG_WARNING(HLE, "es::peek(%sAu(Ex)): (%s) size = 0x%x, info = 0x%x, pts = 0x%x", - //wxString(update_index ? "Get" : "Peek").wx_str(), - //wxString(fidMajor == 0xbd ? "ATRAC3P Audio" : "Video AVC").wx_str(), (u32)info->auSize, peek, (u32)info->ptsLower); - - out_data = addr; - out_spec = out_data + sizeof(CellDmuxAuInfoEx); - if (no_ex) out_data += 64; - - if (update_index) - { - /*u32 new_addr = a128(peek + 128 + info->auSize); - if (new_addr == put) - { - peek = 0; - } - else if ((new_addr + GetMaxAU()) > (memAddr + memSize)) - { - peek = memAddr; - } - else - { - peek = new_addr; - }*/ - peek_count++; - } - - //if (fidMajor != 0xbd) LOG_NOTICE(HLE, "<<< es::peek(%sAu%s): peek=0x%x, first=0x%x, put=0x%x, size=0x%x", wxString(update_index ? "Get" : "Peek").wx_str(), - //wxString(no_ex ? "" : "Ex").wx_str(), peek, first, put, size); - return true; - } - - void reset() - { - std::lock_guard lock(m_mutex); - //first = 0; - //peek = 0; - put = memAddr; - size = 0; - entries.Clear(); - put_count = 0; - released = 0; - peek_count = 0; - } + void reset(); }; diff --git a/rpcs3/Emu/SysCalls/Modules/cellFont.cpp b/rpcs3/Emu/SysCalls/Modules/cellFont.cpp index c9b94eea86..5987358ef3 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellFont.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellFont.cpp @@ -1,12 +1,10 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" + +#include "stblib/stb_truetype.h" #include "Emu/FS/vfsFile.h" #include "cellFont.h" -#include "stblib/stb_truetype.h" //void cellFont_init(); //void cellFont_load(); @@ -14,224 +12,6 @@ //Module cellFont(0x0019, cellFont_init, cellFont_load, cellFont_unload); Module *cellFont = nullptr; -// Font Set Types -enum -{ - CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN = 0x00000000, - CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN = 0x00000001, - CELL_FONT_TYPE_RODIN_SANS_SERIF_BOLD_LATIN = 0x00000002, - CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN2 = 0x00000018, - CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN2 = 0x00000019, - CELL_FONT_TYPE_RODIN_SANS_SERIF_BOLD_LATIN2 = 0x0000001a, - CELL_FONT_TYPE_MATISSE_SERIF_LATIN = 0x00000020, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_JAPANESE = 0x00000008, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_LIGHT_JAPANESE = 0x00000009, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_BOLD_JAPANESE = 0x0000000a, - CELL_FONT_TYPE_YD_GOTHIC_KOREAN = 0x0000000c, - CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_LATIN = 0x00000040, - CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_LATIN2 = 0x00000041, - CELL_FONT_TYPE_VAGR_SANS_SERIF_ROUND = 0x00000043, - CELL_FONT_TYPE_VAGR_SANS_SERIF_ROUND_LATIN2 = 0x00000044, - CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_JAPANESE = 0x00000048, - - CELL_FONT_TYPE_NEWRODIN_GOTHIC_JP_SET = 0x00000100, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_LATIN_SET = 0x00000101, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_SET = 0x00000104, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_SET = 0x00000204, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_SET = 0x00000201, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_SET = 0x00000108, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_RODIN_SET = 0x00000109, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_RODIN2_SET = 0x00000209, - CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_TCH_SET = 0x0000010a, - CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN_TCH_SET = 0x0000010b, - CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN2_TCH_SET = 0x0000020b, - CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_SCH_SET = 0x0000010c, - CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN_SCH_SET = 0x0000010d, - CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN2_SCH_SET = 0x0000020d, - - CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_RSANS_SET = 0x00300104, - CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_RSANS_SET = 0x00300105, - CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_JP_SET = 0x00300107, - CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_YG_DFHEI5_RSANS_SET = 0x00300109, - CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS_SET = 0x0030010F, - CELL_FONT_TYPE_VAGR_SEURAT_CAPIE_MARU_GOTHIC_RSANS_SET = 0x00300124, - CELL_FONT_TYPE_VAGR_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS_SET = 0x00300129, - - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_LIGHT_SET = 0x00040100, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN_LIGHT_SET = 0x00040101, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_LIGHT_SET = 0x00040201, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_LIGHT_SET = 0x00040104, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_LIGHT_SET = 0x00040204, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_BOLD_SET = 0x00070100, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN_BOLD_SET = 0x00070101, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_BOLD_SET = 0x00070201, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_BOLD_SET = 0x00070104, - CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_BOLD_SET = 0x00070204, - - CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_RSANS2_SET = 0x00300204, - CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_RSANS2_SET = 0x00300205, - CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET = 0x00300209, - CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET = 0x0030020F, - CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_VAGR2_SET = 0x00300229, - CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_VAGR2_SET = 0x00300224, -}; - -enum -{ - CELL_FONT_MAP_FONT = 0, - CELL_FONT_MAP_UNICODE = 1, -}; - -struct CellFontConfig -{ - struct { - be_t buffer_addr; - be_t size; - } FileCache; - - be_t userFontEntryMax; - be_t userFontEntrys_addr; - be_t flags; -}; - -struct CellFontRenderer -{ - void *systemReserved[64]; -}; - -//Custom enum to determine the origin of a CellFont object -enum -{ - CELL_FONT_OPEN_FONTSET, - CELL_FONT_OPEN_FONT_FILE, - CELL_FONT_OPEN_FONT_INSTANCE, - CELL_FONT_OPEN_MEMORY, -}; - -struct CellFont -{ - //void* SystemReserved[64]; - be_t scale_x; - be_t scale_y; - be_t slant; - be_t renderer_addr; - - stbtt_fontinfo stbfont; - be_t fontdata_addr; - be_t origin; -}; - -struct CellFontType -{ - be_t type; - be_t map; -}; - -struct CellFontInitGraphicsConfigGcm -{ - be_t configType; - struct { - be_t address; - be_t size; - } GraphicsMemory; - struct { - be_t address; - be_t size; - } MappedMainMemory; - struct { - be_t slotNumber; - be_t slotCount; - } VertexShader; -}; - -struct CellFontGraphics -{ - u32 graphicsType; - u32 SystemClosed_addr; -}; - -struct CellFontHorizontalLayout -{ - be_t baseLineY; - be_t lineHeight; - be_t effectHeight; -}; - -struct CellFontVerticalLayout -{ - be_t baseLineX; - be_t lineWidth; - be_t effectWidth; -}; - -struct CellFontGlyphMetrics -{ - be_t width; - be_t height; - struct { - be_t bearingX; - be_t bearingY; - be_t advance; - } Horizontal; - struct { - be_t bearingX; - be_t bearingY; - be_t advance; - } Vertical; -}; - -struct CellFontImageTransInfo -{ - be_t Image_addr; - be_t imageWidthByte; - be_t imageWidth; - be_t imageHeight; - be_t Surface_addr; - be_t surfWidthByte; -}; - -struct CellFontRendererConfig -{ - struct BufferingPolicy - { - be_t buffer; - be_t initSize; - be_t maxSize; - be_t expandSize; - be_t resetSize; - }; -}; - -struct CellFontRenderSurface -{ - be_t buffer_addr; - be_t widthByte; - be_t pixelSizeByte; - be_t width, height; - struct { - be_t x0, y0; - be_t x1, y1; - } Scissor; -}; - -// Internal Datatypes -struct CCellFontInternal //Module cellFont -{ - u32 m_buffer_addr, m_buffer_size; - u32 m_userFontEntrys_addr, m_userFontEntryMax; - - bool m_bInitialized; - bool m_bFontGcmInitialized; - - CCellFontInternal() - : m_buffer_addr(0) - , m_buffer_size(0) - , m_bInitialized(false) - , m_bFontGcmInitialized(false) - { - } -}; - CCellFontInternal* s_fontInternalInstance = nullptr; // Functions @@ -295,7 +75,9 @@ int cellFontOpenFontMemory(mem_ptr_t library, u32 fontAddr, u32 if (!s_fontInternalInstance->m_bInitialized) return CELL_FONT_ERROR_UNINITIALIZED; - if (!stbtt_InitFont(&(font->stbfont), (unsigned char*)Memory.VirtualToRealAddr(fontAddr), 0)) + font->stbfont = (stbtt_fontinfo*)((u8*)&(font->stbfont) + sizeof(void*)); // hack: use next bytes of the struct + + if (!stbtt_InitFont(font->stbfont, (unsigned char*)Memory.VirtualToRealAddr(fontAddr), 0)) return CELL_FONT_ERROR_FONT_OPEN_FAILED; font->renderer_addr = 0; @@ -483,8 +265,8 @@ int cellFontGetHorizontalLayout(mem_ptr_t font, mem_ptr_tstbfont), font->scale_y); - stbtt_GetFontVMetrics(&(font->stbfont), &ascent, &descent, &lineGap); + float scale = stbtt_ScaleForPixelHeight(font->stbfont, font->scale_y); + stbtt_GetFontVMetrics(font->stbfont, &ascent, &descent, &lineGap); layout->baseLineY = ascent * scale; layout->lineHeight = (ascent-descent+lineGap) * scale; @@ -558,14 +340,14 @@ int cellFontRenderCharGlyphImage(mem_ptr_t font, u32 code, mem_ptr_tstbfont), font->scale_y); - unsigned char* box = stbtt_GetCodepointBitmap(&(font->stbfont), scale, scale, code, &width, &height, &xoff, &yoff); + float scale = stbtt_ScaleForPixelHeight(font->stbfont, font->scale_y); + unsigned char* box = stbtt_GetCodepointBitmap(font->stbfont, scale, scale, code, &width, &height, &xoff, &yoff); if (!box) return CELL_OK; // Get the baseLineY value int baseLineY; int ascent, descent, lineGap; - stbtt_GetFontVMetrics(&(font->stbfont), &ascent, &descent, &lineGap); + stbtt_GetFontVMetrics(font->stbfont, &ascent, &descent, &lineGap); baseLineY = ascent * scale; // Move the rendered character to the surface @@ -640,9 +422,9 @@ int cellFontGetCharGlyphMetrics(mem_ptr_t font, u32 code, mem_ptr_tstbfont), font->scale_y); - stbtt_GetCodepointBox(&(font->stbfont), code, &x0, &y0, &x1, &y1); - stbtt_GetCodepointHMetrics(&(font->stbfont), code, &advanceWidth, &leftSideBearing); + float scale = stbtt_ScaleForPixelHeight(font->stbfont, font->scale_y); + stbtt_GetCodepointBox(font->stbfont, code, &x0, &y0, &x1, &y1); + stbtt_GetCodepointHMetrics(font->stbfont, code, &advanceWidth, &leftSideBearing); // TODO: Add the rest of the information metrics->width = (x1-x0) * scale; diff --git a/rpcs3/Emu/SysCalls/Modules/cellFont.h b/rpcs3/Emu/SysCalls/Modules/cellFont.h index f2cf9f1321..2f4dee8410 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellFont.h +++ b/rpcs3/Emu/SysCalls/Modules/cellFont.h @@ -44,4 +44,225 @@ struct CellFontMemoryInterface //CellFontFreeCallback Free; //CellFontReallocCallback Realloc; //CellFontCallocCallback Calloc; +}; + +// Font Set Types +enum +{ + CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN = 0x00000000, + CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN = 0x00000001, + CELL_FONT_TYPE_RODIN_SANS_SERIF_BOLD_LATIN = 0x00000002, + CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN2 = 0x00000018, + CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN2 = 0x00000019, + CELL_FONT_TYPE_RODIN_SANS_SERIF_BOLD_LATIN2 = 0x0000001a, + CELL_FONT_TYPE_MATISSE_SERIF_LATIN = 0x00000020, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_JAPANESE = 0x00000008, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_LIGHT_JAPANESE = 0x00000009, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_BOLD_JAPANESE = 0x0000000a, + CELL_FONT_TYPE_YD_GOTHIC_KOREAN = 0x0000000c, + CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_LATIN = 0x00000040, + CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_LATIN2 = 0x00000041, + CELL_FONT_TYPE_VAGR_SANS_SERIF_ROUND = 0x00000043, + CELL_FONT_TYPE_VAGR_SANS_SERIF_ROUND_LATIN2 = 0x00000044, + CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_JAPANESE = 0x00000048, + + CELL_FONT_TYPE_NEWRODIN_GOTHIC_JP_SET = 0x00000100, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_LATIN_SET = 0x00000101, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_SET = 0x00000104, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_SET = 0x00000204, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_SET = 0x00000201, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_SET = 0x00000108, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_RODIN_SET = 0x00000109, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_RODIN2_SET = 0x00000209, + CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_TCH_SET = 0x0000010a, + CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN_TCH_SET = 0x0000010b, + CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN2_TCH_SET = 0x0000020b, + CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_SCH_SET = 0x0000010c, + CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN_SCH_SET = 0x0000010d, + CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN2_SCH_SET = 0x0000020d, + + CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_RSANS_SET = 0x00300104, + CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_RSANS_SET = 0x00300105, + CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_JP_SET = 0x00300107, + CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_YG_DFHEI5_RSANS_SET = 0x00300109, + CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS_SET = 0x0030010F, + CELL_FONT_TYPE_VAGR_SEURAT_CAPIE_MARU_GOTHIC_RSANS_SET = 0x00300124, + CELL_FONT_TYPE_VAGR_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS_SET = 0x00300129, + + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_LIGHT_SET = 0x00040100, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN_LIGHT_SET = 0x00040101, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_LIGHT_SET = 0x00040201, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_LIGHT_SET = 0x00040104, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_LIGHT_SET = 0x00040204, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_BOLD_SET = 0x00070100, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN_BOLD_SET = 0x00070101, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_BOLD_SET = 0x00070201, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_BOLD_SET = 0x00070104, + CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_BOLD_SET = 0x00070204, + + CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_RSANS2_SET = 0x00300204, + CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_RSANS2_SET = 0x00300205, + CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET = 0x00300209, + CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET = 0x0030020F, + CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_VAGR2_SET = 0x00300229, + CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_VAGR2_SET = 0x00300224, +}; + +enum +{ + CELL_FONT_MAP_FONT = 0, + CELL_FONT_MAP_UNICODE = 1, +}; + +struct CellFontConfig +{ + struct { + be_t buffer_addr; + be_t size; + } FileCache; + + be_t userFontEntryMax; + be_t userFontEntrys_addr; + be_t flags; +}; + +struct CellFontRenderer +{ + void *systemReserved[64]; +}; + +//Custom enum to determine the origin of a CellFont object +enum +{ + CELL_FONT_OPEN_FONTSET, + CELL_FONT_OPEN_FONT_FILE, + CELL_FONT_OPEN_FONT_INSTANCE, + CELL_FONT_OPEN_MEMORY, +}; + +struct stbtt_fontinfo; + +struct CellFont +{ + //void* SystemReserved[64]; + be_t scale_x; + be_t scale_y; + be_t slant; + be_t renderer_addr; + + be_t fontdata_addr; + be_t origin; + stbtt_fontinfo* stbfont; + // hack: don't place anything after pointer +}; + +struct CellFontType +{ + be_t type; + be_t map; +}; + +struct CellFontInitGraphicsConfigGcm +{ + be_t configType; + struct { + be_t address; + be_t size; + } GraphicsMemory; + struct { + be_t address; + be_t size; + } MappedMainMemory; + struct { + be_t slotNumber; + be_t slotCount; + } VertexShader; +}; + +struct CellFontGraphics +{ + u32 graphicsType; + u32 SystemClosed_addr; +}; + +struct CellFontHorizontalLayout +{ + be_t baseLineY; + be_t lineHeight; + be_t effectHeight; +}; + +struct CellFontVerticalLayout +{ + be_t baseLineX; + be_t lineWidth; + be_t effectWidth; +}; + +struct CellFontGlyphMetrics +{ + be_t width; + be_t height; + struct { + be_t bearingX; + be_t bearingY; + be_t advance; + } Horizontal; + struct { + be_t bearingX; + be_t bearingY; + be_t advance; + } Vertical; +}; + +struct CellFontImageTransInfo +{ + be_t Image_addr; + be_t imageWidthByte; + be_t imageWidth; + be_t imageHeight; + be_t Surface_addr; + be_t surfWidthByte; +}; + +struct CellFontRendererConfig +{ + struct BufferingPolicy + { + be_t buffer; + be_t initSize; + be_t maxSize; + be_t expandSize; + be_t resetSize; + }; +}; + +struct CellFontRenderSurface +{ + be_t buffer_addr; + be_t widthByte; + be_t pixelSizeByte; + be_t width, height; + struct { + be_t x0, y0; + be_t x1, y1; + } Scissor; +}; + +// Internal Datatypes +struct CCellFontInternal //Module cellFont +{ + u32 m_buffer_addr, m_buffer_size; + u32 m_userFontEntrys_addr, m_userFontEntryMax; + + bool m_bInitialized; + bool m_bFontGcmInitialized; + + CCellFontInternal() + : m_buffer_addr(0) + , m_buffer_size(0) + , m_bInitialized(false) + , m_bFontGcmInitialized(false) + { + } }; \ No newline at end of file diff --git a/rpcs3/Emu/SysCalls/Modules/cellFontFT.cpp b/rpcs3/Emu/SysCalls/Modules/cellFontFT.cpp index ed1a50092b..7b42bf90fd 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellFontFT.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellFontFT.cpp @@ -1,9 +1,9 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "cellFont.h" +#include "cellFontFT.h" //void cellFontFT_init(); //void cellFontFT_load(); @@ -11,33 +11,6 @@ //Module cellFontFT(0x001a, cellFontFT_init, cellFontFT_load, cellFontFT_unload); Module *cellFontFT = nullptr; -struct CellFontLibraryConfigFT -{ - u32 library_addr; //void* - CellFontMemoryInterface MemoryIF; -}; - -struct CellFontRendererConfigFT -{ - struct { - u32 buffer_addr; //void* - u32 initSize; - u32 maxSize; - u32 expandSize; - u32 resetSize; - } BufferingPolicy; -}; - -struct CCellFontFTInternal -{ - bool m_bInitialized; - - CCellFontFTInternal() - : m_bInitialized(false) - { - } -}; - CCellFontFTInternal* s_fontFtInternalInstance = nullptr; int cellFontInitLibraryFreeTypeWithRevision(u64 revisionFlags, mem_ptr_t config, u32 lib_addr_addr) diff --git a/rpcs3/Emu/SysCalls/Modules/cellFontFT.h b/rpcs3/Emu/SysCalls/Modules/cellFontFT.h new file mode 100644 index 0000000000..fb8a0c109f --- /dev/null +++ b/rpcs3/Emu/SysCalls/Modules/cellFontFT.h @@ -0,0 +1,28 @@ +#pragma once + +struct CellFontLibraryConfigFT +{ + u32 library_addr; //void* + CellFontMemoryInterface MemoryIF; +}; + +struct CellFontRendererConfigFT +{ + struct { + u32 buffer_addr; //void* + u32 initSize; + u32 maxSize; + u32 expandSize; + u32 resetSize; + } BufferingPolicy; +}; + +struct CCellFontFTInternal +{ + bool m_bInitialized; + + CCellFontFTInternal() + : m_bInitialized(false) + { + } +}; \ No newline at end of file diff --git a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp index cec371afba..95d8bff3f2 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp @@ -1,13 +1,11 @@ #include "stdafx.h" -#include "Utilities/Log.h" -#include "Utilities/rMsgBox.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + +#include "Utilities/rMsgBox.h" #include "Emu/FS/vfsFile.h" - #include "Loader/PSF.h" - #include "cellGame.h" //void cellGame_init(); diff --git a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp index 688db567f8..5c994b3baf 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp @@ -1,11 +1,10 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" -#include "Emu/RSX/GCM.h" -#include "Emu/SysCalls/lv2/sys_process.h" -#include "sysPrxForUser.h" + +//#include "Emu/RSX/GCM.h" +//#include "Emu/SysCalls/lv2/sys_process.h" #include "cellGcmSys.h" //void cellGcmSys_init(); @@ -487,7 +486,7 @@ s32 cellGcmSetPrepareFlip(mem_ptr_t ctxt, u32 id) if(current + 8 >= end) { - LOG_WARNING(HLE, "bad flip!"); + cellGcmSys->Error("bad flip!"); //cellGcmCallback(ctxt.GetAddr(), current + 8 - end); //copied: diff --git a/rpcs3/Emu/SysCalls/Modules/cellGem.cpp b/rpcs3/Emu/SysCalls/Modules/cellGem.cpp index f70893af79..96ebff239e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGem.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGem.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/SysCalls/Modules.h" + #include "cellGem.h" void cellGem_init(); diff --git a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp index 9662ba0417..b684204a00 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp @@ -1,13 +1,11 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" -#include "cellGifDec.h" -#include "Emu/SysCalls/lv2/lv2Fs.h" #include "stblib/stb_image.h" #include "stblib/stb_image.c" // (TODO: Should we put this elsewhere?) +#include "Emu/SysCalls/lv2/lv2Fs.h" +#include "cellGifDec.h" //void cellGifDec_init(); //Module cellGifDec(0xf010, cellGifDec_init); @@ -269,7 +267,7 @@ int cellGifDecClose(u32 mainHandle, u32 subHandle) return CELL_GIFDEC_ERROR_FATAL; cellFsClose(subHandle_data->fd); - Emu.GetIdManager().RemoveID(subHandle); + cellGifDec->RemoveId(subHandle); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellGifDec.h b/rpcs3/Emu/SysCalls/Modules/cellGifDec.h index 7ed3160b27..7783855306 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGifDec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellGifDec.h @@ -1,6 +1,5 @@ #pragma once - //Return Codes enum { diff --git a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp index 64eb0696d6..43fd50ca63 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp @@ -1,11 +1,10 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" -#include "cellJpgDec.h" + #include "stblib/stb_image.h" #include "Emu/SysCalls/lv2/lv2Fs.h" +#include "cellJpgDec.h" //void cellJpgDec_init(); //Module cellJpgDec(0x000f, cellJpgDec_init); @@ -76,7 +75,7 @@ int cellJpgDecClose(u32 mainHandle, u32 subHandle) return CELL_JPGDEC_ERROR_FATAL; cellFsClose(subHandle_data->fd); - Emu.GetIdManager().RemoveID(subHandle); + cellJpgDec->RemoveId(subHandle); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp index b9eb3f6739..3f4db02ebd 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp @@ -1,8 +1,7 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "cellL10n.h" #include #include @@ -286,9 +285,9 @@ int _L10nConvertStr(int src_code, const void* src, size_t * src_len, int dst_cod //TODO: Check the code in emulation. If support for UTF8/UTF16/UTF32/UCS2/UCS4 should use wider chars.. awful. int L10nConvertStr(int src_code, mem8_ptr_t src, mem64_t src_len, int dst_code, mem8_ptr_t dst, mem64_t dst_len) { - LOG_ERROR(HLE, "L10nConvertStr(src_code=%d,src=0x%x,src_len=%ld,dst_code=%d,dst=0x%x,dst_len=%ld)", + cellL10n->Todo("L10nConvertStr(src_code=%d,src=0x%x,src_len=%ld,dst_code=%d,dst=0x%x,dst_len=%ld)", src_code, src.GetAddr(), src_len.GetValue(), dst_code, dst.GetAddr(), dst_len.GetValue()); - LOG_ERROR(HLE, "L10nConvertStr: 1st char at dst: %x(Hex)", *((char*)Memory.VirtualToRealAddr(src.GetAddr()))); + cellL10n->Todo("L10nConvertStr: 1st char at dst: %x(Hex)", *((char*)Memory.VirtualToRealAddr(src.GetAddr()))); #ifdef _MSC_VER unsigned int srcCode = 0, dstCode = 0; //OEM code pages bool src_page_converted = _L10nCodeParse(src_code, srcCode); //Check if code is in list. diff --git a/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp b/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp index dc958afdc9..76b43b0643 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp @@ -1,12 +1,11 @@ #include "stdafx.h" -#include "Utilities/Log.h" -#include "Utilities/rMsgBox.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" -#include "Emu/SysCalls/lv2/sys_time.h" -#include "rpcs3.h" +#include "rpcs3.h" +#include "Utilities/rMsgBox.h" +#include "Emu/SysCalls/lv2/sys_time.h" #include "cellSysutil.h" #include "cellMsgDialog.h" @@ -46,8 +45,8 @@ int cellMsgDialogOpen2(u32 type, mem_list_ptr_t msgString, mem_func_ptr_tWarning("Message: \n%s", msgString.GetString()); break; + case CELL_MSGDIALOG_TYPE_SE_TYPE_ERROR: cellSysutil->Error("Message: \n%s", msgString.GetString()); break; } switch (type & CELL_MSGDIALOG_TYPE_SE_MUTE) // TODO @@ -361,7 +360,7 @@ int cellMsgDialogProgressBarSetMsg(u32 progressBarIndex, mem_list_ptr_t msgS return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED; } - if (progressBarIndex >= (u32)(bool)m_gauge1 + (u32)(bool)m_gauge2) + if (progressBarIndex >= (m_gauge1 ? 1u : 0u) + (m_gauge2 ? 1u : 0u)) { return CELL_MSGDIALOG_ERROR_PARAM; } @@ -390,7 +389,7 @@ int cellMsgDialogProgressBarReset(u32 progressBarIndex) return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED; } - if (progressBarIndex >= (u32)(bool)m_gauge1 + (u32)(bool)m_gauge2) + if (progressBarIndex >= (m_gauge1 ? 1u : 0u) + (m_gauge2 ? 1u : 0u)) { return CELL_MSGDIALOG_ERROR_PARAM; } @@ -415,7 +414,7 @@ int cellMsgDialogProgressBarInc(u32 progressBarIndex, u32 delta) return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED; } - if (progressBarIndex >= (u32)(bool)m_gauge1 + (u32)(bool)m_gauge2) + if (progressBarIndex >= (m_gauge1 ? 1u : 0u) + (m_gauge2 ? 1u : 0u)) { return CELL_MSGDIALOG_ERROR_PARAM; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp b/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp index ad1b6d5e41..e4c2df02b9 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp @@ -1,7 +1,5 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" #include "cellNetCtl.h" diff --git a/rpcs3/Emu/SysCalls/Modules/cellPamf.cpp b/rpcs3/Emu/SysCalls/Modules/cellPamf.cpp index 7332696116..1ea9c785a0 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPamf.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellPamf.cpp @@ -1,8 +1,7 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "cellPamf.h" Module *cellPamf = nullptr; diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp index 988cd09c82..e94e3369c8 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp @@ -1,11 +1,10 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" -#include "cellPngDec.h" + #include "stblib/stb_image.h" #include "Emu/SysCalls/lv2/lv2Fs.h" +#include "cellPngDec.h" #include //void cellPngDec_init(); @@ -114,7 +113,7 @@ int cellPngDecClose(u32 mainHandle, u32 subHandle) return CELL_PNGDEC_ERROR_FATAL; cellFsClose(subHandle_data->fd); - Emu.GetIdManager().RemoveID(subHandle); + cellPngDec->RemoveId(subHandle); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellResc.cpp b/rpcs3/Emu/SysCalls/Modules/cellResc.cpp index cdc2a27488..e27532d895 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellResc.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellResc.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "cellSysutil.h" #include "Emu/RSX/sysutil_video.h" #include "cellResc.h" diff --git a/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp b/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp index 529a62f129..fbb110e40b 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp @@ -1,9 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" -#include "Utilities/rTime.h" #include "Emu/Memory/Memory.h" #include "Emu/SysCalls/Modules.h" +#include "Utilities/rTime.h" #include "cellRtc.h" //void cellRtc_init(); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSail.cpp b/rpcs3/Emu/SysCalls/Modules/cellSail.cpp index e191eea5e0..6859c20edf 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSail.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSail.cpp @@ -1,7 +1,5 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" #include "cellSail.h" diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp index d8af04b127..16860d49a4 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp @@ -1,9 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" +#include "Emu/Cell/SPURSManager.h" #include "cellSpurs.h" //void cellSpurs_init(); @@ -258,10 +257,10 @@ s32 cellSpursEnableExceptionEventHandler(mem_ptr_t spurs, bool flag) #endif } -s32 cellSpursSetGlobalExceptionEventHandler(mem_ptr_t spurs, mem_func_ptr_t eaHandler, u32 arg_addr) +s32 cellSpursSetGlobalExceptionEventHandler(mem_ptr_t spurs, u32 eaHandler_addr, u32 arg_addr) { - cellSpurs->Warning("cellSpursSetGlobalExceptionEventHandler(spurs_addr=0x%x, eaHandler_addr=0x%x, arg_addr=0x%x,)", - spurs.GetAddr(), eaHandler.GetAddr(), arg_addr); + cellSpurs->Warning("cellSpursSetGlobalExceptionEventHandler(spurs_addr=0x%x, eaHandler_addr=0x%x, arg_addr=0x%x)", + spurs.GetAddr(), eaHandler_addr, arg_addr); #ifdef PRX_DEBUG return GetCurrentPPUThread().FastCall2(libsre + 0xD6D0, libsre_rtoc); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h index 13d56dfaef..b23fea8496 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h @@ -1,5 +1,4 @@ #pragma once -#include "Emu/Cell/SPURSManager.h" // Core return codes. enum @@ -33,6 +32,55 @@ enum CELL_SPURS_TASK_ERROR_SHUTDOWN = 0x80410920, }; +// SPURS defines. +enum SPURSKernelInterfaces +{ + CELL_SPURS_MAX_SPU = 8, + CELL_SPURS_MAX_WORKLOAD = 16, + CELL_SPURS_MAX_WORKLOAD2 = 32, + CELL_SPURS_MAX_PRIORITY = 16, + CELL_SPURS_NAME_MAX_LENGTH = 15, + CELL_SPURS_SIZE = 4096, + CELL_SPURS_SIZE2 = 8192, + CELL_SPURS_ALIGN = 128, + CELL_SPURS_ATTRIBUTE_SIZE = 512, + CELL_SPURS_ATTRIBUTE_ALIGN = 8, + CELL_SPURS_INTERRUPT_VECTOR = 0x0, + CELL_SPURS_LOCK_LINE = 0x80, + CELL_SPURS_KERNEL_DMA_TAG_ID = 31, +}; + +enum RangeofEventQueuePortNumbers +{ + CELL_SPURS_STATIC_PORT_RANGE_BOTTOM = 15, + CELL_SPURS_DYNAMIC_PORT_RANGE_TOP = 16, + CELL_SPURS_DYNAMIC_PORT_RANGE_BOTTOM = 63, +}; + +enum SPURSTraceTypes +{ + CELL_SPURS_TRACE_TAG_LOAD = 0x2a, + CELL_SPURS_TRACE_TAG_MAP = 0x2b, + CELL_SPURS_TRACE_TAG_START = 0x2c, + CELL_SPURS_TRACE_TAG_STOP = 0x2d, + CELL_SPURS_TRACE_TAG_USER = 0x2e, + CELL_SPURS_TRACE_TAG_GUID = 0x2f, +}; + +// SPURS task defines. +enum TaskConstants +{ + CELL_SPURS_MAX_TASK = 128, + CELL_SPURS_TASK_TOP = 0x3000, + CELL_SPURS_TASK_BOTTOM = 0x40000, + CELL_SPURS_MAX_TASK_NAME_LENGTH = 32, +}; + +class SPURSManager; +class SPURSManagerAttribute; +class SPURSManagerEventFlag; +class SPURSManagerTaskset; + // Core CellSpurs structures. struct CellSpurs { @@ -146,11 +194,11 @@ struct CellSpursTracePacket }; // Exception handlers. -typedef void (*CellSpursGlobalExceptionEventHandler)(mem_ptr_t spurs, const mem_ptr_t info, - u32 id, mem_ptr_t arg); - -typedef void (*CellSpursTasksetExceptionEventHandler)(mem_ptr_t spurs, mem_ptr_t taskset, - u32 idTask, const mem_ptr_t info, mem_ptr_t arg); +//typedef void (*CellSpursGlobalExceptionEventHandler)(mem_ptr_t spurs, const mem_ptr_t info, +// u32 id, mem_ptr_t arg); +// +//typedef void (*CellSpursTasksetExceptionEventHandler)(mem_ptr_t spurs, mem_ptr_t taskset, +// u32 idTask, const mem_ptr_t info, mem_ptr_t arg); struct CellSpursTasksetInfo { @@ -159,7 +207,7 @@ struct CellSpursTasksetInfo be_t idWorkload; be_t idLastScheduledTask; //typedef unsigned CellSpursTaskId be_t name_addr; - CellSpursTasksetExceptionEventHandler exceptionEventHandler; + be_t exceptionEventHandler_addr; be_t exceptionEventHandlerArgument_addr; //void *exceptionEventHandlerArgument be_t sizeTaskset; //be_t reserved[]; diff --git a/rpcs3/Emu/SysCalls/Modules/cellSync.cpp b/rpcs3/Emu/SysCalls/Modules/cellSync.cpp index be77ae600f..e8f2908d89 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSync.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSync.cpp @@ -1,11 +1,10 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "Emu/SysCalls/lv2/sys_process.h" #include "Emu/Event.h" - #include "cellSync.h" //void cellSync_init(); @@ -90,7 +89,7 @@ s32 cellSyncMutexLock(mem_ptr_t mutex) std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellSyncMutexLock(mutex_addr=0x%x) aborted", mutex.GetAddr()); + cellSync->Warning("cellSyncMutexLock(mutex_addr=0x%x) aborted", mutex.GetAddr()); break; } } @@ -219,7 +218,7 @@ s32 cellSyncBarrierNotify(mem_ptr_t barrier) std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellSyncBarrierNotify(barrier_addr=0x%x) aborted", barrier.GetAddr()); + cellSync->Warning("cellSyncBarrierNotify(barrier_addr=0x%x) aborted", barrier.GetAddr()); return CELL_OK; } continue; @@ -306,7 +305,7 @@ s32 cellSyncBarrierWait(mem_ptr_t barrier) std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellSyncBarrierWait(barrier_addr=0x%x) aborted", barrier.GetAddr()); + cellSync->Warning("cellSyncBarrierWait(barrier_addr=0x%x) aborted", barrier.GetAddr()); return CELL_OK; } continue; @@ -1039,10 +1038,10 @@ s32 cellSyncQueueClear(mem_ptr_t queue) void syncLFQueueDump(mem_ptr_t queue) { - LOG_NOTICE(HLE, "CellSyncLFQueue dump: addr = 0x%x", queue.GetAddr()); + cellSync->Notice("CellSyncLFQueue dump: addr = 0x%x", queue.GetAddr()); for (u32 i = 0; i < sizeof(CellSyncLFQueue) / 16; i++) { - LOG_NOTICE(HLE, "*** 0x%.16llx 0x%.16llx", Memory.Read64(queue.GetAddr() + i * 16), Memory.Read64(queue.GetAddr() + i * 16 + 8)); + cellSync->Notice("*** 0x%.16llx 0x%.16llx", Memory.Read64(queue.GetAddr() + i * 16), Memory.Read64(queue.GetAddr() + i * 16 + 8)); } } @@ -2309,7 +2308,7 @@ void cellSync_init() } else { - LOG_NOTICE(HLE, "libsre: 0x%x : 0x%llx", i - libsre, flag); + cellSync->Notice("libsre: 0x%x : 0x%llx", i - libsre, flag); } } }); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp index c470d28e36..89b1b9333d 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/ModuleManager.h" diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp index 5490e172be..343637046f 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp @@ -1,20 +1,18 @@ #include "stdafx.h" -#include "rpcs3/Ini.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" #include "Emu/DbgCommand.h" -#include "Emu/FS/vfsFile.h" -#include "Emu/Audio/sysutil_audio.h" -#include "cellSysutil.h" -#include "cellSysutil_SaveData.h" +#include "rpcs3/Ini.h" +#include "Emu/FS/vfsFile.h" +#include "Loader/PSF.h" +#include "Emu/Audio/sysutil_audio.h" #include "Emu/RSX/sysutil_video.h" #include "cellMsgDialog.h" #include "cellGame.h" - -#include "Loader/PSF.h" +#include "cellSysutil.h" +#include "cellSysutil_SaveData.h" typedef void (*CellHddGameStatCallback)(mem_ptr_t cbResult, mem_ptr_t get, mem_ptr_t set); @@ -329,7 +327,7 @@ int cellSysutilCheckCallback() std::this_thread::sleep_for(std::chrono::milliseconds(1)); if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellSysutilCheckCallback() aborted"); + cellSysutil->Warning("cellSysutilCheckCallback() aborted"); break; } } diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysutilAp.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysutilAp.cpp index 2c2ddb95b3..0eb532cfed 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysutilAp.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysutilAp.cpp @@ -1,7 +1,5 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/Modules.h" //void cellSysutilAp_init(); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysutil_SaveData.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysutil_SaveData.cpp index fbc06e6693..d3b465417c 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysutil_SaveData.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysutil_SaveData.cpp @@ -1,14 +1,13 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" + #include "Emu/FS/vfsFile.h" #include "Emu/FS/vfsDir.h" -#include - -#include "cellSysutil_SaveData.h" #include "Loader/PSF.h" +#include "cellSysutil_SaveData.h" +#include extern Module *cellSysutil; @@ -228,7 +227,7 @@ s32 modifySaveDataFiles(mem_func_ptr_t& funcFile, mem_ { funcFile(result.GetAddr(), fileGet.GetAddr(), fileSet.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "modifySaveDataFiles: CellSaveDataFileCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("modifySaveDataFiles: CellSaveDataFileCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } if (result->result == CELL_SAVEDATA_CBRESULT_OK_LAST) { @@ -249,7 +248,7 @@ s32 modifySaveDataFiles(mem_func_ptr_t& funcFile, mem_ case CELL_SAVEDATA_FILETYPE_CONTENT_SND0: filepath += "SND0.AT3"; break; default: - LOG_ERROR(HLE, "modifySaveDataFiles: Unknown fileType! Aborting..."); + cellSysutil->Error("modifySaveDataFiles: Unknown fileType! Aborting..."); return CELL_SAVEDATA_ERROR_PARAM; } @@ -272,11 +271,11 @@ s32 modifySaveDataFiles(mem_func_ptr_t& funcFile, mem_ break; case CELL_SAVEDATA_FILEOP_WRITE_NOTRUNC: - LOG_WARNING(HLE, "modifySaveDataFiles: File operation CELL_SAVEDATA_FILEOP_WRITE_NOTRUNC not yet implemented"); + cellSysutil->Warning("modifySaveDataFiles: File operation CELL_SAVEDATA_FILEOP_WRITE_NOTRUNC not yet implemented"); break; default: - LOG_ERROR(HLE, "modifySaveDataFiles: Unknown fileOperation! Aborting..."); + cellSysutil->Error("modifySaveDataFiles: Unknown fileOperation! Aborting..."); return CELL_SAVEDATA_ERROR_PARAM; } @@ -334,7 +333,7 @@ int cellSaveDataListSave2(u32 version, mem_ptr_t setList, m funcList(result.GetAddr(), listGet.GetAddr(), listSet.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataListSave2: CellSaveDataListCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataListSave2: CellSaveDataListCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } @@ -342,7 +341,7 @@ int cellSaveDataListSave2(u32 version, mem_ptr_t setList, m if (listSet->newData.GetAddr()) addNewSaveDataEntry(saveEntries, (u32)listSet->newData.GetAddr()); if (saveEntries.size() == 0) { - LOG_WARNING(HLE, "cellSaveDataListSave2: No save entries found!"); // TODO: Find a better way to handle this error + cellSysutil->Warning("cellSaveDataListSave2: No save entries found!"); // TODO: Find a better way to handle this error return CELL_SAVEDATA_RET_OK; } @@ -355,7 +354,7 @@ int cellSaveDataListSave2(u32 version, mem_ptr_t setList, m funcStat(result.GetAddr(), statGet.GetAddr(), statSet.GetAddr()); Memory.Free(statGet->fileList.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataListLoad2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataListLoad2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } /*if (statSet->setParam.GetAddr()) @@ -414,7 +413,7 @@ int cellSaveDataListLoad2(u32 version, mem_ptr_t setList, m funcList(result.GetAddr(), listGet.GetAddr(), listSet.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataListLoad2: CellSaveDataListCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataListLoad2: CellSaveDataListCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } @@ -422,7 +421,7 @@ int cellSaveDataListLoad2(u32 version, mem_ptr_t setList, m if (listSet->newData.GetAddr()) addNewSaveDataEntry(saveEntries, (u32)listSet->newData.GetAddr()); if (saveEntries.size() == 0) { - LOG_WARNING(HLE, "cellSaveDataListLoad2: No save entries found!"); // TODO: Find a better way to handle this error + cellSysutil->Warning("cellSaveDataListLoad2: No save entries found!"); // TODO: Find a better way to handle this error return CELL_SAVEDATA_RET_OK; } @@ -435,7 +434,7 @@ int cellSaveDataListLoad2(u32 version, mem_ptr_t setList, m funcStat(result.GetAddr(), statGet.GetAddr(), statSet.GetAddr()); Memory.Free(statGet->fileList.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataListLoad2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataListLoad2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } /*if (statSet->setParam.GetAddr()) @@ -493,7 +492,7 @@ int cellSaveDataFixedSave2(u32 version, mem_ptr_t setList, } funcFixed(result.GetAddr(), listGet.GetAddr(), fixedSet.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataFixedSave2: CellSaveDataFixedCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataFixedSave2: CellSaveDataFixedCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } setSaveDataFixed(saveEntries, fixedSet.GetAddr()); @@ -504,7 +503,7 @@ int cellSaveDataFixedSave2(u32 version, mem_ptr_t setList, funcStat(result.GetAddr(), statGet.GetAddr(), statSet.GetAddr()); Memory.Free(statGet->fileList.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataFixedSave2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataFixedSave2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } /*if (statSet->setParam.GetAddr()) @@ -562,7 +561,7 @@ int cellSaveDataFixedLoad2(u32 version, mem_ptr_t setList, } funcFixed(result.GetAddr(), listGet.GetAddr(), fixedSet.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataFixedLoad2: CellSaveDataFixedCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataFixedLoad2: CellSaveDataFixedCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } setSaveDataFixed(saveEntries, fixedSet.GetAddr()); @@ -573,7 +572,7 @@ int cellSaveDataFixedLoad2(u32 version, mem_ptr_t setList, funcStat(result.GetAddr(), statGet.GetAddr(), statSet.GetAddr()); Memory.Free(statGet->fileList.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataFixedLoad2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataFixedLoad2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } /*if (statSet->setParam.GetAddr()) @@ -626,7 +625,7 @@ int cellSaveDataAutoSave2(u32 version, u32 dirName_addr, u32 errDialog, mem_ptr_ Memory.Free(statGet->fileList.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataAutoSave2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataAutoSave2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } /*if (statSet->setParam.GetAddr()) @@ -666,7 +665,7 @@ int cellSaveDataAutoLoad2(u32 version, u32 dirName_addr, u32 errDialog, mem_ptr_ // The target entry does not exist if (saveEntries.size() == 0) { - LOG_WARNING(HLE, "cellSaveDataAutoLoad2: Couldn't find save entry (%s)", dirName.c_str()); + cellSysutil->Warning("cellSaveDataAutoLoad2: Couldn't find save entry (%s)", dirName.c_str()); return CELL_OK; // TODO: Can anyone check the actual behaviour of a PS3 when saves are not found? } @@ -676,7 +675,7 @@ int cellSaveDataAutoLoad2(u32 version, u32 dirName_addr, u32 errDialog, mem_ptr_ Memory.Free(statGet->fileList.GetAddr()); if (result->result < 0) { - LOG_ERROR(HLE, "cellSaveDataAutoLoad2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. + cellSysutil->Error("cellSaveDataAutoLoad2: CellSaveDataStatCallback failed."); // TODO: Once we verify that the entire SysCall is working, delete this debug error message. return CELL_SAVEDATA_ERROR_CBRESULT; } /*if (statSet->setParam.GetAddr()) diff --git a/rpcs3/Emu/SysCalls/Modules/cellUserInfo.cpp b/rpcs3/Emu/SysCalls/Modules/cellUserInfo.cpp index a8325f6082..c549d2fada 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellUserInfo.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellUserInfo.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp index 9cb6efa0bf..73da9bb124 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp @@ -1,9 +1,7 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" -#include "cellPamf.h" std::mutex g_mutex_avcodec_open2; @@ -14,12 +12,77 @@ extern "C" #include "libavutil/imgutils.h" } +#include "cellPamf.h" #include "cellVdec.h" //void cellVdec_init(); //Module cellVdec(0x0005, cellVdec_init); Module *cellVdec = nullptr; +VideoDecoder::VideoDecoder(CellVdecCodecType type, u32 profile, u32 addr, u32 size, u32 func, u32 arg) + : type(type) + , profile(profile) + , memAddr(addr) + , memSize(size) + , memBias(0) + , cbFunc(func) + , cbArg(arg) + , is_finished(false) + , is_running(false) + , just_started(false) + , just_finished(false) + , ctx(nullptr) + , vdecCb(nullptr) +{ + AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_H264); + if (!codec) + { + cellVdec->Error("VideoDecoder(): avcodec_find_decoder(H264) failed"); + Emu.Pause(); + return; + } + fmt = avformat_alloc_context(); + if (!fmt) + { + cellVdec->Error("VideoDecoder(): avformat_alloc_context failed"); + Emu.Pause(); + return; + } + io_buf = (u8*)av_malloc(4096); + fmt->pb = avio_alloc_context(io_buf, 4096, 0, this, vdecRead, NULL, NULL); + if (!fmt->pb) + { + cellVdec->Error("VideoDecoder(): avio_alloc_context failed"); + Emu.Pause(); + return; + } +} + +VideoDecoder::~VideoDecoder() +{ + // TODO: check finalization + if (ctx) + { + for (u32 i = frames.GetCount() - 1; ~i; i--) + { + VdecFrame& vf = frames.Peek(i); + av_frame_unref(vf.data); + av_frame_free(&vf.data); + } + avcodec_close(ctx); + avformat_close_input(&fmt); + } + if (fmt) + { + if (io_buf) + { + av_free(io_buf); + } + if (fmt->pb) av_free(fmt->pb); + avformat_free_context(fmt); + } +} + int vdecRead(void* opaque, u8* buf, int buf_size) { VideoDecoder& vdec = *(VideoDecoder*)opaque; @@ -33,7 +96,7 @@ next: { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "vdecRead(): aborted"); + cellVdec->Warning("vdecRead(): aborted"); return 0; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -69,7 +132,7 @@ next: } break; default: - LOG_ERROR(HLE, "vdecRead(): sequence error (task %d)", vdec.job.Peek().type); + cellVdec->Error("vdecRead(): sequence error (task %d)", vdec.job.Peek().type); return 0; } @@ -126,7 +189,7 @@ u32 vdecOpen(VideoDecoder* data) thread t("Video Decoder[" + std::to_string(vdec_id) + "] Thread", [&]() { - LOG_NOTICE(HLE, "Video Decoder thread started"); + cellVdec->Notice("Video Decoder thread started"); VdecTask& task = vdec.task; @@ -157,257 +220,257 @@ u32 vdecOpen(VideoDecoder* data) switch (task.type) { case vdecStartSeq: - { - // TODO: reset data - LOG_WARNING(HLE, "vdecStartSeq:"); + { + // TODO: reset data + cellVdec->Warning("vdecStartSeq:"); - vdec.reader.addr = 0; - vdec.reader.size = 0; - vdec.is_running = true; - vdec.just_started = true; - } - break; + vdec.reader.addr = 0; + vdec.reader.size = 0; + vdec.is_running = true; + vdec.just_started = true; + } + break; case vdecEndSeq: - { - // TODO: finalize - LOG_WARNING(HLE, "vdecEndSeq:"); + { + // TODO: finalize + cellVdec->Warning("vdecEndSeq:"); - vdec.vdecCb->ExecAsCallback(vdec.cbFunc, false, vdec.id, CELL_VDEC_MSG_TYPE_SEQDONE, CELL_OK, vdec.cbArg); - /*Callback cb; - cb.SetAddr(vdec.cbFunc); - cb.Handle(vdec.id, CELL_VDEC_MSG_TYPE_SEQDONE, CELL_OK, vdec.cbArg); - cb.Branch(true); // ???*/ + vdec.vdecCb->ExecAsCallback(vdec.cbFunc, false, vdec.id, CELL_VDEC_MSG_TYPE_SEQDONE, CELL_OK, vdec.cbArg); + /*Callback cb; + cb.SetAddr(vdec.cbFunc); + cb.Handle(vdec.id, CELL_VDEC_MSG_TYPE_SEQDONE, CELL_OK, vdec.cbArg); + cb.Branch(true); // ???*/ - vdec.is_running = false; - vdec.just_finished = true; - } - break; + vdec.is_running = false; + vdec.just_finished = true; + } + break; case vdecDecodeAu: - { - int err; + { + int err; - if (task.mode != CELL_VDEC_DEC_MODE_NORMAL) + if (task.mode != CELL_VDEC_DEC_MODE_NORMAL) + { + cellVdec->Error("vdecDecodeAu: unsupported decoding mode(%d)", task.mode); + break; + } + + vdec.reader.addr = task.addr; + vdec.reader.size = task.size; + //LOG_NOTICE(HLE, "Video AU: size = 0x%x, pts = 0x%llx, dts = 0x%llx", task.size, task.pts, task.dts); + + if (vdec.just_started) + { + vdec.first_pts = task.pts; + vdec.last_pts = task.pts; + vdec.first_dts = task.dts; + } + + struct AVPacketHolder : AVPacket + { + AVPacketHolder(u32 size) { - LOG_ERROR(HLE, "vdecDecodeAu: unsupported decoding mode(%d)", task.mode); + av_init_packet(this); + + if (size) + { + data = (u8*)av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); + memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + this->size = size + FF_INPUT_BUFFER_PADDING_SIZE; + } + else + { + data = NULL; + size = 0; + } + } + + ~AVPacketHolder() + { + av_free(data); + //av_free_packet(this); + } + + } au(0); + + if (vdec.just_started && vdec.just_finished) + { + avcodec_flush_buffers(vdec.ctx); + vdec.just_started = false; + vdec.just_finished = false; + } + else if (vdec.just_started) // deferred initialization + { + err = avformat_open_input(&vdec.fmt, NULL, av_find_input_format("mpeg"), NULL); + if (err) + { + cellVdec->Error("vdecDecodeAu: avformat_open_input() failed"); + Emu.Pause(); + break; + } + AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_H264); // ??? + if (!codec) + { + cellVdec->Error("vdecDecodeAu: avcodec_find_decoder() failed"); + Emu.Pause(); + break; + } + /*err = avformat_find_stream_info(vdec.fmt, NULL); + if (err) + { + LOG_ERROR(HLE, "vdecDecodeAu: avformat_find_stream_info() failed"); + Emu.Pause(); + break; + } + if (!vdec.fmt->nb_streams) + { + LOG_ERROR(HLE, "vdecDecodeAu: no stream found"); + Emu.Pause(); + break; + }*/ + if (!avformat_new_stream(vdec.fmt, codec)) + { + cellVdec->Error("vdecDecodeAu: avformat_new_stream() failed"); + Emu.Pause(); + break; + } + vdec.ctx = vdec.fmt->streams[0]->codec; // TODO: check data + + AVDictionary* opts = nullptr; + av_dict_set(&opts, "refcounted_frames", "1", 0); + { + std::lock_guard lock(g_mutex_avcodec_open2); + // not multithread-safe (???) + err = avcodec_open2(vdec.ctx, codec, &opts); + } + if (err) + { + cellVdec->Error("vdecDecodeAu: avcodec_open2() failed"); + Emu.Pause(); + break; + } + vdec.just_started = false; + } + + bool last_frame = false; + + while (true) + { + if (Emu.IsStopped() || vdec.job.PeekIfExist().type == vdecClose) + { + vdec.is_finished = true; + cellVdec->Warning("vdecDecodeAu: aborted"); + return; + } + + last_frame = av_read_frame(vdec.fmt, &au) < 0; + if (last_frame) + { + //break; + av_free(au.data); + au.data = NULL; + au.size = 0; + } + + struct VdecFrameHolder : VdecFrame + { + VdecFrameHolder() + { + data = av_frame_alloc(); + } + + ~VdecFrameHolder() + { + if (data) + { + av_frame_unref(data); + av_frame_free(&data); + } + } + + } frame; + + if (!frame.data) + { + cellVdec->Error("vdecDecodeAu: av_frame_alloc() failed"); + Emu.Pause(); break; } - vdec.reader.addr = task.addr; - vdec.reader.size = task.size; - //LOG_NOTICE(HLE, "Video AU: size = 0x%x, pts = 0x%llx, dts = 0x%llx", task.size, task.pts, task.dts); + int got_picture = 0; - if (vdec.just_started) + int decode = avcodec_decode_video2(vdec.ctx, frame.data, &got_picture, &au); + + if (decode <= 0) { - vdec.first_pts = task.pts; - vdec.last_pts = task.pts; - vdec.first_dts = task.dts; + if (!last_frame && decode < 0) + { + cellVdec->Error("vdecDecodeAu: AU decoding error(0x%x)", decode); + } + if (!got_picture && vdec.reader.size == 0) break; // video end? } - struct AVPacketHolder : AVPacket + if (got_picture) { - AVPacketHolder(u32 size) + u64 ts = av_frame_get_best_effort_timestamp(frame.data); + if (ts != AV_NOPTS_VALUE) { - av_init_packet(this); - - if (size) - { - data = (u8*)av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); - memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); - this->size = size + FF_INPUT_BUFFER_PADDING_SIZE; - } - else - { - data = NULL; - size = 0; - } + frame.pts = ts/* - vdec.first_pts*/; // ??? + vdec.last_pts = frame.pts; } - - ~AVPacketHolder() + else { - av_free(data); - //av_free_packet(this); + vdec.last_pts += vdec.ctx->time_base.num * 90000 / (vdec.ctx->time_base.den / vdec.ctx->ticks_per_frame); + frame.pts = vdec.last_pts; } + //frame.pts = vdec.last_pts; + //vdec.last_pts += 3754; + frame.dts = (frame.pts - vdec.first_pts) + vdec.first_dts; + frame.userdata = task.userData; - } au(0); + //LOG_NOTICE(HLE, "got picture (pts=0x%llx, dts=0x%llx)", frame.pts, frame.dts); - if (vdec.just_started && vdec.just_finished) - { - avcodec_flush_buffers(vdec.ctx); - vdec.just_started = false; - vdec.just_finished = false; + vdec.frames.Push(frame); // !!!!!!!! + frame.data = nullptr; // to prevent destruction + + vdec.vdecCb->ExecAsCallback(vdec.cbFunc, false, vdec.id, CELL_VDEC_MSG_TYPE_PICOUT, CELL_OK, vdec.cbArg); + /*Callback cb; + cb.SetAddr(vdec.cbFunc); + cb.Handle(vdec.id, CELL_VDEC_MSG_TYPE_PICOUT, CELL_OK, vdec.cbArg); + cb.Branch(false);*/ } - else if (vdec.just_started) // deferred initialization - { - err = avformat_open_input(&vdec.fmt, NULL, av_find_input_format("mpeg"), NULL); - if (err) - { - LOG_ERROR(HLE, "vdecDecodeAu: avformat_open_input() failed"); - Emu.Pause(); - break; - } - AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_H264); // ??? - if (!codec) - { - LOG_ERROR(HLE, "vdecDecodeAu: avcodec_find_decoder() failed"); - Emu.Pause(); - break; - } - /*err = avformat_find_stream_info(vdec.fmt, NULL); - if (err) - { - LOG_ERROR(HLE, "vdecDecodeAu: avformat_find_stream_info() failed"); - Emu.Pause(); - break; - } - if (!vdec.fmt->nb_streams) - { - LOG_ERROR(HLE, "vdecDecodeAu: no stream found"); - Emu.Pause(); - break; - }*/ - if (!avformat_new_stream(vdec.fmt, codec)) - { - LOG_ERROR(HLE, "vdecDecodeAu: avformat_new_stream() failed"); - Emu.Pause(); - break; - } - vdec.ctx = vdec.fmt->streams[0]->codec; // TODO: check data - - AVDictionary* opts = nullptr; - av_dict_set(&opts, "refcounted_frames", "1", 0); - { - std::lock_guard lock(g_mutex_avcodec_open2); - // not multithread-safe (???) - err = avcodec_open2(vdec.ctx, codec, &opts); - } - if (err) - { - LOG_ERROR(HLE, "vdecDecodeAu: avcodec_open2() failed"); - Emu.Pause(); - break; - } - vdec.just_started = false; - } - - bool last_frame = false; - - while (true) - { - if (Emu.IsStopped() || vdec.job.PeekIfExist().type == vdecClose) - { - vdec.is_finished = true; - LOG_WARNING(HLE, "vdecDecodeAu: aborted"); - return; - } - - last_frame = av_read_frame(vdec.fmt, &au) < 0; - if (last_frame) - { - //break; - av_free(au.data); - au.data = NULL; - au.size = 0; - } - - struct VdecFrameHolder : VdecFrame - { - VdecFrameHolder() - { - data = av_frame_alloc(); - } - - ~VdecFrameHolder() - { - if (data) - { - av_frame_unref(data); - av_frame_free(&data); - } - } - - } frame; - - if (!frame.data) - { - LOG_ERROR(HLE, "vdecDecodeAu: av_frame_alloc() failed"); - Emu.Pause(); - break; - } - - int got_picture = 0; - - int decode = avcodec_decode_video2(vdec.ctx, frame.data, &got_picture, &au); - - if (decode <= 0) - { - if (!last_frame && decode < 0) - { - LOG_ERROR(HLE, "vdecDecodeAu: AU decoding error(0x%x)", decode); - } - if (!got_picture && vdec.reader.size == 0) break; // video end? - } - - if (got_picture) - { - u64 ts = av_frame_get_best_effort_timestamp(frame.data); - if (ts != AV_NOPTS_VALUE) - { - frame.pts = ts/* - vdec.first_pts*/; // ??? - vdec.last_pts = frame.pts; - } - else - { - vdec.last_pts += vdec.ctx->time_base.num * 90000 / (vdec.ctx->time_base.den / vdec.ctx->ticks_per_frame); - frame.pts = vdec.last_pts; - } - //frame.pts = vdec.last_pts; - //vdec.last_pts += 3754; - frame.dts = (frame.pts - vdec.first_pts) + vdec.first_dts; - frame.userdata = task.userData; - - //LOG_NOTICE(HLE, "got picture (pts=0x%llx, dts=0x%llx)", frame.pts, frame.dts); - - vdec.frames.Push(frame); // !!!!!!!! - frame.data = nullptr; // to prevent destruction - - vdec.vdecCb->ExecAsCallback(vdec.cbFunc, false, vdec.id, CELL_VDEC_MSG_TYPE_PICOUT, CELL_OK, vdec.cbArg); - /*Callback cb; - cb.SetAddr(vdec.cbFunc); - cb.Handle(vdec.id, CELL_VDEC_MSG_TYPE_PICOUT, CELL_OK, vdec.cbArg); - cb.Branch(false);*/ - } - } - - vdec.vdecCb->ExecAsCallback(vdec.cbFunc, false, vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg); - /*Callback cb; - cb.SetAddr(vdec.cbFunc); - cb.Handle(vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg); - cb.Branch(false);*/ } - break; + + vdec.vdecCb->ExecAsCallback(vdec.cbFunc, false, vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg); + /*Callback cb; + cb.SetAddr(vdec.cbFunc); + cb.Handle(vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg); + cb.Branch(false);*/ + } + break; case vdecClose: - { - vdec.is_finished = true; - LOG_NOTICE(HLE, "Video Decoder thread ended"); - return; - } + { + vdec.is_finished = true; + cellVdec->Notice("Video Decoder thread ended"); + return; + } case vdecSetFrameRate: - { - LOG_ERROR(HLE, "TODO: vdecSetFrameRate(%d)", task.frc); - } - break; + { + cellVdec->Error("TODO: vdecSetFrameRate(%d)", task.frc); + } + break; default: - LOG_ERROR(HLE, "Video Decoder thread error: unknown task(%d)", task.type); + cellVdec->Error("Video Decoder thread error: unknown task(%d)", task.type); } } vdec.is_finished = true; - LOG_WARNING(HLE, "Video Decoder thread aborted"); + cellVdec->Warning("Video Decoder thread aborted"); }); t.detach(); @@ -465,7 +528,7 @@ int cellVdecClose(u32 handle) { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellVdecClose(%d) aborted", handle); + cellVdec->Warning("cellVdecClose(%d) aborted", handle); break; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -516,7 +579,7 @@ int cellVdecEndSeq(u32 handle) { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "cellVdecEndSeq(%d) aborted", handle); + cellVdec->Warning("cellVdecEndSeq(%d) aborted", handle); return CELL_OK; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -690,13 +753,13 @@ int cellVdecGetPicItem(u32 handle, mem32_t picItem_ptr) } else { - LOG_ERROR(HLE, "cellVdecGetPicItem: unsupported time_base.den (%d)", vdec->ctx->time_base.den); + cellVdec->Error("cellVdecGetPicItem: unsupported time_base.den (%d)", vdec->ctx->time_base.den); Emu.Pause(); } } else { - LOG_ERROR(HLE, "cellVdecGetPicItem: unsupported time_base.num (%d)", vdec->ctx->time_base.num); + cellVdec->Error("cellVdecGetPicItem: unsupported time_base.num (%d)", vdec->ctx->time_base.num); Emu.Pause(); } avc->fixed_frame_rate_flag = true; diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.h b/rpcs3/Emu/SysCalls/Modules/cellVdec.h index 5b6a5633d2..10fb65a16e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.h @@ -727,67 +727,7 @@ public: CPUThread* vdecCb; - VideoDecoder(CellVdecCodecType type, u32 profile, u32 addr, u32 size, u32 func, u32 arg) - : type(type) - , profile(profile) - , memAddr(addr) - , memSize(size) - , memBias(0) - , cbFunc(func) - , cbArg(arg) - , is_finished(false) - , is_running(false) - , just_started(false) - , just_finished(false) - , ctx(nullptr) - , vdecCb(nullptr) - { - AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_H264); - if (!codec) - { - LOG_ERROR(HLE, "VideoDecoder(): avcodec_find_decoder(H264) failed"); - Emu.Pause(); - return; - } - fmt = avformat_alloc_context(); - if (!fmt) - { - LOG_ERROR(HLE, "VideoDecoder(): avformat_alloc_context failed"); - Emu.Pause(); - return; - } - io_buf = (u8*)av_malloc(4096); - fmt->pb = avio_alloc_context(io_buf, 4096, 0, this, vdecRead, NULL, NULL); - if (!fmt->pb) - { - LOG_ERROR(HLE, "VideoDecoder(): avio_alloc_context failed"); - Emu.Pause(); - return; - } - } + VideoDecoder(CellVdecCodecType type, u32 profile, u32 addr, u32 size, u32 func, u32 arg); - ~VideoDecoder() - { - // TODO: check finalization - if (ctx) - { - for (u32 i = frames.GetCount() - 1; ~i; i--) - { - VdecFrame& vf = frames.Peek(i); - av_frame_unref(vf.data); - av_frame_free(&vf.data); - } - avcodec_close(ctx); - avformat_close_input(&fmt); - } - if (fmt) - { - if (io_buf) - { - av_free(io_buf); - } - if (fmt->pb) av_free(fmt->pb); - avformat_free_context(fmt); - } - } + ~VideoDecoder(); }; diff --git a/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp b/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp index a2ac4e5beb..038fb4b891 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" @@ -33,7 +32,7 @@ u32 vpostOpen(VpostInstance* data) { u32 id = cellVpost->GetNewId(data); - LOG_NOTICE(HLE, "*** Vpost instance created (to_rgba=%d): id = %d", data->to_rgba, id); + cellVpost->Notice("*** Vpost instance created (to_rgba=%d): id = %d", data->to_rgba, id); return id; } @@ -90,15 +89,15 @@ int cellVpostExec(u32 handle, const u32 inPicBuff_addr, const mem_ptr_toutHeight; ctrlParam->inWindow; // ignored - if (ctrlParam->inWindow.x) LOG_WARNING(HLE, "*** inWindow.x = %d", (u32)ctrlParam->inWindow.x); - if (ctrlParam->inWindow.y) LOG_WARNING(HLE, "*** inWindow.y = %d", (u32)ctrlParam->inWindow.y); - if (ctrlParam->inWindow.width != w) LOG_WARNING(HLE, "*** inWindow.width = %d", (u32)ctrlParam->inWindow.width); - if (ctrlParam->inWindow.height != h) LOG_WARNING(HLE, "*** inWindow.height = %d", (u32)ctrlParam->inWindow.height); + if (ctrlParam->inWindow.x) cellVpost->Notice("*** inWindow.x = %d", (u32)ctrlParam->inWindow.x); + if (ctrlParam->inWindow.y) cellVpost->Notice("*** inWindow.y = %d", (u32)ctrlParam->inWindow.y); + if (ctrlParam->inWindow.width != w) cellVpost->Notice("*** inWindow.width = %d", (u32)ctrlParam->inWindow.width); + if (ctrlParam->inWindow.height != h) cellVpost->Notice("*** inWindow.height = %d", (u32)ctrlParam->inWindow.height); ctrlParam->outWindow; // ignored - if (ctrlParam->outWindow.x) LOG_WARNING(HLE, "*** outWindow.x = %d", (u32)ctrlParam->outWindow.x); - if (ctrlParam->outWindow.y) LOG_WARNING(HLE, "*** outWindow.y = %d", (u32)ctrlParam->outWindow.y); - if (ctrlParam->outWindow.width != ow) LOG_WARNING(HLE, "*** outWindow.width = %d", (u32)ctrlParam->outWindow.width); - if (ctrlParam->outWindow.height != oh) LOG_WARNING(HLE, "*** outWindow.height = %d", (u32)ctrlParam->outWindow.height); + if (ctrlParam->outWindow.x) cellVpost->Notice("*** outWindow.x = %d", (u32)ctrlParam->outWindow.x); + if (ctrlParam->outWindow.y) cellVpost->Notice("*** outWindow.y = %d", (u32)ctrlParam->outWindow.y); + if (ctrlParam->outWindow.width != ow) cellVpost->Notice("*** outWindow.width = %d", (u32)ctrlParam->outWindow.width); + if (ctrlParam->outWindow.height != oh) cellVpost->Notice("*** outWindow.height = %d", (u32)ctrlParam->outWindow.height); ctrlParam->execType; // ignored ctrlParam->scalerType; // ignored ctrlParam->ipcType; // ignored diff --git a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp index 028592ba62..ce707c74c6 100644 --- a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp +++ b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp @@ -1,9 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" + #include "Emu/Audio/cellAudio.h" #include "libmixer.h" @@ -337,7 +336,7 @@ int cellSurMixerCreate(const mem_ptr_t config) { if (Emu.IsStopped()) { - LOG_WARNING(HLE, "Surmixer aborted"); + libmixer->Warning("Surmixer aborted"); break; } diff --git a/rpcs3/Emu/SysCalls/Modules/sceNp.cpp b/rpcs3/Emu/SysCalls/Modules/sceNp.cpp index 4e3038fb3c..4135045b0b 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNp.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNp.cpp @@ -1,9 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" + #include "Emu/FS/vfsDir.h" #include "Crypto/unedat.h" #include "sceNp.h" diff --git a/rpcs3/Emu/SysCalls/Modules/sceNp.h b/rpcs3/Emu/SysCalls/Modules/sceNp.h index f8526e476d..0ac739cab0 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNp.h +++ b/rpcs3/Emu/SysCalls/Modules/sceNp.h @@ -1,5 +1,4 @@ #pragma once - #include "cellRtc.h" // Error Codes diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpClans.cpp b/rpcs3/Emu/SysCalls/Modules/sceNpClans.cpp index 3297717004..d0528c0334 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpClans.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNpClans.cpp @@ -1,9 +1,8 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/SysCalls/Modules.h" #include "Emu/System.h" -#include "cellRtc.h" +#include "Emu/SysCalls/Modules.h" + #include "sceNp.h" #include "sceNpClans.h" diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpCommerce2.cpp b/rpcs3/Emu/SysCalls/Modules/sceNpCommerce2.cpp index 8b6dbc76a7..c6e29023b0 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpCommerce2.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNpCommerce2.cpp @@ -1,8 +1,7 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/SysCalls/Modules.h" -#include "cellRtc.h" + #include "sceNpCommerce2.h" //void sceNpCommerce2_unload(); diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpCommerce2.h b/rpcs3/Emu/SysCalls/Modules/sceNpCommerce2.h index 3dd26730ef..90e30569d7 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpCommerce2.h +++ b/rpcs3/Emu/SysCalls/Modules/sceNpCommerce2.h @@ -1,4 +1,5 @@ #pragma once +#include "cellRtc.h" // Return codes enum diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpSns.cpp b/rpcs3/Emu/SysCalls/Modules/sceNpSns.cpp index bb7e7ba139..a5930c192d 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpSns.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNpSns.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/SysCalls/Modules.h" #include "sceNpSns.h" diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp b/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp index 3185e257e0..24a5360065 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp @@ -1,21 +1,16 @@ #include "stdafx.h" -#include "rpcs3/Ini.h" -#include "Utilities/Log.h" -#include "Utilities/rXml.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" -#include "Emu/FS/vfsDir.h" - -#include "cellRtc.h" -#include "sceNp.h" -#include "sceNpTrophy.h" +#include "rpcs3/Ini.h" +#include "Utilities/rXml.h" #include "Loader/TRP.h" #include "Loader/TROPUSR.h" +#include "Emu/FS/vfsDir.h" #include "Emu/SysCalls/lv2/sys_time.h" - +#include "sceNp.h" +#include "sceNpTrophy.h" #include #include @@ -350,7 +345,7 @@ int sceNpTrophyGetTrophyUnlockState(u32 context, u32 handle, mem_ptr_tGetTrophiesCount(); if (count.GetValue() > 128) - LOG_WARNING(HLE, "sceNpTrophyGetTrophyUnlockState: More than 128 trophies detected!"); + sceNpTrophy->Warning("sceNpTrophyGetTrophyUnlockState: More than 128 trophies detected!"); // Pack up to 128 bools in u32 flag_bits[4] for (u32 id=0; idTodo("_sys_printf(arg1=0x%x)", arg1); // probably, assertion failed - LOG_WARNING(TTY, "%s", (char*)(Memory + arg1)); - Emu.Pause(); + sysPrxForUser->Warning("_sys_printf: \n%s", (char*)(Memory + arg1)); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp index 87b8fe99b8..b99a75b804 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp @@ -1,9 +1,6 @@ #include "stdafx.h" -#include "rpcs3/Ini.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" #include "Emu/SysCalls/lv2/lv2Fs.h" @@ -157,7 +154,7 @@ void fsAioRead(u32 fd, mem_ptr_t aio, int xid, mem_func_ptr_tWarning("fsAioRead() aborted"); return; } } @@ -188,9 +185,8 @@ void fsAioRead(u32 fd, mem_ptr_t aio, int xid, mem_func_ptr_toffset, buf_addr, (u64)aio->size, error, res, xid, orig_file->GetPath().c_str()); + sys_fs->Log("*** fsAioRead(fd=%d, offset=0x%llx, buf_addr=0x%x, size=0x%x, error=0x%x, res=0x%x, xid=0x%x [%s])", + fd, (u64)aio->offset, buf_addr, (u64)aio->size, error, res, xid, orig_file->GetPath().c_str()); if (func) // start callback thread { diff --git a/rpcs3/Emu/SysCalls/Modules/sys_io.cpp b/rpcs3/Emu/SysCalls/Modules/sys_io.cpp index 37fc397e85..1eca9381a1 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_io.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_io.cpp @@ -1,8 +1,5 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" //void sys_io_init(); diff --git a/rpcs3/Emu/SysCalls/Modules/sys_net.cpp b/rpcs3/Emu/SysCalls/Modules/sys_net.cpp index 9923a619cd..40332c7240 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_net.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_net.cpp @@ -1,12 +1,7 @@ #include "stdafx.h" -#include "Utilities/Log.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" -#include "sys_net.h" - #ifdef _WIN32 #include #else @@ -19,6 +14,8 @@ extern "C" } #endif +#include "sys_net.h" + //void sys_net_init(); //Module sys_net((u16)0x0000, sys_net_init); Module *sys_net = nullptr; diff --git a/rpcs3/Emu/SysCalls/SC_FUNC.h b/rpcs3/Emu/SysCalls/SC_FUNC.h index 413f1a6d7a..7e3ecc41ad 100644 --- a/rpcs3/Emu/SysCalls/SC_FUNC.h +++ b/rpcs3/Emu/SysCalls/SC_FUNC.h @@ -1,5 +1,4 @@ #pragma once - #include "Emu/Cell/PPUThread.h" #define RESULT(x) CPU.GPR[3] = (x) diff --git a/rpcs3/Emu/SysCalls/Static.cpp b/rpcs3/Emu/SysCalls/Static.cpp index e1d206f769..866f50fe6e 100644 --- a/rpcs3/Emu/SysCalls/Static.cpp +++ b/rpcs3/Emu/SysCalls/Static.cpp @@ -1,9 +1,6 @@ #include "stdafx.h" #include "rpcs3/Ini.h" #include "Utilities/Log.h" -#include "Emu/Memory/Memory.h" -#include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/Modules.h" #include "Static.h" diff --git a/rpcs3/Emu/SysCalls/SysCalls.cpp b/rpcs3/Emu/SysCalls/SysCalls.cpp index ef8a18b00b..54ce826b74 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.cpp +++ b/rpcs3/Emu/SysCalls/SysCalls.cpp @@ -4,8 +4,6 @@ #include "Utilities/AutoPause.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" -#include "Emu/SysCalls/SC_FUNC.h" #include "ModuleManager.h" #include "lv2/lv2Fs.h" @@ -971,4 +969,9 @@ void SysCalls::DoSyscall(u32 code) IdManager& SysCallBase::GetIdManager() const { return Emu.GetIdManager(); +} + +bool SysCallBase::RemoveId(u32 id) +{ + return Emu.GetIdManager().RemoveID(id); } \ No newline at end of file diff --git a/rpcs3/Emu/SysCalls/SysCalls.h b/rpcs3/Emu/SysCalls/SysCalls.h index 76d6e80214..c96cbfcfb7 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.h +++ b/rpcs3/Emu/SysCalls/SysCalls.h @@ -52,6 +52,8 @@ public: { return GetIdManager().GetNewID(GetName(), data, type); } + + bool RemoveId(u32 id); }; extern bool dump_enable; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp b/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp index 30035fe135..082f933bdc 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/SysCalls.h" #include "sys_memory.h" @@ -140,7 +139,7 @@ s32 sys_memory_container_destroy(u32 cid) // Release the allocated memory and remove the ID. Memory.Free(ct->addr); - Emu.GetIdManager().RemoveID(cid); + sys_memory.RemoveId(cid); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp index 603e17b6a3..3c580f1721 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" #include "Emu/Memory/Memory.h" -#include "Emu/System.h" #include "Emu/SysCalls/SysCalls.h" #include "sys_memory.h" @@ -155,7 +154,7 @@ s32 sys_mmapper_free_memory(u32 mem_id) // Release the allocated memory and remove the ID. Memory.Free(info->addr); - Emu.GetIdManager().RemoveID(mem_id); + sys_mmapper.RemoveId(mem_id); return CELL_OK; } diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index ec21d85dbd..4f48d787df 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -2,7 +2,6 @@ #include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -//#include "Ini.h" #include "Emu/GameInfo.h" #include "Emu/SysCalls/Static.h" diff --git a/rpcs3/Loader/ELF.cpp b/rpcs3/Loader/ELF.cpp index d967e4583e..aaa7af4c65 100644 --- a/rpcs3/Loader/ELF.cpp +++ b/rpcs3/Loader/ELF.cpp @@ -1,7 +1,16 @@ #include "stdafx.h" -#include "Loader.h" #include "ELF.h" +void Elf_Ehdr::Show() +{ +} + +void Elf_Ehdr::Load(vfsStream& f) +{ + e_magic = Read32(f); + e_class = Read8(f); +} + ELFLoader::ELFLoader(vfsStream& f) : elf_f(f) , LoaderBase() diff --git a/rpcs3/Loader/ELF.h b/rpcs3/Loader/ELF.h index cbb9d88473..3ff9e34224 100644 --- a/rpcs3/Loader/ELF.h +++ b/rpcs3/Loader/ELF.h @@ -1,7 +1,6 @@ #pragma once #include "ELF64.h" #include "ELF32.h" -#include "Emu/FS/vfsStream.h" enum ElfClass { @@ -15,15 +14,9 @@ struct Elf_Ehdr u32 e_magic; u8 e_class; - virtual void Show() - { - } + virtual void Show(); - virtual void Load(vfsStream& f) - { - e_magic = Read32(f); - e_class = Read8(f); - } + virtual void Load(vfsStream& f); bool CheckMagic() const { return e_magic == 0x7F454C46; } diff --git a/rpcs3/Loader/ELF32.cpp b/rpcs3/Loader/ELF32.cpp index 2c3c4f4fac..6c327e0494 100644 --- a/rpcs3/Loader/ELF32.cpp +++ b/rpcs3/Loader/ELF32.cpp @@ -3,6 +3,207 @@ #include "Emu/Memory/Memory.h" #include "ELF32.h" +void Elf32_Ehdr::Show() +{ +#ifdef LOADER_DEBUG + LOG_NOTICE(LOADER, "Magic: %08x", e_magic); + LOG_NOTICE(LOADER, "Class: %s", "ELF32"); + LOG_NOTICE(LOADER, "Data: %s", Ehdr_DataToString(e_data).c_str()); + LOG_NOTICE(LOADER, "Current Version: %d", e_curver); + LOG_NOTICE(LOADER, "OS/ABI: %s", Ehdr_OS_ABIToString(e_os_abi).c_str()); + LOG_NOTICE(LOADER, "ABI version: %lld", e_abi_ver); + LOG_NOTICE(LOADER, "Type: %s", Ehdr_TypeToString(e_type).c_str()); + LOG_NOTICE(LOADER, "Machine: %s", Ehdr_MachineToString(e_machine).c_str()); + LOG_NOTICE(LOADER, "Version: %d", e_version); + LOG_NOTICE(LOADER, "Entry point address: 0x%x", e_entry); + LOG_NOTICE(LOADER, "Program headers offset: 0x%08x", e_phoff); + LOG_NOTICE(LOADER, "Section headers offset: 0x%08x", e_shoff); + LOG_NOTICE(LOADER, "Flags: 0x%x", e_flags); + LOG_NOTICE(LOADER, "Size of this header: %d", e_ehsize); + LOG_NOTICE(LOADER, "Size of program headers: %d", e_phentsize); + LOG_NOTICE(LOADER, "Number of program headers: %d", e_phnum); + LOG_NOTICE(LOADER, "Size of section headers: %d", e_shentsize); + LOG_NOTICE(LOADER, "Number of section headers: %d", e_shnum); + LOG_NOTICE(LOADER, "Section header string table index: %d", e_shstrndx); +#endif +} + +void Elf32_Ehdr::Load(vfsStream& f) +{ + e_magic = Read32(f); + e_class = Read8(f); + e_data = Read8(f); + e_curver = Read8(f); + e_os_abi = Read8(f); + + if(IsLittleEndian()) + { + e_abi_ver = Read64LE(f); + e_type = Read16LE(f); + e_machine = Read16LE(f); + e_version = Read32LE(f); + e_entry = Read32LE(f); + e_phoff = Read32LE(f); + e_shoff = Read32LE(f); + e_flags = Read32LE(f); + e_ehsize = Read16LE(f); + e_phentsize = Read16LE(f); + e_phnum = Read16LE(f); + e_shentsize = Read16LE(f); + e_shnum = Read16LE(f); + e_shstrndx = Read16LE(f); + } + else + { + e_abi_ver = Read64(f); + e_type = Read16(f); + e_machine = Read16(f); + e_version = Read32(f); + e_entry = Read32(f); + e_phoff = Read32(f); + e_shoff = Read32(f); + e_flags = Read32(f); + e_ehsize = Read16(f); + e_phentsize = Read16(f); + e_phnum = Read16(f); + e_shentsize = Read16(f); + e_shnum = Read16(f); + e_shstrndx = Read16(f); + } +} + +void Elf32_Desc::Load(vfsStream& f) +{ + revision = Read32(f); + ls_size = Read32(f); + stack_size = Read32(f); + flags = Read32(f); +} + +void Elf32_Desc::LoadLE(vfsStream& f) +{ + revision = Read32LE(f); + ls_size = Read32LE(f); + stack_size = Read32LE(f); + flags = Read32LE(f); +} + +void Elf32_Note::Load(vfsStream& f) +{ + namesz = Read32(f); + descsz = Read32(f); + type = Read32(f); + f.Read(name, 8); + + if (descsz == 32) + { + f.Read(desc_text, descsz); + } + else + { + desc.Load(f); + } +} + +void Elf32_Note::LoadLE(vfsStream& f) +{ + namesz = Read32LE(f); + descsz = Read32LE(f); + type = Read32LE(f); + f.Read(name, 8); + + if (descsz == 32) + { + f.Read(desc_text, descsz); + } + else + { + desc.Load(f); + } +} + +void Elf32_Shdr::Load(vfsStream& f) +{ + sh_name = Read32(f); + sh_type = Read32(f); + sh_flags = Read32(f); + sh_addr = Read32(f); + sh_offset = Read32(f); + sh_size = Read32(f); + sh_link = Read32(f); + sh_info = Read32(f); + sh_addralign = Read32(f); + sh_entsize = Read32(f); +} + +void Elf32_Shdr::LoadLE(vfsStream& f) +{ + sh_name = Read32LE(f); + sh_type = Read32LE(f); + sh_flags = Read32LE(f); + sh_addr = Read32LE(f); + sh_offset = Read32LE(f); + sh_size = Read32LE(f); + sh_link = Read32LE(f); + sh_info = Read32LE(f); + sh_addralign = Read32LE(f); + sh_entsize = Read32LE(f); +} + +void Elf32_Shdr::Show() +{ +#ifdef LOADER_DEBUG + LOG_NOTICE(LOADER, "Name offset: %x", sh_name); + LOG_NOTICE(LOADER, "Type: %d", sh_type); + LOG_NOTICE(LOADER, "Addr: %x", sh_addr); + LOG_NOTICE(LOADER, "Offset: %x", sh_offset); + LOG_NOTICE(LOADER, "Size: %x", sh_size); + LOG_NOTICE(LOADER, "EntSize: %d", sh_entsize); + LOG_NOTICE(LOADER, "Flags: %x", sh_flags); + LOG_NOTICE(LOADER, "Link: %x", sh_link); + LOG_NOTICE(LOADER, "Info: %d", sh_info); + LOG_NOTICE(LOADER, "Address align: %x", sh_addralign); +#endif +} + +void Elf32_Phdr::Load(vfsStream& f) +{ + p_type = Read32(f); + p_offset = Read32(f); + p_vaddr = Read32(f); + p_paddr = Read32(f); + p_filesz = Read32(f); + p_memsz = Read32(f); + p_flags = Read32(f); + p_align = Read32(f); +} + +void Elf32_Phdr::LoadLE(vfsStream& f) +{ + p_type = Read32LE(f); + p_offset = Read32LE(f); + p_vaddr = Read32LE(f); + p_paddr = Read32LE(f); + p_filesz = Read32LE(f); + p_memsz = Read32LE(f); + p_flags = Read32LE(f); + p_align = Read32LE(f); +} + +void Elf32_Phdr::Show() +{ +#ifdef LOADER_DEBUG + LOG_NOTICE(LOADER, "Type: %s", Phdr_TypeToString(p_type).c_str()); + LOG_NOTICE(LOADER, "Offset: 0x%08x", p_offset); + LOG_NOTICE(LOADER, "Virtual address: 0x%08x", p_vaddr); + LOG_NOTICE(LOADER, "Physical address: 0x%08x", p_paddr); + LOG_NOTICE(LOADER, "File size: 0x%08x", p_filesz); + LOG_NOTICE(LOADER, "Memory size: 0x%08x", p_memsz); + LOG_NOTICE(LOADER, "Flags: %s", Phdr_FlagsToString(p_flags).c_str()); + LOG_NOTICE(LOADER, "Align: 0x%x", p_align); +#endif +} + void WriteEhdr(rFile& f, Elf32_Ehdr& ehdr) { Write32(f, ehdr.e_magic); diff --git a/rpcs3/Loader/ELF32.h b/rpcs3/Loader/ELF32.h index 50b5c6bd66..6d600fd82c 100644 --- a/rpcs3/Loader/ELF32.h +++ b/rpcs3/Loader/ELF32.h @@ -23,79 +23,14 @@ struct Elf32_Ehdr u16 e_shnum; u16 e_shstrndx; - void Show() - { -#ifdef LOADER_DEBUG - LOG_NOTICE(LOADER, "Magic: %08x", e_magic); - LOG_NOTICE(LOADER, "Class: %s", "ELF32"); - LOG_NOTICE(LOADER, "Data: %s", Ehdr_DataToString(e_data).c_str()); - LOG_NOTICE(LOADER, "Current Version: %d", e_curver); - LOG_NOTICE(LOADER, "OS/ABI: %s", Ehdr_OS_ABIToString(e_os_abi).c_str()); - LOG_NOTICE(LOADER, "ABI version: %lld", e_abi_ver); - LOG_NOTICE(LOADER, "Type: %s", Ehdr_TypeToString(e_type).c_str()); - LOG_NOTICE(LOADER, "Machine: %s", Ehdr_MachineToString(e_machine).c_str()); - LOG_NOTICE(LOADER, "Version: %d", e_version); - LOG_NOTICE(LOADER, "Entry point address: 0x%x", e_entry); - LOG_NOTICE(LOADER, "Program headers offset: 0x%08x", e_phoff); - LOG_NOTICE(LOADER, "Section headers offset: 0x%08x", e_shoff); - LOG_NOTICE(LOADER, "Flags: 0x%x", e_flags); - LOG_NOTICE(LOADER, "Size of this header: %d", e_ehsize); - LOG_NOTICE(LOADER, "Size of program headers: %d", e_phentsize); - LOG_NOTICE(LOADER, "Number of program headers: %d", e_phnum); - LOG_NOTICE(LOADER, "Size of section headers: %d", e_shentsize); - LOG_NOTICE(LOADER, "Number of section headers: %d", e_shnum); - LOG_NOTICE(LOADER, "Section header string table index: %d", e_shstrndx); -#endif - } + void Show(); bool IsLittleEndian() const { return e_data == 1; } - void Load(vfsStream& f) - { - e_magic = Read32(f); - e_class = Read8(f); - e_data = Read8(f); - e_curver = Read8(f); - e_os_abi = Read8(f); - - if(IsLittleEndian()) - { - e_abi_ver = Read64LE(f); - e_type = Read16LE(f); - e_machine = Read16LE(f); - e_version = Read32LE(f); - e_entry = Read32LE(f); - e_phoff = Read32LE(f); - e_shoff = Read32LE(f); - e_flags = Read32LE(f); - e_ehsize = Read16LE(f); - e_phentsize = Read16LE(f); - e_phnum = Read16LE(f); - e_shentsize = Read16LE(f); - e_shnum = Read16LE(f); - e_shstrndx = Read16LE(f); - } - else - { - e_abi_ver = Read64(f); - e_type = Read16(f); - e_machine = Read16(f); - e_version = Read32(f); - e_entry = Read32(f); - e_phoff = Read32(f); - e_shoff = Read32(f); - e_flags = Read32(f); - e_ehsize = Read16(f); - e_phentsize = Read16(f); - e_phnum = Read16(f); - e_shentsize = Read16(f); - e_shnum = Read16(f); - e_shstrndx = Read16(f); - } - } + void Load(vfsStream& f); bool CheckMagic() const { return e_magic == 0x7F454C46; } u32 GetEntry() const { return e_entry; } @@ -108,21 +43,9 @@ struct Elf32_Desc u32 stack_size; u32 flags; - void Load(vfsStream& f) - { - revision = Read32(f); - ls_size = Read32(f); - stack_size = Read32(f); - flags = Read32(f); - } + void Load(vfsStream& f); - void LoadLE(vfsStream& f) - { - revision = Read32LE(f); - ls_size = Read32LE(f); - stack_size = Read32LE(f); - flags = Read32LE(f); - } + void LoadLE(vfsStream& f); }; struct Elf32_Note @@ -137,39 +60,9 @@ struct Elf32_Note char desc_text[32]; }; - void Load(vfsStream& f) - { - namesz = Read32(f); - descsz = Read32(f); - type = Read32(f); - f.Read(name, 8); + void Load(vfsStream& f); - if(descsz == 32) - { - f.Read(desc_text, descsz); - } - else - { - desc.Load(f); - } - } - - void LoadLE(vfsStream& f) - { - namesz = Read32LE(f); - descsz = Read32LE(f); - type = Read32LE(f); - f.Read(name, 8); - - if(descsz == 32) - { - f.Read(desc_text, descsz); - } - else - { - desc.Load(f); - } - } + void LoadLE(vfsStream& f); }; struct Elf32_Shdr @@ -185,49 +78,11 @@ struct Elf32_Shdr u32 sh_addralign; u32 sh_entsize; - void Load(vfsStream& f) - { - sh_name = Read32(f); - sh_type = Read32(f); - sh_flags = Read32(f); - sh_addr = Read32(f); - sh_offset = Read32(f); - sh_size = Read32(f); - sh_link = Read32(f); - sh_info = Read32(f); - sh_addralign = Read32(f); - sh_entsize = Read32(f); - } + void Load(vfsStream& f); - void LoadLE(vfsStream& f) - { - sh_name = Read32LE(f); - sh_type = Read32LE(f); - sh_flags = Read32LE(f); - sh_addr = Read32LE(f); - sh_offset = Read32LE(f); - sh_size = Read32LE(f); - sh_link = Read32LE(f); - sh_info = Read32LE(f); - sh_addralign = Read32LE(f); - sh_entsize = Read32LE(f); - } + void LoadLE(vfsStream& f); - void Show() - { -#ifdef LOADER_DEBUG - LOG_NOTICE(LOADER, "Name offset: %x", sh_name); - LOG_NOTICE(LOADER, "Type: %d", sh_type); - LOG_NOTICE(LOADER, "Addr: %x", sh_addr); - LOG_NOTICE(LOADER, "Offset: %x", sh_offset); - LOG_NOTICE(LOADER, "Size: %x", sh_size); - LOG_NOTICE(LOADER, "EntSize: %d", sh_entsize); - LOG_NOTICE(LOADER, "Flags: %x", sh_flags); - LOG_NOTICE(LOADER, "Link: %x", sh_link); - LOG_NOTICE(LOADER, "Info: %d", sh_info); - LOG_NOTICE(LOADER, "Address align: %x", sh_addralign); -#endif - } + void Show(); }; struct Elf32_Phdr @@ -241,43 +96,11 @@ struct Elf32_Phdr u32 p_flags; u32 p_align; - void Load(vfsStream& f) - { - p_type = Read32(f); - p_offset = Read32(f); - p_vaddr = Read32(f); - p_paddr = Read32(f); - p_filesz = Read32(f); - p_memsz = Read32(f); - p_flags = Read32(f); - p_align = Read32(f); - } + void Load(vfsStream& f); - void LoadLE(vfsStream& f) - { - p_type = Read32LE(f); - p_offset = Read32LE(f); - p_vaddr = Read32LE(f); - p_paddr = Read32LE(f); - p_filesz = Read32LE(f); - p_memsz = Read32LE(f); - p_flags = Read32LE(f); - p_align = Read32LE(f); - } + void LoadLE(vfsStream& f); - void Show() - { -#ifdef LOADER_DEBUG - LOG_NOTICE(LOADER, "Type: %s", Phdr_TypeToString(p_type).c_str()); - LOG_NOTICE(LOADER, "Offset: 0x%08x", p_offset); - LOG_NOTICE(LOADER, "Virtual address: 0x%08x", p_vaddr); - LOG_NOTICE(LOADER, "Physical address: 0x%08x", p_paddr); - LOG_NOTICE(LOADER, "File size: 0x%08x", p_filesz); - LOG_NOTICE(LOADER, "Memory size: 0x%08x", p_memsz); - LOG_NOTICE(LOADER, "Flags: %s", Phdr_FlagsToString(p_flags).c_str()); - LOG_NOTICE(LOADER, "Align: 0x%x", p_align); -#endif - } + void Show(); }; class ELF32Loader : public LoaderBase diff --git a/rpcs3/Loader/ELF64.cpp b/rpcs3/Loader/ELF64.cpp index 07693354a5..42c7a12042 100644 --- a/rpcs3/Loader/ELF64.cpp +++ b/rpcs3/Loader/ELF64.cpp @@ -2,9 +2,7 @@ #include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/SysCalls.h" -#include "Emu/SysCalls/Modules.h" #include "Emu/SysCalls/Static.h" #include "Emu/Cell/PPUInstrTable.h" #include "Emu/SysCalls/ModuleManager.h" @@ -12,6 +10,110 @@ using namespace PPU_instr; +void Elf64_Ehdr::Load(vfsStream& f) +{ + e_magic = Read32(f); + e_class = Read8(f); + e_data = Read8(f); + e_curver = Read8(f); + e_os_abi = Read8(f); + e_abi_ver = Read64(f); + e_type = Read16(f); + e_machine = Read16(f); + e_version = Read32(f); + e_entry = Read64(f); + e_phoff = Read64(f); + e_shoff = Read64(f); + e_flags = Read32(f); + e_ehsize = Read16(f); + e_phentsize = Read16(f); + e_phnum = Read16(f); + e_shentsize = Read16(f); + e_shnum = Read16(f); + e_shstrndx = Read16(f); +} + +void Elf64_Ehdr::Show() +{ +#ifdef LOADER_DEBUG + LOG_NOTICE(LOADER, "Magic: %08x", e_magic); + LOG_NOTICE(LOADER, "Class: %s", "ELF64"); + LOG_NOTICE(LOADER, "Data: %s", Ehdr_DataToString(e_data).c_str()); + LOG_NOTICE(LOADER, "Current Version: %d", e_curver); + LOG_NOTICE(LOADER, "OS/ABI: %s", Ehdr_OS_ABIToString(e_os_abi).c_str()); + LOG_NOTICE(LOADER, "ABI version: %lld", e_abi_ver); + LOG_NOTICE(LOADER, "Type: %s", Ehdr_TypeToString(e_type).c_str()); + LOG_NOTICE(LOADER, "Machine: %s", Ehdr_MachineToString(e_machine).c_str()); + LOG_NOTICE(LOADER, "Version: %d", e_version); + LOG_NOTICE(LOADER, "Entry point address: 0x%08llx", e_entry); + LOG_NOTICE(LOADER, "Program headers offset: 0x%08llx", e_phoff); + LOG_NOTICE(LOADER, "Section headers offset: 0x%08llx", e_shoff); + LOG_NOTICE(LOADER, "Flags: 0x%x", e_flags); + LOG_NOTICE(LOADER, "Size of this header: %d", e_ehsize); + LOG_NOTICE(LOADER, "Size of program headers: %d", e_phentsize); + LOG_NOTICE(LOADER, "Number of program headers: %d", e_phnum); + LOG_NOTICE(LOADER, "Size of section headers: %d", e_shentsize); + LOG_NOTICE(LOADER, "Number of section headers: %d", e_shnum); + LOG_NOTICE(LOADER, "Section header string table index: %d", e_shstrndx); +#endif +} + +void Elf64_Shdr::Load(vfsStream& f) +{ + sh_name = Read32(f); + sh_type = Read32(f); + sh_flags = Read64(f); + sh_addr = Read64(f); + sh_offset = Read64(f); + sh_size = Read64(f); + sh_link = Read32(f); + sh_info = Read32(f); + sh_addralign = Read64(f); + sh_entsize = Read64(f); +} + +void Elf64_Shdr::Show() +{ +#ifdef LOADER_DEBUG + LOG_NOTICE(LOADER, "Name offset: %x", sh_name); + LOG_NOTICE(LOADER, "Type: %d", sh_type); + LOG_NOTICE(LOADER, "Addr: %llx", sh_addr); + LOG_NOTICE(LOADER, "Offset: %llx", sh_offset); + LOG_NOTICE(LOADER, "Size: %llx", sh_size); + LOG_NOTICE(LOADER, "EntSize: %lld", sh_entsize); + LOG_NOTICE(LOADER, "Flags: %llx", sh_flags); + LOG_NOTICE(LOADER, "Link: %x", sh_link); + LOG_NOTICE(LOADER, "Info: %x", sh_info); + LOG_NOTICE(LOADER, "Address align: %llx", sh_addralign); +#endif +} + +void Elf64_Phdr::Load(vfsStream& f) +{ + p_type = Read32(f); + p_flags = Read32(f); + p_offset = Read64(f); + p_vaddr = Read64(f); + p_paddr = Read64(f); + p_filesz = Read64(f); + p_memsz = Read64(f); + p_align = Read64(f); +} + +void Elf64_Phdr::Show() +{ +#ifdef LOADER_DEBUG + LOG_NOTICE(LOADER, "Type: %s", Phdr_TypeToString(p_type).c_str()); + LOG_NOTICE(LOADER, "Offset: 0x%08llx", p_offset); + LOG_NOTICE(LOADER, "Virtual address: 0x%08llx", p_vaddr); + LOG_NOTICE(LOADER, "Physical address: 0x%08llx", p_paddr); + LOG_NOTICE(LOADER, "File size: 0x%08llx", p_filesz); + LOG_NOTICE(LOADER, "Memory size: 0x%08llx", p_memsz); + LOG_NOTICE(LOADER, "Flags: %s", Phdr_FlagsToString(p_flags).c_str()); + LOG_NOTICE(LOADER, "Align: 0x%llx", p_align); +#endif +} + void WriteEhdr(rFile& f, Elf64_Ehdr& ehdr) { Write32(f, ehdr.e_magic); diff --git a/rpcs3/Loader/ELF64.h b/rpcs3/Loader/ELF64.h index f6f6792922..162d153fb7 100644 --- a/rpcs3/Loader/ELF64.h +++ b/rpcs3/Loader/ELF64.h @@ -23,53 +23,9 @@ struct Elf64_Ehdr u16 e_shnum; u16 e_shstrndx; - void Load(vfsStream& f) - { - e_magic = Read32(f); - e_class = Read8(f); - e_data = Read8(f); - e_curver = Read8(f); - e_os_abi = Read8(f); - e_abi_ver = Read64(f); - e_type = Read16(f); - e_machine = Read16(f); - e_version = Read32(f); - e_entry = Read64(f); - e_phoff = Read64(f); - e_shoff = Read64(f); - e_flags = Read32(f); - e_ehsize = Read16(f); - e_phentsize = Read16(f); - e_phnum = Read16(f); - e_shentsize = Read16(f); - e_shnum = Read16(f); - e_shstrndx = Read16(f); - } + void Load(vfsStream& f); - void Show() - { -#ifdef LOADER_DEBUG - LOG_NOTICE(LOADER, "Magic: %08x", e_magic); - LOG_NOTICE(LOADER, "Class: %s", "ELF64"); - LOG_NOTICE(LOADER, "Data: %s", Ehdr_DataToString(e_data).c_str()); - LOG_NOTICE(LOADER, "Current Version: %d", e_curver); - LOG_NOTICE(LOADER, "OS/ABI: %s", Ehdr_OS_ABIToString(e_os_abi).c_str()); - LOG_NOTICE(LOADER, "ABI version: %lld", e_abi_ver); - LOG_NOTICE(LOADER, "Type: %s", Ehdr_TypeToString(e_type).c_str()); - LOG_NOTICE(LOADER, "Machine: %s", Ehdr_MachineToString(e_machine).c_str()); - LOG_NOTICE(LOADER, "Version: %d", e_version); - LOG_NOTICE(LOADER, "Entry point address: 0x%08llx", e_entry); - LOG_NOTICE(LOADER, "Program headers offset: 0x%08llx", e_phoff); - LOG_NOTICE(LOADER, "Section headers offset: 0x%08llx", e_shoff); - LOG_NOTICE(LOADER, "Flags: 0x%x", e_flags); - LOG_NOTICE(LOADER, "Size of this header: %d", e_ehsize); - LOG_NOTICE(LOADER, "Size of program headers: %d", e_phentsize); - LOG_NOTICE(LOADER, "Number of program headers: %d", e_phnum); - LOG_NOTICE(LOADER, "Size of section headers: %d", e_shentsize); - LOG_NOTICE(LOADER, "Number of section headers: %d", e_shnum); - LOG_NOTICE(LOADER, "Section header string table index: %d", e_shstrndx); -#endif - } + void Show(); bool CheckMagic() const { return e_magic == 0x7F454C46; } u32 GetEntry() const { return e_entry; } @@ -88,35 +44,9 @@ struct Elf64_Shdr u64 sh_addralign; u64 sh_entsize; - void Load(vfsStream& f) - { - sh_name = Read32(f); - sh_type = Read32(f); - sh_flags = Read64(f); - sh_addr = Read64(f); - sh_offset = Read64(f); - sh_size = Read64(f); - sh_link = Read32(f); - sh_info = Read32(f); - sh_addralign = Read64(f); - sh_entsize = Read64(f); - } + void Load(vfsStream& f); - void Show() - { -#ifdef LOADER_DEBUG - LOG_NOTICE(LOADER, "Name offset: %x", sh_name); - LOG_NOTICE(LOADER, "Type: %d", sh_type); - LOG_NOTICE(LOADER, "Addr: %llx", sh_addr); - LOG_NOTICE(LOADER, "Offset: %llx", sh_offset); - LOG_NOTICE(LOADER, "Size: %llx", sh_size); - LOG_NOTICE(LOADER, "EntSize: %lld", sh_entsize); - LOG_NOTICE(LOADER, "Flags: %llx", sh_flags); - LOG_NOTICE(LOADER, "Link: %x", sh_link); - LOG_NOTICE(LOADER, "Info: %x", sh_info); - LOG_NOTICE(LOADER, "Address align: %llx", sh_addralign); -#endif - } + void Show(); }; struct Elf64_Phdr @@ -130,31 +60,9 @@ struct Elf64_Phdr u64 p_memsz; u64 p_align; - void Load(vfsStream& f) - { - p_type = Read32(f); - p_flags = Read32(f); - p_offset = Read64(f); - p_vaddr = Read64(f); - p_paddr = Read64(f); - p_filesz = Read64(f); - p_memsz = Read64(f); - p_align = Read64(f); - } + void Load(vfsStream& f); - void Show() - { -#ifdef LOADER_DEBUG - LOG_NOTICE(LOADER, "Type: %s", Phdr_TypeToString(p_type).c_str()); - LOG_NOTICE(LOADER, "Offset: 0x%08llx", p_offset); - LOG_NOTICE(LOADER, "Virtual address: 0x%08llx", p_vaddr); - LOG_NOTICE(LOADER, "Physical address: 0x%08llx", p_paddr); - LOG_NOTICE(LOADER, "File size: 0x%08llx", p_filesz); - LOG_NOTICE(LOADER, "Memory size: 0x%08llx", p_memsz); - LOG_NOTICE(LOADER, "Flags: %s", Phdr_FlagsToString(p_flags).c_str()); - LOG_NOTICE(LOADER, "Align: 0x%llx", p_align); -#endif - } + void Show(); }; class ELF64Loader : public LoaderBase diff --git a/rpcs3/Loader/TROPUSR.cpp b/rpcs3/Loader/TROPUSR.cpp index b19f0016d7..35e3b7bda0 100644 --- a/rpcs3/Loader/TROPUSR.cpp +++ b/rpcs3/Loader/TROPUSR.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "Utilities/Log.h" #include "Utilities/rXml.h" -#include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "TROPUSR.h" @@ -212,7 +211,8 @@ bool TROPUSRLoader::Close() { if (m_file && m_file->Close()) { - safe_delete(m_file); + delete m_file; + m_file = nullptr; return true; } return false; diff --git a/rpcs3/Loader/TRP.cpp b/rpcs3/Loader/TRP.cpp index 87427a4326..2127e4acf6 100644 --- a/rpcs3/Loader/TRP.cpp +++ b/rpcs3/Loader/TRP.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" #include "Utilities/Log.h" -#include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/FS/vfsFile.h" #include "TRP.h" diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 142f07ce89..3ed057f908 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -355,6 +355,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 7f758f7a2b..b4afa1ee91 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1162,5 +1162,8 @@ Emu + + Emu\SysCalls\Modules + \ No newline at end of file