Romhacking.net

Romhacking => Newcomer's Board => Topic started by: Mr. Saturn on January 02, 2020, 05:53:52 pm

Title: entire rom palette tinted green
Post by: Mr. Saturn on January 02, 2020, 05:53:52 pm
Whilst hacking the Earthbound Zero ROM, everything became tinted green. I edited it, saved it and came back to it later, and it was tinted green. I checked the palettes but they were unchanged.
Unfortunately I have no idea what I was doing before this happened. So I don't know if anything can be done about it.
Title: Re: entire rom palette tinted green
Post by: Jorpho on January 03, 2020, 11:49:17 pm
Your last thread suggested you were trying to copy and paste all the colors from one version of a ROM to another.
http://www.romhacking.net/forum/index.php?topic=29394.msg383380

Is that what you tried to do?
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 04, 2020, 02:27:32 am
Quote
Unfortunately I have no idea what I was doing before this happened.

Compare original and hacked files. Make changes one by one in original file and test it until you find the source of your issue.

And for starters learn how to ask proper questions. We are not telepathists here. 
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 04, 2020, 07:18:38 am
Sounds like you wrote emphasis bits to the ppu mask.  https://wiki.nesdev.com/w/index.php/PPU_registers#PPUMASK
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 04, 2020, 05:33:59 pm
Quote
Sounds like you wrote emphasis bits to the ppu mask.
I thought that's what it was, but couldn't quite figure it out. The value in my hex editor (FCEUX), the 2nd value of 2000 (as that's where going to $2001 took me) is identical to that of the unmodified ROM. Maybe I'm looking in the wrong place?

Quote
We are not telepathists here.
Sorry about that, the last thing I remember doing was haphazardly searching for where a certain sprite's data was stored. Editing things, seeing what happened, then switching it back. I may have forgotten to change a value back, or gave it the wrong value. It was kinda all over the place, so I guess that probably doesn't help much.

Quote
Your last thread suggested you were trying to copy and paste all the colors from one version of a ROM to another.
I wound up just doing that the hard way, going to every sprite in the game and changing it's palette. The palettes themselves (their values and whatnot) are unchanged, but they've all been tinted green.
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 04, 2020, 10:02:56 pm
I thought that's what it was, but couldn't quite figure it out. The value in my hex editor (FCEUX), the 2nd value of 2000 (as that's where going to $2001 took me) is identical to that of the unmodified ROM. Maybe I'm looking in the wrong place?
Imagine the $2001 address as a command. It's a special address. You're not writing the byte to a memory location that you can read from later, it's just how the processor takes these very specific instructions. So somewhere in your new code you're writing a byte that has the green bit set to the $2001 address. Set breakpoints to writes to $2001 and see if you're writing any byte with that bit set (anything from #40-#7F or #C0-#FF).

Since you forgot what you changed you can open the original file and your modified file in Frhed (a free hex editor) to compare differences.
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 06, 2020, 06:39:53 pm
Thanks for your advice.
I downloaded Frhed and compared both files. There are a LOT of differences (specifically 6256).
So I moved onto trying the breakpoints.
Admittedly, I've never used breakpoints before. I set the address to 2001, set it to write, and kept it in CPU memory. I tried several different things with the condition, but I'm kinda at a total loss.
I'm assuming I need to find if (thingy here) is greater than #40 or less than #7F, or greater than #0F and less than #FF, but nothing I've tried so far has worked.

Shortly after writing the above, I thought to try switching the breakpoint from CPU memory to PPU memory. The game runs now, but nothing else is really happening. There doesn't appear to be any indication of, well, anything.

The main two conditions I'm using are:
A >= #40 || A<= #7f
and
A >= #C0 || A<= #FF
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 07, 2020, 08:32:25 am
You don't need to use conditions, leave it blank. Set the breakpoint for writes to $2001, reset the game, and run. Then look into the instruction that is writing to $2001, likely a STA, which means it is taking the value at the accumulator (A) and copying it into $2001. So it is a matter of keep clicking "run" while keeping your eyes on A. Once A has one of the values that meets the criteria you may have found the problem. Now mark the address where this happens and compare to the same address on the original ROM.

If you really want to use conditions, then it has to be A >= #40 && A<= #7f. When you use || you're writing "or" which means it will break on any values in that expression you wrote (anything that is bigger than 40 or smaller than 7F is all values from 0-FF, so that doesn't help). You want to use && which means "and".
A more complete condition then is
(A >= #40 && A<= #7F) || (A >= #C0 && A<= #FF)
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 07, 2020, 09:28:43 am
Better use W instead of A in case it is not written via A. W is a condition on "write value", basically it is like all 3 registers combined.

And you don't need to compare the very original rom. Take the rom where you don't have green, and compare to the rom where it's started. You do have previous hack versions, don't you?
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 07, 2020, 09:45:16 am
Better use W instead of A in case it is not written via A. W is a condition on "write value", basically it is like all 3 registers combined.
I wasn't aware of W in the conditions setter. Nice! Yes, so it is
Code: [Select]
(W >= #40 && W<= #7F) || (W >= #C0 && W<= #FF)
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 07, 2020, 06:49:34 pm
I'm not totally sure I'm doing this right:
I have a breakpoint set to $2001, and I'm running about in the game watching the A value shown under Seek To and all that stuff.
Whenever it breaks I'm looking at the line the breakpoint has selected
(such as 0F:F973:8D 07 20  STA PPU_DATA = #$00)
and watching to see if the #$00 matches up with the A value.
So far the #$00 has only ever been #$00 and #$0A. The A value hasn't matched up with it except for on the title screen where A is also 00, which is identical to my backup ROM. This is after wandering around in the game for a while doing this.
Title: Re: entire rom palette tinted green
Post by: Fox Cunning on January 08, 2020, 08:58:19 am
I'm not totally sure I'm doing this right:
I have a breakpoint set to $2001, and I'm running about in the game watching the A value shown under Seek To and all that stuff.
Whenever it breaks I'm looking at the line the breakpoint has selected
(such as 0F:F973:8D 07 20  STA PPU_DATA = #$00)
and watching to see if the #$00 matches up with the A value.
So far the #$00 has only ever been #$00 and #$0A. The A value hasn't matched up with it except for on the title screen where A is also 00, which is identical to my backup ROM. This is after wandering around in the game for a while doing this.
FCEUX is not main main emu/debugger, but I'm fairly sure what you are seeing is the value of the register at the moment execution was stopped.
In this case, you can completely ignore that value and check the code before that instruction, e.g.:

Code: [Select]
  LDA $04 = #$0A
  STA PPU_DATA = #$00

or:

  LDA #$0A
  STA PPU_DATA = #$00

In both these examples #$0A is being written, not #$00, and it should be the value in the Accumulator if execution stops at the "STA".
But you can ignore any value read from PPU_Data unless you are specifically reading PPU_Data (in that case, only ignore the first read).

Anyway, I believe you should be looking at writes to $2001 (PPU_MASK), not $2007 (PPU_DATA). Double-check your breakpoints.
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 08, 2020, 10:27:17 am
That "= $00" is a value stored in ram address $2001. That's not the value you need to look at. Like I said, you need to look at the value in the accumulator A at the moment the breakpoint occurs. It should be to the right inside a small box. If A holds one of the no-no values, then that may be where the problem is.
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 08, 2020, 06:58:10 pm
Quote
If A holds one of the no-no values, then that may be where the problem is.
What values am I looking for?
I know that bit 5 in the PPU_mask controls the green tint, but admittedly I don't know how these bits are stored. I'm guessing that they're somehow compiled into what is seen in A? Or is A modifying the PPU_mask bits? Basically, how do I know if a value is the problematic one?

Also, when I do find the green value, would I find it in the hex editor or can I change it in the debugger? I'm guessing it's the former, but regardless, how would I do that?

Quote
But you can ignore any value read from PPU_Data unless you are specifically reading PPU_Data (in that case, only ignore the first read).
The breakpoint is pretty much only finding PPU_data lines. Should I (and how would I) add some sort of condition to exclude them?


Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 08, 2020, 07:55:23 pm
If you forgot what values you are looking for, read this thread again.

If you don't know bits work, then look it up.
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 08, 2020, 10:22:44 pm
Fiddling with registers and bits may not be the easiest task to start with when learning assembly and NES. But I didn't want to say that because if there's a task that gets you to learn something it is going to be the task that you actually want to do. So, okay.

You should read more about how bytes and bits work. There's a lot of info about that online. But, to make it short, the values I mentioned all have the 5th bit set. So whenever any of those byte values are written to $2001, that's setting the green emphasis bit (and may be doing other irrelevant things to this case).
The other thing that you should learn is some level of 6502 asm coding. This is because in order to detect the problem and fix it you're gonna need to read and write assembly code, respectively. The good news is that it's not too hard, it's just basically some instructions executed one at a time that change values in memory or registers. You don't need to know them all, you can check them as you read them. Fceux's debugger is great at showing you how the ROM's byte code would probably be interpreted by the CPU. To answer your question, you can use the debugger to navigate, but changes need to be made in the hex editor (when viewing the ROM memory, not RAM).

When setting the breakpoint you write 2001-2001 in the address range. I don't know how you got 2007 there. And I think you can leave it at CPU space, no need to select PPU. I can't be sure of that one right now.
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 08, 2020, 10:46:07 pm
He needs to select CPU memory option.

He doesn't need to write 2001 in both fields if it's not a range (but it will work anyway even if he uses range for a single address).
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 09, 2020, 12:54:30 am
Quote
If you forgot what values you are looking for, read this thread again.
I forgot those were there. My bad.
Quote
When setting the breakpoint you write 2001-2001 in the address range. I don't know how you got 2007 there.
I know what I did wrong here. I had 2001-unspecified instead of 2001-2001.
Quote
He doesn't need to write 2001 in both fields if it's not a range (but it will work anyway even if he uses range for a single address).
...Or maybe I don't know what I did wrong there. So 2001-unspecified probably wasn't the problem?
I just tested it, and 2001-2001 still gives PPU_Data breaks. Definitely not the problem.

Quote
You should read more about how bytes and bits work.
I did do a little research on bits/bytes, but didn't catch much of it due to lack of time. What you've said helps a lot though. Now I've got a much better idea of where to start researching, and where to go from there.

Now that's I've got a breakpoint with the address set to 2001-2001, with write and CPU memory selected, the game freezes.
Sometimes clicking 'run' will make at least change where it breaks and the A value (I assume it also makes the game run, but stops again before it's noticeable). Then it invariably gets caught on A=88.
This particular 88 and it's line are identical to that of the non-green ROM.
The values that happen before it aren't between #40-#7F or #C0-#FF.
Specifically they are 00, 1e, 18, and 88.
So I went back to the conditions that were discussed a while ago. I found that any inclusion of 'W' in a condition makes it invalid. When using the variant with A's it never breaks. When I initially tried the conditions I had the same results, but figured I'd just go without them.
However, when I have the A variant of the condition the game doesn't freeze.

I'd try to be more thorough before posting this, but I'm rather short on time again. Sorry if that's a problem.
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 09, 2020, 01:11:10 am
"W" being invalid means you are using older emulator version. Since debugger shows "PPU_DATA" words, I presume it's 2.2.3 from official site. Download (https://ci.appveyor.com/project/zeromus/fceux/build/artifacts) the latest build instead.

I'd like to see a video of exactly what you are doing (preferably with voice comments). And also screenshots of normal game and green game.
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 09, 2020, 08:38:22 am
#88 is not within the problematic values range (#40-#7F or #C0-#FF). That's not where the problem is. Set the breakpoint, pause the emulator, reset the game, and unpause the emulator.
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 09, 2020, 06:48:29 pm
I've updated the emulator, and the condition works now. This also solved the breakpoint getting PPU_Data results. However, besides that things remain unchanged. With the condition the breakpoint never breaks, and not having the condition still gets it stuck on the same values every time, not going anywhere after A becomes 88.
I tested this on the original ROM and it also has this problem.

Here's the video:
https://drive.google.com/file/d/1RtAmtLxQMKjYUbUpF4q3tMKLMviLlW65/view?usp=sharing
I couldn't get any sort of voiceover or subtitles, and the video quality was as high as the software would allow.
So I guess I'll just explain the video here:
I first open up my hacked ROM (which is actually a hack of a hack, the 25th anniversary hack), and demonstrate how it gets stuck every time (as specified above and in my previous comment). A few of the lines selected by the breakpoints are different from the original ROM (25th anniversary), but none are within the range of the problematic values.
Then I bring up the 25th anniversary edition, and show how it does the same thing.
Then I show how, as far as I can tell, nothing happens with the condition set (running about to different parts of the game for a while still did nothing).
One of the main things I was doing with the ROM was restoring the original graphics, palettes, and aesthetics to make it more faithful to the original, as well as various optimizations that the original hack didn't cover. That's why they look so different.
I then pull up the completely unmodified Earthbound Zero ROM for a better comparison of the colors.

I hope this helps
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 09, 2020, 07:02:16 pm
I'm testing here and I can't use "W". And I don't see it documented in fceux's help page. Is the page outdated? I'm using fceux from january 2019.
edit: while testing with january 2020 fceux "W" worked. But it still says 2.2.3. That's very confusing. Any reason they chose to do this? Just make it 2.2.4...
Anyway, I tested it in my ghostbusters hack and the condition worked where I expected it to. I'm too curious now, just host the patch so I can check it myself.
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 09, 2020, 07:50:42 pm
Here's the link:
https://drive.google.com/file/d/1Hnui9vuA5Hdb1th_xCXPDz9gDa8lQ8nh/view?usp=sharing
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 09, 2020, 08:21:39 pm
I'm sorry, but I applied the 25th anniversary edition patch to the earthbound proto ROM, then I applied your patch to that ROM. The game is not tinted green. Did you try the ROM on another emulator? I mean, can it be an emulator palette thing?

(https://i.imgur.com/BTSxr6A.png)
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 09, 2020, 10:29:26 pm
I included 25th anniversary with the patch. I probably should have said that.
My patch should look almost identical to the regular mother ROM, whereas your screenshot looked largely the same as 25th anniversary.

I did test it on another emulator  (nestopia) shortly after discovering the problem. It was still green.

So try patching the unmodified ROM with only my patch. Again, it should look mostly the same as the unmodified ROM, albeit greenish.
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 09, 2020, 11:40:22 pm
@Mr. Saturn. I've applied your patch to Earthbound (U) ROM. Palettes are the same for me.

(https://i.imgur.com/Xl7V4bT.png)

Your patch that you've uploaded probably doesn't contain necessary changes. I've watched your video and saw that green problem you were talking about.

(https://i.imgur.com/akitxU0.jpg)

So I've tried to reproduce it myself. I checked palette values. By manually changing in Hex Editor -> View -> PPU Memory $3F01, $3F05, $3F09 and $3F0B for the grass from #$3A to #$3B, and also $3F0B for the trees from #$1A to #$1B, I got the same result.

(https://i.imgur.com/TqHeiry.png)

And in case you are interested, this is how it would look like if the problem was with $2001.

(https://i.imgur.com/QeTafZi.png)



@nesrocks. This version from the link is a current build, it's not a release version, that's why it's not on the official site and not 2.2.4 either.

I don't know exactly when they added this new condition. It's not listed in fceux.chm, but it does in online help (http://www.fceux.com/web/help/fceux.html?Debugger.html).
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 10, 2020, 12:44:20 am
I just tested myself and had the same results. I applied the patch to an unmodified ROM, and there was no green tint. I tried making a patch again, and it yielded the same results.
The only explanation I can think of is that something about the thing I messed up didn't transfer through Lunar IPS.
Quote
So I've tried to reproduce it myself. I checked palette values. By manually changing in Hex Editor -> View -> PPU Memory $3F01, $3F05, $3F09 and $3F0B for the grass from #$3A to #$3B, and also $3F0B for the trees from #$1A to #$1B, I got the same result.
The tint in your image is slightly different. Mine's more of a yellowish green, and it applies to all sprites.
Though I guess the issue is pretty much resolved, if you make a patch out of your green ROM, and apply it to an unmodified ROM, is it still green?
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 10, 2020, 12:48:21 am
Changing palette manually in ppu memory does't save anything in the file, so there is no point to even try to make a patch. If that what you've meant.
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 10, 2020, 06:56:00 am
I believe that if you apply the same patch twice it doesn't do anything, so it didn't hurt that I first applied the 25th anniversary patch before yours.
Yeah, maybe you changed something in RAM or PPU memory and somehow it stuck as a cheat for that specific ROM file. Rename the ROM and open it again on fceux to see.

Cyneprepou4uk: that's the online one that I looked at. I guess it's not very good at explaining what W or R do. They should include an example and a better description, I guess.
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 10, 2020, 07:41:28 am
I don't know, looks fine to me. At least there was more than enough information for my taste in order for me to pick my interest and go test it by myself and be very pleased that such feature exist.

Does this explanation looks better? (from google translate, that's why # and $ are messed up)

(https://i.imgur.com/hqmgd1M.png)

Today I happened to search through for a very speciefic build version at github, and on my way I've encountered this build version (https://github.com/TASVideos/fceux/commit/6e5cfae6f70719db64a1f2577e4d0abc2383dc77), which says that these conditions were added 24 august 2016 (1 month after 2.2.3 release).

Which makes this sounds very strange.
Quote
I'm using fceux from january 2019.

I'm guessing you are looking at data in your folder, not in help -> about.
Title: Re: entire rom palette tinted green
Post by: nesrocks on January 10, 2020, 10:31:38 am
If I add W==#0 as a condition it says invalid condition. Yeah, I looked in the "about" menu option.
I guess I didn't understand that W or R would mean what they do. It was too unclear for me to take the time to test it because I couldn't even know what advantages it would provide.
Yes, that description is a lot better!
And I'm using fceux that I compiled myself from the source because I've made a few changes to the debugger's UI. Maybe that date reflects build date?
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 10, 2020, 10:36:46 am
Yes, that must be it. I've just read your topic on nesdev like 10 minutes ago. Ain't I the lucky one
Title: Re: entire rom palette tinted green
Post by: Mr. Saturn on January 10, 2020, 06:18:53 pm
Yeah, maybe you changed something in RAM or PPU memory and somehow it stuck as a cheat for that specific ROM file. Rename the ROM and open it again on fceux to see.
Yep. I tried it and you're right. I was confused about why it was still green with Nestopia. So I messed around with it, and found that any ROM on Nestopia was tinted green (even on a clean copy of Nestopia). So it's good that we've got that figured out.
I believe that if you apply the same patch twice it doesn't do anything, so it didn't hurt that I first applied the 25th anniversary patch before yours.
Actually, I just tried it myself, and it messed up a lot of the graphics, and used 25th anniversary's palettes, like in your screenshot. Like I said before, my patch should look pretty much the same as the unmodified ROM.

Overall, I guess this is pretty much all resolved. Thanks for your help and patience.

January 10, 2020, 06:21:02 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Also, I just noticed that in FCEUX, there was a file called Mother (modified).pal. I deleted it, and the game was no longer green.
Title: Re: entire rom palette tinted green
Post by: Cyneprepou4uk on January 10, 2020, 11:30:42 pm
Never would have guessed about .pal file.

Nestopia palette is different from fceux by default. You can insert FCEUX.pal in video options in nestopia.