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.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

This is the code where I now have LDA $4212, BPL back to $4212, before it.

Code: Select all

LDA $82,x ;dp indirect, low byte for stack address
CLC
SEP #$30 ;set to 16bit
ADC #$0100 ;add 100 to current low byte stack address, so that I can create the high byte for it, high byte always 01, since the 3 stack locations are within $1## ram
AA ;transfer A to X
9A ;transfer X to Stack
LDA #$0000 ;clear out A
;this point is where my irq would fire, causing the crash, I did the suggestions of setting 16bit in the irq, but I still got issues
REP #$30 ; set back to 8bit
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Need guidance with nes to snes.

Post by Oziphantom »

Those should be fine, unless the stacks are so close to each other that the extra pushes by the 65816 causes it to overflow and hence you trash one of the other "stacks

a cleaner way to do it would be

Code: Select all

lda #$01
xba
lda $82,x
rep #$10 ; xy 16
tax
txs
sep $%10 ; xy 8
lda #0
but in you IRQ and NMI you should set AXY to 16bits, and do your pushes, so entering it with A as 16 shouldn't make a difference.
So put a break point on that line and inspect the stack stack, look at the values in $82 and see if you are running out of room.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

You have it backwards, infidelity

SEP #$30 ; sets AXY 8 bit mode

REP #$30 ; sets AXY 16 bit mode

edit, and if you try TXS (9A) while X is in 8 bit mode, it will zero the high byte of the stack pointer, meaning your stack will be in the zeropage, likely overwriting variables there when the stack grows.
Last edited by dougeff on Tue Apr 20, 2021 8:34 am, edited 1 time in total.
nesdoug.com -- blog/tutorial on programming for the NES
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Need guidance with nes to snes.

Post by Oziphantom »

Oh yeah, well spotted.

Make macros, trust me make macros.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

Thanks on the typeo, but again I code via hexadecimal, I understand if ones who use assemblers were to take my code right there, it'd be incorrect, I'll he more careful with writing code here.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

I can't tell if your code is wrong, or you just typed it wrong, but in hex...

if you want 8-bit, the opcode is e2 (sep)

if you want 16 bit, the opcode is c2 (rep)
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: Tue Apr 20, 2021 10:03 am I can't tell if your code is wrong, or you just typed it wrong, but in hex...

if you want 8-bit, the opcode is e2 (sep)

if you want 16 bit, the opcode is c2 (rep)
It's just a typo, I'm using the reps/seps correctly.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

dougeff wrote: Tue Apr 20, 2021 8:25 am and if you try TXS (9A) while X is in 8 bit mode, it will zero the high byte of the stack pointer, meaning your stack will be in the zeropage, likely overwriting variables there when the stack grows.
I only transfer the stack values as a 16bit value, since my code earlier shows how I've been making sure to keep the high byte as 01. The original nes game just simply swaps out the low byte, but I needed to go a different route when I began the port

Right now I'm making very good progress, I held off again on the sound engine, cause I'm working on some additional screens and sprites and chr conversions. Everything is appearing exactly as the original game.

I'm hoping before Friday, I can begin trying to figure out how to use the 2A03 sound emulator. I know nothing of the APU for the snes, and need to learn how to inject data from ROM, into the APU, and how to access it for usage.

update - Sonner than expected, I now have the port identical to the original in graphics/sprites/irq/etc, I'm now at the point where gameplay is about to take place. This is where I'm going to stop, and need to figure out the APU.

update 2 - Does anyone have an up to date precompiled 2A03 NES emulator file? Idk how to build files from memblers page, and I still need to figure out how to upload the .bin of the 2A03 from my rom to the apu.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

Any assistance will be greatly appreciated 🙂
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Need guidance with nes to snes.

Post by calima »

You can find upload code in the manual, and in snesmod and gss code.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

I'm sort of in the hand holding territory for what I'm asking, heh. Either way, I obtained the official a snes development manual off of archive.

update - hoping to get in touch with Memblers. I'm still skimming though the official SNES dev pdf file.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

Oziphantom wrote: Tue Apr 20, 2021 4:46 am you IRQ and NMI should not have any issues with dealing with interrupting something that is 16bits not 8. As in the IRQ you should set the size you want.

Moving the stack can be an issue. It depends on how you are moving it and where you are moving it too.
As an interrupt will use the stack and place 4 bytes, and then you code will place 6 for the A,X,Y, 1 for PBR, 1 for DP so 12 bytes are pushed to the stack, and then pulled from the stack.
So if you stack is somewhere that is not RAM, it will fail and crash. If your stack is pointing to data that you need to keep and you are doing it for fast PLA to read data, then it will trash the data.
I quote this because it crashed again during my pre-intro. I checked my ram, and it is one of the three stacks that is running into the other.... I've highlighted the 3 stacks.

Image

Question, does Branch Always_Branch Always Long do anything to the stack? Because I've been using a lot of those thinking it would be better than a simple JMP.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

No.

I see a lot of repeated values in the stack, which probably means your stack is growing every frame, which means you probably have interrupts that are interrupting interrupts... ie, they push values that never get popped.... they never reach their exit / return point.

You probably need to do a trace log to see what is going wrong. A growing stack is a problem that NEEDS fixing.

It could mean an imbalance of push and pops. Possibly pushing more things to the stack than you are popping. Possibly you are pushing in 16bit mode and popping in 8bit mode. Etc.
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 »

Think I found the culprit. At one point when my IRQ routine is loading the indirect address values to store into ram, it is not loading the table from the correct DB, and when my irq vector fires up, its indirect jumping to $0000.

So right now I removed the waiting for vBlank fix I did a few days ago, and now with the proper DB bank being loaded for my irq addresses, I'm no longer getting any crashes. I've had 5 successful loops of the intro replaying. Going to let it sit for an hour just to play it safe, then I'm going to test with No$sns.

Update - That was the issue. My port is working perfectly on both bsnes & No$sns. Phew.

Now back to needing assistance with the APU. 🙂
creaothceann
Posts: 610
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Need guidance with nes to snes.

Post by creaothceann »

infidelity wrote: Fri Apr 23, 2021 10:41 am Now back to needing assistance with the APU. 🙂
https://youtu.be/n5eTOGZdnTU
https://wiki.superfamicom.org/spc700-reference
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
Post Reply