Need help with compressed tiles

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
Mr_Zee
Posts: 4
Joined: Thu May 28, 2020 7:43 am

Need help with compressed tiles

Post by Mr_Zee » Thu May 28, 2020 8:08 am

Hi everyone! Excuse me if i chosen wrong part of this forum for my topic. I tried to do my best )

Here is the deal: i need to replace girls with simple numbers in NES ROM named Ivan "Ironman" Stewart's Super Off Road
Here is the screens wich i need to edit:
Image
Image




Here is an idea of the way i want to replace it with:
Image

I want to make this game a bit more censored. Don't ask me why. This task may look strange - but this is definitely what i need to do. :lol:

The first problem is that graphics in this ROm is compressed.
Image

The second one - i am totally noob at this kind of job ( I can try to use some kind of soft like YYCHR - but as i said - the graphics is compressed ((

Help me guys!

p.s.: i understand that it can take time to do this - so i am absolutely ready to pay for this job!

A lot of thanks for your patience and attention!

calima
Posts: 1160
Joined: Tue Oct 06, 2015 10:16 am

Re: Need help with compressed tiles

Post by calima » Thu May 28, 2020 10:10 am

A graphics edit is not enough: as you see, 2-4 use the same graphics, just palette swapped. So it needs some code edits too. Perhaps it'd be better to ask at romhacking.net than here.

User avatar
Dwedit
Posts: 4333
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Need help with compressed tiles

Post by Dwedit » Thu May 28, 2020 11:29 am

The font in that screenshot isn't compressed, it just aren't aligned to a usual 16-byte boundary. Use the + or - buttons in YY-CHR to change the byte alignment.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Mr_Zee
Posts: 4
Joined: Thu May 28, 2020 7:43 am

Re: Need help with compressed tiles

Post by Mr_Zee » Thu May 28, 2020 2:14 pm

Dwedit wrote:
Thu May 28, 2020 11:29 am
The font in that screenshot isn't compressed, it just aren't aligned to a usual 16-byte boundary. Use the + or - buttons in YY-CHR to change the byte alignment.
Oh my! It works! Thanks a lot!

Ok, here is the next part - how to find all of the tiles i need? Using an emulator i can find tiles like in the picture. But i don't understand how to fund all these parts of the tileset in YY-CHR?
Image


Is there any way to findem easier the searching all of the tile by tile (( It looks imposible as look at this:
Image

strat
Posts: 364
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Re: Need help with compressed tiles

Post by strat » Thu May 28, 2020 3:03 pm

You'll just have to learn programming (6502 assembly and NES hardware required; a PC-based language like Python is recommended) to do this properly.

I figured out in a few minutes how to scramble the offending graphics beyond recognition (without replacing them). The compression format is a simple RLE where any byte not 0 or 0xFF is written to chr-ram as is; any byte that is 0 or 0xFF is followed by how many times 0 or 0xFF is written to chr-ram. The image below results from replacing all the single-written bytes with 0xFE so now we know how to edit the tiles.
sofferase-0.png
sofferase-0.png (6.65 KiB) Viewed 2372 times
Just to give an idea of the work involved, these are the next steps:

1. Writing a tool to export your NES tiles into the format used by the game and inserting it into the rom. This will be the easiest step in the whole thing.

2. The game's routine to output the tiles from rom to chr-ram checks for certain addresses supplied by the tile data to terminate the routine, so you'll have to modify that when deleting the woman graphics and inserting your own. Ideally, your replacement graphics will take up the same or less space than the deleted material, otherwise you'll have another problem.

3. Figuring out how the game arranges the tiles into a coherent image on the tilemap (nametable) and documenting that routine. Then changing whatever is needed to display those tiles - this might be the hardest part. It might be as simple as changing the bytes used by the woman images so the existing routine knows where to put your graphics. But there's a chance you might have to alter the asm instructions. Either way, you'll have to know asm just to figure out what to do.

Here's an example of the kind of tools you'll be writing in a language like Python (any language where you can read and manipulate files with a few lines of code will do).

Code: Select all

import sys

def Overwrite(st_start, wo_end, rom_bytes):
	#st_start = 0x21B4
	#wo_end = 0x2B33
	bi = st_start
	while bi < wo_end:
		if 0 == rom_bytes[bi] or 0xFF == rom_bytes[bi]:
			bi += 2
		else:
			rom_bytes[bi] = 0xFE
			bi += 1

def main():

	romfname = sys.argv[1]

	with open(romfname,"rb") as rom_file:
		rom_bytes = bytearray(rom_file.read() )
	rom_file.close()
	
	Overwrite(0x3724,0x3889,rom_bytes)
	Overwrite(0x3E3E,0x3FF5,rom_bytes)
	Overwrite(0x21B4,0x2B33,rom_bytes)
	
	with open("sofferase.nes","wb") as output_file:
		output_file.write(rom_bytes)
	output_file.close()	
	
main()	
And this is an example of the asm you'll read to figure out the game. A good place to start would be figuring out where $B879 is written to $30/$31. Then you can delete the woman graphics completely and supply a new address so the other tiles remain in their place in chr-ram. This must be done so the rom still has the same amount of bytes and whatever bytes you move around must not be asm instructions because that will likely break the program.

Code: Select all

 00:9F75:A0 00     LDY #$00
 00:9F77:A2 01     LDX #$01
 00:9F79:B1 2E     LDA ($2E),Y @ $B713 = #$10
 00:9F7B:F0 04     BEQ $9F81
 00:9F7D:C9 FF     CMP #$FF
 00:9F7F:D0 08     BNE $9F89
 00:9F81:20 1A AE  JSR $AE1A
 00:9F84:48        PHA
 00:9F85:B1 2E     LDA ($2E),Y @ $B713 = #$10
 00:9F87:AA        TAX
 00:9F88:68        PLA
>00:9F89:8D 07 20  STA PPU_DATA = #$00
 00:9F8C:CA        DEX
 00:9F8D:D0 FA     BNE $9F89
 00:9F8F:20 1A AE  JSR $AE1A
 00:9F92:A5 2E     LDA $002E = #$13
 00:9F94:C5 30     CMP $0030 = #$79
 00:9F96:D0 DF     BNE $9F77
 00:9F98:A5 2F     LDA $002F = #$B7
 00:9F9A:C5 31     CMP $0031 = #$B8
 00:9F9C:D0 D9     BNE $9F77
 00:9F9E:60        RTS
 
I don't know if anyone will do this whole thing for pay but these days who knows.

P.S. You'll also need a hex editor like XVI32 to verify the location in the rom file corresponding to what you see in the debugger. YY-CHR might be useful for finding empty rom space if needed, but not so much for editing the rom itself.
Last edited by strat on Sun May 31, 2020 10:41 pm, edited 1 time in total.

Mr_Zee
Posts: 4
Joined: Thu May 28, 2020 7:43 am

Re: Need help with compressed tiles

Post by Mr_Zee » Fri May 29, 2020 6:28 pm

strat wrote:
Thu May 28, 2020 3:03 pm
I figured out in a few minutes how to scramble the offending graphics beyond recognition (without replacing them). The compression format is a simple RLE where any byte not 0 or 0xFF is written to chr-ram as is; any byte that is 0 or 0xFF is followed by how many times 0 or 0xFF is written to chr-ram. The image below results from replacing all the single-written bytes with 0xFE so now we know how to edit the tiles.
THANKS A LOT

Dear friends!

I will very appreciate any help from every person who could scramble two screens i showed at the beigining of this topic and send me in any format for your choise (ips for ex.) via PM!

Everthing i need from you is to screw up girls in this game (theese are only two screens with em) and send me it with screwed graphics.

The first screen with girls is the one you see at the begining of the game.
And the second one you will see after each race (this is a racing game as you remember :) )

Thank you so much brave stranger!
Last edited by Mr_Zee on Sun May 31, 2020 7:02 am, edited 2 times in total.

tepples
Posts: 22020
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Need help with compressed tiles

Post by tepples » Sat May 30, 2020 2:28 pm

Hold up. Don't break the law. IPS yes, ROM no.

Mr_Zee
Posts: 4
Joined: Thu May 28, 2020 7:43 am

Re: Need help with compressed tiles

Post by Mr_Zee » Sun May 31, 2020 6:52 am

tepples wrote:
Sat May 30, 2020 2:28 pm
Hold up. Don't break the law. IPS yes, ROM no.
Sorry for that. I edited my messege. There is no any piracy requests now.

tepples
Posts: 22020
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Need help with compressed tiles

Post by tepples » Sun May 31, 2020 8:41 pm

Thanks for updating the request. With that out of the way. we can get to the hackin'.

strat
Posts: 364
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Re: Need help with compressed tiles

Post by strat » Sun May 31, 2020 9:48 pm

For those following this topic, you might be interested to know just overwriting tiles is a bigger pain than it should be. The RLE-compressed data stream has to be the same length no matter what and the loop that reads it must terminate with the same chr-ram bytes getting filled in. Otherwise the graphics you don't want to edit are thrown out of whack. Because the programmer decided to do this:

Code: Select all

; $AF2E = starting address of compressed tiles
 00:AE21:A9 2E     LDA #$2E		
 00:AE23:85 2E     STA $002E = #$23
 00:AE25:A9 AF     LDA #$AF
 00:AE27:85 2F     STA $002F = #$AB
 00:AE29:A9 BA     LDA #$BA
 00:AE2B:85 30     STA $0030 = #$97
 00:AE2D:A9 B0     LDA #$B0		; end address of compressed tiles
 00:AE2F:85 31     STA $0031 = #$AC
 00:AE31:A0 00     LDY #$00
 00:AE33:8C 06 20  STY PPU_ADDRESS = #$00
 00:AE36:8C 06 20  STY PPU_ADDRESS = #$00
 00:AE39:4C 75 9F  JMP $9F75	; loop to decompress tiles
 
 00:AE3C:A9 46     LDA #$46		; end address of compressed tiles
 00:AE3E:85 30     STA $0030 = #$97
 00:AE40:A9 B2     LDA #$B2
 00:AE42:85 31     STA $0031 = #$AC
 00:AE44:4C 75 9F  JMP $9F75	; loop to decompress tiles
 
 00:AE47:A9 D2     LDA #$D2		; end address of compressed tiles
 00:AE49:85 30     STA $0030 = #$97
 00:AE4B:A9 B3     LDA #$B3
 00:AE4D:85 31     STA $0031 = #$AC
 00:AE4F:4C 75 9F  JMP $9F75	; loop to decompress tiles
 
 00:AE52:A9 5E     LDA #$5E		; end address of compressed tiles
 00:AE54:85 30     STA $0030 = #$97
 00:AE56:A9 B5     LDA #$B5
 00:AE58:85 31     STA $0031 = #$AC
 00:AE5A:4C 75 9F  JMP $9F75	; loop to decompress tiles
 
; ... and so on and so forth ...
Funny enough, commercial NES programmers don't seem to care how difficult their work is to tamper with 30 years later. It's impossible to make major edits to the graphics of this game without rewriting the asm code.

Post Reply