src/mame/video/n64.c
| r6431 | r6432 | |
| 242 | 242 | |
| 243 | 243 | static RECTANGLE clip; |
| 244 | 244 | |
| 245 | | static UINT8 *texture_cache; |
| 246 | | static UINT32 tlut[256]; |
| 245 | static UINT8 *TMEM; |
| 246 | #define tlut ((UINT16*)(TMEM + 0x800)) |
| 247 | 247 | |
| 248 | 248 | static INT32 k0, k1, k2, k3, k4, k5; |
| 249 | 249 | static UINT8 primitive_lod_frac = 0; |
| r6431 | r6432 | |
| 473 | 473 | if (LOG_RDP_EXECUTION) |
| 474 | 474 | rdp_exec = fopen("rdp_execute.txt", "wt"); |
| 475 | 475 | |
| 476 | | texture_cache = auto_alloc_array(machine, UINT8, 0x100000); |
| 476 | TMEM = auto_alloc_array(machine, UINT8, 0x1004); // 4 guard bytes |
| 477 | memset(TMEM, 0, 0x1000); |
| 478 | TMEM[0x1000] = TMEM[0x1001] = 25; |
| 477 | 479 | |
| 478 | 480 | combiner_rgbsub_a_r[0] = combiner_rgbsub_a_r[1] = &one_color.r; |
| 479 | 481 | combiner_rgbsub_a_g[0] = combiner_rgbsub_a_g[1] = &one_color.g; |
| r6431 | r6432 | |
| 1126 | 1128 | } |
| 1127 | 1129 | |
| 1128 | 1130 | memory_color.r = (((mem >> 11) & 0x1f) << 3) | (((mem >> 11) & 0x1f) >> 2); |
| 1129 | | memory_color.g = (((mem >> 6) & 0x1f) << 3) | (((mem >> 11) & 0x1f) >> 2); |
| 1130 | | memory_color.b = (((mem >> 1) & 0x1f) << 3) | (((mem >> 11) & 0x1f) >> 2); |
| 1131 | memory_color.g = (((mem >> 6) & 0x1f) << 3) | (((mem >> 6) & 0x1f) >> 2); |
| 1132 | memory_color.b = (((mem >> 1) & 0x1f) << 3) | (((mem >> 1) & 0x1f) >> 2); |
| 1131 | 1133 | |
| 1132 | 1134 | if (other_modes.image_read_en) |
| 1133 | 1135 | { |
| r6431 | r6432 | |
| 1320 | 1322 | UINT32 tformat = tile[tilenum].format; |
| 1321 | 1323 | UINT32 tsize = tile[tilenum].size; |
| 1322 | 1324 | UINT32 tbase = tile[tilenum].tmem; |
| 1323 | | UINT32 tpal = tile[tilenum].palette; |
| 1325 | UINT32 tpal = tile[tilenum].palette & 0xf; |
| 1324 | 1326 | |
| 1325 | 1327 | if (t < 0) t = 0; |
| 1326 | 1328 | if (s < 0) s = 0; |
| r6431 | r6432 | |
| 1333 | 1335 | { |
| 1334 | 1336 | case PIXEL_SIZE_4BIT: |
| 1335 | 1337 | { |
| 1336 | | UINT8 *tc = (UINT8*)texture_cache; |
| 1338 | UINT8 *tc = (UINT8*)TMEM; |
| 1337 | 1339 | int taddr = ((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0x7ff; |
| 1338 | 1340 | UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4); |
| 1339 | | UINT16 c = tlut[((tpal << 4) | p) ^ WORD_ADDR_XOR]; |
| 1341 | UINT16 c = tlut[(((tpal << 4) | p) ^ WORD_ADDR_XOR) << 2]; |
| 1340 | 1342 | |
| 1341 | 1343 | if (other_modes.en_tlut) |
| 1342 | 1344 | { |
| r6431 | r6432 | |
| 1361 | 1363 | } |
| 1362 | 1364 | case PIXEL_SIZE_8BIT: |
| 1363 | 1365 | { |
| 1364 | | UINT8 *tc = (UINT8*)texture_cache; |
| 1366 | UINT8 *tc = (UINT8*)TMEM; |
| 1365 | 1367 | int taddr = ((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0x7ff; |
| 1366 | 1368 | UINT8 p = tc[taddr ^ BYTE_ADDR_XOR]; |
| 1367 | | UINT16 c = tlut[p ^ WORD_ADDR_XOR]; |
| 1369 | UINT16 c = tlut[(p ^ WORD_ADDR_XOR) << 2]; |
| 1368 | 1370 | |
| 1369 | 1371 | if (other_modes.en_tlut) |
| 1370 | 1372 | { |
| r6431 | r6432 | |
| 1389 | 1391 | } |
| 1390 | 1392 | case PIXEL_SIZE_16BIT: |
| 1391 | 1393 | { |
| 1392 | | UINT16 *tc = (UINT16*)texture_cache; |
| 1394 | UINT16 *tc = (UINT16*)TMEM; |
| 1393 | 1395 | int taddr = ((tbase>>1) + ((t) * (twidth>>1)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0); |
| 1394 | 1396 | UINT16 c = tc[(taddr & 0x7ff) ^ WORD_ADDR_XOR]; // PGA European Tour (U) |
| 1395 | 1397 | |
| r6431 | r6432 | |
| 1420 | 1422 | } |
| 1421 | 1423 | case PIXEL_SIZE_32BIT: |
| 1422 | 1424 | { |
| 1423 | | UINT32 *tc = (UINT32*)texture_cache; |
| 1425 | UINT32 *tc = (UINT32*)TMEM; |
| 1424 | 1426 | int xorval = (fb_size == PIXEL_SIZE_16BIT) ? XOR_SWAP_WORD : XOR_SWAP_DWORD; // Conker's Bad Fur Day, Jet Force Gemini, Super Smash Bros., Mickey's Speedway USA, Ogre Battle, Wave Race, Gex 3, South Park Rally |
| 1425 | 1427 | int taddr = (((tbase >> 2) + ((t) * (twidth >> 1)) + (s)) ^ ((t & 1) ? xorval : 0)) & 0x3ff; |
| 1426 | 1428 | UINT32 c = tc[taddr]; |
| r6431 | r6432 | |
| 1466 | 1468 | INT32 newr = 0; |
| 1467 | 1469 | INT32 newg = 0; |
| 1468 | 1470 | INT32 newb = 0; |
| 1469 | | UINT16 *tc = (UINT16*)texture_cache; |
| 1471 | UINT16 *tc = (UINT16*)TMEM; |
| 1470 | 1472 | int taddr = ((tbase >> 1) + ((t) * (twidth)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0); |
| 1471 | 1473 | UINT16 c1, c2; |
| 1472 | 1474 | INT32 y; |
| r6431 | r6432 | |
| 1510 | 1512 | { |
| 1511 | 1513 | case PIXEL_SIZE_4BIT: |
| 1512 | 1514 | { |
| 1513 | | UINT8 *tc = (UINT8*)texture_cache; |
| 1515 | UINT8 *tc = (UINT8*)TMEM; |
| 1514 | 1516 | int taddr = ((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0x7ff; |
| 1515 | 1517 | UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4); |
| 1516 | | UINT16 c = tlut[((tpal << 4) | p) ^ WORD_ADDR_XOR]; |
| 1518 | UINT16 c = tlut[((tpal << 4) | p) << 2]; |
| 1517 | 1519 | |
| 1518 | 1520 | if (other_modes.en_tlut) |
| 1519 | 1521 | { |
| r6431 | r6432 | |
| 1538 | 1540 | } |
| 1539 | 1541 | case PIXEL_SIZE_8BIT: |
| 1540 | 1542 | { |
| 1541 | | UINT8 *tc = (UINT8*)texture_cache; |
| 1543 | UINT8 *tc = (UINT8*)TMEM; |
| 1542 | 1544 | int taddr = ((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0x7ff; |
| 1543 | 1545 | UINT8 p = tc[taddr ^ BYTE_ADDR_XOR]; |
| 1544 | | UINT16 c = tlut[p ^ WORD_ADDR_XOR]; |
| 1546 | UINT16 c = tlut[p << 2]; |
| 1545 | 1547 | |
| 1546 | 1548 | if (other_modes.en_tlut) |
| 1547 | 1549 | { |
| r6431 | r6432 | |
| 1567 | 1569 | case PIXEL_SIZE_16BIT: |
| 1568 | 1570 | { |
| 1569 | 1571 | // 16-bit CI is a "valid" mode; some games use it, it behaves the same as 16-bit RGBA |
| 1570 | | UINT16 *tc = (UINT16*)texture_cache; |
| 1572 | UINT16 *tc = (UINT16*)TMEM; |
| 1571 | 1573 | int taddr = ((tbase>>1) + ((t) * (twidth>>1)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0); |
| 1572 | 1574 | UINT16 c = tc[(taddr & 0x7ff) ^ WORD_ADDR_XOR]; // PGA European Tour (U) |
| 1573 | 1575 | |
| r6431 | r6432 | |
| 1609 | 1611 | { |
| 1610 | 1612 | case PIXEL_SIZE_4BIT: |
| 1611 | 1613 | { |
| 1612 | | UINT8 *tc = (UINT8*)texture_cache; |
| 1614 | UINT8 *tc = (UINT8*)TMEM; |
| 1613 | 1615 | int taddr = (tbase + ((t) * twidth) + (s >> 1)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0); |
| 1614 | 1616 | UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4); |
| 1615 | 1617 | UINT8 i = ((p & 0xe) << 4) | ((p & 0xe) << 1) | (p & 0xe >> 2); |
| r6431 | r6432 | |
| 1626 | 1628 | UINT16 c = tlut[((tpal << 4) | p) << 2]; |
| 1627 | 1629 | if (!other_modes.tlut_type) |
| 1628 | 1630 | { |
| 1629 | | color->r = (((c >> 11) & 0x1f) << 3) | (((c >> 11) & 0x1f) << 3); |
| 1630 | | color->g = (((c >> 6) & 0x1f) << 3) | (((c >> 6) & 0x1f) << 3); |
| 1631 | | color->b = (((c >> 1) & 0x1f) << 3) | (((c >> 1) & 0x1f) << 3); |
| 1631 | color->r = (((c >> 11) & 0x1f) << 3) | (((c >> 11) & 0x1f) >> 2); |
| 1632 | color->g = (((c >> 6) & 0x1f) << 3) | (((c >> 6) & 0x1f) >> 2); |
| 1633 | color->b = (((c >> 1) & 0x1f) << 3) | (((c >> 1) & 0x1f) >> 2); |
| 1632 | 1634 | color->a = (c & 1) ? 0xff : 0; |
| 1633 | 1635 | } |
| 1634 | 1636 | else |
| r6431 | r6432 | |
| 1641 | 1643 | } |
| 1642 | 1644 | case PIXEL_SIZE_8BIT: |
| 1643 | 1645 | { |
| 1644 | | UINT8 *tc = (UINT8*)texture_cache; |
| 1646 | UINT8 *tc = (UINT8*)TMEM; |
| 1645 | 1647 | int taddr = ((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0xfff; |
| 1646 | 1648 | UINT8 p = tc[taddr ^ BYTE_ADDR_XOR]; |
| 1647 | 1649 | UINT8 i = 0; |
| r6431 | r6432 | |
| 1674 | 1676 | } |
| 1675 | 1677 | case PIXEL_SIZE_16BIT: |
| 1676 | 1678 | { |
| 1677 | | UINT16 *tc = (UINT16*)texture_cache; |
| 1679 | UINT16 *tc = (UINT16*)TMEM; |
| 1678 | 1680 | int taddr = ((tbase >> 1) + ((t) * (twidth >> 1)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0); |
| 1679 | 1681 | UINT16 c = tc[taddr ^ WORD_ADDR_XOR]; |
| 1680 | 1682 | UINT8 i = (c >> 8); |
| r6431 | r6432 | |
| 1719 | 1721 | { |
| 1720 | 1722 | case PIXEL_SIZE_4BIT: |
| 1721 | 1723 | { |
| 1722 | | UINT8 *tc = (UINT8*)texture_cache; |
| 1724 | UINT8 *tc = (UINT8*)TMEM; |
| 1723 | 1725 | int taddr = ((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0xfff; |
| 1724 | 1726 | UINT8 c = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4); |
| 1725 | 1727 | c |= (c << 4); |
| r6431 | r6432 | |
| 1751 | 1753 | } |
| 1752 | 1754 | case PIXEL_SIZE_8BIT: |
| 1753 | 1755 | { |
| 1754 | | UINT8 *tc = (UINT8*)texture_cache; |
| 1756 | UINT8 *tc = (UINT8*)TMEM; |
| 1755 | 1757 | int taddr = ((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0xfff; |
| 1756 | 1758 | UINT8 c = tc[taddr ^ BYTE_ADDR_XOR]; |
| 1757 | 1759 | |
| r6431 | r6432 | |
| 5133 | 5135 | sh = tile[tilenum].sh = ((w2 >> 12) & 0xfff); |
| 5134 | 5136 | th = tile[tilenum].th = w2 & 0xfff; |
| 5135 | 5137 | |
| 5136 | | switch (ti_format) |
| 5138 | switch (ti_size) |
| 5137 | 5139 | { |
| 5138 | | case 0: // RGBA |
| 5140 | case PIXEL_SIZE_16BIT: |
| 5139 | 5141 | { |
| 5140 | | switch (ti_size) |
| 5142 | //UINT16 *src = (UINT16*)&rdram[(ti_address + (tl >> 2) * (ti_width << 1) + (sl >> 1)) >> 2]; |
| 5143 | UINT16 *src = (UINT16*)rdram; |
| 5144 | UINT32 srcstart = (ti_address + (tl >> 2) * (ti_width << 1) + (sl >> 1)) >> 1; |
| 5145 | UINT16 *dst = (UINT16*)&TMEM[tile[tilenum].tmem]; |
| 5146 | int count = ((sh >> 2) - (sl >> 2)) + 1; |
| 5147 | |
| 5148 | for (i = 0; i < count; i++) |
| 5141 | 5149 | { |
| 5142 | | case PIXEL_SIZE_16BIT: |
| 5150 | if((i*4) < 0x400) |
| 5143 | 5151 | { |
| 5144 | | UINT16 *src = (UINT16*)&rdram[(ti_address + (tl >> 2) * (ti_width << 1) + (sl >> 1)) >> 2]; |
| 5145 | | |
| 5146 | | for (i = (sl >> 2); i <= (sh >> 2); i++) |
| 5147 | | { |
| 5148 | | tlut[i] = src[i]; |
| 5149 | | } |
| 5150 | | break; |
| 5152 | dst[i*4] = src[(srcstart + i) ^ WORD_ADDR_XOR]; |
| 5153 | dst[i*4+1] = 0; |
| 5154 | dst[i*4+2] = 0; |
| 5155 | dst[i*4+3] = 0; |
| 5151 | 5156 | } |
| 5152 | | default: fatalerror("RDP: load_tlut: size = %d\n", ti_size); |
| 5157 | //tlut[i] = src[i]; |
| 5153 | 5158 | } |
| 5154 | 5159 | break; |
| 5155 | 5160 | } |
| 5161 | /* |
| 5162 | case PIXEL_SIZE_16BIT: |
| 5163 | { |
| 5164 | UINT16 *src = (UINT16*)&rdram[(ti_address + (tl >> 2) * (ti_width << 1) + (sl >> 1)) >> 2]; |
| 5156 | 5165 | |
| 5157 | | default: fatalerror("RDP: load_tlut: format = %d\n", ti_format); |
| 5166 | for (i = (sl >> 2); i <= (sh >> 2); i++) |
| 5167 | { |
| 5168 | tlut[i] = src[i]; |
| 5169 | } |
| 5170 | break; |
| 5171 | }*/ |
| 5172 | default: stricterror("RDP: load_tlut: size = %d\n", ti_size); |
| 5158 | 5173 | } |
| 5174 | |
| 5175 | if (TMEM[0x1000] != 25 || TMEM[0x1001] != 25) |
| 5176 | { |
| 5177 | stricterror("rdp_load_tlut: TMEM has been written out-of-bounds"); |
| 5178 | } |
| 5159 | 5179 | } |
| 5160 | 5180 | |
| 5161 | 5181 | static RDP_COMMAND( rdp_set_tile_size ) |
| r6431 | r6432 | |
| 5211 | 5231 | } |
| 5212 | 5232 | |
| 5213 | 5233 | src = (UINT32*)&ram16[ti_address2 >> 1]; |
| 5214 | | tc = (UINT32*)texture_cache; |
| 5234 | tc = (UINT32*)TMEM; |
| 5215 | 5235 | tb = tile[tilenum].tmem >> 2; |
| 5216 | 5236 | |
| 5217 | 5237 | if ((tb + (width >> 2)) > 0x400) |
| r6431 | r6432 | |
| 5324 | 5344 | case PIXEL_SIZE_8BIT: |
| 5325 | 5345 | { |
| 5326 | 5346 | UINT8 *src = (UINT8*)rdram; |
| 5327 | | UINT8 *tc = (UINT8*)texture_cache; |
| 5347 | UINT8 *tc = (UINT8*)TMEM; |
| 5328 | 5348 | int tb = tile[tilenum].tmem; |
| 5329 | 5349 | |
| 5330 | 5350 | if (tb + (width * height) > 4096) |
| r6431 | r6432 | |
| 5354 | 5374 | { |
| 5355 | 5375 | UINT16 *src = (UINT16*)rdram; |
| 5356 | 5376 | UINT32 ti_addr16 = ti_address >> 1; |
| 5357 | | UINT16 *tc = (UINT16*)texture_cache; |
| 5377 | UINT16 *tc = (UINT16*)TMEM; |
| 5358 | 5378 | int tb = (tile[tilenum].tmem / 2); |
| 5359 | 5379 | int taddr; |
| 5360 | 5380 | |
| r6431 | r6432 | |
| 5394 | 5414 | case PIXEL_SIZE_32BIT: |
| 5395 | 5415 | { |
| 5396 | 5416 | UINT32 *src = (UINT32*)&rdram[ti_address / 4]; |
| 5397 | | UINT32 *tc = (UINT32*)texture_cache; |
| 5417 | UINT32 *tc = (UINT32*)TMEM; |
| 5398 | 5418 | int tb = (tile[tilenum].tmem / 4); |
| 5399 | 5419 | int xorval32 = ((fb_size == PIXEL_SIZE_16BIT) ? 2 : 1); |
| 5400 | 5420 | |