News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: zelda 2 ASM hacking and improvements  (Read 14065 times)

njosro

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
zelda 2 ASM hacking and improvements
« on: February 05, 2018, 10:20:28 pm »
A few years ago I tried to do an asm hack that would alleviate the pain of being sent back to the beginning after you lost all your lives. It was my first time doing any sort of assembly, so it had a few flaws that would mess up the collectible items.

Recently I had a good reason to work on version 2.0: It was requested by hollowshadow for his new hack.

So here it is. It doesn't have any unwanted side effects! (at least I'm 95% sure...)

http://www.romhacking.net/hacks/3859/

Here is the code for anyone interested.

Code: [Select]
Asterisk * means I added this section or modded the instruction.

07:CAD0 (01CAE0)
JSR $AB10*
--------------------------
00: AB10 (002B20)*
LDA $707 ; current world
RTS
--------------------------
07:CAD3 (01CAE3)
CMP #$03* ; if > 3
BCS $CADE ; goto the jsr below
LDA #$00
LDY #$01
JMP $CAF0 ; jump to ~~label 1~~
JSR $AB14*
--------------------------
00:AB14 (002B24)*
LDA $706 ; region
ASL ; *2
ASL ; *2
CLC
ADC $707 ; +world
ADC $748 ; +area_index
SEC
SBC #$34 ; -52
TAX
LDA $AB30,X ; @ AB33, AB34, AB36, AB38, AB3B, AB3D, or AB3F
STA $561 ; set scene index
JMP $C358

07:C358 () ; (built-in) reset lives and other paramaters.
LDA #$03
STA $700
INC $760
INC $76C
RTS
--------------------------
07:CAE1 ()
LDA #$00
NOP
NOP
NOP
STA $701
STA $75C
LDA #$01
LDY #$02
~~label 1~~
STA $76C
STY $75F
RTS

the end.
« Last Edit: March 09, 2018, 11:10:28 am by njosro »

ShadowOne333

  • Hero Member
  • *****
  • Posts: 960
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #1 on: February 05, 2018, 11:42:45 pm »
This hack really sparked my interest for sure!
It will aliviate one of the more excruciatingly obnoxious points in the game, which is having to traverse Hyrule all over again just to get a shot at the Temple you left off befor a Game Over.

I will try this one out for sure!

Also, are you willing to make some more quality ASM hacks into Zelda II?
To make it a more suitable experience overall, don't know if you have any ideas but it'd be neat to at least take them into consideration for a further project implementing this as the base. :P

EDIT:
Btw, does this also change where you spawn after you reboot the game and continue a save file?
« Last Edit: February 06, 2018, 02:40:21 pm by ShadowOne333 »

Revility

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
    • The Revility
Re: zelda 2 restart from current palace after game over
« Reply #2 on: February 06, 2018, 08:42:40 am »
Very cool!  I will give this a shot.

This game has so much potential, but just needs the rough edges sanded off. This is definitely a great little quality of life improvement.

Can I add it into the rev hack?
I'm going to make a seperate version that is purely just the updated sprites to make it easier for other's to use in their hacks.  :)

ultimaweapon

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #3 on: February 08, 2018, 11:13:00 am »
This is definitely a most welcomed edition. It's most certainly a pain trying to get back to a palace after losing all of your lives especially the last 4 palaces.
Trust in the Heart of the Cards

njosro

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #4 on: February 09, 2018, 11:42:54 am »
Thanks guys!

ShadowOne, yes, I made a few other asm hacks. The most notable one is built-in to the side view editor. It lets you assign any key item to any palace (i.e. the condition to turn to stone) without screwing up the crystal returns. In the original game this was not possible.

This particular "respawn" hack does not affect where you start after rebooting the game. That would be a whole new thing to implement.

I also made one more half-done hack where SPELL becomes GHOST. It makes Link flicker for the entire screen so he's invulnerable.

Revility, you can patch this to your hack :) Just be careful that you don't overwrite something important. I don't think it will be a problem, but it's something to remember if you experience any problems.

ShadowOne333

  • Hero Member
  • *****
  • Posts: 960
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #5 on: February 09, 2018, 12:15:34 pm »
Neat!

Another thing I would suggest is probably...
When you save the game manually, that counts as a Game Over or as a Death towards the counter in the Selection Screen.
Perhaps keep it so that when saving manually does NOT count towards that number, and only Deaths and Game Overs do count towards it.

This is something I never liked from the 2D Zeldas.

ultimaweapon

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #6 on: February 11, 2018, 10:24:58 pm »
NJOSRO

Changing SPELL to GHOST is quite interesting. What is the link, so I can check that out? I wish I would have known that you have done that?

Also, do you think you could change JUMP in the way it behaves from jumping high to doing a double jump? I think a double just would be better for Zelda 2 as opposed to jumping higher.
Trust in the Heart of the Cards

Shadic

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #7 on: February 13, 2018, 02:02:39 pm »
This is awesome!

The biggest "rough edge" I believe that the game has left would be losing a life when you fall into a pit.. Would it be feasible to make it instead restart the room and take 10-20% of your life?

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3455
    • View Profile
    • Aeon Genesis
Re: zelda 2 restart from current palace after game over
« Reply #8 on: February 13, 2018, 02:35:29 pm »
Curious, if you don't get kicked back to the starting palace when you game over, what's the difference between losing one life and losing all of your lives? Do you now, in effect, have infinite lives?
« Last Edit: February 13, 2018, 03:47:40 pm by Gideon Zhi »

pocket

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #9 on: February 13, 2018, 02:49:48 pm »
That's one of the biggest problems with the game out of the way. All I'd change now is speeding up the NPC text.

njosro

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #10 on: February 14, 2018, 12:40:45 pm »
Thanks guys!!

Another thing I would suggest is probably...
When you save the game manually, that counts as a Game Over or as a Death towards the counter in the Selection Screen.
Perhaps keep it so that when saving manually does NOT count towards that number, and only Deaths and Game Overs do count towards it.

To do that you would need to set a flag when the game detects up + A on the controller (or whatever it was), and then check the flag when you choose the save option. (But I always ignore the game over counter anyway hahaha)

Changing SPELL to GHOST is quite interesting. What is the link, so I can check that out? I wish I would have known that you have done that?

Also, do you think you could change JUMP in the way it behaves from jumping high to doing a double jump? I think a double just would be better for Zelda 2 as opposed to jumping higher.

I don't have a patch ready for download because I was just experimenting with it a long time ago. I don't think I have the file anymore. Maybe one day I'll try it again.
As for JUMP, I don't have much experience messing with the physics of the game. It's an interesting suggestion though, and I think I would try it!

The biggest "rough edge" I believe that the game has left would be losing a life when you fall into a pit.. Would it be feasible to make it instead restart the room and take 10-20% of your life?

I actually had the same thought! I haven't tried to do anything like that yet... but if I did, I'd imagine it going like this:
1. Lose a some life the moment you touch the lava
2. Skip the death, and just go to the routine that "refreshes" the room. This would also make the music keep playing.


Curious, if you don't get kicked back to the starting palace when you game over, what's the difference between losing one life and losing all of your lives? Do you now, in effect, have infinite lives?

No, you still get punished for losing all your lives. It's just softer. When you lose one life you start at the exact same screen, and you keep your EXP. When you lose all your lives, you get kicked back to the entrance of the palace and lose all your EXP. If you're not in a palace, you go back to the starting palace and lose all your EXP like the original.

That's one of the biggest problems with the game out of the way. All I'd change now is speeding up the NPC text.

If you download my dialog editor you can change the text speed.

ShadowOne333

  • Hero Member
  • *****
  • Posts: 960
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #11 on: February 14, 2018, 01:04:10 pm »
Thanks guys!!

To do that you would need to set a flag when the game detects up + A on the controller (or whatever it was), and then check the flag when you choose the save option. (But I always ignore the game over counter anyway hahaha)
I managed to get the game to save with Controller #1 by pressing Up+A after pausing.
This saves manually, all I gotta do is add the flag check right now and make the custom subroutine.

I am really interested in making some sort of Quality hack for Zelda II, as it's the one that needs it most out of the NES Zeldas.
Basically I am planning this right now:
  • Add a manual Save for the game by pressing Pause and then Up+A on Controller #1. This save should NOT be counter towards the Death counter on the Game Selection Screen.
  • Implementing your Restart in Current Palace hack
  • Implement the "Falling on pits takes health but doesn't count as a life" idea you guys have in mind.
I don't know how this sounds for you, but I would love to see this come to fruition.
Perhaps someone else has better ideas as to how to make Zelda II a better and more balanced game.
I was also thinking about the possibility of reducing how much Magic each spell consumes, this should be fairly easy to do as well.

So let me know what do you think, and what others think as well
I am very interested in doing this to let Zelda II become a more welcomed game to the franchise instead of the Black Sheep.
« Last Edit: February 15, 2018, 08:43:32 pm by ShadowOne333 »

IAmCaptPlanet

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #12 on: February 15, 2018, 04:17:25 pm »
I think all of that sounds great!

And as a suggestion, also try to get the double jump thing in there. the Jump Spell makes Link to "floaty".

and would really be nice to have Hearts for a health meter and a green Magic meter, to bring it more in line with the rest of the series (although it would be purely cosmetic, i think it would help out a lot)

also, the dialogue speed,and the ANNOYING CLACK CLACK (typewriter noise) could use some work.

ShadowOne333

  • Hero Member
  • *****
  • Posts: 960
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #13 on: February 15, 2018, 08:42:59 pm »
and would really be nice to have Hearts for a health meter and a green Magic meter, to bring it more in line with the rest of the series (although it would be purely cosmetic, i think it would help out a lot)
I could try that.

Edit:
Okay I might take a while to try to do this lol
The Linux PC where I usually do all my hacking just had a cutoff update and I have to pinpoint what package it was and reinstall/update again. Until then :P

In the meanwhile, I searched around for existing hacks of Zelda II that could be a great addition to a Quality hack for Zelda II:
Zelda II MMC1 to MMC3 Hack, Zelda II: Remove big flasheffect and some aspects of Zelda II Easy, like less Magic consumption and perhaps more starting lives and I'm not sure if perhaps lowering the Experience points required per-level.
« Last Edit: February 16, 2018, 01:04:08 pm by ShadowOne333 »

njosro

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #14 on: February 16, 2018, 11:50:27 pm »
I tinkered around tonight, and I have a strong base for anyone interested in the lava code. It's cool and all, but I don't want to spend time debugging and perfecting it. Here is what I've got. Feel free to build on it.

Whenever RAM $494 is incremented, you die. This is the way the game does it.

The code for sinking in lava and executing a lava death is at 119E in ROM:

Code: [Select]
LDA #$00
STA $0014
LDA $29         ; y position
CMP #$D0        ; if not at bottom of screen,
BCC $119C       ; skip next instruction
INC $0494       ; DIE
INC $29 ; increment y position
JSR $93AC
JMP $EBF0

If you change INC $0494 to a JSR, you can inject your own code. I decided to JSR to the middle of some empty space at the end of bank 0 (at 3F0A in ROM). I put 3 instructions there:

Code: [Select]
LDA #$07
STA $0736
RTS

RAM $736 controls what 'mode' the game is in. A value of 7 instructs the game to reload the scene. The game naturally writes to this address when changing scenes. (Other values for $736 specify whether Link is falling, whether it's a side view vs the over world, and so on.)

It works, but with 2 issues.

1. You can see the screen jerk around a bit before it blacks out to refresh
2. The enemies don't reappear for some reason. Not even the blobs will respawn.

So there you go! Refer to the zelda 2 dump at https://lemmy.neocities.org/zelda2/zelda2.html if you want to add your own stuff.

ShadowOne333

  • Hero Member
  • *****
  • Posts: 960
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #15 on: February 17, 2018, 03:09:11 pm »
How is this for a PoC for making the Health bar Hearts instead of a single bar? :P



I struggled quite a bit because the game uses some kind of background colour for keeping track of the health, which is why I ended up putting a blue colour around the hearts so that this effect is not seen while in gameplay.

I am also thinking about making the Magic meter a single block instead of segmented blocks, but I'm not sure yet, this is how it'd look:


Some might like it, some might not.
In the meanwhile, I'll leave it as segmented blocks instead.

Another modification I thought of is switching the places of the Magic and Health meters.
I am nitpicky like that and feel like Health should go before Magic, but that's just me. xD

Here is the IPS Patch:
https://www.dropbox.com/s/iq0za2d5rvr21lk/Zelda2%20-%20LifeMeter-ManualSave.ips?dl=0

Also, as an added bonus, this patch also has a Manual Save feature ;)
While in gameplay, Pause the game and then press Up+A to save at any time during gameplay.

@njosro, the code which reads the button combo for saving is located in 0x0021AF for Sidescrolling sections and in 0x0021ED for Overworld areas. For some reason the code is split like that.
The RAM address for button inputs on controller #1 is at $00F7, and the value which the code checks for is $88 (Up+A), while the Death counter is stored at $742A in RAM.
The beginning opcode in hex looks like this for the first section of code (Sidescrolling section manual save):

[A5 F7 C9 88 D0 37 20 4C D2 20]

I haven't figured out a way to make it so that saving manually doesn't add to the Death counter, but if you manage to find a way before I do, that'd be awesome :P
ASM is not my strength so I am making baby steps with this, so I'll see what I can do.

ultimaweapon

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #16 on: February 20, 2018, 12:21:04 pm »
@ShadowOne333 - Trax already has a tool for reducing the cost for magic spells, but it's for Mac OS X Tiger and earlier versions and not Windows. I had to emulate the Mac OS to use it for my hack I'm working on. Here is Trax's tool. https://www.romhacking.net/utilities/375/

I like the design of the hearts. It gives it a more classic Zelda feel.
Trust in the Heart of the Cards

ShadowOne333

  • Hero Member
  • *****
  • Posts: 960
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #17 on: February 20, 2018, 01:36:03 pm »
@ShadowOne333 - Trax already has a tool for reducing the cost for magic spells, but it's for Mac OS X Tiger and earlier versions and not Windows. I had to emulate the Mac OS to use it for my hack I'm working on. Here is Trax's tool. https://www.romhacking.net/utilities/375/

I like the design of the hearts. It gives it a more classic Zelda feel.
Oh I didn't know about that software.
It does look good, sadly it relies on Mac OSX, which is somewhat niche when it comes to RomHacking in general.
I mostly use Linux to work on hacks, and since the source code for that app is not available, I won't be able to run it in anything else other than a VM, which might take way more time than I'd like.
I'd try to port it to Linux if I had the source code handy.

Besides, I believe I already have the ROM offsets identified which modify the values for magic, so changing them manually through Hex editing should be fairly easier than doing a whole VM setup just for that one software :P

Revility

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
    • The Revility
Re: zelda 2 restart from current palace after game over
« Reply #18 on: February 20, 2018, 09:37:42 pm »
There are hearts for the life bar in the last build of the rev hack.  Feel free to use or edit. 

I looked into changing the magic bar green, but it appears part of the bar has it's color set in a different way so I stopped snooping into it.

The health and magic bars go into negative when your dead or use all your magic.  I have a hunch this wasn't intentional just by how the negative part of the bar looks when it happens.

ultimaweapon

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: zelda 2 restart from current palace after game over
« Reply #19 on: February 21, 2018, 01:33:48 pm »
@ShadowOne333 - Do you think you can find the ROM offsets that controls how much experience you gain from each enemy? If so, I have a problem with my hack that maybe you can help me solve.
Trust in the Heart of the Cards