From 3b3ccf7fbf075f4477153288671ca8cddde36f06 Mon Sep 17 00:00:00 2001 From: DPS2004 <10176105+DPS2004@users.noreply.github.com> Date: Wed, 12 Jul 2023 02:58:42 -0400 Subject: [PATCH 1/6] initial messy implementation missing the ability to turn on/off via config, and some code cleanup --- config.c | 2 ++ features.h | 7 +++++ player.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++----- zelda3.ini | 7 +++-- 4 files changed, 93 insertions(+), 9 deletions(-) diff --git a/config.c b/config.c index 5ba0f5c2..f5224ce8 100644 --- a/config.c +++ b/config.c @@ -475,6 +475,8 @@ static bool HandleIniConfig(int section, const char *key, char *value) { return ParseBoolBit(value, &g_config.features0, kFeatures0_GameChangingBugFixes); } else if (StringEqualsNoCase(key, "CancelBirdTravel")) { return ParseBoolBit(value, &g_config.features0, kFeatures0_CancelBirdTravel); + } else if (StringEqualsNoCase(key, "QuickSpin")) { + return ParseBoolBit(value, &g_config.features0, kFeatures0_QuickSpin); } } return false; diff --git a/features.h b/features.h index eff4cafa..5d1e6508 100644 --- a/features.h +++ b/features.h @@ -46,6 +46,8 @@ enum { kFeatures0_SwitchLRLimit = 32768, kFeatures0_DimFlashes = 65536, + + kFeatures0_QuickSpin = 262144, }; #define enhanced_features0 (*(uint32*)(g_ram+0x64c)) @@ -56,6 +58,11 @@ enum { #define hud_cur_item_x (*(uint8*)(g_ram+0x656)) #define hud_cur_item_l (*(uint8*)(g_ram+0x657)) #define hud_cur_item_r (*(uint8*)(g_ram+0x658)) +#define quickspin_timer_up (*(uint8*)(g_ram+0x659)) +#define quickspin_timer_down (*(uint8*)(g_ram+0x65a)) +#define quickspin_timer_left (*(uint8*)(g_ram+0x65b)) +#define quickspin_timer_right (*(uint8*)(g_ram+0x65c)) +#define quickspin_is_ready (*(bool*)(g_ram+0x65d)) diff --git a/player.c b/player.c index 2ed9b5e1..41f32321 100644 --- a/player.c +++ b/player.c @@ -1970,6 +1970,7 @@ void Link_HandleSwordCooldown() { // 879ac2 } else { HandleSwordControls(); } + quickspin_is_ready = false; } @@ -2133,6 +2134,7 @@ void Link_APress_PerformBasic(uint8 action_x2) { // 879c5f } void HandleSwordSfxAndBeam() { // 879c66 + link_direction &= ~0xf; button_b_frames = 0; link_spin_attack_step_counter = 0; @@ -2165,10 +2167,19 @@ void Link_CheckForSwordSwing() { // 879cd9 if ((R14 & 0x30) == 0x30) return; } - button_mask_b_y |= 0x80; - HandleSwordSfxAndBeam(); - link_cant_change_direction |= 1; - link_animation_steps = 0; + + if(quickspin_is_ready){ + Link_ResetSwordAndItemUsage(); + Link_ActivateSpinAttack(); + //fprintf(stderr,"performed quickspin\n"); + } else { + + + button_mask_b_y |= 0x80; + HandleSwordSfxAndBeam(); + link_cant_change_direction |= 1; + link_animation_steps = 0; + } } if (!(joypad1H_last & kJoypadH_B)) @@ -5754,11 +5765,72 @@ void Link_HandleVelocity() { // 87e245 static const uint8 kSpeedMod[27] = { 24, 16, 10, 24, 16, 8, 8, 4, 12, 16, 9, 25, 20, 13, 16, 8, 64, 42, 16, 8, 4, 2, 48, 24, 32, 21, 0 }; uint8 vel = link_speed_modifier + kSpeedMod[r0]; - if (link_direction & 3) + if (link_direction & 3){ link_actual_vel_x = (link_direction & 2) ? -vel : vel; - if (link_direction & 0xC) + } + if (link_direction & 0xC){ link_actual_vel_y = (link_direction & 8) ? -vel : vel; - + } + + //----------- QUICK SPIN -------------- + + // convert velocity to signed ints + int velx = link_actual_vel_x; + int vely = link_actual_vel_y; + if(velx >= 127){ + velx -= 256; + } + if(vely >= 127){ + vely -= 256; + } + //fprintf(stderr, "x: %d y: %d\n",velx,vely); + + //check for directions + + uint8 quickspin_timer_duration = 24; + + if(vely < 0){ + quickspin_timer_up = quickspin_timer_duration; + } + if(vely > 0){ + quickspin_timer_down = quickspin_timer_duration; + } + if(velx < 0){ + quickspin_timer_left = quickspin_timer_duration; + } + if(velx > 0){ + quickspin_timer_right = quickspin_timer_duration; + } + + //decrement timers + + uint8 quickspin_timer_count = 0; + + if(quickspin_timer_up > 0){ + quickspin_timer_up--; + quickspin_timer_count++; + } + if(quickspin_timer_down > 0){ + quickspin_timer_down--; + quickspin_timer_count++; + } + if(quickspin_timer_left > 0){ + quickspin_timer_left--; + quickspin_timer_count++; + } + if(quickspin_timer_right > 0){ + quickspin_timer_right--; + quickspin_timer_count++; + } + //fprintf(stderr, "U: %d | D: %d | L: %d | R: %d | T: %d |\n", quickspin_timer_up,quickspin_timer_down,quickspin_timer_left,quickspin_timer_right, quickspin_timer_count); + if(quickspin_timer_count == 4){ + //fprintf(stderr, "Can quickspin!\n"); + quickspin_is_ready = true; + //Link_ActivateSpinAttack(); + } + + + //-------------- END QUICKSPIN ------------------- link_actual_vel_z = 0xff; link_z_coord = 0xffff; link_subpixel_z = 0; diff --git a/zelda3.ini b/zelda3.ini index 807d180c..03135464 100644 --- a/zelda3.ini +++ b/zelda3.ini @@ -137,6 +137,9 @@ GameChangingBugFixes = 0 # Allow bird travel to be cancelled by hitting the X key CancelBirdTravel = 0 +# Allow 3D Zelda style quick spin attack +QuickSpin = 1 + [KeyMap] # Change what keyboard keys map to the joypad @@ -173,8 +176,8 @@ Save = Shift+F1,Shift+F2,Shift+F3,Shift+F4,Shift+F5,Shift+F6,Shift+F7,Shift+F8,S Replay= Ctrl+F1,Ctrl+F2,Ctrl+F3,Ctrl+F4,Ctrl+F5,Ctrl+F6,Ctrl+F7,Ctrl+F8,Ctrl+F9,Ctrl+F10 # Uncomment this to allow loading of reference saves -#LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace -#ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace +LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace +ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace [GamepadMap] # Any keys used in KeyMap can be used also in this section. From 2572baee2151291e32fea61443aa2aa7ba9b264d Mon Sep 17 00:00:00 2001 From: DPS2004 <10176105+DPS2004@users.noreply.github.com> Date: Thu, 13 Jul 2023 16:06:12 -0400 Subject: [PATCH 2/6] force an actual spin + rename variables --- features.h | 10 +++--- player.c | 89 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 71 insertions(+), 28 deletions(-) diff --git a/features.h b/features.h index 5d1e6508..18933da6 100644 --- a/features.h +++ b/features.h @@ -58,11 +58,11 @@ enum { #define hud_cur_item_x (*(uint8*)(g_ram+0x656)) #define hud_cur_item_l (*(uint8*)(g_ram+0x657)) #define hud_cur_item_r (*(uint8*)(g_ram+0x658)) -#define quickspin_timer_up (*(uint8*)(g_ram+0x659)) -#define quickspin_timer_down (*(uint8*)(g_ram+0x65a)) -#define quickspin_timer_left (*(uint8*)(g_ram+0x65b)) -#define quickspin_timer_right (*(uint8*)(g_ram+0x65c)) -#define quickspin_is_ready (*(bool*)(g_ram+0x65d)) +#define qs_up (*(uint8*)(g_ram+0x659)) +#define qs_down (*(uint8*)(g_ram+0x65a)) +#define qs_left (*(uint8*)(g_ram+0x65b)) +#define qs_right (*(uint8*)(g_ram+0x65c)) +#define qs_ready (*(bool*)(g_ram+0x65d)) diff --git a/player.c b/player.c index 41f32321..20b316ae 100644 --- a/player.c +++ b/player.c @@ -1970,7 +1970,6 @@ void Link_HandleSwordCooldown() { // 879ac2 } else { HandleSwordControls(); } - quickspin_is_ready = false; } @@ -2168,9 +2167,13 @@ void Link_CheckForSwordSwing() { // 879cd9 return; } - if(quickspin_is_ready){ + if(qs_ready){ Link_ResetSwordAndItemUsage(); Link_ActivateSpinAttack(); + qs_up = 0; + qs_down = 0; + qs_left = 0; + qs_right = 0; //fprintf(stderr,"performed quickspin\n"); } else { @@ -5773,6 +5776,7 @@ void Link_HandleVelocity() { // 87e245 } //----------- QUICK SPIN -------------- + qs_ready = false; // convert velocity to signed ints int velx = link_actual_vel_x; @@ -5787,45 +5791,84 @@ void Link_HandleVelocity() { // 87e245 //check for directions - uint8 quickspin_timer_duration = 24; + uint8 qs_duration = 24; if(vely < 0){ - quickspin_timer_up = quickspin_timer_duration; + qs_up = qs_duration; } if(vely > 0){ - quickspin_timer_down = quickspin_timer_duration; + qs_down = qs_duration; } if(velx < 0){ - quickspin_timer_left = quickspin_timer_duration; + qs_left = qs_duration; } if(velx > 0){ - quickspin_timer_right = quickspin_timer_duration; + qs_right = qs_duration; } //decrement timers - uint8 quickspin_timer_count = 0; + uint8 qs_count = 0; - if(quickspin_timer_up > 0){ - quickspin_timer_up--; - quickspin_timer_count++; + if(qs_up > 0){ + qs_up--; + qs_count++; } - if(quickspin_timer_down > 0){ - quickspin_timer_down--; - quickspin_timer_count++; + if(qs_down > 0){ + qs_down--; + qs_count++; } - if(quickspin_timer_left > 0){ - quickspin_timer_left--; - quickspin_timer_count++; + if(qs_left > 0){ + qs_left--; + qs_count++; } - if(quickspin_timer_right > 0){ - quickspin_timer_right--; - quickspin_timer_count++; + if(qs_right > 0){ + qs_right--; + qs_count++; } - //fprintf(stderr, "U: %d | D: %d | L: %d | R: %d | T: %d |\n", quickspin_timer_up,quickspin_timer_down,quickspin_timer_left,quickspin_timer_right, quickspin_timer_count); - if(quickspin_timer_count == 4){ + //fprintf(stderr, "U: %d | D: %d | L: %d | R: %d | T: %d |\n", qs_up,qs_down,qs_left,qs_right, qs_count); + + + + if(qs_count == 4){ + //CLOCKWISE + //U -> L + if(qs_up < qs_right && qs_right < qs_down && qs_down < qs_left){ + qs_ready = true; + } + // R -> U + if(qs_right < qs_down && qs_down < qs_left && qs_left < qs_up){ + qs_ready = true; + } + // D -> R + if(qs_down < qs_left && qs_left < qs_up && qs_up < qs_right){ + qs_ready = true; + } + // L -> D + if(qs_left < qs_up && qs_up < qs_right && qs_right < qs_down){ + qs_ready = true; + } + + //COUNTERCLOCKWISE + //U -> R + if(qs_up < qs_left && qs_left < qs_down && qs_down < qs_right){ + qs_ready = true; + } + // L -> U + if(qs_left < qs_down && qs_down < qs_right && qs_right < qs_up){ + qs_ready = true; + } + // D -> L + if(qs_down < qs_right && qs_right <= qs_up && qs_up < qs_left){ + qs_ready = true; + } + // R -> D + if(qs_right < qs_up && qs_up < qs_left && qs_left < qs_down){ + qs_ready = true; + } + //fprintf(stderr, "Can quickspin!\n"); - quickspin_is_ready = true; + //quickspin_is_ready = true; //Link_ActivateSpinAttack(); } From 3105bb1959ac4e33d51ef04ffbfbe7fceb6660e4 Mon Sep 17 00:00:00 2001 From: DPS2004 <10176105+DPS2004@users.noreply.github.com> Date: Thu, 13 Jul 2023 16:34:17 -0400 Subject: [PATCH 3/6] reformat code and respect ini file --- features.h | 2 +- player.c | 170 ++++++++++++++++++++++++----------------------------- zelda3.ini | 4 +- 3 files changed, 80 insertions(+), 96 deletions(-) diff --git a/features.h b/features.h index 18933da6..7aa4e534 100644 --- a/features.h +++ b/features.h @@ -47,7 +47,7 @@ enum { kFeatures0_DimFlashes = 65536, - kFeatures0_QuickSpin = 262144, + kFeatures0_QuickSpin = 131072, }; #define enhanced_features0 (*(uint32*)(g_ram+0x64c)) diff --git a/player.c b/player.c index 20b316ae..76e4769c 100644 --- a/player.c +++ b/player.c @@ -2167,14 +2167,13 @@ void Link_CheckForSwordSwing() { // 879cd9 return; } - if(qs_ready){ + if((enhanced_features0 & kFeatures0_QuickSpin) && qs_ready){ Link_ResetSwordAndItemUsage(); Link_ActivateSpinAttack(); qs_up = 0; qs_down = 0; qs_left = 0; qs_right = 0; - //fprintf(stderr,"performed quickspin\n"); } else { @@ -5775,105 +5774,90 @@ void Link_HandleVelocity() { // 87e245 link_actual_vel_y = (link_direction & 8) ? -vel : vel; } - //----------- QUICK SPIN -------------- - qs_ready = false; - // convert velocity to signed ints - int velx = link_actual_vel_x; - int vely = link_actual_vel_y; - if(velx >= 127){ + if(enhanced_features0 & kFeatures0_QuickSpin){ + //----------- QUICK SPIN -------------- + qs_ready = false; + + // convert velocity to signed ints + int velx = link_actual_vel_x; + int vely = link_actual_vel_y; + if(velx >= 127) velx -= 256; - } - if(vely >= 127){ + if(vely >= 127) vely -= 256; - } - //fprintf(stderr, "x: %d y: %d\n",velx,vely); - - //check for directions - - uint8 qs_duration = 24; - - if(vely < 0){ - qs_up = qs_duration; - } - if(vely > 0){ - qs_down = qs_duration; - } - if(velx < 0){ - qs_left = qs_duration; - } - if(velx > 0){ - qs_right = qs_duration; - } - - //decrement timers - - uint8 qs_count = 0; - - if(qs_up > 0){ + //fprintf(stderr, "x: %d y: %d\n",velx,vely); + + //check for directions + uint8 qs_duration = 24; + + if(vely < 0){ + qs_up = qs_duration; + } + if(vely > 0){ + qs_down = qs_duration; + } + if(velx < 0){ + qs_left = qs_duration; + } + if(velx > 0){ + qs_right = qs_duration; + } + + //decrement timers + + uint8 qs_count = 0; + + if(qs_up > 0){ qs_up--; - qs_count++; - } - if(qs_down > 0){ + qs_count++; + } + if(qs_down > 0){ qs_down--; - qs_count++; - } - if(qs_left > 0){ + qs_count++; + } + if(qs_left > 0){ qs_left--; - qs_count++; - } - if(qs_right > 0){ + qs_count++; + } + if(qs_right > 0){ qs_right--; - qs_count++; - } - //fprintf(stderr, "U: %d | D: %d | L: %d | R: %d | T: %d |\n", qs_up,qs_down,qs_left,qs_right, qs_count); - - - - if(qs_count == 4){ - //CLOCKWISE - //U -> L - if(qs_up < qs_right && qs_right < qs_down && qs_down < qs_left){ - qs_ready = true; - } - // R -> U - if(qs_right < qs_down && qs_down < qs_left && qs_left < qs_up){ - qs_ready = true; - } - // D -> R - if(qs_down < qs_left && qs_left < qs_up && qs_up < qs_right){ - qs_ready = true; - } - // L -> D - if(qs_left < qs_up && qs_up < qs_right && qs_right < qs_down){ - qs_ready = true; - } - - //COUNTERCLOCKWISE - //U -> R - if(qs_up < qs_left && qs_left < qs_down && qs_down < qs_right){ - qs_ready = true; - } - // L -> U - if(qs_left < qs_down && qs_down < qs_right && qs_right < qs_up){ - qs_ready = true; - } - // D -> L - if(qs_down < qs_right && qs_right <= qs_up && qs_up < qs_left){ - qs_ready = true; - } - // R -> D - if(qs_right < qs_up && qs_up < qs_left && qs_left < qs_down){ - qs_ready = true; - } - - //fprintf(stderr, "Can quickspin!\n"); - //quickspin_is_ready = true; - //Link_ActivateSpinAttack(); + qs_count++; + } + //fprintf(stderr, "U: %d | D: %d | L: %d | R: %d | T: %d |\n", qs_up,qs_down,qs_left,qs_right, qs_count); + + + + if(qs_count == 4){ + // CLOCKWISE + // U -> L + if(qs_up < qs_right && qs_right < qs_down && qs_down < qs_left) + qs_ready = true; + // R -> U + else if(qs_right < qs_down && qs_down < qs_left && qs_left < qs_up) + qs_ready = true; + // D -> R + else if(qs_down < qs_left && qs_left < qs_up && qs_up < qs_right) + qs_ready = true; + // L -> D + else if(qs_left < qs_up && qs_up < qs_right && qs_right < qs_down) + qs_ready = true; + + // COUNTERCLOCKWISE + // U -> R + else if(qs_up < qs_left && qs_left < qs_down && qs_down < qs_right) + qs_ready = true; + // L -> U + else if(qs_left < qs_down && qs_down < qs_right && qs_right < qs_up) + qs_ready = true; + // D -> L + else if(qs_down < qs_right && qs_right <= qs_up && qs_up < qs_left) + qs_ready = true; + // R -> D + else if(qs_right < qs_up && qs_up < qs_left && qs_left < qs_down) + qs_ready = true; + } } - - - //-------------- END QUICKSPIN ------------------- link_actual_vel_z = 0xff; link_z_coord = 0xffff; link_subpixel_z = 0; diff --git a/zelda3.ini b/zelda3.ini index 03135464..d5553810 100644 --- a/zelda3.ini +++ b/zelda3.ini @@ -137,8 +137,8 @@ GameChangingBugFixes = 0 # Allow bird travel to be cancelled by hitting the X key CancelBirdTravel = 0 -# Allow 3D Zelda style quick spin attack -QuickSpin = 1 +# Allow 3D Zelda style quick spin attack by doing a spin then using sword +QuickSpin = 0 [KeyMap] From d22b04c17786681779a25b9401a84dd13f784b9e Mon Sep 17 00:00:00 2001 From: DPS2004 <10176105+DPS2004@users.noreply.github.com> Date: Sat, 15 Jul 2023 13:39:53 -0400 Subject: [PATCH 4/6] re-comment loadref+replayref --- zelda3.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zelda3.ini b/zelda3.ini index d5553810..e9860f20 100644 --- a/zelda3.ini +++ b/zelda3.ini @@ -176,8 +176,8 @@ Save = Shift+F1,Shift+F2,Shift+F3,Shift+F4,Shift+F5,Shift+F6,Shift+F7,Shift+F8,S Replay= Ctrl+F1,Ctrl+F2,Ctrl+F3,Ctrl+F4,Ctrl+F5,Ctrl+F6,Ctrl+F7,Ctrl+F8,Ctrl+F9,Ctrl+F10 # Uncomment this to allow loading of reference saves -LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace -ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace +# LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace +# ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace [GamepadMap] # Any keys used in KeyMap can be used also in this section. From 6ddf70423101b242b8171c008e4824e11782094a Mon Sep 17 00:00:00 2001 From: DPS2004 <10176105+DPS2004@users.noreply.github.com> Date: Sat, 15 Jul 2023 14:16:29 -0400 Subject: [PATCH 5/6] oops, added extra spaces --- zelda3.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zelda3.ini b/zelda3.ini index e9860f20..b818a215 100644 --- a/zelda3.ini +++ b/zelda3.ini @@ -138,7 +138,7 @@ GameChangingBugFixes = 0 CancelBirdTravel = 0 # Allow 3D Zelda style quick spin attack by doing a spin then using sword -QuickSpin = 0 +QuickSpin = 1 [KeyMap] @@ -176,8 +176,8 @@ Save = Shift+F1,Shift+F2,Shift+F3,Shift+F4,Shift+F5,Shift+F6,Shift+F7,Shift+F8,S Replay= Ctrl+F1,Ctrl+F2,Ctrl+F3,Ctrl+F4,Ctrl+F5,Ctrl+F6,Ctrl+F7,Ctrl+F8,Ctrl+F9,Ctrl+F10 # Uncomment this to allow loading of reference saves -# LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace -# ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace +#LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace +#ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace [GamepadMap] # Any keys used in KeyMap can be used also in this section. From a262945676f7e8667c1cf712bcbd2a504ec12f9e Mon Sep 17 00:00:00 2001 From: DPS2004 <10176105+DPS2004@users.noreply.github.com> Date: Sat, 15 Jul 2023 14:17:03 -0400 Subject: [PATCH 6/6] gahhhhhhhhh --- zelda3.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zelda3.ini b/zelda3.ini index b818a215..7aef8dd3 100644 --- a/zelda3.ini +++ b/zelda3.ini @@ -138,7 +138,7 @@ GameChangingBugFixes = 0 CancelBirdTravel = 0 # Allow 3D Zelda style quick spin attack by doing a spin then using sword -QuickSpin = 1 +QuickSpin = 0 [KeyMap]