Skip to content

Commit

Permalink
Merge branch 'main' of http://github.com/grumpycoders/pcsx-redux into…
Browse files Browse the repository at this point in the history
… fuckit
  • Loading branch information
nicolasnoble committed Feb 20, 2024
2 parents c641128 + e1465ba commit 0293274
Show file tree
Hide file tree
Showing 26 changed files with 1,536 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ SUPPORT_SRCS += third_party/ucl/src/n2e_99.c third_party/ucl/src/alloc.c
SUPPORT_SRCS += $(wildcard third_party/iec-60908b/*.c)
OBJECTS := third_party/luajit/src/libluajit.a

TOOLS = exe2elf exe2iso ps1-packer psyq-obj-parser
TOOLS = exe2elf exe2iso modconv ps1-packer psyq-obj-parser

##############################################################################

Expand Down
10 changes: 6 additions & 4 deletions azure-pipelines-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ steps:
vsprojects/x64/ReleaseCLI/crashpad_handler.exe
vsprojects/x64/ReleaseCLI/exe2elf.exe
vsprojects/x64/ReleaseCLI/exe2iso.exe
vsprojects/x64/ReleaseCLI/psyq-obj-parser.exe
vsprojects/x64/ReleaseCLI/modconv.exe
vsprojects/x64/ReleaseCLI/ps1-packer.exe
vsprojects/x64/ReleaseCLI/psyq-obj-parser.exe
vsprojects/x64/ReleaseCLI/*.dll
TargetFolder: '$(build.artifactStagingDirectory)/binaries'

Expand All @@ -83,11 +84,12 @@ steps:
!**\crashpad_handler.exe
!**\exe2elf.exe
!**\exe2iso.exe
!**\pcsxrunner.exe
!**\pcsx-wrapper.exe
!**\modconv.exe
!**\pcsx-redux.exe
!**\psyq-obj-parser.exe
!**\pcsx-wrapper.exe
!**\pcsxrunner.exe
!**\ps1-packer.exe
!**\psyq-obj-parser.exe
!third_party\**\*.exe
searchFolder: '$(System.DefaultWorkingDirectory)'
pathtoCustomTestAdapters: 'GoogleTestAdapter'
Expand Down
8 changes: 5 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ steps:
vsprojects/x64/ReleaseWithClangCL/crashpad_handler.exe
vsprojects/x64/ReleaseWithClangCL/exe2elf.exe
vsprojects/x64/ReleaseWithClangCL/exe2iso.exe
vsprojects/x64/ReleaseWithClangCL/psyq-obj-parser.exe
vsprojects/x64/ReleaseWithClangCL/modconv.exe
vsprojects/x64/ReleaseWithClangCL/ps1-packer.exe
vsprojects/x64/ReleaseWithClangCL/psyq-obj-parser.exe
vsprojects/x64/ReleaseWithClangCL/*.dll
TargetFolder: '$(build.artifactStagingDirectory)/binaries'

Expand All @@ -91,11 +92,12 @@ steps:
!**\crashpad_handler.exe
!**\exe2elf.exe
!**\exe2iso.exe
!**\pcsxrunner.exe
!**\modconv.exe
!**\pcsx-redux.main
!**\pcsx-redux.exe
!**\psyq-obj-parser.exe
!**\pcsxrunner.exe
!**\ps1-packer.exe
!**\psyq-obj-parser.exe
!third_party\**\*.exe
searchFolder: '$(System.DefaultWorkingDirectory)'
pathtoCustomTestAdapters: 'GoogleTestAdapter'
Expand Down
2 changes: 2 additions & 0 deletions src/core/psxemulator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extern "C" {
#include "luv/src/luv.h"
}
#include "spu/interface.h"
#include "supportpsx/adpcmlua.h"
#include "supportpsx/assembler.h"
#include "supportpsx/binlua.h"

Expand Down Expand Up @@ -105,6 +106,7 @@ void PCSX::Emulator::setLua() {
LuaFFI::open_iso(L);
LuaFFI::open_extra(L);
LuaBindings::open_events(L);
LuaSupportPSX::open_adpcm(L);
LuaSupportPSX::open_assembler(L);
LuaSupportPSX::open_binaries(L);

Expand Down
4 changes: 2 additions & 2 deletions src/lua/fileffi-cdef.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void closeFile(LuaFile* wrapper);
uint64_t readFileRawPtr(LuaFile* wrapper, void* dst, uint64_t size);
uint64_t readFileBuffer(LuaFile* wrapper, LuaBuffer* buffer);

uint64_t writeFileRawPtr(LuaFile* wrapper, const const uint8_t* data, uint64_t size);
uint64_t writeFileRawPtr(LuaFile* wrapper, const const void* data, uint64_t size);
uint64_t writeFileBuffer(LuaFile* wrapper, const LuaBuffer* buffer);
void writeFileMoveSlice(LuaFile* wrapper, LuaSlice* slice);

Expand All @@ -71,7 +71,7 @@ uint64_t getFileSize(LuaFile*);
uint64_t readFileAtRawPtr(LuaFile* wrapper, void* dst, uint64_t size, uint64_t pos);
uint64_t readFileAtBuffer(LuaFile* wrapper, LuaBuffer* buffer, uint64_t pos);

uint64_t writeFileAtRawPtr(LuaFile* wrapper, const const uint8_t* data, uint64_t size, uint64_t pos);
uint64_t writeFileAtRawPtr(LuaFile* wrapper, const const void* data, uint64_t size, uint64_t pos);
uint64_t writeFileAtBuffer(LuaFile* wrapper, const LuaBuffer* buffer, uint64_t pos);
void writeFileAtMoveSlice(LuaFile* wrapper, LuaSlice* slice, uint64_t pos);

Expand Down
16 changes: 8 additions & 8 deletions src/lua/fileffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ local function startCachingAndWait(self)
end
end

local uint8_t = ffi.typeof('uint8_t[1]');
local uint16_t = ffi.typeof('uint16_t[1]');
local uint32_t = ffi.typeof('uint32_t[1]');
local uint64_t = ffi.typeof('uint64_t[1]');
local int8_t = ffi.typeof('int8_t[1]');
local int16_t = ffi.typeof('int16_t[1]');
local int32_t = ffi.typeof('int32_t[1]');
local int64_t = ffi.typeof('int64_t[1]');
local uint8_t = ffi.typeof 'uint8_t[1]'
local uint16_t = ffi.typeof 'uint16_t[1]'
local uint32_t = ffi.typeof 'uint32_t[1]'
local uint64_t = ffi.typeof 'uint64_t[1]'
local int8_t = ffi.typeof 'int8_t[1]'
local int16_t = ffi.typeof 'int16_t[1]'
local int32_t = ffi.typeof 'int32_t[1]'
local int64_t = ffi.typeof 'int64_t[1]'

local function deleteFile(wrapper)
Support.extra.safeFFI('File::~File', C.deleteFile, wrapper)
Expand Down
2 changes: 1 addition & 1 deletion src/mips/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ $(BINDIR)$(TARGET).elf: $(OBJS) $(LIBRARIES) $(EXTRA_DEPS)
ifneq ($(strip $(BINDIR)),)
mkdir -p $(BINDIR)
endif
$(CC) $(LDFLAGS) -g -o $(BINDIR)$(TARGET).elf $(OBJS) $(LIBRARIES)
$(CC) -g -o $(BINDIR)$(TARGET).elf $(OBJS) $(LDFLAGS) $(LIBRARIES)

$(BINDIR)lib$(TARGET).a: $(OBJS) $(EXTRA_DEPS)
$(AR) rcs $(BINDIR)lib$(TARGET).a $(OBJS)
Expand Down
2 changes: 2 additions & 0 deletions src/mips/modplayer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ This code is a reverse engineering of the file MODPLAY.BIN, located in the zip f
The current API behaves roughly the same the original one. The code should provide information about the alterations made to it.

The demo song, "timewarped", written by [Jesster](https://modarchive.org/index.php?request=view_profile&query=69138), comes from [the modarchive](https://modarchive.org/index.php?request=view_by_moduleid&query=106481) with a [CC BY-NC-SA 3.0](https://creativecommons.org/licenses/by-nc-sa/3.0/) license, allowing non-commercial adaptations. The file has been converted from MOD to HIT using the MODCONV.EXE software provided by Hitmen.

A modern recreation of the MODCONV.EXE software is available within the PCSX-Redux project itself. See the [modconv](https://github.com/grumpycoders/pcsx-redux/tree/main/tools/modconv) folder for more information.
17 changes: 14 additions & 3 deletions src/mips/modplayer/modplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static void MOD_SetBPM(unsigned bpm) {

static struct SPUChannelData s_channelData[24];

uint32_t MOD_Load(const struct MODFileFormat* module) {
static uint32_t loadInternal(const struct MODFileFormat* module, const uint8_t* sampleData) {
SPUInit();
MOD_Channels = MOD_Check(module);

Expand All @@ -241,8 +241,12 @@ uint32_t MOD_Load(const struct MODFileFormat* module) {

MOD_ModuleData = (const uint8_t*)&module->patternTable[0];

SPUUploadInstruments(0x1010, MOD_ModuleData + 4 + 128 + MOD_Channels * 0x100 * (maxPatternID + 1),
currentSpuAddress - 0x1010);
if (sampleData) {
SPUUploadInstruments(0x1010, sampleData, currentSpuAddress - 0x1010);
} else {
SPUUploadInstruments(0x1010, MOD_ModuleData + 4 + 128 + MOD_Channels * 0x100 * (maxPatternID + 1),
currentSpuAddress - 0x1010);
}

MOD_CurrentOrder = 0;
MOD_CurrentPattern = module->patternTable[0];
Expand Down Expand Up @@ -274,6 +278,13 @@ uint32_t MOD_Load(const struct MODFileFormat* module) {
return 4 + 128 + MOD_Channels * 0x100 * (maxPatternID + 1);
}

uint32_t MOD_Load(const struct MODFileFormat* module) { return loadInternal(module, NULL); }

unsigned MOD_LoadEx(const struct MODFileFormat* module, const uint8_t* sampleData) {
loadInternal(module, sampleData);
return MOD_Channels;
}

void MOD_Silence() {
SPUInit();
for (unsigned i = 0; i < 24; i++) {
Expand Down
11 changes: 11 additions & 0 deletions src/mips/modplayer/modplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ unsigned MOD_Check(const struct MODFileFormat* module);
// the SPU.
uint32_t MOD_Load(const struct MODFileFormat* module);

// Loads the specified module and gets it ready for
// playback. The pointers have to be aligned to a
// 4-bytes boundary. Will also setup the SPU. This
// call is meant to be used with the separate .smp
// file, which the new modconv.exe tool can generate.
// Returns the number of channels from the module,
// or 0 if the module is invalid. No relocation is
// needed, and the sampleData pointer can simply be
// freed after this call.
unsigned MOD_LoadEx(const struct MODFileFormat* module, const uint8_t* sampleData);

// Call this function periodically to play sound. The
// frequency at which this is called will determine the
// actual playback speed of the module. Most modules will
Expand Down
91 changes: 77 additions & 14 deletions src/support/binstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SOFTWARE.
#include <stdint.h>

#include <bit>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -91,10 +92,6 @@ struct UInt64 : public BasicFieldType<uint64_t, std::endian::little> {
static constexpr char const typeName[] = "uint64_t";
};

struct BEInt8 : public BasicFieldType<int8_t, std::endian::big> {
static constexpr char const typeName[] = "int8_t";
};

struct BEInt16 : public BasicFieldType<int16_t, std::endian::big> {
static constexpr char const typeName[] = "int16_t";
};
Expand All @@ -107,10 +104,6 @@ struct BEInt64 : public BasicFieldType<int64_t, std::endian::big> {
static constexpr char const typeName[] = "int64_t";
};

struct BEUInt8 : public BasicFieldType<uint8_t, std::endian::big> {
static constexpr char const typeName[] = "uint8_t";
};

struct BEUInt16 : public BasicFieldType<uint16_t, std::endian::big> {
static constexpr char const typeName[] = "uint16_t";
};
Expand Down Expand Up @@ -160,11 +153,17 @@ struct CString {
memcpy(value, v.data(), S);
return *this;
}
void set(const type &v) { memcpy(value, v.data(), S); }
void set(const type &v) {
value[S] = 0;
memcpy(value, v.data(), S);
}
void serialize(IO<File> f) const { f->write(value, S); }
void deserialize(IO<File> f) { f->read(value, S); }
void reset() { memset(value, 0, S); }
char value[S];
void deserialize(IO<File> f) {
value[S] = 0;
f->read(value, S);
}
void reset() { memset(value, 0, S + 1); }
char value[S + 1];
};

template <typename FieldType, typename name>
Expand All @@ -183,6 +182,70 @@ struct StructField<StructType, irqus::typestring<C...>> : public StructType {
typedef irqus::typestring<C...> fieldName;
};

template <typename FieldType, typename name, size_t N>
struct RepeatedField;
template <typename FieldType, char... C, size_t N>
struct RepeatedField<FieldType, irqus::typestring<C...>, N> {
RepeatedField() {}
typedef irqus::typestring<C...> fieldName;
FieldType value[N];
FieldType &operator[](size_t i) {
if (i >= N) throw std::out_of_range("Index out of range");
return value[i];
}
const FieldType &operator[](size_t i) const {
if (i >= N) throw std::out_of_range("Index out of range");
return value[i];
}
void serialize(IO<File> f) const {
for (size_t i = 0; i < N; i++) {
value[i].serialize(f);
}
}
void deserialize(IO<File> f) {
for (size_t i = 0; i < N; i++) {
value[i].deserialize(f);
}
}
void reset() {
for (size_t i = 0; i < N; i++) {
value[i].reset();
}
}
};

template <typename FieldType, typename name, size_t N>
struct RepeatedStruct;
template <typename FieldType, char... C, size_t N>
struct RepeatedStruct<FieldType, irqus::typestring<C...>, N> {
RepeatedStruct() {}
typedef irqus::typestring<C...> fieldName;
FieldType value[N];
FieldType &operator[](size_t i) {
if (i >= N) throw std::out_of_range("Index out of range");
return value[i];
}
const FieldType &operator[](size_t i) const {
if (i >= N) throw std::out_of_range("Index out of range");
return value[i];
}
void serialize(IO<File> f) const {
for (size_t i = 0; i < N; i++) {
value[i].serialize(f);
}
}
void deserialize(IO<File> f) {
for (size_t i = 0; i < N; i++) {
value[i].deserialize(f);
}
}
void reset() {
for (size_t i = 0; i < N; i++) {
value[i].reset();
}
}
};

template <typename name, typename... fields>
class Struct;
template <char... C, typename... fields>
Expand All @@ -208,8 +271,8 @@ class Struct<irqus::typestring<C...>, fields...> : private std::tuple<fields...>
constexpr void reset() {}
template <size_t index, typename FieldType, typename... nestedFields>
constexpr void reset() {
FieldType &setting = std::get<index>(*this);
setting.reset();
FieldType &field = std::get<index>(*this);
field.reset();
reset<index + 1, nestedFields...>();
}
template <size_t index>
Expand Down
1 change: 1 addition & 0 deletions src/supportpsx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The code in this folder is licensed under the terms of the MIT license.

## Contents

* `adpcm.h` & `adpcm.cc` - Provides a simple ADPCM encoder. It is a re-creation of the original encvag.dll from Sony's development kit for the PlayStation 1, and is meant to produce similar results with a similar API.
* `binloader.h` & `binloader.cc` - Loads a PlayStation 1 binary file from a `File` abstraction to another `File` abstraction. The binary file can be of the following formats:
* PlayStation 1 executable file (needs the "PS-X EXE" signature)
* ELF
Expand Down
Loading

0 comments on commit 0293274

Please sign in to comment.