port: make it not crash on the intro sequence and render SOME geometry

This commit is contained in:
fgsfds 2023-08-01 23:38:06 +02:00
parent 9508b136ff
commit 9433dc7769
14 changed files with 854 additions and 310 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
*.o
*.pyc
*.dll
*.exe
pd.*.z64
build
extracted

View File

@ -1291,10 +1291,17 @@ typedef union {
* Graphics DMA Packet
*/
typedef struct {
#ifdef PLATFORM_BIG_ENDIAN
int cmd:8;
unsigned int par:8;
unsigned int len:16;
unsigned int addr;
#else // NOTE: changing signedness mid int will break up the bitfield on normal platforms, even BE
int len:16;
int par:8;
int cmd:8;
unsigned int addr;
#endif
} Gdma;
/*
@ -1500,6 +1507,7 @@ typedef struct {
// xxxxxxxx 11223344 44555566 66666777
// 88888888 99999999 9999aaaa aaaaaaaa
typedef struct {
#ifdef PLATFORM_BIG_ENDIAN
unsigned int cmd:8;
unsigned int unk08:2;
unsigned int unk0a:2;
@ -1511,6 +1519,19 @@ typedef struct {
unsigned int unk20:8;
unsigned int tile1:12;
unsigned int tile2:12;
#else
unsigned int subcmd:3;
unsigned int flags:7;
unsigned int unk12:4;
unsigned int unk0e:4;
unsigned int unk0c:2;
unsigned int unk0a:2;
unsigned int unk08:2;
unsigned int cmd:8;
unsigned int tile2:12;
unsigned int tile1:12;
unsigned int unk20:8;
#endif
} GunkC0;
typedef struct {
@ -1554,7 +1575,7 @@ typedef union {
long long int force_structure_alignment;
} Gfx;
#ifdef PLATFORM_N64
#ifdef PLATFORM_BIG_ENDIAN
#define GFX_W0_BYTE(i) (i)
#define GFX_W1_BYTE(i) (4 + (i))
#else

View File

@ -73,9 +73,6 @@
#include "data.h"
#include "types.h"
#include "video.h"
#include "input.h"
extern u8 *g_MempHeap;
extern u32 g_MempHeapSize;

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <PR/ultratypes.h>
#include <PR/gbi.h>
#include "../fast3d/gfx_pc.h"
#include "../fast3d/gfx_sdl2.h"
#include "../fast3d/gfx_api.h"
#include "../fast3d/gfx_sdl.h"
#include "../fast3d/gfx_opengl.h"
static struct GfxWindowManagerAPI *wmAPI;
@ -13,11 +14,18 @@ static struct GfxRenderingAPI *renderingAPI;
static bool initDone = false;
static u32 dlcount = 0;
static u32 frames = 0;
static u32 framesPerSec = 0;
static double startTime, endTime, fpsTime;
s32 videoInit(void)
{
wmAPI = &gfx_sdl;
renderingAPI = &gfx_opengl_api;
gfx_init(wmAPI, renderingAPI, "PD", false);
gfx_current_game_window_viewport.width = 640;
gfx_current_game_window_viewport.height = 480;
gfx_init(wmAPI, renderingAPI, "PD", false, 640, 480, 100, 100);
initDone = true;
return 0;
}
@ -25,6 +33,7 @@ s32 videoInit(void)
void videoStartFrame(void)
{
if (initDone) {
startTime = wmAPI->get_time();
gfx_start_frame();
}
}
@ -33,13 +42,29 @@ void videoSubmitCommands(Gfx *cmds)
{
if (initDone) {
gfx_run(cmds);
++dlcount;
}
}
void videoEndFrame(void)
{
if (initDone) {
gfx_end_frame();
if (!initDone) {
return;
}
gfx_end_frame();
endTime = wmAPI->get_time();
++frames;
++framesPerSec;
if (endTime >= fpsTime) {
char tmp[128];
snprintf(tmp, sizeof(tmp), "fps %3u frt %lf frm %u", framesPerSec, endTime - startTime, frames);
wmAPI->set_window_title(tmp);
framesPerSec = 0;
fpsTime = endTime + 1.0;
}
}
@ -52,7 +77,7 @@ void videoClearScreen(void)
void *videoGetWindowHandle(void)
{
if (initDone && wmAPI) {
if (initDone) {
return wmAPI->get_window_handle();
}
return NULL;

View File

@ -3299,7 +3299,7 @@ s32 bgPopulateVtxBatchType(s32 roomnum, struct vtxbatch *batches, Gfx *gdl, s32
batches[batchindex].bbmax.f[j] = -32768.0f;
}
numvertices = (((u32)gdl[i].bytes[1] >> 4) & 0xf) + 1;
numvertices = (((u32)gdl[i].bytes[GFX_W0_BYTE(1)] >> 4) & 0xf) + 1;
batchvertices = (Vtx *)((uintptr_t)vertices + (gdl[i].words.w1 & 0xffffff));
for (j = 0; j < numvertices; j++) {

View File

@ -97,6 +97,7 @@ Gfx *bview0f141a20(Gfx *gdl, s32 top, s32 height, s32 left, s32 width)
Gfx *bviewCopyPixels(Gfx *gdl, u16 *fb, s32 top, u32 tile, s32 arg4, f32 arg5, s32 left, s32 width)
{
#ifdef PLATFORM_N64
uintptr_t image;
s32 width2;
s32 numparts;
@ -161,6 +162,10 @@ Gfx *bviewCopyPixels(Gfx *gdl, u16 *fb, s32 top, u32 tile, s32 arg4, f32 arg5, s
}
return gdl;
#else // PLATFORM_N64
// TODO: add an extended GBI opcode for this
return gdl;
#endif // PLATFORM_N64
}
Gfx *bviewDrawFisheyeRect(Gfx *gdl, s32 arg1, f32 arg2, s32 arg3, s32 arg4)

View File

@ -9839,7 +9839,11 @@ bool aiIfMusicEventQueueIsEmpty(void)
{
f32 value = (u64)osGetCount() * 64 / 3000;
#ifdef PLATFORM_N64
if (g_MusicEventQueueLength) {
#else // don't hang when sound is disabled
if (g_MusicEventQueueLength && !g_SndDisabled) {
#endif
g_Vars.aioffset += 4;
} else {
u8 *cmd = g_Vars.ailist + g_Vars.aioffset;

View File

@ -7,6 +7,7 @@
void mtxF2LBulk(Mtxf *mtx, s32 count)
{
#ifndef GBI_FLOATS
do {
u32 m00 = (s32) (mtx->m[0][0] * var8005ef10[0]);
u32 m01 = (s32) (mtx->m[0][1] * var8005ef10[0]);
@ -46,4 +47,5 @@ void mtxF2LBulk(Mtxf *mtx, s32 count)
count--;
} while (count);
#endif
}

View File

@ -22,6 +22,7 @@
#include "lib/mtx.h"
#include "data.h"
#include "types.h"
#include "platform.h"
struct objective *g_Objectives[MAX_OBJECTIVES];
u32 g_ObjectiveStatuses[MAX_OBJECTIVES];
@ -210,11 +211,11 @@ s32 objectiveCheck(s32 index)
// iteration of the while loop below will skip past it.
u32 *cmd = (u32 *)g_Objectives[index];
while ((u8)cmd[0] != OBJTYPE_ENDOBJECTIVE) {
while ((u8)PD_BE32(cmd[0]) != OBJTYPE_ENDOBJECTIVE) {
// The status of this requirement
s32 reqstatus = OBJECTIVE_COMPLETE;
switch ((u8)cmd[0]) {
switch ((u8)PD_BE32(cmd[0])) {
case OBJECTIVETYPE_DESTROYOBJ:
{
struct defaultobj *obj = objFindByTagId(cmd[1]);

View File

@ -5,14 +5,15 @@
#include "bss.h"
#include "data.h"
#include "types.h"
#include "platform.h"
void objsStop(void)
{
u32 *ptr = g_StageSetup.props;
if (ptr) {
while ((u8)ptr[0] != OBJTYPE_END) {
switch ((u8)ptr[0]) {
while ((u8)PD_BE32(ptr[0]) != OBJTYPE_END) {
switch ((u8)PD_BE32(ptr[0])) {
case OBJTYPE_DOOR:
case OBJTYPE_BASIC:
case OBJTYPE_KEY:

View File

@ -11,6 +11,7 @@
#include "bss.h"
#include "data.h"
#include "types.h"
#include "platform.h"
struct stagesetup g_StageSetup;
u8 *g_GeCreditsData;
@ -23,7 +24,7 @@ u32 setupGetCmdLength(u32 *cmd)
mainOverrideVariable("crash1", &crash1);
#endif
switch ((u8)cmd[0]) {
switch ((u8)PD_BE32(cmd[0])) {
case OBJTYPE_CHR: return 11;
case OBJTYPE_DOOR: return 55;
case OBJTYPE_DOORSCALE: return 2;
@ -98,7 +99,7 @@ u32 *setupGetCmdByIndex(s32 wantindex)
if (wantindex >= 0 && cmd) {
s32 cmdindex = 0;
while ((u8)cmd[0] != OBJTYPE_END) {
while ((u8)PD_BE32(cmd[0]) != OBJTYPE_END) {
if (cmdindex == wantindex) {
return cmd;
}
@ -118,7 +119,7 @@ s32 setupGetCmdIndexByTag(struct tag *tag)
if (cmd) {
s32 cmdindex = 0;
while ((u8)cmd[0] != OBJTYPE_END) {
while ((u8)PD_BE32(cmd[0]) != OBJTYPE_END) {
if ((struct tag *)cmd == tag) {
return cmdindex;
}
@ -138,7 +139,7 @@ u32 setupGetCmdIndexByProp(struct prop *prop)
if (cmd) {
s32 cmdindex = 0;
while ((u8)cmd[0] != OBJTYPE_END) {
while ((u8)PD_BE32(cmd[0]) != OBJTYPE_END) {
if ((struct prop *)cmd[5] == prop) {
return cmdindex;
}
@ -216,7 +217,7 @@ struct defaultobj *setupGetObjByCmdIndex(u32 cmdindex)
u32 *cmd = setupGetCmdByIndex(cmdindex);
if (cmd) {
switch ((u8)cmd[0]) {
switch ((u8)PD_BE32(cmd[0])) {
case OBJTYPE_DOOR:
case OBJTYPE_BASIC:
case OBJTYPE_KEY:
@ -309,8 +310,8 @@ struct defaultobj *setupFindObjForReuse(s32 wanttype, struct defaultobj **offscr
u32 *cmd = g_StageSetup.props;
if (cmd) {
while ((u8)cmd[0] != OBJTYPE_END) {
if ((wanttype & 0xff) == (u8)cmd[0]) {
while ((u8)PD_BE32(cmd[0]) != OBJTYPE_END) {
if ((wanttype & 0xff) == (u8)PD_BE32(cmd[0])) {
struct defaultobj *obj = (struct defaultobj *)cmd;
if (obj->prop == NULL) {

View File

@ -313,9 +313,15 @@ struct prop {
};
struct packedpad {
#ifdef PLATFORM_BIG_ENDIAN
s32 liftnum : 4;
s32 flags : 18;
s32 room : 10;
#else
s32 liftnum : 4;
s32 room : 10;
s32 flags : 18;
#endif
};
struct pad {

View File

@ -320,6 +320,7 @@ u32 mtxGetObfuscatedRomBase(void)
void mtxF2L(Mtxf *src, Mtxf *dst)
{
#ifndef GBI_FLOATS
u32 src00 = (s32) (src->m[0][0] * var8005ef10[0]);
u32 src01 = (s32) (src->m[0][1] * var8005ef10[0]);
u32 src02 = (s32) (src->m[0][2] * var8005ef10[0]);
@ -354,4 +355,7 @@ void mtxF2L(Mtxf *src, Mtxf *dst)
dst->l[3][1] = src22 << 16 | (src23 & 0xffff);
dst->l[3][2] = src30 << 16 | (src31 & 0xffff);
dst->l[3][3] = src32 << 16 | (src33 & 0xffff);
#else
bcopy(src, dst, sizeof(*dst));
#endif
}