Skip to content

Commit

Permalink
nakano: Decompile rtconn.c (mostly)
Browse files Browse the repository at this point in the history
  • Loading branch information
entriphy committed Jan 15, 2024
1 parent 180c3a9 commit 50cfbbf
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/nakano/rtconn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "nakano/rtconn.h"
#include "nakano/main.h"
#include "nakano/route.h"

static RT_CONN *rt_start;
static RT_CONN *rt_conn[128];
static s32 rtcon_area_max;

void nkRtConnInit(qword *adr) {
RT_CONN *rt_conw;
s32 lp0;
s32 *version;

if (nkDG.flag & 4) {
return;
}
if ((*adr)[0] != 2) {
nkDG.flag |= 4;
return;
}

adr++;
rt_conw = (RT_CONN *)adr;
rt_start = rt_conw++;

lp0 = 0;
while (1) {
rt_conn[lp0] = rt_conw;
while (rt_conw->mode != rcZONEE) {
rt_conw++;
}
rt_conw++;
lp0++;
if (rt_conw->mode == rcSTAGEE) {
break;
}
if (lp0 > 128) {
exit(1);
}
};
rtcon_area_max = lp0;
}

void nkSetRtConn(OBJWORK *objw) {
RT_CONN *rt_conw = rt_start;
s32 bun1;
s32 sube_muki;

if (nkDG.flag & 4) {
GameGbl.st_rtn = 0;
GameGbl.st_mcn = 0;
return;
}

GameGbl.Re_st_rtn = rt_conw->ortn;
GameGbl.Re_st_mcn = rt_conw->ortcnt << 12;
GameGbl.Re_st_vision = GameGbl.vision & 0xFF00;
if (GameGbl.flag & 8) {
GameGbl.Re_st_height = GameGbl.retry_posy;
GameGbl.Re_st_muki = GameGbl.retry_muki;
GameGbl.Re_st_klomode = GameGbl.retry_bun1;
} else {
RT_WRK rtw;

SetRouteNo(&rtw, GameGbl.Re_st_rtn);
SetMichinori(&rtw, GameGbl.Re_st_mcn);
GameGbl.Re_st_height = MichiPosiY(&rtw);
GameGbl.retry_posy = GameGbl.Re_st_height;
bun1 = nkRtconnKloMode(&rtw, &sube_muki);
if (bun1 > 1) {
GameGbl.Re_st_muki = sube_muki;
} else {
GameGbl.Re_st_muki = rt_conw->omuki;
}
GameGbl.retry_muki = GameGbl.Re_st_muki;
GameGbl.Re_st_klomode = bun1;
GameGbl.retry_bun1 = bun1;
}

GameGbl.st_flag = rt_conw->flag;
if (rt_conw->flag & 8) {
GameGbl.Re_st_height = rt_conw->oheight;
}
OkSaveforReStart(GameGbl.Re_st_rtn, GameGbl.Re_st_mcn >> 12, GameGbl.Re_st_height, GameGbl.Re_st_klomode, GameGbl.Re_st_muki);
GameGbl.st_rtn = GameGbl.Re_st_rtn;
GameGbl.st_mcn = GameGbl.Re_st_mcn;
GameGbl.st_muki = GameGbl.Re_st_muki;
GameGbl.st_height = GameGbl.Re_st_height;
GameGbl.st_klomode = GameGbl.Re_st_klomode;
}

27 changes: 27 additions & 0 deletions src/nakano/rtconn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef RTCONN_H
#define RTCONN_H

#include "nakano.h"

#define rcSTART 1
#define rcDOOR 2
#define rcZONEE 3
#define rcSTAGEE 4
#define rcKLOMODE 5

typedef struct { // 0x20
/* 0x00 */ s16 irtn;
/* 0x02 */ s16 imuki;
/* 0x04 */ s16 nextst;
/* 0x06 */ s16 ortn;
/* 0x08 */ s32 irtcnt;
/* 0x0c */ s32 ortcnt;
/* 0x10 */ s16 omuki;
/* 0x12 */ s16 mode;
/* 0x14 */ s32 iheight;
/* 0x18 */ s32 oheight;
/* 0x1c */ s16 flag;
/* 0x1e */ s16 fdata;
} RT_CONN;

#endif
28 changes: 28 additions & 0 deletions src/nakano/vu0mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@

#include "nakano.h"

static inline s32 nkScrClip(sceVu0IVECTOR vi) {
return !(vi[0] <= 0x6C00 || vi[0] >= 0x9400 || vi[1] <= 0x7900 + (GameGbl.inter << 3) || vi[1] >= 0x7900 + (GameGbl.inter << 3) + 0xE00);
}

static inline void qword_Copy(void *dst, void *src) {
__asm__ volatile(
"lq $6,0x0(%1)\n"
"sq $6,0x0(%0)\n"
: : "r" (dst), "r" (src));
}

static inline void vu0_ITOF12Vector(sceVu0FVECTOR dst, sceVu0IVECTOR src) {
__asm__ volatile(
".set noreoder\n"
"lqc2 $vf8, 0x0(%1)\n"
"vitof12.xyzw $vf5, $vf8\n"
"sqc2 $vf5, 0x0(%0)\n"
Expand All @@ -13,14 +25,25 @@ static inline void vu0_ITOF12Vector(sceVu0FVECTOR dst, sceVu0IVECTOR src) {

static inline void vu0_ITOF0Vector(sceVu0FVECTOR dst, sceVu0IVECTOR src) {
__asm__ volatile(
".set noreoder\n"
"lqc2 $vf8, 0x0(%1)\n"
"vitof0.xyzw $vf5, $vf8\n"
"sqc2 $vf5, 0x0(%0)\n"
: : "r" (dst), "r" (src));
}

static inline void vu0_ITOF4Vector(sceVu0FVECTOR dst, sceVu0IVECTOR src) {
__asm__ volatile(
".set noreoder\n"
"lqc2 $vf8, 0x0(%1)\n"
"vitof4.xyzw $vf5, $vf8\n"
"sqc2 $vf5, 0x0(%0)\n"
: : "r" (dst), "r" (src));
}

static inline void vu0_FTOI4Vector(sceVu0IVECTOR dst, sceVu0FVECTOR src) {
__asm__ volatile(
".set noreoder\n"
"lqc2 $vf8, 0x0(%1)\n"
"vftoi4.xyzw $vf5, $vf8\n"
"sqc2 $vf5, 0x0(%0)\n"
Expand All @@ -29,6 +52,7 @@ static inline void vu0_FTOI4Vector(sceVu0IVECTOR dst, sceVu0FVECTOR src) {

static inline void vu0_FTOI12Vector(sceVu0IVECTOR dst, sceVu0FVECTOR src) {
__asm__ volatile(
".set noreoder\n"
"lqc2 $vf8, 0x0(%1)\n"
"vftoi12.xyzw $vf5, $vf8\n"
"sqc2 $vf5, 0x0(%0)\n"
Expand All @@ -37,6 +61,7 @@ static inline void vu0_FTOI12Vector(sceVu0IVECTOR dst, sceVu0FVECTOR src) {

static inline void vu0_Square(sceVu0FVECTOR dst, sceVu0FVECTOR src) {
__asm__ volatile(
".set noreoder\n"
"lqc2 $vf8, 0x0(%1)\n"
"vmul.xyzw $vf5, $vf8, $vf8\n"
"sqc2 $vf5, 0x0(%0)\n"
Expand All @@ -46,6 +71,7 @@ static inline void vu0_Square(sceVu0FVECTOR dst, sceVu0FVECTOR src) {
static inline f32 vu0_SquareRoot(f32 x) {
f32 ret;
__asm__ volatile(
".set noreoder\n"
"mfc1 $6, %1\n"
"qmtc2 $6, $vf4\n"
"vsqrt Q, $vf4x\n"
Expand All @@ -59,6 +85,7 @@ static inline f32 vu0_SquareRoot(f32 x) {
// ?
static inline void vu0_LoadMtx(sceVu0FMATRIX mtx) {
__asm__ volatile(
".set noreoder\n"
"lqc2 $vf4, 0x0(%0)\n"
"lqc2 $vf5, 0x10(%0)\n"
"lqc2 $vf6, 0x20(%0)\n"
Expand All @@ -69,6 +96,7 @@ static inline void vu0_LoadMtx(sceVu0FMATRIX mtx) {
// ?
static inline void vu0_Thing(sceVu0FVECTOR dst, sceVu0FVECTOR src) {
__asm__ volatile(
".set noreoder\n"
"lqc2 $vf8, 0x0(%1)\n"
"vmove.w $vf8, $vf0\n"
"vmulax.xyzw ACC, $vf4, $vf8x\n"
Expand Down

0 comments on commit 50cfbbf

Please sign in to comment.