OVR: Add patch to make game render planets behind observer
authorAndreas Eversberg <jolly@eversberg.eu>
Sat, 14 Apr 2018 12:12:36 +0000 (14:12 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sat, 14 Apr 2018 12:12:36 +0000 (14:12 +0200)
src/mercenary/mercenary.h
src/mercenary/mercenary2.c
src/mercenary/mercenary3.c
src/mercenary/render.c

index c3c2a92..b65b54e 100644 (file)
@@ -2,6 +2,7 @@
 /* cause why the cpu execution loop stopped */
 enum {
        STOP_AT_END = 0,
+       STOP_AT_PATCH_RENDER,
        STOP_AT_WAIT_VBL,
        STOP_AT_WAIT_INPUT,
        STOP_AT_CLEAR_SCREEN1,
@@ -66,6 +67,7 @@ enum {
 extern const struct cpu_stop mercenary_stop_at[];
 void mercenary_load(void);
 void mercenary_patch(void);
+void mercenary_patch_render(void);
 uint32_t mercenary_palette_view(void);
 uint32_t mercenary_palette_render(void);
 uint32_t mercenary_palette_predefined(void);
index 47b8af5..bfba01e 100644 (file)
@@ -104,6 +104,9 @@ const struct cpu_stop mercenary_stop_at[] = {
        { 0x511FE,      STOP_AT_DRAW_SIGHTS },                  /* when sights are rendered */
        { 0x5351A,      STOP_AT_EXPLOSION },                    /* explosion debris */
        { 0x4C514,      STOP_AT_EXPLOSION },
+       { 0x52C42,      STOP_AT_PATCH_RENDER },                 /* patch away planet check (behind observer) */
+       { 0x528C4,      STOP_AT_PATCH_RENDER },                 /* patch away planet check (behind observer) */
+       { 0x45806,      STOP_AT_PATCH_RENDER },                 /* patch away planet rendering (would crash without check above) */
        { 0x0,          STOP_AT_END },                          /* end */
 };
 
@@ -157,6 +160,22 @@ void mercenary_patch(void)
        m68k_write_memory_32(0x54ffc, 1);
 }
 
+/* skip certain parts when rendering improved graphics */
+void mercenary_patch_render(void)
+{
+       switch (REG_PC) {
+       case 0x52C42: /* take that branch, so planets get rendered behind obersver */
+               REG_PC += 10;
+               break;
+       case 0x528C4: /* take that branch, so planets get rendered behind obersver */
+               REG_PC += 10;
+               break;
+       case 0x45806: /* just RTS to avoid crashing of rendering functions when planets are behind obersver */
+               REG_PC -= 2;
+               break;
+       }
+}
+
 uint32_t mercenary_palette_view(void)
 {
        return m68k_read_memory_32(0x007c14);
index 28751e2..7fe20c2 100644 (file)
@@ -110,6 +110,9 @@ const struct cpu_stop mercenary_stop_at[] = {
        { 0x4F748,      STOP_AT_POLY_UKN2 },
        { 0x54362,      STOP_AT_EXPLOSION },                    /* explosion debris */
        { 0x4CA18,      STOP_AT_EXPLOSION },
+       { 0x53A6C,      STOP_AT_PATCH_RENDER },                 /* patch away planet check (behind observer) */
+       { 0x537B0,      STOP_AT_PATCH_RENDER },                 /* patch away planet check (behind observer) */
+       { 0x45806,      STOP_AT_PATCH_RENDER },                 /* patch away planet rendering (would crash without check above) */
        { 0x0,          STOP_AT_END },                          /* end */
 };
 
@@ -158,9 +161,10 @@ void mercenary_patch(void)
 //m68k_write_memory_16(0x58388, 0x4E75); /* rts */
 //m68k_write_memory_16(0x4FE3E, 0x4E75); /* rts */
 
-//test: loesche mit index 0
-//m68k_write_memory_16(0x5ABC2, 0x4e71); /* nop */
-//
+//m68k_write_memory_16(0x53A6C, 0x6008); /* bra */
+//m68k_write_memory_16(0x537B0, 0x6008); /* bra */
+//m68k_write_memory_16(0x45806, 0x4E75); /* rts */
+
 //m68k_write_memory_16(0x54342, 0x4e71); /* nop */
 //m68k_write_memory_16(0x54344, 0x4e71); /* nop */
 //m68k_write_memory_16(0x5059e, 0x3f0); /* nop */
@@ -192,6 +196,22 @@ m68k_write_memory_16(0x4FB6c, 0x4e71); /* nop */
        m68k_write_memory_32(0x55f5c, 1);
 }
 
+/* skip certain parts when rendering improved graphics */
+void mercenary_patch_render(void)
+{
+       switch (REG_PC) {
+       case 0x53A6C: /* take that branch, so planets get rendered behind obersver */
+               REG_PC += 10;
+               break;
+       case 0x537B0: /* take that branch, so planets get rendered behind obersver */
+               REG_PC += 10;
+               break;
+       case 0x45806: /* just RTS to avoid crashing of rendering functions when planets are behind obersver */
+               REG_PC -= 2;
+               break;
+       }
+}
+
 uint32_t mercenary_palette_view(void)
 {
        return m68k_read_memory_32(0x0072b0);
index f4af63c..8f0b140 100644 (file)
@@ -1472,6 +1472,9 @@ void render_capture_event(int event)
        case STOP_AT_EXPLOSION:
                draw_explosion();
                break;
+       case STOP_AT_PATCH_RENDER:
+               mercenary_patch_render();
+               break;
        }
 }