getting started on 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.
Optiroc
Posts: 129
Joined: Thu Feb 07, 2013 1:15 am
Location: Sweden

Re: getting started on SNES

Post by Optiroc » Thu Mar 02, 2017 1:17 am

zkip wrote:Also, the way OAM works on the SNES seems weird to me. IIRC, you have the set the sprite number multiplied by either 2 or 4 when you write the OAM address low.
Not particularly weird considering that the size of each OAM entry is 4 bytes.

zkip
Posts: 67
Joined: Tue Nov 20, 2012 1:59 pm

Re: getting started on SNES

Post by zkip » Thu Mar 02, 2017 8:55 am

Not particularly weird considering that the size of each OAM entry is 4 bytes.
Exactly, so why multiply the address by 2? (I'm recalling now that it was actually 2 because that's what made it seem weird to me.)

By the way, I actually have no right to try to help here. I'm probably confusing you more. It's been 5+ years since I've done anything with the SNES. :oops:

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

Re: getting started on SNES

Post by dougeff » Thu Mar 02, 2017 9:00 am

I'm just frustrated. I just got my running shoes (everdrive) in the mail, and want to go for a jog, and then i spend 4 hours trying to tie my shoes (and failing).
nesdoug.com -- blog/tutorial on programming for the NES

zkip
Posts: 67
Joined: Tue Nov 20, 2012 1:59 pm

Re: getting started on SNES

Post by zkip » Thu Mar 02, 2017 9:10 am

You seem to be writing sprites in a straight forward way. Maybe try DMAing the sprites from a copy in RAM? Not sure if those "tutorials" have been depreciated yet or not though.

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

Re: getting started on SNES

Post by dougeff » Thu Mar 02, 2017 9:43 am

I got it to work.

I wrote to the low table, but then no follow up to the high table, thus the low table was never updated, my sprites didn't appear.

Ok, I feel better.

Edit, I think I misunderstood the wiki above, but somehow, rewriting the entire OAM (low and high) fixed it, and sprites are showing. Perhaps leaving the OAM address set mid-way screws things up.
Last edited by dougeff on Wed Sep 13, 2017 3:41 pm, edited 1 time in total.
nesdoug.com -- blog/tutorial on programming for the NES

Optiroc
Posts: 129
Joined: Thu Feb 07, 2013 1:15 am
Location: Sweden

Re: getting started on SNES

Post by Optiroc » Thu Mar 02, 2017 12:32 pm

zkip wrote:
Not particularly weird considering that the size of each OAM entry is 4 bytes.
Exactly, so why multiply the address by 2? (I'm recalling now that it was actually 2 because that's what made it seem weird to me.)

By the way, I actually have no right to try to help here. I'm probably confusing you more. It's been 5+ years since I've done anything with the SNES. :oops:
Yet you couldn't resist the urge to spread disinformation in the very same post?

Of course you don't multiply by 2 to index into an array of data structures of size 4.

tepples
Posts: 21945
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: getting started on SNES

Post by tepples » Thu Mar 02, 2017 1:06 pm

2 what? 4 what?

To clarify things, I applied dimensional analysis. I searched superfamicom.org's page about MMIO ports for "word address", and it turns out VRAM, OAM, and CGRAM are all addressed in 16-bit units. Such address registers behave as if they multiply the address by 2 bytes per word. Thus accessing data structures of size 4 bytes per element requires multiplying the index by 2 words per element, not 4 bytes per element.

But in practice, it's more common to write to OAM using DMA from a display list in a memory that's byte-addressed, namely WRAM. For this, you do need 4 bytes per element.

zkip
Posts: 67
Joined: Tue Nov 20, 2012 1:59 pm

Re: getting started on SNES

Post by zkip » Thu Mar 02, 2017 1:55 pm

Yet you couldn't resist the urge to spread disinformation in the very same post?
At least I tried to help?

No need to be snarky.

BTW, thanks tepples for clearing that up.

creaothceann
Posts: 221
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: getting started on SNES

Post by creaothceann » Thu Mar 02, 2017 4:54 pm

dougeff wrote:I got it to work!

Quote from the superfamicom wiki
the low table of OAM is not affected until the high byte of a word is written
I wrote to the low table, but then no follow up to the high table, thus the low table was never updated, my sprites didn't appear.

Ok, I feel better.

Edit, I think I misunderstood the wiki above, but somehow, rewriting the entire OAM (low and high) fixed it, and sprites are showing. Perhaps leaving the OAM address set mid-way screws things up.
Think of the high table as a separate chip that is only accessed with addresses 512..543. Only the lower table has a latch that buffers writes.

See anomie's regs.txt (e.g. on RHDN) for details.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10

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

Re: getting started on SNES

Post by dougeff » Thu Mar 02, 2017 9:09 pm

I was still having tons of problems, bugs, making me very angry... I think I fixed it... my bad init code says this...

sep #$20 ;a 8
rep #$10 ;i 16
...
lda #$00
tcd

But, TCD transfers low AND high byte of A+B, regardless of processor status, and the value of A is not know at startup, so I was storing a random value for the high byte of the Direct Page Register.

correct init code should be...

rep #$30 ;a 16 i 16
lda #$0000
tcd


Ok, hopefully, I can get this stupid first test program up and running soon.
nesdoug.com -- blog/tutorial on programming for the NES

lidnariq
Posts: 9299
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: getting started on SNES

Post by lidnariq » Thu Mar 02, 2017 9:21 pm

Well, or
sep #$20
lda #0
xba
lda #0
tcd

Also, the 65816 datasheet says D is set to 0 on reset (although I suppose it's possible that this is not true for the 5a22?)

Revenant
Posts: 441
Joined: Sat Apr 25, 2015 1:47 pm
Location: FL

Re: getting started on SNES

Post by Revenant » Thu Mar 02, 2017 9:41 pm

I assume this is still running on the Everdrive, in which case that's probably not a safe assumption.

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

Re: getting started on SNES

Post by dougeff » Thu Mar 02, 2017 10:00 pm

Yes, I'm running on an Everdrive.

Here's the code that IS working on the Everdrive. Slight changes, the background auto-scrolls left (during NMI, let's me know that NMI is firing correctly). And, Controller Reads, Up/Down/Left/Right moves one of the sprites (outside of NMI, let's me know program is running outside NMI correctly).

http://dl.dropboxusercontent.com/s/n93a ... ello11.zip

Improvement still needed, pushing unused sprites offscreen. You can see them in the top left corner. I can't seem to find any documentation on this. Perhaps a Y value of $ff would do it?


Hey, should I also do this on INIT?
lda #00
pha
plb ; set the data bank to 0

EDIT: link updated to push unused sprites to Y = $f0.
Last edited by dougeff on Sun Mar 05, 2017 7:51 pm, edited 1 time in total.
nesdoug.com -- blog/tutorial on programming for the NES

Optiroc
Posts: 129
Joined: Thu Feb 07, 2013 1:15 am
Location: Sweden

Re: getting started on SNES

Post by Optiroc » Fri Mar 03, 2017 4:06 am

zkip wrote:At least I tried to help?

No need to be snarky..
Yeah, sorry about lashing out a bit there. Especially since you stating "multiplying by either 4 or 2" is technically exactly true depending if you want the word or byte offset. :oops: (Then, of course, not having an OAM shadow buffer in RAM and DMA it during vblank is rather bonkers, so it didn't even cross my mind that you might want to use the word offset.)

Sometimes I just get a bit disillusioned with how SNES homebrew never seems to be able to get out of the ghetto...

zkip
Posts: 67
Joined: Tue Nov 20, 2012 1:59 pm

Re: getting started on SNES

Post by zkip » Fri Mar 03, 2017 8:26 am

pushing unused sprites offscreen
You can use the 9th bit for the X location (located in the second OAM table) of the sprite to move it off-screen. Actually, I'm pretty sure that this is the exact purpose of having this bit there anyway as I see no other reason for it.
Sometimes I just get a bit disillusioned with how SNES homebrew never seems to be able to get out of the ghetto...
I agree. There's some sort of jump-start that NESDEV got that SNES didn't.

Post Reply