diff --git a/src/graphic/Fast3D/gfx_gx2.cpp b/src/graphic/Fast3D/gfx_gx2.cpp index ce5b2f61a..f87985820 100644 --- a/src/graphic/Fast3D/gfx_gx2.cpp +++ b/src/graphic/Fast3D/gfx_gx2.cpp @@ -16,7 +16,6 @@ #ifndef _LANGUAGE_C #define _LANGUAGE_C #endif -#include "libultraship/libultra/gbi.h" #include #include "gfx_cc.h" diff --git a/src/graphic/Fast3D/gfx_metal.cpp b/src/graphic/Fast3D/gfx_metal.cpp index 4c1a287f6..75870ef2e 100644 --- a/src/graphic/Fast3D/gfx_metal.cpp +++ b/src/graphic/Fast3D/gfx_metal.cpp @@ -36,7 +36,6 @@ #include "gfx_pc.h" #include "gfx_metal_shader.h" -#include "libultraship/libultra/gbi.h" #include "libultraship/libultra/abi.h" #include "public/bridge/consolevariablebridge.h" diff --git a/src/graphic/Fast3D/gfx_pc.cpp b/src/graphic/Fast3D/gfx_pc.cpp index 519ec4679..be1a4013e 100644 --- a/src/graphic/Fast3D/gfx_pc.cpp +++ b/src/graphic/Fast3D/gfx_pc.cpp @@ -20,8 +20,7 @@ #endif #include "debug/GfxDebugger.h" #include "libultraship/libultra/types.h" - -#include "libultraship/libultra/gs2dex.h" +//#include "libultraship/libultra/gs2dex.h" #include #include "gfx_pc.h" @@ -2443,7 +2442,7 @@ static void gfx_dp_set_other_mode(uint32_t h, uint32_t l) { g_rdp.other_mode_l = l; } -static void gfx_s2dex_bg_copy(uObjBg* bg) { +static void gfx_s2dex_bg_copy(F3DuObjBg* bg) { /* bg->b.imageX = 0; bg->b.imageW = width * 4; @@ -2497,7 +2496,7 @@ static void gfx_s2dex_bg_copy(uObjBg* bg) { false); } -static void gfx_s2dex_bg_1cyc(uObjBg* bg) { +static void gfx_s2dex_bg_1cyc(F3DuObjBg* bg) { uintptr_t data = (uintptr_t)bg->b.imagePtr; uint32_t texFlags = 0; @@ -2540,7 +2539,7 @@ static void gfx_s2dex_bg_1cyc(uObjBg* bg) { bg->b.imageY << 3, dsdxRect, 1 << 10, false); } -static void gfx_s2dex_rect_copy(uObjSprite* spr) { +static void gfx_s2dex_rect_copy(F3DuObjSprite* spr) { s16 dsdx = 4 << 10; s16 uls = spr->s.objX << 3; // Flip flag only flips horizontally @@ -2665,7 +2664,7 @@ bool gfx_cull_dl_handler_f3dex2(F3DGfx** cmd) { return false; } -bool gfx_marker_handler_f3dex2(F3DGfx** cmd0) { +bool gfx_marker_handler_otr(F3DGfx** cmd0) { (*cmd0)++; F3DGfx* cmd = (*cmd0); const uint64_t hash = ((uint64_t)(cmd)->words.w0 << 32) + (cmd)->words.w1; @@ -2936,7 +2935,7 @@ bool gfx_modify_vtx_handler_f3dex2(F3DGfx** cmd0) { return false; } -// F3D, F3DEX, and F3DEX2 do the same thing +// F3D, F3DEX, and F3DEX2 do the same thing but F3DEX2 has its own opcode number bool gfx_dl_handler_common(F3DGfx** cmd0) { F3DGfx* cmd = *cmd0; F3DGfx* subGFX = (F3DGfx*)seg_addr(cmd->words.w1); @@ -2997,7 +2996,7 @@ bool gfx_dl_index_handler(F3DGfx** cmd0) { } // TODO handle special OTR opcodes later... -bool gfx_pushcd_handler_f3dex2(F3DGfx** cmd0) { +bool gfx_pushcd_handler_custom(F3DGfx** cmd0) { gfx_push_current_dir((char*)(*cmd0)->words.w1); return false; } @@ -3024,7 +3023,7 @@ bool gfx_branch_z_otr_handler_f3dex2(F3DGfx** cmd0) { return false; } -// F3D, F3DEX, and F3DEX2 do the same thing +// F3D, F3DEX, and F3DEX2 do the same thing but F3DEX2 has its own opcode number bool gfx_end_dl_handler_common(F3DGfx** cmd0) { markerOn = false; *cmd0 = g_exec_stack.ret(); @@ -3044,14 +3043,14 @@ bool gfx_geometry_mode_handler_f3dex2(F3DGfx** cmd0) { } // Only on F3DEX and older -bool gfx_set_geometry_mode_handler_f3dex(F3DGfx** cmd0) { +bool gfx_set_geometry_mode_handler_f3d(F3DGfx** cmd0) { F3DGfx* cmd = *cmd0; gfx_sp_geometry_mode(0, (uint32_t)cmd->words.w1); return false; } // Only on F3DEX and older -bool gfx_clear_geometry_mode_handler_f3dex(F3DGfx** cmd0) { +bool gfx_clear_geometry_mode_handler_f3d(F3DGfx** cmd0) { F3DGfx* cmd = *cmd0; gfx_sp_geometry_mode((uint32_t)cmd->words.w1, 0); return false; @@ -3427,7 +3426,7 @@ bool gfx_set_combine_handler_rdp(F3DGfx** cmd0) { bool gfx_tex_rect_and_flip_handler_rdp(F3DGfx** cmd0) { F3DGfx* cmd = *cmd0; - uint32_t opcode = (uint32_t)(cmd->words.w0 >> 24); + int8_t opcode = (int8_t)(cmd->words.w0 >> 24); int32_t lrx, lry, tile, ulx, uly; uint32_t uls, ult, dsdx, dtdy; @@ -3446,13 +3445,13 @@ bool gfx_tex_rect_and_flip_handler_rdp(F3DGfx** cmd0) { dsdx = C1(16, 16); dtdy = C1(0, 16); - gfx_dp_texture_rectangle(ulx, uly, lrx, lry, tile, uls, ult, dsdx, dtdy, opcode == G_TEXRECTFLIP); + gfx_dp_texture_rectangle(ulx, uly, lrx, lry, tile, uls, ult, dsdx, dtdy, opcode == RDP_G_TEXRECTFLIP); return false; } bool gfx_tex_rect_wide_handler_custom(F3DGfx** cmd0) { F3DGfx* cmd = *cmd0; - uint32_t opcode = (uint32_t)(cmd->words.w0 >> 24); + int8_t opcode = (int8_t)(cmd->words.w0 >> 24); int32_t lrx, lry, tile, ulx, uly; uint32_t uls, ult, dsdx, dtdy; @@ -3469,7 +3468,7 @@ bool gfx_tex_rect_wide_handler_custom(F3DGfx** cmd0) { ult = C0(0, 16); dsdx = C1(16, 16); dtdy = C1(0, 16); - gfx_dp_texture_rectangle(ulx, uly, lrx, lry, tile, uls, ult, dsdx, dtdy, opcode == G_TEXRECTFLIP); + gfx_dp_texture_rectangle(ulx, uly, lrx, lry, tile, uls, ult, dsdx, dtdy, opcode == RDP_G_TEXRECTFLIP); return false; } @@ -3549,7 +3548,7 @@ bool gfx_bg_copy_handler_s2dex(F3DGfx** cmd0) { F3DGfx* cmd = *(cmd0); if (!markerOn) { - gfx_s2dex_bg_copy((uObjBg*)cmd->words.w1); // not seg_addr here it seems + gfx_s2dex_bg_copy((F3DuObjBg*)cmd->words.w1); // not seg_addr here it seems } return false; } @@ -3557,7 +3556,7 @@ bool gfx_bg_copy_handler_s2dex(F3DGfx** cmd0) { bool gfx_bg_1cyc_handler_s2dex(F3DGfx** cmd0) { F3DGfx* cmd = *(cmd0); - gfx_s2dex_bg_1cyc((uObjBg*)cmd->words.w1); + gfx_s2dex_bg_1cyc((F3DuObjBg*)cmd->words.w1); return false; } @@ -3565,7 +3564,7 @@ bool gfx_obj_rectangle_handler_s2dex(F3DGfx** cmd0) { F3DGfx* cmd = *(cmd0); if (!markerOn) { - gfx_s2dex_rect_copy((uObjSprite*)cmd->words.w1); // not seg_addr here it seems + gfx_s2dex_rect_copy((F3DuObjSprite*)cmd->words.w1); // not seg_addr here it seems } return false; } @@ -3586,111 +3585,113 @@ bool gfx_spnoop_command_handler_f3dex2(F3DGfx** cmd0) { } const static std::unordered_map rdpHandlers = { - { G_TEXRECT, gfx_tex_rect_and_flip_handler_rdp }, // G_TEXRECT (-28) - { G_TEXRECTFLIP, gfx_tex_rect_and_flip_handler_rdp }, // G_TEXRECTFLIP (-27) - { G_RDPLOADSYNC, gfx_stubbed_command_handler }, // G_RDPLOADSYNC (-26) - { G_RDPPIPESYNC, gfx_stubbed_command_handler }, // G_RDPPIPESYNC (-25) - { G_RDPTILESYNC, gfx_stubbed_command_handler }, // G_RDPPIPESYNC (-24) - { G_RDPFULLSYNC, gfx_stubbed_command_handler }, // G_RDPFULLSYNC (-23) - { G_SETSCISSOR, gfx_set_scissor_handler_rdp }, // G_SETSCISSOR (-19) - { G_SETPRIMDEPTH, gfx_set_prim_depth_handler_rdp }, // G_SETPRIMDEPTH (-18) - { G_RDPSETOTHERMODE, gfx_rdp_set_other_mode_rdp }, // G_RDPSETOTHERMODE (-17) - { G_LOADTLUT, gfx_load_tlut_handler_rdp }, // G_LOADTLUT (-16) - { G_SETTILESIZE, gfx_set_tile_size_handler_rdp }, // G_SETTILESIZE (-14) - { G_LOADBLOCK, gfx_load_block_handler_rdp }, // G_LOADBLOCK (-13) - { G_LOADTILE, gfx_load_tile_handler_rdp }, // G_LOADTILE (-12) - { G_SETTILE, gfx_set_tile_handler_rdp }, // G_SETTILE (-11) - { G_FILLRECT, gfx_fill_rect_handler_rdp }, // G_FILLRECT (-10) - { G_SETFILLCOLOR, gfx_set_fill_color_handler_rdp }, // G_SETFILLCOLOR (-9) - { G_SETFOGCOLOR, gfx_set_fog_color_handler_rdp }, // G_SETFOGCOLOR (-8) - { G_SETBLENDCOLOR, gfx_set_blend_color_handler_rdp }, // G_SETBLENDCOLOR (-7) - { G_SETPRIMCOLOR, gfx_set_prim_color_handler_rdp }, // G_SETPRIMCOLOR (-6) - { G_SETENVCOLOR, gfx_set_env_color_handler_rdp }, // G_SETENVCOLOR (-5) - { G_SETCOMBINE, gfx_set_combine_handler_rdp }, // G_SETCOMBINE (-4) - { G_SETTIMG, gfx_set_timg_handler_rdp }, // G_SETTIMG (-3) - { G_SETZIMG, gfx_set_z_img_handler_rdp }, // G_SETZIMG (-2) - { G_SETCIMG, gfx_set_c_img_handler_rdp }, // G_SETCIMG (-1) + { RDP_G_TEXRECT, gfx_tex_rect_and_flip_handler_rdp }, // G_TEXRECT (-28) + { RDP_G_TEXRECTFLIP, gfx_tex_rect_and_flip_handler_rdp }, // G_TEXRECTFLIP (-27) + { RDP_G_RDPLOADSYNC, gfx_stubbed_command_handler }, // G_RDPLOADSYNC (-26) + { RDP_G_RDPPIPESYNC, gfx_stubbed_command_handler }, // G_RDPPIPESYNC (-25) + { RDP_G_RDPTILESYNC, gfx_stubbed_command_handler }, // G_RDPPIPESYNC (-24) + { RDP_G_RDPFULLSYNC, gfx_stubbed_command_handler }, // G_RDPFULLSYNC (-23) + { RDP_G_SETSCISSOR, gfx_set_scissor_handler_rdp }, // G_SETSCISSOR (-19) + { RDP_G_SETPRIMDEPTH, gfx_set_prim_depth_handler_rdp }, // G_SETPRIMDEPTH (-18) + { RDP_G_RDPSETOTHERMODE, gfx_rdp_set_other_mode_rdp }, // G_RDPSETOTHERMODE (-17) + { RDP_G_LOADTLUT, gfx_load_tlut_handler_rdp }, // G_LOADTLUT (-16) + { RDP_G_SETTILESIZE, gfx_set_tile_size_handler_rdp }, // G_SETTILESIZE (-14) + { RDP_G_LOADBLOCK, gfx_load_block_handler_rdp }, // G_LOADBLOCK (-13) + { RDP_G_LOADTILE, gfx_load_tile_handler_rdp }, // G_LOADTILE (-12) + { RDP_G_SETTILE, gfx_set_tile_handler_rdp }, // G_SETTILE (-11) + { RDP_G_FILLRECT, gfx_fill_rect_handler_rdp }, // G_FILLRECT (-10) + { RDP_G_SETFILLCOLOR, gfx_set_fill_color_handler_rdp }, // G_SETFILLCOLOR (-9) + { RDP_G_SETFOGCOLOR, gfx_set_fog_color_handler_rdp }, // G_SETFOGCOLOR (-8) + { RDP_G_SETBLENDCOLOR, gfx_set_blend_color_handler_rdp }, // G_SETBLENDCOLOR (-7) + { RDP_G_SETPRIMCOLOR, gfx_set_prim_color_handler_rdp }, // G_SETPRIMCOLOR (-6) + { RDP_G_SETENVCOLOR, gfx_set_env_color_handler_rdp }, // G_SETENVCOLOR (-5) + { RDP_G_SETCOMBINE, gfx_set_combine_handler_rdp }, // G_SETCOMBINE (-4) + { RDP_G_SETTIMG, gfx_set_timg_handler_rdp }, // G_SETTIMG (-3) + { RDP_G_SETZIMG, gfx_set_z_img_handler_rdp }, // G_SETZIMG (-2) + { RDP_G_SETCIMG, gfx_set_c_img_handler_rdp }, // G_SETCIMG (-1) }; -const static std::unordered_map otrHandlers = { - { G_SETTIMG_OTR_HASH, gfx_set_timg_otr_hash_handler_custom }, // G_SETTIMG_OTR_HASH (0x20) - { G_SETFB, gfx_set_fb_handler_custom }, // G_SETFB (0x21) - { G_RESETFB, gfx_reset_fb_handler_custom }, // G_RESETFB (0x22) - { G_SETTIMG_FB, gfx_set_timg_fb_handler_custom }, // G_SETTIMG_FB (0x23) - { G_VTX_OTR_FILEPATH, gfx_vtx_otr_filepath_handler_custom }, // G_VTX_OTR_FILEPATH (0x24) - { G_SETTIMG_OTR_FILEPATH, gfx_set_timg_otr_filepath_handler_custom }, // G_SETTIMG_OTR_FILEPATH (0x25) - { G_TRI1_OTR, gfx_tri1_otr_handler_f3dex2 }, // G_TRI1_OTR (0x26) - { G_DL_OTR_FILEPATH, gfx_dl_otr_filepath_handler_custom }, // G_DL_OTR_FILEPATH (0x27) - { G_DL_OTR_HASH, gfx_dl_otr_hash_handler_custom }, // G_DL_OTR_HASH (0x31) - { G_VTX_OTR_HASH, gfx_vtx_hash_handler_custom }, // G_VTX_OTR_HASH (0x32) - { G_BRANCH_Z_OTR, gfx_branch_z_otr_handler_f3dex2 }, // G_BRANCH_Z_OTR (0x35) +const static std::unordered_map otrHandlers = { + { OTR_G_SETTIMG_OTR_HASH, gfx_set_timg_otr_hash_handler_custom }, // G_SETTIMG_OTR_HASH (0x20) + { OTR_G_SETFB, gfx_set_fb_handler_custom }, // G_SETFB (0x21) + { OTR_G_RESETFB, gfx_reset_fb_handler_custom }, // G_RESETFB (0x22) + { OTR_G_SETTIMG_FB, gfx_set_timg_fb_handler_custom }, // G_SETTIMG_FB (0x23) + { OTR_G_VTX_OTR_FILEPATH, gfx_vtx_otr_filepath_handler_custom }, // G_VTX_OTR_FILEPATH (0x24) + { OTR_G_SETTIMG_OTR_FILEPATH, gfx_set_timg_otr_filepath_handler_custom }, // G_SETTIMG_OTR_FILEPATH (0x25) + { OTR_G_TRI1_OTR, gfx_tri1_otr_handler_f3dex2 }, // G_TRI1_OTR (0x26) + { OTR_G_DL_OTR_FILEPATH, gfx_dl_otr_filepath_handler_custom }, // G_DL_OTR_FILEPATH (0x27) + { OTR_G_PUSHCD, gfx_pushcd_handler_custom }, // G_PUSHCD (0x28) + { OTR_G_DL_OTR_HASH, gfx_dl_otr_hash_handler_custom }, // G_DL_OTR_HASH (0x31) + { OTR_G_VTX_OTR_HASH, gfx_vtx_hash_handler_custom }, // G_VTX_OTR_HASH (0x32) + { OTR_G_MARKER, gfx_marker_handler_otr }, // G_MARKER (0X33) + { OTR_G_INVALTEXCACHE, gfx_invalidate_tex_cache_handler_f3dex2 }, // G_INVALTEXCACHE (0X34) + { OTR_G_BRANCH_Z_OTR, gfx_branch_z_otr_handler_f3dex2 }, // G_BRANCH_Z_OTR (0x35) #ifdef F3DEX_GBI_2 - { G_MTX_OTR, gfx_mtx_otr_handler_custom_f3dex2 }, // G_MTX_OTR (0x36) + { OTR_G_MTX_OTR, gfx_mtx_otr_handler_custom_f3dex2 }, // G_MTX_OTR (0x36) #else - { G_MTX_OTR, gfx_mtx_otr_handler_custom_f3d }, // G_MTX_OTR (0x36) + { OTR_G_MTX_OTR2, gfx_mtx_otr_handler_custom_f3d }, //G_MTX_OTR2 (0x29) Is this the right code? #endif - { G_TEXRECT_WIDE, gfx_tex_rect_wide_handler_custom }, // G_TEXRECT_WIDE (0x37) - { G_FILLWIDERECT, gfx_fill_wide_rect_handler_custom }, // G_FILLWIDERECT (0x38) - { G_SETGRAYSCALE, gfx_set_grayscale_handler_custom }, // G_SETGRAYSCALE (0x39) - { G_EXTRAGEOMETRYMODE, gfx_extra_geometry_mode_handler_custom }, // G_EXTRAGEOMETRYMODE (0x3a) - { G_COPYFB, gfx_copy_fb_handler_custom }, // G_COPYFB (0x3b) - { G_READFB, gfx_read_fb_handler_custom }, // G_READFB (0x3e) - { G_IMAGERECT, gfx_image_rect_handler_custom }, // G_IMAGERECT (0x3c) - { G_SETINTENSITY, gfx_set_intensity_handler_custom }, // G_SETINTENSITY (0x40) + { OTR_G_TEXRECT_WIDE, gfx_tex_rect_wide_handler_custom }, // G_TEXRECT_WIDE (0x37) + { OTR_G_FILLWIDERECT, gfx_fill_wide_rect_handler_custom }, // G_FILLWIDERECT (0x38) + { OTR_G_SETGRAYSCALE, gfx_set_grayscale_handler_custom }, // G_SETGRAYSCALE (0x39) + { OTR_G_EXTRAGEOMETRYMODE, gfx_extra_geometry_mode_handler_custom }, // G_EXTRAGEOMETRYMODE (0x3a) + { OTR_G_COPYFB, gfx_copy_fb_handler_custom }, // G_COPYFB (0x3b) + { OTR_G_IMAGERECT, gfx_image_rect_handler_custom }, // G_IMAGERECT (0x3c) + { OTR_G_DL_INDEX, gfx_dl_index_handler }, // G_DL_INDEX (0x3d) + { OTR_G_READFB, gfx_read_fb_handler_custom }, // G_READFB (0x3e) + { OTR_G_SETINTENSITY, gfx_set_intensity_handler_custom }, // G_SETINTENSITY (0x40) }; -const static std::unordered_map f3dex2Handlers = { - { G_NOOP, gfx_noop_handler_f3dex2 }, - { G_CULLDL, gfx_cull_dl_handler_f3dex2 }, - { G_MARKER, gfx_marker_handler_f3dex2 }, - { G_INVALTEXCACHE, gfx_invalidate_tex_cache_handler_f3dex2 }, - { G_MTX, gfx_mtx_handler_f3dex2 }, - { G_POPMTX, gfx_pop_mtx_handler_f3dex2 }, +const static std::unordered_map f3dex2Handlers = { + { F3DEX2_G_NOOP, gfx_noop_handler_f3dex2 }, + { F3DEX2_G_CULLDL, gfx_cull_dl_handler_f3dex2 }, + { F3DEX2_G_MTX, gfx_mtx_handler_f3dex2 }, + { F3DEX2_G_POPMTX, gfx_pop_mtx_handler_f3dex2 }, #ifdef F3DEX_GBI_2 - { G_MOVEMEM, gfx_movemem_handler_f3dex2 }, - { G_MOVEWORD, gfx_moveword_handler_f3dex2 }, + { F3DEX2_G_MOVEMEM, gfx_movemem_handler_f3dex2 }, + { F3DEX2_G_MOVEWORD, gfx_moveword_handler_f3dex2 }, #else { G_MOVEMEM, gfx_movemem_handler_f3d }, { G_MOVEWORD, gfx_moveword_handler_f3d }, #endif - { G_TEXTURE, gfx_texture_handler_f3dex2 }, - { G_VTX, gfx_vtx_handler_f3dex2 }, - { G_MODIFYVTX, gfx_modify_vtx_handler_f3dex2 }, - { G_DL, gfx_dl_handler_common }, - { G_DL_INDEX, gfx_dl_index_handler }, - { G_PUSHCD, gfx_pushcd_handler_f3dex2 }, - { G_ENDDL, gfx_end_dl_handler_common }, + { F3DEX2_G_TEXTURE, gfx_texture_handler_f3dex2 }, + { F3DEX2_G_VTX, gfx_vtx_handler_f3dex2 }, + { F3DEX2_G_MODIFYVTX, gfx_modify_vtx_handler_f3dex2 }, + { F3DEX2_G_DL, gfx_dl_handler_common }, + { F3DEX2_G_ENDDL, gfx_end_dl_handler_common }, #ifdef F3DEX_GBI_2 - { G_GEOMETRYMODE, gfx_geometry_mode_handler_f3dex2 }, + { F3DEX2_G_GEOMETRYMODE, gfx_geometry_mode_handler_f3dex2 }, #else - { G_SETGEOMETRYMODE, gfx_set_geometry_mode_handler_f3dex }, - { G_CLEARGEOMETRYMODE, gfx_clear_geometry_mode_handler_f3dex }, + { G_SETGEOMETRYMODE, gfx_set_geometry_mode_handler_f3d }, + { G_CLEARGEOMETRYMODE, gfx_clear_geometry_mode_handler_f3d }, #endif - { G_TRI1, gfx_tri1_handler_f3dex2 }, - { G_QUAD, gfx_quad_handler_f3dex2 }, - { G_TRI2, gfx_tri2_handler_f3dex }, - { G_SETOTHERMODE_L, gfx_othermode_l_handler_f3dex2 }, - { G_SETOTHERMODE_H, gfx_othermode_h_handler_f3dex2 }, + { F3DEX2_G_TRI1, gfx_tri1_handler_f3dex2 }, + { F3DEX2_G_TRI2, gfx_tri2_handler_f3dex }, + { F3DEX2_G_QUAD, gfx_quad_handler_f3dex2 }, + { F3DEX2_G_SETOTHERMODE_L, gfx_othermode_l_handler_f3dex2 }, + { F3DEX2_G_SETOTHERMODE_H, gfx_othermode_h_handler_f3dex2 }, // Commands to implement - { G_SPNOOP, gfx_spnoop_command_handler_f3dex2 }, - { G_RDPHALF_1, gfx_stubbed_command_handler }, + { F3DEX2_G_SPNOOP, gfx_spnoop_command_handler_f3dex2 }, + { F3DEX2_G_RDPHALF_1, gfx_stubbed_command_handler }, }; -const static std::unordered_map s2dexHandlers = { - { G_BG_COPY, gfx_bg_copy_handler_s2dex }, - { G_BG_1CYC, gfx_bg_1cyc_handler_s2dex }, - { G_OBJ_RENDERMODE, gfx_stubbed_command_handler }, - { G_OBJ_RECTANGLE_R, gfx_stubbed_command_handler }, - { G_OBJ_RECTANGLE, gfx_obj_rectangle_handler_s2dex }, - { G_DL, gfx_dl_handler_common }, - { G_SETOTHERMODE_L, gfx_othermode_l_handler_f3dex2 }, - { G_SETOTHERMODE_H, gfx_othermode_h_handler_f3dex2 }, - { G_ENDDL, gfx_end_dl_handler_common }, - { G_RDPHALF_1, gfx_stubbed_command_handler }, - { G_RDPHALF_2, gfx_stubbed_command_handler }, +// LUSTODO figure out how to deal with non f3dex2. It seems that the opcode numbers are different. +// Are the actual implementations different? +const static std::unordered_map s2dexHandlers = { + { S2DEX_G_BG_COPY, gfx_bg_copy_handler_s2dex }, + { S2DEX_G_BG_1CYC, gfx_bg_1cyc_handler_s2dex }, + { S2DEX_G_OBJ_RENDERMODE, gfx_stubbed_command_handler }, + { S2DEX_G_OBJ_RECTANGLE_R, gfx_stubbed_command_handler }, + { S2DEX_G_OBJ_RECTANGLE, gfx_obj_rectangle_handler_s2dex }, + { F3DEX2_G_DL, gfx_dl_handler_common }, + //{ G_SETOTHERMODE_L, gfx_othermode_l_handler_f3dex2 }, + //{ G_SETOTHERMODE_H, gfx_othermode_h_handler_f3dex2 }, + { F3DEX2_G_ENDDL, gfx_end_dl_handler_common }, + { F3DEX2_G_RDPHALF_1, gfx_stubbed_command_handler }, + { F3DEX2_G_RDPHALF_2, gfx_stubbed_command_handler }, }; -const static std::array*, UcodeHandlers::ucode_max> +const static std::array*, UcodeHandlers::ucode_max> ucode_handlers = { &f3dex2Handlers, &s2dexHandlers, @@ -3707,7 +3708,7 @@ static void gfx_set_ucode_handler(UcodeHandlers ucode) { static void gfx_step() { auto& cmd = g_exec_stack.currCmd(); auto cmd0 = cmd; - uint32_t opcode = (uint32_t)(cmd->words.w0 >> 24); + int8_t opcode = (int8_t)(cmd->words.w0 >> 24); if (opcode == G_LOAD_UCODE) { gfx_set_ucode_handler((UcodeHandlers)(cmd->words.w0 & 0xFFFFFF)); diff --git a/src/graphic/Fast3D/gfx_pc.h b/src/graphic/Fast3D/gfx_pc.h index 175c6776c..912b9f35f 100644 --- a/src/graphic/Fast3D/gfx_pc.h +++ b/src/graphic/Fast3D/gfx_pc.h @@ -10,7 +10,6 @@ #include #include -//#include "libultraship/libultra/gbi.h" #include "graphic/Fast3D/lus_gbi.h" #include "libultraship/libultra/types.h" diff --git a/src/graphic/Fast3D/lus_gbi.h b/src/graphic/Fast3D/lus_gbi.h index 4878a7534..72de01b70 100644 --- a/src/graphic/Fast3D/lus_gbi.h +++ b/src/graphic/Fast3D/lus_gbi.h @@ -1,4 +1,5 @@ #pragma once +#include /* To enable Fast3DEX grucode support, define F3DEX_GBI. */ /* Types */ @@ -15,33 +16,33 @@ #ifndef F3DEX_GBI #define F3DEX_GBI #endif -#define G_NOOP 0x00 -#define G_RDPHALF_2 0xf1 -#define G_SETOTHERMODE_H 0xe3 -#define G_SETOTHERMODE_L 0xe2 -#define G_RDPHALF_1 0xe1 -#define G_SPNOOP 0xe0 -#define G_ENDDL 0xdf -#define G_DL 0xde +constexpr int8_t F3DEX2_G_NOOP = 0x00; +constexpr int8_t F3DEX2_G_RDPHALF_2 = 0xf1; +constexpr int8_t F3DEX2_G_SETOTHERMODE_H = 0xe3; +constexpr int8_t F3DEX2_G_SETOTHERMODE_L = 0xe2; +constexpr int8_t F3DEX2_G_RDPHALF_1 = 0xe1; +constexpr int8_t F3DEX2_G_SPNOOP = 0xe0; +constexpr int8_t F3DEX2_G_ENDDL = 0xdf; +constexpr int8_t F3DEX2_G_DL = 0xde; #define G_LOAD_UCODE 0xdd -#define G_MOVEMEM 0xdc -#define G_MOVEWORD 0xdb -#define G_MTX 0xda -#define G_GEOMETRYMODE 0xd9 -#define G_POPMTX 0xd8 -#define G_TEXTURE 0xd7 +constexpr int8_t F3DEX2_G_MOVEMEM = 0xdc; +constexpr int8_t F3DEX2_G_MOVEWORD = 0xdb; +constexpr int8_t F3DEX2_G_MTX = 0xda; +constexpr int8_t F3DEX2_G_GEOMETRYMODE = 0xd9; +constexpr int8_t F3DEX2_G_POPMTX = 0xd8; +constexpr int8_t F3DEX2_G_TEXTURE = 0xd7; #define G_DMA_IO 0xd6 #define G_SPECIAL_1 0xd5 #define G_SPECIAL_2 0xd4 #define G_SPECIAL_3 0xd3 -#define G_VTX 0x01 -#define G_MODIFYVTX 0x02 -#define G_CULLDL 0x03 -#define G_BRANCH_Z 0x04 -#define G_TRI1 0x05 -#define G_TRI2 0x06 -#define G_QUAD 0x07 +constexpr int8_t F3DEX2_G_VTX = 0x01; +constexpr int8_t F3DEX2_G_MODIFYVTX = 0x02; +constexpr int8_t F3DEX2_G_CULLDL = 0x03; +constexpr int8_t F3DEX2_G_BRANCH_Z = 0x04; +constexpr int8_t F3DEX2_G_TRI1 = 0x05; +constexpr int8_t F3DEX2_G_TRI2 = 0x06; +constexpr int8_t F3DEX2_G_QUAD = 0x07; #define G_LINE3D 0x08 #else /* F3DEX_GBI_2 */ @@ -49,7 +50,7 @@ #define G_SPNOOP 0 /* handle 0 gracefully */ #define G_MTX 1 #define G_RESERVED0 2 /* not implemeted */ -#define G_MOVEMEM 3 /* move a block of memory (up to 4 words) to dmem */ +constexpr int8_t G_MOVEMEM 3 /* move a block of memory (up to 4 words) to dmem */ #define G_VTX 4 #define G_RESERVED1 5 /* not implemeted */ #define G_DL 6 @@ -62,13 +63,13 @@ #define G_TRI1 (G_IMMFIRST - 0) #define G_CULLDL (G_IMMFIRST - 1) #define G_POPMTX (G_IMMFIRST - 2) -#define G_MOVEWORD (G_IMMFIRST - 3) +constexpr int8_t G_MOVEWORD = (G_IMMFIRST - 3); #define G_TEXTURE (G_IMMFIRST - 4) #define G_SETOTHERMODE_H (G_IMMFIRST - 5) #define G_SETOTHERMODE_L (G_IMMFIRST - 6) #define G_ENDDL (G_IMMFIRST - 7) -#define G_SETGEOMETRYMODE (G_IMMFIRST - 8) -#define G_CLEARGEOMETRYMODE (G_IMMFIRST - 9) +constexpr int8_t G_SETGEOMETRYMODE = (G_IMMFIRST - 8); +constexpr int8_t G_CLEARGEOMETRYMODE - (G_IMMFIRST - 9); #define G_LINE3D (G_IMMFIRST - 10) #define G_RDPHALF_1 (G_IMMFIRST - 11) #define G_RDPHALF_2 (G_IMMFIRST - 12) @@ -93,64 +94,64 @@ #endif /* F3DEX_GBI_2 */ /* RDP commands: */ -#define G_SETCIMG 0xff /* -1 */ -#define G_SETZIMG 0xfe /* -2 */ -#define G_SETTIMG 0xfd /* -3 */ -#define G_SETCOMBINE 0xfc /* -4 */ -#define G_SETENVCOLOR 0xfb /* -5 */ -#define G_SETPRIMCOLOR 0xfa /* -6 */ -#define G_SETBLENDCOLOR 0xf9 /* -7 */ -#define G_SETFOGCOLOR 0xf8 /* -8 */ -#define G_SETFILLCOLOR 0xf7 /* -9 */ -#define G_FILLRECT 0xf6 /* -10 */ -#define G_SETTILE 0xf5 /* -11 */ -#define G_LOADTILE 0xf4 /* -12 */ -#define G_LOADBLOCK 0xf3 /* -13 */ -#define G_SETTILESIZE 0xf2 /* -14 */ -#define G_LOADTLUT 0xf0 /* -16 */ -#define G_RDPSETOTHERMODE 0xef /* -17 */ -#define G_SETPRIMDEPTH 0xee /* -18 */ -#define G_SETSCISSOR 0xed /* -19 */ -#define G_SETCONVERT 0xec /* -20 */ -#define G_SETKEYR 0xeb /* -21 */ -#define G_SETKEYGB 0xea /* -22 */ -#define G_RDPFULLSYNC 0xe9 /* -23 */ -#define G_RDPTILESYNC 0xe8 /* -24 */ -#define G_RDPPIPESYNC 0xe7 /* -25 */ -#define G_RDPLOADSYNC 0xe6 /* -26 */ -#define G_TEXRECTFLIP 0xe5 /* -27 */ -#define G_TEXRECT 0xe4 /* -28 */ +constexpr int8_t RDP_G_SETCIMG = 0xff; /* -1 */ +constexpr int8_t RDP_G_SETZIMG = 0xfe; /* -2 */ +constexpr int8_t RDP_G_SETTIMG = 0xfd; /* -3 */ +constexpr int8_t RDP_G_SETCOMBINE= 0xfc; /* -4 */ +constexpr int8_t RDP_G_SETENVCOLOR = 0xfb; /* -5 */ +constexpr int8_t RDP_G_SETPRIMCOLOR = 0xfa; /* -6 */ +constexpr int8_t RDP_G_SETBLENDCOLOR = 0xf9; /* -7 */ +constexpr int8_t RDP_G_SETFOGCOLOR = 0xf8; /* -8 */ +constexpr int8_t RDP_G_SETFILLCOLOR = 0xf7; /* -9 */ +constexpr int8_t RDP_G_FILLRECT = 0xf6; /* -10 */ +constexpr int8_t RDP_G_SETTILE = 0xf5; /* -11 */ +constexpr int8_t RDP_G_LOADTILE = 0xf4; /* -12 */ +constexpr int8_t RDP_G_LOADBLOCK = 0xf3; /* -13 */ +constexpr int8_t RDP_G_SETTILESIZE = 0xf2; /* -14 */ +constexpr int8_t RDP_G_LOADTLUT = 0xf0; /* -16 */ +constexpr int8_t RDP_G_RDPSETOTHERMODE = 0xef; /* -17 */ +constexpr int8_t RDP_G_SETPRIMDEPTH = 0xee; /* -18 */ +constexpr int8_t RDP_G_SETSCISSOR = 0xed; /* -19 */ +constexpr int8_t RDP_G_SETCONVERT = 0xec; /* -20 */ +constexpr int8_t RDP_G_SETKEYR = 0xeb; /* -21 */ +constexpr int8_t RDP_G_SETKEYGB = 0xea; /* -22 */ +constexpr int8_t RDP_G_RDPFULLSYNC = 0xe9; /* -23 */ +constexpr int8_t RDP_G_RDPTILESYNC = 0xe8; /* -24 */ +constexpr int8_t RDP_G_RDPPIPESYNC = 0xe7; /* -25 */ +constexpr int8_t RDP_G_RDPLOADSYNC = 0xe6; /* -26 */ +constexpr int8_t RDP_G_TEXRECTFLIP = 0xe5; /* -27 */ +constexpr int8_t RDP_G_TEXRECT = 0xe4; /* -28 */ // CUSTOM OTR COMMANDS -#define G_SETTIMG_OTR_HASH 0x20 -#define G_SETFB 0x21 -#define G_RESETFB 0x22 -#define G_SETTIMG_FB 0x23 -#define G_VTX_OTR_FILEPATH 0x24 -#define G_SETTIMG_OTR_FILEPATH 0x25 -#define G_TRI1_OTR 0x26 -#define G_DL_OTR_FILEPATH 0x27 -#define G_PUSHCD 0x28 -#define G_MTX_OTR2 0x29 -#define G_DL_OTR_HASH 0x31 -#define G_VTX_OTR_HASH 0x32 -#define G_MARKER 0x33 -#define G_INVALTEXCACHE 0x34 -#define G_BRANCH_Z_OTR 0x35 -#define G_MTX_OTR 0x36 -#define G_TEXRECT_WIDE 0x37 -#define G_FILLWIDERECT 0x38 +constexpr int8_t OTR_G_SETTIMG_OTR_HASH = 0x20; +constexpr int8_t OTR_G_SETFB = 0x21; +constexpr int8_t OTR_G_RESETFB = 0x22; +constexpr int8_t OTR_G_SETTIMG_FB = 0x23; +constexpr int8_t OTR_G_VTX_OTR_FILEPATH = 0x24; +constexpr int8_t OTR_G_SETTIMG_OTR_FILEPATH = 0x25; +constexpr int8_t OTR_G_TRI1_OTR = 0x26; +constexpr int8_t OTR_G_DL_OTR_FILEPATH = 0x27; +constexpr int8_t OTR_G_PUSHCD = 0x28; +constexpr int8_t OTR_G_MTX_OTR2 = 0x29; +constexpr int8_t OTR_G_DL_OTR_HASH = 0x31; +constexpr int8_t OTR_G_VTX_OTR_HASH = 0x32; +constexpr int8_t OTR_G_MARKER = 0x33; +constexpr int8_t OTR_G_INVALTEXCACHE = 0x34; +constexpr int8_t OTR_G_BRANCH_Z_OTR = 0x35; +constexpr int8_t OTR_G_MTX_OTR = 0x36; +constexpr int8_t OTR_G_TEXRECT_WIDE = 0x37; +constexpr int8_t OTR_G_FILLWIDERECT = 0x38; /* GFX Effects */ // RDP Cmd -#define G_SETGRAYSCALE 0x39 -#define G_EXTRAGEOMETRYMODE 0x3a -#define G_COPYFB 0x3b -#define G_IMAGERECT 0x3c -#define G_DL_INDEX 0x3d -#define G_READFB 0x3e -#define G_SETINTENSITY 0x40 +constexpr int8_t OTR_G_SETGRAYSCALE = 0x39; +constexpr int8_t OTR_G_EXTRAGEOMETRYMODE = 0x3a; +constexpr int8_t OTR_G_COPYFB = 0x3b; +constexpr int8_t OTR_G_IMAGERECT = 0x3c; +constexpr int8_t OTR_G_DL_INDEX = 0x3d; +constexpr int8_t OTR_G_READFB = 0x3e; +constexpr int8_t OTR_G_SETINTENSITY = 0x40; /* * The following commands are the "generated" RDP commands; the user @@ -1336,5 +1337,235 @@ typedef union F3DGfx{ long long int force_structure_alignment; } F3DGfx; +/*===========================================================================* + * GBI Commands for S2DEX microcode + *===========================================================================*/ +/* GBI Header */ +#ifdef F3DEX_GBI_2 +constexpr int8_t S2DEX_G_OBJ_RECTANGLE_R = 0xda; +#define G_OBJ_MOVEMEM 0xdc +#define G_RDPHALF_0 0xe4 +constexpr int8_t S2DEX_G_OBJ_RECTANGLE = 0x01; +#define G_OBJ_SPRITE 0x02 +#define G_SELECT_DL 0x04 +#define G_OBJ_LOADTXTR 0x05 +#define G_OBJ_LDTX_SPRITE 0x06 +#define G_OBJ_LDTX_RECT 0x07 +#define G_OBJ_LDTX_RECT_R 0x08 +constexpr int8_t S2DEX_G_BG_1CYC = 0x09; +constexpr int8_t S2DEX_G_BG_COPY = 0x0a; +constexpr int8_t S2DEX_G_OBJ_RENDERMODE = 0x0b; +#else +#define G_BG_1CYC 0x01 +#define G_BG_COPY 0x02 +#define G_OBJ_RECTANGLE 0x03 +#define G_OBJ_SPRITE 0x04 +#define G_OBJ_MOVEMEM 0x05 +#define G_SELECT_DL 0xb0 +#define G_OBJ_RENDERMODE 0xb1 +#define G_OBJ_RECTANGLE_R 0xb2 +#define G_OBJ_LOADTXTR 0xc1 +#define G_OBJ_LDTX_SPRITE 0xc2 +#define G_OBJ_LDTX_RECT 0xc3 +#define G_OBJ_LDTX_RECT_R 0xc4 +#define G_RDPHALF_0 0xe4 +#endif + +#define G_BGLT_LOADBLOCK 0x0033 +#define G_BGLT_LOADTILE 0xfff4 + +#define G_BG_FLAG_FLIPS 0x01 +#define G_BG_FLAG_FLIPT 0x10 + +/* Non scalable background plane */ +typedef struct { + unsigned short imageX; /* x-coordinate of upper-left position of texture (u10.5) */ + unsigned short imageW; /* width of the texture (u10.2) */ + short frameX; /* upper-left position of transferred frame (s10.2) */ + unsigned short frameW; /* width of transferred frame (u10.2) */ + + unsigned short imageY; /* y-coordinate of upper-left position of texture (u10.5) */ + unsigned short imageH; /* height of the texture (u10.2) */ + short frameY; /* upper-left position of transferred frame (s10.2) */ + unsigned short frameH; /* height of transferred frame (u10.2) */ + + unsigned long long int* imagePtr; /* texture source address on DRAM */ + unsigned short imageLoad; /* which to use, LoadBlock or LoadTile */ + unsigned char imageFmt; /* format of texel - G_IM_FMT_* */ + unsigned char imageSiz; /* size of texel - G_IM_SIZ_* */ + unsigned short imagePal; /* pallet number */ + unsigned short imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */ + + /* The following is set in the initialization routine guS2DInitBg(). There is no need for the user to set it. */ + unsigned short tmemW; /* TMEM width and Word size of frame 1 line. + At LoadBlock, GS_PIX2TMEM(imageW/4,imageSiz) + At LoadTile GS_PIX2TMEM(frameW/4,imageSiz)+1 */ + unsigned short tmemH; /* height of TMEM loadable at a time (s13.2) 4 times value + When the normal texture, 512/tmemW*4 + When the CI texture, 256/tmemW*4 */ + unsigned short tmemLoadSH; /* SH value + At LoadBlock, tmemSize/2-1 + At LoadTile, tmemW*16-1 */ + unsigned short tmemLoadTH; /* TH value or Stride value + At LoadBlock, GS_CALC_DXT(tmemW) + At LoadTile, tmemH-1 */ + unsigned short tmemSizeW; /* skip value of imagePtr for image 1-line + At LoadBlock, tmemW*2 + At LoadTile, GS_PIX2TMEM(imageW/4,imageSiz)*2 */ + unsigned short tmemSize; /* skip value of imagePtr for 1-loading + = tmemSizeW*tmemH */ +} F3DuObjBg_t; /* 40 bytes */ + +/* Scalable background plane */ +typedef struct { + unsigned short imageX; /* x-coordinate of upper-left position of texture (u10.5) */ + unsigned short imageW; /* width of texture (u10.2) */ + short frameX; /* upper-left position of transferred frame (s10.2) */ + unsigned short frameW; /* width of transferred frame (u10.2) */ + + unsigned short imageY; /* y-coordinate of upper-left position of texture (u10.5) */ + unsigned short imageH; /* height of texture (u10.2) */ + short frameY; /* upper-left position of transferred frame (s10.2) */ + unsigned short frameH; /* height of transferred frame (u10.2) */ + + unsigned long long int* imagePtr; /* texture source address on DRAM */ + unsigned short imageLoad; /* Which to use, LoadBlock or LoadTile? */ + unsigned char imageFmt; /* format of texel - G_IM_FMT_* */ + unsigned char imageSiz; /* size of texel - G_IM_SIZ_* */ + unsigned short imagePal; /* pallet number */ + unsigned short imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */ + + unsigned short scaleW; /* scale value of X-direction (u5.10) */ + unsigned short scaleH; /* scale value of Y-direction (u5.10) */ + int imageYorig; /* start point of drawing on image (s20.5) */ + + unsigned char padding[4]; + +} F3DuObjScaleBg_t; /* 40 bytes */ + +typedef union { + F3DuObjBg_t b; + F3DuObjScaleBg_t s; + long long int force_structure_alignment; +} F3DuObjBg; + +/*---------------------------------------------------------------------------* + * 2D Objects + *---------------------------------------------------------------------------*/ +#define G_OBJ_FLAG_FLIPS 1 << 0 /* inversion to S-direction */ +#define G_OBJ_FLAG_FLIPT 1 << 4 /* nversion to T-direction */ + +typedef struct { + short objX; /* s10.2 OBJ x-coordinate of upper-left end */ + unsigned short scaleW; /* u5.10 Scaling of u5.10 width direction */ + unsigned short imageW; /* u10.5 width of u10.5 texture (length of S-direction) */ + unsigned short paddingX; /* Unused - Always 0 */ + short objY; /* s10.2 OBJ y-coordinate of s10.2 OBJ upper-left end */ + unsigned short scaleH; /* u5.10 Scaling of u5.10 height direction */ + unsigned short imageH; /* u10.5 height of u10.5 texture (length of T-direction) */ + unsigned short paddingY; /* Unused - Always 0 */ + unsigned short imageStride; /* folding width of texel (In units of 64bit word) */ + unsigned short imageAdrs; /* texture header position in TMEM (In units of 64bit word) */ + unsigned char imageFmt; /* format of texel - G_IM_FMT_* */ + unsigned char imageSiz; /* size of texel - G_IM_SIZ_* */ + unsigned char imagePal; /* pallet number (0-7) */ + unsigned char imageFlags; /* The display flag - G_OBJ_FLAG_FLIP* */ +} F3DuObjSprite_t; /* 24 bytes */ + +typedef union { + F3DuObjSprite_t s; + long long int force_structure_alignment; +} F3DuObjSprite; + +/*---------------------------------------------------------------------------* + * 2D Matrix + *---------------------------------------------------------------------------*/ +typedef struct { + int A, B, C, D; /* s15.16 */ + short X, Y; /* s10.2 */ + unsigned short BaseScaleX; /* u5.10 */ + unsigned short BaseScaleY; /* u5.10 */ +} F3DuObjMtx_t; /* 24 bytes */ + +typedef union { + F3DuObjMtx_t m; + long long int force_structure_alignment; +} F3DuObjMtx; + +typedef struct { + short X, Y; /* s10.2 */ + unsigned short BaseScaleX; /* u5.10 */ + unsigned short BaseScaleY; /* u5.10 */ +} F3DuObjSubMtx_t; /* 8 bytes */ + +typedef union { + F3DuObjSubMtx_t m; + long long int force_structure_alignment; +} F3DuObjSubMtx; + +/*---------------------------------------------------------------------------* + * Loading into TMEM + *---------------------------------------------------------------------------*/ +#define G_OBJLT_TXTRBLOCK 0x00001033 +#define G_OBJLT_TXTRTILE 0x00fc1034 +#define G_OBJLT_TLUT 0x00000030 + +#define GS_TB_TSIZE(pix, siz) (GS_PIX2TMEM((pix), (siz)) - 1) +#define GS_TB_TLINE(pix, siz) (GS_CALC_DXT(GS_PIX2TMEM((pix), (siz)))) + +typedef struct { + unsigned int type; /* G_OBJLT_TXTRBLOCK divided into types */ + unsigned long long int* image; /* texture source address on DRAM */ + unsigned short tmem; /* loaded TMEM word address (8byteWORD) */ + unsigned short tsize; /* Texture size, Specified by macro GS_TB_TSIZE() */ + unsigned short tline; /* width of Texture 1-line, Specified by macro GS_TB_TLINE() */ + unsigned short sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */ + unsigned int flag; /* STATE flag */ + unsigned int mask; /* STATE mask */ +} F3DuObjTxtrBlock_t; /* 24 bytes */ + +#define GS_TT_TWIDTH(pix, siz) ((GS_PIX2TMEM((pix), (siz)) << 2) - 1) +#define GS_TT_THEIGHT(pix, siz) (((pix) << 2) - 1) + +typedef struct { + unsigned int type; /* G_OBJLT_TXTRTILE divided into types */ + unsigned long long int* image; /* texture source address on DRAM */ + unsigned short tmem; /* loaded TMEM word address (8byteWORD)*/ + unsigned short twidth; /* width of Texture (Specified by macro GS_TT_TWIDTH()) */ + unsigned short theight; /* height of Texture (Specified by macro GS_TT_THEIGHT()) */ + unsigned short sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */ + unsigned int flag; /* STATE flag */ + unsigned int mask; /* STATE mask */ +} F3DuObjTxtrTile_t; /* 24 bytes */ + +#define GS_PAL_HEAD(head) ((head) + 256) +#define GS_PAL_NUM(num) ((num)-1) + +typedef struct { + unsigned int type; /* G_OBJLT_TLUT divided into types */ + unsigned long long int* image; /* texture source address on DRAM */ + unsigned short phead; /* pallet number of load header (Between 256 and 511) */ + unsigned short pnum; /* loading pallet number -1 */ + unsigned short zero; /* Assign 0 all the time */ + unsigned short sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12)*/ + unsigned int flag; /* STATE flag */ + unsigned int mask; /* STATE mask */ +} F3DuObjTxtrTLUT_t; /* 24 bytes */ + +typedef union { + F3DuObjTxtrBlock_t block; + F3DuObjTxtrTile_t tile; + F3DuObjTxtrTLUT_t tlut; + long long int force_structure_alignment; +} F3DuObjTxtr; + +/*---------------------------------------------------------------------------* + * Loading into TMEM & 2D Objects + *---------------------------------------------------------------------------*/ +typedef struct { + F3DuObjTxtr txtr; + F3DuObjSprite sprite; +} F3DuObjTxSprite; /* 48 bytes */ + #endif diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index 52bc7ffbd..fc65792d0 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -1,8 +1,8 @@ #include "resource/factory/DisplayListFactory.h" #include "resource/type/DisplayList.h" #include "spdlog/spdlog.h" -#include "graphic/Fast3D/lus_gbi.h" - +#include "libultraship/libultra/gbi.h" +#if 0 typedef int Mtx_t[4][4]; typedef union { Mtx_t m; @@ -315,7 +315,7 @@ typedef union { #define gsSPLightColor(n, col) gsMoveWd(G_MW_LIGHTCOL, G_MWO_a##n, col), gsMoveWd(G_MW_LIGHTCOL, G_MWO_b##n, col) - +#endif namespace LUS { std::unordered_map renderModes = { { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, { "G_RM_AA_ZB_OPA_SURF", G_RM_AA_ZB_OPA_SURF }, @@ -431,7 +431,7 @@ uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(std::string valStr) { G_ACMUX_LOD_FRACTION, G_ACMUX_PRIM_LOD_FRAC }; - for (int i = 0; i < ARRAY_COUNT(values); i++) { + for (size_t i = 0; i < std::size(values); i++) { if (valStr == strings[i]) { return values[i]; } diff --git a/src/window/gui/GfxDebuggerWindow.cpp b/src/window/gui/GfxDebuggerWindow.cpp index b78f11f22..cd99d413c 100644 --- a/src/window/gui/GfxDebuggerWindow.cpp +++ b/src/window/gui/GfxDebuggerWindow.cpp @@ -24,8 +24,9 @@ void GfxDebuggerWindow::InitElement() { void GfxDebuggerWindow::UpdateElement() { } -static const char* GetOpName(uint32_t op) { +static const char* GetOpName(int8_t op) { switch (op) { + #if 0 #define CASE(x) \ case x: \ return #x @@ -99,6 +100,7 @@ static const char* GetOpName(uint32_t op) { CASE(G_CULLDL); CASE(G_IMAGERECT); CASE(G_COPYFB); + #endif default: return nullptr; // return "UNKNOWN"; @@ -154,10 +156,10 @@ void GfxDebuggerWindow::DrawDisasNode(const F3DGfx* cmd, std::vectorwords.w0 >> 24; + int8_t opcode = (int8_t)(cmd->words.w0 >> 24); node_with_text(cmd, fmt::format("UNK: 0x{:X}", opcode)); } }; while (true) { - uint32_t opcode = cmd->words.w0 >> 24; + int8_t opcode = (int8_t)(cmd->words.w0 >> 24); const F3DGfx* cmd0 = cmd; switch (opcode) { - case G_NOOP: { + case F3DEX2_G_NOOP: { const char* filename = (const char*)cmd->words.w1; uint32_t p = C0(16, 8); uint32_t l = C0(0, 16); @@ -209,7 +211,7 @@ void GfxDebuggerWindow::DrawDisasNode(const F3DGfx* cmd, std::vectorwords.w0 << 32) + cmd->words.w1; const char* dlName = ResourceGetNameByCrc(hash); @@ -221,7 +223,7 @@ void GfxDebuggerWindow::DrawDisasNode(const F3DGfx* cmd, std::vectorwords.w0 << 32) + cmd->words.w1; const char* name = ResourceGetNameByCrc(hash); @@ -255,7 +257,7 @@ void GfxDebuggerWindow::DrawDisasNode(const F3DGfx* cmd, std::vectorwords.w0 << 32) + cmd->words.w1; const char* name = ResourceGetNameByCrc(hash); @@ -269,7 +271,7 @@ void GfxDebuggerWindow::DrawDisasNode(const F3DGfx* cmd, std::vectorwords.w1); if (C0(16, 1) == 0) { node_with_text(cmd0, fmt::format("G_DL: 0x{:x} -> {}", cmd->words.w1, (void*)subGFX), subGFX); @@ -282,30 +284,30 @@ void GfxDebuggerWindow::DrawDisasNode(const F3DGfx* cmd, std::vectorwords.w1)); cmd++; break; } - case G_COPYFB: { + case OTR_G_COPYFB: { node_with_text(cmd0, fmt::format("G_COPYFB: src {}, dest {}, new frames only {}", C0(0, 11), C0(11, 11), C0(22, 1))); cmd++;