Previous 15994 Revisions Next

r9649 Tuesday 23rd November, 2010 at 23:14:35 UTC by Nathan Woods
Added driver_device state to many drivers. [Atari Ace]
[docs]messnew.txt
[src/mess/drivers]a7800.c adam.c aim65.c amstrad.c apple1.c apple2.c apple2gs.c apple3.c aquarius.c atom.c avigo.c
[src/mess/includes]a7800.h adam.h aim65.h amstrad.h apple1.h apple2.h apple2gs.h apple3.h aquarius.h atom.h avigo.h
[src/mess/machine]a7800.c adam.c aim65.c amstrad.c apple1.c apple2gs.c apple3.c
[src/mess/video]a7800.c aim65.c apple1.c apple2gs.c apple3.c aquarius.c avigo.c

src/mess/machine/apple3.c
r9648r9649
2424#include "machine/6551.h"
2525#include "devices/messram.h"
2626
27UINT32 apple3_flags;
2827
2928static void apple3_update_drives(running_device *device);
3029
31static UINT8 via_0_a;
32static UINT8 via_0_b;
33static UINT8 via_1_a;
34static UINT8 via_1_b;
35static int via_1_irq;
36static int apple3_enable_mask;
37static offs_t zpa;
3830
3931#define LOG_MEMORY      1
4032#define LOG_INDXADDR   1
r9648r9649
4335
4436/* ----------------------------------------------------------------------- */
4537
46static int profile_lastaddr;
47static UINT8 profile_gotstrobe;
48static UINT8 profile_readdata;
49static UINT8 profile_busycount;
50static UINT8 profile_busy;
51static UINT8 profile_online;
52static UINT8 profile_writedata;
5338
5439static void apple3_profile_init(void)
5540{
r9648r9649
6348
6449
6550
66static UINT8 apple3_profile_r(offs_t offset)
51static UINT8 apple3_profile_r(apple3_state *state, offs_t offset)
6752{
6853   UINT8 result = 0;
6954
7055   offset %= 4;
7156   apple3_profile_statemachine();
7257
73   profile_lastaddr = offset;
58   state->profile_lastaddr = offset;
7459
7560   switch(offset)
7661   {
7762      case 1:
78         profile_gotstrobe = 1;
63         state->profile_gotstrobe = 1;
7964         apple3_profile_statemachine();
80         result = profile_readdata;
65         result = state->profile_readdata;
8166         break;
8267
8368      case 2:
84         if (profile_busycount > 0)
69         if (state->profile_busycount > 0)
8570         {
86            profile_busycount--;
71            state->profile_busycount--;
8772            result = 0xFF;
8873         }
8974         else
9075         {
91            result = profile_busy | profile_online;
76            result = state->profile_busy | state->profile_online;
9277         }
9378         break;
9479   }
r9648r9649
9782
9883
9984
100static void apple3_profile_w(offs_t offset, UINT8 data)
85static void apple3_profile_w(apple3_state *state, offs_t offset, UINT8 data)
10186{
10287   offset %= 4;
103   profile_lastaddr = -1;
88   state->profile_lastaddr = -1;
10489
10590   switch(offset)
10691   {
10792      case 0:
108         profile_writedata = data;
109         profile_gotstrobe = 1;
93         state->profile_writedata = data;
94         state->profile_gotstrobe = 1;
11095         break;
11196   }
11297   apple3_profile_statemachine();
r9648r9649
118103
119104static READ8_HANDLER( apple3_c0xx_r )
120105{
106   apple3_state *state = space->machine->driver_data<apple3_state>();
121107   running_device *acia = space->machine->device("acia");
122108   running_device *fdc = space->machine->device("fdc");
123109   UINT8 result = 0xFF;
r9648r9649
146132      case 0x54: case 0x55: case 0x56: case 0x57:
147133         /* graphics softswitches */
148134         if (offset & 1)
149            apple3_flags |= 1 << ((offset - 0x50) / 2);
135            state->flags |= 1 << ((offset - 0x50) / 2);
150136         else
151            apple3_flags &= ~(1 << ((offset - 0x50) / 2));
137            state->flags &= ~(1 << ((offset - 0x50) / 2));
152138         break;
153139
154140      case 0x60: case 0x61: case 0x62: case 0x63:
r9648r9649
164150      case 0xC8: case 0xC9: case 0xCA: case 0xCB:
165151      case 0xCC: case 0xCD: case 0xCE: case 0xCF:
166152         /* profile */
167         result = apple3_profile_r(offset);
153         result = apple3_profile_r(state, offset);
168154         break;
169155
170156      case 0xD0: case 0xD1: case 0xD2: case 0xD3:
171157      case 0xD4: case 0xD5: case 0xD6: case 0xD7:
172158         /* external drive stuff */
173159         if (offset & 1)
174            apple3_flags |= VAR_EXTA0 << ((offset - 0xD0) / 2);
160            state->flags |= VAR_EXTA0 << ((offset - 0xD0) / 2);
175161         else
176            apple3_flags &= ~(VAR_EXTA0 << ((offset - 0xD0) / 2));
162            state->flags &= ~(VAR_EXTA0 << ((offset - 0xD0) / 2));
177163         apple3_update_drives(space->machine->device("fdc"));
178164         result = 0x00;
179165         break;
r9648r9649
203189
204190static WRITE8_HANDLER( apple3_c0xx_w )
205191{
192   apple3_state *state = space->machine->driver_data<apple3_state>();
206193   running_device *acia = space->machine->device("acia");
207194   running_device *fdc = space->machine->device("fdc");
208195   switch(offset)
r9648r9649
218205      case 0x54: case 0x55: case 0x56: case 0x57:
219206         /* graphics softswitches */
220207         if (offset & 1)
221            apple3_flags |= 1 << ((offset - 0x50) / 2);
208            state->flags |= 1 << ((offset - 0x50) / 2);
222209         else
223            apple3_flags &= ~(1 << ((offset - 0x50) / 2));
210            state->flags &= ~(1 << ((offset - 0x50) / 2));
224211         break;
225212
226213      case 0xC0: case 0xC1: case 0xC2: case 0xC3:
r9648r9649
228215      case 0xC8: case 0xC9: case 0xCA: case 0xCB:
229216      case 0xCC: case 0xCD: case 0xCE: case 0xCF:
230217         /* profile */
231         apple3_profile_w(offset, data);
218         apple3_profile_w(state, offset, data);
232219         break;
233220
234221      case 0xD0: case 0xD1: case 0xD2: case 0xD3:
235222      case 0xD4: case 0xD5: case 0xD6: case 0xD7:
236223         /* external drive stuff */
237224         if (offset & 1)
238            apple3_flags |= VAR_EXTA0 << ((offset - 0xD0) / 2);
225            state->flags |= VAR_EXTA0 << ((offset - 0xD0) / 2);
239226         else
240            apple3_flags &= ~(VAR_EXTA0 << ((offset - 0xD0) / 2));
227            state->flags &= ~(VAR_EXTA0 << ((offset - 0xD0) / 2));
241228         apple3_update_drives(space->machine->device("fdc"));
242229         break;
243230
r9648r9649
308295
309296static UINT8 *apple3_get_zpa_addr(running_machine *machine,offs_t offset)
310297{
311   zpa = (((offs_t) via_0_b) * 0x100) + offset;
298   apple3_state *state = machine->driver_data<apple3_state>();
299   state->zpa = (((offs_t) state->via_0_b) * 0x100) + offset;
312300
313   if (via_0_b < 0x20)
314      return apple3_bankaddr(machine,~0, zpa);
315   else if (via_0_b > 0x9F)
316      return apple3_bankaddr(machine,~0, zpa - 0x8000);
301   if (state->via_0_b < 0x20)
302      return apple3_bankaddr(machine,~0, state->zpa);
303   else if (state->via_0_b > 0x9F)
304      return apple3_bankaddr(machine,~0, state->zpa - 0x8000);
317305   else
318      return apple3_bankaddr(machine,via_1_a, zpa - 0x2000);
306      return apple3_bankaddr(machine,state->via_1_a, state->zpa - 0x2000);
319307}
320308
321309
r9648r9649
336324
337325static void apple3_update_memory(running_machine *machine)
338326{
327   apple3_state *state = machine->driver_data<apple3_state>();
339328   UINT16 bank;
340329   UINT8 page;
341330   address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
342331
343332   if (LOG_MEMORY)
344333   {
345      logerror("apple3_update_memory(): via_0_b=0x%02x via_1_a=0x0x%02x\n", via_0_b, via_1_a);
334      logerror("apple3_update_memory(): state->via_0_b=0x%02x state->via_1_a=0x0x%02x\n", state->via_0_b, state->via_1_a);
346335   }
347336
348   cputag_set_clock(machine, "maincpu", (via_0_a & 0x80) ? 1000000 : 2000000);
337   cputag_set_clock(machine, "maincpu", (state->via_0_a & 0x80) ? 1000000 : 2000000);
349338
350339   /* bank 2 (0100-01FF) */
351   if (!(via_0_a & 0x04))
340   if (!(state->via_0_a & 0x04))
352341   {
353      if (via_0_b < 0x20)
342      if (state->via_0_b < 0x20)
354343      {
355344         bank = ~0;   /* system bank */
356         page = via_0_b ^ 0x01;
345         page = state->via_0_b ^ 0x01;
357346      }
358      else if (via_0_b >= 0xA0)
347      else if (state->via_0_b >= 0xA0)
359348      {
360349         bank = ~0;   /* system bank */
361         page = (via_0_b ^ 0x01) - 0x80;
350         page = (state->via_0_b ^ 0x01) - 0x80;
362351      }
363352      else
364353      {
365         bank = via_1_a;
366         page = (via_0_b ^ 0x01) - 0x20;
354         bank = state->via_1_a;
355         page = (state->via_0_b ^ 0x01) - 0x20;
367356      }
368357   }
369358   else
r9648r9649
377366   apple3_setbank(machine,"bank3", ~0, 0x0200);
378367
379368   /* bank 4 (2000-9FFF) */
380   apple3_setbank(machine,"bank4", via_1_a, 0x0000);
369   apple3_setbank(machine,"bank4", state->via_1_a, 0x0000);
381370
382371   /* bank 5 (A000-BFFF) */
383372   apple3_setbank(machine,"bank5", ~0, 0x2000);
384373
385374   /* install bank 8 (C000-CFFF) */
386   if (via_0_a & 0x40)
375   if (state->via_0_a & 0x40)
387376   {
388377      memory_install_read8_handler(space, 0xC000, 0xC0FF, 0, 0, apple3_c0xx_r);
389378      memory_install_write8_handler(space, 0xC000, 0xC0FF, 0, 0, apple3_c0xx_w);
r9648r9649
391380   else
392381   {
393382      memory_install_read_bank(space, 0xC000, 0xC0FF, 0, 0, "bank8");
394      if (via_0_a & 0x08)
383      if (state->via_0_a & 0x08)
395384         memory_unmap_write(space, 0xC000, 0xC0FF, 0, 0);
396385      else
397386         memory_install_write_bank(space, 0xC000, 0xC0FF, 0, 0, "bank8");
r9648r9649
399388   }
400389
401390   /* install bank 9 (C100-C4FF) */
402   if (via_0_a & 0x40)
391   if (state->via_0_a & 0x40)
403392   {
404393      memory_nop_readwrite(space, 0xC100, 0xC4FF, 0, 0);
405394   }
406395   else
407396   {
408397      memory_install_read_bank(space, 0xC100, 0xC4FF, 0, 0, "bank9");
409      if (via_0_a & 0x08)
398      if (state->via_0_a & 0x08)
410399         memory_unmap_write(space, 0xC100, 0xC4FF, 0, 0);
411400      else
412401         memory_install_write_bank(space, 0xC100, 0xC4FF, 0, 0, "bank9");
r9648r9649
415404
416405   /* install bank 10 (C500-C7FF) */
417406   memory_install_read_bank(space, 0xC500, 0xC7FF, 0, 0, "bank10");
418   if (via_0_a & 0x08)
407   if (state->via_0_a & 0x08)
419408      memory_unmap_write(space, 0xC500, 0xC7FF, 0, 0);
420409   else
421410      memory_install_write_bank(space, 0xC500, 0xC7FF, 0, 0, "bank10");
422411   apple3_setbank(machine,"bank10", ~0, 0x4500);
423412
424413   /* install bank 11 (C800-CFFF) */
425   if (via_0_a & 0x40)
414   if (state->via_0_a & 0x40)
426415   {
427416      memory_nop_readwrite(space, 0xC800, 0xCFFF, 0, 0);
428417   }
429418   else
430419   {
431420      memory_install_read_bank(space, 0xC800, 0xCFFF, 0, 0, "bank11");
432      if (via_0_a & 0x08)
421      if (state->via_0_a & 0x08)
433422         memory_unmap_write(space, 0xC800, 0xCFFF, 0, 0);
434423      else
435424         memory_install_write_bank(space, 0xC800, 0xCFFF, 0, 0, "bank11");
r9648r9649
438427
439428   /* install bank 6 (D000-EFFF) */
440429   memory_install_read_bank(space, 0xD000, 0xEFFF, 0, 0, "bank6");
441   if (via_0_a & 0x08)
430   if (state->via_0_a & 0x08)
442431      memory_unmap_write(space, 0xD000, 0xEFFF, 0, 0);
443432   else
444433      memory_install_write_bank(space, 0xD000, 0xEFFF, 0, 0, "bank6");
r9648r9649
446435
447436   /* install bank 7 (F000-FFFF) */
448437   memory_install_read_bank(space, 0xF000, 0xFFFF, 0, 0, "bank7");
449   if (via_0_a & 0x09)
438   if (state->via_0_a & 0x09)
450439      memory_unmap_write(space, 0xF000, 0xFFFF, 0, 0);
451440   else
452441      memory_install_write_bank(space, 0xF000, 0xFFFF, 0, 0, "bank7");
453   if (via_0_a & 0x01)
442   if (state->via_0_a & 0x01)
454443      memory_set_bankptr(machine,"bank7", memory_region(machine, "maincpu"));
455444   else
456445      apple3_setbank(machine,"bank7", ~0, 0x7000);
r9648r9649
481470static READ8_DEVICE_HANDLER(apple3_via_1_in_a) { return ~0; }
482471static READ8_DEVICE_HANDLER(apple3_via_1_in_b) { return ~0; }
483472
484static WRITE8_DEVICE_HANDLER(apple3_via_0_out_a) { apple3_via_out(device->machine, &via_0_a, data); }
485static WRITE8_DEVICE_HANDLER(apple3_via_0_out_b) { apple3_via_out(device->machine, &via_0_b, data); }
486static WRITE8_DEVICE_HANDLER(apple3_via_1_out_a) { apple3_via_out(device->machine, &via_1_a, data); }
487static WRITE8_DEVICE_HANDLER(apple3_via_1_out_b) { apple3_via_out(device->machine, &via_1_b, data); }
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); }
488481
489482static void apple2_via_1_irq_func(running_device *device, int state)
490483{
491   if (!via_1_irq && state)
484   apple3_state *drvstate = device->machine->driver_data<apple3_state>();
485   if (!drvstate->via_1_irq && state)
492486   {
493487      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, ASSERT_LINE);
494488      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, CLEAR_LINE);
495489   }
496   via_1_irq = state;
490   drvstate->via_1_irq = state;
497491}
498492
499493const via6522_interface apple3_via_0_intf =
r9648r9649
540534
541535static UINT8 *apple3_get_indexed_addr(running_machine *machine,offs_t offset)
542536{
537   apple3_state *state = machine->driver_data<apple3_state>();
543538   UINT8 n;
544539   UINT8 *result = NULL;
545540
546   if ((via_0_b >= 0x18) && (via_0_b <= 0x1F))
541   if ((state->via_0_b >= 0x18) && (state->via_0_b <= 0x1F))
547542   {
548      n = *apple3_bankaddr(machine,~0, zpa ^ 0x0C00);
543      n = *apple3_bankaddr(machine,~0, state->zpa ^ 0x0C00);
549544
550545      if (LOG_INDXADDR)
551546      {
552         static UINT8 last_n;
553         if (last_n != n)
547         if (state->last_n != n)
554548         {
555            logerror("indxaddr: zpa=0x%04x n=0x%02x\n", zpa, n);
556            last_n = n;
549            logerror("indxaddr: state->zpa=0x%04x n=0x%02x\n", state->zpa, n);
550            state->last_n = n;
557551         }
558552      }
559553
r9648r9649
572566      else if ((n >= 0x80) && (n <= 0x8E))
573567      {
574568         if (offset < 0x0100)
575            result = apple3_bankaddr(machine,~0, ((offs_t) via_0_b) * 0x100 + offset);
569            result = apple3_bankaddr(machine,~0, ((offs_t) state->via_0_b) * 0x100 + offset);
576570         else
577571            result = apple3_bankaddr(machine,n, offset);
578572      }
r9648r9649
581575         if (offset < 0x2000)
582576            result = apple3_bankaddr(machine,~0, offset - 0x2000);
583577         else if (offset < 0xA000)
584            result = apple3_bankaddr(machine,via_1_a, offset - 0x2000);
578            result = apple3_bankaddr(machine,state->via_1_a, offset - 0x2000);
585579         else if (offset < 0xC000)
586580            result = apple3_bankaddr(machine,~0, offset - 0x8000);
587581         else if (offset < 0xD000)
r9648r9649
593587      }
594588      else if (offset < 0x0100)
595589      {
596         result = apple3_bankaddr(machine,~0, ((offs_t) via_0_b) * 0x100 + offset);
590         result = apple3_bankaddr(machine,~0, ((offs_t) state->via_0_b) * 0x100 + offset);
597591      }
598592   }
599   else if ((offset >= 0xF000) && (via_0_a & 0x01))
593   else if ((offset >= 0xF000) && (state->via_0_a & 0x01))
600594   {
601595#if 0
602596      /* The Apple /// Diagnostics seems to expect that indexed writes
r9648r9649
661655
662656static void apple3_update_drives(running_device *device)
663657{
658   apple3_state *state = device->machine->driver_data<apple3_state>();
664659   int enable_mask = 0x00;
665660
666   if (apple3_enable_mask & 0x01)
661   if (state->enable_mask & 0x01)
667662      enable_mask |= 0x01;
668663
669   if (apple3_enable_mask & 0x02)
664   if (state->enable_mask & 0x02)
670665   {
671      switch(apple3_flags & (VAR_EXTA0 | VAR_EXTA1))
666      switch(state->flags & (VAR_EXTA0 | VAR_EXTA1))
672667      {
673668         case VAR_EXTA0:
674669            enable_mask |= 0x02;
r9648r9649
689684
690685static void apple3_set_enable_lines(running_device *device,int enable_mask)
691686{
692   apple3_enable_mask = enable_mask;
687   apple3_state *state = device->machine->driver_data<apple3_state>();
688   state->enable_mask = enable_mask;
693689   apple3_update_drives(device);
694690}
695691
r9648r9649
707703
708704DRIVER_INIT( apple3 )
709705{
706   apple3_state *state = machine->driver_data<apple3_state>();
710707   /* hack to get around VIA problem */
711708   memory_region(machine, "maincpu")[0x0685] = 0x00;
712709
713   apple3_enable_mask = 0;
710   state->enable_mask = 0;
714711   apple3_update_drives(machine->device("fdc"));
715712
716713   AY3600_init(machine);
717714
718715   apple3_profile_init();
719716
720   apple3_flags = 0;
721   via_0_a = ~0;
722   via_1_a = ~0;
723   via_1_irq = 0;
717   state->flags = 0;
718   state->via_0_a = ~0;
719   state->via_1_a = ~0;
720   state->via_1_irq = 0;
724721   apple3_update_memory(machine);
725722
726723   cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(apple3_opbase, *machine));
src/mess/machine/adam.c
r9648r9649
1212#include "devices/flopdrv.h"
1313#include "devices/cartslot.h"
1414
15int adam_lower_memory; /* Lower 32k memory Z80 address configuration */
16int adam_upper_memory; /* Upper 32k memory Z80 address configuration */
17int adam_joy_stat[2];
18int adam_net_data; /* Data on AdamNet Bus */
19int adam_pcb;
2015
21static int joy_mode = 0;
2216
2317/* TODO: Are these digits correct? */
24static int KeyboardBuffer[20]; /* Buffer to store keys pressed */
2518static const int KbBufferCapacity = 15; /* Capacity of the Keyboard Buffer */
2619static const int KbRepeatDelay = 20;
2720
28static UINT8 KbRepeatTable[256];
2921
3022#ifdef UNUSED_FUNCTION
3123int adam_cart_verify(const UINT8 *cartdata, size_t size)
r9648r9649
4234}
4335#endif
4436
45void adam_clear_keyboard_buffer(void)
37void adam_clear_keyboard_buffer(running_machine *machine)
4638{
39   adam_state *state = machine->driver_data<adam_state>();
4740    int i;
4841
49    KeyboardBuffer[0] = 0; /* Keys on current buffer */
42    state->KeyboardBuffer[0] = 0; /* Keys on current buffer */
5043    for(i=1;i<KbBufferCapacity;i++)
5144    {
52        KeyboardBuffer[i] = 0; /* Key pressed */
45        state->KeyboardBuffer[i] = 0; /* Key pressed */
5346    }
5447    for(i=0;i<255;i++)
5548    {
56        KbRepeatTable[i]=0; /* Clear Key Repeat Table */
49        state->KbRepeatTable[i]=0; /* Clear Key Repeat Table */
5750    }
5851
5952}
6053
61static unsigned char getKeyFromBuffer(void)
54static unsigned char getKeyFromBuffer(adam_state *state)
6255{
6356   int i;
6457   UINT8 kbcode;
6558
66   kbcode=KeyboardBuffer[1];
67   for(i=1;i<KeyboardBuffer[0];i++)
59   kbcode=state->KeyboardBuffer[1];
60   for(i=1;i<state->KeyboardBuffer[0];i++)
6861   {
69      KeyboardBuffer[i]=KeyboardBuffer[i+1];
62      state->KeyboardBuffer[i]=state->KeyboardBuffer[i+1];
7063   }
71   KeyboardBuffer[KeyboardBuffer[0]]=0;
72   if (KeyboardBuffer[0]>0) KeyboardBuffer[0]--;
64   state->KeyboardBuffer[state->KeyboardBuffer[0]]=0;
65   if (state->KeyboardBuffer[0]>0) state->KeyboardBuffer[0]--;
7366   return kbcode;
7467}
7568
76static void addToKeyboardBuffer(unsigned char kbcode)
69static void addToKeyboardBuffer(adam_state *state, unsigned char kbcode)
7770{
78    if (KbRepeatTable[kbcode]==0)
71    if (state->KbRepeatTable[kbcode]==0)
7972    {
80        if ((KeyboardBuffer[0] < KbBufferCapacity))
73        if ((state->KeyboardBuffer[0] < KbBufferCapacity))
8174        {
82            KeyboardBuffer[0]++;
83            KeyboardBuffer[KeyboardBuffer[0]] = kbcode;
84            KbRepeatTable[kbcode]=255-KbRepeatDelay;
75            state->KeyboardBuffer[0]++;
76            state->KeyboardBuffer[state->KeyboardBuffer[0]] = kbcode;
77            state->KbRepeatTable[kbcode]=255-KbRepeatDelay;
8578        }
8679    }
8780}
8881
8982void adam_explore_keyboard(running_machine *machine)
9083{
84   adam_state *state = machine->driver_data<adam_state>();
9185    int controlKey, shiftKey;
9286    int i, keyboard[10];
9387
9488//logerror("Exploring Keyboard.............\n");
95    for(i=0;i<=255;i++) {if (KbRepeatTable[i]>0) KbRepeatTable[i]++;} /* Update repeat table */
89    for(i=0;i<=255;i++) {if (state->KbRepeatTable[i]>0) state->KbRepeatTable[i]++;} /* Update repeat table */
9690
9791    keyboard[0] = input_port_read(machine, "keyboard_1");
9892    keyboard[1] = input_port_read(machine, "keyboard_2");
r9648r9649
110104    controlKey = !(keyboard[9]&0x01);                                                /* Control */
111105    shiftKey = (!(keyboard[8]&0x40) || !(keyboard[8]&0x80) || !(keyboard[9]&0x04));  /* Left shiftKey or Right shiftKey or Lock */
112106
113    if (controlKey && !shiftKey && !(keyboard[4] & 0x04)) addToKeyboardBuffer(0x00); /* controlKey + 2 */
114    else {KbRepeatTable[0x00]=0;}
115    if (controlKey && !shiftKey && !(keyboard[0] & 0x02)) addToKeyboardBuffer(0x01); /* controlKey + A */
116    else {KbRepeatTable[0x01]=0;}
117    if (controlKey && !shiftKey && !(keyboard[0] & 0x04)) addToKeyboardBuffer(0x02); /* controlKey + B */
118    else {KbRepeatTable[0x02]=0;}
119    if (controlKey && !shiftKey && !(keyboard[0] & 0x08)) addToKeyboardBuffer(0x03); /* controlKey + C */
120    else {KbRepeatTable[0x03]=0;}
121    if (controlKey && !shiftKey && !(keyboard[0] & 0x10)) addToKeyboardBuffer(0x04); /* controlKey + D */
122    else {KbRepeatTable[0x04]=0;}
123    if (controlKey && !shiftKey && !(keyboard[0] & 0x20)) addToKeyboardBuffer(0x05); /* controlKey + E */
124    else {KbRepeatTable[0x05]=0;}
125    if (controlKey && !shiftKey && !(keyboard[0] & 0x40)) addToKeyboardBuffer(0x06); /* controlKey + F */
126    else {KbRepeatTable[0x06]=0;}
127    if (controlKey && !shiftKey && !(keyboard[0] & 0x80)) addToKeyboardBuffer(0x07); /* controlKey + G */
128    else {KbRepeatTable[0x07]=0;}
107    if (controlKey && !shiftKey && !(keyboard[4] & 0x04)) addToKeyboardBuffer(state, 0x00); /* controlKey + 2 */
108    else {state->KbRepeatTable[0x00]=0;}
109    if (controlKey && !shiftKey && !(keyboard[0] & 0x02)) addToKeyboardBuffer(state, 0x01); /* controlKey + A */
110    else {state->KbRepeatTable[0x01]=0;}
111    if (controlKey && !shiftKey && !(keyboard[0] & 0x04)) addToKeyboardBuffer(state, 0x02); /* controlKey + B */
112    else {state->KbRepeatTable[0x02]=0;}
113    if (controlKey && !shiftKey && !(keyboard[0] & 0x08)) addToKeyboardBuffer(state, 0x03); /* controlKey + C */
114    else {state->KbRepeatTable[0x03]=0;}
115    if (controlKey && !shiftKey && !(keyboard[0] & 0x10)) addToKeyboardBuffer(state, 0x04); /* controlKey + D */
116    else {state->KbRepeatTable[0x04]=0;}
117    if (controlKey && !shiftKey && !(keyboard[0] & 0x20)) addToKeyboardBuffer(state, 0x05); /* controlKey + E */
118    else {state->KbRepeatTable[0x05]=0;}
119    if (controlKey && !shiftKey && !(keyboard[0] & 0x40)) addToKeyboardBuffer(state, 0x06); /* controlKey + F */
120    else {state->KbRepeatTable[0x06]=0;}
121    if (controlKey && !shiftKey && !(keyboard[0] & 0x80)) addToKeyboardBuffer(state, 0x07); /* controlKey + G */
122    else {state->KbRepeatTable[0x07]=0;}
129123
130    if ((controlKey && !shiftKey && !(keyboard[1] & 0x01)) || !(keyboard[9] & 0x02)) addToKeyboardBuffer(0x08); /* controlKey + H or BACKSPACE */
131    else {KbRepeatTable[0x08]=0;}
132    if ((controlKey && !shiftKey && !(keyboard[1] & 0x02)) || !(keyboard[8] & 0x20)) addToKeyboardBuffer(0x09); /* controlKey + I or TAB */
133    else {KbRepeatTable[0x09]=0;}
134    if (controlKey && !shiftKey && !(keyboard[1] & 0x04)) addToKeyboardBuffer(0x0A); /* controlKey + J */
135    else {KbRepeatTable[0x0A]=0;}
136    if (controlKey && !shiftKey && !(keyboard[1] & 0x08)) addToKeyboardBuffer(0x0B); /* controlKey + K */
137    else {KbRepeatTable[0x0B]=0;}
138    if (controlKey && !shiftKey && !(keyboard[1] & 0x10)) addToKeyboardBuffer(0x0C); /* controlKey + L */
139    else {KbRepeatTable[0x0C]=0;}
140    if ((controlKey && !shiftKey && !(keyboard[1] & 0x20)) || !(keyboard[6] & 0x80)) addToKeyboardBuffer(0x0D); /* controlKey + M or RETURN */
141    else {KbRepeatTable[0x0D]=0;}
142    if (controlKey && !shiftKey && !(keyboard[1] & 0x40)) addToKeyboardBuffer(0x0E); /* controlKey + N */
143    else {KbRepeatTable[0x0E]=0;}
144    if (controlKey && !shiftKey && !(keyboard[1] & 0x80)) addToKeyboardBuffer(0x0F); /* controlKey + O */
145    else {KbRepeatTable[0x0F]=0;}
124    if ((controlKey && !shiftKey && !(keyboard[1] & 0x01)) || !(keyboard[9] & 0x02)) addToKeyboardBuffer(state, 0x08); /* controlKey + H or BACKSPACE */
125    else {state->KbRepeatTable[0x08]=0;}
126    if ((controlKey && !shiftKey && !(keyboard[1] & 0x02)) || !(keyboard[8] & 0x20)) addToKeyboardBuffer(state, 0x09); /* controlKey + I or TAB */
127    else {state->KbRepeatTable[0x09]=0;}
128    if (controlKey && !shiftKey && !(keyboard[1] & 0x04)) addToKeyboardBuffer(state, 0x0A); /* controlKey + J */
129    else {state->KbRepeatTable[0x0A]=0;}
130    if (controlKey && !shiftKey && !(keyboard[1] & 0x08)) addToKeyboardBuffer(state, 0x0B); /* controlKey + K */
131    else {state->KbRepeatTable[0x0B]=0;}
132    if (controlKey && !shiftKey && !(keyboard[1] & 0x10)) addToKeyboardBuffer(state, 0x0C); /* controlKey + L */
133    else {state->KbRepeatTable[0x0C]=0;}
134    if ((controlKey && !shiftKey && !(keyboard[1] & 0x20)) || !(keyboard[6] & 0x80)) addToKeyboardBuffer(state, 0x0D); /* controlKey + M or RETURN */
135    else {state->KbRepeatTable[0x0D]=0;}
136    if (controlKey && !shiftKey && !(keyboard[1] & 0x40)) addToKeyboardBuffer(state, 0x0E); /* controlKey + N */
137    else {state->KbRepeatTable[0x0E]=0;}
138    if (controlKey && !shiftKey && !(keyboard[1] & 0x80)) addToKeyboardBuffer(state, 0x0F); /* controlKey + O */
139    else {state->KbRepeatTable[0x0F]=0;}
146140
147    if (controlKey && !shiftKey && !(keyboard[2] & 0x01)) addToKeyboardBuffer(0x10); /* controlKey + P */
148    else {KbRepeatTable[0x10]=0;}
149    if (controlKey && !shiftKey && !(keyboard[2] & 0x02)) addToKeyboardBuffer(0x11); /* controlKey + Q */
150    else {KbRepeatTable[0x11]=0;}
151    if (controlKey && !shiftKey && !(keyboard[2] & 0x04)) addToKeyboardBuffer(0x12); /* controlKey + R */
152    else {KbRepeatTable[0x12]=0;}
153    if (controlKey && !shiftKey && !(keyboard[2] & 0x08)) addToKeyboardBuffer(0x13); /* controlKey + S */
154    else {KbRepeatTable[0x13]=0;}
155    if (controlKey && !shiftKey && !(keyboard[2] & 0x10)) addToKeyboardBuffer(0x14); /* controlKey + T */
156    else {KbRepeatTable[0x14]=0;}
157    if (controlKey && !shiftKey && !(keyboard[2] & 0x20)) addToKeyboardBuffer(0x15); /* controlKey + U */
158    else {KbRepeatTable[0x15]=0;}
159    if (controlKey && !shiftKey && !(keyboard[2] & 0x40)) addToKeyboardBuffer(0x16); /* controlKey + V */
160    else {KbRepeatTable[0x16]=0;}
161    if (controlKey && !shiftKey && !(keyboard[2] & 0x80)) addToKeyboardBuffer(0x17); /* controlKey + W */
162    else {KbRepeatTable[0x17]=0;}
141    if (controlKey && !shiftKey && !(keyboard[2] & 0x01)) addToKeyboardBuffer(state, 0x10); /* controlKey + P */
142    else {state->KbRepeatTable[0x10]=0;}
143    if (controlKey && !shiftKey && !(keyboard[2] & 0x02)) addToKeyboardBuffer(state, 0x11); /* controlKey + Q */
144    else {state->KbRepeatTable[0x11]=0;}
145    if (controlKey && !shiftKey && !(keyboard[2] & 0x04)) addToKeyboardBuffer(state, 0x12); /* controlKey + R */
146    else {state->KbRepeatTable[0x12]=0;}
147    if (controlKey && !shiftKey && !(keyboard[2] & 0x08)) addToKeyboardBuffer(state, 0x13); /* controlKey + S */
148    else {state->KbRepeatTable[0x13]=0;}
149    if (controlKey && !shiftKey && !(keyboard[2] & 0x10)) addToKeyboardBuffer(state, 0x14); /* controlKey + T */
150    else {state->KbRepeatTable[0x14]=0;}
151    if (controlKey && !shiftKey && !(keyboard[2] & 0x20)) addToKeyboardBuffer(state, 0x15); /* controlKey + U */
152    else {state->KbRepeatTable[0x15]=0;}
153    if (controlKey && !shiftKey && !(keyboard[2] & 0x40)) addToKeyboardBuffer(state, 0x16); /* controlKey + V */
154    else {state->KbRepeatTable[0x16]=0;}
155    if (controlKey && !shiftKey && !(keyboard[2] & 0x80)) addToKeyboardBuffer(state, 0x17); /* controlKey + W */
156    else {state->KbRepeatTable[0x17]=0;}
163157
164    if (controlKey && !shiftKey && !(keyboard[3] & 0x01)) addToKeyboardBuffer(0x18); /* controlKey + X */
165    else {KbRepeatTable[0x18]=0;}
166    if (controlKey && !shiftKey && !(keyboard[3] & 0x02)) addToKeyboardBuffer(0x19); /* controlKey + Y */
167    else {KbRepeatTable[0x19]=0;}
168    if (controlKey && !shiftKey && !(keyboard[3] & 0x04)) addToKeyboardBuffer(0x1A); /* controlKey + Z */
169    else {KbRepeatTable[0x1A]=0;}
170    if ((controlKey && !shiftKey && !(keyboard[5] & 0x80)) || !(keyboard[0] & 0x01)) addToKeyboardBuffer(0x1B); /* controlKey + [ or ESCAPE/WP */
171    else {KbRepeatTable[0x1B]=0;}
172    if (controlKey && !shiftKey && !(keyboard[3] & 0x10)) addToKeyboardBuffer(0x1C); /* controlKey + \ */
173    else {KbRepeatTable[0x1C]=0;}
174    if (controlKey && !shiftKey && !(keyboard[3] & 0x08)) addToKeyboardBuffer(0x1D); /* controlKey + ] */
175    else {KbRepeatTable[0x1D]=0;}
176    if (controlKey && !shiftKey && !(keyboard[3] & 0x20)) addToKeyboardBuffer(0x1E); /* controlKey + ^ */
177    else {KbRepeatTable[0x1E]=0;}
178    if (controlKey && !shiftKey && !(keyboard[4] & 0x40)) addToKeyboardBuffer(0x1F); /* controlKey + 6 */
179    else {KbRepeatTable[0x1F]=0;}
158    if (controlKey && !shiftKey && !(keyboard[3] & 0x01)) addToKeyboardBuffer(state, 0x18); /* controlKey + X */
159    else {state->KbRepeatTable[0x18]=0;}
160    if (controlKey && !shiftKey && !(keyboard[3] & 0x02)) addToKeyboardBuffer(state, 0x19); /* controlKey + Y */
161    else {state->KbRepeatTable[0x19]=0;}
162    if (controlKey && !shiftKey && !(keyboard[3] & 0x04)) addToKeyboardBuffer(state, 0x1A); /* controlKey + Z */
163    else {state->KbRepeatTable[0x1A]=0;}
164    if ((controlKey && !shiftKey && !(keyboard[5] & 0x80)) || !(keyboard[0] & 0x01)) addToKeyboardBuffer(state, 0x1B); /* controlKey + [ or ESCAPE/WP */
165    else {state->KbRepeatTable[0x1B]=0;}
166    if (controlKey && !shiftKey && !(keyboard[3] & 0x10)) addToKeyboardBuffer(state, 0x1C); /* controlKey + \ */
167    else {state->KbRepeatTable[0x1C]=0;}
168    if (controlKey && !shiftKey && !(keyboard[3] & 0x08)) addToKeyboardBuffer(state, 0x1D); /* controlKey + ] */
169    else {state->KbRepeatTable[0x1D]=0;}
170    if (controlKey && !shiftKey && !(keyboard[3] & 0x20)) addToKeyboardBuffer(state, 0x1E); /* controlKey + ^ */
171    else {state->KbRepeatTable[0x1E]=0;}
172    if (controlKey && !shiftKey && !(keyboard[4] & 0x40)) addToKeyboardBuffer(state, 0x1F); /* controlKey + 6 */
173    else {state->KbRepeatTable[0x1F]=0;}
180174
181    if (!controlKey && !shiftKey && !(keyboard[6] & 0x40)) addToKeyboardBuffer(0x20); /* SPACEBAR */
182    else {KbRepeatTable[0x20]=0;}
183    if (shiftKey && !controlKey && !(keyboard[4] & 0x02)) addToKeyboardBuffer(0x21); /* shiftKey + 1 */
184    else {KbRepeatTable[0x21]=0;}
185    if (shiftKey && !controlKey && !(keyboard[5] & 0x04)) addToKeyboardBuffer(0x22); /* shiftKey + ' */
186    else {KbRepeatTable[0x22]=0;}
187    if (shiftKey && !controlKey && !(keyboard[4] & 0x08)) addToKeyboardBuffer(0x23); /* shiftKey + 3 */
188    else {KbRepeatTable[0x23]=0;}
189    if (shiftKey && !controlKey && !(keyboard[4] & 0x10)) addToKeyboardBuffer(0x24); /* shiftKey + 4 */
190    else {KbRepeatTable[0x24]=0;}
191    if (shiftKey && !controlKey && !(keyboard[4] & 0x20)) addToKeyboardBuffer(0x25); /* shiftKey + 5 */
192    else {KbRepeatTable[0x25]=0;}
193    if (shiftKey && !controlKey && !(keyboard[4] & 0x80)) addToKeyboardBuffer(0x26); /* shiftKey + 7 */
194    else {KbRepeatTable[0x26]=0;}
195    if (!shiftKey && !controlKey && !(keyboard[5] & 0x04)) addToKeyboardBuffer(0x27); /* ' */
196    else {KbRepeatTable[0x27]=0;}
175    if (!controlKey && !shiftKey && !(keyboard[6] & 0x40)) addToKeyboardBuffer(state, 0x20); /* SPACEBAR */
176    else {state->KbRepeatTable[0x20]=0;}
177    if (shiftKey && !controlKey && !(keyboard[4] & 0x02)) addToKeyboardBuffer(state, 0x21); /* shiftKey + 1 */
178    else {state->KbRepeatTable[0x21]=0;}
179    if (shiftKey && !controlKey && !(keyboard[5] & 0x04)) addToKeyboardBuffer(state, 0x22); /* shiftKey + ' */
180    else {state->KbRepeatTable[0x22]=0;}
181    if (shiftKey && !controlKey && !(keyboard[4] & 0x08)) addToKeyboardBuffer(state, 0x23); /* shiftKey + 3 */
182    else {state->KbRepeatTable[0x23]=0;}
183    if (shiftKey && !controlKey && !(keyboard[4] & 0x10)) addToKeyboardBuffer(state, 0x24); /* shiftKey + 4 */
184    else {state->KbRepeatTable[0x24]=0;}
185    if (shiftKey && !controlKey && !(keyboard[4] & 0x20)) addToKeyboardBuffer(state, 0x25); /* shiftKey + 5 */
186    else {state->KbRepeatTable[0x25]=0;}
187    if (shiftKey && !controlKey && !(keyboard[4] & 0x80)) addToKeyboardBuffer(state, 0x26); /* shiftKey + 7 */
188    else {state->KbRepeatTable[0x26]=0;}
189    if (!shiftKey && !controlKey && !(keyboard[5] & 0x04)) addToKeyboardBuffer(state, 0x27); /* ' */
190    else {state->KbRepeatTable[0x27]=0;}
197191
198    if (shiftKey && !controlKey && !(keyboard[5] & 0x02)) addToKeyboardBuffer(0x28); /* shiftKey + 9 */
199    else {KbRepeatTable[0x28]=0;}
200    if (shiftKey && !controlKey && !(keyboard[4] & 0x01)) addToKeyboardBuffer(0x29); /* shiftKey + 0 */
201    else {KbRepeatTable[0x29]=0;}
202    if (shiftKey && !controlKey && !(keyboard[5] & 0x01)) addToKeyboardBuffer(0x2A); /* shiftKey + 8 */
203    else {KbRepeatTable[0x2A]=0;}
204    if (!controlKey && !shiftKey && !(keyboard[5] & 0x08)) addToKeyboardBuffer(0x2B); /* + */
205    else {KbRepeatTable[0x2B]=0;}
206    if (!controlKey && !shiftKey && !(keyboard[5] & 0x10)) addToKeyboardBuffer(0x2C); /* , */
207    else {KbRepeatTable[0x2C]=0;}
208    if (!controlKey && !shiftKey && !(keyboard[3] & 0x40)) addToKeyboardBuffer(0x2D); /* - */
209    else {KbRepeatTable[0x2D]=0;}
210    if (!controlKey && !shiftKey && !(keyboard[5] & 0x20)) addToKeyboardBuffer(0x2E); /* . */
211    else {KbRepeatTable[0x2E]=0;}
212    if (!controlKey && !shiftKey && !(keyboard[5] & 0x40)) addToKeyboardBuffer(0x2F); /* / */
213    else {KbRepeatTable[0x2F]=0;}
192    if (shiftKey && !controlKey && !(keyboard[5] & 0x02)) addToKeyboardBuffer(state, 0x28); /* shiftKey + 9 */
193    else {state->KbRepeatTable[0x28]=0;}
194    if (shiftKey && !controlKey && !(keyboard[4] & 0x01)) addToKeyboardBuffer(state, 0x29); /* shiftKey + 0 */
195    else {state->KbRepeatTable[0x29]=0;}
196    if (shiftKey && !controlKey && !(keyboard[5] & 0x01)) addToKeyboardBuffer(state, 0x2A); /* shiftKey + 8 */
197    else {state->KbRepeatTable[0x2A]=0;}
198    if (!controlKey && !shiftKey && !(keyboard[5] & 0x08)) addToKeyboardBuffer(state, 0x2B); /* + */
199    else {state->KbRepeatTable[0x2B]=0;}
200    if (!controlKey && !shiftKey && !(keyboard[5] & 0x10)) addToKeyboardBuffer(state, 0x2C); /* , */
201    else {state->KbRepeatTable[0x2C]=0;}
202    if (!controlKey && !shiftKey && !(keyboard[3] & 0x40)) addToKeyboardBuffer(state, 0x2D); /* - */
203    else {state->KbRepeatTable[0x2D]=0;}
204    if (!controlKey && !shiftKey && !(keyboard[5] & 0x20)) addToKeyboardBuffer(state, 0x2E); /* . */
205    else {state->KbRepeatTable[0x2E]=0;}
206    if (!controlKey && !shiftKey && !(keyboard[5] & 0x40)) addToKeyboardBuffer(state, 0x2F); /* / */
207    else {state->KbRepeatTable[0x2F]=0;}
214208
215    if (!shiftKey && !controlKey && !(keyboard[4] & 0x01)) addToKeyboardBuffer(0x30); /* 0 */
216    else {KbRepeatTable[0x30]=0;}
217    if (!shiftKey && !controlKey && !(keyboard[4] & 0x02)) addToKeyboardBuffer(0x31); /* 1 */
218    else {KbRepeatTable[0x31]=0;}
219    if (!shiftKey && !controlKey && !(keyboard[4] & 0x04)) addToKeyboardBuffer(0x32); /* 2 */
220    else {KbRepeatTable[0x32]=0;}
221    if (!shiftKey && !controlKey && !(keyboard[4] & 0x08)) addToKeyboardBuffer(0x33); /* 3 */
222    else {KbRepeatTable[0x33]=0;}
223    if (!shiftKey && !controlKey && !(keyboard[4] & 0x10)) addToKeyboardBuffer(0x34); /* 4 */
224    else {KbRepeatTable[0x34]=0;}
225    if (!shiftKey && !controlKey && !(keyboard[4] & 0x20)) addToKeyboardBuffer(0x35); /* 5 */
226    else {KbRepeatTable[0x35]=0;}
227    if (!shiftKey && !controlKey && !(keyboard[4] & 0x40)) addToKeyboardBuffer(0x36); /* 6 */
228    else {KbRepeatTable[0x36]=0;}
229    if (!shiftKey && !controlKey && !(keyboard[4] & 0x80)) addToKeyboardBuffer(0x37); /* 7 */
230    else {KbRepeatTable[0x37]=0;}
209    if (!shiftKey && !controlKey && !(keyboard[4] & 0x01)) addToKeyboardBuffer(state, 0x30); /* 0 */
210    else {state->KbRepeatTable[0x30]=0;}
211    if (!shiftKey && !controlKey && !(keyboard[4] & 0x02)) addToKeyboardBuffer(state, 0x31); /* 1 */
212    else {state->KbRepeatTable[0x31]=0;}
213    if (!shiftKey && !controlKey && !(keyboard[4] & 0x04)) addToKeyboardBuffer(state, 0x32); /* 2 */
214    else {state->KbRepeatTable[0x32]=0;}
215    if (!shiftKey && !controlKey && !(keyboard[4] & 0x08)) addToKeyboardBuffer(state, 0x33); /* 3 */
216    else {state->KbRepeatTable[0x33]=0;}
217    if (!shiftKey && !controlKey && !(keyboard[4] & 0x10)) addToKeyboardBuffer(state, 0x34); /* 4 */
218    else {state->KbRepeatTable[0x34]=0;}
219    if (!shiftKey && !controlKey && !(keyboard[4] & 0x20)) addToKeyboardBuffer(state, 0x35); /* 5 */
220    else {state->KbRepeatTable[0x35]=0;}
221    if (!shiftKey && !controlKey && !(keyboard[4] & 0x40)) addToKeyboardBuffer(state, 0x36); /* 6 */
222    else {state->KbRepeatTable[0x36]=0;}
223    if (!shiftKey && !controlKey && !(keyboard[4] & 0x80)) addToKeyboardBuffer(state, 0x37); /* 7 */
224    else {state->KbRepeatTable[0x37]=0;}
231225
232    if (!shiftKey && !controlKey && !(keyboard[5] & 0x01)) addToKeyboardBuffer(0x38); /* 8 */
233    else {KbRepeatTable[0x38]=0;}
234    if (!shiftKey && !controlKey && !(keyboard[5] & 0x02)) addToKeyboardBuffer(0x39); /* 9 */
235    else {KbRepeatTable[0x39]=0;}
236    if (shiftKey && !controlKey && !(keyboard[3] & 0x80)) addToKeyboardBuffer(0x3A); /* shiftKey + ; */
237    else {KbRepeatTable[0x3A]=0;}
238    if (!controlKey && !shiftKey && !(keyboard[3] & 0x80)) addToKeyboardBuffer(0x3B); /* ; */
239    else {KbRepeatTable[0x3B]=0;}
240    if (shiftKey && !controlKey && !(keyboard[5] & 0x10)) addToKeyboardBuffer(0x3C); /* shiftKey + , */
241    else {KbRepeatTable[0x3C]=0;}
242    if (shiftKey && !controlKey && !(keyboard[5] & 0x08)) addToKeyboardBuffer(0x3D); /* shiftKey + + */
243    else {KbRepeatTable[0x3D]=0;}
244    if (shiftKey && !controlKey && !(keyboard[5] & 0x20)) addToKeyboardBuffer(0x3E); /* shiftKey + . */
245    else {KbRepeatTable[0x3E]=0;}
246    if (shiftKey && !controlKey && !(keyboard[5] & 0x40)) addToKeyboardBuffer(0x3F); /* shiftKey + / */
247    else {KbRepeatTable[0x3F]=0;}
226    if (!shiftKey && !controlKey && !(keyboard[5] & 0x01)) addToKeyboardBuffer(state, 0x38); /* 8 */
227    else {state->KbRepeatTable[0x38]=0;}
228    if (!shiftKey && !controlKey && !(keyboard[5] & 0x02)) addToKeyboardBuffer(state, 0x39); /* 9 */
229    else {state->KbRepeatTable[0x39]=0;}
230    if (shiftKey && !controlKey && !(keyboard[3] & 0x80)) addToKeyboardBuffer(state, 0x3A); /* shiftKey + ; */
231    else {state->KbRepeatTable[0x3A]=0;}
232    if (!controlKey && !shiftKey && !(keyboard[3] & 0x80)) addToKeyboardBuffer(state, 0x3B); /* ; */
233    else {state->KbRepeatTable[0x3B]=0;}
234    if (shiftKey && !controlKey && !(keyboard[5] & 0x10)) addToKeyboardBuffer(state, 0x3C); /* shiftKey + , */
235    else {state->KbRepeatTable[0x3C]=0;}
236    if (shiftKey && !controlKey && !(keyboard[5] & 0x08)) addToKeyboardBuffer(state, 0x3D); /* shiftKey + + */
237    else {state->KbRepeatTable[0x3D]=0;}
238    if (shiftKey && !controlKey && !(keyboard[5] & 0x20)) addToKeyboardBuffer(state, 0x3E); /* shiftKey + . */
239    else {state->KbRepeatTable[0x3E]=0;}
240    if (shiftKey && !controlKey && !(keyboard[5] & 0x40)) addToKeyboardBuffer(state, 0x3F); /* shiftKey + / */
241    else {state->KbRepeatTable[0x3F]=0;}
248242
249    if (shiftKey && !controlKey && !(keyboard[4] & 0x04)) addToKeyboardBuffer(0x40); /* shiftKey + 2 */
250    else {KbRepeatTable[0x40]=0;}
251    if (shiftKey && !controlKey && !(keyboard[0] & 0x02)) addToKeyboardBuffer(0x41); /* shiftKey + A */
252    else {KbRepeatTable[0x41]=0;}
253    if (shiftKey && !controlKey && !(keyboard[0] & 0x04)) addToKeyboardBuffer(0x42); /* shiftKey + B */
254    else {KbRepeatTable[0x42]=0;}
255    if (shiftKey && !controlKey && !(keyboard[0] & 0x08)) addToKeyboardBuffer(0x43); /* shiftKey + C */
256    else {KbRepeatTable[0x43]=0;}
257    if (shiftKey && !controlKey && !(keyboard[0] & 0x10)) addToKeyboardBuffer(0x44); /* shiftKey + D */
258    else {KbRepeatTable[0x44]=0;}
259    if (shiftKey && !controlKey && !(keyboard[0] & 0x20)) addToKeyboardBuffer(0x45); /* shiftKey + E */
260    else {KbRepeatTable[0x45]=0;}
261    if (shiftKey && !controlKey && !(keyboard[0] & 0x40)) addToKeyboardBuffer(0x46); /* shiftKey + F */
262    else {KbRepeatTable[0x46]=0;}
263    if (shiftKey && !controlKey && !(keyboard[0] & 0x80)) addToKeyboardBuffer(0x47); /* shiftKey + G */
264    else {KbRepeatTable[0x47]=0;}
243    if (shiftKey && !controlKey && !(keyboard[4] & 0x04)) addToKeyboardBuffer(state, 0x40); /* shiftKey + 2 */
244    else {state->KbRepeatTable[0x40]=0;}
245    if (shiftKey && !controlKey && !(keyboard[0] & 0x02)) addToKeyboardBuffer(state, 0x41); /* shiftKey + A */
246    else {state->KbRepeatTable[0x41]=0;}
247    if (shiftKey && !controlKey && !(keyboard[0] & 0x04)) addToKeyboardBuffer(state, 0x42); /* shiftKey + B */
248    else {state->KbRepeatTable[0x42]=0;}
249    if (shiftKey && !controlKey && !(keyboard[0] & 0x08)) addToKeyboardBuffer(state, 0x43); /* shiftKey + C */
250    else {state->KbRepeatTable[0x43]=0;}
251    if (shiftKey && !controlKey && !(keyboard[0] & 0x10)) addToKeyboardBuffer(state, 0x44); /* shiftKey + D */
252    else {state->KbRepeatTable[0x44]=0;}
253    if (shiftKey && !controlKey && !(keyboard[0] & 0x20)) addToKeyboardBuffer(state, 0x45); /* shiftKey + E */
254    else {state->KbRepeatTable[0x45]=0;}
255    if (shiftKey && !controlKey && !(keyboard[0] & 0x40)) addToKeyboardBuffer(state, 0x46); /* shiftKey + F */
256    else {state->KbRepeatTable[0x46]=0;}
257    if (shiftKey && !controlKey && !(keyboard[0] & 0x80)) addToKeyboardBuffer(state, 0x47); /* shiftKey + G */
258    else {state->KbRepeatTable[0x47]=0;}
265259
266    if (shiftKey && !controlKey && !(keyboard[1] & 0x01)) addToKeyboardBuffer(0x48); /* shiftKey + H */
267    else {KbRepeatTable[0x48]=0;}
268    if (shiftKey && !controlKey && !(keyboard[1] & 0x02)) addToKeyboardBuffer(0x49); /* shiftKey + I */
269    else {KbRepeatTable[0x49]=0;}
270    if (shiftKey && !controlKey && !(keyboard[1] & 0x04)) addToKeyboardBuffer(0x4A); /* shiftKey + J */
271    else {KbRepeatTable[0x4A]=0;}
272    if (shiftKey && !controlKey && !(keyboard[1] & 0x08)) addToKeyboardBuffer(0x4B); /* shiftKey + K */
273    else {KbRepeatTable[0x4B]=0;}
274    if (shiftKey && !controlKey && !(keyboard[1] & 0x10)) addToKeyboardBuffer(0x4C); /* shiftKey + L */
275    else {KbRepeatTable[0x4C]=0;}
276    if (shiftKey && !controlKey && !(keyboard[1] & 0x20)) addToKeyboardBuffer(0x4D); /* shiftKey + M */
277    else {KbRepeatTable[0x4D]=0;}
278    if (shiftKey && !controlKey && !(keyboard[1] & 0x40)) addToKeyboardBuffer(0x4E); /* shiftKey + N */
279    else {KbRepeatTable[0x4E]=0;}
280    if (shiftKey && !controlKey && !(keyboard[1] & 0x80)) addToKeyboardBuffer(0x4F); /* shiftKey + O */
281    else {KbRepeatTable[0x4F]=0;}
260    if (shiftKey && !controlKey && !(keyboard[1] & 0x01)) addToKeyboardBuffer(state, 0x48); /* shiftKey + H */
261    else {state->KbRepeatTable[0x48]=0;}
262    if (shiftKey && !controlKey && !(keyboard[1] & 0x02)) addToKeyboardBuffer(state, 0x49); /* shiftKey + I */
263    else {state->KbRepeatTable[0x49]=0;}
264    if (shiftKey && !controlKey && !(keyboard[1] & 0x04)) addToKeyboardBuffer(state, 0x4A); /* shiftKey + J */
265    else {state->KbRepeatTable[0x4A]=0;}
266    if (shiftKey && !controlKey && !(keyboard[1] & 0x08)) addToKeyboardBuffer(state, 0x4B); /* shiftKey + K */
267    else {state->KbRepeatTable[0x4B]=0;}
268    if (shiftKey && !controlKey && !(keyboard[1] & 0x10)) addToKeyboardBuffer(state, 0x4C); /* shiftKey + L */
269    else {state->KbRepeatTable[0x4C]=0;}
270    if (shiftKey && !controlKey && !(keyboard[1] & 0x20)) addToKeyboardBuffer(state, 0x4D); /* shiftKey + M */
271    else {state->KbRepeatTable[0x4D]=0;}
272    if (shiftKey && !controlKey && !(keyboard[1] & 0x40)) addToKeyboardBuffer(state, 0x4E); /* shiftKey + N */
273    else {state->KbRepeatTable[0x4E]=0;}
274    if (shiftKey && !controlKey && !(keyboard[1] & 0x80)) addToKeyboardBuffer(state, 0x4F); /* shiftKey + O */
275    else {state->KbRepeatTable[0x4F]=0;}
282276
283    if (shiftKey && !controlKey && !(keyboard[2] & 0x01)) addToKeyboardBuffer(0x50); /* shiftKey + P */
284    else {KbRepeatTable[0x50]=0;}
285    if (shiftKey && !controlKey && !(keyboard[2] & 0x02)) addToKeyboardBuffer(0x51); /* shiftKey + Q */
286    else {KbRepeatTable[0x51]=0;}
287    if (shiftKey && !controlKey && !(keyboard[2] & 0x04)) addToKeyboardBuffer(0x52); /* shiftKey + R */
288    else {KbRepeatTable[0x52]=0;}
289    if (shiftKey && !controlKey && !(keyboard[2] & 0x08)) addToKeyboardBuffer(0x53); /* shiftKey + S */
290    else {KbRepeatTable[0x53]=0;}
291    if (shiftKey && !controlKey && !(keyboard[2] & 0x10)) addToKeyboardBuffer(0x54); /* shiftKey + T */
292    else {KbRepeatTable[0x54]=0;}
293    if (shiftKey && !controlKey && !(keyboard[2] & 0x20)) addToKeyboardBuffer(0x55); /* shiftKey + U */
294    else {KbRepeatTable[0x55]=0;}
295    if (shiftKey && !controlKey && !(keyboard[2] & 0x40)) addToKeyboardBuffer(0x56); /* shiftKey + V */
296    else {KbRepeatTable[0x56]=0;}
297    if (shiftKey && !controlKey && !(keyboard[2] & 0x80)) addToKeyboardBuffer(0x57); /* shiftKey + W */
298    else {KbRepeatTable[0x57]=0;}
277    if (shiftKey && !controlKey && !(keyboard[2] & 0x01)) addToKeyboardBuffer(state, 0x50); /* shiftKey + P */
278    else {state->KbRepeatTable[0x50]=0;}
279    if (shiftKey && !controlKey && !(keyboard[2] & 0x02)) addToKeyboardBuffer(state, 0x51); /* shiftKey + Q */
280    else {state->KbRepeatTable[0x51]=0;}
281    if (shiftKey && !controlKey && !(keyboard[2] & 0x04)) addToKeyboardBuffer(state, 0x52); /* shiftKey + R */
282    else {state->KbRepeatTable[0x52]=0;}
283    if (shiftKey && !controlKey && !(keyboard[2] & 0x08)) addToKeyboardBuffer(state, 0x53); /* shiftKey + S */
284    else {state->KbRepeatTable[0x53]=0;}
285    if (shiftKey && !controlKey && !(keyboard[2] & 0x10)) addToKeyboardBuffer(state, 0x54); /* shiftKey + T */
286    else {state->KbRepeatTable[0x54]=0;}
287    if (shiftKey && !controlKey && !(keyboard[2] & 0x20)) addToKeyboardBuffer(state, 0x55); /* shiftKey + U */
288    else {state->KbRepeatTable[0x55]=0;}
289    if (shiftKey && !controlKey && !(keyboard[2] & 0x40)) addToKeyboardBuffer(state, 0x56); /* shiftKey + V */
290    else {state->KbRepeatTable[0x56]=0;}
291    if (shiftKey && !controlKey && !(keyboard[2] & 0x80)) addToKeyboardBuffer(state, 0x57); /* shiftKey + W */
292    else {state->KbRepeatTable[0x57]=0;}
299293
300    if (shiftKey && !controlKey && !(keyboard[3] & 0x01)) addToKeyboardBuffer(0x58); /* shiftKey + X */
301    else {KbRepeatTable[0x58]=0;}
302    if (shiftKey && !controlKey && !(keyboard[3] & 0x02)) addToKeyboardBuffer(0x59); /* shiftKey + Y */
303    else {KbRepeatTable[0x59]=0;}
304    if (shiftKey && !controlKey && !(keyboard[3] & 0x04)) addToKeyboardBuffer(0x5A); /* shiftKey + Z */
305    else {KbRepeatTable[0x5A]=0;}
306    if (!controlKey && !shiftKey && !(keyboard[5] & 0x80)) addToKeyboardBuffer(0x5B); /* [ */
307    else {KbRepeatTable[0x5B]=0;}
308    if (!controlKey && !shiftKey && !(keyboard[3] & 0x10)) addToKeyboardBuffer(0x5C); /* \ */
309    else {KbRepeatTable[0x5C]=0;}
310    if (!controlKey && !shiftKey && !(keyboard[3] & 0x08)) addToKeyboardBuffer(0x5D); /* ] */
311    else {KbRepeatTable[0x5D]=0;}
312    if (!controlKey && !shiftKey && !(keyboard[3] & 0x20)) addToKeyboardBuffer(0x5E); /* ^ */
313    else {KbRepeatTable[0x5E]=0;}
314    if (shiftKey && !controlKey && !(keyboard[4] & 0x40)) addToKeyboardBuffer(0x5F); /* shiftKey + 6 */
315    else {KbRepeatTable[0x5F]=0;}
294    if (shiftKey && !controlKey && !(keyboard[3] & 0x01)) addToKeyboardBuffer(state, 0x58); /* shiftKey + X */
295    else {state->KbRepeatTable[0x58]=0;}
296    if (shiftKey && !controlKey && !(keyboard[3] & 0x02)) addToKeyboardBuffer(state, 0x59); /* shiftKey + Y */
297    else {state->KbRepeatTable[0x59]=0;}
298    if (shiftKey && !controlKey && !(keyboard[3] & 0x04)) addToKeyboardBuffer(state, 0x5A); /* shiftKey + Z */
299    else {state->KbRepeatTable[0x5A]=0;}
300    if (!controlKey && !shiftKey && !(keyboard[5] & 0x80)) addToKeyboardBuffer(state, 0x5B); /* [ */
301    else {state->KbRepeatTable[0x5B]=0;}
302    if (!controlKey && !shiftKey && !(keyboard[3] & 0x10)) addToKeyboardBuffer(state, 0x5C); /* \ */
303    else {state->KbRepeatTable[0x5C]=0;}
304    if (!controlKey && !shiftKey && !(keyboard[3] & 0x08)) addToKeyboardBuffer(state, 0x5D); /* ] */
305    else {state->KbRepeatTable[0x5D]=0;}
306    if (!controlKey && !shiftKey && !(keyboard[3] & 0x20)) addToKeyboardBuffer(state, 0x5E); /* ^ */
307    else {state->KbRepeatTable[0x5E]=0;}
308    if (shiftKey && !controlKey && !(keyboard[4] & 0x40)) addToKeyboardBuffer(state, 0x5F); /* shiftKey + 6 */
309    else {state->KbRepeatTable[0x5F]=0;}
316310
317    if (shiftKey && !controlKey && !(keyboard[3] & 0x40)) addToKeyboardBuffer(0x60); /* shiftKey + - */
318    else {KbRepeatTable[0x60]=0;}
319    if (!controlKey && !shiftKey && !(keyboard[0] & 0x02)) addToKeyboardBuffer(0x61); /* A */
320    else {KbRepeatTable[0x61]=0;}
321    if (!controlKey && !shiftKey && !(keyboard[0] & 0x04)) addToKeyboardBuffer(0x62); /* B */
322    else {KbRepeatTable[0x62]=0;}
323    if (!controlKey && !shiftKey && !(keyboard[0] & 0x08)) addToKeyboardBuffer(0x63); /* C */
324    else {KbRepeatTable[0x63]=0;}
325    if (!controlKey && !shiftKey && !(keyboard[0] & 0x10)) addToKeyboardBuffer(0x64); /* D */
326    else {KbRepeatTable[0x64]=0;}
327    if (!controlKey && !shiftKey && !(keyboard[0] & 0x20)) addToKeyboardBuffer(0x65); /* E */
328    else {KbRepeatTable[0x65]=0;}
329    if (!controlKey && !shiftKey && !(keyboard[0] & 0x40)) addToKeyboardBuffer(0x66); /* F */
330    else {KbRepeatTable[0x66]=0;}
331    if (!controlKey && !shiftKey && !(keyboard[0] & 0x80)) addToKeyboardBuffer(0x67); /* G */
332    else {KbRepeatTable[0x67]=0;}
311    if (shiftKey && !controlKey && !(keyboard[3] & 0x40)) addToKeyboardBuffer(state, 0x60); /* shiftKey + - */
312    else {state->KbRepeatTable[0x60]=0;}
313    if (!controlKey && !shiftKey && !(keyboard[0] & 0x02)) addToKeyboardBuffer(state, 0x61); /* A */
314    else {state->KbRepeatTable[0x61]=0;}
315    if (!controlKey && !shiftKey && !(keyboard[0] & 0x04)) addToKeyboardBuffer(state, 0x62); /* B */
316    else {state->KbRepeatTable[0x62]=0;}
317    if (!controlKey && !shiftKey && !(keyboard[0] & 0x08)) addToKeyboardBuffer(state, 0x63); /* C */
318    else {state->KbRepeatTable[0x63]=0;}
319    if (!controlKey && !shiftKey && !(keyboard[0] & 0x10)) addToKeyboardBuffer(state, 0x64); /* D */
320    else {state->KbRepeatTable[0x64]=0;}
321    if (!controlKey && !shiftKey && !(keyboard[0] & 0x20)) addToKeyboardBuffer(state, 0x65); /* E */
322    else {state->KbRepeatTable[0x65]=0;}
323    if (!controlKey && !shiftKey && !(keyboard[0] & 0x40)) addToKeyboardBuffer(state, 0x66); /* F */
324    else {state->KbRepeatTable[0x66]=0;}
325    if (!controlKey && !shiftKey && !(keyboard[0] & 0x80)) addToKeyboardBuffer(state, 0x67); /* G */
326    else {state->KbRepeatTable[0x67]=0;}
333327
334    if (!controlKey && !shiftKey && !(keyboard[1] & 0x01)) addToKeyboardBuffer(0x68); /* H */
335    else {KbRepeatTable[0x68]=0;}
336    if (!controlKey && !shiftKey && !(keyboard[1] & 0x02)) addToKeyboardBuffer(0x69); /* I */
337    else {KbRepeatTable[0x69]=0;}
338    if (!controlKey && !shiftKey && !(keyboard[1] & 0x04)) addToKeyboardBuffer(0x6A); /* J */
339    else {KbRepeatTable[0x6A]=0;}
340    if (!controlKey && !shiftKey && !(keyboard[1] & 0x08)) addToKeyboardBuffer(0x6B); /* K */
341    else {KbRepeatTable[0x6B]=0;}
342    if (!controlKey && !shiftKey && !(keyboard[1] & 0x10)) addToKeyboardBuffer(0x6C); /* L */
343    else {KbRepeatTable[0x6C]=0;}
344    if (!controlKey && !shiftKey && !(keyboard[1] & 0x20)) addToKeyboardBuffer(0x6D); /* M */
345    else {KbRepeatTable[0x6D]=0;}
346    if (!controlKey && !shiftKey && !(keyboard[1] & 0x40)) addToKeyboardBuffer(0x6E); /* N */
347    else {KbRepeatTable[0x6E]=0;}
348    if (!controlKey && !shiftKey && !(keyboard[1] & 0x80)) addToKeyboardBuffer(0x6F); /* O */
349    else {KbRepeatTable[0x6F]=0;}
328    if (!controlKey && !shiftKey && !(keyboard[1] & 0x01)) addToKeyboardBuffer(state, 0x68); /* H */
329    else {state->KbRepeatTable[0x68]=0;}
330    if (!controlKey && !shiftKey && !(keyboard[1] & 0x02)) addToKeyboardBuffer(state, 0x69); /* I */
331    else {state->KbRepeatTable[0x69]=0;}
332    if (!controlKey && !shiftKey && !(keyboard[1] & 0x04)) addToKeyboardBuffer(state, 0x6A); /* J */
333    else {state->KbRepeatTable[0x6A]=0;}
334    if (!controlKey && !shiftKey && !(keyboard[1] & 0x08)) addToKeyboardBuffer(state, 0x6B); /* K */
335    else {state->KbRepeatTable[0x6B]=0;}
336    if (!controlKey && !shiftKey && !(keyboard[1] & 0x10)) addToKeyboardBuffer(state, 0x6C); /* L */
337    else {state->KbRepeatTable[0x6C]=0;}
338    if (!controlKey && !shiftKey && !(keyboard[1] & 0x20)) addToKeyboardBuffer(state, 0x6D); /* M */
339    else {state->KbRepeatTable[0x6D]=0;}
340    if (!controlKey && !shiftKey && !(keyboard[1] & 0x40)) addToKeyboardBuffer(state, 0x6E); /* N */
341    else {state->KbRepeatTable[0x6E]=0;}
342    if (!controlKey && !shiftKey && !(keyboard[1] & 0x80)) addToKeyboardBuffer(state, 0x6F); /* O */
343    else {state->KbRepeatTable[0x6F]=0;}
350344
351    if (!controlKey && !shiftKey && !(keyboard[2] & 0x01)) addToKeyboardBuffer(0x70); /* P */
352    else {KbRepeatTable[0x70]=0;}
353    if (!controlKey && !shiftKey && !(keyboard[2] & 0x02)) addToKeyboardBuffer(0x71); /* Q */
354    else {KbRepeatTable[0x71]=0;}
355    if (!controlKey && !shiftKey && !(keyboard[2] & 0x04)) addToKeyboardBuffer(0x72); /* R */
356    else {KbRepeatTable[0x72]=0;}
357    if (!controlKey && !shiftKey && !(keyboard[2] & 0x08)) addToKeyboardBuffer(0x73); /* S */
358    else {KbRepeatTable[0x73]=0;}
359    if (!controlKey && !shiftKey && !(keyboard[2] & 0x10)) addToKeyboardBuffer(0x74); /* T */
360    else {KbRepeatTable[0x74]=0;}
361    if (!controlKey && !shiftKey && !(keyboard[2] & 0x20)) addToKeyboardBuffer(0x75); /* U */
362    else {KbRepeatTable[0x75]=0;}
363    if (!controlKey && !shiftKey && !(keyboard[2] & 0x40)) addToKeyboardBuffer(0x76); /* V */
364    else {KbRepeatTable[0x76]=0;}
365    if (!controlKey && !shiftKey && !(keyboard[2] & 0x80)) addToKeyboardBuffer(0x77); /* W */
366    else {KbRepeatTable[0x77]=0;}
345    if (!controlKey && !shiftKey && !(keyboard[2] & 0x01)) addToKeyboardBuffer(state, 0x70); /* P */
346    else {state->KbRepeatTable[0x70]=0;}
347    if (!controlKey && !shiftKey && !(keyboard[2] & 0x02)) addToKeyboardBuffer(state, 0x71); /* Q */
348    else {state->KbRepeatTable[0x71]=0;}
349    if (!controlKey && !shiftKey && !(keyboard[2] & 0x04)) addToKeyboardBuffer(state, 0x72); /* R */
350    else {state->KbRepeatTable[0x72]=0;}
351    if (!controlKey && !shiftKey && !(keyboard[2] & 0x08)) addToKeyboardBuffer(state, 0x73); /* S */
352    else {state->KbRepeatTable[0x73]=0;}
353    if (!controlKey && !shiftKey && !(keyboard[2] & 0x10)) addToKeyboardBuffer(state, 0x74); /* T */
354    else {state->KbRepeatTable[0x74]=0;}
355    if (!controlKey && !shiftKey && !(keyboard[2] & 0x20)) addToKeyboardBuffer(state, 0x75); /* U */
356    else {state->KbRepeatTable[0x75]=0;}
357    if (!controlKey && !shiftKey && !(keyboard[2] & 0x40)) addToKeyboardBuffer(state, 0x76); /* V */
358    else {state->KbRepeatTable[0x76]=0;}
359    if (!controlKey && !shiftKey && !(keyboard[2] & 0x80)) addToKeyboardBuffer(state, 0x77); /* W */
360    else {state->KbRepeatTable[0x77]=0;}
367361
368    if (!controlKey && !shiftKey && !(keyboard[3] & 0x01)) addToKeyboardBuffer(0x78); /* X */
369    else {KbRepeatTable[0x78]=0;}
370    if (!controlKey && !shiftKey && !(keyboard[3] & 0x02)) addToKeyboardBuffer(0x79); /* Y */
371    else {KbRepeatTable[0x79]=0;}
372    if (!controlKey && !shiftKey && !(keyboard[3] & 0x04)) addToKeyboardBuffer(0x7A); /* Z */
373    else {KbRepeatTable[0x7A]=0;}
374    if (shiftKey && !controlKey && !(keyboard[5] & 0x80)) addToKeyboardBuffer(0x7B); /* shiftKey + [ */
375    else {KbRepeatTable[0x7B]=0;}
376    if (shiftKey && !controlKey && !(keyboard[3] & 0x10)) addToKeyboardBuffer(0x7C); /* shiftKey + \ */
377    else {KbRepeatTable[0x7C]=0;}
378    if (shiftKey && !controlKey && !(keyboard[3] & 0x08)) addToKeyboardBuffer(0x7D); /* shiftKey + ] */
379    else {KbRepeatTable[0x7D]=0;}
380    if (shiftKey && !controlKey && !(keyboard[3] & 0x20)) addToKeyboardBuffer(0x7E); /* shiftKey + ^ */
381    else {KbRepeatTable[0x7E]=0;}
382    if (controlKey && !shiftKey && !(keyboard[7] & 0x80)) addToKeyboardBuffer(0x7F); /* controlKey + DELETE */
383    else {KbRepeatTable[0x7F]=0;}
362    if (!controlKey && !shiftKey && !(keyboard[3] & 0x01)) addToKeyboardBuffer(state, 0x78); /* X */
363    else {state->KbRepeatTable[0x78]=0;}
364    if (!controlKey && !shiftKey && !(keyboard[3] & 0x02)) addToKeyboardBuffer(state, 0x79); /* Y */
365    else {state->KbRepeatTable[0x79]=0;}
366    if (!controlKey && !shiftKey && !(keyboard[3] & 0x04)) addToKeyboardBuffer(state, 0x7A); /* Z */
367    else {state->KbRepeatTable[0x7A]=0;}
368    if (shiftKey && !controlKey && !(keyboard[5] & 0x80)) addToKeyboardBuffer(state, 0x7B); /* shiftKey + [ */
369    else {state->KbRepeatTable[0x7B]=0;}
370    if (shiftKey && !controlKey && !(keyboard[3] & 0x10)) addToKeyboardBuffer(state, 0x7C); /* shiftKey + \ */
371    else {state->KbRepeatTable[0x7C]=0;}
372    if (shiftKey && !controlKey && !(keyboard[3] & 0x08)) addToKeyboardBuffer(state, 0x7D); /* shiftKey + ] */
373    else {state->KbRepeatTable[0x7D]=0;}
374    if (shiftKey && !controlKey && !(keyboard[3] & 0x20)) addToKeyboardBuffer(state, 0x7E); /* shiftKey + ^ */
375    else {state->KbRepeatTable[0x7E]=0;}
376    if (controlKey && !shiftKey && !(keyboard[7] & 0x80)) addToKeyboardBuffer(state, 0x7F); /* controlKey + DELETE */
377    else {state->KbRepeatTable[0x7F]=0;}
384378
385    if (!shiftKey && !(keyboard[8] & 0x01)) addToKeyboardBuffer(0x80); /* HOME */
386    else {KbRepeatTable[0x80]=0;}
387    if (!shiftKey && !(keyboard[6] & 0x01)) addToKeyboardBuffer(0x81); /* I */
388    else {KbRepeatTable[0x81]=0;}
389    if (!shiftKey && !(keyboard[6] & 0x02)) addToKeyboardBuffer(0x82); /* II */
390    else {KbRepeatTable[0x82]=0;}
391    if (!shiftKey && !(keyboard[6] & 0x04)) addToKeyboardBuffer(0x83); /* III */
392    else {KbRepeatTable[0x83]=0;}
393    if (!shiftKey && !(keyboard[6] & 0x08)) addToKeyboardBuffer(0x84); /* IV */
394    else {KbRepeatTable[0x84]=0;}
395    if (!shiftKey && !(keyboard[6] & 0x10)) addToKeyboardBuffer(0x85); /* V */
396    else {KbRepeatTable[0x85]=0;}
397    if (!shiftKey && !(keyboard[6] & 0x20)) addToKeyboardBuffer(0x86); /* VI */
398    else {KbRepeatTable[0x86]=0;}
379    if (!shiftKey && !(keyboard[8] & 0x01)) addToKeyboardBuffer(state, 0x80); /* HOME */
380    else {state->KbRepeatTable[0x80]=0;}
381    if (!shiftKey && !(keyboard[6] & 0x01)) addToKeyboardBuffer(state, 0x81); /* I */
382    else {state->KbRepeatTable[0x81]=0;}
383    if (!shiftKey && !(keyboard[6] & 0x02)) addToKeyboardBuffer(state, 0x82); /* II */
384    else {state->KbRepeatTable[0x82]=0;}
385    if (!shiftKey && !(keyboard[6] & 0x04)) addToKeyboardBuffer(state, 0x83); /* III */
386    else {state->KbRepeatTable[0x83]=0;}
387    if (!shiftKey && !(keyboard[6] & 0x08)) addToKeyboardBuffer(state, 0x84); /* IV */
388    else {state->KbRepeatTable[0x84]=0;}
389    if (!shiftKey && !(keyboard[6] & 0x10)) addToKeyboardBuffer(state, 0x85); /* V */
390    else {state->KbRepeatTable[0x85]=0;}
391    if (!shiftKey && !(keyboard[6] & 0x20)) addToKeyboardBuffer(state, 0x86); /* VI */
392    else {state->KbRepeatTable[0x86]=0;}
399393    /* 0x87 - Unused */
400394
401395    /* 0x88 - Unused */
402    if (shiftKey && !controlKey && !(keyboard[6] & 0x01)) addToKeyboardBuffer(0x89); /* shiftKey + I */
403    else {KbRepeatTable[0x89]=0;}
404    if (shiftKey && !controlKey && !(keyboard[6] & 0x02)) addToKeyboardBuffer(0x8A); /* shiftKey + II */
405    else {KbRepeatTable[0x8A]=0;}
406    if (shiftKey && !controlKey && !(keyboard[6] & 0x04)) addToKeyboardBuffer(0x8B); /* shiftKey + III */
407    else {KbRepeatTable[0x8B]=0;}
408    if (shiftKey && !controlKey && !(keyboard[6] & 0x08)) addToKeyboardBuffer(0x8C); /* shiftKey + IV */
409    else {KbRepeatTable[0x8C]=0;}
410    if (shiftKey && !controlKey && !(keyboard[6] & 0x10)) addToKeyboardBuffer(0x8D); /* shiftKey + V */
411    else {KbRepeatTable[0x8D]=0;}
412    if (shiftKey && !controlKey && !(keyboard[6] & 0x20)) addToKeyboardBuffer(0x8E); /* shiftKey + VI */
413    else {KbRepeatTable[0x8E]=0;}
396    if (shiftKey && !controlKey && !(keyboard[6] & 0x01)) addToKeyboardBuffer(state, 0x89); /* shiftKey + I */
397    else {state->KbRepeatTable[0x89]=0;}
398    if (shiftKey && !controlKey && !(keyboard[6] & 0x02)) addToKeyboardBuffer(state, 0x8A); /* shiftKey + II */
399    else {state->KbRepeatTable[0x8A]=0;}
400    if (shiftKey && !controlKey && !(keyboard[6] & 0x04)) addToKeyboardBuffer(state, 0x8B); /* shiftKey + III */
401    else {state->KbRepeatTable[0x8B]=0;}
402    if (shiftKey && !controlKey && !(keyboard[6] & 0x08)) addToKeyboardBuffer(state, 0x8C); /* shiftKey + IV */
403    else {state->KbRepeatTable[0x8C]=0;}
404    if (shiftKey && !controlKey && !(keyboard[6] & 0x10)) addToKeyboardBuffer(state, 0x8D); /* shiftKey + V */
405    else {state->KbRepeatTable[0x8D]=0;}
406    if (shiftKey && !controlKey && !(keyboard[6] & 0x20)) addToKeyboardBuffer(state, 0x8E); /* shiftKey + VI */
407    else {state->KbRepeatTable[0x8E]=0;}
414408    /* 0x8F - Unused */
415409
416    if (!shiftKey && !(keyboard[7] & 0x01)) addToKeyboardBuffer(0x90); /* WILD CARD */
417    else {KbRepeatTable[0x90]=0;}
418    if (!shiftKey && !(keyboard[7] & 0x02)) addToKeyboardBuffer(0x91); /* UNDO */
419    else {KbRepeatTable[0x91]=0;}
420    if (!shiftKey && !(keyboard[7] & 0x04)) addToKeyboardBuffer(0x92); /* MOVE */
421    else {KbRepeatTable[0x92]=0;}
422    if (!shiftKey && !(keyboard[7] & 0x08)) addToKeyboardBuffer(0x93); /* STORE */
423    else {KbRepeatTable[0x93]=0;}
424    if (!shiftKey && !(keyboard[7] & 0x10)) addToKeyboardBuffer(0x94); /* INSERT */
425    else {KbRepeatTable[0x94]=0;}
426    if (!shiftKey && !(keyboard[7] & 0x20)) addToKeyboardBuffer(0x95); /* PRINT */
427    else {KbRepeatTable[0x95]=0;}
428    if (!shiftKey && !(keyboard[7] & 0x40)) addToKeyboardBuffer(0x96); /* CLEAR */
429    else {KbRepeatTable[0x96]=0;}
430    if (!shiftKey && !(keyboard[7] & 0x80)) addToKeyboardBuffer(0x97); /* DELETE */
431    else {KbRepeatTable[0x97]=0;}
410    if (!shiftKey && !(keyboard[7] & 0x01)) addToKeyboardBuffer(state, 0x90); /* WILD CARD */
411    else {state->KbRepeatTable[0x90]=0;}
412    if (!shiftKey && !(keyboard[7] & 0x02)) addToKeyboardBuffer(state, 0x91); /* UNDO */
413    else {state->KbRepeatTable[0x91]=0;}
414    if (!shiftKey && !(keyboard[7] & 0x04)) addToKeyboardBuffer(state, 0x92); /* MOVE */
415    else {state->KbRepeatTable[0x92]=0;}
416    if (!shiftKey && !(keyboard[7] & 0x08)) addToKeyboardBuffer(state, 0x93); /* STORE */
417    else {state->KbRepeatTable[0x93]=0;}
418    if (!shiftKey && !(keyboard[7] & 0x10)) addToKeyboardBuffer(state, 0x94); /* INSERT */
419    else {state->KbRepeatTable[0x94]=0;}
420    if (!shiftKey && !(keyboard[7] & 0x20)) addToKeyboardBuffer(state, 0x95); /* PRINT */
421    else {state->KbRepeatTable[0x95]=0;}
422    if (!shiftKey && !(keyboard[7] & 0x40)) addToKeyboardBuffer(state, 0x96); /* CLEAR */
423    else {state->KbRepeatTable[0x96]=0;}
424    if (!shiftKey && !(keyboard[7] & 0x80)) addToKeyboardBuffer(state, 0x97); /* DELETE */
425    else {state->KbRepeatTable[0x97]=0;}
432426
433    if (shiftKey && !controlKey && !(keyboard[7] & 0x01)) addToKeyboardBuffer(0x98); /* shiftKey + WILD CARD */
434    else {KbRepeatTable[0x98]=0;}
435    if (shiftKey && !controlKey && !(keyboard[7] & 0x02)) addToKeyboardBuffer(0x99); /* shiftKey + UNDO */
436    else {KbRepeatTable[0x99]=0;}
437    if (shiftKey && !controlKey && !(keyboard[7] & 0x04)) addToKeyboardBuffer(0x9A); /* shiftKey + MOVE */
438    else {KbRepeatTable[0x9A]=0;}
439    if (shiftKey && !controlKey && !(keyboard[7] & 0x08)) addToKeyboardBuffer(0x9B); /* shiftKey + STORE */
440    else {KbRepeatTable[0x9B]=0;}
441    if (shiftKey && !controlKey && !(keyboard[7] & 0x10)) addToKeyboardBuffer(0x9C); /* shiftKey + INSERT */
442    else {KbRepeatTable[0x9C]=0;}
443    if (shiftKey && !controlKey && !(keyboard[7] & 0x20)) addToKeyboardBuffer(0x9D); /* shiftKey + PRINT */
444    else {KbRepeatTable[0x9D]=0;}
445    if (shiftKey && !controlKey && !(keyboard[7] & 0x40)) addToKeyboardBuffer(0x9E); /* shiftKey + CLEAR */
446    else {KbRepeatTable[0x9E]=0;}
447    if (shiftKey && !controlKey && !(keyboard[7] & 0x80)) addToKeyboardBuffer(0x9F); /* shiftKey + DELETE */
448    else {KbRepeatTable[0x9F]=0;}
427    if (shiftKey && !controlKey && !(keyboard[7] & 0x01)) addToKeyboardBuffer(state, 0x98); /* shiftKey + WILD CARD */
428    else {state->KbRepeatTable[0x98]=0;}
429    if (shiftKey && !controlKey && !(keyboard[7] & 0x02)) addToKeyboardBuffer(state, 0x99); /* shiftKey + UNDO */
430    else {state->KbRepeatTable[0x99]=0;}
431    if (shiftKey && !controlKey && !(keyboard[7] & 0x04)) addToKeyboardBuffer(state, 0x9A); /* shiftKey + MOVE */
432    else {state->KbRepeatTable[0x9A]=0;}
433    if (shiftKey && !controlKey && !(keyboard[7] & 0x08)) addToKeyboardBuffer(state, 0x9B); /* shiftKey + STORE */
434    else {state->KbRepeatTable[0x9B]=0;}
435    if (shiftKey && !controlKey && !(keyboard[7] & 0x10)) addToKeyboardBuffer(state, 0x9C); /* shiftKey + INSERT */
436    else {state->KbRepeatTable[0x9C]=0;}
437    if (shiftKey && !controlKey && !(keyboard[7] & 0x20)) addToKeyboardBuffer(state, 0x9D); /* shiftKey + PRINT */
438    else {state->KbRepeatTable[0x9D]=0;}
439    if (shiftKey && !controlKey && !(keyboard[7] & 0x40)) addToKeyboardBuffer(state, 0x9E); /* shiftKey + CLEAR */
440    else {state->KbRepeatTable[0x9E]=0;}
441    if (shiftKey && !controlKey && !(keyboard[7] & 0x80)) addToKeyboardBuffer(state, 0x9F); /* shiftKey + DELETE */
442    else {state->KbRepeatTable[0x9F]=0;}
449443
450    if (!controlKey && !(keyboard[8] & 0x02)) addToKeyboardBuffer(0xA0); /* UP ARROW */
451    else {KbRepeatTable[0xA0]=0;}
452    if (!controlKey && !(keyboard[8] & 0x10)) addToKeyboardBuffer(0xA1); /* RIGHT ARROW */
453    else {KbRepeatTable[0xA1]=0;}
454    if (!controlKey && !(keyboard[8] & 0x04)) addToKeyboardBuffer(0xA2); /* DOWN ARROW */
455    else {KbRepeatTable[0xA2]=0;}
456    if (!controlKey && !(keyboard[8] & 0x08)) addToKeyboardBuffer(0xA3); /* LEFT ARROW */
457    else {KbRepeatTable[0xA3]=0;}
458    if (controlKey && !shiftKey && !(keyboard[8] & 0x02)) addToKeyboardBuffer(0xA4); /* controlKey + UP ARROW */
459    else {KbRepeatTable[0xA4]=0;}
460    if (controlKey && !shiftKey && !(keyboard[8] & 0x10)) addToKeyboardBuffer(0xA5); /* controlKey + RIGHT ARROW */
461    else {KbRepeatTable[0xA5]=0;}
462    if (controlKey && !shiftKey && !(keyboard[8] & 0x04)) addToKeyboardBuffer(0xA6); /* controlKey + DOWN ARROW */
463    else {KbRepeatTable[0xA6]=0;}
464    if (controlKey && !shiftKey && !(keyboard[8] & 0x08)) addToKeyboardBuffer(0xA7); /* controlKey + LEFT ARROW */
465    else {KbRepeatTable[0xA7]=0;}
444    if (!controlKey && !(keyboard[8] & 0x02)) addToKeyboardBuffer(state, 0xA0); /* UP ARROW */
445    else {state->KbRepeatTable[0xA0]=0;}
446    if (!controlKey && !(keyboard[8] & 0x10)) addToKeyboardBuffer(state, 0xA1); /* RIGHT ARROW */
447    else {state->KbRepeatTable[0xA1]=0;}
448    if (!controlKey && !(keyboard[8] & 0x04)) addToKeyboardBuffer(state, 0xA2); /* DOWN ARROW */
449    else {state->KbRepeatTable[0xA2]=0;}
450    if (!controlKey && !(keyboard[8] & 0x08)) addToKeyboardBuffer(state, 0xA3); /* LEFT ARROW */
451    else {state->KbRepeatTable[0xA3]=0;}
452    if (controlKey && !shiftKey && !(keyboard[8] & 0x02)) addToKeyboardBuffer(state, 0xA4); /* controlKey + UP ARROW */
453    else {state->KbRepeatTable[0xA4]=0;}
454    if (controlKey && !shiftKey && !(keyboard[8] & 0x10)) addToKeyboardBuffer(state, 0xA5); /* controlKey + RIGHT ARROW */
455    else {state->KbRepeatTable[0xA5]=0;}
456    if (controlKey && !shiftKey && !(keyboard[8] & 0x04)) addToKeyboardBuffer(state, 0xA6); /* controlKey + DOWN ARROW */
457    else {state->KbRepeatTable[0xA6]=0;}
458    if (controlKey && !shiftKey && !(keyboard[8] & 0x08)) addToKeyboardBuffer(state, 0xA7); /* controlKey + LEFT ARROW */
459    else {state->KbRepeatTable[0xA7]=0;}
466460
467    if (!controlKey && !(keyboard[8] & 0x02) && !(keyboard[8] & 0x10)) addToKeyboardBuffer(0xA8); /* UP ARROW + RIGHT ARROW */
468    else {KbRepeatTable[0xA8]=0;}
469    if (!controlKey && !(keyboard[8] & 0x10) && !(keyboard[8] & 0x04)) addToKeyboardBuffer(0xA9); /* RIGHT ARROW + DOWN ARROW */
470    else {KbRepeatTable[0xA9]=0;}
471    if (!controlKey && !(keyboard[8] & 0x04) && !(keyboard[8] & 0x08)) addToKeyboardBuffer(0xAA); /* DOWN ARROW + LEFT ARROW */
472    else {KbRepeatTable[0xAA]=0;}
473    if (!controlKey && !(keyboard[8] & 0x08) && !(keyboard[8] & 0x02)) addToKeyboardBuffer(0xAB); /* LEFT ARROW + UP ARROW */
474    else {KbRepeatTable[0xAB]=0;}
475    if (!controlKey && !(keyboard[8] & 0x01) && !(keyboard[8] & 0x02)) addToKeyboardBuffer(0xAC); /* HOME + UP ARROW */
476    else {KbRepeatTable[0xAC]=0;}
477    if (!controlKey && !(keyboard[8] & 0x01) && !(keyboard[8] & 0x10)) addToKeyboardBuffer(0xAD); /* HOME + RIGHT ARROW */
478    else {KbRepeatTable[0xAD]=0;}
479    if (!controlKey && !(keyboard[8] & 0x01) && !(keyboard[8] & 0x04)) addToKeyboardBuffer(0xAE); /* HOME + DOWN ARROW */
480    else {KbRepeatTable[0xAE]=0;}
481    if (!controlKey && !(keyboard[8] & 0x01) && !(keyboard[8] & 0x08)) addToKeyboardBuffer(0xAF); /* HOME + LEFT ARROW */
482    else {KbRepeatTable[0xAF]=0;}
461    if (!controlKey && !(keyboard[8] & 0x02) && !(keyboard[8] & 0x10)) addToKeyboardBuffer(state, 0xA8); /* UP ARROW + RIGHT ARROW */
462    else {state->KbRepeatTable[0xA8]=0;}
463    if (!controlKey && !(keyboard[8] & 0x10) && !(keyboard[8] & 0x04)) addToKeyboardBuffer(state, 0xA9); /* RIGHT ARROW + DOWN ARROW */
464    else {state->KbRepeatTable[0xA9]=0;}
465    if (!controlKey && !(keyboard[8] & 0x04) && !(keyboard[8] & 0x08)) addToKeyboardBuffer(state, 0xAA); /* DOWN ARROW + LEFT ARROW */
466    else {state->KbRepeatTable[0xAA]=0;}
467    if (!controlKey && !(keyboard[8] & 0x08) && !(keyboard[8] & 0x02)) addToKeyboardBuffer(state, 0xAB); /* LEFT ARROW + UP ARROW */
468    else {state->KbRepeatTable[0xAB]=0;}
469    if (!controlKey && !(keyboard[8] & 0x01) && !(keyboard[8] & 0x02)) addToKeyboardBuffer(state, 0xAC); /* HOME + UP ARROW */
470    else {state->KbRepeatTable[0xAC]=0;}
471    if (!controlKey && !(keyboard[8] & 0x01) && !(keyboard[8] & 0x10)) addToKeyboardBuffer(state, 0xAD); /* HOME + RIGHT ARROW */
472    else {state->KbRepeatTable[0xAD]=0;}
473    if (!controlKey && !(keyboard[8] & 0x01) && !(keyboard[8] & 0x04)) addToKeyboardBuffer(state, 0xAE); /* HOME + DOWN ARROW */
474    else {state->KbRepeatTable[0xAE]=0;}
475    if (!controlKey && !(keyboard[8] & 0x01) && !(keyboard[8] & 0x08)) addToKeyboardBuffer(state, 0xAF); /* HOME + LEFT ARROW */
476    else {state->KbRepeatTable[0xAF]=0;}
483477
484478    /* 0xB0-0xB7 - Unused */
485479
486    if (shiftKey && !controlKey && !(keyboard[9] & 0x02)) addToKeyboardBuffer(0xB8); /* shiftKey + BACKSPACE */
487    else {KbRepeatTable[0xB8]=0;}
488    if (shiftKey && !controlKey && !(keyboard[8] & 0x20)) addToKeyboardBuffer(0xB9); /* shiftKey + TAB */
489    else {KbRepeatTable[0xB9]=0;}
480    if (shiftKey && !controlKey && !(keyboard[9] & 0x02)) addToKeyboardBuffer(state, 0xB8); /* shiftKey + BACKSPACE */
481    else {state->KbRepeatTable[0xB8]=0;}
482    if (shiftKey && !controlKey && !(keyboard[8] & 0x20)) addToKeyboardBuffer(state, 0xB9); /* shiftKey + TAB */
483    else {state->KbRepeatTable[0xB9]=0;}
490484    /* 0xBA-0xEF - Unused */
491485
492486    /* 0xF0-0xFF - Reserved for internal use by keyboard software */
r9648r9649
494488
495489static void master6801_behaviour(running_machine *machine, int offset, int data)
496490{
491   adam_state *state = machine->driver_data<adam_state>();
497492/*
498493The Master MC6801 controls all AdamNet operations, keyboard, tapes, disks...
499494We are going to "simulate" the behaviour of the master 6801, because we does not have the 2kbytes ROM DUMP
r9648r9649
507502   UINT8 *ram;
508503
509504   ram = memory_region(machine, "maincpu");
510   if (offset == adam_pcb)
505   if (offset == state->pcb)
511506   {
512507      switch (data)
513508      {
r9648r9649
519514            ram[offset] = 0x82;
520515            //logerror("Synchronizing the Master 6801 clock\n");
521516            break;
522         case 3: /* Request to relocate adam_pcb */
517         case 3: /* Request to relocate state->pcb */
523518            ram[offset] = 0x83; /* Must return 0x83 if success */
524519            //ram[offset] = 0x9B; /* Time Out */
525            logerror("Request to relocate adam_pcb from %04Xh to %04Xh... not implemented... but returns OK\n", adam_pcb, (ram[adam_pcb+1]|ram[adam_pcb+2]<<8));
520            logerror("Request to relocate state->pcb from %04Xh to %04Xh... not implemented... but returns OK\n", state->pcb, (ram[state->pcb+1]|ram[state->pcb+2]<<8));
526521            break;
527522      }
528523   }
529524
530   for(DCB_Num=1;DCB_Num<=ram[adam_pcb+3];DCB_Num++) /* Test status of each DCB in adam_pcb table */
525   for(DCB_Num=1;DCB_Num<=ram[state->pcb+3];DCB_Num++) /* Test status of each DCB in state->pcb table */
531526   {
532      statusDCB = (adam_pcb+4)+(DCB_Num-1)*21;
527      statusDCB = (state->pcb+4)+(DCB_Num-1)*21;
533528      if (offset==statusDCB)
534529      {
535530         //logerror("Accesing DCB %02Xh\n", DCB_Num);
r9648r9649
609604                    */
610605               if (deviceNum==1)
611606               {
612                  kbcode=getKeyFromBuffer();
607                  kbcode=getKeyFromBuffer(state);
613608                  if (kbcode>0)
614609                  {
615610                     ram[buffer] = kbcode; /* Key pressed  */
r9648r9649
663658
664659WRITE8_HANDLER( adam_common_writes_w )
665660{
666    switch (adam_upper_memory)
661   adam_state *state = space->machine->driver_data<adam_state>();
662    switch (state->upper_memory)
667663    {
668664        case 0: /* Internal RAM */
669665            memory_region(space->machine, "maincpu")[0x08000+offset] = data;
670            if (offset>=(adam_pcb-0x08000)) master6801_behaviour(space->machine, offset+0x08000, data);
666            if (offset>=(state->pcb-0x08000)) master6801_behaviour(space->machine, offset+0x08000, data);
671667            break;
672668        case 1: /* ROM Expansion */
673669            break;
r9648r9649
681677
682678 READ8_HANDLER( adamnet_r )
683679{
684    //logerror("adam_net_data Read %2xh\n",adam_net_data);
685    return adam_net_data;
680   adam_state *state = space->machine->driver_data<adam_state>();
681    //logerror("adam_net_data Read %2xh\n",state->net_data);
682    return state->net_data;
686683}
687684
688685WRITE8_HANDLER( adamnet_w )
689686{
687   adam_state *state = space->machine->driver_data<adam_state>();
690688   /*
691689    If SmartWriter ROM is selected on lower Z80 memory
692690    if data bit1 is 1 -> Lower 32k = EOS otherwise Lower 32k = SmartWriter
r9648r9649
696694
697695   if (data==0x0F)
698696      adam_reset_pcb(space->machine);
699   if ( (adam_lower_memory==0) && ((data&0x02)!=(adam_net_data&0x02)) )
697   if ( (state->lower_memory==0) && ((data&0x02)!=(state->net_data&0x02)) )
700698   {
701699      if (data&0x02)
702700      {
r9648r9649
723721         memory_set_bankptr(space->machine, "bank9", BankBase+0x3A000); /* Write protecting ROM */
724722      }
725723   }
726   adam_net_data = data;
724   state->net_data = data;
727725}
728726
729727READ8_HANDLER( adam_memory_map_controller_r )
730728{
731    return (adam_upper_memory << 2) + adam_lower_memory;
729   adam_state *state = space->machine->driver_data<adam_state>();
730    return (state->upper_memory << 2) + state->lower_memory;
732731}
733732
734733WRITE8_HANDLER( adam_memory_map_controller_w )
735734{
735   adam_state *state = space->machine->driver_data<adam_state>();
736736    /*
737737    Writes to ports 0x60 to 0x7F set memory map:
738738
r9648r9649
752752
753753    */
754754
755    adam_lower_memory = (data & 0x03);
756    adam_upper_memory = (data & 0x0C)>>2;
755    state->lower_memory = (data & 0x03);
756    state->upper_memory = (data & 0x0C)>>2;
757757    adam_set_memory_banks(space->machine);
758    //logerror("Configurando la memoria, L:%02xh, U:%02xh\n", adam_lower_memory, adam_upper_memory);
758    //logerror("Configurando la memoria, L:%02xh, U:%02xh\n", state->lower_memory, state->upper_memory);
759759}
760760
761761READ8_HANDLER(adam_video_r)
r9648r9649
783783
784784READ8_HANDLER ( adam_paddle_r )
785785{
786   adam_state *state = space->machine->driver_data<adam_state>();
786787
787788    if (!(input_port_read(space->machine, "controllers") & 0x0F)) return (0xFF); /* If no controllers enabled */
788789   /* Player 1 */
789790   if ((offset & 0x02)==0)
790791   {
791792      /* Keypad and fire 1 (SAC Yellow Button) */
792      if (joy_mode==0)
793      if (state->joy_mode==0)
793794      {
794795         int inport0,inport1,inport6,data;
795796
r9648r9649
827828
828829         if (inport6&0x07) /* If Extra Contollers enabled */
829830         {
830             if (adam_joy_stat[0]==0)
831             if (state->joy_stat[0]==0)
831832               data |= 0x30; /* Spinner Move Left */
832             else if (adam_joy_stat[0]==1)
833             else if (state->joy_stat[0]==1)
833834               data |= 0x20; /* Spinner Move Right */
834835         }
835836         return data | 0x80;
r9648r9649
839840   else
840841   {
841842      /* Keypad and fire 1 */
842      if (joy_mode==0)
843      if (state->joy_mode==0)
843844      {
844845         int inport3,inport4,data;
845846
r9648r9649
874875
875876         if (inport6&0x02) /* If Roller Controller enabled */
876877         {
877             if (adam_joy_stat[1]==0) data|=0x30;
878             else if (adam_joy_stat[1]==1) data|=0x20;
878             if (state->joy_stat[1]==0) data|=0x30;
879             else if (state->joy_stat[1]==1) data|=0x20;
879880         }
880881
881882         return data | 0x80;
r9648r9649
887888
888889WRITE8_HANDLER ( adam_paddle_toggle_off )
889890{
890   joy_mode = 0;
891    return;
891   adam_state *state = space->machine->driver_data<adam_state>();
892   state->joy_mode = 0;
892893}
893894
894895WRITE8_HANDLER ( adam_paddle_toggle_on )
895896{
896   joy_mode = 1;
897    return;
897   adam_state *state = space->machine->driver_data<adam_state>();
898   state->joy_mode = 1;
898899}
src/mess/machine/aim65.c
r9648r9649
2626******************************************************************************/
2727
2828
29static UINT8 pia_a, pia_b;
30static UINT8 riot_port_a;
3129
3230
3331
r9648r9649
6664
6765static void dl1416_update(running_device *device, int index)
6866{
69   dl1416_ce_w(device, pia_a & (0x04 << index));
70   dl1416_wr_w(device, BIT(pia_a, 7));
71   dl1416_cu_w(device, BIT(pia_b, 7));
72   dl1416_data_w(device, pia_a & 0x03, pia_b & 0x7f);
67   aim65_state *state = device->machine->driver_data<aim65_state>();
68   dl1416_ce_w(device, state->pia_a & (0x04 << index));
69   dl1416_wr_w(device, BIT(state->pia_a, 7));
70   dl1416_cu_w(device, BIT(state->pia_b, 7));
71   dl1416_data_w(device, state->pia_a & 0x03, state->pia_b & 0x7f);
7372}
7473
7574static void aim65_pia(running_machine *machine)
r9648r9649
8483
8584WRITE8_DEVICE_HANDLER(aim65_pia_a_w)
8685{
87   pia_a = data;
86   aim65_state *state = device->machine->driver_data<aim65_state>();
87   state->pia_a = data;
8888   aim65_pia(device->machine);
8989}
9090
9191
9292WRITE8_DEVICE_HANDLER(aim65_pia_b_w)
9393{
94   pia_b = data;
94   aim65_state *state = device->machine->driver_data<aim65_state>();
95   state->pia_b = data;
9596   aim65_pia(device->machine);
9697}
9798
r9648r9649
130131
131132READ8_DEVICE_HANDLER(aim65_riot_b_r)
132133{
134   aim65_state *state = device->machine->driver_data<aim65_state>();
133135   static const char *const keynames[] =
134136   {
135137      "keyboard_0", "keyboard_1", "keyboard_2", "keyboard_3",
r9648r9649
141143   /* scan keyboard rows */
142144   for (row = 0; row < 8; row++)
143145   {
144      if (!(riot_port_a & (1 << row)))
146      if (!(state->riot_port_a & (1 << row)))
145147         data &= input_port_read(device->machine, keynames[row]);
146148   }
147149
r9648r9649
151153
152154WRITE8_DEVICE_HANDLER(aim65_riot_a_w)
153155{
154   riot_port_a = data;
156   aim65_state *state = device->machine->driver_data<aim65_state>();
157   state->riot_port_a = data;
155158}
156159
157160
src/mess/machine/a7800.c
r9648r9649
3030#include "hash.h"
3131
3232
33int a7800_lines;
34int a7800_ispal;
3533
3634/* local */
37static unsigned char *a7800_cart_bkup = NULL;
38static unsigned char *a7800_bios_bkup = NULL;
39static int a7800_ctrl_lock;
40static int a7800_ctrl_reg;
41static int maria_flag;
4235
43static unsigned char *a7800_cartridge_rom;
44static unsigned int a7800_cart_type;
45static unsigned long a7800_cart_size;
46static unsigned char a7800_stick_type;
47static UINT8 *ROM;
4836
4937
5038/***************************************************************************
r9648r9649
7664
7765static void a7800_driver_init(running_machine *machine, int ispal, int lines)
7866{
67   a7800_state *state = machine->driver_data<a7800_state>();
7968   address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
80   ROM = memory_region(machine, "maincpu");
81   a7800_ispal = ispal;
82   a7800_lines = lines;
69   state->ROM = memory_region(machine, "maincpu");
70   state->ispal = ispal;
71   state->lines = lines;
8372
8473   /* standard banks */
85   memory_set_bankptr(machine, "bank5", &ROM[0x2040]);      /* RAM0 */
86   memory_set_bankptr(machine, "bank6", &ROM[0x2140]);      /* RAM1 */
87   memory_set_bankptr(machine, "bank7", &ROM[0x2000]);      /* MAINRAM */
74   memory_set_bankptr(machine, "bank5", &state->ROM[0x2040]);      /* RAM0 */
75   memory_set_bankptr(machine, "bank6", &state->ROM[0x2140]);      /* RAM1 */
76   memory_set_bankptr(machine, "bank7", &state->ROM[0x2000]);      /* MAINRAM */
8877
8978   /* Brutal hack put in as a consequence of new memory system; fix this */
9079   memory_install_readwrite_bank(space, 0x0480, 0x04FF, 0, 0,"bank10");
91   memory_set_bankptr(machine, "bank10", ROM + 0x0480);
80   memory_set_bankptr(machine, "bank10", state->ROM + 0x0480);
9281   memory_install_readwrite_bank(space, 0x1800, 0x27FF, 0, 0, "bank11");
93   memory_set_bankptr(machine, "bank11", ROM + 0x1800);
82   memory_set_bankptr(machine, "bank11", state->ROM + 0x1800);
9483}
9584
9685
r9648r9649
10897
10998MACHINE_RESET( a7800 )
11099{
100   a7800_state *state = machine->driver_data<a7800_state>();
111101   UINT8 *memory;
112102   address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
113103
114   a7800_ctrl_lock = 0;
115   a7800_ctrl_reg = 0;
116   maria_flag = 0;
104   state->ctrl_lock = 0;
105   state->ctrl_reg = 0;
106   state->maria_flag = 0;
117107
118108   /* set banks to default states */
119109   memory = memory_region(machine, "maincpu");
r9648r9649
123113   memory_set_bankptr(machine,  "bank4", memory + 0xC000 );
124114
125115   /* pokey cartridge */
126   if (a7800_cart_type & 0x01)
116   if (state->cart_type & 0x01)
127117   {
128118      running_device *pokey = machine->device("pokey");
129119      memory_install_read8_device_handler(space, pokey, 0x4000, 0x7FFF, 0, 0, pokey_r);
r9648r9649
149139    bit 0 0x01 - pokey cart
150140    bit 1 0x02 - supercart bank switched
151141    bit 2 0x04 - supercart RAM at $4000
152    bit 3 0x08 - additional ROM at $4000
142    bit 3 0x08 - additional state->ROM at $4000
153143
154144    bit 8-15 - Special
155145        0 = Normal cart
r9648r9649
198188
199189DEVICE_START( a7800_cart )
200190{
191   a7800_state *state = device->machine->driver_data<a7800_state>();
201192   UINT8   *memory;
202193
203194   memory = memory_region(device->machine, "maincpu");
204   a7800_bios_bkup = NULL;
205   a7800_cart_bkup = NULL;
195   state->bios_bkup = NULL;
196   state->cart_bkup = NULL;
206197
207198   /* Allocate memory for BIOS bank switching */
208   a7800_bios_bkup = auto_alloc_array(device->machine, UINT8, 0x4000);
209   a7800_cart_bkup = auto_alloc_array(device->machine, UINT8, 0x4000);
199   state->bios_bkup = auto_alloc_array(device->machine, UINT8, 0x4000);
200   state->cart_bkup = auto_alloc_array(device->machine, UINT8, 0x4000);
210201
211202   /* save the BIOS so we can switch it in and out */
212   memcpy( a7800_bios_bkup, memory + 0xC000, 0x4000 );
203   memcpy( state->bios_bkup, memory + 0xC000, 0x4000 );
213204
214205   /* defaults for PAL bios without cart */
215   a7800_cart_type = 0;
216   a7800_stick_type = 1;
206   state->cart_type = 0;
207   state->stick_type = 1;
217208}
218209
219210
220211DEVICE_IMAGE_LOAD( a7800_cart )
221212{
213   a7800_state *state = image.device().machine->driver_data<a7800_state>();
222214   long len,start;
223215   unsigned char header[128];
224216   UINT8 *memory;
r9648r9649
233225      return IMAGE_INIT_FAIL;
234226
235227   len =(header[49] << 24) |(header[50] << 16) |(header[51] << 8) | header[52];
236   a7800_cart_size = len;
228   state->cart_size = len;
237229
238   a7800_cart_type =(header[53] << 8) | header[54];
239   a7800_stick_type = header[55];
240   logerror( "Cart type: %x\n", a7800_cart_type );
230   state->cart_type =(header[53] << 8) | header[54];
231   state->stick_type = header[55];
232   logerror( "Cart type: %x\n", state->cart_type );
241233
242234   /* For now, if game support stick and gun, set it to stick */
243   if( a7800_stick_type == 3 )
244      a7800_stick_type = 1;
235   if( state->stick_type == 3 )
236      state->stick_type = 1;
245237
246   if( a7800_cart_type == 0 || a7800_cart_type == 1 )
238   if( state->cart_type == 0 || state->cart_type == 1 )
247239   {
248240      /* Normal Cart */
249241
250242      start = 0x10000 - len;
251      a7800_cartridge_rom = memory + start;
252      image.fread(a7800_cartridge_rom, len);
243      state->cartridge_rom = memory + start;
244      image.fread(state->cartridge_rom, len);
253245   }
254   else if( a7800_cart_type & 0x02 )
246   else if( state->cart_type & 0x02 )
255247   {
256248      /* Super Cart */
257249
258      /* Extra ROM at $4000 */
259      if( a7800_cart_type & 0x08 )
250      /* Extra state->ROM at $4000 */
251      if( state->cart_type & 0x08 )
260252      {
261253         image.fread(memory + 0x4000, 0x4000 );
262254         len -= 0x4000;
263255      }
264256
265      a7800_cartridge_rom = memory + 0x10000;
266      image.fread(a7800_cartridge_rom, len);
257      state->cartridge_rom = memory + 0x10000;
258      image.fread(state->cartridge_rom, len);
267259
268260      /* bank 0 */
269261      memcpy( memory + 0x8000, memory + 0x10000, 0x4000);
r9648r9649
277269        */
278270
279271      /* bank n-2 */
280      if( ! ( a7800_cart_type & 0x0D ) )
272      if( ! ( state->cart_type & 0x0D ) )
281273      {
282274         memcpy( memory + 0x4000, memory + 0x10000 + len - 0x8000, 0x4000);
283275      }
284276   }
285   else if( a7800_cart_type == MBANK_TYPE_ABSOLUTE )
277   else if( state->cart_type == MBANK_TYPE_ABSOLUTE )
286278   {
287279      /* F18 Hornet */
288280
289      logerror( "Cart type: %x Absolute\n",a7800_cart_type );
281      logerror( "Cart type: %x Absolute\n",state->cart_type );
290282
291      a7800_cartridge_rom = memory + 0x10000;
292      image.fread(a7800_cartridge_rom, len );
283      state->cartridge_rom = memory + 0x10000;
284      image.fread(state->cartridge_rom, len );
293285
294286      /* bank 0 */
295287      memcpy( memory + 0x4000, memory + 0x10000, 0x4000 );
r9648r9649
297289      /* last bank */
298290      memcpy( memory + 0x8000, memory + 0x18000, 0x8000);
299291   }
300   else if( a7800_cart_type == MBANK_TYPE_ACTIVISION )
292   else if( state->cart_type == MBANK_TYPE_ACTIVISION )
301293   {
302294      /* Activision */
303295
304      logerror( "Cart type: %x Activision\n",a7800_cart_type );
296      logerror( "Cart type: %x Activision\n",state->cart_type );
305297
306      a7800_cartridge_rom = memory + 0x10000;
307      image.fread(a7800_cartridge_rom, len );
298      state->cartridge_rom = memory + 0x10000;
299      image.fread(state->cartridge_rom, len );
308300
309301      /* bank 0 */
310302      memcpy( memory + 0xA000, memory + 0x10000, 0x4000 );
r9648r9649
323315
324316   }
325317
326   memcpy( a7800_cart_bkup, memory + 0xC000, 0x4000 );
327   memcpy( memory + 0xC000, a7800_bios_bkup, 0x4000 );
318   memcpy( state->cart_bkup, memory + 0xC000, 0x4000 );
319   memcpy( memory + 0xC000, state->bios_bkup, 0x4000 );
328320   return IMAGE_INIT_PASS;
329321}
330322
331323
332324WRITE8_HANDLER( a7800_RAM0_w )
333325{
334   ROM[0x2040 + offset] = data;
335   ROM[0x40 + offset] = data;
326   a7800_state *state = space->machine->driver_data<a7800_state>();
327   state->ROM[0x2040 + offset] = data;
328   state->ROM[0x40 + offset] = data;
336329}
337330
338331
339332WRITE8_HANDLER( a7800_cart_w )
340333{
334   a7800_state *state = space->machine->driver_data<a7800_state>();
341335   UINT8 *memory = memory_region(space->machine, "maincpu");
342336
343337   if(offset < 0x4000)
344338   {
345      if(a7800_cart_type & 0x04)
339      if(state->cart_type & 0x04)
346340      {
347         ROM[0x4000 + offset] = data;
341         state->ROM[0x4000 + offset] = data;
348342      }
349      else if(a7800_cart_type & 0x01)
343      else if(state->cart_type & 0x01)
350344      {
351345         running_device *pokey = space->machine->device("pokey");
352346         pokey_w(pokey, offset, data);
r9648r9649
357351      }
358352   }
359353
360   if(( a7800_cart_type & 0x02 ) &&( offset >= 0x4000 ) )
354   if(( state->cart_type & 0x02 ) &&( offset >= 0x4000 ) )
361355   {
362356      /* fix for 64kb supercart */
363      if( a7800_cart_size == 0x10000 )
357      if( state->cart_size == 0x10000 )
364358      {
365359         data &= 0x03;
366360      }
r9648r9649
372366      memory_set_bankptr(space->machine, "bank3",memory + 0x12000 + (data << 14));
373367   /*  logerror("BANK SEL: %d\n",data); */
374368   }
375   else if(( a7800_cart_type == MBANK_TYPE_ABSOLUTE ) &&( offset == 0x4000 ) )
369   else if(( state->cart_type == MBANK_TYPE_ABSOLUTE ) &&( offset == 0x4000 ) )
376370   {
377371      /* F18 Hornet */
378372      /*logerror( "F18 BANK SEL: %d\n", data );*/
r9648r9649
385379         memory_set_bankptr(space->machine, "bank1",memory + 0x14000 );
386380      }
387381   }
388   else if(( a7800_cart_type == MBANK_TYPE_ACTIVISION ) &&( offset >= 0xBF80 ) )
382   else if(( state->cart_type == MBANK_TYPE_ACTIVISION ) &&( offset >= 0xBF80 ) )
389383   {
390384      /* Activision */
391385      data = offset & 7;
r9648r9649
434428
435429WRITE8_HANDLER( a7800_TIA_w )
436430{
431   a7800_state *state = space->machine->driver_data<a7800_state>();
437432   switch(offset) {
438433   case 0x01:
439434      if(data & 0x01)
440435      {
441         maria_flag=1;
436         state->maria_flag=1;
442437      }
443      if(!a7800_ctrl_lock)
438      if(!state->ctrl_lock)
444439      {
445         a7800_ctrl_lock = data & 0x01;
446         a7800_ctrl_reg = data;
440         state->ctrl_lock = data & 0x01;
441         state->ctrl_reg = data;
447442
448443         if (data & 0x04)
449            memcpy( ROM + 0xC000, a7800_cart_bkup, 0x4000 );
444            memcpy( state->ROM + 0xC000, state->cart_bkup, 0x4000 );
450445         else
451            memcpy( ROM + 0xC000, a7800_bios_bkup, 0x4000 );
446            memcpy( state->ROM + 0xC000, state->bios_bkup, 0x4000 );
452447      }
453448      break;
454449   }
455450   tia_sound_w(space->machine->device("tia"), offset, data);
456   ROM[offset] = data;
451   state->ROM[offset] = data;
457452}
src/mess/machine/amstrad.c
r9648r9649
6868   0xff, 0x77, 0xb3, 0x51, 0xa8, 0xd4, 0x62, 0x39, 0x9c, 0x46, 0x2b, 0x15, 0x8a, 0xcd, 0xee
6969};
7070
71static int amstrad_system_type;
72static UINT8 aleste_mode;
73static int amstrad_plus_irq_cause;  // part of the interrupt vector for IM 2.  6 = raster IRQ, 4 = DMA channel 2, 2 = DMA channel 1, 0 = DMA channel 0
7471
7572
76/****************************
77 * Gate Array data (CPC) -
78 ****************************/
79static struct {
80   bitmap_t   *bitmap;      /* The bitmap we work on */
81   UINT8   pen_selected;      /* Pen selection */
82   UINT8   mrer;            /* Mode and ROM Enable Register */
83   UINT8   upper_bank;
8473
85   /* input signals from CRTC */
86   int      vsync;
87   int      hsync;
88   int      de;
89   int      ma;
90   int      ra;
9174
92   /* used for timing */
93   int      hsync_after_vsync_counter;
94   int      hsync_counter;            /* The gate array counts CRTC HSYNC pulses using an internal 6-bit counter. */
95
96   /* used for drawing the screen */
97   attotime   last_draw_time;
98   int      y;
99   UINT16   *draw_p;               /* Position in the bitmap where we are currently drawing */
100   UINT16   colour;
101   UINT16   address;
102   UINT8   *mode_lookup;
103   UINT8   data;
104   UINT8   ticks;
105   UINT8   ticks_increment;
106   UINT16   line_ticks;
107   UINT8   colour_ticks;
108   UINT8   max_colour_ticks;
109} gate_array;
110
111
112/****************************
113 * ASIC data (CPC plus)
114 ****************************/
115static struct {
116   UINT8   *ram;            /* pointer to RAM used for the CPC+ ASIC memory-mapped registers */
117   UINT8   enabled;         /* Are CPC plus features enabled/unlocked */
118   UINT8   pri;            /* Programmable raster interrupt */
119   UINT8   seqptr;            /* Current position in the ASIC unlocking sequence */
120   UINT8   rmr2;            /* ROM mapping register 2 */
121   UINT16   split_ma_base;      /* Used to handle split screen support */
122   UINT16   split_ma_started;   /* Used to handle split screen support */
123   UINT16   vpos;            /* Current logical scanline */
124   UINT16   h_start;         /* Position where DE became active */
125   UINT16   h_end;            /* Position where DE became inactive */
126   UINT8   addr_6845;         /* We need these to store a shadow copy of R1 of the mc6845 */
127   UINT8   horiz_disp;
128   UINT8   hscroll;
129   UINT8   de_start;          /* flag to check if DE is been enabled this frame yet */
130
131   /* DMA */
132   UINT8   dma_status;
133   UINT8   dma_clear;         /* Set if DMA interrupts are to be cleared automatically */
134   UINT8   dma_prescaler[3];   /* DMA channel prescaler */
135   UINT16   dma_repeat[3];      /* Location of the DMA channel's last repeat */
136   UINT16   dma_addr[3];      /* DMA channel address */
137   UINT16   dma_loopcount[3];   /* Count loops taken on this channel */
138   UINT16   dma_pause[3];      /* DMA pause count */
139} asic;
140
141
14275/* Ram configuration */
143static int amstrad_GateArray_RamConfiguration = 0;
14476
14577/* pointers to current ram configuration selected for banks */
146static unsigned char *AmstradCPC_RamBanks[4];
147static unsigned char *Aleste_RamBanks[4];
148static int aleste_active_page[4];  // page mapped to CPU RAM (is readable?)
14978
15079/* the hardware allows selection of 256 ROMs. Rom 0 is usually BASIC and Rom 7 is AMSDOS */
15180/* With the CPC hardware, if a expansion ROM is not connected, BASIC rom will be selected instead */
152static unsigned char *Amstrad_ROM_Table[256];
15381/* data present on input of ppi, and data written to ppi output */
15482#define amstrad_ppi_PortA 0
15583#define amstrad_ppi_PortB 1
15684#define amstrad_ppi_PortC 2
15785
158static UINT8 ppi_port_inputs[3];
159static UINT8 ppi_port_outputs[3];
16086
161static int aleste_rtc_function;
162static int aleste_fdc_int;
16387
16488/*------------------
16589  - Ram Management -
r9648r9649
179103};
180104
181105
182static int prev_reg;
183106
184107//static int amstrad_CRTC_CR = 0;        /* CR = Cursor Enabled */
185108
r9648r9649
187110/* this is updated from the eventlist and reflects the current state
188111of the render colours - these may be different to the current colour palette values */
189112/* colours can be changed at any time and will take effect immediatly */
190static UINT16 amstrad_GateArray_render_colours[17];
191113
192static UINT8 mode0_lookup[256];
193static UINT8 mode1_lookup[256];
194static UINT8 mode2_lookup[256];
195114
196115
197116/* The Amstrad CPC has a fixed palette of 27 colours generated from 3 levels of Red, Green and Blue.
r9648r9649
296215
297216WRITE_LINE_DEVICE_HANDLER( aleste_interrupt )
298217{
218   amstrad_state *drvstate = device->machine->driver_data<amstrad_state>();
299219   if(state == CLEAR_LINE)
300      aleste_fdc_int = 0;
220      drvstate->aleste_fdc_int = 0;
301221   else
302      aleste_fdc_int = 1;
222      drvstate->aleste_fdc_int = 1;
303223}
304224
305225
r9648r9649
444364}
445365
446366
447static void amstrad_init_lookups(void)
367static void amstrad_init_lookups( amstrad_state *state )
448368{
449369   int i;
450370
451371   for ( i = 0; i < 256; i++ )
452372   {
453      mode0_lookup[i] = ( ( i & 0x80 ) >> 7 ) | ( ( i & 0x20 ) >> 3 ) | ( ( i & 0x08 ) >> 2 ) | ( ( i & 0x02 ) << 2 );
454      mode1_lookup[i] = ( ( i & 0x80 ) >> 7 ) | ( ( i & 0x08 ) >> 2 );
455      mode2_lookup[i] = ( ( i & 0x80 ) >> 7 );
373      state->mode0_lookup[i] = ( ( i & 0x80 ) >> 7 ) | ( ( i & 0x20 ) >> 3 ) | ( ( i & 0x08 ) >> 2 ) | ( ( i & 0x02 ) << 2 );
374      state->mode1_lookup[i] = ( ( i & 0x80 ) >> 7 ) | ( ( i & 0x08 ) >> 2 );
375      state->mode2_lookup[i] = ( ( i & 0x80 ) >> 7 );
456376   }
457377}
458378
459379
460380/* Set the new screen mode (0,1,2,4) from the GateArray */
461static void amstrad_vh_update_mode( void )
381static void amstrad_vh_update_mode( amstrad_state *state )
462382{
463   if ( amstrad_system_type == SYSTEM_PLUS || amstrad_system_type == SYSTEM_GX4000 )
383   if ( state->system_type == SYSTEM_PLUS || state->system_type == SYSTEM_GX4000 )
464384   {
465385      /* select a cpc plus mode */
466      switch ( gate_array.mrer & 0x03 )
386      switch ( state->gate_array.mrer & 0x03 )
467387      {
468388      case 0:      /* Mode 0: 160x200, 16 colours */
469         gate_array.mode_lookup = mode0_lookup;
470         gate_array.max_colour_ticks = 4;
471         gate_array.ticks_increment = 1;
389         state->gate_array.mode_lookup = state->mode0_lookup;
390         state->gate_array.max_colour_ticks = 4;
391         state->gate_array.ticks_increment = 1;
472392         break;
473393
474394      case 1:      /* Mode 1: 320x200, 4 colous */
475         gate_array.mode_lookup = mode1_lookup;
476         gate_array.max_colour_ticks = 2;
477         gate_array.ticks_increment = 1;
395         state->gate_array.mode_lookup = state->mode1_lookup;
396         state->gate_array.max_colour_ticks = 2;
397         state->gate_array.ticks_increment = 1;
478398         break;
479399
480400      case 2:      /* Mode 2: 640x200, 2 colours */
481         gate_array.mode_lookup = mode2_lookup;
482         gate_array.max_colour_ticks = 1;
483         gate_array.ticks_increment = 1;
401         state->gate_array.mode_lookup = state->mode2_lookup;
402         state->gate_array.max_colour_ticks = 1;
403         state->gate_array.ticks_increment = 1;
484404         break;
485405
486406      case 3:      /* Mode 3: 160x200, 4 colours */
487         gate_array.mode_lookup = mode0_lookup;
488         gate_array.max_colour_ticks = 4;
489         gate_array.ticks_increment = 1;
407         state->gate_array.mode_lookup = state->mode0_lookup;
408         state->gate_array.max_colour_ticks = 4;
409         state->gate_array.ticks_increment = 1;
490410         break;
491411      }
492412   }
493413   else
494414   {
495      if ( aleste_mode & 0x02 )
415      if ( state->aleste_mode & 0x02 )
496416      {
497417         /* select an aleste mode */
498         switch ( gate_array.mrer & 0x03 )
418         switch ( state->gate_array.mrer & 0x03 )
499419         {
500420         case 0:      /* Aleste Mode 0 (= Amstrad CPC mode 2): 640x200, 2 colours */
501            gate_array.mode_lookup = mode2_lookup;
502            gate_array.max_colour_ticks = 1;
503            gate_array.ticks_increment = 1;
421            state->gate_array.mode_lookup = state->mode2_lookup;
422            state->gate_array.max_colour_ticks = 1;
423            state->gate_array.ticks_increment = 1;
504424            break;
505425
506426         case 1:      /* Aleste mode 1 (= Amstrad CPC mode 1): 320x200, 4 colours */
507            gate_array.mode_lookup = mode1_lookup;
508            gate_array.max_colour_ticks = 2;
509            gate_array.ticks_increment = 1;
427            state->gate_array.mode_lookup = state->mode1_lookup;
428            state->gate_array.max_colour_ticks = 2;
429            state->gate_array.ticks_increment = 1;
510430            break;
511431
512432         case 2:      /* Aleste mode 2: 4 colours */
513            gate_array.mode_lookup = mode1_lookup;
514            gate_array.max_colour_ticks = 1;
515            gate_array.ticks_increment = 2;
433            state->gate_array.mode_lookup = state->mode1_lookup;
434            state->gate_array.max_colour_ticks = 1;
435            state->gate_array.ticks_increment = 2;
516436            break;
517437
518438         case 3:      /* Aleste mode 3: 16 colours */
519            gate_array.mode_lookup = mode0_lookup;
520            gate_array.max_colour_ticks = 2;
521            gate_array.ticks_increment = 2;
439            state->gate_array.mode_lookup = state->mode0_lookup;
440            state->gate_array.max_colour_ticks = 2;
441            state->gate_array.ticks_increment = 2;
522442            break;
523443         }
524444      }
525445      else
526446      {
527447         /* select an original cpc mode */
528         switch ( gate_array.mrer & 0x03 )
448         switch ( state->gate_array.mrer & 0x03 )
529449         {
530450         case 0:      /* Mode 0: 160x200, 16 colours */
531            gate_array.mode_lookup = mode0_lookup;
532            gate_array.max_colour_ticks = 4;
533            gate_array.ticks_increment = 1;
451            state->gate_array.mode_lookup = state->mode0_lookup;
452            state->gate_array.max_colour_ticks = 4;
453            state->gate_array.ticks_increment = 1;
534454            break;
535455
536456         case 1:      /* Mode 1: 320x200, 4 colous */
537            gate_array.mode_lookup = mode1_lookup;
538            gate_array.max_colour_ticks = 2;
539            gate_array.ticks_increment = 1;
457            state->gate_array.mode_lookup = state->mode1_lookup;
458            state->gate_array.max_colour_ticks = 2;
459            state->gate_array.ticks_increment = 1;
540460            break;
541461
542462         case 2:      /* Mode 2: 640x200, 2 colours */
543            gate_array.mode_lookup = mode2_lookup;
544            gate_array.max_colour_ticks = 1;
545            gate_array.ticks_increment = 1;
463            state->gate_array.mode_lookup = state->mode2_lookup;
464            state->gate_array.max_colour_ticks = 1;
465            state->gate_array.ticks_increment = 1;
546466            break;
547467
548468         case 3:      /* Mode 3: 160x200, 4 colours */
549            gate_array.mode_lookup = mode0_lookup;
550            gate_array.max_colour_ticks = 4;
551            gate_array.ticks_increment = 1;
469            state->gate_array.mode_lookup = state->mode0_lookup;
470            state->gate_array.max_colour_ticks = 4;
471            state->gate_array.ticks_increment = 1;
552472            break;
553473         }
554474      }
r9648r9649
571491
572492static void amstrad_plus_dma_parse(running_machine *machine, int channel)
573493{
494   amstrad_state *state = machine->driver_data<amstrad_state>();
574495   unsigned short command;
575496
576   if( asic.dma_addr[channel] & 0x01)
577      asic.dma_addr[channel]++;  // align to even address
497   if( state->asic.dma_addr[channel] & 0x01)
498      state->asic.dma_addr[channel]++;  // align to even address
578499
579   if ( asic.dma_pause[channel] != 0 )
500   if ( state->asic.dma_pause[channel] != 0 )
580501   {  // do nothing, this channel is paused
581      asic.dma_prescaler[channel]--;
582      if ( asic.dma_prescaler[channel] == 0 )
502      state->asic.dma_prescaler[channel]--;
503      if ( state->asic.dma_prescaler[channel] == 0 )
583504      {
584         asic.dma_pause[channel]--;
585         asic.dma_prescaler[channel] = asic.ram[0x2c02 + (4*channel)] + 1;
505         state->asic.dma_pause[channel]--;
506         state->asic.dma_prescaler[channel] = state->asic.ram[0x2c02 + (4*channel)] + 1;
586507      }
587508      return;
588509   }
589   command = (messram_get_ptr(machine->device("messram"))[asic.dma_addr[channel]+1] << 8) + messram_get_ptr(machine->device("messram"))[asic.dma_addr[channel]];
590//  logerror("DMA #%i: address %04x: command %04x\n",channel,asic.dma_addr[channel],command);
510   command = (messram_get_ptr(machine->device("messram"))[state->asic.dma_addr[channel]+1] << 8) + messram_get_ptr(machine->device("messram"))[state->asic.dma_addr[channel]];
511//  logerror("DMA #%i: address %04x: command %04x\n",channel,state->asic.dma_addr[channel],command);
591512   switch (command & 0xf000)
592513   {
593514   case 0x0000:  // Load PSG register
r9648r9649
595516         running_device *ay8910 = machine->device("ay");
596517         ay8910_address_w(ay8910, 0, (command & 0x0f00) >> 8);
597518         ay8910_data_w(ay8910, 0, command & 0x00ff);
598         ay8910_address_w(ay8910, 0, prev_reg);
519         ay8910_address_w(ay8910, 0, state->prev_reg);
599520      }
600521      logerror("DMA %i: LOAD %i, %i\n",channel,(command & 0x0f00) >> 8, command & 0x00ff);
601522      break;
602523   case 0x1000:  // Pause for n HSYNCs (0 - 4095)
603      asic.dma_pause[channel] = (command & 0x0fff) - 1;
524      state->asic.dma_pause[channel] = (command & 0x0fff) - 1;
604525      logerror("DMA %i: PAUSE %i\n",channel,command & 0x0fff);
605526      break;
606527   case 0x2000:  // Beginning of repeat loop
607      asic.dma_repeat[channel] = asic.dma_addr[channel];
608      asic.dma_loopcount[channel] = (command & 0x0fff);
528      state->asic.dma_repeat[channel] = state->asic.dma_addr[channel];
529      state->asic.dma_loopcount[channel] = (command & 0x0fff);
609530      logerror("DMA %i: REPEAT %i\n",channel,command & 0x0fff);
610531      break;
611532   case 0x4000:  // Control functions
612533      if (command & 0x01) // Loop back to last Repeat instruction
613534      {
614         if (asic.dma_loopcount[channel] > 0)
535         if (state->asic.dma_loopcount[channel] > 0)
615536         {
616            asic.dma_addr[channel] = asic.dma_repeat[channel];
617            logerror("DMA %i: LOOP (%i left)\n",channel,asic.dma_loopcount[channel]);
618            asic.dma_loopcount[channel]--;
537            state->asic.dma_addr[channel] = state->asic.dma_repeat[channel];
538            logerror("DMA %i: LOOP (%i left)\n",channel,state->asic.dma_loopcount[channel]);
539            state->asic.dma_loopcount[channel]--;
619540         }
620541         else
621542            logerror("DMA %i: LOOP (end)\n",channel);
622543      }
623544      if (command & 0x10) // Cause interrupt
624545      {
625         amstrad_plus_irq_cause = channel * 2;
626         asic.ram[0x2c0f] |= (0x40 >> channel);
546         state->plus_irq_cause = channel * 2;
547         state->asic.ram[0x2c0f] |= (0x40 >> channel);
627548         cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE);
628549         logerror("DMA %i: INT\n",channel);
629550      }
630551      if (command & 0x20)  // Stop processing on this channel
631552      {
632         asic.dma_status &= ~(0x01 << channel);
553         state->asic.dma_status &= ~(0x01 << channel);
633554         logerror("DMA %i: STOP\n",channel);
634555      }
635556      break;
636557   default:
637      logerror("DMA: Unknown DMA command - %04x - at address &%04x\n",command,asic.dma_addr[channel]);
558      logerror("DMA: Unknown DMA command - %04x - at address &%04x\n",command,state->asic.dma_addr[channel]);
638559   }
639   asic.dma_addr[channel] += 2;  // point to next DMA instruction
560   state->asic.dma_addr[channel] += 2;  // point to next DMA instruction
640561}
641562
642563
643564static void amstrad_plus_handle_dma(running_machine *machine)
644565{
645   if ( asic.dma_status & 0x01 )  // DMA channel 0
566   amstrad_state *state = machine->driver_data<amstrad_state>();
567   if ( state->asic.dma_status & 0x01 )  // DMA channel 0
646568      amstrad_plus_dma_parse( machine, 0 );
647569
648   if ( asic.dma_status & 0x02 )  // DMA channel 1
570   if ( state->asic.dma_status & 0x02 )  // DMA channel 1
649571      amstrad_plus_dma_parse( machine, 1 );
650572
651   if ( asic.dma_status & 0x04 )  // DMA channel 2
573   if ( state->asic.dma_status & 0x04 )  // DMA channel 2
652574      amstrad_plus_dma_parse( machine, 2 );
653575}
654576
r9648r9649
656578/* Set the new colour from the GateArray */
657579static void amstrad_vh_update_colour(running_machine *machine, int PenIndex, UINT16 hw_colour_index)
658580{
659   if ( amstrad_system_type == SYSTEM_PLUS || amstrad_system_type == SYSTEM_GX4000 )
581   amstrad_state *state = machine->driver_data<amstrad_state>();
582   if ( state->system_type == SYSTEM_PLUS || state->system_type == SYSTEM_GX4000 )
660583   {
661584      int val;
662585
r9648r9649
665588      /* CPC+/GX4000 - normal palette changes through the Gate Array also makes the corresponding change in the ASIC palette */
666589      val = (amstrad_palette[hw_colour_index] & 0xf00000) >> 16; /* red */
667590      val |= (amstrad_palette[hw_colour_index] & 0x0000f0) >> 4; /* blue */
668      asic.ram[0x2400+PenIndex*2] = val;
591      state->asic.ram[0x2400+PenIndex*2] = val;
669592      val = (amstrad_palette[hw_colour_index] & 0x00f000) >> 12; /* green */
670      asic.ram[0x2401+PenIndex*2] = val;
593      state->asic.ram[0x2401+PenIndex*2] = val;
671594   }
672595   else
673596   {
674597      amstrad_update_video( machine );
675598   }
676   amstrad_GateArray_render_colours[PenIndex] = hw_colour_index;
599   state->GateArray_render_colours[PenIndex] = hw_colour_index;
677600}
678601
679602
680603static void aleste_vh_update_colour(running_machine *machine, int PenIndex, UINT16 hw_colour_index)
681604{
605   amstrad_state *state = machine->driver_data<amstrad_state>();
682606   amstrad_update_video( machine );
683   amstrad_GateArray_render_colours[PenIndex] = hw_colour_index+32;
607   state->GateArray_render_colours[PenIndex] = hw_colour_index+32;
684608}
685609
686610
687611INLINE void amstrad_gate_array_get_video_data( running_machine *machine )
688612{
689   if ( aleste_mode & 0x02 )
690      gate_array.address = ( ( gate_array.ma & 0x2000 ) << 2 ) | ( ( gate_array.ra & 0x06 ) << 11 ) | ( ( gate_array.ra & 0x01 ) << 14 ) | ( ( gate_array.ma & 0x7ff ) << 1 );
613   amstrad_state *state = machine->driver_data<amstrad_state>();
614   if ( state->aleste_mode & 0x02 )
615      state->gate_array.address = ( ( state->gate_array.ma & 0x2000 ) << 2 ) | ( ( state->gate_array.ra & 0x06 ) << 11 ) | ( ( state->gate_array.ra & 0x01 ) << 14 ) | ( ( state->gate_array.ma & 0x7ff ) << 1 );
691616   else
692      gate_array.address = ( ( gate_array.ma & 0x3000 ) << 2 ) | ( ( gate_array.ra & 0x07 ) << 11 ) | ( ( gate_array.ma & 0x3ff ) << 1 );
693   gate_array.data = messram_get_ptr(machine->device("messram"))[ gate_array.address ];
694   gate_array.colour = amstrad_GateArray_render_colours[ gate_array.mode_lookup[gate_array.data] ];
695   gate_array.colour_ticks = gate_array.max_colour_ticks;
696   gate_array.ticks = 0;
617      state->gate_array.address = ( ( state->gate_array.ma & 0x3000 ) << 2 ) | ( ( state->gate_array.ra & 0x07 ) << 11 ) | ( ( state->gate_array.ma & 0x3ff ) << 1 );
618   state->gate_array.data = messram_get_ptr(machine->device("messram"))[ state->gate_array.address ];
619   state->gate_array.colour = state->GateArray_render_colours[ state->gate_array.mode_lookup[state->gate_array.data] ];
620   state->gate_array.colour_ticks = state->gate_array.max_colour_ticks;
621   state->gate_array.ticks = 0;
697622}
698623
699624
700625INLINE void amstrad_update_video( running_machine *machine )
701626{
627   amstrad_state *state = machine->driver_data<amstrad_state>();
702628   attotime now = timer_get_time(machine);
703629
704   if ( gate_array.draw_p )
630   if ( state->gate_array.draw_p )
705631   {
706      UINT32 cycles_passed = attotime_to_ticks( attotime_sub( now, gate_array.last_draw_time ), XTAL_16MHz );
632      UINT32 cycles_passed = attotime_to_ticks( attotime_sub( now, state->gate_array.last_draw_time ), XTAL_16MHz );
707633
708634      while( cycles_passed )
709635      {
710         if ( ! gate_array.de || ( ( aleste_mode & 0x02 ) && ! ( aleste_mode & 0x08 ) ) )
636         if ( ! state->gate_array.de || ( ( state->aleste_mode & 0x02 ) && ! ( state->aleste_mode & 0x08 ) ) )
711637         {
712            *gate_array.draw_p = amstrad_GateArray_render_colours[ 16 ];
638            *state->gate_array.draw_p = state->GateArray_render_colours[ 16 ];
713639         }
714640         else
715641         {
716            *gate_array.draw_p = gate_array.colour;
717            gate_array.colour_ticks--;
718            if ( ! gate_array.colour_ticks )
642            *state->gate_array.draw_p = state->gate_array.colour;
643            state->gate_array.colour_ticks--;
644            if ( ! state->gate_array.colour_ticks )
719645            {
720               gate_array.data <<= 1;
721               gate_array.colour = amstrad_GateArray_render_colours[ gate_array.mode_lookup[gate_array.data] ];
722               gate_array.colour_ticks = gate_array.max_colour_ticks;
646               state->gate_array.data <<= 1;
647               state->gate_array.colour = state->GateArray_render_colours[ state->gate_array.mode_lookup[state->gate_array.data] ];
648               state->gate_array.colour_ticks = state->gate_array.max_colour_ticks;
723649            }
724            gate_array.ticks += gate_array.ticks_increment;
725            switch( gate_array.ticks)
650            state->gate_array.ticks += state->gate_array.ticks_increment;
651            switch( state->gate_array.ticks)
726652            {
727653            case 8:
728               gate_array.data = messram_get_ptr(machine->device("messram"))[ gate_array.address + 1 ];
729               gate_array.colour = amstrad_GateArray_render_colours[ gate_array.mode_lookup[gate_array.data] ];
654               state->gate_array.data = messram_get_ptr(machine->device("messram"))[ state->gate_array.address + 1 ];
655               state->gate_array.colour = state->GateArray_render_colours[ state->gate_array.mode_lookup[state->gate_array.data] ];
730656               break;
731657            case 16:
732               gate_array.ma += 1;                  /* If we were synced with the 6845 mc6845_get_ma should return this value */
658               state->gate_array.ma += 1;                  /* If we were synced with the 6845 mc6845_get_ma should return this value */
733659               amstrad_gate_array_get_video_data( machine );
734660               break;
735661            }
736662         }
737         gate_array.draw_p++;
663         state->gate_array.draw_p++;
738664         cycles_passed--;
739         gate_array.line_ticks++;
740         if ( gate_array.line_ticks > gate_array.bitmap->width )
665         state->gate_array.line_ticks++;
666         if ( state->gate_array.line_ticks > state->gate_array.bitmap->width )
741667         {
742            gate_array.draw_p = NULL;
668            state->gate_array.draw_p = NULL;
743669            cycles_passed = 0;
744670         }
745671      }
746672   }
747673
748   gate_array.last_draw_time = now;
674   state->gate_array.last_draw_time = now;
749675}
750676
751677
752678INLINE void amstrad_plus_gate_array_get_video_data( running_machine *machine )
753679{
680   amstrad_state *state = machine->driver_data<amstrad_state>();
754681   UINT16 caddr;
755   UINT16 ma = ( gate_array.ma - asic.split_ma_started ) + asic.split_ma_base;
756   UINT16 ra = gate_array.ra + ( ( asic.ram[0x2804] >> 4 ) & 0x07 );
682   UINT16 ma = ( state->gate_array.ma - state->asic.split_ma_started ) + state->asic.split_ma_base;
683   UINT16 ra = state->gate_array.ra + ( ( state->asic.ram[0x2804] >> 4 ) & 0x07 );
757684
758685   if ( ra > 7 )
759686   {
760      ma += asic.horiz_disp;
687      ma += state->asic.horiz_disp;
761688   }
762   gate_array.address = ( ( ma & 0x3000 ) << 2 ) | ( ( gate_array.ra & 0x07 ) << 11 ) | ( ( ma & 0x3ff ) << 1 );
763   gate_array.data = messram_get_ptr(machine->device("messram"))[ gate_array.address ];
764   caddr = 0x2400 + gate_array.mode_lookup[gate_array.data] * 2;
765   gate_array.colour = asic.ram[caddr] + ( asic.ram[caddr+1] << 8 );
766   gate_array.colour_ticks = gate_array.max_colour_ticks;
767   gate_array.ticks = 0;
689   state->gate_array.address = ( ( ma & 0x3000 ) << 2 ) | ( ( state->gate_array.ra & 0x07 ) << 11 ) | ( ( ma & 0x3ff ) << 1 );
690   state->gate_array.data = messram_get_ptr(machine->device("messram"))[ state->gate_array.address ];
691   caddr = 0x2400 + state->gate_array.mode_lookup[state->gate_array.data] * 2;
692   state->gate_array.colour = state->asic.ram[caddr] + ( state->asic.ram[caddr+1] << 8 );
693   state->gate_array.colour_ticks = state->gate_array.max_colour_ticks;
694   state->gate_array.ticks = 0;
768695}
769696
770697
771698INLINE void amstrad_plus_update_video( running_machine *machine )
772699{
700   amstrad_state *state = machine->driver_data<amstrad_state>();
773701   attotime now = timer_get_time(machine);
774702
775   if ( gate_array.draw_p )
703   if ( state->gate_array.draw_p )
776704   {
777      UINT32 cycles_passed = attotime_to_ticks( attotime_sub( now, gate_array.last_draw_time ), XTAL_16MHz );
705      UINT32 cycles_passed = attotime_to_ticks( attotime_sub( now, state->gate_array.last_draw_time ), XTAL_16MHz );
778706
779707      while( cycles_passed )
780708      {
781         if ( ! gate_array.de )
709         if ( ! state->gate_array.de )
782710         {
783            *gate_array.draw_p = asic.ram[0x2420] + ( asic.ram[0x2421] << 8 );
711            *state->gate_array.draw_p = state->asic.ram[0x2420] + ( state->asic.ram[0x2421] << 8 );
784712         }
785713         else
786714         {
787            *gate_array.draw_p = gate_array.colour;
715            *state->gate_array.draw_p = state->gate_array.colour;
788716
789            if ( asic.hscroll )
717            if ( state->asic.hscroll )
790718            {
791               asic.hscroll--;
792               if ( asic.hscroll == 0 )
719               state->asic.hscroll--;
720               if ( state->asic.hscroll == 0 )
793721                  amstrad_plus_gate_array_get_video_data( machine );
794722            }
795723            else
796724            {
797               gate_array.colour_ticks--;
798               if ( ! gate_array.colour_ticks )
725               state->gate_array.colour_ticks--;
726               if ( ! state->gate_array.colour_ticks )
799727               {
800728                  UINT16 caddr;
801729
802                  gate_array.data <<= 1;
803                  caddr = 0x2400 + gate_array.mode_lookup[gate_array.data] * 2;
804                  gate_array.colour = asic.ram[caddr] + ( asic.ram[caddr+1] << 8 );
805                  gate_array.colour_ticks = gate_array.max_colour_ticks;
730                  state->gate_array.data <<= 1;
731                  caddr = 0x2400 + state->gate_array.mode_lookup[state->gate_array.data] * 2;
732                  state->gate_array.colour = state->asic.ram[caddr] + ( state->asic.ram[caddr+1] << 8 );
733                  state->gate_array.colour_ticks = state->gate_array.max_colour_ticks;
806734               }
807               gate_array.ticks += gate_array.ticks_increment;
808               switch( gate_array.ticks)
735               state->gate_array.ticks += state->gate_array.ticks_increment;
736               switch( state->gate_array.ticks)
809737               {
810738               case 8:
811739                  {
812740                     UINT16 caddr;
813741
814                     gate_array.data = messram_get_ptr(machine->device("messram"))[ gate_array.address + 1 ];
815                     caddr = 0x2400 + gate_array.mode_lookup[gate_array.data] * 2;
816                     gate_array.colour = asic.ram[caddr] + ( asic.ram[caddr+1] << 8 );
742                     state->gate_array.data = messram_get_ptr(machine->device("messram"))[ state->gate_array.address + 1 ];
743                     caddr = 0x2400 + state->gate_array.mode_lookup[state->gate_array.data] * 2;
744                     state->gate_array.colour = state->asic.ram[caddr] + ( state->asic.ram[caddr+1] << 8 );
817745                  }
818746                  break;
819747               case 16:
820                  gate_array.ma += 1;                  /* If we were synced with the 6845 mc6845_get_ma should return this value */
748                  state->gate_array.ma += 1;                  /* If we were synced with the 6845 mc6845_get_ma should return this value */
821749                  amstrad_plus_gate_array_get_video_data( machine );
822750                  break;
823751               }
824752            }
825753         }
826         gate_array.draw_p++;
754         state->gate_array.draw_p++;
827755         cycles_passed--;
828         gate_array.line_ticks++;
829         if ( gate_array.line_ticks > gate_array.bitmap->width )
756         state->gate_array.line_ticks++;
757         if ( state->gate_array.line_ticks > state->gate_array.bitmap->width )
830758         {
831            gate_array.draw_p = NULL;
759            state->gate_array.draw_p = NULL;
832760            cycles_passed = 0;
833761         }
834762      }
835763   }
836764
837   gate_array.last_draw_time = now;
765   state->gate_array.last_draw_time = now;
838766}
839767
840768
841769INLINE void amstrad_plus_update_video_sprites( running_machine *machine )
842770{
843   UINT16   *p = BITMAP_ADDR16( gate_array.bitmap, gate_array.y, asic.h_start );
771   amstrad_state *state = machine->driver_data<amstrad_state>();
772   UINT16   *p = BITMAP_ADDR16( state->gate_array.bitmap, state->gate_array.y, state->asic.h_start );
844773   int i;
845774
846   if ( gate_array.y < 0 )
775   if ( state->gate_array.y < 0 )
847776      return;
848777
849778   for ( i = 15 * 8; i >= 0; i -= 8 )
850779   {
851      UINT8   xmag = ( asic.ram[ 0x2000 + i + 4 ] >> 2 ) & 0x03;
852      UINT8   ymag = asic.ram[ 0x2000 + i + 4 ] & 0x03;
780      UINT8   xmag = ( state->asic.ram[ 0x2000 + i + 4 ] >> 2 ) & 0x03;
781      UINT8   ymag = state->asic.ram[ 0x2000 + i + 4 ] & 0x03;
853782
854783      /* Check if sprite is enabled */
855784      if ( xmag && ymag )
856785      {
857         INT16   spr_x = asic.ram[ 0x2000 + i ] + ( asic.ram[ 0x2001 + i ] << 8 );
858         INT16   spr_y = asic.ram[ 0x2002 + i ] + ( asic.ram[ 0x2003 + i ] << 8 );
786         INT16   spr_x = state->asic.ram[ 0x2000 + i ] + ( state->asic.ram[ 0x2001 + i ] << 8 );
787         INT16   spr_y = state->asic.ram[ 0x2002 + i ] + ( state->asic.ram[ 0x2003 + i ] << 8 );
859788
860789         xmag -= 1;
861790         ymag -= 1;
862791
863792         /* Check if sprite would appear on this scanline */
864         if ( spr_y <= asic.vpos && asic.vpos < spr_y + ( 16 << ymag ) && spr_x < ( asic.h_end - asic.h_start ) && spr_x + ( 16 << xmag ) > 0 )
793         if ( spr_y <= state->asic.vpos && state->asic.vpos < spr_y + ( 16 << ymag ) && spr_x < ( state->asic.h_end - state->asic.h_start ) && spr_x + ( 16 << xmag ) > 0 )
865794         {
866            UINT16   spr_addr = i * 32 + ( ( ( asic.vpos - spr_y ) >> ymag ) * 16 );
795            UINT16   spr_addr = i * 32 + ( ( ( state->asic.vpos - spr_y ) >> ymag ) * 16 );
867796            int      j, k;
868797
869798            for ( j = 0; j < 16; j++ )
r9648r9649
872801               {
873802                  INT16 x = spr_x + ( j << xmag ) + k;
874803
875                  if ( x >= 0 && x < ( asic.h_end - asic.h_start ) )
804                  if ( x >= 0 && x < ( state->asic.h_end - state->asic.h_start ) )
876805                  {
877                     UINT8   spr_col = ( asic.ram[ spr_addr + j ] & 0x0f ) * 2;
806                     UINT8   spr_col = ( state->asic.ram[ spr_addr + j ] & 0x0f ) * 2;
878807
879808                     if ( spr_col )
880                        p[x] = asic.ram[ 0x2420 + spr_col ] + ( asic.ram[ 0x2421 + spr_col ] << 8 );
809                        p[x] = state->asic.ram[ 0x2420 + spr_col ] + ( state->asic.ram[ 0x2421 + spr_col ] << 8 );
881810                  }
882811               }
883812            }
r9648r9649
889818
890819static WRITE_LINE_DEVICE_HANDLER( amstrad_hsync_changed )
891820{
821   amstrad_state *drvstate = device->machine->driver_data<amstrad_state>();
892822   amstrad_update_video( device->machine );
893823
894824   /* The gate array reacts to de-assertion of the hsycnc 6845 line */
895   if ( gate_array.hsync && !state )
825   if ( drvstate->gate_array.hsync && !state )
896826   {
897      gate_array.hsync_counter++;
827      drvstate->gate_array.hsync_counter++;
898828      /* Advance to next drawing line */
899      gate_array.y++;
900      gate_array.line_ticks = 0;
901      if ( gate_array.y >= 0 && gate_array.y < gate_array.bitmap->height )
829      drvstate->gate_array.y++;
830      drvstate->gate_array.line_ticks = 0;
831      if ( drvstate->gate_array.y >= 0 && drvstate->gate_array.y < drvstate->gate_array.bitmap->height )
902832      {
903         gate_array.draw_p = BITMAP_ADDR16( gate_array.bitmap, gate_array.y, 0 );
833         drvstate->gate_array.draw_p = BITMAP_ADDR16( drvstate->gate_array.bitmap, drvstate->gate_array.y, 0 );
904834      }
905835      else
906836      {
907         gate_array.draw_p = NULL;
837         drvstate->gate_array.draw_p = NULL;
908838      }
909839
910      if ( gate_array.hsync_after_vsync_counter != 0 )  // counters still operate regardless of PRI state
840      if ( drvstate->gate_array.hsync_after_vsync_counter != 0 )  // counters still operate regardless of PRI state
911841      {
912         gate_array.hsync_after_vsync_counter--;
842         drvstate->gate_array.hsync_after_vsync_counter--;
913843
914         if (gate_array.hsync_after_vsync_counter == 0)
844         if (drvstate->gate_array.hsync_after_vsync_counter == 0)
915845         {
916            if (gate_array.hsync_counter >= 32)
846            if (drvstate->gate_array.hsync_counter >= 32)
917847            {
918848               cputag_set_input_line(device->machine, "maincpu", 0, ASSERT_LINE);
919849            }
920            gate_array.hsync_counter = 0;
850            drvstate->gate_array.hsync_counter = 0;
921851         }
922852      }
923853
924      if ( gate_array.hsync_counter >= 52 )
854      if ( drvstate->gate_array.hsync_counter >= 52 )
925855      {
926         gate_array.hsync_counter = 0;
856         drvstate->gate_array.hsync_counter = 0;
927857         cputag_set_input_line(device->machine, "maincpu", 0, ASSERT_LINE);
928858      }
929859   }
930   gate_array.hsync = state ? 1 : 0;
860   drvstate->gate_array.hsync = state ? 1 : 0;
931861}
932862
933863
934864static WRITE_LINE_DEVICE_HANDLER( amstrad_plus_hsync_changed )
935865{
866   amstrad_state *drvstate = device->machine->driver_data<amstrad_state>();
936867   amstrad_plus_update_video( device->machine );
937868
938   if ( gate_array.hsync && !state )
869   if ( drvstate->gate_array.hsync && !state )
939870   {
940      gate_array.hsync_counter++;
871      drvstate->gate_array.hsync_counter++;
941872      /* Advance to next drawing line */
942      gate_array.y++;
943      gate_array.line_ticks = 0;
944      if ( gate_array.y >= 0 && gate_array.y < gate_array.bitmap->height )
873      drvstate->gate_array.y++;
874      drvstate->gate_array.line_ticks = 0;
875      if ( drvstate->gate_array.y >= 0 && drvstate->gate_array.y < drvstate->gate_array.bitmap->height )
945876      {
946         gate_array.draw_p = BITMAP_ADDR16( gate_array.bitmap, gate_array.y, 0 );
877         drvstate->gate_array.draw_p = BITMAP_ADDR16( drvstate->gate_array.bitmap, drvstate->gate_array.y, 0 );
947878      }
948879      else
949880      {
950         gate_array.draw_p = NULL;
881         drvstate->gate_array.draw_p = NULL;
951882      }
952883
953      if ( gate_array.hsync_after_vsync_counter != 0 )  // counters still operate regardless of PRI state
884      if ( drvstate->gate_array.hsync_after_vsync_counter != 0 )  // counters still operate regardless of PRI state
954885      {
955         gate_array.hsync_after_vsync_counter--;
886         drvstate->gate_array.hsync_after_vsync_counter--;
956887
957         if (gate_array.hsync_after_vsync_counter == 0)
888         if (drvstate->gate_array.hsync_after_vsync_counter == 0)
958889         {
959            if (gate_array.hsync_counter >= 32)
890            if (drvstate->gate_array.hsync_counter >= 32)
960891            {
961               if( asic.pri == 0 || asic.enabled == 0)
892               if( drvstate->asic.pri == 0 || drvstate->asic.enabled == 0)
962893               {
963894                  cputag_set_input_line(device->machine, "maincpu", 0, ASSERT_LINE);
964895               }
965896            }
966            gate_array.hsync_counter = 0;
897            drvstate->gate_array.hsync_counter = 0;
967898         }
968899      }
969900
970      if ( gate_array.hsync_counter >= 52 )
901      if ( drvstate->gate_array.hsync_counter >= 52 )
971902      {
972         gate_array.hsync_counter = 0;
973         if ( asic.pri == 0 || asic.enabled == 0 )
903         drvstate->gate_array.hsync_counter = 0;
904         if ( drvstate->asic.pri == 0 || drvstate->asic.enabled == 0 )
974905         {
975906            cputag_set_input_line(device->machine, "maincpu", 0, ASSERT_LINE);
976907         }
977908      }
978909
979      if ( asic.enabled )
910      if ( drvstate->asic.enabled )
980911      {
981912         // CPC+/GX4000 Programmable Raster Interrupt (disabled if &6800 in ASIC RAM is 0)
982         if ( asic.pri != 0 )
913         if ( drvstate->asic.pri != 0 )
983914         {
984            if ( asic.pri == asic.vpos - 1 )
915            if ( drvstate->asic.pri == drvstate->asic.vpos - 1 )
985916            {
986               logerror("PRI: triggered, scanline %d\n",asic.pri);
917               logerror("PRI: triggered, scanline %d\n",drvstate->asic.pri);
987918               cputag_set_input_line(device->machine, "maincpu", 0, ASSERT_LINE);
988               amstrad_plus_irq_cause = 0x06;  // raster interrupt vector
989               gate_array.hsync_counter &= ~0x20;  // ASIC PRI resets the MSB of the raster counter
919               drvstate->plus_irq_cause = 0x06;  // raster interrupt vector
920               drvstate->gate_array.hsync_counter &= ~0x20;  // ASIC PRI resets the MSB of the raster counter
990921            }
991922         }
992923         // CPC+/GX4000 Split screen registers  (disabled if &6801 in ASIC RAM is 0)
993         if(asic.ram[0x2801] != 0)
924         if(drvstate->asic.ram[0x2801] != 0)
994925         {
995            if ( asic.ram[0x2801] == asic.vpos - 1 )   // split occurs here (hopefully)
926            if ( drvstate->asic.ram[0x2801] == drvstate->asic.vpos - 1 )   // split occurs here (hopefully)
996927            {
997               logerror("SSCR: Split screen occured at scanline %d\n",asic.ram[0x2801]);
928               logerror("SSCR: Split screen occured at scanline %d\n",drvstate->asic.ram[0x2801]);
998929            }
999930         }
1000931         // CPC+/GX4000 DMA channels
1001932         amstrad_plus_handle_dma(device->machine);  // a DMA command is handled at the leading edge of HSYNC (every 64us)
1002         if(asic.de_start != 0)
1003            asic.vpos++;
933         if(drvstate->asic.de_start != 0)
934            drvstate->asic.vpos++;
1004935      }
1005936   }
1006   gate_array.hsync = state ? 1 : 0;
937   drvstate->gate_array.hsync = state ? 1 : 0;
1007938}
1008939
1009940
1010941static WRITE_LINE_DEVICE_HANDLER( amstrad_vsync_changed )
1011942{
943   amstrad_state *drvstate = device->machine->driver_data<amstrad_state>();
1012944   amstrad_update_video( device->machine );
1013945
1014   if ( ! gate_array.vsync && state )
946   if ( ! drvstate->gate_array.vsync && state )
1015947   {
1016948      /* Reset the amstrad_CRTC_HS_After_VS_Counter */
1017      gate_array.hsync_after_vsync_counter = 3;
949      drvstate->gate_array.hsync_after_vsync_counter = 3;
1018950
1019951      /* Start of new frame */
1020      gate_array.y = -1;
1021      asic.vpos = 1;
1022      asic.de_start = 0;
952      drvstate->gate_array.y = -1;
953      drvstate->asic.vpos = 1;
954      drvstate->asic.de_start = 0;
1023955   }
1024956
1025   gate_array.vsync = state ? 1 : 0;
957   drvstate->gate_array.vsync = state ? 1 : 0;
1026958
1027959   /* Schedule a write to PC2 */
1028960   timer_set( device->machine, attotime_zero, NULL, 0, amstrad_pc2_low );
r9648r9649
1031963
1032964static WRITE_LINE_DEVICE_HANDLER( amstrad_plus_vsync_changed )
1033965{
966   amstrad_state *drvstate = device->machine->driver_data<amstrad_state>();
1034967   amstrad_plus_update_video( device->machine );
1035968
1036   if ( ! gate_array.vsync && state )
969   if ( ! drvstate->gate_array.vsync && state )
1037970   {
1038971      /* Reset the amstrad_CRTC_HS_After_VS_Counter */
1039      gate_array.hsync_after_vsync_counter = 3;
972      drvstate->gate_array.hsync_after_vsync_counter = 3;
1040973
1041974      /* Start of new frame */
1042      gate_array.y = -1;
1043      asic.vpos = 1;
1044      asic.de_start = 0;
975      drvstate->gate_array.y = -1;
976      drvstate->asic.vpos = 1;
977      drvstate->asic.de_start = 0;
1045978   }
1046979
1047   gate_array.vsync = state ? 1 : 0;
980   drvstate->gate_array.vsync = state ? 1 : 0;
1048981
1049982   /* Schedule a write to PC2 */
1050983   timer_set( device->machine, attotime_zero, NULL, 0, amstrad_pc2_low );
r9648r9649
1053986
1054987static WRITE_LINE_DEVICE_HANDLER( amstrad_de_changed )
1055988{
989   amstrad_state *drvstate = device->machine->driver_data<amstrad_state>();
1056990   amstrad_update_video( device->machine );
1057991
1058   if ( ! gate_array.de && state )
992   if ( ! drvstate->gate_array.de && state )
1059993   {
1060994      /* DE became active, store the starting MA and RA signals */
1061995      running_device *mc6845 = device->machine->device("mc6845" );
1062996
1063      gate_array.ma = mc6845_get_ma( mc6845 );
1064      gate_array.ra = mc6845_get_ra( mc6845 );
1065logerror("y = %d; ma = %02x; ra = %02x, address = %04x\n", gate_array.y, gate_array.ma, gate_array.ra, ( ( gate_array.ma & 0x3000 ) << 2 ) | ( ( gate_array.ra & 0x07 ) << 11 ) | ( ( gate_array.ma & 0x3ff ) << 1 ) );
997      drvstate->gate_array.ma = mc6845_get_ma( mc6845 );
998      drvstate->gate_array.ra = mc6845_get_ra( mc6845 );
999logerror("y = %d; ma = %02x; ra = %02x, address = %04x\n", drvstate->gate_array.y, drvstate->gate_array.ma, drvstate->gate_array.ra, ( ( drvstate->gate_array.ma & 0x3000 ) << 2 ) | ( ( drvstate->gate_array.ra & 0x07 ) << 11 ) | ( ( drvstate->gate_array.ma & 0x3ff ) << 1 ) );
10661000      amstrad_gate_array_get_video_data( device->machine );
1067      asic.de_start = 1;
1001      drvstate->asic.de_start = 1;
10681002   }
10691003
1070   gate_array.de = state ? 1 : 0;
1004   drvstate->gate_array.de = state ? 1 : 0;
10711005}
10721006
10731007
10741008static WRITE_LINE_DEVICE_HANDLER( amstrad_plus_de_changed )
10751009{
1010   amstrad_state *drvstate = device->machine->driver_data<amstrad_state>();
10761011   amstrad_plus_update_video( device->machine );
10771012
1078   if ( ! gate_array.de && state )
1013   if ( ! drvstate->gate_array.de && state )
10791014   {
10801015      /* DE became active, store the starting MA and RA signals */
10811016      running_device *mc6845 = device->machine->device("mc6845" );
10821017
1083      gate_array.ma = mc6845_get_ma( mc6845 );
1084      gate_array.ra = mc6845_get_ra( mc6845 );
1085      asic.h_start = gate_array.line_ticks;
1086      asic.de_start = 1;
1018      drvstate->gate_array.ma = mc6845_get_ma( mc6845 );
1019      drvstate->gate_array.ra = mc6845_get_ra( mc6845 );
1020      drvstate->asic.h_start = drvstate->gate_array.line_ticks;
1021      drvstate->asic.de_start = 1;
10871022
10881023      /* Start of screen */
1089      if ( asic.vpos == 1 )
1024      if ( drvstate->asic.vpos == 1 )
10901025      {
1091         asic.split_ma_base = 0x0000;
1092         asic.split_ma_started = 0x0000;
1026         drvstate->asic.split_ma_base = 0x0000;
1027         drvstate->asic.split_ma_started = 0x0000;
10931028      }
10941029      /* Start of split screen section */
1095      else if ( asic.enabled && asic.ram[0x2801] != 0 && asic.ram[0x2801] == asic.vpos - 1 )
1030      else if ( drvstate->asic.enabled && drvstate->asic.ram[0x2801] != 0 && drvstate->asic.ram[0x2801] == drvstate->asic.vpos - 1 )
10961031      {
1097         asic.split_ma_started = gate_array.ma;
1098         asic.split_ma_base = ( asic.ram[0x2802] << 8 ) | asic.ram[0x2803];
1032         drvstate->asic.split_ma_started = drvstate->gate_array.ma;
1033         drvstate->asic.split_ma_base = ( drvstate->asic.ram[0x2802] << 8 ) | drvstate->asic.ram[0x2803];
10991034      }
11001035
1101      gate_array.colour = asic.ram[0x2420] + ( asic.ram[0x2421] << 8 );
1102      asic.hscroll = asic.ram[0x2804] & 0x0f;
1036      drvstate->gate_array.colour = drvstate->asic.ram[0x2420] + ( drvstate->asic.ram[0x2421] << 8 );
1037      drvstate->asic.hscroll = drvstate->asic.ram[0x2804] & 0x0f;
11031038
1104      if ( asic.hscroll == 0 )
1039      if ( drvstate->asic.hscroll == 0 )
11051040         amstrad_plus_gate_array_get_video_data( device->machine );
11061041   }
11071042
1108   if ( gate_array.de && ! state )
1043   if ( drvstate->gate_array.de && ! state )
11091044   {
1110      asic.h_end = gate_array.line_ticks;
1045      drvstate->asic.h_end = drvstate->gate_array.line_ticks;
11111046      amstrad_plus_update_video_sprites( device->machine );
11121047   }
11131048
1114   gate_array.de = state ? 1 : 0;
1049   drvstate->gate_array.de = state ? 1 : 0;
11151050}
11161051
11171052
11181053VIDEO_START( amstrad )
11191054{
1055   amstrad_state *state = machine->driver_data<amstrad_state>();
11201056   screen_device *screen = downcast<screen_device *>(machine->device("screen"));
11211057
1122   amstrad_init_lookups();
1058   amstrad_init_lookups(state);
11231059
1124   gate_array.bitmap = auto_bitmap_alloc( machine, screen->width(), screen->height(), screen->format() );
1125   gate_array.hsync_after_vsync_counter = 3;
1060   state->gate_array.bitmap = auto_bitmap_alloc( machine, screen->width(), screen->height(), screen->format() );
1061   state->gate_array.hsync_after_vsync_counter = 3;
11261062}
11271063
11281064
11291065VIDEO_UPDATE( amstrad )
11301066{
1131   copybitmap( bitmap, gate_array.bitmap, 0, 0, 0, 0, cliprect );
1067   amstrad_state *state = screen->machine->driver_data<amstrad_state>();
1068   copybitmap( bitmap, state->gate_array.bitmap, 0, 0, 0, 0, cliprect );
11321069   return 0;
11331070}
11341071
r9648r9649
11671104    Multiface emulation
11681105  ****************************************************************************************/
11691106
1170static unsigned char *multiface_ram;
1171static unsigned long multiface_flags;
11721107
11731108/* stop button has been pressed */
11741109#define MULTIFACE_STOP_BUTTON_PRESSED   0x0001
r9648r9649
11921127/* used to setup computer if a snapshot was specified */
11931128DIRECT_UPDATE_HANDLER( amstrad_multiface_directoverride )
11941129{
1130   amstrad_state *state = machine->driver_data<amstrad_state>();
11951131      int pc;
11961132
11971133      pc = cpu_get_pc(machine->device("maincpu"));
r9648r9649
12131149      if (pc==0x0164)
12141150      {
12151151         /* first call? */
1216         multiface_flags |= MULTIFACE_VISIBLE;
1152         state->multiface_flags |= MULTIFACE_VISIBLE;
12171153      }
12181154      else if (pc==0x0c98)
12191155      {
12201156        /* second call */
12211157
12221158        /* no longer visible */
1223        multiface_flags &= ~(MULTIFACE_VISIBLE|MULTIFACE_STOP_BUTTON_PRESSED);
1159        state->multiface_flags &= ~(MULTIFACE_VISIBLE|MULTIFACE_STOP_BUTTON_PRESSED);
12241160
12251161       /* clear op base override */
12261162        cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(amstrad_default, *machine));
r9648r9649
12311167
12321168static void multiface_init(running_machine *machine)
12331169{
1170   amstrad_state *state = machine->driver_data<amstrad_state>();
12341171   /* after a reset the multiface is visible */
1235   multiface_flags = MULTIFACE_VISIBLE;
1172   state->multiface_flags = MULTIFACE_VISIBLE;
12361173
12371174   /* allocate ram */
1238   multiface_ram = auto_alloc_array(machine, UINT8, 8192);
1175   state->multiface_ram = auto_alloc_array(machine, UINT8, 8192);
12391176}
12401177
12411178/* call when a system reset is done */
1242static void multiface_reset(void)
1179static void multiface_reset(amstrad_state *state)
12431180{
12441181      /* stop button not pressed and ram/rom disabled */
1245      multiface_flags &= ~(MULTIFACE_STOP_BUTTON_PRESSED |
1182      state->multiface_flags &= ~(MULTIFACE_STOP_BUTTON_PRESSED |
12461183                  MULTIFACE_RAM_ROM_ENABLED);
12471184      /* as on the real hardware the multiface is visible after a reset! */
1248      multiface_flags |= MULTIFACE_VISIBLE;
1185      state->multiface_flags |= MULTIFACE_VISIBLE;
12491186}
12501187
12511188static int multiface_hardware_enabled(running_machine *machine)
12521189{
1253      if (multiface_ram!=NULL)
1190   amstrad_state *state = machine->driver_data<amstrad_state>();
1191      if (state->multiface_ram!=NULL)
12541192      {
12551193            if ((input_port_read(machine, "multiface") & 0x01)!=0)
12561194            {
r9648r9649
12641202
12651203static void multiface_rethink_memory(running_machine *machine)
12661204{
1205   amstrad_state *state = machine->driver_data<amstrad_state>();
12671206   unsigned char *multiface_rom;
12681207
12691208   /* multiface hardware enabled? */
r9648r9649
12731212   multiface_rom = &memory_region(machine, "maincpu")[0x01C000];
12741213
12751214   if (
1276      ((multiface_flags & MULTIFACE_RAM_ROM_ENABLED)!=0) &&
1277      ((gate_array.mrer & 0x04) == 0)
1215      ((state->multiface_flags & MULTIFACE_RAM_ROM_ENABLED)!=0) &&
1216      ((state->gate_array.mrer & 0x04) == 0)
12781217      )
12791218   {
12801219
12811220      /* set bank addressess */
12821221      memory_set_bankptr(machine,"bank1", multiface_rom);
1283      memory_set_bankptr(machine,"bank2", multiface_ram);
1222      memory_set_bankptr(machine,"bank2", state->multiface_ram);
12841223      memory_set_bankptr(machine,"bank9", multiface_rom);
1285      memory_set_bankptr(machine,"bank10", multiface_ram);
1224      memory_set_bankptr(machine,"bank10", state->multiface_ram);
12861225   }
12871226}
12881227
r9648r9649
12901229/* simulate the stop button has been pressed */
12911230static void multiface_stop(running_machine *machine)
12921231{
1232   amstrad_state *state = machine->driver_data<amstrad_state>();
12931233   /* multiface hardware enabled? */
12941234   if (!multiface_hardware_enabled(machine))
12951235      return;
12961236
12971237   /* if stop button not already pressed, do press action */
12981238   /* pressing stop button while multiface is running has no effect */
1299   if ((multiface_flags & MULTIFACE_STOP_BUTTON_PRESSED)==0)
1239   if ((state->multiface_flags & MULTIFACE_STOP_BUTTON_PRESSED)==0)
13001240   {
13011241      /* initialise 0065 toggle */
1302            /*multiface_flags &= ~MULTIFACE_0065_TOGGLE;*/
1242            /*state->multiface_flags &= ~MULTIFACE_0065_TOGGLE;*/
13031243
1304      multiface_flags |= MULTIFACE_RAM_ROM_ENABLED;
1244      state->multiface_flags |= MULTIFACE_RAM_ROM_ENABLED;
13051245
13061246      /* stop button has been pressed, furthur pressess will not issue a NMI */
1307      multiface_flags |= MULTIFACE_STOP_BUTTON_PRESSED;
1247      state->multiface_flags |= MULTIFACE_STOP_BUTTON_PRESSED;
13081248
1309      gate_array.mrer &=~0x04;
1249      state->gate_array.mrer &=~0x04;
13101250
13111251      /* page rom into memory */
13121252      multiface_rethink_memory(machine);
r9648r9649
13241264/* any io writes are passed through here */
13251265static WRITE8_HANDLER(multiface_io_write)
13261266{
1267   amstrad_state *state = space->machine->driver_data<amstrad_state>();
13271268   /* multiface hardware enabled? */
13281269      if (!multiface_hardware_enabled(space->machine))
13291270      return;
13301271
13311272      /* visible? */
1332   if (multiface_flags & MULTIFACE_VISIBLE)
1273   if (state->multiface_flags & MULTIFACE_VISIBLE)
13331274   {
13341275      if (offset==0x0fee8)
13351276      {
1336         multiface_flags |= MULTIFACE_RAM_ROM_ENABLED;
1277         state->multiface_flags |= MULTIFACE_RAM_ROM_ENABLED;
13371278         amstrad_rethinkMemory(space->machine);
13381279      }
13391280
13401281      if (offset==0x0feea)
13411282      {
1342         multiface_flags &= ~MULTIFACE_RAM_ROM_ENABLED;
1283         state->multiface_flags &= ~MULTIFACE_RAM_ROM_ENABLED;
13431284         amstrad_rethinkMemory(space->machine);
13441285      }
13451286   }
r9648r9649
13561297                        /* pen index */
13571298                        case 0x00:
13581299                        {
1359                           multiface_ram[0x01fcf] = data;
1300                           state->multiface_ram[0x01fcf] = data;
13601301
13611302                        }
13621303                        break;
r9648r9649
13661307                        {
13671308                           int pen_index;
13681309
1369                           pen_index = multiface_ram[0x01fcf] & 0x0f;
1310                           pen_index = state->multiface_ram[0x01fcf] & 0x0f;
13701311
1371                           if (multiface_ram[0x01fcf] & 0x010)
1312                           if (state->multiface_ram[0x01fcf] & 0x010)
13721313                           {
13731314
1374                              multiface_ram[0x01fdf + pen_index] = data;
1315                              state->multiface_ram[0x01fdf + pen_index] = data;
13751316                           }
13761317                           else
13771318                           {
1378                              multiface_ram[0x01f90 + pen_index] = data & 0x01f;
1319                              state->multiface_ram[0x01f90 + pen_index] = data & 0x01f;
13791320                           }
13801321
13811322                        }
r9648r9649
13851326                        case 0x080:
13861327                        {
13871328
1388                           multiface_ram[0x01fef] = data;
1329                           state->multiface_ram[0x01fef] = data;
13891330
13901331                        }
13911332                        break;
r9648r9649
13941335                        case 0x0c0:
13951336                        {
13961337
1397                           multiface_ram[0x01fff] = data;
1338                           state->multiface_ram[0x01fff] = data;
13981339
13991340                        }
14001341                        break;
r9648r9649
14111352            /* crtc register index */
14121353            case 0x0bc:
14131354            {
1414                  multiface_ram[0x01cff] = data;
1355                  state->multiface_ram[0x01cff] = data;
14151356            }
14161357            break;
14171358
r9648r9649
14201361            {
14211362                  int reg_index;
14221363
1423                  reg_index = multiface_ram[0x01cff] & 0x0f;
1364                  reg_index = state->multiface_ram[0x01cff] & 0x0f;
14241365
1425                  multiface_ram[0x01db0 + reg_index] = data;
1366                  state->multiface_ram[0x01db0 + reg_index] = data;
14261367            }
14271368            break;
14281369
r9648r9649
14301371            /* 8255 ppi control */
14311372            case 0x0f7:
14321373            {
1433              multiface_ram[0x017ff] = data;
1374              state->multiface_ram[0x017ff] = data;
14341375
14351376            }
14361377            break;
r9648r9649
14381379            /* rom select */
14391380            case 0x0df:
14401381            {
1441               multiface_ram[0x01aac] = data;
1382               state->multiface_ram[0x01aac] = data;
14421383            }
14431384            break;
14441385
r9648r9649
14581399  -----------------*/
14591400static void amstrad_setLowerRom(running_machine *machine)
14601401{
1402   amstrad_state *state = machine->driver_data<amstrad_state>();
14611403   UINT8 *bank_base;
14621404
14631405   /* b2 : "1" Lower rom area disable or "0" Lower rom area enable */
1464   if ( amstrad_system_type == SYSTEM_CPC || amstrad_system_type == SYSTEM_ALESTE )
1406   if ( state->system_type == SYSTEM_CPC || state->system_type == SYSTEM_ALESTE )
14651407   {
1466      if ((gate_array.mrer & (1<<2)) == 0)
1408      if ((state->gate_array.mrer & (1<<2)) == 0)
14671409      {
14681410         bank_base = &memory_region(machine, "maincpu")[0x010000];
14691411      }
14701412      else
14711413      {
1472         if(aleste_mode & 0x04)
1473            bank_base = Aleste_RamBanks[0];
1414         if(state->aleste_mode & 0x04)
1415            bank_base = state->Aleste_RamBanks[0];
14741416         else
1475            bank_base = AmstradCPC_RamBanks[0];
1417            bank_base = state->AmstradCPC_RamBanks[0];
14761418      }
14771419      memory_set_bankptr(machine,"bank1", bank_base);
14781420      memory_set_bankptr(machine,"bank2", bank_base+0x02000);
r9648r9649
14811423   {
14821424      address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
14831425
1484      if ( asic.enabled && ( asic.rmr2 & 0x18 ) == 0x18 )
1426      if ( state->asic.enabled && ( state->asic.rmr2 & 0x18 ) == 0x18 )
14851427      {
14861428         memory_install_read8_handler(space, 0x4000, 0x5fff, 0, 0, amstrad_plus_asic_4000_r);
14871429         memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, amstrad_plus_asic_6000_r);
r9648r9649
14961438         memory_install_write_bank(space, 0x6000, 0x7fff, 0, 0, "bank12");
14971439      }
14981440
1499      if(AmstradCPC_RamBanks[0] != NULL)
1441      if(state->AmstradCPC_RamBanks[0] != NULL)
15001442      {
1501         memory_set_bankptr(machine,"bank1", AmstradCPC_RamBanks[0]);
1502         memory_set_bankptr(machine,"bank2", AmstradCPC_RamBanks[0]+0x2000);
1503         memory_set_bankptr(machine,"bank3", AmstradCPC_RamBanks[1]);
1504         memory_set_bankptr(machine,"bank4", AmstradCPC_RamBanks[1]+0x2000);
1505         memory_set_bankptr(machine,"bank5", AmstradCPC_RamBanks[2]);
1506         memory_set_bankptr(machine,"bank6", AmstradCPC_RamBanks[2]+0x2000);
1443         memory_set_bankptr(machine,"bank1", state->AmstradCPC_RamBanks[0]);
1444         memory_set_bankptr(machine,"bank2", state->AmstradCPC_RamBanks[0]+0x2000);
1445         memory_set_bankptr(machine,"bank3", state->AmstradCPC_RamBanks[1]);
1446         memory_set_bankptr(machine,"bank4", state->AmstradCPC_RamBanks[1]+0x2000);
1447         memory_set_bankptr(machine,"bank5", state->AmstradCPC_RamBanks[2]);
1448         memory_set_bankptr(machine,"bank6", state->AmstradCPC_RamBanks[2]+0x2000);
15071449      }
15081450
1509      if ( (gate_array.mrer & (1<<2)) == 0)
1451      if ( (state->gate_array.mrer & (1<<2)) == 0)
15101452      {  // ASIC secondary lower ROM selection (bit 5: 1 = enabled)
1511         if ( asic.enabled )
1453         if ( state->asic.enabled )
15121454         {
1513//              logerror("L-ROM: Lower ROM enabled, cart bank %i\n", asic.rmr2 & 0x07 );
1514            bank_base = &memory_region(machine, "maincpu")[0x4000 * ( asic.rmr2 & 0x07 )];
1515            switch( asic.rmr2 & 0x18 )
1455//              logerror("L-ROM: Lower ROM enabled, cart bank %i\n", state->asic.rmr2 & 0x07 );
1456            bank_base = &memory_region(machine, "maincpu")[0x4000 * ( state->asic.rmr2 & 0x07 )];
1457            switch( state->asic.rmr2 & 0x18 )
15161458            {
15171459            case 0x00:
15181460//                  logerror("L-ROM: located at &0000\n");
r9648r9649
15511493  -----------------*/
15521494static void amstrad_setUpperRom(running_machine *machine)
15531495{
1496   amstrad_state *state = machine->driver_data<amstrad_state>();
15541497   UINT8 *bank_base = NULL;
15551498
15561499   /* b3 : "1" Upper rom area disable or "0" Upper rom area enable */
1557   if ( ! ( gate_array.mrer & 0x08 ) )
1500   if ( ! ( state->gate_array.mrer & 0x08 ) )
15581501   {
1559      bank_base = Amstrad_ROM_Table[ gate_array.upper_bank ];
1502      bank_base = state->Amstrad_ROM_Table[ state->gate_array.upper_bank ];
15601503   }
15611504   else
15621505   {
1563      if(aleste_mode & 0x04)
1564         bank_base = Aleste_RamBanks[3];
1506      if(state->aleste_mode & 0x04)
1507         bank_base = state->Aleste_RamBanks[3];
15651508      else
1566         bank_base = AmstradCPC_RamBanks[3];
1509         bank_base = state->AmstradCPC_RamBanks[3];
15671510   }
15681511
15691512   if (bank_base)
r9648r9649
15961539*/
15971540static void AmstradCPC_GA_SetRamConfiguration(running_machine *machine)
15981541{
1599   int ConfigurationIndex = amstrad_GateArray_RamConfiguration & 0x07;
1542   amstrad_state *state = machine->driver_data<amstrad_state>();
1543   int ConfigurationIndex = state->GateArray_RamConfiguration & 0x07;
16001544   int BankIndex,i;
16011545   unsigned char *BankAddr;
16021546
16031547/* if b5 = 0 */
1604   if(((amstrad_GateArray_RamConfiguration) & (1<<5)) == 0)
1548   if(((state->GateArray_RamConfiguration) & (1<<5)) == 0)
16051549   {
16061550       for (i=0;i<4;i++)
16071551      {
16081552         BankIndex = RamConfigurations[(ConfigurationIndex << 2) + i];
16091553         BankAddr = messram_get_ptr(machine->device("messram")) + (BankIndex << 14);
1610         Aleste_RamBanks[i] = BankAddr;
1611         AmstradCPC_RamBanks[i] = BankAddr;
1554         state->Aleste_RamBanks[i] = BankAddr;
1555         state->AmstradCPC_RamBanks[i] = BankAddr;
16121556      }
16131557   }
16141558   else
r9648r9649
16861630
16871631WRITE8_HANDLER( amstrad_plus_asic_4000_w )
16881632{
1633   amstrad_state *state = space->machine->driver_data<amstrad_state>();
16891634//  logerror("ASIC: Write to register at &%04x\n",offset+0x4000);
1690   asic.ram[offset] = data & 0x0f;
1635   state->asic.ram[offset] = data & 0x0f;
16911636}
16921637
16931638
16941639WRITE8_HANDLER( amstrad_plus_asic_6000_w )
16951640{
1696   asic.ram[offset+0x2000] = data;
1641   amstrad_state *state = space->machine->driver_data<amstrad_state>();
1642   state->asic.ram[offset+0x2000] = data;
16971643   if(offset >= 0x0400 && offset < 0x440 && ( offset & 0x01 ) ) // ASIC palette
16981644   {
1699      asic.ram[ offset + 0x2000 ] = data & 0x0f;
1645      state->asic.ram[ offset + 0x2000 ] = data & 0x0f;
17001646   }
17011647   if(offset == 0x0800)  // Programmable raster interrupt
17021648   {
17031649//      logerror("ASIC: Wrote %02x to PRI\n",data);
1704      asic.pri = data;
1650      state->asic.pri = data;
17051651   }
17061652   if(offset >= 0x0801 && offset <= 0x0803)  // Split screen registers
17071653   {
1708      logerror("ASIC: Split screen at line %i, address &%04x\n",asic.ram[0x2801],asic.ram[0x2803] + (asic.ram[0x2802] << 8));
1654      logerror("ASIC: Split screen at line %i, address &%04x\n",state->asic.ram[0x2801],state->asic.ram[0x2803] + (state->asic.ram[0x2802] << 8));
17091655   }
17101656   if(offset == 0x0804)  // Soft scroll register
17111657   {
r9648r9649
17151661      // high 5 bits go to interrupt vector
17161662      int vector;
17171663
1718      if ( asic.enabled )
1664      if ( state->asic.enabled )
17191665      {
1720         vector = (data & 0xf8) + (amstrad_plus_irq_cause);
1666         vector = (data & 0xf8) + (state->plus_irq_cause);
17211667         cpu_set_input_line_vector(space->machine->device("maincpu"), 0, vector);
17221668         logerror("ASIC: IM 2 vector write %02x, data = &%02x\n",vector,data);
17231669      }
1724      asic.dma_clear = data & 0x01;
1670      state->asic.dma_clear = data & 0x01;
17251671   }
17261672   // DMA channels
17271673   switch(offset)
17281674   {
17291675   case 0x0c00:
17301676   case 0x0c01:
1731      asic.dma_addr[0] = (asic.ram[0x2c01] << 8) + asic.ram[0x2c00];
1732      asic.dma_status &= ~0x01;
1733      logerror("ASIC: DMA 0 address set to &%04x\n",asic.dma_addr[0]);
1677      state->asic.dma_addr[0] = (state->asic.ram[0x2c01] << 8) + state->asic.ram[0x2c00];
1678      state->asic.dma_status &= ~0x01;
1679      logerror("ASIC: DMA 0 address set to &%04x\n",state->asic.dma_addr[0]);
17341680      break;
17351681   case 0x0c04:
17361682   case 0x0c05:
1737      asic.dma_addr[1] = (asic.ram[0x2c05] << 8) + asic.ram[0x2c04];
1738      asic.dma_status &= ~0x02;
1739      logerror("ASIC: DMA 1 address set to &%04x\n",asic.dma_addr[1]);
1683      state->asic.dma_addr[1] = (state->asic.ram[0x2c05] << 8) + state->asic.ram[0x2c04];
1684      state->asic.dma_status &= ~0x02;
1685      logerror("ASIC: DMA 1 address set to &%04x\n",state->asic.dma_addr[1]);
17401686      break;
17411687   case 0x0c08:
17421688   case 0x0c09:
1743      asic.dma_addr[2] = (asic.ram[0x2c09] << 8) + asic.ram[0x2c08];
1744      asic.dma_status &= ~0x04;
1745      logerror("ASIC: DMA 2 address set to &%04x\n",asic.dma_addr[2]);
1689      state->asic.dma_addr[2] = (state->asic.ram[0x2c09] << 8) + state->asic.ram[0x2c08];
1690      state->asic.dma_status &= ~0x04;
1691      logerror("ASIC: DMA 2 address set to &%04x\n",state->asic.dma_addr[2]);
17461692      break;
17471693   case 0x0c02:
1748      asic.dma_prescaler[0] = data + 1;
1694      state->asic.dma_prescaler[0] = data + 1;
17491695      logerror("ASIC: DMA 0 pause prescaler set to %i\n",data);
17501696      break;
17511697   case 0x0c06:
1752      asic.dma_prescaler[1] = data + 1;
1698      state->asic.dma_prescaler[1] = data + 1;
17531699      logerror("ASIC: DMA 1 pause prescaler set to %i\n",data);
17541700      break;
17551701   case 0x0c0a:
1756      asic.dma_prescaler[2] = data + 1;
1702      state->asic.dma_prescaler[2] = data + 1;
17571703      logerror("ASIC: DMA 2 pause prescaler set to %i\n",data);
17581704      break;
17591705   case 0x0c0f:
1760      asic.dma_status = data;
1706      state->asic.dma_status = data;
17611707      logerror("ASIC: DMA status write - %02x\n",data);
17621708      if(data & 0x40)
17631709      {
17641710         logerror("ASIC: DMA 0 IRQ acknowledge\n");
17651711         cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE);
1766         amstrad_plus_irq_cause = 0x06;
1767         asic.ram[0x2c0f] &= ~0x40;
1712         state->plus_irq_cause = 0x06;
1713         state->asic.ram[0x2c0f] &= ~0x40;
17681714      }
17691715      if(data & 0x20)
17701716      {
17711717         logerror("ASIC: DMA 1 IRQ acknowledge\n");
17721718         cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE);
1773         amstrad_plus_irq_cause = 0x06;
1774         asic.ram[0x2c0f] &= ~0x20;
1719         state->plus_irq_cause = 0x06;
1720         state->asic.ram[0x2c0f] &= ~0x20;
17751721      }
17761722      if(data & 0x10)
17771723      {
17781724         logerror("ASIC: DMA 2 IRQ acknowledge\n");
17791725         cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE);
1780         amstrad_plus_irq_cause = 0x06;
1781         asic.ram[0x2c0f] &= ~0x10;
1726         state->plus_irq_cause = 0x06;
1727         state->asic.ram[0x2c0f] &= ~0x10;
17821728      }
17831729      break;
17841730   }
r9648r9649
17871733
17881734READ8_HANDLER( amstrad_plus_asic_4000_r )
17891735{
1736   amstrad_state *state = space->machine->driver_data<amstrad_state>();
17901737//  logerror("RAM: read from &%04x\n",offset+0x4000);
1791   return asic.ram[offset];
1738   return state->asic.ram[offset];
17921739}
17931740
17941741
17951742READ8_HANDLER( amstrad_plus_asic_6000_r )
17961743{
1744   amstrad_state *state = space->machine->driver_data<amstrad_state>();
17971745//  logerror("RAM: read from &%04x\n",offset+0x6000);
17981746   // Analogue ports
17991747   if(offset == 0x0808)
r9648r9649
18241772   if(offset == 0x0c0f)  // DMA status and control
18251773        {
18261774            int result = 0;
1827            if(amstrad_plus_irq_cause == 0x00)
1775            if(state->plus_irq_cause == 0x00)
18281776                result |= 0x40;
1829            if(amstrad_plus_irq_cause == 0x02)
1777            if(state->plus_irq_cause == 0x02)
18301778                result |= 0x20;
1831            if(amstrad_plus_irq_cause == 0x04)
1779            if(state->plus_irq_cause == 0x04)
18321780                result |= 0x10;
1833            if(amstrad_plus_irq_cause == 0x06)
1781            if(state->plus_irq_cause == 0x06)
18341782                result |= 0x80;
18351783            return result;
18361784        }
18371785#endif
1838   return asic.ram[offset+0x2000];
1786   return state->asic.ram[offset+0x2000];
18391787}
18401788
18411789
18421790/* used for loading snapshot only ! */
18431791static void AmstradCPC_PALWrite(running_machine *machine, int data)
18441792{
1793   amstrad_state *state = machine->driver_data<amstrad_state>();
18451794   if ((data & 0x0c0)==0x0c0)
18461795   {
1847      amstrad_GateArray_RamConfiguration = data;
1796      state->GateArray_RamConfiguration = data;
18481797      AmstradCPC_GA_SetRamConfiguration(machine);
18491798   }
18501799}
r9648r9649
18721821
18731822static void amstrad_GateArray_write(running_machine *machine, UINT8 dataToGateArray)
18741823{
1824   amstrad_state *state = machine->driver_data<amstrad_state>();
18751825/* Get Bit 7 and 6 of the dataToGateArray = Gate Array function selected */
18761826   switch ((dataToGateArray & 0xc0)>>6)
18771827   {
r9648r9649
18881838   case 0x00:
18891839      /* Select Border Number, get b4 */
18901840      /* if b4 = 0 : Select Pen Number, get b3-b0 */
1891      gate_array.pen_selected = ( dataToGateArray & 0x10 ) ? 0x10 : ( dataToGateArray & 0x0f );
1841      state->gate_array.pen_selected = ( dataToGateArray & 0x10 ) ? 0x10 : ( dataToGateArray & 0x0f );
18921842      break;
18931843
18941844/* Colour selection
r9648r9649
190418541   x     |
190518550   x     |*/
19061856   case 0x01:
1907      amstrad_vh_update_colour( machine, gate_array.pen_selected, (dataToGateArray & 0x1F));
1857      amstrad_vh_update_colour( machine, state->gate_array.pen_selected, (dataToGateArray & 0x1F));
19081858      break;
19091859
19101860/* Select screen mode and rom configuration
r9648r9649
19381888      /* If bit 5 is enabled on a CPC Plus/GX4000 when the ASIC is unlocked, sets the lower ROM position and cart bank
19391889           b5 = 1, b4b3 = RAM position for lower ROM area and if the ASIC registers are visible at &4000,
19401890           b2b1b0 = cartridge bank to read from lower ROM area (0-7 only) */
1941      if ( amstrad_system_type == SYSTEM_PLUS || amstrad_system_type == SYSTEM_GX4000 )
1891      if ( state->system_type == SYSTEM_PLUS || state->system_type == SYSTEM_GX4000 )
19421892      {
1943         if ( asic.enabled && (dataToGateArray & 0x20) )
1893         if ( state->asic.enabled && (dataToGateArray & 0x20) )
19441894         {
1945            asic.rmr2 = dataToGateArray;
1895            state->asic.rmr2 = dataToGateArray;
19461896         }
19471897         else
19481898         {
1949            gate_array.mrer = dataToGateArray;
1899            state->gate_array.mrer = dataToGateArray;
19501900         }
19511901      }
19521902      else
19531903      {
1954         gate_array.mrer = dataToGateArray;
1904         state->gate_array.mrer = dataToGateArray;
19551905      }
19561906
19571907      /* If bit 4 of the "Select screen mode and rom configuration" register of the Gate-Array is set to "1"
19581908         then the interrupt request is cleared and the 6-bit counter is reset to "0".  */
1959      if ( gate_array.mrer & 0x10 )
1909      if ( state->gate_array.mrer & 0x10 )
19601910      {
1961         gate_array.hsync_counter = 0;
1911         state->gate_array.hsync_counter = 0;
19621912         cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
19631913      }
19641914
r9648r9649
19671917      amstrad_setUpperRom(machine);
19681918
19691919      /* b1b0 mode */
1970      amstrad_vh_update_mode();
1920      amstrad_vh_update_mode(state);
19711921
19721922      break;
19731923
r9648r9649
19791929In the 464+ and 6128+ this function is performed by the ASIC or a memory expansion.
19801930*/
19811931   case 0x03:
1982      amstrad_GateArray_RamConfiguration = dataToGateArray;
1932      state->GateArray_RamConfiguration = dataToGateArray;
19831933      break;
19841934
19851935   default:
r9648r9649
19901940
19911941static WRITE8_HANDLER( aleste_msx_mapper )
19921942{
1943   amstrad_state *state = space->machine->driver_data<amstrad_state>();
19931944   int page = (offset & 0x0300) >> 8;
19941945   int ramptr = (data & 0x1f) * 0x4000;
19951946   int rampage = data & 0x1f;
r9648r9649
20021953      amstrad_GateArray_write(space->machine, data);
20031954      break;
20041955   case 1:  // Colour select (6-bit palette)
2005      aleste_vh_update_colour( space->machine, gate_array.pen_selected, data & 0x3f );
1956      aleste_vh_update_colour( space->machine, state->gate_array.pen_selected, data & 0x3f );
20061957      break;
20071958   case 2:  // Screen mode, Upper/Lower ROM select
20081959      amstrad_GateArray_write(space->machine, data);
r9648r9649
20151966         memory_set_bankptr(space->machine,"bank2",messram_get_ptr(space->machine->device("messram"))+ramptr+0x2000);
20161967         memory_set_bankptr(space->machine,"bank9",messram_get_ptr(space->machine->device("messram"))+ramptr);
20171968         memory_set_bankptr(space->machine,"bank10",messram_get_ptr(space->machine->device("messram"))+ramptr+0x2000);
2018         Aleste_RamBanks[0] = messram_get_ptr(space->machine->device("messram"))+ramptr;
2019         aleste_active_page[0] = data;
1969         state->Aleste_RamBanks[0] = messram_get_ptr(space->machine->device("messram"))+ramptr;
1970         state->aleste_active_page[0] = data;
20201971         logerror("RAM: RAM location 0x%06x (page %02x) mapped to 0x0000\n",ramptr,rampage);
20211972         break;
20221973      case 1:  /* 0x4000 - 0x7fff */
r9648r9649
20241975         memory_set_bankptr(space->machine,"bank4",messram_get_ptr(space->machine->device("messram"))+ramptr+0x2000);
20251976         memory_set_bankptr(space->machine,"bank11",messram_get_ptr(space->machine->device("messram"))+ramptr);
20261977         memory_set_bankptr(space->machine,"bank12",messram_get_ptr(space->machine->device("messram"))+ramptr+0x2000);
2027         Aleste_RamBanks[1] = messram_get_ptr(space->machine->device("messram"))+ramptr;
2028         aleste_active_page[1] = data;
1978         state->Aleste_RamBanks[1] = messram_get_ptr(space->machine->device("messram"))+ramptr;
1979         state->aleste_active_page[1] = data;
20291980         logerror("RAM: RAM location 0x%06x (page %02x) mapped to 0x4000\n",ramptr,rampage);
20301981         break;
20311982      case 2:  /* 0x8000 - 0xbfff */
r9648r9649
20331984         memory_set_bankptr(space->machine,"bank6",messram_get_ptr(space->machine->device("messram"))+ramptr+0x2000);
20341985         memory_set_bankptr(space->machine,"bank13",messram_get_ptr(space->machine->device("messram"))+ramptr);
20351986         memory_set_bankptr(space->machine,"bank14",messram_get_ptr(space->machine->device("messram"))+ramptr+0x2000);
2036         Aleste_RamBanks[2] = messram_get_ptr(space->machine->device("messram"))+ramptr;
2037         aleste_active_page[2] = data;
1987         state->Aleste_RamBanks[2] = messram_get_ptr(space->machine->device("messram"))+ramptr;
1988         state->aleste_active_page[2] = data;
20381989         logerror("RAM: RAM location 0x%06x (page %02x) mapped to 0x8000\n",ramptr,rampage);
20391990         break;
20401991      case 3:  /* 0xc000 - 0xffff */
r9648r9649
20421993         memory_set_bankptr(space->machine,"bank8",messram_get_ptr(space->machine->device("messram"))+ramptr+0x2000);
20431994         memory_set_bankptr(space->machine,"bank15",messram_get_ptr(space->machine->device("messram"))+ramptr);
20441995         memory_set_bankptr(space->machine,"bank16",messram_get_ptr(space->machine->device("messram"))+ramptr+0x2000);
2045         Aleste_RamBanks[3] = messram_get_ptr(space->machine->device("messram"))+ramptr;
2046         aleste_active_page[3] = data;
1996         state->Aleste_RamBanks[3] = messram_get_ptr(space->machine->device("messram"))+ramptr;
1997         state->aleste_active_page[3] = data;
20471998         logerror("RAM: RAM location 0x%06x (page %02x) mapped to 0xc000\n",ramptr,rampage);
20481999         break;
20492000      }
r9648r9649
21152066
21162067READ8_HANDLER ( amstrad_cpc_io_r )
21172068{
2069   amstrad_state *state = space->machine->driver_data<amstrad_state>();
21182070   running_device *fdc = space->machine->device("upd765");
21192071   running_device *mc6845 = space->machine->device("mc6845" );
21202072
r9648r9649
21262078//  crtc_type = input_port_read_safe(space->machine, "crtc", 0);
21272079//  m6845_set_personality(crtc_type);
21282080
2129   if(aleste_mode & 0x04)
2081   if(state->aleste_mode & 0x04)
21302082   {
21312083      if ((offset & (1<<15)) == 0)  // Aleste Mapper is readable?
21322084      {
21332085         page = (offset & 0x0300) >> 8;
2134         data = aleste_active_page[page];
2086         data = state->aleste_active_page[page];
21352087         return data;
21362088      }
21372089   }
r9648r9649
21962148If b10 is reset but none of b7-b5 are reset, user expansion peripherals are selected.
21972149The exception is the case where none of b7-b0 are reset (i.e. port &FBFF), which causes the expansion peripherals to reset.
21982150 */
2199   if ( amstrad_system_type != SYSTEM_GX4000 )
2151   if ( state->system_type != SYSTEM_GX4000 )
22002152   {
22012153      if ( ( offset & (1<<10) ) == 0 )
22022154      {
r9648r9649
22232175
22242176
22252177// Handler for checking the ASIC unlocking sequence
2226static void amstrad_plus_seqcheck(int data)
2178static void amstrad_plus_seqcheck(amstrad_state *state, int data)
22272179{
2228   static int prev_data;
2229
2230   if(data == 0 && prev_data != 0)
2180   if(data == 0 && state->prev_data != 0)
22312181   {
2232      asic.seqptr = 0;  // non-zero value followed by zero will sync the locking mechanism
2182      state->asic.seqptr = 0;  // non-zero value followed by zero will sync the locking mechanism
22332183   }
2234   if(data == asic_unlock_seq[asic.seqptr])
2184   if(data == asic_unlock_seq[state->asic.seqptr])
22352185   {
2236      asic.seqptr++;
2237      if ( asic.seqptr == 14 && asic.enabled )
2186      state->asic.seqptr++;
2187      if ( state->asic.seqptr == 14 && state->asic.enabled )
22382188      {
22392189         logerror("SYS: ASIC locked\n");
2240         asic.enabled = 0;
2190         state->asic.enabled = 0;
22412191      }
2242      if ( asic.seqptr >= 15 )  // end of sequence
2192      if ( state->asic.seqptr >= 15 )  // end of sequence
22432193      {
22442194         logerror("SYS: ASIC unlocked\n");
2245         asic.enabled = 1;
2195         state->asic.enabled = 1;
22462196      }
22472197   }
2248   prev_data = data;
2198   state->prev_data = data;
22492199}
22502200
22512201
22522202/* Offset handler for write */
22532203WRITE8_HANDLER ( amstrad_cpc_io_w )
22542204{
2205   amstrad_state *state = space->machine->driver_data<amstrad_state>();
22552206   running_device *fdc = space->machine->device("upd765");
22562207   running_device *mc6845 = space->machine->device("mc6845");
22572208
2258   static int printer_bit8_selected = FALSE;
2259
22602209   if ((offset & (1<<15)) == 0)
22612210   {
2262      if(aleste_mode & 0x04) // Aleste mode
2211      if(state->aleste_mode & 0x04) // Aleste mode
22632212      {
22642213         aleste_msx_mapper(space, offset, data);
22652214      }
r9648r9649
22822231      {
22832232      case 0x00:      /* Select internal 6845 register Write Only */
22842233         mc6845_address_w( mc6845, 0, data );
2285         if ( amstrad_system_type == SYSTEM_PLUS || amstrad_system_type == SYSTEM_GX4000 )
2286            amstrad_plus_seqcheck(data);
2234         if ( state->system_type == SYSTEM_PLUS || state->system_type == SYSTEM_GX4000 )
2235            amstrad_plus_seqcheck(state, data);
22872236
22882237         /* printer port d7 */
2289         if (data == 0x0c && amstrad_system_type == SYSTEM_PLUS)
2290            printer_bit8_selected = TRUE;
2238         if (data == 0x0c && state->system_type == SYSTEM_PLUS)
2239            state->printer_bit8_selected = TRUE;
22912240
2292         asic.addr_6845 = data;
2241         state->asic.addr_6845 = data;
22932242         break;
22942243      case 0x01:      /* Write to selected internal 6845 register Write Only */
2295         if ( amstrad_system_type == SYSTEM_PLUS || amstrad_system_type == SYSTEM_GX4000 )
2244         if ( state->system_type == SYSTEM_PLUS || state->system_type == SYSTEM_GX4000 )
22962245            amstrad_plus_update_video( space->machine );
22972246         else
22982247            amstrad_update_video( space->machine );
22992248         mc6845_register_w( mc6845, 0, data );
23002249
23012250         /* printer port bit 8 */
2302         if (printer_bit8_selected && amstrad_system_type == SYSTEM_PLUS)
2251         if (state->printer_bit8_selected && state->system_type == SYSTEM_PLUS)
23032252         {
23042253            running_device *printer = space->machine->device("centronics");
23052254            centronics_d7_w(printer, BIT(data, 3));
2306            printer_bit8_selected = FALSE;
2255            state->printer_bit8_selected = FALSE;
23072256         }
23082257
2309         if ( asic.addr_6845 == 0x01 )
2310            asic.horiz_disp = data;
2258         if ( state->asic.addr_6845 == 0x01 )
2259            state->asic.horiz_disp = data;
23112260
23122261         break;
23132262      default:
r9648r9649
23192268   /* b13 = 0 : ROM select Write Selected*/
23202269   if ((offset & (1<<13)) == 0)
23212270   {
2322      gate_array.upper_bank = data;
2271      state->gate_array.upper_bank = data;
23232272      amstrad_setUpperRom( space->machine );
23242273   }
23252274
23262275   /* b12 = 0 : Printer port Write Selected*/
2327   if(amstrad_system_type != SYSTEM_GX4000)
2276   if(state->system_type != SYSTEM_GX4000)
23282277   {
23292278      if ((offset & (1<<12)) == 0)
23302279      {
r9648r9649
23702319If b10 is reset but none of b7-b5 are reset, user expansion peripherals are selected.
23712320The exception is the case where none of b7-b0 are reset (i.e. port &FBFF), which causes the expansion peripherals to reset.
23722321*/
2373      if(amstrad_system_type != SYSTEM_GX4000)
2322      if(state->system_type != SYSTEM_GX4000)
23742323      {
23752324         if ((offset & (1<<7)) == 0)
23762325         {
r9648r9649
24082357        D5 - 0-AY8910 ,1-512WI1 */
24092358   if(offset == 0xfabf)
24102359   {
2411      aleste_mode = data;
2360      state->aleste_mode = data;
24122361      logerror("EXTEND: Port &FABF write 0x%02x\n",data);
2413      mc6845_set_clock( mc6845, ( aleste_mode & 0x02 ) ? ( XTAL_16MHz / 8 ) : ( XTAL_16MHz / 16 ) );
2362      mc6845_set_clock( mc6845, ( state->aleste_mode & 0x02 ) ? ( XTAL_16MHz / 8 ) : ( XTAL_16MHz / 16 ) );
24142363   }
24152364
24162365   multiface_io_write(space, offset, data);
r9648r9649
24202369/* load CPCEMU style snapshots */
24212370static void amstrad_handle_snapshot(running_machine *machine, unsigned char *pSnapshot)
24222371{
2372   amstrad_state *state = machine->driver_data<amstrad_state>();
24232373   address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
24242374   running_device *mc6845 = space->machine->device("mc6845" );
24252375   running_device *ay8910 = machine->device("ay");
r9648r9649
25172467   mc6845_address_w( mc6845, 0, i );
25182468
25192469   /* upper rom selection */
2520   gate_array.upper_bank = pSnapshot[0x055];
2470   state->gate_array.upper_bank = pSnapshot[0x055];
25212471
25222472   /* PPI */
25232473   i8255a_w(machine->device("ppi8255"),3,pSnapshot[0x059] & 0x0ff);
r9648r9649
25622512control is passed to the default entry in rom 0*/
25632513static void amstrad_reset_machine(running_machine *machine)
25642514{
2515   amstrad_state *state = machine->driver_data<amstrad_state>();
25652516   /* enable lower rom (OS rom) */
25662517   amstrad_GateArray_write(machine, 0x089);
25672518
r9648r9649
25692520   amstrad_GateArray_write(machine, 0x0c0);
25702521
25712522  // Get manufacturer name and TV refresh rate from PCB link (dipswitch for mess emulation)
2572   ppi_port_inputs[amstrad_ppi_PortB] = (((input_port_read(machine, "solder_links")&MANUFACTURER_NAME)<<1) | (input_port_read(machine, "solder_links")&TV_REFRESH_RATE));
2523   state->ppi_port_inputs[amstrad_ppi_PortB] = (((input_port_read(machine, "solder_links")&MANUFACTURER_NAME)<<1) | (input_port_read(machine, "solder_links")&TV_REFRESH_RATE));
25732524
2574   if ( amstrad_system_type == SYSTEM_PLUS || amstrad_system_type == SYSTEM_GX4000 )
2575      memset(asic.ram,0,16384);  // clear ASIC RAM
2525   if ( state->system_type == SYSTEM_PLUS || state->system_type == SYSTEM_GX4000 )
2526      memset(state->asic.ram,0,16384);  // clear ASIC RAM
25762527
2577   multiface_reset();
2528   multiface_reset(state);
25782529}
25792530
25802531
r9648r9649
25832534  ------------------*/
25842535static void amstrad_rethinkMemory(running_machine *machine)
25852536{
2537   amstrad_state *state = machine->driver_data<amstrad_state>();
25862538   /* the following is used for banked memory read/writes and for setting up
25872539     * opcode and opcode argument reads */
25882540
r9648r9649
25902542   amstrad_setLowerRom(machine);
25912543
25922544   /* bank 1 - 0x04000..0x07fff */
2593   if ( amstrad_system_type == SYSTEM_CPC || amstrad_system_type == SYSTEM_ALESTE || asic.enabled == 0 )
2545   if ( state->system_type == SYSTEM_CPC || state->system_type == SYSTEM_ALESTE || state->asic.enabled == 0 )
25942546   {
2595      if(aleste_mode & 0x04)
2547      if(state->aleste_mode & 0x04)
25962548      {
2597         memory_set_bankptr(machine,"bank3", Aleste_RamBanks[1]);
2598         memory_set_bankptr(machine,"bank4", Aleste_RamBanks[1]+0x2000);
2549         memory_set_bankptr(machine,"bank3", state->Aleste_RamBanks[1]);
2550         memory_set_bankptr(machine,"bank4", state->Aleste_RamBanks[1]+0x2000);
25992551         /* bank 2 - 0x08000..0x0bfff */
2600         memory_set_bankptr(machine,"bank5", Aleste_RamBanks[2]);
2601         memory_set_bankptr(machine,"bank6", Aleste_RamBanks[2]+0x2000);
2552         memory_set_bankptr(machine,"bank5", state->Aleste_RamBanks[2]);
2553         memory_set_bankptr(machine,"bank6", state->Aleste_RamBanks[2]+0x2000);
26022554      }
26032555      else
26042556      {
2605         memory_set_bankptr(machine,"bank3", AmstradCPC_RamBanks[1]);
2606         memory_set_bankptr(machine,"bank4", AmstradCPC_RamBanks[1]+0x2000);
2557         memory_set_bankptr(machine,"bank3", state->AmstradCPC_RamBanks[1]);
2558         memory_set_bankptr(machine,"bank4", state->AmstradCPC_RamBanks[1]+0x2000);
26072559         /* bank 2 - 0x08000..0x0bfff */
2608         memory_set_bankptr(machine,"bank5", AmstradCPC_RamBanks[2]);
2609         memory_set_bankptr(machine,"bank6", AmstradCPC_RamBanks[2]+0x2000);
2560         memory_set_bankptr(machine,"bank5", state->AmstradCPC_RamBanks[2]);
2561         memory_set_bankptr(machine,"bank6", state->AmstradCPC_RamBanks[2]+0x2000);
26102562      }
26112563   }
26122564   else
r9648r9649
26162568   amstrad_setUpperRom(machine);
26172569
26182570   /* other banks */
2619   if(aleste_mode & 0x04)
2571   if(state->aleste_mode & 0x04)
26202572   {
2621      memory_set_bankptr(machine,"bank9", Aleste_RamBanks[0]);
2622      memory_set_bankptr(machine,"bank10", Aleste_RamBanks[0]+0x2000);
2623      memory_set_bankptr(machine,"bank11", Aleste_RamBanks[1]);
2624      memory_set_bankptr(machine,"bank12", Aleste_RamBanks[1]+0x2000);
2625      memory_set_bankptr(machine,"bank13", Aleste_RamBanks[2]);
2626      memory_set_bankptr(machine,"bank14", Aleste_RamBanks[2]+0x2000);
2627      memory_set_bankptr(machine,"bank15", Aleste_RamBanks[3]);
2628      memory_set_bankptr(machine,"bank16", Aleste_RamBanks[3]+0x2000);
2573      memory_set_bankptr(machine,"bank9", state->Aleste_RamBanks[0]);
2574      memory_set_bankptr(machine,"bank10", state->Aleste_RamBanks[0]+0x2000);
2575      memory_set_bankptr(machine,"bank11", state->Aleste_RamBanks[1]);
2576      memory_set_bankptr(machine,"bank12", state->Aleste_RamBanks[1]+0x2000);
2577      memory_set_bankptr(machine,"bank13", state->Aleste_RamBanks[2]);
2578      memory_set_bankptr(machine,"bank14", state->Aleste_RamBanks[2]+0x2000);
2579      memory_set_bankptr(machine,"bank15", state->Aleste_RamBanks[3]);
2580      memory_set_bankptr(machine,"bank16", state->Aleste_RamBanks[3]+0x2000);
26292581   }
26302582   else
26312583   {
2632      memory_set_bankptr(machine,"bank9", AmstradCPC_RamBanks[0]);
2633      memory_set_bankptr(machine,"bank10", AmstradCPC_RamBanks[0]+0x2000);
2634      memory_set_bankptr(machine,"bank11", AmstradCPC_RamBanks[1]);
2635      memory_set_bankptr(machine,"bank12", AmstradCPC_RamBanks[1]+0x2000);
2636      memory_set_bankptr(machine,"bank13", AmstradCPC_RamBanks[2]);
2637      memory_set_bankptr(machine,"bank14", AmstradCPC_RamBanks[2]+0x2000);
2638      memory_set_bankptr(machine,"bank15", AmstradCPC_RamBanks[3]);
2639      memory_set_bankptr(machine,"bank16", AmstradCPC_RamBanks[3]+0x2000);
2584      memory_set_bankptr(machine,"bank9", state->AmstradCPC_RamBanks[0]);
2585      memory_set_bankptr(machine,"bank10", state->AmstradCPC_RamBanks[0]+0x2000);
2586      memory_set_bankptr(machine,"bank11", state->AmstradCPC_RamBanks[1]);
2587      memory_set_bankptr(machine,"bank12", state->AmstradCPC_RamBanks[1]+0x2000);
2588      memory_set_bankptr(machine,"bank13", state->AmstradCPC_RamBanks[2]);
2589      memory_set_bankptr(machine,"bank14", state->AmstradCPC_RamBanks[2]+0x2000);
2590      memory_set_bankptr(machine,"bank15", state->AmstradCPC_RamBanks[3]);
2591      memory_set_bankptr(machine,"bank16", state->AmstradCPC_RamBanks[3]+0x2000);
26402592   }
26412593
26422594   /* multiface hardware enabled? */
r9648r9649
268826401    1         | Select PSG register. When set, the PSG will take the data at PPI Port A and select a register
26892641*/
26902642/* PSG function selected */
2691static unsigned char amstrad_Psg_FunctionSelected;
26922643static void update_psg(running_machine *machine)
26932644{
2645   amstrad_state *state = machine->driver_data<amstrad_state>();
26942646   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
26952647   running_device *ay8910 = machine->device("ay");
26962648   mc146818_device *rtc = space->machine->device<mc146818_device>("rtc");
26972649
2698   if(aleste_mode & 0x20)  // RTC selected
2650   if(state->aleste_mode & 0x20)  // RTC selected
26992651   {
2700      switch(aleste_rtc_function)
2652      switch(state->aleste_rtc_function)
27012653      {
27022654      case 0x02:  // AS
2703         rtc->write(*space, 0,ppi_port_outputs[amstrad_ppi_PortA]);
2655         rtc->write(*space, 0,state->ppi_port_outputs[amstrad_ppi_PortA]);
27042656         break;
27052657      case 0x04:  // DS write
2706         rtc->write(*space, 1,ppi_port_outputs[amstrad_ppi_PortA]);
2658         rtc->write(*space, 1,state->ppi_port_outputs[amstrad_ppi_PortA]);
27072659         break;
27082660      case 0x05:  // DS read
2709         ppi_port_inputs[amstrad_ppi_PortA] = rtc->read(*space, 1);
2661         state->ppi_port_inputs[amstrad_ppi_PortA] = rtc->read(*space, 1);
27102662         break;
27112663      }
27122664      return;
27132665   }
2714   switch (amstrad_Psg_FunctionSelected)
2666   switch (state->Psg_FunctionSelected)
27152667   {
27162668   case 0:
27172669      {/* Inactive */
27182670      } break;
27192671   case 1:
27202672      {/* b6 = 1 ? : Read from selected PSG register and make the register data available to PPI Port A */
2721         ppi_port_inputs[amstrad_ppi_PortA] = ay8910_r(ay8910, 0);
2673         state->ppi_port_inputs[amstrad_ppi_PortA] = ay8910_r(ay8910, 0);
27222674      }
27232675      break;
27242676   case 2:
27252677      {/* b7 = 1 ? : Write to selected PSG register and write data to PPI Port A */
2726         ay8910_data_w(ay8910, 0, ppi_port_outputs[amstrad_ppi_PortA]);
2678         ay8910_data_w(ay8910, 0, state->ppi_port_outputs[amstrad_ppi_PortA]);
27272679      }
27282680      break;
27292681   case 3:
27302682      {/* b6 and b7 = 1 ? : The register will now be selected and the user can read from or write to it.  The register will remain selected until another is chosen.*/
2731         ay8910_address_w(ay8910, 0, ppi_port_outputs[amstrad_ppi_PortA]);
2732         prev_reg = ppi_port_outputs[amstrad_ppi_PortA];
2683         ay8910_address_w(ay8910, 0, state->ppi_port_outputs[amstrad_ppi_PortA]);
2684         state->prev_reg = state->ppi_port_outputs[amstrad_ppi_PortA];
27332685      }
27342686      break;
27352687   default:
r9648r9649
27422694/* Read/Write 8255 PPI port A (connected to AY-3-8912 databus) */
27432695READ8_DEVICE_HANDLER ( amstrad_ppi_porta_r )
27442696{
2697   amstrad_state *state = device->machine->driver_data<amstrad_state>();
27452698   update_psg(device->machine);
2746   return ppi_port_inputs[amstrad_ppi_PortA];
2699   return state->ppi_port_inputs[amstrad_ppi_PortA];
27472700}
27482701
27492702
27502703WRITE8_DEVICE_HANDLER ( amstrad_ppi_porta_w )
27512704{
2752   ppi_port_outputs[amstrad_ppi_PortA] = data;
2705   amstrad_state *state = device->machine->driver_data<amstrad_state>();
2706   state->ppi_port_outputs[amstrad_ppi_PortA] = data;
27532707   update_psg(device->machine);
27542708}
27552709
r9648r9649
27822736
27832737READ8_DEVICE_HANDLER (amstrad_ppi_portb_r)
27842738{
2739   amstrad_state *state = device->machine->driver_data<amstrad_state>();
27852740   int data = 0;
27862741/* Set b7 with cassette tape input */
2787   if(amstrad_system_type != SYSTEM_GX4000)
2742   if(state->system_type != SYSTEM_GX4000)
27882743   {
27892744      if (cassette_input(device->machine->device("cassette" )) > 0.03)
27902745      {
r9648r9649
27922747      }
27932748   }
27942749/* Set b6 with Parallel/Printer port ready */
2795   if(amstrad_system_type != SYSTEM_GX4000)
2750   if(state->system_type != SYSTEM_GX4000)
27962751   {
27972752      running_device *printer = device->machine->device("centronics");
27982753      data |= centronics_busy_r(printer) << 6;
27992754   }
28002755/* Set b4-b1 50Hz/60Hz state and manufacturer name defined by links on PCB */
2801   data |= (ppi_port_inputs[amstrad_ppi_PortB] & 0x1e);
2756   data |= (state->ppi_port_inputs[amstrad_ppi_PortB] & 0x1e);
28022757
28032758/*  Set b0 with VSync state from the CRTC */
2804   data |= gate_array.vsync;
2759   data |= state->gate_array.vsync;
28052760
2806   if(aleste_mode & 0x04)
2761   if(state->aleste_mode & 0x04)
28072762   {
2808      if(aleste_fdc_int == 0)
2763      if(state->aleste_fdc_int == 0)
28092764         data &= ~0x02;
28102765      else
28112766         data |= 0x02;
r9648r9649
283127860                |*/
28322787
28332788/* previous_ppi_portc_w value */
2834static int previous_ppi_portc_w;
28352789
28362790WRITE8_DEVICE_HANDLER ( amstrad_ppi_portc_w )
28372791{
2792   amstrad_state *state = device->machine->driver_data<amstrad_state>();
28382793   int changed_data;
28392794
2840   previous_ppi_portc_w = ppi_port_outputs[amstrad_ppi_PortC];
2795   state->previous_ppi_portc_w = state->ppi_port_outputs[amstrad_ppi_PortC];
28412796/* Write the data to Port C */
2842   changed_data = previous_ppi_portc_w^data;
2797   changed_data = state->previous_ppi_portc_w^data;
28432798
2844   ppi_port_outputs[amstrad_ppi_PortC] = data;
2799   state->ppi_port_outputs[amstrad_ppi_PortC] = data;
28452800
28462801/* get b7 and b6 (PSG Function Selected */
2847   amstrad_Psg_FunctionSelected = ((data & 0xC0)>>6);
2802   state->Psg_FunctionSelected = ((data & 0xC0)>>6);
28482803
28492804   /* MC146818 function */
2850   aleste_rtc_function = data & 0x07;
2805   state->aleste_rtc_function = data & 0x07;
28512806
28522807   /* Perform PSG function */
28532808   update_psg(device->machine);
28542809
28552810   /* b5 Cassette Write data */
2856   if(amstrad_system_type != SYSTEM_GX4000)
2811   if(state->system_type != SYSTEM_GX4000)
28572812   {
28582813      if ((changed_data & 0x20) != 0)
28592814      {
r9648r9649
28632818   }
28642819
28652820   /* b4 Cassette Motor Control */
2866   if(amstrad_system_type != SYSTEM_GX4000)
2821   if(state->system_type != SYSTEM_GX4000)
28672822   {
28682823      if ((changed_data & 0x10) != 0)
28692824      {
r9648r9649
28852840/* read PSG port A */
28862841READ8_HANDLER ( amstrad_psg_porta_read )
28872842{
2843   amstrad_state *state = space->machine->driver_data<amstrad_state>();
28882844   /* Read CPC Keyboard
28892845   If keyboard matrix line 11-14 are selected, the byte is always &ff.
28902846   After testing on a real CPC, it is found that these never change, they always return &FF. */
r9648r9649
28952851      "keyboard_row_10"
28962852   };
28972853
2898   if ( ( ppi_port_outputs[amstrad_ppi_PortC] & 0x0F ) > 10)
2854   if ( ( state->ppi_port_outputs[amstrad_ppi_PortC] & 0x0F ) > 10)
28992855   {
29002856      return 0xFF;
29012857   }
29022858   else
29032859   {
2904      if(aleste_mode == 0x08 && ( ppi_port_outputs[amstrad_ppi_PortC] & 0x0F ) == 10)
2860      if(state->aleste_mode == 0x08 && ( state->ppi_port_outputs[amstrad_ppi_PortC] & 0x0F ) == 10)
29052861         return 0xff;
29062862
2907      return input_port_read_safe(space->machine, keynames[ppi_port_outputs[amstrad_ppi_PortC] & 0x0F], 0) & 0xFF;
2863      return input_port_read_safe(space->machine, keynames[state->ppi_port_outputs[amstrad_ppi_PortC] & 0x0F], 0) & 0xFF;
29082864   }
29092865}
29102866
r9648r9649
29142870/* this ensures that the next interrupt is no closer than 32 lines */
29152871static IRQ_CALLBACK(amstrad_cpu_acknowledge_int)
29162872{
2873   amstrad_state *state = device->machine->driver_data<amstrad_state>();
29172874   // DMA interrupts can be automatically cleared if bit 0 of &6805 is set to 0
2918   if( asic.enabled && amstrad_plus_irq_cause != 0x06 && asic.dma_clear & 0x01)
2875   if( state->asic.enabled && state->plus_irq_cause != 0x06 && state->asic.dma_clear & 0x01)
29192876   {
2920      logerror("IRQ: Not cleared, IRQ was called by DMA [%i]\n",amstrad_plus_irq_cause);
2921      asic.ram[0x2c0f] &= ~0x80;  // not a raster interrupt, so this bit is reset
2922      return (asic.ram[0x2805] & 0xf8) | amstrad_plus_irq_cause;
2877      logerror("IRQ: Not cleared, IRQ was called by DMA [%i]\n",state->plus_irq_cause);
2878      state->asic.ram[0x2c0f] &= ~0x80;  // not a raster interrupt, so this bit is reset
2879      return (state->asic.ram[0x2805] & 0xf8) | state->plus_irq_cause;
29232880   }
29242881   cputag_set_input_line(device->machine,"maincpu", 0, CLEAR_LINE);
2925   gate_array.hsync_counter &= 0x1F;
2926   if ( asic.enabled )
2882   state->gate_array.hsync_counter &= 0x1F;
2883   if ( state->asic.enabled )
29272884   {
2928      if(amstrad_plus_irq_cause == 6)  // bit 7 is set "if last interrupt acknowledge cycle was caused by a raster interrupt"
2929         asic.ram[0x2c0f] |= 0x80;
2885      if(state->plus_irq_cause == 6)  // bit 7 is set "if last interrupt acknowledge cycle was caused by a raster interrupt"
2886         state->asic.ram[0x2c0f] |= 0x80;
29302887      else
29312888      {
2932         asic.ram[0x2c0f] &= ~0x80;
2933         asic.ram[0x2c0f] &= (0x40 >> amstrad_plus_irq_cause/2);
2889         state->asic.ram[0x2c0f] &= ~0x80;
2890         state->asic.ram[0x2c0f] &= (0x40 >> state->plus_irq_cause/2);
29342891      }
2935      return (asic.ram[0x2805] & 0xf8) | amstrad_plus_irq_cause;
2892      return (state->asic.ram[0x2805] & 0xf8) | state->plus_irq_cause;
29362893   }
29372894   return 0xFF;
29382895}
r9648r9649
30603017
30613018static void amstrad_common_init(running_machine *machine)
30623019{
3020   amstrad_state *state = machine->driver_data<amstrad_state>();
30633021   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
30643022
3065   aleste_mode = 0;
3023   state->aleste_mode = 0;
30663024
3067   gate_array.mrer = 0;
3068   gate_array.vsync = 0;
3069   gate_array.hsync = 0;
3070   amstrad_GateArray_RamConfiguration = 0;
3071   gate_array.hsync_counter = 2;
3025   state->gate_array.mrer = 0;
3026   state->gate_array.vsync = 0;
3027   state->gate_array.hsync = 0;
3028   state->GateArray_RamConfiguration = 0;
3029   state->gate_array.hsync_counter = 2;
30723030
30733031   memory_install_read_bank(space, 0x0000, 0x1fff, 0, 0, "bank1");
30743032   memory_install_read_bank(space, 0x2000, 0x3fff, 0, 0, "bank2");
r9648r9649
30953053   memory_install_write_bank(space, 0xe000, 0xffff, 0, 0, "bank16");
30963054
30973055   space->machine->device("maincpu")->reset();
3098   if ( amstrad_system_type == SYSTEM_CPC || amstrad_system_type == SYSTEM_ALESTE )
3056   if ( state->system_type == SYSTEM_CPC || state->system_type == SYSTEM_ALESTE )
30993057      cpu_set_input_line_vector(machine->device("maincpu"), 0, 0xff);
31003058   else
31013059      cpu_set_input_line_vector(machine->device("maincpu"), 0, 0x00);
r9648r9649
31553113
31563114MACHINE_START( amstrad )
31573115{
3116   amstrad_state *state = machine->driver_data<amstrad_state>();
31583117   multiface_init(machine);
3159   amstrad_system_type = SYSTEM_CPC;
3118   state->system_type = SYSTEM_CPC;
31603119}
31613120
31623121
31633122MACHINE_RESET( amstrad )
31643123{
3124   amstrad_state *state = machine->driver_data<amstrad_state>();
31653125   int i;
31663126   UINT8 *rom = memory_region(machine, "maincpu");
31673127
31683128   for (i=0; i<256; i++)
31693129   {
3170      Amstrad_ROM_Table[i] = &rom[0x014000];
3130      state->Amstrad_ROM_Table[i] = &rom[0x014000];
31713131   }
31723132
3173   Amstrad_ROM_Table[7] = &rom[0x018000];
3133   state->Amstrad_ROM_Table[7] = &rom[0x018000];
31743134   amstrad_common_init(machine);
31753135   amstrad_reset_machine(machine);
31763136//  amstrad_init_palette(machine);
31773137
3178   gate_array.de = 0;
3179   gate_array.draw_p = NULL;
3180   gate_array.hsync = 0;
3181   gate_array.vsync = 0;
3138   state->gate_array.de = 0;
3139   state->gate_array.draw_p = NULL;
3140   state->gate_array.hsync = 0;
3141   state->gate_array.vsync = 0;
31823142
31833143   timer_set( machine, attotime_zero, NULL, 0, cb_set_resolution );
31843144}
r9648r9649
31863146
31873147MACHINE_START( plus )
31883148{
3189   asic.ram = memory_region(machine, "user1");  // 16kB RAM for ASIC, memory-mapped registers.
3190   amstrad_system_type = SYSTEM_PLUS;
3149   amstrad_state *state = machine->driver_data<amstrad_state>();
3150   state->asic.ram = memory_region(machine, "user1");  // 16kB RAM for ASIC, memory-mapped registers.
3151   state->system_type = SYSTEM_PLUS;
31913152}
31923153
31933154
31943155MACHINE_RESET( plus )
31953156{
3157   amstrad_state *state = machine->driver_data<amstrad_state>();
31963158   int i;
31973159   UINT8 *rom = memory_region(machine, "maincpu");
31983160
31993161   for (i=0; i<128; i++)  // fill ROM table
32003162   {
3201      Amstrad_ROM_Table[i] = &rom[0x4000];  // BASIC in system cart
3163      state->Amstrad_ROM_Table[i] = &rom[0x4000];  // BASIC in system cart
32023164   }
32033165   for(i=128;i<160;i++)
32043166   {
3205      Amstrad_ROM_Table[i] = &rom[(i-128)*0x4000];
3167      state->Amstrad_ROM_Table[i] = &rom[(i-128)*0x4000];
32063168   }
3207   Amstrad_ROM_Table[7] = &rom[0xc000];  // AMSDOS in system cart
3169   state->Amstrad_ROM_Table[7] = &rom[0xc000];  // AMSDOS in system cart
32083170
3209   asic.enabled = 0;
3210   asic.seqptr = 0;
3211   asic.pri = 0;  // disable PRI
3212   asic.dma_status = 0;  // disable all DMA channels
3213   asic.dma_addr[0] = 0;
3214   asic.dma_prescaler[0] = 0;
3215   asic.dma_addr[1] = 0;
3216   asic.dma_prescaler[1] = 0;
3217   asic.dma_addr[2] = 0;
3218   asic.dma_prescaler[2] = 0;
3219   asic.dma_clear = 1;  // by default, DMA interrupts must be cleared by writing to the DSCR (&6c0f)
3220   amstrad_plus_irq_cause = 6;
3171   state->asic.enabled = 0;
3172   state->asic.seqptr = 0;
3173   state->asic.pri = 0;  // disable PRI
3174   state->asic.dma_status = 0;  // disable all DMA channels
3175   state->asic.dma_addr[0] = 0;
3176   state->asic.dma_prescaler[0] = 0;
3177   state->asic.dma_addr[1] = 0;
3178   state->asic.dma_prescaler[1] = 0;
3179   state->asic.dma_addr[2] = 0;
3180   state->asic.dma_prescaler[2] = 0;
3181   state->asic.dma_clear = 1;  // by default, DMA interrupts must be cleared by writing to the DSCR (&6c0f)
3182   state->plus_irq_cause = 6;
32213183
32223184   amstrad_common_init(machine);
32233185   amstrad_reset_machine(machine);
3224   asic.ram[0x2805] = 0x01;  // interrupt vector is undefined at startup, except that bit 0 is always 1.
3186   state->asic.ram[0x2805] = 0x01;  // interrupt vector is undefined at startup, except that bit 0 is always 1.
32253187   AmstradCPC_GA_SetRamConfiguration(machine);
32263188   amstrad_GateArray_write(machine, 0x081); // Epyx World of Sports requires upper ROM to be enabled by default
32273189
r9648r9649
32313193
32323194MACHINE_START( gx4000 )
32333195{
3234   asic.ram = memory_region(machine, "user1");  // 16kB RAM for ASIC, memory-mapped registers.
3235   amstrad_system_type = SYSTEM_GX4000;
3196   amstrad_state *state = machine->driver_data<amstrad_state>();
3197   state->asic.ram = memory_region(machine, "user1");  // 16kB RAM for ASIC, memory-mapped registers.
3198   state->system_type = SYSTEM_GX4000;
32363199}
32373200
32383201MACHINE_RESET( gx4000 )
32393202{
3203   amstrad_state *state = machine->driver_data<amstrad_state>();
32403204   int i;
32413205   UINT8 *rom = memory_region(machine, "maincpu");
32423206
32433207   for (i=0; i<128; i++)  // fill ROM table
32443208   {
3245      Amstrad_ROM_Table[i] = &rom[0x4000];
3209      state->Amstrad_ROM_Table[i] = &rom[0x4000];
32463210   }
32473211   for(i=128;i<160;i++)
32483212   {
3249      Amstrad_ROM_Table[i] = &rom[(i-128)*0x4000];
3213      state->Amstrad_ROM_Table[i] = &rom[(i-128)*0x4000];
32503214   }
3251   Amstrad_ROM_Table[7] = &rom[0xc000];
3215   state->Amstrad_ROM_Table[7] = &rom[0xc000];
32523216
3253   asic.enabled = 0;
3254   asic.seqptr = 0;
3255   asic.pri = 0;  // disable PRI
3256   asic.dma_status = 0;  // disable all DMA channels
3257   asic.dma_addr[0] = 0;
3258   asic.dma_prescaler[0] = 0;
3259   asic.dma_addr[1] = 0;
3260   asic.dma_prescaler[1] = 0;
3261   asic.dma_addr[2] = 0;
3262   asic.dma_prescaler[2] = 0;
3263   asic.dma_clear = 1;  // by default, DMA interrupts must be cleared by writing to the DSCR (&6c0f)
3264   amstrad_plus_irq_cause = 6;
3217   state->asic.enabled = 0;
3218   state->asic.seqptr = 0;
3219   state->asic.pri = 0;  // disable PRI
3220   state->asic.dma_status = 0;  // disable all DMA channels
3221   state->asic.dma_addr[0] = 0;
3222   state->asic.dma_prescaler[0] = 0;
3223   state->asic.dma_addr[1] = 0;
3224   state->asic.dma_prescaler[1] = 0;
3225   state->asic.dma_addr[2] = 0;
3226   state->asic.dma_prescaler[2] = 0;
3227   state->asic.dma_clear = 1;  // by default, DMA interrupts must be cleared by writing to the DSCR (&6c0f)
3228   state->plus_irq_cause = 6;
32653229
32663230   amstrad_common_init(machine);
32673231   amstrad_reset_machine(machine);
3268   asic.ram[0x2805] = 0x01;  // interrupt vector is undefined at startup, except that bit 0 is always 1.
3232   state->asic.ram[0x2805] = 0x01;  // interrupt vector is undefined at startup, except that bit 0 is always 1.
32693233   AmstradCPC_GA_SetRamConfiguration(machine);
32703234   amstrad_GateArray_write(machine, 0x081); // Epyx World of Sports requires upper ROM to be enabled by default
32713235   //  multiface_init();
r9648r9649
32753239
32763240MACHINE_START( kccomp )
32773241{
3242   amstrad_state *state = machine->driver_data<amstrad_state>();
32783243   multiface_init(machine);
3279   amstrad_system_type = SYSTEM_CPC;
3244   state->system_type = SYSTEM_CPC;
32803245}
32813246
32823247
32833248MACHINE_RESET( kccomp )
32843249{
3250   amstrad_state *state = machine->driver_data<amstrad_state>();
32853251   int i;
32863252   UINT8 *rom = memory_region(machine, "maincpu");
32873253
32883254   for (i=0; i<256; i++)
32893255   {
3290      Amstrad_ROM_Table[i] = &rom[0x014000];
3256      state->Amstrad_ROM_Table[i] = &rom[0x014000];
32913257   }
32923258
32933259   amstrad_common_init(machine);
r9648r9649
32993265    When the program has been transfered, it will be executed. This
33003266    is not supported in the driver */
33013267   /* bit 3,4 are tied to +5V, bit 2 is tied to 0V */
3302   ppi_port_inputs[amstrad_ppi_PortB] = (1<<4) | (1<<3) | 2;
3268   state->ppi_port_inputs[amstrad_ppi_PortB] = (1<<4) | (1<<3) | 2;
33033269}
33043270
33053271
33063272MACHINE_START( aleste )
33073273{
3274   amstrad_state *state = machine->driver_data<amstrad_state>();
33083275   multiface_init(machine);
3309   amstrad_system_type = SYSTEM_ALESTE;
3276   state->system_type = SYSTEM_ALESTE;
33103277}
33113278
33123279MACHINE_RESET( aleste )
33133280{
3281   amstrad_state *state = machine->driver_data<amstrad_state>();
33143282   int i;
33153283   UINT8 *rom = memory_region(machine, "maincpu");
33163284
33173285   for (i=0; i<256; i++)
33183286   {
3319      Amstrad_ROM_Table[i] = &rom[0x014000];
3287      state->Amstrad_ROM_Table[i] = &rom[0x014000];
33203288   }
33213289
3322   Amstrad_ROM_Table[3] = &rom[0x01c000];  // MSX-DOS / BIOS
3323   Amstrad_ROM_Table[7] = &rom[0x018000];  // AMSDOS
3290   state->Amstrad_ROM_Table[3] = &rom[0x01c000];  // MSX-DOS / BIOS
3291   state->Amstrad_ROM_Table[7] = &rom[0x018000];  // AMSDOS
33243292   amstrad_common_init(machine);
33253293   amstrad_reset_machine(machine);
33263294
src/mess/machine/apple2gs.c
r9648r9649
132132#define IRQ_INTEN_VBL      0x40
133133#define IRQ_DOC         0x80
134134
135UINT8 *apple2gs_slowmem;
136UINT8 apple2gs_newvideo;
137UINT8 apple2gs_docram[64*1024];
138135
139static UINT8 apple2gs_vgcint;
140static UINT8 apple2gs_langsel;
141static UINT8 apple2gs_sltromsel;
142static UINT8 apple2gs_cyareg;
143static UINT8 apple2gs_inten;
144static UINT8 apple2gs_intflag;
145static UINT8 apple2gs_shadow;
146static UINT8 apple2gs_pending_irqs;
147static UINT8 apple2gs_mouse_x;
148static UINT8 apple2gs_mouse_y;
149static INT8  apple2gs_mouse_dx;
150static INT8  apple2gs_mouse_dy;
151static running_device *apple2gs_cur_slot6_image;
152static emu_timer *apple2gs_scanline_timer;
153static emu_timer *apple2gs_clock_timer;
154static emu_timer *apple2gs_qsecond_timer;
155136
156137
157138/* -----------------------------------------------------------------------
158139 * Apple IIgs clock
159140 * ----------------------------------------------------------------------- */
160141
161typedef enum
162{
163   CLOCKMODE_IDLE,
164   CLOCKMODE_TIME,
165   CLOCKMODE_INTERNALREGS,
166   CLOCKMODE_BRAM1,
167   CLOCKMODE_BRAM2
168} apple2gs_clock_mode;
169142
170static UINT8 clock_data;
171static UINT8 clock_control;
172static UINT8 clock_read;
173static UINT8 clock_reg1;
174static apple2gs_clock_mode clock_mode;
175static UINT32 clock_curtime;            /* number of seconds since 1-Jan-1904 */
176static seconds_t clock_curtime_interval;   /* second index at which clock_curtime is valid */
177static UINT8 clock_bram[256];
178143
179
180144static void process_clock(running_machine *machine)
181145{
146   apple2gs_state *state = machine->driver_data<apple2gs_state>();
182147   UINT8 operation;
183148   seconds_t current_interval;
184149
185   /* update clock_curtime */
150   /* update state->clock_curtime */
186151   current_interval = timer_get_time(machine).seconds;
187   clock_curtime += current_interval - clock_curtime_interval;
188   clock_curtime_interval = current_interval;
152   state->clock_curtime += current_interval - state->clock_curtime_interval;
153   state->clock_curtime_interval = current_interval;
189154
190   switch(clock_mode)
155   switch(state->clock_mode)
191156   {
192157      case CLOCKMODE_IDLE:
193         clock_read = (clock_data >> 7);
194         clock_reg1 = (clock_data >> 2) & 0x03;
195         operation = (clock_data >> 4) & 0x07;
158         state->clock_read = (state->clock_data >> 7);
159         state->clock_reg1 = (state->clock_data >> 2) & 0x03;
160         operation = (state->clock_data >> 4) & 0x07;
196161
197         if ((clock_data & 0x40) == 0x00)
162         if ((state->clock_data & 0x40) == 0x00)
198163         {
199164            switch(operation)
200165            {
201166               case 0x00:
202167                  /* read/write seconds register */
203                  clock_mode = CLOCKMODE_TIME;
168                  state->clock_mode = CLOCKMODE_TIME;
204169                  break;
205170
206171               case 0x03:
207172                  /* internal registers */
208                  if (clock_reg1 & 0x02)
173                  if (state->clock_reg1 & 0x02)
209174                  {
210                     clock_mode = CLOCKMODE_BRAM2;
211                     clock_reg1 = (clock_data & 0x07) << 5;
175                     state->clock_mode = CLOCKMODE_BRAM2;
176                     state->clock_reg1 = (state->clock_data & 0x07) << 5;
212177                  }
213178                  else
214179                  {
215                     clock_mode = CLOCKMODE_INTERNALREGS;
180                     state->clock_mode = CLOCKMODE_INTERNALREGS;
216181                  }
217182                  break;
218183
r9648r9649
224189         break;
225190
226191      case CLOCKMODE_BRAM1:
227         if (clock_read)
228            clock_data = clock_bram[clock_reg1];
192         if (state->clock_read)
193            state->clock_data = state->clock_bram[state->clock_reg1];
229194         else
230            clock_bram[clock_reg1] = clock_data;
231         clock_mode = CLOCKMODE_IDLE;
195            state->clock_bram[state->clock_reg1] = state->clock_data;
196         state->clock_mode = CLOCKMODE_IDLE;
232197         break;
233198
234199      case CLOCKMODE_BRAM2:
235         clock_reg1 |= (clock_data >> 2) & 0x1F;
236         clock_mode = CLOCKMODE_BRAM1;
200         state->clock_reg1 |= (state->clock_data >> 2) & 0x1F;
201         state->clock_mode = CLOCKMODE_BRAM1;
237202         break;
238203
239204      case CLOCKMODE_INTERNALREGS:
240         switch (clock_reg1)
205         switch (state->clock_reg1)
241206         {
242207            case 0x00:
243208               /* test register */
r9648r9649
247212               /* write protect register */
248213               break;
249214         }
250         clock_mode = CLOCKMODE_IDLE;
215         state->clock_mode = CLOCKMODE_IDLE;
251216         break;
252217
253218      case CLOCKMODE_TIME:
254         if (clock_data & 0x40)
219         if (state->clock_data & 0x40)
255220         {
256            clock_data = clock_curtime >> (clock_reg1 * 8);
221            state->clock_data = state->clock_curtime >> (state->clock_reg1 * 8);
257222         }
258223         else
259224         {
260            clock_curtime &= ~(0xFF << (clock_reg1 * 8));
261            clock_curtime |= clock_data << (clock_reg1 * 8);
225            state->clock_curtime &= ~(0xFF << (state->clock_reg1 * 8));
226            state->clock_curtime |= state->clock_data << (state->clock_reg1 * 8);
262227         }
263         clock_mode = CLOCKMODE_IDLE;
228         state->clock_mode = CLOCKMODE_IDLE;
264229         break;
265230
266231      default:
r9648r9649
273238
274239NVRAM_HANDLER( apple2gs )
275240{
241   apple2gs_state *state = machine->driver_data<apple2gs_state>();
276242   if (read_or_write)
277243   {
278      mame_fwrite(file, clock_bram, sizeof(clock_bram));
244      mame_fwrite(file, state->clock_bram, sizeof(state->clock_bram));
279245   }
280246   else if (file)
281247   {
282      mame_fread(file, clock_bram, sizeof(clock_bram));
248      mame_fread(file, state->clock_bram, sizeof(state->clock_bram));
283249   }
284250   else
285251   {
286      memset(clock_bram, 0x00, sizeof(clock_bram));
252      memset(state->clock_bram, 0x00, sizeof(state->clock_bram));
287253   }
288254}
289255
r9648r9649
311277
312278static void apple2gs_add_irq(running_machine *machine, UINT8 irq_mask)
313279{
314   if ((apple2gs_pending_irqs & irq_mask) == 0x00)
280   apple2gs_state *state = machine->driver_data<apple2gs_state>();
281   if ((state->pending_irqs & irq_mask) == 0x00)
315282   {
316283      if (LOG_IRQ)
317284         logerror("apple2gs_add_irq(): adding %s\n", apple2gs_irq_name(irq_mask));
318285
319      apple2gs_pending_irqs |= irq_mask;
320      cputag_set_input_line(machine, "maincpu", G65816_LINE_IRQ, apple2gs_pending_irqs ? ASSERT_LINE : CLEAR_LINE);
286      state->pending_irqs |= irq_mask;
287      cputag_set_input_line(machine, "maincpu", G65816_LINE_IRQ, state->pending_irqs ? ASSERT_LINE : CLEAR_LINE);
321288   }
322289}
323290
r9648r9649
325292
326293static void apple2gs_remove_irq(running_machine *machine, UINT8 irq_mask)
327294{
328   if (apple2gs_pending_irqs & irq_mask)
295   apple2gs_state *state = machine->driver_data<apple2gs_state>();
296   if (state->pending_irqs & irq_mask)
329297   {
330298      if (LOG_IRQ)
331299         logerror("apple2gs_remove_irq(): removing %s\n", apple2gs_irq_name(irq_mask));
332300
333      apple2gs_pending_irqs &= ~irq_mask;
334      cputag_set_input_line(machine, "maincpu", G65816_LINE_IRQ, apple2gs_pending_irqs ? ASSERT_LINE : CLEAR_LINE);
301      state->pending_irqs &= ~irq_mask;
302      cputag_set_input_line(machine, "maincpu", G65816_LINE_IRQ, state->pending_irqs ? ASSERT_LINE : CLEAR_LINE);
335303   }
336304}
337305
r9648r9649
351319/* Clock interrupt */
352320static TIMER_CALLBACK( apple2gs_clock_tick )
353321{
354   if ((apple2gs_vgcint & 0x04) && !(apple2gs_vgcint & 0x40))
322   apple2gs_state *state = machine->driver_data<apple2gs_state>();
323   if ((state->vgcint & 0x04) && !(state->vgcint & 0x40))
355324   {
356      apple2gs_vgcint |= 0xc0;
325      state->vgcint |= 0xc0;
357326      apple2gs_add_irq(machine, IRQ_VGC_SECOND);
358327   }
359328}
r9648r9649
362331/* Quarter-second interrupt */
363332static TIMER_CALLBACK( apple2gs_qsecond_tick )
364333{
365   if ((apple2gs_inten & 0x10) && !(apple2gs_intflag & 0x10))
334   apple2gs_state *state = machine->driver_data<apple2gs_state>();
335   if ((state->inten & 0x10) && !(state->intflag & 0x10))
366336   {
367      apple2gs_intflag |= 0x10;
337      state->intflag |= 0x10;
368338      apple2gs_add_irq(machine, IRQ_INTEN_QSECOND);
369339   }
370340}
r9648r9649
374344 * ADB
375345 * ----------------------------------------------------------------------- */
376346
377typedef enum
378{
379   ADBSTATE_IDLE,
380   ADBSTATE_INCOMMAND,
381   ADBSTATE_INRESPONSE
382} adbstate_t;
383347
384static adbstate_t adb_state;
385static UINT8 adb_command;
386static UINT8 adb_mode;
387static UINT8 adb_kmstatus;
388static UINT8 adb_latent_result;
389static INT32 adb_command_length;
390static INT32 adb_command_pos;
391static UINT8 adb_command_bytes[8];
392static UINT8 adb_response_bytes[8];
393static UINT8 adb_response_length;
394static INT32 adb_response_pos;
395static UINT8 adb_memory[0x100];
396static int adb_address_keyboard;
397static int adb_address_mouse;
398348
399
400static UINT8 adb_read_memory(UINT32 address)
349static UINT8 adb_read_memory(apple2gs_state *state, UINT32 address)
401350{
402   if (address < ARRAY_LENGTH(adb_memory))
403      return adb_memory[address];
351   if (address < ARRAY_LENGTH(state->adb_memory))
352      return state->adb_memory[address];
404353   else
405354      return 0x00;
406355}
407356
408357
409358
410static void adb_write_memory(UINT32 address, UINT8 data)
359static void adb_write_memory(apple2gs_state *state, UINT32 address, UINT8 data)
411360{
412   if (address < ARRAY_LENGTH(adb_memory))
413      adb_memory[address] = data;
361   if (address < ARRAY_LENGTH(state->adb_memory))
362      state->adb_memory[address] = data;
414363}
415364
416365
417366
418static void adb_set_mode(UINT8 mode)
367static void adb_set_mode(apple2gs_state *state, UINT8 mode)
419368{
420   adb_mode = mode;
369   state->adb_mode = mode;
421370}
422371
423372
r9648r9649
429378
430379
431380
432static void adb_post_response(const UINT8 *bytes, size_t length)
381static void adb_post_response(apple2gs_state *state, const UINT8 *bytes, size_t length)
433382{
434   assert(length < ARRAY_LENGTH(adb_response_bytes));
435   memcpy(adb_response_bytes, bytes, length);
383   assert(length < ARRAY_LENGTH(state->adb_response_bytes));
384   memcpy(state->adb_response_bytes, bytes, length);
436385
437   adb_state = ADBSTATE_INRESPONSE;
438   adb_response_length = length;
439   adb_response_pos = 0;
386   state->adb_state = ADBSTATE_INRESPONSE;
387   state->adb_response_length = length;
388   state->adb_response_pos = 0;
440389}
441390
442391
443392
444static void adb_post_response_1(UINT8 b)
393static void adb_post_response_1(apple2gs_state *state, UINT8 b)
445394{
446   adb_post_response(&b, 1);
395   adb_post_response(state, &b, 1);
447396}
448397
449398
450399
451static void adb_post_response_2(UINT8 b1, UINT8 b2)
400static void adb_post_response_2(apple2gs_state *state, UINT8 b1, UINT8 b2)
452401{
453402   UINT8 b[2];
454403   b[0] = b1;
455404   b[1] = b2;
456   adb_post_response(b, 2);
405   adb_post_response(state, b, 2);
457406}
458407
459408
460409
461static void adb_do_command(void)
410static void adb_do_command(apple2gs_state *state)
462411{
463412   int device;
464413   UINT32 address;
465414   UINT8 val;
466415
467   adb_state = ADBSTATE_IDLE;
416   state->adb_state = ADBSTATE_IDLE;
468417   if (LOG_ADB)
469      logerror("adb_do_command(): adb_command=0x%02x\n", adb_command);
418      logerror("adb_do_command(): state->adb_command=0x%02x\n", state->adb_command);
470419
471   switch(adb_command)
420   switch(state->adb_command)
472421   {
473422      case 0x00:   /* ??? */
474423         break;
r9648r9649
477426         break;
478427
479428      case 0x04:   /* set modes */
480         adb_set_mode(adb_mode | adb_command_bytes[0]);
429         adb_set_mode(state, state->adb_mode | state->adb_command_bytes[0]);
481430         break;
482431
483432      case 0x05:   /* clear modes */
484         adb_set_mode(adb_mode & ~adb_command_bytes[0]);
433         adb_set_mode(state, state->adb_mode & ~state->adb_command_bytes[0]);
485434         break;
486435
487436      case 0x06:   /* set config */
488         adb_set_config(adb_command_bytes[0], adb_command_bytes[1], adb_command_bytes[2]);
437         adb_set_config(state->adb_command_bytes[0], state->adb_command_bytes[1], state->adb_command_bytes[2]);
489438         break;
490439
491440      case 0x07:   /* synchronize */
492         adb_set_mode(adb_command_bytes[0]);
493         adb_set_config(adb_command_bytes[1], adb_command_bytes[2], adb_command_bytes[3]);
441         adb_set_mode(state, state->adb_command_bytes[0]);
442         adb_set_config(state->adb_command_bytes[1], state->adb_command_bytes[2], state->adb_command_bytes[3]);
494443         break;
495444
496445      case 0x08:   /* write memory */
497         address = adb_command_bytes[0];
498         val = adb_command_bytes[1];
499         adb_write_memory(address, val);
446         address = state->adb_command_bytes[0];
447         val = state->adb_command_bytes[1];
448         adb_write_memory(state, address, val);
500449         break;
501450
502451      case 0x09:   /* read memory */
503         address = (adb_command_bytes[1] << 8) | adb_command_bytes[0];
504         adb_post_response_1(adb_read_memory(address));
452         address = (state->adb_command_bytes[1] << 8) | state->adb_command_bytes[0];
453         adb_post_response_1(state, adb_read_memory(state, address));
505454         break;
506455
507456      case 0x0d:   /* get version */
508         adb_post_response_1(0x06);
457         adb_post_response_1(state, 0x06);
509458         break;
510459
511460      case 0x0e:   /* read available charsets */
512         adb_post_response_2(0x01, 0x00);
461         adb_post_response_2(state, 0x01, 0x00);
513462         break;
514463
515464      case 0x0f:   /* read available layouts */
516         adb_post_response_2(0x01, 0x00);
465         adb_post_response_2(state, 0x01, 0x00);
517466         break;
518467
519468      case 0x12:   /* mystery command 0x12 */
r9648r9649
525474      case 0xb8: case 0xb9: case 0xba: case 0xbb:
526475      case 0xbc: case 0xbd: case 0xbe: case 0xbf:
527476         /* send data to device */
528         device = adb_command & 0x0f;
529         if (device == adb_address_keyboard)
477         device = state->adb_command & 0x0f;
478         if (device == state->adb_address_keyboard)
530479         {
531480         }
532         else if (device == adb_address_mouse)
481         else if (device == state->adb_address_mouse)
533482         {
534483         }
535484         break;
536485
537486      default:
538         fatalerror("ADB command 0x%02x unimplemented", adb_command);
487         fatalerror("ADB command 0x%02x unimplemented", state->adb_command);
539488         break;
540489   }
541   adb_kmstatus |= 0x20;
490   state->adb_kmstatus |= 0x20;
542491}
543492
544493
545494
546static UINT8 adb_read_datareg(void)
495static UINT8 adb_read_datareg(apple2gs_state *state)
547496{
548497   UINT8 result;
549498
550   switch(adb_state)
499   switch(state->adb_state)
551500   {
552501      case ADBSTATE_INRESPONSE:
553         result = adb_response_bytes[adb_response_pos++];
554         if (adb_response_pos >= adb_response_length)
502         result = state->adb_response_bytes[state->adb_response_pos++];
503         if (state->adb_response_pos >= state->adb_response_length)
555504         {
556            adb_state = ADBSTATE_IDLE;
557            adb_latent_result = result;
558            adb_kmstatus &= ~0x20;
505            state->adb_state = ADBSTATE_IDLE;
506            state->adb_latent_result = result;
507            state->adb_kmstatus &= ~0x20;
559508         }
560509         break;
561510
562511      default:
563         result = 0; //adb_latent_result & 0x7f;
512         result = 0; //state->adb_latent_result & 0x7f;
564513         break;
565514   }
566515
r9648r9649
574523
575524static void adb_write_datareg(running_machine *machine, UINT8 data)
576525{
526   apple2gs_state *state = machine->driver_data<apple2gs_state>();
577527   if (LOG_ADB)
578528      logerror("adb_write_datareg(): data=0x%02x\n", data);
579529
580   switch(adb_state)
530   switch(state->adb_state)
581531   {
582532      case ADBSTATE_IDLE:
583         adb_command = data;
584         adb_command_length = 0;
585         adb_command_pos = 0;
533         state->adb_command = data;
534         state->adb_command_length = 0;
535         state->adb_command_pos = 0;
586536
587537         switch(data)
588538         {
r9648r9649
592542               break;
593543
594544            case 0x03:   /* flush keyboard buffer */
595               adb_command_length = 0;
545               state->adb_command_length = 0;
596546               break;
597547
598548            case 0x04:   /* set modes */
599549            case 0x05:   /* clear modes */
600               adb_command_length = 1;
550               state->adb_command_length = 1;
601551               break;
602552
603553            case 0x06:   /* set config */
604               adb_command_length = 3;
554               state->adb_command_length = 3;
605555               break;
606556
607557            case 0x07:   /* synchronize */
608558               if (memory_region_length(machine, "maincpu") == 0x40000)   /* HACK */
609                  adb_command_length = 8;
559                  state->adb_command_length = 8;
610560               else
611                  adb_command_length = 4;
561                  state->adb_command_length = 4;
612562               break;
613563
614564            case 0x08:   /* write memory */
615565            case 0x09:   /* read memory */
616               adb_command_length = 2;
566               state->adb_command_length = 2;
617567               break;
618568
619569            case 0x0d:   /* get version */
620               adb_command_length = 0;
570               state->adb_command_length = 0;
621571               break;
622572
623573            case 0x0e:   /* read available charsets */
624               adb_command_length = 0;
625               adb_state = ADBSTATE_INCOMMAND;   /* HACK */
574               state->adb_command_length = 0;
575               state->adb_state = ADBSTATE_INCOMMAND;   /* HACK */
626576               break;
627577
628578            case 0x0f:   /* read available layouts */
629               adb_command_length = 0;
630               adb_state = ADBSTATE_INCOMMAND;   /* HACK */
579               state->adb_command_length = 0;
580               state->adb_state = ADBSTATE_INCOMMAND;   /* HACK */
631581               break;
632582
633583            case 0x12:   /* mystery command 0x12 */
634584            case 0x13:   /* mystery command 0x13 */
635               adb_command_length = 2;
585               state->adb_command_length = 2;
636586               break;
637587
638588            case 0x70:   /* disable SRQ device 0 */
r9648r9649
647597            case 0xb8: case 0xb9: case 0xba: case 0xbb:
648598            case 0xbc: case 0xbd: case 0xbe: case 0xbf:
649599               /* send data to device */
650               adb_command_length = 2;
600               state->adb_command_length = 2;
651601               break;
652602
653603            default:
r9648r9649
656606
657607         }
658608
659         if (adb_command_length > 0)
609         if (state->adb_command_length > 0)
660610         {
661            adb_state = ADBSTATE_INCOMMAND;
611            state->adb_state = ADBSTATE_INCOMMAND;
662612            if (LOG_ADB)
663               logerror("adb_write_datareg(): in command length %u\n", (unsigned) adb_command_length);
613               logerror("adb_write_datareg(): in command length %u\n", (unsigned) state->adb_command_length);
664614         }
665615         break;
666616
667617      case ADBSTATE_INCOMMAND:
668         assert(adb_command_pos < ARRAY_LENGTH(adb_command_bytes));
669         adb_command_bytes[adb_command_pos++] = data;
618         assert(state->adb_command_pos < ARRAY_LENGTH(state->adb_command_bytes));
619         state->adb_command_bytes[state->adb_command_pos++] = data;
670620         break;
671621
672622      case ADBSTATE_INRESPONSE:
673         adb_state = ADBSTATE_IDLE;
623         state->adb_state = ADBSTATE_IDLE;
674624         break;
675625   }
676626
677627   /* do command if necessary */
678   if ((adb_state == ADBSTATE_INCOMMAND) && (adb_command_pos >= adb_command_length))
679      adb_do_command();
628   if ((state->adb_state == ADBSTATE_INCOMMAND) && (state->adb_command_pos >= state->adb_command_length))
629      adb_do_command(state);
680630}
681631
682632
683633// real rom 3 h/w reads 0x90 when idle, 0x98 when key pressed
684634// current MESS reads back 0xb0 when idle
685static UINT8 adb_read_kmstatus(void)
635static UINT8 adb_read_kmstatus(apple2gs_state *state)
686636{
687   return adb_kmstatus;
637   return state->adb_kmstatus;
688638}
689639
690640
691641
692static void adb_write_kmstatus(UINT8 data)
642static void adb_write_kmstatus(apple2gs_state *state, UINT8 data)
693643{
694   adb_kmstatus &= ~0x54;
695   adb_kmstatus |= data & 0x54;
644   state->adb_kmstatus &= ~0x54;
645   state->adb_kmstatus |= data & 0x54;
696646}
697647
698648
699649
700650static UINT8 adb_read_mousedata(running_machine *machine)
701651{
652   apple2gs_state *state = machine->driver_data<apple2gs_state>();
702653   UINT8 result = 0x00;
703654   UINT8 absolute;
704655   INT8 delta;
705656
706   if (adb_kmstatus & 0x80)   // mouse register full
657   if (state->adb_kmstatus & 0x80)   // mouse register full
707658   {
708      if (adb_kmstatus & 0x02)   // H/V mouse data select
659      if (state->adb_kmstatus & 0x02)   // H/V mouse data select
709660      {
710         absolute = apple2gs_mouse_y;
711         delta = apple2gs_mouse_dy;
712         adb_kmstatus &= ~0x82;
661         absolute = state->mouse_y;
662         delta = state->mouse_dy;
663         state->adb_kmstatus &= ~0x82;
713664         apple2gs_remove_irq(machine, IRQ_ADB_MOUSE);
714665      }
715666      else
716667      {
717         absolute = apple2gs_mouse_x;
718         delta = apple2gs_mouse_dx;
719         adb_kmstatus |= 0x02;
668         absolute = state->mouse_x;
669         delta = state->mouse_dx;
670         state->adb_kmstatus |= 0x02;
720671      }
721672
722673      if (delta > 63)
r9648r9649
745696
746697static void adb_check_mouse(running_machine *machine)
747698{
699   apple2gs_state *state = machine->driver_data<apple2gs_state>();
748700   UINT8 new_mouse_x, new_mouse_y;
749701
750702   /* read mouse values */
751   if ((adb_kmstatus & 0x80) == 0x00)
703   if ((state->adb_kmstatus & 0x80) == 0x00)
752704   {
753705      new_mouse_x = input_port_read(machine, "adb_mouse_x");
754706      new_mouse_y = input_port_read(machine, "adb_mouse_y");
755707
756      if ((apple2gs_mouse_x != new_mouse_x) || (apple2gs_mouse_y != new_mouse_y))
708      if ((state->mouse_x != new_mouse_x) || (state->mouse_y != new_mouse_y))
757709      {
758         apple2gs_mouse_dx = seven_bit_diff(new_mouse_x, apple2gs_mouse_x);
759         apple2gs_mouse_dy = seven_bit_diff(new_mouse_y, apple2gs_mouse_y);
760         apple2gs_mouse_x = new_mouse_x;
761         apple2gs_mouse_y = new_mouse_y;
710         state->mouse_dx = seven_bit_diff(new_mouse_x, state->mouse_x);
711         state->mouse_dy = seven_bit_diff(new_mouse_y, state->mouse_y);
712         state->mouse_x = new_mouse_x;
713         state->mouse_y = new_mouse_y;
762714
763         adb_kmstatus |= 0x80;
764         adb_kmstatus &= ~0x02;
765         if (adb_kmstatus & 0x40)
715         state->adb_kmstatus |= 0x80;
716         state->adb_kmstatus &= ~0x02;
717         if (state->adb_kmstatus & 0x40)
766718            apple2gs_add_irq(machine, IRQ_ADB_MOUSE);
767719      }
768720   }
r9648r9649
772724
773725static void apple2gs_set_scanint(running_machine *machine, UINT8 data)
774726{
727   apple2gs_state *state = machine->driver_data<apple2gs_state>();
775728   /* second interrupt */
776   if ((apple2gs_vgcint & 0x40) && !(data & 0x40))
729   if ((state->vgcint & 0x40) && !(data & 0x40))
777730   {
778731      apple2gs_remove_irq(machine, IRQ_VGC_SECOND);
779      apple2gs_vgcint &= ~0xC0;
732      state->vgcint &= ~0xC0;
780733   }
781734
782735   /* scanline interrupt */
783   if ((apple2gs_vgcint & 0x20) && !(data & 0x20))
736   if ((state->vgcint & 0x20) && !(data & 0x20))
784737   {
785738      apple2gs_remove_irq(machine, IRQ_VGC_SCANLINE);
786      apple2gs_vgcint &= ~0xA0;
739      state->vgcint &= ~0xA0;
787740   }
788741
789   if (apple2gs_pending_irqs & (IRQ_VGC_SECOND | IRQ_VGC_SCANLINE))
790      apple2gs_vgcint |= 0x80;
742   if (state->pending_irqs & (IRQ_VGC_SECOND | IRQ_VGC_SCANLINE))
743      state->vgcint |= 0x80;
791744}
792745
793746
794747static TIMER_CALLBACK(apple2gs_scanline_tick)
795748{
749   apple2gs_state *state = machine->driver_data<apple2gs_state>();
796750   int scanline;
797751
798752   scanline = machine->primary_screen->vpos();
799753   machine->primary_screen->update_partial(scanline);
800754
801755   /* scanline interrupt */
802   if ((apple2gs_newvideo & 0x80) && (apple2gs_vgcint & 0x02) && (scanline >= (BORDER_TOP-1)) && (scanline < (200+BORDER_TOP-1)))
756   if ((state->newvideo & 0x80) && (state->vgcint & 0x02) && (scanline >= (BORDER_TOP-1)) && (scanline < (200+BORDER_TOP-1)))
803757   {
804758      UINT8 scb;
805759
806      scb = apple2gs_slowmem[0x19D00 + scanline - BORDER_TOP + 1];
760      scb = state->slowmem[0x19D00 + scanline - BORDER_TOP + 1];
807761
808762      if (scb & 0x40)
809763      {
810         apple2gs_vgcint |= 0xa0;
764         state->vgcint |= 0xa0;
811765         apple2gs_add_irq(machine, IRQ_VGC_SCANLINE);
812766      }
813767   }
r9648r9649
815769   if (scanline == (192+BORDER_TOP))
816770   {
817771      /* VBL interrupt */
818      if ((apple2gs_inten & 0x08) && !(apple2gs_intflag & 0x08))
772      if ((state->inten & 0x08) && !(state->intflag & 0x08))
819773      {
820         apple2gs_intflag |= 0x08;
774         state->intflag |= 0x08;
821775         apple2gs_add_irq(machine, IRQ_INTEN_VBL);
822776      }
823777   }
r9648r9649
832786         apple2_interrupt(machine->device("maincpu"));
833787   }
834788
835   timer_adjust_oneshot(apple2gs_scanline_timer, machine->primary_screen->time_until_pos((scanline+1)%262, 0), 0);
789   timer_adjust_oneshot(state->scanline_timer, machine->primary_screen->time_until_pos((scanline+1)%262, 0), 0);
836790}
837791
838792
r9648r9649
841795 * Sound handlers
842796 * ----------------------------------------------------------------------- */
843797
844static UINT8 sndglu_ctrl;
845static int sndglu_addr, sndglu_dummy_read;
846798
847799static READ8_HANDLER( gssnd_r )
848800{
801   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
849802   UINT8 ret = 0;
850803
851804   switch (offset)
852805   {
853806      case 0:   // control
854         ret = sndglu_ctrl;
807         ret = state->sndglu_ctrl;
855808         break;
856809      case 1:   // data read
857         ret = sndglu_dummy_read;
810         ret = state->sndglu_dummy_read;
858811
859         if (sndglu_ctrl & 0x40)   // docram access
812         if (state->sndglu_ctrl & 0x40)   // docram access
860813         {
861            sndglu_dummy_read = apple2gs_docram[sndglu_addr];
814            state->sndglu_dummy_read = state->docram[state->sndglu_addr];
862815         }
863816         else
864817         {
865818            running_device *es5503 = space->machine->device("es5503");
866            sndglu_dummy_read = es5503_r(es5503, sndglu_addr);
819            state->sndglu_dummy_read = es5503_r(es5503, state->sndglu_addr);
867820         }
868821
869         if (sndglu_ctrl & 0x20)   // auto-increment
822         if (state->sndglu_ctrl & 0x20)   // auto-increment
870823         {
871            sndglu_addr++;
824            state->sndglu_addr++;
872825         }
873826         break;
874827      case 2:   // addr l
875         ret = sndglu_addr & 0xff;
828         ret = state->sndglu_addr & 0xff;
876829         break;
877830      case 3:   // addr h
878         ret = (sndglu_addr >> 8) & 0xff;
831         ret = (state->sndglu_addr >> 8) & 0xff;
879832         break;
880833   }
881834
r9648r9649
886839
887840static WRITE8_HANDLER( gssnd_w )
888841{
842   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
889843   switch (offset)
890844   {
891845      case 0:   // control
892         sndglu_ctrl = data & 0x7f;   // make sure DOC is never busy
893         if (!(sndglu_ctrl & 0x40))   // clear hi byte of address pointer on DOC access
846         state->sndglu_ctrl = data & 0x7f;   // make sure DOC is never busy
847         if (!(state->sndglu_ctrl & 0x40))   // clear hi byte of address pointer on DOC access
894848         {
895            sndglu_addr &= 0xff;
849            state->sndglu_addr &= 0xff;
896850         }
897851         break;
898852      case 1:   // data write
899         if (sndglu_ctrl & 0x40)   // docram access
853         if (state->sndglu_ctrl & 0x40)   // docram access
900854         {
901            apple2gs_docram[sndglu_addr] = data;
855            state->docram[state->sndglu_addr] = data;
902856         }
903857         else
904858         {
905859            running_device *es5503 = space->machine->device("es5503");
906            es5503_w(es5503, sndglu_addr, data);
860            es5503_w(es5503, state->sndglu_addr, data);
907861         }
908862
909         if (sndglu_ctrl & 0x20)   // auto-increment
863         if (state->sndglu_ctrl & 0x20)   // auto-increment
910864         {
911            sndglu_addr++;
865            state->sndglu_addr++;
912866         }
913867         break;
914868      case 2:   // addr l
915         sndglu_addr &= 0xff00;
916         sndglu_addr |= data;
869         state->sndglu_addr &= 0xff00;
870         state->sndglu_addr |= data;
917871         break;
918872      case 3: // addr h
919         sndglu_addr &= 0x00ff;
920         sndglu_addr |= data<<8;
873         state->sndglu_addr &= 0x00ff;
874         state->sndglu_addr |= data<<8;
921875         break;
922876   }
923877}
r9648r9649
955909
956910static READ8_HANDLER( apple2gs_c0xx_r )
957911{
912   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
958913   UINT8 result;
959914   running_device *scc;
960915
r9648r9649
972927         break;
973928
974929      case 0x23:   /* C023 - VGCINT */
975         result = apple2gs_vgcint;
930         result = state->vgcint;
976931         break;
977932
978933      case 0x24:   /* C024 - MOUSEDATA */
r9648r9649
984939         break;
985940
986941      case 0x26:   /* C026 - DATAREG */
987         result = adb_read_datareg();
942         result = adb_read_datareg(state);
988943         break;
989944
990945      case 0x27:   /* C027 - KMSTATUS */
991         result = adb_read_kmstatus();
946         result = adb_read_kmstatus(state);
992947         break;
993948
994949      case 0x29:   /* C029 - NEWVIDEO */
995         result = apple2gs_newvideo;
950         result = state->newvideo;
996951         break;
997952
998953      case 0x2B:   /* C02B - LANGSEL */
999         result = apple2gs_langsel;
954         result = state->langsel;
1000955         break;
1001956
1002957      case 0x2D:   /* C02D - SLTROMSEL */
1003         result = apple2gs_sltromsel;
958         result = state->sltromsel;
1004959         break;
1005960
1006961      case 0x2E:   /* C02E - VERTCNT */
r9648r9649
1025980         break;
1026981
1027982      case 0x33:   /* C033 - CLOCKDATA */
1028         result = clock_data;
983         result = state->clock_data;
1029984         break;
1030985
1031986      case 0x34:   /* C034 - CLOCKCTL */
1032         result = clock_control;
987         result = state->clock_control;
1033988         break;
1034989
1035990      case 0x35:   /* C035 - SHADOW */
1036         result = apple2gs_shadow;
991         result = state->shadow;
1037992         break;
1038993
1039994      case 0x36:   /* C036 - CYAREG */
1040         result = apple2gs_cyareg;
995         result = state->cyareg;
1041996         break;
1042997
1043998      case 0x38:   /* C038 - SCCBREG */
r9648r9649
10561011         break;
10571012
10581013      case 0x41:   /* C041 - INTEN */
1059         result = apple2gs_inten;
1014         result = state->inten;
10601015         break;
10611016
10621017      case 0x46:   /* C046 - INTFLAG */
1063         result = apple2gs_intflag;
1018         result = state->intflag;
10641019         break;
10651020
10661021      case 0x68:   /* C068 - STATEREG */
r9648r9649
10991054
11001055static WRITE8_HANDLER( apple2gs_c0xx_w )
11011056{
1057   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
11021058   running_device *scc;
11031059
11041060   offset &= 0xFF;
r9648r9649
11141070         break;
11151071
11161072      case 0x23:   /* C023 - VGCINT */
1117         apple2gs_vgcint &= ~0x0F;
1118         apple2gs_vgcint |= data & 0x0F;
1073         state->vgcint &= ~0x0F;
1074         state->vgcint |= data & 0x0F;
11191075         break;
11201076
11211077      case 0x24:   /* C024 - MOUSEDATA */
r9648r9649
11321088         break;
11331089
11341090      case 0x27:   /* C027 - KMSTATUS */
1135         adb_write_kmstatus(data);
1091         adb_write_kmstatus(state, data);
11361092         break;
11371093
11381094      case 0x29:   /* C029 - NEWVIDEO */
1139         apple2gs_newvideo = data;
1095         state->newvideo = data;
11401096         break;
11411097
11421098      case 0x2B:   /* C02B - LANGSEL */
1143         apple2gs_langsel = data;
1099         state->langsel = data;
11441100         break;
11451101
11461102      case 0x2D:   /* C02D - SLTROMSEL */
1147         apple2gs_sltromsel = data;
1103         state->sltromsel = data;
11481104         apple2_update_memory(space->machine);
11491105         break;
11501106
r9648r9649
11571113         break;
11581114
11591115      case 0x33:   /* C033 - CLOCKDATA */
1160         clock_data = data;
1116         state->clock_data = data;
11611117         break;
11621118
11631119      case 0x34:   /* C034 - CLOCKCTL */
1164         clock_control = data & 0x7F;
1165         apple2gs_bordercolor = data & 0x0F;
1120         state->clock_control = data & 0x7F;
1121         state->bordercolor = data & 0x0F;
11661122         if (data & 0x80)
11671123            process_clock(space->machine);
11681124         break;
11691125
11701126      case 0x35:   /* C035 - SHADOW */
1171         if (apple2gs_shadow != data)
1127         if (state->shadow != data)
11721128         {
1173            apple2gs_shadow = data;
1129            state->shadow = data;
11741130            apple2_update_memory(space->machine);
11751131         }
11761132         break;
11771133
11781134      case 0x36:   /* C036 - CYAREG */
1179         apple2gs_cyareg = data & ~0x20;
1135         state->cyareg = data & ~0x20;
11801136         cputag_set_clock(space->machine, "maincpu", (data & 0x80) ? APPLE2GS_14M/5 : APPLE2GS_7M/7);
11811137         break;
11821138
r9648r9649
11961152         break;
11971153
11981154      case 0x41:   /* C041 - INTEN */
1199         apple2gs_inten = data & 0x1F;
1200         if ((apple2gs_inten & 0x10) == 0x00)
1155         state->inten = data & 0x1F;
1156         if ((state->inten & 0x10) == 0x00)
12011157            apple2gs_remove_irq(space->machine, IRQ_INTEN_QSECOND);
1202         if ((apple2gs_inten & 0x08) == 0x00)
1158         if ((state->inten & 0x08) == 0x00)
12031159            apple2gs_remove_irq(space->machine, IRQ_INTEN_VBL);
12041160         break;
12051161
12061162      case 0x47:   /* C047 - CLRVBLINT */
1207         apple2gs_intflag &= ~0x18;
1163         state->intflag &= ~0x18;
12081164         apple2gs_remove_irq(space->machine, IRQ_INTEN_QSECOND);
12091165         apple2gs_remove_irq(space->machine, IRQ_INTEN_VBL);
12101166         break;
r9648r9649
12351191
12361192static WRITE8_HANDLER( apple2gs_main0400_w )
12371193{
1194   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
12381195   offset += 0x000400;
12391196   messram_get_ptr(space->machine->device("messram"))[offset] = data;
12401197
1241   if (!(apple2gs_shadow & 0x01))
1198   if (!(state->shadow & 0x01))
12421199   {
1243      apple2gs_slowmem[offset] = data;
1200      state->slowmem[offset] = data;
12441201   }
12451202}
12461203
12471204static WRITE8_HANDLER( apple2gs_aux0400_w )
12481205{
1206   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
12491207   offset += 0x010400;
12501208   messram_get_ptr(space->machine->device("messram"))[offset] = data;
12511209
1252   if (!(apple2gs_shadow & 0x01))
1210   if (!(state->shadow & 0x01))
12531211   {
1254      apple2gs_slowmem[offset] = data;
1212      state->slowmem[offset] = data;
12551213   }
12561214}
12571215
12581216static WRITE8_HANDLER( apple2gs_main2000_w )
12591217{
1218   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
12601219   offset += 0x002000;
12611220   messram_get_ptr(space->machine->device("messram"))[offset] = data;
12621221
1263   if (!(apple2gs_shadow & 0x02))
1222   if (!(state->shadow & 0x02))
12641223   {
1265      apple2gs_slowmem[offset] = data;
1224      state->slowmem[offset] = data;
12661225   }
12671226}
12681227
12691228static WRITE8_HANDLER( apple2gs_aux2000_w )
12701229{
1230   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
12711231   offset += 0x012000;
12721232   messram_get_ptr(space->machine->device("messram"))[offset] = data;
12731233
1274   if (!(apple2gs_shadow & 0x12) || !(apple2gs_shadow & 0x08))
1234   if (!(state->shadow & 0x12) || !(state->shadow & 0x08))
12751235   {
1276      apple2gs_slowmem[offset] = data;
1236      state->slowmem[offset] = data;
12771237   }
12781238}
12791239
12801240static WRITE8_HANDLER( apple2gs_main4000_w )
12811241{
1242   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
12821243   offset += 0x004000;
12831244   messram_get_ptr(space->machine->device("messram"))[offset] = data;
12841245
12851246   if ((offset >= 0x004000) && (offset <= 0x005FFF))
12861247   {
1287      if (!(apple2gs_shadow & 0x04))
1288         apple2gs_slowmem[offset] = data;
1248      if (!(state->shadow & 0x04))
1249         state->slowmem[offset] = data;
12891250   }
12901251}
12911252
12921253static WRITE8_HANDLER( apple2gs_aux4000_w )
12931254{
1255   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
12941256   offset += 0x014000;
12951257   messram_get_ptr(space->machine->device("messram"))[offset] = data;
12961258
12971259   if ((offset >= 0x014000) && (offset <= 0x015FFF))
12981260   {
1299      if (!(apple2gs_shadow & 0x14) || !(apple2gs_shadow & 0x08))
1300         apple2gs_slowmem[offset] = data;
1261      if (!(state->shadow & 0x14) || !(state->shadow & 0x08))
1262         state->slowmem[offset] = data;
13011263   }
13021264   else if ((offset >= 0x016000) && (offset <= 0x019FFF))
13031265   {
1304      if (!(apple2gs_shadow & 0x08))
1266      if (!(state->shadow & 0x08))
13051267      {
1306         apple2gs_slowmem[offset] = data;
1268         state->slowmem[offset] = data;
13071269
13081270         if (offset >= 0x19e00)
13091271         {
13101272            int color = (offset - 0x19e00) >> 1;
13111273
13121274            palette_set_color_rgb(space->machine, color + 16,
1313               ((apple2gs_slowmem[0x19E00 + (color * 2) + 1] >> 0) & 0x0F) * 17,
1314               ((apple2gs_slowmem[0x19E00 + (color * 2) + 0] >> 4) & 0x0F) * 17,
1315               ((apple2gs_slowmem[0x19E00 + (color * 2) + 0] >> 0) & 0x0F) * 17);
1275               ((state->slowmem[0x19E00 + (color * 2) + 1] >> 0) & 0x0F) * 17,
1276               ((state->slowmem[0x19E00 + (color * 2) + 0] >> 4) & 0x0F) * 17,
1277               ((state->slowmem[0x19E00 + (color * 2) + 0] >> 0) & 0x0F) * 17);
13161278         }
13171279      }
13181280   }
r9648r9649
14181380
14191381static void apple2gs_mem_00D000(running_machine *machine,offs_t begin, offs_t end, apple2_meminfo *meminfo)
14201382{
1421   if (apple2gs_shadow & 0x40)
1383   apple2gs_state *state = machine->driver_data<apple2gs_state>();
1384   if (state->shadow & 0x40)
14221385   {
14231386      meminfo->read_mem      = (apple2_flags & VAR_RAMRD) ? 0x01D000 : 0x00D000;
14241387      meminfo->write_mem      = (apple2_flags & VAR_RAMWRT) ? 0x01D000 : 0x00D000;
r9648r9649
14311394
14321395static void apple2gs_mem_00E000(running_machine *machine,offs_t begin, offs_t end, apple2_meminfo *meminfo)
14331396{
1434   if (apple2gs_shadow & 0x40)
1397   apple2gs_state *state = machine->driver_data<apple2gs_state>();
1398   if (state->shadow & 0x40)
14351399   {
14361400      meminfo->read_mem      = (apple2_flags & VAR_RAMRD) ? 0x01E000 : 0x00E000;
14371401      meminfo->write_mem      = (apple2_flags & VAR_RAMWRT) ? 0x01E000 : 0x00E000;
r9648r9649
14441408
14451409static void apple2gs_mem_01D000(running_machine *machine,offs_t begin, offs_t end, apple2_meminfo *meminfo)
14461410{
1447   if (apple2gs_shadow & 0x40)
1411   apple2gs_state *state = machine->driver_data<apple2gs_state>();
1412   if (state->shadow & 0x40)
14481413   {
14491414      meminfo->read_mem      = 0x01D000;
14501415      meminfo->write_mem      = 0x01D000;
r9648r9649
14571422
14581423static void apple2gs_mem_01E000(running_machine *machine,offs_t begin, offs_t end, apple2_meminfo *meminfo)
14591424{
1460   if (apple2gs_shadow & 0x40)
1425   apple2gs_state *state = machine->driver_data<apple2gs_state>();
1426   if (state->shadow & 0x40)
14611427   {
14621428      meminfo->read_mem      = 0x01E000;
14631429      meminfo->write_mem      = 0x01E000;
r9648r9649
15301496
15311497static UINT8 apple2gs_xxCxxx_r(running_machine *machine, offs_t address)
15321498{
1499   apple2gs_state *state = machine->driver_data<apple2gs_state>();
15331500   UINT8 result;
15341501   int slot;
15351502
1536   if ((apple2gs_shadow & 0x40) && ((address & 0xF00000) == 0x000000))
1503   if ((state->shadow & 0x40) && ((address & 0xF00000) == 0x000000))
15371504   {
15381505      result = messram_get_ptr(machine->device("messram"))[address];
15391506   }
r9648r9649
15451512   {
15461513      slot = (address & 0x000F00) / 0x100;
15471514
1548      if ((slot > 7) || ((apple2gs_sltromsel & (1 << slot)) == 0))
1515      if ((slot > 7) || ((state->sltromsel & (1 << slot)) == 0))
15491516         result = *apple2gs_getslotmem(machine, address);
15501517      else
15511518         result = apple2_getfloatingbusvalue(machine);
r9648r9649
15571524
15581525static void apple2gs_xxCxxx_w(running_machine *machine, offs_t address, UINT8 data)
15591526{
1527   apple2gs_state *state = machine->driver_data<apple2gs_state>();
15601528   int slot;
15611529
1562   if ((apple2gs_shadow & 0x40) && ((address & 0xF00000) == 0x000000))
1530   if ((state->shadow & 0x40) && ((address & 0xF00000) == 0x000000))
15631531   {
15641532      messram_get_ptr(machine->device("messram"))[address] = data;
15651533   }
r9648r9649
15711539   {
15721540      slot = (address & 0x000F00) / 0x100;
15731541
1574      if ((slot > 7) || ((apple2gs_sltromsel & (1 << slot)) == 0))
1542      if ((slot > 7) || ((state->sltromsel & (1 << slot)) == 0))
15751543         *apple2gs_getslotmem(machine, address) = data;
15761544   }
15771545}
r9648r9649
15801548
15811549DIRECT_UPDATE_HANDLER( apple2gs_opbase )
15821550{
1551   apple2gs_state *state = machine->driver_data<apple2gs_state>();
15831552   UINT8 *opptr = NULL;
15841553   int slot;
15851554
15861555   if (((address & 0xFEF000) == 0x00C000) || ((address & 0xFEF000) == 0xE0C000))
15871556   {
1588      if ((apple2gs_shadow & 0x40) && ((address & 0xF00000) == 0x000000))
1557      if ((state->shadow & 0x40) && ((address & 0xF00000) == 0x000000))
15891558      {
15901559         opptr = &messram_get_ptr(machine->device("messram"))[address];
15911560      }
r9648r9649
15981567      {
15991568         slot = (address & 0x000F00) / 0x100;
16001569
1601         if ((slot > 7) || ((apple2gs_sltromsel & (1 << slot)) == 0))
1570         if ((slot > 7) || ((state->sltromsel & (1 << slot)) == 0))
16021571            opptr = apple2gs_getslotmem(machine, address);
16031572      }
16041573
r9648r9649
16261595
16271596static WRITE8_HANDLER( apple2gs_Exxxxx_w )
16281597{
1629   apple2gs_slowmem[offset] = data;
1598   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
1599   state->slowmem[offset] = data;
16301600}
16311601
16321602static WRITE8_HANDLER( apple2gs_E004xx_w ) { apple2gs_Exxxxx_w(space, offset + 0x00400, data); }
r9648r9649
16361606
16371607static WRITE8_HANDLER( apple2gs_slowmem_w )
16381608{
1639   apple2gs_slowmem[offset] = data;
1609   apple2gs_state *state = space->machine->driver_data<apple2gs_state>();
1610   state->slowmem[offset] = data;
16401611
16411612   if ((offset >= 0x19e00) && (offset < 0x19fff))
16421613   {
16431614      int color = (offset - 0x19e00) >> 1;
16441615
16451616      palette_set_color_rgb(space->machine, color + 16,
1646         ((apple2gs_slowmem[0x19E00 + (color * 2) + 1] >> 0) & 0x0F) * 17,
1647         ((apple2gs_slowmem[0x19E00 + (color * 2) + 0] >> 4) & 0x0F) * 17,
1648         ((apple2gs_slowmem[0x19E00 + (color * 2) + 0] >> 0) & 0x0F) * 17);
1617         ((state->slowmem[0x19E00 + (color * 2) + 1] >> 0) & 0x0F) * 17,
1618         ((state->slowmem[0x19E00 + (color * 2) + 0] >> 4) & 0x0F) * 17,
1619         ((state->slowmem[0x19E00 + (color * 2) + 0] >> 0) & 0x0F) * 17);
16491620   }
16501621}
16511622
16521623
16531624static void apple2gs_setup_memory(running_machine *machine)
16541625{
1626   apple2gs_state *state = machine->driver_data<apple2gs_state>();
16551627   address_space* space = cputag_get_address_space(machine, "maincpu",ADDRESS_SPACE_PROGRAM);
16561628   offs_t begin, end;
16571629   apple2_memmap_config cfg;
16581630
16591631   /* allocate memory for E00000-E1FFFF */
1660   apple2gs_slowmem = auto_alloc_array_clear(machine, UINT8, 128*1024);
1632   state->slowmem = auto_alloc_array_clear(machine, UINT8, 128*1024);
16611633
1662   state_save_register_item_array(machine, "APPLE2GS_SLOWMEM", NULL, 0, apple2gs_slowmem);
1634   state_save_register_item_array(machine, "APPLE2GS_SLOWMEM", NULL, 0, state->slowmem);
16631635
16641636   /* install expanded memory */
16651637   memory_install_readwrite_bank(space, 0x010000, messram_get_size(machine->device("messram")) - 1, 0, 0, "bank1");
r9648r9649
16721644   memory_install_write8_handler(space, 0xe02000, 0xe03fff, 0, 0, apple2gs_E02xxx_w);
16731645   memory_install_write8_handler(space, 0xe10400, 0xe107ff, 0, 0, apple2gs_E104xx_w);
16741646   memory_install_write8_handler(space, 0xe12000, 0xe13fff, 0, 0, apple2gs_E12xxx_w);
1675   memory_set_bankptr(machine,"bank2", apple2gs_slowmem);
1647   memory_set_bankptr(machine,"bank2", state->slowmem);
16761648
16771649   /* install alternate ROM bank */
16781650   begin = 0x1000000 - memory_region_length(machine, "maincpu");
r9648r9649
17011673   memset(&cfg, 0, sizeof(cfg));
17021674   cfg.first_bank = 4;
17031675   cfg.memmap = apple2gs_memmap_entries;
1704   cfg.auxmem = apple2gs_slowmem;
1676   cfg.auxmem = state->slowmem;
17051677   cfg.auxmem_length = 0x20000;
17061678   apple2_setup_memory(machine, &cfg);
17071679}
r9648r9649
17251697
17261698MACHINE_START( apple2gs )
17271699{
1700   apple2gs_state *state = machine->driver_data<apple2gs_state>();
17281701   apple2_init_common(machine);
17291702
17301703   /* set up Apple IIgs vectoring */
17311704   g65816_set_read_vector_callback(machine->device("maincpu"), apple2gs_read_vector);
17321705
17331706   /* setup globals */
1734   apple2gs_cur_slot6_image = NULL;
1735   apple2gs_newvideo = 0x00;
1736   apple2gs_vgcint = 0x00;
1737   apple2gs_langsel = 0x00;
1738   apple2gs_sltromsel = 0x00;
1739   apple2gs_cyareg = 0x80;
1740   apple2gs_inten = 0x00;
1741   apple2gs_intflag = 0x00;
1742   apple2gs_shadow = 0x00;
1743   apple2gs_pending_irqs = 0x00;
1744   apple2gs_mouse_x = 0x00;
1745   apple2gs_mouse_y = 0x00;
1746   apple2gs_mouse_dx = 0x00;
1747   apple2gs_mouse_dy = 0x00;
1748   adb_state = ADBSTATE_IDLE;
1749   adb_kmstatus = 0x00;
1750   adb_command = 0;
1751   adb_mode = 0;
1752   adb_latent_result = 0;
1753   adb_command_length = 0;
1754   adb_command_pos = 0;
1755   memset(adb_command_bytes, 0, sizeof(adb_command_bytes));
1756   memset(adb_response_bytes, 0, sizeof(adb_response_bytes));
1757   adb_response_length = 0;
1758   adb_response_pos = 0;
1759   memset(adb_memory, 0, sizeof(adb_memory));
1760   adb_address_keyboard = 2;
1761   adb_address_mouse = 3;
1707   state->cur_slot6_image = NULL;
1708   state->newvideo = 0x00;
1709   state->vgcint = 0x00;
1710   state->langsel = 0x00;
1711   state->sltromsel = 0x00;
1712   state->cyareg = 0x80;
1713   state->inten = 0x00;
1714   state->intflag = 0x00;
1715   state->shadow = 0x00;
1716   state->pending_irqs = 0x00;
1717   state->mouse_x = 0x00;
1718   state->mouse_y = 0x00;
1719   state->mouse_dx = 0x00;
1720   state->mouse_dy = 0x00;
1721   state->adb_state = ADBSTATE_IDLE;
1722   state->adb_kmstatus = 0x00;
1723   state->adb_command = 0;
1724   state->adb_mode = 0;
1725   state->adb_latent_result = 0;
1726   state->adb_command_length = 0;
1727   state->adb_command_pos = 0;
1728   memset(state->adb_command_bytes, 0, sizeof(state->adb_command_bytes));
1729   memset(state->adb_response_bytes, 0, sizeof(state->adb_response_bytes));
1730   state->adb_response_length = 0;
1731   state->adb_response_pos = 0;
1732   memset(state->adb_memory, 0, sizeof(state->adb_memory));
1733   state->adb_address_keyboard = 2;
1734   state->adb_address_mouse = 3;
17621735
17631736   /* init time */
1764   clock_data = 0;
1765   clock_control =0;
1766   clock_read = 0;
1767   clock_reg1 = 0;
1768   clock_mode = CLOCKMODE_IDLE;
1769   clock_curtime = 0;
1770   clock_curtime_interval = 0;
1737   state->clock_data = 0;
1738   state->clock_control =0;
1739   state->clock_read = 0;
1740   state->clock_reg1 = 0;
1741   state->clock_mode = CLOCKMODE_IDLE;
1742   state->clock_curtime = 0;
1743   state->clock_curtime_interval = 0;
17711744
1772   sndglu_ctrl = 0x00;
1773   sndglu_addr = 0;
1774   sndglu_dummy_read = 0;
1745   state->sndglu_ctrl = 0x00;
1746   state->sndglu_addr = 0;
1747   state->sndglu_dummy_read = 0;
17751748
17761749   /* init the various subsystems */
17771750   apple2gs_setup_memory(machine);
r9648r9649
17791752   /* save state stuff.  note that the driver takes care of docram. */
17801753   state_save_register_global_array(machine, messram_get_ptr(machine->device("messram")));
17811754
1782   state_save_register_item(machine, "NEWVIDEO", NULL, 0, apple2gs_newvideo);
1755   state_save_register_item(machine, "NEWVIDEO", NULL, 0, state->newvideo);
17831756
1784   state_save_register_item(machine, "VGCINT", NULL,0, apple2gs_vgcint);
1785   state_save_register_item(machine, "LANGSEL", NULL,0, apple2gs_langsel);
1786   state_save_register_item(machine, "SLTROMSEL", NULL,0, apple2gs_sltromsel);
1787   state_save_register_item(machine, "CYAREG", NULL,0, apple2gs_cyareg);
1788   state_save_register_item(machine, "INTEN", NULL,0, apple2gs_inten);
1789   state_save_register_item(machine, "INTFLAG", NULL,0, apple2gs_intflag);
1790   state_save_register_item(machine, "SHADOW", NULL,0, apple2gs_shadow);
1791   state_save_register_item(machine, "PENDIRQ", NULL,0, apple2gs_pending_irqs);
1792   state_save_register_item(machine, "MX", NULL,0, apple2gs_mouse_x);
1793   state_save_register_item(machine, "MY", NULL,0, apple2gs_mouse_y);
1794   state_save_register_item(machine, "MDX", NULL,0, apple2gs_mouse_dx);
1795   state_save_register_item(machine, "MDY", NULL,0, apple2gs_mouse_dy);
1757   state_save_register_item(machine, "VGCINT", NULL,0, state->vgcint);
1758   state_save_register_item(machine, "LANGSEL", NULL,0, state->langsel);
1759   state_save_register_item(machine, "SLTROMSEL", NULL,0, state->sltromsel);
1760   state_save_register_item(machine, "CYAREG", NULL,0, state->cyareg);
1761   state_save_register_item(machine, "INTEN", NULL,0, state->inten);
1762   state_save_register_item(machine, "INTFLAG", NULL,0, state->intflag);
1763   state_save_register_item(machine, "SHADOW", NULL,0, state->shadow);
1764   state_save_register_item(machine, "PENDIRQ", NULL,0, state->pending_irqs);
1765   state_save_register_item(machine, "MX", NULL,0, state->mouse_x);
1766   state_save_register_item(machine, "MY", NULL,0, state->mouse_y);
1767   state_save_register_item(machine, "MDX", NULL,0, state->mouse_dx);
1768   state_save_register_item(machine, "MDY", NULL,0, state->mouse_dy);
17961769
1797   state_save_register_item(machine, "CLKDATA", NULL,0, clock_data);
1798   state_save_register_item(machine, "CLKCTRL", NULL,0, clock_control);
1799   state_save_register_item(machine, "CLKRD", NULL,0, clock_read);
1800   state_save_register_item(machine, "CLKREG1", NULL,0, clock_reg1);
1801   state_save_register_item(machine, "CLKCURTIME", NULL,0, clock_curtime);
1802   state_save_register_item(machine, "CLKCURTIMEINT", NULL,0, clock_curtime_interval);
1803   state_save_register_item(machine, "CLKMODE", NULL,0, clock_mode);
1804   state_save_register_global_array(machine, clock_bram);
1770   state_save_register_item(machine, "CLKDATA", NULL,0, state->clock_data);
1771   state_save_register_item(machine, "CLKCTRL", NULL,0, state->clock_control);
1772   state_save_register_item(machine, "CLKRD", NULL,0, state->clock_read);
1773   state_save_register_item(machine, "CLKREG1", NULL,0, state->clock_reg1);
1774   state_save_register_item(machine, "CLKCURTIME", NULL,0, state->clock_curtime);
1775   state_save_register_item(machine, "CLKCURTIMEINT", NULL,0, state->clock_curtime_interval);
1776   state_save_register_item(machine, "CLKMODE", NULL,0, state->clock_mode);
1777   state_save_register_global_array(machine, state->clock_bram);
18051778
1806   state_save_register_global_array(machine, adb_memory);
1807   state_save_register_global_array(machine, adb_command_bytes);
1808   state_save_register_global_array(machine, adb_response_bytes);
1809   state_save_register_item(machine, "ADB", NULL,0, adb_state);
1810   state_save_register_item(machine, "ADB", NULL,0, adb_command);
1811   state_save_register_item(machine, "ADB", NULL,0, adb_mode);
1812   state_save_register_item(machine, "ADB", NULL,0, adb_kmstatus);
1813   state_save_register_item(machine, "ADB", NULL,0, adb_latent_result);
1814   state_save_register_item(machine, "ADB", NULL,0, adb_command_length);
1815   state_save_register_item(machine, "ADB", NULL,0, adb_command_pos);
1816   state_save_register_item(machine, "ADB", NULL,0, adb_response_length);
1817   state_save_register_item(machine, "ADB", NULL,0, adb_response_pos);
1818   state_save_register_item(machine, "ADB", NULL,0, adb_address_keyboard);
1819   state_save_register_item(machine, "ADB", NULL,0, adb_address_mouse);
1779   state_save_register_global_array(machine, state->adb_memory);
1780   state_save_register_global_array(machine, state->adb_command_bytes);
1781   state_save_register_global_array(machine, state->adb_response_bytes);
1782   state_save_register_item(machine, "ADB", NULL,0, state->adb_state);
1783   state_save_register_item(machine, "ADB", NULL,0, state->adb_command);
1784   state_save_register_item(machine, "ADB", NULL,0, state->adb_mode);
1785   state_save_register_item(machine, "ADB", NULL,0, state->adb_kmstatus);
1786   state_save_register_item(machine, "ADB", NULL,0, state->adb_latent_result);
1787   state_save_register_item(machine, "ADB", NULL,0, state->adb_command_length);
1788   state_save_register_item(machine, "ADB", NULL,0, state->adb_command_pos);
1789   state_save_register_item(machine, "ADB", NULL,0, state->adb_response_length);
1790   state_save_register_item(machine, "ADB", NULL,0, state->adb_response_pos);
1791   state_save_register_item(machine, "ADB", NULL,0, state->adb_address_keyboard);
1792   state_save_register_item(machine, "ADB", NULL,0, state->adb_address_mouse);
18201793
1821   state_save_register_item(machine, "SNDGLUCTRL", NULL,0, sndglu_ctrl);
1822   state_save_register_item(machine, "SNDGLUADDR", NULL,0, sndglu_addr);
1823   state_save_register_item(machine, "SNDGLUDUMMYRD", NULL,0, sndglu_dummy_read);
1794   state_save_register_item(machine, "SNDGLUCTRL", NULL,0, state->sndglu_ctrl);
1795   state_save_register_item(machine, "SNDGLUADDR", NULL,0, state->sndglu_addr);
1796   state_save_register_item(machine, "SNDGLUDUMMYRD", NULL,0, state->sndglu_dummy_read);
18241797
1825   apple2gs_clock_timer = timer_alloc(machine, apple2gs_clock_tick, NULL);
1826   timer_adjust_periodic(apple2gs_clock_timer, ATTOTIME_IN_SEC(1), 0, ATTOTIME_IN_SEC(1));
1798   state->clock_timer = timer_alloc(machine, apple2gs_clock_tick, NULL);
1799   timer_adjust_periodic(state->clock_timer, ATTOTIME_IN_SEC(1), 0, ATTOTIME_IN_SEC(1));
18271800
1828   apple2gs_qsecond_timer = timer_alloc(machine, apple2gs_qsecond_tick, NULL);
1829   timer_adjust_periodic(apple2gs_qsecond_timer, ATTOTIME_IN_USEC(266700), 0, ATTOTIME_IN_USEC(266700));
1801   state->qsecond_timer = timer_alloc(machine, apple2gs_qsecond_tick, NULL);
1802   timer_adjust_periodic(state->qsecond_timer, ATTOTIME_IN_USEC(266700), 0, ATTOTIME_IN_USEC(266700));
18301803
1831   apple2gs_scanline_timer = timer_alloc(machine, apple2gs_scanline_tick, NULL);
1832   timer_adjust_oneshot(apple2gs_scanline_timer, attotime_never, 0);
1804   state->scanline_timer = timer_alloc(machine, apple2gs_scanline_tick, NULL);
1805   timer_adjust_oneshot(state->scanline_timer, attotime_never, 0);
18331806
18341807   // fire on scanline zero
1835   timer_adjust_oneshot(apple2gs_scanline_timer, machine->primary_screen->time_until_pos(0, 0), 0);
1808   timer_adjust_oneshot(state->scanline_timer, machine->primary_screen->time_until_pos(0, 0), 0);
18361809}
src/mess/machine/apple1.c
r9648r9649
136136   '\x00', ESCAPE
137137};
138138
139static int apple1_kbd_data = 0;
140139
141140
142141/*****************************************************************************
r9648r9649
171170MACHINE_RESET( apple1 )
172171{
173172   /* Reset the display hardware. */
174   apple1_vh_dsp_clr();
173   apple1_vh_dsp_clr(machine);
175174}
176175
177176
r9648r9649
281280*****************************************************************************/
282281static TIMER_CALLBACK(apple1_kbd_poll)
283282{
283   apple1_state *state = machine->driver_data<apple1_state>();
284284   int port, bit;
285285   int key_pressed;
286286   UINT32 shiftkeys, ctrlkeys;
r9648r9649
289289
290290   /* This holds the values of all the input ports for ordinary keys
291291       seen during the last scan. */
292   static UINT32 kbd_last_scan[] = { 0, 0, 0, 0 };
293292
294   static int reset_flag = 0;
295
296293   /* First we check the RESET and CLEAR SCREEN pushbutton switches. */
297294
298295   /* The RESET switch resets the CPU and the 6820 PIA. */
299296   if (input_port_read(machine, "KEY5") & 0x0001)
300297   {
301      if (!reset_flag) {
302         reset_flag = 1;
298      if (!state->reset_flag) {
299         state->reset_flag = 1;
303300         /* using PULSE_LINE does not allow us to press and hold key */
304301         cputag_set_input_line(machine, "maincpu", INPUT_LINE_RESET, ASSERT_LINE);
305302         pia->reset();
306303      }
307304   }
308   else if (reset_flag) {
305   else if (state->reset_flag) {
309306      /* RESET released--allow the processor to continue. */
310      reset_flag = 0;
307      state->reset_flag = 0;
311308      cputag_set_input_line(machine, "maincpu", INPUT_LINE_RESET, CLEAR_LINE);
312309   }
313310
314311   /* The CLEAR SCREEN switch clears the video hardware. */
315312   if (input_port_read(machine, "KEY5") & 0x0002)
316313   {
317      if (!apple1_vh_clrscrn_pressed)
314      if (!state->vh_clrscrn_pressed)
318315      {
319316         /* Ignore further video writes, and clear the screen. */
320         apple1_vh_clrscrn_pressed = 1;
321         apple1_vh_dsp_clr();
317         state->vh_clrscrn_pressed = 1;
318         apple1_vh_dsp_clr(machine);
322319      }
323320   }
324   else if (apple1_vh_clrscrn_pressed)
321   else if (state->vh_clrscrn_pressed)
325322   {
326323      /* CLEAR SCREEN released--pay attention to video writes again. */
327      apple1_vh_clrscrn_pressed = 0;
324      state->vh_clrscrn_pressed = 0;
328325   }
329326
330327   /* Now we scan all the input ports for ordinary keys, recording
331328       new keypresses while ignoring keys that were already pressed in
332329       the last scan. */
333330
334   apple1_kbd_data = 0;
331   state->kbd_data = 0;
335332   key_pressed = 0;
336333
337334   /* The keyboard strobe line should always be low when a scan starts. */
r9648r9649
345342      UINT32 portval, newkeys;
346343
347344      portval = input_port_read(machine, keynames[port]);
348      newkeys = portval & ~(kbd_last_scan[port]);
345      newkeys = portval & ~(state->kbd_last_scan[port]);
349346
350347      if (newkeys)
351348      {
r9648r9649
353350         for (bit = 0; bit < 16; bit++) {
354351            if (newkeys & 1)
355352            {
356               apple1_kbd_data = (ctrlkeys)
353               state->kbd_data = (ctrlkeys)
357354                 ? apple1_control_keymap[port*16 + bit]
358355                 : (shiftkeys)
359356                 ? apple1_shifted_keymap[port*16 + bit]
r9648r9649
362359            newkeys >>= 1;
363360         }
364361      }
365      kbd_last_scan[port] = portval;
362      state->kbd_last_scan[port] = portval;
366363   }
367364
368365   if (key_pressed)
r9648r9649
388385*****************************************************************************/
389386static READ8_DEVICE_HANDLER( apple1_pia0_kbdin )
390387{
388   apple1_state *state = device->machine->driver_data<apple1_state>();
391389   /* Bit 7 of the keyboard input is permanently wired high.  This is
392390       what the ROM Monitor software expects. */
393   return apple1_kbd_data | 0x80;
391   return state->kbd_data | 0x80;
394392}
395393
396394static WRITE8_DEVICE_HANDLER( apple1_pia0_dspout )
397395{
398396   /* Send an ASCII character to the video hardware. */
399   apple1_vh_dsp_w(data);
397   apple1_vh_dsp_w(device->machine, data);
400398}
401399
402400static WRITE8_DEVICE_HANDLER( apple1_pia0_dsp_write_signal )
r9648r9649
503501   toggles this flip-flop. */
504502static void cassette_toggle_output(running_machine *machine)
505503{
506   static int cassette_output_flipflop = 0;
507
508   cassette_output_flipflop = !cassette_output_flipflop;
504   apple1_state *state = machine->driver_data<apple1_state>();
505   state->cassette_output_flipflop = !state->cassette_output_flipflop;
509506   cassette_output(cassette_device_image(machine),
510               cassette_output_flipflop ? 1.0 : -1.0);
507               state->cassette_output_flipflop ? 1.0 : -1.0);
511508}
512509
513510READ8_HANDLER( apple1_cassette_r )
src/mess/video/apple2gs.c
r9648r9649
1212#include "includes/apple2gs.h"
1313
1414
15static bitmap_t *apple2gs_legacy_gfx;
16UINT16 apple2gs_bordercolor;
1715
1816VIDEO_START( apple2gs )
1917{
20   apple2gs_bordercolor = 0;
21   apple2_video_start(machine, apple2gs_slowmem, 0x20000, 0, 8);
22   apple2gs_legacy_gfx = auto_bitmap_alloc(machine, 560, 192, BITMAP_FORMAT_INDEXED16);
18   apple2gs_state *state = machine->driver_data<apple2gs_state>();
19   state->bordercolor = 0;
20   apple2_video_start(machine, state->slowmem, 0x20000, 0, 8);
21   state->legacy_gfx = auto_bitmap_alloc(machine, 560, 192, BITMAP_FORMAT_INDEXED16);
2322
24   state_save_register_item(machine, "BORDERCLR", NULL, 0, apple2gs_bordercolor);
23   state_save_register_item(machine, "BORDERCLR", NULL, 0, state->bordercolor);
2524}
2625
2726
2827
2928VIDEO_UPDATE( apple2gs )
3029{
30   apple2gs_state *state = screen->machine->driver_data<apple2gs_state>();
3131   const UINT8 *vram;
3232   UINT16 *scanline;
3333   UINT8 scb, b;
r9648r9649
3737
3838   beamy = cliprect->min_y;
3939
40   if (apple2gs_newvideo & 0x80)
40   if (state->newvideo & 0x80)
4141   {
4242      // in top or bottom border?
4343      if ((beamy < BORDER_TOP) || (beamy >= 200+BORDER_TOP))
r9648r9649
5151         scanline = BITMAP_ADDR16(bitmap, beamy, 0);
5252         for (col = 0; col < BORDER_LEFT+BORDER_RIGHT+640; col++)
5353         {
54            scanline[col] = apple2gs_bordercolor;
54            scanline[col] = state->bordercolor;
5555         }
5656      }
5757      else   // regular screen area
5858      {
5959         int shrline = beamy - BORDER_TOP;
6060
61         scb = apple2gs_slowmem[0x19D00 + shrline];
61         scb = state->slowmem[0x19D00 + shrline];
6262         palette = ((scb & 0x0f) << 4) + 16;
6363
64         vram = &apple2gs_slowmem[0x12000 + (shrline * 160)];
64         vram = &state->slowmem[0x12000 + (shrline * 160)];
6565         scanline = BITMAP_ADDR16(bitmap, beamy, 0);
6666
6767         // draw left and right borders
6868         for (col = 0; col < BORDER_LEFT; col++)
6969         {
70            scanline[col] = apple2gs_bordercolor;
71            scanline[col+BORDER_LEFT+640] = apple2gs_bordercolor;
70            scanline[col] = state->bordercolor;
71            scanline[col+BORDER_LEFT+640] = state->bordercolor;
7272         }
7373
7474         if (scb & 0x80)   // 640 mode
r9648r9649
122122         new_cliprect.min_y = 0;
123123         new_cliprect.max_x = 559;
124124         new_cliprect.max_y = 191;
125         video_update_apple2(screen, apple2gs_legacy_gfx, &new_cliprect);
125         video_update_apple2(screen, state->legacy_gfx, &new_cliprect);
126126      }
127127
128128      if ((beamy < (BORDER_TOP+4)) || (beamy >= (192+4+BORDER_TOP)))
r9648r9649
135135         scanline = BITMAP_ADDR16(bitmap, beamy, 0);
136136         for (col = 0; col < BORDER_LEFT+BORDER_RIGHT+640; col++)
137137         {
138            scanline[col] = apple2gs_bordercolor;
138            scanline[col] = state->bordercolor;
139139         }
140140      }
141141      else
r9648r9649
145145         // draw left and right borders
146146         for (col = 0; col < BORDER_LEFT + 40; col++)
147147         {
148            scanline[col] = apple2gs_bordercolor;
149            scanline[col+BORDER_LEFT+600] = apple2gs_bordercolor;
148            scanline[col] = state->bordercolor;
149            scanline[col+BORDER_LEFT+600] = state->bordercolor;
150150         }
151151
152         memcpy(scanline + 40 + BORDER_LEFT, BITMAP_ADDR16(apple2gs_legacy_gfx, beamy-(BORDER_TOP+4), 0), 560 * sizeof(UINT16));
152         memcpy(scanline + 40 + BORDER_LEFT, BITMAP_ADDR16(state->legacy_gfx, beamy-(BORDER_TOP+4), 0), 560 * sizeof(UINT16));
153153      }
154154   }
155155   return 0;
src/mess/video/apple3.c
r9648r9649
3535   0x428, 0x4a8, 0x528, 0x5a8, 0x628, 0x6a8, 0x728, 0x7a8,
3636   0x450, 0x4d0, 0x550, 0x5d0, 0x650, 0x6d0, 0x750, 0x7d0
3737};
38static UINT8 *char_mem;
39static UINT32 *hgr_map;
4038
4139
4240void apple3_write_charmem(running_machine *machine)
4341{
42   apple3_state *state = machine->driver_data<apple3_state>();
4443   address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
4544   static const UINT32 screen_hole_map[] =
4645   {
r9648r9649
5554      {
5655         addr = 0x7f & space->read_byte(screen_hole_map[i] + 0x400 + j + 0);
5756         val = space->read_byte(screen_hole_map[i] + j + 0);
58         char_mem[((addr * 8) + ((i & 3) * 2) + 0) & 0x3ff] = val;
57         state->char_mem[((addr * 8) + ((i & 3) * 2) + 0) & 0x3ff] = val;
5958
6059         addr = 0x7f & space->read_byte(screen_hole_map[i] + 0x400 + j + 4);
6160         val = space->read_byte(screen_hole_map[i] + j + 4);
62         char_mem[((addr * 8) + ((i & 3) * 2) + 1) & 0x3ff] = val;
61         state->char_mem[((addr * 8) + ((i & 3) * 2) + 1) & 0x3ff] = val;
6362      }
6463   }
6564}
r9648r9649
6867
6968VIDEO_START( apple3 )
7069{
70   apple3_state *state = machine->driver_data<apple3_state>();
7171   int i, j;
7272   UINT32 v;
7373
74   char_mem = auto_alloc_array(machine, UINT8, 0x800);
75   memset(char_mem, 0, 0x800);
74   state->char_mem = auto_alloc_array(machine, UINT8, 0x800);
75   memset(state->char_mem, 0, 0x800);
7676
77   hgr_map = auto_alloc_array(machine, UINT32, 192);
77   state->hgr_map = auto_alloc_array(machine, UINT32, 192);
7878   for (i = 0; i < 24; i++)
7979   {
8080      v = text_map[i] - 0x0400;
8181      for (j = 0; j < 8; j++)
8282      {
83         hgr_map[(i * 8) + j] = 0x2000 + v + (j * 0x400);
83         state->hgr_map[(i * 8) + j] = 0x2000 + v + (j * 0x400);
8484      }
8585   }
8686}
r9648r9649
8989
9090static void apple3_video_text40(running_machine *machine,bitmap_t *bitmap)
9191{
92   apple3_state *state = machine->driver_data<apple3_state>();
9293   int x, y, col, row;
9394   offs_t offset;
9495   UINT8 ch;
r9648r9649
100101   {
101102      for (x = 0; x < 40; x++)
102103      {
103         offset = messram_get_size(machine->device("messram")) - 0x8000 + text_map[y] + x + (apple3_flags & VAR_VM2 ? 0x0400 : 0x0000);
104         offset = messram_get_size(machine->device("messram")) - 0x8000 + text_map[y] + x + (state->flags & VAR_VM2 ? 0x0400 : 0x0000);
104105         ch = messram_get_ptr(machine->device("messram"))[offset];
105106
106         if (apple3_flags & VAR_VM0)
107         if (state->flags & VAR_VM0)
107108         {
108109            /* color text */
109            offset = messram_get_size(machine->device("messram")) - 0x8000 + text_map[y] + x + (apple3_flags & VAR_VM2 ? 0x0000 : 0x0400);
110            offset = messram_get_size(machine->device("messram")) - 0x8000 + text_map[y] + x + (state->flags & VAR_VM2 ? 0x0000 : 0x0400);
110111            bg = (messram_get_ptr(machine->device("messram"))[offset] >> 0) & 0x0F;
111112            fg = (messram_get_ptr(machine->device("messram"))[offset] >> 4) & 0x0F;
112113         }
r9648r9649
125126            bg = temp;
126127         }
127128
128         char_data = &char_mem[(ch & 0x7F) * 8];
129         char_data = &state->char_mem[(ch & 0x7F) * 8];
129130
130131         for (row = 0; row < 8; row++)
131132         {
r9648r9649
144145
145146static void apple3_video_text80(running_machine *machine,bitmap_t *bitmap)
146147{
148   apple3_state *state = machine->driver_data<apple3_state>();
147149   int x, y, col, row;
148150   offs_t offset;
149151   UINT8 ch;
r9648r9649
159161
160162         /* first character */
161163         ch = messram_get_ptr(machine->device("messram"))[offset + 0x0000];
162         char_data = &char_mem[(ch & 0x7F) * 8];
164         char_data = &state->char_mem[(ch & 0x7F) * 8];
163165         fg = (ch & 0x80) ? GREEN : BLACK;
164166         bg = (ch & 0x80) ? BLACK : GREEN;
165167
r9648r9649
174176
175177         /* second character */
176178         ch = messram_get_ptr(machine->device("messram"))[offset + 0x0400];
177         char_data = &char_mem[(ch & 0x7F) * 8];
179         char_data = &state->char_mem[(ch & 0x7F) * 8];
178180         fg = (ch & 0x80) ? GREEN : BLACK;
179181         bg = (ch & 0x80) ? BLACK : GREEN;
180182
r9648r9649
194196
195197static void apple3_video_graphics_hgr(running_machine *machine,bitmap_t *bitmap)
196198{
199   apple3_state *state = machine->driver_data<apple3_state>();
197200   /* hi-res mode: 280x192x2 */
198201   int y, i, x;
199202   const UINT8 *pix_info;
r9648r9649
202205
203206   for (y = 0; y < 192; y++)
204207   {
205      if (apple3_flags & VAR_VM2)
206         pix_info = &messram_get_ptr(machine->device("messram"))[hgr_map[y]];
208      if (state->flags & VAR_VM2)
209         pix_info = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y]];
207210      else
208         pix_info = &messram_get_ptr(machine->device("messram"))[hgr_map[y] - 0x2000];
211         pix_info = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y] - 0x2000];
209212      ptr = BITMAP_ADDR16(bitmap, y, 0);
210213
211214      for (i = 0; i < 40; i++)
r9648r9649
236239
237240static void apple3_video_graphics_chgr(running_machine *machine,bitmap_t *bitmap)
238241{
242   apple3_state *state = machine->driver_data<apple3_state>();
239243   /* color hi-res mode: 280x192x16 */
240244   int y, i, x;
241245   const UINT8 *pix_info;
r9648r9649
246250
247251   for (y = 0; y < 192; y++)
248252   {
249      if (apple3_flags & VAR_VM2)
253      if (state->flags & VAR_VM2)
250254      {
251         pix_info = &messram_get_ptr(machine->device("messram"))[hgr_map[y]];
252         col_info = &messram_get_ptr(machine->device("messram"))[hgr_map[y] - 0x2000];
255         pix_info = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y]];
256         col_info = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y] - 0x2000];
253257      }
254258      else
255259      {
256         pix_info = &messram_get_ptr(machine->device("messram"))[hgr_map[y] - 0x2000];
257         col_info = &messram_get_ptr(machine->device("messram"))[hgr_map[y]];
260         pix_info = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y] - 0x2000];
261         col_info = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y]];
258262      }
259263      ptr = BITMAP_ADDR16(bitmap, y, 0);
260264
r9648r9649
281285
282286static void apple3_video_graphics_shgr(running_machine *machine,bitmap_t *bitmap)
283287{
288   apple3_state *state = machine->driver_data<apple3_state>();
284289   /* super hi-res mode: 560x192x2 */
285290   int y, i, x;
286291   const UINT8 *pix_info1;
r9648r9649
290295
291296   for (y = 0; y < 192; y++)
292297   {
293      if (apple3_flags & VAR_VM2)
298      if (state->flags & VAR_VM2)
294299      {
295         pix_info1 = &messram_get_ptr(machine->device("messram"))[hgr_map[y]];
296         pix_info2 = &messram_get_ptr(machine->device("messram"))[hgr_map[y] + 0x2000];
300         pix_info1 = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y]];
301         pix_info2 = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y] + 0x2000];
297302      }
298303      else
299304      {
300         pix_info1 = &messram_get_ptr(machine->device("messram"))[hgr_map[y] - 0x2000];
301         pix_info2 = &messram_get_ptr(machine->device("messram"))[hgr_map[y]];
305         pix_info1 = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y] - 0x2000];
306         pix_info2 = &messram_get_ptr(machine->device("messram"))[state->hgr_map[y]];
302307      }
303308      ptr = BITMAP_ADDR16(bitmap, y, 0);
304309
r9648r9649
322327
323328static void apple3_video_graphics_chires(running_machine *machine,bitmap_t *bitmap)
324329{
330   apple3_state *state = machine->driver_data<apple3_state>();
325331   UINT16 *pen;
326332   PAIR pix;
327333   int y, i;
r9648r9649
331337      pen = BITMAP_ADDR16(bitmap, y, 0);
332338      for (i = 0; i < 20; i++)
333339      {
334         pix.b.l  = messram_get_ptr(machine->device("messram"))[hgr_map[y] - 0x2000 + (i * 2) + (apple3_flags & VAR_VM2 ? 1 : 0) + 0];
335         pix.b.h  = messram_get_ptr(machine->device("messram"))[hgr_map[y] - 0x0000 + (i * 2) + (apple3_flags & VAR_VM2 ? 1 : 0) + 0];
336         pix.b.h2 = messram_get_ptr(machine->device("messram"))[hgr_map[y] - 0x2000 + (i * 2) + (apple3_flags & VAR_VM2 ? 1 : 0) + 1];
337         pix.b.h3 = messram_get_ptr(machine->device("messram"))[hgr_map[y] - 0x0000 + (i * 2) + (apple3_flags & VAR_VM2 ? 1 : 0) + 1];
340         pix.b.l  = messram_get_ptr(machine->device("messram"))[state->hgr_map[y] - 0x2000 + (i * 2) + (state->flags & VAR_VM2 ? 1 : 0) + 0];
341         pix.b.h  = messram_get_ptr(machine->device("messram"))[state->hgr_map[y] - 0x0000 + (i * 2) + (state->flags & VAR_VM2 ? 1 : 0) + 0];
342         pix.b.h2 = messram_get_ptr(machine->device("messram"))[state->hgr_map[y] - 0x2000 + (i * 2) + (state->flags & VAR_VM2 ? 1 : 0) + 1];
343         pix.b.h3 = messram_get_ptr(machine->device("messram"))[state->hgr_map[y] - 0x0000 + (i * 2) + (state->flags & VAR_VM2 ? 1 : 0) + 1];
338344
339345         pen[ 0] = pen[ 1] = pen[ 2] = pen[ 3] = ((pix.d >>  0) & 0x0F);
340346         pen[ 4] = pen[ 5] = pen[ 6] = pen[ 7] = ((pix.d >>  4) & 0x07) | ((pix.d >>  1) & 0x08);
r9648r9649
352358
353359VIDEO_UPDATE( apple3 )
354360{
355   switch(apple3_flags & (VAR_VM3|VAR_VM1|VAR_VM0))
361   apple3_state *state = screen->machine->driver_data<apple3_state>();
362   switch(state->flags & (VAR_VM3|VAR_VM1|VAR_VM0))
356363   {
357364      case 0:
358365      case VAR_VM0:
src/mess/video/aim65.c
r9648r9649
1111#include "machine/6522via.h"
1212
1313
14static int printer_x;
15static int printer_y;
16static int printer_dir;
17static int flag_a;
18static int flag_b;
1914
2015//UINT16 *printerRAM;
2116
22static emu_timer *print_timer;
23static int printer_level;
2417
2518
2619
r9648r9649
4437 */
4538
4639
47static void aim65_printer_inc(void)
40static void aim65_printer_inc(aim65_state *state)
4841{
49   if (printer_dir)
42   if (state->printer_dir)
5043   {
51      if (printer_x > 0) {
52         printer_x--;
44      if (state->printer_x > 0) {
45         state->printer_x--;
5346      }
5447      else {
55         printer_dir = 0;
56         printer_x++;
57         printer_y++;
48         state->printer_dir = 0;
49         state->printer_x++;
50         state->printer_y++;
5851      }
5952   }
6053   else
6154   {
62      if (printer_x < 9) {
63         printer_x++;
55      if (state->printer_x < 9) {
56         state->printer_x++;
6457      }
6558      else {
66         printer_dir = 1;
67         printer_x--;
68         printer_y++;
59         state->printer_dir = 1;
60         state->printer_x--;
61         state->printer_y++;
6962      }
7063   }
7164
72   if (printer_y > 500) printer_y = 0;
65   if (state->printer_y > 500) state->printer_y = 0;
7366
74   flag_a=0;
75   flag_b=0;
67   state->flag_a=0;
68   state->flag_b=0;
7669}
7770
78static void aim65_printer_cr(void) {
79   printer_x=0;
80   printer_y++;
81   if (printer_y > 500) printer_y = 0;
82   flag_a=flag_b=0;
71static void aim65_printer_cr(aim65_state *state)
72{
73   state->printer_x=0;
74   state->printer_y++;
75   if (state->printer_y > 500) state->printer_y = 0;
76   state->flag_a=state->flag_b=0;
8377}
8478
8579static TIMER_CALLBACK(aim65_printer_timer)
8680{
81   aim65_state *state = machine->driver_data<aim65_state>();
8782   via6522_device *via_0 = machine->device<via6522_device>("via6522_0");
8883
89   via_0->write_cb1(printer_level);
90   via_0->write_cb1(!printer_level);
91   printer_level = !printer_level;
92   aim65_printer_inc();
84   via_0->write_cb1(state->printer_level);
85   via_0->write_cb1(!state->printer_level);
86   state->printer_level = !state->printer_level;
87   aim65_printer_inc(state);
9388}
9489
9590
9691WRITE8_DEVICE_HANDLER( aim65_printer_on )
9792{
93   aim65_state *state = device->machine->driver_data<aim65_state>();
9894   via6522_device *via_0 = device->machine->device<via6522_device>("via6522_0");
9995   if (!data)
10096   {
101      aim65_printer_cr();
102      timer_adjust_periodic(print_timer, attotime_zero, 0, ATTOTIME_IN_USEC(10));
97      aim65_printer_cr(state);
98      timer_adjust_periodic(state->print_timer, attotime_zero, 0, ATTOTIME_IN_USEC(10));
10399      via_0->write_cb1(0);
104      printer_level = 1;
100      state->printer_level = 1;
105101   }
106102   else
107      timer_reset(print_timer, attotime_never);
103      timer_reset(state->print_timer, attotime_never);
108104}
109105
110106
111107WRITE8_DEVICE_HANDLER( aim65_printer_data_a )
112108{
113109#if 0
114   if (flag_a == 0) {
115      printerRAM[(printer_y * 20) + printer_x] |= data;
116      flag_a = 1;
110   aim65_state *state = device->machine->driver_data<aim65_state>();
111   if (state->flag_a == 0) {
112      printerRAM[(state->printer_y * 20) + state->printer_x] |= data;
113      state->flag_a = 1;
117114   }
118115#endif
119116}
r9648r9649
121118WRITE8_DEVICE_HANDLER( aim65_printer_data_b )
122119{
123120#if 0
121   aim65_state *state = device->machine->driver_data<aim65_state>();
124122   data &= 0x03;
125123
126   if (flag_b == 0) {
127      printerRAM[(printer_y * 20) + printer_x ] |= (data << 8);
128      flag_b = 1;
124   if (state->flag_b == 0) {
125      printerRAM[(state->printer_y * 20) + state->printer_x ] |= (data << 8);
126      state->flag_b = 1;
129127   }
130128#endif
131129}
132130
133131VIDEO_START( aim65 )
134132{
135   print_timer = timer_alloc(machine, aim65_printer_timer, NULL);
133   aim65_state *state = machine->driver_data<aim65_state>();
134   state->print_timer = timer_alloc(machine, aim65_printer_timer, NULL);
136135
137136#if 0
138137   videoram_size = 600 * 10 * 2;
139138   printerRAM = auto_alloc_array(machine, UINT16, videoram_size / 2);
140139   memset(printerRAM, 0, videoram_size);
141   printer_x = 0;
142   printer_y = 0;
143   printer_dir = 0;
144   flag_a=0;
145   flag_b=0;
140   state->printer_x = 0;
141   state->printer_y = 0;
142   state->printer_dir = 0;
143   state->flag_a=0;
144   state->flag_b=0;
146145
147146
148   printer_level = 0;
147   state->printer_level = 0;
149148
150149   VIDEO_START_CALL(generic);
151150#endif
src/mess/video/aquarius.c
r9648r9649
99#include "emu.h"
1010#include "includes/aquarius.h"
1111
12static tilemap_t *aquarius_tilemap;
1312
14UINT8 *aquarius_colorram;
1513
1614static const rgb_t aquarius_colors[] =
1715{
r9648r9649
7169   aquarius_state *state = space->machine->driver_data<aquarius_state>();
7270   UINT8 *videoram = state->videoram;
7371   videoram[offset] = data;
74   tilemap_mark_tile_dirty(aquarius_tilemap, offset);
72   tilemap_mark_tile_dirty(state->tilemap, offset);
7573}
7674
7775WRITE8_HANDLER( aquarius_colorram_w )
7876{
79   aquarius_colorram[offset] = data;
80   tilemap_mark_tile_dirty(aquarius_tilemap, offset);
77   aquarius_state *state = space->machine->driver_data<aquarius_state>();
78   state->colorram[offset] = data;
79   tilemap_mark_tile_dirty(state->tilemap, offset);
8180}
8281
8382static TILE_GET_INFO(aquarius_gettileinfo)
r9648r9649
8685   UINT8 *videoram = state->videoram;
8786   int bank = 0;
8887   int code = videoram[tile_index];
89   int color = aquarius_colorram[tile_index];
88   int color = state->colorram[tile_index];
9089   int flags = 0;
9190
9291   SET_TILE_INFO(bank, code, color, flags);
r9648r9649
9493
9594VIDEO_START( aquarius )
9695{
97   aquarius_tilemap = tilemap_create(machine, aquarius_gettileinfo, tilemap_scan_rows, 8, 8, 40, 25);
96   aquarius_state *state = machine->driver_data<aquarius_state>();
97   state->tilemap = tilemap_create(machine, aquarius_gettileinfo, tilemap_scan_rows, 8, 8, 40, 25);
9898}
9999
100100VIDEO_UPDATE( aquarius )
101101{
102   tilemap_draw(bitmap, NULL, aquarius_tilemap, 0, 0);
102   aquarius_state *state = screen->machine->driver_data<aquarius_state>();
103   tilemap_draw(bitmap, NULL, state->tilemap, 0, 0);
103104
104105   return 0;
105106}
src/mess/video/apple1.c
r9648r9649
7070
7171***************************************************************************/
7272
73typedef short termchar_t;
74
75typedef struct
76{
77   tilemap_t *tm;
78   int gfx;
79   int blank_char;
80   int char_bits;
81   int num_cols;
82   int num_rows;
83   int (*getcursorcode)(int original_code);
84   int cur_offset;
85   int cur_hidden;
86   termchar_t mem[1];
87} terminal_t;
88
89static terminal_t *current_terminal;
90
9173static TILE_GET_INFO(terminal_gettileinfo)
9274{
75   apple1_state *state = machine->driver_data<apple1_state>();
9376   int ch, gfxfont, code, color;
9477
95   ch = current_terminal->mem[tile_index];
96   code = ch & ((1 << current_terminal->char_bits) - 1);
97   color = ch >> current_terminal->char_bits;
98   gfxfont = current_terminal->gfx;
78   ch = state->current_terminal->mem[tile_index];
79   code = ch & ((1 << state->current_terminal->char_bits) - 1);
80   color = ch >> state->current_terminal->char_bits;
81   gfxfont = state->current_terminal->gfx;
9982
100   if ((tile_index == current_terminal->cur_offset) && !current_terminal->cur_hidden && current_terminal->getcursorcode)
101      code = current_terminal->getcursorcode(code);
83   if ((tile_index == state->current_terminal->cur_offset) && !state->current_terminal->cur_hidden && state->current_terminal->getcursorcode)
84      code = state->current_terminal->getcursorcode(code);
10285
10386   SET_TILE_INFO(
10487      gfxfont,   /* gfx */
r9648r9649
10790      0);         /* flags */
10891}
10992
110static void terminal_draw(bitmap_t *dest, const rectangle *cliprect, terminal_t *terminal)
93static void terminal_draw(running_machine *machine, bitmap_t *dest, const rectangle *cliprect, terminal_t *terminal)
11194{
112   current_terminal = terminal;
95   apple1_state *state = machine->driver_data<apple1_state>();
96   state->current_terminal = terminal;
11397   tilemap_draw(dest, cliprect, terminal->tm, 0, 0);
114   current_terminal = NULL;
98   state->current_terminal = NULL;
11599}
116100
117101static void verify_coords(terminal_t *terminal, int x, int y)
r9648r9649
228212/**************************************************************************/
229213
230214
231static terminal_t *apple1_terminal;
232215
233int apple1_vh_clrscrn_pressed = 0;      /* flag for CLEAR SCREEN switch */
234
235216/* The cursor blinking is generated by a free-running timer with a
236217   0.52-second period.  It is on for 2/3 of this period and off for
237218   1/3. */
r9648r9649
249230
250231VIDEO_START( apple1 )
251232{
252   apple1_terminal = terminal_create(
233   apple1_state *state = machine->driver_data<apple1_state>();
234   state->blink_on = 1;      /* cursor is visible initially */
235   state->terminal = terminal_create(
253236      machine,
254237      0,         /* graphics font 0 (the only one we have) */
255238      32,         /* Blank character is symbol 32 in the ROM */
r9648r9649
257240      apple1_getcursorcode,
258241      40, 24);   /* 40 columns, 24 rows */
259242
260   terminal_setcursor(apple1_terminal, 0, 0);
243   terminal_setcursor(state->terminal, 0, 0);
261244}
262245
263246/* This function handles all writes to the video display. */
264void apple1_vh_dsp_w (int data)
247void apple1_vh_dsp_w (running_machine *machine, int data)
265248{
249   apple1_state *state = machine->driver_data<apple1_state>();
266250   int   x, y;
267251   int cursor_x, cursor_y;
268252
269253   /* While CLEAR SCREEN is being held down, the hardware is forced
270254       to clear the video memory, so video writes have no effect. */
271   if (apple1_vh_clrscrn_pressed)
255   if (state->vh_clrscrn_pressed)
272256      return;
273257
274258   /* The video display port only accepts the 7 lowest bits of the char. */
275259   data &= 0x7f;
276260
277   terminal_getcursor(apple1_terminal, &cursor_x, &cursor_y);
261   terminal_getcursor(state->terminal, &cursor_x, &cursor_y);
278262
279263   if (data == '\r') {
280264      /* Carriage-return moves the cursor to the start of the next
r9648r9649
299283
300284      int romindx = (data & 0x1f) | (((data ^ 0x40) & 0x40) >> 1);
301285
302      terminal_putchar(apple1_terminal, cursor_x, cursor_y, romindx);
286      terminal_putchar(state->terminal, cursor_x, cursor_y, romindx);
303287      if (cursor_x < 39)
304288      {
305289         cursor_x++;
r9648r9649
316300   {
317301      for (y = 1; y < 24; y++)
318302         for (x = 0; x < 40; x++)
319            terminal_putchar(apple1_terminal, x, y-1,
320                         terminal_getchar(apple1_terminal, x, y));
303            terminal_putchar(state->terminal, x, y-1,
304                         terminal_getchar(state->terminal, x, y));
321305
322306      for (x = 0; x < 40; x++)
323         terminal_putblank(apple1_terminal, x, 23);
307         terminal_putblank(state->terminal, x, 23);
324308
325309      cursor_y--;
326310   }
327311
328   terminal_setcursor(apple1_terminal, cursor_x, cursor_y);
312   terminal_setcursor(state->terminal, cursor_x, cursor_y);
329313}
330314
331315/* This function handles clearing the video display on cold-boot or in
332316   response to a press of the CLEAR SCREEN switch. */
333void apple1_vh_dsp_clr (void)
317void apple1_vh_dsp_clr (running_machine *machine)
334318{
335   terminal_setcursor(apple1_terminal, 0, 0);
336   terminal_clear(apple1_terminal);
319   apple1_state *state = machine->driver_data<apple1_state>();
320   terminal_setcursor(state->terminal, 0, 0);
321   terminal_clear(state->terminal);
337322}
338323
339324/* Calculate how long it will take for the display to assert the RDA
r9648r9649
342327   write. */
343328attotime apple1_vh_dsp_time_to_ready (running_machine *machine)
344329{
330   apple1_state *state = machine->driver_data<apple1_state>();
345331   int cursor_x, cursor_y;
346332   int cursor_scanline;
347333   double scanline_period = attotime_to_double(machine->primary_screen->scan_period());
r9648r9649
355341       the cursor's character line, when the beam reaches the cursor's
356342       horizontal position. */
357343
358   terminal_getcursor(apple1_terminal, &cursor_x, &cursor_y);
344   terminal_getcursor(state->terminal, &cursor_x, &cursor_y);
359345   cursor_scanline = cursor_y * apple1_charlayout.height;
360346
361347   /* Each scanline is composed of 455 pixel times.  The first 175 of
r9648r9649
383369/* Blink the cursor on or off, as appropriate. */
384370static void apple1_vh_cursor_blink (running_machine *machine)
385371{
386   static int blink_on = 1;      /* cursor is visible initially */
372   apple1_state *state = machine->driver_data<apple1_state>();
387373   int new_blink_on;
388374
389375   /* The cursor is on for 2/3 of its blink period and off for 1/3.
r9648r9649
397383   else
398384      new_blink_on = 0;
399385
400   if (new_blink_on != blink_on) {      /* have we changed state? */
386   if (new_blink_on != state->blink_on) {      /* have we changed state? */
401387      if (new_blink_on)
402         terminal_showcursor(apple1_terminal);
388         terminal_showcursor(state->terminal);
403389      else
404         terminal_hidecursor(apple1_terminal);
405      blink_on = new_blink_on;
390         terminal_hidecursor(state->terminal);
391      state->blink_on = new_blink_on;
406392   }
407393}
408394
409395VIDEO_UPDATE( apple1 )
410396{
397   apple1_state *state = screen->machine->driver_data<apple1_state>();
411398   apple1_vh_cursor_blink(screen->machine);
412   terminal_draw(bitmap, NULL, apple1_terminal);
399   terminal_draw(screen->machine, bitmap, NULL, state->terminal);
413400   return 0;
414401}
src/mess/video/a7800.c
r9648r9649
3030
3131#define READ_MEM(x) space->read_byte(x)
3232
33/*static unsigned char *ROM; */
34
3533/********** Maria ***********/
3634
3735#define DPPH 0x2c
3836#define DPPL 0x30
3937#define CTRL 0x3c
4038
41static int maria_palette[8][4];
42static int maria_write_mode;
43static int maria_scanline;
44static unsigned int maria_dll;
45static unsigned int maria_dl;
46static int maria_holey;
47static int maria_offset;
48static int maria_vblank;
49static int maria_dli;
50static int maria_dmaon;            /* dma is enabled */
51static int maria_dodma;            /* doing dma right now */
52static int maria_wsync;
53static int maria_backcolor;
5439
55static int maria_color_kill;
56static int maria_cwidth;
57static int maria_bcntl;
58static int maria_kangaroo;
59static int maria_rm;
6040
61static unsigned int maria_charbase;
6241
6342// 20030621 ericball define using logical operations
6443#define inc_hpos() { hpos = (hpos + 1) & 0x1FF; }
r9648r9649
7150***************************************************************************/
7251VIDEO_START( a7800 )
7352{
53   a7800_state *state = machine->driver_data<a7800_state>();
7454   int i;
7555
7656   VIDEO_START_CALL(generic_bitmapped);
7757
7858   for(i=0; i<8; i++)
7959   {
80      maria_palette[i][0]=0;
81      maria_palette[i][1]=0;
82      maria_palette[i][2]=0;
83      maria_palette[i][3]=0;
60      state->maria_palette[i][0]=0;
61      state->maria_palette[i][1]=0;
62      state->maria_palette[i][2]=0;
63      state->maria_palette[i][3]=0;
8464   }
8565
86   maria_write_mode=0;
87   maria_scanline=0;
88   maria_dmaon=0;
89   maria_vblank=0x80;
90   maria_dll=0;
91   maria_dodma=0;
92   maria_wsync=0;
66   state->maria_write_mode=0;
67   state->maria_scanline=0;
68   state->maria_dmaon=0;
69   state->maria_vblank=0x80;
70   state->maria_dll=0;
71   state->maria_dodma=0;
72   state->maria_wsync=0;
9373
94   maria_color_kill = 0;
95   maria_cwidth = 0;
96   maria_bcntl = 0;
97   maria_kangaroo = 0;
98   maria_rm = 0;
74   state->maria_color_kill = 0;
75   state->maria_cwidth = 0;
76   state->maria_bcntl = 0;
77   state->maria_kangaroo = 0;
78   state->maria_rm = 0;
9979}
10080
10181/***************************************************************************
r9648r9649
10686
10787static void maria_draw_scanline(running_machine *machine)
10888{
89   a7800_state *state = machine->driver_data<a7800_state>();
10990   address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
11091   unsigned int graph_adr,data_addr;
11192   int width,hpos,pal,mode,ind;
r9648r9649
11596   UINT16 *scanline;
11697
11798   /* set up scanline */
118   scanline = BITMAP_ADDR16(machine->generic.tmpbitmap, maria_scanline, 0);
99   scanline = BITMAP_ADDR16(machine->generic.tmpbitmap, state->maria_scanline, 0);
119100   for (i = 0; i < 320; i++)
120      scanline[i] = maria_backcolor;
101      scanline[i] = state->maria_backcolor;
121102
122103   /* Process this DLL entry */
123   dl = maria_dl;
104   dl = state->maria_dl;
124105
125106   /* Step through DL's */
126107   while ((READ_MEM(dl + 1) & 0x5F) != 0)
r9648r9649
133114         width = ((READ_MEM(dl+3) ^ 0xff) & 0x1F) + 1;
134115         hpos = READ_MEM(dl+4)*2;
135116         pal = READ_MEM(dl+3) >> 5;
136         maria_write_mode = (READ_MEM(dl+1) & 0x80) >> 5;
117         state->maria_write_mode = (READ_MEM(dl+1) & 0x80) >> 5;
137118         ind = READ_MEM(dl+1) & 0x20;
138119         dl+=5;
139120      }
r9648r9649
148129         dl+=4;
149130      }
150131
151      mode = maria_rm | maria_write_mode;
132      mode = state->maria_rm | state->maria_write_mode;
152133
153      /*logerror("%x DL: ADR=%x  width=%x  hpos=%x  pal=%x  mode=%x  ind=%x\n",maria_scanline,graph_adr,width,hpos,pal,mode,ind );*/
134      /*logerror("%x DL: ADR=%x  width=%x  hpos=%x  pal=%x  mode=%x  ind=%x\n",state->maria_scanline,graph_adr,width,hpos,pal,mode,ind );*/
154135
155136      for (x=0; x<width; x++) // 20030621 ericball get graphic data first, then switch (mode)
156137      {
r9648r9649
160141         if (ind)
161142         {
162143            c = READ_MEM(graph_adr + x) & 0xFF;
163            data_addr= (maria_charbase | c) + (maria_offset << 8);
164            if( maria_cwidth )
144            data_addr= (state->maria_charbase | c) + (state->maria_offset << 8);
145            if( state->maria_cwidth )
165146               ind_bytes = 2;
166147         }
167148         else
168149         {
169            data_addr = graph_adr + x + (maria_offset  << 8);
150            data_addr = graph_adr + x + (state->maria_offset  << 8);
170151         }
171152
172         if ( (maria_holey & 0x02) && ((data_addr & 0x9000) == 0x9000))
153         if ( (state->maria_holey & 0x02) && ((data_addr & 0x9000) == 0x9000))
173154            continue;
174         if ( (maria_holey & 0x01) && ((data_addr & 0x8800) == 0x8800))
155         if ( (state->maria_holey & 0x01) && ((data_addr & 0x8800) == 0x8800))
175156            continue;
176157
177158         while (ind_bytes > 0)
r9648r9649
184165               case 0x00:  /* 160A (160x2) */
185166               case 0x01:  /* 160A (160x2) */
186167                  c = (d & 0xC0) >> 6;
187                  if (c || maria_kangaroo)
168                  if (c || state->maria_kangaroo)
188169                  {
189                     scanline[hpos + 0] = maria_palette[pal][c];
190                     scanline[hpos + 1] = maria_palette[pal][c];
170                     scanline[hpos + 0] = state->maria_palette[pal][c];
171                     scanline[hpos + 1] = state->maria_palette[pal][c];
191172                  }
192173                  inc_hpos_by_2();
193174
194175                  c = (d & 0x30) >> 4;
195                  if (c || maria_kangaroo)
176                  if (c || state->maria_kangaroo)
196177                  {
197                     scanline[hpos + 0] = maria_palette[pal][c];
198                     scanline[hpos + 1] = maria_palette[pal][c];
178                     scanline[hpos + 0] = state->maria_palette[pal][c];
179                     scanline[hpos + 1] = state->maria_palette[pal][c];
199180                  }
200181                  inc_hpos_by_2();
201182
202183                  c = (d & 0x0C) >> 2;
203                  if (c || maria_kangaroo)
184                  if (c || state->maria_kangaroo)
204185                  {
205                     scanline[hpos + 0] = maria_palette[pal][c];
206                     scanline[hpos + 1] = maria_palette[pal][c];
186                     scanline[hpos + 0] = state->maria_palette[pal][c];
187                     scanline[hpos + 1] = state->maria_palette[pal][c];
207188                  }
208189                  inc_hpos_by_2();
209190
210191                  c = (d & 0x03);
211                  if (c || maria_kangaroo)
192                  if (c || state->maria_kangaroo)
212193                  {
213                     scanline[hpos + 0] = maria_palette[pal][c];
214                     scanline[hpos + 1] = maria_palette[pal][c];
194                     scanline[hpos + 0] = state->maria_palette[pal][c];
195                     scanline[hpos + 1] = state->maria_palette[pal][c];
215196                  }
216197                  inc_hpos_by_2();
217198                  break;
218199
219200               case 0x02: /* 320D used by Jinks! */
220201                  c = pal & 0x04;
221                  if ( d & 0xC0 || pal & 0x03 || maria_kangaroo )
202                  if ( d & 0xC0 || pal & 0x03 || state->maria_kangaroo )
222203                  {
223                     scanline[hpos + 0] = maria_palette[c][((d & 0x80) >> 6) | ((pal & 2) >> 1)];
224                     scanline[hpos + 1] = maria_palette[c][((d & 0x40) >> 5) | ((pal & 1) >> 0)];
204                     scanline[hpos + 0] = state->maria_palette[c][((d & 0x80) >> 6) | ((pal & 2) >> 1)];
205                     scanline[hpos + 1] = state->maria_palette[c][((d & 0x40) >> 5) | ((pal & 1) >> 0)];
225206                  }
226207                  inc_hpos_by_2();
227208
228                  if ( d & 0x30 || pal & 0x03 || maria_kangaroo )
209                  if ( d & 0x30 || pal & 0x03 || state->maria_kangaroo )
229210                  {
230                     scanline[hpos + 0] = maria_palette[c][((d & 0x20) >> 4) | ((pal & 2) >> 1)];
231                     scanline[hpos + 1] = maria_palette[c][((d & 0x10) >> 3) | ((pal & 1) >> 0)];
211                     scanline[hpos + 0] = state->maria_palette[c][((d & 0x20) >> 4) | ((pal & 2) >> 1)];
212                     scanline[hpos + 1] = state->maria_palette[c][((d & 0x10) >> 3) | ((pal & 1) >> 0)];
232213                  }
233214                  inc_hpos_by_2();
234215
235                  if ( d & 0x0C || pal & 0x03 || maria_kangaroo )
216                  if ( d & 0x0C || pal & 0x03 || state->maria_kangaroo )
236217                  {
237                     scanline[hpos + 0] = maria_palette[c][((d & 0x08) >> 2) | ((pal & 2) >> 1)];
238                     scanline[hpos + 1] = maria_palette[c][((d & 0x04) >> 1) | ((pal & 1) >> 0)];
218                     scanline[hpos + 0] = state->maria_palette[c][((d & 0x08) >> 2) | ((pal & 2) >> 1)];
219                     scanline[hpos + 1] = state->maria_palette[c][((d & 0x04) >> 1) | ((pal & 1) >> 0)];
239220                  }
240221                  inc_hpos_by_2();
241222
242                  if ( d & 0x03 || pal & 0x03 || maria_kangaroo )
223                  if ( d & 0x03 || pal & 0x03 || state->maria_kangaroo )
243224                  {
244                     scanline[hpos + 0] = maria_palette[c][((d & 0x02) << 0) | ((pal & 2) >> 1)];
245                     scanline[hpos + 1] = maria_palette[c][((d & 0x01) << 1) | ((pal & 1) >> 0)];
225                     scanline[hpos + 0] = state->maria_palette[c][((d & 0x02) << 0) | ((pal & 2) >> 1)];
226                     scanline[hpos + 1] = state->maria_palette[c][((d & 0x01) << 1) | ((pal & 1) >> 0)];
246227                  }
247228                  inc_hpos_by_2();
248229
249230                  break;
250231
251232               case 0x03:  /* MODE 320A */
252                  if (d & 0xC0 || maria_kangaroo)
233                  if (d & 0xC0 || state->maria_kangaroo)
253234                  {
254                     scanline[hpos + 0] = maria_palette[pal][(d & 0x80) >> 6];
255                     scanline[hpos + 1] = maria_palette[pal][(d & 0x40) >> 5];
235                     scanline[hpos + 0] = state->maria_palette[pal][(d & 0x80) >> 6];
236                     scanline[hpos + 1] = state->maria_palette[pal][(d & 0x40) >> 5];
256237                  }
257238                  inc_hpos_by_2();
258239
259                  if ( d & 0x30 || maria_kangaroo)
240                  if ( d & 0x30 || state->maria_kangaroo)
260241                  {
261                     scanline[hpos + 0] = maria_palette[pal][(d & 0x20) >> 4];
262                     scanline[hpos + 1] = maria_palette[pal][(d & 0x10) >> 3];
242                     scanline[hpos + 0] = state->maria_palette[pal][(d & 0x20) >> 4];
243                     scanline[hpos + 1] = state->maria_palette[pal][(d & 0x10) >> 3];
263244                  }
264245                  inc_hpos_by_2();
265246
266                  if (d & 0x0C || maria_kangaroo)
247                  if (d & 0x0C || state->maria_kangaroo)
267248                  {
268                     scanline[hpos + 0] = maria_palette[pal][(d & 0x08) >> 2];
269                     scanline[hpos + 1] = maria_palette[pal][(d & 0x04) >> 1];
249                     scanline[hpos + 0] = state->maria_palette[pal][(d & 0x08) >> 2];
250                     scanline[hpos + 1] = state->maria_palette[pal][(d & 0x04) >> 1];
270251                  }
271252                  inc_hpos_by_2();
272253
273                  if (d & 0x03 || maria_kangaroo)
254                  if (d & 0x03 || state->maria_kangaroo)
274255                  {
275                     scanline[hpos + 0] = maria_palette[pal][(d & 0x02)];
276                     scanline[hpos + 1] = maria_palette[pal][(d & 0x01) << 1];
256                     scanline[hpos + 0] = state->maria_palette[pal][(d & 0x02)];
257                     scanline[hpos + 1] = state->maria_palette[pal][(d & 0x01) << 1];
277258                  }
278259                  inc_hpos_by_2();
279260                  break;
r9648r9649
281262               case 0x04:  /* 160B (160x4) */
282263               case 0x05:  /* 160B (160x4) */
283264                  c = (d & 0xC0) >> 6;
284                  if (c || maria_kangaroo)
265                  if (c || state->maria_kangaroo)
285266                  {
286                     scanline[hpos + 0] = maria_palette[(pal & 0x04) | ((d & 0x0C) >> 2)][c];
287                     scanline[hpos + 1] = maria_palette[(pal & 0x04) | ((d & 0x0C) >> 2)][c];
267                     scanline[hpos + 0] = state->maria_palette[(pal & 0x04) | ((d & 0x0C) >> 2)][c];
268                     scanline[hpos + 1] = state->maria_palette[(pal & 0x04) | ((d & 0x0C) >> 2)][c];
288269                  }
289270                  inc_hpos_by_2();
290271
291272                  c = (d & 0x30) >> 4;
292                  if (c || maria_kangaroo)
273                  if (c || state->maria_kangaroo)
293274                  {
294                     scanline[hpos + 0] = maria_palette[(pal & 0x04) | (d & 0x03)][c];
295                     scanline[hpos + 1] = maria_palette[(pal & 0x04) | (d & 0x03)][c];
275                     scanline[hpos + 0] = state->maria_palette[(pal & 0x04) | (d & 0x03)][c];
276                     scanline[hpos + 1] = state->maria_palette[(pal & 0x04) | (d & 0x03)][c];
296277                  }
297278                  inc_hpos_by_2();
298279                  break;
299280
300281               case 0x06:  /* MODE 320B */
301                  if (d & 0xCC || maria_kangaroo)
282                  if (d & 0xCC || state->maria_kangaroo)
302283                  {
303                     scanline[hpos + 0] = maria_palette[pal][((d & 0x80) >> 6) | ((d & 0x08) >> 3)];
304                     scanline[hpos + 1] = maria_palette[pal][((d & 0x40) >> 5) | ((d & 0x04) >> 2)];
284                     scanline[hpos + 0] = state->maria_palette[pal][((d & 0x80) >> 6) | ((d & 0x08) >> 3)];
285                     scanline[hpos + 1] = state->maria_palette[pal][((d & 0x40) >> 5) | ((d & 0x04) >> 2)];
305286                  }
306287                  inc_hpos_by_2();
307288
308                  if ( d & 0x33 || maria_kangaroo)
289                  if ( d & 0x33 || state->maria_kangaroo)
309290                  {
310                     scanline[hpos + 0] = maria_palette[pal][((d & 0x20) >> 4) | ((d & 0x02) >> 1)];
311                     scanline[hpos + 1] = maria_palette[pal][((d & 0x10) >> 3) | (d & 0x01)];
291                     scanline[hpos + 0] = state->maria_palette[pal][((d & 0x20) >> 4) | ((d & 0x02) >> 1)];
292                     scanline[hpos + 1] = state->maria_palette[pal][((d & 0x10) >> 3) | (d & 0x01)];
312293                  }
313294                  inc_hpos_by_2();
314295                  break;
315296
316297               case 0x07: /* (320C mode) */
317                  if (d & 0xC0 || maria_kangaroo)
298                  if (d & 0xC0 || state->maria_kangaroo)
318299                  {
319                     scanline[hpos + 0] = maria_palette[(pal & 0x04) | ((d & 0x0C) >> 2)][(d & 0x80) >> 6];
320                     scanline[hpos + 1] = maria_palette[(pal & 0x04) | ((d & 0x0C) >> 2)][(d & 0x40) >> 5];
300                     scanline[hpos + 0] = state->maria_palette[(pal & 0x04) | ((d & 0x0C) >> 2)][(d & 0x80) >> 6];
301                     scanline[hpos + 1] = state->maria_palette[(pal & 0x04) | ((d & 0x0C) >> 2)][(d & 0x40) >> 5];
321302                  }
322303                  inc_hpos_by_2();
323304
324                  if ( d & 0x30 || maria_kangaroo)
305                  if ( d & 0x30 || state->maria_kangaroo)
325306                  {
326                     scanline[hpos + 0] = maria_palette[(pal & 0x04) | (d & 0x03)][(d & 0x20) >> 4];
327                     scanline[hpos + 1] = maria_palette[(pal & 0x04) | (d & 0x03)][(d & 0x10) >> 3];
307                     scanline[hpos + 0] = state->maria_palette[(pal & 0x04) | (d & 0x03)][(d & 0x20) >> 4];
308                     scanline[hpos + 1] = state->maria_palette[(pal & 0x04) | (d & 0x03)][(d & 0x10) >> 3];
328309                  }
329310                  inc_hpos_by_2();
330311                  break;
r9648r9649
338319
339320INTERRUPT_GEN( a7800_interrupt )
340321{
322   a7800_state *state = device->machine->driver_data<a7800_state>();
341323   int frame_scanline;
342324   UINT8 *ROM = memory_region(device->machine, "maincpu");
343325   address_space* space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
344326
345   maria_scanline++;
327   state->maria_scanline++;
346328
347329   /* why + 1? */
348   frame_scanline = maria_scanline % ( a7800_lines + 1 );
330   frame_scanline = state->maria_scanline % ( state->lines + 1 );
349331
350332   if( frame_scanline == 1 )
351333   {
352334      /*logerror( "frame beg\n" );*/
353335   }
354336
355   if( maria_wsync )
337   if( state->maria_wsync )
356338   {
357339      cpuexec_trigger( device->machine, TRIGGER_HSYNC );
358      maria_wsync = 0;
340      state->maria_wsync = 0;
359341   }
360342
361343   if( frame_scanline == 16 )
362344   {
363345      /* end of vblank */
364346
365      maria_vblank=0;
366      if( maria_dmaon || maria_dodma )
347      state->maria_vblank=0;
348      if( state->maria_dmaon || state->maria_dodma )
367349      {
368         maria_dodma = 1;   /* if dma allowed, start it */
350         state->maria_dodma = 1;   /* if dma allowed, start it */
369351
370         maria_dll = (ROM[DPPH] << 8) | ROM[DPPL];
371         maria_dl = (READ_MEM(maria_dll+1) << 8) | READ_MEM(maria_dll+2);
372         maria_offset = READ_MEM(maria_dll) & 0x0f;
373         maria_holey = (READ_MEM(maria_dll) & 0x60) >> 5;
374         maria_dli = READ_MEM(maria_dll) & 0x80;
375         /*  logerror("DLL=%x\n",maria_dll); */
376         /*  logerror("DLL: DL = %x  dllctrl = %x\n",maria_dl,ROM[maria_dll]); */
352         state->maria_dll = (ROM[DPPH] << 8) | ROM[DPPL];
353         state->maria_dl = (READ_MEM(state->maria_dll+1) << 8) | READ_MEM(state->maria_dll+2);
354         state->maria_offset = READ_MEM(state->maria_dll) & 0x0f;
355         state->maria_holey = (READ_MEM(state->maria_dll) & 0x60) >> 5;
356         state->maria_dli = READ_MEM(state->maria_dll) & 0x80;
357         /*  logerror("DLL=%x\n",state->maria_dll); */
358         /*  logerror("DLL: DL = %x  dllctrl = %x\n",state->maria_dl,ROM[state->maria_dll]); */
377359      }
378360
379361      /*logerror( "vblank end on line %d\n", frame_scanline );*/
r9648r9649
383365        this fix made PR Baseball happy
384366        Kung-Fu Master looks worse
385367        don't know about others yet */
386   if( frame_scanline == ( a7800_lines - 4 ) )
368   if( frame_scanline == ( state->lines - 4 ) )
387369   {
388370      /* vblank starts 4 scanlines before end of screen */
389371
390      maria_vblank = 0x80;
372      state->maria_vblank = 0x80;
391373
392374      /* fixed 2002/05/14 kubecj
393375                when going vblank, dma must be stopped
r9648r9649
404386                Jinks
405387        */
406388
407      maria_dodma = 0;
389      state->maria_dodma = 0;
408390      /*logerror( "vblank on line %d\n\n", frame_scanline );*/
409391   }
410392
411393
412   if( ( frame_scanline > 15 ) && maria_dodma )
394   if( ( frame_scanline > 15 ) && state->maria_dodma )
413395   {
414      if (maria_scanline < ( a7800_lines - 4 ) )
396      if (state->maria_scanline < ( state->lines - 4 ) )
415397         maria_draw_scanline(device->machine);
416398
417      if( maria_offset == 0 )
399      if( state->maria_offset == 0 )
418400      {
419         maria_dll+=3;
420         maria_dl = (READ_MEM(maria_dll+1) << 8) | READ_MEM(maria_dll+2);
421         maria_offset = READ_MEM(maria_dll) & 0x0f;
422         maria_holey = (READ_MEM(maria_dll) & 0x60) >> 5;
423         maria_dli = READ_MEM(maria_dll) & 0x80;
401         state->maria_dll+=3;
402         state->maria_dl = (READ_MEM(state->maria_dll+1) << 8) | READ_MEM(state->maria_dll+2);
403         state->maria_offset = READ_MEM(state->maria_dll) & 0x0f;
404         state->maria_holey = (READ_MEM(state->maria_dll) & 0x60) >> 5;
405         state->maria_dli = READ_MEM(state->maria_dll) & 0x80;
424406      }
425407      else
426408      {
427         maria_offset--;
409         state->maria_offset--;
428410      }
429411   }
430412
431   if( maria_dli )
413   if( state->maria_dli )
432414   {
433415      /*logerror( "dli on line %d [%02X] [%02X] [%02X]\n", frame_scanline, ROM[0x7E], ROM[0x7C], ROM[0x7D] );*/
434416   }
435417
436   if( maria_dli )
418   if( state->maria_dli )
437419   {
438      maria_dli = 0;
420      state->maria_dli = 0;
439421      cpu_set_input_line(device, INPUT_LINE_NMI, PULSE_LINE);
440422   }
441423
r9648r9649
449431/* This routine is called at the start of vblank to refresh the screen */
450432VIDEO_UPDATE( a7800 )
451433{
452   maria_scanline = 0;
434   a7800_state *state = screen->machine->driver_data<a7800_state>();
435   state->maria_scanline = 0;
453436   VIDEO_UPDATE_CALL(generic_bitmapped);
454437   return 0;
455438}
r9648r9649
459442
460443 READ8_HANDLER( a7800_MARIA_r )
461444{
445   a7800_state *state = space->machine->driver_data<a7800_state>();
462446   UINT8 *ROM = memory_region(space->machine, "maincpu");
463447   switch (offset)
464448   {
465449      case 0x08:
466         return maria_vblank;
450         return state->maria_vblank;
467451
468452      default:
469453         logerror("undefined MARIA read %x\n",offset);
r9648r9649
473457
474458WRITE8_HANDLER( a7800_MARIA_w )
475459{
460   a7800_state *state = space->machine->driver_data<a7800_state>();
476461   UINT8 *ROM = memory_region(space->machine, "maincpu");
477462   switch (offset)
478463   {
479464      case 0x00:
480         maria_backcolor = data;
481         // 20030621 ericball added maria_palette[pal][0] to make kanagroo mode easier
482         maria_palette[0][0]=maria_backcolor;
483         maria_palette[1][0]=maria_backcolor;
484         maria_palette[2][0]=maria_backcolor;
485         maria_palette[3][0]=maria_backcolor;
486         maria_palette[4][0]=maria_backcolor;
487         maria_palette[5][0]=maria_backcolor;
488         maria_palette[6][0]=maria_backcolor;
489         maria_palette[7][0]=maria_backcolor;
465         state->maria_backcolor = data;
466         // 20030621 ericball added state->maria_palette[pal][0] to make kanagroo mode easier
467         state->maria_palette[0][0]=state->maria_backcolor;
468         state->maria_palette[1][0]=state->maria_backcolor;
469         state->maria_palette[2][0]=state->maria_backcolor;
470         state->maria_palette[3][0]=state->maria_backcolor;
471         state->maria_palette[4][0]=state->maria_backcolor;
472         state->maria_palette[5][0]=state->maria_backcolor;
473         state->maria_palette[6][0]=state->maria_backcolor;
474         state->maria_palette[7][0]=state->maria_backcolor;
490475         break;
491476      case 0x01:
492         maria_palette[0][1] = data;
477         state->maria_palette[0][1] = data;
493478         break;
494479      case 0x02:
495         maria_palette[0][2] = data;
480         state->maria_palette[0][2] = data;
496481         break;
497482      case 0x03:
498         maria_palette[0][3] = data;
483         state->maria_palette[0][3] = data;
499484         break;
500485      case 0x04:
501486         cpu_spinuntil_trigger(space->machine->device("maincpu"), TRIGGER_HSYNC);
502         maria_wsync=1;
487         state->maria_wsync=1;
503488         break;
504489
505490      case 0x05:
506         maria_palette[1][1] = data;
491         state->maria_palette[1][1] = data;
507492         break;
508493      case 0x06:
509         maria_palette[1][2] = data;
494         state->maria_palette[1][2] = data;
510495         break;
511496      case 0x07:
512         maria_palette[1][3] = data;
497         state->maria_palette[1][3] = data;
513498         break;
514499
515500      case 0x09:
516         maria_palette[2][1] = data;
501         state->maria_palette[2][1] = data;
517502         break;
518503      case 0x0A:
519         maria_palette[2][2] = data;
504         state->maria_palette[2][2] = data;
520505         break;
521506      case 0x0B:
522         maria_palette[2][3] = data;
507         state->maria_palette[2][3] = data;
523508         break;
524509
525510      case 0x0D:
526         maria_palette[3][1] = data;
511         state->maria_palette[3][1] = data;
527512         break;
528513      case 0x0E:
529         maria_palette[3][2] = data;
514         state->maria_palette[3][2] = data;
530515         break;
531516      case 0x0F:
532         maria_palette[3][3] = data;
517         state->maria_palette[3][3] = data;
533518         break;
534519
535520      case 0x11:
536         maria_palette[4][1] = data;
521         state->maria_palette[4][1] = data;
537522         break;
538523      case 0x12:
539         maria_palette[4][2] = data;
524         state->maria_palette[4][2] = data;
540525         break;
541526      case 0x13:
542         maria_palette[4][3] = data;
527         state->maria_palette[4][3] = data;
543528         break;
544529      case 0x14:
545         maria_charbase = (data << 8);
530         state->maria_charbase = (data << 8);
546531         break;
547532      case 0x15:
548         maria_palette[5][1] = data;
533         state->maria_palette[5][1] = data;
549534         break;
550535      case 0x16:
551         maria_palette[5][2] = data;
536         state->maria_palette[5][2] = data;
552537         break;
553538      case 0x17:
554         maria_palette[5][3] = data;
539         state->maria_palette[5][3] = data;
555540         break;
556541
557542      case 0x19:
558         maria_palette[6][1] = data;
543         state->maria_palette[6][1] = data;
559544         break;
560545      case 0x1A:
561         maria_palette[6][2] = data;
546         state->maria_palette[6][2] = data;
562547         break;
563548      case 0x1B:
564         maria_palette[6][3] = data;
549         state->maria_palette[6][3] = data;
565550         break;
566551
567552      case 0x1C:
568553         /*logerror("MARIA CTRL=%x\n",data);*/
569         maria_color_kill = data & 0x80;
554         state->maria_color_kill = data & 0x80;
570555         if ((data & 0x60) == 0x40)
571            maria_dmaon = 1;
556            state->maria_dmaon = 1;
572557         else
573            maria_dmaon = maria_dodma = 0;
558            state->maria_dmaon = state->maria_dodma = 0;
574559
575         maria_cwidth = data & 0x10;
576         maria_bcntl = data & 0x08;
577         maria_kangaroo = data & 0x04;
578         maria_rm = data & 0x03;
560         state->maria_cwidth = data & 0x10;
561         state->maria_bcntl = data & 0x08;
562         state->maria_kangaroo = data & 0x04;
563         state->maria_rm = data & 0x03;
579564
580565         /*logerror( "MARIA CTRL: CK:%d DMA:%d CW:%d BC:%d KM:%d RM:%d\n",
581                    maria_color_kill ? 1 : 0,
566                    state->maria_color_kill ? 1 : 0,
582567                    ( data & 0x60 ) >> 5,
583                    maria_cwidth ? 1 : 0,
584                    maria_bcntl ? 1 : 0,
585                    maria_kangaroo ? 1 : 0,
586                    maria_rm );*/
568                    state->maria_cwidth ? 1 : 0,
569                    state->maria_bcntl ? 1 : 0,
570                    state->maria_kangaroo ? 1 : 0,
571                    state->maria_rm );*/
587572
588573         break;
589574      case 0x1D:
590         maria_palette[7][1] = data;
575         state->maria_palette[7][1] = data;
591576         break;
592577      case 0x1E:
593         maria_palette[7][2] = data;
578         state->maria_palette[7][2] = data;
594579         break;
595580      case 0x1F:
596         maria_palette[7][3] = data;
581         state->maria_palette[7][3] = data;
597582         break;
598583   }
599584   ROM[ 0x20 + offset ] = data;
src/mess/video/avigo.c
r9648r9649
1515
1616/* mem size = 0x017c0 */
1717
18static UINT8 *avigo_video_memory;
1918
2019/* current column to read/write */
21static UINT8 avigo_screen_column = 0;
2220
2321#define AVIGO_VIDEO_DEBUG 0
2422#define LOG(x) do { if (AVIGO_VIDEO_DEBUG) logerror x; } while (0)
2523
26static int stylus_x;
27static int stylus_y;
2824
2925static const gfx_layout pointerlayout =
3026{
r9648r9649
4339   0xf0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00   /* whitemask */
4440};
4541
46static gfx_element *stylus_pointer;
47
48void avigo_vh_set_stylus_marker_position(int x,int y)
42void avigo_vh_set_stylus_marker_position(running_machine *machine, int x, int y)
4943{
50   stylus_x = x;
51   stylus_y = y;
44   avigo_state *state = machine->driver_data<avigo_state>();
45   state->stylus_x = x;
46   state->stylus_y = y;
5247}
5348
5449READ8_HANDLER(avigo_vid_memory_r)
5550{
51   avigo_state *state = space->machine->driver_data<avigo_state>();
5652   if (!offset)
57      return avigo_screen_column;
53      return state->screen_column;
5854
5955   if ((offset<0x0100) || (offset>=0x01f0))
6056   {
r9648r9649
6359   }
6460
6561   /* 0x0100-0x01f0 contains data for selected column */
66   return avigo_video_memory[avigo_screen_column + ((offset&0xff)*(AVIGO_SCREEN_WIDTH>>3))];
62   return state->video_memory[state->screen_column + ((offset&0xff)*(AVIGO_SCREEN_WIDTH>>3))];
6763}
6864
6965WRITE8_HANDLER(avigo_vid_memory_w)
7066{
67   avigo_state *state = space->machine->driver_data<avigo_state>();
7168   if (!offset)
7269   {
7370      /* select column to read/write */
74      avigo_screen_column = data;
71      state->screen_column = data;
7572
7673      LOG(("vid mem column write: %02x\n",data));
7774
r9648r9649
9087
9188
9289   /* 0x0100-0x01f0 contains data for selected column */
93   avigo_video_memory[avigo_screen_column + ((offset&0xff)*(AVIGO_SCREEN_WIDTH>>3))] = data;
90   state->video_memory[state->screen_column + ((offset&0xff)*(AVIGO_SCREEN_WIDTH>>3))] = data;
9491}
9592
9693VIDEO_START( avigo )
9794{
95   avigo_state *state = machine->driver_data<avigo_state>();
9896   /* current selected column to read/write */
99   avigo_screen_column = 0;
97   state->screen_column = 0;
10098
10199   /* allocate video memory */
102   avigo_video_memory = auto_alloc_array(machine, UINT8, ((AVIGO_SCREEN_WIDTH>>3)*AVIGO_SCREEN_HEIGHT+1));
103   machine->gfx[0] = stylus_pointer = gfx_element_alloc(machine, &pointerlayout, pointermask, machine->total_colors() / 16, 0);
100   state->video_memory = auto_alloc_array_clear(machine, UINT8, ((AVIGO_SCREEN_WIDTH>>3)*AVIGO_SCREEN_HEIGHT+1));
101   machine->gfx[0] = gfx_element_alloc(machine, &pointerlayout, pointermask, machine->total_colors() / 16, 0);
104102
105   stylus_pointer->total_colors = 3;
103   machine->gfx[0]->total_colors = 3;
106104}
107105
108106/* Initialise the palette */
r9648r9649
122120***************************************************************************/
123121VIDEO_UPDATE( avigo )
124122{
123   avigo_state *state = screen->machine->driver_data<avigo_state>();
125124   int y;
126125   int b;
127126   int x;
r9648r9649
131130   for (y=0; y<AVIGO_SCREEN_HEIGHT; y++)
132131   {
133132      int by;
134      unsigned char *line_ptr = avigo_video_memory +  (y*(AVIGO_SCREEN_WIDTH>>3));
133      unsigned char *line_ptr = state->video_memory +  (y*(AVIGO_SCREEN_WIDTH>>3));
135134
136135      x = 0;
137136      for (by=((AVIGO_SCREEN_WIDTH>>3)-1); by>=0; by--)
r9648r9649
160159   r.max_y = AVIGO_SCREEN_HEIGHT;
161160
162161   /* draw stylus marker */
163   drawgfx_transpen (bitmap, &r, stylus_pointer, 0, 0, 0, 0, stylus_x, stylus_y, 0);
162   drawgfx_transpen (bitmap, &r, screen->machine->gfx[0], 0, 0, 0, 0, state->stylus_x, state->stylus_y, 0);
164163#if 0
165164   {
166165
src/mess/includes/apple2gs.h
r9648r9649
2121#define BORDER_TOP   (16)   // (plus bottom)
2222
2323
24/*----------- defined in machine/apple2gs.c -----------*/
24typedef enum
25{
26   CLOCKMODE_IDLE,
27   CLOCKMODE_TIME,
28   CLOCKMODE_INTERNALREGS,
29   CLOCKMODE_BRAM1,
30   CLOCKMODE_BRAM2
31} apple2gs_clock_mode;
2532
26extern UINT8 *apple2gs_slowmem;
27extern UINT8 apple2gs_newvideo;
2833
29extern UINT8 apple2gs_docram[64*1024];
34typedef enum
35{
36   ADBSTATE_IDLE,
37   ADBSTATE_INCOMMAND,
38   ADBSTATE_INRESPONSE
39} adbstate_t;
3040
41
42class apple2gs_state : public driver_device
43{
44public:
45   apple2gs_state(running_machine &machine, const driver_device_config_base &config)
46      : driver_device(machine, config) { }
47
48   UINT8 *slowmem;
49   UINT8 newvideo;
50   UINT8 docram[64*1024];
51   UINT16 bordercolor;
52   UINT8 vgcint;
53   UINT8 langsel;
54   UINT8 sltromsel;
55   UINT8 cyareg;
56   UINT8 inten;
57   UINT8 intflag;
58   UINT8 shadow;
59   UINT8 pending_irqs;
60   UINT8 mouse_x;
61   UINT8 mouse_y;
62   INT8 mouse_dx;
63   INT8 mouse_dy;
64   running_device *cur_slot6_image;
65   emu_timer *scanline_timer;
66   emu_timer *clock_timer;
67   emu_timer *qsecond_timer;
68   UINT8 clock_data;
69   UINT8 clock_control;
70   UINT8 clock_read;
71   UINT8 clock_reg1;
72   apple2gs_clock_mode clock_mode;
73   UINT32 clock_curtime;
74   seconds_t clock_curtime_interval;
75   UINT8 clock_bram[256];
76   adbstate_t adb_state;
77   UINT8 adb_command;
78   UINT8 adb_mode;
79   UINT8 adb_kmstatus;
80   UINT8 adb_latent_result;
81   INT32 adb_command_length;
82   INT32 adb_command_pos;
83   UINT8 adb_command_bytes[8];
84   UINT8 adb_response_bytes[8];
85   UINT8 adb_response_length;
86   INT32 adb_response_pos;
87   UINT8 adb_memory[0x100];
88   int adb_address_keyboard;
89   int adb_address_mouse;
90   UINT8 sndglu_ctrl;
91   int sndglu_addr;
92   int sndglu_dummy_read;
93   bitmap_t *legacy_gfx;
94};
95
96
97/*----------- defined in machine/apple2gs.c -----------*/
98
3199MACHINE_START( apple2gs );
32100MACHINE_RESET( apple2gs );
33101
r9648r9649
38106
39107/*----------- defined in video/apple2gs.c -----------*/
40108
41extern UINT16 apple2gs_bordercolor;
42
43109VIDEO_START( apple2gs );
44110VIDEO_UPDATE( apple2gs );
45111
src/mess/includes/apple3.h
r9648r9649
2222#define VAR_EXTSIDE      0x0080
2323
2424
25class apple3_state : public driver_device
26{
27public:
28   apple3_state(running_machine &machine, const driver_device_config_base &config)
29      : driver_device(machine, config) { }
30
31   UINT32 flags;
32   UINT8 via_0_a;
33   UINT8 via_0_b;
34   UINT8 via_1_a;
35   UINT8 via_1_b;
36   int via_1_irq;
37   int enable_mask;
38   offs_t zpa;
39   int profile_lastaddr;
40   UINT8 profile_gotstrobe;
41   UINT8 profile_readdata;
42   UINT8 profile_busycount;
43   UINT8 profile_busy;
44   UINT8 profile_online;
45   UINT8 profile_writedata;
46   UINT8 last_n;
47   UINT8 *char_mem;
48   UINT32 *hgr_map;
49};
50
51
2552/*----------- defined in machine/apple3.c -----------*/
2653
27extern UINT32 apple3_flags;
2854extern const applefdc_interface apple3_fdc_interface;
2955extern const via6522_interface apple3_via_0_intf;
3056extern const via6522_interface apple3_via_1_intf;
src/mess/includes/adam.h
r9648r9649
88#define ADAM_H_
99
1010
11class adam_state : public driver_device
12{
13public:
14   adam_state(running_machine &machine, const driver_device_config_base &config)
15      : driver_device(machine, config) { }
16
17   int last_state;
18   int lower_memory;
19   int upper_memory;
20   int joy_stat[2];
21   int net_data;
22   int pcb;
23   int joy_mode;
24   int KeyboardBuffer[20];
25   UINT8 KbRepeatTable[256];
26};
27
28
1129/*----------- defined in drivers/adam.c -----------*/
1230
1331void adam_set_memory_banks(running_machine *machine);
r9648r9649
1634
1735/*----------- defined in machine/adam.c -----------*/
1836
19extern int adam_lower_memory; /* Lower 32k memory Z80 address configuration */
20extern int adam_upper_memory; /* Upper 32k memory Z80 address configuration */
21extern int adam_joy_stat[2];
22extern int adam_net_data; /* Data on AdamNet Bus */
23extern int adam_pcb;
24
2537//int adam_cart_verify(const UINT8 *buf, size_t size);
2638
27void adam_clear_keyboard_buffer(void);
39void adam_clear_keyboard_buffer(running_machine *machine);
2840void adam_explore_keyboard(running_machine *machine);
2941
3042READ8_HANDLER  ( adamnet_r );
src/mess/includes/aim65.h
r9648r9649
2121#define AIM65_CLOCK  XTAL_4MHz/4
2222
2323
24class aim65_state : public driver_device
25{
26public:
27   aim65_state(running_machine &machine, const driver_device_config_base &config)
28      : driver_device(machine, config) { }
29
30   UINT8 pia_a;
31   UINT8 pia_b;
32   UINT8 riot_port_a;
33   int printer_x;
34   int printer_y;
35   int printer_dir;
36   int flag_a;
37   int flag_b;
38   emu_timer *print_timer;
39   int printer_level;
40};
41
42
2443/*----------- defined in machine/aim65.c -----------*/
2544
2645void aim65_update_ds1(running_device *device, int digit, int data);
src/mess/includes/aquarius.h
r9648r9649
1414      : driver_device(machine, config) { }
1515
1616   UINT8 *videoram;
17   UINT8 scrambler;
18   UINT8 *colorram;
19   tilemap_t *tilemap;
1720};
1821
1922
2023/*----------- defined in video/aquarius.c -----------*/
2124
22extern UINT8 *aquarius_colorram;
2325WRITE8_HANDLER( aquarius_videoram_w );
2426WRITE8_HANDLER( aquarius_colorram_w );
2527
src/mess/includes/atom.h
r9648r9649
4242   /* devices */
4343   running_device *mc6847;
4444   running_device *cassette;
45   int previous_i8271_int_state;
4546};
4647
4748#endif
src/mess/includes/apple1.h
r9648r9649
1010#include "devices/snapquik.h"
1111#include "machine/6821pia.h"
1212
13typedef short termchar_t;
1314
15typedef struct
16{
17   tilemap_t *tm;
18   int gfx;
19   int blank_char;
20   int char_bits;
21   int num_cols;
22   int num_rows;
23   int (*getcursorcode)(int original_code);
24   int cur_offset;
25   int cur_hidden;
26   termchar_t mem[1];
27} terminal_t;
28
29
30class apple1_state : public driver_device
31{
32public:
33   apple1_state(running_machine &machine, const driver_device_config_base &config)
34      : driver_device(machine, config) { }
35
36   int vh_clrscrn_pressed;
37   int kbd_data;
38   UINT32 kbd_last_scan[4];
39   int reset_flag;
40   int cassette_output_flipflop;
41   terminal_t *current_terminal;
42   terminal_t *terminal;
43   int blink_on;
44};
45
46
1447/*----------- defined in machine/apple1.c -----------*/
1548
1649extern const pia6821_interface apple1_pia0;
r9648r9649
2861VIDEO_START( apple1 );
2962VIDEO_UPDATE( apple1 );
3063
31void apple1_vh_dsp_w (int data);
32void apple1_vh_dsp_clr (void);
64void apple1_vh_dsp_w (running_machine *machine, int data);
65void apple1_vh_dsp_clr (running_machine *machine);
3366attotime apple1_vh_dsp_time_to_ready (running_machine *machine);
3467
35extern int apple1_vh_clrscrn_pressed;
3668
3769
3870/*----------- defined in drivers/apple1.c -----------*/
src/mess/includes/a7800.h
r9648r9649
99
1010#include "machine/6532riot.h"
1111
12class a7800_state : public driver_device
13{
14public:
15   a7800_state(running_machine &machine, const driver_device_config_base &config)
16      : driver_device(machine, config) { }
17
18   int lines;
19   int ispal;
20   unsigned char *cart_bkup;
21   unsigned char *bios_bkup;
22   int ctrl_lock;
23   int ctrl_reg;
24   int maria_flag;
25   unsigned char *cartridge_rom;
26   unsigned int cart_type;
27   unsigned long cart_size;
28   unsigned char stick_type;
29   UINT8 *ROM;
30   int maria_palette[8][4];
31   int maria_write_mode;
32   int maria_scanline;
33   unsigned int maria_dll;
34   unsigned int maria_dl;
35   int maria_holey;
36   int maria_offset;
37   int maria_vblank;
38   int maria_dli;
39   int maria_dmaon;
40   int maria_dodma;
41   int maria_wsync;
42   int maria_backcolor;
43   int maria_color_kill;
44   int maria_cwidth;
45   int maria_bcntl;
46   int maria_kangaroo;
47   int maria_rm;
48   unsigned int maria_charbase;
49};
50
51
1252/*----------- defined in video/a7800.c -----------*/
1353
1454VIDEO_START( a7800 );
r9648r9649
2262
2363extern const riot6532_interface a7800_r6532_interface;
2464
25extern int a7800_lines;
26extern int a7800_ispal;
2765
2866MACHINE_RESET( a7800 );
2967
src/mess/includes/amstrad.h
r9648r9649
1111#include "video/mc6845.h"
1212#include "devices/snapquik.h"
1313
14/****************************
15 * Gate Array data (CPC) -
16 ****************************/
17typedef struct
18{
19   bitmap_t   *bitmap;      /* The bitmap we work on */
20   UINT8   pen_selected;      /* Pen selection */
21   UINT8   mrer;            /* Mode and ROM Enable Register */
22   UINT8   upper_bank;
23
24   /* input signals from CRTC */
25   int      vsync;
26   int      hsync;
27   int      de;
28   int      ma;
29   int      ra;
30
31   /* used for timing */
32   int      hsync_after_vsync_counter;
33   int      hsync_counter;            /* The gate array counts CRTC HSYNC pulses using an internal 6-bit counter. */
34
35   /* used for drawing the screen */
36   attotime   last_draw_time;
37   int      y;
38   UINT16   *draw_p;               /* Position in the bitmap where we are currently drawing */
39   UINT16   colour;
40   UINT16   address;
41   UINT8   *mode_lookup;
42   UINT8   data;
43   UINT8   ticks;
44   UINT8   ticks_increment;
45   UINT16   line_ticks;
46   UINT8   colour_ticks;
47   UINT8   max_colour_ticks;
48} gate_array_t;
49
50/****************************
51 * ASIC data (CPC plus)
52 ****************************/
53typedef struct
54{
55   UINT8   *ram;            /* pointer to RAM used for the CPC+ ASIC memory-mapped registers */
56   UINT8   enabled;         /* Are CPC plus features enabled/unlocked */
57   UINT8   pri;            /* Programmable raster interrupt */
58   UINT8   seqptr;            /* Current position in the ASIC unlocking sequence */
59   UINT8   rmr2;            /* ROM mapping register 2 */
60   UINT16   split_ma_base;      /* Used to handle split screen support */
61   UINT16   split_ma_started;   /* Used to handle split screen support */
62   UINT16   vpos;            /* Current logical scanline */
63   UINT16   h_start;         /* Position where DE became active */
64   UINT16   h_end;            /* Position where DE became inactive */
65   UINT8   addr_6845;         /* We need these to store a shadow copy of R1 of the mc6845 */
66   UINT8   horiz_disp;
67   UINT8   hscroll;
68   UINT8   de_start;          /* flag to check if DE is been enabled this frame yet */
69
70   /* DMA */
71   UINT8   dma_status;
72   UINT8   dma_clear;         /* Set if DMA interrupts are to be cleared automatically */
73   UINT8   dma_prescaler[3];   /* DMA channel prescaler */
74   UINT16   dma_repeat[3];      /* Location of the DMA channel's last repeat */
75   UINT16   dma_addr[3];      /* DMA channel address */
76   UINT16   dma_loopcount[3];   /* Count loops taken on this channel */
77   UINT16   dma_pause[3];      /* DMA pause count */
78} asic_t;
79
80
81class amstrad_state : public driver_device
82{
83public:
84   amstrad_state(running_machine &machine, const driver_device_config_base &config)
85      : driver_device(machine, config) { }
86
87   int system_type;
88   UINT8 aleste_mode;
89   int plus_irq_cause;
90   gate_array_t gate_array;
91   asic_t asic;
92   int GateArray_RamConfiguration;
93   unsigned char *AmstradCPC_RamBanks[4];
94   unsigned char *Aleste_RamBanks[4];
95   int aleste_active_page[4];
96   unsigned char *Amstrad_ROM_Table[256];
97   UINT8 ppi_port_inputs[3];
98   UINT8 ppi_port_outputs[3];
99   int aleste_rtc_function;
100   int aleste_fdc_int;
101   int prev_reg;
102   UINT16 GateArray_render_colours[17];
103   UINT8 mode0_lookup[256];
104   UINT8 mode1_lookup[256];
105   UINT8 mode2_lookup[256];
106   unsigned char *multiface_ram;
107   unsigned long multiface_flags;
108   int prev_data;
109   int printer_bit8_selected;
110   unsigned char Psg_FunctionSelected;
111   int previous_ppi_portc_w;
112};
113
114
14115/*----------- defined in machine/amstrad.c -----------*/
15116
16117READ8_HANDLER ( amstrad_cpc_io_r );
src/mess/includes/avigo.h
r9648r9649
77#ifndef AVIGO_H_
88#define AVIGO_H_
99
10#include "machine/intelfsh.h"
1011
1112#define AVIGO_NUM_COLOURS 2
1213
r9648r9649
1415#define AVIGO_SCREEN_HEIGHT       240
1516
1617
18class avigo_state : public driver_device
19{
20public:
21   avigo_state(running_machine &machine, const driver_device_config_base &config)
22      : driver_device(machine, config) { }
23
24   UINT8 key_line;
25   UINT8 irq;
26   UINT8 speaker_data;
27   unsigned long ram_bank_l;
28   unsigned long ram_bank_h;
29   unsigned long rom_bank_l;
30   unsigned long rom_bank_h;
31   unsigned long ad_control_status;
32   intelfsh8_device *flashes[3];
33   int flash_at_0x4000;
34   int flash_at_0x8000;
35   void *banked_opbase[4];
36   int previous_input_port_data[4];
37   int stylus_marker_x;
38   int stylus_marker_y;
39   int stylus_press_x;
40   int stylus_press_y;
41   int ox;
42   int oy;
43   unsigned int ad_value;
44   UINT8 *video_memory;
45   UINT8 screen_column;
46   int stylus_x;
47   int stylus_y;
48   gfx_element *stylus_pointer;
49};
50
51
1752/*----------- defined in video/avigo.c -----------*/
1853
1954extern  READ8_HANDLER(avigo_vid_memory_r);
r9648r9649
2358extern VIDEO_UPDATE( avigo );
2459extern PALETTE_INIT( avigo );
2560
26void avigo_vh_set_stylus_marker_position(int x,int y);
61void avigo_vh_set_stylus_marker_position(running_machine *machine, int x, int y);
2762
2863
2964#endif /* AVIGO_H_ */
src/mess/includes/apple2.h
r9648r9649
104104
105105/*----------- defined in drivers/apple2.c -----------*/
106106
107MACHINE_CONFIG_EXTERN( apple2e );
108107INPUT_PORTS_EXTERN( apple2ep );
109108PALETTE_INIT( apple2 );
110109
src/mess/drivers/apple3.c
r9648r9649
7575   NULL
7676};
7777
78static MACHINE_CONFIG_START( apple3, driver_device )
78static MACHINE_CONFIG_START( apple3, apple3_state )
7979   /* basic machine hardware */
8080   MDRV_CPU_ADD("maincpu", M6502, 2000000)        /* 2 MHz */
8181   MDRV_CPU_PROGRAM_MAP(apple3_map)
src/mess/drivers/adam.c
r9648r9649
424424
425425static INTERRUPT_GEN( adam_interrupt )
426426{
427    TMS9928A_interrupt(device->machine);
428    adam_explore_keyboard(device->machine);
427   TMS9928A_interrupt(device->machine);
428   adam_explore_keyboard(device->machine);
429429}
430430
431static void adam_vdp_interrupt (running_machine *machine, int state)
431static void adam_vdp_interrupt(running_machine *machine, int state)
432432{
433   static int last_state = 0;
434
435    /* only if it goes up */
436   if (state && !last_state)
437    {
438        cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
439    }
440   last_state = state;
433   adam_state *drvstate = machine->driver_data<adam_state>();
434   /* only if it goes up */
435   if (state && !drvstate->last_state)
436   {
437      cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
438   }
439   drvstate->last_state = state;
441440}
442441
443442static TIMER_CALLBACK(adam_paddle_callback)
444443{
444   adam_state *state = machine->driver_data<adam_state>();
445445   int port7 = input_port_read(machine, "controller1_analog");
446446   int port8 = input_port_read(machine, "controller2_analog");
447447
448448   if (port7 == 0)
449      adam_joy_stat[0] = 0;
449      state->joy_stat[0] = 0;
450450   else if (port7 & 0x08)
451      adam_joy_stat[0] = -1;
451      state->joy_stat[0] = -1;
452452   else
453      adam_joy_stat[0] = 1;
453      state->joy_stat[0] = 1;
454454
455455   if (port8 == 0)
456      adam_joy_stat[1] = 0;
456      state->joy_stat[1] = 0;
457457   else if (port8 & 0x08)
458      adam_joy_stat[1] = -1;
458      state->joy_stat[1] = -1;
459459   else
460      adam_joy_stat[1] = 1;
460      state->joy_stat[1] = 1;
461461
462   if (adam_joy_stat[0] || adam_joy_stat[1])
462   if (state->joy_stat[0] || state->joy_stat[1])
463463      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
464464}
465465
466466void adam_set_memory_banks(running_machine *machine)
467467{
468   adam_state *state = machine->driver_data<adam_state>();
468469/*
469470Lineal virtual memory map:
470471
r9648r9649
481482   UINT8 *BankBase;
482483   BankBase = &memory_region(machine, "maincpu")[0x00000];
483484
484   switch (adam_lower_memory)
485   switch (state->lower_memory)
485486   {
486487      case 0: /* SmartWriter ROM */
487         if (adam_net_data & 0x02)
488         if (state->net_data & 0x02)
488489         {
489490            /* Read */
490491            memory_set_bankptr(machine, "bank1", BankBase+0x32000); /* No data here */
r9648r9649
553554         memory_set_bankptr(machine, "bank9", BankBase+0x06000);
554555   }
555556
556   switch (adam_upper_memory)
557   switch (state->upper_memory)
557558   {
558559      case 0: /* Internal RAM */
559560         /* Read */
r9648r9649
577578
578579void adam_reset_pcb(running_machine *machine)
579580{
580    int i;
581    memory_region(machine, "maincpu")[adam_pcb] = 0x01;
581   adam_state *state = machine->driver_data<adam_state>();
582   int i;
583   memory_region(machine, "maincpu")[state->pcb] = 0x01;
582584
583585   for (i = 0; i < 15; i++)
584      memory_region(machine, "maincpu")[(adam_pcb+4+i*21)&0xFFFF]=i+1;
586      memory_region(machine, "maincpu")[(state->pcb+4+i*21)&0xFFFF]=i+1;
585587}
586588
587589static const TMS9928a_interface tms9928a_interface =
r9648r9649
600602
601603static MACHINE_RESET( adam )
602604{
605   adam_state *state = machine->driver_data<adam_state>();
603606   device_image_interface *image = dynamic_cast<device_image_interface *>(machine->device("cart"));
604607
605608   if (image->exists())
606609   {
607610      /* ColecoVision Mode Reset (Cartridge Mounted) */
608      adam_lower_memory = 3; /* OS7 + 24k RAM */
609      adam_upper_memory = 3; /* Cartridge ROM */
611      state->lower_memory = 3; /* OS7 + 24k RAM */
612      state->upper_memory = 3; /* Cartridge ROM */
610613   }
611614   else
612615   {
613616      /* Adam Mode Reset */
614      adam_lower_memory = 0; /* SmartWriter ROM/EOS */
615      adam_upper_memory = 0; /* Internal RAM */
617      state->lower_memory = 0; /* SmartWriter ROM/EOS */
618      state->upper_memory = 0; /* Internal RAM */
616619   }
617620
618   adam_net_data = 0;
621   state->net_data = 0;
619622   adam_set_memory_banks(machine);
620   adam_pcb=0xFEC0;
621   adam_clear_keyboard_buffer();
623   state->pcb=0xFEC0;
624   adam_clear_keyboard_buffer(machine);
622625
623626   memset(&memory_region(machine, "maincpu")[0x0000], 0xFF, 0x20000); /* Initializing RAM */
624627}
r9648r9649
635638   NULL
636639};
637640
638static MACHINE_CONFIG_START( adam, driver_device )
641static MACHINE_CONFIG_START( adam, adam_state )
639642   /* Machine hardware */
640643   MDRV_CPU_ADD("maincpu", Z80, 3579545)       /* 3.579545 MHz */
641644   MDRV_CPU_PROGRAM_MAP(adam_mem)
642645   MDRV_CPU_IO_MAP(adam_io)
643646
644    /* Master M6801 AdamNet controller */
647   /* Master M6801 AdamNet controller */
645648   //MDRV_CPU_ADD("adamnet", M6800, 4000000)       /* 4.0 MHz */
646649   //MDRV_CPU_PROGRAM_MAP(master6801_mem, 0)
647650
r9648r9649
650653   MDRV_MACHINE_START( adam )
651654   MDRV_MACHINE_RESET( adam )
652655
653    /* video hardware */
656   /* video hardware */
654657   MDRV_FRAGMENT_ADD(tms9928a)
655658   MDRV_SCREEN_MODIFY("screen")
656659   MDRV_SCREEN_REFRESH_RATE(50)
src/mess/drivers/aim65.c
r9648r9649
187187    MACHINE DRIVERS
188188***************************************************************************/
189189
190static MACHINE_CONFIG_START( aim65, driver_device )
190static MACHINE_CONFIG_START( aim65, aim65_state )
191191   /* basic machine hardware */
192192   MDRV_CPU_ADD("maincpu", M6502, AIM65_CLOCK) /* 1 MHz */
193193   MDRV_CPU_PROGRAM_MAP(aim65_mem)
src/mess/drivers/a7800.c
r9648r9649
250250    MACHINE DRIVERS
251251***************************************************************************/
252252
253static MACHINE_CONFIG_START( a7800_ntsc, driver_device )
253static MACHINE_CONFIG_START( a7800_ntsc, a7800_state )
254254   /* basic machine hardware */
255255   MDRV_CPU_ADD("maincpu", M6502, A7800_NTSC_Y1/8)   /* 1.79 MHz (switches to 1.19 MHz on TIA or RIOT access) */
256256   MDRV_CPU_PROGRAM_MAP(a7800_mem)
src/mess/drivers/amstrad.c
r9648r9649
870870   MDRV_SOFTWARE_LIST_ADD("cart_list","gx4000")
871871MACHINE_CONFIG_END
872872
873static MACHINE_CONFIG_START( amstrad, driver_device )
873static MACHINE_CONFIG_START( amstrad, amstrad_state )
874874   /* Machine hardware */
875875   MDRV_CPU_ADD("maincpu", Z80, XTAL_16MHz / 4)
876876   MDRV_CPU_PROGRAM_MAP(amstrad_mem)
r9648r9649
932932MACHINE_CONFIG_END
933933
934934
935static MACHINE_CONFIG_START( cpcplus, driver_device )
935static MACHINE_CONFIG_START( cpcplus, amstrad_state )
936936   /* Machine hardware */
937937   MDRV_CPU_ADD("maincpu", Z80, XTAL_40MHz / 10)
938938   MDRV_CPU_PROGRAM_MAP(amstrad_mem)
r9648r9649
988988MACHINE_CONFIG_END
989989
990990
991static MACHINE_CONFIG_START( gx4000, driver_device )
991static MACHINE_CONFIG_START( gx4000, amstrad_state )
992992   /* Machine hardware */
993993   MDRV_CPU_ADD("maincpu", Z80, XTAL_40MHz / 10)
994994   MDRV_CPU_PROGRAM_MAP(amstrad_mem)
src/mess/drivers/apple2gs.c
r9648r9649
5858#include "machine/8530scc.h"
5959#include "sound/ay8910.h"
6060#include "sound/speaker.h"
61#include "devices/cassette.h"
6162#include "devices/messram.h"
63#include "deprecat.h"
6264
6365static const gfx_layout apple2gs_text_layout =
6466{
r9648r9649
125127/* Initialize the palette */
126128static PALETTE_INIT( apple2gs )
127129{
128   extern PALETTE_INIT( apple2 );
129130   int i;
130131
131132   PALETTE_INIT_CALL(apple2);
r9648r9649
148149{
149150   apple2gs_doc_irq,
150151   apple2gs_adc_read,
151   apple2gs_docram
152   NULL
152153};
153154
154155#ifdef UNUSED_FUNCTION
r9648r9649
216217   NULL
217218};
218219
219static MACHINE_CONFIG_DERIVED( apple2gs, apple2e )
220   MDRV_CPU_REPLACE("maincpu", G65816, APPLE2GS_14M/5)
220static const cassette_config apple2gs_cassette_config =
221{
222   cassette_default_formats,
223   NULL,
224   (cassette_state)(CASSETTE_STOPPED),
225   NULL
226};
221227
222   MDRV_SCREEN_MODIFY("screen")
228static ADDRESS_MAP_START( apple2gs_map, ADDRESS_SPACE_PROGRAM, 8 )
229   /* nothing in the address map - everything is added dynamically */
230ADDRESS_MAP_END
231
232
233static const ay8910_interface apple2_ay8910_interface =
234{
235   AY8910_LEGACY_OUTPUT,
236   AY8910_DEFAULT_LOADS,
237   DEVCB_NULL
238};
239
240static MACHINE_CONFIG_START( apple2gs, apple2gs_state )
241   /* basic machine hardware */
242   MDRV_CPU_ADD("maincpu", G65816, APPLE2GS_14M/5)
243   MDRV_CPU_PROGRAM_MAP(apple2gs_map)
244   MDRV_CPU_VBLANK_INT_HACK(apple2_interrupt, 192/8)
245   MDRV_QUANTUM_TIME(HZ(60))
246
247   MDRV_SCREEN_ADD("screen", RASTER)
248   MDRV_SCREEN_REFRESH_RATE(60)
249   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
250   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
223251   MDRV_SCREEN_SIZE(704, 262)   // 640+32+32 for the borders
224252   MDRV_SCREEN_VISIBLE_AREA(0,703,0,230)
225253   MDRV_PALETTE_LENGTH( 16+256 )
r9648r9649
232260   MDRV_VIDEO_START( apple2gs )
233261   MDRV_VIDEO_UPDATE( apple2gs )
234262
235   MDRV_NVRAM_HANDLER( apple2gs )
236
237   MDRV_SOUND_REPLACE("a2speaker", SPEAKER_SOUND, 0)
263   /* sound hardware */
264   MDRV_SPEAKER_STANDARD_MONO("mono")
265   MDRV_SOUND_ADD("a2speaker", SPEAKER_SOUND, 0)
238266   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
239267   MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
268   MDRV_SOUND_ADD("ay8913.1", AY8913, 1022727)
269   MDRV_SOUND_CONFIG(apple2_ay8910_interface)
270   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
271   MDRV_SOUND_ADD("ay8913.2", AY8913, 1022727)
272   MDRV_SOUND_CONFIG(apple2_ay8910_interface)
273   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
274
240275   MDRV_SOUND_ADD("es5503", ES5503, APPLE2GS_7M)
241276   MDRV_SOUND_CONFIG(apple2gs_es5503_interface)
242277   MDRV_SOUND_ROUTE(0, "lspeaker", 1.0)
243278   MDRV_SOUND_ROUTE(1, "rspeaker", 1.0)
244279
245   /* replace the old-style FDC with an IWM */
246   MDRV_DEVICE_REMOVE("fdc")
280   /* slot devices */
281   MDRV_APPLE2_LANGCARD_ADD("langcard")
282   MDRV_MOCKINGBOARD_ADD("mockingboard")
247283   MDRV_IWM_ADD("fdc", apple2_fdc_interface)
284
285   /* slots */
286   MDRV_APPLE2_SLOT_ADD(0, "langcard", apple2_langcard_r, apple2_langcard_w, 0, 0, 0, 0)
287   MDRV_APPLE2_SLOT_ADD(4, "mockingboard", mockingboard_r, mockingboard_w, 0, 0, 0, 0)
288   MDRV_APPLE2_SLOT_ADD(6, "fdc", applefdc_r, applefdc_w, 0, 0, 0, 0)
289
248290   /* SCC */
249291   MDRV_SCC8530_ADD("scc", APPLE2GS_14M/2)
250292
251   MDRV_FLOPPY_APPLE_2_DRIVES_REMOVE()
252293   MDRV_FLOPPY_APPLE_2_DRIVES_ADD(apple2gs_floppy525_floppy_config,15,16)
253294   MDRV_FLOPPY_SONY_2_DRIVES_ADDITIONAL_ADD(apple2gs_floppy35_floppy_config)
254295
296   MDRV_NVRAM_HANDLER( apple2gs )
297
298   MDRV_CASSETTE_ADD( "cassette", apple2gs_cassette_config )
299
255300   /* internal ram */
256   MDRV_RAM_MODIFY("messram")
301   MDRV_RAM_ADD("messram")
257302   MDRV_RAM_DEFAULT_SIZE("2M")
303   MDRV_RAM_EXTRA_OPTIONS("64K")
304   MDRV_RAM_DEFAULT_VALUE(0x00)
258305MACHINE_CONFIG_END
259306
260307
r9648r9649
329376
330377static DRIVER_INIT(apple2gs)
331378{
332   state_save_register_global_array(machine, apple2gs_docram);
379   apple2gs_state *state = machine->driver_data<apple2gs_state>();
380   es5503_set_base(machine->device("es5503"), state->docram);
381   state_save_register_global_array(machine, state->docram);
333382}
334383
335384/*    YEAR  NAME      PARENT    COMPAT  MACHINE   INPUT       INIT      COMPANY            FULLNAME */
src/mess/drivers/aquarius.c
r9648r9649
4242    GLOBAL VARIABLES
4343***************************************************************************/
4444
45static UINT8 scrambler;
4645
4746
4847/***************************************************************************
r9648r9649
181180*/
182181static WRITE8_HANDLER( scrambler_w )
183182{
184   scrambler = data;
183   aquarius_state *state = space->machine->driver_data<aquarius_state>();
184   state->scrambler = data;
185185}
186186
187187static READ8_HANDLER( cartridge_r )
188188{
189   aquarius_state *state = space->machine->driver_data<aquarius_state>();
189190   UINT8 *rom = memory_region(space->machine, "maincpu") + 0xc000;
190   return rom[offset] ^ scrambler;
191   return rom[offset] ^ state->scrambler;
191192}
192193
193194
r9648r9649
232233static ADDRESS_MAP_START( aquarius_mem, ADDRESS_SPACE_PROGRAM, 8 )
233234   AM_RANGE(0x0000, 0x1fff) AM_ROM
234235   AM_RANGE(0x3000, 0x33ff) AM_RAM_WRITE(aquarius_videoram_w) AM_BASE_MEMBER(aquarius_state, videoram)
235   AM_RANGE(0x3400, 0x37ff) AM_RAM_WRITE(aquarius_colorram_w) AM_BASE(&aquarius_colorram)
236   AM_RANGE(0x3400, 0x37ff) AM_RAM_WRITE(aquarius_colorram_w) AM_BASE_MEMBER(aquarius_state, colorram)
236237   AM_RANGE(0x3800, 0x3fff) AM_RAM
237238   AM_RANGE(0x4000, 0xbfff) AM_NOP /* expansion ram */
238239   AM_RANGE(0xc000, 0xffff) AM_READ(cartridge_r)
src/mess/drivers/atom.c
r9648r9649
558558    i8271_interface fdc_intf
559559-------------------------------------------------*/
560560
561static int previous_i8271_int_state = 0;
562561
563562static void atom_8271_interrupt_callback(running_device *device, int state)
564563{
564   atom_state *drvstate = device->machine->driver_data<atom_state>();
565565   /* I'm assuming that the nmi is edge triggered */
566566   /* a interrupt from the fdc will cause a change in line state, and
567567    the nmi will be triggered, but when the state changes because the int
568568    is cleared this will not cause another nmi */
569569   /* I'll emulate it like this to be sure */
570570
571   if (state!=previous_i8271_int_state)
571   if (state!=drvstate->previous_i8271_int_state)
572572   {
573573      if (state)
574574      {
r9648r9649
578578      }
579579   }
580580
581   previous_i8271_int_state = state;
581   drvstate->previous_i8271_int_state = state;
582582}
583583
584584static const i8271_interface fdc_intf =
src/mess/drivers/apple1.c
r9648r9649
218218};
219219
220220/* machine definition */
221static MACHINE_CONFIG_START( apple1, driver_device )
221static MACHINE_CONFIG_START( apple1, apple1_state )
222222   /* basic machine hardware */
223223   /* Actual CPU speed is 1.023 MHz, but RAM refresh effectively
224224       slows it to 960 kHz. */
src/mess/drivers/avigo.c
r9648r9649
4141#include "emu.h"
4242#include "cpu/z80/z80.h"
4343#include "includes/avigo.h"
44#include "machine/intelfsh.h"
4544#include "machine/tc8521.h"
4645#include "machine/ins8250.h"
4746#include "sound/speaker.h"
4847#include "devices/messram.h"
4948
50static UINT8 avigo_key_line;
5149/*
5250    bit 7:                      ?? high priority. When it occurs, clear this bit.
5351    bit 6: pen int
r9648r9649
6866
6967*/
7068
71static UINT8 avigo_irq;
7269
7370/* bit 3 = speaker state */
74static UINT8 avigo_speaker_data;
7571
7672/* bits 0-5 define bank index */
77static unsigned long avigo_ram_bank_l;
78static unsigned long avigo_ram_bank_h;
7973/* bits 0-5 define bank index */
80static unsigned long avigo_rom_bank_l;
81static unsigned long avigo_rom_bank_h;
82static unsigned long avigo_ad_control_status;
83static intelfsh8_device *avigo_flashes[3];
84static int avigo_flash_at_0x4000;
85static int avigo_flash_at_0x8000;
86static void *avigo_banked_opbase[4];
8774
8875static void avigo_setbank(running_machine *machine, int bank, void *address, read8_space_func rh, write8_space_func wh)
8976{
77   avigo_state *state = machine->driver_data<avigo_state>();
9078   address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
9179   char bank_1[10];
9280   char bank_5[10];
r9648r9649
9785   {
9886      memory_set_bankptr(machine, bank_1, address);
9987      memory_set_bankptr(machine, bank_5, address);
100      avigo_banked_opbase[bank] = ((UINT8 *) address) - (bank * 0x4000);
88      state->banked_opbase[bank] = ((UINT8 *) address) - (bank * 0x4000);
10189   }
10290   if (rh)
10391   {
r9648r9649
116104/* memory 0x0000-0x03fff */
117105static  READ8_HANDLER(avigo_flash_0x0000_read_handler)
118106{
119   return avigo_flashes[0]->read(offset);
107   avigo_state *state = space->machine->driver_data<avigo_state>();
108   return state->flashes[0]->read(offset);
120109}
121110
122111/* memory 0x04000-0x07fff */
123112static  READ8_HANDLER(avigo_flash_0x4000_read_handler)
124113{
125   return avigo_flashes[avigo_flash_at_0x4000]->read((avigo_rom_bank_l<<14) | offset);
114   avigo_state *state = space->machine->driver_data<avigo_state>();
115   return state->flashes[state->flash_at_0x4000]->read((state->rom_bank_l<<14) | offset);
126116}
127117
128118/* memory 0x0000-0x03fff */
129119static WRITE8_HANDLER(avigo_flash_0x0000_write_handler)
130120{
131   avigo_flashes[0]->write(offset, data);
121   avigo_state *state = space->machine->driver_data<avigo_state>();
122   state->flashes[0]->write(offset, data);
132123}
133124
134125/* memory 0x04000-0x07fff */
135126static WRITE8_HANDLER(avigo_flash_0x4000_write_handler)
136127{
137   avigo_flashes[avigo_flash_at_0x4000]->write((avigo_rom_bank_l<<14) | offset, data);
128   avigo_state *state = space->machine->driver_data<avigo_state>();
129   state->flashes[state->flash_at_0x4000]->write((state->rom_bank_l<<14) | offset, data);
138130}
139131
140132/* memory 0x08000-0x0bfff */
141133static  READ8_HANDLER(avigo_flash_0x8000_read_handler)
142134{
143   return avigo_flashes[avigo_flash_at_0x8000]->read((avigo_ram_bank_l<<14) | offset);
135   avigo_state *state = space->machine->driver_data<avigo_state>();
136   return state->flashes[state->flash_at_0x8000]->read((state->ram_bank_l<<14) | offset);
144137}
145138
146139#ifdef UNUSED_FUNCTION
147140/* memory 0x08000-0x0bfff */
148141static WRITE8_HANDLER(avigo_flash_0x8000_write_handler)
149142{
150   avigo_flashes[avigo_flash_at_0x8000]->write((avigo_rom_bank_l<<14) | offset, data);
143   avigo_state *state = space->machine->driver_data<avigo_state>();
144   state->flashes[state->flash_at_0x8000]->write((state->rom_bank_l<<14) | offset, data);
151145}
152146#endif
153147
154148static void avigo_refresh_ints(running_machine *machine)
155149{
156   if (avigo_irq!=0)
150   avigo_state *state = machine->driver_data<avigo_state>();
151   if (state->irq!=0)
157152      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
158153   else
159154      cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
r9648r9649
161156
162157
163158/* previous input port data */
164static int previous_input_port_data[4];
165static int stylus_marker_x;
166static int stylus_marker_y;
167static int stylus_press_x;
168static int stylus_press_y;
169159
170160/* this is not a real interrupt. This timer updates the stylus position from mouse
171161movements, and checks if the mouse button is pressed to emulate a press of the stylus to the screen.
172162*/
173163static TIMER_CALLBACK(avigo_dummy_timer_callback)
174164{
165   avigo_state *state = machine->driver_data<avigo_state>();
175166   int i;
176167   int current_input_port_data[4];
177168   int changed;
178   static int ox = 0, oy = 0;
179169   int nx,ny;
180170   int dx, dy;
181171   static const char *const linenames[] = { "LINE0", "LINE1", "LINE2", "LINE3" };
r9648r9649
185175      current_input_port_data[i] = input_port_read(machine, linenames[i]);
186176   }
187177
188   changed = current_input_port_data[3]^previous_input_port_data[3];
178   changed = current_input_port_data[3]^state->previous_input_port_data[3];
189179
190180   if ((changed & 0x01)!=0)
191181   {
r9648r9649
194184         /* pen pressed to screen */
195185
196186         logerror("pen pressed interrupt\n");
197         stylus_press_x = stylus_marker_x;
198         stylus_press_y = stylus_marker_y;
187         state->stylus_press_x = state->stylus_marker_x;
188         state->stylus_press_y = state->stylus_marker_y;
199189         /* set pen interrupt */
200         avigo_irq |= (1<<6);
190         state->irq |= (1<<6);
201191      }
202192      else
203193      {
204         stylus_press_x = 0;
205         stylus_press_y = 0;
194         state->stylus_press_x = 0;
195         state->stylus_press_y = 0;
206196      }
207197   }
208198
r9648r9649
217207
218208   for (i=0; i<4; i++)
219209   {
220      previous_input_port_data[i] = current_input_port_data[i];
210      state->previous_input_port_data[i] = current_input_port_data[i];
221211   }
222212
223213   nx = input_port_read(machine, "POSX");
224214   if (nx>=0x800) nx-=0x1000;
225215   else if (nx<=-0x800) nx+=0x1000;
226216
227   dx = nx - ox;
228   ox = nx;
217   dx = nx - state->ox;
218   state->ox = nx;
229219
230220   ny = input_port_read(machine, "POSY");
231221   if (ny>=0x800) ny-=0x1000;
232222   else if (ny<=-0x800) ny+=0x1000;
233223
234   dy = ny - oy;
235   oy = ny;
224   dy = ny - state->oy;
225   state->oy = ny;
236226
237   stylus_marker_x +=dx;
238   stylus_marker_y +=dy;
227   state->stylus_marker_x +=dx;
228   state->stylus_marker_y +=dy;
239229
240   avigo_vh_set_stylus_marker_position(stylus_marker_x, stylus_marker_y);
230   avigo_vh_set_stylus_marker_position(machine, state->stylus_marker_x, state->stylus_marker_y);
241231#if 0
242232   /* not sure if keyboard generates an interrupt, or if something
243233    is plugged in for synchronisation! */
r9648r9649
248238      int current;
249239      current = ~current_input_port_data[i];
250240
251      changed = ((current^(~previous_input_port_data[i])) & 0x07);
241      changed = ((current^(~state->previous_input_port_data[i])) & 0x07);
252242
253243      if (changed!=0)
254244      {
r9648r9649
256246            that has changed, the old state was off and new state is on */
257247         if (current & changed)
258248         {
259            avigo_irq |= (1<<2);
249            state->irq |= (1<<2);
260250            break;
261251         }
262252      }
263253   }
264254#endif
265255   /* copy current to previous */
266   memcpy(previous_input_port_data, current_input_port_data, sizeof(int)*4);
256   memcpy(state->previous_input_port_data, current_input_port_data, sizeof(int)*4);
267257
268258   /* refresh status of interrupts */
269259   avigo_refresh_ints(machine);
r9648r9649
272262/* does not do anything yet */
273263static void avigo_tc8521_alarm_int(running_device *device, int state)
274264{
265   avigo_state *drvstate = device->machine->driver_data<avigo_state>();
275266//#if 0
276   avigo_irq &=~(1<<5);
267   drvstate->irq &=~(1<<5);
277268
278269   if (state)
279270   {
280      avigo_irq |= (1<<5);
271      drvstate->irq |= (1<<5);
281272   }
282273
283274   avigo_refresh_ints(device->machine);
r9648r9649
292283
293284static void avigo_refresh_memory(running_machine *machine)
294285{
286   avigo_state *state = machine->driver_data<avigo_state>();
295287   unsigned char *addr;
296288   address_space* space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
297289
298   switch (avigo_rom_bank_h)
290   switch (state->rom_bank_h)
299291   {
300292      /* 011 */
301293      case 0x03:
302294      {
303         avigo_flash_at_0x4000 = 1;
295         state->flash_at_0x4000 = 1;
304296      }
305297      break;
306298
307299      /* 101 */
308300      case 0x05:
309301      {
310         avigo_flash_at_0x4000 = 2;
302         state->flash_at_0x4000 = 2;
311303      }
312304      break;
313305
314306      default:
315         avigo_flash_at_0x4000 = 0;
307         state->flash_at_0x4000 = 0;
316308         break;
317309   }
318310
319   addr = (unsigned char *)avigo_flashes[avigo_flash_at_0x4000]->space()->get_read_ptr(0);
320   addr = addr + (avigo_rom_bank_l<<14);
311   addr = (unsigned char *)state->flashes[state->flash_at_0x4000]->space()->get_read_ptr(0);
312   addr = addr + (state->rom_bank_l<<14);
321313   avigo_setbank(machine, 1, addr, avigo_flash_0x4000_read_handler, avigo_flash_0x4000_write_handler);
322314
323   switch (avigo_ram_bank_h)
315   switch (state->ram_bank_h)
324316   {
325317      /* %101 */
326318      /* screen */
r9648r9649
331323      /* %001 */
332324      /* ram */
333325      case 0x01:
334         addr = messram_get_ptr(machine->device("messram")) + ((avigo_ram_bank_l & 0x07)<<14);
326         addr = messram_get_ptr(machine->device("messram")) + ((state->ram_bank_l & 0x07)<<14);
335327         memory_set_bankptr(machine, "bank3", addr);
336328         memory_set_bankptr(machine, "bank7", addr);
337         avigo_banked_opbase[2] = ((UINT8 *) addr) - (2 * 0x4000);
329         state->banked_opbase[2] = ((UINT8 *) addr) - (2 * 0x4000);
338330         memory_install_read_bank (space, (2 * 0x4000),(2 * 0x4000) + 0x3FFF, 0, 0, "bank3");
339331         memory_install_write_bank(space, (2 * 0x4000),(2 * 0x4000) + 0x3FFF, 0, 0, "bank7");
340332         break;
341333
342334      /* %111 */
343335      case 0x03:
344         avigo_flash_at_0x8000 = 1;
336         state->flash_at_0x8000 = 1;
345337
346338
347         addr = (unsigned char *)avigo_flashes[avigo_flash_at_0x8000]->space()->get_read_ptr(0);
348         addr = addr + (avigo_ram_bank_l<<14);
339         addr = (unsigned char *)state->flashes[state->flash_at_0x8000]->space()->get_read_ptr(0);
340         addr = addr + (state->ram_bank_l<<14);
349341         avigo_setbank(machine, 2, addr, avigo_flash_0x8000_read_handler, NULL /* avigo_flash_0x8000_write_handler */);
350342         break;
351343
352344      case 0x07:
353         avigo_flash_at_0x8000 = 0;
345         state->flash_at_0x8000 = 0;
354346
355         addr = (unsigned char *)avigo_flashes[avigo_flash_at_0x8000]->space()->get_read_ptr(0);
356         addr = addr + (avigo_ram_bank_l<<14);
347         addr = (unsigned char *)state->flashes[state->flash_at_0x8000]->space()->get_read_ptr(0);
348         addr = addr + (state->ram_bank_l<<14);
357349         avigo_setbank(machine, 2, addr, avigo_flash_0x8000_read_handler, NULL /* avigo_flash_0x8000_write_handler */);
358350         break;
359351   }
r9648r9649
363355
364356static INS8250_INTERRUPT( avigo_com_interrupt )
365357{
358   avigo_state *drvstate = device->machine->driver_data<avigo_state>();
366359   logerror("com int\r\n");
367360
368   avigo_irq &= ~(1<<3);
361   drvstate->irq &= ~(1<<3);
369362
370363   if (state)
371364   {
372      avigo_irq |= (1<<3);
365      drvstate->irq |= (1<<3);
373366   }
374367
375368   avigo_refresh_ints(device->machine);
r9648r9649
389382/* this is needed because this driver uses handlers in memory that gets executed */
390383DIRECT_UPDATE_HANDLER( avigo_opbase_handler )
391384{
385   avigo_state *state = machine->driver_data<avigo_state>();
392386   void *opbase_ptr;
393387
394   opbase_ptr = avigo_banked_opbase[address / 0x4000];
388   opbase_ptr = state->banked_opbase[address / 0x4000];
395389   if (opbase_ptr != NULL)
396390   {
397391      direct.explicit_configure(0x0000, 0xffff, 0xffff, (UINT8*)opbase_ptr);
r9648r9649
402396
403397static MACHINE_RESET( avigo )
404398{
399   avigo_state *state = machine->driver_data<avigo_state>();
405400   int i;
406401   unsigned char *addr;
407402   static const char *const linenames[] = { "LINE0", "LINE1", "LINE2", "LINE3" };
408403
409   memset(avigo_banked_opbase, 0, sizeof(avigo_banked_opbase));
404   memset(state->banked_opbase, 0, sizeof(state->banked_opbase));
410405
411406   /* keep machine pointers to flash devices */
412   avigo_flashes[0] = machine->device<intelfsh8_device>("flash0");
413   avigo_flashes[1] = machine->device<intelfsh8_device>("flash1");
414   avigo_flashes[2] = machine->device<intelfsh8_device>("flash2");
407   state->flashes[0] = machine->device<intelfsh8_device>("flash0");
408   state->flashes[1] = machine->device<intelfsh8_device>("flash1");
409   state->flashes[2] = machine->device<intelfsh8_device>("flash2");
415410
416411   /* initialize flash contents */
417   memcpy(memory_region(machine, "maincpu")+0x10000, avigo_flashes[0]->space()->get_read_ptr(0), 0x100000);
418   memcpy(memory_region(machine, "maincpu")+0x110000, avigo_flashes[1]->space()->get_read_ptr(0), 0x100000);
412   memcpy(memory_region(machine, "maincpu")+0x10000, state->flashes[0]->space()->get_read_ptr(0), 0x100000);
413   memcpy(memory_region(machine, "maincpu")+0x110000, state->flashes[1]->space()->get_read_ptr(0), 0x100000);
419414
420   stylus_marker_x = AVIGO_SCREEN_WIDTH>>1;
421   stylus_marker_y = AVIGO_SCREEN_HEIGHT>>1;
422   stylus_press_x = 0;
423   stylus_press_y = 0;
424   avigo_vh_set_stylus_marker_position(stylus_marker_x, stylus_marker_y);
415   state->stylus_marker_x = AVIGO_SCREEN_WIDTH>>1;
416   state->stylus_marker_y = AVIGO_SCREEN_HEIGHT>>1;
417   state->stylus_press_x = 0;
418   state->stylus_press_y = 0;
419   avigo_vh_set_stylus_marker_position(machine, state->stylus_marker_x, state->stylus_marker_y);
425420
426421   /* initialise settings for port data */
427422   for (i = 0; i < 4; i++)
428423   {
429      previous_input_port_data[i] = input_port_read(machine, linenames[i]);
424      state->previous_input_port_data[i] = input_port_read(machine, linenames[i]);
430425   }
431426
432   avigo_irq = 0;
433   avigo_rom_bank_l = 0;
434   avigo_rom_bank_h = 0;
435   avigo_ram_bank_l = 0;
436   avigo_ram_bank_h = 0;
437   avigo_flash_at_0x4000 = 0;
438   avigo_flash_at_0x8000 = 0;
427   state->irq = 0;
428   state->rom_bank_l = 0;
429   state->rom_bank_h = 0;
430   state->ram_bank_l = 0;
431   state->ram_bank_h = 0;
432   state->flash_at_0x4000 = 0;
433   state->flash_at_0x8000 = 0;
439434
440435   /* clear */
441436   memset(messram_get_ptr(machine->device("messram")), 0, 128*1024);
442437
443438   cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(avigo_opbase_handler, *machine));
444439
445   addr = (unsigned char *)avigo_flashes[0]->space()->get_read_ptr(0);
440   addr = (unsigned char *)state->flashes[0]->space()->get_read_ptr(0);
446441   avigo_setbank(machine, 0, addr, avigo_flash_0x0000_read_handler, avigo_flash_0x0000_write_handler);
447442
448443   avigo_setbank(machine, 3, messram_get_ptr(machine->device("messram")), NULL, NULL);
r9648r9649
469464
470465static  READ8_HANDLER(avigo_key_data_read_r)
471466{
467   avigo_state *state = space->machine->driver_data<avigo_state>();
472468   UINT8 data;
473469
474470   data = 0x007;
475471
476   if (avigo_key_line & 0x01)
472   if (state->key_line & 0x01)
477473   {
478474      data &= input_port_read(space->machine, "LINE0");
479475   }
480476
481   if (avigo_key_line & 0x02)
477   if (state->key_line & 0x02)
482478   {
483479      data &= input_port_read(space->machine, "LINE1");
484480   }
485481
486   if (avigo_key_line & 0x04)
482   if (state->key_line & 0x04)
487483   {
488484      data &= input_port_read(space->machine, "LINE2");
489485
r9648r9649
501497/* bit 0 set for line 0, bit 1 set for line 1, bit 2 set for line 2 */
502498static WRITE8_HANDLER(avigo_set_key_line_w)
503499{
500   avigo_state *state = space->machine->driver_data<avigo_state>();
504501   /* 5, 101, read back 3 */
505   avigo_key_line = data;
502   state->key_line = data;
506503}
507504
508505static  READ8_HANDLER(avigo_irq_r)
509506{
510   return avigo_irq;
507   avigo_state *state = space->machine->driver_data<avigo_state>();
508   return state->irq;
511509}
512510
513511static WRITE8_HANDLER(avigo_irq_w)
514512{
515   avigo_irq &= ~data;
513   avigo_state *state = space->machine->driver_data<avigo_state>();
514   state->irq &= ~data;
516515
517516   avigo_refresh_ints(space->machine);
518517}
519518
520519static  READ8_HANDLER(avigo_rom_bank_l_r)
521520{
522   return avigo_rom_bank_l;
521   avigo_state *state = space->machine->driver_data<avigo_state>();
522   return state->rom_bank_l;
523523}
524524
525525static  READ8_HANDLER(avigo_rom_bank_h_r)
526526{
527   return avigo_rom_bank_h;
527   avigo_state *state = space->machine->driver_data<avigo_state>();
528   return state->rom_bank_h;
528529}
529530
530531static  READ8_HANDLER(avigo_ram_bank_l_r)
531532{
532   return avigo_ram_bank_l;
533   avigo_state *state = space->machine->driver_data<avigo_state>();
534   return state->ram_bank_l;
533535}
534536
535537static  READ8_HANDLER(avigo_ram_bank_h_r)
536538{
537   return avigo_ram_bank_h;
539   avigo_state *state = space->machine->driver_data<avigo_state>();
540   return state->ram_bank_h;
538541}
539542
540543
541544
542545static WRITE8_HANDLER(avigo_rom_bank_l_w)
543546{
547   avigo_state *state = space->machine->driver_data<avigo_state>();
544548   logerror("rom bank l w: %04x\n", data);
545549
546        avigo_rom_bank_l = data & 0x03f;
550        state->rom_bank_l = data & 0x03f;
547551
548552        avigo_refresh_memory(space->machine);
549553}
550554
551555static WRITE8_HANDLER(avigo_rom_bank_h_w)
552556{
557   avigo_state *state = space->machine->driver_data<avigo_state>();
553558   logerror("rom bank h w: %04x\n", data);
554559
555560
r9648r9649
562567
563568
564569        */
565   avigo_rom_bank_h = data;
570   state->rom_bank_h = data;
566571
567572
568573        avigo_refresh_memory(space->machine);
r9648r9649
570575
571576static WRITE8_HANDLER(avigo_ram_bank_l_w)
572577{
578   avigo_state *state = space->machine->driver_data<avigo_state>();
573579   logerror("ram bank l w: %04x\n", data);
574580
575        avigo_ram_bank_l = data & 0x03f;
581        state->ram_bank_l = data & 0x03f;
576582
577583        avigo_refresh_memory(space->machine);
578584}
579585
580586static WRITE8_HANDLER(avigo_ram_bank_h_w)
581587{
588   avigo_state *state = space->machine->driver_data<avigo_state>();
582589   logerror("ram bank h w: %04x\n", data);
583590
584   avigo_ram_bank_h = data;
591   state->ram_bank_h = data;
585592
586593        avigo_refresh_memory(space->machine);
587594}
588595
589596static  READ8_HANDLER(avigo_ad_control_status_r)
590597{
591   logerror("avigo ad control read %02x\n", (int) avigo_ad_control_status);
592   return avigo_ad_control_status;
598   avigo_state *state = space->machine->driver_data<avigo_state>();
599   logerror("avigo ad control read %02x\n", (int) state->ad_control_status);
600   return state->ad_control_status;
593601}
594602
595static unsigned int avigo_ad_value;
596603
597604static WRITE8_HANDLER(avigo_ad_control_status_w)
598605{
606   avigo_state *state = space->machine->driver_data<avigo_state>();
599607   logerror("avigo ad control w %02x\n",data);
600608
601609   if ((data & 0x070)==0x070)
r9648r9649
605613      if ((data & 0x08)!=0)
606614      {
607615         logerror("a/d select x coordinate\n");
608         logerror("x coord: %d\n",stylus_press_x);
616         logerror("x coord: %d\n",state->stylus_press_x);
609617
610618         /* on screen range 0x060->0x03a0 */
611619         /* 832 is on-screen range */
612620         /* 5.2 a/d units per pixel */
613621
614         if (stylus_press_x!=0)
622         if (state->stylus_press_x!=0)
615623         {
616624            /* this might not be totally accurate because hitable screen
617625                area may include the border around the screen! */
618            avigo_ad_value = ((int)(stylus_press_x * 5.2f))+0x060;
619            avigo_ad_value &= 0x03fc;
626            state->ad_value = ((int)(state->stylus_press_x * 5.2f))+0x060;
627            state->ad_value &= 0x03fc;
620628         }
621629         else
622630         {
623            avigo_ad_value = 0;
631            state->ad_value = 0;
624632         }
625633
626         logerror("ad value: %d\n",avigo_ad_value);
627         stylus_press_x = 0;
634         logerror("ad value: %d\n",state->ad_value);
635         state->stylus_press_x = 0;
628636
629637      }
630638      else
r9648r9649
645653         /* 3.25 * 1024.00 = 315.07 */
646654
647655         logerror("a/d select y coordinate\n");
648         logerror("y coord: %d\n",stylus_press_y);
656         logerror("y coord: %d\n",state->stylus_press_y);
649657
650         if (stylus_press_y!=0)
658         if (state->stylus_press_y!=0)
651659         {
652            avigo_ad_value = 1024 - (((stylus_press_y)*3.25f) + 0x040);
660            state->ad_value = 1024 - (((state->stylus_press_y)*3.25f) + 0x040);
653661         }
654662         else
655663         {
656            avigo_ad_value = 0;
664            state->ad_value = 0;
657665         }
658666
659         logerror("ad value: %d\n",avigo_ad_value);
660         stylus_press_y = 0;
667         logerror("ad value: %d\n",state->ad_value);
668         state->stylus_press_y = 0;
661669      }
662670   }
663671
664672   /* bit 0: 1 if a/d complete, 0 if a/d not complete */
665   avigo_ad_control_status = data | 1;
673   state->ad_control_status = data | 1;
666674}
667675
668676static  READ8_HANDLER(avigo_ad_data_r)
669677{
678   avigo_state *state = space->machine->driver_data<avigo_state>();
670679   unsigned char data;
671680
672681   data = 0;
r9648r9649
676685   /* status AND   11110111 */
677686   /* status OR    01110000 -> C20F */
678687
679   switch (avigo_ad_control_status & 0x078)
688   switch (state->ad_control_status & 0x078)
680689   {
681690      /* x1110xxx */
682691      /* read upper 4 bits of 10 bit A/D number */
r9648r9649
688697         /* bit 3 must be 1. bit 2 can have any value */
689698
690699         logerror("a/d read upper 4 bits\n");
691         data = ((avigo_ad_value>>6) & 0x0f)<<4;
700         data = ((state->ad_value>>6) & 0x0f)<<4;
692701         data |= 8;
693702      }
694703      break;
r9648r9649
700709         /* bit 0 must be 1, bit 1 must be 0 */
701710
702711         logerror("a/d lower 6-bits\n");
703         data = ((avigo_ad_value & 0x03f)<<2);
712         data = ((state->ad_value & 0x03f)<<2);
704713         data |= 1;
705714      }
706715      break;
r9648r9649
769778
770779static WRITE8_HANDLER(avigo_speaker_w)
771780{
781   avigo_state *state = space->machine->driver_data<avigo_state>();
772782   running_device *speaker = space->machine->device("speaker");
773783   UINT8 previous_speaker;
774784
775   previous_speaker = avigo_speaker_data;
776   avigo_speaker_data = data;
785   previous_speaker = state->speaker_data;
786   state->speaker_data = data;
777787
778788   /* changed state? */
779   if (((data^avigo_speaker_data) & (1<<3))!=0)
789   if (((data^state->speaker_data) & (1<<3))!=0)
780790   {
781791      /* DAC output state */
782792      speaker_level_w(speaker,(data>>3) & 0x01);
r9648r9649
949959GFXDECODE_END
950960
951961
952static MACHINE_CONFIG_START( avigo, driver_device )
962static MACHINE_CONFIG_START( avigo, avigo_state )
953963   /* basic machine hardware */
954964   MDRV_CPU_ADD("maincpu", Z80, 4000000)
955965   MDRV_CPU_PROGRAM_MAP(avigo_mem)
r9648r9649
961971
962972   MDRV_NS16550_ADD( "ns16550", avigo_com_interface )
963973
964    /* video hardware */
974   /* video hardware */
965975   MDRV_SCREEN_ADD("screen", LCD)
966976   MDRV_SCREEN_REFRESH_RATE(50)
967977   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
src/mess/drivers/apple2.c
r9648r9649
683683   ROM_LOAD ( "l3kdisk.rom", 0x8500, 0x0100, CRC(2D4B1584) SHA1(989780B77E100598124DF7B72663E5A31A3339C0))
684684ROM_END
685685
686MACHINE_CONFIG_DERIVED( apple2e, apple2_common )
686static MACHINE_CONFIG_DERIVED( apple2e, apple2_common )
687687   MDRV_VIDEO_START(apple2e)
688688   /* internal ram */
689689   MDRV_RAM_ADD("messram")
docs/messnew.txt
r9648r9649
9595- Refactored the UPD765 DRQ line to use devcb. The read_write parameter is
9696  not present on the real chip, and no driver was using it. [Curt Coder]
9797 
98- Static and const changes.  [Atari Ace]
98- Static/const changes, and added driver_device state to many drivers.
99  [Atari Ace]
99100
100101
101102

Previous 15994 Revisions Next


© 1998-2018 The MESS Team