port: 64-bit: more cleanup

replace the byte swapping macros with the ones from platform.h

rename and move things to match the rest of the code
This commit is contained in:
fgsfds committed 2024-11-12 10:34:10 +01:00
1 parent 68e3a79e47
commit 1448cd597a
15 files changed
+458 -548

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
#ifndef _IN_PREPROCESS_COMMON_H
#define _IN_PREPROCESS_COMMON_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <PR/ultratypes.h>
#include "types.h"
#include "constants.h"
#include "platform.h"
#include "system.h"
#include "romdata.h"
#include "preprocess.h"
#define MAX_PTR_MARKERS (1024 * 8)
#define PD_ALIGN(val, size) (((val) + ((size) - 1)) & ~((size) - 1))
#define PD_PTR_BASE(x, b) (void *)((u8 *)b + (uintptr_t)x)
#define PD_PTR_BASEOFS(x, b, d) (void *)((u8 *)b - d + (uintptr_t)x)
static inline f32 swapF32(f32 x) { *(u32*)&x = PD_BE32(*(u32*)&x); return x; }
static inline u32 swapU32(u32 x) { return PD_BE32(x); }
static inline s32 swapS32(s32 x) { return PD_BE32(x); }
static inline u16 swapU16(u16 x) { return PD_BE16(x); }
static inline s16 swapS16(s16 x) { return PD_BE16(x); }
static inline void* swapPtr(void** x) { return (void*)PD_BEPTR((uintptr_t)x); }
static inline struct coord swapCrd(struct coord crd) { crd.x = swapF32(crd.x); crd.y = swapF32(crd.y); crd.z = swapF32(crd.z); return crd; }
static inline u32 swapUnk(u32 x) { assert(0 && "unknown type"); return x; }
#define PD_SWAP_VAL(x) x = _Generic((x), \
f32: swapF32, \
u32: swapU32, \
s32: swapS32, \
u16: swapU16, \
s16: swapS16, \
struct coord: swapCrd, \
default: swapUnk \
)(x)
#define PD_SWAP_PTR(x) x = swapPtr((void *)(x))
// ptr marker functions
struct ptrmarker {
u32 ptr_src;
uintptr_t ptr_host;
};
void ptrAdd(u32 ptr_src, uintptr_t ptr_host);
struct ptrmarker* ptrFind(uintptr_t ptr_src);
void ptrReset(void);
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef _IN_PREPROCESS_GBI_H
#define _IN_PREPROCESS_GBI_H
#include "preprocess/common.h"
// gbi related functions
void gbiReset(void);
void gbiSetSegment(int segment, u32 offset);
void gbiSetVtx(u32 src_offset, u32 dst_offset);
u32 gbiConvertGdl(u8 *dst, u32 dstpos, u8 *src, u32 srcpos, int segment_cmds);
void gbiConvertVtx(u8* dst, u32 dstpos, int count);
void gbiGdlRewriteAddrs(u8* dst, u32 offset);
void gbiAddTexAddr(u32 src_offset, u32 dst_offset);
#endif
@@ -1,8 +1,7 @@
#ifndef _IN_SETUP_DECL
#define _IN_SETUP_DECL
#include "common.h"
#include "preprocess/common.h"
struct n64_stagesetup {
u32 ptr_waypoints;
@@ -639,4 +638,4 @@ struct n64_path {
u16 len;
};
#endif
#endif
+15 -16
View File
@@ -1,32 +1,31 @@
#include "common.h"
#include "system.h"
#include "preprocess/common.h"
static struct ptrmarker m_PtrMarkers[1024*8];
static int m_NumPtrMarkers;
static struct ptrmarker ptrMarkers[MAX_PTR_MARKERS];
static int numPtrMarkers;
void addMarker(u32 ptr_src, uintptr_t ptr_host)
void ptrAdd(u32 ptr_src, uintptr_t ptr_host)
{
if (m_NumPtrMarkers >= ARRAYCOUNT(m_PtrMarkers)) {
sysFatalError("Marker limit exceeded");
if (numPtrMarkers >= ARRAYCOUNT(ptrMarkers)) {
sysFatalError("ptrAdd(%p, %p): ptrmarker limit exceeded", (void *)(uintptr_t)ptr_src, (void *)ptr_host);
}
m_PtrMarkers[m_NumPtrMarkers].ptr_src = ptr_src;
m_PtrMarkers[m_NumPtrMarkers].ptr_host = ptr_host;
m_NumPtrMarkers++;
ptrMarkers[numPtrMarkers].ptr_src = ptr_src;
ptrMarkers[numPtrMarkers].ptr_host = ptr_host;
numPtrMarkers++;
}
struct ptrmarker* findPtrMarker(uintptr_t ptr_src)
struct ptrmarker *ptrFind(uintptr_t ptr_src)
{
for (int i = 0; i < m_NumPtrMarkers; i++) {
if (m_PtrMarkers[i].ptr_src == ptr_src) {
return &m_PtrMarkers[i];
for (int i = 0; i < numPtrMarkers; i++) {
if (ptrMarkers[i].ptr_src == ptr_src) {
return &ptrMarkers[i];
}
}
return NULL;
}
void resetMarkers()
void ptrReset(void)
{
m_NumPtrMarkers = 0;
numPtrMarkers = 0;
}
-129
View File
@@ -1,129 +0,0 @@
#ifndef _PDE_COMMON_H
#define _PDE_COMMON_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "platform.h"
#ifdef PLATFORM_WIN32
#include <winsock2.h>
// this BS comes from windows.h
#undef near
#undef far
#else
#include <arpa/inet.h>
#endif
#include <sys/param.h>
#include <PR/ultratypes.h>
#include "types.h"
#include "constants.h"
#include "system.h"
#if __BIG_ENDIAN__
#define htonll(x) (x)
#define ntohll(x) (x)
#else
#define htonll(x) ((((uint64_t)htonl(x&0xFFFFFFFF)) << 32) + htonl(x >> 32))
#define ntohll(x) ((((uint64_t)ntohl(x&0xFFFFFFFF)) << 32) + ntohl(x >> 32))
#endif
#define htobe16(x) htons(x)
#define htole16(x) (x)
#define be16toh(x) ntohs(x)
#define le16toh(x) (x)
#define htobe32(x) htonl(x)
#define htole32(x) (x)
#define be32toh(x) ntohl(x)
#define le32toh(x) (x)
#define htobe64(x) htonll(x)
#define htole64(x) (x)
#define be64toh(x) ntohll(x)
#define le64toh(x) (x)
#define srctoh16(value) ntohs(value)
#define srctoh32(value) ntohl(value)
#define srctoh64(value) ntohll(value)
#ifdef FORCE_BE32
#define htodst16(value) htons(value)
#define htodst32(value) htonl(value)
#define htodst64(value) htonll(value)
#define dsttoh16(value) ntohs(value)
#define dsttoh32(value) ntohl(value)
#define dsttoh64(value) ntohll(value)
#else
#define htodst16(value) (value)
#define htodst32(value) (value)
#define htodst64(value) (value)
#define dsttoh16(value) (value)
#define dsttoh32(value) (value)
#define dsttoh64(value) (value)
#endif
#define srctodst16(value) htodst16(srctoh16(value))
#define srctodst32(value) htodst32(srctoh32(value))
#define srctodst64(value) htodst64(srctoh64(value))
#ifdef FORCE_BE32
#define uintptr_t u32
#endif
#define ALIGN(val, size) ((val + (size - 1)) & ~(size - 1))
#define PD_PTR_BASE(x, b) (void *)((u8 *)b + (uintptr_t)x)
#define PD_PTR_BASEOFS(x, b, d) (void *)((u8 *)b - d + (uintptr_t)x)
static inline f32 swapF32(f32 x) { *(u32*)&x = PD_BE32(*(u32*)&x); return x; }
static inline u32 swapU32(u32 x) { return PD_BE32(x); }
static inline s32 swapS32(s32 x) { return PD_BE32(x); }
static inline u16 swapU16(u16 x) { return PD_BE16(x); }
static inline s16 swapS16(s16 x) { return PD_BE16(x); }
static inline void* swapPtr(void** x) { return (void*)PD_BEPTR((uintptr_t)x); }
static inline struct coord swapCrd(struct coord crd) { crd.x = swapF32(crd.x); crd.y = swapF32(crd.y); crd.z = swapF32(crd.z); return crd; }
static inline u32 swapUnk(u32 x) { assert(0 && "unknown type"); return x; }
#define PD_SWAP_VAL(x) x = _Generic((x), \
f32: swapF32, \
u32: swapU32, \
s32: swapS32, \
u16: swapU16, \
s16: swapS16, \
struct coord: swapCrd, \
default: swapUnk \
)(x)
#define PD_SWAP_PTR(x) x = swapPtr((void *)(x))
// gbi related functions
void gbiReset(void);
void gbiSetSegment(int segment, u32 offset);
void gbiSetVtx(u32 src_offset, u32 dst_offset);
u32 gbiConvertGdl(u8 *dst, u32 dstpos, u8 *src, u32 srcpos, int segment_cmds);
void gbiConvertVtx(u8* dst, u32 dstpos, int count);
void gbiGdlRewriteAddrs(u8* dst, u32 offset);
void gbiAddTexAddr(u32 src_offset, u32 dst_offset);
// ptr marker functions
struct ptrmarker {
u32 ptr_src;
uintptr_t ptr_host;
};
void addMarker(u32 ptr_src, uintptr_t ptr_host);
struct ptrmarker* findPtrMarker(uintptr_t ptr_src);
void resetMarkers();
#endif
+63 -68
View File
@@ -5,12 +5,9 @@
#include "data.h"
#include "bss.h"
#include "platform.h"
#include "common.h"
#include "system.h"
int m_SizeGDLs;
#include "preprocess/common.h"
#include "preprocess/gbi.h"
/**
* 4 bytes decompressed size of primary data
@@ -180,10 +177,10 @@ static void convertPrimaryRooms(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos)
}
for (int i = 0; i < m_NumRooms + 1; i++) {
host_rooms[i].ptr_gfxdata = srctodst32(n64_rooms[i].ptr_gfxdata);
host_rooms[i].pos[0] = srctodst32(n64_rooms[i].pos[0]);
host_rooms[i].pos[1] = srctodst32(n64_rooms[i].pos[1]);
host_rooms[i].pos[2] = srctodst32(n64_rooms[i].pos[2]);
host_rooms[i].ptr_gfxdata = PD_BE32(n64_rooms[i].ptr_gfxdata);
host_rooms[i].pos[0] = PD_BE32(n64_rooms[i].pos[0]);
host_rooms[i].pos[1] = PD_BE32(n64_rooms[i].pos[1]);
host_rooms[i].pos[2] = PD_BE32(n64_rooms[i].pos[2]);
host_rooms[i].br_light_min = n64_rooms[i].br_light_min;
host_rooms[i].br_light_max = n64_rooms[i].br_light_max;
}
@@ -206,9 +203,9 @@ static void convertPrimaryPortals(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos, u3
// Convert portals
for (int i = 0; i < numportals; i++) {
host_portals[i].verticesoffset = srctodst16(n64_portals[i].verticesoffset);
host_portals[i].roomnum1 = srctodst16(n64_portals[i].roomnum1);
host_portals[i].roomnum2 = srctodst16(n64_portals[i].roomnum2);
host_portals[i].verticesoffset = PD_BE16(n64_portals[i].verticesoffset);
host_portals[i].roomnum1 = PD_BE16(n64_portals[i].roomnum1);
host_portals[i].roomnum2 = PD_BE16(n64_portals[i].roomnum2);
host_portals[i].flags = n64_portals[i].flags;
}
@@ -225,12 +222,12 @@ static void convertPrimaryPortals(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos, u3
host_pvertices->count = n64_pvertices->count;
for (int j = 0; j < host_pvertices->count; j++) {
//host_pvertices->vertices[j].x = srctodst32(n64_pvertices->vertices[j].x);
//host_pvertices->vertices[j].y = srctodst32(n64_pvertices->vertices[j].y);
//host_pvertices->vertices[j].z = srctodst32(n64_pvertices->vertices[j].z);
host_pvertices->vertices[j][0] = srctodst32(n64_pvertices->vertices[j][0]);
host_pvertices->vertices[j][1] = srctodst32(n64_pvertices->vertices[j][1]);
host_pvertices->vertices[j][2] = srctodst32(n64_pvertices->vertices[j][2]);
//host_pvertices->vertices[j].x = PD_BE32(n64_pvertices->vertices[j].x);
//host_pvertices->vertices[j].y = PD_BE32(n64_pvertices->vertices[j].y);
//host_pvertices->vertices[j].z = PD_BE32(n64_pvertices->vertices[j].z);
host_pvertices->vertices[j][0] = PD_BE32(n64_pvertices->vertices[j][0]);
host_pvertices->vertices[j][1] = PD_BE32(n64_pvertices->vertices[j][1]);
host_pvertices->vertices[j][2] = PD_BE32(n64_pvertices->vertices[j][2]);
}
*srcpos += 4 + host_pvertices->count * 12;
@@ -255,7 +252,7 @@ static void convertPrimaryBgCmds(u8 *dst, u32 *dstpos, u8 *src, u32 dst_portalvt
for (int i = 0; i < num_cmds; i++) {
host_cmds[i].type = n64_cmds[i].type;
host_cmds[i].len = n64_cmds[i].len;
host_cmds[i].param = srctodst32(n64_cmds[i].param);
host_cmds[i].param = PD_BE32(n64_cmds[i].param);
if (host_cmds[i].type == 0x64) {
u32 offset = host_cmds[i].param - src_portalvtxs;
@@ -273,8 +270,8 @@ static void convertPrimaryLights(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos, u32
int num_lights = (end - *srcpos) / sizeof(struct light);
for (int i = 0; i < num_lights; i++) {
host_lights[i].roomnum = srctodst16(n64_lights[i].roomnum);
host_lights[i].colour = srctodst16(n64_lights[i].colour);
host_lights[i].roomnum = PD_BE16(n64_lights[i].roomnum);
host_lights[i].colour = PD_BE16(n64_lights[i].colour);
host_lights[i].brightness = n64_lights[i].brightness;
host_lights[i].sparkable = n64_lights[i].sparkable;
host_lights[i].healthy = n64_lights[i].healthy;
@@ -287,9 +284,9 @@ static void convertPrimaryLights(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos, u32
host_lights[i].dirz = n64_lights[i].dirz;
for (int j = 0; j < 4; j++) {
host_lights[i].bbox[j].x = srctodst16(n64_lights[i].bbox[j].x);
host_lights[i].bbox[j].y = srctodst16(n64_lights[i].bbox[j].y);
host_lights[i].bbox[j].z = srctodst16(n64_lights[i].bbox[j].z);
host_lights[i].bbox[j].x = PD_BE16(n64_lights[i].bbox[j].x);
host_lights[i].bbox[j].y = PD_BE16(n64_lights[i].bbox[j].y);
host_lights[i].bbox[j].z = PD_BE16(n64_lights[i].bbox[j].z);
}
}
@@ -304,7 +301,7 @@ void relinkPtr(uintptr_t* ptr)
{
if (!*ptr) return;
struct ptrmarker* marker = findPtrMarker(*ptr);
struct ptrmarker* marker = ptrFind(*ptr);
if (!marker) {
sysFatalError("[BG] WARNING: Unable to relink pointer: %p\n", ptr);
}
@@ -314,7 +311,7 @@ void relinkPtr(uintptr_t* ptr)
static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
{
resetMarkers();
ptrReset();
gbiReset();
u32 dst_roomoffset = src_ofs;
@@ -325,14 +322,14 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
struct n64_roomgfxdata *src_header = (struct n64_roomgfxdata*)src;
struct host_roomgfxdata *dst_header = (struct host_roomgfxdata*)dst;
dst_header->ptr_vertices = srctoh32(src_header->ptr_vertices);
dst_header->ptr_colours = srctoh32(src_header->ptr_colours);
dst_header->ptr_opablocks = srctoh32(src_header->ptr_opablocks);
dst_header->ptr_xlublocks = srctoh32(src_header->ptr_xlublocks);
dst_header->lightsindex = srctoh16(src_header->lightsindex);
dst_header->numlights = srctoh16(src_header->numlights);
dst_header->numvertices = srctoh16(src_header->numvertices);
dst_header->numcolours = srctoh16(src_header->numcolours);
dst_header->ptr_vertices = PD_BE32(src_header->ptr_vertices);
dst_header->ptr_colours = PD_BE32(src_header->ptr_colours);
dst_header->ptr_opablocks = PD_BE32(src_header->ptr_opablocks);
dst_header->ptr_xlublocks = PD_BE32(src_header->ptr_xlublocks);
dst_header->lightsindex = PD_BE16(src_header->lightsindex);
dst_header->numlights = PD_BE16(src_header->numlights);
dst_header->numvertices = PD_BE16(src_header->numvertices);
dst_header->numcolours = PD_BE16(src_header->numcolours);
intptr_t endpos = dst_header->ptr_vertices - src_ofs;
uintptr_t curpos_src = sizeof(struct n64_roomgfxdata);
@@ -350,12 +347,12 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
struct host_roomblock *dest_roomblock = (struct host_roomblock*)&dst[curpos_dst];
dest_roomblock->type = src_roomblock->type;
dest_roomblock->ptr_next = srctoh32(src_roomblock->ptr_next);
dest_roomblock->ptr_gdl = srctoh32(src_roomblock->ptr_gdl);
dest_roomblock->ptr_vertices = srctoh32(src_roomblock->ptr_vertices);
dest_roomblock->ptr_colours = srctoh32(src_roomblock->ptr_colours);
dest_roomblock->ptr_next = PD_BE32(src_roomblock->ptr_next);
dest_roomblock->ptr_gdl = PD_BE32(src_roomblock->ptr_gdl);
dest_roomblock->ptr_vertices = PD_BE32(src_roomblock->ptr_vertices);
dest_roomblock->ptr_colours = PD_BE32(src_roomblock->ptr_colours);
addMarker(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
ptrAdd(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
if (src_roomblock->type == BLOCK_PARENT) {
ncoords++;
@@ -363,7 +360,7 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
if (vtx_ptr < endpos) endpos = vtx_ptr;
}
else if (src_roomblock->ptr_gdl) {
gdls_addr[numgdls++] = srctoh32(src_roomblock->ptr_gdl) - src_ofs;
gdls_addr[numgdls++] = PD_BE32(src_roomblock->ptr_gdl) - src_ofs;
}
curpos_src += sizeof(struct n64_roomblock);
@@ -376,15 +373,15 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
u32 *src_coord = (u32*)(src + curpos_src);
u32 *dst_coord = (u32*)(dst + curpos_dst);
dst_coord[0] = srctoh32(src_coord[0]);
dst_coord[1] = srctoh32(src_coord[1]);
dst_coord[2] = srctoh32(src_coord[2]);
dst_coord[0] = PD_BE32(src_coord[0]);
dst_coord[1] = PD_BE32(src_coord[1]);
dst_coord[2] = PD_BE32(src_coord[2]);
dst_coord[3] = srctoh32(src_coord[3]);
dst_coord[4] = srctoh32(src_coord[4]);
dst_coord[5] = srctoh32(src_coord[5]);
dst_coord[3] = PD_BE32(src_coord[3]);
dst_coord[4] = PD_BE32(src_coord[4]);
dst_coord[5] = PD_BE32(src_coord[5]);
addMarker(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
ptrAdd(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
curpos_src += 6 * sizeof(u32);
curpos_dst += 6 * sizeof(u32);
@@ -396,7 +393,7 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
uintptr_t ptr_src_vertices = curpos_src = ALIGN8(dst_header->ptr_vertices - src_ofs);
uintptr_t ptr_dst_vertices = curpos_dst + dst_roomoffset;
addMarker(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
ptrAdd(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
uintptr_t vtx_end = dst_header->ptr_colours - src_ofs;
@@ -404,15 +401,15 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
struct vtx *src_vtx = (struct vtx*)(src + curpos_src);
struct vtx *dst_vtx = (struct vtx*)(dst + curpos_dst);
dst_vtx->coord[0] = srctoh16(src_vtx->coord[0]);
dst_vtx->coord[1] = srctoh16(src_vtx->coord[1]);
dst_vtx->coord[2] = srctoh16(src_vtx->coord[2]);
dst_vtx->coord[0] = PD_BE16(src_vtx->coord[0]);
dst_vtx->coord[1] = PD_BE16(src_vtx->coord[1]);
dst_vtx->coord[2] = PD_BE16(src_vtx->coord[2]);
dst_vtx->flag = src_vtx->flag;
dst_vtx->color = src_vtx->color;
dst_vtx->s = srctoh16(src_vtx->s);
dst_vtx->t = srctoh16(src_vtx->t);
dst_vtx->s = PD_BE16(src_vtx->s);
dst_vtx->t = PD_BE16(src_vtx->t);
curpos_src += sizeof(struct vtx);
curpos_dst += sizeof(struct vtx);
@@ -428,7 +425,7 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
ptr_src_colors = curpos_src = ALIGN8(dst_header->ptr_colours - src_ofs);
ptr_dst_colors = curpos_dst + dst_roomoffset;
addMarker(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
ptrAdd(curpos_src + src_ofs, curpos_dst + dst_roomoffset);
uintptr_t col_end = numgdls > 0 != 0 ? gdls_addr[0] : infsize;
size_t col_len = col_end - curpos_src;
@@ -441,14 +438,12 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs)
// gdls
gbiSetVtx(src_header->ptr_vertices, ptr_src_vertices);
gbiSetSegment(0x0e, dst_header->ptr_vertices);
m_SizeGDLs = 0;
uintptr_t gdlstart = curpos_dst;
for (size_t i = 0; i < numgdls; i++) {
addMarker(gdls_addr[i] + src_ofs, curpos_dst + dst_roomoffset);
ptrAdd(gdls_addr[i] + src_ofs, curpos_dst + dst_roomoffset);
curpos_dst = gbiConvertGdl(dst, curpos_dst, src, gdls_addr[i], 1);
}
m_SizeGDLs = curpos_dst - gdlstart;
// relink ptrs: roomblocks
for (size_t i = 0; i < numblocks; i++) {
@@ -489,7 +484,7 @@ static u32 convertSection1(u8 *dst, u8 *src, u32 ofs)
srcpos += sizeof(struct n64_primaryheader);
dstpos += sizeof(*host_primary_header);
u32 src_bgcmds = srctodst32(n64_primary_header->ptr_bgcmds) - ofs;
u32 src_bgcmds = PD_BE32(n64_primary_header->ptr_bgcmds) - ofs;
host_primary_header->unused1 = 0;
host_primary_header->unused2 = 0;
@@ -499,12 +494,12 @@ static u32 convertSection1(u8 *dst, u8 *src, u32 ofs)
if (n64_primary_header->ptr_lights) {
host_primary_header->ptr_lights = dstpos + ofs;
srcpos = srctodst32(n64_primary_header->ptr_lights) - ofs;
srcpos = PD_BE32(n64_primary_header->ptr_lights) - ofs;
convertPrimaryLights(dst, &dstpos, src, &srcpos, src_bgcmds);
}
host_primary_header->ptr_portals = dstpos + ofs;
srcpos = srctodst32(n64_primary_header->ptr_portals) - ofs;
srcpos = PD_BE32(n64_primary_header->ptr_portals) - ofs;
u32 src_portalvtxs, dst_portalvtxs;
convertPrimaryPortals(dst, &dstpos, src, &srcpos, &src_portalvtxs, &dst_portalvtxs);
@@ -521,7 +516,7 @@ static void convertSection2TextureNums(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpo
int count = srclen / sizeof(u16);
for (int i = 0; i < count; i++) {
dst_ids[i] = srctodst16(src_ids[i]);
dst_ids[i] = PD_BE16(src_ids[i]);
}
*srcpos += srclen;
@@ -534,12 +529,12 @@ static void convertSection3Bboxes(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos)
s16 *dst_bboxes = (s16 *) &dst[*dstpos];
for (int i = 0; i < m_NumRooms; i++) {
dst_bboxes[i * 6 + 0] = srctodst16(src_bboxes[i * 6 + 0]);
dst_bboxes[i * 6 + 1] = srctodst16(src_bboxes[i * 6 + 1]);
dst_bboxes[i * 6 + 2] = srctodst16(src_bboxes[i * 6 + 2]);
dst_bboxes[i * 6 + 3] = srctodst16(src_bboxes[i * 6 + 3]);
dst_bboxes[i * 6 + 4] = srctodst16(src_bboxes[i * 6 + 4]);
dst_bboxes[i * 6 + 5] = srctodst16(src_bboxes[i * 6 + 5]);
dst_bboxes[i * 6 + 0] = PD_BE16(src_bboxes[i * 6 + 0]);
dst_bboxes[i * 6 + 1] = PD_BE16(src_bboxes[i * 6 + 1]);
dst_bboxes[i * 6 + 2] = PD_BE16(src_bboxes[i * 6 + 2]);
dst_bboxes[i * 6 + 3] = PD_BE16(src_bboxes[i * 6 + 3]);
dst_bboxes[i * 6 + 4] = PD_BE16(src_bboxes[i * 6 + 4]);
dst_bboxes[i * 6 + 5] = PD_BE16(src_bboxes[i * 6 + 5]);
}
*srcpos += sizeof(s16) * 6 * (m_NumRooms - 1);
+5 -7
View File
@@ -2,9 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "romdata.h"
#include "system.h"
#include "preprocess/common.h"
static int getNextNonZero(u8 *src, u32 offset, size_t len)
{
@@ -13,7 +11,7 @@ static int getNextNonZero(u8 *src, u32 offset, size_t len)
while (ptr < end) {
if (*ptr != 0) {
return srctoh32(*ptr);
return PD_BE32(*ptr);
}
ptr++;
@@ -37,7 +35,7 @@ u32 convertLangFile(u8 *dst, u8 *src, size_t srclen)
{
// Convert it
u32 *src_offsets = (u32 *) src;
size_t src_ptr_table_len = srctoh32(src_offsets[0]);
size_t src_ptr_table_len = PD_BE32(src_offsets[0]);
size_t src_str_table_len = srclen - src_ptr_table_len;
int num_strings = getNumStrings(src, srclen);
size_t dst_ptr_table_len = num_strings * sizeof(uintptr_t);
@@ -48,11 +46,11 @@ u32 convertLangFile(u8 *dst, u8 *src, size_t srclen)
uintptr_t *dst_offsets = (uintptr_t *) dst;
for (int i = 0; i < num_strings; i++) {
u32 src_offset = srctoh32(src_offsets[i]);
u32 src_offset = PD_BE32(src_offsets[i]);
if (src_offset) {
// Write pointer
dst_offsets[i] = htodst32(cur_dst_offset);
dst_offsets[i] = (cur_dst_offset);
// Write string
u32 end = getNextNonZero(src, (i + 1) * 4, num_strings * 4);
+146 -147
View File
@@ -6,9 +6,8 @@
#include "gbi.h"
#include "game/texdecompress.h"
#include "common.h"
#include "romdata.h"
#include "system.h"
#include "preprocess/common.h"
#include "preprocess/gbi.h"
enum contenttype {
/* 0*/ CT_MODELDEF,
@@ -402,10 +401,10 @@ static void populateMarkers(u8 *src)
switch (marker->type) {
case CT_MODELDEF:
struct src_modeldef *src_modeldef = src_thing;
int num_texconfigs = srctoh16(src_modeldef->numtexconfigs);
u32 texconfigpos = srctoh32(src_modeldef->ptr_texconfigs);
set_marker(srctoh32(src_modeldef->ptr_rootnode), CT_NODE, marker->src_offset);
set_marker(srctoh32(src_modeldef->ptr_parts), CT_PARTS, marker->src_offset);
int num_texconfigs = PD_BE16(src_modeldef->numtexconfigs);
u32 texconfigpos = PD_BE32(src_modeldef->ptr_texconfigs);
set_marker(PD_BE32(src_modeldef->ptr_rootnode), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_modeldef->ptr_parts), CT_PARTS, marker->src_offset);
for (int i = 0; i < num_texconfigs; i++) {
set_marker(texconfigpos + sizeof(struct src_texconfig) * i, CT_TEXCONFIG, marker->src_offset);
@@ -413,26 +412,26 @@ static void populateMarkers(u8 *src)
break;
case CT_NODE:
struct src_modelnode *src_node = src_thing;
u32 node_type = srctoh16(src_node->type) & 0xff;
set_marker(srctoh32(src_node->ptr_rodata), m_NodeTypeToContentType[node_type], marker->src_offset);
set_marker(srctoh32(src_node->ptr_parent), CT_NODE, marker->src_offset);
set_marker(srctoh32(src_node->ptr_next), CT_NODE, marker->src_offset);
set_marker(srctoh32(src_node->ptr_prev), CT_NODE, marker->src_offset);
set_marker(srctoh32(src_node->ptr_child), CT_NODE, marker->src_offset);
u32 node_type = PD_BE16(src_node->type) & 0xff;
set_marker(PD_BE32(src_node->ptr_rodata), m_NodeTypeToContentType[node_type], marker->src_offset);
set_marker(PD_BE32(src_node->ptr_parent), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_node->ptr_next), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_node->ptr_prev), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_node->ptr_child), CT_NODE, marker->src_offset);
break;
case CT_TEXCONFIG:
struct src_texconfig *src_texconfig = src_thing;
if ((srctoh32(src_texconfig->ptr) & 0xff000000) == 0x05000000) {
set_marker(srctoh32(src_texconfig->ptr), CT_TEXDATA, marker->src_offset);
if ((PD_BE32(src_texconfig->ptr) & 0xff000000) == 0x05000000) {
set_marker(PD_BE32(src_texconfig->ptr), CT_TEXDATA, marker->src_offset);
}
break;
case CT_PARTS:
struct src_modeldef *src_modeldef2 = (struct src_modeldef *) src;
u32 *src_parts = (u32 *) src_thing;
int num_parts = srctoh16(src_modeldef2->numparts);
int num_parts = PD_BE16(src_modeldef2->numparts);
for (int i = 0; i < num_parts; i++) {
set_marker(srctoh32(src_parts[i]), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_parts[i]), CT_NODE, marker->src_offset);
}
break;
case CT_RODATA_CHRINFO:
@@ -441,31 +440,31 @@ static void populateMarkers(u8 *src)
break;
case CT_RODATA_GUNDL:
struct src_rodata_gundl *src_gundl = src_thing;
set_marker(srctoh32(src_gundl->ptr_opagdl), CT_GDL, marker->src_offset);
set_marker(srctoh32(src_gundl->ptr_xlugdl), CT_GDL, marker->src_offset);
set_marker(srctoh32(src_gundl->ptr_vertices), CT_VTXCOL, marker->src_offset);
set_marker(PD_BE32(src_gundl->ptr_opagdl), CT_GDL, marker->src_offset);
set_marker(PD_BE32(src_gundl->ptr_xlugdl), CT_GDL, marker->src_offset);
set_marker(PD_BE32(src_gundl->ptr_vertices), CT_VTXCOL, marker->src_offset);
break;
case CT_RODATA_DISTANCE:
struct src_rodata_distance *src_dist = src_thing;
set_marker(srctoh32(src_dist->ptr_target), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_dist->ptr_target), CT_NODE, marker->src_offset);
break;
case CT_RODATA_REORDER:
struct src_rodata_reorder *src_reorder = src_thing;
set_marker(srctoh32(src_reorder->ptr_node_unk18), CT_NODE, marker->src_offset);
set_marker(srctoh32(src_reorder->ptr_node_unk1c), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_reorder->ptr_node_unk18), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_reorder->ptr_node_unk1c), CT_NODE, marker->src_offset);
break;
case CT_RODATA_CHRGUNFIRE:
struct src_rodata_chrgunfire *src_chrgunfire = src_thing;
set_marker(srctoh32(src_chrgunfire->ptr_texture), CT_TEXCONFIG, marker->src_offset);
set_marker(PD_BE32(src_chrgunfire->ptr_texture), CT_TEXCONFIG, marker->src_offset);
break;
case CT_RODATA_TOGGLE:
struct src_rodata_toggle *src_toggle = src_thing;
set_marker(srctoh32(src_toggle->ptr_target), CT_NODE, marker->src_offset);
set_marker(PD_BE32(src_toggle->ptr_target), CT_NODE, marker->src_offset);
break;
case CT_RODATA_STARGUNFIRE:
struct src_rodata_stargunfire *src_stargunfire = src_thing;
colstart = srctoh32(src_stargunfire->unk00)*4*(sizeof(s16) * 6);
u32 vtxstart = srctoh32(src_stargunfire->ptr_vertices);
colstart = PD_BE32(src_stargunfire->unk00)*4*(sizeof(s16) * 6);
u32 vtxstart = PD_BE32(src_stargunfire->ptr_vertices);
u32 vtxend = vtxstart + colstart;
colstart = ALIGN8(vtxstart + colstart);
set_marker(vtxstart, CT_VTXCOL4, marker->src_offset);
@@ -473,14 +472,14 @@ static void populateMarkers(u8 *src)
set_marker(vtxend, CT_SKIP, marker->src_offset);
}
set_marker(colstart, CT_VTXCOL, marker->src_offset);
set_marker(srctoh32(src_stargunfire->ptr_gdl), CT_GDL, marker->src_offset);
set_marker(PD_BE32(src_stargunfire->ptr_gdl), CT_GDL, marker->src_offset);
break;
case CT_RODATA_DL:
struct src_rodata_dl *src_dl = src_thing;
set_marker(srctoh32(src_dl->ptr_opagdl), CT_GDL, marker->src_offset);
set_marker(srctoh32(src_dl->ptr_xlugdl), CT_GDL, marker->src_offset);
set_marker(srctoh32(src_dl->ptr_colours), CT_VTXCOL, marker->src_offset);
set_marker(srctoh32(src_dl->ptr_vertices), CT_VTXCOL, marker->src_offset);
set_marker(PD_BE32(src_dl->ptr_opagdl), CT_GDL, marker->src_offset);
set_marker(PD_BE32(src_dl->ptr_xlugdl), CT_GDL, marker->src_offset);
set_marker(PD_BE32(src_dl->ptr_colours), CT_VTXCOL, marker->src_offset);
set_marker(PD_BE32(src_dl->ptr_vertices), CT_VTXCOL, marker->src_offset);
break;
case CT_TEXDATA:
case CT_VTXCOL:
@@ -526,7 +525,7 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len)
u32 src_end = i < m_NumMarkers - 1 ? m_Markers[i + 1].src_offset : src_file_len;
u32 src_len = src_end - marker->src_offset;
dstpos = ALIGN(dstpos, m_AlignConfigs[marker->type].before);
dstpos = PD_ALIGN(dstpos, m_AlignConfigs[marker->type].before);
marker->dst_offset = dstpos;
void *dst_thing = &dst[dstpos];
@@ -535,18 +534,18 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len)
case CT_MODELDEF:
struct src_modeldef *src_modeldef = src_thing;
struct dst_modeldef *dst_modeldef = dst_thing;
dst_modeldef->ptr_skel = srctodst32(src_modeldef->ptr_skel);
dst_modeldef->numparts = srctodst16(src_modeldef->numparts);
dst_modeldef->nummatrices = srctodst16(src_modeldef->nummatrices);
dst_modeldef->scale = srctodst32(src_modeldef->scale);
dst_modeldef->rwdatalen = srctodst16(src_modeldef->rwdatalen);
dst_modeldef->numtexconfigs = srctodst16(src_modeldef->numtexconfigs);
dst_modeldef->ptr_skel = PD_BE32(src_modeldef->ptr_skel);
dst_modeldef->numparts = PD_BE16(src_modeldef->numparts);
dst_modeldef->nummatrices = PD_BE16(src_modeldef->nummatrices);
dst_modeldef->scale = PD_BE32(src_modeldef->scale);
dst_modeldef->rwdatalen = PD_BE16(src_modeldef->rwdatalen);
dst_modeldef->numtexconfigs = PD_BE16(src_modeldef->numtexconfigs);
dstpos += sizeof(*dst_modeldef);
break;
case CT_NODE:
struct src_modelnode *src_node = src_thing;
struct dst_modelnode *dst_node = dst_thing;
dst_node->type = srctodst16(src_node->type);
dst_node->type = PD_BE16(src_node->type);
dstpos += sizeof(*dst_node);
break;
case CT_TEXCONFIG:
@@ -554,8 +553,8 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len)
struct dst_texconfig *dst_texconfig = dst_thing;
while (src_len >= sizeof(*src_texconfig)) {
if ((srctoh32(src_texconfig->ptr) & 0xff000000) != 0x05000000) {
dst_texconfig->ptr = srctodst32(src_texconfig->ptr);
if ((PD_BE32(src_texconfig->ptr) & 0xff000000) != 0x05000000) {
dst_texconfig->ptr = PD_BE32(src_texconfig->ptr);
}
dst_texconfig->width = src_texconfig->width;
@@ -581,12 +580,12 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len)
struct src_modeldef *src_modeldef2 = (struct src_modeldef *) src;
u32 *src_parts = (u32 *) src_thing;
uintptr_t *dst_parts = (uintptr_t *) dst_thing;
int num_parts = srctoh16(src_modeldef2->numparts);
int num_parts = PD_BE16(src_modeldef2->numparts);
u16 *src_nums = (u16 *) &src_parts[num_parts];
u16 *dst_nums = (u16 *) &dst_parts[num_parts];
for (int i = 0; i < num_parts; i++) {
dst_nums[i] = srctodst16(src_nums[i]);
dst_nums[i] = PD_BE16(src_nums[i]);
}
dstpos += num_parts * sizeof(uintptr_t) + num_parts * sizeof(u16);
if (num_parts) {
@@ -606,18 +605,18 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len)
if (parent->type == CT_RODATA_GUNDL) {
struct src_rodata_gundl *src_rodata = (struct src_rodata_gundl *) &src[parent->src_offset];
struct dst_rodata_gundl *dst_rodata = (struct dst_rodata_gundl *) &dst[parent->dst_offset];
src_vtx = srctoh32(src_rodata->ptr_vertices) & 0x00ffffff;
dst_vtx = dsttoh32(dst_rodata->ptr_vertices) & 0x00ffffff;
src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff;
dst_vtx = (dst_rodata->ptr_vertices) & 0x00ffffff;
} else if (parent->type == CT_RODATA_STARGUNFIRE) {
struct src_rodata_stargunfire *src_rodata = (struct src_rodata_stargunfire *) &src[parent->src_offset];
struct dst_rodata_stargunfire *dst_rodata = (struct dst_rodata_stargunfire *) &dst[parent->dst_offset];
src_vtx = srctoh32(src_rodata->ptr_vertices) & 0x00ffffff;
dst_vtx = dsttoh32(dst_rodata->ptr_vertices) & 0x00ffffff;
src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff;
dst_vtx = (dst_rodata->ptr_vertices) & 0x00ffffff;
} else if (parent->type == CT_RODATA_DL) {
struct src_rodata_dl *src_rodata = (struct src_rodata_dl *) &src[parent->src_offset];
struct dst_rodata_dl *dst_rodata = (struct dst_rodata_dl *) &dst[parent->dst_offset];
src_vtx = srctoh32(src_rodata->ptr_vertices) & 0x00ffffff;
dst_vtx = dsttoh32(dst_rodata->ptr_vertices) & 0x00ffffff;
src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff;
dst_vtx = (dst_rodata->ptr_vertices) & 0x00ffffff;
}
dstpos = gbiConvertGdl(dst, dstpos, src, marker->src_offset, 0);
@@ -625,127 +624,127 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len)
case CT_RODATA_CHRINFO:
struct generic_rodata_chrinfo *src_chrinfo = src_thing;
struct generic_rodata_chrinfo *dst_chrinfo = dst_thing;
dst_chrinfo->animpart = srctodst16(src_chrinfo->animpart);
dst_chrinfo->mtxindex = srctodst16(src_chrinfo->mtxindex);
dst_chrinfo->unk04 = srctodst32(src_chrinfo->unk04);
dst_chrinfo->rwdataindex = srctodst16(src_chrinfo->rwdataindex);
dst_chrinfo->animpart = PD_BE16(src_chrinfo->animpart);
dst_chrinfo->mtxindex = PD_BE16(src_chrinfo->mtxindex);
dst_chrinfo->unk04 = PD_BE32(src_chrinfo->unk04);
dst_chrinfo->rwdataindex = PD_BE16(src_chrinfo->rwdataindex);
dstpos += sizeof(*dst_chrinfo);
break;
case CT_RODATA_POSITION:
struct generic_rodata_position *src_position = src_thing;
struct generic_rodata_position *dst_position = dst_thing;
dst_position->pos[0] = srctodst32(src_position->pos[0]);
dst_position->pos[1] = srctodst32(src_position->pos[1]);
dst_position->pos[2] = srctodst32(src_position->pos[2]);
dst_position->part = srctodst16(src_position->part);
dst_position->mtxindexes[0] = srctodst16(src_position->mtxindexes[0]);
dst_position->mtxindexes[1] = srctodst16(src_position->mtxindexes[1]);
dst_position->mtxindexes[2] = srctodst16(src_position->mtxindexes[2]);
dst_position->drawdist = srctodst32(src_position->drawdist);
dst_position->pos[0] = PD_BE32(src_position->pos[0]);
dst_position->pos[1] = PD_BE32(src_position->pos[1]);
dst_position->pos[2] = PD_BE32(src_position->pos[2]);
dst_position->part = PD_BE16(src_position->part);
dst_position->mtxindexes[0] = PD_BE16(src_position->mtxindexes[0]);
dst_position->mtxindexes[1] = PD_BE16(src_position->mtxindexes[1]);
dst_position->mtxindexes[2] = PD_BE16(src_position->mtxindexes[2]);
dst_position->drawdist = PD_BE32(src_position->drawdist);
dstpos += sizeof(*dst_position);
break;
case CT_RODATA_GUNDL:
struct src_rodata_gundl *src_gundl = src_thing;
struct dst_rodata_gundl *dst_gundl = dst_thing;
dst_gundl->ptr_vertices = 0;
dst_gundl->numvertices = srctodst16(src_gundl->numvertices);
dst_gundl->unk12 = srctodst16(src_gundl->unk12);
dst_gundl->numvertices = PD_BE16(src_gundl->numvertices);
dst_gundl->unk12 = PD_BE16(src_gundl->unk12);
dstpos += sizeof(*dst_gundl);
break;
case CT_RODATA_DISTANCE:
struct src_rodata_distance *src_dist = src_thing;
struct dst_rodata_distance *dst_dist = dst_thing;
dst_dist->near = srctodst32(src_dist->near);
dst_dist->far = srctodst32(src_dist->far);
dst_dist->rwdataindex = srctodst16(src_dist->rwdataindex);
dst_dist->near = PD_BE32(src_dist->near);
dst_dist->far = PD_BE32(src_dist->far);
dst_dist->rwdataindex = PD_BE16(src_dist->rwdataindex);
dstpos += sizeof(*dst_dist);
break;
case CT_RODATA_REORDER:
struct src_rodata_reorder *src_reorder = src_thing;
struct dst_rodata_reorder *dst_reorder = dst_thing;
dst_reorder->unk00 = srctodst32(src_reorder->unk00);
dst_reorder->unk04 = srctodst32(src_reorder->unk04);
dst_reorder->unk08 = srctodst32(src_reorder->unk08);
dst_reorder->unk0c[0] = srctodst32(src_reorder->unk0c[0]);
dst_reorder->unk0c[1] = srctodst32(src_reorder->unk0c[1]);
dst_reorder->unk0c[2] = srctodst32(src_reorder->unk0c[2]);
dst_reorder->side = srctodst16(src_reorder->side);
dst_reorder->rwdataindex = srctodst16(src_reorder->rwdataindex);
dst_reorder->unk00 = PD_BE32(src_reorder->unk00);
dst_reorder->unk04 = PD_BE32(src_reorder->unk04);
dst_reorder->unk08 = PD_BE32(src_reorder->unk08);
dst_reorder->unk0c[0] = PD_BE32(src_reorder->unk0c[0]);
dst_reorder->unk0c[1] = PD_BE32(src_reorder->unk0c[1]);
dst_reorder->unk0c[2] = PD_BE32(src_reorder->unk0c[2]);
dst_reorder->side = PD_BE16(src_reorder->side);
dst_reorder->rwdataindex = PD_BE16(src_reorder->rwdataindex);
dstpos += sizeof(*dst_reorder);
break;
case CT_RODATA_BBOX:
struct generic_rodata_bbox *src_bbox = src_thing;
struct generic_rodata_bbox *dst_bbox = dst_thing;
dst_bbox->hitpart = srctodst32(src_bbox->hitpart);
dst_bbox->bbox[0] = srctodst32(src_bbox->bbox[0]);
dst_bbox->bbox[1] = srctodst32(src_bbox->bbox[1]);
dst_bbox->bbox[2] = srctodst32(src_bbox->bbox[2]);
dst_bbox->bbox[3] = srctodst32(src_bbox->bbox[3]);
dst_bbox->bbox[4] = srctodst32(src_bbox->bbox[4]);
dst_bbox->bbox[5] = srctodst32(src_bbox->bbox[5]);
dst_bbox->hitpart = PD_BE32(src_bbox->hitpart);
dst_bbox->bbox[0] = PD_BE32(src_bbox->bbox[0]);
dst_bbox->bbox[1] = PD_BE32(src_bbox->bbox[1]);
dst_bbox->bbox[2] = PD_BE32(src_bbox->bbox[2]);
dst_bbox->bbox[3] = PD_BE32(src_bbox->bbox[3]);
dst_bbox->bbox[4] = PD_BE32(src_bbox->bbox[4]);
dst_bbox->bbox[5] = PD_BE32(src_bbox->bbox[5]);
dstpos += sizeof(*dst_bbox);
break;
case CT_RODATA_CHRGUNFIRE:
struct src_rodata_chrgunfire *src_chrgunfire = src_thing;
struct dst_rodata_chrgunfire *dst_chrgunfire = dst_thing;
dst_chrgunfire->pos[0] = srctodst32(src_chrgunfire->pos[0]);
dst_chrgunfire->pos[1] = srctodst32(src_chrgunfire->pos[1]);
dst_chrgunfire->pos[2] = srctodst32(src_chrgunfire->pos[2]);
dst_chrgunfire->dim[0] = srctodst32(src_chrgunfire->dim[0]);
dst_chrgunfire->dim[1] = srctodst32(src_chrgunfire->dim[1]);
dst_chrgunfire->dim[2] = srctodst32(src_chrgunfire->dim[2]);
dst_chrgunfire->unk1c = srctodst32(src_chrgunfire->unk1c);
dst_chrgunfire->rwdataindex = srctodst16(src_chrgunfire->rwdataindex);
dst_chrgunfire->pos[0] = PD_BE32(src_chrgunfire->pos[0]);
dst_chrgunfire->pos[1] = PD_BE32(src_chrgunfire->pos[1]);
dst_chrgunfire->pos[2] = PD_BE32(src_chrgunfire->pos[2]);
dst_chrgunfire->dim[0] = PD_BE32(src_chrgunfire->dim[0]);
dst_chrgunfire->dim[1] = PD_BE32(src_chrgunfire->dim[1]);
dst_chrgunfire->dim[2] = PD_BE32(src_chrgunfire->dim[2]);
dst_chrgunfire->unk1c = PD_BE32(src_chrgunfire->unk1c);
dst_chrgunfire->rwdataindex = PD_BE16(src_chrgunfire->rwdataindex);
dst_chrgunfire->ptr_baseaddr = 0;
dstpos += sizeof(*dst_chrgunfire);
break;
case CT_RODATA_11:
struct src_rodata_type11 *src_type11 = src_thing;
struct dst_rodata_type11 *dst_type11 = dst_thing;
dst_type11->unk00 = srctodst32(src_type11->unk00);
dst_type11->unk04 = srctodst32(src_type11->unk04);
dst_type11->unk08 = srctodst32(src_type11->unk08);
dst_type11->unk0c = srctodst32(src_type11->unk0c);
dst_type11->unk10 = srctodst32(src_type11->unk10);
dst_type11->extra1 = srctodst32(src_type11->extra1);
dst_type11->extra2 = srctodst32(src_type11->extra2);
dst_type11->unk00 = PD_BE32(src_type11->unk00);
dst_type11->unk04 = PD_BE32(src_type11->unk04);
dst_type11->unk08 = PD_BE32(src_type11->unk08);
dst_type11->unk0c = PD_BE32(src_type11->unk0c);
dst_type11->unk10 = PD_BE32(src_type11->unk10);
dst_type11->extra1 = PD_BE32(src_type11->extra1);
dst_type11->extra2 = PD_BE32(src_type11->extra2);
dstpos += sizeof(*dst_type11);
break;
case CT_RODATA_TOGGLE:
struct src_rodata_toggle *src_toggle = src_thing;
struct dst_rodata_toggle *dst_toggle = dst_thing;
dst_toggle->rwdataindex = srctodst16(src_toggle->rwdataindex);
dst_toggle->rwdataindex = PD_BE16(src_toggle->rwdataindex);
dstpos += sizeof(*dst_toggle);
break;
case CT_RODATA_POSITIONHELD:
struct generic_rodata_positionheld *src_posheld = src_thing;
struct generic_rodata_positionheld *dst_posheld = dst_thing;
dst_posheld->pos[0] = srctodst32(src_posheld->pos[0]);
dst_posheld->pos[1] = srctodst32(src_posheld->pos[1]);
dst_posheld->pos[2] = srctodst32(src_posheld->pos[2]);
dst_posheld->mtxindex = srctodst16(src_posheld->mtxindex);
dst_posheld->unk10 = srctodst32(src_posheld->unk10);
dst_posheld->pos[0] = PD_BE32(src_posheld->pos[0]);
dst_posheld->pos[1] = PD_BE32(src_posheld->pos[1]);
dst_posheld->pos[2] = PD_BE32(src_posheld->pos[2]);
dst_posheld->mtxindex = PD_BE16(src_posheld->mtxindex);
dst_posheld->unk10 = PD_BE32(src_posheld->unk10);
dstpos += sizeof(*dst_posheld);
break;
case CT_RODATA_STARGUNFIRE:
struct src_rodata_stargunfire *src_stargunfire = src_thing;
struct dst_rodata_stargunfire *dst_stargunfire = dst_thing;
dst_stargunfire->unk00 = srctodst32(src_stargunfire->unk00);
dst_stargunfire->unk00 = PD_BE32(src_stargunfire->unk00);
dstpos += sizeof(*dst_stargunfire);
break;
case CT_RODATA_HEADSPOT:
struct generic_rodata_headspot *src_headspot = src_thing;
struct generic_rodata_headspot *dst_headspot = dst_thing;
dst_headspot->rwdataindex = srctodst16(src_headspot->rwdataindex);
dst_headspot->rwdataindex = PD_BE16(src_headspot->rwdataindex);
dstpos += sizeof(*dst_headspot);
break;
case CT_RODATA_DL:
struct src_rodata_dl *src_dl = src_thing;
struct dst_rodata_dl *dst_dl = dst_thing;
dst_dl->numvertices = srctodst16(src_dl->numvertices);
dst_dl->mcount = srctodst16(src_dl->mcount);
dst_dl->rwdataindex = srctodst16(src_dl->rwdataindex);
dst_dl->numcolours = srctodst16(src_dl->numcolours);
dst_dl->numvertices = PD_BE16(src_dl->numvertices);
dst_dl->mcount = PD_BE16(src_dl->mcount);
dst_dl->rwdataindex = PD_BE16(src_dl->rwdataindex);
dst_dl->numcolours = PD_BE16(src_dl->numcolours);
dstpos += sizeof(*dst_dl);
break;
case CT_RODATA_19:
@@ -753,15 +752,15 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len)
struct generic_rodata_type19 *dst_type19 = dst_thing;
u32 *src_vertices = src_thing + sizeof(u32);
u32 *dst_vertices = dst_thing + sizeof(u32);
int num_vertices = srctoh32(src_type19->numvertices);
int num_vertices = PD_BE32(src_type19->numvertices);
dst_type19->numvertices = htodst32(num_vertices);
dst_type19->numvertices = (num_vertices);
dstpos += sizeof(u32);
for (int i = 0; i < num_vertices; i++) {
dst_vertices[i * 3 + 0] = srctodst32(src_vertices[i * 3 + 0]);
dst_vertices[i * 3 + 1] = srctodst32(src_vertices[i * 3 + 1]);
dst_vertices[i * 3 + 2] = srctodst32(src_vertices[i * 3 + 2]);
dst_vertices[i * 3 + 0] = PD_BE32(src_vertices[i * 3 + 0]);
dst_vertices[i * 3 + 1] = PD_BE32(src_vertices[i * 3 + 1]);
dst_vertices[i * 3 + 2] = PD_BE32(src_vertices[i * 3 + 2]);
dstpos += sizeof(u32) * 3;
}
break;
@@ -769,7 +768,7 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len)
break;
}
dstpos = ALIGN(dstpos, m_AlignConfigs[marker->type].after);
dstpos = PD_ALIGN(dstpos, m_AlignConfigs[marker->type].after);
}
return dstpos;
@@ -800,37 +799,37 @@ static u8 *relinkPointers(u8 *dst, u8 *src)
case CT_MODELDEF:
struct src_modeldef *src_modeldef = src_thing;
struct dst_modeldef *dst_modeldef = dst_thing;
dst_modeldef->ptr_rootnode = htodst32(resolvePointer(srctoh32(src_modeldef->ptr_rootnode)));
dst_modeldef->ptr_parts = htodst32(resolvePointer(srctoh32(src_modeldef->ptr_parts)));
dst_modeldef->ptr_texconfigs = htodst32(resolvePointer(srctoh32(src_modeldef->ptr_texconfigs)));
dst_modeldef->ptr_rootnode = (resolvePointer(PD_BE32(src_modeldef->ptr_rootnode)));
dst_modeldef->ptr_parts = (resolvePointer(PD_BE32(src_modeldef->ptr_parts)));
dst_modeldef->ptr_texconfigs = (resolvePointer(PD_BE32(src_modeldef->ptr_texconfigs)));
break;
case CT_NODE:
struct src_modelnode *src_node = src_thing;
struct dst_modelnode *dst_node = dst_thing;
dst_node->ptr_rodata = htodst32(resolvePointer(srctoh32(src_node->ptr_rodata)));
dst_node->ptr_parent = htodst32(resolvePointer(srctoh32(src_node->ptr_parent)));
dst_node->ptr_next = htodst32(resolvePointer(srctoh32(src_node->ptr_next)));
dst_node->ptr_prev = htodst32(resolvePointer(srctoh32(src_node->ptr_prev)));
dst_node->ptr_child = htodst32(resolvePointer(srctoh32(src_node->ptr_child)));
dst_node->ptr_rodata = (resolvePointer(PD_BE32(src_node->ptr_rodata)));
dst_node->ptr_parent = (resolvePointer(PD_BE32(src_node->ptr_parent)));
dst_node->ptr_next = (resolvePointer(PD_BE32(src_node->ptr_next)));
dst_node->ptr_prev = (resolvePointer(PD_BE32(src_node->ptr_prev)));
dst_node->ptr_child = (resolvePointer(PD_BE32(src_node->ptr_child)));
lowestptr = dst_node->ptr_rodata;
break;
case CT_TEXCONFIG:
struct src_texconfig *src_texconfig = src_thing;
struct dst_texconfig *dst_texconfig = dst_thing;
if ((srctoh32(src_texconfig->ptr) & 0xff000000) == 0x05000000) {
dst_texconfig->ptr = htodst32(resolvePointer(srctoh32(src_texconfig->ptr)));
gbiAddTexAddr(srctoh32(src_texconfig->ptr), dst_texconfig->ptr);
if ((PD_BE32(src_texconfig->ptr) & 0xff000000) == 0x05000000) {
dst_texconfig->ptr = (resolvePointer(PD_BE32(src_texconfig->ptr)));
gbiAddTexAddr(PD_BE32(src_texconfig->ptr), dst_texconfig->ptr);
}
break;
case CT_PARTS:
struct src_modeldef *src_modeldef2 = (struct src_modeldef *) src;
u32 *src_parts = (u32 *) src_thing;
uintptr_t *dst_parts = (uintptr_t *) dst_thing;
int num_parts = srctoh16(src_modeldef2->numparts);
int num_parts = PD_BE16(src_modeldef2->numparts);
for (int i = 0; i < num_parts; i++) {
dst_parts[i] = htodst32(resolvePointer(srctoh32(src_parts[i])));
dst_parts[i] = (resolvePointer(PD_BE32(src_parts[i])));
}
break;
case CT_RODATA_CHRINFO:
@@ -840,13 +839,13 @@ static u8 *relinkPointers(u8 *dst, u8 *src)
case CT_RODATA_GUNDL:
struct src_rodata_gundl *src_gundl = src_thing;
struct dst_rodata_gundl *dst_gundl = dst_thing;
dst_gundl->ptr_opagdl = htodst32(resolvePointer(srctoh32(src_gundl->ptr_opagdl)));
dst_gundl->ptr_xlugdl = htodst32(resolvePointer(srctoh32(src_gundl->ptr_xlugdl)));
dst_gundl->ptr_vertices = htodst32(resolvePointer(srctoh32(src_gundl->ptr_vertices)));
dst_gundl->ptr_opagdl = (resolvePointer(PD_BE32(src_gundl->ptr_opagdl)));
dst_gundl->ptr_xlugdl = (resolvePointer(PD_BE32(src_gundl->ptr_xlugdl)));
dst_gundl->ptr_vertices = (resolvePointer(PD_BE32(src_gundl->ptr_vertices)));
gbiConvertVtx(dst, dst_gundl->ptr_vertices & 0x00ffffff, dst_gundl->numvertices);
gbiSetVtx(srctoh32(src_gundl->ptr_vertices), dst_gundl->ptr_vertices);
gbiSetVtx(PD_BE32(src_gundl->ptr_vertices), dst_gundl->ptr_vertices);
gbiSetSegment(0x04, dst_gundl->ptr_vertices);
gbiGdlRewriteAddrs(dst, dst_gundl->ptr_opagdl);
@@ -860,36 +859,36 @@ static u8 *relinkPointers(u8 *dst, u8 *src)
case CT_RODATA_DISTANCE:
struct src_rodata_distance *src_dist = src_thing;
struct dst_rodata_distance *dst_dist = dst_thing;
dst_dist->ptr_target = htodst32(resolvePointer(srctoh32(src_dist->ptr_target)));
dst_dist->ptr_target = (resolvePointer(PD_BE32(src_dist->ptr_target)));
break;
case CT_RODATA_REORDER:
struct src_rodata_reorder *src_reorder = src_thing;
struct dst_rodata_reorder *dst_reorder = dst_thing;
dst_reorder->ptr_node_unk18 = htodst32(resolvePointer(srctoh32(src_reorder->ptr_node_unk18)));
dst_reorder->ptr_node_unk1c = htodst32(resolvePointer(srctoh32(src_reorder->ptr_node_unk1c)));
dst_reorder->ptr_node_unk18 = (resolvePointer(PD_BE32(src_reorder->ptr_node_unk18)));
dst_reorder->ptr_node_unk1c = (resolvePointer(PD_BE32(src_reorder->ptr_node_unk1c)));
break;
case CT_RODATA_CHRGUNFIRE:
struct src_rodata_chrgunfire *src_chrgunfire = src_thing;
struct dst_rodata_chrgunfire *dst_chrgunfire = dst_thing;
dst_chrgunfire->ptr_texture = htodst32(resolvePointer(srctoh32(src_chrgunfire->ptr_texture)));
if ((srctoh32(dst_chrgunfire->ptr_texture) & 0xff000000) == 0x05000000) {
gbiAddTexAddr(srctoh32(dst_chrgunfire->ptr_texture), dst_chrgunfire->ptr_texture);
dst_chrgunfire->ptr_texture = (resolvePointer(PD_BE32(src_chrgunfire->ptr_texture)));
if ((PD_BE32(dst_chrgunfire->ptr_texture) & 0xff000000) == 0x05000000) {
gbiAddTexAddr(PD_BE32(dst_chrgunfire->ptr_texture), dst_chrgunfire->ptr_texture);
}
break;
case CT_RODATA_TOGGLE:
struct src_rodata_toggle *src_toggle = src_thing;
struct dst_rodata_toggle *dst_toggle = dst_thing;
dst_toggle->ptr_target = htodst32(resolvePointer(srctoh32(src_toggle->ptr_target)));
dst_toggle->ptr_target = (resolvePointer(PD_BE32(src_toggle->ptr_target)));
break;
case CT_RODATA_STARGUNFIRE:
struct src_rodata_stargunfire *src_stargunfire = src_thing;
struct dst_rodata_stargunfire *dst_stargunfire = dst_thing;
dst_stargunfire->ptr_vertices = htodst32(resolvePointer(srctoh32(src_stargunfire->ptr_vertices)));
dst_stargunfire->ptr_gdl = htodst32(resolvePointer(srctoh32(src_stargunfire->ptr_gdl)));
dst_stargunfire->ptr_vertices = (resolvePointer(PD_BE32(src_stargunfire->ptr_vertices)));
dst_stargunfire->ptr_gdl = (resolvePointer(PD_BE32(src_stargunfire->ptr_gdl)));
gbiConvertVtx(dst, dst_stargunfire->ptr_vertices & 0x00ffffff, dst_stargunfire->unk00*4);
gbiSetVtx(srctoh32(src_stargunfire->ptr_vertices), dst_stargunfire->ptr_vertices);
gbiSetVtx(PD_BE32(src_stargunfire->ptr_vertices), dst_stargunfire->ptr_vertices);
gbiSetSegment(0x04, dst_stargunfire->ptr_vertices);
gbiGdlRewriteAddrs(dst, dst_stargunfire->ptr_gdl);
if (dst_stargunfire->ptr_gdl) dst_stargunfire->ptr_gdl |= 1;
@@ -899,14 +898,14 @@ static u8 *relinkPointers(u8 *dst, u8 *src)
case CT_RODATA_DL:
struct src_rodata_dl *src_dl = src_thing;
struct dst_rodata_dl *dst_dl = dst_thing;
dst_dl->ptr_opagdl = htodst32(resolvePointer(srctoh32(src_dl->ptr_opagdl)));
dst_dl->ptr_xlugdl = htodst32(resolvePointer(srctoh32(src_dl->ptr_xlugdl)));
dst_dl->ptr_colours = htodst32(resolvePointer(srctoh32(src_dl->ptr_colours)));
dst_dl->ptr_vertices = htodst32(resolvePointer(srctoh32(src_dl->ptr_vertices)));
dst_dl->ptr_opagdl = (resolvePointer(PD_BE32(src_dl->ptr_opagdl)));
dst_dl->ptr_xlugdl = (resolvePointer(PD_BE32(src_dl->ptr_xlugdl)));
dst_dl->ptr_colours = (resolvePointer(PD_BE32(src_dl->ptr_colours)));
dst_dl->ptr_vertices = (resolvePointer(PD_BE32(src_dl->ptr_vertices)));
gbiConvertVtx(dst, dst_dl->ptr_vertices & 0x00ffffff, dst_dl->numvertices);
gbiSetVtx(srctoh32(src_dl->ptr_vertices), dst_dl->ptr_vertices);
gbiSetVtx(PD_BE32(src_dl->ptr_vertices), dst_dl->ptr_vertices);
gbiSetSegment(0x04, dst_dl->ptr_vertices);
gbiGdlRewriteAddrs(dst, dst_dl->ptr_opagdl);
gbiGdlRewriteAddrs(dst, dst_dl->ptr_xlugdl);
+53 -64
View File
@@ -2,20 +2,9 @@
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "romdata.h"
#include "system.h"
#include "preprocess/common.h"
#define PADFLAG_INTPOS 0x0001
#define PADFLAG_UPALIGNTOX 0x0002
#define PADFLAG_UPALIGNTOY 0x0004
#define PADFLAG_UPALIGNTOZ 0x0008
#define PADFLAG_UPALIGNINVERT 0x0010
#define PADFLAG_LOOKALIGNTOX 0x0020
#define PADFLAG_LOOKALIGNTOY 0x0040
#define PADFLAG_LOOKALIGNTOZ 0x0080
#define PADFLAG_LOOKALIGNINVERT 0x0100
#define PADFLAG_HASBBOXDATA 0x0200
#include "constants.h"
struct n64_header {
s32 num_pads;
@@ -80,16 +69,16 @@ static int convertPads(u8 *dst, int dstpos, u8 *src, int srcpos, int num_pads)
dstpos += num_pads * sizeof(u16);
for (int i = 0; i < num_pads; i++) {
srcpos = srctoh16(src_offsets[i]);
srcpos = PD_BE16(src_offsets[i]);
dst_offsets[i] = htodst16(dstpos);
dst_offsets[i] = (dstpos);
// Header
u32 n64_padheader = srctoh32(*(u32 *) &src[srcpos]);
u32 n64_padheader = PD_BE32(*(u32 *) &src[srcpos]);
struct padheader *host_padheader = (struct padheader *) &dst[dstpos];
u32 flags = (n64_padheader >> 14) & 0x3ffff;
*(u32*)host_padheader = htodst32(n64_padheader);
*(u32*)host_padheader = (n64_padheader);
srcpos += sizeof(struct padheader);
dstpos += sizeof(struct padheader);
@@ -99,9 +88,9 @@ static int convertPads(u8 *dst, int dstpos, u8 *src, int srcpos, int num_pads)
s16 *srcptr = (s16 *) &src[srcpos];
s16 *dstptr = (s16 *) &dst[dstpos];
dstptr[0] = srctodst16(srcptr[0]);
dstptr[1] = srctodst16(srcptr[1]);
dstptr[2] = srctodst16(srcptr[2]);
dstptr[0] = PD_BE16(srcptr[0]);
dstptr[1] = PD_BE16(srcptr[1]);
dstptr[2] = PD_BE16(srcptr[2]);
srcpos += 8;
dstpos += 8;
@@ -109,9 +98,9 @@ static int convertPads(u8 *dst, int dstpos, u8 *src, int srcpos, int num_pads)
u32 *srcptr = (u32 *) &src[srcpos];
u32 *dstptr = (u32 *) &dst[dstpos];
dstptr[0] = srctodst32(srcptr[0]);
dstptr[1] = srctodst32(srcptr[1]);
dstptr[2] = srctodst32(srcptr[2]);
dstptr[0] = PD_BE32(srcptr[0]);
dstptr[1] = PD_BE32(srcptr[1]);
dstptr[2] = PD_BE32(srcptr[2]);
srcpos += 12;
dstpos += 12;
@@ -122,9 +111,9 @@ static int convertPads(u8 *dst, int dstpos, u8 *src, int srcpos, int num_pads)
u32 *srcptr = (u32 *) &src[srcpos];
u32 *dstptr = (u32 *) &dst[dstpos];
dstptr[0] = srctodst32(srcptr[0]);
dstptr[1] = srctodst32(srcptr[1]);
dstptr[2] = srctodst32(srcptr[2]);
dstptr[0] = PD_BE32(srcptr[0]);
dstptr[1] = PD_BE32(srcptr[1]);
dstptr[2] = PD_BE32(srcptr[2]);
srcpos += 12;
dstpos += 12;
@@ -135,9 +124,9 @@ static int convertPads(u8 *dst, int dstpos, u8 *src, int srcpos, int num_pads)
u32 *srcptr = (u32 *) &src[srcpos];
u32 *dstptr = (u32 *) &dst[dstpos];
dstptr[0] = srctodst32(srcptr[0]);
dstptr[1] = srctodst32(srcptr[1]);
dstptr[2] = srctodst32(srcptr[2]);
dstptr[0] = PD_BE32(srcptr[0]);
dstptr[1] = PD_BE32(srcptr[1]);
dstptr[2] = PD_BE32(srcptr[2]);
srcpos += 12;
dstpos += 12;
@@ -148,12 +137,12 @@ static int convertPads(u8 *dst, int dstpos, u8 *src, int srcpos, int num_pads)
u32 *srcptr = (u32 *) &src[srcpos];
u32 *dstptr = (u32 *) &dst[dstpos];
dstptr[0] = srctodst32(srcptr[0]);
dstptr[1] = srctodst32(srcptr[1]);
dstptr[2] = srctodst32(srcptr[2]);
dstptr[3] = srctodst32(srcptr[3]);
dstptr[4] = srctodst32(srcptr[4]);
dstptr[5] = srctodst32(srcptr[5]);
dstptr[0] = PD_BE32(srcptr[0]);
dstptr[1] = PD_BE32(srcptr[1]);
dstptr[2] = PD_BE32(srcptr[2]);
dstptr[3] = PD_BE32(srcptr[3]);
dstptr[4] = PD_BE32(srcptr[4]);
dstptr[5] = PD_BE32(srcptr[5]);
srcpos += 4 * 6;
dstpos += 4 * 6;
@@ -177,15 +166,15 @@ static int convertWayPoints(u8 *dst, int dstpos, u8 *src, int srcpos)
int n = 0;
for (int i = 0; i < num_waypoints; i++) {
host_waypoints[i].padnum = srctodst32(n64_waypoints[i].padnum);
host_waypoints[i].ptr_neighbours = htodst32(dstpos);
host_waypoints[i].groupnum = srctodst32(n64_waypoints[i].groupnum);
host_waypoints[i].padnum = PD_BE32(n64_waypoints[i].padnum);
host_waypoints[i].ptr_neighbours = (dstpos);
host_waypoints[i].groupnum = PD_BE32(n64_waypoints[i].groupnum);
host_waypoints[i].step = 0;
u32 *n64_neighbours = (u32 *) &src[srctoh32(n64_waypoints[i].ptr_neighbours)];
u32 *n64_neighbours = (u32 *) &src[PD_BE32(n64_waypoints[i].ptr_neighbours)];
for (int j = 0; n64_neighbours[j] != 0xffffffff; j++) {
host_neighbours[n++] = srctodst32(n64_neighbours[j]);
host_neighbours[n++] = PD_BE32(n64_neighbours[j]);
dstpos += 4;
}
@@ -217,13 +206,13 @@ static int convertWayGroups(u8 *dst, int dstpos, u8 *src, int srcpos)
int n = 0;
for (int i = 0; i < num_waygroups; i++) {
host_waygroups[i].ptr_waypoints = htodst32(dstpos);
host_waygroups[i].ptr_waypoints = (dstpos);
host_waygroups[i].step = 0;
u32 *n64_waypoints = (u32 *) &src[srctoh32(n64_waygroups[i].ptr_waypoints)];
u32 *n64_waypoints = (u32 *) &src[PD_BE32(n64_waygroups[i].ptr_waypoints)];
for (int j = 0; n64_waypoints[j] != 0xffffffff; j++) {
host_waypoints[n++] = srctodst32(n64_waypoints[j]);
host_waypoints[n++] = PD_BE32(n64_waypoints[j]);
dstpos += 4;
}
@@ -241,12 +230,12 @@ static int convertWayGroups(u8 *dst, int dstpos, u8 *src, int srcpos)
n = 0;
for (int i = 0; i < num_waygroups; i++) {
host_waygroups[i].ptr_neighbours = htodst32(dstpos);
host_waygroups[i].ptr_neighbours = (dstpos);
u32 *n64_neighbours = (u32 *) &src[srctoh32(n64_waygroups[i].ptr_neighbours)];
u32 *n64_neighbours = (u32 *) &src[PD_BE32(n64_waygroups[i].ptr_neighbours)];
for (int j = 0; n64_neighbours[j] != 0xffffffff; j++) {
host_neighbours[n++] = srctodst32(n64_neighbours[j]);
host_neighbours[n++] = PD_BE32(n64_neighbours[j]);
dstpos += 4;
}
@@ -263,14 +252,14 @@ static int convertCover(u8 *dst, int dstpos, u8 *src, int srcpos, int num_covers
struct generic_coverdefinition *host_covers = (struct generic_coverdefinition *) &dst[dstpos];
for (int i = 0; i < num_covers; i++) {
host_covers[i].pos[0] = srctodst32(n64_covers[i].pos[0]);
host_covers[i].pos[1] = srctodst32(n64_covers[i].pos[1]);
host_covers[i].pos[2] = srctodst32(n64_covers[i].pos[2]);
host_covers[i].dir[0] = srctodst32(n64_covers[i].dir[0]);
host_covers[i].dir[1] = srctodst32(n64_covers[i].dir[1]);
host_covers[i].dir[2] = srctodst32(n64_covers[i].dir[2]);
host_covers[i].flags = srctodst16(n64_covers[i].flags);
host_covers[i].unk1a = srctodst16(n64_covers[i].unk1a);
host_covers[i].pos[0] = PD_BE32(n64_covers[i].pos[0]);
host_covers[i].pos[1] = PD_BE32(n64_covers[i].pos[1]);
host_covers[i].pos[2] = PD_BE32(n64_covers[i].pos[2]);
host_covers[i].dir[0] = PD_BE32(n64_covers[i].dir[0]);
host_covers[i].dir[1] = PD_BE32(n64_covers[i].dir[1]);
host_covers[i].dir[2] = PD_BE32(n64_covers[i].dir[2]);
host_covers[i].flags = PD_BE16(n64_covers[i].flags);
host_covers[i].unk1a = PD_BE16(n64_covers[i].unk1a);
}
dstpos += num_covers * sizeof(struct generic_coverdefinition);
@@ -284,10 +273,10 @@ static int convertPadsFile(u8 *dst, u8 *src)
struct n64_header *n64_header = (struct n64_header *) src;
struct host_header *host_header = (struct host_header *) dst;
int num_pads = srctoh32(n64_header->num_pads);
int num_covers = srctoh32(n64_header->num_covers);
host_header->num_pads = htodst32(num_pads);
host_header->num_covers = htodst32(num_covers);
int num_pads = PD_BE32(n64_header->num_pads);
int num_covers = PD_BE32(n64_header->num_covers);
host_header->num_pads = (num_pads);
host_header->num_covers = (num_covers);
dstpos += sizeof(struct host_header);
@@ -295,16 +284,16 @@ static int convertPadsFile(u8 *dst, u8 *src)
dstpos = convertPads(dst, dstpos, src, sizeof(struct n64_header), num_pads);
// Waypoints
host_header->ptr_waypoints = htodst32(dstpos);
dstpos = convertWayPoints(dst, dstpos, src, srctoh32(n64_header->ptr_waypoints));
host_header->ptr_waypoints = (dstpos);
dstpos = convertWayPoints(dst, dstpos, src, PD_BE32(n64_header->ptr_waypoints));
// Waygroups
host_header->ptr_waygroups = htodst32(dstpos);
dstpos = convertWayGroups(dst, dstpos, src, srctoh32(n64_header->ptr_waygroups));
host_header->ptr_waygroups = (dstpos);
dstpos = convertWayGroups(dst, dstpos, src, PD_BE32(n64_header->ptr_waygroups));
// Cover
host_header->ptr_cover = htodst32(dstpos);
dstpos = convertCover(dst, dstpos, src, srctoh32(n64_header->ptr_cover), num_covers);
host_header->ptr_cover = (dstpos);
dstpos = convertCover(dst, dstpos, src, PD_BE32(n64_header->ptr_cover), num_covers);
return dstpos;
}
+23 -29
View File
@@ -4,20 +4,14 @@
#include "types.h"
#include "assert.h"
#include "preprocess/common.h"
#include "preprocess/setup.h"
#include "common.h"
#include "setups_decl.h"
#include "romdata.h"
#include "system.h"
static inline void convF32(f32 *dst, f32 src) { *(u32*)dst = srctoh32(*(u32*)&src); }
static inline void convU32(u32 *dst, u32 src) { *dst = srctoh32(src); }
static inline void convS32(s32 *dst, s32 src) { *dst = srctoh32(src); }
static inline void convU16(u16 *dst, u32 src) { *dst = srctoh16(src); }
static inline void convS16(s16 *dst, s32 src) { *dst = srctoh16(src); }
static inline void convF32(f32 *dst, f32 src) { *(u32*)dst = PD_BE32(*(u32*)&src); }
static inline void convU32(u32 *dst, u32 src) { *dst = PD_BE32(src); }
static inline void convS32(s32 *dst, s32 src) { *dst = PD_BE32(src); }
static inline void convU16(u16 *dst, u32 src) { *dst = PD_BE16(src); }
static inline void convS16(s16 *dst, s32 src) { *dst = PD_BE16(src); }
static inline void cpyByte(u8 *dst, u8 src) { *dst = src; }
static inline void convCoord(struct coord* dst, struct n64_coord src) { convF32(&dst->x, src.x); convF32(&dst->y, src.y); convF32(&dst->z, src.z); }
static inline void convUnk(u32 x) { assert(0 && "unknown type"); }
@@ -40,7 +34,7 @@ static inline void convUnk(u32 x) { assert(0 && "unknown type"); }
for (int j = 0; j < ARRAYCOUNT(dst); j++) PD_CONV_VAL(dst[i][j], src[i][j]); \
}
#define PD_CONV_PTR(dst, src, type) dst = (type)srctoh32(src)
#define PD_CONV_PTR(dst, src, type) dst = (type)PD_BE32(src)
static u32 obj_size(struct n64_defaultobj *obj)
{
@@ -165,7 +159,7 @@ void convertDefaultObjHdr(struct defaultobj* dstobj, struct n64_defaultobj* srco
u16 *src_unk00_1 = (u16*)&srcobj->extrascale;
u8 *src_unk00_2 = (u8*)(src_unk00_1 + 1);
*dst_unk00_1 = srctoh16(*src_unk00_1);
*dst_unk00_1 = PD_BE16(*src_unk00_1);
dst_unk00_2[0] = src_unk00_2[0];
dst_unk00_2[1] = src_unk00_2[1];
}
@@ -1000,7 +994,7 @@ u32 convertProps(u8* dst, u8* src)
type = cmd->type;
}
*(u32*)(dst) = htobe32(OBJTYPE_END);
*(u32*)(dst) = PD_BE32(OBJTYPE_END);
dst += sizeof(u32);
return (u32)(dst - start);
@@ -1028,10 +1022,10 @@ static uintptr_t convertIntro(u8 *dst, u8 *src)
s32* srcintro = (s32*)src;
while (true) {
s32 cmd = dstintro[0] = srctodst32(srcintro[0]);
s32 cmd = dstintro[0] = PD_BE32(srcintro[0]);
u8 size = cmd_size[*dstintro];
for (int i = 1; i < size; i++) {
dstintro[i] = srctodst32(srcintro[i]);
dstintro[i] = PD_BE32(srcintro[i]);
}
dstintro += size;
@@ -1073,7 +1067,7 @@ static u32 convertPads(struct path *dstpaths, u8 *dst, u8 *src, u32 dstpos)
dstpaths->pads = (s32*)dstpos;
while (*pads) {
s32 p = srctoh32(*pads++);
s32 p = PD_BE32(*pads++);
*dstpads++ = p;
dstpos += sizeof(s32);
if (p == -1) break;
@@ -1109,14 +1103,14 @@ u32 chraiGetAilistLength(u8 *list);
static u32 convertLists(u8 *dst, u8 *src, u32 dstpos, u32 src_ofs)
{
resetMarkers();
ptrReset();
struct n64_ailist *src_ailists = (struct n64_ailist*)&src[src_ofs];
// count the lists and pre-convert the fields
int nlists = 0;
for (struct n64_ailist *tmp = src_ailists; tmp->ptr_list; tmp++, nlists++) {
tmp->ptr_list = srctodst32(tmp->ptr_list);
tmp->id = srctodst32(tmp->id);
tmp->ptr_list = PD_BE32(tmp->ptr_list);
tmp->id = PD_BE32(tmp->id);
}
for (struct n64_ailist *ailist = src_ailists; ailist->ptr_list; ailist++) {
@@ -1125,19 +1119,19 @@ static u32 convertLists(u8 *dst, u8 *src, u32 dstpos, u32 src_ofs)
ailist->ptr_list = dstpos;
// multiple ailists can point to the same list, so we need to check if it was already copied
struct ptrmarker *marker = findPtrMarker(src_ptr_list);
struct ptrmarker *marker = ptrFind(src_ptr_list);
if (marker) {
ailist->ptr_list = marker->ptr_host;
continue;
}
addMarker(src_ptr_list, dstpos);
ptrAdd(src_ptr_list, dstpos);
u8 *list = &src[src_ptr_list];
u32 listsize = chraiGetAilistLength(list);
memcpy(dst + dstpos, list, listsize);
dstpos += ALIGN(listsize, 4);
dstpos += PD_ALIGN(listsize, 4);
}
return dstpos;
@@ -1148,10 +1142,10 @@ static int convertSetup(u8 *dst, u8 *src, u32 srclen)
struct n64_stagesetup *src_header = (struct n64_stagesetup*)src;
struct stagesetup *dst_header = (struct stagesetup*)dst;
src_header->ptr_props = srctodst32(src_header->ptr_props);
src_header->ptr_intro = srctodst32(src_header->ptr_intro);
src_header->ptr_ailists = srctodst32(src_header->ptr_ailists);
src_header->ptr_paths = srctodst32(src_header->ptr_paths);
src_header->ptr_props = PD_BE32(src_header->ptr_props);
src_header->ptr_intro = PD_BE32(src_header->ptr_intro);
src_header->ptr_ailists = PD_BE32(src_header->ptr_ailists);
src_header->ptr_paths = PD_BE32(src_header->ptr_paths);
u32 srcpos = sizeof(*src_header);
u32 dstpos = sizeof(*dst_header);
+13 -16
View File
@@ -2,10 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "romdata.h"
#include "system.h"
#include "preprocess/common.h"
struct tile {
u8 type;
@@ -23,7 +20,7 @@ struct tile {
u32 convertTiles(u8 *dst, u8 *src, size_t srclen)
{
int num_rooms = srctoh32(*(u32 *) src);
int num_rooms = PD_BE32(*(u32 *) src);
size_t src_ptr_table_len = (num_rooms + 1) * 4;
size_t dst_ptr_table_len = (num_rooms + 1) * sizeof(u32);
@@ -32,19 +29,19 @@ u32 convertTiles(u8 *dst, u8 *src, size_t srclen)
size_t data_len = srclen - src_ptr_table_len - 4;
*(u32 *) dst = htodst32(num_rooms);
*(u32 *) dst = (num_rooms);
u32 *dst_offsets = (u32 *) (dst + sizeof(u32));
u32 cur_dst_offset = dst_ptr_table_len + sizeof(u32);
u32 cur_src_offset = srctoh32(src_offsets[0]);
u32 end_src_offset = srctoh32(src_offsets[num_rooms]);
u32 cur_src_offset = PD_BE32(src_offsets[0]);
u32 end_src_offset = PD_BE32(src_offsets[num_rooms]);
int room = 0;
while (1) {
// Check if this is a new room and write the pointer offset if so
while (room < (num_rooms + 1) && srctoh32(src_offsets[room]) == cur_src_offset) {
dst_offsets[room] = htodst32(cur_dst_offset);
while (room < (num_rooms + 1) && PD_BE32(src_offsets[room]) == cur_src_offset) {
dst_offsets[room] = (cur_dst_offset);
room++;
}
@@ -58,15 +55,15 @@ u32 convertTiles(u8 *dst, u8 *src, size_t srclen)
hosttile.type = n64tile->type;
hosttile.numvertices = n64tile->numvertices;
hosttile.flags = srctodst16(n64tile->flags);
hosttile.floortype = srctodst16(n64tile->floortype);
hosttile.flags = PD_BE16(n64tile->flags);
hosttile.floortype = PD_BE16(n64tile->floortype);
hosttile.xmin = n64tile->xmin;
hosttile.ymin = n64tile->ymin;
hosttile.zmin = n64tile->zmin;
hosttile.xmax = n64tile->xmax;
hosttile.ymax = n64tile->ymax;
hosttile.zmax = n64tile->zmax;
hosttile.floorcol = srctodst16(n64tile->floorcol);
hosttile.floorcol = PD_BE16(n64tile->floorcol);
memcpy(&dst[cur_dst_offset], &hosttile, sizeof(struct tile));
@@ -75,9 +72,9 @@ u32 convertTiles(u8 *dst, u8 *src, size_t srclen)
// Write tile vertices
for (int i = 0; i < hosttile.numvertices; i++) {
*(s16 *) &dst[cur_dst_offset + 0] = srctodst16(*(s16 *) &src[cur_src_offset + 0]);
*(s16 *) &dst[cur_dst_offset + 2] = srctodst16(*(s16 *) &src[cur_src_offset + 2]);
*(s16 *) &dst[cur_dst_offset + 4] = srctodst16(*(s16 *) &src[cur_src_offset + 4]);
*(s16 *) &dst[cur_dst_offset + 0] = PD_BE16(*(s16 *) &src[cur_src_offset + 0]);
*(s16 *) &dst[cur_dst_offset + 2] = PD_BE16(*(s16 *) &src[cur_src_offset + 2]);
*(s16 *) &dst[cur_dst_offset + 4] = PD_BE16(*(s16 *) &src[cur_src_offset + 4]);
cur_dst_offset += 6;
cur_src_offset += 6;
}
@@ -1,12 +1,12 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#include "gbi.h"
#include <limits.h>
#ifdef FORCE_BE32
#define HOST_DWORDS_PER_CMD 1
#elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFu
#include "preprocess/common.h"
#include "preprocess/gbi.h"
#if UINTPTR_MAX > 0xFFFFFFFFu
#define HOST_DWORDS_PER_CMD 2
#else
#define HOST_DWORDS_PER_CMD 1
@@ -80,11 +80,11 @@ void gbiConvertVtx(u8 *dst, u32 offset, int count)
for (int i = 0; i < count; i++) {
struct vtx* vtx = &vtxs[i];
vtx->x = srctodst16(vtx->x);
vtx->y = srctodst16(vtx->y);
vtx->z = srctodst16(vtx->z);
vtx->s = srctodst16(vtx->s);
vtx->t = srctodst16(vtx->t);
vtx->x = PD_BE16(vtx->x);
vtx->y = PD_BE16(vtx->y);
vtx->z = PD_BE16(vtx->z);
vtx->s = PD_BE16(vtx->s);
vtx->t = PD_BE16(vtx->t);
}
}
@@ -181,11 +181,11 @@ u32 gbiConvertGdl(u8 *dst, u32 dstpos, u8 *src, u32 srcpos, int segment_cmds)
u64 cmd;
do {
cmd = srctoh64(*n64_cmd);
cmd = PD_BE64(*n64_cmd);
#if HOST_DWORDS_PER_CMD == 2
host_cmd[0] = htodst64((cmd & 0xffffffff00000000) >> 32);
host_cmd[1] = htodst64(cmd & 0xffffffff);
host_cmd[0] = ((cmd & 0xffffffff00000000) >> 32);
host_cmd[1] = (cmd & 0xffffffff);
if (segment_cmds && CMD_IS_SEGMENTED(cmd)) {
host_cmd[1] |= 1;
@@ -4,16 +4,14 @@
#include <assert.h>
#include <PR/ultratypes.h>
#include <PR/gbi.h>
#include "platform.h"
#include "data.h"
#include "bss.h"
#include "game/setuputils.h"
#include "game/texdecompress.h"
#include "preprocess.h"
#include "romdata.h"
#include "mod.h"
#include "system.h"
#include "common.h"
#include "preprocess/common.h"
u8* preprocessAnimations(u8* data, u32 size, u32* outSize)
{
+40 -41
View File
@@ -4,8 +4,7 @@
#include "libaudio.h"
#include "common.h"
#include "system.h"
#include "preprocess/common.h"
struct generic_adpcm_book {
s32 order;
@@ -169,10 +168,10 @@ struct host_bankfile {
// only proceeds to convert the next item if it's not already converted
#define AL_NEXT_ITEM(field, func) { \
struct ptrmarker *marker = findPtrMarker(srcpos); \
struct ptrmarker *marker = ptrFind(srcpos); \
if (marker == NULL) { \
field = htodst32(dstpos); \
addMarker(srcpos, field); \
field = (dstpos); \
ptrAdd(srcpos, field); \
dstpos = func(dst, dstpos, src, srcpos); \
} else { \
field = marker->ptr_host; } \
@@ -185,9 +184,9 @@ static int convertAudioEnvelope(u8 *dst, int dstpos, u8 *src, int srcpos)
dstpos += sizeof(struct generic_envelope);
host_envelope->attackTime = srctodst32(n64_envelope->attackTime);
host_envelope->decayTime = srctodst32(n64_envelope->decayTime);
host_envelope->releaseTime = srctodst32(n64_envelope->releaseTime);
host_envelope->attackTime = PD_BE32(n64_envelope->attackTime);
host_envelope->decayTime = PD_BE32(n64_envelope->decayTime);
host_envelope->releaseTime = PD_BE32(n64_envelope->releaseTime);
host_envelope->attackVolume = n64_envelope->attackVolume;
host_envelope->decayVolume = n64_envelope->decayVolume;
@@ -218,12 +217,12 @@ static int convertAudioAdpcmLoop(u8 *dst, int dstpos, u8 *src, int srcpos)
dstpos += sizeof(struct generic_adpcm_loop);
host_loop->start = srctodst32(n64_loop->start);
host_loop->end = srctodst32(n64_loop->end);
host_loop->count = srctodst32(n64_loop->count);
host_loop->start = PD_BE32(n64_loop->start);
host_loop->end = PD_BE32(n64_loop->end);
host_loop->count = PD_BE32(n64_loop->count);
for (int i = 0; i < ARRAYCOUNT(host_loop->state); i++) {
host_loop->state[i] = srctodst16(n64_loop->state[i]);
host_loop->state[i] = PD_BE16(n64_loop->state[i]);
}
return dstpos;
@@ -236,11 +235,11 @@ static int convertAudioAdpcmBook(u8 *dst, int dstpos, u8 *src, int srcpos)
dstpos += sizeof(struct generic_adpcm_book);
host_book->order = srctodst32(n64_book->order);
host_book->npredictors = srctodst32(n64_book->npredictors);
host_book->order = PD_BE32(n64_book->order);
host_book->npredictors = PD_BE32(n64_book->npredictors);
for (int i = 0; i < ARRAYCOUNT(host_book->book); i++) {
host_book->book[i] = srctodst16(n64_book->book[i]);
host_book->book[i] = PD_BE16(n64_book->book[i]);
}
return dstpos;
@@ -253,9 +252,9 @@ static int convertAudioRawLoop(u8 *dst, int dstpos, u8 *src, int srcpos)
dstpos += sizeof(struct generic_raw_loop);
host_loop->start = srctodst32(n64_loop->start);
host_loop->end = srctodst32(n64_loop->end);
host_loop->count = srctodst32(n64_loop->count);
host_loop->start = PD_BE32(n64_loop->start);
host_loop->end = PD_BE32(n64_loop->end);
host_loop->count = PD_BE32(n64_loop->count);
return dstpos;
}
@@ -267,28 +266,28 @@ static int convertAudioWaveTable(u8 *dst, int dstpos, u8 *src, int srcpos)
dstpos += sizeof(struct host_wavetable);
host_wavetable->base = srctodst32(n64_wavetable->base);
host_wavetable->len = srctodst32(n64_wavetable->len);
host_wavetable->base = PD_BE32(n64_wavetable->base);
host_wavetable->len = PD_BE32(n64_wavetable->len);
host_wavetable->type = n64_wavetable->type;
host_wavetable->flags = n64_wavetable->flags;
if (host_wavetable->type == AL_ADPCM_WAVE) {
if (n64_wavetable->waveInfo.adpcmWave.loop) {
srcpos = srctoh32(n64_wavetable->waveInfo.adpcmWave.loop);
srcpos = PD_BE32(n64_wavetable->waveInfo.adpcmWave.loop);
AL_NEXT_ITEM(host_wavetable->waveInfo.adpcmWave.loop, convertAudioAdpcmLoop);
} else {
host_wavetable->waveInfo.adpcmWave.loop = 0;
}
if (n64_wavetable->waveInfo.adpcmWave.book) {
srcpos = srctoh32(n64_wavetable->waveInfo.adpcmWave.book);
srcpos = PD_BE32(n64_wavetable->waveInfo.adpcmWave.book);
AL_NEXT_ITEM(host_wavetable->waveInfo.adpcmWave.book, convertAudioAdpcmBook);
} else {
host_wavetable->waveInfo.adpcmWave.book = 0;
}
} else if (host_wavetable->type == AL_RAW16_WAVE) {
if (n64_wavetable->waveInfo.rawWave.loop) {
srcpos = srctoh32(n64_wavetable->waveInfo.rawWave.loop);
srcpos = PD_BE32(n64_wavetable->waveInfo.rawWave.loop);
AL_NEXT_ITEM(host_wavetable->waveInfo.rawWave.loop, convertAudioRawLoop);
} else {
host_wavetable->waveInfo.rawWave.loop = 0;
@@ -306,21 +305,21 @@ static int convertAudioSound(u8 *dst, int dstpos, u8 *src, int srcpos)
dstpos += sizeof(struct host_sound);
if (n64_sound->envelope) {
srcpos = srctoh32(n64_sound->envelope);
srcpos = PD_BE32(n64_sound->envelope);
AL_NEXT_ITEM(host_sound->envelope, convertAudioEnvelope);
} else {
host_sound->envelope = 0;
}
if (n64_sound->keyMap) {
srcpos = srctoh32(n64_sound->keyMap);
srcpos = PD_BE32(n64_sound->keyMap);
AL_NEXT_ITEM(host_sound->keyMap, convertAudioKeyMap);
} else {
host_sound->keyMap = 0;
}
if (n64_sound->wavetable) {
srcpos = srctoh32(n64_sound->wavetable);
srcpos = PD_BE32(n64_sound->wavetable);
AL_NEXT_ITEM(host_sound->wavetable, convertAudioWaveTable);
} else {
host_sound->wavetable = 0;
@@ -337,7 +336,7 @@ static int convertAudioInstrument(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct n64_instrument *n64_instrument = (struct n64_instrument *) &src[srcpos];
struct host_instrument *host_instrument = (struct host_instrument *) &dst[dstpos];
int soundCount = srctoh16(n64_instrument->soundCount);
int soundCount = PD_BE16(n64_instrument->soundCount);
host_instrument->volume = n64_instrument->volume;
host_instrument->pan = n64_instrument->pan;
@@ -351,13 +350,13 @@ static int convertAudioInstrument(u8 *dst, int dstpos, u8 *src, int srcpos)
host_instrument->vibRate = n64_instrument->vibRate;
host_instrument->vibDepth = n64_instrument->vibDepth;
host_instrument->vibDelay = n64_instrument->vibDelay;
host_instrument->bendRange = srctodst16(n64_instrument->bendRange);
host_instrument->soundCount = htodst16(soundCount);
host_instrument->bendRange = PD_BE16(n64_instrument->bendRange);
host_instrument->soundCount = (soundCount);
dstpos = dstpos + sizeof(struct host_instrument) + sizeof(uintptr_t) * (soundCount - 1);
for (int i = 0; i < soundCount; i++) {
srcpos = srctoh32(n64_instrument->soundArray[i]);
srcpos = PD_BE32(n64_instrument->soundArray[i]);
AL_NEXT_ITEM(host_instrument->soundArray[i], convertAudioSound);
}
@@ -368,24 +367,24 @@ static int convertAudioBank(u8 *dst, int dstpos, u8 *src, int srcpos)
{
struct n64_bank *n64_bank = (struct n64_bank *) &src[srcpos];
struct host_bank *host_bank = (struct host_bank *) &dst[dstpos];
int instCount = srctoh16(n64_bank->instCount);
int instCount = PD_BE16(n64_bank->instCount);
host_bank->instCount = htodst16(instCount);
host_bank->instCount = (instCount);
host_bank->flags = n64_bank->flags;
host_bank->pad = n64_bank->pad;
host_bank->sampleRate = srctodst32(n64_bank->sampleRate);
host_bank->sampleRate = PD_BE32(n64_bank->sampleRate);
dstpos = dstpos + sizeof(struct host_bank) + sizeof(uintptr_t) * (instCount - 1);
if (n64_bank->percussion) {
srcpos = srctoh32(n64_bank->percussion);
srcpos = PD_BE32(n64_bank->percussion);
AL_NEXT_ITEM(host_bank->percussion, convertAudioInstrument);
} else {
host_bank->percussion = 0;
}
for (int i = 0; i < instCount; i++) {
srcpos = srctoh32(n64_bank->instArray[i]);
srcpos = PD_BE32(n64_bank->instArray[i]);
AL_NEXT_ITEM(host_bank->instArray[i], convertAudioInstrument);
}
@@ -396,17 +395,17 @@ static int convertAudioBankFile(u8 *dst, u8 *src)
{
struct n64_bankfile *n64_bankfile = (struct n64_bankfile *)src;
struct host_bankfile *host_bankfile = (struct host_bankfile *)dst;
int bankCount = srctoh16(n64_bankfile->bankCount);
int bankCount = PD_BE16(n64_bankfile->bankCount);
host_bankfile->revision = srctodst16(n64_bankfile->revision);
host_bankfile->bankCount = htodst16(bankCount);
host_bankfile->revision = PD_BE16(n64_bankfile->revision);
host_bankfile->bankCount = (bankCount);
u32 dstpos = sizeof(struct host_bankfile) + sizeof(uintptr_t) * (bankCount - 1);
for (int i = 0; i < bankCount; i++) {
host_bankfile->bankArray[i] = htodst32(dstpos);
u32 srcpos = srctoh32(n64_bankfile->bankArray[i]);
host_bankfile->bankArray[i] = (dstpos);
u32 srcpos = PD_BE32(n64_bankfile->bankArray[i]);
dstpos = convertAudioBank(dst, dstpos, src, srcpos);
}
@@ -415,7 +414,7 @@ static int convertAudioBankFile(u8 *dst, u8 *src)
u8 *preprocessALBankFile(u8 *src, u32 size, u32 *outSize)
{
resetMarkers();
ptrReset();
u32 dstlen = size * 3;
u8 *dst = sysMemZeroAlloc(dstlen);
+10 -10
View File
@@ -3,8 +3,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "system.h"
#include "preprocess/common.h"
struct n64fontchar {
u8 index;
@@ -71,11 +71,11 @@ u8 *preprocessFont(u8 *src, u32 srclen, u32 *outSize)
s32 *dst_kerning_table = (s32 *)dst;
for (int i = 0; i < 13 * 13; i++) {
dst_kerning_table[i] = srctodst32(src_kerning_table[i]);
dst_kerning_table[i] = PD_BE32(src_kerning_table[i]);
}
u32 src_offset = ALIGN(13 * 13 * 4, sizeof(u32));
u32 dst_offset = ALIGN(13 * 13 * 4, sizeof(uintptr_t));
u32 src_offset = PD_ALIGN(13 * 13 * 4, sizeof(u32));
u32 dst_offset = PD_ALIGN(13 * 13 * 4, sizeof(uintptr_t));
// Character table
#if VERSION == VERSION_JPN_FINAL
@@ -84,12 +84,12 @@ u8 *preprocessFont(u8 *src, u32 srclen, u32 *outSize)
u32 diff = (dst_offset + num_chars * sizeof(struct hostfontcharjpn)) - (src_offset + num_chars * sizeof(struct n64fontcharjpn));
for (int i = 0; i < num_chars; i++) {
dst_char_table[i].index = srctodst16(src_char_table[i].index);
dst_char_table[i].index = PD_BE16(src_char_table[i].index);
dst_char_table[i].baseline = src_char_table[i].baseline;
dst_char_table[i].height = src_char_table[i].height;
dst_char_table[i].width = src_char_table[i].width;
dst_char_table[i].kerningindex = srctodst16(src_char_table[i].kerningindex);
dst_char_table[i].pixeldata = src_char_table[i].pixeldata ? srctodst32(src_char_table[i].pixeldata) + diff : 0;
dst_char_table[i].kerningindex = PD_BE16(src_char_table[i].kerningindex);
dst_char_table[i].pixeldata = src_char_table[i].pixeldata ? PD_BE32(src_char_table[i].pixeldata) + diff : 0;
}
src_offset += num_chars * sizeof(struct n64fontcharjpn);
@@ -104,8 +104,8 @@ u8 *preprocessFont(u8 *src, u32 srclen, u32 *outSize)
dst_char_table[i].baseline = src_char_table[i].baseline;
dst_char_table[i].height = src_char_table[i].height;
dst_char_table[i].width = src_char_table[i].width;
dst_char_table[i].kerningindex = srctodst32(src_char_table[i].kerningindex);
dst_char_table[i].pixeldata = src_char_table[i].pixeldata ? srctodst32(src_char_table[i].pixeldata) + diff : 0;
dst_char_table[i].kerningindex = PD_BE32(src_char_table[i].kerningindex);
dst_char_table[i].pixeldata = src_char_table[i].pixeldata ? PD_BE32(src_char_table[i].pixeldata) + diff : 0;
}
src_offset += num_chars * sizeof(struct n64fontchar);