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

Author Topic: Super Mario All-Stars FastROM Issue *SOLVED*  (Read 3248 times)

justin3009

  • Hero Member
  • *****
  • Posts: 1658
  • Welp
    • View Profile
Super Mario All-Stars FastROM Issue *SOLVED*
« on: October 29, 2016, 07:45:29 pm »
I'm having an absolute bastard of a time trying to figure this issue out.

So the basic sum up of the project I've done before and now was that I modified Super Mario All-Stars to load SMB2 right away.  All data that I could find relating to the other games in All-Stars has been completely removed pretty much leaving the entirety of the ROM to be for SMB2 only.  After that, I altered how the PC graphics are done so they are specifically their own thing now with Sprite Assembly, Animation Data and graphic pointers and such.  This worked just fine before in bSNES and SNES9X.  ZSNES, ignoring that mainly just fails on start-up after the coin logo but that's not important.

I've converted the ROM to FastROM to allow more sprites on screen without as much lag, thankfully, that works flawlessly in SNES9X and it really shows how much it's improved this way.  The problem comes now with more accurate emulators like BSNES.  I've also made sure 420D is set to 01 so that's not a problem either.

Everything loads up just fine in-game when you start up, select your character and the map loads.  The first frame of the only character I have in thus far, Peach, loads up flawlessly and just fine.  The moment when it has to change frames, however, the entire game bugs the hell out and essentially crashes.

I've searched my code forwards and backwards and I cannot find ANY reason on why this would happen.  Everything loads just fine, everything stores just fine from what I see.  It just.. breaks and seemingly only breaks when the sprite is NOT her single Idle Frame sprite.  I can change that value to anything and it'll just instantly break.

I am absolutely baffled as all the pointers are correct, all banks are correct, all information from what I can tell is correct.  Tracing in BSNES doesn't even help at all either as it leads to the same conclusion so I'm just confused as hell.
« Last Edit: October 29, 2016, 08:21:26 pm by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

SunGodPortal

  • Hero Member
  • *****
  • Posts: 2928
  • 2 + 2 = 5
    • View Profile
Re: Super Mario All-Stars FastROM Issue
« Reply #1 on: October 29, 2016, 07:56:51 pm »
Could it be the result of some sort of copy protection? Like, at a certain point it runs a check and if it finds something else it is programmed to just crash. Just a thought...
Cigarettes, ice-cream, figurines of the Virgin Mary...

justin3009

  • Hero Member
  • *****
  • Posts: 1658
  • Welp
    • View Profile
Re: Super Mario All-Stars FastROM Issue
« Reply #2 on: October 29, 2016, 07:58:55 pm »
No, because before I altered the game to FastROM the entirety of the routine worked just fine in BSNES.  Only when I converted everything to FastROM is when it decides to freak out upon sprite frame changing.  If I remove the entire PC sprite code, everything works just fine.  It's something with that routine that's causing it yet tracing it does absolutely nothing to help out which is what's throwing me off.

Edit: If I stop the sprite frames from changing.. it works just fine.  I don't understand what's going on.

Edit 2: Oh!  I see the problem.. sorta!  For some reason in BSNES it's actually storing the pointer to the sprite incorrectly as the sprite transitions.. not sure why this is.  Yet in SNES9X it's just fine.  I think I know where it's occurring but it doesn't make any sense on why it'd be happening.

7E:02ED is the 3-byte pointer to the current sprite and 7E:02F0 is how much data to send to VRAM.  For some reason when it transitions in BSNES, it shoves all that data BACKWARDS by a byte which is what's causing the graphics corruption!

Edit 3: Here's the culprit!  Could I get a bit of help figuring out why this is happening?

BSNES Code
Code: [Select]
94e5bf lda $0163     [910163] A:fa00 X:0003 Y:0000 S:01f5 D:0000 DB:91 Nvmxdizc V: 20 H: 674 F:38
94e5c2 and #$00ff             A:0001 X:0003 Y:0000 S:01f5 D:0000 DB:91 nvmxdizc V: 20 H: 708 F:38
94e5c5 sta $4202     [914202] A:0001 X:0003 Y:0000 S:01f5 D:0000 DB:91 nvmxdizc V: 20 H: 726 F:38
94e5c8 lda #$0004             A:0001 X:0003 Y:0000 S:01f5 D:0000 DB:91 nvmxdizc V: 20 H: 756 F:38
94e5cb sta $4203     [914203] A:0004 X:0003 Y:0000 S:01f5 D:0000 DB:91 nvmxdizc V: 20 H: 774 F:38
94e5ce lda #$0700             A:0004 X:0003 Y:0000 S:01f5 D:0000 DB:91 nvmxdizc V: 20 H: 804 F:38
94e5d1 tcd                    A:0700 X:0003 Y:0000 S:01f5 D:0000 DB:91 nvmxdizc V: 20 H: 822 F:38
94e5d2 nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 834 F:38
94e5d3 nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 846 F:38
94e5d4 nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 858 F:38
94e5d5 nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 870 F:38
94e5d6 nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 882 F:38
94e5d7 nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 894 F:38
94e5d8 nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 906 F:38
94e5d9 nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 918 F:38
94e5da nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 930 F:38
94e5db nop                    A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 942 F:38
94e5dc lda $4216     [914216] A:0700 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdizc V: 20 H: 954 F:38
94e5df clc                    A:0000 X:0003 Y:0000 S:01f5 D:0700 DB:91 nvmxdiZc V: 20 H: 984 F:38

SNES9X Code
Code: [Select]
$94/E5BF AD 63 01    LDA $0163  [$91:0163]   A:FA00 X:0003 Y:0000 P:eNvmxdizc
$94/E5C2 29 FF 00    AND #$00FF              A:0001 X:0003 Y:0000 P:envmxdizc
$94/E5C5 8D 02 42    STA $4202  [$91:4202]   A:0001 X:0003 Y:0000 P:envmxdizc
$94/E5C8 A9 04 00    LDA #$0004              A:0001 X:0003 Y:0000 P:envmxdizc
$94/E5CB 8D 03 42    STA $4203  [$91:4203]   A:0004 X:0003 Y:0000 P:envmxdizc
$94/E5CE A9 00 07    LDA #$0700              A:0004 X:0003 Y:0000 P:envmxdizc
$94/E5D1 5B          TCD                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5D2 EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5D3 EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5D4 EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5D5 EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5D6 EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5D7 EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5D8 EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5D9 EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5DA EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5DB EA          NOP                     A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5DC AD 16 42    LDA $4216  [$91:4216]   A:0700 X:0003 Y:0000 P:envmxdizc
$94/E5DF 18          CLC                     A:0004 X:0003 Y:0000 P:envmxdizc

Edit 4: Think I fixed it now.  It's because it was using two bytes instead of one.  Set everything during that so it reads one byte and it's fixed! I always seem to be able to fix things RIGHT after I post them, weirdly.  Thank goodness this is out of the way though!
« Last Edit: October 29, 2016, 08:21:52 pm by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

STARWIN

  • Sr. Member
  • ****
  • Posts: 454
    • View Profile
Re: Super Mario All-Stars FastROM Issue *SOLVED*
« Reply #3 on: October 29, 2016, 08:52:11 pm »
Is this exactly the same issue as here: http://www.romhacking.net/forum/index.php/topic,18590.msg311917.html#msg311917 ?

If so, it is possible that this isn't that uncommon.. which would probably mean that a bunch of older hacks here are likely to have a variant of this bug.

justin3009

  • Hero Member
  • *****
  • Posts: 1658
  • Welp
    • View Profile
Re: Super Mario All-Stars FastROM Issue *SOLVED*
« Reply #4 on: October 29, 2016, 08:55:13 pm »
Yep, that's the exact same issue I was having and pretty much did exactly that to fix it.  Glad to see it's not exactly 'uncommon' per se, though, this is probably very important to know for others who fall into this same issue.
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

DougRPG

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Re: Super Mario All-Stars FastROM Issue *SOLVED*
« Reply #5 on: October 31, 2016, 07:00:25 am »
So the problem is that you cannot write in 16bits mode to $4203?

Doing that you are overwriting the Dma bank in $4204?
But this works on Snes9x?

STARWIN

  • Sr. Member
  • ****
  • Posts: 454
    • View Profile
Re: Super Mario All-Stars FastROM Issue *SOLVED*
« Reply #6 on: October 31, 2016, 11:24:40 am »
I'm neither a good snes coder nor a hardware tester, so feel free to test yourself if you really want to know, but given that..

I would imagine the issue is writing to 4202 in 16-bit mode because (I imagine) that covers both 4202 and 4203 and hence initiates a multiplication between the 8-bit parts of the 16-bit value written.

Google says 4204 is related to division and not dma (and a write there will do nothing).

Snes9x and some versions of bsnes (not the old ones I believe) give different results, yes.
« Last Edit: October 31, 2016, 11:31:21 am by STARWIN »

DougRPG

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Re: Super Mario All-Stars FastROM Issue *SOLVED*
« Reply #7 on: October 31, 2016, 02:46:18 pm »
Ah, yeah, Dma is in $43xx, not $42xx.
Sorry...

Revenant

  • Full Member
  • ***
  • Posts: 205
    • View Profile
Re: Super Mario All-Stars FastROM Issue *SOLVED*
« Reply #8 on: October 31, 2016, 08:43:19 pm »
Like STARWIN said, with 16-bit writes you're touching $4203 twice which causes a second bogus multiplication.

But if you're multiplying by a constant value of 4, why not just ASL twice and avoid the slow multiplication registers entirely?

justin3009

  • Hero Member
  • *****
  • Posts: 1658
  • Welp
    • View Profile
Re: Super Mario All-Stars FastROM Issue *SOLVED*
« Reply #9 on: November 01, 2016, 06:55:08 am »
I think this was my first use of the multiplication bit so I wanted to try it.  I'll be changing that!

Edit: Changed.  Much better now.
« Last Edit: November 01, 2016, 04:08:38 pm by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'