Romhacking.net

Romhacking => ROM Hacking Discussion => Topic started by: fhrans on November 23, 2021, 06:50:38 am

Title: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Anime_World 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:


Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans 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
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans 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?
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Anime_World 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?

(https://cdn.imgpaste.net/2021/12/02/KTShcN.png)

2BPP Linear, set blocks to 2x2
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans 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
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla 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
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans 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!
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on January 24, 2022, 03:25:15 pm
Can you advise me a good program to edit Sega Genesis sprites?
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans 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!
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans 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.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho 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?
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on January 25, 2022, 04:14:04 pm
It does exactly what was said: each line combines four different files into one larger file. (What did you think it did?)
Okay, I had not read the second part well, that once the odd and even files were combined, the resulting files had to be interleaved.

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.
After interleaving the EvenGFX.Bin and OddGFX.Bin files, I have obtained OutGFX.bin and when editing it with Tile Molester, I still cannot see any sprites.


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?
I want to learn and I really appreciate you sharing your knowledge with me.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho on January 25, 2022, 05:11:52 pm
Sir, I suggest you show your appreciation by taking the time to carefully read what people are writing.

Someone already said that you need to set Tile Molester to 2BPP Linear with blocks set to 2x2. Is that what you did?
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on January 25, 2022, 05:21:19 pm
You're right, I read it quickly from the mobile.

Yes, I have tried that way and also in other ways but I can't see any sprite.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho on January 25, 2022, 09:15:46 pm
Then either you are doing something wrong, or there is something wrong with the file.

Working with the unmodified files, have you been able to get the same image that was posted on the previous page?
Spoiler:
(https://cdn.imgpaste.net/2021/12/02/KTShcN.png)
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on January 26, 2022, 01:31:13 am
You should look for "4 bpp linear" I believe.

I used this utility: http://www.romhacking.net/utilities/93/

I opened the resulting OutGFX.Bin that the interleave program I showed you produced and I can see the Ninja's sprites at the beginning. On the arcade hardware sprites can be 8x8, 16x16, 32x32, or 64x64 pixels in size. Depending on the size of the sprite being displayed it will determine which areas in ROM are fetched. There may be settings in Tile Molester to rearrange the viewer to make them appear arranged like the hardware would do so for a 16x16 or larger sprite, or it might not.

If you have never edited graphics in a ROM before it might be a better choice to try doing it on a console game like for the NES, SNES, or Genesis. There are more tutorials available to help you with that sort of things. Hacking arcade games will be more difficult due to the lack of resources available. You can make up for that if you have enough experience with other things but if you are just starting it's going to be very difficult. So you might want to try something a bit easier and come back to this idea once you have some experience.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on January 26, 2022, 02:29:04 am
Working with the unmodified files, have you been able to get the same image that was posted on the previous page?
Yeah I got the same sprite but I only got to see that one.

I opened the resulting OutGFX.Bin that the interleave program I showed you produced and I can see the Ninja's sprites at the beginning. On the arcade hardware sprites can be 8x8, 16x16, 32x32, or 64x64 pixels in size. Depending on the size of the sprite being displayed it will determine which areas in ROM are fetched. There may be settings in Tile Molester to rearrange the viewer to make them appear arranged like the hardware would do so for a 16x16 or larger sprite, or it might not.
What settings did you use other than 4 linear bpp?

January 26, 2022, 07:09:27 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Good!! I have managed to see the sprites in OutGFX.bin.

Is there a way to see them larger? They look cut off.

How can I see the colors of the sprites palette correctly?

https://ibb.co/hccbRwW
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on January 27, 2022, 02:51:16 am
You are seeing the sprites as they are stored in ROM. They aren't going to look neat and organized like you might have thought. The data for different frames of animation or even the blocks of sprites that make up a frame may not be next to each other in ROM to appear correct in your graphics editor. That is just how it is, there is nothing you can do about it.

The graphics ROM does not contain any palette data. If you want to see a sprite with the correct palette it is up to you to enter the correct palette into your graphics editor. You can find what palettes look like if you run the game in MAME with the debug mode enabled.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on January 27, 2022, 03:26:07 am
Wow, that greatly reduces the possibilities for editing the sprite graphics.

So just to be clear, can I set the correct palette in Tile Molester? I already extracted the palette with MameDebug.

Once I have made the modifications in the OutGFX.bin file, how do I unmerge the OutGFX.bin file to be able to have the loose files of the rom again and later compress them to a zip?
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on January 27, 2022, 06:35:45 pm
Editing sprites in any game can be difficult. If you only need to change the pattern data, it's not too bad. But if you need to change the arrangement of sprite cells it's going to require altering data in the program rom.

Yes you can set the correct palette if you know the colors and the order of them, which you can see in MAME.

After making your modifications you need to do the reverse of what the program source code I posted does. You'll be taking the first byte and outputting that to a EvenGFX.bin, then the next byte to OddGFX.bin, and repeat until reaching the end. Then after you have those you'd just need to chop out each section for the original rom files.

All of this is very simple to do if you know a programming language to make a program to do it for you.

Also MAME doesn't require zipped roms so you could just place them in the appropriate folder in the ROMS folder. Be aware that MAME might complain if your ROMs are modified and you may have to use a command to tell it to ignore that and load the ROMs anyway.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on January 28, 2022, 03:02:27 am
So, there are sprites that are cut, for example, the trunk and on the other hand the legs. I don't see a way to edit an entire sequence. Sequences such as walking, running, jumping...

I wonder how they edited Dragon Bowl? In it, they replaced all the graphics except the sound.
https://www.youtube.com/watch?v=BcVqSL5rGCA

I already have Ryu Hayabusa's palette. I'm going to try editing the palette in Tile Molester and show you the results.

I don't really understand how to do it:
Here is the code you posted. What should I modify?
#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");

}

What command should I use if MAME won't run the modified game?

I know I ask a lot of questions but many doubts arise as I go along.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on January 28, 2022, 04:02:58 am
I think MAME will run your modified ROMs as long as you launch the game from the command line. So by typing at the command prompt "mame.exe gaiden" for example.

Dragon Bowl was a "professional" bootleg made by people with enough knowledge and experience to do such a ROM hack. There is no secret to it.

It would not help you for me to tell you what to modify in the C program code I posted. If you understand what the program is doing, then you will understand how to make it "undo" what it is doing. But if you have no understanding of programming then you need to learn and that's beyond what anyone can teach you here in a few posts.

I will explain one more time about what the program is doing. The program takes the Even and Odd graphics ROM data and combines them into one file which represents how the arcade hardware sees the graphics data. So you can see in the program where it opens the two files and then creates a third file for the output. It then creates the output file by switching between reads a byte from the Even data and then the Odd data until all of the even and odd data has been read.

To reverse this you need a program to read the OutGFX.Bin and write new EvenGFX.bin and OddGFX.bin files. The program would read a byte from the OutGFX and write it to the EvenGFX, then read the next byte and write that to the OddGFX, and repeat that process in the same way it did before until all the data has been written.

The final step would be to take the EvenGFX and OddGFX files and cut them into pieces which made up the original ROM files. You could write a program to do this for you if you learn C or another programming language. It's all very simple moving data around.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on January 28, 2022, 08:22:53 am
Good!
Do you know any book or website that stands out to learn C/C++?

I've already got the right palette for Ryu hayabusa.
https://ibb.co/K78t5Gw

Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho on January 28, 2022, 11:29:24 am
Do you know any book or website that stands out to learn C/C++?
You really don't have to know much about C specifically in order to do this, except maybe the particular syntax of "fputc" and "fgetc". Just look at each line and think about what it is doing. You don't even have to use C if you don't want to; other languages will have similar commands.

If you've never, ever programmed before I might suggest starting with Python. There are lots of Python courses for non-programmers out there. A Byte of Python (https://python.swaroopch.com/) seems popular.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on January 28, 2022, 04:26:52 pm
There are many languages you could achieve what you need to do. A long time ago I liked BlitzBasic. The related BlitzPlus is available here:
https://blitzresearch.itch.io/

It's pretty easy to use. Though it may cost money, I don't think it's free. Alternatively if you want to use the C program I posted and adapt it to do the other tasks you could setup something like DevCpp which is free. You can find the setup for that here:
https://sourceforge.net/projects/orwelldevcpp/files/Setup%20Releases/Dev-Cpp%205.11%20TDM-GCC%204.9.2%20Setup.exe/download

As Jorpho said, just look over the example program I posted and you can learn how you can open files either to read or write and how to read a byte or write a byte. Just take your time to understand and figure out how it works.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on January 28, 2022, 06:02:06 pm
I'm going to try to modify the code you posted to do what I want.
I really appreciate the patience and help you offer me, it is a pleasure to deal with such wise people.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on January 29, 2022, 03:11:18 am
Good luck. With some time and patience you can figure it out.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 03, 2022, 03:08:26 am
I have one more query. To change the color palette, for example, the colors of Ryu Hayabusa's clothes, you would have to do it from Tile Molester or by modifying the code in another way. In the event that it was with another program, with which one would it be and how could it be done?
Thanks!
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on February 04, 2022, 01:07:56 am
If you want to alter the palette in the game that will require finding the palette data in the Program ROM data. I believe the palette entries are organized like this:

(xxxxBBBBGGGGRRRR)

x = Not Used.
B = Blue
G = Green
R = Red

Palette RAM on the hardware is mapped at 078000-079fff.

I would suggest using MAME in Debug mode and once Ryu's palette is loaded into Palette RAM use the memory viewer in MAME to see the exact values of all 16 colors of his palette in RAM and then use a hex editor to see if you can find that same data in program ROM. However like the Graphics ROMs the Program ROMs are 8-bit and you'll need to combine them by interleaving the data from both ROMs. gaiden_1.3s is the Odd bytes and gaiden_2.4s is the Even bytes I believe.

Or in the MAME debug window you can type in this command
Code: [Select]
save gaidenprg.bin,0,40000
It will save the program data to a file for you and then you can open that in a hex editor. But once you find the data if you change it in the combined (16-bit) file you'll need to make a program or find one to take the rom back apart into two 8-bit roms so you can have MAME load from the original file names. Or you could find the data and then try to find it in each of the original 8-bit files and edit it there.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 04, 2022, 01:22:08 pm
How can I see that the palette is already loaded in Palette RAM?
Where is it and how can I use the MAME memory viewer?
Which hex editor is better?
I found a C++ teacher but I haven't started classes yet.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on February 04, 2022, 06:35:44 pm
When you run MAME you need to add a command line option which is
Code: [Select]
-d
If you aren't familiar with the command line you can right click on the MAME program and click Create Shortcut. Then right click on the shortcut and select properties. In the box that says Target, add the -d to the end which should be after the .exe

This will make MAME start with the debugger on when you start it through the shortcut.

There will be a window where if you look in the File menu you can tell it to make a New Memory Window. Then you just need to go look starting at that 78000 address I mentioned before. The memory in that section from 78000 to 79fff will change as the game runs.

Another thing, when the game is running press F4 to bring up a graphics viewer. Press Enter to cycle through different options. One option will show you the palettes, others will show different things related to the graphics.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 05, 2022, 02:43:30 am
Yes, I know how to run MAME in debugger mode.
So for example if I wanted to change Ryu Hayabusa's clothes to yellow, would I just change that code and save?
I also knew the way to see the tiles and the palettes with F4, in fact, I have saved the palettes, but how can I apply them to make changes in the code according to the way you tell me?

February 05, 2022, 04:39:33 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Ok, now I opened MAME in debugger mode and exported gaidenprg.bin.

https://ibb.co/gTZQYjF

What hex editor do you advise me to edit it?
Until I start the C++ classes, could you create the program or code for me to de-interleave the files? You would do me a great favor.
I have already opened the memory window and found the value 078000 but it is not clear to me if it can be edited from the MAME Debugger itself or if I have to do it from the exported gaidenprg.bin file. Because then, what is the point of finding that value in MAME Debugger if we then edit it from a hex editor?
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on February 06, 2022, 11:18:13 pm
If you type in different values at the 78000-79fff range in the memory viewer it may change the colors, it depends on both how the game is programmed and how MAME works. I haven't tried it. But if you look at the values in the range and look at what I already told you about how each 16-bit value relates to Red, Green, and Blue color values you could probably find Ryu's palette. Then you'd just search the program ROM for that string of values in a Hex Editor. If you find it, then you can modify it and see what happens.

I like the Hex Editor called HxD.

Code: [Select]
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");

}

Three files are opened. The ones with "rb" are being Read. The one with "wb" is being written. In this program you're interleaving the Even and Odd together. That's why in the loop which starts with "for(int n=0;n<0x80000;n++)" you see it is reading a byte from the even file and putting that in the output file, then reading a byte from the Odd file and putting that in the output file.

To reverse this you'd instead open two files from writing and one for reading. You would read a byte from your interleaved file and write to your Even output file. Then read another from the interleaved file, and write to the Odd output file. Pretty simple.

To change the palette data you'll be editing the values in the "gaidenprg.bin". You can maybe edit them in MAME but for permanent changes you need to edit the rom.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 07, 2022, 04:55:30 pm
I don't know how to look at the exact values of his 16 palette colors in RAM in MAME Debugger to find Ryu's palette.
For example, one of the hexadecimal color codes for Ryu's clothing is bbbbee but I don't know how it is expressed in the MAME memory window.
https://ibb.co/YLbFRVT

I also downloaded the HxD program and opened the gaidenprg.bin file that I exported in MAME Debugger earlier but when searching for the value 78000 for example, it doesn't find it.
https://ibb.co/RHgJdBs
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on February 07, 2022, 07:26:35 pm
You misunderstand, $78000 is the address in the hardware where palette RAM is located. If you point a Memory Viewer to that address by typing 78000 into the white box and press enter it will seek to there. The Blue Ninja is actually the very first palette when the game is running and the Red Ninja is the second palette. The values for his Blue Ninja palette are:

Code: [Select]
0000.0FFF.0040.0633.0855.0A77.0C99.0EBB.0008.000B.007F.0358.09BD.057A.0BDF.079C
Unfortunately I didn't find this string of bytes in ROM like that, which means changing the palette would take more research to do it. Using the MAME debugger you can find there is a function around $11C0 which tends to do all the writing to Palette RAM and it seems to source the data from WorkRAM rather than ROM. So the values in ROM are loaded into WorkRAM before they get sent to Palette RAM.

If you search for only part of the string like 09BD.057A.0BDF.079C you will find a match. I did not try modifying it to see if it is part of palette data in rom.

Edit: I did try changing the values and they did not appear to change anything. Most likely changing the palette in the game is going to require you to learn how to use the debugger and gain some understanding of 68000 assembly language. Sorry it's not an easy game to tackle.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 08, 2022, 04:47:23 am
Wow, I know it's hard and I really appreciate your help and patience, but I'm really looking forward to hacking this game, even if it's just changing the color of Ryu's clothes.  :)
Could you guide me in the process even if it is complicated to achieve it?
I will follow the steps you tell me.

February 08, 2022, 09:22:45 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Can the information in this file be of any use to us?
https://we.tl/t-FkLFuTpF0s
I downloaded it from this website:
http://adb.arcadeitalia.net/dettaglio_mame.php?game_name=gaiden
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho on February 08, 2022, 10:55:50 am
Could you guide me in the process even if it is complicated to achieve it?
I will follow the steps you tell me.
Sooner or later you're going to have to figure out some of these things on your own.

Quote
Can the information in this file be of any use to us?
Isn't that the MAME source code? That was already referenced on the first page of the thread.

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:
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 08, 2022, 05:11:11 pm
My idea is to learn but I wanted to motivate myself by getting something simple first, like changing the color of her clothes but apparently it's not as simple as changing a code and that's it.
You are right, I already named the file gaiden.cpp. I wrote in many forums and I no longer remember if I had named it in this one.
The truth is that only in this forum I found interesting answers.
So, what steps do you advise me to follow?
How can I get to hack the game?
Learn C++
Learn how the MAME Debugger works
Learn 68000 assembly language
Correct?

February 08, 2022, 05:37:18 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
I found these videos:
https://www.youtube.com/watch?v=NGibh6uPKRA&t=186s
https://www.youtube.com/watch?v=jP-j4F-X9RM
https://www.youtube.com/watch?v=h6PiYtlv7qA
https://www.youtube.com/watch?v=yasHR7F9oBU&t=22s
https://www.youtube.com/watch?v=qbsJI2F1fjs&t=20s
https://www.youtube.com/watch?v=bIl5hgVB4JE&t=569s
https://www.youtube.com/watch?v=p-Wa8TMd2jI&t=392s
https://www.youtube.com/watch?v=5kYBgawhXJA&t=184s
https://www.youtube.com/watch?v=RPEKtR9xeCo&t=21s
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on February 08, 2022, 07:48:02 pm
Learning 68000 assembly language will help you understand what is going on when using the MAME debugger in Ninja Gaiden and other games using the 68000 processor. You don't need to be an expert, you just need to be familiar with it enough to figure out what is going on. Then learning about how you can use the MAME debugger will be more helpful.

Learning C++ is fine, but it doesn't have to be that. You could learn any programming language that would allow you to make programs to run on your computer. The reason you'd want to be able to do this is then these basic data manipulation tasks are something you can program yourself.

Yes, looking at the MAME source code for the "gaiden" driver can give you a lot of information if you know what you're looking at. But it won't tell you everything.

As I stated earlier, I did briefly look into seeing if the palette data loaded into palette RAM was present in ROM as-is and it was not. The data appears to get written to WorkRAM at some point which is then transferred to palette RAM by a function located near the beginning of progrom rom. So you'd probably want to seek out the part where the palette data gets placed into WorkRAM and see where those values are loaded from. This is something the MAME debugger can help you do.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 10, 2022, 02:47:55 am
Download a 68000 assembly language manual. Due to my lack of programming knowledge, I see it as somewhat complicated.
https://ruidera.uclm.es/xmlui/bitstream/handle/10578/42/A_%20hardware_software_68000.pdf?sequence=1&isAllowed=y

To rule out alternatives, is it possible to modify the palette from Tile Molester and have it be modified in the ROM once you save it, or does the Tile Molester palette only serve to see the sprites with the correct colors and thus facilitate the location of the sprites?
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: Jorpho on February 10, 2022, 11:05:26 am
Due to my lack of programming knowledge, I see it as somewhat complicated.
So learn to program! I agree that 68000 assembly language might not be the best place to start if you've never, ever programmed before. (Even C++ might be a bit much.) You have already been provided some excellent resources.

Quote
is it possible to modify the palette from Tile Molester and have it be modified in the ROM once you save it, or does the Tile Molester palette only serve to see the sprites with the correct colors and thus facilitate the location of the sprites?
If it was possible to modify the palette in ROM using Tile Molester, then someone would have suggested that already.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 10, 2022, 11:29:52 am
Ok, as you advised me, a good start would be with BlitzPlus.

I have contacted the person who has the channel arcade-cabinets.com and he told me that this video can help me:
https://www.youtube.com/watch?v=Rmd-tjT7Qvw
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: MottZilla on February 10, 2022, 11:35:25 pm
That video is not going to help you with Ninja Gaiden. That video looks to be talking about much more simple hardware.

As I said before the Ninja Gaiden palette data is located somewhere in the Program ROM and gets written to WorkRAM before later being copied into Palette RAM. You'll have to figure out how this all happens and you can work backwards and by using the MAME debugger you may be able to discover where in ROM the data is located.

BlitzPlus would be one options for learning how to do some programming and would help you with making simple programs for manipulating the ROM data as needed.
Title: Re: Hack Ninja Gaiden Arcade (original 1988) for MAME
Post by: fhrans on February 12, 2022, 07:32:08 am
In MAME Debugger the colors of the palette change but, I understand that there is no way to export the ROM saving the edited changes in the Memory window.
https://we.tl/t-JcLnHmjpnA
You commented that you only found a snippet of the palette's code chain and didn't change anything by modifying it.
I don't know where to look to find out how this process happens, I've looked on Google but I can't find anything.

February 15, 2022, 04:12:34 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Can this website help to find the palette in the ROM?
https://web.archive.org/web/20161106154933/http://letshackarcadegames.com/?p=407