shithub: zelda3

Download patch

ref: 44514855c603d63fc11d3b864d72feab5e2f9cb6
parent: 10fbd868af38da0b420da8a0c5c277d68ed3d204
author: Snesrev <snesrev@protonmail.com>
date: Thu Sep 22 07:26:39 EDT 2022

Added 'ShowMaxItemsInYellow'

--- a/ancilla.c
+++ b/ancilla.c
@@ -5752,7 +5752,7 @@
 uint8 Ancilla_SetOam_XY(OamEnt *oam, uint16 x, uint16 y) {  // 88f6e1
   uint8 rv = 0;
   uint8 yval = 0xf0;
-  int xt = (g_ram[kRam_Features0] & kFeatures0_ExtendScreen64) ? 0x40 : 0;
+  int xt = enhanced_features0 ? 0x40 : 0;
   if ((uint16)(x + xt) < 256 + xt * 2 && y < 256) {
     rv = (x >> 8) & 1;
     oam->x = x;
@@ -7307,7 +7307,7 @@
 }
 
 void Ancilla_TerminateIfOffscreen(int j) {  // 8ffd52
-  int xt = (g_ram[kRam_Features0] & kFeatures0_ExtendScreen64) ? 0x40 : 0;
+  int xt = (enhanced_features0 & kFeatures0_ExtendScreen64) ? 0x40 : 0;
   uint16 x = Ancilla_GetX(j) - BG2HOFS_copy2 + xt;
   uint16 y = Ancilla_GetY(j) - BG2VOFS_copy2;
   if (x >= 244 + xt * 2 || y >= 240)
--- a/config.c
+++ b/config.c
@@ -294,7 +294,12 @@
     } else if (StringEqualsNoCase(key, "SkipIntroOnKeypress")) {
       g_config.skip_intro_on_keypress = (bool)strtol(value, (char **)NULL, 10);
       return true;
+    } else if (StringEqualsNoCase(key, "ShowMaxItemsInYellow")) {
+      g_config.show_max_items_in_yellow = (bool)strtol(value, (char **)NULL, 10);
+      return true;
     }
+
+    
   }
   return false;
 }
--- a/config.h
+++ b/config.h
@@ -54,6 +54,7 @@
   bool break_pots_with_sword;
   bool disable_low_health_beep;
   bool skip_intro_on_keypress;
+  bool show_max_items_in_yellow;
 } Config;
 
 extern Config g_config;
--- a/hud.c
+++ b/hud.c
@@ -1347,17 +1347,28 @@
   uint8 d[3];
 
   Hud_IntToDecimal(link_rupees_actual, d);
-  hud_tile_indices_buffer[0x28] = 0x2400 | d[0];
-  hud_tile_indices_buffer[0x29] = 0x2400 | d[1];
-  hud_tile_indices_buffer[0x2A] = 0x2400 | d[2];
 
+
+  const uint16 base_tiles[2] = {
+    0x2400,
+    (enhanced_features0 & kFeatures0_ShowMaxItemsInYellow) ? 0x3400 : 0x2400,
+  };
+
+  int base_tile = base_tiles[link_rupees_actual == 999];
+  hud_tile_indices_buffer[0x28] = base_tile | d[0];
+  hud_tile_indices_buffer[0x29] = base_tile | d[1];
+  hud_tile_indices_buffer[0x2A] = base_tile | d[2];
+
   Hud_IntToDecimal(link_item_bombs, d);
-  hud_tile_indices_buffer[0x2C] = 0x2400 | d[1];
-  hud_tile_indices_buffer[0x2D] = 0x2400 | d[2];
+  base_tile = base_tiles[link_item_bombs == kMaxBombsForLevel[link_bomb_upgrades]];
 
+  hud_tile_indices_buffer[0x2C] = base_tile | d[1];
+  hud_tile_indices_buffer[0x2D] = base_tile | d[2];
+
   Hud_IntToDecimal(link_num_arrows, d);
-  hud_tile_indices_buffer[0x2F] = 0x2400 | d[1];
-  hud_tile_indices_buffer[0x30] = 0x2400 | d[2];
+  base_tile = base_tiles[link_num_arrows == kMaxArrowsForLevel[link_arrow_upgrades]];
+  hud_tile_indices_buffer[0x2F] = base_tile | d[1];
+  hud_tile_indices_buffer[0x30] = base_tile | d[2];
 
   d[2] = 0x7f;
   if (link_num_keys != 0xff)
--- a/main.c
+++ b/main.c
@@ -194,6 +194,7 @@
     f |= g_config.break_pots_with_sword * kFeatures0_BreakPotsWithSword;
     f |= g_config.disable_low_health_beep * kFeatures0_DisableLowHealthBeep;
     f |= g_config.skip_intro_on_keypress * kFeatures0_SkipIntroOnKeypress;
+    f |= g_config.show_max_items_in_yellow * kFeatures0_ShowMaxItemsInYellow;
     g_wanted_zelda_features = f;
   }
 
--- a/sprite.c
+++ b/sprite.c
@@ -1867,7 +1867,7 @@
   R2 = y - sprite_z[k];
   ret->flags = sprite_oam_flags[k] ^ sprite_obj_prio[k];
   ret->r4 = 0;
-  int xt = (g_ram[kRam_Features0] & kFeatures0_ExtendScreen64) ? 0x40 : 0;
+  int xt = (enhanced_features0 & kFeatures0_ExtendScreen64) ? 0x40 : 0;
 
   if ((uint16)(x + 0x40 + xt) >= (0x170 + xt * 2) ||
       (uint16)(y + 0x40) >= 0x170 && !(sprite_flags4[k] & 0x20)) {
@@ -3841,7 +3841,7 @@
   uint8 bak1 = byte_7E069E[1];
   byte_7E069E[1] = 0xff;
 
-  int xt = (g_ram[kRam_Features0] & kFeatures0_ExtendScreen64) ? 0x40 : 0;
+  int xt = (enhanced_features0 & kFeatures0_ExtendScreen64) ? 0x40 : 0;
   BG2HOFS_copy2 -= xt;
   for (int i = 21 + (xt >> 3); i >= 0; i--) {
     Sprite_ActivateWhenProximal();
@@ -3866,7 +3866,7 @@
 
 void Sprite_ActivateWhenProximal() {  // 89c5bb
   if (byte_7E069E[1]) {
-    int xt = (g_ram[kRam_Features0] & kFeatures0_ExtendScreen64) ? 0x40 : 0;
+    int xt = (enhanced_features0 & kFeatures0_ExtendScreen64) ? 0x40 : 0;
     uint16 x = BG2HOFS_copy2 + (sign8(byte_7E069E[1]) ? -0x10 - xt : 0x110 + xt);
     uint16 y = BG2VOFS_copy2 - 0x30;
     for (int i = 21; i >= 0; i--, y += 16)
@@ -3876,7 +3876,7 @@
 
 void Sprite_ActivateWhenProximalBig() {  // 89c5fa
   if (byte_7E069E[0]) {
-    int xt = (g_ram[kRam_Features0] & kFeatures0_ExtendScreen64) ? 0x40 : 0;
+    int xt = (enhanced_features0 & kFeatures0_ExtendScreen64) ? 0x40 : 0;
     uint16 x = BG2HOFS_copy2 - 0x30 - xt;
     uint16 y = BG2VOFS_copy2 + (sign8(byte_7E069E[0]) ? -0x10 : 0x110);
     for (int i = 21 + (xt >> 3); i >= 0; i--, x += 16)
--- a/variables.h
+++ b/variables.h
@@ -1420,3 +1420,6 @@
 #define R18 (*(uint16*)(g_ram+0xca))
 #define R20 (*(uint16*)(g_ram+0xcc))
 
+// Relocated the hdma table so it can fit 240 rows
+#define hdma_table_dynamic_orig_pos ((uint16*)(g_ram+0x1B00))
+#define hdma_table_dynamic ((uint16*)(g_ram+0x1DBA0))
--- a/zelda3.ini
+++ b/zelda3.ini
@@ -60,6 +60,9 @@
 # Avoid waiting too much at the start
 SkipIntroOnKeypress = 0
 
+# Display max rupees/bombs/arrows with orange/yellow color
+ShowMaxItemsInYellow = 0
+
 [KeyMap]
 # Change what keyboard keys map to the joypad
 # Order: Up, Down, Left, Right, Select, Start, A, B, X, Y, L, R
--- a/zelda_cpu_infra.c
+++ b/zelda_cpu_infra.c
@@ -722,9 +722,9 @@
         StateRecorder_RecordPatchByte(&state_recorder, kRam_BugsFixed, &g_ram[kRam_BugsFixed], 1);
       }
 
-      if (g_ram[kRam_Features0] != g_wanted_zelda_features) {
-        g_emulated_ram[kRam_Features0] = g_ram[kRam_Features0] = g_wanted_zelda_features;
-        StateRecorder_RecordPatchByte(&state_recorder, kRam_Features0, &g_ram[kRam_Features0], 1);
+      if (enhanced_features0 != g_wanted_zelda_features) {
+        *(uint32*)&g_emulated_ram[kRam_Features0] = enhanced_features0 = g_wanted_zelda_features;
+        StateRecorder_RecordPatchByte(&state_recorder, kRam_Features0, (uint8*)&enhanced_features0, 4);
       }
     }
   }
@@ -742,7 +742,7 @@
     g_emulated_ram[kRam_CrystalRotateCounter] = g_ram[kRam_CrystalRotateCounter];
   }
   
-  if (snes == NULL || g_ram[kRam_Features0] != 0) {
+  if (snes == NULL || enhanced_features0 != 0) {
     // can't compare against real impl when running with extra features.
     ZeldaRunFrame(input_state, run_what);
     return turbo;
--- a/zelda_rtl.h
+++ b/zelda_rtl.h
@@ -122,6 +122,7 @@
   kFeatures0_BreakPotsWithSword = 32,
   kFeatures0_DisableLowHealthBeep = 64,
   kFeatures0_SkipIntroOnKeypress = 128,
+  kFeatures0_ShowMaxItemsInYellow = 256,
 };
 
 #define enhanced_features0 (*(uint32*)(g_ram+0x64c))
@@ -129,91 +130,11 @@
 #define msu_volume (*(uint8*)(g_ram+0x654))
 #define msu_track (*(uint8*)(g_ram+0x655))
 #define hud_cur_item_x (*(uint8*)(g_ram+0x656))
-
-
 #define hud_inventory_order ((uint8*)(g_ram + 0x225)) // 4x6 bytes
 
 extern uint32 g_wanted_zelda_features;
+extern bool msu_enabled;
 
-#define scratch_0 (*(uint16*)(g_ram+0x72))
-#define scratch_1 (*(uint16*)(g_ram+0x74))
-#define srm_var1 (*(uint16*)(g_zenv.sram+0x1ffe))
-#define messaging_buf ((uint16*)(g_ram+0x10000))
-#define quake_arr1 ((uint8*)(g_ram+0x15800))
-#define quake_arr2 ((uint8*)(g_ram+0x15805))
-#define quake_var5 (*(uint8*)(g_ram+0x1580A))
-#define quake_var1 (*(uint16*)(g_ram+0x1580B))
-#define quake_var2 (*(uint16*)(g_ram+0x1580D))
-#define quake_var4 (*(uint8*)(g_ram+0x1580F))
-#define ether_y3 (*(uint16*)(g_ram+0x15810))
-#define ether_var1 (*(uint8*)(g_ram+0x15812))
-#define ether_y (*(uint16*)(g_ram+0x15813))
-#define ether_x (*(uint16*)(g_ram+0x15815))
-#define quake_var3 (*(uint16*)(g_ram+0x1581E))
-#define bombos_arr7 ((uint8*)(g_ram+0x15820))
-#define bombos_y_lo ((uint8*)(g_ram+0x15824))
-#define bombos_y_hi ((uint8*)(g_ram+0x15864))
-#define bombos_x_lo ((uint8*)(g_ram+0x158A4))
-#define bombos_x_hi ((uint8*)(g_ram+0x158E4))
-#define bombos_y_coord2 ((uint16*)(g_ram+0x15924))
-#define bombos_x_coord2 ((uint16*)(g_ram+0x1592C))
-#define bombos_var4 (*(uint8*)(g_ram+0x15934))
-#define bombos_arr3 ((uint8*)(g_ram+0x15935))
-#define bombos_arr4 ((uint8*)(g_ram+0x15945))
-#define bombos_y_coord ((uint16*)(g_ram+0x15955))
-#define bombos_x_coord ((uint16*)(g_ram+0x159D5))
-#define bombos_var3 (*(uint8*)(g_ram+0x15A55))
-#define bombos_var2 (*(uint8*)(g_ram+0x15A56))
-#define bombos_var1 (*(uint8*)(g_ram+0x15A57))
-
-#define happiness_pond_y_vel ((uint8*)(g_ram+0x15800))
-#define happiness_pond_x_vel ((uint8*)(g_ram+0x1580C))
-#define happiness_pond_z_vel ((uint8*)(g_ram+0x15818))
-#define happiness_pond_y_lo ((uint8*)(g_ram+0x15824))
-#define happiness_pond_y_hi ((uint8*)(g_ram+0x15830))
-#define happiness_pond_x_lo ((uint8*)(g_ram+0x1583C))
-#define happiness_pond_x_hi ((uint8*)(g_ram+0x15848))
-#define happiness_pond_z ((uint8*)(g_ram+0x15854))
-#define happiness_pond_timer ((uint8*)(g_ram+0x15860))
-#define happiness_pond_arr1 ((uint8*)(g_ram+0x1586C))
-#define happiness_pond_item_to_link ((uint8*)(g_ram+0x1587A))
-#define happiness_pond_y_subpixel ((uint8*)(g_ram+0x15886))
-#define happiness_pond_x_subpixel ((uint8*)(g_ram+0x15892))
-#define happiness_pond_z_subpixel ((uint8*)(g_ram+0x1589E))
-#define happiness_pond_step ((uint8*)(g_ram+0x158AA))
-
-
-#define turn_on_off_water_ctr (*(uint8*)(g_ram+0x424))
-#define mirror_vars (*(MirrorHdmaVars*)(g_ram+0x6A0))
-#define sprite_N_word ((uint16*)(g_ram+0xBC0))
-#define sprite_where_in_overworld ((uint8*)(g_ram+0x1DF80))
-#define alt_sprite_B ((uint8*)(g_ram+0x1FA5C))
-#define uvram_screen (*(UploadVram_32x32*)&g_ram[0x1000])
-#define vram_upload_offset (*(uint16*)(g_ram+0x1000))
-#define vram_upload_data ((uint16*)(g_ram+0x1002))
-#define vram_upload_tile_buf ((uint16*)(g_ram+0x1100))
-#define overworld_entrance_sequence_counter (*(uint8*)(g_ram+0xc8))
-
-#ifndef overworld_tileattr
-#define overworld_tileattr ((uint16*)(g_ram+0x2000))
-#endif
-#define dung_line_ptrs_row0 (*(uint16*)(g_ram+0xbf))
-#define star_shaped_switches_tile ((uint16*)(g_ram+0x6A0))
-#define dung_inter_starcases ((uint16*)(g_ram+0x6B0))
-#define dung_stairs_table_1 ((uint16*)(g_ram+0x6B8))
-#define selectfile_var8 (*(uint16*)(g_ram+0x630))
-
-#define R10 (*(uint16*)(g_ram+10))
-#define R12 (*(uint16*)(g_ram+12))
-#define R14 (*(uint16*)(g_ram+14))
-#define R16 (*(uint16*)(g_ram+0xc8))
-#define R18 (*(uint16*)(g_ram+0xca))
-#define R20 (*(uint16*)(g_ram+0xcc))
-
-// Relocated the hdma table so it can fit 240 rows
-#define hdma_table_dynamic_orig_pos ((uint16*)(g_ram+0x1B00))
-#define hdma_table_dynamic ((uint16*)(g_ram+0x1DBA0))
-
 void zelda_apu_write(uint32_t adr, uint8_t val);
 void zelda_apu_write_word(uint32_t adr, uint16_t val);
 uint8_t zelda_read_apui00();
@@ -242,6 +163,5 @@
 void ZeldaOpenMsuFile();
 bool ZeldaIsMusicPlaying();
 
-extern bool msu_enabled;
 
 #endif  // ZELDA_RTL_H