src/mess/video/fmtowns.c
| r9237 | r9238 | |
| 102 | 102 | |
| 103 | 103 | //static UINT32 pshift; // for debugging |
| 104 | 104 | |
| 105 | void draw_sprites(running_machine* machine, const rectangle* rect); |
| 106 | |
| 105 | 107 | void towns_crtc_refresh_mode(running_machine* machine) |
| 106 | 108 | { |
| 107 | 109 | towns_state* state = machine->driver_data<towns_state>(); |
| r9237 | r9238 | |
| 415 | 417 | state->video.towns_dpmd_flag = 0; |
| 416 | 418 | ret |= 0x80; |
| 417 | 419 | } |
| 418 | | ret |= (state->video.towns_vblank_flag ? 0x02 : 0x00); // TODO: figure out just what this bit is... |
| 420 | ret |= (state->video.towns_sprite_flag ? 0x02 : 0x00); // Sprite drawing flag |
| 421 | ret |= state->video.towns_sprite_page & 0x01; |
| 419 | 422 | return ret; |
| 420 | 423 | case 0x10: |
| 421 | 424 | return state->video.towns_sprite_sel; |
| r9237 | r9238 | |
| 720 | 723 | int xdir,ydir; |
| 721 | 724 | int width = (state->video.towns_crtc_reg[12] - state->video.towns_crtc_reg[11]) / (((state->video.towns_crtc_reg[27] & 0x0f00) >> 8)+1); |
| 722 | 725 | int height = (state->video.towns_crtc_reg[16] - state->video.towns_crtc_reg[15]) / (((state->video.towns_crtc_reg[27] & 0xf000) >> 12)+1); |
| 723 | | UINT32 vram_start = (state->video.towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 724 | 726 | |
| 725 | 727 | if(xflip) |
| 726 | 728 | { |
| r9237 | r9238 | |
| 756 | 758 | { |
| 757 | 759 | for(xpos=xstart;xpos!=xend;xpos+=xdir,xpos&=0x1ff) |
| 758 | 760 | { |
| 759 | | voffset = 0; |
| 761 | if(state->video.towns_sprite_page != 0) |
| 762 | voffset = 0x20000; |
| 763 | else |
| 764 | voffset = 0x00000; |
| 760 | 765 | pixel = (state->towns_txtvram[poffset] & 0xf0) >> 4; |
| 761 | 766 | col = state->towns_txtvram[coffset+(pixel*2)] | (state->towns_txtvram[coffset+(pixel*2)+1] << 8); |
| 762 | | voffset += (state->video.towns_crtc_reg[24] * 4) * ypos; // scanline size in bytes * y pos |
| 767 | voffset += (state->video.towns_crtc_reg[24] * 4) * (ypos & 0x1ff); // scanline size in bytes * y pos |
| 763 | 768 | voffset += (xpos & 0x1ff) * 2; |
| 764 | 769 | voffset &= 0x3ffff; |
| 765 | | //voffset += (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 766 | 770 | if(xpos < width && ypos < height && pixel != 0) |
| 767 | 771 | { |
| 768 | | state->towns_gfxvram[voffset+vram_start+1] = (col & 0xff00) >> 8; |
| 769 | | state->towns_gfxvram[voffset+vram_start] = col & 0x00ff; |
| 772 | state->towns_gfxvram[0x40000+voffset+1] = (col & 0xff00) >> 8; |
| 773 | state->towns_gfxvram[0x40000+voffset] = col & 0x00ff; |
| 770 | 774 | } |
| 771 | 775 | if(xflip) |
| 772 | 776 | voffset+=2; |
| r9237 | r9238 | |
| 777 | 781 | voffset &= 0x3ffff; |
| 778 | 782 | if(xpos < width && ypos < height && pixel != 0) |
| 779 | 783 | { |
| 780 | | state->towns_gfxvram[voffset+vram_start+1] = (col & 0xff00) >> 8; |
| 781 | | state->towns_gfxvram[voffset+vram_start] = col & 0x00ff; |
| 784 | state->towns_gfxvram[0x40000+voffset+1] = (col & 0xff00) >> 8; |
| 785 | state->towns_gfxvram[0x40000+voffset] = col & 0x00ff; |
| 782 | 786 | } |
| 783 | 787 | poffset++; |
| 784 | 788 | poffset &= 0x1ffff; |
| r9237 | r9238 | |
| 831 | 835 | { |
| 832 | 836 | for(xpos=xstart;xpos!=xend;xpos+=xdir,xpos&=0x1ff) |
| 833 | 837 | { |
| 834 | | voffset = (state->video.towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 838 | if(state->video.towns_sprite_page != 0) |
| 839 | voffset = 0x20000; |
| 840 | else |
| 841 | voffset = 0x00000; |
| 835 | 842 | col = state->towns_txtvram[poffset] | (state->towns_txtvram[poffset+1] << 8); |
| 836 | | voffset += (state->video.towns_crtc_reg[24] * 4) * ypos; // scanline size in bytes * y pos |
| 843 | voffset += (state->video.towns_crtc_reg[24] * 4) * (ypos & 0x1ff); // scanline size in bytes * y pos |
| 837 | 844 | voffset += (xpos & 0x1ff) * 2; |
| 838 | | voffset &= 0x7ffff; |
| 845 | voffset &= 0x3ffff; |
| 839 | 846 | if(xpos < width && ypos < height && col < 0x8000) |
| 840 | 847 | { |
| 841 | | state->towns_gfxvram[voffset+1] = (col & 0xff00) >> 8; |
| 842 | | state->towns_gfxvram[voffset] = col & 0x00ff; |
| 848 | state->towns_gfxvram[0x40000+voffset+1] = (col & 0xff00) >> 8; |
| 849 | state->towns_gfxvram[0x40000+voffset] = col & 0x00ff; |
| 843 | 850 | } |
| 844 | 851 | poffset+=2; |
| 845 | 852 | poffset &= 0x1ffff; |
| r9237 | r9238 | |
| 861 | 868 | return; |
| 862 | 869 | |
| 863 | 870 | // clears VRAM for each frame? |
| 864 | | if(state->video.towns_sprite_reg[6] & 0x10) |
| 871 | if(state->video.towns_sprite_page == 0) |
| 872 | memset(state->towns_gfxvram+0x40000,0x80,0x20000); |
| 873 | else |
| 865 | 874 | memset(state->towns_gfxvram+0x60000,0x80,0x20000); |
| 866 | | else |
| 867 | | memset(state->towns_gfxvram+0x40000,0x80,0x20000); |
| 868 | 875 | |
| 869 | 876 | for(n=sprite_limit;n<1024;n++) |
| 870 | 877 | { |
| r9237 | r9238 | |
| 903 | 910 | render_sprite_16(machine,(poffset)&0x1ffff,x,y,attr&0x2000,attr&0x1000,rect); |
| 904 | 911 | } |
| 905 | 912 | } |
| 913 | |
| 914 | if(state->video.towns_sprite_page == 0) // flip VRAM page |
| 915 | state->video.towns_sprite_page = 1; |
| 916 | else |
| 917 | state->video.towns_sprite_page = 0; |
| 918 | |
| 919 | state->video.towns_sprite_flag = 1; // we are now drawing |
| 920 | timer_adjust_oneshot(state->video.sprite_timer,machine->device<cpu_device>("maincpu")->cycles_to_attotime(16 * (1025-sprite_limit)),0); |
| 906 | 921 | } |
| 907 | 922 | |
| 908 | 923 | void towns_crtc_draw_scan_layer_hicolour(running_machine* machine, bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline) |
| r9237 | r9238 | |
| 922 | 937 | |
| 923 | 938 | if(state->video.towns_display_page_sel != 0) |
| 924 | 939 | off = 0x20000; |
| 940 | |
| 941 | // if((layer == 1) && (state->video.towns_sprite_reg[1] & 0x80) && (state->video.towns_sprite_page == 1)) |
| 942 | // off = 0x20000; |
| 943 | |
| 925 | 944 | if(layer != 0) |
| 926 | 945 | { |
| 927 | 946 | if(!(state->video.towns_video_reg[0] & 0x10)) |
| r9237 | r9238 | |
| 1105 | 1124 | |
| 1106 | 1125 | if(state->video.towns_display_page_sel != 0) |
| 1107 | 1126 | off = 0x20000; |
| 1127 | |
| 1128 | // if((layer == 1) && (state->video.towns_sprite_reg[1] & 0x80) && (state->video.towns_sprite_page == 1)) |
| 1129 | // off = 0x20000; |
| 1130 | |
| 1108 | 1131 | if(layer == 0) |
| 1109 | 1132 | linesize = state->video.towns_crtc_reg[20] * 8; |
| 1110 | 1133 | else |
| r9237 | r9238 | |
| 1272 | 1295 | |
| 1273 | 1296 | if(state->video.towns_display_page_sel != 0) |
| 1274 | 1297 | off = 0x20000; |
| 1298 | |
| 1299 | // if((layer == 1) && (state->video.towns_sprite_reg[1] & 0x80) && (state->video.towns_sprite_page == 1)) |
| 1300 | // off = 0x20000; |
| 1301 | |
| 1275 | 1302 | if(layer == 0) |
| 1276 | 1303 | linesize = state->video.towns_crtc_reg[20] * 4; |
| 1277 | 1304 | else |
| r9237 | r9238 | |
| 1735 | 1762 | } |
| 1736 | 1763 | } |
| 1737 | 1764 | |
| 1765 | static TIMER_CALLBACK( towns_sprite_done ) |
| 1766 | { |
| 1767 | // sprite drawing is complete, lower flag |
| 1768 | towns_state* state = machine->driver_data<towns_state>(); |
| 1769 | state->video.towns_sprite_flag = 0; |
| 1770 | if(state->video.towns_sprite_page != 0) |
| 1771 | state->video.towns_crtc_reg[21] |= 0x8000; |
| 1772 | else |
| 1773 | state->video.towns_crtc_reg[21] &= ~0x8000; |
| 1774 | } |
| 1775 | |
| 1738 | 1776 | static TIMER_CALLBACK( towns_vblank_end ) |
| 1739 | 1777 | { |
| 1740 | 1778 | // here we'll clear the vsync signal, I presume it goes low on it's own eventually |
| r9237 | r9238 | |
| 1755 | 1793 | timer_set(device->machine,device->machine->primary_screen->time_until_vblank_end(),(void*)dev,0,towns_vblank_end); |
| 1756 | 1794 | if(state->video.towns_tvram_enable) |
| 1757 | 1795 | draw_text_layer(dev->machine); |
| 1758 | | if(state->video.towns_sprite_reg[1] & 0x80) // if sprites are enabled, then sprites are drawn on this layer. |
| 1796 | if(state->video.towns_sprite_reg[1] & 0x80) |
| 1759 | 1797 | draw_sprites(dev->machine,&state->video.towns_crtc_layerscr[1]); |
| 1760 | 1798 | } |
| 1761 | 1799 | |
| r9237 | r9238 | |
| 1764 | 1802 | towns_state* state = machine->driver_data<towns_state>(); |
| 1765 | 1803 | |
| 1766 | 1804 | state->video.towns_vram_wplane = 0x00; |
| 1805 | state->video.towns_sprite_page = 0; |
| 1806 | state->video.sprite_timer = timer_alloc(machine,towns_sprite_done,NULL); |
| 1767 | 1807 | } |
| 1768 | 1808 | |
| 1769 | 1809 | VIDEO_UPDATE( towns ) |
| r9237 | r9238 | |
| 1809 | 1849 | |
| 1810 | 1850 | #ifdef CRTC_REG_DISP |
| 1811 | 1851 | popmessage("CRTC: %i %i %i %i %i %i %i %i %i\n%i %i %i %i | %i %i %i %i\n%04x %i %i %i | %04x %i %i %i\nZOOM: %04x\nVideo: %02x %02x\nText=%i Spr=%02x\nReg28=%04x", |
| 1812 | | towns_crtc_reg[0],towns_crtc_reg[1],towns_crtc_reg[2],towns_crtc_reg[3], |
| 1813 | | towns_crtc_reg[4],towns_crtc_reg[5],towns_crtc_reg[6],towns_crtc_reg[7], |
| 1814 | | towns_crtc_reg[8], |
| 1815 | | towns_crtc_reg[9],towns_crtc_reg[10],towns_crtc_reg[11],towns_crtc_reg[12], |
| 1816 | | towns_crtc_reg[13],towns_crtc_reg[14],towns_crtc_reg[15],towns_crtc_reg[16], |
| 1817 | | towns_crtc_reg[17],towns_crtc_reg[18],towns_crtc_reg[19],towns_crtc_reg[20], |
| 1818 | | towns_crtc_reg[21],towns_crtc_reg[22],towns_crtc_reg[23],towns_crtc_reg[24], |
| 1819 | | towns_crtc_reg[27],towns_video_reg[0],towns_video_reg[1],towns_tvram_enable,towns_sprite_reg[1] & 0x80, |
| 1820 | | towns_crtc_reg[28]); |
| 1852 | state->video.towns_crtc_reg[0],state->video.towns_crtc_reg[1],state->video.towns_crtc_reg[2],state->video.towns_crtc_reg[3], |
| 1853 | state->video.towns_crtc_reg[4],state->video.towns_crtc_reg[5],state->video.towns_crtc_reg[6],state->video.towns_crtc_reg[7], |
| 1854 | state->video.towns_crtc_reg[8], |
| 1855 | state->video.towns_crtc_reg[9],state->video.towns_crtc_reg[10],state->video.towns_crtc_reg[11],state->video.towns_crtc_reg[12], |
| 1856 | state->video.towns_crtc_reg[13],state->video.towns_crtc_reg[14],state->video.towns_crtc_reg[15],state->video.towns_crtc_reg[16], |
| 1857 | state->video.towns_crtc_reg[17],state->video.towns_crtc_reg[18],state->video.towns_crtc_reg[19],state->video.towns_crtc_reg[20], |
| 1858 | state->video.towns_crtc_reg[21],state->video.towns_crtc_reg[22],state->video.towns_crtc_reg[23],state->video.towns_crtc_reg[24], |
| 1859 | state->video.towns_crtc_reg[27],state->video.towns_video_reg[0],state->video.towns_video_reg[1],state->video.towns_tvram_enable,state->video.towns_sprite_reg[1] & 0x80, |
| 1860 | state->video.towns_crtc_reg[28]); |
| 1821 | 1861 | #endif |
| 1822 | 1862 | |
| 1823 | 1863 | return 0; |