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

Author Topic: Zelda 2 widening dialog pane  (Read 5672 times)

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Zelda 2 widening dialog pane
« on: April 21, 2013, 01:06:22 pm »
I've made the dialog box taller but, is there any way to widen it so i can at least input 12 letters instead of 11 without it going on to the dialog pane?

I'm thinking the solution lies with these pointers for the lines for content at F425 - F432.
Am I on the right track here?

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7002
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Zelda 2 widening dialog pane
« Reply #1 on: April 21, 2013, 01:16:50 pm »
Probably. You'd need to change the VRAM address it writes the characters to, to move the starting position one tile to the left.
(the VRAM address is set by writing the high and then low bytes consecutively to $2006.
Seeing as the game writes one character at a time, it probably has a variable to control the address. Try tracing the game drawing, and look for writes to $2006.)
"My watch says 30 chickens" Google, 2018

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Zelda 2 widening dialog pane
« Reply #2 on: April 21, 2013, 08:28:10 pm »
Well, seeing as how my skill 6502 asm is just a smidge above zero... I'm having trouble understanding these two routine. Meaning that while I traced the dialog box and the text and logged the data that deals with 2006 it to a file. I'm at a loss as to what all this means. I was hoping to find the variable in the somewhere... I think it's A0 00 but I am not sure how to change it.

Code: [Select]
A:FF X:00 Y:00 S:FB P:nvUBdIZC     $C0DC:A9 3F     LDA #$3F
A:3F X:00 Y:00 S:FB P:nvUBdIzC     $C0DE:8D 06 20  STA $2006 = #$48
A:3F X:00 Y:00 S:FB P:nvUBdIzC     $C0E1:A0 00     LDY #$00
A:3F X:00 Y:00 S:FB P:nvUBdIZC     $C0E3:8C 06 20  STY $2006 = #$48
A:3F X:00 Y:00 S:FB P:nvUBdIZC     $C0E6:8C 06 20  STY $2006 = #$00
A:3F X:00 Y:00 S:FB P:nvUBdIZC     $C0E9:8C 06 20  STY $2006 = #$00
A:3F X:00 Y:00 S:FB P:nvUBdIZC     $C0EC:AD 68 07  LDA $0768 = #$06
A:06 X:00 Y:00 S:FB P:nvUBdIzC     $C0EF:D0 12     BNE $C103
A:06 X:00 Y:00 S:FB P:nvUBdIzC     $C103:A5 FE     LDA $00FE = #$1E
A:1E X:00 Y:00 S:FB P:nvUBdIzC     $C105:8D 01 20  STA $2001 = #$00
A:1E X:00 Y:00 S:FB P:nvUBdIzC     $C108:AE 25 07  LDX $0725 = #$00
A:1E X:00 Y:00 S:FB P:nvUBdIZC     $C10B:F0 0F     BEQ $C11C
A:1E X:00 Y:00 S:FB P:nvUBdIZC     $C11C:BE 5D C0  LDX $C05D,Y @ $C05D = #$00
A:1E X:00 Y:00 S:FB P:nvUBdIZC     $C11F:A9 00     LDA #$00
A:00 X:00 Y:00 S:FB P:nvUBdIZC     $C121:9D 01 03  STA $0301,X @ $0301 = #$00
A:00 X:00 Y:00 S:FB P:nvUBdIZC     $C124:A9 FF     LDA #$FF
A:FF X:00 Y:00 S:FB P:NvUBdIzC     $C126:9D 02 03  STA $0302,X @ $0302 = #$FF
A:FF X:00 Y:00 S:FB P:NvUBdIzC     $C129:AD 25 07  LDA $0725 = #$00
A:00 X:00 Y:00 S:FB P:nvUBdIZC     $C12C:8D 25 07  STA $0725 = #$00
A:00 X:00 Y:00 S:FB P:nvUBdIZC     $C12F:20 C1 C1  JSR $C1C1


Code: [Select]
A:24 X:02 Y:00 S:F9 P:nvUBdIzc       $D2F4:C9 4C     CMP #$4C
A:24 X:02 Y:00 S:F9 P:NvUBdIzc       $D2F6:D0 0F     BNE $D307
A:24 X:02 Y:00 S:F9 P:NvUBdIzc       $D307:AE 02 20  LDX $2002 = #$55
A:24 X:55 Y:00 S:F9 P:nvUBdIzc       $D30A:8D 06 20  STA $2006 = #$48
A:24 X:55 Y:00 S:F9 P:nvUBdIzc       $D30D:C8        INY
A:24 X:55 Y:01 S:F9 P:nvUBdIzc       $D30E:B1 00     LDA ($00),Y @ $0364 = #$CE
A:CE X:55 Y:01 S:F9 P:NvUBdIzc       $D310:8D 06 20  STA $2006 = #$48
A:CE X:55 Y:01 S:F9 P:NvUBdIzc       $D313:C8        INY
A:CE X:55 Y:02 S:F9 P:nvUBdIzc       $D314:B1 00     LDA ($00),Y @ $0365 = #$0E
A:0E X:55 Y:02 S:F9 P:nvUBdIzc       $D316:0A        ASL
A:1C X:55 Y:02 S:F9 P:nvUBdIzc       $D317:48        PHA
A:1C X:55 Y:02 S:F8 P:nvUBdIzc        $D318:A5 FF     LDA $00FF = #$30
A:30 X:55 Y:02 S:F8 P:nvUBdIzc        $D31A:09 04     ORA #$04
A:34 X:55 Y:02 S:F8 P:nvUBdIzc        $D31C:B0 02     BCS $D320
A:34 X:55 Y:02 S:F8 P:nvUBdIzc        $D31E:29 FB     AND #$FB
A:30 X:55 Y:02 S:F8 P:nvUBdIzc        $D320:8D 00 20  STA $2000 = #$30
A:30 X:55 Y:02 S:F8 P:nvUBdIzc        $D323:68        PLA
A:1C X:55 Y:02 S:F9 P:nvUBdIzc       $D324:0A        ASL
A:38 X:55 Y:02 S:F9 P:nvUBdIzc       $D325:90 03     BCC $D32A
A:38 X:55 Y:02 S:F9 P:nvUBdIzc       $D32A:4A        LSR
A:1C X:55 Y:02 S:F9 P:nvUBdIzc       $D32B:4A        LSR
A:0E X:55 Y:02 S:F9 P:nvUBdIzc       $D32C:AA        TAX
A:0E X:0E Y:02 S:F9 P:nvUBdIzc       $D32D:B0 01     BCS $D330
A:0E X:0E Y:02 S:F9 P:nvUBdIzc       $D32F:C8        INY
A:0E X:0E Y:03 S:F9 P:nvUBdIzc       $D330:B1 00     LDA ($00),Y @ $0366 = #$CA
A:CA X:0E Y:03 S:F9 P:NvUBdIzc       $D332:8D 07 20  STA $2007 = #$68
A:CA X:0E Y:03 S:F9 P:NvUBdIzc       $D335:CA        DEX
A:CA X:0D Y:03 S:F9 P:nvUBdIzc       $D336:D0 F5     BNE $D32D


Pennywise

  • Hero Member
  • *****
  • Posts: 2327
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: Zelda 2 widening dialog pane
« Reply #3 on: April 22, 2013, 12:26:30 pm »
I don't know the specifics of the game, so I don't know if you're on the right track or not. That said 2 writes to $2006 set the PPU address and a write to $2007 writes A to the screen on the PPU address etc. They're very important registers for the NES. What I would do is first determine where in the PPU/nametable etc your text box is stored. I would then set a PPU breakpoint to that location to find out how it gets there. Maybe you've already got part of it in that code. If 24CE is where the box appears, then yes.

Turambar

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Re: Zelda 2 widening dialog pane
« Reply #4 on: April 23, 2013, 11:25:06 am »
I always wanted to expand the text boxes in this game but never had much success.
I tried to disassemble the game, but all the disassemblers that I used didn't work.
I would be interested in pouring through the disassembled code if I had it.

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Zelda 2 widening dialog pane
« Reply #5 on: April 24, 2013, 03:22:43 am »
You can trace and dump the code with fceux. If only meka had something like that.
« Last Edit: April 24, 2013, 04:28:35 am by Pikachumanson »

Trax

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 563
    • View Profile
    • Trax ROM Hacking
Re: Zelda 2 widening dialog pane
« Reply #6 on: April 24, 2013, 06:57:24 pm »
I worked on this quite a lot, and it's not as easy as it seems, although the basic reasoning is there. I tried many things and it seemed I was always bumping into problems. I'm not saying it's impossible, but it's contrived. Here's my observations:

- There are two pointers in the ROM that point to a series of bytes that are Tile Mapping Codes for the outline of the box. The box is made of two types of "lines": either the top/bottom, or something inbetween. These values are all stored at once, somewhere into CPU RAM before being fed to the PPU, which is a big hassle in itself, since the memory immediately following is not unused. I tried to simply change the variable that controls the loop and add bytes to the two types of lines, but it's not that simple. You will probably end up with unwanted corruption of RAM values...

- After the box is dismissed, the game must redraw what was behind, which is not trivial either. There's a lot of manipulation at the bits level because of the way the palette mappings are coded on the NES. Even when the box is simply moved to another location (which is something you have to do anyway since you want its X origin to be moved to the left), you get color artifacts either when the box is drawn, or when the box is dismissed, or both...

- I had one success through all this turmoil: it's possible, with minimal modifications of existing bytes in the code, to make the text not skip a line. This is okay for English, since you don't have the need for accented characters, which is not the case for, say, Japanese. Even the US version of the game still has the orphaned code to generate Japanese accents in the space between lines of text, but the game simply never use it. This does not solve the problem of short words, but at least you can cram more text in the box...

Here's the data pertaining to the dialog box visual:

F3F3: Pointer table for rows of dialog box (A * 2 = 14 bytes)

07B4 -> F407
15B4 -> F415
15B4 -> F415
15B4 -> F415
15B4 -> F415
15B4 -> F415
15B4 -> F415
15B4 -> F415
15B4 -> F415
07B4 -> F407

----

Tables for dialog box rows tile mappings (1C bytes)

F407: CA CB CB CB CB CB CB CB CB CB CB CB CB CA   Row Type 1
F415: CC F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 CC   Row Type 2


For each of the 10 rows of the box, the pointers at $F3F3 are loaded, 2 at a time (row 0-A, then 1-B, and so on), then the corresponding row's bytes are loaded into RAM at $053E and $054C, to be drawn later. Remember that some palette mappings need to be modified if you want uniform colors for your text box, so the old ones must be kept somewhere in memory. There's a routine for that. This is Hell, my friends...

Make sure you take a serious look at the pointer table at $F0B1. It's a table that contains 11 pointers related to the routines used for dialogs. Sound, tile loading, palette mappings loading, etc. This is a good start if you want to trace the code...

As usual, you can always peek into my own complete disassembly of Bank 3. There are a few comments in there which could be useful...

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Zelda 2 widening dialog pane
« Reply #7 on: April 26, 2013, 10:30:16 am »
Thanx Trax! Hopefully I can figure out something! I would love to expand this here:

Tables for dialog box rows tile mappings (1C bytes)

F407: CA CB CB CB CB CB CB CB CB CB CB CB CB CA   Row Type 1
F415: CC F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 CC   Row Type 2

But that area is so crammed with code it's really hard to do anything. Culdn't I just move that routine and rewrite the whole routine to make room for more  CB's and F4's?

Trax

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 563
    • View Profile
    • Trax ROM Hacking
Re: Zelda 2 widening dialog pane
« Reply #8 on: April 29, 2013, 03:27:01 pm »
You're quite welcome...

Pikachumanson, I can tell you right off the bat that your idea of extending the line bytes will not work. That's exactly what I did in the first place when I tried to do something about the dialog pane's width. Your hypothesis is sound, but the mechanics of the dialog pane doesn't work like that, unfortunately. The reason it doesn't work is because the bytes used in the tables at F407 and F515 are not fed to the PPU directly. They are loaded in RAM first, then used to create a PPU macro in the 3xx range...

The first RAM addresses used are 53E-54B and 54C-559. The loading routine starts at F0D2. Each row is E tiles wide. If you try to extend the line's number of bytes, you will overwrite a part of the second range, and overwrite other important bytes beyond the second range...

The actual letter bytes are loaded using the routine at F6DD. At this point, RAM addresses 301 to 307 are used to construct a PPU macro that will draw the letter, and the optional accented character above (which never happens in the US version). The dialog box is drawn in a similar way. So a viable option would be to construct a custom PPU macro to draw each line of the box, and make it the width we want...

Trax

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 563
    • View Profile
    • Trax ROM Hacking
Re: Zelda 2 widening dialog pane
« Reply #9 on: May 14, 2013, 12:19:51 am »
I tried to use the Cartridge RAM instead of CPU RAM to store the tiles that make the individual rows of the dialog box. It does work, but there are lots of other things to take into account. The palettes temporary changes need to be adapted to the box's width as well, as this screenshot shows:



I tried to add 4 extra tiles to the box's width. You can see that the original palette is not changed on the right, because I only modified the X offset of the loops that color the box. The colors still match the background. And when the box is dismissed, we get garbage stamped on the background because some memory bytes are overwritten. It needs work, but it doesn't seem completely impossible...

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Zelda 2 widening dialog pane
« Reply #10 on: May 14, 2013, 12:47:09 am »
Oh God i hope you are successful in perfecting that!

KillerBob

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: Zelda 2 widening dialog pane
« Reply #11 on: June 13, 2013, 05:47:29 pm »
This is awesome work Trax, damn I hope you solve this issue with the dialog boxes, have long dreamt about making a de-engrished version and inserting a more complete English script, it took quite a hit from the space limitation.

Btw, any idea what causes the flickering on the title screen, seen right above the water in the right part of the frame, is it a bug of some sort? Not present in the original FDS version of the game.

Also, any complete text tbl-files out there? the one on datacrystal seems to be incomplete. The comma can only be used in the title text, the in-game text comma is different and is included in the graphics but was never used, have trouble locating it. The game also lack an apostrophe but that can of course easily be fixed by editing the leftover interpunct character from the Japanese game listed as 32=* in the tbl-file.

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 593
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: Zelda 2 widening dialog pane
« Reply #12 on: June 13, 2013, 06:50:08 pm »
If you feel that the table file on Data Crystal could be improved, I highly encourage you to update it. It is a wiki.  :)

Trax

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 563
    • View Profile
    • Trax ROM Hacking
Re: Zelda 2 widening dialog pane
« Reply #13 on: June 17, 2013, 02:49:04 am »
If anyone has info on that particular piece of code, please let us know. The answer will not spring out of nowhere...

The code is in Bank 3, dialog pointer list is at F0B1 and has 11 pointers. The code uses many kind of arithmetic manipulations to account for Name Table overlap. Some data is stored temporarily in RAM, so you need to move that to somewhere else (because longer box means more RAM space needed), probably in Cartridge RAM (6000-7FFF), where there's more potential free space...

Also, it seems that some of the code that is used for the Dialog Boxes is also used for the Pause Pane, so we need to keep this in mind as well...