Fix mislabeled ScreenViewport struct values, created simple macros for video with and height calcls, and found a match for func_80066940

This commit is contained in:
Ryan Myers
2021-12-11 22:59:46 -05:00
parent 7c50dca304
commit 9496ea78e5
7 changed files with 72 additions and 63 deletions
+50 -54
View File
@@ -29,6 +29,10 @@ const char D_800E7048[] = "camPopModelMtx: bsp stack negative overflow!!\n";
s8 D_800DD060 = 0;
// x1, y1, x2, y2
// posX, posY, width, height
// scissorX1, scissorY1, scissorX2, scissorY2
// flags
#define DEFAULT_VIEWPORT \
0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, \
SCREEN_WIDTH_HALF, SCREEN_HEIGHT_HALF, SCREEN_WIDTH, SCREEN_HEIGHT, \
@@ -161,7 +165,7 @@ void func_80065EA0(void) {
D_80120D18 = 0;
D_80120D15 = 0;
D_800DD060 = 0;
while (IO_READ(PI_STATUS_REG) & 3) {
while (IO_READ(PI_STATUS_REG) & PI_STATUS_ERROR) {
}
if ((D_B0000578 & 0xFFFF) != 0x8965) {
D_800DD060 = 1;
@@ -447,66 +451,58 @@ s32 func_80066910(s32 viewPortIndex) {
return gScreenViewports[viewPortIndex].flags & VIEWPORT_UNK_01;
}
#ifdef NON_MATCHING
// Should be functionally equivalent.
// proposed name: reesize_viewport
void func_80066940(s32 viewPortIndex, s32 x1, s32 x2, s32 y1, s32 y2) {
// proposed name: resize_viewport
void func_80066940(s32 viewPortIndex, s32 x1, s32 y1, s32 x2, s32 y2) {
s32 widthAndHeight, width, height;
s32 tempX1;
s32 tempY2;
s32 tempX2;
s32 temp;
widthAndHeight = get_video_width_and_height_as_s32();
width = widthAndHeight & 0xFFFF;
// Placement issues with the height variable.
height = (widthAndHeight >> 0x10) & 0xFFFF;
tempY2 = y2;
tempX2 = x2;
tempX1 = x1;
height = GET_VIDEO_HEIGHT(widthAndHeight) & 0xFFFF;
width = GET_VIDEO_WIDTH(widthAndHeight);
if (x2 < x1) {
tempX1 = x2;
tempX2 = x1;
temp = x1;
x1 = x2;
x2 = temp;
}
if (y2 < y1) {
temp = y1;
y1 = y2;
tempY2 = y1;
y2 = temp;
}
if ((tempX1 >= width) || (tempX2 < 0) || (y1 >= height) || (tempY2 < 0)) {
if ((x1 >= width) || (x2 < 0) || (y1 >= height) || (y2 < 0)) {
gScreenViewports[viewPortIndex].scissorX1 = 0;
gScreenViewports[viewPortIndex].scissorY1 = 0;
gScreenViewports[viewPortIndex].scissorX2 = 0;
gScreenViewports[viewPortIndex].scissorY2 = 0;
} else {
if (tempX1 < 0) {
if (x1 < 0) {
gScreenViewports[viewPortIndex].scissorX1 = 0;
} else {
gScreenViewports[viewPortIndex].scissorX1 = tempX1;
gScreenViewports[viewPortIndex].scissorX1 = x1;
}
if (y1 < 0) {
gScreenViewports[viewPortIndex].scissorY1 = 0;
} else {
gScreenViewports[viewPortIndex].scissorY1 = y1;
}
if (tempX2 >= width) {
if (x2 >= width) {
gScreenViewports[viewPortIndex].scissorX2 = width - 1;
} else {
gScreenViewports[viewPortIndex].scissorX2 = tempX2;
gScreenViewports[viewPortIndex].scissorX2 = x2;
}
if (tempY2 >= height) {
if (y2 >= height) {
gScreenViewports[viewPortIndex].scissorY2 = height - 1;
} else {
gScreenViewports[viewPortIndex].scissorY2 = tempY2;
gScreenViewports[viewPortIndex].scissorY2 = y2;
}
}
gScreenViewports[viewPortIndex].y1 = y1;
gScreenViewports[viewPortIndex].x1 = tempX1;
gScreenViewports[viewPortIndex].x2 = tempX2;
gScreenViewports[viewPortIndex].y2 = tempY2;
gScreenViewports[viewPortIndex].x1 = x1;
gScreenViewports[viewPortIndex].x2 = x2;
gScreenViewports[viewPortIndex].y2 = y2;
}
#else
GLOBAL_ASM("asm/non_matchings/camera/func_80066940.s")
#endif
/**
* Set the selected viewport's coordinate offsets and view size.
@@ -562,8 +558,8 @@ s32 copy_viewport_background_size_to_coords(s32 viewPortIndex, s32 *x1, s32 *y1,
*/
void copy_viewport_frame_size_to_coords(s32 viewPortIndex, s32 *x1, s32 *y1, s32 *x2, s32 *y2) {
*x1 = gScreenViewports[viewPortIndex].x1;
*y1 = gScreenViewports[viewPortIndex].x2;
*x2 = gScreenViewports[viewPortIndex].y1;
*y1 = gScreenViewports[viewPortIndex].y1;
*x2 = gScreenViewports[viewPortIndex].x2;
*y2 = gScreenViewports[viewPortIndex].y2;
}
@@ -571,11 +567,11 @@ void copy_viewport_frame_size_to_coords(s32 viewPortIndex, s32 *x1, s32 *y1, s32
* Unused function that sets the passed values to the framebuffer's size in coordinates.
*/
UNUSED void copy_framebuffer_size_to_coords(s32 *x1, s32 *y1, s32 *x2, s32 *y2) {
u32 width = get_video_width_and_height_as_s32();
u32 widthAndHeight = get_video_width_and_height_as_s32();
*x1 = 0;
*y1 = 0;
*x2 = width & 0xFFFF;
*y2 = width >> 16;
*x2 = GET_VIDEO_WIDTH(widthAndHeight);
*y2 = GET_VIDEO_HEIGHT(widthAndHeight);
}
#ifdef NON_MATCHING
@@ -592,7 +588,7 @@ void func_80066CDC(Gfx **dlist, s32 arg1) {
u32 temp_a2;
u32 temp_a3;
u32 temp_t0;
u32 temp_t1;
u32 width;
u32 widthAndHeight;
u32 temp_v0_6;
u32 phi_a1;
@@ -619,11 +615,11 @@ void func_80066CDC(Gfx **dlist, s32 arg1) {
}
return;
}
temp_t1 = widthAndHeight & 0xFFFF;
width = GET_VIDEO_WIDTH(widthAndHeight);
if (gNumberOfViewports == VIEWPORTS_COUNT_3_PLAYERS) {
gNumberOfViewports = VIEWPORTS_COUNT_4_PLAYERS;
}
temp_a2 = temp_t1 >> 1;
temp_a2 = width >> 1;
sp54 = temp_a2;
sp58 = temp_a3;
if (osTvType == TV_TYPE_PAL) {
@@ -636,7 +632,7 @@ void func_80066CDC(Gfx **dlist, s32 arg1) {
if (osTvType == TV_TYPE_PAL) {
phi_t3 = sp58 - 0x12;
}
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, temp_t1, temp_t0);
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, width, temp_t0);
sp4C = temp_a2;
break;
case VIEWPORTS_COUNT_2_PLAYERS:
@@ -646,20 +642,20 @@ void func_80066CDC(Gfx **dlist, s32 arg1) {
if (osTvType == TV_TYPE_PAL) {
phi_t3 = temp_v0_6 - 0xC;
}
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, temp_t1, (temp_a3 - (temp_t0 >> 7)));
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, width, (temp_a3 - (temp_t0 >> 7)));
} else {
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, (temp_a3 + (temp_t0 >> 7)), temp_t1, (temp_t0 - (temp_t0 >> 7)));
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, (temp_a3 + (temp_t0 >> 7)), width, (temp_t0 - (temp_t0 >> 7)));
phi_t3 = temp_a3 + (temp_t0 >> 2);
}
sp4C = temp_a2;
break;
case VIEWPORTS_COUNT_3_PLAYERS:
if (D_80120CE4 == 0) {
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, temp_a2 - (temp_t1 >> 8), temp_t0);
phi_a1 = temp_t1 >> 2;
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, temp_a2 - (width >> 8), temp_t0);
phi_a1 = width >> 2;
} else {
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, temp_a2 + (temp_t1 >> 8), 0, temp_t1 - (temp_t1 >> 8), temp_t0);
phi_a1 = temp_a2 + (temp_t1 >> 2);
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, temp_a2 + (width >> 8), 0, width - (width >> 8), temp_t0);
phi_a1 = temp_a2 + (width >> 2);
}
sp4C = phi_a1;
phi_t3 = sp58;
@@ -669,21 +665,21 @@ void func_80066CDC(Gfx **dlist, s32 arg1) {
sp54 = temp_a2 >> 1;
switch (D_80120CE4) {
case 0:
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0.0f, 0.0f, (temp_a2 - (temp_t1 >> 8)), (temp_a3 - (temp_t0 >> 7)));
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0.0f, 0.0f, (temp_a2 - (width >> 8)), (temp_a3 - (temp_t0 >> 7)));
phi_t5 = 0;
phi_t4 = 0;
case 1:
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, (temp_a2 + (temp_t1 >> 8)), 0, ((temp_a2 * 2) - (temp_t1 >> 8)), (temp_a3 - (temp_t0 >> 7)));
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, (temp_a2 + (width >> 8)), 0, ((temp_a2 * 2) - (width >> 8)), (temp_a3 - (temp_t0 >> 7)));
phi_t5 = 0;
phi_t4 = temp_a2;
break;
case 2:
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, temp_a3 + (temp_t0 >> 7), temp_a2 - (temp_t1 >> 8), (temp_a3 * 2) - (temp_t0 >> 7));
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, temp_a3 + (temp_t0 >> 7), temp_a2 - (width >> 8), (temp_a3 * 2) - (temp_t0 >> 7));
phi_t5 = temp_a3;
phi_t4 = 0;
break;
case 3:
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, temp_a2 + (temp_t1 >> 8), temp_a3 + (temp_t0 >> 7), (temp_a2 * 2) - (temp_t1 >> 8), (temp_a3 * 2) - (temp_t0 >> 7));
gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, temp_a2 + (width >> 8), temp_a3 + (temp_t0 >> 7), (temp_a2 * 2) - (width >> 8), (temp_a3 * 2) - (temp_t0 >> 7));
phi_t5 = temp_a3;
phi_t4 = temp_a2;
break;
@@ -738,8 +734,8 @@ void func_80067F2C(Gfx **dlist, s32 *arg1) {
s32 i, j;
widthAndHeight = get_video_width_and_height_as_s32();
height = widthAndHeight >> 0x10;
width = widthAndHeight & 0xFFFF;
height = GET_VIDEO_HEIGHT(widthAndHeight);
width = GET_VIDEO_WIDTH(widthAndHeight);
func_8006F870(gOrthoMatrix, *arg1);
D_80120D88[0] = *arg1;
D_800DD148[D_80120CE4 + 5].vp.vscale[0] = width * 2;
@@ -796,8 +792,8 @@ void func_800682AC(Gfx **dlist) {
u32 widthAndHeight, width, height;
D_80120CE4 = 4;
widthAndHeight = get_video_width_and_height_as_s32();
height = widthAndHeight >> 0x10;
width = widthAndHeight & 0xFFFF;
height = GET_VIDEO_HEIGHT(widthAndHeight);
width = GET_VIDEO_WIDTH(widthAndHeight);
if (!(gScreenViewports[D_80120CE4].flags & VIEWPORT_UNK_01)) {
gDPSetScissor((*dlist)++, G_SC_NON_INTERLACE, 0, 0, width - 1, height - 1);
func_80068158(dlist, width >> 1, height >> 1, width >> 1, height >> 1);
+3 -3
View File
@@ -54,8 +54,8 @@ extern s8 D_800DD060;
/* Size: 0x34 bytes. */
typedef struct ScreenViewport {
/* 0x00 */ s32 x1;
/* 0x04 */ s32 x2;
/* 0x08 */ s32 y1;
/* 0x04 */ s32 y1;
/* 0x08 */ s32 x2;
/* 0x0C */ s32 y2;
/* 0x10 */ s32 posX;
/* 0x14 */ s32 posY;
@@ -127,7 +127,7 @@ void func_800665E8(s32 arg0);
void func_80066818(s32 viewPortIndex, s32 arg1);
void func_80066894(s32 viewPortIndex, s32 arg1);
s32 func_80066910(s32 viewPortIndex);
void func_80066940(s32 viewPortIndex, s32 posX, s32 posY, s32 width, s32 height);
void func_80066940(s32 viewPortIndex, s32 x1, s32 y1, s32 x2, s32 y2);
void set_viewport_properties(s32 viewPortIndex, s32 x1, s32 x2, s32 y1, s32 y2);
s32 copy_viewport_background_size_to_coords(s32 viewPortIndex, s32 *x1, s32 *y1, s32 *x2, s32 *y2);
void copy_viewport_frame_size_to_coords(s32 viewPortIndex, s32 *arg1, s32 *arg2, s32 *arg3, s32 *arg4);
+5 -2
View File
@@ -619,8 +619,11 @@ GLOBAL_ASM("asm/non_matchings/font/s32_to_string.s")
* lrx, lry = lower-right position
*/
void render_fill_rectangle(Gfx **dlist, s32 ulx, s32 uly, s32 lrx, s32 lry) {
u32 temp_v0 = get_video_width_and_height_as_s32();
if (lrx >= 0 && ulx < (temp_v0 & 0xFFFF) && lry >= 0 && uly < (temp_v0 >> 16)) {
u32 widthAndHeight = get_video_width_and_height_as_s32();
u32 width = GET_VIDEO_WIDTH(widthAndHeight);
u32 height = GET_VIDEO_HEIGHT(widthAndHeight);
if (lrx >= 0 && ulx < width && lry >= 0 && uly < height) {
if (ulx < 0) {
ulx = 0;
}
+2 -2
View File
@@ -2170,10 +2170,10 @@ void menu_logos_screen_init(void) {
sBootScreenTimer = 16.0f;
set_background_fill_colour(0, 0, 0);
if (osTvType == TV_TYPE_PAL) {
func_80066940(0, 0, 38, SCREEN_WIDTH, 224);
func_80066940(0, 0, 38, SCREEN_WIDTH, SCREEN_HEIGHT - 16);
set_viewport_properties(0, VIEWPORT_AUTO, VIEWPORT_AUTO, SCREEN_WIDTH, SCREEN_HEIGHT + 44);
} else {
func_80066940(0, 0, 40, SCREEN_WIDTH, 196);
func_80066940(0, 0, 40, SCREEN_WIDTH, SCREEN_HEIGHT - 44);
set_viewport_properties(0, VIEWPORT_AUTO, VIEWPORT_AUTO, SCREEN_WIDTH, SCREEN_HEIGHT);
}
func_80066610();
+2 -1
View File
@@ -5,6 +5,7 @@
#include "types.h"
#include "structs.h"
#include "macros.h"
#include "video.h"
//#include "lib/src/unknown_0D24D0.h"
/************ .data ************/
@@ -277,7 +278,7 @@ GLOBAL_ASM("asm/non_matchings/unknown_078050/render_background.s")
* afterwards, alls the draw command that initialises all the rendermodes, ready for use.
*/
void init_rdp_and_framebuffer(Gfx **dlist) {
s32 width = get_video_width_and_height_as_s32() & 0xFFF;
s32 width = GET_VIDEO_WIDTH(get_video_width_and_height_as_s32());
gDPSetColorImage((*dlist)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, 0x01000000);
gDPSetDepthImage((*dlist)++, 0x2000000);
gSPDisplayList((*dlist)++, dRdpInit);
+1 -1
View File
@@ -120,7 +120,7 @@ UNUSED void set_video_width_and_height_from_index(s32 fbIndex) {
}
/**
* Return the current framebuffer dimenions as a single s32 value.
* Return the current framebuffer dimensions as a single s32 value.
* The high 16 bits are the height of the frame, and the low 16 bits are the width.
*/
s32 get_video_width_and_height_as_s32(void) {
+9
View File
@@ -32,6 +32,15 @@
#define HEIGHT_RATIO_NTSC (LOW_RES_NTSC_HEIGHT / LOW_RES_NTSC_HEIGHT)
#define HEIGHT_RATIO_MPAL (LOW_RES_MPAL_HEIGHT / LOW_RES_NTSC_HEIGHT)
/**
* The video width is the lower 16 bits of the returned 32 bit value
*/
#define GET_VIDEO_WIDTH(width_and_height) (width_and_height & 0xFFFF)
/**
* The video width is the higher 16 bits of the returned 32 bit value
*/
#define GET_VIDEO_HEIGHT(width_and_height) (width_and_height >> 16)
/**
* Values for the rate game logic will work depending on the framerate. Vanilla DKR will default to LOGIC_30FPS (2)
*/