src/mess/drivers/fmtowns.c
| r6014 | r6015 | |
| 109 | 109 | static int towns_srom_position; |
| 110 | 110 | static UINT8 towns_srom_clk; |
| 111 | 111 | static UINT8 towns_srom_reset; |
| 112 | static UINT8 towns_rtc_select; |
| 113 | static UINT8 towns_rtc_data; |
| 114 | static UINT8 towns_rtc_reg[16]; |
| 115 | emu_timer* towns_rtc_timer; |
| 112 | 116 | |
| 113 | 117 | static void towns_update_video_banks(const address_space* space); |
| 114 | 118 | |
| r6014 | r6015 | |
| 141 | 145 | towns_serial_rom[6] = 0x10; |
| 142 | 146 | } |
| 143 | 147 | |
| 148 | static void towns_init_rtc(void) |
| 149 | { |
| 150 | // for now, we'll just keep a static time stored here |
| 151 | // seconds |
| 152 | towns_rtc_reg[0] = 0; |
| 153 | towns_rtc_reg[1] = 3; |
| 154 | // minutes |
| 155 | towns_rtc_reg[2] = 2; |
| 156 | towns_rtc_reg[3] = 1; |
| 157 | // hours |
| 158 | towns_rtc_reg[4] = 8; |
| 159 | towns_rtc_reg[5] = 0; |
| 160 | // weekday |
| 161 | towns_rtc_reg[6] = 2; |
| 162 | // day |
| 163 | towns_rtc_reg[7] = 1; |
| 164 | towns_rtc_reg[8] = 1; |
| 165 | // month |
| 166 | towns_rtc_reg[9] = 6; |
| 167 | towns_rtc_reg[10] = 0; |
| 168 | // year |
| 169 | towns_rtc_reg[11] = 9; |
| 170 | towns_rtc_reg[12] = 0; |
| 171 | } |
| 172 | |
| 144 | 173 | static READ8_HANDLER(towns_system_r) |
| 145 | 174 | { |
| 146 | 175 | UINT8 ret = 0; |
| r6014 | r6015 | |
| 788 | 817 | } |
| 789 | 818 | } |
| 790 | 819 | |
| 820 | /* CMOS RTC |
| 821 | * 0x70: Data port |
| 822 | * 0x80: Register select |
| 823 | */ |
| 824 | static READ32_HANDLER(towns_rtc_r) |
| 825 | { |
| 826 | if(ACCESSING_BITS_0_7) |
| 827 | return 0x80 | towns_rtc_reg[towns_rtc_select]; |
| 828 | |
| 829 | return 0x00; |
| 830 | } |
| 831 | |
| 832 | static WRITE32_HANDLER(towns_rtc_w) |
| 833 | { |
| 834 | if(ACCESSING_BITS_0_7) |
| 835 | towns_rtc_data = data;; |
| 836 | } |
| 837 | |
| 838 | static WRITE32_HANDLER(towns_rtc_select_w) |
| 839 | { |
| 840 | if(ACCESSING_BITS_0_7) |
| 841 | { |
| 842 | if(!(data & 0x80)) |
| 843 | { |
| 844 | if(data & 0x01) |
| 845 | towns_rtc_select = towns_rtc_data & 0x0f; |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | static void rtc_hour(void) |
| 851 | { |
| 852 | towns_rtc_reg[4]++; |
| 853 | if(towns_rtc_reg[4] > 4 && towns_rtc_reg[5] == 2) |
| 854 | { |
| 855 | towns_rtc_reg[4] = 0; |
| 856 | towns_rtc_reg[5] = 0; |
| 857 | } |
| 858 | else if(towns_rtc_reg[4] > 9) |
| 859 | { |
| 860 | towns_rtc_reg[4] = 0; |
| 861 | towns_rtc_reg[5]++; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | static void rtc_minute(void) |
| 866 | { |
| 867 | towns_rtc_reg[2]++; |
| 868 | if(towns_rtc_reg[2] > 9) |
| 869 | { |
| 870 | towns_rtc_reg[2] = 0; |
| 871 | towns_rtc_reg[3]++; |
| 872 | if(towns_rtc_reg[3] > 5) |
| 873 | { |
| 874 | towns_rtc_reg[3] = 0; |
| 875 | rtc_hour(); |
| 876 | } |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | static TIMER_CALLBACK(rtc_second) |
| 881 | { |
| 882 | // increase RTC time by one second |
| 883 | towns_rtc_reg[0]++; |
| 884 | if(towns_rtc_reg[0] > 9) |
| 885 | { |
| 886 | towns_rtc_reg[0] = 0; |
| 887 | towns_rtc_reg[1]++; |
| 888 | if(towns_rtc_reg[1] > 5) |
| 889 | { |
| 890 | towns_rtc_reg[1] = 0; |
| 891 | rtc_minute(); |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | |
| 791 | 896 | static READ8_HANDLER(towns_unknown_r) |
| 792 | 897 | { |
| 793 | 898 | return 0x08; |
| r6014 | r6015 | |
| 795 | 900 | |
| 796 | 901 | static IRQ_CALLBACK( towns_irq_callback ) |
| 797 | 902 | { |
| 798 | | const device_config* dev = devtag_get_device(device->machine,"pic8259_master"); |
| 799 | | return pic8259_acknowledge(dev); |
| 903 | const device_config* pic1 = devtag_get_device(device->machine,"pic8259_master"); |
| 904 | const device_config* pic2 = devtag_get_device(device->machine,"pic8259_slave"); |
| 905 | int r; |
| 906 | |
| 907 | r = pic8259_acknowledge(pic2); |
| 908 | if(r == 0) |
| 909 | { |
| 910 | r = pic8259_acknowledge(pic1); |
| 911 | } |
| 912 | |
| 913 | return r; |
| 800 | 914 | } |
| 801 | 915 | |
| 802 | 916 | static PIC8259_SET_INT_LINE( towns_pic_irq ) |
| r6014 | r6015 | |
| 804 | 918 | cputag_set_input_line(device->machine,"maincpu",0,interrupt ? ASSERT_LINE : CLEAR_LINE); |
| 805 | 919 | } |
| 806 | 920 | |
| 921 | static PIC8259_SET_INT_LINE( towns_slave_pic_irq ) |
| 922 | { |
| 923 | cputag_set_input_line(device->machine,"maincpu",7,interrupt ? ASSERT_LINE : CLEAR_LINE); |
| 924 | } |
| 925 | |
| 807 | 926 | static PIT8253_OUTPUT_CHANGED( towns_pit_out0_changed ) |
| 808 | 927 | { |
| 809 | 928 | const device_config* dev = devtag_get_device(device->machine,"pic8259_master"); |
| r6014 | r6015 | |
| 850 | 969 | AM_RANGE(0x0060,0x0063) AM_READWRITE8(towns_port60_r, towns_port60_w, 0x000000ff) |
| 851 | 970 | AM_RANGE(0x006c,0x006f) AM_READWRITE8(towns_sys6c_r,towns_sys6c_w, 0x000000ff) |
| 852 | 971 | // 0x0070/0x0080 - CMOS RTC |
| 972 | AM_RANGE(0x0070,0x0073) AM_READWRITE(towns_rtc_r,towns_rtc_w) |
| 973 | AM_RANGE(0x0080,0x0083) AM_WRITE(towns_rtc_select_w) |
| 853 | 974 | // DMA controllers (uPD71071) |
| 854 | 975 | AM_RANGE(0x00a0,0x00af) AM_READWRITE8(towns_dma1_r, towns_dma1_w, 0xffffffff) |
| 855 | 976 | AM_RANGE(0x00b0,0x00bf) AM_READWRITE8(towns_dma2_r, towns_dma2_w, 0xffffffff) |
| r6014 | r6015 | |
| 902 | 1023 | towns_txtvram = auto_alloc_array(machine,UINT8,0x8000); |
| 903 | 1024 | towns_serial_rom = auto_alloc_array(machine,UINT8,256/8); |
| 904 | 1025 | towns_init_serial_rom(); |
| 1026 | towns_init_rtc(); |
| 1027 | towns_rtc_timer = timer_alloc(machine,rtc_second,NULL); |
| 905 | 1028 | |
| 906 | 1029 | cpu_set_irq_callback(cputag_get_cpu(machine,"maincpu"), towns_irq_callback); |
| 907 | 1030 | } |
| r6014 | r6015 | |
| 916 | 1039 | towns_ram_enable = 0x00; |
| 917 | 1040 | towns_update_video_banks(cpu_get_address_space(cputag_get_cpu(machine,"maincpu"),ADDRESS_SPACE_PROGRAM)); |
| 918 | 1041 | towns_vram_wplane = 0x00; |
| 1042 | timer_adjust_periodic(towns_rtc_timer,attotime_zero,0,ATTOTIME_IN_HZ(1)); |
| 919 | 1043 | } |
| 920 | 1044 | |
| 921 | 1045 | static VIDEO_START( towns ) |
| r6014 | r6015 | |
| 978 | 1102 | |
| 979 | 1103 | static const struct pic8259_interface towns_pic8259_slave_config = |
| 980 | 1104 | { |
| 981 | | NULL |
| 1105 | towns_slave_pic_irq |
| 982 | 1106 | }; |
| 983 | 1107 | |
| 984 | 1108 | static const wd17xx_interface towns_mb8877a_interface = |