Views: 859,113,432
17 users online: chickaDEE Magazine, codfish1002, Darknubs, Digital Entertainment, FYRE150, Gurggz, HammerBrother, Mr. MS, NewPointless, Nirv, Ralshi02, RollingRigatonis, Sapphire, singlepat, TDWarrior, Theresy, WFR98 - Guests: 457 - Bots: 95 Users: 47,485 (2,223 active)
Latest: daniellola
Tip: If you place too many sprites on the same screen, it will slow the game down and cause frustration to the player.Not logged in.
Sprite priority, OAM, and level settings
Forum Index - SMW Hacking - SMW Hacking Help - ASM & Related Topics - Sprite priority, OAM, and level settings
Pages: « 1 »
I'll get right to the point. I want to force a sprite's graphics to be drawn in front of mario. I know it's possible, because, well... one of the tiles of a door sprite does it.

It's 8 8x8 tiles. I've no clue why one goes in front of mario, as they all have the same settings. The only unique thing about that tile is that it is rather high in the OAM order.
EDIT: The graphics routine of that sprite, if interested. The last tile is the one being drawn over mario.

I want to prevent tiles drawing over mario in this case, and cause it elsewhere.

Everything I've ever read about sprite priority in SMW states that they're drawn over each other in relation to the order of the OAM. I want to know exactly what that means. I thought lower OAM order meant higher priority, as evidenced by mario's tiles being at $0310, when the sprite tile OAM starts at $0300 (only allowing for 3 tiles to be below him, which I presume to be used by yoshi).
But if that's true, why is the tile in my above screenshot acting the way it is?

Oh, and another thing. Here's an excerpt from a SNES graphics reference I've been using:
Register $2105: Screen mode register (1b/W)

dcbapmmm  d: BG4 tile size  c: BG3 tile size  b: BG2 tile size
          a: BG1 tile size  Sizes are: 0=8x8; 1=16x16. (See reg. $2107)
          p: order of BG priorities  m: General screen mode

I'm mostly interested in bits p and m of that register. From all.log:
CODE_0082F7:        A9 09         LDA.B #$09                
CODE_0082F9:        8D 05 21      STA.W $2105               ; BG Mode and Tile Size Setting

This, as far as I can tell, is a regular level's settings. #$09 means that it is mode 1, and the priority bit is set (00001001).

Now, back to the graphic reference:
The p (priority bit) affects the order in which BGs are drawn on the screen, as follows
("o" refers to the setting of bit 13 of the tile map):

p (Priority) 0             1
Drawn first  BG4, o=0      BG4, o=0
   (Behind)  BG3, o=0      BG3, o=0
      .      Sprites with OAM priority 0 (%00)
      .      BG4, o=1      BG4, o=1
      .      BG3, o=1      OAM pri. 1
      .      OAM pri. 1    BG2, o=0
      .      BG2, o=0      BG1, o=0
      .      BG1, o=0      BG2, o=1
      .      Sprites with OAM priority 2 (%10)
      .      BG2, o=1      BG1, o=1
Drawn last   BG1, o=1      OAM pri. 3
  (in front) OAM pri. 3    BG3, o=1

The p bit only works in Mode 1.  In all other modes, it is ignored (drawing is performed as if this bit were clear.) 

My question is: Is my reference incorrect? Am I misreading it? It states that, in a regular SMW level, sprites with both priority bits set should be drawn above other sprites, and in fact everything but layer 3. In other words, sprites should be drawn over each other based on priority. But they are not in SMW... Is this true for every SNES game, or is it a quirk of SMW?

Maybe I am misreading it. Does that list of priorities only matter when comparing different BG/sprite layers? So, if you could somehow had a tile of BG1 with priority and one without overlap, would they theoretically also respect some sort of VRAM order, and not priority bits? (I'm pretty sure it's impossible for BG tiles from the same layer to overlap, but :P )

I'm certain I can do what I want regardless of the answer. I'm just a little confused as to how these things work.

Mod edit: stretch--;
In $2105, bits 0-2 are used to determine the BG mode. I'm sure you once heard of this. Mode 7, anyone? SMW uses Mode 1. These bits are irrelevant to your priority questions though. (Unless you want to have the list of which layer goes above another, but I can see you already have that one.)

Yes, the p bit gives Layer 3 ultimate priority over everything else. You can see this in the status bar.
It only works in Mode 1. (Obviously not in Modes 2-6 since those don't have Layer 3. Not sure why it doesn't work in Mode 0.)

From what I've tested, sprite <-> sprite overlap depends on the OAM order.
The lower in the OAM table, the higher the sprite <-> sprite priority. This is why extended sprites, cluster sprites, etc. are always in front of other sprites. (They use $0200-$02FF IIRC.) This is why Mario is in front of most normal sprites. (Most normal ones are drawn on $0318 and beyond. Not sure about Yoshi.)
The PP bits in YXPPCCCT don't seem to have any effect in sprite <-> sprite overlap at all. Their effect goes into layer <-> sprite. (And here, the order in OAM doesn't matter, again.)
The higher the value of the PP bits, the higher the priority of sprites over layers.
Again, I assume you have a good reference of this. I myself prefer regs.txt.

I hope this helped a small bit. I don't think this is something specific to SMW, I believe SMAS has it too but I might have to double-check that.

--------> Don't follow "Find Roy's Dignity", my hack. Because it's pretty outdated. <--------
Alright then. The tile in my screenshot must be a victim of the OAM index overflowing back to 00, though I'm not sure why it does. I have no where near 64 sprite tiles being displayed on that level (more like 20, including mario).
I'll have to make a patch that moves Mario's OAM index on a per-level basis. Shouldn't be too hard.

I still wonder if sprite/bg layers all ignore priority bits in relation to tiles on the same layer, but I guess it really makes no difference. The sprite layer is the only layer which tiles can overlap.

Make a savestate and view it in this tool, you can see the entire machine state including a handy OAM viewer so it beats posting here wondeirng what is going on inside. It's a very useful tool, fully graphical and all of that.

sprite to sprite priority is based on OAM order yes but is subject to OAM priority rotation, see regs.txt for that. Usually it is not used at all.

The PP bits in YXPPCCCT don't seem to have any effect in sprite <-> sprite overlap at all.

nope, not true at all.

If you have a sprite with a higher OAM priority than another sprite, but the higher priority sprite has LESS BG ('pp') priority then the sprite is masked and you just see the BG instead of either sprite, where it looks like the sprite is 'overlapping' with transparency.

to quote regs.txt

Thus, if FirstSprite+3 and
FirstSprite+4 are identical except FirstSprite+3 has priority 0 and
FirstSprite+4 has priority 3, they will both be hidden by any backgrounds that
hide priority 0 sprites. This may seem counterintuitive, since FirstSprite+4
would normally go in front of these BGs, but many games depend on this

Ah, I already have vSNES. Didn't know it could do all that! Checking it out, and I'm going to see if I can make the OAM rotation thing work for my purposes.

EDIT: Well, my current solution is to set $3F to the sprite OAM index of the sprite I want Mario to go behind. Not sure of any adverse effects from this yet.

All.log shows SMW setting $2102 to this value right after some sprite DMA during the NMI. Dunno why after and not during...
I'd like to find out a way to do this as well. I was trying to make a mine cart sprite quite a while ago, and the number-one biggest problem with it was that the player always went in front of it even though I really needed him to go behind. If copying the sprite's OAM index to $3F works, then that's what I'll do. I just have a feeling that it might mess something else up....
Yeah, me too. Haven't found any real problems yet. Something tells me, though, that this will make mario go behind other sprites on the screen as well, though maybe not all. I doubt anything worse than that could happen.
Pages: « 1 »
Forum Index - SMW Hacking - SMW Hacking Help - ASM & Related Topics - Sprite priority, OAM, and level settings

The purpose of this site is not to distribute copyrighted material, but to honor one of our favourite games.

Copyright © 2005 - 2020 - SMW Central
Legal Information - Privacy Policy - Link To Us


Follow Us On

  • YouTube
  • Twitch
  • Twitter


  • Super Mario Bros. X Community
  • Mario Fan Games Galaxy