Previous 199869 Revisions Next

r20916 Sunday 10th February, 2013 at 21:48:52 UTC by Wilbert Pol
(MESS) gp32.c: Some tagmap cleanups (nw)
[src/mess/drivers]gp32.c
[src/mess/includes]gp32.h

trunk/src/mess/includes/gp32.h
r20915r20916
8686{
8787public:
8888   gp32_state(const machine_config &mconfig, device_type type, const char *tag)
89      : driver_device(mconfig, type, tag) ,
90      m_s3c240x_ram(*this, "s3c240x_ram"){ }
89      : driver_device(mconfig, type, tag)
90      , m_s3c240x_ram(*this, "s3c240x_ram")
91      , m_maincpu(*this, "maincpu")
92   { }
9193
9294   virtual void video_start();
9395
r20915r20916
169171   TIMER_CALLBACK_MEMBER(s3c240x_dma_timer_exp);
170172   TIMER_CALLBACK_MEMBER(s3c240x_iic_timer_exp);
171173   TIMER_CALLBACK_MEMBER(s3c240x_iis_timer_exp);
174
175protected:
176   required_device<cpu_device> m_maincpu;
177
178   UINT32 s3c240x_get_fclk(int reg);
179   UINT32 s3c240x_get_hclk(int reg);
180   UINT32 s3c240x_get_pclk(int reg);
181   void s3c240x_lcd_dma_reload();
182   void s3c240x_lcd_dma_init();
183   void s3c240x_lcd_configure();
184   void s3c240x_lcd_start();
185   void s3c240x_lcd_stop();
186   void s3c240x_lcd_recalc();
187   void s3c240x_check_pending_irq();
188   void s3c240x_request_irq(UINT32 int_type);
189   void s3c240x_dma_reload(int dma);
190   void s3c240x_dma_trigger(int dma);
191   void s3c240x_dma_request_iis();
192   void s3c240x_dma_request_pwm();
193   void s3c240x_dma_start(int dma);
194   void s3c240x_dma_stop(int dma);
195   void s3c240x_dma_recalc(int dma);
196   void s3c240x_pwm_start(int timer);
197   void s3c240x_pwm_stop(int timer);
198   void s3c240x_pwm_recalc(int timer);
199   void s3c240x_iis_start();
200   void s3c240x_iis_stop();
201   void s3c240x_iis_recalc();
172202};
173203
174204
trunk/src/mess/drivers/gp32.c
r20915r20916
4747#define BITS(x,m,n) (((x)>>(n))&((1<<((m)-(n)+1))-1))
4848
4949
50static UINT32 s3c240x_get_fclk(gp32_state *state, int reg);
51static UINT32 s3c240x_get_hclk(gp32_state *state, int reg);
52static UINT32 s3c240x_get_pclk(gp32_state *state, int reg);
53
54static void s3c240x_dma_request_iis( running_machine &machine);
55static void s3c240x_dma_request_pwm( running_machine &machine);
56
5750// LCD CONTROLLER
5851
5952
r20915r20916
7366   return MAKE_RGB( r | i, g | i, b | i);
7467}
7568
76static void s3c240x_lcd_dma_reload( running_machine &machine)
69void gp32_state::s3c240x_lcd_dma_reload()
7770{
78   gp32_state *state = machine.driver_data<gp32_state>();
79   state->m_s3c240x_lcd.vramaddr_cur = state->m_s3c240x_lcd_regs[5] << 1;
80   state->m_s3c240x_lcd.vramaddr_max = ((state->m_s3c240x_lcd_regs[5] & 0xFFE00000) | state->m_s3c240x_lcd_regs[6]) << 1;
81   state->m_s3c240x_lcd.offsize = BITS( state->m_s3c240x_lcd_regs[7], 21, 11);
82   state->m_s3c240x_lcd.pagewidth_cur = 0;
83   state->m_s3c240x_lcd.pagewidth_max = BITS( state->m_s3c240x_lcd_regs[7], 10, 0);
84   verboselog( machine, 3, "LCD - vramaddr %08X %08X offsize %08X pagewidth %08X\n", state->m_s3c240x_lcd.vramaddr_cur, state->m_s3c240x_lcd.vramaddr_max, state->m_s3c240x_lcd.offsize, state->m_s3c240x_lcd.pagewidth_max);
71   m_s3c240x_lcd.vramaddr_cur = m_s3c240x_lcd_regs[5] << 1;
72   m_s3c240x_lcd.vramaddr_max = ((m_s3c240x_lcd_regs[5] & 0xFFE00000) | m_s3c240x_lcd_regs[6]) << 1;
73   m_s3c240x_lcd.offsize = BITS( m_s3c240x_lcd_regs[7], 21, 11);
74   m_s3c240x_lcd.pagewidth_cur = 0;
75   m_s3c240x_lcd.pagewidth_max = BITS( m_s3c240x_lcd_regs[7], 10, 0);
76   verboselog( machine(), 3, "LCD - vramaddr %08X %08X offsize %08X pagewidth %08X\n", m_s3c240x_lcd.vramaddr_cur, m_s3c240x_lcd.vramaddr_max, m_s3c240x_lcd.offsize, m_s3c240x_lcd.pagewidth_max);
8577}
8678
87static void s3c240x_lcd_dma_init( running_machine &machine)
79void gp32_state::s3c240x_lcd_dma_init()
8880{
89   gp32_state *state = machine.driver_data<gp32_state>();
90   s3c240x_lcd_dma_reload( machine);
91   state->m_s3c240x_lcd.bppmode = BITS( state->m_s3c240x_lcd_regs[0], 4, 1);
92   state->m_s3c240x_lcd.bswp = BIT( state->m_s3c240x_lcd_regs[4], 1);
93   state->m_s3c240x_lcd.hwswp = BIT( state->m_s3c240x_lcd_regs[4], 0);
94   state->m_s3c240x_lcd.lineval = BITS( state->m_s3c240x_lcd_regs[1], 23, 14);
95   state->m_s3c240x_lcd.hozval = BITS( state->m_s3c240x_lcd_regs[2], 18, 8);
81   s3c240x_lcd_dma_reload();
82   m_s3c240x_lcd.bppmode = BITS( m_s3c240x_lcd_regs[0], 4, 1);
83   m_s3c240x_lcd.bswp = BIT( m_s3c240x_lcd_regs[4], 1);
84   m_s3c240x_lcd.hwswp = BIT( m_s3c240x_lcd_regs[4], 0);
85   m_s3c240x_lcd.lineval = BITS( m_s3c240x_lcd_regs[1], 23, 14);
86   m_s3c240x_lcd.hozval = BITS( m_s3c240x_lcd_regs[2], 18, 8);
9687}
9788
9889static UINT32 s3c240x_lcd_dma_read( running_machine &machine)
r20915r20916
266257   verboselog( machine(), 3, "LCD - vpos %d hpos %d\n", m_s3c240x_lcd.vpos, m_s3c240x_lcd.hpos);
267258   if (m_s3c240x_lcd.vramaddr_cur >= m_s3c240x_lcd.vramaddr_max)
268259   {
269      s3c240x_lcd_dma_reload( machine());
260      s3c240x_lcd_dma_reload();
270261   }
271262   verboselog( machine(), 3, "LCD - vramaddr %08X\n", m_s3c240x_lcd.vramaddr_cur);
272263   while (m_s3c240x_lcd.vramaddr_cur < m_s3c240x_lcd.vramaddr_max)
r20915r20916
293284UINT32 gp32_state::screen_update_gp32(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
294285{
295286   copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect);
296   s3c240x_lcd_dma_init( machine());
287   s3c240x_lcd_dma_init();
297288   return 0;
298289}
299290
r20915r20916
315306   return data;
316307}
317308
318static void s3c240x_lcd_configure( running_machine &machine)
309void gp32_state::s3c240x_lcd_configure()
319310{
320   gp32_state *state = machine.driver_data<gp32_state>();
321   screen_device *screen = machine.primary_screen;
311   screen_device *screen = machine().primary_screen;
322312   UINT32 vspw, vbpd, lineval, vfpd, hspw, hbpd, hfpd, hozval, clkval, hclk;
323313   double framerate, vclk;
324314   rectangle visarea;
325   vspw = BITS( state->m_s3c240x_lcd_regs[1], 5, 0);
326   vbpd = BITS( state->m_s3c240x_lcd_regs[1], 31, 24);
327   lineval = BITS( state->m_s3c240x_lcd_regs[1], 23, 14);
328   vfpd = BITS( state->m_s3c240x_lcd_regs[1], 13, 6);
329   hspw = BITS( state->m_s3c240x_lcd_regs[3], 7, 0);
330   hbpd = BITS( state->m_s3c240x_lcd_regs[2], 25, 19);
331   hfpd = BITS( state->m_s3c240x_lcd_regs[2], 7, 0);
332   hozval = BITS( state->m_s3c240x_lcd_regs[2], 18, 8);
333   clkval = BITS( state->m_s3c240x_lcd_regs[0], 17, 8);
334   hclk = s3c240x_get_hclk(state, MPLLCON);
335   verboselog( machine, 3, "LCD - vspw %d vbpd %d lineval %d vfpd %d hspw %d hbpd %d hfpd %d hozval %d clkval %d hclk %d\n", vspw, vbpd, lineval, vfpd, hspw, hbpd, hfpd, hozval, clkval, hclk);
315   vspw = BITS( m_s3c240x_lcd_regs[1], 5, 0);
316   vbpd = BITS( m_s3c240x_lcd_regs[1], 31, 24);
317   lineval = BITS( m_s3c240x_lcd_regs[1], 23, 14);
318   vfpd = BITS( m_s3c240x_lcd_regs[1], 13, 6);
319   hspw = BITS( m_s3c240x_lcd_regs[3], 7, 0);
320   hbpd = BITS( m_s3c240x_lcd_regs[2], 25, 19);
321   hfpd = BITS( m_s3c240x_lcd_regs[2], 7, 0);
322   hozval = BITS( m_s3c240x_lcd_regs[2], 18, 8);
323   clkval = BITS( m_s3c240x_lcd_regs[0], 17, 8);
324   hclk = s3c240x_get_hclk(MPLLCON);
325   verboselog( machine(), 3, "LCD - vspw %d vbpd %d lineval %d vfpd %d hspw %d hbpd %d hfpd %d hozval %d clkval %d hclk %d\n", vspw, vbpd, lineval, vfpd, hspw, hbpd, hfpd, hozval, clkval, hclk);
336326   vclk = (double)(hclk / ((clkval + 1) * 2));
337   verboselog( machine, 3, "LCD - vclk %f\n", vclk);
327   verboselog( machine(), 3, "LCD - vclk %f\n", vclk);
338328   framerate = vclk / (((vspw + 1) + (vbpd + 1) + (lineval + 1) + (vfpd + 1)) * ((hspw + 1) + (hbpd + 1) + (hfpd + 1) + (hozval + 1)));
339   verboselog( machine, 3, "LCD - framerate %f\n", framerate);
329   verboselog( machine(), 3, "LCD - framerate %f\n", framerate);
340330   visarea.set(0, hozval, 0, lineval);
341   verboselog( machine, 3, "LCD - visarea min_x %d min_y %d max_x %d max_y %d\n", visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y);
331   verboselog( machine(), 3, "LCD - visarea min_x %d min_y %d max_x %d max_y %d\n", visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y);
342332   screen->configure(hozval + 1, lineval + 1, visarea, HZ_TO_ATTOSECONDS( framerate));
343333}
344334
345static void s3c240x_lcd_start( running_machine &machine)
335void gp32_state::s3c240x_lcd_start()
346336{
347   gp32_state *state = machine.driver_data<gp32_state>();
348   screen_device *screen = machine.primary_screen;
349   verboselog( machine, 1, "LCD start\n");
350   s3c240x_lcd_configure( machine);
351   s3c240x_lcd_dma_init( machine);
352   state->m_s3c240x_lcd_timer->adjust( screen->time_until_pos(0, 0));
337   screen_device *screen = machine().primary_screen;
338   verboselog( machine(), 1, "LCD start\n");
339   s3c240x_lcd_configure();
340   s3c240x_lcd_dma_init();
341   m_s3c240x_lcd_timer->adjust( screen->time_until_pos(0, 0));
353342}
354343
355static void s3c240x_lcd_stop( running_machine &machine)
344void gp32_state::s3c240x_lcd_stop()
356345{
357   gp32_state *state = machine.driver_data<gp32_state>();
358   verboselog( machine, 1, "LCD stop\n");
359   state->m_s3c240x_lcd_timer->adjust( attotime::never);
346   verboselog( machine(), 1, "LCD stop\n");
347   m_s3c240x_lcd_timer->adjust( attotime::never);
360348}
361349
362static void s3c240x_lcd_recalc( running_machine &machine)
350void gp32_state::s3c240x_lcd_recalc()
363351{
364   gp32_state *state = machine.driver_data<gp32_state>();
365   if (state->m_s3c240x_lcd_regs[0] & 1)
352   if (m_s3c240x_lcd_regs[0] & 1)
366353   {
367      s3c240x_lcd_start( machine);
354      s3c240x_lcd_start();
368355   }
369356   else
370357   {
371      s3c240x_lcd_stop( machine);
358      s3c240x_lcd_stop();
372359   }
373360}
374361
r20915r20916
384371      {
385372         if ((old_value & 1) != (data & 1))
386373         {
387            s3c240x_lcd_recalc( machine());
374            s3c240x_lcd_recalc();
388375         }
389376      }
390377      break;
r20915r20916
415402// CLOCK & POWER MANAGEMENT
416403
417404
418static UINT32 s3c240x_get_fclk(gp32_state *state, int reg)
405UINT32 gp32_state::s3c240x_get_fclk(int reg)
419406{
420407   UINT32 data, mdiv, pdiv, sdiv;
421   data = state->m_s3c240x_clkpow_regs[reg]; // MPLLCON or UPLLCON
408   data = m_s3c240x_clkpow_regs[reg]; // MPLLCON or UPLLCON
422409   mdiv = BITS( data, 19, 12);
423410   pdiv = BITS( data, 9, 4);
424411   sdiv = BITS( data, 1, 0);
425412   return (UINT32)((double)((mdiv + 8) * 12000000) / (double)((pdiv + 2) * (1 << sdiv)));
426413}
427414
428static UINT32 s3c240x_get_hclk(gp32_state *state, int reg)
415UINT32 gp32_state::s3c240x_get_hclk(int reg)
429416{
430   switch (state->m_s3c240x_clkpow_regs[5] & 0x3) // CLKDIVN
417   switch (m_s3c240x_clkpow_regs[5] & 0x3) // CLKDIVN
431418   {
432      case 0 : return s3c240x_get_fclk(state, reg) / 1;
433      case 1 : return s3c240x_get_fclk(state, reg) / 1;
434      case 2 : return s3c240x_get_fclk(state, reg) / 2;
435      case 3 : return s3c240x_get_fclk(state, reg) / 2;
419      case 0 : return s3c240x_get_fclk(reg) / 1;
420      case 1 : return s3c240x_get_fclk(reg) / 1;
421      case 2 : return s3c240x_get_fclk(reg) / 2;
422      case 3 : return s3c240x_get_fclk(reg) / 2;
436423   }
437424   return 0;
438425}
439426
440static UINT32 s3c240x_get_pclk(gp32_state *state, int reg)
427UINT32 gp32_state::s3c240x_get_pclk(int reg)
441428{
442   switch (state->m_s3c240x_clkpow_regs[5] & 0x3) // CLKDIVN
429   switch (m_s3c240x_clkpow_regs[5] & 0x3) // CLKDIVN
443430   {
444      case 0 : return s3c240x_get_fclk(state, reg) / 1;
445      case 1 : return s3c240x_get_fclk(state, reg) / 2;
446      case 2 : return s3c240x_get_fclk(state, reg) / 2;
447      case 3 : return s3c240x_get_fclk(state, reg) / 4;
431      case 0 : return s3c240x_get_fclk(reg) / 1;
432      case 1 : return s3c240x_get_fclk(reg) / 2;
433      case 2 : return s3c240x_get_fclk(reg) / 2;
434      case 3 : return s3c240x_get_fclk(reg) / 4;
448435   }
449436   return 0;
450437}
r20915r20916
465452      // MPLLCON
466453      case 0x04 / 4 :
467454      {
468         gp32_state *state = machine().driver_data<gp32_state>();
469         machine().device("maincpu")->set_unscaled_clock(s3c240x_get_fclk(state, MPLLCON) * CLOCK_MULTIPLIER);
455         m_maincpu->set_unscaled_clock(s3c240x_get_fclk(MPLLCON) * CLOCK_MULTIPLIER);
470456      }
471457      break;
472458   }
r20915r20916
475461// INTERRUPT CONTROLLER
476462
477463
478static void s3c240x_check_pending_irq( running_machine &machine)
464void gp32_state::s3c240x_check_pending_irq()
479465{
480   gp32_state *state = machine.driver_data<gp32_state>();
481   if (state->m_s3c240x_irq_regs[0] != 0)
466   if (m_s3c240x_irq_regs[0] != 0)
482467   {
483468      UINT32 int_type = 0, temp;
484      temp = state->m_s3c240x_irq_regs[0];
469      temp = m_s3c240x_irq_regs[0];
485470      while (!(temp & 1))
486471      {
487472         int_type++;
488473         temp = temp >> 1;
489474      }
490      state->m_s3c240x_irq_regs[4] |= (1 << int_type); // INTPND
491      state->m_s3c240x_irq_regs[5] = int_type; // INTOFFSET
492      machine.device( "maincpu")->execute().set_input_line(ARM7_IRQ_LINE, ASSERT_LINE);
475      m_s3c240x_irq_regs[4] |= (1 << int_type); // INTPND
476      m_s3c240x_irq_regs[5] = int_type; // INTOFFSET
477      m_maincpu->set_input_line(ARM7_IRQ_LINE, ASSERT_LINE);
493478   }
494479   else
495480   {
496      machine.device( "maincpu")->execute().set_input_line(ARM7_IRQ_LINE, CLEAR_LINE);
481      m_maincpu->set_input_line(ARM7_IRQ_LINE, CLEAR_LINE);
497482   }
498483}
499484
500static void s3c240x_request_irq( running_machine &machine, UINT32 int_type)
485void gp32_state::s3c240x_request_irq(UINT32 int_type)
501486{
502   gp32_state *state = machine.driver_data<gp32_state>();
503   verboselog( machine, 5, "request irq %d\n", int_type);
504   if (state->m_s3c240x_irq_regs[0] == 0)
487   verboselog( machine(), 5, "request irq %d\n", int_type);
488   if (m_s3c240x_irq_regs[0] == 0)
505489   {
506      state->m_s3c240x_irq_regs[0] |= (1 << int_type); // SRCPND
507      state->m_s3c240x_irq_regs[4] |= (1 << int_type); // INTPND
508      state->m_s3c240x_irq_regs[5] = int_type; // INTOFFSET
509      machine.device( "maincpu")->execute().set_input_line(ARM7_IRQ_LINE, ASSERT_LINE);
490      m_s3c240x_irq_regs[0] |= (1 << int_type); // SRCPND
491      m_s3c240x_irq_regs[4] |= (1 << int_type); // INTPND
492      m_s3c240x_irq_regs[5] = int_type; // INTOFFSET
493      m_maincpu->set_input_line(ARM7_IRQ_LINE, ASSERT_LINE);
510494   }
511495   else
512496   {
513      state->m_s3c240x_irq_regs[0] |= (1 << int_type); // SRCPND
514      s3c240x_check_pending_irq( machine);
497      m_s3c240x_irq_regs[0] |= (1 << int_type); // SRCPND
498      s3c240x_check_pending_irq();
515499   }
516500}
517501
r20915r20916
534518      case 0x00 / 4 :
535519      {
536520         m_s3c240x_irq_regs[0] = (old_value & ~data); // clear only the bit positions of SRCPND corresponding to those set to one in the data
537         s3c240x_check_pending_irq( machine());
521         s3c240x_check_pending_irq();
538522      }
539523      break;
540524      // INTPND
r20915r20916
580564   return data;
581565}
582566
583static void s3c240x_pwm_start( running_machine &machine, int timer)
567void gp32_state::s3c240x_pwm_start(int timer)
584568{
585   gp32_state *state = machine.driver_data<gp32_state>();
586569   static const int mux_table[] = { 2, 4, 8, 16 };
587570   static const int prescaler_shift[] = { 0, 0, 8, 8, 8 };
588571   static const int mux_shift[] = { 0, 4, 8, 12, 16 };
589572   static const int tcon_shift[] = { 0, 8, 12, 16, 20 };
590   const UINT32 *regs = &state->m_s3c240x_pwm_regs[3+timer*3];
573   const UINT32 *regs = &m_s3c240x_pwm_regs[3+timer*3];
591574   UINT32 prescaler, mux, cnt, cmp, auto_reload;
592575   double freq, hz;
593   verboselog( machine, 1, "PWM %d start\n", timer);
594   prescaler = (state->m_s3c240x_pwm_regs[0] >> prescaler_shift[timer]) & 0xFF;
595   mux = (state->m_s3c240x_pwm_regs[1] >> mux_shift[timer]) & 0x0F;
596   freq = s3c240x_get_pclk(state, MPLLCON) / (prescaler + 1) / mux_table[mux];
576   verboselog( machine(), 1, "PWM %d start\n", timer);
577   prescaler = (m_s3c240x_pwm_regs[0] >> prescaler_shift[timer]) & 0xFF;
578   mux = (m_s3c240x_pwm_regs[1] >> mux_shift[timer]) & 0x0F;
579   freq = s3c240x_get_pclk(MPLLCON) / (prescaler + 1) / mux_table[mux];
597580   cnt = BITS( regs[0], 15, 0);
598581   if (timer != 4)
599582   {
600583      cmp = BITS( regs[1], 15, 0);
601      auto_reload = BIT( state->m_s3c240x_pwm_regs[2], tcon_shift[timer] + 3);
584      auto_reload = BIT( m_s3c240x_pwm_regs[2], tcon_shift[timer] + 3);
602585   }
603586   else
604587   {
605588      cmp = 0;
606      auto_reload = BIT( state->m_s3c240x_pwm_regs[2], tcon_shift[timer] + 2);
589      auto_reload = BIT( m_s3c240x_pwm_regs[2], tcon_shift[timer] + 2);
607590   }
608591   hz = freq / (cnt - cmp + 1);
609   verboselog( machine, 5, "PWM %d - FCLK=%d HCLK=%d PCLK=%d prescaler=%d div=%d freq=%f cnt=%d cmp=%d auto_reload=%d hz=%f\n", timer, s3c240x_get_fclk(state, MPLLCON), s3c240x_get_hclk(state, MPLLCON), s3c240x_get_pclk(state, MPLLCON), prescaler, mux_table[mux], freq, cnt, cmp, auto_reload, hz);
592   verboselog( machine(), 5, "PWM %d - FCLK=%d HCLK=%d PCLK=%d prescaler=%d div=%d freq=%f cnt=%d cmp=%d auto_reload=%d hz=%f\n", timer, s3c240x_get_fclk(MPLLCON), s3c240x_get_hclk(MPLLCON), s3c240x_get_pclk(MPLLCON), prescaler, mux_table[mux], freq, cnt, cmp, auto_reload, hz);
610593   if (auto_reload)
611594   {
612      state->m_s3c240x_pwm_timer[timer]->adjust( attotime::from_hz( hz), timer, attotime::from_hz( hz));
595      m_s3c240x_pwm_timer[timer]->adjust( attotime::from_hz( hz), timer, attotime::from_hz( hz));
613596   }
614597   else
615598   {
616      state->m_s3c240x_pwm_timer[timer]->adjust( attotime::from_hz( hz), timer);
599      m_s3c240x_pwm_timer[timer]->adjust( attotime::from_hz( hz), timer);
617600   }
618601}
619602
620static void s3c240x_pwm_stop( running_machine &machine, int timer)
603void gp32_state::s3c240x_pwm_stop(int timer)
621604{
622   gp32_state *state = machine.driver_data<gp32_state>();
623   verboselog( machine, 1, "PWM %d stop\n", timer);
624   state->m_s3c240x_pwm_timer[timer]->adjust( attotime::never);
605   verboselog( machine(), 1, "PWM %d stop\n", timer);
606   m_s3c240x_pwm_timer[timer]->adjust( attotime::never);
625607}
626608
627static void s3c240x_pwm_recalc( running_machine &machine, int timer)
609void gp32_state::s3c240x_pwm_recalc(int timer)
628610{
629   gp32_state *state = machine.driver_data<gp32_state>();
630611   static const int tcon_shift[] = { 0, 8, 12, 16, 20 };
631   if (state->m_s3c240x_pwm_regs[2] & (1 << tcon_shift[timer]))
612   if (m_s3c240x_pwm_regs[2] & (1 << tcon_shift[timer]))
632613   {
633      s3c240x_pwm_start( machine, timer);
614      s3c240x_pwm_start(timer);
634615   }
635616   else
636617   {
637      s3c240x_pwm_stop( machine, timer);
618      s3c240x_pwm_stop(timer);
638619   }
639620}
640621
r20915r20916
650631      {
651632         if ((data & 1) != (old_value & 1))
652633         {
653            s3c240x_pwm_recalc( machine(), 0);
634            s3c240x_pwm_recalc(0);
654635         }
655636         if ((data & 0x100) != (old_value & 0x100))
656637         {
657            s3c240x_pwm_recalc( machine(), 1);
638            s3c240x_pwm_recalc(1);
658639         }
659640         if ((data & 0x1000) != (old_value & 0x1000))
660641         {
661            s3c240x_pwm_recalc( machine(), 2);
642            s3c240x_pwm_recalc(2);
662643         }
663644         if ((data & 0x10000) != (old_value & 0x10000))
664645         {
665            s3c240x_pwm_recalc( machine(), 3);
646            s3c240x_pwm_recalc(3);
666647         }
667648         if ((data & 0x100000) != (old_value & 0x100000))
668649         {
669            s3c240x_pwm_recalc( machine(), 4);
650            s3c240x_pwm_recalc(4);
670651         }
671652      }
672653   }
r20915r20916
679660   verboselog( machine(), 2, "PWM %d timer callback\n", ch);
680661   if (BITS( m_s3c240x_pwm_regs[1], 23, 20) == (ch + 1))
681662   {
682      s3c240x_dma_request_pwm( machine());
663      s3c240x_dma_request_pwm();
683664   }
684665   else
685666   {
686      s3c240x_request_irq( machine(), ch_int[ch]);
667      s3c240x_request_irq(ch_int[ch]);
687668   }
688669}
689670
690671// DMA
691672
692673
693static void s3c240x_dma_reload( running_machine &machine, int dma)
674void gp32_state::s3c240x_dma_reload(int dma)
694675{
695   gp32_state *state = machine.driver_data<gp32_state>();
696   UINT32 *regs = &state->m_s3c240x_dma_regs[dma<<3];
676   UINT32 *regs = &m_s3c240x_dma_regs[dma<<3];
697677   regs[3] = (regs[3] & ~0x000FFFFF) | BITS( regs[2], 19, 0);
698678   regs[4] = (regs[4] & ~0x1FFFFFFF) | BITS( regs[0], 28, 0);
699679   regs[5] = (regs[5] & ~0x1FFFFFFF) | BITS( regs[1], 28, 0);
700680}
701681
702static void s3c240x_dma_trigger( running_machine &machine, int dma)
682void gp32_state::s3c240x_dma_trigger(int dma)
703683{
704   gp32_state *state = machine.driver_data<gp32_state>();
705   UINT32 *regs = &state->m_s3c240x_dma_regs[dma<<3];
684   UINT32 *regs = &m_s3c240x_dma_regs[dma<<3];
706685   UINT32 curr_tc, curr_src, curr_dst;
707   address_space &space = machine.device( "maincpu")->memory().space( AS_PROGRAM);
686   address_space &space = m_maincpu->space( AS_PROGRAM);
708687   int dsz, inc_src, inc_dst, servmode;
709688   static const UINT32 ch_int[] = { INT_DMA0, INT_DMA1, INT_DMA2, INT_DMA3 };
710   verboselog( machine, 5, "DMA %d trigger\n", dma);
689   verboselog( machine(), 5, "DMA %d trigger\n", dma);
711690   curr_tc = BITS( regs[3], 19, 0);
712691   curr_src = BITS( regs[4], 28, 0);
713692   curr_dst = BITS( regs[5], 28, 0);
r20915r20916
715694   servmode = BIT( regs[2], 26);
716695   inc_src = BIT( regs[0], 29);
717696   inc_dst = BIT( regs[1], 29);
718   verboselog( machine, 5, "DMA %d - curr_src %08X curr_dst %08X curr_tc %d dsz %d\n", dma, curr_src, curr_dst, curr_tc, dsz);
697   verboselog( machine(), 5, "DMA %d - curr_src %08X curr_dst %08X curr_tc %d dsz %d\n", dma, curr_src, curr_dst, curr_tc, dsz);
719698   while (curr_tc > 0)
720699   {
721700      curr_tc--;
r20915r20916
742721      reload = BIT( regs[2], 22);
743722      if (!reload)
744723      {
745         s3c240x_dma_reload( machine, dma);
724         s3c240x_dma_reload(dma);
746725      }
747726      else
748727      {
r20915r20916
751730      _int = BIT( regs[2], 28);
752731      if (_int)
753732      {
754         s3c240x_request_irq( machine, ch_int[dma]);
733         s3c240x_request_irq(ch_int[dma]);
755734      }
756735   }
757736}
758737
759static void s3c240x_dma_request_iis( running_machine &machine)
738void gp32_state::s3c240x_dma_request_iis()
760739{
761   gp32_state *state = machine.driver_data<gp32_state>();
762   UINT32 *regs = &state->m_s3c240x_dma_regs[2<<3];
763   verboselog( machine, 5, "s3c240x_dma_request_iis\n");
740   UINT32 *regs = &m_s3c240x_dma_regs[2<<3];
741   verboselog( machine(), 5, "s3c240x_dma_request_iis\n");
764742   if ((BIT( regs[6], 1) != 0) && (BIT( regs[2], 23) != 0) && (BITS( regs[2], 25, 24) == 0))
765743   {
766      s3c240x_dma_trigger( machine, 2);
744      s3c240x_dma_trigger(2);
767745   }
768746}
769747
770static void s3c240x_dma_request_pwm( running_machine &machine)
748void gp32_state::s3c240x_dma_request_pwm()
771749{
772   gp32_state *state = machine.driver_data<gp32_state>();
773750   int i;
774   verboselog( machine, 5, "s3c240x_dma_request_pwm\n");
751   verboselog( machine(), 5, "s3c240x_dma_request_pwm\n");
775752   for (i = 0; i < 4; i++)
776753   {
777754      if (i != 1)
778755      {
779         UINT32 *regs = &state->m_s3c240x_dma_regs[i<<3];
756         UINT32 *regs = &m_s3c240x_dma_regs[i<<3];
780757         if ((BIT( regs[6], 1) != 0) && (BIT( regs[2], 23) != 0) && (BITS( regs[2], 25, 24) == 3))
781758         {
782            s3c240x_dma_trigger( machine, i);
759            s3c240x_dma_trigger(i);
783760         }
784761      }
785762   }
786763}
787764
788static void s3c240x_dma_start( running_machine &machine, int dma)
765void gp32_state::s3c240x_dma_start(int dma)
789766{
790   gp32_state *state = machine.driver_data<gp32_state>();
791767   UINT32 addr_src, addr_dst, tc;
792   UINT32 *regs = &state->m_s3c240x_dma_regs[dma<<3];
768   UINT32 *regs = &m_s3c240x_dma_regs[dma<<3];
793769   UINT32 dsz, tsz, reload;
794770   int inc_src, inc_dst, _int, servmode, swhwsel, hwsrcsel;
795   verboselog( machine, 1, "DMA %d start\n", dma);
771   verboselog( machine(), 1, "DMA %d start\n", dma);
796772   addr_src = BITS( regs[0], 28, 0);
797773   addr_dst = BITS( regs[1], 28, 0);
798774   tc = BITS( regs[2], 19, 0);
r20915r20916
805781   swhwsel = BIT( regs[2], 23);
806782   reload = BIT( regs[2], 22);
807783   dsz = BITS( regs[2], 21, 20);
808   verboselog( machine, 5, "DMA %d - addr_src %08X inc_src %d addr_dst %08X inc_dst %d int %d tsz %d servmode %d hwsrcsel %d swhwsel %d reload %d dsz %d tc %d\n", dma, addr_src, inc_src, addr_dst, inc_dst, _int, tsz, servmode, hwsrcsel, swhwsel, reload, dsz, tc);
809   verboselog( machine, 5, "DMA %d - copy %08X bytes from %08X (%s) to %08X (%s)\n", dma, tc << dsz, addr_src, inc_src ? "fix" : "inc", addr_dst, inc_dst ? "fix" : "inc");
810   s3c240x_dma_reload( machine, dma);
784   verboselog( machine(), 5, "DMA %d - addr_src %08X inc_src %d addr_dst %08X inc_dst %d int %d tsz %d servmode %d hwsrcsel %d swhwsel %d reload %d dsz %d tc %d\n", dma, addr_src, inc_src, addr_dst, inc_dst, _int, tsz, servmode, hwsrcsel, swhwsel, reload, dsz, tc);
785   verboselog( machine(), 5, "DMA %d - copy %08X bytes from %08X (%s) to %08X (%s)\n", dma, tc << dsz, addr_src, inc_src ? "fix" : "inc", addr_dst, inc_dst ? "fix" : "inc");
786   s3c240x_dma_reload(dma);
811787   if (swhwsel == 0)
812788   {
813      s3c240x_dma_trigger( machine, dma);
789      s3c240x_dma_trigger(dma);
814790   }
815791}
816792
817static void s3c240x_dma_stop( running_machine &machine, int dma)
793void gp32_state::s3c240x_dma_stop(int dma)
818794{
819   verboselog( machine, 1, "DMA %d stop\n", dma);
795   verboselog( machine(), 1, "DMA %d stop\n", dma);
820796}
821797
822static void s3c240x_dma_recalc( running_machine &machine, int dma)
798void gp32_state::s3c240x_dma_recalc(int dma)
823799{
824   gp32_state *state = machine.driver_data<gp32_state>();
825   if (state->m_s3c240x_dma_regs[(dma<<3)+6] & 2)
800   if (m_s3c240x_dma_regs[(dma<<3)+6] & 2)
826801   {
827      s3c240x_dma_start( machine, dma);
802      s3c240x_dma_start(dma);
828803   }
829804   else
830805   {
831      s3c240x_dma_stop( machine, dma);
806      s3c240x_dma_stop(dma);
832807   }
833808}
834809
r20915r20916
858833      // DMASKTRIG0
859834      case 0x18 / 4 :
860835      {
861         if ((old_value & 2) != (data & 2)) s3c240x_dma_recalc( machine(), 0);
836         if ((old_value & 2) != (data & 2)) s3c240x_dma_recalc(0);
862837      }
863838      break;
864839      // DCON1
r20915r20916
873848      // DMASKTRIG1
874849      case 0x38 / 4 :
875850      {
876         if ((old_value & 2) != (data & 2)) s3c240x_dma_recalc( machine(), 1);
851         if ((old_value & 2) != (data & 2)) s3c240x_dma_recalc(1);
877852      }
878853      break;
879854      // DCON2
r20915r20916
888863      // DMASKTRIG2
889864      case 0x58 / 4 :
890865      {
891         if ((old_value & 2) != (data & 2)) s3c240x_dma_recalc( machine(), 2);
866         if ((old_value & 2) != (data & 2)) s3c240x_dma_recalc(2);
892867      }
893868      break;
894869      // DCON3
r20915r20916
903878      // DMASKTRIG3
904879      case 0x78 / 4 :
905880      {
906         if ((old_value & 2) != (data & 2)) s3c240x_dma_recalc( machine(), 3);
881         if ((old_value & 2) != (data & 2)) s3c240x_dma_recalc(3);
907882      }
908883      break;
909884   }
r20915r20916
14051380         transmit_clock_value = (data >> 0) & 0xF;
14061381         tx_clock_source_selection = (data >> 6) & 1;
14071382         enable_interrupt = (data >> 5) & 1;
1408         clock = (double)(s3c240x_get_pclk(state, MPLLCON) / div_table[tx_clock_source_selection] / (transmit_clock_value + 1));
1383         clock = (double)(s3c240x_get_pclk(MPLLCON) / div_table[tx_clock_source_selection] / (transmit_clock_value + 1));
14091384#endif
14101385         interrupt_pending_flag = BIT( data, 4);
14111386         if (interrupt_pending_flag == 0)
r20915r20916
14811456   enable_interrupt = BIT( m_s3c240x_iic_regs[0], 5);
14821457   if (enable_interrupt)
14831458   {
1484      s3c240x_request_irq( machine(), INT_IIC);
1459      s3c240x_request_irq(INT_IIC);
14851460   }
14861461}
14871462
14881463// IIS
14891464
1490static void s3c240x_iis_start( running_machine &machine)
1465void gp32_state::s3c240x_iis_start()
14911466{
1492   gp32_state *state = machine.driver_data<gp32_state>();
14931467   static const UINT32 codeclk_table[] = { 256, 384 };
14941468   double freq;
14951469   int prescaler_enable, prescaler_control_a, prescaler_control_b, codeclk;
1496   verboselog( machine, 1, "IIS start\n");
1497   prescaler_enable = BIT( state->m_s3c240x_iis_regs[0], 1);
1498   prescaler_control_a = BITS( state->m_s3c240x_iis_regs[2], 9, 5);
1499   prescaler_control_b = BITS( state->m_s3c240x_iis_regs[2], 4, 0);
1500   codeclk = BIT( state->m_s3c240x_iis_regs[1], 2);
1501   freq = (double)(s3c240x_get_pclk(state, MPLLCON) / (prescaler_control_a + 1) / codeclk_table[codeclk]) * 2; // why do I have to multiply by two?
1502   verboselog( machine, 5, "IIS - pclk %d psc_enable %d psc_a %d psc_b %d codeclk %d freq %f\n", s3c240x_get_pclk(state, MPLLCON), prescaler_enable, prescaler_control_a, prescaler_control_b, codeclk_table[codeclk], freq);
1503   state->m_s3c240x_iis_timer->adjust( attotime::from_hz( freq), 0, attotime::from_hz( freq));
1470   verboselog( machine(), 1, "IIS start\n");
1471   prescaler_enable = BIT( m_s3c240x_iis_regs[0], 1);
1472   prescaler_control_a = BITS( m_s3c240x_iis_regs[2], 9, 5);
1473   prescaler_control_b = BITS( m_s3c240x_iis_regs[2], 4, 0);
1474   codeclk = BIT( m_s3c240x_iis_regs[1], 2);
1475   freq = (double)(s3c240x_get_pclk(MPLLCON) / (prescaler_control_a + 1) / codeclk_table[codeclk]) * 2; // why do I have to multiply by two?
1476   verboselog( machine(), 5, "IIS - pclk %d psc_enable %d psc_a %d psc_b %d codeclk %d freq %f\n", s3c240x_get_pclk(MPLLCON), prescaler_enable, prescaler_control_a, prescaler_control_b, codeclk_table[codeclk], freq);
1477   m_s3c240x_iis_timer->adjust( attotime::from_hz( freq), 0, attotime::from_hz( freq));
15041478}
15051479
1506static void s3c240x_iis_stop( running_machine &machine)
1480void gp32_state::s3c240x_iis_stop()
15071481{
1508   gp32_state *state = machine.driver_data<gp32_state>();
1509   verboselog( machine, 1, "IIS stop\n");
1510   state->m_s3c240x_iis_timer->adjust( attotime::never);
1482   verboselog( machine(), 1, "IIS stop\n");
1483   m_s3c240x_iis_timer->adjust( attotime::never);
15111484}
15121485
1513static void s3c240x_iis_recalc( running_machine &machine)
1486void gp32_state::s3c240x_iis_recalc()
15141487{
1515   gp32_state *state = machine.driver_data<gp32_state>();
1516   if (state->m_s3c240x_iis_regs[0] & 1)
1488   if (m_s3c240x_iis_regs[0] & 1)
15171489   {
1518      s3c240x_iis_start( machine);
1490      s3c240x_iis_start();
15191491   }
15201492   else
15211493   {
1522      s3c240x_iis_stop( machine);
1494      s3c240x_iis_stop();
15231495   }
15241496}
15251497
r20915r20916
15511523      // IISCON
15521524      case 0x00 / 4 :
15531525      {
1554         if ((old_value & 1) != (data & 1)) s3c240x_iis_recalc( machine());
1526         if ((old_value & 1) != (data & 1)) s3c240x_iis_recalc();
15551527      }
15561528      break;
15571529      // IISFIF
r20915r20916
15821554TIMER_CALLBACK_MEMBER(gp32_state::s3c240x_iis_timer_exp)
15831555{
15841556   verboselog( machine(), 2, "IIS timer callback\n");
1585   s3c240x_dma_request_iis( machine());
1557   s3c240x_dma_request_iis();
15861558}
15871559
15881560// RTC

Previous 199869 Revisions Next


© 1997-2024 The MAME Team