trunk/src/mame/drivers/gunpey.c
| r21563 | r21564 | |
| 224 | 224 | UINT16 m_vram_bank; |
| 225 | 225 | UINT16 m_vreg_addr; |
| 226 | 226 | |
| 227 | | //UINT16 main_vram[0x800][0x800]; |
| 227 | UINT8* m_blit_rom; |
| 228 | UINT8* m_vram; |
| 229 | |
| 230 | // work variables for the decompression |
| 231 | int m_srcx; |
| 232 | int m_srcxbase; |
| 233 | int m_scrxcount; |
| 234 | int m_srcy; |
| 235 | int m_srcycount; |
| 236 | UINT8 m_sourcewide; |
| 237 | int m_ysize; |
| 238 | int m_xsize; |
| 239 | int m_dstx; |
| 240 | int m_dsty; |
| 241 | int m_dstxbase; |
| 242 | int m_dstxcount; |
| 243 | int m_dstycount; |
| 244 | |
| 245 | int m_latched_bits_left; |
| 246 | UINT8 m_latched_byte; |
| 247 | int m_zero_bit_count; |
| 248 | |
| 249 | void get_stream_next_byte(void); |
| 250 | int get_steam_bit(void); |
| 251 | UINT32 gunpey_state_get_stream_bits(int bits); |
| 252 | |
| 253 | int write_dest_byte(UINT8 usedata); |
| 254 | //UINT16 main_m_vram[0x800][0x800]; |
| 228 | 255 | }; |
| 229 | 256 | |
| 230 | 257 | |
| r21563 | r21564 | |
| 238 | 265 | int x,y; |
| 239 | 266 | int bpp_sel; |
| 240 | 267 | int color; |
| 241 | | UINT8 *vram = memregion("vram")->base(); |
| 242 | 268 | |
| 243 | 269 | // there doesn't seem to be a specific bit to mark compressed sprites (we currently have a hack to look at the first byte of the data) |
| 244 | 270 | // do they get decompressed at blit time instead? of are there other registers we need to look at |
| r21563 | r21564 | |
| 291 | 317 | // xsource<<=1; |
| 292 | 318 | // ysource <<=2; |
| 293 | 319 | |
| 294 | | // UINT8 testhack = vram[((((ysource+0)&0x7ff)*0x800) + ((xsource+0)&0x7ff))]; |
| 295 | | // UINT8 testhack2 = vram[((((ysource+0)&0x7ff)*0x800) + ((xsource+1)&0x7ff))]; |
| 320 | // UINT8 testhack = m_vram[((((ysource+0)&0x7ff)*0x800) + ((xsource+0)&0x7ff))]; |
| 321 | // UINT8 testhack2 = m_vram[((((ysource+0)&0x7ff)*0x800) + ((xsource+1)&0x7ff))]; |
| 296 | 322 | |
| 297 | 323 | //if (m_wram[count+1] & 0x0010) |
| 298 | 324 | // color = machine.rand()&0xf; |
| r21563 | r21564 | |
| 330 | 356 | { |
| 331 | 357 | for(int xi=0;xi<sourcewidth/2;xi++) |
| 332 | 358 | { |
| 333 | | UINT8 data = vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))]; |
| 359 | UINT8 data = m_vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))]; |
| 334 | 360 | UINT8 pix; |
| 335 | 361 | UINT32 col_offs; |
| 336 | 362 | UINT16 color_data; |
| r21563 | r21564 | |
| 338 | 364 | pix = (data & 0x0f); |
| 339 | 365 | col_offs = ((pix + color*0x10) & 0xff) << 1; |
| 340 | 366 | col_offs+= ((pix + color*0x10) >> 8)*0x800; |
| 341 | | color_data = (vram[col_offs])|(vram[col_offs+1]<<8); |
| 367 | color_data = (m_vram[col_offs])|(m_vram[col_offs+1]<<8); |
| 342 | 368 | |
| 343 | 369 | if(!(color_data & 0x8000)) |
| 344 | 370 | { |
| r21563 | r21564 | |
| 366 | 392 | pix = (data & 0xf0)>>4; |
| 367 | 393 | col_offs = ((pix + color*0x10) & 0xff) << 1; |
| 368 | 394 | col_offs+= ((pix + color*0x10) >> 8)*0x800; |
| 369 | | color_data = (vram[col_offs])|(vram[col_offs+1]<<8); |
| 395 | color_data = (m_vram[col_offs])|(m_vram[col_offs+1]<<8); |
| 370 | 396 | |
| 371 | 397 | if(!(color_data & 0x8000)) |
| 372 | 398 | { |
| r21563 | r21564 | |
| 401 | 427 | { |
| 402 | 428 | for(int xi=0;xi<sourcewidth;xi++) |
| 403 | 429 | { |
| 404 | | UINT8 data = vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))]; |
| 430 | UINT8 data = m_vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))]; |
| 405 | 431 | UINT8 pix; |
| 406 | 432 | UINT32 col_offs; |
| 407 | 433 | UINT16 color_data; |
| r21563 | r21564 | |
| 419 | 445 | { |
| 420 | 446 | for(int xi=0;xi<sourcewidth;xi++) |
| 421 | 447 | { |
| 422 | | UINT8 data = vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))]; |
| 448 | UINT8 data = m_vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))]; |
| 423 | 449 | UINT8 pix; |
| 424 | 450 | UINT32 col_offs; |
| 425 | 451 | UINT16 color_data; |
| r21563 | r21564 | |
| 427 | 453 | pix = (data & 0xff); |
| 428 | 454 | col_offs = ((pix + color*0x100) & 0xff) << 1; |
| 429 | 455 | col_offs+= ((pix + color*0x100) >> 8)*0x800; |
| 430 | | color_data = (vram[col_offs])|(vram[col_offs+1]<<8); |
| 456 | color_data = (m_vram[col_offs])|(m_vram[col_offs+1]<<8); |
| 431 | 457 | |
| 432 | 458 | if(!(color_data & 0x8000)) |
| 433 | 459 | { |
| r21563 | r21564 | |
| 565 | 591 | gunpey_irq_check(4); |
| 566 | 592 | } |
| 567 | 593 | |
| 594 | void gunpey_state::get_stream_next_byte(void) |
| 595 | { |
| 596 | // check if we need to move on to the next row of the source bitmap |
| 597 | // to get the data requested |
| 598 | if (m_scrxcount==m_sourcewide) |
| 599 | { |
| 600 | m_scrxcount = 0; |
| 601 | m_srcx = m_srcxbase; |
| 602 | m_srcy++; m_srcycount++; |
| 603 | } |
| 604 | |
| 605 | m_latched_byte = m_blit_rom[(((m_srcy)&0x7ff)*0x800)+((m_srcx)&0x7ff)]; |
| 606 | m_latched_bits_left = 8; |
| 607 | |
| 608 | // increase counters |
| 609 | m_srcx++; m_scrxcount++; |
| 610 | } |
| 611 | |
| 612 | int gunpey_state::get_steam_bit(void) |
| 613 | { |
| 614 | if (m_latched_bits_left==0) |
| 615 | { |
| 616 | get_stream_next_byte(); |
| 617 | } |
| 618 | |
| 619 | m_latched_bits_left--; |
| 620 | |
| 621 | int bit = (m_latched_byte >> (7-m_latched_bits_left))&1; |
| 622 | |
| 623 | if (bit==0) m_zero_bit_count++; |
| 624 | else m_zero_bit_count=0; |
| 625 | |
| 626 | return bit; |
| 627 | } |
| 628 | |
| 629 | UINT32 gunpey_state::gunpey_state_get_stream_bits(int bits) |
| 630 | { |
| 631 | UINT32 output = 0; |
| 632 | for (int i=0;i<bits;i++) |
| 633 | { |
| 634 | output = output<<1; |
| 635 | output |= get_steam_bit(); |
| 636 | } |
| 637 | |
| 638 | return output; |
| 639 | } |
| 640 | |
| 641 | int gunpey_state::write_dest_byte(UINT8 usedata) |
| 642 | { |
| 643 | // write the byte we and to destination and increase our counters |
| 644 | m_vram[(((m_dsty)&0x7ff)*0x800)+((m_dstx)&0x7ff)] = usedata; |
| 645 | |
| 646 | // increase destination counter and check if we've filled our destination rectangle |
| 647 | m_dstx++; m_dstxcount++; |
| 648 | if (m_dstxcount==m_xsize) |
| 649 | { |
| 650 | m_dstxcount = 0; |
| 651 | m_dstx = m_dstxbase; |
| 652 | m_dsty++; m_dstycount++; |
| 653 | if (m_dstycount==m_ysize) |
| 654 | { |
| 655 | return -1; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | return 1; |
| 660 | } |
| 661 | |
| 662 | |
| 568 | 663 | //#define SHOW_COMPRESSED_DATA_DEBUG |
| 569 | 664 | |
| 665 | |
| 666 | |
| 570 | 667 | WRITE8_MEMBER(gunpey_state::gunpey_blitter_w) |
| 571 | 668 | { |
| 572 | 669 | // UINT16 *blit_buffer = m_blit_buffer; |
| 573 | 670 | UINT16 *blit_ram = m_blit_ram; |
| 574 | | UINT8 *blit_rom = memregion("blit_data")->base(); |
| 575 | | UINT8 *vram = memregion("vram")->base(); |
| 576 | 671 | |
| 672 | |
| 577 | 673 | // int x,y; |
| 578 | 674 | |
| 579 | 675 | //printf("gunpey_blitter_w offset %01x data %02x\n", offset,data); |
| r21563 | r21564 | |
| 582 | 678 | |
| 583 | 679 | if(offset == 0 && data == 2) // blitter trigger, 0->1 transition |
| 584 | 680 | { |
| 585 | | int srcx = blit_ram[0x04]+(blit_ram[0x05]<<8); |
| 586 | | int srcy = blit_ram[0x06]+(blit_ram[0x07]<<8); |
| 587 | | int dstx = blit_ram[0x08]+(blit_ram[0x09]<<8); |
| 588 | | int dsty = blit_ram[0x0a]+(blit_ram[0x0b]<<8); |
| 589 | | int xsize = blit_ram[0x0c]+1; |
| 590 | | int ysize = blit_ram[0x0e]+1; |
| 681 | m_srcx = blit_ram[0x04]+(blit_ram[0x05]<<8); |
| 682 | m_srcy = blit_ram[0x06]+(blit_ram[0x07]<<8); |
| 683 | m_dstx = blit_ram[0x08]+(blit_ram[0x09]<<8); |
| 684 | m_dsty = blit_ram[0x0a]+(blit_ram[0x0b]<<8); |
| 685 | m_xsize = blit_ram[0x0c]+1; |
| 686 | m_ysize = blit_ram[0x0e]+1; |
| 591 | 687 | int rle = blit_ram[0x01]; |
| 592 | 688 | // int color,color_offs; |
| 593 | 689 | |
| r21563 | r21564 | |
| 596 | 692 | ,blit_ram[0],blit_ram[1],blit_ram[2],blit_ram[3] |
| 597 | 693 | |
| 598 | 694 | |
| 599 | | ,blit_ram[4],blit_ram[5], srcx |
| 600 | | ,blit_ram[6],blit_ram[7], srcy |
| 695 | ,blit_ram[4],blit_ram[5], m_srcx |
| 696 | ,blit_ram[6],blit_ram[7], m_srcy |
| 601 | 697 | |
| 602 | | ,blit_ram[8],blit_ram[9], dstx |
| 603 | | ,blit_ram[0xa],blit_ram[0xb], dsty |
| 698 | ,blit_ram[8],blit_ram[9], m_dstx |
| 699 | ,blit_ram[0xa],blit_ram[0xb], m_dsty |
| 604 | 700 | ,blit_ram[0xc], |
| 605 | 701 | |
| 606 | 702 | blit_ram[0xd],blit_ram[0xe],blit_ram[0xf]); |
| 607 | 703 | */ |
| 608 | | //if (srcx & 0xf800) printf("(error srcx &0xf800)"); |
| 609 | | //if (srcy & 0xf800) printf("(error srcy &0xf800)"); |
| 704 | //if (m_srcx & 0xf800) printf("(error m_srcx &0xf800)"); |
| 705 | //if (m_srcy & 0xf800) printf("(error m_srcy &0xf800)"); |
| 610 | 706 | |
| 611 | 707 | // these are definitely needed for 4bpp.. |
| 612 | | dstx<<=1; |
| 613 | | xsize<<=1; |
| 708 | m_dstx<<=1; |
| 709 | m_xsize<<=1; |
| 614 | 710 | |
| 615 | 711 | |
| 616 | 712 | //int color = space.machine().rand()&0x1f; |
| r21563 | r21564 | |
| 652 | 748 | |
| 653 | 749 | */ |
| 654 | 750 | |
| 751 | |
| 655 | 752 | if(rle) |
| 656 | 753 | { |
| 657 | 754 | if(rle == 8) |
| r21563 | r21564 | |
| 672 | 769 | const int show_bytes = 0; |
| 673 | 770 | int bitspacer = 0; |
| 674 | 771 | int bitspace = 9; |
| 772 | int linespacer = 0; |
| 675 | 773 | #endif |
| 676 | 774 | |
| 677 | 775 | |
| 678 | | int dstxbase = dstx; |
| 679 | | int dstwcount = 0; |
| 680 | | int dstycount = 0; |
| 681 | | int srcxbase = srcx; |
| 682 | | int srcwcount = 0; |
| 683 | | int srcycount = 0; |
| 776 | m_dstxbase = m_dstx; |
| 777 | m_dstxcount = 0; |
| 778 | m_dstycount = 0; |
| 779 | m_srcxbase = m_srcx; |
| 780 | m_scrxcount = 0; |
| 781 | m_srcycount = 0; |
| 684 | 782 | |
| 685 | | UINT8 sourcewide = blit_rom[(((srcy)&0x7ff)*0x800)+((srcx)&0x7ff)]; |
| 686 | | srcx++;srcwcount++; // we don't want to decode the width as part of the data stream.. |
| 687 | | UINT8 lastdata = 0xff; // hack so we can bail when we appear to have run out of compressed data |
| 783 | m_sourcewide = m_blit_rom[(((m_srcy)&0x7ff)*0x800)+((m_srcx)&0x7ff)]+1; |
| 784 | m_srcx++;m_scrxcount++; // we don't want to decode the width as part of the data stream.. |
| 785 | m_latched_bits_left = 0; |
| 786 | m_zero_bit_count = 0; |
| 787 | |
| 788 | int lastdata = 0xff; // hack so we can bail when we appear to have run out of compressed data |
| 688 | 789 | bool out_of_data = false; |
| 689 | 790 | |
| 690 | 791 | for (;;) |
| 691 | 792 | { |
| 692 | | UINT8 data = blit_rom[(((srcy)&0x7ff)*0x800)+((srcx)&0x7ff)]; |
| 693 | 793 | |
| 794 | int data = gunpey_state_get_stream_bits(8); |
| 795 | |
| 694 | 796 | // hack, really I imagine there is exactly enough compressed data to fill the dest bitmap area when decompressed, but to stop us |
| 695 | 797 | // overrunning into reading other data we terminate on a 0000, which doesn't seem likely to be compressed data. |
| 696 | 798 | if (data==0x00 && lastdata == 0x00) |
| r21563 | r21564 | |
| 698 | 800 | |
| 699 | 801 | lastdata = data; |
| 700 | 802 | |
| 803 | |
| 804 | UINT8 usedata = 0xff; |
| 701 | 805 | if (!out_of_data) |
| 702 | 806 | { |
| 703 | 807 | #ifdef SHOW_COMPRESSED_DATA_DEBUG |
| 704 | | if (count<256) |
| 705 | | { |
| 808 | if (count<512) |
| 809 | { |
| 810 | |
| 811 | |
| 706 | 812 | if (show_bytes) |
| 707 | 813 | { |
| 708 | 814 | printf("%02x ", data); |
| 709 | 815 | } |
| 710 | 816 | else |
| 711 | 817 | { |
| 712 | | //data = BITSWAP8(data,7,6,5,4,3,2,1,0); |
| 713 | | data = BITSWAP8(data,0,1,2,3,4,5,6,7); |
| 714 | 818 | for (int z=0;z<8;z++) |
| 715 | 819 | { |
| 716 | 820 | printf("%d", (data>>(7-z))&1); |
| 717 | 821 | bitspacer++; |
| 718 | 822 | if (bitspacer == bitspace) |
| 719 | 823 | { |
| 824 | linespacer++; |
| 825 | if ((linespacer%16) == 0) printf("\n"); |
| 826 | |
| 720 | 827 | printf(" "); |
| 721 | 828 | bitspacer = 0; |
| 722 | 829 | } |
| r21563 | r21564 | |
| 726 | 833 | } |
| 727 | 834 | #endif |
| 728 | 835 | |
| 729 | | vram[(((dsty)&0x7ff)*0x800)+((dstx)&0x7ff)] = data; |
| 836 | usedata = data; |
| 730 | 837 | } |
| 731 | 838 | else |
| 732 | | vram[(((dsty)&0x7ff)*0x800)+((dstx)&0x7ff)] = 0x44; |
| 839 | usedata = 0x44; |
| 733 | 840 | |
| 734 | | // increase our source counter, taking note of the width of the compressed data in |
| 735 | | // source (it differs from the destination width) |
| 736 | | srcx++; srcwcount++; |
| 737 | | if (srcwcount==sourcewide+1) |
| 738 | | { |
| 739 | | srcwcount = 0; |
| 740 | | srcx = srcxbase; |
| 741 | | srcy++; srcycount++; |
| 742 | | } |
| 841 | if ((write_dest_byte(usedata))==-1) |
| 842 | break; |
| 743 | 843 | |
| 744 | | // increase destination counter and check if we've filled our destination rectangle |
| 745 | | dstx++; dstwcount++; |
| 746 | | if (dstwcount==xsize) |
| 747 | | { |
| 748 | | dstwcount = 0; |
| 749 | | dstx = dstxbase; |
| 750 | | dsty++; dstycount++; |
| 751 | | if (dstycount==ysize) |
| 752 | | { |
| 753 | | break; |
| 754 | | } |
| 755 | | } |
| 756 | 844 | } |
| 757 | 845 | |
| 758 | 846 | #ifdef SHOW_COMPRESSED_DATA_DEBUG |
| r21563 | r21564 | |
| 765 | 853 | } |
| 766 | 854 | else |
| 767 | 855 | { |
| 768 | | int dstxbase = dstx; |
| 769 | | int dstwcount = 0; |
| 770 | | int dstycount = 0; |
| 771 | | int srcxbase = srcx; |
| 772 | | int srcwcount = 0; |
| 773 | | int srcycount = 0; |
| 856 | m_dstxbase = m_dstx; |
| 857 | m_dstxcount = 0; |
| 858 | m_dstycount = 0; |
| 859 | m_srcxbase = m_srcx; |
| 860 | m_scrxcount = 0; |
| 861 | m_srcycount = 0; |
| 774 | 862 | |
| 775 | 863 | for (;;) |
| 776 | 864 | { |
| 777 | | UINT8 data = blit_rom[(((srcy)&0x7ff)*0x800)+((srcx)&0x7ff)]; |
| 778 | | vram[(((dsty)&0x7ff)*0x800)+((dstx)&0x7ff)] = data; |
| 865 | UINT8 usedata = m_blit_rom[(((m_srcy)&0x7ff)*0x800)+((m_srcx)&0x7ff)]; |
| 779 | 866 | |
| 780 | | srcx++; srcwcount++; |
| 781 | | if (srcwcount==xsize) |
| 867 | m_srcx++; m_scrxcount++; |
| 868 | if (m_scrxcount==m_xsize) |
| 782 | 869 | { |
| 783 | | srcwcount = 0; |
| 784 | | srcx = srcxbase; |
| 785 | | srcy++; srcycount++; |
| 870 | m_scrxcount = 0; |
| 871 | m_srcx = m_srcxbase; |
| 872 | m_srcy++; m_srcycount++; |
| 786 | 873 | } |
| 787 | 874 | |
| 788 | | // increase destination counter and check if we've filled our destination rectangle |
| 789 | | dstx++; dstwcount++; |
| 790 | | if (dstwcount==xsize) |
| 791 | | { |
| 792 | | dstwcount = 0; |
| 793 | | dstx = dstxbase; |
| 794 | | dsty++; dstycount++; |
| 795 | | if (dstycount==ysize) |
| 796 | | { |
| 797 | | break; |
| 798 | | } |
| 799 | | } |
| 875 | if ((write_dest_byte(usedata))==-1) |
| 876 | break; |
| 800 | 877 | } |
| 801 | 878 | } |
| 802 | 879 | |
| 803 | | machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(xsize*ysize), timer_expired_delegate(FUNC(gunpey_state::blitter_end),this)); |
| 880 | machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(m_xsize*m_ysize), timer_expired_delegate(FUNC(gunpey_state::blitter_end),this)); |
| 804 | 881 | |
| 805 | 882 | |
| 806 | 883 | /* |
| r21563 | r21564 | |
| 1063 | 1140 | |
| 1064 | 1141 | DRIVER_INIT_MEMBER(gunpey_state,gunpey) |
| 1065 | 1142 | { |
| 1143 | |
| 1144 | m_blit_rom = memregion("blit_data")->base(); |
| 1145 | m_vram = memregion("vram")->base(); |
| 1066 | 1146 | // ... |
| 1067 | 1147 | } |
| 1068 | 1148 | |