News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Infinite loop inside Megaman X2 Cx4 transformation routines? Bsnes plus  (Read 890 times)

PostMortem

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
OK maybe I'm delusional, but I'll describe what I've found so far. In a nutshell, the Megaman X2 wireframe loading -> transformation -> drawing algorithm seems to work like this:

1) Program counter at: 0780CD
2) First subroutine (jsr $8309) doesn't seem to be relevant.
3) Second subroutine (jsr $827D) is really important because it copies raw wireframe data from ROM to RAM as shown:


4) Third subroutine (jsr $823D) maybe it's important but it doesn't seem to have a direct effect on RAM data in this case.
5) Fourth routine ($732692) seems to be the actual Cx4 processing region. Now, I'm having trouble here because it seems to reach an infinite loop, maybe expecting a signal or something from the co-processor? This behavior doesn't allow me to scrutinize the whole section of code step by step:

6) After forcibly stepping out of the previous routine, the data has been successfully transformed and RAM is updated:

6) The last routines seem to be in charge of drawing everything (SEE UPDATE). There is a huge memory region starting at $7eb000 where bytes are being literally dumped and I assume it's likely to be a rough representation of the actual state or shape of the 3d model.
7) Loop again, goes back to 1)

I'm using bsnes plus. Is this infinite loop behavior at the fourth routine (where the <SNES.NMITIMEM> lives) when it comes to this chip an expected situation or should I just continue hitting step until something happens?  :-\

UPDATE:

After some checking I just found that there is yet another subroutine that seem to be important, I found this after comparing both MMX2 (left side) vs MMX3 (right side):




I've already talked about the first routine, which I think has to do with Cx4 setup and transformation logic because after the routine ends a lot of RAM data related to the wireframe 3d model is being updated. The second routine I just found out it is pretty different between both games, maybe this is where part of the magic actually happens?

The rest of the subroutines are pretty much the same in both games and I think nothing substantial happens in there other than some ROM reading and RAM / screen updating. This is the scheme I've come up so far:



I still can't go through the Cx4 routine step by step without falling into an infinite loop though.
« Last Edit: November 16, 2020, 04:24:04 pm by PostMortem »

slidelljohn

  • Sr. Member
  • ****
  • Posts: 331
    • View Profile
Re: Infinite loop inside Megaman X2 Cx4 transformation routines? Bsnes plus
« Reply #1 on: November 17, 2020, 12:20:37 am »
Could the infinite loop just be waiting for a interrupt?

I see what looks like infinite loops all of the time in snes code and they exit the loop when a interrupt occurs.

PostMortem

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: Infinite loop inside Megaman X2 Cx4 transformation routines? Bsnes plus
« Reply #2 on: November 18, 2020, 03:45:39 pm »
Could the infinite loop just be waiting for a interrupt?

I see what looks like infinite loops all of the time in snes code and they exit the loop when a interrupt occurs.

I found a way to go through the loop but I still cannot understand the way those memory values in the $6000 region are being updated. It is a complete black box for me because when it's completed the numbers are just somehow updated. The problem is that there is nothing inside the loop besides this:

Code: [Select]
PC
7e2721   lda $0075fe
7e2725   and #$40
7e2727   bne $2721
732729   rtl

When the loop ends the data points are magically updated.