Page 6 of 23

Re: Need guidance with nes to snes.

Posted: Tue Mar 09, 2021 12:31 am
by calima
dougeff wrote: Mon Mar 08, 2021 5:48 pm I had a thought. Instead of changing all the 6502/NES code to SNES... keep the 6502 exactly the same, and build an interpreter that parses every 6502 instruction like some kind of emulator.
I seem to recall this already exists elsewhere on this forum :lol:

Re: Need guidance with nes to snes.

Posted: Tue Mar 09, 2021 6:39 am
by infidelity
93143 wrote: Mon Mar 08, 2021 7:17 pm I was editing my previous post when you showed back up, and you may have missed a detail. In any case I might as well be explicit about this, just in case you don't already know:

The SNES has two bank registers: the program bank and the data bank. They are not the same thing and can have different values. The former is the top byte of the 24-bit program counter, and is changed via jml (or jsl or rtl, technically). The latter is used with loads and stores as the implicit top byte of a 16-bit ("absolute") address, to form a 24-bit address, and is changed via plb. This is very important to keep in mind if you're attempting to emulate a PRG ROM bankswitch, because you may need to change both registers.

phk pushes the program bank byte onto the stack. This is often used to set up for plb, for instance when initializing a FastROM program.
Thank you for all of that. I'm not going to actually use the mmc3 bankswap routine in this game, I am however keeping the games bankswap values it stores in ram intact, so that when those are read, pushed, pulled, that there will be no issue. In the routine I simply remove the writes to the mmc3's $8000/$8001 addresses. I've been slowly including the 2000 byte banks that are bankswapped to, and jotting down their original bank id, and where they are now in the snes.

There are some hard coded sections that do bankswaps, like for the sound engine. But right now everything is going at a snails pace, I'm at the palette animation routine the game uses, and I just decided to place my CGRAM 16 bit table at the end of the snes wram, since the nes game I'm porting only uses $0-$7FF. I plan to use the nes palette values 00-3F as a Y value, to load its 16 bit equivalent from the CGRAM table in wram.

Re: Need guidance with nes to snes.

Posted: Wed Mar 10, 2021 4:37 pm
by infidelity
Ok, so I started experiencing an issue where my NMI wouldn't fire back up for a second time.

I did some investigating, and I came to my mmc3 irq setup. IRQ HV enable is included in $4200. As bits 2# and 1#.

Now, before this routine i had set the NMI enable 8# bit in $4200. And later on I come to the point where the irq enable address does its check of not equal. So my routine I either set, or reset the irq horizontal bit in $4200, and nothing else i touch in $4200.

I'm nowhere near gameplay or loading anything, just setting up the various functions within the rom, but ingot stuck in a constant loop that is used before the NMI fires.

My question is, even though I ONLY altered the irq H bit 1#, do I always need to set the NMI? Cause I'm wondering if my irq enable/disable setup in $4200, cleared out my NMI enable?

Re: Need guidance with nes to snes.

Posted: Wed Mar 10, 2021 5:05 pm
by Myself086
$4200 is write-only so you need to keep its state elsewhere (can't use TSB nor TRB). Writing a 0 to the NMI bit will disable NMI.

Re: Need guidance with nes to snes.

Posted: Wed Mar 10, 2021 5:30 pm
by infidelity
Crap cause I have a good sized routine that sets and resets bits TRB/TSB on $4200.....

Re: Need guidance with nes to snes.

Posted: Wed Mar 10, 2021 7:36 pm
by 93143
You know, this stuff is documented already in a really easy-to-read format. I've mentioned it before:

https://wiki.superfamicom.org/registers

What are you using as reference?

Re: Need guidance with nes to snes.

Posted: Thu Mar 11, 2021 4:19 am
by Myself086
Sounds to me like you're coding directly in hex without an assembler. I hope you're using an assembler for a project of this size.

I use https://problemkaputt.de/fullsnes.htm as reference.

Re: Need guidance with nes to snes.

Posted: Thu Mar 11, 2021 9:06 am
by infidelity
Felling good! Created a new routine so that the original games current buffered bg/sprite palette id's, are converted to their 16-bit equivalent, stored into an area in wram for my 200 byte table to be uploaded into CGRAM, and uploaded via DMA.

Code: Select all

;setup indirect indexed addressing to $70-$71.
lda #$40          
sta $70
lda #$1d
sta $71

;to see if routine has converted 20th nes palette, 
if so, skip to DMA transfer.
cmp #$20
beq $8245

;use $1d30 as an x counter, for which of the 20 nes
palette colors you are currently on in $600-$61F, use
loaded nes color value as x pointer, to get it's new x 
value to load within the 16-bit/2 byte equivalent table,
check to see if routine has loaded 8 bytes. (4 colors)
ldy #$00
ldx $1d30
lda $0600,x
tax
lda $1f40,x
tax
lda $1f40,x
sta ($70),y
iny
inx
lda $1f40,x
sta ($70),y
inc $1d30
iny
cpy #$08
beq $820e

;if y has reached 8 bytes, (4 nes colors) take low byte from $70, inc 
by 20, so that the next bg/sprite can receive its 16-bit
values.
lda $70
clc
adc #$20
sta $70
lda $1d30
cmp #$10
bne $8208

;if 10 nes colors have been converted by this time,
(bg1-4) then reset $70-$71 for new indirect indexed
addressing for sprite palettes.
lda #$40
sta $70
lda #$1e
sta $71
bne $8208

;dma transfer of newly created 200 byte table within
wram, this routine is reached when the conversion
routine has completed converting 20 nes colors.
stz $1d30
stz $70
stz $71
rep #$18
lda #$00
sta $2121
lda #$7e
ldx #$1d40
ldy #$0200
stx $4302
sta $4304
sty $4305
stz $4300
lda #$22
sta $4301
lda #$01
sta $420b
sep #$30

rtl
93143 wrote: Wed Mar 10, 2021 7:36 pm You know, this stuff is documented already in a really easy-to-read format. I've mentioned it before:

https://wiki.superfamicom.org/registers

What are you using as reference?
I'm using that and various other docs, but I must've overlooked something in regards to $4200. I know it's a write only register, but I didn't know if I was setting resting the irq bits, that I'd need to make sure the NMI bit as still set, because i was stuck in an infinite loop, and my NMI wouldn't refire, but when I went back to my irq setup, I made sure to include the NMI bit as set, and then my NMI fired up and was able to continue working on the port.
Myself086 wrote: Thu Mar 11, 2021 4:19 am Sounds to me like you're coding directly in hex without an assembler.
Yup, I work entirely via hex, been coding that way since 2004.

Re: Need guidance with nes to snes.

Posted: Thu Mar 11, 2021 10:44 am
by turboxray
infidelity wrote: Thu Mar 11, 2021 9:06 am Yup, I work entirely via hex, been coding that way since 2004.
It's 2021. This could be the year that you finally switch over to an assembler 8-) Really though, working with an assembler isn't that bad. I mean, your projects are ambitious and impressive. I loved your NES zelda hack (more of a new game than a hack). Anyway, you could totally be fluent/comfortable with an assembler with a month or two.

Re: Need guidance with nes to snes.

Posted: Fri Mar 12, 2021 7:22 am
by infidelity
turboxray wrote: Thu Mar 11, 2021 10:44 am
infidelity wrote: Thu Mar 11, 2021 9:06 am Yup, I work entirely via hex, been coding that way since 2004.
It's 2021. This could be the year that you finally switch over to an assembler 8-) Really though, working with an assembler isn't that bad. I mean, your projects are ambitious and impressive. I loved your NES zelda hack (more of a new game than a hack). Anyway, you could totally be fluent/comfortable with an assembler with a month or two.
Thank you for those kind words, extremely appreciated! But I'm just so used to coding via hex, especially from using FCEUX, my favorite debugging emulator ever.

So I'm having another issue with my stack. Again I'm trying to recreate how the stack looks, compared to the nes rom.

During the loop at the end of the reset vector, before the NMI fires, my stack, my stack pointer, A,X,Y, all match between my port, and the original nes rom.

But, when the NMI fires in my port, my stack gets shifted down by 1 byte.

NES ROM NMI register status: A:00 X:08 Y:02 S:$1FC

Port ROM NMI register status: A:00 X:0C Y:01 S$1FB

If there was an issue with the stack before the reset vector loop, I'd get it regarding the change. But everything matches when both roms reach the reset vector loop.

Do I need to add some extra timing somewhere in the reset vector? I wanted to ask before I waste time. I made absolute certain the stack functioning properly, everything matches. Thanks for any suggestions!

Re: Need guidance with nes to snes.

Posted: Fri Mar 12, 2021 7:42 am
by creaothceann
infidelity wrote: Fri Mar 12, 2021 7:22 am During the loop at the end of the reset vector, before the NMI fires, my stack, my stack pointer, A,X,Y, all match between my port, and the original nes rom.

But, when the NMI fires in my port, my stack gets shifted down by 1 byte.
Is that perhaps the program bank byte?

https://en.wikipedia.org/wiki/Interrupt ... rupt_types

Re: Need guidance with nes to snes.

Posted: Fri Mar 12, 2021 8:39 am
by infidelity
Yeah I think that's it, still doesnt explain by the time my NMI is supposed to fire up for a 3rd time, it doesn't and brings me to $0000

Technically its not the point of the NMI being fired up for a 3rd time, the nes rom forces an address into the stack, and its supposed to goto that address.

This works fine the first time it comes to this section, but when I come back to it a second time, it kicks me to $0000

Its something off in the stack before those force values.

Re: Need guidance with nes to snes.

Posted: Fri Mar 12, 2021 9:35 am
by dougeff
You sure it's not an IRQ or BRK $00 and your IRQ or BRK vectors point to $0000 ?

Or do you mean, when you RETURN from NMI you return to $0000?

Quick question. Do you know if your processor is emulation mode or native mode ? You really should be in native mode. I would assume you are, but NMI behaving unexpectedly might mean wrong mode.

If you don't know what I mean, there should be a
CLC
XCE
at the beginning of the program, to put it in native mode. Native mode has an entirely different set of vectors than emulation mode.

Re: Need guidance with nes to snes.

Posted: Fri Mar 12, 2021 12:47 pm
by creaothceann
Maybe he should get it working with emulation mode first?

@infidelity:
Something to keep in mind for the future: while the 65c816 uses all 256 possible opcodes, the 6502 has undocumented ones. Some of them had useful effects and were used by some NES games.
https://wiki.nesdev.com/w/index.php/CPU ... al_opcodes
https://wiki.nesdev.com/w/index.php/Pro ... al_opcodes

Re: Need guidance with nes to snes.

Posted: Fri Mar 12, 2021 2:13 pm
by infidelity
dougeff wrote: Fri Mar 12, 2021 9:35 am You sure it's not an IRQ or BRK $00 and your IRQ or BRK vectors point to $0000 ?
:shock: sigh, whoops, didnt have the irq vector pointer set. Yes before my snes init code I have CLC,XCE. What happened was since I'm from the NES side of things, I had $FFFE-$FFFF set, $FFEE-$FFEF was all 00's. I forgot to set that, since my reset & nmi are correct in the $FE## region.

I'm back in business.