Phantasy Star Disassemblies

Discuss anything related to the Phantasy Star series

Phantasy Star Disassemblies

Postby lorenzo » Fri Dec 26, 2014 1:38 pm

Hello everyone!

I've been working on disassembling the original games of the Phantasy Star series. For those who don't know anything about hacking or programming, let me tell you something about it: Disassembling means turning a binary file into assembly code which is more readable and much more convenient than direct hex editing. Through assembly you can use some basic but useful features such as labels which are descriptive names for sections in the code, so that you know what each section does. By using labels you can turn raw pointers or addresses into names that the code will jump to no matter if data is shifted: the assembler will calculate the address for you when generating the bin file saving you tons of work, and you can extend or simply change some functionality without any problems.


* Links to the available disassemblies

Phantasy Star: http://www.romhacking.net/documents/723/
Phantasy Star II: http://www.romhacking.net/documents/685/
Phantasy Star III: http://www.romhacking.net/documents/690/
Phantasy Star IV: http://www.romhacking.net/documents/697/


* GitHub

Phantasy Star II: https://github.com/lory90/ps2disasm
Phantasy Star III: https://github.com/lory90/ps3disasm
Phantasy Star IV: https://github.com/lory90/ps4disasm


* Tutorials on Git and GitHub

https://progit.org/
http://rogerdudler.github.io/git-guide/
https://help.github.com/articles/fork-a-repo/
https://help.github.com/articles/using-pull-requests/


* Programming links for M68K, Z80, Mega Drive and Sega Master System

Motorola 68000

Tutorial: http://mrjester.hapisan.com/04_MC68/
Resources: http://www.easy68k.com/paulrsm/
Speed and Optimization: http://www.mactech.com/articles/mactech/Vol.08/08.02/Efficient68000/index.html
Simulator: http://www.easy68k.com/

Z80

Tutorial: http://sgate.emt.bme.hu/patai/publications/z80guide/
Tutorial: http://z80-heaven.wikidot.com/system:tutorials
Speed and Optimization: http://wikiti.brandonw.net/index.php?title=Z80_Optimization

Mega Drive/Sega Genesis

Tutorial: http://bigevilcorporation.co.uk/
Tutorial: http://darkdust.net/retrogaming/megadrive
Resources: http://gendev.spritesmind.net/
Resources: http://info.sonicretro.org/Category:Sonic_Community_Hacking_Guide
Resources: http://emu-docs.org/?page=Genesis

Sega Master System

Tutorial: http://www.smstributes.co.uk/view_page.asp?articleid=206
Resources: http://www.smspower.org/
Resources: http://emu-docs.org/?page=Master%20System


Happy hacking!
Last edited by lorenzo on Fri Apr 01, 2016 11:57 am, edited 8 times in total.
lorenzo
Blastoid
Blastoid
 
Posts: 92
Joined: Thu Dec 25, 2014 12:57 am
Location: Italy

Re: Phantasy Star Disassemblies

Postby Parma Ham » Fri Dec 26, 2014 4:52 pm

.
Last edited by Parma Ham on Thu Feb 12, 2015 9:59 pm, edited 1 time in total.
Parma Ham
 

Re: Phantasy Star Disassemblies

Postby lorenzo » Fri Dec 26, 2014 7:14 pm

Parma Ham wrote:Where do you recommend someone should go to start learning if they don't know any 68k or z80 assembly? (I know a VERY SMALL amount of NASM-syntax x86 code, and I've only tried it out under DOS. ) What assembler software is needed, and is it free? And where's a good place to learn about the Megadrive/Genesis hardware?.


Here's a good place to learn 68k assembly:

http://mrjester.hapisan.com/04_MC68/

It starts explaining the basics of computer memory, bits, bytes, hex, etc. It's very linear and easy to follow. Then there's the reference manual which is a technical explanation of M68000 family. I won't provide a link here, but if you Google something like Motorola M68000 family reference manual you should find a PDF about this document. It's kinda complicated for a beginner and you don't have to learn everything from it to program in 68k.

For z80 here's a good website:

http://sgate.emt.bme.hu/patai/publications/z80guide/

It should be detailed enough to cover a lot of information. Of course the official documentation for z80 is always good to have. If you search by using keywords "Z80 User Manual", you should be able to grab a PDF document easily

Actually if you search around, a good number of tutorials can be found.

Here are some free assemblers for m68k:

- ASM68K = Good for beginners and works also on Windows 64-bit
- SNASM68K = Similar to ASM68K but won't work on Windows 64-bit
- ASMX - Never used it, but I heard it has some bugs so I'd stay away from this one
- AS = Powerful assembler which supports many processors (including m68k and z80) and has tons of useful features, but not easy to set up specifically for Megadrive and it's not recommended for beginners

I switched from ASM68K to AS for PS2 and I'll do the same for 3 and 4 since it's much better in my opinion. For the PS disassemblies AS is already set up to work perfectly for PS2 so you shouldn't have any problems.

I didn't work much with z80 assembly, but I used Pasmo when learning some of it. It's similar to ASM68K, so it shouldn't be too complicated to set up. If you look at tutorials specifically for Megadrive and SMS, you should find downloadable examples so you can already take a look at how to set up a batch file to assemble your files.

Unfortunately there's no website that deals specifically with Megadrive programming. So you should look around and learn on your own. My disassemblies can also be used to learn, but you need to keep a reference for the basic stuff. Here's someone's blog that may come in handy:

http://bigevilcorporation.co.uk/

This guy was learning, but he explained things in great detail. Again you can find the official documentation (still in PDF format) for Megadrive if you search around using words such as Genesis Software Manual. A great forum to ask questions is this:

http://gendev.spritesmind.net/forum/

I think the best source for Megadrive programming is the Sonic Retro website:

http://info.sonicretro.org

It deals with Sonic for the most part, but it can be a good spot for learning Megadrive in general and you can find disassemblies for the classic Sonic games as well. If you like Sonic you can start looking at those since they spent many years on them.

Even if you didn't ask for SMS, I can link you to a good website:

http://www.smspower.org/

You can find and download many documents, tutorials and stuff for SMS and z80, so it's good to know for the first Phantasy Star at least.

Parma Ham wrote:My foremost interest is in cleaning up the games' scripts (fixing typos, etc.), so could you elaborate on this point, as well:
lorenzo wrote:- The game script can be edited at will...Some things require some code tweaking, but most of it can be changed freely.


Everything was labelled in the game script section so, when you change the data inside that section, everything will still work correctly, so it's very flexible. Through AS assembler you can type your text normally as a string, and the assembler will remap them to character-encoding of PS2. You'll see it more clearly in the disassembly. There are some control bytes which govern how to handle text, like newline, new box, etc. Here are some basic ones:

- C1 = new line
- C3 = scroll down
- C4 = close window

For example there can only be 24 characters per line before it starts spilling over, so to avoid this you need to put a C1 or C3.

Another thing to keep in mind is that the game introduction section which shows up after the title screen has text which closes windows automatically, so if you want to extend text, you need to handle logic for having the text scroll automatically, but I won't explain everything now, otherwise it'll be too confusing, especially if you don't see it. So it's relatively easy to edit text provided that you pay attention to the max number of character per line and put those control codes when needed.

Let me know if you have other questions or need clarifications.
lorenzo
Blastoid
Blastoid
 
Posts: 92
Joined: Thu Dec 25, 2014 12:57 am
Location: Italy

Re: Phantasy Star Disassemblies

Postby Tryphon » Fri Dec 26, 2014 10:05 pm

Wonderful work you did :)

You should submit it to romhacking.net, I think that's a very valuable piece of knowledge, and if one day a hacker is interested in the PS serie, it'll be the first place he'll look.

Did you begin PSIV ? I've given an eye on Surging Aura recently, and was told it uses the same engine than PSIV (I take this kind of affirmation with a grain of salt, few people actually read the disassemblies to check that). Most of the data in this game seems compressed in a weird way I'm still studying, and wondered if something similar was already known in PSIV.
Tryphon
Scorpius
Scorpius
 
Posts: 357
Joined: Wed Mar 28, 2012 11:29 pm

Re: Phantasy Star Disassemblies

Postby Parma Ham » Fri Dec 26, 2014 10:48 pm

.
Last edited by Parma Ham on Thu Feb 12, 2015 10:00 pm, edited 1 time in total.
Parma Ham
 

Re: Phantasy Star Disassemblies

Postby lorenzo » Sat Dec 27, 2014 11:39 am

Tryphon wrote:Did you begin PSIV ? I've given an eye on Surging Aura recently, and was told it uses the same engine than PSIV (I take this kind of affirmation with a grain of salt, few people actually read the disassemblies to check that). Most of the data in this game seems compressed in a weird way I'm still studying, and wondered if something similar was already known in PSIV.


No, I haven't started looking at PSIV yet. The only thing I discovered was the Kosinski compression used for text. I've never played Surging Aura... Is it good? What exactly do you mean by "compressed in a weird way"?

Parma Ham wrote:So are you saying AS (for beginners: "AS" is the GNU Assembler, AKA "gas" ) is normally hard to use for Gen/MD development, but the PS games are the exception? Or you mean it's better for DISassembly?


It's hard to set up for Megadrive, but I did all the work for PSII so all you need to do is build the ROM. It's hard because you need to create macros and functions in order to create a byte-perfect copy of the ROM, then it took some time to integrate z80 code so I had to modify the source file and there could be other things I can't say off the top of my head. By the way, by AS I meant Macro Assembler AS (sorry, should've been more specific) which is a totally different project from the GNU Assembler.

Parma Ham wrote:If I just want to edit PS2's script, do I need to worry about learning any z80 stuff to accomplish that? Or is that only necessary if I mess with the game's sound engine? (For beginners: in the Genesis/Megadrive, the z80 CPU is responsible for controlling the system's sound chips.)


No, z80 is the processor for the sound chip only in the Megadrive so you're fine with just m68k if don't care about the sound part.

Parma Ham wrote:Is there a limit on how much new text can be added? Can the script be added to indefinitely?


For the text per se, add as much as you want. So if you just edit the script there's tons of space. Regarding space limitations, the max ROM size for the Megadrive is 4MB, also you need to pay attention to the SRAM part (section where data are saved): the start of this section is from location $200001 and the end address is $203FFF, so it takes up 16kb for the saved data. If your rom size reaches 2MB, you'll need to tell the CPU to start from location after $203FFF. I think I'll put a warning which'll say if you exceeded 2MB and that you need to handle this case, but as I said earlier, if you just edit the script, you won't have a problem... Unless you write a novel that is

Parma Ham wrote:I guess now the only question is: when do we get to see your work?


Be patient. It won't take long. I need to finish cleaning up the script and the text for windows. I'll need to put a few more comments in the code, then I'll have this submitted. After that I'll clean up more complicated stuff and get to see what happens more at the hardware level, such as compression, collision, maps, sound, etc. It's kinda tricky doing all this as a solo project. :)
lorenzo
Blastoid
Blastoid
 
Posts: 92
Joined: Thu Dec 25, 2014 12:57 am
Location: Italy

Re: Phantasy Star Disassemblies

Postby BenoitRen » Sat Dec 27, 2014 1:19 pm

What I'm interested in is seeing a dissection of the game's logic when it comes to movement and damage formula. I programmed a neat (but unfinished) Mega Man clone using such data.
Get Xenoblade Chronicles!
User avatar
BenoitRen
Moderator
Moderator
 
Posts: 3122
Joined: Fri Jul 27, 2007 5:19 pm
Location: Belgium

Re: Phantasy Star Disassemblies

Postby lorenzo » Sat Dec 27, 2014 4:13 pm

Do you mean you took Mega Man code dealing with movement and damage formula and recreated them in another language/software?
lorenzo
Blastoid
Blastoid
 
Posts: 92
Joined: Thu Dec 25, 2014 12:57 am
Location: Italy

Re: Phantasy Star Disassemblies

Postby Parma Ham » Sat Dec 27, 2014 5:32 pm

.
Last edited by Parma Ham on Thu Feb 12, 2015 10:00 pm, edited 1 time in total.
Parma Ham
 

Re: Phantasy Star Disassemblies

Postby Tryphon » Sat Dec 27, 2014 11:12 pm

Parma Ham wrote:
Regarding space limitations, the max ROM size for the Megadrive is 4MB

Is there a way around this 4MB limit? (It doesn't really matter, I'm just curious. )


Yes there are. You can for example use a bank-switching method (require additional chips on the catridge) and the size is virtually illimited. Super Street Fighter II and Pier Solar do that.

I've heard that the Mega Everdrive use its own system, making possible to use the acess the whole flashcart (up to 16 or 32 GB, I don't remember).

lorenzo wrote:ted looking at PSIV yet. The only thing I discovered was the Kosinski compression used for text. I've never played Surging Aura... Is it good? What exactly do you mean by "compressed in a weird way"?


To both questions : I don't know :)

Surging Aura is totally in Japanese so unplayable for me. It's beautiful, undoubtly, and got good critics.
For the "compression", I'm not even sure it's a compression. It rather looks like a small scripting language. The code handling that is not concise, so I'm not sure the aim is compression, but I haven't yet figured out what it is for. I'm not really working on it to be honest.
Tryphon
Scorpius
Scorpius
 
Posts: 357
Joined: Wed Mar 28, 2012 11:29 pm

Re: Phantasy Star Disassemblies

Postby lorenzo » Sun Dec 28, 2014 9:05 am

Parma Ham wrote:
lorenzo wrote: By the way, by AS I meant Macro Assembler AS (sorry, should've been more specific) which is a totally different project from the GNU Assembler.

Oops, my mistake. I shouldn't have assumed. But in that case, do you have an opinion about GNU Assembler for MD/Gen development?


No worries! I've never used the GNU Assembler and I'm not sure how easy it would be to set up. There are already disassemblies which use AS and the programmers already wrote functions and routines to make the assembler work perfectly for MD/Gen, so it was much easier than it would've been.
lorenzo
Blastoid
Blastoid
 
Posts: 92
Joined: Thu Dec 25, 2014 12:57 am
Location: Italy

Re: Phantasy Star Disassemblies

Postby BenoitRen » Sun Dec 28, 2014 4:08 pm

lorenzo wrote:Do you mean you took Mega Man code dealing with movement and damage formula and recreated them in another language/software?

I meant that I read Rockman's technical data and programmed a Rockman / Mega Man in C++.
Get Xenoblade Chronicles!
User avatar
BenoitRen
Moderator
Moderator
 
Posts: 3122
Joined: Fri Jul 27, 2007 5:19 pm
Location: Belgium

Re: Phantasy Star Disassemblies

Postby lorenzo » Mon Jan 05, 2015 1:44 pm

Hey everyone. I wanted to let you know that I sent the PSII disassembly over to the administrator so it will most likely be on the next website update. I also submitted it on romhacking.net, so if everything goes well and it gets approved, you can also download it from there.
lorenzo
Blastoid
Blastoid
 
Posts: 92
Joined: Thu Dec 25, 2014 12:57 am
Location: Italy

Re: Phantasy Star Disassemblies

Postby Parma Ham » Mon Jan 05, 2015 11:03 pm

.
Last edited by Parma Ham on Thu Feb 12, 2015 10:00 pm, edited 1 time in total.
Parma Ham
 

Re: Phantasy Star Disassemblies

Postby lorenzo » Tue Jan 06, 2015 11:01 am

The PSII disassembly was approved on RHDN. Here's the link:

http://www.romhacking.net/documents/685/

As soon as the disassembly gets submitted on this website as well, I'll edit the first post and I'll include the link to the disassembly (only to the one hosted here)
lorenzo
Blastoid
Blastoid
 
Posts: 92
Joined: Thu Dec 25, 2014 12:57 am
Location: Italy

Next

Return to Phantasy Star

Who is online

Users browsing this forum: No registered users and 6 guests

cron