trunk/src/mame/drivers/coolridr.c
| r21418 | r21419 | |
| 424 | 424 | |
| 425 | 425 | bitmap_rgb32 m_screen1_bitmap; |
| 426 | 426 | bitmap_rgb32 m_screen2_bitmap; |
| 427 | | int m_color; |
| 428 | | UINT8 m_vblank; |
| 429 | 427 | int m_scsp_last_line; |
| 430 | 428 | UINT8 an_mux_data; |
| 431 | 429 | UINT8 sound_data, sound_fifo_full; |
| r21418 | r21419 | |
| 477 | 475 | void sysh1_dma_transfer( address_space &space, UINT16 dma_index ); |
| 478 | 476 | |
| 479 | 477 | UINT16 *m_h1_vram; |
| 480 | | UINT16 *m_h1_pcg; |
| 478 | UINT8 *m_h1_pcg; |
| 481 | 479 | UINT16 *m_h1_pal; |
| 480 | void flush_pal_data( UINT16 offset ); |
| 481 | int m_gfx_index; |
| 482 | int m_color_bank; |
| 482 | 483 | |
| 483 | 484 | osd_work_queue * m_work_queue[2]; // work queue, one per screen |
| 484 | 485 | static void *draw_tile_row_threaded(void *param, int threadid); |
| r21418 | r21419 | |
| 493 | 494 | |
| 494 | 495 | #define VRAM_SIZE 0x100000 |
| 495 | 496 | |
| 497 | static const gfx_layout h1_tile_layout = |
| 498 | { |
| 499 | 16,16, |
| 500 | 0x800, |
| 501 | 8, |
| 502 | { 0, 1, 2, 3, 4, 5, 6, 7 }, |
| 503 | { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 }, |
| 504 | { 0*128, 1*128, 2*128, 3*128, 4*128, 5*128, 6*128, 7*128, 8*128, 9*128, 10*128, 11*128, 12*128, 13*128, 14*128, 15*128 }, |
| 505 | 16*128 |
| 506 | }; |
| 507 | |
| 508 | |
| 496 | 509 | void coolridr_state::video_start() |
| 497 | 510 | { |
| 511 | /* find first empty slot to decode gfx */ |
| 512 | for (m_gfx_index = 0; m_gfx_index < MAX_GFX_ELEMENTS; m_gfx_index++) |
| 513 | if (machine().gfx[m_gfx_index] == 0) |
| 514 | break; |
| 515 | |
| 498 | 516 | machine().primary_screen->register_screen_bitmap(m_temp_bitmap_sprites[0]); |
| 499 | 517 | machine().primary_screen->register_screen_bitmap(m_temp_bitmap_sprites2[0]); |
| 500 | 518 | machine().primary_screen->register_screen_bitmap(m_zbuffer_bitmap); |
| 501 | 519 | machine().primary_screen->register_screen_bitmap(m_zbuffer_bitmap2); |
| 502 | 520 | |
| 503 | 521 | |
| 504 | | |
| 505 | 522 | |
| 523 | |
| 506 | 524 | // testing, not right |
| 507 | 525 | machine().primary_screen->register_screen_bitmap(m_temp_bitmap_sprites[1]); |
| 508 | 526 | machine().primary_screen->register_screen_bitmap(m_temp_bitmap_sprites2[1]); |
| r21418 | r21419 | |
| 514 | 532 | machine().primary_screen->register_screen_bitmap(m_screen1_bitmap); |
| 515 | 533 | machine().primary_screen->register_screen_bitmap(m_screen2_bitmap); |
| 516 | 534 | |
| 517 | | m_h1_vram = auto_alloc_array_clear(machine(), UINT16, VRAM_SIZE); |
| 518 | | m_h1_pcg = auto_alloc_array_clear(machine(), UINT16, VRAM_SIZE); |
| 519 | | m_h1_pal = auto_alloc_array_clear(machine(), UINT16, VRAM_SIZE); |
| 520 | | |
| 521 | | save_pointer(NAME(m_h1_vram), VRAM_SIZE); |
| 522 | | save_pointer(NAME(m_h1_pcg), VRAM_SIZE); |
| 523 | | save_pointer(NAME(m_h1_pal), VRAM_SIZE); |
| 535 | machine().gfx[m_gfx_index] = auto_alloc(machine(), gfx_element(machine(), h1_tile_layout, m_h1_pcg, 8, 0)); |
| 524 | 536 | } |
| 525 | 537 | |
| 526 | 538 | // might be a page 'map / base' setup somewhere, but it's just used for ingame backgrounds |
| r21418 | r21419 | |
| 532 | 544 | /* planes seems to basically be at 0x8000 and 0x28000... */ |
| 533 | 545 | #if 1 |
| 534 | 546 | UINT32 base_offset; |
| 535 | | int xsrc,ysrc,ydst,xdst; |
| 536 | | int xisrc,yisrc; |
| 537 | 547 | int tile,color; |
| 538 | 548 | int scrollx; |
| 539 | 549 | int scrolly; |
| 540 | | #define xsize_mask 2048-1 |
| 541 | | #define ysize_mask 1024-1 |
| 542 | | #define xsize 128 |
| 543 | | #define xi_size 16 |
| 544 | | #define yi_size 16 |
| 545 | | #define xi_mask xi_size-1 |
| 546 | | #define yi_mask yi_size-1 |
| 547 | | UINT32 src_offs,pcg_offs; |
| 550 | gfx_element *gfx = machine().gfx[m_gfx_index]; |
| 548 | 551 | |
| 549 | 552 | scrollx = (m_framebuffer_vram[(0x9bac+which*0x40)/4] >> 16) & 0x7ff; |
| 550 | 553 | scrolly = m_framebuffer_vram[(0x9bac+which*0x40)/4] & 0x3ff; |
| 551 | 554 | |
| 552 | | base_offset = which * 0x20000; |
| 553 | | m_color = which * 2; |
| 555 | base_offset = (which * 0x20000)/2; |
| 556 | m_color_bank = which * 2; |
| 554 | 557 | |
| 555 | | // drawgfx was a lot faster, and I think can handle what we need, even if there |
| 556 | | // are RGB effects I think it will be cheaper to manipulate the palette... |
| 557 | | for(ydst=cliprect.min_y;ydst<=cliprect.max_y;ydst++) |
| 558 | | { |
| 559 | | for(xdst=cliprect.min_x;xdst<=cliprect.max_x;xdst++) |
| 560 | | { |
| 561 | | UINT16 cur_tile; |
| 562 | | UINT16 dot_data,pal_data; |
| 563 | | int r,g,b; |
| 558 | for (int y=0;y<64;y++) |
| 559 | { |
| 560 | for (int x=0;x<128;x++) |
| 561 | { |
| 562 | int res_x,res_y; |
| 564 | 563 | |
| 565 | | /* base tile scrolling */ |
| 566 | | xsrc = ((xdst + scrollx) & (xsize_mask)) >> 4; |
| 567 | | ysrc = ((ydst + scrolly) & (ysize_mask)) >> 4; |
| 568 | | /* apply fractional scrolling */ |
| 569 | | xisrc = (xdst + scrollx) & (xi_mask); |
| 570 | | yisrc = (ydst + scrolly) & (yi_mask); |
| 571 | | /* do the tile offset calc */ |
| 572 | | src_offs = (xsrc + (ysrc*xsize)); |
| 573 | | src_offs += base_offset; |
| 564 | res_x = (x*16)-scrollx; |
| 565 | res_y = (y*16)-scrolly; |
| 574 | 566 | |
| 575 | | /* fetch tilemap data */ |
| 576 | | cur_tile = m_h1_vram[src_offs]; |
| 567 | tile = (m_h1_vram[x+y*128+base_offset] & 0x0fff); |
| 568 | color = m_color_bank + ((tile & 0x800) >> 11) * 4; |
| 577 | 569 | |
| 578 | | /* split proper tile reading and apply color too */ |
| 579 | | tile = cur_tile & 0x07ff; |
| 580 | | color = m_color + ((cur_tile & 0x0800) >> 11) * 4; |
| 581 | | |
| 582 | | /* we have a tile number, fetch the PCG RAM */ |
| 583 | | pcg_offs = (xisrc+yisrc*xi_size)+tile*xi_size*yi_size; |
| 584 | | /* the dot offset calculation */ |
| 585 | | dot_data = m_h1_pcg[pcg_offs/2]; |
| 586 | | dot_data>>= ((pcg_offs & 1) ^ 1) * 8; |
| 587 | | dot_data&= 0xff; |
| 588 | | dot_data+= color<<8; |
| 589 | | |
| 590 | | /* finally, take the palette data (TODO: apply RGB control) */ |
| 591 | | pal_data = m_h1_pal[dot_data]; |
| 592 | | r = pal5bit((pal_data >> 10) & 0x1f); |
| 593 | | g = pal5bit((pal_data >> 5) & 0x1f); |
| 594 | | b = pal5bit((pal_data >> 0) & 0x1f); |
| 595 | | |
| 596 | | /* put on the screen */ |
| 597 | | bitmap.pix32(ydst, xdst) = r<<16 | g<<8 | b; |
| 570 | drawgfx_opaque(bitmap,cliprect,gfx,tile & 0x7ff,color,0,0,res_x,res_y); |
| 571 | drawgfx_opaque(bitmap,cliprect,gfx,tile & 0x7ff,color,0,0,res_x+2048,res_y); |
| 572 | drawgfx_opaque(bitmap,cliprect,gfx,tile & 0x7ff,color,0,0,res_x,res_y+1024); |
| 573 | drawgfx_opaque(bitmap,cliprect,gfx,tile & 0x7ff,color,0,0,res_x+2048,res_y+1024); |
| 598 | 574 | } |
| 599 | 575 | } |
| 576 | |
| 600 | 577 | #endif |
| 601 | 578 | if (which==0) |
| 602 | 579 | { |
| r21418 | r21419 | |
| 626 | 603 | |
| 627 | 604 | |
| 628 | 605 | |
| 629 | | /* According to Guru, this is actually the same I/O chip of Sega Model 2 HW */ |
| 630 | | #if 0 |
| 631 | | READ32_MEMBER(coolridr_state::sysh1_ioga_r) |
| 632 | | { |
| 633 | | //return machine().rand();//h1_ioga[offset]; |
| 634 | | return h1_ioga[offset]; |
| 635 | | } |
| 636 | 606 | |
| 637 | | WRITE32_MEMBER(coolridr_state::sysh1_ioga_w) |
| 638 | | { |
| 639 | | COMBINE_DATA(&h1_ioga[offset]); |
| 640 | | } |
| 641 | | #endif |
| 642 | | |
| 643 | 607 | struct cool_render_object |
| 644 | 608 | { |
| 645 | 609 | UINT8* indirect_tiles; |
| r21418 | r21419 | |
| 836 | 800 | { |
| 837 | 801 | cool_render_object *object = reinterpret_cast<cool_render_object *>(param); |
| 838 | 802 | bitmap_rgb32* drawbitmap = object->drawbitmap; |
| 839 | | |
| 803 | |
| 840 | 804 | UINT16* rearranged_16bit_gfx = object->state->m_rearranged_16bit_gfx; |
| 841 | 805 | UINT16* expanded_10bit_gfx = object->state->m_expanded_10bit_gfx; |
| 842 | | |
| 843 | 806 | |
| 844 | 807 | |
| 808 | |
| 845 | 809 | /************* object->spriteblit[1] *************/ |
| 846 | 810 | |
| 847 | 811 | // 000u0ccc - c = colour? u = 0/1 |
| r21418 | r21419 | |
| 862 | 826 | { |
| 863 | 827 | // b1colorNumber = space.machine().rand()&0xfff; |
| 864 | 828 | } |
| 865 | | |
| 866 | 829 | |
| 830 | |
| 867 | 831 | // if(b1colorNumber > 0x60 || b2colorNumber) |
| 868 | 832 | // printf("%08x %08x\n",b1colorNumber,b2colorNumber); |
| 869 | 833 | |
| r21418 | r21419 | |
| 895 | 859 | UINT32 blit4_unused = object->spriteblit[4] & 0xf8fefefe; |
| 896 | 860 | //UINT32 blit4 = (object->spriteblit[4] & 0x07000000)>>24; |
| 897 | 861 | //object->zpri = 7-blit4; |
| 898 | | |
| 862 | |
| 899 | 863 | UINT32 blit_flipx = object->spriteblit[4] & 0x00000001; |
| 900 | 864 | UINT32 blit_flipy = (object->spriteblit[4] & 0x00000100)>>8; |
| 901 | 865 | UINT32 blit_rotate = (object->spriteblit[4] & 0x00010000)>>16; |
| r21418 | r21419 | |
| 1189 | 1153 | // these should be 'cell numbers' (tile numbers) which look up RLE data? |
| 1190 | 1154 | UINT32 spriteNumber = (expanded_10bit_gfx[ (b3romoffset) + (lookupnum<<1) +0 ] << 10) | (expanded_10bit_gfx[ (b3romoffset) + (lookupnum<<1) + 1 ]); |
| 1191 | 1155 | UINT16 tempshape[16*16]; |
| 1192 | | |
| 1156 | |
| 1193 | 1157 | int color_offs = (0x7b20 + (b1colorNumber & 0x7ff))*0x40 * 5; /* yes, * 5 */ |
| 1194 | 1158 | UINT16 blankcount = 256; |
| 1195 | | |
| 1159 | |
| 1196 | 1160 | if (used_flipy) |
| 1197 | 1161 | { |
| 1198 | 1162 | if (used_flipx) |
| r21418 | r21419 | |
| 1353 | 1317 | } // end no indirect zoom |
| 1354 | 1318 | } |
| 1355 | 1319 | } |
| 1356 | | |
| 1357 | 1320 | |
| 1358 | 1321 | |
| 1322 | |
| 1359 | 1323 | end: |
| 1360 | 1324 | |
| 1361 | 1325 | if (object->indirect_tiles) |
| r21418 | r21419 | |
| 1482 | 1446 | testobject->state = this; |
| 1483 | 1447 | |
| 1484 | 1448 | for (int i=0;i<12;i++) |
| 1485 | | testobject->spriteblit[i] = m_spriteblit[i]; |
| 1449 | testobject->spriteblit[i] = m_spriteblit[i]; |
| 1486 | 1450 | |
| 1487 | 1451 | // cache some values that are looked up from RAM to be safe.. alternatively we could stall the rendering if they get written to, but they're a direct memory pointer.. |
| 1488 | 1452 | int test_indirect_tile_enable = (m_spriteblit[5] & 0x00010000)>>16; |
| r21418 | r21419 | |
| 1507 | 1471 | int test_indirect_zoom_enable = (m_spriteblit[5] & 0x00000001); |
| 1508 | 1472 | if (test_indirect_zoom_enable) |
| 1509 | 1473 | { |
| 1510 | | UINT32 test_blit10 = m_spriteblit[10]; |
| 1474 | UINT32 test_blit10 = m_spriteblit[10]; |
| 1511 | 1475 | UINT16 test_vCellCount = (m_spriteblit[6] & 0x03ff0000) >> 16; |
| 1512 | 1476 | int bytes = test_vCellCount * 4 * 16; |
| 1513 | 1477 | testobject->indirect_zoom = (UINT32*)malloc(bytes); |
| r21418 | r21419 | |
| 1519 | 1483 | else |
| 1520 | 1484 | { |
| 1521 | 1485 | testobject->indirect_zoom = NULL; |
| 1522 | | } |
| 1486 | } |
| 1523 | 1487 | |
| 1524 | 1488 | testobject->zpri = m_blitterAddr | m_blittype<<12; |
| 1525 | 1489 | testobject->blittype = m_blittype; |
| r21418 | r21419 | |
| 1819 | 1783 | } |
| 1820 | 1784 | |
| 1821 | 1785 | |
| 1786 | void coolridr_state::flush_pal_data( UINT16 offset ) |
| 1787 | { |
| 1788 | int r,g,b; |
| 1789 | r = ((m_h1_pal[offset] & 0x7c00) >> 10); |
| 1790 | g = ((m_h1_pal[offset] & 0x03e0) >> 5); |
| 1791 | b = ((m_h1_pal[offset] & 0x001f) >> 0); |
| 1792 | palette_set_color_rgb(machine(),offset,pal5bit(r),pal5bit(g),pal5bit(b)); |
| 1793 | } |
| 1822 | 1794 | |
| 1823 | | |
| 1824 | 1795 | void coolridr_state::sysh1_dma_transfer( address_space &space, UINT16 dma_index ) |
| 1825 | 1796 | { |
| 1826 | 1797 | UINT32 src = 0,dst = 0,size = 0; |
| 1827 | 1798 | UINT8 end_dma_mark; |
| 1828 | 1799 | UINT8 cmd; |
| 1829 | | UINT8 is_dma; |
| 1830 | | UINT16 *dst_ptr; |
| 1831 | 1800 | |
| 1832 | 1801 | end_dma_mark = 0; |
| 1833 | 1802 | |
| 1834 | 1803 | do{ |
| 1835 | 1804 | cmd = (m_framebuffer_vram[(0+dma_index)/4] & 0xfc000000) >> 24; |
| 1836 | 1805 | |
| 1837 | | is_dma = 0; |
| 1838 | 1806 | |
| 1839 | 1807 | switch(cmd) |
| 1840 | 1808 | { |
| r21418 | r21419 | |
| 1846 | 1814 | src = (m_framebuffer_vram[(0+dma_index)/4] & 0x03ffffff); |
| 1847 | 1815 | dst = (m_framebuffer_vram[(4+dma_index)/4]); |
| 1848 | 1816 | size = m_framebuffer_vram[(8+dma_index)/4]; |
| 1849 | | if(dst & 0xfff00000) |
| 1817 | if(dst & 0xfff00001) |
| 1850 | 1818 | printf("unk values to %02x dst %08x\n",cmd,dst); |
| 1851 | | dst_ptr = m_h1_vram; |
| 1852 | 1819 | dst &= 0x000ffffe; |
| 1853 | 1820 | dst >>= 1; |
| 1854 | | is_dma = 1; |
| 1821 | |
| 1822 | for(int i=0;i<size;i+=2) |
| 1823 | { |
| 1824 | m_h1_vram[dst] = space.read_word(src); |
| 1825 | dst++; |
| 1826 | src+=2; |
| 1827 | } |
| 1828 | |
| 1855 | 1829 | dma_index+=0xc; |
| 1856 | 1830 | break; |
| 1857 | 1831 | |
| r21418 | r21419 | |
| 1861 | 1835 | size = m_framebuffer_vram[(8+dma_index)/4]; |
| 1862 | 1836 | if(dst & 0xfff00000) |
| 1863 | 1837 | printf("unk values to %02x dst %08x\n",cmd,dst); |
| 1864 | | dst_ptr = m_h1_pcg; |
| 1865 | | dst &= 0x000ffffe; |
| 1866 | | dst >>= 1; |
| 1867 | | is_dma = 1; |
| 1838 | dst &= 0x000fffff; |
| 1839 | |
| 1840 | /* TODO: might as well improve the dirty handling */ |
| 1841 | for(int i=0;i<size;i++) |
| 1842 | { |
| 1843 | m_h1_pcg[dst] = space.read_byte(src); |
| 1844 | machine().gfx[m_gfx_index]->mark_dirty(dst/256); |
| 1845 | dst++; |
| 1846 | src++; |
| 1847 | } |
| 1848 | |
| 1868 | 1849 | dma_index+=0xc; |
| 1869 | 1850 | break; |
| 1870 | 1851 | |
| r21418 | r21419 | |
| 1873 | 1854 | dst = (m_framebuffer_vram[(4+dma_index)/4]); |
| 1874 | 1855 | size = m_framebuffer_vram[(8+dma_index)/4]; |
| 1875 | 1856 | /* Note: there are also some reads at 0x3e00000. This tells us that the DMA thing actually mirrors at 0x3c00000 too. */ |
| 1876 | | if(dst & 0xfff00000) |
| 1857 | if(dst & 0xfff00001) |
| 1877 | 1858 | printf("unk values to %02x dst %08x\n",cmd,dst); |
| 1878 | | dst_ptr = m_h1_pal; |
| 1879 | 1859 | dst &= 0x000ffffe; |
| 1880 | 1860 | dst >>= 1; |
| 1881 | | is_dma = 1; |
| 1861 | |
| 1862 | for(int i=0;i<size;i+=2) |
| 1863 | { |
| 1864 | m_h1_pal[dst] = space.read_word(src); |
| 1865 | flush_pal_data(dst); |
| 1866 | dst++; |
| 1867 | src+=2; |
| 1868 | } |
| 1869 | |
| 1882 | 1870 | dma_index+=0xc; |
| 1883 | 1871 | break; |
| 1884 | 1872 | |
| r21418 | r21419 | |
| 1901 | 1889 | break; |
| 1902 | 1890 | } |
| 1903 | 1891 | |
| 1904 | | if(is_dma) |
| 1905 | | { |
| 1906 | | for(int i=0;i<size;i+=2) |
| 1907 | | { |
| 1908 | | dst_ptr[dst] = space.read_word(src); |
| 1909 | | dst++; |
| 1910 | | src+=2; |
| 1911 | | } |
| 1912 | | } |
| 1913 | | |
| 1914 | 1892 | }while(!end_dma_mark ); |
| 1915 | 1893 | } |
| 1916 | 1894 | |
| r21418 | r21419 | |
| 2123 | 2101 | |
| 2124 | 2102 | |
| 2125 | 2103 | |
| 2126 | | static const gfx_layout tiles16x16_layout = |
| 2127 | | { |
| 2128 | | 16,16, |
| 2129 | | RGN_FRAC(1,1), |
| 2130 | | 8, |
| 2131 | | { 0, 1, 2, 3, 4, 5, 6, 7 }, |
| 2132 | | { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 }, |
| 2133 | | { 0*128, 1*128, 2*128, 3*128, 4*128, 5*128, 6*128, 7*128, 8*128, 9*128, 10*128, 11*128, 12*128, 13*128, 14*128, 15*128 }, |
| 2134 | | 16*128 |
| 2135 | | }; |
| 2136 | 2104 | |
| 2137 | 2105 | |
| 2138 | 2106 | static GFXDECODE_START( coolridr ) |
| 2139 | | GFXDECODE_ENTRY( "ram_gfx", 0, tiles16x16_layout, 0, 0x100 ) |
| 2107 | // GFXDECODE_ENTRY( NULL, 0, tiles16x16_layout, 0, 0x100 ) |
| 2140 | 2108 | GFXDECODE_END |
| 2141 | 2109 | |
| 2142 | 2110 | static INPUT_PORTS_START( coolridr ) |
| r21418 | r21419 | |
| 2602 | 2570 | } |
| 2603 | 2571 | } |
| 2604 | 2572 | |
| 2573 | m_h1_vram = auto_alloc_array_clear(machine(), UINT16, VRAM_SIZE); |
| 2574 | m_h1_pcg = auto_alloc_array_clear(machine(), UINT8, VRAM_SIZE); |
| 2575 | m_h1_pal = auto_alloc_array_clear(machine(), UINT16, VRAM_SIZE); |
| 2576 | |
| 2577 | save_pointer(NAME(m_h1_vram), VRAM_SIZE); |
| 2578 | save_pointer(NAME(m_h1_pcg), VRAM_SIZE); |
| 2579 | save_pointer(NAME(m_h1_pal), VRAM_SIZE); |
| 2605 | 2580 | } |
| 2606 | 2581 | |
| 2607 | 2582 | void coolridr_state::machine_reset() |
| r21418 | r21419 | |
| 2741 | 2716 | ROM_LOAD32_WORD_SWAP( "mp17656.17", 0x0c00002, 0x0200000, CRC(945c89e3) SHA1(8776d74f73898d948aae3c446d7c710ad0407603) ) |
| 2742 | 2717 | ROM_LOAD32_WORD_SWAP( "mp17657.18", 0x0c00000, 0x0200000, CRC(74676b1f) SHA1(b4a9003a052bde93bebfa4bef9e8dff65003c3b2) ) |
| 2743 | 2718 | |
| 2744 | | ROM_REGION32_BE( 0x100000, "ram_gfx", ROMREGION_ERASE00 ) /* SH2 code */ |
| 2745 | | |
| 2746 | 2719 | ROM_REGION( 0x100000, "soundcpu", ROMREGION_ERASE00 ) /* 68000 */ |
| 2747 | 2720 | |
| 2748 | 2721 | ROM_REGION( 0x100000, "sub", 0 ) /* SH1 */ |