diff --git a/include/PR/gbi.h b/include/PR/gbi.h index 79401166e..e10a51b95 100644 --- a/include/PR/gbi.h +++ b/include/PR/gbi.h @@ -1356,12 +1356,21 @@ typedef struct { } GsetothermodeH; typedef struct { +#ifdef PLATFORM_BIG_ENDIAN unsigned char cmd; unsigned char lodscale; unsigned char tile; unsigned char on; unsigned short s; unsigned short t; +#else + unsigned char on; + unsigned char tile; + unsigned char lodscale; + unsigned char cmd; + unsigned short t; + unsigned short s; +#endif } Gtexture; typedef struct { @@ -1543,6 +1552,14 @@ typedef union { long long int force_structure_alignment; } Gfx; +#ifdef PLATFORM_N64 +#define GFX_W0_BYTE(i) (i) +#define GFX_W1_BYTE(i) (4 + (i)) +#else +#define GFX_W0_BYTE(i) (3 - (i)) +#define GFX_W1_BYTE(i) (7 - (i)) +#endif + /* * Macros to assemble the graphics display list */ diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h index 2754f2504..15ee60f3f 100644 --- a/include/PR/os_cont.h +++ b/include/PR/os_cont.h @@ -53,14 +53,14 @@ extern "C" { typedef struct { u16 type; /* Controller Type */ u8 status; /* Controller status */ - u8 errno; + u8 errnum; }OSContStatus; typedef struct { u16 button; s8 stick_x; /* -80 <= stick_x <= 80 */ s8 stick_y; /* -80 <= stick_y <= 80 */ - u8 errno; + u8 errnum; } OSContPad; typedef struct { @@ -68,7 +68,7 @@ typedef struct { u8 databuffer[32]; /* address of the data buffer */ u8 addressCrc; /* CRC code for address */ u8 dataCrc; /* CRC code for data */ - u8 errno; + u8 errnum; } OSContRamIo; diff --git a/port/n64-fast3d-engine/LICENSE.txt b/port/fast3d/LICENSE.txt similarity index 100% rename from port/n64-fast3d-engine/LICENSE.txt rename to port/fast3d/LICENSE.txt diff --git a/port/n64-fast3d-engine/gfx_cc.c b/port/fast3d/gfx_cc.c similarity index 100% rename from port/n64-fast3d-engine/gfx_cc.c rename to port/fast3d/gfx_cc.c diff --git a/port/n64-fast3d-engine/gfx_cc.h b/port/fast3d/gfx_cc.h similarity index 100% rename from port/n64-fast3d-engine/gfx_cc.h rename to port/fast3d/gfx_cc.h diff --git a/port/n64-fast3d-engine/gfx_opengl.c b/port/fast3d/gfx_opengl.c similarity index 100% rename from port/n64-fast3d-engine/gfx_opengl.c rename to port/fast3d/gfx_opengl.c diff --git a/port/n64-fast3d-engine/gfx_opengl.h b/port/fast3d/gfx_opengl.h similarity index 100% rename from port/n64-fast3d-engine/gfx_opengl.h rename to port/fast3d/gfx_opengl.h diff --git a/port/n64-fast3d-engine/gfx_pc.c b/port/fast3d/gfx_pc.c similarity index 89% rename from port/n64-fast3d-engine/gfx_pc.c rename to port/fast3d/gfx_pc.c index e8ccf15c8..66d525f3f 100644 --- a/port/n64-fast3d-engine/gfx_pc.c +++ b/port/fast3d/gfx_pc.c @@ -12,6 +12,8 @@ #endif #include +#include "platform.h" + #include "gfx_pc.h" #include "gfx_cc.h" #include "gfx_window_manager_api.h" @@ -28,8 +30,8 @@ #define SCALE_3_8(VAL_) ((VAL_) * 0x24) #define SCALE_8_3(VAL_) ((VAL_) / 0x24) -#define SCREEN_WIDTH 320 -#define SCREEN_HEIGHT 240 +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 #define HALF_SCREEN_WIDTH (SCREEN_WIDTH / 2) #define HALF_SCREEN_HEIGHT (SCREEN_HEIGHT / 2) @@ -40,6 +42,9 @@ #define MAX_LIGHTS 2 #define MAX_VERTICES 64 +#define C0(pos, width) ((cmd->words.w0 >> (pos)) & ((1U << width) - 1)) +#define C1(pos, width) ((cmd->words.w1 >> (pos)) & ((1U << width) - 1)) + struct RGBA { uint8_t r, g, b, a; }; @@ -114,7 +119,6 @@ static struct RSP { } rsp; static struct RDP { - const uint8_t *palette; struct { const uint8_t *addr; uint8_t siz; @@ -128,9 +132,18 @@ static struct RDP { uint8_t fmt; uint8_t siz; uint8_t cms, cmt; + uint8_t shifts, shiftt; uint16_t uls, ult, lrs, lrt; // U10.2 + uint16_t tmem; // 0-511, in 64-bit word units uint32_t line_size_bytes; - } texture_tile; + uint8_t palette; + uint8_t tmem_index; // 0 or 1 for offset 0 kB or offset 2 kB, respectively + } texture_tile[8]; + struct { + const uint16_t *ptr; + uint32_t fmt; + } palette; + bool textures_changed[2]; uint32_t other_mode_l, other_mode_h; @@ -297,15 +310,15 @@ static void import_texture_rgba16(int tile) { rgba32_buf[4*i + 3] = a ? 255 : 0; } - uint32_t width = rdp.texture_tile.line_size_bytes / 2; - uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes / 2; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rgba32_buf, width, height); } static void import_texture_rgba32(int tile) { - uint32_t width = rdp.texture_tile.line_size_bytes / 2; - uint32_t height = (rdp.loaded_texture[tile].size_bytes / 2) / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes / 2; + uint32_t height = (rdp.loaded_texture[tile].size_bytes / 2) / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rdp.loaded_texture[tile].addr, width, height); } @@ -326,8 +339,8 @@ static void import_texture_ia4(int tile) { rgba32_buf[4*i + 3] = alpha ? 255 : 0; } - uint32_t width = rdp.texture_tile.line_size_bytes * 2; - uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes * 2; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rgba32_buf, width, height); } @@ -347,8 +360,8 @@ static void import_texture_ia8(int tile) { rgba32_buf[4*i + 3] = SCALE_4_8(alpha); } - uint32_t width = rdp.texture_tile.line_size_bytes; - uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rgba32_buf, width, height); } @@ -368,8 +381,8 @@ static void import_texture_ia16(int tile) { rgba32_buf[4*i + 3] = alpha; } - uint32_t width = rdp.texture_tile.line_size_bytes / 2; - uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes / 2; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rgba32_buf, width, height); } @@ -390,8 +403,8 @@ static void import_texture_i4(int tile) { rgba32_buf[4*i + 3] = 255; } - uint32_t width = rdp.texture_tile.line_size_bytes * 2; - uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes * 2; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rgba32_buf, width, height); } @@ -410,32 +423,46 @@ static void import_texture_i8(int tile) { rgba32_buf[4*i + 3] = 255; } - uint32_t width = rdp.texture_tile.line_size_bytes; - uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rgba32_buf, width, height); } +static inline void palette_to_rgba32(const uint32_t idx, uint8_t *rgba32_buf) { + const uint8_t *cptr = rdp.palette.ptr + idx; + if (rdp.palette.fmt == G_TT_IA16) { + const uint8_t intensity = cptr[0]; + const uint8_t alpha = cptr[1]; + rgba32_buf[0] = intensity; + rgba32_buf[1] = intensity; + rgba32_buf[2] = intensity; + rgba32_buf[3] = alpha; + } else { + // assume G_TT_RGBA16 + const uint16_t col16 = PD_BE16(*cptr); + const uint8_t a = col16 & 1; + const uint8_t r = col16 >> 11; + const uint8_t g = (col16 >> 6) & 0x1f; + const uint8_t b = (col16 >> 1) & 0x1f; + rgba32_buf[0] = SCALE_5_8(r); + rgba32_buf[1] = SCALE_5_8(g); + rgba32_buf[2] = SCALE_5_8(b); + rgba32_buf[3] = a ? 255 : 0; + } +} static void import_texture_ci4(int tile) { uint8_t rgba32_buf[32768]; for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes * 2; i++) { - uint8_t byte = rdp.loaded_texture[tile].addr[i / 2]; - uint8_t idx = (byte >> (4 - (i % 2) * 4)) & 0xf; - uint16_t col16 = (rdp.palette[idx * 2] << 8) | rdp.palette[idx * 2 + 1]; // Big endian load - uint8_t a = col16 & 1; - uint8_t r = col16 >> 11; - uint8_t g = (col16 >> 6) & 0x1f; - uint8_t b = (col16 >> 1) & 0x1f; - rgba32_buf[4*i + 0] = SCALE_5_8(r); - rgba32_buf[4*i + 1] = SCALE_5_8(g); - rgba32_buf[4*i + 2] = SCALE_5_8(b); - rgba32_buf[4*i + 3] = a ? 255 : 0; + const uint8_t byte = rdp.loaded_texture[tile].addr[i / 2]; + const uint8_t idx = (byte >> (4 - (i % 2) * 4)) & 0xf; + palette_to_rgba32(idx, rgba32_buf + 4*i); } - uint32_t width = rdp.texture_tile.line_size_bytes * 2; - uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes * 2; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rgba32_buf, width, height); } @@ -444,27 +471,19 @@ static void import_texture_ci8(int tile) { uint8_t rgba32_buf[16384]; for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes; i++) { - uint8_t idx = rdp.loaded_texture[tile].addr[i]; - uint16_t col16 = (rdp.palette[idx * 2] << 8) | rdp.palette[idx * 2 + 1]; // Big endian load - uint8_t a = col16 & 1; - uint8_t r = col16 >> 11; - uint8_t g = (col16 >> 6) & 0x1f; - uint8_t b = (col16 >> 1) & 0x1f; - rgba32_buf[4*i + 0] = SCALE_5_8(r); - rgba32_buf[4*i + 1] = SCALE_5_8(g); - rgba32_buf[4*i + 2] = SCALE_5_8(b); - rgba32_buf[4*i + 3] = a ? 255 : 0; + const uint8_t idx = rdp.loaded_texture[tile].addr[i]; + palette_to_rgba32(idx, rgba32_buf + 4*i); } - uint32_t width = rdp.texture_tile.line_size_bytes; - uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + uint32_t width = rdp.texture_tile[tile].line_size_bytes; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile[tile].line_size_bytes; gfx_rapi->upload_texture(rgba32_buf, width, height); } static void import_texture(int tile) { - uint8_t fmt = rdp.texture_tile.fmt; - uint8_t siz = rdp.texture_tile.siz; + uint8_t fmt = rdp.texture_tile[tile].fmt; + uint8_t siz = rdp.texture_tile[tile].siz; if (gfx_texture_cache_lookup(tile, &rendering_state.textures[tile], rdp.loaded_texture[tile].addr, fmt, siz)) { return; @@ -658,12 +677,8 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti doty += normcolor->y * rsp.current_lookat_coeffs[1][1]; doty += normcolor->z * rsp.current_lookat_coeffs[1][2]; - float ssc = rsp.texture_scaling_factor.s; - float tsc = rsp.texture_scaling_factor.t; - - //U = (int32_t)((dotx / 127.0f + 1.0f) / 4.0f * rsp.texture_scaling_factor.s); - //V = (int32_t)((doty / 127.0f + 1.0f) / 4.0f * rsp.texture_scaling_factor.t); - + const float ssc = rsp.texture_scaling_factor.s; + const float tsc = rsp.texture_scaling_factor.t; U = (int32_t)((dotx / 127.0f + 1.0f) / 4.0f * ssc); V = (int32_t)((doty / 127.0f + 1.0f) / 4.0f * tsc); } @@ -711,7 +726,71 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti } } -static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) { +static void gfx_get_texture_size(const uint32_t tile, uint32_t *out_w, uint32_t *out_h) { + const uint32_t tex_size_bytes = rdp.loaded_texture[tile].size_bytes; + uint32_t line_size = rdp.texture_tile[tile].line_size_bytes; + + if (line_size == 0) { + line_size = 1; + } + + uint32_t tex_height = tex_size_bytes / line_size; + switch (rdp.texture_tile[tile].siz) { + case G_IM_SIZ_4b: + line_size <<= 1; + break; + case G_IM_SIZ_8b: + break; + case G_IM_SIZ_16b: + line_size /= G_IM_SIZ_16b_LINE_BYTES; + break; + case G_IM_SIZ_32b: + line_size /= G_IM_SIZ_32b_LINE_BYTES; // this is 2! + tex_height /= 2; + break; + } + + *out_w = line_size; + *out_h = tex_height; +} + +static inline void gfx_get_texture_uv(const uint32_t tile, const bool is_rect, float *inout_u, float *inout_v) { + float u = *inout_u / 32.0f; + float v = *inout_v / 32.0f; + + const int shifts = rdp.texture_tile[tile].shifts; + const int shiftt = rdp.texture_tile[tile].shiftt; + if (shifts != 0) { + if (shifts <= 10) { + u /= 1 << shifts; + } else { + u *= 1 << (16 - shifts); + } + } + if (shiftt != 0) { + if (shiftt <= 10) { + v /= 1 << shiftt; + } else { + v *= 1 << (16 - shiftt); + } + } + + u -= rdp.texture_tile[tile].uls / 4.0f; + v -= rdp.texture_tile[tile].ult / 4.0f; + + if ((rdp.other_mode_h & (3U << G_MDSFT_TEXTFILT)) != G_TF_POINT) { + // Linear filter adds 0.5f to the coordinates + if (is_rect) { + u += 0.5f; + v += 0.5f; + } + } + + *inout_u = u; + *inout_v = v; +} + +static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bool is_rect) { struct LoadedVertex *v1 = &rsp.loaded_vertices[vtx1_idx]; struct LoadedVertex *v2 = &rsp.loaded_vertices[vtx2_idx]; struct LoadedVertex *v3 = &rsp.loaded_vertices[vtx3_idx]; @@ -822,6 +901,10 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) { bool used_textures[2]; gfx_rapi->shader_get_info(prg, &num_inputs, used_textures); + uint32_t tm = 0; + uint32_t tex_width, tex_height; + gfx_get_texture_size(G_TX_RENDERTILE, &tex_width, &tex_height); + for (int i = 0; i < 2; i++) { if (used_textures[i]) { if (rdp.textures_changed[i]) { @@ -829,22 +912,19 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) { import_texture(i); rdp.textures_changed[i] = false; } - bool linear_filter = (rdp.other_mode_h & (3U << G_MDSFT_TEXTFILT)) != G_TF_POINT; - if (linear_filter != rendering_state.textures[i]->linear_filter || rdp.texture_tile.cms != rendering_state.textures[i]->cms || rdp.texture_tile.cmt != rendering_state.textures[i]->cmt) { + const bool linear_filter = (rdp.other_mode_h & (3U << G_MDSFT_TEXTFILT)) != G_TF_POINT; + if (linear_filter != rendering_state.textures[i]->linear_filter || rdp.texture_tile[i].cms != rendering_state.textures[i]->cms || rdp.texture_tile[i].cmt != rendering_state.textures[i]->cmt) { gfx_flush(); - gfx_rapi->set_sampler_parameters(i, linear_filter, rdp.texture_tile.cms, rdp.texture_tile.cmt); + gfx_rapi->set_sampler_parameters(i, linear_filter, rdp.texture_tile[i].cms, rdp.texture_tile[i].cmt); rendering_state.textures[i]->linear_filter = linear_filter; - rendering_state.textures[i]->cms = rdp.texture_tile.cms; - rendering_state.textures[i]->cmt = rdp.texture_tile.cmt; + rendering_state.textures[i]->cms = rdp.texture_tile[i].cms; + rendering_state.textures[i]->cmt = rdp.texture_tile[i].cmt; } } } - bool use_texture = used_textures[0] || used_textures[1]; - uint32_t tex_width = (rdp.texture_tile.lrs - rdp.texture_tile.uls + 4) / 4; - uint32_t tex_height = (rdp.texture_tile.lrt - rdp.texture_tile.ult + 4) / 4; - - bool z_is_from_0_to_1 = gfx_rapi->z_is_from_0_to_1(); + const bool use_texture = used_textures[0] || used_textures[1]; + const bool z_is_from_0_to_1 = gfx_rapi->z_is_from_0_to_1(); for (int i = 0; i < 3; i++) { float z = v_arr[i]->z, w = v_arr[i]->w; @@ -857,13 +937,9 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) { buf_vbo[buf_vbo_len++] = w; if (use_texture) { - float u = (v_arr[i]->u - rdp.texture_tile.uls * 8) / 32.0f; - float v = (v_arr[i]->v - rdp.texture_tile.ult * 8) / 32.0f; - if ((rdp.other_mode_h & (3U << G_MDSFT_TEXTFILT)) != G_TF_POINT) { - // Linear filter adds 0.5f to the coordinates - u += 0.5f; - v += 0.5f; - } + float u = v_arr[i]->u; + float v = v_arr[i]->v; + gfx_get_texture_uv(G_TX_RENDERTILE, is_rect, &u, &v); buf_vbo[buf_vbo_len++] = u / tex_width; buf_vbo[buf_vbo_len++] = v / tex_height; } @@ -928,6 +1004,41 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx) { } } +static void gfx_sp_tri4(Gfx *cmd) { + // the game issues gSPTri2 for quads, which uses G_TRI4 with 2 empty triangles + uint8_t x = C1(0, 4); + uint8_t y = C1(4, 4); + uint8_t z = C0(0, 4); + + if(x || y || z) { + gfx_sp_tri1(x, y, z, false); + } + + x = C1(8, 4); + y = C1(12, 4); + z = C0(4, 4); + + if (x || y || z) { + gfx_sp_tri1(x, y, z, false); + } + + x = C1(16, 4); + y = C1(20, 4); + z = C0(8, 4); + + if (x || y || z) { + gfx_sp_tri1(x, y, z, false); + } + + x = C1(24, 4); + y = C1(28, 4); + z = C0(12, 4); + + if (x || y || z) { + gfx_sp_tri1(x, y, z, false); + } +} + static void gfx_sp_geometry_mode(uint32_t clear, uint32_t set) { rsp.geometry_mode &= ~clear; rsp.geometry_mode |= set; @@ -1034,11 +1145,13 @@ static void gfx_dp_set_texture_image(uint32_t format, uint32_t size, uint32_t wi static void gfx_dp_set_tile(uint8_t fmt, uint32_t siz, uint32_t line, uint32_t tmem, uint8_t tile, uint32_t palette, uint32_t cmt, uint32_t maskt, uint32_t shiftt, uint32_t cms, uint32_t masks, uint32_t shifts) { if (tile == G_TX_RENDERTILE) { SUPPORT_CHECK(palette == 0); // palette should set upper 4 bits of color index in 4b mode - rdp.texture_tile.fmt = fmt; - rdp.texture_tile.siz = siz; - rdp.texture_tile.cms = cms; - rdp.texture_tile.cmt = cmt; - rdp.texture_tile.line_size_bytes = line * 8; + rdp.texture_tile[tile].fmt = fmt; + rdp.texture_tile[tile].siz = siz; + rdp.texture_tile[tile].cms = cms; + rdp.texture_tile[tile].cmt = cmt; + rdp.texture_tile[tile].shifts = shifts; + rdp.texture_tile[tile].shiftt = shiftt; + rdp.texture_tile[tile].line_size_bytes = line * 8; rdp.textures_changed[0] = true; rdp.textures_changed[1] = true; } @@ -1050,10 +1163,10 @@ static void gfx_dp_set_tile(uint8_t fmt, uint32_t siz, uint32_t line, uint32_t t static void gfx_dp_set_tile_size(uint8_t tile, uint16_t uls, uint16_t ult, uint16_t lrs, uint16_t lrt) { if (tile == G_TX_RENDERTILE) { - rdp.texture_tile.uls = uls; - rdp.texture_tile.ult = ult; - rdp.texture_tile.lrs = lrs; - rdp.texture_tile.lrt = lrt; + rdp.texture_tile[tile].uls = uls; + rdp.texture_tile[tile].ult = ult; + rdp.texture_tile[tile].lrs = lrs; + rdp.texture_tile[tile].lrt = lrt; rdp.textures_changed[0] = true; rdp.textures_changed[1] = true; } @@ -1062,7 +1175,7 @@ static void gfx_dp_set_tile_size(uint8_t tile, uint16_t uls, uint16_t ult, uint1 static void gfx_dp_load_tlut(uint8_t tile, uint32_t high_index) { //SUPPORT_CHECK(tile == G_TX_LOADTILE); SUPPORT_CHECK(rdp.texture_to_load.siz == G_IM_SIZ_16b); - rdp.palette = rdp.texture_to_load.addr; + rdp.palette.ptr = (uint16_t *)rdp.texture_to_load.addr; } static void gfx_dp_load_block(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t lrs, uint32_t dxt) { @@ -1122,10 +1235,10 @@ static void gfx_dp_load_tile(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t assert(size_bytes <= 4096 && "bug: too big texture"); rdp.loaded_texture[rdp.texture_to_load.tile_number].addr = rdp.texture_to_load.addr; - rdp.texture_tile.uls = uls; - rdp.texture_tile.ult = ult; - rdp.texture_tile.lrs = lrs; - rdp.texture_tile.lrt = lrt; + rdp.texture_tile[tile].uls = uls; + rdp.texture_tile[tile].ult = ult; + rdp.texture_tile[tile].lrs = lrs; + rdp.texture_tile[tile].lrt = lrt; rdp.textures_changed[rdp.texture_to_load.tile_number] = true; } @@ -1256,8 +1369,8 @@ static void gfx_draw_rectangle(int32_t ulx, int32_t uly, int32_t lrx, int32_t lr rdp.viewport_or_scissor_changed = true; rsp.geometry_mode = 0; - gfx_sp_tri1(MAX_VERTICES + 0, MAX_VERTICES + 1, MAX_VERTICES + 3); - gfx_sp_tri1(MAX_VERTICES + 1, MAX_VERTICES + 2, MAX_VERTICES + 3); + gfx_sp_tri1(MAX_VERTICES + 0, MAX_VERTICES + 1, MAX_VERTICES + 3, true); + gfx_sp_tri1(MAX_VERTICES + 1, MAX_VERTICES + 2, MAX_VERTICES + 3, true); rsp.geometry_mode = geometry_mode_saved; rdp.viewport = viewport_saved; @@ -1358,6 +1471,7 @@ static void gfx_sp_set_other_mode(uint32_t shift, uint32_t num_bits, uint64_t mo om = (om & ~mask) | mode; rdp.other_mode_l = (uint32_t)om; rdp.other_mode_h = (uint32_t)(om >> 32); + rdp.palette.fmt = rdp.other_mode_h & (3U << G_MDSFT_TEXTLUT); } static void gfx_sp_set_vertex_colors(uint32_t count, union Vec4b* rgba) { @@ -1377,9 +1491,6 @@ static inline void *seg_addr(const uintptr_t w1) { return (void *) w1; } -#define C0(pos, width) ((cmd->words.w0 >> (pos)) & ((1U << width) - 1)) -#define C1(pos, width) ((cmd->words.w1 >> (pos)) & ((1U << width) - 1)) - static void gfx_run_dl(Gfx* cmd) { int dummy = 0; for (;;) { @@ -1456,24 +1567,21 @@ static void gfx_run_dl(Gfx* cmd) { #endif case (uint8_t)G_TRI1: #ifdef F3DEX_GBI_2 - gfx_sp_tri1(C0(16, 8) / 2, C0(8, 8) / 2, C0(0, 8) / 2); + gfx_sp_tri1(C0(16, 8) / 2, C0(8, 8) / 2, C0(0, 8) / 2, false); #elif defined(F3DEX_GBI) || defined(F3DLP_GBI) - gfx_sp_tri1(C1(16, 8) / 2, C1(8, 8) / 2, C1(0, 8) / 2); + gfx_sp_tri1(C1(16, 8) / 2, C1(8, 8) / 2, C1(0, 8) / 2, false); #else - gfx_sp_tri1(C1(16, 8) / 10, C1(8, 8) / 10, C1(0, 8) / 10); + gfx_sp_tri1(C1(16, 8) / 10, C1(8, 8) / 10, C1(0, 8) / 10, false); #endif break; #if defined(F3DEX_GBI) || defined(F3DLP_GBI) case (uint8_t)G_TRI2: - gfx_sp_tri1(C0(16, 8) / 2, C0(8, 8) / 2, C0(0, 8) / 2); - gfx_sp_tri1(C1(16, 8) / 2, C1(8, 8) / 2, C1(0, 8) / 2); + gfx_sp_tri1(C0(16, 8) / 2, C0(8, 8) / 2, C0(0, 8) / 2, false); + gfx_sp_tri1(C1(16, 8) / 2, C1(8, 8) / 2, C1(0, 8) / 2, false); break; #endif case (uint8_t)G_TRI4: - gfx_sp_tri1(C1(0, 4), C1(4, 4), C0(0, 4)); - gfx_sp_tri1(C1(8, 4), C1(12, 4), C0(4, 4)); - gfx_sp_tri1(C1(16, 4), C1(20, 4), C0(8, 4)); - gfx_sp_tri1(C1(24, 4), C1(28, 4), C0(12, 4)); + gfx_sp_tri4(cmd); break; case (uint8_t)G_SETOTHERMODE_L: #ifdef F3DEX_GBI_2 diff --git a/port/n64-fast3d-engine/gfx_pc.h b/port/fast3d/gfx_pc.h similarity index 100% rename from port/n64-fast3d-engine/gfx_pc.h rename to port/fast3d/gfx_pc.h diff --git a/port/n64-fast3d-engine/gfx_rendering_api.h b/port/fast3d/gfx_rendering_api.h similarity index 100% rename from port/n64-fast3d-engine/gfx_rendering_api.h rename to port/fast3d/gfx_rendering_api.h diff --git a/port/n64-fast3d-engine/gfx_screen_config.h b/port/fast3d/gfx_screen_config.h similarity index 100% rename from port/n64-fast3d-engine/gfx_screen_config.h rename to port/fast3d/gfx_screen_config.h diff --git a/port/n64-fast3d-engine/gfx_sdl2.c b/port/fast3d/gfx_sdl2.c similarity index 100% rename from port/n64-fast3d-engine/gfx_sdl2.c rename to port/fast3d/gfx_sdl2.c diff --git a/port/n64-fast3d-engine/gfx_sdl2.h b/port/fast3d/gfx_sdl2.h similarity index 100% rename from port/n64-fast3d-engine/gfx_sdl2.h rename to port/fast3d/gfx_sdl2.h diff --git a/port/n64-fast3d-engine/gfx_window_manager_api.h b/port/fast3d/gfx_window_manager_api.h similarity index 100% rename from port/n64-fast3d-engine/gfx_window_manager_api.h rename to port/fast3d/gfx_window_manager_api.h diff --git a/port/n64-fast3d-engine/glad/glad.c b/port/fast3d/glad/glad.c similarity index 100% rename from port/n64-fast3d-engine/glad/glad.c rename to port/fast3d/glad/glad.c diff --git a/port/n64-fast3d-engine/glad/glad.h b/port/fast3d/glad/glad.h similarity index 100% rename from port/n64-fast3d-engine/glad/glad.h rename to port/fast3d/glad/glad.h diff --git a/port/n64-fast3d-engine/glad/khrplatform.h b/port/fast3d/glad/khrplatform.h similarity index 100% rename from port/n64-fast3d-engine/glad/khrplatform.h rename to port/fast3d/glad/khrplatform.h diff --git a/port/src/libultra.c b/port/src/libultra.c index 21ca2d881..6e551c8df 100644 --- a/port/src/libultra.c +++ b/port/src/libultra.c @@ -199,9 +199,9 @@ void osContGetReadData(OSContPad *pad) pad->stick_x = 0; pad->stick_y = 0; if (inputReadController(i, pad) < 0) { - pad->errno = CONT_NO_RESPONSE_ERROR; + pad->errnum = CONT_NO_RESPONSE_ERROR; } else { - pad->errno = 0; + pad->errnum = 0; } } } @@ -216,11 +216,11 @@ void osContGetQuery(OSContStatus *status) // also always 4 status structs here for (s32 i = 0; i < MAXCONTROLLERS; ++i, ++status) { if (inputControllerConnected(i)) { - status->errno = 0; + status->errnum = 0; status->type = CONT_ABSOLUTE; status->status = 1; } else { - status->errno = CONT_NO_RESPONSE_ERROR; + status->errnum = CONT_NO_RESPONSE_ERROR; status->type = 0; status->status = 0; } diff --git a/port/src/main.c b/port/src/main.c index 534a706c3..cb4fc9b39 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -13,6 +13,9 @@ #include "romdata.h" #include "system.h" +#define WIN32_LEAN_AND_MEAN 1 +#include + u32 g_OsMemSize = 0; u8 g_Is4Mb = 0; s8 g_Resetting = false; @@ -68,6 +71,10 @@ int main(int argc, const char **argv) sysFatalError("Could not alloc %u bytes for memp heap.", g_MempHeapSize); } + printf("memp heap at %p - %p\n", g_MempHeap, g_MempHeap + g_MempHeapSize); + printf("rom file at %p - %p\n", g_RomFile, g_RomFile + g_RomFileSize); + printf("exe data at %p\n", GetModuleHandleA(NULL)); + mainProc(); return 0; diff --git a/port/src/preprocess.c b/port/src/preprocess.c index 287c0b498..b5e2f7860 100644 --- a/port/src/preprocess.c +++ b/port/src/preprocess.c @@ -15,7 +15,7 @@ #define PD_BEFIELD_PTR(x) x = (void *)PD_BE32((u32)x) #define PD_PTR_BASE(x, b) (void *)((u8 *)b + (u32)x) -#define PD_PTR_BASEOFS(x, b, d) (void *)((u8 *)b + (u32)x - d) +#define PD_PTR_BASEOFS(x, b, d) (void *)((u8 *)b - d + (u32)x) static inline void preprocessALWaveTable(ALWaveTable *tbl, u8 *bankBase) { @@ -128,11 +128,15 @@ static inline void preprocessALBank(ALBank *bank, u8 *bankBase) static inline void preprocessGfx(Gfx *gdl) { while (gdl) { - const u8 opcode = gdl->bytes[0]; + const s8 opcode = (s8)gdl->bytes[0]; PD_BEFIELD_I32(gdl->words.w0); PD_BEFIELD_I32(gdl->words.w1); - if (opcode == G_ENDDL) { + printf("swapped opcode %4d %08x %08x\n", opcode, gdl->words.w0, gdl->words.w1); + fflush(stdout); + if (opcode == (s8)G_ENDDL) { break; + } else if (opcode == (s8)G_DL) { + // preprocessGfx(); } ++gdl; } @@ -149,8 +153,6 @@ static inline void preprocessVtx(Vtx *vtx) static void preprocessModelGunDL(struct modelrodata_gundl *gundl, u8 *base, u32 ofs) { - PD_BEFIELD_PTR(gundl->opagdl); - PD_BEFIELD_PTR(gundl->xlugdl); PD_BEFIELD_PTR(gundl->baseaddr); PD_BEFIELD_PTR(gundl->vertices); PD_BEFIELD_I32(gundl->numvertices); @@ -161,14 +163,18 @@ static void preprocessModelGunDL(struct modelrodata_gundl *gundl, u8 *base, u32 preprocessVtx(vtx); } - preprocessGfx(PD_PTR_BASEOFS(gundl->opagdl, base, ofs)); - preprocessGfx(PD_PTR_BASEOFS(gundl->xlugdl, base, ofs)); + if (gundl->opagdl) { + PD_BEFIELD_PTR(gundl->opagdl); + preprocessGfx(PD_PTR_BASEOFS(gundl->opagdl, base, ofs)); + } + if (gundl->xlugdl) { + PD_BEFIELD_PTR(gundl->xlugdl); + preprocessGfx(PD_PTR_BASEOFS(gundl->xlugdl, base, ofs)); + } } static void preprocessModelDL(struct modelrodata_dl *dl, u8 *base, u32 ofs) { - PD_BEFIELD_PTR(dl->opagdl); - PD_BEFIELD_PTR(dl->xlugdl); PD_BEFIELD_PTR(dl->colours); PD_BEFIELD_PTR(dl->vertices); @@ -182,135 +188,141 @@ static void preprocessModelDL(struct modelrodata_dl *dl, u8 *base, u32 ofs) preprocessVtx(vtx); } - preprocessGfx(PD_PTR_BASEOFS(dl->opagdl, base, ofs)); - preprocessGfx(PD_PTR_BASEOFS(dl->xlugdl, base, ofs)); + if (dl->opagdl) { + PD_BEFIELD_PTR(dl->opagdl); + preprocessGfx(PD_PTR_BASEOFS(dl->opagdl, base, ofs)); + } + if (dl->xlugdl) { + PD_BEFIELD_PTR(dl->xlugdl); + preprocessGfx(PD_PTR_BASEOFS(dl->xlugdl, base, ofs)); + } } static void preprocessModelNode(struct modelnode *node, u8 *base, u32 ofs) { - PD_BEFIELD_I16(node->type); - PD_BEFIELD_PTR(node->child); - PD_BEFIELD_PTR(node->next); - PD_BEFIELD_PTR(node->parent); + while (node) { + PD_BEFIELD_I16(node->type); + PD_BEFIELD_PTR(node->child); + PD_BEFIELD_PTR(node->next); + PD_BEFIELD_PTR(node->parent); + PD_BEFIELD_PTR(node->rodata); - if (!node->rodata) { - return; - } + if (node->rodata) { + union modelrodata* ro = PD_PTR_BASEOFS(node->rodata, base, ofs); - PD_BEFIELD_PTR(node->rodata); - union modelrodata* ro = PD_PTR_BASEOFS(node->rodata, base, ofs); - - switch (node->type & 0xff) { - case MODELNODETYPE_CHRINFO: - PD_BEFIELD_I16(ro->chrinfo.animpart); - PD_BEFIELD_I16(ro->chrinfo.mtxindex); - PD_BEFIELD_I16(ro->chrinfo.rwdataindex); - PD_BEFIELD_F32(ro->chrinfo.unk04); - break; - case MODELNODETYPE_POSITION: - PD_BEFIELD_F32(ro->position.drawdist); - PD_BEFIELD_F32(ro->position.pos.x); - PD_BEFIELD_F32(ro->position.pos.y); - PD_BEFIELD_F32(ro->position.pos.z); - PD_BEFIELD_I16(ro->position.part); - PD_BEFIELD_I16(ro->position.mtxindex0); - PD_BEFIELD_I16(ro->position.mtxindex1); - PD_BEFIELD_I16(ro->position.mtxindex2); - break; - case MODELNODETYPE_GUNDL: - preprocessModelGunDL(&ro->gundl, base, ofs); - break; - case MODELNODETYPE_05: - break; - case MODELNODETYPE_DISTANCE: - PD_BEFIELD_F32(ro->distance.near); - PD_BEFIELD_F32(ro->distance.far); - PD_BEFIELD_I16(ro->distance.rwdataindex); - PD_BEFIELD_PTR(ro->distance.target); - // TODO: assuming target points to one of the nodes we'll swap by following node->next - break; - case MODELNODETYPE_REORDER: - PD_BEFIELD_F32(ro->reorder.unk00); - PD_BEFIELD_F32(ro->reorder.unk04); - PD_BEFIELD_F32(ro->reorder.unk08); - PD_BEFIELD_F32(ro->reorder.unk0c[0]); - PD_BEFIELD_F32(ro->reorder.unk0c[1]); - PD_BEFIELD_F32(ro->reorder.unk0c[2]); - PD_BEFIELD_I16(ro->reorder.rwdataindex); - PD_BEFIELD_I16(ro->reorder.side); - break; - case MODELNODETYPE_BBOX: - PD_BEFIELD_F32(ro->bbox.xmin); - PD_BEFIELD_F32(ro->bbox.xmax); - PD_BEFIELD_F32(ro->bbox.ymin); - PD_BEFIELD_F32(ro->bbox.ymax); - PD_BEFIELD_F32(ro->bbox.zmin); - PD_BEFIELD_F32(ro->bbox.zmax); - PD_BEFIELD_I32(ro->bbox.hitpart); - break; - case MODELNODETYPE_0B: - PD_BEFIELD_PTR(ro->type0b.baseaddr); - PD_BEFIELD_I16(ro->type0b.rwdataindex); - PD_BEFIELD_I32(ro->type0b.unk00); - PD_BEFIELD_PTR(ro->type0b.unk3c); - // TODO: do we need to swap the rest of the words? - break; - case MODELNODETYPE_CHRGUNFIRE: - PD_BEFIELD_PTR(ro->chrgunfire.baseaddr); - PD_BEFIELD_PTR(ro->chrgunfire.texture); - PD_BEFIELD_I16(ro->chrgunfire.rwdataindex); - PD_BEFIELD_F32(ro->chrgunfire.pos.x); - PD_BEFIELD_F32(ro->chrgunfire.pos.y); - PD_BEFIELD_F32(ro->chrgunfire.pos.z); - PD_BEFIELD_F32(ro->chrgunfire.dim.x); - PD_BEFIELD_F32(ro->chrgunfire.dim.y); - PD_BEFIELD_F32(ro->chrgunfire.dim.z); - PD_BEFIELD_F32(ro->chrgunfire.unk1c); - // TODO: do we swap contents of *texture or is it part of mdl->textureconfigs[]? - break; - case MODELNODETYPE_0D: - PD_BEFIELD_PTR(ro->type0d.baseaddr); - PD_BEFIELD_PTR(ro->type0d.unk10); - PD_BEFIELD_PTR(ro->type0d.unk14); - // TODO: do we need to swap the rest of the words? - break; - case MODELNODETYPE_0E: - case MODELNODETYPE_0F: - break; - case MODELNODETYPE_11: - PD_BEFIELD_PTR(ro->type11.unk14); - // TODO: do we need to swap the rest of the words? - break; - case MODELNODETYPE_TOGGLE: - PD_BEFIELD_I16(ro->toggle.rwdataindex); - PD_BEFIELD_PTR(ro->toggle.target); - // TODO: assuming target points to one of the nodes we'll swap by following node->next - break; - case MODELNODETYPE_DL: - preprocessModelDL(&ro->dl, base, ofs); - break; - case 0x19: - PD_BEFIELD_I32(ro->type19.numvertices); - for (s32 i = 0; i < ARRAYCOUNT(ro->type19.vertices); ++i) { - PD_BEFIELD_F32(ro->type19.vertices[i].x); - PD_BEFIELD_F32(ro->type19.vertices[i].y); - PD_BEFIELD_F32(ro->type19.vertices[i].z); + switch (node->type & 0xff) { + case MODELNODETYPE_CHRINFO: + PD_BEFIELD_I16(ro->chrinfo.animpart); + PD_BEFIELD_I16(ro->chrinfo.mtxindex); + PD_BEFIELD_I16(ro->chrinfo.rwdataindex); + PD_BEFIELD_F32(ro->chrinfo.unk04); + break; + case MODELNODETYPE_POSITION: + PD_BEFIELD_F32(ro->position.drawdist); + PD_BEFIELD_F32(ro->position.pos.x); + PD_BEFIELD_F32(ro->position.pos.y); + PD_BEFIELD_F32(ro->position.pos.z); + PD_BEFIELD_I16(ro->position.part); + PD_BEFIELD_I16(ro->position.mtxindex0); + PD_BEFIELD_I16(ro->position.mtxindex1); + PD_BEFIELD_I16(ro->position.mtxindex2); + break; + case MODELNODETYPE_GUNDL: + preprocessModelGunDL(&ro->gundl, base, ofs); + break; + case MODELNODETYPE_05: + break; + case MODELNODETYPE_DISTANCE: + PD_BEFIELD_F32(ro->distance.near); + PD_BEFIELD_F32(ro->distance.far); + PD_BEFIELD_I16(ro->distance.rwdataindex); + PD_BEFIELD_PTR(ro->distance.target); + // TODO: assuming target points to one of the nodes we'll swap by following node->next + break; + case MODELNODETYPE_REORDER: + PD_BEFIELD_F32(ro->reorder.unk00); + PD_BEFIELD_F32(ro->reorder.unk04); + PD_BEFIELD_F32(ro->reorder.unk08); + PD_BEFIELD_F32(ro->reorder.unk0c[0]); + PD_BEFIELD_F32(ro->reorder.unk0c[1]); + PD_BEFIELD_F32(ro->reorder.unk0c[2]); + PD_BEFIELD_I16(ro->reorder.rwdataindex); + PD_BEFIELD_I16(ro->reorder.side); + break; + case MODELNODETYPE_BBOX: + PD_BEFIELD_F32(ro->bbox.xmin); + PD_BEFIELD_F32(ro->bbox.xmax); + PD_BEFIELD_F32(ro->bbox.ymin); + PD_BEFIELD_F32(ro->bbox.ymax); + PD_BEFIELD_F32(ro->bbox.zmin); + PD_BEFIELD_F32(ro->bbox.zmax); + PD_BEFIELD_I32(ro->bbox.hitpart); + break; + case MODELNODETYPE_0B: + PD_BEFIELD_PTR(ro->type0b.baseaddr); + PD_BEFIELD_I16(ro->type0b.rwdataindex); + PD_BEFIELD_I32(ro->type0b.unk00); + PD_BEFIELD_PTR(ro->type0b.unk3c); + // TODO: do we need to swap the rest of the words? + break; + case MODELNODETYPE_CHRGUNFIRE: + PD_BEFIELD_PTR(ro->chrgunfire.baseaddr); + PD_BEFIELD_PTR(ro->chrgunfire.texture); + PD_BEFIELD_I16(ro->chrgunfire.rwdataindex); + PD_BEFIELD_F32(ro->chrgunfire.pos.x); + PD_BEFIELD_F32(ro->chrgunfire.pos.y); + PD_BEFIELD_F32(ro->chrgunfire.pos.z); + PD_BEFIELD_F32(ro->chrgunfire.dim.x); + PD_BEFIELD_F32(ro->chrgunfire.dim.y); + PD_BEFIELD_F32(ro->chrgunfire.dim.z); + PD_BEFIELD_F32(ro->chrgunfire.unk1c); + // TODO: do we swap contents of *texture or is it part of mdl->textureconfigs[]? + break; + case MODELNODETYPE_0D: + PD_BEFIELD_PTR(ro->type0d.baseaddr); + PD_BEFIELD_PTR(ro->type0d.unk10); + PD_BEFIELD_PTR(ro->type0d.unk14); + // TODO: do we need to swap the rest of the words? + break; + case MODELNODETYPE_0E: + case MODELNODETYPE_0F: + break; + case MODELNODETYPE_11: + PD_BEFIELD_PTR(ro->type11.unk14); + // TODO: do we need to swap the rest of the words? + break; + case MODELNODETYPE_TOGGLE: + PD_BEFIELD_I16(ro->toggle.rwdataindex); + PD_BEFIELD_PTR(ro->toggle.target); + // TODO: assuming target points to one of the nodes we'll swap by following node->next + break; + case MODELNODETYPE_DL: + preprocessModelDL(&ro->dl, base, ofs); + break; + case 0x19: + PD_BEFIELD_I32(ro->type19.numvertices); + for (s32 i = 0; i < ARRAYCOUNT(ro->type19.vertices); ++i) { + PD_BEFIELD_F32(ro->type19.vertices[i].x); + PD_BEFIELD_F32(ro->type19.vertices[i].y); + PD_BEFIELD_F32(ro->type19.vertices[i].z); + } + break; + default: + fprintf(stderr, "preprocessModelNode: node at %p: unknown node->type: 0x%02x\n", node, node->type & 0xff); + break; } - break; - default: - fprintf(stderr, "preprocessModelNode: node at %p: unknown node->type: 0x%02x\n", node, node->type & 0xff); - break; - } + } - if (node->child) { - node = PD_PTR_BASEOFS(node->child, base, ofs); - } else { - while (node) { - if (node->next) { - node = PD_PTR_BASEOFS(node->next, base, ofs); - break; + if (node->child) { + node = PD_PTR_BASEOFS(node->child, base, ofs); + } else { + while (node) { + if (node->next) { + node = PD_PTR_BASEOFS(node->next, base, ofs); + break; + } + node = node->parent ? PD_PTR_BASEOFS(node->parent, base, ofs) : NULL; } - node = PD_PTR_BASEOFS(node->parent, base, ofs); } } } @@ -700,7 +712,7 @@ void preprocessSetupFile(u8 *data, u32 size) void preprocessModelFile(u8 *data, u32 size) { - preprocessModel(data, size); + preprocessModel(data, 0x5000000); } void preprocessGunFile(u8 *data, u32 size) diff --git a/port/src/video.c b/port/src/video.c index 16570a305..c2a3525e7 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -4,9 +4,9 @@ #include #include -#include "../n64-fast3d-engine/gfx_pc.h" -#include "../n64-fast3d-engine/gfx_sdl2.h" -#include "../n64-fast3d-engine/gfx_opengl.h" +#include "../fast3d/gfx_pc.h" +#include "../fast3d/gfx_sdl2.h" +#include "../fast3d/gfx_opengl.h" static struct GfxWindowManagerAPI *wmAPI; static struct GfxRenderingAPI *renderingAPI; diff --git a/src/game/bg.c b/src/game/bg.c index 4835c75a2..37b889939 100644 --- a/src/game/bg.c +++ b/src/game/bg.c @@ -708,8 +708,8 @@ Gfx *bgRenderGdlInXray(Gfx *gdl, s8 *readgdl, Vtx *vertices, s16 arg3[3]) // empty } else if (readgdl[0] == G_VTX) { Gfx *cmd = (Gfx *) readgdl; - s32 dmemindex = cmd->bytes[1] & 0xf; - s32 numvertices = ((u32) cmd->bytes[1] >> 4) + 1; + s32 dmemindex = cmd->bytes[GFX_W0_BYTE(1)] & 0xf; + s32 numvertices = ((u32) cmd->bytes[GFX_W0_BYTE(1)] >> 4) + 1; u32 offset = cmd->words.w1 & 0xffffff; for (i = 0; i < numvertices; i++) { @@ -3608,9 +3608,9 @@ bool bgTestHitOnObj(struct coord *arg0, struct coord *arg1, struct coord *arg2, break; } else if (gdl->dma.cmd == G_VTX) { ptr = var800a6470; - count = gdl->bytes[1] & 0xf; + count = gdl->bytes[GFX_W0_BYTE(1)] & 0xf; offset = (gdl->words.w1 & 0xffffff); - numvertices = (((u32)gdl->bytes[1] >> 4) & 0xf) + 1; + numvertices = (((u32) gdl->bytes[GFX_W0_BYTE(1)] >> 4) & 0xf) + 1; vtx = (Vtx *)((uintptr_t)vertices + offset); vtx -= count; @@ -3909,9 +3909,9 @@ bool bgTestHitOnChr(struct model *model, struct coord *arg1, struct coord *arg2, i = word / sizeof(Mtxf); mtx = &model->matrices[i]; } else if (gdl->dma.cmd == G_VTX) { - count = (gdl->bytes[1] & 0xf); + count = (gdl->bytes[GFX_W0_BYTE(1)] & 0xf); word = gdl->words.w1 & 0xffffff; - numvertices = ((u32)gdl->bytes[1] >> 4) + 1; + numvertices = ((u32) gdl->bytes[GFX_W0_BYTE(1)] >> 4) + 1; vtx = (Vtx *)((uintptr_t)vertices + word); if (count < spdc) { @@ -4172,7 +4172,7 @@ bool bgTestHitInVtxBatch(struct coord *arg0, struct coord *arg1, struct coord *a vtx = bgFindVerticesForGdl(roomnum, gdl); iter = &gdl[batch->gbicmdindex]; vtx = (Vtx *)((iter->words.w1 & 0xffffff) + (s32)vtx); - numvertices = (((u32)iter->bytes[1] >> 4) & 0xf) + 1; + numvertices = (((u32) iter->bytes[GFX_W0_BYTE(1)] >> 4) & 0xf) + 1; ptr = var800a6470; while (numvertices > 0) { @@ -4302,7 +4302,7 @@ bool bgTestHitInVtxBatch(struct coord *arg0, struct coord *arg1, struct coord *a tmpgdl = iter; - while (tmpgdl->bytes[0] != G_SETTIMG && tmpgdl > gdl) { + while (tmpgdl->bytes[GFX_W0_BYTE(0)] != G_SETTIMG && tmpgdl > gdl) { tmpgdl--; } diff --git a/src/game/file.c b/src/game/file.c index 2760f6d14..6bad0b536 100644 --- a/src/game/file.c +++ b/src/game/file.c @@ -4210,6 +4210,7 @@ void fileLoad(u8 *dst, u32 allocationlen, romptr_t *romaddrptr, struct fileinfo // byteswap/preprocess file according to g_LoadType right after inflating it const u32 dstsize = allocationlen ? info->loadedsize : romsize; romdataFilePreprocess(filenum, g_LoadType, dst, dstsize); + g_LoadType = LOADTYPE_NONE; #endif } diff --git a/src/game/filemgr.c b/src/game/filemgr.c index 43566b180..ef3cf8d67 100644 --- a/src/game/filemgr.c +++ b/src/game/filemgr.c @@ -295,7 +295,7 @@ char *filemgrMenuTextFailReason(struct menuitem *item) L_OPTIONS_330, // "Game note delete failed." }; - return langGet(reasons[g_Menus[g_MpPlayerNum].fm.errno]); + return langGet(reasons[g_Menus[g_MpPlayerNum].fm.errnum]); } /** @@ -314,7 +314,7 @@ MenuItemHandlerResult filemgrDeviceNameForErrorMenuHandler(s32 operation, struct return true; } - switch (g_Menus[g_MpPlayerNum].fm.errno) { + switch (g_Menus[g_MpPlayerNum].fm.errnum) { case FILEERROR_OUTOFMEMORY: case FILEERROR_ALREADYLOADED: case FILEERROR_PAKDAMAGED: @@ -336,7 +336,7 @@ char *filemgrMenuTextDeviceNameForError(struct menuitem *item) { sprintf(g_StringPointer, "%s", filemgrGetDeviceName(g_Menus[g_MpPlayerNum].fm.device1 & 0x7f)); - if (g_Menus[g_MpPlayerNum].fm.errno != FILEERROR_PAKREMOVED) { + if (g_Menus[g_MpPlayerNum].fm.errnum != FILEERROR_PAKREMOVED) { s32 i = 0; while (g_StringPointer[i] != '\0') { @@ -363,9 +363,9 @@ const char var7f1b3024[] = "MyResult: %d\n"; const char var7f1b3034[] = "PakOperationSearch>> Search for pak: %x = %d\n"; #endif -void filemgrPushErrorDialog(u16 errno) +void filemgrPushErrorDialog(u16 errnum) { - g_Menus[g_MpPlayerNum].fm.errno = errno; + g_Menus[g_MpPlayerNum].fm.errnum = errnum; menuPushDialog(&g_FilemgrErrorMenuDialog); } @@ -788,7 +788,7 @@ void filemgrRetrySave(s32 context) bool filemgrAttemptOperation(s32 device, bool closeonsuccess) { - s32 errno = 0; + s32 errnum = 0; bool showfilesaved = (g_Menus[g_MpPlayerNum].fm.isretryingsave & 1) != 0; const s32 filetypes[] = { @@ -806,18 +806,18 @@ bool filemgrAttemptOperation(s32 device, bool closeonsuccess) // fall through case FILEOP_SAVE_GAME_000: case FILEOP_SAVE_GAME_001: - errno = gamefileSave(device, + errnum = gamefileSave(device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.deviceserial); break; case FILEOP_SAVE_MPPLAYER: - errno = mpplayerfileSave( + errnum = mpplayerfileSave( (s32) g_Menus[g_MpPlayerNum].fm.unke44, device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.deviceserial); break; case FILEOP_SAVE_MPSETUP: - errno = mpsetupfileSave(device, + errnum = mpsetupfileSave(device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.deviceserial); showfilesaved = true; @@ -829,24 +829,24 @@ bool filemgrAttemptOperation(s32 device, bool closeonsuccess) #if VERSION >= VERSION_NTSC_1_0 func0f0d5690(g_Menus[g_MpPlayerNum].fm.unke44, g_Menus[g_MpPlayerNum].fm.filename); #endif - errno = pakSaveAtGuid(device, + errnum = pakSaveAtGuid(device, g_Menus[g_MpPlayerNum].fm.fileid, filetypes[g_Menus[g_MpPlayerNum].fm.fileop - 6], g_Menus[g_MpPlayerNum].fm.unke44, &newfileid, NULL); var80075bd0[g_Menus[g_MpPlayerNum].fm.fileop - 6] = 1; break; case FILEOP_LOAD_GAME: - errno = gamefileLoad(device); + errnum = gamefileLoad(device); break; case FILEOP_LOAD_MPPLAYER: - errno = mpplayerfileLoad( + errnum = mpplayerfileLoad( (s32) g_Menus[g_MpPlayerNum].fm.unke44, device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.deviceserial); break; case FILEOP_LOAD_MPSETUP: - errno = mpsetupfileLoad(device, + errnum = mpsetupfileLoad(device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.deviceserial); break; @@ -854,35 +854,35 @@ bool filemgrAttemptOperation(s32 device, bool closeonsuccess) case FILEOP_READ_MPSETUP: case FILEOP_READ_MPPLAYER: #if VERSION >= VERSION_NTSC_1_0 - errno = pakReadBodyAtGuid(device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.unke44, 0); + errnum = pakReadBodyAtGuid(device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.unke44, 0); #else - errno = pakReadBodyAtGuid(device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.unke44, + errnum = pakReadBodyAtGuid(device, g_Menus[g_MpPlayerNum].fm.fileid, g_Menus[g_MpPlayerNum].fm.unke44, g_FileTypeSizes[g_Menus[g_MpPlayerNum].fm.fileop - FILEOP_READ_GAME]); #endif break; } - if (errno == 0 && closeonsuccess) { + if (errnum == 0 && closeonsuccess) { menuCloseDialog(); } if (FILEOP_IS_SAVE(g_Menus[g_MpPlayerNum].fm.fileop)) { - if (errno == 0) { + if (errnum == 0) { filemgrHandleSuccess(); } - if (showfilesaved && errno == 0) { + if (showfilesaved && errnum == 0) { menuPushDialog(&g_FilemgrFileSavedMenuDialog); } } else { - if (errno == 0) { + if (errnum == 0) { filemgrHandleSuccess(); } } menuUpdateCurFrame(); - return errno; + return errnum; } #if VERSION >= VERSION_NTSC_1_0 diff --git a/src/game/game_1531a0.c b/src/game/game_1531a0.c index 7f302a5d6..e49899762 100644 --- a/src/game/game_1531a0.c +++ b/src/game/game_1531a0.c @@ -13,6 +13,7 @@ #include "lib/memp.h" #include "data.h" #include "types.h" +#include "platform.h" #define SPACE_WIDTH 5 @@ -111,38 +112,38 @@ u32 var8007fb34 = 0x00000000; u32 var8007fb38 = 0x00000000; u16 var8007fb3c[] = { - 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, - 0xff00, 0xff24, 0xff48, 0xff6c, 0xff90, 0xffb4, 0xffd8, 0xffff, + PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), + PD_BE16(0xff00), PD_BE16(0xff24), PD_BE16(0xff48), PD_BE16(0xff6c), PD_BE16(0xff90), PD_BE16(0xffb4), PD_BE16(0xffd8), PD_BE16(0xffff), }; u16 var8007fb5c[] = { - 0xff00, 0xff58, 0xff74, 0xff90, 0xffac, 0xffc8, 0xffe4, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + PD_BE16(0xff00), PD_BE16(0xff58), PD_BE16(0xff74), PD_BE16(0xff90), PD_BE16(0xffac), PD_BE16(0xffc8), PD_BE16(0xffe4), PD_BE16(0xffff), + PD_BE16(0xffff), PD_BE16(0xffff), PD_BE16(0xffff), PD_BE16(0xffff), PD_BE16(0xffff), PD_BE16(0xffff), PD_BE16(0xffff), PD_BE16(0xffff), }; u16 var8007fb7c[] = { - 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, - 0xff00, 0xff18, 0xff30, 0xff5c, 0xff88, 0xffb4, 0xffd8, 0xffff, + PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), PD_BE16(0xff00), + PD_BE16(0xff00), PD_BE16(0xff18), PD_BE16(0xff30), PD_BE16(0xff5c), PD_BE16(0xff88), PD_BE16(0xffb4), PD_BE16(0xffd8), PD_BE16(0xffff), }; #if VERSION == VERSION_JPN_FINAL u16 var800801d8jf[] = { - 0xff00, - 0xff11, - 0xff22, - 0xff33, - 0xff44, - 0xff55, - 0xff66, - 0xff77, - 0xff88, - 0xff99, - 0xffaa, - 0xffbb, - 0xffcc, - 0xffdd, - 0xffee, - 0xffff, + PD_BE16(0xff00), + PD_BE16(0xff11), + PD_BE16(0xff22), + PD_BE16(0xff33), + PD_BE16(0xff44), + PD_BE16(0xff55), + PD_BE16(0xff66), + PD_BE16(0xff77), + PD_BE16(0xff88), + PD_BE16(0xff99), + PD_BE16(0xffaa), + PD_BE16(0xffbb), + PD_BE16(0xffcc), + PD_BE16(0xffdd), + PD_BE16(0xffee), + PD_BE16(0xffff), }; #endif diff --git a/src/game/pak.c b/src/game/pak.c index 0361f980d..a274012f5 100644 --- a/src/game/pak.c +++ b/src/game/pak.c @@ -1406,7 +1406,7 @@ s32 _pakCreateCameraFile(s8 device, s32 *outfileid) bool pakResizeNote(s8 device, s32 numpages) { s32 stack1[2]; - s32 errno; + s32 errnum; struct pak *devicedata; s32 stack2[2]; OSPfsState *note; @@ -1416,10 +1416,10 @@ bool pakResizeNote(s8 device, s32 numpages) pakQueryNumFreePages(device); numbytes = numpages * 256; - errno = _pakResizeNote(PFS(device), ROM_COMPANYCODE, ROM_GAMECODE, g_PakNoteGameName, g_PakNoteExtName, numbytes); - pakHandleResult(errno, device, true, LINE_1802); + errnum = _pakResizeNote(PFS(device), ROM_COMPANYCODE, ROM_GAMECODE, g_PakNoteGameName, g_PakNoteExtName, numbytes); + pakHandleResult(errnum, device, true, LINE_1802); - if (errno == PAK_ERR1_OK) { + if (errnum == PAK_ERR1_OK) { devicedata = &g_Paks[device]; note = &devicedata->pakdata.notes[devicedata->pdnoteindex]; diff --git a/src/game/tex.c b/src/game/tex.c index 9b3a30403..3fd12b9b1 100644 --- a/src/game/tex.c +++ b/src/game/tex.c @@ -978,7 +978,7 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo Vtx *vtx; if (spe0) { - start = s5->bytes[1] & 0xf; + start = s5->bytes[GFX_W0_BYTE(1)] & 0xf; count = s5->vtx.unk08 + 1; vtx = (Vtx *)(s5->dma.addr & 0x00ffffff); diff --git a/src/game/texdecompress.c b/src/game/texdecompress.c index 055d52e21..96c6fe2f1 100644 --- a/src/game/texdecompress.c +++ b/src/game/texdecompress.c @@ -1909,6 +1909,7 @@ s32 texInflateLookupFromBuffer(u8 *src, s32 width, s32 height, u8 *dst, u8 *look */ void texSwapAltRowBytes(u8 *dst, s32 width, s32 height, s32 format) { +#ifdef PLATFORM_N64 // I'm assuming this is required on N64 because the GPU reads them in words s32 x; s32 y; s32 alignedwidth; @@ -1966,6 +1967,7 @@ void texSwapAltRowBytes(u8 *dst, s32 width, s32 height, s32 format) row += alignedwidth * 2; } } +#endif } /** @@ -2074,10 +2076,10 @@ void texLoadFromDisplayList(Gfx *gdl, struct texpool *pool, s32 arg2) { u8 *bytes = (u8 *)gdl; - while (bytes[0] != (u8)G_ENDDL) { + while (bytes[GFX_W0_BYTE(0)] != (u8)G_ENDDL) { // Look for GBI sequence: fd...... abcd.... - if (bytes[0] == G_SETTIMG && bytes[4] == 0xab && bytes[5] == 0xcd) { - texLoad((s32 *)((s32)bytes + 4), pool, arg2); + if (bytes[GFX_W0_BYTE(0)] == G_SETTIMG && bytes[GFX_W1_BYTE(0)] == 0xab && bytes[GFX_W1_BYTE(1)] == 0xcd) { + texLoad((s32 *)((uintptr_t)bytes + 4), pool, arg2); } bytes += 8; diff --git a/src/include/game/filemgr.h b/src/include/game/filemgr.h index d1f56f76b..c0f63bad8 100644 --- a/src/include/game/filemgr.h +++ b/src/include/game/filemgr.h @@ -15,7 +15,7 @@ void filemgrSetDevice1ByFile(struct filelistfile *file); void filemgrSetFileToDelete(struct filelistfile *file, s32 filetype); char *filemgrMenuTextFailReason(struct menuitem *item); char *filemgrMenuTextDeviceNameForError(struct menuitem *item); -void filemgrPushErrorDialog(u16 errno); +void filemgrPushErrorDialog(u16 errnum); s32 filemgrGetDeviceNameOrStartIndex(s32 listnum, s32 operation, s32 optionindex); char *filemgrMenuTextErrorTitle(struct menuitem *item); char *filemgrMenuTextFileType(struct menuitem *item); diff --git a/src/include/math.h b/src/include/math.h index 2eaf5462f..eb49a0c08 100644 --- a/src/include/math.h +++ b/src/include/math.h @@ -5,7 +5,6 @@ #include_next #undef M_PI #undef M_TAU -#undef errno // fuck off #endif // @bug? diff --git a/src/include/stdlib.h b/src/include/stdlib.h index 2a00a8212..92186fa5b 100755 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -4,7 +4,6 @@ #ifndef PLATFORM_N64 #include_next -#undef errno // fuck off #else // PLATFORM_N64 diff --git a/src/include/string.h b/src/include/string.h index ed13c9352..c017dd372 100755 --- a/src/include/string.h +++ b/src/include/string.h @@ -59,7 +59,6 @@ extern size_t strlen(const char *); #else #include_next -#undef errno // fuck off #endif diff --git a/src/include/types.h b/src/include/types.h index cea8ef6f3..401941a4f 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -18,7 +18,6 @@ #define romptr_t u32 #else #include -#undef errno // fuck off #define romptr_t uintptr_t #endif @@ -3765,7 +3764,7 @@ struct menudata_filemgr { }; /*0xe2c*/ s32 unke2c; /*0xe30*/ u32 unke30; - /*0xe34*/ u16 errno; + /*0xe34*/ u16 errnum; /*0xe38*/ struct filelistfile *filetodelete; /*0xe3c*/ u8 device1; /*0xe3d*/ u8 filetypetodelete; diff --git a/src/lib/dma.c b/src/lib/dma.c index bfc5ef4a7..e3701a677 100644 --- a/src/lib/dma.c +++ b/src/lib/dma.c @@ -117,8 +117,9 @@ void dmaCheckPiracy(void *memaddr, u32 len) ptr[i] ^= data; } #endif - +#ifdef PLATFORM_N64 // we're actually using g_LoadType for something on pc, the value gets reset later g_LoadType = LOADTYPE_NONE; +#endif } } #endif diff --git a/src/lib/joy.c b/src/lib/joy.c index ae8650210..64e7b969f 100644 --- a/src/lib/joy.c +++ b/src/lib/joy.c @@ -322,7 +322,7 @@ void joyInit(void) g_JoyData[i].samples[0].pads[j].button = 0; g_JoyData[i].samples[0].pads[j].stick_x = 0; g_JoyData[i].samples[0].pads[j].stick_y = 0; - g_JoyData[i].samples[0].pads[j].errno = 0; + g_JoyData[i].samples[0].pads[j].errnum = 0; } } @@ -390,7 +390,7 @@ void joy00013e84(void) osContGetQuery(g_JoyContStatuses); for (i = 0; i < ARRAYCOUNT(g_JoyContStatuses); i++) { - if (g_JoyContStatuses[i].errno & CONT_NO_RESPONSE_ERROR) { + if (g_JoyContStatuses[i].errnum & CONT_NO_RESPONSE_ERROR) { slots -= 1 << i; } } @@ -639,8 +639,8 @@ void joysHandleRetrace(void) // Check if error state has changed for any controller for (i = 0; i < NUM_PADS; i++) { - if ((g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errno == 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errno != 0) - || (g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errno != 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errno == 0)) { + if ((g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errnum == 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errnum != 0) + || (g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errnum != 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errnum == 0)) { joy00013e84(); break; } @@ -691,8 +691,8 @@ void joysHandleRetrace(void) // Check if error state has changed for any controller for (i = 0; i < NUM_PADS; i++) { - if ((g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errno == 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errno != 0) - || (g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errno != 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errno == 0)) { + if ((g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errnum == 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errnum != 0) + || (g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errnum != 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errnum == 0)) { joy00013e84(); break; } diff --git a/src/lib/rzip_c.c b/src/lib/rzip_c.c index 925b5c950..4b2f1c65a 100644 --- a/src/lib/rzip_c.c +++ b/src/lib/rzip_c.c @@ -3,9 +3,6 @@ #include -// OSContPad has a field called errno because fuck you -#undef errno - #include "lib/rzip.h" void *var80091558; // g_RzipUnused diff --git a/src/lib/ultra/io/conteepwrite.c b/src/lib/ultra/io/conteepwrite.c index 45e8da79b..2b355f5c5 100644 --- a/src/lib/ultra/io/conteepwrite.c +++ b/src/lib/ultra/io/conteepwrite.c @@ -145,12 +145,12 @@ s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data) } requestformat = *(__OSContRequestFormat *)ptr; - data->errno = CHNL_ERR(requestformat); + data->errnum = CHNL_ERR(requestformat); data->type = (requestformat.typel << 8) | requestformat.typeh; data->status = requestformat.status; - if (data->errno != 0) { - return data->errno; + if (data->errnum != 0) { + return data->errnum; } return 0; diff --git a/src/lib/ultra/io/contreaddata.c b/src/lib/ultra/io/contreaddata.c index 10d414d28..b9c9674ef 100644 --- a/src/lib/ultra/io/contreaddata.c +++ b/src/lib/ultra/io/contreaddata.c @@ -35,9 +35,9 @@ void osContGetReadData(OSContPad *data) for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContReadFormat), data++) { readformat = *(__OSContReadFormat *)ptr; - data->errno = CHNL_ERR(readformat); + data->errnum = CHNL_ERR(readformat); - if (data->errno == 0) { + if (data->errnum == 0) { data->button = readformat.button; data->stick_x = readformat.stick_x; data->stick_y = readformat.stick_y; diff --git a/src/lib/ultra/io/controller.c b/src/lib/ultra/io/controller.c index 157d6edbf..ff39603f6 100644 --- a/src/lib/ultra/io/controller.c +++ b/src/lib/ultra/io/controller.c @@ -69,9 +69,9 @@ void __osContGetInitData(u8 *pattern, OSContStatus *data) for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContRequestFormat), data++) { requestformat = *(__OSContRequestFormat *)ptr; - data->errno = CHNL_ERR(requestformat); + data->errnum = CHNL_ERR(requestformat); - if (data->errno == 0) { + if (data->errnum == 0) { data->type = (requestformat.typel << 8) | requestformat.typeh; data->status = requestformat.status; bits |= 1 << i; diff --git a/src/lib/ultra/io/pfsgetstatus.c b/src/lib/ultra/io/pfsgetstatus.c index 66aad1d85..b68ed4ed7 100644 --- a/src/lib/ultra/io/pfsgetstatus.c +++ b/src/lib/ultra/io/pfsgetstatus.c @@ -27,7 +27,7 @@ s32 __osPfsGetStatus(OSMesgQueue *queue, int channel) return PFS_ERR_NEW_PACK; } - if (data.errno != 0 || (data.status & CONT_CARD_ON) == 0) { + if (data.errnum != 0 || (data.status & CONT_CARD_ON) == 0) { return PFS_ERR_NOPACK; } @@ -77,9 +77,9 @@ void __osPfsGetOneChannelData(int channel, OSContStatus *data) } requestformat = *(__OSContRequestFormatShort *)ptr; - data->errno = CHNL_ERR(requestformat); + data->errnum = CHNL_ERR(requestformat); - if (data->errno == 0) { + if (data->errnum == 0) { data->type = (requestformat.typel << 8) | (requestformat.typeh); data->status = requestformat.status; } diff --git a/src/lib/ultra/io/pfsisplug.c b/src/lib/ultra/io/pfsisplug.c index 70de3dcac..3418cacda 100644 --- a/src/lib/ultra/io/pfsisplug.c +++ b/src/lib/ultra/io/pfsisplug.c @@ -50,7 +50,7 @@ s32 osPfsIsPlug(OSMesgQueue *queue, u8 *pattern) if (crc_error_cnt < 1) { for (channel = 0; channel < __osMaxControllers; channel++) { - if (data[channel].errno == 0 && (data[channel].status & CONT_CARD_ON) != 0) { + if (data[channel].errnum == 0 && (data[channel].status & CONT_CARD_ON) != 0) { bits |= 1 << channel; } } @@ -99,9 +99,9 @@ void __osPfsGetInitData(u8 *pattern, OSContStatus *data) for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContRequestFormat)) { requestformat = *(__OSContRequestFormat *)ptr; - data->errno = CHNL_ERR(requestformat); + data->errnum = CHNL_ERR(requestformat); - if (data->errno == 0) { + if (data->errnum == 0) { data->type = (requestformat.typel << 8) | (requestformat.typeh); data->status = requestformat.status; bits |= 1 << i;