News: 11 March 2016 - Forum Rules

Author Topic: Dragon Ball Z - Legend Of The Super Saiyan?  (Read 8205 times)

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Dragon Ball Z - Legend Of The Super Saiyan?
« on: November 19, 2012, 02:24:41 am »
Has anyone ever messed with the sprites or tilesets or anything in this game?  I've been trying to trace the code down to see if I can load everything decompressed (Considering this game is absolutely small and has very VERY few graphics, it'd be easier).

I'm literally so lost on how this code even works so I'm curious to see if anyone else has tried messing with this game.

(I hope to do something with this if I can.  There's so much that needs to be changed.)
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

DarknessSavior

  • Hero Member
  • *****
  • Posts: 5031
  • Darkness.
    • View Profile
    • DS: No, not the Nintendo one.
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #1 on: November 19, 2012, 08:03:19 pm »
If you manage to get any work done on this and need a translator, lemme know. I would LOVE to do it. Loved the DBZ RPGs since I first started getting into emulation way back in the day.

~DS
Red Comet: :'( Poor DS. Nobody loves him like RC does. :'(
Sliver-X: LET ME INFRINGE UPON IT WITH MY MOUTH
DSRH - Currently working on: Demon's Blazon, Romancing SaGa, FFIV EasyType.
http://www.youtube.com/user/DarknessSavior

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #2 on: November 19, 2012, 09:27:53 pm »
I would love, LOVE to heavily re-do this game so badly, which is why I was trying to figure out how the graphics load and force them to load decompressed so they could be edited real-time by anyone to mod.  Considering this game has well more than enough room to do so in it's original form, it'd be a blast to expand it to 6 megs and have all that extra room for new animations and what not.

I've been rather dumbfounded by how this game loads it's graphics though.  Either I'm not reading the code correctly or it's obnoxiously convoluted, which is why I was hoping someone had any experience with this game and knew how it that worked.

Code: [Select]
$00/881A B7 00       LDA [$00],y[$02:8333]   A:0000 X:9540 Y:0001 P:envMxdIZc - ???
$00/881C 85 1E       STA $1E    [$00:001E]   A:0001 X:9540 Y:0001 P:envMxdIzc
$00/881E C9 FF       CMP #$FF                A:0001 X:9540 Y:0001 P:envMxdIzc
$00/8820 D0 01       BNE $01    [$8823]      A:0001 X:9540 Y:0001 P:envMxdIzc
$00/8823 C8          INY                     A:0001 X:9540 Y:0001 P:envMxdIzc
$00/8824 84 22       STY $22    [$00:0022]   A:0001 X:9540 Y:0002 P:envMxdIzc
$00/8826 C2 20       REP #$20                A:0001 X:9540 Y:0002 P:envMxdIzc
$00/8828 0A          ASL A                   A:0001 X:9540 Y:0002 P:envmxdIzc
$00/8829 0A          ASL A                   A:0002 X:9540 Y:0002 P:envmxdIzc
$00/882A AA          TAX                     A:0004 X:9540 Y:0002 P:envmxdIzc
$00/882B BF C4 83 02 LDA $0283C4,x[$02:83C8] A:0004 X:0004 Y:0002 P:envmxdIzc - Loads 2-Byte pointer for sprites
$00/882F 85 83       STA $83    [$00:0083]   A:81F7 X:0004 Y:0002 P:eNvmxdIzc
$00/8831 E8          INX                     A:81F7 X:0004 Y:0002 P:eNvmxdIzc
$00/8832 E8          INX                     A:81F7 X:0005 Y:0002 P:envmxdIzc
$00/8833 BF C4 83 02 LDA $0283C4,x[$02:83CA] A:81F7 X:0006 Y:0002 P:envmxdIzc
$00/8837 85 20       STA $20    [$00:0020]   A:0300 X:0006 Y:0002 P:envmxdIzc
$00/8839 E2 20       SEP #$20                A:0300 X:0006 Y:0002 P:envmxdIzc
$00/883B A9 0F       LDA #$0F                A:0300 X:0006 Y:0002 P:envMxdIzc - Bank of sprites
$00/883D 85 85       STA $85    [$00:0085]   A:030F X:0006 Y:0002 P:envMxdIzc
$00/883F A9 80       LDA #$80                A:030F X:0006 Y:0002 P:envMxdIzc
$00/8841 8D 15 21    STA $2115  [$00:2115]   A:0380 X:0006 Y:0002 P:eNvMxdIzc
$00/8844 22 59 C5 00 JSL $00C559[$00:C559]   A:0380 X:0006 Y:0002 P:eNvMxdIzc
$00/C559 08          PHP                     A:0380 X:0006 Y:0002 P:eNvMxdIzc
$00/C55A 8B          PHB                     A:0380 X:0006 Y:0002 P:eNvMxdIzc
$00/C55B E2 20       SEP #$20                A:0380 X:0006 Y:0002 P:eNvMxdIzc
$00/C55D C2 10       REP #$10                A:0380 X:0006 Y:0002 P:eNvMxdIzc
$00/C55F A2 00 90    LDX #$9000              A:0380 X:0006 Y:0002 P:eNvMxdIzc
$00/C562 86 86       STX $86    [$00:0086]   A:0380 X:9000 Y:0002 P:eNvMxdIzc
$00/C564 A9 7E       LDA #$7E                A:0380 X:9000 Y:0002 P:eNvMxdIzc
$00/C566 85 88       STA $88    [$00:0088]   A:037E X:9000 Y:0002 P:envMxdIzc
$00/C568 A4 83       LDY $83    [$00:0083]   A:037E X:9000 Y:0002 P:envMxdIzc
$00/C56A A5 85       LDA $85    [$00:0085]   A:037E X:9000 Y:81F7 P:eNvMxdIzc
$00/C56C 48          PHA                     A:030F X:9000 Y:81F7 P:envMxdIzc
$00/C56D AB          PLB                     A:030F X:9000 Y:81F7 P:envMxdIzc
$00/C56E BE 00 00    LDX $0000,y[$0F:81F7]   A:030F X:9000 Y:81F7 P:envMxdIzc - Sprite Data

I'm not even honestly sure on this code.  I'm so horrifically confused with it. :|  I don't understand what's going on at F81F7 either . It's just.. kind of a mess.
« Last Edit: November 19, 2012, 11:07:47 pm by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

LostTemplar

  • Hero Member
  • *****
  • Posts: 910
    • View Profile
    • au-ro-ra.net
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #3 on: November 20, 2012, 05:51:15 am »
For whatever reason, my ROM has some of the code off by 4 bytes, but okay.

Anyway, it actually looks pretty straight forward to me. Beginning where you left off, the game decompresses the graphics to $7e9000 with LZSS+RLE, if I'm not mistaken (I only took a quick look at it). If you have any specific questions on how some part of it works I can probably answer it, but unfortunately I don't have the time to comment the whole code.

RedComet

  • Hero Member
  • *****
  • Posts: 3169
    • View Profile
    • Twilight Translations
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #4 on: November 20, 2012, 10:04:03 am »
If you manage to get any work done on this and need a translator, lemme know. I would LOVE to do it. Loved the DBZ RPGs since I first started getting into emulation way back in the day.

~DS

How bout that DBZ2 RPG for the Famicom, hmmm?  ;)

EDIT: Also, IIRC the script is also compressed using an LZ variant. I had to write a simple decompressor to dump the scritpt, but I don't know where the source code is. I have stuff for this game in my to-do folder from 2008. :(
Twilight Translations - More than just Dragonball Z. :P

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #5 on: November 20, 2012, 01:56:57 pm »
Yep it starts decompressing to 7E9000.  I was hoping there was some way to force it to load graphics decompressed or something as I'm very inexperienced in coding in any other language.  I wouldn't know where to begin to write a decompressor let a lot something that can recompress.

Which, I don't honestly have much of the time to sit back and take years to learn C++, Python or anything else which is the main reason I'm wanting to take the easy route out.

And figures the script would be compressed.  I'm actually rather shocked that everything, EVERYTHING in this game is compressed.  Usually there's even the font that isn't or something, but it seems every little thing was.  And considering not even a 5th of what the SNES's space can hold is used, it's interesting to see it like this.
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

LostTemplar

  • Hero Member
  • *****
  • Posts: 910
    • View Profile
    • au-ro-ra.net
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #6 on: November 20, 2012, 02:15:11 pm »
Yep it starts decompressing to 7E9000.  I was hoping there was some way to force it to load graphics decompressed

Easy. Just directly DMA it from the ROM to WRAM via port $2180 instead of calling that decompression routine. Or, as it seems the game transfers it to VRAM directly after that code anyway, skip the WRAM and transfer it directly to VRAM. However, unless you are going to decompress every graphic and insert it back uncompressed, you should have some flag byte somewhere (indexed by the sprite index that is given in A at the beginning to calculate the pointer to the data) to tell the game to only load some graphics (the ones you changed) directly.

Another option is to insert the uncompressed graphics as LZSS stream, but with all flag bits set to 'uncompressed'.

On a side note, if you know 65816 assembler, C++/Python/Java/whatever shouldn't be too difficult to learn, and especially shouldn't take "years". It comes in handy very often so you should consider learning at least one programming language. If you're planning to only use it for jobs like this Python should be a pretty good match for you.
« Last Edit: November 20, 2012, 02:20:58 pm by LostTemplar »

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #7 on: November 20, 2012, 02:34:52 pm »
I was going for the uncompressed bit flag.  I did something similar with Breath of Fire 2 for the portraits, same exact thing with Mega Man X2 with the unused capsule portraits so I know it's possible, I'm just not sure WHAT the flag is for this considering everything in the game is compressed and there's no real example.

Edit: I'm no pro at 65816 Assembly and I did take at least 3 classes on C++ and something with Java, but I've literally forgotten everything and how the whole structure works.  I know I had horrible issues back in the day trying to understand C++, not sure how much it'd pertain now, but wouldn't even know where to start on it anymore.
« Last Edit: November 20, 2012, 02:48:40 pm by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

LostTemplar

  • Hero Member
  • *****
  • Posts: 910
    • View Profile
    • au-ro-ra.net
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #8 on: November 20, 2012, 02:57:00 pm »
The flags are interleaved with the data. From the quick glance I took at the code, it should be like this:

  • the first 2 bytes are the uncompressed size of the data. This means you just have to set this to the size of the data.
  • after that, if you're going for completely uncompressed data storage, it's always 0xFF + (8 bytes of your data), 0xFF + (8 bytes of your data) + ... Each bit of the flag byte (the 0xFF) means uncompressed byte (1) or back-reference/RLE (0).

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #9 on: November 20, 2012, 03:33:36 pm »
8 bytes of your data?  8 bytes of the decompressed data I assume?
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

LostTemplar

  • Hero Member
  • *****
  • Posts: 910
    • View Profile
    • au-ro-ra.net
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #10 on: November 20, 2012, 03:45:08 pm »
Yes. Let's assume you have an 'A', with one byte per pixel, like this:

0 0 0 1 1 0 0 0
0 0 1 0 0 1 0 0
0 1 0 0 0 0 1 0
0 1 1 1 1 1 1 0
0 1 0 0 0 0 1 0
0 1 0 0 0 0 1 0
0 1 0 0 0 0 1 0

It's 8x8 = 64 bytes big, so first write 0x0040 (that's 40 00 in the hex editor because the SNES is little endian). Then follows the data, every 8 byte prefixed with 0xFF:

40 00 FF 00 00 00 01 01 00 00 00 FF 00 00 01 00 00 01 00 00 ...

The 0xFF just tells the decompressor that the next 8 bytes are uncompressed and should be copied to the output location.

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #11 on: November 20, 2012, 03:49:52 pm »
Woah, that's quite a tedious little task to do for it.  That DEFINITELY explains why only certain pieces of sprites would change when I altered some location.  So it wasn't just my imagination then, makes sense at least now.
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Hiei-

  • Sr. Member
  • ****
  • Posts: 379
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #12 on: November 20, 2012, 07:24:29 pm »
Yep it starts decompressing to 7E9000.  I was hoping there was some way to force it to load graphics decompressed or something as I'm very inexperienced in coding in any other language.  I wouldn't know where to begin to write a decompressor let a lot something that can recompress.

Which, I don't honestly have much of the time to sit back and take years to learn C++, Python or anything else which is the main reason I'm wanting to take the easy route out.

And figures the script would be compressed.  I'm actually rather shocked that everything, EVERYTHING in this game is compressed.  Usually there's even the font that isn't or something, but it seems every little thing was.  And considering not even a 5th of what the SNES's space can hold is used, it's interesting to see it like this.

The script (if you talk about the texts) is not compressed.

About the font, I have a working compressor/decompressor done in LUA (made by a friend).



I also have the tilemaps/value to modify the width/height of the menu windows.

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #13 on: November 20, 2012, 07:42:39 pm »
Any kind of tool would be exceptionally useful.

I know the English Translation that's supposedly 100% has the battle graphics/font and such decompressed, but the font is in such a disgusting mess of things that it's just eek.  It'd be nice to  have anything for usage in all honesty.

Actually, I think I'd rather just straight up use the JP rom to start fresh with EVERYTHING.  That would be a lot better.
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Hiei-

  • Sr. Member
  • ****
  • Posts: 379
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #14 on: November 20, 2012, 08:23:30 pm »
The compression is not very fast (17 seconds on my Core2Duo 2.7 Ghz) but works fine : http://www.hiei-tf.fr/DBZ_RPG_1.rar

- "decompress_font.bat" to decompress/extract the font to a file ("decompressed_font_japanese.bin").
- "compress_font.bat" to compress/insert the font back to the rom.

You can see the source code in the .lua files.

The code was made by Bahabulle (http://www.romhacking.net/forum/index.php?action=profile;u=14762) on a request from me for a future japanese-french translation planned with a friend.

The pointers of the different banks for the texts are a bit mess up in the japanese rom and it took me some times to move them without any bugs. If you're also interested, I have an .IPS patch I made which expand the rom and move the japanese texts to the expanded part, with all the pointers already fixed (I had to add some sentences twice to be sure the extraction of the script isn't a mess). I also have a working tool/scripts to dump/reinsert those texts (moved in the expanded part).

The only thing that I haven't dumped correctly is the battle texts, as each first byte is the length of the string, and it's dumped as a japanese character in my dump :

Code: [Select]
<PT0001>
[Carre Bleu]ゴクウ<PT0002>
[Carre Bleu]ゴハン<PT0003>
あピッコロ<PT0004>
あクリリン<PT0005>
うテンシンハン<PT0006>
あヤムチャ<PT0007>
あチャオズ<PT0008>
あベジータ<PT0009>
[Carre Bleu]ネイル<PT0010>
あツムリー<PT0011>
あマイーマ<PT0012>
[Carre Bleu]デンデ<PT0013>
[Carre Bleu]カルゴ<PT0014>

But that's not a problem for me, as I can manually edit those bytes after, in an hex editor, to fit the new length of the strings.

About the length of the menu windows, it's at 0x160F2 for the one of the bottom-left corner of the map, with the actions "Fly/etc...". (four bytes for each window : Width, Height, X axis, Y axis), etc...

Then you have to modify the coordinates of the texts of the window, in this example, it's at 0x15AB6 (16-bits pointers at 0x15A16).

1 byte (+1) : number of characters per word.
1 byte (+1) : number of words
2 bytes : location of the first word on the screen
n bytes : menu texts

And finally, the cursor position at 0x16233.

(All those infos are, again, from Bahabulle).

And no, the text is not compressed at all. That's probably the only thing uncompressed in the rom. For example, the main script start at 0x302DC and end at 0x35108 (or something like that for the end of the text, not sure it's the final value as I now only use my expanded version, which use differents address for the texts). There are 366 (16-bits) pointers for the main text, located at 0x30000.

And the 24-bits pointer of the 16-bits pointer table of the main text (if you want to move the pointers table and the texts in another bank to have more free room for the text) is at 0x38F1C.
« Last Edit: November 20, 2012, 08:40:13 pm by Hiei- »

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #15 on: November 20, 2012, 08:35:36 pm »
Anything honestly is perfect.  Even this is just an outstanding amount of information.  I definitely plan to give this a whack now, even if for now it's just re-doing some fonts and fixing the menus up.
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Hiei-

  • Sr. Member
  • ****
  • Posts: 379
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #16 on: November 20, 2012, 08:41:03 pm »
Hope those informations will help you then :)

If you need some help with the text expansion/extraction/insertion later, feel free to pm me :)

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #17 on: November 23, 2012, 09:47:27 am »
I actually have a question to bring up.

Would it be possible to have the byte size and 'decompression' bits load from a table?  So essentially, it loads the header sized and then if it reads the uncompressed bit as 'FF', it just keeps loading all the data until it reaches the end of the header?  So basically it keeps writing itself telling it's FF without having to keep putting up with 8 bytes of uncompressed, then stop, then do it agan.

So basically like:

02 02 FF would be the main thing telling the header size and that it's uncompressed.  Then it'd just keep going as '02 02 FF xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx' but it would automatically put the FF there after 8 bytes.

Instead of 02 02 FF xx xx xx xx xx xx xx xx FF xx xx... etc..

I 'THINK' this could work but I'd probably have to heavily re-do some things, but it'd make the job a lot easier for loading uncompressed data.
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7209
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #18 on: November 24, 2012, 10:01:06 pm »
Probably not easily unless you plan to reinsert every graphic (and maybe tilemap, I know I've hacked a couple Bandai games that used the same routine for both graphics and tilemaps).
Maybe the other way is to hack the routine that checks the compression value and automatically replace it with 0xFF if the pointer is in an expanded portion of the ROM (or wherever you store your uncompressed versions of the graphics)?
"My watch says 30 chickens" Google, 2018

justin3009

  • Hero Member
  • *****
  • Posts: 1660
  • Welp
    • View Profile
Re: Dragon Ball Z - Legend Of The Super Saiyan?
« Reply #19 on: November 24, 2012, 10:34:53 pm »
As far as I can see, both sprite and tilemap may use the same code. I'll have to test that compression bit once I've actually moved I've persons graphics to a new location.

Thanks for that idea. Didn't even think of that.

Edit: Now I'm slightly confused.  From what I'm seeing Goku's sprite data, some of his data looks like it's already marked as loading uncompressed? 

Code: [Select]
00 0C FF 00 0C 06 73 1F 0F 1F 2F FA E4 00 01 2F
02 00 C0 F6 FC F8 F5 FE E4 02 40 FD 03 0A 1D 36
33 FF 51 58 5C 7F 05 02 0D 1E FF 2F 2F 2F 37 00

Third byte is FF.  But then it loads 8 bytes, but then it's not compressed, then does FF again, 8 bytes, then FF again.  Am I missing something here?  Cause even at the hex data it's pretty clear nothing is uncompressed there.
« Last Edit: November 25, 2012, 11:04:01 am by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'