src/mess/video/fmtowns.c
| r6721 | r6722 | |
| 69 | 69 | * YM (bit 2) - unknown |
| 70 | 70 | * peltype (bits 4 and 5) |
| 71 | 71 | * |
| 72 | * |
| 73 | * Sprite registers: |
| 74 | * |
| 75 | * 0,1: Maximum sprite (last one to render?) (10-bit) |
| 76 | * |
| 77 | * 1 (bit 7): Enable sprite display |
| 78 | * |
| 79 | * 2,3: X offset (9-bit) |
| 80 | * |
| 81 | * 4,5: Y offset (9-bit) |
| 82 | * |
| 83 | * 6 (bit 4): VRAM location (0=0x40000,1=0x60000) |
| 84 | * |
| 72 | 85 | */ |
| 73 | 86 | |
| 74 | 87 | #include "driver.h" |
| r6721 | r6722 | |
| 77 | 90 | #include "includes/fmtowns.h" |
| 78 | 91 | |
| 79 | 92 | //#define CRTC_REG_DISP 1 |
| 93 | //#define SPR_DEBUG 1 |
| 80 | 94 | |
| 81 | 95 | static UINT8 towns_vram_wplane; |
| 82 | 96 | static UINT8 towns_vram_rplane; |
| r6721 | r6722 | |
| 92 | 106 | static UINT16 towns_crtc_reg[32]; |
| 93 | 107 | static UINT8 towns_video_sel; // selected video register |
| 94 | 108 | static UINT8 towns_video_reg[2]; |
| 109 | static UINT8 towns_sprite_sel; // selected sprite register |
| 110 | static UINT8 towns_sprite_reg[8]; |
| 95 | 111 | static UINT8 towns_tvram_enable; |
| 96 | 112 | static UINT16 towns_kanji_offset; |
| 97 | 113 | static UINT8 towns_kanji_code_h; |
| r6721 | r6722 | |
| 106 | 122 | extern UINT32 towns_mainmem_enable; |
| 107 | 123 | extern UINT32 towns_ankcg_enable; |
| 108 | 124 | |
| 125 | static UINT32 pshift; // for debugging |
| 126 | |
| 109 | 127 | void towns_crtc_refresh_mode(running_machine* machine) |
| 110 | 128 | { |
| 111 | 129 | rectangle scr; |
| r6721 | r6722 | |
| 344 | 362 | } |
| 345 | 363 | else |
| 346 | 364 | return 0x00; |
| 365 | case 0x10: |
| 366 | return towns_sprite_sel; |
| 367 | case 0x12: |
| 368 | logerror("SPR: reading register %i (0x452) [%02x]\n",towns_sprite_sel,towns_sprite_reg[towns_sprite_sel]); |
| 369 | return towns_sprite_reg[towns_sprite_sel]; |
| 347 | 370 | default: |
| 348 | 371 | logerror("VID: read port %04x\n",offset+0x440); |
| 349 | 372 | } |
| r6721 | r6722 | |
| 376 | 399 | logerror("Video: writing register %i (0x44a) [%02x]\n",towns_video_sel,data); |
| 377 | 400 | towns_video_reg[towns_video_sel] = data; |
| 378 | 401 | break; |
| 402 | case 0x10: |
| 403 | towns_sprite_sel = data & 0x07; |
| 404 | break; |
| 405 | case 0x12: |
| 406 | logerror("SPR: writing register %i (0x452) [%02x]\n",towns_sprite_sel,data); |
| 407 | towns_sprite_reg[towns_sprite_sel] = data; |
| 408 | break; |
| 379 | 409 | default: |
| 380 | 410 | logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0x440); |
| 381 | 411 | } |
| r6721 | r6722 | |
| 559 | 589 | } |
| 560 | 590 | } |
| 561 | 591 | |
| 562 | | // Should this area return TVRAM if enabled? |
| 563 | 592 | READ8_HANDLER( towns_spriteram_r) |
| 564 | 593 | { |
| 565 | 594 | return towns_sprram[offset]; |
| r6721 | r6722 | |
| 570 | 599 | towns_sprram[offset] = data; |
| 571 | 600 | } |
| 572 | 601 | |
| 602 | /* |
| 603 | * Sprites |
| 604 | * |
| 605 | * Max. 1024, 16x16, 16 colours per sprite |
| 606 | * 128kB Sprite RAM (8kB attributes, 120kB pattern/colour data) |
| 607 | * Sprites are rendered directly to VRAM layer 1 (VRAM offset 0x40000 or 0x60000) |
| 608 | * |
| 609 | * Sprite RAM format: |
| 610 | * 4 words per sprite |
| 611 | * +0: X position (10-bit) |
| 612 | * +2: Y position (10-bit) |
| 613 | * +4: Sprite Attribute |
| 614 | * bit 15: enforce offsets (regs 2-5) |
| 615 | * bits 10-0: Sprite RAM offset containing sprite pattern |
| 616 | * TODO: other attributes (zoom?) |
| 617 | * +6: Sprite Colour |
| 618 | * bit 15: use colour data in located in sprite RAM offset in bits 11-0 (x32) |
| 619 | */ |
| 620 | void render_sprite_4(bitmap_t* bitmap, UINT32 poffset, UINT32 coffset, UINT16 x, UINT16 y, const rectangle* rect) |
| 621 | { |
| 622 | UINT16 xpos,ypos; |
| 623 | UINT16 col,pixel; |
| 624 | UINT32 voffset; |
| 625 | |
| 626 | for(ypos=y;ypos<y+16;ypos++) |
| 627 | { |
| 628 | for(xpos=x;xpos<x+16;xpos+=2) |
| 629 | { |
| 630 | voffset = 0; |
| 631 | pixel = towns_sprram[poffset] & 0x0f; |
| 632 | col = towns_sprram[coffset+(pixel*2)] | (towns_sprram[coffset+(pixel*2)+1] << 8); |
| 633 | voffset += (towns_crtc_reg[24] * 4) * ypos; // scanline size in bytes * y pos |
| 634 | voffset += (xpos & 0x1ff) * 2; |
| 635 | voffset &= 0x3ffff; |
| 636 | voffset += (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 637 | if(xpos <= rect->max_x && ypos <= rect->max_y && col != 0) |
| 638 | { |
| 639 | towns_gfxvram[voffset+1] = (col & 0xff00) >> 8; |
| 640 | towns_gfxvram[voffset] = col & 0x00ff; |
| 641 | } |
| 642 | voffset+=2; |
| 643 | pixel = (towns_sprram[poffset] & 0xf0) >> 4; |
| 644 | col = towns_sprram[coffset+(pixel*2)] | (towns_sprram[coffset+(pixel*2)+1] << 8); |
| 645 | voffset &= 0x3ffff; |
| 646 | voffset += (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 647 | if(xpos <= rect->max_x && ypos <= rect->max_y && col != 0) |
| 648 | { |
| 649 | towns_gfxvram[voffset+1] = (col & 0xff00) >> 8; |
| 650 | towns_gfxvram[voffset] = col & 0x00ff; |
| 651 | } |
| 652 | poffset++; |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | void render_sprite_16(bitmap_t* bitmap, UINT32 poffset, UINT16 x, UINT16 y, const rectangle* rect) |
| 658 | { |
| 659 | UINT16 xpos,ypos; |
| 660 | UINT16 col;//,pixel; |
| 661 | UINT32 voffset; |
| 662 | |
| 663 | for(ypos=y;ypos<y+16;ypos++) |
| 664 | { |
| 665 | for(xpos=x;xpos<x+16;xpos++) |
| 666 | { |
| 667 | voffset = (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 668 | col = towns_sprram[poffset] | (towns_sprram[poffset+1] << 8); |
| 669 | voffset += (towns_crtc_reg[24] * 4) * ypos; // scanline size in bytes * y pos |
| 670 | voffset += (xpos & 0x1ff) * 2; |
| 671 | voffset &= 0x7ffff; |
| 672 | if(xpos <= rect->max_x && ypos <= rect->max_y) |
| 673 | { |
| 674 | towns_gfxvram[voffset+1] = (col & 0xff00) >> 8; |
| 675 | towns_gfxvram[voffset] = col & 0x00ff; |
| 676 | } |
| 677 | poffset+=2; |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | void draw_sprites(running_machine* machine,bitmap_t* bitmap, const rectangle* rect) |
| 683 | { |
| 684 | UINT16 sprite_limit = (towns_sprite_reg[0] | (towns_sprite_reg[1] << 8)) & 0x3ff; |
| 685 | int n; |
| 686 | UINT16 x,y,attr,colour; |
| 687 | UINT16 xoff = (towns_sprite_reg[2] | (towns_sprite_reg[3] << 8)) & 0x1ff; |
| 688 | UINT16 yoff = (towns_sprite_reg[4] | (towns_sprite_reg[5] << 8)) & 0x1ff; |
| 689 | UINT32 poffset,coffset; |
| 690 | |
| 691 | if(!(towns_sprite_reg[1] & 0x80)) |
| 692 | return; |
| 693 | |
| 694 | // clears VRAM for each frame? |
| 695 | memset(towns_gfxvram+0x40000,0x80,0x40000); |
| 696 | |
| 697 | for(n=sprite_limit;n<1024;n++) |
| 698 | { |
| 699 | x = towns_sprram[8*n] | (towns_sprram[8*n+1] << 8); |
| 700 | y = towns_sprram[8*n+2] | (towns_sprram[8*n+3] << 8); |
| 701 | attr = towns_sprram[8*n+4] | (towns_sprram[8*n+5] << 8); |
| 702 | colour = towns_sprram[8*n+6] | (towns_sprram[8*n+7] << 8); |
| 703 | if(attr & 0x8000) |
| 704 | { |
| 705 | x += xoff; |
| 706 | y += yoff; |
| 707 | } |
| 708 | x &= 0x1ff; |
| 709 | y &= 0x1ff; |
| 710 | |
| 711 | if(colour & 0x8000) |
| 712 | { |
| 713 | poffset = (attr & 0x3ff) << 7; |
| 714 | coffset = (colour & 0xfff) << 5; |
| 715 | #ifdef SPR_DEBUG |
| 716 | printf("Sprite4 #%i, X %i Y %i Attr %04x Col %04x Poff %05x Coff %05x\n", |
| 717 | n,x,y,attr,colour,poffset,coffset); |
| 718 | #endif |
| 719 | if(!(colour & 0x2000)) |
| 720 | render_sprite_4(bitmap,(poffset+pshift)&0x1ffff,coffset,x,y,rect); |
| 721 | } |
| 722 | else |
| 723 | { |
| 724 | poffset = (attr & 0x3ff) << 7; |
| 725 | coffset = (colour & 0xfff) << 5; |
| 726 | #ifdef SPR_DEBUG |
| 727 | printf("Sprite16 #%i, X %i Y %i Attr %04x Col %04x Poff %05x Coff %05x\n", |
| 728 | n,x,y,attr,colour,poffset,coffset); |
| 729 | #endif |
| 730 | render_sprite_16(bitmap,(poffset+pshift)&0x1ffff,x,y,rect); |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 573 | 735 | void towns_crtc_draw_scan_layer_hicolour(bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline) |
| 574 | 736 | { |
| 575 | 737 | UINT32 off = 0; |
| r6721 | r6722 | |
| 800 | 962 | } |
| 801 | 963 | } |
| 802 | 964 | |
| 803 | | void towns_crtc_draw_layer(bitmap_t* bitmap,const rectangle* rect,int layer) |
| 965 | void towns_crtc_draw_layer(running_machine* machine,bitmap_t* bitmap,const rectangle* rect,int layer) |
| 804 | 966 | { |
| 805 | 967 | int line; |
| 806 | 968 | int scanline; |
| r6721 | r6722 | |
| 854 | 1016 | } |
| 855 | 1017 | else |
| 856 | 1018 | { |
| 1019 | if(towns_sprite_reg[1] & 0x80) // if sprites are enabled, then sprites are drawn on this layer. |
| 1020 | draw_sprites(machine,bitmap,rect); |
| 1021 | |
| 857 | 1022 | scanline = rect->min_y; |
| 858 | 1023 | height = (rect->max_y - rect->min_y); |
| 859 | 1024 | if(towns_crtc_reg[27] & 0x1000) |
| r6721 | r6722 | |
| 990 | 1155 | if(!(towns_video_reg[1] & 0x01)) |
| 991 | 1156 | { |
| 992 | 1157 | if(!input_code_pressed(screen->machine,KEYCODE_Q)) |
| 993 | | towns_crtc_draw_layer(bitmap,&towns_crtc_layerscr[1],1); |
| 1158 | towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[1],1); |
| 994 | 1159 | if(!input_code_pressed(screen->machine,KEYCODE_W)) |
| 995 | | towns_crtc_draw_layer(bitmap,&towns_crtc_layerscr[0],0); |
| 1160 | towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[0],0); |
| 996 | 1161 | } |
| 997 | 1162 | else |
| 998 | 1163 | { |
| 999 | 1164 | if(!input_code_pressed(screen->machine,KEYCODE_Q)) |
| 1000 | | towns_crtc_draw_layer(bitmap,&towns_crtc_layerscr[0],0); |
| 1165 | towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[0],0); |
| 1001 | 1166 | if(!input_code_pressed(screen->machine,KEYCODE_W)) |
| 1002 | | towns_crtc_draw_layer(bitmap,&towns_crtc_layerscr[1],1); |
| 1167 | towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[1],1); |
| 1003 | 1168 | } |
| 1004 | 1169 | |
| 1005 | | draw_text_layer(screen->machine,bitmap,cliprect); |
| 1170 | if(!(towns_sprite_reg[1] & 0x80)) // if sprites are not enabled |
| 1171 | draw_text_layer(screen->machine,bitmap,cliprect); |
| 1006 | 1172 | |
| 1173 | #ifdef SPR_DEBUG |
| 1174 | if(input_code_pressed(screen->machine,KEYCODE_O)) |
| 1175 | pshift+=0x80; |
| 1176 | if(input_code_pressed(screen->machine,KEYCODE_I)) |
| 1177 | pshift-=0x80; |
| 1178 | popmessage("Pixel shift = %08x",pshift); |
| 1179 | #endif |
| 1180 | |
| 1007 | 1181 | #ifdef CRTC_REG_DISP |
| 1008 | 1182 | popmessage("CRTC: %i %i %i %i %i %i %i %i %i\n%i %i %i %i | %i %i %i %i\n%i %i %i %i | %i %i %i %i\nZOOM: %04x\nVideo: %02x %02x\nText=%i", |
| 1009 | 1183 | towns_crtc_reg[0],towns_crtc_reg[1],towns_crtc_reg[2],towns_crtc_reg[3], |
src/mess/drivers/fmtowns.c
| r6721 | r6722 | |
| 1604 | 1604 | AM_RANGE(0x000f8000, 0x000fffff) AM_READ_BANK("bank11") AM_WRITE_BANK("bank12") |
| 1605 | 1605 | AM_RANGE(0x00100000, 0x005fffff) AM_RAM // some extra RAM - seems to be needed to boot |
| 1606 | 1606 | AM_RANGE(0x80000000, 0x8007ffff) AM_READWRITE8(towns_gfx_high_r,towns_gfx_high_w,0xffffffff) AM_MIRROR(0x180000) // VRAM |
| 1607 | | AM_RANGE(0x81000000, 0x8101ffff) AM_RAM // Sprite RAM |
| 1607 | AM_RANGE(0x81000000, 0x8101ffff) AM_READWRITE8(towns_spriteram_r,towns_spriteram_w,0xffffffff) // Sprite RAM |
| 1608 | 1608 | AM_RANGE(0xc2000000, 0xc207ffff) AM_ROM AM_REGION("user",0x000000) // OS ROM |
| 1609 | 1609 | AM_RANGE(0xc2080000, 0xc20fffff) AM_ROM AM_REGION("user",0x100000) // DIC ROM |
| 1610 | 1610 | AM_RANGE(0xc2100000, 0xc213ffff) AM_ROM AM_REGION("user",0x180000) // FONT ROM |
| r6721 | r6722 | |
| 1630 | 1630 | AM_RANGE(0x00600000, 0x0067ffff) AM_ROM AM_REGION("user",0x000000) // OS |
| 1631 | 1631 | AM_RANGE(0x00680000, 0x0087ffff) AM_ROM AM_REGION("user",0x280000) // EX ROM |
| 1632 | 1632 | AM_RANGE(0x00a00000, 0x00a7ffff) AM_READWRITE8(towns_gfx_high_r,towns_gfx_high_w,0xffffffff) AM_MIRROR(0x180000) // VRAM |
| 1633 | AM_RANGE(0x00c00000, 0x00c1ffff) AM_READWRITE8(towns_spriteram_r,towns_spriteram_w,0xffffffff) // Sprite RAM |
| 1633 | 1634 | AM_RANGE(0x00e80000, 0x00efffff) AM_ROM AM_REGION("user",0x100000) // DIC ROM |
| 1634 | 1635 | AM_RANGE(0x00f00000, 0x00f7ffff) AM_ROM AM_REGION("user",0x180000) // FONT |
| 1635 | 1636 | AM_RANGE(0x00fc0000, 0x00ffffff) AM_ROM AM_REGION("user",0x200000) // SYSTEM ROM |
| 1636 | | AM_RANGE(0x80000000, 0x8007ffff) AM_READWRITE8(towns_gfx_high_r,towns_gfx_high_w,0xffffffff) AM_MIRROR(0x180000) // VRAM |
| 1637 | /* AM_RANGE(0x80000000, 0x8007ffff) AM_READWRITE8(towns_gfx_high_r,towns_gfx_high_w,0xffffffff) AM_MIRROR(0x180000) // VRAM |
| 1637 | 1638 | AM_RANGE(0x81000000, 0x8101ffff) AM_READWRITE8(towns_spriteram_r,towns_spriteram_w,0xffffffff) // Sprite RAM |
| 1638 | 1639 | AM_RANGE(0xc2000000, 0xc207ffff) AM_ROM AM_REGION("user",0x000000) // OS ROM |
| 1639 | 1640 | AM_RANGE(0xc2080000, 0xc20fffff) AM_ROM AM_REGION("user",0x100000) // DIC ROM |
| 1640 | 1641 | AM_RANGE(0xc2100000, 0xc213ffff) AM_ROM AM_REGION("user",0x180000) // FONT ROM |
| 1641 | 1642 | AM_RANGE(0xc2140000, 0xc2141fff) AM_READWRITE8(towns_cmos_r,towns_cmos_w,0xffffffff) // CMOS (mirror?) |
| 1642 | 1643 | AM_RANGE(0xc2200000, 0xc2200fff) AM_NOP // WAVE RAM |
| 1643 | | AM_RANGE(0xfffc0000, 0xffffffff) AM_ROM AM_REGION("user",0x200000) // SYSTEM ROM |
| 1644 | */AM_RANGE(0xfffc0000, 0xffffffff) AM_ROM AM_REGION("user",0x200000) // SYSTEM ROM |
| 1644 | 1645 | ADDRESS_MAP_END |
| 1645 | 1646 | |
| 1646 | 1647 | static ADDRESS_MAP_START( towns_io , ADDRESS_SPACE_IO, 32) |