diff --git a/src/lua/extra.cc b/src/lua/extra.cc index 480168186..3d959f635 100644 --- a/src/lua/extra.cc +++ b/src/lua/extra.cc @@ -26,9 +26,9 @@ #include "lua-protobuf/pb.h" #include "lua/luafile.h" #include "lua/luawrapper.h" +#include "support/djbhash.h" #include "support/file.h" #include "support/strings-helpers.h" -#include "support/djbhash.h" #include "support/zip.h" namespace { @@ -82,9 +82,7 @@ PCSX::File* load(std::string_view name, std::string_view from, bool inArchives = return new PCSX::PosixFile(absolutePath); } -uint64_t djbHash(const char* str, size_t len) { - return PCSX::djb::hash(str, len); -} +uint64_t djbHash(const char* str, size_t len) { return PCSX::djb::hash(str, len); } template void registerSymbol(PCSX::Lua L, const char (&name)[S], const T ptr) { diff --git a/src/lua/extra.lua b/src/lua/extra.lua index 738e920d6..e805b602a 100644 --- a/src/lua/extra.lua +++ b/src/lua/extra.lua @@ -15,7 +15,6 @@ -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - ffi.cdef [[ uint64_t djbHash(const char* str, size_t len); ]] @@ -40,8 +39,6 @@ Support.extra = { error('FFI call failed in ' .. name .. ': ' .. ret) end, - djbHash = function(str) - return C.djbHash(str, #str) - end, + djbHash = function(str) return C.djbHash(str, #str) end, } -- )EOF" diff --git a/src/lua/fileffi.lua b/src/lua/fileffi.lua index b3cc015ec..8bcf2da1c 100644 --- a/src/lua/fileffi.lua +++ b/src/lua/fileffi.lua @@ -20,7 +20,7 @@ local C = ffi.load 'SUPPORT_FILE' local function validateBuffer(buffer) if buffer:maxsize() < buffer.size then error('Invalid or corrupted LuaBuffer: claims size of ' .. buffer.size .. ' but actual size is ' .. - buffer:maxsize()) + buffer:maxsize()) end return buffer end @@ -34,19 +34,19 @@ local function read(self, ptr, size) return validateBuffer(buf) elseif type(ptr) == 'cdata' and size == nil and ffi.typeof(ptr) == Support.File._LuaBuffer then return Support.extra.safeFFI('File::read(C.readFileBuffer)', C.readFileBuffer, self._wrapper, - validateBuffer(ptr)) + validateBuffer(ptr)) elseif type(ptr) == 'userdata' and size == nil then return Support._internal.readFileUserData(self._wrapper, ptr) elseif type(ptr) == 'table' and ptr._type == 'Slice' then return Support.extra.safeFFI('File::read(C.readFileToExistingSlice)', C.readFileToExistingSlice, self._wrapper, - ptr._wrapper, size or ptr:size()) + ptr._wrapper, size or ptr:size()) end return Support.extra.safeFFI('File::read(C.readFileRawPtr)', C.readFileRawPtr, self._wrapper, ptr, size) end local function readToSlice(self, size) return Support.File._createSliceWrapper(Support.extra.safeFFI('File::read(C.readFileToSlice)', C.readFileToSlice, - self._wrapper, size)) + self._wrapper, size)) end local function readAt(self, ptr, size, pos) @@ -59,25 +59,25 @@ local function readAt(self, ptr, size, pos) return validateBuffer(buf) elseif type(ptr) == 'cdata' and type(size) == 'number' and pos == nil and ffi.typeof(ptr) == LuaBuffer then return Support.extra.safeFFI('File::readAt(C.readFileAtBuffer)', C.readFileAtBuffer, self._wrapper, - validateBuffer(ptr), size) + validateBuffer(ptr), size) elseif type(ptr) == 'userdata' and type(size) == 'number' and pos == nil then return Support._internal.readFileAtUserData(self._wrapper, ptr, size) elseif type(ptr) == 'table' and ptr._type == 'Slice' then return Support.extra.safeFFI('File::readAt(C.readFileAtToExistingSlice)', C.readFileAtToExistingSlice, - self._wrapper, ptr._wrapper, size or ptr:size(), pos) + self._wrapper, ptr._wrapper, size or ptr:size(), pos) end return Support.extra.safeFFI('File::readAt(C.readFileAtRawPtr)', C.readFileAtRawPtr, self._wrapper, ptr, size, pos) end local function readAtToSlice(self, size, pos) return Support.File._createSliceWrapper(Support.extra.safeFFI('File::readAt(C.readFileAtToSlice)', - C.readFileAtToSlice, self._wrapper, size, pos)) + C.readFileAtToSlice, self._wrapper, size, pos)) end local function write(self, data, size) if type(data) == 'cdata' and size == nil and ffi.typeof(data) == LuaBuffer then return Support.extra.safeFFI('File::write(C.writeFileBuffer)', C.writeFileBuffer, self._wrapper, - validateBuffer(data)) + validateBuffer(data)) elseif type(data) == 'userdata' and size == nil then return Support._internal.writeFileUserData(self._wrapper, data) elseif type(size) == 'number' then @@ -85,22 +85,22 @@ local function write(self, data, size) end if type(data) ~= 'string' then data = tostring(data) end return Support.extra.safeFFI('File::write(C.writeFileRawPtr)', C.writeFileRawPtr, self._wrapper, data, - string.len(data)) + string.len(data)) end local function writeAt(self, data, size, pos) if type(data) == 'cdata' and type(size) == 'number' and pos == nil and ffi.typeof(data) == LuaBuffer then return Support.extra.safeFFI('File::writeAt(C.writeFileAtBuffer)', C.writeFileAtBuffer, self._wrapper, - validateBuffer(data), size) + validateBuffer(data), size) elseif type(data) == 'userdata' and type(size) == 'number' and pos == nil then return Support._internal.writeFileAtUserData(self._wrapper, data, size) elseif type(size) == 'number' and type(pos) == 'number' then return Support.extra.safeFFI('File::writeAt(C.writeFileAtRawPtr)', C.writeFileAtRawPtr, self._wrapper, data, - size, pos) + size, pos) end if type(data) ~= 'string' then data = tostring(data) end return Support.extra.safeFFI('File::writeAt(C.writeFileAtRawPtr)', C.writeFileAtRawPtr, self._wrapper, data, - string.len(data), size) + string.len(data), size) end local function writeMoveSlice(self, slice) C.writeFileMoveSlice(self._wrapper, slice._wrapper) end @@ -319,10 +319,10 @@ end local function ffmpegAudioFile(file, options) if type(options) ~= 'table' then options = {} end local channels, endianness, sampleFormat, frequency = options.channels, options.endianness, options.sampleFormat, - options.frequency + options.frequency return createFileWrapper(Support.extra.safeFFI('Support.File.ffmpegAudioFile', C.ffmpegAudioFile, file._wrapper, - channels or 'Stereo', endianness or 'Little', sampleFormat or 'S16', - frequency or 44100)) + channels or 'Stereo', endianness or 'Little', sampleFormat or 'S16', + frequency or 44100)) end if (type(Support) ~= 'table') then Support = {} end diff --git a/src/lua/fileffimeta.lua b/src/lua/fileffimeta.lua index b54670d6e..9c428ceb6 100644 --- a/src/lua/fileffimeta.lua +++ b/src/lua/fileffimeta.lua @@ -32,9 +32,7 @@ local sliceMeta = { elseif index == 'size' then return tonumber(C.getSliceSize(slice._wrapper)) elseif index == 'resize' then - return function(slice, size) - C.resizeSlice(slice._wrapper, size) - end + return function(slice, size) C.resizeSlice(slice._wrapper, size) end end error('Unknown index `' .. index .. '` for LuaSlice') end, diff --git a/src/mips/common/hardware/sio.h b/src/mips/common/hardware/sio.h index 1c2bdb8cb..e765ffeb7 100644 --- a/src/mips/common/hardware/sio.h +++ b/src/mips/common/hardware/sio.h @@ -27,6 +27,7 @@ SOFTWARE. #pragma once #include + #include "common/hardware/irq.h" struct SIOPort { diff --git a/src/mips/common/psxlibc/fastmemset.s b/src/mips/common/psxlibc/fastmemset.s index 9dc771cee..38fb9ed03 100644 --- a/src/mips/common/psxlibc/fastmemset.s +++ b/src/mips/common/psxlibc/fastmemset.s @@ -44,7 +44,7 @@ fastMemset: addu $a2, $a0 addiu $a2, -1 small_memset_loop: - sb $a1, 0($a0) + sb $a1, 0($a0) bne $a0, $a2, small_memset_loop addiu $a0, 1 jr $ra @@ -95,70 +95,70 @@ t1 - the remainder counter to store big_loop: addiu $t0, -1 - sw $a1, 0x0000($a0) - sw $a1, 0x0004($a0) - sw $a1, 0x0008($a0) - sw $a1, 0x000c($a0) - sw $a1, 0x0010($a0) - sw $a1, 0x0014($a0) - sw $a1, 0x0018($a0) - sw $a1, 0x001c($a0) - sw $a1, 0x0020($a0) - sw $a1, 0x0024($a0) - sw $a1, 0x0028($a0) - sw $a1, 0x002c($a0) - sw $a1, 0x0030($a0) - sw $a1, 0x0034($a0) - sw $a1, 0x0038($a0) - sw $a1, 0x003c($a0) - sw $a1, 0x0040($a0) - sw $a1, 0x0044($a0) - sw $a1, 0x0048($a0) - sw $a1, 0x004c($a0) - sw $a1, 0x0050($a0) - sw $a1, 0x0054($a0) - sw $a1, 0x0058($a0) - sw $a1, 0x005c($a0) - sw $a1, 0x0060($a0) - sw $a1, 0x0064($a0) - sw $a1, 0x0068($a0) - sw $a1, 0x006c($a0) - sw $a1, 0x0070($a0) - sw $a1, 0x0074($a0) - sw $a1, 0x0078($a0) - sw $a1, 0x007c($a0) - sw $a1, 0x0080($a0) - sw $a1, 0x0084($a0) - sw $a1, 0x0088($a0) - sw $a1, 0x008c($a0) - sw $a1, 0x0090($a0) - sw $a1, 0x0094($a0) - sw $a1, 0x0098($a0) - sw $a1, 0x009c($a0) - sw $a1, 0x00a0($a0) - sw $a1, 0x00a4($a0) - sw $a1, 0x00a8($a0) - sw $a1, 0x00ac($a0) - sw $a1, 0x00b0($a0) - sw $a1, 0x00b4($a0) - sw $a1, 0x00b8($a0) - sw $a1, 0x00bc($a0) - sw $a1, 0x00c0($a0) - sw $a1, 0x00c4($a0) - sw $a1, 0x00c8($a0) - sw $a1, 0x00cc($a0) - sw $a1, 0x00d0($a0) - sw $a1, 0x00d4($a0) - sw $a1, 0x00d8($a0) - sw $a1, 0x00dc($a0) - sw $a1, 0x00e0($a0) - sw $a1, 0x00e4($a0) - sw $a1, 0x00e8($a0) - sw $a1, 0x00ec($a0) - sw $a1, 0x00f0($a0) - sw $a1, 0x00f4($a0) - sw $a1, 0x00f8($a0) - sw $a1, 0x00fc($a0) + sw $a1, 0x0000($a0) + sw $a1, 0x0004($a0) + sw $a1, 0x0008($a0) + sw $a1, 0x000c($a0) + sw $a1, 0x0010($a0) + sw $a1, 0x0014($a0) + sw $a1, 0x0018($a0) + sw $a1, 0x001c($a0) + sw $a1, 0x0020($a0) + sw $a1, 0x0024($a0) + sw $a1, 0x0028($a0) + sw $a1, 0x002c($a0) + sw $a1, 0x0030($a0) + sw $a1, 0x0034($a0) + sw $a1, 0x0038($a0) + sw $a1, 0x003c($a0) + sw $a1, 0x0040($a0) + sw $a1, 0x0044($a0) + sw $a1, 0x0048($a0) + sw $a1, 0x004c($a0) + sw $a1, 0x0050($a0) + sw $a1, 0x0054($a0) + sw $a1, 0x0058($a0) + sw $a1, 0x005c($a0) + sw $a1, 0x0060($a0) + sw $a1, 0x0064($a0) + sw $a1, 0x0068($a0) + sw $a1, 0x006c($a0) + sw $a1, 0x0070($a0) + sw $a1, 0x0074($a0) + sw $a1, 0x0078($a0) + sw $a1, 0x007c($a0) + sw $a1, 0x0080($a0) + sw $a1, 0x0084($a0) + sw $a1, 0x0088($a0) + sw $a1, 0x008c($a0) + sw $a1, 0x0090($a0) + sw $a1, 0x0094($a0) + sw $a1, 0x0098($a0) + sw $a1, 0x009c($a0) + sw $a1, 0x00a0($a0) + sw $a1, 0x00a4($a0) + sw $a1, 0x00a8($a0) + sw $a1, 0x00ac($a0) + sw $a1, 0x00b0($a0) + sw $a1, 0x00b4($a0) + sw $a1, 0x00b8($a0) + sw $a1, 0x00bc($a0) + sw $a1, 0x00c0($a0) + sw $a1, 0x00c4($a0) + sw $a1, 0x00c8($a0) + sw $a1, 0x00cc($a0) + sw $a1, 0x00d0($a0) + sw $a1, 0x00d4($a0) + sw $a1, 0x00d8($a0) + sw $a1, 0x00dc($a0) + sw $a1, 0x00e0($a0) + sw $a1, 0x00e4($a0) + sw $a1, 0x00e8($a0) + sw $a1, 0x00ec($a0) + sw $a1, 0x00f0($a0) + sw $a1, 0x00f4($a0) + sw $a1, 0x00f8($a0) + sw $a1, 0x00fc($a0) bnez $t0, big_loop addiu $a0, 0x0100 diff --git a/src/mips/openbios/sio0/card.c b/src/mips/openbios/sio0/card.c index 70f664e6a..8207cfa36 100644 --- a/src/mips/openbios/sio0/card.c +++ b/src/mips/openbios/sio0/card.c @@ -97,8 +97,7 @@ int __attribute__((section(".ramtext"))) mcReadHandler() { switch (g_mcOperation) { case 1: g_sio0Mask = port == 0 ? 0x0000 : SIO_CTRL_PORTSEL; - SIOS[0].ctrl = g_sio0Mask | SIO_CTRL_TXEN | SIO_CTRL_ACKIRQEN - | SIO_CTRL_DTR; + SIOS[0].ctrl = g_sio0Mask | SIO_CTRL_TXEN | SIO_CTRL_ACKIRQEN | SIO_CTRL_DTR; exchangeByte((g_mcDeviceId[port] & 0x0f) + 0x81); g_mcActionInProgress = 1; break; @@ -176,8 +175,7 @@ int __attribute__((section(".ramtext"))) mcWriteHandler() { switch (g_mcOperation) { case 1: g_sio0Mask = port == 0 ? 0x0000 : SIO_CTRL_PORTSEL; - SIOS[0].ctrl = g_sio0Mask | SIO_CTRL_TXEN | SIO_CTRL_ACKIRQEN - | SIO_CTRL_DTR; + SIOS[0].ctrl = g_sio0Mask | SIO_CTRL_TXEN | SIO_CTRL_ACKIRQEN | SIO_CTRL_DTR; exchangeByte((g_mcDeviceId[port] & 0x0f) + 0x81); g_mcActionInProgress = 1; break; @@ -249,8 +247,7 @@ int __attribute__((section(".ramtext"))) mcInfoHandler() { switch (g_mcOperation) { case 1: g_sio0Mask = port == 0 ? 0x0000 : SIO_CTRL_PORTSEL; - SIOS[0].ctrl = g_sio0Mask | SIO_CTRL_TXEN | SIO_CTRL_ACKIRQEN - | SIO_CTRL_DTR; + SIOS[0].ctrl = g_sio0Mask | SIO_CTRL_TXEN | SIO_CTRL_ACKIRQEN | SIO_CTRL_DTR; exchangeByte((g_mcDeviceId[port] & 0x0f) + 0x81); g_mcActionInProgress = 1; break; diff --git a/src/mips/openbios/sio0/driver.c b/src/mips/openbios/sio0/driver.c index b846e440f..c35e33b7a 100644 --- a/src/mips/openbios/sio0/driver.c +++ b/src/mips/openbios/sio0/driver.c @@ -318,7 +318,7 @@ static void __attribute__((section(".ramtext"))) firstStageCardAction() { sysDeqIntRP(1, &g_mcHandlerInfo); SIOS[0].ctrl = SIO_CTRL_IR; SIOS[0].baudRate = 2073600 / 15200; - SIOS[0].mode = 13; // MUL1, 8bit, no parity, normal polarity + SIOS[0].mode = 13; // MUL1, 8bit, no parity, normal polarity SIOS[0].ctrl = 0; return; } diff --git a/src/mips/psyqo-paths/archive-manager.hh b/src/mips/psyqo-paths/archive-manager.hh index d0382527e..fff9a21cc 100644 --- a/src/mips/psyqo-paths/archive-manager.hh +++ b/src/mips/psyqo-paths/archive-manager.hh @@ -382,7 +382,8 @@ class ArchiveManager { uint32_t indexSize = (getIndexCount() + 1) * sizeof(IndexEntry); return (indexSize + 2047) / 2048; } - static eastl::array s_decompressors; + static eastl::array + s_decompressors; void decompressUCL_NRV2E(const IndexEntry *entry); void decompressLZ4(const IndexEntry *entry); }; diff --git a/src/mips/psyqo-paths/cdrom-loader.hh b/src/mips/psyqo-paths/cdrom-loader.hh index 4862f6e52..f1ce70c19 100644 --- a/src/mips/psyqo-paths/cdrom-loader.hh +++ b/src/mips/psyqo-paths/cdrom-loader.hh @@ -106,9 +106,7 @@ class CDRomLoader { setupQueue(path, parser, {}); return m_queue.schedule(); } - ReadFileAwaiter readFile(eastl::string_view path, ISO9660Parser &parser) { - return {path, parser, *this}; - } + ReadFileAwaiter readFile(eastl::string_view path, ISO9660Parser &parser) { return {path, parser, *this}; } private: void setupQueue(eastl::string_view path, ISO9660Parser &parser, diff --git a/src/mips/psyqo-paths/examples/cdrom-loader/cdrom-loader.cpp b/src/mips/psyqo-paths/examples/cdrom-loader/cdrom-loader.cpp index 64cdab179..7e945fb3b 100644 --- a/src/mips/psyqo-paths/examples/cdrom-loader/cdrom-loader.cpp +++ b/src/mips/psyqo-paths/examples/cdrom-loader/cdrom-loader.cpp @@ -70,11 +70,10 @@ void CDRomLoaderExample::prepare() { void CDRomLoaderExample::createScene() { m_font.uploadSystemFont(gpu()); pushScene(&cdromLoaderExampleScene); - m_cdromLoader.readFile("SYSTEM.CNF;1", cdromLoaderExample.m_isoParser, - [this](psyqo::Buffer&& buffer) { - m_buffer = eastl::move(buffer); - m_callbackCalled = true; - }); + m_cdromLoader.readFile("SYSTEM.CNF;1", cdromLoaderExample.m_isoParser, [this](psyqo::Buffer&& buffer) { + m_buffer = eastl::move(buffer); + m_callbackCalled = true; + }); } void CDRomLoaderExampleScene::frame() { diff --git a/src/mips/psyqo-paths/tools/mkarchive.lua b/src/mips/psyqo-paths/tools/mkarchive.lua index 63ed8599b..6d6699524 100644 --- a/src/mips/psyqo-paths/tools/mkarchive.lua +++ b/src/mips/psyqo-paths/tools/mkarchive.lua @@ -19,7 +19,6 @@ -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. - --[[ This script creates a PSX archive file from a JSON index file. The JSON file needs @@ -199,77 +198,58 @@ The archive manager may simply be given a hardcoded LBA for the beginning of the archive, and the authoring software would always write the archive at that location, while reserving space inside the archive for the iso9660 filesystem. -]]-- - +]] -- -- Taken and adapted from https://gist.github.com/hmenke/4536dda27095634b4563a1a9d854a040 -local bit = require 'bit' -local ffi = require 'ffi' -local lpeg = require 'lpeg' -local C = lpeg.C -local Cf = lpeg.Cf -local Cg = lpeg.Cg -local Ct = lpeg.Ct -local P = lpeg.P -local R = lpeg.R -local S = lpeg.S -local V = lpeg.V +local bit = require 'bit' +local ffi = require 'ffi' +local lpeg = require 'lpeg' +local C = lpeg.C +local Cf = lpeg.Cf +local Cg = lpeg.Cg +local Ct = lpeg.Ct +local P = lpeg.P +local R = lpeg.R +local S = lpeg.S +local V = lpeg.V -- number parsing -local digit = R '09' -local dot = P '.' -local eE = S 'eE' -local sign = S '+-' ^ -1 +local digit = R '09' +local dot = P '.' +local eE = S 'eE' +local sign = S '+-' ^ -1 local mantissa = digit ^ 1 * dot * digit ^ 0 + dot * digit ^ 1 + digit ^ 1 local exponent = (eE * sign * digit ^ 1) ^ -1 -local real = sign * mantissa * exponent / tonumber +local real = sign * mantissa * exponent / tonumber -- optional whitespace -local ws = S ' \t\n\r' ^ 0 +local ws = S ' \t\n\r' ^ 0 -- match a literal string surrounded by whitespace -local lit = function(str) - return ws * P(str) * ws -end +local lit = function(str) return ws * P(str) * ws end -- match a literal string and synthesize an attribute -local attr = function(str, attr) - return ws * P(str) / function() return attr end * ws -end +local attr = function(str, attr) return ws * P(str) / function() return attr end * ws end -- JSON grammar -local json = P { +local json = P { 'value', - value = - V 'null_value' + - V 'bool_value' + - V 'string_value' + - V 'real_value' + - V 'array' + - V 'object', + value = V 'null_value' + V 'bool_value' + V 'string_value' + V 'real_value' + V 'array' + V 'object', - null_value = attr('null', nil), - bool_value = attr('true', true) + attr('false', false), + null_value = attr('null', nil), + bool_value = attr('true', true) + attr('false', false), string_value = ws * P '"' * C((P '\\"' + 1 - P '"') ^ 0) * P '"' * ws, - real_value = ws * real * ws, - array = lit '[' * Ct((V 'value' * lit ',' ^ -1) ^ 0) * lit ']', - member_pair = Cg(V 'string_value' * lit ':' * V 'value') * lit ',' ^ -1, - object = lit '{' * Cf(Ct '' * V 'member_pair' ^ 0, rawset) * lit '}' + real_value = ws * real * ws, + array = lit '[' * Ct((V 'value' * lit ',' ^ -1) ^ 0) * lit ']', + member_pair = Cg(V 'string_value' * lit ':' * V 'value') * lit ',' ^ -1, + object = lit '{' * Cf(Ct '' * V 'member_pair' ^ 0, rawset) * lit '}', } function mkarchive(index, out) - if type(index) == 'string' then - index = Support.File.open(index) - end - if type(index) == 'table' and index._type == 'File' then - index = tostring(index:read(index:size())) - end - if type(index) == 'string' then - index = json:match(index) - end - if type(index) ~= 'table' then - error('mkarchive: invalid index type') - end + if type(index) == 'string' then index = Support.File.open(index) end + if type(index) == 'table' and index._type == 'File' then index = tostring(index:read(index:size())) end + if type(index) == 'string' then index = json:match(index) end + if type(index) ~= 'table' then error('mkarchive: invalid index type') end index = index.files or {} local needsToClose = false @@ -280,12 +260,8 @@ function mkarchive(index, out) end for k, v in ipairs(index) do - if type(v) ~= 'table' then - error('mkarchive: invalid index entry type') - end - if not v.path then - error('mkarchive: missing file path in index entry') - end + if type(v) ~= 'table' then error('mkarchive: invalid index entry type') end + if not v.path then error('mkarchive: missing file path in index entry') end index[k].hash = v.hash or Support.extra.djbHash(v.path) end @@ -314,9 +290,7 @@ function mkarchive(index, out) compressedSize = index[k].decompressedSize local padding = compressedSize % 2048 out:writeMoveSlice(srcData) - if padding > 0 then - out:write(zeroBuffer, 2048 - padding) - end + if padding > 0 then out:write(zeroBuffer, 2048 - padding) end index[k].compressionMethod = 0 index[k].padding = 0 else @@ -344,9 +318,7 @@ function mkarchive(index, out) out:writeU32(fileCount) out:writeU32(totalSize) - table.sort(index, function(a, b) - return a.hash < b.hash - end) + table.sort(index, function(a, b) return a.hash < b.hash end) for _, v in ipairs(index) do out:writeU32(bit.band(v.hash, 0xffffffff)) @@ -362,22 +334,13 @@ function mkarchive(index, out) local offset = bit.band(v.offset, 0x7ffff) local compressedSize = bit.band(v.compressedSize, 0x3ff) local compressionMethod = bit.band(v.compressionMethod, 0x7) - local low = bit.bor( - bit.lshift(decompressedSize, 0), - bit.lshift(padding, 21) - ) - local high = bit.bor( - bit.lshift(offset, 0), - bit.lshift(compressedSize, 19), - bit.lshift(compressionMethod, 29) - ) + local low = bit.bor(bit.lshift(decompressedSize, 0), bit.lshift(padding, 21)) + local high = bit.bor(bit.lshift(offset, 0), bit.lshift(compressedSize, 19), bit.lshift(compressionMethod, 29)) out:writeU32(low) out:writeU32(high) end - if needsToClose then - out:close() - end + if needsToClose then out:close() end print('Packed', fileCount, 'files into', tonumber(totalSize), 'sectors, with', indexSectors, 'sectors of index data') pprint(index) diff --git a/src/mips/psyqo/cdrom-commandbuffer.hh b/src/mips/psyqo/cdrom-commandbuffer.hh index bbe471cd9..6ef155d59 100644 --- a/src/mips/psyqo/cdrom-commandbuffer.hh +++ b/src/mips/psyqo/cdrom-commandbuffer.hh @@ -55,4 +55,4 @@ struct CDRomCommandBuffer { recursiveSet(pos + 1, args...); } }; -} // namespace psyqo::Hardware::CDRom \ No newline at end of file +} // namespace psyqo::Hardware::CDRom \ No newline at end of file diff --git a/src/mips/psyqo/examples/pcsxlua/pcsxlua.lua b/src/mips/psyqo/examples/pcsxlua/pcsxlua.lua index 95ab846ce..de4ef4b0e 100644 --- a/src/mips/psyqo/examples/pcsxlua/pcsxlua.lua +++ b/src/mips/psyqo/examples/pcsxlua/pcsxlua.lua @@ -19,7 +19,6 @@ -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. - -- This is the companion Lua script for the PCSX-Redux Lua editor demo. -- See pcsxlua.cpp for the C++ side of the demo. local addresses = {} diff --git a/src/mips/ucl-demo/n2e-d.S b/src/mips/ucl-demo/n2e-d.S index dba8d5d85..7cc4a3428 100644 --- a/src/mips/ucl-demo/n2e-d.S +++ b/src/mips/ucl-demo/n2e-d.S @@ -50,111 +50,111 @@ n2e_decompress: // t9 = saved_ra - move saved_ra, $ra + move saved_ra, $ra - move bb, $0 - li last_m_off, 1 - lui ff0000, 0xff + move bb, $0 + li last_m_off, 1 + lui ff0000, 0xff -main_loop: // for (;;) +main_loop: // for (;;) - bal getbit // while (getbit(bb)) + bal getbit // while (getbit(bb)) nop - beqz $v0, m_off_loop - li m_off, 1 // m_off = 1 (doing it there, in the unused delay slot) */ - lbu $t1, 0(source) // dst[olen++] = src[ilen++] - addiu source, 1 - sb $t1, 0(dest) - b main_loop - addiu dest, 1 + beqz $v0, m_off_loop + li m_off, 1 // m_off = 1 (doing it there, in the unused delay slot) */ + lbu $t1, 0(source) // dst[olen++] = src[ilen++] + addiu source, 1 + sb $t1, 0(dest) + b main_loop + addiu dest, 1 m_off_loop: - bal getbit // + getbi... - sll m_off, 1 // m_off = m_off * 2... - bal getbit // if (getbit(bb)... - addu m_off, $v0 // ..t(bb) - bnez $v0, exit_m_off_loop // ... break (and m_off-- as a side effect) - addiu m_off, -1 // m_off = (m_off-1).. - bal getbit // + getbi... - sll m_off, 1 // ..*2 - b m_off_loop // for(;;) - addu m_off, $v0 // ..t(bb) + bal getbit // + getbi... + sll m_off, 1 // m_off = m_off * 2... + bal getbit // if (getbit(bb)... + addu m_off, $v0 // ..t(bb) + bnez $v0, exit_m_off_loop // ... break (and m_off-- as a side effect) + addiu m_off, -1 // m_off = (m_off-1).. + bal getbit // + getbi... + sll m_off, 1 // ..*2 + b m_off_loop // for(;;) + addu m_off, $v0 // ..t(bb) exit_m_off_loop: - addiu m_off, -1 // if (!(--m_off)) ... - bnez m_off, m_off_diff_2 - nop - bal getbit // m_len = getbit(bb) - move m_off, last_m_off // m_off = last_m_off - b exit_if_moff_eq_2 - move m_len, $v0 + addiu m_off, -1 // if (!(--m_off)) ... + bnez m_off, m_off_diff_2 + nop + bal getbit // m_len = getbit(bb) + move m_off, last_m_off // m_off = last_m_off + b exit_if_moff_eq_2 + move m_len, $v0 m_off_diff_2: // else - addiu m_off, -1 // (m_off-1) (m_off was already sub by 2) - lbu $t1, 0(source) // src[ilen++] - sll m_off, 8 // *256 - addiu source, 1 - addu m_off, $t1 // m_off = ... - addiu $t1, m_off, 1 // if (m_off == -1) (that is, t1 == 0) - bnez $t1, 1f - nop - jr saved_ra // break; (that is, return) -1: andi m_len, $t1, 1 // mlen = (m_off ^ 1) & 1 (that is, (m_off + 1) & 1) - srl m_off, 1 // m_off >>= 1 - addiu m_off, 1 // ++m_off - move last_m_off, m_off // last_m_off = m_off - - // endif + addiu m_off, -1 // (m_off-1) (m_off was already sub by 2) + lbu $t1, 0(source) // src[ilen++] + sll m_off, 8 // *256 + addiu source, 1 + addu m_off, $t1 // m_off = ... + addiu $t1, m_off, 1 // if (m_off == -1) (that is, t1 == 0) + bnez $t1, 1f + nop + jr saved_ra // break; (that is, return) +1: andi m_len, $t1, 1 // mlen = (m_off ^ 1) & 1 (that is, (m_off + 1) & 1) + srl m_off, 1 // m_off >>= 1 + addiu m_off, 1 // ++m_off + move last_m_off, m_off // last_m_off = m_off + + // endif exit_if_moff_eq_2: - bal getbit // prefetch next bit, can be used twice + bal getbit // prefetch next bit, can be used twice nop - beqz m_len, else_1 // if (m_len) + beqz m_len, else_1 // if (m_len) nop - b exit_if - addiu m_len, $v0, 3 // m_len = 3 + getbit(bb) (I add 2 everywhere, for later) + b exit_if + addiu m_len, $v0, 3 // m_len = 3 + getbit(bb) (I add 2 everywhere, for later) else_1: - bnez $v0, else_2_reversed // else if (getbit(bb)) (second time the prefetched bit can be used) + bnez $v0, else_2_reversed // else if (getbit(bb)) (second time the prefetched bit can be used) nop // else... - addiu m_len, 1 // m_len++ + addiu m_len, 1 // m_len++ while_m_len: - bal getbit // + getbit(bb) - sll m_len, 1 // m_len * 2 - bal getbit // preparing the condition - addu m_len, $v0 // m_len = ... - beqz $v0, while_m_len // while(!getbit(bb)) + bal getbit // + getbit(bb) + sll m_len, 1 // m_len * 2 + bal getbit // preparing the condition + addu m_len, $v0 // m_len = ... + beqz $v0, while_m_len // while(!getbit(bb)) nop - b exit_if - addiu m_len, 5 // m_len += 5 (+2 from the original code) + b exit_if + addiu m_len, 5 // m_len += 5 (+2 from the original code) else_2_reversed: - bal getbit // m_len = 5 + getbit(bb) (still + 2 from the original code) + bal getbit // m_len = 5 + getbit(bb) (still + 2 from the original code) nop - addiu m_len, $v0, 5 - - // endif + addiu m_len, $v0, 5 + + // endif exit_if: - sltiu $t1, m_off, 0x501 // original code does m_len += (m_off > 0x500) - subu m_len, $t1 // we do m_len -= (m_off < 0x501) (to use sltiu) - // which get one of the +1 from before + sltiu $t1, m_off, 0x501 // original code does m_len += (m_off > 0x500) + subu m_len, $t1 // we do m_len -= (m_off < 0x501) (to use sltiu) + // which get one of the +1 from before - subu m_pos, dest, m_off // m_pos = dest + olen - m_off + subu m_pos, dest, m_off // m_pos = dest + olen - m_off - // Here, the original code does dst[olen++] = *m_pos++ - // we roll it back in the loop, by adding +1 before to m_len. + // Here, the original code does dst[olen++] = *m_pos++ + // we roll it back in the loop, by adding +1 before to m_len. copy_loop: - lbu $t1, 0(m_pos) // dst[olen++] = *m_pos++ - addiu m_pos, 1 - sb $t1, 0(dest) + lbu $t1, 0(m_pos) // dst[olen++] = *m_pos++ + addiu m_pos, 1 + sb $t1, 0(dest) nop // stupid 5900 loop bug... - addiu m_len, -1 - bnez m_len, copy_loop - addiu dest, 1 + addiu m_len, -1 + bnez m_len, copy_loop + addiu dest, 1 - b main_loop + b main_loop nop .end n2e_decompress @@ -167,17 +167,17 @@ copy_loop: .ent getbit getbit: - and $t1, bb, ff0000 - bnez $t1, bb_okay + and $t1, bb, ff0000 + bnez $t1, bb_okay nop - lbu $t1, 0(source) - addiu source, 1 - or bb, $t1, ff0000 + lbu $t1, 0(source) + addiu source, 1 + or bb, $t1, ff0000 bb_okay: - srl $v0, bb, 7 - sll bb, 1 - jr $ra - andi $v0, 1 + srl $v0, bb, 7 + sll bb, 1 + jr $ra + andi $v0, 1 .end getbit diff --git a/src/supportpsx/binffi.lua b/src/supportpsx/binffi.lua index e2f400622..77f0a52fc 100644 --- a/src/supportpsx/binffi.lua +++ b/src/supportpsx/binffi.lua @@ -191,9 +191,7 @@ PCSX.Misc.uclPack = function(src, dest) local outSize = C.uclWrapper(srcPtr, srcSize, destPtr) - if outSize == 0 then - error('Fatal error during data compression.') - end + if outSize == 0 then error('Fatal error during data compression.') end if type(dest) == 'table' and dest._type == 'File' then destSlice:resize(outSize) diff --git a/src/supportpsx/n2e-d.S b/src/supportpsx/n2e-d.S index d3f3f276c..d13c91a1a 100644 --- a/src/supportpsx/n2e-d.S +++ b/src/supportpsx/n2e-d.S @@ -38,111 +38,111 @@ n2e_decompress: // t9 = saved_ra - move saved_ra, $ra + move saved_ra, $ra - move bb, $0 - li last_m_off, 1 - lui ff0000, 0xff + move bb, $0 + li last_m_off, 1 + lui ff0000, 0xff -main_loop: // for (;;) +main_loop: // for (;;) - bal getbit // while (getbit(bb)) + bal getbit // while (getbit(bb)) nop - beqz $v0, m_off_loop - li m_off, 1 // m_off = 1 (doing it there, in the unused delay slot) */ - lbu $t1, 0(source) // dst[olen++] = src[ilen++] - addiu source, 1 - sb $t1, 0(dest) - b main_loop - addiu dest, 1 + beqz $v0, m_off_loop + li m_off, 1 // m_off = 1 (doing it there, in the unused delay slot) */ + lbu $t1, 0(source) // dst[olen++] = src[ilen++] + addiu source, 1 + sb $t1, 0(dest) + b main_loop + addiu dest, 1 m_off_loop: - bal getbit // + getbi... - sll m_off, 1 // m_off = m_off * 2... - bal getbit // if (getbit(bb)... - addu m_off, $v0 // ..t(bb) - bnez $v0, exit_m_off_loop // ... break (and m_off-- as a side effect) - addiu m_off, -1 // m_off = (m_off-1).. - bal getbit // + getbi... - sll m_off, 1 // ..*2 - b m_off_loop // for(;;) - addu m_off, $v0 // ..t(bb) + bal getbit // + getbi... + sll m_off, 1 // m_off = m_off * 2... + bal getbit // if (getbit(bb)... + addu m_off, $v0 // ..t(bb) + bnez $v0, exit_m_off_loop // ... break (and m_off-- as a side effect) + addiu m_off, -1 // m_off = (m_off-1).. + bal getbit // + getbi... + sll m_off, 1 // ..*2 + b m_off_loop // for(;;) + addu m_off, $v0 // ..t(bb) exit_m_off_loop: - addiu m_off, -1 // if (!(--m_off)) ... - bnez m_off, m_off_diff_2 - nop - bal getbit // m_len = getbit(bb) - move m_off, last_m_off // m_off = last_m_off - b exit_if_moff_eq_2 - move m_len, $v0 + addiu m_off, -1 // if (!(--m_off)) ... + bnez m_off, m_off_diff_2 + nop + bal getbit // m_len = getbit(bb) + move m_off, last_m_off // m_off = last_m_off + b exit_if_moff_eq_2 + move m_len, $v0 m_off_diff_2: // else - addiu m_off, -1 // (m_off-1) (m_off was already sub by 2) - lbu $t1, 0(source) // src[ilen++] - sll m_off, 8 // *256 - addiu source, 1 - addu m_off, $t1 // m_off = ... - addiu $t1, m_off, 1 // if (m_off == -1) (that is, t1 == 0) - bnez $t1, 1f - nop - jr saved_ra // break; (that is, return) -1: andi m_len, $t1, 1 // mlen = (m_off ^ 1) & 1 (that is, (m_off + 1) & 1) - srl m_off, 1 // m_off >>= 1 - addiu m_off, 1 // ++m_off - move last_m_off, m_off // last_m_off = m_off - - // endif + addiu m_off, -1 // (m_off-1) (m_off was already sub by 2) + lbu $t1, 0(source) // src[ilen++] + sll m_off, 8 // *256 + addiu source, 1 + addu m_off, $t1 // m_off = ... + addiu $t1, m_off, 1 // if (m_off == -1) (that is, t1 == 0) + bnez $t1, 1f + nop + jr saved_ra // break; (that is, return) +1: andi m_len, $t1, 1 // mlen = (m_off ^ 1) & 1 (that is, (m_off + 1) & 1) + srl m_off, 1 // m_off >>= 1 + addiu m_off, 1 // ++m_off + move last_m_off, m_off // last_m_off = m_off + + // endif exit_if_moff_eq_2: - bal getbit // prefetch next bit, can be used twice + bal getbit // prefetch next bit, can be used twice nop - beqz m_len, else_1 // if (m_len) + beqz m_len, else_1 // if (m_len) nop - b exit_if - addiu m_len, $v0, 3 // m_len = 3 + getbit(bb) (I add 2 everywhere, for later) + b exit_if + addiu m_len, $v0, 3 // m_len = 3 + getbit(bb) (I add 2 everywhere, for later) else_1: - bnez $v0, else_2_reversed // else if (getbit(bb)) (second time the prefetched bit can be used) + bnez $v0, else_2_reversed // else if (getbit(bb)) (second time the prefetched bit can be used) nop // else... - addiu m_len, 1 // m_len++ + addiu m_len, 1 // m_len++ while_m_len: - bal getbit // + getbit(bb) - sll m_len, 1 // m_len * 2 - bal getbit // preparing the condition - addu m_len, $v0 // m_len = ... - beqz $v0, while_m_len // while(!getbit(bb)) + bal getbit // + getbit(bb) + sll m_len, 1 // m_len * 2 + bal getbit // preparing the condition + addu m_len, $v0 // m_len = ... + beqz $v0, while_m_len // while(!getbit(bb)) nop - b exit_if - addiu m_len, 5 // m_len += 5 (+2 from the original code) + b exit_if + addiu m_len, 5 // m_len += 5 (+2 from the original code) else_2_reversed: - bal getbit // m_len = 5 + getbit(bb) (still + 2 from the original code) + bal getbit // m_len = 5 + getbit(bb) (still + 2 from the original code) nop - addiu m_len, $v0, 5 - - // endif + addiu m_len, $v0, 5 + + // endif exit_if: - sltiu $t1, m_off, 0x501 // original code does m_len += (m_off > 0x500) - subu m_len, $t1 // we do m_len -= (m_off < 0x501) (to use sltiu) - // which get one of the +1 from before + sltiu $t1, m_off, 0x501 // original code does m_len += (m_off > 0x500) + subu m_len, $t1 // we do m_len -= (m_off < 0x501) (to use sltiu) + // which get one of the +1 from before - subu m_pos, dest, m_off // m_pos = dest + olen - m_off + subu m_pos, dest, m_off // m_pos = dest + olen - m_off - // Here, the original code does dst[olen++] = *m_pos++ - // we roll it back in the loop, by adding +1 before to m_len. + // Here, the original code does dst[olen++] = *m_pos++ + // we roll it back in the loop, by adding +1 before to m_len. copy_loop: - lbu $t1, 0(m_pos) // dst[olen++] = *m_pos++ - addiu m_pos, 1 - sb $t1, 0(dest) + lbu $t1, 0(m_pos) // dst[olen++] = *m_pos++ + addiu m_pos, 1 + sb $t1, 0(dest) nop // stupid 5900 loop bug... - addiu m_len, -1 - bnez m_len, copy_loop - addiu dest, 1 + addiu m_len, -1 + bnez m_len, copy_loop + addiu dest, 1 - b main_loop + b main_loop nop .end n2e_decompress @@ -155,17 +155,17 @@ copy_loop: .ent getbit getbit: - and $t1, bb, ff0000 - bnez $t1, bb_okay + and $t1, bb, ff0000 + bnez $t1, bb_okay nop - lbu $t1, 0(source) - addiu source, 1 - or bb, $t1, ff0000 + lbu $t1, 0(source) + addiu source, 1 + or bb, $t1, ff0000 bb_okay: - srl $v0, bb, 7 - sll bb, 1 - jr $ra - andi $v0, 1 + srl $v0, bb, 7 + sll bb, 1 + jr $ra + andi $v0, 1 .end getbit