It is currently Sun May 20, 2018 10:33 pm

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Apr 06, 2018 11:07 pm 
Online

Joined: Fri Feb 16, 2018 5:52 am
Posts: 6
Location: Ukraine
Now I add Offset-per-tile mode in my FPGA SNES, for now I did Offset-per-tile only for BG1 in BGMODE 2 (it works in Tetris Attack, Battletoads in battlemaniacs and SNES burn-in test rom), and I have a few questions.

As I understand, scrolling values in BG3 common to BG1 and BG2, but read 2 times: one for BG1 with BG1HOFS, and one for BG2 with BG2HOFS. Also, I think that in hardware reading scrolling values from BG3 occurs after reading tiles of BG1 and BG2 (in the place where the reading occurs tiles of BG3 and BG4 in BGMODE 0), therefore this scrolling values apply to next tile in row. I'm right or not?

And the second question, what games or test roms using Offset-per-tile in BGMODE 4 and 6?


Top
 Profile  
 
PostPosted: Sat Apr 07, 2018 4:39 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2049
Location: DIGDUG
lidnariq posted a test ROM here which uses modes 0-6.

viewtopic.php?f=12&t=14945

And I think Yoshi's Island uses an offset per tile mode on the "Touch Fuzzy Get Dizzy" level.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Sat Apr 07, 2018 7:05 am 
Offline
User avatar

Joined: Mon Jan 23, 2006 7:47 am
Posts: 104
Also in the levels that use lava or stone blocks that move up/down, iirc.


Top
 Profile  
 
PostPosted: Sun Apr 08, 2018 6:47 am 
Online

Joined: Fri Feb 16, 2018 5:52 am
Posts: 6
Location: Ukraine
Thanks, lidnariq's test rom very helped me.


Top
 Profile  
 
PostPosted: Sun May 20, 2018 10:31 am 
Online

Joined: Fri Feb 16, 2018 5:52 am
Posts: 6
Location: Ukraine
AWJ wrote:
Code:
0.000004208333333, 0, 0, 1, 0, 1, 0, 0, 1 ; BG2 nametable  .1666 us
0.000004375000000, 0, 0, 0, 0, 0, 0, 0, 1 ; BG1 nametable  .1666 us
0.000004541666667, 0, 1, 0, 1, 0, 0, 0, 1 ; BG3 OPT        .3750 us
0.000004916666667, 1, 0, 0, 0, 0, 0, 0, 1 ; BG2 4bpp       .3750 us
0.000005291666667, 1, 0, 1, 0, 1, 0, 0, 1 ; BG1 4bpp       .3750 us
0.000005666666667, 0, 0, 1, 0, 1, 0, 0, 1 ; BG2 nametable  .2083 us
0.000005875000000, 0, 0, 0, 0, 0, 0, 0, 1 ; BG1 nametable  .1666 us
0.000006041666667, 0, 1, 0, 1, 0, 0, 0, 1 ; BG3 OPT        .3750 us
0.000006416666667, 1, 0, 0, 0, 0, 0, 0, 1 ; BG2 4bpp       .3750 us
0.000006791666667, 1, 0, 1, 0, 1, 0, 0, 1 ; BG1 4bpp       .3750 us
0.000007166666667, 0, 0, 1, 0, 1, 0, 0, 1 ; BG2 nametable

Mode 2 fetches the nametables, then two words of offset-per-tile data (again, we would need the lower address lines to distinguish them), then the patterns. Since the offset-per-tile is fetched after the nametables, each offset-per-tile fetch must apply to the next set of nametable fetches. This explains why offset-per-tile never applies to the first visible tile in a scanline.


If Mode 2 fetches only two words of offset-per-tile data for BG1 and BG2, then how calculate HOFS and VOFS for BG3?


Top
 Profile  
 
PostPosted: Sun May 20, 2018 10:51 am 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2647
srg320 wrote:
AWJ wrote:
Code:
0.000004208333333, 0, 0, 1, 0, 1, 0, 0, 1 ; BG2 nametable  .1666 us
0.000004375000000, 0, 0, 0, 0, 0, 0, 0, 1 ; BG1 nametable  .1666 us
0.000004541666667, 0, 1, 0, 1, 0, 0, 0, 1 ; BG3 OPT        .3750 us
0.000004916666667, 1, 0, 0, 0, 0, 0, 0, 1 ; BG2 4bpp       .3750 us
0.000005291666667, 1, 0, 1, 0, 1, 0, 0, 1 ; BG1 4bpp       .3750 us
0.000005666666667, 0, 0, 1, 0, 1, 0, 0, 1 ; BG2 nametable  .2083 us
0.000005875000000, 0, 0, 0, 0, 0, 0, 0, 1 ; BG1 nametable  .1666 us
0.000006041666667, 0, 1, 0, 1, 0, 0, 0, 1 ; BG3 OPT        .3750 us
0.000006416666667, 1, 0, 0, 0, 0, 0, 0, 1 ; BG2 4bpp       .3750 us
0.000006791666667, 1, 0, 1, 0, 1, 0, 0, 1 ; BG1 4bpp       .3750 us
0.000007166666667, 0, 0, 1, 0, 1, 0, 0, 1 ; BG2 nametable

Mode 2 fetches the nametables, then two words of offset-per-tile data (again, we would need the lower address lines to distinguish them), then the patterns. Since the offset-per-tile is fetched after the nametables, each offset-per-tile fetch must apply to the next set of nametable fetches. This explains why offset-per-tile never applies to the first visible tile in a scanline.


If Mode 2 fetches only two words of offset-per-tile data for BG1 and BG2, then how calculate HOFS and VOFS for BG3?


It doesn't. Mode 2 only has 2 layers.


Top
 Profile  
 
PostPosted: Sun May 20, 2018 11:13 am 
Online

Joined: Fri Feb 16, 2018 5:52 am
Posts: 6
Location: Ukraine
Code:
HOFS = X + BGnHOFS
VOFS = Y + BGnVOFS
ValidBit = 0x2000 for BG1, or 0x4000 for BG2
if (!IsFirst8x8Tile(BGn, HOFS)) {
  /* Hopefully these calculations are right... */
  Hval = GetTile(BG3, (HOFS&7)|(((X-8)&~7)+(BG3HOFS&~7)), BG3VOFS)
  Vval = GetTile(BG3, (HOFS&7)|(((X-8)&~7)+(BG3HOFS&~7)), BG3VOFS + 8)
  if (Hval&ValidBit) HOFS = (HOFS&7) | ((X&~7) + (Hval&~7))
  if (Vval&ValidBit) VOFS = Y + Vval
}
Pixel[X,Y] = GetPixel(Get8x8Tile(BGn, HOFS, VOFS), HOFS, VOFS)

What does means n in this formula?

In BSNES source BG3's offsets calculate separately for BG1 and BG2, that is 4 words of offset-per-tile data reads from BG3 tilemap.
Code:
if(self.regs.bgmode == 2 || self.regs.bgmode == 4 || self.regs.bgmode == 6) {
    uint16 offset_x = (x + (hscroll & 7));

    if(offset_x >= 8) {
      unsigned hval = self.bg3.get_tile((offset_x - 8) + (self.bg3.regs.hoffset & ~7), self.bg3.regs.voffset + 0);
      unsigned vval = self.bg3.get_tile((offset_x - 8) + (self.bg3.regs.hoffset & ~7), self.bg3.regs.voffset + 8);
      unsigned valid_mask = (id == ID::BG1 ? 0x2000 : 0x4000);

      if(self.regs.bgmode == 4) {
        if(hval & valid_mask) {
          if((hval & 0x8000) == 0) {
            hoffset = offset_x + (hval & ~7);
          } else {
            voffset = y + hval;
          }
        }
      } else {
        if(hval & valid_mask) hoffset = offset_x + (hval & ~7);
        if(vval & valid_mask) voffset = y + vval;
      }
    }
  }


Top
 Profile  
 
PostPosted: Sun May 20, 2018 1:00 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 7118
Location: Seattle
srg320 wrote:
If Mode 2 fetches only two words of offset-per-tile data for BG1 and BG2, then how calculate HOFS and VOFS for BG3?
In the offset-per-tile modes, BG3 doesn't contain a nametable. Instead it literally contains the horizontal and vertical offsets for the lower-numbered backgrounds.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: srg320 and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group