Previous 15994 Revisions Next

r9675 Saturday 27th November, 2010 at 12:10:13 UTC by Nathan Woods
Another batch of driver_data conversions. [Atari Ace]
[src/mess/drivers]a2600.c llc.c mc80.c mekd2.c mikro80.c mz80.c newbrain.c ondra.c orao.c orion.c socrates.c svision.c tec1.c trs80.c univac.c x1.c
[src/mess/includes]llc.h mbee.h mc80.h mekd2.h mikro80.h mz80.h newbrain.h ondra.h orao.h orion.h svision.h trs80.h x1.h
[src/mess/machine]apple3.c llc.c mbee.c mc80.c mikro80.c mz80.c ondra.c orao.c orion.c trs80.c x1.c
[src/mess/video]llc.c mbee.c mc80.c mikro80.c mz80.c ondra.c orao.c orion.c trs80.c

src/mess/machine/apple3.c
r9674r9675
470470static READ8_DEVICE_HANDLER(apple3_via_1_in_a) { return ~0; }
471471static READ8_DEVICE_HANDLER(apple3_via_1_in_b) { return ~0; }
472472
473static WRITE8_DEVICE_HANDLER(apple3_via_0_out_a) {
474   apple3_state *state = device->machine->driver_data<apple3_state>(); apple3_via_out(device->machine, &state->via_0_a, data); }
475static WRITE8_DEVICE_HANDLER(apple3_via_0_out_b) {
476   apple3_state *state = device->machine->driver_data<apple3_state>(); apple3_via_out(device->machine, &state->via_0_b, data); }
477static WRITE8_DEVICE_HANDLER(apple3_via_1_out_a) {
478   apple3_state *state = device->machine->driver_data<apple3_state>(); apple3_via_out(device->machine, &state->via_1_a, data); }
479static WRITE8_DEVICE_HANDLER(apple3_via_1_out_b) {
480   apple3_state *state = device->machine->driver_data<apple3_state>(); apple3_via_out(device->machine, &state->via_1_b, data); }
473static WRITE8_DEVICE_HANDLER(apple3_via_0_out_a)
474{
475   apple3_state *state = device->machine->driver_data<apple3_state>();
476   apple3_via_out(device->machine, &state->via_0_a, data);
477}
481478
479static WRITE8_DEVICE_HANDLER(apple3_via_0_out_b)
480{
481   apple3_state *state = device->machine->driver_data<apple3_state>();
482   apple3_via_out(device->machine, &state->via_0_b, data);
483}
484
485static WRITE8_DEVICE_HANDLER(apple3_via_1_out_a)
486{
487   apple3_state *state = device->machine->driver_data<apple3_state>();
488   apple3_via_out(device->machine, &state->via_1_a, data);
489}
490
491static WRITE8_DEVICE_HANDLER(apple3_via_1_out_b)
492{
493   apple3_state *state = device->machine->driver_data<apple3_state>();
494   apple3_via_out(device->machine, &state->via_1_b, data);
495}
496
482497static void apple2_via_1_irq_func(running_device *device, int state)
483498{
484499   apple3_state *drvstate = device->machine->driver_data<apple3_state>();
src/mess/machine/mc80.c
r9674r9675
8989
9090WRITE8_HANDLER( mc8030_vis_w )
9191{
92   mc80_state *state = space->machine->driver_data<mc80_state>();
9293   // reg C
9394   // 7 6 5 4 -- module
9495   //         3 - 0 left half, 1 right half
r9674r9675
104105   UINT16 addr = ((offset & 0xff00) >> 2) | ((offset & 0x08) << 2) | (data >> 3);
105106   UINT8 val[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
106107   int c = offset & 1;
107   mc8030_video_mem[addr] = mc8030_video_mem[addr] | (val[data & 7]*c);
108   state->mc8030_video_mem[addr] = state->mc8030_video_mem[addr] | (val[data & 7]*c);
108109
109110}
110111
src/mess/machine/mbee.c
r9674r9675
1313#include "devices/flopdrv.h"
1414#include "includes/mbee.h"
1515
16static size_t mbee_size;
17static UINT8 mbee_clock_pulse;
18static UINT8 mbee256_key_available;
19static UINT8 fdc_intrq,fdc_drq;
20static UINT8 mbee_0a;
21static running_device *mbee_fdc;
22static mc146818_device *mbee_rtc;
23static running_device *mbee_z80pio;
24static running_device *mbee_speaker;
25static running_device *mbee_cassette;
26static running_device *mbee_printer;
2716
2817/***********************************************************
2918
r9674r9675
3322
3423static WRITE8_DEVICE_HANDLER( pio_ardy )
3524{
25   mbee_state *state = device->machine->driver_data<mbee_state>();
3626   /* devices need to be redeclared in this callback for some strange reason */
37   mbee_printer = device->machine->device("centronics");
38   centronics_strobe_w(mbee_printer, (data) ? 0 : 1);
27   state->printer = device->machine->device("centronics");
28   centronics_strobe_w(state->printer, (data) ? 0 : 1);
3929}
4030
4131static WRITE8_DEVICE_HANDLER( pio_port_a_w )
4232{
33   mbee_state *state = device->machine->driver_data<mbee_state>();
4334   /* hardware strobe driven by PIO ARDY, bit 7..0 = data */
44   z80pio_astb_w( mbee_z80pio, 1);   /* needed - otherwise nothing prints */
45   centronics_data_w(mbee_printer, 0, data);
35   z80pio_astb_w( state->z80pio, 1);   /* needed - otherwise nothing prints */
36   centronics_data_w(state->printer, 0, data);
4637};
4738
4839static WRITE8_DEVICE_HANDLER( pio_port_b_w )
4940{
41   mbee_state *state = device->machine->driver_data<mbee_state>();
5042/*  PIO port B - d5..d2 not emulated
5143    d7 network interrupt (microbee network for classrooms)
5244    d6 speaker
r9674r9675
5749    d1 cass out and (on 256tc) keyboard irq
5850    d0 cass in */
5951
60   cassette_output(mbee_cassette, (data & 0x02) ? -1.0 : +1.0);
52   cassette_output(state->cassette, (data & 0x02) ? -1.0 : +1.0);
6153
62   speaker_level_w(mbee_speaker, (data & 0x40) ? 1 : 0);
54   speaker_level_w(state->speaker, (data & 0x40) ? 1 : 0);
6355};
6456
6557static READ8_DEVICE_HANDLER( pio_port_b_r )
6658{
59   mbee_state *state = device->machine->driver_data<mbee_state>();
6760   UINT8 data = 0;
6861
69   if (cassette_input(mbee_cassette) > 0.03) data |= 1;
62   if (cassette_input(state->cassette) > 0.03) data |= 1;
7063
71   data |= mbee_clock_pulse;
72   data |= mbee256_key_available;
64   data |= state->clock_pulse;
65   data |= state->mbee256_key_available;
7366
74   mbee_clock_pulse = 0;
67   state->clock_pulse = 0;
7568
7669   return data;
7770};
r9674r9675
9891
9992static WRITE_LINE_DEVICE_HANDLER( mbee_fdc_intrq_w )
10093{
101   fdc_intrq = state ? 0x80 : 0;
94   mbee_state *drvstate = device->machine->driver_data<mbee_state>();
95   drvstate->fdc_intrq = state ? 0x80 : 0;
10296}
10397
10498static WRITE_LINE_DEVICE_HANDLER( mbee_fdc_drq_w )
10599{
106   fdc_drq = state ? 0x80 : 0;
100   mbee_state *drvstate = device->machine->driver_data<mbee_state>();
101   drvstate->fdc_drq = state ? 0x80 : 0;
107102}
108103
109104const wd17xx_interface mbee_wd17xx_interface =
r9674r9675
116111
117112READ8_HANDLER ( mbee_fdc_status_r )
118113{
114   mbee_state *state = space->machine->driver_data<mbee_state>();
119115/*  d7 indicate if IRQ or DRQ is occuring (1=happening)
120116    d6..d0 not used */
121117
122   return 0x7f | fdc_intrq | fdc_drq;
118   return 0x7f | state->fdc_intrq | state->fdc_drq;
123119}
124120
125121WRITE8_HANDLER ( mbee_fdc_motor_w )
126122{
123   mbee_state *state = space->machine->driver_data<mbee_state>();
127124/*  d7..d4 not used
128125    d3 density (1=MFM)
129126    d2 side (1=side 1)
130127    d1..d0 drive select (0 to 3) */
131128
132   wd17xx_set_drive(mbee_fdc, data & 3);
133   wd17xx_set_side(mbee_fdc, (data & 4) ? 1 : 0);
134   wd17xx_dden_w(mbee_fdc, !BIT(data, 3));
129   wd17xx_set_drive(state->fdc, data & 3);
130   wd17xx_set_side(state->fdc, (data & 4) ? 1 : 0);
131   wd17xx_dden_w(state->fdc, !BIT(data, 3));
135132   /* no idea what turns the motors on & off, guessing it could be drive select
136133   commented out because it prevents 128k and 256TC from booting up */
137134   //floppy_mon_w(floppy_get_device(space->machine, data & 3), CLEAR_LINE); // motor on
r9674r9675
143140
144141************************************************************/
145142
146static UINT8 mbee256_was_pressed[15] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
147static UINT8 mbee256_q[20];
148static UINT8 mbee256_q_pos;
149143
150144static TIMER_CALLBACK( mbee256_kbd )
151145{
146   mbee_state *state = machine->driver_data<mbee_state>();
152147    /* Keyboard scanner is a Mostek M3870 chip. Its speed of operation is determined by a 15k resistor on
153148    pin 2 (XTL2) and is therefore unknown. If a key change is detected (up or down), the /strobe
154149    line activates, sending a high to bit 1 of port 2 (one of the pio input lines). The next read of
r9674r9675
175170   /* find what has changed */
176171   for (i = 0; i < 15; i++)
177172   {
178      if (pressed[i] != mbee256_was_pressed[i])
173      if (pressed[i] != state->mbee256_was_pressed[i])
179174      {
180175         /* get scankey value */
181176         for (j = 0; j < 8; j++)
182177         {
183            if (BIT(pressed[i]^mbee256_was_pressed[i], j))
178            if (BIT(pressed[i]^state->mbee256_was_pressed[i], j))
184179            {
185180               /* put it in the queue */
186               mbee256_q[mbee256_q_pos] = (i << 3) | j | (BIT(pressed[i], j) ? 0x80 : 0);
187               if (mbee256_q_pos < 19) mbee256_q_pos++;
181               state->mbee256_q[state->mbee256_q_pos] = (i << 3) | j | (BIT(pressed[i], j) ? 0x80 : 0);
182               if (state->mbee256_q_pos < 19) state->mbee256_q_pos++;
188183            }
189184         }
190         mbee256_was_pressed[i] = pressed[i];
185         state->mbee256_was_pressed[i] = pressed[i];
191186      }
192187   }
193188
194189   /* if anything queued, cause an interrupt */
195   if (mbee256_q_pos)
196      mbee256_key_available = 2; // set irq
190   if (state->mbee256_q_pos)
191      state->mbee256_key_available = 2; // set irq
197192}
198193
199194READ8_HANDLER( mbee256_18_r )
200195{
201   UINT8 i, data = mbee256_q[0]; // get oldest key
196   mbee_state *state = space->machine->driver_data<mbee_state>();
197   UINT8 i, data = state->mbee256_q[0]; // get oldest key
202198
203   if (mbee256_q_pos)
199   if (state->mbee256_q_pos)
204200   {
205      mbee256_q_pos--;
206      for (i = 0; i < mbee256_q_pos; i++) mbee256_q[i] = mbee256_q[i+1]; // ripple queue
201      state->mbee256_q_pos--;
202      for (i = 0; i < state->mbee256_q_pos; i++) state->mbee256_q[i] = state->mbee256_q[i+1]; // ripple queue
207203   }
208204
209   mbee256_key_available = 0; // clear irq
205   state->mbee256_key_available = 0; // clear irq
210206   return data;
211207}
212208
r9674r9675
239235
240236WRITE8_HANDLER( mbee_04_w )   // address
241237{
242   mbee_rtc->write(*space, 0, data);
238   mbee_state *state = space->machine->driver_data<mbee_state>();
239   state->rtc->write(*space, 0, data);
243240}
244241
245242WRITE8_HANDLER( mbee_06_w )   // write
246243{
247   mbee_rtc->write(*space, 1, data);
244   mbee_state *state = space->machine->driver_data<mbee_state>();
245   state->rtc->write(*space, 1, data);
248246}
249247
250248READ8_HANDLER( mbee_07_r )   // read
251249{
252   return mbee_rtc->read(*space, 1);
250   mbee_state *state = space->machine->driver_data<mbee_state>();
251   return state->rtc->read(*space, 1);
253252}
254253
255254static TIMER_CALLBACK( mbee_rtc_irq )
256255{
256   mbee_state *state = machine->driver_data<mbee_state>();
257257   address_space *mem = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
258258   mc146818_device *rtc = machine->device<mc146818_device>("rtc");
259259   UINT8 data = rtc->read(*mem, 12);
260   if (data) mbee_clock_pulse = 0x80;
260   if (data) state->clock_pulse = 0x80;
261261}
262262
263263
r9674r9675
472472
473473READ8_HANDLER ( mbeeic_0a_r )
474474{
475   return mbee_0a;
475   mbee_state *state = space->machine->driver_data<mbee_state>();
476   return state->_0a;
476477}
477478
478479WRITE8_HANDLER ( mbeeic_0a_w )
479480{
480   mbee_0a = data;
481   mbee_state *state = space->machine->driver_data<mbee_state>();
482   state->_0a = data;
481483   memory_set_bank(space->machine, "pak", data & 15);
482484}
483485
484486READ8_HANDLER ( mbeepc_telcom_low_r )
485487{
488   mbee_state *state = space->machine->driver_data<mbee_state>();
486489/* Read of port 0A - set Telcom rom to first half */
487490   memory_set_bank(space->machine, "telcom", 0);
488   return mbee_0a;
491   return state->_0a;
489492}
490493
491494READ8_HANDLER ( mbeepc_telcom_high_r )
492495{
496   mbee_state *state = space->machine->driver_data<mbee_state>();
493497/* Read of port 10A - set Telcom rom to 2nd half */
494498   memory_set_bank(space->machine, "telcom", 1);
495   return mbee_0a;
499   return state->_0a;
496500}
497501
498502
r9674r9675
516520
517521static void machine_reset_common(running_machine *machine)
518522{
519   mbee_z80pio = machine->device("z80pio");
520   mbee_speaker = machine->device("speaker");
521   mbee_cassette = machine->device("cassette");
522   mbee_printer = machine->device("centronics");
523   mbee_state *state = machine->driver_data<mbee_state>();
524   state->z80pio = machine->device("z80pio");
525   state->speaker = machine->device("speaker");
526   state->cassette = machine->device("cassette");
527   state->printer = machine->device("centronics");
523528}
524529
525530static void machine_reset_common_disk(running_machine *machine)
526531{
532   mbee_state *state = machine->driver_data<mbee_state>();
527533   machine_reset_common(machine);
528   mbee_fdc = machine->device("fdc");
534   state->fdc = machine->device("fdc");
529535   /* These values need to be fine tuned or the fdc repaired */
530   wd17xx_set_pause_time(mbee_fdc, 45);       /* default is 40 usec if not set */
531   wd17xx_set_complete_command_delay(mbee_fdc, 50);   /* default is 12 usec if not set */
536   wd17xx_set_pause_time(state->fdc, 45);       /* default is 40 usec if not set */
537   wd17xx_set_complete_command_delay(state->fdc, 50);   /* default is 12 usec if not set */
532538}
533539
534540MACHINE_RESET( mbee )
r9674r9675
563569
564570MACHINE_RESET( mbee256 )
565571{
572   mbee_state *state = machine->driver_data<mbee_state>();
566573   UINT8 i;
567574   address_space *mem = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
568575   machine_reset_common_disk(machine);
569   mbee_rtc = machine->device<mc146818_device>("rtc");
570   for (i = 0; i < 15; i++) mbee256_was_pressed[i] = 0;
571   mbee256_q_pos = 0;
576   state->rtc = machine->device<mc146818_device>("rtc");
577   for (i = 0; i < 15; i++) state->mbee256_was_pressed[i] = 0;
578   state->mbee256_q_pos = 0;
572579   mbee256_50_w(mem,0,0); // set banks to default
573580   memory_set_bank(machine, "boot", 8); // boot time
574581   timer_set(machine, ATTOTIME_IN_USEC(4), NULL, 0, mbee_reset);
r9674r9675
576583
577584MACHINE_RESET( mbeett )
578585{
586   mbee_state *state = machine->driver_data<mbee_state>();
579587   UINT8 i;
580   mbee_rtc = machine->device<mc146818_device>("rtc");
581   for (i = 0; i < 15; i++) mbee256_was_pressed[i] = 0;
582   mbee256_q_pos = 0;
588   state->rtc = machine->device<mc146818_device>("rtc");
589   for (i = 0; i < 15; i++) state->mbee256_was_pressed[i] = 0;
590   state->mbee256_q_pos = 0;
583591   machine_reset_common(machine);
584592   memory_set_bank(machine, "boot", 1);
585593   timer_set(machine, ATTOTIME_IN_USEC(4), NULL, 0, mbee_reset);
r9674r9675
589597{
590598// Due to the uncertainly and hackage here, this is commented out for now - Robbbert - 05-Oct-2010
591599#if 0
600   mbee_state *state = device->machine->driver_data<mbee_state>();
592601
593602   //address_space *space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
594603   /* The printer status connects to the pio ASTB pin, and the printer changing to not
r9674r9675
596605        The line below does what the interrupt should be doing. */
597606   /* But it would break any program loaded to that area of memory, such as CP/M programs */
598607
599   //z80pio_astb_w( mbee_z80pio, centronics_busy_r(mbee_printer));   /* signal int when not busy (L->H) */
600   //space->write_byte(0x109, centronics_busy_r(mbee_printer));
608   //z80pio_astb_w( state->z80pio, centronics_busy_r(state->printer));   /* signal int when not busy (L->H) */
609   //space->write_byte(0x109, centronics_busy_r(state->printer));
601610
602611
603612   /* once per frame, pulse the PIO B bit 7 - it is in the schematic as an option,
604613   but need to find out what it does */
605   mbee_clock_pulse = 0x80;
614   state->clock_pulse = 0x80;
606615   irq0_line_hold(device);
607616
608617#endif
r9674r9675
610619
611620DRIVER_INIT( mbee )
612621{
622   mbee_state *state = machine->driver_data<mbee_state>();
613623   UINT8 *RAM = memory_region(machine, "maincpu");
614624   memory_configure_bank(machine, "boot", 0, 2, &RAM[0x0000], 0x8000);
615   mbee_size = 0x4000;
625   state->size = 0x4000;
616626}
617627
618628DRIVER_INIT( mbeeic )
619629{
630   mbee_state *state = machine->driver_data<mbee_state>();
620631   UINT8 *RAM = memory_region(machine, "maincpu");
621632   memory_configure_bank(machine, "boot", 0, 2, &RAM[0x0000], 0x8000);
622633
r9674r9675
624635   memory_configure_bank(machine, "pak", 0, 16, &RAM[0x0000], 0x2000);
625636
626637   memory_set_bank(machine, "pak", 0);
627   mbee_size = 0x8000;
638   state->size = 0x8000;
628639}
629640
630641DRIVER_INIT( mbeepc )
631642{
643   mbee_state *state = machine->driver_data<mbee_state>();
632644   UINT8 *RAM = memory_region(machine, "maincpu");
633645   memory_configure_bank(machine, "boot", 0, 2, &RAM[0x0000], 0x8000);
634646
r9674r9675
640652
641653   memory_set_bank(machine, "pak", 0);
642654   memory_set_bank(machine, "telcom", 0);
643   mbee_size = 0x8000;
655   state->size = 0x8000;
644656}
645657
646658DRIVER_INIT( mbeepc85 )
647659{
660   mbee_state *state = machine->driver_data<mbee_state>();
648661   UINT8 *RAM = memory_region(machine, "maincpu");
649662   memory_configure_bank(machine, "boot", 0, 2, &RAM[0x0000], 0x8000);
650663
r9674r9675
656669
657670   memory_set_bank(machine, "pak", 5);
658671   memory_set_bank(machine, "telcom", 0);
659   mbee_size = 0x8000;
672   state->size = 0x8000;
660673}
661674
662675DRIVER_INIT( mbeeppc )
663676{
677   mbee_state *state = machine->driver_data<mbee_state>();
664678   UINT8 *RAM = memory_region(machine, "maincpu");
665679   memory_configure_bank(machine, "boot", 0, 1, &RAM[0x0000], 0x0000);
666680
r9674r9675
677691   memory_set_bank(machine, "pak", 5);
678692   memory_set_bank(machine, "telcom", 0);
679693   memory_set_bank(machine, "basic", 0);
680   mbee_size = 0x8000;
694   state->size = 0x8000;
681695}
682696
683697DRIVER_INIT( mbee56 )
684698{
699   mbee_state *state = machine->driver_data<mbee_state>();
685700   UINT8 *RAM = memory_region(machine, "maincpu");
686701   memory_configure_bank(machine, "boot", 0, 2, &RAM[0x0000], 0xe000);
687   mbee_size = 0xe000;
702   state->size = 0xe000;
688703}
689704
690705DRIVER_INIT( mbee64 )
691706{
707   mbee_state *state = machine->driver_data<mbee_state>();
692708   UINT8 *RAM = memory_region(machine, "maincpu");
693709   memory_configure_bank(machine, "boot", 0, 1, &RAM[0x0000], 0x0000);
694710   memory_configure_bank(machine, "bankl", 0, 1, &RAM[0x1000], 0x0000);
r9674r9675
699715   memory_configure_bank(machine, "bankh", 1, 1, &RAM[0x0000], 0x0000);
700716   memory_configure_bank(machine, "boot", 1, 1, &RAM[0x0000], 0x0000);
701717
702   mbee_size = 0xf000;
718   state->size = 0xf000;
703719}
704720
705721DRIVER_INIT( mbee128 )
706722{
723   mbee_state *state = machine->driver_data<mbee_state>();
707724   UINT8 *RAM = memory_region(machine, "maincpu");
708725   memory_configure_bank(machine, "boot", 0, 4, &RAM[0x0000], 0x8000); // standard banks 0000
709726   memory_configure_bank(machine, "bank1", 0, 4, &RAM[0x1000], 0x8000); // standard banks 1000
r9674r9675
719736   memory_configure_bank(machine, "bank8l", 0, 1, &RAM[0x0000], 0x0000); // rom
720737   memory_configure_bank(machine, "bank8h", 0, 1, &RAM[0x0800], 0x0000); // rom
721738
722   mbee_size = 0x8000;
739   state->size = 0x8000;
723740}
724741
725742DRIVER_INIT( mbee256 )
726743{
744   mbee_state *state = machine->driver_data<mbee_state>();
727745   UINT8 *RAM = memory_region(machine, "maincpu");
728746   memory_configure_bank(machine, "boot", 0, 8, &RAM[0x0000], 0x8000); // standard banks 0000
729747   memory_configure_bank(machine, "bank1", 0, 8, &RAM[0x1000], 0x8000); // standard banks 1000
r9674r9675
742760   timer_pulse(machine, ATTOTIME_IN_HZ(1),NULL,0,mbee_rtc_irq);   /* timer for rtc */
743761   timer_pulse(machine, ATTOTIME_IN_HZ(25),NULL,0,mbee256_kbd);   /* timer for kbd */
744762
745   mbee_size = 0x8000;
763   state->size = 0x8000;
746764}
747765
748766DRIVER_INIT( mbeett )
749767{
768   mbee_state *state = machine->driver_data<mbee_state>();
750769   UINT8 *RAM = memory_region(machine, "maincpu");
751770   memory_configure_bank(machine, "boot", 0, 2, &RAM[0x0000], 0x8000);
752771
r9674r9675
762781   timer_pulse(machine, ATTOTIME_IN_HZ(1),NULL,0,mbee_rtc_irq);   /* timer for rtc */
763782   timer_pulse(machine, ATTOTIME_IN_HZ(25),NULL,0,mbee256_kbd);   /* timer for kbd */
764783
765   mbee_size = 0x8000;
784   state->size = 0x8000;
766785}
767786
768787
r9674r9675
795814
796815QUICKLOAD_LOAD( mbee )
797816{
817   mbee_state *state = image.device().machine->driver_data<mbee_state>();
798818   running_device *cpu = image.device().machine->device("maincpu");
799819   address_space *space = cputag_get_address_space(image.device().machine, "maincpu", ADDRESS_SPACE_PROGRAM);
800820   UINT16 i, j;
r9674r9675
813833            return IMAGE_INIT_FAIL;
814834         }
815835
816         if ((j < mbee_size) || (j > 0xefff))
836         if ((j < state->size) || (j > 0xefff))
817837            space->write_byte(j, data);
818838         else
819839         {
r9674r9675
843863            return IMAGE_INIT_FAIL;
844864         }
845865
846         if ((j < mbee_size) || (j > 0xefff))
866         if ((j < state->size) || (j > 0xefff))
847867            space->write_byte(j, data);
848868         else
849869         {
src/mess/machine/x1.c
r9674r9675
7070
7171int x1_keyboard_device::z80daisy_irq_state()
7272{
73   if(x1_key_irq_flag != 0)
73   x1_state *state = machine->driver_data<x1_state>();
74   if(state->key_irq_flag != 0)
7475      return Z80_DAISY_INT;
7576   return 0;
7677}
r9674r9675
8384
8485int x1_keyboard_device::z80daisy_irq_ack()
8586{
86   x1_key_irq_flag = 0;
87   x1_state *state = machine->driver_data<x1_state>();
88   state->key_irq_flag = 0;
8789   cputag_set_input_line(device().machine,"maincpu",INPUT_LINE_IRQ0,CLEAR_LINE);
88   return x1_key_irq_vector;
90   return state->key_irq_vector;
8991}
9092
9193//-------------------------------------------------
src/mess/machine/orao.c
r9674r9675
1212#include "devices/cassette.h"
1313#include "includes/orao.h"
1414
15UINT8 *orao_memory;
1615
1716/* Driver initialization */
1817DRIVER_INIT(orao)
1918{
20   memset(orao_memory,0xff,0x6000);
19   orao_state *state = machine->driver_data<orao_state>();
20   memset(state->memory,0xff,0x6000);
2121}
2222
2323DRIVER_INIT(orao103)
2424{
25   memset(orao_memory,0xff,0x6000);
25   orao_state *state = machine->driver_data<orao_state>();
26   memset(state->memory,0xff,0x6000);
2627}
2728
2829MACHINE_RESET( orao )
src/mess/machine/orion.c
r9674r9675
2323#define SCREEN_WIDTH_480 60
2424#define SCREEN_WIDTH_512 64
2525
26static UINT8 romdisk_lsb,romdisk_msb;
27UINT8 orion128_video_mode;
28UINT8 orion128_video_page;
29static UINT8 orion128_memory_page;
3026
31UINT8 orion128_video_width;
3227
33static UINT8 orionz80_memory_page;
34static UINT8 orionz80_dispatcher;
3528
36UINT8 orion_video_mode_mask;
3729
3830static READ8_DEVICE_HANDLER (orion_romdisk_porta_r )
3931{
32   orion_state *state = device->machine->driver_data<orion_state>();
4033   UINT8 *romdisk = memory_region(device->machine, "maincpu") + 0x10000;
41   return romdisk[romdisk_msb*256+romdisk_lsb];
34   return romdisk[state->romdisk_msb*256+state->romdisk_lsb];
4235}
4336
4437static WRITE8_DEVICE_HANDLER (orion_romdisk_portb_w )
4538{
46   romdisk_lsb = data;
39   orion_state *state = device->machine->driver_data<orion_state>();
40   state->romdisk_lsb = data;
4741}
4842
4943static WRITE8_DEVICE_HANDLER (orion_romdisk_portc_w )
5044{
51   romdisk_msb = data;
45   orion_state *state = device->machine->driver_data<orion_state>();
46   state->romdisk_msb = data;
5247}
5348
5449I8255A_INTERFACE( orion128_ppi8255_interface_1)
r9674r9675
6459
6560MACHINE_START( orion128 )
6661{
67   orion_video_mode_mask = 7;
62   orion_state *state = machine->driver_data<orion_state>();
63   state->video_mode_mask = 7;
6864}
6965
7066READ8_HANDLER ( orion128_system_r )
r9674r9675
10096
10197WRITE8_HANDLER ( orion128_video_mode_w )
10298{
103   if ((data & 0x80)!=(orion128_video_mode & 0x80))
99   orion_state *state = space->machine->driver_data<orion_state>();
100   if ((data & 0x80)!=(state->orion128_video_mode & 0x80))
104101   {
105102      if ((data & 0x80)==0x80)
106103      {
107         if (orion_video_mode_mask == 31)
104         if (state->video_mode_mask == 31)
108105         {
109            orion128_video_width = SCREEN_WIDTH_512;
106            state->orion128_video_width = SCREEN_WIDTH_512;
110107            orion_set_video_mode(space->machine,512);
111108         }
112109         else
113110         {
114            orion128_video_width = SCREEN_WIDTH_480;
111            state->orion128_video_width = SCREEN_WIDTH_480;
115112            orion_set_video_mode(space->machine,480);
116113         }
117114      }
118115      else
119116      {
120         orion128_video_width = SCREEN_WIDTH_384;
117         state->orion128_video_width = SCREEN_WIDTH_384;
121118         orion_set_video_mode(space->machine,384);
122119      }
123120   }
124121
125   orion128_video_mode = data;
122   state->orion128_video_mode = data;
126123}
127124
128125WRITE8_HANDLER ( orion128_video_page_w )
129126{
130   if (orion128_video_page != data)
127   orion_state *state = space->machine->driver_data<orion_state>();
128   if (state->orion128_video_page != data)
131129   {
132      if ((data & 0x80)!=(orion128_video_page & 0x80))
130      if ((data & 0x80)!=(state->orion128_video_page & 0x80))
133131      {
134132         if ((data & 0x80)==0x80)
135133         {
136            if (orion_video_mode_mask == 31)
134            if (state->video_mode_mask == 31)
137135            {
138               orion128_video_width = SCREEN_WIDTH_512;
136               state->orion128_video_width = SCREEN_WIDTH_512;
139137               orion_set_video_mode(space->machine,512);
140138            }
141139            else
142140            {
143               orion128_video_width = SCREEN_WIDTH_480;
141               state->orion128_video_width = SCREEN_WIDTH_480;
144142               orion_set_video_mode(space->machine,480);
145143            }
146144         }
147145         else
148146         {
149            orion128_video_width = SCREEN_WIDTH_384;
147            state->orion128_video_width = SCREEN_WIDTH_384;
150148            orion_set_video_mode(space->machine,384);
151149         }
152150      }
153151   }
154   orion128_video_page = data;
152   state->orion128_video_page = data;
155153}
156154
157155
158156WRITE8_HANDLER ( orion128_memory_page_w )
159157{
160   if (data!=orion128_memory_page )
158   orion_state *state = space->machine->driver_data<orion_state>();
159   if (data!=state->orion128_memory_page )
161160   {
162161      memory_set_bankptr(space->machine, "bank1", messram_get_ptr(space->machine->device("messram")) + (data & 3) * 0x10000);
163      orion128_memory_page = (data & 3);
162      state->orion128_memory_page = (data & 3);
164163   }
165164}
166165
167166MACHINE_RESET ( orion128 )
168167{
169   orion128_video_page = 0;
170   orion128_video_mode = 0;
171   orion128_memory_page = -1;
168   orion_state *state = machine->driver_data<orion_state>();
169   state->orion128_video_page = 0;
170   state->orion128_video_mode = 0;
171   state->orion128_memory_page = -1;
172172   memory_set_bankptr(machine, "bank1", memory_region(machine, "maincpu") + 0xf800);
173173   memory_set_bankptr(machine, "bank2", messram_get_ptr(machine->device("messram")) + 0xf000);
174   orion128_video_width = SCREEN_WIDTH_384;
174   state->orion128_video_width = SCREEN_WIDTH_384;
175175   orion_set_video_mode(machine,384);
176176   radio86_init_keyboard();
177177}
r9674r9675
248248
249249MACHINE_START( orionz80 )
250250{
251   orion_video_mode_mask = 7;
251   orion_state *state = machine->driver_data<orion_state>();
252   state->video_mode_mask = 7;
252253}
253254
254static UINT8 orion_speaker;
255255WRITE8_HANDLER ( orionz80_sound_w )
256256{
257   orion_state *state = space->machine->driver_data<orion_state>();
257258   running_device *speaker = space->machine->device("speaker");
258   if (orion_speaker == 0)
259   if (state->speaker == 0)
259260   {
260      orion_speaker = data;
261      state->speaker = data;
261262   }
262263   else
263264   {
264      orion_speaker = 0 ;
265      state->speaker = 0 ;
265266   }
266   speaker_level_w(speaker,orion_speaker);
267   speaker_level_w(speaker,state->speaker);
267268
268269}
269270
r9674r9675
276277
277278static void orionz80_switch_bank(running_machine *machine)
278279{
280   orion_state *state = machine->driver_data<orion_state>();
279281   UINT8 bank_select;
280282   UINT8 segment_select;
281283   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
282284
283   bank_select = (orionz80_dispatcher & 0x0c) >> 2;
284   segment_select = orionz80_dispatcher & 0x03;
285   bank_select = (state->orionz80_dispatcher & 0x0c) >> 2;
286   segment_select = state->orionz80_dispatcher & 0x03;
285287
286288   memory_install_write_bank(space, 0x0000, 0x3fff, 0, 0, "bank1");
287   if ((orionz80_dispatcher & 0x80)==0)
289   if ((state->orionz80_dispatcher & 0x80)==0)
288290   { // dispatcher on
289291      memory_set_bankptr(machine, "bank1", messram_get_ptr(machine->device("messram")) + 0x10000 * bank_select + segment_select * 0x4000 );
290292   }
291293   else
292294   { // dispatcher off
293      memory_set_bankptr(machine, "bank1", messram_get_ptr(machine->device("messram")) + 0x10000 * orionz80_memory_page);
295      memory_set_bankptr(machine, "bank1", messram_get_ptr(machine->device("messram")) + 0x10000 * state->orionz80_memory_page);
294296   }
295297
296   memory_set_bankptr(machine, "bank2", messram_get_ptr(machine->device("messram")) + 0x4000 + 0x10000 * orionz80_memory_page);
298   memory_set_bankptr(machine, "bank2", messram_get_ptr(machine->device("messram")) + 0x4000 + 0x10000 * state->orionz80_memory_page);
297299
298   if ((orionz80_dispatcher & 0x20) == 0)
300   if ((state->orionz80_dispatcher & 0x20) == 0)
299301   {
300302      memory_install_write8_handler(space, 0xf400, 0xf4ff, 0, 0, orion128_system_w);
301303      memory_install_write8_handler(space, 0xf500, 0xf5ff, 0, 0, orion128_romdisk_w);
r9674r9675
318320   else
319321   {
320322      /* if it is full memory access */
321      memory_set_bankptr(machine, "bank3", messram_get_ptr(machine->device("messram")) + 0xf000 + 0x10000 * orionz80_memory_page);
322      memory_set_bankptr(machine, "bank4", messram_get_ptr(machine->device("messram")) + 0xf400 + 0x10000 * orionz80_memory_page);
323      memory_set_bankptr(machine, "bank5", messram_get_ptr(machine->device("messram")) + 0xf800 + 0x10000 * orionz80_memory_page);
323      memory_set_bankptr(machine, "bank3", messram_get_ptr(machine->device("messram")) + 0xf000 + 0x10000 * state->orionz80_memory_page);
324      memory_set_bankptr(machine, "bank4", messram_get_ptr(machine->device("messram")) + 0xf400 + 0x10000 * state->orionz80_memory_page);
325      memory_set_bankptr(machine, "bank5", messram_get_ptr(machine->device("messram")) + 0xf800 + 0x10000 * state->orionz80_memory_page);
324326   }
325327}
326328
327329WRITE8_HANDLER ( orionz80_memory_page_w )
328330{
329   orionz80_memory_page = data & 7;
331   orion_state *state = space->machine->driver_data<orion_state>();
332   state->orionz80_memory_page = data & 7;
330333   orionz80_switch_bank(space->machine);
331334}
332335
333336WRITE8_HANDLER ( orionz80_dispatcher_w )
334337{
335   orionz80_dispatcher = data;
338   orion_state *state = space->machine->driver_data<orion_state>();
339   state->orionz80_dispatcher = data;
336340   orionz80_switch_bank(space->machine);
337341}
338342
339343MACHINE_RESET ( orionz80 )
340344{
345   orion_state *state = machine->driver_data<orion_state>();
341346   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
342347
343348   memory_unmap_write(space, 0x0000, 0x3fff, 0, 0);
r9674r9675
365370   memory_set_bankptr(machine, "bank5", memory_region(machine, "maincpu") + 0xf800);
366371
367372
368   orion128_video_page = 0;
369   orion128_video_mode = 0;
370   orionz80_memory_page = 0;
371   orionz80_dispatcher = 0;
372   orion_speaker = 0;
373   orion128_video_width = SCREEN_WIDTH_384;
373   state->orion128_video_page = 0;
374   state->orion128_video_mode = 0;
375   state->orionz80_memory_page = 0;
376   state->orionz80_dispatcher = 0;
377   state->speaker = 0;
378   state->orion128_video_width = SCREEN_WIDTH_384;
374379   orion_set_video_mode(machine,384);
375380   radio86_init_keyboard();
376381}
377382
378383INTERRUPT_GEN( orionz80_interrupt )
379384{
380   if ((orionz80_dispatcher & 0x40)==0x40)
385   orion_state *state = device->machine->driver_data<orion_state>();
386   if ((state->orionz80_dispatcher & 0x40)==0x40)
381387   {
382388      cpu_set_input_line(device, 0, HOLD_LINE);
383389   }
r9674r9675
413419   }
414420}
415421
416static UINT8 orionpro_ram0_segment;
417static UINT8 orionpro_ram1_segment;
418static UINT8 orionpro_ram2_segment;
419422
420static UINT8 orionpro_page;
421static UINT8 orionpro_128_page;
422static UINT8 orionpro_rom2_segment;
423423
424static UINT8 orionpro_dispatcher;
425UINT8 orionpro_pseudo_color;
426424
427425
428426static WRITE8_HANDLER ( orionpro_memory_page_w );
429427
430428static void orionpro_bank_switch(running_machine *machine)
431429{
430   orion_state *state = machine->driver_data<orion_state>();
432431   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
433   int page = orionpro_page & 7; // we have only 8 pages
434   int is128 = (orionpro_dispatcher & 0x80) ? 1 : 0;
432   int page = state->orionpro_page & 7; // we have only 8 pages
433   int is128 = (state->orionpro_dispatcher & 0x80) ? 1 : 0;
435434   if (is128==1)
436435   {
437      page = orionpro_128_page & 7;
436      page = state->orionpro_128_page & 7;
438437   }
439438   memory_install_write_bank(space, 0x0000, 0x1fff, 0, 0, "bank1");
440439   memory_install_write_bank(space, 0x2000, 0x3fff, 0, 0, "bank2");
r9674r9675
446445   memory_install_write_bank(space, 0xf800, 0xffff, 0, 0, "bank8");
447446
448447
449   if ((orionpro_dispatcher & 0x01)==0x00)
448   if ((state->orionpro_dispatcher & 0x01)==0x00)
450449   {   // RAM0 segment disabled
451450      memory_set_bankptr(machine, "bank1", messram_get_ptr(machine->device("messram")) + 0x10000 * page);
452451      memory_set_bankptr(machine, "bank2", messram_get_ptr(machine->device("messram")) + 0x10000 * page + 0x2000);
453452   }
454453   else
455454   {
456      memory_set_bankptr(machine, "bank1", messram_get_ptr(machine->device("messram")) + (orionpro_ram0_segment & 31) * 0x4000);
457      memory_set_bankptr(machine, "bank2", messram_get_ptr(machine->device("messram")) + (orionpro_ram0_segment & 31) * 0x4000 + 0x2000);
455      memory_set_bankptr(machine, "bank1", messram_get_ptr(machine->device("messram")) + (state->orionpro_ram0_segment & 31) * 0x4000);
456      memory_set_bankptr(machine, "bank2", messram_get_ptr(machine->device("messram")) + (state->orionpro_ram0_segment & 31) * 0x4000 + 0x2000);
458457   }
459   if ((orionpro_dispatcher & 0x10)==0x10)
458   if ((state->orionpro_dispatcher & 0x10)==0x10)
460459   {   // ROM1 enabled
461460      memory_unmap_write(space, 0x0000, 0x1fff, 0, 0);
462461      memory_set_bankptr(machine, "bank1", memory_region(machine, "maincpu") + 0x20000);
463462   }
464   if ((orionpro_dispatcher & 0x08)==0x08)
463   if ((state->orionpro_dispatcher & 0x08)==0x08)
465464   {   // ROM2 enabled
466465      memory_unmap_write(space, 0x2000, 0x3fff, 0, 0);
467      memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x22000 + (orionpro_rom2_segment & 7) * 0x2000);
466      memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x22000 + (state->orionpro_rom2_segment & 7) * 0x2000);
468467   }
469468
470   if ((orionpro_dispatcher & 0x02)==0x00)
469   if ((state->orionpro_dispatcher & 0x02)==0x00)
471470   {   // RAM1 segment disabled
472471      memory_set_bankptr(machine, "bank3", messram_get_ptr(machine->device("messram")) + 0x10000 * page + 0x4000);
473472   }
474473   else
475474   {
476      memory_set_bankptr(machine, "bank3", messram_get_ptr(machine->device("messram")) + (orionpro_ram1_segment & 31) * 0x4000);
475      memory_set_bankptr(machine, "bank3", messram_get_ptr(machine->device("messram")) + (state->orionpro_ram1_segment & 31) * 0x4000);
477476   }
478477
479   if ((orionpro_dispatcher & 0x04)==0x00)
478   if ((state->orionpro_dispatcher & 0x04)==0x00)
480479   {   // RAM2 segment disabled
481480      memory_set_bankptr(machine, "bank4", messram_get_ptr(machine->device("messram")) + 0x10000 * page + 0x8000);
482481   }
483482   else
484483   {
485      memory_set_bankptr(machine, "bank4", messram_get_ptr(machine->device("messram")) + (orionpro_ram2_segment & 31) * 0x4000);
484      memory_set_bankptr(machine, "bank4", messram_get_ptr(machine->device("messram")) + (state->orionpro_ram2_segment & 31) * 0x4000);
486485   }
487486
488487   memory_set_bankptr(machine, "bank5", messram_get_ptr(machine->device("messram")) + 0x10000 * page + 0xc000);
r9674r9675
511510   }
512511   else
513512   {
514      if ((orionpro_dispatcher & 0x40)==0x40)
513      if ((state->orionpro_dispatcher & 0x40)==0x40)
515514      {   // FIX F000 enabled
516515         memory_set_bankptr(machine, "bank6", messram_get_ptr(machine->device("messram")) + 0x10000 * 0 + 0xf000);
517516         memory_set_bankptr(machine, "bank7", messram_get_ptr(machine->device("messram")) + 0x10000 * 0 + 0xf400);
r9674r9675
528527
529528static WRITE8_HANDLER ( orionpro_memory_page_w )
530529{
531   orionpro_128_page = data;
530   orion_state *state = space->machine->driver_data<orion_state>();
531   state->orionpro_128_page = data;
532532   orionpro_bank_switch(space->machine);
533533}
534534
535535MACHINE_RESET ( orionpro )
536536{
537   orion_state *state = machine->driver_data<orion_state>();
537538   radio86_init_keyboard();
538539
539   orion128_video_page = 0;
540   orion128_video_mode = 0;
541   orionpro_ram0_segment = 0;
542   orionpro_ram1_segment = 0;
543   orionpro_ram2_segment = 0;
540   state->orion128_video_page = 0;
541   state->orion128_video_mode = 0;
542   state->orionpro_ram0_segment = 0;
543   state->orionpro_ram1_segment = 0;
544   state->orionpro_ram2_segment = 0;
544545
545   orionpro_page = 0;
546   orionpro_128_page = 0;
547   orionpro_rom2_segment = 0;
546   state->orionpro_page = 0;
547   state->orionpro_128_page = 0;
548   state->orionpro_rom2_segment = 0;
548549
549   orionpro_dispatcher = 0x50;
550   state->orionpro_dispatcher = 0x50;
550551   orionpro_bank_switch(machine);
551552
552   orion_speaker = 0;
553   orion128_video_width = SCREEN_WIDTH_384;
553   state->speaker = 0;
554   state->orion128_video_width = SCREEN_WIDTH_384;
554555   orion_set_video_mode(machine,384);
555556
556   orion_video_mode_mask = 31;
557   orionpro_pseudo_color = 0;
557   state->video_mode_mask = 31;
558   state->orionpro_pseudo_color = 0;
558559}
559560
560561READ8_HANDLER ( orionpro_io_r )
561562{
563   orion_state *state = space->machine->driver_data<orion_state>();
562564   running_device *fdc = space->machine->device("wd1793");
563565
564566   switch (offset & 0xff)
565567   {
566568      case 0x00 : return 0x56;
567      case 0x04 : return orionpro_ram0_segment;
568      case 0x05 : return orionpro_ram1_segment;
569      case 0x06 : return orionpro_ram2_segment;
570      case 0x08 : return orionpro_page;
571      case 0x09 : return orionpro_rom2_segment;
572      case 0x0a : return orionpro_dispatcher;
569      case 0x04 : return state->orionpro_ram0_segment;
570      case 0x05 : return state->orionpro_ram1_segment;
571      case 0x06 : return state->orionpro_ram2_segment;
572      case 0x08 : return state->orionpro_page;
573      case 0x09 : return state->orionpro_rom2_segment;
574      case 0x0a : return state->orionpro_dispatcher;
573575      case 0x10 : return wd17xx_status_r(fdc,0);
574576      case 0x11 : return wd17xx_track_r(fdc,0);
575577      case 0x12 : return wd17xx_sector_r(fdc,0);
r9674r9675
593595
594596WRITE8_HANDLER ( orionpro_io_w )
595597{
598   orion_state *state = space->machine->driver_data<orion_state>();
596599   running_device *fdc = space->machine->device("wd1793");
597600
598601   switch (offset & 0xff)
599602   {
600      case 0x04 : orionpro_ram0_segment = data; orionpro_bank_switch(space->machine); break;
601      case 0x05 : orionpro_ram1_segment = data; orionpro_bank_switch(space->machine); break;
602      case 0x06 : orionpro_ram2_segment = data; orionpro_bank_switch(space->machine); break;
603      case 0x08 : orionpro_page = data;        orionpro_bank_switch(space->machine); break;
604      case 0x09 : orionpro_rom2_segment = data; orionpro_bank_switch(space->machine); break;
605      case 0x0a : orionpro_dispatcher = data;   orionpro_bank_switch(space->machine); break;
603      case 0x04 : state->orionpro_ram0_segment = data; orionpro_bank_switch(space->machine); break;
604      case 0x05 : state->orionpro_ram1_segment = data; orionpro_bank_switch(space->machine); break;
605      case 0x06 : state->orionpro_ram2_segment = data; orionpro_bank_switch(space->machine); break;
606      case 0x08 : state->orionpro_page = data;        orionpro_bank_switch(space->machine); break;
607      case 0x09 : state->orionpro_rom2_segment = data; orionpro_bank_switch(space->machine); break;
608      case 0x0a : state->orionpro_dispatcher = data;   orionpro_bank_switch(space->machine); break;
606609      case 0x10 : wd17xx_command_w(fdc,0,data); break;
607610      case 0x11 : wd17xx_track_w(fdc,0,data);break;
608611      case 0x12 : wd17xx_sector_w(fdc,0,data);break;
r9674r9675
618621      case 0x2a : orion128_romdisk_w(space,2,data); break;
619622      case 0x2b : orion128_romdisk_w(space,3,data); break;
620623      case 0xf8 : orion128_video_mode_w(space,0,data);break;
621      case 0xf9 : orionpro_128_page = data;     orionpro_bank_switch(space->machine); break;
624      case 0xf9 : state->orionpro_128_page = data;     orionpro_bank_switch(space->machine); break;
622625      case 0xfa : orion128_video_page_w(space,0,data);break;
623      case 0xfc : orionpro_pseudo_color = data;break;
626      case 0xfc : state->orionpro_pseudo_color = data;break;
624627      case 0xfe : orionz80_sound_fe_w(space,0,data);break;
625628      case 0xff : orionz80_sound_w(space,0,data);break;
626629   }
src/mess/machine/llc.c
r9674r9675
1212#include "includes/llc.h"
1313#include "devices/messram.h"
1414
15static UINT8 s_code = 0;
1615
17static UINT8 llc1_key_state = 0;
1816
1917static READ8_DEVICE_HANDLER (llc1_port_b_r)
2018{
19   llc_state *state = device->machine->driver_data<llc_state>();
2120   UINT8 retVal = 0;
22   if (s_code!=0) {
23      if (llc1_key_state==0) {
24         llc1_key_state = 1;
21   if (state->s_code!=0) {
22      if (state->llc1_key_state==0) {
23         state->llc1_key_state = 1;
2524         retVal = 0x5F;
2625      } else {
27         if (llc1_key_state == 1) {
28            llc1_key_state = 2;
26         if (state->llc1_key_state == 1) {
27            state->llc1_key_state = 2;
2928            retVal = 0;
3029         } else {
31            llc1_key_state = 0;
32            retVal = s_code;
33            s_code =0;
30            state->llc1_key_state = 0;
31            retVal = state->s_code;
32            state->s_code =0;
3433         }
3534      }
3635   } else {
37      llc1_key_state = 0;
36      state->llc1_key_state = 0;
3837      retVal = 0;
3938   }
4039   return retVal;
r9674r9675
6665
6766static TIMER_CALLBACK(keyboard_callback)
6867{
68   llc_state *state = machine->driver_data<llc_state>();
6969   int i,j;
7070   UINT8 c;
7171   static const char *const keynames[] = {
r9674r9675
8282         {
8383            if (c == (1 << j))
8484            {
85               s_code = j + i*8;
85               state->s_code = j + i*8;
8686               break;
8787            }
8888         }
r9674r9675
106106
107107DRIVER_INIT(llc2)
108108{
109   llc_video_ram = messram_get_ptr(machine->device("messram")) + 0xc000;
109   llc_state *state = machine->driver_data<llc_state>();
110   state->video_ram = messram_get_ptr(machine->device("messram")) + 0xc000;
110111}
111112
112113MACHINE_RESET( llc2 )
src/mess/machine/trs80.c
r9674r9675
3232#define LOG(x)   do { if (VERBOSE) logerror x; } while (0)
3333
3434
35static UINT8 trs80_irq=0;      /* interrupting devices */
36static UINT8 trs80_mask= 0;      /* interrupt mask */
37static UINT8 trs80_nmi_mask= 0;      /* nmi mask */
38static UINT8 trs80_port_ec=0;      /* bit d6..d1 of port EC to be read by port FF */
39static UINT8 trs80_tape_unit;      /* selected cassette unit (trs80l2 and sys80 only) (not implemented yet) */
40static UINT8 trs80_reg_load;      /* Controls what port EA will do */
41static UINT8 trs80_nmi_data;   /* Passes FDC int to NMI handler */
42UINT8 trs80_mode = 0;         /* Control bits passed to video output routine */
43
4435#define IRQ_M1_RTC      0x80   /* RTC on Model I */
4536#define IRQ_M1_FDC      0x40   /* FDC on Model I */
4637#define IRQ_M4_RTC      0x04   /* RTC on Model 4 */
r9674r9675
5142#define MAX_GRANULES   8      /* lumps consisted of granules.. aha */
5243#define MAX_SECTORS    5      /* and granules of sectors */
5344
54#ifdef USE_TRACK
55static UINT8 track[4] = {0, };            /* current track per drive */
56#endif
57static UINT8 head;                      /* current head per drive */
58#ifdef USE_SECTOR
59static UINT8 sector[4] = {0, };          /* current sector per drive */
60#endif
61
6245#define MODEL4_MASTER_CLOCK 20275200
6346
64static UINT8 cassette_data;
65static emu_timer *cassette_data_timer;
66static running_device *trs80_printer;
67static running_device *trs80_ay31015;
68static running_device *trs80_cass;
69static running_device *trs80_speaker;
70static running_device *trs80_fdc;
7147
7248static TIMER_CALLBACK( cassette_data_callback )
7349{
50   trs80_state *state = machine->driver_data<trs80_state>();
7451/* This does all baud rates. 250 baud (trs80), and 500 baud (all others) set bit 7 of "cassette_data".
7552    1500 baud (trs80m3, trs80m4) is interrupt-driven and uses bit 0 of "cassette_data" */
7653
77   static double old_cassette_val;
78   double new_val = cassette_input(trs80_cass);
54   double new_val = cassette_input(state->cass);
7955
8056   /* Check for HI-LO transition */
81   if ( old_cassette_val > -0.2 && new_val < -0.2 )
57   if ( state->old_cassette_val > -0.2 && new_val < -0.2 )
8258   {
83      cassette_data |= 0x80;      /* 500 baud */
84      if (trs80_mask & CASS_FALL)   /* see if 1500 baud */
59      state->cassette_data |= 0x80;      /* 500 baud */
60      if (state->mask & CASS_FALL)   /* see if 1500 baud */
8561      {
86         cassette_data = 0;
87         trs80_irq |= CASS_FALL;
62         state->cassette_data = 0;
63         state->irq |= CASS_FALL;
8864         cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
8965      }
9066   }
9167   else
92   if ( old_cassette_val < -0.2 && new_val > -0.2 )
68   if ( state->old_cassette_val < -0.2 && new_val > -0.2 )
9369   {
94      if (trs80_mask & CASS_RISE)   /* 1500 baud */
70      if (state->mask & CASS_RISE)   /* 1500 baud */
9571      {
96         cassette_data = 1;
97         trs80_irq |= CASS_RISE;
72         state->cassette_data = 1;
73         state->irq |= CASS_RISE;
9874         cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
9975      }
10076   }
10177
102   old_cassette_val = new_val;
78   state->old_cassette_val = new_val;
10379}
10480
10581
r9674r9675
11288
11389READ8_HANDLER( trs80m4_e0_r )
11490{
91   trs80_state *state = space->machine->driver_data<trs80_state>();
11592/* Indicates which devices are interrupting - d6..d3 not emulated.
11693    Whenever an interrupt occurs, this port is immediately read
11794    to find out which device requires service. Lowest-numbered
r9674r9675
127104    d0 Cass 1500 baud Rising */
128105
129106   cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE);
130   return ~(trs80_mask & trs80_irq);
107   return ~(state->mask & state->irq);
131108}
132109
133110READ8_HANDLER( trs80m4_e4_r )
134111{
112   trs80_state *state = space->machine->driver_data<trs80_state>();
135113/* Indicates which devices are interrupting - d6..d5 not emulated.
136114    Whenever an NMI occurs, this port is immediately read
137115    to find out which device requires service. Lowest-numbered
r9674r9675
144122
145123   cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE);
146124
147   return ~(trs80_nmi_mask & trs80_nmi_data);
125   return ~(state->nmi_mask & state->nmi_data);
148126}
149127
150128READ8_HANDLER( trs80m4_e8_r )
r9674r9675
162140
163141READ8_HANDLER( trs80m4_ea_r )
164142{
143   trs80_state *state = space->machine->driver_data<trs80_state>();
165144/* UART Status Register
166145    d7 Data Received ('1'=condition true)
167146    d6 Transmitter Holding Register empty ('1'=condition true)
r9674r9675
171150    d2..d0 Not used */
172151
173152   UINT8 data=7;
174   ay31015_set_input_pin( trs80_ay31015, AY31015_SWE, 0 );
175   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_TBMT ) ? 0x40 : 0;
176   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_DAV  ) ? 0x80 : 0;
177   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_OR   ) ? 0x20 : 0;
178   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_FE   ) ? 0x10 : 0;
179   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_PE   ) ? 0x08 : 0;
180   ay31015_set_input_pin( trs80_ay31015, AY31015_SWE, 1 );
153   ay31015_set_input_pin( state->ay31015, AY31015_SWE, 0 );
154   data |= ay31015_get_output_pin( state->ay31015, AY31015_TBMT ) ? 0x40 : 0;
155   data |= ay31015_get_output_pin( state->ay31015, AY31015_DAV  ) ? 0x80 : 0;
156   data |= ay31015_get_output_pin( state->ay31015, AY31015_OR   ) ? 0x20 : 0;
157   data |= ay31015_get_output_pin( state->ay31015, AY31015_FE   ) ? 0x10 : 0;
158   data |= ay31015_get_output_pin( state->ay31015, AY31015_PE   ) ? 0x08 : 0;
159   ay31015_set_input_pin( state->ay31015, AY31015_SWE, 1 );
181160
182161   return data;
183162}
184163
185164READ8_HANDLER( trs80m4_eb_r )
186165{
166   trs80_state *state = space->machine->driver_data<trs80_state>();
187167/* UART received data */
188   UINT8 data = ay31015_get_received_data( trs80_ay31015 );
189   ay31015_set_input_pin( trs80_ay31015, AY31015_RDAV, 0 );
190   ay31015_set_input_pin( trs80_ay31015, AY31015_RDAV, 1 );
168   UINT8 data = ay31015_get_received_data( state->ay31015 );
169   ay31015_set_input_pin( state->ay31015, AY31015_RDAV, 0 );
170   ay31015_set_input_pin( state->ay31015, AY31015_RDAV, 1 );
191171   return data;
192172}
193173
194174READ8_HANDLER( trs80m4_ec_r )
195175{
176   trs80_state *state = space->machine->driver_data<trs80_state>();
196177/* Reset the RTC interrupt */
197   trs80_irq &= ~IRQ_M4_RTC;
178   state->irq &= ~IRQ_M4_RTC;
198179   return 0;
199180}
200181
201182READ8_HANDLER( sys80_f9_r )
202183{
184   trs80_state *state = space->machine->driver_data<trs80_state>();
203185/* UART Status Register - d6..d4 not emulated
204186    d7 Transmit buffer empty (inverted)
205187    d6 CTS pin
r9674r9675
211193    d0 Data Available */
212194
213195   UINT8 data=70;
214   ay31015_set_input_pin( trs80_ay31015, AY31015_SWE, 0 );
215   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_TBMT ) ? 0 : 0x80;
216   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_DAV  ) ? 0x01 : 0;
217   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_OR   ) ? 0x02 : 0;
218   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_FE   ) ? 0x04 : 0;
219   data |= ay31015_get_output_pin( trs80_ay31015, AY31015_PE   ) ? 0x08 : 0;
220   ay31015_set_input_pin( trs80_ay31015, AY31015_SWE, 1 );
196   ay31015_set_input_pin( state->ay31015, AY31015_SWE, 0 );
197   data |= ay31015_get_output_pin( state->ay31015, AY31015_TBMT ) ? 0 : 0x80;
198   data |= ay31015_get_output_pin( state->ay31015, AY31015_DAV  ) ? 0x01 : 0;
199   data |= ay31015_get_output_pin( state->ay31015, AY31015_OR   ) ? 0x02 : 0;
200   data |= ay31015_get_output_pin( state->ay31015, AY31015_FE   ) ? 0x04 : 0;
201   data |= ay31015_get_output_pin( state->ay31015, AY31015_PE   ) ? 0x08 : 0;
202   ay31015_set_input_pin( state->ay31015, AY31015_SWE, 1 );
221203
222204   return data;
223205}
224206
225207READ8_HANDLER( lnw80_fe_r )
226208{
227   return ((trs80_mode & 0x78) >> 3) | 0xf0;
209   trs80_state *state = space->machine->driver_data<trs80_state>();
210   return ((state->mode & 0x78) >> 3) | 0xf0;
228211}
229212
230213READ8_HANDLER( trs80_ff_r )
231214{
215   trs80_state *state = space->machine->driver_data<trs80_state>();
232216/* ModeSel and cassette data
233217    d7 cassette data from tape
234218    d2 modesel setting */
235219
236   UINT8 data = (~trs80_mode & 1) << 5;
237   return data | cassette_data;
220   UINT8 data = (~state->mode & 1) << 5;
221   return data | state->cassette_data;
238222}
239223
240224READ8_HANDLER( trs80m4_ff_r )
241225{
226   trs80_state *state = space->machine->driver_data<trs80_state>();
242227/* Return of cassette data stream from tape
243228    d7 Low-speed data
244229    d6..d1 info from write of port EC
245230    d0 High-speed data */
246231
247   trs80_irq &= 0xfc;   /* clear cassette interrupts */
232   state->irq &= 0xfc;   /* clear cassette interrupts */
248233
249   return trs80_port_ec | cassette_data;
234   return state->port_ec | state->cassette_data;
250235}
251236
252237
253238WRITE8_HANDLER( trs80m4_84_w )
254239{
240   trs80_state *state = space->machine->driver_data<trs80_state>();
255241/* Hi-res graphics control - d6..d4 not emulated
256242    d7 Page Control
257243    d6 Fix upper memory
r9674r9675
265251   /* get address space instead of io space */
266252   address_space *mem = cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
267253
268   trs80_mode = (trs80_mode & 0x73) | (data & 0x8c);
254   state->mode = (state->mode & 0x73) | (data & 0x8c);
269255
270   trs80_model4 &= 0xce;
271   trs80_model4 |= (data & 3) << 4;
256   state->model4 &= 0xce;
257   state->model4 |= (data & 3) << 4;
272258
273259   switch (data & 3)
274260   {
275261      case 0:   /* normal operation */
276262
277         if (trs80_model4 & 4)   /* Model 4P gets RAM while Model 4 gets ROM */
263         if (state->model4 & 4)   /* Model 4P gets RAM while Model 4 gets ROM */
278264         {
279            if (trs80_model4 & 8)
265            if (state->model4 & 8)
280266               memory_set_bankptr(mem->machine, "bank1", memory_region(mem->machine, "maincpu"));
281267            else
282268               memory_set_bankptr(mem->machine, "bank1", memory_region(mem->machine, "maincpu") + 0x10000);
r9674r9675
308294
309295      case 1:   /* write-only ram backs up the rom */
310296
311         if (trs80_model4 & 4)   /* Model 4P gets RAM while Model 4 gets ROM */
297         if (state->model4 & 4)   /* Model 4P gets RAM while Model 4 gets ROM */
312298         {
313            if (trs80_model4 & 8)
299            if (state->model4 & 8)
314300               memory_set_bankptr(mem->machine, "bank1", memory_region(mem->machine, "maincpu"));
315301            else
316302               memory_set_bankptr(mem->machine, "bank1", memory_region(mem->machine, "maincpu") + 0x10000);
r9674r9675
360346         memory_set_bankptr(mem->machine, "bank18", memory_region(mem->machine, "maincpu") + 0x0a000);
361347         memory_install_read8_handler (mem, 0xf400, 0xf7ff, 0, 0, trs80_keyboard_r);   /* 8 */
362348         memory_install_readwrite8_handler (mem, 0xf800, 0xffff, 0, 0, trs80_videoram_r, trs80_videoram_w);   /* 9 & 19 */
363         trs80_model4++;
349         state->model4++;
364350         break;
365351
366352      case 3:   /* 64k of ram */
r9674r9675
388374
389375WRITE8_HANDLER( trs80m4_90_w )
390376{
391   speaker_level_w(trs80_speaker, ~data & 1);
377   trs80_state *state = space->machine->driver_data<trs80_state>();
378   speaker_level_w(state->speaker, ~data & 1);
392379}
393380
394381WRITE8_HANDLER( trs80m4p_9c_w )      /* model 4P only - swaps the ROM with read-only RAM */
395382{
396   /* Meaning of trs80_model4 variable:
383   trs80_state *state = space->machine->driver_data<trs80_state>();
384   /* Meaning of model4 variable:
397385        d5..d4 memory mode (as described in section above)
398386        d3 rom switch (1=enabled) only effective in mode0 and 1
399387        d2 this is a Model 4P
r9674r9675
403391   /* get address space instead of io space */
404392   address_space *mem = cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
405393
406   trs80_model4 &= 0xf7;
407   trs80_model4 |= (data << 3);
394   state->model4 &= 0xf7;
395   state->model4 |= (data << 3);
408396
409   if ((trs80_model4) && (~trs80_model4 & 0x20))
397   if ((state->model4) && (~state->model4 & 0x20))
410398   {
411      switch (trs80_model4 & 8)
399      switch (state->model4 & 8)
412400      {
413401         case 0:      /* Read-only RAM replaces rom */
414402            memory_set_bankptr(mem->machine, "bank1", memory_region(mem->machine, "maincpu") + 0x10000);
r9674r9675
422410
423411WRITE8_HANDLER( trs80m4_e0_w )
424412{
413   trs80_state *state = space->machine->driver_data<trs80_state>();
425414/* Interrupt settings - which devices are allowed to interrupt - bits align with read of E0
426415    d6 Enable Rec Err
427416    d5 Enable Rec Data
r9674r9675
431420    d1 C fall Int
432421    d0 C Rise Int */
433422
434   trs80_mask = data;
423   state->mask = data;
435424}
436425
437426WRITE8_HANDLER( trs80m4_e4_w )
438427{
428   trs80_state *state = space->machine->driver_data<trs80_state>();
439429/* Disk to NMI interface
440430    d7 1=enable disk INTRQ to generate NMI
441431    d6 1=enable disk Motor Timeout to generate NMI */
442432
443   trs80_nmi_mask = data;
433   state->nmi_mask = data;
444434}
445435
446436WRITE8_HANDLER( trs80m4_e8_w )
447437{
438   trs80_state *state = space->machine->driver_data<trs80_state>();
448439/* d1 when '1' enables control register load (see below) */
449440
450   trs80_reg_load = data & 2;
441   state->reg_load = data & 2;
451442}
452443
453444WRITE8_HANDLER( trs80m4_e9_w )
454445{
446   trs80_state *state = space->machine->driver_data<trs80_state>();
455447/* UART set baud rate. Rx = bits 0..3, Tx = bits 4..7
456448    00h    50
457449    11h    75
r9674r9675
471463    FFh    19200 */
472464
473465   int baud_clock[]={ 800, 1200, 1760, 2152, 2400, 4800, 9600, 19200, 28800, 32000, 38400, 57600, 76800, 115200, 153600, 307200 };
474   ay31015_set_receiver_clock( trs80_ay31015, baud_clock[data & 0x0f]);
475   ay31015_set_transmitter_clock( trs80_ay31015, baud_clock[data>>4]);
466   ay31015_set_receiver_clock( state->ay31015, baud_clock[data & 0x0f]);
467   ay31015_set_transmitter_clock( state->ay31015, baud_clock[data>>4]);
476468}
477469
478470WRITE8_HANDLER( trs80m4_ea_w )
479471{
480   if (trs80_reg_load)
472   trs80_state *state = space->machine->driver_data<trs80_state>();
473   if (state->reg_load)
481474
482475/* d2..d0 not emulated
483476    d7 Even Parity Enable ('1'=even, '0'=odd)
r9674r9675
492485    d0 Data-Terminal-Ready (DTR), pin 20 */
493486
494487   {
495      ay31015_set_input_pin( trs80_ay31015, AY31015_CS, 0 );
496      ay31015_set_input_pin( trs80_ay31015, AY31015_NB1, ( data & 0x40 ) ? 1 : 0 );
497      ay31015_set_input_pin( trs80_ay31015, AY31015_NB2, ( data & 0x20 ) ? 1 : 0 );
498      ay31015_set_input_pin( trs80_ay31015, AY31015_TSB, ( data & 0x10 ) ? 1 : 0 );
499      ay31015_set_input_pin( trs80_ay31015, AY31015_EPS, ( data & 0x80 ) ? 1 : 0 );
500      ay31015_set_input_pin( trs80_ay31015, AY31015_NP,  ( data & 0x08 ) ? 1 : 0 );
501      ay31015_set_input_pin( trs80_ay31015, AY31015_CS, 1 );
488      ay31015_set_input_pin( state->ay31015, AY31015_CS, 0 );
489      ay31015_set_input_pin( state->ay31015, AY31015_NB1, ( data & 0x40 ) ? 1 : 0 );
490      ay31015_set_input_pin( state->ay31015, AY31015_NB2, ( data & 0x20 ) ? 1 : 0 );
491      ay31015_set_input_pin( state->ay31015, AY31015_TSB, ( data & 0x10 ) ? 1 : 0 );
492      ay31015_set_input_pin( state->ay31015, AY31015_EPS, ( data & 0x80 ) ? 1 : 0 );
493      ay31015_set_input_pin( state->ay31015, AY31015_NP,  ( data & 0x08 ) ? 1 : 0 );
494      ay31015_set_input_pin( state->ay31015, AY31015_CS, 1 );
502495   }
503496   else
504497   {
r9674r9675
517510
518511WRITE8_HANDLER( trs80m4_eb_w )
519512{
520   ay31015_set_transmit_data( trs80_ay31015, data );
513   trs80_state *state = space->machine->driver_data<trs80_state>();
514   ay31015_set_transmit_data( state->ay31015, data );
521515}
522516
523517WRITE8_HANDLER( trs80m4_ec_w )
524518{
519   trs80_state *state = space->machine->driver_data<trs80_state>();
525520/* Hardware settings - d5..d4 not emulated
526521    d6 CPU fast (1=4MHz, 0=2MHz)
527522    d5 1=Enable Video Wait
r9674r9675
532527
533528   cputag_set_clock(space->machine, "maincpu", data & 0x40 ? MODEL4_MASTER_CLOCK/5 : MODEL4_MASTER_CLOCK/10);
534529
535   trs80_mode = (trs80_mode & 0xde) | ((data & 4) ? 1 : 0) | ((data & 8) ? 0x20 : 0);
530   state->mode = (state->mode & 0xde) | ((data & 4) ? 1 : 0) | ((data & 8) ? 0x20 : 0);
536531
537   cassette_change_state( trs80_cass, ( data & 2 ) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR );
532   cassette_change_state( state->cass, ( data & 2 ) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR );
538533
539   trs80_port_ec = data & 0x7e;
534   state->port_ec = data & 0x7e;
540535}
541536
542537WRITE8_HANDLER( trs80m4_f4_w )
543538{
539   trs80_state *state = space->machine->driver_data<trs80_state>();
544540/* Selection of drive and parameters - d6..d5 not emulated.
545541 A write also causes the selected drive motor to turn on for about 3 seconds.
546542 When the motor turns off, the drive is deselected.
r9674r9675
567563   if (data & 8)
568564      drive = 3;
569565
570   head = (data & 16) ? 1 : 0;
566   state->head = (data & 16) ? 1 : 0;
571567
572568   if (drive < 4)
573569   {
574      wd17xx_set_drive(trs80_fdc,drive);
575      wd17xx_set_side(trs80_fdc,head);
570      wd17xx_set_drive(state->fdc,drive);
571      wd17xx_set_side(state->fdc,state->head);
576572   }
577573
578   wd17xx_dden_w(trs80_fdc, !BIT(data, 7));
574   wd17xx_dden_w(state->fdc, !BIT(data, 7));
579575
580576   /* CLEAR_LINE means to turn motors on */
581577   floppy_mon_w(floppy_get_device(space->machine, 0), (data & 0x0f) ? CLEAR_LINE : ASSERT_LINE);
r9674r9675
594590
595591WRITE8_HANDLER( sys80_fe_w )
596592{
593   trs80_state *state = space->machine->driver_data<trs80_state>();
597594/* not emulated
598595    d4 select internal or external cassette player */
599596
600   trs80_tape_unit = (data & 0x10) ? 2 : 1;
597   state->tape_unit = (data & 0x10) ? 2 : 1;
601598}
602599
603600/* lnw80 can switch out all the devices, roms and video ram to be replaced by graphics ram. */
604601WRITE8_HANDLER( lnw80_fe_w )
605602{
603   trs80_state *state = space->machine->driver_data<trs80_state>();
606604/* lnw80 video options
607605    d3 bankswitch lower 16k between roms and hires ram (1=hires)
608606    d2 enable colour    \
r9674r9675
612610   /* get address space instead of io space */
613611   address_space *mem = cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
614612
615   trs80_mode = (trs80_mode & 0x87) | ((data & 0x0f) << 3);
613   state->mode = (state->mode & 0x87) | ((data & 0x0f) << 3);
616614
617615   if (data & 8)
618616   {
r9674r9675
626624      memory_set_bankptr(mem->machine, "bank1", memory_region(mem->machine, "maincpu"));
627625      memory_install_readwrite8_handler (mem, 0x37e0, 0x37e3, 0, 0, trs80_irq_status_r, trs80_motor_w);
628626      memory_install_readwrite8_handler (mem, 0x37e8, 0x37eb, 0, 0, trs80_printer_r, trs80_printer_w);
629      memory_install_readwrite8_device_handler (mem, trs80_fdc, 0x37ec, 0x37ec, 0, 0, trs80_wd179x_r, wd17xx_command_w);
630      memory_install_readwrite8_device_handler (mem, trs80_fdc, 0x37ed, 0x37ed, 0, 0, wd17xx_track_r, wd17xx_track_w);
631      memory_install_readwrite8_device_handler (mem, trs80_fdc, 0x37ee, 0x37ee, 0, 0, wd17xx_sector_r, wd17xx_sector_w);
632      memory_install_readwrite8_device_handler (mem, trs80_fdc, 0x37ef, 0x37ef, 0, 0, wd17xx_data_r, wd17xx_data_w);
627      memory_install_readwrite8_device_handler (mem, state->fdc, 0x37ec, 0x37ec, 0, 0, trs80_wd179x_r, wd17xx_command_w);
628      memory_install_readwrite8_device_handler (mem, state->fdc, 0x37ed, 0x37ed, 0, 0, wd17xx_track_r, wd17xx_track_w);
629      memory_install_readwrite8_device_handler (mem, state->fdc, 0x37ee, 0x37ee, 0, 0, wd17xx_sector_r, wd17xx_sector_w);
630      memory_install_readwrite8_device_handler (mem, state->fdc, 0x37ef, 0x37ef, 0, 0, wd17xx_data_r, wd17xx_data_w);
633631      memory_install_read8_handler (mem, 0x3800, 0x38ff, 0, 0x0300, trs80_keyboard_r);
634632      memory_install_readwrite8_handler (mem, 0x3c00, 0x3fff, 0, 0, trs80_videoram_r, trs80_videoram_w);
635633   }
r9674r9675
637635
638636WRITE8_HANDLER( trs80_ff_w )
639637{
638   trs80_state *state = space->machine->driver_data<trs80_state>();
640639/* Standard output port of Model I
641640    d3 ModeSel bit
642641    d2 Relay
r9674r9675
644643
645644   static const double levels[4] = { 0.0, -1.0, 0.0, 1.0 };
646645
647   cassette_change_state( trs80_cass, ( data & 4 ) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR );
648   cassette_output( trs80_cass, levels[data & 3]);
649   cassette_data &= ~0x80;
646   cassette_change_state( state->cass, ( data & 4 ) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR );
647   cassette_output( state->cass, levels[data & 3]);
648   state->cassette_data &= ~0x80;
650649
651   trs80_mode = (trs80_mode & 0xfe) | ((data & 8) >> 3);
650   state->mode = (state->mode & 0xfe) | ((data & 8) >> 3);
652651
653652   /* Speaker for System-80 MK II - only sounds if relay is off */
654653   if (~data & 4)
655      speaker_level_w(trs80_speaker, data & 3);
654      speaker_level_w(state->speaker, data & 3);
656655}
657656
658657WRITE8_HANDLER( trs80m4_ff_w )
659658{
659   trs80_state *state = space->machine->driver_data<trs80_state>();
660660/* Cassette port
661661    d1, d0 Cassette output */
662662
663663   static const double levels[4] = { 0.0, -1.0, 0.0, 1.0 };
664   cassette_output( trs80_cass, levels[data & 3]);
665   cassette_data &= ~0x80;
664   cassette_output( state->cass, levels[data & 3]);
665   state->cassette_data &= ~0x80;
666666}
667667
668668
r9674r9675
674674
675675INTERRUPT_GEN( trs80_rtc_interrupt )
676676{
677   trs80_state *state = device->machine->driver_data<trs80_state>();
677678/* This enables the processing of interrupts for the clock and the flashing cursor.
678679    The OS counts one tick for each interrupt. The Model I has 40 ticks per
679680    second, while the Model III/4 has 30. */
680681
681   if (trs80_model4)   // Model 4
682   if (state->model4)   // Model 4
682683   {
683      if (trs80_mask & IRQ_M4_RTC)
684      if (state->mask & IRQ_M4_RTC)
684685      {
685         trs80_irq |= IRQ_M4_RTC;
686         state->irq |= IRQ_M4_RTC;
686687         cpu_set_input_line(device, 0, HOLD_LINE);
687688      }
688689   }
689690   else      // Model 1
690691   {
691      trs80_irq |= IRQ_M1_RTC;
692      state->irq |= IRQ_M1_RTC;
692693      cpu_set_input_line(device, 0, HOLD_LINE);
693694   }
694695}
695696
696697static void trs80_fdc_interrupt_internal(running_machine *machine)
697698{
698   if (trs80_model4)
699   trs80_state *state = machine->driver_data<trs80_state>();
700   if (state->model4)
699701   {
700      if (trs80_nmi_mask & 0x80)   // Model 4 does a NMI
702      if (state->nmi_mask & 0x80)   // Model 4 does a NMI
701703      {
702         trs80_nmi_data = 0x80;
704         state->nmi_data = 0x80;
703705         cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
704706      }
705707   }
706708   else      // Model 1 does a IRQ
707709   {
708      trs80_irq |= IRQ_M1_FDC;
710      state->irq |= IRQ_M1_FDC;
709711      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
710712   }
711713}
r9674r9675
717719
718720static WRITE_LINE_DEVICE_HANDLER( trs80_fdc_intrq_w )
719721{
722   trs80_state *drvstate = device->machine->driver_data<trs80_state>();
720723   if (state)
721724   {
722725      trs80_fdc_interrupt_internal(device->machine);
723726   }
724727   else
725728   {
726      if (trs80_model4)
727         trs80_nmi_data = 0;
729      if (drvstate->model4)
730         drvstate->nmi_data = 0;
728731      else
729         trs80_irq &= ~IRQ_M1_FDC;
732         drvstate->irq &= ~IRQ_M1_FDC;
730733   }
731734}
732735
r9674r9675
755758
756759READ8_HANDLER ( trs80_printer_r )
757760{
761   trs80_state *state = space->machine->driver_data<trs80_state>();
758762   /* Bit 7 - 1 = Busy; 0 = Not Busy
759763       Bit 6 - 1 = Out of Paper; 0 = Paper
760764       Bit 5 - 1 = Printer selected; 0 = Printer not selected
r9674r9675
762766       Bits 3..0 - Not used */
763767
764768   UINT8 data = 0;
765   data |= centronics_busy_r(trs80_printer) << 7;
766   data |= centronics_pe_r(trs80_printer) << 6;
767   data |= centronics_vcc_r(trs80_printer) << 5;
768   data |= centronics_fault_r(trs80_printer) << 4;
769   data |= centronics_busy_r(state->printer) << 7;
770   data |= centronics_pe_r(state->printer) << 6;
771   data |= centronics_vcc_r(state->printer) << 5;
772   data |= centronics_fault_r(state->printer) << 4;
769773
770774   return data;
771775}
772776
773777WRITE8_HANDLER( trs80_printer_w )
774778{
775   centronics_strobe_w(trs80_printer, 1);
776   centronics_data_w(trs80_printer, 0, data);
777   centronics_strobe_w(trs80_printer, 0);
779   trs80_state *state = space->machine->driver_data<trs80_state>();
780   centronics_strobe_w(state->printer, 1);
781   centronics_data_w(state->printer, 0, data);
782   centronics_strobe_w(state->printer, 0);
778783}
779784
780785WRITE8_HANDLER( trs80_cassunit_w )
781786{
787   trs80_state *state = space->machine->driver_data<trs80_state>();
782788/* not emulated
783789    01 for unit 1 (default
784790    02 for unit 2 */
785791
786   trs80_tape_unit = data;
792   state->tape_unit = data;
787793}
788794
789795READ8_HANDLER( trs80_irq_status_r )
790796{
797   trs80_state *state = space->machine->driver_data<trs80_state>();
791798/* (trs80l2) Whenever an interrupt occurs, 37E0 is read to see what devices require service.
792799    d7 = RTC
793800    d6 = FDC
r9674r9675
795802    All interrupting devices are serviced in a single interrupt. There is a mask byte,
796803    which is dealt with by the DOS. We take the opportunity to reset the cpu INT line. */
797804
798   int result = trs80_irq;
805   int result = state->irq;
799806   cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE);
800   trs80_irq = 0;
807   state->irq = 0;
801808   return result;
802809}
803810
804811
805812WRITE8_HANDLER( trs80_motor_w )
806813{
814   trs80_state *state = space->machine->driver_data<trs80_state>();
807815   UINT8 drive = 255;
808816
809817   LOG(("trs80 motor_w $%02X\n", data));
r9674r9675
812820   {
813821   case 1:
814822      drive = 0;
815      head = 0;
823      state->head = 0;
816824      break;
817825   case 2:
818826      drive = 1;
819      head = 0;
827      state->head = 0;
820828      break;
821829   case 4:
822830      drive = 2;
823      head = 0;
831      state->head = 0;
824832      break;
825833   case 8:
826834      drive = 3;
827      head = 0;
835      state->head = 0;
828836      break;
829837   /* These 3 combinations aren't official. Some manufacturers of double-sided disks
830838        used drive select 4 to indicate the other side. */
831839   case 9:
832840      drive = 0;
833      head = 1;
841      state->head = 1;
834842      break;
835843   case 10:
836844      drive = 1;
837      head = 1;
845      state->head = 1;
838846      break;
839847   case 12:
840848      drive = 2;
841      head = 1;
849      state->head = 1;
842850      break;
843851   }
844852
r9674r9675
851859      return;
852860   }
853861
854   wd17xx_set_drive(trs80_fdc,drive);
855   wd17xx_set_side(trs80_fdc,head);
862   wd17xx_set_drive(state->fdc,drive);
863   wd17xx_set_side(state->fdc,state->head);
856864
857865   /* Turn motors on */
858866   floppy_mon_w(floppy_get_device(space->machine, 0), CLEAR_LINE);
r9674r9675
895903
896904MACHINE_START( trs80 )
897905{
898   trs80_tape_unit=1;
899   trs80_reg_load=1;
900   trs80_nmi_data=0xff;
906   trs80_state *state = machine->driver_data<trs80_state>();
907   state->tape_unit=1;
908   state->reg_load=1;
909   state->nmi_data=0xff;
901910
902   cassette_data_timer = timer_alloc(machine,  cassette_data_callback, NULL );
903   timer_adjust_periodic( cassette_data_timer, attotime_zero, 0, ATTOTIME_IN_HZ(11025) );
904   trs80_printer = machine->device("centronics");
905   trs80_ay31015 = machine->device("tr1602");
906   trs80_cass = machine->device("cassette");
907   trs80_speaker = machine->device("speaker");
908   trs80_fdc = machine->device("wd179x");
911   state->cassette_data_timer = timer_alloc(machine,  cassette_data_callback, NULL );
912   timer_adjust_periodic( state->cassette_data_timer, attotime_zero, 0, ATTOTIME_IN_HZ(11025) );
913   state->printer = machine->device("centronics");
914   state->ay31015 = machine->device("tr1602");
915   state->cass = machine->device("cassette");
916   state->speaker = machine->device("speaker");
917   state->fdc = machine->device("wd179x");
909918}
910919
911920MACHINE_RESET( trs80 )
912921{
913   cassette_data = 0;
922   trs80_state *state = machine->driver_data<trs80_state>();
923   state->cassette_data = 0;
914924}
915925
916926MACHINE_RESET( trs80m4 )
917927{
928   trs80_state *state = machine->driver_data<trs80_state>();
918929   address_space *mem = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
919   cassette_data = 0;
930   state->cassette_data = 0;
920931
921932   memory_install_read_bank (mem, 0x0000, 0x0fff, 0, 0, "bank1");
922933   memory_install_read_bank (mem, 0x1000, 0x37e7, 0, 0, "bank2");
r9674r9675
943954
944955MACHINE_RESET( lnw80 )
945956{
957   trs80_state *state = machine->driver_data<trs80_state>();
946958   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
947   cassette_data = 0;
948   trs80_reg_load = 1;
959   state->cassette_data = 0;
960   state->reg_load = 1;
949961   lnw80_fe_w(space, 0, 0);
950962}
951963
src/mess/machine/ondra.c
r9674r9675
1919   return machine->device("cassette");
2020}
2121
22static UINT8 ondra_bank1_status;
23static UINT8 ondra_bank2_status;
2422
2523static READ8_HANDLER( ondra_keyboard_r )
2624{
r9674r9675
4139
4240static void ondra_update_banks(running_machine *machine)
4341{
42   ondra_state *state = machine->driver_data<ondra_state>();
4443   UINT8 *mem = memory_region(machine, "maincpu");
45   if (ondra_bank1_status==0) {
44   if (state->bank1_status==0) {
4645      memory_unmap_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0000, 0x3fff, 0, 0);
4746      memory_set_bankptr(machine, "bank1", mem + 0x010000);
4847   } else {
r9674r9675
5049      memory_set_bankptr(machine, "bank1", messram_get_ptr(machine->device("messram")) + 0x0000);
5150   }
5251   memory_set_bankptr(machine, "bank2", messram_get_ptr(machine->device("messram")) + 0x4000);
53   if (ondra_bank2_status==0) {
52   if (state->bank2_status==0) {
5453      memory_install_readwrite_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xe000, 0xffff, 0, 0, "bank3");
5554      memory_set_bankptr(machine, "bank3", messram_get_ptr(machine->device("messram")) + 0xe000);
5655   } else {
r9674r9675
6160
6261WRITE8_HANDLER( ondra_port_03_w )
6362{
64   ondra_video_enable = data & 1;
65   ondra_bank1_status = (data >> 1) & 1;
66   ondra_bank2_status = (data >> 2) & 1;
63   ondra_state *state = space->machine->driver_data<ondra_state>();
64   state->video_enable = data & 1;
65   state->bank1_status = (data >> 1) & 1;
66   state->bank2_status = (data >> 2) & 1;
6767   ondra_update_banks(space->machine);
6868   cassette_output(cassette_device_image(space->machine), ((data >> 3) & 1) ? -1.0 : +1.0);
6969}
r9674r9675
8686
8787MACHINE_RESET( ondra )
8888{
89   ondra_bank1_status = 0;
90   ondra_bank2_status = 0;
89   ondra_state *state = machine->driver_data<ondra_state>();
90   state->bank1_status = 0;
91   state->bank2_status = 0;
9192   ondra_update_banks(machine);
9293}
9394
src/mess/machine/mikro80.c
r9674r9675
1313#include "machine/i8255a.h"
1414#include "includes/mikro80.h"
1515
16static int mikro80_keyboard_mask;
17static int mikro80_key_mask;
1816/* Driver initialization */
1917DRIVER_INIT(mikro80)
2018{
19   mikro80_state *state = machine->driver_data<mikro80_state>();
2120   /* set initialy ROM to be visible on first bank */
2221   UINT8 *RAM = memory_region(machine, "maincpu");
2322   memset(RAM,0x0000,0x0800); // make frist page empty by default
2423   memory_configure_bank(machine, "bank1", 1, 2, RAM, 0x0000);
2524   memory_configure_bank(machine, "bank1", 0, 2, RAM, 0xf800);
26   mikro80_key_mask = 0x7f;
25   state->key_mask = 0x7f;
2726}
2827
2928DRIVER_INIT(radio99)
3029{
30   mikro80_state *state = machine->driver_data<mikro80_state>();
3131   DRIVER_INIT_CALL(mikro80);
32   mikro80_key_mask = 0xff;
32   state->key_mask = 0xff;
3333}
3434
3535READ8_HANDLER (mikro80_8255_portb_r )
3636{
37   mikro80_state *state = space->machine->driver_data<mikro80_state>();
3738   UINT8 key = 0xff;
38   if ((mikro80_keyboard_mask & 0x01)!=0) { key &= input_port_read(space->machine,"LINE0"); }
39   if ((mikro80_keyboard_mask & 0x02)!=0) { key &= input_port_read(space->machine,"LINE1"); }
40   if ((mikro80_keyboard_mask & 0x04)!=0) { key &= input_port_read(space->machine,"LINE2"); }
41   if ((mikro80_keyboard_mask & 0x08)!=0) { key &= input_port_read(space->machine,"LINE3"); }
42   if ((mikro80_keyboard_mask & 0x10)!=0) { key &= input_port_read(space->machine,"LINE4"); }
43   if ((mikro80_keyboard_mask & 0x20)!=0) { key &= input_port_read(space->machine,"LINE5"); }
44   if ((mikro80_keyboard_mask & 0x40)!=0) { key &= input_port_read(space->machine,"LINE6"); }
45   if ((mikro80_keyboard_mask & 0x80)!=0) { key &= input_port_read(space->machine,"LINE7"); }
46   return key & mikro80_key_mask;
39   if ((state->keyboard_mask & 0x01)!=0) { key &= input_port_read(space->machine,"LINE0"); }
40   if ((state->keyboard_mask & 0x02)!=0) { key &= input_port_read(space->machine,"LINE1"); }
41   if ((state->keyboard_mask & 0x04)!=0) { key &= input_port_read(space->machine,"LINE2"); }
42   if ((state->keyboard_mask & 0x08)!=0) { key &= input_port_read(space->machine,"LINE3"); }
43   if ((state->keyboard_mask & 0x10)!=0) { key &= input_port_read(space->machine,"LINE4"); }
44   if ((state->keyboard_mask & 0x20)!=0) { key &= input_port_read(space->machine,"LINE5"); }
45   if ((state->keyboard_mask & 0x40)!=0) { key &= input_port_read(space->machine,"LINE6"); }
46   if ((state->keyboard_mask & 0x80)!=0) { key &= input_port_read(space->machine,"LINE7"); }
47   return key & state->key_mask;
4748}
4849
4950READ8_HANDLER (mikro80_8255_portc_r )
r9674r9675
5354
5455WRITE8_HANDLER (mikro80_8255_porta_w )
5556{
56   mikro80_keyboard_mask = data ^ 0xff;
57   mikro80_state *state = space->machine->driver_data<mikro80_state>();
58   state->keyboard_mask = data ^ 0xff;
5759}
5860
5961WRITE8_HANDLER (mikro80_8255_portc_w )
r9674r9675
8284
8385MACHINE_RESET( mikro80 )
8486{
87   mikro80_state *state = machine->driver_data<mikro80_state>();
8588   timer_set(machine, ATTOTIME_IN_USEC(10), NULL, 0, mikro80_reset);
8689   memory_set_bank(machine, "bank1", 1);
87   mikro80_keyboard_mask = 0;
90   state->keyboard_mask = 0;
8891}
8992
9093
src/mess/machine/mz80.c
r9674r9675
1414#include "includes/mz80.h"
1515
1616UINT8 mz80k_tempo_strobe = 0;
17static UINT8 mz80k_8255_portc = 0;
1817UINT8 mz80k_vertical = 0;
1918UINT8 mz80k_cursor_cnt = 0;
20static UINT8 mz80k_keyboard_line = 0;
2119
2220
2321/* Driver initialization */
r9674r9675
2725
2826MACHINE_RESET( mz80k )
2927{
30   mz80k_tempo_strobe = 0;
31   mz80k_8255_portc = 0;
32   mz80k_vertical = 0;
33   mz80k_cursor_cnt = 0;
34   mz80k_keyboard_line = 0;
28   mz80_state *state = machine->driver_data<mz80_state>();
29   state->mz80k_tempo_strobe = 0;
30   state->mz80k_8255_portc = 0;
31   state->mz80k_vertical = 0;
32   state->mz80k_cursor_cnt = 0;
33   state->mz80k_keyboard_line = 0;
3534}
3635
3736
3837static READ8_DEVICE_HANDLER(mz80k_8255_portb_r)
3938{
39   mz80_state *state = device->machine->driver_data<mz80_state>();
4040   static const char *const keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", "LINE5", "LINE6", "LINE7", "LINE8", "LINE9" };
41   if (mz80k_keyboard_line > 9) {
41   if (state->mz80k_keyboard_line > 9) {
4242      return 0xff;
4343   } else {
44      return input_port_read(device->machine, keynames[mz80k_keyboard_line]);
44      return input_port_read(device->machine, keynames[state->mz80k_keyboard_line]);
4545   }
4646}
4747
4848static READ8_DEVICE_HANDLER(mz80k_8255_portc_r)
4949{
50   mz80_state *state = device->machine->driver_data<mz80_state>();
5051   UINT8 val = 0;
51   val |= mz80k_vertical ? 0x80 : 0x00;
52   val |= (mz80k_cursor_cnt > 31) ? 0x40 : 0x00;
52   val |= state->mz80k_vertical ? 0x80 : 0x00;
53   val |= (state->mz80k_cursor_cnt > 31) ? 0x40 : 0x00;
5354    val |= (cassette_get_state(device->machine->device("cassette")) & CASSETTE_MASK_UISTATE)== CASSETTE_PLAY ? 0x10 : 0x00;
5455
5556    if (cassette_input(device->machine->device("cassette")) > 0.00)
r9674r9675
6061
6162static WRITE8_DEVICE_HANDLER(mz80k_8255_porta_w)
6263{
63   mz80k_keyboard_line = data & 0x0f;
64   mz80_state *state = device->machine->driver_data<mz80_state>();
65   state->mz80k_keyboard_line = data & 0x0f;
6466}
6567
6668static WRITE8_DEVICE_HANDLER(mz80k_8255_portc_w)
r9674r9675
6870//  logerror("mz80k_8255_portc_w %02x\n",data);
6971}
7072
71static UINT8 speaker_level = 0;
72static UINT8 prev_state = 0;
7373
7474static WRITE_LINE_DEVICE_HANDLER( pit_out0_changed )
7575{
76   mz80_state *drvstate = device->machine->driver_data<mz80_state>();
7677   running_device *speaker = device->machine->device("speaker");
77   if((prev_state==0) && (state==1)) {
78      speaker_level ^= 1;
78   if((drvstate->prev_state==0) && (state==1)) {
79      drvstate->speaker_level ^= 1;
7980   }
80   prev_state = state;
81   speaker_level_w( speaker, speaker_level);
81   drvstate->prev_state = state;
82   speaker_level_w( speaker, drvstate->speaker_level);
8283}
8384
8485static WRITE_LINE_DEVICE_HANDLER( pit_out2_changed )
r9674r9675
108109
109110READ8_HANDLER(mz80k_strobe_r)
110111{
111   return(0x7e | mz80k_tempo_strobe);
112   mz80_state *state = space->machine->driver_data<mz80_state>();
113   return(0x7e | state->mz80k_tempo_strobe);
112114}
113115WRITE8_HANDLER(mz80k_strobe_w)
114116{
src/mess/video/mc80.c
r9674r9675
9191/*                            Implementation for MC80.2x                     */
9292/*****************************************************************************/
9393
94UINT8* mc8020_video_ram;
9594
9695
9796VIDEO_START( mc8020 )
r9674r9675
10099
101100VIDEO_UPDATE( mc8020 )
102101{
102   mc80_state *state = screen->machine->driver_data<mc80_state>();
103103   int x,y,j,b;
104104   UINT16 addr;
105105   int xpos;
r9674r9675
110110      xpos = 0;
111111      for(x = 0; x < 32; x++ )
112112      {
113         UINT8 code = mc8020_video_ram[addr + x] & 0x3f;
113         UINT8 code = state->mc8020_video_ram[addr + x] & 0x3f;
114114         for(j = 0; j < 8; j++ )
115115         {
116116           for(b = 0; b < 6; b++ )
r9674r9675
128128/*                            Implementation for MC80.3x                     */
129129/*****************************************************************************/
130130
131UINT8 *mc8030_video_mem;
132131
133132VIDEO_START( mc8030 )
134133{
135   mc8030_video_mem = auto_alloc_array_clear(machine, UINT8, 16*1024);
134   mc80_state *state = machine->driver_data<mc80_state>();
135   state->mc8030_video_mem = auto_alloc_array_clear(machine, UINT8, 16*1024);
136136}
137137
138138VIDEO_UPDATE( mc8030 )
139139{
140   mc80_state *state = screen->machine->driver_data<mc80_state>();
140141   UINT8 code;
141142   int y, x, b;
142143
r9674r9675
146147      int horpos = 0;
147148      for (x = 0; x < 64; x++)
148149      {
149         code = mc8030_video_mem[addr++];
150         code = state->mc8030_video_mem[addr++];
150151         for (b = 0; b < 8; b++)
151152         {
152153            *BITMAP_ADDR16(bitmap, 255-y, horpos++) =  (code >> b) & 0x01;
src/mess/video/mbee.c
r9674r9675
2828#include "emu.h"
2929#include "includes/mbee.h"
3030
31static UINT8 framecnt = 0;
32static UINT8 *gfxram;
33static UINT8 *colorram;
34static UINT8 *videoram;
35static UINT8 *attribram;
36static UINT8 mbee_08;
37static UINT8 mbee_0b;
38static UINT8 mbee_1c;
39static UINT8 is_premium;
40static UINT8 sy6545_cursor[16];
41static UINT8 sy6545_status = 0;
42static void sy6545_cursor_configure(void);
43static running_device *mc6845;
44static UINT8 speed,flash;
45static UINT16 cursor;
46static UINT8 sy6545_reg[32];            /* registers */
47static UINT8 sy6545_ind;            /* register index */
31static void sy6545_cursor_configure(mbee_state *state);
4832static const UINT8 sy6545_mask[32]={0xff,0xff,0xff,0x0f,0x7f,0x1f,0x7f,0x7f,3,0x1f,0x7f,0x1f,0x3f,0xff,0x3f,0xff,0,0,0x3f,0xff};
4933
5034
r9674r9675
5741
5842READ8_HANDLER( mbee_low_r )
5943{
60   if (mbee_0b & 1)
61      return gfxram[offset];
44   mbee_state *state = space->machine->driver_data<mbee_state>();
45   if (state->_0b & 1)
46      return state->gfxram[offset];
6247   else
63      return videoram[offset];
48      return state->videoram[offset];
6449}
6550
6651WRITE8_HANDLER( mbee_low_w )
6752{
68   videoram[offset] = data;
53   mbee_state *state = space->machine->driver_data<mbee_state>();
54   state->videoram[offset] = data;
6955}
7056
7157READ8_HANDLER( mbee_high_r )
7258{
73   return gfxram[0x800 | offset];
59   mbee_state *state = space->machine->driver_data<mbee_state>();
60   return state->gfxram[0x800 | offset];
7461}
7562
7663WRITE8_HANDLER( mbee_high_w )
7764{
78   gfxram[0x800 | offset] = data;
65   mbee_state *state = space->machine->driver_data<mbee_state>();
66   state->gfxram[0x800 | offset] = data;
7967}
8068
8169READ8_HANDLER ( mbee_0b_r )
8270{
83   return mbee_0b;
71   mbee_state *state = space->machine->driver_data<mbee_state>();
72   return state->_0b;
8473}
8574
8675WRITE8_HANDLER ( mbee_0b_w )
8776{
88   mbee_0b = data;
77   mbee_state *state = space->machine->driver_data<mbee_state>();
78   state->_0b = data;
8979}
9080
9181READ8_HANDLER ( mbeeic_08_r )
9282{
93   return mbee_08;
83   mbee_state *state = space->machine->driver_data<mbee_state>();
84   return state->_08;
9485}
9586
9687WRITE8_HANDLER ( mbeeic_08_w )
9788{
98   mbee_08 = data;
89   mbee_state *state = space->machine->driver_data<mbee_state>();
90   state->_08 = data;
9991}
10092
10193READ8_HANDLER( mbeeic_high_r )
10294{
103   if (mbee_08 & 0x40)
104      return colorram[offset];
95   mbee_state *state = space->machine->driver_data<mbee_state>();
96   if (state->_08 & 0x40)
97      return state->colorram[offset];
10598   else
106      return gfxram[0x800 | offset];
99      return state->gfxram[0x800 | offset];
107100}
108101
109102WRITE8_HANDLER ( mbeeic_high_w )
110103{
111   if ((mbee_08 & 0x40) && (~mbee_0b & 1))
112      colorram[offset] = data;
104   mbee_state *state = space->machine->driver_data<mbee_state>();
105   if ((state->_08 & 0x40) && (~state->_0b & 1))
106      state->colorram[offset] = data;
113107   else
114      gfxram[0x0800 | offset] = data;
108      state->gfxram[0x0800 | offset] = data;
115109}
116110
117111READ8_HANDLER ( mbeeppc_1c_r )
118112{
119   return mbee_1c;
113   mbee_state *state = space->machine->driver_data<mbee_state>();
114   return state->_1c;
120115}
121116
122117WRITE8_HANDLER( mbeeppc_1c_w )
123118{
119   mbee_state *state = space->machine->driver_data<mbee_state>();
124120/*  d7 extended graphics (1=allow attributes and pcg banks)
125121    d5 bankswitch basic rom
126122    d4 select attribute ram
127    d3..d0 select videoram bank */
123    d3..d0 select state->videoram bank */
128124
129   mbee_1c = data;
125   state->_1c = data;
130126   memory_set_bank(space->machine, "basic", (data & 0x20) ? 1 : 0);
131127}
132128
133129WRITE8_HANDLER( mbee256_1c_w )
134130{
131   mbee_state *state = space->machine->driver_data<mbee_state>();
135132/*  d7 extended graphics (1=allow attributes and pcg banks)
136133    d5 bankswitch basic rom
137134    d4 select attribute ram
138    d3..d0 select videoram bank */
135    d3..d0 select state->videoram bank */
139136
140   mbee_1c = data;
137   state->_1c = data;
141138}
142139
143140READ8_HANDLER( mbeeppc_low_r )
144141{
145   if ((mbee_1c & 0x1f) == 0x10)
146      return attribram[offset];
142   mbee_state *state = space->machine->driver_data<mbee_state>();
143   if ((state->_1c & 0x1f) == 0x10)
144      return state->attribram[offset];
147145   else
148   if (mbee_0b & 1)
149      return gfxram[offset];
146   if (state->_0b & 1)
147      return state->gfxram[offset];
150148   else
151      return videoram[offset];
149      return state->videoram[offset];
152150}
153151
154152WRITE8_HANDLER( mbeeppc_low_w )
155153{
156   if (mbee_1c & 16)
157      attribram[offset] = data;
154   mbee_state *state = space->machine->driver_data<mbee_state>();
155   if (state->_1c & 16)
156      state->attribram[offset] = data;
158157   else
159      videoram[offset] = data;
158      state->videoram[offset] = data;
160159}
161160
162161READ8_HANDLER( mbeeppc_high_r )
163162{
164   if (mbee_08 & 0x40)
165      return colorram[offset];
163   mbee_state *state = space->machine->driver_data<mbee_state>();
164   if (state->_08 & 0x40)
165      return state->colorram[offset];
166166   else
167      return gfxram[(((mbee_1c & 15) + 1) << 11) | offset];
167      return state->gfxram[(((state->_1c & 15) + 1) << 11) | offset];
168168}
169169
170170WRITE8_HANDLER ( mbeeppc_high_w )
171171{
172   if ((mbee_08 & 0x40) && (~mbee_0b & 1))
173      colorram[offset] = data;
172   mbee_state *state = space->machine->driver_data<mbee_state>();
173   if ((state->_08 & 0x40) && (~state->_0b & 1))
174      state->colorram[offset] = data;
174175   else
175      gfxram[(((mbee_1c & 15) + 1) << 11) | offset] = data;
176      state->gfxram[(((state->_1c & 15) + 1) << 11) | offset] = data;
176177}
177178
178179
r9674r9675
187188/* The direction keys are used by the pc85 menu. Do not know what uses the "insert" key. */
188189static void keyboard_matrix_r(running_machine *machine, int offs)
189190{
191   mbee_state *state = machine->driver_data<mbee_state>();
190192   UINT8 port = (offs >> 7) & 7;
191193   UINT8 bit = (offs >> 4) & 7;
192194   UINT8 data = (input_port_read(machine, keynames[port]) >> bit) & 1;
193195
194   if ((data | is_premium) == 0)
196   if ((data | state->is_premium) == 0)
195197   {
196198      UINT8 extra = input_port_read(machine, "EXTRA");
197199
r9674r9675
231233
232234   if( data )
233235   {
234      sy6545_reg[17] = offs;
235      sy6545_reg[16] = (offs >> 8) & 0x3f;
236      sy6545_status |= 0x40; //lpen_strobe
236      state->sy6545_reg[17] = offs;
237      state->sy6545_reg[16] = (offs >> 8) & 0x3f;
238      state->sy6545_status |= 0x40; //lpen_strobe
237239   }
238240}
239241
240242
241243static void mbee_video_kbd_scan( running_machine *machine, int param )
242244{
243   if (mbee_0b) return;
245   mbee_state *state = machine->driver_data<mbee_state>();
246   if (state->_0b) return;
244247
245248   keyboard_matrix_r(machine, param);
246249}
r9674r9675
254257
255258READ8_HANDLER ( m6545_status_r )
256259{
260   mbee_state *state = space->machine->driver_data<mbee_state>();
257261   screen_device *screen = screen_first(*space->machine);
258262   const rectangle &visarea = screen->visible_area();
259263
260   UINT8 data = sy6545_status; // bit 6 = lpen strobe, bit 7 = update strobe
264   UINT8 data = state->sy6545_status; // bit 6 = lpen strobe, bit 7 = update strobe
261265   int y = space->machine->primary_screen->vpos();
262266
263267   if( y < visarea.min_y || y > visarea.max_y )
r9674r9675
268272
269273READ8_HANDLER ( m6545_data_r )
270274{
275   mbee_state *state = space->machine->driver_data<mbee_state>();
271276   UINT16 addr;
272   UINT8 data = mc6845_register_r(mc6845, 0);
277   UINT8 data = mc6845_register_r(state->mc6845, 0);
273278
274   switch( sy6545_ind )
279   switch( state->sy6545_ind )
275280   {
276281   case 16:
277282   case 17:
278      sy6545_status &= 0x80; // turn off lpen_strobe
283      state->sy6545_status &= 0x80; // turn off lpen_strobe
279284      break;
280285   case 31:
281286      /* This firstly pushes the contents of the transparent registers onto the MA lines,
282287      then increments the address, then sets update strobe on. */
283      addr = (sy6545_reg[18] << 8) | sy6545_reg[19];
288      addr = (state->sy6545_reg[18] << 8) | state->sy6545_reg[19];
284289      keyboard_matrix_r(space->machine, addr);
285      sy6545_reg[19]++;
286      if (!sy6545_reg[19]) sy6545_reg[18]++;
287      sy6545_status |= 0x80; // update_strobe
290      state->sy6545_reg[19]++;
291      if (!state->sy6545_reg[19]) state->sy6545_reg[18]++;
292      state->sy6545_status |= 0x80; // update_strobe
288293      break;
289294   }
290295   return data;
r9674r9675
292297
293298WRITE8_HANDLER ( m6545_index_w )
294299{
300   mbee_state *state = space->machine->driver_data<mbee_state>();
295301   data &= 0x1f;
296   sy6545_ind = data;
297   mc6845_address_w( mc6845, 0, data );
302   state->sy6545_ind = data;
303   mc6845_address_w( state->mc6845, 0, data );
298304}
299305
300306WRITE8_HANDLER ( m6545_data_w )
301307{
308   mbee_state *state = space->machine->driver_data<mbee_state>();
302309   int addr = 0;
303310
304   switch( sy6545_ind )
311   switch( state->sy6545_ind )
305312   {
306313   case 12:
307314      data &= 0x3f; // select alternate character set
308      if( sy6545_reg[12] != data )
309         memcpy(gfxram, memory_region(space->machine, "gfx") + (((data & 0x30) == 0x20) << 11), 0x800);
315      if( state->sy6545_reg[12] != data )
316         memcpy(state->gfxram, memory_region(space->machine, "gfx") + (((data & 0x30) == 0x20) << 11), 0x800);
310317      break;
311318   case 31:
312319      /* This firstly pushes the contents of the transparent registers onto the MA lines,
313320      then increments the address, then sets update strobe on. */
314      addr = (sy6545_reg[18] << 8) | sy6545_reg[19];
321      addr = (state->sy6545_reg[18] << 8) | state->sy6545_reg[19];
315322      keyboard_matrix_r(space->machine, addr);
316      sy6545_reg[19]++;
317      if (!sy6545_reg[19]) sy6545_reg[18]++;
318      sy6545_status |= 0x80; // update_strobe
323      state->sy6545_reg[19]++;
324      if (!state->sy6545_reg[19]) state->sy6545_reg[18]++;
325      state->sy6545_status |= 0x80; // update_strobe
319326      break;
320327   }
321   sy6545_reg[sy6545_ind] = data & sy6545_mask[sy6545_ind];   /* save data in register */
322   mc6845_register_w( mc6845, 0, data );
323   if ((sy6545_ind > 8) && (sy6545_ind < 12)) sy6545_cursor_configure();      /* adjust cursor shape - remove when mame fixed */
328   state->sy6545_reg[state->sy6545_ind] = data & sy6545_mask[state->sy6545_ind];   /* save data in register */
329   mc6845_register_w( state->mc6845, 0, data );
330   if ((state->sy6545_ind > 8) && (state->sy6545_ind < 12)) sy6545_cursor_configure(state);      /* adjust cursor shape - remove when mame fixed */
324331}
325332
326333
r9674r9675
334341
335342************************************************************/
336343
337static void sy6545_cursor_configure(void)
344static void sy6545_cursor_configure(mbee_state *state)
338345{
339346   UINT8 i,curs_type=0,r9,r10,r11;
340347
r9674r9675
344351        2 = full cursor
345352        3 = two-part cursor (has a part at the top and bottom with the middle blank) */
346353
347   for ( i = 0; i < ARRAY_LENGTH(sy6545_cursor); i++) sy6545_cursor[i] = 0;      // prepare cursor by erasing old one
354   for ( i = 0; i < ARRAY_LENGTH(state->sy6545_cursor); i++) state->sy6545_cursor[i] = 0;      // prepare cursor by erasing old one
348355
349   r9  = sy6545_reg[9];               // number of scan lines - 1
350   r10 = sy6545_reg[10] & 0x1f;            // cursor start line = last 5 bits
351   r11 = sy6545_reg[11]+1;               // cursor end line incremented to suit for-loops below
356   r9  = state->sy6545_reg[9];               // number of scan lines - 1
357   r10 = state->sy6545_reg[10] & 0x1f;            // cursor start line = last 5 bits
358   r11 = state->sy6545_reg[11]+1;               // cursor end line incremented to suit for-loops below
352359
353360   /* decide the curs_type by examining the registers */
354361   if (r10 < r11) curs_type=1;            // start less than end, show start to end
r9674r9675
361368   if (r11 > 16) r11=16;               // truncate 5-bit register to fit our 4-bit hardware
362369
363370   /* create the new cursor */
364   if (curs_type > 1) for (i = 0;i < ARRAY_LENGTH(sy6545_cursor);i++) sy6545_cursor[i]=0xff; // turn on full cursor
371   if (curs_type > 1) for (i = 0;i < ARRAY_LENGTH(state->sy6545_cursor);i++) state->sy6545_cursor[i]=0xff; // turn on full cursor
365372
366   if (curs_type == 1) for (i = r10;i < r11;i++) sy6545_cursor[i]=0xff; // for each line that should show, turn on that scan line
373   if (curs_type == 1) for (i = r10;i < r11;i++) state->sy6545_cursor[i]=0xff; // for each line that should show, turn on that scan line
367374
368   if (curs_type == 3) for (i = r11; i < r10;i++) sy6545_cursor[i]=0; // now take a bite out of the middle
375   if (curs_type == 3) for (i = r11; i < r10;i++) state->sy6545_cursor[i]=0; // now take a bite out of the middle
369376}
370377
371378
r9674r9675
379386
380387VIDEO_START( mbee )
381388{
382   mc6845 = machine->device("crtc");
383   videoram = memory_region(machine, "videoram");
384   gfxram = memory_region(machine, "gfx")+0x1000;
385   is_premium = 0;
389   mbee_state *state = machine->driver_data<mbee_state>();
390   state->mc6845 = machine->device("crtc");
391   state->videoram = memory_region(machine, "videoram");
392   state->gfxram = memory_region(machine, "gfx")+0x1000;
393   state->is_premium = 0;
386394}
387395
388396VIDEO_START( mbeeic )
389397{
390   mc6845 = machine->device("crtc");
391   videoram = memory_region(machine, "videoram");
392   colorram = memory_region(machine, "colorram");
393   gfxram = memory_region(machine, "gfx")+0x1000;
394   is_premium = 0;
398   mbee_state *state = machine->driver_data<mbee_state>();
399   state->mc6845 = machine->device("crtc");
400   state->videoram = memory_region(machine, "videoram");
401   state->colorram = memory_region(machine, "colorram");
402   state->gfxram = memory_region(machine, "gfx")+0x1000;
403   state->is_premium = 0;
395404}
396405
397406VIDEO_START( mbeeppc )
398407{
399   mc6845 = machine->device("crtc");
400   videoram = memory_region(machine, "videoram");
401   colorram = memory_region(machine, "colorram");
402   gfxram = memory_region(machine, "gfx")+0x1000;
403   attribram = memory_region(machine, "attrib");
404   is_premium = 1;
408   mbee_state *state = machine->driver_data<mbee_state>();
409   state->mc6845 = machine->device("crtc");
410   state->videoram = memory_region(machine, "videoram");
411   state->colorram = memory_region(machine, "colorram");
412   state->gfxram = memory_region(machine, "gfx")+0x1000;
413   state->attribram = memory_region(machine, "attrib");
414   state->is_premium = 1;
405415}
406416
407417VIDEO_UPDATE( mbee )
408418{
409   framecnt++;
410   speed = sy6545_reg[10]&0x20, flash = sy6545_reg[10]&0x40;         // cursor modes
411   cursor = (sy6545_reg[14]<<8) | sy6545_reg[15];               // get cursor position
412   mc6845_update(mc6845, bitmap, cliprect);
419   mbee_state *state = screen->machine->driver_data<mbee_state>();
420   state->framecnt++;
421   state->speed = state->sy6545_reg[10]&0x20, state->flash = state->sy6545_reg[10]&0x40;         // cursor modes
422   state->cursor = (state->sy6545_reg[14]<<8) | state->sy6545_reg[15];               // get cursor position
423   mc6845_update(state->mc6845, bitmap, cliprect);
413424   return 0;
414425}
415426
r9674r9675
428439/* monochrome bee */
429440MC6845_UPDATE_ROW( mbee_update_row )
430441{
442   mbee_state *state = device->machine->driver_data<mbee_state>();
431443   UINT8 chr,gfx;
432444   UINT16 mem,x;
433445   UINT16  *p = BITMAP_ADDR16(bitmap, y, 0);
r9674r9675
436448   {
437449      UINT8 inv=0;
438450      mem = (ma + x) & 0x7ff;
439      chr = videoram[mem];
451      chr = state->videoram[mem];
440452
441453      mbee_video_kbd_scan(device->machine, x+ma);
442454
443455      /* process cursor */
444      if ((((!flash) && (!speed)) ||               // (5,6)=(0,0) = cursor on always
445         ((flash) && (speed) && (framecnt & 0x10)) ||      // (5,6)=(1,1) = cycle per 32 frames
446         ((flash) && (!speed) && (framecnt & 8))) &&      // (5,6)=(0,1) = cycle per 16 frames
447         (mem == cursor))               // displaying at cursor position?
448            inv ^= sy6545_cursor[ra];         // cursor scan row
456      if ((((!state->flash) && (!state->speed)) ||               // (5,6)=(0,0) = cursor on always
457         ((state->flash) && (state->speed) && (state->framecnt & 0x10)) ||      // (5,6)=(1,1) = cycle per 32 frames
458         ((state->flash) && (!state->speed) && (state->framecnt & 8))) &&      // (5,6)=(0,1) = cycle per 16 frames
459         (mem == state->cursor))               // displaying at cursor position?
460            inv ^= state->sy6545_cursor[ra];         // cursor scan row
449461
450462      /* get pattern of pixels for that character scanline */
451      gfx = gfxram[(chr<<4) | ra] ^ inv;
463      gfx = state->gfxram[(chr<<4) | ra] ^ inv;
452464
453465      /* Display a scanline of a character (8 pixels) */
454466      *p++ = ( gfx & 0x80 ) ? 1 : 0;
r9674r9675
465477/* prom-based colours */
466478MC6845_UPDATE_ROW( mbeeic_update_row )
467479{
480   mbee_state *state = device->machine->driver_data<mbee_state>();
468481   UINT8 chr,gfx,fg,bg;
469482   UINT16 mem,x,col;
470   UINT16 colourm = (mbee_08 & 0x0e) << 7;
483   UINT16 colourm = (state->_08 & 0x0e) << 7;
471484   UINT16  *p = BITMAP_ADDR16(bitmap, y, 0);
472485
473486   for (x = 0; x < x_count; x++)         // for each character
474487   {
475488      UINT8 inv=0;
476489      mem = (ma + x) & 0x7ff;
477      chr = videoram[mem];
478      col = colorram[mem] | colourm;               // read a byte of colour
490      chr = state->videoram[mem];
491      col = state->colorram[mem] | colourm;               // read a byte of colour
479492
480493      mbee_video_kbd_scan(device->machine, x+ma);
481494
482495      /* process cursor */
483      if ((((!flash) && (!speed)) ||               // (5,6)=(0,0) = cursor on always
484         ((flash) && (speed) && (framecnt & 0x10)) ||      // (5,6)=(1,1) = cycle per 32 frames
485         ((flash) && (!speed) && (framecnt & 8))) &&      // (5,6)=(0,1) = cycle per 16 frames
486         (mem == cursor))               // displaying at cursor position?
487            inv ^= sy6545_cursor[ra];         // cursor scan row
496      if ((((!state->flash) && (!state->speed)) ||               // (5,6)=(0,0) = cursor on always
497         ((state->flash) && (state->speed) && (state->framecnt & 0x10)) ||      // (5,6)=(1,1) = cycle per 32 frames
498         ((state->flash) && (!state->speed) && (state->framecnt & 8))) &&      // (5,6)=(0,1) = cycle per 16 frames
499         (mem == state->cursor))               // displaying at cursor position?
500            inv ^= state->sy6545_cursor[ra];         // cursor scan row
488501
489502      /* get pattern of pixels for that character scanline */
490      gfx = gfxram[(chr<<4) | ra] ^ inv;
503      gfx = state->gfxram[(chr<<4) | ra] ^ inv;
491504      fg = (col & 0x001f) | 64;               // map to foreground palette
492505      bg = (col & 0x07e0) >> 5;               // and background palette
493506
r9674r9675
507520/* new colours & hires2 */
508521MC6845_UPDATE_ROW( mbeeppc_update_row )
509522{
523   mbee_state *state = device->machine->driver_data<mbee_state>();
510524   UINT8 gfx,fg,bg;
511525   UINT16 mem,x,col,chr;
512526   UINT16  *p = BITMAP_ADDR16(bitmap, y, 0);
r9674r9675
515529   {
516530      UINT8 inv=0;
517531      mem = (ma + x) & 0x7ff;
518      chr = videoram[mem];
519      col = colorram[mem];                  // read a byte of colour
532      chr = state->videoram[mem];
533      col = state->colorram[mem];                  // read a byte of colour
520534
521      if (mbee_1c & 0x80)                  // are extended features enabled?
535      if (state->_1c & 0x80)                  // are extended features enabled?
522536      {
523         UINT8 attr = attribram[mem];
537         UINT8 attr = state->attribram[mem];
524538
525539         if (chr & 0x80)
526540            chr += ((attr & 15) << 7);         // bump chr to its particular pcg definition
r9674r9675
528542         if (attr & 0x40)
529543            inv ^= 0xff;               // inverse attribute
530544
531         if ((attr & 0x80) && (framecnt & 0x10))         // flashing attribute
545         if ((attr & 0x80) && (state->framecnt & 0x10))         // flashing attribute
532546            chr = 0x20;
533547      }
534548
535549      mbee_video_kbd_scan(device->machine, x+ma);
536550
537551      /* process cursor */
538      if ((((!flash) && (!speed)) ||               // (5,6)=(0,0) = cursor on always
539         ((flash) && (speed) && (framecnt & 0x10)) ||      // (5,6)=(1,1) = cycle per 32 frames
540         ((flash) && (!speed) && (framecnt & 8))) &&      // (5,6)=(0,1) = cycle per 16 frames
541         (mem == cursor))               // displaying at cursor position?
542            inv ^= sy6545_cursor[ra];         // cursor scan row
552      if ((((!state->flash) && (!state->speed)) ||               // (5,6)=(0,0) = cursor on always
553         ((state->flash) && (state->speed) && (state->framecnt & 0x10)) ||      // (5,6)=(1,1) = cycle per 32 frames
554         ((state->flash) && (!state->speed) && (state->framecnt & 8))) &&      // (5,6)=(0,1) = cycle per 16 frames
555         (mem == state->cursor))               // displaying at cursor position?
556            inv ^= state->sy6545_cursor[ra];         // cursor scan row
543557
544558      /* get pattern of pixels for that character scanline */
545      gfx = gfxram[(chr<<4) | ra] ^ inv;
559      gfx = state->gfxram[(chr<<4) | ra] ^ inv;
546560      fg = col & 15;                     // map to foreground palette
547561      bg = (col & 0xf0) >> 4;                  // and background palette
548562
src/mess/video/ondra.c
r9674r9675
1111#include "includes/ondra.h"
1212#include "devices/messram.h"
1313
14UINT8 ondra_video_enable;
1514
1615
1716VIDEO_START( ondra )
1817{
19   ondra_video_enable = 0;
18   ondra_state *state = machine->driver_data<ondra_state>();
19   state->video_enable = 0;
2020}
2121
2222VIDEO_UPDATE( ondra )
2323{
24   ondra_state *state = screen->machine->driver_data<ondra_state>();
2425   UINT8 code1,code2;
2526   int y, x, b;
2627   int Vaddr = 0x2800;
2728
28   if (ondra_video_enable==1) {
29   if (state->video_enable==1) {
2930      for (x = 0; x < 40; x++)
3031      {
3132         for (y = 127; y >=0; y--)
src/mess/video/orao.c
r9674r9675
1010#include "emu.h"
1111#include "includes/orao.h"
1212
13UINT8 *orao_video_ram;
1413
1514VIDEO_START( orao )
1615{
r9674r9675
1817
1918VIDEO_UPDATE( orao )
2019{
20   orao_state *state = screen->machine->driver_data<orao_state>();
2121   UINT8 code;
2222   int y, x, b;
2323
r9674r9675
2727      int horpos = 0;
2828      for (x = 0; x < 32; x++)
2929      {
30         code = orao_video_ram[addr++];
30         code = state->video_ram[addr++];
3131         for (b = 0; b < 8; b++)
3232         {
3333            *BITMAP_ADDR16(bitmap, y, horpos++) =  (code >> b) & 0x01;
src/mess/video/orion.c
r9674r9675
1818
1919VIDEO_UPDATE( orion128 )
2020{
21   orion_state *state = screen->machine->driver_data<orion_state>();
2122   UINT8 code1,code2,code3,code4,color,val;
2223   int y, x,b;
23   int orionproshift = (orion128_video_mode & 0x10) ? 1 : 0;
24   int part1addr = (3-((orion128_video_page & 3) | orionproshift)) * 0x4000;
24   int orionproshift = (state->orion128_video_mode & 0x10) ? 1 : 0;
25   int part1addr = (3-((state->orion128_video_page & 3) | orionproshift)) * 0x4000;
2526
2627   int part2addr = part1addr + 0x10000;
27   int video_mode = orion128_video_mode & orion_video_mode_mask;
28   for (x = 0; x < orion128_video_width; x++)
28   int video_mode = state->orion128_video_mode & state->video_mode_mask;
29   for (x = 0; x < state->orion128_video_width; x++)
2930   {
3031      for (y = 0; y < 256; y++)
3132      {
r9674r9675
3435         code3 = messram_get_ptr(screen->machine->device("messram"))[part1addr + y + x*256 + 0x4000];
3536         code4 = messram_get_ptr(screen->machine->device("messram"))[part2addr + y + x*256 + 0x4000];
3637         if ((video_mode==14) || (video_mode==15)) {
37            code2 = orionpro_pseudo_color;
38            code2 = state->orionpro_pseudo_color;
3839         }
3940         color = 0;
4041         for (b = 7; b >= 0; b--)
4142         {
42            switch(orion128_video_mode & orion_video_mode_mask) {
43            switch(state->orion128_video_mode & state->video_mode_mask) {
4344               case 0 : color = ((code1 >> b) & 0x01) ? 10 : 0; break;
4445               case 1 : color = ((code1 >> b) & 0x01) ? 17 : 16; break;
4546               case 4 : val = (((code1 >> b) & 0x01) << 1) + ((code2 >> b) & 0x01);
r9674r9675
6566                      color = ((code1 >> b) & 0x01) ? (code2 & 0x0f) : (code2 >> 4); break;
6667
6768               default:
68                  switch(orion128_video_mode & orion_video_mode_mask & 20) {
69                  switch(state->orion128_video_mode & state->video_mode_mask & 20) {
6970                     case 16 :
7071                            color = (((code1 >> b) & 0x01) << 2) + (((code3 >> b) & 0x01) << 1) + ((code2 >> b) & 0x01);
7172                            break;
src/mess/video/mikro80.c
r9674r9675
1010#include "emu.h"
1111#include "includes/mikro80.h"
1212
13UINT8 *mikro80_video_ram;
14UINT8 *mikro80_cursor_ram;
1513
1614VIDEO_START( mikro80 )
1715{
r9674r9675
1917
2018VIDEO_UPDATE( mikro80 )
2119{
20   mikro80_state *state = screen->machine->driver_data<mikro80_state>();
2221   UINT8 *gfx = memory_region(screen->machine, "gfx1");
2322   int x,y,b;
2423
r9674r9675
2726      for(x = 0; x < 64; x++ )
2827      {
2928         int addr = x + (y / 8)*64;
30         UINT8 code = gfx[mikro80_video_ram [addr]*8+ (y % 8)];
31         UINT8 attr = mikro80_cursor_ram[addr+1] & 0x80 ? 1 : 0;
29         UINT8 code = gfx[state->video_ram [addr]*8+ (y % 8)];
30         UINT8 attr = state->cursor_ram[addr+1] & 0x80 ? 1 : 0;
3231         for (b = 7; b >= 0; b--)
3332         {
3433            UINT8 col = (code >> b) & 0x01;
src/mess/video/mz80.c
r9674r9675
4040
4141VIDEO_UPDATE( mz80k )
4242{
43   mz80_state *state = screen->machine->driver_data<mz80_state>();
4344   int x,y;
4445   address_space *space = cputag_get_address_space(screen->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
45   mz80k_vertical = mz80k_vertical ? 0 : 1;
46   mz80k_cursor_cnt++;
47   if (mz80k_cursor_cnt==64) mz80k_cursor_cnt = 0;
46   state->mz80k_vertical = state->mz80k_vertical ? 0 : 1;
47   state->mz80k_cursor_cnt++;
48   if (state->mz80k_cursor_cnt==64) state->mz80k_cursor_cnt = 0;
4849
4950   for(y = 0; y < 25; y++ )
5051   {
src/mess/video/llc.c
r9674r9675
1010#include "emu.h"
1111#include "includes/llc.h"
1212
13UINT8 *llc_video_ram;
1413
1514VIDEO_START( llc1 )
1615{
r9674r9675
1817
1918VIDEO_UPDATE( llc1 )
2019{
20   llc_state *state = screen->machine->driver_data<llc_state>();
2121   UINT8 code,disp;
2222   int y, x, b,c,inv;
2323   UINT8 *gfx = memory_region(screen->machine, "gfx1");
r9674r9675
2626   {
2727      for (y = 0; y < 16; y++)
2828      {
29         code = llc_video_ram[x + y*64];
29         code = state->video_ram[x + y*64];
3030         inv = code & 0x80; // highest bit is invert flag
3131         code &= 0x7f;
3232         for (b = 0; b < 8; b++)
r9674r9675
4949
5050VIDEO_UPDATE( llc2 )
5151{
52   llc_state *state = screen->machine->driver_data<llc_state>();
5253   UINT8 code,disp;
5354   int y, x, b,c;
5455   UINT8 *gfx = memory_region(screen->machine, "gfx1");
r9674r9675
5758   {
5859      for (y = 0; y < 32; y++)
5960      {
60         code = llc_video_ram[x + y*64];
61         code = state->video_ram[x + y*64];
6162         for (b = 0; b < 8; b++)
6263         {
6364            disp = gfx[code * 8 + b];
src/mess/video/trs80.c
r9674r9675
1818    d1 7 or 8 bit video (1=requires 7-bit, 0=don't care)
1919    d0 80/64 or 40/32 characters per line (1=32) */
2020
21static UINT16 start_address=0;
22static UINT8 crtc_reg;
23static UINT8 trs80_size_store;
2421
2522WRITE8_HANDLER( trs80m4_88_w )
2623{
24   trs80_state *state = space->machine->driver_data<trs80_state>();
2725/* This is for the programming of the CRTC registers.
2826    However this CRTC is mask-programmed, and only the
2927    start address register can be used. The cursor and
r9674r9675
3230    Therefore it is easier to use normal
3331    coding rather than the mc6845 device. */
3432
35   if (!offset) crtc_reg = data & 0x1f;
33   if (!offset) state->crtc_reg = data & 0x1f;
3634
37   if (offset) switch (crtc_reg)
35   if (offset) switch (state->crtc_reg)
3836   {
3937      case 12:
40         start_address = (start_address & 0x00ff) | (data << 8);
38         state->start_address = (state->start_address & 0x00ff) | (data << 8);
4139         break;
4240      case 13:
43         start_address = (start_address & 0xff00) | data;
41         state->start_address = (state->start_address & 0xff00) | data;
4442   }
4543}
4644
4745
4846VIDEO_START( trs80 )
4947{
50   trs80_size_store = 0xff;
51   trs80_mode &= 2;
48   trs80_state *state = machine->driver_data<trs80_state>();
49   state->size_store = 0xff;
50   state->mode &= 2;
5251}
5352
5453
r9674r9675
6059   UINT8 y,ra,chr,gfx,gfxbit;
6160   UINT16 sy=0,ma=0,x;
6261   UINT8 *FNT = memory_region(screen->machine, "gfx1");
63   UINT8 cols = (trs80_mode & 1) ? 32 : 64;
64   UINT8 skip = (trs80_mode & 1) ? 2 : 1;
62   UINT8 cols = (state->mode & 1) ? 32 : 64;
63   UINT8 skip = (state->mode & 1) ? 2 : 1;
6564
66   if (trs80_mode != trs80_size_store)
65   if (state->mode != state->size_store)
6766   {
68      trs80_size_store = trs80_mode & 1;
67      state->size_store = state->mode & 1;
6968      screen->set_visible_area(0, cols*FW-1, 0, 16*FH-1);
7069   }
7170
r9674r9675
9392            }
9493            else
9594            {
96               if ((trs80_mode & 2) && (chr < 32)) chr+=64;
95               if ((state->mode & 2) && (chr < 32)) chr+=64;
9796
9897               /* get pattern of pixels for that character scanline */
9998               if (ra < 8)
r9674r9675
125124   UINT16 sy=0,ma=0,x;
126125   UINT8 *FNT = memory_region(screen->machine, "gfx1");
127126   UINT8 skip=1;
128   UINT8 cols = (trs80_mode & 4) ? 80 : 64;
129   UINT8 rows = (trs80_mode & 4) ? 24 : 16;
130   UINT8 lines = (trs80_mode & 4) ? 10 : 12;
127   UINT8 cols = (state->mode & 4) ? 80 : 64;
128   UINT8 rows = (state->mode & 4) ? 24 : 16;
129   UINT8 lines = (state->mode & 4) ? 10 : 12;
131130   UINT8 s_cols = cols;
132   UINT8 mask = (trs80_mode & 0x20) ? 0xff : 0xbf;   /* Select Japanese or extended chars */
131   UINT8 mask = (state->mode & 0x20) ? 0xff : 0xbf;   /* Select Japanese or extended chars */
133132
134   if (trs80_mode & 1)
133   if (state->mode & 1)
135134   {
136135      s_cols >>= 1;
137136      skip = 2;
138137   }
139138
140   if ((trs80_mode & 0x7f) != trs80_size_store)
139   if ((state->mode & 0x7f) != state->size_store)
141140   {
142      trs80_size_store = trs80_mode & 5;
141      state->size_store = state->mode & 5;
143142      screen->set_visible_area(0, s_cols*8-1, 0, rows*lines-1);
144143   }
145144
r9674r9675
151150
152151         for (x = ma; x < ma + cols; x+=skip)
153152         {
154            chr = videoram[x+start_address];
153            chr = videoram[x+state->start_address];
155154
156            if (((chr & 0xc0) == 0xc0) && (~trs80_mode & 8))
155            if (((chr & 0xc0) == 0xc0) && (~state->mode & 8))
157156            {
158157               if (ra < 8)
159158                  gfx = FNT[((chr&mask)<<3) | ra ];
r9674r9675
170169               *p++ = ( gfx & 0x01 ) ? 1 : 0;
171170            }
172171            else
173            if ((chr & 0x80) && (~trs80_mode & 8))
172            if ((chr & 0x80) && (~state->mode & 8))
174173            {
175174               gfxbit = 1<<((ra & 0x0c)>>1);
176175               /* Display one line of a lores character */
r9674r9675
193192                  gfx = 0;
194193
195194               /* if inverse mode, and bit 7 set, invert gfx */
196               if ((trs80_mode & 8) && (chr & 0x80))
195               if ((state->mode & 8) && (chr & 0x80))
197196                  gfx ^= 0xff;
198197
199198               /* Display a scanline of a character */
r9674r9675
221220   UINT8 y,ra,chr,gfx,gfxbit;
222221   UINT16 sy=0,ma=0,x;
223222   UINT8 *FNT = memory_region(screen->machine, "gfx1");
224   UINT8 cols = (trs80_mode & 1) ? 32 : 64;
225   UINT8 skip = (trs80_mode & 1) ? 2 : 1;
223   UINT8 cols = (state->mode & 1) ? 32 : 64;
224   UINT8 skip = (state->mode & 1) ? 2 : 1;
226225
227   if (trs80_mode != trs80_size_store)
226   if (state->mode != state->size_store)
228227   {
229      trs80_size_store = trs80_mode & 1;
228      state->size_store = state->mode & 1;
230229      screen->set_visible_area(0, cols*FW-1, 0, 16*FH-1);
231230   }
232231
r9674r9675
254253            }
255254            else
256255            {
257               if ((trs80_mode & 2) && (chr < 32)) chr+=64;
256               if ((state->mode & 2) && (chr < 32)) chr+=64;
258257
259258               /* get pattern of pixels for that character scanline */
260259               gfx = FNT[(chr<<4) | ra ];
r9674r9675
283282   UINT8 chr,gfx,gfxbit,bg=7,fg=0;
284283   UINT16 sy=0,ma=0,x,y,ra;
285284   UINT8 *FNT = memory_region(screen->machine, "gfx1");
286   UINT8 cols = (trs80_mode & 0x10) ? 80 : 64;
285   UINT8 cols = (state->mode & 0x10) ? 80 : 64;
287286
288287   /* Although the OS can select 32-character mode, it is not supported by hardware */
289   if (trs80_mode != trs80_size_store)
288   if (state->mode != state->size_store)
290289   {
291      trs80_size_store = trs80_mode & 0x10;
290      state->size_store = state->mode & 0x10;
292291      screen->set_visible_area(0, cols*FW-1, 0, 16*FH-1);
293292   }
294293
295   if (trs80_mode & 8)
294   if (state->mode & 8)
296295   {
297296      bg = 0;
298297      fg = 7;
299298   }
300299
301   switch (trs80_mode & 0x30)
300   switch (state->mode & 0x30)
302301   {
303302      case 0:               // MODE 0
304303         for (y = 0; y < 16; y++)
r9674r9675
354353
355354               for (x = 0; x < 0x40; x++)
356355               {
357                  gfx = trs80_gfxram[ y | x | ra];
356                  gfx = state->gfxram[ y | x | ra];
358357                  /* Display 6 pixels in normal region */
359358                  *p++ = ( gfx & 0x01 ) ? fg : bg;
360359                  *p++ = ( gfx & 0x02 ) ? fg : bg;
r9674r9675
366365
367366               for (x = 0; x < 0x10; x++)
368367               {
369                  gfx = trs80_gfxram[ 0x3000 | x | (ra & 0xc00) | ((ra & 0x3000) >> 8)];
368                  gfx = state->gfxram[ 0x3000 | x | (ra & 0xc00) | ((ra & 0x3000) >> 8)];
370369                  /* Display 6 pixels in extended region */
371370                  *p++ = ( gfx & 0x01 ) ? fg : bg;
372371                  *p++ = ( gfx & 0x02 ) ? fg : bg;
r9674r9675
390389
391390               for (x = 0; x < 0x40; x++)
392391               {
393                  gfx = trs80_gfxram[ y | x | ra];
392                  gfx = state->gfxram[ y | x | ra];
394393                  /* Display 6 pixels in normal region */
395394                  fg = (gfx & 0x38) >> 3;
396395                  *p++ = fg;
r9674r9675
417416
418417               for (x = 0; x < 0x40; x++)
419418               {
420                  gfx = trs80_gfxram[ y | x | ra];
419                  gfx = state->gfxram[ y | x | ra];
421420                  fg = (videoram[ 0x3c00 | x | y ] & 0x38) >> 3;
422421                  /* Display 6 pixels in normal region */
423422                  *p++ = ( gfx & 0x01 ) ? fg : bg;
r9674r9675
431430
432431               for (x = 0; x < 0x10; x++)
433432               {
434                  gfx = trs80_gfxram[ 0x3000 | x | (ra & 0xc00) | ((ra & 0x3000) >> 8)];
435                  fg = (trs80_gfxram[ 0x3c00 | x | y ] & 0x38) >> 3;
433                  gfx = state->gfxram[ 0x3000 | x | (ra & 0xc00) | ((ra & 0x3000) >> 8)];
434                  fg = (state->gfxram[ 0x3c00 | x | y ] & 0x38) >> 3;
436435                  /* Display 6 pixels in extended region */
437436                  *p++ = ( gfx & 0x01 ) ? fg : bg;
438437                  *p++ = ( gfx & 0x02 ) ? fg : bg;
439438                  *p++ = ( gfx & 0x04 ) ? fg : bg;
440                  fg = trs80_gfxram[ 0x3c00 | x | y ] & 0x07;
439                  fg = state->gfxram[ 0x3c00 | x | y ] & 0x07;
441440                  *p++ = ( gfx & 0x08 ) ? fg : bg;
442441                  *p++ = ( gfx & 0x10 ) ? fg : bg;
443442                  *p++ = ( gfx & 0x20 ) ? fg : bg;
r9674r9675
457456   UINT8 y,ra,chr,gfx;
458457   UINT16 sy=0,ma=0,x;
459458   UINT8 *FNT = memory_region(screen->machine, "gfx1");
460   UINT8 cols = (trs80_mode & 1) ? 32 : 64;
461   UINT8 skip = (trs80_mode & 1) ? 2 : 1;
459   UINT8 cols = (state->mode & 1) ? 32 : 64;
460   UINT8 skip = (state->mode & 1) ? 2 : 1;
462461
463   if (trs80_mode != trs80_size_store)
462   if (state->mode != state->size_store)
464463   {
465      trs80_size_store = trs80_mode & 1;
464      state->size_store = state->mode & 1;
466465      screen->set_visible_area(0, cols*8-1, 0, 16*16-1);
467466   }
468467
r9674r9675
504503{
505504   trs80_state *state = space->machine->driver_data<trs80_state>();
506505   UINT8 *videoram = state->videoram;
507   if ((trs80_mode & 0x80) && (~trs80_model4 & 1)) offset |= 0x400;
506   if ((state->mode & 0x80) && (~state->model4 & 1)) offset |= 0x400;
508507   return videoram[offset];
509508}
510509
r9674r9675
512511{
513512   trs80_state *state = space->machine->driver_data<trs80_state>();
514513   UINT8 *videoram = state->videoram;
515   if ((trs80_mode & 0x80) && (~trs80_model4 & 1)) offset |= 0x400;
514   if ((state->mode & 0x80) && (~state->model4 & 1)) offset |= 0x400;
516515   videoram[offset] = data;
517516}
518517
r9674r9675
523522
524523READ8_HANDLER( trs80_gfxram_r )
525524{
526   return trs80_gfxram[offset];
525   trs80_state *state = space->machine->driver_data<trs80_state>();
526   return state->gfxram[offset];
527527}
528528
529529WRITE8_HANDLER( trs80_gfxram_w )
530530{
531   trs80_gfxram[offset] = data;
531   trs80_state *state = space->machine->driver_data<trs80_state>();
532   state->gfxram[offset] = data;
532533}
533534
534535
src/mess/includes/mc80.h
r9674r9675
1111#include "machine/z80pio.h"
1212#include "machine/z80sio.h"
1313
14class mc80_state : public driver_device
15{
16public:
17   mc80_state(running_machine &machine, const driver_device_config_base &config)
18      : driver_device(machine, config) { }
19
20   UINT8* mc8020_video_ram;
21   UINT8 *mc8030_video_mem;
22};
23
24
1425/*----------- defined in machine/mc80.c -----------*/
1526
1627/*****************************************************************************/
r9674r9675
4253/*                            Implementation for MC80.2x                     */
4354/*****************************************************************************/
4455
45extern UINT8* mc8020_video_ram;
4656
4757extern VIDEO_START( mc8020 );
4858extern VIDEO_UPDATE( mc8020 );
r9674r9675
5161/*                            Implementation for MC80.3x                     */
5262/*****************************************************************************/
5363
54extern UINT8 *mc8030_video_mem;
5564
5665extern VIDEO_START( mc8030 );
5766extern VIDEO_UPDATE( mc8030 );
src/mess/includes/mbee.h
r9674r9675
1313#include "machine/z80pio.h"
1414#include "devices/cassette.h"
1515#include "machine/ctronics.h"
16#include "machine/mc146818.h"
1617#include "video/mc6845.h"
1718#include "sound/speaker.h"
1819
r9674r9675
2425      : driver_device(machine, config) { }
2526
2627   UINT8 dummy;
28   size_t size;
29   UINT8 clock_pulse;
30   UINT8 mbee256_key_available;
31   UINT8 fdc_intrq;
32   UINT8 fdc_drq;
33   UINT8 _0a;
34   running_device *fdc;
35   mc146818_device *rtc;
36   running_device *z80pio;
37   running_device *speaker;
38   running_device *cassette;
39   running_device *printer;
40   UINT8 mbee256_was_pressed[15];
41   UINT8 mbee256_q[20];
42   UINT8 mbee256_q_pos;
43   UINT8 framecnt;
44   UINT8 *gfxram;
45   UINT8 *colorram;
46   UINT8 *videoram;
47   UINT8 *attribram;
48   UINT8 _08;
49   UINT8 _0b;
50   UINT8 _1c;
51   UINT8 is_premium;
52   UINT8 sy6545_cursor[16];
53   UINT8 sy6545_status;
54   running_device *mc6845;
55   UINT8 speed;
56   UINT8 flash;
57   UINT16 cursor;
58   UINT8 sy6545_reg[32];
59   UINT8 sy6545_ind;
2760};
2861
2962
30/*----------- defined in drivers/mbee.c -----------*/
31
32
33
3463/*----------- defined in machine/mbee.c -----------*/
3564
3665extern const wd17xx_interface mbee_wd17xx_interface;
r9674r9675
75104
76105/*----------- defined in video/mbee.c -----------*/
77106
78
79107READ8_HANDLER( m6545_status_r );
80108WRITE8_HANDLER( m6545_index_w );
81109READ8_HANDLER( m6545_data_r );
src/mess/includes/x1.h
r9674r9675
4848   const x1_keyboard_device_config &m_config;
4949};
5050
51typedef struct
52{
53   UINT8 gfx_bank;
54   UINT8 disp_bank;
55   UINT8 pcg_mode;
56   UINT8 v400_mode;
57
58   UINT8 ply;
59   UINT8 blackclip; // x1 turbo specific
60} scrn_reg_t;
61
62typedef struct
63{
64   UINT8 pal;
65   UINT8 gfx_pal;
66   UINT8 txt_pal[8];
67   UINT8 txt_disp;
68} turbo_reg_t;
69
70typedef struct
71{
72   UINT8 sec, min, hour, day, wday, month, year;
73} x1_rtc_t;
74
75
5176class x1_state : public driver_device
5277{
5378public:
r9674r9675
5580      : driver_device(machine, config) { }
5681
5782   UINT8 *videoram;
83   UINT8 hres_320;
84   UINT8 io_switch;
85   UINT8 io_sys;
86   UINT8 vsync;
87   UINT8 vdisp;
88   UINT8 io_bank_mode;
89   UINT8 *gfx_bitmap_ram;
90   UINT16 pcg_index[3];
91   UINT8 pcg_reset;
92   UINT16 crtc_start_addr;
93   UINT8 tile_height;
94   UINT8 sub_obf;
95   UINT8 ctc_irq_flag;
96   scrn_reg_t scrn_reg;
97   turbo_reg_t turbo_reg;
98   x1_rtc_t rtc;
99   emu_timer *rtc_timer;
100   UINT8 pcg_write_addr;
101   UINT8 *colorram;
102   UINT8 sub_cmd;
103   UINT8 sub_cmd_length;
104   UINT8 sub_val[8];
105   int sub_val_ptr;
106   int key_i;
107   UINT8 irq_vector;
108   UINT8 cmt_current_cmd;
109   UINT8 cmt_test;
110   UINT8 rom_index[3];
111   UINT32 kanji_offset;
112   UINT8 bios_offset;
113   UINT8 pcg_index_r[3];
114   UINT16 used_pcg_addr;
115   UINT8 x_b;
116   UINT8 x_g;
117   UINT8 x_r;
118   int addr_latch;
119   UINT8 kanji_addr_l;
120   UINT8 kanji_addr_h;
121   UINT8 kanji_count;
122   UINT32 kanji_addr;
123   UINT8 pcg_reset_occurred;
124   UINT32 old_key1;
125   UINT32 old_key2;
126   UINT32 old_key3;
127   UINT32 old_key4;
128   UINT32 old_fkey;
129   UINT8 key_irq_flag;
130   UINT8 key_irq_vector;
58131};
59132
60133
61/*----------- defined in drivers/x1.c -----------*/
62
63extern UINT8 x1_key_irq_flag;
64extern UINT8 x1_key_irq_vector;
65
66134/*----------- defined in machine/x1.c -----------*/
67135
68136extern const device_type X1_KEYBOARD;
src/mess/includes/ondra.h
r9674r9675
77#ifndef ONDRA_H_
88#define ONDRA_H_
99
10class ondra_state : public driver_device
11{
12public:
13   ondra_state(running_machine &machine, const driver_device_config_base &config)
14      : driver_device(machine, config) { }
15
16   UINT8 video_enable;
17   UINT8 bank1_status;
18   UINT8 bank2_status;
19};
20
21
1022/*----------- defined in machine/ondra.c -----------*/
1123
1224extern MACHINE_START( ondra );
r9674r9675
1729extern WRITE8_HANDLER( ondra_port_0a_w );
1830/*----------- defined in video/ondra.c -----------*/
1931
20extern UINT8 ondra_video_enable;
2132extern VIDEO_START( ondra );
2233extern VIDEO_UPDATE( ondra );
2334
src/mess/includes/orao.h
r9674r9675
88#define ORAO_H_
99
1010
11class orao_state : public driver_device
12{
13public:
14   orao_state(running_machine &machine, const driver_device_config_base &config)
15      : driver_device(machine, config) { }
16
17   UINT8 *memory;
18   UINT8 *video_ram;
19};
20
21
1122/*----------- defined in machine/orao.c -----------*/
1223
13extern UINT8 *orao_memory;
14
1524extern DRIVER_INIT( orao );
1625extern MACHINE_RESET( orao );
1726
r9674r9675
2231
2332
2433/*----------- defined in video/orao.c -----------*/
25extern UINT8 *orao_video_ram;
2634
2735extern VIDEO_START( orao );
2836extern VIDEO_UPDATE( orao );
src/mess/includes/mekd2.h
r9674r9675
1515      : driver_device(machine, config) { }
1616
1717   UINT8 *videoram;
18   UINT8 segment;
19   UINT8 digit;
20   UINT8 keydata;
1821};
1922
2023
src/mess/includes/orion.h
r9674r9675
99
1010#include "machine/i8255a.h"
1111
12class orion_state : public driver_device
13{
14public:
15   orion_state(running_machine &machine, const driver_device_config_base &config)
16      : driver_device(machine, config) { }
17
18   UINT8 orion128_video_mode;
19   UINT8 orion128_video_page;
20   UINT8 orion128_video_width;
21   UINT8 video_mode_mask;
22   UINT8 orionpro_pseudo_color;
23   UINT8 romdisk_lsb;
24   UINT8 romdisk_msb;
25   UINT8 orion128_memory_page;
26   UINT8 orionz80_memory_page;
27   UINT8 orionz80_dispatcher;
28   UINT8 speaker;
29   UINT8 orionpro_ram0_segment;
30   UINT8 orionpro_ram1_segment;
31   UINT8 orionpro_ram2_segment;
32   UINT8 orionpro_page;
33   UINT8 orionpro_128_page;
34   UINT8 orionpro_rom2_segment;
35   UINT8 orionpro_dispatcher;
36};
37
38
1239/*----------- defined in machine/orion.c -----------*/
1340
14extern UINT8 orion128_video_mode;
15extern UINT8 orion128_video_page;
16extern UINT8 orion128_video_width;
17extern UINT8 orion_video_mode_mask;
18extern UINT8 orionpro_pseudo_color;
19
2041extern const i8255a_interface orion128_ppi8255_interface_1;
2142
2243extern MACHINE_START( orion128 );
src/mess/includes/newbrain.h
r9674r9675
102102   running_device *upd765;
103103   running_device *cassette1;
104104   running_device *cassette2;
105   UINT8 copdata;
106   int copstate;
107   int copbytes;
108   int copregint;
105109};
106110
107111/* ---------- defined in video/newbrain.c ---------- */
src/mess/includes/mikro80.h
r9674r9675
99
1010#include "machine/i8255a.h"
1111
12class mikro80_state : public driver_device
13{
14public:
15   mikro80_state(running_machine &machine, const driver_device_config_base &config)
16      : driver_device(machine, config) { }
17
18   UINT8 *video_ram;
19   UINT8 *cursor_ram;
20   int keyboard_mask;
21   int key_mask;
22};
23
24
1225/*----------- defined in machine/mikro80.c -----------*/
1326
1427extern const i8255a_interface mikro80_ppi8255_interface;
r9674r9675
2639extern WRITE8_HANDLER (mikro80_8255_porta_w );
2740extern WRITE8_HANDLER (mikro80_8255_portc_w );
2841/*----------- defined in video/mikro80.c -----------*/
29extern UINT8 *mikro80_video_ram;
30extern UINT8 *mikro80_cursor_ram;
3142
3243extern VIDEO_START( mikro80 );
3344extern VIDEO_UPDATE( mikro80 );
src/mess/includes/mz80.h
r9674r9675
77#ifndef MZ80_H_
88#define MZ80_H_
99
10class mz80_state : public driver_device
11{
12public:
13   mz80_state(running_machine &machine, const driver_device_config_base &config)
14      : driver_device(machine, config) { }
15
16   UINT8 mz80k_vertical;
17   UINT8 mz80k_cursor_cnt;
18   UINT8 mz80k_tempo_strobe;
19   UINT8 mz80k_8255_portc;
20   UINT8 mz80k_keyboard_line;
21   UINT8 speaker_level;
22   UINT8 prev_state;
23};
24
25
1026/*----------- defined in machine/mz80.c -----------*/
1127
1228extern DRIVER_INIT( mz80k );
r9674r9675
1733extern const i8255a_interface mz80k_8255_int;
1834extern const struct pit8253_config mz80k_pit8253_config;
1935
20extern UINT8 mz80k_vertical;
21extern UINT8 mz80k_cursor_cnt;
22extern UINT8 mz80k_tempo_strobe;
2336
2437/*----------- defined in video/mz80.c -----------*/
2538
src/mess/includes/llc.h
r9674r9675
1010#include "machine/z80pio.h"
1111#include "machine/z80ctc.h"
1212
13class llc_state : public driver_device
14{
15public:
16   llc_state(running_machine &machine, const driver_device_config_base &config)
17      : driver_device(machine, config) { }
18
19   UINT8 *video_ram;
20   UINT8 s_code;
21   UINT8 llc1_key_state;
22};
23
24
1325/*----------- defined in machine/llc.c -----------*/
1426extern DRIVER_INIT( llc1 );
1527extern MACHINE_START( llc1 );
r9674r9675
2739extern WRITE8_HANDLER(llc2_basic_enable_w);
2840
2941/*----------- defined in video/llc.c -----------*/
30extern UINT8 *llc_video_ram;
3142
3243extern VIDEO_START( llc1 );
3344extern VIDEO_UPDATE( llc1 );
src/mess/includes/trs80.h
r9674r9675
2121      : driver_device(machine, config) { }
2222
2323   UINT8 *videoram;
24   UINT8 model4;
25   UINT8 *gfxram;
26   UINT8 mode;
27   UINT8 irq;
28   UINT8 mask;
29   UINT8 nmi_mask;
30   UINT8 port_ec;
31   UINT8 tape_unit;
32   UINT8 reg_load;
33   UINT8 nmi_data;
34#ifdef USE_TRACK
35   UINT8 track[4];
36#endif
37   UINT8 head;
38#ifdef USE_SECTOR
39   UINT8 sector[4];
40#endif
41   UINT8 cassette_data;
42   emu_timer *cassette_data_timer;
43   running_device *printer;
44   running_device *ay31015;
45   running_device *cass;
46   running_device *speaker;
47   running_device *fdc;
48   double old_cassette_val;
49   UINT16 start_address;
50   UINT8 crtc_reg;
51   UINT8 size_store;
2452};
2553
2654
27/*----------- defined in drivers/trs80.c -----------*/
28
29extern UINT8 trs80_model4;
30extern UINT8 *trs80_gfxram;
31
3255/*----------- defined in machine/trs80.c -----------*/
3356
3457extern const wd17xx_interface trs80_wd17xx_interface;
35extern UINT8 trs80_mode;
3658
3759MACHINE_START( trs80 );
3860MACHINE_RESET( trs80 );
src/mess/includes/svision.h
r9674r9675
77#ifndef SVISION_H_
88#define SVISION_H_
99
10typedef struct
11{
12   emu_timer *timer1;
13   int timer_shot;
14} svision_t;
1015
16typedef struct
17{
18   int state;
19   int on, clock, data;
20   UINT8 input;
21   emu_timer *timer;
22} svision_pet_t;
1123
24typedef struct
25{
26   UINT16 palette[4/*0x40?*/]; /* rgb8 */
27   int palette_on;
28} tvlink_t;
29
30
1231class svision_state : public driver_device
1332{
1433public:
r9674r9675
1635      : driver_device(machine, config) { }
1736
1837   UINT8 *videoram;
38   UINT8 *reg;
39   running_device *sound;
40   int *dma_finished;
41   svision_t svision;
42   svision_pet_t pet;
43   tvlink_t tvlink;
1944};
2045
2146
src/mess/drivers/tec1.c
r9674r9675
4848#include "sound/speaker.h"
4949#include "tec1.lh"
5050
51static emu_timer *tec1_kbd_timer;
52static UINT8 tec1_kbd;
53static UINT8 tec1_segment;
54static UINT8 tec1_digit;
55static running_device *tec1_speaker;
5651
52class tec1_state : public driver_device
53{
54public:
55   tec1_state(running_machine &machine, const driver_device_config_base &config)
56      : driver_device(machine, config) { }
5757
58   emu_timer *kbd_timer;
59   UINT8 kbd;
60   UINT8 segment;
61   UINT8 digit;
62   running_device *speaker;
63   UINT8 kbd_row;
64};
65
66
67
68
5869/***************************************************************************
5970
6071    Display
6172
6273***************************************************************************/
6374
64static void tec1_display(void)
75static void tec1_display(tec1_state *state)
6576{
6677   UINT8 i;
6778   for (i = 0; i < 6; i++)
68      if (tec1_digit & (1 << i))
69         output_set_digit_value(5-i, tec1_segment);
79      if (state->digit & (1 << i))
80         output_set_digit_value(5-i, state->segment);
7081}
7182
7283static WRITE8_HANDLER( tec1_segment_w )
7384{
85   tec1_state *state = space->machine->driver_data<tec1_state>();
7486/*  d7 segment d
7587    d6 segment e
7688    d5 segment c
r9674r9675
8092    d1 segment f
8193    d0 segment a */
8294
83   tec1_segment = BITSWAP8(data, 4, 2, 1, 6, 7, 5, 3, 0);
84   if (tec1_digit) tec1_display();
95   state->segment = BITSWAP8(data, 4, 2, 1, 6, 7, 5, 3, 0);
96   if (state->digit) tec1_display(state);
8597}
8698
8799static WRITE8_HANDLER( tec1_digit_w )
88100{
101   tec1_state *state = space->machine->driver_data<tec1_state>();
89102/*  d7 speaker
90103    d6 not used
91104    d5 data digit 1
r9674r9675
95108    d1 address digit 3
96109    d0 address digit 4 */
97110
98   speaker_level_w(tec1_speaker, (data & 0x80) ? 1 : 0);
111   speaker_level_w(state->speaker, (data & 0x80) ? 1 : 0);
99112
100   tec1_digit = data & 0x3f;
101   if (tec1_digit) tec1_display();
113   state->digit = data & 0x3f;
114   if (state->digit) tec1_display(state);
102115}
103116
104117
r9674r9675
110123
111124static READ8_HANDLER( tec1_kbd_r )
112125{
126   tec1_state *state = space->machine->driver_data<tec1_state>();
113127   cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE);
114   return tec1_kbd;
128   return state->kbd;
115129}
116130
117131static UINT8 tec1_convert_col_to_bin( UINT8 col, UINT8 row )
r9674r9675
138152
139153static TIMER_CALLBACK( tec1_kbd_callback )
140154{
155   tec1_state *state = machine->driver_data<tec1_state>();
141156/* 74C923 4 by 5 key encoder. */
142
143
144   static UINT8 row=0;
145
146157   /* if previous key is still held, bail out */
147   if (input_port_read(machine, keynames[row]))
148      if (tec1_convert_col_to_bin(input_port_read(machine, keynames[row]), row) == tec1_kbd)
158   if (input_port_read(machine, keynames[state->kbd_row]))
159      if (tec1_convert_col_to_bin(input_port_read(machine, keynames[state->kbd_row]), state->kbd_row) == state->kbd)
149160         return;
150161
151   row++;
152   row &= 3;
162   state->kbd_row++;
163   state->kbd_row &= 3;
153164
154165   /* see if a key pressed */
155   if (input_port_read(machine, keynames[row]))
166   if (input_port_read(machine, keynames[state->kbd_row]))
156167   {
157      tec1_kbd = tec1_convert_col_to_bin(input_port_read(machine, keynames[row]), row);
168      state->kbd = tec1_convert_col_to_bin(input_port_read(machine, keynames[state->kbd_row]), state->kbd_row);
158169      cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, HOLD_LINE);
159170   }
160171}
r9674r9675
168179
169180static MACHINE_START( tec1 )
170181{
171   tec1_kbd_timer = timer_alloc(machine,  tec1_kbd_callback, NULL );
172   timer_adjust_periodic( tec1_kbd_timer, attotime_zero, 0, ATTOTIME_IN_HZ(500) );
173   tec1_speaker = machine->device("speaker");
182   tec1_state *state = machine->driver_data<tec1_state>();
183   state->kbd_timer = timer_alloc(machine,  tec1_kbd_callback, NULL );
184   timer_adjust_periodic( state->kbd_timer, attotime_zero, 0, ATTOTIME_IN_HZ(500) );
185   state->speaker = machine->device("speaker");
174186}
175187
176188static MACHINE_RESET( tec1 )
177189{
178   tec1_kbd = 0;
190   tec1_state *state = machine->driver_data<tec1_state>();
191   state->kbd = 0;
179192}
180193
181194
r9674r9675
243256
244257***************************************************************************/
245258
246static MACHINE_CONFIG_START( tec1, driver_device )
259static MACHINE_CONFIG_START( tec1, tec1_state )
247260   /* basic machine hardware */
248261   MDRV_CPU_ADD("maincpu", Z80, 500000)   /* speed can be varied between 250kHz and 2MHz */
249262   MDRV_CPU_PROGRAM_MAP(tec1_map)
src/mess/drivers/mc80.c
r9674r9675
1414static ADDRESS_MAP_START(mc8020_mem, ADDRESS_SPACE_PROGRAM, 8)
1515   ADDRESS_MAP_UNMAP_HIGH
1616   AM_RANGE(0x0000, 0x0bff) AM_ROM
17   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_BASE(&mc8020_video_ram)// 1KB RAM ZRE
17   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_BASE_MEMBER(mc80_state, mc8020_video_ram)// 1KB RAM ZRE
1818   AM_RANGE(0x2000, 0x5fff) AM_ROM
1919   AM_RANGE(0x6000, 0xffff) AM_RAM
2020ADDRESS_MAP_END
r9674r9675
5454INPUT_PORTS_END
5555
5656
57static MACHINE_CONFIG_START( mc8020, driver_device )
57static MACHINE_CONFIG_START( mc8020, mc80_state )
5858    /* basic machine hardware */
5959    MDRV_CPU_ADD("maincpu",Z80, XTAL_2_4576MHz)
6060    MDRV_CPU_PROGRAM_MAP(mc8020_mem)
r9674r9675
7979   MDRV_Z80CTC_ADD( "z80ctc", XTAL_2_4576MHz / 100, mc8020_ctc_intf )
8080MACHINE_CONFIG_END
8181
82static MACHINE_CONFIG_START( mc8030, driver_device )
82static MACHINE_CONFIG_START( mc8030, mc80_state )
8383    /* basic machine hardware */
8484    MDRV_CPU_ADD("maincpu",Z80, XTAL_2_4576MHz)
8585    MDRV_CPU_PROGRAM_MAP(mc8030_mem)
src/mess/drivers/x1.c
r9674r9675
209209#define VDP_CLOCK  XTAL_42_9545MHz
210210#define MCU_CLOCK  XTAL_6MHz
211211
212static UINT8 hres_320,io_switch,io_sys,vsync,vdisp;
213static UINT8 io_bank_mode;
214static UINT8 *gfx_bitmap_ram;
215static UINT16 pcg_index[3];
216static UINT8 pcg_reset;
217static UINT16 crtc_start_addr;
218static UINT8 tile_height;
219static UINT8 sub_obf;
220UINT8 x1_key_irq_flag;
221static UINT8 ctc_irq_flag;
222static struct
223{
224   UINT8 gfx_bank;
225   UINT8 disp_bank;
226   UINT8 pcg_mode;
227   UINT8 v400_mode;
228212
229   UINT8 ply;
230   UINT8 blackclip; // x1 turbo specific
231}scrn_reg;
232213
233static struct
234{
235   UINT8 pal;
236   UINT8 gfx_pal;
237   UINT8 txt_pal[8];
238   UINT8 txt_disp;
239}turbo_reg;
240214
241static struct
242{
243   UINT8 sec, min, hour, day, wday, month, year;
244}x1_rtc;
245215
246static emu_timer *x1_rtc_timer;
247216
248static UINT8 pcg_write_addr;
249
250217//static DEVICE_START(x1_daisy){}
251218
252static UINT8 *x1_colorram;
253219/*************************************
254220 *
255221 *  Video Functions
r9674r9675
259225static VIDEO_START( x1 )
260226{
261227   x1_state *state = machine->driver_data<x1_state>();
262   x1_colorram = auto_alloc_array(machine, UINT8, 0x1000);
228   state->colorram = auto_alloc_array(machine, UINT8, 0x1000);
263229   state->videoram = auto_alloc_array(machine, UINT8, 0x1000);
264   gfx_bitmap_ram = auto_alloc_array(machine, UINT8, 0xc000*2);
230   state->gfx_bitmap_ram = auto_alloc_array(machine, UINT8, 0xc000*2);
265231}
266232
267233static void draw_fgtilemap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w)
r9674r9675
277243   {
278244      for (x=0;x<40*w;x++)
279245      {
280         int tile = videoram[(x+(y*40*w)+crtc_start_addr) & screen_mask];
281         int color = x1_colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x1f;
282         int width = (x1_colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x80)>>7;
283         int height = (x1_colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x40)>>6;
284         int pcg_bank = (x1_colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x20)>>5;
246         int tile = videoram[(x+(y*40*w)+state->crtc_start_addr) & screen_mask];
247         int color = state->colorram[(x+(y*40*w)+state->crtc_start_addr) & screen_mask] & 0x1f;
248         int width = (state->colorram[(x+(y*40*w)+state->crtc_start_addr) & screen_mask] & 0x80)>>7;
249         int height = (state->colorram[(x+(y*40*w)+state->crtc_start_addr) & screen_mask] & 0x40)>>6;
250         int pcg_bank = (state->colorram[(x+(y*40*w)+state->crtc_start_addr) & screen_mask] & 0x20)>>5;
285251         UINT8 *gfx_data = pcg_bank ? memory_region(machine, "pcg") : memory_region(machine, "cgrom");
286252
287253         /* skip draw if the x/y values are odd and the width/height is active, */
r9674r9675
290256         if((y & 1) == 1 && height) continue;
291257
292258         res_x = (x/(width+1))*8*(width+1);
293         res_y = (y/(height+1))*(tile_height+1)*(height+1);
259         res_y = (y/(height+1))*(state->tile_height+1)*(height+1);
294260
295261         {
296262            int pen[3],pen_mask,pcg_pen,xi,yi;
r9674r9675
298264            pen_mask = color & 7;
299265
300266            /* We use custom drawing code due of the bitplane disable and the color revert stuff. */
301            for(yi=0;yi<(tile_height+1)*(height+1);yi+=(height+1))
267            for(yi=0;yi<(state->tile_height+1)*(height+1);yi+=(height+1))
302268            {
303269               for(xi=0;xi<8*(width+1);xi+=(width+1))
304270               {
r9674r9675
317283                  if(color & 8) //revert the used color pen
318284                     pcg_pen^=7;
319285
320                  if((scrn_reg.blackclip & 8) && (color == (scrn_reg.blackclip & 7)))
286                  if((state->scrn_reg.blackclip & 8) && (color == (state->scrn_reg.blackclip & 7)))
321287                     pcg_pen = 0; // clip the pen to black
322288
323289                  if((res_x+xi)>machine->primary_screen->visible_area().max_x && (res_y+yi)>machine->primary_screen->visible_area().max_y)
324290                     continue;
325291
326                  if(scrn_reg.v400_mode)
292                  if(state->scrn_reg.v400_mode)
327293                  {
328294                     *BITMAP_ADDR16(bitmap, (res_y+yi)*2+0, res_x+xi) = machine->pens[pcg_pen];
329295                     *BITMAP_ADDR16(bitmap, (res_y+yi)*2+1, res_x+xi) = machine->pens[pcg_pen];
r9674r9675
390356
391357static void draw_gfxbitmap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w,int plane,int pri)
392358{
359   x1_state *state = machine->driver_data<x1_state>();
393360   int xi,yi,x,y;
394361   int pen_r,pen_g,pen_b,color;
395362   int pri_mask_val;
r9674r9675
398365   {
399366      for(x=0;x<40*w;x++)
400367      {
401         for(yi=0;yi<(tile_height+1);yi++)
368         for(yi=0;yi<(state->tile_height+1);yi++)
402369         {
403370            for(xi=0;xi<8;xi++)
404371            {
405               pen_b = (gfx_bitmap_ram[(((x+(y*40*w)+yi*0x800)+crtc_start_addr) & 0x3fff)+0x0000+plane*0xc000]>>(7-xi)) & 1;
406               pen_r = (gfx_bitmap_ram[(((x+(y*40*w)+yi*0x800)+crtc_start_addr) & 0x3fff)+0x4000+plane*0xc000]>>(7-xi)) & 1;
407               pen_g = (gfx_bitmap_ram[(((x+(y*40*w)+yi*0x800)+crtc_start_addr) & 0x3fff)+0x8000+plane*0xc000]>>(7-xi)) & 1;
372               pen_b = (state->gfx_bitmap_ram[(((x+(y*40*w)+yi*0x800)+state->crtc_start_addr) & 0x3fff)+0x0000+plane*0xc000]>>(7-xi)) & 1;
373               pen_r = (state->gfx_bitmap_ram[(((x+(y*40*w)+yi*0x800)+state->crtc_start_addr) & 0x3fff)+0x4000+plane*0xc000]>>(7-xi)) & 1;
374               pen_g = (state->gfx_bitmap_ram[(((x+(y*40*w)+yi*0x800)+state->crtc_start_addr) & 0x3fff)+0x8000+plane*0xc000]>>(7-xi)) & 1;
408375
409376               color =  pen_g<<2 | pen_r<<1 | pen_b<<0;
410377
411378               pri_mask_val = priority_mixer_ply(machine,color);
412379               if(pri_mask_val & pri) continue;
413380
414               if(scrn_reg.v400_mode)
381               if(state->scrn_reg.v400_mode)
415382               {
416                  if((x*8+xi)<=machine->primary_screen->visible_area().max_x && (( y*(tile_height+1)+yi)*2+0)<=machine->primary_screen->visible_area().max_y)
417                     *BITMAP_ADDR16(bitmap, ( y*(tile_height+1)+yi)*2+0, x*8+xi) = machine->pens[color+0x100];
418                  if((x*8+xi)<=machine->primary_screen->visible_area().max_x && (( y*(tile_height+1)+yi)*2+1)<=machine->primary_screen->visible_area().max_y)
419                     *BITMAP_ADDR16(bitmap, ( y*(tile_height+1)+yi)*2+1, x*8+xi) = machine->pens[color+0x100];
383                  if((x*8+xi)<=machine->primary_screen->visible_area().max_x && (( y*(state->tile_height+1)+yi)*2+0)<=machine->primary_screen->visible_area().max_y)
384                     *BITMAP_ADDR16(bitmap, ( y*(state->tile_height+1)+yi)*2+0, x*8+xi) = machine->pens[color+0x100];
385                  if((x*8+xi)<=machine->primary_screen->visible_area().max_x && (( y*(state->tile_height+1)+yi)*2+1)<=machine->primary_screen->visible_area().max_y)
386                     *BITMAP_ADDR16(bitmap, ( y*(state->tile_height+1)+yi)*2+1, x*8+xi) = machine->pens[color+0x100];
420387               }
421388               else
422389               {
423                  if((x*8+xi)<=machine->primary_screen->visible_area().max_x && (y*(tile_height+1)+yi)<=machine->primary_screen->visible_area().max_y)
424                     *BITMAP_ADDR16(bitmap, y*(tile_height+1)+yi, x*8+xi) = machine->pens[color+0x100];
390                  if((x*8+xi)<=machine->primary_screen->visible_area().max_x && (y*(state->tile_height+1)+yi)<=machine->primary_screen->visible_area().max_y)
391                     *BITMAP_ADDR16(bitmap, y*(state->tile_height+1)+yi, x*8+xi) = machine->pens[color+0x100];
425392               }
426393            }
427394         }
r9674r9675
433400/* Old code for reference, to be removed soon */
434401static void draw_gfxbitmap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w,int plane,int pri)
435402{
403   x1_state *state = machine->driver_data<x1_state>();
436404   int count,xi,yi,x,y;
437405   int pen_r,pen_g,pen_b,color;
438406   int yi_size;
439407   int pri_mask_val;
440408
441   count = crtc_start_addr;
409   count = state->crtc_start_addr;
442410
443411   yi_size = (w == 1) ? 16 : 8;
444412
r9674r9675
450418         {
451419            for(xi=0;xi<8;xi++)
452420            {
453               pen_b = (gfx_bitmap_ram[count+0x0000+plane*0xc000]>>(7-xi)) & 1;
454               pen_r = (gfx_bitmap_ram[count+0x4000+plane*0xc000]>>(7-xi)) & 1;
455               pen_g = (gfx_bitmap_ram[count+0x8000+plane*0xc000]>>(7-xi)) & 1;
421               pen_b = (state->gfx_bitmap_ram[count+0x0000+plane*0xc000]>>(7-xi)) & 1;
422               pen_r = (state->gfx_bitmap_ram[count+0x4000+plane*0xc000]>>(7-xi)) & 1;
423               pen_g = (state->gfx_bitmap_ram[count+0x8000+plane*0xc000]>>(7-xi)) & 1;
456424
457425               color =  pen_g<<2 | pen_r<<1 | pen_b<<0;
458426
r9674r9675
464432                  if(yi & 1)
465433                     continue;
466434
467                  if(scrn_reg.v400_mode)
435                  if(state->scrn_reg.v400_mode)
468436                  {
469437                     if((x+xi)<=machine->primary_screen->visible_area().max_x && (y+(yi >> 1)*2+0)<=machine->primary_screen->visible_area().max_y)
470438                        *BITMAP_ADDR16(bitmap, (y+(yi >> 1))*2+0, x+xi) = machine->pens[color+0x100];
r9674r9675
479447               }
480448               else
481449               {
482                  if(scrn_reg.v400_mode)
450                  if(state->scrn_reg.v400_mode)
483451                  {
484452                     if((x+xi)<=machine->primary_screen->visible_area().max_x && ((y+yi)*2+0)<=machine->primary_screen->visible_area().max_y)
485453                        *BITMAP_ADDR16(bitmap, (y+yi)*2+0, x+xi) = machine->pens[color+0x100];
r9674r9675
504472
505473static VIDEO_UPDATE( x1 )
506474{
475   x1_state *state = screen->machine->driver_data<x1_state>();
507476   int w;
508477
509478   w = (screen->width() < 640) ? 1 : 2;
510479
511480   bitmap_fill(bitmap, cliprect, MAKE_ARGB(0xff,0x00,0x00,0x00));
512481
513   draw_gfxbitmap(screen->machine,bitmap,cliprect,w,scrn_reg.disp_bank,scrn_reg.ply);
482   draw_gfxbitmap(screen->machine,bitmap,cliprect,w,state->scrn_reg.disp_bank,state->scrn_reg.ply);
514483   draw_fgtilemap(screen->machine,bitmap,cliprect,w);
515   draw_gfxbitmap(screen->machine,bitmap,cliprect,w,scrn_reg.disp_bank,scrn_reg.ply^0xff);
484   draw_gfxbitmap(screen->machine,bitmap,cliprect,w,state->scrn_reg.disp_bank,state->scrn_reg.ply^0xff);
516485   /* Y's uses the following as a normal buffer/work ram without anything reasonable to draw */
517486//  draw_gfxbitmap(screen->machine,bitmap,cliprect,w,1);
518487
r9674r9675
529498 *
530499 *************************************/
531500
532static UINT8 sub_cmd;//,key_flag;
533static UINT8 sub_cmd_length;
534static UINT8 sub_val[8];
535501
536502static UINT8 check_keyboard_press(running_machine *machine)
537503{
r9674r9675
658624
659625static READ8_HANDLER( sub_io_r )
660626{
661   static int sub_val_ptr,key_i = 0;
627   x1_state *state = space->machine->driver_data<x1_state>();
662628   UINT8 ret,bus_res;
663629
664630   /* Looks like that the HW retains the latest data putted on the bus here, behaviour confirmed by Rally-X */
665   if(sub_obf)
631   if(state->sub_obf)
666632   {
667      bus_res = sub_val[key_i];
633      bus_res = state->sub_val[state->key_i];
668634      /* FIXME: likely to be different here. */
669      key_i++;
670      if(key_i >= 2) { key_i = 0; }
635      state->key_i++;
636      if(state->key_i >= 2) { state->key_i = 0; }
671637
672638      return bus_res;
673639   }
r9674r9675
680646   }
681647#endif
682648
683   sub_cmd_length--;
684   sub_obf = (sub_cmd_length) ? 0x00 : 0x20;
649   state->sub_cmd_length--;
650   state->sub_obf = (state->sub_cmd_length) ? 0x00 : 0x20;
685651
686   ret = sub_val[sub_val_ptr];
652   ret = state->sub_val[state->sub_val_ptr];
687653
688   sub_val_ptr++;
689   if(sub_cmd_length <= 0)
690      sub_val_ptr = 0;
654   state->sub_val_ptr++;
655   if(state->sub_cmd_length <= 0)
656      state->sub_val_ptr = 0;
691657
692658   return ret;
693659}
694660
695static UINT8 x1_irq_vector;
696661//static UINT8 ctc_irq_vector; //always 0x5e?
697UINT8 x1_key_irq_vector;
698static UINT8 cmt_current_cmd;
699static UINT8 cmt_test;
700662
701663static void cmt_command( running_machine* machine, UINT8 cmd )
702664{
665   x1_state *state = machine->driver_data<x1_state>();
703666   // CMT deck control command (E9 xx)
704667   // E9 00 - Eject
705668   // E9 01 - Stop
r9674r9675
709672   // E9 05 - APSS(?) Fast Forward
710673   // E9 06 - APSS(?) Rewind
711674   // E9 0A - Record
712   cmt_current_cmd = cmd;
675   state->cmt_current_cmd = cmd;
713676
714677   switch(cmd)
715678   {
716679      case 0x01:  // Stop
717680         cassette_change_state(machine->device("cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR);
718681         cassette_change_state(machine->device("cass" ),CASSETTE_STOPPED,CASSETTE_MASK_UISTATE);
719         cmt_test = 1;
682         state->cmt_test = 1;
720683         popmessage("CMT: Stop");
721684         break;
722685      case 0x02:  // Play
r9674r9675
757720
758721static TIMER_CALLBACK( cmt_wind_timer )
759722{
723   x1_state *state = machine->driver_data<x1_state>();
760724   running_device* cmt = machine->device("cass");
761   switch(cmt_current_cmd)
725   switch(state->cmt_current_cmd)
762726   {
763727      case 0x03:
764728      case 0x05:  // Fast Forwarding tape
r9674r9675
777741
778742static WRITE8_HANDLER( sub_io_w )
779743{
744   x1_state *state = space->machine->driver_data<x1_state>();
780745   /* TODO: check sub-routine at $10e */
781746   /* $17a -> floppy? */
782747   /* $094 -> ROM */
r9674r9675
784749   /* $052 -> cmt */
785750   /* $0f5 -> reload sub-routine? */
786751
787   if(sub_cmd == 0xe4)
752   if(state->sub_cmd == 0xe4)
788753   {
789      x1_key_irq_vector = data;
754      state->key_irq_vector = data;
790755      logerror("Key vector set to 0x%02x\n",data);
791756   }
792757
793   if(sub_cmd == 0xe9)
758   if(state->sub_cmd == 0xe9)
794759      cmt_command(space->machine,data);
795760
796761   if((data & 0xf0) == 0xd0) //reads here tv recording timer data.
797762   {
798      sub_val[0] = 0;
799      sub_val[1] = 0;
800      sub_val[2] = 0;
801      sub_val[3] = 0;
802      sub_val[4] = 0;
803      sub_val[5] = 0;
804      sub_cmd_length = 6;
763      state->sub_val[0] = 0;
764      state->sub_val[1] = 0;
765      state->sub_val[2] = 0;
766      state->sub_val[3] = 0;
767      state->sub_val[4] = 0;
768      state->sub_val[5] = 0;
769      state->sub_cmd_length = 6;
805770   }
806771
807772   switch(data)
808773   {
809774      case 0xe3:
810         sub_cmd_length = 3;
811         sub_val[0] = get_game_key(space->machine,0);
812         sub_val[1] = get_game_key(space->machine,1);
813         sub_val[2] = get_game_key(space->machine,2);
775         state->sub_cmd_length = 3;
776         state->sub_val[0] = get_game_key(space->machine,0);
777         state->sub_val[1] = get_game_key(space->machine,1);
778         state->sub_val[2] = get_game_key(space->machine,2);
814779         break;
815780      case 0xe6:
816         sub_val[0] = check_keyboard_shift(space->machine);
817         sub_val[1] = check_keyboard_press(space->machine);
818         sub_cmd_length = 2;
781         state->sub_val[0] = check_keyboard_shift(space->machine);
782         state->sub_val[1] = check_keyboard_press(space->machine);
783         state->sub_cmd_length = 2;
819784         break;
820785      case 0xe8:
821         sub_val[0] = sub_cmd;
822         sub_cmd_length = 1;
786         state->sub_val[0] = state->sub_cmd;
787         state->sub_cmd_length = 1;
823788         break;
824789      case 0xea:  // CMT Control status
825         sub_val[0] = cmt_current_cmd;
826         sub_cmd_length = 1;
827         logerror("CMT: Command 0xEA received, returning 0x%02x.\n",sub_val[0]);
790         state->sub_val[0] = state->cmt_current_cmd;
791         state->sub_cmd_length = 1;
792         logerror("CMT: Command 0xEA received, returning 0x%02x.\n",state->sub_val[0]);
828793         break;
829794      case 0xeb:  // CMT Tape status
830795                  // bit 0 = tape end (0=end of tape)
831796               // bit 1 = tape inserted
832797               // bit 2 = record status (1=OK, 0=write protect?)
833         sub_val[0] = 0x05;
798         state->sub_val[0] = 0x05;
834799         if(cassette_get_image(space->machine->device("cass")) != NULL)
835            sub_val[0] |= 0x02;
836         sub_cmd_length = 1;
837         logerror("CMT: Command 0xEB received, returning 0x%02x.\n",sub_val[0]);
800            state->sub_val[0] |= 0x02;
801         state->sub_cmd_length = 1;
802         logerror("CMT: Command 0xEB received, returning 0x%02x.\n",state->sub_val[0]);
838803         break;
839804      case 0xed: //get date
840         sub_val[0] = x1_rtc.day;
841         sub_val[1] = (x1_rtc.month<<4) | (x1_rtc.wday & 0xf);
842         sub_val[2] = x1_rtc.year;
843         sub_cmd_length = 3;
805         state->sub_val[0] = state->rtc.day;
806         state->sub_val[1] = (state->rtc.month<<4) | (state->rtc.wday & 0xf);
807         state->sub_val[2] = state->rtc.year;
808         state->sub_cmd_length = 3;
844809         break;
845810      case 0xef: //get time
846         sub_val[0] = x1_rtc.hour;
847         sub_val[1] = x1_rtc.min;
848         sub_val[2] = x1_rtc.sec;
849         sub_cmd_length = 3;
811         state->sub_val[0] = state->rtc.hour;
812         state->sub_val[1] = state->rtc.min;
813         state->sub_val[2] = state->rtc.sec;
814         state->sub_cmd_length = 3;
850815         break;
851816      #if 0
852817      default:
r9674r9675
857822      #endif
858823   }
859824
860   sub_cmd = data;
825   state->sub_cmd = data;
861826
862   sub_obf = (sub_cmd_length) ? 0x00 : 0x20;
827   state->sub_obf = (state->sub_cmd_length) ? 0x00 : 0x20;
863828   logerror("SUB: Command byte 0x%02x\n",data);
864829}
865830
r9674r9675
869834 *
870835 *************************************/
871836
872static UINT8 rom_index[3];
873837
874838static READ8_HANDLER( x1_rom_r )
875839{
840   x1_state *state = space->machine->driver_data<x1_state>();
876841   UINT8 *rom = memory_region(space->machine, "cart_img");
877842
878//  printf("%06x\n",rom_index[0]<<16|rom_index[1]<<8|rom_index[2]<<0);
843//  printf("%06x\n",state->rom_index[0]<<16|state->rom_index[1]<<8|state->rom_index[2]<<0);
879844
880   return rom[rom_index[0]<<16|rom_index[1]<<8|rom_index[2]<<0];
845   return rom[state->rom_index[0]<<16|state->rom_index[1]<<8|state->rom_index[2]<<0];
881846}
882847
883848static WRITE8_HANDLER( x1_rom_w )
884849{
885   rom_index[offset] = data;
850   x1_state *state = space->machine->driver_data<x1_state>();
851   state->rom_index[offset] = data;
886852}
887853
888854static WRITE8_HANDLER( rom_bank_0_w )
r9674r9675
1005971
1006972static UINT16 check_pcg_addr(running_machine *machine)
1007973{
1008   if(x1_colorram[0x7ff] & 0x20) return 0x7ff;
1009   if(x1_colorram[0x3ff] & 0x20) return 0x3ff;
1010   if(x1_colorram[0x5ff] & 0x20) return 0x5ff;
1011   if(x1_colorram[0x1ff] & 0x20) return 0x1ff;
974   x1_state *state = machine->driver_data<x1_state>();
975   if(state->colorram[0x7ff] & 0x20) return 0x7ff;
976   if(state->colorram[0x3ff] & 0x20) return 0x3ff;
977   if(state->colorram[0x5ff] & 0x20) return 0x5ff;
978   if(state->colorram[0x1ff] & 0x20) return 0x1ff;
1012979
1013980   return 0x3ff;
1014981}
1015982
1016983static UINT16 check_chr_addr(running_machine *machine)
1017984{
1018   if(!(x1_colorram[0x7ff] & 0x20)) return 0x7ff;
1019   if(!(x1_colorram[0x3ff] & 0x20)) return 0x3ff;
1020   if(!(x1_colorram[0x5ff] & 0x20)) return 0x5ff;
1021   if(!(x1_colorram[0x1ff] & 0x20)) return 0x1ff;
985   x1_state *state = machine->driver_data<x1_state>();
986   if(!(state->colorram[0x7ff] & 0x20)) return 0x7ff;
987   if(!(state->colorram[0x3ff] & 0x20)) return 0x3ff;
988   if(!(state->colorram[0x5ff] & 0x20)) return 0x5ff;
989   if(!(state->colorram[0x1ff] & 0x20)) return 0x1ff;
1022990
1023991   return 0x3ff;
1024992}
r9674r9675
1029997   UINT8 *videoram = state->videoram;
1030998   int addr;
1031999   int calc_pcg_offset;
1032   static UINT32 kanji_offset;
1033   static UINT8 bios_offset,pcg_index_r[3];
10341000   UINT8 res;
10351001   UINT8 *gfx_data;
10361002
10371003   addr = (offset & 0x300) >> 8;
10381004
1039   if(pcg_reset)
1005   if(state->pcg_reset)
10401006   {
1041      pcg_index_r[0] = pcg_index_r[1] = pcg_index_r[2] = bios_offset = 0;
1042      pcg_reset = 0;
1007      state->pcg_index_r[0] = state->pcg_index_r[1] = state->pcg_index_r[2] = state->bios_offset = 0;
1008      state->pcg_reset = 0;
10431009   }
10441010
10451011   if(addr == 0)
10461012   {
1047      if(scrn_reg.pcg_mode)
1013      if(state->scrn_reg.pcg_mode)
10481014      {
10491015         gfx_data = memory_region(space->machine, "kanji");
10501016         calc_pcg_offset = (videoram[check_chr_addr(space->machine)]+(videoram[check_chr_addr(space->machine)+0x800]<<8)) & 0xfff;
10511017
1052         kanji_offset = calc_pcg_offset*0x20;
1018         state->kanji_offset = calc_pcg_offset*0x20;
10531019
1054         res = gfx_data[0x0000+bios_offset+kanji_offset];
1020         res = gfx_data[0x0000+state->bios_offset+state->kanji_offset];
10551021
1056         bios_offset++;
1057         bios_offset&=0x1f;
1022         state->bios_offset++;
1023         state->bios_offset&=0x1f;
10581024      }
10591025      else
10601026      {
1061//          printf("%04x %04x %02x\n",pcg_write_addr*4*8,pcg_write_addr,bios_offset);
1027//          printf("%04x %04x %02x\n",state->pcg_write_addr*4*8,state->pcg_write_addr,state->bios_offset);
10621028         gfx_data = memory_region(space->machine, "kanji");
1063         if(bios_offset == 0)
1064            kanji_offset = pcg_write_addr*4*8;//TODO: check me
1029         if(state->bios_offset == 0)
1030            state->kanji_offset = state->pcg_write_addr*4*8;//TODO: check me
10651031
1066         res = gfx_data[0x0000+bios_offset+kanji_offset];
1032         res = gfx_data[0x0000+state->bios_offset+state->kanji_offset];
10671033
1068         bios_offset++;
1069         bios_offset&=0x1f;
1034         state->bios_offset++;
1035         state->bios_offset&=0x1f;
10701036      }
10711037      return res;
10721038   }
10731039   else
10741040   {
10751041      gfx_data = memory_region(space->machine, "pcg");
1076      calc_pcg_offset = (pcg_index_r[addr-1]) | ((addr-1)*0x800);
1077      res = gfx_data[0x0000+calc_pcg_offset+(pcg_write_addr*8)];
1042      calc_pcg_offset = (state->pcg_index_r[addr-1]) | ((addr-1)*0x800);
1043      res = gfx_data[0x0000+calc_pcg_offset+(state->pcg_write_addr*8)];
10781044
1079      pcg_index_r[addr-1]++;
1080      pcg_index_r[addr-1]&=0x7;
1045      state->pcg_index_r[addr-1]++;
1046      state->pcg_index_r[addr-1]&=0x7;
10811047      return res;
10821048   }
10831049
r9674r9675
10901056   UINT8 *videoram = state->videoram;
10911057   int addr,pcg_offset;
10921058   UINT8 *PCG_RAM = memory_region(space->machine, "pcg");
1093   static UINT16 used_pcg_addr;
10941059
10951060   addr = (offset & 0x300) >> 8;
10961061
1097   if(pcg_reset)
1062   if(state->pcg_reset)
10981063   {
1099      pcg_index[0] = pcg_index[1] = pcg_index[2] = 0;
1100      pcg_reset = 0;
1064      state->pcg_index[0] = state->pcg_index[1] = state->pcg_index[2] = 0;
1065      state->pcg_reset = 0;
11011066   }
11021067
11031068   if(addr == 0)
r9674r9675
11071072   }
11081073   else
11091074   {
1110      if(scrn_reg.pcg_mode)
1075      if(state->scrn_reg.pcg_mode)
11111076      {
1112         used_pcg_addr = videoram[check_pcg_addr(space->machine)]*8;
1113         pcg_index[addr-1] = (offset & 0xe) >> 1;
1114         pcg_offset = (pcg_index[addr-1]+used_pcg_addr) & 0x7ff;
1077         state->used_pcg_addr = videoram[check_pcg_addr(space->machine)]*8;
1078         state->pcg_index[addr-1] = (offset & 0xe) >> 1;
1079         pcg_offset = (state->pcg_index[addr-1]+state->used_pcg_addr) & 0x7ff;
11151080         pcg_offset+=((addr-1)*0x800);
11161081         PCG_RAM[pcg_offset] = data;
11171082
r9674r9675
11221087      else
11231088      {
11241089         /* TODO: understand what 1942, Herzog and friends wants there */
1125         used_pcg_addr = pcg_write_addr*8;
1126         pcg_offset = (pcg_index[addr-1]+used_pcg_addr) & 0x7ff;
1090         state->used_pcg_addr = state->pcg_write_addr*8;
1091         pcg_offset = (state->pcg_index[addr-1]+state->used_pcg_addr) & 0x7ff;
11271092         pcg_offset+=((addr-1)*0x800);
11281093         PCG_RAM[pcg_offset] = data;
11291094
r9674r9675
11311096
11321097          gfx_element_mark_dirty(space->machine->gfx[1], pcg_offset >> 3);
11331098
1134         pcg_index[addr-1]++;
1135         pcg_index[addr-1]&=7;
1099         state->pcg_index[addr-1]++;
1100         state->pcg_index[addr-1]&=7;
11361101      }
11371102   }
11381103}
r9674r9675
11441109 *************************************/
11451110
11461111/* for bitmap mode */
1147static UINT8 x_b,x_g,x_r;
11481112
11491113static void set_current_palette(running_machine *machine)
11501114{
1115   x1_state *state = machine->driver_data<x1_state>();
11511116   UINT8 addr,r,g,b;
11521117
11531118   for(addr=0;addr<8;addr++)
11541119   {
1155      r = ((x_r)>>(addr)) & 1;
1156      g = ((x_g)>>(addr)) & 1;
1157      b = ((x_b)>>(addr)) & 1;
1120      r = ((state->x_r)>>(addr)) & 1;
1121      g = ((state->x_g)>>(addr)) & 1;
1122      b = ((state->x_b)>>(addr)) & 1;
11581123
11591124      palette_set_color_rgb(machine, addr+0x100, pal1bit(r), pal1bit(g), pal1bit(b));
11601125   }
11611126}
11621127
1163static WRITE8_HANDLER( x1_pal_r_w ) { x_r = data; set_current_palette(space->machine); }
1164static WRITE8_HANDLER( x1_pal_g_w ) { x_g = data; set_current_palette(space->machine); }
1165static WRITE8_HANDLER( x1_pal_b_w ) { x_b = data; set_current_palette(space->machine); }
1128static WRITE8_HANDLER( x1_pal_r_w )
1129{
1130   x1_state *state = space->machine->driver_data<x1_state>();
1131   state->x_r = data;
1132   set_current_palette(space->machine);
1133}
11661134
1135static WRITE8_HANDLER( x1_pal_g_w )
1136{
1137   x1_state *state = space->machine->driver_data<x1_state>();
1138   state->x_g = data;
1139   set_current_palette(space->machine);
1140}
1141
1142static WRITE8_HANDLER( x1_pal_b_w )
1143{
1144   x1_state *state = space->machine->driver_data<x1_state>();
1145   state->x_b = data;
1146   set_current_palette(space->machine);
1147}
1148
11671149static WRITE8_HANDLER( x1_ex_gfxram_w )
11681150{
1151   x1_state *state = space->machine->driver_data<x1_state>();
11691152   UINT8 ex_mask;
11701153
11711154   if     (offset >= 0x0000 && offset <= 0x3fff)   { ex_mask = 7; }
r9674r9675
11731156   else if(offset >= 0x8000 && offset <= 0xbfff)   { ex_mask = 5; }
11741157   else                                           { ex_mask = 3; }
11751158
1176   if(ex_mask & 1) { gfx_bitmap_ram[(offset & 0x3fff)+0x0000+(scrn_reg.gfx_bank*0xc000)] = data; }
1177   if(ex_mask & 2) { gfx_bitmap_ram[(offset & 0x3fff)+0x4000+(scrn_reg.gfx_bank*0xc000)] = data; }
1178   if(ex_mask & 4) { gfx_bitmap_ram[(offset & 0x3fff)+0x8000+(scrn_reg.gfx_bank*0xc000)] = data; }
1159   if(ex_mask & 1) { state->gfx_bitmap_ram[(offset & 0x3fff)+0x0000+(state->scrn_reg.gfx_bank*0xc000)] = data; }
1160   if(ex_mask & 2) { state->gfx_bitmap_ram[(offset & 0x3fff)+0x4000+(state->scrn_reg.gfx_bank*0xc000)] = data; }
1161   if(ex_mask & 4) { state->gfx_bitmap_ram[(offset & 0x3fff)+0x8000+(state->scrn_reg.gfx_bank*0xc000)] = data; }
11791162}
11801163
11811164/*
r9674r9675
11951178*/
11961179static WRITE8_HANDLER( x1_scrn_w )
11971180{
1198   scrn_reg.pcg_mode = (data & 0x20)>>5;
1199   scrn_reg.gfx_bank = (data & 0x10)>>4;
1200   scrn_reg.disp_bank = (data & 0x08)>>3;
1201   scrn_reg.v400_mode = ((data & 0x03) == 3) ? 1 : 0;
1181   x1_state *state = space->machine->driver_data<x1_state>();
1182   state->scrn_reg.pcg_mode = (data & 0x20)>>5;
1183   state->scrn_reg.gfx_bank = (data & 0x10)>>4;
1184   state->scrn_reg.disp_bank = (data & 0x08)>>3;
1185   state->scrn_reg.v400_mode = ((data & 0x03) == 3) ? 1 : 0;
12021186   if(data & 0xc4)
12031187      printf("SCRN = %02x\n",data & 0xc4);
12041188}
12051189
12061190static WRITE8_HANDLER( x1_ply_w )
12071191{
1208   scrn_reg.ply = data;
1192   x1_state *state = space->machine->driver_data<x1_state>();
1193   state->scrn_reg.ply = data;
12091194//  printf("PLY = %02x\n",data);
12101195}
12111196
12121197static WRITE8_HANDLER( x1_6845_w )
12131198{
1214   static int addr_latch;
1215
1199   x1_state *state = space->machine->driver_data<x1_state>();
12161200   if(offset == 0)
12171201   {
1218      addr_latch = data;
1202      state->addr_latch = data;
12191203      mc6845_address_w(space->machine->device("crtc"), 0,data);
12201204   }
12211205   else
12221206   {
12231207      /* FIXME: this should be inside the MC6845 core! */
1224      if(addr_latch == 0x09)
1225         tile_height = data;
1226      if(addr_latch == 0x0c)
1227         crtc_start_addr = ((data<<8) & 0x3f00) | (crtc_start_addr & 0xff);
1228      else if(addr_latch == 0x0d)
1229         crtc_start_addr = (crtc_start_addr & 0x3f00) | (data & 0xff);
1208      if(state->addr_latch == 0x09)
1209         state->tile_height = data;
1210      if(state->addr_latch == 0x0c)
1211         state->crtc_start_addr = ((data<<8) & 0x3f00) | (state->crtc_start_addr & 0xff);
1212      else if(state->addr_latch == 0x0d)
1213         state->crtc_start_addr = (state->crtc_start_addr & 0x3f00) | (data & 0xff);
12301214
12311215      mc6845_register_w(space->machine->device("crtc"), 0,data);
12321216
r9674r9675
12371221
12381222static READ8_HANDLER( x1_blackclip_r )
12391223{
1240   return scrn_reg.blackclip;
1224   x1_state *state = space->machine->driver_data<x1_state>();
1225   return state->scrn_reg.blackclip;
12411226}
12421227
12431228static WRITE8_HANDLER( x1_blackclip_w )
12441229{
1245   scrn_reg.blackclip = data;
1230   x1_state *state = space->machine->driver_data<x1_state>();
1231   state->scrn_reg.blackclip = data;
12461232}
12471233
1248static READ8_HANDLER( x1turbo_pal_r )    { return turbo_reg.pal; }
1249static READ8_HANDLER( x1turbo_txpal_r )  { return turbo_reg.txt_pal[offset]; }
1250static READ8_HANDLER( x1turbo_txdisp_r ) { return turbo_reg.txt_disp; }
1251static READ8_HANDLER( x1turbo_gfxpal_r ) { return turbo_reg.gfx_pal; }
1234static READ8_HANDLER( x1turbo_pal_r )
1235{
1236   x1_state *state = space->machine->driver_data<x1_state>();
1237   return state->turbo_reg.pal;
1238}
12521239
1240static READ8_HANDLER( x1turbo_txpal_r )
1241{
1242   x1_state *state = space->machine->driver_data<x1_state>();
1243   return state->turbo_reg.txt_pal[offset];
1244}
1245
1246static READ8_HANDLER( x1turbo_txdisp_r )
1247{
1248   x1_state *state = space->machine->driver_data<x1_state>();
1249   return state->turbo_reg.txt_disp;
1250}
1251
1252static READ8_HANDLER( x1turbo_gfxpal_r )
1253{
1254   x1_state *state = space->machine->driver_data<x1_state>();
1255   return state->turbo_reg.gfx_pal;
1256}
1257
12531258static WRITE8_HANDLER( x1turbo_pal_w )
12541259{
1260   x1_state *state = space->machine->driver_data<x1_state>();
12551261   printf("TURBO PAL %02x\n",data);
1256   turbo_reg.pal = data;
1262   state->turbo_reg.pal = data;
12571263}
12581264
12591265static WRITE8_HANDLER( x1turbo_txpal_w )
12601266{
1267   x1_state *state = space->machine->driver_data<x1_state>();
12611268   int r,g,b;
12621269
12631270   printf("TURBO TEXT PAL %02x %02x\n",data,offset);
1264   turbo_reg.txt_pal[offset] = data;
1271   state->turbo_reg.txt_pal[offset] = data;
12651272
1266   if(turbo_reg.pal & 0x80)
1273   if(state->turbo_reg.pal & 0x80)
12671274   {
12681275      r = (data & 0x0c) >> 2;
12691276      g = (data & 0x30) >> 4;
r9674r9675
12751282
12761283static WRITE8_HANDLER( x1turbo_txdisp_w )
12771284{
1285   x1_state *state = space->machine->driver_data<x1_state>();
12781286   printf("TURBO TEXT DISPLAY %02x\n",data);
1279   turbo_reg.txt_disp = data;
1287   state->turbo_reg.txt_disp = data;
12801288}
12811289
12821290static WRITE8_HANDLER( x1turbo_gfxpal_w )
12831291{
1292   x1_state *state = space->machine->driver_data<x1_state>();
12841293   printf("TURBO GFX PAL %02x\n",data);
1285   turbo_reg.gfx_pal = data;
1294   state->turbo_reg.gfx_pal = data;
12861295}
12871296
1288static UINT8 kanji_addr_l,kanji_addr_h,kanji_count;
1289static UINT32 kanji_addr;
12901297
12911298/*
12921299 *  FIXME: this makes no sense atm, the only game that uses this function so far is Hyper Olympics '84 disk version
12931300 */
12941301static READ8_HANDLER( x1_kanji_r )
12951302{
1303   x1_state *state = space->machine->driver_data<x1_state>();
12961304   UINT8 *kanji_rom = memory_region(space->machine, "kanji");
12971305   UINT8 res;
12981306
12991307   //res = 0;
13001308
1301   printf("%08x\n",kanji_addr*0x20+kanji_count);
1309   printf("%08x\n",state->kanji_addr*0x20+state->kanji_count);
13021310
1303   res = kanji_rom[(kanji_addr*0x20)+(kanji_count)];
1304   kanji_count++;
1305   kanji_count&=0x1f;
1311   res = kanji_rom[(state->kanji_addr*0x20)+(state->kanji_count)];
1312   state->kanji_count++;
1313   state->kanji_count&=0x1f;
13061314
13071315   //printf("%04x R\n",offset);
13081316
r9674r9675
13111319
13121320static WRITE8_HANDLER( x1_kanji_w )
13131321{
1322   x1_state *state = space->machine->driver_data<x1_state>();
13141323//  if(offset < 2)
13151324      printf("%04x %02x W\n",offset,data);
13161325
13171326   switch(offset)
13181327   {
1319      case 0: kanji_addr_l = (data & 0xff); break;
1320      case 1: kanji_addr_h = (data & 0xff); kanji_count = 0; break;
1328      case 0: state->kanji_addr_l = (data & 0xff); break;
1329      case 1: state->kanji_addr_h = (data & 0xff); state->kanji_count = 0; break;
13211330      case 2:
13221331         if(data)
13231332         {
1324            kanji_addr = (kanji_addr_h<<8) | (kanji_addr_l);
1325            //kanji_addr &= 0x3fff; //<- temp kludge until the rom is redumped.
1326            //printf("%08x\n",kanji_addr);
1327            //kanji_addr+= kanji_count;
1333            state->kanji_addr = (state->kanji_addr_h<<8) | (state->kanji_addr_l);
1334            //state->kanji_addr &= 0x3fff; //<- temp kludge until the rom is redumped.
1335            //printf("%08x\n",state->kanji_addr);
1336            //state->kanji_addr+= state->kanji_count;
13281337         }
13291338         break;
13301339   }
r9674r9675
13401349{
13411350   x1_state *state = space->machine->driver_data<x1_state>();
13421351   UINT8 *videoram = state->videoram;
1343   io_bank_mode = 0; //any read disables the extended mode.
1352   state->io_bank_mode = 0; //any read disables the extended mode.
13441353
13451354   //if(offset >= 0x0704 && offset <= 0x0707)      { return z80ctc_r(space->machine->device("ctc"), offset-0x0704); }
13461355   if(offset == 0x0e03)                          { return x1_rom_r(space, 0); }
r9674r9675
13561365   else if(offset >= 0x1fa8 && offset <= 0x1fab)   { return z80ctc_r(space->machine->device("ctc"), offset-0x1fa8); }
13571366//  else if(offset >= 0x1fd0 && offset <= 0x1fdf)   { return x1_scrn_r(space,offset-0x1fd0); }
13581367//  else if(offset == 0x1fe0)                       { return x1_blackclip_r(space,0); }
1359   else if(offset >= 0x2000 && offset <= 0x2fff)   { return x1_colorram[offset-0x2000]; }
1368   else if(offset >= 0x2000 && offset <= 0x2fff)   { return state->colorram[offset-0x2000]; }
13601369   else if(offset >= 0x3000 && offset <= 0x3fff)   { return videoram[offset-0x3000]; }
1361   else if(offset >= 0x4000 && offset <= 0xffff)   { return gfx_bitmap_ram[offset-0x4000+(scrn_reg.gfx_bank*0xc000)]; }
1370   else if(offset >= 0x4000 && offset <= 0xffff)   { return state->gfx_bitmap_ram[offset-0x4000+(state->scrn_reg.gfx_bank*0xc000)]; }
13621371   else
13631372   {
13641373      logerror("(PC=%06x) Read i/o address %04x\n",cpu_get_pc(space->cpu),offset);
r9674r9675
13701379{
13711380   x1_state *state = space->machine->driver_data<x1_state>();
13721381   UINT8 *videoram = state->videoram;
1373   if(io_bank_mode == 1)                          { x1_ex_gfxram_w(space, offset, data); }
1382   if(state->io_bank_mode == 1)                          { x1_ex_gfxram_w(space, offset, data); }
13741383//  else if(offset >= 0x0704 && offset <= 0x0707)   { z80ctc_w(space->machine->device("ctc"), offset-0x0704,data); }
13751384//  else if(offset >= 0x0c00 && offset <= 0x0cff)   { x1_rs232c_w(space->machine, 0, data); }
13761385   else if(offset >= 0x0e00 && offset <= 0x0e02)   { x1_rom_w(space, offset-0xe00,data); }
r9674r9675
13991408//  else if(offset == 0x1fc5)                       { x1turbo_gfxpal_w(space,0,data); }
14001409   else if(offset >= 0x1fd0 && offset <= 0x1fdf)   { x1_scrn_w(space,0,data); }
14011410//  else if(offset == 0x1fe0)                       { x1_blackclip_w(space,0,data); }
1402   else if(offset >= 0x2000 && offset <= 0x2fff)   { x1_colorram[offset-0x2000] = data; }
1403   else if(offset >= 0x3000 && offset <= 0x3fff)   { videoram[offset-0x3000] = pcg_write_addr = data; }
1404   else if(offset >= 0x4000 && offset <= 0xffff)   { gfx_bitmap_ram[offset-0x4000+(scrn_reg.gfx_bank*0xc000)] = data; }
1411   else if(offset >= 0x2000 && offset <= 0x2fff)   { state->colorram[offset-0x2000] = data; }
1412   else if(offset >= 0x3000 && offset <= 0x3fff)   { videoram[offset-0x3000] = state->pcg_write_addr = data; }
1413   else if(offset >= 0x4000 && offset <= 0xffff)   { state->gfx_bitmap_ram[offset-0x4000+(state->scrn_reg.gfx_bank*0xc000)] = data; }
14051414   else
14061415   {
14071416      logerror("(PC=%06x) Write %02x at i/o address %04x\n",cpu_get_pc(space->cpu),data,offset);
r9674r9675
14121421{
14131422   x1_state *state = space->machine->driver_data<x1_state>();
14141423   UINT8 *videoram = state->videoram;
1415   io_bank_mode = 0; //any read disables the extended mode.
1424   state->io_bank_mode = 0; //any read disables the extended mode.
14161425
14171426   if(offset == 0x0700)                     { return (ym2151_r(space->machine->device("ym"), offset-0x0700) & 0x7f) | (input_port_read(space->machine, "SOUND_SW") & 0x80); }
14181427   else if(offset == 0x0701)                      { return ym2151_r(space->machine->device("ym"), offset-0x0700); }
r9674r9675
14351444   else if(offset == 0x1fc5)                  { return x1turbo_gfxpal_r(space,0); }
14361445//  else if(offset >= 0x1fd0 && offset <= 0x1fdf)   { return x1_scrn_r(space,offset-0x1fd0); }
14371446   else if(offset == 0x1fe0)                  { return x1_blackclip_r(space,0); }
1438   else if(offset >= 0x2000 && offset <= 0x2fff)   { return x1_colorram[offset-0x2000]; }
1447   else if(offset >= 0x2000 && offset <= 0x2fff)   { return state->colorram[offset-0x2000]; }
14391448   else if(offset >= 0x3000 && offset <= 0x3fff)   { return videoram[offset-0x3000]; }
1440   else if(offset >= 0x4000 && offset <= 0xffff)   { return gfx_bitmap_ram[offset-0x4000+(scrn_reg.gfx_bank*0xc000)]; }
1449   else if(offset >= 0x4000 && offset <= 0xffff)   { return state->gfx_bitmap_ram[offset-0x4000+(state->scrn_reg.gfx_bank*0xc000)]; }
14411450   else
14421451   {
14431452      //0xfd0-0xfd7: FDC extended area?
r9674r9675
14511460{
14521461   x1_state *state = space->machine->driver_data<x1_state>();
14531462   UINT8 *videoram = state->videoram;
1454   if(io_bank_mode == 1)                          { x1_ex_gfxram_w(space, offset, data); }
1463   if(state->io_bank_mode == 1)                          { x1_ex_gfxram_w(space, offset, data); }
14551464   else if(offset == 0x0700 || offset == 0x0701)   { ym2151_w(space->machine->device("ym"), offset-0x0700,data); }
14561465   else if(offset >= 0x0704 && offset <= 0x0707)   { z80ctc_w(space->machine->device("ctc"), offset-0x0704,data); }
14571466//  else if(offset >= 0x0c00 && offset <= 0x0cff)   { x1_rs232c_w(space->machine, 0, data); }
r9674r9675
14811490   else if(offset == 0x1fc5)                  { x1turbo_gfxpal_w(space,0,data); }
14821491   else if(offset >= 0x1fd0 && offset <= 0x1fdf)   { x1_scrn_w(space,0,data); }
14831492   else if(offset == 0x1fe0)                  { x1_blackclip_w(space,0,data); }
1484   else if(offset >= 0x2000 && offset <= 0x2fff)   { x1_colorram[offset-0x2000] = data; }
1485   else if(offset >= 0x3000 && offset <= 0x3fff)   { videoram[offset-0x3000] = pcg_write_addr = data; }
1486   else if(offset >= 0x4000 && offset <= 0xffff)   { gfx_bitmap_ram[offset-0x4000+(scrn_reg.gfx_bank*0xc000)] = data; }
1493   else if(offset >= 0x2000 && offset <= 0x2fff)   { state->colorram[offset-0x2000] = data; }
1494   else if(offset >= 0x3000 && offset <= 0x3fff)   { videoram[offset-0x3000] = state->pcg_write_addr = data; }
1495   else if(offset >= 0x4000 && offset <= 0xffff)   { state->gfx_bitmap_ram[offset-0x4000+(state->scrn_reg.gfx_bank*0xc000)] = data; }
14871496   else
14881497   {
14891498      logerror("(PC=%06x) Write %02x at i/o address %04x\n",cpu_get_pc(space->cpu),data,offset);
r9674r9675
15221531/* this port is system related */
15231532static READ8_DEVICE_HANDLER( x1_portb_r )
15241533{
1534   x1_state *state = device->machine->driver_data<x1_state>();
15251535   //printf("PPI Port B read\n");
15261536   /*
15271537    x--- ---- "v disp"
r9674r9675
15341544    ---- ---x "cmt test" (active low)
15351545    */
15361546   UINT8 dat = 0;
1537   vdisp = (device->machine->primary_screen->vpos() < 200) ? 0x80 : 0x00;
1538   dat = (input_port_read(device->machine, "SYSTEM") & 0x10) | sub_obf | vsync | vdisp;
1547   state->vdisp = (device->machine->primary_screen->vpos() < 200) ? 0x80 : 0x00;
1548   dat = (input_port_read(device->machine, "SYSTEM") & 0x10) | state->sub_obf | state->vsync | state->vdisp;
15391549
15401550   if(cassette_input(device->machine->device("cass")) > 0.03)
15411551      dat |= 0x02;
r9674r9675
15461556   // CMT test bit is set low when the CMT Stop command is issued, and becomes
15471557   // high again when this bit is read.
15481558   dat |= 0x01;
1549   if(cmt_test != 0)
1559   if(state->cmt_test != 0)
15501560   {
1551      cmt_test = 0;
1561      state->cmt_test = 0;
15521562      dat &= ~0x01;
15531563   }
15541564
r9674r9675
15581568/* I/O system port */
15591569static READ8_DEVICE_HANDLER( x1_portc_r )
15601570{
1571   x1_state *state = device->machine->driver_data<x1_state>();
15611572   //printf("PPI Port C read\n");
15621573   /*
15631574    x--x xxxx <unknown>
15641575    -x-- ---- 320 mode (r/w)
15651576    --x- ---- i/o mode (r/w)
15661577    */
1567   return (io_sys & 0x9f) | hres_320 | ~io_switch;
1578   return (state->io_sys & 0x9f) | state->hres_320 | ~state->io_switch;
15681579}
15691580
15701581static WRITE8_DEVICE_HANDLER( x1_porta_w )
r9674r9675
15791590
15801591static WRITE8_DEVICE_HANDLER( x1_portc_w )
15811592{
1582   hres_320 = data & 0x40;
1593   x1_state *state = device->machine->driver_data<x1_state>();
1594   state->hres_320 = data & 0x40;
15831595
1584   if(((data & 0x20) == 0) && (io_switch & 0x20))
1585      io_bank_mode = 1;
1596   if(((data & 0x20) == 0) && (state->io_switch & 0x20))
1597      state->io_bank_mode = 1;
15861598
1587   io_switch = data & 0x20;
1588   io_sys = data & 0xff;
1599   state->io_switch = data & 0x20;
1600   state->io_sys = data & 0xff;
15891601
15901602   cassette_output(device->machine->device("cass"),(data & 0x01) ? +1.0 : -1.0);
15911603}
r9674r9675
16021614
16031615static WRITE_LINE_DEVICE_HANDLER(vsync_changed)
16041616{
1605   static UINT8 pcg_reset_occurred;
1606
1607   vsync = (state & 1) ? 0x04 : 0x00;
1608   if(state & 1 && pcg_reset_occurred == 0) { pcg_reset = pcg_reset_occurred = 1; }
1609   if(!(state & 1))                         { pcg_reset_occurred = 0; }
1610   //printf("%d %02x\n",device->machine->primary_screen->vpos(),vsync);
1617   x1_state *drvstate = device->machine->driver_data<x1_state>();
1618   drvstate->vsync = (state & 1) ? 0x04 : 0x00;
1619   if(state & 1 && drvstate->pcg_reset_occurred == 0) { drvstate->pcg_reset = drvstate->pcg_reset_occurred = 1; }
1620   if(!(state & 1))                         { drvstate->pcg_reset_occurred = 0; }
1621   //printf("%d %02x\n",device->machine->primary_screen->vpos(),drvstate->vsync);
16111622}
16121623
16131624static const mc6845_interface mc6845_intf =
r9674r9675
20472058#ifdef UNUSED_FUNCTION
20482059static IRQ_CALLBACK(x1_irq_callback)
20492060{
2050    if(ctc_irq_flag != 0)
2061   x1_state *state = device->machine->driver_data<x1_state>();
2062    if(state->ctc_irq_flag != 0)
20512063    {
2052        ctc_irq_flag = 0;
2053        if(x1_key_irq_flag == 0)  // if no other devices are pulling the IRQ line high
2064        state->ctc_irq_flag = 0;
2065        if(state->key_irq_flag == 0)  // if no other devices are pulling the IRQ line high
20542066            cpu_set_input_line(device, 0, CLEAR_LINE);
2055        return x1_irq_vector;
2067        return state->irq_vector;
20562068    }
2057    if(x1_key_irq_flag != 0)
2069    if(state->key_irq_flag != 0)
20582070    {
2059        x1_key_irq_flag = 0;
2060        if(ctc_irq_flag == 0)  // if no other devices are pulling the IRQ line high
2071        state->key_irq_flag = 0;
2072        if(state->ctc_irq_flag == 0)  // if no other devices are pulling the IRQ line high
20612073            cpu_set_input_line(device, 0, CLEAR_LINE);
2062        return x1_key_irq_vector;
2074        return state->key_irq_vector;
20632075    }
2064    return x1_irq_vector;
2076    return state->irq_vector;
20652077}
20662078#endif
20672079
20682080static TIMER_CALLBACK(keyboard_callback)
20692081{
2082   x1_state *state = machine->driver_data<x1_state>();
20702083   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
20712084   UINT32 key1 = input_port_read(machine,"key1");
20722085   UINT32 key2 = input_port_read(machine,"key2");
20732086   UINT32 key3 = input_port_read(machine,"key3");
20742087   UINT32 key4 = input_port_read(machine,"tenkey");
20752088   UINT32 f_key = input_port_read(machine, "f_keys");
2076   static UINT32 old_key1,old_key2,old_key3,old_key4,old_fkey;
20772089
2078   if(x1_key_irq_vector)
2090   if(state->key_irq_vector)
20792091   {
2080      if((key1 != old_key1) || (key2 != old_key2) || (key3 != old_key3) || (key4 != old_key4) || (f_key != old_fkey))
2092      if((key1 != state->old_key1) || (key2 != state->old_key2) || (key3 != state->old_key3) || (key4 != state->old_key4) || (f_key != state->old_fkey))
20812093      {
20822094         // generate keyboard IRQ
20832095         sub_io_w(space,0,0xe6);
2084         x1_irq_vector = x1_key_irq_vector;
2085         x1_key_irq_flag = 1;
2096         state->irq_vector = state->key_irq_vector;
2097         state->key_irq_flag = 1;
20862098         cputag_set_input_line(machine,"maincpu",0,ASSERT_LINE);
2087         old_key1 = key1;
2088         old_key2 = key2;
2089         old_key3 = key3;
2090         old_key4 = key4;
2091         old_fkey = f_key;
2099         state->old_key1 = key1;
2100         state->old_key2 = key2;
2101         state->old_key3 = key3;
2102         state->old_key4 = key4;
2103         state->old_fkey = f_key;
20922104      }
20932105   }
20942106}
20952107
20962108static TIMER_CALLBACK(x1_rtc_increment)
20972109{
2110   x1_state *state = machine->driver_data<x1_state>();
20982111   static const UINT8 dpm[12] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 };
20992112
2100   x1_rtc.sec++;
2113   state->rtc.sec++;
21012114
2102   if((x1_rtc.sec & 0x0f) >= 0x0a)             { x1_rtc.sec+=0x10; x1_rtc.sec&=0xf0; }
2103   if((x1_rtc.sec & 0xf0) >= 0x60)             { x1_rtc.min++; x1_rtc.sec = 0; }
2104   if((x1_rtc.min & 0x0f) >= 0x0a)             { x1_rtc.min+=0x10; x1_rtc.min&=0xf0; }
2105   if((x1_rtc.min & 0xf0) >= 0x60)             { x1_rtc.hour++; x1_rtc.min = 0; }
2106   if((x1_rtc.hour & 0x0f) >= 0x0a)            { x1_rtc.hour+=0x10; x1_rtc.hour&=0xf0; }
2107   if((x1_rtc.hour & 0xff) >= 0x24)            { x1_rtc.day++; x1_rtc.wday++; x1_rtc.hour = 0; }
2108   if((x1_rtc.wday & 0x0f) >= 0x07)            { x1_rtc.wday = 0; }
2109   if((x1_rtc.day & 0x0f) >= 0x0a)               { x1_rtc.day+=0x10; x1_rtc.day&=0xf0; }
2115   if((state->rtc.sec & 0x0f) >= 0x0a)             { state->rtc.sec+=0x10; state->rtc.sec&=0xf0; }
2116   if((state->rtc.sec & 0xf0) >= 0x60)             { state->rtc.min++; state->rtc.sec = 0; }
2117   if((state->rtc.min & 0x0f) >= 0x0a)             { state->rtc.min+=0x10; state->rtc.min&=0xf0; }
2118   if((state->rtc.min & 0xf0) >= 0x60)             { state->rtc.hour++; state->rtc.min = 0; }
2119   if((state->rtc.hour & 0x0f) >= 0x0a)            { state->rtc.hour+=0x10; state->rtc.hour&=0xf0; }
2120   if((state->rtc.hour & 0xff) >= 0x24)            { state->rtc.day++; state->rtc.wday++; state->rtc.hour = 0; }
2121   if((state->rtc.wday & 0x0f) >= 0x07)            { state->rtc.wday = 0; }
2122   if((state->rtc.day & 0x0f) >= 0x0a)               { state->rtc.day+=0x10; state->rtc.day&=0xf0; }
21102123   /* FIXME: very crude leap year support (i.e. it treats the RTC to be with a 2000-2099 timeline), dunno how the real x1 supports this,
21112124       maybe it just have a 1980-1999 timeline since year 0x00 shows as a XX on display */
2112   if(((x1_rtc.year % 4) == 0) && x1_rtc.month == 2)
2125   if(((state->rtc.year % 4) == 0) && state->rtc.month == 2)
21132126   {
2114      if((x1_rtc.day & 0xff) >= dpm[x1_rtc.month-1]+1+1)
2115         { x1_rtc.month++; x1_rtc.day = 0x01; }
2127      if((state->rtc.day & 0xff) >= dpm[state->rtc.month-1]+1+1)
2128         { state->rtc.month++; state->rtc.day = 0x01; }
21162129   }
2117   else if((x1_rtc.day & 0xff) >= dpm[x1_rtc.month-1]+1){ x1_rtc.month++; x1_rtc.day = 0x01; }
2118   if(x1_rtc.month > 12)                     { x1_rtc.year++;  x1_rtc.month = 0x01; }
2119   if((x1_rtc.year & 0x0f) >= 0x0a)            { x1_rtc.year+=0x10; x1_rtc.year&=0xf0; }
2120   if((x1_rtc.year & 0xf0) >= 0xa0)            { x1_rtc.year = 0; } //roll over
2130   else if((state->rtc.day & 0xff) >= dpm[state->rtc.month-1]+1){ state->rtc.month++; state->rtc.day = 0x01; }
2131   if(state->rtc.month > 12)                     { state->rtc.year++;  state->rtc.month = 0x01; }
2132   if((state->rtc.year & 0x0f) >= 0x0a)            { state->rtc.year+=0x10; state->rtc.year&=0xf0; }
2133   if((state->rtc.year & 0xf0) >= 0xa0)            { state->rtc.year = 0; } //roll over
21212134}
21222135
21232136static MACHINE_RESET( x1 )
21242137{
2138   x1_state *state = machine->driver_data<x1_state>();
21252139   UINT8 *ROM = memory_region(machine, "maincpu");
21262140   UINT8 *PCG_RAM = memory_region(machine, "pcg");
21272141   int i;
21282142
21292143   memory_set_bankptr(machine, "bank1", &ROM[0x00000]);
21302144
2131   memset(gfx_bitmap_ram,0x00,0xc000*2);
2145   memset(state->gfx_bitmap_ram,0x00,0xc000*2);
21322146
21332147   for(i=0;i<0x1800;i++)
21342148   {
r9674r9675
21412155   }
21422156
21432157   /* X1 Turbo specific */
2144   scrn_reg.blackclip = 0;
2158   state->scrn_reg.blackclip = 0;
21452159
2146   io_bank_mode = 0;
2147   pcg_index[0] = pcg_index[1] = pcg_index[2] = 0;
2160   state->io_bank_mode = 0;
2161   state->pcg_index[0] = state->pcg_index[1] = state->pcg_index[2] = 0;
21482162
21492163   //cpu_set_irq_callback(machine->device("maincpu"), x1_irq_callback);
21502164
2151   cmt_current_cmd = 0;
2152   cmt_test = 0;
2165   state->cmt_current_cmd = 0;
2166   state->cmt_test = 0;
21532167   cassette_change_state(machine->device("cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR);
21542168
2155   x1_key_irq_flag = ctc_irq_flag = 0;
2169   state->key_irq_flag = state->ctc_irq_flag = 0;
21562170
21572171   /* Reinitialize palette here if there's a soft reset for the Turbo PAL stuff*/
21582172   for(i=0;i<8;i++)
r9674r9675
21612175      palette_set_color_rgb(machine, i+0x100, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0));
21622176   }
21632177
2164   timer_adjust_periodic(x1_rtc_timer, attotime_zero, 0, ATTOTIME_IN_SEC(1));
2178   timer_adjust_periodic(state->rtc_timer, attotime_zero, 0, ATTOTIME_IN_SEC(1));
21652179}
21662180
21672181static MACHINE_START( x1 )
21682182{
2183   x1_state *state = machine->driver_data<x1_state>();
21692184   timer_pulse(machine, ATTOTIME_IN_HZ(240), NULL, 0, keyboard_callback);
21702185   timer_pulse(machine, ATTOTIME_IN_HZ(16), NULL, 0, cmt_wind_timer);
21712186
r9674r9675
21742189      system_time systime;
21752190      machine->base_datetime(systime);
21762191
2177      x1_rtc.day = ((systime.local_time.mday / 10)<<4) | ((systime.local_time.mday % 10) & 0xf);
2178      x1_rtc.month = ((systime.local_time.month+1));
2179      x1_rtc.wday = ((systime.local_time.weekday % 10) & 0xf);
2180      x1_rtc.year = (((systime.local_time.year % 100)/10)<<4) | ((systime.local_time.year % 10) & 0xf);
2181      x1_rtc.hour = ((systime.local_time.hour / 10)<<4) | ((systime.local_time.hour % 10) & 0xf);
2182      x1_rtc.min = ((systime.local_time.minute / 10)<<4) | ((systime.local_time.minute % 10) & 0xf);
2183      x1_rtc.sec = ((systime.local_time.second / 10)<<4) | ((systime.local_time.second % 10) & 0xf);
2192      state->rtc.day = ((systime.local_time.mday / 10)<<4) | ((systime.local_time.mday % 10) & 0xf);
2193      state->rtc.month = ((systime.local_time.month+1));
2194      state->rtc.wday = ((systime.local_time.weekday % 10) & 0xf);
2195      state->rtc.year = (((systime.local_time.year % 100)/10)<<4) | ((systime.local_time.year % 10) & 0xf);
2196      state->rtc.hour = ((systime.local_time.hour / 10)<<4) | ((systime.local_time.hour % 10) & 0xf);
2197      state->rtc.min = ((systime.local_time.minute / 10)<<4) | ((systime.local_time.minute % 10) & 0xf);
2198      state->rtc.sec = ((systime.local_time.second / 10)<<4) | ((systime.local_time.second % 10) & 0xf);
21842199
2185      x1_rtc_timer = timer_alloc(machine, x1_rtc_increment, 0);
2200      state->rtc_timer = timer_alloc(machine, x1_rtc_increment, 0);
21862201   }
21872202}
21882203
src/mess/drivers/a2600.c
r9674r9675
757757
758758
759759/* These read handlers will return the byte from the new bank */
760static  READ8_HANDLER(modeF8_switch_r) {
761   a2600_state *state = space->machine->driver_data<a2600_state>(); modeF8_switch(space->machine, offset, 0); return state->bank_base[1][0xff8 + offset]; }
762static  READ8_HANDLER(modeFA_switch_r) {
763   a2600_state *state = space->machine->driver_data<a2600_state>(); modeFA_switch(space->machine, offset, 0); return state->bank_base[1][0xff8 + offset]; }
764static  READ8_HANDLER(modeF6_switch_r) {
765   a2600_state *state = space->machine->driver_data<a2600_state>(); modeF6_switch(space->machine, offset, 0); return state->bank_base[1][0xff6 + offset]; }
766static  READ8_HANDLER(modeF4_switch_r) {
767   a2600_state *state = space->machine->driver_data<a2600_state>(); modeF4_switch(space->machine, offset, 0); return state->bank_base[1][0xff4 + offset]; }
768static  READ8_HANDLER(modeE0_switch_r) {
769   a2600_state *state = space->machine->driver_data<a2600_state>(); modeE0_switch(space->machine, offset, 0); return state->bank_base[4][0x3e0 + offset]; }
770static  READ8_HANDLER(modeE7_switch_r) {
771   a2600_state *state = space->machine->driver_data<a2600_state>(); modeE7_switch(space->machine, offset, 0); return state->bank_base[1][0xfe0 + offset]; }
772static  READ8_HANDLER(modeE7_RAM_switch_r) { modeE7_RAM_switch(space->machine, offset, 0); return 0; }
773static  READ8_HANDLER(modeUA_switch_r) { modeUA_switch(space->machine, offset, 0); return 0; }
774static  READ8_HANDLER(modeDC_switch_r) {
775   a2600_state *state = space->machine->driver_data<a2600_state>(); modeDC_switch(space->machine, offset, 0); return state->bank_base[1][0xff0 + offset]; }
776static  READ8_HANDLER(modeFV_switch_r) {
777   a2600_state *state = space->machine->driver_data<a2600_state>(); modeFV_switch(space->machine, offset, 0); return state->bank_base[1][0xfd0 + offset]; }
778static  READ8_HANDLER(modeJVP_switch_r) {
779   a2600_state *state = space->machine->driver_data<a2600_state>(); modeJVP_switch(space->machine, offset, 0); return state->riot_ram[ 0x20 + offset ]; }
760static  READ8_HANDLER(modeF8_switch_r)
761{
762   a2600_state *state = space->machine->driver_data<a2600_state>();
763   modeF8_switch(space->machine, offset, 0);
764   return state->bank_base[1][0xff8 + offset];
765}
780766
767static  READ8_HANDLER(modeFA_switch_r)
768{
769   a2600_state *state = space->machine->driver_data<a2600_state>();
770   modeFA_switch(space->machine, offset, 0);
771   return state->bank_base[1][0xff8 + offset];
772}
781773
774static  READ8_HANDLER(modeF6_switch_r)
775{
776   a2600_state *state = space->machine->driver_data<a2600_state>();
777   modeF6_switch(space->machine, offset, 0);
778   return state->bank_base[1][0xff6 + offset];
779}
780
781static  READ8_HANDLER(modeF4_switch_r)
782{
783   a2600_state *state = space->machine->driver_data<a2600_state>();
784   modeF4_switch(space->machine, offset, 0);
785   return state->bank_base[1][0xff4 + offset];
786}
787
788static  READ8_HANDLER(modeE0_switch_r)
789{
790   a2600_state *state = space->machine->driver_data<a2600_state>();
791   modeE0_switch(space->machine, offset, 0);
792   return state->bank_base[4][0x3e0 + offset];
793}
794
795static  READ8_HANDLER(modeE7_switch_r)
796{
797   a2600_state *state = space->machine->driver_data<a2600_state>();
798   modeE7_switch(space->machine, offset, 0);
799   return state->bank_base[1][0xfe0 + offset];
800}
801
802static  READ8_HANDLER(modeE7_RAM_switch_r)
803{
804   modeE7_RAM_switch(space->machine, offset, 0);
805   return 0;
806}
807
808static  READ8_HANDLER(modeUA_switch_r)
809{
810   modeUA_switch(space->machine, offset, 0);
811   return 0;
812}
813
814static  READ8_HANDLER(modeDC_switch_r)
815{
816   a2600_state *state = space->machine->driver_data<a2600_state>();
817   modeDC_switch(space->machine, offset, 0);
818   return state->bank_base[1][0xff0 + offset];
819}
820
821static  READ8_HANDLER(modeFV_switch_r)
822{
823   a2600_state *state = space->machine->driver_data<a2600_state>();
824   modeFV_switch(space->machine, offset, 0);
825   return state->bank_base[1][0xfd0 + offset];
826}
827
828static  READ8_HANDLER(modeJVP_switch_r)
829{
830   a2600_state *state = space->machine->driver_data<a2600_state>();
831   modeJVP_switch(space->machine, offset, 0);
832   return state->riot_ram[ 0x20 + offset ];
833}
834
835
782836static WRITE8_HANDLER(modeF8_switch_w) { modeF8_switch(space->machine, offset, data); }
783837static WRITE8_HANDLER(modeFA_switch_w) { modeFA_switch(space->machine, offset, data); }
784838static WRITE8_HANDLER(modeF6_switch_w) { modeF6_switch(space->machine, offset, data); }
r9674r9675
800854   }
801855}
802856static WRITE8_HANDLER(modeFV_switch_w) { modeFV_switch(space->machine, offset, data); }
803static WRITE8_HANDLER(modeJVP_switch_w) {
804   a2600_state *state = space->machine->driver_data<a2600_state>(); modeJVP_switch(space->machine, offset, data); state->riot_ram[ 0x20 + offset ] = data; }
857static WRITE8_HANDLER(modeJVP_switch_w)
858{
859   a2600_state *state = space->machine->driver_data<a2600_state>();
860   modeJVP_switch(space->machine, offset, data); state->riot_ram[ 0x20 + offset ] = data;
861}
805862
806863
807864DIRECT_UPDATE_HANDLER( modeF6_opbase )
src/mess/drivers/orao.c
r9674r9675
2020
2121/* Address maps */
2222static ADDRESS_MAP_START(orao_mem, ADDRESS_SPACE_PROGRAM, 8)
23    AM_RANGE( 0x0000, 0x5fff ) AM_RAM AM_BASE(&orao_memory)
24    AM_RANGE( 0x6000, 0x7fff ) AM_RAM AM_BASE(&orao_video_ram) // video ram
23    AM_RANGE( 0x0000, 0x5fff ) AM_RAM AM_BASE_MEMBER(orao_state, memory)
24    AM_RANGE( 0x6000, 0x7fff ) AM_RAM AM_BASE_MEMBER(orao_state, video_ram) // video ram
2525    AM_RANGE( 0x8000, 0x9fff ) AM_READWRITE( orao_io_r, orao_io_w )
2626    AM_RANGE( 0xa000, 0xafff ) AM_RAM  // extension
2727    AM_RANGE( 0xb000, 0xbfff ) AM_RAM  // DOS
r9674r9675
171171};
172172
173173
174static MACHINE_CONFIG_START( orao, driver_device )
174static MACHINE_CONFIG_START( orao, orao_state )
175175    /* basic machine hardware */
176176    MDRV_CPU_ADD("maincpu", M6502, 1000000)
177177    MDRV_CPU_PROGRAM_MAP(orao_mem)
src/mess/drivers/mekd2.c
r9674r9675
4242
4343#define XTAL_MEKD2 1228800
4444
45static UINT8 mekd2_segment;
46static UINT8 mekd2_digit;
47static UINT8 mekd2_keydata;
4845
4946/***********************************************************
5047
r9674r9675
7370
7471static READ_LINE_DEVICE_HANDLER( mekd2_key40_r )
7572{
76   return (mekd2_keydata & 0x40) ? 1 : 0;
73   mekd2_state *state = device->machine->driver_data<mekd2_state>();
74   return (state->keydata & 0x40) ? 1 : 0;
7775}
7876
7977static READ8_DEVICE_HANDLER( mekd2_key_r )
8078{
79   mekd2_state *state = device->machine->driver_data<mekd2_state>();
8180   char kbdrow[4];
8281   UINT8 i;
83   mekd2_keydata = 0xff;
82   state->keydata = 0xff;
8483
8584   for (i = 0; i < 6; i++)
86      if (BIT(mekd2_digit, i))
85      if (BIT(state->digit, i))
8786      {
8887         sprintf(kbdrow,"X%d",i);
89         mekd2_keydata &= input_port_read(device->machine, kbdrow);
88         state->keydata &= input_port_read(device->machine, kbdrow);
9089      }
9190
92   if (mekd2_digit < 0x40)
93      i = (mekd2_keydata & 1) ? 0x80 : 0;
91   if (state->digit < 0x40)
92      i = (state->keydata & 1) ? 0x80 : 0;
9493   else
95   if (mekd2_digit < 0x80)
96      i = (mekd2_keydata & 2) ? 0x80 : 0;
94   if (state->digit < 0x80)
95      i = (state->keydata & 2) ? 0x80 : 0;
9796   else
98   if (mekd2_digit < 0xc0)
99      i = (mekd2_keydata & 4) ? 0x80 : 0;
97   if (state->digit < 0xc0)
98      i = (state->keydata & 4) ? 0x80 : 0;
10099   else
101      i = (mekd2_keydata & 8) ? 0x80 : 0;
100      i = (state->keydata & 8) ? 0x80 : 0;
102101
103102   return i;
104103}
r9674r9675
111110
112111static WRITE8_DEVICE_HANDLER( mekd2_segment_w )
113112{
114   mekd2_segment = ~data;
113   mekd2_state *state = device->machine->driver_data<mekd2_state>();
114   state->segment = ~data;
115115}
116116
117117static WRITE8_DEVICE_HANDLER( mekd2_digit_w )
r9674r9675
123123   for (i = 0; i < 6; i++)
124124      if (BIT(data, i))
125125      {
126         videoram[10 - i * 2] = mekd2_segment;
126         videoram[10 - i * 2] = state->segment;
127127         videoram[11 - i * 2] = 14;
128128      }
129129
130   mekd2_digit = data;
130   state->digit = data;
131131}
132132
133133/***********************************************************
src/mess/drivers/orion.c
r9674r9675
123123};
124124
125125/* Machine driver */
126static MACHINE_CONFIG_START( orion128, driver_device )
126static MACHINE_CONFIG_START( orion128, orion_state )
127127    MDRV_CPU_ADD("maincpu", I8080, 2000000)
128128    MDRV_CPU_PROGRAM_MAP(orion128_mem)
129129    MDRV_CPU_IO_MAP(orion128_io)
r9674r9675
180180   DEVCB_NULL
181181};
182182
183static MACHINE_CONFIG_START( orionz80, driver_device )
183static MACHINE_CONFIG_START( orionz80, orion_state )
184184    MDRV_CPU_ADD("maincpu", Z80, 2500000)
185185    MDRV_CPU_PROGRAM_MAP(orionz80_mem)
186186    MDRV_CPU_IO_MAP(orionz80_io)
r9674r9675
238238   MDRV_I8255A_ADD( "ppi8255_2", rk7007_ppi8255_interface )
239239MACHINE_CONFIG_END
240240
241static MACHINE_CONFIG_START( orionpro, driver_device )
241static MACHINE_CONFIG_START( orionpro, orion_state )
242242    MDRV_CPU_ADD("maincpu", Z80, 5000000)
243243    MDRV_CPU_PROGRAM_MAP(orionpro_mem)
244244    MDRV_CPU_IO_MAP(orionpro_io)
src/mess/drivers/newbrain.c
r9674r9675
743743   NEWBRAIN_COP_STATE_DATA
744744};
745745
746static UINT8 copdata;
747static int copstate, copbytes, copregint;
748746
749747static READ8_HANDLER( cop_r )
750748{
r9674r9675
753751   state->copint = 1;
754752   check_interrupt(space->machine);
755753
756   return copdata;
754   return state->copdata;
757755}
758756
759757static WRITE8_HANDLER( cop_w )
760758{
761759   newbrain_state *state = space->machine->driver_data<newbrain_state>();
762760
763   copdata = data;
761   state->copdata = data;
764762
765   switch (copstate)
763   switch (state->copstate)
766764   {
767765   case NEWBRAIN_COP_STATE_COMMAND:
768766      logerror("COP command %02x\n", data);
r9674r9675
773771         break;
774772
775773      case NEWBRAIN_COPCMD_DISPCOM:
776         copregint = 0;
777         copbytes = 18;
778         copstate = NEWBRAIN_COP_STATE_DATA;
774         state->copregint = 0;
775         state->copbytes = 18;
776         state->copstate = NEWBRAIN_COP_STATE_DATA;
779777
780         copdata = NEWBRAIN_COP_NO_DATA;
778         state->copdata = NEWBRAIN_COP_NO_DATA;
781779         state->copint = 0;
782780         check_interrupt(space->machine);
783781
r9674r9675
785783
786784#if 0
787785      case NEWBRAIN_COPCMD_TIMCOM:
788         copregint = 0;
789         copbytes = 6;
790         copstate = NEWBRAIN_COP_STATE_DATA;
786         state->copregint = 0;
787         state->copbytes = 6;
788         state->copstate = NEWBRAIN_COP_STATE_DATA;
791789         break;
792790#endif
793791      case NEWBRAIN_COPCMD_PDNCOM:
794792         /* power down */
795         copregint = 0;
793         state->copregint = 0;
796794         break;
797795
798796      default:
799797         if (data & NEWBRAIN_COPCMD_TAPECOM)
800798         {
801            copregint = 0;
799            state->copregint = 0;
802800         }
803801      }
804802      break;
805803
806804   case NEWBRAIN_COP_STATE_DATA:
807805      logerror("COP data %02x\n", data);
808      copbytes--;
806      state->copbytes--;
809807
810      if (copbytes == 0)
808      if (state->copbytes == 0)
811809      {
812         copstate = NEWBRAIN_COP_STATE_COMMAND;
813         copregint = 1;
810         state->copstate = NEWBRAIN_COP_STATE_COMMAND;
811         state->copregint = 1;
814812      }
815813
816      copdata = NEWBRAIN_COP_NO_DATA;
814      state->copdata = NEWBRAIN_COP_NO_DATA;
817815      state->copint = 0;
818816      check_interrupt(space->machine);
819817
r9674r9675
825823{
826824   newbrain_state *state = timer.machine->driver_data<newbrain_state>();
827825
828   if (copregint)
826   if (state->copregint)
829827   {
830828      logerror("COP REGINT\n");
831829      state->copint = 0;
r9674r9675
13831381{
13841382   newbrain_state *state = machine->driver_data<newbrain_state>();
13851383
1386   copregint = 1;
1384   state->copregint = 1;
13871385
13881386   /* find devices */
13891387   state->cassette1 = machine->device(CASSETTE1_TAG);
src/mess/drivers/llc.c
r9674r9675
2020   AM_RANGE(0x0000, 0x07ff) AM_ROM // Monitor ROM
2121   AM_RANGE(0x0800, 0x13ff) AM_ROM // BASIC ROM
2222   AM_RANGE(0x1400, 0x1bff) AM_RAM // RAM
23   AM_RANGE(0x1c00, 0x1fff) AM_RAM AM_BASE(&llc_video_ram) // Video RAM
23   AM_RANGE(0x1c00, 0x1fff) AM_RAM AM_BASE_MEMBER(llc_state, video_ram) // Video RAM
2424   AM_RANGE(0x2000, 0xffff) AM_RAM // RAM
2525ADDRESS_MAP_END
2626
r9674r9675
314314GFXDECODE_END
315315
316316/* Machine driver */
317static MACHINE_CONFIG_START( llc1, driver_device )
317static MACHINE_CONFIG_START( llc1, llc_state )
318318   /* basic machine hardware */
319319   MDRV_CPU_ADD("maincpu", Z80, XTAL_3MHz)
320320   MDRV_CPU_CONFIG(llc1_daisy_chain)
r9674r9675
342342   MDRV_Z80CTC_ADD( "z80ctc", XTAL_3MHz, llc1_ctc_intf )
343343MACHINE_CONFIG_END
344344
345static MACHINE_CONFIG_START( llc2, driver_device )
345static MACHINE_CONFIG_START( llc2, llc_state )
346346   /* basic machine hardware */
347347   MDRV_CPU_ADD("maincpu", Z80, XTAL_3MHz)
348348   MDRV_CPU_PROGRAM_MAP(llc2_mem)
src/mess/drivers/trs80.c
r9674r9675
158158#include "formats/trs_cas.h"
159159#include "formats/trs_cmd.h"
160160
161UINT8 *trs80_gfxram;
162UINT8 trs80_model4;
163161
164162static ADDRESS_MAP_START( trs80_map, ADDRESS_SPACE_PROGRAM, 8 )
165163   AM_RANGE(0x0000, 0x0fff) AM_ROM
r9674r9675
825823
826824static DRIVER_INIT( trs80 )
827825{
828   trs80_mode = 0;
829   trs80_model4 = 0;
826   trs80_state *state = machine->driver_data<trs80_state>();
827   state->mode = 0;
828   state->model4 = 0;
830829}
831830
832831static DRIVER_INIT( trs80l2 )
833832{
834   trs80_mode = 2;
835   trs80_model4 = 0;
833   trs80_state *state = machine->driver_data<trs80_state>();
834   state->mode = 2;
835   state->model4 = 0;
836836}
837837
838838static DRIVER_INIT( trs80m4 )
839839{
840840   trs80_state *state = machine->driver_data<trs80_state>();
841   trs80_mode = 0;
842   trs80_model4 = 2;
841   state->mode = 0;
842   state->model4 = 2;
843843   state->videoram = memory_region(machine, "maincpu")+0x4000;
844844}
845845
846846static DRIVER_INIT( trs80m4p )
847847{
848848   trs80_state *state = machine->driver_data<trs80_state>();
849   trs80_mode = 0;
850   trs80_model4 = 4;
849   state->mode = 0;
850   state->model4 = 4;
851851   state->videoram = memory_region(machine, "maincpu")+0x4000;
852852}
853853
854854static DRIVER_INIT( lnw80 )
855855{
856856   trs80_state *state = machine->driver_data<trs80_state>();
857   trs80_mode = 0;
858   trs80_model4 = 0;
859   trs80_gfxram = memory_region(machine, "gfx2");
857   state->mode = 0;
858   state->model4 = 0;
859   state->gfxram = memory_region(machine, "gfx2");
860860   state->videoram = memory_region(machine, "gfx2")+0x4000;
861861}
862862
src/mess/drivers/ondra.c
r9674r9675
119119};
120120
121121/* Machine driver */
122static MACHINE_CONFIG_START( ondra, driver_device )
122static MACHINE_CONFIG_START( ondra, ondra_state )
123123   /* basic machine hardware */
124124   MDRV_CPU_ADD("maincpu", Z80, 2000000)
125125   MDRV_CPU_PROGRAM_MAP(ondra_mem)
src/mess/drivers/socrates.c
r9674r9675
7575#include "cpu/z80/z80.h"
7676#include "audio/socrates.h"
7777
78
79class socrates_state : public driver_device
80{
81public:
82   socrates_state(running_machine &machine, const driver_device_config_base &config)
83      : driver_device(machine, config) { }
84
85   rgb_t palette[256];
86
87   UINT8 data[8];
88   UINT8 rom_bank;
89   UINT8 ram_bank;
90   UINT16 scroll_offset;
91   UINT8* videoram;
92   UINT8 kb_latch_low[2];
93   UINT8 kb_latch_high[2];
94   UINT8 kb_latch_mouse;
95   UINT8 io40_latch; // what was last written to speech reg (for open bus)?
96   UINT8 hblankstate; // are we in hblank?
97   UINT8 vblankstate; // are we in vblank?
98   UINT8 speech_running; // is speech synth talking?
99   UINT32 speech_address; // address in speech space
100   UINT8 speech_settings; // speech settings (nybble 0: ? externrom ? ?; nybble 1: ? ? ? ?)
101   UINT8 speech_dummy_read; // have we done a dummy read yet?
102   UINT8 speech_load_address_count; // number of times load address has happened
103   UINT8 speech_load_settings_count; // number of times load settings has happened
104};
105
106
78107/* Defines */
79108
80109/* Components */
81110
82111/* Devices */
83112
84/* stuff below belongs in machine/socrates.c */
85static struct
86{
87UINT8 data[8];
88UINT8 rom_bank;
89UINT8 ram_bank;
90UINT16 scroll_offset;
91UINT8* videoram;
92UINT8 kb_latch_low[2];
93UINT8 kb_latch_high[2];
94UINT8 kb_latch_mouse;
95UINT8 io40_latch; // what was last written to speech reg (for open bus)?
96UINT8 hblankstate; // are we in hblank?
97UINT8 vblankstate; // are we in vblank?
98UINT8 speech_running; // is speech synth talking?
99UINT32 speech_address; // address in speech space
100UINT8 speech_settings; // speech settings (nybble 0: ? externrom ? ?; nybble 1: ? ? ? ?)
101UINT8 speech_dummy_read; // have we done a dummy read yet?
102UINT8 speech_load_address_count; // number of times load address has happened
103UINT8 speech_load_settings_count; // number of times load settings has happened
104
105} socrates={ {0}};
106
107113static void socrates_set_rom_bank( running_machine *machine )
108114{
109 memory_set_bankptr( machine, "bank1", memory_region(machine, "maincpu") + ( socrates.rom_bank * 0x4000 ));
115   socrates_state *state = machine->driver_data<socrates_state>();
116   memory_set_bankptr( machine, "bank1", memory_region(machine, "maincpu") + ( state->rom_bank * 0x4000 ));
110117}
111118
112119static void socrates_set_ram_bank( running_machine *machine )
113120{
114 memory_set_bankptr( machine, "bank2", memory_region(machine, "vram") + ( (socrates.ram_bank&0x3) * 0x4000 )); // window 0
115 memory_set_bankptr( machine, "bank3", memory_region(machine, "vram") + ( ((socrates.ram_bank&0xC)>>2) * 0x4000 )); // window 1
121   socrates_state *state = machine->driver_data<socrates_state>();
122   memory_set_bankptr( machine, "bank2", memory_region(machine, "vram") + ( (state->ram_bank&0x3) * 0x4000 )); // window 0
123   memory_set_bankptr( machine, "bank3", memory_region(machine, "vram") + ( ((state->ram_bank&0xC)>>2) * 0x4000 )); // window 1
116124}
117125
118126static void socrates_update_kb( running_machine *machine )
119127{
128   socrates_state *state = machine->driver_data<socrates_state>();
120129   static const char *const rownames[] = { "keyboard_40", "keyboard_41", "keyboard_42", "keyboard_43", "keyboard_44" };
121130   int row, keyvalue, powerof2;
122131   int shift = 0;
123132   // first check that the kb latch[1] is clear; if it isn't, don't touch it!
124   if ((socrates.kb_latch_low[1] != 0) || (socrates.kb_latch_high[1] != 1)) return;
133   if ((state->kb_latch_low[1] != 0) || (state->kb_latch_high[1] != 1)) return;
125134   // next check for joypad buttons
126135   keyvalue = input_port_read(machine, "keyboard_jp");
127136   if (keyvalue != 0)
128137   {
129      socrates.kb_latch_low[1] = (keyvalue & 0xFF0)>>4;
130      socrates.kb_latch_high[1] = 0x80 | (keyvalue & 0xF);
138      state->kb_latch_low[1] = (keyvalue & 0xFF0)>>4;
139      state->kb_latch_high[1] = 0x80 | (keyvalue & 0xF);
131140      return; // get out of this function; due to the way key priorities work, we're done here.
132141   }
133142   // next check for mouse movement.
r9674r9675
144153         {
145154            if ((keyvalue&(1<<powerof2)) == (1<<powerof2))
146155            {
147               socrates.kb_latch_low[1] = (shift?0x50:0x40)+row;
148               socrates.kb_latch_high[1] = (0x80 | powerof2);
156               state->kb_latch_low[1] = (shift?0x50:0x40)+row;
157               state->kb_latch_high[1] = (0x80 | powerof2);
149158               return; // get out of the for loop; due to the way key priorities work, we're done here.
150159            }
151160         }
r9674r9675
154163   // no key was pressed... check if shift was hit then?
155164   if (shift != 0)
156165   {
157      socrates.kb_latch_low[1] = 0x50;
158      socrates.kb_latch_high[1] = 0x80;
166      state->kb_latch_low[1] = 0x50;
167      state->kb_latch_high[1] = 0x80;
159168   }
160169}
161170
162171static void socrates_check_kb_latch( running_machine *machine ) // if kb[1] is full and kb[0] is not, shift [1] to [0] and clear [1]
163172{
164   if (((socrates.kb_latch_low[1] != 0) || (socrates.kb_latch_high[1] != 1)) &&
165   ((socrates.kb_latch_low[0] == 0) && (socrates.kb_latch_high[0] == 1)))
173   socrates_state *state = machine->driver_data<socrates_state>();
174   if (((state->kb_latch_low[1] != 0) || (state->kb_latch_high[1] != 1)) &&
175   ((state->kb_latch_low[0] == 0) && (state->kb_latch_high[0] == 1)))
166176   {
167      socrates.kb_latch_low[0] = socrates.kb_latch_low[1];
168      socrates.kb_latch_low[1] = 0;
169      socrates.kb_latch_high[0] = socrates.kb_latch_high[1];
170      socrates.kb_latch_high[1] = 1;
177      state->kb_latch_low[0] = state->kb_latch_low[1];
178      state->kb_latch_low[1] = 0;
179      state->kb_latch_high[0] = state->kb_latch_high[1];
180      state->kb_latch_high[1] = 1;
171181   }
172182}
173183
174184static MACHINE_RESET( socrates )
175185{
176 socrates.rom_bank = 0xF3; // actually set semi-randomly on real console but we need to initialize it somewhere...
186   socrates_state *state = machine->driver_data<socrates_state>();
187 state->rom_bank = 0xF3; // actually set semi-randomly on real console but we need to initialize it somewhere...
177188 socrates_set_rom_bank( machine );
178 socrates.ram_bank = 0;  // the actual console sets it semi randomly on power up, and the bios cleans it up.
189 state->ram_bank = 0;  // the actual console sets it semi randomly on power up, and the bios cleans it up.
179190 socrates_set_ram_bank( machine );
180 socrates.kb_latch_low[0] = 0xFF;
181 socrates.kb_latch_high[0] = 0x8F;
182 socrates.kb_latch_low[1] = 0x00;
183 socrates.kb_latch_high[1] = 0x01;
184 socrates.kb_latch_mouse = 0;
185 socrates.io40_latch = 0;
186 socrates.hblankstate = 0;
187 socrates.vblankstate = 0;
188 socrates.speech_running = 0;
189 socrates.speech_address = 0;
190 socrates.speech_settings = 0;
191 socrates.speech_dummy_read = 0;
192 socrates.speech_load_address_count = 0;
193 socrates.speech_load_settings_count = 0;
191 state->kb_latch_low[0] = 0xFF;
192 state->kb_latch_high[0] = 0x8F;
193 state->kb_latch_low[1] = 0x00;
194 state->kb_latch_high[1] = 0x01;
195 state->kb_latch_mouse = 0;
196 state->io40_latch = 0;
197 state->hblankstate = 0;
198 state->vblankstate = 0;
199 state->speech_running = 0;
200 state->speech_address = 0;
201 state->speech_settings = 0;
202 state->speech_dummy_read = 0;
203 state->speech_load_address_count = 0;
204 state->speech_load_settings_count = 0;
194205}
195206
196207static DRIVER_INIT( socrates )
r9674r9675
206217
207218static READ8_HANDLER( socrates_rom_bank_r )
208219{
220   socrates_state *state = space->machine->driver_data<socrates_state>();
209221 UINT8 data = 0xFF;
210 data = socrates.rom_bank;
222 data = state->rom_bank;
211223 return data;
212224}
213225
214226static WRITE8_HANDLER( socrates_rom_bank_w )
215227{
216 socrates.rom_bank = data;
228   socrates_state *state = space->machine->driver_data<socrates_state>();
229 state->rom_bank = data;
217230 socrates_set_rom_bank( space->machine );
218231}
219232
220233static READ8_HANDLER( socrates_ram_bank_r )
221234{
235   socrates_state *state = space->machine->driver_data<socrates_state>();
222236 UINT8 data = 0xFF;
223 data = socrates.ram_bank;
237 data = state->ram_bank;
224238 return data;
225239}
226240
227241static WRITE8_HANDLER( socrates_ram_bank_w )
228242{
229 socrates.ram_bank = data&0xF;
243   socrates_state *state = space->machine->driver_data<socrates_state>();
244 state->ram_bank = data&0xF;
230245 socrates_set_ram_bank( space->machine );
231246}
232247
r9674r9675
242257
243258static READ8_HANDLER( status_and_speech ) // read 0x4x, some sort of status reg
244259{
260   socrates_state *state = space->machine->driver_data<socrates_state>();
245261// bit 7 - speech status: high when speech is playing, low when it is not (or when speech cart is not present)
246262// bit 6 - unknown, usually set, may involve the writes to 0x30, possibly some sort of fixed-length timer?
247263// bit 5 - vblank status, high when not in vblank
r9674r9675
253269UINT8 *speechromint = memory_region(space->machine, "speechint");
254270UINT8 *speechromext = memory_region(space->machine, "speechext");
255271   int temp = 0;
256   temp |= (socrates.speech_running)?0x80:0;
272   temp |= (state->speech_running)?0x80:0;
257273   temp |= 0x40; // unknown
258   temp |= (socrates.vblankstate)?0:0x20;
259   temp |= (socrates.hblankstate)?0:0x10;
260   switch(socrates.io40_latch&0xF0) // what was last opcode sent?
274   temp |= (state->vblankstate)?0:0x20;
275   temp |= (state->hblankstate)?0:0x10;
276   switch(state->io40_latch&0xF0) // what was last opcode sent?
261277   {
262278      case 0x60: case 0xE0:// speech status 'read' register
263         if(socrates.speech_settings&0x04) // external speech roms (outside of speech ic but still in cart) enabled
279         if(state->speech_settings&0x04) // external speech roms (outside of speech ic but still in cart) enabled
264280         {
265         logerror("reading external speech rom nybble from nybble address %x (byte address %x)\n",socrates.speech_address, socrates.speech_address>>1);
266         temp |= ((speechromext[((socrates.speech_address>>1)&0xffff)]>>((socrates.speech_address&1)*4))&0xF);
281         logerror("reading external speech rom nybble from nybble address %x (byte address %x)\n",state->speech_address, state->speech_address>>1);
282         temp |= ((speechromext[((state->speech_address>>1)&0xffff)]>>((state->speech_address&1)*4))&0xF);
267283         }
268284         else
269285         {
270         logerror("reading internal speech rom nybble from nybble address %x (byte address %x)\n",socrates.speech_address, socrates.speech_address>>1);
271         temp |= ((speechromint[((socrates.speech_address>>1)&0x1fff)]>>((socrates.speech_address&1)*4))&0xF);
286         logerror("reading internal speech rom nybble from nybble address %x (byte address %x)\n",state->speech_address, state->speech_address>>1);
287         temp |= ((speechromint[((state->speech_address>>1)&0x1fff)]>>((state->speech_address&1)*4))&0xF);
272288         }
273         if (socrates.speech_dummy_read == 0) // if we havent done the dummy read yet, do so now
289         if (state->speech_dummy_read == 0) // if we havent done the dummy read yet, do so now
274290         {
275            socrates.speech_dummy_read++;
291            state->speech_dummy_read++;
276292         }
277293         else
278294         {
279            socrates.speech_address++;
295            state->speech_address++;
280296         }
281297         break;
282298      default:
283         temp |= socrates.io40_latch&0xF; // read open bus
299         temp |= state->io40_latch&0xF; // read open bus
284300         break;
285301   }
286302   logerror("read from i/o 0x4x of %x\n", temp);
r9674r9675
288304}
289305static TIMER_CALLBACK( clear_speech_cb )
290306{
291   socrates.speech_running = 0;
292   socrates.speech_load_address_count = 0; // should this be here or in the write functuon subpart which is speak command?
293   socrates.speech_load_settings_count = 0;
307   socrates_state *state = machine->driver_data<socrates_state>();
308   state->speech_running = 0;
309   state->speech_load_address_count = 0; // should this be here or in the write functuon subpart which is speak command?
310   state->speech_load_settings_count = 0;
294311}
295312
296313static WRITE8_HANDLER( speech_command ) // write 0x4x, some sort of bitfield; speech chip is probably hitachi hd38880 related but not exact, w/4 bit interface
297314{
315   socrates_state *state = space->machine->driver_data<socrates_state>();
298316   logerror("write to i/o 0x4x of %x\n", data);
299317/*
300318// the high 4 bits of the write control which 'register' is written to, the low 4 bits are data (this is based on a readback test)
r9674r9675
352370         if (data==0x80)
353371         {
354372            /* write me: start talking */
355            socrates.speech_running = 1;
373            state->speech_running = 1;
356374            timer_set(space->machine, ATTOTIME_IN_SEC(4), NULL, 0, clear_speech_cb); // hack
357375         }
358376         break;
r9674r9675
363381      case 0xB0: // unknown
364382         break;
365383      case 0xC0: // load address to vsm
366         socrates.speech_address |= (((int)data&0xF)<<(socrates.speech_load_address_count*4))<<1;
367         socrates.speech_load_address_count++;
368         logerror("loaded address nybble %X, byte address is currently %5X with %d nybbles loaded\n", data&0xF, socrates.speech_address>>1, socrates.speech_load_address_count);
384         state->speech_address |= (((int)data&0xF)<<(state->speech_load_address_count*4))<<1;
385         state->speech_load_address_count++;
386         logerror("loaded address nybble %X, byte address is currently %5X with %d nybbles loaded\n", data&0xF, state->speech_address>>1, state->speech_load_address_count);
369387         break;
370388      case 0xD0: // load settings
371         socrates.speech_settings |= ((data&0xF)<<(socrates.speech_load_settings_count*4));
372         socrates.speech_load_settings_count++;
389         state->speech_settings |= ((data&0xF)<<(state->speech_load_settings_count*4));
390         state->speech_load_settings_count++;
373391         break;
374392      case 0xE0: // read byte, handled elsewhere
375393         break;
376394      case 0xF0: // command: sub 0 is speak, sub 8 is reset
377395         if ((data&0xF) == 0) // speak
378396         {
379            socrates.speech_running = 1;
397            state->speech_running = 1;
380398            timer_set(space->machine, ATTOTIME_IN_SEC(4), NULL, 0, clear_speech_cb); // hack
381399         }
382400         else if ((data&0xF) == 8) // reset
383401         {
384            socrates.speech_running = 0;
385            socrates.speech_address = 0;
386            socrates.speech_settings = 0;
387            socrates.speech_dummy_read = 0;
388            socrates.speech_load_address_count = 0;
389            socrates.speech_load_settings_count = 0;
390            socrates.io40_latch &= 0x0f; // set last command to 0 to prevent problems
402            state->speech_running = 0;
403            state->speech_address = 0;
404            state->speech_settings = 0;
405            state->speech_dummy_read = 0;
406            state->speech_load_address_count = 0;
407            state->speech_load_settings_count = 0;
408            state->io40_latch &= 0x0f; // set last command to 0 to prevent problems
391409         }
392410         else // other
393411         {
r9674r9675
397415      default: // 00 thru 70 are packets without the write bit set, ignore them
398416         break;
399417   }
400   socrates.io40_latch = data;
418   state->io40_latch = data;
401419}
402420
403421static READ8_HANDLER( socrates_keyboard_low_r ) // keyboard code low
404422{
423   socrates_state *state = space->machine->driver_data<socrates_state>();
405424 socrates_update_kb( space->machine );
406425 socrates_check_kb_latch( space->machine );
407 return socrates.kb_latch_low[0];
426 return state->kb_latch_low[0];
408427}
409428
410429static READ8_HANDLER( socrates_keyboard_high_r ) // keyboard code high
411430{
431   socrates_state *state = space->machine->driver_data<socrates_state>();
412432 socrates_update_kb( space->machine );
413433 socrates_check_kb_latch( space->machine );
414 return socrates.kb_latch_high[0];
434 return state->kb_latch_high[0];
415435}
416436
417437static WRITE8_HANDLER( socrates_keyboard_clear ) // keyboard latch shift/clear
418438{
419   socrates.kb_latch_low[0] = socrates.kb_latch_low[1];
420   socrates.kb_latch_high[0] = socrates.kb_latch_high[1];
421   socrates.kb_latch_low[1] = 0;
422   socrates.kb_latch_high[1] = 1;
439   socrates_state *state = space->machine->driver_data<socrates_state>();
440   state->kb_latch_low[0] = state->kb_latch_low[1];
441   state->kb_latch_high[0] = state->kb_latch_high[1];
442   state->kb_latch_low[1] = 0;
443   state->kb_latch_high[1] = 1;
423444}
424445
425446static WRITE8_HANDLER( reset_speech ) // i/o 60: reset speech synth
426447{
427 socrates.speech_running = 0;
428 socrates.speech_address = 0;
429 socrates.speech_settings = 0;
430 socrates.speech_dummy_read = 0;
431 socrates.speech_load_address_count = 0;
432 socrates.speech_load_settings_count = 0;
433 socrates.io40_latch &= 0x0f; // set last command to 0 to prevent problems
448   socrates_state *state = space->machine->driver_data<socrates_state>();
449 state->speech_running = 0;
450 state->speech_address = 0;
451 state->speech_settings = 0;
452 state->speech_dummy_read = 0;
453 state->speech_load_address_count = 0;
454 state->speech_load_settings_count = 0;
455 state->io40_latch &= 0x0f; // set last command to 0 to prevent problems
434456logerror("write to i/o 0x60 of %x\n",data);
435457}
436458
437/* stuff below belongs in video/socrates.c */
459/* stuff below belongs in video/nc.c */
438460
439461static WRITE8_HANDLER( socrates_scroll_w )
440462{
463   socrates_state *state = space->machine->driver_data<socrates_state>();
441464 if (offset == 0)
442 socrates.scroll_offset = (socrates.scroll_offset&0x100) | data;
465 state->scroll_offset = (state->scroll_offset&0x100) | data;
443466 else
444 socrates.scroll_offset = (socrates.scroll_offset&0xFF) | ((data&1)<<8);
467 state->scroll_offset = (state->scroll_offset&0xFF) | ((data&1)<<8);
445468}
446469
447470/* NTSC-based Palette stuff */
r9674r9675
547570return composedcolor;
548571}
549572
550static rgb_t socrates_palette[256];
551573
552574static PALETTE_INIT( socrates )
553575{
576   socrates_state *state = machine->driver_data<socrates_state>();
554577   int i; // iterator
555578   for (i = 0; i < 256; i++)
556579   {
557    socrates_palette[i] = socrates_create_color(i);
580    state->palette[i] = socrates_create_color(i);
558581   }
559   palette_set_colors(machine, 0, socrates_palette, ARRAY_LENGTH(socrates_palette));
582   palette_set_colors(machine, 0, state->palette, ARRAY_LENGTH(state->palette));
560583}
561584
562585static VIDEO_START( socrates )
563586{
564   socrates.videoram = memory_region(machine, "vram");
565   socrates.scroll_offset = 0;
587   socrates_state *state = machine->driver_data<socrates_state>();
588   state->videoram = memory_region(machine, "vram");
589   state->scroll_offset = 0;
566590}
567591
568592static VIDEO_UPDATE( socrates )
569593{
570   UINT8 fixedcolors[8] =
594   socrates_state *state = screen->machine->driver_data<socrates_state>();
595   static const UINT8 fixedcolors[8] =
571596   {
572597   0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0xF7
573598   };
r9674r9675
575600   int lineoffset = 0; // if display ever tries to display data at 0xfxxx, offset line displayed by 0x1000
576601   for (y = 0; y < 228; y++)
577602   {
578      if ((((y+socrates.scroll_offset)*128)&0xffff) >= 0xf000) lineoffset = 0x1000; // see comment above
603      if ((((y+state->scroll_offset)*128)&0xffff) >= 0xf000) lineoffset = 0x1000; // see comment above
579604      for (x = 0; x < 264; x++)
580605      {
581606         if (x < 256)
582607         {
583            colidx = socrates.videoram[(((y+socrates.scroll_offset)*128)+(x>>1)+lineoffset)&0xffff];
608            colidx = state->videoram[(((y+state->scroll_offset)*128)+(x>>1)+lineoffset)&0xffff];
584609            if (x&1) colidx >>=4;
585610            colidx &= 0xF;
586            if (colidx > 7) color=socrates.videoram[0xF000+(colidx<<8)+((y+socrates.scroll_offset)&0xFF)];
611            if (colidx > 7) color=state->videoram[0xF000+(colidx<<8)+((y+state->scroll_offset)&0xFF)];
587612            else color=fixedcolors[colidx];
588613            *BITMAP_ADDR16(bitmap, y,  x) = color;
589614         }
590615         else
591616         {
592            colidx = socrates.videoram[(((y+socrates.scroll_offset)*128)+(127)+lineoffset)&0xffff];
617            colidx = state->videoram[(((y+state->scroll_offset)*128)+(127)+lineoffset)&0xffff];
593618            colidx >>=4;
594619            colidx &= 0xF;
595            if (colidx > 7) color=socrates.videoram[0xF000+(colidx<<8)+((y+socrates.scroll_offset)&0xFF)];
620            if (colidx > 7) color=state->videoram[0xF000+(colidx<<8)+((y+state->scroll_offset)&0xFF)];
596621            else color=fixedcolors[colidx];
597622            *BITMAP_ADDR16(bitmap, y,  x) = color;
598623         }
r9674r9675
601626   return 0;
602627}
603628
604/* below belongs in sound/socrates.c */
629/* below belongs in sound/nc.c */
605630
606631static WRITE8_HANDLER(socrates_sound_w)
607632{
r9674r9675
860885******************************************************************************/
861886static TIMER_CALLBACK( clear_irq_cb )
862887{
888   socrates_state *state = machine->driver_data<socrates_state>();
863889   cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
864   socrates.vblankstate = 0;
890   state->vblankstate = 0;
865891}
866892
867893static INTERRUPT_GEN( assert_irq )
868894{
895   socrates_state *state = device->machine->driver_data<socrates_state>();
869896   cpu_set_input_line(device, 0, ASSERT_LINE);
870897   timer_set(device->machine, downcast<cpu_device *>(device)->cycles_to_attotime(44), NULL, 0, clear_irq_cb);
871898// 44 is a complete and total guess, need to properly measure how many clocks/microseconds the int line is high for.
872   socrates.vblankstate = 1;
899   state->vblankstate = 1;
873900}
874901
875static MACHINE_CONFIG_START( socrates, driver_device )
902static MACHINE_CONFIG_START( socrates, socrates_state )
876903    /* basic machine hardware */
877904    MDRV_CPU_ADD("maincpu", Z80, XTAL_21_4772MHz/6)  /* Toshiba TMPZ84C00AP @ 3.579545 MHz, verified, xtal is divided by 6 */
878905    MDRV_CPU_PROGRAM_MAP(z80_mem)
src/mess/drivers/univac.c
r9674r9675
1616#include "emu.h"
1717#include "cpu/z80/z80.h"
1818
19static const UINT8 *FNT;
20static UINT8 uts20_screen;
2119
20class univac_state : public driver_device
21{
22public:
23   univac_state(running_machine &machine, const driver_device_config_base &config)
24      : driver_device(machine, config) { }
25
26   const UINT8 *FNT;
27   UINT8 uts20_screen;
28   UINT8 framecnt;
29};
30
31
32
2233static WRITE8_HANDLER( uts20_43_w )
2334{
24   uts20_screen = data & 1;
35   univac_state *state = space->machine->driver_data<univac_state>();
36   state->uts20_screen = data & 1;
2537}
2638
2739static READ8_HANDLER( uts20_vram_r )
2840{
41   univac_state *state = space->machine->driver_data<univac_state>();
2942   UINT8 *RAM = memory_region(space->machine, "maincpu");
30   return RAM[offset | ((uts20_screen) ? 0xe000 : 0xc000)];
43   return RAM[offset | ((state->uts20_screen) ? 0xe000 : 0xc000)];
3144}
3245
3346static WRITE8_HANDLER( uts20_vram_w )
3447{
48   univac_state *state = space->machine->driver_data<univac_state>();
3549   UINT8 *RAM = memory_region(space->machine, "maincpu");
36   RAM[offset | ((uts20_screen) ? 0xe000 : 0xc000)] = data;
50   RAM[offset | ((state->uts20_screen) ? 0xe000 : 0xc000)] = data;
3751}
3852
3953
r9674r9675
5872
5973static MACHINE_RESET(uts20)
6074{
61   uts20_screen = 0;
75   univac_state *state = machine->driver_data<univac_state>();
76   state->uts20_screen = 0;
6277}
6378
6479static VIDEO_START( uts20 )
6580{
66   FNT = memory_region(machine, "chargen");
81   univac_state *state = machine->driver_data<univac_state>();
82   state->FNT = memory_region(machine, "chargen");
6783}
6884
6985static VIDEO_UPDATE( uts20 )
7086{
71   static UINT8 framecnt=0;
87   univac_state *state = screen->machine->driver_data<univac_state>();
7288   UINT8 y,ra,chr,gfx;
7389   UINT16 sy=0,ma=0,x;
74   UINT8 *videoram = memory_region(screen->machine, "maincpu")+((uts20_screen) ? 0xe000 : 0xc000);
90   UINT8 *videoram = memory_region(screen->machine, "maincpu")+((state->uts20_screen) ? 0xe000 : 0xc000);
7591
76   framecnt++;
92   state->framecnt++;
7793
7894   for (y = 0; y < 25; y++)
7995   {
r9674r9675
90106               chr = videoram[x];
91107
92108               /* Take care of flashing characters */
93               if ((chr & 0x80) && (framecnt & 0x08))
109               if ((chr & 0x80) && (state->framecnt & 0x08))
94110                  chr = 0x20;
95111
96112               chr &= 0x7f;
97113
98               gfx = FNT[(chr<<4) | ra ];
114               gfx = state->FNT[(chr<<4) | ra ];
99115            }
100116
101117            /* Display a scanline of a character */
r9674r9675
114130   return 0;
115131}
116132
117static MACHINE_CONFIG_START( uts20, driver_device )
133static MACHINE_CONFIG_START( uts20, univac_state )
118134    /* basic machine hardware */
119135    MDRV_CPU_ADD("maincpu",Z80, XTAL_4MHz)
120136    MDRV_CPU_PROGRAM_MAP(uts20_mem)
src/mess/drivers/mikro80.c
r9674r9675
2121static ADDRESS_MAP_START(mikro80_mem, ADDRESS_SPACE_PROGRAM, 8)
2222   AM_RANGE( 0x0000, 0x07ff ) AM_RAMBANK("bank1") // First bank
2323    AM_RANGE( 0x0800, 0xdfff ) AM_RAM  // RAM
24    AM_RANGE( 0xe000, 0xe7ff ) AM_RAM  AM_BASE(&mikro80_cursor_ram)// Video RAM
25    AM_RANGE( 0xe800, 0xefff ) AM_RAM  AM_BASE(&mikro80_video_ram) // Video RAM
24    AM_RANGE( 0xe000, 0xe7ff ) AM_RAM  AM_BASE_MEMBER(mikro80_state, cursor_ram)// Video RAM
25    AM_RANGE( 0xe800, 0xefff ) AM_RAM  AM_BASE_MEMBER(mikro80_state, video_ram) // Video RAM
2626    AM_RANGE( 0xd000, 0xf7ff ) AM_RAM  // RAM
2727    AM_RANGE( 0xf800, 0xffff ) AM_ROM  // System ROM
2828ADDRESS_MAP_END
r9674r9675
165165   GFXDECODE_ENTRY( "gfx1", 0x0000, mikro80_charlayout, 0, 1 )
166166GFXDECODE_END
167167
168static MACHINE_CONFIG_START( mikro80, driver_device )
168static MACHINE_CONFIG_START( mikro80, mikro80_state )
169169   /* basic machine hardware */
170170   MDRV_CPU_ADD("maincpu",I8080, 2000000)
171171   MDRV_CPU_PROGRAM_MAP(mikro80_mem)
src/mess/drivers/mz80.c
r9674r9675
258258
259259static TIMER_DEVICE_CALLBACK( ne555_tempo_callback )
260260{
261   mz80k_tempo_strobe ^= 1;
261   mz80_state *state = timer.machine->driver_data<mz80_state>();
262   state->mz80k_tempo_strobe ^= 1;
262263}
263264
264static MACHINE_CONFIG_START( mz80k, driver_device )
265static MACHINE_CONFIG_START( mz80k, mz80_state )
265266   /* basic machine hardware */
266267
267268   /* main CPU */
src/mess/drivers/svision.c
r9674r9675
1919
2020
2121// in pixel
22#define XSIZE (svision_reg[0]&~3)
23#define XPOS svision_reg[2]
24#define YPOS svision_reg[3]
25#define BANK svision_reg[0x26]
22#define XSIZE (state->reg[0]&~3)
23#define XPOS state->reg[2]
24#define YPOS state->reg[3]
25#define BANK state->reg[0x26]
2626
27static UINT8 *svision_reg;
28static running_device *svision_sound;
29static int *dma_finished;
3027
31static struct
32{
33   emu_timer *timer1;
34   int timer_shot;
35} svision;
36
37static struct
38{
39   int state;
40   int on, clock, data;
41   UINT8 input;
42   emu_timer *timer;
43} svision_pet;
44
45static struct
46{
47   UINT16 palette[4/*0x40?*/]; /* rgb8 */
48   int palette_on;
49} tvlink;
50
5128static TIMER_CALLBACK(svision_pet_timer)
5229{
53   switch (svision_pet.state)
30   svision_state *state = machine->driver_data<svision_state>();
31   switch (state->pet.state)
5432   {
5533      case 0:
56         svision_pet.input = input_port_read(machine, "JOY2");
34         state->pet.input = input_port_read(machine, "JOY2");
5735         /* fall through */
5836
5937      case 2: case 4: case 6: case 8:
6038      case 10: case 12: case 14:
61         svision_pet.clock=svision_pet.state&2;
62         svision_pet.data=svision_pet.input&1;
63         svision_pet.input>>=1;
64         svision_pet.state++;
39         state->pet.clock=state->pet.state&2;
40         state->pet.data=state->pet.input&1;
41         state->pet.input>>=1;
42         state->pet.state++;
6543         break;
6644
6745      case 16+15:
68         svision_pet.state = 0;
46         state->pet.state = 0;
6947         break;
7048
7149      default:
72         svision_pet.state++;
50         state->pet.state++;
7351         break;
7452   }
7553}
7654
7755void svision_irq(running_machine *machine)
7856{
79   int irq = svision.timer_shot && (BANK & 2);
80   irq = irq || (*dma_finished && (BANK & 4));
57   svision_state *state = machine->driver_data<svision_state>();
58   int irq = state->svision.timer_shot && (BANK & 2);
59   irq = irq || (*state->dma_finished && (BANK & 4));
8160
8261   cputag_set_input_line(machine, "maincpu", M6502_IRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
8362}
8463
8564static TIMER_CALLBACK(svision_timer)
8665{
87    svision.timer_shot = TRUE;
88    timer_enable(svision.timer1, FALSE);
66   svision_state *state = machine->driver_data<svision_state>();
67    state->svision.timer_shot = TRUE;
68    timer_enable(state->svision.timer1, FALSE);
8969    svision_irq( machine );
9070}
9171
9272static READ8_HANDLER(svision_r)
9373{
94   int data = svision_reg[offset];
74   svision_state *state = space->machine->driver_data<svision_state>();
75   int data = state->reg[offset];
9576   switch (offset)
9677   {
9778      case 0x20:
r9674r9675
9980         break;
10081      case 0x21:
10182         data &= ~0xf;
102         data |= svision_reg[0x22] & 0xf;
103         if (svision_pet.on)
83         data |= state->reg[0x22] & 0xf;
84         if (state->pet.on)
10485         {
105            if (!svision_pet.clock)
86            if (!state->pet.clock)
10687               data &= ~4;
107            if (!svision_pet.data)
88            if (!state->pet.data)
10889               data &= ~8;
10990         }
11091         break;
11192      case 0x27:
11293         data &= ~3;
113         if (svision.timer_shot)
94         if (state->svision.timer_shot)
11495            data|=1;
115         if (*dma_finished)
96         if (*state->dma_finished)
11697            data|=2;
11798         break;
11899      case 0x24:
119         svision.timer_shot = FALSE;
100         state->svision.timer_shot = FALSE;
120101         svision_irq( space->machine );
121102         break;
122103      case 0x25:
123         *dma_finished = FALSE;
104         *state->dma_finished = FALSE;
124105         svision_irq( space->machine );
125106         break;
126107      default:
r9674r9675
133114
134115static WRITE8_HANDLER(svision_w)
135116{
117   svision_state *state = space->machine->driver_data<svision_state>();
136118   int value;
137119   int delay;
138120
139   svision_reg[offset] = data;
121   state->reg[offset] = data;
140122
141123   switch (offset)
142124   {
r9674r9675
145127         break;
146128      case 0x26: /* bits 5,6 memory management for a000? */
147129         logerror("%.6f svision write %04x %02x\n", attotime_to_double(timer_get_time(space->machine)),offset,data);
148         memory_set_bankptr(space->machine, "bank1", memory_region(space->machine, "user1") + ((svision_reg[0x26] & 0xe0) << 9));
130         memory_set_bankptr(space->machine, "bank1", memory_region(space->machine, "user1") + ((state->reg[0x26] & 0xe0) << 9));
149131         svision_irq( space->machine );
150132         break;
151133      case 0x23: /* delta hero irq routine write */
r9674r9675
156138            delay = 16384;
157139         else
158140            delay = 256;
159         timer_enable(svision.timer1, TRUE);
160         timer_reset(svision.timer1, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime(value * delay));
141         timer_enable(state->svision.timer1, TRUE);
142         timer_reset(state->svision.timer1, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime(value * delay));
161143         break;
162144      case 0x10: case 0x11: case 0x12: case 0x13:
163         svision_soundport_w(svision_sound, 0, offset & 3, data);
145         svision_soundport_w(state->sound, 0, offset & 3, data);
164146         break;
165147      case 0x14: case 0x15: case 0x16: case 0x17:
166         svision_soundport_w(svision_sound, 1, offset & 3, data);
148         svision_soundport_w(state->sound, 1, offset & 3, data);
167149         break;
168150      case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c:
169         svision_sounddma_w(svision_sound, offset - 0x18, data);
151         svision_sounddma_w(state->sound, offset - 0x18, data);
170152         break;
171153      case 0x28: case 0x29: case 0x2a:
172         svision_noise_w(svision_sound, offset - 0x28, data);
154         svision_noise_w(state->sound, offset - 0x28, data);
173155         break;
174156      default:
175157         logerror("%.6f svision write %04x %02x\n", attotime_to_double(timer_get_time(space->machine)), offset, data);
r9674r9675
196178
197179static WRITE8_HANDLER(tvlink_w)
198180{
181   svision_state *state = space->machine->driver_data<svision_state>();
199182   switch (offset)
200183   {
201184      case 0x0e:
202         svision_reg[offset] = data;
203         tvlink.palette_on = data & 1;
204         if (tvlink.palette_on)
185         state->reg[offset] = data;
186         state->tvlink.palette_on = data & 1;
187         if (state->tvlink.palette_on)
205188         {
206189            // hack, normally initialising with palette from ram
207            tvlink.palette[0] = MAKE12_RGB15(163/16,172/16,115/16); // these are the tron colors messured from screenshot
208            tvlink.palette[1] = MAKE12_RGB15(163/16,155/16,153/16);
209            tvlink.palette[2] = MAKE12_RGB15(77/16,125/16,73/16);
210            tvlink.palette[3] = MAKE12_RGB15(59/16,24/16,20/16);
190            state->tvlink.palette[0] = MAKE12_RGB15(163/16,172/16,115/16); // these are the tron colors messured from screenshot
191            state->tvlink.palette[1] = MAKE12_RGB15(163/16,155/16,153/16);
192            state->tvlink.palette[2] = MAKE12_RGB15(77/16,125/16,73/16);
193            state->tvlink.palette[3] = MAKE12_RGB15(59/16,24/16,20/16);
211194         }
212195         else
213196         {
214197            // cleaner to use colors from compile time palette, or compose from "fixed" palette values
215            tvlink.palette[0]=MAKE12_RGB15(0,0,0);
216            tvlink.palette[1]=MAKE12_RGB15(5*16/256,18*16/256,9*16/256);
217            tvlink.palette[2]=MAKE12_RGB15(48*16/256,76*16/256,100*16/256);
218            tvlink.palette[3]=MAKE12_RGB15(190*16/256,190*16/256,190*16/256);
198            state->tvlink.palette[0]=MAKE12_RGB15(0,0,0);
199            state->tvlink.palette[1]=MAKE12_RGB15(5*16/256,18*16/256,9*16/256);
200            state->tvlink.palette[2]=MAKE12_RGB15(48*16/256,76*16/256,100*16/256);
201            state->tvlink.palette[3]=MAKE12_RGB15(190*16/256,190*16/256,190*16/256);
219202         }
220203         break;
221204      default:
r9674r9675
226209            if (offset == 0x803 && data == 0x07)
227210            {
228211               /* tron hack */
229               svision_reg[0x0804]=0x00;
230               svision_reg[0x0805]=0x01;
231               svision_reg[0x0806]=0x00;
232               svision_reg[0x0807]=0x00;
212               state->reg[0x0804]=0x00;
213               state->reg[0x0805]=0x01;
214               state->reg[0x0806]=0x00;
215               state->reg[0x0807]=0x00;
233216            }
234            c = svision_reg[0x800] | (svision_reg[0x804] << 8);
235            tvlink.palette[0] = MAKE9_RGB15( (c>>0)&7, (c>>3)&7, (c>>6)&7);
236            c = svision_reg[0x801] | (svision_reg[0x805] << 8);
237            tvlink.palette[1] = MAKE9_RGB15( (c>>0)&7, (c>>3)&7, (c>>6)&7);
238            c = svision_reg[0x802] | (svision_reg[0x806]<<8);
239            tvlink.palette[2]=MAKE9_RGB15( (c>>0)&7, (c>>3)&7, (c>>6)&7);
240            c = svision_reg[0x803] | (svision_reg[0x807]<<8);
241            tvlink.palette[3]=MAKE9_RGB15( (c>>0)&7, (c>>3)&7, (c>>6)&7);
217            c = state->reg[0x800] | (state->reg[0x804] << 8);
218            state->tvlink.palette[0] = MAKE9_RGB15( (c>>0)&7, (c>>3)&7, (c>>6)&7);
219            c = state->reg[0x801] | (state->reg[0x805] << 8);
220            state->tvlink.palette[1] = MAKE9_RGB15( (c>>0)&7, (c>>3)&7, (c>>6)&7);
221            c = state->reg[0x802] | (state->reg[0x806]<<8);
222            state->tvlink.palette[2]=MAKE9_RGB15( (c>>0)&7, (c>>3)&7, (c>>6)&7);
223            c = state->reg[0x803] | (state->reg[0x807]<<8);
224            state->tvlink.palette[3]=MAKE9_RGB15( (c>>0)&7, (c>>3)&7, (c>>6)&7);
242225            /* writes to palette effect video color immediately */
243226            /* some writes modify other registers, */
244227            /* encoding therefor not known (rgb8 or rgb9) */
r9674r9675
248231
249232static ADDRESS_MAP_START( svision_mem , ADDRESS_SPACE_PROGRAM, 8)
250233   AM_RANGE( 0x0000, 0x1fff) AM_RAM
251   AM_RANGE( 0x2000, 0x3fff) AM_READWRITE(svision_r, svision_w) AM_BASE(&svision_reg)
234   AM_RANGE( 0x2000, 0x3fff) AM_READWRITE(svision_r, svision_w) AM_BASE_MEMBER(svision_state, reg)
252235   AM_RANGE( 0x4000, 0x5fff) AM_RAM AM_BASE_MEMBER(svision_state, videoram)
253236   AM_RANGE( 0x6000, 0x7fff) AM_NOP
254237   AM_RANGE( 0x8000, 0xbfff) AM_ROMBANK("bank1")
r9674r9675
257240
258241static ADDRESS_MAP_START( tvlink_mem , ADDRESS_SPACE_PROGRAM, 8)
259242   AM_RANGE( 0x0000, 0x1fff) AM_RAM
260   AM_RANGE( 0x2000, 0x3fff) AM_READWRITE(tvlink_r, tvlink_w) AM_BASE(&svision_reg)
243   AM_RANGE( 0x2000, 0x3fff) AM_READWRITE(tvlink_r, tvlink_w) AM_BASE_MEMBER(svision_state, reg)
261244   AM_RANGE( 0x4000, 0x5fff) AM_RAM AM_BASE_MEMBER(svision_state, videoram)
262245   AM_RANGE( 0x6000, 0x7fff) AM_NOP
263246   AM_RANGE( 0x8000, 0xbfff) AM_ROMBANK("bank1")
r9674r9675
412395         for (x = 3 - (XPOS & 3), i = 0; x < 160 + 3 && x < XSIZE + 3; x += 4, i++)
413396         {
414397            UINT8 b=videoram[j+i];
415            line[3]=tvlink.palette[(b>>6)&3];
416            line[2]=tvlink.palette[(b>>4)&3];
417            line[1]=tvlink.palette[(b>>2)&3];
418            line[0]=tvlink.palette[(b>>0)&3];
398            line[3]=state->tvlink.palette[(b>>6)&3];
399            line[2]=state->tvlink.palette[(b>>4)&3];
400            line[1]=state->tvlink.palette[(b>>2)&3];
401            line[0]=state->tvlink.palette[(b>>0)&3];
419402            line+=4;
420403         }
421404         j += 0x30;
r9674r9675
432415
433416static INTERRUPT_GEN( svision_frame_int )
434417{
418   svision_state *state = device->machine->driver_data<svision_state>();
435419   if (BANK&1)
436420      cpu_set_input_line(device, INPUT_LINE_NMI, PULSE_LINE);
437421
438   svision_sound_decrement(svision_sound);
422   svision_sound_decrement(state->sound);
439423}
440424
441425static DRIVER_INIT( svision )
442426{
443   svision.timer1 = timer_alloc(machine, svision_timer, NULL);
444   svision_sound = machine->device("custom");
445   dma_finished = svision_dma_finished(svision_sound);
446   svision_pet.on = FALSE;
427   svision_state *state = machine->driver_data<svision_state>();
428   state->svision.timer1 = timer_alloc(machine, svision_timer, NULL);
429   state->sound = machine->device("custom");
430   state->dma_finished = svision_dma_finished(state->sound);
431   state->pet.on = FALSE;
447432   memory_set_bankptr(machine, "bank2", memory_region(machine, "user1") + 0x1c000);
448433}
449434
450435static DRIVER_INIT( svisions )
451436{
452   svision.timer1 = timer_alloc(machine, svision_timer, NULL);
453   svision_sound = machine->device("custom");
454   dma_finished = svision_dma_finished(svision_sound);
437   svision_state *state = machine->driver_data<svision_state>();
438   state->svision.timer1 = timer_alloc(machine, svision_timer, NULL);
439   state->sound = machine->device("custom");
440   state->dma_finished = svision_dma_finished(state->sound);
455441   memory_set_bankptr(machine, "bank2", memory_region(machine, "user1") + 0x1c000);
456   svision.timer1 = timer_alloc(machine, svision_timer, NULL);
457   svision_pet.on = TRUE;
458   svision_pet.timer = timer_alloc(machine, svision_pet_timer, NULL);
442   state->svision.timer1 = timer_alloc(machine, svision_timer, NULL);
443   state->pet.on = TRUE;
444   state->pet.timer = timer_alloc(machine, svision_pet_timer, NULL);
459445   timer_pulse(machine, attotime_mul(ATTOTIME_IN_SEC(8), 256/cputag_get_clock(machine, "maincpu")), NULL, 0, svision_pet_timer);
460446}
461447
r9674r9675
504490
505491static MACHINE_RESET( svision )
506492{
507   svision.timer_shot = FALSE;
508   *dma_finished = FALSE;
493   svision_state *state = machine->driver_data<svision_state>();
494   state->svision.timer_shot = FALSE;
495   *state->dma_finished = FALSE;
509496   memory_set_bankptr(machine, "bank1", memory_region(machine, "user1"));
510497}
511498
512499
513500static MACHINE_RESET( tvlink )
514501{
515   svision.timer_shot = FALSE;
516   *dma_finished = FALSE;
502   svision_state *state = machine->driver_data<svision_state>();
503   state->svision.timer_shot = FALSE;
504   *state->dma_finished = FALSE;
517505   memory_set_bankptr(machine, "bank1", memory_region(machine, "user1"));
518   tvlink.palette_on = FALSE;
506   state->tvlink.palette_on = FALSE;
519507
520   memset(svision_reg + 0x800, 0xff, 0x40); // normally done from tvlink microcontroller
521   svision_reg[0x82a] = 0xdf;
508   memset(state->reg + 0x800, 0xff, 0x40); // normally done from state->tvlink microcontroller
509   state->reg[0x82a] = 0xdf;
522510
523   tvlink.palette[0] = MAKE24_RGB15(svisionp_palette[(PALETTE_START+0)*3+0], svisionp_palette[(PALETTE_START+0)*3+1], svisionp_palette[(PALETTE_START+0)*3+2]);
524   tvlink.palette[1] = MAKE24_RGB15(svisionp_palette[(PALETTE_START+1)*3+0], svisionp_palette[(PALETTE_START+1)*3+1], svisionp_palette[(PALETTE_START+1)*3+2]);
525   tvlink.palette[2] = MAKE24_RGB15(svisionp_palette[(PALETTE_START+2)*3+0], svisionp_palette[(PALETTE_START+2)*3+1], svisionp_palette[(PALETTE_START+2)*3+2]);
526   tvlink.palette[3] = MAKE24_RGB15(svisionp_palette[(PALETTE_START+3)*3+0], svisionp_palette[(PALETTE_START+3)*3+1], svisionp_palette[(PALETTE_START+3)*3+2]);
511   state->tvlink.palette[0] = MAKE24_RGB15(svisionp_palette[(PALETTE_START+0)*3+0], svisionp_palette[(PALETTE_START+0)*3+1], svisionp_palette[(PALETTE_START+0)*3+2]);
512   state->tvlink.palette[1] = MAKE24_RGB15(svisionp_palette[(PALETTE_START+1)*3+0], svisionp_palette[(PALETTE_START+1)*3+1], svisionp_palette[(PALETTE_START+1)*3+2]);
513   state->tvlink.palette[2] = MAKE24_RGB15(svisionp_palette[(PALETTE_START+2)*3+0], svisionp_palette[(PALETTE_START+2)*3+1], svisionp_palette[(PALETTE_START+2)*3+2]);
514   state->tvlink.palette[3] = MAKE24_RGB15(svisionp_palette[(PALETTE_START+3)*3+0], svisionp_palette[(PALETTE_START+3)*3+1], svisionp_palette[(PALETTE_START+3)*3+2]);
527515}
528516
529517static MACHINE_CONFIG_START( svision, svision_state )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team