Romhacking.net

Romhacking => ROM Hacking Discussion => Topic started by: gzip on September 19, 2020, 06:41:40 pm

Title: Zelda 1 level text
Post by: gzip on September 19, 2020, 06:41:40 pm
I'd like to change the text in the dungeons from "Level-1" to "Dungeon-1". In addition to the text change, the text also has to move over to the left one space so it fits well. This is probably an easy change for someone that knows what they're doing. I'm not having much luck.

(https://i.imgur.com/9hGWRNv.png)
Title: Re: Zelda 1 level text
Post by: ultimaweapon on September 19, 2020, 10:40:38 pm
The3Dude changes his from Level to Map, so he would be the person to ask.
Title: Re: Zelda 1 level text
Post by: The3Dude on September 19, 2020, 10:57:59 pm
I'd like to change the text in the dungeons from "Level-1" to "Dungeon-1". In addition to the text change, the text also has to move over to the left one space so it fits well. This is probably an easy change for someone that knows what they're doing. I'm not having much luck.

(https://i.imgur.com/9hGWRNv.png)

First things first, if you are hacking an NES game, the EASIEST way to hex edit is by using the FCEUX emulator. Here is a step by step to getting to the line of text you want to find.

1. Open Zelda 1 in FCEUX.
2. Click the debug tab.
3. After clicking the debug tab, click the "Hex editor..." tab.
4. Once the hex editor appears, click "View".
5. Change from "NES MEMORY" view to "ROM FILE" view.
6. After above steps, click "File"... You should now see a selection called "Load *.TBL File"
7. Click Load Table file, download this table file https://drive.google.com/file/d/1sRZBYPIOS42uWmxNC1qUGAUHwPyPm9uv/view?usp=sharing (https://drive.google.com/file/d/1sRZBYPIOS42uWmxNC1qUGAUHwPyPm9uv/view?usp=sharing) and then load the downloaded table file.

8. After loading the .TBL file, finding your text string is super easy. All you must do is click the "Edit" tab, then the "Find..." tab, search for the text you are looking for, which in this case is LEVEL-, Just search "level" all lowercase and you should find what you're looking for.
9. MAKE SURE YOU CHANGE  THE VIEW TYPE FROM HEX VIEW TO TEXT VIEW OR YOU WON'T FIND THE TEXT STRING!
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 19, 2020, 11:00:05 pm
I think I tried to do something similar for Redux, but I ended up not going for it, can't truly remember why.

I believe because I was having issues with either the character length, the dash being handled through code or the number, which is also handled through code.
I might give this a go again later this week.
Title: Re: Zelda 1 level text
Post by: gzip on September 19, 2020, 11:25:31 pm
First things first, if you are hacking an NES game, the EASIEST way to hex edit is by using the FCEUX emulator.

Thanks, I've done all this already but the text doesn't really allow me to go beyond the current length without causing corruption. I also need to move the text to the left one space. I imagine that I'll have to relocate the text, read from there, and then tweak the start column and number replacement. Can you point me to the relevant code?

I added a read breakpoint for the RAM location (0x681F) and I can see the text being written to the PPU but I'm not sure where the column location and text length are stored.

Code: [Select]
> 01A0DE:B0 01     BCS $A0D1
  01A0E0:C8        INY
  01A0E1:B1 00     LDA ($00),Y @ $6823 = #$0E
  01A0E3:8D 07 20  STA PPU_DATA = #$F6
  01A0E6:CA        DEX
  01A0E7:D0 F5     BNE $A0CE

It would be really useful to know how to use the stack to see where this was called from.
Title: Re: Zelda 1 level text
Post by: The3Dude on September 19, 2020, 11:39:54 pm
Thanks, I've done all this already but the text doesn't really allow me to go beyond the current length without causing corruption. I also need to move the text to the left one space. I imagine that I'll have to relocate the text, read from there, and then tweak the start column and number replacement. Can you point me to the code where the text gets written to the screen?

I honestly same as you have no idea on how to move the text offset. But I did find a "Smarter not Harder"  ;) workaround for it. If you have graphics space "Which you most likely do" Just do this.

(https://i.ibb.co/6tbvtKp/level.png)

That way, it will still say dungeon, and you won't have to find the pointers.
Title: Re: Zelda 1 level text
Post by: gzip on September 19, 2020, 11:44:50 pm
Good idea! I don't have the graphics space though. :-\
Title: Re: Zelda 1 level text
Post by: The3Dude on September 19, 2020, 11:53:10 pm
Good idea! I don't have the graphics space though. :-\

You very sure? I can make some space if you send me the current build.

As long as it doesn't look like this (https://i.ibb.co/LNSdgV5/gfx.png) :laugh: :-\ And If you have title screen graphics in the section of space seen on that image above, I could move it to the top of the game near where the "PLEASE READ THE MANUAL FOR DETAILS" sign is located.


(https://i.ibb.co/KxQhqcG/Legend-of-Zelda-The-U-PRG0-5-0.png)

It would look like this in game btw.

Title: Re: Zelda 1 level text
Post by: gzip on September 20, 2020, 12:15:01 am
Here's how my space currently looks (a lot of it gets eaten up by automap). There are title graphics in there, the "A NEW LIGHT" part, so if you have some magic to move them, then by all means. The extra space would be welcome either way (if I can make the text change without additional graphics then all the better).

The current build is on the hack page (https://www.romhacking.net/hacks/5028/).

(https://i.imgur.com/RfNGDSO.png)
Title: Re: Zelda 1 level text
Post by: The3Dude on September 20, 2020, 12:25:07 am
Would you like me to modernize the Zelda title screen font too?
Title: Re: Zelda 1 level text
Post by: gzip on September 20, 2020, 12:28:23 am
Would you like me to modernize the Zelda title screen font too?

Hmm, not sure what that means. Maybe in a separate patch. Do you have an example?
Title: Re: Zelda 1 level text
Post by: The3Dude on September 20, 2020, 12:29:47 am
Hmm, not sure what that means. Maybe in a separate patch. Do you have an example?

This (https://geekireland.com/wp-content/uploads/2019/02/zelda1.jpg)

to this

(https://www.zelda.com/online-guide/assets/img/legend-of-zelda-logo.png)
Title: Re: Zelda 1 level text
Post by: gzip on September 20, 2020, 12:33:48 am
Tempting but I think I'll stick with the classic title screen for now. :thumbsup:
Title: Re: Zelda 1 level text
Post by: The3Dude on September 20, 2020, 01:05:20 am
Check PM's ;D
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 20, 2020, 10:15:26 am
Give me some hours, maybe I can come up with something for the LEVEL text.

September 20, 2020, 12:19:16 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Okay this is what I found so far.

The PPU transfer for the "LEVEL-0" string is located at 0x19D14 in the ROM, or $19D04 in NES address.
Here's what's in there:
Code: [Select]
// LEVEL-X text
org $9D04 // $19D14
db $20,$42,$07
db "LEVEL-0"
db $FF

The first 3 bytes specify the PPU address where to start printing it, and then comes the actual letters, then the end command "FF" for PPU transfers. Changing this to say DUNGEON-0 would be like this:
Code: [Select]
// LEVEL-X text
org $9D04 // $19D14
db $20,$42,$09
db "DUNGEON-0"
db $FF

However, trouble arises when we try to make the room for the 2 additional bytes we require.
The LEVEL text and its PPU transfer don't seem to have any direct pointer that I can track down. I tried debugging it a little bit, and I came to the same routine you guys hit, with no direct reference to $9D04 that I could tell.
The whole routine for this I will post next, however I am unfamiliar with most of the opcodes here, so I'm at a bit of a loss here.

Once the PPU transfer is dealt with, there's still the numeral that gets placed depending on the Dungeon number, which always gets sent to PPU $205C, so we would also need to locate the code that handles that.

Code: [Select]
1A0A2: 48 PHA
1A0A3: 8D 0620 STA $2006
1A0A6: C8 INY
1A0A7: B1 00 LDA ($00),Y
1A0A9: 8D 0620 STA $2006
1A0AC: C8 INY
1A0AD: B1 00 LDA ($00),Y
1A0AF: 0A ASL
1A0B0: 48 PHA
1A0B1: A5 FF LDA $FF
1A0B3: 09 04 ORA #$04 ; set  bits .... .x..
1A0B5: B0 02 BCS $1A0B9

1A0B7: 29 FB AND #$FB ; keep bits xxxx x.xx

1A0B9: 8D 0020 STA $2000
1A0BC: 85 FF STA $FF
1A0BE: 68 PLA
1A0BF: 0A ASL
1A0C0: 08 PHP
1A0C1: 90 03 BCC $1A0C6

1A0C3: 09 02 ORA #$02 ; set  bits .... ..x.
1A0C5: C8 INY

1A0C6: 28 PLP
1A0C7: 18 CLC
1A0C8: D0 01 BNE $1A0CB

1A0CA: 38 SEC

1A0CB: 6A ROR
1A0CC: 4A LSR
1A0CD: AA TAX

1A0CE: B0 01 BCS $1A0D1

1A0D0: C8 INY

1A0D1: B1 00 LDA ($00),Y
1A0D3: 8D 0720 STA $2007
1A0D6: CA DEX
1A0D7: D0 F5 BNE $1A0CE

1A0D9: 68 PLA
1A0DA: C9 3F CMP #$3F
1A0DC: D0 0C BNE $1A0EA

1A0DE: 8D 0620 STA $2006
1A0E1: 8E 0620 STX $2006
1A0E4: 8E 0620 STX $2006
1A0E7: 8E 0620 STX $2006

1A0EA: 38 SEC
1A0EB: 98 TYA
1A0EC: 65 00 ADC $00
1A0EE: 85 00 STA $00
1A0F0: A9 00 LDA #$00 ; A = 00
1A0F2: 65 01 ADC $01
1A0F4: 85 01 STA $01

1A0F6: AE 0220 LDX $2002
1A0F9: A0 00 LDY #$00 ; Y = 00
1A0FB: B1 00 LDA ($00),Y
1A0FD: 10 A3 BPL $1A0A2

1A0FF: 60 RTS
Title: Re: Zelda 1 level text
Post by: abw on September 20, 2020, 12:45:36 pm
I honestly same as you have no idea on how to move the text offset.
This is the easy part. As with many of the other strings in this game, the format is [2-byte PPU address (big endian)] + [1-byte string length] + [string], so changing its screen position is trivial; if you want to move it 1 tile to the left, simply subtract 1 from the PPU address, i.e. $2042 -> $2041.

The hard part is that the "LEVEL-0" text gets copied from ROM into cartridge RAM (ending up at $681C) on power/reset and is tightly packed in cartridge RAM with a bunch of other data, so instead of just updating some ROM pointer to target somewhere in the giant chunk of nearby free space in ROM, you also need to change the game's RAM usage, which is more annoying.

Changing the position of the dynamic level number, however, is also easy: that's controlled by the STA $6825 at $05:$B02F, so once you've got the RAM usage sorted out, just replace $6825 with the new RAM address of the level number placeholder.
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 20, 2020, 12:57:23 pm
The code @abw pointed out for the number is correct.
Changing it to the following:
Code: [Select]
bank 5;
org $B02F // 0x1703F
    sta $6827   // Originally STA $6825

Makes it so the number is now printed two positions to the right from the original one, so once the "DUNGEON-0" pointer has been figured out, having that for the number printing would move the numeral accordingly for the DUNGEON text.
Title: Re: Zelda 1 level text
Post by: abw on September 20, 2020, 03:49:27 pm
Ah, sorry, I didn't see your previous edit before posting.

The LEVEL text and its PPU transfer don't seem to have any direct pointer that I can track down.
The pointer to the LEVEL text lives at $06:$A00C.

The various sections of RAM loading code populate $67F0-$6C7D, and it looks like $67CE-$6C8F might be unused, in which case you could probably insert your extra 2 bytes in ROM and (find and) update everything that references $681D-$6C7D accordingly. Or add new code to load the LEVEL text into $67CE-$6C8F and update just $06:$A00C and $05:$B02F. The squishy tiles also look okay, if that ends up being easier.
Title: Re: Zelda 1 level text
Post by: gzip on September 20, 2020, 07:15:48 pm
This is the easy part. As with many of the other strings in this game, the format is [2-byte PPU address (big endian)] + [1-byte string length] + [string], so changing its screen position is trivial; if you want to move it 1 tile to the left, simply subtract 1 from the PPU address, i.e. $2042 -> $2041.

I had no idea that strings were formatted like this. Very useful, thanks!

September 20, 2020, 07:19:18 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
The code @abw pointed out for the number is correct.
Changing it to the following:
Code: [Select]
bank 5;
org $B02F // 0x1703F
    sta $6827   // Originally STA $6825

Makes it so the number is now printed two positions to the right from the original one, so once the "DUNGEON-0" pointer has been figured out, having that for the number printing would move the numeral accordingly for the DUNGEON text.

Hmm, I don't get any number printed when I make this change, not sure why. Maybe it's being redrawn after the fact? Maybe the initial string has to be longer?

Here's my latest thinking:

1) Change "LEVEL-0" to "DUNGEON", same number of bytes, sacrifice the dash, no big loss (verified)
2) Move the text to the left one space by changing 2042 to 2041 (verified)
3) Move the number right two positions as outlined above (not working)

That way all the RAM and ROM shuffling is eliminated (depending on 3).
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 20, 2020, 07:23:48 pm
The reason why the moved number doesn't show up is because you need a sprite there that the number can replace. Try putting $09 in the PPU Transfer for LEVEL and then make the number change, you'll see the number in red now moved two tiles to the right.
Title: Re: Zelda 1 level text
Post by: gzip on September 20, 2020, 07:31:30 pm
The reason why the moved number doesn't show up is because you need a sprite there that the number can replace. Try putting $09 in the PPU Transfer for LEVEL and then make the number change, you'll see the number in red now moved two tiles to the right.

So close! Is there any way around this without having to relocate the string? Maybe a palette change for the blue tile?

(https://i.imgur.com/hSHEDa7.png)
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 20, 2020, 07:35:25 pm
Maybe the Number code could be modified to send the dash AND the number to RAM, so the dash replaces the current glitchy tile?
It's dirty, but a possibility for sure.
Title: Re: Zelda 1 level text
Post by: gzip on September 20, 2020, 07:40:44 pm
I changed the FF to 24 and it works, as does 62. How critical is that FF, is it going to bite me somewhere?
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 20, 2020, 07:51:19 pm
I changed the FF to 24 and it works, as does 62. How critical is that FF, is it going to bite me somewhere?
The FF I'm not sure.
From my experience, most PPU Transfers use FF as an END command, to let the code know that's where the transfer finishes, but I've seen some instances of some transfers coupled together one after the other, where they don't use FF, but the very last one does have it. Better to test it well enough in-game to be sure.

As for the 64, DON'T touch that one. That's part of a pointer table for some palette or dungeon stuff iIrc.

Just do the FF change for now (you can put the dash back there if you want), and test thoroughly in-game that it doesn't alter anything else.

Also, you might want to move the other thread you made here about the pushable rock.
Title: Re: Zelda 1 level text
Post by: gzip on September 20, 2020, 08:19:02 pm
So far so good. It does fill a bit dirty to modify the FF but it is a hack after all. :laugh: We'll see if it holds up. Thanks for all the help!
Title: Re: Zelda 1 level text
Post by: ultimaweapon on September 21, 2020, 01:12:08 am
This (https://geekireland.com/wp-content/uploads/2019/02/zelda1.jpg)

to this

(https://www.zelda.com/online-guide/assets/img/legend-of-zelda-logo.png)

That modernized title is nice. It would be even better if you found a way to include the Triforce and the Sword in the picture.
Title: Re: Zelda 1 level text
Post by: abw on September 21, 2020, 09:04:38 am
So far so good. It does fill a bit dirty to modify the FF but it is a hack after all. :laugh: We'll see if it holds up. Thanks for all the help!
This might actually work out to be safe enough as long as you don't change certain other things. Normally the FF is used to kick out of the outer PPU transfer loop, but the code really only cares about whether the PPU address is < $8000 (that's the "BPL $A0A2") and it just so happens that the byte following the "DUNGEON 0" string appears to always have its high bit set, so you won't end up accidentally setting off an extra PPU transfer loop and getting garbled graphics.

As for positioning the number at $6827, overwriting other data is normally also bad, but in this case $6827-$6828 are dynamically updated *after* the "DUNGEON #" text is displayed, so all that happens is you get your # displayed and then the # at $6827 gets overwritten with the value the game wants to be there anyway. So... no harm no foul?
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 21, 2020, 07:41:18 pm
Hope you don't mind, gzip, but I also implemented the change for Redux :P
So it now says "DUNGEON-X" above the Dungeon map.
Though for me, the whole map is in the right side of the screen, since I flipped the hearts and Map stuff for Redux.

@abw, if I were to repoint just the $20,$42,$09 "LEVEL-0" $FF PPU transfer somewhere else, is it possible? And if so, what would be needed to do so?
Title: Re: Zelda 1 level text
Post by: gzip on September 21, 2020, 09:53:56 pm
Hope you don't mind, gzip, but I also implemented the change for Redux :P

:thumbsup: Yep, I figured as much. Glad to be able to contribute again.
Title: Re: Zelda 1 level text
Post by: abw on September 21, 2020, 11:17:33 pm
@abw, if I were to repoint just the $20,$42,$09 "LEVEL-0" $FF PPU transfer somewhere else, is it possible? And if so, what would be needed to do so?
It's definitely possible, and it doesn't look to even be that much work. The existing routine for copying data from ROM to RAM and that routine's associated sections of variable setup code cover $06:$8047-$06:$8106 and are pretty bloated, so you could easily optimize them to free up at least 20 bytes for new code,
Spoiler:
Code: [Select]
.org $180FC
; frees up 14 bytes right here
INC $02
BNE @done_write_addr_INC
INC $03
@done_write_addr_INC:
INC $00
BNE @done_read_addr_INC
INC $01
@done_read_addr_INC:
JMP $80D9
which is more than enough space for a simple copy loop (you're already in bank 6, so no need to worry about swapping banks).
Spoiler:
Code: [Select]
LDX #$0D ; or however long your new string is
@loop:
LDA $9D70,X ; or wherever else you want to read it from
STA $6780,X ; or wherever else you want to write it to
DEX
BPL @loop
RTS
After that, just update $06:$A00C to point to the start of your new string, update the level number write address at $05:$B02F, and it should all work out.
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 22, 2020, 12:55:32 pm
It's definitely possible, and it doesn't look to even be that much work. The existing routine for copying data from ROM to RAM and that routine's associated sections of variable setup code cover $06:$8047-$06:$8106 and are pretty bloated, so you could easily optimize them to free up at least 20 bytes for new code,
Spoiler:
Code: [Select]
.org $180FC
; frees up 14 bytes right here
INC $02
BNE @done_write_addr_INC
INC $03
@done_write_addr_INC:
INC $00
BNE @done_read_addr_INC
INC $01
@done_read_addr_INC:
JMP $80D9
which is more than enough space for a simple copy loop (you're already in bank 6, so no need to worry about swapping banks).
Spoiler:
Code: [Select]
LDX #$0D ; or however long your new string is
@loop:
LDA $9D70,X ; or wherever else you want to read it from
STA $6780,X ; or wherever else you want to write it to
DEX
BPL @loop
RTS
After that, just update $06:$A00C to point to the start of your new string, update the level number write address at $05:$B02F, and it should all work out.

Oh interesting.
You saved up quite a bit of space for new code, amazing.

I implemented the code in xkas for Redux, and while the "DUNGEON-0" text does appear, I cannot seem to be able to make the actual dungeon number to load now. It simply stays as "0" at all times. This is the code itself:

Code: [Select]
// LEVEL-X text changed to "DUNGEON-X"
org $80EC // 0x180FC
inc.b $02
bne write_INC
inc.b $03
write_INC:
inc.b $00
bne read_INC
inc.b $01
read_INC:
jmp $80D9

ldx.b #$09 // New text length
loop:
lda.w $9D70,x
sta.w $6780,x
dex
bpl loop
rts
fillto $8109, $EA

org $A00C // 0x1A01C
dw $83C0 // New string for Dungeons
//org $A02E // 0x1A03E
// dw $83C0 // New string for Dungeons

//org $9D04 // $19D14 - Original location
org $83C0 // 0x183D0
db $20,$56,$09 // Originally $20,$56,$07
db "DUNGEON-0" // Originally "LEVEL-0"
db $FF

bank 5;
// Move Dungeon numeral two tiles to the right (DUNGEON-X)
org $B02F // 0x1703F
    sta $6827 // Originally STA $6825

I tried looking around in RAM around $6780 up to $6840, but I couldn't find anything, other than "LEVEL-X" still being loaded in RAM at $681F.
Did I do something wrong?
Title: Re: Zelda 1 level text
Post by: abw on September 22, 2020, 07:36:35 pm
Yeah, you missed a few things - I was just sketching the outline of one possible solution and left it up to you to fill in the details :P.

Here's a fully-implemented version including ASM source code. (https://drive.google.com/open?id=18aGdsP2IyFc-YrNszh9Zpz39_NSi04hW)
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 23, 2020, 12:48:11 pm
Yeah, you missed a few things - I was just sketching the outline of one possible solution and left it up to you to fill in the details :P.

Here's a fully-implemented version including ASM source code. (https://drive.google.com/open?id=18aGdsP2IyFc-YrNszh9Zpz39_NSi04hW)

Oh nice!
I just downloaded the source and tried it out myself.
However, I'm having issues with this in particular:

Code: [Select]
!level_string_ram_addr = $6C80
The issue is that:
1) xkas doesn't recognize "!", it can only do defines for what I know. So I ditched it and made a "define" for it.
2) Using $6C80 directly in place of "!level_string_ram_addr" makes the game behave in a really glitchy way as soon as you get into the File Select menu. I changed the level_string+11 to $6C8B as well, but it still glitches out the entire game in Redux.
Title: Re: Zelda 1 level text
Post by: abw on September 23, 2020, 02:48:07 pm
1) xkas doesn't recognize "!", it can only do defines for what I know. So I ditched it and made a "define" for it.
That *is* a define :P. I was actually using Asar (a fork of xkas), and as far as I can tell based on their respective documentation xkas has the exact same syntax for defines, so I don't know why it wouldn't recognize "!level_string_ram_addr = $6C80" as a define.

2) Using $6C80 directly in place of "!level_string_ram_addr" makes the game behave in a really glitchy way as soon as you get into the File Select menu. I changed the level_string+11 to $6C8B as well, but it still glitches out the entire game in Redux.
How does the patch generated by xkas differ from the .ips I provided? What happens if you apply it to a clean ROM? I guess I should have also mentioned that I was using the US PRG0 dump as my base, so it's possible there could be a conflict with a different dump or with any other changes you've made for Redux, in which case you'll have to resolve those conflicts (which would probably just mean picking a different address for level_string_ram_addr or level_text, but could potentially be almost anything).
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 23, 2020, 06:01:05 pm
I found the issue. I had this:
Code: [Select]
lda.w $8028,x
lda.b $00

Instead of this:
Code: [Select]
lda.w $8028,x
sta.b $00

Now the game boots.
However, I did find another issue. It seems that the Automap hack is colliding in some form with this implementation.
The Automap seems to be filling sporadically and randomly, like if I go up, normally it should just make the screen you are visible in the Automap, but with this implemented, suddenly I get like 4 screens appearing at once in the Automap tiles. The whole code for it is here:
https://github.com/ShadowOne333/The-Legend-of-Zelda-Redux/blob/master/code/automap.asm

And I noticed it does some writes into $6C00 in RAM, so maybe some things are colliding there.

Aside from that, I noticed that the code you have in .asm file has one byte that differs from the IPS.
In the .asm file, you have the following:
Code: [Select]
jsr copy_level_textBut apparently, in the IPS this very part has a JMP ($20) in its place, instead of JSR ($4C)
Code: [Select]
jmp copy_level_text
Which one of the two is it? JMP or JSR?
Title: Re: Zelda 1 level text
Post by: abw on September 23, 2020, 08:28:44 pm
I found the issue. [...]
Ha, yes, that would definitely cause some problems - glad to see you got it sorted out :thumbsup:!

However, I did find another issue. It seems that the Automap hack is colliding in some form with this implementation.
Looking at that Automap source code, Automap writes a bunch of code to previously unused space starting at 0x19D80, which is where I stuck the new "DUNGEON-0" string. Switching my "org $19D80" to someplace else in bank 6 that still has at least 13 bytes of free space in your hack should be enough to fix that conflict.

In the .asm file, you have the following:
Code: [Select]
jsr copy_level_textBut apparently, in the IPS this very part has a JMP ($20) in its place, instead of JSR ($4C)
Code: [Select]
jmp copy_level_text
Which one of the two is it? JMP or JSR?
It should definitely be JSR, but if you consult an opcode chart, I think you'll find that you've got things backwards and $20 is the opcode for JSR while $4C is the opcode for JMP, so the .asm and the .ips files are both saying the same thing.
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 23, 2020, 08:58:07 pm
Oh I forgot to say, I did move the location of the DUNGEON-0 text to around 19DA0, so it didn't overwrite code there. But the issue still happens even with the text moved to proper free space.
Title: Re: Zelda 1 level text
Post by: abw on September 23, 2020, 09:56:07 pm
Okay, in that case my next guess is 0x18099 - I see Automap changes that to a JMP $FFC0, which conflicts with my patch rearranging 0x18095-0x1809A to save space by avoiding duplication with code starting at 0x180AF. You'll need to do some further optimization to free up space for the "JSR copy_level_text", but that should be pretty easy since (as I said earlier) the original code is pretty bloated.

Any decent IPS patch conflict finder should have been able to point both of those conflicts out immediately.
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 24, 2020, 01:33:19 pm
Oh you're right, I completely overlooked that part of the Automap code.
I did look at it with Advanced Patch Conflict Finder, and indeed, there's a conflict in $18085-$1808B due to a collision between the repoint code and Automap, Automap's being the jmp $FFC0 that should go at $18089.

I tried doing some JMPs and JSRs to $83C0 (free space) to try to make the code there without having to worry about space, but I can't seem to place the Automap's 'jmp $FFC0' in a good enough way to make it work without glitching stuff to oblivion lol.

In the meanwhile, I'll keep the old method of having DUNGEON-0 without the final FF in the original location.
Still, I'll post the xkas code I had here for reference sake.

Code: [Select]
//*************************************
// Change "LEVEL-0" to "DUNGEON-0"
//*************************************

define level_string_ram_addr $6C80

// LEVEL-X text changed to "DUNGEON-X" for text that appears above the Dungeon maps
// Re-arrange existing code to free up space for a JSR to new code
org $8085 // 0x18095
inc.b $11
clear_13_and_RTS:
lda.b #$00
sta.b $13 // jmp $FFC0 for Automap goes here originally
rts

// Original code
ldx.b #$00
lda.w $8028,x
sta.b $00
inx
lda.w $8028,x
sta.b $01
jsr $80C6 // Set up destination start ($02) and end ($04) variables
jsr $80D7 // Read data from ($00) and write it to ($02) through to ($04)
// JSR to call new code and then BRA to continue old code
jsr copy_level_text
bmi clear_13_and_RTS

// Optimize existing code to free up space for a new routine
org $80EC // 0x180FC
inc.b $02
bne write_INC
inc.b $03
write_INC:
inc.b $00
bne read_INC
inc.b $01
read_INC:
jmp $80D9

// New routine to copy the "DUNGEON-X" string from ROM to cartridge RAM
copy_level_text:
ldx.b #$0C // New text length, including PPU address and byte length
// 12 = Length of PPU address (2) + text length (1) + text (9) + string end token (1) - 1 (since we're looping until X == -1)

loop:
lda.w dungeon_text,x
sta.w {level_string_ram_addr},x // $6780
dex
bpl loop
rts
fillto $8109, $EA

// The old "LEVEL-0" string still gets copied to RAM $681C, but is no longer used
org $9D04 // $19D14 - Original location
db $20,$56,$07 // Originally $20,$56,$07
db "LEVEL-0" // Originally "LEVEL-0"
db $FF

// String bytes
org $9D90 // 0x19DA0, Free Space
//dungeon_text:
db $20,$56,$09 // Originally $20,$56,$07
db "DUNGEON-0" // Originally "LEVEL-0"
db $FF

// Update pointer to new string for Dungeons
org $A00C // 0x1A01C
dw {level_string_ram_addr} // Originally $681C

bank 5;
// Move Dungeon numeral two tiles to the right (DUNGEON-X)
org $B02F // 0x1703F
// Update level number write address
sta.w $6827 // Originally STA $6825
Title: Re: Zelda 1 level text
Post by: abw on September 25, 2020, 05:18:22 pm
I tried doing some JMPs and JSRs to $83C0 (free space) to try to make the code there without having to worry about space, but I can't seem to place the Automap's 'jmp $FFC0' in a good enough way to make it work without glitching stuff to oblivion lol.
Or you could just free up some more space :P. I've updated the linked asm + patch to rewrite that entire section of code to free up 48 bytes and leave 0x18099 in its original state, so Automap's JMP won't conflict any more; even after fitting in the new "DUNGEON-0" text (so it no longer consumes 13 bytes of free space at 0x19D80) and the code for copying it, there's still an additional 24 bytes of free space left, so if you wanted to you could move some of Automap's $FFC0 code back to bank 6 and use up less free space from the fixed bank.
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 27, 2020, 07:03:03 pm
@abw sorry I had quite some busy days, and a little health issue yesterday, but I managed to get back to this today.

Just checked the updated code you sent, and damn you really did a lot of work on this.
I don't even know how to thank you for my bothersome nature of me being unable to do a thing on my own in terms of assembly :/

This time I made sure to check everything was in the proper place, checked each opcode in Hex to its corresponding writing, and it seems to be fine.
I also went ahead and tracked down the exact place where the Automap code would be placed, removed some code and added it back, and it seems to work properly with Automap now! First hint was that upon loading, the Automap tiles that I have walked into are still the same as the one I had before the new code, and second hint that it worked properly was that upon discovering a new area, the Automap filled in only the proper square for the current screen Link is in, and not any adjacent ones.

For reference, this is what I modified to make Automap work with your code:

Code: [Select]
// Indirect control flow target
L06_8070:
lda.b $10
asl
tax
lda.w $8014,x
sta.b $00
lda.w $8015,x
sta.b $01
ldy.b #$07
jsr setup_copy_range // Set up copy destination start ($02) and end ($04) variables
jsr L06_80D7 // Read data from ($00) and write it to ($02) through to ($04); exits with Y == #$00
sty.b $13
nop // Maintain original code alignment
L06_8089:
jmp $FFC0 // JMP $FFC0 required by Automap!

I replaced the INC and RTS for the JMP $FFC0, and that did the trick.

So I think this is now properly implemented!
I will make the push into the GitHub, and will credit you for this work in its entirety.

I am even kinda shy to ask this, but I want to ask you @abw, if you are okay with it and are willing to, if I could please ask for your help on the very last thing I want to do for Zelda Redux?
Given how your optimizations on ASM are outstanding, I'm certain that will help to make and close up the very last feature I want to make for it.

Please, let me know if you are interested, and if so, how would you want me to contact you about it.
Title: Re: Zelda 1 level text
Post by: abw on September 27, 2020, 11:43:52 pm
@abw sorry I had quite some busy days, and a little health issue yesterday, but I managed to get back to this today.

Just checked the updated code you sent, and damn you really did a lot of work on this.
I don't even know how to thank you for my bothersome nature of me being unable to do a thing on my own in terms of assembly :/
Eh, no worries. Stuff happens, and different things come easier to different people. Staying healthy is more important than ROM hacking any day of the week! (...cuz it lets you do more ROM hacking later)

I am even kinda shy to ask this, but I want to ask you @abw, if you are okay with it and are willing to, if I could please ask for your help on the very last thing I want to do for Zelda Redux?
Given how your optimizations on ASM are outstanding, I'm certain that will help to make and close up the very last feature I want to make for it.

Please, let me know if you are interested, and if so, how would you want me to contact you about it.
Possibly. What is this very last thing that you had in mind? I'm guessing it'll be mentioned somewhere in the Redux thread, but I haven't been following that much and don't really want to wade through all 400+ posts to find it :D. Based on the to-do list in the first post, it looks like your next focus is some graphical stuff, which is not exactly my forte, but I can take a look and see if there's anything that sounds easy for me.
Title: Re: Zelda 1 level text
Post by: ShadowOne333 on September 30, 2020, 01:33:29 am
Neat! I sent you a PM with what's left for the project :)
Title: Re: Zelda 1 level text
Post by: abw on September 30, 2020, 09:32:52 pm
Replied!