Need guidance with nes to snes. UPDATE: Port Complete of Mega Man IV + MSU-1

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

I like talking music / SPC programming, but I don't know anything about Membler's thing.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

I believe this is membler's APU / SPC code, assembled into a binary file.

https://github.com/mandraga/upernes/blo ... s_2a03.bin

And this looks like the sound functions on the CPU side.

https://github.com/mandraga/upernes/blo ... /Sound.asm
nesdoug.com -- blog/tutorial on programming for the NES
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

Thank you dougeff, creaothceann, Myself086! Right now I've got the 2A03.bin uploaded to the APU, but in the upernes sound.asm file, it says APUINIT, but I cant find what that exactly is?

Right now I just have

lda #$01
Nop
Nop
Nop

Code: Select all

Spc700FwEnd:
		lda #$01
		sta APUInit ;??? Is it an apu address $214x??
		plb ; Restore the bank
        plp
        rts
Also... this part of code that transfers the current Y count to A, the Y count is 16bit while A is 8bit.

Code: Select all

; send the transfered byte count
		iny
		iny
		tya
		sta $2140
Is that ok? I checked to make sure A was still 8bit from that .asm file.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

APUinit is a RAM variable, 8 bit. Defined here, with about a dozen other variables you will also need.

https://github.com/mandraga/upernes/blo ... sm/var.inc

It is a fail safe measure to make sure the APU update code doesn't run until the init function has completed.
Is that ok?
If it works, it's ok. you will have to test it and see if it does.

size mismatches sometimes are ok (on register transfers). so, it might work.
nesdoug.com -- blog/tutorial on programming for the NES
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

dougeff wrote: Mon Apr 26, 2021 8:19 am
Is that ok?
If it works, it's ok. you will have to test it and see if it does.

size mismatches sometimes are ok (on register transfers). so, it might work.

Yes it looks ok within the APU. From the video I watched, idk if I misinterpreted it, but I thought the APU gets cleared out all the way to the boot rom? For me, the DP is cleared only in the APU. I have the 2A03 as the last function ar the end if my snesinit.

Also I checked that link you sent me regarding the variables, very overwhelming. Looks like the base address starts at $0800. I have my new vram buffer located at $0800. I'll have to adjust the base to $0900 instead for me? I'll look through the sound.asm to see what variables I need to have.
Myself086
Posts: 158
Joined: Sat Nov 10, 2018 2:49 pm

Re: Need guidance with nes to snes.

Post by Myself086 »

No RAM ever gets cleared out on reset. The APU has software to reset part of its memory.

The transfer from 16-bit Y to 8-bit A is because the APU expects an increment of one on the index (at $2140) when a new byte is available but only the lowest 8-bit. The data is on the very next byte ($2141) and needs to be written first. Writing the index in 8-bit mode is required here.

Code: Select all

		; send the transfered byte count
		iny
		iny
		tya
		sta $2140
This code is for terminating a block transfer. This is done by incrementing the index by more than 1. I believe the termination index has to be non-zero because I have an additional ORA #1 in my code.


On another note, I looked into improving the triangle and noise channels yesterday, volume accuracy could be improved a bit. Since I know you're working in hex, expect to eventually receive a bigger bin file for the APU.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

I look forward to the updated .bin for the spc :-)
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

Oh man, yet again an NMI issue. I kept getting crash again in my story mode part of the game, and it seems to happen all the time now that i have the sound engine (running original data, no output yet) running. I do not have much additional code happening, its quick little changes to the DB register when I need to load somewhere else during an indirect load.

Anyway, what's happening is during my Sprite engine, it loads up a certain amount of tiles depending on what's coming on the screen, and it decrements until it is time for BPL, (when counter reaches FF) this scene I'm on uses 15 sprites, and when my counter reaches 02 and performs the rest of the routine, it gets interrupted by the NMI firing all l over again, the game never finishes the routine, getting stuck in a loop, the scene gets sluggish and then it crashes, there is no stack overflow either, wanted to mention that.

Idk if I have 4210 or 4212 not used properly or something. I know I needed 4212 at the beginning of my NMI to stop my irq vector from firing constantly, but now I'm stuck with my NMI firing again when it hasnt finished itself.

Again my additional code shouldn't be adding this much time to cause any issue i think, im hoping it's just a matter of setting flags for my NMI not to refire.

Please help, thanks! :-)
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Need guidance with nes to snes.

Post by Oziphantom »

DB change, sounds the culprit, however your NMI should explicitly set the DB and thus read the registers it needs. There is only 1 source for the NMI it shouldn't be hard to track it. No 1 reason DB is 7e and not <$40 No2 it's 7F.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

Oziphantom wrote: Fri Apr 30, 2021 6:12 am DB change, sounds the culprit, however your NMI should explicitly set the DB and thus read the registers it needs. There is only 1 source for the NMI it shouldn't be hard to track it. No 1 reason DB is 7e and not <$40 No2 it's 7F.
I can't imagine a DB change can cause my NMI to refire? The retire doesnt happen right when I perform a DB change, the DB change I do is just to load a value from a table in 7E:8000, once I get my value I immediately restore the previous DB value. Sorry if I'm not understanding, I feel I'm misusing 4210 or 4212 maybe?
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

Could have just run out of active frame time, and this is the normal NMI happening.

Possible cause, the music code is taking a long time waiting for APU responses.
nesdoug.com -- blog/tutorial on programming for the NES
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

Hmm, not sure what to do. I even tried adding a flag within the beginning of the NMI, does a check to bot refire if a certain register isn't cleared. That gave me problems.

Bumming, wasnt expecting slowdown/crash like this during one scene, hoping I dont have to scratch this project, dang. :'(

Right now I'm going to tighten up code, remove any waste.
Myself086
Posts: 158
Joined: Sat Nov 10, 2018 2:49 pm

Re: Need guidance with nes to snes.

Post by Myself086 »

Some emulators allow changing the CPU's clock speed. It's great for testing whether performance is the cause of crashes or other anomalies. I'm not sure which emulators have this option other than my private SNES emulator.

Trying to save some cycles before NMI happens is not a viable long-term solution for fixing a crash. You should always let your program be able to handle lag frames.
infidelity wrote: Fri Apr 30, 2021 6:30 am
Oziphantom wrote: Fri Apr 30, 2021 6:12 am DB change, sounds the culprit, however your NMI should explicitly set the DB and thus read the registers it needs. There is only 1 source for the NMI it shouldn't be hard to track it. No 1 reason DB is 7e and not <$40 No2 it's 7F.
I can't imagine a DB change can cause my NMI to refire? The retire doesnt happen right when I perform a DB change, the DB change I do is just to load a value from a table in 7E:8000, once I get my value I immediately restore the previous DB value. Sorry if I'm not understanding, I feel I'm misusing 4210 or 4212 maybe?
Interrupt code that uses 16-bit addresses shouldn't assume that DB is set correctly. Do you change DB for both NMI and IRQ?
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

It's a bit difficult to diagnose problems over a forum when you can't see the code in question, or a trace log at the problem area, or something.
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Need guidance with nes to snes.

Post by tepples »

Myself086 wrote: Fri Apr 30, 2021 12:38 pmSome emulators allow changing the CPU's clock speed. It's great for testing whether performance is the cause of crashes or other anomalies. I'm not sure which emulators have this option other than my private SNES emulator.
Any emulator that supports the Super NES (PAL version) should allow inserting 50 scanlines' worth of CPU time between the start of NMI and the start of active picture.
Post Reply