Trying to understand the purpose of this operation:

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

Moderator: Moderators

Post Reply
Dugongue
Posts: 5
Joined: Wed Apr 18, 2018 4:53 pm

Trying to understand the purpose of this operation:

Post by Dugongue » Fri May 29, 2020 6:05 pm

So every once in a while I do a side-by-side comparison of the JP/US versions of games to work out what's changed between revisions. I was looking at the JP and US version of Blaster Master, specifically Page 6 which contains the AI code for objects in the side/tank view sections.
I'm not fully through the page but I've found at least 8 separate occurrences of the operation "LDY #$00" added in various spots. At first I thought this must have been a case where the original code falsely assumed that Y, or certain status flags, would always have a specific value at that point, and this was a fix for that. But that doesn't seem to be the case.

Attached is a specific example. The code itself has to do w/ the speed of Jason's swimming animation (faster if the D-Pad is pressed). I made a trace log for the original code + the same code with the operation skipped over. This operation doesn't seem to have any direct effect on the following code, since the next relevant values of Y/the status flags are set by other operations afterward.

It's probably not that important but the fact they would go out of their way to add something so specific multiple times makes me wonder what the purpose could possibly be. I was just wondering if it rang a bell for something someone has seen in another game.

Image

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

Re: Trying to understand the purpose of this operation:

Post by calima » Sat May 30, 2020 12:40 am

My guess: they changed their optimizer to fix a missing Y clear, like you assumed, just not for handmade asm. Then the fixed version could not determine it wasn't needed in some of those places.

If the addition looks automated, then the code may have been compiled from something else.

User avatar
Bregalad
Posts: 7892
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Trying to understand the purpose of this operation:

Post by Bregalad » Sat May 30, 2020 2:15 am

I can't answer the original question, but I can say I witnessed that the AI of enemies in Blaster Master is extremely glitched, so I wouldn't be suprised if it would have been coded very badly, and (insufficient) fixes would have been made between the JP and US versions of the game. Even the movement when using the vehicle is erratic and sometimes you can exit the vehicle, only to be stuck outside and never climb in it ever again. It's also possible at the gate between world 1 and world 2, on world 1 side, to be stuck below the game with the vehicle and be unable to leave with the vehicle, effectively making you stuck there.

Great music, OK levels but what a shame the game is so full of glitches !

User avatar
Controllerhead
Posts: 103
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Trying to understand the purpose of this operation:

Post by Controllerhead » Sat May 30, 2020 4:21 am

Sup dewey!

It's odd to see two NOP's replaced with a seemingly useless LDY immediate as TAY happens after the JMP. They are both 2 bytes, and the NOPs take 4 cycles instead of the LDY immediate's 2, but hmmm.... i guesssss it could be a precise timing thing? but that seems like a stretch. Very strange.

Are the other LDY #$00's also replacing NOP's? Also Check to see if the Y register is ever referenced after the other LDY #$00's before being altered identically, if it is, then you might be on to something. Maybe watch out for BEQ / BNE branches too, as LDY #$00 will set the Z flag if it is the latest thing altered.

Otherwise LDY #$00 will give the sliiightest speed advantage over two NOPs and maybe prevent a frame of lag here and there. Possibly. That may be of interest to you. Also could cause a movie desync in that same situation, if the NOP version gets a frame behind, or the LDY version gets a frame ahead, depending on which version it was recorded on; ....but i don't know about the rest of the code, so i can't say for sure.

Edit: He added the NOP's himself. D'oh! I am a NOP. Pardon me whilst i halt and catch fire.
Last edited by Controllerhead on Sat May 30, 2020 6:43 am, edited 5 times in total.
Image

User avatar
aa-dav
Posts: 92
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: Trying to understand the purpose of this operation:

Post by aa-dav » Sat May 30, 2020 5:13 am

I bet this is just some macro like "LDXY" which programmer thoughtlessly used.
Or scraps of removed code.

Dugongue
Posts: 5
Joined: Wed Apr 18, 2018 4:53 pm

Re: Trying to understand the purpose of this operation:

Post by Dugongue » Sat May 30, 2020 6:02 am

Controllerhead wrote:
Sat May 30, 2020 4:21 am
It's odd to see two NOP's replaced with a seemingly useless LDY immediate as TAY happens after the JMP.
Sorry I didn't explain that very well, the NOPs I manually added into the US ROM to see if it resulted in any difference in the trace. The JP rom has no operation there at all.
calima wrote:
Sat May 30, 2020 12:40 am
My guess: they changed their optimizer to fix a missing Y clear, like you assumed, just not for handmade asm. Then the fixed version could not determine it wasn't needed in some of those places.
If the addition looks automated, then the code may have been compiled from something else.
aa-dav wrote:
Sat May 30, 2020 5:13 am
I bet this is just some macro like "LDXY" which programmer thoughtlessly used.
These were my thoughts as well. The way the branching is structured looks a lot to me like other examples I've seen of C-like control structures compiled to 6502.
The only other difference I've seen so far is a change to a branch that removed a redunant RTS, which also seems like the result of an updated optimizer.
So presumably if I keep looking through the code for all new instances of LDY #$00 I should find one where it actually does something.

User avatar
aa-dav
Posts: 92
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: Trying to understand the purpose of this operation:

Post by aa-dav » Sat May 30, 2020 7:05 am

Does it look real what someone in 1988 had compiler for NES with optimizations and so on?
It looks unreal for me.
I think "automated" here is just "macros".

Post Reply