Need guidance with nes to snes.

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
infidelity
Posts: 462
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity » Sat Apr 10, 2021 2:28 am

93143 wrote:
Fri Apr 09, 2021 7:47 pm
That's correct. The inventor wanted it to have multichannel capability, but found that it would be too complicated. The audio module in the SNES can produce sound effects while the MSU1 is playing music, but the MSU1 itself cannot.
Thank you. I'm thinking at the point I'm at in the game, I'd like to have MSU-1 active, but I dont know how to operate it? I own an SD2SNES, and using bsnes to debug my port as I build it. I know the exact location in my port where the sound engine is initiated, I guess that there is a start?

d4s
Posts: 94
Joined: Mon Jul 14, 2008 4:02 pm

Re: Need guidance with nes to snes.

Post by d4s » Sat Apr 10, 2021 3:37 am

infidelity wrote:
Mon Apr 05, 2021 7:35 am
The next thing is the sound engine. What I'll probably end up doing for now, until I have the game running 100%, is bypass the games sound engine and work on it later. Cause I was poking around an snes title to see how it works with the APU and wow that's crazy.

Again I'm coming from working with nes roms since '04, and I now have to learn how a sound engine is copied from rom and injected into the APU.
Have you checked Memblers NES 2A03 Sound Emulator/NSF player for SNES?
It should be trivial to adapt to your use case:
Upload the precompiled binary to the apu once, then replace NES sound register writes in the games sound engine with the respective sound emulator calls.
Probably no need to touch spc code at all to get it running.

Here's what it sounds like:
https://www.youtube.com/watch?v=cHPgbuM3Yo8&lc=

You can get the source code and precompiled ROMs here:
http://membler-industries.com/SNES/

It appears to be used in this project aswell, although I don't have any hands-on experience with that:
https://github.com/mandraga/upernes

If you actually want to improve on the NES audio, that's a different story, of course, but this approach should give you something to listen to pretty quickly.

infidelity
Posts: 462
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity » Sat Apr 10, 2021 6:30 am

d4s wrote:
Sat Apr 10, 2021 3:37 am
infidelity wrote:
Mon Apr 05, 2021 7:35 am
The next thing is the sound engine. What I'll probably end up doing for now, until I have the game running 100%, is bypass the games sound engine and work on it later. Cause I was poking around an snes title to see how it works with the APU and wow that's crazy.

Again I'm coming from working with nes roms since '04, and I now have to learn how a sound engine is copied from rom and injected into the APU.
Have you checked Memblers NES 2A03 Sound Emulator/NSF player for SNES?
It should be trivial to adapt to your use case:
Upload the precompiled binary to the apu once, then replace NES sound register writes in the games sound engine with the respective sound emulator calls.
Probably no need to touch spc code at all to get it running.

Here's what it sounds like:
https://www.youtube.com/watch?v=cHPgbuM3Yo8&lc=

You can get the source code and precompiled ROMs here:
http://membler-industries.com/SNES/

It appears to be used in this project aswell, although I don't have any hands-on experience with that:
https://github.com/mandraga/upernes

If you actually want to improve on the NES audio, that's a different story, of course, but this approach should give you something to listen to pretty quickly.
I'll definitely check this out, I'd love to have this game sound like it does originally on the NES. I still want to include an MSU-1 soundtrack, but for now what you listed here has me intrigued. :-)

Right now I'm almost at the title screen, everything has been running flawlessly code wise. I'm at the point where sprites are being initiated.

Now that I've learned how to utilize the snes wram at $7E:0000-$7E:FFFF, I came up with an easy solution with my Sprite bank data in this game. The game swaps out 8kb banks in $8000-$9FFF & $A000-$BFFF, so I wrote a DMA routine to load the appropriate Sprite bank that is called upon, and I inject it directly into $7E:8000 & $7E:A000, that way I dont have to edit any hard written load addresses! All I gotta do is set the DB register to 7E, especially for the indirect loading. Very excited over this, but I also need to change where the Sprite data gets stored in the Sprite DMA buffer.

infidelity
Posts: 462
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity » Mon Apr 12, 2021 6:18 am

Update - very excited! Got the games sprite engine converted/modified, it loads the original sprite data, stores it in the appropriate snes oam sections, and I even modify the original attribute byte for the sprites, the two that I needed to focus on was the priority and palette, and I'm so happy everything is working thus far in the story mode introduction of the game!

I'm now at the point where the game initiates an irq, right now nothing is happening, and I made sure I had $4200 set properly, it even says i do according to the properties viewer in bsnes debugger.

Very happy right now! Pushing onward, hoping to get the irq figured out.
Last edited by infidelity on Mon Apr 12, 2021 7:02 am, edited 1 time in total.

Oziphantom
Posts: 1129
Joined: Tue Feb 07, 2017 2:03 am

Re: Need guidance with nes to snes.

Post by Oziphantom » Mon Apr 12, 2021 6:35 am

make sure you have a CLI somewhere in your code.

infidelity
Posts: 462
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity » Mon Apr 12, 2021 7:15 am

Oziphantom wrote:
Mon Apr 12, 2021 6:35 am
make sure you have a CLI somewhere in your code.
I'll check if that has been initiated or not, the original game definitely has that, I'm just not sure if i got to that point where it does. Update - yes I do have CLI read in my code.

However I had an issue with my sprite engine last night, and found out what was causing it to crash the rom after 2 seconds of initiation.

It kept crashing once a few sprites were initiated. After trace stepping through the port, I noticed the irq engine was being initiated while my code was in the middle of reading from my 7E data bank, and while my prg bank was in 04. The irq routine was reading from within the 7E data bank, pointing to nowhere, causing the crash.

My solution, was at the very beginning of the sprite engine, I shut of both H&V irq's in $4200, then when my sprite engine ended, I re-enabled both the H&V irq's in $4200.

In doing that, my sprite engine works perfectly.

But now im wondering if that's the correct way of making sure this routine doesnt get interrupted, should I have used the WAI opcode at the start of my sprite engine?

Again this is new to me doing a port, an I had a feeling getting to this point of the game where a split screen happens, that I'd need a lil guidence in making sure I'm going about things correctly.

Dartan
Posts: 8
Joined: Mon Mar 22, 2021 10:58 am
Location: Germany

Re: Need guidance with nes to snes.

Post by Dartan » Mon Apr 12, 2021 7:31 am

infidelity wrote:
Mon Apr 12, 2021 7:15 am
My solution, was at the very beginning of the sprite engine, I shut of both H&V irq's in $4200, then when my sprite engine ended, I re-enabled both the H&V irq's in $4200.

In doing that, my sprite engine works perfectly.

But now im wondering if that's the correct way of making sure this routine doesnt get interrupted, should I have used the WAI opcode at the start of my sprite engine?
If you want to make sure that the routine does not get interrupted, I guess that's one way of doing that. And if you *really* don't want any interruptions, make sure also to temporary disable the NMI using the same register.

But wouldn't it be easier (and less error prone) to modify the IRQ handler to save the current value of DBR (PHB instruction), set DBR to whatever bank the IRQ handler needs it to be and finally the end of the handler restore DBR to it's the original value (PLB instruction)?

Oziphantom
Posts: 1129
Joined: Tue Feb 07, 2017 2:03 am

Re: Need guidance with nes to snes.

Post by Oziphantom » Mon Apr 12, 2021 7:33 am

*got ninja'd :)

well the way to stop an IRQ is to just
SEI
then
CLI
This won't stop NMI's though.

WAI is not what you want it waits for one to happen, doesn't stop another from happening while it runs.

However what you should be doing it setting the data bank to what you need during your interrupt and not relying upon then being something valid. i.e

Code: Select all

IRQ
REP #$30
PHA
PHX
PHY
PHB
PHK
PLB
... code here
PLB
PLY
PLX
PLA
RTI
Please see Elements of a SNES Engine Episode 1 walk through of the 2 threads method for full details on what can go wrong in a NMI/IRQ case and how to deal with them.

infidelity
Posts: 462
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity » Mon Apr 12, 2021 8:00 am

Does my data bank need to be 00, when loading from an snes address? I'm doing lda's of 4211, and in the debugger I'm only seeing their name appear when my data bank is 00?

Oziphantom
Posts: 1129
Joined: Tue Feb 07, 2017 2:03 am

Re: Need guidance with nes to snes.

Post by Oziphantom » Mon Apr 12, 2021 8:04 am

In LOROM, 00-3F, 80-BF has registers. ROM is available in 00-6F, 80-BF.



edit had ROM and Registers backwards :)
Last edited by Oziphantom on Mon Apr 12, 2021 8:28 am, edited 1 time in total.

Dartan
Posts: 8
Joined: Mon Mar 22, 2021 10:58 am
Location: Germany

Re: Need guidance with nes to snes.

Post by Dartan » Mon Apr 12, 2021 8:13 am

To access internal cpu registers ($4000 to $43FF), the DBR need to be anywhere in the range from $00-$3F (or $80-$BF) (see 'Memory Map' on
https://wiki.superfamicom.org/memory-mapping)

(HiROM or LoROM actually doesn't matter here, because the S-CPU itself has no clue about these mapping modes and therefore they can only affect the addressing of things *inside the cartridge* => ROM, (B)WRAM and expansion chips)

User avatar
dougeff
Posts: 2868
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Need guidance with nes to snes.

Post by dougeff » Mon Apr 12, 2021 11:08 am

Another option for registers. Use direct page addresses, which always map to bank zero (00).

(A in 16 bit)
LDA #$4300
TCD

(A in 8 bit)
LDA #value
STA $00
; goes to $4300, always in bank 00

alternatively, you can set the Direct Page Register with
PEA $4300
PLD
and not have to change the size of A

Don't forget to change D back to $0000 if you have code that expects zeropage to be $0000 (which all 6502 code does)
nesdoug.com -- blog/tutorial on programming for the NES

infidelity
Posts: 462
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity » Mon Apr 12, 2021 12:06 pm

Seems I'm doing more damage with trying to get the irq going. Im really disliking the bsnes debugger when tracing, the window doesnt show what took place before the caused the crash, it just shows you where you crashed. This is gonna take some time to figure out.

infidelity
Posts: 462
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity » Mon Apr 12, 2021 4:16 pm

Damn, In getting that issue again where my irq engine comes on constantly, and I have my lda 4211 in there as well that fixed this in the first place.

update

I've wasted a entire day going back and forth trying to get the irq engine to function, but i'm crashing my port way too much, beucase of the irq engine firing all the time, it would end up initiating when i was performing a DB setup elsewhere.

I think what i need is a horizontal irq split, not a vertical one. the game splits the screen from left to right.

Right now i still have B1 getting stored into $4200, but B# is (NMI, VerticalIRQ, HorizontalIRQ) I read somewhere that if you both HV set, one or the other gets initiated? But i only need the Horizontal since the NES game never performs a vertical scroll in it's MMC3 form.

User avatar
dougeff
Posts: 2868
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Need guidance with nes to snes.

Post by dougeff » Mon Apr 12, 2021 5:39 pm

SEI prevents IRQs (for when you don't need IRQs at all)

If you have $4200 incorrect, you could get an IRQ every scanline that the PPU is drawing the screen. That would result in IRQs firing rapidly.

Edit, I reread your post...
But i only need the Horizontal [IRQ timer]
THAT is incorrect. You want either V timer, or H and V timer. Easiest would be just the V timer, which should work the same as MMC3 scanline IRQ, plus or minus a few pixels.

.

Edit 2

Another thought. If all you are doing is some split screen with H scroll changes, consider using HDMA instead. That would allow you to avoid IRQs altogether.
nesdoug.com -- blog/tutorial on programming for the NES

Post Reply