Previous 15994 Revisions Next

r6015 Thursday 8th October, 2009 at 10:59:00 UTC by Barry Rodewald
[FMTOWNS] Added simple RTC setup, hooked up slave PIC.
[src/mess/drivers]fmtowns.c

src/mess/drivers/fmtowns.c
r6014r6015
109109static int towns_srom_position;
110110static UINT8 towns_srom_clk;
111111static UINT8 towns_srom_reset;
112static UINT8 towns_rtc_select;
113static UINT8 towns_rtc_data;
114static UINT8 towns_rtc_reg[16];
115emu_timer* towns_rtc_timer;
112116
113117static void towns_update_video_banks(const address_space* space);
114118
r6014r6015
141145   towns_serial_rom[6] = 0x10;
142146}
143147
148static 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
144173static READ8_HANDLER(towns_system_r)
145174{
146175   UINT8 ret = 0;
r6014r6015
788817   }
789818}
790819
820/* CMOS RTC
821 * 0x70: Data port
822 * 0x80: Register select
823 */
824static 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
832static WRITE32_HANDLER(towns_rtc_w)
833{
834   if(ACCESSING_BITS_0_7)
835      towns_rtc_data = data;;
836}
837
838static 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
850static 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
865static 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
880static 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
791896static READ8_HANDLER(towns_unknown_r)
792897{
793898   return 0x08;
r6014r6015
795900
796901static IRQ_CALLBACK( towns_irq_callback )
797902{
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;
800914}
801915
802916static PIC8259_SET_INT_LINE( towns_pic_irq )
r6014r6015
804918   cputag_set_input_line(device->machine,"maincpu",0,interrupt ? ASSERT_LINE : CLEAR_LINE);
805919}
806920
921static 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
807926static PIT8253_OUTPUT_CHANGED( towns_pit_out0_changed )
808927{
809928   const device_config* dev = devtag_get_device(device->machine,"pic8259_master");
r6014r6015
850969  AM_RANGE(0x0060,0x0063) AM_READWRITE8(towns_port60_r, towns_port60_w, 0x000000ff)
851970  AM_RANGE(0x006c,0x006f) AM_READWRITE8(towns_sys6c_r,towns_sys6c_w, 0x000000ff)
852971  // 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)
853974  // DMA controllers (uPD71071)
854975  AM_RANGE(0x00a0,0x00af) AM_READWRITE8(towns_dma1_r, towns_dma1_w, 0xffffffff)
855976  AM_RANGE(0x00b0,0x00bf) AM_READWRITE8(towns_dma2_r, towns_dma2_w, 0xffffffff)
r6014r6015
9021023   towns_txtvram = auto_alloc_array(machine,UINT8,0x8000);
9031024   towns_serial_rom = auto_alloc_array(machine,UINT8,256/8);
9041025   towns_init_serial_rom();
1026   towns_init_rtc();
1027   towns_rtc_timer = timer_alloc(machine,rtc_second,NULL);
9051028   
9061029   cpu_set_irq_callback(cputag_get_cpu(machine,"maincpu"), towns_irq_callback);
9071030}
r6014r6015
9161039   towns_ram_enable = 0x00;
9171040   towns_update_video_banks(cpu_get_address_space(cputag_get_cpu(machine,"maincpu"),ADDRESS_SPACE_PROGRAM));
9181041   towns_vram_wplane = 0x00;
1042   timer_adjust_periodic(towns_rtc_timer,attotime_zero,0,ATTOTIME_IN_HZ(1));
9191043}
9201044
9211045static VIDEO_START( towns )
r6014r6015
9781102
9791103static const struct pic8259_interface towns_pic8259_slave_config =
9801104{
981   NULL
1105   towns_slave_pic_irq
9821106};
9831107
9841108static const wd17xx_interface towns_mb8877a_interface =

Previous 15994 Revisions Next


© 1998-2018 The MESS Team