MCPcopy Create free account
hub / github.com/TASEmulators/fceux / DrawNameTable

Function DrawNameTable

src/drivers/Qt/NameTableViewer.cpp:1672–1753  ·  view source on GitHub ↗

----------------------------------------------------

Source from the content-addressed store, hash-verified

1670}
1671//----------------------------------------------------
1672static void DrawNameTable(int scanline, int ntnum, bool invalidateCache)
1673{
1674 NTCache &c = cache[ntnum];
1675 uint8_t *tablecache = c.cache;
1676
1677 uint8_t *table = vnapage[ntnum];
1678 if (table == NULL)
1679 {
1680 table = vnapage[ntnum&1];
1681 }
1682
1683 int a, ptable=0;
1684
1685 if (PPU[0]&0x10){ //use the correct pattern table based on this bit
1686 ptable=0x1000;
1687 }
1688
1689 bool invalid = invalidateCache;
1690 //if we werent asked to invalidate the cache, maybe we need to invalidate it anyway due to vnapage changing
1691 if (!invalid)
1692 {
1693 invalid = (c.curr_vnapage != vnapage[ntnum]);
1694 }
1695 c.curr_vnapage = vnapage[ntnum];
1696
1697 //HACK: never cache anything
1698 invalid = true;
1699
1700 for (int y=0;y<30;y++)
1701 {
1702 for (int x=0;x<32;x++)
1703 {
1704 int ntaddr = (y*32)+x;
1705 int attraddr = 0x3C0+((y>>2)<<3)+(x>>2);
1706 if (invalid
1707 || (table[ntaddr] != tablecache[ntaddr])
1708 || (table[attraddr] != tablecache[attraddr]))
1709 {
1710 int temp = (((y&2)<<1)+(x&2));
1711 a = (table[attraddr] & (3<<temp)) >> temp;
1712
1713 //the commented out code below is all allegedly equivalent to the single line above:
1714 //tmpx = x>>2;
1715 //tmpy = y>>2;
1716 //a = 0x3C0+(tmpy*8)+tmpx;
1717 //if((((x>>1)&1) == 0) && (((y>>1)&1) == 0)) a = table[a]&0x3;
1718 //if((((x>>1)&1) == 1) && (((y>>1)&1) == 0)) a = (table[a]&0xC)>>2;
1719 //if((((x>>1)&1) == 0) && (((y>>1)&1) == 1)) a = (table[a]&0x30)>>4;
1720 //if((((x>>1)&1) == 1) && (((y>>1)&1) == 1)) a = (table[a]&0xC0)>>6;
1721
1722 int chr = table[ntaddr]*16;
1723
1724 //test.. instead of pretending that the nametable is a screen at 0,0 we pretend that it is at the current xscroll and yscroll
1725 //int xpos = ((RefreshAddr & 0x400) >> 2) | ((RefreshAddr & 0x1F) << 3) | XOffset;
1726 //int ypos = ((RefreshAddr & 0x3E0) >> 2) | ((RefreshAddr & 0x7000) >> 12);
1727 //if(RefreshAddr & 0x800) ypos += 240;
1728 //int refreshaddr = (xpos/8+x)+(ypos/8+y)*32;
1729

Callers 1

FCEUD_UpdateNTViewFunction · 0.70

Calls 3

FCEUPPU_GetAttrFunction · 0.85
FCEUPPU_GetCHRFunction · 0.85
DrawChrFunction · 0.70

Tested by

no test coverage detected