diff --git a/src/cdrom/cdriso.cc b/src/cdrom/cdriso.cc index 02661b0a55..07e8a64c08 100644 --- a/src/cdrom/cdriso.cc +++ b/src/cdrom/cdriso.cc @@ -248,12 +248,10 @@ uint8_t *PCSX::CDRIso::getBuffer() { void PCSX::CDRIso::printTracks() { for (int i = 1; i <= m_numtracks; i++) { - PCSX::g_system->printf(_("Track %.2d (%s) - Start %.2d:%.2d:%.2d, Length %.2d:%.2d:%.2d\n"), i, - (m_ti[i].type == TrackType::DATA ? "DATA" - : m_ti[i].cddatype == trackinfo::CCDDA ? "CZDA" - : "CDDA"), - m_ti[i].start.m, m_ti[i].start.s, m_ti[i].start.f, m_ti[i].length.m, m_ti[i].length.s, - m_ti[i].length.f); + PCSX::g_system->printf( + _("Track %.2d (%s) - Start %.2d:%.2d:%.2d, Length %.2d:%.2d:%.2d\n"), i, + (m_ti[i].type == TrackType::DATA ? "DATA" : m_ti[i].cddatype == trackinfo::CCDDA ? "CZDA" : "CDDA"), + m_ti[i].start.m, m_ti[i].start.s, m_ti[i].start.f, m_ti[i].length.m, m_ti[i].length.s, m_ti[i].length.f); } } diff --git a/src/cdrom/cdriso.h b/src/cdrom/cdriso.h index 54b6f5da77..16804a26ef 100644 --- a/src/cdrom/cdriso.h +++ b/src/cdrom/cdriso.h @@ -139,9 +139,9 @@ class CDRIso { IEC60908b::MSF pregap; IEC60908b::MSF start; IEC60908b::MSF length; - IO handle = nullptr; // for multi-track images CDDA - enum CDDAType { NONE = 0, BIN = 1, CCDDA = 2 } cddatype = NONE; // BIN, WAV, MP3, APE - uint32_t start_offset = 0; // byte offset from start of above file + IO handle = nullptr; // for multi-track images CDDA + enum CDDAType { NONE = 0, BIN = 1, CCDDA = 2 } cddatype = NONE; // BIN, WAV, MP3, APE + uint32_t start_offset = 0; // byte offset from start of above file }; static constexpr unsigned MAXTRACKS = 100; /* How many tracks can a CD hold? */ diff --git a/src/core/gpu.cc b/src/core/gpu.cc index f172be7eef..61fc0987e3 100644 --- a/src/core/gpu.cc +++ b/src/core/gpu.cc @@ -1097,9 +1097,10 @@ void PCSX::GPU::Poly::drawLogNode(u ImGui::SameLine(); std::string label = fmt::format(f_("Go to texture##{}"), n); if (ImGui::Button(label.c_str())) { - const auto mode = tpage.texDepth == TexDepth::Tex16Bits ? Events::GUI::VRAMFocus::VRAM_16BITS - : tpage.texDepth == TexDepth::Tex8Bits ? Events::GUI::VRAMFocus::VRAM_8BITS - : Events::GUI::VRAMFocus::VRAM_4BITS; + const auto mode = tpage.texDepth == TexDepth::Tex16Bits + ? Events::GUI::VRAMFocus::VRAM_16BITS + : tpage.texDepth == TexDepth::Tex8Bits ? Events::GUI::VRAMFocus::VRAM_8BITS + : Events::GUI::VRAMFocus::VRAM_4BITS; g_system->m_eventBus->signal(Events::GUI::SelectClut{clutX(), clutY()}); g_system->m_eventBus->signal( Events::GUI::VRAMFocus{int(minU + tx), int(minV + ty), int(maxU + tx), int(maxV + ty), mode}); @@ -1193,9 +1194,10 @@ void PCSX::GPU::Rect::drawLogNode(unsigned n) ImGui::SameLine(); std::string label = fmt::format(f_("Go to texture##{}"), n); if (ImGui::Button(label.c_str())) { - const auto mode = tpage.texDepth == TexDepth::Tex16Bits ? Events::GUI::VRAMFocus::VRAM_16BITS - : tpage.texDepth == TexDepth::Tex8Bits ? Events::GUI::VRAMFocus::VRAM_8BITS - : Events::GUI::VRAMFocus::VRAM_4BITS; + const auto mode = tpage.texDepth == TexDepth::Tex16Bits + ? Events::GUI::VRAMFocus::VRAM_16BITS + : tpage.texDepth == TexDepth::Tex8Bits ? Events::GUI::VRAMFocus::VRAM_8BITS + : Events::GUI::VRAMFocus::VRAM_4BITS; g_system->m_eventBus->signal(Events::GUI::SelectClut{clutX(), clutY()}); g_system->m_eventBus->signal(Events::GUI::VRAMFocus{int((u >> shift) + tx), int(v + ty), int(((u + w) >> shift) + tx), int(v + h + ty), mode}); diff --git a/src/core/isoffi.lua b/src/core/isoffi.lua index 89396ead77..6e8787740d 100644 --- a/src/core/isoffi.lua +++ b/src/core/isoffi.lua @@ -84,16 +84,17 @@ end local function createIsoBuilderWrapper(wrapper) local iso = { - _wrapper = ffi.gc(wrapper, function(self) C.isoBuilderClose(self) C.deleteIsoBuilder(self) end), + _wrapper = ffi.gc(wrapper, function(self) + C.isoBuilderClose(self) + C.deleteIsoBuilder(self) + end), writeLicense = function(self, file) if not file then file = Support.File.failedFile() end C.isoBuilderWriteLicense(self._wrapper, file._wrapper) end, writeSector = function(self, sectorData, mode) if not mode then mode = 'M2_FORM1' end - if Support.isLuaBuffer(sectorData) then - sectorData = sectorData.data - end + if Support.isLuaBuffer(sectorData) then sectorData = sectorData.data end C.isoBuilderWriteSector(self._wrapper, sectorData, mode) end, close = function(self) C.isoBuilderClose(self._wrapper) end, @@ -116,9 +117,7 @@ PCSX.isoTools = { local mul = 1 while bcd ~= 0 do local digit = bcd % 16 - if digit >= 10 then - error('Invalid BCD digit: ' .. digit) - end + if digit >= 10 then error('Invalid BCD digit: ' .. digit) end dec = dec + mul * digit mul = mul * 10 bcd = math.floor(bcd / 16) @@ -140,12 +139,8 @@ PCSX.isoTools = { m = PCSX.isoTools.fromBCD(m) s = PCSX.isoTools.fromBCD(s) f = PCSX.isoTools.fromBCD(f) - if s >= 60 then - error('Invalid MSF seconds: ' .. s) - end - if f >= 75 then - error('Invalid MSF frames: ' .. f) - end + if s >= 60 then error('Invalid MSF seconds: ' .. s) end + if f >= 75 then error('Invalid MSF frames: ' .. f) end return (m * 60 + s) * 75 + f - 150 end, toMSF = function(lba) diff --git a/src/core/logger.h b/src/core/logger.h index f8214e5999..e1f56d348d 100644 --- a/src/core/logger.h +++ b/src/core/logger.h @@ -53,7 +53,7 @@ enum class LogClass : unsigned { template struct Logger { template - static void Log(const char *format, const Args &...args) { + static void Log(const char *format, const Args &... args) { if (!enabled) return; std::string s = fmt::sprintf(format, args...); g_system->log(logClass, std::move(s)); diff --git a/src/core/pad.cc b/src/core/pad.cc index 3711540823..2a95bc1608 100644 --- a/src/core/pad.cc +++ b/src/core/pad.cc @@ -1303,7 +1303,8 @@ void PadsImpl::setLua(PCSX::Lua L) { L.getfieldtable(1); L.declareFunc( - "getButton", [this, pad](PCSX::Lua L) -> int { + "getButton", + [this, pad](PCSX::Lua L) -> int { int n = L.gettop(); if (n == 0) { return L.error("Not enough arguments to getButton"); @@ -1316,9 +1317,11 @@ void PadsImpl::setLua(PCSX::Lua L) { unsigned button = L.checknumber(1); L.push(((overrides & buttons) & (1 << button)) == 0); return 1; - }, -1); + }, + -1); L.declareFunc( - "setOverride", [this, pad](PCSX::Lua L) -> int { + "setOverride", + [this, pad](PCSX::Lua L) -> int { int n = L.gettop(); if (n == 0) { return L.error("Not enough arguments to setOverride"); @@ -1331,9 +1334,11 @@ void PadsImpl::setLua(PCSX::Lua L) { button = 1 << button; overrides &= ~button; return 0; - }, -1); + }, + -1); L.declareFunc( - "clearOverride", [this, pad](PCSX::Lua L) -> int { + "clearOverride", + [this, pad](PCSX::Lua L) -> int { int n = L.gettop(); if (n == 0) { return L.error("Not enough arguments to clearOverride"); @@ -1346,9 +1351,11 @@ void PadsImpl::setLua(PCSX::Lua L) { button = 1 << button; overrides |= button; return 0; - }, -1); + }, + -1); L.declareFunc( - "setAnalogMode", [this, pad](PCSX::Lua L) -> int { + "setAnalogMode", + [this, pad](PCSX::Lua L) -> int { int n = L.gettop(); if (n == 0) { m_pads[pad].m_analogMode = false; @@ -1356,12 +1363,15 @@ void PadsImpl::setLua(PCSX::Lua L) { m_pads[pad].m_analogMode = L.toboolean(); } return 0; - }, -1); + }, + -1); L.declareFunc( - "map", [this, pad](PCSX::Lua L) -> int { + "map", + [this, pad](PCSX::Lua L) -> int { m_pads[pad].map(); return 0; - }, -1); + }, + -1); L.pop(); L.pop(); diff --git a/src/core/pcsxffi.lua b/src/core/pcsxffi.lua index f0a0573ca6..64eb43b3eb 100644 --- a/src/core/pcsxffi.lua +++ b/src/core/pcsxffi.lua @@ -195,7 +195,12 @@ PCSX = { GPU = { takeScreenShot = function() local ss = C.takeScreenShot() - return { data = Support.File._createSliceWrapper(ss.data), width = ss.width, height = ss.height, bpp = ss.bpp } + return { + data = Support.File._createSliceWrapper(ss.data), + width = ss.width, + height = ss.height, + bpp = ss.bpp, + } end, }, createSaveState = function() diff --git a/src/core/pio-cart.h b/src/core/pio-cart.h index 1c735d7363..fecd1e9592 100644 --- a/src/core/pio-cart.h +++ b/src/core/pio-cart.h @@ -31,9 +31,7 @@ namespace PCSX { class PIOCart { public: - PIOCart() : m_pal(this) { - memset(m_detachedMemory, 0xff, sizeof(m_detachedMemory)); - } + PIOCart() : m_pal(this) { memset(m_detachedMemory, 0xff, sizeof(m_detachedMemory)); } void setLuts(); diff --git a/src/core/psxemulator.h b/src/core/psxemulator.h index e94a115197..67ae21c3a7 100644 --- a/src/core/psxemulator.h +++ b/src/core/psxemulator.h @@ -186,14 +186,14 @@ class Emulator { typedef SettingPath SettingEXP1BrowsePath; typedef Setting SettingPIOConnected; - Settings + Settings settings; class PcsxConfig { public: diff --git a/src/core/psxmem.cc b/src/core/psxmem.cc index 863691c0b8..3c9ea31698 100644 --- a/src/core/psxmem.cc +++ b/src/core/psxmem.cc @@ -545,7 +545,8 @@ void PCSX::Memory::write32(uint32_t address, uint32_t value) { address); } else { g_system->log(LogClass::CPU, _("32-bit write to unknown address: %8.8lx\n"), address); - if (g_emulator->settings.get().get()) { + if (g_emulator->settings.get() + .get()) { g_system->pause(); } } diff --git a/src/core/r3000a.h b/src/core/r3000a.h index c8faa91b9e..cbb1831b6d 100644 --- a/src/core/r3000a.h +++ b/src/core/r3000a.h @@ -456,8 +456,8 @@ Formula One 2001 uint32_t pcOffset = pc & 0xffffff; uint32_t pcCache = pc & 0xfff; - uint8_t * iAddr = m_regs.iCacheAddr; - uint8_t * iCode = m_regs.iCacheCode; + uint8_t *iAddr = m_regs.iCacheAddr; + uint8_t *iCode = m_regs.iCacheCode; // cached - RAM if (pcBank == 0x00 || pcBank == 0x80) { @@ -504,8 +504,10 @@ Formula One 2001 PCdrvFile(const std::filesystem::path &filename) : IO(new PosixFile(filename)) {} PCdrvFile(const std::filesystem::path &filename, FileOps::ReadWrite) : IO(new PosixFile(filename, FileOps::READWRITE)) {} - PCdrvFile(const std::filesystem::path &filename, FileOps::Truncate) : IO(new PosixFile(filename, FileOps::TRUNCATE)) {} - PCdrvFile(const std::filesystem::path &filename, FileOps::Create) : IO(new PosixFile(filename, FileOps::CREATE)) {} + PCdrvFile(const std::filesystem::path &filename, FileOps::Truncate) + : IO(new PosixFile(filename, FileOps::TRUNCATE)) {} + PCdrvFile(const std::filesystem::path &filename, FileOps::Create) + : IO(new PosixFile(filename, FileOps::CREATE)) {} virtual ~PCdrvFile() = default; std::string m_relativeFilename; }; diff --git a/src/core/system.h b/src/core/system.h index 15ca820d84..8ca5bccb9e 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -126,21 +126,21 @@ class System { // Legacy printf stuff; needs to be replaced with loggers template - void printf(const char *format, const Args &...args) { + void printf(const char *format, const Args &... args) { std::string s = fmt::sprintf(format, args...); printf(std::move(s)); } virtual void printf(std::string &&) = 0; // Add a log line template - void log(LogClass logClass, const char *format, const Args &...args) { + void log(LogClass logClass, const char *format, const Args &... args) { std::string s = fmt::sprintf(format, args...); log(logClass, std::move(s)); } virtual void log(LogClass, std::string &&) = 0; // Display a popup message to the user template - void message(const char *format, const Args &...args) { + void message(const char *format, const Args &... args) { std::string s = fmt::sprintf(format, args...); message(std::move(s)); } diff --git a/src/gui/extra.lua b/src/gui/extra.lua index 9343869bef..f80d6cb3d7 100644 --- a/src/gui/extra.lua +++ b/src/gui/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. - PCSX.Helpers = PCSX.Helpers or {} PCSX.Helpers.UI = { imageCoordinates = function(x, y, w, h, imageW, imageH) diff --git a/src/gui/imguiextraffi.lua b/src/gui/imguiextraffi.lua index 2589bc89c2..7bd4708b65 100644 --- a/src/gui/imguiextraffi.lua +++ b/src/gui/imguiextraffi.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 [[ typedef struct { float x, y; } ImVec2; diff --git a/src/gui/luanvg.cc b/src/gui/luanvg.cc index d25a263be8..b12530f674 100644 --- a/src/gui/luanvg.cc +++ b/src/gui/luanvg.cc @@ -32,7 +32,9 @@ void guiDrawBezierArrow(PCSX::GUI* gui, float width, ImVec2 p1, ImVec2 c1, ImVec void nvgRGBWrapper(unsigned char r, unsigned char g, unsigned char b, NVGcolor* ret) { *ret = nvgRGB(r, g, b); } void nvgRGBfWrapper(float r, float g, float b, NVGcolor* ret) { *ret = nvgRGBf(r, g, b); } -void nvgRGBAWrapper(unsigned char r, unsigned char g, unsigned char b, unsigned char a, NVGcolor* ret) { *ret = nvgRGBA(r, g, b, a); } +void nvgRGBAWrapper(unsigned char r, unsigned char g, unsigned char b, unsigned char a, NVGcolor* ret) { + *ret = nvgRGBA(r, g, b, a); +} void nvgRGBAfWrapper(float r, float g, float b, float a, NVGcolor* ret) { *ret = nvgRGBAf(r, g, b, a); } void nvgLerpRGBAWrapper(NVGcolor c0, NVGcolor c1, float u, NVGcolor* ret) { *ret = nvgLerpRGBA(c0, c1, u); } void nvgTransRGBAWrapper(NVGcolor c0, unsigned char a, NVGcolor* ret) { *ret = nvgTransRGBA(c0, a); } @@ -40,16 +42,20 @@ void nvgTransRGBAfWrapper(NVGcolor c0, float a, NVGcolor* ret) { *ret = nvgTrans void nvgHSLWrapper(float h, float s, float l, NVGcolor* ret) { *ret = nvgHSL(h, s, l); } void nvgHSLAWrapper(float h, float s, float l, unsigned char a, NVGcolor* ret) { *ret = nvgHSLA(h, s, l, a); } -void nvgLinearGradientWrapper(NVGcontext* ctx, float sx, float sy, float ex, float ey, NVGcolor icol, NVGcolor ocol, NVGpaint* ret) { +void nvgLinearGradientWrapper(NVGcontext* ctx, float sx, float sy, float ex, float ey, NVGcolor icol, NVGcolor ocol, + NVGpaint* ret) { *ret = nvgLinearGradient(ctx, sx, sy, ex, ey, icol, ocol); } -void nvgBoxGradientWrapper(NVGcontext* ctx, float x, float y, float w, float h, float r, float f, NVGcolor icol, NVGcolor ocol, NVGpaint* ret) { +void nvgBoxGradientWrapper(NVGcontext* ctx, float x, float y, float w, float h, float r, float f, NVGcolor icol, + NVGcolor ocol, NVGpaint* ret) { *ret = nvgBoxGradient(ctx, x, y, w, h, r, f, icol, ocol); } -void nvgRadialGradientWrapper(NVGcontext* ctx, float cx, float cy, float inr, float outr, NVGcolor icol, NVGcolor ocol, NVGpaint* ret) { +void nvgRadialGradientWrapper(NVGcontext* ctx, float cx, float cy, float inr, float outr, NVGcolor icol, NVGcolor ocol, + NVGpaint* ret) { *ret = nvgRadialGradient(ctx, cx, cy, inr, outr, icol, ocol); } -void nvgImagePatternWrapper(NVGcontext* ctx, float ox, float oy, float ex, float ey, float angle, int image, float alpha, NVGpaint* ret) { +void nvgImagePatternWrapper(NVGcontext* ctx, float ox, float oy, float ex, float ey, float angle, int image, + float alpha, NVGpaint* ret) { *ret = nvgImagePattern(ctx, ox, oy, ex, ey, angle, image, alpha); } diff --git a/src/gui/nvgffi-cdefs.lua b/src/gui/nvgffi-cdefs.lua index fd11d42bd5..74dcf7c4e8 100644 --- a/src/gui/nvgffi-cdefs.lua +++ b/src/gui/nvgffi-cdefs.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 [[ typedef struct NVGcontext NVGcontext; diff --git a/src/gui/nvgffi.lua b/src/gui/nvgffi.lua index edda656a24..ed4490311d 100644 --- a/src/gui/nvgffi.lua +++ b/src/gui/nvgffi.lua @@ -15,34 +15,13 @@ -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - local C = ffi.load 'NANOVG' nvg = { - Winding = { - CCW = 1, - CW = 2, - }, - Solidity = { - SOLID = 1, - HOLE = 2, - }, - LineCap = { - BUTT = 0, - ROUND = 1, - SQUARE = 2, - BEVEL = 3, - MITER = 4, - }, - Align = { - LEFT = 1, - CENTER = 2, - RIGHT = 4, - TOP = 8, - MIDDLE = 16, - BOTTOM = 32, - BASELINE = 64, - }, + Winding = { CCW = 1, CW = 2 }, + Solidity = { SOLID = 1, HOLE = 2 }, + LineCap = { BUTT = 0, ROUND = 1, SQUARE = 2, BEVEL = 3, MITER = 4 }, + Align = { LEFT = 1, CENTER = 2, RIGHT = 4, TOP = 8, MIDDLE = 16, BOTTOM = 32, BASELINE = 64 }, BlendFactor = { ZERO = 1, ONE = 2, @@ -69,13 +48,7 @@ nvg = { COPY = 9, XOR = 10, }, - ImageFlags = { - GENERATE_MIPMAPS = 1, - REPEATX = 2, - REPEATY = 4, - FLIPY = 8, - PREMULTIPLIED = 16, - }, + ImageFlags = { GENERATE_MIPMAPS = 1, REPEATX = 2, REPEATY = 4, FLIPY = 8, PREMULTIPLIED = 16 }, Color = { New = function(r, g, b, a) local c = ffi.new('NVGcolor') @@ -86,14 +59,8 @@ nvg = { return c end, }, - Paint = { - New = function() - return ffi.new('NVGpaint') - end, - }, - globalCompositeOperation = function(self, op) - C.nvgGlobalCompositeOperation(self._ctx, op) - end, + Paint = { New = function() return ffi.new('NVGpaint') end }, + globalCompositeOperation = function(self, op) C.nvgGlobalCompositeOperation(self._ctx, op) end, globalCompositeBlendFunc = function(self, sfactor, dfactor) C.nvgGlobalCompositeBlendFunc(self._ctx, sfactor, dfactor) end, @@ -145,66 +112,26 @@ nvg = { C.nvgHSLAWrapper(h, s, l, a, ret) return ret[0] end, - save = function(self) - C.nvgSave(self._ctx) - end, - restore = function(self) - C.nvgRestore(self._ctx) - end, - reset = function(self) - C.nvgReset(self._ctx) - end, - shapeAntiAlias = function(self, enabled) - C.nvgShapeAntiAlias(self._ctx, enabled and 1 or 0) - end, - strokeColor = function(self, color) - C.nvgStrokeColor(self._ctx, color) - end, - strokePaint = function(self, paint) - C.nvgStrokePaint(self._ctx, paint) - end, - fillColor = function(self, color) - C.nvgFillColor(self._ctx, color) - end, - fillPaint = function(self, paint) - C.nvgFillPaint(self._ctx, paint) - end, - miterLimit = function(self, limit) - C.nvgMiterLimit(self._ctx, limit) - end, - strokeWidth = function(self, size) - C.nvgStrokeWidth(self._ctx, size) - end, - lineCap = function(self, cap) - C.nvgLineCap(self._ctx, cap) - end, - lineJoin = function(self, join) - C.nvgLineJoin(self._ctx, join) - end, - globalAlpha = function(self, alpha) - C.nvgGlobalAlpha(self._ctx, alpha) - end, - resetTransform = function(self) - C.nvgResetTransform(self._ctx) - end, - translate = function(self, x, y) - C.nvgTranslate(self._ctx, x, y) - end, - rotate = function(self, angle) - C.nvgRotate(self._ctx, angle) - end, - skewX = function(self, angle) - C.nvgSkewX(self._ctx, angle) - end, - skewY = function(self, angle) - C.nvgSkewY(self._ctx, angle) - end, - scale = function(self, x, y) - C.nvgScale(self._ctx, x, y) - end, - currentTransform = function(self, xform) - C.nvgCurrentTransform(self._ctx, xform) - end, + save = function(self) C.nvgSave(self._ctx) end, + restore = function(self) C.nvgRestore(self._ctx) end, + reset = function(self) C.nvgReset(self._ctx) end, + shapeAntiAlias = function(self, enabled) C.nvgShapeAntiAlias(self._ctx, enabled and 1 or 0) end, + strokeColor = function(self, color) C.nvgStrokeColor(self._ctx, color) end, + strokePaint = function(self, paint) C.nvgStrokePaint(self._ctx, paint) end, + fillColor = function(self, color) C.nvgFillColor(self._ctx, color) end, + fillPaint = function(self, paint) C.nvgFillPaint(self._ctx, paint) end, + miterLimit = function(self, limit) C.nvgMiterLimit(self._ctx, limit) end, + strokeWidth = function(self, size) C.nvgStrokeWidth(self._ctx, size) end, + lineCap = function(self, cap) C.nvgLineCap(self._ctx, cap) end, + lineJoin = function(self, join) C.nvgLineJoin(self._ctx, join) end, + globalAlpha = function(self, alpha) C.nvgGlobalAlpha(self._ctx, alpha) end, + resetTransform = function(self) C.nvgResetTransform(self._ctx) end, + translate = function(self, x, y) C.nvgTranslate(self._ctx, x, y) end, + rotate = function(self, angle) C.nvgRotate(self._ctx, angle) end, + skewX = function(self, angle) C.nvgSkewX(self._ctx, angle) end, + skewY = function(self, angle) C.nvgSkewY(self._ctx, angle) end, + scale = function(self, x, y) C.nvgScale(self._ctx, x, y) end, + currentTransform = function(self, xform) C.nvgCurrentTransform(self._ctx, xform) end, transFormIdentity = C.nvgTransformIdentity, transformTranslate = C.nvgTransformTranslate, transformScale = C.nvgTransformScale, @@ -220,15 +147,9 @@ nvg = { createImageRGBA = function(self, w, h, imageFlags, data) return C.nvgCreateImageRGBA(self._ctx, w, h, imageFlags, data) end, - updateImage = function(self, image, data) - C.nvgUpdateImage(self._ctx, image, data) - end, - imageSize = function(self, image, w, h) - C.nvgImageSize(self._ctx, image, w, h) - end, - deleteImage = function(self, image) - C.nvgDeleteImage(self._ctx, image) - end, + updateImage = function(self, image, data) C.nvgUpdateImage(self._ctx, image, data) end, + imageSize = function(self, image, w, h) C.nvgImageSize(self._ctx, image, w, h) end, + deleteImage = function(self, image) C.nvgDeleteImage(self._ctx, image) end, linearGradient = function(self, sx, sy, ex, ey, icol, ocol) local ret = ffi.new('NVGpaint[1]') C.nvgLinearGradientWrapper(self._ctx, sx, sy, ex, ey, icol, ocol, ret) @@ -249,66 +170,28 @@ nvg = { C.nvgImagePatternWrapper(self._ctx, ox, oy, ex, ey, angle, image, alpha, ret) return ret[0] end, - scissor = function(self, x, y, w, h) - C.nvgScissor(self._ctx, x, y, w, h) - end, - intersectScissor = function(self, x, y, w, h) - C.nvgIntersectScissor(self._ctx, x, y, w, h) - end, - resetScissor = function(self) - C.nvgResetScissor(self._ctx) - end, - beginPath = function(self) - C.nvgBeginPath(self._ctx) - end, - moveTo = function(self, x, y) - C.nvgMoveTo(self._ctx, x, y) - end, - lineTo = function(self, x, y) - C.nvgLineTo(self._ctx, x, y) - end, - bezierTo = function(self, c1x, c1y, c2x, c2y, x, y) - C.nvgBezierTo(self._ctx, c1x, c1y, c2x, c2y, x, y) - end, - quadTo = function(self, cx, cy, x, y) - C.nvgQuadTo(self._ctx, cx, cy, x, y) - end, - arcTo = function(self, x1, y1, x2, y2, radius) - C.nvgArcTo(self._ctx, x1, y1, x2, y2, radius) - end, - closePath = function(self) - C.nvgClosePath(self._ctx) - end, - pathWinding = function(self, dir) - C.nvgPathWinding(self._ctx, dir) - end, - arc = function(self, cx, cy, r, a0, a1, dir) - C.nvgArc(self._ctx, cx, cy, r, a0, a1, dir) - end, - rect = function(self, x, y, w, h) - C.nvgRect(self._ctx, x, y, w, h) - end, - roundedRect = function(self, x, y, w, h, r) - C.nvgRoundedRect(self._ctx, x, y, w, h, r) - end, + scissor = function(self, x, y, w, h) C.nvgScissor(self._ctx, x, y, w, h) end, + intersectScissor = function(self, x, y, w, h) C.nvgIntersectScissor(self._ctx, x, y, w, h) end, + resetScissor = function(self) C.nvgResetScissor(self._ctx) end, + beginPath = function(self) C.nvgBeginPath(self._ctx) end, + moveTo = function(self, x, y) C.nvgMoveTo(self._ctx, x, y) end, + lineTo = function(self, x, y) C.nvgLineTo(self._ctx, x, y) end, + bezierTo = function(self, c1x, c1y, c2x, c2y, x, y) C.nvgBezierTo(self._ctx, c1x, c1y, c2x, c2y, x, y) end, + quadTo = function(self, cx, cy, x, y) C.nvgQuadTo(self._ctx, cx, cy, x, y) end, + arcTo = function(self, x1, y1, x2, y2, radius) C.nvgArcTo(self._ctx, x1, y1, x2, y2, radius) end, + closePath = function(self) C.nvgClosePath(self._ctx) end, + pathWinding = function(self, dir) C.nvgPathWinding(self._ctx, dir) end, + arc = function(self, cx, cy, r, a0, a1, dir) C.nvgArc(self._ctx, cx, cy, r, a0, a1, dir) end, + rect = function(self, x, y, w, h) C.nvgRect(self._ctx, x, y, w, h) end, + roundedRect = function(self, x, y, w, h, r) C.nvgRoundedRect(self._ctx, x, y, w, h, r) end, roundedRectVarying = function(self, x, y, w, h, radTopLeft, radTopRight, radBottomRight, radBottomLeft) C.nvgRoundedRectVarying(self._ctx, x, y, w, h, radTopLeft, radTopRight, radBottomRight, radBottomLeft) end, - ellipse = function(self, cx, cy, rx, ry) - C.nvgEllipse(self._ctx, cx, cy, rx, ry) - end, - circle = function(self, cx, cy, r) - C.nvgCircle(self._ctx, cx, cy, r) - end, - fill = function(self) - C.nvgFill(self._ctx) - end, - stroke = function(self) - C.nvgStroke(self._ctx) - end, - createFont = function(self, name, filename) - return C.nvgCreateFont(self._ctx, name, filename) - end, + ellipse = function(self, cx, cy, rx, ry) C.nvgEllipse(self._ctx, cx, cy, rx, ry) end, + circle = function(self, cx, cy, r) C.nvgCircle(self._ctx, cx, cy, r) end, + fill = function(self) C.nvgFill(self._ctx) end, + stroke = function(self) C.nvgStroke(self._ctx) end, + createFont = function(self, name, filename) return C.nvgCreateFont(self._ctx, name, filename) end, createFontAtIndex = function(self, name, filename, fontIndex) return C.nvgCreateFontAtIndex(self._ctx, name, filename, fontIndex) end, @@ -318,82 +201,52 @@ nvg = { createFontMemAtIndex = function(self, name, data, ndata, freeData, fontIndex) return C.nvgCreateFontMemAtIndex(self._ctx, name, data, ndata, freeData, fontIndex) end, - findFont = function(self, name) - return C.nvgFindFont(self._ctx, name) - end, + findFont = function(self, name) return C.nvgFindFont(self._ctx, name) end, addFallbackFontId = function(self, baseFont, fallbackFont) C.nvgAddFallbackFontId(self._ctx, baseFont, fallbackFont) end, - addFallbackFont = function(self, baseFont, fallbackFont) - C.nvgAddFallbackFont(self._ctx, baseFont, fallbackFont) - end, - resetFallbackFontsId = function(self, baseFont) - C.nvgResetFallbackFontsId(self._ctx, baseFont) - end, - resetFallbackFonts = function(self, baseFont) - C.nvgResetFallbackFonts(self._ctx, baseFont) - end, - fontSize = function(self, size) - C.nvgFontSize(self._ctx, size) - end, - fontBlur = function(self, blur) - C.nvgFontBlur(self._ctx, blur) - end, - textLetterSpacing = function(self, spacing) - C.nvgTextLetterSpacing(self._ctx, spacing) - end, - textLineHeight = function(self, lineHeight) - C.nvgTextLineHeight(self._ctx, lineHeight) - end, - textAlign = function(self, align) - C.nvgTextAlign(self._ctx, align) - end, - fontFaceId = function(self, font) - C.nvgFontFaceId(self._ctx, font) - end, - fontFace = function(self, font) - C.nvgFontFace(self._ctx, font) - end, - text = function(self, x, y, string) - C.nvgText(self._ctx, x, y, string, nil) - end, - textBox = function(self, x, y, breakRowWidth, string) - C.nvgTextBox(self._ctx, x, y, breakRowWidth, string, nil) - end, + addFallbackFont = function(self, baseFont, fallbackFont) C.nvgAddFallbackFont(self._ctx, baseFont, fallbackFont) end, + resetFallbackFontsId = function(self, baseFont) C.nvgResetFallbackFontsId(self._ctx, baseFont) end, + resetFallbackFonts = function(self, baseFont) C.nvgResetFallbackFonts(self._ctx, baseFont) end, + fontSize = function(self, size) C.nvgFontSize(self._ctx, size) end, + fontBlur = function(self, blur) C.nvgFontBlur(self._ctx, blur) end, + textLetterSpacing = function(self, spacing) C.nvgTextLetterSpacing(self._ctx, spacing) end, + textLineHeight = function(self, lineHeight) C.nvgTextLineHeight(self._ctx, lineHeight) end, + textAlign = function(self, align) C.nvgTextAlign(self._ctx, align) end, + fontFaceId = function(self, font) C.nvgFontFaceId(self._ctx, font) end, + fontFace = function(self, font) C.nvgFontFace(self._ctx, font) end, + text = function(self, x, y, string) C.nvgText(self._ctx, x, y, string, nil) end, + textBox = function(self, x, y, breakRowWidth, string) C.nvgTextBox(self._ctx, x, y, breakRowWidth, string, nil) end, textBounds = function(self, x, y, string) - local bounds = ffi.new("float[4]") + local bounds = ffi.new('float[4]') local ret = C.nvgTextBounds(self._ctx, x, y, string, nil, bounds) return ret, bounds end, textBoxBounds = function(self, x, y, breakRowWidth, string) - local bounds = ffi.new("float[4]") + local bounds = ffi.new('float[4]') C.nvgTextBoxBounds(self._ctx, x, y, breakRowWidth, string, nil, bounds) return bounds end, textGlyphPositions = function(self, x, y, string) - local positions = ffi.new("NVGglyphPosition[?]", #string) + local positions = ffi.new('NVGglyphPosition[?]', #string) local ret = C.nvgTextGlyphPositions(self._ctx, x, y, string, nil, positions, #string) return ret, positions end, textMetrics = function(self) - local ascender = ffi.new("float[1]") - local descender = ffi.new("float[1]") - local lineh = ffi.new("float[1]") + local ascender = ffi.new('float[1]') + local descender = ffi.new('float[1]') + local lineh = ffi.new('float[1]') C.nvgTextMetrics(self._ctx, ascender, descender, lineh) return ascender[0], descender[0], lineh[0] end, textBreakLines = function(self, string, breakRowWidth) - local rows = ffi.new("NVGtextRow[?]", #string) + local rows = ffi.new('NVGtextRow[?]', #string) local ret = C.nvgTextBreakLines(self._ctx, string, nil, breakRowWidth, rows, #string) return ret, rows end, drawBezierArrow = function(self, width, p1, c1, c2, p2, innerColor, outerColor) - if innerColor == nil then - innerColor = self.Color.New(1.0, 1.0, 1.0) - end - if outerColor == nil then - outerColor = self.Color.New(0.5, 0.5, 0.5) - end + if innerColor == nil then innerColor = self.Color.New(1.0, 1.0, 1.0) end + if outerColor == nil then outerColor = self.Color.New(0.5, 0.5, 0.5) end local p1 = imgui.extra.ImVec2.New(p1.x, p1.y) local c1 = imgui.extra.ImVec2.New(c1.x, c1.y) local c2 = imgui.extra.ImVec2.New(c2.x, c2.y) @@ -413,12 +266,8 @@ nvg = { _queue = {}, _processQueueForViewportId = function(self, viewportId) local viewportQueue = self._queue[viewportId] - if viewportQueue == nil then - return - end - for i = 1, #viewportQueue do - viewportQueue[i]() - end + if viewportQueue == nil then return end + for i = 1, #viewportQueue do viewportQueue[i]() end self._queue[viewportId] = nil end, } diff --git a/src/gui/widgets/memory_observer.cc b/src/gui/widgets/memory_observer.cc index 3d38db380c..80f7a950a0 100644 --- a/src/gui/widgets/memory_observer.cc +++ b/src/gui/widgets/memory_observer.cc @@ -334,9 +334,9 @@ void PCSX::Widgets::MemoryObserver::draw(const char* title) { ImGui::TableHeadersRow(); bool as_uint = (m_scanValueType == ScanValueType::Uint); - const auto valueDisplayFormat = m_hex ? "%x" - : (m_fixedPoint && stride > 1) ? (as_uint ? "%u.%u" : "%i.%i") - : (as_uint ? "%u" : "%i"); + const auto valueDisplayFormat = + m_hex ? "%x" + : (m_fixedPoint && stride > 1) ? (as_uint ? "%u.%u" : "%i.%i") : (as_uint ? "%u" : "%i"); ImGuiListClipper clipper; clipper.Begin(m_addressValuePairs.size()); diff --git a/src/gui/widgets/pio-cart.cc b/src/gui/widgets/pio-cart.cc index b68ee613ba..df41498474 100644 --- a/src/gui/widgets/pio-cart.cc +++ b/src/gui/widgets/pio-cart.cc @@ -56,7 +56,6 @@ bool PCSX::Widgets::PIOCart::draw(const char* title) { g_emulator->m_pioCart->setLuts(); } - { // Select EXP1 Dialog auto& exp1path = settings.get(); if (selectEXP1Dialog) { @@ -73,7 +72,8 @@ bool PCSX::Widgets::PIOCart::draw(const char* title) { // Maybe we should check the file size here? // Display a warning if the file is too big? settings.get().value = fileToOpen[0]; - g_emulator->m_mem->loadEXP1FromFile(g_emulator->settings.get().value); + g_emulator->m_mem->loadEXP1FromFile( + g_emulator->settings.get().value); changed = true; } } diff --git a/src/lua/fileffi.lua b/src/lua/fileffi.lua index 0fc32cac6d..7a44bb2dd4 100644 --- a/src/lua/fileffi.lua +++ b/src/lua/fileffi.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. - local C = ffi.load 'SUPPORT_FILE' local sliceMeta = { @@ -342,8 +341,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 - return createFileWrapper(C.ffmpegAudioFile(file._wrapper, channels or 'Stereo', endianness or 'Little', sampleFormat or 'S16', frequency or 44100)) + local channels, endianness, sampleFormat, frequency = options.channels, options.endianness, options.sampleFormat, + options.frequency + return createFileWrapper(C.ffmpegAudioFile(file._wrapper, channels or 'Stereo', endianness or 'Little', + sampleFormat or 'S16', frequency or 44100)) end if (type(Support) ~= 'table') then Support = {} end diff --git a/src/mips/common/syscalls/syscalls.h b/src/mips/common/syscalls/syscalls.h index 9bfb398bbc..55799098e3 100644 --- a/src/mips/common/syscalls/syscalls.h +++ b/src/mips/common/syscalls/syscalls.h @@ -39,29 +39,20 @@ struct JmpBuf; static __attribute__((always_inline)) int enterCriticalSection() { register int n asm("a0") = 1; register int r asm("v0"); - __asm__ volatile("syscall\n" - : "=r"(r) - : "r"(n) - : "memory"); + __asm__ volatile("syscall\n" : "=r"(r) : "r"(n) : "memory"); return r; } static __attribute__((always_inline)) void leaveCriticalSection() { register int n asm("a0") = 2; - __asm__ volatile("syscall\n" - : - : "r"(n) - : "memory"); + __asm__ volatile("syscall\n" : : "r"(n) : "memory"); } static __attribute__((always_inline)) int changeThreadSubFunction(uint32_t address) { register int n asm("a0") = 3; register int tcb asm("a1") = address; register int r asm("v0"); - __asm__ volatile("syscall\n" - : "=r"(r) - : "r"(n), "r"(tcb) - : "memory"); + __asm__ volatile("syscall\n" : "=r"(r) : "r"(n), "r"(tcb) : "memory"); return r; } diff --git a/src/mips/openbios/patches/custom_handler_1.c b/src/mips/openbios/patches/custom_handler_1.c index 27554b4b2c..97a7343236 100644 --- a/src/mips/openbios/patches/custom_handler_1.c +++ b/src/mips/openbios/patches/custom_handler_1.c @@ -34,16 +34,16 @@ SOFTWARE. /* Found in Point Blank USA: ************************************************************* - * FUNCTION + * FUNCTION ************************************************************* undefined installCustomHandler () assume gp = 0x8009c180 - undefined v0:1 XREF[2]: 800606d4 (W) , - 800606f0 (W) - dword * v0:4 c0table XREF[2]: 800606d4 (W) , - 800606f0 (W) - dword * v0:4 exceptionHandlerPtr XREF[1]: 800606f0 (W) - installCustomHandler XREF[1]: FUN_800601bc:800602ac (c) + undefined v0:1 XREF[2]: 800606d4 (W) , + 800606f0 (W) + dword * v0:4 c0table XREF[2]: 800606d4 (W) , + 800606f0 (W) + dword * v0:4 exceptionHandlerPtr XREF[1]: 800606f0 (W) + installCustomHandler XREF[1]: FUN_800601bc:800602ac (c) 800606b4 0a 80 01 3c lui at,0x800a 800606b8 ac c3 3f ac sw ra,-0x3c54 (at)=>DAT_8009c3ac 800606bc 0a 80 01 3c lui at,0x800a @@ -59,7 +59,7 @@ SOFTWARE. 800606e4 18 00 42 8c lw c0table ,0x18 (c0table ) 800606e8 3c 08 4a 25 addiu t2,t2,0x83c 800606ec 4c 08 29 25 addiu t1,t1,0x84c - LAB_800606f0 XREF[1]: 800606fc (j) + LAB_800606f0 XREF[1]: 800606fc (j) 800606f0 00 00 43 8d lw v1,0x0 (t2)=>LAB_8006083c 800606f4 04 00 4a 25 addiu t2,t2,0x4 800606f8 04 00 42 24 addiu exceptionHandlerPtr ,exceptionHandlerPtr ,0x4 @@ -73,7 +73,7 @@ SOFTWARE. 80060718 00 00 00 00 _nop 8006071c 80 00 0a 24 li t2,0x80 80060720 90 00 09 24 li t1,0x90 - LAB_80060724 XREF[1]: 80060730 (j) + LAB_80060724 XREF[1]: 80060730 (j) 80060724 00 00 43 8d lw v1,0x0 (t2)=>DAT_00000080 80060728 04 00 4a 25 addiu t2,t2,0x4 8006072c 04 00 42 24 addiu exceptionHandlerPtr ,exceptionHandlerPtr ,0x4 @@ -84,13 +84,13 @@ SOFTWARE. 80060740 80 00 02 24 li exceptionHandlerPtr ,0x80 80060744 a0 09 4a 25 addiu t2,t2,0x9a0 80060748 b0 09 29 25 addiu t1,t1,0x9b0 - LAB_8006074c XREF[1]: 80060758 (j) + LAB_8006074c XREF[1]: 80060758 (j) 8006074c 00 00 43 8d lw v1,0x0 (t2)=>LAB_800609a0 80060750 04 00 4a 25 addiu t2,t2,0x4 80060754 04 00 42 24 addiu exceptionHandlerPtr ,exceptionHandlerPtr ,0x4 80060758 fc ff 49 15 bne t2,t1,LAB_8006074c 8006075c fc ff 43 ac _sw v1,-0x4 (exceptionHandlerPtr )=>DAT_00000080 - LAB_80060760 XREF[1]: 80060714 (j) + LAB_80060760 XREF[1]: 80060714 (j) 80060760 11 7c 01 0c jal FlushCache void FlushCache(void) 80060764 00 00 00 00 _nop 80060768 0a 80 1f 3c lui ra,0x800a @@ -112,9 +112,7 @@ SOFTWARE. #ifndef GENERATE_HASHES -enum patch_behavior custom_handler_1_execute(uint32_t* ra) { - return PATCH_PASSTHROUGH; -} +enum patch_behavior custom_handler_1_execute(uint32_t* ra) { return PATCH_PASSTHROUGH; } #else diff --git a/src/mips/openbios/sio0/card.c b/src/mips/openbios/sio0/card.c index 65261298ee..2957460057 100644 --- a/src/mips/openbios/sio0/card.c +++ b/src/mips/openbios/sio0/card.c @@ -362,9 +362,7 @@ int __attribute__((section(".ramtext"))) mcInfoHandler() { return 0; } -uint8_t __attribute__((section(".ramtext"))) getCardStatus(int port) { - return g_mcFlags[port]; -} +uint8_t __attribute__((section(".ramtext"))) getCardStatus(int port) { return g_mcFlags[port]; } uint8_t __attribute__((section(".ramtext"))) waitCardStatus(int port) { while ((g_mcFlags[port] & 1) == 0) { diff --git a/src/mips/psyqo-paths/cdrom-loader.hh b/src/mips/psyqo-paths/cdrom-loader.hh index 72a8284a47..c0040d178d 100644 --- a/src/mips/psyqo-paths/cdrom-loader.hh +++ b/src/mips/psyqo-paths/cdrom-loader.hh @@ -68,12 +68,13 @@ class CDRomLoader { } private: - void setupQueue(eastl::string_view path, GPU& gpu, ISO9660Parser& parser, eastl::function &&)> &&callback); - eastl::function &&)> m_callback; + void setupQueue(eastl::string_view path, GPU& gpu, ISO9660Parser& parser, + eastl::function&&)>&& callback); + eastl::function&&)> m_callback; psyqo::TaskQueue m_queue; ISO9660Parser::ReadRequest m_request; eastl::vector m_data; bool m_pending = false; }; -} +} // namespace psyqo::paths diff --git a/src/mips/psyqo/bezier.hh b/src/mips/psyqo/bezier.hh index f50e29ada4..58f9e7f434 100644 --- a/src/mips/psyqo/bezier.hh +++ b/src/mips/psyqo/bezier.hh @@ -32,7 +32,7 @@ namespace Bezier { /** * @brief Cubic Bezier curve helper function. - * + * * @param a Start of the Bezier curve. * @param b Control point 1. * @param c Control point 2. @@ -43,6 +43,6 @@ namespace Bezier { Vec2 cubic(const Vec2& a, const Vec2& b, const Vec2& c, const Vec2& d, FixedPoint<> t); Vec3 cubic(const Vec3& a, const Vec3& b, const Vec3& c, const Vec3& d, FixedPoint<> t); -} +} // namespace Bezier } // namespace psyqo diff --git a/src/mips/psyqo/fixed-point.hh b/src/mips/psyqo/fixed-point.hh index 916609f535..639e6ef6b0 100644 --- a/src/mips/psyqo/fixed-point.hh +++ b/src/mips/psyqo/fixed-point.hh @@ -119,7 +119,7 @@ class FixedPoint { * @brief Construct a new Fixed Point number from a different * fixed point number. */ - template + template explicit FixedPoint(FixedPoint other) { if constexpr (precisionBits == otherPrecisionBits) { *this = other; @@ -149,7 +149,7 @@ class FixedPoint { return (value + scale / 2) / scale; } - template + template constexpr U integer() const { if constexpr (std::is_signed::value) { if (value < 0) { diff --git a/src/mips/psyqo/hardware/cdrom.hh b/src/mips/psyqo/hardware/cdrom.hh index bd02dbda90..e875180db8 100644 --- a/src/mips/psyqo/hardware/cdrom.hh +++ b/src/mips/psyqo/hardware/cdrom.hh @@ -90,9 +90,7 @@ struct CommandFifo { } private: - void recursiveSend(uint8_t arg) { - Fifo = arg; - } + void recursiveSend(uint8_t arg) { Fifo = arg; } template void recursiveSend(uint8_t arg, Args... args) { Fifo = arg; @@ -105,4 +103,4 @@ extern Register<0, uint8_t, WriteQueue::Bypass, Access, 1>> CauseMask; extern Register<0, uint8_t, WriteQueue::Bypass, Access, 1>> Cause; -} +} // namespace psyqo::Hardware::CDRom diff --git a/src/mips/psyqo/hardware/cpu.hh b/src/mips/psyqo/hardware/cpu.hh index 93d82e67a5..0bfbc80f78 100644 --- a/src/mips/psyqo/hardware/cpu.hh +++ b/src/mips/psyqo/hardware/cpu.hh @@ -55,5 +55,4 @@ extern IRQReg<0x0074> IMask; extern Register<0x00f0> DPCR; extern Register<0x00f4> DICR; - -} +} // namespace psyqo::Hardware::CPU diff --git a/src/mips/psyqo/hardware/gpu.hh b/src/mips/psyqo/hardware/gpu.hh index 54b35923af..2128ddf821 100644 --- a/src/mips/psyqo/hardware/gpu.hh +++ b/src/mips/psyqo/hardware/gpu.hh @@ -33,4 +33,4 @@ namespace psyqo::Hardware::GPU { extern Register<0x0810> Data; extern Register<0x0814> Ctrl; -} +} // namespace psyqo::Hardware::GPU diff --git a/src/mips/psyqo/hardware/hwregs.hh b/src/mips/psyqo/hardware/hwregs.hh index 9d1e8741ea..a6c186b1b0 100644 --- a/src/mips/psyqo/hardware/hwregs.hh +++ b/src/mips/psyqo/hardware/hwregs.hh @@ -41,7 +41,8 @@ struct BasicAccess { static volatile T* accessPtr(int index = 0) { return reinterpret_cast(BaseAddress + offset + index); } }; -template > +template > struct Register { static constexpr uint32_t BaseAddress = writeQueue == WriteQueue::Use ? 0x1f801000 : 0xbf801000; void throwAway() const { *Access::accessPtr(); } @@ -158,7 +159,7 @@ struct Register { bool operator>=(T value) const { return access() >= value; } T operator[](int index) const { return access(index); } - volatile T & access(int index = 0) const { return Access::access(index); } + volatile T& access(int index = 0) const { return Access::access(index); } }; -} +} // namespace psyqo::Hardware diff --git a/src/mips/psyqo/hardware/sbus.hh b/src/mips/psyqo/hardware/sbus.hh index 602b9f05c0..91530d8f04 100644 --- a/src/mips/psyqo/hardware/sbus.hh +++ b/src/mips/psyqo/hardware/sbus.hh @@ -34,4 +34,4 @@ extern Register<0x0014> Dev4Ctrl; extern Register<0x0018> Dev5Ctrl; extern Register<0x0020> ComCtrl; -} +} // namespace psyqo::Hardware::SBus diff --git a/src/mips/psyqo/primitives/lines.hh b/src/mips/psyqo/primitives/lines.hh index c5782e084d..29e8cef2ce 100644 --- a/src/mips/psyqo/primitives/lines.hh +++ b/src/mips/psyqo/primitives/lines.hh @@ -26,9 +26,8 @@ SOFTWARE. #pragma once -#include - #include +#include #include "psyqo/primitives/common.hh" @@ -161,7 +160,7 @@ struct PolyLineEnd { * @tparam N The number of segments in the polyline. */ -template +template struct PolyLine { PolyLine() : command(0x48000000) {} PolyLine(Color c) : command(0x48000000 | c.packed) {} diff --git a/src/mips/psyqo/trigonometry.hh b/src/mips/psyqo/trigonometry.hh index ad990be4af..3a4ec6808d 100644 --- a/src/mips/psyqo/trigonometry.hh +++ b/src/mips/psyqo/trigonometry.hh @@ -26,9 +26,9 @@ SOFTWARE. #pragma once +#include #include -#include #include "psyqo/fixed-point.hh" namespace psyqo { @@ -51,7 +51,7 @@ namespace trig_literals { /** * @brief A user-defined literal for angle values. - * + * * @param angle The angle in fractions of Pi. * @return consteval Angle The constructed angle. */ @@ -77,7 +77,7 @@ class Trig { /** * @brief Calculate the cosine of an angle. - * + * * @param a The angle to calculate the cosine of. * @return FixedPoint The cosine of the angle. */ @@ -106,7 +106,7 @@ class Trig { /** * @brief Calculate the sine of an angle. - * + * * @param a The angle to calculate the sine of. * @return FixedPoint The sine of the angle. */ diff --git a/src/mips/psyqo/vector.hh b/src/mips/psyqo/vector.hh index 771542ad01..a2e9b20524 100644 --- a/src/mips/psyqo/vector.hh +++ b/src/mips/psyqo/vector.hh @@ -31,7 +31,7 @@ namespace psyqo { struct Vec2 { FixedPoint<> x, y; - operator Vertex() const { return {{ .x = x.integer(), .y = y.integer() }}; } + operator Vertex() const { return {{.x = x.integer(), .y = y.integer()}}; } }; struct Vec3 { diff --git a/src/mips/ucl-demo/compress.lua b/src/mips/ucl-demo/compress.lua index 5afe87cf55..fd85890489 100644 --- a/src/mips/ucl-demo/compress.lua +++ b/src/mips/ucl-demo/compress.lua @@ -14,7 +14,6 @@ -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - local ffi = require('ffi') -- This file can be used as a library to compress assets using the UCL library. @@ -33,11 +32,11 @@ local ffi = require('ffi') function compress(input, output) local ownInput = false local ownOutput = false - if type(input) == "string" then + if type(input) == 'string' then input = Support.File.open(input) ownInput = true end - if type(output) == "string" then + if type(output) == 'string' then output = Support.File.open(output, 'TRUNCATE') ownOutput = true end @@ -67,11 +66,7 @@ function compress(input, output) -- Write the compressed data. output:write(compressed:read(compressedSize)) - if ownInput then - input:close() - end + if ownInput then input:close() end - if ownOutput then - output:close() - end + if ownOutput then output:close() end end diff --git a/src/spu/debug.cc b/src/spu/debug.cc index 5d7b195668..630f4de928 100644 --- a/src/spu/debug.cc +++ b/src/spu/debug.cc @@ -134,7 +134,8 @@ void PCSX::SPU::impl::debug() { } ImGui::NextColumn(); { - ImGui::TextUnformatted(_("Start pos:\nCurr pos:\nLoop pos:\n\nRight vol:\nLeft vol:\n\nAct freq:\nUsed freq:")); + ImGui::TextUnformatted( + _("Start pos:\nCurr pos:\nLoop pos:\n\nRight vol:\nLeft vol:\n\nAct freq:\nUsed freq:")); ImGui::SameLine(); ImGui::Text("%li\n%li\n%li\n\n%6i %04x\n%6i %04x\n\n%i\n%i", ch.pStart - spuMemC, ch.pCurr - spuMemC, ch.pLoop - spuMemC, ch.data.get().value, diff --git a/src/spu/miniaudio.cc b/src/spu/miniaudio.cc index a7497fe908..b67f045891 100644 --- a/src/spu/miniaudio.cc +++ b/src/spu/miniaudio.cc @@ -197,22 +197,22 @@ void PCSX::SPU::MiniAudio::callback(ma_device* device, float* output, ma_uint32 } } - for (ma_uint32 f = 0; f < frameCount; f++) { - float l = 0.0f, r = 0.0f; - for (unsigned i = 0; i < STREAMS; i++) { - l += static_cast(buffers[i][f].L) / static_cast(std::numeric_limits::max()); - r += static_cast(buffers[i][f].R) / static_cast(std::numeric_limits::max()); - } + for (ma_uint32 f = 0; f < frameCount; f++) { + float l = 0.0f, r = 0.0f; + for (unsigned i = 0; i < STREAMS; i++) { + l += static_cast(buffers[i][f].L) / static_cast(std::numeric_limits::max()); + r += static_cast(buffers[i][f].R) / static_cast(std::numeric_limits::max()); + } - if (mono) { - const float lr = (l+r)*0.5f; - output[f * 2 + 0] = lr; - output[f * 2 + 1] = lr; - } else { - output[f * 2 + 0] = l; - output[f * 2 + 1] = r; - } + if (mono) { + const float lr = (l + r) * 0.5f; + output[f * 2 + 0] = lr; + output[f * 2 + 1] = lr; + } else { + output[f * 2 + 0] = l; + output[f * 2 + 1] = r; } + } if (m_settings.get()) return; diff --git a/src/support/opengl.h b/src/support/opengl.h index e539342b02..cd0ae9927d 100644 --- a/src/support/opengl.h +++ b/src/support/opengl.h @@ -73,7 +73,9 @@ struct VertexArray { } } - ~VertexArray() { if (exists()) glDeleteVertexArrays(1, &m_handle); } + ~VertexArray() { + if (exists()) glDeleteVertexArrays(1, &m_handle); + } GLuint handle() { return m_handle; } bool exists() { return m_handle != 0; } void bind() { glBindVertexArray(m_handle); } @@ -172,7 +174,9 @@ struct Texture { create(width, height, internalFormat, GL_TEXTURE_2D_MULTISAMPLE, samples); } - ~Texture() { if (exists()) glDeleteTextures(1, &m_handle); } + ~Texture() { + if (exists()) glDeleteTextures(1, &m_handle); + } GLuint handle() { return m_handle; } bool exists() { return m_handle != 0; } void bind() { glBindTexture(m_binding, m_handle); } @@ -199,7 +203,9 @@ struct Framebuffer { } } - ~Framebuffer() { if (exists()) glDeleteFramebuffers(1, &m_handle); } + ~Framebuffer() { + if (exists()) glDeleteFramebuffers(1, &m_handle); + } GLuint handle() { return m_handle; } bool exists() { return m_handle != 0; } void bind(GLenum target) { glBindFramebuffer(target, m_handle); } @@ -243,7 +249,9 @@ enum ShaderType { struct Shader { Shader() {} Shader(const std::string_view source, ShaderType type) { create(source, static_cast(type)); } - ~Shader() { if (exists()) glDeleteShader(m_handle); } + ~Shader() { + if (exists()) glDeleteShader(m_handle); + } // Returns whether compilation failed or not Status create(const std::string_view source, GLenum type) { @@ -344,7 +352,9 @@ struct VertexBuffer { } } - ~VertexBuffer() { if (exists()) glDeleteBuffers(1, &m_handle); } + ~VertexBuffer() { + if (exists()) glDeleteBuffers(1, &m_handle); + } GLuint handle() { return m_handle; } bool exists() { return m_handle != 0; } void bind() { glBindBuffer(GL_ARRAY_BUFFER, m_handle); } diff --git a/src/support/polyfills.h b/src/support/polyfills.h index f624dba01c..0d9261a4f5 100644 --- a/src/support/polyfills.h +++ b/src/support/polyfills.h @@ -1,53 +1,53 @@ -/*************************************************************************** - * Copyright (C) 2023 PCSX-Redux authors * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - ***************************************************************************/ - -#pragma once - -#include -#include -#include - -namespace PCSX { - -namespace PolyFill { - -// MacOS / AppleClang is bad. -template -concept IntegralConcept = std::is_integral::value; - -template -static constexpr T byteSwap(T val) { -#if defined(__cpp_lib_byteswap) && (__cpp_lib_byteswap >= 202110L) - return std::byteswap(val); -#else - if constexpr (sizeof(T) == 1) { - return val; - } else { - T ret = 0; - for (size_t i = 0; i < sizeof(T); i++) { - ret |= static_cast(static_cast(val >> (i * 8)) << ((sizeof(T) - i - 1) * 8)); - } - return ret; - } -#endif -} - -} - -} +/*************************************************************************** + * Copyright (C) 2023 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#pragma once + +#include +#include +#include + +namespace PCSX { + +namespace PolyFill { + +// MacOS / AppleClang is bad. +template +concept IntegralConcept = std::is_integral::value; + +template +static constexpr T byteSwap(T val) { +#if defined(__cpp_lib_byteswap) && (__cpp_lib_byteswap >= 202110L) + return std::byteswap(val); +#else + if constexpr (sizeof(T) == 1) { + return val; + } else { + T ret = 0; + for (size_t i = 0; i < sizeof(T); i++) { + ret |= static_cast(static_cast(val >> (i * 8)) << ((sizeof(T) - i - 1) * 8)); + } + return ret; + } +#endif +} + +} // namespace PolyFill + +} // namespace PCSX diff --git a/src/support/slice.h b/src/support/slice.h index db8ed37a9c..93df6699f5 100644 --- a/src/support/slice.h +++ b/src/support/slice.h @@ -120,9 +120,7 @@ class Slice { memcpy(dest, data, size); } void acquire(std::string &&str) { m_data = std::move(str); } - void acquire(void *data, uint32_t size) { - m_data = Owned{size, data}; - } + void acquire(void *data, uint32_t size) { m_data = Owned{size, data}; } void borrow(const Slice &other, uint32_t from = 0, uint32_t amount = std::numeric_limits::max()) { const uint8_t *ptr = static_cast(other.data()); uint32_t size = other.size(); diff --git a/src/support/uvfile.h b/src/support/uvfile.h index d61b4177f9..a5fb003a1d 100644 --- a/src/support/uvfile.h +++ b/src/support/uvfile.h @@ -146,9 +146,8 @@ class UvFile : public File, public UvThreadOp { virtual bool eof() final override; virtual std::filesystem::path filename() final override { return m_filename; } virtual File* dup() final override { - return m_download ? new UvFile(m_filename.string(), DOWNLOAD_URL) - : writable() ? new UvFile(m_filename, FileOps::READWRITE) - : new UvFile(m_filename); + return m_download ? new UvFile(m_filename.string(), DOWNLOAD_URL) + : writable() ? new UvFile(m_filename, FileOps::READWRITE) : new UvFile(m_filename); } // Open the file in read-only mode. diff --git a/src/supportpsx/assembler/assembler.lua b/src/supportpsx/assembler/assembler.lua index d0919c416e..2e8e25b785 100644 --- a/src/supportpsx/assembler/assembler.lua +++ b/src/supportpsx/assembler/assembler.lua @@ -15,71 +15,54 @@ -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -local bit = require("bit") +local bit = require('bit') PCSX.Assembler = {} PCSX.Assembler.Internals = {} PCSX.Assembler.Internals.checks = {} PCSX.Assembler.Internals.checks.imm26 = function(imm, place) - if type(imm) == "number" then - if (imm % 4) ~= 0 then - error("Immediate must be a multiple of 4: " .. imm) - end + if type(imm) == 'number' then + if (imm % 4) ~= 0 then error('Immediate must be a multiple of 4: ' .. imm) end imm = imm / 4 - if imm < 0 or imm > 0x3ffffff then - error("Immediate out of range: " .. imm) - end - return imm - end - if type(imm) == "string" then + if imm < 0 or imm > 0x3ffffff then error('Immediate out of range: ' .. imm) end return imm end - error("Argument " .. place .. " must be a number or a label") + if type(imm) == 'string' then return imm end + error('Argument ' .. place .. ' must be a number or a label') end PCSX.Assembler.Internals.checks.imm20 = function(imm, place) - if type(imm) == "number" then - if imm < 0 or imm > 0xfffff then - error("Immediate out of range: " .. imm) - end + if type(imm) == 'number' then + if imm < 0 or imm > 0xfffff then error('Immediate out of range: ' .. imm) end return imm end - error("Argument " .. place .. " must be a number") + error('Argument ' .. place .. ' must be a number') end PCSX.Assembler.Internals.checks.bimm16 = function(imm, place) - if type(imm) == "number" then - if imm < -0x8000 or imm > 0x7fff then - error("Immediate out of range: " .. imm) - end + if type(imm) == 'number' then + if imm < -0x8000 or imm > 0x7fff then error('Immediate out of range: ' .. imm) end return imm end - if type(imm) == "string" then - return imm - end - error("Argument " .. place .. " must be a number or a label") + if type(imm) == 'string' then return imm end + error('Argument ' .. place .. ' must be a number or a label') end PCSX.Assembler.Internals.checks.imm16 = function(imm, place) - if type(imm) == "number" then - if imm < -0x8000 or imm > 0xffff then - error("Immediate out of range: " .. imm) - end + if type(imm) == 'number' then + if imm < -0x8000 or imm > 0xffff then error('Immediate out of range: ' .. imm) end return imm end - error("Argument " .. place .. " must be a number") + error('Argument ' .. place .. ' must be a number') end PCSX.Assembler.Internals.checks.imm5 = function(imm, place) - if type(imm) == "number" then - if imm < 0 or imm > 0x1f then - error("Immediate out of range: " .. imm) - end + if type(imm) == 'number' then + if imm < 0 or imm > 0x1f then error('Immediate out of range: ' .. imm) end return imm end - error("Argument " .. place .. " must be a number") + error('Argument ' .. place .. ' must be a number') end PCSX.Assembler.New = function() @@ -87,106 +70,76 @@ PCSX.Assembler.New = function() local ret = code.base local hi16 = code.hi16 if hi16 then - if type(hi16) == "string" then + if type(hi16) == 'string' then local symbol = PCSX.Assembler.Internals.resolveSymbol(hi16) - if not symbol then - error("Unknown symbol: " .. hi16) - end + if not symbol then error('Unknown symbol: ' .. hi16) end hi16 = symbol.address end ret = bit.bor(ret, bit.rshift(hi16, 16)) - if (bit.band(hi16, 0x8000) ~= 0) then - ret = ret + 1 - end + if (bit.band(hi16, 0x8000) ~= 0) then ret = ret + 1 end end local lo16 = code.lo16 if lo16 then - if type(lo16) == "string" then + if type(lo16) == 'string' then local symbol = PCSX.Assembler.Internals.resolveSymbol(lo16) - if not symbol then - error("Unknown symbol: " .. lo16) - end + if not symbol then error('Unknown symbol: ' .. lo16) end lo16 = symbol.address end ret = bit.bor(ret, bit.band(lo16, 16)) end local imm26 = code.imm26 if imm26 then - if type(imm26) == "string" then + if type(imm26) == 'string' then local symbol = PCSX.Assembler.Internals.resolveSymbol(imm26) - if not symbol then - error("Unknown symbol: " .. imm26) - end + if not symbol then error('Unknown symbol: ' .. imm26) end if (symbol.address % 4) ~= 0 then - error("Jump address must be a multiple of 4: " .. imm26) + error('Jump address must be a multiple of 4: ' .. imm26) end if (bit.band(0xfc000000, bit.bxor(symbol.address, baseAddress)) ~= 0) then - error("Jump address out of range: " .. imm26) + error('Jump address out of range: ' .. imm26) end imm26 = bit.band(symbol.address / 4, 0x3ffffff) end ret = bit.bor(ret, imm26) end - if code.imm16 then - ret = bit.bor(ret, bit.band(code.imm16, 0xffff)) - end + if code.imm16 then ret = bit.bor(ret, bit.band(code.imm16, 0xffff)) end local bimm16 = code.bimm16 if bimm16 then - if type(bimm16) == "string" then + if type(bimm16) == 'string' then local address = baseAddress if bimm16:sub(1, 1) == '@' then address = tonumber(bimm16:sub(2)) else local symbol = PCSX.Assembler.Internals.resolveSymbol(bimm16) - if not symbol then - error("Unknown symbol: " .. bimm16) - end + if not symbol then error('Unknown symbol: ' .. bimm16) end address = symbol.address end - if (address % 4) ~= 0 then - error("Branch address must be a multiple of 4: " .. bimm16) - end + if (address % 4) ~= 0 then error('Branch address must be a multiple of 4: ' .. bimm16) end local offset = (address - baseAddress - 4) / 4 - if offset < -0x8000 or offset > 0x7fff then - error("Branch out of range: " .. bimm16) - end + if offset < -0x8000 or offset > 0x7fff then error('Branch out of range: ' .. bimm16) end bimm16 = offset end ret = bit.bor(ret, bit.band(bimm16, 0xffff)) end - if code.imm5 then - ret = bit.bor(ret, bit.lshift(code.imm5, 6)) - end - if code.imm20 then - ret = bit.bor(ret, bit.lshift(code.imm20, 6)) - end - if code.rs then - ret = bit.bor(ret, bit.lshift(code.rs, 21)) - end - if code.rt then - ret = bit.bor(ret, bit.lshift(code.rt, 16)) - end - if code.rd then - ret = bit.bor(ret, bit.lshift(code.rd, 11)) - end + if code.imm5 then ret = bit.bor(ret, bit.lshift(code.imm5, 6)) end + if code.imm20 then ret = bit.bor(ret, bit.lshift(code.imm20, 6)) end + if code.rs then ret = bit.bor(ret, bit.lshift(code.rs, 21)) end + if code.rt then ret = bit.bor(ret, bit.lshift(code.rt, 16)) end + if code.rd then ret = bit.bor(ret, bit.lshift(code.rd, 11)) end return ret end local function split(str, sep) local ret = {} - for str in string.gmatch(str, "([^" .. sep .. "]+)") do - table.insert(ret, str) - end + for str in string.gmatch(str, '([^' .. sep .. ']+)') do table.insert(ret, str) end return ret end - local function trim(str) - return string.gsub(str, "^%s*(.-)%s*$", "%1") - end + local function trim(str) return string.gsub(str, '^%s*(.-)%s*$', '%1') end local function parseOneString(self, line) - local parts = split(line, " \\(\\),") + local parts = split(line, ' \\(\\),') local args = {} for _, v in ipairs(parts) do v = trim(v) - if v ~= "" then + if v ~= '' then local maybeNumber = tonumber(v) if maybeNumber == nil then table.insert(args, v) @@ -202,12 +155,10 @@ PCSX.Assembler.New = function() local assembler = { __code = {}, parse = function(self, code) - local lines = split(code, "\n") + local lines = split(code, '\n') for _, v in ipairs(lines) do v = trim(v) - if v ~= "" then - parseOneString(self, v) - end + if v ~= '' then parseOneString(self, v) end end return self end, @@ -233,16 +184,10 @@ PCSX.Assembler.New = function() return self end, compileToFile = function(self, file, baseAddress, fileStartAddress) - if type(file) ~= 'table' or file._type ~= 'File' then - error("Invalid first argument: not a file") - end - if type(baseAddress) ~= "number" then - error("Invalid second argument: not a number") - end + if type(file) ~= 'table' or file._type ~= 'File' then error('Invalid first argument: not a file') end + if type(baseAddress) ~= 'number' then error('Invalid second argument: not a number') end if fileStartAddress == nil then fileStartAddress = 0 end - if type(fileStartAddress) ~= "number" then - error("Invalid third argument: not a number") - end + if type(fileStartAddress) ~= 'number' then error('Invalid third argument: not a number') end local offset = baseAddress - fileStartAddress for _, v in ipairs(self.__code) do local compiled = compileOne(v, baseAddress) @@ -254,14 +199,10 @@ PCSX.Assembler.New = function() end, } local wrapper = function(self, f, name, args) - if #args ~= 1 or type(args[1]) ~= "table" then - error("Invalid arguments for instruction " .. name) - end + if #args ~= 1 or type(args[1]) ~= 'table' then error('Invalid arguments for instruction ' .. name) end local ret = f(table.unpack(args)) - if type(ret) == "table" and type(ret[1]) == "table" then - for _, v in ipairs(ret) do - table.insert(self.__code, v) - end + if type(ret) == 'table' and type(ret[1]) == 'table' then + for _, v in ipairs(ret) do table.insert(self.__code, v) end else table.insert(self.__code, ret) end @@ -270,35 +211,21 @@ PCSX.Assembler.New = function() local meta = { __index = function(self, key) local instr = PCSX.Assembler.Internals.simpleInstructions[key] - if instr then - return function(...) return wrapper(self, instr, key, { ... }) end - end + if instr then return function(...) return wrapper(self, instr, key, { ... }) end end instr = PCSX.Assembler.Internals.loadAndStoreInstructions[key] - if instr then - return function(...) return wrapper(self, instr, key, { ... }) end - end + if instr then return function(...) return wrapper(self, instr, key, { ... }) end end instr = PCSX.Assembler.Internals.specialInstructions[key] - if instr then - return function(...) return wrapper(self, instr, key, { ... }) end - end + if instr then return function(...) return wrapper(self, instr, key, { ... }) end end instr = PCSX.Assembler.Internals.bcondInstructions[key] - if instr then - return function(...) return wrapper(self, instr, key, { ... }) end - end + if instr then return function(...) return wrapper(self, instr, key, { ... }) end end instr = PCSX.Assembler.Internals.cop0Instructions[key] - if instr then - return function(...) return wrapper(self, instr, key, { ... }) end - end + if instr then return function(...) return wrapper(self, instr, key, { ... }) end end instr = PCSX.Assembler.Internals.gteInstructions[key] - if instr then - return function(...) return wrapper(self, instr, key, { ... }) end - end + if instr then return function(...) return wrapper(self, instr, key, { ... }) end end instr = PCSX.Assembler.Internals.pseudoInstructions[key] - if instr then - return function(...) return wrapper(self, instr, key, { ... }) end - end - error("Unknown instruction " .. key) - end + if instr then return function(...) return wrapper(self, instr, key, { ... }) end end + error('Unknown instruction ' .. key) + end, } setmetatable(assembler, meta) return assembler diff --git a/src/supportpsx/assembler/extra.lua b/src/supportpsx/assembler/extra.lua index 8b2ab64857..b7c4ab6398 100644 --- a/src/supportpsx/assembler/extra.lua +++ b/src/supportpsx/assembler/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. - local checkBImm16 = PCSX.Assembler.Internals.checks.bimm16 local checkGPR = PCSX.Assembler.Internals.checks.gpr local checkImm5 = PCSX.Assembler.Internals.checks.imm5 @@ -24,463 +23,196 @@ local checkCOP0 = PCSX.Assembler.Internals.checks.cop0 PCSX.Assembler.Internals.specialInstructions = { sll = function(args) - if #args < 2 or #args > 3 then - error("sll takes two or three arguments") - end + if #args < 2 or #args > 3 then error('sll takes two or three arguments') end if #args == 2 then - return { - base = 0x00000000, - rd = checkGPR(args[1]), - rt = checkGPR(args[1]), - imm5 = checkImm5(args[2], 2), - } + return { base = 0x00000000, rd = checkGPR(args[1]), rt = checkGPR(args[1]), imm5 = checkImm5(args[2], 2) } end - return { - base = 0x00000000, - rd = checkGPR(args[1]), - rt = checkGPR(args[2]), - imm5 = checkImm5(args[3], 3), - } + return { base = 0x00000000, rd = checkGPR(args[1]), rt = checkGPR(args[2]), imm5 = checkImm5(args[3], 3) } end, srl = function(args) - if #args < 2 or #args > 3 then - error("srl takes two or three arguments") - end + if #args < 2 or #args > 3 then error('srl takes two or three arguments') end if #args == 2 then - return { - base = 0x00000002, - rd = checkGPR(args[1]), - rt = checkGPR(args[1]), - imm5 = checkImm5(args[2], 2), - } + return { base = 0x00000002, rd = checkGPR(args[1]), rt = checkGPR(args[1]), imm5 = checkImm5(args[2], 2) } end - return { - base = 0x00000002, - rd = checkGPR(args[1]), - rt = checkGPR(args[2]), - imm5 = checkImm5(args[3], 3), - } + return { base = 0x00000002, rd = checkGPR(args[1]), rt = checkGPR(args[2]), imm5 = checkImm5(args[3], 3) } end, sra = function(args) - if #args < 2 or #args > 3 then - error("sra takes two or three arguments") - end + if #args < 2 or #args > 3 then error('sra takes two or three arguments') end if #args == 2 then - return { - base = 0x00000003, - rd = checkGPR(args[1]), - rt = checkGPR(args[1]), - imm5 = checkImm5(args[2], 2), - } + return { base = 0x00000003, rd = checkGPR(args[1]), rt = checkGPR(args[1]), imm5 = checkImm5(args[2], 2) } end - return { - base = 0x00000003, - rd = checkGPR(args[1]), - rt = checkGPR(args[2]), - imm5 = checkImm5(args[3], 3), - - } + return { base = 0x00000003, rd = checkGPR(args[1]), rt = checkGPR(args[2]), imm5 = checkImm5(args[3], 3) } end, sllv = function(args) - if #args < 2 or #args > 3 then - error("sllv takes two or three arguments") - end + if #args < 2 or #args > 3 then error('sllv takes two or three arguments') end if #args == 2 then - return { - base = 0x00000004, - rd = checkGPR(args[1]), - rt = checkGPR(args[1]), - imm5 = checkImm5(args[2], 2), - } + return { base = 0x00000004, rd = checkGPR(args[1]), rt = checkGPR(args[1]), imm5 = checkImm5(args[2], 2) } end - return { - base = 0x00000004, - rd = checkGPR(args[1]), - rt = checkGPR(args[2]), - imm5 = checkImm5(args[3], 3), - } + return { base = 0x00000004, rd = checkGPR(args[1]), rt = checkGPR(args[2]), imm5 = checkImm5(args[3], 3) } end, srlv = function(args) - if #args < 2 or #args > 3 then - error("srlv takes two or three arguments") - end + if #args < 2 or #args > 3 then error('srlv takes two or three arguments') end if #args == 2 then - return { - base = 0x00000006, - rd = checkGPR(args[1]), - rt = checkGPR(args[1]), - imm5 = checkImm5(args[2], 2), - } + return { base = 0x00000006, rd = checkGPR(args[1]), rt = checkGPR(args[1]), imm5 = checkImm5(args[2], 2) } end - return { - base = 0x00000006, - rd = checkGPR(args[1]), - rt = checkGPR(args[2]), - imm5 = checkImm5(args[3], 3), - } + return { base = 0x00000006, rd = checkGPR(args[1]), rt = checkGPR(args[2]), imm5 = checkImm5(args[3], 3) } end, srav = function(args) - if #args < 2 or #args > 3 then - error("srav takes two or three arguments") - end + if #args < 2 or #args > 3 then error('srav takes two or three arguments') end if #args == 2 then - return { - base = 0x00000007, - rd = checkGPR(args[1]), - rt = checkGPR(args[1]), - imm5 = checkImm5(args[2], 2), - } + return { base = 0x00000007, rd = checkGPR(args[1]), rt = checkGPR(args[1]), imm5 = checkImm5(args[2], 2) } end - return { - base = 0x00000007, - rd = checkGPR(args[1]), - rt = checkGPR(args[2]), - imm5 = checkImm5(args[3], 3), - } + return { base = 0x00000007, rd = checkGPR(args[1]), rt = checkGPR(args[2]), imm5 = checkImm5(args[3], 3) } end, jr = function(args) - if #args ~= 1 then - error("jr takes one argument") - end - return { - base = 0x00000008, - rs = checkGPR(args[1]), - } + if #args ~= 1 then error('jr takes one argument') end + return { base = 0x00000008, rs = checkGPR(args[1]) } end, jalr = function(args) - if #args < 1 or #args > 2 then - error("jalr takes one or two arguments") - end - if #args == 1 then - return { - base = 0x00000009, - rs = checkGPR(args[1]), - rd = 31, - } - end - return { - base = 0x00000009, - rs = checkGPR(args[1]), - rd = checkGPR(args[2]), - } + if #args < 1 or #args > 2 then error('jalr takes one or two arguments') end + if #args == 1 then return { base = 0x00000009, rs = checkGPR(args[1]), rd = 31 } end + return { base = 0x00000009, rs = checkGPR(args[1]), rd = checkGPR(args[2]) } end, syscall = function(args) - if #args > 1 then - error("syscall takes one or no arguments") - end - if #args == 1 then - return { - base = 0x0000000c, - imm20 = checkImm20(args[1]) - } - end - return { - base = 0x0000000c - } + if #args > 1 then error('syscall takes one or no arguments') end + if #args == 1 then return { base = 0x0000000c, imm20 = checkImm20(args[1]) } end + return { base = 0x0000000c } end, break_ = function(args) - if #args > 1 then - error("break takes one or no arguments") - end - if #args == 1 then - return { - base = 0x0000000d, - imm20 = checkImm20(args[1]) - } - end - return { - base = 0x0000000d - } + if #args > 1 then error('break takes one or no arguments') end + if #args == 1 then return { base = 0x0000000d, imm20 = checkImm20(args[1]) } end + return { base = 0x0000000d } end, mfhi = function(args) - if #args ~= 1 then - error("mfhi takes one argument") - end - return { - base = 0x00000010, - rd = checkGPR(args[1]), - } + if #args ~= 1 then error('mfhi takes one argument') end + return { base = 0x00000010, rd = checkGPR(args[1]) } end, mthi = function(args) - if #args ~= 1 then - error("mthi takes one argument") - end - return { - base = 0x00000011, - rs = checkGPR(args[1]), - } + if #args ~= 1 then error('mthi takes one argument') end + return { base = 0x00000011, rs = checkGPR(args[1]) } end, mflo = function(args) - if #args ~= 1 then - error("mflo takes one argument") - end - return { - base = 0x00000012, - rd = checkGPR(args[1]), - } + if #args ~= 1 then error('mflo takes one argument') end + return { base = 0x00000012, rd = checkGPR(args[1]) } end, mtlo = function(args) - if #args ~= 1 then - error("mtlo takes one argument") - end - return { - base = 0x00000013, - rs = checkGPR(args[1]), - } + if #args ~= 1 then error('mtlo takes one argument') end + return { base = 0x00000013, rs = checkGPR(args[1]) } end, mult = function(args) - if #args ~= 2 then - error("mult takes two arguments") - end - return { - base = 0x00000018, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + if #args ~= 2 then error('mult takes two arguments') end + return { base = 0x00000018, rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end, multu = function(args) - if #args ~= 2 then - error("multu takes two arguments") - end - return { - base = 0x00000019, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + if #args ~= 2 then error('multu takes two arguments') end + return { base = 0x00000019, rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end, div = function(args) - if #args ~= 2 then - error("div takes two arguments") - end - return { - base = 0x0000001a, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + if #args ~= 2 then error('div takes two arguments') end + return { base = 0x0000001a, rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end, divu = function(args) - if #args ~= 2 then - error("divu takes two arguments") - end - return { - base = 0x0000001b, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + if #args ~= 2 then error('divu takes two arguments') end + return { base = 0x0000001b, rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end, add = function(args) - if #args ~= 3 then - error("add takes three arguments") - end - return { - base = 0x00000020, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + if #args ~= 3 then error('add takes three arguments') end + return { base = 0x00000020, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, addu = function(args) - if #args < 2 or #args > 3 then - error("addu takes two or three arguments") - end + if #args < 2 or #args > 3 then error('addu takes two or three arguments') end if #args == 2 then - return { - base = 0x00000021, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x00000021, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x00000021, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x00000021, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, sub = function(args) - if #args < 2 or #args > 3 then - error("sub takes two or three arguments") - end + if #args < 2 or #args > 3 then error('sub takes two or three arguments') end if #args == 2 then - return { - base = 0x00000022, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x00000022, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x00000022, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x00000022, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, subu = function(args) - if #args < 2 or #args > 3 then - error("subu takes two or three arguments") - end + if #args < 2 or #args > 3 then error('subu takes two or three arguments') end if #args == 2 then - return { - base = 0x00000023, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x00000023, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x00000023, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x00000023, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, and_ = function(args) - if #args < 2 or #args > 3 then - error("and takes two or three arguments") - end + if #args < 2 or #args > 3 then error('and takes two or three arguments') end if #args == 2 then - return { - base = 0x00000024, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x00000024, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x00000024, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x00000024, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, or_ = function(args) - if #args < 2 or #args > 3 then - error("or takes two or three arguments") - end + if #args < 2 or #args > 3 then error('or takes two or three arguments') end if #args == 2 then - return { - base = 0x00000025, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x00000025, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x00000025, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x00000025, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, xor_ = function(args) - if #args < 2 or #args > 3 then - error("xor takes two or three arguments") - end + if #args < 2 or #args > 3 then error('xor takes two or three arguments') end if #args == 2 then - return { - base = 0x00000026, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x00000026, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x00000026, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x00000026, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, nor = function(args) - if #args < 2 or #args > 3 then - error("nor takes three arguments") - end + if #args < 2 or #args > 3 then error('nor takes three arguments') end if #args == 2 then - return { - base = 0x00000027, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x00000027, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x00000027, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x00000027, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, slt = function(args) - if #args < 2 or #args > 3 then - error("slt takes three arguments") - end + if #args < 2 or #args > 3 then error('slt takes three arguments') end if #args == 2 then - return { - base = 0x0000002a, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x0000002a, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x0000002a, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x0000002a, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, sltu = function(args) - if #args < 2 or #args > 3 then - error("sltu takes three arguments") - end + if #args < 2 or #args > 3 then error('sltu takes three arguments') end if #args == 2 then - return { - base = 0x0000002b, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - } + return { base = 0x0000002b, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = checkGPR(args[2]) } end - return { - base = 0x0000002b, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = checkGPR(args[3]), - } + return { base = 0x0000002b, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = checkGPR(args[3]) } end, } for k, v in pairs(PCSX.Assembler.Internals.specialInstructions) do - if k:sub(-1) == "_" then + if k:sub(-1) == '_' then local newKey = k:sub(1, -2) PCSX.Assembler.Internals.specialInstructions[newKey] = v PCSX.Assembler.Internals.specialInstructions[k] = nil @@ -489,80 +221,40 @@ end PCSX.Assembler.Internals.bcondInstructions = { bltz = function(args) - if #args ~= 2 then - error("bltz takes two arguments") - end - return { - base = 0x04000000, - rs = checkGPR(args[1]), - bimm16 = checkBImm16(args[2], 2), - } + if #args ~= 2 then error('bltz takes two arguments') end + return { base = 0x04000000, rs = checkGPR(args[1]), bimm16 = checkBImm16(args[2], 2) } end, bgez = function(args) - if #args ~= 2 then - error("bgez takes two arguments") - end - return { - base = 0x04010000, - rs = checkGPR(args[1]), - bimm16 = checkBImm16(args[2], 2), - } + if #args ~= 2 then error('bgez takes two arguments') end + return { base = 0x04010000, rs = checkGPR(args[1]), bimm16 = checkBImm16(args[2], 2) } end, bltzal = function(args) - if #args ~= 2 then - error("bltzal takes two arguments") - end - return { - base = 0x04100000, - rs = checkGPR(args[1]), - bimm16 = checkBImm16(args[2], 2), - } + if #args ~= 2 then error('bltzal takes two arguments') end + return { base = 0x04100000, rs = checkGPR(args[1]), bimm16 = checkBImm16(args[2], 2) } end, bgezal = function(args) - if #args ~= 2 then - error("bgezal takes two arguments") - end - return { - base = 0x04110000, - rs = checkGPR(args[1]), - bimm16 = checkBImm16(args[2], 2), - } + if #args ~= 2 then error('bgezal takes two arguments') end + return { base = 0x04110000, rs = checkGPR(args[1]), bimm16 = checkBImm16(args[2], 2) } end, } PCSX.Assembler.Internals.cop0Instructions = { mfc0 = function(args) - if #args ~= 2 then - error("mfc0 takes two arguments") - end - return { - base = 0x40000000, - rt = checkGPR(args[1]), - rd = checkCOP0(args[2]), - } + if #args ~= 2 then error('mfc0 takes two arguments') end + return { base = 0x40000000, rt = checkGPR(args[1]), rd = checkCOP0(args[2]) } end, mtc0 = function(args) - if #args ~= 2 then - error("mtc0 takes two arguments") - end - return { - base = 0x40800000, - rt = checkGPR(args[1]), - rd = checkCOP0(args[2]), - } + if #args ~= 2 then error('mtc0 takes two arguments') end + return { base = 0x40800000, rt = checkGPR(args[1]), rd = checkCOP0(args[2]) } end, rfe = function(args) - if #args ~= 0 then - error("rfe takes no arguments") - end - return { - base = 0x42000010, - } + if #args ~= 0 then error('rfe takes no arguments') end + return { base = 0x42000010 } end, } diff --git a/src/supportpsx/assembler/gte.lua b/src/supportpsx/assembler/gte.lua index a0f3dd3e69..db353dceb2 100644 --- a/src/supportpsx/assembler/gte.lua +++ b/src/supportpsx/assembler/gte.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. - local checkGPR = PCSX.Assembler.Internals.checks.gpr local checkImm16 = PCSX.Assembler.Internals.checks.imm16 local checkGTE0 = PCSX.Assembler.Internals.checks.gte0 @@ -23,269 +22,143 @@ local checkGTE1 = PCSX.Assembler.Internals.checks.gte1 PCSX.Assembler.Internals.gteInstructions = { mfc2 = function(args) - if #args ~= 2 then - error("mfc2 takes two arguments") - end - return { - base = 0x44000000, - rt = checkGPR(args[1]), - rd = checkGTE0(args[2]), - } + if #args ~= 2 then error('mfc2 takes two arguments') end + return { base = 0x44000000, rt = checkGPR(args[1]), rd = checkGTE0(args[2]) } end, mtc2 = function(args) - if #args ~= 2 then - error("mtc2 takes two arguments") - end - return { - base = 0x44800000, - rt = checkGPR(args[1]), - rd = checkGTE0(args[2]), - } + if #args ~= 2 then error('mtc2 takes two arguments') end + return { base = 0x44800000, rt = checkGPR(args[1]), rd = checkGTE0(args[2]) } end, cfc2 = function(args) - if #args ~= 2 then - error("cfc2 takes two arguments") - end - return { - base = 0x44c00000, - rt = checkGPR(args[1]), - rd = checkGTE1(args[2]), - } + if #args ~= 2 then error('cfc2 takes two arguments') end + return { base = 0x44c00000, rt = checkGPR(args[1]), rd = checkGTE1(args[2]) } end, ctc2 = function(args) - if #args ~= 2 then - error("ctc2 takes two arguments") - end - return { - base = 0x44e00000, - rt = checkGPR(args[1]), - rd = checkGTE1(args[2]), - } + if #args ~= 2 then error('ctc2 takes two arguments') end + return { base = 0x44e00000, rt = checkGPR(args[1]), rd = checkGTE1(args[2]) } end, lwc2 = function(args) - if #args ~= 3 then - error("lwc2 takes three arguments") - end - return { - base = 0xc4000000, - rt = checkGTE0(args[1]), - imm16 = checkImm16(args[2]), - rs = checkGPR(args[3]), - } + if #args ~= 3 then error('lwc2 takes three arguments') end + return { base = 0xc4000000, rt = checkGTE0(args[1]), imm16 = checkImm16(args[2]), rs = checkGPR(args[3]) } end, swc2 = function(args) - if #args ~= 3 then - error("swc2 takes three arguments") - end - return { - base = 0xe4000000, - rt = checkGTE0(args[1]), - imm16 = checkImm16(args[2]), - rs = checkGPR(args[3]), - } + if #args ~= 3 then error('swc2 takes three arguments') end + return { base = 0xe4000000, rt = checkGTE0(args[1]), imm16 = checkImm16(args[2]), rs = checkGPR(args[3]) } end, rtps = function(args) - if #args ~= 0 then - error("rtps takes no arguments") - end - return { - base = 0x4a180001, - } + if #args ~= 0 then error('rtps takes no arguments') end + return { base = 0x4a180001 } end, nclip = function(args) - if #args ~= 0 then - error("nclip takes no arguments") - end - return { - base = 0x4a180006, - } + if #args ~= 0 then error('nclip takes no arguments') end + return { base = 0x4a180006 } end, op = function(args) - if #args ~= 0 then - error("op takes no arguments") - end - return { - base = 0x4a18000c, - } + if #args ~= 0 then error('op takes no arguments') end + return { base = 0x4a18000c } end, dpcs = function(args) - if #args ~= 0 then - error("dpcs takes no arguments") - end - return { - base = 0x4a180010, - } + if #args ~= 0 then error('dpcs takes no arguments') end + return { base = 0x4a180010 } end, intpl = function(args) - if #args ~= 0 then - error("intpl takes no arguments") - end - return { - base = 0x4a180011, - } + if #args ~= 0 then error('intpl takes no arguments') end + return { base = 0x4a180011 } end, mvmva = function(args) - if #args ~= 0 then - error("mvmva takes no arguments") - end - return { - base = 0x4a180012, - } + if #args ~= 0 then error('mvmva takes no arguments') end + return { base = 0x4a180012 } end, ncds = function(args) - if #args ~= 0 then - error("ncds takes no arguments") - end - return { - base = 0x4a180013, - } + if #args ~= 0 then error('ncds takes no arguments') end + return { base = 0x4a180013 } end, cdp = function(args) - if #args ~= 0 then - error("cdp takes no arguments") - end - return { - base = 0x4a180014, - } + if #args ~= 0 then error('cdp takes no arguments') end + return { base = 0x4a180014 } end, ncdt = function(args) - if #args ~= 0 then - error("ncdt takes no arguments") - end - return { - base = 0x4a180016, - } + if #args ~= 0 then error('ncdt takes no arguments') end + return { base = 0x4a180016 } end, nccs = function(args) - if #args ~= 0 then - error("nccs takes no arguments") - end - return { - base = 0x4a18001b, - } + if #args ~= 0 then error('nccs takes no arguments') end + return { base = 0x4a18001b } end, cc = function(args) - if #args ~= 0 then - error("cc takes no arguments") - end - return { - base = 0x4a18001c, - } + if #args ~= 0 then error('cc takes no arguments') end + return { base = 0x4a18001c } end, ncs = function(args) - if #args ~= 0 then - error("ncs takes no arguments") - end - return { - base = 0x4a18001e, - } + if #args ~= 0 then error('ncs takes no arguments') end + return { base = 0x4a18001e } end, nct = function(args) - if #args ~= 0 then - error("nct takes no arguments") - end - return { - base = 0x4a180020, - } + if #args ~= 0 then error('nct takes no arguments') end + return { base = 0x4a180020 } end, sqr = function(args) - if #args ~= 0 then - error("sqr takes no arguments") - end - return { - base = 0x4a180028, - } + if #args ~= 0 then error('sqr takes no arguments') end + return { base = 0x4a180028 } end, dcpl = function(args) - if #args ~= 0 then - error("dcpl takes no arguments") - end - return { - base = 0x4a180029, - } + if #args ~= 0 then error('dcpl takes no arguments') end + return { base = 0x4a180029 } end, dpct = function(args) - if #args ~= 0 then - error("dpct takes no arguments") - end - return { - base = 0x4a18002a, - } + if #args ~= 0 then error('dpct takes no arguments') end + return { base = 0x4a18002a } end, avsz3 = function(args) - if #args ~= 0 then - error("avsz3 takes no arguments") - end - return { - base = 0x4a18002d, - } + if #args ~= 0 then error('avsz3 takes no arguments') end + return { base = 0x4a18002d } end, avsz4 = function(args) - if #args ~= 0 then - error("avsz4 takes no arguments") - end - return { - base = 0x4a18002e, - } + if #args ~= 0 then error('avsz4 takes no arguments') end + return { base = 0x4a18002e } end, rtpt = function(args) - if #args ~= 0 then - error("rtpt takes no arguments") - end - return { - base = 0x4a180030, - } + if #args ~= 0 then error('rtpt takes no arguments') end + return { base = 0x4a180030 } end, gpf = function(args) - if #args ~= 0 then - error("gpf takes no arguments") - end - return { - base = 0x4a18003d, - } + if #args ~= 0 then error('gpf takes no arguments') end + return { base = 0x4a18003d } end, gpl = function(args) - if #args ~= 0 then - error("gpl takes no arguments") - end - return { - base = 0x4a18003e, - } + if #args ~= 0 then error('gpl takes no arguments') end + return { base = 0x4a18003e } end, ncct = function(args) - if #args ~= 0 then - error("ncct takes no arguments") - end - return { - base = 0x4a18003f, - } + if #args ~= 0 then error('ncct takes no arguments') end + return { base = 0x4a18003f } end, } diff --git a/src/supportpsx/assembler/loadstore.lua b/src/supportpsx/assembler/loadstore.lua index 227afce365..35781c1034 100644 --- a/src/supportpsx/assembler/loadstore.lua +++ b/src/supportpsx/assembler/loadstore.lua @@ -15,465 +15,212 @@ -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - local checkImm16 = PCSX.Assembler.Internals.checks.imm16 local checkGPR = PCSX.Assembler.Internals.checks.gpr PCSX.Assembler.Internals.loadAndStoreInstructions = { lb = function(args) - if #args < 2 or #args > 3 then - error("lb takes two or three arguments") - end + if #args < 2 or #args > 3 then error('lb takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("lb takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('lb takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2], - }, - { - base = 0x80000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[1]), - }, + { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] }, + { base = 0x80000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[1]) }, } end - if type(args[2]) == "string" then - return { - base = 0x80000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0x80000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0x80000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0x80000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, lh = function(args) - if #args < 2 or #args > 3 then - error("lh takes two or three arguments") - end + if #args < 2 or #args > 3 then error('lh takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("lh takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('lh takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2], - }, - { - base = 0x84000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[1]), - }, + { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] }, + { base = 0x84000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[1]) }, } end - if type(args[2]) == "string" then - return { - base = 0x84000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0x84000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0x84000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0x84000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, lwl = function(args) - if #args < 2 or #args > 3 then - error("lwl takes two or three arguments") - end + if #args < 2 or #args > 3 then error('lwl takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("lwl takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('lwl takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2], - }, - { - base = 0x88000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[1]), - }, + { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] }, + { base = 0x88000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[1]) }, } end - if type(args[2]) == "string" then - return { - base = 0x88000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0x88000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0x88000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0x88000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, lw = function(args) - if #args < 2 or #args > 3 then - error("lw takes two or three arguments") - end + if #args < 2 or #args > 3 then error('lw takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("lw takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('lw takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2], - }, - { - base = 0x8c000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[1]), - }, + { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] }, + { base = 0x8c000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[1]) }, } end - if type(args[2]) == "string" then - return { - base = 0x8c000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0x8c000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0x8c000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0x8c000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, lbu = function(args) - if #args < 2 or #args > 3 then - error("lbu takes two or three arguments") - end + if #args < 2 or #args > 3 then error('lbu takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("lbu takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('lbu takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2], - }, - { - base = 0x90000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[1]), - }, + { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] }, + { base = 0x90000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[1]) }, } end - if type(args[2]) == "string" then - return { - base = 0x90000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0x90000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0x90000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0x90000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, lhu = function(args) - if #args < 2 or #args > 3 then - error("lhu takes two or three arguments") - end + if #args < 2 or #args > 3 then error('lhu takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("lhu takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('lhu takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2], - }, - { - base = 0x94000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[1]), - }, + { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] }, + { base = 0x94000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[1]) }, } end - if type(args[2]) == "string" then - return { - base = 0x94000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0x94000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0x94000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0x94000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, lwr = function(args) - if #args < 2 or #args > 3 then - error("lwr takes two or three arguments") - end + if #args < 2 or #args > 3 then error('lwr takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("lwr takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('lwr takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2], - }, - { - base = 0x98000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[1]), - }, + { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] }, + { base = 0x98000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[1]) }, } end - if type(args[2]) == "string" then - return { - base = 0x98000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0x98000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0x98000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0x98000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, sb = function(args) - if #args < 2 or #args > 3 then - error("sb takes two or three arguments") - end + if #args < 2 or #args > 3 then error('sb takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("sb takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('sb takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = 1, - hi16 = args[2], - }, - { - base = 0xa0000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = 1, - }, + { base = 0x3c000000, rt = 1, hi16 = args[2] }, + { base = 0xa0000000, rt = checkGPR(args[1]), lo16 = args[2], rs = 1 }, } end - if type(args[2]) == "string" then - return { - base = 0xa0000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0xa0000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0xa0000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0xa0000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, sh = function(args) - if #args < 2 or #args > 3 then - error("sh takes two or three arguments") - end + if #args < 2 or #args > 3 then error('sh takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("sh takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('sh takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = 1, - hi16 = args[2], - }, - { - base = 0xa4000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = 1, - }, + { base = 0x3c000000, rt = 1, hi16 = args[2] }, + { base = 0xa4000000, rt = checkGPR(args[1]), lo16 = args[2], rs = 1 }, } end - if type(args[2]) == "string" then - return { - base = 0xa4000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0xa4000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0xa4000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0xa4000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, swl = function(args) - if #args < 2 or #args > 3 then - error("swl takes two or three arguments") - end + if #args < 2 or #args > 3 then error('swl takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("swl takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('swl takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = 1, - hi16 = args[2], - }, - { - base = 0xa8000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = 1, - }, + { base = 0x3c000000, rt = 1, hi16 = args[2] }, + { base = 0xa8000000, rt = checkGPR(args[1]), lo16 = args[2], rs = 1 }, } end - if type(args[2]) == "string" then - return { - base = 0xa8000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0xa8000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0xa8000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0xa8000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, sw = function(args) - if #args < 2 or #args > 3 then - error("sw takes two or three arguments") - end + if #args < 2 or #args > 3 then error('sw takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("sw takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('sw takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = 1, - hi16 = args[2], - }, - { - base = 0xac000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = 1, - }, + { base = 0x3c000000, rt = 1, hi16 = args[2] }, + { base = 0xac000000, rt = checkGPR(args[1]), lo16 = args[2], rs = 1 }, } end - if type(args[2]) == "string" then - return { - base = 0xac000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0xac000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0xac000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0xac000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, swr = function(args) - if #args < 2 or #args > 3 then - error("swr takes two or three arguments") - end + if #args < 2 or #args > 3 then error('swr takes two or three arguments') end if #args == 2 then - if type(args[2]) ~= "string" then - error("swr takes a label as its second argument when given two arguments") + if type(args[2]) ~= 'string' then + error('swr takes a label as its second argument when given two arguments') end return { - { - base = 0x3c000000, - rt = 1, - hi16 = args[2], - }, - { - base = 0xb0000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = 1, - }, + { base = 0x3c000000, rt = 1, hi16 = args[2] }, + { base = 0xb0000000, rt = checkGPR(args[1]), lo16 = args[2], rs = 1 }, } end - if type(args[2]) == "string" then - return { - base = 0xb8000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - } + if type(args[2]) == 'string' then + return { base = 0xb8000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) } end - return { - base = 0xb8000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - } + return { base = 0xb8000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) } end, } diff --git a/src/supportpsx/assembler/pseudo.lua b/src/supportpsx/assembler/pseudo.lua index a7d1c80480..1b10ffec0c 100644 --- a/src/supportpsx/assembler/pseudo.lua +++ b/src/supportpsx/assembler/pseudo.lua @@ -15,8 +15,7 @@ -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -local bit = require("bit") +local bit = require('bit') local checkGPR = PCSX.Assembler.Internals.checks.gpr local checkBImm16 = PCSX.Assembler.Internals.checks.bimm16 @@ -24,326 +23,138 @@ local checkImm16 = PCSX.Assembler.Internals.checks.imm16 PCSX.Assembler.Internals.pseudoInstructions = { nop = function(args) - if #args ~= 0 then - error("nop takes no arguments") - end - return { - base = 0x00000000, - } + if #args ~= 0 then error('nop takes no arguments') end + return { base = 0x00000000 } end, move = function(args) - if #args ~= 2 then - error("move takes two arguments") - end - return { - base = 0x00000021, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = 0, - } + if #args ~= 2 then error('move takes two arguments') end + return { base = 0x00000021, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = 0 } end, li = function(args) - if #args ~= 2 then - error("li takes two arguments") - end - if type(args[2]) ~= "number" then - error("li second argument must be a number") - end + if #args ~= 2 then error('li takes two arguments') end + if type(args[2]) ~= 'number' then error('li second argument must be a number') end local imm = args[2] if imm < -0x8000 or imm > 0xffff then return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - imm16 = bit.rshift(imm, 16), - }, - { - base = 0x34000000, - rt = checkGPR(args[1]), - imm16 = bit.band(imm, 0xffff), - }, + { base = 0x3c000000, rt = checkGPR(args[1]), imm16 = bit.rshift(imm, 16) }, + { base = 0x34000000, rt = checkGPR(args[1]), imm16 = bit.band(imm, 0xffff) }, } else - return { - base = 0x3c000000, - rt = checkGPR(args[1]), - imm16 = args[2], - } + return { base = 0x3c000000, rt = checkGPR(args[1]), imm16 = args[2] } end end, la = function(args) - if #args ~= 2 then - error("la takes two arguments") - end - if type(args[2]) ~= "string" then - error("la second argument must be a string") - end + if #args ~= 2 then error('la takes two arguments') end + if type(args[2]) ~= 'string' then error('la second argument must be a string') end return { - { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2], - }, - { - base = 0x24000000, - rt = checkGPR(args[1]), - lo16 = args[2], - }, + { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] }, + { base = 0x24000000, rt = checkGPR(args[1]), lo16 = args[2] }, } end, not_ = function(args) - if #args < 1 or #args > 2 then - error("not takes one or two arguments") - end - if #args == 1 then - return { - base = 0x00000027, - rd = checkGPR(args[1]), - rs = checkGPR(args[1]), - rt = 0, - } - end - return { - base = 0x00000027, - rd = checkGPR(args[1]), - rs = checkGPR(args[2]), - rt = 0, - } + if #args < 1 or #args > 2 then error('not takes one or two arguments') end + if #args == 1 then return { base = 0x00000027, rd = checkGPR(args[1]), rs = checkGPR(args[1]), rt = 0 } end + return { base = 0x00000027, rd = checkGPR(args[1]), rs = checkGPR(args[2]), rt = 0 } end, neg = function(args) - if #args < 1 or #args > 2 then - error("neg takes one or two arguments") - end - if #args == 1 then - return { - base = 0x00000023, - rd = checkGPR(args[1]), - rs = 0, - rt = checkGPR(args[1]), - } - end - return { - base = 0x00000023, - rd = checkGPR(args[1]), - rs = 0, - rt = checkGPR(args[2]), - } + if #args < 1 or #args > 2 then error('neg takes one or two arguments') end + if #args == 1 then return { base = 0x00000023, rd = checkGPR(args[1]), rs = 0, rt = checkGPR(args[1]) } end + return { base = 0x00000023, rd = checkGPR(args[1]), rs = 0, rt = checkGPR(args[2]) } end, b = function(args) - if #args ~= 1 then - error("b takes one argument") - end - return { - base = 0x10000000, - bimm16 = checkBImm16(args[1], 1), - } + if #args ~= 1 then error('b takes one argument') end + return { base = 0x10000000, bimm16 = checkBImm16(args[1], 1) } end, bal = function(args) - if #args ~= 1 then - error("bal takes one argument") - end - return { - base = 0x04110000, - bimm16 = checkBImm16(args[1], 1), - } + if #args ~= 1 then error('bal takes one argument') end + return { base = 0x04110000, bimm16 = checkBImm16(args[1], 1) } end, blt = function(args) - if #args ~= 3 then - error("blt takes three arguments") - end + if #args ~= 3 then error('blt takes three arguments') end return { - { - base = 0x0000002a, - rd = 1, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - }, - { - base = 0x14000000, - rs = 1, - rt = 0, - bimm16 = checkBImm16(args[3], 2), - }, + { base = 0x0000002a, rd = 1, rs = checkGPR(args[1]), rt = checkGPR(args[2]) }, + { base = 0x14000000, rs = 1, rt = 0, bimm16 = checkBImm16(args[3], 2) }, } end, bltu = function(args) - if #args ~= 3 then - error("bltu takes three arguments") - end + if #args ~= 3 then error('bltu takes three arguments') end return { - { - base = 0x0000002b, - rd = 1, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - }, - { - base = 0x14000000, - rs = 1, - rt = 0, - bimm16 = checkBImm16(args[3], 2), - }, + { base = 0x0000002b, rd = 1, rs = checkGPR(args[1]), rt = checkGPR(args[2]) }, + { base = 0x14000000, rs = 1, rt = 0, bimm16 = checkBImm16(args[3], 2) }, } end, bgt = function(args) - if #args ~= 3 then - error("bgt takes three arguments") - end + if #args ~= 3 then error('bgt takes three arguments') end return { - { - base = 0x0000002a, - rd = 1, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - }, - { - base = 0x14000000, - rs = 1, - rt = 0, - bimm16 = checkBImm16(args[3], 2), - }, + { base = 0x0000002a, rd = 1, rs = checkGPR(args[1]), rt = checkGPR(args[2]) }, + { base = 0x14000000, rs = 1, rt = 0, bimm16 = checkBImm16(args[3], 2) }, } end, bgtu = function(args) - if #args ~= 3 then - error("bgtu takes three arguments") - end + if #args ~= 3 then error('bgtu takes three arguments') end return { - { - base = 0x0000002b, - rd = 1, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - }, - { - base = 0x14000000, - rs = 1, - rt = 0, - bimm16 = checkBImm16(args[3], 2), - }, + { base = 0x0000002b, rd = 1, rs = checkGPR(args[1]), rt = checkGPR(args[2]) }, + { base = 0x14000000, rs = 1, rt = 0, bimm16 = checkBImm16(args[3], 2) }, } end, beq = function(args) - if #args ~= 3 then - error("beq takes three arguments") - end - return { - { - base = 0x10000000, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - bimm16 = checkBImm16(args[3], 1), - }, - } + if #args ~= 3 then error('beq takes three arguments') end + return + { { base = 0x10000000, rs = checkGPR(args[1]), rt = checkGPR(args[2]), bimm16 = checkBImm16(args[3], 1) } } end, ulw = function(args) - if #args ~= 3 then - error("ulw takes three arguments") - end - if type(args[2]) == "string" then + if #args ~= 3 then error('ulw takes three arguments') end + if type(args[2]) == 'string' then return { - { - base = 0x88000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - }, - { - base = 0x98000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - }, + { base = 0x88000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) }, + { base = 0x98000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) }, } end return { - { - base = 0x88000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - }, - { - base = 0x98000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - }, + { base = 0x88000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) }, + { base = 0x98000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) }, } end, usw = function(args) - if #args ~= 3 then - error("usw takes three arguments") - end - if type(args[2]) == "string" then + if #args ~= 3 then error('usw takes three arguments') end + if type(args[2]) == 'string' then return { - { - base = 0xa8000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - }, - { - base = 0xb8000000, - rt = checkGPR(args[1]), - lo16 = args[2], - rs = checkGPR(args[3]), - }, + { base = 0xa8000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) }, + { base = 0xb8000000, rt = checkGPR(args[1]), lo16 = args[2], rs = checkGPR(args[3]) }, } end return { - { - base = 0xa8000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - }, - { - base = 0xb8000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - rs = checkGPR(args[3]), - }, + { base = 0xa8000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) }, + { base = 0xb8000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2), rs = checkGPR(args[3]) }, } end, subi = function(args) - if #args < 2 or #args > 3 then - error("subi takes two or three arguments") - end + if #args < 2 or #args > 3 then error('subi takes two or three arguments') end if #args == 2 then - return { - base = 0x24000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[1]), - imm16 = checkImm16(-args[2], 1), - } + return + { base = 0x24000000, rt = checkGPR(args[1]), rs = checkGPR(args[1]), imm16 = checkImm16(-args[2], 1) } end - return { - base = 0x24000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - imm16 = checkImm16(-args[3], 1), - } + return { base = 0x24000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), imm16 = checkImm16(-args[3], 1) } end, } for k, v in pairs(PCSX.Assembler.Internals.pseudoInstructions) do - if k:sub(-1) == "_" then + if k:sub(-1) == '_' then local newKey = k:sub(1, -2) PCSX.Assembler.Internals.pseudoInstructions[newKey] = v PCSX.Assembler.Internals.pseudoInstructions[k] = nil diff --git a/src/supportpsx/assembler/registers.lua b/src/supportpsx/assembler/registers.lua index f86cf90a24..391c829e07 100644 --- a/src/supportpsx/assembler/registers.lua +++ b/src/supportpsx/assembler/registers.lua @@ -15,110 +15,206 @@ -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - local gpr = { - r0 = 0, r1 = 1, r2 = 2, r3 = 3, r4 = 4, r5 = 5, r6 = 6, r7 = 7, - r8 = 8, r9 = 9, r10 = 10, r11 = 11, r12 = 12, r13 = 13, r14 = 14, r15 = 15, - r16 = 16, r17 = 17, r18 = 18, r19 = 19, r20 = 20, r21 = 21, r22 = 22, r23 = 23, - r24 = 24, r25 = 25, r26 = 26, r27 = 27, r28 = 28, r29 = 29, r30 = 30, r31 = 31, - zero = 0, at = 1, v0 = 2, v1 = 3, a0 = 4, a1 = 5, a2 = 6, a3 = 7, - t0 = 8, t1 = 9, t2 = 10, t3 = 11, t4 = 12, t5 = 13, t6 = 14, t7 = 15, - s0 = 16, s1 = 17, s2 = 18, s3 = 19, s4 = 20, s5 = 21, s6 = 22, s7 = 23, - t8 = 24, t9 = 25, k0 = 26, k1 = 27, gp = 28, sp = 29, fp = 30, ra = 31, + r0 = 0, + r1 = 1, + r2 = 2, + r3 = 3, + r4 = 4, + r5 = 5, + r6 = 6, + r7 = 7, + r8 = 8, + r9 = 9, + r10 = 10, + r11 = 11, + r12 = 12, + r13 = 13, + r14 = 14, + r15 = 15, + r16 = 16, + r17 = 17, + r18 = 18, + r19 = 19, + r20 = 20, + r21 = 21, + r22 = 22, + r23 = 23, + r24 = 24, + r25 = 25, + r26 = 26, + r27 = 27, + r28 = 28, + r29 = 29, + r30 = 30, + r31 = 31, + zero = 0, + at = 1, + v0 = 2, + v1 = 3, + a0 = 4, + a1 = 5, + a2 = 6, + a3 = 7, + t0 = 8, + t1 = 9, + t2 = 10, + t3 = 11, + t4 = 12, + t5 = 13, + t6 = 14, + t7 = 15, + s0 = 16, + s1 = 17, + s2 = 18, + s3 = 19, + s4 = 20, + s5 = 21, + s6 = 22, + s7 = 23, + t8 = 24, + t9 = 25, + k0 = 26, + k1 = 27, + gp = 28, + sp = 29, + fp = 30, + ra = 31, } local gteRegistersSet0 = { - vxz0 = 0, vz0 = 1, vxy1 = 2, vyz1 = 3, vxz1 = 4, vz1 = 5, rgb = 6, otz = 7, - ir0 = 8, ir1 = 9, ir2 = 10, ir3 = 11, sxy0 = 12, sxy1 = 13, sxy2 = 14, sxyp = 15, - sz0 = 16, sz1 = 17, sz2 = 18, sz3 = 19, rgb0 = 20, rgb1 = 21, rgb2 = 22, res1 = 23, - mac0 = 24, mac1 = 25, mac2 = 26, mac3 = 27, irgb = 28, orgb = 29, lzcs = 30, lzcr = 31, + vxz0 = 0, + vz0 = 1, + vxy1 = 2, + vyz1 = 3, + vxz1 = 4, + vz1 = 5, + rgb = 6, + otz = 7, + ir0 = 8, + ir1 = 9, + ir2 = 10, + ir3 = 11, + sxy0 = 12, + sxy1 = 13, + sxy2 = 14, + sxyp = 15, + sz0 = 16, + sz1 = 17, + sz2 = 18, + sz3 = 19, + rgb0 = 20, + rgb1 = 21, + rgb2 = 22, + res1 = 23, + mac0 = 24, + mac1 = 25, + mac2 = 26, + mac3 = 27, + irgb = 28, + orgb = 29, + lzcs = 30, + lzcr = 31, } local gteRegistersSet1 = { - r11r12 = 0, r13r21 = 1, r22r23 = 2, r31r32 = 3, r33 = 4, trx = 5, try = 6, trz = 7, - l11l12 = 8, l13l21 = 9, l22l23 = 10, l31l32 = 11, l33 = 12, rbk = 13, gbk = 14, bbk = 15, - lr1lr2 = 16, lr3lg1 = 17, lg2lg3 = 18, lb1lb2 = 19, lb3 = 20, rfc = 21, gfc = 22, bfc = 23, - ofx = 24, ofy = 25, h = 26, dqa = 27, dqb = 28, zsf3 = 29, zsf4 = 30, flag = 31, + r11r12 = 0, + r13r21 = 1, + r22r23 = 2, + r31r32 = 3, + r33 = 4, + trx = 5, + try = 6, + trz = 7, + l11l12 = 8, + l13l21 = 9, + l22l23 = 10, + l31l32 = 11, + l33 = 12, + rbk = 13, + gbk = 14, + bbk = 15, + lr1lr2 = 16, + lr3lg1 = 17, + lg2lg3 = 18, + lb1lb2 = 19, + lb3 = 20, + rfc = 21, + gfc = 22, + bfc = 23, + ofx = 24, + ofy = 25, + h = 26, + dqa = 27, + dqb = 28, + zsf3 = 29, + zsf4 = 30, + flag = 31, } local cop0Registers = { - bpc = 3, bda = 5, dcic = 12, badv = 8, bdam = 9, bpcm = 11, sr = 12, cause = 13, epc = 14, prid = 15, + bpc = 3, + bda = 5, + dcic = 12, + badv = 8, + bdam = 9, + bpcm = 11, + sr = 12, + cause = 13, + epc = 14, + prid = 15, } PCSX.Assembler.Internals.checks.gpr = function(reg) - if type(reg) == "number" then - if reg < 0 or reg > 31 then - error("Invalid GPR: " .. reg) - end + if type(reg) == 'number' then + if reg < 0 or reg > 31 then error('Invalid GPR: ' .. reg) end return reg end - if type(reg) == "string" then + if type(reg) == 'string' then reg = reg:lower() - if reg:sub(1, 1) == "$" then - reg = reg:sub(2) - end - end - if gpr[reg] ~= nil then - return gpr[reg] + if reg:sub(1, 1) == '$' then reg = reg:sub(2) end end - error("Unknown GPR: " .. reg) + if gpr[reg] ~= nil then return gpr[reg] end + error('Unknown GPR: ' .. reg) end PCSX.Assembler.Internals.checks.cop0 = function(reg) - if type(reg) == "number" then - if reg < 0 or reg > 31 then - error("Invalid COP0 register: " .. reg) - end + if type(reg) == 'number' then + if reg < 0 or reg > 31 then error('Invalid COP0 register: ' .. reg) end return reg end - if type(reg) == "string" then + if type(reg) == 'string' then reg = reg:lower() - if reg:sub(1, 1) == "$" then - reg = reg:sub(2) - end - end - if cop0Registers[reg] ~= nil then - return cop0Registers[reg] + if reg:sub(1, 1) == '$' then reg = reg:sub(2) end end - error("Unknown COP0 register: " .. reg) + if cop0Registers[reg] ~= nil then return cop0Registers[reg] end + error('Unknown COP0 register: ' .. reg) end PCSX.Assembler.Internals.checks.gte0 = function(reg) - if type(reg) == "number" then - if reg < 0 or reg > 31 then - error("Invalid GTE register: " .. reg) - end + if type(reg) == 'number' then + if reg < 0 or reg > 31 then error('Invalid GTE register: ' .. reg) end return reg end - if type(reg) == "string" then + if type(reg) == 'string' then reg = reg:lower() - if reg:sub(1, 1) == "$" then - reg = reg:sub(2) - end + if reg:sub(1, 1) == '$' then reg = reg:sub(2) end end - if gteRegistersSet0[reg] ~= nil then - return gteRegistersSet0[reg] - end - error("Unknown GTE register: " .. reg) + if gteRegistersSet0[reg] ~= nil then return gteRegistersSet0[reg] end + error('Unknown GTE register: ' .. reg) end PCSX.Assembler.Internals.checks.gte1 = function(reg) - if type(reg) == "number" then - if reg < 0 or reg > 31 then - error("Invalid GTE register: " .. reg) - end + if type(reg) == 'number' then + if reg < 0 or reg > 31 then error('Invalid GTE register: ' .. reg) end return reg end - if type(reg) == "string" then + if type(reg) == 'string' then reg = reg:lower() - if reg:sub(1, 1) == "$" then - reg = reg:sub(2) - end - end - if gteRegistersSet1[reg] ~= nil then - return gteRegistersSet1[reg] + if reg:sub(1, 1) == '$' then reg = reg:sub(2) end end - error("Unknown GTE register: " .. reg) + if gteRegistersSet1[reg] ~= nil then return gteRegistersSet1[reg] end + error('Unknown GTE register: ' .. reg) end -- )EOF" diff --git a/src/supportpsx/assembler/simple.lua b/src/supportpsx/assembler/simple.lua index f16d2f1219..0df447dda0 100644 --- a/src/supportpsx/assembler/simple.lua +++ b/src/supportpsx/assembler/simple.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. - local checkImm26 = PCSX.Assembler.Internals.checks.imm26 local checkBImm16 = PCSX.Assembler.Internals.checks.bimm16 local checkImm16 = PCSX.Assembler.Internals.checks.imm16 @@ -23,227 +22,95 @@ local checkGPR = PCSX.Assembler.Internals.checks.gpr PCSX.Assembler.Internals.simpleInstructions = { j = function(args) - if #args ~= 1 then - error("j takes one argument") - end - return { - base = 0x08000000, - imm26 = checkImm26(args[1], 1), - } + if #args ~= 1 then error('j takes one argument') end + return { base = 0x08000000, imm26 = checkImm26(args[1], 1) } end, jal = function(args) - if #args ~= 1 then - error("jal takes one argument") - end - return { - base = 0x0c000000, - imm26 = checkImm26(args[1], 1), - } + if #args ~= 1 then error('jal takes one argument') end + return { base = 0x0c000000, imm26 = checkImm26(args[1], 1) } end, beq = function(args) - if #args ~= 3 then - error("beq takes three arguments") - end - return { - base = 0x10000000, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - bimm16 = checkBImm16(args[3], 3), - } + if #args ~= 3 then error('beq takes three arguments') end + return { base = 0x10000000, rs = checkGPR(args[1]), rt = checkGPR(args[2]), bimm16 = checkBImm16(args[3], 3) } end, bne = function(args) - if #args ~= 3 then - error("bne takes three arguments") - end - return { - base = 0x14000000, - rs = checkGPR(args[1]), - rt = checkGPR(args[2]), - bimm16 = checkBImm16(args[3], 3), - } + if #args ~= 3 then error('bne takes three arguments') end + return { base = 0x14000000, rs = checkGPR(args[1]), rt = checkGPR(args[2]), bimm16 = checkBImm16(args[3], 3) } end, blez = function(args) - if #args ~= 2 then - error("blez takes two arguments") - end - return { - base = 0x18000000, - rs = checkGPR(args[1]), - bimm16 = checkBImm16(args[2], 2), - } + if #args ~= 2 then error('blez takes two arguments') end + return { base = 0x18000000, rs = checkGPR(args[1]), bimm16 = checkBImm16(args[2], 2) } end, bgtz = function(args) - if #args ~= 2 then - error("bgtz takes two arguments") - end - return { - base = 0x1c000000, - rs = checkGPR(args[1]), - bimm16 = checkBImm16(args[2], 2), - } + if #args ~= 2 then error('bgtz takes two arguments') end + return { base = 0x1c000000, rs = checkGPR(args[1]), bimm16 = checkBImm16(args[2], 2) } end, addi = function(args) - if #args < 2 or #args > 3 then - error("addi takes two or three arguments") - end + if #args < 2 or #args > 3 then error('addi takes two or three arguments') end if #args == 2 then - return { - base = 0x20000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - } + return { base = 0x20000000, rt = checkGPR(args[1]), rs = checkGPR(args[1]), imm16 = checkImm16(args[2], 2) } end - return { - base = 0x20000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - imm16 = checkImm16(args[3], 3), - } + return { base = 0x20000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), imm16 = checkImm16(args[3], 3) } end, addiu = function(args) - if #args < 2 or #args > 3 then - error("addiu takes two or three arguments") - end + if #args < 2 or #args > 3 then error('addiu takes two or three arguments') end if #args == 2 then - if type(args[2]) == "string" then - return { - base = 0x24000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[1]), - lo16 = args[2] - } + if type(args[2]) == 'string' then + return { base = 0x24000000, rt = checkGPR(args[1]), rs = checkGPR(args[1]), lo16 = args[2] } end - return { - base = 0x24000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - } + return { base = 0x24000000, rt = checkGPR(args[1]), rs = checkGPR(args[1]), imm16 = checkImm16(args[2], 2) } end - if type(args[3]) == "string" then - return { - base = 0x24000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - lo16 = args[3] - } + if type(args[3]) == 'string' then + return { base = 0x24000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), lo16 = args[3] } end - return { - base = 0x24000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - imm16 = checkImm16(args[3], 3), - } + return { base = 0x24000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), imm16 = checkImm16(args[3], 3) } end, slti = function(args) - if #args ~= 3 then - error("slti takes three arguments") - end - return { - base = 0x28000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - imm16 = checkImm16(args[3], 3), - } + if #args ~= 3 then error('slti takes three arguments') end + return { base = 0x28000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), imm16 = checkImm16(args[3], 3) } end, sltiu = function(args) - if #args ~= 3 then - error("sltiu takes three arguments") - end - return { - base = 0x2c000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - imm16 = checkImm16(args[3], 3), - } + if #args ~= 3 then error('sltiu takes three arguments') end + return { base = 0x2c000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), imm16 = checkImm16(args[3], 3) } end, andi = function(args) - if #args < 2 or #args > 3 then - error("andi takes two or three arguments") - end + if #args < 2 or #args > 3 then error('andi takes two or three arguments') end if #args == 2 then - return { - base = 0x30000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - } + return { base = 0x30000000, rt = checkGPR(args[1]), rs = checkGPR(args[1]), imm16 = checkImm16(args[2], 2) } end - return { - base = 0x30000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - imm16 = checkImm16(args[3], 3), - } + return { base = 0x30000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), imm16 = checkImm16(args[3], 3) } end, ori = function(args) - if #args < 2 or #args > 3 then - error("ori takes two or three arguments") - end + if #args < 2 or #args > 3 then error('ori takes two or three arguments') end if #args == 2 then - return { - base = 0x34000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - } + return { base = 0x34000000, rt = checkGPR(args[1]), rs = checkGPR(args[1]), imm16 = checkImm16(args[2], 2) } end - return { - base = 0x34000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - imm16 = checkImm16(args[3], 3), - } + return { base = 0x34000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), imm16 = checkImm16(args[3], 3) } end, xori = function(args) - if #args < 2 or #args > 3 then - error("xori takes two or three arguments") - end + if #args < 2 or #args > 3 then error('xori takes two or three arguments') end if #args == 2 then - return { - base = 0x38000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - } + return { base = 0x38000000, rt = checkGPR(args[1]), rs = checkGPR(args[1]), imm16 = checkImm16(args[2], 2) } end - return { - base = 0x38000000, - rt = checkGPR(args[1]), - rs = checkGPR(args[2]), - imm16 = checkImm16(args[3], 3), - } + return { base = 0x38000000, rt = checkGPR(args[1]), rs = checkGPR(args[2]), imm16 = checkImm16(args[3], 3) } end, lui = function(args) - if #args ~= 2 then - error("lui takes two arguments") - end - if type(args[2]) == "string" then - return { - base = 0x3c000000, - rt = checkGPR(args[1]), - hi16 = args[2] - } - end - return { - base = 0x3c000000, - rt = checkGPR(args[1]), - imm16 = checkImm16(args[2], 2), - } + if #args ~= 2 then error('lui takes two arguments') end + if type(args[2]) == 'string' then return { base = 0x3c000000, rt = checkGPR(args[1]), hi16 = args[2] } end + return { base = 0x3c000000, rt = checkGPR(args[1]), imm16 = checkImm16(args[2], 2) } end, } diff --git a/src/supportpsx/assembler/symbols.lua b/src/supportpsx/assembler/symbols.lua index 1d547cd816..0276e9bc9f 100644 --- a/src/supportpsx/assembler/symbols.lua +++ b/src/supportpsx/assembler/symbols.lua @@ -15,18 +15,10 @@ -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -PCSX.Assembler.Internals.resolveSymbol = function (name) +PCSX.Assembler.Internals.resolveSymbol = function(name) -- This is a bit of a bad one, as it creates a circular dependency, -- but since it's Lua, it's not too much of an issue. - for k, v in PCSX.iterateSymbols() do - if v == name then - return { - address = k, - name = v, - } - end - end + for k, v in PCSX.iterateSymbols() do if v == name then return { address = k, name = v } end end return nil end diff --git a/src/supportpsx/binffi.lua b/src/supportpsx/binffi.lua index 78d983f656..d35a76b907 100644 --- a/src/supportpsx/binffi.lua +++ b/src/supportpsx/binffi.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. - local C = ffi.load 'SUPPORTPSX_BINARY' ffi.cdef [[ @@ -49,12 +48,8 @@ uint32_t writeUclDecomp(LuaFile* dest); PCSX.Binary = {} PCSX.Binary.load = function(src, dest) - if type(src) ~= 'table' or src._type ~= 'File' then - error('Expected a File object as first argument') - end - if type(dest) ~= 'table' or dest._type ~= 'File' then - error('Expected a File object as second argument') - end + if type(src) ~= 'table' or src._type ~= 'File' then error('Expected a File object as first argument') end + if type(dest) ~= 'table' or dest._type ~= 'File' then error('Expected a File object as second argument') end local info = ffi.new('struct BinaryLoaderInfo') if not C.binaryLoaderLoad(src._wrapper, dest._wrapper, info) then return nil end local ret = {} @@ -66,30 +61,16 @@ PCSX.Binary.load = function(src, dest) end PCSX.Binary.pack = function(src, dest, addr, pc, gp, sp, options) - if type(src) ~= 'table' or src._type ~= 'File' then - error('Expected a File object as first argument') - end - if type(dest) ~= 'table' or dest._type ~= 'File' then - error('Expected a File object as second argument') - end - if type(addr) ~= 'number' then - error('Expected a number as third argument') - end - if type(pc) ~= 'number' then - error('Expected a number as fourth argument') - end + if type(src) ~= 'table' or src._type ~= 'File' then error('Expected a File object as first argument') end + if type(dest) ~= 'table' or dest._type ~= 'File' then error('Expected a File object as second argument') end + if type(addr) ~= 'number' then error('Expected a number as third argument') end + if type(pc) ~= 'number' then error('Expected a number as fourth argument') end if gp == nil then gp = 0 end - if type(gp) ~= 'number' then - error('Expected a number as fifth argument') - end + if type(gp) ~= 'number' then error('Expected a number as fifth argument') end if sp == nil then sp = 0 end - if type(sp) ~= 'number' then - error('Expected a number as sixth argument') - end + if type(sp) ~= 'number' then error('Expected a number as sixth argument') end if options == nil then options = {} end - if type(options) ~= 'table' then - error('Expected a table as seventh argument') - end + if type(options) ~= 'table' then error('Expected a table as seventh argument') end local opts = ffi.new('struct PS1PackerOptions') opts.tload = options.tload and options.tload or 0 opts.booty = options.booty and true or false @@ -101,26 +82,14 @@ PCSX.Binary.pack = function(src, dest, addr, pc, gp, sp, options) end PCSX.Binary.createExe = function(src, dest, addr, pc, gp, sp) - if type(src) ~= 'table' or src._type ~= 'File' then - error('Expected a File object as first argument') - end - if type(dest) ~= 'table' or dest._type ~= 'File' then - error('Expected a File object as second argument') - end - if type(addr) ~= 'number' then - error('Expected a number as third argument') - end - if type(pc) ~= 'number' then - error('Expected a number as fourth argument') - end + if type(src) ~= 'table' or src._type ~= 'File' then error('Expected a File object as first argument') end + if type(dest) ~= 'table' or dest._type ~= 'File' then error('Expected a File object as second argument') end + if type(addr) ~= 'number' then error('Expected a number as third argument') end + if type(pc) ~= 'number' then error('Expected a number as fourth argument') end if gp == nil then gp = 0 end - if type(gp) ~= 'number' then - error('Expected a number as fifth argument') - end + if type(gp) ~= 'number' then error('Expected a number as fifth argument') end if sp == nil then sp = 0 end - if type(sp) ~= 'number' then - error('Expected a number as sixth argument') - end + if type(sp) ~= 'number' then error('Expected a number as sixth argument') end local size = src:size() size = bit.band(size + 0x7ff, bit.bnot(0x7ff)) @@ -138,28 +107,16 @@ PCSX.Binary.createExe = function(src, dest, addr, pc, gp, sp) dest:writeU32(0) dest:writeU32(0) dest:writeU32(sp) - while dest:size() < 0x800 do - dest:writeU8(0) - end + while dest:size() < 0x800 do dest:writeU8(0) end dest:write(src:read(src:size())) - while bit.band(dest:size(), 0x7ff) ~= 0 do - dest:writeU8(0) - end + while bit.band(dest:size(), 0x7ff) ~= 0 do dest:writeU8(0) end end PCSX.Binary.createCpe = function(src, dest, addr, pc) - if type(src) ~= 'table' or src._type ~= 'File' then - error('Expected a File object as first argument') - end - if type(dest) ~= 'table' or dest._type ~= 'File' then - error('Expected a File object as second argument') - end - if type(addr) ~= 'number' then - error('Expected a number as third argument') - end - if type(pc) ~= 'number' then - error('Expected a number as fourth argument') - end + if type(src) ~= 'table' or src._type ~= 'File' then error('Expected a File object as first argument') end + if type(dest) ~= 'table' or dest._type ~= 'File' then error('Expected a File object as second argument') end + if type(addr) ~= 'number' then error('Expected a number as third argument') end + if type(pc) ~= 'number' then error('Expected a number as fourth argument') end local size = src:size() @@ -178,19 +135,13 @@ end if type(PCSX.Misc) ~= 'table' then PCSX.Misc = {} end PCSX.Misc.uclPack = function(src, dest) - if type(src) ~= 'table' or src._type ~= 'File' then - error('Expected a File object as first argument') - end - if type(dest) ~= 'table' or dest._type ~= 'File' then - error('Expected a File object as second argument') - end + if type(src) ~= 'table' or src._type ~= 'File' then error('Expected a File object as first argument') end + if type(dest) ~= 'table' or dest._type ~= 'File' then error('Expected a File object as second argument') end return C.uclPack(src._wrapper, dest._wrapper) end PCSX.Misc.writeUclDecomp = function(dest) - if type(dest) ~= 'table' or dest._type ~= 'File' then - error('Expected a File object as first argument') - end + if type(dest) ~= 'table' or dest._type ~= 'File' then error('Expected a File object as first argument') end return C.writeUclDecomp(dest._wrapper) end