From 78e6ee8b4eeb8bd13e1babc630c5c7ad1dbaae9d Mon Sep 17 00:00:00 2001 From: farisawan-2000 Date: Mon, 31 May 2021 03:05:52 -0400 Subject: [PATCH] added emulator check --- config.h | 6 +----- f3d_draw.c | 17 ++++------------- init.c | 7 +++---- s2d_draw.c | 17 +++++------------ s2d_parse.c | 15 ++++++++------- 5 files changed, 21 insertions(+), 41 deletions(-) diff --git a/config.h b/config.h index a2501026..66d56006 100644 --- a/config.h +++ b/config.h @@ -13,8 +13,6 @@ * Helpful defines to change ***********/ -#define DRAW_F3D - #define BASE_SCALE 1.0f /****************************** @@ -87,10 +85,8 @@ extern char *proutSprintf(char *dst, const char *src, size_t count); #define TEX_HEIGHT 16 #define TEX_BITDEPTH 8 -#define glyph_draw draw_f3d_glyph -#define glyph_shadow draw_f3d_dropshadow - #define seg2virt segmented_to_virtual +#define IS_RUNNING_ON_EMULATOR (IO_READ(DPC_PIPEBUSY_REG) == 0) // Texture resolution (pixels on the texture per pixel on the framebuffer) #define TEX_RES 1 diff --git a/f3d_draw.c b/f3d_draw.c index fd0654bd..c4cd9e46 100644 --- a/f3d_draw.c +++ b/f3d_draw.c @@ -1,17 +1,10 @@ #include "config.h" -#ifdef DRAW_F3D #include #include "mtx.h" #include "debug.h" -float myScale = 1.0f; -int myDegrees = 0; -uObjMtx final_mtx, rot_mtx; -int s2d_red = 255, s2d_green = 255, s2d_blue = 255, s2d_alpha = 255; -int drop_shadow = FALSE; -int drop_x = 0; -int drop_y = 0; +#include "s2d_draw.h" #define s(sprite) ((uObjSprite *)seg2virt(&sprite)) #define t(texture) ((uObjTxtr *)seg2virt(&texture)) @@ -30,7 +23,7 @@ void f3d_rdp_init(void) { ); } -void setup_font_texture(int idx) { +void setup_f3d_texture(int idx) { gDPPipeSync(gdl_head++); @@ -70,7 +63,7 @@ void texrect(int x, int y, float scale) { } void draw_f3d_dropshadow(char c, int x, int y, uObjMtx *ds) { - setup_font_texture(c); + setup_f3d_texture(c); if (s2d_red != 0 && s2d_green != 0 @@ -89,7 +82,7 @@ void draw_f3d_dropshadow(char c, int x, int y, uObjMtx *ds) { } void draw_f3d_glyph(char c, int x, int y, uObjMtx *mt) { - setup_font_texture(c); + setup_f3d_texture(c); texrect(x, y, myScale); gDPPipeSync(gdl_head++); @@ -97,5 +90,3 @@ void draw_f3d_glyph(char c, int x, int y, uObjMtx *mt) { #undef s #undef t - -#endif diff --git a/init.c b/init.c index 321db619..64bbe106 100644 --- a/init.c +++ b/init.c @@ -7,19 +7,18 @@ void s2d_init(void) { s2d_error_y = TEX_HEIGHT; - #ifdef DRAW_S2D + if (IS_RUNNING_ON_EMULATOR) gSPLoadUcode(gdl_head++, s2d_text, s2d_data); - #endif } void s2d_stop(void) { - #ifdef DRAW_S2D + if (IS_RUNNING_ON_EMULATOR) { gSPLoadUcode(gdl_head++, zex_text, zex_data); if deinit_cond { my_rdp_init(); my_rsp_init(); } - #endif + } s2d_reset_defer_index(); } diff --git a/s2d_draw.c b/s2d_draw.c index 47c48c31..2be848fa 100644 --- a/s2d_draw.c +++ b/s2d_draw.c @@ -1,5 +1,4 @@ #include "config.h" -#ifdef DRAW_S2D #include #include "mtx.h" #include "debug.h" @@ -21,8 +20,6 @@ Gfx s2d_text_init_dl[] = { gsDPSetAlphaCompare(G_AC_THRESHOLD), gsDPSetBlendColor(0, 0, 0, 0x01), - // IA8 - // TODO: add more formats gsDPSetCombineLERP( 0, 0, 0, ENVIRONMENT, 0, 0, 0, TEXEL0, @@ -44,17 +41,15 @@ void s2d_rdp_init(void) { } } -void setup_font_texture(int idx) { +void setup_s2d_texture(int idx) { gDPPipeSync(gdl_head++); gDPSetEnvColor(gdl_head++, s2d_red, s2d_green, s2d_blue, s2d_alpha); gSPObjLoadTxtr(gdl_head++, &s2d_tex[idx]); } -// Original Mtx Pipeline -// Distorts when rotating, but is faster void mtx_pipeline(uObjMtx *m, int x, int y) { - // init gDPPipeSync(gdl_head++); + mat2_ident(m, 1.0f / myScale); mat2_translate(m, x, y); @@ -63,9 +58,9 @@ void mtx_pipeline(uObjMtx *m, int x, int y) { #define CLAMP_0(x) ((x < 0) ? 0 : x) -void draw_s2d_shadow(char c, int x, int y, uObjMtx *ds) { +void draw_s2d_dropshadow(char c, int x, int y, uObjMtx *ds) { if (mtx_cond) mtx_pipeline(ds, x, y); - if (tex_cond) setup_font_texture(c); + if (tex_cond) setup_s2d_texture(c); if (s2d_red != 0 && s2d_green != 0 @@ -84,10 +79,8 @@ void draw_s2d_shadow(char c, int x, int y, uObjMtx *ds) { void draw_s2d_glyph(char c, int x, int y, uObjMtx *mt) { if (mtx_cond) mtx_pipeline(mt, x, y); - if (tex_cond) setup_font_texture(c); - // mtx_pipeline2(mt, x, y); + if (tex_cond) setup_s2d_texture(c); if (spr_cond) gSPObjRectangleR(gdl_head++, &s2d_font); } -#endif diff --git a/s2d_parse.c b/s2d_parse.c index 5baecaf5..104cd8de 100644 --- a/s2d_parse.c +++ b/s2d_parse.c @@ -27,11 +27,10 @@ static int s2d_snprint(int x, int y, int align, const char *str, uObjMtx *buf, i if (*p == '\0') return; - #ifdef DRAW_S2D + if (IS_RUNNING_ON_EMULATOR) s2d_rdp_init(); - #else + else f3d_rdp_init(); - #endif // resets parameters s2d_red = s2d_green = s2d_blue = 255; @@ -166,10 +165,12 @@ static int s2d_snprint(int x, int y, int align, const char *str, uObjMtx *buf, i if (current_char != '\0' && current_char != CH_SEPARATOR) { char *tbl = segmented_to_virtual(s2d_kerning_table); - if (drop_shadow && mode == MODE_DRAW_DROPSHADOW) { - glyph_shadow(current_char, x + drop_x, y + drop_y, (buf++)); - } else if (mode == MODE_DRAW_NORMALTEXT) { - glyph_draw(current_char, x, y, (buf++)); + if (IS_RUNNING_ON_EMULATOR) { + if (drop_shadow && mode == MODE_DRAW_DROPSHADOW) { + draw_s2d_dropshadow(current_char, x + drop_x, y + drop_y, (buf++)); + } else if (mode == MODE_DRAW_NORMALTEXT) { + draw_s2d_glyph(current_char, x, y, (buf++)); + } } (x += (tbl[(int) current_char] * (BASE_SCALE * myScale))); }