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

Author Topic: Super Pitfall NES (improvements)  (Read 97374 times)

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Super Pitfall NES (improvements)
« Reply #240 on: August 10, 2016, 11:11:01 am »
Wow... So I have listed every sound and music channel in the game and their rom offsets. Here it is:

ID (hex)         
00   19926-1992A         mute sound
01   1992F-19933         mute sound
02   19938-1993C         mute sound
03   19941-19955   sfx      pause
04   1995A-199D6   music   baloon theme square
05   199D7-10A0D   music   main theme square
06    19A0E-19A2B   music   cutscene theme square
07   19A2D-19A79   music   darkworld theme square
08   19A7A-19A92   music   invincibilty square
09   19A93-19ABF   music   game over theme square
0A   19AC0-19AEA   music   game over theme square 2
0B   19AEB-19B15   music   game over theme triangle
0C   19B1C-19B26   sfx      extra life
0D   19B27-19B31   sfx      death
0E   19B32-19B42   sfx      kill an enemy
0F   19B43-19B4F   sfx      take a warp
10   19B50-19B5A   sfx      get an item
11   19B50-19B5A   sfx      get an item
12   19B5B-19B61   sfx      get an item higher pitch (gold I think)
13   19B62-19B6A   sfx      enemy shoots
14   19B6B-19B73   sfx      damage an enemy (without killing it)
15   19B74-19B7E   sfx      firing a bullet
16   19B7F-19B87   sfx      object hitting the ground
17   19B88-19B92   sfx      falling ceiling
18   19B93-19B9B   sfx      jump low pitch (it is used, I don't know what for)
19   19B9C-19BA6   sfx      jump
1A   19BA7-19BB5   sfx      imp / big cavemen shooting
1B   19BB6-19BC0   sfx      elevator and spikes
1C   19BC1-19BCD   sfx      lava ball launched (music totally overshadows this very bad sound effect)
1D   19BCE-19BD8   sfx      waterfall
1E   19BD9-19BDF   sfx      harry landing on the ground
1F   19BE0-19BEC   sfx      unused sound
20   19BE0-19BEC   sfx      it may be related to the falling ceiling
21   19BED-19BF3   sfx      I think it's when the balloon pops
22   19BF4-19C98   music   ballon theme triangle
23   19CA4-19CBC   music   ballon theme noise
24   19CBD-19D3B   music   main theme triangle
25   19D3C-19D8A   music   main theme noise
26   19D8B-19DA8   music   cutscene theme triangle
27   19DAA-19DB0   music   cutscene theme noise
28   19DB1-19DC3   music   darkworld theme triangle
29   19DC4-19DE8   music   darkworld theme noise
2A   19DE9-19E7D   music   invincibilty theme square 2
2B   19E7E-19EB8   music   invincibility theme noise
2C   19EB9-19F1D   music   ending theme square
2D   19F1E-19F7C   music   ending theme square 2
2E   19F7D-19FCF   music   ending theme triangle

These sound IDs simply indicate the offset on the list of pointers to the actual sounds. Each pointer is 2 bytes long, so this list of pointers is $2E times 2 bytes long. Okay.

So, why on earth would that value at 0x1FB17 (originally set to $2F) that completely kills the game's performance be directly related to which sounds can be played? If I set it to $1C then every sound with ID bigger than $1C will get muted. If I set it to $01 the game gets muted (but runs incredibly smooth). This limitation should be removed and the game should run with 0x1FB17 as $01. Not sure if it's an easy fix (it will be if this is just a bug, not a core feature of the sound engine).

jonk

  • Sr. Member
  • ****
  • Posts: 273
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #241 on: August 10, 2016, 01:02:10 pm »
I don't recall a separate conversation about address 0x1FB17. But I gather that this is a byte value that sets a limit that is somehow elsewhere applied when indexing into the sounds you listed out -- if there are N sounds/themes, then the value is set to N+1?

Then you say that setting it to limit pretty much all the sounds leads to an incredibly smooth operation and that setting it to allow all the sounds leads to almost killing the performance. I think I also read you saying that the original ROM doesn't have this problem, but that a patched ROM does. (If so, have you tested the original ROM by varying this particular value between $01 and $2F to make sure that its performance remains _good_ regardless?)

If the original ROM works good regardless of this setting and the patched ROM you are working with has the behavior you are describing, then it is likely that there is a significant assembly source code difference that was applied to some interrupt events and that is sucking away valuable processor time without any good purpose. It's not uncommon that people add code to interrupt events and attempt to perform work there that they REALLY SHOULD NOT HAVE DONE. If they aren't careful, all they wind up doing is sucking away time on every interrupt reducing the available processor time for other tasks. This sounds a LOT like that to me.

The weird thing to explain, perhaps, is why a simple difference in the allowed range might take away time that it didn't take away before in the earlier ROM. What could they have possibly done in the patch that would suck away processor time regarding this value that was done _better_ in the earlier ROM and done lots more stupidly in the patch? Honestly, I've no clue because I don't know what all they took on to change in the patch from which you are working. But if perhaps the old ROM code didn't use a mapper capability that the new, patched ROM now requires? Then perhaps they felt they had to add code into some interrupt in order to make sure certain things were "mapped" in when other code expected it. Or it could be something totally different.

Regardless, this sounds an awful lot as though an interrupt event that used to take a fixed amount of X time each interval is now taking Y(v) time, where Y(v) is variable and depends in some obscure way on that limit value. So I'd be looking at interrupt code differences between the two: the original ROM and the patched ROM (before your own changes are applied to it.)
An equal right to an opinion isn't a right to an equal opinion. -- 1995, me
Saying religion is the source of morality is like saying a squirrel is the source of acorns.  -- 2002, me

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Super Pitfall NES (improvements)
« Reply #242 on: August 10, 2016, 01:14:51 pm »
Thanks for the insights, I'm looking further into the issue. That value is read from a compare routine. When I delete that compare line the game gets perfectly muted and perfectly smooth. That means It doesn't enter that loop $2F times, only once and proceeds.

 06:964B:60        RTS -----------------------------------------
 06:964C:A9 00     LDA #$00
 06:964E:85 F8     STA $00F8 = #$00
 06:9650:85 F9     STA $00F9 = #$00
 06:9652:85 FA     STA $00FA = #$00
 06:9654:85 FB     STA $00FB = #$00
 06:9656:85 FD     STA $00FD = #$30
 06:9658:85 FF     STA $00FF = #$00
 06:965A:A9 F8     LDA #$F8
 06:965C:85 FE     STA $00FE = #$F8
 06:965E:A9 00     LDA #$00
 06:9660:85 33     STA $0033 = #$00
 06:9662:85 32     STA $0032 = #$00

 06:9664:A5 33     LDA $0033 = #$00
 06:9666:CD 07 FB  CMP $FB07 = #$2F     // delete this line and...
 06:9669:F0 71     BEQ $96DC                    // it will always break to 96DC, otherwise it continues until $33 is equal to FB07
 06:966B:A5 32     LDA $0032 = #$00     
 06:966D:C9 06     CMP #$06
 06:966F:F0 12     BEQ $9683
 06:9671:A4 32     LDY $0032 = #$00
 06:9673:B9 CB 06  LDA $06CB,Y @ $06CB = #$01
 06:9676:C9 FF     CMP #$FF
 06:9678:F0 04     BEQ $967E
 06:967A:C5 33     CMP $0033 = #$00
 06:967C:F0 0E     BEQ $968C
 06:967E:E6 32     INC $0032 = #$00
 06:9680:4C 64 96  JMP $9664
 06:9683:A9 00     LDA #$00
 06:9685:85 32     STA $0032 = #$00
 06:9687:E6 33     INC $0033 = #$00
 06:9689:4C 64 96  JMP $9664

You are mistaken about the bug not being present on the original game though. It is. The bug that was added from the mmc3 patch is related to the pause button (I have fixed that one now by removing the patch, so my hack is the same mapper as the original game).
« Last Edit: August 10, 2016, 01:23:12 pm by nesrocks »

dACE

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #243 on: August 10, 2016, 01:59:40 pm »
What happens if you load 2F into a - instead of 33?
Is the game still muted? Did it crash?

/dACE

jonk

  • Sr. Member
  • ****
  • Posts: 273
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #244 on: August 10, 2016, 02:02:53 pm »
Thanks for the insights, I'm looking further into the issue. That value is read from a compare routine. When I delete that compare line the game gets perfectly muted and perfectly smooth. That means It doesn't enter that loop $2F times, only once and proceeds.
The problem really does sound [sorry about the pun] to me like an interrupt handler issue where the code spends too much time in the interrupt. I'm gathering now that you are also saying this problem exists in the original ROM (my mistake.) So that just means bad coding, in all likelihood. I rather doubt that the hardware itself is so fatally flawed that it makes smooth operation nearly impossible. So it's almost certainly bad choices made in the design and coding. The way to fix that is to do some re-design and re-coding.

You are mistaken about the bug not being present on the original game though. It is. The bug that was added from the mmc3 patch is related to the pause button (I have fixed that one now by removing the patch, so my hack is the same mapper as the original game).

Yeah. It's probably me misreading your writing. I got confused by the following thing you wrote a ways back:

edit: I have detected a problem with the pause function in the game. It was too sensitive, like, you had to press start really quickly or else it would pause and unpause with a single press. I checked the clean ROM and it didn't have this problem. So I investigated and identified that it is a problem with the MMC3 patch. I have reconverted my hack back to unrom and fixed the programming of the hud that was mapper patch dependant.

So it's just me.

EDIT: That means there probably is a design issue to resolve. And my first place to go would be to the interrupt routine that gets called the most often. I don't know if the horizontal retrace is supported -- that would be pretty fast if it is present. But I'm pretty sure the vertical retrace interrupt is supported -- though that is almost so slow I don't know why that would be a problem. There are timers too, I suppose? Do you know all of the interrupting events and their frequencies? I'd go first to the fastest ones and see what exactly they are doing there. But of course there's no point if the routines don't access that value in some way. So I may be completely off the beam here. It's just that the resulting behavior seems like value-dependent, wasted time in an interrupt. (For example, suppose the interrupt _examines_ a different table you are NOT looking at right now that has the same number of entries so as to hold the "next" byte of music to play.... and that the code has to examine ALL of these locations to figure out how to "mix" the music together if more than one is playing or else has to at least "look" at all of them, even if it doesn't mix them.) It just feels like that, to me.
« Last Edit: August 10, 2016, 02:11:38 pm by jonk »
An equal right to an opinion isn't a right to an equal opinion. -- 1995, me
Saying religion is the source of morality is like saying a squirrel is the source of acorns.  -- 2002, me

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Super Pitfall NES (improvements)
« Reply #245 on: August 10, 2016, 02:11:12 pm »
What happens if you load 2F into a - instead of 33?
Is the game still muted? Did it crash?
Humm... #2F is never loaded into $33. It is a fixed value (stored on $FB07) that is read once during the loop to see if $33 has reached that value (when it has, it breaks from the loop). Notice how at the end of the loop it increases $33 by one and returns to the start.

That means there probably is a design issue to resolve. And my first place to go would be to the interrupt routine that gets called the most often. I don't know if the horizontal retrace is supported -- that would be pretty fast if it is present. But I'm pretty sure the vertical retrace interrupt is supported -- though that is almost so slow I don't know why that would be a problem. There are timers too, I suppose? Do you know all of the interrupting events and their frequencies?
I know absolutely nothing about interrupts.  :-\  Let alone this game's interrupts. I will try to edit that section of code and see what it does and then move on.

edit: I have read your edit, and yes, that may be the case. I will see what the $32 does for example.
edit2: that is the only place that reads for $FB07
« Last Edit: August 10, 2016, 02:37:55 pm by nesrocks »

jonk

  • Sr. Member
  • ****
  • Posts: 273
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #246 on: August 10, 2016, 02:12:51 pm »
I know absolutely nothing about interrupts.  :-\  Let alone this game's interrupts. I will try to edit that section of code and see what it does and then move on.
Okay. So that's it, then.
An equal right to an opinion isn't a right to an equal opinion. -- 1995, me
Saying religion is the source of morality is like saying a squirrel is the source of acorns.  -- 2002, me

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Super Pitfall NES (improvements)
« Reply #247 on: August 10, 2016, 02:43:21 pm »
okay, I can change

 06:9666:CD 07 FB  CMP $FB07 = #$2F

to

 06:9666:C9 2F     CMP #$2F     

And the game works just the same. The value on 0x1FB17 is never read again (as confirmed by fceux's debugging tools). So the problem lies here. ($33 is never read outside of this loop either)

dACE

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #248 on: August 10, 2016, 02:46:32 pm »
I changed it to read from FB06 - but I didn't notice any difference..

/dACE

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Super Pitfall NES (improvements)
« Reply #249 on: August 10, 2016, 02:52:58 pm »
I changed it to read from FB06 - but I didn't notice any difference..

/dACE
That's because $FB06 stores a #2E. Try FB05 and you will see the game plays in slow mo because $FB05 stores an #82. Try FB1D and the performance will be boosted at the expense of sounds because that one stores a #03.

dACE

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #250 on: August 10, 2016, 03:13:56 pm »
Try FB36 - that address contains 26, which still plays all channels (I think).
The address FB73 - that contains 24, made it loose one channel.

/dACE

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Super Pitfall NES (improvements)
« Reply #251 on: August 10, 2016, 03:15:44 pm »
Take a look at the list of sounds and look at the leftmost number. Sounds with a higher number than the one at FB07 will not play. So, when you set it to 26 these stopped working:
27   19DAA-19DB0   music   cutscene theme noise
28   19DB1-19DC3   music   darkworld theme triangle
29   19DC4-19DE8   music   darkworld theme noise
2A   19DE9-19E7D   music   invincibilty theme square 2
2B   19E7E-19EB8   music   invincibility theme noise
2C   19EB9-19F1D   music   ending theme square
2D   19F1E-19F7C   music   ending theme square 2
2E   19F7D-19FCF   music   ending theme triangle

Also, you don't need to compare to other addresses, you can change the value at FB07 to anything you like. Better yet, compare to a value directly instead of a value stored somewhere else (same effects, but cleaner code).

For example:
replace CD 07 FB on 0x19676 (06:9666:CD 07 FB  CMP $FB07 = #$2F)
with
EA (no operation) C9 2F
You need the EA to fill in because it has to be 3 bytes long. So now you can change 2F there without scrolling to other sections of code.
« Last Edit: August 10, 2016, 03:27:21 pm by nesrocks »

dACE

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #252 on: August 10, 2016, 08:18:53 pm »
Yeah - I should have read your posts more carefully, sorry for that.

I didn't know the NOP instruction for NES (in ASM for GB it's 00) so at least I learned something.

/dACE

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Super Pitfall NES (improvements)
« Reply #253 on: August 11, 2016, 12:14:26 am »
No problem, dACE!

So, after some thinking and a lot of testing (or vice-versa?) I have discovered that sounds/music with lower ID have priority to play. So the order they are listed in is not by chance. The programmer chose the main themes' (main theme, underworld theme and invincibility theme) square channels to have priority over everything else, but the rest of the songs (triangle and noise) are on the bottom of the list so sfx can play muting those music channels temporarily.

Which got me thinking (unrelated, but it just popped). The whole problem is that the game performs slowly because of the amount of sounds. So, instead of having a big list of sounds couldn't I divide them by groups? So I can have smaller lists and use a smaller compare value from 0x1FB17, effectively increasing the game's performance despite the sound engine's bad programming. Nice! But how?

Here's maybe how: I could make a sound manager to retrieve the correct sound list based on some condition, which is how the sounds would be grouped together. Such conditions could be "sounds that play during the overworld 1", or "sounds that play on cutscene, game over, ending and title screen". So I'd just need to have a ram address keeping track of which sound list is to be used and make sure it's updated on scene transitions, and I'm good to go.

So this may be a good course of action:
- make the lists on a txt to get a practical preview of how fast the game will run afterwards (it's easy to test the performance knowing the bigger list's length)
- find an unused RAM address and use it to make the condition. Test the condition by playing the game and observing the value
- program the manager that redirects the list

Why am I going through all this trouble? Well, it's because just two days ago I have managed to insert FCandChill's song into the game :D I was keeping it a secret. He sent me a few more notes (huge help, thanks dude!) and his song in famitracker and I bashed my head on the keyboard real hard and it worked (just kidding, it was actually magic). I even got it to play on the title screen. Yes, I can choose any song to play anywhere now. I have that power.

So... Spoiler again, I have decided to do this:
- play the original main theme on the title screen.
- play FCandChill's song on all three of the overworld 2 areas (those areas that you play on when you warp, except for the darkworld).
- and I'm going to arrange the atari 2600's pitfall II three songs into one to be played on the overworld 1 (yes, I believe there is still enough free space for even that on bank 7). I have found a thread over at the famitracker forums where user rockmanx2002 made a ftm of that game's ost already (it sounds awesome), so I can use that as a base to convert just as I did with FCandChill's song. Nice. I'll credit both him and FCandChill for their songs. So good.

The songs in Super Pitfall only have three channels, and I have already adapted FCandChill's song to use 3 channels instead of his original 4, but now I realize that it really can have all 4 channels. All is needed is the the sound list to be correctly arranged for priorities (and an extra instruction to load that extra channel). So, I plan to make both his song and the new main theme 4 channels.

Phew! I hope the new manager works. If it doesn't, we will still have the new songs, just with the same bad old performance. If I can get it to work though all that will be missing for me to be really happy is to fix the controls.

Da_GPer

  • Full Member
  • ***
  • Posts: 176
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #254 on: August 11, 2016, 05:16:55 am »
Yay! It be great to hear the main theme to Pitfall II in Super Pitfall. Its like the game is begging to play that song but since the graphics and bugs was killing it, it could only spit out the horrible mess that we all know so well. Now that you gave it better graphics and fixed those bugs, it will finally be able to play the theme song it should rightly play.

cospefogo

  • Full Member
  • ***
  • Posts: 173
  • "Take this silver dagger to save your neck."
    • View Profile
    • Fliperamas
Re: Super Pitfall NES (improvements)
« Reply #255 on: August 11, 2016, 07:33:55 am »
NesRocks!

You do deserve a monument of yourself on a public plaza. Awesome, man, you are turning one of my favorite games (back in its time) to a marvelous master piece!

OFF:
In the future, let's insert Ultima Exodus music INTO Ultima Quest of Avatar?
Do you think you can take a look into that?
=P

Regards,
Cospefogo.
"Replicants are like any other machine - they're either a benefit or a hazard.
If they're a benefit, it's not my problem."

protomank

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: Super Pitfall NES (improvements)
« Reply #256 on: August 11, 2016, 09:10:08 am »
As a fan of Pitfall II Lost Caverns, that would be amazing :D

FCandChill

  • Hero Member
  • *****
  • Posts: 553
    • View Profile
###
« Reply #257 on: August 11, 2016, 03:15:28 pm »
Comment removed because reasons...
« Last Edit: September 25, 2016, 09:05:16 pm by FCandChill »

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Super Pitfall NES (improvements)
« Reply #258 on: August 11, 2016, 09:56:11 pm »
@Nesrocks Sent you the file. Famitacker tip ... you can export songs as TXT files. You can use the "replace all" function in notepad to replace notes to their corresponding hex value!
Humm... Yeah, I had seen the txt export but I didn't think it'd be useful. I guess you're right, I'll try that later!

So, I have created smaller sound lists. Three of them. One for title screen+lives screen+game over screen+ending screen, one for overworld 1 and 2, and one for the darkworld. I have programmed the manager that redirects to these lists. I have replaced every single sound call in the game to the new sound IDs. And I have reduced the $2F compare to a $18 now.

After testing:
The good:
- The game is running a lot of smoother!
- Sounds are playing correctly.
- I have more flexibility to add sounds/music channels (pointers-wise. rom space is still to be considered).

The bad:
- The pause bug is back. Gotta tap the start button fast so it stays paused.
- If I tried to pause during invincibility the game would freeze. For now I've removed that item.
- I've tested, and this is directly related only to lowering the 0x1FB17 value (has no relation with my sound manager), but now there are a little bit more temporary graphical glitches when moving the screen vertically on the newly revealed metatiles.

These empty metatiles appear for 2 frames during fast vertical scrolling before they are replaced with the correct ones. This is the worst case of the problem I have spotted. This problem happened before too, but they never got that much inside the screen. Maybe there's a way to amp up the metatile refresh rate... What it is doing is that it displays the correct metatile but the attribute is not updated yet.

FCandChill

  • Hero Member
  • *****
  • Posts: 553
    • View Profile
###
« Reply #259 on: August 11, 2016, 11:04:47 pm »
Comment removed because reasons...
« Last Edit: September 25, 2016, 09:05:56 pm by FCandChill »