Previous 15994 Revisions Next

r9668 Friday 26th November, 2010 at 12:53:51 UTC by Nathan Woods
More driver_device conversions. [Atari Ace]
[src/mess/drivers]beehive.c d6800.c dual68.c gp2x.c h8.c homez80.c jr100.c jr200.c lviv.c multi8.c mz2500.c nc.c odyssey2.c pdp1.c psx.c ssystem3.c tx0.c vectrex.c
[src/mess/includes]concept.h lviv.h nc.h odyssey2.h pdp1.h ssystem3.h tx0.h vectrex.h
[src/mess/machine]concept.c lviv.c nc.c odyssey2.c pdp1.c tx0.c vectrex.c
[src/mess/video]lviv.c nc.c odyssey2.c pdp1.c ssystem3.c tx0.c vectrex.c

src/mess/machine/pdp1.c
r9667r9668
3434#define LOG_IOT_OVERLAP 0
3535
3636
37static int tape_read(UINT8 *reply);
37static int tape_read(pdp1_state *state, UINT8 *reply);
3838static TIMER_CALLBACK(reader_callback);
3939static TIMER_CALLBACK(puncher_callback);
4040static TIMER_CALLBACK(tyo_callback);
r9667r9668
7171    emulated:
7272    * perforated tape reader
7373    * perforated tape punch
74    * typewriter output
74    * state->typewriter output
7575    * CRT display
7676    unemulated:
7777    * card punch (pac: 43)
r9667r9668
8181*/
8282
8383/* IO status word */
84static int io_status;
8584
8685/* defines for io_status bits */
8786enum
8887{
8988   io_st_pen = 0400000,   /* light pen: light has hit the pen */
9089   io_st_ptr = 0200000,   /* perforated tape reader: reader buffer full */
91   io_st_tyo = 0100000,   /* typewriter out: device ready */
92   io_st_tyi = 0040000,   /* typewriter in: new character in buffer */
90   io_st_tyo = 0100000,   /* state->typewriter out: device ready */
91   io_st_tyi = 0040000,   /* state->typewriter in: new character in buffer */
9392   io_st_ptp = 0020000      /* perforated tape punch: device ready */
9493};
9594
96/* tape reader registers */
97typedef struct tape_reader_t
98{
99   device_image_interface *fd;   /* file descriptor of tape image */
10095
101   int motor_on;   /* 1-bit reader motor on */
10296
103   int rb;         /* 18-bit reader buffer */
104   int rcl;      /* 1-bit reader clutch */
105   int rc;         /* 2-bit reader counter */
106   int rby;      /* 1-bit reader binary mode flip-flop */
107   int rcp;      /* 1-bit reader "need a completion pulse" flip-flop */
10897
109   emu_timer *timer;   /* timer to simulate reader timing */
110} tape_reader_t;
11198
112static tape_reader_t tape_reader;
11399
114100
115/* tape puncher registers */
116typedef struct tape_puncher_t
117{
118   device_image_interface *fd;   /* file descriptor of tape image */
119
120   emu_timer *timer;   /* timer to generate completion pulses */
121} tape_puncher_t;
122
123static tape_puncher_t tape_puncher;
124
125
126/* typewriter registers */
127typedef struct typewriter_t
128{
129   device_image_interface *fd;   /* file descriptor of output image */
130
131   int tb;         /* typewriter buffer */
132
133   emu_timer *tyo_timer;/* timer to generate completion pulses */
134} typewriter_t;
135
136static typewriter_t typewriter;
137
138
139101/* crt display timer */
140static emu_timer *dpy_timer;
141102
142103/* light pen config */
143static lightpen_t lightpen;
144104
145105
146/* MIT parallel drum (mostly similar to type 23) */
147typedef struct parallel_drum_t
148{
149   device_image_interface *fd;   /* file descriptor of drum image */
150106
151   int il;         /* initial location (12-bit) */
152   int wc;         /* word counter (12-bit) */
153   int wcl;      /* word core location counter (16-bit) */
154   int rfb;      /* read field buffer (5-bit) */
155   int wfb;      /* write field buffer (5-bit) */
156
157   int dba;
158
159   emu_timer *rotation_timer;   /* timer called each time dc is 0 */
160   emu_timer *il_timer;      /* timer called each time dc is il */
161} parallel_drum_t;
162
163static parallel_drum_t parallel_drum;
164
165107#define PARALLEL_DRUM_WORD_TIME ATTOTIME_IN_NSEC(8500)
166108#define PARALLEL_DRUM_ROTATION_TIME ATTOTIME_IN_NSEC(8500*4096)
167109
r9667r9668
202144
203145MACHINE_RESET( pdp1 )
204146{
147   pdp1_state *state = machine->driver_data<pdp1_state>();
205148   int cfg;
206149
207150   cfg = input_port_read(machine, "CFG");
r9667r9668
210153   pdp1_reset_param.type_20_sbs = (cfg >> pdp1_config_type_20_sbs_bit) & pdp1_config_type_20_sbs_mask;
211154
212155   /* reset device state */
213   tape_reader.rcl = tape_reader.rc = 0;
214   io_status = io_st_tyo | io_st_ptp;
215   lightpen.active = lightpen.down = 0;
216   lightpen.x = lightpen.y = 0;
217   lightpen.radius = 10;   /* ??? */
218   pdp1_update_lightpen_state(&lightpen);
156   state->tape_reader.rcl = state->tape_reader.rc = 0;
157   state->io_status = io_st_tyo | io_st_ptp;
158   state->lightpen.active = state->lightpen.down = 0;
159   state->lightpen.x = state->lightpen.y = 0;
160   state->lightpen.radius = 10;   /* ??? */
161   pdp1_update_lightpen_state(machine, &state->lightpen);
219162}
220163
221164
222165static void pdp1_machine_stop(running_machine &machine)
223166{
167   pdp1_state *state = machine.driver_data<pdp1_state>();
224168   /* the core will take care of freeing the timers, BUT we must set the variables
225169    to NULL if we don't want to risk confusing the tape image init function */
226   tape_reader.timer = tape_puncher.timer = typewriter.tyo_timer = dpy_timer = NULL;
170   state->tape_reader.timer = state->tape_puncher.timer = state->typewriter.tyo_timer = state->dpy_timer = NULL;
227171}
228172
229173
r9667r9668
234178*/
235179MACHINE_START( pdp1 )
236180{
181   pdp1_state *state = machine->driver_data<pdp1_state>();
237182   UINT8 *dst;
238183
239184   static const unsigned char fontdata6x8[pdp1_fontdata_size] =
r9667r9668
367312
368313   machine->add_notifier(MACHINE_NOTIFY_EXIT, pdp1_machine_stop);
369314
370   tape_reader.timer = timer_alloc(machine, reader_callback, NULL);
371   tape_puncher.timer = timer_alloc(machine, puncher_callback, NULL);
372   typewriter.tyo_timer = timer_alloc(machine, tyo_callback, NULL);
373   dpy_timer = timer_alloc(machine, dpy_callback, NULL);
315   state->tape_reader.timer = timer_alloc(machine, reader_callback, NULL);
316   state->tape_puncher.timer = timer_alloc(machine, puncher_callback, NULL);
317   state->typewriter.tyo_timer = timer_alloc(machine, tyo_callback, NULL);
318   state->dpy_timer = timer_alloc(machine, dpy_callback, NULL);
374319}
375320
376321
r9667r9668
410355*/
411356DEVICE_IMAGE_LOAD( pdp1_tape )
412357{
358   pdp1_state *state = image.device().machine->driver_data<pdp1_state>();
413359   int id = image_index_in_device(image);
414360
415361   switch (id)
416362   {
417363   case 0:
418364      /* reader unit */
419      tape_reader.fd = image;
365      state->tape_reader.fd = image;
420366
421367      /* start motor */
422      tape_reader.motor_on = 1;
368      state->tape_reader.motor_on = 1;
423369
424370      /* restart reader IO when necessary */
425371      /* note that this function may be called before pdp1_init_machine, therefore
426        before tape_reader.timer is allocated.  It does not matter, as the clutch is never
372        before state->tape_reader.timer is allocated.  It does not matter, as the clutch is never
427373        down at power-up, but we must not call timer_enable with a NULL parameter! */
428      if (tape_reader.timer)
374      if (state->tape_reader.timer)
429375      {
430         if (tape_reader.motor_on && tape_reader.rcl)
376         if (state->tape_reader.motor_on && state->tape_reader.rcl)
431377         {
432378            /* delay is approximately 1/400s */
433            timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
379            timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
434380         }
435381         else
436382         {
437            timer_enable(tape_reader.timer, 0);
383            timer_enable(state->tape_reader.timer, 0);
438384         }
439385      }
440386      break;
441387
442388   case 1:
443389      /* punch unit */
444      tape_puncher.fd = image;
390      state->tape_puncher.fd = image;
445391      break;
446392   }
447393
r9667r9668
450396
451397DEVICE_IMAGE_UNLOAD( pdp1_tape )
452398{
399   pdp1_state *state = image.device().machine->driver_data<pdp1_state>();
453400   int id = image_index_in_device(image);
454401
455402   switch (id)
456403   {
457404   case 0:
458405      /* reader unit */
459      tape_reader.fd = NULL;
406      state->tape_reader.fd = NULL;
460407
461408      /* stop motor */
462      tape_reader.motor_on = 0;
409      state->tape_reader.motor_on = 0;
463410
464      if (tape_reader.timer)
465         timer_enable(tape_reader.timer, 0);
411      if (state->tape_reader.timer)
412         timer_enable(state->tape_reader.timer, 0);
466413      break;
467414
468415   case 1:
469416      /* punch unit */
470      tape_puncher.fd = NULL;
417      state->tape_puncher.fd = NULL;
471418      break;
472419   }
473420}
r9667r9668
475422/*
476423    Read a byte from perforated tape
477424*/
478static int tape_read(UINT8 *reply)
425static int tape_read(pdp1_state *state, UINT8 *reply)
479426{
480   if (tape_reader.fd && (tape_reader.fd->fread(reply, 1) == 1))
427   if (state->tape_reader.fd && (state->tape_reader.fd->fread(reply, 1) == 1))
481428      return 0;   /* unit OK */
482429   else
483430      return 1;   /* unit not ready */
r9667r9668
486433/*
487434    Write a byte to perforated tape
488435*/
489static void tape_write(UINT8 data)
436static void tape_write(pdp1_state *state, UINT8 data)
490437{
491   if (tape_puncher.fd)
492      tape_puncher.fd->fwrite(& data, 1);
438   if (state->tape_puncher.fd)
439      state->tape_puncher.fd->fwrite(& data, 1);
493440}
494441
495442/*
496443    common code for tape read commands (RPA, RPB, and read-in mode)
497444*/
498static void begin_tape_read(int binary, int nac)
445static void begin_tape_read(pdp1_state *state, int binary, int nac)
499446{
500   tape_reader.rb = 0;
501   tape_reader.rcl = 1;
502   tape_reader.rc = (binary) ? 1 : 3;
503   tape_reader.rby = (binary) ? 1 : 0;
504   tape_reader.rcp = nac;
447   state->tape_reader.rb = 0;
448   state->tape_reader.rcl = 1;
449   state->tape_reader.rc = (binary) ? 1 : 3;
450   state->tape_reader.rby = (binary) ? 1 : 0;
451   state->tape_reader.rcp = nac;
505452
506453   if (LOG_IOT_OVERLAP)
507454   {
508      if (timer_enable(tape_reader.timer, 0))
455      if (timer_enable(state->tape_reader.timer, 0))
509456         logerror("Error: overlapped perforated tape reads (Read-in mode, RPA/RPB instruction)\n");
510457   }
511458   /* set up delay if tape is advancing */
512   if (tape_reader.motor_on && tape_reader.rcl)
459   if (state->tape_reader.motor_on && state->tape_reader.rcl)
513460   {
514461      /* delay is approximately 1/400s */
515      timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
462      timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
516463   }
517464   else
518465   {
519      timer_enable(tape_reader.timer, 0);
466      timer_enable(state->tape_reader.timer, 0);
520467   }
521468}
522469
r9667r9668
525472*/
526473static TIMER_CALLBACK(reader_callback)
527474{
475   pdp1_state *state = machine->driver_data<pdp1_state>();
528476   int not_ready;
529477   UINT8 data;
530478
531   if (tape_reader.rc)
479   if (state->tape_reader.rc)
532480   {
533      not_ready = tape_read(& data);
481      not_ready = tape_read(state, & data);
534482      if (not_ready)
535483      {
536         tape_reader.motor_on = 0;   /* let us stop the motor */
484         state->tape_reader.motor_on = 0;   /* let us stop the motor */
537485      }
538486      else
539487      {
540         if ((! tape_reader.rby) || (data & 0200))
488         if ((! state->tape_reader.rby) || (data & 0200))
541489         {
542            tape_reader.rb |= (tape_reader.rby) ? (data & 077) : data;
490            state->tape_reader.rb |= (state->tape_reader.rby) ? (data & 077) : data;
543491
544            if (tape_reader.rc != 3)
492            if (state->tape_reader.rc != 3)
545493            {
546               tape_reader.rb <<= 6;
494               state->tape_reader.rb <<= 6;
547495            }
548496
549            tape_reader.rc = (tape_reader.rc+1) & 3;
497            state->tape_reader.rc = (state->tape_reader.rc+1) & 3;
550498
551            if (tape_reader.rc == 0)
499            if (state->tape_reader.rc == 0)
552500            {   /* IO complete */
553               tape_reader.rcl = 0;
554               if (tape_reader.rcp)
501               state->tape_reader.rcl = 0;
502               if (state->tape_reader.rcp)
555503               {
556                  cpu_set_reg(machine->device("maincpu"), PDP1_IO, tape_reader.rb);   /* transfer reader buffer to IO */
504                  cpu_set_reg(machine->device("maincpu"), PDP1_IO, state->tape_reader.rb);   /* transfer reader buffer to IO */
557505                  pdp1_pulse_iot_done(machine->device("maincpu"));
558506               }
559507               else
560                  io_status |= io_st_ptr;
508                  state->io_status |= io_st_ptr;
561509            }
562510         }
563511      }
564512   }
565513
566   if (tape_reader.motor_on && tape_reader.rcl)
514   if (state->tape_reader.motor_on && state->tape_reader.rcl)
567515      /* delay is approximately 1/400s */
568      timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
516      timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
569517   else
570      timer_enable(tape_reader.timer, 0);
518      timer_enable(state->tape_reader.timer, 0);
571519}
572520
573521/*
r9667r9668
575523*/
576524static TIMER_CALLBACK(puncher_callback)
577525{
526   pdp1_state *state = machine->driver_data<pdp1_state>();
578527   int nac = param;
579   io_status |= io_st_ptp;
528   state->io_status |= io_st_ptp;
580529   if (nac)
581530   {
582531      pdp1_pulse_iot_done(machine->device("maincpu"));
r9667r9668
588537*/
589538void pdp1_tape_read_binary(running_device *device)
590539{
591   begin_tape_read(1, 1);
540   pdp1_state *state = device->machine->driver_data<pdp1_state>();
541   begin_tape_read(state, 1, 1);
592542}
593543
594544/*
r9667r9668
620570 */
621571static void iot_rpa(running_device *device, int op2, int nac, int mb, int *io, int ac)
622572{
573   pdp1_state *state = device->machine->driver_data<pdp1_state>();
623574   if (LOG_IOT_EXTRA)
624575      logerror("Warning, RPA instruction not fully emulated: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
625576
626   begin_tape_read(0, nac);
577   begin_tape_read(state, 0, nac);
627578}
628579
629580/*
r9667r9668
657608 */
658609static void iot_rpb(running_device *device, int op2, int nac, int mb, int *io, int ac)
659610{
611   pdp1_state *state = device->machine->driver_data<pdp1_state>();
660612   if (LOG_IOT_EXTRA)
661613      logerror("Warning, RPB instruction not fully emulated: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
662614
663   begin_tape_read(1, nac);
615   begin_tape_read(state, 1, nac);
664616}
665617
666618/*
r9667r9668
668620*/
669621static void iot_rrb(running_device *device, int op2, int nac, int mb, int *io, int ac)
670622{
623   pdp1_state *state = device->machine->driver_data<pdp1_state>();
671624   if (LOG_IOT_EXTRA)
672625      logerror("RRB instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
673626
674   *io = tape_reader.rb;
675   io_status &= ~io_st_ptr;
627   *io = state->tape_reader.rb;
628   state->io_status &= ~io_st_ptr;
676629}
677630
678631/*
r9667r9668
691644 */
692645static void iot_ppa(running_device *device, int op2, int nac, int mb, int *io, int ac)
693646{
647   pdp1_state *state = device->machine->driver_data<pdp1_state>();
694648   if (LOG_IOT_EXTRA)
695649      logerror("PPA instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
696650
697   tape_write(*io & 0377);
698   io_status &= ~io_st_ptp;
651   tape_write(state, *io & 0377);
652   state->io_status &= ~io_st_ptp;
699653   /* delay is approximately 1/63.3 second */
700654   if (LOG_IOT_OVERLAP)
701655   {
702      if (timer_enable(tape_puncher.timer, 0))
656      if (timer_enable(state->tape_puncher.timer, 0))
703657         logerror("Error: overlapped PPA/PPB instructions: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
704658   }
705659
706   timer_adjust_oneshot(tape_puncher.timer, ATTOTIME_IN_USEC(15800), nac);
660   timer_adjust_oneshot(state->tape_puncher.timer, ATTOTIME_IN_USEC(15800), nac);
707661}
708662
709663/*
r9667r9668
719673 */
720674static void iot_ppb(running_device *device, int op2, int nac, int mb, int *io, int ac)
721675{
676   pdp1_state *state = device->machine->driver_data<pdp1_state>();
722677   if (LOG_IOT_EXTRA)
723678      logerror("PPB instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
724679
725   tape_write((*io >> 12) | 0200);
726   io_status &= ~io_st_ptp;
680   tape_write(state, (*io >> 12) | 0200);
681   state->io_status &= ~io_st_ptp;
727682   /* delay is approximately 1/63.3 second */
728683   if (LOG_IOT_OVERLAP)
729684   {
730      if (timer_enable(tape_puncher.timer, 0))
685      if (timer_enable(state->tape_puncher.timer, 0))
731686         logerror("Error: overlapped PPA/PPB instructions: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
732687   }
733   timer_adjust_oneshot(tape_puncher.timer, ATTOTIME_IN_USEC(15800), nac);
688   timer_adjust_oneshot(state->tape_puncher.timer, ATTOTIME_IN_USEC(15800), nac);
734689}
735690
736691
r9667r9668
746701*/
747702DEVICE_IMAGE_LOAD(pdp1_typewriter)
748703{
704   pdp1_state *state = image.device().machine->driver_data<pdp1_state>();
749705   /* open file */
750   typewriter.fd = &image;
706   state->typewriter.fd = &image;
751707
752   io_status |= io_st_tyo;
708   state->io_status |= io_st_tyo;
753709
754710   return IMAGE_INIT_PASS;
755711}
756712
757713DEVICE_IMAGE_UNLOAD(pdp1_typewriter)
758714{
759   typewriter.fd = NULL;
715   pdp1_state *state = image.device().machine->driver_data<pdp1_state>();
716   state->typewriter.fd = NULL;
760717}
761718
762719/*
r9667r9668
764721*/
765722static void typewriter_out(running_machine *machine, UINT8 data)
766723{
724   pdp1_state *state = machine->driver_data<pdp1_state>();
767725   if (LOG_IOT_EXTRA)
768726      logerror("typewriter output %o\n", data);
769727
770728   pdp1_typewriter_drawchar(machine, data);
771   if (typewriter.fd)
729   if (state->typewriter.fd)
772730#if 1
773      typewriter.fd->fwrite(& data, 1);
731      state->typewriter.fd->fwrite(& data, 1);
774732#else
775733   {
776734      static const char ascii_table[2][64] =
r9667r9668
812770            '*',/*Upper Case*/   '\b',/*Backspace*/   '*',            '*'/*Carriage Return*/
813771         }
814772      };
815      static int case_shift;
816773
817774      data &= 0x3f;
818775
r9667r9668
823780         //color = color_typewriter_black;
824781         {
825782            static const char black[5] = { '\033', '[', '3', '0', 'm' };
826            image_fwrite(typewriter.fd, black, sizeof(black));
783            image_fwrite(state->typewriter.fd, black, sizeof(black));
827784         }
828785         break;
829786
r9667r9668
832789         //color = color_typewriter_red;
833790         {
834791            static const char red[5] = { '\033', '[', '3', '1', 'm' };
835            image_fwrite(typewriter.fd, red, sizeof(red));
792            image_fwrite(state->typewriter.fd, red, sizeof(red));
836793         }
837794         break;
838795
839796      case 072:
840797         /* Lower case */
841         case_shift = 0;
798         state->case_shift = 0;
842799         break;
843800
844801      case 074:
845802         /* Upper case */
846         case_shift = 1;
803         state->case_shift = 1;
847804         break;
848805
849806      case 077:
850807         /* Carriage Return */
851808         {
852809            static const char line_end[2] = { '\r', '\n' };
853            image_fwrite(typewriter.fd, line_end, sizeof(line_end));
810            image_fwrite(state->typewriter.fd, line_end, sizeof(line_end));
854811         }
855812         break;
856813
r9667r9668
859816
860817         if ((data != 040) && (data != 056))   /* 040 and 056 are non-spacing characters: don't try to print right now */
861818            /* print character (lookup ASCII equivalent in table) */
862            image_fwrite(typewriter.fd, & ascii_table[case_shift][data], 1);
819            image_fwrite(state->typewriter.fd, & ascii_table[state->case_shift][data], 1);
863820
864821         break;
865822      }
r9667r9668
872829*/
873830static TIMER_CALLBACK(tyo_callback)
874831{
832   pdp1_state *state = machine->driver_data<pdp1_state>();
875833   int nac = param;
876   io_status |= io_st_tyo;
834   state->io_status |= io_st_tyo;
877835   if (nac)
878836   {
879837      pdp1_pulse_iot_done(machine->device("maincpu"));
r9667r9668
885843*/
886844static void iot_tyo(running_device *device, int op2, int nac, int mb, int *io, int ac)
887845{
846   pdp1_state *state = device->machine->driver_data<pdp1_state>();
888847   int ch, delay;
889848
890849   if (LOG_IOT_EXTRA)
r9667r9668
893852   ch = (*io) & 077;
894853
895854   typewriter_out(device->machine, ch);
896   io_status &= ~io_st_tyo;
855   state->io_status &= ~io_st_tyo;
897856
898857   /* compute completion delay (source: maintainance manual 9-12, 9-13 and 9-14) */
899858   switch (ch)
r9667r9668
915874   }
916875   if (LOG_IOT_OVERLAP)
917876   {
918      if (timer_enable(typewriter.tyo_timer, 0))
877      if (timer_enable(state->typewriter.tyo_timer, 0))
919878         logerror("Error: overlapped TYO instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
920879   }
921880
922   timer_adjust_oneshot(typewriter.tyo_timer, ATTOTIME_IN_MSEC(delay), nac);
881   timer_adjust_oneshot(state->typewriter.tyo_timer, ATTOTIME_IN_MSEC(delay), nac);
923882}
924883
925884/*
r9667r9668
938897 */
939898static void iot_tyi(running_device *device, int op2, int nac, int mb, int *io, int ac)
940899{
900   pdp1_state *state = device->machine->driver_data<pdp1_state>();
941901   if (LOG_IOT_EXTRA)
942902      logerror("Warning, TYI instruction not fully emulated: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
943903
944   *io = typewriter.tb;
945   if (! (io_status & io_st_tyi))
904   *io = state->typewriter.tb;
905   if (! (state->io_status & io_st_tyi))
946906      *io |= 0100;
947907   else
948908   {
949      io_status &= ~io_st_tyi;
909      state->io_status &= ~io_st_tyi;
950910      if (USE_SBS)
951911         cputag_set_input_line_and_vector(device->machine, "maincpu", 0, CLEAR_LINE, 0);   /* interrupt it, baby */
952912   }
r9667r9668
1003963*/
1004964static void iot_dpy(running_device *device, int op2, int nac, int mb, int *io, int ac)
1005965{
966   pdp1_state *state = device->machine->driver_data<pdp1_state>();
1006967   int x;
1007968   int y;
1008969
r9667r9668
1012973   pdp1_plot(x, y);
1013974
1014975   /* light pen 32 support */
1015   io_status &= ~io_st_pen;
976   state->io_status &= ~io_st_pen;
1016977
1017   if (lightpen.down && ((x-lightpen.x)*(x-lightpen.x)+(y-lightpen.y)*(y-lightpen.y) < lightpen.radius*lightpen.radius))
978   if (state->lightpen.down && ((x-state->lightpen.x)*(x-state->lightpen.x)+(y-state->lightpen.y)*(y-state->lightpen.y) < state->lightpen.radius*state->lightpen.radius))
1018979   {
1019      io_status |= io_st_pen;
980      state->io_status |= io_st_pen;
1020981
1021982      cpu_set_reg(device->machine->device("maincpu"), PDP1_PF3, 1);
1022983   }
r9667r9668
1028989      {
1029990         /* note that overlap detection is incomplete: it will only work if both DPY
1030991            instructions require a completion pulse */
1031         if (timer_enable(dpy_timer, 0))
992         if (timer_enable(state->dpy_timer, 0))
1032993            logerror("Error: overlapped DPY instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
1033994      }
1034      timer_adjust_oneshot(dpy_timer, ATTOTIME_IN_USEC(50), 0);
995      timer_adjust_oneshot(state->dpy_timer, ATTOTIME_IN_USEC(50), 0);
1035996   }
1036997}
1037998
r9667r9668
10411002    MIT parallel drum (variant of type 23)
10421003*/
10431004
1044static void parallel_drum_set_il(int il)
1005static void parallel_drum_set_il(pdp1_state *state, int il)
10451006{
10461007   attotime il_phase;
10471008
1048   parallel_drum.il = il;
1009   state->parallel_drum.il = il;
10491010
1050   il_phase = attotime_sub(attotime_mul(PARALLEL_DRUM_WORD_TIME, il), timer_timeelapsed(parallel_drum.rotation_timer));
1011   il_phase = attotime_sub(attotime_mul(PARALLEL_DRUM_WORD_TIME, il), timer_timeelapsed(state->parallel_drum.rotation_timer));
10511012   if (attotime_compare(il_phase, attotime_zero) < 0)
10521013      il_phase = attotime_add(il_phase, PARALLEL_DRUM_ROTATION_TIME);
1053   timer_adjust_periodic(parallel_drum.il_timer, il_phase, 0, PARALLEL_DRUM_ROTATION_TIME);
1014   timer_adjust_periodic(state->parallel_drum.il_timer, il_phase, 0, PARALLEL_DRUM_ROTATION_TIME);
10541015}
10551016
10561017#ifdef UNUSED_FUNCTION
10571018static TIMER_CALLBACK(il_timer_callback)
10581019{
1059   if (parallel_drum.dba)
1020   pdp1_state *state = machine->driver_data<pdp1_state>();
1021   if (state->parallel_drum.dba)
10601022   {
10611023      /* set break request and status bit 5 */
10621024      /* ... */
10631025   }
10641026}
10651027
1066static void parallel_drum_init(void)
1028static void parallel_drum_init(pdp1_state *state)
10671029{
1068   parallel_drum.rotation_timer = timer_alloc(machine, NULL, NULL);
1069   timer_adjust_periodic(parallel_drum.rotation_timer, PARALLEL_DRUM_ROTATION_TIME, 0, PARALLEL_DRUM_ROTATION_TIME);
1030   state->parallel_drum.rotation_timer = timer_alloc(machine, NULL, NULL);
1031   timer_adjust_periodic(state->parallel_drum.rotation_timer, PARALLEL_DRUM_ROTATION_TIME, 0, PARALLEL_DRUM_ROTATION_TIME);
10701032
1071   parallel_drum.il_timer = timer_alloc(machine, il_timer_callback, NULL);
1033   state->parallel_drum.il_timer = timer_alloc(machine, il_timer_callback, NULL);
10721034   parallel_drum_set_il(0);
10731035}
10741036#endif
r9667r9668
10781040*/
10791041DEVICE_IMAGE_LOAD(pdp1_drum)
10801042{
1043   pdp1_state *state = image.device().machine->driver_data<pdp1_state>();
10811044   /* open file */
1082   parallel_drum.fd = &image;
1045   state->parallel_drum.fd = &image;
10831046
10841047   return IMAGE_INIT_PASS;
10851048}
10861049
10871050DEVICE_IMAGE_UNLOAD(pdp1_drum)
10881051{
1089   parallel_drum.fd = NULL;
1052   pdp1_state *state = image.device().machine->driver_data<pdp1_state>();
1053   state->parallel_drum.fd = NULL;
10901054}
10911055
10921056static void iot_dia(running_device *device, int op2, int nac, int mb, int *io, int ac)
10931057{
1094   parallel_drum.wfb = ((*io) & 0370000) >> 12;
1095   parallel_drum_set_il((*io) & 0007777);
1058   pdp1_state *state = device->machine->driver_data<pdp1_state>();
1059   state->parallel_drum.wfb = ((*io) & 0370000) >> 12;
1060   parallel_drum_set_il(state, (*io) & 0007777);
10961061
1097   parallel_drum.dba = 0;   /* right? */
1062   state->parallel_drum.dba = 0;   /* right? */
10981063}
10991064
11001065static void iot_dba(running_device *device, int op2, int nac, int mb, int *io, int ac)
11011066{
1102   parallel_drum.wfb = ((*io) & 0370000) >> 12;
1103   parallel_drum_set_il((*io) & 0007777);
1067   pdp1_state *state = device->machine->driver_data<pdp1_state>();
1068   state->parallel_drum.wfb = ((*io) & 0370000) >> 12;
1069   parallel_drum_set_il(state, (*io) & 0007777);
11041070
1105   parallel_drum.dba = 1;
1071   state->parallel_drum.dba = 1;
11061072}
11071073
11081074/*
11091075    Read a word from drum
11101076*/
1111static UINT32 drum_read(int field, int position)
1077static UINT32 drum_read(pdp1_state *state, int field, int position)
11121078{
11131079   int offset = (field*4096+position)*3;
11141080   UINT8 buf[3];
11151081
1116   if (parallel_drum.fd && (!parallel_drum.fd->fseek(offset, SEEK_SET)) && (parallel_drum.fd->fread( buf, 3) == 3))
1082   if (state->parallel_drum.fd && (!state->parallel_drum.fd->fseek(offset, SEEK_SET)) && (state->parallel_drum.fd->fread( buf, 3) == 3))
11171083      return ((buf[0] << 16) | (buf[1] << 8) | buf[2]) & 0777777;
11181084
11191085   return 0;
r9667r9668
11221088/*
11231089    Write a word to drum
11241090*/
1125static void drum_write(int field, int position, UINT32 data)
1091static void drum_write(pdp1_state *state, int field, int position, UINT32 data)
11261092{
11271093   int offset = (field*4096+position)*3;
11281094   UINT8 buf[3];
11291095
1130   if (parallel_drum.fd)
1096   if (state->parallel_drum.fd)
11311097   {
11321098      buf[0] = data >> 16;
11331099      buf[1] = data >> 8;
11341100      buf[2] = data;
11351101
1136      parallel_drum.fd->fseek(offset, SEEK_SET);
1137      parallel_drum.fd->fwrite( buf, 3);
1102      state->parallel_drum.fd->fseek(offset, SEEK_SET);
1103      state->parallel_drum.fd->fwrite( buf, 3);
11381104   }
11391105}
11401106
11411107static void iot_dcc(running_device *device, int op2, int nac, int mb, int *io, int ac)
11421108{
1109   pdp1_state *state = device->machine->driver_data<pdp1_state>();
11431110   attotime delay;
11441111   int dc;
11451112
1146   parallel_drum.rfb = ((*io) & 0370000) >> 12;
1147   parallel_drum.wc = - ((*io) & 0007777);
1113   state->parallel_drum.rfb = ((*io) & 0370000) >> 12;
1114   state->parallel_drum.wc = - ((*io) & 0007777);
11481115
1149   parallel_drum.wcl = ac & 0177777/*0007777???*/;
1116   state->parallel_drum.wcl = ac & 0177777/*0007777???*/;
11501117
1151   parallel_drum.dba = 0;   /* right? */
1118   state->parallel_drum.dba = 0;   /* right? */
11521119   /* clear status bit 5... */
11531120
11541121   /* do transfer */
1155   delay = timer_timeleft(parallel_drum.il_timer);
1156   dc = parallel_drum.il;
1122   delay = timer_timeleft(state->parallel_drum.il_timer);
1123   dc = state->parallel_drum.il;
11571124   do
11581125   {
1159      if ((parallel_drum.wfb >= 1) && (parallel_drum.wfb <= 22))
1126      if ((state->parallel_drum.wfb >= 1) && (state->parallel_drum.wfb <= 22))
11601127      {
1161         drum_write(parallel_drum.wfb-1, dc, (signed)cputag_get_address_space(device->machine,"maincpu", ADDRESS_SPACE_PROGRAM)->read_dword(parallel_drum.wcl<<2));
1128         drum_write(state, state->parallel_drum.wfb-1, dc, (signed)cputag_get_address_space(device->machine,"maincpu", ADDRESS_SPACE_PROGRAM)->read_dword(state->parallel_drum.wcl<<2));
11621129      }
11631130
1164      if ((parallel_drum.rfb >= 1) && (parallel_drum.rfb <= 22))
1131      if ((state->parallel_drum.rfb >= 1) && (state->parallel_drum.rfb <= 22))
11651132      {
1166         cputag_get_address_space(device->machine,"maincpu", ADDRESS_SPACE_PROGRAM)->write_dword(parallel_drum.wcl<<2, drum_read(parallel_drum.rfb-1, dc));
1133         cputag_get_address_space(device->machine,"maincpu", ADDRESS_SPACE_PROGRAM)->write_dword(state->parallel_drum.wcl<<2, drum_read(state, state->parallel_drum.rfb-1, dc));
11671134      }
11681135
1169      parallel_drum.wc = (parallel_drum.wc+1) & 07777;
1170      parallel_drum.wcl = (parallel_drum.wcl+1) & 0177777/*0007777???*/;
1136      state->parallel_drum.wc = (state->parallel_drum.wc+1) & 07777;
1137      state->parallel_drum.wcl = (state->parallel_drum.wcl+1) & 0177777/*0007777???*/;
11711138      dc = (dc+1) & 07777;
1172      if (parallel_drum.wc)
1139      if (state->parallel_drum.wc)
11731140         delay = attotime_add(delay, PARALLEL_DRUM_WORD_TIME);
1174   } while (parallel_drum.wc);
1141   } while (state->parallel_drum.wc);
11751142   cpu_adjust_icount(device->machine->device("maincpu"),-device->machine->device<cpu_device>("maincpu")->attotime_to_cycles(delay));
11761143   /* if no error, skip */
11771144   cpu_set_reg(device->machine->device("maincpu"), PDP1_PC, cpu_get_reg(device->machine->device("maincpu"), PDP1_PC)+1);
r9667r9668
11791146
11801147static void iot_dra(running_device *device, int op2, int nac, int mb, int *io, int ac)
11811148{
1149   pdp1_state *state = device->machine->driver_data<pdp1_state>();
11821150   (*io) = attotime_mul(
1183      timer_timeelapsed(parallel_drum.rotation_timer),
1151      timer_timeelapsed(state->parallel_drum.rotation_timer),
11841152      ATTOSECONDS_PER_SECOND / (attotime_to_attoseconds(PARALLEL_DRUM_WORD_TIME))).seconds & 0007777;
11851153
11861154   /* set parity error and timing error... */
r9667r9668
12401208*/
12411209static void iot_cks(running_device *device, int op2, int nac, int mb, int *io, int ac)
12421210{
1211   pdp1_state *state = device->machine->driver_data<pdp1_state>();
12431212   if (LOG_IOT_EXTRA)
12441213      logerror("CKS instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine));
12451214
1246   *io = io_status;
1215   *io = state->io_status;
12471216}
12481217
12491218
r9667r9668
12541223*/
12551224void pdp1_io_sc_callback(running_device *device)
12561225{
1257   tape_reader.rcl = tape_reader.rc = 0;
1258   if (tape_reader.timer)
1259      timer_enable(tape_reader.timer, 0);
1226   pdp1_state *state = device->machine->driver_data<pdp1_state>();
1227   state->tape_reader.rcl = state->tape_reader.rc = 0;
1228   if (state->tape_reader.timer)
1229      timer_enable(state->tape_reader.timer, 0);
12601230
1261   if (tape_puncher.timer)
1262      timer_enable(tape_puncher.timer, 0);
1231   if (state->tape_puncher.timer)
1232      timer_enable(state->tape_puncher.timer, 0);
12631233
1264   if (typewriter.tyo_timer)
1265      timer_enable(typewriter.tyo_timer, 0);
1234   if (state->typewriter.tyo_timer)
1235      timer_enable(state->typewriter.tyo_timer, 0);
12661236
1267   if (dpy_timer)
1268      timer_enable(dpy_timer, 0);
1237   if (state->dpy_timer)
1238      timer_enable(state->dpy_timer, 0);
12691239
1270   io_status = io_st_tyo | io_st_ptp;
1240   state->io_status = io_st_tyo | io_st_ptp;
12711241}
12721242
12731243
r9667r9668
12761246*/
12771247static void pdp1_keyboard(running_machine *machine)
12781248{
1249   pdp1_state *state = machine->driver_data<pdp1_state>();
12791250   int i;
12801251   int j;
12811252
12821253   int typewriter_keys[4];
1283   static int old_typewriter_keys[4];
12841254
12851255   int typewriter_transitions;
12861256   static const char *const twrnames[] = { "TWR0", "TWR1", "TWR2", "TWR3" };
r9667r9668
12931263
12941264   for (i=0; i<4; i++)
12951265   {
1296      typewriter_transitions = typewriter_keys[i] & (~ old_typewriter_keys[i]);
1266      typewriter_transitions = typewriter_keys[i] & (~ state->old_typewriter_keys[i]);
12971267      if (typewriter_transitions)
12981268      {
12991269         for (j=0; (((typewriter_transitions >> j) & 1) == 0) /*&& (j<16)*/; j++)
13001270            ;
1301         typewriter.tb = (i << 4) + j;
1302         io_status |= io_st_tyi;
1271         state->typewriter.tb = (i << 4) + j;
1272         state->io_status |= io_st_tyi;
13031273         #if USE_SBS
13041274            cputag_set_input_line_and_vector(machine, "maincpu", 0, ASSERT_LINE, 0);   /* interrupt it, baby */
13051275         #endif
13061276         cpu_set_reg(machine->device("maincpu"), PDP1_PF1, 1);
1307         pdp1_typewriter_drawchar(machine, typewriter.tb);   /* we want to echo input */
1277         pdp1_typewriter_drawchar(machine, state->typewriter.tb);   /* we want to echo input */
13081278         break;
13091279      }
13101280   }
13111281
13121282   for (i=0; i<4; i++)
1313      old_typewriter_keys[i] = typewriter_keys[i];
1283      state->old_typewriter_keys[i] = typewriter_keys[i];
13141284}
13151285
13161286static void pdp1_lightpen(running_machine *machine)
13171287{
1288   pdp1_state *state = machine->driver_data<pdp1_state>();
13181289   int x_delta, y_delta;
13191290   int current_state;
1320   static int previous_state;
13211291
1322   lightpen.active = (input_port_read(machine, "CFG") >> pdp1_config_lightpen_bit) & pdp1_config_lightpen_mask;
1292   state->lightpen.active = (input_port_read(machine, "CFG") >> pdp1_config_lightpen_bit) & pdp1_config_lightpen_mask;
13231293
13241294   current_state = input_port_read(machine, "LIGHTPEN");
13251295
13261296   /* update pen down state */
1327   lightpen.down = lightpen.active && (current_state & pdp1_lightpen_down);
1297   state->lightpen.down = state->lightpen.active && (current_state & pdp1_lightpen_down);
13281298
13291299   /* update size of pen tip hole */
1330   if ((current_state & ~previous_state) & pdp1_lightpen_smaller)
1300   if ((current_state & ~state->old_lightpen) & pdp1_lightpen_smaller)
13311301   {
1332      lightpen.radius --;
1333      if (lightpen.radius < 0)
1334         lightpen.radius = 0;
1302      state->lightpen.radius --;
1303      if (state->lightpen.radius < 0)
1304         state->lightpen.radius = 0;
13351305   }
1336   if ((current_state & ~previous_state) & pdp1_lightpen_larger)
1306   if ((current_state & ~state->old_lightpen) & pdp1_lightpen_larger)
13371307   {
1338      lightpen.radius ++;
1339      if (lightpen.radius > 32)
1340         lightpen.radius = 32;
1308      state->lightpen.radius ++;
1309      if (state->lightpen.radius > 32)
1310         state->lightpen.radius = 32;
13411311   }
13421312
1343   previous_state = current_state;
1313   state->old_lightpen = current_state;
13441314
13451315   /* update pen position */
13461316   x_delta = input_port_read(machine, "LIGHTX");
r9667r9668
13511321   if (y_delta >= 0x80)
13521322      y_delta -= 256;
13531323
1354   lightpen.x += x_delta;
1355   lightpen.y += y_delta;
1324   state->lightpen.x += x_delta;
1325   state->lightpen.y += y_delta;
13561326
1357   if (lightpen.x < 0)
1358      lightpen.x = 0;
1359   if (lightpen.x > 1023)
1360      lightpen.x = 1023;
1361   if (lightpen.y < 0)
1362      lightpen.y = 0;
1363   if (lightpen.y > 1023)
1364      lightpen.y = 1023;
1327   if (state->lightpen.x < 0)
1328      state->lightpen.x = 0;
1329   if (state->lightpen.x > 1023)
1330      state->lightpen.x = 1023;
1331   if (state->lightpen.y < 0)
1332      state->lightpen.y = 0;
1333   if (state->lightpen.y > 1023)
1334      state->lightpen.y = 1023;
13651335
1366   pdp1_update_lightpen_state(&lightpen);
1336   pdp1_update_lightpen_state(machine, &state->lightpen);
13671337}
13681338
13691339/*
r9667r9668
13711341*/
13721342INTERRUPT_GEN( pdp1_interrupt )
13731343{
1344   pdp1_state *state = device->machine->driver_data<pdp1_state>();
13741345   running_machine *machine = device->machine;
13751346   int control_keys;
13761347   int tw_keys;
13771348   int ta_keys;
13781349
1379   static int old_control_keys;
1380   static int old_tw_keys;
1381   static int old_ta_keys;
1382
13831350   int control_transitions;
13841351   int tw_transitions;
13851352   int ta_transitions;
r9667r9668
13931360   if (control_keys & pdp1_control)
13941361   {
13951362      /* compute transitions */
1396      control_transitions = control_keys & (~ old_control_keys);
1363      control_transitions = control_keys & (~ state->old_control_keys);
13971364
13981365      if (control_transitions & pdp1_extend)
13991366      {
r9667r9668
14761443      }
14771444
14781445      /* remember new state of control keys */
1479      old_control_keys = control_keys;
1446      state->old_control_keys = control_keys;
14801447
14811448
14821449      /* handle test word keys */
14831450      tw_keys = (input_port_read(machine, "TWDMSB") << 16) | input_port_read(machine, "TWDLSB");
14841451
14851452      /* compute transitions */
1486      tw_transitions = tw_keys & (~ old_tw_keys);
1453      tw_transitions = tw_keys & (~ state->old_tw_keys);
14871454
14881455      if (tw_transitions)
14891456         cpu_set_reg(device, PDP1_TW, cpu_get_reg(device, PDP1_TW) ^ tw_transitions);
14901457
14911458      /* remember new state of test word keys */
1492      old_tw_keys = tw_keys;
1459      state->old_tw_keys = tw_keys;
14931460
14941461
14951462      /* handle address keys */
14961463      ta_keys = input_port_read(machine, "TSTADD");
14971464
14981465      /* compute transitions */
1499      ta_transitions = ta_keys & (~ old_ta_keys);
1466      ta_transitions = ta_keys & (~ state->old_ta_keys);
15001467
15011468      if (ta_transitions)
15021469         cpu_set_reg(device, PDP1_TA, cpu_get_reg(device, PDP1_TA) ^ ta_transitions);
15031470
15041471      /* remember new state of test word keys */
1505      old_ta_keys = ta_keys;
1472      state->old_ta_keys = ta_keys;
15061473
15071474   }
15081475   else
15091476   {
1510      old_control_keys = 0;
1511      old_tw_keys = 0;
1512      old_ta_keys = 0;
1477      state->old_control_keys = 0;
1478      state->old_tw_keys = 0;
1479      state->old_ta_keys = 0;
15131480
15141481      pdp1_keyboard(machine);
15151482   }
src/mess/machine/tx0.c
r9667r9668
1616static TIMER_CALLBACK(dis_callback);
1717
1818
19/* tape reader registers */
20typedef struct tape_reader_t
21{
22   device_image_interface *fd;   /* file descriptor of tape image */
2319
24   int motor_on;   /* 1-bit reader motor on */
2520
26   int rcl;      /* 1-bit reader clutch */
27   int rc;         /* 2-bit reader counter */
2821
29   emu_timer *timer;   /* timer to simulate reader timing */
30} tape_reader_t;
3122
32static tape_reader_t tape_reader;
3323
3424
35/* tape puncher registers */
36typedef struct tape_puncher_t
37{
38   device_image_interface *fd;   /* file descriptor of tape image */
39
40   emu_timer *timer;   /* timer to generate completion pulses */
41} tape_puncher_t;
42
43static tape_puncher_t tape_puncher;
44
45
46/* typewriter registers */
47typedef struct typewriter_t
48{
49   device_image_interface *fd;   /* file descriptor of output image */
50
51   emu_timer *prt_timer;/* timer to generate completion pulses */
52} typewriter_t;
53
54static typewriter_t typewriter;
55
56
5725/* crt display timer */
58static emu_timer *dis_timer;
5926
6027
61enum state_t
62{
63   MTS_UNSELECTED,
64   MTS_SELECTING,
65   MTS_SELECTED,
66   MTS_UNSELECTING
67};
68enum backspace_state_t
69{
70   MTBSS_STATE0,
71   MTBSS_STATE1,
72   MTBSS_STATE2,
73   MTBSS_STATE3,
74   MTBSS_STATE4,
75   MTBSS_STATE5,
76   MTBSS_STATE6
77};
78enum state_2_t
79{
80   MTRDS_STATE0,
81   MTRDS_STATE1,
82   MTRDS_STATE2,
83   MTRDS_STATE3,
84   MTRDS_STATE4,
85   MTRDS_STATE5,
86   MTRDS_STATE6
87};
88enum state_3_t
89{
90   MTWTS_STATE0,
91   MTWTS_STATE1,
92   MTWTS_STATE2,
93   MTWTS_STATE3
94};
9528
96enum irg_pos_t
97{
98   MTIRGP_START,
99   MTIRGP_ENDMINUS1,
100   MTIRGP_END
101};
102/* magnetic tape unit registers */
103typedef struct magtape_t
104{
105   device_image_interface *img;      /* image descriptor */
106
107   state_t state;
108
109   int command;
110   int binary_flag;
111
112   union
113   {
114      backspace_state_t backspace_state;
115      struct
116      {
117         state_2_t state;
118         int space_flag;
119      } read;
120      struct
121      {
122         state_3_t state;
123         int counter;
124      } write;
125   } u;
126
127   int sel_pending;
128   int cpy_pending;
129
130   irg_pos_t irg_pos;         /* position relative to inter-record gap */
131
132   int long_parity;
133
134   emu_timer *timer;   /* timer to simulate reader timing */
135} magtape_t;
136
137static magtape_t magtape;
138
13929enum
14030{
14131   PF_RWC = 040,
r9667r9668
14737
14838MACHINE_RESET( tx0 )
14939{
40   tx0_state *state = machine->driver_data<tx0_state>();
15041   /* reset device state */
151   tape_reader.rcl = tape_reader.rc = 0;
42   state->tape_reader.rcl = state->tape_reader.rc = 0;
15243}
15344
15445
15546static void tx0_machine_stop(running_machine &machine)
15647{
48   tx0_state *state = machine.driver_data<tx0_state>();
15749   /* the core will take care of freeing the timers, BUT we must set the variables
15850    to NULL if we don't want to risk confusing the tape image init function */
159   tape_reader.timer = tape_puncher.timer = typewriter.prt_timer = dis_timer = NULL;
51   state->tape_reader.timer = state->tape_puncher.timer = state->typewriter.prt_timer = state->dis_timer = NULL;
16052}
16153
16254
16355MACHINE_START( tx0 )
16456{
165   tape_reader.timer = timer_alloc(machine, reader_callback, NULL);
166   tape_puncher.timer = timer_alloc(machine, puncher_callback, NULL);
167   typewriter.prt_timer = timer_alloc(machine, prt_callback, NULL);
168   dis_timer = timer_alloc(machine, dis_callback, NULL);
57   tx0_state *state = machine->driver_data<tx0_state>();
58   state->tape_reader.timer = timer_alloc(machine, reader_callback, NULL);
59   state->tape_puncher.timer = timer_alloc(machine, puncher_callback, NULL);
60   state->typewriter.prt_timer = timer_alloc(machine, prt_callback, NULL);
61   state->dis_timer = timer_alloc(machine, dis_callback, NULL);
16962
17063   machine->add_notifier(MACHINE_NOTIFY_EXIT, tx0_machine_stop);
17164}
r9667r9668
20598*/
20699DEVICE_IMAGE_LOAD( tx0_tape )
207100{
101   tx0_state *state = image.device().machine->driver_data<tx0_state>();
208102   int id = image_index_in_device(image);
209103
210104   switch (id)
211105   {
212106   case 0:
213107      /* reader unit */
214      tape_reader.fd = image;
108      state->tape_reader.fd = image;
215109
216110      /* start motor */
217      tape_reader.motor_on = 1;
111      state->tape_reader.motor_on = 1;
218112
219113      /* restart reader IO when necessary */
220114      /* note that this function may be called before tx0_init_machine, therefore
221        before tape_reader.timer is allocated.  It does not matter, as the clutch is never
115        before state->tape_reader.timer is allocated.  It does not matter, as the clutch is never
222116        down at power-up, but we must not call timer_enable with a NULL parameter! */
223      if (tape_reader.timer)
117      if (state->tape_reader.timer)
224118      {
225         if (tape_reader.motor_on && tape_reader.rcl)
119         if (state->tape_reader.motor_on && state->tape_reader.rcl)
226120         {
227121            /* delay is approximately 1/400s */
228            timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
122            timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
229123         }
230124         else
231125         {
232            timer_enable(tape_reader.timer, 0);
126            timer_enable(state->tape_reader.timer, 0);
233127         }
234128      }
235129      break;
236130
237131   case 1:
238132      /* punch unit */
239      tape_puncher.fd = image;
133      state->tape_puncher.fd = image;
240134      break;
241135   }
242136
r9667r9668
245139
246140DEVICE_IMAGE_UNLOAD( tx0_tape )
247141{
142   tx0_state *state = image.device().machine->driver_data<tx0_state>();
248143   int id = image_index_in_device(image);
249144
250145   switch (id)
251146   {
252147   case 0:
253148      /* reader unit */
254      tape_reader.fd = NULL;
149      state->tape_reader.fd = NULL;
255150
256151      /* stop motor */
257      tape_reader.motor_on = 0;
152      state->tape_reader.motor_on = 0;
258153
259      if (tape_reader.timer)
260         timer_enable(tape_reader.timer, 0);
154      if (state->tape_reader.timer)
155         timer_enable(state->tape_reader.timer, 0);
261156      break;
262157
263158   case 1:
264159      /* punch unit */
265      tape_puncher.fd = NULL;
160      state->tape_puncher.fd = NULL;
266161      break;
267162   }
268163}
r9667r9668
270165/*
271166    Read a byte from perforated tape
272167*/
273static int tape_read(UINT8 *reply)
168static int tape_read(tx0_state *state, UINT8 *reply)
274169{
275   if (tape_reader.fd && (tape_reader.fd->fread(reply, 1) == 1))
170   if (state->tape_reader.fd && (state->tape_reader.fd->fread(reply, 1) == 1))
276171      return 0;   /* unit OK */
277172   else
278173      return 1;   /* unit not ready */
r9667r9668
281176/*
282177    Write a byte to perforated tape
283178*/
284static void tape_write(UINT8 data)
179static void tape_write(tx0_state *state, UINT8 data)
285180{
286   if (tape_puncher.fd)
287      tape_puncher.fd->fwrite(& data, 1);
181   if (state->tape_puncher.fd)
182      state->tape_puncher.fd->fwrite(& data, 1);
288183}
289184
290185/*
291186    common code for tape read commands (R1C, R3C, and read-in mode)
292187*/
293static void begin_tape_read(int binary)
188static void begin_tape_read(tx0_state *state, int binary)
294189{
295   tape_reader.rcl = 1;
296   tape_reader.rc = (binary) ? 1 : 3;
190   state->tape_reader.rcl = 1;
191   state->tape_reader.rc = (binary) ? 1 : 3;
297192
298193   /* set up delay if tape is advancing */
299   if (tape_reader.motor_on && tape_reader.rcl)
194   if (state->tape_reader.motor_on && state->tape_reader.rcl)
300195   {
301196      /* delay is approximately 1/400s */
302      timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
197      timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
303198   }
304199   else
305200   {
306      timer_enable(tape_reader.timer, 0);
201      timer_enable(state->tape_reader.timer, 0);
307202   }
308203}
309204
r9667r9668
313208*/
314209static TIMER_CALLBACK(reader_callback)
315210{
211   tx0_state *state = machine->driver_data<tx0_state>();
316212   int not_ready;
317213   UINT8 data;
318214   int ac;
319215
320   if (tape_reader.rc)
216   if (state->tape_reader.rc)
321217   {
322      not_ready = tape_read(& data);
218      not_ready = tape_read(state, & data);
323219      if (not_ready)
324220      {
325         tape_reader.motor_on = 0;   /* let us stop the motor */
221         state->tape_reader.motor_on = 0;   /* let us stop the motor */
326222      }
327223      else
328224      {
r9667r9668
337233            /* write modified AC */
338234            cpu_set_reg(machine->device("maincpu"), TX0_AC, ac);
339235
340            tape_reader.rc = (tape_reader.rc+1) & 3;
236            state->tape_reader.rc = (state->tape_reader.rc+1) & 3;
341237
342            if (tape_reader.rc == 0)
238            if (state->tape_reader.rc == 0)
343239            {   /* IO complete */
344               tape_reader.rcl = 0;
240               state->tape_reader.rcl = 0;
345241               cpu_set_reg(machine->device("maincpu"), TX0_IO_COMPLETE, (UINT64)0);
346242            }
347243         }
348244      }
349245   }
350246
351   if (tape_reader.motor_on && tape_reader.rcl)
247   if (state->tape_reader.motor_on && state->tape_reader.rcl)
352248      /* delay is approximately 1/400s */
353      timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
249      timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0);
354250   else
355      timer_enable(tape_reader.timer, 0);
251      timer_enable(state->tape_reader.timer, 0);
356252}
357253
358254/*
r9667r9668
368264*/
369265void tx0_io_r1l(running_device *device)
370266{
371   begin_tape_read(0);
267   tx0_state *state = device->machine->driver_data<tx0_state>();
268   begin_tape_read(state, 0);
372269}
373270
374271/*
r9667r9668
376273*/
377274void tx0_io_r3l(running_device *device)
378275{
379   begin_tape_read(1);
276   tx0_state *state = device->machine->driver_data<tx0_state>();
277   begin_tape_read(state, 1);
380278}
381279
382280/*
r9667r9668
384282*/
385283void tx0_io_p6h(running_device *device)
386284{
285   tx0_state *state = device->machine->driver_data<tx0_state>();
387286   int ac;
388287
389288   /* read current AC */
390289   ac = cpu_get_reg(device, TX0_AC);
391290   /* shuffle and punch 6-bit word */
392   tape_write(((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5));
291   tape_write(state, ((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5));
393292
394   timer_adjust_oneshot(tape_puncher.timer, ATTOTIME_IN_USEC(15800), 0);
293   timer_adjust_oneshot(state->tape_puncher.timer, ATTOTIME_IN_USEC(15800), 0);
395294}
396295
397296/*
r9667r9668
399298*/
400299void tx0_io_p7h(running_device *device)
401300{
301   tx0_state *state = device->machine->driver_data<tx0_state>();
402302   int ac;
403303
404304   /* read current AC */
405305   ac = cpu_get_reg(device, TX0_AC);
406306   /* shuffle and punch 6-bit word */
407   tape_write(((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5) | 0100);
307   tape_write(state, ((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5) | 0100);
408308
409   timer_adjust_oneshot(tape_puncher.timer, ATTOTIME_IN_USEC(15800), 0);
309   timer_adjust_oneshot(state->tape_puncher.timer, ATTOTIME_IN_USEC(15800), 0);
410310}
411311
412312
r9667r9668
422322*/
423323DEVICE_IMAGE_LOAD(tx0_typewriter)
424324{
325   tx0_state *state = image.device().machine->driver_data<tx0_state>();
425326   /* open file */
426   typewriter.fd = &image;
327   state->typewriter.fd = &image;
427328
428329   return IMAGE_INIT_PASS;
429330}
430331
431332DEVICE_IMAGE_UNLOAD(tx0_typewriter)
432333{
433   typewriter.fd = NULL;
334   tx0_state *state = image.device().machine->driver_data<tx0_state>();
335   state->typewriter.fd = NULL;
434336}
435337
436338/*
r9667r9668
438340*/
439341static void typewriter_out(running_machine *machine, UINT8 data)
440342{
343   tx0_state *state = machine->driver_data<tx0_state>();
441344   tx0_typewriter_drawchar(machine, data);
442   if (typewriter.fd)
443      typewriter.fd->fwrite(& data, 1);
345   if (state->typewriter.fd)
346      state->typewriter.fd->fwrite(& data, 1);
444347}
445348
446349/*
r9667r9668
456359*/
457360void tx0_io_prt(running_device *device)
458361{
362   tx0_state *state = device->machine->driver_data<tx0_state>();
459363   int ac;
460364   int ch;
461365
r9667r9668
465369   ch = ((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5);
466370   typewriter_out(device->machine, ch);
467371
468   timer_adjust_oneshot(typewriter.prt_timer, ATTOTIME_IN_MSEC(100), 0);
372   timer_adjust_oneshot(state->typewriter.prt_timer, ATTOTIME_IN_MSEC(100), 0);
469373}
470374
471375
r9667r9668
482386*/
483387void tx0_io_dis(running_device *device)
484388{
389   tx0_state *state = device->machine->driver_data<tx0_state>();
485390   int ac;
486391   int x;
487392   int y;
r9667r9668
491396   y = ac & 0777;
492397   tx0_plot(x, y);
493398
494   timer_adjust_oneshot(dis_timer, ATTOTIME_IN_USEC(50), 0);
399   timer_adjust_oneshot(state->dis_timer, ATTOTIME_IN_USEC(50), 0);
495400}
496401
497402
r9667r9668
505410
506411*/
507412
508static void schedule_select(void)
413static void schedule_select(tx0_state *state)
509414{
510415   attotime delay = attotime_zero;
511416
512   switch (magtape.command)
417   switch (state->magtape.command)
513418   {
514419   case 0:   /* backspace */
515420      delay = ATTOTIME_IN_USEC(4600);
r9667r9668
524429      delay = ATTOTIME_IN_USEC(4600);
525430      break;
526431   }
527   timer_adjust_oneshot(magtape.timer, delay, 0);
432   timer_adjust_oneshot(state->magtape.timer, delay, 0);
528433}
529434
530static void schedule_unselect(void)
435static void schedule_unselect(tx0_state *state)
531436{
532437   attotime delay = attotime_zero;
533438
534   switch (magtape.command)
439   switch (state->magtape.command)
535440   {
536441   case 0:   /* backspace */
537442      delay = ATTOTIME_IN_USEC(5750);
r9667r9668
546451      delay = ATTOTIME_IN_USEC(5750);
547452      break;
548453   }
549   timer_adjust_oneshot(magtape.timer, delay, 0);
454   timer_adjust_oneshot(state->magtape.timer, delay, 0);
550455}
551456
552457DEVICE_START( tx0_magtape )
553458{
554   magtape.img = dynamic_cast<device_image_interface *>(device);
459   tx0_state *state = device->machine->driver_data<tx0_state>();
460   state->magtape.img = dynamic_cast<device_image_interface *>(device);
555461}
556462
557463/*
r9667r9668
559465*/
560466DEVICE_IMAGE_LOAD( tx0_magtape )
561467{
562   magtape.img = &image;
468   tx0_state *state = image.device().machine->driver_data<tx0_state>();
469   state->magtape.img = &image;
563470
564   magtape.irg_pos = MTIRGP_END;
471   state->magtape.irg_pos = MTIRGP_END;
565472
566473   /* restart IO when necessary */
567474   /* note that this function may be called before tx0_init_machine, therefore
568    before magtape.timer is allocated.  We must not call timer_enable with a
475    before state->magtape.timer is allocated.  We must not call timer_enable with a
569476    NULL parameter! */
570   if (magtape.timer)
477   if (state->magtape.timer)
571478   {
572      if (magtape.state == MTS_SELECTING)
573         schedule_select();
479      if (state->magtape.state == MTS_SELECTING)
480         schedule_select(state);
574481   }
575482
576483   return IMAGE_INIT_PASS;
r9667r9668
578485
579486DEVICE_IMAGE_UNLOAD( tx0_magtape )
580487{
581   magtape.img = NULL;
488   tx0_state *state = image.device().machine->driver_data<tx0_state>();
489   state->magtape.img = NULL;
582490
583   if (magtape.timer)
491   if (state->magtape.timer)
584492   {
585      if (magtape.state == MTS_SELECTING)
493      if (state->magtape.state == MTS_SELECTING)
586494         /* I/O has not actually started, we can cancel the selection */
587         timer_enable(tape_reader.timer, 0);
588      if ((magtape.state == MTS_SELECTED) || ((magtape.state == MTS_SELECTING) && (magtape.command == 2)))
495         timer_enable(state->tape_reader.timer, 0);
496      if ((state->magtape.state == MTS_SELECTED) || ((state->magtape.state == MTS_SELECTING) && (state->magtape.command == 2)))
589497      {   /* unit has become unavailable */
590         magtape.state = MTS_UNSELECTING;
498         state->magtape.state = MTS_UNSELECTING;
591499         cpu_set_reg(image.device().machine->device("maincpu"), TX0_PF, cpu_get_reg(image.device().machine->device("maincpu"), TX0_PF) | PF_RWC);
592         schedule_unselect();
500         schedule_unselect(state);
593501      }
594502   }
595503}
596504
597505static void magtape_callback(running_device *device)
598506{
507   tx0_state *state = device->machine->driver_data<tx0_state>();
599508   UINT8 buf = 0;
600509   int lr;
601510
602   switch (magtape.state)
511   switch (state->magtape.state)
603512   {
604513   case MTS_UNSELECTING:
605      magtape.state = MTS_UNSELECTED;
514      state->magtape.state = MTS_UNSELECTED;
606515
607516   case MTS_UNSELECTED:
608      if (magtape.sel_pending)
517      if (state->magtape.sel_pending)
609518      {
610519         int mar;
611520
r9667r9668
618527         }
619528         else
620529         {
621            magtape.state = MTS_SELECTING;
530            state->magtape.state = MTS_SELECTING;
622531
623            magtape.command = (mar & 014 >> 2);
532            state->magtape.command = (mar & 014 >> 2);
624533
625            magtape.binary_flag = (mar & 020 >> 4);
534            state->magtape.binary_flag = (mar & 020 >> 4);
626535
627            if (magtape.img)
628               schedule_select();
536            if (state->magtape.img)
537               schedule_select(state);
629538         }
630539
631         magtape.sel_pending = FALSE;
540         state->magtape.sel_pending = FALSE;
632541         cpu_set_reg(device, TX0_IO_COMPLETE, (UINT64)0);
633542      }
634543      break;
635544
636545   case MTS_SELECTING:
637      magtape.state = MTS_SELECTED;
638      switch (magtape.command)
546      state->magtape.state = MTS_SELECTED;
547      switch (state->magtape.command)
639548      {
640549      case 0:   /* backspace */
641         magtape.long_parity = 0177;
642         magtape.u.backspace_state = MTBSS_STATE0;
550         state->magtape.long_parity = 0177;
551         state->magtape.u.backspace_state = MTBSS_STATE0;
643552         break;
644553      case 1:   /* read */
645         magtape.long_parity = 0177;
646         magtape.u.read.state = MTRDS_STATE0;
554         state->magtape.long_parity = 0177;
555         state->magtape.u.read.state = MTRDS_STATE0;
647556         break;
648557      case 2:   /* rewind */
649558         break;
650559      case 3:   /* write */
651         magtape.long_parity = 0177;
652         magtape.u.write.state = MTWTS_STATE0;
653         switch (magtape.irg_pos)
560         state->magtape.long_parity = 0177;
561         state->magtape.u.write.state = MTWTS_STATE0;
562         switch (state->magtape.irg_pos)
654563         {
655564         case MTIRGP_START:
656            magtape.u.write.counter = 150;
565            state->magtape.u.write.counter = 150;
657566            break;
658567         case MTIRGP_ENDMINUS1:
659            magtape.u.write.counter = 1;
568            state->magtape.u.write.counter = 1;
660569            break;
661570         case MTIRGP_END:
662            magtape.u.write.counter = 0;
571            state->magtape.u.write.counter = 0;
663572            break;
664573         }
665574         break;
666575      }
667576
668577   case MTS_SELECTED:
669      switch (magtape.command)
578      switch (state->magtape.command)
670579      {
671580      case 0:   /* backspace */
672         if (magtape.img->ftell() == 0)
581         if (state->magtape.img->ftell() == 0)
673582         {   /* tape at ldp */
674            magtape.state = MTS_UNSELECTING;
583            state->magtape.state = MTS_UNSELECTING;
675584            cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_RWC);
676            schedule_unselect();
585            schedule_unselect(state);
677586         }
678         else if (magtape.img->fseek( -1, SEEK_CUR))
587         else if (state->magtape.img->fseek( -1, SEEK_CUR))
679588         {   /* eject tape */
680            magtape.img->unload();
589            state->magtape.img->unload();
681590         }
682         else if (magtape.img->fread(&buf, 1) != 1)
591         else if (state->magtape.img->fread(&buf, 1) != 1)
683592         {   /* eject tape */
684            magtape.img->unload();
593            state->magtape.img->unload();
685594         }
686         else if (magtape.img->fseek( -1, SEEK_CUR))
595         else if (state->magtape.img->fseek( -1, SEEK_CUR))
687596         {   /* eject tape */
688            magtape.img->unload();
597            state->magtape.img->unload();
689598         }
690599         else
691600         {
692601            buf &= 0x7f;   /* 7-bit tape, ignore 8th bit */
693            magtape.long_parity ^= buf;
694            switch (magtape.u.backspace_state)
602            state->magtape.long_parity ^= buf;
603            switch (state->magtape.u.backspace_state)
695604            {
696605            case MTBSS_STATE0:
697606               /* STATE0 -> initial interrecord gap, longitudinal parity;
698607                    if longitudinal parity was all 0s, gap between longitudinal
699608                    parity and data, first byte of data */
700609               if (buf != 0)
701                  magtape.u.backspace_state = MTBSS_STATE1;
610                  state->magtape.u.backspace_state = MTBSS_STATE1;
702611               break;
703612            case MTBSS_STATE1:
704613               /* STATE1 -> first byte of gap between longitudinal parity and
705614                    data, second byte of data */
706615               if (buf == 0)
707                  magtape.u.backspace_state = MTBSS_STATE2;
616                  state->magtape.u.backspace_state = MTBSS_STATE2;
708617               else
709                  magtape.u.backspace_state = MTBSS_STATE5;
618                  state->magtape.u.backspace_state = MTBSS_STATE5;
710619               break;
711620            case MTBSS_STATE2:
712621               /* STATE2 -> second byte of gap between longitudinal parity and
713622                    data */
714623               if (buf == 0)
715                  magtape.u.backspace_state = MTBSS_STATE3;
624                  state->magtape.u.backspace_state = MTBSS_STATE3;
716625               else
717626               {
718627                  logerror("tape seems to be corrupt\n");
719628                  /* eject tape */
720                  magtape.img->unload();
629                  state->magtape.img->unload();
721630               }
722631               break;
723632            case MTBSS_STATE3:
724633               /* STATE3 -> third byte of gap between longitudinal parity and
725634                    data */
726635               if (buf == 0)
727                  magtape.u.backspace_state = MTBSS_STATE4;
636                  state->magtape.u.backspace_state = MTBSS_STATE4;
728637               else
729638               {
730639                  logerror("tape seems to be corrupt\n");
731640                  /* eject tape */
732                  magtape.img->unload();
641                  state->magtape.img->unload();
733642               }
734643               break;
735644            case MTBSS_STATE4:
r9667r9668
737646                    interrecord gap after data */
738647               if (buf == 0)
739648               {
740                  if (magtape.long_parity)
649                  if (state->magtape.long_parity)
741650                     logerror("invalid longitudinal parity\n");
742651                  /* set EOR and unselect... */
743                  magtape.state = MTS_UNSELECTING;
652                  state->magtape.state = MTS_UNSELECTING;
744653                  cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_EOR);
745                  schedule_unselect();
746                  magtape.irg_pos = MTIRGP_ENDMINUS1;
654                  schedule_unselect(state);
655                  state->magtape.irg_pos = MTIRGP_ENDMINUS1;
747656               }
748657               else
749                  magtape.u.backspace_state = MTBSS_STATE5;
658                  state->magtape.u.backspace_state = MTBSS_STATE5;
750659               break;
751660            case MTBSS_STATE5:
752661               /* STATE5 -> second byte of data word */
r9667r9668
754663               {
755664                  logerror("tape seems to be corrupt\n");
756665                  /* eject tape */
757                  magtape.img->unload();
666                  state->magtape.img->unload();
758667               }
759668               else
760                  magtape.u.backspace_state = MTBSS_STATE6;
669                  state->magtape.u.backspace_state = MTBSS_STATE6;
761670               break;
762671            case MTBSS_STATE6:
763672               /* STATE6 -> third byte of data word */
r9667r9668
765674               {
766675                  logerror("tape seems to be corrupt\n");
767676                  /* eject tape */
768                  magtape.img->unload();
677                  state->magtape.img->unload();
769678               }
770679               else
771                  magtape.u.backspace_state = MTBSS_STATE6;
680                  state->magtape.u.backspace_state = MTBSS_STATE6;
772681               break;
773682            }
774            if (magtape.state != MTS_UNSELECTING)
775               timer_adjust_oneshot(magtape.timer, ATTOTIME_IN_USEC(66), 0);
683            if (state->magtape.state != MTS_UNSELECTING)
684               timer_adjust_oneshot(state->magtape.timer, ATTOTIME_IN_USEC(66), 0);
776685         }
777686         break;
778687
779688      case 1:   /* read */
780         if (magtape.img->fread(&buf, 1) != 1)
689         if (state->magtape.img->fread(&buf, 1) != 1)
781690         {   /* I/O error or EOF? */
782691            /* The MAME fileio layer makes it very hard to make the
783692                difference...  MAME seems to assume that I/O errors never
784693                happen, whereas it is really easy to cause one by
785694                deconnecting an external drive the image is located on!!! */
786695            UINT64 offs;
787            offs = magtape.img->ftell();
788            if (magtape.img->fseek( 0, SEEK_END) || (offs != magtape.img->ftell()))
696            offs = state->magtape.img->ftell();
697            if (state->magtape.img->fseek( 0, SEEK_END) || (offs != state->magtape.img->ftell()))
789698            {   /* I/O error */
790699               /* eject tape */
791               magtape.img->unload();
700               state->magtape.img->unload();
792701            }
793702            else
794703            {   /* end of tape -> ??? */
795704               /* maybe we run past end of tape, so that tape is ejected from
796705                    upper reel and unit becomes unavailable??? */
797               /*magtape.img->unload();*/
706               /*state->magtape.img->unload();*/
798707               /* Or do we stop at EOT mark??? */
799               magtape.state = MTS_UNSELECTING;
708               state->magtape.state = MTS_UNSELECTING;
800709               cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_EOT);
801               schedule_unselect();
710               schedule_unselect(state);
802711            }
803712         }
804713         else
805714         {
806715            buf &= 0x7f;   /* 7-bit tape, ignore 8th bit */
807            magtape.long_parity ^= buf;
808            switch (magtape.u.read.state)
716            state->magtape.long_parity ^= buf;
717            switch (state->magtape.u.read.state)
809718            {
810719            case MTRDS_STATE0:
811720               /* STATE0 -> interrecord blank or first byte of data */
812721               if (buf != 0)
813722               {
814                  if (magtape.cpy_pending)
723                  if (state->magtape.cpy_pending)
815724                  {   /* read command */
816                     magtape.u.read.space_flag = FALSE;
725                     state->magtape.u.read.space_flag = FALSE;
817726                     cpu_set_reg(device, TX0_IO_COMPLETE, (UINT64)0);
818727                     cpu_set_reg(device, TX0_LR, ((cpu_get_reg(device, TX0_LR) >> 1) & 0333333)
819728                                          | ((buf & 040) << 12) | ((buf & 020) << 10) | ((buf & 010) << 8) | ((buf & 004) << 6) | ((buf & 002) << 4) | ((buf & 001) << 2));
820729                     /* check parity */
821                     if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ magtape.binary_flag))
730                     if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ state->magtape.binary_flag))
822731                        cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC);
823732                  }
824733                  else
825734                  {   /* space command */
826                     magtape.u.read.space_flag = TRUE;
735                     state->magtape.u.read.space_flag = TRUE;
827736                  }
828                  magtape.u.read.state = MTRDS_STATE1;
737                  state->magtape.u.read.state = MTRDS_STATE1;
829738               }
830739               break;
831740            case MTRDS_STATE1:
r9667r9668
834743               {
835744                  logerror("tape seems to be corrupt\n");
836745                  /* eject tape */
837                  magtape.img->unload();
746                  state->magtape.img->unload();
838747               }
839               if (!magtape.u.read.space_flag)
748               if (!state->magtape.u.read.space_flag)
840749               {
841750                  cpu_set_reg(device, TX0_LR, ((cpu_get_reg(device, TX0_LR) >> 1) & 0333333)
842751                                       | ((buf & 040) << 12) | ((buf & 020) << 10) | ((buf & 010) << 8) | ((buf & 004) << 6) | ((buf & 002) << 4) | ((buf & 001) << 2));
843752                  /* check parity */
844                  if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ magtape.binary_flag))
753                  if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ state->magtape.binary_flag))
845754                     cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC);
846755               }
847               magtape.u.read.state = MTRDS_STATE2;
756               state->magtape.u.read.state = MTRDS_STATE2;
848757               break;
849758            case MTRDS_STATE2:
850759               /* STATE2 -> third byte of data word */
r9667r9668
852761               {
853762                  logerror("tape seems to be corrupt\n");
854763                  /* eject tape */
855                  magtape.img->unload();
764                  state->magtape.img->unload();
856765               }
857               if (!magtape.u.read.space_flag)
766               if (!state->magtape.u.read.space_flag)
858767               {
859768                  cpu_set_reg(device, TX0_LR, ((cpu_get_reg(device, TX0_LR) >> 1) & 0333333)
860769                                       | ((buf & 040) << 12) | ((buf & 020) << 10) | ((buf & 010) << 8) | ((buf & 004) << 6) | ((buf & 002) << 4) | ((buf & 001) << 2));
861770                  /* check parity */
862                  if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ magtape.binary_flag))
771                  if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ state->magtape.binary_flag))
863772                     cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC);
864773                  /* synchronize with cpy instruction */
865                  if (magtape.cpy_pending)
774                  if (state->magtape.cpy_pending)
866775                     cpu_set_reg(device, TX0_IO_COMPLETE, (UINT64)0);
867776                  else
868777                     cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_RWC);
869778               }
870               magtape.u.read.state = MTRDS_STATE3;
779               state->magtape.u.read.state = MTRDS_STATE3;
871780               break;
872781            case MTRDS_STATE3:
873782               /* STATE3 -> first byte of new word of data, or first byte
874783                    of gap between data and longitudinal parity */
875784               if (buf != 0)
876785               {
877                  magtape.u.read.state = MTRDS_STATE1;
878                  if (!magtape.u.read.space_flag)
786                  state->magtape.u.read.state = MTRDS_STATE1;
787                  if (!state->magtape.u.read.space_flag)
879788                  {
880789                     cpu_set_reg(device, TX0_LR, ((cpu_get_reg(device, TX0_LR) >> 1) & 0333333)
881790                                          | ((buf & 040) << 12) | ((buf & 020) << 10) | ((buf & 010) << 8) | ((buf & 004) << 6) | ((buf & 002) << 4) | ((buf & 001) << 2));
882791                     /* check parity */
883                     if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ magtape.binary_flag))
792                     if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ state->magtape.binary_flag))
884793                        cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC);
885794                  }
886795               }
887796               else
888                  magtape.u.read.state = MTRDS_STATE4;
797                  state->magtape.u.read.state = MTRDS_STATE4;
889798               break;
890799            case MTRDS_STATE4:
891800               /* STATE4 -> second byte of gap between data and
r9667r9668
894803               {
895804                  logerror("tape seems to be corrupt\n");
896805                  /* eject tape */
897                  magtape.img->unload();
806                  state->magtape.img->unload();
898807               }
899808               else
900                  magtape.u.read.state = MTRDS_STATE5;
809                  state->magtape.u.read.state = MTRDS_STATE5;
901810               break;
902811
903812            case MTRDS_STATE5:
r9667r9668
907816               {
908817                  logerror("tape seems to be corrupt\n");
909818                  /* eject tape */
910                  magtape.img->unload();
819                  state->magtape.img->unload();
911820               }
912821               else
913                  magtape.u.read.state = MTRDS_STATE6;
822                  state->magtape.u.read.state = MTRDS_STATE6;
914823               break;
915824
916825            case MTRDS_STATE6:
917826               /* STATE6 -> longitudinal parity */
918827               /* check parity */
919               if (magtape.long_parity)
828               if (state->magtape.long_parity)
920829               {
921830                  logerror("invalid longitudinal parity\n");
922                  /* no idea if the original tx-0 magtape controller
831                  /* no idea if the original tx-0 state->magtape controller
923832                        checks parity, but can't harm if we do */
924833                  cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC);
925834               }
926835               /* set EOR and unselect... */
927               magtape.state = MTS_UNSELECTING;
836               state->magtape.state = MTS_UNSELECTING;
928837               cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_EOR);
929               schedule_unselect();
930               magtape.irg_pos = MTIRGP_START;
838               schedule_unselect(state);
839               state->magtape.irg_pos = MTIRGP_START;
931840               break;
932841            }
933            if (magtape.state != MTS_UNSELECTING)
934               timer_adjust_oneshot(magtape.timer, ATTOTIME_IN_USEC(66), 0);
842            if (state->magtape.state != MTS_UNSELECTING)
843               timer_adjust_oneshot(state->magtape.timer, ATTOTIME_IN_USEC(66), 0);
935844         }
936845         break;
937846
938847      case 2:   /* rewind */
939         magtape.state = MTS_UNSELECTING;
848         state->magtape.state = MTS_UNSELECTING;
940849         /* we rewind at 10*read speed (I don't know the real value) */
941         timer_adjust_oneshot(magtape.timer, attotime_mul(ATTOTIME_IN_NSEC(6600), magtape.img->ftell()), 0);
942         //schedule_unselect();
943         magtape.img->fseek( 0, SEEK_END);
944         magtape.irg_pos = MTIRGP_END;
850         timer_adjust_oneshot(state->magtape.timer, attotime_mul(ATTOTIME_IN_NSEC(6600), state->magtape.img->ftell()), 0);
851         //schedule_unselect(state);
852         state->magtape.img->fseek( 0, SEEK_END);
853         state->magtape.irg_pos = MTIRGP_END;
945854         break;
946855
947856      case 3:   /* write */
948         switch (magtape.u.write.state)
857         switch (state->magtape.u.write.state)
949858         {
950859         case MTWTS_STATE0:
951            if (magtape.u.write.counter != 0)
860            if (state->magtape.u.write.counter != 0)
952861            {
953               magtape.u.write.counter--;
862               state->magtape.u.write.counter--;
954863               buf = 0;
955864               break;
956865            }
957866            else
958867            {
959               magtape.u.write.state = MTWTS_STATE1;
868               state->magtape.u.write.state = MTWTS_STATE1;
960869            }
961870
962871         case MTWTS_STATE1:
963            if (magtape.u.write.counter)
872            if (state->magtape.u.write.counter)
964873            {
965               magtape.u.write.counter--;
874               state->magtape.u.write.counter--;
966875               lr = cpu_get_reg(device, TX0_LR);
967876               buf = ((lr >> 10) & 040) | ((lr >> 8) & 020) | ((lr >> 6) & 010) | ((lr >> 4) & 004) | ((lr >> 2) & 002) | (lr & 001);
968               buf |= ((buf << 1) ^ (buf << 2) ^ (buf << 3) ^ (buf << 4) ^ (buf << 5) ^ (buf << 6) ^ ((!magtape.binary_flag) << 6)) & 0100;
877               buf |= ((buf << 1) ^ (buf << 2) ^ (buf << 3) ^ (buf << 4) ^ (buf << 5) ^ (buf << 6) ^ ((!state->magtape.binary_flag) << 6)) & 0100;
969878               cpu_set_reg(device, TX0_LR, lr >> 1);
970879            }
971880            else
972881            {
973               if (magtape.cpy_pending)
882               if (state->magtape.cpy_pending)
974883               {
975884                  cpu_set_reg(device, TX0_IO_COMPLETE, (UINT64)0);
976885                  lr = cpu_get_reg(device, TX0_LR);
977886                  buf = ((lr >> 10) & 040) | ((lr >> 8) & 020) | ((lr >> 6) & 010) | ((lr >> 4) & 004) | ((lr >> 2) & 002) | (lr & 001);
978                  buf |= ((buf << 1) ^ (buf << 2) ^ (buf << 3) ^ (buf << 4) ^ (buf << 5) ^ (buf << 6) ^ ((!magtape.binary_flag) << 6)) & 0100;
887                  buf |= ((buf << 1) ^ (buf << 2) ^ (buf << 3) ^ (buf << 4) ^ (buf << 5) ^ (buf << 6) ^ ((!state->magtape.binary_flag) << 6)) & 0100;
979888                  cpu_set_reg(device, TX0_LR, lr >> 1);
980                  magtape.u.write.counter = 2;
889                  state->magtape.u.write.counter = 2;
981890                  break;
982891               }
983892               else
984893               {
985                  magtape.u.write.state = MTWTS_STATE2;
986                  magtape.u.write.counter = 3;
894                  state->magtape.u.write.state = MTWTS_STATE2;
895                  state->magtape.u.write.counter = 3;
987896               }
988897            }
989898
990899         case MTWTS_STATE2:
991            if (magtape.u.write.counter != 0)
900            if (state->magtape.u.write.counter != 0)
992901            {
993               magtape.u.write.counter--;
902               state->magtape.u.write.counter--;
994903               buf = 0;
995904               break;
996905            }
997906            else
998907            {
999               buf = magtape.long_parity;
1000               magtape.state = (state_t)MTWTS_STATE3;
1001               magtape.u.write.counter = 150;
908               buf = state->magtape.long_parity;
909               state->magtape.state = (state_t)MTWTS_STATE3;
910               state->magtape.u.write.counter = 150;
1002911            }
1003912            break;
1004913
1005914         case MTWTS_STATE3:
1006            if (magtape.u.write.counter != 0)
915            if (state->magtape.u.write.counter != 0)
1007916            {
1008               magtape.u.write.counter--;
917               state->magtape.u.write.counter--;
1009918               buf = 0;
1010919               break;
1011920            }
1012921            else
1013922            {
1014               magtape.state = MTS_UNSELECTING;
1015               schedule_unselect();
1016               magtape.irg_pos = MTIRGP_END;
923               state->magtape.state = MTS_UNSELECTING;
924               schedule_unselect(state);
925               state->magtape.irg_pos = MTIRGP_END;
1017926            }
1018927            break;
1019928         }
1020         if (magtape.state != MTS_UNSELECTING)
929         if (state->magtape.state != MTS_UNSELECTING)
1021930         {   /* write data word */
1022            magtape.long_parity ^= buf;
1023            if (magtape.img->fwrite(&buf, 1) != 1)
931            state->magtape.long_parity ^= buf;
932            if (state->magtape.img->fwrite(&buf, 1) != 1)
1024933            {   /* I/O error */
1025934               /* eject tape */
1026               magtape.img->unload();
935               state->magtape.img->unload();
1027936            }
1028937            else
1029               timer_adjust_oneshot(magtape.timer, ATTOTIME_IN_USEC(66), 0);
938               timer_adjust_oneshot(state->magtape.timer, ATTOTIME_IN_USEC(66), 0);
1030939         }
1031940         break;
1032941      }
r9667r9668
1036945
1037946void tx0_sel(running_device *device)
1038947{
1039   magtape.sel_pending = TRUE;
948   tx0_state *state = device->machine->driver_data<tx0_state>();
949   state->magtape.sel_pending = TRUE;
1040950
1041   if (magtape.state == MTS_UNSELECTED)
951   if (state->magtape.state == MTS_UNSELECTED)
1042952   {
1043953      if (0)
1044954         magtape_callback(device);
1045      timer_adjust_oneshot(magtape.timer, attotime_zero, 0);
955      timer_adjust_oneshot(state->magtape.timer, attotime_zero, 0);
1046956   }
1047957}
1048958
1049959void tx0_io_cpy(running_device *device)
1050960{
1051   switch (magtape.state)
961   tx0_state *state = device->machine->driver_data<tx0_state>();
962   switch (state->magtape.state)
1052963   {
1053964   case MTS_UNSELECTED:
1054965   case MTS_UNSELECTING:
r9667r9668
1058969
1059970   case MTS_SELECTING:
1060971   case MTS_SELECTED:
1061      switch (magtape.command)
972      switch (state->magtape.command)
1062973      {
1063974      case 0:   /* backspace */
1064975      case 2:   /* rewind */
r9667r9668
1067978         break;
1068979      case 1:   /* read */
1069980      case 3:   /* write */
1070         magtape.cpy_pending = TRUE;
981         state->magtape.cpy_pending = TRUE;
1071982         break;
1072983      }
1073984      break;
r9667r9668
1082993*/
1083994void tx0_io_reset_callback(running_device *device)
1084995{
1085   tape_reader.rcl = tape_reader.rc = 0;
1086   if (tape_reader.timer)
1087      timer_enable(tape_reader.timer, 0);
996   tx0_state *state = device->machine->driver_data<tx0_state>();
997   state->tape_reader.rcl = state->tape_reader.rc = 0;
998   if (state->tape_reader.timer)
999      timer_enable(state->tape_reader.timer, 0);
10881000
1089   if (tape_puncher.timer)
1090      timer_enable(tape_puncher.timer, 0);
1001   if (state->tape_puncher.timer)
1002      timer_enable(state->tape_puncher.timer, 0);
10911003
1092   if (typewriter.prt_timer)
1093      timer_enable(typewriter.prt_timer, 0);
1004   if (state->typewriter.prt_timer)
1005      timer_enable(state->typewriter.prt_timer, 0);
10941006
1095   if (dis_timer)
1096      timer_enable(dis_timer, 0);
1007   if (state->dis_timer)
1008      timer_enable(state->dis_timer, 0);
10971009}
10981010
10991011
r9667r9668
11021014*/
11031015static void tx0_keyboard(running_machine *machine)
11041016{
1017   tx0_state *state = machine->driver_data<tx0_state>();
11051018   int i;
11061019   int j;
11071020
11081021   int typewriter_keys[4];
1109   static int old_typewriter_keys[4];
11101022
11111023   int typewriter_transitions;
11121024   int charcode, lr;
r9667r9668
11191031
11201032   for (i=0; i<4; i++)
11211033   {
1122      typewriter_transitions = typewriter_keys[i] & (~ old_typewriter_keys[i]);
1034      typewriter_transitions = typewriter_keys[i] & (~ state->old_typewriter_keys[i]);
11231035      if (typewriter_transitions)
11241036      {
11251037         for (j=0; (((typewriter_transitions >> j) & 1) == 0) /*&& (j<16)*/; j++)
r9667r9668
11371049   }
11381050
11391051   for (i=0; i<4; i++)
1140      old_typewriter_keys[i] = typewriter_keys[i];
1052      state->old_typewriter_keys[i] = typewriter_keys[i];
11411053}
11421054
11431055/*
r9667r9668
11451057*/
11461058INTERRUPT_GEN( tx0_interrupt )
11471059{
1060   tx0_state *state = device->machine->driver_data<tx0_state>();
11481061   int control_keys;
11491062   int tsr_keys;
11501063
1151   static int old_control_keys;
1152   static int old_tsr_keys;
1153   static int tsr_index = 0;
1154
11551064   int control_transitions;
11561065   int tsr_transitions;
11571066
r9667r9668
11621071   if (control_keys & tx0_control)
11631072   {
11641073      /* compute transitions */
1165      control_transitions = control_keys & (~ old_control_keys);
1074      control_transitions = control_keys & (~ state->old_control_keys);
11661075
11671076      if (control_transitions & tx0_stop_cyc0)
11681077      {
r9667r9668
11941103      }
11951104      if (control_transitions & tx0_toggle_dn)
11961105      {
1197         tsr_index++;
1198         if (tsr_index == 18)
1199            tsr_index = 0;
1106         state->tsr_index++;
1107         if (state->tsr_index == 18)
1108            state->tsr_index = 0;
12001109      }
12011110      if (control_transitions & tx0_toggle_up)
12021111      {
1203         tsr_index--;
1204         if (tsr_index == -1)
1205            tsr_index = 17;
1112         state->tsr_index--;
1113         if (state->tsr_index == -1)
1114            state->tsr_index = 17;
12061115      }
12071116      if (control_transitions & tx0_cm_sel)
12081117      {
1209         if (tsr_index >= 2)
1118         if (state->tsr_index >= 2)
12101119         {
12111120            UINT32 cm_sel = (UINT32) cpu_get_reg(device->machine->device("maincpu"), TX0_CM_SEL);
1212            cpu_set_reg(device->machine->device("maincpu"), TX0_CM_SEL, cm_sel ^ (1 << (tsr_index - 2)));
1121            cpu_set_reg(device->machine->device("maincpu"), TX0_CM_SEL, cm_sel ^ (1 << (state->tsr_index - 2)));
12131122         }
12141123      }
12151124      if (control_transitions & tx0_lr_sel)
12161125      {
1217         if (tsr_index >= 2)
1126         if (state->tsr_index >= 2)
12181127         {
12191128            UINT32 lr_sel = (UINT32) cpu_get_reg(device->machine->device("maincpu"), TX0_LR_SEL);
1220            cpu_set_reg(device->machine->device("maincpu"), TX0_LR_SEL, (lr_sel ^ (1 << (tsr_index - 2))));
1129            cpu_set_reg(device->machine->device("maincpu"), TX0_LR_SEL, (lr_sel ^ (1 << (state->tsr_index - 2))));
12211130         }
12221131      }
12231132
12241133      /* remember new state of control keys */
1225      old_control_keys = control_keys;
1134      state->old_control_keys = control_keys;
12261135
12271136
12281137      /* handle toggle switch register keys */
12291138      tsr_keys = (input_port_read(device->machine, "MSW") << 16) | input_port_read(device->machine, "LSW");
12301139
12311140      /* compute transitions */
1232      tsr_transitions = tsr_keys & (~ old_tsr_keys);
1141      tsr_transitions = tsr_keys & (~ state->old_tsr_keys);
12331142
12341143      /* update toggle switch register */
12351144      if (tsr_transitions)
1236         cpu_set_reg(device->machine->device("maincpu"), TX0_TBR+tsr_index, cpu_get_reg(device->machine->device("maincpu"), TX0_TBR+tsr_index) ^ tsr_transitions);
1145         cpu_set_reg(device->machine->device("maincpu"), TX0_TBR+state->tsr_index, cpu_get_reg(device->machine->device("maincpu"), TX0_TBR+state->tsr_index) ^ tsr_transitions);
12371146
12381147      /* remember new state of toggle switch register keys */
1239      old_tsr_keys = tsr_keys;
1148      state->old_tsr_keys = tsr_keys;
12401149   }
12411150   else
12421151   {
1243      old_control_keys = 0;
1244      old_tsr_keys = 0;
1152      state->old_control_keys = 0;
1153      state->old_tsr_keys = 0;
12451154
12461155      tx0_keyboard(device->machine);
12471156   }
src/mess/machine/odyssey2.c
r9667r9668
1212#include "sound/sp0256.h"
1313
1414
15static int the_voice_lrq_state;
16static UINT8 *ram;
17static UINT8 p1, p2;
18static size_t   cart_size;
1915
2016static void odyssey2_switch_banks(running_machine *machine)
2117{
22   switch ( cart_size ) {
18   odyssey2_state *state = machine->driver_data<odyssey2_state>();
19   switch ( state->cart_size ) {
2320   case 12288:
2421      /* 12KB cart support (for instance, KTAA as released) */
25      memory_set_bankptr( machine, "bank1", memory_region(machine, "user1") + (p1 & 0x03) * 0xC00 );
26      memory_set_bankptr( machine, "bank2", memory_region(machine, "user1") + (p1 & 0x03) * 0xC00 + 0x800 );
22      memory_set_bankptr( machine, "bank1", memory_region(machine, "user1") + (state->p1 & 0x03) * 0xC00 );
23      memory_set_bankptr( machine, "bank2", memory_region(machine, "user1") + (state->p1 & 0x03) * 0xC00 + 0x800 );
2724      break;
2825   case 16384:
2926      /* 16KB cart support (for instance, full sized version KTAA) */
30      memory_set_bankptr( machine, "bank1", memory_region(machine, "user1") + (p1 & 0x03) * 0x1000 + 0x400 );
31      memory_set_bankptr( machine, "bank2", memory_region(machine, "user1") + (p1 & 0x03) * 0x1000 + 0xC00 );
27      memory_set_bankptr( machine, "bank1", memory_region(machine, "user1") + (state->p1 & 0x03) * 0x1000 + 0x400 );
28      memory_set_bankptr( machine, "bank2", memory_region(machine, "user1") + (state->p1 & 0x03) * 0x1000 + 0xC00 );
3229      break;
3330   default:
34      memory_set_bankptr(machine, "bank1", memory_region(machine, "user1") + (p1 & 0x03) * 0x800);
35      memory_set_bankptr(machine, "bank2", memory_region(machine, "user1") + (p1 & 0x03) * 0x800 );
31      memory_set_bankptr(machine, "bank1", memory_region(machine, "user1") + (state->p1 & 0x03) * 0x800);
32      memory_set_bankptr(machine, "bank2", memory_region(machine, "user1") + (state->p1 & 0x03) * 0x800 );
3633      break;
3734   }
3835}
3936
4037void odyssey2_the_voice_lrq_callback(running_device *device, int state) {
41   the_voice_lrq_state = state;
38   odyssey2_state *drvstate = device->machine->driver_data<odyssey2_state>();
39   drvstate->the_voice_lrq_state = state;
4240}
4341
4442READ8_HANDLER( odyssey2_t0_r ) {
45   return ( the_voice_lrq_state == ASSERT_LINE ) ? 0 : 1;
43   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
44   return ( state->the_voice_lrq_state == ASSERT_LINE ) ? 0 : 1;
4645}
4746
4847DRIVER_INIT( odyssey2 )
4948{
49   odyssey2_state *state = machine->driver_data<odyssey2_state>();
5050   int i;
5151   UINT8 *gfx = memory_region(machine, "gfx1");
52   ram        = auto_alloc_array(machine, UINT8, 256);
52   state->ram        = auto_alloc_array(machine, UINT8, 256);
5353
5454   for (i = 0; i < 256; i++)
5555    {
5656      gfx[i] = i;     /* TODO: Why i and not 0? */
57      ram[i] = 0;
57      state->ram[i] = 0;
5858    }
5959}
6060
6161MACHINE_RESET( odyssey2 )
6262{
63   odyssey2_state *state = machine->driver_data<odyssey2_state>();
6364   /* jump to "last" bank, will work for all sizes due to being mirrored */
64   p1 = 0xFF;
65   p2 = 0xFF;
65   state->p1 = 0xFF;
66   state->p2 = 0xFF;
6667   odyssey2_switch_banks(machine);
6768}
6869
r9667r9668
7071
7172READ8_HANDLER( odyssey2_bus_r )
7273{
73    if ((p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0)
74      return odyssey2_video_r(space, offset); /* seems to have higher priority than ram??? */
74   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
75    if ((state->p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0)
76      return odyssey2_video_r(space, offset); /* seems to have higher priority than state->ram??? */
7577
76    else if (!(p1 & P1_EXT_RAM_ENABLE))
77      return ram[offset];
78    else if (!(state->p1 & P1_EXT_RAM_ENABLE))
79      return state->ram[offset];
7880
7981    return 0;
8082}
8183
8284WRITE8_HANDLER( odyssey2_bus_w )
8385{
84    if ((p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) {
85      ram[offset] = data;
86   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
87    if ((state->p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) {
88      state->ram[offset] = data;
8689      if ( offset & 0x80 ) {
8790         if ( data & 0x20 ) {
88            logerror("voice write %02X, data = %02X (p1 = %02X)\n", offset, data, p1 );
91            logerror("voice write %02X, data = %02X (state->p1 = %02X)\n", offset, data, state->p1 );
8992            sp0256_ALD_w( space->machine->device("sp0256_speech"), 0, offset & 0x7F );
9093         } else {
9194            /* TODO: Reset sp0256 in this case */
r9667r9668
9396      }
9497   }
9598
96    else if (!(p1 & P1_VDC_ENABLE))
99    else if (!(state->p1 & P1_VDC_ENABLE))
97100      odyssey2_video_w(space, offset, data);
98101}
99102
100103READ8_HANDLER( g7400_bus_r )
101104{
102   if ((p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0) {
103      return odyssey2_video_r(space, offset); /* seems to have higher priority than ram??? */
105   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
106   if ((state->p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0) {
107      return odyssey2_video_r(space, offset); /* seems to have higher priority than state->ram??? */
104108   }
105   else if (!(p1 & P1_EXT_RAM_ENABLE)) {
106      return ram[offset];
109   else if (!(state->p1 & P1_EXT_RAM_ENABLE)) {
110      return state->ram[offset];
107111   } else {
108112//      return ef9341_r( offset & 0x02, offset & 0x01 );
109113   }
r9667r9668
113117
114118WRITE8_HANDLER( g7400_bus_w )
115119{
116   if ((p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) {
117      ram[offset] = data;
120   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
121   if ((state->p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) {
122      state->ram[offset] = data;
118123   }
119   else if (!(p1 & P1_VDC_ENABLE)) {
124   else if (!(state->p1 & P1_VDC_ENABLE)) {
120125      odyssey2_video_w(space, offset, data);
121126   } else {
122127//      ef9341_w( offset & 0x02, offset & 0x01, data );
r9667r9668
127132
128133READ8_HANDLER( odyssey2_getp1 )
129134{
130   UINT8 data = p1;
135   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
136   UINT8 data = state->p1;
131137
132   logerror("%.9f p1 read %.2x\n", attotime_to_double(timer_get_time(space->machine)), data);
138   logerror("%.9f state->p1 read %.2x\n", attotime_to_double(timer_get_time(space->machine)), data);
133139   return data;
134140}
135141
136142WRITE8_HANDLER( odyssey2_putp1 )
137143{
138   p1 = data;
144   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
145   state->p1 = data;
139146
140147   odyssey2_switch_banks(space->machine);
141148
142   odyssey2_lum_w ( space, 0, p1 >> 7 );
149   odyssey2_lum_w ( space, 0, state->p1 >> 7 );
143150
144   logerror("%.6f p1 written %.2x\n", attotime_to_double(timer_get_time(space->machine)), data);
151   logerror("%.6f state->p1 written %.2x\n", attotime_to_double(timer_get_time(space->machine)), data);
145152}
146153
147154READ8_HANDLER( odyssey2_getp2 )
148155{
156   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
149157    UINT8 h = 0xFF;
150158    int i, j;
151159   static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5" };
152160
153    if (!(p1 & P1_KEYBOARD_SCAN_ENABLE))
161    if (!(state->p1 & P1_KEYBOARD_SCAN_ENABLE))
154162   {
155      if ((p2 & P2_KEYBOARD_SELECT_MASK) <= 5)  /* read keyboard */
163      if ((state->p2 & P2_KEYBOARD_SELECT_MASK) <= 5)  /* read keyboard */
156164      {
157         h &= input_port_read(space->machine, keynames[p2 & P2_KEYBOARD_SELECT_MASK]);
165         h &= input_port_read(space->machine, keynames[state->p2 & P2_KEYBOARD_SELECT_MASK]);
158166      }
159167
160168      for (i= 0x80, j = 0; i > 0; i >>= 1, j++)
161169      {
162170         if (!(h & i))
163171         {
164            p2 &= ~0x10;                   /* set key was pressed indicator */
165            p2 = (p2 & ~0xE0) | (j << 5);  /* column that was pressed */
172            state->p2 &= ~0x10;                   /* set key was pressed indicator */
173            state->p2 = (state->p2 & ~0xE0) | (j << 5);  /* column that was pressed */
166174
167175            break;
168176         }
169177      }
170178
171179        if (h == 0xFF)  /* active low inputs, so no keypresses */
172            p2 = p2 | 0xF0;
180            state->p2 = state->p2 | 0xF0;
173181    }
174182
175183    else
176        p2 = p2 | 0xF0;
184        state->p2 = state->p2 | 0xF0;
177185
178    logerror("%.6f p2 read %.2x\n", attotime_to_double(timer_get_time(space->machine)), p2);
179    return p2;
186    logerror("%.6f state->p2 read %.2x\n", attotime_to_double(timer_get_time(space->machine)), state->p2);
187    return state->p2;
180188}
181189
182190WRITE8_HANDLER( odyssey2_putp2 )
183191{
184    p2 = data;
192   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
193    state->p2 = data;
185194
186    logerror("%.6f p2 written %.2x\n", attotime_to_double(timer_get_time(space->machine)), data);
195    logerror("%.6f state->p2 written %.2x\n", attotime_to_double(timer_get_time(space->machine)), data);
187196}
188197
189198READ8_HANDLER( odyssey2_getbus )
190199{
200   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
191201    UINT8 data = 0xff;
192202
193    if ((p2 & P2_KEYBOARD_SELECT_MASK) == 1)
203    if ((state->p2 & P2_KEYBOARD_SELECT_MASK) == 1)
194204      data &= input_port_read(space->machine, "JOY0");       /* read joystick 1 */
195205
196    if ((p2 & P2_KEYBOARD_SELECT_MASK) == 0)
206    if ((state->p2 & P2_KEYBOARD_SELECT_MASK) == 0)
197207      data &= input_port_read(space->machine, "JOY1");       /* read joystick 2 */
198208
199209    logerror("%.6f bus read %.2x\n", attotime_to_double(timer_get_time(space->machine)), data);
r9667r9668
210220#ifdef UNUSED_FUNCTION
211221int odyssey2_cart_verify(const UINT8 *cartdata, size_t size)
212222{
213   cart_size = size;
223   odyssey2_state *state = machine->driver_data<odyssey2_state>();
224   state->cart_size = size;
214225    if (   (size == 2048)
215226        || (size == 4096)
216227        || (size == 8192)
src/mess/machine/nc.c
r9667r9668
1616/* the data is stored as a simple memory dump, there is no header or other information */
1717
1818/* stores size of actual file on filesystem */
19static int nc_card_size;
2019
2120/* save card data back */
2221static void nc_card_save(device_image_interface &image)
2322{
23   nc_state *state = image.device().machine->driver_data<nc_state>();
2424   /* if there is no data to write, quit */
25   if (!nc_card_ram || !nc_card_size)
25   if (!state->card_ram || !state->card_size)
2626      return;
2727
2828   logerror("attempting card save\n");
2929
3030   /* write data */
31   image.fwrite(nc_card_ram, nc_card_size);
31   image.fwrite(state->card_ram, state->card_size);
3232
3333   logerror("write succeeded!\r\n");
3434}
r9667r9668
5656/* load card image */
5757static int nc_card_load(device_image_interface &image, unsigned char **ptr)
5858{
59   nc_state *state = image.device().machine->driver_data<nc_state>();
5960   int datasize;
6061   unsigned char *data;
6162
62   /* get file size */
63   /* get state->file size */
6364   datasize = image.length();
6465
6566   if (datasize!=0)
r9667r9668
6970
7071      if (data!=NULL)
7172      {
72         nc_card_size = datasize;
73         state->card_size = datasize;
7374
74         /* read whole file */
75         /* read whole state->file */
7576         image.fread(data, datasize);
7677
7778         *ptr = data;
7879
7980         logerror("File loaded!\r\n");
8081
81         nc_membank_card_ram_mask = nc_card_calculate_mask(datasize);
82         state->membank_card_ram_mask = nc_card_calculate_mask(datasize);
8283
83         logerror("Mask: %02x\n",nc_membank_card_ram_mask);
84         logerror("Mask: %02x\n",state->membank_card_ram_mask);
8485
8586         /* ok! */
8687         return 1;
r9667r9668
9293
9394DEVICE_START( nc_pcmcia_card )
9495{
96   nc_state *state = device->machine->driver_data<nc_state>();
9597   /* card not present */
96   nc_set_card_present_state(0);
98   nc_set_card_present_state(device->machine, 0);
9799   /* card ram NULL */
98   nc_card_ram = NULL;
99   nc_card_size = 0;
100   state->card_ram = NULL;
101   state->card_size = 0;
100102}
101103
102104/* load pcmcia card */
103105DEVICE_IMAGE_LOAD( nc_pcmcia_card )
104106{
107   nc_state *state = image.device().machine->driver_data<nc_state>();
105108   /* filename specified */
106109
107   /* attempt to load file */
108   if (nc_card_load(image, &nc_card_ram))
110   /* attempt to load state->file */
111   if (nc_card_load(image, &state->card_ram))
109112   {
110      if (nc_card_ram!=NULL)
113      if (state->card_ram!=NULL)
111114      {
112115         /* card present! */
113         if (nc_membank_card_ram_mask!=0)
116         if (state->membank_card_ram_mask!=0)
114117         {
115            nc_set_card_present_state(1);
118            nc_set_card_present_state(image.device().machine, 1);
116119         }
117120         return IMAGE_INIT_PASS;
118121      }
r9667r9668
124127
125128DEVICE_IMAGE_UNLOAD( nc_pcmcia_card )
126129{
130   nc_state *state = image.device().machine->driver_data<nc_state>();
127131   /* save card data if there is any */
128132   nc_card_save(image);
129133
130134   /* free ram allocated to card */
131   if (nc_card_ram!=NULL)
135   if (state->card_ram!=NULL)
132136   {
133      free(nc_card_ram);
134      nc_card_ram = NULL;
137      free(state->card_ram);
138      state->card_ram = NULL;
135139   }
136   nc_card_size = 0;
140   state->card_size = 0;
137141
138142   /* set card not present state */
139   nc_set_card_present_state(0);
143   nc_set_card_present_state(image.device().machine, 0);
140144}
141145
142146
src/mess/machine/concept.c
r9667r9668
6262
6363/* Expansion slots */
6464
65static struct
66{
67   read8_space_func reg_read;
68   write8_space_func reg_write;
69   read8_space_func rom_read;
70   write8_space_func rom_write;
71} expansion_slots[4];
72
7365static void concept_fdc_init(running_machine *machine, int slot);
7466static void concept_hdc_init(running_machine *machine, int slot);
7567
r9667r9668
8779   memset(state->KeyStateSave, 0, sizeof(state->KeyStateSave));
8880
8981   /* initialize expansion slots */
90   memset(expansion_slots, 0, sizeof(expansion_slots));
82   memset(state->expansion_slots, 0, sizeof(state->expansion_slots));
9183
9284   concept_hdc_init(machine, 1);   /* Flat cable Hard Disk Controller in Slot 2 */
9385   concept_fdc_init(machine, 2);   /* Floppy Disk Controller in Slot 3 */
9486}
9587
96static void install_expansion_slot(int slot,
88static void install_expansion_slot(running_machine *machine, int slot,
9789   read8_space_func reg_read, write8_space_func reg_write,
9890   read8_space_func rom_read, write8_space_func rom_write)
9991{
100   expansion_slots[slot].reg_read = reg_read;
101   expansion_slots[slot].reg_write = reg_write;
102   expansion_slots[slot].rom_read = rom_read;
103   expansion_slots[slot].rom_write = rom_write;
92   concept_state *state = machine->driver_data<concept_state>();
93   state->expansion_slots[slot].reg_read = reg_read;
94   state->expansion_slots[slot].reg_write = reg_write;
95   state->expansion_slots[slot].rom_read = rom_read;
96   state->expansion_slots[slot].rom_write = rom_write;
10497}
10598
10699VIDEO_START(concept)
r9667r9668
284277         /* IO4 registers */
285278         {
286279            int slot = ((offset >> 4) & 7) - 1;
287            if (expansion_slots[slot].reg_read)
288               return expansion_slots[slot].reg_read(space, offset & 0xf);
280            if (state->expansion_slots[slot].reg_read)
281               return state->expansion_slots[slot].reg_read(space, offset & 0xf);
289282         }
290283         break;
291284
r9667r9668
307300      {
308301         int slot = ((offset >> 8) & 7) - 1;
309302         LOG(("concept_io_r: Slot ROM memory accessed for slot %d at address 0x03%4.4x\n", slot, offset << 1));
310         if (expansion_slots[slot].rom_read)
311            return expansion_slots[slot].rom_read(space, offset & 0xff);
303         if (state->expansion_slots[slot].rom_read)
304            return state->expansion_slots[slot].rom_read(space, offset & 0xff);
312305      }
313306      break;
314307
r9667r9668
427420            int slot = ((offset >> 4) & 7) - 1;
428421            LOG(("concept_io_w: Slot I/O register written for slot %d at address 0x03%4.4x, data: 0x%4.4x\n",
429422               slot, offset << 1, data));
430            if (expansion_slots[slot].reg_write)
431               expansion_slots[slot].reg_write(space, offset & 0xf, data);
423            if (state->expansion_slots[slot].reg_write)
424               state->expansion_slots[slot].reg_write(space, offset & 0xf, data);
432425         }
433426         break;
434427
r9667r9668
450443      {
451444         int slot = ((offset >> 8) & 7) - 1;
452445         LOG(("concept_io_w: Slot ROM memory written to for slot %d at address 0x03%4.4x, data: 0x%4.4x\n", slot, offset << 1, data));
453         if (expansion_slots[slot].rom_write)
454            expansion_slots[slot].rom_write(space, offset & 0xff, data);
446         if (state->expansion_slots[slot].rom_write)
447            state->expansion_slots[slot].rom_write(space, offset & 0xff, data);
455448      }
456449      break;
457450
r9667r9668
568561   state->fdc_local_status = 0;
569562   state->fdc_local_command = 0;
570563
571   install_expansion_slot(slot, concept_fdc_reg_r, concept_fdc_reg_w, concept_fdc_rom_r, NULL);
564   install_expansion_slot(machine, slot, concept_fdc_reg_r, concept_fdc_reg_w, concept_fdc_rom_r, NULL);
572565}
573566
574567static WRITE_LINE_DEVICE_HANDLER( concept_fdc_intrq_w )
r9667r9668
691684static void concept_hdc_init(running_machine *machine, int slot)
692685{
693686   if(corvus_hdc_init(machine))
694      install_expansion_slot(slot, concept_hdc_reg_r, concept_hdc_reg_w, concept_hdc_rom_r, NULL);
687      install_expansion_slot(machine, slot, concept_hdc_reg_r, concept_hdc_reg_w, concept_hdc_rom_r, NULL);
695688}
696689
697690/*
src/mess/machine/vectrex.c
r9667r9668
2828
2929*********************************************************************/
3030
31unsigned char vectrex_via_out[2];
32rgb_t vectrex_beam_color;      /* the color of the vectrex beam */
33int vectrex_imager_status = 0;     /* 0 = off, 1 = right eye, 2 = left eye */
34double vectrex_imager_freq;
35emu_timer *vectrex_imager_timer;
36int vectrex_lightpen_port=0;
37int vectrex_reset_refresh;
3831
3932
4033/*********************************************************************
r9667r9668
4437*********************************************************************/
4538
4639/* Colors for right and left eye */
47static rgb_t imager_colors[6];
4840
4941/* Starting points of the three colors */
5042/* Values taken from J. Nelson's drawings*/
r9667r9668
5547
5648
5749static const double unknown_game_angles[3] = {0,0.16666666, 0.33333333};
58static const double *vectrex_imager_angles;
59static unsigned char vectrex_imager_pinlevel;
6050
6151
6252static int vectrex_verify_cart(char *data)
r9667r9668
7767
7868DEVICE_IMAGE_LOAD(vectrex_cart)
7969{
70   vectrex_state *state = image.device().machine->driver_data<vectrex_state>();
8071   UINT8 *mem = memory_region(image.device().machine, "maincpu");
8172   if (image.software_entry() == NULL)
8273   {
r9667r9668
9384      return IMAGE_INIT_FAIL;
9485   }
9586
96   /* If VIA T2 starts, reset refresh timer.
87   /* If VIA T2 starts, reset state->refresh timer.
9788       This is the best strategy for most games. */
98   vectrex_reset_refresh = 1;
89   state->reset_refresh = 1;
9990
100   vectrex_imager_angles = narrow_escape_angles;
91   state->imager_angles = narrow_escape_angles;
10192
10293   /* let's do this 3D detection with a strcmp using data inside the cart images */
10394   /* slightly prettier than having to hardcode CRCs */
r9667r9668
10596   /* handle 3D Narrow Escape but skip the 2-d hack of it from Fred Taft */
10697   if (!memcmp(mem + 0x11,"NARROW",6) && (((char*)mem)[0x39] == 0x0c))
10798   {
108      vectrex_imager_angles = narrow_escape_angles;
99      state->imager_angles = narrow_escape_angles;
109100   }
110101
111102   if (!memcmp(mem + 0x11,"CRAZY COASTER", 13))
112103   {
113      vectrex_imager_angles = crazy_coaster_angles;
104      state->imager_angles = crazy_coaster_angles;
114105   }
115106
116107   if (!memcmp(mem + 0x11,"3D MINE STORM", 13))
117108   {
118      vectrex_imager_angles = minestorm_3d_angles;
109      state->imager_angles = minestorm_3d_angles;
119110
120111      /* Don't reset T2 each time it's written.
121112           This would cause jerking in mine3. */
122      vectrex_reset_refresh = 0;
113      state->reset_refresh = 0;
123114   }
124115
125116   return IMAGE_INIT_PASS;
r9667r9668
134125
135126void vectrex_configuration(running_machine *machine)
136127{
128   vectrex_state *state = machine->driver_data<vectrex_state>();
137129   unsigned char cport = input_port_read(machine, "3DCONF");
138130
139131   /* Vectrex 'dipswitch' configuration */
r9667r9668
141133   /* Imager control */
142134   if (cport & 0x01) /* Imager enabled */
143135   {
144      if (vectrex_imager_status == 0)
145         vectrex_imager_status = cport & 0x01;
136      if (state->imager_status == 0)
137         state->imager_status = cport & 0x01;
146138
147139      vector_add_point_function = cport & 0x02 ? vectrex_add_point_stereo: vectrex_add_point;
148140
149141      switch ((cport >> 2) & 0x07)
150142      {
151143      case 0x00:
152         imager_colors[0] = imager_colors[1] = imager_colors[2] = RGB_BLACK;
144         state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = RGB_BLACK;
153145         break;
154146      case 0x01:
155         imager_colors[0] = imager_colors[1] = imager_colors[2] = VC_DARKRED;
147         state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = VC_DARKRED;
156148         break;
157149      case 0x02:
158         imager_colors[0] = imager_colors[1] = imager_colors[2] = VC_GREEN;
150         state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = VC_GREEN;
159151         break;
160152      case 0x03:
161         imager_colors[0] = imager_colors[1] = imager_colors[2] = VC_BLUE;
153         state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = VC_BLUE;
162154         break;
163155      case 0x04:
164156         /* mine3 has a different color sequence */
165         if (vectrex_imager_angles == minestorm_3d_angles)
157         if (state->imager_angles == minestorm_3d_angles)
166158         {
167            imager_colors[0] = VC_GREEN;
168            imager_colors[1] = VC_RED;
159            state->imager_colors[0] = VC_GREEN;
160            state->imager_colors[1] = VC_RED;
169161         }
170162         else
171163         {
172            imager_colors[0] = VC_RED;
173            imager_colors[1] = VC_GREEN;
164            state->imager_colors[0] = VC_RED;
165            state->imager_colors[1] = VC_GREEN;
174166         }
175         imager_colors[2]=VC_BLUE;
167         state->imager_colors[2]=VC_BLUE;
176168         break;
177169      }
178170
179171      switch ((cport >> 5) & 0x07)
180172      {
181173      case 0x00:
182         imager_colors[3] = imager_colors[4] = imager_colors[5] = RGB_BLACK;
174         state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = RGB_BLACK;
183175         break;
184176      case 0x01:
185         imager_colors[3] = imager_colors[4] = imager_colors[5] = VC_DARKRED;
177         state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = VC_DARKRED;
186178         break;
187179      case 0x02:
188         imager_colors[3] = imager_colors[4] = imager_colors[5] = VC_GREEN;
180         state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = VC_GREEN;
189181         break;
190182      case 0x03:
191         imager_colors[3] = imager_colors[4] = imager_colors[5] = VC_BLUE;
183         state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = VC_BLUE;
192184         break;
193185      case 0x04:
194         if (vectrex_imager_angles == minestorm_3d_angles)
186         if (state->imager_angles == minestorm_3d_angles)
195187         {
196            imager_colors[3] = VC_GREEN;
197            imager_colors[4] = VC_RED;
188            state->imager_colors[3] = VC_GREEN;
189            state->imager_colors[4] = VC_RED;
198190         }
199191         else
200192         {
201            imager_colors[3] = VC_RED;
202            imager_colors[4] = VC_GREEN;
193            state->imager_colors[3] = VC_RED;
194            state->imager_colors[4] = VC_GREEN;
203195         }
204         imager_colors[5]=VC_BLUE;
196         state->imager_colors[5]=VC_BLUE;
205197         break;
206198      }
207199   }
208200   else
209201   {
210202      vector_add_point_function = vectrex_add_point;
211      vectrex_beam_color = RGB_WHITE;
212      imager_colors[0] = imager_colors[1] = imager_colors[2] = imager_colors[3] = imager_colors[4] = imager_colors[5] = RGB_WHITE;
203      state->beam_color = RGB_WHITE;
204      state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = RGB_WHITE;
213205   }
214   vectrex_lightpen_port = input_port_read(machine, "LPENCONF") & 0x03;
206   state->lightpen_port = input_port_read(machine, "LPENCONF") & 0x03;
215207}
216208
217209
r9667r9668
229221
230222READ8_DEVICE_HANDLER(vectrex_via_pb_r)
231223{
224   vectrex_state *state = device->machine->driver_data<vectrex_state>();
232225   int pot;
233226   static const char *const ctrlnames[] = { "CONTR1X", "CONTR1Y", "CONTR2X", "CONTR2Y" };
234227
235   pot = input_port_read(device->machine, ctrlnames[(vectrex_via_out[PORTB] & 0x6) >> 1]) - 0x80;
228   pot = input_port_read(device->machine, ctrlnames[(state->via_out[PORTB] & 0x6) >> 1]) - 0x80;
236229
237   if (pot > (signed char)vectrex_via_out[PORTA])
238      vectrex_via_out[PORTB] |= 0x20;
230   if (pot > (signed char)state->via_out[PORTA])
231      state->via_out[PORTB] |= 0x20;
239232   else
240      vectrex_via_out[PORTB] &= ~0x20;
233      state->via_out[PORTB] &= ~0x20;
241234
242   return vectrex_via_out[PORTB];
235   return state->via_out[PORTB];
243236}
244237
245238
246239READ8_DEVICE_HANDLER(vectrex_via_pa_r)
247240{
248   if ((!(vectrex_via_out[PORTB] & 0x10)) && (vectrex_via_out[PORTB] & 0x08))
241   vectrex_state *state = device->machine->driver_data<vectrex_state>();
242   if ((!(state->via_out[PORTB] & 0x10)) && (state->via_out[PORTB] & 0x08))
249243      /* BDIR inactive, we can read the PSG. BC1 has to be active. */
250244   {
251245      running_device *ay = device->machine->device("ay8912");
252246
253      vectrex_via_out[PORTA] = ay8910_r(ay, 0)
254         & ~(vectrex_imager_pinlevel & 0x80);
247      state->via_out[PORTA] = ay8910_r(ay, 0)
248         & ~(state->imager_pinlevel & 0x80);
255249   }
256   return vectrex_via_out[PORTA];
250   return state->via_out[PORTA];
257251}
258252
259253
260254READ8_DEVICE_HANDLER(vectrex_s1_via_pb_r)
261255{
262   return (vectrex_via_out[PORTB] & ~0x40) | (input_port_read(device->machine, "COIN") & 0x40);
256   vectrex_state *state = device->machine->driver_data<vectrex_state>();
257   return (state->via_out[PORTB] & ~0x40) | (input_port_read(device->machine, "COIN") & 0x40);
263258}
264259
265260
r9667r9668
271266
272267static TIMER_CALLBACK(vectrex_imager_change_color)
273268{
274   vectrex_beam_color = param;
269   vectrex_state *state = machine->driver_data<vectrex_state>();
270   state->beam_color = param;
275271}
276272
277273
r9667r9668
284280
285281TIMER_CALLBACK(vectrex_imager_eye)
286282{
283   vectrex_state *state = machine->driver_data<vectrex_state>();
287284   via6522_device *via_0 = machine->device<via6522_device>("via6522_0");
288285   int coffset;
289   double rtime = (1.0 / vectrex_imager_freq);
286   double rtime = (1.0 / state->imager_freq);
290287
291   if (vectrex_imager_status > 0)
288   if (state->imager_status > 0)
292289   {
293      vectrex_imager_status = param;
290      state->imager_status = param;
294291      coffset = param > 1? 3: 0;
295      timer_set (machine, double_to_attotime(rtime * vectrex_imager_angles[0]), NULL, imager_colors[coffset+2], vectrex_imager_change_color);
296      timer_set (machine, double_to_attotime(rtime * vectrex_imager_angles[1]), NULL, imager_colors[coffset+1], vectrex_imager_change_color);
297      timer_set (machine, double_to_attotime(rtime * vectrex_imager_angles[2]), NULL, imager_colors[coffset], vectrex_imager_change_color);
292      timer_set (machine, double_to_attotime(rtime * state->imager_angles[0]), NULL, state->imager_colors[coffset+2], vectrex_imager_change_color);
293      timer_set (machine, double_to_attotime(rtime * state->imager_angles[1]), NULL, state->imager_colors[coffset+1], vectrex_imager_change_color);
294      timer_set (machine, double_to_attotime(rtime * state->imager_angles[2]), NULL, state->imager_colors[coffset], vectrex_imager_change_color);
298295
299296      if (param == 2)
300297      {
r9667r9668
303300         /* Index hole sensor is connected to IO7 which triggers also CA1 of VIA */
304301         via_0->write_ca1(1);
305302         via_0->write_ca1(0);
306         vectrex_imager_pinlevel |= 0x80;
307         timer_set (machine, double_to_attotime(rtime / 360.0), &vectrex_imager_pinlevel, 0, update_level);
303         state->imager_pinlevel |= 0x80;
304         timer_set (machine, double_to_attotime(rtime / 360.0), &state->imager_pinlevel, 0, update_level);
308305      }
309306   }
310307}
r9667r9668
312309
313310WRITE8_HANDLER(vectrex_psg_port_w)
314311{
315   static int state;
316   static double sl, pwl;
312   vectrex_state *state = space->machine->driver_data<vectrex_state>();
317313   double wavel, ang_acc, tmp;
318314   int mcontrol;
319315
320316   mcontrol = data & 0x40; /* IO6 controls the imager motor */
321317
322   if (!mcontrol && mcontrol ^ state)
318   if (!mcontrol && mcontrol ^ state->old_mcontrol)
323319   {
324      state = mcontrol;
320      state->old_mcontrol = mcontrol;
325321      tmp = attotime_to_double(timer_get_time(space->machine));
326      wavel = tmp - sl;
327      sl = tmp;
322      wavel = tmp - state->sl;
323      state->sl = tmp;
328324
329325      if (wavel < 1)
330326      {
r9667r9668
334330               of the whole thing and some constants of the motor's torque/speed curve.
335331               pwl is the negative pulse width and wavel is the whole wavelength. */
336332
337         ang_acc = (50.0 - 1.55 * vectrex_imager_freq) / MMI;
338         vectrex_imager_freq += ang_acc * pwl + DAMPC * vectrex_imager_freq / MMI * wavel;
333         ang_acc = (50.0 - 1.55 * state->imager_freq) / MMI;
334         state->imager_freq += ang_acc * state->pwl + DAMPC * state->imager_freq / MMI * wavel;
339335
340         if (vectrex_imager_freq > 1)
336         if (state->imager_freq > 1)
341337         {
342            timer_adjust_periodic(vectrex_imager_timer,
343                             double_to_attotime(MIN(1.0 / vectrex_imager_freq, attotime_to_double(timer_timeleft(vectrex_imager_timer)))),
338            timer_adjust_periodic(state->imager_timer,
339                             double_to_attotime(MIN(1.0 / state->imager_freq, attotime_to_double(timer_timeleft(state->imager_timer)))),
344340                             2,
345                             double_to_attotime(1.0 / vectrex_imager_freq));
341                             double_to_attotime(1.0 / state->imager_freq));
346342         }
347343      }
348344   }
349   if (mcontrol && mcontrol ^ state)
345   if (mcontrol && mcontrol ^ state->old_mcontrol)
350346   {
351      state = mcontrol;
352      pwl = attotime_to_double(timer_get_time(space->machine)) - sl;
347      state->old_mcontrol = mcontrol;
348      state->pwl = attotime_to_double(timer_get_time(space->machine)) - state->sl;
353349   }
354350}
355351
356352DRIVER_INIT(vectrex)
357353{
354   vectrex_state *state = machine->driver_data<vectrex_state>();
358355   int i;
359356
360   vectrex_imager_angles = unknown_game_angles;
361   vectrex_beam_color = RGB_WHITE;
362   for (i=0; i<ARRAY_LENGTH(imager_colors); i++)
363      imager_colors[i] = RGB_WHITE;
357   state->imager_angles = unknown_game_angles;
358   state->beam_color = RGB_WHITE;
359   for (i=0; i<ARRAY_LENGTH(state->imager_colors); i++)
360      state->imager_colors[i] = RGB_WHITE;
364361
365362   /*
366363     * Uninitialized RAM needs to return 0xff. Otherwise the mines in
367364     * the first level of Minestorm are not evenly distributed.
368365     */
369366
370   memset(gce_vectorram, 0xff, gce_vectorram_size);
367   memset(state->gce_vectorram, 0xff, state->gce_vectorram_size);
371368}
src/mess/machine/lviv.c
r9667r9668
2020
2121#define LVIV_SNAPSHOT_SIZE   82219
2222
23unsigned char * lviv_video_ram;
2423
25static UINT8 lviv_ppi_port_outputs[2][3];
2624
27static UINT8 startup_mem_map;
2825
2926
3027static void lviv_update_memory (running_machine *machine)
3128{
32   if (lviv_ppi_port_outputs[0][2] & 0x02)
29   lviv_state *state = machine->driver_data<lviv_state>();
30   if (state->ppi_port_outputs[0][2] & 0x02)
3331   {
3432      memory_set_bankptr(machine,"bank1", messram_get_ptr(machine->device("messram")));
3533      memory_set_bankptr(machine,"bank2", messram_get_ptr(machine->device("messram")) + 0x4000);
r9667r9668
6563
6664static READ8_DEVICE_HANDLER ( lviv_ppi_0_portc_r )
6765{
68   UINT8 data = lviv_ppi_port_outputs[0][2] & 0x0f;
66   lviv_state *state = device->machine->driver_data<lviv_state>();
67   UINT8 data = state->ppi_port_outputs[0][2] & 0x0f;
6968   if (cassette_input(device->machine->device("cassette")) > 0.038)
7069      data |= 0x10;
71   if (lviv_ppi_port_outputs[0][0] & input_port_read(device->machine, "JOY"))
70   if (state->ppi_port_outputs[0][0] & input_port_read(device->machine, "JOY"))
7271      data |= 0x80;
7372   return data;
7473}
7574
7675static WRITE8_DEVICE_HANDLER ( lviv_ppi_0_porta_w )
7776{
78   lviv_ppi_port_outputs[0][0] = data;
77   lviv_state *state = device->machine->driver_data<lviv_state>();
78   state->ppi_port_outputs[0][0] = data;
7979}
8080
8181static WRITE8_DEVICE_HANDLER ( lviv_ppi_0_portb_w )
8282{
83   lviv_ppi_port_outputs[0][1] = data;
84   lviv_update_palette (data&0x7f);
83   lviv_state *state = device->machine->driver_data<lviv_state>();
84   state->ppi_port_outputs[0][1] = data;
85   lviv_update_palette(device->machine, data&0x7f);
8586}
8687
8788static WRITE8_DEVICE_HANDLER ( lviv_ppi_0_portc_w )   /* tape in/out, video memory on/off */
8889{
90   lviv_state *state = device->machine->driver_data<lviv_state>();
8991   running_device *speaker = device->machine->device("speaker");
90   lviv_ppi_port_outputs[0][2] = data;
91   if (lviv_ppi_port_outputs[0][1]&0x80)
92   state->ppi_port_outputs[0][2] = data;
93   if (state->ppi_port_outputs[0][1]&0x80)
9294      speaker_level_w(speaker, data&0x01);
9395   cassette_output(device->machine->device("cassette"), (data & 0x01) ? -1.0 : 1.0);
9496   lviv_update_memory(device->machine);
r9667r9668
101103
102104static READ8_DEVICE_HANDLER ( lviv_ppi_1_portb_r )   /* keyboard reading */
103105{
104   return   ((lviv_ppi_port_outputs[1][0] & 0x01) ? 0xff : input_port_read(device->machine, "KEY0")) &
105      ((lviv_ppi_port_outputs[1][0] & 0x02) ? 0xff : input_port_read(device->machine, "KEY1")) &
106      ((lviv_ppi_port_outputs[1][0] & 0x04) ? 0xff : input_port_read(device->machine, "KEY2")) &
107      ((lviv_ppi_port_outputs[1][0] & 0x08) ? 0xff : input_port_read(device->machine, "KEY3")) &
108      ((lviv_ppi_port_outputs[1][0] & 0x10) ? 0xff : input_port_read(device->machine, "KEY4")) &
109      ((lviv_ppi_port_outputs[1][0] & 0x20) ? 0xff : input_port_read(device->machine, "KEY5")) &
110      ((lviv_ppi_port_outputs[1][0] & 0x40) ? 0xff : input_port_read(device->machine, "KEY6")) &
111      ((lviv_ppi_port_outputs[1][0] & 0x80) ? 0xff : input_port_read(device->machine, "KEY7"));
106   lviv_state *state = device->machine->driver_data<lviv_state>();
107   return   ((state->ppi_port_outputs[1][0] & 0x01) ? 0xff : input_port_read(device->machine, "KEY0")) &
108      ((state->ppi_port_outputs[1][0] & 0x02) ? 0xff : input_port_read(device->machine, "KEY1")) &
109      ((state->ppi_port_outputs[1][0] & 0x04) ? 0xff : input_port_read(device->machine, "KEY2")) &
110      ((state->ppi_port_outputs[1][0] & 0x08) ? 0xff : input_port_read(device->machine, "KEY3")) &
111      ((state->ppi_port_outputs[1][0] & 0x10) ? 0xff : input_port_read(device->machine, "KEY4")) &
112      ((state->ppi_port_outputs[1][0] & 0x20) ? 0xff : input_port_read(device->machine, "KEY5")) &
113      ((state->ppi_port_outputs[1][0] & 0x40) ? 0xff : input_port_read(device->machine, "KEY6")) &
114      ((state->ppi_port_outputs[1][0] & 0x80) ? 0xff : input_port_read(device->machine, "KEY7"));
112115}
113116
114117static READ8_DEVICE_HANDLER ( lviv_ppi_1_portc_r )     /* keyboard reading */
115118{
116   return   ((lviv_ppi_port_outputs[1][2] & 0x01) ? 0xff : input_port_read(device->machine, "KEY8")) &
117      ((lviv_ppi_port_outputs[1][2] & 0x02) ? 0xff : input_port_read(device->machine, "KEY9" )) &
118      ((lviv_ppi_port_outputs[1][2] & 0x04) ? 0xff : input_port_read(device->machine, "KEY10")) &
119      ((lviv_ppi_port_outputs[1][2] & 0x08) ? 0xff : input_port_read(device->machine, "KEY11"));
119   lviv_state *state = device->machine->driver_data<lviv_state>();
120   return   ((state->ppi_port_outputs[1][2] & 0x01) ? 0xff : input_port_read(device->machine, "KEY8")) &
121      ((state->ppi_port_outputs[1][2] & 0x02) ? 0xff : input_port_read(device->machine, "KEY9" )) &
122      ((state->ppi_port_outputs[1][2] & 0x04) ? 0xff : input_port_read(device->machine, "KEY10")) &
123      ((state->ppi_port_outputs[1][2] & 0x08) ? 0xff : input_port_read(device->machine, "KEY11"));
120124}
121125
122126static WRITE8_DEVICE_HANDLER ( lviv_ppi_1_porta_w )   /* kayboard scaning */
123127{
124   lviv_ppi_port_outputs[1][0] = data;
128   lviv_state *state = device->machine->driver_data<lviv_state>();
129   state->ppi_port_outputs[1][0] = data;
125130}
126131
127132static WRITE8_DEVICE_HANDLER ( lviv_ppi_1_portb_w )
128133{
129   lviv_ppi_port_outputs[1][1] = data;
134   lviv_state *state = device->machine->driver_data<lviv_state>();
135   state->ppi_port_outputs[1][1] = data;
130136}
131137
132138static WRITE8_DEVICE_HANDLER ( lviv_ppi_1_portc_w )   /* kayboard scaning */
133139{
134   lviv_ppi_port_outputs[1][2] = data;
140   lviv_state *state = device->machine->driver_data<lviv_state>();
141   state->ppi_port_outputs[1][2] = data;
135142}
136143
137144
138145/* I/O */
139146 READ8_HANDLER ( lviv_io_r )
140147{
141   if (startup_mem_map)
148   lviv_state *state = space->machine->driver_data<lviv_state>();
149   if (state->startup_mem_map)
142150   {
143151      return 0;   /* ??? */
144152   }
r9667r9668
163171
164172WRITE8_HANDLER ( lviv_io_w )
165173{
174   lviv_state *state = space->machine->driver_data<lviv_state>();
166175   address_space *cpuspace = cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
167   if (startup_mem_map)
176   if (state->startup_mem_map)
168177   {
169      startup_mem_map = 0;
178      state->startup_mem_map = 0;
170179
171180      memory_install_write_bank(cpuspace, 0x0000, 0x3fff, 0, 0, "bank1");
172181      memory_install_write_bank(cpuspace, 0x4000, 0x7fff, 0, 0, "bank2");
r9667r9668
221230
222231MACHINE_RESET( lviv )
223232{
233   lviv_state *state = machine->driver_data<lviv_state>();
224234   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
225235   space->set_direct_update_handler(direct_update_delegate_create_static(lviv_directoverride, *machine));
226236
227   lviv_video_ram = messram_get_ptr(machine->device("messram")) + 0xc000;
237   state->video_ram = messram_get_ptr(machine->device("messram")) + 0xc000;
228238
229   startup_mem_map = 1;
239   state->startup_mem_map = 1;
230240
231241   memory_unmap_write(space, 0x0000, 0x3fff, 0, 0);
232242   memory_unmap_write(space, 0x4000, 0x7fff, 0, 0);
r9667r9668
261271
262272static void lviv_setup_snapshot (running_machine *machine,UINT8 * data)
263273{
274   lviv_state *state = machine->driver_data<lviv_state>();
264275   unsigned char lo,hi;
265276
266277   /* Set registers */
r9667r9668
288299   memcpy (messram_get_ptr(machine->device("messram"))+0xc000, data+0x10011, 0x4000);
289300
290301   /* Ports */
291   lviv_ppi_port_outputs[0][0] = data[0x14011+0xc0];
292   lviv_ppi_port_outputs[0][1] = data[0x14011+0xc1];
293   lviv_update_palette (lviv_ppi_port_outputs[0][1]&0x7f);
294   lviv_ppi_port_outputs[0][2] = data[0x14011+0xc2];
302   state->ppi_port_outputs[0][0] = data[0x14011+0xc0];
303   state->ppi_port_outputs[0][1] = data[0x14011+0xc1];
304   lviv_update_palette(machine, state->ppi_port_outputs[0][1]&0x7f);
305   state->ppi_port_outputs[0][2] = data[0x14011+0xc2];
295306   lviv_update_memory(machine);
296307}
297308
src/mess/video/pdp1.c
r9667r9668
2323#include "video/crt.h"
2424
2525
26static int typewriter_color;
2726
28static bitmap_t *panel_bitmap;
29static bitmap_t *typewriter_bitmap;
3027
3128static const rectangle typewriter_bitmap_bounds =
3229{
r9667r9668
4340static void pdp1_draw_panel_backdrop(running_machine *machine, bitmap_t *bitmap);
4441static void pdp1_draw_panel(running_machine *machine, bitmap_t *bitmap);
4542
46static lightpen_t lightpen_state, previous_lightpen_state;
47static void pdp1_erase_lightpen(bitmap_t *bitmap);
48static void pdp1_draw_lightpen(bitmap_t *bitmap);
43static void pdp1_erase_lightpen(pdp1_state *state, bitmap_t *bitmap);
44static void pdp1_draw_lightpen(pdp1_state *state, bitmap_t *bitmap);
4945
5046INLINE void pdp1_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
5147{
r9667r9668
5753*/
5854VIDEO_START( pdp1 )
5955{
60   typewriter_color = color_typewriter_black;
56   pdp1_state *state = machine->driver_data<pdp1_state>();
57   state->typewriter_color = color_typewriter_black;
6158
6259   /* alloc bitmaps for our private fun */
63   panel_bitmap = auto_bitmap_alloc(machine, panel_window_width, panel_window_height, BITMAP_FORMAT_INDEXED16);
64   typewriter_bitmap = auto_bitmap_alloc(machine, typewriter_window_width, typewriter_window_height, BITMAP_FORMAT_INDEXED16);
60   state->panel_bitmap = auto_bitmap_alloc(machine, panel_window_width, panel_window_height, BITMAP_FORMAT_INDEXED16);
61   state->typewriter_bitmap = auto_bitmap_alloc(machine, typewriter_window_width, typewriter_window_height, BITMAP_FORMAT_INDEXED16);
6562
6663   /* set up out bitmaps */
67   pdp1_draw_panel_backdrop(machine, panel_bitmap);
64   pdp1_draw_panel_backdrop(machine, state->panel_bitmap);
6865
69   bitmap_fill(typewriter_bitmap, &typewriter_bitmap_bounds, pen_typewriter_bg);
66   bitmap_fill(state->typewriter_bitmap, &typewriter_bitmap_bounds, pen_typewriter_bg);
7067
7168   /* initialize CRT */
7269   video_start_crt(machine, pen_crt_num_levels, crt_window_offset_x, crt_window_offset_y, crt_window_width, crt_window_height);
r9667r9668
9087*/
9188VIDEO_UPDATE( pdp1 )
9289{
93   pdp1_erase_lightpen(bitmap);
90   pdp1_state *state = screen->machine->driver_data<pdp1_state>();
91   pdp1_erase_lightpen(state, bitmap);
9492   VIDEO_UPDATE_CALL(crt);
95   pdp1_draw_lightpen(bitmap);
93   pdp1_draw_lightpen(state, bitmap);
9694
97   pdp1_draw_panel(screen->machine, panel_bitmap);
98   copybitmap(bitmap, panel_bitmap, 0, 0, panel_window_offset_x, panel_window_offset_y, cliprect);
95   pdp1_draw_panel(screen->machine, state->panel_bitmap);
96   copybitmap(bitmap, state->panel_bitmap, 0, 0, panel_window_offset_x, panel_window_offset_y, cliprect);
9997
100   copybitmap(bitmap, typewriter_bitmap, 0, 0, typewriter_window_offset_x, typewriter_window_offset_y, cliprect);
98   copybitmap(bitmap, state->typewriter_bitmap, 0, 0, typewriter_window_offset_x, typewriter_window_offset_y, cliprect);
10199   return 0;
102100}
103101
r9667r9668
255253*/
256254static void pdp1_draw_panel_backdrop(running_machine *machine, bitmap_t *bitmap)
257255{
256   pdp1_state *state = machine->driver_data<pdp1_state>();
258257   /* fill with black */
259   bitmap_fill(panel_bitmap, &panel_bitmap_bounds, pen_panel_bg);
258   bitmap_fill(state->panel_bitmap, &panel_bitmap_bounds, pen_panel_bg);
260259
261260   /* column 1: registers, test word, test address */
262261   pdp1_draw_string(machine, bitmap, "program counter", x_panel_col1_offset, y_panel_pc_offset, color_panel_caption);
r9667r9668
350349*/
351350
352351
353static int pos;
354352
355static int case_shift;
356353
357354enum
358355{
r9667r9668
374371
375372static void pdp1_typewriter_linefeed(running_machine *machine)
376373{
374   pdp1_state *state = machine->driver_data<pdp1_state>();
377375   UINT8 buf[typewriter_window_width];
378376   int y;
379377
380378   for (y=0; y<typewriter_window_height-typewriter_scroll_step; y++)
381379   {
382      extract_scanline8(typewriter_bitmap, 0, y+typewriter_scroll_step, typewriter_window_width, buf);
383      draw_scanline8(typewriter_bitmap, 0, y, typewriter_window_width, buf, machine->pens);
380      extract_scanline8(state->typewriter_bitmap, 0, y+typewriter_scroll_step, typewriter_window_width, buf);
381      draw_scanline8(state->typewriter_bitmap, 0, y, typewriter_window_width, buf, machine->pens);
384382   }
385383
386   bitmap_fill(typewriter_bitmap, &typewriter_scroll_clear_window, pen_typewriter_bg);
384   bitmap_fill(state->typewriter_bitmap, &typewriter_scroll_clear_window, pen_typewriter_bg);
387385}
388386
389387void pdp1_typewriter_drawchar(running_machine *machine, int character)
390388{
389   pdp1_state *state = machine->driver_data<pdp1_state>();
391390   static const char ascii_table[2][64] =
392391   {   /* n-s = non-spacing */
393392      {   /* lower case */
r9667r9668
436435   {
437436   case 034:
438437      /* Black */
439      typewriter_color = color_typewriter_black;
438      state->typewriter_color = color_typewriter_black;
440439      break;
441440
442441   case 035:
443442      /* Red */
444      typewriter_color = color_typewriter_red;
443      state->typewriter_color = color_typewriter_red;
445444      break;
446445
447446   case 036:
448447      /* Tab */
449      pos = pos + tab_step - (pos % tab_step);
448      state->pos = state->pos + tab_step - (state->pos % tab_step);
450449      break;
451450
452451   case 072:
453452      /* Lower case */
454      case_shift = 0;
453      state->case_shift = 0;
455454      break;
456455
457456   case 074:
458457      /* Upper case */
459      case_shift = 1;
458      state->case_shift = 1;
460459      break;
461460
462461   case 075:
463462      /* Backspace */
464      if (pos)
465         pos--;
463      if (state->pos)
464         state->pos--;
466465      break;
467466
468467   case 077:
469468      /* Carriage Return */
470      pos = 0;
469      state->pos = 0;
471470      pdp1_typewriter_linefeed(machine);
472471      break;
473472
474473   default:
475474      /* Any printable character... */
476475
477      if (pos >= 80)
476      if (state->pos >= 80)
478477      {   /* if past right border, wrap around. (Right???) */
479478         pdp1_typewriter_linefeed(machine);   /* next line */
480         pos = 0;               /* return to start of line */
479         state->pos = 0;               /* return to start of line */
481480      }
482481
483482      /* print character (lookup ASCII equivalent in table) */
484      pdp1_draw_char(machine, typewriter_bitmap, ascii_table[case_shift][character],
485                  8*pos, typewriter_write_offset_y,
486                  typewriter_color);   /* print char */
483      pdp1_draw_char(machine, state->typewriter_bitmap, ascii_table[state->case_shift][character],
484                  8*state->pos, typewriter_write_offset_y,
485                  state->typewriter_color);   /* print char */
487486
488487      if ((character!= 040) && (character!= 056))   /* 040 and 056 are non-spacing characters */
489         pos++;      /* step carriage forward */
488         state->pos++;      /* step carriage forward */
490489
491490      break;
492491   }
r9667r9668
498497    lightpen code
499498*/
500499
501void pdp1_update_lightpen_state(const lightpen_t *new_state)
500void pdp1_update_lightpen_state(running_machine *machine, const lightpen_t *new_state)
502501{
503   lightpen_state = *new_state;
502   pdp1_state *state = machine->driver_data<pdp1_state>();
503   state->lightpen_state = *new_state;
504504}
505505
506506#if 1
r9667r9668
571571}
572572#endif
573573
574static void pdp1_erase_lightpen(bitmap_t *bitmap)
574static void pdp1_erase_lightpen(pdp1_state *state, bitmap_t *bitmap)
575575{
576   if (previous_lightpen_state.active)
576   if (state->previous_lightpen_state.active)
577577   {
578578#if 0
579      if (previous_lightpen_state.x>0)
580         pdp1_plot_pixel(bitmap, previous_lightpen_state.x/2-1, previous_lightpen_state.y/2, pen_black);
581      if (previous_lightpen_state.x<1023)
582         pdp1_plot_pixel(bitmap, previous_lightpen_state.x/2+1, previous_lightpen_state.y/2, pen_black);
583      if (previous_lightpen_state.y>0)
584         pdp1_plot_pixel(bitmap, previous_lightpen_state.x/2, previous_lightpen_state.y/2-1, pen_black);
585      if (previous_lightpen_state.y<1023)
586         pdp1_plot_pixel(bitmap, previous_lightpen_state.x/2, previous_lightpen_state.y/2+1, pen_black);
579      if (state->previous_lightpen_state.x>0)
580         pdp1_plot_pixel(bitmap, state->previous_lightpen_state.x/2-1, state->previous_lightpen_state.y/2, pen_black);
581      if (state->previous_lightpen_state.x<1023)
582         pdp1_plot_pixel(bitmap, state->previous_lightpen_state.x/2+1, state->previous_lightpen_state.y/2, pen_black);
583      if (state->previous_lightpen_state.y>0)
584         pdp1_plot_pixel(bitmap, state->previous_lightpen_state.x/2, state->previous_lightpen_state.y/2-1, pen_black);
585      if (state->previous_lightpen_state.y<1023)
586         pdp1_plot_pixel(bitmap, state->previous_lightpen_state.x/2, state->previous_lightpen_state.y/2+1, pen_black);
587587#endif
588      pdp1_draw_circle(bitmap, previous_lightpen_state.x, previous_lightpen_state.y, previous_lightpen_state.radius, pen_black);
588      pdp1_draw_circle(bitmap, state->previous_lightpen_state.x, state->previous_lightpen_state.y, state->previous_lightpen_state.radius, pen_black);
589589   }
590590}
591591
592static void pdp1_draw_lightpen(bitmap_t *bitmap)
592static void pdp1_draw_lightpen(pdp1_state *state, bitmap_t *bitmap)
593593{
594   if (lightpen_state.active)
594   if (state->lightpen_state.active)
595595   {
596      int color_ = lightpen_state.down ? pen_lightpen_pressed : pen_lightpen_nonpressed;
596      int color_ = state->lightpen_state.down ? pen_lightpen_pressed : pen_lightpen_nonpressed;
597597#if 0
598      if (lightpen_state.x>0)
599         pdp1_plot_pixel(bitmap, lightpen_state.x/2-1, lightpen_state.y/2, color);
600      if (lightpen_state.x<1023)
601         pdp1_plot_pixel(bitmap, lightpen_state.x/2+1, lightpen_state.y/2, color);
602      if (lightpen_state.y>0)
603         pdp1_plot_pixel(bitmap, lightpen_state.x/2, lightpen_state.y/2-1, color);
604      if (lightpen_state.y<1023)
605         pdp1_plot_pixel(bitmap, lightpen_state.x/2, lightpen_state.y/2+1, color);
598      if (state->lightpen_state.x>0)
599         pdp1_plot_pixel(bitmap, state->lightpen_state.x/2-1, state->lightpen_state.y/2, color);
600      if (state->lightpen_state.x<1023)
601         pdp1_plot_pixel(bitmap, state->lightpen_state.x/2+1, state->lightpen_state.y/2, color);
602      if (state->lightpen_state.y>0)
603         pdp1_plot_pixel(bitmap, state->lightpen_state.x/2, state->lightpen_state.y/2-1, color);
604      if (state->lightpen_state.y<1023)
605         pdp1_plot_pixel(bitmap, state->lightpen_state.x/2, state->lightpen_state.y/2+1, color);
606606#endif
607      pdp1_draw_circle(bitmap, lightpen_state.x, lightpen_state.y, lightpen_state.radius, color_);
607      pdp1_draw_circle(bitmap, state->lightpen_state.x, state->lightpen_state.y, state->lightpen_state.radius, color_);
608608   }
609   previous_lightpen_state = lightpen_state;
609   state->previous_lightpen_state = state->lightpen_state;
610610}
src/mess/video/nc.c
r9667r9668
4040   palette_set_colors(machine, 0, nc_palette, ARRAY_LENGTH(nc_palette));
4141}
4242
43static int nc200_backlight = 0;
4443
45void nc200_video_set_backlight(int state)
44void nc200_video_set_backlight(running_machine *machine, int state)
4645{
47   nc200_backlight = state;
46   nc_state *drvstate = machine->driver_data<nc_state>();
47   drvstate->nc200_backlight = state;
4848}
4949
5050
r9667r9668
5555***************************************************************************/
5656VIDEO_UPDATE( nc )
5757{
58   nc_state *state = screen->machine->driver_data<nc_state>();
5859   int y;
5960   int b;
6061   int x;
6162   int height, width;
6263   int pens[2];
6364
64    if (nc_type==NC_TYPE_200)
65    if (state->type==NC_TYPE_200)
6566    {
6667        height = NC200_SCREEN_HEIGHT;
6768        width = NC200_SCREEN_WIDTH;
6869
69      if (nc200_backlight)
70      if (state->nc200_backlight)
7071      {
7172         pens[0] = 2;
7273         pens[1] = 3;
r9667r9668
9091    {
9192      int by;
9293      /* 64 bytes per line */
93      char *line_ptr = ((char*)messram_get_ptr(screen->machine->device("messram"))) + nc_display_memory_start + (y<<6);
94      char *line_ptr = ((char*)messram_get_ptr(screen->machine->device("messram"))) + state->display_memory_start + (y<<6);
9495
9596      x = 0;
9697      for (by=0; by<width>>3; by++)
src/mess/video/vectrex.c
r9667r9668
99
1010
1111#define ANALOG_DELAY 7800
12#define NVECT 10000
1312
1413#define INT_PER_CLOCK 550
1514
r9667r9668
3635   A_Y,
3736};
3837
39typedef struct _vectrex_point
40{
41   int x; int y;
42   rgb_t col;
43   int intensity;
44} vectrex_point;
4538
46
4739/*********************************************************************
4840
4941   Prototypes
r9667r9668
7163   DEVCB_LINE(vectrex_via_irq),                      /* IRQ */
7264};
7365
74static int x_center, y_center, x_max, y_max;
75static int x_int, y_int; /* X, Y integrators */
76static int lightpen_down, pen_x, pen_y; /* Lightpen position */
77static emu_timer *lp_t;
78static emu_timer *refresh;
79static UINT8 blank;
80static UINT8 ramp;
81static INT8 analog[5];
82static int vectrex_point_index;
83static int display_start, display_end;
84static vectrex_point vectrex_points[NVECT];
85static UINT16 via_timer2;
86static attotime vector_start_time;
8766
88typedef void (*vector_add_point_fn)(int, int, rgb_t, int);
67typedef void (*vector_add_point_fn)(running_machine *, int, int, rgb_t, int);
8968vector_add_point_fn vector_add_point_function;
9069
9170
r9667r9668
9776
9877static TIMER_CALLBACK(lightpen_trigger)
9978{
100   if (vectrex_lightpen_port & 1)
79   vectrex_state *state = machine->driver_data<vectrex_state>();
80   if (state->lightpen_port & 1)
10181   {
10282      via6522_device *via_0 = machine->device<via6522_device>("via6522_0");
10383      via_0->write_ca1(1);
10484      via_0->write_ca1(0);
10585   }
10686
107   if (vectrex_lightpen_port & 2)
87   if (state->lightpen_port & 2)
10888   {
10989      cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, PULSE_LINE);
11090   }
r9667r9668
138118
139119WRITE8_HANDLER(vectrex_via_w)
140120{
121   vectrex_state *state = space->machine->driver_data<vectrex_state>();
141122   via6522_device *via = space->machine->device<via6522_device>("via6522_0");
142123   attotime period;
143124
144125   switch (offset)
145126   {
146127   case 8:
147      via_timer2 = (via_timer2 & 0xff00) | data;
128      state->via_timer2 = (state->via_timer2 & 0xff00) | data;
148129      break;
149130
150131   case 9:
151      via_timer2 = (via_timer2 & 0x00ff) | (data << 8);
132      state->via_timer2 = (state->via_timer2 & 0x00ff) | (data << 8);
152133
153      period = attotime_mul(ATTOTIME_IN_HZ(cputag_get_clock(space->machine, "maincpu")), via_timer2);
134      period = attotime_mul(ATTOTIME_IN_HZ(cputag_get_clock(space->machine, "maincpu")), state->via_timer2);
154135
155      if (vectrex_reset_refresh)
156         timer_adjust_periodic(refresh, period, 0, period);
136      if (state->reset_refresh)
137         timer_adjust_periodic(state->refresh, period, 0, period);
157138      else
158         timer_adjust_periodic(refresh,
159                          attotime_min(period, timer_timeleft(refresh)),
139         timer_adjust_periodic(state->refresh,
140                          attotime_min(period, timer_timeleft(state->refresh)),
160141                          0,
161142                          period);
162143      break;
r9667r9668
173154
174155static TIMER_CALLBACK(vectrex_refresh)
175156{
157   vectrex_state *state = machine->driver_data<vectrex_state>();
176158   /* Refresh only marks the range of vectors which will be drawn
177159     * during the next VIDEO_UPDATE. */
178   display_start = display_end;
179   display_end = vectrex_point_index;
160   state->display_start = state->display_end;
161   state->display_end = state->point_index;
180162}
181163
182164
183165VIDEO_UPDATE(vectrex)
184166{
167   vectrex_state *state = screen->machine->driver_data<vectrex_state>();
185168   int i;
186169
187170   vectrex_configuration(screen->machine);
188171
189172   /* start black */
190173   vector_add_point(screen->machine,
191                vectrex_points[display_start].x,
192                vectrex_points[display_start].y,
193                vectrex_points[display_start].col,
174                state->points[state->display_start].x,
175                state->points[state->display_start].y,
176                state->points[state->display_start].col,
194177                0);
195178
196   for (i = display_start; i != display_end; i = (i + 1) % NVECT)
179   for (i = state->display_start; i != state->display_end; i = (i + 1) % NVECT)
197180   {
198181      vector_add_point(screen->machine,
199                   vectrex_points[i].x,
200                   vectrex_points[i].y,
201                   vectrex_points[i].col,
202                   vectrex_points[i].intensity);
182                   state->points[i].x,
183                   state->points[i].y,
184                   state->points[i].col,
185                   state->points[i].intensity);
203186   }
204187
205188   VIDEO_UPDATE_CALL(vector);
r9667r9668
214197
215198*********************************************************************/
216199
217void vectrex_add_point(int x, int y, rgb_t color, int intensity)
200void vectrex_add_point(running_machine *machine, int x, int y, rgb_t color, int intensity)
218201{
202   vectrex_state *state = machine->driver_data<vectrex_state>();
219203   vectrex_point *newpoint;
220204
221   vectrex_point_index = (vectrex_point_index+1) % NVECT;
222   newpoint = &vectrex_points[vectrex_point_index];
205   state->point_index = (state->point_index+1) % NVECT;
206   newpoint = &state->points[state->point_index];
223207
224208   newpoint->x = x;
225209   newpoint->y = y;
r9667r9668
228212}
229213
230214
231void vectrex_add_point_stereo(int x, int y, rgb_t color, int intensity)
215void vectrex_add_point_stereo(running_machine *machine, int x, int y, rgb_t color, int intensity)
232216{
233   if (vectrex_imager_status == 2) /* left = 1, right = 2 */
234      vectrex_add_point ((int)(y * M_SQRT1_2)+ x_center,
235                     (int)(((x_max - x) * M_SQRT1_2)),
217   vectrex_state *state = machine->driver_data<vectrex_state>();
218   if (state->imager_status == 2) /* left = 1, right = 2 */
219      vectrex_add_point(machine, (int)(y * M_SQRT1_2)+ state->x_center,
220                     (int)(((state->x_max - x) * M_SQRT1_2)),
236221                     color,
237222                     intensity);
238223   else
239      vectrex_add_point ((int)(y * M_SQRT1_2),
240                     (int)((x_max - x) * M_SQRT1_2),
224      vectrex_add_point(machine, (int)(y * M_SQRT1_2),
225                     (int)((state->x_max - x) * M_SQRT1_2),
241226                     color,
242227                     intensity);
243228}
r9667r9668
245230
246231static TIMER_CALLBACK(vectrex_zero_integrators)
247232{
248   x_int = x_center + (analog[A_ZR] * INT_PER_CLOCK);
249   y_int = y_center + (analog[A_ZR] * INT_PER_CLOCK);
250   vector_add_point_function (x_int, y_int, vectrex_beam_color, 0);
233   vectrex_state *state = machine->driver_data<vectrex_state>();
234   state->x_int = state->x_center + (state->analog[A_ZR] * INT_PER_CLOCK);
235   state->y_int = state->y_center + (state->analog[A_ZR] * INT_PER_CLOCK);
236   vector_add_point_function(machine, state->x_int, state->y_int, state->beam_color, 0);
251237}
252238
253239
r9667r9668
263249
264250static TIMER_CALLBACK(update_signal)
265251{
252   vectrex_state *state = machine->driver_data<vectrex_state>();
266253   int length;
267254
268   if (!ramp)
255   if (!state->ramp)
269256   {
270257      length = cputag_get_clock(machine, "maincpu") * INT_PER_CLOCK
271         * attotime_to_double(attotime_sub(timer_get_time(machine), vector_start_time));
258         * attotime_to_double(attotime_sub(timer_get_time(machine), state->vector_start_time));
272259
273      x_int += length * (analog[A_X] + analog[A_ZR]);
274      y_int += length * (analog[A_Y] + analog[A_ZR]);
260      state->x_int += length * (state->analog[A_X] + state->analog[A_ZR]);
261      state->y_int += length * (state->analog[A_Y] + state->analog[A_ZR]);
275262
276      vector_add_point_function(x_int, y_int, vectrex_beam_color, 2 * analog[A_Z] * blank);
263      vector_add_point_function(machine, state->x_int, state->y_int, state->beam_color, 2 * state->analog[A_Z] * state->blank);
277264   }
278265   else
279266   {
280      if (blank)
281         vector_add_point_function(x_int, y_int, vectrex_beam_color, 2 * analog[A_Z]);
267      if (state->blank)
268         vector_add_point_function(machine, state->x_int, state->y_int, state->beam_color, 2 * state->analog[A_Z]);
282269   }
283270
284   vector_start_time = timer_get_time(machine);
271   state->vector_start_time = timer_get_time(machine);
285272
286273   if (ptr)
287274      * (UINT8 *) ptr = param;
r9667r9668
296283
297284VIDEO_START(vectrex)
298285{
286   vectrex_state *state = machine->driver_data<vectrex_state>();
299287   screen_device *screen = screen_first(*machine);
300288   const rectangle &visarea = screen->visible_area();
301289
302   x_center=((visarea.max_x - visarea.min_x) / 2) << 16;
303   y_center=((visarea.max_y - visarea.min_y) / 2) << 16;
304   x_max = visarea.max_x << 16;
305   y_max = visarea.max_y << 16;
290   state->x_center=((visarea.max_x - visarea.min_x) / 2) << 16;
291   state->y_center=((visarea.max_y - visarea.min_y) / 2) << 16;
292   state->x_max = visarea.max_x << 16;
293   state->y_max = visarea.max_y << 16;
306294
307   vectrex_imager_freq = 1;
295   state->imager_freq = 1;
308296
309297   vector_add_point_function = vectrex_add_point;
310   vectrex_imager_timer = timer_alloc(machine, vectrex_imager_eye, NULL);
311   timer_adjust_periodic(vectrex_imager_timer,
312                    ATTOTIME_IN_HZ(vectrex_imager_freq),
298   state->imager_timer = timer_alloc(machine, vectrex_imager_eye, NULL);
299   timer_adjust_periodic(state->imager_timer,
300                    ATTOTIME_IN_HZ(state->imager_freq),
313301                    2,
314                    ATTOTIME_IN_HZ(vectrex_imager_freq));
302                    ATTOTIME_IN_HZ(state->imager_freq));
315303
316   lp_t = timer_alloc(machine, lightpen_trigger, NULL);
304   state->lp_t = timer_alloc(machine, lightpen_trigger, NULL);
317305
318   refresh = timer_alloc(machine, vectrex_refresh, NULL);
306   state->refresh = timer_alloc(machine, vectrex_refresh, NULL);
319307
320308   VIDEO_START_CALL(vector);
321309}
r9667r9668
329317
330318static void vectrex_multiplexer(running_machine *machine, int mux)
331319{
320   vectrex_state *state = machine->driver_data<vectrex_state>();
332321   running_device *dac_device = machine->device("dac");
333322
334   timer_set(machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &analog[mux], vectrex_via_out[PORTA], update_signal);
323   timer_set(machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &state->analog[mux], state->via_out[PORTA], update_signal);
335324
336325   if (mux == A_AUDIO)
337      dac_data_w(dac_device, vectrex_via_out[PORTA]);
326      dac_data_w(dac_device, state->via_out[PORTA]);
338327}
339328
340329
341330static WRITE8_DEVICE_HANDLER(v_via_pb_w)
342331{
332   vectrex_state *state = device->machine->driver_data<vectrex_state>();
343333   if (!(data & 0x80))
344334   {
345335      /* RAMP is active */
346      if ((ramp & 0x80))
336      if ((state->ramp & 0x80))
347337      {
348338         /* RAMP was inactive before */
349339
350         if (lightpen_down)
340         if (state->lightpen_down)
351341         {
352342            /* Simple lin. algebra to check if pen is near
353343                 * the line defined by (A_X,A_Y).
r9667r9668
368358                 *            a
369359                 */
370360            double a2, b2, ab, d2;
371            ab = (pen_x - x_int) * analog[A_X]
372               +(pen_y - y_int) * analog[A_Y];
361            ab = (state->pen_x - state->x_int) * state->analog[A_X]
362               +(state->pen_y - state->y_int) * state->analog[A_Y];
373363            if (ab > 0)
374364            {
375               a2 = (double)(analog[A_X] * analog[A_X]
376                          +(double)analog[A_Y] * analog[A_Y]);
377               b2 = (double)(pen_x - x_int) * (pen_x - x_int)
378                  +(double)(pen_y - y_int) * (pen_y - y_int);
365               a2 = (double)(state->analog[A_X] * state->analog[A_X]
366                          +(double)state->analog[A_Y] * state->analog[A_Y]);
367               b2 = (double)(state->pen_x - state->x_int) * (state->pen_x - state->x_int)
368                  +(double)(state->pen_y - state->y_int) * (state->pen_y - state->y_int);
379369               d2 = b2 - ab * ab / a2;
380               if (d2 < 2e10 && analog[A_Z] * blank > 0)
381                  timer_adjust_oneshot(lp_t, double_to_attotime(ab / a2 / (cputag_get_clock(device->machine, "maincpu") * INT_PER_CLOCK)), 0);
370               if (d2 < 2e10 && state->analog[A_Z] * state->blank > 0)
371                  timer_adjust_oneshot(state->lp_t, double_to_attotime(ab / a2 / (cputag_get_clock(device->machine, "maincpu") * INT_PER_CLOCK)), 0);
382372            }
383373         }
384374      }
385375
386      if (!(data & 0x1) && (vectrex_via_out[PORTB] & 0x1))
376      if (!(data & 0x1) && (state->via_out[PORTB] & 0x1))
387377      {
388378         /* MUX has been enabled */
389379         timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), NULL, 0, update_signal);
r9667r9668
392382   else
393383   {
394384      /* RAMP is inactive */
395      if (!(ramp & 0x80))
385      if (!(state->ramp & 0x80))
396386      {
397387         /* Cancel running timer, line already finished */
398         if (lightpen_down)
399            timer_adjust_oneshot(lp_t, attotime_never, 0);
388         if (state->lightpen_down)
389            timer_adjust_oneshot(state->lp_t, attotime_never, 0);
400390      }
401391   }
402392
r9667r9668
406396      running_device *ay8912 = device->machine->device("ay8912");
407397
408398      if (data & 0x08) /* BC1 (do we select a reg or write it ?) */
409         ay8910_address_w(ay8912, 0, vectrex_via_out[PORTA]);
399         ay8910_address_w(ay8912, 0, state->via_out[PORTA]);
410400      else
411         ay8910_data_w(ay8912, 0, vectrex_via_out[PORTA]);
401         ay8910_data_w(ay8912, 0, state->via_out[PORTA]);
412402   }
413403
414   if (!(data & 0x1) && (vectrex_via_out[PORTB] & 0x1))
404   if (!(data & 0x1) && (state->via_out[PORTB] & 0x1))
415405      vectrex_multiplexer (device->machine, (data >> 1) & 0x3);
416406
417   vectrex_via_out[PORTB] = data;
418   timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &ramp, data & 0x80, update_signal);
407   state->via_out[PORTB] = data;
408   timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &state->ramp, data & 0x80, update_signal);
419409}
420410
421411
422412static WRITE8_DEVICE_HANDLER(v_via_pa_w)
423413{
414   vectrex_state *state = device->machine->driver_data<vectrex_state>();
424415   /* DAC output always goes to Y integrator */
425   vectrex_via_out[PORTA] = data;
426   timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &analog[A_Y], data, update_signal);
416   state->via_out[PORTA] = data;
417   timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &state->analog[A_Y], data, update_signal);
427418
428   if (!(vectrex_via_out[PORTB] & 0x1))
429      vectrex_multiplexer (device->machine, (vectrex_via_out[PORTB] >> 1) & 0x3);
419   if (!(state->via_out[PORTB] & 0x1))
420      vectrex_multiplexer (device->machine, (state->via_out[PORTB] >> 1) & 0x3);
430421}
431422
432423
r9667r9668
439430
440431static WRITE8_DEVICE_HANDLER(v_via_cb2_w)
441432{
433   vectrex_state *state = device->machine->driver_data<vectrex_state>();
442434   int dx, dy;
443   static UINT8 cb2 = 0;
444435
445   if (cb2 != data)
436   if (state->cb2 != data)
446437   {
447438
448439      /* Check lightpen */
449      if (vectrex_lightpen_port != 0)
440      if (state->lightpen_port != 0)
450441      {
451         lightpen_down = input_port_read(device->machine, "LPENCONF") & 0x10;
442         state->lightpen_down = input_port_read(device->machine, "LPENCONF") & 0x10;
452443
453         if (lightpen_down)
444         if (state->lightpen_down)
454445         {
455            pen_x = input_port_read(device->machine, "LPENX") * (x_max / 0xff);
456            pen_y = input_port_read(device->machine, "LPENY") * (y_max / 0xff);
446            state->pen_x = input_port_read(device->machine, "LPENX") * (state->x_max / 0xff);
447            state->pen_y = input_port_read(device->machine, "LPENY") * (state->y_max / 0xff);
457448
458            dx = abs(pen_x - x_int);
459            dy = abs(pen_y - y_int);
449            dx = abs(state->pen_x - state->x_int);
450            dy = abs(state->pen_y - state->y_int);
460451            if (dx < 500000 && dy < 500000 && data > 0)
461452               timer_set(device->machine, attotime_zero, NULL, 0, lightpen_trigger);
462453         }
463454      }
464455
465      timer_set(device->machine, attotime_zero, &blank, data, update_signal);
466      cb2 = data;
456      timer_set(device->machine, attotime_zero, &state->blank, data, update_signal);
457      state->cb2 = data;
467458   }
468459}
469460
r9667r9668
492483
493484VIDEO_START(raaspec)
494485{
486   vectrex_state *state = machine->driver_data<vectrex_state>();
495487   screen_device *screen = screen_first(*machine);
496488   const rectangle &visarea = screen->visible_area();
497489
498   x_center=((visarea.max_x - visarea.min_x) / 2) << 16;
499   y_center=((visarea.max_y - visarea.min_y) / 2) << 16;
500   x_max = visarea.max_x << 16;
501   y_max = visarea.max_y << 16;
490   state->x_center=((visarea.max_x - visarea.min_x) / 2) << 16;
491   state->y_center=((visarea.max_y - visarea.min_y) / 2) << 16;
492   state->x_max = visarea.max_x << 16;
493   state->y_max = visarea.max_y << 16;
502494
503495   vector_add_point_function = vectrex_add_point;
504   refresh = timer_alloc(machine, vectrex_refresh, NULL);
496   state->refresh = timer_alloc(machine, vectrex_refresh, NULL);
505497
506498   VIDEO_START_CALL(vector);
507499}
src/mess/video/tx0.c
r9667r9668
1111#include "video/crt.h"
1212
1313
14static int typewriter_color;
1514
16static bitmap_t *panel_bitmap;
17static bitmap_t *typewriter_bitmap;
1815
1916INLINE void tx0_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
2017{
r9667r9668
4340*/
4441VIDEO_START( tx0 )
4542{
46   typewriter_color = color_typewriter_black;
43   tx0_state *state = machine->driver_data<tx0_state>();
44   state->typewriter_color = color_typewriter_black;
4745
4846   /* alloc bitmaps for our private fun */
49   panel_bitmap = auto_bitmap_alloc(machine, panel_window_width, panel_window_height, BITMAP_FORMAT_INDEXED16);
50   typewriter_bitmap = auto_bitmap_alloc(machine, typewriter_window_width, typewriter_window_height, BITMAP_FORMAT_INDEXED16);
47   state->panel_bitmap = auto_bitmap_alloc(machine, panel_window_width, panel_window_height, BITMAP_FORMAT_INDEXED16);
48   state->typewriter_bitmap = auto_bitmap_alloc(machine, typewriter_window_width, typewriter_window_height, BITMAP_FORMAT_INDEXED16);
5149
5250   /* set up out bitmaps */
53   tx0_draw_panel_backdrop(machine, panel_bitmap);
51   tx0_draw_panel_backdrop(machine, state->panel_bitmap);
5452
55   bitmap_fill(typewriter_bitmap, &typewriter_bitmap_bounds, pen_typewriter_bg);
53   bitmap_fill(state->typewriter_bitmap, &typewriter_bitmap_bounds, pen_typewriter_bg);
5654
5755   /* initialize CRT */
5856   video_start_crt(machine, pen_crt_num_levels, crt_window_offset_x, crt_window_offset_y, crt_window_width, crt_window_height);
r9667r9668
7674*/
7775VIDEO_UPDATE( tx0 )
7876{
77   tx0_state *state = screen->machine->driver_data<tx0_state>();
7978   VIDEO_UPDATE_CALL(crt);
8079
81   tx0_draw_panel(screen->machine, panel_bitmap);
82   copybitmap(bitmap, panel_bitmap, 0, 0, panel_window_offset_x, panel_window_offset_y, cliprect);
80   tx0_draw_panel(screen->machine, state->panel_bitmap);
81   copybitmap(bitmap, state->panel_bitmap, 0, 0, panel_window_offset_x, panel_window_offset_y, cliprect);
8382
84   copybitmap(bitmap, typewriter_bitmap, 0, 0, typewriter_window_offset_x, typewriter_window_offset_y, cliprect);
83   copybitmap(bitmap, state->typewriter_bitmap, 0, 0, typewriter_window_offset_x, typewriter_window_offset_y, cliprect);
8584   return 0;
8685}
8786
r9667r9668
245244*/
246245static void tx0_draw_panel_backdrop(running_machine *machine, bitmap_t *bitmap)
247246{
247   tx0_state *state = machine->driver_data<tx0_state>();
248248   int i;
249249   char buf[3];
250250
251251   /* fill with black */
252   bitmap_fill(panel_bitmap, &panel_bitmap_bounds, pen_panel_bg);
252   bitmap_fill(state->panel_bitmap, &panel_bitmap_bounds, pen_panel_bg);
253253
254254   /* column 1: registers, test accumulator, test buffer, toggle switch storage */
255255   tx0_draw_string(machine, bitmap, "program counter", x_panel_col1b_offset, y_panel_pc_offset, color_panel_caption);
r9667r9668
334334*/
335335
336336
337static int pos;
338337
339static int case_shift;
340338
341339
342340enum
r9667r9668
360358
361359static void tx0_typewriter_linefeed(running_machine *machine)
362360{
361   tx0_state *state = machine->driver_data<tx0_state>();
363362   UINT8 buf[typewriter_window_width];
364363   int y;
365364
366365   for (y=0; y<typewriter_window_height-typewriter_scroll_step; y++)
367366   {
368      extract_scanline8(typewriter_bitmap, 0, y+typewriter_scroll_step, typewriter_window_width, buf);
369      draw_scanline8(typewriter_bitmap, 0, y, typewriter_window_width, buf, machine->pens);
367      extract_scanline8(state->typewriter_bitmap, 0, y+typewriter_scroll_step, typewriter_window_width, buf);
368      draw_scanline8(state->typewriter_bitmap, 0, y, typewriter_window_width, buf, machine->pens);
370369   }
371370
372   bitmap_fill(typewriter_bitmap, &typewriter_scroll_clear_window, pen_typewriter_bg);
371   bitmap_fill(state->typewriter_bitmap, &typewriter_scroll_clear_window, pen_typewriter_bg);
373372}
374373
375374void tx0_typewriter_drawchar(running_machine *machine, int character)
376375{
376   tx0_state *state = machine->driver_data<tx0_state>();
377377   static const char ascii_table[2][64] =
378378   {
379379      {   /* lower case */
r9667r9668
423423   case 020:
424424#if 0
425425      /* color shift */
426      typewriter_color = color_typewriter_black;
427      typewriter_color = color_typewriter_red;
426      state->typewriter_color = color_typewriter_black;
427      state->typewriter_color = color_typewriter_red;
428428#endif
429429      break;
430430
431431   case 043:
432432      /* Backspace */
433      if (pos)
434         pos--;
433      if (state->pos)
434         state->pos--;
435435      break;
436436
437437   case 045:
438438      /* Tab */
439      pos = pos + tab_step - (pos % tab_step);
439      state->pos = state->pos + tab_step - (state->pos % tab_step);
440440      break;
441441
442442   case 051:
443443      /* Carriage Return */
444      pos = 0;
444      state->pos = 0;
445445      tx0_typewriter_linefeed( machine );
446446      break;
447447
r9667r9668
452452
453453   case 071:
454454      /* Upper case */
455      case_shift = 1;
455      state->case_shift = 1;
456456      break;
457457
458458   case 075:
459459      /* Lower case */
460      case_shift = 0;
460      state->case_shift = 0;
461461      break;
462462
463463   case 077:
r9667r9668
468468   default:
469469      /* Any printable character... */
470470
471      if (pos >= 80)
471      if (state->pos >= 80)
472472      {   /* if past right border, wrap around. (Right???) */
473473         tx0_typewriter_linefeed( machine );   /* next line */
474         pos = 0;               /* return to start of line */
474         state->pos = 0;               /* return to start of line */
475475      }
476476
477477      /* print character (lookup ASCII equivalent in table) */
478      tx0_draw_char(machine, typewriter_bitmap, ascii_table[case_shift][character],
479                  8*pos, typewriter_write_offset_y,
480                  typewriter_color);   /* print char */
478      tx0_draw_char(machine, state->typewriter_bitmap, ascii_table[state->case_shift][character],
479                  8*state->pos, typewriter_write_offset_y,
480                  state->typewriter_color);   /* print char */
481481
482      pos++;      /* step carriage forward */
482      state->pos++;      /* step carriage forward */
483483      break;
484484   }
485485}
src/mess/video/lviv.c
r9667r9668
2323   0xa4, 0xa4, 0xa4
2424};
2525
26unsigned short lviv_colortable[1][4] =
27{
28   { 0, 0, 0, 0 }
29};
3026
3127PALETTE_INIT( lviv )
3228{
r9667r9668
3834}
3935
4036
41void lviv_update_palette (UINT8 pal)
37void lviv_update_palette(running_machine *machine, UINT8 pal)
4238{
43   lviv_colortable[0][0] = 0;
44   lviv_colortable[0][1] = 0;
45   lviv_colortable[0][2] = 0;
46   lviv_colortable[0][3] = 0;
39   lviv_state *state = machine->driver_data<lviv_state>();
40   state->colortable[0][0] = 0;
41   state->colortable[0][1] = 0;
42   state->colortable[0][2] = 0;
43   state->colortable[0][3] = 0;
4744
48   lviv_colortable[0][0] |= (((pal>>3)&0x01) == ((pal>>4)&0x01)) ? 0x04 : 0x00;
49   lviv_colortable[0][0] |= ((pal>>5)&0x01) ? 0x02 : 0x00;
50   lviv_colortable[0][0] |= (((pal>>2)&0x01) == ((pal>>6)&0x01)) ? 0x01 : 0x00;
45   state->colortable[0][0] |= (((pal>>3)&0x01) == ((pal>>4)&0x01)) ? 0x04 : 0x00;
46   state->colortable[0][0] |= ((pal>>5)&0x01) ? 0x02 : 0x00;
47   state->colortable[0][0] |= (((pal>>2)&0x01) == ((pal>>6)&0x01)) ? 0x01 : 0x00;
5148
52   lviv_colortable[0][1] |= ((pal&0x01) == ((pal>>4)&0x01)) ? 0x04 : 0x00;
53   lviv_colortable[0][1] |= ((pal>>5)&0x01) ? 0x02 : 0x00;
54   lviv_colortable[0][1] |= ((pal>>6)&0x01) ? 0x00 : 0x01;
49   state->colortable[0][1] |= ((pal&0x01) == ((pal>>4)&0x01)) ? 0x04 : 0x00;
50   state->colortable[0][1] |= ((pal>>5)&0x01) ? 0x02 : 0x00;
51   state->colortable[0][1] |= ((pal>>6)&0x01) ? 0x00 : 0x01;
5552
56   lviv_colortable[0][2] |= ((pal>>4)&0x01) ? 0x04 : 0x00;
57   lviv_colortable[0][2] |= ((pal>>5)&0x01) ? 0x00 : 0x02;
58   lviv_colortable[0][2] |= ((pal>>6)&0x01) ? 0x01 : 0x00;
53   state->colortable[0][2] |= ((pal>>4)&0x01) ? 0x04 : 0x00;
54   state->colortable[0][2] |= ((pal>>5)&0x01) ? 0x00 : 0x02;
55   state->colortable[0][2] |= ((pal>>6)&0x01) ? 0x01 : 0x00;
5956
60   lviv_colortable[0][3] |= ((pal>>4)&0x01) ? 0x00 : 0x04;
61   lviv_colortable[0][3] |= (((pal>>1)&0x01) == ((pal>>5)&0x01)) ? 0x02 : 0x00;
62   lviv_colortable[0][3] |= ((pal>>6)&0x01) ? 0x01 : 0x00;
57   state->colortable[0][3] |= ((pal>>4)&0x01) ? 0x00 : 0x04;
58   state->colortable[0][3] |= (((pal>>1)&0x01) == ((pal>>5)&0x01)) ? 0x02 : 0x00;
59   state->colortable[0][3] |= ((pal>>6)&0x01) ? 0x01 : 0x00;
6360}
6461
6562VIDEO_START( lviv )
r9667r9668
6865
6966VIDEO_UPDATE( lviv )
7067{
68   lviv_state *state = screen->machine->driver_data<lviv_state>();
7169   int x,y;
7270   int pen;
7371   UINT8 data;
r9667r9668
7573   for (y=0; y<256; y++)
7674      for (x=0; x<256; x+=4)
7775      {
78         data = lviv_video_ram[y*64+x/4];
76         data = state->video_ram[y*64+x/4];
7977
80         pen = lviv_colortable[0][((data & 0x08) >> 3) | ((data & 0x80) >> (3+3))];
78         pen = state->colortable[0][((data & 0x08) >> 3) | ((data & 0x80) >> (3+3))];
8179         *BITMAP_ADDR16(bitmap, y, x + 0) = pen;
8280
83         pen = lviv_colortable[0][((data & 0x04) >> 2) | ((data & 0x40) >> (2+3))];
81         pen = state->colortable[0][((data & 0x04) >> 2) | ((data & 0x40) >> (2+3))];
8482         *BITMAP_ADDR16(bitmap, y, x + 1) = pen;
8583
86         pen = lviv_colortable[0][((data & 0x02) >> 1) | ((data & 0x20) >> (1+3))];
84         pen = state->colortable[0][((data & 0x02) >> 1) | ((data & 0x20) >> (1+3))];
8785         *BITMAP_ADDR16(bitmap, y, x + 2) = pen;
8886
89         pen = lviv_colortable[0][((data & 0x01) >> 0) | ((data & 0x10) >> (0+3))];
87         pen = state->colortable[0][((data & 0x01) >> 0) | ((data & 0x10) >> (0+3))];
9088         *BITMAP_ADDR16(bitmap, y, x + 3) = pen;
9189      }
9290   return 0;
src/mess/video/ssystem3.c
r9667r9668
55#include "emu.h"
66#include "includes/ssystem3.h"
77
8static struct {
9  UINT8 data[5];
10  int clock;
11  int count;
12} ssystem3_lcd;
13
14void ssystem3_lcd_reset(void)
8void ssystem3_lcd_reset(running_machine *machine)
159{
16  ssystem3_lcd.count=0; ssystem3_lcd.clock=1;
10   ssystem3_state *state = machine->driver_data<ssystem3_state>();
11   state->lcd.count=0; state->lcd.clock=1;
1712}
1813
1914void ssystem3_lcd_write(running_machine *machine, int clock, int data)
2015{
21  if (clock&&!ssystem3_lcd.clock) {
22    ssystem3_lcd.data[ssystem3_lcd.count/8]&=~(1<<(ssystem3_lcd.count&7));
23    if (data) ssystem3_lcd.data[ssystem3_lcd.count/8]|=1<<(ssystem3_lcd.count&7);
24    if (ssystem3_lcd.count+1==40) {
16   ssystem3_state *state = machine->driver_data<ssystem3_state>();
17  if (clock&&!state->lcd.clock) {
18    state->lcd.data[state->lcd.count/8]&=~(1<<(state->lcd.count&7));
19    if (data) state->lcd.data[state->lcd.count/8]|=1<<(state->lcd.count&7);
20    if (state->lcd.count+1==40) {
2521      logerror("%.4x lcd %02x%02x%02x%02x%02x\n",(int)cpu_get_pc(machine->device("maincpu")),
26          ssystem3_lcd.data[0], ssystem3_lcd.data[1], ssystem3_lcd.data[2], ssystem3_lcd.data[3], ssystem3_lcd.data[4]);
22          state->lcd.data[0], state->lcd.data[1], state->lcd.data[2], state->lcd.data[3], state->lcd.data[4]);
2723    }
28    ssystem3_lcd.count=(ssystem3_lcd.count+1)%40;
24    state->lcd.count=(state->lcd.count+1)%40;
2925  }
30  ssystem3_lcd.clock=clock;
26  state->lcd.clock=clock;
3127}
3228
3329
r9667r9668
190186
191187VIDEO_UPDATE( ssystem3 )
192188{
189   ssystem3_state *state = screen->machine->driver_data<ssystem3_state>();
193190   int i;
194191
195192   for (i=0; i<4; i++) {
196      ssystem3_draw_7segment(bitmap, ssystem3_lcd.data[1+i], ssystem3_led_pos[i].x, ssystem3_led_pos[i].y);
193      ssystem3_draw_7segment(bitmap, state->lcd.data[1+i], ssystem3_led_pos[i].x, ssystem3_led_pos[i].y);
197194   }
198195
199   ssystem3_draw_led(bitmap, ssystem3_lcd.data[0]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '0'); //?
200   ssystem3_draw_led(bitmap, ssystem3_lcd.data[0]&2?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '5');
201   ssystem3_draw_led(bitmap, ssystem3_lcd.data[0]&4?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '7');
202   ssystem3_draw_led(bitmap, ssystem3_lcd.data[0]&8?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, 'b');
203   ssystem3_draw_led(bitmap, ssystem3_lcd.data[0]&0x10?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '9');
204   ssystem3_draw_led(bitmap, ssystem3_lcd.data[0]&0x20?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '8');
205   ssystem3_draw_led(bitmap, ssystem3_lcd.data[0]&0x40?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, 'c');
206   ssystem3_draw_led(bitmap, ssystem3_lcd.data[0]&0x80?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '6');
207   ssystem3_draw_led(bitmap, ssystem3_lcd.data[1]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '2');
208   ssystem3_draw_led(bitmap, ssystem3_lcd.data[2]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '1'); //?
209   ssystem3_draw_led(bitmap, ssystem3_lcd.data[3]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '3');
210   ssystem3_draw_led(bitmap, ssystem3_lcd.data[4]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '4');
196   ssystem3_draw_led(bitmap, state->lcd.data[0]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '0'); //?
197   ssystem3_draw_led(bitmap, state->lcd.data[0]&2?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '5');
198   ssystem3_draw_led(bitmap, state->lcd.data[0]&4?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '7');
199   ssystem3_draw_led(bitmap, state->lcd.data[0]&8?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, 'b');
200   ssystem3_draw_led(bitmap, state->lcd.data[0]&0x10?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '9');
201   ssystem3_draw_led(bitmap, state->lcd.data[0]&0x20?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '8');
202   ssystem3_draw_led(bitmap, state->lcd.data[0]&0x40?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, 'c');
203   ssystem3_draw_led(bitmap, state->lcd.data[0]&0x80?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '6');
204   ssystem3_draw_led(bitmap, state->lcd.data[1]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '2');
205   ssystem3_draw_led(bitmap, state->lcd.data[2]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '1'); //?
206   ssystem3_draw_led(bitmap, state->lcd.data[3]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '3');
207   ssystem3_draw_led(bitmap, state->lcd.data[4]&1?1:0, ssystem3_led_pos[4].x, ssystem3_led_pos[4].y, '4');
211208
212   if (input_port_read(screen->machine, "Configuration")&1) { // playfield(optional device)
209   if (input_port_read(screen->machine, "Configuration")&1) { // state->playfield(optional device)
213210     const int lcd_signs_on[]={
214211       0, // empty
215212       1, // bauer
r9667r9668
226223         int figure, black;
227224         int xp=263+x*22;
228225         int yp=55+(y^7)*28;
229         ssystem3_playfield_getfigure(x, y, &figure, &black);
226         ssystem3_playfield_getfigure(screen->machine, x, y, &figure, &black);
230227         ssystem3_draw_led(bitmap, lcd_signs_on[figure]&1?1:0, xp, yp, '6');
231228         ssystem3_draw_led(bitmap, lcd_signs_on[figure]&2?1:0, xp, yp, '8');
232229         ssystem3_draw_led(bitmap, lcd_signs_on[figure]&4?1:0, xp, yp, '9');
src/mess/video/odyssey2.c
r9667r9668
123123    { 0x00,0x00,0x00,0x10,0x38,0xFF,0x7E,0x00 }
124124};
125125
126static union {
127    UINT8 reg[0x100];
128    struct {
129   struct {
130       UINT8 y,x,color,res;
131   } sprites[4];
132   struct {
133       UINT8 y,x,ptr,color;
134   } foreground[12];
135   struct {
136       struct {
137      UINT8 y,x,ptr,color;
138       } single[4];
139   } quad[4];
140   UINT8 shape[4][8];
141   UINT8 control;
142   UINT8 status;
143   UINT8 collision;
144   UINT8 color;
145   UINT8 y;
146   UINT8 x;
147   UINT8 res;
148   UINT8 shift1,shift2,shift3;
149   UINT8 sound;
150   UINT8 res2[5+0x10];
151   UINT8 hgrid[2][0x10];
152   UINT8 vgrid[0x10];
153    } s;
154} o2_vdc= { { 0 } };
155126
156static UINT32      o2_snd_shift[2];
157static UINT8      x_beam_pos;
158static UINT8      y_beam_pos;
159static UINT8      control_status;
160static UINT8      collision_status;
161static int         iff;
162static emu_timer   *i824x_line_timer;
163static emu_timer   *i824x_hblank_timer;
164static bitmap_t      *tmp_bitmap;
165static int         start_vpos;
166static int         start_vblank;
167static UINT8      lum;      /* Output of P1 bit 7 influences the intensity of the background and grid colours */
168static UINT16      lfsr;
169127
170static sound_stream *odyssey2_sh_channel;
171128
172
173129PALETTE_INIT( odyssey2 )
174130{
175131   int i;
r9667r9668
182138
183139READ8_HANDLER( odyssey2_video_r )
184140{
141   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
185142    UINT8 data = 0;
186143
187144    switch (offset)
188145    {
189146        case 0xa1:
190         data = control_status;
191         iff = 0;
147         data = state->control_status;
148         state->iff = 0;
192149         cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE);
193         control_status &= ~ 0x08;
150         state->control_status &= ~ 0x08;
194151         if ( space->machine->primary_screen->hpos() < I824X_START_ACTIVE_SCAN || space->machine->primary_screen->hpos() > I824X_END_ACTIVE_SCAN )
195152         {
196153            data |= 1;
r9667r9668
199156            break;
200157
201158        case 0xa2:
202         data = collision_status;
203         collision_status = 0;
159         data = state->collision_status;
160         state->collision_status = 0;
204161
205162            break;
206163
207164        case 0xa4:
208165
209            if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY))
210                y_beam_pos = space->machine->primary_screen->vpos() - start_vpos;
166            if ((state->o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY))
167                state->y_beam_pos = space->machine->primary_screen->vpos() - state->start_vpos;
211168
212            data = y_beam_pos;
169            data = state->y_beam_pos;
213170
214171            break;
215172
216173
217174        case 0xa5:
218175
219            if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY))
176            if ((state->o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY))
220177         {
221                x_beam_pos = space->machine->primary_screen->hpos();
222            if ( x_beam_pos < I824X_START_ACTIVE_SCAN )
178                state->x_beam_pos = space->machine->primary_screen->hpos();
179            if ( state->x_beam_pos < I824X_START_ACTIVE_SCAN )
223180            {
224               x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN + I824X_LINE_CLOCKS;
181               state->x_beam_pos = state->x_beam_pos - I824X_START_ACTIVE_SCAN + I824X_LINE_CLOCKS;
225182            }
226183            else
227184            {
228               x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN;
185               state->x_beam_pos = state->x_beam_pos - I824X_START_ACTIVE_SCAN;
229186            }
230187         }
231188
232            data = x_beam_pos;
189            data = state->x_beam_pos;
233190
234191            break;
235192
236193        default:
237            data = o2_vdc.reg[offset];
194            data = state->o2_vdc.reg[offset];
238195    }
239196
240197    return data;
r9667r9668
242199
243200WRITE8_HANDLER( odyssey2_video_w )
244201{
202   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
245203   /* Update the sound */
246204   if( offset >= 0xa7 && offset <= 0xaa )
247      stream_update( odyssey2_sh_channel );
205      stream_update( state->sh_channel );
248206
249207    if (offset == 0xa0)
250208    {
251        if (    o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY
209        if (    state->o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY
252210             && !(data & VDC_CONTROL_REG_STROBE_XY))
253211        {
254212            /* Toggling strobe bit, tuck away values */
255            x_beam_pos = space->machine->primary_screen->hpos();
256         if ( x_beam_pos < I824X_START_ACTIVE_SCAN )
213            state->x_beam_pos = space->machine->primary_screen->hpos();
214         if ( state->x_beam_pos < I824X_START_ACTIVE_SCAN )
257215         {
258            x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN + 228;
216            state->x_beam_pos = state->x_beam_pos - I824X_START_ACTIVE_SCAN + 228;
259217         }
260218         else
261219         {
262            x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN;
220            state->x_beam_pos = state->x_beam_pos - I824X_START_ACTIVE_SCAN;
263221         }
264222
265            y_beam_pos = space->machine->primary_screen->vpos() - start_vpos;
223            state->y_beam_pos = space->machine->primary_screen->vpos() - state->start_vpos;
266224
267225            /* This is wrong but more games work with it, TODO: Figure
268226             * out correct change.  Maybe update the screen here??
r9667r9668
274232        }
275233    }
276234
277    o2_vdc.reg[offset] = data;
235    state->o2_vdc.reg[offset] = data;
278236}
279237
280238WRITE8_HANDLER ( odyssey2_lum_w )
281239{
282   lum = data;
240   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
241   state->lum = data;
283242}
284243
285244READ8_HANDLER( odyssey2_t1_r )
286245{
287   if ( space->machine->primary_screen->vpos() > start_vpos && space->machine->primary_screen->vpos() < start_vblank )
246   odyssey2_state *state = space->machine->driver_data<odyssey2_state>();
247   if ( space->machine->primary_screen->vpos() > state->start_vpos && space->machine->primary_screen->vpos() < state->start_vblank )
288248   {
289249      if ( space->machine->primary_screen->hpos() >= I824X_START_ACTIVE_SCAN && space->machine->primary_screen->hpos() < I824X_END_ACTIVE_SCAN )
290250      {
r9667r9668
296256
297257static TIMER_CALLBACK( i824x_scanline_callback )
298258{
259   odyssey2_state *state = machine->driver_data<odyssey2_state>();
299260   UINT8   collision_map[160];
300261   int      vpos = machine->primary_screen->vpos();
301262
302   if ( vpos < start_vpos )
263   if ( vpos < state->start_vpos )
303264      return;
304265
305   if ( vpos == start_vpos )
266   if ( vpos == state->start_vpos )
306267   {
307      control_status &= ~0x08;
268      state->control_status &= ~0x08;
308269   }
309270
310   if ( vpos < start_vblank )
271   if ( vpos < state->start_vblank )
311272   {
312273      rectangle rect;
313274      //int   sprite_width[4] = { 8, 8, 8, 8 };
314275      int i;
315276
316      control_status &= ~ 0x01;
277      state->control_status &= ~ 0x01;
317278
318279      /* Draw a line */
319280      rect.min_y = rect.max_y = vpos;
320281      rect.min_x = I824X_START_ACTIVE_SCAN;
321282      rect.max_x = I824X_END_ACTIVE_SCAN - 1;
322      bitmap_fill( tmp_bitmap, &rect , ( (o2_vdc.s.color >> 3) & 0x7 ) | ( ( lum << 3 ) ^ 0x08 ));
283      bitmap_fill( state->tmp_bitmap, &rect , ( (state->o2_vdc.s.color >> 3) & 0x7 ) | ( ( state->lum << 3 ) ^ 0x08 ));
323284
324285      /* Clear collision map */
325286      memset( collision_map, 0, sizeof( collision_map ) );
326287
327288      /* Display grid if enabled */
328      if ( o2_vdc.s.control & 0x08 )
289      if ( state->o2_vdc.s.control & 0x08 )
329290      {
330         UINT16   color = ( o2_vdc.s.color & 7 ) | ( ( o2_vdc.s.color >> 3 ) & 0x08 ) | ( ( lum << 3 ) ^ 0x08 );
291         UINT16   color = ( state->o2_vdc.s.color & 7 ) | ( ( state->o2_vdc.s.color >> 3 ) & 0x08 ) | ( ( state->lum << 3 ) ^ 0x08 );
331292         int      x_grid_offset = 8;
332293         int    y_grid_offset = 24;
333294         int      width = 16;
334295         int      height = 24;
335         int      w = ( o2_vdc.s.control & 0x80 ) ? width : 2;
296         int      w = ( state->o2_vdc.s.control & 0x80 ) ? width : 2;
336297         int      j, k, y;
337298
338299         /* Draw horizontal part of grid */
339300         for ( j = 1, y = 0; y < 9; y++, j <<= 1 )
340301         {
341            if ( y_grid_offset + y * height <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y_grid_offset + y * height + 3 )
302            if ( y_grid_offset + y * height <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y_grid_offset + y * height + 3 )
342303            {
343304               for ( i = 0; i < 9; i++ )
344305               {
345                  if ( ( o2_vdc.s.hgrid[0][i] & j ) || ( o2_vdc.s.hgrid[1][i] & ( j >> 8 ) ) )
306                  if ( ( state->o2_vdc.s.hgrid[0][i] & j ) || ( state->o2_vdc.s.hgrid[1][i] & ( j >> 8 ) ) )
346307                  {
347308                     for ( k = 0; k < width + 2; k++ )
348309                     {
349310                        int px = x_grid_offset + i * width + k;
350311                        collision_map[ px ] |= COLLISION_HORIZ_GRID_DOTS;
351                        *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color;
312                        *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color;
352313                     }
353314                  }
354315               }
r9667r9668
358319         /* Draw vertical part of grid */
359320         for( j = 1, y = 0; y < 8; y++, j <<= 1 )
360321         {
361            if ( y_grid_offset + y * height <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y_grid_offset + ( y + 1 ) * height )
322            if ( y_grid_offset + y * height <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y_grid_offset + ( y + 1 ) * height )
362323            {
363324               for ( i = 0; i < 10; i++ )
364325               {
365                  if ( o2_vdc.s.vgrid[i] & j )
326                  if ( state->o2_vdc.s.vgrid[i] & j )
366327                  {
367328                     for ( k = 0; k < w; k++ )
368329                     {
369330                        int px = x_grid_offset + i * width + k;
370331
371332                        /* Check if we collide with an already drawn source object */
372                        if ( collision_map[ px ] & o2_vdc.s.collision )
333                        if ( collision_map[ px ] & state->o2_vdc.s.collision )
373334                        {
374                           collision_status |= COLLISION_VERTICAL_GRID;
335                           state->collision_status |= COLLISION_VERTICAL_GRID;
375336                        }
376337                        /* Check if an already drawn object would collide with us */
377                        if ( COLLISION_VERTICAL_GRID & o2_vdc.s.collision && collision_map[ px ] )
338                        if ( COLLISION_VERTICAL_GRID & state->o2_vdc.s.collision && collision_map[ px ] )
378339                        {
379                           collision_status |= collision_map[ px ];
340                           state->collision_status |= collision_map[ px ];
380341                        }
381342                        collision_map[ px ] |= COLLISION_VERTICAL_GRID;
382                        *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color;
343                        *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color;
383344                     }
384345                  }
385346               }
r9667r9668
388349      }
389350
390351      /* Display objects if enabled */
391      if ( o2_vdc.s.control & 0x20 )
352      if ( state->o2_vdc.s.control & 0x20 )
392353      {
393354         /* Regular foreground objects */
394         for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.foreground ); i++ )
355         for ( i = 0; i < ARRAY_LENGTH( state->o2_vdc.s.foreground ); i++ )
395356         {
396            int   y = o2_vdc.s.foreground[i].y;
397            int   height = 8 - ( ( ( y >> 1 ) + o2_vdc.s.foreground[i].ptr ) & 7 );
357            int   y = state->o2_vdc.s.foreground[i].y;
358            int   height = 8 - ( ( ( y >> 1 ) + state->o2_vdc.s.foreground[i].ptr ) & 7 );
398359
399            if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 )
360            if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + height * 2 )
400361            {
401               UINT16   color = 16 + ( ( o2_vdc.s.foreground[i].color & 0x0E ) >> 1 );
402               int      offset = ( o2_vdc.s.foreground[i].ptr | ( ( o2_vdc.s.foreground[i].color & 0x01 ) << 8 ) ) + ( y >> 1 ) + ( ( vpos - start_vpos - y ) >> 1 );
362               UINT16   color = 16 + ( ( state->o2_vdc.s.foreground[i].color & 0x0E ) >> 1 );
363               int      offset = ( state->o2_vdc.s.foreground[i].ptr | ( ( state->o2_vdc.s.foreground[i].color & 0x01 ) << 8 ) ) + ( y >> 1 ) + ( ( vpos - state->start_vpos - y ) >> 1 );
403364               UINT8   chr = ((char*)o2_shape)[ offset & 0x1FF ];
404               int      x = o2_vdc.s.foreground[i].x;
365               int      x = state->o2_vdc.s.foreground[i].x;
405366               UINT8   m;
406367
407368               for ( m = 0x80; m > 0; m >>= 1, x++ )
r9667r9668
411372                     if ( x >= 0 && x < 160 )
412373                     {
413374                        /* Check if we collide with an already drawn source object */
414                        if ( collision_map[ x ] & o2_vdc.s.collision )
375                        if ( collision_map[ x ] & state->o2_vdc.s.collision )
415376                        {
416                           collision_status |= COLLISION_CHARACTERS;
377                           state->collision_status |= COLLISION_CHARACTERS;
417378                        }
418379                        /* Check if an already drawn object would collide with us */
419                        if ( COLLISION_CHARACTERS & o2_vdc.s.collision && collision_map[ x ] )
380                        if ( COLLISION_CHARACTERS & state->o2_vdc.s.collision && collision_map[ x ] )
420381                        {
421                           collision_status |= collision_map[ x ];
382                           state->collision_status |= collision_map[ x ];
422383                        }
423384                        collision_map[ x ] |= COLLISION_CHARACTERS;
424                        *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
385                        *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
425386                     }
426387                  }
427388               }
r9667r9668
429390         }
430391
431392         /* Quad objects */
432         for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.quad ); i++ )
393         for ( i = 0; i < ARRAY_LENGTH( state->o2_vdc.s.quad ); i++ )
433394         {
434            int y = o2_vdc.s.quad[i].single[0].y;
395            int y = state->o2_vdc.s.quad[i].single[0].y;
435396            int height = 8;
436397
437            if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 )
398            if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + height * 2 )
438399            {
439               int   x = o2_vdc.s.quad[i].single[0].x;
400               int   x = state->o2_vdc.s.quad[i].single[0].x;
440401               int j;
441402
442               for ( j = 0; j < ARRAY_LENGTH( o2_vdc.s.quad[0].single ); j++, x += 8 )
403               for ( j = 0; j < ARRAY_LENGTH( state->o2_vdc.s.quad[0].single ); j++, x += 8 )
443404               {
444                  int      char_height = 8 - ( ( ( y >> 1 ) + o2_vdc.s.quad[i].single[j].ptr ) & 7 );
445                  if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + char_height * 2 )
405                  int      char_height = 8 - ( ( ( y >> 1 ) + state->o2_vdc.s.quad[i].single[j].ptr ) & 7 );
406                  if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + char_height * 2 )
446407                  {
447                     UINT16 color = 16 + ( ( o2_vdc.s.quad[i].single[j].color & 0x0E ) >> 1 );
448                     int   offset = ( o2_vdc.s.quad[i].single[j].ptr | ( ( o2_vdc.s.quad[i].single[j].color & 0x01 ) << 8 ) ) + ( y >> 1 ) + ( ( vpos - start_vpos - y ) >> 1 );
408                     UINT16 color = 16 + ( ( state->o2_vdc.s.quad[i].single[j].color & 0x0E ) >> 1 );
409                     int   offset = ( state->o2_vdc.s.quad[i].single[j].ptr | ( ( state->o2_vdc.s.quad[i].single[j].color & 0x01 ) << 8 ) ) + ( y >> 1 ) + ( ( vpos - state->start_vpos - y ) >> 1 );
449410                     UINT8   chr = ((char*)o2_shape)[ offset & 0x1FF ];
450411                     UINT8   m;
451412                     for ( m = 0x80; m > 0; m >>= 1, x++ )
r9667r9668
455416                           if ( x >= 0 && x < 160 )
456417                           {
457418                              /* Check if we collide with an already drawn source object */
458                              if ( collision_map[ x ] & o2_vdc.s.collision )
419                              if ( collision_map[ x ] & state->o2_vdc.s.collision )
459420                              {
460                                 collision_status |= COLLISION_CHARACTERS;
421                                 state->collision_status |= COLLISION_CHARACTERS;
461422                              }
462423                              /* Check if an already drawn object would collide with us */
463                              if ( COLLISION_CHARACTERS & o2_vdc.s.collision && collision_map[ x ] )
424                              if ( COLLISION_CHARACTERS & state->o2_vdc.s.collision && collision_map[ x ] )
464425                              {
465                                 collision_status |= collision_map[ x ];
426                                 state->collision_status |= collision_map[ x ];
466427                              }
467428                              collision_map[ x ] |= COLLISION_CHARACTERS;
468                              *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
429                              *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
469430                           }
470431                        }
471432                     }
r9667r9668
479440         }
480441
481442         /* Sprites */
482         for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.sprites ); i++ )
443         for ( i = 0; i < ARRAY_LENGTH( state->o2_vdc.s.sprites ); i++ )
483444         {
484            int y = o2_vdc.s.sprites[i].y;
445            int y = state->o2_vdc.s.sprites[i].y;
485446            int height = 8;
486            if ( o2_vdc.s.sprites[i].color & 4 )
447            if ( state->o2_vdc.s.sprites[i].color & 4 )
487448            {
488449               /* Zoomed sprite */
489450               //sprite_width[i] = 16;
490               if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 4 )
451               if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + height * 4 )
491452               {
492                  UINT16 color = 16 + ( ( o2_vdc.s.sprites[i].color >> 3 ) & 0x07 );
493                  UINT8   chr = o2_vdc.s.shape[i][ ( ( vpos - start_vpos - y ) >> 2 ) ];
494                  int      x = o2_vdc.s.sprites[i].x;
453                  UINT16 color = 16 + ( ( state->o2_vdc.s.sprites[i].color >> 3 ) & 0x07 );
454                  UINT8   chr = state->o2_vdc.s.shape[i][ ( ( vpos - state->start_vpos - y ) >> 2 ) ];
455                  int      x = state->o2_vdc.s.sprites[i].x;
495456                  UINT8   m;
496457
497458                  for ( m = 0x01; m > 0; m <<= 1, x += 2 )
r9667r9668
501462                        if ( x >= 0 && x < 160 )
502463                        {
503464                           /* Check if we collide with an already drawn source object */
504                           if ( collision_map[ x ] & o2_vdc.s.collision )
465                           if ( collision_map[ x ] & state->o2_vdc.s.collision )
505466                           {
506                              collision_status |= ( 1 << i );
467                              state->collision_status |= ( 1 << i );
507468                           }
508469                           /* Check if an already drawn object would collide with us */
509                           if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] )
470                           if ( ( 1 << i ) & state->o2_vdc.s.collision && collision_map[ x ] )
510471                           {
511                              collision_status |= collision_map[ x ];
472                              state->collision_status |= collision_map[ x ];
512473                           }
513474                           collision_map[ x ] |= ( 1 << i );
514                           *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
475                           *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
515476                        }
516477                        if ( x >= -1 && x < 159 )
517478                        {
518479                           /* Check if we collide with an already drawn source object */
519                           if ( collision_map[ x ] & o2_vdc.s.collision )
480                           if ( collision_map[ x ] & state->o2_vdc.s.collision )
520481                           {
521                              collision_status |= ( 1 << i );
482                              state->collision_status |= ( 1 << i );
522483                           }
523484                           /* Check if an already drawn object would collide with us */
524                           if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] )
485                           if ( ( 1 << i ) & state->o2_vdc.s.collision && collision_map[ x ] )
525486                           {
526                              collision_status |= collision_map[ x ];
487                              state->collision_status |= collision_map[ x ];
527488                           }
528489                           collision_map[ x ] |= ( 1 << i );
529                           *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x + 1 ) = color;
490                           *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x + 1 ) = color;
530491                        }
531492                     }
532493                  }
r9667r9668
535496            else
536497            {
537498               /* Regular sprite */
538               if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 )
499               if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + height * 2 )
539500               {
540                  UINT16 color = 16 + ( ( o2_vdc.s.sprites[i].color >> 3 ) & 0x07 );
541                  UINT8   chr = o2_vdc.s.shape[i][ ( ( vpos - start_vpos - y ) >> 1 ) ];
542                  int      x = o2_vdc.s.sprites[i].x;
501                  UINT16 color = 16 + ( ( state->o2_vdc.s.sprites[i].color >> 3 ) & 0x07 );
502                  UINT8   chr = state->o2_vdc.s.shape[i][ ( ( vpos - state->start_vpos - y ) >> 1 ) ];
503                  int      x = state->o2_vdc.s.sprites[i].x;
543504                  UINT8   m;
544505
545506                  for ( m = 0x01; m > 0; m <<= 1, x++ )
r9667r9668
549510                        if ( x >= 0 && x < 160 )
550511                        {
551512                           /* Check if we collide with an already drawn source object */
552                           if ( collision_map[ x ] & o2_vdc.s.collision )
513                           if ( collision_map[ x ] & state->o2_vdc.s.collision )
553514                           {
554                              collision_status |= ( 1 << i );
515                              state->collision_status |= ( 1 << i );
555516                           }
556517                           /* Check if an already drawn object would collide with us */
557                           if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] )
518                           if ( ( 1 << i ) & state->o2_vdc.s.collision && collision_map[ x ] )
558519                           {
559                              collision_status |= collision_map[ x ];
520                              state->collision_status |= collision_map[ x ];
560521                           }
561522                           collision_map[ x ] |= ( 1 << i );
562                           *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
523                           *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color;
563524                        }
564525                     }
565526                  }
r9667r9668
570531   }
571532
572533   /* Check for start of VBlank */
573   if ( vpos == start_vblank )
534   if ( vpos == state->start_vblank )
574535   {
575      control_status |= 0x08;
576      if ( ! iff )
536      state->control_status |= 0x08;
537      if ( ! state->iff )
577538      {
578539         cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE);
579         iff = 1;
540         state->iff = 1;
580541      }
581542   }
582543}
583544
584545static TIMER_CALLBACK( i824x_hblank_callback )
585546{
547   odyssey2_state *state = machine->driver_data<odyssey2_state>();
586548   int vpos = machine->primary_screen->vpos();
587549
588   if ( vpos < start_vpos - 1 )
550   if ( vpos < state->start_vpos - 1 )
589551      return;
590552
591   if ( vpos < start_vblank - 1 )
553   if ( vpos < state->start_vblank - 1 )
592554   {
593      control_status |= 0x01;
555      state->control_status |= 0x01;
594556   }
595557}
596558
r9667r9668
602564
603565VIDEO_START( odyssey2 )
604566{
567   odyssey2_state *state = machine->driver_data<odyssey2_state>();
605568   screen_device *screen = screen_first(*machine);
606569   int width = screen->width();
607570   int height = screen->height();
608571
609   memset(o2_vdc.reg, 0, 0x100);
572   memset(state->o2_vdc.reg, 0, 0x100);
610573
611   o2_snd_shift[0] = o2_snd_shift[1] = 0;
612   x_beam_pos = 0;
613   y_beam_pos = 0;
614   control_status = 0;
615   collision_status = 0;
616   iff = 0;
617   start_vpos = 0;
618   start_vblank = 0;
619   lum = 0;
620   lfsr = 0;
574   state->o2_snd_shift[0] = state->o2_snd_shift[1] = 0;
575   state->x_beam_pos = 0;
576   state->y_beam_pos = 0;
577   state->control_status = 0;
578   state->collision_status = 0;
579   state->iff = 0;
580   state->start_vpos = 0;
581   state->start_vblank = 0;
582   state->lum = 0;
583   state->lfsr = 0;
621584
622   o2_snd_shift[0] = machine->sample_rate / 983;
623   o2_snd_shift[1] = machine->sample_rate / 3933;
585   state->o2_snd_shift[0] = machine->sample_rate / 983;
586   state->o2_snd_shift[1] = machine->sample_rate / 3933;
624587
625   start_vpos = I824X_START_Y;
626   start_vblank = I824X_START_Y + I824X_SCREEN_HEIGHT;
627   control_status = 0;
628   iff = 0;
588   state->start_vpos = I824X_START_Y;
589   state->start_vblank = I824X_START_Y + I824X_SCREEN_HEIGHT;
590   state->control_status = 0;
591   state->iff = 0;
629592
630   tmp_bitmap = auto_bitmap_alloc( machine, width, height, screen->format() );
593   state->tmp_bitmap = auto_bitmap_alloc( machine, width, height, screen->format() );
631594
632   i824x_line_timer = timer_alloc(machine,  i824x_scanline_callback, NULL );
633   timer_adjust_periodic( i824x_line_timer, machine->primary_screen->time_until_pos(1, I824X_START_ACTIVE_SCAN ), 0,  machine->primary_screen->scan_period() );
595   state->i824x_line_timer = timer_alloc(machine,  i824x_scanline_callback, NULL );
596   timer_adjust_periodic( state->i824x_line_timer, machine->primary_screen->time_until_pos(1, I824X_START_ACTIVE_SCAN ), 0,  machine->primary_screen->scan_period() );
634597
635   i824x_hblank_timer = timer_alloc(machine,  i824x_hblank_callback, NULL );
636   timer_adjust_periodic( i824x_hblank_timer, machine->primary_screen->time_until_pos(1, I824X_END_ACTIVE_SCAN + 18 ), 0, machine->primary_screen->scan_period() );
598   state->i824x_hblank_timer = timer_alloc(machine,  i824x_hblank_callback, NULL );
599   timer_adjust_periodic( state->i824x_hblank_timer, machine->primary_screen->time_until_pos(1, I824X_END_ACTIVE_SCAN + 18 ), 0, machine->primary_screen->scan_period() );
637600}
638601
639602/***************************************************************************
r9667r9668
644607
645608VIDEO_UPDATE( odyssey2 )
646609{
647   copybitmap( bitmap, tmp_bitmap, 0, 0, 0, 0, cliprect );
610   odyssey2_state *state = screen->machine->driver_data<odyssey2_state>();
611   copybitmap( bitmap, state->tmp_bitmap, 0, 0, 0, 0, cliprect );
648612
649613   return 0;
650614}
651615
652616static DEVICE_START( odyssey2_sound )
653617{
654   odyssey2_sh_channel = stream_create(device, 0, 1, device->clock()/(I824X_LINE_CLOCKS*4), 0, odyssey2_sh_update );
618   odyssey2_state *state = device->machine->driver_data<odyssey2_state>();
619   state->sh_channel = stream_create(device, 0, 1, device->clock()/(I824X_LINE_CLOCKS*4), 0, odyssey2_sh_update );
655620}
656621
657622
r9667r9668
670635
671636STREAM_UPDATE( odyssey2_sh_update )
672637{
673   static UINT32 signal;
674   static UINT16 count = 0;
638   odyssey2_state *state = device->machine->driver_data<odyssey2_state>();
639   UINT32 signal;
675640   int ii;
676641   int period;
677642   stream_sample_t *buffer = outputs[0];
678643
679644   /* Generate the signal */
680   signal = o2_vdc.s.shift3 | (o2_vdc.s.shift2 << 8) | (o2_vdc.s.shift1 << 16);
645   signal = state->o2_vdc.s.shift3 | (state->o2_vdc.s.shift2 << 8) | (state->o2_vdc.s.shift1 << 16);
681646
682   if( o2_vdc.s.sound & 0x80 )   /* Sound is enabled */
647   if( state->o2_vdc.s.sound & 0x80 )   /* Sound is enabled */
683648   {
684649      for( ii = 0; ii < samples; ii++, buffer++ )
685650      {
686651         *buffer = 0;
687652         *buffer = signal & 0x1;
688         period = (o2_vdc.s.sound & 0x20) ? 1 : 4;
689         if( ++count >= period )
653         period = (state->o2_vdc.s.sound & 0x20) ? 1 : 4;
654         if( ++state->sh_count >= period )
690655         {
691            count = 0;
656            state->sh_count = 0;
692657            signal >>= 1;
693658            /* Loop sound */
694            if( o2_vdc.s.sound & 0x40 )
659            if( state->o2_vdc.s.sound & 0x40 )
695660            {
696661               signal |= *buffer << 23;
697662            }
698663            /* Noise poly is : L=16 W=2 10000000000100001 */
699            lfsr = ( lfsr >> 1 ) | ( ( ( lfsr & 0x01 ) ^ ( ( lfsr & 0x800 ) >> 11 ) ) << 15 );
700            if ( ! lfsr )
664            state->lfsr = ( state->lfsr >> 1 ) | ( ( ( state->lfsr & 0x01 ) ^ ( ( state->lfsr & 0x800 ) >> 11 ) ) << 15 );
665            if ( ! state->lfsr )
701666            {
702               lfsr = 0xFFFF;
667               state->lfsr = 0xFFFF;
703668            }
704669            /* Check if noise should be applied */
705            if ( o2_vdc.s.sound & 0x10 )
670            if ( state->o2_vdc.s.sound & 0x10 )
706671            {
707               *buffer |= ( lfsr & 0x01 );
672               *buffer |= ( state->lfsr & 0x01 );
708673            }
709            o2_vdc.s.shift3 = signal & 0xFF;
710            o2_vdc.s.shift2 = ( signal >> 8 ) & 0xFF;
711            o2_vdc.s.shift1 = ( signal >> 16 ) & 0xFF;
674            state->o2_vdc.s.shift3 = signal & 0xFF;
675            state->o2_vdc.s.shift2 = ( signal >> 8 ) & 0xFF;
676            state->o2_vdc.s.shift1 = ( signal >> 16 ) & 0xFF;
712677         }
713678
714679         /* Throw an interrupt if enabled */
715         if( o2_vdc.s.control & 0x4 )
680         if( state->o2_vdc.s.control & 0x4 )
716681         {
717682            cputag_set_input_line(device->machine, "maincpu", 1, HOLD_LINE); /* Is this right? */
718683         }
719684
720685         /* Adjust volume */
721         *buffer *= o2_vdc.s.sound & 0xf;
686         *buffer *= state->o2_vdc.s.sound & 0xf;
722687         /* Pump the volume up */
723688         *buffer <<= 10;
724689      }
r9667r9668
736701 */
737702
738703#ifdef UNUSED_FUNCTION
739static struct {
740   UINT8   X;
741   UINT8   Y;
742   UINT8   Y0;
743   UINT8   R;
744   UINT8   M;
745   UINT8   TA;
746   UINT8   TB;
747   UINT8   busy;
748   UINT8   ram[1024];
749} ef9341;
750
751INLINE UINT16 ef9341_get_c_addr( void )
704INLINE UINT16 ef9341_get_c_addr( odyssey2_state *state )
752705{
753   if ( ( ef9341.Y & 0x0C ) == 0x0C )
706   if ( ( state->ef9341.Y & 0x0C ) == 0x0C )
754707   {
755      return 0x318 | ( ( ef9341.X & 0x38 ) << 2 ) | ( ef9341.X & 0x07 );
708      return 0x318 | ( ( state->ef9341.X & 0x38 ) << 2 ) | ( state->ef9341.X & 0x07 );
756709   }
757   if ( ef9341.X & 0x20 )
710   if ( state->ef9341.X & 0x20 )
758711   {
759      return 0x300 | ( ( ef9341.Y & 0x07 ) << 5 ) | ( ef9341.Y & 0x18 ) | ( ef9341.X & 0x07 );
712      return 0x300 | ( ( state->ef9341.Y & 0x07 ) << 5 ) | ( state->ef9341.Y & 0x18 ) | ( state->ef9341.X & 0x07 );
760713   }
761   return ( ef9341.Y << 5 ) | ef9341.X;
714   return ( state->ef9341.Y << 5 ) | state->ef9341.X;
762715}
763716
764INLINE void ef9341_inc_c( void )
717INLINE void ef9341_inc_c( odyssey2_state *state )
765718{
766   ef9341.X++;
767   if ( ef9341.X >= 40 )
719   state->ef9341.X++;
720   if ( state->ef9341.X >= 40 )
768721   {
769      ef9341.Y = ( ef9341.Y + 1 ) % 24;
722      state->ef9341.Y = ( state->ef9341.Y + 1 ) % 24;
770723   }
771724}
772725
773void odyssey2_ef9341_w( int command, int b, UINT8 data )
726void odyssey2_ef9341_w( running_machine *machine, int command, int b, UINT8 data )
774727{
728   odyssey2_state *state = machine->driver_data<odyssey2_state>();
775729   logerror("ef9341 %s write, t%s, data %02X\n", command ? "command" : "data", b ? "B" : "A", data );
776730
777731   if ( command )
778732   {
779733      if ( b )
780734      {
781         ef9341.TB = data;
782         ef9341.busy = 0x80;
783         switch( ef9341.TB & 0xE0 )
735         state->ef9341.TB = data;
736         state->ef9341.busy = 0x80;
737         switch( state->ef9341.TB & 0xE0 )
784738         {
785739         case 0x00:   /* Begin row */
786            ef9341.X = 0;
787            ef9341.Y = ef9341.TA & 0x1F;
740            state->ef9341.X = 0;
741            state->ef9341.Y = state->ef9341.TA & 0x1F;
788742            break;
789743         case 0x20:   /* Load Y */
790            ef9341.Y = ef9341.TA & 0x1F;
744            state->ef9341.Y = state->ef9341.TA & 0x1F;
791745            break;
792746         case 0x40:   /* Load X */
793            ef9341.X = ef9341.TA & 0x3F;
747            state->ef9341.X = state->ef9341.TA & 0x3F;
794748            break;
795749         case 0x60:   /* INC C */
796            ef9341_inc_c();
750            ef9341_inc_c(state);
797751            break;
798752         case 0x80:   /* Load M */
799            ef9341.M = ef9341.TA;
753            state->ef9341.M = state->ef9341.TA;
800754            break;
801755         case 0xA0:   /* Load R */
802            ef9341.R = ef9341.TA;
756            state->ef9341.R = state->ef9341.TA;
803757            break;
804758         case 0xC0:   /* Load Y0 */
805            ef9341.Y0 = ef9341.TA & 0x3F;
759            state->ef9341.Y0 = state->ef9341.TA & 0x3F;
806760            break;
807761         }
808         ef9341.busy = 0;
762         state->ef9341.busy = 0;
809763      }
810764      else
811765      {
812         ef9341.TA = data;
766         state->ef9341.TA = data;
813767      }
814768   }
815769   else
816770   {
817771      if ( b )
818772      {
819         ef9341.TB = data;
820         ef9341.busy = 0x80;
821         switch ( ef9341.M & 0xE0 )
773         state->ef9341.TB = data;
774         state->ef9341.busy = 0x80;
775         switch ( state->ef9341.M & 0xE0 )
822776         {
823777         case 0x00:   /* Write */
824            ef9341.ram[ ef9341_get_c_addr() ] = ef9341.TB;
825            ef9341_inc_c();
778            state->ef9341.ram[ ef9341_get_c_addr(state) ] = state->ef9341.TB;
779            ef9341_inc_c(state);
826780            break;
827781         case 0x20:   /* Read */
828            logerror("ef9341 unimplemented data action %02X\n", ef9341.M & 0xE0 );
829            ef9341_inc_c();
782            logerror("ef9341 unimplemented data action %02X\n", state->ef9341.M & 0xE0 );
783            ef9341_inc_c(state);
830784            break;
831785         case 0x40:   /* Write without increment */
832786         case 0x60:   /* Read without increment */
833787         case 0x80:   /* Write slice */
834788         case 0xA0:   /* Read slice */
835            logerror("ef9341 unimplemented data action %02X\n", ef9341.M & 0xE0 );
789            logerror("ef9341 unimplemented data action %02X\n", state->ef9341.M & 0xE0 );
836790            break;
837791         }
838         ef9341.busy = 0;
792         state->ef9341.busy = 0;
839793      }
840794      else
841795      {
842         ef9341.TA = data;
796         state->ef9341.TA = data;
843797      }
844798   }
845799}
846800
847UINT8 odyssey2_ef9341_r( int command, int b )
801UINT8 odyssey2_ef9341_r( running_machine *machine, int command, int b )
848802{
803   odyssey2_state *state = machine->driver_data<odyssey2_state>();
849804   UINT8   data = 0xFF;
850805
851806   logerror("ef9341 %s read, t%s\n", command ? "command" : "data", b ? "B" : "A" );
r9667r9668
857812      }
858813      else
859814      {
860         data = ef9341.busy;
815         data = state->ef9341.busy;
861816      }
862817   }
863818   else
864819   {
865820      if ( b )
866821      {
867         data = ef9341.TB;
868         ef9341.busy = 0x80;
822         data = state->ef9341.TB;
823         state->ef9341.busy = 0x80;
869824      }
870825      else
871826      {
872         data = ef9341.TA;
827         data = state->ef9341.TA;
873828      }
874829   }
875830   return data;
src/mess/includes/pdp1.h
r9667r9668
9191   pdp1_fontdata_size = 8 * pdp1_charnum
9292};
9393
94
95/*----------- defined in machine/pdp1.c -----------*/
96
97extern pdp1_reset_param_t pdp1_reset_param;
98
99MACHINE_START( pdp1 );
100MACHINE_RESET( pdp1 );
101
102DEVICE_START( pdp1_tape );
103DEVICE_IMAGE_LOAD( pdp1_tape );
104DEVICE_IMAGE_UNLOAD( pdp1_tape );
105
106DEVICE_IMAGE_LOAD(pdp1_typewriter);
107DEVICE_IMAGE_UNLOAD(pdp1_typewriter);
108
109DEVICE_IMAGE_LOAD(pdp1_drum);
110DEVICE_IMAGE_UNLOAD(pdp1_drum);
111
112INTERRUPT_GEN( pdp1_interrupt );
113
114void pdp1_get_open_mode(int id, unsigned int *readable, unsigned int *writeable, unsigned int *creatable);
115
116typedef struct lightpen_t
117{
118   char active;
119   char down;
120   short x, y;
121   short radius;
122} lightpen_t;
123
124
125/*----------- defined in video/pdp1.c -----------*/
126
127VIDEO_START( pdp1 );
128VIDEO_UPDATE( pdp1 );
129
130void pdp1_plot(int x, int y);
131
132void pdp1_typewriter_drawchar(running_machine *machine, int character);
133
134void pdp1_update_lightpen_state(const lightpen_t *new_state);
135
13694enum
13795{
13896   /* size and position of crt window */
r9667r9668
205163   pen_lightpen_pressed = pen_green
206164};
207165
166/* tape reader registers */
167typedef struct tape_reader_t
168{
169   device_image_interface *fd;   /* file descriptor of tape image */
208170
171   int motor_on;   /* 1-bit reader motor on */
172
173   int rb;         /* 18-bit reader buffer */
174   int rcl;      /* 1-bit reader clutch */
175   int rc;         /* 2-bit reader counter */
176   int rby;      /* 1-bit reader binary mode flip-flop */
177   int rcp;      /* 1-bit reader "need a completion pulse" flip-flop */
178
179   emu_timer *timer;   /* timer to simulate reader timing */
180} tape_reader_t;
181
182
183
184/* tape puncher registers */
185typedef struct tape_puncher_t
186{
187   device_image_interface *fd;   /* file descriptor of tape image */
188
189   emu_timer *timer;   /* timer to generate completion pulses */
190} tape_puncher_t;
191
192
193
194/* typewriter registers */
195typedef struct typewriter_t
196{
197   device_image_interface *fd;   /* file descriptor of output image */
198
199   int tb;         /* state->typewriter buffer */
200
201   emu_timer *tyo_timer;/* timer to generate completion pulses */
202} typewriter_t;
203
204/* MIT parallel drum (mostly similar to type 23) */
205typedef struct parallel_drum_t
206{
207   device_image_interface *fd;   /* file descriptor of drum image */
208
209   int il;         /* initial location (12-bit) */
210   int wc;         /* word counter (12-bit) */
211   int wcl;      /* word core location counter (16-bit) */
212   int rfb;      /* read field buffer (5-bit) */
213   int wfb;      /* write field buffer (5-bit) */
214
215   int dba;
216
217   emu_timer *rotation_timer;   /* timer called each time dc is 0 */
218   emu_timer *il_timer;      /* timer called each time dc is il */
219} parallel_drum_t;
220
221
222typedef struct lightpen_t
223{
224   char active;
225   char down;
226   short x, y;
227   short radius;
228} lightpen_t;
229
230
231class pdp1_state : public driver_device
232{
233public:
234   pdp1_state(running_machine &machine, const driver_device_config_base &config)
235      : driver_device(machine, config) { }
236
237   pdp1_reset_param_t reset_param;
238   int io_status;
239   tape_reader_t tape_reader;
240   tape_puncher_t tape_puncher;
241   typewriter_t typewriter;
242   emu_timer *dpy_timer;
243   lightpen_t lightpen;
244   parallel_drum_t parallel_drum;
245   int old_typewriter_keys[4];
246   int old_lightpen;
247   int old_control_keys;
248   int old_tw_keys;
249   int old_ta_keys;
250   int typewriter_color;
251   bitmap_t *panel_bitmap;
252   bitmap_t *typewriter_bitmap;
253   lightpen_t lightpen_state;
254   lightpen_t previous_lightpen_state;
255   int pos;
256   int case_shift;
257};
258
259
260/*----------- defined in machine/pdp1.c -----------*/
261
262extern pdp1_reset_param_t pdp1_reset_param;
263
264MACHINE_START( pdp1 );
265MACHINE_RESET( pdp1 );
266
267DEVICE_START( pdp1_tape );
268DEVICE_IMAGE_LOAD( pdp1_tape );
269DEVICE_IMAGE_UNLOAD( pdp1_tape );
270
271DEVICE_IMAGE_LOAD(pdp1_typewriter);
272DEVICE_IMAGE_UNLOAD(pdp1_typewriter);
273
274DEVICE_IMAGE_LOAD(pdp1_drum);
275DEVICE_IMAGE_UNLOAD(pdp1_drum);
276
277INTERRUPT_GEN( pdp1_interrupt );
278
279void pdp1_get_open_mode(int id, unsigned int *readable, unsigned int *writeable, unsigned int *creatable);
280
281
282/*----------- defined in video/pdp1.c -----------*/
283
284VIDEO_START( pdp1 );
285VIDEO_UPDATE( pdp1 );
286
287void pdp1_plot(int x, int y);
288void pdp1_typewriter_drawchar(running_machine *machine, int character);
289void pdp1_update_lightpen_state(running_machine *machine, const lightpen_t *new_state);
290
291
209292#endif /* PDP1_H_ */
src/mess/includes/nc.h
r9667r9668
2525};
2626
2727
28class nc_state : public driver_device
29{
30public:
31   nc_state(running_machine &machine, const driver_device_config_base &config)
32      : driver_device(machine, config) { }
33
34   emu_timer *serial_timer;
35   char memory_config[4];
36   emu_timer *keyboard_timer;
37   int membank_rom_mask;
38   int membank_internal_ram_mask;
39   UINT8 poweroff_control;
40   int card_status;
41   unsigned char uart_control;
42   int irq_mask;
43   int irq_status;
44   int irq_latch;
45   int irq_latch_mask;
46   int sound_channel_periods[2];
47   mame_file *file;
48   int previous_inputport_10_state;
49   int previous_alarm_state;
50   UINT8 nc200_uart_interrupt_irq;
51   unsigned char *card_ram;
52   int membank_card_ram_mask;
53   unsigned long display_memory_start;
54   UINT8 type;
55   int card_size;
56   int nc200_backlight;
57};
58
59
2860/*----------- defined in video/nc.c -----------*/
2961
3062extern VIDEO_START( nc );
3163extern VIDEO_UPDATE( nc );
3264extern PALETTE_INIT( nc );
3365
34void nc200_video_set_backlight(int state);
66void nc200_video_set_backlight(running_machine *machine, int state);
3567
3668
3769/*----------- defined in drivers/nc.c -----------*/
3870
3971/* pointer to loaded data */
40extern unsigned char *nc_card_ram;
4172/* mask used to stop access over end of card ram area */
42extern int nc_membank_card_ram_mask;
4373
44extern unsigned long nc_display_memory_start;
45extern UINT8 nc_type;
4674
47void nc_set_card_present_state(int);
75void nc_set_card_present_state(running_machine *machine, int state);
4876
4977
5078/*----------- defined in machine/nc.c -----------*/
src/mess/includes/concept.h
r9667r9668
2121   MaxKeyMessageLen = 1
2222};
2323
24typedef struct
25{
26   read8_space_func reg_read;
27   write8_space_func reg_write;
28   read8_space_func rom_read;
29   write8_space_func rom_write;
30} expansion_slot_t;
31
32
2433class concept_state : public driver_device
2534{
2635public:
r9667r9668
3746   UINT32 KeyStateSave[3];
3847   UINT8 fdc_local_status;
3948   UINT8 fdc_local_command;
49   expansion_slot_t expansion_slots[4];
4050};
4151
4252
src/mess/includes/vectrex.h
r9667r9668
99
1010#include "machine/6522via.h"
1111
12/*----------- defined in drivers/vectrex.c -----------*/
12#define NVECT 10000
1313
14extern UINT8 *gce_vectorram;
15extern size_t gce_vectorram_size;
14typedef struct _vectrex_point
15{
16   int x; int y;
17   rgb_t col;
18   int intensity;
19} vectrex_point;
1620
21class vectrex_state : public driver_device
22{
23public:
24   vectrex_state(running_machine &machine, const driver_device_config_base &config)
25      : driver_device(machine, config) { }
1726
27   UINT8 *gce_vectorram;
28   size_t gce_vectorram_size;
29   int imager_status;
30   UINT32 beam_color;
31   unsigned char via_out[2];
32   double imager_freq;
33   emu_timer *imager_timer;
34   int lightpen_port;
35   int reset_refresh;
36   rgb_t imager_colors[6];
37   const double *imager_angles;
38   unsigned char imager_pinlevel;
39   int old_mcontrol;
40   double sl;
41   double pwl;
42   int x_center;
43   int y_center;
44   int x_max;
45   int y_max;
46   int x_int;
47   int y_int;
48   int lightpen_down;
49   int pen_x;
50   int pen_y;
51   emu_timer *lp_t;
52   emu_timer *refresh;
53   UINT8 blank;
54   UINT8 ramp;
55   INT8 analog[5];
56   int point_index;
57   int display_start;
58   int display_end;
59   vectrex_point points[NVECT];
60   UINT16 via_timer2;
61   attotime vector_start_time;
62   UINT8 cb2;
63};
64
65
1866/*----------- defined in machine/vectrex.c -----------*/
1967
2068DEVICE_IMAGE_LOAD( vectrex_cart );
2169
22extern int vectrex_imager_status;
23extern UINT32 vectrex_beam_color;
24extern unsigned char vectrex_via_out[2];
25extern double vectrex_imager_freq;
26extern emu_timer *vectrex_imager_timer;
27extern int vectrex_lightpen_port;
28extern int vectrex_reset_refresh;
2970
3071TIMER_CALLBACK(vectrex_imager_eye);
3172void vectrex_configuration(running_machine *machine);
r9667r9668
5596READ8_HANDLER ( vectrex_via_r );
5697WRITE8_HANDLER ( vectrex_via_w );
5798
58void vectrex_add_point_stereo (int x, int y, rgb_t color, int intensity);
59void vectrex_add_point (int x, int y, rgb_t color, int intensity);
60extern void (*vector_add_point_function) (int, int, rgb_t, int);
99void vectrex_add_point_stereo (running_machine *machine, int x, int y, rgb_t color, int intensity);
100void vectrex_add_point (running_machine *machine, int x, int y, rgb_t color, int intensity);
101extern void (*vector_add_point_function) (running_machine *, int, int, rgb_t, int);
61102
62103#endif /* VECTREX_H_ */
src/mess/includes/tx0.h
r9667r9668
77#ifndef TX0_H_
88#define TX0_H_
99
10enum state_t
11{
12   MTS_UNSELECTED,
13   MTS_SELECTING,
14   MTS_SELECTED,
15   MTS_UNSELECTING
16};
1017
18enum backspace_state_t
19{
20   MTBSS_STATE0,
21   MTBSS_STATE1,
22   MTBSS_STATE2,
23   MTBSS_STATE3,
24   MTBSS_STATE4,
25   MTBSS_STATE5,
26   MTBSS_STATE6
27};
28
29enum state_2_t
30{
31   MTRDS_STATE0,
32   MTRDS_STATE1,
33   MTRDS_STATE2,
34   MTRDS_STATE3,
35   MTRDS_STATE4,
36   MTRDS_STATE5,
37   MTRDS_STATE6
38};
39
40enum state_3_t
41{
42   MTWTS_STATE0,
43   MTWTS_STATE1,
44   MTWTS_STATE2,
45   MTWTS_STATE3
46};
47
48enum irg_pos_t
49{
50   MTIRGP_START,
51   MTIRGP_ENDMINUS1,
52   MTIRGP_END
53};
54
55
56
57/* tape reader registers */
58typedef struct tape_reader_t
59{
60   device_image_interface *fd;   /* file descriptor of tape image */
61
62   int motor_on;   /* 1-bit reader motor on */
63
64   int rcl;      /* 1-bit reader clutch */
65   int rc;         /* 2-bit reader counter */
66
67   emu_timer *timer;   /* timer to simulate reader timing */
68} tape_reader_t;
69
70
71
72/* tape puncher registers */
73typedef struct tape_puncher_t
74{
75   device_image_interface *fd;   /* file descriptor of tape image */
76
77   emu_timer *timer;   /* timer to generate completion pulses */
78} tape_puncher_t;
79
80
81
82/* typewriter registers */
83typedef struct typewriter_t
84{
85   device_image_interface *fd;   /* file descriptor of output image */
86
87   emu_timer *prt_timer;/* timer to generate completion pulses */
88} typewriter_t;
89
90
91/* magnetic tape unit registers */
92typedef struct magtape_t
93{
94   device_image_interface *img;      /* image descriptor */
95
96   state_t state;
97
98   int command;
99   int binary_flag;
100
101   union
102   {
103      backspace_state_t backspace_state;
104      struct
105      {
106         state_2_t state;
107         int space_flag;
108      } read;
109      struct
110      {
111         state_3_t state;
112         int counter;
113      } write;
114   } u;
115
116   int sel_pending;
117   int cpy_pending;
118
119   irg_pos_t irg_pos;         /* position relative to inter-record gap */
120
121   int long_parity;
122
123   emu_timer *timer;   /* timer to simulate reader timing */
124} magtape_t;
125
126
127class tx0_state : public driver_device
128{
129public:
130   tx0_state(running_machine &machine, const driver_device_config_base &config)
131      : driver_device(machine, config) { }
132
133   tape_reader_t tape_reader;
134   tape_puncher_t tape_puncher;
135   typewriter_t typewriter;
136   emu_timer *dis_timer;
137   magtape_t magtape;
138   int old_typewriter_keys[4];
139   int old_control_keys;
140   int old_tsr_keys;
141   int tsr_index;
142   int typewriter_color;
143   bitmap_t *panel_bitmap;
144   bitmap_t *typewriter_bitmap;
145   int pos;
146   int case_shift;
147};
148
149
11150/*----------- defined in machine/tx0.c -----------*/
12151
13152MACHINE_START( tx0 );
src/mess/includes/lviv.h
r9667r9668
1010#include "devices/snapquik.h"
1111#include "machine/i8255a.h"
1212
13class lviv_state : public driver_device
14{
15public:
16   lviv_state(running_machine &machine, const driver_device_config_base &config)
17      : driver_device(machine, config) { }
18
19   unsigned char * video_ram;
20   unsigned short colortable[1][4];
21   UINT8 ppi_port_outputs[2][3];
22   UINT8 startup_mem_map;
23};
24
25
1326/*----------- defined in machine/lviv.c -----------*/
1427
1528extern const i8255a_interface lviv_ppi8255_interface_0;
1629extern const i8255a_interface lviv_ppi8255_interface_1;
1730
18extern unsigned char * lviv_video_ram;
1931 READ8_HANDLER ( lviv_io_r );
2032WRITE8_HANDLER ( lviv_io_w );
2133MACHINE_RESET( lviv );
r9667r9668
2739extern VIDEO_START( lviv );
2840extern VIDEO_UPDATE( lviv );
2941extern const unsigned char lviv_palette[8*3];
30extern unsigned short lviv_colortable[1][4];
3142extern PALETTE_INIT( lviv );
32extern void lviv_update_palette (UINT8);
43extern void lviv_update_palette(running_machine *, UINT8);
3344
3445
3546#endif /* LVIV_H_ */
src/mess/includes/ssystem3.h
r9667r9668
88#define SSYSTEM3_H_
99
1010
11typedef struct
12{
13   int signal;
14   //  int on;
15
16   int count, bit, started;
17   UINT8 data;
18   attotime time, high_time, low_time;
19   union {
20      struct {
21         UINT8 header[7];
22         UINT8 field[8][8/2];
23         UINT8 unknown[5];
24      } s;
25      UINT8 data[7+8*8/2+5];
26   } u;
27} playfield_t;
28
29typedef struct
30{
31   UINT8 data[5];
32   int clock;
33   int count;
34} lcd_t;
35
36
1137class ssystem3_state : public driver_device
1238{
1339public:
1440   ssystem3_state(running_machine &machine, const driver_device_config_base &config)
1541      : driver_device(machine, config) { }
1642
43   UINT8 porta;
1744   UINT8 *videoram;
45   playfield_t playfield;
46   lcd_t lcd;
1847};
1948
2049
2150/*----------- defined in drivers/ssystem3.c -----------*/
2251
23void ssystem3_playfield_getfigure(int x, int y, int *figure, int *black);
52void ssystem3_playfield_getfigure(running_machine *machine, int x, int y, int *figure, int *black);
2453
2554/*----------- defined in video/ssystem3.c -----------*/
2655
r9667r9668
2857extern VIDEO_START( ssystem3 );
2958extern VIDEO_UPDATE( ssystem3 );
3059
31void ssystem3_lcd_reset(void);
60void ssystem3_lcd_reset(running_machine *machine);
3261void ssystem3_lcd_write(running_machine *machine, int clock, int data);
3362
3463#endif /* SSYSTEM3_H_ */
src/mess/includes/odyssey2.h
r9667r9668
2727#define I824X_SCREEN_HEIGHT            243
2828#define I824X_LINE_CLOCKS            228
2929
30typedef union {
31    UINT8 reg[0x100];
32    struct {
33   struct {
34       UINT8 y,x,color,res;
35   } sprites[4];
36   struct {
37       UINT8 y,x,ptr,color;
38   } foreground[12];
39   struct {
40       struct {
41      UINT8 y,x,ptr,color;
42       } single[4];
43   } quad[4];
44   UINT8 shape[4][8];
45   UINT8 control;
46   UINT8 status;
47   UINT8 collision;
48   UINT8 color;
49   UINT8 y;
50   UINT8 x;
51   UINT8 res;
52   UINT8 shift1,shift2,shift3;
53   UINT8 sound;
54   UINT8 res2[5+0x10];
55   UINT8 hgrid[2][0x10];
56   UINT8 vgrid[0x10];
57    } s;
58} o2_vdc_t;
59
60typedef struct
61{
62   UINT8   X;
63   UINT8   Y;
64   UINT8   Y0;
65   UINT8   R;
66   UINT8   M;
67   UINT8   TA;
68   UINT8   TB;
69   UINT8   busy;
70   UINT8   ram[1024];
71} ef9341_t;
72
73
74class odyssey2_state : public driver_device
75{
76public:
77   odyssey2_state(running_machine &machine, const driver_device_config_base &config)
78      : driver_device(machine, config) { }
79
80   int the_voice_lrq_state;
81   UINT8 *ram;
82   UINT8 p1;
83   UINT8 p2;
84   size_t cart_size;
85   o2_vdc_t o2_vdc;
86   UINT32 o2_snd_shift[2];
87   UINT8 x_beam_pos;
88   UINT8 y_beam_pos;
89   UINT8 control_status;
90   UINT8 collision_status;
91   int iff;
92   emu_timer *i824x_line_timer;
93   emu_timer *i824x_hblank_timer;
94   bitmap_t *tmp_bitmap;
95   int start_vpos;
96   int start_vblank;
97   UINT8 lum;
98   UINT16 lfsr;
99   sound_stream *sh_channel;
100   UINT16 sh_count;
101   //ef9341_t ef9341;
102};
103
104
30105/*----------- defined in video/odyssey2.c -----------*/
31106
32107extern const UINT8 odyssey2_colors[];
r9667r9668
41116
42117STREAM_UPDATE( odyssey2_sh_update );
43118
44void odyssey2_ef9341_w( int command, int b, UINT8 data );
45UINT8 odyssey2_ef9341_r( int command, int b );
119void odyssey2_ef9341_w( running_machine *machine, int command, int b, UINT8 data );
120UINT8 odyssey2_ef9341_r( running_machine *machine, int command, int b );
46121
47122DECLARE_LEGACY_SOUND_DEVICE(ODYSSEY2, odyssey2_sound);
48123
src/mess/drivers/pdp1.c
r9667r9668
346346}
347347
348348
349static MACHINE_CONFIG_START( pdp1, driver_device )
349static MACHINE_CONFIG_START( pdp1, pdp1_state )
350350
351351   /* basic machine hardware */
352352   /* PDP1 CPU @ 200 kHz (no master clock, but the instruction and memory rate is 200 kHz) */
src/mess/drivers/d6800.c
r9667r9668
3939#include "machine/6821pia.h"
4040#include "machine/rescap.h"
4141
42static UINT8 d6800_keylatch;
43static UINT8 d6800_keydown;
44static UINT8 d6800_screen;
45static UINT8 d6800_rtc;
46static running_device *d6800_cassette;
47static running_device *d6800_speaker;
4842
4943class d6800_state : public driver_device
5044{
r9667r9668
5347      : driver_device(machine, config) { }
5448
5549   UINT8 dummy;
50   UINT8 keylatch;
51   UINT8 keydown;
52   UINT8 screen;
53   UINT8 rtc;
54   running_device *cassette;
55   running_device *speaker;
5656};
5757
5858
r9667r9668
103103
104104static VIDEO_UPDATE( d6800 )
105105{
106   d6800_state *state = screen->machine->driver_data<d6800_state>();
106107   UINT8 x,y,gfx=0;
107108   UINT8 *RAM = memory_region(screen->machine, "maincpu");
108109
r9667r9668
112113
113114      for (x = 0; x < 8; x++)
114115      {
115         if (d6800_screen)
116         if (state->screen)
116117            gfx = RAM[0x100 | x | (y<<3)];
117118
118119         *p++ = ( gfx & 0x80 ) ? 1 : 0;
r9667r9668
132133
133134static INTERRUPT_GEN( d6800_interrupt )
134135{
135   d6800_rtc = 1;
136   d6800_state *state = device->machine->driver_data<d6800_state>();
137   state->rtc = 1;
136138}
137139
138140static READ_LINE_DEVICE_HANDLER( d6800_rtc_pulse )
139141{
140   UINT8 res = d6800_rtc;
141   d6800_rtc = 0;
142   d6800_state *state = device->machine->driver_data<d6800_state>();
143   UINT8 res = state->rtc;
144   state->rtc = 0;
142145   return res;
143146}
144147
145148static READ_LINE_DEVICE_HANDLER( d6800_keydown_r )
146149{
147   return d6800_keydown;
150   d6800_state *state = device->machine->driver_data<d6800_state>();
151   return state->keydown;
148152}
149153
150154static READ_LINE_DEVICE_HANDLER( d6800_fn_key_r )
r9667r9668
154158
155159static WRITE_LINE_DEVICE_HANDLER( d6800_screen_w )
156160{
157   d6800_screen = state;
161   d6800_state *drvstate = device->machine->driver_data<d6800_state>();
162   drvstate->screen = state;
158163}
159164
160165static READ8_DEVICE_HANDLER( d6800_cassette_r )
r9667r9668
171176
172177static WRITE8_DEVICE_HANDLER( d6800_cassette_w )
173178{
179   d6800_state *state = device->machine->driver_data<d6800_state>();
174180   /*
175181   Cassette circuit consists of a 566 and a transistor. The 556 runs at 2400
176182   or 1200 Hz depending on the state of the transistor. This is controlled by
177183   bit 0 of the PIA. Bit 6 drives the speaker.
178184   */
179185
180   speaker_level_w(d6800_speaker, (data & 0x40) ? 0 : 1);
186   speaker_level_w(state->speaker, (data & 0x40) ? 0 : 1);
181187}
182188
183189static READ8_DEVICE_HANDLER( d6800_keyboard_r )
184190{
191   d6800_state *state = device->machine->driver_data<d6800_state>();
185192   UINT8 data = 0xff;
186193
187   if (!BIT(d6800_keylatch, 4)) data &= input_port_read(device->machine, "LINE0");
188   if (!BIT(d6800_keylatch, 5)) data &= input_port_read(device->machine, "LINE1");
189   if (!BIT(d6800_keylatch, 6)) data &= input_port_read(device->machine, "LINE2");
190   if (!BIT(d6800_keylatch, 7)) data &= input_port_read(device->machine, "LINE3");
194   if (!BIT(state->keylatch, 4)) data &= input_port_read(device->machine, "LINE0");
195   if (!BIT(state->keylatch, 5)) data &= input_port_read(device->machine, "LINE1");
196   if (!BIT(state->keylatch, 6)) data &= input_port_read(device->machine, "LINE2");
197   if (!BIT(state->keylatch, 7)) data &= input_port_read(device->machine, "LINE3");
191198
192   d6800_keydown = (data==0xff) ? 0 : 1;
199   state->keydown = (data==0xff) ? 0 : 1;
193200
194201   return data;
195202}
196203
197204static WRITE8_DEVICE_HANDLER( d6800_keyboard_w )
198205{
206   d6800_state *state = device->machine->driver_data<d6800_state>();
199207   /*
200208
201209        bit     description
r9667r9668
212220    */
213221
214222
215   d6800_keylatch = data & 0xf0;
223   state->keylatch = data & 0xf0;
216224}
217225
218226static const pia6821_interface d6800_mc6821_intf =
r9667r9668
235243
236244static MACHINE_START( d6800 )
237245{
238   d6800_speaker = machine->device("speaker");
239   d6800_cassette = machine->device("cassette");
246   d6800_state *state = machine->driver_data<d6800_state>();
247   state->speaker = machine->device("speaker");
248   state->cassette = machine->device("cassette");
240249}
241250
242251static MACHINE_RESET( d6800 )
src/mess/drivers/beehive.c
r9667r9668
1414#include "emu.h"
1515#include "cpu/i8085/i8085.h"
1616
17static const UINT8 *FNT;
18static const UINT8 *videoram;
1917
18class beehive_state : public driver_device
19{
20public:
21   beehive_state(running_machine &machine, const driver_device_config_base &config)
22      : driver_device(machine, config) { }
23
24   const UINT8 *FNT;
25   const UINT8 *videoram;
26};
27
28
29
2030static ADDRESS_MAP_START(beehive_mem, ADDRESS_SPACE_PROGRAM, 8)
2131   ADDRESS_MAP_UNMAP_HIGH
2232   AM_RANGE( 0x0000, 0x17ff ) AM_ROM
r9667r9668
3848
3949static VIDEO_START( beehive )
4050{
41   FNT = memory_region(machine, "chargen");
42   videoram = memory_region(machine, "maincpu")+0x81fa;
51   beehive_state *state = machine->driver_data<beehive_state>();
52   state->FNT = memory_region(machine, "chargen");
53   state->videoram = memory_region(machine, "maincpu")+0x81fa;
4354}
4455
4556/* This system appears to have inline attribute bytes of unknown meaning.
4657    Currently they are ignored. */
4758static VIDEO_UPDATE( beehive )
4859{
60   beehive_state *state = screen->machine->driver_data<beehive_state>();
4961   //static UINT8 framecnt=0;
5062   UINT8 y,ra,chr,gfx;
5163   UINT16 sy=0,ma=0,x,xx;
r9667r9668
6476            gfx = 0;
6577            if (ra < 9)
6678            {
67               chr = videoram[xx++];
79               chr = state->videoram[xx++];
6880
6981            //   /* Take care of flashing characters */
7082            //   if ((chr < 0x80) && (framecnt & 0x08))
r9667r9668
7486                  x--;
7587               else
7688               {
77                  gfx = FNT[(chr<<4) | ra ];
89                  gfx = state->FNT[(chr<<4) | ra ];
7890
7991                  /* Display a scanline of a character */
8092                  *p = ( gfx & 0x80 ) ? 1 : 0; p++;
r9667r9668
94106   return 0;
95107}
96108
97static MACHINE_CONFIG_START( beehive, driver_device )
109static MACHINE_CONFIG_START( beehive, beehive_state )
98110    /* basic machine hardware */
99111    MDRV_CPU_ADD("maincpu",I8085A, XTAL_4MHz)
100112    MDRV_CPU_PROGRAM_MAP(beehive_mem)
src/mess/drivers/tx0.c
r9667r9668
317317};
318318
319319
320static MACHINE_CONFIG_START( tx0_64kw, driver_device )
320static MACHINE_CONFIG_START( tx0_64kw, tx0_state )
321321   /* basic machine hardware */
322322   /* TX0 CPU @ approx. 167 kHz (no master clock, but the memory cycle time is approximately 6usec) */
323323   MDRV_CPU_ADD("maincpu", TX0_64KW, 166667)
src/mess/drivers/dual68.c
r9667r9668
1111#include "cpu/i8085/i8085.h"
1212#include "machine/terminal.h"
1313
14static UINT16* dual68_ram;
1514
15class dual68_state : public driver_device
16{
17public:
18   dual68_state(running_machine &machine, const driver_device_config_base &config)
19      : driver_device(machine, config) { }
20
21   UINT16* ram;
22};
23
24
25
1626static WRITE16_HANDLER(dual68_terminal_w)
1727{
1828   running_device *devconf = space->machine->device("terminal");
r9667r9668
2131
2232static ADDRESS_MAP_START(dual68_mem, ADDRESS_SPACE_PROGRAM, 16)
2333   ADDRESS_MAP_UNMAP_HIGH
24   AM_RANGE(0x00000000, 0x0000ffff) AM_RAM AM_BASE(&dual68_ram)
34   AM_RANGE(0x00000000, 0x0000ffff) AM_RAM AM_BASE_MEMBER(dual68_state, ram)
2535   AM_RANGE(0x00080000, 0x00081fff) AM_ROM AM_REGION("user1",0)
2636   AM_RANGE(0x007f0000, 0x007f0001) AM_WRITE(dual68_terminal_w)
2737   AM_RANGE(0x00800000, 0x00801fff) AM_ROM AM_REGION("user1",0)
r9667r9668
4555
4656static MACHINE_RESET(dual68)
4757{
58   dual68_state *state = machine->driver_data<dual68_state>();
4859   UINT8* user1 = memory_region(machine, "user1");
4960
50   memcpy((UINT8*)dual68_ram,user1,0x2000);
61   memcpy((UINT8*)state->ram,user1,0x2000);
5162
5263   machine->device("maincpu")->reset();
5364}
r9667r9668
6273   DEVCB_HANDLER(dual68_kbd_put)
6374};
6475
65static MACHINE_CONFIG_START( dual68, driver_device )
76static MACHINE_CONFIG_START( dual68, dual68_state )
6677    /* basic machine hardware */
6778    MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz / 2)
6879    MDRV_CPU_PROGRAM_MAP(dual68_mem)
src/mess/drivers/mz2500.c
r9667r9668
5959#include "formats/flopimg.h"
6060#include "formats/basicdsk.h"
6161
62
63class mz2500_state : public driver_device
64{
65public:
66   mz2500_state(running_machine &machine, const driver_device_config_base &config)
67      : driver_device(machine, config) { }
68
69   UINT8 bank_val[8];
70   UINT8 bank_addr;
71   UINT8 irq_sel;
72   UINT8 irq_vector[4];
73   UINT8 irq_mask[4];
74   UINT8 kanji_bank;
75   UINT8 dic_bank;
76   UINT8 fdc_reverse;
77   UINT8 key_mux;
78   UINT8 monitor_type;
79   UINT8 text_reg[0x100];
80   UINT8 text_reg_index;
81   UINT8 text_col_size;
82   UINT8 text_font_reg;
83   UINT8 pal_select;
84   UINT16 cg_vs;
85   UINT16 cg_ve;
86   UINT16 cg_hs;
87   UINT16 cg_he;
88   INT16 tv_vs;
89   INT16 tv_ve;
90   INT16 tv_hs;
91   INT16 tv_he;
92   UINT8 cg_latch[4];
93   UINT8 cg_reg_index;
94   UINT8 cg_reg[0x20];
95   UINT8 clut16[0x10];
96   UINT16 clut256[0x100];
97   UINT8 cg_mask;
98   int scr_x_size;
99   int scr_y_size;
100   UINT8 cg_clear_flag;
101   UINT32 rom_index;
102   UINT8 hrom_index;
103   UINT8 lrom_index;
104   struct { UINT8 r,g,b; } pal[16];
105   UINT8 joy_mode;
106   UINT16 kanji_index;
107   UINT32 emm_offset;
108   UINT8 old_portc;
109   UINT8 prev_col_val;
110   UINT8 pio_latchb;
111   UINT8 ym_porta;
112};
113
114
62115/* machine stuff */
63static UINT8 bank_val[8],bank_addr;
64static UINT8 irq_sel,irq_vector[4],irq_mask[4];
65static UINT8 kanji_bank,dic_bank;
66static UINT8 fdc_reverse;
67static UINT8 key_mux;
68static UINT8 monitor_type;
69116
70117#define WRAM_RESET 0
71118#define IPL_RESET 1
72119
73static void mz2500_reset(UINT8 type);
120static void mz2500_reset(mz2500_state *state, UINT8 type);
74121static const UINT8 bank_reset_val[2][8] =
75122{
76123   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
r9667r9668
78125};
79126
80127/* video stuff*/
81static UINT8 text_reg[0x100], text_reg_index;
82static UINT8 text_col_size, text_font_reg;
83static UINT8 pal_select;
84static UINT16 cg_vs,cg_ve,cg_hs,cg_he; //CG window parameters
85static INT16 tv_vs,tv_ve,tv_hs,tv_he; //TV window parameters
86static UINT8 cg_latch[4];
87static UINT8 cg_reg_index;
88static UINT8 cg_reg[0x20];
89static UINT8 clut16[0x10];
90static UINT16 clut256[0x100];
91static UINT8 cg_mask;
92static int scr_x_size,scr_y_size;
93static UINT8 cg_clear_flag;
94128
95129static VIDEO_START( mz2500 )
96130{
r9667r9668
132166
133167static void draw_80x25(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,UINT16 map_addr)
134168{
169   mz2500_state *state = machine->driver_data<mz2500_state>();
135170   UINT8 *vram = memory_region(machine, "maincpu");
136171   int x,y,count,xi,yi;
137172   UINT8 *gfx_data;
r9667r9668
141176
142177   count = (map_addr & 0x7ff);
143178
144   y_step = (text_font_reg) ? 1 : 2;
145   y_height = (text_reg[0] & 0x10) ? 10 : 8;
146   s_y = text_reg[9] & 0xf;
179   y_step = (state->text_font_reg) ? 1 : 2;
180   y_height = (state->text_reg[0] & 0x10) ? 10 : 8;
181   s_y = state->text_reg[9] & 0xf;
147182
148183   for (y=0;y<26*y_step;y+=y_step)
149184   {
r9667r9668
190225               res_y = y*y_height+yi-s_y;
191226
192227               /* check TV window boundaries */
193               if(res_x < tv_hs || res_x >= tv_he || res_y < tv_vs || res_y >= tv_ve)
228               if(res_x < state->tv_hs || res_x >= state->tv_he || res_y < state->tv_vs || res_y >= state->tv_ve)
194229                  continue;
195230
196231               if(gfx_sel & 0x8)
r9667r9668
209244               if(pen)
210245               {
211246                  if((res_y) >= 0 && (res_y) < 200*y_step)
212                     mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen+(pal_select ? 0x00 : 0x10),0,0);
247                     mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen+(state->pal_select ? 0x00 : 0x10),0,0);
213248               }
214249            }
215250         }
r9667r9668
222257
223258static void draw_40x25(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int plane,UINT16 map_addr)
224259{
260   mz2500_state *state = machine->driver_data<mz2500_state>();
225261   UINT8 *vram = memory_region(machine, "maincpu");
226262   int x,y,count,xi,yi;
227263   UINT8 *gfx_data;
r9667r9668
231267
232268   count = (((plane * 0x400) + map_addr) & 0x7ff);
233269
234   y_step = (text_font_reg) ? 1 : 2;
235   y_height = (text_reg[0] & 0x10) ? 10 : 8;
236   s_y = text_reg[9] & 0xf;
270   y_step = (state->text_font_reg) ? 1 : 2;
271   y_height = (state->text_reg[0] & 0x10) ? 10 : 8;
272   s_y = state->text_reg[9] & 0xf;
237273
238274   for (y=0;y<26*y_step;y+=y_step)
239275   {
r9667r9668
280316               res_y = y*y_height+yi-s_y;
281317
282318               /* check TV window boundaries */
283               if(res_x < tv_hs || res_x >= tv_he || res_y < tv_vs || res_y >= tv_ve)
319               if(res_x < state->tv_hs || res_x >= state->tv_he || res_y < state->tv_vs || res_y >= state->tv_ve)
284320                  continue;
285321
286322               if(gfx_sel & 0x8)
r9667r9668
299335               if(pen)
300336               {
301337                  if((res_y) >= 0 && (res_y) < 200*y_step)
302                     mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen+(pal_select ? 0x00 : 0x10),scr_x_size == 640,0);
338                     mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen+(state->pal_select ? 0x00 : 0x10),state->scr_x_size == 640,0);
303339               }
304340            }
305341         }
r9667r9668
312348
313349static void draw_cg4_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int pri)
314350{
351   //mz2500_state *state = machine->driver_data<mz2500_state>();
315352   UINT32 count;
316353   UINT8 *vram = memory_region(machine, "maincpu");
317354   UINT8 pen,pen_bit[2];
r9667r9668
330367            res_y = y;
331368
332369            /* check window boundaries */
333            //if(res_x < cg_hs || res_x >= cg_he || res_y < cg_vs || res_y >= cg_ve)
370            //if(res_x < state->cg_hs || res_x >= state->cg_he || res_y < state->cg_vs || res_y >= state->cg_ve)
334371            //  continue;
335372
336373            /* TODO: very preliminary, just Yukar K2 uses this so far*/
r9667r9668
342379               pen |= pen_bit[pen_i];
343380
344381            {
345               //if(pri == ((clut256[pen] & 0x100) >> 8))
382               //if(pri == ((state->clut256[pen] & 0x100) >> 8))
346383               mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen,0,0);
347384            }
348385         }
r9667r9668
353390
354391static void draw_cg16_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int plane,int x_size,int pri)
355392{
393   mz2500_state *state = machine->driver_data<mz2500_state>();
356394   UINT32 count;
357395   UINT8 *vram = memory_region(machine, "maincpu");
358396   UINT8 pen,pen_bit[4];
r9667r9668
366404
367405   base_mask = (x_size == 640) ? 0x3f : 0x1f;
368406
369   count = (cg_reg[0x10]) | ((cg_reg[0x11] & base_mask) << 8);
370   wa_reg = (cg_reg[0x12]) | ((cg_reg[0x13] & base_mask) << 8);
407   count = (state->cg_reg[0x10]) | ((state->cg_reg[0x11] & base_mask) << 8);
408   wa_reg = (state->cg_reg[0x12]) | ((state->cg_reg[0x13] & base_mask) << 8);
371409   /* TODO: layer 2 scrolling */
372   s_x = (cg_reg[0x0f] & 0xf);
373   cg_interlace = text_font_reg ? 1 : 2;
374   pen_mask = (cg_reg[0x18] >> ((plane & 1) * 4)) & 0x0f;
410   s_x = (state->cg_reg[0x0f] & 0xf);
411   cg_interlace = state->text_font_reg ? 1 : 2;
412   pen_mask = (state->cg_reg[0x18] >> ((plane & 1) * 4)) & 0x0f;
375413
376//   popmessage("%d %d %d %d",cg_hs,cg_he,cg_vs,cg_ve);
414//   popmessage("%d %d %d %d",state->cg_hs,state->cg_he,state->cg_vs,state->cg_ve);
377415
378416   for(y=0;y<200;y++)
379417   {
r9667r9668
385423            res_y = y;
386424
387425            /* check window boundaries */
388            if(res_x < cg_hs || res_x >= cg_he || res_y < cg_vs || res_y >= cg_ve)
426            if(res_x < state->cg_hs || res_x >= state->cg_he || res_y < state->cg_vs || res_y >= state->cg_ve)
389427               continue;
390428
391429            pen_bit[0] = (vram[count+0x40000+((plane & 1) * 0x2000)+(((plane & 2)>>1) * 0x10000)]>>(xi)) & 1 ? (pen_mask & 0x01) : 0; //B
r9667r9668
397435            for(pen_i=0;pen_i<4;pen_i++)
398436               pen |= pen_bit[pen_i];
399437
400            if(pri == ((clut16[pen] & 0x10) >> 4) && clut16[pen] != 0x00 && pen_mask) //correct?
401               mz2500_draw_pixel(machine,bitmap,res_x,res_y,(clut16[pen] & 0x0f)+0x10,(x_size == 320 && scr_x_size == 640),cg_interlace == 2);
438            if(pri == ((state->clut16[pen] & 0x10) >> 4) && state->clut16[pen] != 0x00 && pen_mask) //correct?
439               mz2500_draw_pixel(machine,bitmap,res_x,res_y,(state->clut16[pen] & 0x0f)+0x10,(x_size == 320 && state->scr_x_size == 640),cg_interlace == 2);
402440         }
403441         count++;
404442         count&=((base_mask<<8) | 0xff);
r9667r9668
410448
411449static void draw_cg256_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int plane,int pri)
412450{
451   mz2500_state *state = machine->driver_data<mz2500_state>();
413452   UINT32 count;
414453   UINT8 *vram = memory_region(machine, "maincpu");
415454   UINT8 pen,pen_bit[8];
r9667r9668
422461
423462   base_mask = 0x3f; //no x_size == 640
424463
425   count = (cg_reg[0x10]) | ((cg_reg[0x11] & base_mask) << 8);
426   wa_reg = (cg_reg[0x12]) | ((cg_reg[0x13] & base_mask) << 8);
464   count = (state->cg_reg[0x10]) | ((state->cg_reg[0x11] & base_mask) << 8);
465   wa_reg = (state->cg_reg[0x12]) | ((state->cg_reg[0x13] & base_mask) << 8);
427466   /* TODO: layer 2 scrolling */
428   s_x = (cg_reg[0x0f] & 0xf);
429   cg_interlace = text_font_reg ? 1 : 2;
467   s_x = (state->cg_reg[0x0f] & 0xf);
468   cg_interlace = state->text_font_reg ? 1 : 2;
430469
431470   for(y=0;y<200;y++)
432471   {
r9667r9668
438477            res_y = y;
439478
440479            /* check window boundaries */
441            if(res_x < cg_hs || res_x >= cg_he || res_y < cg_vs || res_y >= cg_ve)
480            if(res_x < state->cg_hs || res_x >= state->cg_he || res_y < state->cg_vs || res_y >= state->cg_ve)
442481               continue;
443482
444            pen_bit[0] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x2000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x10) : 0; // B1
445            pen_bit[1] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x0000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x01) : 0; // B0
446            pen_bit[2] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x6000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x20) : 0; // R1
447            pen_bit[3] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x4000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x02) : 0; // R0
448            pen_bit[4] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xa000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x40) : 0; // G1
449            pen_bit[5] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x8000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x04) : 0; // G0
450            pen_bit[6] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xe000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x80) : 0; // I1
451            pen_bit[7] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xc000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x08) : 0; // I0
483            pen_bit[0] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x2000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x10) : 0; // B1
484            pen_bit[1] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x0000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x01) : 0; // B0
485            pen_bit[2] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x6000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x20) : 0; // R1
486            pen_bit[3] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x4000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x02) : 0; // R0
487            pen_bit[4] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xa000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x40) : 0; // G1
488            pen_bit[5] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x8000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x04) : 0; // G0
489            pen_bit[6] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xe000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x80) : 0; // I1
490            pen_bit[7] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xc000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x08) : 0; // I0
452491
453492            pen = 0;
454493            for(pen_i=0;pen_i<8;pen_i++)
455494               pen |= pen_bit[pen_i];
456495
457            if(pri == ((clut256[pen] & 0x100) >> 8))
458               mz2500_draw_pixel(machine,bitmap,res_x,res_y,(clut256[pen] & 0xff)+0x100,scr_x_size == 640,cg_interlace == 2);
496            if(pri == ((state->clut256[pen] & 0x100) >> 8))
497               mz2500_draw_pixel(machine,bitmap,res_x,res_y,(state->clut256[pen] & 0xff)+0x100,state->scr_x_size == 640,cg_interlace == 2);
459498         }
460499         count++;
461500         count&=((base_mask<<8) | 0xff);
r9667r9668
467506
468507static void draw_tv_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
469508{
509   mz2500_state *state = machine->driver_data<mz2500_state>();
470510   UINT16 base_addr;
471511
472   base_addr = text_reg[1] | ((text_reg[2] & 0x7) << 8);
512   base_addr = state->text_reg[1] | ((state->text_reg[2] & 0x7) << 8);
473513
474//   popmessage("%02x",clut16[0]);
475//   popmessage("%d %d %d %d",tv_hs,(tv_he),tv_vs,(tv_ve));
514//   popmessage("%02x",state->clut16[0]);
515//   popmessage("%d %d %d %d",state->tv_hs,(state->tv_he),state->tv_vs,(state->tv_ve));
476516
477   if(text_col_size)
517   if(state->text_col_size)
478518      draw_80x25(machine,bitmap,cliprect,base_addr);
479519   else
480520   {
481521      int tv_mode;
482522
483      tv_mode = text_reg[0] >> 2;
523      tv_mode = state->text_reg[0] >> 2;
484524
485525      switch(tv_mode & 3)
486526      {
r9667r9668
497537            draw_40x25(machine,bitmap,cliprect,1,base_addr);
498538            draw_40x25(machine,bitmap,cliprect,0,base_addr);
499539            break;
500         //default: popmessage("%02x %02x %02x",tv_mode & 3,text_reg[1],text_reg[2]); break;
540         //default: popmessage("%02x %02x %02x",tv_mode & 3,state->text_reg[1],state->text_reg[2]); break;
501541      }
502542   }
503543}
504544
505545static void draw_cg_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int pri)
506546{
507   //popmessage("%02x %02x",cg_reg[0x0e],cg_reg[0x18]);
547   mz2500_state *state = machine->driver_data<mz2500_state>();
548   //popmessage("%02x %02x",state->cg_reg[0x0e],state->cg_reg[0x18]);
508549
509   switch(cg_reg[0x0e])
550   switch(state->cg_reg[0x0e])
510551   {
511552      case 0x00:
512553         break;
r9667r9668
531572         draw_cg16_screen(machine,bitmap,cliprect,2,640,pri);
532573         break;
533574      default:
534         popmessage("Unsupported CG mode %02x, contact MESS dev",cg_reg[0x0e]);
575         popmessage("Unsupported CG mode %02x, contact MESS dev",state->cg_reg[0x0e]);
535576         break;
536577   }
537578}
538579
539580static VIDEO_UPDATE( mz2500 )
540581{
582   //mz2500_state *state = screen->machine->driver_data<mz2500_state>();
541583   bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); //TODO: correct?
542584
543585   draw_cg_screen(screen->machine,bitmap,cliprect,0);
544586   draw_tv_screen(screen->machine,bitmap,cliprect);
545587   draw_cg_screen(screen->machine,bitmap,cliprect,1);
546   //  popmessage("%02x (%02x %02x) (%02x %02x) (%02x %02x) (%02x %02x)",cg_reg[0x0f],cg_reg[0x10],cg_reg[0x11],cg_reg[0x12],cg_reg[0x13],cg_reg[0x14],cg_reg[0x15],cg_reg[0x16],cg_reg[0x17]);
547   //  popmessage("%02x",text_reg[0x0f]);
588   //  popmessage("%02x (%02x %02x) (%02x %02x) (%02x %02x) (%02x %02x)",state->cg_reg[0x0f],state->cg_reg[0x10],state->cg_reg[0x11],state->cg_reg[0x12],state->cg_reg[0x13],state->cg_reg[0x14],state->cg_reg[0x15],state->cg_reg[0x16],state->cg_reg[0x17]);
589   //  popmessage("%02x",state->text_reg[0x0f]);
548590
549591
550592    return 0;
r9667r9668
552594
553595static void mz2500_reconfigure_screen(running_machine *machine)
554596{
597   mz2500_state *state = machine->driver_data<mz2500_state>();
555598   rectangle visarea;
556599
557   if((cg_reg[0x0e] & 0x1f) == 0x17 || (cg_reg[0x0e] & 0x1f) == 0x03 || text_col_size)
558      scr_x_size = 640;
600   if((state->cg_reg[0x0e] & 0x1f) == 0x17 || (state->cg_reg[0x0e] & 0x1f) == 0x03 || state->text_col_size)
601      state->scr_x_size = 640;
559602   else
560      scr_x_size = 320;
603      state->scr_x_size = 320;
561604
562   if((cg_reg[0x0e] & 0x1f) == 0x03)
563      scr_y_size = 400;
605   if((state->cg_reg[0x0e] & 0x1f) == 0x03)
606      state->scr_y_size = 400;
564607   else
565      scr_y_size = 200 * ((text_font_reg) ? 1 : 2);
608      state->scr_y_size = 200 * ((state->text_font_reg) ? 1 : 2);
566609
567610   visarea.min_x = 0;
568611   visarea.min_y = 0;
569   visarea.max_x = scr_x_size - 1;
570   visarea.max_y = scr_y_size - 1;
612   visarea.max_x = state->scr_x_size - 1;
613   visarea.max_y = state->scr_y_size - 1;
571614
572   //popmessage("%d %d %d %d %02x",vs,ve,hs,he,cg_reg[0x0e]);
615   //popmessage("%d %d %d %d %02x",vs,ve,hs,he,state->cg_reg[0x0e]);
573616
574617   machine->primary_screen->configure(720, 480, visarea, machine->primary_screen->frame_period().attoseconds);
575618
576619   /* calculate CG window parameters here */
577   cg_vs = (cg_reg[0x08]) | ((cg_reg[0x09]<<8) & 1);
578   cg_ve = (cg_reg[0x0a]) | ((cg_reg[0x0b]<<8) & 1);
579   cg_hs = ((cg_reg[0x0c] & 0x7f)*8);
580   cg_he = ((cg_reg[0x0d] & 0x7f)*8);
620   state->cg_vs = (state->cg_reg[0x08]) | ((state->cg_reg[0x09]<<8) & 1);
621   state->cg_ve = (state->cg_reg[0x0a]) | ((state->cg_reg[0x0b]<<8) & 1);
622   state->cg_hs = ((state->cg_reg[0x0c] & 0x7f)*8);
623   state->cg_he = ((state->cg_reg[0x0d] & 0x7f)*8);
581624
582   if(scr_x_size == 320)
625   if(state->scr_x_size == 320)
583626   {
584      cg_hs /= 2;
585      cg_he /= 2;
627      state->cg_hs /= 2;
628      state->cg_he /= 2;
586629   }
587630
588631   /* calculate TV window parameters here */
589632   {
590633      int x_offs,y_offs;
591634
592      monitor_type = ((text_reg[0x0f] & 0x08) >> 3);
635      state->monitor_type = ((state->text_reg[0x0f] & 0x08) >> 3);
593636
594      switch((monitor_type|text_col_size<<1) & 3)
637      switch((state->monitor_type|state->text_col_size<<1) & 3)
595638      {
596639         default:
597640         case 0: x_offs = 64; break;
r9667r9668
599642         case 2: x_offs = 72; break;
600643         case 3: x_offs = 88; break;
601644      }
602      //printf("%d %d %d\n",x_offs,(text_reg[7] & 0x7f) * 8,(text_reg[8] & 0x7f)* 8);
645      //printf("%d %d %d\n",x_offs,(state->text_reg[7] & 0x7f) * 8,(state->text_reg[8] & 0x7f)* 8);
603646
604      y_offs = (monitor_type) ? 76 : 34;
647      y_offs = (state->monitor_type) ? 76 : 34;
605648
606      tv_hs = ((text_reg[7] & 0x7f)*8) - x_offs;
607      tv_he = ((text_reg[8] & 0x7f)*8) - x_offs;
608      tv_vs = (text_reg[3]*2) - y_offs;
609      tv_ve = (text_reg[5]*2) - y_offs;
649      state->tv_hs = ((state->text_reg[7] & 0x7f)*8) - x_offs;
650      state->tv_he = ((state->text_reg[8] & 0x7f)*8) - x_offs;
651      state->tv_vs = (state->text_reg[3]*2) - y_offs;
652      state->tv_ve = (state->text_reg[5]*2) - y_offs;
610653
611      if(scr_x_size == 320)
654      if(state->scr_x_size == 320)
612655      {
613         tv_hs /= 2;
614         tv_he /= 2;
656         state->tv_hs /= 2;
657         state->tv_he /= 2;
615658      }
616659
617      if(scr_y_size == 200)
660      if(state->scr_y_size == 200)
618661      {
619         tv_vs /= 2;
620         tv_ve /= 2;
662         state->tv_vs /= 2;
663         state->tv_ve /= 2;
621664      }
622665   }
623666}
624667
625static UINT8 mz2500_cg_latch_compare(void)
668static UINT8 mz2500_cg_latch_compare(mz2500_state *state)
626669{
627   UINT8 compare_val = cg_reg[0x07] & 0xf;
670   UINT8 compare_val = state->cg_reg[0x07] & 0xf;
628671   UINT8 pix_val;
629672   UINT8 res;
630673   UINT16 i;
r9667r9668
632675
633676   for(i=1;i<0x100;i<<=1)
634677   {
635      pix_val = ((cg_latch[0] & i) ? 1 : 0) | ((cg_latch[1] & i) ? 2 : 0) | ((cg_latch[2] & i) ? 4 : 0) | ((cg_latch[3] & i) ? 8 : 0);
678      pix_val = ((state->cg_latch[0] & i) ? 1 : 0) | ((state->cg_latch[1] & i) ? 2 : 0) | ((state->cg_latch[2] & i) ? 4 : 0) | ((state->cg_latch[3] & i) ? 8 : 0);
636679      if(pix_val == compare_val)
637680         res|=i;
638681   }
r9667r9668
642685
643686static UINT8 mz2500_ram_read(running_machine *machine, UINT16 offset, UINT8 bank_num)
644687{
688   mz2500_state *state = machine->driver_data<mz2500_state>();
645689   UINT8 *ram = memory_region(machine, "maincpu");
646   UINT8 cur_bank = bank_val[bank_num];
690   UINT8 cur_bank = state->bank_val[bank_num];
647691
648692   switch(cur_bank)
649693   {
r9667r9668
653697      case 0x33:
654698      {
655699         // READ MODIFY WRITE
656         if(cg_reg[0x0e] == 0x3)
700         if(state->cg_reg[0x0e] == 0x3)
657701         {
658702            // ...
659703         }
660704         else
661705         {
662706            int plane;
663            cg_latch[0] = ram[offset+((cur_bank & 3)*0x2000)+0x40000]; //B
664            cg_latch[1] = ram[offset+((cur_bank & 3)*0x2000)+0x44000]; //R
665            cg_latch[2] = ram[offset+((cur_bank & 3)*0x2000)+0x48000]; //G
666            cg_latch[3] = ram[offset+((cur_bank & 3)*0x2000)+0x4c000]; //I
667            plane = cg_reg[0x07] & 3;
707            state->cg_latch[0] = ram[offset+((cur_bank & 3)*0x2000)+0x40000]; //B
708            state->cg_latch[1] = ram[offset+((cur_bank & 3)*0x2000)+0x44000]; //R
709            state->cg_latch[2] = ram[offset+((cur_bank & 3)*0x2000)+0x48000]; //G
710            state->cg_latch[3] = ram[offset+((cur_bank & 3)*0x2000)+0x4c000]; //I
711            plane = state->cg_reg[0x07] & 3;
668712
669            if(cg_reg[0x07] & 0x10)
670               return mz2500_cg_latch_compare();
713            if(state->cg_reg[0x07] & 0x10)
714               return mz2500_cg_latch_compare(state);
671715            else
672               return cg_latch[plane];
716               return state->cg_latch[plane];
673717         }
674718      }
675719      break;
676720      case 0x39:
677721      {
678         if(kanji_bank & 0x80) //kanji ROM
722         if(state->kanji_bank & 0x80) //kanji ROM
679723         {
680724            UINT8 *knj_rom = memory_region(machine, "kanji");
681725
682            return knj_rom[(offset & 0x7ff)+((kanji_bank & 0x7f)*0x800)];
726            return knj_rom[(offset & 0x7ff)+((state->kanji_bank & 0x7f)*0x800)];
683727         }
684728         else //PCG RAM
685729         {
r9667r9668
693737      {
694738         UINT8 *dic_rom = memory_region(machine, "dictionary");
695739
696         return dic_rom[(offset & 0x1fff) + ((dic_bank & 0x1f)*0x2000)];
740         return dic_rom[(offset & 0x1fff) + ((state->dic_bank & 0x1f)*0x2000)];
697741      }
698742      break;
699743      case 0x3c:
r9667r9668
714758
715759static void mz2500_ram_write(running_machine *machine, UINT16 offset, UINT8 data, UINT8 bank_num)
716760{
761   mz2500_state *state = machine->driver_data<mz2500_state>();
717762   UINT8 *ram = memory_region(machine, "maincpu");
718   UINT8 cur_bank = bank_val[bank_num];
763   UINT8 cur_bank = state->bank_val[bank_num];
719764
720765//  if(cur_bank >= 0x30 && cur_bank <= 0x33)
721//      printf("CG REG = %02x %02x %02x %02x | offset = %04x | data = %02x\n",cg_reg[0],cg_reg[1],cg_reg[2],cg_reg[3],offset,data);
766//      printf("CG REG = %02x %02x %02x %02x | offset = %04x | data = %02x\n",state->cg_reg[0],state->cg_reg[1],state->cg_reg[2],state->cg_reg[3],offset,data);
722767
723768   switch(cur_bank)
724769   {
r9667r9668
728773      case 0x33:
729774      {
730775         // READ MODIFY WRITE
731         if(cg_reg[0x0e] == 0x3)
776         if(state->cg_reg[0x0e] == 0x3)
732777         {
733778            // ...
734779         }
735780         else
736781         {
737            if((cg_reg[0x05] & 0xc0) == 0x00) //replace
782            if((state->cg_reg[0x05] & 0xc0) == 0x00) //replace
738783            {
739               if(cg_reg[5] & 1) //B
784               if(state->cg_reg[5] & 1) //B
740785               {
741                  ram[offset+((cur_bank & 3)*0x2000)+0x40000] &= ~cg_reg[6];
742                  ram[offset+((cur_bank & 3)*0x2000)+0x40000] |= (cg_reg[4] & 1) ? (data & cg_reg[0] & cg_reg[6]) : 0;
786                  ram[offset+((cur_bank & 3)*0x2000)+0x40000] &= ~state->cg_reg[6];
787                  ram[offset+((cur_bank & 3)*0x2000)+0x40000] |= (state->cg_reg[4] & 1) ? (data & state->cg_reg[0] & state->cg_reg[6]) : 0;
743788               }
744               if(cg_reg[5] & 2) //R
789               if(state->cg_reg[5] & 2) //R
745790               {
746                  ram[offset+((cur_bank & 3)*0x2000)+0x44000] &= ~cg_reg[6];
747                  ram[offset+((cur_bank & 3)*0x2000)+0x44000] |= (cg_reg[4] & 2) ? (data & cg_reg[1] & cg_reg[6]) : 0;
791                  ram[offset+((cur_bank & 3)*0x2000)+0x44000] &= ~state->cg_reg[6];
792                  ram[offset+((cur_bank & 3)*0x2000)+0x44000] |= (state->cg_reg[4] & 2) ? (data & state->cg_reg[1] & state->cg_reg[6]) : 0;
748793               }
749               if(cg_reg[5] & 4) //G
794               if(state->cg_reg[5] & 4) //G
750795               {
751                  ram[offset+((cur_bank & 3)*0x2000)+0x48000] &= ~cg_reg[6];
752                  ram[offset+((cur_bank & 3)*0x2000)+0x48000] |= (cg_reg[4] & 4) ? (data & cg_reg[2] & cg_reg[6]) : 0;
796                  ram[offset+((cur_bank & 3)*0x2000)+0x48000] &= ~state->cg_reg[6];
797                  ram[offset+((cur_bank & 3)*0x2000)+0x48000] |= (state->cg_reg[4] & 4) ? (data & state->cg_reg[2] & state->cg_reg[6]) : 0;
753798               }
754               if(cg_reg[5] & 8) //I
799               if(state->cg_reg[5] & 8) //I
755800               {
756                  ram[offset+((cur_bank & 3)*0x2000)+0x4c000] &= ~cg_reg[6];
757                  ram[offset+((cur_bank & 3)*0x2000)+0x4c000] |= (cg_reg[4] & 8) ? (data & cg_reg[3] & cg_reg[6]) : 0;
801                  ram[offset+((cur_bank & 3)*0x2000)+0x4c000] &= ~state->cg_reg[6];
802                  ram[offset+((cur_bank & 3)*0x2000)+0x4c000] |= (state->cg_reg[4] & 8) ? (data & state->cg_reg[3] & state->cg_reg[6]) : 0;
758803               }
759804            }
760            else if((cg_reg[0x05] & 0xc0) == 0x40) //pset
805            else if((state->cg_reg[0x05] & 0xc0) == 0x40) //pset
761806            {
762               if(cg_reg[5] & 1) //B
807               if(state->cg_reg[5] & 1) //B
763808               {
764809                  ram[offset+((cur_bank & 3)*0x2000)+0x40000] &= ~data;
765                  ram[offset+((cur_bank & 3)*0x2000)+0x40000] |= (cg_reg[4] & 1) ? (data & cg_reg[0]) : 0;
810                  ram[offset+((cur_bank & 3)*0x2000)+0x40000] |= (state->cg_reg[4] & 1) ? (data & state->cg_reg[0]) : 0;
766811               }
767               if(cg_reg[5] & 2) //R
812               if(state->cg_reg[5] & 2) //R
768813               {
769814                  ram[offset+((cur_bank & 3)*0x2000)+0x44000] &= ~data;
770                  ram[offset+((cur_bank & 3)*0x2000)+0x44000] |= (cg_reg[4] & 2) ? (data & cg_reg[1]) : 0;
815                  ram[offset+((cur_bank & 3)*0x2000)+0x44000] |= (state->cg_reg[4] & 2) ? (data & state->cg_reg[1]) : 0;
771816               }
772               if(cg_reg[5] & 4) //G
817               if(state->cg_reg[5] & 4) //G
773818               {
774819                  ram[offset+((cur_bank & 3)*0x2000)+0x48000] &= ~data;
775                  ram[offset+((cur_bank & 3)*0x2000)+0x48000] |= (cg_reg[4] & 4) ? (data & cg_reg[2]) : 0;
820                  ram[offset+((cur_bank & 3)*0x2000)+0x48000] |= (state->cg_reg[4] & 4) ? (data & state->cg_reg[2]) : 0;
776821               }
777               if(cg_reg[5] & 8) //I
822               if(state->cg_reg[5] & 8) //I
778823               {
779824                  ram[offset+((cur_bank & 3)*0x2000)+0x4c000] &= ~data;
780                  ram[offset+((cur_bank & 3)*0x2000)+0x4c000] |= (cg_reg[4] & 8) ? (data & cg_reg[3]) : 0;
825                  ram[offset+((cur_bank & 3)*0x2000)+0x4c000] |= (state->cg_reg[4] & 8) ? (data & state->cg_reg[3]) : 0;
781826               }
782827            }
783828         }
r9667r9668
801846      case 0x39:
802847      {
803848         ram[offset+cur_bank*0x2000] = data;
804         if(kanji_bank & 0x80) //kanji ROM
849         if(state->kanji_bank & 0x80) //kanji ROM
805850         {
806851            //NOP
807852         }
r9667r9668
853898
854899static READ8_HANDLER( mz2500_bank_addr_r )
855900{
856   return bank_addr;
901   mz2500_state *state = space->machine->driver_data<mz2500_state>();
902   return state->bank_addr;
857903}
858904
859905static WRITE8_HANDLER( mz2500_bank_addr_w )
860906{
907   mz2500_state *state = space->machine->driver_data<mz2500_state>();
861908//  printf("%02x\n",data);
862   bank_addr = data & 7;
909   state->bank_addr = data & 7;
863910}
864911
865912static READ8_HANDLER( mz2500_bank_data_r )
866913{
914   mz2500_state *state = space->machine->driver_data<mz2500_state>();
867915   UINT8 res;
868916
869   res = bank_val[bank_addr];
917   res = state->bank_val[state->bank_addr];
870918
871   bank_addr++;
872   bank_addr&=7;
919   state->bank_addr++;
920   state->bank_addr&=7;
873921
874922   return res;
875923}
876924
877925static WRITE8_HANDLER( mz2500_bank_data_w )
878926{
927   mz2500_state *state = space->machine->driver_data<mz2500_state>();
879928//  UINT8 *ROM = memory_region(space->machine, "maincpu");
880929//  static const char *const bank_name[] = { "bank0", "bank1", "bank2", "bank3", "bank4", "bank5", "bank6", "bank7" };
881930
882   bank_val[bank_addr] = data & 0x3f;
931   state->bank_val[state->bank_addr] = data & 0x3f;
883932
884933//  if((data*2) >= 0x70)
885//  printf("%s %02x\n",bank_name[bank_addr],bank_val[bank_addr]*2);
934//  printf("%s %02x\n",bank_name[state->bank_addr],state->bank_val[state->bank_addr]*2);
886935
887//  memory_set_bankptr(space->machine, bank_name[bank_addr], &ROM[bank_val[bank_addr]*0x2000]);
936//  memory_set_bankptr(space->machine, bank_name[state->bank_addr], &ROM[state->bank_val[state->bank_addr]*0x2000]);
888937
889   bank_addr++;
890   bank_addr&=7;
938   state->bank_addr++;
939   state->bank_addr&=7;
891940}
892941
893942static WRITE8_HANDLER( mz2500_kanji_bank_w )
894943{
895   kanji_bank = data;
944   mz2500_state *state = space->machine->driver_data<mz2500_state>();
945   state->kanji_bank = data;
896946}
897947
898948static WRITE8_HANDLER( mz2500_dictionary_bank_w )
899949{
900   dic_bank = data;
950   mz2500_state *state = space->machine->driver_data<mz2500_state>();
951   state->dic_bank = data;
901952}
902953
903954/* 0xf4 - 0xf7 all returns vblank / hblank states */
r9667r9668
9521003
9531004static WRITE8_HANDLER( mz2500_tv_crtc_w )
9541005{
1006   mz2500_state *state = space->machine->driver_data<mz2500_state>();
9551007   switch(offset)
9561008   {
957      case 0: text_reg_index = data; break;
1009      case 0: state->text_reg_index = data; break;
9581010      case 1:
959         text_reg[text_reg_index] = data;
1011         state->text_reg[state->text_reg_index] = data;
9601012
9611013         #if 0
962         //printf("[%02x] <- %02x\n",text_reg_index,data);
1014         //printf("[%02x] <- %02x\n",state->text_reg_index,data);
9631015         popmessage("(%02x %02x) (%02x %02x %02x %02x) (%02x %02x %02x) (%02x %02x %02x %02x)"
964         ,text_reg[0] & ~0x1e,text_reg[3]
965         ,text_reg[4],text_reg[5],text_reg[6],text_reg[7]
966         ,text_reg[8],text_reg[10],text_reg[11]
967         ,text_reg[12],text_reg[13],text_reg[14],text_reg[15]);
1016         ,state->text_reg[0] & ~0x1e,state->text_reg[3]
1017         ,state->text_reg[4],state->text_reg[5],state->text_reg[6],state->text_reg[7]
1018         ,state->text_reg[8],state->text_reg[10],state->text_reg[11]
1019         ,state->text_reg[12],state->text_reg[13],state->text_reg[14],state->text_reg[15]);
9681020
9691021         #endif
970         //popmessage("%d %02x %d %02x %d %d",text_reg[3],text_reg[4],text_reg[5],text_reg[6],text_reg[7]*8,text_reg[8]*8);
1022         //popmessage("%d %02x %d %02x %d %d",state->text_reg[3],state->text_reg[4],state->text_reg[5],state->text_reg[6],state->text_reg[7]*8,state->text_reg[8]*8);
9711023
9721024         mz2500_reconfigure_screen(space->machine);
9731025
974         if(text_reg_index == 0x0a) // set 256 color palette
1026         if(state->text_reg_index == 0x0a) // set 256 color palette
9751027         {
9761028            int i,r,g,b;
9771029            UINT8 b_param,r_param,g_param;
r9667r9668
10001052               palette_set_color_rgb(space->machine, i+0x100,pal3bit(r),pal3bit(g),pal3bit(b));
10011053            }
10021054         }
1003         if(text_reg_index >= 0x80 && text_reg_index <= 0x8f) //Bitmap 16 clut registers
1055         if(state->text_reg_index >= 0x80 && state->text_reg_index <= 0x8f) //Bitmap 16 clut registers
10041056         {
10051057            /*
10061058                ---x ---- priority
10071059                ---- xxxx clut number
10081060                */
1009            clut16[text_reg_index & 0xf] = data & 0x1f;
1010            //printf("%02x -> [%02x]\n",text_reg[text_reg_index],text_reg_index);
1061            state->clut16[state->text_reg_index & 0xf] = data & 0x1f;
1062            //printf("%02x -> [%02x]\n",state->text_reg[state->text_reg_index],state->text_reg_index);
10111063
10121064            {
10131065               int i;
10141066
10151067               for(i=0;i<0x10;i++)
10161068               {
1017                  clut256[(text_reg_index & 0xf) | (i << 4)] = (((data & 0x1f) << 4) | i);
1069                  state->clut256[(state->text_reg_index & 0xf) | (i << 4)] = (((data & 0x1f) << 4) | i);
10181070               }
10191071            }
10201072         }
10211073         break;
10221074      case 2: /* CG Mask reg (priority mixer) */
1023         cg_mask = data;
1075         state->cg_mask = data;
10241076         break;
10251077      case 3:
10261078         /* Font size reg */
1027         text_font_reg = data & 1;
1079         state->text_font_reg = data & 1;
10281080         mz2500_reconfigure_screen(space->machine);
10291081         break;
10301082   }
r9667r9668
10321084
10331085static WRITE8_HANDLER( mz2500_irq_sel_w )
10341086{
1035   irq_sel = data;
1036   //printf("%02x\n",irq_sel);
1087   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1088   state->irq_sel = data;
1089   //printf("%02x\n",state->irq_sel);
10371090   // activeness is trusted, see Tower of Druaga
1038   irq_mask[0] = (data & 0x08); //CRTC
1039   irq_mask[1] = (data & 0x04); //i8253
1040   irq_mask[2] = (data & 0x02); //printer
1041   irq_mask[3] = (data & 0x01); //RP5c15
1091   state->irq_mask[0] = (data & 0x08); //CRTC
1092   state->irq_mask[1] = (data & 0x04); //i8253
1093   state->irq_mask[2] = (data & 0x02); //printer
1094   state->irq_mask[3] = (data & 0x01); //RP5c15
10421095}
10431096
10441097static WRITE8_HANDLER( mz2500_irq_data_w )
10451098{
1046   if(irq_sel & 0x80)
1047      irq_vector[0] = data; //CRTC
1048   if(irq_sel & 0x40)
1049      irq_vector[1] = data; //i8253
1050   if(irq_sel & 0x20)
1051      irq_vector[2] = data; //printer
1052   if(irq_sel & 0x10)
1053      irq_vector[3] = data; //RP5c15
1099   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1100   if(state->irq_sel & 0x80)
1101      state->irq_vector[0] = data; //CRTC
1102   if(state->irq_sel & 0x40)
1103      state->irq_vector[1] = data; //i8253
1104   if(state->irq_sel & 0x20)
1105      state->irq_vector[2] = data; //printer
1106   if(state->irq_sel & 0x10)
1107      state->irq_vector[3] = data; //RP5c15
10541108
1055//  popmessage("%02x %02x %02x %02x",irq_vector[0],irq_vector[1],irq_vector[2],irq_vector[3]);
1109//  popmessage("%02x %02x %02x %02x",state->irq_vector[0],state->irq_vector[1],state->irq_vector[2],state->irq_vector[3]);
10561110}
10571111
10581112static WRITE8_HANDLER( mz2500_fdc_w )
r9667r9668
11121166   AM_RANGE(0xe000, 0xffff) AM_READWRITE(bank7_r,bank7_w)
11131167ADDRESS_MAP_END
11141168
1115static UINT32 rom_index;
1116static UINT8 hrom_index,lrom_index;
11171169
11181170static READ8_HANDLER( mz2500_rom_r )
11191171{
1172   mz2500_state *state = space->machine->driver_data<mz2500_state>();
11201173   UINT8 *rom = memory_region(space->machine, "rom");
11211174   UINT8 res;
11221175
1123   lrom_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B));
1176   state->lrom_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B));
11241177
1125   rom_index = (rom_index & 0xffff00) | (lrom_index & 0xff);
1178   state->rom_index = (state->rom_index & 0xffff00) | (state->lrom_index & 0xff);
11261179
1127   res = rom[rom_index];
1180   res = rom[state->rom_index];
11281181
11291182   return res;
11301183}
11311184
11321185static WRITE8_HANDLER( mz2500_rom_w )
11331186{
1134   hrom_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B));
1187   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1188   state->hrom_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B));
11351189
1136   rom_index = (data << 8) | (rom_index & 0x0000ff) | ((hrom_index & 0xff)<<16);
1190   state->rom_index = (data << 8) | (state->rom_index & 0x0000ff) | ((state->hrom_index & 0xff)<<16);
11371191   //printf("%02x\n",data);
11381192}
11391193
11401194/* sets 16 color entries out of 4096 possible combinations */
11411195static WRITE8_HANDLER( palette4096_io_w )
11421196{
1143   static UINT8 r[16],g[16],b[16];
1197   mz2500_state *state = space->machine->driver_data<mz2500_state>();
11441198   UINT8 pal_index;
11451199   UINT8 pal_entry;
11461200
r9667r9668
11481202   pal_entry = (pal_index & 0x1e) >> 1;
11491203
11501204   if(pal_index & 1)
1151      g[pal_entry] = (data & 0x0f);
1205      state->pal[pal_entry].g = (data & 0x0f);
11521206   else
11531207   {
1154      r[pal_entry] = (data & 0xf0) >> 4;
1155      b[pal_entry] = data & 0x0f;
1208      state->pal[pal_entry].r = (data & 0xf0) >> 4;
1209      state->pal[pal_entry].b = data & 0x0f;
11561210   }
11571211
1158   palette_set_color_rgb(space->machine, pal_entry+0x10,pal4bit(r[pal_entry]),pal4bit(g[pal_entry]),pal4bit(b[pal_entry]));
1212   palette_set_color_rgb(space->machine, pal_entry+0x10, pal4bit(state->pal[pal_entry].r), pal4bit(state->pal[pal_entry].g), pal4bit(state->pal[pal_entry].b));
11591213}
11601214
11611215static READ8_DEVICE_HANDLER( mz2500_wd17xx_r )
11621216{
1163   return wd17xx_r(device, offset) ^ fdc_reverse;
1217   mz2500_state *state = device->machine->driver_data<mz2500_state>();
1218   return wd17xx_r(device, offset) ^ state->fdc_reverse;
11641219}
11651220
11661221static WRITE8_DEVICE_HANDLER( mz2500_wd17xx_w )
11671222{
1168   wd17xx_w(device, offset, data ^ fdc_reverse);
1223   mz2500_state *state = device->machine->driver_data<mz2500_state>();
1224   wd17xx_w(device, offset, data ^ state->fdc_reverse);
11691225}
11701226
11711227static READ8_HANDLER( mz2500_bplane_latch_r )
11721228{
1173   if(cg_reg[7] & 0x10)
1174      return mz2500_cg_latch_compare();
1229   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1230   if(state->cg_reg[7] & 0x10)
1231      return mz2500_cg_latch_compare(state);
11751232   else
1176      return cg_latch[0];
1233      return state->cg_latch[0];
11771234}
11781235
11791236
11801237static READ8_HANDLER( mz2500_rplane_latch_r )
11811238{
1182   if(cg_reg[0x07] & 0x10)
1239   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1240   if(state->cg_reg[0x07] & 0x10)
11831241   {
11841242      UINT8 vblank_bit;
11851243
1186      vblank_bit = space->machine->primary_screen->vblank() ? 0 : 0x80 | cg_clear_flag;
1244      vblank_bit = space->machine->primary_screen->vblank() ? 0 : 0x80 | state->cg_clear_flag;
11871245
11881246      return vblank_bit;
11891247   }
11901248   else
1191      return cg_latch[1];
1249      return state->cg_latch[1];
11921250}
11931251
11941252static READ8_HANDLER( mz2500_gplane_latch_r )
11951253{
1196   return cg_latch[2];
1254   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1255   return state->cg_latch[2];
11971256}
11981257
11991258static READ8_HANDLER( mz2500_iplane_latch_r )
12001259{
1201   return cg_latch[3];
1260   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1261   return state->cg_latch[3];
12021262}
12031263
12041264/*
r9667r9668
12331293
12341294static WRITE8_HANDLER( mz2500_cg_addr_w )
12351295{
1236   cg_reg_index = data;
1296   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1297   state->cg_reg_index = data;
12371298}
12381299
12391300static WRITE8_HANDLER( mz2500_cg_data_w )
12401301{
1241   cg_reg[cg_reg_index & 0x1f] = data;
1302   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1303   state->cg_reg[state->cg_reg_index & 0x1f] = data;
12421304
1243   if((cg_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg
1244      cg_reg[0x09] = 0;
1305   if((state->cg_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg
1306      state->cg_reg[0x09] = 0;
12451307
1246   if((cg_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg
1247      cg_reg[0x0b] = 0;
1308   if((state->cg_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg
1309      state->cg_reg[0x0b] = 0;
12481310
1249   if((cg_reg_index & 0x1f) == 0x05 && (cg_reg[0x05] & 0xc0) == 0x80) //clear bitmap buffer
1311   if((state->cg_reg_index & 0x1f) == 0x05 && (state->cg_reg[0x05] & 0xc0) == 0x80) //clear bitmap buffer
12501312   {
12511313      UINT32 i;
12521314      UINT8 *vram = memory_region(space->machine, "maincpu");
12531315      UINT32 layer_bank;
12541316
1255      layer_bank = (cg_reg[0x0e] & 0x80) ? 0x10000 : 0x00000;
1317      layer_bank = (state->cg_reg[0x0e] & 0x80) ? 0x10000 : 0x00000;
12561318
12571319      /* TODO: this isn't yet 100% accurate */
1258      if(cg_reg[0x05] & 1)
1320      if(state->cg_reg[0x05] & 1)
12591321      {
12601322         for(i=0;i<0x4000;i++)
12611323            vram[i+0x40000+layer_bank] = 0x00; //clear B
12621324      }
1263      if(cg_reg[0x05] & 2)
1325      if(state->cg_reg[0x05] & 2)
12641326      {
12651327         for(i=0;i<0x4000;i++)
12661328            vram[i+0x44000+layer_bank] = 0x00; //clear R
12671329      }
1268      if(cg_reg[0x05] & 4)
1330      if(state->cg_reg[0x05] & 4)
12691331      {
12701332         for(i=0;i<0x4000;i++)
12711333            vram[i+0x48000+layer_bank] = 0x00; //clear G
12721334      }
1273      if(cg_reg[0x05] & 8)
1335      if(state->cg_reg[0x05] & 8)
12741336      {
12751337         for(i=0;i<0x4000;i++)
12761338            vram[i+0x4c000+layer_bank] = 0x00; //clear I
12771339      }
1278      cg_clear_flag = 1;
1340      state->cg_clear_flag = 1;
12791341   }
12801342
12811343   {
12821344      mz2500_reconfigure_screen(space->machine);
12831345   }
12841346
1285   if(cg_reg_index & 0x80) //enable auto-inc
1286      cg_reg_index = (cg_reg_index & 0xfc) | ((cg_reg_index + 1) & 0x03);
1347   if(state->cg_reg_index & 0x80) //enable auto-inc
1348      state->cg_reg_index = (state->cg_reg_index & 0xfc) | ((state->cg_reg_index + 1) & 0x03);
12871349}
12881350
12891351static WRITE8_HANDLER( timer_w )
r9667r9668
12981360   pit8253_gate1_w(pit8253, 1);
12991361}
13001362
1301static UINT8 joy_mode;
13021363
13031364static READ8_HANDLER( mz2500_joystick_r )
13041365{
1366   mz2500_state *state = space->machine->driver_data<mz2500_state>();
13051367   UINT8 res,dir_en,in_r;
13061368
13071369   res = 0xff;
1308   in_r = ~input_port_read(space->machine, joy_mode & 0x40 ? "JOY_2P" : "JOY_1P");
1370   in_r = ~input_port_read(space->machine, state->joy_mode & 0x40 ? "JOY_2P" : "JOY_1P");
13091371
1310   if(joy_mode & 0x40)
1372   if(state->joy_mode & 0x40)
13111373   {
1312      if(!(joy_mode & 0x04)) res &= ~0x20;
1313      if(!(joy_mode & 0x08)) res &= ~0x10;
1314      dir_en = (joy_mode & 0x20) ? 0 : 1;
1374      if(!(state->joy_mode & 0x04)) res &= ~0x20;
1375      if(!(state->joy_mode & 0x08)) res &= ~0x10;
1376      dir_en = (state->joy_mode & 0x20) ? 0 : 1;
13151377   }
13161378   else
13171379   {
1318      if(!(joy_mode & 0x01)) res &= ~0x20;
1319      if(!(joy_mode & 0x02)) res &= ~0x10;
1320      dir_en = (joy_mode & 0x10) ? 0 : 1;
1380      if(!(state->joy_mode & 0x01)) res &= ~0x20;
1381      if(!(state->joy_mode & 0x02)) res &= ~0x10;
1382      dir_en = (state->joy_mode & 0x10) ? 0 : 1;
13211383   }
13221384
13231385   if(dir_en)
r9667r9668
13301392
13311393static WRITE8_HANDLER( mz2500_joystick_w )
13321394{
1333   joy_mode = data;
1395   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1396   state->joy_mode = data;
13341397}
13351398
1336static UINT16 kanji_index;
13371399
13381400static READ8_HANDLER( mz2500_kanji_r )
13391401{
1402   mz2500_state *state = space->machine->driver_data<mz2500_state>();
13401403   UINT8 *knj2_rom = memory_region(space->machine, "kanji2");
13411404
13421405   printf("Read from kanji 2 ROM\n");
13431406
1344   return knj2_rom[(kanji_index << 1) | (offset & 1)];
1407   return knj2_rom[(state->kanji_index << 1) | (offset & 1)];
13451408}
13461409
13471410static WRITE8_HANDLER( mz2500_kanji_w )
13481411{
1349   (offset & 1) ? (kanji_index = (data << 8) | (kanji_index & 0xff)) : (kanji_index = (data & 0xff) | (kanji_index & 0xff00));
1412   mz2500_state *state = space->machine->driver_data<mz2500_state>();
1413   (offset & 1) ? (state->kanji_index = (data << 8) | (state->kanji_index & 0xff)) : (state->kanji_index = (data & 0xff) | (state->kanji_index & 0xff00));
13501414}
13511415
13521416static READ8_DEVICE_HANDLER( rp5c15_8_r )
r9667r9668
13671431   rp5c15_w(device,rtc_index,data,0xff);
13681432}
13691433
1370static UINT32 emm_offset;
13711434
13721435static READ8_HANDLER( mz2500_emm_data_r )
13731436{
1437   mz2500_state *state = space->machine->driver_data<mz2500_state>();
13741438   UINT8 *emm_ram = memory_region(space->machine, "emm");
13751439   UINT8 emm_lo_index;
13761440
13771441   emm_lo_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B));
13781442
1379   emm_offset = (emm_offset & 0xffff00) | (emm_lo_index & 0xff);
1443   state->emm_offset = (state->emm_offset & 0xffff00) | (emm_lo_index & 0xff);
13801444
1381   if(emm_offset < 0x100000) //emm max size
1382      return emm_ram[emm_offset];
1445   if(state->emm_offset < 0x100000) //emm max size
1446      return emm_ram[state->emm_offset];
13831447
13841448   return 0xff;
13851449}
13861450
13871451static WRITE8_HANDLER( mz2500_emm_addr_w )
13881452{
1453   mz2500_state *state = space->machine->driver_data<mz2500_state>();
13891454   UINT8 emm_hi_index;
13901455
13911456   emm_hi_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B));
13921457
1393   emm_offset = ((emm_hi_index & 0xff) << 16) | ((data & 0xff) << 8) | (emm_offset & 0xff);
1458   state->emm_offset = ((emm_hi_index & 0xff) << 16) | ((data & 0xff) << 8) | (state->emm_offset & 0xff);
13941459}
13951460
13961461static WRITE8_HANDLER( mz2500_emm_data_w )
13971462{
1463   mz2500_state *state = space->machine->driver_data<mz2500_state>();
13981464   UINT8 *emm_ram = memory_region(space->machine, "emm");
13991465   UINT8 emm_lo_index;
14001466
14011467   emm_lo_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B));
14021468
1403   emm_offset = (emm_offset & 0xffff00) | (emm_lo_index & 0xff);
1469   state->emm_offset = (state->emm_offset & 0xffff00) | (emm_lo_index & 0xff);
14041470
1405   if(emm_offset < 0x100000) //emm max size
1406      emm_ram[emm_offset] = data;
1471   if(state->emm_offset < 0x100000) //emm max size
1472      emm_ram[state->emm_offset] = data;
14071473}
14081474
14091475static ADDRESS_MAP_START(mz2500_io, ADDRESS_SPACE_IO, 8)
r9667r9668
16231689   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
16241690INPUT_PORTS_END
16251691
1626static void mz2500_reset(UINT8 type)
1692static void mz2500_reset(mz2500_state *state, UINT8 type)
16271693{
16281694   int i;
16291695
16301696   for(i=0;i<8;i++)
1631      bank_val[i] = bank_reset_val[type][i];
1697      state->bank_val[i] = bank_reset_val[type][i];
16321698}
16331699
16341700static MACHINE_RESET(mz2500)
16351701{
1702   mz2500_state *state = machine->driver_data<mz2500_state>();
16361703   UINT8 *RAM = memory_region(machine, "maincpu");
16371704   UINT8 *IPL = memory_region(machine, "ipl");
16381705   UINT32 i;
16391706
1640   mz2500_reset(IPL_RESET);
1707   mz2500_reset(state, IPL_RESET);
16411708
1642   //irq_vector[0] = 0xef; /* RST 28h - vblank */
1709   //state->irq_vector[0] = 0xef; /* RST 28h - vblank */
16431710
1644   text_col_size = 0;
1645   text_font_reg = 0;
1711   state->text_col_size = 0;
1712   state->text_font_reg = 0;
16461713
16471714   /* copy IPL to its natural bank ROM/RAM position */
16481715   for(i=0;i<0x8000;i++)
r9667r9668
16571724
16581725   /* disable IRQ */
16591726   for(i=0;i<4;i++)
1660      irq_mask[i] = 0;
1727      state->irq_mask[i] = 0;
16611728
1662   kanji_bank = 0;
1729   state->kanji_bank = 0;
16631730
1664   cg_clear_flag = 0;
1731   state->cg_clear_flag = 0;
16651732
16661733   beep_set_frequency(machine->device("beeper"),4096);
16671734   beep_set_state(machine->device("beeper"),0);
16681735
1669//   monitor_type = input_port_read(machine,"DSW1") & 0x40 ? 1 : 0;
1736//   state->monitor_type = input_port_read(machine,"DSW1") & 0x40 ? 1 : 0;
16701737}
16711738
16721739static const gfx_layout mz2500_cg_layout =
r9667r9668
17361803
17371804static INTERRUPT_GEN( mz2500_vbl )
17381805{
1739   if(irq_mask[0])
1740      cpu_set_input_line_and_vector(device, 0, HOLD_LINE, irq_vector[0]);
1806   mz2500_state *state = device->machine->driver_data<mz2500_state>();
1807   if(state->irq_mask[0])
1808      cpu_set_input_line_and_vector(device, 0, HOLD_LINE, state->irq_vector[0]);
17411809
1742   cg_clear_flag = 0;
1810   state->cg_clear_flag = 0;
17431811}
17441812
17451813static READ8_DEVICE_HANDLER( mz2500_porta_r )
r9667r9668
17771845
17781846static WRITE8_DEVICE_HANDLER( mz2500_portc_w )
17791847{
1780   static UINT8 reset_lines;
1781
1848   mz2500_state *state = device->machine->driver_data<mz2500_state>();
17821849   /*
17831850   ---- x--- 0->1 transition = IPL reset
17841851   ---- -x-- beeper state
r9667r9668
17861853   */
17871854
17881855   /* work RAM reset */
1789   if((reset_lines & 0x02) == 0x00 && (data & 0x02))
1856   if((state->old_portc & 0x02) == 0x00 && (data & 0x02))
17901857   {
1791      mz2500_reset(WRAM_RESET);
1858      mz2500_reset(state, WRAM_RESET);
17921859      /* correct? */
17931860      cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE);
17941861   }
r9667r9668
17961863   /* bit 2 is speaker */
17971864
17981865   /* IPL reset */
1799   if((reset_lines & 0x08) == 0x00 && (data & 0x08))
1800      mz2500_reset(IPL_RESET);
1866   if((state->old_portc & 0x08) == 0x00 && (data & 0x08))
1867      mz2500_reset(state, IPL_RESET);
18011868
1802   reset_lines = data;
1869   state->old_portc = data;
18031870
18041871   beep_set_state(device->machine->device("beeper"),data & 0x04);
18051872
r9667r9668
18191886
18201887static WRITE8_DEVICE_HANDLER( mz2500_pio1_porta_w )
18211888{
1822   static UINT8 prev_col_val;
1889   mz2500_state *state = device->machine->driver_data<mz2500_state>();
18231890//  printf("%02x\n",data);
18241891
1825   if(prev_col_val != ((data & 0x20) >> 5))
1892   if(state->prev_col_val != ((data & 0x20) >> 5))
18261893   {
1827      text_col_size = ((data & 0x20) >> 5);
1828      prev_col_val = text_col_size;
1894      state->text_col_size = ((data & 0x20) >> 5);
1895      state->prev_col_val = state->text_col_size;
18291896      mz2500_reconfigure_screen(device->machine);
18301897   }
1831   key_mux = data & 0x1f;
1898   state->key_mux = data & 0x1f;
18321899}
18331900
1834static UINT8 pio_latchb;
18351901
18361902static READ8_DEVICE_HANDLER( mz2500_pio1_porta_r )
18371903{
1904   mz2500_state *state = device->machine->driver_data<mz2500_state>();
18381905   static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3",
18391906                                           "KEY4", "KEY5", "KEY6", "KEY7",
18401907                                           "KEY8", "KEY9", "KEYA", "KEYB",
18411908                                           "KEYC", "KEYD", "UNUSED", "UNUSED" };
18421909
1843   if(((key_mux & 0x10) == 0x00) || ((key_mux & 0x0f) == 0x0f)) //status read
1910   if(((state->key_mux & 0x10) == 0x00) || ((state->key_mux & 0x0f) == 0x0f)) //status read
18441911   {
18451912      int res,i;
18461913
r9667r9668
18481915      for(i=0;i<0xe;i++)
18491916         res &= input_port_read(device->machine, keynames[i]);
18501917
1851      pio_latchb = res;
1918      state->pio_latchb = res;
18521919
18531920      return res;
18541921   }
18551922
1856   pio_latchb = input_port_read(device->machine, keynames[key_mux & 0xf]);
1923   state->pio_latchb = input_port_read(device->machine, keynames[state->key_mux & 0xf]);
18571924
1858   return input_port_read(device->machine, keynames[key_mux & 0xf]);
1925   return input_port_read(device->machine, keynames[state->key_mux & 0xf]);
18591926}
18601927
18611928#if 0
18621929static READ8_DEVICE_HANDLER( mz2500_pio1_portb_r )
18631930{
1864   return pio_latchb;
1931   mz2500_state *state = device->machine->driver_data<mz2500_state>();
1932   return state->pio_latchb;
18651933}
18661934#endif
18671935
r9667r9668
18761944   DEVCB_NULL
18771945};
18781946
1879static UINT8 ym_porta;
18801947
18811948static READ8_DEVICE_HANDLER( opn_porta_r )
18821949{
1883   return ym_porta;
1950   mz2500_state *state = device->machine->driver_data<mz2500_state>();
1951   return state->ym_porta;
18841952}
18851953
18861954static WRITE8_DEVICE_HANDLER( opn_porta_w )
18871955{
1956   mz2500_state *state = device->machine->driver_data<mz2500_state>();
18881957   /*
18891958    ---- x--- mouse select
18901959    ---- -x-- palette bit (16/4096 colors)
18911960    ---- --x- floppy reverse bit (controls wd17xx bits in command registers)
18921961    */
18931962
1894   fdc_reverse = (data & 2) ? 0x00 : 0xff;
1895   pal_select = (data & 4) ? 1 : 0;
1963   state->fdc_reverse = (data & 2) ? 0x00 : 0xff;
1964   state->pal_select = (data & 4) ? 1 : 0;
18961965
1897   ym_porta = data;
1966   state->ym_porta = data;
18981967}
18991968
19001969static const ym2203_interface ym2203_interface_1 =
r9667r9668
19532022
19542023static WRITE_LINE_DEVICE_HANDLER( pit8253_clk0_irq )
19552024{
1956   if(irq_mask[1]/* && state & 1*/)
1957      cputag_set_input_line_and_vector(device->machine, "maincpu", 0, HOLD_LINE,irq_vector[1]);
2025   mz2500_state *drvstate = device->machine->driver_data<mz2500_state>();
2026   if(drvstate->irq_mask[1]/* && state & 1*/)
2027      cputag_set_input_line_and_vector(device->machine, "maincpu", 0, HOLD_LINE,drvstate->irq_vector[1]);
19582028}
19592029
19602030static const struct pit8253_config mz2500_pit8253_intf =
r9667r9668
19802050
19812051static void mz2500_rtc_alarm_irq(int state)
19822052{
2053   //mz2500_state *drvstate = device->machine->driver_data<mz2500_state>();
19832054   /* TODO: doesn't work yet */
1984//  if(irq_mask[3] && state & 1)
1985//      cputag_set_input_line_and_vector(device, "maincpu", 0, HOLD_LINE,irq_vector[3]);
2055//  if(drvstate->irq_mask[3] && state & 1)
2056//      cputag_set_input_line_and_vector(device, "maincpu", 0, HOLD_LINE,drvstate->irq_vector[3]);
19862057}
19872058
19882059static const struct rp5c15_interface rtc_intf =
r9667r9668
20002071   NULL
20012072};
20022073
2003static MACHINE_CONFIG_START( mz2500, driver_device )
2074static MACHINE_CONFIG_START( mz2500, mz2500_state )
20042075    /* basic machine hardware */
20052076    MDRV_CPU_ADD("maincpu", Z80, 6000000)
20062077    MDRV_CPU_PROGRAM_MAP(mz2500_map)
src/mess/drivers/multi8.c
r9667r9668
1818#include "machine/i8255a.h"
1919#include "sound/beep.h"
2020
21static UINT8 mcu_init;
22static UINT8 keyb_press,keyb_press_flag,shift_press_flag,display_reg;
23static UINT16 cursor_addr,cursor_raster;
24static UINT8 vram_bank;
25static UINT8 pen_clut[8],bw_mode;
2621
22class multi8_state : public driver_device
23{
24public:
25   multi8_state(running_machine &machine, const driver_device_config_base &config)
26      : driver_device(machine, config) { }
27
28   UINT8 mcu_init;
29   UINT8 keyb_press;
30   UINT8 keyb_press_flag;
31   UINT8 shift_press_flag;
32   UINT8 display_reg;
33   UINT16 cursor_addr;
34   UINT16 cursor_raster;
35   UINT8 vram_bank;
36   UINT8 pen_clut[8];
37   UINT8 bw_mode;
38   int addr_latch;
39};
40
41
42
2743static VIDEO_START( multi8 )
2844{
29   keyb_press = keyb_press_flag = shift_press_flag = display_reg = 0;
30   cursor_addr = cursor_raster = 0;
31   for (bw_mode = 0; bw_mode < 8; bw_mode++) pen_clut[bw_mode]=0;
32   vram_bank = 8;
33   bw_mode = 0;
45   multi8_state *state = machine->driver_data<multi8_state>();
46   state->keyb_press = state->keyb_press_flag = state->shift_press_flag = state->display_reg = 0;
47   state->cursor_addr = state->cursor_raster = 0;
48   for (state->bw_mode = 0; state->bw_mode < 8; state->bw_mode++) state->pen_clut[state->bw_mode]=0;
49   state->vram_bank = 8;
50   state->bw_mode = 0;
3451}
3552
3653static VIDEO_UPDATE( multi8 )
3754{
55   multi8_state *state = screen->machine->driver_data<multi8_state>();
3856   int x,y,count;
3957   int x_width;
4058   int xi,yi;
r9667r9668
4361
4462   count = 0x0000;
4563
46   x_width = (display_reg & 0x40) ? 640 : 320;
64   x_width = (state->display_reg & 0x40) ? 640 : 320;
4765
4866   for(y=0;y<200;y++)
4967   {
r9667r9668
5775            pen_r = (vram[count | 0x4000] >> (7-xi)) & 1;
5876            pen_g = (vram[count | 0x8000] >> (7-xi)) & 1;
5977
60            if(bw_mode)
78            if(state->bw_mode)
6179            {
62               pen_b = (display_reg & 1) ? pen_b : 0;
63               pen_r = (display_reg & 2) ? pen_r : 0;
64               pen_g = (display_reg & 4) ? pen_g : 0;
80               pen_b = (state->display_reg & 1) ? pen_b : 0;
81               pen_r = (state->display_reg & 2) ? pen_r : 0;
82               pen_g = (state->display_reg & 4) ? pen_g : 0;
6583
6684               color = ((pen_b) | (pen_r) | (pen_g)) ? 7 : 0;
6785            }
6886            else
6987               color = (pen_b) | (pen_r << 1) | (pen_g << 2);
7088
71            *BITMAP_ADDR16(bitmap, y, x+xi) = screen->machine->pens[pen_clut[color]];
89            *BITMAP_ADDR16(bitmap, y, x+xi) = screen->machine->pens[state->pen_clut[color]];
7290         }
7391         count++;
7492      }
7593   }
7694
77   x_width = (display_reg & 0x40) ? 80 : 40;
95   x_width = (state->display_reg & 0x40) ? 80 : 40;
7896   count = 0xc000;
7997
8098   for(y=0;y<25;y++)
r9667r9668
83101      {
84102         int tile = vram[count];
85103         int attr = vram[count+0x800];
86         int color = (display_reg & 0x80) ? 7 : (attr & 0x07);
104         int color = (state->display_reg & 0x80) ? 7 : (attr & 0x07);
87105
88106         for(yi=0;yi<8;yi++)
89107         {
r9667r9668
104122         //drawgfx_opaque(bitmap, cliprect, screen->machine->gfx[0], tile,color >> 5, 0, 0, x*8, y*8);
105123
106124         // draw cursor
107         if(cursor_addr+0xc000 == count)
125         if(state->cursor_addr+0xc000 == count)
108126         {
109127            int xc,yc,cursor_on;
110128
111129            cursor_on = 0;
112            switch(cursor_raster & 0x60)
130            switch(state->cursor_raster & 0x60)
113131            {
114132               case 0x00: cursor_on = 1; break; //always on
115133               case 0x20: cursor_on = 0; break; //always off
r9667r9668
119137
120138            if(cursor_on)
121139            {
122               for(yc=0;yc<(8-(cursor_raster & 7));yc++)
140               for(yc=0;yc<(8-(state->cursor_raster & 7));yc++)
123141               {
124142                  for(xc=0;xc<8;xc++)
125143                  {
r9667r9668
129147            }
130148         }
131149
132         (display_reg & 0x40) ? count++ : count+=2;
150         (state->display_reg & 0x40) ? count++ : count+=2;
133151      }
134152   }
135153    return 0;
r9667r9668
137155
138156static WRITE8_HANDLER( multi8_6845_w )
139157{
140   static int addr_latch;
141
158   multi8_state *state = space->machine->driver_data<multi8_state>();
142159   if(offset == 0)
143160   {
144      addr_latch = data;
161      state->addr_latch = data;
145162      //mc6845_address_w(space->machine->device("crtc"), 0,data);
146163   }
147164   else
148165   {
149      if(addr_latch == 0x0a)
150         cursor_raster = data;
151      if(addr_latch == 0x0e)
152         cursor_addr = ((data<<8) & 0x3f00) | (cursor_addr & 0xff);
153      else if(addr_latch == 0x0f)
154         cursor_addr = (cursor_addr & 0x3f00) | (data & 0xff);
166      if(state->addr_latch == 0x0a)
167         state->cursor_raster = data;
168      if(state->addr_latch == 0x0e)
169         state->cursor_addr = ((data<<8) & 0x3f00) | (state->cursor_addr & 0xff);
170      else if(state->addr_latch == 0x0f)
171         state->cursor_addr = (state->cursor_addr & 0x3f00) | (data & 0xff);
155172
156173      //mc6845_register_w(space->machine->device("crtc"), 0,data);
157174   }
r9667r9668
159176
160177static READ8_HANDLER( key_input_r )
161178{
162   if(mcu_init == 0){ mcu_init++;   return 3; }
179   multi8_state *state = space->machine->driver_data<multi8_state>();
180   if(state->mcu_init == 0){ state->mcu_init++;   return 3; }
163181
164   keyb_press_flag &= 0xfe;
182   state->keyb_press_flag &= 0xfe;
165183
166   return keyb_press;
184   return state->keyb_press;
167185}
168186
169187static READ8_HANDLER( key_status_r )
170188{
171   if(mcu_init == 0){            return 1; }
172   if(mcu_init == 1){ mcu_init++;   return 1; }
173   if(mcu_init == 2){ mcu_init++;   return 0; }
189   multi8_state *state = space->machine->driver_data<multi8_state>();
190   if(state->mcu_init == 0){            return 1; }
191   if(state->mcu_init == 1){ state->mcu_init++;   return 1; }
192   if(state->mcu_init == 2){ state->mcu_init++;   return 0; }
174193
175   return keyb_press_flag | (shift_press_flag << 7);
194   return state->keyb_press_flag | (state->shift_press_flag << 7);
176195}
177196
178197static READ8_HANDLER( multi8_vram_r )
179198{
199   multi8_state *state = space->machine->driver_data<multi8_state>();
180200   UINT8 *vram = memory_region(space->machine, "vram");
181201   UINT8 *wram = memory_region(space->machine, "wram");
182202   UINT8 res;
183203
184   if(!(vram_bank & 0x10)) //select plain work ram
204   if(!(state->vram_bank & 0x10)) //select plain work ram
185205      return wram[offset];
186206
187207   res = 0xff;
188   if(!(vram_bank & 1)) { res &= vram[offset | 0x0000]; }
189   if(!(vram_bank & 2)) { res &= vram[offset | 0x4000]; }
190   if(!(vram_bank & 4)) { res &= vram[offset | 0x8000]; }
191   if(!(vram_bank & 8)) { res &= vram[offset | 0xc000]; }
208   if(!(state->vram_bank & 1)) { res &= vram[offset | 0x0000]; }
209   if(!(state->vram_bank & 2)) { res &= vram[offset | 0x4000]; }
210   if(!(state->vram_bank & 4)) { res &= vram[offset | 0x8000]; }
211   if(!(state->vram_bank & 8)) { res &= vram[offset | 0xc000]; }
192212
193213   return res;
194214}
195215
196216static WRITE8_HANDLER( multi8_vram_w )
197217{
218   multi8_state *state = space->machine->driver_data<multi8_state>();
198219   UINT8 *vram = memory_region(space->machine, "vram");
199220   UINT8 *wram = memory_region(space->machine, "wram");
200221
201   if(!(vram_bank & 0x10)) //select plain work ram
222   if(!(state->vram_bank & 0x10)) //select plain work ram
202223   {
203224      wram[offset] = data;
204225      return;
205226   }
206227
207   if(!(vram_bank & 1)) { vram[offset | 0x0000] = data; }
208   if(!(vram_bank & 2)) { vram[offset | 0x4000] = data; }
209   if(!(vram_bank & 4)) { vram[offset | 0x8000] = data; }
210   if(!(vram_bank & 8)) { vram[offset | 0xc000] = data; }
228   if(!(state->vram_bank & 1)) { vram[offset | 0x0000] = data; }
229   if(!(state->vram_bank & 2)) { vram[offset | 0x4000] = data; }
230   if(!(state->vram_bank & 4)) { vram[offset | 0x8000] = data; }
231   if(!(state->vram_bank & 8)) { vram[offset | 0xc000] = data; }
211232}
212233
213234static READ8_HANDLER( pal_r )
214235{
215   return pen_clut[offset];
236   multi8_state *state = space->machine->driver_data<multi8_state>();
237   return state->pen_clut[offset];
216238}
217239
218240static WRITE8_HANDLER( pal_w )
219241{
220   pen_clut[offset] = data;
242   multi8_state *state = space->machine->driver_data<multi8_state>();
243   state->pen_clut[offset] = data;
221244
222245   {
223246      int i;
224247      for(i=0;i<8;i++)
225248      {
226         if(pen_clut[i]) { bw_mode = 0; return; }
249         if(state->pen_clut[i]) { state->bw_mode = 0; return; }
227250      }
228      bw_mode = 1;
251      state->bw_mode = 1;
229252   }
230253}
231254
r9667r9668
374397
375398static TIMER_CALLBACK( keyboard_callback )
376399{
400   multi8_state *state = machine->driver_data<multi8_state>();
377401   const char* portnames[3] = { "key1","key2","key3" };
378402   int i,port_i,scancode;
379403   UINT8 keymod = input_port_read(machine,"key_modifiers") & 0x1f;
380404   scancode = 0;
381405
382   shift_press_flag = ((keymod & 0x02) >> 1);
406   state->shift_press_flag = ((keymod & 0x02) >> 1);
383407
384408   for(port_i=0;port_i<3;port_i++)
385409   {
r9667r9668
388412         if((input_port_read(machine,portnames[port_i])>>i) & 1)
389413         {
390414            //key_flag = 1;
391            if(!shift_press_flag)  // shift not pressed
415            if(!state->shift_press_flag)  // shift not pressed
392416            {
393417               if(scancode >= 0x41 && scancode < 0x5b)
394418                  scancode += 0x20;  // lowercase
r9667r9668
410434               if(scancode == 0x3c)
411435                  scancode = 0x3e;
412436            }
413            keyb_press = scancode;
414            keyb_press_flag = 1;
437            state->keyb_press = scancode;
438            state->keyb_press_flag = 1;
415439            return;
416440         }
417441         scancode++;
r9667r9668
469493
470494static WRITE8_DEVICE_HANDLER( portb_w )
471495{
496   multi8_state *state = device->machine->driver_data<multi8_state>();
472497   /*
473498        x--- ---- color mode
474499        -x-- ---- screen width (80 / 40)
r9667r9668
480505//  printf("Port B w = %02x %04x\n",data,cpu_get_pc(space->cpu));
481506
482507   {
483      if((display_reg & 0x40) != (data & 0x40))
508      if((state->display_reg & 0x40) != (data & 0x40))
484509      {
485510         rectangle visarea = device->machine->primary_screen->visible_area();
486511         int x_width;
r9667r9668
495520      }
496521   }
497522
498   display_reg = data;
523   state->display_reg = data;
499524}
500525
501526static WRITE8_DEVICE_HANDLER( portc_w )
502527{
528   multi8_state *state = device->machine->driver_data<multi8_state>();
503529//  printf("Port C w = %02x\n",data);
504   vram_bank = data & 0x1f;
530   state->vram_bank = data & 0x1f;
505531
506532   if(data & 0x20 && data != 0xff)
507533      printf("Work RAM bank selected!\n");
r9667r9668
542568
543569static MACHINE_RESET(multi8)
544570{
571   multi8_state *state = machine->driver_data<multi8_state>();
545572   beep_set_frequency(machine->device("beeper"),1200); //guesswork
546573   beep_set_state(machine->device("beeper"),0);
547   mcu_init = 0;
574   state->mcu_init = 0;
548575}
549576
550static MACHINE_CONFIG_START( multi8, driver_device )
577static MACHINE_CONFIG_START( multi8, multi8_state )
551578    /* basic machine hardware */
552579    MDRV_CPU_ADD("maincpu",Z80, XTAL_4MHz)
553580    MDRV_CPU_PROGRAM_MAP(multi8_mem)
src/mess/drivers/ssystem3.c
r9667r9668
4040#include "cpu/m6502/m6502.h"
4141#include "sound/dac.h"
4242
43static struct {
44  UINT8 porta;
45} ssystem3;
4643
47
4844// in my opinion own cpu to display lcd field and to handle own buttons
49static struct {
50  int signal;
51  //  int on;
52
53  int count, bit, started;
54  UINT8 data;
55  attotime time, high_time, low_time;
56  union {
57    struct {
58      UINT8 header[7];
59      UINT8 field[8][8/2];
60      UINT8 unknown[5];
61    } s;
62    UINT8 data[7+8*8/2+5];
63  } u;
64} playfield;
65
66void ssystem3_playfield_getfigure(int x, int y, int *figure, int *black)
45void ssystem3_playfield_getfigure(running_machine *machine, int x, int y, int *figure, int *black)
6746{
47   ssystem3_state *state = machine->driver_data<ssystem3_state>();
6848  int d;
6949  if (x&1)
70    d=playfield.u.s.field[y][x/2]&0xf;
50    d=state->playfield.u.s.field[y][x/2]&0xf;
7151  else
72    d=playfield.u.s.field[y][x/2]>>4;
52    d=state->playfield.u.s.field[y][x/2]>>4;
7353
7454  *figure=d&7;
7555  *black=d&8;
7656}
7757
78static void ssystem3_playfield_reset(void)
58static void ssystem3_playfield_reset(running_machine *machine)
7959{
80  memset(&playfield, 0, sizeof(playfield));
81  playfield.signal=FALSE;
82  //  playfield.on=TRUE; //input_port_read(machine, "Configuration")&1;
60   ssystem3_state *state = machine->driver_data<ssystem3_state>();
61  memset(&state->playfield, 0, sizeof(state->playfield));
62  state->playfield.signal=FALSE;
63  //  state->playfield.on=TRUE; //input_port_read(machine, "Configuration")&1;
8364}
8465
8566static void ssystem3_playfield_write(running_machine *machine, int reset, int signal)
8667{
68   ssystem3_state *state = machine->driver_data<ssystem3_state>();
8769  int d=FALSE;
8870
8971  if (!reset) {
90    playfield.count=0;
91    playfield.bit=0;
92    playfield.started=FALSE;
93    playfield.signal=signal;
94    playfield.time=timer_get_time(machine);
72    state->playfield.count=0;
73    state->playfield.bit=0;
74    state->playfield.started=FALSE;
75    state->playfield.signal=signal;
76    state->playfield.time=timer_get_time(machine);
9577  }
96  if (!signal && playfield.signal) {
78  if (!signal && state->playfield.signal) {
9779    attotime t=timer_get_time(machine);
98    playfield.high_time=attotime_sub(t, playfield.time);
99    playfield.time=t;
80    state->playfield.high_time=attotime_sub(t, state->playfield.time);
81    state->playfield.time=t;
10082
101    //    logerror("%.4x playfield %d lowtime %s hightime %s\n",(int)activecpu_get_pc(), playfield.count,
102    //       attotime_string(playfield.low_time, 7), attotime_string(playfield.high_time,7) );
83    //    logerror("%.4x playfield %d lowtime %s hightime %s\n",(int)activecpu_get_pc(), state->playfield.count,
84    //       attotime_string(state->playfield.low_time, 7), attotime_string(state->playfield.high_time,7) );
10385
104    if (playfield.started) {
86    if (state->playfield.started) {
10587      // 0 twice as long low
10688      // 1 twice as long high
107      if (attotime_compare(playfield.low_time,playfield.high_time)>0) d=TRUE;
89      if (attotime_compare(state->playfield.low_time,state->playfield.high_time)>0) d=TRUE;
10890
109      playfield.data&=~(1<<(playfield.bit^7));
110      if (d) playfield.data|=1<<(playfield.bit^7);
111      playfield.bit++;
112      if (playfield.bit==8) {
113   logerror("%.4x playfield wrote %d %02x\n", (int)cpu_get_pc(machine->device("maincpu")), playfield.count, playfield.data);
114   playfield.u.data[playfield.count]=playfield.data;
115   playfield.bit=0;
116   playfield.count=(playfield.count+1)%ARRAY_LENGTH(playfield.u.data);
117   if (playfield.count==0) playfield.started=FALSE;
91      state->playfield.data&=~(1<<(state->playfield.bit^7));
92      if (d) state->playfield.data|=1<<(state->playfield.bit^7);
93      state->playfield.bit++;
94      if (state->playfield.bit==8) {
95   logerror("%.4x playfield wrote %d %02x\n", (int)cpu_get_pc(machine->device("maincpu")), state->playfield.count, state->playfield.data);
96   state->playfield.u.data[state->playfield.count]=state->playfield.data;
97   state->playfield.bit=0;
98   state->playfield.count=(state->playfield.count+1)%ARRAY_LENGTH(state->playfield.u.data);
99   if (state->playfield.count==0) state->playfield.started=FALSE;
118100      }
119101    }
120102
121  } else if (signal && !playfield.signal) {
103  } else if (signal && !state->playfield.signal) {
122104    attotime t=timer_get_time(machine);
123    playfield.low_time=attotime_sub(t, playfield.time);
124    playfield.time=t;
125    playfield.started=TRUE;
105    state->playfield.low_time=attotime_sub(t, state->playfield.time);
106    state->playfield.time=t;
107    state->playfield.started=TRUE;
126108  }
127  playfield.signal=signal;
109  state->playfield.signal=signal;
128110}
129111
130112static void ssystem3_playfield_read(running_machine *machine, int *on, int *ready)
131113{
114   //ssystem3_state *state = machine->driver_data<ssystem3_state>();
132115   *on=!(input_port_read(machine, "Configuration")&1);
133   //  *on=!playfield.on;
116   //  *on=!state->playfield.on;
134117   *ready=FALSE;
135118}
136119
137120static WRITE8_DEVICE_HANDLER(ssystem3_via_write_a)
138121{
139  ssystem3.porta=data;
122   ssystem3_state *state = device->machine->driver_data<ssystem3_state>();
123   state->porta=data;
140124  //  logerror("%.4x via port a write %02x\n",(int)activecpu_get_pc(), data);
141125}
142126
143127static READ8_DEVICE_HANDLER(ssystem3_via_read_a)
144128{
129   ssystem3_state *state = device->machine->driver_data<ssystem3_state>();
145130  UINT8 data=0xff;
146131#if 1 // time switch
147  if (!(ssystem3.porta&0x10)) data&=input_port_read(device->machine, "matrix1")|0xf1;
148  if (!(ssystem3.porta&0x20)) data&=input_port_read(device->machine, "matrix2")|0xf1;
149  if (!(ssystem3.porta&0x40)) data&=input_port_read(device->machine, "matrix3")|0xf1;
150  if (!(ssystem3.porta&0x80)) data&=input_port_read(device->machine, "matrix4")|0xf1;
132  if (!(state->porta&0x10)) data&=input_port_read(device->machine, "matrix1")|0xf1;
133  if (!(state->porta&0x20)) data&=input_port_read(device->machine, "matrix2")|0xf1;
134  if (!(state->porta&0x40)) data&=input_port_read(device->machine, "matrix3")|0xf1;
135  if (!(state->porta&0x80)) data&=input_port_read(device->machine, "matrix4")|0xf1;
151136#else
152  if (!(ssystem3.porta&0x10)) data&=input_port_read(device->machine, "matrix1")|0xf0;
153  if (!(ssystem3.porta&0x20)) data&=input_port_read(device->machine, "matrix2")|0xf0;
154  if (!(ssystem3.porta&0x40)) data&=input_port_read(device->machine, "matrix3")|0xf0;
155  if (!(ssystem3.porta&0x80)) data&=input_port_read(device->machine, "matrix4")|0xf0;
137  if (!(state->porta&0x10)) data&=input_port_read(device->machine, "matrix1")|0xf0;
138  if (!(state->porta&0x20)) data&=input_port_read(device->machine, "matrix2")|0xf0;
139  if (!(state->porta&0x40)) data&=input_port_read(device->machine, "matrix3")|0xf0;
140  if (!(state->porta&0x80)) data&=input_port_read(device->machine, "matrix4")|0xf0;
156141#endif
157  if (!(ssystem3.porta&1)) {
142  if (!(state->porta&1)) {
158143    if (!(input_port_read(device->machine, "matrix1")&1)) data&=~0x10;
159144    if (!(input_port_read(device->machine, "matrix2")&1)) data&=~0x20;
160145    if (!(input_port_read(device->machine, "matrix3")&1)) data&=~0x40;
161146    if (!(input_port_read(device->machine, "matrix4")&1)) data&=~0x80;
162147  }
163  if (!(ssystem3.porta&2)) {
148  if (!(state->porta&2)) {
164149    if (!(input_port_read(device->machine, "matrix1")&2)) data&=~0x10;
165150    if (!(input_port_read(device->machine, "matrix2")&2)) data&=~0x20;
166151    if (!(input_port_read(device->machine, "matrix3")&2)) data&=~0x40;
167152    if (!(input_port_read(device->machine, "matrix4")&2)) data&=~0x80;
168153  }
169  if (!(ssystem3.porta&4)) {
154  if (!(state->porta&4)) {
170155    if (!(input_port_read(device->machine, "matrix1")&4)) data&=~0x10;
171156    if (!(input_port_read(device->machine, "matrix2")&4)) data&=~0x20;
172157    if (!(input_port_read(device->machine, "matrix3")&4)) data&=~0x40;
173158    if (!(input_port_read(device->machine, "matrix4")&4)) data&=~0x80;
174159  }
175  if (!(ssystem3.porta&8)) {
160  if (!(state->porta&8)) {
176161    if (!(input_port_read(device->machine, "matrix1")&8)) data&=~0x10;
177162    if (!(input_port_read(device->machine, "matrix2")&8)) data&=~0x20;
178163    if (!(input_port_read(device->machine, "matrix3")&8)) data&=~0x40;
r9667r9668
246231
247232static DRIVER_INIT( ssystem3 )
248233{
249   ssystem3_playfield_reset();
250   ssystem3_lcd_reset();
234   ssystem3_playfield_reset(machine);
235   ssystem3_lcd_reset(machine);
251236}
252237
253238static ADDRESS_MAP_START( ssystem3_map , ADDRESS_SPACE_PROGRAM, 8)
src/mess/drivers/psx.c
r9667r9668
457457#define PAD_DATA_OK   ( 0x5a ) /* Z */
458458#define PAD_DATA_IDLE ( 0xff )
459459
460static struct
460typedef struct
461461{
462462   int n_shiftin;
463463   int n_shiftout;
r9667r9668
466466   int n_byte;
467467   int b_lastclock;
468468   int b_ack;
469} m_pad[ 2 ];
469} pad_t;
470static pad_t m_pad[ 2 ];
470471
471472static TIMER_CALLBACK(psx_pad_ack)
472473{
473474   int n_port = param;
474   if( m_pad[ n_port ].n_state != PAD_STATE_IDLE )
475   pad_t *pad = &m_pad[ n_port];
476
477   if( pad->n_state != PAD_STATE_IDLE )
475478   {
476      psx_sio_input( machine, 0, PSX_SIO_IN_DSR, m_pad[ n_port ].b_ack * PSX_SIO_IN_DSR );
477      if( !m_pad[ n_port ].b_ack )
479      psx_sio_input( machine, 0, PSX_SIO_IN_DSR, pad->b_ack * PSX_SIO_IN_DSR );
480      if( !pad->b_ack )
478481      {
479         m_pad[ n_port ].b_ack = 1;
482         pad->b_ack = 1;
480483         timer_set(machine, ATTOTIME_IN_USEC( 2 ), NULL, n_port, psx_pad_ack );
481484      }
482485   }
r9667r9668
484487
485488static void psx_pad( running_machine *machine, int n_port, int n_data )
486489{
490   pad_t *pad = &m_pad[ n_port];
487491   int b_sel;
488492   int b_clock;
489493   int b_data;
r9667r9668
499503
500504   if( b_sel )
501505   {
502      m_pad[ n_port ].n_state = PAD_STATE_IDLE;
506      pad->n_state = PAD_STATE_IDLE;
503507   }
504508
505   switch( m_pad[ n_port ].n_state )
509   switch( pad->n_state )
506510   {
507511   case PAD_STATE_LISTEN:
508512   case PAD_STATE_ACTIVE:
509513   case PAD_STATE_READ:
510      if( m_pad[ n_port ].b_lastclock && !b_clock )
514      if( pad->b_lastclock && !b_clock )
511515      {
512         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( m_pad[ n_port ].n_shiftout & 1 ) * PSX_SIO_IN_DATA );
513         m_pad[ n_port ].n_shiftout >>= 1;
516         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( pad->n_shiftout & 1 ) * PSX_SIO_IN_DATA );
517         pad->n_shiftout >>= 1;
514518      }
515      if( !m_pad[ n_port ].b_lastclock && b_clock )
519      if( !pad->b_lastclock && b_clock )
516520      {
517         m_pad[ n_port ].n_shiftin >>= 1;
518         m_pad[ n_port ].n_shiftin |= b_data << 7;
519         m_pad[ n_port ].n_bits++;
521         pad->n_shiftin >>= 1;
522         pad->n_shiftin |= b_data << 7;
523         pad->n_bits++;
520524
521         if( m_pad[ n_port ].n_bits == 8 )
525         if( pad->n_bits == 8 )
522526         {
523            m_pad[ n_port ].n_bits = 0;
527            pad->n_bits = 0;
524528            b_ready = 1;
525529         }
526530      }
527531      break;
528532   }
529533
530   m_pad[ n_port ].b_lastclock = b_clock;
534   pad->b_lastclock = b_clock;
531535
532   switch( m_pad[ n_port ].n_state )
536   switch( pad->n_state )
533537   {
534538   case PAD_STATE_IDLE:
535539      if( !b_sel )
536540      {
537         m_pad[ n_port ].n_state = PAD_STATE_LISTEN;
538         m_pad[ n_port ].n_shiftout = PAD_DATA_IDLE;
539         m_pad[ n_port ].n_bits = 0;
541         pad->n_state = PAD_STATE_LISTEN;
542         pad->n_shiftout = PAD_DATA_IDLE;
543         pad->n_bits = 0;
540544      }
541545      break;
542546   case PAD_STATE_LISTEN:
543547      if( b_ready )
544548      {
545         if( m_pad[ n_port ].n_shiftin == PAD_CMD_START )
549         if( pad->n_shiftin == PAD_CMD_START )
546550         {
547            m_pad[ n_port ].n_state = PAD_STATE_ACTIVE;
548            m_pad[ n_port ].n_shiftout = ( PAD_TYPE_STANDARD << 4 ) | ( PAD_BYTES_STANDARD >> 1 );
551            pad->n_state = PAD_STATE_ACTIVE;
552            pad->n_shiftout = ( PAD_TYPE_STANDARD << 4 ) | ( PAD_BYTES_STANDARD >> 1 );
549553            b_ack = 1;
550554         }
551555         else
552556         {
553            m_pad[ n_port ].n_state = PAD_STATE_UNLISTEN;
557            pad->n_state = PAD_STATE_UNLISTEN;
554558         }
555559      }
556560      break;
557561   case PAD_STATE_ACTIVE:
558562      if( b_ready )
559563      {
560         if( m_pad[ n_port ].n_shiftin == PAD_CMD_READ )
564         if( pad->n_shiftin == PAD_CMD_READ )
561565         {
562            m_pad[ n_port ].n_state = PAD_STATE_READ;
563            m_pad[ n_port ].n_shiftout = PAD_DATA_OK;
564            m_pad[ n_port ].n_byte = 0;
566            pad->n_state = PAD_STATE_READ;
567            pad->n_shiftout = PAD_DATA_OK;
568            pad->n_byte = 0;
565569            b_ack = 1;
566570         }
567571         else
568572         {
569            logerror( "unknown pad command %02x\n", m_pad[ n_port ].n_shiftin );
570            m_pad[ n_port ].n_state = PAD_STATE_UNLISTEN;
573            logerror( "unknown pad command %02x\n", pad->n_shiftin );
574            pad->n_state = PAD_STATE_UNLISTEN;
571575         }
572576      }
573577      break;
574578   case PAD_STATE_READ:
575579      if( b_ready )
576580      {
577         if( m_pad[ n_port ].n_byte < PAD_BYTES_STANDARD )
581         if( pad->n_byte < PAD_BYTES_STANDARD )
578582         {
579            m_pad[ n_port ].n_shiftout = input_port_read(machine, portnames[m_pad[ n_port ].n_byte + ( n_port * PAD_BYTES_STANDARD )]);
580            m_pad[ n_port ].n_byte++;
583            pad->n_shiftout = input_port_read(machine, portnames[pad->n_byte + ( n_port * PAD_BYTES_STANDARD )]);
584            pad->n_byte++;
581585            b_ack = 1;
582586         }
583587         else
584588         {
585            m_pad[ n_port ].n_state = PAD_STATE_LISTEN;
589            pad->n_state = PAD_STATE_LISTEN;
586590         }
587591      }
588592      break;
r9667r9668
590594
591595   if( b_ack )
592596   {
593      m_pad[ n_port ].b_ack = 0;
597      pad->b_ack = 0;
594598      timer_set(machine, ATTOTIME_IN_USEC( 10 ), NULL, n_port, psx_pad_ack );
595599   }
596600}
src/mess/drivers/odyssey2.c
r9667r9668
172172   MDRV_CARTSLOT_NOT_MANDATORY
173173MACHINE_CONFIG_END
174174
175static MACHINE_CONFIG_START( odyssey2, driver_device )
175static MACHINE_CONFIG_START( odyssey2, odyssey2_state )
176176   /* basic machine hardware */
177177   MDRV_CPU_ADD("maincpu", I8048, ( ( XTAL_7_15909MHz * 3 ) / 4 ) )
178178   MDRV_CPU_PROGRAM_MAP(odyssey2_mem)
r9667r9668
206206   MDRV_FRAGMENT_ADD(odyssey2_cartslot)
207207MACHINE_CONFIG_END
208208
209static MACHINE_CONFIG_START( videopac, driver_device )
209static MACHINE_CONFIG_START( videopac, odyssey2_state )
210210   /* basic machine hardware */
211211   MDRV_CPU_ADD("maincpu", I8048, ( XTAL_17_73447MHz / 3 ) )
212212   MDRV_CPU_PROGRAM_MAP(odyssey2_mem)
r9667r9668
239239   MDRV_FRAGMENT_ADD(odyssey2_cartslot)
240240MACHINE_CONFIG_END
241241
242static MACHINE_CONFIG_START( g7400, driver_device )
242static MACHINE_CONFIG_START( g7400, odyssey2_state )
243243   /* basic machine hardware */
244244   MDRV_CPU_ADD("maincpu", I8048, 5911000 )
245245   MDRV_CPU_PROGRAM_MAP(odyssey2_mem)
src/mess/drivers/homez80.c
r9667r9668
1111#include "emu.h"
1212#include "cpu/z80/z80.h"
1313
14static UINT8* homez80_video_ram;
1514
15class homez80_state : public driver_device
16{
17public:
18   homez80_state(running_machine &machine, const driver_device_config_base &config)
19      : driver_device(machine, config) { }
20
21   UINT8* video_ram;
22   int irq;
23};
24
25
26
1627const gfx_layout homez80_charlayout =
1728{
1829   8, 8,            /* 8x8 characters */
r9667r9668
3849static ADDRESS_MAP_START(homez80_mem, ADDRESS_SPACE_PROGRAM, 8)
3950   ADDRESS_MAP_UNMAP_HIGH
4051    AM_RANGE( 0x0000, 0x0fff ) AM_ROM  // Monitor
41   AM_RANGE( 0x2000, 0x23ff ) AM_RAM  AM_BASE(&homez80_video_ram) // Video RAM   
52   AM_RANGE( 0x2000, 0x23ff ) AM_RAM  AM_BASE_MEMBER(homez80_state, video_ram) // Video RAM   
4253   AM_RANGE( 0x7020, 0x702f ) AM_READ(homez80_keyboard_r)
4354    AM_RANGE( 0x8000, 0xffff ) AM_RAM  // 32 K RAM   
4455ADDRESS_MAP_END
r9667r9668
206217
207218static VIDEO_UPDATE( homez80 )
208219{
220   homez80_state *state = screen->machine->driver_data<homez80_state>();
209221    int x,y;
210222   for(y = 0; y < 32; y++ )
211223   {
212224      for(x = 0; x < 32; x++ )
213225      {
214         drawgfx_opaque(bitmap, NULL, screen->machine->gfx[0],  homez80_video_ram[x + y*32] , 0, 0,0, x*8+44,y*8);
226         drawgfx_opaque(bitmap, NULL, screen->machine->gfx[0],  state->video_ram[x + y*32] , 0, 0,0, x*8+44,y*8);
215227      }
216228   }
217229   return 0;
r9667r9668
221233   GFXDECODE_ENTRY( "gfx1", 0x0000, homez80_charlayout, 0, 1 )
222234GFXDECODE_END
223235
224static int homez80_irq = 0;
225236
226237static INTERRUPT_GEN( homez80_interrupt )
227{   
228   cpu_set_input_line(device, 0, (homez80_irq & 1) ? HOLD_LINE : CLEAR_LINE);
229   homez80_irq ^= 1;
238{
239   homez80_state *state = device->machine->driver_data<homez80_state>();   
240   cpu_set_input_line(device, 0, (state->irq & 1) ? HOLD_LINE : CLEAR_LINE);
241   state->irq ^= 1;
230242}
231243
232static MACHINE_CONFIG_START( homez80, driver_device )
244static MACHINE_CONFIG_START( homez80, homez80_state )
233245    /* basic machine hardware */
234246    MDRV_CPU_ADD("maincpu",Z80, XTAL_8MHz / 2)
235247    MDRV_CPU_PROGRAM_MAP(homez80_mem)
src/mess/drivers/gp2x.c
r9667r9668
2121#include "video/generic.h"
2222#include "cpu/arm7/arm7.h"
2323
24static UINT32 *gp2x_ram;
2524
26static UINT16 gp2x_vidregs[0x200/2];
25class gp2x_state : public driver_device
26{
27public:
28   gp2x_state(running_machine &machine, const driver_device_config_base &config)
29      : driver_device(machine, config) { }
30
31   UINT32 *ram;
32   UINT16 vidregs[0x200/2];
33   UINT32 nand_ptr;
34   UINT32 nand_cmd;
35   UINT32 nand_subword_stage;
36   UINT32 nand_stage;
37   UINT32 nand_ptr_temp;
38   UINT32 timer;
39};
40
41
42
2743#if 0
2844static const char* gp2x_regnames[0x200] =
2945{
r9667r9668
113129#endif
114130static VIDEO_UPDATE( gp2x )
115131{
132   gp2x_state *state = screen->machine->driver_data<gp2x_state>();
116133   // display enabled?
117   if (gp2x_vidregs[0] & 1)
134   if (state->vidregs[0] & 1)
118135   {
119136      // only support RGB still image layer for now
120      if (gp2x_vidregs[0x80/2] & 4)
137      if (state->vidregs[0x80/2] & 4)
121138      {
122139         int x, y;
123         UINT16 *vram = (UINT16 *)&gp2x_ram[0x2100000/4];
140         UINT16 *vram = (UINT16 *)&state->ram[0x2100000/4];
124141
125142/*          printf("RGB still image 1 enabled, bpp %d, size is %d %d %d %d\n",
126                (gp2x_vidregs[(0xda/2)]>>9)&3,
127                gp2x_vidregs[(0xe2/2)],
128                gp2x_vidregs[(0xe4/2)],
129                gp2x_vidregs[(0xe6/2)],
130                gp2x_vidregs[(0xe8/2)]);*/
143                (state->vidregs[(0xda/2)]>>9)&3,
144                state->vidregs[(0xe2/2)],
145                state->vidregs[(0xe4/2)],
146                state->vidregs[(0xe6/2)],
147                state->vidregs[(0xe8/2)]);*/
131148
132149
133150         for (y = 0; y < 240; y++)
r9667r9668
149166
150167static READ32_HANDLER( gp2x_lcdc_r )
151168{
152   return gp2x_vidregs[offset*2] | gp2x_vidregs[(offset*2)+1]<<16;
169   gp2x_state *state = space->machine->driver_data<gp2x_state>();
170   return state->vidregs[offset*2] | state->vidregs[(offset*2)+1]<<16;
153171}
154172
155173static WRITE32_HANDLER( gp2x_lcdc_w )
156174{
175   gp2x_state *state = space->machine->driver_data<gp2x_state>();
157176   if (mem_mask == 0xffff)
158177   {
159      gp2x_vidregs[offset*2] = data;
178      state->vidregs[offset*2] = data;
160179//      printf("%x to video reg %x (%s)\n", data, offset*2, gp2x_regnames[offset*2]);
161180   }
162181   else if (mem_mask == 0xffff0000)
163182   {
164      gp2x_vidregs[(offset*2)+1] = data>>16;
183      state->vidregs[(offset*2)+1] = data>>16;
165184//      printf("%x to video reg %x (%s)\n", data>>16, (offset*2)+1, gp2x_regnames[(offset*2)+1]);
166185   }
167186   else
r9667r9668
170189   }
171190}
172191
173static UINT32 nand_ptr = 0, nand_cmd, nand_subword_stage;
174static UINT32 nand_stage = 0, nand_ptr_temp = 0;
175192static READ32_HANDLER(nand_r)
176193{
194   gp2x_state *state = space->machine->driver_data<gp2x_state>();
177195   UINT32 *ROM = (UINT32 *)memory_region(space->machine, "maincpu");
178196   UINT32 ret;
179197
180198   if (offset == 0)
181199   {
182      switch (nand_cmd)
200      switch (state->nand_cmd)
183201      {
184202         case 0:
185203            if (mem_mask == 0xffffffff)
186204            {
187               return ROM[nand_ptr++];
205               return ROM[state->nand_ptr++];
188206            }
189207            else if (mem_mask == 0x000000ff)   // byte-wide reads?
190208            {
191               switch (nand_subword_stage++)
209               switch (state->nand_subword_stage++)
192210               {
193211                  case 0:
194                     return ROM[nand_ptr];
212                     return ROM[state->nand_ptr];
195213                  case 1:
196                     return ROM[nand_ptr]>>8;
214                     return ROM[state->nand_ptr]>>8;
197215                  case 2:
198                     return ROM[nand_ptr]>>16;
216                     return ROM[state->nand_ptr]>>16;
199217                  case 3:
200                     ret = ROM[nand_ptr]>>24;
201                     nand_subword_stage = 0;
202                     nand_ptr++;
218                     ret = ROM[state->nand_ptr]>>24;
219                     state->nand_subword_stage = 0;
220                     state->nand_ptr++;
203221                     return ret;
204222                  default:
205                     logerror("Bad nand_subword_stage = %d\n", nand_subword_stage);
223                     logerror("Bad state->nand_subword_stage = %d\n", state->nand_subword_stage);
206224                     break;
207225               }
208226            }
r9667r9668
212230            return 0xff;
213231
214232         case 0x90:   // read ID
215            switch (nand_stage++)
233            switch (state->nand_stage++)
216234            {
217235               case 0:
218236                  return 0xec;   // Samsung
r9667r9668
222240            break;
223241
224242         default:
225            logerror("NAND: read unk command %x (PC %x)\n", nand_cmd, cpu_get_pc(space->cpu));
243            logerror("NAND: read unk command %x (PC %x)\n", state->nand_cmd, cpu_get_pc(space->cpu));
226244            break;
227245      }
228246   }
r9667r9668
234252
235253static WRITE32_HANDLER(nand_w)
236254{
255   gp2x_state *state = space->machine->driver_data<gp2x_state>();
237256   switch (offset)
238257   {
239258      case 4:   // command
240         nand_cmd = data;
259         state->nand_cmd = data;
241260//          printf("NAND: command %x (PC %x0)\n", data, cpu_get_pc(space->cpu));
242         nand_stage = 0;
243         nand_subword_stage = 0;
261         state->nand_stage = 0;
262         state->nand_subword_stage = 0;
244263         break;
245264
246265      case 6:   // address
247         if (nand_cmd == 0)
266         if (state->nand_cmd == 0)
248267         {
249            switch (nand_stage)
268            switch (state->nand_stage)
250269            {
251270               case 0:
252                  nand_ptr_temp &= ~0xff;
253                  nand_ptr_temp |= data;
271                  state->nand_ptr_temp &= ~0xff;
272                  state->nand_ptr_temp |= data;
254273                  break;
255274               case 1:
256                  nand_ptr_temp &= ~0xff00;
257                  nand_ptr_temp |= data<<8;
275                  state->nand_ptr_temp &= ~0xff00;
276                  state->nand_ptr_temp |= data<<8;
258277                  break;
259278               case 2:
260                  nand_ptr_temp &= ~0xff0000;
261                  nand_ptr_temp |= data<<16;
279                  state->nand_ptr_temp &= ~0xff0000;
280                  state->nand_ptr_temp |= data<<16;
262281                  break;
263282               case 3:
264                  nand_ptr_temp &= ~0xff000000;
265                  nand_ptr_temp |= data<<24;
283                  state->nand_ptr_temp &= ~0xff000000;
284                  state->nand_ptr_temp |= data<<24;
266285
267//                      printf("NAND: ptr now %x, /2 %x, replacing %x\n", nand_ptr_temp, nand_ptr_temp/2, nand_ptr);
268                  nand_ptr = nand_ptr_temp/2;
286//                      printf("NAND: ptr now %x, /2 %x, replacing %x\n", state->nand_ptr_temp, state->nand_ptr_temp/2, state->nand_ptr);
287                  state->nand_ptr = state->nand_ptr_temp/2;
269288                  break;
270289            }
271            nand_stage++;
290            state->nand_stage++;
272291         }
273292         break;
274293
r9667r9668
288307   printf("%c", data&0xff);
289308}
290309
291static UINT32 timer = 0;
292310static READ32_HANDLER(timer_r)
293311{
294   return timer++;
312   gp2x_state *state = space->machine->driver_data<gp2x_state>();
313   return state->timer++;
295314}
296315
297316static READ32_HANDLER(nand_ctrl_r)
r9667r9668
311330
312331static ADDRESS_MAP_START( gp2x_map, ADDRESS_SPACE_PROGRAM, 32 )
313332   AM_RANGE(0x00000000, 0x00007fff) AM_ROM
314   AM_RANGE(0x01000000, 0x04ffffff) AM_RAM   AM_BASE(&gp2x_ram) // 64 MB of RAM
333   AM_RANGE(0x01000000, 0x04ffffff) AM_RAM   AM_BASE_MEMBER(gp2x_state, ram) // 64 MB of RAM
315334   AM_RANGE(0x9c000000, 0x9c00001f) AM_READWRITE(nand_r, nand_w)
316335   AM_RANGE(0xc0000a00, 0xc0000a03) AM_READ(timer_r)
317336   AM_RANGE(0xc0001208, 0xc000120b) AM_READ(tx_status_r)
r9667r9668
324343static INPUT_PORTS_START( gp2x )
325344INPUT_PORTS_END
326345
327static MACHINE_CONFIG_START( gp2x, driver_device )
346static MACHINE_CONFIG_START( gp2x, gp2x_state )
328347   MDRV_CPU_ADD("maincpu", ARM9, 80000000)
329348   MDRV_CPU_PROGRAM_MAP(gp2x_map)
330349
src/mess/drivers/jr100.c
r9667r9668
2020#include "sound/beep.h"
2121#include "devices/snapquik.h"
2222
23static UINT8 *jr100_ram;
24static UINT8 *jr100_vram;
25static UINT8 *jr100_pcg;
26static UINT8 keyboard_line;
27static bool jr100_use_pcg;
28static UINT8 jr100_speaker;
2923
24class jr100_state : public driver_device
25{
26public:
27   jr100_state(running_machine &machine, const driver_device_config_base &config)
28      : driver_device(machine, config) { }
29
30   UINT8 *ram;
31   UINT8 *vram;
32   UINT8 *pcg;
33   UINT8 keyboard_line;
34   bool use_pcg;
35   UINT8 speaker;
36   UINT16 t1latch;
37   UINT8 beep_en;
38};
39
40
41
42
3043static WRITE8_HANDLER( jr100_via_w )
3144{
32   static UINT16 t1latch;
33   static UINT8 beep_en;
34
45   jr100_state *state = space->machine->driver_data<jr100_state>();
3546   /* ACR: beeper masking */
3647   if(offset == 0x0b)
3748   {
3849      //printf("BEEP %s\n",((data & 0xe0) == 0xe0) ? "ON" : "OFF");
39      beep_en = ((data & 0xe0) == 0xe0);
50      state->beep_en = ((data & 0xe0) == 0xe0);
4051
41      if(!beep_en)
52      if(!state->beep_en)
4253         beep_set_state(space->machine->device("beeper"),0);
4354   }
4455
4556   /* T1L-L */
4657   if(offset == 0x04)
4758   {
48      t1latch = (t1latch & 0xff00) | (data & 0xff);
59      state->t1latch = (state->t1latch & 0xff00) | (data & 0xff);
4960      //printf("BEEP T1CL %02x\n",data);
5061   }
5162
5263   /* T1L-H */
5364   if(offset == 0x05)
5465   {
55      t1latch = (t1latch & 0xff) | ((data & 0xff) << 8);
66      state->t1latch = (state->t1latch & 0xff) | ((data & 0xff) << 8);
5667      //printf("BEEP T1CH %02x\n",data);
5768
5869      /* writing here actually enables the beeper, if above masking condition is satisfied */
59      if(beep_en)
70      if(state->beep_en)
6071      {
6172         beep_set_state(space->machine->device("beeper"),1);
62         beep_set_frequency(space->machine->device("beeper"),894886.25 / (double)(t1latch) / 2.0);
73         beep_set_frequency(space->machine->device("beeper"),894886.25 / (double)(state->t1latch) / 2.0);
6374      }
6475   }
6576   via6522_device *via = space->machine->device<via6522_device>("via");   
r9667r9668
6879
6980static ADDRESS_MAP_START(jr100_mem, ADDRESS_SPACE_PROGRAM, 8)
7081   ADDRESS_MAP_UNMAP_HIGH
71   AM_RANGE(0x0000, 0x3fff) AM_RAM AM_BASE(&jr100_ram)
72   AM_RANGE(0xc000, 0xc0ff) AM_RAM AM_BASE(&jr100_pcg)
73   AM_RANGE(0xc100, 0xc3ff) AM_RAM AM_BASE(&jr100_vram)
82   AM_RANGE(0x0000, 0x3fff) AM_RAM AM_BASE_MEMBER(jr100_state, ram)
83   AM_RANGE(0xc000, 0xc0ff) AM_RAM AM_BASE_MEMBER(jr100_state, pcg)
84   AM_RANGE(0xc100, 0xc3ff) AM_RAM AM_BASE_MEMBER(jr100_state, vram)
7485   AM_RANGE(0xc800, 0xc80f) AM_DEVREAD_MODERN("via", via6522_device, read) AM_WRITE(jr100_via_w)
7586   AM_RANGE(0xe000, 0xffff) AM_ROM
7687ADDRESS_MAP_END
r9667r9668
158169
159170static VIDEO_UPDATE( jr100 )
160171{
172   jr100_state *state = screen->machine->driver_data<jr100_state>();
161173   int x,y,xi,yi;
162174
163175   UINT8 *rom_pcg = memory_region(screen->machine, "maincpu") + 0xe000;
r9667r9668
165177   {
166178      for (x = 0; x < 32; x++)
167179      {
168         UINT8 tile = jr100_vram[x + y*32];
180         UINT8 tile = state->vram[x + y*32];
169181         UINT8 attr = tile >> 7;
170182         // ATTR is inverted for normal char or use PCG in case of CMODE1
171183         UINT8 *gfx_data = rom_pcg;
172         if (jr100_use_pcg && attr) {
173            gfx_data = jr100_pcg;
184         if (state->use_pcg && attr) {
185            gfx_data = state->pcg;
174186            attr = 0; // clear attr so bellow code stay same
175187         }
176188         tile &= 0x7f;
r9667r9668
211223
212224static READ8_DEVICE_HANDLER(jr100_via_read_b)
213225{
226   jr100_state *state = device->machine->driver_data<jr100_state>();
214227   UINT8 val = 0x1f;
215   if (keynames[keyboard_line]) {
216      val = input_port_read(device->machine, keynames[keyboard_line]);
228   if (keynames[state->keyboard_line]) {
229      val = input_port_read(device->machine, keynames[state->keyboard_line]);
217230   }
218231   return val;
219232}
220233
221234static WRITE8_DEVICE_HANDLER(jr100_via_write_a )
222235{
223   keyboard_line = data & 0x0f;
236   jr100_state *state = device->machine->driver_data<jr100_state>();
237   state->keyboard_line = data & 0x0f;
224238}
225239
226240static WRITE8_DEVICE_HANDLER(jr100_via_write_b )
227241{
228   jr100_use_pcg = (data & 0x20) ? TRUE : FALSE;
229   jr100_speaker = data>>7;
242   jr100_state *state = device->machine->driver_data<jr100_state>();
243   state->use_pcg = (data & 0x20) ? TRUE : FALSE;
244   state->speaker = data>>7;
230245}
231246
232247static WRITE_LINE_DEVICE_HANDLER(jr100_via_write_cb2)
r9667r9668
259274
260275static TIMER_DEVICE_CALLBACK( sound_tick )
261276{
277   jr100_state *state = timer.machine->driver_data<jr100_state>();
262278   running_device *speaker = timer.machine->device("speaker");
263   speaker_level_w(speaker,jr100_speaker);
264   jr100_speaker = 0;
279   speaker_level_w(speaker,state->speaker);
280   state->speaker = 0;
265281
266282   via6522_device *via = timer.machine->device<via6522_device>("via");
267283   double level = cassette_input(timer.machine->device("cassette"));
r9667r9668
283299
284300static QUICKLOAD_LOAD(jr100)
285301{
302   jr100_state *state = image.device().machine->driver_data<jr100_state>();
286303   int quick_length;
287304   UINT8 buf[0x10000];
288305   int read_;
r9667r9668
311328
312329   UINT32 end_address = start_address + code_length - 1;
313330   // copy code
314   memcpy(jr100_ram + start_address,buf + pos,code_length);
331   memcpy(state->ram + start_address,buf + pos,code_length);
315332   if (flag == 0) {
316      jr100_ram[end_address + 1] =  0xdf;
317      jr100_ram[end_address + 2] =  0xdf;
318      jr100_ram[end_address + 3] =  0xdf;
319      jr100_ram[6 ] = (end_address >> 8 & 0xFF);
320      jr100_ram[7 ] = (end_address & 0xFF);
321      jr100_ram[8 ] = ((end_address + 1) >> 8 & 0xFF);
322      jr100_ram[9 ] = ((end_address + 1) & 0xFF);
323      jr100_ram[10] = ((end_address + 2) >> 8 & 0xFF);
324      jr100_ram[11] = ((end_address + 2) & 0xFF);
325      jr100_ram[12] = ((end_address + 3) >> 8 & 0xFF);
326      jr100_ram[13] = ((end_address + 3) & 0xFF);
333      state->ram[end_address + 1] =  0xdf;
334      state->ram[end_address + 2] =  0xdf;
335      state->ram[end_address + 3] =  0xdf;
336      state->ram[6 ] = (end_address >> 8 & 0xFF);
337      state->ram[7 ] = (end_address & 0xFF);
338      state->ram[8 ] = ((end_address + 1) >> 8 & 0xFF);
339      state->ram[9 ] = ((end_address + 1) & 0xFF);
340      state->ram[10] = ((end_address + 2) >> 8 & 0xFF);
341      state->ram[11] = ((end_address + 2) & 0xFF);
342      state->ram[12] = ((end_address + 3) >> 8 & 0xFF);
343      state->ram[13] = ((end_address + 3) & 0xFF);
327344    }
328345
329346   return IMAGE_INIT_PASS;
330347}
331348
332static MACHINE_CONFIG_START( jr100, driver_device )
349static MACHINE_CONFIG_START( jr100, jr100_state )
333350    /* basic machine hardware */
334351    MDRV_CPU_ADD("maincpu",M6802, XTAL_14_31818MHz / 4) // clock devided internaly by 4
335352    MDRV_CPU_PROGRAM_MAP(jr100_mem)
src/mess/drivers/nc.c
r9667r9668
119119
120120/* the serial clock is generated by the nc hardware and connected to the msm8251
121121receive clock and transmit clock inputs */
122static emu_timer *nc_serial_timer;
123122
124123static void nc_printer_update(running_machine *machine, UINT8 data);
125124
126UINT8 nc_type;
127125
128static char nc_memory_config[4];
129unsigned long nc_display_memory_start;
130static emu_timer *nc_keyboard_timer = NULL;
131126
132static int nc_membank_rom_mask;
133static int nc_membank_internal_ram_mask;
134int nc_membank_card_ram_mask;
135127
136128static void nc100_machine_stop(running_machine &machine);
137129static void nc200_machine_stop(running_machine &machine);
r9667r9668
265257*/
266258
267259
268static UINT8 nc_poweroff_control;
269260
270261/* this is not a real register, it is used to record card status */
271262/* ==0, card not inserted, !=0 card is inserted */
272static int nc_card_status = 0;
273263
274264/* set pcmcia card present state */
275void nc_set_card_present_state(int state)
265void nc_set_card_present_state(running_machine *machine, int state)
276266{
277   nc_card_status = state;
267   nc_state *drvstate = machine->driver_data<nc_state>();
268   drvstate->card_status = state;
278269}
279270
280271/* card ram */
281272unsigned char *nc_card_ram = NULL;
282273
283static unsigned char nc_uart_control;
284274
285static int nc_irq_mask;
286static int nc_irq_status;
287275
288276
289277/* latched interrupts are interrupts that cannot be cleared by writing to the irq
290278mask. latched interrupts can only be cleared by accessing the interrupting
291279device e.g. serial chip, fdc */
292static int nc_irq_latch;
293280/* this is a mask of irqs that are latched, and it is different for nc100 and
294281nc200 */
295static int nc_irq_latch_mask;
296static int nc_sound_channel_periods[2];
297282
298283static void nc_update_interrupts(running_machine *machine)
299284{
300   nc_irq_status &= ~nc_irq_latch_mask;
301   nc_irq_status |= nc_irq_latch;
285   nc_state *state = machine->driver_data<nc_state>();
286   state->irq_status &= ~state->irq_latch_mask;
287   state->irq_status |= state->irq_latch;
302288
303289   /* any ints set and they are not masked? */
304290   if (
305         (((nc_irq_status & nc_irq_mask) & 0x3f)!=0)
291         (((state->irq_status & state->irq_mask) & 0x3f)!=0)
306292         )
307293   {
308      logerror("int set %02x\n", nc_irq_status & nc_irq_mask);
294      logerror("int set %02x\n", state->irq_status & state->irq_mask);
309295      /* set int */
310296      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
311297   }
r9667r9668
318304
319305static TIMER_CALLBACK(nc_keyboard_timer_callback)
320306{
307   nc_state *state = machine->driver_data<nc_state>();
321308      LOG(("keyboard int\n"));
322309
323310        /* set int */
324        nc_irq_status |= (1<<3);
311        state->irq_status |= (1<<3);
325312
326313        /* update ints */
327314        nc_update_interrupts(machine);
328315
329316        /* don't trigger again, but don't free it */
330        timer_reset(nc_keyboard_timer, attotime_never);
317        timer_reset(state->keyboard_timer, attotime_never);
331318}
332319
333320
r9667r9668
339326
340327static void nc_refresh_memory_bank_config(running_machine *machine, int bank)
341328{
329   nc_state *state = machine->driver_data<nc_state>();
342330   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
343331   int mem_type;
344332   int mem_bank;
r9667r9668
347335   sprintf(bank1,"bank%d",bank+1);
348336   sprintf(bank5,"bank%d",bank+5);
349337
350   mem_type = (nc_memory_config[bank]>>6) & 0x03;
351   mem_bank = nc_memory_config[bank] & 0x03f;
338   mem_type = (state->memory_config[bank]>>6) & 0x03;
339   mem_bank = state->memory_config[bank] & 0x03f;
352340
353341   memory_install_read_bank(space,(bank * 0x4000), (bank * 0x4000) + 0x3fff, 0, 0, nc_bankhandler_r[bank]);
354342
r9667r9668
360348      {
361349         unsigned char *addr;
362350
363         mem_bank = mem_bank & nc_membank_rom_mask;
351         mem_bank = mem_bank & state->membank_rom_mask;
364352
365353         addr = (memory_region(machine, "maincpu")+0x010000) + (mem_bank<<14);
366354
r9667r9668
376364      {
377365         unsigned char *addr;
378366
379         mem_bank = mem_bank & nc_membank_internal_ram_mask;
367         mem_bank = mem_bank & state->membank_internal_ram_mask;
380368
381369         addr = messram_get_ptr(machine->device("messram")) + (mem_bank<<14);
382370
r9667r9668
392380      case 2:
393381      {
394382         /* card connected? */
395         if ((nc_card_status) && (nc_card_ram!=NULL))
383         if ((state->card_status) && (state->card_ram!=NULL))
396384         {
397385            unsigned char *addr;
398386
399            mem_bank = mem_bank & nc_membank_card_ram_mask;
400            addr = nc_card_ram + (mem_bank<<14);
387            mem_bank = mem_bank & state->membank_card_ram_mask;
388            addr = state->card_ram + (mem_bank<<14);
401389
402390            memory_set_bankptr(machine, bank1, addr);
403391
r9667r9668
436424}
437425
438426
439static mame_file *file;
440427
441428/* restore a block of memory from the nvram file */
442429static void nc_common_restore_memory_from_stream(running_machine *machine)
443430{
431   nc_state *state = machine->driver_data<nc_state>();
444432   unsigned long stored_size;
445433   unsigned long restore_size;
446434
447   if (!file)
435   if (!state->file)
448436      return;
449437
450438   LOG(("restoring nc memory\n"));
451439   /* get size of memory data stored */
452   mame_fread(file, &stored_size, sizeof(unsigned long));
440   mame_fread(state->file, &stored_size, sizeof(unsigned long));
453441
454442   if (stored_size > messram_get_size(machine->device("messram")))
455443      restore_size = messram_get_size(machine->device("messram"));
r9667r9668
457445      restore_size = stored_size;
458446
459447   /* read as much as will fit into memory */
460   mame_fread(file, messram_get_ptr(machine->device("messram")), restore_size);
448   mame_fread(state->file, messram_get_ptr(machine->device("messram")), restore_size);
461449   /* seek over remaining data */
462   mame_fseek(file, SEEK_CUR,stored_size - restore_size);
450   mame_fseek(state->file, SEEK_CUR,stored_size - restore_size);
463451}
464452
465453/* store a block of memory to the nvram file */
466454static void nc_common_store_memory_to_stream(running_machine *machine)
467455{
456   nc_state *state = machine->driver_data<nc_state>();
468457   UINT32 size = messram_get_size(machine->device("messram"));
469   if (!file)
458   if (!state->file)
470459      return;
471460
472461   LOG(("storing nc memory\n"));
473462   /* write size of memory data */
474   mame_fwrite(file, &size, sizeof(UINT32));
463   mame_fwrite(state->file, &size, sizeof(UINT32));
475464
476465   /* write data block */
477   mame_fwrite(file, messram_get_ptr(machine->device("messram")), size);
466   mame_fwrite(state->file, messram_get_ptr(machine->device("messram")), size);
478467}
479468
480469static void nc_common_open_stream_for_reading(running_machine *machine)
481470{
471   nc_state *state = machine->driver_data<nc_state>();
482472   char filename[MAX_DRIVER_NAME_CHARS + 5];
483473
484474   sprintf(filename,"%s.nv", machine->gamedrv->name);
485475
486   mame_fopen(SEARCHPATH_MEMCARD, filename, OPEN_FLAG_READ, &file);
476   mame_fopen(SEARCHPATH_MEMCARD, filename, OPEN_FLAG_READ, &state->file);
487477}
488478
489479static void nc_common_open_stream_for_writing(running_machine *machine)
490480{
491    char filename[MAX_DRIVER_NAME_CHARS + 5];
481   nc_state *state = machine->driver_data<nc_state>();
482   char filename[MAX_DRIVER_NAME_CHARS + 5];
492483
493    sprintf(filename,"%s.nv", machine->gamedrv->name);
484   sprintf(filename,"%s.nv", machine->gamedrv->name);
494485
495   mame_fopen(SEARCHPATH_MEMCARD, filename, OPEN_FLAG_WRITE, &file);
486   mame_fopen(SEARCHPATH_MEMCARD, filename, OPEN_FLAG_WRITE, &state->file);
496487}
497488
498489
499static void nc_common_close_stream(void)
490static void nc_common_close_stream(running_machine *machine)
500491{
501   if (file)
502      mame_fclose(file);
492   nc_state *state = machine->driver_data<nc_state>();
493   if (state->file)
494      mame_fclose(state->file);
503495}
504496
505497
506498
507static int previous_inputport_10_state;
508499
509500static TIMER_CALLBACK(dummy_timer_callback)
510501{
502   nc_state *state = machine->driver_data<nc_state>();
511503   int inputport_10_state;
512504   int changed_bits;
513505
514    inputport_10_state = input_port_read(machine, "EXTRA");
506   inputport_10_state = input_port_read(machine, "EXTRA");
515507
516   changed_bits = inputport_10_state^previous_inputport_10_state;
508   changed_bits = inputport_10_state^state->previous_inputport_10_state;
517509
518510   /* on/off button changed state? */
519511   if (changed_bits & 0x01)
r9667r9668
522514        {
523515         /* on NC100 on/off button causes a nmi, on
524516            nc200 on/off button causes an int */
525         switch (nc_type)
517         switch (state->type)
526518         {
527519            case NC_TYPE_1xx:
528520            {
r9667r9668
533525
534526            case NC_TYPE_200:
535527            {
536               nc_irq_status |= (1 << 4);
528               state->irq_status |= (1 << 4);
537529               nc_update_interrupts(machine);
538530            }
539531            break;
r9667r9668
548540      nc_refresh_memory_config(machine);
549541   }
550542
551   previous_inputport_10_state = inputport_10_state;
543   state->previous_inputport_10_state = inputport_10_state;
552544}
553545
554546static TIMER_CALLBACK(nc_serial_timer_callback);
555547
556548static void nc_common_init_machine(running_machine *machine)
557549{
550   nc_state *state = machine->driver_data<nc_state>();
558551   /* setup reset state */
559   nc_display_memory_start = 0;
552   state->display_memory_start = 0;
560553
561554   /* setup reset state */
562    nc_memory_config[0] = 0;
563    nc_memory_config[1] = 0;
564    nc_memory_config[2] = 0;
565    nc_memory_config[3] = 0;
555   state->memory_config[0] = 0;
556   state->memory_config[1] = 0;
557   state->memory_config[2] = 0;
558   state->memory_config[3] = 0;
566559
567   previous_inputport_10_state = input_port_read(machine, "EXTRA");
560   state->previous_inputport_10_state = input_port_read(machine, "EXTRA");
568561
569    /* setup reset state ints are masked */
570    nc_irq_mask = 0;
571    /* setup reset state no ints wanting servicing */
572    nc_irq_status = 0;
573    /* at reset set to 0x0ffff */
562   /* setup reset state ints are masked */
563   state->irq_mask = 0;
564   /* setup reset state no ints wanting servicing */
565   state->irq_status = 0;
566   /* at reset set to 0x0ffff */
574567
575   nc_irq_latch = 0;
576   nc_irq_latch_mask = 0;
568   state->irq_latch = 0;
569   state->irq_latch_mask = 0;
577570
578571   /* setup reset state */
579   nc_sound_channel_periods[0] = (nc_sound_channel_periods[1] = 0x0ffff);
572   state->sound_channel_periods[0] = (state->sound_channel_periods[1] = 0x0ffff);
580573
581    /* at reset set to 1 */
582    nc_poweroff_control = 1;
574   /* at reset set to 1 */
575   state->poweroff_control = 1;
583576
584    nc_refresh_memory_config(machine);
577   nc_refresh_memory_config(machine);
585578   nc_update_interrupts(machine);
586579
587580   /* at reset set to 0x0ff */
588   nc_uart_control = 0x0ff;
581   state->uart_control = 0x0ff;
589582}
590583
591584static ADDRESS_MAP_START(nc_map, ADDRESS_SPACE_PROGRAM, 8 )
r9667r9668
598591
599592static  READ8_HANDLER(nc_memory_management_r)
600593{
601   return nc_memory_config[offset];
594   nc_state *state = space->machine->driver_data<nc_state>();
595   return state->memory_config[offset];
602596}
603597
604598static WRITE8_HANDLER(nc_memory_management_w)
605599{
600   nc_state *state = space->machine->driver_data<nc_state>();
606601   LOG(("Memory management W: %02x %02x\n",offset,data));
607        nc_memory_config[offset] = data;
602        state->memory_config[offset] = data;
608603
609604        nc_refresh_memory_config(space->machine);
610605}
611606
612607static WRITE8_HANDLER(nc_irq_mask_w)
613608{
609   nc_state *state = space->machine->driver_data<nc_state>();
614610   LOG(("irq mask w: %02x\n", data));
615611   LOG_DEBUG(("irq mask nc200 w: %02x\n",data & ((1<<4) | (1<<5) | (1<<6) | (1<<7))));
616612
617613   /* writing mask clears ints that are to be masked? */
618   nc_irq_mask = data;
614   state->irq_mask = data;
619615
620616   nc_update_interrupts(space->machine);
621617}
622618
623619static WRITE8_HANDLER(nc_irq_status_w)
624620{
621   nc_state *state = space->machine->driver_data<nc_state>();
625622   LOG(("irq status w: %02x\n", data));
626    data = data^0x0ff;
623   data = data^0x0ff;
627624
628   if (nc_type == NC_TYPE_200)
625   if (state->type == NC_TYPE_200)
629626   {
630627      /* Russell Marks confirms that on the NC200, the key scan interrupt must be explicitly
631628        cleared. It is not automatically cleared when reading 0x0b9 */
632629      if ((data & (1<<3))!=0)
633630      {
634631         /* set timer to occur again */
635         timer_reset(nc_keyboard_timer, ATTOTIME_IN_MSEC(10));
632         timer_reset(state->keyboard_timer, ATTOTIME_IN_MSEC(10));
636633
637634         nc_update_interrupts(space->machine);
638635      }
r9667r9668
645642                /* clearing keyboard int? */
646643                ((data & (1<<3))!=0) &&
647644                /* keyboard int request? */
648                ((nc_irq_status & (1<<3))!=0)
645                ((state->irq_status & (1<<3))!=0)
649646           )
650647        {
651648         /* set timer to occur again */
652         timer_reset(nc_keyboard_timer, ATTOTIME_IN_MSEC(10));
649         timer_reset(state->keyboard_timer, ATTOTIME_IN_MSEC(10));
653650        }
654651#endif
655        nc_irq_status &=~data;
652        state->irq_status &=~data;
656653
657654        nc_update_interrupts(space->machine);
658655}
659656
660657static READ8_HANDLER(nc_irq_status_r)
661658{
662        return ~((nc_irq_status & (~nc_irq_latch_mask)) | nc_irq_latch);
659   nc_state *state = space->machine->driver_data<nc_state>();
660        return ~((state->irq_status & (~state->irq_latch_mask)) | state->irq_latch);
663661}
664662
665663
666664static READ8_HANDLER(nc_key_data_in_r)
667665{
666   nc_state *state = space->machine->driver_data<nc_state>();
668667   static const char *const keynames[] = {
669668      "LINE0", "LINE1", "LINE2", "LINE3", "LINE4",
670669      "LINE5", "LINE6", "LINE7", "LINE8", "LINE9"
r9667r9668
673672   if (offset==9)
674673   {
675674      /* reading 0x0b9 will clear int and re-start scan procedure! */
676      nc_irq_status &= ~(1<<3);
675      state->irq_status &= ~(1<<3);
677676
678677      /* set timer to occur again */
679      timer_reset(nc_keyboard_timer, ATTOTIME_IN_MSEC(10));
678      timer_reset(state->keyboard_timer, ATTOTIME_IN_MSEC(10));
680679
681680      nc_update_interrupts(space->machine);
682681   }
r9667r9668
687686
688687static void nc_sound_update(running_machine *machine, int channel)
689688{
689   nc_state *state = machine->driver_data<nc_state>();
690690   int on;
691691   int frequency;
692692   int period;
r9667r9668
702702         break;
703703   }
704704
705   period = nc_sound_channel_periods[channel];
705   period = state->sound_channel_periods[channel];
706706
707707   /* if top bit is 0, sound is on */
708708   on = ((period & (1<<15))==0);
r9667r9668
718718
719719static WRITE8_HANDLER(nc_sound_w)
720720{
721   nc_state *state = space->machine->driver_data<nc_state>();
721722   LOG(("sound w: %04x %02x\n", offset, data));
722723
723724   switch (offset)
r9667r9668
725726      case 0x0:
726727      {
727728         /* update period value */
728         nc_sound_channel_periods[0]  =
729            (nc_sound_channel_periods[0] & 0x0ff00) | (data & 0x0ff);
729         state->sound_channel_periods[0]  =
730            (state->sound_channel_periods[0] & 0x0ff00) | (data & 0x0ff);
730731
731732         nc_sound_update(space->machine, 0);
732733      }
r9667r9668
734735
735736      case 0x01:
736737      {
737         nc_sound_channel_periods[0] =
738            (nc_sound_channel_periods[0] & 0x0ff) | ((data & 0x0ff)<<8);
738         state->sound_channel_periods[0] =
739            (state->sound_channel_periods[0] & 0x0ff) | ((data & 0x0ff)<<8);
739740
740741         nc_sound_update(space->machine, 0);
741742      }
r9667r9668
744745      case 0x02:
745746      {
746747         /* update period value */
747         nc_sound_channel_periods[1]  =
748            (nc_sound_channel_periods[1] & 0x0ff00) | (data & 0x0ff);
748         state->sound_channel_periods[1]  =
749            (state->sound_channel_periods[1] & 0x0ff00) | (data & 0x0ff);
749750
750751         nc_sound_update(space->machine, 1);
751752      }
r9667r9668
753754
754755      case 0x03:
755756      {
756         nc_sound_channel_periods[1] =
757            (nc_sound_channel_periods[1] & 0x0ff) | ((data & 0x0ff)<<8);
757         state->sound_channel_periods[1] =
758            (state->sound_channel_periods[1] & 0x0ff) | ((data & 0x0ff)<<8);
758759
759760         nc_sound_update(space->machine, 1);
760761      }
r9667r9668
787788
788789static WRITE8_HANDLER(nc_uart_control_w)
789790{
791   nc_state *state = space->machine->driver_data<nc_state>();
790792   /* update printer state */
791793   nc_printer_update(space->machine, data);
792794
793795   /* on/off changed state? */
794   if (((nc_uart_control ^ data) & (1<<3))!=0)
796   if (((state->uart_control ^ data) & (1<<3))!=0)
795797   {
796798      /* changed uart from off to on */
797799      if ((data & (1<<3))==0)
r9667r9668
800802      }
801803   }
802804
803   timer_adjust_periodic(nc_serial_timer, attotime_zero, 0, ATTOTIME_IN_HZ(baud_rate_table[(data & 0x07)]));
805   timer_adjust_periodic(state->serial_timer, attotime_zero, 0, ATTOTIME_IN_HZ(baud_rate_table[(data & 0x07)]));
804806
805   nc_uart_control = data;
807   state->uart_control = data;
806808}
807809
808810/* NC100 printer emulation */
r9667r9668
820822/********************************************************************************************************/
821823/* NC100 hardware */
822824
823static int previous_alarm_state;
824825
825826
826827static WRITE8_HANDLER(nc100_display_memory_start_w)
827828{
829   nc_state *state = space->machine->driver_data<nc_state>();
828830   /* bit 7: A15 */
829831   /* bit 6: A14 */
830832   /* bit 5: A13 */
831833   /* bit 4: A12 */
832834   /* bit 3-0: not used */
833   nc_display_memory_start = (data & 0x0f0)<<(12-4);
835   state->display_memory_start = (data & 0x0f0)<<(12-4);
834836
835   LOG(("disp memory w: %04x\n", (int) nc_display_memory_start));
837   LOG(("disp memory w: %04x\n", (int) state->display_memory_start));
836838}
837839
838840
839841static WRITE8_HANDLER(nc100_uart_control_w)
840842{
843   //nc_state *state = space->machine->driver_data<nc_state>();
841844   nc_uart_control_w(space, offset,data);
842845
843846//  /* is this correct?? */
844847//  if (data & (1<<3))
845848//  {
846849//      /* clear latched irq's */
847//      nc_irq_latch &= ~3;
850//      state->irq_latch &= ~3;
848851//      nc_update_interrupts(machine);
849852//  }
850853}
r9667r9668
852855
853856static void nc100_tc8521_alarm_callback(running_device *device, int state)
854857{
858   nc_state *drvstate = device->machine->driver_data<nc_state>();
855859   /* I'm assuming that the nmi is edge triggered */
856860   /* a interrupt from the fdc will cause a change in line state, and
857861    the nmi will be triggered, but when the state changes because the int
858862    is cleared this will not cause another nmi */
859863   /* I'll emulate it like this to be sure */
860864
861   if (state != previous_alarm_state)
865   if (state != drvstate->previous_alarm_state)
862866   {
863867      if (state)
864868      {
r9667r9668
868872      }
869873   }
870874
871   previous_alarm_state = state;
875   drvstate->previous_alarm_state = state;
872876}
873877
874878static void nc100_txrdy_callback(running_device *device, int state)
875879{
876   nc_irq_latch &= ~(1 << 1);
880   nc_state *drvstate = device->machine->driver_data<nc_state>();
881   drvstate->irq_latch &= ~(1 << 1);
877882
878883   /* uart on? */
879   if ((nc_uart_control & (1 << 3)) == 0)
884   if ((drvstate->uart_control & (1 << 3)) == 0)
880885   {
881886      if (state)
882887      {
883888         logerror("tx ready\n");
884         nc_irq_latch |= (1 << 1);
889         drvstate->irq_latch |= (1 << 1);
885890      }
886891   }
887892
r9667r9668
890895
891896static void nc100_rxrdy_callback(running_device *device, int state)
892897{
893   nc_irq_latch &= ~(1<<0);
898   nc_state *drvstate = device->machine->driver_data<nc_state>();
899   drvstate->irq_latch &= ~(1<<0);
894900
895   if ((nc_uart_control & (1<<3))==0)
901   if ((drvstate->uart_control & (1<<3))==0)
896902   {
897903      if (state)
898904      {
899905         logerror("rx ready\n");
900         nc_irq_latch |= (1<<0);
906         drvstate->irq_latch |= (1<<0);
901907      }
902908   }
903909
r9667r9668
920926
921927static WRITE_LINE_DEVICE_HANDLER( nc100_centronics_ack_w )
922928{
929   nc_state *drvstate = device->machine->driver_data<nc_state>();
923930   if (state)
924      nc_irq_status |= 0x04;
931      drvstate->irq_status |= 0x04;
925932   else
926      nc_irq_status &= ~0x04;
933      drvstate->irq_status &= ~0x04;
927934
928935   /* trigger an int if the irq is set */
929936   nc_update_interrupts(device->machine);
r9667r9668
940947
941948static MACHINE_RESET( nc100 )
942949{
943    /* 256k of rom */
944    nc_membank_rom_mask = 0x0f;
950   nc_state *state = machine->driver_data<nc_state>();
951   /* 256k of rom */
952   state->membank_rom_mask = 0x0f;
945953
946    nc_membank_internal_ram_mask = 3;
954   state->membank_internal_ram_mask = 3;
947955
948    nc_membank_card_ram_mask = 0x03f;
956   state->membank_card_ram_mask = 0x03f;
949957
950    nc_common_init_machine(machine);
958   nc_common_init_machine(machine);
951959
952960   nc_common_open_stream_for_reading(machine);
953961
954962   {
955963      running_device *rtc = machine->device("rtc");
956      tc8521_load_stream(rtc, file);
964      tc8521_load_stream(rtc, state->file);
957965   }
958966
959967   nc_common_restore_memory_from_stream(machine);
960968
961   nc_common_close_stream();
969   nc_common_close_stream(machine);
962970
963971   /* serial */
964   nc_irq_latch_mask = (1<<0) | (1<<1);
972   state->irq_latch_mask = (1<<0) | (1<<1);
965973}
966974
967975static void nc100_machine_stop(running_machine &machine)
968976{
977   nc_state *state = machine.driver_data<nc_state>();
969978   nc_common_open_stream_for_writing(&machine);
970979   {
971980      running_device *rtc = machine.device("rtc");
972      tc8521_save_stream(rtc, file);
981      tc8521_save_stream(rtc, state->file);
973982   }
974983   nc_common_store_memory_to_stream(&machine);
975   nc_common_close_stream();
984   nc_common_close_stream(&machine);
976985}
977986
978987static MACHINE_START( nc100 )
979988{
980    nc_type = NC_TYPE_1xx;
989   nc_state *state = machine->driver_data<nc_state>();
990    state->type = NC_TYPE_1xx;
981991
982992   machine->add_notifier(MACHINE_NOTIFY_EXIT, nc100_machine_stop);
983993
984994   /* keyboard timer */
985   nc_keyboard_timer = timer_alloc(machine, nc_keyboard_timer_callback, NULL);
986   timer_adjust_oneshot(nc_keyboard_timer, ATTOTIME_IN_MSEC(10), 0);
995   state->keyboard_timer = timer_alloc(machine, nc_keyboard_timer_callback, NULL);
996   timer_adjust_oneshot(state->keyboard_timer, ATTOTIME_IN_MSEC(10), 0);
987997
988998   /* dummy timer */
989999   timer_pulse(machine, ATTOTIME_IN_HZ(50), NULL, 0, dummy_timer_callback);
9901000
9911001   /* serial timer */
992   nc_serial_timer = timer_alloc(machine, nc_serial_timer_callback, NULL);
1002   state->serial_timer = timer_alloc(machine, nc_serial_timer_callback, NULL);
9931003}
9941004
9951005
9961006static WRITE8_HANDLER(nc100_poweroff_control_w)
9971007{
1008   nc_state *state = space->machine->driver_data<nc_state>();
9981009   /* bits 7-1: not used */
9991010   /* bit 0: 1 = no effect, 0 = power off */
1000   nc_poweroff_control = data;
1011   state->poweroff_control = data;
10011012   LOG(("nc poweroff control: %02x\n",data));
10021013}
10031014
r9667r9668
10051016/* nc100 version of card/battery status */
10061017static  READ8_HANDLER(nc100_card_battery_status_r)
10071018{
1019   nc_state *state = space->machine->driver_data<nc_state>();
10081020   running_device *printer = space->machine->device("centronics");
10091021   int nc_card_battery_status = 0x0fc;
10101022
r9667r9668
10121024   nc_card_battery_status |= centronics_ack_r(printer);
10131025   nc_card_battery_status |= centronics_busy_r(printer) << 1;
10141026
1015   if (nc_card_status)
1027   if (state->card_status)
10161028   {
10171029      /* card present */
10181030      nc_card_battery_status &=~(1<<7);
r9667r9668
10291041   nc_card_battery_status |= (1<<5);
10301042   nc_card_battery_status &= ~((1<<2) | (1<<3));
10311043
1032    return nc_card_battery_status;
1044   return nc_card_battery_status;
10331045}
10341046
10351047static WRITE8_HANDLER(nc100_memory_card_wait_state_w)
r9667r9668
11901202#if 0
11911203void nc150_init_machine(running_machine *machine)
11921204{
1193        nc_membank_internal_ram_mask = 7;
1205   nc_state *state = machine->driver_data<nc_state>();
1206        state->membank_internal_ram_mask = 7;
11941207
1195        nc_membank_card_ram_mask = 0x03f;
1208        state->membank_card_ram_mask = 0x03f;
11961209
11971210        nc_common_init_machine(machine);
11981211}
r9667r9668
12061219#ifdef UNUSED_FUNCTION
12071220static WRITE8_HANDLER(nc200_display_memory_start_w)
12081221{
1222   nc_state *state = space->machine->driver_data<nc_state>();
12091223   /* bit 7: A15 */
12101224   /* bit 6: A14 */
12111225   /* bit 5: A13 */
12121226   /* bit 4-0: not used */
1213   nc_display_memory_start = (data & 0x0e0)<<(12-4);
1227   state->display_memory_start = (data & 0x0e0)<<(12-4);
12141228
1215   LOG(("disp memory w: %04x\n", (int) nc_display_memory_start));
1229   LOG(("disp memory w: %04x\n", (int) state->display_memory_start));
12161230}
12171231#endif
12181232
12191233
12201234static WRITE_LINE_DEVICE_HANDLER( nc200_centronics_ack_w )
12211235{
1236   nc_state *drvstate = device->machine->driver_data<nc_state>();
12221237   if (state)
1223      nc_irq_status |= 0x01;
1238      drvstate->irq_status |= 0x01;
12241239   else
1225      nc_irq_status &= ~0x01;
1240      drvstate->irq_status &= ~0x01;
12261241
12271242   /* trigger an int if the irq is set */
12281243   nc_update_interrupts(device->machine);
r9667r9668
12391254
12401255/* assumption. nc200 uses the same uart chip. The rxrdy and txrdy are combined
12411256together with a or to generate a single interrupt */
1242static UINT8 nc200_uart_interrupt_irq;
12431257
12441258static void nc200_refresh_uart_interrupt(running_machine *machine)
12451259{
1246   nc_irq_latch &=~(1<<2);
1260   nc_state *state = machine->driver_data<nc_state>();
1261   state->irq_latch &=~(1<<2);
12471262
12481263   /* uart enabled? */
1249   if ((nc_uart_control & (1<<3))==0)
1264   if ((state->uart_control & (1<<3))==0)
12501265   {
1251      if ((nc200_uart_interrupt_irq & 0x03)!=0)
1266      if ((state->nc200_uart_interrupt_irq & 0x03)!=0)
12521267      {
1253         nc_irq_latch |= (1<<2);
1268         state->irq_latch |= (1<<2);
12541269      }
12551270   }
12561271   nc_update_interrupts(machine);
r9667r9668
12581273
12591274static void nc200_txrdy_callback(running_device *device, int state)
12601275{
1261//  nc200_uart_interrupt_irq &=~(1<<0);
1276   //nc_state *drvstate = machine->driver_data<nc_state>();
1277//  drvstate->nc200_uart_interrupt_irq &=~(1<<0);
12621278//
12631279//  if (state)
12641280//  {
1265//      nc200_uart_interrupt_irq |=(1<<0);
1281//      drvstate->nc200_uart_interrupt_irq |=(1<<0);
12661282//  }
12671283//
12681284//  nc200_refresh_uart_interrupt(device->machine);
r9667r9668
12701286
12711287static void nc200_rxrdy_callback(running_device *device, int state)
12721288{
1273   nc200_uart_interrupt_irq &=~(1<<1);
1289   nc_state *drvstate = device->machine->driver_data<nc_state>();
1290   drvstate->nc200_uart_interrupt_irq &=~(1<<1);
12741291
12751292   if (state)
12761293   {
1277      nc200_uart_interrupt_irq |=(1<<1);
1294      drvstate->nc200_uart_interrupt_irq |=(1<<1);
12781295   }
12791296
12801297   nc200_refresh_uart_interrupt(device->machine);
r9667r9668
12901307
12911308static WRITE_LINE_DEVICE_HANDLER( nc200_fdc_interrupt )
12921309{
1310   nc_state *drvstate = device->machine->driver_data<nc_state>();
12931311#if 0
1294    nc_irq_latch &=~(1<<5);
1312    drvstate->irq_latch &=~(1<<5);
12951313
12961314    if (state)
12971315    {
1298            nc_irq_latch |=(1<<5);
1316            drvstate->irq_latch |=(1<<5);
12991317    }
13001318#endif
1301    nc_irq_status &=~(1<<5);
1319    drvstate->irq_status &=~(1<<5);
13021320
13031321    if (state)
13041322    {
1305            nc_irq_status |=(1<<5);
1323            drvstate->irq_status |=(1<<5);
13061324    }
13071325
13081326    nc_update_interrupts(device->machine);
r9667r9668
13201338#ifdef UNUSED_FUNCTION
13211339static void nc200_floppy_drive_index_callback(int drive_id)
13221340{
1341   nc_state *state = machine->driver_data<nc_state>();
13231342   LOG_DEBUG(("nc200 index pulse\n"));
1324//  nc_irq_status |= (1<<4);
1343//  state->irq_status |= (1<<4);
13251344
13261345//  nc_update_interrupts(Machine);
13271346}
r9667r9668
13291348
13301349static MACHINE_RESET( nc200 )
13311350{
1351   nc_state *state = machine->driver_data<nc_state>();
13321352   /* 512k of rom */
1333   nc_membank_rom_mask = 0x1f;
1353   state->membank_rom_mask = 0x1f;
13341354
1335    nc_membank_internal_ram_mask = 7;
1355   state->membank_internal_ram_mask = 7;
13361356
1337    nc_membank_card_ram_mask = 0x03f;
1357   state->membank_card_ram_mask = 0x03f;
13381358
1339    nc_common_init_machine(machine);
1359   nc_common_init_machine(machine);
13401360
1341   nc200_uart_interrupt_irq = 0;
1361   state->nc200_uart_interrupt_irq = 0;
13421362
13431363   nc_common_open_stream_for_reading(machine);
13441364   nc_common_restore_memory_from_stream(machine);
1345   nc_common_close_stream();
1365   nc_common_close_stream(machine);
13461366
13471367   /* fdc, serial */
1348   nc_irq_latch_mask = /*(1<<5) |*/ (1<<2);
1368   state->irq_latch_mask = /*(1<<5) |*/ (1<<2);
13491369
1350   nc200_video_set_backlight(0);
1370   nc200_video_set_backlight(machine, 0);
13511371}
13521372
13531373static void nc200_machine_stop(running_machine &machine)
13541374{
13551375   nc_common_open_stream_for_writing(&machine);
13561376   nc_common_store_memory_to_stream(&machine);
1357   nc_common_close_stream();
1377   nc_common_close_stream(&machine);
13581378}
13591379
13601380static MACHINE_START( nc200 )
13611381{
1362    nc_type = NC_TYPE_200;
1382   nc_state *state = machine->driver_data<nc_state>();
1383   state->type = NC_TYPE_200;
13631384
13641385   machine->add_notifier(MACHINE_NOTIFY_EXIT, nc200_machine_stop);
13651386
13661387   /* keyboard timer */
1367   nc_keyboard_timer = timer_alloc(machine, nc_keyboard_timer_callback, NULL);
1368   timer_adjust_oneshot(nc_keyboard_timer, ATTOTIME_IN_MSEC(10), 0);
1388   state->keyboard_timer = timer_alloc(machine, nc_keyboard_timer_callback, NULL);
1389   timer_adjust_oneshot(state->keyboard_timer, ATTOTIME_IN_MSEC(10), 0);
13691390
13701391   /* dummy timer */
13711392   timer_pulse(machine, ATTOTIME_IN_HZ(50), NULL, 0, dummy_timer_callback);
13721393
13731394   /* serial timer */
1374   nc_serial_timer = timer_alloc(machine, nc_serial_timer_callback, NULL);
1395   state->serial_timer = timer_alloc(machine, nc_serial_timer_callback, NULL);
13751396}
13761397
13771398/*
r9667r9668
13911412/* nc200 version of card/battery status */
13921413static  READ8_HANDLER(nc200_card_battery_status_r)
13931414{
1415   nc_state *state = space->machine->driver_data<nc_state>();
13941416   int nc_card_battery_status = 0x0ff;
13951417
13961418   /* enough power */
r9667r9668
14011423    and there is enough power for disk usage */
14021424   nc_card_battery_status &=~((1<<5) | (1<<2) | (1<<0));
14031425
1404   if (nc_card_status)
1426   if (state->card_status)
14051427   {
14061428      /* card present */
14071429      nc_card_battery_status&=~(1<<7);
r9667r9668
14351457
14361458static WRITE8_HANDLER(nc200_uart_control_w)
14371459{
1438   /* int reset_fdc = (nc_uart_control^data) & (1<<5); */
1460   nc_state *state = space->machine->driver_data<nc_state>();
1461   /* int reset_fdc = (state->uart_control^data) & (1<<5); */
14391462
14401463   nc_uart_control_w(space, offset,data);
14411464
14421465   if (data & (1<<3))
14431466   {
1444      nc200_uart_interrupt_irq &=~3;
1467      state->nc200_uart_interrupt_irq &=~3;
14451468
14461469      nc200_refresh_uart_interrupt(space->machine);
14471470   }
r9667r9668
14811504{
14821505   LOG_DEBUG(("nc200 power off: PC: %04x %02x\n", cpu_get_pc(space->machine->device("maincpu")), data));
14831506
1484   nc200_video_set_backlight(((data ^ (1 << 2)) >> 2) & 0x01);
1507   nc200_video_set_backlight(space->machine, ((data ^ (1 << 2)) >> 2) & 0x01);
14851508}
14861509
14871510static ADDRESS_MAP_START(nc200_io, ADDRESS_SPACE_IO, 8)
r9667r9668
16621685
16631686/**********************************************************************************************************/
16641687
1665static MACHINE_CONFIG_START( nc100, driver_device )
1688static MACHINE_CONFIG_START( nc100, nc_state )
16661689   /* basic machine hardware */
16671690   MDRV_CPU_ADD("maincpu", Z80, /*6000000*/ 4606000)        /* Russell Marks says this is more accurate */
16681691   MDRV_CPU_PROGRAM_MAP(nc_map)
src/mess/drivers/vectrex.c
r9667r9668
1818#include "sound/dac.h"
1919#include "machine/nvram.h"
2020
21UINT8 *gce_vectorram;
22size_t gce_vectorram_size;
2321
2422static ADDRESS_MAP_START(vectrex_map, ADDRESS_SPACE_PROGRAM, 8)
2523   AM_RANGE(0x0000, 0x7fff) AM_ROM
26   AM_RANGE(0xc800, 0xcbff) AM_RAM AM_MIRROR(0x0400) AM_BASE(&gce_vectorram) AM_SIZE(&gce_vectorram_size)
24   AM_RANGE(0xc800, 0xcbff) AM_RAM AM_MIRROR(0x0400) AM_BASE_MEMBER(vectrex_state, gce_vectorram) AM_SIZE_MEMBER(vectrex_state, gce_vectorram_size)
2725   AM_RANGE(0xd000, 0xd7ff) AM_READWRITE(vectrex_via_r, vectrex_via_w)
2826   AM_RANGE(0xe000, 0xffff) AM_ROM
2927ADDRESS_MAP_END
r9667r9668
9896   DEVCB_NULL
9997};
10098
101static MACHINE_CONFIG_START( vectrex, driver_device )
99static MACHINE_CONFIG_START( vectrex, vectrex_state )
102100   /* basic machine hardware */
103101   MDRV_CPU_ADD("maincpu", M6809, XTAL_6MHz / 4)
104102   MDRV_CPU_PROGRAM_MAP(vectrex_map)
r9667r9668
181179   AM_RANGE(0x0000, 0x7fff) AM_ROM
182180   AM_RANGE(0x8000, 0x87ff) AM_RAM AM_SHARE("nvram")
183181   AM_RANGE(0xa000, 0xa000) AM_WRITE(raaspec_led_w)
184   AM_RANGE(0xc800, 0xcbff) AM_RAM AM_MIRROR(0x0400) AM_BASE(&gce_vectorram) AM_SIZE(&gce_vectorram_size)
182   AM_RANGE(0xc800, 0xcbff) AM_RAM AM_MIRROR(0x0400) AM_BASE_MEMBER(vectrex_state, gce_vectorram) AM_SIZE_MEMBER(vectrex_state, gce_vectorram_size)
185183   AM_RANGE(0xd000, 0xd7ff) AM_READWRITE (vectrex_via_r, vectrex_via_w)
186184   AM_RANGE(0xe000, 0xffff) AM_ROM
187185ADDRESS_MAP_END
src/mess/drivers/lviv.c
r9667r9668
425425
426426
427427/* machine definition */
428static MACHINE_CONFIG_START( lviv, driver_device )
428static MACHINE_CONFIG_START( lviv, lviv_state )
429429   /* basic machine hardware */
430430   MDRV_CPU_ADD("maincpu", I8080, 2500000)
431431   MDRV_CPU_PROGRAM_MAP(lviv_mem)
src/mess/drivers/jr200.c
r9667r9668
1919#include "cpu/m6800/m6800.h"
2020#include "sound/beep.h"
2121
22static UINT8 *jr200_vram,*jr200_cram;
23static UINT8 *mn1271_ram;
24static UINT8 jr200_border_col;
2522
23class jr200_state : public driver_device
24{
25public:
26   jr200_state(running_machine &machine, const driver_device_config_base &config)
27      : driver_device(machine, config) { }
28
29   UINT8 *vram;
30   UINT8 *cram;
31   UINT8 *mn1271_ram;
32   UINT8 border_col;
33   UINT8 old_keydata;
34   UINT8 freq_reg[2];
35   emu_timer *timer_d;
36};
37
38
39
2640/* TODO: double check this */
2741static const UINT8 jr200_keycodes[4][9][8] =
2842{
r9667r9668
86100
87101static VIDEO_UPDATE( jr200 )
88102{
103   jr200_state *state = screen->machine->driver_data<jr200_state>();
89104   int x,y,xi,yi,pen;
90105
91   bitmap_fill(bitmap, cliprect, jr200_border_col);
106   bitmap_fill(bitmap, cliprect, state->border_col);
92107
93108   for (y = 0; y < 24; y++)
94109   {
95110      for (x = 0; x < 32; x++)
96111      {
97         UINT8 tile = jr200_vram[x + y*32];
98         UINT8 attr = jr200_cram[x + y*32];
112         UINT8 tile = state->vram[x + y*32];
113         UINT8 attr = state->cram[x + y*32];
99114
100115         for(yi=0;yi<8;yi++)
101116         {
r9667r9668
193208
194209static READ8_HANDLER( mcu_keyb_r )
195210{
211   jr200_state *state = space->machine->driver_data<jr200_state>();
196212   int row, col, table = 0;
197   int keydata = 0;
198   static UINT8 res;
213   UINT8 keydata = 0;
199214   static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7", "ROW8" };
200215
201216   if (input_port_read(space->machine, "ROW9") & 0x07)
r9667r9668
219234      }
220235   }
221236
222   if(res == keydata)
237   if(state->old_keydata == keydata)
223238      return 0x00;
224239
225   res = keydata;
240   state->old_keydata = keydata;
226241
227   return res;
242   return keydata;
228243}
229244
230245static WRITE8_HANDLER( jr200_beep_w )
r9667r9668
235250
236251static WRITE8_HANDLER( jr200_beep_freq_w )
237252{
253   jr200_state *state = space->machine->driver_data<jr200_state>();
238254   UINT32 beep_freq;
239   static UINT8 freq_reg[2];
240255
241   freq_reg[offset] = data;
256   state->freq_reg[offset] = data;
242257
243   beep_freq = ((freq_reg[0]<<8) | (freq_reg[1] & 0xff)) + 1;
258   beep_freq = ((state->freq_reg[0]<<8) | (state->freq_reg[1] & 0xff)) + 1;
244259
245260   beep_set_frequency(space->machine->device("beeper"),84000 / beep_freq);
246261}
247262
248263static WRITE8_HANDLER( jr200_border_col_w )
249264{
250   jr200_border_col = data;
265   jr200_state *state = space->machine->driver_data<jr200_state>();
266   state->border_col = data;
251267}
252268
253static emu_timer *timer_d;
254269
255270static TIMER_CALLBACK(timer_d_callback)
256271{
r9667r9668
259274
260275static READ8_HANDLER( mn1271_io_r )
261276{
262   UINT8 retVal = mn1271_ram[offset];
277   jr200_state *state = space->machine->driver_data<jr200_state>();
278   UINT8 retVal = state->mn1271_ram[offset];
263279   if((offset+0xc800) > 0xca00)
264280      retVal= 0xff;
265281
266282   switch(offset+0xc800)
267283   {
268284      case 0xc801: retVal= mcu_keyb_r(space,0); break;
269      case 0xc803: retVal= (mn1271_ram[0x03] & 0xcf) | 0x30;  break;//---x ---- printer status ready (ACTIVE HIGH)
270      case 0xc807: retVal= (mn1271_ram[0x07] & 0x80) | 0x60; break;
271      case 0xc80a: retVal= (mn1271_ram[0x0a] & 0xfe); break;
272      case 0xc80c: retVal= (mn1271_ram[0x0c] & 0xdf) | 0x20; break;
285      case 0xc803: retVal= (state->mn1271_ram[0x03] & 0xcf) | 0x30;  break;//---x ---- printer status ready (ACTIVE HIGH)
286      case 0xc807: retVal= (state->mn1271_ram[0x07] & 0x80) | 0x60; break;
287      case 0xc80a: retVal= (state->mn1271_ram[0x0a] & 0xfe); break;
288      case 0xc80c: retVal= (state->mn1271_ram[0x0c] & 0xdf) | 0x20; break;
273289      case 0xc80e: retVal= 0; break;
274290      case 0xc810: retVal= 0; break;
275291      case 0xc816: retVal= 0x4e; break;
276      case 0xc81c: retVal= (mn1271_ram[0x1c] & 0xfe) | 1;  break;//bit 0 needs to be high otherwise system refuses to boot
277      case 0xc81d: retVal= (mn1271_ram[0x1d] & 0xed); break;
292      case 0xc81c: retVal= (state->mn1271_ram[0x1c] & 0xfe) | 1;  break;//bit 0 needs to be high otherwise system refuses to boot
293      case 0xc81d: retVal= (state->mn1271_ram[0x1d] & 0xed); break;
278294   }
279295   //logerror("mn1271_io_r [%04x] = %02x\n",offset+0xc800,retVal);
280296   return retVal;
r9667r9668
282298
283299static WRITE8_HANDLER( mn1271_io_w )
284300{
285   mn1271_ram[offset] = data;
301   jr200_state *state = space->machine->driver_data<jr200_state>();
302   state->mn1271_ram[offset] = data;
286303   switch(offset+0xc800)
287304   {
288305      case 0xc805: break; //LPT printer port W
289306      case 0xc816: if (data!=0) {
290               timer_adjust_periodic(timer_d, attotime_zero, 0, attotime_mul(ATTOTIME_IN_HZ(XTAL_14_31818MHz), (mn1271_ram[0x17]*0x100 + mn1271_ram[0x18])));
307               timer_adjust_periodic(state->timer_d, attotime_zero, 0, attotime_mul(ATTOTIME_IN_HZ(XTAL_14_31818MHz), (state->mn1271_ram[0x17]*0x100 + state->mn1271_ram[0x18])));
291308            } else {
292               timer_adjust_periodic(timer_d, attotime_zero, 0,  attotime_zero);
309               timer_adjust_periodic(state->timer_d, attotime_zero, 0,  attotime_zero);
293310            }
294311            break;
295312      case 0xc819: jr200_beep_w(space,0,data); break;
r9667r9668
311328   AM_RANGE(0xa000, 0xbfff) AM_ROM
312329
313330   AM_RANGE(0xc000, 0xc0ff) AM_READWRITE(jr200_pcg_1_r,jr200_pcg_1_w) //PCG area (1)
314   AM_RANGE(0xc100, 0xc3ff) AM_RAM AM_BASE(&jr200_vram)
331   AM_RANGE(0xc100, 0xc3ff) AM_RAM AM_BASE_MEMBER(jr200_state, vram)
315332   AM_RANGE(0xc400, 0xc4ff) AM_READWRITE(jr200_pcg_2_r,jr200_pcg_2_w) //PCG area (2)
316   AM_RANGE(0xc500, 0xc7ff) AM_RAM AM_BASE(&jr200_cram)
333   AM_RANGE(0xc500, 0xc7ff) AM_RAM AM_BASE_MEMBER(jr200_state, cram)
317334
318335//  0xc800 - 0xcfff I / O area
319   AM_RANGE(0xc800, 0xcfff) AM_READWRITE(mn1271_io_r,mn1271_io_w) AM_BASE(&mn1271_ram)
336   AM_RANGE(0xc800, 0xcfff) AM_READWRITE(mn1271_io_r,mn1271_io_w) AM_BASE_MEMBER(jr200_state, mn1271_ram)
320337
321338   AM_RANGE(0xd000, 0xd7ff) AM_READWRITE(jr200_bios_char_r,jr200_bios_char_w) //BIOS PCG RAM area
322339   AM_RANGE(0xd800, 0xdfff) AM_ROM // cart space (header 0x7e)
r9667r9668
451468
452469static MACHINE_START(jr200)
453470{
471   jr200_state *state = machine->driver_data<jr200_state>();
454472   beep_set_frequency(machine->device("beeper"),0);
455473   beep_set_state(machine->device("beeper"),0);
456   timer_d = timer_alloc(machine, timer_d_callback, NULL);
474   state->timer_d = timer_alloc(machine, timer_d_callback, NULL);
457475}
458476
459477static MACHINE_RESET(jr200)
460478{
479   jr200_state *state = machine->driver_data<jr200_state>();
461480   UINT8 *gfx_rom = memory_region(machine, "gfx_rom");
462481   UINT8 *gfx_ram = memory_region(machine, "gfx_ram");
463482   int i;
464   memset(mn1271_ram,0,0x800);
483   memset(state->mn1271_ram,0,0x800);
465484
466485   for(i=0;i<0x800;i++)
467486      gfx_ram[i] = gfx_rom[i];
r9667r9668
471490}
472491
473492
474static MACHINE_CONFIG_START( jr200, driver_device )
493static MACHINE_CONFIG_START( jr200, jr200_state )
475494   /* basic machine hardware */
476495   MDRV_CPU_ADD("maincpu", M6802, XTAL_14_31818MHz / 4) /* MN1800A, ? Mhz assumption that it is same as JR-100*/
477496   MDRV_CPU_PROGRAM_MAP(jr200_mem)
src/mess/drivers/h8.c
r9667r9668
2020#include "sound/beep.h"
2121#include "h8.lh"
2222
23
24class h8_state : public driver_device
25{
26public:
27   h8_state(running_machine &machine, const driver_device_config_base &config)
28      : driver_device(machine, config) { }
29
30   UINT8 digit;
31   UINT8 segment;
32   UINT8 irq_ctl;
33   running_device *beeper;
34   UINT8 ff_b;
35};
36
37
2338#define H8_CLOCK (XTAL_12_288MHz / 6)
2439#define H8_BEEP_FRQ (H8_CLOCK / 1024)
2540#define H8_IRQ_PULSE (H8_BEEP_FRQ / 2)
2641
27static UINT8 h8_digit;
28static UINT8 h8_segment;
29static UINT8 h8_irq_ctl;
30static running_device *h8_beeper;
3142
3243static TIMER_DEVICE_CALLBACK( h8_irq_pulse )
3344{
34   if (h8_irq_ctl & 1)
45   h8_state *state = timer.machine->driver_data<h8_state>();
46   if (state->irq_ctl & 1)
3547      cpu_set_input_line_and_vector(timer.machine->device("maincpu"), INPUT_LINE_IRQ0, ASSERT_LINE, 0xcf);
3648}
3749
r9667r9668
6779
6880static WRITE8_HANDLER( h8_f0_w )
6981{
82   h8_state *state = space->machine->driver_data<h8_state>();
7083    // this will always turn off int10 that was set by the timer
7184    // d0-d3 = digit select
7285    // d4 = int20 is allowed
r9667r9668
7487    // d6 = int10 is allowed
7588    // d7 = beeper enable
7689
77   h8_digit = data & 15;
78   if (h8_digit) output_set_digit_value(h8_digit, h8_segment);
90   state->digit = data & 15;
91   if (state->digit) output_set_digit_value(state->digit, state->segment);
7992
8093   output_set_value("mon_led",(data & 0x20) ? 0 : 1);
81   beep_set_state(h8_beeper, (data & 0x80) ? 0 : 1);
94   beep_set_state(state->beeper, (data & 0x80) ? 0 : 1);
8295
8396   cpu_set_input_line(space->machine->device("maincpu"), INPUT_LINE_IRQ0, CLEAR_LINE);
84   h8_irq_ctl &= 0xf0;
85   if (data & 0x40) h8_irq_ctl |= 1;
86   if (~data & 0x10) h8_irq_ctl |= 2;
97   state->irq_ctl &= 0xf0;
98   if (data & 0x40) state->irq_ctl |= 1;
99   if (~data & 0x10) state->irq_ctl |= 2;
87100}
88101
89102static WRITE8_HANDLER( h8_f1_w )
90103{
104   h8_state *state = space->machine->driver_data<h8_state>();
91105    //d7 segment dot
92106    //d6 segment f
93107    //d5 segment e
r9667r9668
97111    //d1 segment a
98112    //d0 segment g
99113
100   h8_segment = 0xff ^ BITSWAP8(data, 7, 0, 6, 5, 4, 3, 2, 1);
101   if (h8_digit) output_set_digit_value(h8_digit, h8_segment);
114   state->segment = 0xff ^ BITSWAP8(data, 7, 0, 6, 5, 4, 3, 2, 1);
115   if (state->digit) output_set_digit_value(state->digit, state->segment);
102116}
103117
104118static ADDRESS_MAP_START(h8_mem, ADDRESS_SPACE_PROGRAM, 8)
r9667r9668
144158
145159static MACHINE_RESET(h8)
146160{
147   h8_beeper = machine->device("beep");
148   beep_set_frequency(h8_beeper, H8_BEEP_FRQ);
161   h8_state *state = machine->driver_data<h8_state>();
162   state->beeper = machine->device("beep");
163   beep_set_frequency(state->beeper, H8_BEEP_FRQ);
149164   output_set_value("pwr_led", 0);
150   h8_irq_ctl = 1;
165   state->irq_ctl = 1;
151166}
152167
153168static WRITE_LINE_DEVICE_HANDLER( h8_inte_callback )
154169{
170   h8_state *drvstate = device->machine->driver_data<h8_state>();
155171        // operate the ION LED
156172   output_set_value("ion_led",(state) ? 0 : 1);
157   h8_irq_ctl &= 0x7f | ((state) ? 0 : 0x80);
173   drvstate->irq_ctl &= 0x7f | ((state) ? 0 : 0x80);
158174}
159175
160176static WRITE8_DEVICE_HANDLER( h8_status_callback )
161177{
178   h8_state *drvstate = device->machine->driver_data<h8_state>();
162179/* This is rather messy, but basically there are 2 D flipflops, one drives the other,
163180the data is /INTE while the clock is /M1. If the system is in Single Instruction mode,
164181a int20 (output of 2nd flipflop) will occur after 4 M1 steps, to pause the running program.
165182But, all of this can only occur if bit 5 of port F0 is low. */
166183
167   static UINT8 b=0;
168
169184   UINT8 state = (data & I8085_STATUS_M1) ? 0 : 1;
170   UINT8 c,a = (h8_irq_ctl & 0x80) ? 1 : 0;
185   UINT8 c,a = (drvstate->irq_ctl & 0x80) ? 1 : 0;
171186
172   if (h8_irq_ctl & 2)
187   if (drvstate->irq_ctl & 2)
173188   {
174189      if (!state) // rising pulse to push data through flipflops
175190      {
176         c=b^1; // from /Q of 2nd flipflop
177         b=a; // from Q of 1st flipflop
191         c=drvstate->ff_b^1; // from /Q of 2nd flipflop
192         drvstate->ff_b=a; // from Q of 1st flipflop
178193         if (c)
179194            cpu_set_input_line_and_vector(device->machine->device("maincpu"), INPUT_LINE_IRQ0, ASSERT_LINE, 0xd7);
180195      }
r9667r9668
182197   else
183198   { // flipflops are 'set'
184199      c=0;
185      b=1;
200      drvstate->ff_b=1;
186201   }
187202
188203     
r9667r9668
198213   DEVCB_NULL               /* SOD changed callback (I8085A only) */
199214};
200215
201static MACHINE_CONFIG_START( h8, driver_device )
216static MACHINE_CONFIG_START( h8, h8_state )
202217   /* basic machine hardware */
203218   MDRV_CPU_ADD("maincpu", I8080, H8_CLOCK)
204219   MDRV_CPU_PROGRAM_MAP(h8_mem)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team