+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  Having trouble with a double line hack
Pages: [1]
Author Topic: Having trouble with a double line hack  (Read 1 times)
Kagemusha
Guest
« on: July 11, 2010, 02:17:39 pm »

The execution of the code is all good, but the new line break doesn't want to go where I want it to. I guess the whole setup goes something like this

+
-
+
-
+
-

It doesn't want to go where the -'s are and I can't for the life of me figure it out.
DarknessSavior
Guest
« Reply #1 on: July 11, 2010, 04:24:37 pm »

You might try posting some of the code. Cheesy

~DS
Kagemusha
Guest
« Reply #2 on: July 11, 2010, 04:46:15 pm »

Alright, I'll do that, but it might be a little lengthy.

Code:
$C527:AE B2 03  LDX $03B2 = #$01           A:2F X:00 Y:22 S:F1 P:nvUbdizC
$C52A:F0 04     BEQ $C530                  A:2F X:01 Y:22 S:F1 P:nvUbdizC
$C52C:CA        DEX                        A:2F X:01 Y:22 S:F1 P:nvUbdizC
$C52D:F0 0F     BEQ $C53E                  A:2F X:00 Y:22 S:F1 P:nvUbdiZC
$C53E:20 E1 C5  JSR $C5E1                  A:2F X:00 Y:22 S:F1 P:nvUbdiZC
$C5E1:AD B1 03  LDA $03B1 = #$B6           A:2F X:00 Y:22 S:EF P:nvUbdiZC
$C5E4:29 07     AND #$07                   A:B6 X:00 Y:22 S:EF P:NvUbdizC
$C5E6:8D 19 00  STA $0019 = #$07           A:06 X:00 Y:22 S:EF P:nvUbdizC
$C5E9:EE 19 00  INC $0019 = #$06           A:06 X:00 Y:22 S:EF P:nvUbdizC
$C5EC:AD B1 03  LDA $03B1 = #$B6           A:06 X:00 Y:22 S:EF P:nvUbdizC
$C5EF:4A        LSR                        A:B6 X:00 Y:22 S:EF P:NvUbdizC
$C5F0:4A        LSR                        A:5B X:00 Y:22 S:EF P:nvUbdizc
$C5F1:29 0E     AND #$0E                   A:2D X:00 Y:22 S:EF P:nvUbdizC
$C5F3:18        CLC                        A:0C X:00 Y:22 S:EF P:nvUbdizC
$C5F4:69 02     ADC #$02                   A:0C X:00 Y:22 S:EF P:nvUbdizc
$C5F6:8D 1A 00  STA $001A = #$0E           A:0E X:00 Y:22 S:EF P:nvUbdizc
$C5F9:60        RTS                        A:0E X:00 Y:22 S:EF P:nvUbdizc
$C541:AC B4 03  LDY $03B4 = #$22           A:0E X:00 Y:22 S:F1 P:nvUbdizc
$C544:60        RTS                        A:0E X:00 Y:22 S:F1 P:nvUbdizc
$C51B:98        TYA                        A:0E X:00 Y:22 S:F3 P:nvUbdizc
$C51C:29 1F     AND #$1F                   A:22 X:00 Y:22 S:F3 P:nvUbdizc
$C51E:F0 06     BEQ $C526                  A:02 X:00 Y:22 S:F3 P:nvUbdizc
$C520:20 4E C5  JSR $C54E                  A:02 X:00 Y:22 S:F3 P:nvUbdizc
$C54E:98        TYA                        A:02 X:00 Y:22 S:F1 P:nvUbdizc
$C54F:29 E0     AND #$E0                   A:22 X:00 Y:22 S:F1 P:nvUbdizc
$C551:18        CLC                        A:20 X:00 Y:22 S:F1 P:nvUbdizc
$C552:69 20     ADC #$20                   A:20 X:00 Y:22 S:F1 P:nvUbdizc
$C554:A8        TAY                        A:40 X:00 Y:22 S:F1 P:nvUbdizc
$C555:4A        LSR                        A:40 X:00 Y:40 S:F1 P:nvUbdizc
$C556:4A        LSR                        A:20 X:00 Y:40 S:F1 P:nvUbdizc
$C557:4A        LSR                        A:10 X:00 Y:40 S:F1 P:nvUbdizc
$C558:4A        LSR                        A:08 X:00 Y:40 S:F1 P:nvUbdizc
$C559:CD 1A 00  CMP $001A = #$0E           A:04 X:00 Y:40 S:F1 P:nvUbdizc
$C55C:90 02     BCC $C560                  A:04 X:00 Y:40 S:F1 P:NvUbdizc
$C560:60        RTS                        A:04 X:00 Y:40 S:F1 P:NvUbdizc
$C523:20 61 C5  JSR $C561                  A:04 X:00 Y:40 S:F3 P:NvUbdizc
$C561:AE B2 03  LDX $03B2 = #$01           A:04 X:00 Y:40 S:F1 P:NvUbdizc
$C564:F0 04     BEQ $C56A                  A:04 X:01 Y:40 S:F1 P:nvUbdizc
$C566:CA        DEX                        A:04 X:01 Y:40 S:F1 P:nvUbdizc
$C567:F0 0B     BEQ $C574                  A:04 X:00 Y:40 S:F1 P:nvUbdiZc
$C574:8C B4 03  STY $03B4 = #$22           A:04 X:00 Y:40 S:F1 P:nvUbdiZc
$C577:60        RTS                        A:04 X:00 Y:40 S:F1 P:nvUbdiZc

That's the whole thing though for how line breaks function. To make it look like less, I've gotten rid of the excess, which shouldn't have been included in the first place. I just need some help with this because I haven't been able to figure out the problem yet.
« Last Edit: July 12, 2010, 04:45:55 pm by Pennywise »
Nightcrawler
Guest
« Reply #3 on: July 13, 2010, 07:26:45 am »

Ok.. So now you've pasted some code. Great. However, you've not told us a single thing about it. Do you know anything about the above code? What any of those addresses are?  You haven't even told us what the game is currently doing instead of what you expect. How about what the line break control code even IS? I don't think you're going to get much help like this...
Kagemusha
Guest
« Reply #4 on: July 13, 2010, 01:20:08 pm »

Yeah, I realize that. But to answer, the control code value is 2f and the ADC #$20 is key to where in the PPU the new line is written. Normally, all I would have to do is not add anything and the new line wouldn't skip a line and would be directly under the text. However, I think I was wrong to think the problem came from this particular piece of code as relevant to line break as it may be. It doesn't actually write anything to the PPU. Every single letter is written and its PPU coordinates are loaded in RAM and then written to the PPU. I've actually gotten the double line to work with some cheats altering the PPU coordinates.

But then again I could be wrong. The cheat I used changed the ppu coordinates stored in $04FA-$05xx, but those coordinates go through $0038 and $0039 before reaching $04FA. On top of that before the ppu goes through $0038, I think the coordinates are written to $0019.

Edit:

I've managed to locate what I consider very important code.

Code:
$F58B:AD 1B 00  LDA $001B = #$16           A:00 X:23 Y:00 S:E6 P:nvUbdiZc
$F58E:29 1F     AND #$1F                   A:16 X:23 Y:00 S:E6 P:nvUbdizc
$F590:8D 38 00  STA $0038 = #$D8           A:16 X:23 Y:00 S:E6 P:nvUbdizc
$F593:AD 1C 00  LDA $001C = #$08           A:16 X:23 Y:00 S:E6 P:nvUbdizc
$F596:8D 39 00  STA $0039 = #$20           A:08 X:23 Y:00 S:E6 P:nvUbdizc
$F599:38        SEC                        A:08 X:23 Y:00 S:E6 P:nvUbdizc
$F59A:A9 00     LDA #$00                   A:08 X:23 Y:00 S:E6 P:nvUbdizC
$F59C:6E 39 00  ROR $0039 = #$08           A:00 X:23 Y:00 S:E6 P:nvUbdiZC
$F59F:6A        ROR                        A:00 X:23 Y:00 S:E6 P:NvUbdizc
$F5A0:4E 39 00  LSR $0039 = #$84           A:00 X:23 Y:00 S:E6 P:nvUbdiZc
$F5A3:6A        ROR                        A:00 X:23 Y:00 S:E6 P:nvUbdizc
$F5A4:4E 39 00  LSR $0039 = #$42           A:00 X:23 Y:00 S:E6 P:nvUbdiZc
$F5A7:6A        ROR                        A:00 X:23 Y:00 S:E6 P:nvUbdizc
$F5A8:0D 38 00  ORA $0038 = #$16           A:00 X:23 Y:00 S:E6 P:nvUbdiZc
$F5AB:8D 38 00  STA $0038 = #$16           A:16 X:23 Y:00 S:E6 P:nvUbdizc
$F5AE:AD 3D 00  LDA $003D = #$88           A:16 X:23 Y:00 S:E6 P:nvUbdizc
$F5B1:0A        ASL                        A:88 X:23 Y:00 S:E6 P:NvUbdizc
$F5B2:0A        ASL                        A:10 X:23 Y:00 S:E6 P:nvUbdizC
$F5B3:29 0C     AND #$0C                   A:20 X:23 Y:00 S:E6 P:nvUbdizc
$F5B5:0D 39 00  ORA $0039 = #$21           A:00 X:23 Y:00 S:E6 P:nvUbdiZc
$F5B8:8D 39 00  STA $0039 = #$21           A:21 X:23 Y:00 S:E6 P:nvUbdizc
$F5BB:60        RTS                        A:21 X:23 Y:00 S:E6 P:nvUbdizc
$F580:AD 1D 00  LDA $001D = #$CE           A:21 X:23 Y:00 S:E8 P:nvUbdizc

As I've mentioned before, $0038-39 are where the PPU addresses are stored and $2116 is the location for where the text starts after the line break. I've think I've been able to figure out how they're calculated.

Code:
$C594:A9 00     LDA #$00                   A:40 X:03 Y:00 S:EA P:nvUbdizc
$C596:0E 1B 00  ASL $001B = #$40           A:00 X:03 Y:00 S:EA P:nvUbdiZc
$C599:2A        ROL                        A:00 X:03 Y:00 S:EA P:NvUbdizc
$C59A:0E 1B 00  ASL $001B = #$80           A:00 X:03 Y:00 S:EA P:nvUbdiZc
$C59D:2A        ROL                        A:00 X:03 Y:00 S:EA P:nvUbdiZC
$C59E:0E 1B 00  ASL $001B = #$00           A:01 X:03 Y:00 S:EA P:nvUbdizc
$C5A1:2A        ROL                        A:01 X:03 Y:00 S:EA P:nvUbdiZc
$C5A2:0A        ASL                        A:02 X:03 Y:00 S:EA P:nvUbdizc
$C5A3:18        CLC                        A:04 X:03 Y:00 S:EA P:nvUbdizc
$C5A4:7D DB C5  ADC $C5DB,X @ $C5DE = #$04 A:04 X:03 Y:00 S:EA P:nvUbdizc
$C5A7:E8        INX                        A:08 X:03 Y:00 S:EA P:nvUbdizc
$C5A8:8D 1C 00  STA $001C = #$06           A:08 X:04 Y:00 S:EA P:nvUbdizc
$C5AB:AD 1B 00  LDA $001B = #$00           A:08 X:04 Y:00 S:EA P:nvUbdizc
$C5AE:4A        LSR                        A:00 X:04 Y:00 S:EA P:nvUbdiZc
$C5AF:4A        LSR                        A:00 X:04 Y:00 S:EA P:nvUbdiZc
$C5B0:4A        LSR                        A:00 X:04 Y:00 S:EA P:nvUbdiZc
$C5B1:18        CLC                        A:00 X:04 Y:00 S:EA P:nvUbdiZc
$C5B2:7D DB C5  ADC $C5DB,X @ $C5DF = #$16 A:00 X:04 Y:00 S:EA P:nvUbdiZc
$C5B5:E8        INX                        A:16 X:04 Y:00 S:EA P:nvUbdizc
$C5B6:8D 1B 00  STA $001B = #$00           A:16 X:05 Y:00 S:EA P:nvUbdizc

So at $C5DE is sort of the vertical offset variable and DF is the horizontal one. The text after the line break starts on the 8th row of tiles.  Now the problem that I have is that this code is executed after the code that I posted in the first post. I also think I've found the problem. The calculation for the vertical offset gets messed up. So in the case of the the double line hack, $03B4 would be reduced to 20, but the calculation ends up making it appear on the 6th line down, which is the same line as the text started on. Currently I'm going with a two part hack, first the A is reduced to 20 for the first piece of code and then I set a check for 20 at C594. Unfortunately I haven't been able to get it to work yet, but I hope I'm on the right path.
« Last Edit: July 13, 2010, 10:28:14 pm by Pennywise »
Trax
Guest
« Reply #5 on: July 24, 2010, 01:07:53 am »

What's the game, just in case?...
Or is it your own code?
Kagemusha
Guest
« Reply #6 on: July 24, 2010, 06:40:05 pm »

That code is from Jesus Kyoufu no Biomonster for the NES. One of the problems I ran into was that my new code was executing when I didn't want it to. That was because the first character of the string triggered a branch for a CMP $20 when under normal circumstances it should have been a $40 instead. To be fair the game's really evil. That's not my code btw. I think one of issues that I have to modify the code in several places just to get the hack to work.
« Last Edit: July 24, 2010, 07:23:08 pm by Pennywise »
RedComet
Guest
« Reply #7 on: July 25, 2010, 12:34:52 am »

Here's what you do. Get the text on screen complete with slightly messed up line break. Next, open up the PPU in the hex editor and find where the line starts in the tilemap. Okay, now get the line break to occur again (set a breakpoint for the control code read) and then set a write break point for the tilemap address in the PPU. Now log all the instructions from there until the tilemap is written to. Then just work backwards through the log and find out when exactly that pesky variable is changed.

I've found with most things hacking related (or anything that requires problem solving), when in doubt start with what you know and work backwards. No reason to start at the beginning (i.e. the problem) because you don't know what the problem is exactly (where it's at)! So all you have is the ending (the results) to go on.

Hope that helps.
Trax
Guest
« Reply #8 on: July 25, 2010, 01:26:15 pm »

Here's what comes to mind when seeing this. If it's what I think, I had the same problem with Zelda II text engine. Instead of the text tiles being added to the screen one by one, it is added in blocks of 2x2. The "writing head" is 2x2 tiles, it moves right 1 tile for the next letter, but for a line break, it moves 2 tiles down. That's my hypothesis. Here's a picture that illustrates what I'm saying...

The yellow lines are the actual 2-tile lines that the engine writes on. The red square represents the writing head. The engine sets the character tile to the bottom-left corner of the writing head, and, if applicable, an accent tile just over it. Then it moves 1 tile to the right for the next letter. When a line break occurs, the writing head goes back to the beginning of a line and goes down 2 tiles...

If this is all accurate, then your aim would be:

1) Offset the writing head 1 tile down.
2) Change the RAM offsets used so that the character to insert would be in the upper-left corner of the writing head, instead of the bottom-left.
3) Make the writing head go down 1 tile when a line break occurs, instead of 2 tiles.

« Last Edit: July 25, 2010, 02:12:46 pm by Trax »
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC