Previous 15994 Revisions Next

r2235 Thursday 3rd April, 2008 at 16:54:40 UTC by Wilbert Pol
Updated pit8253 to a device.
[src/emu]devconv.h*
[src/emu/machine]pit8253.c pit8253.h
[src/mess/audio]dai.c pc.c pc.h
[src/mess/drivers]bebox.c bw2.c dai.c ip22.c mz700.c pasogo.c pc.c pmd85.c special.c
[src/mess/includes]bebox.h compis.h dai.h mz700.h pmd85.h special.h
[src/mess/machine]amstr_pc.c at.c bebox.c compis.c dai.c europc.c ibmpc.c mz700.c pc.c pmd85.c special.c tandy1t.c
[src/mess/video]mz700.c

src/emu/machine/pit8253.c
r2234r2235
88 *  8254 has an additional readback feature
99 *
1010 *  Revision History
11 *      1-Apr-2008 - WFP:   Changed the implementation into a device.
1112 *      8-Jul-2004 - AJ:    Fixed some bugs. Styx now runs correctly.
1213 *                          Implemented 8254 features.
1314 *      1-Mar-2004 - NPW:   Did an almost total rewrite and cleaned out much
r2234r2235
1920
2021#include <math.h>
2122#include "driver.h"
22#include "memconv.h"
23#include "devconv.h"
2324#include "machine/pit8253.h"
2425
2526
r2234r2235
4142
4243#define   CYCLES_NEVER ((UINT32) -1)
4344
45/* device types */
46enum {
47   TYPE_PIT8253 = 0,
48   TYPE_PIT8254,
49
50   NUM_TYPES
51};
52
53
54/* device tags */
55static const char * const device_tags[NUM_TYPES] = { "pit8253", "pit8254" };
56
57
4458struct pit8253_timer
4559{
4660   double clockin;               /* input clock frequency in Hz */
4761
48   void (*output_callback_func)(int);   /* callback function for when output changes */
49   void (*freq_callback)(double);   /* callback function for when output frequency changes */
62   pit8253_output_changed_func      output_changed;   /* callback function for when output changes */
63   pit8253_frequency_changed_func   frequency_changed;   /* callback function for when output frequency changes */
5064
5165   attotime last_updated;         /* time when last updated */
5266
r2234r2235
7488   UINT32 freq_count;            /* counter period for periodic modes, 0 if counter non-periodic */
7589};
7690
77struct pit8253
91typedef struct _pit8253_t   pit8253_t;
92struct _pit8253_t
7893{
7994   const struct pit8253_config *config;
95   int   device_type;
8096   struct pit8253_timer timers[MAX_TIMER];
8197};
8298
r2234r2235
85101#define   CTRL_BCD(control)         (((control)   >> 0) &   0x01)
86102
87103
88static int pit_count;
89static struct pit8253 *pits;
90
91
92
93104/***************************************************************************
94105
95106    Functions
96107
97108***************************************************************************/
98109
99static struct pit8253 *get_pit(int which)
100{
101   return &pits[which];
110/* makes sure that the passed in device is of the right type */
111INLINE pit8253_t *get_safe_token(const device_config *device) {
112   assert( device != NULL );
113   assert( device->token != NULL );
114   assert( ( device->type == DEVICE_GET_INFO_NAME(pit8253) ) ||
115          ( device->type == DEVICE_GET_INFO_NAME(pit8254) ) );
116   return ( pit8253_t * ) device->token;
102117}
103118
104119
105static struct pit8253_timer   *get_timer(struct pit8253 *pit,int which)
120static struct pit8253_timer   *get_timer(struct _pit8253_t *pit,int which)
106121{
107122   which &= 3;
108123   if (which < MAX_TIMER)
r2234r2235
111126}
112127
113128
114static UINT32 decimal_from_bcd(UINT16 val)
129INLINE UINT32 decimal_from_bcd(UINT16 val)
115130{
116131   /* In BCD mode, a nybble loaded with value A-F counts down the same as in
117132       binary mode, but wraps around to 9 instead of F after 0, so loading the
r2234r2235
208223{
209224   LOG2(("pit8253: freq_callback_in(): %d cycles\n",cycles));
210225
211   if (timer->freq_callback ==   NULL)
226   if (timer->frequency_changed == NULL)
212227   {
213228      return;
214229   }
r2234r2235
225240}
226241
227242
228static void   set_freq_count(struct pit8253_timer   *timer)
243static void   set_freq_count(const device_config *device, struct pit8253_timer *timer)
229244{
230245   int   mode = CTRL_MODE(timer->control);
231246   UINT32 freq_count;
r2234r2235
242257   if (freq_count != timer->freq_count)
243258   {
244259      timer->freq_count =   freq_count;
245      if (timer->freq_callback !=   NULL)
260      if (timer->frequency_changed != NULL)
246261      {
247         timer->freq_callback(get_frequency(timer));
262         timer->frequency_changed(device, get_frequency(timer));
248263         freq_callback_in(timer,CYCLES_NEVER);
249264      }
250265   }
r2234r2235
254269
255270
256271/* Call the output callback in "cycles" cycles */
257static void   trigger_countdown(struct pit8253_timer *timer)
272static void   trigger_countdown(const device_config *device, struct pit8253_timer *timer)
258273{
259274   LOG2(("pit8253: trigger_countdown()\n"));
260275
r2234r2235
263278   if (CTRL_MODE(timer->control) == 3 && timer->output   == 0)
264279      timer->value &=   0xfffe;
265280
266   set_freq_count(timer);
281   set_freq_count(device, timer);
267282}
268283
269284
270static void   set_output(struct pit8253_timer   *timer,int output)
285static void   set_output(const device_config *device, struct pit8253_timer *timer,int output)
271286{
272287   if (output != timer->output)
273288   {
274289      timer->output =   output;
275      if (timer->output_callback_func != NULL)
290      if (timer->output_changed != NULL)
276291      {
277         timer->output_callback_func(output);
292         timer->output_changed(device, output);
278293      }
279294   }
280295}
r2234r2235
282297
283298/* This emulates timer "timer" for "elapsed_cycles" cycles and assumes no
284299   callbacks occur during that time. */
285static void   simulate2(struct pit8253_timer *timer,UINT64 elapsed_cycles)
300static void   simulate2(const device_config *device, struct pit8253_timer *timer,UINT64 elapsed_cycles)
286301{
287302   UINT32 adjusted_value;
288303   int   bcd   = CTRL_BCD(timer->control);
r2234r2235
358373         }
359374      }
360375
361      set_output(timer,timer->phase == 3 ? 1 : 0);
376      set_output(device, timer, timer->phase == 3 ? 1 : 0);
362377      break;
363378
364379
r2234r2235
397412         decrease_counter_value(timer,elapsed_cycles);
398413         cycles_to_output = CYCLES_NEVER;
399414      }
400      set_output(timer,timer->phase == 0 ? 1 : 0);
415      set_output(device, timer, timer->phase == 0 ? 1 : 0);
401416      break;
402417
403418
r2234r2235
427442      if (timer->gate   == 0 ||   timer->phase ==   0)
428443      {
429444         /* Gate low or mode control write forces output high */
430         set_output(timer,1);
445         set_output(device, timer, 1);
431446         cycles_to_output = CYCLES_NEVER;
432447      }
433448      else
r2234r2235
442457         {
443458            /* Counter wrapped around one or more times */
444459            elapsed_cycles -= adjusted_value;
445            trigger_countdown(timer);
460            trigger_countdown(device, timer);
446461            decrease_counter_value(timer,elapsed_cycles   % adjusted_count(bcd,timer->count));
447462         }
448463         cycles_to_output = (timer->value ==   1 ?   1 :   (adjusted_count(bcd,timer->value) -   1));
449464
450         set_output(timer,timer->value != 1 ? 1 : 0);
465         set_output(device, timer, timer->value != 1 ? 1 : 0);
451466      }
452467      break;
453468
r2234r2235
477492      if (timer->gate   == 0 ||   timer->phase ==   0)
478493      {
479494         /* Gate low or mode control write forces output high */
480         set_output(timer,1);
495         set_output(device, timer, 1);
481496         cycles_to_output = CYCLES_NEVER;
482497      }
483498      else
r2234r2235
493508            /* Counter wrapped around one or more times */
494509            elapsed_cycles -= ((adjusted_value+1)>>1);
495510
496            set_output(timer,1 - timer->output);
497            trigger_countdown(timer);
511            set_output(device, timer, 1 - timer->output);
512            trigger_countdown(device, timer);
498513
499514            elapsed_cycles %= adjusted_count(bcd,timer->count);
500515            adjusted_value = adjusted_count(bcd,timer->value);
r2234r2235
503518               /* Counter wrapped around an even number of times */
504519               elapsed_cycles -= ((adjusted_value+1)>>1);
505520
506               set_output(timer,1 - timer->output);
507               trigger_countdown(timer);
521               set_output(device, timer, 1 - timer->output);
522               trigger_countdown(device, timer);
508523            }
509524            decrease_counter_value(timer,elapsed_cycles<<1);
510525         }
r2234r2235
598613            break;
599614         }
600615      }
601      set_output(timer,timer->phase != 3 ? 1 : 0);
616      set_output(device, timer, timer->phase != 3 ? 1 : 0);
602617      break;
603618   }
604619
605   if (timer->output_callback_func != NULL)
620   if (timer->output_changed != NULL)
606621   {
607622      timer->cycles_to_output   = cycles_to_output;
608623      if (cycles_to_output ==   CYCLES_NEVER ||   timer->clockin == 0)
r2234r2235
638653   inaccurate by more than one cycle, and the output changed multiple
639654   times during the discrepancy. In practice updates should still be O(1).
640655*/
641static void   simulate(struct   pit8253_timer *timer,UINT64   elapsed_cycles)
656static void   simulate(const device_config *device, struct pit8253_timer *timer,UINT64 elapsed_cycles)
642657{
643658   while ((timer->cycles_to_output   != CYCLES_NEVER   &&
644659         timer->cycles_to_output   <= elapsed_cycles) ||
r2234r2235
657672         cycles_to_callback = timer->cycles_to_freq;
658673      }
659674
660      simulate2(timer,cycles_to_callback);
675      simulate2(device, timer, cycles_to_callback);
661676      elapsed_cycles -= cycles_to_callback;
662677   }
663   simulate2(timer,elapsed_cycles);
678   simulate2(device, timer, elapsed_cycles);
664679}
665680
666681
667682/* This brings timer "timer" up to date */
668static void   update(struct pit8253_timer   *timer)
683static void   update(const device_config *device, struct pit8253_timer *timer)
669684{
670685   /* With the 82C54's maximum clockin of 10MHz, 64 bits is nearly 60,000
671686       years of time. Should be enough for now. */
r2234r2235
675690
676691   timer->last_updated   = attotime_add(timer->last_updated,double_to_attotime(elapsed_cycles/timer->clockin));
677692
678   simulate(timer,elapsed_cycles);
693   simulate(device, timer,elapsed_cycles);
679694}
680695
681696
682void pit8253_reset(int which)
697static TIMER_CALLBACK( frequency_changed )
683698{
684   struct pit8253 *pit   = get_pit(which);
685   struct pit8253_timer *timer;
686   int   i;
687
688   LOG1(("pit8253_reset(): resetting pit %d\n", which));
689
690   for   (i = 0;   i <   MAX_TIMER; i++)
691   {
692      timer =   get_timer(pit,i);
693      /* According to Intel's 8254 docs, the state of a timer is undefined
694           until the first mode control word is written. Here we define this
695           undefined behaviour */
696      timer->control = timer->status = 0x30;
697      timer->rmsb   = timer->wmsb =   0;
698      timer->count = timer->value   = timer->latch = 0;
699      timer->lowcount   = 0;
700      timer->gate   = 1;
701      timer->output =   0;
702      timer->latched_count = 0;
703      timer->latched_status =   0;
704      timer->null_count =   1;
705      timer->cycles_to_output   = timer->cycles_to_freq   = CYCLES_NEVER;
706
707      timer->last_updated   = timer_get_time();
708
709      update(timer);
710   }
711}
712
713
714static TIMER_CALLBACK( freqcallback )
715{
716   struct pit8253_timer *timer = get_timer(get_pit(param &   0x0F),(param >>   4) & 0x0F);
699   const device_config *device = ptr;
700   pit8253_t   *pit8253 = get_safe_token(device);
701   struct pit8253_timer *timer = get_timer(pit8253,param);
717702   INT64 cycles =   timer->cycles_to_freq;
718703   double t;
719704
720   LOG2(("pit8253: freqcallback(): pit %d, timer %d, %d cycles\n",param & 0xf,(param >> 4) & 0xf,(UINT32)cycles));
705   LOG2(("pit8253: frequency_changed(): timer %d, %d cycles\n",param,(UINT32)cycles));
721706
722   simulate(timer,cycles);
707   simulate(device, timer,cycles);
723708
724709   t = cycles / timer->clockin;
725710
r2234r2235
727712}
728713
729714
730static TIMER_CALLBACK( outputcallback )
715static TIMER_CALLBACK( output_changed )
731716{
732   struct pit8253_timer *timer = get_timer(get_pit(param &   0x0F),(param >>   4) & 0x0F);
717   const device_config *device = ptr;
718   pit8253_t   *pit8253 = get_safe_token(device);
719   struct pit8253_timer *timer = get_timer(pit8253,param);
733720   INT64 cycles =   timer->cycles_to_output;
734721   double t;
735722
736   LOG2(("pit8253: outputcallback(): pit %d, timer %d, %d cycles\n",param & 0xf,(param >> 4) & 0xf,(UINT32)cycles));
723   LOG2(("pit8253: output_changed(): timer %d, %d cycles\n",param,(UINT32)cycles));
737724
738   simulate(timer,cycles);
725   simulate(device, timer,cycles);
739726
740727   t = cycles / timer->clockin;
741728
r2234r2235
743730}
744731
745732
746int   pit8253_init(int count,   const struct pit8253_config *config)
747{
748   int   i, timerno,   n=0;
749   struct pit8253 *pit;
750   struct pit8253_timer *timer;
751
752   LOG2(("pit8253_init(): initializing %d pit(s)\n", count));
753
754   pit_count =   count;
755   pits = auto_malloc(count * sizeof(struct pit8253));
756
757   memset(pits, 0,   count *   sizeof(struct pit8253));
758
759   for (i = 0;   i < count; i++)
760   {
761      pit   = get_pit(i);
762      pit->config   = &config[i];
763
764      for   (timerno = 0; timerno <   MAX_TIMER; timerno++)
765      {
766         timer =   get_timer(pit,timerno);
767
768         timer->clockin = pit->config->timer[timerno].clockin;
769         timer->output_callback_func = pit->config->timer[timerno].output_callback_func;
770         timer->freq_callback = pit->config->timer[timerno].clock_callback;
771
772         if (timer->output_callback_func == NULL)
773            timer->outputtimer = NULL;
774         else
775         {
776            timer->outputtimer = timer_alloc(outputcallback, NULL);
777            timer_adjust_oneshot(timer->outputtimer, attotime_never, i   | (timerno<<4));
778         }
779         if (timer->freq_callback ==   NULL)
780            timer->freqtimer = NULL;
781         else
782         {
783            timer->freqtimer = timer_alloc(freqcallback, NULL);
784            timer_adjust_oneshot(timer->freqtimer,   attotime_never,   i |   (timerno<<4));
785         }
786
787         /* set up state save values */
788         state_save_register_item("pit8253", n, timer->clockin);
789         state_save_register_item("pit8253", n, timer->control);
790         state_save_register_item("pit8253", n, timer->status);
791         state_save_register_item("pit8253", n, timer->lowcount);
792         state_save_register_item("pit8253", n, timer->latch);
793         state_save_register_item("pit8253", n, timer->count);
794         state_save_register_item("pit8253", n, timer->value);
795         state_save_register_item("pit8253", n, timer->wmsb);
796         state_save_register_item("pit8253", n, timer->rmsb);
797         state_save_register_item("pit8253", n, timer->output);
798         state_save_register_item("pit8253", n, timer->gate);
799         state_save_register_item("pit8253", n, timer->latched_count);
800         state_save_register_item("pit8253", n, timer->latched_status);
801         state_save_register_item("pit8253", n, timer->null_count);
802         state_save_register_item("pit8253", n, timer->phase);
803         state_save_register_item("pit8253", n, timer->cycles_to_output);
804         state_save_register_item("pit8253", n, timer->cycles_to_freq);
805         state_save_register_item("pit8253", n, timer->freq_count);
806         state_save_register_item("pit8253", n, timer->last_updated.seconds);
807         state_save_register_item("pit8253", n, timer->last_updated.attoseconds);
808         ++n;
809      }
810      pit8253_reset(i);
811   }
812
813   LOG1(("pit8253_init(): initialized successfully\n"));
814
815   return 0;
816}
817
818
819733/* We recycle bit 0 of timer->value to hold the phase in mode 3 when count is
820734   odd. Since read commands in mode 3 always return even numbers, we need to
821735   mask this bit off. */
r2234r2235
833747     latched_count
834748     rmsb
835749  so they don't affect any timer operations except other reads. */
836static UINT8 pit8253_read(int   which,offs_t offset)
750READ8_DEVICE_HANDLER( pit8253_r )
837751{
838   struct pit8253 *pit   = get_pit(which);
839   struct pit8253_timer *timer   = get_timer(pit,offset);
752   pit8253_t   *pit8253 = get_safe_token(device);
753   struct pit8253_timer *timer   = get_timer(pit8253,offset);
840754   UINT8   data;
841755   UINT16 value;
842756
843   LOG2(("pit8253_read(): pit %d, offset %d\n",which,offset));
757   LOG2(("pit8253_r(): offset %d\n", offset));
844758
845759   if (timer == NULL)
846760   {
r2234r2235
850764   }
851765   else
852766   {
853      update(timer);
767      update(device, timer);
854768
855769      if (timer->latched_status)
856770      {
r2234r2235
898812      }
899813   }
900814
901   LOG2(("pit8253_read(): PIT #%d offset=%d data=0x%02x\n", which, (int) offset, (unsigned) data));
815   LOG2(("pit8253_r(): offset=%d data=0x%02x\n", offset, data));
902816   return data;
903817}
904818
905819
906820/* Loads a new value from the bus to the count register (CR) */
907static void   load_count(struct pit8253_timer   *timer,   UINT16 newcount)
821static void   load_count(const device_config *device, struct pit8253_timer *timer, UINT16 newcount)
908822{
909823   int   mode = CTRL_MODE(timer->control);
910824
r2234r2235
925839   {
926840      if (timer->phase ==   0)
927841      {
928         trigger_countdown(timer);
842         trigger_countdown(device, timer);
929843      }
930844      else
931845      {
r2234r2235
944858   {
945859      if (mode ==   0 || mode == 4)
946860      {
947         trigger_countdown(timer);
861         trigger_countdown(device, timer);
948862      }
949863   }
950864}
951865
952866
953static void   readback(struct   pit8253_timer *timer,int command)
867static void   readback(const device_config *device, struct pit8253_timer *timer,int command)
954868{
955869   UINT16 value;
956   update(timer);
870   update(device, timer);
957871
958872   if ((command & 1) == 0)
959873   {
r2234r2235
1002916}
1003917
1004918
1005static void   pit8253_write(int which, offs_t   offset,   int   data)
919WRITE8_DEVICE_HANDLER( pit8253_w )
1006920{
1007   struct pit8253 *pit   = get_pit(which);
1008   struct pit8253_timer *timer   = get_timer(pit,offset);
921   pit8253_t   *pit8253 = get_safe_token(device);
922   struct pit8253_timer *timer   = get_timer(pit8253,offset);
1009923   int   read_command;
1010924
1011   LOG2(("pit8253_write(): PIT #%d offset=%d data=0x%02x\n", which, (int) offset, (unsigned) data));
925   LOG2(("pit8253_w(): offset=%d data=0x%02x\n", offset, data));
1012926
1013927   if (timer == NULL) {
1014928      /* Write to mode control register */
1015      timer =   get_timer(pit, (data >>   6) & 3);
929      timer =   get_timer(pit8253, (data >>   6) & 3);
1016930      if (timer == NULL)
1017931      {
1018932         /* Readback command. Illegal on 8253 */
1019933         /* Todo: find out what (if anything) the 8253 hardware actually does here. */
1020         if (pit->config->type == TYPE8254)
934         if (pit8253->device_type == TYPE_PIT8254)
1021935         {
1022            LOG1(("pit8253_write(): PIT #%d readback %02x\n", which, data & 0x3f));
936            LOG1(("pit8253_w(): readback %02x\n", data & 0x3f));
1023937
1024938            /* Bit 0 of data must be 0. Todo: find out what the hardware does if it isn't. */
1025939            read_command = (data >>   4) & 3;
1026940            if ((data &   2) != 0)
1027               readback(get_timer(pit,0),read_command);
941               readback(device, get_timer(pit8253,0), read_command);
1028942            if ((data &   4) != 0)
1029               readback(get_timer(pit,1),read_command);
943               readback(device, get_timer(pit8253,1), read_command);
1030944            if ((data &   8) != 0)
1031               readback(get_timer(pit,2),read_command);
945               readback(device, get_timer(pit8253,2), read_command);
1032946         }
1033947         return;
1034948      }
1035949
1036      update(timer);
950      update(device, timer);
1037951
1038952      if (CTRL_ACCESS(data) == 0)
1039953      {
1040         LOG1(("pit8253_write(): PIT #%d timer=%d readback\n", which, (data >> 6) & 3));
954         LOG1(("pit8253_write(): timer=%d readback\n", (data >> 6) & 3));
1041955
1042956         /* Latch current timer value */
1043957         /* Experimentally verified: this command does not affect the mode control register */
1044         readback(timer,1);
958         readback(device, timer, 1);
1045959      }
1046960      else {
1047         LOG1(("pit8253_write(): PIT #%d timer=%d bytes=%d mode=%d bcd=%d\n", which, (data >> 6) & 3, (data >> 4) & 3, (data >> 1) & 7,data & 1));
961         LOG1(("pit8253_write(): timer=%d bytes=%d mode=%d bcd=%d\n", (data >> 6) & 3, (data >> 4) & 3, (data >> 1) & 7,data & 1));
1048962
1049963         timer->control = (data & 0x3f);
1050964         timer->null_count =   1;
1051965         timer->wmsb   = timer->rmsb =   0;
1052966         /* Phase 0 is always the phase after a mode control write */
1053967         timer->phase = 0;
1054         set_output(timer,1);
1055         set_freq_count(timer);
968         set_output(device, timer, 1);
969         set_freq_count(device, timer);
1056970      }
1057971   }
1058972   else
1059973   {
1060      update(timer);
974      update(device, timer);
1061975
1062976      switch(CTRL_ACCESS(timer->control))   {
1063977      case 0:
r2234r2235
1066980
1067981      case 1:
1068982         /* read/write counter bits 0-7 only */
1069         load_count(timer,data);
983         load_count(device, timer, data);
1070984         break;
1071985
1072986      case 2:
1073987         /* read/write counter bits 8-15 only */
1074         load_count(timer,data << 8);
988         load_count(device, timer, data << 8);
1075989         break;
1076990
1077991      case 3:
1078992         /* read/write bits 0-7 first, then 8-15 */
1079993         if (timer->wmsb   != 0)
1080994         {
1081            load_count(timer,timer->lowcount | (data <<   8));
995            load_count(device, timer,timer->lowcount | (data << 8));
1082996         }
1083997         else
1084998         {
r2234r2235
10951009         break;
10961010      }
10971011   }
1098   update(timer);
1012   update(device, timer);
10991013}
11001014
11011015
1102static void   pit8253_gate_write(int which,int offset,int   data)
1016WRITE8_DEVICE_HANDLER( pit8253_gate_w )
11031017{
1104   struct pit8253_timer *timer   = get_timer(get_pit(which),offset);
1018   pit8253_t   *pit8253 = get_safe_token(device);
1019   struct pit8253_timer *timer   = get_timer(pit8253,offset);
11051020   int   mode;
11061021   int   gate = (data!=0   ? 1   : 0);
11071022
1108   LOG2(("pit8253_gate_write(): PIT #%d offset=%d gate=%d\n", which, (int) offset, (unsigned) data));
1023   LOG2(("pit8253_gate_w(): offset=%d gate=%d\n", offset, data));
11091024
11101025   if (timer == NULL)
11111026      return;
r2234r2235
11141029
11151030   if (gate !=   timer->gate)
11161031   {
1117      update(timer);
1032      update(device, timer);
11181033      timer->gate   = gate;
1119      set_freq_count(timer);
1034      set_freq_count(device, timer);
11201035      if (gate !=   0 &&
11211036         (mode == 1 || mode == 5   ||
11221037          (timer->phase == 1   && (mode ==   2 || mode == 3))))
11231038      {
1124         trigger_countdown(timer);
1039         trigger_countdown(device, timer);
11251040      }
1126      update(timer);
1041      update(device, timer);
11271042   }
11281043}
11291044
r2234r2235
11311046
11321047/* ----------------------------------------------------------------------- */
11331048
1134int   pit8253_get_frequency(int which, int timerno)
1049int   pit8253_get_frequency(const device_config *device, int timerno)
11351050{
1136   struct pit8253_timer *timer   = get_timer(get_pit(which),timerno);
1051   pit8253_t   *pit8253 = get_safe_token(device);
1052   struct pit8253_timer *timer   = get_timer(pit8253,timerno);
11371053
1138   update(timer);
1054   update(device, timer);
11391055   return get_frequency(timer);
11401056}
11411057
11421058
11431059
1144int   pit8253_get_output(int which, int timerno)
1060int   pit8253_get_output(const device_config *device, int timerno)
11451061{
1146   struct pit8253_timer *timer   = get_timer(get_pit(which),timerno);
1062   pit8253_t   *pit8253 = get_safe_token(device);
1063   struct pit8253_timer *timer   = get_timer(pit8253,timerno);
11471064   int   result;
11481065
1149   update(timer);
1066   update(device, timer);
11501067   result = timer->output;
1151   LOG2(("pit8253_get_output(): PIT #%d timer=%d result=%d\n", which, timerno, result));
1068   LOG2(("pit8253_get_output(): PIT timer=%d result=%d\n", timerno, result));
11521069   return result;
11531070}
11541071
11551072
11561073
1157void pit8253_set_clockin(int which,   int   timerno, double   new_clockin)
1074void pit8253_set_clockin(const device_config *device, int timerno, double new_clockin)
11581075{
1159   struct pit8253_timer *timer   = get_timer(get_pit(which),timerno);
1076   pit8253_t   *pit8253 = get_safe_token(device);
1077   struct pit8253_timer *timer   = get_timer(pit8253,timerno);
11601078
1161   LOG2(("pit8253_set_clockin(): PIT #%d timer=%d, clockin = %lf\n", which, (int) timerno,new_clockin));
1079   LOG2(("pit8253_set_clockin(): PIT timer=%d, clockin = %lf\n", timerno,new_clockin));
11621080
1163   update(timer);
1081   update(device, timer);
11641082   timer->clockin = new_clockin;
1165   update(timer);
1083   update(device, timer);
11661084
1167   if (timer->freq_callback !=   NULL)
1085   if (timer->frequency_changed != NULL)
11681086   {
1169      timer->freq_callback(get_frequency(timer));
1087      timer->frequency_changed(device, get_frequency(timer));
11701088      if (timer->cycles_to_freq != CYCLES_NEVER)
11711089      {
11721090         freq_callback_in(timer,timer->cycles_to_freq);
r2234r2235
11751093}
11761094
11771095
1096static void common_start( const device_config *device, int device_type ) {
1097   pit8253_t   *pit8253 = get_safe_token(device);
1098   char      unique_tag[30];
1099   int         timerno;
11781100
1179/* ----------------------------------------------------------------------- */
1101   pit8253->config = device->static_config;
1102   pit8253->device_type = device_type;
11801103
1181READ8_HANDLER (   pit8253_0_r   ) {   return pit8253_read(0, offset);   }
1182READ8_HANDLER (   pit8253_1_r   ) {   return pit8253_read(1, offset);   }
1183WRITE8_HANDLER ( pit8253_0_w ) { pit8253_write(0, offset, data); }
1184WRITE8_HANDLER ( pit8253_1_w ) { pit8253_write(1, offset, data); }
1104   /* register for state saving */
1105   state_save_combine_module_and_tag(unique_tag, device_tags[device_type], device->tag);
11851106
1186READ16_HANDLER ( pit8253_0_lsb_r ) { return pit8253_read(0, offset);   }
1187READ16_HANDLER ( pit8253_1_lsb_r ) { return pit8253_read(1, offset);   }
1188WRITE16_HANDLER ( pit8253_0_lsb_w ) { if (ACCESSING_LSB) pit8253_write(0, offset, data); }
1189WRITE16_HANDLER ( pit8253_1_lsb_w ) { if (ACCESSING_LSB) pit8253_write(1, offset, data); }
1107   for (timerno = 0; timerno < MAX_TIMER; timerno++)
1108   {
1109      struct pit8253_timer *timer = get_timer(pit8253,timerno);
11901110
1191READ16_HANDLER ( pit8253_16le_0_r ) { return read16le_with_read8_handler(pit8253_0_r, machine, offset, mem_mask); }
1192READ16_HANDLER ( pit8253_16le_1_r ) { return read16le_with_read8_handler(pit8253_1_r, machine, offset, mem_mask); }
1193WRITE16_HANDLER   ( pit8253_16le_0_w ) { write16le_with_write8_handler(pit8253_0_w, machine, offset, data,   mem_mask); }
1194WRITE16_HANDLER   ( pit8253_16le_1_w ) { write16le_with_write8_handler(pit8253_1_w, machine, offset, data,   mem_mask); }
1111      timer->clockin = pit8253->config->timer[timerno].clockin;
1112      timer->output_changed = pit8253->config->timer[timerno].output_changed;
1113      timer->frequency_changed = pit8253->config->timer[timerno].frequency_changed;
11951114
1196READ32_HANDLER ( pit8253_32le_0_r ) { return read32le_with_read8_handler(pit8253_0_r, machine, offset, mem_mask); }
1197READ32_HANDLER ( pit8253_32le_1_r ) { return read32le_with_read8_handler(pit8253_1_r, machine, offset, mem_mask); }
1198WRITE32_HANDLER   ( pit8253_32le_0_w ) { write32le_with_write8_handler(pit8253_0_w, machine, offset, data,   mem_mask); }
1199WRITE32_HANDLER   ( pit8253_32le_1_w ) { write32le_with_write8_handler(pit8253_1_w, machine, offset, data,   mem_mask); }
1115      if (timer->output_changed == NULL)
1116         timer->outputtimer = NULL;
1117      else
1118      {
1119         timer->outputtimer = timer_alloc(output_changed, (void *)device);
1120         timer_adjust_oneshot(timer->outputtimer, attotime_never, timerno);
1121      }
1122      if (timer->frequency_changed == NULL)
1123         timer->freqtimer = NULL;
1124      else
1125      {
1126         timer->freqtimer = timer_alloc(frequency_changed, (void *)device);
1127         timer_adjust_oneshot(timer->freqtimer,  attotime_never, timerno);
1128      }
12001129
1201READ64_HANDLER ( pit8253_64be_0_r ) { return read64be_with_read8_handler(pit8253_0_r, machine, offset, mem_mask); }
1202READ64_HANDLER ( pit8253_64be_1_r ) { return read64be_with_read8_handler(pit8253_1_r, machine, offset, mem_mask); }
1203WRITE64_HANDLER   ( pit8253_64be_0_w ) { write64be_with_write8_handler(pit8253_0_w, machine, offset, data,   mem_mask); }
1204WRITE64_HANDLER   ( pit8253_64be_1_w ) { write64be_with_write8_handler(pit8253_1_w, machine, offset, data,   mem_mask); }
1130      /* set up state save values */
1131      state_save_register_item(unique_tag, timerno, timer->clockin);
1132      state_save_register_item(unique_tag, timerno, timer->control);
1133      state_save_register_item(unique_tag, timerno, timer->status);
1134      state_save_register_item(unique_tag, timerno, timer->lowcount);
1135      state_save_register_item(unique_tag, timerno, timer->latch);
1136      state_save_register_item(unique_tag, timerno, timer->count);
1137      state_save_register_item(unique_tag, timerno, timer->value);
1138      state_save_register_item(unique_tag, timerno, timer->wmsb);
1139      state_save_register_item(unique_tag, timerno, timer->rmsb);
1140      state_save_register_item(unique_tag, timerno, timer->output);
1141      state_save_register_item(unique_tag, timerno, timer->gate);
1142      state_save_register_item(unique_tag, timerno, timer->latched_count);
1143      state_save_register_item(unique_tag, timerno, timer->latched_status);
1144      state_save_register_item(unique_tag, timerno, timer->null_count);
1145      state_save_register_item(unique_tag, timerno, timer->phase);
1146      state_save_register_item(unique_tag, timerno, timer->cycles_to_output);
1147      state_save_register_item(unique_tag, timerno, timer->cycles_to_freq);
1148      state_save_register_item(unique_tag, timerno, timer->freq_count);
1149      state_save_register_item(unique_tag, timerno, timer->last_updated.seconds);
1150      state_save_register_item(unique_tag, timerno, timer->last_updated.attoseconds);
1151   }
1152}
12051153
1206WRITE8_HANDLER ( pit8253_0_gate_w )   { pit8253_gate_write(0,   offset,   data); }
1207WRITE8_HANDLER ( pit8253_1_gate_w )   { pit8253_gate_write(1,   offset,   data); }
12081154
1155static DEVICE_START( pit8253 ) {
1156   common_start( device, TYPE_PIT8253 );
1157}
1158
1159
1160static DEVICE_START( pit8254 ) {
1161   common_start( device, TYPE_PIT8254 );
1162}
1163
1164
1165static DEVICE_RESET( pit8253 ) {
1166   pit8253_t *pit  = get_safe_token(device);
1167   int i;
1168
1169   for (i = 0; i < MAX_TIMER; i++)
1170   {
1171      struct pit8253_timer *timer = get_timer(pit,i);
1172      /* According to Intel's 8254 docs, the state of a timer is undefined
1173         until the first mode control word is written. Here we define this
1174         undefined behaviour */
1175      timer->control = timer->status = 0x30;
1176      timer->rmsb = timer->wmsb = 0;
1177      timer->count = timer->value = timer->latch = 0;
1178      timer->lowcount = 0;
1179      timer->gate = 1;
1180      timer->output = 0;
1181      timer->latched_count = 0;
1182      timer->latched_status = 0;
1183      timer->null_count = 1;
1184      timer->cycles_to_output = timer->cycles_to_freq = CYCLES_NEVER;
1185
1186      timer->last_updated = timer_get_time();
1187
1188      update(device, timer);
1189   }
1190}
1191
1192
1193static DEVICE_SET_INFO( pit8253 ) {
1194   switch ( state ) {
1195      /* no parameters to set */
1196   }
1197}
1198
1199
1200DEVICE_GET_INFO( pit8253 ) {
1201   switch ( state ) {
1202      /* --- the following bits of info are returned as 64-bit signed integers --- */
1203      case DEVINFO_INT_TOKEN_BYTES:            info->i = sizeof(pit8253_t);            break;
1204      case DEVINFO_INT_INLINE_CONFIG_BYTES:      info->i = 0;                        break;
1205      case DEVINFO_INT_CLASS:                  info->i = DEVICE_CLASS_PERIPHERAL;         break;
1206
1207      /* --- the following bits of info are returned as pointers to data or functions --- */
1208      case DEVINFO_FCT_SET_INFO:               info->set_info = DEVICE_SET_INFO_NAME(pit8253);   break;
1209      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME(pit8253);   break;
1210      case DEVINFO_FCT_STOP:                  /* nothing */                        break;
1211      case DEVINFO_FCT_RESET:                  info->reset = DEVICE_RESET_NAME(pit8253);   break;
1212
1213      /* --- the following bits of info are returned as NULL-terminated strings --- */
1214      case DEVINFO_STR_NAME:                  info->s = "Intel PIT8253";               break;
1215      case DEVINFO_STR_FAMILY:               info->s = "PIT8253";                  break;
1216      case DEVINFO_STR_VERSION:               info->s = "1.00";                     break;
1217      case DEVINFO_STR_SOURCE_FILE:            info->s = __FILE__;                     break;
1218      case DEVINFO_STR_CREDITS:               info->s = "Copyright the MAME and MESS Teams"; break;
1219   }
1220}
1221
1222
1223DEVICE_GET_INFO( pit8254 ) {
1224   switch ( state ) {
1225      /* --- the following bits of info are returned as 64-bit signed integers --- */
1226      case DEVINFO_STR_NAME:                  info->s = "Intel PIT8254";               break;
1227
1228      /* --- the following bits of info are returned as pointers to data or functions --- */
1229      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME(pit8254);   break;
1230
1231      default:                           DEVICE_GET_INFO_CALL(pit8253);            break;
1232   }
1233}
1234
src/emu/machine/pit8253.h
r2234r2235
44 *
55 *****************************************************************************/
66
7#ifndef PIT8253_H
8#define PIT8253_H
7#ifndef __PIT8253_H_
8#define __PIT8253_H_
99
10typedef enum { TYPE8253, TYPE8254 } PIT8253_TYPE;
10#define PIT8253      DEVICE_GET_INFO_NAME(pit8253)
11#define PIT8254      DEVICE_GET_INFO_NAME(pit8254)
1112
13
14typedef void (*pit8253_output_changed_func)(const device_config *device, int state);
15#define PIT8253_OUTPUT_CHANGED(name)   void name(const device_config *device, int state )
16
17typedef void (*pit8253_frequency_changed_func)(const device_config *device, double frequency);
18#define PIT8253_FREQUENCY_CHANGED(name)   void name(const device_config *device, double frequency)
19
20
1221struct pit8253_config
1322{
14    PIT8253_TYPE type;
1523   struct
1624   {
25      /* Input clock for this timer */
1726      double clockin;
18      void (*output_callback_func)(int state);
19      void (*clock_callback)(double clockout);
27
28      /* If specified, this gets called whenever the output for this timer changes */
29      pit8253_output_changed_func         output_changed;
30
31      /* If specified, this gets called whenever the frequency of the output for this
32         timer changes. */
33      pit8253_frequency_changed_func      frequency_changed;     
2034   } timer[3];
2135};
2236
2337
38/* device interface */
39DEVICE_GET_INFO( pit8253 );
40DEVICE_GET_INFO( pit8254 );
2441
25int pit8253_init(int count, const struct pit8253_config *config);
26void pit8253_reset(int which);
42READ8_DEVICE_HANDLER( pit8253_r );
43WRITE8_DEVICE_HANDLER( pit8253_w );
2744
28READ8_HANDLER ( pit8253_0_r );
29READ8_HANDLER ( pit8253_1_r );
30WRITE8_HANDLER ( pit8253_0_w );
31WRITE8_HANDLER ( pit8253_1_w );
45WRITE8_DEVICE_HANDLER( pit8253_gate_w );
3246
33READ16_HANDLER ( pit8253_0_lsb_r );
34READ16_HANDLER ( pit8253_1_lsb_r );
35WRITE16_HANDLER ( pit8253_0_lsb_w );
36WRITE16_HANDLER ( pit8253_1_lsb_w );
3747
38READ16_HANDLER ( pit8253_16le_0_r );
39READ16_HANDLER ( pit8253_16le_1_r );
40WRITE16_HANDLER ( pit8253_16le_0_w );
41WRITE16_HANDLER ( pit8253_16le_1_w );
48int pit8253_get_frequency(const device_config *device, int timer);
49int pit8253_get_output(const device_config *device, int timer);
50void pit8253_set_clockin(const device_config *device, int timer, double new_clockin);
4251
43READ32_HANDLER ( pit8253_32le_0_r );
44READ32_HANDLER ( pit8253_32le_1_r );
45WRITE32_HANDLER ( pit8253_32le_0_w );
46WRITE32_HANDLER ( pit8253_32le_1_w );
4752
48READ64_HANDLER ( pit8253_64be_0_r );
49READ64_HANDLER ( pit8253_64be_1_r );
50WRITE64_HANDLER ( pit8253_64be_0_w );
51WRITE64_HANDLER ( pit8253_64be_1_w );
53#endif   /* __PIT8253_H_ */
5254
53WRITE8_HANDLER ( pit8253_0_gate_w );
54WRITE8_HANDLER ( pit8253_1_gate_w );
55
56int pit8253_get_frequency(int which, int timer);
57int pit8253_get_output(int which, int timer);
58void pit8253_set_clockin(int which, int timer, double new_clockin);
59
60
61#endif   /* PIT8253_H */
62
src/emu/devconv.h
r0r2235
1/***************************************************************************
2
3    devconv.h
4
5    Functions which help convert between different device handlers.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10****************************************************************************
11
12    ***** VERY IMPORTANT NOTICE *****
13
14    These functions and macros are provided to facilitate the mapping
15    of devices on cpus with different data bus widths.
16    Devices should be implemented using their native data bus width,
17    since that ensures that read/write operations are kept atomic.
18    If we discover you have abused the functionality presented in this
19    file, you *will* be publicly humiliated and your code submission
20    will probably not be accepted. Seriously, please do not abuse these
21    functions/macros.
22
23****************************************************************************
24
25    Conversions supported:
26
27    CW = CPU Data Bus Width in bits
28    CBO = CPU Byte Order
29    DW = Device Data Bus Width in bits
30    DBO = Device Byte Order
31
32    CW | CBO    | DW | DBO    | Functions to use
33    ---+--------+----+--------+-----------------------------------------------------------
34    16 | Big    | 8  | N/A    | read16be_with_read8_device_handler,write16be_with_write8_device_handler
35    16 | Little | 8  | N/A    | read16le_with_read8_device_handler,write16le_with_write8_device_handler
36    ---+--------+----+--------+-----------------------------------------------------------
37    32 | Big    | 8  | N/A    | read32be_with_read8_device_handler,write32be_with_write8_device_handler
38    32 | Little | 8  | N/A    | read32le_with_read8_device_handler,write32le_with_write8_device_handler
39    32 | Big    | 16 | Big    | read32be_with_16be_device_handler,write32be_with_16be_device_handler
40    32 | Little | 16 | Little | read32le_with_16le_device_handler,write32le_with_16le_device_handler
41    32 | Big    | 16 | Little | read32be_with_16le_device_handler,write32be_with_16le_device_handler
42    32 | Little | 16 | Big    | read32le_with_16be_device_handler,write32le_with_16be_device_handler
43    ---+--------+----+--------+-----------------------------------------------------------
44    64 | Big    | 8  | N/A    | read64be_with_read8_device_handler,write64be_with_write8_device_handler
45    64 | Little | 8  | N/A    | read64le_with_read8_device_handler,write64le_with_write8_device_handler
46    64 | Big    | 16 | Big    | read64be_with_16be_device_handler,write64be_with_16be_device_handler
47    64 | Little | 16 | Little | read64le_with_16le_device_handler,write64le_with_16le_device_handler
48    64 | Big    | 16 | Little | read64be_with_16le_device_handler,write64be_with_16le_device_handler
49    64 | Little | 16 | Big    | read64le_with_16be_device_handler,write64le_with_16be_device_handler
50    64 | Big    | 32 | Big    | read64be_with_32be_device_handler,write64be_with_32be_device_handler
51    64 | Little | 32 | Little | read64le_with_32le_device_handler,write64le_with_32le_device_handler
52    64 | Big    | 32 | Little | read64be_with_32le_device_handler,write64be_with_32le_device_handler
53    64 | Little | 32 | Big    | read64le_with_32be_device_handler,write64le_with_32be_device_handler
54
55    You can also find at the bottom of this file a few convernient
56    macros that will create the stub read and/or write handlers for
57    the most common mappings, that will use the functions above.
58    Here's an example on how to use them: Say you have a 8 bit device
59    whose handlers are device8_r and device8_w, and you want to connect
60    it to a 16 bit, big endian cpu. We'll say the device is mapped on
61    the least significant byte of the data bus (LSB).
62
63    In your driver, you would add:
64
65    DEV_READWRITE8TO16BE_LSB( device16, device8_r, device8_w )
66
67    which will create two 16 bit memory handlers, one for read, called
68    device16_r, and one for write, called device16_w, with the proper
69    mapping.
70
71    then in the MEMORY_MAP you would specify:
72
73    AM_RANGE(0x000000, 0x0000ff) AM_DEVREADWRITE( DEVICE, "device", device16_r, device16_w )
74
75    And that is all. Your device should be mapped properly.
76    If you need to do custom mappings, or a mapping that is not currently
77    supported in this file, you can always write the stub yourself, and
78    call the above functions to invoke the base handlers.
79
80***************************************************************************/
81
82/*************************************
83 *
84 *  16-bit BE using 8-bit handlers
85 *
86 *************************************/
87
88INLINE UINT16 read16be_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT16 mem_mask)
89{
90   UINT16 result = 0;
91   if ((mem_mask & 0xff00) != 0xff00)
92      result |= ((UINT16)(*handler)(param, offset * 2 + 0)) << 8;
93   if ((mem_mask & 0x00ff) != 0x00ff)
94      result |= ((UINT16)(*handler)(param, offset * 2 + 1)) << 0;
95   return result;
96}
97
98
99INLINE void write16be_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT16 data, UINT16 mem_mask)
100{
101   if ((mem_mask & 0xff00) != 0xff00)
102      (*handler)(param, offset * 2 + 0, data >> 8);
103   if ((mem_mask & 0x00ff) != 0x00ff)
104      (*handler)(param, offset * 2 + 1, data >> 0);
105}
106
107
108/*************************************
109 *
110 *  16-bit LE using 8-bit handlers
111 *
112 *************************************/
113
114INLINE UINT16 read16le_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT16 mem_mask)
115{
116   UINT16 result = 0;
117   if ((mem_mask & 0x00ff) != 0x00ff)
118      result |= ((UINT16) (*handler)(param, offset * 2 + 0)) << 0;
119   if ((mem_mask & 0xff00) != 0xff00)
120      result |= ((UINT16) (*handler)(param, offset * 2 + 1)) << 8;
121   return result;
122}
123
124
125INLINE void write16le_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT16 data, UINT16 mem_mask)
126{
127   if ((mem_mask & 0x00ff) != 0x00ff)
128      (*handler)(param, offset * 2 + 0, data >> 0);
129   if ((mem_mask & 0xff00) != 0xff00)
130      (*handler)(param, offset * 2 + 1, data >> 8);
131}
132
133
134/*************************************
135 *
136 *  32-bit BE using 8-bit handlers
137 *
138 *************************************/
139
140INLINE UINT32 read32be_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT32 mem_mask)
141{
142   UINT32 result = 0;
143   if ((mem_mask & 0xffff0000) != 0xffff0000)
144      result |= read16be_with_read8_device_handler(handler, param, offset * 2 + 0, mem_mask >> 16) << 16;
145   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
146      result |= read16be_with_read8_device_handler(handler, param, offset * 2 + 1, mem_mask) << 0;
147   return result;
148}
149
150
151INLINE void write32be_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask)
152{
153   if ((mem_mask & 0xffff0000) != 0xffff0000)
154      write16be_with_write8_device_handler(handler, param, offset * 2 + 0, data >> 16, mem_mask >> 16);
155   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
156      write16be_with_write8_device_handler(handler, param, offset * 2 + 1, data, mem_mask);
157}
158
159
160/*************************************
161 *
162 *  32-bit LE using 8-bit handlers
163 *
164 *************************************/
165
166INLINE UINT32 read32le_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT32 mem_mask)
167{
168   UINT32 result = 0;
169   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
170      result |= read16le_with_read8_device_handler(handler, param, offset * 2 + 0, mem_mask) << 0;
171   if ((mem_mask & 0xffff0000) != 0xffff0000)
172      result |= read16le_with_read8_device_handler(handler, param, offset * 2 + 1, mem_mask >> 16) << 16;
173   return result;
174}
175
176
177INLINE void write32le_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask)
178{
179   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
180      write16le_with_write8_device_handler(handler, param, offset * 2 + 0, data, mem_mask);
181   if ((mem_mask & 0xffff0000) != 0xffff0000)
182      write16le_with_write8_device_handler(handler, param, offset * 2 + 1, data >> 16, mem_mask >> 16);
183}
184
185
186/*************************************
187 *
188 *  32-bit BE using 16-bit BE handlers
189 *
190 *************************************/
191
192INLINE UINT32 read32be_with_16be_device_handler(read16_device_func handler, void *param, offs_t offset, UINT32 mem_mask)
193{
194   UINT32 result = 0;
195   if ((mem_mask & 0xffff0000) != 0xffff0000)
196      result |= (*handler)(param, offset * 2 + 0, mem_mask >> 16) << 16;
197   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
198      result |= (*handler)(param, offset * 2 + 1, mem_mask) << 0;
199   return result;
200}
201
202
203INLINE void write32be_with_16be_device_handler(write16_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask)
204{
205   if ((mem_mask & 0xffff0000) != 0xffff0000)
206      (*handler)(param, offset * 2 + 0, data >> 16, mem_mask >> 16);
207   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
208      (*handler)(param, offset * 2 + 1, data, mem_mask);
209}
210
211
212/*************************************
213 *
214 *  32-bit LE using 16-bit LE handlers
215 *
216 *************************************/
217
218INLINE UINT32 read32le_with_16le_device_handler(read16_device_func handler, void *param, offs_t offset, UINT32 mem_mask)
219{
220   UINT32 result = 0;
221   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
222      result |= (*handler)(param, offset * 2 + 0, mem_mask) << 0;
223   if ((mem_mask & 0xffff0000) != 0xffff0000)
224      result |= (*handler)(param, offset * 2 + 1, mem_mask >> 16) << 16;
225   return result;
226}
227
228
229INLINE void write32le_with_16le_device_handler(write16_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask)
230{
231   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
232      (*handler)(param, offset * 2 + 0, data, mem_mask);
233   if ((mem_mask & 0xffff0000) != 0xffff0000)
234      (*handler)(param, offset * 2 + 1, data >> 16, mem_mask >> 16);
235}
236
237
238/*************************************
239 *
240 *  32-bit BE using 16-bit LE handlers
241 *
242 *************************************/
243
244INLINE UINT32 read32be_with_16le_device_handler(read16_device_func handler, void *param, offs_t offset, UINT32 mem_mask)
245{
246   UINT32 result = 0;
247   mem_mask = FLIPENDIAN_INT32(mem_mask);
248   result = read32le_with_16le_device_handler(handler, param, offset, mem_mask);
249   return FLIPENDIAN_INT32(result);
250}
251
252
253INLINE void write32be_with_16le_device_handler(write16_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask)
254{
255   data = FLIPENDIAN_INT32(data);
256   mem_mask = FLIPENDIAN_INT32(mem_mask);
257   write32le_with_16le_device_handler(handler, param, offset, data, mem_mask);
258}
259
260
261/*************************************
262 *
263 *  32-bit LE using 16-bit BE handlers
264 *
265 *************************************/
266
267INLINE UINT32 read32le_with_16be_device_handler(read16_device_func handler, void *param, offs_t offset, UINT32 mem_mask)
268{
269   UINT32 result = 0;
270   mem_mask = FLIPENDIAN_INT32(mem_mask);
271   result = read32be_with_16be_device_handler(handler, param, offset, mem_mask);
272   return FLIPENDIAN_INT32(result);
273}
274
275
276INLINE void write32le_with_16be_device_handler(write16_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask)
277{
278   data = FLIPENDIAN_INT32(data);
279   mem_mask = FLIPENDIAN_INT32(mem_mask);
280   write32be_with_16be_device_handler(handler, param, offset, data, mem_mask);
281}
282
283
284/*************************************
285 *
286 *  64-bit BE using 8-bit handlers
287 *
288 *************************************/
289
290INLINE UINT64 read64be_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
291{
292   UINT64 result = 0;
293   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
294      result |= (UINT64)read32be_with_read8_device_handler(handler, param, offset * 2 + 0, mem_mask >> 32) << 32;
295   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
296      result |= (UINT64)read32be_with_read8_device_handler(handler, param, offset * 2 + 1, mem_mask) << 0;
297   return result;
298}
299
300
301INLINE void write64be_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
302{
303   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
304      write32be_with_write8_device_handler(handler, param, offset * 2 + 0, data >> 32, mem_mask >> 32);
305   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
306      write32be_with_write8_device_handler(handler, param, offset * 2 + 1, data, mem_mask);
307}
308
309
310/*************************************
311 *
312 *  64-bit LE using 8-bit handlers
313 *
314 *************************************/
315
316INLINE UINT64 read64le_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
317{
318   UINT64 result = 0;
319   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
320      result |= (UINT64)read32le_with_read8_device_handler(handler, param, offset * 2 + 0, mem_mask >> 0) << 0;
321   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
322      result |= (UINT64)read32le_with_read8_device_handler(handler, param, offset * 2 + 1, mem_mask >> 32) << 32;
323   return result;
324}
325
326
327INLINE void write64le_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
328{
329   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
330      write32le_with_write8_device_handler(handler, param, offset * 2 + 0, data >> 0, mem_mask >> 0);
331   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
332      write32le_with_write8_device_handler(handler, param, offset * 2 + 1, data >> 32, mem_mask >> 32);
333}
334
335
336/*************************************
337 *
338 *  64-bit BE using 16-bit BE handlers
339 *
340 *************************************/
341
342INLINE UINT32 read64be_with_16be_device_handler(read16_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
343{
344   UINT64 result = 0;
345   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
346      result |= (UINT64)read32be_with_16be_device_handler(handler, param, offset * 2 + 0, mem_mask >> 32) << 32;
347   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
348      result |= (UINT64)read32be_with_16be_device_handler(handler, param, offset * 2 + 1, mem_mask >> 0) << 0;
349   return result;
350}
351
352
353INLINE void write64be_with_16be_device_handler(write16_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
354{
355   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
356      write32be_with_16be_device_handler(handler, param, offset * 2 + 0, data >> 32, mem_mask >> 32);
357   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
358      write32be_with_16be_device_handler(handler, param, offset * 2 + 1, data >> 0, mem_mask >> 0);
359}
360
361
362/*************************************
363 *
364 *  64-bit LE using 16-bit LE handlers
365 *
366 *************************************/
367
368INLINE UINT32 read64le_with_16le_device_handler(read16_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
369{
370   UINT64 result = 0;
371   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
372      result |= (UINT64)read32le_with_16le_device_handler(handler, param, offset * 2 + 0, mem_mask >> 0) << 0;
373   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
374      result |= (UINT64)read32le_with_16le_device_handler(handler, param, offset * 2 + 1, mem_mask >> 32) << 32;
375   return result;
376}
377
378
379INLINE void write64le_with_16le_device_handler(write16_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
380{
381   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
382      write32le_with_16le_device_handler(handler, param, offset * 2 + 0, data >> 0, mem_mask >> 0);
383   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
384      write32le_with_16le_device_handler(handler, param, offset * 2 + 1, data >> 32, mem_mask >> 32);
385}
386
387
388/*************************************
389 *
390 *  64-bit BE using 16-bit LE handlers
391 *
392 *************************************/
393
394INLINE UINT32 read64be_with_16le_device_handler(read16_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
395{
396   UINT64 result = 0;
397   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
398      result |= (UINT64)read32be_with_16le_device_handler(handler, param, offset * 2 + 0, mem_mask >> 32) << 32;
399   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
400      result |= (UINT64)read32be_with_16le_device_handler(handler, param, offset * 2 + 1, mem_mask >> 0) << 0;
401   return result;
402}
403
404
405INLINE void write64be_with_16le_device_handler(write16_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
406{
407   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
408      write32be_with_16le_device_handler(handler, param, offset * 2 + 0, data >> 32, mem_mask >> 32);
409   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
410      write32be_with_16le_device_handler(handler, param, offset * 2 + 1, data >> 0, mem_mask >> 0);
411}
412
413
414/*************************************
415 *
416 *  64-bit LE using 16-bit BE handlers
417 *
418 *************************************/
419
420INLINE UINT32 read64le_with_16be_device_handler(read16_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
421{
422   UINT64 result = 0;
423   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
424      result |= (UINT64)read32le_with_16be_device_handler(handler, param, offset * 2 + 0, mem_mask >> 0) << 0;
425   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
426      result |= (UINT64)read32le_with_16be_device_handler(handler, param, offset * 2 + 1, mem_mask >> 32) << 32;
427   return result;
428}
429
430
431INLINE void write64le_with_16be_device_handler(write16_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
432{
433   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
434      write32le_with_16be_device_handler(handler, param, offset * 2 + 0, data >> 0, mem_mask >> 0);
435   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
436      write32le_with_16be_device_handler(handler, param, offset * 2 + 1, data >> 32, mem_mask >> 32);
437}
438
439
440/*************************************
441 *
442 *  64-bit BE using 32-bit BE handlers
443 *
444 *************************************/
445
446INLINE UINT64 read64be_with_32be_device_handler(read32_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
447{
448   UINT64 result = 0;
449   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
450      result |= (UINT64)(*handler)(param, offset * 2 + 0, mem_mask >> 32) << 32;
451   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
452      result |= (UINT64)(*handler)(param, offset * 2 + 1, mem_mask >> 0) << 0;
453   return result;
454}
455
456
457INLINE void write64be_with_32be_device_handler(write32_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
458{
459   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
460      (*handler)(param, offset * 2 + 0, data >> 32, mem_mask >> 32);
461   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
462      (*handler)(param, offset * 2 + 1, data >>  0, mem_mask >>  0);
463}
464
465
466/*************************************
467 *
468 *  64-bit LE using 32-bit LE handlers
469 *
470 *************************************/
471
472INLINE UINT64 read64le_with_32le_device_handler(read32_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
473{
474   UINT64 result = 0;
475   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
476      result |= (UINT64)(*handler)(param, offset * 2 + 0, mem_mask >> 0) << 0;
477   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
478      result |= (UINT64)(*handler)(param, offset * 2 + 1, mem_mask >> 32) << 32;
479   return result;
480}
481
482
483INLINE void write64le_with_32le_device_handler(write32_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
484{
485   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
486      (*handler)(param, offset * 2 + 0, data >> 0, mem_mask >> 0);
487   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
488      (*handler)(param, offset * 2 + 1, data >> 32, mem_mask >> 32);
489}
490
491
492/*************************************
493 *
494 *  64-bit BE using 32-bit LE handlers
495 *
496 *************************************/
497
498INLINE UINT64 read64be_with_32le_device_handler(read32_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
499{
500   UINT64 result;
501   mem_mask = FLIPENDIAN_INT64(mem_mask);
502   result = read64le_with_32le_device_handler(handler, param, offset, mem_mask);
503   return FLIPENDIAN_INT64(result);
504}
505
506
507INLINE void write64be_with_32le_device_handler(write32_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
508{
509   data = FLIPENDIAN_INT64(data);
510   mem_mask = FLIPENDIAN_INT64(mem_mask);
511   write64le_with_32le_device_handler(handler, param, offset, data, mem_mask);
512}
513
514
515/*************************************
516 *
517 *  64-bit LE using 32-bit BE handlers
518 *
519 *************************************/
520
521INLINE UINT64 read64le_with_32be_device_handler(read32_device_func handler, void *param, offs_t offset, UINT64 mem_mask)
522{
523   UINT64 result;
524   mem_mask = FLIPENDIAN_INT64(mem_mask);
525   result = read64be_with_32be_device_handler(handler, param, offset, mem_mask);
526   return FLIPENDIAN_INT64(result);
527}
528
529
530INLINE void write64le_with_32be_device_handler(write32_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask)
531{
532   data = FLIPENDIAN_INT64(data);
533   mem_mask = FLIPENDIAN_INT64(mem_mask);
534   write64be_with_32be_device_handler(handler, param, offset, data, mem_mask);
535}
536
537
538
539/**************************************************************************
540
541    Utility macros
542
543**************************************************************************/
544
545#define DEV_READ_TEMPLATE(bits, name, handler, func)            \
546READ##bits##_DEVICE_HANDLER( name##_r )                        \
547{                                                   \
548   return func(handler, device, offset, mem_mask);               \
549}
550
551#define DEV_READ_TEMPLATE_COND(bits, name, handler, func, cond)      \
552READ##bits##_DEVICE_HANDLER( name##_r )                        \
553{                                                   \
554   if (cond)                                          \
555      return func(handler, device, offset, mem_mask);            \
556   return 0;                                          \
557}
558
559#define DEV_WRITE_TEMPLATE(bits, name, handler, func)            \
560WRITE##bits##_DEVICE_HANDLER( name##_w )                     \
561{                                                   \
562   func(handler, device, offset, data, mem_mask);               \
563}
564
565#define DEV_WRITE_TEMPLATE_COND(bits, name, handler, func, cond)   \
566WRITE##bits##_DEVICE_HANDLER( name##_w )                     \
567{                                                   \
568   if (cond)                                          \
569      return func(handler, device, offset, data, mem_mask);      \
570}
571
572
573
574/**************************************************************************
575
576    Generic conversions macros
577
578**************************************************************************/
579
580
581/*************************************
582 * 8->16be, 1:1 mapping
583 ************************************/
584
585#define DEV_READ8TO16BE( name, read8 ) \
586DEV_READ_TEMPLATE( 16, name, read8, read16be_with_read8_device_handler )
587
588
589#define DEV_WRITE8TO16BE( name, write8 ) \
590DEV_WRITE_TEMPLATE( 16, name, write8, write16be_with_write8_device_handler )
591
592
593#define DEV_READWRITE8TO16BE( name, read8, write8 ) \
594DEV_READ8TO16BE(name,read8) \
595DEV_WRITE8TO16BE(name,write8)
596
597
598/*************************************
599 * 8->16le, 1:1 mapping
600 ************************************/
601
602#define DEV_READ8TO16LE( name, read8 ) \
603DEV_READ_TEMPLATE( 16, name, read8, read16le_with_read8_device_handler )
604
605
606#define DEV_WRITE8TO16LE( name, write8 ) \
607DEV_WRITE_TEMPLATE( 16, name, write8, write16le_with_write8_device_handler )
608
609
610#define DEV_READWRITE8TO16LE( name, read8, write8 ) \
611DEV_READ8TO16LE(name,read8) \
612DEV_WRITE8TO16LE(name,write8)
613
614
615/*************************************
616 * 8->16be, MSB mapping
617 ************************************/
618
619#define DEV_READ8TO16BE_MSB( name, read8 ) \
620DEV_READ_TEMPLATE_COND( 16, name, read8, read16be_with_read8_device_handler, ACCESSING_MSB )
621
622
623#define DEV_WRITE8TO16BE_MSB( name, write8 ) \
624DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_device_handler, ACCESSING_MSB )
625
626
627#define DEV_READWRITE8TO16BE_MSB( name, read8, write8 ) \
628DEV_READ8TO16BE_MSB(name,read8) \
629DEV_WRITE8TO16BE_MSB(name,write8)
630
631
632/*************************************
633 * 8->16le, MSB mapping
634 ************************************/
635
636#define DEV_READ8TO16LE_MSB( name, read8 ) \
637DEV_READ_TEMPLATE_COND( 16, name, read8, read16le_with_read8_device_handler, ACCESSING_MSB )
638
639
640#define DEV_WRITE8TO16LE_MSB( name, write8 ) \
641DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_device_handler, ACCESSING_MSB )
642
643
644#define DEV_READWRITE8TO16LE_MSB( name, read8, write8 ) \
645DEV_READ8TO16LE_MSB(name,read8) \
646DEV_WRITE8TO16LE_MSB(name,write8)
647
648
649/*************************************
650 * 8->16be, LSB mapping
651 ************************************/
652
653#define DEV_READ8TO16BE_LSB( name, read8 ) \
654DEV_READ_TEMPLATE_COND( 16, name, read8, read16be_with_read8_device_handler, ACCESSING_LSB )
655
656
657#define DEV_WRITE8TO16BE_LSB( name, write8 ) \
658DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_device_handler, ACCESSING_LSB )
659
660
661#define DEV_READWRITE8TO16BE_LSB( name, read8, write8 ) \
662DEV_READ8TO16BE_LSB(name,read8) \
663DEV_WRITE8TO16BE_LSB(name,write8)
664
665
666/*************************************
667 * 8->16le, LSB mapping
668 ************************************/
669
670#define DEV_READ8TO16LE_LSB( name, read8 ) \
671DEV_READ_TEMPLATE_COND( 16, name, read8, read16le_with_read8_device_handler, ACCESSING_LSB )
672
673
674#define DEV_WRITE8TO16LE_LSB( name, write8 ) \
675DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_device_handler, ACCESSING_LSB )
676
677
678#define DEV_READWRITE8TO16LE_LSB( name, read8, write8 ) \
679DEV_READ8TO16LE_LSB(name,read8) \
680DEV_WRITE8TO16LE_LSB(name,write8)
681
682
683/*************************************
684 * 8->32be, 1:1 mapping
685 ************************************/
686
687#define DEV_READ8TO32BE( name, read8 ) \
688DEV_READ_TEMPLATE( 32, name, read8, read32be_with_read8_device_handler )
689
690
691#define DEV_WRITE8TO32BE( name, write8 ) \
692DEV_WRITE_TEMPLATE( 32, name, write8, write32be_with_write8_device_handler )
693
694
695#define DEV_READWRITE8TO32BE( name, read8, write8 ) \
696DEV_READ8TO32BE(name,read8) \
697DEV_WRITE8TO32BE(name,write8)
698
699
700/*************************************
701 * 8->32le, 1:1 mapping
702 ************************************/
703
704#define DEV_READ8TO32LE( name, read8 ) \
705DEV_READ_TEMPLATE( 32, name, read8, read32le_with_read8_device_handler )
706
707
708#define DEV_WRITE8TO32LE( name, write8 ) \
709DEV_WRITE_TEMPLATE( 32, name, write8, write32le_with_write8_device_handler )
710
711
712#define DEV_READWRITE8TO32LE( name, read8, write8 ) \
713DEV_READ8TO32LE(name,read8) \
714DEV_WRITE8TO32LE(name,write8)
715
716
717/*************************************
718 * 8->32be, MSB mapping
719 ************************************/
720
721#define DEV_READ8TO32BE_MSB( name, read8 ) \
722DEV_READ_TEMPLATE_COND( 32, name, read8, read32be_with_read8_device_handler, ACCESSING_MSB32 )
723
724
725#define DEV_WRITE8TO32BE_MSB( name, write8 ) \
726DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_device_handler, ACCESSING_MSB32 )
727
728
729#define DEV_READWRITE8TO32BE_MSB( name, read8, write8 ) \
730DEV_READ8TO32BE_MSB(name,read8) \
731DEV_WRITE8TO32BE_MSB(name,write8)
732
733
734/*************************************
735 * 8->32le, MSB mapping
736 ************************************/
737
738#define DEV_READ8TO32LE_MSB( name, read8 ) \
739DEV_READ_TEMPLATE_COND( 32, name, read8, read32le_with_read8_device_handler, ACCESSING_MSB32 )
740
741
742#define DEV_WRITE8TO32LE_MSB( name, write8 ) \
743DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_device_handler, ACCESSING_MSB32 )
744
745
746#define DEV_READWRITE8TO32LE_MSB( name, read8, write8 ) \
747DEV_READ8TO32LE_MSB(name,read8) \
748DEV_WRITE8TO32LE_MSB(name,write8)
749
750
751/*************************************
752 * 8->32be, LSB mapping
753 ************************************/
754
755#define DEV_READ8TO32BE_LSB( name, read8 ) \
756DEV_READ_TEMPLATE_COND( 32, name, read8, read32be_with_read8_device_handler, ACCESSING_LSB32 )
757
758
759#define DEV_WRITE8TO32BE_LSB( name, write8 ) \
760DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_device_handler, ACCESSING_LSB32 )
761
762
763#define DEV_READWRITE8TO32BE_LSB( name, read8, write8 ) \
764DEV_READ8TO32BE_LSB(name,read8) \
765DEV_WRITE8TO32BE_LSB(name,write8)
766
767
768/*************************************
769 * 8->32le, LSB mapping
770 ************************************/
771
772#define DEV_READ8TO32LE_LSB( name, read8 ) \
773DEV_READ_TEMPLATE_COND( 32, name, read8, read32le_with_read8_device_handler, ACCESSING_LSB32 )
774
775
776#define DEV_WRITE8TO32LE_LSB( name, write8 ) \
777DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_device_handler, ACCESSING_LSB32 )
778
779
780#define DEV_READWRITE8TO32LE_LSB( name, read8, write8 ) \
781DEV_READ8TO32LE_LSB(name,read8) \
782DEV_WRITE8TO32LE_LSB(name,write8)
783
784
785/*************************************
786 * 8->64be, 1:1 mapping
787 ************************************/
788
789#define DEV_READ8TO64BE( name, read8 ) \
790DEV_READ_TEMPLATE( 64, name, read8, read64be_with_read8_device_handler )
791
792
793#define DEV_WRITE8TO64BE( name, write8 ) \
794DEV_WRITE_TEMPLATE( 64, name, write8, write64be_with_write8_device_handler )
795
796
797#define DEV_READWRITE8TO64BE( name, read8, write8 ) \
798DEV_READ8TO64BE(name,read8) \
799DEV_WRITE8TO64BE(name,write8)
800
801
802/*************************************
803 * 8->64le, 1:1 mapping
804 ************************************/
805
806#define DEV_READ8TO64LE( name, read8 ) \
807DEV_READ_TEMPLATE( 64, name, read8, read64le_with_read8_device_handler )
808
809
810#define DEV_WRITE8TO64LE( name, write8 ) \
811DEV_WRITE_TEMPLATE( 64, name, write8, write64le_with_write8_device_handler )
812
813
814#define DEV_READWRITE8TO64LE( name, read8, write8 ) \
815DEV_READ8TO64LE(name,read8) \
816DEV_WRITE8TO64LE(name,write8)
817
818
819/*************************************
820 *  16be->32be, 1:1 mapping
821 *************************************/
822
823#define DEV_READ16BETO32BE( name, read16 ) \
824DEV_READ_TEMPLATE( 32, name, read16, read32be_with_16be_device_handler )
825
826
827#define DEV_WRITE16BETO32BE( name, write16 ) \
828DEV_WRITE_TEMPLATE( 32, name, write16, write32be_with_16be_device_handler )
829
830
831#define DEV_READWRITE16BETO32BE( name, read16, write16 ) \
832DEV_READ16BETO32BE(name,read16) \
833DEV_WRITE16BETO32BE(name,write16)
834
835
836/*************************************
837 *  16le->32be, 1:1 mapping
838 *************************************/
839
840#define DEV_READ16LETO32BE( name, read16 ) \
841DEV_READ_TEMPLATE( 32, name, read16, read32be_with_16le_device_handler )
842
843
844#define DEV_WRITE16LETO32BE( name, write16 ) \
845DEV_WRITE_TEMPLATE( 32, name, write16, write32be_with_16le_device_handler )
846
847
848#define DEV_READWRITE16LETO32BE( name, read16, write16 ) \
849DEV_READ16LETO32BE(name,read16) \
850DEV_WRITE16LETO32BE(name,write16)
851
852
853/*************************************
854 *  16be->32le, 1:1 mapping
855 *************************************/
856
857#define DEV_READ16BETO32LE( name, read16 ) \
858DEV_READ_TEMPLATE( 32, name, read16, read32le_with_16be_device_handler )
859
860
861#define DEV_WRITE16BETO32LE( name, write16 ) \
862DEV_WRITE_TEMPLATE( 32, name, write16, write32le_with_16be_device_handler )
863
864
865#define DEV_READWRITE16BETO32LE( name, read16, write16 ) \
866DEV_READ16BETO32LE(name,read16) \
867DEV_WRITE16BETO32LE(name,write16)
868
869
870/*************************************
871 *  16le->32le, 1:1 mapping
872 *************************************/
873
874#define DEV_READ16LETO32LE( name, read16 ) \
875DEV_READ_TEMPLATE( 32, name, read16, read32le_with_16le_device_handler )
876
877
878#define DEV_WRITE16LETO32LE( name, write16 ) \
879DEV_WRITE_TEMPLATE( 32, name, write16, write32le_with_16le_device_handler )
880
881
882#define DEV_READWRITE16LETO32LE( name, read16, write16 ) \
883DEV_READ16LETO32LE(name,read16) \
884DEV_WRITE16LETO32LE(name,write16)
885
886
887/*************************************
888 *  16be->32be, MSW mapping
889 *************************************/
890
891#define DEV_READ16BETO32BE_MSW( name, read16 ) \
892DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16be_device_handler, ACCESSING_MSW32 )
893
894
895#define DEV_WRITE16BETO32BE_MSW( name, write16 ) \
896DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_device_handler, ACCESSING_MSW32 )
897
898
899#define DEV_READWRITE16BETO32BE_MSW( name, read16, write16 ) \
900DEV_READ16BETO32BE_MSW(name,read16) \
901DEV_WRITE16BETO32BE_MSW(name,write16)
902
903
904/*************************************
905 *  16le->32be, MSW mapping
906 *************************************/
907
908#define DEV_READ16LETO32BE_MSW( name, read16 ) \
909DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16le_device_handler, ACCESSING_MSW32 )
910
911
912#define DEV_WRITE16LETO32BE_MSW( name, write16 ) \
913DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_device_handler, ACCESSING_MSW32 )
914
915
916#define DEV_READWRITE16LETO32BE_MSW( name, read16, write16 ) \
917DEV_READ16LETO32BE_MSW(name,read16) \
918DEV_WRITE16LETO32BE_MSW(name,write16)
919
920
921/*************************************
922 *  16be->32le, MSW mapping
923 *************************************/
924
925#define DEV_READ16BETO32LE_MSW( name, read16 ) \
926DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16be_device_handler, ACCESSING_MSW32 )
927
928
929#define DEV_WRITE16BETO32LE_MSW( name, write16 ) \
930DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_device_handler, ACCESSING_MSW32 )
931
932
933#define DEV_READWRITE16BETO32LE_MSW( name, read16, write16 ) \
934DEV_READ16BETO32LE_MSW(name,read16) \
935DEV_WRITE16BETO32LE_MSW(name,write16)
936
937
938/*************************************
939 *  16le->32le, MSW mapping
940 *************************************/
941
942#define DEV_READ16LETO32LE_MSW( name, read16 ) \
943DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16le_device_handler, ACCESSING_MSW32 )
944
945
946#define DEV_WRITE16LETO32LE_MSW( name, write16 ) \
947DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_device_handler, ACCESSING_MSW32 )
948
949
950#define DEV_READWRITE16LETO32LE_MSW( name, read16, write16 ) \
951DEV_READ16LETO32LE_MSW(name,read16) \
952DEV_WRITE16LETO32LE_MSW(name,write16)
953
954/*************************************
955 *  16be->32be, LSW mapping
956 *************************************/
957
958#define DEV_READ16BETO32BE_LSW( name, read16 ) \
959DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16be_device_handler, ACCESSING_LSW32 )
960
961
962#define DEV_WRITE16BETO32BE_LSW( name, write16 ) \
963DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_device_handler, ACCESSING_LSW32 )
964
965
966#define DEV_READWRITE16BETO32BE_LSW( name, read16, write16 ) \
967DEV_READ16BETO32BE_LSW(name,read16) \
968DEV_WRITE16BETO32BE_LSW(name,write16)
969
970
971/*************************************
972 *  16le->32be, LSW mapping
973 *************************************/
974
975#define DEV_READ16LETO32BE_LSW( name, read16 ) \
976DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16le_device_handler, ACCESSING_LSW32 )
977
978
979#define DEV_WRITE16LETO32BE_LSW( name, write16 ) \
980DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_device_handler, ACCESSING_LSW32 )
981
982
983#define DEV_READWRITE16LETO32BE_LSW( name, read16, write16 ) \
984DEV_READ16LETO32BE_LSW(name,read16) \
985DEV_WRITE16LETO32BE_LSW(name,write16)
986
987
988/*************************************
989 *  16be->32le, LSW mapping
990 *************************************/
991
992#define DEV_READ16BETO32LE_LSW( name, read16 ) \
993DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16be_device_handler, ACCESSING_LSW32 )
994
995
996#define DEV_WRITE16BETO32LE_LSW( name, write16 ) \
997DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_device_handler, ACCESSING_LSW32 )
998
999
1000#define DEV_READWRITE16BETO32LE_LSW( name, read16, write16 ) \
1001DEV_READ16BETO32LE_LSW(name,read16) \
1002DEV_WRITE16BETO32LE_LSW(name,write16)
1003
1004
1005/*************************************
1006 *  16le->32le, LSW mapping
1007 *************************************/
1008
1009#define DEV_READ16LETO32LE_LSW( name, read16 ) \
1010DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16le_device_handler, ACCESSING_LSW32 )
1011
1012
1013#define DEV_WRITE16LETO32LE_LSW( name, write16 ) \
1014DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_device_handler, ACCESSING_LSW32 )
1015
1016
1017#define DEV_READWRITE16LETO32LE_LSW( name, read16, write16 ) \
1018DEV_READ16LETO32LE_LSW(name,read16) \
1019DEV_WRITE16LETO32LE_LSW(name,write16)
1020
src/mess/audio/pc.c
r2234r2235
3030
3131static sound_stream *channel;
3232static int speaker_gate = 0;
33static int baseclock;
3334
3435
3536
r2234r2235
4344{
4445   logerror("pc_sh_start\n");
4546   channel = stream_create(0, 1, Machine->sample_rate, 0, pc_sh_update);
47   baseclock = 4772720/4;
4648    return 0;
4749}
4850
r2234r2235
5961void pc_sh_speaker(running_machine *machine, int data)
6062{
6163   int mode = 0;
62   pit8253_0_gate_w(machine, 2, data & 1);
6364
6465   switch( data )
6566   {
r2234r2235
9091    }
9192}
9293
93void pc_sh_speaker_change_clock(double pc_clock)
94void pc_sh_speaker_change_clock(const device_config *device, double pc_clock)
9495{
9596    stream_update(channel);
97   baseclock = pit8253_get_frequency( device, 2 );
9698}
9799
98100
r2234r2235
109111   stream_sample_t *buffer = outputs[0];
110112   static int incr = 0;
111113   stream_sample_t *sample = buffer;
112   int baseclock, rate = Machine->sample_rate / 2;
114   int rate = Machine->sample_rate / 2;
113115
114   baseclock = pit8253_get_frequency(0, 2);
115
116116   switch( speaker_gate ) {
117117   case 0:
118118      /* speaker off */
src/mess/audio/pc.h
r2234r2235
1919void pc_sh_update(void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
2020void pc_sh_speaker(running_machine *machine, int mode);
2121
22void pc_sh_speaker_change_clock(double pc_clock);
22void pc_sh_speaker_change_clock(const device_config *device, double pc_clock);
2323
2424#endif /* __AUDIO_PC_H__ */
src/mess/audio/dai.c
r2234r2235
119119   }
120120}
121121
122void dai_sh_change_clock(double clock)
122void dai_sh_change_clock(const device_config *device, double clock)
123123{
124124   stream_update(mixer_channel);
125125}
src/mess/includes/compis.h
r2234r2235
1515
1616/*----------- defined in machine/compis.c -----------*/
1717
18extern const struct pit8253_config compis_pit8253_config;
19extern const struct pit8253_config compis_pit8254_config;
20
1821DRIVER_INIT(compis);
1922MACHINE_RESET(compis);
2023INTERRUPT_GEN(compis_vblank_int);
r2234r2235
2427WRITE16_HANDLER (compis_ppi_w);
2528
2629/* PIT 8253 */
27READ16_HANDLER (compis_pit_r);
28WRITE16_HANDLER (compis_pit_w);
30READ16_DEVICE_HANDLER (compis_pit_r);
31WRITE16_DEVICE_HANDLER (compis_pit_w);
2932
3033/* PIC 8259 (80150/80130) */
3134READ16_HANDLER (compis_osp_pic_r);
3235WRITE16_HANDLER (compis_osp_pic_w);
3336
3437/* PIT 8254 (80150/80130) */
35READ16_HANDLER (compis_osp_pit_r);
36WRITE16_HANDLER (compis_osp_pit_w);
38READ16_DEVICE_HANDLER (compis_osp_pit_r);
39WRITE16_DEVICE_HANDLER (compis_osp_pit_w);
3740
3841/* USART 8251 */
3942READ16_HANDLER (compis_usart_r);
src/mess/includes/dai.h
r2234r2235
1313
1414/*----------- defined in machine/dai.c -----------*/
1515
16extern const struct pit8253_config dai_pit8253_intf;
17
1618MACHINE_START( dai );
1719READ8_HANDLER( dai_io_discrete_devices_r );
1820WRITE8_HANDLER( dai_io_discrete_devices_w );
r2234r2235
3537/*----------- defined in audio/dai.c -----------*/
3638
3739extern const struct CustomSound_interface dai_sound_interface;
38extern void dai_sh_change_clock(double);
40void dai_sh_change_clock(const device_config *,double);
3941
4042
4143#endif /* DAI_H_ */
src/mess/includes/mz700.h
r2234r2235
1515
1616/*----------- defined in machine/mz700.c -----------*/
1717
18const struct pit8253_config mz700_pit8253_config;
19
1820DRIVER_INIT( mz700 );
1921MACHINE_RESET( mz700 );
2022
src/mess/includes/pmd85.h
r2234r2235
1010
1111/*----------- defined in machine/pmd85.c -----------*/
1212
13extern const struct pit8253_config pmd85_pit8253_interface;
14
1315 READ8_HANDLER ( pmd85_io_r );
1416WRITE8_HANDLER ( pmd85_io_w );
1517 READ8_HANDLER ( mato_io_r );
src/mess/includes/bebox.h
r2234r2235
1212
1313/*----------- defined in machine/bebox.c -----------*/
1414
15extern const struct pit8253_config bebox_pit8254_config;
16
1517MACHINE_RESET( bebox );
1618DRIVER_INIT( bebox );
1719NVRAM_HANDLER( bebox );
src/mess/includes/special.h
r2234r2235
1010
1111/*----------- defined in machine/special.c -----------*/
1212
13const struct pit8253_config specimx_pit8253_intf;
14
1315extern DRIVER_INIT( special );
1416extern MACHINE_RESET( special );
1517
src/mess/video/mz700.c
r2234r2235
1010 ***************************************************************************/
1111
1212#include "driver.h"
13#include "machine/pit8253.h"
1314#include "includes/mz700.h"
1415
1516
src/mess/machine/dai.c
r2234r2235
100100   { NULL, NULL },      /* Port C read */
101101};
102102
103static const struct pit8253_config dai_pit8253_intf =
103const struct pit8253_config dai_pit8253_intf =
104104{
105   TYPE8253,
106105   {
107106      {
108107         2000000,
r2234r2235
131130
132131   tms5501_init(0, &dai_tms5501_init_param);
133132   ppi8255_init(&dai_ppi82555_intf);
134   pit8253_init(1, &dai_pit8253_intf);
135133
136134   timer_set(attotime_zero, NULL, 0, dai_bootstrap_callback);
137135}
src/mess/machine/mz700.c
r2234r2235
5858static int pio_port_a_output;
5959static int pio_port_c_output;
6060
61static void pit_clk_0(double clock);
62static void pit_clk_1(double clock);
63static void pit_irq_2(int which);
61static PIT8253_FREQUENCY_CHANGED( pit_clk_0 );
62static PIT8253_FREQUENCY_CHANGED( pit_clk_1 );
63static PIT8253_OUTPUT_CHANGED( pit_irq_2 );
6464
65static const struct pit8253_config pit8253 =
65const struct pit8253_config mz700_pit8253_config =
6666{
67   TYPE8253,
6867   {
6968      /* clockin     irq callback    clock change callback */
7069      { 1108800.0,  NULL,        pit_clk_0    },
r2234r2235
8483DRIVER_INIT( mz700 )
8584{
8685   ppi8255_init(&ppi8255);
87   pit8253_init(1, &pit8253);
8886
8987   videoram_size = 0x5000;
9088   videoram = auto_malloc(videoram_size);
r2234r2235
109107/************************ PIT ************************************************/
110108
111109/* timer 0 is the clock for the speaker output */
112static void pit_clk_0(double clockout)
110static PIT8253_FREQUENCY_CHANGED( pit_clk_0 )
113111{
114112   beep_set_state(0, 1);
115    beep_set_frequency(0, clockout);
113    beep_set_frequency(0, frequency);
116114}
117115
118116/* timer 1 is the clock for timer 2 clock input */
119static void pit_clk_1(double clockout)
117static PIT8253_FREQUENCY_CHANGED( pit_clk_1 )
120118{
121   pit8253_set_clockin(0, 2, clockout);
119   pit8253_set_clockin(0, 2, frequency);
122120}
123121
124122/* timer 2 is the AM/PM (12 hour) interrupt */
125static void pit_irq_2(int which)
123static PIT8253_OUTPUT_CHANGED( pit_irq_2 )
126124{
127125   /* INTMSK: interrupt enabled? */
128126    if (pio_port_c_output & 0x04)
r2234r2235
235233      break;
236234
237235   case 4: case 5: case 6: case 7:
238      data = pit8253_0_r(machine, offset & 3);
236      data = pit8253_r((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), offset & 3);
239237        break;
240238
241239   case 8:
r2234r2235
260258
261259   /* the next four ports are connected to a 8253 PIT */
262260    case 4: case 5: case 6: case 7:
263      pit8253_0_w(machine, offset & 3, data);
261      pit8253_w((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), offset & 3, data);
264262      break;
265263
266264   case 8:
267265      LOG(1,"mz700_e008_w",("%02X\n", data));
268      pit8253_0_gate_w(machine, 0, data & 1);
266      pit8253_gate_w((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), 0, data & 1);
269267        break;
270268   }
271269}
r2234r2235
517515      break;
518516
519517   case 4: case 5: case 6: case 7:
520      data = pit8253_0_r(machine, offset & 3);
518      data = pit8253_r((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), offset & 3);
521519        break;
522520
523521   default:
src/mess/machine/pmd85.c
r2234r2235
375375
376376*******************************************************************************/
377377
378static const struct pit8253_config pmd85_pit8253_interface =
378const struct pit8253_config pmd85_pit8253_interface =
379379{
380   TYPE8253,
381380   {
382381      { 0,      NULL,   NULL },
383382      { 2000000,   NULL,   NULL },
r2234r2235
506505                        case 0x40:      /* 8255 (GPIO/0, GPIO/1) */
507506                              return ppi8255_1_r(machine, offset & 0x03);
508507                        case 0x50:   /* 8253 */
509                              return pit8253_0_r(machine, offset & 0x03);
508                              return pit8253_r( (device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), offset & 0x03);
510509                        case 0x70:   /* 8255 (IMS-2) */
511510                              return ppi8255_2_r(machine, offset & 0x03);
512511                     }
r2234r2235
581580                              ppi8255_1_w(machine, offset & 0x03, data);
582581                              break;
583582                        case 0x50:   /* 8253 */
584                              pit8253_0_w(machine, offset & 0x03, data);
583                              pit8253_w((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), offset & 0x03, data);
585584                              logerror ("8253 writing. Address: %02x, Data: %02x\n", offset, data);
586585                              break;
587586                        case 0x70:   /* 8255 (IMS-2) */
r2234r2235
774773
775774static void pmd85_common_driver_init (running_machine *machine)
776775{
776   device_config *pit8253 = (device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" );
777777   memory_set_opbase_handler(0, pmd85_opbaseoverride);
778778
779   pit8253_init(1, &pmd85_pit8253_interface);
780   pit8253_0_gate_w(machine, 0, 1);
781   pit8253_0_gate_w(machine, 1, 1);
782   pit8253_0_gate_w(machine, 2, 1);
779   pit8253_gate_w(pit8253, 0, 1);
780   pit8253_gate_w(pit8253, 1, 1);
781   pit8253_gate_w(pit8253, 2, 1);
783782
784783   msm8251_init(&pmd85_msm8251_interface);
785784
r2234r2235
860859      case PMD85_3:
861860      case ALFA:
862861         msm8251_reset();
863         pit8253_reset(0);
864862         break;
865863      case MATO:
866864         break;
src/mess/machine/europc.c
r2234r2235
170170      europc_pio.port61=data;
171171//      if (data==0x30) pc1640.port62=(pc1640.port65&0x10)>>4;
172172//      else if (data==0x34) pc1640.port62=pc1640.port65&0xf;
173      pit8253_gate_w( (device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), 2, data & 1);
173174      pc_sh_speaker(machine, data&3);
174175      pc_keyb_set_clock(data&0x40);
175176      break;
src/mess/machine/at.c
r2234r2235
4040
4141static void init_at_common(const struct kbdc8042_interface *at8042)
4242{
43   mess_init_pc_common(PCCOMMON_KEYBOARD_AT | PCCOMMON_DMA8237_AT | PCCOMMON_TIMER_8254);
43   mess_init_pc_common(PCCOMMON_KEYBOARD_AT | PCCOMMON_DMA8237_AT);
4444   mc146818_init(MC146818_STANDARD);
4545   soundblaster_config(&soundblaster);
4646   kbdc8042_init(at8042);
src/mess/machine/ibmpc.c
r2234r2235
172172      }
173173   } else {
174174      if ( pc_ppi.portb & 0x01 ) {
175         data = ( data & ~0x10 ) | ( pit8253_get_output( 0, 2 ) ? 0x10 : 0x00 );
175         data = ( data & ~0x10 ) | ( pit8253_get_output( (device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), 2 ) ? 0x10 : 0x00 );
176176      }
177177   }
178178   return data;
r2234r2235
190190   pc_ppi.portb = data;
191191   pc_ppi.portc_switch_high = data & 0x08;
192192   pc_ppi.keyboard_disabled = data & 0x80;
193   pit8253_gate_w( (device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), 2, data & 1);
193194   pc_sh_speaker(machine, data & 0x03);
194195   pc_keyb_set_clock(data & 0x40);
195196
src/mess/machine/bebox.c
r2234r2235
698698 *
699699 *************************************/
700700
701static void bebox_timer0_w(int state)
701static void bebox_timer0_w(const device_config *device, int state)
702702{
703703   pic8259_set_irq_line(0, 0, state);
704704}
705705
706706
707static const struct pit8253_config bebox_pit8254_config =
707const struct pit8253_config bebox_pit8254_config =
708708{
709   TYPE8254,
710709   {
711710      {
712711         4772720/4,            /* heartbeat IRQ */
r2234r2235
10181017   pic8259_init(2, bebox_pic_set_int_line);
10191018   ide_controller_init_custom(0, &bebox_ide_interface, NULL);
10201019   pc_vga_init(&bebox_vga_interface, &cirrus_svga_interface);
1021   pit8253_init(1, &bebox_pit8254_config);
10221020   kbdc8042_init(&bebox_8042_interface);
10231021
10241022   dma8237_init(2);
src/mess/machine/special.c
r2234r2235
206206   memset(mess_ram,0,128*1024);
207207}
208208
209static const struct pit8253_config specimx_pit8253_intf =
209const struct pit8253_config specimx_pit8253_intf =
210210{
211   TYPE8253,
212211   {
213212      {
214213         2000000,
r2234r2235
232231{
233232   wd17xx_init(machine, WD_TYPE_1793, NULL , NULL);
234233   wd17xx_set_density (DEN_FM_HI);
235   pit8253_init(1, &specimx_pit8253_intf);
236234}
237235
238236MACHINE_RESET( specimx )
239237{
238   device_config *pit8253 = (device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" );
239
240240   ppi8255_init(&specialist_ppi8255_interface);
241241   specimx_set_bank(2,0x00); // Initiali load ROM disk
242242   specimx_color = 0x70;   
243243   wd17xx_reset();
244244   wd17xx_set_side(0);
245   pit8253_reset(0);
246   pit8253_0_gate_w(machine, 0, 0);
247   pit8253_0_gate_w(machine, 1, 0);
248   pit8253_0_gate_w(machine, 2, 0);
245   pit8253_gate_w(pit8253, 0, 0);
246   pit8253_gate_w(pit8253, 1, 0);
247   pit8253_gate_w(pit8253, 2, 0);
249248}
250249
251250READ8_HANDLER ( specimx_disk_ctrl_r )
r2234r2235
305304WRITE8_HANDLER( specimx_sound_w)
306305{
307306   
308      pit8253_0_w(machine,offset,data);     
307      pit8253_w((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ),offset,data);     
309308}
310309
311310
src/mess/machine/tandy1t.c
r2234r2235
33#include "machine/pckeybrd.h"
44
55#include "machine/pcshare.h"
6#include "machine/pit8253.h"
67#include "audio/pc.h"
78#include "includes/tandy1t.h"
89
r2234r2235
183184   switch (offset) {
184185   case 1:
185186      tandy_ppi.portb = data;
187      pit8253_gate_w( (device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), 2, data & 1);
186188      pc_sh_speaker(machine, data&3);
187189      pc_keyb_set_clock(data&0x40);
188190      break;
src/mess/machine/pc.c
r2234r2235
221221
222222DRIVER_INIT( pccga )
223223{
224   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
224   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
225225   ppi8255_init(&pc_ppi8255_interface);
226226   pc_rtc_init();
227227   pc_turbo_setup(0, 3, 0x02, 4.77/12, 1);
r2234r2235
229229
230230DRIVER_INIT( bondwell )
231231{
232   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
232   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
233233   ppi8255_init(&pc_ppi8255_interface);
234234   pc_turbo_setup(0, 3, 0x02, 4.77/12, 1);
235235}
236236
237237DRIVER_INIT( pcmda )
238238{
239   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
239   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
240240   ppi8255_init(&pc_ppi8255_interface);
241241   pc_turbo_setup(0, 3, 0x02, 4.77/12, 1);
242242}
r2234r2235
262262      rom[0xfffff]=256-a;
263263   }
264264
265   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
265   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
266266
267267   europc_rtc_init();
268268//   europc_rtc_set_time(machine);
r2234r2235
275275    /* just a plain bit pattern for graphics data generation */
276276    for (i = 0; i < 256; i++)
277277      gfx[i] = i;
278   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
278   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
279279   pc_turbo_setup(0, 3, 0x02, 4.77/12, 1);
280280}
281281
r2234r2235
294294   videoram=memory_region(REGION_CPU1)+0xb0000;
295295   memory_install_read16_handler(0, ADDRESS_SPACE_IO, 0x278, 0x27b, 0, 0, pc200_16le_port378_r );
296296
297   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
297   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
298298}
299299
300300DRIVER_INIT( pc1512 )
r2234r2235
315315   memory_install_read16_handler(0, ADDRESS_SPACE_IO, 0x278, 0x27b, 0, 0, pc16le_parallelport2_r );
316316
317317
318   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
318   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
319319   mc146818_init(MC146818_IGNORE_CENTURY);
320320}
321321
r2234r2235
378378   memory_install_read16_handler(0, ADDRESS_SPACE_IO, 0x278, 0x27b, 0, 0, pc1640_16le_port278_r );
379379   memory_install_read16_handler(0, ADDRESS_SPACE_IO, 0x4278, 0x427b, 0, 0, pc1640_16le_port4278_r );
380380
381   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
381   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
382382
383383   mc146818_init(MC146818_IGNORE_CENTURY);
384384}
385385
386386DRIVER_INIT( pc_vga )
387387{
388   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_TIMER_8253 | PCCOMMON_NEC765_RDY_NC);
388   mess_init_pc_common(PCCOMMON_KEYBOARD_PC | PCCOMMON_DMA8237_PC | PCCOMMON_NEC765_RDY_NC);
389389   ppi8255_init(&pc_ppi8255_interface);
390390
391391   pc_vga_init(&vga_interface, NULL);
src/mess/machine/amstr_pc.c
r2234r2235
154154      pc1640.port61=data;
155155      if (data==0x30) pc1640.port62=(pc1640.port65&0x10)>>4;
156156      else if (data==0x34) pc1640.port62=pc1640.port65&0xf;
157      pit8253_gate_w( (device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8253, "pit8253" ), 2, data & 1);
157158      pc_sh_speaker(machine, data&3);
158159      pc_keyb_set_clock(data&0x40);
159160      break;
src/mess/machine/compis.c
r2234r2235
460460/*  PIT 8253                                                               */
461461/*-------------------------------------------------------------------------*/
462462
463static const struct pit8253_config compis_pit_config[2] =
463const struct pit8253_config compis_pit8253_config =
464464{
465{
466   TYPE8253,
467465   {
468466      /* Timer0 */
469467      {4770000/4, NULL, NULL },
r2234r2235
472470      /* Timer2 */
473471      {4770000/4, NULL, NULL }
474472   }
475},
473};
474
475const struct pit8253_config compis_pit8254_config =
476476{
477   TYPE8254,
478477   {
479478      /* Timer0 */
480479      {4770000/4, NULL, NULL },
r2234r2235
483482      /* Timer2 */
484483      {4770000/4, NULL, NULL }
485484   }
486}
487485};
488486
489READ16_HANDLER ( compis_pit_r )
487READ16_DEVICE_HANDLER ( compis_pit_r )
490488{
491   return pit8253_0_r(machine, offset);
489   return pit8253_r(device, offset);
492490}
493491
494WRITE16_HANDLER ( compis_pit_w )
492WRITE16_DEVICE_HANDLER ( compis_pit_w )
495493{
496   pit8253_0_w(machine, offset , data);
494   pit8253_w(device, offset , data);
497495}
498496
499497/*-------------------------------------------------------------------------*/
500498/*  OSP PIT 8254                                                           */
501499/*-------------------------------------------------------------------------*/
502500
503READ16_HANDLER ( compis_osp_pit_r )
501READ16_DEVICE_HANDLER ( compis_osp_pit_r )
504502{
505   return pit8253_1_r(machine, offset);
503   return pit8253_r(device, offset);
506504}
507505
508WRITE16_HANDLER ( compis_osp_pit_w )
506WRITE16_DEVICE_HANDLER ( compis_osp_pit_w )
509507{
510   pit8253_1_w(machine, offset, data);
508   pit8253_w(device, offset, data);
511509}
512510
513511/*-------------------------------------------------------------------------*/
r2234r2235
15811579   /* CPU */
15821580   compis_cpu_init();
15831581
1584   /* OSP PIT 8254 */
1585   pit8253_init(2, compis_pit_config);
1586
15871582   /* PPI */
15881583   ppi8255_init(&compis_ppi_interface);
15891584
src/mess/drivers/dai.c
r2234r2235
7979   AM_RANGE( 0xf000, 0xf7ff) AM_WRITE( dai_stack_interrupt_circuit_w )
8080   AM_RANGE( 0xf800, 0xf8ff) AM_RAM
8181   AM_RANGE( 0xfb00, 0xfbff) AM_READWRITE( amd9511_r, amd9511_w )
82   AM_RANGE( 0xfc00, 0xfcff) AM_READWRITE( pit8253_0_r, pit8253_0_w )
82   AM_RANGE( 0xfc00, 0xfcff) AM_DEVREADWRITE( PIT8253, "pit8253", pit8253_r, pit8253_w )
8383   AM_RANGE( 0xfd00, 0xfdff) AM_READWRITE( dai_io_discrete_devices_r, dai_io_discrete_devices_w )
8484   AM_RANGE( 0xfe00, 0xfeff) AM_READWRITE( ppi8255_0_r, ppi8255_0_w )
8585   AM_RANGE( 0xff00, 0xffff) AM_READWRITE( tms5501_0_r, tms5501_0_w )
r2234r2235
184184
185185   MDRV_MACHINE_START( dai )
186186
187   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
188   MDRV_DEVICE_CONFIG( dai_pit8253_intf )
189
187190   /* video hardware */
188191   MDRV_SCREEN_ADD("main", RASTER)
189192   MDRV_SCREEN_REFRESH_RATE(50)
src/mess/drivers/mz700.c
r2234r2235
6666/* Core includes */
6767#include "driver.h"
6868#include "includes/mz700.h"
69#include "machine/pit8253.h"
6970
7071/* Devices */
7172#include "devices/cassette.h"
r2234r2235
255256
256257   MDRV_MACHINE_RESET( mz700 )
257258
259   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
260   MDRV_DEVICE_CONFIG( mz700_pit8253_config )
261
258262   /* video hardware - include overscan */
259263   MDRV_SCREEN_ADD("main", RASTER)
260264   MDRV_SCREEN_REFRESH_RATE(50)
r2234r2235
284288
285289   MDRV_MACHINE_RESET( mz700 )
286290
291   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
292   MDRV_DEVICE_CONFIG( mz700_pit8253_config )
293
287294   /* video hardware - include overscan */
288295   MDRV_SCREEN_ADD("main", RASTER)
289296   MDRV_SCREEN_REFRESH_RATE(50)
src/mess/drivers/pasogo.c
r2234r2235
296296//   ADDRESS_MAP_GLOBAL_MASK(0xfFFF)
297297   AM_RANGE(0x0020, 0x0021) AM_READWRITE(pic8259_0_r,         pic8259_0_w)
298298     AM_RANGE(0x26, 0x27) AM_READWRITE(vg230_io_r, vg230_io_w )
299   AM_RANGE(0x0040, 0x0043) AM_READWRITE(pit8253_0_r,         pit8253_0_w)
299   AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE(PIT8254, "pit8254", pit8253_r, pit8253_w)
300300     AM_RANGE(0x6c, 0x6f) AM_READWRITE(ems_r, ems_w )
301301ADDRESS_MAP_END
302302
r2234r2235
399399
400400static MACHINE_RESET( pasogo )
401401{
402  pit8253_reset(0);
403402  cpunum_set_irq_callback(0, pasogo_irq_callback);
404403}
405404
406405//static const unsigned i86_address_mask = 0x000fffff;
407406
407static PIT8253_OUTPUT_CHANGED( pc_timer0_w )
408{
409   pic8259_set_irq_line(0, 0, state);
410}
411
412static const struct pit8253_config pc_pit8254_config =
413{
414   {
415      {
416         4772720/4,            /* heartbeat IRQ */
417         pc_timer0_w,
418         NULL
419      }, {
420         4772720/4,            /* dram refresh */
421         NULL,
422         NULL
423      }, {
424         4772720/4,            /* pio port c pin 4, and speaker polling enough */
425         NULL,
426         //      pc_sh_speaker_change_clock
427      }
428   }
429};
430
408431static MACHINE_DRIVER_START( pasogo )
409432     MDRV_CPU_ADD_TAG("main", I80188/*V30HL in vadem vg230*/, 10000000/*?*/)
410433MDRV_CPU_PROGRAM_MAP(pasogo_mem, 0)
r2234r2235
413436//   MDRV_CPU_CONFIG(i86_address_mask)
414437   MDRV_MACHINE_RESET( pasogo )
415438
439   MDRV_DEVICE_ADD( "pit8254", PIT8254 )
440   MDRV_DEVICE_CONFIG( pc_pit8254_config )
416441
417442     MDRV_SCREEN_ADD("main", LCD)
418443     MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
r2234r2235
438463   ROM_REGION(0x80000,REGION_USER1, 0)
439464ROM_END
440465
441static void pc_timer0_w(int state)
442{
443   pic8259_set_irq_line(0, 0, state);
444}
445
446static const struct pit8253_config pc_pit8254_config =
447{
448   TYPE8254,
449   {
450      {
451         4772720/4,            /* heartbeat IRQ */
452         pc_timer0_w,
453         NULL
454      }, {
455         4772720/4,            /* dram refresh */
456         NULL,
457         NULL
458      }, {
459         4772720/4,            /* pio port c pin 4, and speaker polling enough */
460         NULL,
461         //         pc_sh_speaker_change_clock
462      }
463   }
464};
465
466466static void pasogo_pic_set_int_line(int which, int interrupt)
467467{
468468  cpunum_set_input_line(Machine, 0, 0, interrupt ? HOLD_LINE : CLEAR_LINE);
r2234r2235
474474  memset(&ems, 0, sizeof(ems));
475475  memory_set_bankptr( 27, memory_region(REGION_USER1) + 0x00000 );
476476  memory_set_bankptr( 28, memory_region(REGION_CPU1) + 0xb8000/*?*/ );
477  pit8253_init(1, &pc_pit8254_config);
478477  pic8259_init(1, pasogo_pic_set_int_line);
479478}
480479
src/mess/drivers/pmd85.c
r2234r2235
173173#include "cpu/i8085/i8085.h"
174174#include "devices/cassette.h"
175175#include "includes/pmd85.h"
176#include "machine/pit8253.h"
176177#include "formats/pmd_pmd.h"
177178
178179/* I/O ports */
r2234r2235
532533
533534   MDRV_MACHINE_RESET( pmd85 )
534535
536   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
537   MDRV_DEVICE_CONFIG( pmd85_pit8253_interface )
538
535539   /* video hardware */
536540   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
537541   MDRV_SCREEN_SIZE(288, 256)
src/mess/drivers/ip22.c
r2234r2235
8484
8585static const struct pit8253_config ip22_pit8254_config =
8686{
87   TYPE8254,
8887   {
8988      {
9089         1000000,            /* Timer 0: 1MHz */
r2234r2235
254253      return int3_regs[offset-0x80/4];
255254      break;
256255   case 0xb0/4:
257      ret8 = pit8253_0_r(machine, 0);
256      ret8 = pit8253_r((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8254, "pit8254" ), 0);
258257      verboselog( 0, "HPC PBUS6 IOC4 Timer Counter 0 Register Read: 0x%02x (%08x)\n", ret8, mem_mask );
259258      return ret8;
260259      break;
261260   case 0xb4/4:
262      ret8 = pit8253_0_r(machine, 1);
261      ret8 = pit8253_r((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8254, "pit8254" ), 1);
263262      verboselog( 0, "HPC PBUS6 IOC4 Timer Counter 1 Register Read: 0x%02x (%08x)\n", ret8, mem_mask );
264263      return ret8;
265264      break;
266265   case 0xb8/4:
267      ret8 = pit8253_0_r(machine, 2);
266      ret8 = pit8253_r((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8254, "pit8254" ), 2);
268267      verboselog( 0, "HPC PBUS6 IOC4 Timer Counter 2 Register Read: 0x%02x (%08x)\n", ret8, mem_mask );
269268      return ret8;
270269      break;
271270   case 0xbc/4:
272      ret8 = pit8253_0_r(machine, 3);
271      ret8 = pit8253_r((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8254, "pit8254" ), 3);
273272      verboselog( 0, "HPC PBUS6 IOC4 Timer Control Word Register Read: 0x%02x (%08x)\n", ret8, mem_mask );
274273      return ret8;
275274      break;
r2234r2235
362361      break;
363362   case 0xb0/4:
364363      verboselog( 0, "HPC PBUS6 IOC4 Timer Counter 0 Register Write: 0x%08x (%08x)\n", data, mem_mask );
365      pit8253_0_w(machine, 0, data & 0x000000ff);
364      pit8253_w((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8254, "pit8254" ), 0, data & 0x000000ff);
366365      return;
367366      break;
368367   case 0xb4/4:
369368      verboselog( 0, "HPC PBUS6 IOC4 Timer Counter 1 Register Write: 0x%08x (%08x)\n", data, mem_mask );
370      pit8253_0_w(machine, 1, data & 0x000000ff);
369      pit8253_w((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8254, "pit8254" ), 1, data & 0x000000ff);
371370      return;
372371      break;
373372   case 0xb8/4:
374373      verboselog( 0, "HPC PBUS6 IOC4 Timer Counter 2 Register Write: 0x%08x (%08x)\n", data, mem_mask );
375      pit8253_0_w(machine, 2, data & 0x000000ff);
374      pit8253_w((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8254, "pit8254" ), 2, data & 0x000000ff);
376375      return;
377376      break;
378377   case 0xbc/4:
379378      verboselog( 0, "HPC PBUS6 IOC4 Timer Control Word Register Write: 0x%08x (%08x)\n", data, mem_mask );
380      pit8253_0_w(machine, 3, data & 0x000000ff);
379      pit8253_w((device_config*)device_list_find_by_tag( machine->config->devicelist, PIT8254, "pit8254" ), 3, data & 0x000000ff);
381380      return;
382381      break;
383382   default:
r2234r2235
14531452
14541453   // IP22 uses 2 pieces of PC-compatible hardware: the 8042 PS/2 keyboard/mouse
14551454   // interface and the 8254 PIT.  Both are licensed cores embedded in the IOC custom chip.
1456   init_pc_common(PCCOMMON_KEYBOARD_AT | PCCOMMON_TIMER_NONE );
1455   init_pc_common(PCCOMMON_KEYBOARD_AT);
14571456   kbdc8042_init(&at8042);
1458   pit8253_init(1, &ip22_pit8254_config);
14591457
14601458   // SCSI init
14611459   wd33c93_init(&scsi_intf);
r2234r2235
15881586   MDRV_MACHINE_RESET( ip225015 )
15891587   MDRV_NVRAM_HANDLER( ip22 )
15901588
1589   MDRV_DEVICE_ADD( "pit8254", PIT8254 )
1590   MDRV_DEVICE_CONFIG( ip22_pit8254_config )
1591
15911592   /* video hardware */
15921593   MDRV_SCREEN_ADD("main", RASTER)
15931594   MDRV_SCREEN_REFRESH_RATE( 60 )
src/mess/drivers/bw2.c
r2234r2235
3636#include "devices/printer.h"
3737#include "video/msm6255.h"
3838
39#define SCREEN_TAG   "main"
40#define MSM6255_TAG   "ic49"
39#define SCREEN_TAG   "main"
40#define MSM6255_TAG   "ic49"
4141
4242/* Memory */
4343
r2234r2235
299299
300300
301301/* PIT */
302
303static void bw2_timer0_w(int state)
302static PIT8253_OUTPUT_CHANGED( bw2_timer0_w )
304303{
305304   msm8251_transmit_clock();
306305   msm8251_receive_clock();
307306}
308307
309static void bw2_timer2_w(int state)
308
309static PIT8253_OUTPUT_CHANGED( bw2_timer2_w )
310310{
311311
312312}
313313
314314static const struct pit8253_config bw2_pit8253_interface =
315315{
316   TYPE8253,
317316   {
318317      {
319318         XTAL_4MHz,   /* 8251 USART TXC, RXC */
r2234r2235
394393   centronics_config(0, bw2_centronics_config);
395394
396395   msm8251_init(&bw2_msm8251_interface);
397   pit8253_init(1, &bw2_pit8253_interface);
398396
399397   ppi8255_init(&bw2_ppi8255_interface);
400398
r2234r2235
417415   ADDRESS_MAP_UNMAP_HIGH
418416   ADDRESS_MAP_GLOBAL_MASK(0xff)
419417   AM_RANGE( 0x00, 0x03 ) AM_READWRITE( ppi8255_0_r, ppi8255_0_w )
420   AM_RANGE( 0x10, 0x13 ) AM_READWRITE( pit8253_0_r, pit8253_0_w )
418   AM_RANGE( 0x10, 0x13 ) AM_DEVREADWRITE( PIT8253, "pit8253", pit8253_r, pit8253_w )
421419   AM_RANGE( 0x20, 0x21 ) AM_DEVREADWRITE( MSM6255, MSM6255_TAG, msm6255_register_r, msm6255_register_w )
422420
423421   AM_RANGE( 0x40, 0x40 ) AM_READWRITE( msm8251_data_r, msm8251_data_w )
r2234r2235
558556   return videoram[ma & 0x3fff];
559557}
560558
561static const msm6255_interface bw2_msm6255_intf =
562{
563   SCREEN_TAG,
564   0,
565   0,
566   bw2_charram_r,
567};
559static const msm6255_interface bw2_msm6255_intf =
560{
561   SCREEN_TAG,
562   0,
563   0,
564   bw2_charram_r,
565};
568566
569567static MACHINE_DRIVER_START( bw2 )
570568   /* basic machine hardware */
r2234r2235
575573   MDRV_MACHINE_START( bw2 )
576574   MDRV_MACHINE_RESET( bw2 )
577575
576   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
577   MDRV_DEVICE_CONFIG( bw2_pit8253_interface )
578
578579   /* video hardware */
579580   MDRV_SCREEN_ADD( SCREEN_TAG, LCD )
580581   MDRV_SCREEN_REFRESH_RATE( 60 )
r2234r2235
587588   MDRV_VIDEO_START( bw2 )
588589   MDRV_VIDEO_UPDATE( bw2 )
589590
590   MDRV_DEVICE_ADD(MSM6255_TAG, MSM6255)
591   MDRV_DEVICE_CONFIG(bw2_msm6255_intf)
591   MDRV_DEVICE_ADD(MSM6255_TAG, MSM6255)
592   MDRV_DEVICE_CONFIG(bw2_msm6255_intf)
592593MACHINE_DRIVER_END
593594
594595/***************************************************************************
src/mess/drivers/bebox.c
r2234r2235
99/* Core includes */
1010#include "driver.h"
1111#include "memconv.h"
12#include "devconv.h"
1213#include "includes/bebox.h"
1314
1415/* Components */
r2234r2235
4546   write64be_with_write8_handler(at_dma8237_1_w, machine, offset, data, mem_mask);
4647}
4748
49DEV_READWRITE8TO64BE( bebox_pit8254_64be, pit8253_r, pit8253_w )
50
4851static ADDRESS_MAP_START( bebox_mem, ADDRESS_SPACE_PROGRAM, 64 )
4952   AM_RANGE(0x7FFFF0F0, 0x7FFFF0F7) AM_READWRITE( bebox_cpu0_imask_r, bebox_cpu0_imask_w )
5053   AM_RANGE(0x7FFFF1F0, 0x7FFFF1F7) AM_READWRITE( bebox_cpu1_imask_r, bebox_cpu1_imask_w )
r2234r2235
5457
5558   AM_RANGE(0x80000000, 0x8000001F) AM_READWRITE( dma8237_64be_0_r, dma8237_64be_0_w )
5659   AM_RANGE(0x80000020, 0x8000003F) AM_READWRITE( pic8259_64be_0_r, pic8259_64be_0_w )
57   AM_RANGE(0x80000040, 0x8000005f) AM_READWRITE( pit8253_64be_0_r, pit8253_64be_0_w )
60   AM_RANGE(0x80000040, 0x8000005f) AM_DEVREADWRITE(PIT8254, "pit8254", bebox_pit8254_64be_r, bebox_pit8254_64be_w)
5861   AM_RANGE(0x80000060, 0x8000006F) AM_READWRITE( kbdc8042_64be_r, kbdc8042_64be_w )
5962   AM_RANGE(0x80000070, 0x8000007F) AM_READWRITE( mc146818_port64be_r, mc146818_port64be_w )
6063   AM_RANGE(0x80000080, 0x8000009F) AM_READWRITE( bebox_page_r, bebox_page_w)
r2234r2235
104107
105108   MDRV_INTERLEAVE(1)
106109
110   MDRV_DEVICE_ADD( "pit8254", PIT8254 )
111   MDRV_DEVICE_CONFIG( bebox_pit8254_config )
112
107113   /* video hardware */
108114   MDRV_IMPORT_FROM( pcvideo_vga )
109115   MDRV_SCREEN_MODIFY("main")
src/mess/drivers/special.c
r2234r2235
7070    AM_RANGE( 0xffe9, 0xffe9 ) AM_READWRITE(wd17xx_track_r,wd17xx_track_w)
7171    AM_RANGE( 0xffea, 0xffea ) AM_READWRITE(wd17xx_sector_r,wd17xx_sector_w)
7272    AM_RANGE( 0xffea, 0xffeb ) AM_READWRITE(wd17xx_data_r,wd17xx_data_w)
73    AM_RANGE( 0xffec, 0xffef ) AM_READWRITE(pit8253_0_r, specimx_sound_w)
73    AM_RANGE( 0xffec, 0xffef ) AM_DEVREAD(PIT8253, "pit8253", pit8253_r) AM_WRITE(specimx_sound_w)
7474    AM_RANGE( 0xfff0, 0xfff3 ) AM_READWRITE(specimx_disk_ctrl_r, specimx_disk_ctrl_w)
7575    AM_RANGE( 0xfff8, 0xfff8 ) AM_READWRITE(specimx_video_color_r,specimx_video_color_w)
7676    AM_RANGE( 0xfffc, 0xfffe ) AM_WRITE(specimx_select_bank)     
r2234r2235
317317    MDRV_CPU_ADD_TAG("main", 8080, 2000000)
318318    MDRV_CPU_PROGRAM_MAP(specialist_mem, 0)
319319    MDRV_MACHINE_RESET( special )
320       
320
321   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
322   MDRV_DEVICE_CONFIG( specimx_pit8253_intf )
323
321324    /* video hardware */       
322325      MDRV_SCREEN_ADD("main", RASTER)         
323326      MDRV_SCREEN_REFRESH_RATE(50)
src/mess/drivers/pc.c
r2234r2235
4343#include "driver.h"
4444#include "deprecat.h"
4545#include "memconv.h"
46#include "devconv.h"
4647
4748#include "machine/8255ppi.h"
4849#include "machine/uart8250.h"
r2234r2235
161162static ADDRESS_MAP_START(pc8_io, ADDRESS_SPACE_IO, 8)
162163   AM_RANGE(0x0000, 0x000f) AM_READWRITE(dma8237_0_r,         dma8237_0_w)
163164   AM_RANGE(0x0020, 0x0021) AM_READWRITE(pic8259_0_r,         pic8259_0_w)
164   AM_RANGE(0x0040, 0x0043) AM_READWRITE(pit8253_0_r,         pit8253_0_w)
165   AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE(PIT8253, "pit8253", pit8253_r, pit8253_w)
165166   AM_RANGE(0x0060, 0x0063) AM_READWRITE(ppi8255_0_r,         ppi8255_0_w)
166167   AM_RANGE(0x0080, 0x0087) AM_READWRITE(pc_page_r,         pc_page_w)
167168   AM_RANGE(0x0200, 0x0207) AM_READWRITE(pc_JOY_r,            pc_JOY_w)
r2234r2235
186187ADDRESS_MAP_END
187188
188189
190DEV_READWRITE8TO16LE_LSB( pc_pit8253_16le, pit8253_r, pit8253_w )
189191
190192static ADDRESS_MAP_START(pc16_io, ADDRESS_SPACE_IO, 16)
191193   AM_RANGE(0x0000, 0x000f) AM_READWRITE(dma8237_16le_0_r,         dma8237_16le_0_w)
192194   AM_RANGE(0x0020, 0x0021) AM_READWRITE(pic8259_16le_0_r,         pic8259_16le_0_w)
193   AM_RANGE(0x0040, 0x0043) AM_READWRITE(pit8253_16le_0_r,         pit8253_16le_0_w)
195   AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE(PIT8253, "pit8253", pc_pit8253_16le_r, pc_pit8253_16le_w)
194196   AM_RANGE(0x0060, 0x0063) AM_READWRITE(ppi8255_16le_0_r,         ppi8255_16le_0_w)
195197   AM_RANGE(0x0080, 0x0087) AM_READWRITE(pc_page16le_r,         pc_page16le_w)
196198   AM_RANGE(0x0200, 0x0207) AM_READWRITE(pc16le_JOY_r,            pc16le_JOY_w)
r2234r2235
231233static ADDRESS_MAP_START(europc_io, ADDRESS_SPACE_IO, 8)
232234   AM_RANGE(0x0000, 0x000f) AM_READWRITE(dma8237_0_r,         dma8237_0_w)
233235   AM_RANGE(0x0020, 0x0021) AM_READWRITE(pic8259_0_r,         pic8259_0_w)
234   AM_RANGE(0x0040, 0x0043) AM_READWRITE(pit8253_0_r,         pit8253_0_w)
236   AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE(PIT8253, "pit8253", pit8253_r, pit8253_w)
235237   AM_RANGE(0x0060, 0x0063) AM_READWRITE(europc_pio_r,         europc_pio_w)
236238   AM_RANGE(0x0080, 0x0087) AM_READWRITE(pc_page_r,         pc_page_w)
237239   AM_RANGE(0x0200, 0x0207) AM_READWRITE(pc_JOY_r,            pc_JOY_w)
r2234r2235
271273static ADDRESS_MAP_START(tandy1000_io, ADDRESS_SPACE_IO, 8)
272274   AM_RANGE(0x0000, 0x000f) AM_READWRITE(dma8237_0_r,            dma8237_0_w)
273275   AM_RANGE(0x0020, 0x0021) AM_READWRITE(pic8259_0_r,            pic8259_0_w)
274   AM_RANGE(0x0040, 0x0043) AM_READWRITE(pit8253_0_r,            pit8253_0_w)
276   AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE(PIT8253, "pit8253", pit8253_r, pit8253_w)
275277   AM_RANGE(0x0060, 0x0063) AM_READWRITE(tandy1000_pio_r,         tandy1000_pio_w)
276278   AM_RANGE(0x0080, 0x0087) AM_READWRITE(pc_page_r,            pc_page_w)
277279   AM_RANGE(0x00c0, 0x00c0) AM_WRITE(                        SN76496_0_w)
r2234r2235
291293static ADDRESS_MAP_START(pc200_io, ADDRESS_SPACE_IO, 16)
292294   AM_RANGE(0x0000, 0x000f) AM_READWRITE(dma8237_16le_0_r,            dma8237_16le_0_w)
293295   AM_RANGE(0x0020, 0x0021) AM_READWRITE(pic8259_16le_0_r,            pic8259_16le_0_w)
294   AM_RANGE(0x0040, 0x0043) AM_READWRITE(pit8253_16le_0_r,            pit8253_16le_0_w)
296   AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE(PIT8253, "pit8253", pc_pit8253_16le_r, pc_pit8253_16le_w)
295297   AM_RANGE(0x0060, 0x0065) AM_READWRITE(pc1640_16le_port60_r,         pc1640_16le_port60_w)
296298   AM_RANGE(0x0078, 0x0079) AM_READWRITE(pc1640_16le_mouse_x_r,         pc1640_16le_mouse_x_w)
297299   AM_RANGE(0x007a, 0x007b) AM_READWRITE(pc1640_16le_mouse_y_r,         pc1640_16le_mouse_y_w)
r2234r2235
324326static ADDRESS_MAP_START(pc1640_io, ADDRESS_SPACE_IO, 16)
325327   AM_RANGE(0x0000, 0x000f) AM_READWRITE(dma8237_16le_0_r,         dma8237_16le_0_w)
326328   AM_RANGE(0x0020, 0x0021) AM_READWRITE(pic8259_16le_0_r,         pic8259_16le_0_w)
327   AM_RANGE(0x0040, 0x0043) AM_READWRITE(pit8253_16le_0_r,         pit8253_16le_0_w)
329   AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE(PIT8253, "pit8253", pc_pit8253_16le_r, pc_pit8253_16le_w)
328330   AM_RANGE(0x0060, 0x0065) AM_READWRITE(pc1640_16le_port60_r,         pc1640_16le_port60_w)
329331   AM_RANGE(0x0070, 0x0071) AM_READWRITE(mc146818_port16le_r,      mc146818_port16le_w)
330332   AM_RANGE(0x0078, 0x0079) AM_READWRITE(pc1640_16le_mouse_x_r,   pc1640_16le_mouse_x_w)
r2234r2235
11261128};
11271129#endif
11281130
1131static PIT8253_OUTPUT_CHANGED( pc_timer0_w )
1132{
1133   pic8259_set_irq_line(0, 0, state);
1134}
1135 
1136
1137static const struct pit8253_config pc_pit8253_config =
1138{
1139   {
1140      {
1141         4772720/4,            /* heartbeat IRQ */
1142         pc_timer0_w,
1143         NULL
1144      }, {
1145         4772720/4,            /* dram refresh */
1146         NULL,
1147         NULL
1148      }, {
1149         4772720/4,            /* pio port c pin 4, and speaker polling enough */
1150         NULL,
1151         pc_sh_speaker_change_clock
1152      }
1153   }
1154};
1155
1156
11291157#define MDRV_CPU_PC(mem, port, type, clock, vblankfunc)   \
11301158   MDRV_CPU_ADD_TAG("main", type, clock)            \
11311159   MDRV_CPU_PROGRAM_MAP(mem##_map, 0)         \
r2234r2235
11431171
11441172   MDRV_MACHINE_RESET(pc_mda)
11451173
1174   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1175   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1176
11461177   /* video hardware */
11471178   MDRV_IMPORT_FROM( pcvideo_mda )
11481179
r2234r2235
11741205
11751206   MDRV_MACHINE_RESET(pc_mda)
11761207
1208   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1209   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1210
11771211   /* video hardware */
11781212   MDRV_IMPORT_FROM( pcvideo_hercules )
11791213
r2234r2235
12011235
12021236   MDRV_MACHINE_RESET(pc_cga)
12031237
1238   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1239   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1240
12041241   /* video hardware */
12051242   MDRV_IMPORT_FROM( pcvideo_cga )
12061243
r2234r2235
12291266
12301267   MDRV_MACHINE_RESET(pc_aga)
12311268
1269   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1270   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1271
12321272   /* video hardware */
12331273   MDRV_IMPORT_FROM( pcvideo_aga )
12341274
r2234r2235
12531293
12541294   MDRV_MACHINE_RESET(pc_cga)
12551295
1296   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1297   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1298
12561299   /* video hardware */
12571300   MDRV_IMPORT_FROM( pcvideo_cga )
12581301
r2234r2235
12811324
12821325   MDRV_MACHINE_RESET(pc_aga)
12831326
1327   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1328   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1329
12841330   /* video hardware */
12851331   MDRV_IMPORT_FROM( pcvideo_pc200 )
12861332
r2234r2235
12981344
12991345   MDRV_MACHINE_RESET(pc_pc1512)
13001346
1347   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1348   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1349
13011350   /* video hardware */
13021351   MDRV_IMPORT_FROM( pcvideo_pc1512 )
13031352
r2234r2235
13171366
13181367   MDRV_MACHINE_RESET(pc_vga)
13191368
1369   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1370   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1371
13201372   /* video hardware */
13211373   MDRV_IMPORT_FROM(pcvideo_pc1640)
13221374   MDRV_SCREEN_MODIFY("main")
r2234r2235
13391391
13401392   MDRV_MACHINE_RESET(pc_vga)
13411393
1394   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1395   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1396
13421397   /* video hardware */
13431398   MDRV_IMPORT_FROM( pcvideo_vga )
13441399   MDRV_SCREEN_MODIFY("main")
r2234r2235
13701425
13711426   MDRV_MACHINE_RESET(pc_t1t)
13721427
1428   MDRV_DEVICE_ADD( "pit8253", PIT8253 )
1429   MDRV_DEVICE_CONFIG( pc_pit8253_config )
1430
13731431   /* video hardware */
13741432   MDRV_IMPORT_FROM( pcvideo_t1000 )
13751433

Previous 15994 Revisions Next


© 1998-2018 The MESS Team