Dragon Crystal (SMS) Disassembly and Exploration

Discussion in 'Engineering & Reverse Engineering' started by trykaar, Oct 6, 2014.

  1. trykaar

    trykaar

    Member
    14
    0
    0
    St. Louis, MO
    Sega Roguelike Exploration/Disassembly
    [​IMG]

    Hello everyone,

    I've started a disassembly of Dragon Crystal for the Sega Master System as a project to learn z80 assembly and more about how the games I grew up with work. For those who aren't familiar with the game, it and its Game Gear counterpart (which is the same underlying game, but with significant cosmetic differences including music and monster names and art) and the closely related Fatal Labyrinth for the Genesis/Mega Drive are graphical roguelikes developed by Sega sometime in 1989-1991. The Game Gear version has been one of my favorite games for years, but as the SMS seemed somewhat better documented from a development/hacking standpoint I've decided to start with that.

    So far I have the item names and the in-game messages extracted and editable, the map chunks extracted and separated out, and some functions and many game variables documented; the disassembly reassembles with WLA DX. Based on comparisons with the Sonic 2 SMS disassembly in the Sonic Retro repository, the sound engine appears to be SMPS- several functions seem nearly exact line by line. I've found some of the graphics with Master Tile Converter as well, but haven't focused on them yet either.

    It is trivial to change item names, as you can see from the screenshot above- the listings are extracted into the items folder, and the format is very simple, an initial length byte and then the string, padded out to 15 characters with spaces. The in-game messages seem to be more of a challenge, however- they also start with a length byte, but they are variable-length, and even shortening the strings and padding with spaces or the $FF filler used elsewhere so as not to disturb other strings causes graphical corruption. The map data is composed of 16x16 chunks- I've split out these chunks into individual blobs in the "map" folder for now, but my plan is to make them editable plain text by setting up an ascii table the way I've done with the text.

    Currently I'm focusing on the data- there is more text yet to be extracted, such as the class/level names and monster names, as well as fixing up the maps. After that will come more work on the code. I'm doing research on the release order of the games as well- it's actually not terribly clear, as both Dragon Crystals and Fatal Labyrinth are given 1991 release dates, but my current best guess is Fatal Labyrinth (ROM header date of October 1989 and credits containing 1990 in the Japanese version, Shi no Meikyuu), then Dragon Crystal GG (known to have a Japanese release date of December 1990), then Dragon Crystal SMS (which is given as 1991, but does not show up in game magazines until fall of 1991- Dragon Crystal SMS never had a Japanese or US release, just Europe and Brazil.)

    The development order is a bit more uncertain, especially with the two versions of Dragon Crystal- a user on SMS Power! pointed me to a couple of French reviews of the game which seem to show a prototype version (still with English text): see here and here- the HUD shows both HP and food. I am unsure if this was an expansion to take advantage of the larger display area on the SMS, or a feature that was originally in both versions- curiously, the only name shared between the credits (and with Fatal Labyrinth for that matter) is E. Fugu, the composer, so there appear to have been completely different development teams at work on the GG and SMS versions.

    More information as I find it.

    Links and resources:

    • The disassembly
    • Exploration and disassembly progress thread at SMS Power!
    • Development page for the game at SMS Power!- I have been tracking findings such as memory values, text locations, etc here
    • The Dragon Crystal Shrine at RPG Classics by Dammit9x got me started with a number of memory locations and other data- check it out if you like the games, it's a fantastic resource
    • WLA DX is required to reassemble- use the included Compile.bat
    • Disassembly was created with the help of Emulicious and its creator Calindro
    • The debugging features of MEKA are also super-useful
    • As is the PAR code support in Kega Fusion
     
  2. Ravenfreak

    Ravenfreak

    Is actually a guy. Tech Member
    2,953
    92
    28
    O'Fallon Mo
    Hacking Sonic Drift, Writer at Sonic Cage Dome
    Amazing work! While I haven't played this game before, it's still refreshing seeing someone working on a disassembly of a SMS game it's something you don't see every day. :) I'll check your disassembly out after I play the game a tiny bit. ^_^
     
  3. trykaar

    trykaar

    Member
    14
    0
    0
    St. Louis, MO
    Sega Roguelike Exploration/Disassembly
    I've started work on an editor with JRuby/Swing, so far it can display the map files (blockX.bin in the map directory of the disassembly):

    [​IMG]

    Note ugly colors not final.

    I've extracted a bit more of the text as well, monster names and character death messages. The monster name text is a little different from the items, and the death messages seem to be more variable length text like the rest of the in-game messages. One death message, "I killed myself," baffles me- there is a separate message for starvation (damage done to the player when out of food), and to my knowledge there is no other way for fatal damage to be done to the player than attack from a monster, which has its own message ("(monster name) wins!"). The poison status merely prevents healing, and none of the items do damage. Maybe it's unused?

    Most of the remaining text- character classes/levels, the credits, the ending screen message, and the menus- appears to be in a slightly different format. It uses the table, but each character is padded with an $11, eg:

    $59 $11 $68 $11 $68 $11 $6A $11 $5D $11 $66 $11 $6C $11 $61 $11 $5B $11

    "A P P R E N T I C E"

    Does anyone know the significance of the $11s? I was reading the SCHG for Sonic 2 8-bit, and it appears that the title cards use a similar mapping, but I'm not sure I understand why. All of the text in the Game Gear version of Dragon Crystal seems be spaced out like this. The text is not displayed with spaces on screen- you can see the occurrence of the text "APPRENTICE" in the screenshot at the top of the thread.

    Thank you! My first Sega system was the Game Gear, and I've long thought that the 8-bit Sega systems need more attention. :)/>/> I hope you like the game- in my opinion, the Game Gear version, which is available on the 3DS virtual console, is the best, but I'm a bit biased since that's the version I grew up with. I'm enjoying exploring the Master System version since I only recently found out it existed- there are enough differences to keep it interesting!
     
  4. nineko

    nineko

    I am the Holy Cat Tech Member
    Why isn't trykaar a Tech Member yet?

    Actually, brb raising a formal nomination in the proper place
     
  5. trykaar

    trykaar

    Member
    14
    0
    0
    St. Louis, MO
    Sega Roguelike Exploration/Disassembly
    Work on the map viewer progresses, just enough to answer a burning question... Is the map data the same between the SMS and Game Gear versions?

    The table format at least is the same!

    And the answer is...

    [​IMG]

    Yes, pretty much- SMS on the top, GG on the bottom. You'll note that the GG version is off by one row, it wraps around. I wonder why that could be? Alas, the map data in Shi no Meikyuu and Fatal Labyrinth is in a different format- which makes sense, as the maps behave a bit differently. (Fatal Labyrinth has a lot more hidden doors, for one thing!)

    Wow! I'm honored, thank you :)/>
     
  6. ICEknight

    ICEknight

    Researcher Researcher
    Oh hey, this is odd.
    [​IMG]
    What do those differences mean?
     
  7. trykaar

    trykaar

    Member
    14
    0
    0
    St. Louis, MO
    Sega Roguelike Exploration/Disassembly
    Hello everyone,

    It's been a little while, but I have some updates.

    ValleyBell has given me a disassembly of the sound driver that includes a ton of information about functions and data structures, so I have been porting all of this from the IDA disassembly format into my WLA DX disassembly. The function names are over, and so are most of the data tables- there is still a big blob of the actual sound data, though, which I've left as a .bin for now- I'm still deciding how best to organize that, but I'm leaning towards an ASM with the headers and leaving the track data as binary blobs.

    I'm starting to look at the graphics data. I've found a number of the graphics stored with Phantasy Star RLE compression using jmimu's Master Tile Converter, and I believe I've found the decompression routine here- it looks very similar to the decompression algorithm sample that comes with BMP2Tile at least.

    I'll probably get the sound into a better place, and then move on to graphics and back to the map and game logic.

    That's a really good question! I didn't even notice that. I'm not entirely sure what those are used for. Obviously the white is for corridors, dark teal for walls, and light teal for room space, but the green (which really needs more contrast with the room space!), orange, and gold are still up in the air. There are room functions that I believe must be associated with them- placement of the portal to the next level and hidden doors (both of which may only be to the left or right walls of the room in this game, unlike Fatal Labyrinth I believe), possibly boundaries that prevent some monsters from leaving the room, possibly the placement of items within the room. I had suspected the gold marks to be the next level portals based on the way they "hang out" of the rooms (the portal replaces a wall tile), but that doesn't explain their occurrence in the corridors or non-vertical walls.

    I've also done more research into Fatal Labyrinth, and the games diverge more than I would have thought. Playing it more, I suspect it uses an algorithm like this to generate rooms rather than map data- that would make more sense anyways as it would keep the download size down more than using map chunks like Dragon Crystal does.

    I've discovered that there are in fact at least three versions of Fatal Labyrinth in existence too: the original downloadable Shi no Meikyuu, the version released overseas as Fatal Labyrinth (which has significant changes, like a real title screen and the town in the beginning), and the revised Fatal Labyrinth as released in the Game Kanzume collection of Sega Game Library games for Sega CD in 1994- this version has very nice CD audio versions of the opening and ending themes, but no music in-game!

    Check out this video of Shi no Meikyuu. No village or skeleton dragon title screen, but we have a nice scrolling text prologue- here's a rough translation.

    The game goes directly into the labyrinth when you press start, though the video doesn't show it.

    So... Shi no Meikyuu is dated 1990 in its credits, but was part of the Sega Game Toshokan service which did not debut until an unspecified time in 1991(?), meaning that Dragon Crystal GG is likely the first game released. I suspect that Shi no Meikyuu came first, or was contemporaneous with Dragon Crystal GG, but they had different programming teams, as the credits suggest. Fatal Labyrinth's enhanced version probably came next, as I believe that was released Spring-Summer of 1991, and Dragon Crystal SMS last, in Summer-Fall of 1991. The Game Kanzume version came out much later, in 1994.

    But perhaps most interestingly, Dragon Crystal II was released for mobile phones through the Sonic Café service: see this page on Sonic Team's site here. I would dearly love to play this! Are the Sonic Café games archived online anywhere?
     
  8. ICEknight

    ICEknight

    Researcher Researcher
    Some sources say that it was cancelled before release, but it would be nice to have some kind of confirmation.
     
  9. trykaar

    trykaar

    Member
    14
    0
    0
    St. Louis, MO
    Sega Roguelike Exploration/Disassembly
    Yeah, that's where I first saw it mentioned too. However, when I went to the article from IGN in 2004 that was linked as a source, the author is lamenting that none of the Sega Mobile games discussed have yet come to the US- the article mentions that players in Japan were already enjoying the game, so I started digging into Japanese sites. The page I linked before is from Sonic Team's Sonic Cafe site. According to Famitsu here, the game was released through Sonic Cafe on 10/13/2004. There appears to have been an update in 2007 that added support for 3G as well, per an article on Yahoo.

    There seem to be some really interesting multiplayer features, such as downloading other people's character data to help you through the quest if you find an item called the "guild ring" or playing against other players' character data in an arena mode. Most of what I've seen focuses on that, so I'm not sure how different the single-player experience would be. There seems to have been some kind of high score leaderboard too, with the amount of gold and "battle points" players collected.
     
  10. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    18,227
    349
    63
    Berkshire, England
    Learning Cymraeg
    What little we know about Sonic Cafe probably has here as a good start.
     
  11. trykaar

    trykaar

    Member
    14
    0
    0
    St. Louis, MO
    Sega Roguelike Exploration/Disassembly
    Hello everyone,

    I've not had terribly much to update lately- it's been mostly quieter, less interesting work on the disassembly front, but I have been messing around a bit with palette and graphics hacking:

    [​IMG]

    Here's a new palette for the flower field level, with orange flowers and less... eye-searing grass. I've also replaced the "ooze" enemy with the slime enemy from the Game Gear version- both versions use Phantasy Star RLE compression, so I was able to extract from one and insert into the other with Master Tile Converter. (The reverse does not work, as the ooze tiles take up more space- the graphics are corrupted.) The sprite palette was not even altered- the slime looks pretty much just as it does in the Game Gear version with the existing palette.

    A few translation/localization curiosities, regarding the weapons:

    - The "I killed myself" message is used in the game, if the player is killed by recoil from using the Death Blade, a powerful sword which sometimes does damage back to the player. In the Japanese version, this sword is the "Harakiri Blade," and the death message is "Defeated by committing seppuku." (Source, the top item on the page.)

    - The sword called Masamune in the English GG localization is a reasonably powerful sword for the mid-game, but it does no damage to slimes/oozes. According to legend, Masamune's blades were holy swords who did no damage to the "innocent and undeserving." However, in the Japanese version, this sword is called Zantetsuken, the "iron-cutting sword," after the sword wielded by Goemon in the Lupin III anime- Zantetsuken is capable of cutting through anything... except konnyaku jelly. Quite a difference in tone! (In the SMS version, only released in English, this sword is just called "Great Sword.")

    - The "Gladius" (GG)/"Flamberge" (SMS) sword in the English localization is the "Laconia Sword" in the Japanese version, after the Laconia Sword in Phantasy Star. (There's a Laconia Armor in the Japanese version too!)

    - The Japanese version also has "Excalibur," which one would think would be an easily recognizable reference for a Western audience, but this sword was renamed to "Flamberge" (GG)/"Rune Blade" (SMS) in the localization. However, the English version of Fatal Labyrinth does have a sword named Excalibur.

    I've started a Google Site to keep track of things like this- the list of Dragon Crystal weapons with Japanese name, translation, and both localizations is here, and I'll probably add the other types of items to it as I get time.

    Possibly the most interesting thing I've discovered is that the monster names seem to be different between Dragon Crystal and Fatal Labyrinth even in the Japanese version. The red pillbug-like enemy that shoots projectiles is Scorpion in the Japanese version of Dragon Crystal GG, but Worm in the Japanese version of Fatal Labyrinth. In fact, despite starting from the same character designs and graphics (designs credited to Naoto Ohshima, "Azarashi," and "Sato (Tokumei)" in Fatal Labyrinth and uncredited in either Dragon Crystal), the games seem to have diverged a lot despite both being roguelikes.

    Fatal Labryinth includes gameplay features like traps in the levels (pits that send you back a level and alert monsters to your presence) and way more (and more frustrating) hidden exits, a wider variety of equipment (axes and spears in addition to swords, shurikens and certain rings that are meant to be thrown rather than equipped, and helmets in addition to armor) but fewer consumables (Dragon Crystal has eg thirteen types of potions where Fatal Labyrinth has only seven). Fatal Labyrinth (the later cartridge release) also has the town at the beginning filled with NPCs where there is no such thing in Dragon Crystal (though it's possible there was such a feature in a beta version with NPCs appearing in the dungeon- that review seems more like the reviewer is confused about how to play the game, though).

    Thanks! The page lacks anything about the non-Sonic Sonic Cafe titles, though, and I didn't see any corresponding page at Sega Retro. I tried signing up for a Sega Retro wiki account to try to add one and put in some details from the Sonic Cafe website I linked above, but I got an "Account Creation Error, Incorrect or missing confirmation code" and could not create an account. (Perhaps I'm entering an incorrectly formatted answer for the CAPTCHA questions? I tried "Sega Genesis" and "Genesis" for the question about American name of the Mega Drive and "Mega Drive" and "Sega Mega Drive" for the question about the international name of the Genesis...) Is it because I'm still a trial member, maybe?
     
  12. trykaar

    trykaar

    Member
    14
    0
    0
    St. Louis, MO
    Sega Roguelike Exploration/Disassembly
    Major progress, everyone!

    I've located the statistics for weapons and armor and the logic for the scroll, rod, potion, and ring items! (Special effects of weapons, armor, and rings seem to be handled at the place they affect behavior, though, so for the rings most of the behavior is just displaying the correct message when the ring is equipped, and only armor statistics are here so far.)

    This makes it very easy to edit items in the game to swap their behavior with other items or change weapon/armor statistics! Here is a "proof of concept" ROM with the following changes:

    - The Leathersuit armor has been replaced with the "Ghost Mantle," which offers no defense bonus but a large bonus to evasion
    - The typo "You dodger the attack!" has been corrected to "You dodge the attack!"
    - The Minheal potion has been replaced with the "Boom Potion," which behaves as the thunder rod, damaging enemies in the room with you
    - The slime enemy has been imported from the Game Gear version- different graphics and name changed to "Slime" instead of "Ooze" (I did not alter the higher level Ooze enemies' names, but their graphics should also have changed)
    - New, less eye-searing palette for the flower field level, with yellow flowers instead of blue (as seen in the screenshot last post)

    The weapon and armor statistics are very simple tables that list the hit and power of each weapon and the evasion and armor class of each piece of armor. Just adjust the stats here, edit the name if you so wish in items/names, compile, and go!

    To create the Ghost Mantle:

    In items/behavior/armor_statistics.asm, simply change

    Code (Text):
    1. .db $08 $02     ; Leathersuit
    to

    Code (Text):
    1. .db $20 $00     ; Leathersuit
    and edit the name in items/names/armor.asm like so

    Code (Text):
    1. LightArmorName2:
    2.     .db $0B
    3.     .asc "LEATHERSUIT   "
    to

    Code (Text):
    1. LightArmorName2:
    2.     .db $0C
    3.     .asc "GHOST MANTLE  "
    (Note the change to the initial byte for length!)

    The item behavior takes a little more explanation- the IDs of items as stored in your inventory in RAM are offsets into a table of item behavior for each item, and the item behaviors in this table for each item are themselves offsets into a jump table to select the right routine for each item.

    Breaking it down a little...

    These items are stored in the player's inventory in the following locations in memory:

    Code (Text):
    1. $C910-$C917     Scrolls
    2. $C918-$C91F     Rods
    3. $C920-$C927     Potions
    4. $C928-$C92F     Rings
    Each item has an ID in the following range:

    Code (Text):
    1. $20-$2F Scrolls
    2. $30-3F  Rods
    3. $40-4F  Potions
    4. $50-5F  Rings
    For example, here are the scrolls:

    Code (Text):
    1. $20     Blade Scroll
    2. $21     Shield Scroll
    3. $22     Norust Scroll
    4. $23     Bless Scroll
    5. $24     Map Scroll
    6. $25     Shift Scroll
    7. $26     Mad Scroll
    8. $27     Magi Scroll
    9. $28     Gas Scroll
    10. $29     Ghost Scroll
    11. $2A     Dragon Scroll
    12. $2B     Summon Scroll
    13. $2C     Blank Scroll
    14. $2D     Potion Scroll
    15. $2E     Unused
    16. $2F     Unused
    If you edit memory to place $20 into the location $C910, you will have a Blade Scroll in your first scroll inventory slot.

    When you go to use a scroll, the game stores the item ID in $C931, the current item slot, and uses the item IDs (minus $20, as weapons occupy the range $00-0F and armor occupies the range $10-1F in IDs) as offsets into a behavior table:

    Code (Text):
    1. ; Scrolls
    2. .db $00 ; Blade Scroll
    3. .db $01 ; Shield Scroll
    4. .db $02 ; Norust Scroll
    5. .db $03 ; Bless Scroll
    6. .db $05 ; Map Scroll
    7. .db $06 ; Shift Scroll
    8. .db $07 ; Mad Scroll
    9. .db $0A ; Magi Scroll
    10. .db $0B ; Gas Scroll
    11. .db $0C ; Ghost Scroll
    12. .db $0D ; Dragon Scroll
    13. .db $09 ; Summon Scroll
    14. .db $0E ; Blank Scroll
    15. .db $30 ; Potion Scroll
    16. .db $FF
    17. .db $FF
    These values are actually offsets into the jump table that governs item behavior, which I've labeled "ItemActionTable." It looks like this:

    Code (Text):
    1. ItemActionTable:
    2.     .dw BladeScrollAction     ShieldScrollAction   NorustScrollAction   BlessScrollAction
    3.     .dw NothingHappenedAction MapScrollAction      ShiftScrollAction    MadScrollAction
    4.     .dw FreezePotionAction    SummonScrollAction   MagiScrollAction     GasScrollAction
    5. ...
    So, let's go through acquiring and using a Map Scroll:

    1. Map Scroll is picked up and stored in the first item slot: $24 written to $C900
    2. Map Scroll is used: $24 stored in $C931, the current item slot
    3. Behavior lookup for Map Scroll: $24 - $20 = $04, fifth offset into the item behavior table, which yields behavior $05
    4. Call routine for Map Scroll: Item Table starting point + $05 gives us the sixth entry of the Item Action Table, which is... MapScrollAction!

    Switching object logic turns out to be rather simple. To change the "Minheal Potion" to the "Boom Potion":

    In items/behavior/item_action_offsets.asm, simply change

    Code (Text):
    1. .db $19     ; Minheal Potion
    to

    Code (Text):
    1. .db $11     ; Minheal Potion
    (note $11 is the offset used for Thunder Rod!) and edit the name in items/names/potions_identified.asm like so

    Code (Text):
    1. IdentifiedPotionName1:
    2.     .db $0e
    3.     .asc "MINHEAL POTION"
    to

    Code (Text):
    1. IdentifiedPotionName1:
    2.     .db $0B
    3.     .asc "BOOM POTION   "
    (Note the change to the initial byte for length!)

    I recommend Dammit9x' Dragon Crystal Shrine as a good reference for the standard stats and behavior of weapons and items. Have fun!
     
  13. trykaar

    trykaar

    Member
    14
    0
    0
    St. Louis, MO
    Sega Roguelike Exploration/Disassembly
    Hello everyone! It's been quite a while since my last update.

    I'm continuing to focus on the game mechanics surrounding items and monsters. I've converted a number of set values to constants (eg monster and item IDs, game messages) and discovered the following data tables, which are now broken out and editable in the disassembly:


    Most of the consumable items' behavior is contained in the Item Action Table I mentioned in my last post. The Item Action Table contains actions that are executed when rings are equipped as well, which is all there is for some rings, but most of the special effects for equippable items are spread throughout the battle system in checks for whether a particular piece of equipment is equipped- for example, the armor rusting routine checks to see if a shield ring is equipped, and if so, does not rust the armor. (This effect of the shield ring is, I believe, previously undocumented!)

    I am going through and addressing most of the direct item references with item constants, but the programmers often take advantage of the specific numbers and sequential order of IDs (eg see checks for swords effective against specific monsters having IDs $0C-09 here), so there are going to be a number of indirect references to document.

    There is still much to be deciphered about items as well- how items and monsters are randomly placed on the map (I believe that a lot of this takes place in the jump table currently named "JumpTable4"), targeting, thrown items (I believe that the jump table currently labeled JumpTable6 contains this logic), identification of unidentified items, and the cursed item mechanism; cursed items are denoted by the high bit of the item ID being set, but I haven't discovered where this is set yet, I only see where it's read and cleared eg by the bless scroll. More remains about monsters too- placement on the map, behavior, graphics selected, HP.

    Little by little, work progresses!