Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sozud committed Jan 21, 2024
0 parents commit 3f119fe
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build-linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install dosemu
run: |
git clone https://github.com/sozud/dosemu-deb.git
cd dosemu-deb
sudo apt-get install xfonts-utils
sudo dpkg -i fdpp_1.6-1_amd64.deb
sudo dpkg -i fdpp-dev_1.6-1_amd64.deb
sudo dpkg -i comcom32_0.1~alpha3-1_all.deb
sudo dpkg -i dosemu2_2.0~pre9-1_amd64.deb
- name: Build
run: sh split.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
libsnd_linked/build
src
asm
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "splat"]
path = splat
url = https://github.com/Xeeynamo/splat.git
[submodule "psx_psyq_signatures"]
path = psx_psyq_signatures
url = https://github.com/lab313ru/psx_psyq_signatures.git
[submodule "psy-q"]
path = psy-q
url = https://github.com/sozud/psy-q.git
12 changes: 12 additions & 0 deletions dosemurc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$_cpu_vm = "emulated"
$_cpu_vm_dpmi = "emulated"
$_sound = (off)
$_hogthreshold = (0)

$_cpuspeed = (333.333)
$_pci = (off)
$_rdtsc = (off)
$_term_color = (off)
$_ipxsupport = (off)
$_pktdriver = (off)

157 changes: 157 additions & 0 deletions gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#!/usr/bin/python3

# signatures:
# https://github.com/lab313ru/psx_psyq_signatures

import json

preamble ="""
options:
platform: psx
basename: main
base_path: .
build_path: build/us
target_path: libsnd_linked/build/main.exe
asm_path: asm/us/main
asset_path: assets/main
src_path: src/main
ld_script_path: build/us/main.ld
compiler: GCC
symbol_addrs_path: config/symbols.libsnd.txt
undefined_funcs_auto_path: config/undefined_funcs_auto.libsnd.main.txt
undefined_syms_auto_path: config/undefined_syms_auto.libsnd.main.txt
find_file_boundaries: yes
use_legacy_include_asm: no
migrate_rodata_to_functions: no
asm_jtbl_label_macro: jlabel
section_order:
- ".rodata"
- ".text"
- ".data"
segments:
- name: main
type: code
start: 0x00000800
vram: 0x80010000
subalign: 4
subsegments:
"""

def match_signature(data, sig: str):
if len(sig) == 0:
return 0

tokens = []
for ch in sig.split(" "):
if ch == " " or len(ch) == 0:
continue
if ch == "??":
tokens.append(None)
else:
tokens.append(int(ch, 16))

n_tokens = len(tokens)
i = 0
while i + n_tokens < len(data):
start = i
found = True
for t in tokens:
ch = data[i]
i += 1
if t == None:
continue
if t != ch:
found = False
break
if found:
return start
return -1


def parse_libsig(lib_name, path, data):
res = []
with open(path, "r") as f:
lib = json.load(f)

for obj in lib:
if "sig" not in obj:
continue
sig = obj["sig"]
offset = match_signature(data, sig)
if offset < 0:
continue
obj_name = str(obj["name"]).lower().replace(".obj", "")
r = dict()
r["lib"] = lib_name
r["obj"] = obj_name
r["data"] = obj
r["off"] = offset
res.append(r)
return res

with open("./libsnd_linked/build/main.exe", "rb") as f:
data = f.read()

res = []
for lib_name in [
# "libapi",
# "libc2",
# "libcard",
# "libcd",
# "libc",
# "libcomb",
# "libetc",
# "libgpu",
# "libgs",
# "libgte",
# "libgun",
# "libmath",
# "libpress",
"libsnd",
# "libsn",
# "libspu",
# "libtap",
]:
sig_path = f"./psx_psyq_signatures/350/{lib_name.upper()}.LIB.json"
res.extend(parse_libsig(lib_name, sig_path, data))
for obj_name in ["2mbyte", "8mbyte", "none2", "none3"]:
sig_path = f"./psx_psyq_signatures/350/{obj_name.upper()}.OBJ.json"
res.extend(parse_libsig(obj_name, sig_path, data))

for r in sorted(res, key=lambda item: item["off"]):
print(r["obj"], hex(r["off"]))

with open('splat.yaml', 'w') as file:
file.write(preamble)

# print splat subsegment
for r in sorted(res, key=lambda item: item["off"]):
lib_name = r["lib"]
obj_name = r["obj"]
obj = r["data"]
offset = r["off"]
# print(f"- [0x{offset:X}, c, psxsdk/{lib_name}, {obj_name}]")
file.write(f" - [0x{offset:X}, c, psxsdk/{lib_name}/{obj_name}]\n")
file.write(f" - [{hex(len(data))}]")

address_map = {}

with open('./libsnd_linked/build/main.map', 'r') as file:
start_parsing = False
for line in file:
if start_parsing:
# Split the line into address and name
try:
address, name = line.split(maxsplit=1)
except:
break
address = int(address, 16)
name = name.strip()
address_map[address] = name
elif "Address" in line and "Names in address order" in line:
# Start parsing when the header is found
start_parsing = True

with open('config/symbols.libsnd.txt', 'w') as file:
for address, name in address_map.items():
file.write(f"{name} = {hex(address)};\n")
16 changes: 16 additions & 0 deletions libsnd_linked/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rm -rf build
mkdir -p build
cp -r ../psy-q/PSYQ/* build
cp -r ../psy-q/PSX/INCLUDE/* build
cp -r ../psy-q/PSX/LIB/* build
cp -r ../psy-q/PSX/BIN/* build
cp ../dosemurc ./build
cp ./main.c build

unix2dos -n ./link.txt build/link.txt

export MYDIR=$(pwd)/build

cd $MYDIR && dosemu -quiet -dumb -f ./dosemurc -K . -E "ccpsx.exe -O2 -g -c -I. main.c -omain.obj"
cd $MYDIR && dosemu -quiet -dumb -f ./dosemurc -K . -E "psylink.exe /m /c /g @link.txt,main.cpe,main.sym,main.map"
cd $MYDIR && dosemu -quiet -dumb -f ./dosemurc -K . -E "cpe2x.exe main.cpe"
28 changes: 28 additions & 0 deletions libsnd_linked/link.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

org $80010000

text group ; main text group
bss group bss ; main data group

section .rdata,text ; main sections
section .text,text
section .data,text
section .sdata,text
section .sbss,bss
section .bss,bss

include "main.obj"

inclib libsn.lib
inclib libapi.lib
inclib libgpu.lib
inclib libspu.lib
inclib libsnd.lib
inclib libcd.lib
inclib libgs.lib
inclib libc.lib
inclib libetc.lib
inclib libgte.lib

regs pc=__SN_ENTRY_POINT ; entry point

132 changes: 132 additions & 0 deletions libsnd_linked/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#include <libsnd.h>

void do_libsnd()
{
SndVolume m_vol;
short voll, volr;
SsMarkCallbackProc proc;
VabHdr* vabhdr;
ProgAtr* progatr;
VagAtr* vagatr;

SsVabOpen (0, vabhdr);
SsVabClose (0);
SsVabTransCompleted (0);
SsVabOpenHead (0, 0);
SsVabTransBody (0, 0);
SsVabTransBodyPartly (0, 0, 0);
SsVabOpenHeadSticky (0, 0, 0);
SsVabTransfer (0, 0, 0, 0);

SsInit ();
SsInitHot ();
SsQuit ();
SsSetTableSize (0, 0, 0);
SsSetTickMode (0);
SsSetTickCallback ( proc);
SsStart ();
SsStart2 ();
SsEnd ();

SsSeqCalledTbyT ();
SsSeqOpen (0, 0);
SsSeqPlay (0, 0, 0);
SsSeqPause (0);
SsSeqReplay (0);
SsSeqStop (0);
SsSeqSetVol (0, 0, 0);
SsSeqSetNext (0, 0);
SsSeqSetCrescendo (0, 0, 0);
SsSeqSetDecrescendo (0, 0, 0);
SsSeqSetRitardando (0, 0, 0);
SsSeqSetAccelerando (0, 0, 0);
SsSeqClose (0);

SsSepOpen (0, 0, 0);
SsSepPlay (0, 0, 0, 0);
SsSepPause (0, 0);
SsSepReplay (0, 0);
SsSepStop (0, 0);
SsSepSetVol (0, 0, 0, 0);
SsSepSetCrescendo (0, 0, 0, 0);
SsSepSetDecrescendo (0, 0, 0, 0);
SsSepSetRitardando (0, 0, 0, 0);
SsSepSetAccelerando (0, 0, 0, 0);
SsSepClose (0);

SsVoKeyOn (0, 0, 0, 0);
SsVoKeyOff (0, 0);
SsSetMVol (0, 0);
SsGetMVol (&m_vol);
SsSetRVol (0, 0);
SsGetRVol (&m_vol);
SsSetMute (0);
SsSetSerialAttr (0, 0, 0);
SsGetSerialAttr (0, 0);
SsSetSerialVol (0, 0, 0);
SsGetSerialVol (0, &m_vol);
SsSetNck (0);
SsGetNck ();
SsSetNoiseOn (0, 0);
SsSetNoiseOff ();
SsSetMono ();
SsSetStereo ();

SsSetTempo (0, 0, 0);
SsSetLoop (0, 0, 0);
SsIsEos (0, 0);
SsPlayBack (0, 0, 0);
SsSetMarkCallback (0, 0, proc);
SsSetReservedVoice (0);

SsUtKeyOn (0, 0, 0, 0, 0, 0, 0);
SsUtKeyOff (0, 0, 0, 0, 0);

SsUtKeyOnV (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0);
SsUtKeyOffV (0);

SsUtPitchBend (0, 0, 0, 0, 0);
SsUtChangePitch (0, 0, 0, 0, 0,
0, 0);
SsUtChangeADSR (0, 0, 0, 0,
0, 0);
SsUtSetVabHdr (0, vabhdr);
SsUtGetVabHdr (0, vabhdr);
SsUtSetProgAtr (0, 0, 0);
SsUtGetProgAtr (0, 0, 0);
SsUtSetVagAtr (0, 0, 0, vagatr);
SsUtGetVagAtr (0, 0, 0, vagatr);
SsUtSetDetVVol (0, 0, 0);
SsUtGetDetVVol (0, 0, 0);
SsUtSetVVol (0, 0, 0);
SsUtGetVVol (0, 0, 0);
SsUtAutoVol (0, 0, 0, 0);
SsUtAutoPan (0, 0, 0, 0);
SsUtReverbOn ();
SsUtReverbOff ();
SsUtSetReverbType (0);
SsUtGetReverbType ();
SsUtSetReverbDepth (0, 0);
SsUtSetReverbFeedback (0);
SsUtSetReverbDelay (0);
SsUtAllKeyOff (0);

SsSetAutoKeyOffMode( 0 );
SsUtFlush( );
SsUtVibrateOn( 0 , 0 , 0 );
SsUtVibrateOff( 0 );

SsVabFakeHead (0, 0, 0);
SsVabFakeBody (0);
SsUtGetVBaddrInSB (0);
SsUtGetVagAddr( 0, 0 );
SsUtGetVagAddrFromTone(0, 0, 0);

SsSetNext (0, 0, 0, 0);
SsSeqGetVol (0, 0, 0, 0);
}

int main()
{
do_libsnd();
}
1 change: 1 addition & 0 deletions psx_psyq_signatures
Submodule psx_psyq_signatures added at e9e46e
1 change: 1 addition & 0 deletions psy-q
Submodule psy-q added at 8d34b6
1 change: 1 addition & 0 deletions splat
Submodule splat added at e60277

0 comments on commit 3f119fe

Please sign in to comment.