src/mess/drivers/x1.c
| r5580 | r5581 | |
| 2 | 2 | |
| 3 | 3 | Sharp X1 (c) 1983 Sharp Corporation |
| 4 | 4 | |
| 5 | | preliminary driver by Angelo Salese |
| 5 | driver by Angelo Salese & Barry Rodewald |
| 6 | 6 | |
| 7 | 7 | TODO: |
| 8 | 8 | - Understand how keyboard works and decap/dump the keyboard MCU if possible; |
| r5580 | r5581 | |
| 10 | 10 | - Implement tape commands; |
| 11 | 11 | - Sort out / redump the BIOS gfx roms; |
| 12 | 12 | - Implement the interrupts (uses IM 2), basically used by the keyboard. |
| 13 | | - Implement DMA (X1Turbo only?) |
| 13 | - Implement DMA,CTC and SIO, they are X1Turbo only features. |
| 14 | 14 | - clean-ups! |
| 15 | 15 | - x1turbo: understand how irq generation works for the ym-2151; |
| 16 | 16 | - There are various unclear video things, these are: |
| 17 | 17 | - Understand why some games still doesn't upload the proper PCG index; |
| 18 | | - Support the alternative PCG upload mode; |
| 19 | 18 | - Implement PCG reading, used by Maison Ikkoku, Mule and Gyajiko for kanji reading; |
| 20 | | - Implement the scrn params; |
| 19 | - Implement the scrn regs; |
| 21 | 20 | - Interlace mode? |
| 22 | 21 | - Some colors are still way wrong (check 1942 or Dialide), needs update_partial perhaps? |
| 23 | 22 | - Maybe the colorram/videoram stuff is actually a converter for the BRG framebuffer in |
| 24 | 23 | the end? |
| 24 | - Implement the new features of the x1turbo, namely the 4096 color feature amongst other |
| 25 | things |
| 25 | 26 | - (anything else?) |
| 26 | 27 | |
| 27 | 28 | per-game specific TODO: |
| 28 | 29 | - Bosconian: title screen background is completely white because it reverts the pen used |
| 29 | 30 | (it's gray in the Arcade version),could be either flickering for pseudo-alpha effect or it's |
| 30 | 31 | a btanb; |
| 31 | | - Dragon Slayer: colors aren't 100% and for whatever reason it doesn't clear the screen on the |
| 32 | | gameplay. |
| 33 | 32 | - Super Mario Bros. SP: background color is black, should be blue. DMA issue? |
| 33 | - Mappy (New Version): has color issues, should be identical to the Arcade version, sets PLY reg == 0xe; |
| 34 | - Gradius: PCG tiles should be 16 colors or use the entire 8 color range, it's sure that the current palette |
| 35 | bank isn't right (it's ok for the bitmaps only) |
| 34 | 36 | |
| 35 | 37 | Notes: |
| 36 | 38 | - An interesting feature of the Sharp X-1 is the extended i/o bank. When the ppi port c bit 5 |
| r5580 | r5581 | |
| 166 | 168 | { |
| 167 | 169 | UINT8 gfx_bank; |
| 168 | 170 | UINT8 pcg_mode; |
| 171 | UINT8 blackclip; // x1 turbo specific |
| 169 | 172 | }scrn_reg; |
| 173 | |
| 170 | 174 | static UINT8 pcg_write_addr; |
| 171 | 175 | |
| 172 | 176 | |
| r5580 | r5581 | |
| 232 | 236 | if(color & 8) //revert the used color pen |
| 233 | 237 | pcg_pen^=7; |
| 234 | 238 | |
| 239 | if((scrn_reg.blackclip & 8) && (color == (scrn_reg.blackclip & 7))) |
| 240 | pcg_pen = 8; // clip the pen to black |
| 241 | |
| 235 | 242 | if((res_x+xi)>video_screen_get_visible_area(machine->primary_screen)->max_x && (res_y+yi)>video_screen_get_visible_area(machine->primary_screen)->max_y) |
| 236 | 243 | continue; |
| 237 | 244 | |
| r5580 | r5581 | |
| 365 | 372 | { |
| 366 | 373 | UINT8 val = 0xe0; |
| 367 | 374 | val |= input_port_read(machine,"key_modifiers") & 0x1f; |
| 368 | | |
| 375 | |
| 369 | 376 | if(check_keyboard_press(machine) != 0) |
| 370 | 377 | val &= ~0x40; |
| 371 | 378 | |
| r5580 | r5581 | |
| 376 | 383 | { |
| 377 | 384 | static int sub_val_ptr; |
| 378 | 385 | UINT8 ret; |
| 379 | | |
| 386 | |
| 380 | 387 | if(sub_obf) |
| 381 | 388 | return 0xff; |
| 382 | 389 | |
| r5580 | r5581 | |
| 413 | 420 | // E9 06 - APSS(?) Rewind |
| 414 | 421 | // E9 0A - Record |
| 415 | 422 | cmt_current_cmd = cmd; |
| 416 | | |
| 423 | |
| 417 | 424 | switch(cmd) |
| 418 | 425 | { |
| 419 | 426 | case 0x01: // Stop |
| r5580 | r5581 | |
| 779 | 786 | { |
| 780 | 787 | scrn_reg.pcg_mode = (data & 0x20)>>5; |
| 781 | 788 | scrn_reg.gfx_bank = 0;//(data & 0x10)>>4; |
| 789 | printf("SCRN = %02x\n",data); |
| 782 | 790 | } |
| 783 | 791 | |
| 784 | 792 | static WRITE8_HANDLER( x1_ply_w ) |
| 785 | 793 | { |
| 794 | printf("PLY = %02x\n",data); |
| 786 | 795 | } |
| 787 | 796 | |
| 788 | 797 | static WRITE8_HANDLER( x1_6845_w ) |
| r5580 | r5581 | |
| 808 | 817 | |
| 809 | 818 | static WRITE8_HANDLER( x1_dma_w ) |
| 810 | 819 | { |
| 811 | | printf("%02x %02x\n",offset,data); |
| 820 | //printf("%02x %02x\n",offset,data); |
| 812 | 821 | //if(data) |
| 813 | 822 | // fatalerror("Data written to the DMA space"); |
| 814 | 823 | } |
| 815 | 824 | |
| 825 | static READ8_HANDLER( x1_blackclip_r ) |
| 826 | { |
| 827 | return scrn_reg.blackclip; |
| 828 | } |
| 816 | 829 | |
| 830 | static WRITE8_HANDLER( x1_blackclip_w ) |
| 831 | { |
| 832 | scrn_reg.blackclip = data; |
| 833 | } |
| 834 | |
| 835 | static WRITE8_HANDLER( x1turbo_pal_w ) |
| 836 | { |
| 837 | printf("TURBO PAL %02x\n",data); |
| 838 | } |
| 839 | |
| 840 | static WRITE8_HANDLER( x1turbo_txpal_w ) |
| 841 | { |
| 842 | printf("TURBO TEXT PAL %02x\n",data); |
| 843 | } |
| 844 | |
| 845 | static WRITE8_HANDLER( x1turbo_txdisp_w ) |
| 846 | { |
| 847 | printf("TURBO TEXT DISPLAY %02x\n",data); |
| 848 | } |
| 849 | |
| 850 | static WRITE8_HANDLER( x1turbo_gfxpal_w ) |
| 851 | { |
| 852 | printf("TURBO GFX PAL %02x\n",data); |
| 853 | } |
| 854 | |
| 817 | 855 | /************************************* |
| 818 | 856 | * |
| 819 | 857 | * Memory maps |
| r5580 | r5581 | |
| 835 | 873 | else if(offset >= 0x1fa0 && offset <= 0x1fa3) { return z80ctc_r(devtag_get_device(space->machine, "ctc"), offset-0x1fa3); } |
| 836 | 874 | else if(offset >= 0x1fa8 && offset <= 0x1fab) { return z80ctc_r(devtag_get_device(space->machine, "ctc"), offset-0x1fa8); } |
| 837 | 875 | // else if(offset >= 0x1fd0 && offset <= 0x1fdf) { return x1_scrn_r(space,offset-0x1fd0); } |
| 876 | else if(offset == 0x1fe0) { return x1_blackclip_r(space,0); } |
| 838 | 877 | else if(offset >= 0x2000 && offset <= 0x2fff) { return colorram[offset-0x2000]; } |
| 839 | 878 | else if(offset >= 0x3000 && offset <= 0x3fff) { return videoram[offset-0x3000]; } |
| 840 | 879 | else if(offset >= 0x4000 && offset <= 0xffff) { return gfx_bitmap_ram[offset-0x4000+(scrn_reg.gfx_bank*0xc000)]; } |
| r5580 | r5581 | |
| 869 | 908 | // else if(offset >= 0x1f90 && offset <= 0x1f93) { x1_sio_w(space->machine,(offset-0x1f90) & 3),data; } |
| 870 | 909 | else if(offset >= 0x1fa0 && offset <= 0x1fa3) { z80ctc_w(devtag_get_device(space->machine, "ctc"), offset-0x1fa3,data); } |
| 871 | 910 | else if(offset >= 0x1fa8 && offset <= 0x1fab) { z80ctc_w(devtag_get_device(space->machine, "ctc"), offset-0x1fa8,data); } |
| 911 | else if(offset == 0x1fb0) { x1turbo_pal_w(space,0,data); } |
| 912 | else if(offset >= 0x1fb9 && offset <= 0x1fbf) { x1turbo_txpal_w(space,offset-0x1fb9,data); } |
| 913 | else if(offset == 0x1fc0) { x1turbo_txdisp_w(space,0,data); } |
| 914 | else if(offset == 0x1fc5) { x1turbo_gfxpal_w(space,0,data); } |
| 872 | 915 | else if(offset >= 0x1fd0 && offset <= 0x1fdf) { x1_scrn_w(space,0,data); } |
| 916 | else if(offset == 0x1fe0) { x1_blackclip_w(space,0,data); } |
| 873 | 917 | else if(offset >= 0x2000 && offset <= 0x2fff) { colorram[offset-0x2000] = data; } |
| 874 | 918 | else if(offset >= 0x3000 && offset <= 0x3fff) { videoram[offset-0x3000] = pcg_write_addr = data; } |
| 875 | 919 | else if(offset >= 0x4000 && offset <= 0xffff) { gfx_bitmap_ram[offset-0x4000+(scrn_reg.gfx_bank*0xc000)] = data; } |
| r5580 | r5581 | |
| 895 | 939 | else if(offset >= 0x1fa0 && offset <= 0x1fa3) { return z80ctc_r(devtag_get_device(space->machine, "ctc"), offset-0x1fa3); } |
| 896 | 940 | else if(offset >= 0x1fa8 && offset <= 0x1fab) { return z80ctc_r(devtag_get_device(space->machine, "ctc"), offset-0x1fa8); } |
| 897 | 941 | // else if(offset >= 0x1fd0 && offset <= 0x1fdf) { return x1_scrn_r(space,offset-0x1fd0); } |
| 942 | else if(offset == 0x1fe0) { return x1_blackclip_r(space,0); } |
| 898 | 943 | else if(offset >= 0x2000 && offset <= 0x2fff) { return colorram[offset-0x2000]; } |
| 899 | 944 | else if(offset >= 0x3000 && offset <= 0x3fff) { return videoram[offset-0x3000]; } |
| 900 | 945 | else if(offset >= 0x4000 && offset <= 0xffff) { return gfx_bitmap_ram[offset-0x4000+(scrn_reg.gfx_bank*0xc000)]; } |
| r5580 | r5581 | |
| 930 | 975 | // else if(offset >= 0x1f90 && offset <= 0x1f93) { x1_sio_w(space->machine,(offset-0x1f90) & 3),data; } |
| 931 | 976 | else if(offset >= 0x1fa0 && offset <= 0x1fa3) { z80ctc_w(devtag_get_device(space->machine, "ctc"), offset-0x1fa3,data); } |
| 932 | 977 | else if(offset >= 0x1fa8 && offset <= 0x1fab) { z80ctc_w(devtag_get_device(space->machine, "ctc"), offset-0x1fa8,data); } |
| 978 | else if(offset == 0x1fb0) { x1turbo_pal_w(space,0,data); } |
| 979 | else if(offset >= 0x1fb9 && offset <= 0x1fbf) { x1turbo_txpal_w(space,offset-0x1fb9,data); } |
| 980 | else if(offset == 0x1fc0) { x1turbo_txdisp_w(space,0,data); } |
| 981 | else if(offset == 0x1fc5) { x1turbo_gfxpal_w(space,0,data); } |
| 933 | 982 | else if(offset >= 0x1fd0 && offset <= 0x1fdf) { x1_scrn_w(space,0,data); } |
| 983 | else if(offset == 0x1fe0) { x1_blackclip_w(space,0,data); } |
| 934 | 984 | else if(offset >= 0x2000 && offset <= 0x2fff) { colorram[offset-0x2000] = data; } |
| 935 | 985 | else if(offset >= 0x3000 && offset <= 0x3fff) { videoram[offset-0x3000] = pcg_write_addr = data; } |
| 936 | 986 | else if(offset >= 0x4000 && offset <= 0xffff) { gfx_bitmap_ram[offset-0x4000+(scrn_reg.gfx_bank*0xc000)] = data; } |
| r5580 | r5581 | |
| 985 | 1035 | */ |
| 986 | 1036 | UINT8 dat = 0; |
| 987 | 1037 | dat = (input_port_read(device->machine, "SYSTEM") & ~0x68) | sub_obf; |
| 988 | | |
| 1038 | |
| 989 | 1039 | if((dat & 0x80) == 0) |
| 990 | 1040 | dat |= 0x04; // VSync (todo: proper implementation of vsync) |
| 991 | | |
| 1041 | |
| 992 | 1042 | if(cassette_input(devtag_get_device(device->machine,"cass")) > 0.03) |
| 993 | 1043 | dat |= 0x02; |
| 994 | 1044 | |
| 995 | 1045 | if(cassette_get_state(devtag_get_device(device->machine,"cass")) & CASSETTE_MOTOR_DISABLED) |
| 996 | 1046 | dat |= 0x02; |
| 997 | | |
| 1047 | |
| 998 | 1048 | return dat; |
| 999 | 1049 | } |
| 1000 | 1050 | |
| r5580 | r5581 | |
| 1029 | 1079 | |
| 1030 | 1080 | io_switch = data & 0x20; |
| 1031 | 1081 | io_sys = data & 0xff; |
| 1032 | | |
| 1082 | |
| 1033 | 1083 | cassette_output(devtag_get_device(device->machine,"cass"),(data & 0x01) ? +1.0 : -1.0); |
| 1034 | 1084 | } |
| 1035 | 1085 | |
| r5580 | r5581 | |
| 1516 | 1566 | gfx_element_mark_dirty(machine->gfx[7], i); |
| 1517 | 1567 | } |
| 1518 | 1568 | |
| 1569 | /* X1 Turbo specific */ |
| 1570 | scrn_reg.blackclip = 0; |
| 1571 | |
| 1519 | 1572 | io_bank_mode = 0; |
| 1520 | 1573 | pcg_index[0] = pcg_index[1] = pcg_index[2] = 0; |
| 1521 | 1574 | |
| 1522 | 1575 | cpu_set_irq_callback(cputag_get_cpu(machine, "maincpu"), x1_irq_callback); |
| 1523 | 1576 | timer_pulse(machine, ATTOTIME_IN_HZ(240), NULL, 0, keyboard_callback); |
| 1524 | | |
| 1577 | |
| 1525 | 1578 | cmt_current_cmd = 0; |
| 1526 | 1579 | cassette_change_state(devtag_get_device(machine, "cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR); |
| 1527 | 1580 | } |
| r5580 | r5581 | |
| 1553 | 1606 | /* TODO: fix this */ |
| 1554 | 1607 | for(i=0;i<8;i++) |
| 1555 | 1608 | { |
| 1556 | | palette_set_color_rgb(machine, i+0x000, pal1bit(i >> 2), pal1bit(i >> 1), pal1bit(i >> 0)); |
| 1557 | | palette_set_color_rgb(machine, i+0x100, pal1bit(i >> 2), pal1bit(i >> 1), pal1bit(i >> 0)); |
| 1609 | palette_set_color_rgb(machine, i+0x000, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0)); |
| 1610 | palette_set_color_rgb(machine, i+0x100, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0)); |
| 1558 | 1611 | } |
| 1559 | 1612 | } |
| 1560 | 1613 | |