News: 11 March 2016 - Forum Rules

Author Topic: Hack Ninja Gaiden Arcade (original 1988) for MAME  (Read 7885 times)

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Hack Ninja Gaiden Arcade (original 1988) for MAME
« on: November 23, 2021, 06:50:38 am »
Hello,
I wanted to learn how to hack the Ninja Gaiden Arcade game (the original from 1988) for MAME. My intention is to modify the graphics of the game.
Could someone help me to know what "specific" programs I need and how to do it?
I have the following doubts:
The tiles will be extracted but,
How do I interpret them? Since Ryu Hayabusa is not seen in its entirety. I understand that the graphics are divided.
How to disassemble the game (rom)? Would dz80 work? How does it work in that case?
How do I modify the tiles? Would Paint or Gimp serve?
How do I insert them once modified?
How do I reassemble the game? Would TASM work? How does it work in that case?
I have no knowledge of how to hack a rom.
Thanks.

Jorpho

  • Hero Member
  • *****
  • Posts: 5229
  • The cat screams with the voice of a man.
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #1 on: November 24, 2021, 09:45:51 pm »
I don't know why you're talking about disassembling and reassembling.  Assembling and disassembling is for code, not graphics.

The first second thing to try would be to try opening the various parts of the ROM in Tile Molester. You may be able to find the graphics somewhere, but you might have to try different graphic modes; Tile Molester supports a lot of them.

If you can't find the graphics anywhere, then they are probably compressed. Decompression is very difficult.

The first thing to try would be to Google around and see if anyone has already tried to do anything with this game before.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

Anime_World

  • RHDN Supporter
  • Jr. Member
  • *****
  • Posts: 83
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #2 on: November 25, 2021, 03:10:58 am »
Start here, learning Motorola 68000 assembly:
https://mrjester.hapisan.com/04_MC68/

The original Ninja Gaiden is programmed and run under a Motorola 68000 CPU. Take a look at PCB Layout:
Code: [Select]
-----------------------------------------------
|         MN50005XTA         4MHz  DSW2 DSW1  |
|                    6264 6264       8049     |
|           IOP8     1.3S 2.4S                |
|24MHz                                        |
|                                             |
|18.432MHz                                   J|
|                                             |
|              68000P10                      A|
|                                             |
|          6116                              M|
|          6116                               |
|          6116                              M|
|                                             |
|                                            A|
|                                             |
|              6264    YM2203  YM3014         |
|       Z80    3.4B                           |
| 4MHz  6295   4.4A    YM2203  YM3014         |
-----------------------------------------------

A second cpu can be found, it's a Zilog Z80.
Some coroutines and audio drivers are written in Z80 assembly.
So, you need to learn Z80 too.
https://www.msx.org/wiki/Z80_Assembler_for_Dummies

After known some basics, you can start a disassembly using IDA.
Here is some steps:
 1 - Locate tiledata and split it in single files. If tiledata is compressed, you 'll need to write a decompressor/recompressor recreating it using original decompressor routine in asm as base.
 2 - Locate text data, label and comment them
 3 - Locate and label all variables and constants inside RAM
 4 - Label all main routines
 5 - Label all coroutines

Golden Tip:
Mame Debugger can help you in disassembly processs.
https://www.youtube.com/watch?v=CGNXFNogYpA&list=PL4X0K6ZbXhINtESNGa9q7qGuFE83VLZyd&index=1

Good Work :thumbsup:


« Last Edit: November 25, 2021, 03:53:06 am by Anime_World »

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #3 on: November 29, 2021, 04:09:51 pm »
I really appreciate the answers. It seems complex!
Ninja Gaiden was hacked a while ago. You can see the result in this video:
https://www.youtube.com/watch?v=vxuIKgEVmCY

Jorpho

  • Hero Member
  • *****
  • Posts: 5229
  • The cat screams with the voice of a man.
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #4 on: November 29, 2021, 07:59:32 pm »
Ninja Gaiden was hacked a while ago. You can see the result in this video:
https://www.youtube.com/watch?v=vxuIKgEVmCY
That seems to be a professional job.

It is entirely possible that the code in that version was substantially re-written and that you may have an easier time finding the graphics there (i.e. using Tile Molester) than in the original.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #5 on: November 30, 2021, 05:16:57 pm »
I have unzipped gaiden.zip and opened the .bin files but cannot decrypt any graphics with Tile Molester. I have tried different codecs but there is no way to visualize anything.

Jorpho

  • Hero Member
  • *****
  • Posts: 5229
  • The cat screams with the voice of a man.
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #6 on: November 30, 2021, 09:19:58 pm »
Like I said, the next step is to try doing the same thing with Dragon Bowl (which you linked to).

If you can't find anything in there, then it's going to be pretty hopeless.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #7 on: December 01, 2021, 06:32:32 am »
Yes, excuse me, I also tried Dragon Bowl. I think it is more a problem of my lack of ability to use the program, since it is difficult to locate the sprites. I saw a tutorial in which I mentioned changing the codecs, changing 2-Dimensional Mode and activating the Full Canvas box but I can't see anything.
Do you know which codecs I should use for Ninja Gaiden or Dragon Bowl?
Could someone proficient in Tile Molester take a test?

Jorpho

  • Hero Member
  • *****
  • Posts: 5229
  • The cat screams with the voice of a man.
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #8 on: December 01, 2021, 11:46:50 am »
If you're not sure whether you're using Tile Molester correctly, why not try it with something known to actually work with Tile Molester, like a console ROM?

You can also try looking at the source code of the MAME driver to narrow down where the graphics are stored.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

Anime_World

  • RHDN Supporter
  • Jr. Member
  • *****
  • Posts: 83
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #9 on: December 01, 2021, 02:22:36 pm »
Yes, excuse me, I also tried Dragon Bowl. I think it is more a problem of my lack of ability to use the program, since it is difficult to locate the sprites. I saw a tutorial in which I mentioned changing the codecs, changing 2-Dimensional Mode and activating the Full Canvas box but I can't see anything.
Do you know which codecs I should use for Ninja Gaiden or Dragon Bowl?
Could someone proficient in Tile Molester take a test?



2BPP Linear, set blocks to 2x2

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #10 on: December 02, 2021, 06:30:20 am »
I appreciate the help you are offering me. I'm really looking forward to this project. Since I was little I have admired this video game.
As I said, I have managed to visualize the sprite.
Is there a way to see the whole sprite set? For example, the sequence of when he walks, but all the sprites in a row. I have seen some tutorial of Tile Molester and in roms of other consoles they manage to visualize everything together.
On the other hand, as I mentioned, I have also seen how, from the option Palette> Import From> This File, the Offset and Size options make the color palette look good.
I have downloaded the gaiden.cpp file, which I am attaching:
https://drive.google.com/file/d/1eBF8w5nDjWeoLhrXhiYqP7dVQw5yLLLj/view?usp=sharing
In this file you can see a lot of information about the game. For instance:
PALETTE (config, m_palette) .set_format (palette_device :: xBGR_444, 4096);
I do not know if that information can be useful to get a good view of the color palette.

Some time ago, with the help of a fellow OpenBOR forum, I started a Ninja Gaiden project. You could select the enemy of the hockey mask, choose the color of Ryu Hayabusa, and a few more modifications.
Although it is very incomplete, it can be downloaded at this link:
https://drive.google.com/file/d/1Q3EOd1AxyQqgTxmwudQ9kVY6jauEq2rX/view?usp=sharing
« Last Edit: December 04, 2021, 07:22:01 am by fhrans »

MottZilla

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #11 on: January 23, 2022, 08:22:12 pm »
Ninja Gaiden's sprite graphics are 4bpp. The data for sprites is stored on multiple 8-bit ROMs. You're going to need to combine these ROMs to see more than 2bpp. From MAME's source code:

Code: [Select]
ROM_LOAD16_BYTE( "6.3m",  0x000000, 0x20000, CRC(e7ccdf9f) SHA1(80ffcefc95660471124898a9c2bee55df36bda13) ) /* sprites A1 */
ROM_LOAD16_BYTE( "7.1m",  0x000001, 0x20000, CRC(016bec95) SHA1(6a6757c52ca9a2398ea43d1af4a8d5adde6f4cd2) ) /* sprites A2 */
ROM_LOAD16_BYTE( "8.3n",  0x040000, 0x20000, CRC(7ef7f880) SHA1(26ba9a76adce24beea3cffa1cb95aeafe6f82f96) ) /* sprites B1 */
ROM_LOAD16_BYTE( "9.1n",  0x040001, 0x20000, CRC(6e9b7fd3) SHA1(c86ff61844fc94c02625bb812b9062d0649c8fdf) ) /* sprites B2 */
ROM_LOAD16_BYTE( "10.3r", 0x080000, 0x20000, CRC(a6451dec) SHA1(553e7a1453b59055fa0b10ca04125543d9f8987c) ) /* sprites C1 */
ROM_LOAD16_BYTE( "11.1r", 0x080001, 0x20000, CRC(7fbfdf5e) SHA1(ab67b72dcadb5f2236d29de751de5bf890a9e423) ) /* sprites C2 */
ROM_LOAD16_BYTE( "12.3s", 0x0c0000, 0x20000, CRC(94a836d8) SHA1(55658f4c6cf6aadc4369b943705f5734396b2e43) ) /* sprites D1 */
ROM_LOAD16_BYTE( "13.1s", 0x0c0001, 0x20000, CRC(e9caea3b) SHA1(39ef300e7dfd9469f04127d5a06dceb0b7e357f8) ) /* sprites D2 */

So you need to combine roms 6.3m & 7.1m to get the first 0x40000 of sprite graphics data. And the same for 8&9, 10&11, 12&13. After you combine them I *think* using the Sega Genesis mode in most tile editors will work. I wrote my own emulator for Ninja Gaiden as well as Genesis and if I'm remembering correctly it has the same format. I could be mistaken as it has been awhile.

So if you can program all you need to do is interleave the ROMs and then reverse that process after editing. You should probably copy the even and odd roms using a command like like this: copy /b 6.3m + 8.3n + 10.3r + 12.3s EvenGfx.Bin

And then do the same for the Odd ROMs, then interleave the OddGfx.bin and EvenGfx.bin

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #12 on: January 24, 2022, 05:36:17 am »
Hello,
Forgive my inexperience on the matter.
I don't know how or with what programs to do what you tell me.
Could you explain it to me in more detail and also with names of programs to do what you tell me?
Thanks a lot!

MottZilla

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #13 on: January 24, 2022, 03:15:50 pm »
I am not aware of a program that already does this operation but it is very simple if you can program in any language.

First you can do from the command line on Windows and many other operating systems the command I previously mentioned. Something like this.

Code: [Select]
copy /b 6.3m + 8.3n + 10.3r + 12.3s EvenGFX.Bin
copy /b 7.1m + 9.1n + 11.1r + 13.1s OddGFX.Bin

That will give you just 2 files that you need to interleave meaning to alternate each byte between the even and odd files.

So in C/C++ you would want to do something like this.

Code: [Select]
#include <stdio.h>
#include <stdlib.h>

FILE *fEven;
FILE *fOdd;
FILE *fOut;

int main()
{

fEven = fopen("EvenGFX.bin","rb");
fOdd = fopen("OddGFX.bin","rb");
fOut = fopen("OutGFX.bin","wb");

if(fEven == NULL || fOdd == NULL || fOut == NULL)
{
printf("Error");
return 0;
}

for(int n=0;n<0x80000;n++)
{
  fputc(fgetc(fEven),fOut);
  fputc(fgetc(fOdd),fOut);
}

fclose(fEven);
fclose(fOdd);
fclose(fOut);

printf("Done");

}

Afterwards you should be able to open the OutGFX.bin like a Sega Genesis ROM and be able to see the sprites. The code posted above should compile and work. You can probably use about any compiler such as DevCpp.
« Last Edit: January 24, 2022, 03:23:05 pm by MottZilla »

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #14 on: January 24, 2022, 03:25:15 pm »
Can you advise me a good program to edit Sega Genesis sprites?

MottZilla

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #15 on: January 24, 2022, 03:31:45 pm »
Not really. I don't generally edit sprites. There are tons of utilities on romhacking.net for doing that sort of thing. Just find one you like that has the features you need. Tile Molester was already mentioned and would probably work just fine.

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #16 on: January 24, 2022, 04:34:33 pm »
What configuration do I have to give to Tile Molester, codec, mode... etc?
I can't see sprites.
I have combined the files you told me, EvenGFX.Bin and OddGFX.Bin.
Once I am able to modify the sprites, with what code in cmd do I separate the files again?
I am attaching Tile Molester and the files I have obtained (EvenGFX.Bin and OddGFX.Bin) to see if you can do any tests:
https://we.tl/t-vldvC6nz55
I really appreciate your help!

MottZilla

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #17 on: January 24, 2022, 09:04:16 pm »
Did you compile the program or otherwise combine the Even and Odd graphics roms? The mode should be whatever is used for Sega Genesis I believe. I've not used that program before so I cannot say what it calls that mode.

Edit:
https://ufile.io/qbwrunke

You can download the compiled program to interleave the two files. Source code included.
« Last Edit: January 24, 2022, 09:09:50 pm by MottZilla »

fhrans

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #18 on: January 25, 2022, 02:17:31 am »
I used this code you told me:
copy /b 6.3m + 8.3n + 10.3r + 12.3s EvenGFX.Bin
copy /b 7.1m + 9.1n + 11.1r + 13.1s OddGFX.Bin
And I got the EvenGFX.Bin and OddGFX.Bin files.

To clarify, the steps should be the following:
1. Mix odd and even graphics roms.
2. Edit the graphics with Tile Molester.
3. Uncombine the EvenGFX.Bin and OddGFX.Bin files with the already edited sprites. With what code do I decombine them?
4. Recompress the uncombined files in a .zip file (Gaiden.zip) to be able to play in MAME.
Is the process correct?

What this code does:
copy /b 6.3m + 8.3n + 10.3r + 12.3s EvenGFX.Bin
copy /b 7.1m + 9.1n + 11.1r + 13.1s OddGFX.Bin

Isn't it the same as what this other one does?
#include <stdio.h>
#include <stdlib.h>

FILE *fEven;
FILE *fOdd;
FILE *fOut;

int main()
{

fEven = fopen("EvenGFX.bin","rb");
fOdd = fopen("OddGFX.bin","rb");
fOut = fopen("OutGFX.bin","wb");

if(fEven == NULL || fOdd == NULL || fOut == NULL)
{
   printf("Error");
   return 0;
}

for(int n=0;n<0x80000;n++)
{
  fputc(fgetc(fEven),fOut);
  fputc(fgetc(fOdd),fOut);
}

fclose(fEven);
fclose(fOdd);
fclose(fOut);

printf("Done");

}

Sorry for my clumsiness, I have no idea of programming.
« Last Edit: January 25, 2022, 04:18:09 am by fhrans »

Jorpho

  • Hero Member
  • *****
  • Posts: 5229
  • The cat screams with the voice of a man.
    • View Profile
Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
« Reply #19 on: January 25, 2022, 10:54:29 am »
What this code does:
copy /b 6.3m + 8.3n + 10.3r + 12.3s EvenGFX.Bin
copy /b 7.1m + 9.1n + 11.1r + 13.1s OddGFX.Bin
It does exactly what was said: each line combines four different files into one larger file. (What did you think it did?)

Quote
Isn't it the same as what this other one does?
That code interleaves the files.

Look at the picture that was posted earlier. It has vertical lines running through it because half the bytes have to come from a different file. That's what interleaving fixes.

Sorry for my clumsiness, I have no idea of programming.
Well, maybe you're going to have to learn..? In your first post you were going to go ahead and disassemble the entire ROM; did you not expect programming would be involved?
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!