Previous 15994 Revisions Next

r9670 Friday 26th November, 2010 at 21:29:39 UTC by Nathan Woods
More Atari Ace stuff. [Atari Ace]
[src/mess/drivers]lynx.c mac.c mz2500.c oric.c pet.c pokemini.c vc4000.c wswan.c x68k.c zexall.c zx.c
[src/mess/includes]lynx.h mac.h nascom1.h oric.h pet.h pokemini.h super80.h vc4000.h vtech2.h wswan.h x68k.h z80ne.h zx.h
[src/mess/machine]lynx.c mac.c nascom1.c oric.c pet.c pokemini.c rp5c15.c rp5c15.h super80.c vtech2.c wswan.c z80ne.c zx.c
[src/mess/video]mac.c oric.c pc8801.c pet.c super80.c vc4000.c vtech2.c wswan.c x68k.c zx.c

src/mess/machine/pokemini.c
r9669r9670
1313#include "cpu/minx/minx.h"
1414
1515
16struct PRC
17{
18   UINT8      colors_inverted;
19   UINT8      background_enabled;
20   UINT8      sprites_enabled;
21   UINT8      copy_enabled;
22   UINT8      map_size;
23   UINT8      map_size_x;
24   UINT8      frame_count;
25   UINT8      max_frame_count;
26   UINT32      bg_tiles;
27   UINT32      spr_tiles;
28   UINT8      count;
29   emu_timer   *count_timer;
30};
31
32
33struct TIMERS
34{
35   emu_timer   *seconds_timer;
36   emu_timer   *hz256_timer;
37   emu_timer   *timer1;            /* Timer 1 low or 16bit */
38   emu_timer   *timer1_hi;            /* Timer 1 hi */
39   emu_timer   *timer2;            /* Timer 2 low or 16bit */
40   emu_timer   *timer2_hi;            /* Timer 2 high */
41   emu_timer   *timer3;            /* Timer 3 low or 16bit */
42   emu_timer   *timer3_hi;            /* Timer 3 high */
43};
44
45
46UINT8   *pokemini_ram;
47static UINT8 pm_reg[0x100];
48static struct PRC prc;
49static struct TIMERS timers;
50
51
5216static void pokemini_check_irqs( running_machine *machine )
5317{
18   pokemini_state *state = machine->driver_data<pokemini_state>();
5419   int irq_set[4] = { 1, 0, 0, 0 };
5520   int prio, vector;
5621
5722   /* Check IRQ $03-$04 */
58   prio = ( pm_reg[0x20] >> 6 ) & 0x03;
23   prio = ( state->pm_reg[0x20] >> 6 ) & 0x03;
5924   if ( ! irq_set[prio] )
6025   {
61      if ( pm_reg[0x23] & pm_reg[0x27] & 0x40 )
26      if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x40 )
6227         irq_set[prio] = 0x04;
6328
64      if ( pm_reg[0x23] & pm_reg[0x27] & 0x80 )
29      if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x80 )
6530         irq_set[prio] = 0x03;
6631   }
6732
6833   /* Check IRQ $05-$06 */
69   prio = ( pm_reg[0x20] >> 4 ) & 0x03;
34   prio = ( state->pm_reg[0x20] >> 4 ) & 0x03;
7035   if ( ! irq_set[prio] )
7136   {
72      if ( pm_reg[0x23] & pm_reg[0x27] & 0x10 )
37      if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x10 )
7338         irq_set[prio] = 0x06;
7439
75      if ( pm_reg[0x23] & pm_reg[0x27] & 0x20 )
40      if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x20 )
7641         irq_set[prio] = 0x05;
7742   }
7843
7944   /* Check IRQ $07-$08 */
80   prio = ( pm_reg[0x20] >> 2 ) & 0x03;
45   prio = ( state->pm_reg[0x20] >> 2 ) & 0x03;
8146   if ( ! irq_set[prio] )
8247   {
83      if ( pm_reg[0x23] & pm_reg[0x27] & 0x04 )
48      if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x04 )
8449         irq_set[prio] = 0x08;
8550
86      if ( pm_reg[0x23] & pm_reg[0x27] & 0x08 )
51      if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x08 )
8752         irq_set[prio] = 0x07;
8853   }
8954
9055   /* Check IRQ $09-$0A */
91   prio = ( pm_reg[0x20] >> 0 ) & 0x03;
56   prio = ( state->pm_reg[0x20] >> 0 ) & 0x03;
9257   if ( ! irq_set[prio] )
9358   {
94      if ( pm_reg[0x23] & pm_reg[0x27] & 0x01 )
59      if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x01 )
9560         irq_set[prio] = 0x0A;
9661
97      if ( pm_reg[0x23] & pm_reg[0x27] & 0x02 )
62      if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x02 )
9863         irq_set[prio] = 0x09;
9964   }
10065
10166   /* Check IRQ $0B-$0E */
102   prio = ( pm_reg[0x21] >> 6 ) & 0x03;
67   prio = ( state->pm_reg[0x21] >> 6 ) & 0x03;
10368   if ( ! irq_set[prio] )
10469   {
105      if ( pm_reg[0x24] & pm_reg[0x28] & 0x04 )
70      if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x04 )
10671         irq_set[prio] = 0x0E;
10772
108      if ( pm_reg[0x24] & pm_reg[0x28] & 0x08 )
73      if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x08 )
10974         irq_set[prio] = 0x0D;
11075
111      if ( pm_reg[0x24] & pm_reg[0x28] & 0x10 )
76      if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x10 )
11277         irq_set[prio] = 0x0C;
11378
114      if ( pm_reg[0x24] & pm_reg[0x28] & 0x20 )
79      if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x20 )
11580         irq_set[prio] = 0x0B;
11681   }
11782
11883   /* Check IRQ $0F-$10 */
119   prio = ( pm_reg[0x22] >> 0 ) & 0x03;
84   prio = ( state->pm_reg[0x22] >> 0 ) & 0x03;
12085   if ( ! irq_set[prio] )
12186   {
122      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x40 )
87      if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x40 )
12388         irq_set[prio] = 0x10;
12489
125      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x80 )
90      if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x80 )
12691         irq_set[prio] = 0x0F;
12792   }
12893
12994   /* Check IRQ $13-$14 */
130   prio = ( pm_reg[0x21] >> 4 ) & 0x03;
95   prio = ( state->pm_reg[0x21] >> 4 ) & 0x03;
13196   if ( ! irq_set[prio] )
13297   {
133      if ( pm_reg[0x24] & pm_reg[0x28] & 0x01 )
98      if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x01 )
13499         irq_set[prio] = 0x14;
135100
136      if ( pm_reg[0x24] & pm_reg[0x28] & 0x02 )
101      if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x02 )
137102         irq_set[prio] = 0x13;
138103   }
139104
140105   /* Check IRQ $15-$1C */
141   prio = ( pm_reg[0x21] >> 2 ) & 0x03;
106   prio = ( state->pm_reg[0x21] >> 2 ) & 0x03;
142107   if ( ! irq_set[prio] )
143108   {
144      if ( pm_reg[0x25] & pm_reg[0x29] & 0x01 )
109      if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x01 )
145110         irq_set[prio] = 0x1C;
146111
147      if ( pm_reg[0x25] & pm_reg[0x29] & 0x02 )
112      if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x02 )
148113         irq_set[prio] = 0x1B;
149114
150      if ( pm_reg[0x25] & pm_reg[0x29] & 0x04 )
115      if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x04 )
151116         irq_set[prio] = 0x1A;
152117
153      if ( pm_reg[0x25] & pm_reg[0x29] & 0x08 )
118      if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x08 )
154119         irq_set[prio] = 0x19;
155120
156      if ( pm_reg[0x25] & pm_reg[0x29] & 0x10 )
121      if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x10 )
157122         irq_set[prio] = 0x18;
158123
159      if ( pm_reg[0x25] & pm_reg[0x29] & 0x20 )
124      if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x20 )
160125         irq_set[prio] = 0x17;
161126
162      if ( pm_reg[0x25] & pm_reg[0x29] & 0x40 )
127      if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x40 )
163128         irq_set[prio] = 0x16;
164129
165      if ( pm_reg[0x25] & pm_reg[0x29] & 0x80 )
130      if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x80 )
166131         irq_set[prio] = 0x15;
167132   }
168133
169134   /* Check IRQ $1D-$1F */
170   prio = ( pm_reg[0x21] >> 0 ) & 0x03;
171   if ( ! irq_set[prio] && ( pm_reg[0x26] & pm_reg[0x2A] & 0x07 ) )
135   prio = ( state->pm_reg[0x21] >> 0 ) & 0x03;
136   if ( ! irq_set[prio] && ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x07 ) )
172137   {
173      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x01 )
138      if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x01 )
174139         irq_set[prio] = 0x1F;
175140
176      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x02 )
141      if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x02 )
177142         irq_set[prio] = 0x1E;
178143
179      if ( pm_reg[0x26] & pm_reg[0x2A] & 0x04 )
144      if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x04 )
180145         irq_set[prio] = 0x1D;
181146   }
182147
r9669r9670
204169
205170static void pokemini_update_sound( running_machine *machine )
206171{
172   pokemini_state *state = machine->driver_data<pokemini_state>();
207173   running_device *speaker = machine->device("speaker");
208174   /* Check if sound should be muted */
209   if ( pm_reg[0x70] & 0x03 )
175   if ( state->pm_reg[0x70] & 0x03 )
210176   {
211177      speaker_level_w( speaker, 0 );
212178   }
213179   else
214180   {
215181      static const int levels[4] = { 0, 1, 1, 2 };
216      int level = levels[ pm_reg[0x71] & 0x03 ];
182      int level = levels[ state->pm_reg[0x71] & 0x03 ];
217183
218//      if ( ( ( pm_reg[0x48] & 0x80 ) && ( pm_reg[0x4E] | ( pm_reg[0x4F] << 8 ) ) > ( pm_reg[0x4C] | ( pm_reg[0x4D] << 8 ) ) )
219//        || ( ( pm_reg[0x48] & 0x80 ) && pm_reg[0x4F] > pm_reg[0x4D] ) )
184//      if ( ( ( state->pm_reg[0x48] & 0x80 ) && ( state->pm_reg[0x4E] | ( state->pm_reg[0x4F] << 8 ) ) > ( state->pm_reg[0x4C] | ( state->pm_reg[0x4D] << 8 ) ) )
185//        || ( ( state->pm_reg[0x48] & 0x80 ) && state->pm_reg[0x4F] > state->pm_reg[0x4D] ) )
220186//      {
221187         level = 0;
222188//      }
r9669r9670
228194
229195static TIMER_CALLBACK(pokemini_seconds_timer_callback)
230196{
231   if ( pm_reg[0x08] & 0x01 )
197   pokemini_state *state = machine->driver_data<pokemini_state>();
198   if ( state->pm_reg[0x08] & 0x01 )
232199   {
233      pm_reg[0x09] += 1;
234      if ( ! pm_reg[0x09] )
200      state->pm_reg[0x09] += 1;
201      if ( ! state->pm_reg[0x09] )
235202      {
236         pm_reg[0x0A] += 1;
237         if ( ! pm_reg[0x0A] )
203         state->pm_reg[0x0A] += 1;
204         if ( ! state->pm_reg[0x0A] )
238205         {
239            pm_reg[0x0B] += 1;
206            state->pm_reg[0x0B] += 1;
240207         }
241208      }
242209   }
r9669r9670
245212
246213static TIMER_CALLBACK(pokemini_256hz_timer_callback)
247214{
248   if ( pm_reg[0x40] & 0x01 )
215   pokemini_state *state = machine->driver_data<pokemini_state>();
216   if ( state->pm_reg[0x40] & 0x01 )
249217   {
250      pm_reg[0x41] += 1;
218      state->pm_reg[0x41] += 1;
251219      /* Check if the 32Hz IRQ should be triggered */
252      if ( ! ( pm_reg[0x41] & 0x07 ) )
220      if ( ! ( state->pm_reg[0x41] & 0x07 ) )
253221      {
254         pm_reg[0x28] |= 0x20;
222         state->pm_reg[0x28] |= 0x20;
255223
256224         /* Check if the 8Hz IRQ should be triggered */
257         if ( ! ( pm_reg[0x41] & 0x1F ) )
225         if ( ! ( state->pm_reg[0x41] & 0x1F ) )
258226         {
259            pm_reg[0x28] |= 0x10;
227            state->pm_reg[0x28] |= 0x10;
260228
261229            /* Check if the 2Hz IRQ should be triggered */
262            if ( ! ( pm_reg[0x41] & 0x7F ) )
230            if ( ! ( state->pm_reg[0x41] & 0x7F ) )
263231            {
264               pm_reg[0x28] |= 0x08;
232               state->pm_reg[0x28] |= 0x08;
265233
266234               /* Check if the 1Hz IRQ should be triggered */
267               if ( ! pm_reg[0x41] )
235               if ( ! state->pm_reg[0x41] )
268236               {
269                  pm_reg[0x28] |= 0x04;
237                  state->pm_reg[0x28] |= 0x04;
270238               }
271239            }
272240         }
r9669r9670
279247
280248static TIMER_CALLBACK(pokemini_timer1_callback)
281249{
282   pm_reg[0x36] -= 1;
250   pokemini_state *state = machine->driver_data<pokemini_state>();
251   state->pm_reg[0x36] -= 1;
283252   /* Check for underflow of timer */
284   if ( pm_reg[0x36] == 0xFF )
253   if ( state->pm_reg[0x36] == 0xFF )
285254   {
286255      /* Check if timer1 is running in 16bit mode */
287      if ( pm_reg[0x30] & 0x80 )
256      if ( state->pm_reg[0x30] & 0x80 )
288257      {
289         pm_reg[0x37] -= 1;
290         if ( pm_reg[0x37] == 0xFF )
258         state->pm_reg[0x37] -= 1;
259         if ( state->pm_reg[0x37] == 0xFF )
291260         {
292            pm_reg[0x27] |= 0x08;
261            state->pm_reg[0x27] |= 0x08;
293262            pokemini_check_irqs( machine );
294            pm_reg[0x36] = pm_reg[0x32];
295            pm_reg[0x37] = pm_reg[0x33];
263            state->pm_reg[0x36] = state->pm_reg[0x32];
264            state->pm_reg[0x37] = state->pm_reg[0x33];
296265         }
297266      }
298267      else
299268      {
300         pm_reg[0x27] |= 0x04;
269         state->pm_reg[0x27] |= 0x04;
301270         pokemini_check_irqs( machine );
302         pm_reg[0x36] = pm_reg[0x32];
271         state->pm_reg[0x36] = state->pm_reg[0x32];
303272      }
304273   }
305274}
r9669r9670
307276
308277static TIMER_CALLBACK(pokemini_timer1_hi_callback)
309278{
310   pm_reg[0x37] -= 1;
279   pokemini_state *state = machine->driver_data<pokemini_state>();
280   state->pm_reg[0x37] -= 1;
311281   /* Check for underflow of timer */
312   if ( pm_reg[0x37] == 0xFF )
282   if ( state->pm_reg[0x37] == 0xFF )
313283   {
314      pm_reg[0x27] |= 0x08;
284      state->pm_reg[0x27] |= 0x08;
315285      pokemini_check_irqs( machine );
316      pm_reg[0x37] = pm_reg[0x33];
286      state->pm_reg[0x37] = state->pm_reg[0x33];
317287   }
318288}
319289
320290
321291static TIMER_CALLBACK(pokemini_timer2_callback)
322292{
323   pm_reg[0x3E] -= 1;
293   pokemini_state *state = machine->driver_data<pokemini_state>();
294   state->pm_reg[0x3E] -= 1;
324295   /* Check for underflow of timer */
325   if ( pm_reg[0x3E] == 0xFF )
296   if ( state->pm_reg[0x3E] == 0xFF )
326297   {
327298      /* Check if timer2 is running in 16bit mode */
328      if ( pm_reg[0x38] & 0x80 )
299      if ( state->pm_reg[0x38] & 0x80 )
329300      {
330         pm_reg[0x3F] -= 1;
331         if ( pm_reg[0x3F] == 0xFF )
301         state->pm_reg[0x3F] -= 1;
302         if ( state->pm_reg[0x3F] == 0xFF )
332303         {
333            pm_reg[0x27] |= 0x20;
304            state->pm_reg[0x27] |= 0x20;
334305            pokemini_check_irqs( machine );
335            pm_reg[0x3E] = pm_reg[0x3A];
336            pm_reg[0x3F] = pm_reg[0x3B];
306            state->pm_reg[0x3E] = state->pm_reg[0x3A];
307            state->pm_reg[0x3F] = state->pm_reg[0x3B];
337308         }
338309      }
339310      else
340311      {
341         pm_reg[0x27] |= 0x10;
312         state->pm_reg[0x27] |= 0x10;
342313         pokemini_check_irqs( machine );
343         pm_reg[0x3E] = pm_reg[0x3A];
314         state->pm_reg[0x3E] = state->pm_reg[0x3A];
344315      }
345316   }
346317}
r9669r9670
348319
349320static TIMER_CALLBACK(pokemini_timer2_hi_callback)
350321{
351   pm_reg[0x3F] -= 1;
322   pokemini_state *state = machine->driver_data<pokemini_state>();
323   state->pm_reg[0x3F] -= 1;
352324   /* Check for underfow of timer */
353   if ( pm_reg[0x3F] == 0xFF )
325   if ( state->pm_reg[0x3F] == 0xFF )
354326   {
355      pm_reg[0x27] |= 0x20;
327      state->pm_reg[0x27] |= 0x20;
356328      pokemini_check_irqs( machine );
357      pm_reg[0x3F] = pm_reg[0x3B];
329      state->pm_reg[0x3F] = state->pm_reg[0x3B];
358330   }
359331}
360332
361333
362334static TIMER_CALLBACK(pokemini_timer3_callback)
363335{
364   pm_reg[0x4E] -= 1;
336   pokemini_state *state = machine->driver_data<pokemini_state>();
337   state->pm_reg[0x4E] -= 1;
365338   /* Check for underflow of timer */
366   if ( pm_reg[0x4E] == 0xFF )
339   if ( state->pm_reg[0x4E] == 0xFF )
367340   {
368341      /* Check if timer3 is running in 16bit mode */
369      if ( pm_reg[0x48] & 0x80 )
342      if ( state->pm_reg[0x48] & 0x80 )
370343      {
371         pm_reg[0x4F] -= 1;
372         if ( pm_reg[0x4F] == 0xFF )
344         state->pm_reg[0x4F] -= 1;
345         if ( state->pm_reg[0x4F] == 0xFF )
373346         {
374            pm_reg[0x27] |= 0x02;
347            state->pm_reg[0x27] |= 0x02;
375348            pokemini_check_irqs( machine );
376            pm_reg[0x4E] = pm_reg[0x4A];
377            pm_reg[0x4F] = pm_reg[0x4B];
349            state->pm_reg[0x4E] = state->pm_reg[0x4A];
350            state->pm_reg[0x4F] = state->pm_reg[0x4B];
378351         }
379352      }
380353      else
381354      {
382         pm_reg[0x4E] = pm_reg[0x4A];
355         state->pm_reg[0x4E] = state->pm_reg[0x4A];
383356      }
384357   }
385358
386   if ( pm_reg[0x48] & 0x80 )
359   if ( state->pm_reg[0x48] & 0x80 )
387360   {
388      if (  ( pm_reg[0x4E] == pm_reg[0x4C] ) && ( pm_reg[0x4F] == pm_reg[0x4D] ) )
361      if (  ( state->pm_reg[0x4E] == state->pm_reg[0x4C] ) && ( state->pm_reg[0x4F] == state->pm_reg[0x4D] ) )
389362      {
390         pm_reg[0x27] |= 0x01;
363         state->pm_reg[0x27] |= 0x01;
391364         pokemini_check_irqs( machine );
392365      }
393366      pokemini_update_sound( machine );
r9669r9670
397370
398371static TIMER_CALLBACK(pokemini_timer3_hi_callback)
399372{
400   pm_reg[0x4F] -= 1;
373   pokemini_state *state = machine->driver_data<pokemini_state>();
374   state->pm_reg[0x4F] -= 1;
401375   /* Check for underflow of timer */
402   if ( pm_reg[0x4F] == 0xFF )
376   if ( state->pm_reg[0x4F] == 0xFF )
403377   {
404      pm_reg[0x27] |= 0x02;
378      state->pm_reg[0x27] |= 0x02;
405379      pokemini_check_irqs( machine );
406      pm_reg[0x4F] = pm_reg[0x4B];
380      state->pm_reg[0x4F] = state->pm_reg[0x4B];
407381   }
408382
409   if ( ! ( pm_reg[0x48] & 0x80 ) )
383   if ( ! ( state->pm_reg[0x48] & 0x80 ) )
410384   {
411      if( pm_reg[0x4F] == pm_reg[0x4D] )
385      if( state->pm_reg[0x4F] == state->pm_reg[0x4D] )
412386      {
413         pm_reg[0x27] |= 0x01;
387         state->pm_reg[0x27] |= 0x01;
414388         pokemini_check_irqs( machine );
415389      }
416390      pokemini_update_sound( machine );
r9669r9670
420394
421395WRITE8_DEVICE_HANDLER( pokemini_hwreg_w )
422396{
397   pokemini_state *state = device->machine->driver_data<pokemini_state>();
423398   static const int timer_to_cycles_fast[8] = { 2, 8, 32, 64, 128, 256, 1024, 4096 };
424399   static const int timer_to_cycles_slow[8] = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384 };
425400
r9669r9670
446421            */
447422      if ( data & 0x02 )
448423      {
449         pm_reg[0x09] = 0x00;
450         pm_reg[0x0A] = 0x00;
451         pm_reg[0x0B] = 0x00;
424         state->pm_reg[0x09] = 0x00;
425         state->pm_reg[0x0A] = 0x00;
426         state->pm_reg[0x0B] = 0x00;
452427         data &= ~0x02;
453428      }
454429      break;
r9669r9670
486461               Bit 7   R/W Enable high counting
487462            */
488463      /* Check for prescaler change for the low counter */
489      if ( ( data & 0x07 ) != ( pm_reg[0x18] & 0x07 ) )
464      if ( ( data & 0x07 ) != ( state->pm_reg[0x18] & 0x07 ) )
490465      {
491466         int index = data & 0x07;
492         int cycles = ( pm_reg[0x19] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
467         int cycles = ( state->pm_reg[0x19] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
493468
494         timer_adjust_periodic(timers.timer1, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
469         timer_adjust_periodic(state->timers.timer1, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
495470      }
496471
497472      /* Check for prescaler change for the high counter */
498      if ( ( data & 0x70 ) != ( pm_reg[0x18] & 0x70 ) )
473      if ( ( data & 0x70 ) != ( state->pm_reg[0x18] & 0x70 ) )
499474      {
500475         int index = ( data >> 4 ) & 0x07;
501         int cycles = ( pm_reg[0x19] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
476         int cycles = ( state->pm_reg[0x19] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
502477
503         timer_adjust_periodic(timers.timer1_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
478         timer_adjust_periodic(state->timers.timer1_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
504479      }
505480
506481      /* Check if timer1 low should be enabled */
507      if ( ( data & 0x08 ) && ( pm_reg[0x30] & 0x04 ) &&
508           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x01 ) ) ||
509             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x01 ) ) ) )
482      if ( ( data & 0x08 ) && ( state->pm_reg[0x30] & 0x04 ) &&
483           ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x01 ) ) ||
484             ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x01 ) ) ) )
510485      {
511         timer_enable( timers.timer1, 1 );
486         timer_enable( state->timers.timer1, 1 );
512487      }
513488      else
514489      {
515         timer_enable( timers.timer1, 0 );
490         timer_enable( state->timers.timer1, 0 );
516491      }
517492
518493      /* Check if timer1 high should be enabled */
519      if ( ( data & 0x80 ) && ( pm_reg[0x31] & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) &&
520           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ||
521             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) ) )
494      if ( ( data & 0x80 ) && ( state->pm_reg[0x31] & 0x04 ) && ! ( state->pm_reg[0x30] & 0x80 ) &&
495           ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x02 ) ) ||
496             ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x02 ) ) ) )
522497      {
523         timer_enable( timers.timer1_hi, 1 );
498         timer_enable( state->timers.timer1_hi, 1 );
524499      }
525500      else
526501      {
527         timer_enable( timers.timer1_hi, 0 );
502         timer_enable( state->timers.timer1_hi, 0 );
528503      }
529504      break;
530505   case 0x19:   /* Timers 1 speed
r9669r9670
536511               Bit 6-7     Unused
537512            */
538513      /* Check for prescaler change for the high counter */
539      if ( ( data & 0x01 ) != ( pm_reg[0x19] & 0x01 ) )
514      if ( ( data & 0x01 ) != ( state->pm_reg[0x19] & 0x01 ) )
540515      {
541         int index = pm_reg[0x18] & 0x07;
516         int index = state->pm_reg[0x18] & 0x07;
542517         int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
543518
544         timer_adjust_periodic(timers.timer1, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
519         timer_adjust_periodic(state->timers.timer1, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
545520      }
546521
547522      /* Check for prescaler change for the low counter */
548      if ( ( data & 0x02 ) != ( pm_reg[0x19] & 0x02 ) )
523      if ( ( data & 0x02 ) != ( state->pm_reg[0x19] & 0x02 ) )
549524      {
550         int index = ( pm_reg[0x18] >> 4 ) & 0x07;
525         int index = ( state->pm_reg[0x18] >> 4 ) & 0x07;
551526         int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
552527
553         timer_adjust_periodic(timers.timer1_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
528         timer_adjust_periodic(state->timers.timer1_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
554529      }
555530
556531      {
r9669r9670
561536         /* Check which fast timers should be enabled */
562537         if ( data & 0x20 )
563538         {
564            if ( ( pm_reg[0x18] & 0x08 ) && ( pm_reg[0x30] & 0x04 ) && ! ( data & 0x01 ) )
539            if ( ( state->pm_reg[0x18] & 0x08 ) && ( state->pm_reg[0x30] & 0x04 ) && ! ( data & 0x01 ) )
565540               timer1_enable = 1;
566541
567            if ( ( pm_reg[0x18] & 0x80 ) && ( pm_reg[0x31] & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && ! ( data & 0x02 ) )
542            if ( ( state->pm_reg[0x18] & 0x80 ) && ( state->pm_reg[0x31] & 0x04 ) && ! ( state->pm_reg[0x30] & 0x80 ) && ! ( data & 0x02 ) )
568543               timer1_hi_enable = 1;
569544
570            if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x38] & 0x04 ) && ! ( pm_reg[0x1B] & 0x01 ) )
545            if ( ( state->pm_reg[0x1A] & 0x08 ) && ( state->pm_reg[0x38] & 0x04 ) && ! ( state->pm_reg[0x1B] & 0x01 ) )
571546               timer2_enable = 1;
572547
573            if ( ( pm_reg[0x1A] & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && ! ( pm_reg[0x1B] & 0x02 ) )
548            if ( ( state->pm_reg[0x1A] & 0x80 ) && ( state->pm_reg[0x39] & 0x04 ) && ! ( state->pm_reg[0x38] & 0x80 ) && ! ( state->pm_reg[0x1B] & 0x02 ) )
574549               timer2_hi_enable = 1;
575550
576            if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x48] & 0x04 ) && ! ( pm_reg[0x1D] & 0x01 ) )
551            if ( ( state->pm_reg[0x1C] & 0x08 ) && ( state->pm_reg[0x48] & 0x04 ) && ! ( state->pm_reg[0x1D] & 0x01 ) )
577552               timer3_enable = 1;
578553
579            if ( ( pm_reg[0x1C] & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && ! ( pm_reg[0x1D] & 0x02 ) )
554            if ( ( state->pm_reg[0x1C] & 0x80 ) && ( state->pm_reg[0x49] & 0x04 ) && ! ( state->pm_reg[0x48] & 0x80 ) && ! ( state->pm_reg[0x1D] & 0x02 ) )
580555               timer3_hi_enable = 1;
581556         }
582557
583558         /* Check which slow timers should be enabled */
584559         if ( data & 0x10 )
585560         {
586            if ( ( pm_reg[0x18] & 0x08 ) && ( data & 0x01 ) )
561            if ( ( state->pm_reg[0x18] & 0x08 ) && ( data & 0x01 ) )
587562               timer1_enable = 1;
588563
589            if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x1B] & 0x01 ) )
564            if ( ( state->pm_reg[0x1A] & 0x08 ) && ( state->pm_reg[0x1B] & 0x01 ) )
590565               timer2_enable = 1;
591566
592            if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x1D] & 0x01 ) )
567            if ( ( state->pm_reg[0x1C] & 0x08 ) && ( state->pm_reg[0x1D] & 0x01 ) )
593568               timer3_enable = 1;
594569         }
595         timer_enable( timers.timer1, timer1_enable );
596         timer_enable( timers.timer1_hi, timer1_hi_enable );
597         timer_enable( timers.timer2, timer2_enable );
598         timer_enable( timers.timer2_hi, timer2_hi_enable );
599         timer_enable( timers.timer3, timer3_enable );
600         timer_enable( timers.timer3_hi, timer3_hi_enable );
570         timer_enable( state->timers.timer1, timer1_enable );
571         timer_enable( state->timers.timer1_hi, timer1_hi_enable );
572         timer_enable( state->timers.timer2, timer2_enable );
573         timer_enable( state->timers.timer2_hi, timer2_hi_enable );
574         timer_enable( state->timers.timer3, timer3_enable );
575         timer_enable( state->timers.timer3_hi, timer3_hi_enable );
601576      }
602577      break;
603578   case 0x1A:   /* Timer 2 pre-scale + enable
r9669r9670
615590               Bit 7   R/W Enable high counting
616591            */
617592      /* Check for prescaler change for the low counter */
618      if ( ( data & 0x07 ) != ( pm_reg[0x1A] & 0x07 ) )
593      if ( ( data & 0x07 ) != ( state->pm_reg[0x1A] & 0x07 ) )
619594      {
620595         int index = data & 0x07;
621         int cycles = ( pm_reg[0x1B] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
596         int cycles = ( state->pm_reg[0x1B] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
622597
623         timer_adjust_periodic(timers.timer2, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
598         timer_adjust_periodic(state->timers.timer2, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
624599      }
625600
626601      /* Check for prescaler change for the high counter */
627      if ( ( data & 0x70 ) != ( pm_reg[0x1A] & 0x70 ) )
602      if ( ( data & 0x70 ) != ( state->pm_reg[0x1A] & 0x70 ) )
628603      {
629604         int index = ( data >> 4 ) & 0x07;
630         int cycles = ( pm_reg[0x1B] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
605         int cycles = ( state->pm_reg[0x1B] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
631606
632         timer_adjust_periodic(timers.timer2_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
607         timer_adjust_periodic(state->timers.timer2_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
633608      }
634609
635610      /* Check if timer2 low should be enabled */
636      if ( ( data & 0x08 ) && ( pm_reg[0x38] & 0x04 ) &&
637           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x01 ) ) ||
638             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x01 ) ) ) )
611      if ( ( data & 0x08 ) && ( state->pm_reg[0x38] & 0x04 ) &&
612           ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1B] & 0x01 ) ) ||
613             ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1B] & 0x01 ) ) ) )
639614      {
640         timer_enable( timers.timer2, 1 );
615         timer_enable( state->timers.timer2, 1 );
641616      }
642617      else
643618      {
644         timer_enable( timers.timer2, 0 );
619         timer_enable( state->timers.timer2, 0 );
645620      }
646621
647622      /* Check if timer2 high should be enabled */
648      if ( ( data & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) &&
649           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ||
650             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) ) )
623      if ( ( data & 0x80 ) && ( state->pm_reg[0x39] & 0x04 ) && ! ( state->pm_reg[0x38] & 0x80 ) &&
624           ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1B] & 0x02 ) ) ||
625             ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1B] & 0x02 ) ) ) )
651626      {
652         timer_enable( timers.timer2_hi, 1 );
627         timer_enable( state->timers.timer2_hi, 1 );
653628      }
654629      else
655630      {
656         timer_enable( timers.timer2_hi, 0 );
631         timer_enable( state->timers.timer2_hi, 0 );
657632      }
658633      break;
659634   case 0x1B:   /* Timer 2 speeds
r9669r9670
661636               Bit 1   R/W Select slow timer for timer 2 hi
662637            */
663638      /* Check for prescaler change for the high counter */
664      if ( ( data & 0x01 ) != ( pm_reg[0x1B] & 0x01 ) )
639      if ( ( data & 0x01 ) != ( state->pm_reg[0x1B] & 0x01 ) )
665640      {
666         int index = pm_reg[0x1A] & 0x07;
641         int index = state->pm_reg[0x1A] & 0x07;
667642         int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
668643
669         timer_adjust_periodic(timers.timer2, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
644         timer_adjust_periodic(state->timers.timer2, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
670645
671         if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x38] & 0x04 ) &&
672              ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) ||
673                ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) )
646         if ( ( state->pm_reg[0x1A] & 0x08 ) && ( state->pm_reg[0x38] & 0x04 ) &&
647              ( ( ( state->pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) ||
648                ( ( state->pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) )
674649         {
675            timer_enable( timers.timer2, 1 );
650            timer_enable( state->timers.timer2, 1 );
676651         }
677652         else
678653         {
679            timer_enable( timers.timer2, 0 );
654            timer_enable( state->timers.timer2, 0 );
680655         }
681656      }
682657
683658      /* Check for prescaler change for the low counter */
684      if ( ( data & 0x02 ) != ( pm_reg[0x1B] & 0x02 ) )
659      if ( ( data & 0x02 ) != ( state->pm_reg[0x1B] & 0x02 ) )
685660      {
686         int index = ( pm_reg[0x1A] >> 4 ) & 0x07;
661         int index = ( state->pm_reg[0x1A] >> 4 ) & 0x07;
687662         int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
688663
689         timer_adjust_periodic(timers.timer2_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
664         timer_adjust_periodic(state->timers.timer2_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
690665
691         if ( ( pm_reg[0x1A] & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) &&
692              ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) ||
693                ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) )
666         if ( ( state->pm_reg[0x1A] & 0x80 ) && ( state->pm_reg[0x39] & 0x04 ) && ! ( state->pm_reg[0x38] & 0x80 ) &&
667              ( ( ( state->pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) ||
668                ( ( state->pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) )
694669         {
695            timer_enable( timers.timer2_hi, 1 );
670            timer_enable( state->timers.timer2_hi, 1 );
696671         }
697672         else
698673         {
699            timer_enable( timers.timer2_hi, 0 );
674            timer_enable( state->timers.timer2_hi, 0 );
700675         }
701676      }
702677      break;
r9669r9670
715690               Bit 7   R/W Enable high counting
716691            */
717692      /* Check for prescaler change for the low counter */
718      if ( ( data & 0x07 ) != ( pm_reg[0x1C] & 0x07 ) )
693      if ( ( data & 0x07 ) != ( state->pm_reg[0x1C] & 0x07 ) )
719694      {
720695         int index = data & 0x07;
721         int cycles = ( pm_reg[0x1D] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
696         int cycles = ( state->pm_reg[0x1D] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
722697
723         timer_adjust_periodic(timers.timer3, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
698         timer_adjust_periodic(state->timers.timer3, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
724699      }
725700
726701      /* Check for prescaler change for the high counter */
727      if ( ( data & 0x70 ) != ( pm_reg[0x1C] & 0x70 ) )
702      if ( ( data & 0x70 ) != ( state->pm_reg[0x1C] & 0x70 ) )
728703      {
729704         int index = ( data >> 4 ) & 0x07;
730         int cycles = ( pm_reg[0x1D] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
705         int cycles = ( state->pm_reg[0x1D] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
731706
732         timer_adjust_periodic(timers.timer3_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
707         timer_adjust_periodic(state->timers.timer3_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
733708      }
734709
735710      /* Check if timer2 low should be enabled */
736      if ( ( data & 0x08 ) && ( pm_reg[0x48] & 0x04 ) &&
737           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x01 ) ) ||
738             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x01 ) ) ) )
711      if ( ( data & 0x08 ) && ( state->pm_reg[0x48] & 0x04 ) &&
712           ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x01 ) ) ||
713             ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x01 ) ) ) )
739714      {
740         timer_enable( timers.timer3, 1 );
715         timer_enable( state->timers.timer3, 1 );
741716      }
742717      else
743718      {
744         timer_enable( timers.timer3, 0 );
719         timer_enable( state->timers.timer3, 0 );
745720      }
746721
747722      /* Check if timer2 high should be enabled */
748      if ( ( data & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) &&
749           ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ||
750             ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) ) )
723      if ( ( data & 0x80 ) && ( state->pm_reg[0x49] & 0x04 ) && ! ( state->pm_reg[0x48] & 0x80 ) &&
724           ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x02 ) ) ||
725             ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x02 ) ) ) )
751726      {
752         timer_enable( timers.timer3_hi, 1 );
727         timer_enable( state->timers.timer3_hi, 1 );
753728      }
754729      else
755730      {
756         timer_enable( timers.timer3_hi, 0 );
731         timer_enable( state->timers.timer3_hi, 0 );
757732      }
758733      break;
759734   case 0x1D:   /* Timer 3 speeds
r9669r9670
761736               Bit 1   R/W Select slow timer for timer 3 hi
762737            */
763738      /* Check for prescaler change for the high counter */
764      if ( ( data & 0x01 ) != ( pm_reg[0x1D] & 0x01 ) )
739      if ( ( data & 0x01 ) != ( state->pm_reg[0x1D] & 0x01 ) )
765740      {
766         int index = pm_reg[0x1C] & 0x07;
741         int index = state->pm_reg[0x1C] & 0x07;
767742         int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
768743
769         timer_adjust_periodic(timers.timer3, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
744         timer_adjust_periodic(state->timers.timer3, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
770745
771         if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x48] & 0x04 ) &&
772              ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) ||
773                ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) )
746         if ( ( state->pm_reg[0x1C] & 0x08 ) && ( state->pm_reg[0x48] & 0x04 ) &&
747              ( ( ( state->pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) ||
748                ( ( state->pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) )
774749         {
775            timer_enable( timers.timer3, 1 );
750            timer_enable( state->timers.timer3, 1 );
776751         }
777752         else
778753         {
779            timer_enable( timers.timer3, 0 );
754            timer_enable( state->timers.timer3, 0 );
780755         }
781756      }
782757
783758      /* Check for prescaler change for the low counter */
784      if ( ( data & 0x02 ) != ( pm_reg[0x1D] & 0x02 ) )
759      if ( ( data & 0x02 ) != ( state->pm_reg[0x1D] & 0x02 ) )
785760      {
786         int index = ( pm_reg[0x1C] >> 4 ) & 0x07;
761         int index = ( state->pm_reg[0x1C] >> 4 ) & 0x07;
787762         int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index];
788763
789         timer_adjust_periodic(timers.timer3_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
764         timer_adjust_periodic(state->timers.timer3_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles));
790765
791         if ( ( pm_reg[0x1C] & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) &&
792              ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) ||
793                ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) )
766         if ( ( state->pm_reg[0x1C] & 0x80 ) && ( state->pm_reg[0x49] & 0x04 ) && ! ( state->pm_reg[0x48] & 0x80 ) &&
767              ( ( ( state->pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) ||
768                ( ( state->pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) )
794769         {
795            timer_enable( timers.timer3_hi, 1 );
770            timer_enable( state->timers.timer3_hi, 1 );
796771         }
797772         else
798773         {
799            timer_enable( timers.timer3_hi, 0 );
774            timer_enable( state->timers.timer3_hi, 0 );
800775         }
801776      }
802777      break;
r9669r9670
806781               Bit 4-5 R/W Timer 2 overflow Interrupt #3-#4
807782               Bit 6-7 R/W VDraw/VBlank trigger Interrupt #1-#2
808783            */
809      pm_reg[0x20] = data;
784      state->pm_reg[0x20] = data;
810785      pokemini_check_irqs( device->machine );
811786      break;
812787   case 0x21:   /* Event #15-#22 priority
r9669r9670
814789               Bit 2-3 R/W All keypad interrupts - Interrupt #15-#22
815790               Bit 4-7 R/W Unknown
816791            */
817      pm_reg[0x21] = data;
792      state->pm_reg[0x21] = data;
818793      pokemini_check_irqs( device->machine );
819794      break;
820795   case 0x22:   /* Event #9-#14 priority
821796               Bit 0-1 R/W All #9 - #14 events - Interrupt #9-#14
822797               Bit 2-7     Unused
823798            */
824      pm_reg[0x22] = data;
799      state->pm_reg[0x22] = data;
825800      pokemini_check_irqs( device->machine );
826801      break;
827802   case 0x23:   /* Event #1-#8 enable
r9669r9670
834809               Bit 6   R/W V-Draw trigger - Enable Interrupt #2
835810               Bit 7   R/W V-Blank trigger - Enable Interrupt #1
836811            */
837      pm_reg[0x23] = data;
812      state->pm_reg[0x23] = data;
838813      pokemini_check_irqs( device->machine );
839814      break;
840815   case 0x24:   /* Event #9-#12 enable
841816               Bit 0-5 R/W Unknown
842817               Bit 6-7     Unused
843818            */
844      pm_reg[0x24] = data;
819      state->pm_reg[0x24] = data;
845820      pokemini_check_irqs( device->machine );
846821      break;
847822   case 0x25:   /* Event #15-#22 enable
r9669r9670
854829               Bit 6   R/W Press D-pad right key event - Enable interrupt #16
855830               Bit 7   R/W Press power button event - Enable interrupt #15
856831            */
857      pm_reg[0x25] = data;
832      state->pm_reg[0x25] = data;
858833      pokemini_check_irqs( device->machine );
859834      break;
860835   case 0x26:   /* Event #13-#14 enable
r9669r9670
864839               Bit 6   R/W Shock detector trigger - Enable interrupt #14
865840               Bit 7   R/W IR receiver - low to high trigger - Enable interrupt #13
866841            */
867      pm_reg[0x26] = data;
842      state->pm_reg[0x26] = data;
868843      pokemini_check_irqs( device->machine );
869844      break;
870845   case 0x27:   /* Interrupt active flag #1-#8
r9669r9670
877852               Bit 6       VDraw trigger / Clear interrupt #2
878853               Bit 7       VBlank trigger / Clear interrupt #1
879854            */
880      pm_reg[0x27] &= ~data;
855      state->pm_reg[0x27] &= ~data;
881856      pokemini_check_irqs( device->machine );
882857      return;
883858   case 0x28:   /* Interrupt active flag #9-#12
r9669r9670
888863               Bit 5       Unknown / Clear interrupt #9
889864               Bit 6-7     Unknown
890865            */
891      pm_reg[0x28] &= ~data;
866      state->pm_reg[0x28] &= ~data;
892867      pokemini_check_irqs( device->machine );
893868      return;
894869   case 0x29:   /* Interrupt active flag #15-#22
r9669r9670
901876               Bit 6       Press D-pad right key event / Clear interrupt #16
902877               Bit 7       Press power button event / Clear interrupt #15
903878            */
904      pm_reg[0x29] &= ~data;
879      state->pm_reg[0x29] &= ~data;
905880      pokemini_check_irqs( device->machine );
906881      return;
907882   case 0x2A:   /* Interrupt active flag #13-#14
r9669r9670
909884               Bit 6       Shock detector trigger / Clear interrupt #14
910885               Bit 7       Unknown / Clear interrupt #13
911886            */
912      pm_reg[0x2A] &= ~data;
887      state->pm_reg[0x2A] &= ~data;
913888      pokemini_check_irqs( device->machine );
914889      return;
915890   case 0x30:   /* Timer 1 control 1
r9669r9670
922897            */
923898      if ( data & 0x02 )
924899      {
925         pm_reg[0x36] = pm_reg[0x32];
900         state->pm_reg[0x36] = state->pm_reg[0x32];
926901         data &= ~0x02;
927902      }
928903
929      if ( ( data & 0x04 ) && ( pm_reg[0x18] & 0x08 ) &&
930           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x01 ) ) ||
931             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x01 ) ) ) )
904      if ( ( data & 0x04 ) && ( state->pm_reg[0x18] & 0x08 ) &&
905           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x01 ) ) ||
906             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x01 ) ) ) )
932907      {
933         timer_enable( timers.timer1, 1 );
908         timer_enable( state->timers.timer1, 1 );
934909      }
935910      else
936911      {
937         timer_enable( timers.timer1, 0 );
912         timer_enable( state->timers.timer1, 0 );
938913      }
939914
940      if ( ( pm_reg[0x31] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x18] & 0x80 ) &&
941           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) ||
942             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ) )
915      if ( ( state->pm_reg[0x31] & 0x04 ) && ! ( data & 0x80 ) && ( state->pm_reg[0x18] & 0x80 ) &&
916           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x02 ) ) ||
917             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x02 ) ) ) )
943918      {
944         timer_enable( timers.timer1_hi, 1 );
919         timer_enable( state->timers.timer1_hi, 1 );
945920      }
946921      else
947922      {
948         timer_enable( timers.timer1_hi, 0 );
923         timer_enable( state->timers.timer1_hi, 0 );
949924      }
950925      break;
951926   case 0x31:   /* Timer 1 control 2
r9669r9670
957932            */
958933      if ( data & 0x02 )
959934      {
960         pm_reg[0x37] = pm_reg[0x33];
935         state->pm_reg[0x37] = state->pm_reg[0x33];
961936         data &= ~0x02;
962937      }
963938
964      if ( ( data & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && ( pm_reg[0x18] & 0x80 ) &&
965           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) ||
966             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ) )
939      if ( ( data & 0x04 ) && ! ( state->pm_reg[0x30] & 0x80 ) && ( state->pm_reg[0x18] & 0x80 ) &&
940           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x02 ) ) ||
941             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x02 ) ) ) )
967942      {
968         timer_enable( timers.timer1_hi, 1 );
943         timer_enable( state->timers.timer1_hi, 1 );
969944      }
970945      else
971946      {
972         timer_enable( timers.timer1_hi, 0 );
947         timer_enable( state->timers.timer1_hi, 0 );
973948      }
974949      break;
975950   case 0x32:   /* Timer 1 preset value (low)
r9669r9670
1002977            */
1003978      if ( data & 0x02 )
1004979      {
1005         pm_reg[0x3E] = pm_reg[0x3A];
980         state->pm_reg[0x3E] = state->pm_reg[0x3A];
1006981         data &= ~0x02;
1007982      }
1008983
1009      if ( ( data & 0x04 ) && ( pm_reg[0x1A] & 0x08 ) &&
1010           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1A] & 0x01 ) ) ||
1011             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1A] & 0x01 ) ) ) )
984      if ( ( data & 0x04 ) && ( state->pm_reg[0x1A] & 0x08 ) &&
985           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1A] & 0x01 ) ) ||
986             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1A] & 0x01 ) ) ) )
1012987      {
1013         timer_enable( timers.timer2, 1 );
988         timer_enable( state->timers.timer2, 1 );
1014989      }
1015990      else
1016991      {
1017         timer_enable( timers.timer2, 0 );
992         timer_enable( state->timers.timer2, 0 );
1018993      }
1019      if ( ( pm_reg[0x39] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x1A] & 0x80 ) &&
1020           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) ||
1021             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ) )
994      if ( ( state->pm_reg[0x39] & 0x04 ) && ! ( data & 0x80 ) && ( state->pm_reg[0x1A] & 0x80 ) &&
995           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1B] & 0x02 ) ) ||
996             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1B] & 0x02 ) ) ) )
1022997      {
1023         timer_enable( timers.timer2_hi, 1 );
998         timer_enable( state->timers.timer2_hi, 1 );
1024999      }
10251000      else
10261001      {
1027         timer_enable( timers.timer2_hi, 0 );
1002         timer_enable( state->timers.timer2_hi, 0 );
10281003      }
10291004      break;
10301005   case 0x39:   /* Timer 2 control 2
r9669r9670
10361011            */
10371012      if ( data & 0x02 )
10381013      {
1039         pm_reg[0x3F] = pm_reg[0x3A];
1014         state->pm_reg[0x3F] = state->pm_reg[0x3A];
10401015         data &= ~0x02;
10411016      }
10421017
1043      if ( ( data & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && ( pm_reg[0x1A] & 0x80 ) &&
1044           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) ||
1045             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ) )
1018      if ( ( data & 0x04 ) && ! ( state->pm_reg[0x38] & 0x80 ) && ( state->pm_reg[0x1A] & 0x80 ) &&
1019           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1B] & 0x02 ) ) ||
1020             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1B] & 0x02 ) ) ) )
10461021      {
1047         timer_enable( timers.timer2_hi, 1 );
1022         timer_enable( state->timers.timer2_hi, 1 );
10481023      }
10491024      else
10501025      {
1051         timer_enable( timers.timer2_hi, 0 );
1026         timer_enable( state->timers.timer2_hi, 0 );
10521027      }
10531028      break;
10541029   case 0x3A:   /* Timer 2 preset value (low)
r9669r9670
10801055            */
10811056      if ( data & 0x02 )
10821057      {
1083         pm_reg[0x41] = 0;
1058         state->pm_reg[0x41] = 0;
10841059         data &= ~0x02;
10851060      }
10861061      break;
r9669r9670
10981073            */
10991074      if ( data & 0x02 )
11001075      {
1101         pm_reg[0x4E] = pm_reg[0x4A];
1076         state->pm_reg[0x4E] = state->pm_reg[0x4A];
11021077         data &= ~0x02;
11031078      }
11041079
1105      if ( ( data & 0x04 ) && ( pm_reg[0x1C] & 0x08 ) &&
1106           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x01 ) ) ||
1107             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x01 ) ) ) )
1080      if ( ( data & 0x04 ) && ( state->pm_reg[0x1C] & 0x08 ) &&
1081           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x01 ) ) ||
1082             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x01 ) ) ) )
11081083      {
1109         timer_enable( timers.timer3, 1 );
1084         timer_enable( state->timers.timer3, 1 );
11101085      }
11111086      else
11121087      {
1113         timer_enable( timers.timer3, 0 );
1088         timer_enable( state->timers.timer3, 0 );
11141089      }
1115      if ( ( pm_reg[0x49] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x1C] & 0x80 ) &&
1116           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) ||
1117             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ) )
1090      if ( ( state->pm_reg[0x49] & 0x04 ) && ! ( data & 0x80 ) && ( state->pm_reg[0x1C] & 0x80 ) &&
1091           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x02 ) ) ||
1092             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x02 ) ) ) )
11181093      {
1119         timer_enable( timers.timer3_hi, 1 );
1094         timer_enable( state->timers.timer3_hi, 1 );
11201095      }
11211096      else
11221097      {
1123         timer_enable( timers.timer3_hi, 0 );
1098         timer_enable( state->timers.timer3_hi, 0 );
11241099      }
1125      pm_reg[0x48] = data;
1100      state->pm_reg[0x48] = data;
11261101      pokemini_update_sound( device->machine );
11271102      break;
11281103   case 0x49:   /* Timer 3 control 2
r9669r9670
11341109            */
11351110      if ( data & 0x02 )
11361111      {
1137         pm_reg[0x4F] = pm_reg[0x4B];
1112         state->pm_reg[0x4F] = state->pm_reg[0x4B];
11381113         data &= ~0x02;
11391114      }
11401115
1141      if ( ( data & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && ( pm_reg[0x1C] & 0x80 ) &&
1142           ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) ||
1143             ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ) )
1116      if ( ( data & 0x04 ) && ! ( state->pm_reg[0x48] & 0x80 ) && ( state->pm_reg[0x1C] & 0x80 ) &&
1117           ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x02 ) ) ||
1118             ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x02 ) ) ) )
11441119      {
1145         timer_enable( timers.timer3_hi, 1 );
1120         timer_enable( state->timers.timer3_hi, 1 );
11461121      }
11471122      else
11481123      {
1149         timer_enable( timers.timer3_hi, 0 );
1124         timer_enable( state->timers.timer3_hi, 0 );
11501125      }
1151      pm_reg[0x49] = data;
1126      state->pm_reg[0x49] = data;
11521127      pokemini_update_sound( device->machine );
11531128      break;
11541129   case 0x4A:   /* Timer 3 preset value (low)
11551130               Bit 0-7 R/W Timer 3 preset value bit 0-7
11561131            */
1157      pm_reg[0x4A] = data;
1132      state->pm_reg[0x4A] = data;
11581133      pokemini_update_sound( device->machine );
11591134      break;
11601135   case 0x4B:   /* Timer 3 preset value (high)
11611136               Bit 0-7 R/W Timer 3 preset value bit 8-15
11621137            */
1163      pm_reg[0x4B] = data;
1138      state->pm_reg[0x4B] = data;
11641139      pokemini_update_sound( device->machine );
11651140      break;
11661141   case 0x4C:   /* Timer 3 sound-pivot (low)
11671142               Bit 0-7 R/W Timer 3 sound-pivot value bit 0-7
11681143            */
1169      pm_reg[0x4C] = data;
1144      state->pm_reg[0x4C] = data;
11701145      pokemini_update_sound( device->machine );
11711146      break;
11721147   case 0x4D:   /* Timer 3 sound-pivot (high)
r9669r9670
11771152               Pulse-Width of 50% = Half of preset-value
11781153               Pulse-Width of 100% = Same as preset-value
11791154            */
1180      pm_reg[0x4D] = data;
1155      state->pm_reg[0x4D] = data;
11811156      pokemini_update_sound( device->machine );
11821157      break;
11831158   case 0x4E:   /* Timer 3 counter (low), read only
r9669r9670
12201195               Bit 6       Always 1
12211196               Bit 7   R/W IR received bit (mirror, if device not selected: 0)
12221197            */
1223      if ( pm_reg[0x60] & 0x04 )
1198      if ( state->pm_reg[0x60] & 0x04 )
12241199         i2cmem_sda_write(device, ( data & 0x04 ) ? 1 : 0 );
12251200
1226      if ( pm_reg[0x60] & 0x08 )
1201      if ( state->pm_reg[0x60] & 0x08 )
12271202         i2cmem_scl_write(device, ( data & 0x08 ) ? 1 : 0 );
12281203      break;
12291204   case 0x70:   /* Sound related */
1230      pm_reg[0x70] = data;
1205      state->pm_reg[0x70] = data;
12311206      pokemini_update_sound( device->machine );
12321207      break;
12331208   case 0x71:   /* Sound volume
r9669r9670
12391214               Bit 2   R/W Always set to 0
12401215               Bit 3-7     Unused
12411216            */
1242      pm_reg[0x71] = data;
1217      state->pm_reg[0x71] = data;
12431218      pokemini_update_sound( device->machine );
12441219      break;
12451220   case 0x80:   /* LCD control
r9669r9670
12541229                           11 - 24x8 (prohibited code)
12551230              Bit 6-7      Unused
12561231            */
1257      prc.colors_inverted = ( data & 0x01 ) ? 1 : 0;
1258      prc.background_enabled = ( data & 0x02 ) ? 1 : 0;
1259      prc.sprites_enabled = ( data & 0x04 ) ? 1 : 0;
1260      prc.copy_enabled = ( data & 0x08 ) ? 1 : 0;
1261      prc.map_size = ( data >> 4 ) & 0x03;
1262      switch( prc.map_size )
1232      state->prc.colors_inverted = ( data & 0x01 ) ? 1 : 0;
1233      state->prc.background_enabled = ( data & 0x02 ) ? 1 : 0;
1234      state->prc.sprites_enabled = ( data & 0x04 ) ? 1 : 0;
1235      state->prc.copy_enabled = ( data & 0x08 ) ? 1 : 0;
1236      state->prc.map_size = ( data >> 4 ) & 0x03;
1237      switch( state->prc.map_size )
12631238      {
12641239      case 0:
1265         prc.map_size_x = 12; break;
1240         state->prc.map_size_x = 12; break;
12661241      case 1:
1267         prc.map_size_x = 16; break;
1242         state->prc.map_size_x = 16; break;
12681243      case 2:
12691244      case 3:
1270         prc.map_size_x = 24; break;
1245         state->prc.map_size_x = 24; break;
12711246      }
12721247      break;
12731248   case 0x81:   /* LCD render refresh rate
r9669r9670
12851260            */
12861261      switch ( data & 0x0E )
12871262      {
1288      case 0x00:   prc.max_frame_count = 3; break;
1289      case 0x02:   prc.max_frame_count = 6; break;
1290      case 0x04:   prc.max_frame_count = 9; break;
1291      case 0x06:   prc.max_frame_count = 12; break;
1292      case 0x08:   prc.max_frame_count = 2; break;
1293      case 0x0A:   prc.max_frame_count = 4; break;
1294      case 0x0C:   prc.max_frame_count = 6; break;
1295      case 0x0E:   prc.max_frame_count = 8; break;
1263      case 0x00:   state->prc.max_frame_count = 3; break;
1264      case 0x02:   state->prc.max_frame_count = 6; break;
1265      case 0x04:   state->prc.max_frame_count = 9; break;
1266      case 0x06:   state->prc.max_frame_count = 12; break;
1267      case 0x08:   state->prc.max_frame_count = 2; break;
1268      case 0x0A:   state->prc.max_frame_count = 4; break;
1269      case 0x0C:   state->prc.max_frame_count = 6; break;
1270      case 0x0E:   state->prc.max_frame_count = 8; break;
12961271      }
12971272      break;
12981273   case 0x82:   /* BG tile data memory offset (low)
r9669r9670
13001275               Bit 3-7 R/W BG tile data memory offset bit 3-7
13011276            */
13021277      data &= 0xF8;
1303      prc.bg_tiles = ( prc.bg_tiles & 0xFFFF00 ) | data;
1278      state->prc.bg_tiles = ( state->prc.bg_tiles & 0xFFFF00 ) | data;
13041279      break;
13051280   case 0x83:   /* BG tile data memory offset (mid)
13061281               Bit 0-7 R/W BG tile data memory offset bit 8-15
13071282            */
1308      prc.bg_tiles = ( prc.bg_tiles & 0xFF00FF ) | ( data << 8 );
1283      state->prc.bg_tiles = ( state->prc.bg_tiles & 0xFF00FF ) | ( data << 8 );
13091284      break;
13101285   case 0x84:   /* BG tile data memory offset (high)
13111286               Bit 0-4 R/W BG tile data memory offset bit 16-20
13121287               Bit 5-7     Unused
13131288            */
13141289      data &= 0x1F;
1315      prc.bg_tiles = ( prc.bg_tiles & 0x00FFFF ) | ( data << 16 );
1290      state->prc.bg_tiles = ( state->prc.bg_tiles & 0x00FFFF ) | ( data << 16 );
13161291      break;
13171292   case 0x85:   /* BG vertical move
13181293               Bit 0-6 R/W Move the background up, move range:
r9669r9670
13351310               Bit 6-7 R/W Sprite tile data memory offset bit 6-7
13361311            */
13371312      data &= 0xC0;
1338      prc.spr_tiles = ( prc.spr_tiles & 0xFFFF00 ) | data;
1313      state->prc.spr_tiles = ( state->prc.spr_tiles & 0xFFFF00 ) | data;
13391314      break;
13401315   case 0x88:   /* Sprite tile data memory offset (med)
13411316               Bit 0-7 R/W Sprite tile data memory offset bit 8-15
13421317            */
1343      prc.spr_tiles = ( prc.spr_tiles & 0xFF00FF ) | ( data << 8 );
1318      state->prc.spr_tiles = ( state->prc.spr_tiles & 0xFF00FF ) | ( data << 8 );
13441319      break;
13451320   case 0x89:   /* Sprite tile data memory offset (high)
13461321               Bit 0-4 R/W Sprite tile data memory offset bit 16-20
13471322               Bit 5-7     Unused
13481323            */
13491324      data &= 0x1F;
1350      prc.spr_tiles = ( prc.spr_tiles & 0x00FFFF ) | ( data << 16 );
1325      state->prc.spr_tiles = ( state->prc.spr_tiles & 0x00FFFF ) | ( data << 16 );
13511326      break;
13521327   case 0x8A:   /* LCD status
13531328               Bit 0   R   Unknown
r9669r9670
13721347      logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", cpu_get_pc( device->machine->firstcpu ), offset, data );
13731348      break;
13741349   }
1375   pm_reg[offset] = data;
1350   state->pm_reg[offset] = data;
13761351}
13771352
13781353READ8_DEVICE_HANDLER( pokemini_hwreg_r )
13791354{
1380   UINT8 data = pm_reg[offset];
1355   pokemini_state *state = device->machine->driver_data<pokemini_state>();
1356   UINT8 data = state->pm_reg[offset];
13811357
13821358   switch( offset )
13831359   {
13841360   case 0x52:   return input_port_read(device->machine, "INPUTS");
13851361   case 0x61:
1386      if ( ! ( pm_reg[0x60] & 0x04 ) )
1362      if ( ! ( state->pm_reg[0x60] & 0x04 ) )
13871363      {
13881364         data = ( data & ~ 0x04 ) | ( i2cmem_sda_read( device) ? 0x04 : 0x00 );
13891365      }
13901366
1391      if ( ! ( pm_reg[0x60] & 0x08 ) )
1367      if ( ! ( state->pm_reg[0x60] & 0x08 ) )
13921368      {
13931369         data &= ~0x08;
13941370      }
13951371      break;
1396   case 0x81:   return ( pm_reg[offset] & 0x0F ) | ( prc.frame_count << 4 );
1397   case 0x8A:   return prc.count;
1372   case 0x81:   return ( state->pm_reg[offset] & 0x0F ) | ( state->prc.frame_count << 4 );
1373   case 0x8A:   return state->prc.count;
13981374   }
13991375   return data;
14001376}
r9669r9670
14421418
14431419static TIMER_CALLBACK( pokemini_prc_counter_callback )
14441420{
1421   pokemini_state *state = machine->driver_data<pokemini_state>();
14451422   address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM );
1446   prc.count++;
1423   state->prc.count++;
14471424
14481425   /* Check for overflow */
1449   if ( prc.count >= 0x42 )
1426   if ( state->prc.count >= 0x42 )
14501427   {
1451      prc.count = 0;
1452      prc.frame_count++;
1428      state->prc.count = 0;
1429      state->prc.frame_count++;
14531430   }
14541431   else
14551432   {
1456      if ( prc.count == 0x18 && prc.frame_count >= prc.max_frame_count )
1433      if ( state->prc.count == 0x18 && state->prc.frame_count >= state->prc.max_frame_count )
14571434      {
1458         prc.frame_count = 0;
1435         state->prc.frame_count = 0;
14591436
14601437         /* Check if the background should be drawn */
1461         if ( prc.background_enabled )
1438         if ( state->prc.background_enabled )
14621439         {
14631440            int x, y;
14641441            for ( y = 0; y < 8; y++ ) {
14651442               for ( x = 0; x < 12; x++ ) {
1466                  UINT8 tile = pokemini_ram[ 0x360 + ( y * prc.map_size_x ) + x ];
1443                  UINT8 tile = state->ram[ 0x360 + ( y * state->prc.map_size_x ) + x ];
14671444                  int i;
14681445                  for( i = 0; i < 8; i++ ) {
1469                     pokemini_ram[ ( y * 96 ) + ( x * 8 ) + i ] = space->read_byte( prc.bg_tiles + ( tile * 8 ) + i );
1446                     state->ram[ ( y * 96 ) + ( x * 8 ) + i ] = space->read_byte( state->prc.bg_tiles + ( tile * 8 ) + i );
14701447                  }
14711448               }
14721449            }
14731450         }
14741451
14751452         /* Check if the sprites should be drawn */
1476         if ( prc.sprites_enabled )
1453         if ( state->prc.sprites_enabled )
14771454         {
14781455            UINT16   spr;
14791456
14801457            for ( spr = 0x35C; spr >= 0x300; spr -= 4 )
14811458            {
1482               int      spr_x = ( pokemini_ram[ spr + 0 ] & 0x7F ) - 16;
1483               int      spr_y = ( pokemini_ram[ spr + 1 ] & 0x7F ) - 16;
1484               UINT8   spr_tile = pokemini_ram[ spr + 2 ];
1485               UINT8   spr_flag = pokemini_ram[ spr + 3 ];
1459               int      spr_x = ( state->ram[ spr + 0 ] & 0x7F ) - 16;
1460               int      spr_y = ( state->ram[ spr + 1 ] & 0x7F ) - 16;
1461               UINT8   spr_tile = state->ram[ spr + 2 ];
1462               UINT8   spr_flag = state->ram[ spr + 3 ];
14861463
14871464               if ( spr_flag & 0x08 )
14881465               {
14891466                  UINT16   gfx, mask;
1490                  UINT32   spr_base = prc.spr_tiles + spr_tile * 64;
1467                  UINT32   spr_base = state->prc.spr_tiles + spr_tile * 64;
14911468                  int      i, j;
14921469
14931470                  for ( i = 0; i < 16; i++ )
r9669r9670
15161493                              {
15171494                                 if ( mask & 0x8000 )
15181495                                 {
1519                                    pokemini_ram[ ram_addr ] &= ~ ( 1 << ( ( spr_y + j ) & 0x07 ) );
1496                                    state->ram[ ram_addr ] &= ~ ( 1 << ( ( spr_y + j ) & 0x07 ) );
15201497                                    if ( gfx & 0x8000 )
15211498                                    {
1522                                       pokemini_ram[ ram_addr ] |= ( 1 << ( ( spr_y + j ) & 0x07 ) );
1499                                       state->ram[ ram_addr ] |= ( 1 << ( ( spr_y + j ) & 0x07 ) );
15231500                                    }
15241501                                 }
15251502                                 mask <<= 1;
r9669r9670
15291506                              {
15301507                                 if ( mask & 0x0001 )
15311508                                 {
1532                                    pokemini_ram[ ram_addr ] &= ~ ( 1 << ( ( spr_y + j ) & 0x07 ) );
1509                                    state->ram[ ram_addr ] &= ~ ( 1 << ( ( spr_y + j ) & 0x07 ) );
15331510                                    if ( gfx & 0x0001 )
15341511                                    {
1535                                       pokemini_ram[ ram_addr ] |= ( 1 << ( ( spr_y + j ) & 0x07 ) );
1512                                       state->ram[ ram_addr ] |= ( 1 << ( ( spr_y + j ) & 0x07 ) );
15361513                                    }
15371514                                 }
15381515                                 mask >>= 1;
r9669r9670
15471524         }
15481525
15491526         /* Set PRC Render interrupt */
1550         pm_reg[0x27] |= 0x40;
1527         state->pm_reg[0x27] |= 0x40;
15511528         pokemini_check_irqs( machine );
15521529
15531530         /* Check if the rendered data should be copied to the LCD */
1554         if ( prc.copy_enabled )
1531         if ( state->prc.copy_enabled )
15551532         {
15561533            int   x, y;
15571534
15581535            for( y = 0; y < 64; y += 8 ) {
15591536               for( x = 0; x < 96; x++ ) {
1560                  UINT8 data = pokemini_ram[ ( y * 12 ) + x ];
1537                  UINT8 data = state->ram[ ( y * 12 ) + x ];
15611538
15621539                  *BITMAP_ADDR16(machine->generic.tmpbitmap, y + 0, x) = ( data & 0x01 ) ? 3 : 0;
15631540                  *BITMAP_ADDR16(machine->generic.tmpbitmap, y + 1, x) = ( data & 0x02 ) ? 3 : 0;
r9669r9670
15711548            }
15721549
15731550            /* Set PRC Copy interrupt */
1574            pm_reg[0x27] |= 0x80;
1551            state->pm_reg[0x27] |= 0x80;
15751552            pokemini_check_irqs( machine );
15761553         }
15771554      }
15781555
15791556      /* Set possible input irqs */
1580      pm_reg[0x29] |= ~ input_port_read( machine, "INPUTS" );
1557      state->pm_reg[0x29] |= ~ input_port_read( machine, "INPUTS" );
15811558   }
15821559}
15831560
15841561
15851562MACHINE_START( pokemini )
15861563{
1564   pokemini_state *state = machine->driver_data<pokemini_state>();
15871565   /* Clear internal structures */
1588   memset( &prc, 0, sizeof(prc) );
1589   memset( &timers, 0, sizeof(timers) );
1590   memset( pm_reg, 0, sizeof(pm_reg) );
1566   memset( &state->prc, 0, sizeof(state->prc) );
1567   memset( &state->timers, 0, sizeof(state->timers) );
1568   memset( state->pm_reg, 0, sizeof(state->pm_reg) );
15911569
15921570   /* Set up timers */
1593   timers.seconds_timer = timer_alloc(machine,  pokemini_seconds_timer_callback , NULL );
1594   timer_adjust_periodic( timers.seconds_timer, attotime_zero, 0, ATTOTIME_IN_SEC( 1 ) );
1571   state->timers.seconds_timer = timer_alloc(machine,  pokemini_seconds_timer_callback , NULL );
1572   timer_adjust_periodic( state->timers.seconds_timer, attotime_zero, 0, ATTOTIME_IN_SEC( 1 ) );
15951573
1596   timers.hz256_timer = timer_alloc(machine,  pokemini_256hz_timer_callback , NULL );
1597   timer_adjust_periodic( timers.hz256_timer, attotime_zero, 0, ATTOTIME_IN_HZ( 256 ) );
1574   state->timers.hz256_timer = timer_alloc(machine,  pokemini_256hz_timer_callback , NULL );
1575   timer_adjust_periodic( state->timers.hz256_timer, attotime_zero, 0, ATTOTIME_IN_HZ( 256 ) );
15981576
1599   timers.timer1 = timer_alloc(machine,  pokemini_timer1_callback , NULL );
1600   timers.timer1_hi = timer_alloc(machine,  pokemini_timer1_hi_callback, NULL );
1601   timers.timer2 = timer_alloc(machine,  pokemini_timer2_callback , NULL );
1602   timers.timer2_hi = timer_alloc(machine,  pokemini_timer2_hi_callback, NULL );
1603   timers.timer3 = timer_alloc(machine,  pokemini_timer3_callback , NULL );
1604   timers.timer3_hi = timer_alloc(machine,  pokemini_timer3_hi_callback, NULL );
1577   state->timers.timer1 = timer_alloc(machine,  pokemini_timer1_callback , NULL );
1578   state->timers.timer1_hi = timer_alloc(machine,  pokemini_timer1_hi_callback, NULL );
1579   state->timers.timer2 = timer_alloc(machine,  pokemini_timer2_callback , NULL );
1580   state->timers.timer2_hi = timer_alloc(machine,  pokemini_timer2_hi_callback, NULL );
1581   state->timers.timer3 = timer_alloc(machine,  pokemini_timer3_callback , NULL );
1582   state->timers.timer3_hi = timer_alloc(machine,  pokemini_timer3_hi_callback, NULL );
16051583
16061584   /* Set up the PRC */
1607   prc.max_frame_count = 2;
1608   prc.count_timer = timer_alloc(machine,  pokemini_prc_counter_callback, NULL );
1609   timer_adjust_periodic( prc.count_timer, attotime_zero, 0, machine->device<cpu_device>("maincpu")->cycles_to_attotime(55640 / 65) );
1585   state->prc.max_frame_count = 2;
1586   state->prc.count_timer = timer_alloc(machine,  pokemini_prc_counter_callback, NULL );
1587   timer_adjust_periodic( state->prc.count_timer, attotime_zero, 0, machine->device<cpu_device>("maincpu")->cycles_to_attotime(55640 / 65) );
16101588}
16111589
src/mess/machine/rp5c15.c
r9669r9670
109109   int pulse1_state;
110110   int pulse16_state;
111111   void (*timer_fired_func)(int state);
112   void (*alarm_callback)(int state);
112   void (*alarm_callback)(running_machine *machine, int state);
113113   const rp5c15_intf* intf;
114114};  //  Ricoh RP5C15
115115
src/mess/machine/rp5c15.h
r9669r9670
1010typedef struct rp5c15_interface rp5c15_intf;
1111struct rp5c15_interface
1212{
13   void (*alarm_irq_callback)(int state);
13   void (*alarm_irq_callback)(running_machine *machine, int state);
1414};
1515
1616DECLARE_LEGACY_DEVICE(RP5C15, rp5c15);
src/mess/machine/pet.c
r9669r9670
2929      } \
3030   } while (0)
3131
32int pet_font;
33UINT8 *pet_memory;
34UINT8 *superpet_memory;
35static UINT8 *pet80_bank1_base;
36static int pet_keyline_select;
3732
38static emu_timer *datasette1_timer;
39static emu_timer *datasette2_timer;
4033
4134/* pia at 0xe810
4235   port a
r9669r9670
5447*/
5548static READ8_DEVICE_HANDLER( pia0_pa_r )
5649{
50   pet_state *state = device->machine->driver_data<pet_state>();
5751   /*
5852
5953        bit     description
r9669r9670
7367   UINT8 data = 0;
7468
7569   /* key */
76   data |= pet_keyline_select;
70   data |= state->keyline_select;
7771
7872   /* #1 cassette switch */
7973   data |= ((cassette_get_state(device->machine->device("cassette1")) & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED) << 4;
r9669r9670
9286
9387static WRITE8_DEVICE_HANDLER( pia0_pa_w )
9488{
89   pet_state *state = device->machine->driver_data<pet_state>();
9590   /*
9691
9792        bit     description
r9669r9670
108103    */
109104
110105   /* key */
111   pet_keyline_select = data & 0x0f;
106   state->keyline_select = data & 0x0f;
112107}
113108
114109/* Keyboard reading/handling for regular keyboard */
115110static READ8_DEVICE_HANDLER( kin_r )
116111{
112   pet_state *state = device->machine->driver_data<pet_state>();
117113   /*
118114
119115        bit     description
r9669r9670
135131      "ROW5", "ROW6", "ROW7", "ROW8", "ROW9"
136132   };
137133
138   if (pet_keyline_select < 10)
134   if (state->keyline_select < 10)
139135   {
140      data = input_port_read(device->machine, keynames[pet_keyline_select]);
136      data = input_port_read(device->machine, keynames[state->keyline_select]);
141137      /* Check for left-shift lock */
142      if ((pet_keyline_select == 8) && (input_port_read(device->machine, "SPECIAL") & 0x80))
138      if ((state->keyline_select == 8) && (input_port_read(device->machine, "SPECIAL") & 0x80))
143139         data &= 0xfe;
144140   }
145141   return data;
r9669r9670
155151      "ROW5", "ROW6", "ROW7", "ROW8", "ROW9"
156152   };
157153
158   if (pet_keyline_select < 10)
154   if (state->keyline_select < 10)
159155   {
160      data = input_port_read(device->machine, keynames[pet_keyline_select]);
156      data = input_port_read(device->machine, keynames[state->keyline_select]);
161157      /* Check for left-shift lock */
162158      /* 2008-05 FP: For some reason, superpet read it in the opposite way!! */
163159      /* While waiting for confirmation from docs, we add a workaround here. */
164160      if (state->superpet)
165161      {
166         if ((pet_keyline_select == 6) && !(input_port_read(device->machine, "SPECIAL") & 0x80))
162         if ((state->keyline_select == 6) && !(input_port_read(device->machine, "SPECIAL") & 0x80))
167163            data &= 0xfe;
168164      }
169165      else
170166      {
171         if ((pet_keyline_select == 6) && (input_port_read(device->machine, "SPECIAL") & 0x80))
167         if ((state->keyline_select == 6) && (input_port_read(device->machine, "SPECIAL") & 0x80))
172168            data &= 0xfe;
173169      }
174170   }
r9669r9670
190186
191187static WRITE8_DEVICE_HANDLER( cass1_motor_w )
192188{
189   pet_state *state = device->machine->driver_data<pet_state>();
193190   if (!data)
194191   {
195192      cassette_change_state(device->machine->device("cassette1"),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR);
196      timer_adjust_periodic(datasette1_timer, attotime_zero, 0, ATTOTIME_IN_HZ(48000));   // I put 48000 because I was given some .wav with this freq
193      timer_adjust_periodic(state->datasette1_timer, attotime_zero, 0, ATTOTIME_IN_HZ(48000));   // I put 48000 because I was given some .wav with this freq
197194   }
198195   else
199196   {
200197      cassette_change_state(device->machine->device("cassette1"),CASSETTE_MOTOR_DISABLED ,CASSETTE_MASK_MOTOR);
201      timer_reset(datasette1_timer, attotime_never);
198      timer_reset(state->datasette1_timer, attotime_never);
202199   }
203200}
204201
r9669r9670
374371
375372static WRITE8_DEVICE_HANDLER( via_pb_w )
376373{
374   pet_state *state = device->machine->driver_data<pet_state>();
377375   /*
378376
379377        bit     description
r9669r9670
405403   if (BIT(data, 4))
406404   {
407405      cassette_change_state(device->machine->device("cassette2"), CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR);
408      timer_adjust_periodic(datasette2_timer, attotime_zero, 0, ATTOTIME_IN_HZ(48000));   // I put 48000 because I was given some .wav with this freq
406      timer_adjust_periodic(state->datasette2_timer, attotime_zero, 0, ATTOTIME_IN_HZ(48000));   // I put 48000 because I was given some .wav with this freq
409407   }
410408   else
411409   {
412410      cassette_change_state(device->machine->device("cassette2"), CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR);
413      timer_reset(datasette2_timer, attotime_never);
411      timer_reset(state->datasette2_timer, attotime_never);
414412   }
415413}
416414
417415static WRITE_LINE_DEVICE_HANDLER( gb_w )
418416{
417   pet_state *drvstate = device->machine->driver_data<pet_state>();
419418   DBG_LOG(device->machine, 1, "address line", ("%d\n", state));
420   if (state) pet_font |= 1;
421   else pet_font &= ~1;
419   if (state) drvstate->font |= 1;
420   else drvstate->font &= ~1;
422421}
423422
424423static WRITE_LINE_DEVICE_HANDLER( via_irq_w )
r9669r9670
448447   DEVCB_LINE(via_irq_w)      /* out_irq_func */
449448};
450449
451static struct {
452   int bank; /* rambank to be switched in 0x9000 */
453   int rom; /* rom socket 6502? at 0x9000 */
454} spet= { 0 };
455450
456451static WRITE8_HANDLER( cbm8096_io_w )
457452{
r9669r9670
492487
493488static WRITE8_HANDLER( pet80_bank1_w )
494489{
495   pet80_bank1_base[offset] = data;
490   pet_state *state = space->machine->driver_data<pet_state>();
491   state->pet80_bank1_base[offset] = data;
496492}
497493
498494/*
r9669r9670
508504*/
509505WRITE8_HANDLER( cbm8096_w )
510506{
507   pet_state *state = space->machine->driver_data<pet_state>();
511508   if (data & 0x80)
512509   {
513510      if (data & 0x40)
r9669r9670
537534
538535      if (data & 0x20)
539536      {
540         pet80_bank1_base = pet_memory + 0x8000;
541         memory_set_bankptr(space->machine, "bank1", pet80_bank1_base);
537         state->pet80_bank1_base = state->memory + 0x8000;
538         memory_set_bankptr(space->machine, "bank1", state->pet80_bank1_base);
542539         memory_install_write8_handler(space, 0x8000, 0x8fff, 0, 0, pet80_bank1_w);
543540      }
544541      else
r9669r9670
563560      {
564561         if (!(data & 0x20))
565562         {
566            pet80_bank1_base = pet_memory + 0x14000;
567            memory_set_bankptr(space->machine, "bank1", pet80_bank1_base);
563            state->pet80_bank1_base = state->memory + 0x14000;
564            memory_set_bankptr(space->machine, "bank1", state->pet80_bank1_base);
568565         }
569         memory_set_bankptr(space->machine, "bank2", pet_memory + 0x15000);
570         memory_set_bankptr(space->machine, "bank3", pet_memory + 0x16000);
571         memory_set_bankptr(space->machine, "bank4", pet_memory + 0x17000);
566         memory_set_bankptr(space->machine, "bank2", state->memory + 0x15000);
567         memory_set_bankptr(space->machine, "bank3", state->memory + 0x16000);
568         memory_set_bankptr(space->machine, "bank4", state->memory + 0x17000);
572569      }
573570      else
574571      {
575572         if (!(data & 0x20))
576573         {
577            pet80_bank1_base = pet_memory + 0x10000;
578            memory_set_bankptr(space->machine, "bank1", pet80_bank1_base);
574            state->pet80_bank1_base = state->memory + 0x10000;
575            memory_set_bankptr(space->machine, "bank1", state->pet80_bank1_base);
579576         }
580         memory_set_bankptr(space->machine, "bank2", pet_memory + 0x11000);
581         memory_set_bankptr(space->machine, "bank3", pet_memory + 0x12000);
582         memory_set_bankptr(space->machine, "bank4", pet_memory + 0x13000);
577         memory_set_bankptr(space->machine, "bank2", state->memory + 0x11000);
578         memory_set_bankptr(space->machine, "bank3", state->memory + 0x12000);
579         memory_set_bankptr(space->machine, "bank4", state->memory + 0x13000);
583580      }
584581
585582      if (data & 8)
586583      {
587584         if (!(data & 0x40))
588585         {
589            memory_set_bankptr(space->machine, "bank7", pet_memory + 0x1e800);
586            memory_set_bankptr(space->machine, "bank7", state->memory + 0x1e800);
590587         }
591         memory_set_bankptr(space->machine, "bank6", pet_memory + 0x1c000);
592         memory_set_bankptr(space->machine, "bank8", pet_memory + 0x1f000);
593         memory_set_bankptr(space->machine, "bank9", pet_memory + 0x1fff1);
588         memory_set_bankptr(space->machine, "bank6", state->memory + 0x1c000);
589         memory_set_bankptr(space->machine, "bank8", state->memory + 0x1f000);
590         memory_set_bankptr(space->machine, "bank9", state->memory + 0x1fff1);
594591      }
595592      else
596593      {
597594         if (!(data & 0x40))
598595         {
599            memory_set_bankptr(space->machine, "bank7", pet_memory+ 0x1a800);
596            memory_set_bankptr(space->machine, "bank7", state->memory+ 0x1a800);
600597         }
601         memory_set_bankptr(space->machine, "bank6", pet_memory + 0x18000);
602         memory_set_bankptr(space->machine, "bank8", pet_memory + 0x1b000);
603         memory_set_bankptr(space->machine, "bank9", pet_memory + 0x1bff1);
598         memory_set_bankptr(space->machine, "bank6", state->memory + 0x18000);
599         memory_set_bankptr(space->machine, "bank8", state->memory + 0x1b000);
600         memory_set_bankptr(space->machine, "bank9", state->memory + 0x1bff1);
604601      }
605602   }
606603   else
607604   {
608      pet80_bank1_base = pet_memory + 0x8000;
609      memory_set_bankptr(space->machine, "bank1", pet80_bank1_base );
605      state->pet80_bank1_base = state->memory + 0x8000;
606      memory_set_bankptr(space->machine, "bank1", state->pet80_bank1_base );
610607      memory_install_write8_handler(space, 0x8000, 0x8fff, 0, 0, pet80_bank1_w);
611608
612      memory_set_bankptr(space->machine, "bank2", pet_memory + 0x9000);
609      memory_set_bankptr(space->machine, "bank2", state->memory + 0x9000);
613610      memory_unmap_write(space, 0x9000, 0x9fff, 0, 0);
614611
615      memory_set_bankptr(space->machine, "bank3", pet_memory + 0xa000);
612      memory_set_bankptr(space->machine, "bank3", state->memory + 0xa000);
616613      memory_unmap_write(space, 0xa000, 0xafff, 0, 0);
617614
618      memory_set_bankptr(space->machine, "bank4", pet_memory + 0xb000);
615      memory_set_bankptr(space->machine, "bank4", state->memory + 0xb000);
619616      memory_unmap_write(space, 0xb000, 0xbfff, 0, 0);
620617
621      memory_set_bankptr(space->machine, "bank6", pet_memory + 0xc000);
618      memory_set_bankptr(space->machine, "bank6", state->memory + 0xc000);
622619      memory_unmap_write(space, 0xc000, 0xe7ff, 0, 0);
623620
624621      memory_install_read8_handler(space, 0xe800, 0xefff, 0, 0, cbm8096_io_r);
625622      memory_install_write8_handler(space, 0xe800, 0xefff, 0, 0, cbm8096_io_w);
626623
627      memory_set_bankptr(space->machine, "bank8", pet_memory + 0xf000);
624      memory_set_bankptr(space->machine, "bank8", state->memory + 0xf000);
628625      memory_unmap_write(space, 0xf000, 0xffef, 0, 0);
629626
630      memory_set_bankptr(space->machine, "bank9", pet_memory + 0xfff1);
627      memory_set_bankptr(space->machine, "bank9", state->memory + 0xfff1);
631628      memory_unmap_write(space, 0xfff1, 0xffff, 0, 0);
632629   }
633630}
r9669r9670
639636
640637WRITE8_HANDLER( superpet_w )
641638{
639   pet_state *state = space->machine->driver_data<pet_state>();
642640   switch (offset)
643641   {
644642      case 0:
r9669r9670
652650
653651      case 4:
654652      case 5:
655         spet.bank = data & 0xf;
656         memory_configure_bank(space->machine, "bank1", 0, 16, superpet_memory, 0x1000);
657         memory_set_bank(space->machine, "bank1", spet.bank);
653         state->spet.bank = data & 0xf;
654         memory_configure_bank(space->machine, "bank1", 0, 16, state->supermemory, 0x1000);
655         memory_set_bank(space->machine, "bank1", state->spet.bank);
658656         /* 7 low writeprotects systemlatch */
659657         break;
660658
661659      case 6:
662660      case 7:
663         spet.rom = data & 1;
661         state->spet.rom = data & 1;
664662         break;
665663   }
666664}
667665
668666static TIMER_CALLBACK( pet_interrupt )
669667{
668   pet_state *state = machine->driver_data<pet_state>();
670669   running_device *pia_0 = machine->device("pia_0");
671   static int level = 0;
672670
673   pia6821_cb1_w(pia_0, level);
674   level = !level;
671   pia6821_cb1_w(pia_0, state->pia_level);
672   state->pia_level = !state->pia_level;
675673}
676674
677675
r9669r9670
697695   int i;
698696   pet_state *state = machine->driver_data<pet_state>();
699697
700   pet_font = 0;
698   state->font = 0;
701699
702700   state->pet_basic1 = 0;
703701   state->superpet = 0;
704702   state->cbm8096 = 0;
705703
706704   memory_install_readwrite_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0000, messram_get_size(machine->device("messram")) - 1, 0, 0, "bank10");
707   memory_set_bankptr(machine, "bank10", pet_memory);
705   memory_set_bankptr(machine, "bank10", state->memory);
708706
709707   if (messram_get_size(machine->device("messram")) < 0x8000)
710708   {
r9669r9670
714712   /* 2114 poweron ? 64 x 0xff, 64x 0, and so on */
715713   for (i = 0; i < messram_get_size(machine->device("messram")); i += 0x40)
716714   {
717      memset (pet_memory + i, i & 0x40 ? 0 : 0xff, 0x40);
715      memset (state->memory + i, i & 0x40 ? 0 : 0xff, 0x40);
718716   }
719717
720718   /* pet clock */
721719   timer_pulse(machine, ATTOTIME_IN_MSEC(10), NULL, 0, pet_interrupt);
722720
723721   /* datasette */
724   datasette1_timer = timer_alloc(machine, pet_tape1_timer, NULL);
725   datasette2_timer = timer_alloc(machine, pet_tape2_timer, NULL);
722   state->datasette1_timer = timer_alloc(machine, pet_tape1_timer, NULL);
723   state->datasette2_timer = timer_alloc(machine, pet_tape2_timer, NULL);
726724}
727725
728726
729727DRIVER_INIT( pet2001 )
730728{
731729   pet_state *state = machine->driver_data<pet_state>();
732   pet_memory = messram_get_ptr(machine->device("messram"));
730   state->memory = messram_get_ptr(machine->device("messram"));
733731   pet_common_driver_init(machine);
734732   state->pet_basic1 = 1;
735733   pet_vh_init(machine);
r9669r9670
737735
738736DRIVER_INIT( pet )
739737{
740   pet_memory = messram_get_ptr(machine->device("messram"));
738   pet_state *state = machine->driver_data<pet_state>();
739   state->memory = messram_get_ptr(machine->device("messram"));
741740   pet_common_driver_init(machine);
742741   pet_vh_init(machine);
743742}
r9669r9670
745744DRIVER_INIT( pet80 )
746745{
747746   pet_state *state = machine->driver_data<pet_state>();
748   pet_memory = memory_region(machine, "maincpu");
747   state->memory = memory_region(machine, "maincpu");
749748
750749   pet_common_driver_init(machine);
751750   state->cbm8096 = 1;
752   state->videoram = &pet_memory[0x8000];
751   state->videoram = &state->memory[0x8000];
753752   pet80_vh_init(machine);
754753
755754}
r9669r9670
757756DRIVER_INIT( superpet )
758757{
759758   pet_state *state = machine->driver_data<pet_state>();
760   pet_memory = messram_get_ptr(machine->device("messram"));
759   state->memory = messram_get_ptr(machine->device("messram"));
761760   pet_common_driver_init(machine);
762761   state->superpet = 1;
763762
764   superpet_memory = auto_alloc_array(machine, UINT8, 0x10000);
763   state->supermemory = auto_alloc_array(machine, UINT8, 0x10000);
765764
766   memory_configure_bank(machine, "bank1", 0, 16, superpet_memory, 0x1000);
765   memory_configure_bank(machine, "bank1", 0, 16, state->supermemory, 0x1000);
767766   memory_set_bank(machine, "bank1", 0);
768767
769768   superpet_vh_init(machine);
r9669r9670
777776
778777   if (state->superpet)
779778   {
780      spet.rom = 0;
779      state->spet.rom = 0;
781780      if (input_port_read(machine, "CFG") & 0x04)
782781      {
783782         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 1);
784783         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 0);
785         pet_font = 2;
784         state->font = 2;
786785      }
787786      else
788787      {
789788         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 0);
790789         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 1);
791         pet_font = 0;
790         state->font = 0;
792791      }
793792   }
794793
r9669r9670
824823      {
825824         cpu_set_input_line(device, INPUT_LINE_HALT, 1);
826825         cpu_set_input_line(device, INPUT_LINE_HALT, 0);
827         pet_font |= 2;
826         state->font |= 2;
828827      }
829828      else
830829      {
831830         cpu_set_input_line(device, INPUT_LINE_HALT, 0);
832831         cpu_set_input_line(device, INPUT_LINE_HALT, 1);
833         pet_font &= ~2;
832         state->font &= ~2;
834833      }
835834   }
836835
r9669r9670
846845
847846static DEVICE_IMAGE_LOAD(pet_cart)
848847{
848   pet_state *state = image.device().machine->driver_data<pet_state>();
849849   UINT32 size = image.length();
850850   const char *filetype = image.filetype();
851851   int address = 0;
r9669r9670
860860
861861   logerror("Loading cart %s at %.4x size:%.4x\n", image.filename(), address, size);
862862
863   image.fread(pet_memory + address, size);
863   image.fread(state->memory + address, size);
864864
865865   return IMAGE_INIT_PASS;
866866}
src/mess/machine/oric.c
r9669r9670
3030#include "devices/flopdrv.h"
3131
3232
33UINT8 *oric_ram;
3433
3534static const int enable_logging = 1;
36/* static int save_done = 0; */
3735
3836
3937/* ==0 if oric1 or oric atmos, !=0 if telestrat */
40static int oric_is_telestrat = 0;
4138
4239/* This does not exist in the real hardware. I have used it to
4340know which sources are interrupting */
4441/* bit 2 = telestrat 2nd via interrupt, 1 = microdisc interface,
45420 = oric 1st via interrupt */
46static unsigned char oric_irqs;
4743
4844enum
4945{
r9669r9670
6662/* called when ints are changed - cleared/set */
6763static void oric_refresh_ints(running_machine *machine)
6864{
65   oric_state *state = machine->driver_data<oric_state>();
6966   /* telestrat has floppy hardware built-in! */
70   if (oric_is_telestrat==0)
67   if (state->is_telestrat==0)
7168   {
7269      /* oric 1 or oric atmos */
7370
7471      /* if floppy disc hardware is disabled, do not allow interrupts from it */
7572      if ((input_port_read(machine, "FLOPPY") & 0x07) == ORIC_FLOPPY_INTERFACE_NONE)
7673      {
77         oric_irqs &=~(1<<1);
74         state->irqs &=~(1<<1);
7875      }
7976   }
8077
8178   /* any irq set? */
82   if ((oric_irqs & 0x0f)!=0)
79   if ((state->irqs & 0x0f)!=0)
8380   {
8481      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
8582   }
r9669r9670
8986   }
9087}
9188
92static char *oric_ram_0x0c000 = NULL;
9389
9490
9591/* index of keyboard line to scan */
96static int oric_keyboard_line;
9792/* sense result */
98static char oric_key_sense_bit;
9993/* mask to read keys */
100static char oric_keyboard_mask;
10194
10295
103static unsigned char oric_via_port_a_data;
10496
10597
10698
10799/* refresh keyboard sense */
108100static void oric_keyboard_sense_refresh(running_machine *machine)
109101{
102   oric_state *state = machine->driver_data<oric_state>();
110103   /* The following assumes that if a 0 is written, it can be used to detect if any key
111104    has been pressed.. */
112105   /* for each bit that is 0, it combines it's pressed state with the pressed state so far */
r9669r9670
118111   int input_port_data;
119112   static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7" };
120113
121   input_port_data = input_port_read(machine, keynames[oric_keyboard_line]);
114   input_port_data = input_port_read(machine, keynames[state->keyboard_line]);
122115
123116   /* go through all bits in line */
124117   for (i=0; i<8; i++)
125118   {
126119      /* sense this bit? */
127      if (((~oric_keyboard_mask) & (1<<i)) != 0)
120      if (((~state->keyboard_mask) & (1<<i)) != 0)
128121      {
129122         /* is key pressed? */
130123         if (input_port_data & (1<<i))
r9669r9670
136129   }
137130
138131   /* clear sense result */
139   oric_key_sense_bit = 0;
132   state->key_sense_bit = 0;
140133   /* any keys pressed on this line? */
141134   if (key_bit!=0)
142135   {
143136      /* set sense result */
144      oric_key_sense_bit = (1<<3);
137      state->key_sense_bit = (1<<3);
145138   }
146139}
147140
r9669r9670
149142/* this is executed when a write to psg port a is done */
150143WRITE8_HANDLER (oric_psg_porta_write)
151144{
152   oric_keyboard_mask = data;
145   oric_state *state = space->machine->driver_data<oric_state>();
146   state->keyboard_mask = data;
153147}
154148
155149
156150/* PSG control pins */
157151/* bit 1 = BDIR state */
158152/* bit 0 = BC1 state */
159static char oric_psg_control;
160153
161154/* this port is also used to read printer data */
162155static READ8_DEVICE_HANDLER ( oric_via_in_a_func )
163156{
157   oric_state *state = device->machine->driver_data<oric_state>();
164158   address_space *space = cputag_get_address_space( device->machine, "maincpu", ADDRESS_SPACE_PROGRAM );
165159
166160   /*logerror("port a read\r\n"); */
167161
168162   /* access psg? */
169   if (oric_psg_control!=0)
163   if (state->psg_control!=0)
170164   {
171165      /* if psg is in read register state return reg data */
172      if (oric_psg_control==0x01)
166      if (state->psg_control==0x01)
173167      {
174168         return ay8910_r(space->machine->device("ay8912"), 0);
175169      }
r9669r9670
179173   }
180174
181175   /* correct?? */
182   return oric_via_port_a_data;
176   return state->via_port_a_data;
183177}
184178
185179static READ8_DEVICE_HANDLER ( oric_via_in_b_func )
186180{
181   oric_state *state = device->machine->driver_data<oric_state>();
187182   int data;
188183
189184   oric_keyboard_sense_refresh(device->machine);
190185
191   data = oric_key_sense_bit;
192   data |= oric_keyboard_line & 0x07;
186   data = state->key_sense_bit;
187   data |= state->keyboard_line & 0x07;
193188
194189   return data;
195190}
r9669r9670
198193/* read/write data depending on state of bdir, bc1 pins and data output to psg */
199194static void oric_psg_connection_refresh(running_machine *machine)
200195{
201   if (oric_psg_control!=0)
196   oric_state *state = machine->driver_data<oric_state>();
197   if (state->psg_control!=0)
202198   {
203      switch (oric_psg_control)
199      switch (state->psg_control)
204200      {
205201         /* PSG inactive */
206202         case 0:
r9669r9670
208204         /* read register data */
209205         case 1:
210206         {
211            //oric_via_port_a_data = ay8910_read_port_0_r(space, 0);
207            //state->via_port_a_data = ay8910_read_port_0_r(space, 0);
212208         }
213209         break;
214210         /* write register data */
215211         case 2:
216212         {
217213            running_device *ay8912 = machine->device("ay8912");
218            ay8910_data_w(ay8912, 0, oric_via_port_a_data);
214            ay8910_data_w(ay8912, 0, state->via_port_a_data);
219215         }
220216         break;
221217         /* write register index */
222218         case 3:
223219         {
224220            running_device *ay8912 = machine->device("ay8912");
225            ay8910_address_w(ay8912, 0, oric_via_port_a_data);
221            ay8910_address_w(ay8912, 0, state->via_port_a_data);
226222         }
227223         break;
228224
r9669r9670
236232
237233static WRITE8_DEVICE_HANDLER ( oric_via_out_a_func )
238234{
239   oric_via_port_a_data = data;
235   oric_state *state = device->machine->driver_data<oric_state>();
236   state->via_port_a_data = data;
240237
241238   oric_psg_connection_refresh(device->machine);
242239
243240
244   if (oric_psg_control==0)
241   if (state->psg_control==0)
245242   {
246243      /* if psg not selected, write to printer */
247244      running_device *printer = device->machine->device("centronics");
r9669r9670
305302   via_0->write_cb1(data);
306303}
307304
308static unsigned char previous_portb_data = 0;
309305static WRITE8_DEVICE_HANDLER ( oric_via_out_b_func )
310306{
307   oric_state *state = device->machine->driver_data<oric_state>();
311308   running_device *printer = device->machine->device("centronics");
312309
313310   /* KEYBOARD */
314   oric_keyboard_line = data & 0x07;
311   state->keyboard_line = data & 0x07;
315312
316313   /* CASSETTE */
317314   /* cassette motor control */
318   if ((previous_portb_data^data) & (1<<6))
315   if ((state->previous_portb_data^data) & (1<<6))
319316   {
320317      if (data & (1<<6))
321318      {
r9669r9670
335332   centronics_strobe_w(printer, BIT(data, 4));
336333
337334   oric_psg_connection_refresh(device->machine);
338   previous_portb_data = data;
335   state->previous_portb_data = data;
339336}
340337
341338
342339static READ8_DEVICE_HANDLER ( oric_via_in_ca2_func )
343340{
344   return oric_psg_control & 1;
341   oric_state *state = device->machine->driver_data<oric_state>();
342   return state->psg_control & 1;
345343}
346344
347345static READ8_DEVICE_HANDLER ( oric_via_in_cb2_func )
348346{
349   return (oric_psg_control>>1) & 1;
347   oric_state *state = device->machine->driver_data<oric_state>();
348   return (state->psg_control>>1) & 1;
350349}
351350
352351static WRITE8_DEVICE_HANDLER ( oric_via_out_ca2_func )
353352{
354   oric_psg_control &=~1;
353   oric_state *state = device->machine->driver_data<oric_state>();
354   state->psg_control &=~1;
355355
356356   if (data)
357357   {
358      oric_psg_control |=1;
358      state->psg_control |=1;
359359   }
360360
361361   oric_psg_connection_refresh(device->machine);
r9669r9670
363363
364364static WRITE8_DEVICE_HANDLER ( oric_via_out_cb2_func )
365365{
366   oric_psg_control &=~2;
366   oric_state *state = device->machine->driver_data<oric_state>();
367   state->psg_control &=~2;
367368
368369   if (data)
369370   {
370      oric_psg_control |=2;
371      state->psg_control |=2;
371372   }
372373
373374   oric_psg_connection_refresh(device->machine);
r9669r9670
376377
377378static void oric_via_irq_func(running_device *device, int state)
378379{
379   oric_irqs &= ~(1<<0);
380   oric_state *drvstate = device->machine->driver_data<oric_state>();
381   drvstate->irqs &= ~(1<<0);
380382
381383   if (state)
382384   {
r9669r9670
385387         //logerror("oric via1 interrupt\r\n");
386388      }
387389
388      oric_irqs |=(1<<0);
390      drvstate->irqs |=(1<<0);
389391   }
390392
391393   oric_refresh_ints(device->machine);
r9669r9670
464466
465467static void oric_install_apple2_interface(running_machine *machine)
466468{
469   oric_state *state = machine->driver_data<oric_state>();
467470   running_device *fdc = machine->device("fdc");
468471   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
469472
470   if (oric_is_telestrat)
473   if (state->is_telestrat)
471474      return;
472475
473476   memory_install_read8_handler(space, 0x0300, 0x030f, 0, 0, oric_IO_r);
r9669r9670
482485
483486static void oric_enable_memory(running_machine *machine, int low, int high, int rd, int wr)
484487{
488   oric_state *state = machine->driver_data<oric_state>();
485489   int i;
486490   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
487491
488   if (oric_is_telestrat)
492   if (state->is_telestrat)
489493      return;
490494   for (i = low; i <= high; i++)
491495   {
r9669r9670
541545
542546static WRITE8_HANDLER(apple2_v2_interface_w)
543547{
548   oric_state *state = space->machine->driver_data<oric_state>();
544549   /* data is ignored, address is used to decode operation */
545   if (oric_is_telestrat)
550   if (state->is_telestrat)
546551      return;
547552
548553/*  logerror("apple 2 interface v2 rom page: %01x\n",(offset & 0x02)>>1); */
r9669r9670
564569      memory_set_bankptr(space->machine, "bank1", rom_ptr);
565570      memory_set_bankptr(space->machine, "bank2", rom_ptr+0x02000);
566571      memory_set_bankptr(space->machine, "bank3", rom_ptr+0x03800);
567      memory_set_bankptr(space->machine, "bank5", oric_ram_0x0c000);
568      memory_set_bankptr(space->machine, "bank6", oric_ram_0x0c000+0x02000);
569      memory_set_bankptr(space->machine, "bank7", oric_ram_0x0c000+0x03800);
572      memory_set_bankptr(space->machine, "bank5", state->ram_0x0c000);
573      memory_set_bankptr(space->machine, "bank6", state->ram_0x0c000+0x02000);
574      memory_set_bankptr(space->machine, "bank7", state->ram_0x0c000+0x03800);
570575   }
571576   else
572577   {
573578      /*logerror("apple 2 interface v2: ram enabled\n"); */
574579
575580      /* enable ram */
576      memory_set_bankptr(space->machine, "bank1", oric_ram_0x0c000);
577      memory_set_bankptr(space->machine, "bank2", oric_ram_0x0c000+0x02000);
578      memory_set_bankptr(space->machine, "bank3", oric_ram_0x0c000+0x03800);
579      memory_set_bankptr(space->machine, "bank5", oric_ram_0x0c000);
580      memory_set_bankptr(space->machine, "bank6", oric_ram_0x0c000+0x02000);
581      memory_set_bankptr(space->machine, "bank7", oric_ram_0x0c000+0x03800);
581      memory_set_bankptr(space->machine, "bank1", state->ram_0x0c000);
582      memory_set_bankptr(space->machine, "bank2", state->ram_0x0c000+0x02000);
583      memory_set_bankptr(space->machine, "bank3", state->ram_0x0c000+0x03800);
584      memory_set_bankptr(space->machine, "bank5", state->ram_0x0c000);
585      memory_set_bankptr(space->machine, "bank6", state->ram_0x0c000+0x02000);
586      memory_set_bankptr(space->machine, "bank7", state->ram_0x0c000+0x03800);
582587   }
583588}
584589
r9669r9670
605610
606611
607612/* bit 0: overlay ram access (1 means overlay ram enabled) */
608static unsigned char port_3fa_w;
609613
610614/* bit 0: ROMDIS (1 means internal Basic rom disabled) */
611static unsigned char port_3fb_w;
612615
613616
614617static void oric_jasmin_set_mem_0x0c000(running_machine *machine)
615618{
619   oric_state *state = machine->driver_data<oric_state>();
616620   /* assumption:
617621    1. It is possible to access all 16k overlay ram.
618622    2. If os is enabled, and overlay ram is enabled, all 16k can be accessed.
619623    3. if os is disabled, and overlay ram is enabled, jasmin rom takes priority.
620624    */
621   if (oric_is_telestrat)
625   if (state->is_telestrat)
622626      return;
623627
624628   /* the ram is disabled in the jasmin rom which indicates that jasmin takes
625629    priority over the ram */
626630
627631   /* basic rom disabled? */
628   if ((port_3fb_w & 0x01)==0)
632   if ((state->port_3fb_w & 0x01)==0)
629633   {
630634      /* no, it is enabled! */
631635
632636      /* overlay ram enabled? */
633      if ((port_3fa_w & 0x01)==0)
637      if ((state->port_3fa_w & 0x01)==0)
634638      {
635639         unsigned char *rom_ptr;
636640
r9669r9670
650654
651655         oric_enable_memory(machine, 1, 3, TRUE, TRUE);
652656
653         memory_set_bankptr(machine, "bank1", oric_ram_0x0c000);
654         memory_set_bankptr(machine, "bank2", oric_ram_0x0c000+0x02000);
655         memory_set_bankptr(machine, "bank3", oric_ram_0x0c000+0x03800);
656         memory_set_bankptr(machine, "bank5", oric_ram_0x0c000);
657         memory_set_bankptr(machine, "bank6", oric_ram_0x0c000+0x02000);
658         memory_set_bankptr(machine, "bank7", oric_ram_0x0c000+0x03800);
657         memory_set_bankptr(machine, "bank1", state->ram_0x0c000);
658         memory_set_bankptr(machine, "bank2", state->ram_0x0c000+0x02000);
659         memory_set_bankptr(machine, "bank3", state->ram_0x0c000+0x03800);
660         memory_set_bankptr(machine, "bank5", state->ram_0x0c000);
661         memory_set_bankptr(machine, "bank6", state->ram_0x0c000+0x02000);
662         memory_set_bankptr(machine, "bank7", state->ram_0x0c000+0x03800);
659663      }
660664   }
661665   else
662666   {
663667      /* yes, basic rom is disabled */
664668
665      if ((port_3fa_w & 0x01)==0)
669      if ((state->port_3fa_w & 0x01)==0)
666670      {
667671         /* overlay ram disabled */
668672
r9669r9670
674678         /*logerror("&c000-&f8ff is ram!\n"); */
675679         oric_enable_memory(machine, 1, 2, TRUE, TRUE);
676680
677         memory_set_bankptr(machine, "bank1", oric_ram_0x0c000);
678         memory_set_bankptr(machine, "bank2", oric_ram_0x0c000+0x02000);
679         memory_set_bankptr(machine, "bank5", oric_ram_0x0c000);
680         memory_set_bankptr(machine, "bank6", oric_ram_0x0c000+0x02000);
681         memory_set_bankptr(machine, "bank1", state->ram_0x0c000);
682         memory_set_bankptr(machine, "bank2", state->ram_0x0c000+0x02000);
683         memory_set_bankptr(machine, "bank5", state->ram_0x0c000);
684         memory_set_bankptr(machine, "bank6", state->ram_0x0c000+0x02000);
681685      }
682686
683687      {
r9669r9670
697701/* DRQ is connected to interrupt */
698702static WRITE_LINE_DEVICE_HANDLER( oric_jasmin_wd179x_drq_w )
699703{
704   oric_state *drvstate = device->machine->driver_data<oric_state>();
700705   if (state)
701      oric_irqs |= (1<<1);
706      drvstate->irqs |= (1<<1);
702707   else
703      oric_irqs &=~(1<<1);
708      drvstate->irqs &=~(1<<1);
704709
705710   oric_refresh_ints(device->machine);
706711}
r9669r9670
738743
739744static WRITE8_HANDLER(oric_jasmin_w)
740745{
746   oric_state *state = space->machine->driver_data<oric_state>();
741747   via6522_device *via_0 = space->machine->device<via6522_device>("via6522_0");;
742748   running_device *fdc = space->machine->device("wd179x");
743749   switch (offset & 0x0f)
r9669r9670
765771         break;
766772      case 0x0a:
767773         //logerror("jasmin overlay ram w: %02x PC: %04x\n", data, cpu_get_pc(space->machine->device("maincpu")));
768         port_3fa_w = data;
774         state->port_3fa_w = data;
769775         oric_jasmin_set_mem_0x0c000(space->machine);
770776         break;
771777      case 0x0b:
772778         //logerror("jasmin romdis w: %02x PC: %04x\n", data, cpu_get_pc(space->machine->device("maincpu")));
773         port_3fb_w = data;
779         state->port_3fb_w = data;
774780         oric_jasmin_set_mem_0x0c000(space->machine);
775781         break;
776782      /* bit 0,1 of addr is the drive */
r9669r9670
790796
791797static void oric_install_jasmin_interface(running_machine *machine)
792798{
799   oric_state *state = machine->driver_data<oric_state>();
793800   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
794801   /* romdis */
795   port_3fb_w = 1;
802   state->port_3fb_w = 1;
796803   oric_jasmin_set_mem_0x0c000(machine);
797804
798805   memory_install_read8_handler(space, 0x0300, 0x03ef, 0, 0, oric_IO_r);
r9669r9670
806813/* MICRODISC INTERFACE variables */
807814
808815/* used by Microdisc interfaces */
809static unsigned char oric_wd179x_int_state = 0;
810816
811817/* bit 7 is intrq state */
812static unsigned char port_314_r;
813818/* bit 7 is drq state (active low) */
814static unsigned char port_318_r;
815819/* bit 6,5: drive */
816820/* bit 4: side */
817821/* bit 3: double density enable */
818822/* bit 0: enable FDC IRQ to trigger IRQ on CPU */
819static unsigned char port_314_w;
820823
821824
822825static void oric_microdisc_refresh_wd179x_ints(running_machine *machine)
823826{
824   oric_irqs &=~(1<<1);
827   oric_state *state = machine->driver_data<oric_state>();
828   state->irqs &=~(1<<1);
825829
826   if ((oric_wd179x_int_state) && (port_314_w & (1<<0)))
830   if ((state->wd179x_int_state) && (state->port_314_w & (1<<0)))
827831   {
828832      /*logerror("oric microdisc interrupt\n"); */
829833
830      oric_irqs |=(1<<1);
834      state->irqs |=(1<<1);
831835   }
832836
833837   oric_refresh_ints(machine);
r9669r9670
835839
836840static WRITE_LINE_DEVICE_HANDLER( oric_microdisc_wd179x_intrq_w )
837841{
838   oric_wd179x_int_state = state;
842   oric_state *drvstate = device->machine->driver_data<oric_state>();
843   drvstate->wd179x_int_state = state;
839844
840845   if (state)
841      port_314_r &= ~(1<<7);
846      drvstate->port_314_r &= ~(1<<7);
842847   else
843      port_314_r |=(1<<7);
848      drvstate->port_314_r |=(1<<7);
844849
845850   oric_microdisc_refresh_wd179x_ints(device->machine);
846851}
847852
848853static WRITE_LINE_DEVICE_HANDLER( oric_microdisc_wd179x_drq_w )
849854{
855   oric_state *drvstate = device->machine->driver_data<oric_state>();
850856   if (state)
851      port_318_r &=~(1<<7);
857      drvstate->port_318_r &=~(1<<7);
852858   else
853      port_318_r |= (1<<7);
859      drvstate->port_318_r |= (1<<7);
854860}
855861
856862static void oric_microdisc_set_mem_0x0c000(running_machine *machine)
857863{
858   if (oric_is_telestrat)
864   oric_state *state = machine->driver_data<oric_state>();
865   if (state->is_telestrat)
859866      return;
860867
861868   /* for 0x0c000-0x0dfff: */
862869   /* if os disabled, ram takes priority */
863870   /* /ROMDIS */
864   if ((port_314_w & (1<<1))==0)
871   if ((state->port_314_w & (1<<1))==0)
865872   {
866873      /*logerror("&c000-&dfff is ram\n"); */
867874      /* rom disabled enable ram */
868875      oric_enable_memory(machine, 1, 1, TRUE, TRUE);
869      memory_set_bankptr(machine, "bank1", oric_ram_0x0c000);
870      memory_set_bankptr(machine, "bank5", oric_ram_0x0c000);
876      memory_set_bankptr(machine, "bank1", state->ram_0x0c000);
877      memory_set_bankptr(machine, "bank5", state->ram_0x0c000);
871878   }
872879   else
873880   {
r9669r9670
882889
883890   /* for 0x0e000-0x0ffff */
884891   /* if not disabled, os takes priority */
885   if ((port_314_w & (1<<1))!=0)
892   if ((state->port_314_w & (1<<1))!=0)
886893   {
887894      unsigned char *rom_ptr;
888895      /*logerror("&e000-&ffff is os rom\n"); */
r9669r9670
898905   else
899906   {
900907      /* if eprom is enabled, it takes priority over ram */
901      if ((port_314_w & (1<<7))==0)
908      if ((state->port_314_w & (1<<7))==0)
902909      {
903910         unsigned char *rom_ptr;
904911         /*logerror("&e000-&ffff is disk rom\n"); */
r9669r9670
913920         /*logerror("&e000-&ffff is ram\n"); */
914921         /* rom disabled enable ram */
915922         oric_enable_memory(machine, 2, 3, TRUE, TRUE);
916         memory_set_bankptr(machine, "bank2", oric_ram_0x0c000+0x02000);
917         memory_set_bankptr(machine, "bank3", oric_ram_0x0c000+0x03800);
918         memory_set_bankptr(machine, "bank6", oric_ram_0x0c000+0x02000);
919         memory_set_bankptr(machine, "bank7", oric_ram_0x0c000+0x03800);
923         memory_set_bankptr(machine, "bank2", state->ram_0x0c000+0x02000);
924         memory_set_bankptr(machine, "bank3", state->ram_0x0c000+0x03800);
925         memory_set_bankptr(machine, "bank6", state->ram_0x0c000+0x02000);
926         memory_set_bankptr(machine, "bank7", state->ram_0x0c000+0x03800);
920927      }
921928   }
922929}
r9669r9670
925932
926933READ8_HANDLER (oric_microdisc_r)
927934{
935   oric_state *state = space->machine->driver_data<oric_state>();
928936   unsigned char data = 0x0ff;
929937   running_device *fdc = space->machine->device("wd179x");
930938
r9669r9670
944952         data = wd17xx_data_r(fdc, 0);
945953         break;
946954      case 0x04:
947         data = port_314_r | 0x07f;
955         data = state->port_314_r | 0x07f;
948956/*          logerror("port_314_r: %02x\n",data); */
949957         break;
950958      case 0x08:
951         data = port_318_r | 0x07f;
959         data = state->port_318_r | 0x07f;
952960/*          logerror("port_318_r: %02x\n",data); */
953961         break;
954962
r9669r9670
966974
967975WRITE8_HANDLER(oric_microdisc_w)
968976{
977   oric_state *state = space->machine->driver_data<oric_state>();
969978   running_device *fdc = space->machine->device("wd179x");
970979   switch (offset & 0x0ff)
971980   {
r9669r9670
984993         break;
985994      case 0x04:
986995      {
987         port_314_w = data;
996         state->port_314_w = data;
988997
989998         //logerror("port_314_w: %02x\n",data);
990999
r9669r9670
10121021
10131022static void oric_install_microdisc_interface(running_machine *machine)
10141023{
1024   oric_state *state = machine->driver_data<oric_state>();
10151025   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
10161026
10171027   memory_install_read8_handler(space, 0x0300, 0x030f, 0, 0, oric_IO_r);
r9669r9670
10241034
10251035   /* disable os rom, enable microdisc rom */
10261036   /* 0x0c000-0x0dfff will be ram, 0x0e000-0x0ffff will be microdisc rom */
1027   port_314_w = 0x0ff^((1<<7) | (1<<1));
1037   state->port_314_w = 0x0ff^((1<<7) | (1<<1));
10281038
10291039   oric_microdisc_set_mem_0x0c000(machine);
10301040}
r9669r9670
10661076
10671077static void oric_common_init_machine(running_machine *machine)
10681078{
1079   oric_state *state = machine->driver_data<oric_state>();
10691080   /* clear all irqs */
1070   oric_irqs = 0;
1071   oric_ram_0x0c000 = NULL;
1081   state->irqs = 0;
1082   state->ram_0x0c000 = NULL;
10721083
10731084    timer_pulse(machine, ATTOTIME_IN_HZ(4800), NULL, 0, oric_refresh_tape);
10741085}
10751086
10761087MACHINE_START( oric )
10771088{
1089   oric_state *state = machine->driver_data<oric_state>();
10781090   oric_common_init_machine(machine);
10791091
1080   oric_is_telestrat = 0;
1092   state->is_telestrat = 0;
10811093
1082   oric_ram_0x0c000 = auto_alloc_array(machine, char, 16384);
1094   state->ram_0x0c000 = auto_alloc_array(machine, char, 16384);
10831095}
10841096
10851097
10861098MACHINE_RESET( oric )
10871099{
1100   oric_state *state = machine->driver_data<oric_state>();
10881101   int disc_interface_id = input_port_read(machine, "FLOPPY") & 0x07;
10891102   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
1090   if (oric_is_telestrat)
1103   if (state->is_telestrat)
10911104      return;
10921105
10931106   switch (disc_interface_id)
r9669r9670
12741287
12751288*/
12761289
1277static unsigned char telestrat_bank_selection;
1278static unsigned char telestrat_via2_port_a_data;
1279static unsigned char telestrat_via2_port_b_data;
12801290
1281enum
1282{
1283   TELESTRAT_MEM_BLOCK_UNDEFINED,
1284   TELESTRAT_MEM_BLOCK_RAM,
1285   TELESTRAT_MEM_BLOCK_ROM
1286};
1287
1288struct  telestrat_mem_block
1289{
1290   int      MemType;
1291   unsigned char *ptr;
1292};
1293
1294
1295static struct telestrat_mem_block   telestrat_blocks[8];
1296
12971291static void telestrat_refresh_mem(running_machine *machine)
12981292{
1293   oric_state *state = machine->driver_data<oric_state>();
12991294   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
13001295
1301   struct telestrat_mem_block *mem_block = &telestrat_blocks[telestrat_bank_selection];
1296   telestrat_mem_block *mem_block = &state->telestrat_blocks[state->telestrat_bank_selection];
13021297
13031298   switch (mem_block->MemType)
13041299   {
r9669r9670
13301325
13311326static READ8_DEVICE_HANDLER(telestrat_via2_in_a_func)
13321327{
1333   //logerror("via 2 - port a %02x\n",telestrat_via2_port_a_data);
1334   return telestrat_via2_port_a_data;
1328   oric_state *state = device->machine->driver_data<oric_state>();
1329   //logerror("via 2 - port a %02x\n",state->telestrat_via2_port_a_data);
1330   return state->telestrat_via2_port_a_data;
13351331}
13361332
13371333
13381334static WRITE8_DEVICE_HANDLER(telestrat_via2_out_a_func)
13391335{
1336   oric_state *state = device->machine->driver_data<oric_state>();
13401337   //logerror("via 2 - port a w: %02x\n",data);
13411338
1342   telestrat_via2_port_a_data = data;
1339   state->telestrat_via2_port_a_data = data;
13431340
1344   if (((data^telestrat_bank_selection) & 0x07)!=0)
1341   if (((data^state->telestrat_bank_selection) & 0x07)!=0)
13451342   {
1346      telestrat_bank_selection = data & 0x07;
1343      state->telestrat_bank_selection = data & 0x07;
13471344
13481345      telestrat_refresh_mem(device->machine);
13491346   }
r9669r9670
13511348
13521349static READ8_DEVICE_HANDLER(telestrat_via2_in_b_func)
13531350{
1351   oric_state *state = device->machine->driver_data<oric_state>();
13541352   unsigned char data = 0x01f;
13551353
13561354   /* left joystick selected? */
1357   if (telestrat_via2_port_b_data & (1<<6))
1355   if (state->telestrat_via2_port_b_data & (1<<6))
13581356   {
13591357      data &= input_port_read(device->machine, "JOY0");
13601358   }
13611359
13621360   /* right joystick selected? */
1363   if (telestrat_via2_port_b_data & (1<<7))
1361   if (state->telestrat_via2_port_b_data & (1<<7))
13641362   {
13651363      data &= input_port_read(device->machine, "JOY1");
13661364   }
13671365
1368   data |= telestrat_via2_port_b_data & ((1<<7) | (1<<6) | (1<<5));
1366   data |= state->telestrat_via2_port_b_data & ((1<<7) | (1<<6) | (1<<5));
13691367
13701368   return data;
13711369}
13721370
13731371static WRITE8_DEVICE_HANDLER(telestrat_via2_out_b_func)
13741372{
1375   telestrat_via2_port_b_data = data;
1373   oric_state *state = device->machine->driver_data<oric_state>();
1374   state->telestrat_via2_port_b_data = data;
13761375}
13771376
13781377
13791378static void telestrat_via2_irq_func(running_device *device, int state)
13801379{
1381    oric_irqs &=~(1<<2);
1380   oric_state *drvstate = device->machine->driver_data<oric_state>();
1381    drvstate->irqs &=~(1<<2);
13821382
13831383   if (state)
13841384   {
13851385        //logerror("telestrat via2 interrupt\n");
13861386
1387        oric_irqs |=(1<<2);
1387        drvstate->irqs |=(1<<2);
13881388   }
13891389
13901390    oric_refresh_ints(device->machine);
r9669r9670
14101410/* interrupt state from acia6551 */
14111411static void telestrat_acia_callback(running_machine *machine, int irq_state)
14121412{
1413   oric_irqs&=~(1<<3);
1413   oric_state *state = machine->driver_data<oric_state>();
1414   state->irqs&=~(1<<3);
14141415
14151416   if (irq_state)
14161417   {
1417      oric_irqs |= (1<<3);
1418      state->irqs |= (1<<3);
14181419   }
14191420
14201421   oric_refresh_ints(machine);
r9669r9670
14231424
14241425MACHINE_START( telestrat )
14251426{
1427   oric_state *state = machine->driver_data<oric_state>();
14261428   oric_common_init_machine(machine);
14271429
1428   oric_is_telestrat = 1;
1430   state->is_telestrat = 1;
14291431
14301432   /* initialise overlay ram */
1431   telestrat_blocks[0].MemType = TELESTRAT_MEM_BLOCK_RAM;
1432   telestrat_blocks[0].ptr = auto_alloc_array(machine, UINT8, 16384);
1433   state->telestrat_blocks[0].MemType = TELESTRAT_MEM_BLOCK_RAM;
1434   state->telestrat_blocks[0].ptr = auto_alloc_array(machine, UINT8, 16384);
14331435
1434   telestrat_blocks[1].MemType = TELESTRAT_MEM_BLOCK_RAM;
1435   telestrat_blocks[1].ptr = auto_alloc_array(machine, UINT8, 16384);
1436   telestrat_blocks[2].MemType = TELESTRAT_MEM_BLOCK_RAM;
1437   telestrat_blocks[2].ptr = auto_alloc_array(machine, UINT8, 16384);
1436   state->telestrat_blocks[1].MemType = TELESTRAT_MEM_BLOCK_RAM;
1437   state->telestrat_blocks[1].ptr = auto_alloc_array(machine, UINT8, 16384);
1438   state->telestrat_blocks[2].MemType = TELESTRAT_MEM_BLOCK_RAM;
1439   state->telestrat_blocks[2].ptr = auto_alloc_array(machine, UINT8, 16384);
14381440
14391441   /* initialise default cartridge */
1440   telestrat_blocks[3].MemType = TELESTRAT_MEM_BLOCK_ROM;
1441   telestrat_blocks[3].ptr = memory_region(machine, "maincpu")+0x010000;
1442   state->telestrat_blocks[3].MemType = TELESTRAT_MEM_BLOCK_ROM;
1443   state->telestrat_blocks[3].ptr = memory_region(machine, "maincpu")+0x010000;
14421444
1443   telestrat_blocks[4].MemType = TELESTRAT_MEM_BLOCK_RAM;
1444   telestrat_blocks[4].ptr = auto_alloc_array(machine, UINT8, 16384);
1445   state->telestrat_blocks[4].MemType = TELESTRAT_MEM_BLOCK_RAM;
1446   state->telestrat_blocks[4].ptr = auto_alloc_array(machine, UINT8, 16384);
14451447
14461448   /* initialise default cartridge */
1447   telestrat_blocks[5].MemType = TELESTRAT_MEM_BLOCK_ROM;
1448   telestrat_blocks[5].ptr = memory_region(machine, "maincpu")+0x014000;
1449   state->telestrat_blocks[5].MemType = TELESTRAT_MEM_BLOCK_ROM;
1450   state->telestrat_blocks[5].ptr = memory_region(machine, "maincpu")+0x014000;
14491451
14501452   /* initialise default cartridge */
1451   telestrat_blocks[6].MemType = TELESTRAT_MEM_BLOCK_ROM;
1452   telestrat_blocks[6].ptr = memory_region(machine, "maincpu")+0x018000;
1453   state->telestrat_blocks[6].MemType = TELESTRAT_MEM_BLOCK_ROM;
1454   state->telestrat_blocks[6].ptr = memory_region(machine, "maincpu")+0x018000;
14531455
14541456   /* initialise default cartridge */
1455   telestrat_blocks[7].MemType = TELESTRAT_MEM_BLOCK_ROM;
1456   telestrat_blocks[7].ptr = memory_region(machine, "maincpu")+0x01c000;
1457   state->telestrat_blocks[7].MemType = TELESTRAT_MEM_BLOCK_ROM;
1458   state->telestrat_blocks[7].ptr = memory_region(machine, "maincpu")+0x01c000;
14571459
1458   telestrat_bank_selection = 7;
1460   state->telestrat_bank_selection = 7;
14591461   telestrat_refresh_mem(machine);
14601462
14611463   /* disable os rom, enable microdisc rom */
14621464   /* 0x0c000-0x0dfff will be ram, 0x0e000-0x0ffff will be microdisc rom */
1463    port_314_w = 0x0ff^((1<<7) | (1<<1));
1465    state->port_314_w = 0x0ff^((1<<7) | (1<<1));
14641466}
src/mess/machine/nascom1.c
r9669r9670
3030 *
3131 *************************************/
3232
33static running_device *nascom1_hd6402;
34static int nascom1_tape_size = 0;
35static UINT8 *nascom1_tape_image = NULL;
36static int nascom1_tape_index = 0;
3733
38static struct
39{
40   UINT8   stat_flags;
41   UINT8   stat_count;
42} nascom1_portstat;
4334
44static struct
45{
46   UINT8 select;
47   UINT8 irq;
48   UINT8 drq;
49} nascom2_fdc;
5035
51
52
5336/*************************************
5437 *
5538 *  Floppy
r9669r9670
5841
5942static WRITE_LINE_DEVICE_HANDLER( nascom2_fdc_intrq_w )
6043{
61   nascom2_fdc.irq = state;
44   nascom1_state *drvstate = device->machine->driver_data<nascom1_state>();
45   drvstate->nascom2_fdc.irq = state;
6246}
6347
6448static WRITE_LINE_DEVICE_HANDLER( nascom2_fdc_drq_w )
6549{
66   nascom2_fdc.drq = state;
50   nascom1_state *drvstate = device->machine->driver_data<nascom1_state>();
51   drvstate->nascom2_fdc.drq = state;
6752}
6853
6954const wd17xx_interface nascom2_wd17xx_interface =
r9669r9670
7762
7863READ8_HANDLER( nascom2_fdc_select_r )
7964{
80   return nascom2_fdc.select | 0xa0;
65   nascom1_state *state = space->machine->driver_data<nascom1_state>();
66   return state->nascom2_fdc.select | 0xa0;
8167}
8268
8369
8470WRITE8_HANDLER( nascom2_fdc_select_w )
8571{
72   nascom1_state *state = space->machine->driver_data<nascom1_state>();
8673   running_device *fdc = space->machine->device("wd1793");
87   nascom2_fdc.select = data;
74   state->nascom2_fdc.select = data;
8875
8976   logerror("nascom2_fdc_select_w: %02x\n", data);
9077
r9669r9670
10592 */
10693READ8_HANDLER( nascom2_fdc_status_r )
10794{
108   return (nascom2_fdc.drq << 7) | nascom2_fdc.irq;
95   nascom1_state *state = space->machine->driver_data<nascom1_state>();
96   return (state->nascom2_fdc.drq << 7) | state->nascom2_fdc.irq;
10997}
11098
11199/*************************************
r9669r9670
116104
117105READ8_HANDLER ( nascom1_port_00_r )
118106{
107   nascom1_state *state = space->machine->driver_data<nascom1_state>();
119108   static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5", "KEY6", "KEY7", "KEY8" };
120109
121   if (nascom1_portstat.stat_count < 9)
122      return (input_port_read(space->machine, keynames[nascom1_portstat.stat_count]) | ~0x7f);
110   if (state->portstat.stat_count < 9)
111      return (input_port_read(space->machine, keynames[state->portstat.stat_count]) | ~0x7f);
123112
124113   return (0xff);
125114}
r9669r9670
127116
128117WRITE8_HANDLER( nascom1_port_00_w )
129118{
119   nascom1_state *state = space->machine->driver_data<nascom1_state>();
130120
131121   cassette_change_state( space->machine->device("cassette"),
132122      ( data & 0x10 ) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR );
133123
134124   if (!(data & NASCOM1_KEY_RESET))
135125   {
136      if (nascom1_portstat.stat_flags & NASCOM1_KEY_RESET)
137         nascom1_portstat.stat_count = 0;
126      if (state->portstat.stat_flags & NASCOM1_KEY_RESET)
127         state->portstat.stat_count = 0;
138128   }
139129   else
140      nascom1_portstat.stat_flags = NASCOM1_KEY_RESET;
130      state->portstat.stat_flags = NASCOM1_KEY_RESET;
141131
142132   if (!(data & NASCOM1_KEY_INCR))
143133   {
144      if (nascom1_portstat.stat_flags & NASCOM1_KEY_INCR)
145         nascom1_portstat.stat_count++;
134      if (state->portstat.stat_flags & NASCOM1_KEY_INCR)
135         state->portstat.stat_count++;
146136   }
147137   else
148      nascom1_portstat.stat_flags = NASCOM1_KEY_INCR;
138      state->portstat.stat_flags = NASCOM1_KEY_INCR;
149139}
150140
151141
r9669r9670
160150
161151READ8_HANDLER( nascom1_port_01_r )
162152{
163   return ay31015_get_received_data( nascom1_hd6402 );
153   nascom1_state *state = space->machine->driver_data<nascom1_state>();
154   return ay31015_get_received_data( state->hd6402 );
164155}
165156
166157
167158WRITE8_HANDLER( nascom1_port_01_w )
168159{
169   ay31015_set_transmit_data( nascom1_hd6402, data );
160   nascom1_state *state = space->machine->driver_data<nascom1_state>();
161   ay31015_set_transmit_data( state->hd6402, data );
170162}
171163
172164READ8_HANDLER( nascom1_port_02_r )
173165{
166   nascom1_state *state = space->machine->driver_data<nascom1_state>();
174167   UINT8 data = 0x31;
175168
176   ay31015_set_input_pin( nascom1_hd6402, AY31015_SWE, 0 );
177   data |= ay31015_get_output_pin( nascom1_hd6402, AY31015_OR ) ? 0x02 : 0;
178   data |= ay31015_get_output_pin( nascom1_hd6402, AY31015_PE ) ? 0x04 : 0;
179   data |= ay31015_get_output_pin( nascom1_hd6402, AY31015_FE ) ? 0x08 : 0;
180   data |= ay31015_get_output_pin( nascom1_hd6402, AY31015_TBMT ) ? 0x40 : 0;
181   data |= ay31015_get_output_pin( nascom1_hd6402, AY31015_DAV ) ? 0x80 : 0;
182   ay31015_set_input_pin( nascom1_hd6402, AY31015_SWE, 1 );
169   ay31015_set_input_pin( state->hd6402, AY31015_SWE, 0 );
170   data |= ay31015_get_output_pin( state->hd6402, AY31015_OR ) ? 0x02 : 0;
171   data |= ay31015_get_output_pin( state->hd6402, AY31015_PE ) ? 0x04 : 0;
172   data |= ay31015_get_output_pin( state->hd6402, AY31015_FE ) ? 0x08 : 0;
173   data |= ay31015_get_output_pin( state->hd6402, AY31015_TBMT ) ? 0x40 : 0;
174   data |= ay31015_get_output_pin( state->hd6402, AY31015_DAV ) ? 0x80 : 0;
175   ay31015_set_input_pin( state->hd6402, AY31015_SWE, 1 );
183176
184177   return data;
185178}
r9669r9670
198191
199192DEVICE_IMAGE_LOAD( nascom1_cassette )
200193{
201   nascom1_tape_size = image.length();
202   nascom1_tape_image = (UINT8*)image.ptr();
203   if (!nascom1_tape_image)
194   nascom1_state *state = image.device().machine->driver_data<nascom1_state>();
195   state->tape_size = image.length();
196   state->tape_image = (UINT8*)image.ptr();
197   if (!state->tape_image)
204198      return IMAGE_INIT_FAIL;
205199
206   nascom1_tape_index = 0;
200   state->tape_index = 0;
207201   return IMAGE_INIT_PASS;
208202}
209203
210204
211205DEVICE_IMAGE_UNLOAD( nascom1_cassette )
212206{
213   nascom1_tape_image = NULL;
214   nascom1_tape_size = nascom1_tape_index = 0;
207   nascom1_state *state = image.device().machine->driver_data<nascom1_state>();
208   state->tape_image = NULL;
209   state->tape_size = state->tape_index = 0;
215210}
216211
217212
r9669r9670
259254
260255MACHINE_RESET( nascom1 )
261256{
262   nascom1_hd6402 = machine->device("hd6402");
257   nascom1_state *state = machine->driver_data<nascom1_state>();
258   state->hd6402 = machine->device("hd6402");
263259
264260   /* Set up hd6402 pins */
265   ay31015_set_input_pin( nascom1_hd6402, AY31015_SWE, 1 );
261   ay31015_set_input_pin( state->hd6402, AY31015_SWE, 1 );
266262
267   ay31015_set_input_pin( nascom1_hd6402, AY31015_CS, 0 );
268   ay31015_set_input_pin( nascom1_hd6402, AY31015_NP, 1 );
269   ay31015_set_input_pin( nascom1_hd6402, AY31015_NB1, 1 );
270   ay31015_set_input_pin( nascom1_hd6402, AY31015_NB2, 1 );
271   ay31015_set_input_pin( nascom1_hd6402, AY31015_EPS, 1 );
272   ay31015_set_input_pin( nascom1_hd6402, AY31015_TSB, 1 );
273   ay31015_set_input_pin( nascom1_hd6402, AY31015_CS, 1 );
263   ay31015_set_input_pin( state->hd6402, AY31015_CS, 0 );
264   ay31015_set_input_pin( state->hd6402, AY31015_NP, 1 );
265   ay31015_set_input_pin( state->hd6402, AY31015_NB1, 1 );
266   ay31015_set_input_pin( state->hd6402, AY31015_NB2, 1 );
267   ay31015_set_input_pin( state->hd6402, AY31015_EPS, 1 );
268   ay31015_set_input_pin( state->hd6402, AY31015_TSB, 1 );
269   ay31015_set_input_pin( state->hd6402, AY31015_CS, 1 );
274270}
275271
276272DRIVER_INIT( nascom1 )
src/mess/machine/vtech2.c
r9669r9670
2020#include "sound/speaker.h"
2121
2222/* public */
23int laser_latch;
2423
2524/* static */
26static UINT8 *mem;
27static int laser_bank_mask;   /* up to 16 4K banks supported */
28static int laser_bank[4];
29static int laser_video_bank;
3025
3126#define TRKSIZE_VZ   0x9a0   /* arbitrary (actually from analyzing format) */
32#define TRKSIZE_FM   3172   /* size of a standard FM mode track */
3327
34static UINT8 laser_track_x2[2];
3528static const UINT8 laser_fdc_wrprot[2] = {0x80, 0x80};
36static UINT8 laser_fdc_status = 0;
37static UINT8 laser_fdc_data[TRKSIZE_FM];
38static int laser_data;
39static int laser_fdc_edge = 0;
40static int laser_fdc_bits;
41static int laser_drive;
42static int laser_fdc_start = 0;
43static int laser_fdc_write = 0;
44static int laser_fdc_offs = 0;
45static int laser_fdc_latch = 0;
4629
4730/* write to banked memory (handle memory mapped i/o and videoram) */
4831static void mwa_bank(running_machine *machine, int bank, int offs, int data);
r9669r9670
10083
10184DRIVER_INIT(laser)
10285{
86   vtech2_state *state = machine->driver_data<vtech2_state>();
10387   UINT8 *gfx = memory_region(machine, "gfx2");
10488   int i;
10589
106   laser_track_x2[0] = laser_track_x2[1] = 80;
107   laser_fdc_bits = 8;
108   laser_drive = -1;
90   state->laser_track_x2[0] = state->laser_track_x2[1] = 80;
91   state->laser_fdc_bits = 8;
92   state->laser_drive = -1;
10993
11094   for (i = 0; i < 256; i++)
11195      gfx[i] = i;
11296
113   laser_latch = -1;
114   mem = memory_region(machine, "maincpu");
97   state->laser_latch = -1;
98   state->mem = memory_region(machine, "maincpu");
11599
116   for (i = 0; i < ARRAY_LENGTH(laser_bank); i++)
117      laser_bank[i] = -1;
100   for (i = 0; i < ARRAY_LENGTH(state->laser_bank); i++)
101      state->laser_bank[i] = -1;
118102}
119103
120104
r9669r9670
124108   vtech2_state *state = machine->driver_data<vtech2_state>();
125109    int i;
126110
127   laser_bank_mask = bank_mask;
128    laser_video_bank = video_mask;
129   state->videoram = mem + laser_video_bank * 0x04000;
130   logerror("laser_machine_init(): bank mask $%04X, video %d [$%05X]\n", laser_bank_mask, laser_video_bank, laser_video_bank * 0x04000);
111   state->laser_bank_mask = bank_mask;
112    state->laser_video_bank = video_mask;
113   state->videoram = state->mem + state->laser_video_bank * 0x04000;
114   logerror("laser_machine_init(): bank mask $%04X, video %d [$%05X]\n", state->laser_bank_mask, state->laser_video_bank, state->laser_video_bank * 0x04000);
131115
132   for (i = 0; i < ARRAY_LENGTH(laser_bank); i++)
116   for (i = 0; i < ARRAY_LENGTH(state->laser_bank); i++)
133117      laser_bank_select_w(cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), i, 0);
134118}
135119
r9669r9670
154138
155139WRITE8_HANDLER( laser_bank_select_w )
156140{
141   vtech2_state *state = space->machine->driver_data<vtech2_state>();
157142    static const char *const bank_name[16] = {
158143        "ROM lo","ROM hi","MM I/O","Video RAM lo",
159144        "RAM #0","RAM #1","RAM #2","RAM #3",
r9669r9670
164149   offset %= 4;
165150    data &= 15;
166151
167   if( data != laser_bank[offset] )
152   if( data != state->laser_bank[offset] )
168153    {
169        laser_bank[offset] = data;
154        state->laser_bank[offset] = data;
170155      logerror("select bank #%d $%02X [$%05X] %s\n", offset+1, data, 0x4000 * (data & 15), bank_name[data]);
171156
172157        /* memory mapped I/O bank selected? */
r9669r9670
178163      else
179164      {
180165         sprintf(bank,"bank%d",offset+1);
181         memory_set_bankptr(space->machine, bank, &mem[0x4000*laser_bank[offset]]);
182         if( laser_bank_mask & (1 << data) )
166         memory_set_bankptr(space->machine, bank, &state->mem[0x4000*state->laser_bank[offset]]);
167         if( state->laser_bank_mask & (1 << data) )
183168         {
184169            /* video RAM bank selected? */
185            if( data == laser_video_bank )
170            if( data == state->laser_video_bank )
186171            {
187172               logerror("select bank #%d VIDEO!\n", offset+1);
188173            }
r9669r9670
219204 ************************************************/
220205static int mra_bank(running_machine *machine, int bank, int offs)
221206{
222   static int level_old = 0, cassette_bit = 0;
207   vtech2_state *state = machine->driver_data<vtech2_state>();
223208    int level, data = 0xff;
224209
225210    /* Laser 500/700 only: keyboard rows A through D */
226211   if( (offs & 0x00ff) == 0x00ff )
227212   {
228      static int row_a,row_b,row_c,row_d;
229213      if( (offs & 0x0300) == 0x0000 ) /* keyboard row A */
230214      {
231         if( input_port_read(machine, "ROWA") != row_a )
215         if( input_port_read(machine, "ROWA") != state->row_a )
232216         {
233            row_a = input_port_read(machine, "ROWA");
234            data &= row_a;
217            state->row_a = input_port_read(machine, "ROWA");
218            data &= state->row_a;
235219         }
236220      }
237221      if( (offs & 0x0300) == 0x0100 ) /* keyboard row B */
238222      {
239         if( input_port_read(machine, "ROWB") != row_b )
223         if( input_port_read(machine, "ROWB") != state->row_b )
240224         {
241            row_b = input_port_read(machine, "ROWB");
242            data &= row_b;
225            state->row_b = input_port_read(machine, "ROWB");
226            data &= state->row_b;
243227         }
244228      }
245229      if( (offs & 0x0300) == 0x0200 ) /* keyboard row C */
246230      {
247         if( input_port_read(machine, "ROWC") != row_c )
231         if( input_port_read(machine, "ROWC") != state->row_c )
248232         {
249            row_c = input_port_read(machine, "ROWC");
250            data &= row_c;
233            state->row_c = input_port_read(machine, "ROWC");
234            data &= state->row_c;
251235         }
252236      }
253237      if( (offs & 0x0300) == 0x0300 ) /* keyboard row D */
254238      {
255         if( input_port_read(machine, "ROWD") != row_d )
239         if( input_port_read(machine, "ROWD") != state->row_d )
256240         {
257            row_d = input_port_read(machine, "ROWD");
258            data &= row_d;
241            state->row_d = input_port_read(machine, "ROWD");
242            data &= state->row_d;
259243         }
260244      }
261245   }
r9669r9670
282266
283267    /* what's bit 7 good for? tape input maybe? */
284268   level = cassette_input(vtech2_cassette_image(machine)) * 65536.0;
285   if( level < level_old - 511 )
286      cassette_bit = 0x00;
287   if( level > level_old + 511 )
288      cassette_bit = 0x80;
289   level_old = level;
269   if( level < state->level_old - 511 )
270      state->cassette_bit = 0x00;
271   if( level > state->level_old + 511 )
272      state->cassette_bit = 0x80;
273   state->level_old = level;
290274
291   data &= ~cassette_bit;
275   data &= ~state->cassette_bit;
292276    // logerror("bank #%d keyboard_r [$%04X] $%02X\n", bank, offs, data);
293277
294278    return data;
r9669r9670
307291 ************************************************/
308292static void mwa_bank(running_machine *machine, int bank, int offs, int data)
309293{
294   vtech2_state *state = machine->driver_data<vtech2_state>();
310295   running_device *speaker = machine->device("speaker");
311   offs += 0x4000 * laser_bank[bank];
312    switch (laser_bank[bank])
296   offs += 0x4000 * state->laser_bank[bank];
297    switch (state->laser_bank[bank])
313298    {
314299    case  0:    /* ROM lower 16K */
315300    case  1:    /* ROM upper 16K */
316301      logerror("bank #%d write to ROM [$%05X] $%02X\n", bank+1, offs, data);
317302        break;
318303    case  2:    /* memory mapped output */
319        if (data != laser_latch)
304        if (data != state->laser_latch)
320305        {
321306            logerror("bank #%d write to I/O [$%05X] $%02X\n", bank+1, offs, data);
322307            /* Toggle between graphics and text modes? */
323         if ((data ^ laser_latch) & 0x01)
308         if ((data ^ state->laser_latch) & 0x01)
324309            speaker_level_w(speaker, data & 1);
325            laser_latch = data;
310            state->laser_latch = data;
326311        }
327312        break;
328313    case 12:    /* ext. ROM #1 */
r9669r9670
332317      logerror("bank #%d write to ROM [$%05X] $%02X\n", bank+1, offs, data);
333318        break;
334319    default:    /* RAM */
335        if( laser_bank[bank] == laser_video_bank && mem[offs] != data )
320        if( state->laser_bank[bank] == state->laser_video_bank && state->mem[offs] != data )
336321      {
337322         logerror("bank #%d write to videoram [$%05X] $%02X\n", bank+1, offs, data);
338323      }
339        mem[offs] = data;
324        state->mem[offs] = data;
340325        break;
341326    }
342327}
343328
344329DEVICE_IMAGE_LOAD( laser_cart )
345330{
331   vtech2_state *state = image.device().machine->driver_data<vtech2_state>();
346332   int size = 0;
347333
348   size = image.fread(&mem[0x30000], 0x10000);
349   laser_bank_mask &= ~0xf000;
334   size = image.fread(&state->mem[0x30000], 0x10000);
335   state->laser_bank_mask &= ~0xf000;
350336   if( size > 0 )
351      laser_bank_mask |= 0x1000;
337      state->laser_bank_mask |= 0x1000;
352338   if( size > 0x4000 )
353      laser_bank_mask |= 0x2000;
339      state->laser_bank_mask |= 0x2000;
354340   if( size > 0x8000 )
355      laser_bank_mask |= 0x4000;
341      state->laser_bank_mask |= 0x4000;
356342   if( size > 0xc000 )
357      laser_bank_mask |= 0x8000;
343      state->laser_bank_mask |= 0x8000;
358344
359345   return size > 0 ? IMAGE_INIT_PASS : IMAGE_INIT_FAIL;
360346}
361347
362348DEVICE_IMAGE_UNLOAD( laser_cart )
363349{
364   laser_bank_mask &= ~0xf000;
350   vtech2_state *state = image.device().machine->driver_data<vtech2_state>();
351   state->laser_bank_mask &= ~0xf000;
365352   /* wipe out the memory contents to be 100% sure */
366   memset(&mem[0x30000], 0xff, 0x10000);
353   memset(&state->mem[0x30000], 0xff, 0x10000);
367354}
368355
369356static running_device *laser_file(running_machine *machine)
370357{
371   return machine->device( laser_drive ? FLOPPY_1 : FLOPPY_0 );
358   vtech2_state *state = machine->driver_data<vtech2_state>();
359   return machine->device( state->laser_drive ? FLOPPY_1 : FLOPPY_0 );
372360}
373361
374362static void laser_get_track(running_machine *machine)
375363{
376    sprintf(laser_frame_message, "#%d get track %02d", laser_drive, laser_track_x2[laser_drive]/2);
377    laser_frame_time = 30;
364   vtech2_state *state = machine->driver_data<vtech2_state>();
365    sprintf(state->laser_frame_message, "#%d get track %02d", state->laser_drive, state->laser_track_x2[state->laser_drive]/2);
366    state->laser_frame_time = 30;
378367    /* drive selected or and image file ok? */
379    if( laser_drive >= 0 && laser_file(machine) != NULL )
368    if( state->laser_drive >= 0 && laser_file(machine) != NULL )
380369    {
381370        int size, offs;
382371      device_image_interface *image = dynamic_cast<device_image_interface *>(laser_file(machine));
383372        size = TRKSIZE_VZ;
384        offs = TRKSIZE_VZ * laser_track_x2[laser_drive]/2;
373        offs = TRKSIZE_VZ * state->laser_track_x2[state->laser_drive]/2;
385374        image->fseek(offs, SEEK_SET);
386        size = image->fread(laser_fdc_data, size);
375        size = image->fread(state->laser_fdc_data, size);
387376        logerror("get track @$%05x $%04x bytes\n", offs, size);
388377    }
389    laser_fdc_offs = 0;
390    laser_fdc_write = 0;
378    state->laser_fdc_offs = 0;
379    state->laser_fdc_write = 0;
391380}
392381
393382static void laser_put_track(running_machine *machine)
394383{
384   vtech2_state *state = machine->driver_data<vtech2_state>();
395385   device_image_interface *image = dynamic_cast<device_image_interface *>(laser_file(machine));
396386    /* drive selected and image file ok? */
397    if( laser_drive >= 0 && laser_file(machine) != NULL )
387    if( state->laser_drive >= 0 && laser_file(machine) != NULL )
398388    {
399389        int size, offs;
400        offs = TRKSIZE_VZ * laser_track_x2[laser_drive]/2;
401        image->fseek(offs + laser_fdc_start, SEEK_SET);
402        size = image->fwrite(&laser_fdc_data[laser_fdc_start], laser_fdc_write);
403        logerror("put track @$%05X+$%X $%04X/$%04X bytes\n", offs, laser_fdc_start, size, laser_fdc_write);
390        offs = TRKSIZE_VZ * state->laser_track_x2[state->laser_drive]/2;
391        image->fseek(offs + state->laser_fdc_start, SEEK_SET);
392        size = image->fwrite(&state->laser_fdc_data[state->laser_fdc_start], state->laser_fdc_write);
393        logerror("put track @$%05X+$%X $%04X/$%04X bytes\n", offs, state->laser_fdc_start, size, state->laser_fdc_write);
404394    }
405395}
406396
r9669r9670
411401
412402 READ8_HANDLER( laser_fdc_r )
413403{
404   vtech2_state *state = space->machine->driver_data<vtech2_state>();
414405    int data = 0xff;
415406    switch( offset )
416407    {
417408    case 1: /* data (read-only) */
418        if( laser_fdc_bits > 0 )
409        if( state->laser_fdc_bits > 0 )
419410        {
420            if( laser_fdc_status & 0x80 )
421                laser_fdc_bits--;
422            data = (laser_data >> laser_fdc_bits) & 0xff;
411            if( state->laser_fdc_status & 0x80 )
412                state->laser_fdc_bits--;
413            data = (state->laser_data >> state->laser_fdc_bits) & 0xff;
423414#if 0
424415            logerror("laser_fdc_r bits %d%d%d%d%d%d%d%d\n",
425416                (data>>7)&1,(data>>6)&1,(data>>5)&1,(data>>4)&1,
426417                (data>>3)&1,(data>>2)&1,(data>>1)&1,(data>>0)&1 );
427418#endif
428419        }
429        if( laser_fdc_bits == 0 )
420        if( state->laser_fdc_bits == 0 )
430421        {
431            laser_data = laser_fdc_data[laser_fdc_offs];
432            logerror("laser_fdc_r %d : data ($%04X) $%02X\n", offset, laser_fdc_offs, laser_data);
433            if( laser_fdc_status & 0x80 )
422            state->laser_data = state->laser_fdc_data[state->laser_fdc_offs];
423            logerror("laser_fdc_r %d : data ($%04X) $%02X\n", offset, state->laser_fdc_offs, state->laser_data);
424            if( state->laser_fdc_status & 0x80 )
434425            {
435                laser_fdc_bits = 8;
436                laser_fdc_offs = (laser_fdc_offs + 1) % TRKSIZE_FM;
426                state->laser_fdc_bits = 8;
427                state->laser_fdc_offs = (state->laser_fdc_offs + 1) % TRKSIZE_FM;
437428            }
438            laser_fdc_status &= ~0x80;
429            state->laser_fdc_status &= ~0x80;
439430        }
440431        break;
441432    case 2: /* polling (read-only) */
442433        /* fake */
443        if( laser_drive >= 0 )
444            laser_fdc_status |= 0x80;
445        data = laser_fdc_status;
434        if( state->laser_drive >= 0 )
435            state->laser_fdc_status |= 0x80;
436        data = state->laser_fdc_status;
446437        break;
447438    case 3: /* write protect status (read-only) */
448        if( laser_drive >= 0 )
449            data = laser_fdc_wrprot[laser_drive];
439        if( state->laser_drive >= 0 )
440            data = laser_fdc_wrprot[state->laser_drive];
450441        logerror("laser_fdc_r %d : write_protect $%02X\n", offset, data);
451442        break;
452443    }
r9669r9670
455446
456447WRITE8_HANDLER( laser_fdc_w )
457448{
449   vtech2_state *state = space->machine->driver_data<vtech2_state>();
458450    int drive;
459451
460452    switch( offset )
461453    {
462454    case 0: /* latch (write-only) */
463455        drive = (data & 0x10) ? 0 : (data & 0x80) ? 1 : -1;
464        if( drive != laser_drive )
456        if( drive != state->laser_drive )
465457        {
466            laser_drive = drive;
467            if( laser_drive >= 0 )
458            state->laser_drive = drive;
459            if( state->laser_drive >= 0 )
468460                laser_get_track(space->machine);
469461        }
470        if( laser_drive >= 0 )
462        if( state->laser_drive >= 0 )
471463        {
472            if( (PHI0(data) && !(PHI1(data) || PHI2(data) || PHI3(data)) && PHI1(laser_fdc_latch)) ||
473                (PHI1(data) && !(PHI0(data) || PHI2(data) || PHI3(data)) && PHI2(laser_fdc_latch)) ||
474                (PHI2(data) && !(PHI0(data) || PHI1(data) || PHI3(data)) && PHI3(laser_fdc_latch)) ||
475                (PHI3(data) && !(PHI0(data) || PHI1(data) || PHI2(data)) && PHI0(laser_fdc_latch)) )
464            if( (PHI0(data) && !(PHI1(data) || PHI2(data) || PHI3(data)) && PHI1(state->laser_fdc_latch)) ||
465                (PHI1(data) && !(PHI0(data) || PHI2(data) || PHI3(data)) && PHI2(state->laser_fdc_latch)) ||
466                (PHI2(data) && !(PHI0(data) || PHI1(data) || PHI3(data)) && PHI3(state->laser_fdc_latch)) ||
467                (PHI3(data) && !(PHI0(data) || PHI1(data) || PHI2(data)) && PHI0(state->laser_fdc_latch)) )
476468            {
477                if( laser_track_x2[laser_drive] > 0 )
478                    laser_track_x2[laser_drive]--;
479                logerror("laser_fdc_w(%d) $%02X drive %d: stepout track #%2d.%d\n", offset, data, laser_drive, laser_track_x2[laser_drive]/2,5*(laser_track_x2[laser_drive]&1));
480                if( (laser_track_x2[laser_drive] & 1) == 0 )
469                if( state->laser_track_x2[state->laser_drive] > 0 )
470                    state->laser_track_x2[state->laser_drive]--;
471                logerror("laser_fdc_w(%d) $%02X drive %d: stepout track #%2d.%d\n", offset, data, state->laser_drive, state->laser_track_x2[state->laser_drive]/2,5*(state->laser_track_x2[state->laser_drive]&1));
472                if( (state->laser_track_x2[state->laser_drive] & 1) == 0 )
481473                    laser_get_track(space->machine);
482474            }
483475            else
484            if( (PHI0(data) && !(PHI1(data) || PHI2(data) || PHI3(data)) && PHI3(laser_fdc_latch)) ||
485                (PHI1(data) && !(PHI0(data) || PHI2(data) || PHI3(data)) && PHI0(laser_fdc_latch)) ||
486                (PHI2(data) && !(PHI0(data) || PHI1(data) || PHI3(data)) && PHI1(laser_fdc_latch)) ||
487                (PHI3(data) && !(PHI0(data) || PHI1(data) || PHI2(data)) && PHI2(laser_fdc_latch)) )
476            if( (PHI0(data) && !(PHI1(data) || PHI2(data) || PHI3(data)) && PHI3(state->laser_fdc_latch)) ||
477                (PHI1(data) && !(PHI0(data) || PHI2(data) || PHI3(data)) && PHI0(state->laser_fdc_latch)) ||
478                (PHI2(data) && !(PHI0(data) || PHI1(data) || PHI3(data)) && PHI1(state->laser_fdc_latch)) ||
479                (PHI3(data) && !(PHI0(data) || PHI1(data) || PHI2(data)) && PHI2(state->laser_fdc_latch)) )
488480            {
489                if( laser_track_x2[laser_drive] < 2*40 )
490                    laser_track_x2[laser_drive]++;
491                logerror("laser_fdc_w(%d) $%02X drive %d: stepin track #%2d.%d\n", offset, data, laser_drive, laser_track_x2[laser_drive]/2,5*(laser_track_x2[laser_drive]&1));
492                if( (laser_track_x2[laser_drive] & 1) == 0 )
481                if( state->laser_track_x2[state->laser_drive] < 2*40 )
482                    state->laser_track_x2[state->laser_drive]++;
483                logerror("laser_fdc_w(%d) $%02X drive %d: stepin track #%2d.%d\n", offset, data, state->laser_drive, state->laser_track_x2[state->laser_drive]/2,5*(state->laser_track_x2[state->laser_drive]&1));
484                if( (state->laser_track_x2[state->laser_drive] & 1) == 0 )
493485                    laser_get_track(space->machine);
494486            }
495487            if( (data & 0x40) == 0 )
496488            {
497                laser_data <<= 1;
498                if( (laser_fdc_latch ^ data) & 0x20 )
499                    laser_data |= 1;
500                if( (laser_fdc_edge ^= 1) == 0 )
489                state->laser_data <<= 1;
490                if( (state->laser_fdc_latch ^ data) & 0x20 )
491                    state->laser_data |= 1;
492                if( (state->laser_fdc_edge ^= 1) == 0 )
501493                {
502                    if( --laser_fdc_bits == 0 )
494                    if( --state->laser_fdc_bits == 0 )
503495                    {
504496                        UINT8 value = 0;
505                        laser_data &= 0xffff;
506                        if( laser_data & 0x4000 ) value |= 0x80;
507                        if( laser_data & 0x1000 ) value |= 0x40;
508                        if( laser_data & 0x0400 ) value |= 0x20;
509                        if( laser_data & 0x0100 ) value |= 0x10;
510                        if( laser_data & 0x0040 ) value |= 0x08;
511                        if( laser_data & 0x0010 ) value |= 0x04;
512                        if( laser_data & 0x0004 ) value |= 0x02;
513                        if( laser_data & 0x0001 ) value |= 0x01;
514                        logerror("laser_fdc_w(%d) data($%04X) $%02X <- $%02X ($%04X)\n", offset, laser_fdc_offs, laser_fdc_data[laser_fdc_offs], value, laser_data);
515                        laser_fdc_data[laser_fdc_offs] = value;
516                        laser_fdc_offs = (laser_fdc_offs + 1) % TRKSIZE_FM;
517                        laser_fdc_write++;
518                        laser_fdc_bits = 8;
497                        state->laser_data &= 0xffff;
498                        if( state->laser_data & 0x4000 ) value |= 0x80;
499                        if( state->laser_data & 0x1000 ) value |= 0x40;
500                        if( state->laser_data & 0x0400 ) value |= 0x20;
501                        if( state->laser_data & 0x0100 ) value |= 0x10;
502                        if( state->laser_data & 0x0040 ) value |= 0x08;
503                        if( state->laser_data & 0x0010 ) value |= 0x04;
504                        if( state->laser_data & 0x0004 ) value |= 0x02;
505                        if( state->laser_data & 0x0001 ) value |= 0x01;
506                        logerror("laser_fdc_w(%d) data($%04X) $%02X <- $%02X ($%04X)\n", offset, state->laser_fdc_offs, state->laser_fdc_data[state->laser_fdc_offs], value, state->laser_data);
507                        state->laser_fdc_data[state->laser_fdc_offs] = value;
508                        state->laser_fdc_offs = (state->laser_fdc_offs + 1) % TRKSIZE_FM;
509                        state->laser_fdc_write++;
510                        state->laser_fdc_bits = 8;
519511                    }
520512                }
521513            }
522514            /* change of write signal? */
523            if( (laser_fdc_latch ^ data) & 0x40 )
515            if( (state->laser_fdc_latch ^ data) & 0x40 )
524516            {
525517                /* falling edge? */
526                if ( laser_fdc_latch & 0x40 )
518                if ( state->laser_fdc_latch & 0x40 )
527519                {
528                    sprintf(laser_frame_message, "#%d put track %02d", laser_drive, laser_track_x2[laser_drive]/2);
529                    laser_frame_time = 30;
530                    laser_fdc_start = laser_fdc_offs;
531               laser_fdc_edge = 0;
520                    sprintf(state->laser_frame_message, "#%d put track %02d", state->laser_drive, state->laser_track_x2[state->laser_drive]/2);
521                    state->laser_frame_time = 30;
522                    state->laser_fdc_start = state->laser_fdc_offs;
523               state->laser_fdc_edge = 0;
532524                }
533525                else
534526                {
535527                    /* data written to track before? */
536                    if( laser_fdc_write )
528                    if( state->laser_fdc_write )
537529                        laser_put_track(space->machine);
538530                }
539                laser_fdc_bits = 8;
540                laser_fdc_write = 0;
531                state->laser_fdc_bits = 8;
532                state->laser_fdc_write = 0;
541533            }
542534        }
543        laser_fdc_latch = data;
535        state->laser_fdc_latch = data;
544536        break;
545537    }
546538}
src/mess/machine/wswan.c
r9669r9670
2727static const char *const wswan_sram_str[] = { "none", "64Kbit SRAM", "256Kbit SRAM", "512Kbit SRAM", "1Mbit SRAM", "2Mbit SRAM", "1Kbit EEPROM", "16Kbit EEPROM", "8Kbit EEPROM", "Unknown" };
2828static const int wswan_sram_size[] = { 0, 64*1024/8, 256*1024/8, 512*1024/8, 1024*1024/8, 2*1024*1024/8,  1024/8, 16*1024/8, 8*1024/8, 0 };
2929
30typedef struct {
31   UINT8   mode;      /* eeprom mode */
32   UINT16   address;   /* Read/write address */
33   UINT8   command;   /* Commands: 00, 01, 02, 03, 04, 08, 0C */
34   UINT8   start;      /* start bit */
35   UINT8   write_enabled;   /* write enabled yes/no */
36   int   size;      /* size of eeprom/sram area */
37   UINT8   *data;      /* pointer to start of sram/eeprom data */
38   UINT8   *page;      /* pointer to current sram/eeprom page */
39} EEPROM;
40
41typedef struct {
42   UINT8   present;   /* Is an RTC present */
43   UINT8   setting;   /* Timer setting byte */
44   UINT8   year;      /* Year */
45   UINT8   month;      /* Month */
46   UINT8   day;      /* Day */
47   UINT8   day_of_week;   /* Day of the week */
48   UINT8   hour;      /* Hour, high bit = 0 => AM, high bit = 1 => PM */
49   UINT8   minute;      /* Minute */
50   UINT8   second;      /* Second */
51   UINT8   index;      /* index for reading/writing of current of alarm time */
52} RTC;
53
54typedef struct {
55   UINT32   source;      /* Source address */
56   UINT16   size;      /* Size */
57   UINT8   enable;      /* Enabled */
58} SoundDMA;
59
6030static TIMER_CALLBACK(wswan_scanline_interrupt);
6131
6232
63static UINT8 *ROMMap[256];
64static UINT32 ROMBanks;
65static UINT8 internal_eeprom[INTERNAL_EEPROM_SIZE];
66static UINT8 system_type;
67VDP wswan_vdp;
68static EEPROM eeprom;
69static RTC rtc;
70static SoundDMA sound_dma;
71static UINT8 *ws_ram;
72static UINT8 *ws_bios_bank;
73static UINT8 wswan_bios_disabled;
74UINT8 ws_portram[256];
7533static const UINT8 ws_portram_init[256] =
7634{
7735   0x00, 0x00, 0x00/*?*/, 0xbb, 0x00, 0x00, 0x00, 0x26, 0xfe, 0xde, 0xf9, 0xfb, 0xdb, 0xd7, 0x7f, 0xf5,
r9669r9670
13088
13189static void wswan_handle_irqs( running_machine *machine )
13290{
133   if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_HBLTMR ) {
134      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_HBLTMR );
135   } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_VBL ) {
136      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_VBL );
137   } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_VBLTMR ) {
138      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_VBLTMR );
139   } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_LCMP ) {
140      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_LCMP );
141   } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_SRX ) {
142      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_SRX );
143   } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_RTC ) {
144      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_RTC );
145   } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_KEY ) {
146      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_KEY );
147   } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_STX ) {
148      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_STX );
91   wswan_state *state = machine->driver_data<wswan_state>();
92   if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_HBLTMR ) {
93      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_HBLTMR );
94   } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_VBL ) {
95      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_VBL );
96   } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_VBLTMR ) {
97      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_VBLTMR );
98   } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_LCMP ) {
99      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_LCMP );
100   } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_SRX ) {
101      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_SRX );
102   } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_RTC ) {
103      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_RTC );
104   } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_KEY ) {
105      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_KEY );
106   } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_STX ) {
107      cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_STX );
149108   } else {
150109      cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE );
151110   }
r9669r9670
153112
154113static void wswan_set_irq_line( running_machine *machine, int irq)
155114{
156   if ( ws_portram[0xb2] & irq )
115   wswan_state *state = machine->driver_data<wswan_state>();
116   if ( state->ws_portram[0xb2] & irq )
157117   {
158      ws_portram[0xb6] |= irq;
118      state->ws_portram[0xb6] |= irq;
159119      wswan_handle_irqs( machine );
160120   }
161121}
162122
163123static void wswan_clear_irq_line( running_machine *machine, int irq)
164124{
165   ws_portram[0xb6] &= ~irq;
125   wswan_state *state = machine->driver_data<wswan_state>();
126   state->ws_portram[0xb6] &= ~irq;
166127   wswan_handle_irqs( machine );
167128}
168129
169130static TIMER_CALLBACK(wswan_rtc_callback)
170131{
132   wswan_state *state = machine->driver_data<wswan_state>();
171133   /* A second passed */
172   rtc.second = rtc.second + 1;
173   if ( ( rtc.second & 0x0F ) > 9 )
134   state->rtc.second = state->rtc.second + 1;
135   if ( ( state->rtc.second & 0x0F ) > 9 )
174136   {
175      rtc.second = ( rtc.second & 0xF0 ) + 0x10;
137      state->rtc.second = ( state->rtc.second & 0xF0 ) + 0x10;
176138   }
177139
178140   /* Check for minute passed */
179   if ( rtc.second >= 0x60 )
141   if ( state->rtc.second >= 0x60 )
180142   {
181      rtc.second = 0;
182      rtc.minute = rtc.minute + 1;
183      if ( ( rtc.minute & 0x0F ) > 9 )
143      state->rtc.second = 0;
144      state->rtc.minute = state->rtc.minute + 1;
145      if ( ( state->rtc.minute & 0x0F ) > 9 )
184146      {
185         rtc.minute = ( rtc.minute & 0xF0 ) + 0x10;
147         state->rtc.minute = ( state->rtc.minute & 0xF0 ) + 0x10;
186148      }
187149   }
188150
189151   /* Check for hour passed */
190   if ( rtc.minute >= 0x60 )
152   if ( state->rtc.minute >= 0x60 )
191153   {
192      rtc.minute = 0;
193      rtc.hour = rtc.hour + 1;
194      if ( ( rtc.hour & 0x0F ) > 9 )
154      state->rtc.minute = 0;
155      state->rtc.hour = state->rtc.hour + 1;
156      if ( ( state->rtc.hour & 0x0F ) > 9 )
195157      {
196         rtc.hour = ( rtc.hour & 0xF0 ) + 0x10;
158         state->rtc.hour = ( state->rtc.hour & 0xF0 ) + 0x10;
197159      }
198      if ( rtc.hour == 0x12 )
160      if ( state->rtc.hour == 0x12 )
199161      {
200         rtc.hour |= 0x80;
162         state->rtc.hour |= 0x80;
201163      }
202164   }
203165
204166   /* Check for day passed */
205   if ( rtc.hour >= 0x24 )
167   if ( state->rtc.hour >= 0x24 )
206168   {
207      rtc.hour = 0;
208      rtc.day = rtc.day + 1;
169      state->rtc.hour = 0;
170      state->rtc.day = state->rtc.day + 1;
209171   }
210172}
211173
212174static void wswan_machine_stop( running_machine &machine )
213175{
176   wswan_state *state = machine.driver_data<wswan_state>();
214177   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
215   if ( eeprom.size )
178   if ( state->eeprom.size )
216179   {
217      image->battery_save(eeprom.data, eeprom.size );
180      image->battery_save(state->eeprom.data, state->eeprom.size );
218181   }
219182}
220183
221184static void wswan_setup_bios( running_machine *machine )
222185{
223   if ( ws_bios_bank == NULL )
186   wswan_state *state = machine->driver_data<wswan_state>();
187   if ( state->ws_bios_bank == NULL )
224188   {
225      ws_bios_bank = auto_alloc_array(machine, UINT8, 0x10000 );
226      memcpy( ws_bios_bank + 0xffc0, ws_fake_bios_code, 0x40 );
189      state->ws_bios_bank = auto_alloc_array(machine, UINT8, 0x10000 );
190      memcpy( state->ws_bios_bank + 0xffc0, ws_fake_bios_code, 0x40 );
227191   }
228192}
229193
230194MACHINE_START( wswan )
231195{
232   ws_bios_bank = NULL;
233   system_type = TYPE_WSWAN;
196   wswan_state *state = machine->driver_data<wswan_state>();
197   state->ws_bios_bank = NULL;
198   state->system_type = TYPE_WSWAN;
234199   machine->add_notifier(MACHINE_NOTIFY_EXIT, wswan_machine_stop );
235   wswan_vdp.timer = timer_alloc( machine, wswan_scanline_interrupt, &wswan_vdp );
236   timer_adjust_periodic( wswan_vdp.timer, ticks_to_attotime( 256, 3072000 ), 0, ticks_to_attotime( 256, 3072000 ) );
200   state->vdp.timer = timer_alloc( machine, wswan_scanline_interrupt, &state->vdp );
201   timer_adjust_periodic( state->vdp.timer, ticks_to_attotime( 256, 3072000 ), 0, ticks_to_attotime( 256, 3072000 ) );
237202
238203   wswan_setup_bios(machine);
239204
240205   /* Set up RTC timer */
241   if ( rtc.present )
206   if ( state->rtc.present )
242207      timer_pulse(machine,  ATTOTIME_IN_SEC(1), NULL, 0, wswan_rtc_callback );
243208}
244209
245210MACHINE_START( wscolor )
246211{
247   ws_bios_bank = NULL;
248   system_type = TYPE_WSC;
212   wswan_state *state = machine->driver_data<wswan_state>();
213   state->ws_bios_bank = NULL;
214   state->system_type = TYPE_WSC;
249215   machine->add_notifier(MACHINE_NOTIFY_EXIT, wswan_machine_stop );
250   wswan_vdp.timer = timer_alloc( machine, wswan_scanline_interrupt, &wswan_vdp );
251   timer_adjust_periodic( wswan_vdp.timer, ticks_to_attotime( 256, 3072000 ), 0, ticks_to_attotime( 256, 3072000 ) );
216   state->vdp.timer = timer_alloc( machine, wswan_scanline_interrupt, &state->vdp );
217   timer_adjust_periodic( state->vdp.timer, ticks_to_attotime( 256, 3072000 ), 0, ticks_to_attotime( 256, 3072000 ) );
252218
253219   wswan_setup_bios(machine);
254220
255221   /* Set up RTC timer */
256   if ( rtc.present )
222   if ( state->rtc.present )
257223      timer_pulse(machine,  ATTOTIME_IN_SEC(1), NULL, 0, wswan_rtc_callback );
258224}
259225
260226MACHINE_RESET( wswan )
261227{
228   wswan_state *state = machine->driver_data<wswan_state>();
262229   address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM );
263230
264231   /* Intialize ports */
265   memcpy( ws_portram, ws_portram_init, 256 );
232   memcpy( state->ws_portram, ws_portram_init, 256 );
266233
267234   /* Initialize VDP */
268   memset( &wswan_vdp, 0, sizeof( wswan_vdp ) );
235   memset( &state->vdp, 0, sizeof( state->vdp ) );
269236
270   wswan_vdp.vram = (UINT8*)space->get_read_ptr(0);
271   wswan_vdp.palette_vram = (UINT8*)space->get_read_ptr(( system_type == TYPE_WSC ) ? 0xFE00 : 0 );
272   wswan_vdp.current_line = 145;  /* Randomly chosen, beginning of VBlank period to give cart some time to boot up */
273   wswan_vdp.new_display_vertical = ROMMap[ROMBanks-1][0xfffc] & 0x01;
274   wswan_vdp.display_vertical = ~wswan_vdp.new_display_vertical;
275   wswan_vdp.color_mode = 0;
276   wswan_vdp.colors_16 = 0;
277   wswan_vdp.tile_packed = 0;
237   state->vdp.vram = (UINT8*)space->get_read_ptr(0);
238   state->vdp.palette_vram = (UINT8*)space->get_read_ptr(( state->system_type == TYPE_WSC ) ? 0xFE00 : 0 );
239   state->vdp.current_line = 145;  /* Randomly chosen, beginning of VBlank period to give cart some time to boot up */
240   state->vdp.new_display_vertical = state->ROMMap[state->ROMBanks-1][0xfffc] & 0x01;
241   state->vdp.display_vertical = ~state->vdp.new_display_vertical;
242   state->vdp.color_mode = 0;
243   state->vdp.colors_16 = 0;
244   state->vdp.tile_packed = 0;
278245
279246   /* Initialize sound DMA */
280   memset( &sound_dma, 0, sizeof( sound_dma ) );
247   memset( &state->sound_dma, 0, sizeof( state->sound_dma ) );
281248
282249   /* Switch in the banks */
283   memory_set_bankptr( machine, "bank2", ROMMap[(ROMBanks - 1) & (ROMBanks - 1)] );
284   memory_set_bankptr( machine, "bank3", ROMMap[(ROMBanks - 1) & (ROMBanks - 1)] );
285   memory_set_bankptr( machine, "bank4", ROMMap[(ROMBanks - 12) & (ROMBanks - 1)] );
286   memory_set_bankptr( machine, "bank5", ROMMap[(ROMBanks - 11) & (ROMBanks - 1)] );
287   memory_set_bankptr( machine, "bank6", ROMMap[(ROMBanks - 10) & (ROMBanks - 1)] );
288   memory_set_bankptr( machine, "bank7", ROMMap[(ROMBanks - 9) & (ROMBanks - 1)] );
289   memory_set_bankptr( machine, "bank8", ROMMap[(ROMBanks - 8) & (ROMBanks - 1)] );
290   memory_set_bankptr( machine, "bank9", ROMMap[(ROMBanks - 7) & (ROMBanks - 1)] );
291   memory_set_bankptr( machine, "bank10", ROMMap[(ROMBanks - 6) & (ROMBanks - 1)] );
292   memory_set_bankptr( machine, "bank11", ROMMap[(ROMBanks - 5) & (ROMBanks - 1)] );
293   memory_set_bankptr( machine, "bank12", ROMMap[(ROMBanks - 4) & (ROMBanks - 1)] );
294   memory_set_bankptr( machine, "bank13", ROMMap[(ROMBanks - 3) & (ROMBanks - 1)] );
295   memory_set_bankptr( machine, "bank14", ROMMap[(ROMBanks - 2) & (ROMBanks - 1)] );
296   wswan_bios_disabled = 0;
297   memory_set_bankptr( machine, "bank15", ws_bios_bank );
298//  memory_set_bankptr( machine, 15, ROMMap[(ROMBanks - 1) & (ROMBanks - 1)] );
250   memory_set_bankptr( machine, "bank2", state->ROMMap[(state->ROMBanks - 1) & (state->ROMBanks - 1)] );
251   memory_set_bankptr( machine, "bank3", state->ROMMap[(state->ROMBanks - 1) & (state->ROMBanks - 1)] );
252   memory_set_bankptr( machine, "bank4", state->ROMMap[(state->ROMBanks - 12) & (state->ROMBanks - 1)] );
253   memory_set_bankptr( machine, "bank5", state->ROMMap[(state->ROMBanks - 11) & (state->ROMBanks - 1)] );
254   memory_set_bankptr( machine, "bank6", state->ROMMap[(state->ROMBanks - 10) & (state->ROMBanks - 1)] );
255   memory_set_bankptr( machine, "bank7", state->ROMMap[(state->ROMBanks - 9) & (state->ROMBanks - 1)] );
256   memory_set_bankptr( machine, "bank8", state->ROMMap[(state->ROMBanks - 8) & (state->ROMBanks - 1)] );
257   memory_set_bankptr( machine, "bank9", state->ROMMap[(state->ROMBanks - 7) & (state->ROMBanks - 1)] );
258   memory_set_bankptr( machine, "bank10", state->ROMMap[(state->ROMBanks - 6) & (state->ROMBanks - 1)] );
259   memory_set_bankptr( machine, "bank11", state->ROMMap[(state->ROMBanks - 5) & (state->ROMBanks - 1)] );
260   memory_set_bankptr( machine, "bank12", state->ROMMap[(state->ROMBanks - 4) & (state->ROMBanks - 1)] );
261   memory_set_bankptr( machine, "bank13", state->ROMMap[(state->ROMBanks - 3) & (state->ROMBanks - 1)] );
262   memory_set_bankptr( machine, "bank14", state->ROMMap[(state->ROMBanks - 2) & (state->ROMBanks - 1)] );
263   state->bios_disabled = 0;
264   memory_set_bankptr( machine, "bank15", state->ws_bios_bank );
265//  memory_set_bankptr( machine, 15, state->ROMMap[(state->ROMBanks - 1) & (state->ROMBanks - 1)] );
299266}
300267
301268NVRAM_HANDLER( wswan )
302269{
270   wswan_state *state = machine->driver_data<wswan_state>();
303271   if ( read_or_write )
304272   {
305273      /* Save the EEPROM data */
306      mame_fwrite( file, internal_eeprom, INTERNAL_EEPROM_SIZE );
274      mame_fwrite( file, state->internal_eeprom, INTERNAL_EEPROM_SIZE );
307275   }
308276   else
309277   {
310278      /* Load the EEPROM data */
311279      if ( file )
312280      {
313         mame_fread( file, internal_eeprom, INTERNAL_EEPROM_SIZE );
281         mame_fread( file, state->internal_eeprom, INTERNAL_EEPROM_SIZE );
314282      }
315283      else
316284      {
317285         /* Initialize the EEPROM data */
318         memset( internal_eeprom, 0xFF, sizeof( internal_eeprom ) );
286         memset( state->internal_eeprom, 0xFF, sizeof( state->internal_eeprom ) );
319287      }
320288   }
321289}
322290
323291READ8_HANDLER( wswan_sram_r )
324292{
325   if ( eeprom.data == NULL )
293   wswan_state *state = space->machine->driver_data<wswan_state>();
294   if ( state->eeprom.data == NULL )
326295   {
327296      return 0xFF;
328297   }
329   return eeprom.page[ offset & ( eeprom.size - 1 ) ];
298   return state->eeprom.page[ offset & ( state->eeprom.size - 1 ) ];
330299}
331300
332301WRITE8_HANDLER( wswan_sram_w )
333302{
334   if ( eeprom.data == NULL )
303   wswan_state *state = space->machine->driver_data<wswan_state>();
304   if ( state->eeprom.data == NULL )
335305   {
336306      return;
337307   }
338   eeprom.page[ offset & ( eeprom.size - 1 ) ] = data;
308   state->eeprom.page[ offset & ( state->eeprom.size - 1 ) ] = data;
339309}
340310
341311READ8_HANDLER( wswan_port_r )
342312{
343   UINT8 value = ws_portram[offset];
313   wswan_state *state = space->machine->driver_data<wswan_state>();
314   UINT8 value = state->ws_portram[offset];
344315
345316   if ( offset != 2 )
346317   logerror( "PC=%X: port read %02X\n", cpu_get_pc( space->cpu ), offset );
347318   switch( offset )
348319   {
349320      case 0x02:      /* Current line */
350         value = wswan_vdp.current_line;
321         value = state->vdp.current_line;
351322         break;
352323      case 0x4A:      /* Sound DMA source address (low) */
353         value = sound_dma.source & 0xFF;
324         value = state->sound_dma.source & 0xFF;
354325         break;
355326      case 0x4B:      /* Sound DMA source address (high) */
356         value = ( sound_dma.source >> 8 ) & 0xFF;
327         value = ( state->sound_dma.source >> 8 ) & 0xFF;
357328         break;
358329      case 0x4C:      /* Sound DMA source memory segment */
359         value = ( sound_dma.source >> 16 ) & 0xFF;
330         value = ( state->sound_dma.source >> 16 ) & 0xFF;
360331         break;
361332      case 0x4E:      /* Sound DMA transfer size (low) */
362         value = sound_dma.size & 0xFF;
333         value = state->sound_dma.size & 0xFF;
363334         break;
364335      case 0x4F:      /* Sound DMA transfer size (high) */
365         value = ( sound_dma.size >> 8 ) & 0xFF;
336         value = ( state->sound_dma.size >> 8 ) & 0xFF;
366337         break;
367338      case 0x52:      /* Sound DMA start/stop */
368         value = sound_dma.enable;
339         value = state->sound_dma.enable;
369340         break;
370341      case 0xA0:      /* Hardware type */
371342               /* Bit 0 - Disable/enable Bios */
372343               /* Bit 1 - Determine mono/color */
373344               /* Bit 2 - Determine color/crystal */
374345         value = value & ~ 0x02;
375         if ( system_type == TYPE_WSC )
346         if ( state->system_type == TYPE_WSC )
376347         {
377348            value |= 2;
378349         }
379350         break;
380351      case 0xA8:
381         value = wswan_vdp.timer_hblank_count & 0xFF;
352         value = state->vdp.timer_hblank_count & 0xFF;
382353         break;
383354      case 0xA9:
384         value = wswan_vdp.timer_hblank_count >> 8;
355         value = state->vdp.timer_hblank_count >> 8;
385356         break;
386357      case 0xAA:
387         value = wswan_vdp.timer_vblank_count & 0xFF;
358         value = state->vdp.timer_vblank_count & 0xFF;
388359         break;
389360      case 0xAB:
390         value = wswan_vdp.timer_vblank_count >> 8;
361         value = state->vdp.timer_vblank_count >> 8;
391362         break;
392363      case 0xCB:      /* RTC data */
393         if ( ws_portram[0xca] == 0x95 && ( rtc.index < 7 ) )
364         if ( state->ws_portram[0xca] == 0x95 && ( state->rtc.index < 7 ) )
394365         {
395            switch( rtc.index )
366            switch( state->rtc.index )
396367            {
397            case 0: value = rtc.year; break;
398            case 1: value = rtc.month; break;
399            case 2: value = rtc.day; break;
400            case 3: value = rtc.day_of_week; break;
401            case 4: value = rtc.hour; break;
402            case 5: value = rtc.minute; break;
403            case 6: value = rtc.second; break;
368            case 0: value = state->rtc.year; break;
369            case 1: value = state->rtc.month; break;
370            case 2: value = state->rtc.day; break;
371            case 3: value = state->rtc.day_of_week; break;
372            case 4: value = state->rtc.hour; break;
373            case 5: value = state->rtc.minute; break;
374            case 6: value = state->rtc.second; break;
404375            }
405            rtc.index++;
376            state->rtc.index++;
406377         }
407378   }
408379
r9669r9670
411382
412383WRITE8_HANDLER( wswan_port_w )
413384{
385   wswan_state *state = space->machine->driver_data<wswan_state>();
414386   logerror( "PC=%X: port write %02X <- %02X\n", cpu_get_pc( space->cpu ), offset, data );
415387   switch( offset )
416388   {
r9669r9670
426398                             11 - Foreground layer is displayed outside foreground window area
427399                   Bit 6-7 - Unknown
428400                */
429         wswan_vdp.layer_bg_enable = data & 0x1;
430         wswan_vdp.layer_fg_enable = (data & 0x2) >> 1;
431         wswan_vdp.sprites_enable = (data & 0x4) >> 2;
432         wswan_vdp.window_sprites_enable = (data & 0x8) >> 3;
433         wswan_vdp.window_fg_mode = (data & 0x30) >> 4;
401         state->vdp.layer_bg_enable = data & 0x1;
402         state->vdp.layer_fg_enable = (data & 0x2) >> 1;
403         state->vdp.sprites_enable = (data & 0x4) >> 2;
404         state->vdp.window_sprites_enable = (data & 0x8) >> 3;
405         state->vdp.window_fg_mode = (data & 0x30) >> 4;
434406         break;
435407      case 0x01:   /* Background colour
436408                   In 16 colour mode:
r9669r9670
444416      case 0x02:   /* Current scanline
445417                   Bit 0-7 - Current scanline (Most likely read-only)
446418                */
447         logerror( "Write to current scanline! Current value: %d  Data to write: %d\n", wswan_vdp.current_line, data );
419         logerror( "Write to current scanline! Current value: %d  Data to write: %d\n", state->vdp.current_line, data );
448420         /* Returning so we don't overwrite the value here, not that it
449421             * really matters */
450422         return;
451423      case 0x03:   /* Line compare
452424                   Bit 0-7 - Line compare
453425                */
454         wswan_vdp.line_compare = data;
426         state->vdp.line_compare = data;
455427         break;
456428      case 0x04:   /* Sprite table base address
457429                   Bit 0-5 - Determine sprite table base address 0 0xxxxxx0 00000000
458430                   Bit 6-7 - Unknown
459431                */
460         wswan_vdp.sprite_table_address = ( data & 0x3F ) << 9;
432         state->vdp.sprite_table_address = ( data & 0x3F ) << 9;
461433         break;
462434      case 0x05:   /* Number of sprite to start drawing with
463435                   Bit 0-7 - First sprite number
464436                */
465         wswan_vdp.sprite_first = data;
437         state->vdp.sprite_first = data;
466438         break;
467439      case 0x06:   /* Number of sprites to draw
468440                   Bit 0-7 - Number of sprites to draw
469441                */
470         wswan_vdp.sprite_count = data;
442         state->vdp.sprite_count = data;
471443         break;
472444      case 0x07:   /* Background/Foreground table base addresses
473445                   Bit 0-2 - Determine background table base address 00xxx000 00000000
r9669r9670
475447                   Bit 4-6 - Determine foreground table base address 00xxx000 00000000
476448                   Bit 7   - Unknown
477449                */
478         wswan_vdp.layer_bg_address = (data & 0x7) << 11;
479         wswan_vdp.layer_fg_address = (data & 0x70) << 7;
450         state->vdp.layer_bg_address = (data & 0x7) << 11;
451         state->vdp.layer_fg_address = (data & 0x70) << 7;
480452         break;
481453      case 0x08:   /* Left coordinate of foreground window
482454                   Bit 0-7 - Left coordinate of foreground window area
483455                */
484         wswan_vdp.window_fg_left = data;
456         state->vdp.window_fg_left = data;
485457         break;
486458      case 0x09:   /* Top coordinate of foreground window
487459                   Bit 0-7 - Top coordinatte of foreground window area
488460                */
489         wswan_vdp.window_fg_top = data;
461         state->vdp.window_fg_top = data;
490462         break;
491463      case 0x0A:   /* Right coordinate of foreground window
492464                   Bit 0-7 - Right coordinate of foreground window area
493465                */
494         wswan_vdp.window_fg_right = data;
466         state->vdp.window_fg_right = data;
495467         break;
496468      case 0x0B:   /* Bottom coordinate of foreground window
497469                   Bit 0-7 - Bottom coordinate of foreground window area
498470                */
499         wswan_vdp.window_fg_bottom = data;
471         state->vdp.window_fg_bottom = data;
500472         break;
501473      case 0x0C:   /* Left coordinate of sprite window
502474                   Bit 0-7 - Left coordinate of sprite window area
503475                */
504         wswan_vdp.window_sprites_left = data;
476         state->vdp.window_sprites_left = data;
505477         break;
506478      case 0x0D:   /* Top coordinate of sprite window
507479                   Bit 0-7 - Top coordinate of sprite window area
508480                */
509         wswan_vdp.window_sprites_top = data;
481         state->vdp.window_sprites_top = data;
510482         break;
511483      case 0x0E:   /* Right coordinate of sprite window
512484                   Bit 0-7 - Right coordinate of sprite window area
513485                */
514         wswan_vdp.window_sprites_right = data;
486         state->vdp.window_sprites_right = data;
515487         break;
516488      case 0x0F:   /* Bottom coordinate of sprite window
517489                   Bit 0-7 - Bottom coordiante of sprite window area
518490                */
519         wswan_vdp.window_sprites_bottom = data;
491         state->vdp.window_sprites_bottom = data;
520492         break;
521493      case 0x10:   /* Background layer X scroll
522494                   Bit 0-7 - Background layer X scroll
523495                */
524         wswan_vdp.layer_bg_scroll_x = data;
496         state->vdp.layer_bg_scroll_x = data;
525497         break;
526498      case 0x11:   /* Background layer Y scroll
527499                   Bit 0-7 - Background layer Y scroll
528500                */
529         wswan_vdp.layer_bg_scroll_y = data;
501         state->vdp.layer_bg_scroll_y = data;
530502         break;
531503      case 0x12:   /* Foreground layer X scroll
532504                   Bit 0-7 - Foreground layer X scroll
533505                */
534         wswan_vdp.layer_fg_scroll_x = data;
506         state->vdp.layer_fg_scroll_x = data;
535507         break;
536508      case 0x13:   /* Foreground layer Y scroll
537509                   Bit 0-7 - Foreground layer Y scroll
538510                */
539         wswan_vdp.layer_fg_scroll_y = data;
511         state->vdp.layer_fg_scroll_y = data;
540512         break;
541513      case 0x14:   /* LCD control
542514                   Bit 0   - LCD enable
543515                   Bit 1-7 - Unknown
544516                */
545         wswan_vdp.lcd_enable = data & 0x1;
517         state->vdp.lcd_enable = data & 0x1;
546518         break;
547519      case 0x15:   /* LCD icons
548520                   Bit 0   - LCD sleep icon enable
r9669r9670
553525                   Bit 5   - Dot 3 icon enable
554526                   Bit 6-7 - Unknown
555527                */
556         wswan_vdp.icons = data;   /* ummmmm */
528         state->vdp.icons = data;   /* ummmmm */
557529         break;
558530      case 0x1c:   /* Palette colors 0 and 1
559531                   Bit 0-3 - Gray tone setting for main palette index 0
560532                   Bit 4-7 - Gray tone setting for main palette index 1
561533                */
562         if ( system_type == TYPE_WSC )
534         if ( state->system_type == TYPE_WSC )
563535         {
564536            int i = 15 - ( data & 0x0F );
565537            int j = 15 - ( ( data & 0xF0 ) >> 4 );
566            wswan_vdp.main_palette[0] = ( i << 8 ) | ( i << 4 ) | i;
567            wswan_vdp.main_palette[1] = ( j << 8 ) | ( j << 4 ) | j;
538            state->vdp.main_palette[0] = ( i << 8 ) | ( i << 4 ) | i;
539            state->vdp.main_palette[1] = ( j << 8 ) | ( j << 4 ) | j;
568540         }
569541         else
570542         {
571            wswan_vdp.main_palette[0] = data & 0x0F;
572            wswan_vdp.main_palette[1] = ( data & 0xF0 ) >> 4;
543            state->vdp.main_palette[0] = data & 0x0F;
544            state->vdp.main_palette[1] = ( data & 0xF0 ) >> 4;
573545         }
574546         break;
575547      case 0x1d:   /* Palette colors 2 and 3
576548                   Bit 0-3 - Gray tone setting for main palette index 2
577549                   Bit 4-7 - Gray tone setting for main palette index 3
578550                */
579         if ( system_type == TYPE_WSC )
551         if ( state->system_type == TYPE_WSC )
580552         {
581553            int i = 15 - ( data & 0x0F );
582554            int j = 15 - ( ( data & 0xF0 ) >> 4 );
583            wswan_vdp.main_palette[2] = ( i << 8 ) | ( i << 4 ) | i;
584            wswan_vdp.main_palette[3] = ( j << 8 ) | ( j << 4 ) | j;
555            state->vdp.main_palette[2] = ( i << 8 ) | ( i << 4 ) | i;
556            state->vdp.main_palette[3] = ( j << 8 ) | ( j << 4 ) | j;
585557         }
586558         else
587559         {
588            wswan_vdp.main_palette[2] = data & 0x0F;
589            wswan_vdp.main_palette[3] = ( data & 0xF0 ) >> 4;
560            state->vdp.main_palette[2] = data & 0x0F;
561            state->vdp.main_palette[3] = ( data & 0xF0 ) >> 4;
590562         }
591563         break;
592564      case 0x1e:   /* Palette colors 4 and 5
593565                   Bit 0-3 - Gray tone setting for main palette index 4
594566                   Bit 4-7 - Gray tone setting for main paeltte index 5
595567                */
596         if ( system_type == TYPE_WSC )
568         if ( state->system_type == TYPE_WSC )
597569         {
598570            int i = 15 - ( data & 0x0F );
599571            int j = 15 - ( ( data & 0xF0 ) >> 4 );
600            wswan_vdp.main_palette[4] = ( i << 8 ) | ( i << 4 ) | i;
601            wswan_vdp.main_palette[5] = ( j << 8 ) | ( j << 4 ) | j;
572            state->vdp.main_palette[4] = ( i << 8 ) | ( i << 4 ) | i;
573            state->vdp.main_palette[5] = ( j << 8 ) | ( j << 4 ) | j;
602574         }
603575         else
604576         {
605            wswan_vdp.main_palette[4] = data & 0x0F;
606            wswan_vdp.main_palette[5] = ( data & 0xF0 ) >> 4;
577            state->vdp.main_palette[4] = data & 0x0F;
578            state->vdp.main_palette[5] = ( data & 0xF0 ) >> 4;
607579         }
608580         break;
609581      case 0x1f:   /* Palette colors 6 and 7
610582                   Bit 0-3 - Gray tone setting for main palette index 6
611583                   Bit 4-7 - Gray tone setting for main palette index 7
612584                */
613         if ( system_type == TYPE_WSC )
585         if ( state->system_type == TYPE_WSC )
614586         {
615587            int i = 15 - ( data & 0x0F );
616588            int j = 15 - ( ( data & 0xF0 ) >> 4 );
617            wswan_vdp.main_palette[6] = ( i << 8 ) | ( i << 4 ) | i;
618            wswan_vdp.main_palette[7] = ( j << 8 ) | ( j << 4 ) | j;
589            state->vdp.main_palette[6] = ( i << 8 ) | ( i << 4 ) | i;
590            state->vdp.main_palette[7] = ( j << 8 ) | ( j << 4 ) | j;
619591         }
620592         else
621593         {
622            wswan_vdp.main_palette[6] = data & 0x0F;
623            wswan_vdp.main_palette[7] = ( data & 0xF0 ) >> 4;
594            state->vdp.main_palette[6] = data & 0x0F;
595            state->vdp.main_palette[7] = ( data & 0xF0 ) >> 4;
624596         }
625597         break;
626598      case 0x20:   /* tile/sprite palette settings
r9669r9670
723695            UINT32 src, dst;
724696            UINT16 length;
725697
726            src = ws_portram[0x40] + (ws_portram[0x41] << 8) + (ws_portram[0x42] << 16);
727            dst = ws_portram[0x44] + (ws_portram[0x45] << 8) + (ws_portram[0x43] << 16);
728            length = ws_portram[0x46] + (ws_portram[0x47] << 8);
698            src = state->ws_portram[0x40] + (state->ws_portram[0x41] << 8) + (state->ws_portram[0x42] << 16);
699            dst = state->ws_portram[0x44] + (state->ws_portram[0x45] << 8) + (state->ws_portram[0x43] << 16);
700            length = state->ws_portram[0x46] + (state->ws_portram[0x47] << 8);
729701            for( ; length > 0; length-- )
730702            {
731703               space->write_byte(dst, space->read_byte(src ) );
r9669r9670
735707#ifdef DEBUG
736708               logerror( "DMA  src:%X dst:%X length:%d\n", src, dst, length );
737709#endif
738            ws_portram[0x40] = src & 0xFF;
739            ws_portram[0x41] = ( src >> 8 ) & 0xFF;
740            ws_portram[0x44] = dst & 0xFF;
741            ws_portram[0x45] = ( dst >> 8 ) & 0xFF;
742            ws_portram[0x46] = length & 0xFF;
743            ws_portram[0x47] = ( length >> 8 ) & 0xFF;
710            state->ws_portram[0x40] = src & 0xFF;
711            state->ws_portram[0x41] = ( src >> 8 ) & 0xFF;
712            state->ws_portram[0x44] = dst & 0xFF;
713            state->ws_portram[0x45] = ( dst >> 8 ) & 0xFF;
714            state->ws_portram[0x46] = length & 0xFF;
715            state->ws_portram[0x47] = ( length >> 8 ) & 0xFF;
744716            data &= 0x7F;
745717         }
746718         break;
747719      case 0x4A:   /* Sound DMA source address (low)
748720                   Bit 0-7 - Sound DMA source address bit 0-7
749721                */
750         sound_dma.source = ( sound_dma.source & 0x0FFF00 ) | data;
722         state->sound_dma.source = ( state->sound_dma.source & 0x0FFF00 ) | data;
751723         break;
752724      case 0x4B:   /* Sound DMA source address (high)
753725                   Bit 0-7 - Sound DMA source address bit 8-15
754726                */
755         sound_dma.source = ( sound_dma.source & 0x0F00FF ) | ( data << 8 );
727         state->sound_dma.source = ( state->sound_dma.source & 0x0F00FF ) | ( data << 8 );
756728         break;
757729      case 0x4C:   /* Sound DMA source memory segment
758730                   Bit 0-3 - Sound DMA source address segment
759731                   Bit 4-7 - Unknown
760732                */
761         sound_dma.source = ( sound_dma.source & 0xFFFF ) | ( ( data & 0x0F ) << 16 );
733         state->sound_dma.source = ( state->sound_dma.source & 0xFFFF ) | ( ( data & 0x0F ) << 16 );
762734         break;
763735      case 0x4D:   /* Unknown */
764736         break;
765737      case 0x4E:   /* Sound DMA transfer size (low)
766738                   Bit 0-7 - Sound DMA transfer size bit 0-7
767739                */
768         sound_dma.size = ( sound_dma.size & 0xFF00 ) | data;
740         state->sound_dma.size = ( state->sound_dma.size & 0xFF00 ) | data;
769741         break;
770742      case 0x4F:   /* Sound DMA transfer size (high)
771743                   Bit 0-7 - Sound DMA transfer size bit 8-15
772744                */
773         sound_dma.size = ( sound_dma.size & 0xFF ) | ( data << 8 );
745         state->sound_dma.size = ( state->sound_dma.size & 0xFF ) | ( data << 8 );
774746         break;
775747      case 0x50:   /* Unknown */
776748      case 0x51:   /* Unknown */
r9669r9670
779751                   Bit 0-6 - Unknown
780752                   Bit 7   - Sound DMA stop/start
781753                */
782         sound_dma.enable = data;
754         state->sound_dma.enable = data;
783755         break;
784756      case 0x60:   /* Video mode
785757                   Bit 0-4 - Unknown
r9669r9670
797769             * 001  - packed, 4 color, use 2000, monochrome
798770             * 000  - not packed, 4 color, use 2000, monochrome - Regular WS monochrome
799771             */
800         if ( system_type == TYPE_WSC )
772         if ( state->system_type == TYPE_WSC )
801773         {
802            wswan_vdp.color_mode = data & 0x80;
803            wswan_vdp.colors_16 = data & 0x40;
804            wswan_vdp.tile_packed = data & 0x20;
774            state->vdp.color_mode = data & 0x80;
775            state->vdp.colors_16 = data & 0x40;
776            state->vdp.tile_packed = data & 0x20;
805777         }
806778         break;
807779      case 0x80:   /* Audio 1 freq (lo)
r9669r9670
894866                   Bit 1   - Hardware type: 0 = WS, 1 = WSC
895867                   Bit 2-7 - Unknown
896868                */
897         if ( ( data & 0x01 ) && !wswan_bios_disabled )
869         if ( ( data & 0x01 ) && !state->bios_disabled )
898870         {
899            wswan_bios_disabled = 1;
900            memory_set_bankptr( space->machine, "bank15", ROMMap[ ( ( ( ws_portram[0xc0] & 0x0F ) << 4 ) | 15 ) & ( ROMBanks - 1 ) ] );
871            state->bios_disabled = 1;
872            memory_set_bankptr( space->machine, "bank15", state->ROMMap[ ( ( ( state->ws_portram[0xc0] & 0x0F ) << 4 ) | 15 ) & ( state->ROMBanks - 1 ) ] );
901873         }
902874         break;
903875      case 0xa2:   /* Timer control
r9669r9670
907879                   Bit 3   - VBlank Timer mode: 0 = one shot, 1 = auto reset
908880                   Bit 4-7 - Unknown
909881                */
910         wswan_vdp.timer_hblank_enable = data & 0x1;
911         wswan_vdp.timer_hblank_mode = (data & 0x2) >> 1;
912         wswan_vdp.timer_vblank_enable = (data & 0x4) >> 2;
913         wswan_vdp.timer_vblank_mode = (data & 0x8) >> 3;
882         state->vdp.timer_hblank_enable = data & 0x1;
883         state->vdp.timer_hblank_mode = (data & 0x2) >> 1;
884         state->vdp.timer_vblank_enable = (data & 0x4) >> 2;
885         state->vdp.timer_vblank_mode = (data & 0x8) >> 3;
914886         break;
915887      case 0xa4:   /* HBlank timer frequency (low) - reload value
916888                   Bit 0-7 - HBlank timer reload value bit 0-7
917889                */
918         wswan_vdp.timer_hblank_reload &= 0xff00;
919         wswan_vdp.timer_hblank_reload += data;
920         wswan_vdp.timer_hblank_count = wswan_vdp.timer_hblank_reload;
890         state->vdp.timer_hblank_reload &= 0xff00;
891         state->vdp.timer_hblank_reload += data;
892         state->vdp.timer_hblank_count = state->vdp.timer_hblank_reload;
921893         break;
922894      case 0xa5:   /* HBlank timer frequency (high) - reload value
923895                   Bit 8-15 - HBlank timer reload value bit 8-15
924896                */
925         wswan_vdp.timer_hblank_reload &= 0xff;
926         wswan_vdp.timer_hblank_reload += data << 8;
927         wswan_vdp.timer_hblank_count = wswan_vdp.timer_hblank_reload;
897         state->vdp.timer_hblank_reload &= 0xff;
898         state->vdp.timer_hblank_reload += data << 8;
899         state->vdp.timer_hblank_count = state->vdp.timer_hblank_reload;
928900         break;
929901      case 0xa6:   /* VBlank timer frequency (low) - reload value
930902                   Bit 0-7 - VBlank timer reload value bit 0-7
931903                */
932         wswan_vdp.timer_vblank_reload &= 0xff00;
933         wswan_vdp.timer_vblank_reload += data;
934         wswan_vdp.timer_vblank_count = wswan_vdp.timer_vblank_reload;
904         state->vdp.timer_vblank_reload &= 0xff00;
905         state->vdp.timer_vblank_reload += data;
906         state->vdp.timer_vblank_count = state->vdp.timer_vblank_reload;
935907         break;
936908      case 0xa7:   /* VBlank timer frequency (high) - reload value
937909                   Bit 0-7 - VBlank timer reload value bit 8-15
938910                */
939         wswan_vdp.timer_vblank_reload &= 0xff;
940         wswan_vdp.timer_vblank_reload += data << 8;
941         wswan_vdp.timer_vblank_count = wswan_vdp.timer_vblank_reload;
911         state->vdp.timer_vblank_reload &= 0xff;
912         state->vdp.timer_vblank_reload += data << 8;
913         state->vdp.timer_vblank_count = state->vdp.timer_vblank_reload;
942914         break;
943915      case 0xa8:   /* HBlank counter (low)
944916                   Bit 0-7 - HBlank counter bit 0-7
r9669r9670
983955                   bit 7   - Receive data interrupt generation
984956                */
985957//          data |= 0x02;
986         ws_portram[0xb1] = 0xFF;
958         state->ws_portram[0xb1] = 0xFF;
987959         if ( data & 0x80 )
988960         {
989//              ws_portram[0xb1] = 0x00;
961//              state->ws_portram[0xb1] = 0x00;
990962            data |= 0x04;
991963         }
992964         if (data & 0x20 )
r9669r9670
1027999                   Bit 7   - HBlank timer interrupt acknowledge
10281000                */
10291001         wswan_clear_irq_line( space->machine, data );
1030         data = ws_portram[0xB6];
1002         data = state->ws_portram[0xB6];
10311003         break;
10321004      case 0xba:   /* Internal EEPROM data (low)
10331005                   Bit 0-7 - Internal EEPROM data transfer bit 0-7
r9669r9670
10561028                */
10571029         if ( data & 0x20 )
10581030         {
1059            UINT16 addr = ( ( ( ws_portram[0xbd] << 8 ) | ws_portram[0xbc] ) << 1 ) & 0x1FF;
1060            internal_eeprom[ addr ] = ws_portram[0xba];
1061            internal_eeprom[ addr + 1 ] = ws_portram[0xbb];
1031            UINT16 addr = ( ( ( state->ws_portram[0xbd] << 8 ) | state->ws_portram[0xbc] ) << 1 ) & 0x1FF;
1032            state->internal_eeprom[ addr ] = state->ws_portram[0xba];
1033            state->internal_eeprom[ addr + 1 ] = state->ws_portram[0xbb];
10621034            data |= 0x02;
10631035         }
10641036         else if ( data & 0x10 )
10651037         {
1066            UINT16 addr = ( ( ( ws_portram[0xbd] << 8 ) | ws_portram[0xbc] ) << 1 ) & 0x1FF;
1067            ws_portram[0xba] = internal_eeprom[ addr ];
1068            ws_portram[0xbb] = internal_eeprom[ addr + 1];
1038            UINT16 addr = ( ( ( state->ws_portram[0xbd] << 8 ) | state->ws_portram[0xbc] ) << 1 ) & 0x1FF;
1039            state->ws_portram[0xba] = state->internal_eeprom[ addr ];
1040            state->ws_portram[0xbb] = state->internal_eeprom[ addr + 1];
10691041            data |= 0x01;
10701042         }
10711043         else
r9669r9670
10771049                   Bit 0-3 - ROM bank base register for banks 4-15
10781050                   Bit 4-7 - Unknown
10791051                */
1080         memory_set_bankptr( space->machine, "bank4", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 4 ) & ( ROMBanks - 1 ) ] );
1081         memory_set_bankptr( space->machine, "bank5", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 5 ) & ( ROMBanks - 1 ) ] );
1082         memory_set_bankptr( space->machine, "bank6", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 6 ) & ( ROMBanks - 1 ) ] );
1083         memory_set_bankptr( space->machine, "bank7", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 7 ) & ( ROMBanks - 1 ) ] );
1084         memory_set_bankptr( space->machine, "bank8", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 8 ) & ( ROMBanks - 1 ) ] );
1085         memory_set_bankptr( space->machine, "bank9", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 9 ) & ( ROMBanks - 1 ) ] );
1086         memory_set_bankptr( space->machine, "bank10", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 10 ) & ( ROMBanks - 1 ) ] );
1087         memory_set_bankptr( space->machine, "bank11", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 11 ) & ( ROMBanks - 1 ) ] );
1088         memory_set_bankptr( space->machine, "bank12", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 12 ) & ( ROMBanks - 1 ) ] );
1089         memory_set_bankptr( space->machine, "bank13", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 13 ) & ( ROMBanks - 1 ) ] );
1090         memory_set_bankptr( space->machine, "bank14", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 14 ) & ( ROMBanks - 1 ) ] );
1091         if ( wswan_bios_disabled )
1052         memory_set_bankptr( space->machine, "bank4", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 4 ) & ( state->ROMBanks - 1 ) ] );
1053         memory_set_bankptr( space->machine, "bank5", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 5 ) & ( state->ROMBanks - 1 ) ] );
1054         memory_set_bankptr( space->machine, "bank6", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 6 ) & ( state->ROMBanks - 1 ) ] );
1055         memory_set_bankptr( space->machine, "bank7", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 7 ) & ( state->ROMBanks - 1 ) ] );
1056         memory_set_bankptr( space->machine, "bank8", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 8 ) & ( state->ROMBanks - 1 ) ] );
1057         memory_set_bankptr( space->machine, "bank9", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 9 ) & ( state->ROMBanks - 1 ) ] );
1058         memory_set_bankptr( space->machine, "bank10", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 10 ) & ( state->ROMBanks - 1 ) ] );
1059         memory_set_bankptr( space->machine, "bank11", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 11 ) & ( state->ROMBanks - 1 ) ] );
1060         memory_set_bankptr( space->machine, "bank12", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 12 ) & ( state->ROMBanks - 1 ) ] );
1061         memory_set_bankptr( space->machine, "bank13", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 13 ) & ( state->ROMBanks - 1 ) ] );
1062         memory_set_bankptr( space->machine, "bank14", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 14 ) & ( state->ROMBanks - 1 ) ] );
1063         if ( state->bios_disabled )
10921064         {
1093            memory_set_bankptr( space->machine, "bank15", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 15 ) & ( ROMBanks - 1 ) ] );
1065            memory_set_bankptr( space->machine, "bank15", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 15 ) & ( state->ROMBanks - 1 ) ] );
10941066         }
10951067         break;
10961068      case 0xc1:   /* SRAM bank select
10971069                   Bit 0-7 - SRAM bank to select
10981070                */
1099         if ( eeprom.mode == SRAM_64K || eeprom.mode == SRAM_256K || eeprom.mode == SRAM_512K || eeprom.mode == SRAM_1M || eeprom.mode == SRAM_2M )
1071         if ( state->eeprom.mode == SRAM_64K || state->eeprom.mode == SRAM_256K || state->eeprom.mode == SRAM_512K || state->eeprom.mode == SRAM_1M || state->eeprom.mode == SRAM_2M )
11001072         {
1101            eeprom.page = &eeprom.data[ ( data * 64 * 1024 ) & ( eeprom.size - 1 ) ];
1073            state->eeprom.page = &state->eeprom.data[ ( data * 64 * 1024 ) & ( state->eeprom.size - 1 ) ];
11021074         }
11031075         break;
11041076      case 0xc2:   /* ROM bank select for segment 2 (0x20000 - 0x2ffff)
11051077                   Bit 0-7 - ROM bank for segment 2
11061078                */
1107         memory_set_bankptr( space->machine, "bank2", ROMMap[ data & ( ROMBanks - 1 ) ]);
1079         memory_set_bankptr( space->machine, "bank2", state->ROMMap[ data & ( state->ROMBanks - 1 ) ]);
11081080         break;
11091081      case 0xc3:   /* ROM bank select for segment 3 (0x30000-0x3ffff)
11101082                   Bit 0-7 - ROM bank for segment 3
11111083                */
1112         memory_set_bankptr( space->machine, "bank3", ROMMap[ data & ( ROMBanks - 1 ) ]);
1084         memory_set_bankptr( space->machine, "bank3", state->ROMMap[ data & ( state->ROMBanks - 1 ) ]);
11131085         break;
11141086      case 0xc6:   /* EEPROM address lower bits port/EEPROM address and command port
11151087                   1KBit EEPROM:
r9669r9670
11261098                   16KBit EEPROM:
11271099                   Bit 0-7 - EEPROM address bit 1-8
11281100                */
1129         switch( eeprom.mode )
1101         switch( state->eeprom.mode )
11301102         {
11311103         case EEPROM_1K:
1132            eeprom.address = data & 0x3F;
1133            eeprom.command = data >> 4;
1134            if ( ( eeprom.command & 0x0C ) != 0x00 )
1104            state->eeprom.address = data & 0x3F;
1105            state->eeprom.command = data >> 4;
1106            if ( ( state->eeprom.command & 0x0C ) != 0x00 )
11351107            {
1136               eeprom.command = eeprom.command & 0x0C;
1108               state->eeprom.command = state->eeprom.command & 0x0C;
11371109            }
11381110            break;
11391111         case EEPROM_16K:
1140            eeprom.address = ( eeprom.address & 0xFF00 ) | data;
1112            state->eeprom.address = ( state->eeprom.address & 0xFF00 ) | data;
11411113            break;
11421114         default:
11431115            logerror( "Write EEPROM address/register register C6 for unsupported EEPROM type\n" );
r9669r9670
11621134                   Bit 4   - Start
11631135                   Bit 5-7 - Unknown
11641136                */
1165         switch( eeprom.mode )
1137         switch( state->eeprom.mode )
11661138         {
11671139         case EEPROM_1K:
1168            eeprom.start = data & 0x01;
1140            state->eeprom.start = data & 0x01;
11691141            break;
11701142         case EEPROM_16K:
1171            eeprom.address = ( ( data & 0x03 ) << 8 ) | ( eeprom.address & 0xFF );
1172            eeprom.command = data & 0x0F;
1173            if ( ( eeprom.command & 0x0C ) != 0x00 )
1143            state->eeprom.address = ( ( data & 0x03 ) << 8 ) | ( state->eeprom.address & 0xFF );
1144            state->eeprom.command = data & 0x0F;
1145            if ( ( state->eeprom.command & 0x0C ) != 0x00 )
11741146            {
1175               eeprom.command = eeprom.command & 0x0C;
1147               state->eeprom.command = state->eeprom.command & 0x0C;
11761148            }
1177            eeprom.start = ( data >> 4 ) & 0x01;
1149            state->eeprom.start = ( data >> 4 ) & 0x01;
11781150            break;
11791151         default:
11801152            logerror( "Write EEPROM address/command register C7 for unsupported EEPROM type\n" );
r9669r9670
11901162                   Bit 6   - Protect
11911163                   Bit 7   - Initialize
11921164                */
1193         if ( eeprom.mode == EEPROM_1K || eeprom.mode == EEPROM_16K )
1165         if ( state->eeprom.mode == EEPROM_1K || state->eeprom.mode == EEPROM_16K )
11941166         {
11951167            if ( data & 0x80 )
11961168            {   /* Initialize */
r9669r9670
11981170            }
11991171            if ( data & 0x40 )
12001172            {   /* Protect */
1201               switch( eeprom.command )
1173               switch( state->eeprom.command )
12021174               {
12031175               case 0x00:
1204                  eeprom.write_enabled = 0;
1176                  state->eeprom.write_enabled = 0;
12051177                  data |= 0x02;
12061178                  break;
12071179               case 0x03:
1208                  eeprom.write_enabled = 1;
1180                  state->eeprom.write_enabled = 1;
12091181                  data |= 0x02;
12101182                  break;
12111183               default:
1212                  logerror( "Unsupported 'Protect' command %X\n", eeprom.command );
1184                  logerror( "Unsupported 'Protect' command %X\n", state->eeprom.command );
12131185               }
12141186            }
12151187            if ( data & 0x20 )
12161188            {   /* Write */
1217               if ( eeprom.write_enabled )
1189               if ( state->eeprom.write_enabled )
12181190               {
1219                  switch( eeprom.command )
1191                  switch( state->eeprom.command )
12201192                  {
12211193                  case 0x04:
1222                     eeprom.data[ ( eeprom.address << 1 ) + 1 ] = ws_portram[0xc4];
1223                     eeprom.data[ eeprom.address << 1 ] = ws_portram[0xc5];
1194                     state->eeprom.data[ ( state->eeprom.address << 1 ) + 1 ] = state->ws_portram[0xc4];
1195                     state->eeprom.data[ state->eeprom.address << 1 ] = state->ws_portram[0xc5];
12241196                     data |= 0x02;
12251197                     break;
12261198                  default:
1227                     logerror( "Unsupported 'Write' command %X\n", eeprom.command );
1199                     logerror( "Unsupported 'Write' command %X\n", state->eeprom.command );
12281200                  }
12291201               }
12301202            }
12311203            if ( data & 0x10 )
12321204            {   /* Read */
1233               ws_portram[0xc4] = eeprom.data[ ( eeprom.address << 1 ) + 1 ];
1234               ws_portram[0xc5] = eeprom.data[ eeprom.address << 1 ];
1205               state->ws_portram[0xc4] = state->eeprom.data[ ( state->eeprom.address << 1 ) + 1 ];
1206               state->ws_portram[0xc5] = state->eeprom.data[ state->eeprom.address << 1 ];
12351207               data |= 0x01;
12361208            }
12371209         }
r9669r9670
12531225         switch( data )
12541226         {
12551227         case 0x10:   /* Reset */
1256            rtc.index = 8;
1257            rtc.year = 0;
1258            rtc.month = 1;
1259            rtc.day = 1;
1260            rtc.day_of_week = 0;
1261            rtc.hour = 0;
1262            rtc.minute = 0;
1263            rtc.second = 0;
1264            rtc.setting = 0xFF;
1228            state->rtc.index = 8;
1229            state->rtc.year = 0;
1230            state->rtc.month = 1;
1231            state->rtc.day = 1;
1232            state->rtc.day_of_week = 0;
1233            state->rtc.hour = 0;
1234            state->rtc.minute = 0;
1235            state->rtc.second = 0;
1236            state->rtc.setting = 0xFF;
12651237            data |= 0x80;
12661238            break;
12671239         case 0x12:   /* Write Timer Settings (Alarm) */
1268            rtc.index = 8;
1269            rtc.setting = ws_portram[0xcb];
1240            state->rtc.index = 8;
1241            state->rtc.setting = state->ws_portram[0xcb];
12701242            data |= 0x80;
12711243            break;
12721244         case 0x13:   /* Read Timer Settings (Alarm) */
1273            rtc.index = 8;
1274            ws_portram[0xcb] = rtc.setting;
1245            state->rtc.index = 8;
1246            state->ws_portram[0xcb] = state->rtc.setting;
12751247            data |= 0x80;
12761248            break;
12771249         case 0x14:   /* Set Time/Date */
1278            rtc.year = ws_portram[0xcb];
1279            rtc.index = 1;
1250            state->rtc.year = state->ws_portram[0xcb];
1251            state->rtc.index = 1;
12801252            data |= 0x80;
12811253            break;
12821254         case 0x15:   /* Get Time/Date */
1283            rtc.index = 0;
1255            state->rtc.index = 0;
12841256            data |= 0x80;
1285            ws_portram[0xcb] = rtc.year;
1257            state->ws_portram[0xcb] = state->rtc.year;
12861258            break;
12871259         default:
12881260            logerror( "%X: Unknown RTC command (%X) requested\n", cpu_get_pc( space->cpu ), data );
12891261         }
12901262         break;
12911263      case 0xcb:   /* RTC Data */
1292         if ( ws_portram[0xca] == 0x94 && rtc.index < 7 )
1264         if ( state->ws_portram[0xca] == 0x94 && state->rtc.index < 7 )
12931265         {
1294            switch( rtc.index )
1266            switch( state->rtc.index )
12951267            {
1296            case 0:   rtc.year = data; break;
1297            case 1: rtc.month = data; break;
1298            case 2: rtc.day = data; break;
1299            case 3: rtc.day_of_week = data; break;
1300            case 4: rtc.hour = data; break;
1301            case 5: rtc.minute = data; break;
1302            case 6: rtc.second = data; break;
1268            case 0:   state->rtc.year = data; break;
1269            case 1: state->rtc.month = data; break;
1270            case 2: state->rtc.day = data; break;
1271            case 3: state->rtc.day_of_week = data; break;
1272            case 4: state->rtc.hour = data; break;
1273            case 5: state->rtc.minute = data; break;
1274            case 6: state->rtc.second = data; break;
13031275            }
1304            rtc.index++;
1276            state->rtc.index++;
13051277         }
13061278         break;
13071279      default:
r9669r9670
13101282   }
13111283
13121284   /* Update the port value */
1313   ws_portram[offset] = data;
1285   state->ws_portram[offset] = data;
13141286}
13151287
1316static const char* wswan_determine_sram( UINT8 data )
1288static const char* wswan_determine_sram( wswan_state *state, UINT8 data )
13171289{
1318   eeprom.write_enabled = 0;
1319   eeprom.mode = SRAM_UNKNOWN;
1290   state->eeprom.write_enabled = 0;
1291   state->eeprom.mode = SRAM_UNKNOWN;
13201292   switch( data )
13211293   {
1322   case 0x00: eeprom.mode = SRAM_NONE; break;
1323   case 0x01: eeprom.mode = SRAM_64K; break;
1324   case 0x02: eeprom.mode = SRAM_256K; break;
1325   case 0x03: eeprom.mode = SRAM_1M; break;
1326   case 0x04: eeprom.mode = SRAM_2M; break;
1327   case 0x05: eeprom.mode = SRAM_512K; break;
1328   case 0x10: eeprom.mode = EEPROM_1K; break;
1329   case 0x20: eeprom.mode = EEPROM_16K; break;
1330   case 0x50: eeprom.mode = EEPROM_8K; break;
1294   case 0x00: state->eeprom.mode = SRAM_NONE; break;
1295   case 0x01: state->eeprom.mode = SRAM_64K; break;
1296   case 0x02: state->eeprom.mode = SRAM_256K; break;
1297   case 0x03: state->eeprom.mode = SRAM_1M; break;
1298   case 0x04: state->eeprom.mode = SRAM_2M; break;
1299   case 0x05: state->eeprom.mode = SRAM_512K; break;
1300   case 0x10: state->eeprom.mode = EEPROM_1K; break;
1301   case 0x20: state->eeprom.mode = EEPROM_16K; break;
1302   case 0x50: state->eeprom.mode = EEPROM_8K; break;
13311303   }
1332   eeprom.size = wswan_sram_size[ eeprom.mode ];
1333   return wswan_sram_str[ eeprom.mode ];
1304   state->eeprom.size = wswan_sram_size[ state->eeprom.mode ];
1305   return wswan_sram_str[ state->eeprom.mode ];
13341306}
13351307
13361308enum enum_romsize { ROM_4M=0, ROM_8M, ROM_16M, ROM_32M, ROM_64M, ROM_128M, ROM_UNKNOWN };
r9669r9670
13541326
13551327DEVICE_START(wswan_cart)
13561328{
1329   wswan_state *state = device->machine->driver_data<wswan_state>();
13571330   /* Initialize EEPROM structure */
1358   memset( &eeprom, 0, sizeof( eeprom ) );
1359   eeprom.data = NULL;
1360   eeprom.page = NULL;
1331   memset( &state->eeprom, 0, sizeof( state->eeprom ) );
1332   state->eeprom.data = NULL;
1333   state->eeprom.page = NULL;
13611334
13621335   /* Initialize RTC structure */
1363   rtc.present = 0;
1364   rtc.index = 0;
1365   rtc.year = 0;
1366   rtc.month = 0;
1367   rtc.day = 0;
1368   rtc.day_of_week = 0;
1369   rtc.hour = 0;
1370   rtc.minute = 0;
1371   rtc.second = 0;
1372   rtc.setting = 0xFF;
1336   state->rtc.present = 0;
1337   state->rtc.index = 0;
1338   state->rtc.year = 0;
1339   state->rtc.month = 0;
1340   state->rtc.day = 0;
1341   state->rtc.day_of_week = 0;
1342   state->rtc.hour = 0;
1343   state->rtc.minute = 0;
1344   state->rtc.second = 0;
1345   state->rtc.setting = 0xFF;
13731346}
13741347
13751348DEVICE_IMAGE_LOAD(wswan_cart)
13761349{
1350   wswan_state *state = image.device().machine->driver_data<wswan_state>();
13771351   UINT32 ii, size;
13781352   const char *sram_str;
13791353
r9669r9670
13821356   else
13831357      size = image.get_software_region_length("rom");
13841358
1385   ws_ram = (UINT8*) cputag_get_address_space(image.device().machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(0);
1386   memset(ws_ram, 0, 0xffff);
1387   ROMBanks = size / 65536;
1359   state->ws_ram = (UINT8*) cputag_get_address_space(image.device().machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(0);
1360   memset(state->ws_ram, 0, 0xffff);
1361   state->ROMBanks = size / 65536;
13881362
1389   for (ii = 0; ii < ROMBanks; ii++)
1363   for (ii = 0; ii < state->ROMBanks; ii++)
13901364   {
1391      if ((ROMMap[ii] = auto_alloc_array(image.device().machine, UINT8, 0x10000)))
1365      if ((state->ROMMap[ii] = auto_alloc_array(image.device().machine, UINT8, 0x10000)))
13921366      {
13931367         if (image.software_entry() == NULL)
13941368         {
1395            if (image.fread( ROMMap[ii], 0x10000) != 0x10000)
1369            if (image.fread( state->ROMMap[ii], 0x10000) != 0x10000)
13961370            {
13971371               logerror("Error while reading loading rom!\n");
13981372               return IMAGE_INIT_FAIL;
13991373            }
14001374         }
14011375         else
1402            memcpy(ROMMap[ii], image.get_software_region("rom") + ii * 0x10000, 0x10000);
1376            memcpy(state->ROMMap[ii], image.get_software_region("rom") + ii * 0x10000, 0x10000);
14031377      }
14041378      else
14051379      {
r9669r9670
14081382      }
14091383   }
14101384
1411   sram_str = wswan_determine_sram(ROMMap[ROMBanks - 1][0xfffb]);
1385   sram_str = wswan_determine_sram(state, state->ROMMap[state->ROMBanks - 1][0xfffb]);
14121386
1413   rtc.present = ROMMap[ROMBanks - 1][0xfffd] ? 1 : 0;
1387   state->rtc.present = state->ROMMap[state->ROMBanks - 1][0xfffd] ? 1 : 0;
14141388
14151389   {
14161390      int sum = 0;
14171391      /* Spit out some info */
14181392      logerror("ROM DETAILS\n" );
1419      logerror("\tDeveloper ID: %X\n", ROMMap[ROMBanks - 1][0xfff6]);
1420      logerror("\tMinimum system: %s\n", ROMMap[ROMBanks - 1][0xfff7] ? "WonderSwan Color" : "WonderSwan");
1421      logerror("\tCart ID: %X\n", ROMMap[ROMBanks - 1][0xfff8]);
1422      logerror("\tROM size: %s\n", wswan_determine_romsize(ROMMap[ROMBanks - 1][0xfffa]));
1393      logerror("\tDeveloper ID: %X\n", state->ROMMap[state->ROMBanks - 1][0xfff6]);
1394      logerror("\tMinimum system: %s\n", state->ROMMap[state->ROMBanks - 1][0xfff7] ? "WonderSwan Color" : "WonderSwan");
1395      logerror("\tCart ID: %X\n", state->ROMMap[state->ROMBanks - 1][0xfff8]);
1396      logerror("\tROM size: %s\n", wswan_determine_romsize(state->ROMMap[state->ROMBanks - 1][0xfffa]));
14231397      logerror("\tSRAM size: %s\n", sram_str);
1424      logerror("\tFeatures: %X\n", ROMMap[ROMBanks - 1][0xfffc]);
1425      logerror("\tRTC: %s\n", ROMMap[ROMBanks - 1][0xfffd] ? "yes" : "no");
1426      for (ii = 0; ii < ROMBanks; ii++)
1398      logerror("\tFeatures: %X\n", state->ROMMap[state->ROMBanks - 1][0xfffc]);
1399      logerror("\tRTC: %s\n", state->ROMMap[state->ROMBanks - 1][0xfffd] ? "yes" : "no");
1400      for (ii = 0; ii < state->ROMBanks; ii++)
14271401      {
14281402         int count;
14291403         for (count = 0; count < 0x10000; count++)
14301404         {
1431            sum += ROMMap[ii][count];
1405            sum += state->ROMMap[ii][count];
14321406         }
14331407      }
1434      sum -= ROMMap[ROMBanks - 1][0xffff];
1435      sum -= ROMMap[ROMBanks - 1][0xfffe];
1408      sum -= state->ROMMap[state->ROMBanks - 1][0xffff];
1409      sum -= state->ROMMap[state->ROMBanks - 1][0xfffe];
14361410      sum &= 0xffff;
1437      logerror("\tChecksum: %X%X (calculated: %04X)\n", ROMMap[ROMBanks - 1][0xffff], ROMMap[ROMBanks - 1][0xfffe], sum);
1411      logerror("\tChecksum: %X%X (calculated: %04X)\n", state->ROMMap[state->ROMBanks - 1][0xffff], state->ROMMap[state->ROMBanks - 1][0xfffe], sum);
14381412   }
14391413
1440   if (eeprom.size != 0)
1414   if (state->eeprom.size != 0)
14411415   {
1442      eeprom.data = auto_alloc_array(image.device().machine, UINT8, eeprom.size);
1443      image.battery_load(eeprom.data, eeprom.size, 0x00);
1444      eeprom.page = eeprom.data;
1416      state->eeprom.data = auto_alloc_array(image.device().machine, UINT8, state->eeprom.size);
1417      image.battery_load(state->eeprom.data, state->eeprom.size, 0x00);
1418      state->eeprom.page = state->eeprom.data;
14451419   }
14461420
14471421   if (image.software_entry() == NULL)
r9669r9670
14571431
14581432static TIMER_CALLBACK(wswan_scanline_interrupt)
14591433{
1460   if( wswan_vdp.current_line < 144 )
1434   wswan_state *state = machine->driver_data<wswan_state>();
1435   if( state->vdp.current_line < 144 )
14611436   {
14621437      wswan_refresh_scanline(machine);
14631438   }
14641439
14651440   /* Decrement 12kHz (HBlank) counter */
1466   if ( wswan_vdp.timer_hblank_enable && wswan_vdp.timer_hblank_reload != 0 )
1441   if ( state->vdp.timer_hblank_enable && state->vdp.timer_hblank_reload != 0 )
14671442   {
1468      wswan_vdp.timer_hblank_count--;
1469      logerror( "timer_hblank_count: %X\n", wswan_vdp.timer_hblank_count );
1470      if ( wswan_vdp.timer_hblank_count == 0 )
1443      state->vdp.timer_hblank_count--;
1444      logerror( "timer_hblank_count: %X\n", state->vdp.timer_hblank_count );
1445      if ( state->vdp.timer_hblank_count == 0 )
14711446      {
1472         if ( wswan_vdp.timer_hblank_mode )
1447         if ( state->vdp.timer_hblank_mode )
14731448         {
1474            wswan_vdp.timer_hblank_count = wswan_vdp.timer_hblank_reload;
1449            state->vdp.timer_hblank_count = state->vdp.timer_hblank_reload;
14751450         }
14761451         else
14771452         {
1478            wswan_vdp.timer_hblank_reload = 0;
1453            state->vdp.timer_hblank_reload = 0;
14791454         }
14801455         logerror( "trigerring hbltmr interrupt\n" );
14811456         wswan_set_irq_line( machine, WSWAN_IFLAG_HBLTMR );
r9669r9670
14831458   }
14841459
14851460   /* Handle Sound DMA */
1486   if ( ( sound_dma.enable & 0x88 ) == 0x80 )
1461   if ( ( state->sound_dma.enable & 0x88 ) == 0x80 )
14871462   {
14881463      address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM );
14891464      /* TODO: Output sound DMA byte */
1490      wswan_port_w( space, 0x89, space->read_byte(sound_dma.source ) );
1491      sound_dma.size--;
1492      sound_dma.source = ( sound_dma.source + 1 ) & 0x0FFFFF;
1493      if ( sound_dma.size == 0 )
1465      wswan_port_w( space, 0x89, space->read_byte(state->sound_dma.source ) );
1466      state->sound_dma.size--;
1467      state->sound_dma.source = ( state->sound_dma.source + 1 ) & 0x0FFFFF;
1468      if ( state->sound_dma.size == 0 )
14941469      {
1495         sound_dma.enable &= 0x7F;
1470         state->sound_dma.enable &= 0x7F;
14961471      }
14971472   }
14981473
1499//  wswan_vdp.current_line = (wswan_vdp.current_line + 1) % 159;
1474//  state->vdp.current_line = (state->vdp.current_line + 1) % 159;
15001475
1501   if( wswan_vdp.current_line == 144 )
1476   if( state->vdp.current_line == 144 )
15021477   {
15031478      wswan_set_irq_line( machine, WSWAN_IFLAG_VBL );
15041479      /* Decrement 75Hz (VBlank) counter */
1505      if ( wswan_vdp.timer_vblank_enable && wswan_vdp.timer_vblank_reload != 0 )
1480      if ( state->vdp.timer_vblank_enable && state->vdp.timer_vblank_reload != 0 )
15061481      {
1507         wswan_vdp.timer_vblank_count--;
1508         logerror( "timer_vblank_count: %X\n", wswan_vdp.timer_vblank_count );
1509         if ( wswan_vdp.timer_vblank_count == 0 )
1482         state->vdp.timer_vblank_count--;
1483         logerror( "timer_vblank_count: %X\n", state->vdp.timer_vblank_count );
1484         if ( state->vdp.timer_vblank_count == 0 )
15101485         {
1511            if ( wswan_vdp.timer_vblank_mode )
1486            if ( state->vdp.timer_vblank_mode )
15121487            {
1513               wswan_vdp.timer_vblank_count = wswan_vdp.timer_vblank_reload;
1488               state->vdp.timer_vblank_count = state->vdp.timer_vblank_reload;
15141489            }
15151490            else
15161491            {
1517               wswan_vdp.timer_vblank_reload = 0;
1492               state->vdp.timer_vblank_reload = 0;
15181493            }
15191494            logerror( "triggering vbltmr interrupt\n" );
15201495            wswan_set_irq_line( machine, WSWAN_IFLAG_VBLTMR );
r9669r9670
15221497      }
15231498   }
15241499
1525//  wswan_vdp.current_line = (wswan_vdp.current_line + 1) % 159;
1500//  state->vdp.current_line = (state->vdp.current_line + 1) % 159;
15261501
1527   if ( wswan_vdp.current_line == wswan_vdp.line_compare )
1502   if ( state->vdp.current_line == state->vdp.line_compare )
15281503   {
15291504      wswan_set_irq_line( machine, WSWAN_IFLAG_LCMP );
15301505   }
15311506
1532   wswan_vdp.current_line = (wswan_vdp.current_line + 1) % 159;
1507   state->vdp.current_line = (state->vdp.current_line + 1) % 159;
15331508
1534   if ( wswan_vdp.current_line == 0 )
1509   if ( state->vdp.current_line == 0 )
15351510   {
1536      if ( wswan_vdp.display_vertical != wswan_vdp.new_display_vertical )
1511      if ( state->vdp.display_vertical != state->vdp.new_display_vertical )
15371512      {
1538         wswan_vdp.display_vertical = wswan_vdp.new_display_vertical;
1539         if ( wswan_vdp.display_vertical )
1513         state->vdp.display_vertical = state->vdp.new_display_vertical;
1514         if ( state->vdp.display_vertical )
15401515         {
15411516            machine->primary_screen->set_visible_area(5*8, 5*8 + WSWAN_Y_PIXELS - 1, 0, WSWAN_X_PIXELS - 1 );
15421517         }
src/mess/machine/zx.c
r9669r9670
2222#define LOG_ZX81_IOW(_comment) do { if (DEBUG_ZX81_PORTS) logerror("ZX81 IOW: %04x, Data: %02x, Scanline: %d (%s)\n", offset, data, space->machine->primary_screen->vpos(), _comment); } while (0)
2323#define LOG_ZX81_VSYNC do { if (DEBUG_ZX81_VSYNC) logerror("VSYNC starts in scanline: %d\n", space->machine->primary_screen->vpos()); } while (0)
2424
25static UINT8 zx_tape_bit;
2625
2726static WRITE8_HANDLER( zx_ram_w )
2827{
r9669r9670
8079
8180MACHINE_RESET ( zx80 )
8281{
82   zx_state *state = machine->driver_data<zx_state>();
8383   cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(zx_setdirect, *machine));
84   zx_tape_bit = 0x80;
84   state->tape_bit = 0x80;
8585}
8686
8787MACHINE_RESET ( pow3000 )
8888{
89   zx_state *state = machine->driver_data<zx_state>();
8990   cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(pow3000_setdirect, *machine));
90   zx_tape_bit = 0x80;
91   state->tape_bit = 0x80;
9192}
9293
9394MACHINE_RESET ( pc8300 )
9495{
96   zx_state *state = machine->driver_data<zx_state>();
9597   cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(pc8300_setdirect, *machine));
96   zx_tape_bit = 0x80;
98   state->tape_bit = 0x80;
9799}
98100
99101static TIMER_CALLBACK(zx_tape_pulse)
100102{
101   zx_tape_bit = 0x80;
103   zx_state *state = machine->driver_data<zx_state>();
104   state->tape_bit = 0x80;
102105}
103106
104107READ8_HANDLER ( zx80_io_r )
105108{
109   zx_state *state = space->machine->driver_data<zx_state>();
106110/* port FE = read keyboard, NTSC/PAL diode, and cass bit; turn off HSYNC-generator/cass-out
107111    The upper 8 bits are used to select a keyboard scan line
108112
r9669r9670
135139
136140      cassette_output(space->machine->device("cassette"), +0.75);
137141
138      if (ula_irq_active)
142      if (state->ula_irq_active)
139143      {
140144         zx_ula_bkgnd(space->machine, 0);
141         ula_irq_active = 0;
145         state->ula_irq_active = 0;
142146
143147//          LOG_ZX81_IOR("ULA IRQs off");
144148      }
145149//      else
146150//      {
147         if ((cassette_input(space->machine->device("cassette")) < -0.75) && zx_tape_bit)
151         if ((cassette_input(space->machine->device("cassette")) < -0.75) && state->tape_bit)
148152         {
149            zx_tape_bit = 0x00;
153            state->tape_bit = 0x00;
150154            timer_set(space->machine, ATTOTIME_IN_USEC(362), NULL, 0, zx_tape_pulse);
151155         }
152156
153         data &= ~zx_tape_bit;
157         data &= ~state->tape_bit;
154158
155159//          LOG_ZX81_IOR("Tape");
156160//      }
157      if (ula_frame_vsync == 3)
161      if (state->ula_frame_vsync == 3)
158162      {
159         ula_frame_vsync = 2;
163         state->ula_frame_vsync = 2;
160164//          LOG_ZX81_VSYNC;
161165      }
162166   }
r9669r9670
168172
169173READ8_HANDLER ( zx81_io_r )
170174{
175   zx_state *state = space->machine->driver_data<zx_state>();
171176/* port FB = read printer status, not emulated
172177    FE = read keyboard, NTSC/PAL diode, and cass bit; turn off HSYNC-generator/cass-out
173178    The upper 8 bits are used to select a keyboard scan line */
r9669r9670
199204
200205      cassette_output(space->machine->device("cassette"), +0.75);
201206
202      if (ula_irq_active)
207      if (state->ula_irq_active)
203208      {
204209         zx_ula_bkgnd(space->machine, 0);
205         ula_irq_active = 0;
210         state->ula_irq_active = 0;
206211
207212//          LOG_ZX81_IOR("ULA IRQs off");
208213      }
209214      else
210215      {
211         if ((cassette_input(space->machine->device("cassette")) < -0.75) && zx_tape_bit)
216         if ((cassette_input(space->machine->device("cassette")) < -0.75) && state->tape_bit)
212217         {
213            zx_tape_bit = 0x00;
218            state->tape_bit = 0x00;
214219            timer_set(space->machine, ATTOTIME_IN_USEC(362), NULL, 0, zx_tape_pulse);
215220         }
216221
217         data &= ~zx_tape_bit;
222         data &= ~state->tape_bit;
218223
219224//          LOG_ZX81_IOR("Tape");
220225      }
221      if (ula_frame_vsync == 3)
226      if (state->ula_frame_vsync == 3)
222227      {
223         ula_frame_vsync = 2;
228         state->ula_frame_vsync = 2;
224229//          LOG_ZX81_VSYNC;
225230      }
226231   }
r9669r9670
232237
233238READ8_HANDLER ( pc8300_io_r )
234239{
240   zx_state *state = space->machine->driver_data<zx_state>();
235241/* port F5 = sound
236242    F6 = unknown
237243    FB = read printer status, not emulated
r9669r9670
241247
242248   UINT8 data = 0xff;
243249   UINT8 offs = offset & 0xff;
244   static UINT8 speaker_state = 0;
245250   running_device *speaker = space->machine->device("speaker");
246251
247252   if (offs == 0xf5)
248253   {
249      speaker_state ^= 1;
250      speaker_level_w(speaker, speaker_state);
254      state->speaker_state ^= 1;
255      speaker_level_w(speaker, state->speaker_state);
251256   }
252257   else
253258   if (offs == 0xfe)
r9669r9670
271276
272277      cassette_output(space->machine->device("cassette"), +0.75);
273278
274      if (ula_irq_active)
279      if (state->ula_irq_active)
275280      {
276281         zx_ula_bkgnd(space->machine, 0);
277         ula_irq_active = 0;
282         state->ula_irq_active = 0;
278283
279284//          LOG_ZX81_IOR("ULA IRQs off");
280285      }
281286      else
282287      {
283         if ((cassette_input(space->machine->device("cassette")) < -0.75) && zx_tape_bit)
288         if ((cassette_input(space->machine->device("cassette")) < -0.75) && state->tape_bit)
284289         {
285            zx_tape_bit = 0x00;
290            state->tape_bit = 0x00;
286291            timer_set(space->machine, ATTOTIME_IN_USEC(362), NULL, 0, zx_tape_pulse);
287292         }
288293
289         data &= ~zx_tape_bit;
294         data &= ~state->tape_bit;
290295
291296//          LOG_ZX81_IOR("Tape");
292297      }
293      if (ula_frame_vsync == 3)
298      if (state->ula_frame_vsync == 3)
294299      {
295         ula_frame_vsync = 2;
300         state->ula_frame_vsync = 2;
296301//          LOG_ZX81_VSYNC;
297302      }
298303   }
r9669r9670
304309
305310READ8_HANDLER ( pow3000_io_r )
306311{
312   zx_state *state = space->machine->driver_data<zx_state>();
307313/* port 7E = read NTSC/PAL diode
308314    F5 = sound
309315    F6 = unknown
r9669r9670
313319
314320   UINT8 data = 0xff;
315321   UINT8 offs = offset & 0xff;
316   static UINT8 speaker_state = 0;
317322   running_device *speaker = space->machine->device("speaker");
318323
319324   if (offs == 0x7e)
r9669r9670
323328   else
324329   if (offs == 0xf5)
325330   {
326      speaker_state ^= 1;
327      speaker_level_w(speaker, speaker_state);
331      state->speaker_state ^= 1;
332      speaker_level_w(speaker, state->speaker_state);
328333   }
329334   else
330335   if (offs == 0xfe)
r9669r9670
348353
349354      cassette_output(space->machine->device("cassette"), +0.75);
350355
351      if (ula_irq_active)
356      if (state->ula_irq_active)
352357      {
353358         zx_ula_bkgnd(space->machine, 0);
354         ula_irq_active = 0;
359         state->ula_irq_active = 0;
355360         LOG_ZX81_IOR("ULA IRQs off");
356361      }
357362      else
358363      {
359         if ((cassette_input(space->machine->device("cassette")) < -0.75) && zx_tape_bit)
364         if ((cassette_input(space->machine->device("cassette")) < -0.75) && state->tape_bit)
360365         {
361            zx_tape_bit = 0x00;
366            state->tape_bit = 0x00;
362367            timer_set(space->machine, ATTOTIME_IN_USEC(362), NULL, 0, zx_tape_pulse);
363368         }
364369
365         data &= ~zx_tape_bit;
370         data &= ~state->tape_bit;
366371
367372//          LOG_ZX81_IOR("Tape");
368373      }
369      if (ula_frame_vsync == 3)
374      if (state->ula_frame_vsync == 3)
370375      {
371         ula_frame_vsync = 2;
376         state->ula_frame_vsync = 2;
372377//          LOG_ZX81_VSYNC;
373378      }
374379   }
r9669r9670
392397
393398WRITE8_HANDLER ( zx81_io_w )
394399{
400   zx_state *state = space->machine->driver_data<zx_state>();
395401/* port F5 = unknown, pc8300/pow3000/lambda only
396402    F6 = unknown, pc8300/pow3000/lambda only
397403    FB = write data to printer, not emulated
r9669r9670
405411
406412   if (offs == 0xfd)
407413   {
408      timer_reset(ula_nmi, attotime_never);
414      timer_reset(state->ula_nmi, attotime_never);
409415
410416      LOG_ZX81_IOW("ULA NMIs off");
411417   }
412418   else
413419   if (offs == 0xfe)
414420   {
415      timer_adjust_periodic(ula_nmi, attotime_zero, 0, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime(207));
421      timer_adjust_periodic(state->ula_nmi, attotime_zero, 0, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime(207));
416422
417423      LOG_ZX81_IOW("ULA NMIs on");
418424
419425      /* remove the IRQ */
420      ula_irq_active = 0;
426      state->ula_irq_active = 0;
421427   }
422428   else
423429   if (offs == 0xff)
424430   {
425431      cassette_output(space->machine->device("cassette"), -0.75);
426432      zx_ula_bkgnd(space->machine, 1);
427      if (ula_frame_vsync == 2)
433      if (state->ula_frame_vsync == 2)
428434      {
429435         cpu_spinuntil_time(space->cpu,space->machine->primary_screen->time_until_pos(height - 1, 0));
430         ula_scanline_count = height - 1;
436         state->ula_scanline_count = height - 1;
431437         logerror ("S: %d B: %d\n", space->machine->primary_screen->vpos(), space->machine->primary_screen->hpos());
432438      }
433439
src/mess/machine/z80ne.c
r9669r9670
2525#define VERBOSE 0
2626#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
2727
28static UINT8 lx383_scan_counter;
29static UINT8 lx383_key[LX383_KEYS];
30static int   lx383_downsampler;
31static int   nmi_delay_counter;
32static int   reset_delay_counter;
33static running_device *z80ne_ay31015;
34static UINT8 lx385_ctrl;
35static running_device *lx388_kr2376;
3628
3729
3830
3931
4032/* timer to read cassette waveforms */
41static emu_timer *cassette_timer;
4233
43/* wave duration threshold */
44typedef enum
45{
46   TAPE_300BPS  = 300, /*  300 bps */
47   TAPE_600BPS  = 600, /*  600 bps */
48   TAPE_1200BPS = 1200 /* 1200 bps */
49} z80netape_speed;
50
51static struct {
52   struct {
53      int length;      /* time cassette level is at input.level */
54      int level;      /* cassette level */
55      int bit;      /* bit being read */
56   } input;
57   struct {
58      int length;      /* time cassette level is at output.level */
59      int level;      /* cassette level */
60      int bit;      /* bit to to output */
61   } output;
62   z80netape_speed speed;         /* 300 - 600 - 1200 */
63   int wave_filter;
64   int wave_length;
65   int wave_short;
66   int wave_long;
67} cass_data;
68
69static struct _wd17xx_state {
70   int drq;
71   int intrq;
72   UINT8 drive; /* current drive */
73   UINT8 head;  /* current head */
74} wd17xx_state;
75
7634static running_device *cassette_device_image(running_machine *machine)
7735{
78   if (lx385_ctrl & 0x08)
36   z80ne_state *state = machine->driver_data<z80ne_state>();
37   if (state->lx385_ctrl & 0x08)
7938      return machine->device("cassetteb");
8039   else
8140      return machine->device("cassettea");
r9669r9670
8342
8443static TIMER_CALLBACK(z80ne_cassette_tc)
8544{
45   z80ne_state *state = machine->driver_data<z80ne_state>();
8646   UINT8 cass_ws = 0;
87   cass_data.input.length++;
47   state->cass_data.input.length++;
8848
8949   cass_ws = (cassette_input(cassette_device_image(machine)) > +0.02) ? 1 : 0;
9050
91   if ((cass_ws ^ cass_data.input.level) & cass_ws)
51   if ((cass_ws ^ state->cass_data.input.level) & cass_ws)
9252   {
93      cass_data.input.level = cass_ws;
94      cass_data.input.bit = ((cass_data.input.length < cass_data.wave_filter) || (cass_data.input.length > 0x20)) ? 1 : 0;
95      cass_data.input.length = 0;
96      ay31015_set_input_pin( z80ne_ay31015, AY31015_SI, cass_data.input.bit );
53      state->cass_data.input.level = cass_ws;
54      state->cass_data.input.bit = ((state->cass_data.input.length < state->cass_data.wave_filter) || (state->cass_data.input.length > 0x20)) ? 1 : 0;
55      state->cass_data.input.length = 0;
56      ay31015_set_input_pin( state->ay31015, AY31015_SI, state->cass_data.input.bit );
9757   }
98   cass_data.input.level = cass_ws;
58   state->cass_data.input.level = cass_ws;
9959
10060   /* saving a tape - convert the serial stream from the uart */
10161
102   cass_data.output.length--;
62   state->cass_data.output.length--;
10363
104   if (!(cass_data.output.length))
64   if (!(state->cass_data.output.length))
10565   {
106      if (cass_data.output.level)
107         cass_data.output.level = 0;
66      if (state->cass_data.output.level)
67         state->cass_data.output.level = 0;
10868      else
10969      {
110         cass_data.output.level=1;
111         cass_ws = ay31015_get_output_pin( z80ne_ay31015, AY31015_SO );
112         cass_data.wave_length = cass_ws ? cass_data.wave_short : cass_data.wave_long;
70         state->cass_data.output.level=1;
71         cass_ws = ay31015_get_output_pin( state->ay31015, AY31015_SO );
72         state->cass_data.wave_length = cass_ws ? state->cass_data.wave_short : state->cass_data.wave_long;
11373      }
114      cassette_output(cassette_device_image(machine), cass_data.output.level ? -1.0 : +1.0);
115      cass_data.output.length = cass_data.wave_length;
74      cassette_output(cassette_device_image(machine), state->cass_data.output.level ? -1.0 : +1.0);
75      state->cass_data.output.length = state->cass_data.wave_length;
11676   }
11777}
11878
r9669r9670
157117
158118static TIMER_CALLBACK( z80ne_kbd_scan )
159119{
120   z80ne_state *state = machine->driver_data<z80ne_state>();
160121   /*
161122     * NE555 is connected to a 74LS93 binary counter
162123     * 74LS93 output:
r9669r9670
181142   UINT8 i;
182143
183144   /* 4-bit counter */
184   --lx383_scan_counter;
185   lx383_scan_counter &= 0x0f;
145   --state->lx383_scan_counter;
146   state->lx383_scan_counter &= 0x0f;
186147
187   if ( --lx383_downsampler == 0 )
148   if ( --state->lx383_downsampler == 0 )
188149   {
189      lx383_downsampler = LX383_DOWNSAMPLING;
150      state->lx383_downsampler = LX383_DOWNSAMPLING;
190151      key_bits = (input_port_read(machine, "ROW1") << 8) | input_port_read(machine, "ROW0");
191152      rst = input_port_read(machine, "RST");
192153      ctrl = input_port_read(machine, "CTRL");
193154
194155      for ( i = 0; i<LX383_KEYS; i++)
195156      {
196         lx383_key[i] = ( i | (key_bits & 0x01 ? 0x80 : 0x00) | ~ctrl);
157         state->lx383_key[i] = ( i | (key_bits & 0x01 ? 0x80 : 0x00) | ~ctrl);
197158         key_bits >>= 1;
198159      }
199160   }
r9669r9670
208169 */
209170DIRECT_UPDATE_HANDLER( z80ne_nmi_delay_count )
210171{
211   nmi_delay_counter--;
172   z80ne_state *state = machine->driver_data<z80ne_state>();
173   state->nmi_delay_counter--;
212174
213   if (!nmi_delay_counter)
175   if (!state->nmi_delay_counter)
214176   {
215177      cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(z80ne_default, *machine));
216178      cputag_set_input_line(machine, "z80ne", INPUT_LINE_NMI, PULSE_LINE);
r9669r9670
224186 */
225187DIRECT_UPDATE_HANDLER( z80ne_reset_delay_count )
226188{
189   z80ne_state *state = machine->driver_data<z80ne_state>();
227190   address_space *space = cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM);
228191   /*
229192     * TODO: when debugger is active, his memory access causes this callback
230193     *
231194     */
232195   if(!space->debugger_access())
233      reset_delay_counter--;
196      state->reset_delay_counter--;
234197
235   if (!reset_delay_counter)
198   if (!state->reset_delay_counter)
236199   {
237200      /* remove this callback */
238201      cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(z80ne_default, *machine));
r9669r9670
244207
245208static void reset_lx388(running_machine *machine)
246209{
247   lx388_kr2376 = machine->device("lx388_kr2376");
248   kr2376_set_input_pin( lx388_kr2376, KR2376_DSII, 0);
249   kr2376_set_input_pin( lx388_kr2376, KR2376_PII, 0);
210   z80ne_state *state = machine->driver_data<z80ne_state>();
211   state->lx388_kr2376 = machine->device("lx388_kr2376");
212   kr2376_set_input_pin( state->lx388_kr2376, KR2376_DSII, 0);
213   kr2376_set_input_pin( state->lx388_kr2376, KR2376_PII, 0);
250214}
251215
252216static void reset_lx382_banking(running_machine *machine)
253217{
218   z80ne_state *state = machine->driver_data<z80ne_state>();
254219   address_space *space = cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM);
255220
256221   /* switch to ROM bank at address 0x0000 */
r9669r9670
258223    memory_set_bank(machine, "bank2", 0);  /* ep382 at 0x8000 */
259224
260225   /* after the first 3 bytes have been read from ROM, switch the RAM back in */
261   reset_delay_counter = 2;
226   state->reset_delay_counter = 2;
262227   space->set_direct_update_handler(direct_update_delegate_create_static(z80ne_reset_delay_count, *machine));
263228}
264229
265230static void reset_lx390_banking(running_machine *machine)
266231{
232   z80ne_state *state = machine->driver_data<z80ne_state>();
267233   address_space *space = cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM);
268   reset_delay_counter = 0;
234   state->reset_delay_counter = 0;
269235
270236   switch (input_port_read(machine, "CONFIG") & 0x07) {
271237   case 0x01: /* EP382 Hex Monitor */
r9669r9670
276242       memory_set_bank(machine, "bank3", 1);  /* ep382 at 0x8000 */
277243       memory_set_bank(machine, "bank4", 0);  /* RAM   at 0xF000 */
278244      /* after the first 3 bytes have been read from ROM, switch the RAM back in */
279      reset_delay_counter = 2;
245      state->reset_delay_counter = 2;
280246      space->set_direct_update_handler(direct_update_delegate_create_static(z80ne_reset_delay_count, *machine));
281247       break;
282248   case 0x02: /* EP548  16k BASIC */
r9669r9670
324290
325291static MACHINE_RESET(z80ne_base)
326292{
293   z80ne_state *state = machine->driver_data<z80ne_state>();
327294   int i;
328295   address_space *space = cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM);
329296
330297   LOG(("In MACHINE_RESET z80ne_base\n"));
331298
332299   for ( i=0; i<LX383_KEYS; i++)
333       lx383_key[i] = 0xf0 | i;
334    lx383_scan_counter = 0x0f;
335    lx383_downsampler = LX383_DOWNSAMPLING;
300       state->lx383_key[i] = 0xf0 | i;
301    state->lx383_scan_counter = 0x0f;
302    state->lx383_downsampler = LX383_DOWNSAMPLING;
336303
337304   /* Initialize cassette interface */
338305   switch(input_port_read(machine, "LX.385") & 0x07)
339306   {
340307   case 0x01:
341      cass_data.speed = TAPE_300BPS;
342      cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 1600;
343      cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (2400 * 2);
344      cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (1200 * 2);
308      state->cass_data.speed = TAPE_300BPS;
309      state->cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 1600;
310      state->cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (2400 * 2);
311      state->cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (1200 * 2);
345312      break;
346313   case 0x02:
347      cass_data.speed = TAPE_600BPS;
348      cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 3200;
349      cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (4800 * 2);
350      cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (2400 * 2);
314      state->cass_data.speed = TAPE_600BPS;
315      state->cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 3200;
316      state->cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (4800 * 2);
317      state->cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (2400 * 2);
351318      break;
352319   case 0x04:
353      cass_data.speed = TAPE_1200BPS;
354      cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 6400;
355      cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (9600 * 2);
356      cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (4800 * 2);
320      state->cass_data.speed = TAPE_1200BPS;
321      state->cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 6400;
322      state->cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (9600 * 2);
323      state->cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (4800 * 2);
357324   }
358   cass_data.wave_length = cass_data.wave_short;
359   cass_data.output.length = cass_data.wave_length;
360   cass_data.output.level = 1;
361   cass_data.input.length = 0;
362   cass_data.input.bit = 1;
325   state->cass_data.wave_length = state->cass_data.wave_short;
326   state->cass_data.output.length = state->cass_data.wave_length;
327   state->cass_data.output.level = 1;
328   state->cass_data.input.length = 0;
329   state->cass_data.input.bit = 1;
363330
364   z80ne_ay31015 = machine->device("ay_3_1015");
365   ay31015_set_input_pin( z80ne_ay31015, AY31015_CS, 0 );
366   ay31015_set_input_pin( z80ne_ay31015, AY31015_NB1, 1 );
367   ay31015_set_input_pin( z80ne_ay31015, AY31015_NB2, 1 );
368   ay31015_set_input_pin( z80ne_ay31015, AY31015_TSB, 1 );
369   ay31015_set_input_pin( z80ne_ay31015, AY31015_EPS, 1 );
370   ay31015_set_input_pin( z80ne_ay31015, AY31015_NP, input_port_read(machine, "LX.385") & 0x80 ? 1 : 0 );
371   ay31015_set_input_pin( z80ne_ay31015, AY31015_CS, 1 );
372   ay31015_set_receiver_clock( z80ne_ay31015, cass_data.speed * 16.0);
373   ay31015_set_transmitter_clock( z80ne_ay31015, cass_data.speed * 16.0);
331   state->ay31015 = machine->device("ay_3_1015");
332   ay31015_set_input_pin( state->ay31015, AY31015_CS, 0 );
333   ay31015_set_input_pin( state->ay31015, AY31015_NB1, 1 );
334   ay31015_set_input_pin( state->ay31015, AY31015_NB2, 1 );
335   ay31015_set_input_pin( state->ay31015, AY31015_TSB, 1 );
336   ay31015_set_input_pin( state->ay31015, AY31015_EPS, 1 );
337   ay31015_set_input_pin( state->ay31015, AY31015_NP, input_port_read(machine, "LX.385") & 0x80 ? 1 : 0 );
338   ay31015_set_input_pin( state->ay31015, AY31015_CS, 1 );
339   ay31015_set_receiver_clock( state->ay31015, state->cass_data.speed * 16.0);
340   ay31015_set_transmitter_clock( state->ay31015, state->cass_data.speed * 16.0);
374341
375   nmi_delay_counter = 0;
342   state->nmi_delay_counter = 0;
376343   lx385_ctrl_w(space, 0, 0);
377344
378345}
r9669r9670
431398
432399MACHINE_START( z80ne )
433400{
401   z80ne_state *state = machine->driver_data<z80ne_state>();
434402   LOG(("In MACHINE_START z80ne\n"));
435   lx385_ctrl = 0x1f;
436   state_save_register_item( machine, "z80ne", NULL, 0, lx383_scan_counter );
437   state_save_register_item( machine, "z80ne", NULL, 0, lx383_downsampler );
438   state_save_register_item_array( machine, "z80ne", NULL, 0, lx383_key );
439   state_save_register_item( machine, "z80ne", NULL, 0, nmi_delay_counter );
440   cassette_timer = timer_alloc(machine, z80ne_cassette_tc, NULL);
403   state->lx385_ctrl = 0x1f;
404   state_save_register_item( machine, "z80ne", NULL, 0, state->lx383_scan_counter );
405   state_save_register_item( machine, "z80ne", NULL, 0, state->lx383_downsampler );
406   state_save_register_item_array( machine, "z80ne", NULL, 0, state->lx383_key );
407   state_save_register_item( machine, "z80ne", NULL, 0, state->nmi_delay_counter );
408   state->cassette_timer = timer_alloc(machine, z80ne_cassette_tc, NULL);
441409   timer_pulse( machine, ATTOTIME_IN_HZ(1000), NULL, 0, z80ne_kbd_scan );
442410}
443411
r9669r9670
466434/* LX.383 - LX.384 HEX keyboard and display */
467435READ8_HANDLER( lx383_r )
468436{
437   z80ne_state *state = space->machine->driver_data<z80ne_state>();
469438   /*
470439     * Keyboard scanning
471440     *
r9669r9670
483452     *      D6 - 0
484453     *      D7 - ~KEY Pressed
485454     */
486    return lx383_key[lx383_scan_counter];
455    return state->lx383_key[state->lx383_scan_counter];
487456}
488457
489458WRITE8_HANDLER( lx383_w )
490459{
460   z80ne_state *state = space->machine->driver_data<z80ne_state>();
491461   /*
492462     * First 8 locations (F0-F7) are mapped to a dual-port 8-byte RAM
493463     * The 1KHz NE-555 astable oscillator circuit drive
r9669r9670
517487       output_set_digit_value( offset, data ^ 0xff );
518488    else
519489       /* after writing to port 0xF8 and the first ~M1 cycles strike a NMI for single step execution */
520       nmi_delay_counter = 1;
490       state->nmi_delay_counter = 1;
521491      cputag_get_address_space(space->machine, "z80ne", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(z80ne_nmi_delay_count, *space->machine));
522492}
523493
r9669r9670
567537 */
568538READ8_HANDLER(lx385_data_r)
569539{
570   return ay31015_get_received_data( z80ne_ay31015 );
540   z80ne_state *state = space->machine->driver_data<z80ne_state>();
541   return ay31015_get_received_data( state->ay31015 );
571542}
572543
573544READ8_HANDLER(lx385_ctrl_r)
574545{
546   z80ne_state *state = space->machine->driver_data<z80ne_state>();
575547   /* set unused bits high */
576548   UINT8 data = 0xc0;
577549
578   ay31015_set_input_pin( z80ne_ay31015, AY31015_SWE, 0 );
579   data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_OR   ) ? 0x01 : 0);
580   data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_FE   ) ? 0x02 : 0);
581   data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_PE   ) ? 0x04 : 0);
582   data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_TBMT ) ? 0x08 : 0);
583   data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_DAV  ) ? 0x10 : 0);
584   data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_EOC  ) ? 0x20 : 0);
585   ay31015_set_input_pin( z80ne_ay31015, AY31015_SWE, 1 );
550   ay31015_set_input_pin( state->ay31015, AY31015_SWE, 0 );
551   data |= (ay31015_get_output_pin( state->ay31015, AY31015_OR   ) ? 0x01 : 0);
552   data |= (ay31015_get_output_pin( state->ay31015, AY31015_FE   ) ? 0x02 : 0);
553   data |= (ay31015_get_output_pin( state->ay31015, AY31015_PE   ) ? 0x04 : 0);
554   data |= (ay31015_get_output_pin( state->ay31015, AY31015_TBMT ) ? 0x08 : 0);
555   data |= (ay31015_get_output_pin( state->ay31015, AY31015_DAV  ) ? 0x10 : 0);
556   data |= (ay31015_get_output_pin( state->ay31015, AY31015_EOC  ) ? 0x20 : 0);
557   ay31015_set_input_pin( state->ay31015, AY31015_SWE, 1 );
586558
587559   return data;
588560}
589561
590562WRITE8_HANDLER(lx385_data_w)
591563{
592   ay31015_set_transmit_data( z80ne_ay31015, data );
564   z80ne_state *state = space->machine->driver_data<z80ne_state>();
565   ay31015_set_transmit_data( state->ay31015, data );
593566}
594567
595568#define LX385_CASSETTE_MOTOR_MASK ((1<<3)|(1<<4))
596569
597570WRITE8_HANDLER(lx385_ctrl_w)
598571{
572   z80ne_state *state = space->machine->driver_data<z80ne_state>();
599573   /* Translate data to control signals
600574     *     0 bit1=0, bit0=0   UART Reset pulse
601575     *     1 bit1=0, bit0=1   UART RDAV (Reset Data Available) pulse
r9669r9670
605579     */
606580   UINT8 uart_reset, uart_rdav, uart_tx_clock;
607581   UINT8 motor_a, motor_b;
608   UINT8 changed_bits = (lx385_ctrl ^ data) & 0x1C;
609   lx385_ctrl = data;
582   UINT8 changed_bits = (state->lx385_ctrl ^ data) & 0x1C;
583   state->lx385_ctrl = data;
610584
611585   uart_reset = ((data & 0x03) == 0x00);
612586   uart_rdav  = ((data & 0x03) == 0x01);
r9669r9670
617591   /* UART Reset and RDAV */
618592   if(uart_reset)
619593   {
620      ay31015_set_input_pin( z80ne_ay31015, AY31015_XR, 1 );
621      ay31015_set_input_pin( z80ne_ay31015, AY31015_XR, 0 );
594      ay31015_set_input_pin( state->ay31015, AY31015_XR, 1 );
595      ay31015_set_input_pin( state->ay31015, AY31015_XR, 0 );
622596   }
623597
624598   if(uart_rdav)
625599   {
626      ay31015_set_input_pin( z80ne_ay31015, AY31015_RDAV, 1 );
627      ay31015_set_input_pin( z80ne_ay31015, AY31015_RDAV, 0 );
600      ay31015_set_input_pin( state->ay31015, AY31015_RDAV, 1 );
601      ay31015_set_input_pin( state->ay31015, AY31015_RDAV, 0 );
628602   }
629603
630604   if (!changed_bits) return;
631605
632606   /* UART Tx Clock enable/disable */
633607   if(changed_bits & 0x04)
634      ay31015_set_transmitter_clock( z80ne_ay31015, uart_tx_clock ? cass_data.speed * 16.0 : 0.0);
608      ay31015_set_transmitter_clock( state->ay31015, uart_tx_clock ? state->cass_data.speed * 16.0 : 0.0);
635609
636610   /* motors */
637611   if(changed_bits & 0x18)
r9669r9670
643617         (motor_b) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR);
644618
645619      if (motor_a || motor_b)
646         timer_adjust_periodic(cassette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(LX385_TAPE_SAMPLE_FREQ));
620         timer_adjust_periodic(state->cassette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(LX385_TAPE_SAMPLE_FREQ));
647621      else
648         timer_adjust_oneshot(cassette_timer, attotime_zero, 0);
622         timer_adjust_oneshot(state->cassette_timer, attotime_zero, 0);
649623   }
650624}
651625
r9669r9670
671645
672646READ8_HANDLER(lx388_data_r)
673647{
648   z80ne_state *state = space->machine->driver_data<z80ne_state>();
674649   UINT8 data;
675650
676   data = kr2376_data_r(lx388_kr2376, 0) & 0x7f;
677   data |= kr2376_get_output_pin(lx388_kr2376, KR2376_SO) << 7;
651   data = kr2376_data_r(state->lx388_kr2376, 0) & 0x7f;
652   data |= kr2376_get_output_pin(state->lx388_kr2376, KR2376_SO) << 7;
678653   return data;
679654}
680655
r9669r9670
695670
696671WRITE8_DEVICE_HANDLER(lx390_motor_w)
697672{
673   z80ne_state *state = device->machine->driver_data<z80ne_state>();
698674   /* Selection of drive and parameters
699675     A write also causes the selected drive motor to turn on for about 3 seconds.
700676     When the motor turns off, the drive is deselected.
r9669r9670
721697      if (data & 8)
722698         drive = 3;
723699
724      wd17xx_state.head = (data & 32) ? 1 : 0;
725      wd17xx_state.drive = data & 0x0F;
700      state->wd17xx_state.head = (data & 32) ? 1 : 0;
701      state->wd17xx_state.drive = data & 0x0F;
726702
727703      /* no drive selected, turn off all leds */
728      if (!wd17xx_state.drive)
704      if (!state->wd17xx_state.drive)
729705      {
730706         output_set_value("drv0", 0);
731707         output_set_value("drv1", 0);
r9669r9670
735711      {
736712         LOG(("lx390_motor_w, set drive %1d\n", drive));
737713         wd17xx_set_drive(device,drive);
738         LOG(("lx390_motor_w, set side %1d\n", wd17xx_state.head));
739         wd17xx_set_side(device, wd17xx_state.head);
714         LOG(("lx390_motor_w, set side %1d\n", state->wd17xx_state.head));
715         wd17xx_set_side(device, state->wd17xx_state.head);
740716      }
741717}
742718
r9669r9670
796772
797773WRITE8_DEVICE_HANDLER(lx390_fdc_w)
798774{
775   z80ne_state *state = device->machine->driver_data<z80ne_state>();
799776   UINT8 d;
800777
801778   d = data;
r9669r9670
804781   case 0:
805782      LOG(("lx390_fdc_w, WD17xx command: %02x\n", d));
806783      wd17xx_command_w(device, offset, d);
807      if (wd17xx_state.drive & 1)
784      if (state->wd17xx_state.drive & 1)
808785         output_set_value("drv0", 2);
809      else if (wd17xx_state.drive & 2)
786      else if (state->wd17xx_state.drive & 2)
810787         output_set_value("drv1", 2);
811788      break;
812789   case 1:
src/mess/machine/mac.c
r9669r9670
143143static TIMER_CALLBACK(mac_adb_tick);
144144static TIMER_CALLBACK(mac_6015_tick);
145145static TIMER_CALLBACK(mac_pmu_tick);
146static emu_timer *mac_scanline_timer, *mac_adb_timer;
147146static int scan_keyboard(running_machine *machine);
148147static TIMER_CALLBACK(inquiry_timeout_func);
149148static void keyboard_receive(running_machine *machine, int val);
r9669r9670
257256    Interrupt handling
258257*/
259258
260void mac_state::field_interrupts(running_machine *machine)
259void mac_state::field_interrupts()
261260{
262261   int take_interrupt = -1;
263262
r9669r9670
305304   }
306305}
307306
308void mac_state::set_scc_interrupt(running_machine *machine, int value)
307void mac_state::set_scc_interrupt(int value)
309308{
310309   m_scc_interrupt = value;
311   field_interrupts(machine);
310   this->field_interrupts();
312311}
313312
314void mac_state::set_via_interrupt(running_machine *machine, int value)
313void mac_state::set_via_interrupt(int value)
315314{
316315   m_via_interrupt = value;
317   field_interrupts(machine);
316   this->field_interrupts();
318317}
319318
320319
321void mac_state::set_via2_interrupt(running_machine *machine, int value)
320void mac_state::set_via2_interrupt(int value)
322321{
323322   m_via2_interrupt = value;
324   field_interrupts(machine);
323   this->field_interrupts();
325324}
326325
327326void mac_asc_irq(running_device *device, int state)
r9669r9670
337336         if (mac->m_rbv_ier & 0x10)   // ASC on RBV is CB1, bit 4 of IER/IFR
338337         {
339338            mac->m_rbv_ifr |= 0x90;
340            mac->set_via2_interrupt(device->machine, 1);
339            mac->set_via2_interrupt(1);
341340         }
342341      }
343342      else
r9669r9670
384383   /* Not Yet Implemented */
385384}
386385
387void mac_state::v8_resize(running_machine *machine)
386void mac_state::v8_resize()
388387{
389388   offs_t memory_size;
390389   UINT8 *memory_data;
r9669r9670
459458   }
460459}
461460
462void mac_state::set_memory_overlay(running_machine *machine, int overlay)
461void mac_state::set_memory_overlay(int overlay)
463462{
464463   offs_t memory_size;
465464   UINT8 *memory_data;
r9669r9670
490489      if (((m_model >= MODEL_MAC_LC) && (m_model <= MODEL_MAC_COLOR_CLASSIC) && ((m_model != MODEL_MAC_LC_III) && (m_model != MODEL_MAC_LC_III_PLUS))) || (m_model == MODEL_MAC_CLASSIC_II))
491490      {
492491         m_overlay = overlay;
493         v8_resize(machine);
492         this->v8_resize();
494493      }
495494      else if ((m_model >= MODEL_MAC_POWERMAC_6100) && (m_model >= MODEL_MAC_POWERMAC_8100))
496495      {
r9669r9670
843842 * Mouse
844843 * *************************************************************************/
845844
846static void mouse_callback(running_machine *machine)
845void mac_state::mouse_callback()
847846{
848   static int   last_mx = 0, last_my = 0;
849   static int   count_x = 0, count_y = 0;
850847   int      new_mx, new_my;
851848   int      x_needs_update = 0, y_needs_update = 0;
852849   mac_state *mac = machine->driver_data<mac_state>();
r9669r9670
917914
918915   if (x_needs_update || y_needs_update)
919916      /* assert Port B External Interrupt on the SCC */
920      mac->scc_mouse_irq(machine, x_needs_update, y_needs_update );
917      mac->scc_mouse_irq(x_needs_update, y_needs_update );
921918}
922919
923920/* *************************************************************************
r9669r9670
10721069   if ((mac->m_scsiirq_enable) && ((mac->m_model == MODEL_MAC_SE) || (mac->m_model == MODEL_MAC_CLASSIC)))
10731070   {
10741071      mac->m_scsi_interrupt = state;
1075      mac->field_interrupts(machine);
1072      mac->field_interrupts();
10761073   }
10771074}
10781075
r9669r9670
10861083{
10871084   mac_state *mac = device->machine->driver_data<mac_state>();
10881085
1089   mac->set_scc_interrupt(device->machine, status);
1086   mac->set_scc_interrupt(status);
10901087}
10911088
10921089
10931090
1094void mac_state::scc_mouse_irq(running_machine *machine, int x, int y)
1091void mac_state::scc_mouse_irq(int x, int y)
10951092{
10961093   running_device *scc = machine->device("scc");
1097   static int last_was_x = 0;
10981094   if (x && y)
10991095   {
11001096      if (last_was_x)
r9669r9670
11131109   }
11141110
11151111   //cputag_set_input_line(machine, "maincpu", 2, ASSERT_LINE);
1116   set_scc_interrupt(machine, 1);
1112   this->set_scc_interrupt(1);
11171113}
11181114
11191115
r9669r9670
15201516static const char *const adb_statenames[4] = { "NEW", "EVEN", "ODD", "IDLE" };
15211517#endif
15221518
1523int mac_state::adb_pollkbd(running_machine *machine, int update)
1519int mac_state::adb_pollkbd(int update)
15241520{
15251521   int i, j, keybuf, report, codes[2], result;
15261522   static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5" };
r9669r9670
16491645   return result;
16501646}
16511647
1652int mac_state::adb_pollmouse(running_machine *machine)
1648int mac_state::adb_pollmouse()
16531649{
16541650   int NewX, NewY, NewButton;
16551651
r9669r9670
16701666   return 0;
16711667}
16721668
1673void mac_state::adb_accummouse( running_machine *machine, UINT8 *MouseX, UINT8 *MouseY )
1669void mac_state::adb_accummouse( UINT8 *MouseX, UINT8 *MouseY )
16741670{
16751671   int MouseCountX = 0, MouseCountY = 0;
16761672   int NewX, NewY;
r9669r9670
17141710   *MouseY = (UINT8)MouseCountY;
17151711}
17161712
1717void mac_state::adb_talk(running_machine *machine)
1713void mac_state::adb_talk()
17181714{
17191715   int addr, reg;
17201716
r9669r9670
17921788                     }
17931789                     else
17941790                     {
1795                        adb_accummouse(machine, &mouseX, &mouseY);
1791                        this->adb_accummouse(&mouseX, &mouseY);
17961792                     }
17971793                     m_adb_buffer[0] = (m_adb_lastbutton & 0x01) ? 0x00 : 0x80;
17981794                     m_adb_buffer[0] |= mouseX & 0x7f;
r9669r9670
18291825                     }
18301826                     else
18311827                     {
1832                        adb_pollkbd(machine, 1);
1828                        this->adb_pollkbd(1);
18331829                     }
18341830//                          printf("keyboard = %02x %02x\n", m_adb_currentkeys[0], m_adb_currentkeys[1]);
18351831                     m_adb_buffer[0] = m_adb_currentkeys[1];
r9669r9670
18391835
18401836                  // read modifier keys
18411837                  case 2:
1842                     adb_pollkbd(machine, 1);
1838                     this->adb_pollkbd(1);
18431839                     m_adb_buffer[0] = m_adb_modifiers;   // nothing pressed
18441840                     m_adb_buffer[1] = 0;
18451841                     m_adb_datasize = 2;
r9669r9670
19131909   mac->m_adb_timer_ticks--;
19141910   if (!mac->m_adb_timer_ticks)
19151911   {
1916      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
1912      timer_adjust_oneshot(mac->adb_timer, attotime_never, 0);
19171913
19181914      if ((mac->m_adb_direction) && (ADB_IS_BITBANG))
19191915      {
1920         mac->adb_talk(machine);
1916         mac->adb_talk();
19211917      }
19221918      else if (ADB_IS_EGRET)
19231919      {
r9669r9670
19611957            }
19621958
19631959//              mac->m_adb_timer_ticks = 8;
1964//              timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
1960//              timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
19651961
19661962            if ((mac->m_adb_datasize == 0) && (mac->m_adb_streaming == MCU_STREAMING_NONE))
19671963            {
r9669r9670
19871983   }
19881984   else
19891985   {
1990      timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
1986      timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
19911987   }
19921988}
19931989
r9669r9670
20312027            mac->m_adb_direction = 1;   // Mac is shifting us a command
20322028            mac->m_adb_waiting_cmd = 1;   // we're going to get a command
20332029            mac->m_adb_irq_pending = 0;
2034            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2030            timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
20352031            break;
20362032
20372033         case ADB_STATE_XFER_EVEN:
r9669r9670
20612057               mac->m_adb_irq_pending = 1;
20622058            }
20632059
2064            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2060            timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
20652061            break;
20662062
20672063         case ADB_STATE_IDLE:
r9669r9670
20802076   mac->m_adb_state |= 1;
20812077   mac->m_adb_timer_ticks = 8;
20822078   mac->m_adb_datasize = 3;
2083   timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2079   timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
20842080}
20852081
20862082static void mac_egret_response_adb(mac_state *mac, int type, int flag, int cmd, int extra)
r9669r9670
20932089   mac->m_adb_state |= 1;
20942090   mac->m_adb_timer_ticks = 8;
20952091   mac->m_adb_datasize = 4;
2096   timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2092   timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
20972093}
20982094
20992095static void mac_egret_response_read_pram(mac_state *mac, int cmd, int addr)
r9669r9670
21082104
21092105   mac->m_adb_state |= 1;
21102106   mac->m_adb_timer_ticks = 8;
2111   timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2107   timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
21122108
21132109   // read PRAM is a "streaming" command, don't drop the state line when we're out of data
21142110   mac->m_adb_streaming = MCU_STREAMING_PRAMRD;
r9669r9670
21302126
21312127   mac->m_adb_state |= 1;
21322128   mac->m_adb_timer_ticks = 8;
2133   timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2129   timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
21342130}
21352131
21362132static void mac_egret_mcu_exec(mac_state *mac)
r9669r9670
22332229         mac->m_adb_buffer[1] = 0;   // spare
22342230         mac->m_adb_state |= 1;
22352231         mac->m_adb_timer_ticks = 8;
2236         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2232         timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
22372233         break;
22382234
22392235      case 0x0e: // send to DFAC
r9669r9670
23032299      {
23042300         mac->m_adb_command = 0;
23052301         mac->m_adb_timer_ticks = 8;
2306         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2302         timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
23072303      }
23082304
23092305      // if bit 2 is high and stays high, the falling edge of bit 1, and we're in send phase, the MCU should clock out a byte
23102306      if ((state & 0x04) && (mac->m_adb_state & 0x04) && !(state & 0x02) && (mac->m_adb_state & 0x02) && (mac->m_adb_state & 0x01))
23112307      {
23122308         mac->m_adb_timer_ticks = 8;
2313         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2309         timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
23142310      }
23152311
23162312      // if bit 2 rises, bit 1 is 0, and MCU XS is high, the MCU should clock out a byte
23172313      if ((state & 0x04) && !(mac->m_adb_state & 0x04) && !(state & 0x02) && (mac->m_adb_state & 0x01))
23182314      {
23192315         mac->m_adb_timer_ticks = 8;
2320         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2316         timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
23212317      }
23222318
23232319      // if bit 2 drops and bit 1 is 1, terminate the command
r9669r9670
25062502   }
25072503}
25082504
2509void mac_state::adb_vblank(running_machine *machine)
2505void mac_state::adb_vblank()
25102506{
25112507   if (m_adb_state == ADB_STATE_IDLE)
25122508   {
2513      if (adb_pollmouse(machine))
2509      if (this->adb_pollmouse())
25142510      {
25152511         // if the mouse was the last TALK, we can just send the new data
25162512         // otherwise we need to pull SRQ
r9669r9670
25182514         {
25192515            // repeat last TALK to get updated data
25202516            m_adb_waiting_cmd = 1;
2521            adb_talk(machine);
2517            this->adb_talk();
25222518
25232519            m_adb_timer_ticks = 8;
2524            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2520            timer_adjust_oneshot(this->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
25252521         }
25262522         else
25272523         {
25282524            m_adb_irq_pending = 1;
25292525            m_adb_command = m_adb_send = 0;
25302526            m_adb_timer_ticks = 1;   // one tick should be sufficient to make it see  the IRQ
2531            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2527            timer_adjust_oneshot(this->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
25322528            m_adb_srq_switch = 1;
25332529         }
25342530      }
2535      else if (adb_pollkbd(machine, 0))
2531      else if (this->adb_pollkbd(0))
25362532      {
25372533         if (m_adb_last_talk == m_adb_keybaddr)
25382534         {
25392535            // repeat last TALK to get updated data
25402536            m_adb_waiting_cmd = 1;
2541            adb_talk(machine);
2537            this->adb_talk();
25422538
25432539            m_adb_timer_ticks = 8;
2544            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2540            timer_adjust_oneshot(this->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
25452541         }
25462542         else
25472543         {
25482544            m_adb_irq_pending = 1;
25492545            m_adb_command = m_adb_send = 0;
25502546            m_adb_timer_ticks = 1;   // one tick should be sufficient to make it see  the IRQ
2551            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2547            timer_adjust_oneshot(this->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
25522548            m_adb_srq_switch = 1;
25532549         }
25542550      }
25552551   }
25562552}
25572553
2558void mac_state::adb_reset(running_machine *machine)
2554void mac_state::adb_reset()
25592555{
25602556   int i;
25612557
r9669r9670
27592755   }
27602756
27612757   set_scc_waitrequest((data & 0x80) >> 7);
2762   mac_set_screen_buffer((data & 0x40) >> 6);
2758   mac->screen_buffer = (data & 0x40) >> 6;
27632759   sony_set_sel_line(fdc,(data & 0x20) >> 5);
27642760   if (mac->m_model == MODEL_MAC_SE)   // on SE this selects which floppy drive (0 = upper, 1 = lower)
27652761   {
r9669r9670
27812777     * first access to the ROM. */
27822778   if (mac->m_model < MODEL_MAC_SE)
27832779   {
2784      mac->set_memory_overlay(device->machine, (data & 0x10) >> 4);
2780      mac->set_memory_overlay((data & 0x10) >> 4);
27852781   }
27862782}
27872783
r9669r9670
28772873      // clear the interrupt if we disabled it
28782874      if (!mac->m_se30_vbl_enable)
28792875      {
2880         mac->nubus_slot_interrupt(device->machine, 0xe, 0);
2876         mac->nubus_slot_interrupt(0xe, 0);
28812877      }
28822878   }
28832879
r9669r9670
29022898   mac_state *mac = device->machine->driver_data<mac_state>();
29032899
29042900   /* interrupt the 68k (level 1) */
2905   mac->set_via_interrupt(device->machine, state);
2901   mac->set_via_interrupt(state);
29062902}
29072903
29082904READ16_MEMBER ( mac_state::mac_via_r )
r9669r9670
29382934static void mac_via2_irq(running_device *device, int state)
29392935{
29402936   mac_state *mac = device->machine->driver_data<mac_state>();
2941   mac->set_via2_interrupt(device->machine, state);
2937   mac->set_via2_interrupt(state);
29422938}
29432939
29442940READ16_MEMBER ( mac_state::mac_via2_r )
r9669r9670
30353031{
30363032   if (has_adb())
30373033   {
3038      mac_adb_timer = timer_alloc(machine, mac_adb_tick, NULL);
3039      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
3034      this->adb_timer = timer_alloc(machine, mac_adb_tick, NULL);
3035      timer_adjust_oneshot(this->adb_timer, attotime_never, 0);
30403036
30413037      // also allocate PMU timer
30423038      if (ADB_IS_PM_CLASS)
30433039      {
30443040         m_pmu_send_timer = timer_alloc(machine, mac_pmu_tick, NULL);
3045         timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
3041         timer_adjust_oneshot(this->adb_timer, attotime_never, 0);
30463042      }
30473043
30483044   }
3049   mac_scanline_timer = timer_alloc(machine, mac_scanline_tick, NULL);
3050   timer_adjust_oneshot(mac_scanline_timer, machine->primary_screen->time_until_pos(0, 0), 0);
3045   this->scanline_timer = timer_alloc(machine, mac_scanline_tick, NULL);
3046   timer_adjust_oneshot(this->scanline_timer, machine->primary_screen->time_until_pos(0, 0), 0);
30513047
30523048   m_6015_timer = timer_alloc(machine, mac_6015_tick, NULL);
30533049   timer_adjust_oneshot(m_6015_timer, attotime_never, 0);
r9669r9670
30673063   // clear PMU response timer
30683064   if (ADB_IS_PM_CLASS)
30693065   {
3070      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
3066      timer_adjust_oneshot(this->adb_timer, attotime_never, 0);
30713067   }
30723068
30733069   // default to 32-bit mode on LC
r9669r9670
30853081   if (m_model < MODEL_MAC_POWERMAC_6100)   // no overlay for PowerPC
30863082   {
30873083      m_overlay = -1;   // insure no match
3088      set_memory_overlay(machine, 1);
3084      this->set_memory_overlay(1);
30893085   }
30903086
30913087   /* setup videoram */
3092   mac_set_screen_buffer(1);
3088   this->screen_buffer = 1;
30933089
30943090   /* setup sound */
30953091   if (AUDIO_IS_CLASSIC_CLASS)
r9669r9670
31043100
31053101   if (has_adb())
31063102   {
3107      adb_reset(machine);
3103      this->adb_reset();
31083104   }
31093105
31103106   if ((m_model == MODEL_MAC_SE) || (m_model == MODEL_MAC_CLASSIC))
r9669r9670
31553151
31563152   overlay = mac->m_overlay;
31573153   mac->m_overlay = -1;
3158   mac->set_memory_overlay(machine, overlay);
3154   mac->set_memory_overlay(overlay);
31593155}
31603156
31613157
r9669r9670
31693165      {
31703166         if ((address >= 0x900000) && (address <= 0x9fffff))
31713167         {
3172            mac->set_memory_overlay(machine, 0);      // kill the overlay
3168            mac->set_memory_overlay(0);      // kill the overlay
31733169         }
31743170      }
31753171      else if ((mac->m_model == MODEL_MAC_SE) || (mac->m_model == MODEL_MAC_CLASSIC))
31763172      {
31773173         if ((address >= 0x400000) && (address <= 0x4fffff))
31783174         {
3179            mac->set_memory_overlay(machine, 0);      // kill the overlay
3175            mac->set_memory_overlay(0);      // kill the overlay
31803176         }
31813177      }
31823178      else if ((mac->m_model == MODEL_MAC_LC) || (mac->m_model == MODEL_MAC_LC_II) || (mac->m_model == MODEL_MAC_CLASSIC_II))
31833179      {
31843180         if ((address >= 0xa00000) && (address <= 0xafffff))
31853181         {
3186            mac->set_memory_overlay(machine, 0);      // kill the overlay
3182            mac->set_memory_overlay(0);      // kill the overlay
31873183         }
31883184      }
31893185      else
31903186      {
31913187         if ((address >= 0x40000000) && (address <= 0x4fffffff))
31923188         {
3193            mac->set_memory_overlay(machine, 0);      // kill the overlay
3189            mac->set_memory_overlay(0);      // kill the overlay
31943190         }
31953191      }
31963192   }
r9669r9670
32203216   }
32213217
32223218   mac->m_overlay = -1;
3223   mac->set_memory_overlay(machine, 1);
3219   mac->set_memory_overlay(1);
32243220
32253221   memset(messram_get_ptr(mac->m_ram), 0, messram_get_size(mac->m_ram));
32263222
r9669r9670
32953291   mac_driver_init(machine, MODEL_MAC_IIX);
32963292}
32973293
3298void mac_state::nubus_slot_interrupt(running_machine *machine, UINT8 slot, UINT32 state)
3294void mac_state::nubus_slot_interrupt(UINT8 slot, UINT32 state)
32993295{
33003296   UINT8 masks[6] = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20 };
33013297   mac_state *mac = machine->driver_data<mac_state>();
r9669r9670
33273323   }
33283324}
33293325
3330void mac_state::vblank_irq(running_machine *machine)
3326void mac_state::vblank_irq()
33313327{
3332   static int irq_count = 0, ca1_data = 0, ca2_data = 0;
3333
33343328   /* handle ADB keyboard/mouse */
33353329   if (has_adb())
33363330   {
3337      adb_vblank(machine);
3331      this->adb_vblank();
33383332   }
33393333
33403334   /* handle keyboard */
r9669r9670
33793373         m_via2_vbl ^= 1;
33803374         if (!m_via2_vbl)
33813375         {
3382            nubus_slot_interrupt(machine, 0xe, 1);
3376            this->nubus_slot_interrupt(0xe, 1);
33833377         }
33843378      }
33853379   }
r9669r9670
33973391
33983392   scanline = machine->primary_screen->vpos();
33993393   if (scanline == MAC_V_VIS)
3400      mac->vblank_irq(machine);
3394      mac->vblank_irq();
34013395   
34023396   /* check for mouse changes at 10 irqs per frame */
34033397   if (mac->m_model <= MODEL_MAC_PLUS)
34043398   {
34053399      if (!(scanline % 10))
3406         mouse_callback(machine);
3400         mac->mouse_callback();
34073401   }
34083402
3409   timer_adjust_oneshot(mac_scanline_timer, machine->primary_screen->time_until_pos((scanline+1) % MAC_V_TOTAL, 0), 0);
3403   timer_adjust_oneshot(mac->scanline_timer, machine->primary_screen->time_until_pos((scanline+1) % MAC_V_TOTAL, 0), 0);
34103404}
34113405
34123406
src/mess/machine/lynx.c
r9669r9670
99#include "devices/cartslot.h"
1010#include "hash.h"
1111
12static UINT16 lynx_granularity;
13static int lynx_line;
14static int lynx_line_y;
15static int sign_AB = 0, sign_CD = 0;
1612
17static UINT32 lynx_palette[0x10];
1813
19static int rotate0 = 0;
20static int lynx_rotate;
21static running_device *lynx_audio;
2214
2315#define MATH_A      0x55
2416#define MATH_B      0x54
r9669r9670
4335#define PAD_LEFT   0x20
4436#define PAD_RIGHT   0x10
4537
46typedef struct
47{
48   UINT8 data[0x100];
49   int accumulate_overflow;
50   UINT8 high;
51   int low;
52} SUZY;
5338
54static SUZY suzy;
55
56static struct
57{
58   UINT8 *mem;
59   // global
60   UINT16 screen;
61   UINT16 colbuf;
62   UINT16 colpos; // byte where value of collision is written
63   UINT16 xoff, yoff;
64   // in command
65   int mode;
66   UINT16 cmd;
67   UINT8 spritenr;
68   int x,y;
69   UINT16 width, height; // uint16 important for blue lightning
70   UINT16 stretch, tilt; // uint16 important
71   UINT8 color[16]; // or stored
72   void (*line_function)(const int y, const int xdir);
73   UINT16 bitmap;
74
75   int everon;
76   int memory_accesses;
77   attotime time;
78} blitter;
79
80UINT8 *lynx_mem_0000;
81UINT8 *lynx_mem_fc00;
82UINT8 *lynx_mem_fd00;
83UINT8 *lynx_mem_fe00;
84UINT8 *lynx_mem_fffa;
85size_t lynx_mem_fe00_size;
86
87static UINT8 lynx_memory_config;
88
8939/****************************************
9040
9141    Graphics Drawing
r9669r9670
12171   SHADOW
12272};
12373
124static UINT8 sprite_collide;
12574
12675/* The pen numbers range from '0' to 'F. Pen numbers '1' thru 'D' are always collidable and opaque. The other
12776ones have different behavior depending on the sprite type: there are 8 types of sprites, each has different
r9669r9670
151100  0  0  0  0  0  0  0  1      exclusive-or the data
152101*/
153102
154INLINE void lynx_plot_pixel(const int mode, const int x, const int y, const int color)
103INLINE void lynx_plot_pixel(lynx_state *state, const int mode, const int x, const int y, const int color)
155104{
156105   int back;
157106   UINT8 *screen;
158107   UINT8 *colbuf;
159108
160   blitter.everon = TRUE;
161   screen = blitter.mem + blitter.screen + y * 80 + x / 2;
162   colbuf = blitter.mem + blitter.colbuf + y * 80 + x / 2;
109   state->blitter.everon = TRUE;
110   screen = state->blitter.mem + state->blitter.screen + y * 80 + x / 2;
111   colbuf = state->blitter.mem + state->blitter.colbuf + y * 80 + x / 2;
163112
164113   switch (mode)
165114   {
r9669r9670
172121         {
173122            *screen = (*screen & 0x0f) | (color << 4);
174123
175            if(sprite_collide)
124            if(state->sprite_collide)
176125            {
177126               back = *colbuf;
178               *colbuf = (back & ~0xf0) | (blitter.spritenr << 4);
179               if ((back >> 4) > blitter.mem[blitter.colpos])
180                  blitter.mem[blitter.colpos] = back >> 4;
181               blitter.memory_accesses += 2;
127               *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4);
128               if ((back >> 4) > state->blitter.mem[state->blitter.colpos])
129                  state->blitter.mem[state->blitter.colpos] = back >> 4;
130               state->blitter.memory_accesses += 2;
182131            }
183132         }
184133         else               /* Lower nibble */
185134         {
186135            *screen = (*screen & 0xf0) | color;
187136
188            if(sprite_collide)
137            if(state->sprite_collide)
189138            {
190139               back = *colbuf;
191               *colbuf = (back & ~0x0f) | (blitter.spritenr);
192               if ((back & 0x0f) > blitter.mem[blitter.colpos])
193                  blitter.mem[blitter.colpos] = back & 0x0f;
194               blitter.memory_accesses += 2;
140               *colbuf = (back & ~0x0f) | (state->blitter.spritenr);
141               if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos])
142                  state->blitter.mem[state->blitter.colpos] = back & 0x0f;
143               state->blitter.memory_accesses += 2;
195144            }
196145         }
197         blitter.memory_accesses++;
146         state->blitter.memory_accesses++;
198147         break;
199148
200149      case BOUNDARY:
r9669r9670
207156            if (color != 0x0f)
208157            {
209158               *screen = (*screen & 0x0f) | (color << 4);
210               blitter.memory_accesses++;
159               state->blitter.memory_accesses++;
211160            }
212            if(sprite_collide)
161            if(state->sprite_collide)
213162            {
214163               back = *colbuf;
215               *colbuf = (back & ~0xf0) | (blitter.spritenr << 4);
216               if ((back >> 4) > blitter.mem[blitter.colpos])
217                  blitter.mem[blitter.colpos] = back >> 4;
218               blitter.memory_accesses += 2;
164               *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4);
165               if ((back >> 4) > state->blitter.mem[state->blitter.colpos])
166                  state->blitter.mem[state->blitter.colpos] = back >> 4;
167               state->blitter.memory_accesses += 2;
219168            }
220169         }
221170         else               /* Lower nibble */
r9669r9670
223172            if (color != 0x0f)
224173            {
225174               *screen = (*screen & 0xf0) | color;
226               blitter.memory_accesses++;
175               state->blitter.memory_accesses++;
227176            }
228            if(sprite_collide)
177            if(state->sprite_collide)
229178            {
230179               back = *colbuf;
231               *colbuf = (back & ~0x0f) | (blitter.spritenr);
232               if ((back & 0x0f) > blitter.mem[blitter.colpos])
233                  blitter.mem[blitter.colpos] = back & 0x0f;
234               blitter.memory_accesses += 2;
180               *colbuf = (back & ~0x0f) | (state->blitter.spritenr);
181               if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos])
182                  state->blitter.mem[state->blitter.colpos] = back & 0x0f;
183               state->blitter.memory_accesses += 2;
235184            }
236185         }
237186         break;
r9669r9670
245194         {
246195            *screen = (*screen & 0x0f) | (color << 4);
247196
248            if (sprite_collide && (color != 0x0e))
197            if (state->sprite_collide && (color != 0x0e))
249198            {
250199               back = *colbuf;
251               *colbuf = (back & ~0xf0) | (blitter.spritenr << 4);
252               if ((back >> 4) > blitter.mem[blitter.colpos])
253                  blitter.mem[blitter.colpos] = back >> 4;
254               blitter.memory_accesses += 2;
200               *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4);
201               if ((back >> 4) > state->blitter.mem[state->blitter.colpos])
202                  state->blitter.mem[state->blitter.colpos] = back >> 4;
203               state->blitter.memory_accesses += 2;
255204            }
256205         }
257206         else               /* Lower nibble */
258207         {
259208            *screen = (*screen & 0xf0) | color;
260209
261            if (sprite_collide && (color != 0x0e))
210            if (state->sprite_collide && (color != 0x0e))
262211            {
263212               back = *colbuf;
264               *colbuf = (back & ~0x0f) | (blitter.spritenr);
265               if ((back & 0x0f) > blitter.mem[blitter.colpos])
266                  blitter.mem[blitter.colpos] = back & 0x0f;
267               blitter.memory_accesses += 2;
213               *colbuf = (back & ~0x0f) | (state->blitter.spritenr);
214               if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos])
215                  state->blitter.mem[state->blitter.colpos] = back & 0x0f;
216               state->blitter.memory_accesses += 2;
268217            }
269218         }
270         blitter.memory_accesses++;
219         state->blitter.memory_accesses++;
271220         break;
272221
273222      case BOUNDARY_SHADOW:
r9669r9670
281230            if (color != 0x0f)
282231            {
283232               *screen = (*screen & 0x0f) | (color << 4);
284               blitter.memory_accesses++;
233               state->blitter.memory_accesses++;
285234            }
286            if (sprite_collide && (color != 0x0e))
235            if (state->sprite_collide && (color != 0x0e))
287236            {
288237               back = *colbuf;
289               *colbuf = (back & ~0xf0) | (blitter.spritenr << 4);
290               if ((back >> 4) > blitter.mem[blitter.colpos])
291                  blitter.mem[blitter.colpos] = back >> 4;
292               blitter.memory_accesses += 2;
238               *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4);
239               if ((back >> 4) > state->blitter.mem[state->blitter.colpos])
240                  state->blitter.mem[state->blitter.colpos] = back >> 4;
241               state->blitter.memory_accesses += 2;
293242            }
294243         }
295244         else               /* Lower nibble */
r9669r9670
297246            if (color != 0x0f)
298247            {
299248               *screen = (*screen & 0xf0) | color;
300               blitter.memory_accesses++;
249               state->blitter.memory_accesses++;
301250            }
302            if (sprite_collide && (color != 0x0e))
251            if (state->sprite_collide && (color != 0x0e))
303252            {
304253               back = *colbuf;
305               *colbuf = (back & ~0x0f) | (blitter.spritenr);
306               if ((back & 0x0f) > blitter.mem[blitter.colpos])
307                  blitter.mem[blitter.colpos] = back & 0x0f;
308               blitter.memory_accesses += 2;
254               *colbuf = (back & ~0x0f) | (state->blitter.spritenr);
255               if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos])
256                  state->blitter.mem[state->blitter.colpos] = back & 0x0f;
257               state->blitter.memory_accesses += 2;
309258            }
310259         }
311260         break;
r9669r9670
320269         {
321270            *screen = (*screen & 0x0f) | (color << 4);
322271
323            if (sprite_collide && (color != 0x0e))
272            if (state->sprite_collide && (color != 0x0e))
324273            {
325               *colbuf = (*colbuf & ~0xf0) | (blitter.spritenr << 4);
326               blitter.memory_accesses++;
274               *colbuf = (*colbuf & ~0xf0) | (state->blitter.spritenr << 4);
275               state->blitter.memory_accesses++;
327276            }
328277         }
329278         else               /* Lower nibble */
330279         {
331280            *screen = (*screen & 0xf0) | color;
332281
333            if (sprite_collide && (color != 0x0e))
282            if (state->sprite_collide && (color != 0x0e))
334283            {
335               *colbuf = (*colbuf & ~0x0f) | (blitter.spritenr);
336               blitter.memory_accesses++;
284               *colbuf = (*colbuf & ~0x0f) | (state->blitter.spritenr);
285               state->blitter.memory_accesses++;
337286            }
338287         }
339         blitter.memory_accesses++;
288         state->blitter.memory_accesses++;
340289         break;
341290
342291      case BACKGROUND_NO_COLL:
r9669r9670
345294            *screen = (*screen & 0x0f) | (color << 4);
346295         else               /* Lower nibble */
347296            *screen = (*screen & 0xf0) | color;
348         blitter.memory_accesses++;
297         state->blitter.memory_accesses++;
349298         break;
350299
351300      case NO_COLL:
r9669r9670
357306            *screen = (*screen & 0x0f) | (color << 4);
358307         else               /* Lower nibble */
359308            *screen = (*screen & 0xf0) | color;
360         blitter.memory_accesses++;
309         state->blitter.memory_accesses++;
361310         break;
362311
363312      case XOR_SPRITE:
r9669r9670
374323            if (color != 0x0e)
375324            {
376325               back = *colbuf;
377               *colbuf = (back & ~0xf0) | (blitter.spritenr << 4);
378               if ((back >> 4) > blitter.mem[blitter.colpos])
379                  blitter.mem[blitter.colpos] = back >> 4;
380               blitter.memory_accesses += 2;
326               *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4);
327               if ((back >> 4) > state->blitter.mem[state->blitter.colpos])
328                  state->blitter.mem[state->blitter.colpos] = back >> 4;
329               state->blitter.memory_accesses += 2;
381330            }
382331         }
383332         else               /* Lower nibble */
r9669r9670
387336            if (color != 0x0e)
388337            {
389338               back = *colbuf;
390               *colbuf = (back & ~0x0f) | (blitter.spritenr);
391               if ((back & 0x0f) > blitter.mem[blitter.colpos])
392                  blitter.mem[blitter.colpos] = back & 0x0f;
393               blitter.memory_accesses += 2;
339               *colbuf = (back & ~0x0f) | (state->blitter.spritenr);
340               if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos])
341                  state->blitter.mem[state->blitter.colpos] = back & 0x0f;
342               state->blitter.memory_accesses += 2;
394343            }
395344         }
396         blitter.memory_accesses++;
345         state->blitter.memory_accesses++;
397346         break;
398347   }
399348}
400349
401static void lynx_blit_do_work( const int y, const int xdir, const int bits, const int mask )
350static void lynx_blit_do_work( lynx_state *state, const int y, const int xdir, const int bits, const int mask )
402351{
403352   int j, xi, wi, i;
404353   int b, p, color;
405354
406   i = blitter.mem[blitter.bitmap];
407   blitter.memory_accesses++;      // ?
355   i = state->blitter.mem[state->blitter.bitmap];
356   state->blitter.memory_accesses++;      // ?
408357
409   for (xi = blitter.x, p = 0, b = 0, j = 1, wi = 0; j < i;)
358   for (xi = state->blitter.x, p = 0, b = 0, j = 1, wi = 0; j < i;)
410359   {
411360      if (p < bits)
412361      {
413         b = (b << 8) | blitter.mem[blitter.bitmap + j];
362         b = (b << 8) | state->blitter.mem[state->blitter.bitmap + j];
414363         j++;
415364         p += 8;
416         blitter.memory_accesses++;
365         state->blitter.memory_accesses++;
417366      }
418367      for ( ; (p >= bits); )
419368      {
420         color = blitter.color[(b >> (p - bits)) & mask];
369         color = state->blitter.color[(b >> (p - bits)) & mask];
421370         p -= bits;
422         for ( ; wi < blitter.width; wi += 0x100, xi += xdir)
371         for ( ; wi < state->blitter.width; wi += 0x100, xi += xdir)
423372         {
424373            if ((xi >= 0) && (xi < 160))
425               lynx_plot_pixel(blitter.mode, xi, y, color);
374               lynx_plot_pixel(state, state->blitter.mode, xi, y, color);
426375         }
427         wi -= blitter.width;
376         wi -= state->blitter.width;
428377      }
429378   }
430379}
431380
432381
433static void lynx_blit_2color_line(const int y, const int xdir)
382static void lynx_blit_2color_line(lynx_state *state, const int y, const int xdir)
434383{
435384   const int bits = 1;
436385   const int mask = 0x01;
437386
438   lynx_blit_do_work(y, xdir, bits, mask);
387   lynx_blit_do_work(state, y, xdir, bits, mask);
439388}
440static void lynx_blit_4color_line(const int y, const int xdir)
389static void lynx_blit_4color_line(lynx_state *state, const int y, const int xdir)
441390{
442391   const int bits = 2;
443392   const int mask = 0x03;
444393
445   lynx_blit_do_work(y, xdir, bits, mask);
394   lynx_blit_do_work(state, y, xdir, bits, mask);
446395}
447static void lynx_blit_8color_line(const int y, const int xdir)
396static void lynx_blit_8color_line(lynx_state *state, const int y, const int xdir)
448397{
449398   const int bits = 3;
450399   const int mask = 0x07;
451400
452   lynx_blit_do_work(y, xdir, bits, mask);
401   lynx_blit_do_work(state, y, xdir, bits, mask);
453402}
454static void lynx_blit_16color_line(const int y, const int xdir)
403static void lynx_blit_16color_line(lynx_state *state, const int y, const int xdir)
455404{
456405   const int bits = 4;
457406   const int mask = 0x0f;
458407
459   lynx_blit_do_work(y, xdir, bits, mask);
408   lynx_blit_do_work(state, y, xdir, bits, mask);
460409}
461410
462411/*
r9669r9670
483432 1, 4 bit count of values-1, 4 bit color, ....
484433*/
485434
486static void lynx_blit_rle_do_work( const int y, const int xdir, const int bits, const int mask )
435static void lynx_blit_rle_do_work( lynx_state *state, const int y, const int xdir, const int bits, const int mask )
487436{
488437   int wi, xi;
489438   int b, p, j;
490439   int t, count, color;
491440
492   for( p = 0, j = 0, b = 0, xi = blitter.x, wi = 0; ; )      /* through the rle entries */
441   for( p = 0, j = 0, b = 0, xi = state->blitter.x, wi = 0; ; )      /* through the rle entries */
493442   {
494443      if (p < 5 + bits) /* under 7 bits no complete entry */
495444      {
496445         j++;
497         if (j >= blitter.mem[blitter.bitmap])
446         if (j >= state->blitter.mem[state->blitter.bitmap])
498447            return;
499448
500449         p += 8;
501         b = (b << 8) | blitter.mem[blitter.bitmap + j];
502         blitter.memory_accesses++;
450         b = (b << 8) | state->blitter.mem[state->blitter.bitmap + j];
451         state->blitter.memory_accesses++;
503452      }
504453
505454      t = (b >> (p - 1)) & 0x01;
r9669r9670
514463            if (p < bits)
515464            {
516465               j++;
517               if (j >= blitter.mem[blitter.bitmap])
466               if (j >= state->blitter.mem[state->blitter.bitmap])
518467                  return;
519468               p += 8;
520               b = (b << 8) | blitter.mem[blitter.bitmap + j];
521               blitter.memory_accesses++;
469               b = (b << 8) | state->blitter.mem[state->blitter.bitmap + j];
470               state->blitter.memory_accesses++;
522471            }
523472
524            color = blitter.color[(b >> (p - bits)) & mask];
473            color = state->blitter.color[(b >> (p - bits)) & mask];
525474            p -= bits;
526            for ( ; wi < blitter.width; wi += 0x100, xi += xdir)
475            for ( ; wi < state->blitter.width; wi += 0x100, xi += xdir)
527476            {
528477               if ((xi >= 0) && (xi < 160))
529                  lynx_plot_pixel(blitter.mode, xi, y, color);
478                  lynx_plot_pixel(state, state->blitter.mode, xi, y, color);
530479            }
531            wi -= blitter.width;
480            wi -= state->blitter.width;
532481         }
533482      }
534483      else      /* count of same pixels */
r9669r9670
539488         if (p < bits)
540489         {
541490            j++;
542            if (j >= blitter.mem[blitter.bitmap])
491            if (j >= state->blitter.mem[state->blitter.bitmap])
543492               return;
544493            p += 8;
545            b = (b << 8) | blitter.mem[blitter.bitmap + j];
546            blitter.memory_accesses++;
494            b = (b << 8) | state->blitter.mem[state->blitter.bitmap + j];
495            state->blitter.memory_accesses++;
547496         }
548497
549         color = blitter.color[(b >> (p - bits)) & mask];
498         color = state->blitter.color[(b >> (p - bits)) & mask];
550499         p -= bits;
551500
552501         for ( ; count; count--)
553502         {
554            for ( ; wi < blitter.width; wi += 0x100, xi += xdir)
503            for ( ; wi < state->blitter.width; wi += 0x100, xi += xdir)
555504            {
556505               if ((xi >= 0) && (xi < 160))
557                  lynx_plot_pixel(blitter.mode, xi, y, color);
506                  lynx_plot_pixel(state, state->blitter.mode, xi, y, color);
558507            }
559            wi -= blitter.width;
508            wi -= state->blitter.width;
560509         }
561510      }
562511   }
563512}
564513
565static void lynx_blit_2color_rle_line(const int y, const int xdir)
514static void lynx_blit_2color_rle_line(lynx_state *state, const int y, const int xdir)
566515{
567516   const int bits = 1;
568517   const int mask = 0x01;
569518
570   lynx_blit_rle_do_work(y, xdir, bits, mask);
519   lynx_blit_rle_do_work(state, y, xdir, bits, mask);
571520}
572static void lynx_blit_4color_rle_line(const int y, const int xdir)
521static void lynx_blit_4color_rle_line(lynx_state *state, const int y, const int xdir)
573522{
574523   const int bits = 2;
575524   const int mask = 0x03;
576525
577   lynx_blit_rle_do_work(y, xdir, bits, mask);
526   lynx_blit_rle_do_work(state, y, xdir, bits, mask);
578527}
579static void lynx_blit_8color_rle_line(const int y, const int xdir)
528static void lynx_blit_8color_rle_line(lynx_state *state, const int y, const int xdir)
580529{
581530   const int bits = 3;
582531   const int mask = 0x07;
583532
584   lynx_blit_rle_do_work(y, xdir, bits, mask);
533   lynx_blit_rle_do_work(state, y, xdir, bits, mask);
585534}
586static void lynx_blit_16color_rle_line(const int y, const int xdir)
535static void lynx_blit_16color_rle_line(lynx_state *state, const int y, const int xdir)
587536{
588537   const int bits = 4;
589538   const int mask = 0x0f;
590539
591   lynx_blit_rle_do_work(y, xdir, bits, mask);
540   lynx_blit_rle_do_work(state, y, xdir, bits, mask);
592541}
593542
594543
595static void lynx_blit_lines(void)
544static void lynx_blit_lines(lynx_state *state)
596545{
597546   int i, hi, y;
598547   int ydir = 0, xdir = 0;
599548   int flip = 0;
600549
601   blitter.everon = FALSE;
550   state->blitter.everon = FALSE;
602551
603552   // flipping sprdemo3
604553   // fat bobby 0x10
605554   // mirror the sprite in gameplay?
606555   xdir = 1;
607556
608   if (blitter.mem[blitter.cmd] & 0x20)   /* Horizontal Flip */
557   if (state->blitter.mem[state->blitter.cmd] & 0x20)   /* Horizontal Flip */
609558   {
610559      xdir = -1;
611      blitter.x--;   /*?*/
560      state->blitter.x--;   /*?*/
612561   }
613562
614563   ydir = 1;
615564
616   if (blitter.mem[blitter.cmd] & 0x10)   /* Vertical Flip */
565   if (state->blitter.mem[state->blitter.cmd] & 0x10)   /* Vertical Flip */
617566   {
618567      ydir = -1;
619      blitter.y--;   /*?*/
568      state->blitter.y--;   /*?*/
620569   }
621570
622   switch (blitter.mem[blitter.cmd + 1] & 0x03)   /* Start Left & Start Up */
571   switch (state->blitter.mem[state->blitter.cmd + 1] & 0x03)   /* Start Left & Start Up */
623572   {
624573      case 0:
625574         flip =0;
r9669r9670
642591         break;
643592   }
644593
645   for (y = blitter.y, hi = 0; blitter.memory_accesses++, i = blitter.mem[blitter.bitmap]; blitter.bitmap += i )
594   for (y = state->blitter.y, hi = 0; state->blitter.memory_accesses++, i = state->blitter.mem[state->blitter.bitmap]; state->blitter.bitmap += i )
646595   {
647596      if (i == 1)
648597      {
r9669r9670
653602            case 0:
654603            case 2:
655604               ydir *= -1;
656               blitter.y += ydir;
605               state->blitter.y += ydir;
657606               break;
658607
659608            case 1:
660609            case 3:
661610               xdir *= -1;
662               blitter.x += xdir;
611               state->blitter.x += xdir;
663612               break;
664613         }
665614
666         y = blitter.y;
615         y = state->blitter.y;
667616         flip++;
668617         continue;
669618      }
670619
671      for ( ; (hi < blitter.height); hi += 0x100, y += ydir)
620      for ( ; (hi < state->blitter.height); hi += 0x100, y += ydir)
672621      {
673622         if (y >= 0 && y < 102)
674            blitter.line_function(y, xdir);
675         blitter.width += blitter.stretch;
676         blitter.x += blitter.tilt;
623            state->blitter.line_function(state, y, xdir);
624         state->blitter.width += state->blitter.stretch;
625         state->blitter.x += state->blitter.tilt;
677626      }
678627
679      hi -= blitter.height;
628      hi -= state->blitter.height;
680629   }
681630
682   if (suzy.data[SPRG0] & 0x04)
631   if (state->suzy.data[SPRG0] & 0x04)
683632   {
684      if (sprite_collide & !blitter.everon)
685         blitter.mem[blitter.colpos] |= 0x80;
633      if (state->sprite_collide & !state->blitter.everon)
634         state->blitter.mem[state->blitter.colpos] |= 0x80;
686635      else
687         blitter.mem[blitter.colpos] &= 0x7f;
636         state->blitter.mem[state->blitter.colpos] &= 0x7f;
688637   }
689638}
690639
691640static TIMER_CALLBACK(lynx_blitter_timer)
692641{
693   suzy.data[SPRSYS] &= ~0x01; //blitter finished
642   lynx_state *state = machine->driver_data<lynx_state>();
643   state->suzy.data[SPRSYS] &= ~0x01; //state->blitter finished
694644}
695645
696646/*
r9669r9670
768718
769719static void lynx_blitter(running_machine *machine)
770720{
721   lynx_state *state = machine->driver_data<lynx_state>();
771722   static const int lynx_colors[4]={2,4,8,16};
772723
773   static void (* const blit_line[4])(const int y, const int xdir)= {
724   static void (* const blit_line[4])(lynx_state *state, const int y, const int xdir)= {
774725   lynx_blit_2color_line,
775726   lynx_blit_4color_line,
776727   lynx_blit_8color_line,
777728   lynx_blit_16color_line
778729   };
779730
780   static void (* const blit_rle_line[4])(const int y, const int xdir)= {
731   static void (* const blit_rle_line[4])(lynx_state *state, const int y, const int xdir)= {
781732   lynx_blit_2color_rle_line,
782733   lynx_blit_4color_rle_line,
783734   lynx_blit_8color_rle_line,
r9669r9670
785736   };
786737   int i; int o;int colors;
787738
788   blitter.memory_accesses = 0;
789   blitter.mem = (UINT8*)cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(0x0000);
739   state->blitter.memory_accesses = 0;
740   state->blitter.mem = (UINT8*)cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(0x0000);
790741
791   blitter.xoff   = GET_WORD(suzy.data, 0x04);
792   blitter.yoff   = GET_WORD(suzy.data, 0x06);
793   blitter.screen = GET_WORD(suzy.data, 0x08);
794   blitter.colbuf = GET_WORD(suzy.data, 0x0a);
795   // hsizeoff GET_WORD(suzy.data, 0x28)
796   // vsizeoff GET_WORD(suzy.data, 0x2a)
742   state->blitter.xoff   = GET_WORD(state->suzy.data, 0x04);
743   state->blitter.yoff   = GET_WORD(state->suzy.data, 0x06);
744   state->blitter.screen = GET_WORD(state->suzy.data, 0x08);
745   state->blitter.colbuf = GET_WORD(state->suzy.data, 0x0a);
746   // hsizeoff GET_WORD(state->suzy.data, 0x28)
747   // vsizeoff GET_WORD(state->suzy.data, 0x2a)
797748
798   // these might be never set by the blitter hardware
799   blitter.width   = 0x100;
800   blitter.height  = 0x100;
801   blitter.stretch = 0;
802   blitter.tilt    = 0;
803   sprite_collide  = 0;
749   // these might be never set by the state->blitter hardware
750   state->blitter.width   = 0x100;
751   state->blitter.height  = 0x100;
752   state->blitter.stretch = 0;
753   state->blitter.tilt    = 0;
754   state->sprite_collide  = 0;
804755
805   blitter.memory_accesses += 2;
756   state->blitter.memory_accesses += 2;
806757
807   for (blitter.cmd = GET_WORD(suzy.data, 0x10); blitter.cmd; )
758   for (state->blitter.cmd = GET_WORD(state->suzy.data, 0x10); state->blitter.cmd; )
808759   {
809      blitter.memory_accesses += 1;
760      state->blitter.memory_accesses += 1;
810761
811      if (!(blitter.mem[blitter.cmd + 1] & 0x04))      // if 0, we skip this sprite
762      if (!(state->blitter.mem[state->blitter.cmd + 1] & 0x04))      // if 0, we skip this sprite
812763      {
813         blitter.colpos = GET_WORD(suzy.data, 0x24) + blitter.cmd;
764         state->blitter.colpos = GET_WORD(state->suzy.data, 0x24) + state->blitter.cmd;
814765
815         blitter.bitmap = GET_WORD(blitter.mem,blitter.cmd + 5);
816         blitter.x = (INT16)GET_WORD(blitter.mem, blitter.cmd + 7) - blitter.xoff;
817         blitter.y = (INT16)GET_WORD(blitter.mem, blitter.cmd + 9) - blitter.yoff;
818         blitter.memory_accesses += 6;
766         state->blitter.bitmap = GET_WORD(state->blitter.mem,state->blitter.cmd + 5);
767         state->blitter.x = (INT16)GET_WORD(state->blitter.mem, state->blitter.cmd + 7) - state->blitter.xoff;
768         state->blitter.y = (INT16)GET_WORD(state->blitter.mem, state->blitter.cmd + 9) - state->blitter.yoff;
769         state->blitter.memory_accesses += 6;
819770
820         blitter.mode = blitter.mem[blitter.cmd] & 0x07;
771         state->blitter.mode = state->blitter.mem[state->blitter.cmd] & 0x07;
821772
822         if (blitter.mem[blitter.cmd + 1] & 0x80)
823            blitter.line_function = blit_line[blitter.mem[blitter.cmd] >> 6];
773         if (state->blitter.mem[state->blitter.cmd + 1] & 0x80)
774            state->blitter.line_function = blit_line[state->blitter.mem[state->blitter.cmd] >> 6];
824775         else
825            blitter.line_function = blit_rle_line[blitter.mem[blitter.cmd] >> 6];
776            state->blitter.line_function = blit_rle_line[state->blitter.mem[state->blitter.cmd] >> 6];
826777
827         if (!(blitter.mem[blitter.cmd + 2] & 0x20) && !(suzy.data[SPRSYS] & 0x20))
778         if (!(state->blitter.mem[state->blitter.cmd + 2] & 0x20) && !(state->suzy.data[SPRSYS] & 0x20))
828779         {
829            switch (blitter.mode)
780            switch (state->blitter.mode)
830781            {
831782               case BACKGROUND:
832783               case BOUNDARY_SHADOW:
r9669r9670
834785               case NORMAL_SPRITE:
835786               case XOR_SPRITE:
836787               case SHADOW:
837                  sprite_collide = 1;
838                  blitter.mem[blitter.colpos] = 0;
839                  blitter.spritenr = blitter.mem[blitter.cmd + 2] & 0x0f;
788                  state->sprite_collide = 1;
789                  state->blitter.mem[state->blitter.colpos] = 0;
790                  state->blitter.spritenr = state->blitter.mem[state->blitter.cmd + 2] & 0x0f;
840791            }
841792         }
842793
843794         /* Sprite Reload Bits */
844795         o = 0x0b;
845         if (blitter.mem[blitter.cmd + 1] & 0x30)
796         if (state->blitter.mem[state->blitter.cmd + 1] & 0x30)
846797         {
847            blitter.width  = GET_WORD(blitter.mem, blitter.cmd + 11);
848            blitter.height = GET_WORD(blitter.mem, blitter.cmd + 13);
849            blitter.memory_accesses += 4;
798            state->blitter.width  = GET_WORD(state->blitter.mem, state->blitter.cmd + 11);
799            state->blitter.height = GET_WORD(state->blitter.mem, state->blitter.cmd + 13);
800            state->blitter.memory_accesses += 4;
850801            o += 4;
851802         }
852         if (blitter.mem[blitter.cmd + 1] & 0x20)
803         if (state->blitter.mem[state->blitter.cmd + 1] & 0x20)
853804         {
854            blitter.stretch = GET_WORD(blitter.mem, blitter.cmd + o);
855            blitter.memory_accesses += 2;
805            state->blitter.stretch = GET_WORD(state->blitter.mem, state->blitter.cmd + o);
806            state->blitter.memory_accesses += 2;
856807            o += 2;
857            if (blitter.mem[blitter.cmd + 1] & 0x10)
808            if (state->blitter.mem[state->blitter.cmd + 1] & 0x10)
858809            {
859               blitter.tilt = GET_WORD(blitter.mem, blitter.cmd+o);
860               blitter.memory_accesses += 2;
810               state->blitter.tilt = GET_WORD(state->blitter.mem, state->blitter.cmd+o);
811               state->blitter.memory_accesses += 2;
861812               o += 2;
862813            }
863814         }
864815
865816         /* Reload Palette Bit */
866         colors = lynx_colors[blitter.mem[blitter.cmd] >> 6];
817         colors = lynx_colors[state->blitter.mem[state->blitter.cmd] >> 6];
867818
868         if (!(blitter.mem[blitter.cmd + 1] & 0x08))
819         if (!(state->blitter.mem[state->blitter.cmd + 1] & 0x08))
869820         {
870821            for (i = 0; i < colors / 2; i++)
871822            {
872               blitter.color[i * 2]      = blitter.mem[blitter.cmd + o + i] >> 4;
873               blitter.color[i * 2 + 1 ] = blitter.mem[blitter.cmd + o + i] & 0x0f;
874               blitter.memory_accesses++;
823               state->blitter.color[i * 2]      = state->blitter.mem[state->blitter.cmd + o + i] >> 4;
824               state->blitter.color[i * 2 + 1 ] = state->blitter.mem[state->blitter.cmd + o + i] & 0x0f;
825               state->blitter.memory_accesses++;
875826            }
876827         }
877828
878829         /* Draw Sprites */
879         lynx_blit_lines();
830         lynx_blit_lines(state);
880831      }
881832
882   blitter.cmd = GET_WORD(blitter.mem,  blitter.cmd + 3);
883   blitter.memory_accesses += 2;
833   state->blitter.cmd = GET_WORD(state->blitter.mem,  state->blitter.cmd + 3);
834   state->blitter.memory_accesses += 2;
884835
885   if (!(blitter.cmd & 0xff00))
836   if (!(state->blitter.cmd & 0xff00))
886837      break;
887838   }
888839
889840   if (0)
890      timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(blitter.memory_accesses*20), NULL, 0, lynx_blitter_timer);
841      timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(state->blitter.memory_accesses*20), NULL, 0, lynx_blitter_timer);
891842}
892843
893844
r9669r9670
908859- in divide, the remainder will have 2 possible errors, depending on its actual value (no further
909860notes on these errors available) */
910861
911static void lynx_divide( void )
862static void lynx_divide( lynx_state *state )
912863{
913864   UINT32 left;
914865   UINT16 right;
r9669r9670
922873    Remainder (JK)LM
923874    */
924875
925   left = suzy.data[MATH_H] | (suzy.data[MATH_G] << 8) | (suzy.data[MATH_F] << 16) | (suzy.data[MATH_E] << 24);
926   right = suzy.data[MATH_P] | (suzy.data[MATH_N] << 8);
876   left = state->suzy.data[MATH_H] | (state->suzy.data[MATH_G] << 8) | (state->suzy.data[MATH_F] << 16) | (state->suzy.data[MATH_E] << 24);
877   right = state->suzy.data[MATH_P] | (state->suzy.data[MATH_N] << 8);
927878
928   suzy.accumulate_overflow = FALSE;
879   state->suzy.accumulate_overflow = FALSE;
929880   if (right == 0)
930881   {
931      suzy.accumulate_overflow = TRUE;   /* during divisions, this bit is used to detect denominator = 0 */
882      state->suzy.accumulate_overflow = TRUE;   /* during divisions, this bit is used to detect denominator = 0 */
932883      res = 0xffffffff;
933884      mod = 0; //?
934885   }
r9669r9670
938889      mod = left % right;
939890   }
940891//  logerror("coprocessor %8x / %8x = %4x\n", left, right, res);
941   suzy.data[MATH_D] = res & 0xff;
942   suzy.data[MATH_C] = res >> 8;
943   suzy.data[MATH_B] = res >> 16;
944   suzy.data[MATH_A] = res >> 24;
892   state->suzy.data[MATH_D] = res & 0xff;
893   state->suzy.data[MATH_C] = res >> 8;
894   state->suzy.data[MATH_B] = res >> 16;
895   state->suzy.data[MATH_A] = res >> 24;
945896
946   suzy.data[MATH_M] = mod & 0xff;
947   suzy.data[MATH_L] = mod >> 8;
948   suzy.data[MATH_K] = mod >> 16;
949   suzy.data[MATH_J] = mod >> 24;
897   state->suzy.data[MATH_M] = mod & 0xff;
898   state->suzy.data[MATH_L] = mod >> 8;
899   state->suzy.data[MATH_K] = mod >> 16;
900   state->suzy.data[MATH_J] = mod >> 24;
950901}
951902
952static void lynx_multiply( void )
903static void lynx_multiply( lynx_state *state )
953904{
954905   UINT16 left, right;
955906   UINT32 res, accu;
r9669r9670
961912                EFGH
962913    Accumulate  JKLM
963914    */
964   suzy.accumulate_overflow = FALSE;
915   state->suzy.accumulate_overflow = FALSE;
965916
966   left = suzy.data[MATH_B] | (suzy.data[MATH_A] << 8);
967   right = suzy.data[MATH_D] | (suzy.data[MATH_C] << 8);
917   left = state->suzy.data[MATH_B] | (state->suzy.data[MATH_A] << 8);
918   right = state->suzy.data[MATH_D] | (state->suzy.data[MATH_C] << 8);
968919
969920   res = left * right;
970921
971   if (suzy.data[SPRSYS] & 0x80)      /* signed math */
922   if (state->suzy.data[SPRSYS] & 0x80)      /* signed math */
972923   {
973      if (!(sign_AB + sign_CD))   /* different signs */
924      if (!(state->sign_AB + state->sign_CD))   /* different signs */
974925         res = (res ^ 0xffffffff) + 1;
975926   }
976927
977   suzy.data[MATH_H] = res & 0xff;
978   suzy.data[MATH_G] = res >> 8;
979   suzy.data[MATH_F] = res >> 16;
980   suzy.data[MATH_E] = res >> 24;
928   state->suzy.data[MATH_H] = res & 0xff;
929   state->suzy.data[MATH_G] = res >> 8;
930   state->suzy.data[MATH_F] = res >> 16;
931   state->suzy.data[MATH_E] = res >> 24;
981932
982   if (suzy.data[SPRSYS] & 0x40)      /* is accumulation allowed? */
933   if (state->suzy.data[SPRSYS] & 0x40)      /* is accumulation allowed? */
983934   {
984      accu = suzy.data[MATH_M] | suzy.data[MATH_L] << 8 | suzy.data[MATH_K] << 16 | suzy.data[MATH_J] << 24;
935      accu = state->suzy.data[MATH_M] | state->suzy.data[MATH_L] << 8 | state->suzy.data[MATH_K] << 16 | state->suzy.data[MATH_J] << 24;
985936      accu += res;
986937
987938      if (accu < res)
988         suzy.accumulate_overflow = TRUE;
939         state->suzy.accumulate_overflow = TRUE;
989940
990      suzy.data[MATH_M] = accu;
991      suzy.data[MATH_L] = accu >> 8;
992      suzy.data[MATH_K] = accu >> 16;
993      suzy.data[MATH_J] = accu >> 24;
941      state->suzy.data[MATH_M] = accu;
942      state->suzy.data[MATH_L] = accu >> 8;
943      state->suzy.data[MATH_K] = accu >> 16;
944      state->suzy.data[MATH_J] = accu >> 24;
994945   }
995946}
996947
997948static READ8_HANDLER( suzy_read )
998949{
950   lynx_state *state = space->machine->driver_data<lynx_state>();
999951   UINT8 value = 0, input;
1000952
1001953   switch (offset)
r9669r9670
1004956         value = 0x01; // must not be 0 for correct power up
1005957         break;
1006958      case 0x92:   /* Better check this with docs! */
1007         if (!attotime_compare(blitter.time, attotime_zero))
959         if (!attotime_compare(state->blitter.time, attotime_zero))
1008960         {
1009            if (space->machine->device<cpu_device>("maincpu")->attotime_to_cycles(attotime_sub(timer_get_time(space->machine), blitter.time)) > blitter.memory_accesses * 20)
961            if (space->machine->device<cpu_device>("maincpu")->attotime_to_cycles(attotime_sub(timer_get_time(space->machine), state->blitter.time)) > state->blitter.memory_accesses * 20)
1010962            {
1011               suzy.data[offset] &= ~0x01; //blitter finished
1012               blitter.time = attotime_zero;
963               state->suzy.data[offset] &= ~0x01; //state->blitter finished
964               state->blitter.time = attotime_zero;
1013965            }
1014966         }
1015         value = suzy.data[offset];
967         value = state->suzy.data[offset];
1016968         value &= ~0x80; // math finished
1017969         value &= ~0x40;
1018         if (suzy.accumulate_overflow)
970         if (state->suzy.accumulate_overflow)
1019971            value |= 0x40;
1020972         break;
1021973      case 0xb0:
1022974         input = input_port_read(space->machine, "JOY");
1023         switch (lynx_rotate)
975         switch (state->rotate)
1024976         {
1025977            case 1:
1026978               value = input;
r9669r9670
1039991               if (value & PAD_LEFT) input |= PAD_UP;
1040992               break;
1041993         }
1042         if (suzy.data[SPRSYS] & 0x08) /* Left handed controls */
994         if (state->suzy.data[SPRSYS] & 0x08) /* Left handed controls */
1043995         {
1044996            value = input & 0x0f;
1045997            if (input & PAD_UP) value |= PAD_DOWN;
r9669r9670
10541006         value = input_port_read(space->machine, "PAUSE");
10551007         break;
10561008      case 0xb2:
1057         value = *(memory_region(space->machine, "user1") + (suzy.high * lynx_granularity) + suzy.low);
1058         suzy.low = (suzy.low + 1) & (lynx_granularity - 1);
1009         value = *(memory_region(space->machine, "user1") + (state->suzy.high * state->granularity) + state->suzy.low);
1010         state->suzy.low = (state->suzy.low + 1) & (state->granularity - 1);
10591011         break;
10601012      case 0xb3: /* we need bank 1 emulation!!! */
10611013      default:
1062         value = suzy.data[offset];
1014         value = state->suzy.data[offset];
10631015   }
10641016//  logerror("suzy read %.2x %.2x\n",offset,data);
10651017   return value;
r9669r9670
10671019
10681020static WRITE8_HANDLER( suzy_write )
10691021{
1070   suzy.data[offset] = data;
1022   lynx_state *state = space->machine->driver_data<lynx_state>();
1023   state->suzy.data[offset] = data;
10711024
10721025   /* Additional effects of a write */
10731026   /* Even addresses are the LSB. Any CPU write to an LSB in 0x00-0x7f will set the MSB to 0. */
r9669r9670
10861039   case 0x70: case 0x72: case 0x74: case 0x76: case 0x78: case 0x7a: case 0x7c: case 0x7e:
10871040   /* B, D, F, H , K */
10881041   case 0x52: case 0x54: case 0x60: case 0x62: case 0x6e:
1089      suzy.data[offset + 1] = 0;
1042      state->suzy.data[offset + 1] = 0;
10901043      break;
10911044   /* Writing to M (0x6c) will also clear the accumulator overflow bit */
10921045   case 0x6c:
1093      suzy.data[offset + 1] = 0;
1094      suzy.accumulate_overflow = FALSE;
1046      state->suzy.data[offset + 1] = 0;
1047      state->suzy.accumulate_overflow = FALSE;
10951048      break;
10961049   case 0x53:
10971050   /* If we are going to perform a signed multiplication, we store the sign and convert the number
10981051    to an unsigned one */
1099      if (suzy.data[SPRSYS] & 0x80)      /* signed math */
1052      if (state->suzy.data[SPRSYS] & 0x80)      /* signed math */
11001053      {
11011054         UINT16 factor, temp;
1102         factor = suzy.data[MATH_D] | (suzy.data[MATH_C] << 8);
1055         factor = state->suzy.data[MATH_D] | (state->suzy.data[MATH_C] << 8);
11031056         if ((factor - 1) & 0x8000)      /* here we use -1 to cover the math bugs on the sign of 0 and 0x8000 */
11041057         {
11051058            temp = (factor ^ 0xffff) + 1;
1106            sign_CD = - 1;
1107            suzy.data[MATH_D] = temp & 0xff;
1108            suzy.data[MATH_C] = temp >> 8;
1059            state->sign_CD = - 1;
1060            state->suzy.data[MATH_D] = temp & 0xff;
1061            state->suzy.data[MATH_C] = temp >> 8;
11091062         }
11101063         else
1111            sign_CD = 1;
1064            state->sign_CD = 1;
11121065      }
11131066      break;
11141067   /* Writing to A will start a 16 bit multiply */
11151068   /* If we are going to perform a signed multiplication, we also store the sign and convert the
11161069    number to an unsigned one */
11171070   case 0x55:
1118      if (suzy.data[SPRSYS] & 0x80)      /* signed math */
1071      if (state->suzy.data[SPRSYS] & 0x80)      /* signed math */
11191072      {
11201073         UINT16 factor, temp;
1121         factor = suzy.data[MATH_B] | (suzy.data[MATH_A] << 8);
1074         factor = state->suzy.data[MATH_B] | (state->suzy.data[MATH_A] << 8);
11221075         if ((factor - 1) & 0x8000)      /* here we use -1 to cover the math bugs on the sign of 0 and 0x8000 */
11231076         {
11241077            temp = (factor ^ 0xffff) + 1;
1125            sign_AB = - 1;
1126            suzy.data[MATH_B] = temp & 0xff;
1127            suzy.data[MATH_A] = temp >> 8;
1078            state->sign_AB = - 1;
1079            state->suzy.data[MATH_B] = temp & 0xff;
1080            state->suzy.data[MATH_A] = temp >> 8;
11281081         }
11291082         else
1130            sign_AB = 1;
1083            state->sign_AB = 1;
11311084      }
1132      lynx_multiply();
1085      lynx_multiply(state);
11331086      break;
11341087   /* Writing to E will start a 16 bit divide */
11351088   case 0x63:
1136      lynx_divide();
1089      lynx_divide(state);
11371090      break;
11381091   case 0x91:
11391092      if (data & 0x01)
11401093      {
1141         blitter.time = timer_get_time(space->machine);
1094         state->blitter.time = timer_get_time(space->machine);
11421095         lynx_blitter(space->machine);
11431096      }
11441097      break;
r9669r9670
11651118 0xfdb0-f rw bit0..3 farben 0..15
11661119*/
11671120
1168typedef struct {
1169   UINT8 data[0x100];
1170} MIKEY;
11711121
1172static MIKEY mikey;
11731122
1174
1175static UINT8 lynx_read_vram(UINT16 address)
1123static UINT8 lynx_read_vram(lynx_state *state, UINT16 address)
11761124{
11771125   UINT8 result = 0x00;
11781126   if (address <= 0xfbff)
1179      result = lynx_mem_0000[address - 0x0000];
1127      result = state->mem_0000[address - 0x0000];
11801128   else if (address <= 0xfcff)
1181      result = lynx_mem_fc00[address - 0xfc00];
1129      result = state->mem_fc00[address - 0xfc00];
11821130   else if (address <= 0xfdff)
1183      result = lynx_mem_fd00[address - 0xfd00];
1131      result = state->mem_fd00[address - 0xfd00];
11841132   else if (address <= 0xfff7)
1185      result = lynx_mem_fe00[address - 0xfe00];
1133      result = state->mem_fe00[address - 0xfe00];
11861134   else if (address >= 0xfffa)
1187      result = lynx_mem_fffa[address - 0xfffa];
1135      result = state->mem_fffa[address - 0xfffa];
11881136   return result;
11891137}
11901138
r9669r9670
11981146; B1    1 EQU flip screen
11991147; B0    1 EQU video DMA enabled
12001148*/
1201static int lynx_height, lynx_width;
12021149static void lynx_draw_lines(running_machine *machine, int newline)
12031150{
1151   lynx_state *state = machine->driver_data<lynx_state>();
12041152   int h,w;
12051153   int x, yend;
12061154   UINT16 j; // clipping needed!
r9669r9670
12151163   if (yend > 102)
12161164      yend = 102;
12171165
1218   if (yend == lynx_line_y)
1166   if (yend == state->line_y)
12191167   {
12201168      if (newline == -1)
1221         lynx_line_y = 0;
1169         state->line_y = 0;
12221170      return;
12231171   }
12241172
1225   j = (mikey.data[0x94] | (mikey.data[0x95]<<8)) + lynx_line_y * 160 / 2;
1226   if (mikey.data[0x92] & 0x02)
1173   j = (state->mikey.data[0x94] | (state->mikey.data[0x95]<<8)) + state->line_y * 160 / 2;
1174   if (state->mikey.data[0x92] & 0x02)
12271175      j -= 160 * 102 / 2 - 1;
12281176
12291177   /* rotation */
1230   if (lynx_rotate & 0x03)
1178   if (state->rotate & 0x03)
12311179   {
12321180      h = 160; w = 102;
1233      if (((lynx_rotate == 1) && (mikey.data[0x92] & 0x02)) || ((lynx_rotate == 2) && !(mikey.data[0x92] & 0x02)))
1181      if (((state->rotate == 1) && (state->mikey.data[0x92] & 0x02)) || ((state->rotate == 2) && !(state->mikey.data[0x92] & 0x02)))
12341182      {
1235         for ( ; lynx_line_y < yend; lynx_line_y++)
1183         for ( ; state->line_y < yend; state->line_y++)
12361184         {
1237            line = BITMAP_ADDR16(machine->generic.tmpbitmap, lynx_line_y, 0);
1185            line = BITMAP_ADDR16(machine->generic.tmpbitmap, state->line_y, 0);
12381186            for (x = 160 - 2; x >= 0; j++, x -= 2)
12391187            {
1240               byte = lynx_read_vram(j);
1241               line[x + 1] = lynx_palette[(byte >> 4) & 0x0f];
1242               line[x + 0] = lynx_palette[(byte >> 0) & 0x0f];
1188               byte = lynx_read_vram(state, j);
1189               line[x + 1] = state->palette[(byte >> 4) & 0x0f];
1190               line[x + 0] = state->palette[(byte >> 0) & 0x0f];
12431191            }
12441192         }
12451193      }
12461194      else
12471195      {
1248         for ( ; lynx_line_y < yend; lynx_line_y++)
1196         for ( ; state->line_y < yend; state->line_y++)
12491197         {
1250            line = BITMAP_ADDR16(machine->generic.tmpbitmap, 102 - 1 - lynx_line_y, 0);
1198            line = BITMAP_ADDR16(machine->generic.tmpbitmap, 102 - 1 - state->line_y, 0);
12511199            for (x = 0; x < 160; j++, x += 2)
12521200            {
1253               byte = lynx_read_vram(j);
1254               line[x + 0] = lynx_palette[(byte >> 4) & 0x0f];
1255               line[x + 1] = lynx_palette[(byte >> 0) & 0x0f];
1201               byte = lynx_read_vram(state, j);
1202               line[x + 0] = state->palette[(byte >> 4) & 0x0f];
1203               line[x + 1] = state->palette[(byte >> 0) & 0x0f];
12561204            }
12571205         }
12581206      }
r9669r9670
12601208   else
12611209   {
12621210      w = 160; h = 102;
1263      if (mikey.data[0x92] & 0x02)
1211      if (state->mikey.data[0x92] & 0x02)
12641212      {
1265         for ( ; lynx_line_y < yend; lynx_line_y++)
1213         for ( ; state->line_y < yend; state->line_y++)
12661214         {
1267            line = BITMAP_ADDR16(machine->generic.tmpbitmap, 102 - 1 - lynx_line_y, 0);
1215            line = BITMAP_ADDR16(machine->generic.tmpbitmap, 102 - 1 - state->line_y, 0);
12681216            for (x = 160 - 2; x >= 0; j++, x -= 2)
12691217            {
1270               byte = lynx_read_vram(j);
1271               line[x + 1] = lynx_palette[(byte >> 4) & 0x0f];
1272               line[x + 0] = lynx_palette[(byte >> 0) & 0x0f];
1218               byte = lynx_read_vram(state, j);
1219               line[x + 1] = state->palette[(byte >> 4) & 0x0f];
1220               line[x + 0] = state->palette[(byte >> 0) & 0x0f];
12731221            }
12741222         }
12751223      }
12761224      else
12771225      {
1278         for ( ; lynx_line_y < yend; lynx_line_y++)
1226         for ( ; state->line_y < yend; state->line_y++)
12791227         {
1280            line = BITMAP_ADDR16(machine->generic.tmpbitmap, lynx_line_y, 0);
1228            line = BITMAP_ADDR16(machine->generic.tmpbitmap, state->line_y, 0);
12811229            for (x = 0; x < 160; j++, x += 2)
12821230            {
1283               byte = lynx_read_vram(j);
1284               line[x + 0] = lynx_palette[(byte >> 4) & 0x0f];
1285               line[x + 1] = lynx_palette[(byte >> 0) & 0x0f];
1231               byte = lynx_read_vram(state, j);
1232               line[x + 0] = state->palette[(byte >> 4) & 0x0f];
1233               line[x + 1] = state->palette[(byte >> 0) & 0x0f];
12861234            }
12871235         }
12881236      }
12891237   }
12901238   if (newline == -1)
12911239   {
1292      lynx_line_y = 0;
1293      if ((w != lynx_width) || (h != lynx_height))
1240      state->line_y = 0;
1241      if ((w != state->width) || (h != state->height))
12941242      {
1295         lynx_width = w;
1296         lynx_height = h;
1243         state->width = w;
1244         state->height = h;
12971245         machine->primary_screen->set_visible_area(0, w - 1, 0, h - 1);
12981246      }
12991247   }
r9669r9670
13391287TIM_BORROWIN    EQU %00000010
13401288TIM_BORROWOUT   EQU %00000001
13411289*/
1342typedef struct {
1343   UINT8   bakup;
1344   UINT8   cntrl1;
1345   UINT8   cntrl2;
1346   int      counter;
1347   emu_timer   *timer;
1348   int      timer_active;
1349} LYNX_TIMER;
13501290
13511291#define NR_LYNX_TIMERS   8
13521292
1353static LYNX_TIMER lynx_timer[NR_LYNX_TIMERS];
13541293
13551294static TIMER_CALLBACK(lynx_timer_shot);
13561295
13571296static void lynx_timer_init(running_machine *machine, int which)
13581297{
1359   memset( &lynx_timer[which], 0, sizeof(LYNX_TIMER) );
1360   lynx_timer[which].timer = timer_alloc(machine,  lynx_timer_shot , NULL);
1298   lynx_state *state = machine->driver_data<lynx_state>();
1299   memset( &state->timer[which], 0, sizeof(LYNX_TIMER) );
1300   state->timer[which].timer = timer_alloc(machine,  lynx_timer_shot , NULL);
13611301}
13621302
13631303static void lynx_timer_signal_irq(running_machine *machine, int which)
13641304{
1365   if ( ( lynx_timer[which].cntrl1 & 0x80 ) && ( which != 4 ) )
1305   lynx_state *state = machine->driver_data<lynx_state>();
1306   if ( ( state->timer[which].cntrl1 & 0x80 ) && ( which != 4 ) )
13661307   { // irq flag handling later
1367      mikey.data[0x81] |= ( 1 << which );
1308      state->mikey.data[0x81] |= ( 1 << which );
13681309      cputag_set_input_line(machine, "maincpu", M65SC02_IRQ_LINE, ASSERT_LINE);
13691310   }
13701311   switch ( which )
13711312   {
13721313   case 0:
13731314      lynx_timer_count_down( machine, 2 );
1374      lynx_line++;
1315      state->line++;
13751316      break;
13761317   case 2:
13771318      lynx_timer_count_down( machine, 4 );
13781319      lynx_draw_lines( machine, -1 );
1379      lynx_line=0;
1320      state->line=0;
13801321      break;
13811322   case 1:
13821323      lynx_timer_count_down( machine, 3 );
r9669r9670
13881329      lynx_timer_count_down( machine, 7 );
13891330      break;
13901331   case 7:
1391      lynx_audio_count_down( lynx_audio, 0 );
1332      lynx_audio_count_down( state->audio, 0 );
13921333      break;
13931334   }
13941335}
13951336
13961337void lynx_timer_count_down(running_machine *machine, int which)
13971338{
1398   if ( ( lynx_timer[which].cntrl1 & 0x0f ) == 0x0f )
1339   lynx_state *state = machine->driver_data<lynx_state>();
1340   if ( ( state->timer[which].cntrl1 & 0x0f ) == 0x0f )
13991341   {
1400      if ( lynx_timer[which].counter > 0 )
1342      if ( state->timer[which].counter > 0 )
14011343      {
1402         lynx_timer[which].counter--;
1344         state->timer[which].counter--;
14031345         return;
14041346      }
1405      if ( lynx_timer[which].counter == 0 )
1347      if ( state->timer[which].counter == 0 )
14061348      {
1407         lynx_timer[which].cntrl2 |= 8;
1349         state->timer[which].cntrl2 |= 8;
14081350         lynx_timer_signal_irq(machine, which);
1409         if ( lynx_timer[which].cntrl1 & 0x10 )
1351         if ( state->timer[which].cntrl1 & 0x10 )
14101352         {
1411            lynx_timer[which].counter = lynx_timer[which].bakup;
1353            state->timer[which].counter = state->timer[which].bakup;
14121354         }
14131355         else
14141356         {
1415            lynx_timer[which].counter--;
1357            state->timer[which].counter--;
14161358         }
14171359         return;
14181360      }
r9669r9670
14211363
14221364static TIMER_CALLBACK(lynx_timer_shot)
14231365{
1424   lynx_timer[param].cntrl2 |= 8;
1366   lynx_state *state = machine->driver_data<lynx_state>();
1367   state->timer[param].cntrl2 |= 8;
14251368   lynx_timer_signal_irq( machine, param );
1426   if ( ! ( lynx_timer[param].cntrl1 & 0x10 ) )
1427      lynx_timer[param].timer_active = 0;
1369   if ( ! ( state->timer[param].cntrl1 & 0x10 ) )
1370      state->timer[param].timer_active = 0;
14281371}
14291372
14301373static UINT32 lynx_time_factor(int val)
r9669r9670
14421385   }
14431386}
14441387
1445static UINT8 lynx_timer_read(int which, int offset)
1388static UINT8 lynx_timer_read(lynx_state *state, int which, int offset)
14461389{
14471390   UINT8 value = 0;
14481391
14491392   switch (offset)
14501393   {
14511394      case 0:
1452         value = lynx_timer[which].bakup;
1395         value = state->timer[which].bakup;
14531396         break;
14541397      case 1:
1455         value = lynx_timer[which].cntrl1;
1398         value = state->timer[which].cntrl1;
14561399         break;
14571400      case 2:
1458         if ((lynx_timer[which].cntrl1 & 0x07) == 0x07)
1401         if ((state->timer[which].cntrl1 & 0x07) == 0x07)
14591402         {
1460            value = lynx_timer[which].counter;
1403            value = state->timer[which].counter;
14611404         }
14621405         else
14631406         {
1464            if ( lynx_timer[which].timer_active )
1465               value = (UINT8) ( lynx_timer[which].bakup - attotime_mul(timer_timeleft(lynx_timer[which].timer), lynx_time_factor( lynx_timer[which].cntrl1 & 0x07 )).seconds);
1407            if ( state->timer[which].timer_active )
1408               value = (UINT8) ( state->timer[which].bakup - attotime_mul(timer_timeleft(state->timer[which].timer), lynx_time_factor( state->timer[which].cntrl1 & 0x07 )).seconds);
14661409         }
14671410         break;
14681411
14691412      case 3:
1470         value = lynx_timer[which].cntrl2;
1413         value = state->timer[which].cntrl2;
14711414         break;
14721415   }
14731416   logerror("timer %d read %x %.2x\n", which, offset, value);
14741417   return value;
14751418}
14761419
1477static void lynx_timer_write(int which, int offset, UINT8 data)
1420static void lynx_timer_write(lynx_state *state, int which, int offset, UINT8 data)
14781421{
14791422   logerror("timer %d write %x %.2x\n", which, offset, data);
14801423
14811424   switch (offset)
14821425   {
14831426      case 0:
1484         lynx_timer[which].bakup = data;
1427         state->timer[which].bakup = data;
14851428         break;
14861429      case 1:
1487         lynx_timer[which].cntrl1 = data;
1430         state->timer[which].cntrl1 = data;
14881431         if (data & 0x40)
1489            lynx_timer[which].cntrl2 &= ~0x08;
1432            state->timer[which].cntrl2 &= ~0x08;
14901433         break;
14911434      case 2:
1492//          lynx_timer[which].counter = data;   // why commented out?
1435//          state->timer[which].counter = data;   // why commented out?
14931436         break;
14941437      case 3:
1495         lynx_timer[which].cntrl2 = (lynx_timer[which].cntrl2 & 0x08) | (data & ~0x08);
1438         state->timer[which].cntrl2 = (state->timer[which].cntrl2 & 0x08) | (data & ~0x08);
14961439         break;
14971440   }
14981441
14991442   /* Update timers */
15001443   if ( offset < 3 )
15011444   {
1502      timer_reset(lynx_timer[which].timer, attotime_never);
1503      lynx_timer[which].timer_active = 0;
1504      if ((lynx_timer[which].cntrl1 & 0x08))      // 0x48?
1445      timer_reset(state->timer[which].timer, attotime_never);
1446      state->timer[which].timer_active = 0;
1447      if ((state->timer[which].cntrl1 & 0x08))      // 0x48?
15051448      {
1506         if ((lynx_timer[which].cntrl1 & 0x07) != 0x07)
1449         if ((state->timer[which].cntrl1 & 0x07) != 0x07)
15071450         {
1508            attotime t = attotime_mul(ATTOTIME_IN_HZ(lynx_time_factor(lynx_timer[which].cntrl1 & 0x07)), lynx_timer[which].bakup + 1);
1509            if (lynx_timer[which].cntrl1 & 0x10)
1510               timer_adjust_periodic(lynx_timer[which].timer, attotime_zero, which, t);
1451            attotime t = attotime_mul(ATTOTIME_IN_HZ(lynx_time_factor(state->timer[which].cntrl1 & 0x07)), state->timer[which].bakup + 1);
1452            if (state->timer[which].cntrl1 & 0x10)
1453               timer_adjust_periodic(state->timer[which].timer, attotime_zero, which, t);
15111454            else
1512               timer_adjust_oneshot(lynx_timer[which].timer, t, which);
1513            lynx_timer[which].timer_active = 1;
1455               timer_adjust_oneshot(state->timer[which].timer, t, which);
1456            state->timer[which].timer_active = 1;
15141457         }
15151458      }
15161459   }
r9669r9670
15241467****************************************/
15251468
15261469
1527static struct {
1528   UINT8 serctl;
1529   UINT8 data_received, data_to_send, buffer;
1530
1531   int received;
1532   int sending;
1533   int buffer_loaded;
1534} uart;
1535
1536static void lynx_uart_reset(void)
1470static void lynx_uart_reset(lynx_state *state)
15371471{
1538   memset(&uart, 0, sizeof(uart));
1472   memset(&state->uart, 0, sizeof(state->uart));
15391473}
15401474
15411475static TIMER_CALLBACK(lynx_uart_timer)
15421476{
1543   if (uart.buffer_loaded)
1477   lynx_state *state = machine->driver_data<lynx_state>();
1478   if (state->uart.buffer_loaded)
15441479   {
1545      uart.data_to_send = uart.buffer;
1546      uart.buffer_loaded = FALSE;
1480      state->uart.data_to_send = state->uart.buffer;
1481      state->uart.buffer_loaded = FALSE;
15471482      timer_set(machine, ATTOTIME_IN_USEC(11), NULL, 0, lynx_uart_timer);
15481483   }
15491484   else
1550      uart.sending = FALSE;
1485      state->uart.sending = FALSE;
15511486
1552//    mikey.data[0x80]|=0x10;
1553   if (uart.serctl & 0x80)
1487//    state->mikey.data[0x80]|=0x10;
1488   if (state->uart.serctl & 0x80)
15541489   {
1555      mikey.data[0x81] |= 0x10;
1490      state->mikey.data[0x81] |= 0x10;
15561491      cputag_set_input_line(machine, "maincpu", M65SC02_IRQ_LINE, ASSERT_LINE);
15571492   }
15581493}
15591494
15601495static  READ8_HANDLER(lynx_uart_r)
15611496{
1497   lynx_state *state = space->machine->driver_data<lynx_state>();
15621498   UINT8 value = 0x00;
15631499   switch (offset)
15641500   {
15651501      case 0x8c:
1566         if (!uart.buffer_loaded)
1502         if (!state->uart.buffer_loaded)
15671503            value |= 0x80;
1568         if (uart.received)
1504         if (state->uart.received)
15691505            value |= 0x40;
1570         if (!uart.sending)
1506         if (!state->uart.sending)
15711507            value |= 0x20;
15721508         break;
15731509
15741510      case 0x8d:
1575         value = uart.data_received;
1511         value = state->uart.data_received;
15761512         break;
15771513   }
15781514   logerror("uart read %.2x %.2x\n", offset, value);
r9669r9670
15811517
15821518static WRITE8_HANDLER(lynx_uart_w)
15831519{
1520   lynx_state *state = space->machine->driver_data<lynx_state>();
15841521   logerror("uart write %.2x %.2x\n", offset, data);
15851522   switch (offset)
15861523   {
15871524      case 0x8c:
1588         uart.serctl = data;
1525         state->uart.serctl = data;
15891526         break;
15901527
15911528      case 0x8d:
1592         if (uart.sending)
1529         if (state->uart.sending)
15931530         {
1594            uart.buffer = data;
1595            uart.buffer_loaded = TRUE;
1531            state->uart.buffer = data;
1532            state->uart.buffer_loaded = TRUE;
15961533         }
15971534         else
15981535         {
1599            uart.sending = TRUE;
1600            uart.data_to_send = data;
1536            state->uart.sending = TRUE;
1537            state->uart.data_to_send = data;
16011538            timer_set(space->machine, ATTOTIME_IN_USEC(11), NULL, 0, lynx_uart_timer);
16021539         }
16031540         break;
r9669r9670
16141551
16151552static READ8_HANDLER( mikey_read )
16161553{
1554   lynx_state *state = space->machine->driver_data<lynx_state>();
16171555   UINT8 direction, value = 0x00;
16181556
16191557   switch (offset)
r9669r9670
16261564   case 0x14: case 0x15: case 0x16: case 0x17:
16271565   case 0x18: case 0x19: case 0x1a: case 0x1b:
16281566   case 0x1c: case 0x1d: case 0x1e: case 0x1f:
1629      value = lynx_timer_read(offset >> 2, offset & 0x03);
1567      value = lynx_timer_read(state, offset >> 2, offset & 0x03);
16301568      break;
16311569
16321570   case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
r9669r9670
16341572   case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
16351573   case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
16361574   case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x50:
1637      value = lynx_audio_read(lynx_audio, offset);
1575      value = lynx_audio_read(state->audio, offset);
16381576      break;
16391577
16401578   case 0x80:
16411579   case 0x81:
1642      value = mikey.data[offset];
1580      value = state->mikey.data[offset];
16431581      logerror( "mikey read %.2x %.2x\n", offset, value );
16441582      break;
16451583
r9669r9670
16571595      break;
16581596
16591597   case 0x8b:
1660      direction = mikey.data[0x8a];
1661      value |= (direction & 0x01) ? (mikey.data[offset] & 0x01) : 0x01;   // External Power input
1662      value |= (direction & 0x02) ? (mikey.data[offset] & 0x02) : 0x00;   // Cart Address Data output (0 turns cart power on)
1663      value |= (direction & 0x04) ? (mikey.data[offset] & 0x04) : 0x04;   // noexp input
1598      direction = state->mikey.data[0x8a];
1599      value |= (direction & 0x01) ? (state->mikey.data[offset] & 0x01) : 0x01;   // External Power input
1600      value |= (direction & 0x02) ? (state->mikey.data[offset] & 0x02) : 0x00;   // Cart Address Data output (0 turns cart power on)
1601      value |= (direction & 0x04) ? (state->mikey.data[offset] & 0x04) : 0x04;   // noexp input
16641602      // REST still to implement
1665      value |= (direction & 0x08) ? (mikey.data[offset] & 0x08) : 0x00;   // rest output
1666      value |= (direction & 0x10) ? (mikey.data[offset] & 0x10) : 0x10;   // audin input
1603      value |= (direction & 0x08) ? (state->mikey.data[offset] & 0x08) : 0x00;   // rest output
1604      value |= (direction & 0x10) ? (state->mikey.data[offset] & 0x10) : 0x10;   // audin input
16671605      /* Hack: we disable COMLynx  */
16681606      value |= 0x04;
16691607      /* B5, B6 & B7 are not used */
r9669r9670
16751613      break;
16761614
16771615   default:
1678      value = mikey.data[offset];
1616      value = state->mikey.data[offset];
16791617      logerror( "mikey read %.2x %.2x\n", offset, value );
16801618   }
16811619
r9669r9670
16841622
16851623static WRITE8_HANDLER( mikey_write )
16861624{
1625   lynx_state *state = space->machine->driver_data<lynx_state>();
16871626   switch (offset)
16881627   {
16891628   case 0x00: case 0x01: case 0x02: case 0x03:
r9669r9670
16941633   case 0x14: case 0x15: case 0x16: case 0x17:
16951634   case 0x18: case 0x19: case 0x1a: case 0x1b:
16961635   case 0x1c: case 0x1d: case 0x1e: case 0x1f:
1697      lynx_timer_write(offset >> 2, offset & 3, data);
1636      lynx_timer_write(state, offset >> 2, offset & 3, data);
16981637      return;
16991638
17001639   case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
r9669r9670
17021641   case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
17031642   case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
17041643   case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x50:
1705      lynx_audio_write(lynx_audio, offset, data);
1644      lynx_audio_write(state->audio, offset, data);
17061645      return;
17071646
17081647   case 0x80:
1709      mikey.data[0x81] &= ~data; // clear interrupt source
1648      state->mikey.data[0x81] &= ~data; // clear interrupt source
17101649      logerror("mikey write %.2x %.2x\n", offset, data);
1711      if (!mikey.data[0x81])
1650      if (!state->mikey.data[0x81])
17121651         cputag_set_input_line(space->machine, "maincpu", M65SC02_IRQ_LINE, CLEAR_LINE);
17131652      break;
17141653
17151654   /* Is this correct? */
17161655   case 0x81:
1717      mikey.data[offset] |= data;
1656      state->mikey.data[offset] |= data;
17181657      break;
17191658
17201659   case 0x87:
1721      mikey.data[offset] = data;
1660      state->mikey.data[offset] = data;
17221661      if (data & 0x02)      // Power (1 = on)
17231662      {
17241663         if (data & 0x01)   // Cart Address Strobe
17251664         {
1726            suzy.high <<= 1;
1727            if (mikey.data[0x8b] & 0x02)
1728               suzy.high |= 1;
1729            suzy.high &= 0xff;
1730            suzy.low = 0;
1665            state->suzy.high <<= 1;
1666            if (state->mikey.data[0x8b] & 0x02)
1667               state->suzy.high |= 1;
1668            state->suzy.high &= 0xff;
1669            state->suzy.low = 0;
17311670         }
17321671      }
17331672      else
17341673      {
1735         suzy.high = 0;
1736         suzy.low = 0;
1674         state->suzy.high = 0;
1675         state->suzy.low = 0;
17371676      }
17381677      break;
17391678
r9669r9670
17451684   case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
17461685   case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
17471686   case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
1748      mikey.data[offset] = data;
1749      lynx_draw_lines(space->machine, lynx_line);
1687      state->mikey.data[offset] = data;
1688      lynx_draw_lines(space->machine, state->line);
17501689
17511690      /* RED = 0xb- & 0x0f, GREEN = 0xa- & 0x0f, BLUE = (0xb- & 0xf0) >> 4 */
1752      lynx_palette[offset & 0x0f] = space->machine->pens[
1753         ((mikey.data[0xb0 + (offset & 0x0f)] & 0x0f)) |
1754         ((mikey.data[0xa0 + (offset & 0x0f)] & 0x0f) << 4) |
1755         ((mikey.data[0xb0 + (offset & 0x0f)] & 0xf0) << 4)];
1691      state->palette[offset & 0x0f] = space->machine->pens[
1692         ((state->mikey.data[0xb0 + (offset & 0x0f)] & 0x0f)) |
1693         ((state->mikey.data[0xa0 + (offset & 0x0f)] & 0x0f) << 4) |
1694         ((state->mikey.data[0xb0 + (offset & 0x0f)] & 0xf0) << 4)];
17561695      break;
17571696
17581697   /* TODO: properly implement these writes */
17591698   case 0x8b:
1760      mikey.data[offset] = data;
1761      if (mikey.data[0x8a] & 0x10)
1762         logerror("Trying to enable bank 1 write. %d\n", mikey.data[offset] & 0x10);
1699      state->mikey.data[offset] = data;
1700      if (state->mikey.data[0x8a] & 0x10)
1701         logerror("Trying to enable bank 1 write. %d\n", state->mikey.data[offset] & 0x10);
17631702      break;
17641703
17651704//  case 0x90: // SDONEACK - Suzy Done Acknowledge
17661705   case 0x91: // CPUSLEEP - CPU Bus Request Disable
1767      mikey.data[offset] = data;
1706      state->mikey.data[offset] = data;
17681707      if (!data)
17691708      {
17701709         /* A write of '0' to this address will reset the CPU bus request flip flop */
r9669r9670
17731712      break;
17741713
17751714   default:
1776      mikey.data[offset]=data;
1715      state->mikey.data[offset]=data;
17771716      logerror("mikey write %.2x %.2x\n",offset,data);
17781717      break;
17791718   }
r9669r9670
17871726
17881727READ8_HANDLER( lynx_memory_config_r )
17891728{
1790   return lynx_memory_config;
1729   lynx_state *state = space->machine->driver_data<lynx_state>();
1730   return state->memory_config;
17911731}
17921732
17931733WRITE8_HANDLER( lynx_memory_config_w )
17941734{
1735   lynx_state *state = space->machine->driver_data<lynx_state>();
17951736   /* bit 7: hispeed, uses page mode accesses (4 instead of 5 cycles )
17961737     * when these are safe in the cpu */
1797   lynx_memory_config = data;
1738   state->memory_config = data;
17981739
17991740   if (data & 1) {
18001741      memory_install_readwrite_bank(space, 0xfc00, 0xfcff, 0, 0, "bank1");
r9669r9670
18081749   }
18091750
18101751   if (data & 1)
1811      memory_set_bankptr(space->machine, "bank1", lynx_mem_fc00);
1752      memory_set_bankptr(space->machine, "bank1", state->mem_fc00);
18121753   if (data & 2)
1813      memory_set_bankptr(space->machine, "bank2", lynx_mem_fd00);
1754      memory_set_bankptr(space->machine, "bank2", state->mem_fd00);
18141755   memory_set_bank(space->machine, "bank3", (data & 4) ? 1 : 0);
18151756   memory_set_bank(space->machine, "bank4", (data & 8) ? 1 : 0);
18161757}
18171758
18181759static void lynx_reset(running_machine &machine)
18191760{
1761   lynx_state *state = machine.driver_data<lynx_state>();
18201762   lynx_memory_config_w(cputag_get_address_space(&machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0, 0);
18211763
18221764   cputag_set_input_line(&machine, "maincpu", M65SC02_IRQ_LINE, CLEAR_LINE);
18231765
1824   memset(&suzy, 0, sizeof(suzy));
1825   memset(&mikey, 0, sizeof(mikey));
1766   memset(&state->suzy, 0, sizeof(state->suzy));
1767   memset(&state->mikey, 0, sizeof(state->mikey));
18261768
1827   suzy.data[0x88]  = 0x01;
1828   suzy.data[0x90]  = 0x00;
1829   suzy.data[0x91]  = 0x00;
1830   mikey.data[0x80] = 0x00;
1831   mikey.data[0x81] = 0x00;
1832   mikey.data[0x88] = 0x01;
1833   mikey.data[0x8a] = 0x00;
1834   mikey.data[0x8c] = 0x00;
1835   mikey.data[0x90] = 0x00;
1836   mikey.data[0x92] = 0x00;
1769   state->suzy.data[0x88]  = 0x01;
1770   state->suzy.data[0x90]  = 0x00;
1771   state->suzy.data[0x91]  = 0x00;
1772   state->mikey.data[0x80] = 0x00;
1773   state->mikey.data[0x81] = 0x00;
1774   state->mikey.data[0x88] = 0x01;
1775   state->mikey.data[0x8a] = 0x00;
1776   state->mikey.data[0x8c] = 0x00;
1777   state->mikey.data[0x90] = 0x00;
1778   state->mikey.data[0x92] = 0x00;
18371779
1838   lynx_uart_reset();
1780   lynx_uart_reset(state);
18391781
18401782   // hack to allow current object loading to work
18411783#if 1
1842   lynx_timer_write( 0, 0, 160 );
1843   lynx_timer_write( 0, 1, 0x10 | 0x8 | 0 );
1844   lynx_timer_write( 2, 0, 102 );
1845   lynx_timer_write( 2, 1, 0x10 | 0x8 | 7 );
1784   lynx_timer_write( state, 0, 0, 160 );
1785   lynx_timer_write( state, 0, 1, 0x10 | 0x8 | 0 );
1786   lynx_timer_write( state, 2, 0, 102 );
1787   lynx_timer_write( state, 2, 1, 0x10 | 0x8 | 7 );
18461788#endif
18471789}
18481790
18491791static STATE_POSTLOAD( lynx_postload )
18501792{
1851   lynx_memory_config_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0, lynx_memory_config);
1793   lynx_state *state = machine->driver_data<lynx_state>();
1794   lynx_memory_config_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0, state->memory_config);
18521795}
18531796
18541797MACHINE_START( lynx )
18551798{
1799   lynx_state *state = machine->driver_data<lynx_state>();
18561800   int i;
1857   state_save_register_global(machine, lynx_memory_config);
1858   state_save_register_global_pointer(machine, lynx_mem_fe00, lynx_mem_fe00_size);
1801   state_save_register_global(machine, state->memory_config);
1802   state_save_register_global_pointer(machine, state->mem_fe00, state->mem_fe00_size);
18591803   state_save_register_postload(machine, lynx_postload, NULL);
18601804
18611805   memory_configure_bank(machine, "bank3", 0, 1, memory_region(machine, "maincpu") + 0x0000, 0);
1862   memory_configure_bank(machine, "bank3", 1, 1, lynx_mem_fe00, 0);
1806   memory_configure_bank(machine, "bank3", 1, 1, state->mem_fe00, 0);
18631807   memory_configure_bank(machine, "bank4", 0, 1, memory_region(machine, "maincpu") + 0x01fa, 0);
1864   memory_configure_bank(machine, "bank4", 1, 1, lynx_mem_fffa, 0);
1808   memory_configure_bank(machine, "bank4", 1, 1, state->mem_fffa, 0);
18651809
1866   lynx_audio = machine->device("custom");
1867   lynx_height = -1;
1868   lynx_width = -1;
1810   state->audio = machine->device("custom");
1811   state->height = -1;
1812   state->width = -1;
18691813
1870   memset(&suzy, 0, sizeof(suzy));
1814   memset(&state->suzy, 0, sizeof(state->suzy));
18711815
18721816   machine->add_notifier(MACHINE_NOTIFY_RESET, lynx_reset);
18731817
r9669r9670
19221866
19231867INTERRUPT_GEN( lynx_frame_int )
19241868{
1925   lynx_rotate = rotate0;
1869   lynx_state *state = device->machine->driver_data<lynx_state>();
1870   state->rotate = state->rotate0;
19261871   if ((input_port_read(device->machine, "ROTATION") & 0x03) != 0x03)
1927      lynx_rotate=input_port_read(device->machine, "ROTATION") & 0x03;
1872      state->rotate=input_port_read(device->machine, "ROTATION") & 0x03;
19281873}
19291874
19301875void lynx_crc_keyword(device_image_interface &image)
19311876{
1877   lynx_state *state = image.device().machine->driver_data<lynx_state>();
19321878   const char *info = NULL;
19331879
19341880   if (strcmp(image.extrainfo(), ""))
19351881      info = image.extrainfo();
19361882
1937   rotate0 = 0;
1883   state->rotate0 = 0;
19381884
19391885   if (info)
19401886   {
19411887      if(strcmp(info, "ROTATE90DEGREE") == 0)
1942         rotate0 = 1;
1888         state->rotate0 = 1;
19431889      else if (strcmp(info, "ROTATE270DEGREE") == 0)
1944         rotate0 = 2;
1890         state->rotate0 = 2;
19451891   }
19461892}
19471893
19481894static DEVICE_IMAGE_LOAD( lynx_cart )
19491895{
1896   lynx_state *state = image.device().machine->driver_data<lynx_state>();
19501897   UINT8 *rom = memory_region(image.device().machine, "user1");
19511898   UINT32 size;
19521899   UINT8 header[0x40];
r9669r9670
19771924         /* 2008-10 FP: According to Handy source these should be page_size_bank0. Are we using
19781925            it correctly in MESS? Moreover, the next two values should be page_size_bank1. We should
19791926            implement this as well */
1980         lynx_granularity = header[4] | (header[5] << 8);
1927         state->granularity = header[4] | (header[5] << 8);
19811928
19821929         logerror ("%s %dkb cartridge with %dbyte granularity from %s\n",
1983               header + 10, size / 1024, lynx_granularity, header + 42);
1930               header + 10, size / 1024, state->granularity, header + 42);
19841931
19851932         size -= 0x40;
19861933      }
r9669r9670
19901937            (see above). What if bank 0 has to be loaded elsewhere? And what about bank 1?
19911938            These should work with most .lyx files, but we need additional info on raw cart images */
19921939         if (size == 0x20000)
1993            lynx_granularity = 0x0200;
1940            state->granularity = 0x0200;
19941941         else if (size == 0x80000)
1995            lynx_granularity = 0x0800;
1942            state->granularity = 0x0800;
19961943         else
1997            lynx_granularity = 0x0400;
1944            state->granularity = 0x0400;
19981945      }
19991946
20001947      if (image.fread( rom, size) != size)
r9669r9670
20171964      /* 2008-10 FP: According to Handy source these should be page_size_bank0. Are we using
20181965         it correctly in MESS? Moreover, the next two values should be page_size_bank1. We should
20191966         implement this as well */
2020      lynx_granularity = header[4] | (header[5] << 8);
1967      state->granularity = header[4] | (header[5] << 8);
20211968
20221969      logerror ("%s %dkb cartridge with %dbyte granularity from %s\n",
2023              header + 10, size / 1024, lynx_granularity, header + 42);
1970              header + 10, size / 1024, state->granularity, header + 42);
20241971
20251972      size -= 0x40;
20261973      memcpy(rom, image.get_software_region("rom") + 0x40, size);
src/mess/machine/super80.c
r9669r9670
88#include "machine/ctronics.h"
99#include "includes/super80.h"
1010
11static running_device *super80_z80pio;
12static running_device *super80_speaker;
13static running_device *super80_cassette;
14static running_device *super80_printer;
1511
1612/**************************** PIO ******************************************************************************/
1713
18static UINT8 keylatch;
1914
2015static WRITE8_DEVICE_HANDLER( pio_port_a_w )
2116{
22   keylatch = data;
17   super80_state *state = device->machine->driver_data<super80_state>();
18   state->keylatch = data;
2319};
2420
2521static READ8_DEVICE_HANDLER( pio_port_b_r )
2622{
23   super80_state *state = device->machine->driver_data<super80_state>();
2724   static const char *const keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", "LINE5", "LINE6", "LINE7" };
2825
2926   int bit;
r9669r9670
3128
3229   for (bit = 0; bit < 8; bit++)
3330   {
34      if (!BIT(keylatch, bit)) data &= input_port_read(device->machine, keynames[bit]);
31      if (!BIT(state->keylatch, bit)) data &= input_port_read(device->machine, keynames[bit]);
3532   }
3633
3734   return data;
r9669r9670
5350
5451static void super80_cassette_motor( running_machine *machine, UINT8 data )
5552{
53   super80_state *state = machine->driver_data<super80_state>();
5654   if (data)
57      cassette_change_state(super80_cassette, CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR);
55      cassette_change_state(state->cassette, CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR);
5856   else
59      cassette_change_state(super80_cassette, CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR);
57      cassette_change_state(state->cassette, CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR);
6058
6159   /* does user want to hear the sound? */
6260   if (input_port_read(machine, "CONFIG") & 8)
63      cassette_change_state(super80_cassette, CASSETTE_SPEAKER_ENABLED, CASSETTE_MASK_SPEAKER);
61      cassette_change_state(state->cassette, CASSETTE_SPEAKER_ENABLED, CASSETTE_MASK_SPEAKER);
6462   else
65      cassette_change_state(super80_cassette, CASSETTE_SPEAKER_MUTED, CASSETTE_MASK_SPEAKER);
63      cassette_change_state(state->cassette, CASSETTE_SPEAKER_MUTED, CASSETTE_MASK_SPEAKER);
6664}
6765
6866/********************************************* TIMER ************************************************/
6967
70static UINT8 cass_data[4]={ 0, 0, 0, 0 };
7168
7269   /* this timer runs at 200khz and does 2 jobs:
7370    1. Scan the keyboard and present the results to the pio
r9669r9670
8986
9087static TIMER_CALLBACK( super80_timer )
9188{
89   super80_state *state = machine->driver_data<super80_state>();
9290   UINT8 cass_ws=0;
9391
94   cass_data[1]++;
95   cass_ws = (cassette_input(super80_cassette) > +0.03) ? 4 : 0;
92   state->cass_data[1]++;
93   cass_ws = (cassette_input(state->cassette) > +0.03) ? 4 : 0;
9694
97   if (cass_ws != cass_data[0])
95   if (cass_ws != state->cass_data[0])
9896   {
99      if (cass_ws) cass_data[3] ^= 2;                  // the MDS flipflop
100      cass_data[0] = cass_ws;
101      cass_data[2] = ((cass_data[1] < 0x40) ? 1 : 0) | cass_ws | cass_data[3];
102      cass_data[1] = 0;
97      if (cass_ws) state->cass_data[3] ^= 2;                  // the MDS flipflop
98      state->cass_data[0] = cass_ws;
99      state->cass_data[2] = ((state->cass_data[1] < 0x40) ? 1 : 0) | cass_ws | state->cass_data[3];
100      state->cass_data[1] = 0;
103101   }
104102
105   z80pio_pb_w(super80_z80pio,1,pio_port_b_r(super80_z80pio,0));
103   z80pio_pb_w(state->z80pio,1,pio_port_b_r(state->z80pio,0));
106104}
107105
108106/* after the first 4 bytes have been read from ROM, switch the ram back in */
r9669r9670
113111
114112static TIMER_CALLBACK( super80_halfspeed )
115113{
116   static UINT8 int_sw=0;
117114   UINT8 go_fast = 0;
118115   super80_state *state = machine->driver_data<super80_state>();
119116   if (!(state->super80_shared & 4) || (!(input_port_read(machine, "CONFIG") & 2)))   /* bit 2 of port F0 is low, OR user turned on config switch */
r9669r9670
122119   /* code to slow down computer to 1 MHz by halting cpu on every second frame */
123120   if (!go_fast)
124121   {
125      if (!int_sw)
122      if (!state->int_sw)
126123         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, ASSERT_LINE);   // if going, stop it
127124
128      int_sw++;
129      if (int_sw > 1)
125      state->int_sw++;
126      if (state->int_sw > 1)
130127      {
131128         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, CLEAR_LINE);      // if stopped, start it
132         int_sw = 0;
129         state->int_sw = 0;
133130      }
134131   }
135132   else
136133   {
137      if (int_sw < 8)                        // @2MHz, reset just once
134      if (state->int_sw < 8)                        // @2MHz, reset just once
138135      {
139136         cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, CLEAR_LINE);
140         int_sw = 8;                     // ...not every time
137         state->int_sw = 8;                     // ...not every time
141138      }
142139   }
143140}
r9669r9670
157154
158155READ8_HANDLER( super80_dc_r )
159156{
157   super80_state *state = space->machine->driver_data<super80_state>();
160158   UINT8 data=0x7f;
161159
162160   /* bit 7 = printer busy
163161    0 = printer is not busy */
164162
165   data |= centronics_busy_r(super80_printer) << 7;
163   data |= centronics_busy_r(state->printer) << 7;
166164
167165   return data;
168166}
169167
170168READ8_HANDLER( super80_f2_r )
171169{
170   super80_state *state = space->machine->driver_data<super80_state>();
172171   UINT8 data = input_port_read(space->machine, "DSW") & 0xf0;   // dip switches on pcb
173   data |= cass_data[2];         // bit 0 = output of U1, bit 1 = MDS cass state, bit 2 = current wave_state
172   data |= state->cass_data[2];         // bit 0 = output of U1, bit 1 = MDS cass state, bit 2 = current wave_state
174173   data |= 0x08;            // bit 3 - not used
175174   return data;
176175}
177176
178177WRITE8_HANDLER( super80_dc_w )
179178{
179   super80_state *state = space->machine->driver_data<super80_state>();
180180   /* hardware strobe driven from port select, bit 7..0 = data */
181   centronics_strobe_w(super80_printer, 1);
182   centronics_data_w(super80_printer, 0, data);
183   centronics_strobe_w(super80_printer, 0);
181   centronics_strobe_w(state->printer, 1);
182   centronics_data_w(state->printer, 0, data);
183   centronics_strobe_w(state->printer, 0);
184184}
185185
186static UINT8 last_data;
187186
188187WRITE8_HANDLER( super80_f0_w )
189188{
190189   super80_state *state = space->machine->driver_data<super80_state>();
191   UINT8 bits = data ^ last_data;
190   UINT8 bits = data ^ state->last_data;
192191   state->super80_shared = data;
193   speaker_level_w(super80_speaker, (data & 8) ? 0 : 1);            /* bit 3 - speaker */
192   speaker_level_w(state->speaker, (data & 8) ? 0 : 1);            /* bit 3 - speaker */
194193   if (bits & 2) super80_cassette_motor(space->machine, data & 2 ? 1 : 0);   /* bit 1 - cassette motor */
195   cassette_output(super80_cassette, (data & 1) ? -1.0 : +1.0);   /* bit 0 - cass out */
194   cassette_output(state->cassette, (data & 1) ? -1.0 : +1.0);   /* bit 0 - cass out */
196195
197   last_data = data;
196   state->last_data = data;
198197}
199198
200199WRITE8_HANDLER( super80r_f0_w )
r9669r9670
212211   state->super80_shared=0xff;
213212   timer_set(machine, ATTOTIME_IN_USEC(10), NULL, 0, super80_reset);
214213   memory_set_bank(machine, "bank1", 1);
215   super80_z80pio = machine->device("z80pio");
216   super80_speaker = machine->device("speaker");
217   super80_cassette = machine->device("cassette");
218   super80_printer = machine->device("centronics");
214   state->z80pio = machine->device("z80pio");
215   state->speaker = machine->device("speaker");
216   state->cassette = machine->device("cassette");
217   state->printer = machine->device("centronics");
219218}
220219
221220static void driver_init_common( running_machine *machine )
src/mess/video/wswan.c
r9669r9670
1212#include "emu.h"
1313#include "includes/wswan.h"
1414
15static int pal[16][16];
1615
1716INLINE void wswan_plot_pixel(running_machine *machine,int x, int y, int pen) {
17   wswan_state *state = machine->driver_data<wswan_state>();
1818   y += 5*8;
19   if ( wswan_vdp.display_vertical ) {
19   if ( state->vdp.display_vertical ) {
2020      *BITMAP_ADDR16(machine->generic.tmpbitmap, 28*8 - 1 - x, y) = pen;
2121   } else {
2222      *BITMAP_ADDR16(machine->generic.tmpbitmap, y, x) = pen;
r9669r9670
2424}
2525
2626INLINE void wswan_fillbitmap( running_machine *machine,int pen, rectangle *rec ) {
27   wswan_state *state = machine->driver_data<wswan_state>();
2728   /* Fill empty area above line 0 when filling line 0 */
28   if ( wswan_vdp.current_line != 0 ) {
29   if ( state->vdp.current_line != 0 ) {
2930      rec->min_y = rec->min_y + 5*8;
3031   }
3132
3233   /* Fill empty area below line 143 when filling line 143 */
33   if ( wswan_vdp.current_line != 143 ) {
34   if ( state->vdp.current_line != 143 ) {
3435      rec->max_y = rec->max_y + 5*8;
3536   } else {
3637      rec->max_y = 28*8;
3738   }
3839
39   if ( wswan_vdp.display_vertical ) {
40   if ( state->vdp.display_vertical ) {
4041      rectangle rec2;
4142      rec2.min_y = 28*8 - 1 - rec->max_x;
4243      rec2.max_y = 28*8 - 1 - rec->min_x;
r9669r9670
4950}
5051
5152
52static void wswan_setup_palettes(void) {
53static void wswan_setup_palettes(wswan_state *state) {
5354   int i,j;
5455
55   if ( wswan_vdp.color_mode ) {
56   if ( state->vdp.color_mode ) {
5657      for( i = 0; i < 16; i++ ) {
5758         for( j = 0; j < 16; j++ ) {
58            pal[i][j] = ( ( wswan_vdp.palette_vram[ ( i << 5 ) + j*2 + 1 ] << 8 ) | wswan_vdp.palette_vram[ ( i << 5 ) + j*2 ] ) & 0x0FFF;
59            state->pal[i][j] = ( ( state->vdp.palette_vram[ ( i << 5 ) + j*2 + 1 ] << 8 ) | state->vdp.palette_vram[ ( i << 5 ) + j*2 ] ) & 0x0FFF;
5960         }
6061      }
6162   } else {
6263      for( i = 0; i < 16; i++ ) {
63         pal[i][0] = ws_portram[ 0x20 + ( i << 1 ) ] & 0x07;
64         pal[i][1] = ( ws_portram[ 0x20 + ( i << 1 ) ] >> 4 ) & 0x07;
65         pal[i][2] = ws_portram[ 0x21 + ( i << 1 ) ] & 0x07;
66         pal[i][3] = ( ws_portram[ 0x21 + ( i << 1 ) ] >> 4 ) & 0x07;
64         state->pal[i][0] = state->ws_portram[ 0x20 + ( i << 1 ) ] & 0x07;
65         state->pal[i][1] = ( state->ws_portram[ 0x20 + ( i << 1 ) ] >> 4 ) & 0x07;
66         state->pal[i][2] = state->ws_portram[ 0x21 + ( i << 1 ) ] & 0x07;
67         state->pal[i][3] = ( state->ws_portram[ 0x21 + ( i << 1 ) ] >> 4 ) & 0x07;
6768      }
6869   }
6970}
7071
7172static void wswan_draw_background( running_machine *machine ) {
73   wswan_state *state = machine->driver_data<wswan_state>();
7274   UINT16   map_addr;
7375   UINT8   start_column;
7476   int   column;
7577
76   map_addr = wswan_vdp.layer_bg_address + ( ( ( wswan_vdp.current_line + wswan_vdp.layer_bg_scroll_y ) & 0xF8 ) << 3 );
77   start_column = ( wswan_vdp.layer_bg_scroll_x >> 3 );
78   map_addr = state->vdp.layer_bg_address + ( ( ( state->vdp.current_line + state->vdp.layer_bg_scroll_y ) & 0xF8 ) << 3 );
79   start_column = ( state->vdp.layer_bg_scroll_x >> 3 );
7880   for( column = 0; column < 29; column++ ) {
7981      int   tile_data, tile_number, tile_palette, tile_line, tile_address;
8082      UINT32   plane0=0, plane1=0, plane2=0, plane3=0;
8183      int   x, x_offset;
8284
83      tile_data = ( wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 )
84                  | wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ];
85      tile_data = ( state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 )
86                  | state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ];
8587      tile_number = tile_data & 0x01FF;
8688      tile_palette = ( tile_data >> 9 ) & 0x0F;
8789
88      tile_line = ( wswan_vdp.current_line + wswan_vdp.layer_bg_scroll_y ) & 0x07;
90      tile_line = ( state->vdp.current_line + state->vdp.layer_bg_scroll_y ) & 0x07;
8991      if ( tile_data & 0x8000 ) {
9092         tile_line = 7 - tile_line;
9193      }
9294
93      if ( wswan_vdp.colors_16 ) {
95      if ( state->vdp.colors_16 ) {
9496         tile_address = ( ( tile_data & 0x2000 ) ? 0x8000 : 0x4000 ) + ( tile_number * 32 ) + ( tile_line << 2 );
95         if ( wswan_vdp.tile_packed ) {
96            plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ];
97         if ( state->vdp.tile_packed ) {
98            plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ];
9799         } else {
98            plane0 = wswan_vdp.vram[ tile_address + 0 ];
99            plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
100            plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2;
101            plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3;
100            plane0 = state->vdp.vram[ tile_address + 0 ];
101            plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
102            plane2 = state->vdp.vram[ tile_address + 2 ] << 2;
103            plane3 = state->vdp.vram[ tile_address + 3 ] << 3;
102104         }
103105      } else {
104106         tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 );
105         if ( wswan_vdp.tile_packed ) {
106            plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ];
107         if ( state->vdp.tile_packed ) {
108            plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ];
107109         } else {
108            plane0 = wswan_vdp.vram[ tile_address + 0 ];
109            plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
110            plane0 = state->vdp.vram[ tile_address + 0 ];
111            plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
110112            plane2 = 0;
111113            plane3 = 0;
112114         }
r9669r9670
114116
115117      for( x = 0; x < 8; x++ ) {
116118         int col;
117         if ( wswan_vdp.tile_packed ) {
118            if ( wswan_vdp.colors_16 ) {
119         if ( state->vdp.tile_packed ) {
120            if ( state->vdp.colors_16 ) {
119121               col = plane0 & 0x0F;
120122               plane0 = plane0 >> 4;
121123            } else {
r9669r9670
130132            plane0 = plane0 >> 1;
131133         }
132134         if ( tile_data & 0x4000 ) {
133            x_offset = x + ( column << 3 ) - ( wswan_vdp.layer_bg_scroll_x & 0x07 );
135            x_offset = x + ( column << 3 ) - ( state->vdp.layer_bg_scroll_x & 0x07 );
134136         } else {
135            x_offset = 7 - x + ( column << 3 ) - ( wswan_vdp.layer_bg_scroll_x & 0x07 );
137            x_offset = 7 - x + ( column << 3 ) - ( state->vdp.layer_bg_scroll_x & 0x07 );
136138         }
137139         if ( x_offset >= 0 && x_offset < WSWAN_X_PIXELS ) {
138            if ( wswan_vdp.colors_16 ) {
140            if ( state->vdp.colors_16 ) {
139141               if ( col ) {
140                  if ( wswan_vdp.color_mode ) {
141                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
142                  if ( state->vdp.color_mode ) {
143                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
142144                  } else {
143145                     /* Hmmmm, what should we do here... Is this correct?? */
144                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
146                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
145147                  }
146148               }
147149            } else {
148150               if ( col || !(tile_palette & 4 ) ) {
149                  if ( wswan_vdp.color_mode ) {
150                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
151                  if ( state->vdp.color_mode ) {
152                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
151153                  } else {
152                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] );
154                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] );
153155                  }
154156               }
155157            }
r9669r9670
159161}
160162
161163static void wswan_draw_foreground_0( running_machine *machine ) {
164   wswan_state *state = machine->driver_data<wswan_state>();
162165   UINT16   map_addr;
163166   UINT8   start_column;
164167   int   column;
165   map_addr = wswan_vdp.layer_fg_address + ( ( ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 );
166   start_column = ( wswan_vdp.layer_fg_scroll_x >> 3 );
168   map_addr = state->vdp.layer_fg_address + ( ( ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 );
169   start_column = ( state->vdp.layer_fg_scroll_x >> 3 );
167170   for( column = 0; column < 29; column++ ) {
168171      UINT32   plane0 = 0, plane1 = 0, plane2 = 0, plane3 = 0;
169172      int   x, x_offset, tile_line, tile_address;
170      int   tile_data = ( wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 )
171                                    | wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ];
173      int   tile_data = ( state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 )
174                                    | state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ];
172175      int   tile_number = tile_data & 0x01FF;
173176      int   tile_palette = ( tile_data >> 9 ) & 0x0F;
174177
175      tile_line = ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0x07;
178      tile_line = ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0x07;
176179      if ( tile_data & 0x8000 ) {
177180         tile_line = 7 - tile_line;
178181      }
179182
180      if ( wswan_vdp.colors_16 ) {
183      if ( state->vdp.colors_16 ) {
181184         tile_address = ( ( tile_data & 0x2000 ) ? 0x8000 : 0x4000 ) + ( tile_number * 32 ) + ( tile_line << 2 );
182         if ( wswan_vdp.tile_packed ) {
183            plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ];
185         if ( state->vdp.tile_packed ) {
186            plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ];
184187         } else {
185            plane0 = wswan_vdp.vram[ tile_address + 0 ];
186            plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
187            plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2;
188            plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3;
188            plane0 = state->vdp.vram[ tile_address + 0 ];
189            plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
190            plane2 = state->vdp.vram[ tile_address + 2 ] << 2;
191            plane3 = state->vdp.vram[ tile_address + 3 ] << 3;
189192         }
190193      } else {
191194         tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 );
192         if ( wswan_vdp.tile_packed ) {
193            plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ];
195         if ( state->vdp.tile_packed ) {
196            plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ];
194197         } else {
195            plane0 = wswan_vdp.vram[ tile_address + 0 ];
196            plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
198            plane0 = state->vdp.vram[ tile_address + 0 ];
199            plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
197200            plane2 = 0;
198201            plane3 = 0;
199202         }
r9669r9670
201204
202205      for( x = 0; x < 8; x++ ) {
203206         int   col;
204         if ( wswan_vdp.tile_packed ) {
205            if ( wswan_vdp.colors_16 ) {
207         if ( state->vdp.tile_packed ) {
208            if ( state->vdp.colors_16 ) {
206209               col = plane0 & 0x0F;
207210               plane0 = plane0 >> 4;
208211            } else {
r9669r9670
217220            plane0 = plane0 >> 1;
218221         }
219222         if ( tile_data & 0x4000 ) {
220            x_offset = x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 );
223            x_offset = x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 );
221224         } else {
222            x_offset = 7 - x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 );
225            x_offset = 7 - x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 );
223226         }
224227         if ( x_offset >= 0 && x_offset < WSWAN_X_PIXELS ) {
225            if ( wswan_vdp.colors_16 ) {
228            if ( state->vdp.colors_16 ) {
226229               if ( col ) {
227//                      if ( wswan_vdp.color_mode ) {
228                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
230//                      if ( state->vdp.color_mode ) {
231                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
229232//                      } else {
230233//                          /* Hmmmm, what should we do here... Is this correct?? */
231//                          wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
234//                          wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
232235//                      }
233236               }
234237            } else {
235238               if ( col || !(tile_palette & 4 ) ) {
236                  if ( wswan_vdp.color_mode ) {
237                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
239                  if ( state->vdp.color_mode ) {
240                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
238241                  } else {
239                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] );
242                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] );
240243                  }
241244               }
242245            }
r9669r9670
246249}
247250
248251static void wswan_draw_foreground_2( running_machine *machine ) {
252   wswan_state *state = machine->driver_data<wswan_state>();
249253   UINT16   map_addr;
250254   UINT8   start_column;
251255   int   column;
252   map_addr = wswan_vdp.layer_fg_address + ( ( ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 );
253   start_column = ( wswan_vdp.layer_fg_scroll_x >> 3 );
256   map_addr = state->vdp.layer_fg_address + ( ( ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 );
257   start_column = ( state->vdp.layer_fg_scroll_x >> 3 );
254258   for( column = 0; column < 29; column++ ) {
255259      UINT32   plane0 = 0, plane1 = 0, plane2 = 0, plane3 = 0;
256260      int   x, x_offset, tile_line, tile_address;
257      int   tile_data = ( wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 )
258                     | wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ];
261      int   tile_data = ( state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 )
262                     | state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ];
259263      int   tile_number = tile_data & 0x01FF;
260264      int   tile_palette = ( tile_data >> 9 ) & 0x0F;
261265
262      tile_line = ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0x07;
266      tile_line = ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0x07;
263267      if ( tile_data & 0x8000 ) {
264268         tile_line = 7 - tile_line;
265269      }
266270
267      if ( wswan_vdp.colors_16 ) {
271      if ( state->vdp.colors_16 ) {
268272         tile_address = ( ( tile_data & 0x2000 ) ? 0x8000 : 0x4000 ) + ( tile_number * 32 ) + ( tile_line << 2 );
269         if ( wswan_vdp.tile_packed ) {
270            plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ];
273         if ( state->vdp.tile_packed ) {
274            plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ];
271275         } else {
272            plane0 = wswan_vdp.vram[ tile_address + 0 ];
273            plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
274            plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2;
275            plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3;
276            plane0 = state->vdp.vram[ tile_address + 0 ];
277            plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
278            plane2 = state->vdp.vram[ tile_address + 2 ] << 2;
279            plane3 = state->vdp.vram[ tile_address + 3 ] << 3;
276280         }
277281      } else {
278282         tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 );
279         if ( wswan_vdp.tile_packed ) {
280            plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ];
283         if ( state->vdp.tile_packed ) {
284            plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ];
281285         } else {
282            plane0 = wswan_vdp.vram[ tile_address + 0 ];
283            plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
286            plane0 = state->vdp.vram[ tile_address + 0 ];
287            plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
284288            plane2 = 0;
285289            plane3 = 0;
286290         }
r9669r9670
288292
289293      for( x = 0; x < 8; x++ ) {
290294         int   col;
291         if ( wswan_vdp.tile_packed ) {
292            if ( wswan_vdp.colors_16 ) {
295         if ( state->vdp.tile_packed ) {
296            if ( state->vdp.colors_16 ) {
293297               col = plane0 & 0x0F;
294298               plane0 = plane0 >> 4;
295299            } else {
r9669r9670
304308            plane0 = plane0 >> 1;
305309         }
306310         if ( tile_data & 0x4000 ) {
307            x_offset = x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 );
311            x_offset = x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 );
308312         } else {
309            x_offset = 7 - x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 );
313            x_offset = 7 - x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 );
310314         }
311         if ( x_offset >= 0 && x_offset >= wswan_vdp.window_fg_left && x_offset < wswan_vdp.window_fg_right && x_offset < WSWAN_X_PIXELS ) {
312            if ( wswan_vdp.colors_16 ) {
315         if ( x_offset >= 0 && x_offset >= state->vdp.window_fg_left && x_offset < state->vdp.window_fg_right && x_offset < WSWAN_X_PIXELS ) {
316            if ( state->vdp.colors_16 ) {
313317               if ( col ) {
314                  if ( wswan_vdp.color_mode ) {
315                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
318                  if ( state->vdp.color_mode ) {
319                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
316320                  } else {
317321                     /* Hmmmm, what should we do here... Is this correct?? */
318                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
322                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
319323                  }
320324               }
321325            } else {
322326               if ( col || !(tile_palette & 4 ) ) {
323                  if ( wswan_vdp.color_mode ) {
324                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
327                  if ( state->vdp.color_mode ) {
328                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
325329                  } else {
326                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] );
330                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] );
327331                  }
328332               }
329333            }
r9669r9670
333337}
334338
335339static void wswan_draw_foreground_3( running_machine *machine ) {
340   wswan_state *state = machine->driver_data<wswan_state>();
336341   UINT16   map_addr;
337342   UINT8   start_column;
338343   int   column;
339   map_addr = wswan_vdp.layer_fg_address + ( ( ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 );
340   start_column = ( wswan_vdp.layer_fg_scroll_x >> 3 );
344   map_addr = state->vdp.layer_fg_address + ( ( ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 );
345   start_column = ( state->vdp.layer_fg_scroll_x >> 3 );
341346   for( column = 0; column < 29; column++ ) {
342347      UINT32   plane0 = 0, plane1 = 0, plane2 = 0, plane3 = 0;
343348      int   x, x_offset, tile_line, tile_address;
344      int   tile_data = ( wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 )
345                     | wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ];
349      int   tile_data = ( state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 )
350                     | state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ];
346351      int   tile_number = tile_data & 0x01FF;
347352      int   tile_palette = ( tile_data >> 9 ) & 0x0F;
348353
349      tile_line = ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0x07;
354      tile_line = ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0x07;
350355      if ( tile_data & 0x8000 ) {
351356         tile_line = 7 - tile_line;
352357      }
353358
354      if ( wswan_vdp.colors_16 ) {
359      if ( state->vdp.colors_16 ) {
355360         tile_address = ( ( tile_data & 0x2000 ) ? 0x8000 : 0x4000 ) + ( tile_number * 32 ) + ( tile_line << 2 );
356         if ( wswan_vdp.tile_packed ) {
357            plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ];
361         if ( state->vdp.tile_packed ) {
362            plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ];
358363         } else {
359            plane0 = wswan_vdp.vram[ tile_address + 0 ];
360            plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
361            plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2;
362            plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3;
364            plane0 = state->vdp.vram[ tile_address + 0 ];
365            plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
366            plane2 = state->vdp.vram[ tile_address + 2 ] << 2;
367            plane3 = state->vdp.vram[ tile_address + 3 ] << 3;
363368         }
364369      } else {
365370         tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 );
366         if ( wswan_vdp.tile_packed ) {
367            plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ];
371         if ( state->vdp.tile_packed ) {
372            plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ];
368373         } else {
369            plane0 = wswan_vdp.vram[ tile_address + 0 ];
370            plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
374            plane0 = state->vdp.vram[ tile_address + 0 ];
375            plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
371376            plane2 = 0;
372377            plane3 = 0;
373378         }
r9669r9670
375380
376381      for( x = 0; x < 8; x++ ) {
377382         int   col;
378         if ( wswan_vdp.tile_packed ) {
379            if ( wswan_vdp.colors_16 ) {
383         if ( state->vdp.tile_packed ) {
384            if ( state->vdp.colors_16 ) {
380385               col = plane0 & 0x0F;
381386               plane0 = plane0 >> 4;
382387            } else {
r9669r9670
391396            plane0 = plane0 >> 1;
392397         }
393398         if ( tile_data & 0x4000 ) {
394            x_offset = x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 );
399            x_offset = x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 );
395400         } else {
396            x_offset = 7 - x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 );
401            x_offset = 7 - x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 );
397402         }
398         if ( ( x_offset >= 0 && x_offset < wswan_vdp.window_fg_left ) || ( x_offset >= wswan_vdp.window_fg_right && x_offset < WSWAN_X_PIXELS ) ) {
399            if ( wswan_vdp.colors_16 ) {
403         if ( ( x_offset >= 0 && x_offset < state->vdp.window_fg_left ) || ( x_offset >= state->vdp.window_fg_right && x_offset < WSWAN_X_PIXELS ) ) {
404            if ( state->vdp.colors_16 ) {
400405               if ( col ) {
401                  if ( wswan_vdp.color_mode ) {
402                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
406                  if ( state->vdp.color_mode ) {
407                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
403408                  } else {
404409                     /* Hmmmm, what should we do here... Is this correct?? */
405                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
410                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
406411                  }
407412               }
408413            } else {
409414               if ( col || !(tile_palette & 4 ) ) {
410                  if ( wswan_vdp.color_mode ) {
411                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
415                  if ( state->vdp.color_mode ) {
416                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
412417                  } else {
413                     wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] );
418                     wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] );
414419                  }
415420               }
416421            }
r9669r9670
420425}
421426
422427static void wswan_handle_sprites( running_machine *machine, int mask ) {
428   wswan_state *state = machine->driver_data<wswan_state>();
423429   int   i;
424   if ( wswan_vdp.sprite_count == 0 )
430   if ( state->vdp.sprite_count == 0 )
425431      return;
426   for( i = wswan_vdp.sprite_first + wswan_vdp.sprite_count - 1; i >= wswan_vdp.sprite_first; i-- ) {
432   for( i = state->vdp.sprite_first + state->vdp.sprite_count - 1; i >= state->vdp.sprite_first; i-- ) {
427433      UINT8   x, y;
428434      UINT16   tile_data;
429435      int   tile_line;
430436
431      tile_data = ( wswan_vdp.vram[ wswan_vdp.sprite_table_address + i * 4 + 1 ] << 8 )
432                  | wswan_vdp.vram[ wswan_vdp.sprite_table_address + i * 4 ];
433      y = wswan_vdp.vram[ wswan_vdp.sprite_table_address + i * 4 + 2 ];
434      x = wswan_vdp.vram[ wswan_vdp.sprite_table_address + i * 4 + 3 ];
435      tile_line = wswan_vdp.current_line - y;
437      tile_data = ( state->vdp.vram[ state->vdp.sprite_table_address + i * 4 + 1 ] << 8 )
438                  | state->vdp.vram[ state->vdp.sprite_table_address + i * 4 ];
439      y = state->vdp.vram[ state->vdp.sprite_table_address + i * 4 + 2 ];
440      x = state->vdp.vram[ state->vdp.sprite_table_address + i * 4 + 3 ];
441      tile_line = state->vdp.current_line - y;
436442      tile_line = tile_line & 0xFF;
437443      if ( ( tile_line >= 0 ) && ( tile_line < 8 ) && ( ( tile_data & mask ) == mask ) ) {
438444         UINT32   plane0 = 0, plane1 = 0, plane2 = 0, plane3 = 0;
r9669r9670
444450            tile_line = 7 - tile_line;
445451         }
446452
447         if ( wswan_vdp.colors_16 ) {
453         if ( state->vdp.colors_16 ) {
448454            tile_address = 0x4000 + ( tile_number * 32 ) + ( tile_line << 2 );
449            if ( wswan_vdp.tile_packed ) {
450               plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ];
455            if ( state->vdp.tile_packed ) {
456               plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ];
451457            } else {
452               plane0 = wswan_vdp.vram[ tile_address + 0 ];
453               plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
454               plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2;
455               plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3;
458               plane0 = state->vdp.vram[ tile_address + 0 ];
459               plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
460               plane2 = state->vdp.vram[ tile_address + 2 ] << 2;
461               plane3 = state->vdp.vram[ tile_address + 3 ] << 3;
456462            }
457463         } else {
458464            tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 );
459            if ( wswan_vdp.tile_packed ) {
460               plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ];
465            if ( state->vdp.tile_packed ) {
466               plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ];
461467            } else {
462               plane0 = wswan_vdp.vram[ tile_address + 0 ];
463               plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1;
468               plane0 = state->vdp.vram[ tile_address + 0 ];
469               plane1 = state->vdp.vram[ tile_address + 1 ] << 1;
464470               plane2 = 0;
465471               plane3 = 0;
466472            }
467473         }
468474
469         if ( wswan_vdp.window_sprites_enable ) {
475         if ( state->vdp.window_sprites_enable ) {
470476            if ( tile_data & 0x1000 ) {
471               if ( wswan_vdp.current_line >= wswan_vdp.window_sprites_top && wswan_vdp.current_line <= wswan_vdp.window_sprites_bottom ) {
477               if ( state->vdp.current_line >= state->vdp.window_sprites_top && state->vdp.current_line <= state->vdp.window_sprites_bottom ) {
472478                  check_clip = 1;
473479               }
474480            } else {
475               if ( wswan_vdp.current_line < wswan_vdp.window_sprites_top || wswan_vdp.current_line > wswan_vdp.window_sprites_bottom ) {
481               if ( state->vdp.current_line < state->vdp.window_sprites_top || state->vdp.current_line > state->vdp.window_sprites_bottom ) {
476482                  continue;
477483               }
478484            }
r9669r9670
480486
481487         for ( j = 0; j < 8; j++ ) {
482488            int col;
483            if ( wswan_vdp.tile_packed ) {
484               if ( wswan_vdp.colors_16 ) {
489            if ( state->vdp.tile_packed ) {
490               if ( state->vdp.colors_16 ) {
485491                  col = plane0 & 0x0F;
486492                  plane0 = plane0 >> 4;
487493               } else {
r9669r9670
501507               x_offset = x + 7 - j;
502508            }
503509            x_offset = x_offset & 0xFF;
504            if ( wswan_vdp.window_sprites_enable ) {
510            if ( state->vdp.window_sprites_enable ) {
505511               if ( tile_data & 0x1000 && check_clip ) {
506                  if ( x_offset >= wswan_vdp.window_sprites_left && x_offset <= wswan_vdp.window_sprites_right ) {
512                  if ( x_offset >= state->vdp.window_sprites_left && x_offset <= state->vdp.window_sprites_right ) {
507513                     continue;
508514                  }
509515               } else {
510                  if ( x_offset < wswan_vdp.window_sprites_left || x_offset > wswan_vdp.window_sprites_right ) {
516                  if ( x_offset < state->vdp.window_sprites_left || x_offset > state->vdp.window_sprites_right ) {
511517//                          continue;
512518                  }
513519               }
514520            }
515521            if ( x_offset >= 0 && x_offset < WSWAN_X_PIXELS ) {
516               if ( wswan_vdp.colors_16 ) {
522               if ( state->vdp.colors_16 ) {
517523                  if ( col ) {
518                     if ( wswan_vdp.color_mode ) {
519                        wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
524                     if ( state->vdp.color_mode ) {
525                        wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
520526                     } else {
521527                        /* Hmmmm, what should we do here... Is this correct?? */
522                        wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
528                        wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
523529                     }
524530                  }
525531               } else {
526532                  if ( col || !(tile_palette & 4 ) ) {
527                     if ( wswan_vdp.color_mode ) {
528                        wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] );
533                     if ( state->vdp.color_mode ) {
534                        wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] );
529535                     } else {
530                        wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] );
536                        wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] );
531537                     }
532538                  }
533539               }
r9669r9670
539545
540546void wswan_refresh_scanline( running_machine *machine )
541547{
548   wswan_state *state = machine->driver_data<wswan_state>();
542549   rectangle rec;
543550
544   wswan_setup_palettes();
551   wswan_setup_palettes(state);
545552
546553   rec.min_x = 0;
547554   rec.max_x = WSWAN_X_PIXELS;
548   rec.min_y = rec.max_y = wswan_vdp.current_line;
549   if ( ws_portram[0x14] ) {
555   rec.min_y = rec.max_y = state->vdp.current_line;
556   if ( state->ws_portram[0x14] ) {
550557      /* Not sure if these background color checks and settings are correct */
551      if ( wswan_vdp.color_mode && wswan_vdp.colors_16 ) {
552         wswan_fillbitmap( machine, pal[ws_portram[0x01]>>4][ws_portram[0x01]&0x0F], &rec );
558      if ( state->vdp.color_mode && state->vdp.colors_16 ) {
559         wswan_fillbitmap( machine, state->pal[state->ws_portram[0x01]>>4][state->ws_portram[0x01]&0x0F], &rec );
553560      } else {
554         wswan_fillbitmap( machine, wswan_vdp.main_palette[ws_portram[0x01]&0x07], &rec );
561         wswan_fillbitmap( machine, state->vdp.main_palette[state->ws_portram[0x01]&0x07], &rec );
555562      }
556563   } else {
557564      wswan_fillbitmap( machine, 0, &rec );
r9669r9670
561568   /*
562569     * Draw background layer
563570     */
564   if ( wswan_vdp.layer_bg_enable ) {
571   if ( state->vdp.layer_bg_enable ) {
565572      wswan_draw_background(machine);
566573   }
567574
568575   /*
569576     * Draw sprites between background and foreground layers
570577     */
571   if ( wswan_vdp.sprites_enable ) {
578   if ( state->vdp.sprites_enable ) {
572579      wswan_handle_sprites( machine, 0 );
573580   }
574581
575582   /*
576583     * Draw foreground layer, taking window settings into account
577584     */
578   if ( wswan_vdp.layer_fg_enable ) {
579      switch( wswan_vdp.window_fg_mode ) {
585   if ( state->vdp.layer_fg_enable ) {
586      switch( state->vdp.window_fg_mode ) {
580587      case 0:   /* FG inside & outside window area */
581588         wswan_draw_foreground_0(machine);
582589         break;
r9669r9670
584591         logerror( "Unknown foreground mode 1 set\n" );
585592         break;
586593      case 2:   /* FG only inside window area */
587         if ( wswan_vdp.current_line >= wswan_vdp.window_fg_top && wswan_vdp.current_line <= wswan_vdp.window_fg_bottom ) {
594         if ( state->vdp.current_line >= state->vdp.window_fg_top && state->vdp.current_line <= state->vdp.window_fg_bottom ) {
588595            wswan_draw_foreground_2(machine);
589596         }
590597         break;
591598      case 3:   /* FG only outside window area */
592         if ( wswan_vdp.current_line < wswan_vdp.window_fg_top || wswan_vdp.current_line > wswan_vdp.window_fg_bottom ) {
599         if ( state->vdp.current_line < state->vdp.window_fg_top || state->vdp.current_line > state->vdp.window_fg_bottom ) {
593600            wswan_draw_foreground_0(machine);
594601         } else {
595602            wswan_draw_foreground_3(machine);
r9669r9670
601608   /*
602609     * Draw sprites in front of foreground layer
603610     */
604   if ( wswan_vdp.sprites_enable ) {
611   if ( state->vdp.sprites_enable ) {
605612      wswan_handle_sprites( machine, 0x2000 );
606613   }
607614}
src/mess/video/zx.c
r9669r9670
2424emu_timer *ula_nmi = NULL;
2525//emu_timer *ula_irq = NULL;
2626//int ula_nmi_active;
27int ula_irq_active;
2827int ula_frame_vsync = 0;
2928//int ula_scancode_count = 0;
3029int ula_scanline_count = 0;
31static int old_x = 0;
32static int old_y = 0;
33static int old_c = 0;
34static UINT8 charline[32];
35static UINT8 charline_ptr;
36static int offs1 = 0;
3730
3831/*
3932 * Toggle the video output between black and white.
r9669r9670
4538 */
4639void zx_ula_bkgnd(running_machine *machine, int color)
4740{
41   zx_state *state = machine->driver_data<zx_state>();
4842   screen_device *screen = screen_first(*machine);
4943   int width = screen->width();
5044   int height = screen->height();
5145   const rectangle &visarea = screen->visible_area();
5246
53   if (ula_frame_vsync == 0 && color != old_c)
47   if (state->ula_frame_vsync == 0 && color != state->old_c)
5448   {
5549      int y, new_x, new_y;
5650      rectangle r;
r9669r9670
5852
5953      new_y = machine->primary_screen->vpos();
6054      new_x = machine->primary_screen->hpos();
61/*      logerror("zx_ula_bkgnd: %3d,%3d - %3d,%3d\n", old_x, old_y, new_x, new_y);*/
62      y = old_y;
55/*      logerror("zx_ula_bkgnd: %3d,%3d - %3d,%3d\n", state->old_x, state->old_y, new_x, new_y);*/
56      y = state->old_y;
6357      for (;;)
6458      {
6559         if (y == new_y)
6660         {
67            r.min_x = old_x;
61            r.min_x = state->old_x;
6862            r.max_x = new_x;
6963            r.min_y = r.max_y = y;
7064            bitmap_fill(bitmap, &r, color);
r9669r9670
7266         }
7367         else
7468         {
75            r.min_x = old_x;
69            r.min_x = state->old_x;
7670            r.max_x = visarea.max_x;
7771            r.min_y = r.max_y = y;
7872            bitmap_fill(bitmap, &r, color);
79            old_x = 0;
73            state->old_x = 0;
8074         }
8175         if (++y == height)
8276            y = 0;
8377      }
84      old_x = (new_x + 1) % width;
85      old_y = new_y;
86      old_c = color;
78      state->old_x = (new_x + 1) % width;
79      state->old_y = new_y;
80      state->old_c = color;
8781   }
8882}
8983
r9669r9670
10094 */
10195static TIMER_CALLBACK(zx_ula_nmi)
10296{
97   zx_state *state = machine->driver_data<zx_state>();
10398   /*
10499     * An NMI is issued on the ZX81 every 64us for the blanked
105100     * scanlines at the top and bottom of the display.
r9669r9670
112107   bitmap_t *bitmap = machine->generic.tmpbitmap;
113108   r.min_x = r1.min_x;
114109   r.max_x = r1.max_x;
115   r.min_y = r.max_y = ula_scanline_count;
110   r.min_y = r.max_y = state->ula_scanline_count;
116111   bitmap_fill(bitmap, &r, 1);
117112//  logerror("ULA %3d[%d] NMI, R:$%02X, $%04x\n", machine->primary_screen->vpos(), ula_scancode_count, (unsigned) cpu_get_reg(machine->device("maincpu"), Z80_R), (unsigned) cpu_get_reg(machine->device("maincpu"), Z80_PC));
118113   cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
119   if (++ula_scanline_count == height)
120      ula_scanline_count = 0;
114   if (++state->ula_scanline_count == height)
115      state->ula_scanline_count = 0;
121116}
122117
123118static TIMER_CALLBACK(zx_ula_irq)
124119{
120   zx_state *state = machine->driver_data<zx_state>();
125121
126122   /*
127123     * An IRQ is issued on the ZX80/81 whenever the R registers
128124     * bit 6 goes low. In MESS this IRQ timed from the first read
129125     * from the copy of the DFILE in the upper 32K in zx_ula_r().
130126     */
131   if (ula_irq_active)
127   if (state->ula_irq_active)
132128   {
133129//      logerror("ULA %3d[%d] IRQ, R:$%02X, $%04x\n", machine->primary_screen->vpos(), ula_scancode_count, (unsigned) cpu_get_reg(machine->device("maincpu"), Z80_R), (unsigned) cpu_get_reg(machine->device("maincpu"), Z80_PC));
134130
135      ula_irq_active = 0;
131      state->ula_irq_active = 0;
136132      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
137133   }
138134}
139135
140136void zx_ula_r(running_machine *machine, int offs, const char *region, const UINT8 param)
141137{
138   zx_state *state = machine->driver_data<zx_state>();
142139   screen_device *screen = screen_first(*machine);
143140   int offs0 = offs & 0x7fff;
144141   UINT8 *rom = memory_region(machine, "maincpu");
145142   UINT8 chr = rom[offs0];
146143
147   if ((!ula_irq_active) && (chr == 0x76))
144   if ((!state->ula_irq_active) && (chr == 0x76))
148145   {
149146      bitmap_t *bitmap = machine->generic.tmpbitmap;
150147      UINT16 y, *scanline;
r9669r9670
158155
159156      chrgen = memory_region(machine, region);
160157
161      if ((++ula_scanline_count == screen->height()) || (creg == 32))
158      if ((++state->ula_scanline_count == screen->height()) || (creg == 32))
162159      {
163         ula_scanline_count = 0;
164         offs1 = offs0;
160         state->ula_scanline_count = 0;
161         state->offs1 = offs0;
165162      }
166163
167      ula_frame_vsync = 3;
164      state->ula_frame_vsync = 3;
168165
169      charline_ptr = 0;
166      state->charline_ptr = 0;
170167
171      for (y = offs1+1; ((y < offs0) && (charline_ptr < ARRAY_LENGTH(charline))); y++)
168      for (y = state->offs1+1; ((y < offs0) && (state->charline_ptr < ARRAY_LENGTH(state->charline))); y++)
172169      {
173         charline[charline_ptr] = rom[y];
174         charline_ptr++;
170         state->charline[state->charline_ptr] = rom[y];
171         state->charline_ptr++;
175172      }
176      for (y = charline_ptr; y < ARRAY_LENGTH(charline); y++)
177         charline[y] = 0;
173      for (y = state->charline_ptr; y < ARRAY_LENGTH(state->charline); y++)
174         state->charline[y] = 0;
178175
179      timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(((32 - charline_ptr) << 2)), NULL, 0, zx_ula_irq);
180      ula_irq_active++;
176      timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(((32 - state->charline_ptr) << 2)), NULL, 0, zx_ula_irq);
177      state->ula_irq_active++;
181178
182      scanline = BITMAP_ADDR16(bitmap, ula_scanline_count, 0);
179      scanline = BITMAP_ADDR16(bitmap, state->ula_scanline_count, 0);
183180      y = 0;
184181
185      for (charline_ptr = 0; charline_ptr < ARRAY_LENGTH(charline); charline_ptr++)
182      for (state->charline_ptr = 0; state->charline_ptr < ARRAY_LENGTH(state->charline); state->charline_ptr++)
186183      {
187         chr = charline[charline_ptr];
184         chr = state->charline[state->charline_ptr];
188185         data = chrgen[ireg | ((chr & 0x3f) << 3) | ((8 - creg)&7) ];
189186         if (chr & 0x80) data ^= 0xff;
190187
r9669r9670
196193         scanline[y++] = (data >> 2) & 1;
197194         scanline[y++] = (data >> 1) & 1;
198195         scanline[y++] = (data >> 0) & 1;
199         charline[charline_ptr] = 0;
196         state->charline[state->charline_ptr] = 0;
200197      }
201198
202      if (creg == 1) offs1 = offs0;
199      if (creg == 1) state->offs1 = offs0;
203200   }
204201}
205202
206203VIDEO_START( zx )
207204{
208   ula_nmi = timer_alloc(machine, zx_ula_nmi, NULL);
209   ula_irq_active = 0;
205   zx_state *state = machine->driver_data<zx_state>();
206   state->ula_nmi = timer_alloc(machine, zx_ula_nmi, NULL);
207   state->ula_irq_active = 0;
210208   VIDEO_START_CALL(generic_bitmapped);
211209}
212210
213211VIDEO_EOF( zx )
214212{
213   zx_state *state = machine->driver_data<zx_state>();
215214   /* decrement video synchronization counter */
216   if (ula_frame_vsync)
217      --ula_frame_vsync;
215   if (state->ula_frame_vsync)
216      --state->ula_frame_vsync;
218217}
src/mess/video/mac.c
r9669r9670
1717#include "includes/mac.h"
1818#include "devices/messram.h"
1919
20static int screen_buffer;
21
2220PALETTE_INIT( mac )
2321{
2422   palette_set_color_rgb(machine, 0, 0xff, 0xff, 0xff);
r9669r9670
2725
2826
2927
30void mac_set_screen_buffer(int buffer)
31{
32   screen_buffer = buffer;
33}
34
35
36
3728VIDEO_START( mac )
3829{
39   screen_buffer = 0;
4030}
4131
4232
r9669r9670
5141   UINT16 word;
5242   UINT16 *line;
5343   int y, x, b;
44   mac_state *mac = screen->machine->driver_data<mac_state>();
5445
55   video_base = messram_get_size(screen->machine->device("messram")) - (screen_buffer ? MAC_MAIN_SCREEN_BUF_OFFSET : MAC_ALT_SCREEN_BUF_OFFSET);
46   video_base = messram_get_size(screen->machine->device("messram")) - (mac->screen_buffer ? MAC_MAIN_SCREEN_BUF_OFFSET : MAC_ALT_SCREEN_BUF_OFFSET);
5647   video_ram = (const UINT16 *) (messram_get_ptr(screen->machine->device("messram")) + video_base);
5748
5849   for (y = 0; y < MAC_V_VIS; y++)
r9669r9670
8071   int y, x, b;
8172   mac_state *mac = screen->machine->driver_data<mac_state>();
8273
83   video_base = screen_buffer ? 0x8000 : 0;
74   video_base = mac->screen_buffer ? 0x8000 : 0;
8475   video_ram = (const UINT16 *) &mac->m_se30_vram[video_base/4];
8576
8677   for (y = 0; y < MAC_V_VIS; y++)
r9669r9670
128119
129120   if (!mac->m_cb264_vbl_disable)
130121   {
131      mac->nubus_slot_interrupt(device->machine, 0xe, 1);
122      mac->nubus_slot_interrupt(0xe, 1);
132123   }
133124}
134125
r9669r9670
277268      case 0x14/4:   // VBL ack
278269         {
279270            mac_state *mac = space.machine->driver_data<mac_state>();
280            mac->nubus_slot_interrupt(space.machine, 0xe, 0);
271            mac->nubus_slot_interrupt(0xe, 0);
281272         }
282273         break;
283274
src/mess/video/x68k.c
r9669r9670
3030#include "machine/68901mfp.h"
3131#include "devices/messram.h"
3232
33UINT16* x68k_gvram;  // Graphic VRAM
34UINT16* x68k_tvram;  // Text VRAM
35UINT16* x68k_spriteram;  // sprite/background RAM
36UINT16* x68k_spritereg;  // sprite/background registers
3733
38static tilemap_t* x68k_bg0_8;  // two 64x64 tilemaps, 8x8 characters
39static tilemap_t* x68k_bg1_8;
40static tilemap_t* x68k_bg0_16;  // two 64x64 tilemaps, 16x16 characters
41static tilemap_t* x68k_bg1_16;
4234
43static int sprite_shift;
4435
4536static void x68k_crtc_refresh_mode(running_machine *machine);
4637
r9669r9670
8778    return NULL;  // should never reach here either.
8879}
8980*/
90static void x68k_crtc_text_copy(int src, int dest)
81static void x68k_crtc_text_copy(x68k_state *state, int src, int dest)
9182{
9283   // copys one raster in T-VRAM to another raster
9384   int src_ram = src * 256;  // 128 bytes per scanline
r9669r9670
10091   for(line=0;line<8;line++)
10192   {
10293      // update RAM in each plane
103      memcpy(x68k_tvram+dest_ram,x68k_tvram+src_ram,128);
104      memcpy(x68k_tvram+dest_ram+0x10000,x68k_tvram+src_ram+0x10000,128);
105      memcpy(x68k_tvram+dest_ram+0x20000,x68k_tvram+src_ram+0x20000,128);
106      memcpy(x68k_tvram+dest_ram+0x30000,x68k_tvram+src_ram+0x30000,128);
94      memcpy(state->tvram+dest_ram,state->tvram+src_ram,128);
95      memcpy(state->tvram+dest_ram+0x10000,state->tvram+src_ram+0x10000,128);
96      memcpy(state->tvram+dest_ram+0x20000,state->tvram+src_ram+0x20000,128);
97      memcpy(state->tvram+dest_ram+0x30000,state->tvram+src_ram+0x30000,128);
10798
10899      src_ram+=64;
109100      dest_ram+=64;
r9669r9670
113104
114105static TIMER_CALLBACK(x68k_crtc_operation_end)
115106{
107   x68k_state *state = machine->driver_data<x68k_state>();
116108   int bit = param;
117   x68k_sys.crtc.operation &= ~bit;
109   state->crtc.operation &= ~bit;
118110}
119111
120112static void x68k_crtc_refresh_mode(running_machine *machine)
121113{
114   x68k_state *state = machine->driver_data<x68k_state>();
122115//  rectangle rect;
123116//  double scantime;
124117   rectangle scr,visiblescr;
125118   int length;
126119
127120   // Calculate data from register values
128   x68k_sys.crtc.vmultiple = 1;
129   if((x68k_sys.crtc.reg[20] & 0x10) != 0 && (x68k_sys.crtc.reg[20] & 0x0c) == 0)
130      x68k_sys.crtc.vmultiple = 2;  // 31.5kHz + 256 lines = doublescan
131   if(x68k_sys.crtc.interlace != 0)
132      x68k_sys.crtc.vmultiple = 0.5f;  // 31.5kHz + 1024 lines or 15kHz + 512 lines = interlaced
133   x68k_sys.crtc.htotal = (x68k_sys.crtc.reg[0] + 1) * 8;
134   x68k_sys.crtc.vtotal = (x68k_sys.crtc.reg[4] + 1) / x68k_sys.crtc.vmultiple; // default is 567 (568 scanlines)
135   x68k_sys.crtc.hbegin = (x68k_sys.crtc.reg[2] * 8) + 1;
136   x68k_sys.crtc.hend = (x68k_sys.crtc.reg[3] * 8);
137   x68k_sys.crtc.vbegin = (x68k_sys.crtc.reg[6]) / x68k_sys.crtc.vmultiple;
138   x68k_sys.crtc.vend = (x68k_sys.crtc.reg[7] - 1) / x68k_sys.crtc.vmultiple;
139   x68k_sys.crtc.hsync_end = (x68k_sys.crtc.reg[1]) * 8;
140   x68k_sys.crtc.vsync_end = (x68k_sys.crtc.reg[5]) / x68k_sys.crtc.vmultiple;
141   x68k_sys.crtc.hsyncadjust = x68k_sys.crtc.reg[8];
121   state->crtc.vmultiple = 1;
122   if((state->crtc.reg[20] & 0x10) != 0 && (state->crtc.reg[20] & 0x0c) == 0)
123      state->crtc.vmultiple = 2;  // 31.5kHz + 256 lines = doublescan
124   if(state->crtc.interlace != 0)
125      state->crtc.vmultiple = 0.5f;  // 31.5kHz + 1024 lines or 15kHz + 512 lines = interlaced
126   state->crtc.htotal = (state->crtc.reg[0] + 1) * 8;
127   state->crtc.vtotal = (state->crtc.reg[4] + 1) / state->crtc.vmultiple; // default is 567 (568 scanlines)
128   state->crtc.hbegin = (state->crtc.reg[2] * 8) + 1;
129   state->crtc.hend = (state->crtc.reg[3] * 8);
130   state->crtc.vbegin = (state->crtc.reg[6]) / state->crtc.vmultiple;
131   state->crtc.vend = (state->crtc.reg[7] - 1) / state->crtc.vmultiple;
132   state->crtc.hsync_end = (state->crtc.reg[1]) * 8;
133   state->crtc.vsync_end = (state->crtc.reg[5]) / state->crtc.vmultiple;
134   state->crtc.hsyncadjust = state->crtc.reg[8];
142135   scr.min_x = scr.min_y = 0;
143   scr.max_x = x68k_sys.crtc.htotal - 8;
144   scr.max_y = x68k_sys.crtc.vtotal;
145   if(scr.max_y <= x68k_sys.crtc.vend)
146      scr.max_y = x68k_sys.crtc.vend + 2;
147   if(scr.max_x <= x68k_sys.crtc.hend)
148      scr.max_x = x68k_sys.crtc.hend + 2;
149   visiblescr.min_x = x68k_sys.crtc.hbegin;
150   visiblescr.max_x = x68k_sys.crtc.hend;
151   visiblescr.min_y = x68k_sys.crtc.vbegin;
152   visiblescr.max_y = x68k_sys.crtc.vend;
136   scr.max_x = state->crtc.htotal - 8;
137   scr.max_y = state->crtc.vtotal;
138   if(scr.max_y <= state->crtc.vend)
139      scr.max_y = state->crtc.vend + 2;
140   if(scr.max_x <= state->crtc.hend)
141      scr.max_x = state->crtc.hend + 2;
142   visiblescr.min_x = state->crtc.hbegin;
143   visiblescr.max_x = state->crtc.hend;
144   visiblescr.min_y = state->crtc.vbegin;
145   visiblescr.max_y = state->crtc.vend;
153146
154147   // expand visible area to the size indicated by CRTC reg 20
155   length = x68k_sys.crtc.hend - x68k_sys.crtc.hbegin;
156   if (length < x68k_sys.crtc.width)
148   length = state->crtc.hend - state->crtc.hbegin;
149   if (length < state->crtc.width)
157150   {
158      visiblescr.min_x = x68k_sys.crtc.hbegin - ((x68k_sys.crtc.width - length)/2);
159      visiblescr.max_x = x68k_sys.crtc.hend + ((x68k_sys.crtc.width - length)/2);
151      visiblescr.min_x = state->crtc.hbegin - ((state->crtc.width - length)/2);
152      visiblescr.max_x = state->crtc.hend + ((state->crtc.width - length)/2);
160153   }
161   length = x68k_sys.crtc.vend - x68k_sys.crtc.vbegin;
162   if (length < x68k_sys.crtc.height)
154   length = state->crtc.vend - state->crtc.vbegin;
155   if (length < state->crtc.height)
163156   {
164      visiblescr.min_y = x68k_sys.crtc.vbegin - ((x68k_sys.crtc.height - length)/2);
165      visiblescr.max_y = x68k_sys.crtc.vend + ((x68k_sys.crtc.height - length)/2);
157      visiblescr.min_y = state->crtc.vbegin - ((state->crtc.height - length)/2);
158      visiblescr.max_y = state->crtc.vend + ((state->crtc.height - length)/2);
166159   }
167160   // bounds check
168161   if(visiblescr.min_x < 0)
r9669r9670
174167   if(visiblescr.max_y >= scr.max_y - 1)
175168      visiblescr.max_y = scr.max_y - 2;
176169
177//  logerror("CRTC regs - %i %i %i %i  - %i %i %i %i - %i - %i\n",x68k_sys.crtc.reg[0],x68k_sys.crtc.reg[1],x68k_sys.crtc.reg[2],x68k_sys.crtc.reg[3],
178//      x68k_sys.crtc.reg[4],x68k_sys.crtc.reg[5],x68k_sys.crtc.reg[6],x68k_sys.crtc.reg[7],x68k_sys.crtc.reg[8],x68k_sys.crtc.reg[9]);
170//  logerror("CRTC regs - %i %i %i %i  - %i %i %i %i - %i - %i\n",state->crtc.reg[0],state->crtc.reg[1],state->crtc.reg[2],state->crtc.reg[3],
171//      state->crtc.reg[4],state->crtc.reg[5],state->crtc.reg[6],state->crtc.reg[7],state->crtc.reg[8],state->crtc.reg[9]);
179172   logerror("video_screen_configure(machine->primary_screen,%i,%i,[%i,%i,%i,%i],55.45)\n",scr.max_x,scr.max_y,visiblescr.min_x,visiblescr.min_y,visiblescr.max_x,visiblescr.max_y);
180173   machine->primary_screen->configure(scr.max_x,scr.max_y,visiblescr,HZ_TO_ATTOSECONDS(55.45));
181174}
182175
183176TIMER_CALLBACK(x68k_hsync)
184177{
185   int state = param;
178   x68k_state *state = machine->driver_data<x68k_state>();
179   int hstate = param;
186180   attotime hsync_time;
187181
188   x68k_sys.crtc.hblank = state;
189   if(x68k_sys.crtc.vmultiple == 2) // 256-line (doublescan)
182   state->crtc.hblank = hstate;
183   if(state->crtc.vmultiple == 2) // 256-line (doublescan)
190184   {
191      static int oddscanline;
192      if(state == 1)
185      if(hstate == 1)
193186      {
194         if(oddscanline == 1)
187         if(state->oddscanline == 1)
195188         {
196189            int scan = machine->primary_screen->vpos();
197            if(scan > x68k_sys.crtc.vend)
198               scan = x68k_sys.crtc.vbegin;
199            hsync_time = machine->primary_screen->time_until_pos(scan,(x68k_sys.crtc.htotal + x68k_sys.crtc.hend) / 2);
200            timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 0);
190            if(scan > state->crtc.vend)
191               scan = state->crtc.vbegin;
192            hsync_time = machine->primary_screen->time_until_pos(scan,(state->crtc.htotal + state->crtc.hend) / 2);
193            timer_adjust_oneshot(state->scanline_timer, hsync_time, 0);
201194            if(scan != 0)
202195            {
203196               if((input_port_read(machine, "options") & 0x04))
r9669r9670
209202         else
210203         {
211204            int scan = machine->primary_screen->vpos();
212            if(scan > x68k_sys.crtc.vend)
213               scan = x68k_sys.crtc.vbegin;
214            hsync_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hend / 2);
215            timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 0);
205            if(scan > state->crtc.vend)
206               scan = state->crtc.vbegin;
207            hsync_time = machine->primary_screen->time_until_pos(scan,state->crtc.hend / 2);
208            timer_adjust_oneshot(state->scanline_timer, hsync_time, 0);
216209            if(scan != 0)
217210            {
218211               if((input_port_read(machine, "options") & 0x04))
r9669r9670
222215            }
223216         }
224217      }
225      if(state == 0)
218      if(hstate == 0)
226219      {
227         if(oddscanline == 1)
220         if(state->oddscanline == 1)
228221         {
229222            int scan = machine->primary_screen->vpos();
230            if(scan > x68k_sys.crtc.vend)
231               scan = x68k_sys.crtc.vbegin;
223            if(scan > state->crtc.vend)
224               scan = state->crtc.vbegin;
232225            else
233226               scan++;
234            hsync_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hbegin / 2);
235            timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 1);
236            oddscanline = 0;
227            hsync_time = machine->primary_screen->time_until_pos(scan,state->crtc.hbegin / 2);
228            timer_adjust_oneshot(state->scanline_timer, hsync_time, 1);
229            state->oddscanline = 0;
237230         }
238231         else
239232         {
240            hsync_time = machine->primary_screen->time_until_pos(machine->primary_screen->vpos(),(x68k_sys.crtc.htotal + x68k_sys.crtc.hbegin) / 2);
241            timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 1);
242            oddscanline = 1;
233            hsync_time = machine->primary_screen->time_until_pos(machine->primary_screen->vpos(),(state->crtc.htotal + state->crtc.hbegin) / 2);
234            timer_adjust_oneshot(state->scanline_timer, hsync_time, 1);
235            state->oddscanline = 1;
243236         }
244237      }
245238   }
246239   else  // 512-line
247240   {
248      if(state == 1)
241      if(hstate == 1)
249242      {
250243         int scan = machine->primary_screen->vpos();
251         if(scan > x68k_sys.crtc.vend)
244         if(scan > state->crtc.vend)
252245            scan = 0;
253         hsync_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hend);
254         timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 0);
246         hsync_time = machine->primary_screen->time_until_pos(scan,state->crtc.hend);
247         timer_adjust_oneshot(state->scanline_timer, hsync_time, 0);
255248         if(scan != 0)
256249         {
257250            if((input_port_read(machine, "options") & 0x04))
r9669r9670
260253            }
261254         }
262255      }
263      if(state == 0)
256      if(hstate == 0)
264257      {
265         hsync_time = machine->primary_screen->time_until_pos(machine->primary_screen->vpos()+1,x68k_sys.crtc.hbegin);
266         timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 1);
267   //      if(!(x68k_sys.mfp.gpio & 0x40))  // if GPIP6 is active, clear it
268   //          x68k_sys.mfp.gpio |= 0x40;
258         hsync_time = machine->primary_screen->time_until_pos(machine->primary_screen->vpos()+1,state->crtc.hbegin);
259         timer_adjust_oneshot(state->scanline_timer, hsync_time, 1);
260   //      if(!(state->mfp.gpio & 0x40))  // if GPIP6 is active, clear it
261   //          state->mfp.gpio |= 0x40;
269262      }
270263   }
271264}
272265
273266static TIMER_CALLBACK(x68k_crtc_raster_end)
274267{
275   x68k_sys.mfp.gpio |= 0x40;
268   x68k_state *state = machine->driver_data<x68k_state>();
269   state->mfp.gpio |= 0x40;
276270}
277271
278272TIMER_CALLBACK(x68k_crtc_raster_irq)
279273{
274   x68k_state *state = machine->driver_data<x68k_state>();
280275   int scan = param;
281276   attotime irq_time;
282277   attotime end_time;
283278
284   if(scan <= x68k_sys.crtc.vtotal)
279   if(scan <= state->crtc.vtotal)
285280   {
286      x68k_sys.mfp.gpio &= ~0x40;  // GPIP6
281      state->mfp.gpio &= ~0x40;  // GPIP6
287282      machine->primary_screen->update_partial(scan);
288      irq_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hbegin);
283      irq_time = machine->primary_screen->time_until_pos(scan,state->crtc.hbegin);
289284      // end of HBlank period clears GPIP6 also?
290      end_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hend);
291      timer_adjust_oneshot(x68k_raster_irq, irq_time, scan);
285      end_time = machine->primary_screen->time_until_pos(scan,state->crtc.hend);
286      timer_adjust_oneshot(state->raster_irq, irq_time, scan);
292287      timer_set(machine, end_time,NULL,0,x68k_crtc_raster_end);
293288      logerror("GPIP6: Raster triggered at line %i (%i)\n",scan,machine->primary_screen->vpos());
294289   }
r9669r9670
296291
297292TIMER_CALLBACK(x68k_crtc_vblank_irq)
298293{
294   x68k_state *state = machine->driver_data<x68k_state>();
299295   running_device *x68k_mfp = machine->device(MC68901_TAG);
300296   int val = param;
301297   attotime irq_time;
r9669r9670
303299
304300   if(val == 1)  // VBlank on
305301   {
306      x68k_sys.crtc.vblank = 1;
307      vblank_line = x68k_sys.crtc.vbegin;
302      state->crtc.vblank = 1;
303      vblank_line = state->crtc.vbegin;
308304      irq_time = machine->primary_screen->time_until_pos(vblank_line,2);
309      timer_adjust_oneshot(x68k_vblank_irq, irq_time, 0);
305      timer_adjust_oneshot(state->vblank_irq, irq_time, 0);
310306      logerror("CRTC: VBlank on\n");
311307   }
312308   if(val == 0)  // VBlank off
313309   {
314      x68k_sys.crtc.vblank = 0;
315      vblank_line = x68k_sys.crtc.vend;
316      if(vblank_line > x68k_sys.crtc.vtotal)
317         vblank_line = x68k_sys.crtc.vtotal;
310      state->crtc.vblank = 0;
311      vblank_line = state->crtc.vend;
312      if(vblank_line > state->crtc.vtotal)
313         vblank_line = state->crtc.vtotal;
318314      irq_time = machine->primary_screen->time_until_pos(vblank_line,2);
319      timer_adjust_oneshot(x68k_vblank_irq, irq_time, 1);
315      timer_adjust_oneshot(state->vblank_irq, irq_time, 1);
320316      logerror("CRTC: VBlank off\n");
321317   }
322318
323319   if (x68k_mfp != NULL)
324      mc68901_tai_w(x68k_mfp, !x68k_sys.crtc.vblank);
320      mc68901_tai_w(x68k_mfp, !state->crtc.vblank);
325321}
326322
327323
r9669r9670
374370 */
375371WRITE16_HANDLER( x68k_crtc_w )
376372{
377   COMBINE_DATA(x68k_sys.crtc.reg+offset);
373   x68k_state *state = space->machine->driver_data<x68k_state>();
374   COMBINE_DATA(state->crtc.reg+offset);
378375   switch(offset)
379376   {
380377   case 0:
r9669r9670
391388   case 9:  // CRTC raster IRQ (GPIP6)
392389      {
393390         attotime irq_time;
394         irq_time = space->machine->primary_screen->time_until_pos((data) / x68k_sys.crtc.vmultiple,2);
391         irq_time = space->machine->primary_screen->time_until_pos((data) / state->crtc.vmultiple,2);
395392
396393         if(attotime_to_double(irq_time) > 0)
397            timer_adjust_oneshot(x68k_raster_irq, irq_time, (data) / x68k_sys.crtc.vmultiple);
394            timer_adjust_oneshot(state->raster_irq, irq_time, (data) / state->crtc.vmultiple);
398395      }
399396      logerror("CRTC: Write to raster IRQ register - %i\n",data);
400397      break;
401398   case 20:
402399      if(ACCESSING_BITS_0_7)
403400      {
404         x68k_sys.crtc.interlace = 0;
401         state->crtc.interlace = 0;
405402         switch(data & 0x0c)
406403         {
407404         case 0x00:
408            x68k_sys.crtc.height = 256;
405            state->crtc.height = 256;
409406            break;
410407         case 0x08:
411408         case 0x0c:  // TODO: 1024 vertical, if horizontal freq = 31kHz
412            x68k_sys.crtc.height = 512;
413            x68k_sys.crtc.interlace = 1;  // if 31kHz, 1024 lines = interlaced
409            state->crtc.height = 512;
410            state->crtc.interlace = 1;  // if 31kHz, 1024 lines = interlaced
414411            break;
415412         case 0x04:
416            x68k_sys.crtc.height = 512;
417            if(!(x68k_sys.crtc.reg[20] & 0x0010))  // if 15kHz, 512 lines = interlaced
418               x68k_sys.crtc.interlace = 1;
413            state->crtc.height = 512;
414            if(!(state->crtc.reg[20] & 0x0010))  // if 15kHz, 512 lines = interlaced
415               state->crtc.interlace = 1;
419416            break;
420417         }
421418         switch(data & 0x03)
422419         {
423420         case 0x00:
424            x68k_sys.crtc.width = 256;
421            state->crtc.width = 256;
425422            break;
426423         case 0x01:
427            x68k_sys.crtc.width = 512;
424            state->crtc.width = 512;
428425            break;
429426         case 0x02:
430427         case 0x03:  // 0x03 = 50MHz clock mode (XVI only)
431            x68k_sys.crtc.width = 768;
428            state->crtc.width = 768;
432429            break;
433430         }
434431      }
435432/*      if(ACCESSING_BITS_8_15)
436433        {
437            x68k_sys.crtc.interlace = 0;
434            state->crtc.interlace = 0;
438435            if(data & 0x0400)
439                x68k_sys.crtc.interlace = 1;
436                state->crtc.interlace = 1;
440437        }*/
441438      x68k_crtc_refresh_mode(space->machine);
442439      break;
443440   case 576:  // operation register
444      x68k_sys.crtc.operation = data;
441      state->crtc.operation = data;
445442      if(data & 0x08)  // text screen raster copy
446443      {
447         x68k_crtc_text_copy((x68k_sys.crtc.reg[22] & 0xff00) >> 8,(x68k_sys.crtc.reg[22] & 0x00ff));
444         x68k_crtc_text_copy(state, (state->crtc.reg[22] & 0xff00) >> 8,(state->crtc.reg[22] & 0x00ff));
448445         timer_set(space->machine, ATTOTIME_IN_MSEC(1), NULL, 0x02,x68k_crtc_operation_end);  // time taken to do operation is a complete guess.
449446      }
450447      if(data & 0x02)  // high-speed graphic screen clear
451448      {
452         memset(x68k_gvram,0,0x40000);
449         memset(state->gvram,0,0x40000);
453450         timer_set(space->machine, ATTOTIME_IN_MSEC(10), NULL, 0x02,x68k_crtc_operation_end);  // time taken to do operation is a complete guess.
454451      }
455452      break;
r9669r9670
459456
460457READ16_HANDLER( x68k_crtc_r )
461458{
459   x68k_state *state = space->machine->driver_data<x68k_state>();
462460#if 0
463461   switch(offset)
464462   {
r9669r9670
470468
471469   if(offset < 24)
472470   {
473//      logerror("CRTC: [%08x] Read %04x from CRTC register %i\n",cpu_get_pc(space->machine->device("maincpu")),x68k_sys.crtc.reg[offset],offset);
471//      logerror("CRTC: [%08x] Read %04x from CRTC register %i\n",cpu_get_pc(space->machine->device("maincpu")),state->crtc.reg[offset],offset);
474472      switch(offset)
475473      {
476474      case 9:
r9669r9670
479477      case 11:
480478      case 12:  // Graphic layer 0 scroll
481479      case 13:
482         return x68k_sys.crtc.reg[offset] & 0x3ff;
480         return state->crtc.reg[offset] & 0x3ff;
483481      case 14:  // Graphic layer 1 scroll
484482      case 15:
485483      case 16:  // Graphic layer 2 scroll
486484      case 17:
487485      case 18:  // Graphic layer 3 scroll
488486      case 19:
489         return x68k_sys.crtc.reg[offset] & 0x1ff;
487         return state->crtc.reg[offset] & 0x1ff;
490488      default:
491         return x68k_sys.crtc.reg[offset];
489         return state->crtc.reg[offset];
492490      }
493491   }
494492   if(offset == 576) // operation port, operation bits are set to 0 when operation is complete
495      return x68k_sys.crtc.operation;
493      return state->crtc.operation;
496494//  logerror("CRTC: [%08x] Read from unknown CRTC register %i\n",activecpu_get_pc(),offset);
497495   return 0xffff;
498496}
499497
500498WRITE16_HANDLER( x68k_gvram_w )
501499{
500   x68k_state *state = space->machine->driver_data<x68k_state>();
502501//  int xloc,yloc,pageoffset;
503502   /*
504503       G-VRAM usage is determined by colour depth and "real" screen size.
r9669r9670
516515    */
517516
518517   // handle different G-VRAM page setups
519   if(x68k_sys.crtc.reg[20] & 0x08)  // G-VRAM set to buffer
518   if(state->crtc.reg[20] & 0x08)  // G-VRAM set to buffer
520519   {
521520      if(offset < 0x40000)
522         COMBINE_DATA(x68k_gvram+offset);
521         COMBINE_DATA(state->gvram+offset);
523522   }
524523   else
525524   {
526      switch(x68k_sys.crtc.reg[20] & 0x0300)
525      switch(state->crtc.reg[20] & 0x0300)
527526      {
528527         case 0x0300:
529528            if(offset < 0x40000)
530               COMBINE_DATA(x68k_gvram+offset);
529               COMBINE_DATA(state->gvram+offset);
531530            break;
532531         case 0x0100:
533532            if(offset < 0x40000)
534533            {
535               x68k_gvram[offset] = (x68k_gvram[offset] & 0xff00) | (data & 0x00ff);
534               state->gvram[offset] = (state->gvram[offset] & 0xff00) | (data & 0x00ff);
536535            }
537536            if(offset >= 0x40000 && offset < 0x80000)
538537            {
539               x68k_gvram[offset-0x40000] = (x68k_gvram[offset-0x40000] & 0x00ff) | ((data & 0x00ff) << 8);
538               state->gvram[offset-0x40000] = (state->gvram[offset-0x40000] & 0x00ff) | ((data & 0x00ff) << 8);
540539            }
541540            break;
542541         case 0x0000:
543542            if(offset < 0x40000)
544543            {
545               x68k_gvram[offset] = (x68k_gvram[offset] & 0xfff0) | (data & 0x000f);
544               state->gvram[offset] = (state->gvram[offset] & 0xfff0) | (data & 0x000f);
546545            }
547546            if(offset >= 0x40000 && offset < 0x80000)
548547            {
549               x68k_gvram[offset-0x40000] = (x68k_gvram[offset-0x40000] & 0xff0f) | ((data & 0x000f) << 4);
548               state->gvram[offset-0x40000] = (state->gvram[offset-0x40000] & 0xff0f) | ((data & 0x000f) << 4);
550549            }
551550            if(offset >= 0x80000 && offset < 0xc0000)
552551            {
553               x68k_gvram[offset-0x80000] = (x68k_gvram[offset-0x80000] & 0xf0ff) | ((data & 0x000f) << 8);
552               state->gvram[offset-0x80000] = (state->gvram[offset-0x80000] & 0xf0ff) | ((data & 0x000f) << 8);
554553            }
555554            if(offset >= 0xc0000 && offset < 0x100000)
556555            {
557               x68k_gvram[offset-0xc0000] = (x68k_gvram[offset-0xc0000] & 0x0fff) | ((data & 0x000f) << 12);
556               state->gvram[offset-0xc0000] = (state->gvram[offset-0xc0000] & 0x0fff) | ((data & 0x000f) << 12);
558557            }
559558            break;
560559         default:
r9669r9670
565564
566565WRITE16_HANDLER( x68k_tvram_w )
567566{
567   x68k_state *state = space->machine->driver_data<x68k_state>();
568568   UINT16 text_mask;
569569
570   text_mask = ~(x68k_sys.crtc.reg[23]) & mem_mask;
570   text_mask = ~(state->crtc.reg[23]) & mem_mask;
571571
572   if(!(x68k_sys.crtc.reg[21] & 0x0200)) // text access mask enable
572   if(!(state->crtc.reg[21] & 0x0200)) // text access mask enable
573573      text_mask = 0xffff & mem_mask;
574574
575575   mem_mask = text_mask;
576576
577   if(x68k_sys.crtc.reg[21] & 0x0100)
577   if(state->crtc.reg[21] & 0x0100)
578578   {  // simultaneous T-VRAM plane access (I think ;))
579579      int plane,wr;
580580      offset = offset & 0x00ffff;
581      wr = (x68k_sys.crtc.reg[21] & 0x00f0) >> 4;
581      wr = (state->crtc.reg[21] & 0x00f0) >> 4;
582582      for(plane=0;plane<4;plane++)
583583      {
584584         if(wr & (1 << plane))
585585         {
586            COMBINE_DATA(x68k_tvram+offset+(0x10000*plane));
586            COMBINE_DATA(state->tvram+offset+(0x10000*plane));
587587         }
588588      }
589589   }
590590   else
591591   {
592      COMBINE_DATA(x68k_tvram+offset);
592      COMBINE_DATA(state->tvram+offset);
593593   }
594594}
595595
596596READ16_HANDLER( x68k_gvram_r )
597597{
598   x68k_state *state = space->machine->driver_data<x68k_state>();
598599   UINT16 ret = 0;
599600
600   if(x68k_sys.crtc.reg[20] & 0x08)  // G-VRAM set to buffer
601      return x68k_gvram[offset];
601   if(state->crtc.reg[20] & 0x08)  // G-VRAM set to buffer
602      return state->gvram[offset];
602603
603   switch(x68k_sys.crtc.reg[20] & 0x0300)  // colour setup determines G-VRAM use
604   switch(state->crtc.reg[20] & 0x0300)  // colour setup determines G-VRAM use
604605   {
605606      case 0x0300: // 65,536 colour (RGB) - 16-bits per word
606607         if(offset < 0x40000)
607            ret = x68k_gvram[offset];
608            ret = state->gvram[offset];
608609         else
609610            ret = 0xffff;
610611         break;
611612      case 0x0100:  // 256 colour (paletted) - 8 bits per word
612613         if(offset < 0x40000)
613            ret = x68k_gvram[offset] & 0x00ff;
614            ret = state->gvram[offset] & 0x00ff;
614615         if(offset >= 0x40000 && offset < 0x80000)
615            ret = (x68k_gvram[offset-0x40000] & 0xff00) >> 8;
616            ret = (state->gvram[offset-0x40000] & 0xff00) >> 8;
616617         if(offset >= 0x80000)
617618            ret = 0xffff;
618619         break;
619620      case 0x0000:  // 16 colour (paletted) - 4 bits per word
620621         if(offset < 0x40000)
621            ret = x68k_gvram[offset] & 0x000f;
622            ret = state->gvram[offset] & 0x000f;
622623         if(offset >= 0x40000 && offset < 0x80000)
623            ret = (x68k_gvram[offset-0x40000] & 0x00f0) >> 4;
624            ret = (state->gvram[offset-0x40000] & 0x00f0) >> 4;
624625         if(offset >= 0x80000 && offset < 0xc0000)
625            ret = (x68k_gvram[offset-0x80000] & 0x0f00) >> 8;
626            ret = (state->gvram[offset-0x80000] & 0x0f00) >> 8;
626627         if(offset >= 0xc0000 && offset < 0x100000)
627            ret = (x68k_gvram[offset-0xc0000] & 0xf000) >> 12;
628            ret = (state->gvram[offset-0xc0000] & 0xf000) >> 12;
628629         break;
629630      default:
630631         logerror("G-VRAM read while layer setup is undefined.\n");
r9669r9670
636637
637638READ16_HANDLER( x68k_tvram_r )
638639{
639   return x68k_tvram[offset];
640   x68k_state *state = space->machine->driver_data<x68k_state>();
641   return state->tvram[offset];
640642}
641643
642644READ32_HANDLER( x68k_tvram32_r )
r9669r9670
689691
690692WRITE16_HANDLER( x68k_spritereg_w )
691693{
692   COMBINE_DATA(x68k_spritereg+offset);
694   x68k_state *state = space->machine->driver_data<x68k_state>();
695   COMBINE_DATA(state->spritereg+offset);
693696   switch(offset)
694697   {
695698   case 0x400:
696      tilemap_set_scrollx(x68k_bg0_8,0,(data - x68k_sys.crtc.hbegin) & 0x3ff);
697      tilemap_set_scrollx(x68k_bg0_16,0,(data - x68k_sys.crtc.hbegin) & 0x3ff);
699      tilemap_set_scrollx(state->bg0_8,0,(data - state->crtc.hbegin) & 0x3ff);
700      tilemap_set_scrollx(state->bg0_16,0,(data - state->crtc.hbegin) & 0x3ff);
698701      break;
699702   case 0x401:
700      tilemap_set_scrolly(x68k_bg0_8,0,(data - x68k_sys.crtc.vbegin) & 0x3ff);
701      tilemap_set_scrolly(x68k_bg0_16,0,(data - x68k_sys.crtc.vbegin) & 0x3ff);
703      tilemap_set_scrolly(state->bg0_8,0,(data - state->crtc.vbegin) & 0x3ff);
704      tilemap_set_scrolly(state->bg0_16,0,(data - state->crtc.vbegin) & 0x3ff);
702705      break;
703706   case 0x402:
704      tilemap_set_scrollx(x68k_bg1_8,0,(data - x68k_sys.crtc.hbegin) & 0x3ff);
705      tilemap_set_scrollx(x68k_bg1_16,0,(data - x68k_sys.crtc.hbegin) & 0x3ff);
707      tilemap_set_scrollx(state->bg1_8,0,(data - state->crtc.hbegin) & 0x3ff);
708      tilemap_set_scrollx(state->bg1_16,0,(data - state->crtc.hbegin) & 0x3ff);
706709      break;
707710   case 0x403:
708      tilemap_set_scrolly(x68k_bg1_8,0,(data - x68k_sys.crtc.vbegin) & 0x3ff);
709      tilemap_set_scrolly(x68k_bg1_16,0,(data - x68k_sys.crtc.vbegin) & 0x3ff);
711      tilemap_set_scrolly(state->bg1_8,0,(data - state->crtc.vbegin) & 0x3ff);
712      tilemap_set_scrolly(state->bg1_16,0,(data - state->crtc.vbegin) & 0x3ff);
710713      break;
711714   case 0x405:  // BG H-DISP (like CRTC reg 2)
712715      if(data != 0x00ff)
713716      {
714         x68k_sys.crtc.bg_visible_width = (x68k_sys.crtc.reg[3] - ((data & 0x003f) - 4)) * 8;
715         x68k_sys.crtc.bg_hshift = (x68k_sys.crtc.width - x68k_sys.crtc.bg_visible_width) / 2;
717         state->crtc.bg_visible_width = (state->crtc.reg[3] - ((data & 0x003f) - 4)) * 8;
718         state->crtc.bg_hshift = (state->crtc.width - state->crtc.bg_visible_width) / 2;
716719      }
717720      else
718         x68k_sys.crtc.bg_hshift = x68k_sys.crtc.hshift;
721         state->crtc.bg_hshift = state->crtc.hshift;
719722      break;
720723   case 0x406:  // BG V-DISP (like CRTC reg 6)
721      x68k_sys.crtc.bg_vshift = x68k_sys.crtc.vshift;
724      state->crtc.bg_vshift = state->crtc.vshift;
722725      break;
723726   }
724727}
725728
726729READ16_HANDLER( x68k_spritereg_r )
727730{
731   x68k_state *state = space->machine->driver_data<x68k_state>();
728732   if(offset >= 0x400 && offset < 0x404)
729      return x68k_spritereg[offset] & 0x3ff;
730   return x68k_spritereg[offset];
733      return state->spritereg[offset] & 0x3ff;
734   return state->spritereg[offset];
731735}
732736
733737WRITE16_HANDLER( x68k_spriteram_w )
734738{
735   COMBINE_DATA(x68k_spriteram+offset);
736   x68k_sys.video.tile8_dirty[offset / 16] = 1;
737   x68k_sys.video.tile16_dirty[offset / 64] = 1;
739   x68k_state *state = space->machine->driver_data<x68k_state>();
740   COMBINE_DATA(state->spriteram+offset);
741   state->video.tile8_dirty[offset / 16] = 1;
742   state->video.tile16_dirty[offset / 64] = 1;
738743   if(offset < 0x2000)
739744   {
740        tilemap_mark_all_tiles_dirty(x68k_bg1_8);
741        tilemap_mark_all_tiles_dirty(x68k_bg1_16);
742        tilemap_mark_all_tiles_dirty(x68k_bg0_8);
743        tilemap_mark_all_tiles_dirty(x68k_bg0_16);
745        tilemap_mark_all_tiles_dirty(state->bg1_8);
746        tilemap_mark_all_tiles_dirty(state->bg1_16);
747        tilemap_mark_all_tiles_dirty(state->bg0_8);
748        tilemap_mark_all_tiles_dirty(state->bg0_16);
744749    }
745750    if(offset >= 0x2000 && offset < 0x3000)
746751    {
747        tilemap_mark_tile_dirty(x68k_bg1_8,offset & 0x0fff);
748        tilemap_mark_tile_dirty(x68k_bg1_16,offset & 0x0fff);
752        tilemap_mark_tile_dirty(state->bg1_8,offset & 0x0fff);
753        tilemap_mark_tile_dirty(state->bg1_16,offset & 0x0fff);
749754    }
750755    if(offset >= 0x3000)
751756    {
752        tilemap_mark_tile_dirty(x68k_bg0_8,offset & 0x0fff);
753        tilemap_mark_tile_dirty(x68k_bg0_16,offset & 0x0fff);
757        tilemap_mark_tile_dirty(state->bg0_8,offset & 0x0fff);
758        tilemap_mark_tile_dirty(state->bg0_16,offset & 0x0fff);
754759    }
755760}
756761
757762READ16_HANDLER( x68k_spriteram_r )
758763{
759   return x68k_spriteram[offset];
764   x68k_state *state = space->machine->driver_data<x68k_state>();
765   return state->spriteram[offset];
760766}
761767
762768static void x68k_draw_text(running_machine* machine,bitmap_t* bitmap, int xscr, int yscr, rectangle rect)
763769{
770   x68k_state *state = machine->driver_data<x68k_state>();
764771   unsigned int line,pixel; // location on screen
765772   UINT32 loc;  // location in TVRAM
766773   UINT32 colour;
r9669r9670
769776   for(line=rect.min_y;line<=rect.max_y;line++)  // per scanline
770777   {
771778      // adjust for scroll registers
772      loc = (((line - x68k_sys.crtc.vbegin) + yscr) & 0x3ff) * 64;
779      loc = (((line - state->crtc.vbegin) + yscr) & 0x3ff) * 64;
773780      loc += (xscr / 16) & 0x7f;
774781      loc &= 0xffff;
775782      bit = 15 - (xscr & 0x0f);
776783      for(pixel=rect.min_x;pixel<=rect.max_x;pixel++)  // per pixel
777784      {
778         colour = (((x68k_tvram[loc] >> bit) & 0x01) ? 1 : 0)
779            + (((x68k_tvram[loc+0x10000] >> bit) & 0x01) ? 2 : 0)
780            + (((x68k_tvram[loc+0x20000] >> bit) & 0x01) ? 4 : 0)
781            + (((x68k_tvram[loc+0x30000] >> bit) & 0x01) ? 8 : 0);
782         if(x68k_sys.video.text_pal[colour] != 0x0000)  // any colour but black
785         colour = (((state->tvram[loc] >> bit) & 0x01) ? 1 : 0)
786            + (((state->tvram[loc+0x10000] >> bit) & 0x01) ? 2 : 0)
787            + (((state->tvram[loc+0x20000] >> bit) & 0x01) ? 4 : 0)
788            + (((state->tvram[loc+0x30000] >> bit) & 0x01) ? 8 : 0);
789         if(state->video.text_pal[colour] != 0x0000)  // any colour but black
783790         {
784791            // Colour 0 is displayable if the text layer is at the priority level 2
785            if(colour == 0 && (x68k_sys.video.reg[1] & 0x0c00) == 0x0800)
786               *BITMAP_ADDR16(bitmap,line,pixel) = 512 + (x68k_sys.video.text_pal[colour] >> 1);
792            if(colour == 0 && (state->video.reg[1] & 0x0c00) == 0x0800)
793               *BITMAP_ADDR16(bitmap,line,pixel) = 512 + (state->video.text_pal[colour] >> 1);
787794            else
788795               if(colour != 0)
789                  *BITMAP_ADDR16(bitmap,line,pixel) = 512 + (x68k_sys.video.text_pal[colour] >> 1);
796                  *BITMAP_ADDR16(bitmap,line,pixel) = 512 + (state->video.text_pal[colour] >> 1);
790797         }
791798         bit--;
792799         if(bit < 0)
r9669r9670
799806   }
800807}
801808
802static void x68k_draw_gfx_scanline(bitmap_t* bitmap, rectangle cliprect, UINT8 priority)
809static void x68k_draw_gfx_scanline(running_machine *machine, bitmap_t* bitmap, rectangle cliprect, UINT8 priority)
803810{
811   x68k_state *state = machine->driver_data<x68k_state>();
804812   int pixel;
805813   int page;
806814   UINT32 loc;  // location in GVRAM
r9669r9670
812820
813821   for(scanline=cliprect.min_y;scanline<=cliprect.max_y;scanline++)  // per scanline
814822   {
815      if(x68k_sys.crtc.reg[20] & 0x0400)  // 1024x1024 "real" screen size - use 1024x1024 16-colour gfx layer
823      if(state->crtc.reg[20] & 0x0400)  // 1024x1024 "real" screen size - use 1024x1024 16-colour gfx layer
816824      {
817825         // adjust for scroll registers
818         if(x68k_sys.video.reg[2] & 0x0010 && priority == x68k_sys.video.gfxlayer_pri[0])
826         if(state->video.reg[2] & 0x0010 && priority == state->video.gfxlayer_pri[0])
819827         {
820            xscr = (x68k_sys.crtc.reg[12] & 0x3ff);
821            yscr = (x68k_sys.crtc.reg[13] & 0x3ff);
822            lineoffset = (((scanline - x68k_sys.crtc.vbegin) + yscr) & 0x3ff) * 1024;
828            xscr = (state->crtc.reg[12] & 0x3ff);
829            yscr = (state->crtc.reg[13] & 0x3ff);
830            lineoffset = (((scanline - state->crtc.vbegin) + yscr) & 0x3ff) * 1024;
823831            loc = xscr & 0x3ff;
824            for(pixel=x68k_sys.crtc.hbegin;pixel<=x68k_sys.crtc.hend;pixel++)
832            for(pixel=state->crtc.hbegin;pixel<=state->crtc.hend;pixel++)
825833            {
826834               switch(lineoffset & 0xc0000)
827835               {
828836               case 0x00000:
829                  colour = x68k_gvram[lineoffset + (loc & 0x3ff)] & 0x000f;
837                  colour = state->gvram[lineoffset + (loc & 0x3ff)] & 0x000f;
830838                  break;
831839               case 0x40000:
832                  colour = (x68k_gvram[(lineoffset - 0x40000) + (loc & 0x3ff)] & 0x00f0) >> 4;
840                  colour = (state->gvram[(lineoffset - 0x40000) + (loc & 0x3ff)] & 0x00f0) >> 4;
833841                  break;
834842               case 0x80000:
835                  colour = (x68k_gvram[(lineoffset - 0x80000) + (loc & 0x3ff)] & 0x0f00) >> 8;
843                  colour = (state->gvram[(lineoffset - 0x80000) + (loc & 0x3ff)] & 0x0f00) >> 8;
836844                  break;
837845               case 0xc0000:
838                  colour = (x68k_gvram[(lineoffset - 0xc0000) + (loc & 0x3ff)] & 0xf000) >> 12;
846                  colour = (state->gvram[(lineoffset - 0xc0000) + (loc & 0x3ff)] & 0xf000) >> 12;
839847                  break;
840848               }
841849               if(colour != 0)
842                  *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (x68k_sys.video.gfx_pal[colour] >> 1);
850                  *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (state->video.gfx_pal[colour] >> 1);
843851               loc++;
844852               loc &= 0x3ff;
845853            }
r9669r9670
847855      }
848856      else  // else 512x512 "real" screen size
849857      {
850         if(x68k_sys.video.reg[2] & (1 << priority))
858         if(state->video.reg[2] & (1 << priority))
851859         {
852            page = x68k_sys.video.gfxlayer_pri[priority];
860            page = state->video.gfxlayer_pri[priority];
853861            // adjust for scroll registers
854            switch(x68k_sys.video.reg[0] & 0x03)
862            switch(state->video.reg[0] & 0x03)
855863            {
856864            case 0x00: // 16 colours
857               xscr = ((x68k_sys.crtc.reg[12+(page*2)])) & 0x1ff;
858               yscr = ((x68k_sys.crtc.reg[13+(page*2)])) & 0x1ff;
859               lineoffset = (((scanline - x68k_sys.crtc.vbegin) + yscr) & 0x1ff) * 512;
865               xscr = ((state->crtc.reg[12+(page*2)])) & 0x1ff;
866               yscr = ((state->crtc.reg[13+(page*2)])) & 0x1ff;
867               lineoffset = (((scanline - state->crtc.vbegin) + yscr) & 0x1ff) * 512;
860868               loc = xscr & 0x1ff;
861869               shift = 4;
862               for(pixel=x68k_sys.crtc.hbegin;pixel<=x68k_sys.crtc.hend;pixel++)
870               for(pixel=state->crtc.hbegin;pixel<=state->crtc.hend;pixel++)
863871               {
864                  colour = ((x68k_gvram[lineoffset + loc] >> page*shift) & 0x000f);
872                  colour = ((state->gvram[lineoffset + loc] >> page*shift) & 0x000f);
865873                  if(colour != 0)
866                     *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (x68k_sys.video.gfx_pal[colour & 0x0f] >> 1);
874                     *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (state->video.gfx_pal[colour & 0x0f] >> 1);
867875                  loc++;
868876                  loc &= 0x1ff;
869877               }
r9669r9670
871879            case 0x01: // 256 colours
872880               if(page == 0 || page == 2)
873881               {
874                  xscr = ((x68k_sys.crtc.reg[12+(page*2)])) & 0x1ff;
875                  yscr = ((x68k_sys.crtc.reg[13+(page*2)])) & 0x1ff;
876                  lineoffset = (((scanline - x68k_sys.crtc.vbegin) + yscr) & 0x1ff) * 512;
882                  xscr = ((state->crtc.reg[12+(page*2)])) & 0x1ff;
883                  yscr = ((state->crtc.reg[13+(page*2)])) & 0x1ff;
884                  lineoffset = (((scanline - state->crtc.vbegin) + yscr) & 0x1ff) * 512;
877885                  loc = xscr & 0x1ff;
878886                  shift = 4;
879                  for(pixel=x68k_sys.crtc.hbegin;pixel<=x68k_sys.crtc.hend;pixel++)
887                  for(pixel=state->crtc.hbegin;pixel<=state->crtc.hend;pixel++)
880888                  {
881                     colour = ((x68k_gvram[lineoffset + loc] >> page*shift) & 0x00ff);
889                     colour = ((state->gvram[lineoffset + loc] >> page*shift) & 0x00ff);
882890                     if(colour != 0)
883                        *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (x68k_sys.video.gfx_pal[colour & 0xff] >> 1);
891                        *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (state->video.gfx_pal[colour & 0xff] >> 1);
884892                     loc++;
885893                     loc &= 0x1ff;
886894                  }
887895               }
888896               break;
889897            case 0x03: // 65536 colours
890               xscr = ((x68k_sys.crtc.reg[12])) & 0x1ff;
891               yscr = ((x68k_sys.crtc.reg[13])) & 0x1ff;
892               lineoffset = (((scanline - x68k_sys.crtc.vbegin) + yscr) & 0x1ff) * 512;
898               xscr = ((state->crtc.reg[12])) & 0x1ff;
899               yscr = ((state->crtc.reg[13])) & 0x1ff;
900               lineoffset = (((scanline - state->crtc.vbegin) + yscr) & 0x1ff) * 512;
893901               loc = xscr & 0x1ff;
894               for(pixel=x68k_sys.crtc.hbegin;pixel<=x68k_sys.crtc.hend;pixel++)
902               for(pixel=state->crtc.hbegin;pixel<=state->crtc.hend;pixel++)
895903               {
896                  colour = x68k_gvram[lineoffset + loc];
904                  colour = state->gvram[lineoffset + loc];
897905                  if(colour != 0)
898906                     *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (colour >> 1);
899907                  loc++;
r9669r9670
906914   }
907915}
908916
909static void x68k_draw_gfx(bitmap_t* bitmap,rectangle cliprect)
917static void x68k_draw_gfx(running_machine *machine, bitmap_t* bitmap,rectangle cliprect)
910918{
919   x68k_state *state = machine->driver_data<x68k_state>();
911920   int priority;
912921   //rectangle rect;
913922   //int xscr,yscr;
914923   //int gpage;
915924
916   if(x68k_sys.crtc.reg[20] & 0x0800)  // if graphic layers are set to buffer, then they aren't visible
925   if(state->crtc.reg[20] & 0x0800)  // if graphic layers are set to buffer, then they aren't visible
917926      return;
918927
919928   for(priority=3;priority>=0;priority--)
920929   {
921      x68k_draw_gfx_scanline(bitmap,cliprect,priority);
930      x68k_draw_gfx_scanline(machine, bitmap,cliprect,priority);
922931   }
923932}
924933
925934// Sprite controller "Cynthia" at 0xeb0000
926935static void x68k_draw_sprites(running_machine *machine, bitmap_t* bitmap, int priority, rectangle cliprect)
927936{
937   x68k_state *state = machine->driver_data<x68k_state>();
928938   /*
929939       0xeb0000 - 0xeb07ff - Sprite registers (up to 128)
930940           + 00 : b9-0,  Sprite X position
r9669r9670
958968
959969   for(ptr=508;ptr>=0;ptr-=4)  // stepping through sprites
960970   {
961      pri = x68k_spritereg[ptr+3] & 0x03;
971      pri = state->spritereg[ptr+3] & 0x03;
962972#ifdef MAME_DEBUG
963973      if(!(input_code_pressed(machine,KEYCODE_I)))
964974#endif
965975      if(pri == priority)
966976      {  // if at the right priority level, draw the sprite
967977         rectangle rect;
968         int code = x68k_spritereg[ptr+2] & 0x00ff;
969         int colour = (x68k_spritereg[ptr+2] & 0x0f00) >> 8;
970         int xflip = x68k_spritereg[ptr+2] & 0x4000;
971         int yflip = x68k_spritereg[ptr+2] & 0x8000;
972         int sx = (x68k_spritereg[ptr+0] & 0x3ff) - 16;
973         int sy = (x68k_spritereg[ptr+1] & 0x3ff) - 16;
978         int code = state->spritereg[ptr+2] & 0x00ff;
979         int colour = (state->spritereg[ptr+2] & 0x0f00) >> 8;
980         int xflip = state->spritereg[ptr+2] & 0x4000;
981         int yflip = state->spritereg[ptr+2] & 0x8000;
982         int sx = (state->spritereg[ptr+0] & 0x3ff) - 16;
983         int sy = (state->spritereg[ptr+1] & 0x3ff) - 16;
974984
975         rect.min_x=x68k_sys.crtc.hshift;
976         rect.min_y=x68k_sys.crtc.vshift;
977         rect.max_x=rect.min_x + x68k_sys.crtc.visible_width-1;
978         rect.max_y=rect.min_y + x68k_sys.crtc.visible_height-1;
985         rect.min_x=state->crtc.hshift;
986         rect.min_y=state->crtc.vshift;
987         rect.max_x=rect.min_x + state->crtc.visible_width-1;
988         rect.max_y=rect.min_y + state->crtc.visible_height-1;
979989
980         sx += sprite_shift;
990         sx += state->sprite_shift;
981991
982         if(x68k_sys.crtc.interlace != 0)
983            drawgfxzoom_transpen(bitmap,&cliprect,machine->gfx[1],code,colour+0x10,xflip,yflip,x68k_sys.crtc.hbegin+sx,x68k_sys.crtc.vbegin+(sy*2),0x10000,0x20000,0x00);
992         if(state->crtc.interlace != 0)
993            drawgfxzoom_transpen(bitmap,&cliprect,machine->gfx[1],code,colour+0x10,xflip,yflip,state->crtc.hbegin+sx,state->crtc.vbegin+(sy*2),0x10000,0x20000,0x00);
984994         else
985            drawgfx_transpen(bitmap,&cliprect,machine->gfx[1],code,colour+0x10,xflip,yflip,x68k_sys.crtc.hbegin+sx,x68k_sys.crtc.vbegin+sy,0x00);
995            drawgfx_transpen(bitmap,&cliprect,machine->gfx[1],code,colour+0x10,xflip,yflip,state->crtc.hbegin+sx,state->crtc.vbegin+sy,0x00);
986996      }
987997   }
988998}
r9669r9670
10331043
10341044static TILE_GET_INFO(x68k_get_bg0_tile)
10351045{
1036   int code = x68k_spriteram[0x3000+tile_index] & 0x00ff;
1037   int colour = (x68k_spriteram[0x3000+tile_index] & 0x0f00) >> 8;
1038   int flags = (x68k_spriteram[0x3000+tile_index] & 0xc000) >> 14;
1046   x68k_state *state = machine->driver_data<x68k_state>();
1047   int code = state->spriteram[0x3000+tile_index] & 0x00ff;
1048   int colour = (state->spriteram[0x3000+tile_index] & 0x0f00) >> 8;
1049   int flags = (state->spriteram[0x3000+tile_index] & 0xc000) >> 14;
10391050   SET_TILE_INFO(0,code,colour+16,flags);
10401051}
10411052
10421053static TILE_GET_INFO(x68k_get_bg1_tile)
10431054{
1044   int code = x68k_spriteram[0x2000+tile_index] & 0x00ff;
1045   int colour = (x68k_spriteram[0x2000+tile_index] & 0x0f00) >> 8;
1046   int flags = (x68k_spriteram[0x2000+tile_index] & 0xc000) >> 14;
1055   x68k_state *state = machine->driver_data<x68k_state>();
1056   int code = state->spriteram[0x2000+tile_index] & 0x00ff;
1057   int colour = (state->spriteram[0x2000+tile_index] & 0x0f00) >> 8;
1058   int flags = (state->spriteram[0x2000+tile_index] & 0xc000) >> 14;
10471059   SET_TILE_INFO(0,code,colour+16,flags);
10481060}
10491061
10501062static TILE_GET_INFO(x68k_get_bg0_tile_16)
10511063{
1052   int code = x68k_spriteram[0x3000+tile_index] & 0x00ff;
1053   int colour = (x68k_spriteram[0x3000+tile_index] & 0x0f00) >> 8;
1054   int flags = (x68k_spriteram[0x3000+tile_index] & 0xc000) >> 14;
1064   x68k_state *state = machine->driver_data<x68k_state>();
1065   int code = state->spriteram[0x3000+tile_index] & 0x00ff;
1066   int colour = (state->spriteram[0x3000+tile_index] & 0x0f00) >> 8;
1067   int flags = (state->spriteram[0x3000+tile_index] & 0xc000) >> 14;
10551068   SET_TILE_INFO(1,code,colour+16,flags);
10561069}
10571070
10581071static TILE_GET_INFO(x68k_get_bg1_tile_16)
10591072{
1060   int code = x68k_spriteram[0x2000+tile_index] & 0x00ff;
1061   int colour = (x68k_spriteram[0x2000+tile_index] & 0x0f00) >> 8;
1062   int flags = (x68k_spriteram[0x2000+tile_index] & 0xc000) >> 14;
1073   x68k_state *state = machine->driver_data<x68k_state>();
1074   int code = state->spriteram[0x2000+tile_index] & 0x00ff;
1075   int colour = (state->spriteram[0x2000+tile_index] & 0x0f00) >> 8;
1076   int flags = (state->spriteram[0x2000+tile_index] & 0xc000) >> 14;
10631077   SET_TILE_INFO(1,code,colour+16,flags);
10641078}
10651079
10661080VIDEO_START( x68000 )
10671081{
1082   x68k_state *state = machine->driver_data<x68k_state>();
10681083   int gfx_index;
10691084
10701085   for (gfx_index = 0; gfx_index < MAX_GFX_ELEMENTS; gfx_index++)
r9669r9670
10801095   machine->gfx[gfx_index]->total_colors = 32;
10811096
10821097   /* Tilemaps */
1083   x68k_bg0_8 = tilemap_create(machine, x68k_get_bg0_tile,tilemap_scan_rows,8,8,64,64);
1084   x68k_bg1_8 = tilemap_create(machine, x68k_get_bg1_tile,tilemap_scan_rows,8,8,64,64);
1085   x68k_bg0_16 = tilemap_create(machine, x68k_get_bg0_tile_16,tilemap_scan_rows,16,16,64,64);
1086   x68k_bg1_16 = tilemap_create(machine, x68k_get_bg1_tile_16,tilemap_scan_rows,16,16,64,64);
1098   state->bg0_8 = tilemap_create(machine, x68k_get_bg0_tile,tilemap_scan_rows,8,8,64,64);
1099   state->bg1_8 = tilemap_create(machine, x68k_get_bg1_tile,tilemap_scan_rows,8,8,64,64);
1100   state->bg0_16 = tilemap_create(machine, x68k_get_bg0_tile_16,tilemap_scan_rows,16,16,64,64);
1101   state->bg1_16 = tilemap_create(machine, x68k_get_bg1_tile_16,tilemap_scan_rows,16,16,64,64);
10871102
1088   tilemap_set_transparent_pen(x68k_bg0_8,0);
1089   tilemap_set_transparent_pen(x68k_bg1_8,0);
1090   tilemap_set_transparent_pen(x68k_bg0_16,0);
1091   tilemap_set_transparent_pen(x68k_bg1_16,0);
1103   tilemap_set_transparent_pen(state->bg0_8,0);
1104   tilemap_set_transparent_pen(state->bg1_8,0);
1105   tilemap_set_transparent_pen(state->bg0_16,0);
1106   tilemap_set_transparent_pen(state->bg1_16,0);
10921107
1093//  timer_adjust_periodic(x68k_scanline_timer, attotime_zero, 0, ATTOTIME_IN_HZ(55.45)/568);
1108//  timer_adjust_periodic(state->scanline_timer, attotime_zero, 0, ATTOTIME_IN_HZ(55.45)/568);
10941109}
10951110
10961111VIDEO_UPDATE( x68000 )
10971112{
1113   x68k_state *state = screen->machine->driver_data<x68k_state>();
10981114   rectangle rect = {0,0,0,0};
10991115   int priority;
11001116   int xscr,yscr;
r9669r9670
11031119   tilemap_t* x68k_bg1;
11041120   //UINT8 *rom;
11051121
1106   if((x68k_spritereg[0x408] & 0x03) == 0x00)  // Sprite/BG H-Res 0=8x8, 1=16x16, 2 or 3 = undefined.
1122   if((state->spritereg[0x408] & 0x03) == 0x00)  // Sprite/BG H-Res 0=8x8, 1=16x16, 2 or 3 = undefined.
11071123   {
1108      x68k_bg0 = x68k_bg0_8;
1109      x68k_bg1 = x68k_bg1_8;
1124      x68k_bg0 = state->bg0_8;
1125      x68k_bg1 = state->bg1_8;
11101126   }
11111127   else
11121128   {
1113      x68k_bg0 = x68k_bg0_16;
1114      x68k_bg1 = x68k_bg1_16;
1129      x68k_bg0 = state->bg0_16;
1130      x68k_bg1 = state->bg1_16;
11151131   }
1116//  rect.max_x=x68k_sys.crtc.width;
1117//  rect.max_y=x68k_sys.crtc.height;
1132//  rect.max_x=state->crtc.width;
1133//  rect.max_y=state->crtc.height;
11181134   bitmap_fill(bitmap,cliprect,0);
11191135
1120   if(x68k_sys.sysport.contrast == 0)  // if monitor contrast is 0, then don't bother displaying anything
1136   if(state->sysport.contrast == 0)  // if monitor contrast is 0, then don't bother displaying anything
11211137      return 0;
11221138
1123   rect.min_x=x68k_sys.crtc.hbegin;
1124   rect.min_y=x68k_sys.crtc.vbegin;
1125//  rect.max_x=rect.min_x + x68k_sys.crtc.visible_width-1;
1126//  rect.max_y=rect.min_y + x68k_sys.crtc.visible_height-1;
1127   rect.max_x=x68k_sys.crtc.hend;
1128   rect.max_y=x68k_sys.crtc.vend;
1139   rect.min_x=state->crtc.hbegin;
1140   rect.min_y=state->crtc.vbegin;
1141//  rect.max_x=rect.min_x + state->crtc.visible_width-1;
1142//  rect.max_y=rect.min_y + state->crtc.visible_height-1;
1143   rect.max_x=state->crtc.hend;
1144   rect.max_y=state->crtc.vend;
11291145
11301146   if(rect.min_y < cliprect->min_y)
11311147      rect.min_y = cliprect->min_y;
r9669r9670
11361152   //rom = memory_region(screen->machine, "user1");
11371153   for(x=0;x<256;x++)
11381154   {
1139      if(x68k_sys.video.tile16_dirty[x] != 0)
1155      if(state->video.tile16_dirty[x] != 0)
11401156      {
11411157         gfx_element_mark_dirty(screen->machine->gfx[1], x);
1142         x68k_sys.video.tile16_dirty[x] = 0;
1158         state->video.tile16_dirty[x] = 0;
11431159      }
1144      if(x68k_sys.video.tile8_dirty[x] != 0)
1160      if(state->video.tile8_dirty[x] != 0)
11451161      {
11461162         gfx_element_mark_dirty(screen->machine->gfx[0], x);
1147         x68k_sys.video.tile8_dirty[x] = 0;
1163         state->video.tile8_dirty[x] = 0;
11481164      }
11491165   }
11501166
11511167   for(priority=3;priority>=0;priority--)
11521168   {
11531169      // Graphics screen(s)
1154      if(priority == x68k_sys.video.gfx_pri)
1155         x68k_draw_gfx(bitmap,rect);
1170      if(priority == state->video.gfx_pri)
1171         x68k_draw_gfx(screen->machine,bitmap,rect);
11561172
11571173      // Sprite / BG Tiles
1158      if(priority == x68k_sys.video.sprite_pri /*&& (x68k_spritereg[0x404] & 0x0200)*/ && (x68k_sys.video.reg[2] & 0x0040))
1174      if(priority == state->video.sprite_pri /*&& (state->spritereg[0x404] & 0x0200)*/ && (state->video.reg[2] & 0x0040))
11591175      {
11601176         x68k_draw_sprites(screen->machine, bitmap,1,rect);
1161         if((x68k_spritereg[0x404] & 0x0008))
1177         if((state->spritereg[0x404] & 0x0008))
11621178         {
1163            if((x68k_spritereg[0x404] & 0x0030) == 0x10)  // BG1 TXSEL
1179            if((state->spritereg[0x404] & 0x0030) == 0x10)  // BG1 TXSEL
11641180            {
1165               tilemap_set_scrollx(x68k_bg0,0,(x68k_spritereg[0x402] - x68k_sys.crtc.hbegin) & 0x3ff);
1166               tilemap_set_scrolly(x68k_bg0,0,(x68k_spritereg[0x403] - x68k_sys.crtc.vbegin) & 0x3ff);
1181               tilemap_set_scrollx(x68k_bg0,0,(state->spritereg[0x402] - state->crtc.hbegin) & 0x3ff);
1182               tilemap_set_scrolly(x68k_bg0,0,(state->spritereg[0x403] - state->crtc.vbegin) & 0x3ff);
11671183               tilemap_draw(bitmap,&rect,x68k_bg0,0,0);
11681184            }
11691185            else
11701186            {
1171               tilemap_set_scrollx(x68k_bg1,0,(x68k_spritereg[0x402] - x68k_sys.crtc.hbegin) & 0x3ff);
1172               tilemap_set_scrolly(x68k_bg1,0,(x68k_spritereg[0x403] - x68k_sys.crtc.vbegin) & 0x3ff);
1187               tilemap_set_scrollx(x68k_bg1,0,(state->spritereg[0x402] - state->crtc.hbegin) & 0x3ff);
1188               tilemap_set_scrolly(x68k_bg1,0,(state->spritereg[0x403] - state->crtc.vbegin) & 0x3ff);
11731189               tilemap_draw(bitmap,&rect,x68k_bg1,0,0);
11741190            }
11751191         }
11761192         x68k_draw_sprites(screen->machine,bitmap,2,rect);
1177         if((x68k_spritereg[0x404] & 0x0001))
1193         if((state->spritereg[0x404] & 0x0001))
11781194         {
1179            if((x68k_spritereg[0x404] & 0x0006) == 0x02)  // BG0 TXSEL
1195            if((state->spritereg[0x404] & 0x0006) == 0x02)  // BG0 TXSEL
11801196            {
1181               tilemap_set_scrollx(x68k_bg0,0,(x68k_spritereg[0x400] - x68k_sys.crtc.hbegin) & 0x3ff);
1182               tilemap_set_scrolly(x68k_bg0,0,(x68k_spritereg[0x401] - x68k_sys.crtc.vbegin) & 0x3ff);
1197               tilemap_set_scrollx(x68k_bg0,0,(state->spritereg[0x400] - state->crtc.hbegin) & 0x3ff);
1198               tilemap_set_scrolly(x68k_bg0,0,(state->spritereg[0x401] - state->crtc.vbegin) & 0x3ff);
11831199               tilemap_draw(bitmap,&rect,x68k_bg0,0,0);
11841200            }
11851201            else
11861202            {
1187               tilemap_set_scrollx(x68k_bg1,0,(x68k_spritereg[0x400] - x68k_sys.crtc.hbegin) & 0x3ff);
1188               tilemap_set_scrolly(x68k_bg1,0,(x68k_spritereg[0x401] - x68k_sys.crtc.vbegin) & 0x3ff);
1203               tilemap_set_scrollx(x68k_bg1,0,(state->spritereg[0x400] - state->crtc.hbegin) & 0x3ff);
1204               tilemap_set_scrolly(x68k_bg1,0,(state->spritereg[0x401] - state->crtc.vbegin) & 0x3ff);
11891205               tilemap_draw(bitmap,&rect,x68k_bg1,0,0);
11901206            }
11911207         }
r9669r9670
11931209      }
11941210
11951211      // Text screen
1196      if(x68k_sys.video.reg[2] & 0x0020 && priority == x68k_sys.video.text_pri)
1212      if(state->video.reg[2] & 0x0020 && priority == state->video.text_pri)
11971213      {
1198         xscr = (x68k_sys.crtc.reg[10] & 0x3ff);
1199         yscr = (x68k_sys.crtc.reg[11] & 0x3ff);
1200         if(!(x68k_sys.crtc.reg[20] & 0x1000))  // if text layer is set to buffer, then it's not visible
1214         xscr = (state->crtc.reg[10] & 0x3ff);
1215         yscr = (state->crtc.reg[11] & 0x3ff);
1216         if(!(state->crtc.reg[20] & 0x1000))  // if text layer is set to buffer, then it's not visible
12011217            x68k_draw_text(screen->machine,bitmap,xscr,yscr,rect);
12021218      }
12031219   }
r9669r9670
12051221#ifdef MAME_DEBUG
12061222   if(input_code_pressed(screen->machine,KEYCODE_I))
12071223   {
1208      x68k_sys.mfp.isra = 0;
1209      x68k_sys.mfp.isrb = 0;
1224      state->mfp.isra = 0;
1225      state->mfp.isrb = 0;
12101226//      mfp_trigger_irq(MFP_IRQ_GPIP6);
12111227//      cputag_set_input_line_and_vector(machine, "maincpu",6,ASSERT_LINE,0x43);
12121228   }
12131229   if(input_code_pressed(screen->machine,KEYCODE_9))
12141230   {
1215      sprite_shift--;
1216      popmessage("Sprite shift = %i",sprite_shift);
1231      state->sprite_shift--;
1232      popmessage("Sprite shift = %i",state->sprite_shift);
12171233   }
12181234   if(input_code_pressed(screen->machine,KEYCODE_0))
12191235   {
1220      sprite_shift++;
1221      popmessage("Sprite shift = %i",sprite_shift);
1236      state->sprite_shift++;
1237      popmessage("Sprite shift = %i",state->sprite_shift);
12221238   }
12231239
12241240#endif
12251241
12261242#ifdef MAME_DEBUG
1227//  popmessage("Layer priorities [%04x] - Txt: %i  Spr: %i  Gfx: %i  Layer Pri0-3: %i %i %i %i",x68k_sys.video.reg[1],x68k_sys.video.text_pri,x68k_sys.video.sprite_pri,
1228//      x68k_sys.video.gfx_pri,x68k_sys.video.gfxlayer_pri[0],x68k_sys.video.gfxlayer_pri[1],x68k_sys.video.gfxlayer_pri[2],x68k_sys.video.gfxlayer_pri[3]);
1229//  popmessage("CRTC regs - %i %i %i %i  - %i %i %i %i - %i - %i",x68k_sys.crtc.reg[0],x68k_sys.crtc.reg[1],x68k_sys.crtc.reg[2],x68k_sys.crtc.reg[3],
1230//      x68k_sys.crtc.reg[4],x68k_sys.crtc.reg[5],x68k_sys.crtc.reg[6],x68k_sys.crtc.reg[7],x68k_sys.crtc.reg[8],x68k_sys.crtc.reg[9]);
1231//  popmessage("Visible resolution = %ix%i (%s) Screen size = %ix%i",x68k_sys.crtc.visible_width,x68k_sys.crtc.visible_height,x68k_sys.crtc.interlace ? "Interlaced" : "Non-interlaced",x68k_sys.crtc.video_width,x68k_sys.crtc.video_height);
1232//  popmessage("VBlank : x68k_scanline = %i",x68k_scanline);
1233//  popmessage("CRTC/BG compare H-TOTAL %i/%i H-DISP %i/%i V-DISP %i/%i BG Res %02x",x68k_sys.crtc.reg[0],x68k_spritereg[0x405],x68k_sys.crtc.reg[2],x68k_spritereg[0x406],
1234//      x68k_sys.crtc.reg[6],x68k_spritereg[0x407],x68k_spritereg[0x408]);
1235//  popmessage("IER %02x %02x  IPR %02x %02x  ISR %02x %02x  IMR %02x %02x", x68k_sys.mfp.iera,x68k_sys.mfp.ierb,x68k_sys.mfp.ipra,x68k_sys.mfp.iprb,
1236//      x68k_sys.mfp.isra,x68k_sys.mfp.isrb,x68k_sys.mfp.imra,x68k_sys.mfp.imrb);
1237//  popmessage("BG Scroll - BG0 X %i Y %i  BG1 X %i Y %i",x68k_spriteram[0x400],x68k_spriteram[0x401],x68k_spriteram[0x402],x68k_spriteram[0x403]);
1238//  popmessage("Keyboard buffer position = %i",x68k_sys.keyboard.headpos);
1239//  popmessage("IERA = 0x%02x, IERB = 0x%02x",x68k_sys.mfp.iera,x68k_sys.mfp.ierb);
1240//  popmessage("IPRA = 0x%02x, IPRB = 0x%02x",x68k_sys.mfp.ipra,x68k_sys.mfp.iprb);
1243//  popmessage("Layer priorities [%04x] - Txt: %i  Spr: %i  Gfx: %i  Layer Pri0-3: %i %i %i %i",state->video.reg[1],state->video.text_pri,state->video.sprite_pri,
1244//      state->video.gfx_pri,state->video.gfxlayer_pri[0],state->video.gfxlayer_pri[1],state->video.gfxlayer_pri[2],state->video.gfxlayer_pri[3]);
1245//  popmessage("CRTC regs - %i %i %i %i  - %i %i %i %i - %i - %i",state->crtc.reg[0],state->crtc.reg[1],state->crtc.reg[2],state->crtc.reg[3],
1246//      state->crtc.reg[4],state->crtc.reg[5],state->crtc.reg[6],state->crtc.reg[7],state->crtc.reg[8],state->crtc.reg[9]);
1247//  popmessage("Visible resolution = %ix%i (%s) Screen size = %ix%i",state->crtc.visible_width,state->crtc.visible_height,state->crtc.interlace ? "Interlaced" : "Non-interlaced",state->crtc.video_width,state->crtc.video_height);
1248//  popmessage("VBlank : scanline = %i",state->scanline);
1249//  popmessage("CRTC/BG compare H-TOTAL %i/%i H-DISP %i/%i V-DISP %i/%i BG Res %02x",state->crtc.reg[0],state->spritereg[0x405],state->crtc.reg[2],state->spritereg[0x406],
1250//      state->crtc.reg[6],state->spritereg[0x407],state->spritereg[0x408]);
1251//  popmessage("IER %02x %02x  IPR %02x %02x  ISR %02x %02x  IMR %02x %02x", state->mfp.iera,state->mfp.ierb,state->mfp.ipra,state->mfp.iprb,
1252//      state->mfp.isra,state->mfp.isrb,state->mfp.imra,state->mfp.imrb);
1253//  popmessage("BG Scroll - BG0 X %i Y %i  BG1 X %i Y %i",state->spriteram[0x400],state->spriteram[0x401],state->spriteram[0x402],state->spriteram[0x403]);
1254//  popmessage("Keyboard buffer position = %i",state->keyboard.headpos);
1255//  popmessage("IERA = 0x%02x, IERB = 0x%02x",state->mfp.iera,state->mfp.ierb);
1256//  popmessage("IPRA = 0x%02x, IPRB = 0x%02x",state->mfp.ipra,state->mfp.iprb);
12411257//  popmessage("uPD72065 status = %02x",upd765_status_r(machine, 0));
1242//  popmessage("Layer enable - 0x%02x",x68k_sys.video.reg[2] & 0xff);
1258//  popmessage("Layer enable - 0x%02x",state->video.reg[2] & 0xff);
12431259//  popmessage("Graphic layer scroll - %i, %i - %i, %i - %i, %i - %i, %i",
1244//      x68k_sys.crtc.reg[12],x68k_sys.crtc.reg[13],x68k_sys.crtc.reg[14],x68k_sys.crtc.reg[15],x68k_sys.crtc.reg[16],x68k_sys.crtc.reg[17],x68k_sys.crtc.reg[18],x68k_sys.crtc.reg[19]);
1245//  popmessage("IOC IRQ status - %02x",x68k_sys.ioc.irqstatus);
1260//      state->crtc.reg[12],state->crtc.reg[13],state->crtc.reg[14],state->crtc.reg[15],state->crtc.reg[16],state->crtc.reg[17],state->crtc.reg[18],state->crtc.reg[19]);
1261//  popmessage("IOC IRQ status - %02x",state->ioc.irqstatus);
12461262//  popmessage("RAM: mouse data - %02x %02x %02x %02x",messram_get_ptr(machine->device("messram"))[0x931],messram_get_ptr(machine->device("messram"))[0x930],messram_get_ptr(machine->device("messram"))[0x933],messram_get_ptr(machine->device("messram"))[0x932]);
12471263#endif
12481264   return 0;
src/mess/video/super80.c
r9669r9670
99#include "includes/super80.h"
1010
1111
12static UINT16 vidpg;   /* Home position of video page being displayed */
1312
14static UINT8 current_palette;   /* for super80m and super80v */
15static UINT8 current_charset;   /* for super80m */
1613
17static const UINT8 *FNT;
18static UINT8 s_options;
1914
2015
2116/**************************** PALETTES for super80m and super80v ******************************************/
r9669r9670
8075
8176VIDEO_EOF( super80m )
8277{
78   super80_state *state = machine->driver_data<super80_state>();
8379   /* if we chose another palette or colour mode, enable it */
8480   UINT8 chosen_palette = (input_port_read(machine, "CONFIG") & 0x60)>>5;            // read colour dipswitches
8581
86   if (chosen_palette != current_palette)                  // any changes?
82   if (chosen_palette != state->current_palette)                  // any changes?
8783   {
88      current_palette = chosen_palette;               // save new palette
89      if (!current_palette)
84      state->current_palette = chosen_palette;               // save new palette
85      if (!state->current_palette)
9086         palette_set_colors_rgb(machine, super80_comp_palette);      // composite colour
9187      else
9288         palette_set_colors_rgb(machine, super80_rgb_palette);      // rgb and b&w
r9669r9670
9591
9692VIDEO_UPDATE( super80 )
9793{
94   super80_state *state = screen->machine->driver_data<super80_state>();
9895   UINT8 y,ra,chr=32,gfx,screen_on=0;
99   UINT16 sy=0,ma=vidpg,x;
96   UINT16 sy=0,ma=state->vidpg,x;
10097   UINT8 *RAM = memory_region(screen->machine, "maincpu");
101   super80_state *state = screen->machine->driver_data<super80_state>();
10298
10399   output_set_value("cass_led",(state->super80_shared & 0x20) ? 1 : 0);
104100
r9669r9670
117113               chr = RAM[ma | x] & 0x3f;
118114
119115            /* get pattern of pixels for that character scanline */
120            gfx = FNT[(chr<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)];
116            gfx = state->FNT[(chr<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)];
121117
122118            /* Display a scanline of a character (8 pixels) */
123119            *p++ = ( gfx & 0x80 ) ? 1 : 0;
r9669r9670
137133
138134VIDEO_UPDATE( super80d )
139135{
136   super80_state *state = screen->machine->driver_data<super80_state>();
140137   UINT8 y,ra,chr=32,gfx,screen_on=0;
141   UINT16 sy=0,ma=vidpg,x;
138   UINT16 sy=0,ma=state->vidpg,x;
142139   UINT8 *RAM = memory_region(screen->machine, "maincpu");
143   super80_state *state = screen->machine->driver_data<super80_state>();
144140
145141   output_set_value("cass_led",(state->super80_shared & 0x20) ? 1 : 0);
146142
r9669r9670
159155               chr = RAM[ma | x];
160156
161157            /* get pattern of pixels for that character scanline */
162            gfx = FNT[((chr & 0x7f)<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)] ^ ((chr & 0x80) ? 0xff : 0);
158            gfx = state->FNT[((chr & 0x7f)<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)] ^ ((chr & 0x80) ? 0xff : 0);
163159
164160            /* Display a scanline of a character (8 pixels) */
165161            *p++ = ( gfx & 0x80 ) ? 1 : 0;
r9669r9670
179175
180176VIDEO_UPDATE( super80e )
181177{
178   super80_state *state = screen->machine->driver_data<super80_state>();
182179   UINT8 y,ra,chr=32,gfx,screen_on=0;
183   UINT16 sy=0,ma=vidpg,x;
180   UINT16 sy=0,ma=state->vidpg,x;
184181   UINT8 *RAM = memory_region(screen->machine, "maincpu");
185   super80_state *state = screen->machine->driver_data<super80_state>();
186182
187183   output_set_value("cass_led",(state->super80_shared & 0x20) ? 1 : 0);
188184
r9669r9670
201197               chr = RAM[ma | x];
202198
203199            /* get pattern of pixels for that character scanline */
204            gfx = FNT[(chr<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)];
200            gfx = state->FNT[(chr<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)];
205201
206202            /* Display a scanline of a character (8 pixels) */
207203            *p++ = ( gfx & 0x80 ) ? 1 : 0;
r9669r9670
221217
222218VIDEO_UPDATE( super80m )
223219{
220   super80_state *state = screen->machine->driver_data<super80_state>();
224221   UINT8 y,ra,chr=32,gfx,screen_on=0;
225   UINT16 sy=0,ma=vidpg,x;
222   UINT16 sy=0,ma=state->vidpg,x;
226223   UINT8 col, bg=0, fg=0, options=input_port_read(screen->machine, "CONFIG");
227224   UINT8 *RAM = memory_region(screen->machine, "maincpu");
228   super80_state *state = screen->machine->driver_data<super80_state>();
229225
230226   /* get selected character generator */
231   UINT8 cgen = current_charset ^ ((options & 0x10)>>4);   /* bit 0 of port F1 and cgen config switch */
227   UINT8 cgen = state->current_charset ^ ((options & 0x10)>>4);   /* bit 0 of port F1 and cgen config switch */
232228
233229   output_set_value("cass_led",(state->super80_shared & 0x20) ? 1 : 0);
234230
r9669r9670
263259
264260            /* get pattern of pixels for that character scanline */
265261            if (cgen)
266               gfx = FNT[(chr<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)];
262               gfx = state->FNT[(chr<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)];
267263            else
268               gfx = FNT[0x1000 | ((chr & 0x7f)<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)] ^ ((chr & 0x80) ? 0xff : 0);
264               gfx = state->FNT[0x1000 | ((chr & 0x7f)<<4) | ((ra & 8) >> 3) | ((ra & 7) << 1)] ^ ((chr & 0x80) ? 0xff : 0);
269265
270266            /* Display a scanline of a character (8 pixels) */
271267            *p++ = ( gfx & 0x80 ) ? fg : bg;
r9669r9670
285281
286282VIDEO_START( super80 )
287283{
288   vidpg = 0xfe00;
289   FNT = memory_region(machine, "gfx1");
284   super80_state *state = machine->driver_data<super80_state>();
285   state->vidpg = 0xfe00;
286   state->FNT = memory_region(machine, "gfx1");
290287}
291288
292289/**************************** I/O PORTS *****************************************************************/
293290
294291WRITE8_HANDLER( super80_f1_w )
295292{
296   vidpg = (data & 0xfe) << 8;
297   current_charset = data & 1;
293   super80_state *state = space->machine->driver_data<super80_state>();
294   state->vidpg = (data & 0xfe) << 8;
295   state->current_charset = data & 1;
298296}
299297
300298/*---------------------------------------------------------------
r9669r9670
303301
304302---------------------------------------------------------------*/
305303
306static UINT8 mc6845_cursor[16];            // cursor shape
307static UINT8 mc6845_reg[32];            /* registers */
308static UINT8 mc6845_ind;            /* register index */
309304static const UINT8 mc6845_mask[32]={0xff,0xff,0xff,0x0f,0x7f,0x1f,0x7f,0x7f,3,0x1f,0x7f,0x1f,0x3f,0xff,0x3f,0xff,0,0};
310static running_device *mc6845;
311static UINT8 framecnt=0;
312static UINT8 speed,flash;
313static UINT16 cursor;
314static UINT8 *videoram;
315static UINT8 *colorram;
316static UINT8 *pcgram;
317305
318306READ8_HANDLER( super80v_low_r )
319307{
320308   super80_state *state = space->machine->driver_data<super80_state>();
321309
322310   if (state->super80_shared & 4)
323      return videoram[offset];
311      return state->videoram[offset];
324312   else
325      return colorram[offset];
313      return state->colorram[offset];
326314}
327315
328316WRITE8_HANDLER( super80v_low_w )
r9669r9670
330318   super80_state *state = space->machine->driver_data<super80_state>();
331319   
332320   if (state->super80_shared & 4)
333      videoram[offset] = data;
321      state->videoram[offset] = data;
334322   else
335      colorram[offset] = data;
323      state->colorram[offset] = data;
336324}
337325
338326READ8_HANDLER( super80v_high_r )
r9669r9670
340328   super80_state *state = space->machine->driver_data<super80_state>();
341329
342330   if (~state->super80_shared & 4)
343      return colorram[0x800 | offset];
331      return state->colorram[0x800 | offset];
344332   else
345333   if (state->super80_shared & 0x10)
346      return pcgram[0x800 | offset];
334      return state->pcgram[0x800 | offset];
347335   else
348      return pcgram[offset];
336      return state->pcgram[offset];
349337}
350338
351339WRITE8_HANDLER( super80v_high_w )
r9669r9670
353341   super80_state *state = space->machine->driver_data<super80_state>();
354342
355343   if (~state->super80_shared & 4)
356      colorram[0x800 | offset] = data;
344      state->colorram[0x800 | offset] = data;
357345   else
358346   {
359      videoram[0x800 | offset] = data;
347      state->videoram[0x800 | offset] = data;
360348
361349      if (state->super80_shared & 0x10)
362         pcgram[0x800 | offset] = data;
350         state->pcgram[0x800 | offset] = data;
363351   }
364352}
365353
366354/* The 6845 can produce a variety of cursor shapes - all are emulated here - remove when mame fixed */
367static void mc6845_cursor_configure(void)
355static void mc6845_cursor_configure(super80_state *state)
368356{
369357   UINT8 i,curs_type=0,r9,r10,r11;
370358
r9669r9670
374362        2 = full cursor
375363        3 = two-part cursor (has a part at the top and bottom with the middle blank) */
376364
377   for ( i = 0; i < ARRAY_LENGTH(mc6845_cursor); i++) mc6845_cursor[i] = 0;      // prepare cursor by erasing old one
365   for ( i = 0; i < ARRAY_LENGTH(state->mc6845_cursor); i++) state->mc6845_cursor[i] = 0;      // prepare cursor by erasing old one
378366
379   r9  = mc6845_reg[9];               // number of scan lines - 1
380   r10 = mc6845_reg[10] & 0x1f;            // cursor start line = last 5 bits
381   r11 = mc6845_reg[11]+1;               // cursor end line incremented to suit for-loops below
367   r9  = state->mc6845_reg[9];               // number of scan lines - 1
368   r10 = state->mc6845_reg[10] & 0x1f;            // cursor start line = last 5 bits
369   r11 = state->mc6845_reg[11]+1;               // cursor end line incremented to suit for-loops below
382370
383371   /* decide the curs_type by examining the registers */
384372   if (r10 < r11) curs_type=1;            // start less than end, show start to end
r9669r9670
391379   if (r11 > 16) r11=16;               // truncate 5-bit register to fit our 4-bit hardware
392380
393381   /* create the new cursor */
394   if (curs_type > 1) for (i = 0;i < ARRAY_LENGTH(mc6845_cursor);i++) mc6845_cursor[i]=0xff; // turn on full cursor
382   if (curs_type > 1) for (i = 0;i < ARRAY_LENGTH(state->mc6845_cursor);i++) state->mc6845_cursor[i]=0xff; // turn on full cursor
395383
396   if (curs_type == 1) for (i = r10;i < r11;i++) mc6845_cursor[i]=0xff; // for each line that should show, turn on that scan line
384   if (curs_type == 1) for (i = r10;i < r11;i++) state->mc6845_cursor[i]=0xff; // for each line that should show, turn on that scan line
397385
398   if (curs_type == 3) for (i = r11; i < r10;i++) mc6845_cursor[i]=0; // now take a bite out of the middle
386   if (curs_type == 3) for (i = r11; i < r10;i++) state->mc6845_cursor[i]=0; // now take a bite out of the middle
399387}
400388
401389VIDEO_START( super80v )
402390{
403   mc6845 = machine->device("crtc");
404   pcgram = memory_region(machine, "maincpu")+0xf000;
405   videoram = memory_region(machine, "videoram");
406   colorram = memory_region(machine, "colorram");
391   super80_state *state = machine->driver_data<super80_state>();
392   state->mc6845 = machine->device("crtc");
393   state->pcgram = memory_region(machine, "maincpu")+0xf000;
394   state->videoram = memory_region(machine, "videoram");
395   state->colorram = memory_region(machine, "colorram");
407396}
408397
409398VIDEO_UPDATE( super80v )
410399{
411400   super80_state *state = screen->machine->driver_data<super80_state>();
412   framecnt++;
413   speed = mc6845_reg[10]&0x20, flash = mc6845_reg[10]&0x40;         // cursor modes
414   cursor = (mc6845_reg[14]<<8) | mc6845_reg[15];               // get cursor position
415   s_options=input_port_read(screen->machine, "CONFIG");
401   state->framecnt++;
402   state->speed = state->mc6845_reg[10]&0x20, state->flash = state->mc6845_reg[10]&0x40;         // cursor modes
403   state->cursor = (state->mc6845_reg[14]<<8) | state->mc6845_reg[15];               // get cursor position
404   state->s_options=input_port_read(screen->machine, "CONFIG");
416405   output_set_value("cass_led",(state->super80_shared & 0x20) ? 1 : 0);
417   mc6845_update(mc6845, bitmap, cliprect);
406   mc6845_update(state->mc6845, bitmap, cliprect);
418407   return 0;
419408}
420409
r9669r9670
430419      UINT8 inv=0;
431420      //      if (x == cursor_x) inv=0xff;    /* uncomment when mame fixed */
432421      mem = (ma + x) & 0xfff;
433      chr = videoram[mem];
422      chr = state->videoram[mem];
434423
435424      /* get colour or b&w */
436425      fg = 5;                  /* green */
437      if ((s_options & 0x60) == 0x60) fg = 15;      /* b&w */
426      if ((state->s_options & 0x60) == 0x60) fg = 15;      /* b&w */
438427
439      if (~s_options & 0x40)
428      if (~state->s_options & 0x40)
440429      {
441         col = colorram[mem];               /* byte of colour to display */
430         col = state->colorram[mem];               /* byte of colour to display */
442431         fg = col & 0x0f;
443432         bg = (col & 0xf0) >> 4;
444433      }
r9669r9670
451440      }
452441
453442      /* process cursor - remove when mame fixed */
454      if ((((!flash) && (!speed)) ||
455         ((flash) && (speed) && (framecnt & 0x10)) ||
456         ((flash) && (!speed) && (framecnt & 8))) &&
457         (mem == cursor))
458            inv ^= mc6845_cursor[ra];
443      if ((((!state->flash) && (!state->speed)) ||
444         ((state->flash) && (state->speed) && (state->framecnt & 0x10)) ||
445         ((state->flash) && (!state->speed) && (state->framecnt & 8))) &&
446         (mem == state->cursor))
447            inv ^= state->mc6845_cursor[ra];
459448
460449      /* get pattern of pixels for that character scanline */
461      gfx = pcgram[(chr<<4) | ra] ^ inv;
450      gfx = state->pcgram[(chr<<4) | ra] ^ inv;
462451
463452      /* Display a scanline of a character (7 pixels) */
464453      *p++ = ( gfx & 0x80 ) ? fg : bg;
r9669r9670
475464
476465WRITE8_HANDLER( super80v_10_w )
477466{
467   super80_state *state = space->machine->driver_data<super80_state>();
478468   data &= 0x1f;
479   mc6845_ind = data;
480   mc6845_address_w( mc6845, 0, data );
469   state->mc6845_ind = data;
470   mc6845_address_w( state->mc6845, 0, data );
481471}
482472
483473WRITE8_HANDLER( super80v_11_w )
484474{
485   mc6845_reg[mc6845_ind] = data & mc6845_mask[mc6845_ind];   /* save data in register */
486   mc6845_register_w( mc6845, 0, data );
487   if ((mc6845_ind > 8) && (mc6845_ind < 12)) mc6845_cursor_configure();      /* adjust cursor shape - remove when mame fixed */
475   super80_state *state = space->machine->driver_data<super80_state>();
476   state->mc6845_reg[state->mc6845_ind] = data & mc6845_mask[state->mc6845_ind];   /* save data in register */
477   mc6845_register_w( state->mc6845, 0, data );
478   if ((state->mc6845_ind > 8) && (state->mc6845_ind < 12)) mc6845_cursor_configure(state);      /* adjust cursor shape - remove when mame fixed */
488479}
src/mess/video/pc8801.c
r9669r9670
2929static UINT16 dmac_addr[3], dmac_size[3];
3030static UINT8 dmac_flag, dmac_status;
3131
32static enum
32enum
3333{
3434   noblink_underline,
3535   blink_underline,
3636   noblink_block,
3737   blink_block
38} cursor_mode;
38};
39static int cursor_mode;
3940
40static enum
41enum
4142{
4243   parameter0,
4344   parameter1,
r9669r9670
4950   lpenx,
5051   lpeny,
5152   other
52} crtc_state;
53};
54static int crtc_state;
5355
54typedef enum
56enum
5557{
5658   GRAPH_NO,
5759   GRAPH_200_COL,
5860   GRAPH_200_BW,
5961   GRAPH_400_BW
60} GMODE;
62};
63static int gmode;
6164
62static GMODE gmode=GRAPH_NO;
6365static int disp_plane[3];
6466
6567#define TX_SEC      0x0001
r9669r9670
993995
994996WRITE8_HANDLER( pc88sr_disp_31 )
995997{
996   GMODE gmode_new = GRAPH_NO;
998   int gmode_new = GRAPH_NO;
997999
9981000   switch (data & 0x19)
9991001   {
src/mess/video/pet.c
r9669r9670
7676   {
7777      for (x=0;x<40;x++, i++)
7878      {
79         drawgfx_opaque(bitmap, NULL,screen->machine->gfx[pet_font],
79         drawgfx_opaque(bitmap, NULL,screen->machine->gfx[state->font],
8080               videoram[i], 0, 0, 0, 8*x,8*y);
8181      }
8282   }
r9669r9670
9191   int i;
9292
9393   for( i = 0; i < x_count; i++ ) {
94      drawgfx_opaque( bitmap, cliprect, device->machine->gfx[pet_font], videoram[(ma+i)&0x3ff], 0, 0, 0, 8 * i, y-ra );
94      drawgfx_opaque( bitmap, cliprect, device->machine->gfx[state->font], videoram[(ma+i)&0x3ff], 0, 0, 0, 8 * i, y-ra );
9595   }
9696}
9797
r9669r9670
102102   int i;
103103
104104   for( i = 0; i < x_count; i++ ) {
105      drawgfx_opaque( bitmap, cliprect, device->machine->gfx[pet_font], videoram[((ma+i)<<1)&0x7ff], 0, 0, 0, 16 * i, y-ra );
106      drawgfx_opaque( bitmap, cliprect, device->machine->gfx[pet_font], videoram[(((ma+i)<<1)+1)&0x7ff], 0, 0, 0, 16 * i + 8, y-ra );
105      drawgfx_opaque( bitmap, cliprect, device->machine->gfx[state->font], videoram[((ma+i)<<1)&0x7ff], 0, 0, 0, 16 * i, y-ra );
106      drawgfx_opaque( bitmap, cliprect, device->machine->gfx[state->font], videoram[(((ma+i)<<1)+1)&0x7ff], 0, 0, 0, 16 * i + 8, y-ra );
107107   }
108108}
109109
src/mess/video/oric.c
r9669r9670
1313#include "emu.h"
1414#include "includes/oric.h"
1515
16static void oric_vh_update_flash(void);
16static void oric_vh_update_flash(oric_state *state);
1717static void oric_vh_update_attribute(running_machine *machine,int c);
18static void oric_refresh_charset(void);
18static void oric_refresh_charset(oric_state *state);
1919
20/* current state of the display */
21/* some attributes persist until they are turned off.
22This structure holds this persistant information */
23struct oric_vh_state
24{
25   /* foreground and background colour used for rendering */
26   /* if flash attribute is set, these two will both be equal
27    to background colour */
28   int active_foreground_colour;
29   int active_background_colour;
30   /* current foreground and background colour */
31   int foreground_colour;
32   int background_colour;
33   int mode;
34   /* text attributes */
35   int text_attributes;
3620
37   unsigned long read_addr;
38
39   /* current addr to fetch data */
40   unsigned char *char_data;
41   /* base of char data */
42   unsigned char *char_base;
43
44   /* if (1<<3), display graphics, if 0, hide graphics */
45   int flash_state;
46   /* current count */
47   int flash_count;
48};
49
50
51static struct oric_vh_state vh_state;
52
5321static TIMER_CALLBACK(oric_vh_timer_callback)
5422{
23   oric_state *state = machine->driver_data<oric_state>();
5524   /* update flash count */
56   vh_state.flash_count++;
57   if (vh_state.flash_count == 16)
25   state->vh_state.flash_count++;
26   if (state->vh_state.flash_count == 16)
5827   {
59      vh_state.flash_count = 0;
60      vh_state.flash_state ^=(1<<3);
61      oric_vh_update_flash();
28      state->vh_state.flash_count = 0;
29      state->vh_state.flash_state ^=(1<<3);
30      oric_vh_update_flash(state);
6231   }
6332}
6433
6534VIDEO_START( oric )
6635{
36   oric_state *state = machine->driver_data<oric_state>();
6737   /* initialise flash timer */
68   vh_state.flash_count = 0;
69   vh_state.flash_state = 0;
38   state->vh_state.flash_count = 0;
39   state->vh_state.flash_state = 0;
7040   timer_pulse(machine, ATTOTIME_IN_HZ(50), NULL, 0, oric_vh_timer_callback);
7141   /* mode */
7242   oric_vh_update_attribute(machine,(1<<3)|(1<<4));
7343}
7444
7545
76static void oric_vh_update_flash(void)
46static void oric_vh_update_flash(oric_state *state)
7747{
7848   /* flash active? */
79   if (vh_state.text_attributes & (1<<2))
49   if (state->vh_state.text_attributes & (1<<2))
8050   {
8151      /* yes */
8252
8353      /* show or hide text? */
84      if (vh_state.flash_state)
54      if (state->vh_state.flash_state)
8555      {
8656         /* hide */
8757         /* set foreground and background to be the same */
88         vh_state.active_foreground_colour = vh_state.background_colour;
89         vh_state.active_background_colour = vh_state.background_colour;
58         state->vh_state.active_foreground_colour = state->vh_state.background_colour;
59         state->vh_state.active_background_colour = state->vh_state.background_colour;
9060         return;
9161      }
9262   }
9363
9464
9565   /* show */
96   vh_state.active_foreground_colour = vh_state.foreground_colour;
97   vh_state.active_background_colour = vh_state.background_colour;
66   state->vh_state.active_foreground_colour = state->vh_state.foreground_colour;
67   state->vh_state.active_background_colour = state->vh_state.background_colour;
9868}
9969
10070/* the alternate charset follows from the standard charset.
10171Each charset holds 128 chars with 8 bytes for each char.
10272
10373The start address for the standard charset is dependant on the video mode */
104static void oric_refresh_charset(void)
74static void oric_refresh_charset(oric_state *state)
10575{
10676   /* alternate char set? */
107   if ((vh_state.text_attributes & (1<<0))==0)
77   if ((state->vh_state.text_attributes & (1<<0))==0)
10878   {
10979      /* no */
110      vh_state.char_data = vh_state.char_base;
80      state->vh_state.char_data = state->vh_state.char_base;
11181   }
11282   else
11383   {
11484      /* yes */
115      vh_state.char_data = vh_state.char_base + (128*8);
85      state->vh_state.char_data = state->vh_state.char_base + (128*8);
11686   }
11787}
11888
11989/* update video hardware state depending on the new attribute */
12090static void oric_vh_update_attribute(running_machine *machine,int c)
12191{
92   oric_state *state = machine->driver_data<oric_state>();
12293   /* attribute */
12394   int attribute = c & 0x03f;
12495   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
r9669r9670
12899      case 0:
129100      {
130101         /* set foreground colour */
131         vh_state.foreground_colour = attribute & 0x07;
132         oric_vh_update_flash();
102         state->vh_state.foreground_colour = attribute & 0x07;
103         oric_vh_update_flash(state);
133104      }
134105      break;
135106
136107      case 1:
137108      {
138         vh_state.text_attributes = attribute & 0x07;
109         state->vh_state.text_attributes = attribute & 0x07;
139110
140         oric_refresh_charset();
111         oric_refresh_charset(state);
141112
142113         /* text attributes */
143         oric_vh_update_flash();
114         oric_vh_update_flash(state);
144115      }
145116      break;
146117
147118      case 2:
148119      {
149120         /* set background colour */
150         vh_state.background_colour = attribute & 0x07;
151         oric_vh_update_flash();
121         state->vh_state.background_colour = attribute & 0x07;
122         oric_vh_update_flash(state);
152123      }
153124      break;
154125
155126      case 3:
156127      {
157128         /* set video mode */
158         vh_state.mode = attribute & 0x07;
129         state->vh_state.mode = attribute & 0x07;
159130
160131         /* a different charset base is used depending on the video mode */
161132         /* hires takes all the data from 0x0a000 through to about 0x0bf68,
162133            so the charset is moved to 0x09800 */
163134         /* text mode starts at 0x0bb80 and so the charset is in a different location */
164         if (vh_state.mode & (1<<2))
135         if (state->vh_state.mode & (1<<2))
165136         {
166137            /* set screen memory base and standard charset location for this mode */
167            vh_state.read_addr = 0x0a000;
168            if (oric_ram)
169               vh_state.char_base = oric_ram + (unsigned long)0x09800;
138            state->vh_state.read_addr = 0x0a000;
139            if (state->ram)
140               state->vh_state.char_base = state->ram + (unsigned long)0x09800;
170141            else
171               vh_state.char_base = (unsigned char *)space->get_read_ptr(0x09800);
142               state->vh_state.char_base = (unsigned char *)space->get_read_ptr(0x09800);
172143
173144            /* changing the mode also changes the position of the standard charset
174145                and alternative charset */
175            oric_refresh_charset();
146            oric_refresh_charset(state);
176147         }
177148         else
178149         {
179150            /* set screen memory base and standard charset location for this mode */
180            vh_state.read_addr = 0x0bb80;
181            if (oric_ram)
182               vh_state.char_base = oric_ram + (unsigned long)0x0b400;
151            state->vh_state.read_addr = 0x0bb80;
152            if (state->ram)
153               state->vh_state.char_base = state->ram + (unsigned long)0x0b400;
183154            else
184               vh_state.char_base = (unsigned char *)space->get_read_ptr(0x0b400);
155               state->vh_state.char_base = (unsigned char *)space->get_read_ptr(0x0b400);
185156
186157            /* changing the mode also changes the position of the standard charset
187158                and alternative charset */
188            oric_refresh_charset();
159            oric_refresh_charset(state);
189160         }
190161      }
191162      break;
r9669r9670
235206***************************************************************************/
236207VIDEO_UPDATE( oric )
237208{
209   oric_state *state = screen->machine->driver_data<oric_state>();
238210   unsigned char *RAM;
239211   int byte_offset;
240212   int y;
241213   unsigned long read_addr_base;
242214   int hires_active;
243215
244   RAM = oric_ram;
216   RAM = state->ram;
245217
246218   /* set initial base */
247   read_addr_base = vh_state.read_addr;
219   read_addr_base = state->vh_state.read_addr;
248220
249221   /* is hires active? */
250   if (vh_state.mode & (1<<2))
222   if (state->vh_state.mode & (1<<2))
251223   {
252224      hires_active = 1;
253225   }
r9669r9670
307279            oric_vh_update_attribute(screen->machine, c);
308280
309281            /* display background colour when attribute has been found */
310            oric_vh_render_6pixels(bitmap, x, y, vh_state.active_foreground_colour, vh_state.active_background_colour, 0, (c & 0x080));
282            oric_vh_render_6pixels(bitmap, x, y, state->vh_state.active_foreground_colour, state->vh_state.active_background_colour, 0, (c & 0x080));
311283
312284            if (y < 200)
313285            {
314286               /* is hires active? */
315               if (vh_state.mode & (1 << 2))
287               if (state->vh_state.mode & (1 << 2))
316288               {
317289                  hires_active = 1;
318290               }
r9669r9670
321293                  hires_active = 0;
322294               }
323295
324               read_addr_base = vh_state.read_addr;
296               read_addr_base = state->vh_state.read_addr;
325297            }
326298         }
327299         else
r9669r9670
331303            {
332304               int pixel_data = c & 0x03f;
333305               /* plot hires pixels */
334               oric_vh_render_6pixels(bitmap,x,y,vh_state.active_foreground_colour, vh_state.active_background_colour, pixel_data,(c & 0x080));
306               oric_vh_render_6pixels(bitmap,x,y,state->vh_state.active_foreground_colour, state->vh_state.active_background_colour, pixel_data,(c & 0x080));
335307            }
336308            else
337309            {
r9669r9670
344316               ch_line = y & 7;
345317
346318               /* is double height set? */
347               if (vh_state.text_attributes & (1<<1))
319               if (state->vh_state.text_attributes & (1<<1))
348320               {
349321                  /* if char line is even, top half of character is displayed,
350322                        if char line is odd, bottom half of character is displayed */
r9669r9670
355327               }
356328
357329               /* fetch pixel data for this char line */
358               char_data = vh_state.char_data[(char_index<<3) | ch_line] & 0x03f;
330               char_data = state->vh_state.char_data[(char_index<<3) | ch_line] & 0x03f;
359331
360332               /* draw! */
361333               oric_vh_render_6pixels(bitmap,x,y,
362                  vh_state.active_foreground_colour,
363                  vh_state.active_background_colour, char_data, (c & 0x080));
334                  state->vh_state.active_foreground_colour,
335                  state->vh_state.active_background_colour, char_data, (c & 0x080));
364336            }
365337
366338         }
src/mess/video/vc4000.c
r9669r9670
2222
2323#define VC4000_END_LINE (269)
2424
25typedef struct {
26   UINT8 bitmap[10],x1,x2,y1,y2, res1, res2;
27} SPRITE_HELPER;
2825
29typedef struct {
30   const SPRITE_HELPER *data;
31   int mask;
32   int state;
33   int delay;
34   int size;
35   int y;
36   UINT8 scolor;
37   int finished;
38   int finished_now;
39} SPRITE;
4026
41static struct
42{
43   SPRITE sprites[4];
44   int line;
45   UINT8 sprite_collision;
46   UINT8 background_collision;
47   union
48   {
49      UINT8 data[0x100];
50      struct
51      {
52         SPRITE_HELPER sprites[3];
53         UINT8 res[0x10];
54         SPRITE_HELPER sprite4;
55         UINT8 res2[0x30];
56         UINT8 grid[20][2];
57         UINT8 grid_control[5];
58         UINT8 res3[0x13];
59         UINT8 sprite_sizes;
60         UINT8 sprite_colors[2];
61         UINT8 score_control;
62         UINT8 res4[2];
63         UINT8 background;
64         UINT8 sound;
65         UINT8 bcd[2];
66         UINT8 background_collision;
67         UINT8 sprite_collision;
68      } d;
69   } reg;
70
71   bitmap_t *bitmap;
72} vc4000_video;
73
74static UINT8 sprite_collision[0x20];
75static UINT8 background_collision[0x20];
76static UINT8 joy1_x,joy1_y,joy2_x,joy2_y;
77
7827VIDEO_START(vc4000)
7928{
29   vc4000_state *state = machine->driver_data<vc4000_state>();
8030   screen_device *screen = screen_first(*machine);
8131   int width = screen->width();
8232   int height = screen->height();
r9669r9670
8434
8535   for (i=0;i<0x20; i++)
8636   {
87      sprite_collision[i]=0;
88      if ((i&3)==3) sprite_collision[i]|=0x20;
89      if ((i&5)==5) sprite_collision[i]|=0x10;
90      if ((i&9)==9) sprite_collision[i]|=8;
91      if ((i&6)==6) sprite_collision[i]|=4;
92      if ((i&0xa)==0xa) sprite_collision[i]|=2;
93      if ((i&0xc)==0xc) sprite_collision[i]|=1;
94      background_collision[i]=0;
95      if ((i&0x11)==0x11) background_collision[i]|=0x80;
96      if ((i&0x12)==0x12) background_collision[i]|=0x40;
97      if ((i&0x14)==0x14) background_collision[i]|=0x20;
98      if ((i&0x18)==0x18) background_collision[i]|=0x10;
37      state->sprite_collision[i]=0;
38      if ((i&3)==3) state->sprite_collision[i]|=0x20;
39      if ((i&5)==5) state->sprite_collision[i]|=0x10;
40      if ((i&9)==9) state->sprite_collision[i]|=8;
41      if ((i&6)==6) state->sprite_collision[i]|=4;
42      if ((i&0xa)==0xa) state->sprite_collision[i]|=2;
43      if ((i&0xc)==0xc) state->sprite_collision[i]|=1;
44      state->background_collision[i]=0;
45      if ((i&0x11)==0x11) state->background_collision[i]|=0x80;
46      if ((i&0x12)==0x12) state->background_collision[i]|=0x40;
47      if ((i&0x14)==0x14) state->background_collision[i]|=0x20;
48      if ((i&0x18)==0x18) state->background_collision[i]|=0x10;
9949   }
10050
101   joy1_x = STICKCENTRE;
102   joy1_y = STICKCENTRE;
103   joy2_x = STICKCENTRE;
104   joy2_y = STICKCENTRE;
51   state->joy1_x = STICKCENTRE;
52   state->joy1_y = STICKCENTRE;
53   state->joy2_x = STICKCENTRE;
54   state->joy2_y = STICKCENTRE;
10555
106   memset(&vc4000_video, 0, sizeof(vc4000_video));
56   memset(&state->video, 0, sizeof(state->video));
10757   for (i=0; i<3; i++)
10858   {
109      vc4000_video.sprites[i].data = &vc4000_video.reg.d.sprites[i];
110      vc4000_video.sprites[i].mask = 1 << i;
59      state->video.sprites[i].data = &state->video.reg.d.sprites[i];
60      state->video.sprites[i].mask = 1 << i;
11161   }
112   vc4000_video.sprites[3].data = &vc4000_video.reg.d.sprite4;
113   vc4000_video.sprites[3].mask = 1 << 3;
62   state->video.sprites[3].data = &state->video.reg.d.sprite4;
63   state->video.sprites[3].mask = 1 << 3;
11464
115   vc4000_video.bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
65   state->video.bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
11666}
11767
11868INLINE UINT8 vc4000_joystick_return_to_centre(UINT8 joy)
r9669r9670
13282
13383READ8_HANDLER(vc4000_video_r)
13484{
85   vc4000_state *state = space->machine->driver_data<vc4000_state>();
13586   UINT8 data=0;
13687   if (offset > 0xcf) offset &= 0xcf;   // c0-cf is mirrored at d0-df, e0-ef, f0-ff
13788   switch (offset) {
13889
13990   case 0xca:      // Background-sprite collision (bit 7-4) and sprite finished (bit 3-0)
140      data |= vc4000_video.background_collision;
141      vc4000_video.background_collision=0;
142      if (vc4000_video.sprites[3].finished)
91      data |= state->video.background_collision;
92      state->video.background_collision=0;
93      if (state->video.sprites[3].finished)
14394      {
14495         data |= 1;
145         vc4000_video.sprites[3].finished = FALSE;
96         state->video.sprites[3].finished = FALSE;
14697      }
14798
148      if (vc4000_video.sprites[2].finished)
99      if (state->video.sprites[2].finished)
149100      {
150101         data |= 2;
151         vc4000_video.sprites[2].finished = FALSE;
102         state->video.sprites[2].finished = FALSE;
152103      }
153      if (vc4000_video.sprites[1].finished)
104      if (state->video.sprites[1].finished)
154105      {
155106         data |= 4;
156         vc4000_video.sprites[1].finished = FALSE;
107         state->video.sprites[1].finished = FALSE;
157108      }
158      if (vc4000_video.sprites[0].finished)
109      if (state->video.sprites[0].finished)
159110      {
160111         data |= 8;
161         vc4000_video.sprites[0].finished = FALSE;
112         state->video.sprites[0].finished = FALSE;
162113      }
163114      break;
164115
165116   case 0xcb:      //    VRST-Flag (bit 6) and intersprite collision (bit5-0)
166      data = vc4000_video.sprite_collision | (vc4000_video.reg.d.sprite_collision & 0xc0);
167      vc4000_video.sprite_collision = 0;
168      vc4000_video.reg.d.sprite_collision &= 0xbf;
117      data = state->video.sprite_collision | (state->video.reg.d.sprite_collision & 0xc0);
118      state->video.sprite_collision = 0;
119      state->video.reg.d.sprite_collision &= 0xbf;
169120      break;
170121
171122#ifndef ANALOG_HACK
r9669r9670
188139            switch (data)
189140            {
190141            case 0x01:
191               joy1_x-=5;
192               if (joy1_x < STICKLOW) joy1_x=STICKLOW;
142               state->joy1_x-=5;
143               if (state->joy1_x < STICKLOW) state->joy1_x=STICKLOW;
193144               break;
194145            case 0x02:
195               joy1_x+=5;
196               if (joy1_x > STICKHIGH) joy1_x=STICKHIGH;
146               state->joy1_x+=5;
147               if (state->joy1_x > STICKHIGH) state->joy1_x=STICKHIGH;
197148               break;
198149            case 0x00:
199               joy1_x = vc4000_joystick_return_to_centre(joy1_x);
150               state->joy1_x = vc4000_joystick_return_to_centre(state->joy1_x);
200151            }
201            data=joy1_x;
152            data=state->joy1_x;
202153         }
203154         else
204155         {
r9669r9670
206157            switch (data)
207158            {
208159            case 0x08:
209               joy1_y-=5;
210               if (joy1_y < STICKLOW) joy1_y=STICKLOW;
160               state->joy1_y-=5;
161               if (state->joy1_y < STICKLOW) state->joy1_y=STICKLOW;
211162               break;
212163            case 0x04:
213               joy1_y+=5;
214               if (joy1_y > STICKHIGH) joy1_y=STICKHIGH;
164               state->joy1_y+=5;
165               if (state->joy1_y > STICKHIGH) state->joy1_y=STICKHIGH;
215166               break;
216167      //      case 0x00:
217      //          joy1_y = vc4000_joystick_return_to_centre(joy1_y);
168      //          state->joy1_y = vc4000_joystick_return_to_centre(state->joy1_y);
218169            }
219            data=joy1_y;
170            data=state->joy1_y;
220171         }
221172      }
222173      else
r9669r9670
227178            switch (data)
228179            {
229180            case 0x01:
230               joy1_x=STICKLOW;
181               state->joy1_x=STICKLOW;
231182               break;
232183            case 0x02:
233               joy1_x=STICKHIGH;
184               state->joy1_x=STICKHIGH;
234185               break;
235186            default:         /* autocentre */
236               joy1_x=STICKCENTRE;
187               state->joy1_x=STICKCENTRE;
237188            }
238            data=joy1_x;
189            data=state->joy1_x;
239190         }
240191         else
241192         {
r9669r9670
243194            switch (data)
244195            {
245196            case 0x08:
246               joy1_y=STICKLOW;
197               state->joy1_y=STICKLOW;
247198               break;
248199            case 0x04:
249               joy1_y=STICKHIGH;
200               state->joy1_y=STICKHIGH;
250201               break;
251202            default:
252               joy1_y=STICKCENTRE;
203               state->joy1_y=STICKCENTRE;
253204            }
254            data=joy1_y;
205            data=state->joy1_y;
255206         }
256207      }
257208      break;
r9669r9670
265216            switch (data)
266217            {
267218            case 0x10:
268               joy2_x-=5;
269               if (joy2_x < STICKLOW) joy2_x=STICKLOW;
219               state->joy2_x-=5;
220               if (state->joy2_x < STICKLOW) state->joy2_x=STICKLOW;
270221               break;
271222            case 0x20:
272               joy2_x+=5;
273               if (joy2_x > STICKHIGH) joy2_x=STICKHIGH;
223               state->joy2_x+=5;
224               if (state->joy2_x > STICKHIGH) state->joy2_x=STICKHIGH;
274225            case 0x00:
275               joy2_x = vc4000_joystick_return_to_centre(joy2_x);
226               state->joy2_x = vc4000_joystick_return_to_centre(state->joy2_x);
276227               break;
277228            }
278            data=joy2_x;
229            data=state->joy2_x;
279230         }
280231         else
281232         {
r9669r9670
283234            switch (data)
284235            {
285236            case 0x80:
286               joy2_y-=5;
287               if (joy2_y < STICKLOW) joy2_y=STICKLOW;
237               state->joy2_y-=5;
238               if (state->joy2_y < STICKLOW) state->joy2_y=STICKLOW;
288239               break;
289240            case 0x40:
290               joy2_y+=5;
291               if (joy2_y > STICKHIGH) joy2_y=STICKHIGH;
241               state->joy2_y+=5;
242               if (state->joy2_y > STICKHIGH) state->joy2_y=STICKHIGH;
292243               break;
293244         //  case 0x00:
294         //      joy2_y = vc4000_joystick_return_to_centre(joy2_y);
245         //      state->joy2_y = vc4000_joystick_return_to_centre(state->joy2_y);
295246            }
296            data=joy2_y;
247            data=state->joy2_y;
297248         }
298249      }
299250      else
r9669r9670
304255            switch (data)
305256            {
306257            case 0x10:
307               joy2_x=STICKLOW;
258               state->joy2_x=STICKLOW;
308259               break;
309260            case 0x20:
310               joy2_x=STICKHIGH;
261               state->joy2_x=STICKHIGH;
311262               break;
312263            default:         /* autocentre */
313               joy2_x=STICKCENTRE;
264               state->joy2_x=STICKCENTRE;
314265            }
315            data=joy2_x;
266            data=state->joy2_x;
316267         }
317268         else
318269         {
r9669r9670
320271            switch (data)
321272            {
322273            case 0x80:
323               joy2_y=STICKLOW;
274               state->joy2_y=STICKLOW;
324275               break;
325276            case 0x40:
326               joy2_y=STICKHIGH;
277               state->joy2_y=STICKHIGH;
327278               break;
328279            default:
329               joy2_y=STICKCENTRE;
280               state->joy2_y=STICKCENTRE;
330281            }
331            data=joy2_y;
282            data=state->joy2_y;
332283         }
333284      }
334285      break;
335286#endif
336287
337288   default:
338      data = vc4000_video.reg.data[offset];
289      data = state->video.reg.data[offset];
339290      break;
340291   }
341292   return data;
r9669r9670
343294
344295WRITE8_HANDLER(vc4000_video_w)
345296{
346//  vc4000_video.reg.data[offset]=data;
297   vc4000_state *state = space->machine->driver_data<vc4000_state>();
298//  state->video.reg.data[offset]=data;
347299   if (offset > 0xcf) offset &= 0xcf;   // c0-cf is mirrored at d0-df, e0-ef, f0-ff
348300
349301   switch (offset) {
350302
351303   case 0xc0:                  // Sprite size
352      vc4000_video.sprites[0].size=1<<(data&3);
353      vc4000_video.sprites[1].size=1<<((data>>2)&3);
354      vc4000_video.sprites[2].size=1<<((data>>4)&3);
355      vc4000_video.sprites[3].size=1<<((data>>6)&3);
304      state->video.sprites[0].size=1<<(data&3);
305      state->video.sprites[1].size=1<<((data>>2)&3);
306      state->video.sprites[2].size=1<<((data>>4)&3);
307      state->video.sprites[3].size=1<<((data>>6)&3);
356308      break;
357309
358310   case 0xc1:                  // Sprite 1+2 color
359      vc4000_video.sprites[0].scolor=((~data>>3)&7);
360      vc4000_video.sprites[1].scolor=(~data&7);
311      state->video.sprites[0].scolor=((~data>>3)&7);
312      state->video.sprites[1].scolor=(~data&7);
361313      break;
362314
363315   case 0xc2:                  // Sprite 2+3 color
364      vc4000_video.sprites[2].scolor=((~data>>3)&7);
365      vc4000_video.sprites[3].scolor=(~data&7);
316      state->video.sprites[2].scolor=((~data>>3)&7);
317      state->video.sprites[3].scolor=(~data&7);
366318      break;
367319
368320   case 0xc3:                  // Score control
369      vc4000_video.reg.d.score_control = data;
321      state->video.reg.d.score_control = data;
370322      break;
371323
372324   case 0xc6:                  // Background color
373      vc4000_video.reg.d.background = data;
325      state->video.reg.d.background = data;
374326      break;
375327
376328   case 0xc7:                  // Soundregister
377      vc4000_video.reg.data[offset] = data;
329      state->video.reg.data[offset] = data;
378330      vc4000_soundport_w(space->machine->device("custom"), 0, data);
379331      break;
380332
381333   case 0xc8:                  // Digits 1 and 2
382      vc4000_video.reg.d.bcd[0] = data;
334      state->video.reg.d.bcd[0] = data;
383335      break;
384336
385337   case 0xc9:                  // Digits 3 and 4
386      vc4000_video.reg.d.bcd[1] = data;
338      state->video.reg.d.bcd[1] = data;
387339      break;
388340
389341   case 0xca:         // Background-sprite collision (bit 7-4) and sprite finished (bit 3-0)
390      vc4000_video.reg.data[offset]=data;
391      vc4000_video.background_collision=data;
342      state->video.reg.data[offset]=data;
343      state->video.background_collision=data;
392344      break;
393345
394346   case 0xcb:               // VRST-Flag (bit 6) and intersprite collision (bit5-0)
395      vc4000_video.reg.data[offset]=data;
396      vc4000_video.sprite_collision=data;
347      state->video.reg.data[offset]=data;
348      state->video.sprite_collision=data;
397349      break;
398350
399351   default:
400      vc4000_video.reg.data[offset]=data;
352      state->video.reg.data[offset]=data;
401353    }
402354}
403355
404356
405357READ8_HANDLER(vc4000_vsync_r)
406358{
407   return vc4000_video.line >= VC4000_END_LINE ? 0x80 : 0;
359   vc4000_state *state = space->machine->driver_data<vc4000_state>();
360   return state->video.line >= VC4000_END_LINE ? 0x80 : 0;
408361}
409362
410363static const char led[20][12+1] =
r9669r9670
431384   "iiiihhhhgggg"
432385};
433386
434static UINT8 objects[256];
435387
436static void vc4000_draw_digit(bitmap_t *bitmap, int x, int y, int d, int line)
388static void vc4000_draw_digit(vc4000_state *state, bitmap_t *bitmap, int x, int y, int d, int line)
437389{
438390   static const int digit_to_segment[0x10]={
439391   0x0fff, 0x007c, 0x17df, 0x15ff, 0x1c7d, 0x1df7, 0x1ff7, 0x007f, 0x1fff, 0x1dff
r9669r9670
444396   for (j=0; j<sizeof(led[0]); j++)
445397   {
446398      if (digit_to_segment[d]&(1<<(led[i][j]-'a')) )
447         *BITMAP_ADDR16(bitmap, y+i, x+j) = ((vc4000_video.reg.d.background>>4)&7)^7;
399         *BITMAP_ADDR16(bitmap, y+i, x+j) = ((state->video.reg.d.background>>4)&7)^7;
448400   }
449401}
450402
r9669r9670
462414}
463415
464416
465static void vc4000_sprite_update(bitmap_t *bitmap, UINT8 *collision, SPRITE *This)
417static void vc4000_sprite_update(vc4000_state *state, bitmap_t *bitmap, UINT8 *collision, SPRITE *This)
466418{
467419   int i,j,m;
468420
469   if (vc4000_video.line==0)
421   if (state->video.line==0)
470422   {
471423      This->y=This->data->y1;
472424      This->state=0;
r9669r9670
476428
477429   This->finished_now=FALSE;
478430
479   if (vc4000_video.line>VC4000_END_LINE) return;
431   if (state->video.line>VC4000_END_LINE) return;
480432
481433   switch (This->state)
482434   {
483435   case 0:
484      if (vc4000_video.line != This->y + 2) break;
436      if (state->video.line != This->y + 2) break;
485437      This->state++;
486438
487439   case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:case 9:case 10:
r9669r9670
494446         {
495447            for (i=0; i<This->size; i++)
496448            {
497               objects[This->data->x1 + i + j*This->size] |= This->scolor;
498               objects[This->data->x1 + i + j*This->size] &= 7;
449               state->objects[This->data->x1 + i + j*This->size] |= This->scolor;
450               state->objects[This->data->x1 + i + j*This->size] &= 7;
499451            }
500452         }
501453      }
r9669r9670
546498         {
547499            for (i=0; i<This->size; i++)
548500            {
549               objects[This->data->x2 + i + j*This->size] |= This->scolor;
550               objects[This->data->x2 + i + j*This->size] &= 7;
501               state->objects[This->data->x2 + i + j*This->size] |= This->scolor;
502               state->objects[This->data->x2 + i + j*This->size] &= 7;
551503            }
552504         }
553505      }
r9669r9670
565517
566518INLINE void vc4000_draw_grid(running_machine *machine, UINT8 *collision)
567519{
520   vc4000_state *state = machine->driver_data<vc4000_state>();
568521   screen_device *screen = screen_first(*machine);
569522   int width = screen->width();
570523   int height = screen->height();
571   int i, j, m, x, line=vc4000_video.line-20;
524   int i, j, m, x, line=state->video.line-20;
572525   int w, k;
573526
574   if (vc4000_video.line>=height) return;
527   if (state->video.line>=height) return;
575528
576   plot_box(vc4000_video.bitmap, 0, vc4000_video.line, width, 1, (vc4000_video.reg.d.background)&7);
529   plot_box(state->video.bitmap, 0, state->video.line, width, 1, (state->video.reg.d.background)&7);
577530
578531   if (line<0 || line>=200) return;
579   if (~vc4000_video.reg.d.background & 8) return;
532   if (~state->video.reg.d.background & 8) return;
580533
581534   i=(line/20)*2;
582535   if (line%20>=2) i++;
583536
584   k=vc4000_video.reg.d.grid_control[i>>2];
537   k=state->video.reg.d.grid_control[i>>2];
585538   switch (k>>6) {
586539      default:
587540      case 0:case 2: w=1;break;
r9669r9670
609562   }
610563   for (x=30, j=0, m=0x80; j<16; j++, x+=8, m>>=1)
611564   {
612      if (vc4000_video.reg.d.grid[i][j>>3]&m)
565      if (state->video.reg.d.grid[i][j>>3]&m)
613566      {
614567         int l;
615568         for (l=0; l<w; l++) collision[x+l]|=0x10;
616         plot_box(vc4000_video.bitmap, x, vc4000_video.line, w, 1, (vc4000_video.reg.d.background>>4)&7);
569         plot_box(state->video.bitmap, x, state->video.line, w, 1, (state->video.reg.d.background>>4)&7);
617570      }
618571      if (j==7) m=0x100;
619572   }
r9669r9670
621574
622575INTERRUPT_GEN( vc4000_video_line )
623576{
577   vc4000_state *state = device->machine->driver_data<vc4000_state>();
624578   int x,y,i;
625579   UINT8 collision[400]={0}; // better alloca or gcc feature of non constant long automatic arrays
626   static UINT8 irq_pause=0;
627580   const rectangle &visarea = device->machine->primary_screen->visible_area();
628581   assert(ARRAY_LENGTH(collision) >= device->machine->primary_screen->width());
629582
630   vc4000_video.line++;
631   if (irq_pause) irq_pause++;
632   if (vc4000_video.line>311) vc4000_video.line=0;
583   state->video.line++;
584   if (state->irq_pause) state->irq_pause++;
585   if (state->video.line>311) state->video.line=0;
633586
634   if (vc4000_video.line==0)
587   if (state->video.line==0)
635588   {
636      vc4000_video.background_collision=0;
637      vc4000_video.sprite_collision=0;
638      vc4000_video.reg.d.sprite_collision=0;
589      state->video.background_collision=0;
590      state->video.sprite_collision=0;
591      state->video.reg.d.sprite_collision=0;
639592//      logerror("begin of frame\n");
640593   }
641594
642   if (irq_pause>10)
595   if (state->irq_pause>10)
643596   {
644597      cputag_set_input_line(device->machine, "maincpu", 0, CLEAR_LINE);
645      irq_pause = 0;
598      state->irq_pause = 0;
646599   }
647600
648   if (vc4000_video.line <= VC4000_END_LINE)
601   if (state->video.line <= VC4000_END_LINE)
649602   {
650603      vc4000_draw_grid(device->machine, collision);
651604
652605      /* init object colours */
653      for (i=visarea.min_x; i<visarea.max_x; i++) objects[i]=8;
606      for (i=visarea.min_x; i<visarea.max_x; i++) state->objects[i]=8;
654607
655608      /* calculate object colours and OR overlapping object colours */
656      vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[0]);
657      vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[1]);
658      vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[2]);
659      vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[3]);
609      vc4000_sprite_update(state, state->video.bitmap, collision, &state->video.sprites[0]);
610      vc4000_sprite_update(state, state->video.bitmap, collision, &state->video.sprites[1]);
611      vc4000_sprite_update(state, state->video.bitmap, collision, &state->video.sprites[2]);
612      vc4000_sprite_update(state, state->video.bitmap, collision, &state->video.sprites[3]);
660613
661614      for (i=visarea.min_x; i<visarea.max_x; i++)
662615      {
663         vc4000_video.sprite_collision|=sprite_collision[collision[i]];
664         vc4000_video.background_collision|=background_collision[collision[i]];
616         state->video.sprite_collision|=state->sprite_collision[collision[i]];
617         state->video.background_collision|=state->background_collision[collision[i]];
665618         /* display final object colours */
666         if (objects[i] < 8)
667               *BITMAP_ADDR16(vc4000_video.bitmap, vc4000_video.line, i) = objects[i];
619         if (state->objects[i] < 8)
620               *BITMAP_ADDR16(state->video.bitmap, state->video.line, i) = state->objects[i];
668621      }
669622
670      y = vc4000_video.reg.d.score_control&1?200:20;
623      y = state->video.reg.d.score_control&1?200:20;
671624
672      if ((vc4000_video.line>=y)&&(vc4000_video.line<y+20))
625      if ((state->video.line>=y)&&(state->video.line<y+20))
673626      {
674627         x = 60;
675         vc4000_draw_digit(vc4000_video.bitmap, x, y, vc4000_video.reg.d.bcd[0]>>4, vc4000_video.line-y);
676         vc4000_draw_digit(vc4000_video.bitmap, x+16, y, vc4000_video.reg.d.bcd[0]&0xf, vc4000_video.line-y);
677         if (vc4000_video.reg.d.score_control&2)   x -= 16;
678         vc4000_draw_digit(vc4000_video.bitmap, x+48, y, vc4000_video.reg.d.bcd[1]>>4, vc4000_video.line-y);
679         vc4000_draw_digit(vc4000_video.bitmap, x+64, y, vc4000_video.reg.d.bcd[1]&0xf, vc4000_video.line-y);
628         vc4000_draw_digit(state, state->video.bitmap, x, y, state->video.reg.d.bcd[0]>>4, state->video.line-y);
629         vc4000_draw_digit(state, state->video.bitmap, x+16, y, state->video.reg.d.bcd[0]&0xf, state->video.line-y);
630         if (state->video.reg.d.score_control&2)   x -= 16;
631         vc4000_draw_digit(state, state->video.bitmap, x+48, y, state->video.reg.d.bcd[1]>>4, state->video.line-y);
632         vc4000_draw_digit(state, state->video.bitmap, x+64, y, state->video.reg.d.bcd[1]&0xf, state->video.line-y);
680633      }
681634   }
682   if (vc4000_video.line==VC4000_END_LINE) vc4000_video.reg.d.sprite_collision |=0x40;
635   if (state->video.line==VC4000_END_LINE) state->video.reg.d.sprite_collision |=0x40;
683636
684   if (((vc4000_video.line == VC4000_END_LINE) |
685      (vc4000_video.sprites[3].finished_now) |
686      (vc4000_video.sprites[2].finished_now) |
687      (vc4000_video.sprites[1].finished_now) |
688      (vc4000_video.sprites[0].finished_now)) && (!irq_pause))
637   if (((state->video.line == VC4000_END_LINE) |
638      (state->video.sprites[3].finished_now) |
639      (state->video.sprites[2].finished_now) |
640      (state->video.sprites[1].finished_now) |
641      (state->video.sprites[0].finished_now)) && (!state->irq_pause))
689642      {
690643         cputag_set_input_line_and_vector(device->machine, "maincpu", 0, ASSERT_LINE, 3);
691         irq_pause=1;
644         state->irq_pause=1;
692645      }
693646}
694647
695648VIDEO_UPDATE( vc4000 )
696649{
697   copybitmap(bitmap, vc4000_video.bitmap, 0, 0, 0, 0, cliprect);
650   vc4000_state *state = screen->machine->driver_data<vc4000_state>();
651   copybitmap(bitmap, state->video.bitmap, 0, 0, 0, 0, cliprect);
698652   return 0;
699653}
src/mess/video/vtech2.c
r9669r9670
1414#define BORDER_H   64
1515#define BORDER_V   32
1616
17/* from machine/laser350.c */
18//extern int laser_latch;
19
2017/* public */
21char laser_frame_message[64+1];
22int laser_frame_time = 0;
2318
2419/*
2520 *  when in text mode (bit 3 of I/O area = 0)
r9669r9670
4439 *      0 1 1 1 GR1 bank 7 1E000-1FFFF
4540 *      1 1 1 1 GR1 bank 3 0E000-0FFFF
4641 */
47static int laser_bg_mode = 0;
48static int laser_two_color = 0;
4942
5043VIDEO_START( laser )
5144{
r9669r9670
128121   int full_refresh = 1;
129122
130123   if( full_refresh )
131      bitmap_fill(bitmap, cliprect, ((laser_bg_mode >> 4) & 15)<<1);
124      bitmap_fill(bitmap, cliprect, ((state->laser_bg_mode >> 4) & 15)<<1);
132125
133   if (laser_latch & 0x08)
126   if (state->laser_latch & 0x08)
134127   {
135128      /* graphics modes */
136      switch (laser_bg_mode & 7)
129      switch (state->laser_bg_mode & 7)
137130        {
138131      case  0:
139132      case  1:
r9669r9670
146139            offs = offs_2[y];
147140            for( x = 0; x < 80; x++, offs++ )
148141            {
149               int sx, sy, code, color = laser_two_color;
142               int sx, sy, code, color = state->laser_two_color;
150143               sy = BORDER_V/2 + y;
151144               sx = BORDER_H/2 + x * 8;
152145               code = videoram[offs];
r9669r9670
224217            offs = offs_1[y];
225218            for( x = 0; x < 40; x++, offs++ )
226219            {
227               int sx, sy, code, color = laser_two_color;
220               int sx, sy, code, color = state->laser_two_color;
228221               sy = BORDER_V/2 + y;
229222               sx = BORDER_H/2 + x * 16;
230223               code = videoram[offs];
r9669r9670
257250   else
258251   {
259252      /* text modes */
260      if (laser_bg_mode & 1)
253      if (state->laser_bg_mode & 1)
261254      {
262255         /* 80 columns text mode */
263256         for( y = 0; y < 24; y++ )
r9669r9670
265258            offs = ((y & 7) << 8) + ((y >> 3) * 80);
266259            for( x = 0; x < 80; x++, offs++ )
267260            {
268               int sx, sy, code, color = laser_two_color;
261               int sx, sy, code, color = state->laser_two_color;
269262               sy = BORDER_V/2 + y * 8;
270263               sx = BORDER_H/2 + x * 8;
271264               code = videoram[0x3800+offs];
r9669r9670
292285      }
293286   }
294287
295   if( laser_frame_time > 0 )
288   if( state->laser_frame_time > 0 )
296289   {
297      popmessage("%s", laser_frame_message);
290      popmessage("%s", state->laser_frame_message);
298291   }
299292   return 0;
300293}
301294
302295WRITE8_HANDLER( laser_bg_mode_w )
303296{
304    if (laser_bg_mode != data)
297   vtech2_state *state = space->machine->driver_data<vtech2_state>();
298    if (state->laser_bg_mode != data)
305299    {
306        laser_bg_mode = data;
300        state->laser_bg_mode = data;
307301      logerror("laser border:$%X mode:$%X\n", data >> 4, data & 15);
308302    }
309303}
310304
311305WRITE8_HANDLER( laser_two_color_w )
312306{
313   if (laser_two_color != data)
307   vtech2_state *state = space->machine->driver_data<vtech2_state>();
308   if (state->laser_two_color != data)
314309   {
315      laser_two_color = data;
310      state->laser_two_color = data;
316311      logerror("laser foreground:$%X background:$%X\n", data >> 4, data & 15);
317312    }
318313}
src/mess/includes/vtech2.h
r9669r9670
88#define VTECH2_H_
99
1010
11#define TRKSIZE_FM   3172   /* size of a standard FM mode track */
12
1113class vtech2_state : public driver_device
1214{
1315public:
r9669r9670
1517      : driver_device(machine, config) { }
1618
1719   UINT8 *videoram;
20   int laser_latch;
21   char laser_frame_message[64+1];
22   int laser_frame_time;
23   UINT8 *mem;
24   int laser_bank_mask;
25   int laser_bank[4];
26   int laser_video_bank;
27   UINT8 laser_track_x2[2];
28   UINT8 laser_fdc_status;
29   UINT8 laser_fdc_data[TRKSIZE_FM];
30   int laser_data;
31   int laser_fdc_edge;
32   int laser_fdc_bits;
33   int laser_drive;
34   int laser_fdc_start;
35   int laser_fdc_write;
36   int laser_fdc_offs;
37   int laser_fdc_latch;
38   int level_old;
39   int cassette_bit;
40   int row_a;
41   int row_b;
42   int row_c;
43   int row_d;
44   int laser_bg_mode;
45   int laser_two_color;
1846};
1947
2048
2149/*----------- defined in machine/vtech2.c -----------*/
2250
23extern int laser_latch;
24
2551DRIVER_INIT(laser);
2652MACHINE_RESET( laser350 );
2753MACHINE_RESET( laser500 );
r9669r9670
3763
3864/*----------- defined in video/vtech2.c -----------*/
3965
40extern char laser_frame_message[64+1];
41extern int laser_frame_time;
42
4366extern VIDEO_START( laser );
4467extern VIDEO_UPDATE( laser );
4568extern WRITE8_HANDLER ( laser_bg_mode_w );
src/mess/includes/wswan.h
r9669r9670
3434#define WSWAN_INT_VBL    6
3535#define WSWAN_INT_HBLTMR 7
3636
37#define INTERNAL_EEPROM_SIZE   1024
3738
39
3840typedef struct
3941{
42   UINT8   mode;      /* eeprom mode */
43   UINT16   address;   /* Read/write address */
44   UINT8   command;   /* Commands: 00, 01, 02, 03, 04, 08, 0C */
45   UINT8   start;      /* start bit */
46   UINT8   write_enabled;   /* write enabled yes/no */
47   int   size;      /* size of eeprom/sram area */
48   UINT8   *data;      /* pointer to start of sram/eeprom data */
49   UINT8   *page;      /* pointer to current sram/eeprom page */
50} EEPROM;
51
52typedef struct
53{
54   UINT8   present;   /* Is an RTC present */
55   UINT8   setting;   /* Timer setting byte */
56   UINT8   year;      /* Year */
57   UINT8   month;      /* Month */
58   UINT8   day;      /* Day */
59   UINT8   day_of_week;   /* Day of the week */
60   UINT8   hour;      /* Hour, high bit = 0 => AM, high bit = 1 => PM */
61   UINT8   minute;      /* Minute */
62   UINT8   second;      /* Second */
63   UINT8   index;      /* index for reading/writing of current of alarm time */
64} RTC;
65
66typedef struct
67{
68   UINT32   source;      /* Source address */
69   UINT16   size;      /* Size */
70   UINT8   enable;      /* Enabled */
71} SoundDMA;
72
73typedef struct
74{
4075   UINT8 layer_bg_enable;         /* Background layer on/off */
4176   UINT8 layer_fg_enable;         /* Foreground layer on/off */
4277   UINT8 sprites_enable;         /* Sprites on/off */
r9669r9670
83118} VDP;
84119
85120
121class wswan_state : public driver_device
122{
123public:
124   wswan_state(running_machine &machine, const driver_device_config_base &config)
125      : driver_device(machine, config) { }
126
127   VDP vdp;
128   UINT8 ws_portram[256];
129   UINT8 *ROMMap[256];
130   UINT32 ROMBanks;
131   UINT8 internal_eeprom[INTERNAL_EEPROM_SIZE];
132   UINT8 system_type;
133   EEPROM eeprom;
134   RTC rtc;
135   SoundDMA sound_dma;
136   UINT8 *ws_ram;
137   UINT8 *ws_bios_bank;
138   UINT8 bios_disabled;
139   int pal[16][16];
140};
141
142
86143/*----------- defined in machine/wswan.c -----------*/
87144
88extern VDP wswan_vdp;
89extern UINT8 ws_portram[256];
90
91145NVRAM_HANDLER( wswan );
92146MACHINE_START( wswan );
93147MACHINE_START( wscolor );
src/mess/includes/zx.h
r9669r9670
88#define ZX_H_
99
1010
11class zx_state : public driver_device
12{
13public:
14   zx_state(running_machine &machine, const driver_device_config_base &config)
15      : driver_device(machine, config) { }
16
17   emu_timer *ula_nmi;
18   int ula_irq_active;
19   int ula_frame_vsync;
20   int ula_scanline_count;
21   UINT8 tape_bit;
22   UINT8 speaker_state;
23   int old_x;
24   int old_y;
25   int old_c;
26   UINT8 charline[32];
27   UINT8 charline_ptr;
28   int offs1;
29};
30
31
1132/*----------- defined in machine/zx.c -----------*/
1233
1334DRIVER_INIT( zx );
r9669r9670
3152void zx_ula_bkgnd(running_machine *machine, int color);
3253void zx_ula_r(running_machine *machine, int offs, const char *region, const UINT8 param);
3354
34extern emu_timer *ula_nmi;
35extern int ula_irq_active;
3655//extern int ula_nmi_active;
37extern int ula_frame_vsync;
38extern int ula_scanline_count;
3956//extern int ula_scancode_count;
4057
4158
src/mess/includes/z80ne.h
r9669r9670
2323
2424#define LX385_TAPE_SAMPLE_FREQ 38400
2525
26/* wave duration threshold */
27typedef enum
28{
29   TAPE_300BPS  = 300, /*  300 bps */
30   TAPE_600BPS  = 600, /*  600 bps */
31   TAPE_1200BPS = 1200 /* 1200 bps */
32} z80netape_speed;
2633
34typedef struct {
35   struct {
36      int length;      /* time cassette level is at input.level */
37      int level;      /* cassette level */
38      int bit;      /* bit being read */
39   } input;
40   struct {
41      int length;      /* time cassette level is at output.level */
42      int level;      /* cassette level */
43      int bit;      /* bit to to output */
44   } output;
45   z80netape_speed speed;         /* 300 - 600 - 1200 */
46   int wave_filter;
47   int wave_length;
48   int wave_short;
49   int wave_long;
50} cass_data_t;
51
52typedef struct {
53   int drq;
54   int intrq;
55   UINT8 drive; /* current drive */
56   UINT8 head;  /* current head */
57} wd17xx_state_t;
58
59
2760class z80ne_state : public driver_device
2861{
2962public:
r9669r9670
3164      : driver_device(machine, config) { }
3265
3366   UINT8 *videoram;
67   UINT8 lx383_scan_counter;
68   UINT8 lx383_key[LX383_KEYS];
69   int lx383_downsampler;
70   int nmi_delay_counter;
71   int reset_delay_counter;
72   running_device *ay31015;
73   UINT8 lx385_ctrl;
74   running_device *lx388_kr2376;
75   emu_timer *cassette_timer;
76   cass_data_t cass_data;
77   wd17xx_state_t wd17xx_state;
3478};
3579
3680
src/mess/includes/mac.h
r9669r9670
157157VIDEO_RESET(macrbv);
158158VIDEO_RESET(maceagle);
159159
160void mac_set_screen_buffer( int buffer );
161
162160VIDEO_START( mac_cb264 );
163161VIDEO_UPDATE( mac_cb264 );
164162INTERRUPT_GEN( mac_cb264_vbl );
r9669r9670
227225
228226   int m_mouse_bit_x;
229227   int m_mouse_bit_y;
228   int last_mx, last_my;
229   int count_x, count_y;
230   int last_was_x;
231   int screen_buffer;
230232
233   int irq_count, ca1_data, ca2_data;
231234
232235   /* state of rTCEnb and rTCClk lines */
233236   UINT8 m_rtc_rTCEnb;
r9669r9670
288291   int m_scc_interrupt, m_via_interrupt, m_via2_interrupt, m_scsi_interrupt, m_last_taken_interrupt;
289292
290293   // defined in machine/mac.c
291   void v8_resize(running_machine *machine);
292   void set_memory_overlay(running_machine *machine, int overlay);
293   void scc_mouse_irq( running_machine *machine, int x, int y );
294   void nubus_slot_interrupt(running_machine *machine, UINT8 slot, UINT32 state);
295   void set_scc_interrupt(running_machine *machine, int value);
296   void set_via_interrupt(running_machine *machine, int value);
297   void set_via2_interrupt(running_machine *machine, int value);
298   void field_interrupts(running_machine *machine);
294   void v8_resize();
295   void set_memory_overlay(int overlay);
296   void scc_mouse_irq( int x, int y );
297   void nubus_slot_interrupt(UINT8 slot, UINT32 state);
298   void set_scc_interrupt(int value);
299   void set_via_interrupt(int value);
300   void set_via2_interrupt(int value);
301   void field_interrupts();
299302   void rtc_write_rTCEnb(int data);
300303   void rtc_shift_data(int data);
301   void vblank_irq(running_machine *machine);
304   void vblank_irq();
302305   void rtc_incticks();
303   void adb_talk(running_machine *machine);
306   void adb_talk();
307   void mouse_callback();
304308
305309   DECLARE_READ16_MEMBER ( mac_via_r );
306310   DECLARE_WRITE16_MEMBER ( mac_via_w );
r9669r9670
339343   int has_adb();
340344   void rtc_init();
341345   void rtc_execute_cmd(int data);
342   void adb_reset(running_machine *machine);
343   void adb_vblank(running_machine *machine);
344   int adb_pollkbd(running_machine *machine, int update);
345   int adb_pollmouse(running_machine *machine);
346   void adb_accummouse( running_machine *machine, UINT8 *MouseX, UINT8 *MouseY );
346   void adb_reset();
347   void adb_vblank();
348   int adb_pollkbd(int update);
349   int adb_pollmouse();
350   void adb_accummouse( UINT8 *MouseX, UINT8 *MouseY );
347351
348352
349353   // ADB mouse state
r9669r9670
353357   // ADB keyboard state
354358   int m_adb_keybaddr;
355359   int m_adb_keybinitialized, m_adb_currentkeys[2], m_adb_modifiers;
360public:
361   emu_timer *scanline_timer;
362   emu_timer *adb_timer;
356363};
357364
358365#endif /* MAC_H_ */
src/mess/includes/pokemini.h
r9669r9670
77#ifndef POKEMINI_H_
88#define POKEMINI_H_
99
10typedef struct
11{
12   UINT8      colors_inverted;
13   UINT8      background_enabled;
14   UINT8      sprites_enabled;
15   UINT8      copy_enabled;
16   UINT8      map_size;
17   UINT8      map_size_x;
18   UINT8      frame_count;
19   UINT8      max_frame_count;
20   UINT32      bg_tiles;
21   UINT32      spr_tiles;
22   UINT8      count;
23   emu_timer   *count_timer;
24} PRC;
1025
26
27typedef struct
28{
29   emu_timer   *seconds_timer;
30   emu_timer   *hz256_timer;
31   emu_timer   *timer1;            /* Timer 1 low or 16bit */
32   emu_timer   *timer1_hi;            /* Timer 1 hi */
33   emu_timer   *timer2;            /* Timer 2 low or 16bit */
34   emu_timer   *timer2_hi;            /* Timer 2 high */
35   emu_timer   *timer3;            /* Timer 3 low or 16bit */
36   emu_timer   *timer3_hi;            /* Timer 3 high */
37} TIMERS;
38
39
40class pokemini_state : public driver_device
41{
42public:
43   pokemini_state(running_machine &machine, const driver_device_config_base &config)
44      : driver_device(machine, config) { }
45
46   UINT8 *ram;
47   UINT8 pm_reg[0x100];
48   PRC prc;
49   TIMERS timers;
50};
51
52
1153/*----------- defined in machine/pokemini.c -----------*/
1254
13extern UINT8 *pokemini_ram;
1455MACHINE_START( pokemini );
1556WRITE8_DEVICE_HANDLER( pokemini_hwreg_w );
1657READ8_DEVICE_HANDLER( pokemini_hwreg_r );
src/mess/includes/lynx.h
r9669r9670
1414#define LYNX_QUICKLOAD   1
1515
1616
17class lynx_state;
18typedef struct
19{
20   UINT8 *mem;
21   // global
22   UINT16 screen;
23   UINT16 colbuf;
24   UINT16 colpos; // byte where value of collision is written
25   UINT16 xoff, yoff;
26   // in command
27   int mode;
28   UINT16 cmd;
29   UINT8 spritenr;
30   int x,y;
31   UINT16 width, height; // uint16 important for blue lightning
32   UINT16 stretch, tilt; // uint16 important
33   UINT8 color[16]; // or stored
34   void (*line_function)(lynx_state *state, const int y, const int xdir);
35   UINT16 bitmap;
36
37   int everon;
38   int memory_accesses;
39   attotime time;
40} BLITTER;
41
42typedef struct
43{
44   UINT8 serctl;
45   UINT8 data_received, data_to_send, buffer;
46
47   int received;
48   int sending;
49   int buffer_loaded;
50} UART;
51
52typedef struct
53{
54   UINT8 data[0x100];
55   int accumulate_overflow;
56   UINT8 high;
57   int low;
58} SUZY;
59
60typedef struct
61{
62   UINT8 data[0x100];
63} MIKEY;
64
65typedef struct
66{
67   UINT8   bakup;
68   UINT8   cntrl1;
69   UINT8   cntrl2;
70   int      counter;
71   emu_timer   *timer;
72   int      timer_active;
73} LYNX_TIMER;
74
75#define NR_LYNX_TIMERS   8
76
77class lynx_state : public driver_device
78{
79public:
80   lynx_state(running_machine &machine, const driver_device_config_base &config)
81      : driver_device(machine, config) { }
82
83   UINT8 *mem_0000;
84   UINT8 *mem_fc00;
85   UINT8 *mem_fd00;
86   UINT8 *mem_fe00;
87   UINT8 *mem_fffa;
88   size_t mem_fe00_size;
89   UINT16 granularity;
90   int line;
91   int line_y;
92   int sign_AB;
93   int sign_CD;
94   UINT32 palette[0x10];
95   int rotate0;
96   int rotate;
97   running_device *audio;
98   SUZY suzy;
99   BLITTER blitter;
100   UINT8 memory_config;
101   UINT8 sprite_collide;
102   MIKEY mikey;
103   int height;
104   int width;
105   LYNX_TIMER timer[NR_LYNX_TIMERS];
106   UART uart;
107};
108
109
17110/*----------- defined in machine/lynx.c -----------*/
18111
19112MACHINE_START( lynx );
20113
21extern UINT8 *lynx_mem_0000;
22extern UINT8 *lynx_mem_fc00;
23extern UINT8 *lynx_mem_fd00;
24extern UINT8 *lynx_mem_fe00;
25extern UINT8 *lynx_mem_fffa;
26extern size_t lynx_mem_fe00_size;
27114
28115READ8_HANDLER( lynx_memory_config_r );
29116WRITE8_HANDLER( lynx_memory_config_w );
src/mess/includes/x68k.h
r9669r9670
3535   MFP_IRQ_GPIP7
3636};  // MC68901 IRQ priority levels
3737
38struct x68k_system
38class x68k_state : public driver_device
3939{
40public:
41   x68k_state(running_machine &machine, const driver_device_config_base &config)
42      : driver_device(machine, config),
43        m_nvram(*this, "nvram") { }
44
45   required_shared_ptr<UINT16>   m_nvram;
4046   struct
4147   {
4248      int sram_writeprotect;
r9669r9670
197203      int seq2;  // part of 6-button input sequence.
198204      emu_timer* io_timeout2;
199205   } mdctrl;
206   UINT16* sram;
207   UINT8 ppi_port[3];
208   int current_vector[8];
209   UINT8 current_irq_line;
210   unsigned int scanline;
211   int led_state;
212   emu_timer* kb_timer;
213   emu_timer* mouse_timer;
214   emu_timer* led_timer;
215   unsigned char scc_prev;
216   UINT16 ppi_prev;
217   int mfp_prev;
218   emu_timer* scanline_timer;
219   emu_timer* raster_irq;
220   emu_timer* vblank_irq;
221   UINT16* gvram;
222   UINT16* tvram;
223   UINT16* spriteram;
224   UINT16* spritereg;
225   tilemap_t* bg0_8;
226   tilemap_t* bg1_8;
227   tilemap_t* bg0_16;
228   tilemap_t* bg1_16;
229   int sprite_shift;
230   int oddscanline;
200231};
201232
202233
203class x68k_state : public driver_device
204{
205public:
206   x68k_state(running_machine &machine, const driver_device_config_base &config)
207      : driver_device(machine, config),
208        m_nvram(*this, "nvram") { }
209
210   required_shared_ptr<UINT16>   m_nvram;
211};
212
213
214234/*----------- defined in drivers/x68k.c -----------*/
215235
216extern struct x68k_system x68k_sys;
217
218extern emu_timer* x68k_scanline_timer;
219extern emu_timer* x68k_raster_irq;
220extern emu_timer* x68k_vblank_irq;
221
222236#ifdef UNUSED_FUNCTION
223237void mfp_trigger_irq(int);
224238TIMER_CALLBACK(mfp_timer_a_callback);
r9669r9670
229243
230244/*----------- defined in video/x68k.c -----------*/
231245
232extern UINT16* x68k_gvram;  // Graphic VRAM
233extern UINT16* x68k_tvram;  // Text VRAM
234extern UINT16* x68k_spriteram;  // sprite/background RAM
235extern UINT16* x68k_spritereg;  // sprite/background registers
236
237246TIMER_CALLBACK(x68k_crtc_raster_irq);
238247TIMER_CALLBACK(x68k_crtc_vblank_irq);
239248TIMER_CALLBACK(x68k_hsync);
src/mess/includes/super80.h
r9669r9670
1616      : driver_device(machine, config) { }
1717
1818   UINT8 super80_shared;
19   running_device *z80pio;
20   running_device *speaker;
21   running_device *cassette;
22   running_device *printer;
23   UINT8 keylatch;
24   UINT8 cass_data[4];
25   UINT8 int_sw;
26   UINT8 last_data;
27   UINT16 vidpg;
28   UINT8 current_palette;
29   UINT8 current_charset;
30   const UINT8 *FNT;
31   UINT8 s_options;
32   UINT8 mc6845_cursor[16];
33   UINT8 mc6845_reg[32];
34   UINT8 mc6845_ind;
35   running_device *mc6845;
36   UINT8 framecnt;
37   UINT8 speed;
38   UINT8 flash;
39   UINT16 cursor;
40   UINT8 *videoram;
41   UINT8 *colorram;
42   UINT8 *pcgram;
1943};
2044
2145
src/mess/includes/pet.h
r9669r9670
1212#include "machine/6522via.h"
1313#include "devices/cartslot.h"
1414
15typedef struct
16{
17   int bank; /* rambank to be switched in 0x9000 */
18   int rom; /* rom socket 6502? at 0x9000 */
19} spet_t;
20
21
1522class pet_state : public driver_device
1623{
1724public:
r9669r9670
2633   int pia1_irq;
2734   int via_irq;
2835   UINT8 *videoram;
36   int font;
37   UINT8 *memory;
38   UINT8 *supermemory;
39   UINT8 *pet80_bank1_base;
40   int keyline_select;
41   emu_timer *datasette1_timer;
42   emu_timer *datasette2_timer;
43   spet_t spet;
44   int pia_level;
2945};
3046
3147/*----------- defined in video/pet.c -----------*/
r9669r9670
4258
4359/*----------- defined in machine/pet.c -----------*/
4460
45extern int pet_font;
4661extern const via6522_interface pet_via;
4762extern const pia6821_interface pet_pia0;
4863extern const pia6821_interface petb_pia0;
4964extern const pia6821_interface pet_pia1;
5065
51extern UINT8 *pet_memory;
52extern UINT8 *superpet_memory;
5366
5467WRITE8_HANDLER(cbm8096_w);
5568extern READ8_HANDLER(superpet_r);
src/mess/includes/oric.h
r9669r9670
1010#include "machine/6522via.h"
1111#include "machine/wd17xx.h"
1212
13enum
14{
15   TELESTRAT_MEM_BLOCK_UNDEFINED,
16   TELESTRAT_MEM_BLOCK_RAM,
17   TELESTRAT_MEM_BLOCK_ROM
18};
19
20typedef struct
21{
22   int      MemType;
23   unsigned char *ptr;
24} telestrat_mem_block;
25
26/* current state of the display */
27/* some attributes persist until they are turned off.
28This structure holds this persistant information */
29typedef struct
30{
31   /* foreground and background colour used for rendering */
32   /* if flash attribute is set, these two will both be equal
33    to background colour */
34   int active_foreground_colour;
35   int active_background_colour;
36   /* current foreground and background colour */
37   int foreground_colour;
38   int background_colour;
39   int mode;
40   /* text attributes */
41   int text_attributes;
42
43   unsigned long read_addr;
44
45   /* current addr to fetch data */
46   unsigned char *char_data;
47   /* base of char data */
48   unsigned char *char_base;
49
50   /* if (1<<3), display graphics, if 0, hide graphics */
51   int flash_state;
52   /* current count */
53   int flash_count;
54} oric_vh_state;
55
56
57class oric_state : public driver_device
58{
59public:
60   oric_state(running_machine &machine, const driver_device_config_base &config)
61      : driver_device(machine, config) { }
62
63   UINT8 *ram;
64   int is_telestrat;
65   unsigned char irqs;
66   char *ram_0x0c000;
67   int keyboard_line;
68   char key_sense_bit;
69   char keyboard_mask;
70   unsigned char via_port_a_data;
71   char psg_control;
72   unsigned char previous_portb_data;
73   unsigned char port_3fa_w;
74   unsigned char port_3fb_w;
75   unsigned char wd179x_int_state;
76   unsigned char port_314_r;
77   unsigned char port_318_r;
78   unsigned char port_314_w;
79   unsigned char telestrat_bank_selection;
80   unsigned char telestrat_via2_port_a_data;
81   unsigned char telestrat_via2_port_b_data;
82   telestrat_mem_block telestrat_blocks[8];
83   oric_vh_state vh_state;
84};
85
86
1387/*----------- defined in machine/oric.c -----------*/
1488
1589extern const via6522_interface oric_6522_interface;
r9669r9670
2296WRITE8_HANDLER( oric_IO_w );
2397READ8_HANDLER( oric_microdisc_r );
2498WRITE8_HANDLER( oric_microdisc_w );
25extern UINT8 *oric_ram;
2699
27100WRITE8_HANDLER(oric_psg_porta_write);
28101
src/mess/includes/nascom1.h
r9669r9670
1010#include "devices/snapquik.h"
1111#include "machine/wd17xx.h"
1212
13typedef struct
14{
15   UINT8   stat_flags;
16   UINT8   stat_count;
17} nascom1_portstat_t;
1318
19typedef struct
20{
21   UINT8 select;
22   UINT8 irq;
23   UINT8 drq;
24} nascom2_fdc_t;
25
26
1427class nascom1_state : public driver_device
1528{
1629public:
r9669r9670
1831      : driver_device(machine, config) { }
1932
2033   UINT8 *videoram;
34   running_device *hd6402;
35   int tape_size;
36   UINT8 *tape_image;
37   int tape_index;
38   nascom1_portstat_t portstat;
39   nascom2_fdc_t nascom2_fdc;
2140};
2241
2342
src/mess/includes/vc4000.h
r9669r9670
1414#define ANALOG_HACK
1515
1616
17typedef struct
18{
19   UINT8 bitmap[10],x1,x2,y1,y2, res1, res2;
20} SPRITE_HELPER;
21
22typedef struct
23{
24   const SPRITE_HELPER *data;
25   int mask;
26   int state;
27   int delay;
28   int size;
29   int y;
30   UINT8 scolor;
31   int finished;
32   int finished_now;
33} SPRITE;
34
35typedef struct
36{
37   SPRITE sprites[4];
38   int line;
39   UINT8 sprite_collision;
40   UINT8 background_collision;
41   union
42   {
43      UINT8 data[0x100];
44      struct
45      {
46         SPRITE_HELPER sprites[3];
47         UINT8 res[0x10];
48         SPRITE_HELPER sprite4;
49         UINT8 res2[0x30];
50         UINT8 grid[20][2];
51         UINT8 grid_control[5];
52         UINT8 res3[0x13];
53         UINT8 sprite_sizes;
54         UINT8 sprite_colors[2];
55         UINT8 score_control;
56         UINT8 res4[2];
57         UINT8 background;
58         UINT8 sound;
59         UINT8 bcd[2];
60         UINT8 background_collision;
61         UINT8 sprite_collision;
62      } d;
63   } reg;
64
65   bitmap_t *bitmap;
66} vc4000_video_t;
67
68class vc4000_state : public driver_device
69{
70public:
71   vc4000_state(running_machine &machine, const driver_device_config_base &config)
72      : driver_device(machine, config) { }
73
74   vc4000_video_t video;
75   UINT8 sprite_collision[0x20];
76   UINT8 background_collision[0x20];
77   UINT8 joy1_x;
78   UINT8 joy1_y;
79   UINT8 joy2_x;
80   UINT8 joy2_y;
81   UINT8 objects[256];
82   UINT8 irq_pause;
83};
84
85
1786/*----------- defined in video/vc4000.c -----------*/
1887
1988extern INTERRUPT_GEN( vc4000_video_line );
src/mess/drivers/pokemini.c
r9669r9670
1717
1818static ADDRESS_MAP_START( pokemini_mem_map, ADDRESS_SPACE_PROGRAM, 8 )
1919   AM_RANGE( 0x000000, 0x000FFF )  AM_ROM                     /* bios */
20   AM_RANGE( 0x001000, 0x001FFF )   AM_RAM AM_BASE( &pokemini_ram)            /* VRAM/RAM */
20   AM_RANGE( 0x001000, 0x001FFF )   AM_RAM AM_BASE_MEMBER(pokemini_state, ram)            /* VRAM/RAM */
2121   AM_RANGE( 0x002000, 0x0020FF )  AM_DEVREADWRITE( "i2cmem", pokemini_hwreg_r, pokemini_hwreg_w )   /* hardware registers */
2222   AM_RANGE( 0x002100, 0x1FFFFF )  AM_ROM                     /* cartridge area */
2323ADDRESS_MAP_END
r9669r9670
5757       I2CMEM_SLAVE_ADDRESS, 0, 0x2000
5858};
5959
60static MACHINE_CONFIG_START( pokemini, driver_device )
60static MACHINE_CONFIG_START( pokemini, pokemini_state )
6161   /* basic machine hardware */
6262   MDRV_CPU_ADD( "maincpu", MINX, 4000000 )
6363   MDRV_CPU_PROGRAM_MAP( pokemini_mem_map)
src/mess/drivers/zexall.c
r9669r9670
2323#include "cpu/z80/z80.h"
2424#include "machine/terminal.h"
2525
26/* Defines */
2726
28/* Components */
29static UINT8 *main_ram;
27class zexall_state : public driver_device
28{
29public:
30   zexall_state(running_machine &machine, const driver_device_config_base &config)
31      : driver_device(machine, config) { }
3032
31static struct
32{
33   UINT8 *main_ram;
3334   UINT8 data[8]; // unused; to suppress the scalar initializer warning
3435   UINT8 out_data; // byte written to 0xFFFF
3536   UINT8 out_req; // byte written to 0xFFFE
3637   UINT8 out_req_last; // old value at 0xFFFE before the most recent write
3738   UINT8 out_ack; // byte written to 0xFFFC
38} zexall={ {0}};
39};
3940
41
42/* Defines */
43
44/* Components */
45
4046/* Devices */
4147
4248static DRIVER_INIT( zexall )
4349{
44   zexall.out_ack = 0;
45   zexall.out_req = 0;
46   zexall.out_req_last = 0;
47   zexall.out_data = 0;
50   zexall_state *state = machine->driver_data<zexall_state>();
51   state->out_ack = 0;
52   state->out_req = 0;
53   state->out_req_last = 0;
54   state->out_data = 0;
4855}
4956
5057static MACHINE_RESET( zexall )
5158{
59   zexall_state *state = machine->driver_data<zexall_state>();
5260   UINT8 *rom = memory_region(machine, "romcode");
53   UINT8 *ram = main_ram;
61   UINT8 *ram = state->main_ram;
5462   int i;
5563    /* fill main ram with zexall code */
5664    for (i = 0; i < 0x228a; i++)
r9669r9670
6068
6169static READ8_HANDLER( zexall_output_ack_r )
6270{
71   zexall_state *state = space->machine->driver_data<zexall_state>();
6372   running_device *devconf = space->machine->device("terminal");
6473// spit out the byte in out_byte if out_req is not equal to out_req_last
65   if (zexall.out_req != zexall.out_req_last)
74   if (state->out_req != state->out_req_last)
6675   {
67   terminal_write(devconf,0,zexall.out_data);
68   fprintf(stderr,"%c",zexall.out_data);
69   zexall.out_req_last = zexall.out_req;
70   zexall.out_ack++;
76   terminal_write(devconf,0,state->out_data);
77   fprintf(stderr,"%c",state->out_data);
78   state->out_req_last = state->out_req;
79   state->out_ack++;
7180   }
72   return zexall.out_ack;
81   return state->out_ack;
7382}
7483
7584static WRITE8_HANDLER( zexall_output_ack_w )
7685{
77   zexall.out_ack = data;
86   zexall_state *state = space->machine->driver_data<zexall_state>();
87   state->out_ack = data;
7888}
7989
8090static READ8_HANDLER( zexall_output_req_r )
8191{
82   return zexall.out_req;
92   zexall_state *state = space->machine->driver_data<zexall_state>();
93   return state->out_req;
8394}
8495
8596static WRITE8_HANDLER( zexall_output_req_w )
8697{
87   zexall.out_req_last = zexall.out_req;
88   zexall.out_req = data;
98   zexall_state *state = space->machine->driver_data<zexall_state>();
99   state->out_req_last = state->out_req;
100   state->out_req = data;
89101}
90102
91103static READ8_HANDLER( zexall_output_data_r )
92104{
93   return zexall.out_data;
105   zexall_state *state = space->machine->driver_data<zexall_state>();
106   return state->out_data;
94107}
95108
96109static WRITE8_HANDLER( zexall_output_data_w )
97110{
98   zexall.out_data = data;
111   zexall_state *state = space->machine->driver_data<zexall_state>();
112   state->out_data = data;
99113}
100114
101115/******************************************************************************
r9669r9670
104118
105119static ADDRESS_MAP_START(z80_mem, ADDRESS_SPACE_PROGRAM, 8)
106120    ADDRESS_MAP_UNMAP_HIGH
107    AM_RANGE(0x0000, 0xfffc) AM_RAM AM_BASE(&main_ram)
121    AM_RANGE(0x0000, 0xfffc) AM_RAM AM_BASE_MEMBER(zexall_state, main_ram)
108122   AM_RANGE(0xfffd, 0xfffd) AM_READWRITE(zexall_output_ack_r,zexall_output_ack_w)
109123   AM_RANGE(0xfffe, 0xfffe) AM_READWRITE(zexall_output_req_r,zexall_output_req_w)
110124   AM_RANGE(0xffff, 0xffff) AM_READWRITE(zexall_output_data_r,zexall_output_data_w)
r9669r9670
135149   DEVCB_HANDLER(null_kbd_put)
136150};
137151
138static MACHINE_CONFIG_START( zexall, driver_device )
152static MACHINE_CONFIG_START( zexall, zexall_state )
139153    /* basic machine hardware */
140154    MDRV_CPU_ADD("maincpu", Z80, XTAL_3_579545MHz*10)
141155    MDRV_CPU_PROGRAM_MAP(z80_mem)
src/mess/drivers/pet.c
r9669r9670
459459
460460*/
461461static ADDRESS_MAP_START( superpet_mem , ADDRESS_SPACE_PROGRAM, 8)
462   AM_RANGE(0x0000, 0x7fff) AM_RAM AM_SHARE("share1") AM_BASE(&pet_memory)
462   AM_RANGE(0x0000, 0x7fff) AM_RAM AM_SHARE("share1") AM_BASE_MEMBER(pet_state, memory)
463463   AM_RANGE(0x8000, 0x87ff) AM_RAM AM_SHARE("share2") AM_BASE_MEMBER(pet_state, videoram)
464464   AM_RANGE(0xa000, 0xe7ff) AM_ROM
465465   AM_RANGE(0xe810, 0xe813) AM_DEVREADWRITE("pia_0", pia6821_r, pia6821_w)
src/mess/drivers/oric.c
r9669r9670
5858
5959
6060static ADDRESS_MAP_START(oric_mem, ADDRESS_SPACE_PROGRAM, 8)
61    AM_RANGE( 0x0000, 0xbfff) AM_RAM AM_BASE( &oric_ram )
61    AM_RANGE( 0x0000, 0xbfff) AM_RAM AM_BASE_MEMBER(oric_state, ram )
6262    AM_RANGE( 0xc000, 0xdfff) AM_READ_BANK("bank1") AM_WRITE_BANK("bank5")
6363   AM_RANGE( 0xe000, 0xf7ff) AM_READ_BANK("bank2") AM_WRITE_BANK("bank6")
6464   AM_RANGE( 0xf800, 0xffff) AM_READ_BANK("bank3") AM_WRITE_BANK("bank7")
r9669r9670
385385   NULL
386386};
387387
388static MACHINE_CONFIG_START( oric, driver_device )
388static MACHINE_CONFIG_START( oric, oric_state )
389389   /* basic machine hardware */
390390   MDRV_CPU_ADD("maincpu", M6502, 1000000)
391391   MDRV_CPU_PROGRAM_MAP(oric_mem)
src/mess/drivers/mz2500.c
r9669r9670
20482048   }
20492049};
20502050
2051static void mz2500_rtc_alarm_irq(int state)
2051static void mz2500_rtc_alarm_irq(running_machine *machine, int state)
20522052{
20532053   //mz2500_state *drvstate = device->machine->driver_data<mz2500_state>();
20542054   /* TODO: doesn't work yet */
src/mess/drivers/wswan.c
r9669r9670
124124   }
125125}
126126
127static MACHINE_CONFIG_START( wswan, driver_device )
127static MACHINE_CONFIG_START( wswan, wswan_state )
128128   /* Basic machine hardware */
129129   MDRV_CPU_ADD("maincpu", V30MZ, 3072000)
130130   MDRV_CPU_PROGRAM_MAP(wswan_mem)
src/mess/drivers/zx.c
r9669r9670
383383};
384384
385385
386static MACHINE_CONFIG_START( zx80, driver_device )
386static MACHINE_CONFIG_START( zx80, zx_state )
387387   /* basic machine hardware */
388388   MDRV_CPU_ADD("maincpu", Z80, ZX81_CPU_CLOCK)
389389   MDRV_CPU_PROGRAM_MAP(zx80_map)
src/mess/drivers/mac.c
r9669r9670
7676   if ((mac->m_rbv_regs[0x12] & 0x40) && (mac->m_rbv_ier & 0x2))   
7777   {
7878      mac->m_rbv_ifr |= 0x82;
79      mac->set_via2_interrupt(device->machine, 1);
79      mac->set_via2_interrupt(1);
8080   }
8181}
8282
r9669r9670
256256            if (((data & 0xc0) != (m_rbv_regs[1] & 0xc0)) && (m_rbv_type == RBV_TYPE_V8))
257257            {
258258               m_rbv_regs[1] = data;
259               v8_resize(space.machine);
259               this->v8_resize();
260260            }
261261            break;
262262
r9669r9670
272272            break;
273273
274274         case 0x03:
275            set_via2_interrupt(space.machine, 0);
275            this->set_via2_interrupt(0);
276276            m_rbv_regs[offset] = data;
277277            break;
278278
r9669r9670
323323         case 13:   // IFR
324324//            printf("rbv_w: %02x to IFR\n", data);
325325            m_rbv_ifr = data;
326            set_via2_interrupt(space.machine, 0);
326            this->set_via2_interrupt(0);
327327            break;
328328
329329         case 14:   // IER
src/mess/drivers/lynx.c
r9669r9670
1515static QUICKLOAD_LOAD( lynx );
1616
1717static ADDRESS_MAP_START( lynx_mem , ADDRESS_SPACE_PROGRAM, 8)
18   AM_RANGE(0x0000, 0xfbff) AM_RAM AM_BASE(&lynx_mem_0000)
19   AM_RANGE(0xfc00, 0xfcff) AM_RAM AM_BASE(&lynx_mem_fc00)
20   AM_RANGE(0xfd00, 0xfdff) AM_RAM AM_BASE(&lynx_mem_fd00)
21   AM_RANGE(0xfe00, 0xfff7) AM_READ_BANK("bank3") AM_WRITEONLY AM_BASE(&lynx_mem_fe00) AM_SIZE(&lynx_mem_fe00_size)
18   AM_RANGE(0x0000, 0xfbff) AM_RAM AM_BASE_MEMBER(lynx_state, mem_0000)
19   AM_RANGE(0xfc00, 0xfcff) AM_RAM AM_BASE_MEMBER(lynx_state, mem_fc00)
20   AM_RANGE(0xfd00, 0xfdff) AM_RAM AM_BASE_MEMBER(lynx_state, mem_fd00)
21   AM_RANGE(0xfe00, 0xfff7) AM_READ_BANK("bank3") AM_WRITEONLY AM_BASE_MEMBER(lynx_state, mem_fe00) AM_SIZE_MEMBER(lynx_state, mem_fe00_size)
2222   AM_RANGE(0xfff8, 0xfff8) AM_RAM
2323   AM_RANGE(0xfff9, 0xfff9) AM_READWRITE(lynx_memory_config_r, lynx_memory_config_w)
24   AM_RANGE(0xfffa, 0xffff) AM_READ_BANK("bank4") AM_WRITEONLY AM_BASE(&lynx_mem_fffa)
24   AM_RANGE(0xfffa, 0xffff) AM_READ_BANK("bank4") AM_WRITEONLY AM_BASE_MEMBER(lynx_state, mem_fffa)
2525ADDRESS_MAP_END
2626
2727static INPUT_PORTS_START( lynx )
r9669r9670
6161}
6262
6363
64static MACHINE_CONFIG_START( lynx, driver_device )
64static MACHINE_CONFIG_START( lynx, lynx_state )
6565   /* basic machine hardware */
6666   MDRV_CPU_ADD("maincpu", M65SC02, 4000000)        /* vti core, integrated in vlsi, stz, but not bbr bbs */
6767   MDRV_CPU_PROGRAM_MAP(lynx_mem)
src/mess/drivers/x68k.c
r9669r9670
139139#include "x68000.lh"
140140
141141
142struct x68k_system x68k_sys;
143142
144static UINT16* sram;   // SRAM
145static UINT8 ppi_port[3];
146static int current_vector[8];
147static UINT8 current_irq_line;
148static unsigned int x68k_scanline;
149static int led_state;
150
151static emu_timer* kb_timer;
152143//emu_timer* mfp_timer[4];
153144//emu_timer* mfp_irq;
154emu_timer* x68k_scanline_timer;
155emu_timer* x68k_raster_irq;
156emu_timer* x68k_vblank_irq;
157static emu_timer* mouse_timer;  // to set off the mouse interrupts via the SCC
158static emu_timer* led_timer;  // to make disk drive control LEDs blink
159145
160146// MFP is clocked at 4MHz, so at /4 prescaler the timer is triggered after 1us (4 cycles)
161147// No longer necessary with the new MFP core
r9669r9670
178164}
179165#endif
180166
181static void mfp_init(void);
182//static TIMER_CALLBACK(mfp_update_irq);
183
184static void mfp_init()
167static void mfp_init(running_machine *machine)
185168{
186   x68k_sys.mfp.tadr = x68k_sys.mfp.tbdr = x68k_sys.mfp.tcdr = x68k_sys.mfp.tddr = 0xff;
169   x68k_state *state = machine->driver_data<x68k_state>();
170   state->mfp.tadr = state->mfp.tbdr = state->mfp.tcdr = state->mfp.tddr = 0xff;
187171
188   x68k_sys.mfp.irqline = 6;  // MFP is connected to 68000 IRQ line 6
189   x68k_sys.mfp.current_irq = -1;  // No current interrupt
172   state->mfp.irqline = 6;  // MFP is connected to 68000 IRQ line 6
173   state->mfp.current_irq = -1;  // No current interrupt
190174
191175#if 0
192176    mfp_timer[0] = timer_alloc(machine, mfp_timer_a_callback, NULL);
r9669r9670
201185#ifdef UNUSED_FUNCTION
202186TIMER_CALLBACK(mfp_update_irq)
203187{
188   x68k_state *state = machine->driver_data<x68k_state>();
204189    int x;
205190
206    if((x68k_sys.ioc.irqstatus & 0xc0) != 0)
191    if((state->ioc.irqstatus & 0xc0) != 0)
207192        return;
208193
209194    // check for pending IRQs, in priority order
210    if(x68k_sys.mfp.ipra != 0)
195    if(state->mfp.ipra != 0)
211196    {
212197        for(x=7;x>=0;x--)
213198        {
214            if((x68k_sys.mfp.ipra & (1 << x)) && (x68k_sys.mfp.imra & (1 << x)))
199            if((state->mfp.ipra & (1 << x)) && (state->mfp.imra & (1 << x)))
215200            {
216                current_irq_line = x68k_sys.mfp.irqline;
217                x68k_sys.mfp.current_irq = x + 8;
201                state->current_irq_line = state->mfp.irqline;
202                state->mfp.current_irq = x + 8;
218203                // assert IRQ line
219//              if(x68k_sys.mfp.iera & (1 << x))
204//              if(state->mfp.iera & (1 << x))
220205                {
221                    current_vector[6] = (x68k_sys.mfp.vr & 0xf0) | (x+8);
222                    cputag_set_input_line_and_vector(machine, "maincpu",x68k_sys.mfp.irqline,ASSERT_LINE,(x68k_sys.mfp.vr & 0xf0) | (x + 8));
223//                  logerror("MFP: Sent IRQ vector 0x%02x (IRQ line %i)\n",(x68k_sys.mfp.vr & 0xf0) | (x+8),x68k_sys.mfp.irqline);
206                    state->current_vector[6] = (state->mfp.vr & 0xf0) | (x+8);
207                    cputag_set_input_line_and_vector(machine, "maincpu",state->mfp.irqline,ASSERT_LINE,(state->mfp.vr & 0xf0) | (x + 8));
208//                  logerror("MFP: Sent IRQ vector 0x%02x (IRQ line %i)\n",(state->mfp.vr & 0xf0) | (x+8),state->mfp.irqline);
224209                    return;  // one at a time only
225210                }
226211            }
227212        }
228213    }
229    if(x68k_sys.mfp.iprb != 0)
214    if(state->mfp.iprb != 0)
230215    {
231216        for(x=7;x>=0;x--)
232217        {
233            if((x68k_sys.mfp.iprb & (1 << x)) && (x68k_sys.mfp.imrb & (1 << x)))
218            if((state->mfp.iprb & (1 << x)) && (state->mfp.imrb & (1 << x)))
234219            {
235                current_irq_line = x68k_sys.mfp.irqline;
236                x68k_sys.mfp.current_irq = x;
220                state->current_irq_line = state->mfp.irqline;
221                state->mfp.current_irq = x;
237222                // assert IRQ line
238//              if(x68k_sys.mfp.ierb & (1 << x))
223//              if(state->mfp.ierb & (1 << x))
239224                {
240                    current_vector[6] = (x68k_sys.mfp.vr & 0xf0) | x;
241                    cputag_set_input_line_and_vector(machine, "maincpu",x68k_sys.mfp.irqline,ASSERT_LINE,(x68k_sys.mfp.vr & 0xf0) | x);
242//                  logerror("MFP: Sent IRQ vector 0x%02x (IRQ line %i)\n",(x68k_sys.mfp.vr & 0xf0) | x,x68k_sys.mfp.irqline);
225                    state->current_vector[6] = (state->mfp.vr & 0xf0) | x;
226                    cputag_set_input_line_and_vector(machine, "maincpu",state->mfp.irqline,ASSERT_LINE,(state->mfp.vr & 0xf0) | x);
227//                  logerror("MFP: Sent IRQ vector 0x%02x (IRQ line %i)\n",(state->mfp.vr & 0xf0) | x,state->mfp.irqline);
243228                    return;  // one at a time only
244229                }
245230            }
r9669r9670
247232    }
248233}
249234
250void mfp_trigger_irq(int irq)
235void mfp_trigger_irq(running_machine *machine, int irq)
251236{
237   x68k_state *state = machine->driver_data<x68k_state>();
252238    // check if interrupt is enabled
253239    if(irq > 7)
254240    {
255        if(!(x68k_sys.mfp.iera & (1 << (irq-8))))
241        if(!(state->mfp.iera & (1 << (irq-8))))
256242            return;  // not enabled, no action taken
257243    }
258244    else
259245    {
260        if(!(x68k_sys.mfp.ierb & (1 << irq)))
246        if(!(state->mfp.ierb & (1 << irq)))
261247            return;  // not enabled, no action taken
262248    }
263249
264250    // set requested IRQ as pending
265251    if(irq > 7)
266        x68k_sys.mfp.ipra |= (1 << (irq-8));
252        state->mfp.ipra |= (1 << (irq-8));
267253    else
268        x68k_sys.mfp.iprb |= (1 << irq);
254        state->mfp.iprb |= (1 << irq);
269255
270256    // check for IRQs to be called
271257//  mfp_update_irq(0);
r9669r9670
274260
275261TIMER_CALLBACK(mfp_timer_a_callback)
276262{
277    x68k_sys.mfp.timer[0].counter--;
278    if(x68k_sys.mfp.timer[0].counter == 0)
263   x68k_state *state = machine->driver_data<x68k_state>();
264    state->mfp.timer[0].counter--;
265    if(state->mfp.timer[0].counter == 0)
279266    {
280        x68k_sys.mfp.timer[0].counter = x68k_sys.mfp.tadr;
267        state->mfp.timer[0].counter = state->mfp.tadr;
281268        mfp_trigger_irq(MFP_IRQ_TIMERA);
282269    }
283270}
284271
285272TIMER_CALLBACK(mfp_timer_b_callback)
286273{
287    x68k_sys.mfp.timer[1].counter--;
288    if(x68k_sys.mfp.timer[1].counter == 0)
274   x68k_state *state = machine->driver_data<x68k_state>();
275    state->mfp.timer[1].counter--;
276    if(state->mfp.timer[1].counter == 0)
289277    {
290        x68k_sys.mfp.timer[1].counter = x68k_sys.mfp.tbdr;
278        state->mfp.timer[1].counter = state->mfp.tbdr;
291279            mfp_trigger_irq(MFP_IRQ_TIMERB);
292280    }
293281}
294282
295283TIMER_CALLBACK(mfp_timer_c_callback)
296284{
297    x68k_sys.mfp.timer[2].counter--;
298    if(x68k_sys.mfp.timer[2].counter == 0)
285   x68k_state *state = machine->driver_data<x68k_state>();
286    state->mfp.timer[2].counter--;
287    if(state->mfp.timer[2].counter == 0)
299288    {
300        x68k_sys.mfp.timer[2].counter = x68k_sys.mfp.tcdr;
289        state->mfp.timer[2].counter = state->mfp.tcdr;
301290            mfp_trigger_irq(MFP_IRQ_TIMERC);
302291    }
303292}
304293
305294TIMER_CALLBACK(mfp_timer_d_callback)
306295{
307    x68k_sys.mfp.timer[3].counter--;
308    if(x68k_sys.mfp.timer[3].counter == 0)
296   x68k_state *state = machine->driver_data<x68k_state>();
297    state->mfp.timer[3].counter--;
298    if(state->mfp.timer[3].counter == 0)
309299    {
310        x68k_sys.mfp.timer[3].counter = x68k_sys.mfp.tddr;
300        state->mfp.timer[3].counter = state->mfp.tddr;
311301            mfp_trigger_irq(MFP_IRQ_TIMERD);
312302    }
313303}
r9669r9670
330320// LED timer callback
331321static TIMER_CALLBACK( x68k_led_callback )
332322{
323   x68k_state *state = machine->driver_data<x68k_state>();
333324   int drive;
334   if(led_state == 0)
335      led_state = 1;
325   if(state->led_state == 0)
326      state->led_state = 1;
336327   else
337      led_state = 0;
338   if(led_state == 1)
328      state->led_state = 0;
329   if(state->led_state == 1)
339330   {
340331      for(drive=0;drive<4;drive++)
341         output_set_indexed_value("ctrl_drv",drive,x68k_sys.fdc.led_ctrl[drive] ? 0 : 1);
332         output_set_indexed_value("ctrl_drv",drive,state->fdc.led_ctrl[drive] ? 0 : 1);
342333   }
343334   else
344335   {
r9669r9670
361352   return hd63450_r(device, offset, mem_mask);
362353}
363354
364static void x68k_keyboard_ctrl_w(int data)
355static void x68k_keyboard_ctrl_w(x68k_state *state, int data)
365356{
366357   /* Keyboard control commands:
367358       00xxxxxx - TV Control
r9669r9670
414405
415406   if((data & 0xf8) == 0x48)  // Keyboard enable
416407   {
417      x68k_sys.keyboard.enabled = data & 0x01;
418      logerror("KB: Keyboard enable bit = %i\n",x68k_sys.keyboard.enabled);
408      state->keyboard.enabled = data & 0x01;
409      logerror("KB: Keyboard enable bit = %i\n",state->keyboard.enabled);
419410   }
420411
421412   if((data & 0xf0) == 0x60)  // Key delay time
422413   {
423      x68k_sys.keyboard.delay = data & 0x0f;
414      state->keyboard.delay = data & 0x0f;
424415      logerror("KB: Keypress delay time is now %ims\n",(data & 0x0f)*100+200);
425416   }
426417
427418   if((data & 0xf0) == 0x70)  // Key repeat rate
428419   {
429      x68k_sys.keyboard.repeat = data & 0x0f;
420      state->keyboard.repeat = data & 0x0f;
430421      logerror("KB: Keypress repeat rate is now %ims\n",((data & 0x0f)^2)*5+30);
431422   }
432423
433424}
434425
435static int x68k_keyboard_pop_scancode(void)
426static int x68k_keyboard_pop_scancode(x68k_state *state)
436427{
437428   int ret;
438   if(x68k_sys.keyboard.keynum == 0)  // no scancodes in USART buffer
429   if(state->keyboard.keynum == 0)  // no scancodes in USART buffer
439430      return 0x00;
440431
441   x68k_sys.keyboard.keynum--;
442   ret = x68k_sys.keyboard.buffer[x68k_sys.keyboard.tailpos++];
443   if(x68k_sys.keyboard.tailpos > 15)
444      x68k_sys.keyboard.tailpos = 0;
432   state->keyboard.keynum--;
433   ret = state->keyboard.buffer[state->keyboard.tailpos++];
434   if(state->keyboard.tailpos > 15)
435      state->keyboard.tailpos = 0;
445436
446437   logerror("MFP: Keyboard buffer pop 0x%02x\n",ret);
447438   return ret;
r9669r9670
449440
450441static void x68k_keyboard_push_scancode(running_machine* machine,unsigned char code)
451442{
452   x68k_sys.keyboard.keynum++;
453   if(x68k_sys.keyboard.keynum >= 1)
443   x68k_state *state = machine->driver_data<x68k_state>();
444   state->keyboard.keynum++;
445   if(state->keyboard.keynum >= 1)
454446   { // keyboard buffer full
455      if(x68k_sys.keyboard.enabled != 0)
447      if(state->keyboard.enabled != 0)
456448      {
457         x68k_sys.mfp.rsr |= 0x80;  // Buffer full
449         state->mfp.rsr |= 0x80;  // Buffer full
458450//          mfp_trigger_irq(MFP_IRQ_RX_FULL);
459451         if(input_port_read(machine,"options") & 0x01)
460452         {
461            current_vector[6] = 0x4c;
453            state->current_vector[6] = 0x4c;
462454            cputag_set_input_line_and_vector(machine, "maincpu",6,ASSERT_LINE,0x4c);
463455            logerror("MFP: Receive buffer full IRQ sent\n");
464456         }
465457      }
466458   }
467   x68k_sys.keyboard.buffer[x68k_sys.keyboard.headpos++] = code;
468   if(x68k_sys.keyboard.headpos > 15)
459   state->keyboard.buffer[state->keyboard.headpos++] = code;
460   if(state->keyboard.headpos > 15)
469461   {
470      x68k_sys.keyboard.headpos = 0;
462      state->keyboard.headpos = 0;
471463//      mfp_trigger_irq(MFP_IRQ_RX_ERROR);
472      current_vector[6] = 0x4b;
464      state->current_vector[6] = 0x4b;
473465//      cputag_set_input_line_and_vector(machine, "maincpu",6,ASSERT_LINE,0x4b);
474466   }
475467}
476468
477469static TIMER_CALLBACK(x68k_keyboard_poll)
478470{
471   x68k_state *state = machine->driver_data<x68k_state>();
479472   int x;
480473   static const char *const keynames[] = { "key1", "key2", "key3", "key4" };
481474
482475   for(x=0;x<0x80;x++)
483476   {
484477      // adjust delay/repeat timers
485      if(x68k_sys.keyboard.keytime[x] > 0)
478      if(state->keyboard.keytime[x] > 0)
486479      {
487         x68k_sys.keyboard.keytime[x] -= 5;
480         state->keyboard.keytime[x] -= 5;
488481      }
489482      if(!(input_port_read(machine, keynames[x / 32]) & (1 << (x % 32))))
490483      {
491         if(x68k_sys.keyboard.keyon[x] != 0)
484         if(state->keyboard.keyon[x] != 0)
492485         {
493486            x68k_keyboard_push_scancode(machine,0x80 + x);
494            x68k_sys.keyboard.keytime[x] = 0;
495            x68k_sys.keyboard.keyon[x] = 0;
496            x68k_sys.keyboard.last_pressed = 0;
487            state->keyboard.keytime[x] = 0;
488            state->keyboard.keyon[x] = 0;
489            state->keyboard.last_pressed = 0;
497490            logerror("KB: Released key 0x%02x\n",x);
498491         }
499492      }
500493      // check to see if a key is being held
501      if(x68k_sys.keyboard.keyon[x] != 0 && x68k_sys.keyboard.keytime[x] == 0 && x68k_sys.keyboard.last_pressed == x)
494      if(state->keyboard.keyon[x] != 0 && state->keyboard.keytime[x] == 0 && state->keyboard.last_pressed == x)
502495      {
503         if(input_port_read(machine, keynames[x68k_sys.keyboard.last_pressed / 32]) & (1 << (x68k_sys.keyboard.last_pressed % 32)))
496         if(input_port_read(machine, keynames[state->keyboard.last_pressed / 32]) & (1 << (state->keyboard.last_pressed % 32)))
504497         {
505            x68k_keyboard_push_scancode(machine,x68k_sys.keyboard.last_pressed);
506            x68k_sys.keyboard.keytime[x68k_sys.keyboard.last_pressed] = (x68k_sys.keyboard.repeat^2)*5+30;
507            logerror("KB: Holding key 0x%02x\n",x68k_sys.keyboard.last_pressed);
498            x68k_keyboard_push_scancode(machine,state->keyboard.last_pressed);
499            state->keyboard.keytime[state->keyboard.last_pressed] = (state->keyboard.repeat^2)*5+30;
500            logerror("KB: Holding key 0x%02x\n",state->keyboard.last_pressed);
508501         }
509502      }
510503      if((input_port_read(machine,  keynames[x / 32]) & (1 << (x % 32))))
511504      {
512         if(x68k_sys.keyboard.keyon[x] == 0)
505         if(state->keyboard.keyon[x] == 0)
513506         {
514507            x68k_keyboard_push_scancode(machine,x);
515            x68k_sys.keyboard.keytime[x] = x68k_sys.keyboard.delay * 100 + 200;
516            x68k_sys.keyboard.keyon[x] = 1;
517            x68k_sys.keyboard.last_pressed = x;
508            state->keyboard.keytime[x] = state->keyboard.delay * 100 + 200;
509            state->keyboard.keyon[x] = 1;
510            state->keyboard.last_pressed = x;
518511            logerror("KB: Pushed key 0x%02x\n",x);
519512         }
520513      }
r9669r9670
525518#ifdef UNUSED_FUNCTION
526519void mfp_recv_data(int data)
527520{
528   x68k_sys.mfp.rsr |= 0x80;  // Buffer full
529   x68k_sys.mfp.tsr |= 0x80;
530   x68k_sys.mfp.usart.recv_buffer = 0x00;   // TODO: set up keyboard data
531   x68k_sys.mfp.vector = current_vector[6] = (x68k_sys.mfp.vr & 0xf0) | 0x0c;
521   x68k_state *state = machine->driver_data<x68k_state>();
522   state->mfp.rsr |= 0x80;  // Buffer full
523   state->mfp.tsr |= 0x80;
524   state->mfp.usart.recv_buffer = 0x00;   // TODO: set up keyboard data
525   state->mfp.vector = state->current_vector[6] = (state->mfp.vr & 0xf0) | 0x0c;
532526//  mfp_trigger_irq(MFP_IRQ_RX_FULL);
533527//  logerror("MFP: Receive buffer full IRQ sent\n");
534528}
r9669r9670
539533// typically read from the SCC data port on receive buffer full interrupt per byte
540534static int x68k_read_mouse(running_machine *machine)
541535{
536   x68k_state *state = machine->driver_data<x68k_state>();
542537   running_device *scc = machine->device("scc");
543538   char val = 0;
544539   char ipt = 0;
r9669r9670
546541   if(!(scc8530_get_reg_b(scc,5) & 0x02))
547542      return 0xff;
548543
549   switch(x68k_sys.mouse.inputtype)
544   switch(state->mouse.inputtype)
550545   {
551546   case 0:
552547      ipt = input_port_read(machine, "mouse1");
553548      break;
554549   case 1:
555550      val = input_port_read(machine, "mouse2");
556      ipt = val - x68k_sys.mouse.last_mouse_x;
557      x68k_sys.mouse.last_mouse_x = val;
551      ipt = val - state->mouse.last_mouse_x;
552      state->mouse.last_mouse_x = val;
558553      break;
559554   case 2:
560555      val = input_port_read(machine, "mouse3");
561      ipt = val - x68k_sys.mouse.last_mouse_y;
562      x68k_sys.mouse.last_mouse_y = val;
556      ipt = val - state->mouse.last_mouse_y;
557      state->mouse.last_mouse_y = val;
563558      break;
564559   }
565   x68k_sys.mouse.inputtype++;
566   if(x68k_sys.mouse.inputtype > 2)
560   state->mouse.inputtype++;
561   if(state->mouse.inputtype > 2)
567562   {
568563      int i_val = scc8530_get_reg_b(scc, 0);
569      x68k_sys.mouse.inputtype = 0;
570      x68k_sys.mouse.bufferempty = 1;
564      state->mouse.inputtype = 0;
565      state->mouse.bufferempty = 1;
571566      i_val &= ~0x01;
572567      scc8530_set_reg_b(scc, 0, i_val);
573568      logerror("SCC: mouse buffer empty\n");
r9669r9670
601596   }
602597}
603598
604static unsigned char scc_prev;
605599static WRITE16_HANDLER( x68k_scc_w )
606600{
601   x68k_state *state = space->machine->driver_data<x68k_state>();
607602   running_device *scc = space->machine->device("scc");
608603   offset %= 4;
609604
r9669r9670
611606   {
612607   case 0:
613608      scc8530_w(scc, 0,(UINT8)data);
614      if((scc8530_get_reg_b(scc, 5) & 0x02) != scc_prev)
609      if((scc8530_get_reg_b(scc, 5) & 0x02) != state->scc_prev)
615610      {
616611         if(scc8530_get_reg_b(scc, 5) & 0x02)  // Request to Send
617612         {
618613            int val = scc8530_get_reg_b(scc, 0);
619            x68k_sys.mouse.bufferempty = 0;
614            state->mouse.bufferempty = 0;
620615            val |= 0x01;
621616            scc8530_set_reg_b(scc, 0,val);
622617         }
r9669r9670
632627      scc8530_w(scc, 3,(UINT8)data);
633628      break;
634629   }
635   scc_prev = scc8530_get_reg_b(scc, 5) & 0x02;
630   state->scc_prev = scc8530_get_reg_b(scc, 5) & 0x02;
636631}
637632
638633static TIMER_CALLBACK(x68k_scc_ack)
639634{
635   x68k_state *state = machine->driver_data<x68k_state>();
640636   running_device *scc = machine->device("scc");
641   if(x68k_sys.mouse.bufferempty != 0)  // nothing to do if the mouse data buffer is empty
637   if(state->mouse.bufferempty != 0)  // nothing to do if the mouse data buffer is empty
642638      return;
643639
644//  if((x68k_sys.ioc.irqstatus & 0xc0) != 0)
640//  if((state->ioc.irqstatus & 0xc0) != 0)
645641//      return;
646642
647643   // hard-code the IRQ vector for now, until the SCC code is more complete
r9669r9670
651647      {
652648         if(scc8530_get_reg_b(scc, 5) & 0x02)  // RTS signal
653649         {
654            x68k_sys.mouse.irqactive = 1;
655            current_vector[5] = 0x54;
656            current_irq_line = 5;
650            state->mouse.irqactive = 1;
651            state->current_vector[5] = 0x54;
652            state->current_irq_line = 5;
657653            cputag_set_input_line_and_vector(machine, "maincpu",5,ASSERT_LINE,0x54);
658654         }
659655      }
r9669r9670
662658
663659static void x68k_set_adpcm(running_machine* machine)
664660{
661   x68k_state *state = machine->driver_data<x68k_state>();
665662   running_device *dev = machine->device("hd63450");
666663   UINT32 rate = 0;
667664
668   switch(x68k_sys.adpcm.rate & 0x0c)
665   switch(state->adpcm.rate & 0x0c)
669666   {
670667      case 0x00:
671668         rate = 7812/2;
r9669r9670
680677         logerror("PPI: Invalid ADPCM sample rate set.\n");
681678         rate = 15625/2;
682679   }
683   if(x68k_sys.adpcm.clock != 0)
680   if(state->adpcm.clock != 0)
684681      rate = rate/2;
685682   hd63450_set_timer(dev,3,ATTOTIME_IN_HZ(rate));
686683}
r9669r9670
693690
694691static UINT8 md_3button_r(running_device* device, int port)
695692{
693   x68k_state *state = device->machine->driver_data<x68k_state>();
696694   if(port == 1)
697695   {
698696      UINT8 porta = input_port_read(device->machine,"md3b") & 0xff;
699697      UINT8 portb = (input_port_read(device->machine,"md3b") >> 8) & 0xff;
700      if(x68k_sys.mdctrl.mux1 & 0x10)
698      if(state->mdctrl.mux1 & 0x10)
701699      {
702700         return porta | 0x90;
703701      }
r9669r9670
710708   {
711709      UINT8 porta = (input_port_read(device->machine,"md3b") >> 16) & 0xff;
712710      UINT8 portb = (input_port_read(device->machine,"md3b") >> 24) & 0xff;
713      if(x68k_sys.mdctrl.mux2 & 0x20)
711      if(state->mdctrl.mux2 & 0x20)
714712      {
715713         return porta | 0x90;
716714      }
r9669r9670
725723// Megadrive 6 button gamepad
726724static TIMER_CALLBACK(md_6button_port1_timeout)
727725{
728   x68k_sys.mdctrl.seq1 = 0;
726   x68k_state *state = machine->driver_data<x68k_state>();
727   state->mdctrl.seq1 = 0;
729728}
730729
731730static TIMER_CALLBACK(md_6button_port2_timeout)
732731{
733   x68k_sys.mdctrl.seq2 = 0;
732   x68k_state *state = machine->driver_data<x68k_state>();
733   state->mdctrl.seq2 = 0;
734734}
735735
736736static void md_6button_init(running_machine* machine)
737737{
738   x68k_sys.mdctrl.io_timeout1 = timer_alloc(machine,md_6button_port1_timeout,NULL);
739   x68k_sys.mdctrl.io_timeout2 = timer_alloc(machine,md_6button_port2_timeout,NULL);
738   x68k_state *state = machine->driver_data<x68k_state>();
739   state->mdctrl.io_timeout1 = timer_alloc(machine,md_6button_port1_timeout,NULL);
740   state->mdctrl.io_timeout2 = timer_alloc(machine,md_6button_port2_timeout,NULL);
740741}
741742
742743static UINT8 md_6button_r(running_device* device, int port)
743744{
745   x68k_state *state = device->machine->driver_data<x68k_state>();
744746   if(port == 1)
745747   {
746748      UINT8 porta = input_port_read(device->machine,"md6b") & 0xff;
747749      UINT8 portb = (input_port_read(device->machine,"md6b") >> 8) & 0xff;
748750      UINT8 extra = input_port_read(device->machine,"md6b_extra") & 0x0f;
749751
750      switch(x68k_sys.mdctrl.seq1)
752      switch(state->mdctrl.seq1)
751753      {
752754         case 1:
753755         default:
754            if(x68k_sys.mdctrl.mux1 & 0x10)
756            if(state->mdctrl.mux1 & 0x10)
755757            {
756758               return porta | 0x90;
757759            }
r9669r9670
760762               return (portb & 0x60) | (porta & 0x03) | 0x90;
761763            }
762764         case 2:
763            if(x68k_sys.mdctrl.mux1 & 0x10)
765            if(state->mdctrl.mux1 & 0x10)
764766            {
765767               return porta | 0x90;
766768            }
r9669r9670
769771               return (portb & 0x60) | 0x90;
770772            }
771773         case 3:
772            if(x68k_sys.mdctrl.mux1 & 0x10)
774            if(state->mdctrl.mux1 & 0x10)
773775            {
774776               return (porta & 0x60) | (extra & 0x0f) | 0x90;
775777            }
r9669r9670
785787      UINT8 portb = (input_port_read(device->machine,"md6b") >> 24) & 0xff;
786788      UINT8 extra = (input_port_read(device->machine,"md6b_extra") >> 4) & 0x0f;
787789
788      switch(x68k_sys.mdctrl.seq2)
790      switch(state->mdctrl.seq2)
789791      {
790792         case 1:
791793         default:
792            if(x68k_sys.mdctrl.mux2 & 0x20)
794            if(state->mdctrl.mux2 & 0x20)
793795            {
794796               return porta | 0x90;
795797            }
r9669r9670
798800               return (portb & 0x60) | (porta & 0x03) | 0x90;
799801            }
800802         case 2:
801            if(x68k_sys.mdctrl.mux2 & 0x20)
803            if(state->mdctrl.mux2 & 0x20)
802804            {
803805               return porta | 0x90;
804806            }
r9669r9670
807809               return (portb & 0x60) | 0x90;
808810            }
809811         case 3:
810            if(x68k_sys.mdctrl.mux2 & 0x20)
812            if(state->mdctrl.mux2 & 0x20)
811813            {
812814               return (porta & 0x60) | (extra & 0x0f) | 0x90;
813815            }
r9669r9670
829831// The buttons are read the same as normal, regardless of ctl.
830832static UINT8 xpd1lr_r(running_device* device, int port)
831833{
834   x68k_state *state = device->machine->driver_data<x68k_state>();
832835   if(port == 1)
833836   {
834837      UINT8 porta = input_port_read(device->machine,"xpd1lr") & 0xff;
835838      UINT8 portb = (input_port_read(device->machine,"xpd1lr") >> 8) & 0xff;
836      if(x68k_sys.mdctrl.mux1 & 0x10)
839      if(state->mdctrl.mux1 & 0x10)
837840      {
838841         return porta;
839842      }
r9669r9670
846849   {
847850      UINT8 porta = (input_port_read(device->machine,"xpd1lr") >> 16) & 0xff;
848851      UINT8 portb = (input_port_read(device->machine,"xpd1lr") >> 24) & 0xff;
849      if(x68k_sys.mdctrl.mux2 & 0x20)
852      if(state->mdctrl.mux2 & 0x20)
850853      {
851854         return porta;
852855      }
r9669r9670
861864// Judging from the XM6 source code, PPI ports A and B are joystick inputs
862865static READ8_DEVICE_HANDLER( ppi_port_a_r )
863866{
867   x68k_state *state = device->machine->driver_data<x68k_state>();
864868   int ctrl = input_port_read(device->machine,"ctrltype") & 0x0f;
865869
866870   switch(ctrl)
867871   {
868872      case 0x00:  // standard MSX/FM-Towns joystick
869         if(x68k_sys.joy.joy1_enable == 0)
873         if(state->joy.joy1_enable == 0)
870874            return input_port_read(device->machine, "joy1");
871875         else
872876            return 0xff;
r9669r9670
883887
884888static READ8_DEVICE_HANDLER( ppi_port_b_r )
885889{
890   x68k_state *state = device->machine->driver_data<x68k_state>();
886891   int ctrl = input_port_read(device->machine,"ctrltype") & 0xf0;
887892
888893   switch(ctrl)
889894   {
890895      case 0x00:  // standard MSX/FM-Towns joystick
891         if(x68k_sys.joy.joy2_enable == 0)
896         if(state->joy.joy2_enable == 0)
892897            return input_port_read(device->machine, "joy2");
893898         else
894899            return 0xff;
r9669r9670
905910
906911static READ8_DEVICE_HANDLER( ppi_port_c_r )
907912{
908   return ppi_port[2];
913   x68k_state *state = device->machine->driver_data<x68k_state>();
914   return state->ppi_port[2];
909915}
910916
911917/* PPI port C (Joystick control, R/W)
r9669r9670
916922   bits 3,2 - ADPCM Sample rate
917923   bits 1,0 - ADPCM Pan
918924*/
919static UINT16 ppi_prev;
920925static WRITE8_DEVICE_HANDLER( ppi_port_c_w )
921926{
927   x68k_state *state = device->machine->driver_data<x68k_state>();
922928   // ADPCM / Joystick control
923929   running_device *oki = device->machine->device("okim6258");
924930
925   ppi_port[2] = data;
926   if((data & 0x0f) != (ppi_prev & 0x0f))
931   state->ppi_port[2] = data;
932   if((data & 0x0f) != (state->ppi_prev & 0x0f))
927933   {
928      x68k_sys.adpcm.pan = data & 0x03;
929      x68k_sys.adpcm.rate = data & 0x0c;
934      state->adpcm.pan = data & 0x03;
935      state->adpcm.rate = data & 0x0c;
930936      x68k_set_adpcm(device->machine);
931937      okim6258_set_divider(oki, (data >> 2) & 3);
932938   }
933939
934940   // The joystick enable bits also handle the multiplexer for various controllers
935   x68k_sys.joy.joy1_enable = data & 0x10;
936   x68k_sys.mdctrl.mux1 = data & 0x10;
937   if((ppi_prev & 0x10) == 0x00 && (data & 0x10) == 0x10)
941   state->joy.joy1_enable = data & 0x10;
942   state->mdctrl.mux1 = data & 0x10;
943   if((state->ppi_prev & 0x10) == 0x00 && (data & 0x10) == 0x10)
938944   {
939      x68k_sys.mdctrl.seq1++;
940      timer_adjust_oneshot(x68k_sys.mdctrl.io_timeout1,device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(8192),0);
945      state->mdctrl.seq1++;
946      timer_adjust_oneshot(state->mdctrl.io_timeout1,device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(8192),0);
941947   }
942948
943   x68k_sys.joy.joy2_enable = data & 0x20;
944   x68k_sys.mdctrl.mux2 = data & 0x20;
945   if((ppi_prev & 0x20) == 0x00 && (data & 0x20) == 0x20)
949   state->joy.joy2_enable = data & 0x20;
950   state->mdctrl.mux2 = data & 0x20;
951   if((state->ppi_prev & 0x20) == 0x00 && (data & 0x20) == 0x20)
946952   {
947      x68k_sys.mdctrl.seq2++;
948      timer_adjust_oneshot(x68k_sys.mdctrl.io_timeout2,device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(8192),0);
953      state->mdctrl.seq2++;
954      timer_adjust_oneshot(state->mdctrl.io_timeout2,device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(8192),0);
949955   }
950   ppi_prev = data;
956   state->ppi_prev = data;
951957
952   x68k_sys.joy.ioc6 = data & 0x40;
953   x68k_sys.joy.ioc7 = data & 0x80;
958   state->joy.ioc6 = data & 0x40;
959   state->joy.ioc7 = data & 0x80;
954960}
955961
956962
957963// NEC uPD72065 at 0xe94000
958964static WRITE16_HANDLER( x68k_fdc_w )
959965{
966   x68k_state *state = space->machine->driver_data<x68k_state>();
960967   running_device *fdc = space->machine->device("upd72065");
961968   unsigned int drive, x;
962969   switch(offset)
r9669r9670
969976      x = data & 0x0f;
970977      for(drive=0;drive<4;drive++)
971978      {
972         if(x68k_sys.fdc.selected_drive & (1 << drive))
979         if(state->fdc.selected_drive & (1 << drive))
973980         {
974981            if(!(x & (1 << drive)))  // functions take place on 1->0 transitions of drive bits only
975982            {
976               x68k_sys.fdc.led_ctrl[drive] = data & 0x80;  // blinking drive LED if no disk inserted
977               x68k_sys.fdc.led_eject[drive] = data & 0x40;  // eject button LED (on when set to 0)
983               state->fdc.led_ctrl[drive] = data & 0x80;  // blinking drive LED if no disk inserted
984               state->fdc.led_eject[drive] = data & 0x40;  // eject button LED (on when set to 0)
978985               output_set_indexed_value("eject_drv",drive,(data & 0x40) ? 1 : 0);
979986               if(data & 0x20)  // ejects disk
980987               {
r9669r9670
984991            }
985992         }
986993      }
987      x68k_sys.fdc.selected_drive = data & 0x0f;
994      state->fdc.selected_drive = data & 0x0f;
988995      logerror("FDC: signal control set to %02x\n",data);
989996      break;
990997   case 0x03:
991      x68k_sys.fdc.media_density[data & 0x03] = data & 0x10;
992      x68k_sys.fdc.motor[data & 0x03] = data & 0x80;
998      state->fdc.media_density[data & 0x03] = data & 0x10;
999      state->fdc.motor[data & 0x03] = data & 0x80;
9931000      floppy_mon_w(floppy_get_device(space->machine, data & 0x03), !BIT(data, 7));
9941001      if(data & 0x80)
9951002      {
r9669r9670
10331040
10341041static READ16_HANDLER( x68k_fdc_r )
10351042{
1043   x68k_state *state = space->machine->driver_data<x68k_state>();
10361044   unsigned int ret;
10371045   int x;
10381046   running_device *fdc = space->machine->device("upd72065");
r9669r9670
10471055      ret = 0x00;
10481056      for(x=0;x<4;x++)
10491057      {
1050         if(x68k_sys.fdc.selected_drive & (1 << x))
1058         if(state->fdc.selected_drive & (1 << x))
10511059         {
10521060            ret = 0x00;
1053            if(x68k_sys.fdc.disk_inserted[x] != 0)
1061            if(state->fdc.disk_inserted[x] != 0)
10541062            {
10551063               ret |= 0x80;
10561064            }
r9669r9670
10711079
10721080static WRITE_LINE_DEVICE_HANDLER( fdc_irq )
10731081{
1074   if((x68k_sys.ioc.irqstatus & 0x04) && state == ASSERT_LINE)
1082   x68k_state *drvstate = device->machine->driver_data<x68k_state>();
1083   if((drvstate->ioc.irqstatus & 0x04) && state == ASSERT_LINE)
10751084   {
1076      current_vector[1] = x68k_sys.ioc.fdcvector;
1077      x68k_sys.ioc.irqstatus |= 0x80;
1078      current_irq_line = 1;
1085      drvstate->current_vector[1] = drvstate->ioc.fdcvector;
1086      drvstate->ioc.irqstatus |= 0x80;
1087      drvstate->current_irq_line = 1;
10791088      logerror("FDC: IRQ triggered\n");
1080      cputag_set_input_line_and_vector(device->machine, "maincpu", 1, ASSERT_LINE, current_vector[1]);
1089      cputag_set_input_line_and_vector(device->machine, "maincpu", 1, ASSERT_LINE, drvstate->current_vector[1]);
10811090   }
10821091}
10831092
10841093static int x68k_fdc_read_byte(running_machine *machine,int addr)
10851094{
1095   x68k_state *state = machine->driver_data<x68k_state>();
10861096   int data = -1;
10871097   running_device *fdc = machine->device("upd72065");
10881098
1089   if(x68k_sys.fdc.drq_state != 0)
1099   if(state->fdc.drq_state != 0)
10901100      data = upd765_dack_r(fdc, 0);
10911101//  logerror("FDC: DACK reading\n");
10921102   return data;
r9669r9670
11001110
11011111static WRITE_LINE_DEVICE_HANDLER ( fdc_drq )
11021112{
1103   x68k_sys.fdc.drq_state = state;
1113   x68k_state *drvstate = device->machine->driver_data<x68k_state>();
1114   drvstate->fdc.drq_state = state;
11041115}
11051116
11061117static WRITE16_HANDLER( x68k_fm_w )
r9669r9670
11241135
11251136static WRITE8_DEVICE_HANDLER( x68k_ct_w )
11261137{
1138   x68k_state *state = device->machine->driver_data<x68k_state>();
11271139   running_device *fdc = device->machine->device("upd72065");
11281140   running_device *okim = device->machine->device("okim6258");
11291141
r9669r9670
11311143   // CT1 - ADPCM clock - 0 = 8MHz, 1 = 4MHz
11321144   // CT2 - 1 = Set ready state of FDC
11331145   upd765_ready_w(fdc,data & 0x01);
1134   x68k_sys.adpcm.clock = data & 0x02;
1146   state->adpcm.clock = data & 0x02;
11351147   x68k_set_adpcm(device->machine);
11361148   okim6258_set_clock(okim, data & 0x02 ? 4000000 : 8000000);
11371149}
r9669r9670
11541166*/
11551167static WRITE16_HANDLER( x68k_ioc_w )
11561168{
1169   x68k_state *state = space->machine->driver_data<x68k_state>();
11571170   switch(offset)
11581171   {
11591172   case 0x00:
1160      x68k_sys.ioc.irqstatus = data & 0x0f;
1173      state->ioc.irqstatus = data & 0x0f;
11611174      logerror("I/O: Status register write %02x\n",data);
11621175      break;
11631176   case 0x01:
11641177      switch(data & 0x03)
11651178      {
11661179      case 0x00:
1167         x68k_sys.ioc.fdcvector = data & 0xfc;
1180         state->ioc.fdcvector = data & 0xfc;
11681181         logerror("IOC: FDC IRQ vector = 0x%02x\n",data & 0xfc);
11691182         break;
11701183      case 0x01:
1171         x68k_sys.ioc.fddvector = data & 0xfc;
1184         state->ioc.fddvector = data & 0xfc;
11721185         logerror("IOC: FDD IRQ vector = 0x%02x\n",data & 0xfc);
11731186         break;
11741187      case 0x02:
1175         x68k_sys.ioc.hdcvector = data & 0xfc;
1188         state->ioc.hdcvector = data & 0xfc;
11761189         logerror("IOC: HDD IRQ vector = 0x%02x\n",data & 0xfc);
11771190         break;
11781191      case 0x03:
1179         x68k_sys.ioc.prnvector = data & 0xfc;
1192         state->ioc.prnvector = data & 0xfc;
11801193         logerror("IOC: Printer IRQ vector = 0x%02x\n",data & 0xfc);
11811194         break;
11821195      }
r9669r9670
11861199
11871200static READ16_HANDLER( x68k_ioc_r )
11881201{
1202   x68k_state *state = space->machine->driver_data<x68k_state>();
11891203   switch(offset)
11901204   {
11911205   case 0x00:
11921206      logerror("I/O: Status register read\n");
1193      return (x68k_sys.ioc.irqstatus & 0xdf) | 0x20;
1207      return (state->ioc.irqstatus & 0xdf) | 0x20;
11941208   default:
11951209      return 0x00;
11961210   }
r9669r9670
12181232*/
12191233static WRITE16_HANDLER( x68k_sysport_w )
12201234{
1235   x68k_state *state = space->machine->driver_data<x68k_state>();
12211236   switch(offset)
12221237   {
12231238   case 0x00:
1224      x68k_sys.sysport.contrast = data & 0x0f;  // often used for screen fades / blanking
1239      state->sysport.contrast = data & 0x0f;  // often used for screen fades / blanking
12251240      // TODO: implement a decent, not slow, brightness control
12261241      break;
12271242   case 0x01:
1228      x68k_sys.sysport.monitor = data & 0x08;
1243      state->sysport.monitor = data & 0x08;
12291244      break;
12301245   case 0x03:
1231      x68k_sys.sysport.keyctrl = data & 0x08;  // bit 3 = enable keyboard data transmission
1246      state->sysport.keyctrl = data & 0x08;  // bit 3 = enable keyboard data transmission
12321247      break;
12331248   case 0x06:
1234      x68k_sys.sysport.sram_writeprotect = data;
1249      state->sysport.sram_writeprotect = data;
12351250      break;
12361251   default:
12371252//      logerror("SYS: [%08x] Wrote %04x to invalid or unimplemented system port %04x\n",cpu_get_pc(space->cpu),data,offset);
r9669r9670
12411256
12421257static READ16_HANDLER( x68k_sysport_r )
12431258{
1259   x68k_state *state = space->machine->driver_data<x68k_state>();
12441260   int ret = 0;
12451261   switch(offset)
12461262   {
12471263   case 0x00:  // monitor contrast setting (bits3-0)
1248      return x68k_sys.sysport.contrast;
1264      return state->sysport.contrast;
12491265   case 0x01:  // monitor control (bit3) / 3D Scope (bits1,0)
1250      ret |= x68k_sys.sysport.monitor;
1266      ret |= state->sysport.monitor;
12511267      return ret;
12521268   case 0x03:  // bit 3 = key control (is 1 if keyboard is connected)
12531269      return 0x08;
12541270   case 0x05:  // CPU type and speed
1255      return x68k_sys.sysport.cputype;
1271      return state->sysport.cputype;
12561272   default:
12571273      logerror("Read from invalid or unimplemented system port %04x\n",offset);
12581274      return 0xff;
r9669r9670
12701286
12711287static READ16_HANDLER( x68k_mfp_r )
12721288{
1289   x68k_state *state = space->machine->driver_data<x68k_state>();
12731290   running_device *x68k_mfp = space->machine->device(MC68901_TAG);
12741291    // Initial settings indicate that IRQs are generated for FM (YM2151), Receive buffer error or full,
12751292    // MFP Timer C, and the power switch
r9669r9670
12791296#if 0
12801297    case 0x00:  // GPIP - General purpose I/O register (read-only)
12811298        ret = 0x23;
1282        if(machine->primary_screen->vpos() == x68k_sys.crtc.reg[9])
1299        if(machine->primary_screen->vpos() == state->crtc.reg[9])
12831300            ret |= 0x40;
1284        if(x68k_sys.crtc.vblank == 0)
1301        if(state->crtc.vblank == 0)
12851302            ret |= 0x10;  // Vsync signal (low if in vertical retrace)
1286//      if(x68k_sys.mfp.isrb & 0x08)
1303//      if(state->mfp.isrb & 0x08)
12871304//          ret |= 0x08;  // FM IRQ signal
1288        if(machine->primary_screen->hpos() > x68k_sys.crtc.width - 32)
1305        if(machine->primary_screen->hpos() > state->crtc.width - 32)
12891306            ret |= 0x80;  // Hsync signal
12901307//      logerror("MFP: [%08x] Reading offset %i (ret=%02x)\n",cpu_get_pc(space->cpu),offset,ret);
12911308        return ret;  // bit 5 is always 1
12921309    case 3:
1293        return x68k_sys.mfp.iera;
1310        return state->mfp.iera;
12941311    case 4:
1295        return x68k_sys.mfp.ierb;
1312        return state->mfp.ierb;
12961313    case 5:
1297        return x68k_sys.mfp.ipra;
1314        return state->mfp.ipra;
12981315    case 6:
1299        return x68k_sys.mfp.iprb;
1316        return state->mfp.iprb;
13001317    case 7:
1301        if(x68k_sys.mfp.eoi_mode == 0)  // forced low in auto EOI mode
1318        if(state->mfp.eoi_mode == 0)  // forced low in auto EOI mode
13021319            return 0;
13031320        else
1304            return x68k_sys.mfp.isra;
1321            return state->mfp.isra;
13051322    case 8:
1306        if(x68k_sys.mfp.eoi_mode == 0)  // forced low in auto EOI mode
1323        if(state->mfp.eoi_mode == 0)  // forced low in auto EOI mode
13071324            return 0;
13081325        else
1309            return x68k_sys.mfp.isrb;
1326            return state->mfp.isrb;
13101327    case 9:
1311        return x68k_sys.mfp.imra;
1328        return state->mfp.imra;
13121329    case 10:
1313        return x68k_sys.mfp.imrb;
1330        return state->mfp.imrb;
13141331    case 15:  // TADR
1315        return x68k_sys.mfp.timer[0].counter;  // Timer data registers return their main counter values
1332        return state->mfp.timer[0].counter;  // Timer data registers return their main counter values
13161333    case 16:  // TBDR
1317        return x68k_sys.mfp.timer[1].counter;
1334        return state->mfp.timer[1].counter;
13181335    case 17:  // TCDR
1319        return x68k_sys.mfp.timer[2].counter;
1336        return state->mfp.timer[2].counter;
13201337    case 18:  // TDDR
1321        return x68k_sys.mfp.timer[3].counter;
1338        return state->mfp.timer[3].counter;
13221339#endif
13231340    case 21:  // RSR
1324        return x68k_sys.mfp.rsr;
1341        return state->mfp.rsr;
13251342    case 22:  // TSR
1326        return x68k_sys.mfp.tsr | 0x80;  // buffer is typically empty?
1343        return state->mfp.tsr | 0x80;  // buffer is typically empty?
13271344    case 23:
1328        return x68k_keyboard_pop_scancode();
1345        return x68k_keyboard_pop_scancode(state);
13291346    default:
13301347      if (ACCESSING_BITS_0_7) return mc68901_register_r(x68k_mfp, offset);
13311348    }
r9669r9670
13341351
13351352static WRITE16_HANDLER( x68k_mfp_w )
13361353{
1354   x68k_state *state = space->machine->driver_data<x68k_state>();
13371355   running_device *x68k_mfp = space->machine->device(MC68901_TAG);
13381356
13391357   /* For the Interrupt registers, the bits are set out as such:
r9669r9670
13611379        // All bits are inputs generally, so no action taken.
13621380        break;
13631381    case 1:  // AER
1364        x68k_sys.mfp.aer = data;
1382        state->mfp.aer = data;
13651383        break;
13661384    case 2:  // DDR
1367        x68k_sys.mfp.ddr = data;  // usually all bits are 0 (input)
1385        state->mfp.ddr = data;  // usually all bits are 0 (input)
13681386        break;
13691387    case 3:  // IERA
1370        x68k_sys.mfp.iera = data;
1388        state->mfp.iera = data;
13711389        break;
13721390    case 4:  // IERB
1373        x68k_sys.mfp.ierb = data;
1391        state->mfp.ierb = data;
13741392        break;
13751393    case 5:  // IPRA
1376        x68k_sys.mfp.ipra = data;
1394        state->mfp.ipra = data;
13771395        break;
13781396    case 6:  // IPRB
1379        x68k_sys.mfp.iprb = data;
1397        state->mfp.iprb = data;
13801398        break;
13811399    case 7:
1382        x68k_sys.mfp.isra = data;
1400        state->mfp.isra = data;
13831401        break;
13841402    case 8:
1385        x68k_sys.mfp.isrb = data;
1403        state->mfp.isrb = data;
13861404        break;
13871405    case 9:
1388        x68k_sys.mfp.imra = data;
1406        state->mfp.imra = data;
13891407//      mfp_update_irq(0);
13901408//      logerror("MFP: IRQ Mask A write: %02x\n",data);
13911409        break;
13921410    case 10:
1393        x68k_sys.mfp.imrb = data;
1411        state->mfp.imrb = data;
13941412//      mfp_update_irq(0);
13951413//      logerror("MFP: IRQ Mask B write: %02x\n",data);
13961414        break;
13971415    case 11:  // VR
1398        x68k_sys.mfp.vr = 0x40;//data;  // High 4 bits = high 4 bits of IRQ vector
1399        x68k_sys.mfp.eoi_mode = data & 0x08;  // 0 = Auto, 1 = Software End-of-interrupt
1400        if(x68k_sys.mfp.eoi_mode == 0)  // In-service registers are cleared if this bit is cleared.
1416        state->mfp.vr = 0x40;//data;  // High 4 bits = high 4 bits of IRQ vector
1417        state->mfp.eoi_mode = data & 0x08;  // 0 = Auto, 1 = Software End-of-interrupt
1418        if(state->mfp.eoi_mode == 0)  // In-service registers are cleared if this bit is cleared.
14011419        {
1402            x68k_sys.mfp.isra = 0;
1403            x68k_sys.mfp.isrb = 0;
1420            state->mfp.isra = 0;
1421            state->mfp.isrb = 0;
14041422        }
14051423        break;
14061424    case 12:  // TACR
1407        x68k_sys.mfp.tacr = data;
1425        state->mfp.tacr = data;
14081426        mfp_set_timer(0,data & 0x0f);
14091427        break;
14101428    case 13:  // TBCR
1411        x68k_sys.mfp.tbcr = data;
1429        state->mfp.tbcr = data;
14121430        mfp_set_timer(1,data & 0x0f);
14131431        break;
14141432    case 14:  // TCDCR
1415        x68k_sys.mfp.tcdcr = data;
1433        state->mfp.tcdcr = data;
14161434        mfp_set_timer(2,(data & 0x70)>>4);
14171435        mfp_set_timer(3,data & 0x07);
14181436        break;
14191437    case 15:  // TADR
1420        x68k_sys.mfp.tadr = data;
1421        x68k_sys.mfp.timer[0].counter = data;
1438        state->mfp.tadr = data;
1439        state->mfp.timer[0].counter = data;
14221440        break;
14231441    case 16:  // TBDR
1424        x68k_sys.mfp.tbdr = data;
1425        x68k_sys.mfp.timer[1].counter = data;
1442        state->mfp.tbdr = data;
1443        state->mfp.timer[1].counter = data;
14261444        break;
14271445    case 17:  // TCDR
1428        x68k_sys.mfp.tcdr = data;
1429        x68k_sys.mfp.timer[2].counter = data;
1446        state->mfp.tcdr = data;
1447        state->mfp.timer[2].counter = data;
14301448        break;
14311449    case 18:  // TDDR
1432        x68k_sys.mfp.tddr = data;
1433        x68k_sys.mfp.timer[3].counter = data;
1450        state->mfp.tddr = data;
1451        state->mfp.timer[3].counter = data;
14341452        break;
14351453    case 20:
1436        x68k_sys.mfp.ucr = data;
1454        state->mfp.ucr = data;
14371455        break;
14381456#endif
14391457    case 21:
14401458        if(data & 0x01)
1441            x68k_sys.mfp.usart.recv_enable = 1;
1459            state->mfp.usart.recv_enable = 1;
14421460        else
1443            x68k_sys.mfp.usart.recv_enable = 0;
1461            state->mfp.usart.recv_enable = 0;
14441462        break;
14451463   case 22:
14461464      if(data & 0x01)
1447         x68k_sys.mfp.usart.send_enable = 1;
1465         state->mfp.usart.send_enable = 1;
14481466      else
1449         x68k_sys.mfp.usart.send_enable = 0;
1467         state->mfp.usart.send_enable = 0;
14501468      break;
14511469   case 23:
1452      if(x68k_sys.mfp.usart.send_enable != 0)
1470      if(state->mfp.usart.send_enable != 0)
14531471      {
14541472         // Keyboard control command.
1455         x68k_sys.mfp.usart.send_buffer = data;
1456         x68k_keyboard_ctrl_w(data);
1473         state->mfp.usart.send_buffer = data;
1474         x68k_keyboard_ctrl_w(state, data);
14571475//          logerror("MFP: [%08x] USART Sent data %04x\n",cpu_get_pc(space->cpu),data);
14581476      }
14591477      break;
r9669r9670
14841502   rp5c15_w(device, offset, data, mem_mask);
14851503}
14861504
1487static void x68k_rtc_alarm_irq(int state)
1505static void x68k_rtc_alarm_irq(running_machine *machine, int state)
14881506{
1489   if(x68k_sys.mfp.aer & 0x01)
1507   x68k_state *drvstate = machine->driver_data<x68k_state>();
1508   if(drvstate->mfp.aer & 0x01)
14901509   {
14911510      if(state == 1)
1492         x68k_sys.mfp.gpio |= 0x01;
1511         drvstate->mfp.gpio |= 0x01;
14931512         //mfp_trigger_irq(MFP_IRQ_GPIP0);  // RTC ALARM
14941513   }
14951514   else
14961515   {
14971516      if(state == 0)
1498         x68k_sys.mfp.gpio &= ~0x01;
1517         drvstate->mfp.gpio &= ~0x01;
14991518         //mfp_trigger_irq(MFP_IRQ_GPIP0);  // RTC ALARM
15001519   }
15011520}
r9669r9670
15051524{
15061525   x68k_state *state = space->machine->driver_data<x68k_state>();
15071526
1508   if(x68k_sys.sysport.sram_writeprotect == 0x31)
1527   if(state->sysport.sram_writeprotect == 0x31)
15091528   {
15101529      COMBINE_DATA(state->m_nvram + offset);
15111530   }
r9669r9670
15491568static WRITE32_HANDLER( x68k_sram32_w )
15501569{
15511570   x68k_state *state = space->machine->driver_data<x68k_state>();
1552   if(x68k_sys.sysport.sram_writeprotect == 0x31)
1571   if(state->sysport.sram_writeprotect == 0x31)
15531572   {
15541573      COMBINE_DATA(state->m_nvram + offset);
15551574   }
r9669r9670
15571576
15581577static WRITE16_HANDLER( x68k_vid_w )
15591578{
1579   x68k_state *state = space->machine->driver_data<x68k_state>();
15601580   int val;
15611581   if(offset < 0x100)  // Graphic layer palette
15621582   {
1563      COMBINE_DATA(x68k_sys.video.gfx_pal+offset);
1564      val = x68k_sys.video.gfx_pal[offset];
1583      COMBINE_DATA(state->video.gfx_pal+offset);
1584      val = state->video.gfx_pal[offset];
15651585      palette_set_color_rgb(space->machine,offset,(val & 0x07c0) >> 3,(val & 0xf800) >> 8,(val & 0x003e) << 2);
15661586      return;
15671587   }
15681588
15691589   if(offset >= 0x100 && offset < 0x200)  // Text / Sprites / Tilemap palette
15701590   {
1571      COMBINE_DATA(x68k_sys.video.text_pal+(offset-0x100));
1572      val = x68k_sys.video.text_pal[offset-0x100];
1591      COMBINE_DATA(state->video.text_pal+(offset-0x100));
1592      val = state->video.text_pal[offset-0x100];
15731593      palette_set_color_rgb(space->machine,offset,(val & 0x07c0) >> 3,(val & 0xf800) >> 8,(val & 0x003e) << 2);
15741594      return;
15751595   }
r9669r9670
15771597   switch(offset)
15781598   {
15791599   case 0x200:
1580      COMBINE_DATA(x68k_sys.video.reg);
1600      COMBINE_DATA(state->video.reg);
15811601      break;
15821602   case 0x280:  // priority levels
1583      COMBINE_DATA(x68k_sys.video.reg+1);
1603      COMBINE_DATA(state->video.reg+1);
15841604      if(ACCESSING_BITS_0_7)
15851605      {
1586         x68k_sys.video.gfxlayer_pri[0] = data & 0x0003;
1587         x68k_sys.video.gfxlayer_pri[1] = (data & 0x000c) >> 2;
1588         x68k_sys.video.gfxlayer_pri[2] = (data & 0x0030) >> 4;
1589         x68k_sys.video.gfxlayer_pri[3] = (data & 0x00c0) >> 6;
1606         state->video.gfxlayer_pri[0] = data & 0x0003;
1607         state->video.gfxlayer_pri[1] = (data & 0x000c) >> 2;
1608         state->video.gfxlayer_pri[2] = (data & 0x0030) >> 4;
1609         state->video.gfxlayer_pri[3] = (data & 0x00c0) >> 6;
15901610      }
15911611      if(ACCESSING_BITS_8_15)
15921612      {
1593         x68k_sys.video.gfx_pri = (data & 0x0300) >> 8;
1594         x68k_sys.video.text_pri = (data & 0x0c00) >> 10;
1595         x68k_sys.video.sprite_pri = (data & 0x3000) >> 12;
1596         if(x68k_sys.video.gfx_pri == 3)
1597            x68k_sys.video.gfx_pri--;
1598         if(x68k_sys.video.text_pri == 3)
1599            x68k_sys.video.text_pri--;
1600         if(x68k_sys.video.sprite_pri == 3)
1601            x68k_sys.video.sprite_pri--;
1613         state->video.gfx_pri = (data & 0x0300) >> 8;
1614         state->video.text_pri = (data & 0x0c00) >> 10;
1615         state->video.sprite_pri = (data & 0x3000) >> 12;
1616         if(state->video.gfx_pri == 3)
1617            state->video.gfx_pri--;
1618         if(state->video.text_pri == 3)
1619            state->video.text_pri--;
1620         if(state->video.sprite_pri == 3)
1621            state->video.sprite_pri--;
16021622      }
16031623      break;
16041624   case 0x300:
1605      COMBINE_DATA(x68k_sys.video.reg+2);
1625      COMBINE_DATA(state->video.reg+2);
16061626      break;
16071627   default:
16081628      logerror("VC: Invalid video controller write (offset = 0x%04x, data = %04x)\n",offset,data);
r9669r9670
16111631
16121632static READ16_HANDLER( x68k_vid_r )
16131633{
1634   x68k_state *state = space->machine->driver_data<x68k_state>();
16141635   if(offset < 0x100)
1615      return x68k_sys.video.gfx_pal[offset];
1636      return state->video.gfx_pal[offset];
16161637
16171638   if(offset >= 0x100 && offset < 0x200)
1618      return x68k_sys.video.text_pal[offset-0x100];
1639      return state->video.text_pal[offset-0x100];
16191640
16201641   switch(offset)
16211642   {
16221643   case 0x200:
1623      return x68k_sys.video.reg[0];
1644      return state->video.reg[0];
16241645   case 0x280:
1625      return x68k_sys.video.reg[1];
1646      return state->video.reg[1];
16261647   case 0x300:
1627      return x68k_sys.video.reg[2];
1648      return state->video.reg[2];
16281649   default:
16291650      logerror("VC: Invalid video controller read (offset = 0x%04x)\n",offset);
16301651   }
r9669r9670
16901711
16911712static READ16_HANDLER( x68k_rom0_r )
16921713{
1714   x68k_state *state = space->machine->driver_data<x68k_state>();
16931715   /* this location contains the address of some expansion device ROM, if no ROM exists,
16941716       then access causes a bus error */
1695   current_vector[2] = 0x02;  // bus error
1696   current_irq_line = 2;
1697//  cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,current_vector[2]);
1717   state->current_vector[2] = 0x02;  // bus error
1718   state->current_irq_line = 2;
1719//  cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]);
16981720   if(input_port_read(space->machine, "options") & 0x02)
16991721   {
17001722      offset *= 2;
r9669r9670
17071729
17081730static WRITE16_HANDLER( x68k_rom0_w )
17091731{
1732   x68k_state *state = space->machine->driver_data<x68k_state>();
17101733   /* this location contains the address of some expansion device ROM, if no ROM exists,
17111734       then access causes a bus error */
1712   current_vector[2] = 0x02;  // bus error
1713   current_irq_line = 2;
1714//  cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,current_vector[2]);
1735   state->current_vector[2] = 0x02;  // bus error
1736   state->current_irq_line = 2;
1737//  cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]);
17151738   if(input_port_read(space->machine, "options") & 0x02)
17161739   {
17171740      offset *= 2;
r9669r9670
17231746
17241747static READ16_HANDLER( x68k_emptyram_r )
17251748{
1749   x68k_state *state = space->machine->driver_data<x68k_state>();
17261750   /* this location is unused RAM, access here causes a bus error
17271751       Often a method for detecting amount of installed RAM, is to read or write at 1MB intervals, until a bus error occurs */
1728   current_vector[2] = 0x02;  // bus error
1729   current_irq_line = 2;
1730//  cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,current_vector[2]);
1752   state->current_vector[2] = 0x02;  // bus error
1753   state->current_irq_line = 2;
1754//  cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]);
17311755   if(input_port_read(space->machine, "options") & 0x02)
17321756   {
17331757      offset *= 2;
r9669r9670
17401764
17411765static WRITE16_HANDLER( x68k_emptyram_w )
17421766{
1767   x68k_state *state = space->machine->driver_data<x68k_state>();
17431768   /* this location is unused RAM, access here causes a bus error
17441769       Often a method for detecting amount of installed RAM, is to read or write at 1MB intervals, until a bus error occurs */
1745   current_vector[2] = 0x02;  // bus error
1746   current_irq_line = 2;
1747//  cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,current_vector[2]);
1770   state->current_vector[2] = 0x02;  // bus error
1771   state->current_irq_line = 2;
1772//  cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]);
17481773   if(input_port_read(space->machine, "options") & 0x02)
17491774   {
17501775      offset *= 2;
r9669r9670
17561781
17571782static READ16_HANDLER( x68k_exp_r )
17581783{
1784   x68k_state *state = space->machine->driver_data<x68k_state>();
17591785   /* These are expansion devices, if not present, they cause a bus error */
17601786   if(input_port_read(space->machine, "options") & 0x02)
17611787   {
1762      current_vector[2] = 0x02;  // bus error
1763      current_irq_line = 2;
1788      state->current_vector[2] = 0x02;  // bus error
1789      state->current_irq_line = 2;
17641790      offset *= 2;
17651791      if(ACCESSING_BITS_0_7)
17661792         offset++;
17671793      timer_set(space->machine, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime(16), NULL, 0xeafa00+offset,x68k_fake_bus_error);
1768//      cputag_set_input_line_and_vector(machine, "maincpu",2,ASSERT_LINE,current_vector[2]);
1794//      cputag_set_input_line_and_vector(machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]);
17691795   }
17701796   return 0xffff;
17711797}
17721798
17731799static WRITE16_HANDLER( x68k_exp_w )
17741800{
1801   x68k_state *state = space->machine->driver_data<x68k_state>();
17751802   /* These are expansion devices, if not present, they cause a bus error */
17761803   if(input_port_read(space->machine, "options") & 0x02)
17771804   {
1778      current_vector[2] = 0x02;  // bus error
1779      current_irq_line = 2;
1805      state->current_vector[2] = 0x02;  // bus error
1806      state->current_irq_line = 2;
17801807      offset *= 2;
17811808      if(ACCESSING_BITS_0_7)
17821809         offset++;
17831810      timer_set(space->machine, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime(16), NULL, 0xeafa00+offset,x68k_fake_bus_error);
1784//      cputag_set_input_line_and_vector(machine, "maincpu",2,ASSERT_LINE,current_vector[2]);
1811//      cputag_set_input_line_and_vector(machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]);
17851812   }
17861813}
17871814
17881815static void x68k_dma_irq(running_machine *machine, int channel)
17891816{
1817   x68k_state *state = machine->driver_data<x68k_state>();
17901818   running_device *device = machine->device("hd63450");
1791   current_vector[3] = hd63450_get_vector(device, channel);
1792   current_irq_line = 3;
1793   logerror("DMA#%i: DMA End (vector 0x%02x)\n",channel,current_vector[3]);
1794   cputag_set_input_line_and_vector(machine, "maincpu",3,ASSERT_LINE,current_vector[3]);
1819   state->current_vector[3] = hd63450_get_vector(device, channel);
1820   state->current_irq_line = 3;
1821   logerror("DMA#%i: DMA End (vector 0x%02x)\n",channel,state->current_vector[3]);
1822   cputag_set_input_line_and_vector(machine, "maincpu",3,ASSERT_LINE,state->current_vector[3]);
17951823}
17961824
17971825static void x68k_dma_end(running_machine *machine, int channel,int irq)
r9669r9670
18041832
18051833static void x68k_dma_error(running_machine *machine, int channel, int irq)
18061834{
1835   x68k_state *state = machine->driver_data<x68k_state>();
18071836   running_device *device = machine->device("hd63450");
18081837   if(irq != 0)
18091838   {
1810      current_vector[3] = hd63450_get_error_vector(device,channel);
1811      current_irq_line = 3;
1812      cputag_set_input_line_and_vector(machine, "maincpu",3,ASSERT_LINE,current_vector[3]);
1839      state->current_vector[3] = hd63450_get_error_vector(device,channel);
1840      state->current_irq_line = 3;
1841      cputag_set_input_line_and_vector(machine, "maincpu",3,ASSERT_LINE,state->current_vector[3]);
18131842   }
18141843}
18151844
18161845static void x68k_fm_irq(running_device *device, int irq)
18171846{
1847   x68k_state *state = device->machine->driver_data<x68k_state>();
18181848   if(irq == CLEAR_LINE)
18191849   {
1820      x68k_sys.mfp.gpio |= 0x08;
1850      state->mfp.gpio |= 0x08;
18211851   }
18221852   else
18231853   {
1824      x68k_sys.mfp.gpio &= ~0x08;
1854      state->mfp.gpio &= ~0x08;
18251855   }
18261856}
18271857
18281858static READ8_DEVICE_HANDLER( mfp_gpio_r )
18291859{
1830   UINT8 data = x68k_sys.mfp.gpio;
1860   x68k_state *state = device->machine->driver_data<x68k_state>();
1861   UINT8 data = state->mfp.gpio;
18311862
1832   data &= ~(x68k_sys.crtc.hblank << 7);
1833   data &= ~(x68k_sys.crtc.vblank << 4);
1863   data &= ~(state->crtc.hblank << 7);
1864   data &= ~(state->crtc.vblank << 4);
18341865   data |= 0x23;  // GPIP5 is unused, always 1
18351866
1836//  mc68901_tai_w(mfp, x68k_sys.crtc.vblank);
1867//  mc68901_tai_w(mfp, state->crtc.vblank);
18371868
18381869   return data;
18391870}
r9669r9670
18511882   }
18521883}
18531884
1854static int mfp_prev;
18551885static WRITE_LINE_DEVICE_HANDLER( mfp_irq_callback )
18561886{
1857   if(mfp_prev == CLEAR_LINE && state == CLEAR_LINE)  // eliminate unnecessary calls to set the IRQ line for speed reasons
1887   x68k_state *drvstate = device->machine->driver_data<x68k_state>();
1888   if(drvstate->mfp_prev == CLEAR_LINE && state == CLEAR_LINE)  // eliminate unnecessary calls to set the IRQ line for speed reasons
18581889      return;
18591890   if(state != CLEAR_LINE)
18601891      state = HOLD_LINE;  // to get around erroneous spurious interrupt
1861//  if((x68k_sys.ioc.irqstatus & 0xc0) != 0)  // if the FDC is busy, then we don't want to miss that IRQ
1892//  if((state->ioc.irqstatus & 0xc0) != 0)  // if the FDC is busy, then we don't want to miss that IRQ
18621893//      return;
18631894   cputag_set_input_line(device->machine, "maincpu", 6, state);
1864   current_vector[6] = 0;
1865   mfp_prev = state;
1895   drvstate->current_vector[6] = 0;
1896   drvstate->mfp_prev = state;
18661897}
18671898
18681899static INTERRUPT_GEN( x68k_vsync_irq )
18691900{
1870//  if(x68k_sys.mfp.ierb & 0x40)
1871//  {
1872//      x68k_sys.mfp.isrb |= 0x40;
1873//      current_vector[6] = (x68k_sys.mfp.vr & 0xf0) | 0x06;  // GPIP4 (V-DISP)
1874//      current_irq_line = 6;
1875//  mfp_timer_a_callback(0);  // Timer A is usually always in event count mode, and is tied to V-DISP
1876//  mfp_trigger_irq(MFP_IRQ_GPIP4);
1877//  }
1878//  if(x68k_sys.crtc.height == 256)
1879//      machine->primary_screen->update_partial(256);//x68k_sys.crtc.reg[4]/2);
1880//  else
1881//      machine->primary_screen->update_partial(512);//x68k_sys.crtc.reg[4]);
1901#if 0
1902   x68k_state *state = machine->driver_data<x68k_state>();
1903   if(state->mfp.ierb & 0x40)
1904   {
1905      state->mfp.isrb |= 0x40;
1906      state->current_vector[6] = (state->mfp.vr & 0xf0) | 0x06;  // GPIP4 (V-DISP)
1907      state->current_irq_line = 6;
1908      mfp_timer_a_callback(0);  // Timer A is usually always in event count mode, and is tied to V-DISP
1909      mfp_trigger_irq(MFP_IRQ_GPIP4);
1910   }
1911   if(state->crtc.height == 256)
1912      machine->primary_screen->update_partial(256);//state->crtc.reg[4]/2);
1913   else
1914      machine->primary_screen->update_partial(512);//state->crtc.reg[4]);
1915#endif
18821916}
18831917
18841918static IRQ_CALLBACK(x68k_int_ack)
18851919{
1920   x68k_state *state = device->machine->driver_data<x68k_state>();
18861921   running_device *x68k_mfp = device->machine->device(MC68901_TAG);
18871922
18881923   if(irqline == 6)  // MFP
18891924   {
1890      x68k_sys.mfp.current_irq = -1;
1891      if(current_vector[6] != 0x4b && current_vector[6] != 0x4c)
1892         current_vector[6] = mc68901_get_vector(x68k_mfp);
1925      state->mfp.current_irq = -1;
1926      if(state->current_vector[6] != 0x4b && state->current_vector[6] != 0x4c)
1927         state->current_vector[6] = mc68901_get_vector(x68k_mfp);
18931928      else
1894         cputag_set_input_line_and_vector(device->machine, "maincpu",irqline,CLEAR_LINE,current_vector[irqline]);
1895      logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",current_vector[6],irqline);
1896      return current_vector[6];
1929         cputag_set_input_line_and_vector(device->machine, "maincpu",irqline,CLEAR_LINE,state->current_vector[irqline]);
1930      logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",state->current_vector[6],irqline);
1931      return state->current_vector[6];
18971932   }
18981933
1899   cputag_set_input_line_and_vector(device->machine, "maincpu",irqline,CLEAR_LINE,current_vector[irqline]);
1934   cputag_set_input_line_and_vector(device->machine, "maincpu",irqline,CLEAR_LINE,state->current_vector[irqline]);
19001935   if(irqline == 1)  // IOSC
19011936   {
1902      x68k_sys.ioc.irqstatus &= ~0xf0;
1937      state->ioc.irqstatus &= ~0xf0;
19031938   }
19041939   if(irqline == 5)  // SCC
19051940   {
1906      x68k_sys.mouse.irqactive = 0;
1941      state->mouse.irqactive = 0;
19071942   }
19081943
1909   logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",current_vector[irqline],irqline);
1910   return current_vector[irqline];
1944   logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",state->current_vector[irqline],irqline);
1945   return state->current_vector[irqline];
19111946}
19121947
19131948static ADDRESS_MAP_START(x68k_map, ADDRESS_SPACE_PROGRAM, 16)
19141949//  AM_RANGE(0x000000, 0xbfffff) AM_RAMBANK(1)
19151950   AM_RANGE(0xbffffc, 0xbfffff) AM_READWRITE(x68k_rom0_r, x68k_rom0_w)
1916//  AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(x68k_gvram_r, x68k_gvram_w) AM_BASE(&x68k_gvram)
1917//  AM_RANGE(0xe00000, 0xe7ffff) AM_READWRITE(x68k_tvram_r, x68k_tvram_w) AM_BASE(&x68k_tvram)
1951//  AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(x68k_gvram_r, x68k_gvram_w) AM_BASE_MEMBER(x68k_state, gvram)
1952//  AM_RANGE(0xe00000, 0xe7ffff) AM_READWRITE(x68k_tvram_r, x68k_tvram_w) AM_BASE_MEMBER(x68k_state, tvram)
19181953   AM_RANGE(0xc00000, 0xdfffff) AM_RAMBANK("bank2")
19191954   AM_RANGE(0xe00000, 0xe7ffff) AM_RAMBANK("bank3")
19201955   AM_RANGE(0xe80000, 0xe81fff) AM_READWRITE(x68k_crtc_r, x68k_crtc_w)
r9669r9670
19491984static ADDRESS_MAP_START(x68030_map, ADDRESS_SPACE_PROGRAM, 32)
19501985//  AM_RANGE(0x000000, 0xbfffff) AM_RAMBANK(1)
19511986   AM_RANGE(0xbffffc, 0xbfffff) AM_READWRITE16(x68k_rom0_r, x68k_rom0_w,0xffffffff)
1952//  AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(x68k_gvram_r, x68k_gvram_w) AM_BASE(&x68k_gvram)
1953//  AM_RANGE(0xe00000, 0xe7ffff) AM_READWRITE(x68k_tvram_r, x68k_tvram_w) AM_BASE(&x68k_tvram)
1987//  AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(x68k_gvram_r, x68k_gvram_w) AM_BASE_MEMBER(x68k_state, gvram)
1988//  AM_RANGE(0xe00000, 0xe7ffff) AM_READWRITE(x68k_tvram_r, x68k_tvram_w) AM_BASE_MEMBER(x68k_state, tvram)
19541989   AM_RANGE(0xc00000, 0xdfffff) AM_RAMBANK("bank2")
19551990   AM_RANGE(0xe00000, 0xe7ffff) AM_RAMBANK("bank3")
19561991   AM_RANGE(0xe80000, 0xe81fff) AM_READWRITE16(x68k_crtc_r, x68k_crtc_w,0xffffffff)
r9669r9670
23622397
23632398static void x68k_load_proc(device_image_interface &image)
23642399{
2365   if(x68k_sys.ioc.irqstatus & 0x02)
2400   x68k_state *state = image.device().machine->driver_data<x68k_state>();
2401   if(state->ioc.irqstatus & 0x02)
23662402   {
2367      current_vector[1] = 0x61;
2368      x68k_sys.ioc.irqstatus |= 0x40;
2369      current_irq_line = 1;
2370      cputag_set_input_line_and_vector(image.device().machine, "maincpu",1,ASSERT_LINE,current_vector[1]);  // Disk insert/eject interrupt
2403      state->current_vector[1] = 0x61;
2404      state->ioc.irqstatus |= 0x40;
2405      state->current_irq_line = 1;
2406      cputag_set_input_line_and_vector(image.device().machine, "maincpu",1,ASSERT_LINE,state->current_vector[1]);  // Disk insert/eject interrupt
23712407      logerror("IOC: Disk image inserted\n");
23722408   }
2373   x68k_sys.fdc.disk_inserted[floppy_get_drive(&image.device())] = 1;
2409   state->fdc.disk_inserted[floppy_get_drive(&image.device())] = 1;
23742410}
23752411
23762412static void x68k_unload_proc(device_image_interface &image)
23772413{
2378   if(x68k_sys.ioc.irqstatus & 0x02)
2414   x68k_state *state = image.device().machine->driver_data<x68k_state>();
2415   if(state->ioc.irqstatus & 0x02)
23792416   {
2380      current_vector[1] = 0x61;
2381      x68k_sys.ioc.irqstatus |= 0x40;
2382      current_irq_line = 1;
2383      cputag_set_input_line_and_vector(image.device().machine, "maincpu",1,ASSERT_LINE,current_vector[1]);  // Disk insert/eject interrupt
2417      state->current_vector[1] = 0x61;
2418      state->ioc.irqstatus |= 0x40;
2419      state->current_irq_line = 1;
2420      cputag_set_input_line_and_vector(image.device().machine, "maincpu",1,ASSERT_LINE,state->current_vector[1]);  // Disk insert/eject interrupt
23842421   }
2385   x68k_sys.fdc.disk_inserted[floppy_get_drive(&image.device())] = 0;
2422   state->fdc.disk_inserted[floppy_get_drive(&image.device())] = 0;
23862423}
23872424
23882425static FLOPPY_OPTIONS_START( x68k )
r9669r9670
24102447
24112448static MACHINE_RESET( x68000 )
24122449{
2450   x68k_state *state = machine->driver_data<x68k_state>();
24132451   /* The last half of the IPLROM is mapped to 0x000000 on reset only
24142452       Just copying the inital stack pointer and program counter should
24152453       more or less do the same job */
r9669r9670
24222460   memcpy(messram_get_ptr(machine->device("messram")),romdata,8);
24232461
24242462   // init keyboard
2425   x68k_sys.keyboard.delay = 500;  // 3*100+200
2426   x68k_sys.keyboard.repeat = 110;  // 4^2*5+30
2463   state->keyboard.delay = 500;  // 3*100+200
2464   state->keyboard.repeat = 110;  // 4^2*5+30
24272465
24282466   // check for disks
24292467   for(drive=0;drive<4;drive++)
24302468   {
24312469      device_image_interface *image = dynamic_cast<device_image_interface *>(floppy_get_device(machine, drive));
24322470      if(image->exists())
2433         x68k_sys.fdc.disk_inserted[drive] = 1;
2471         state->fdc.disk_inserted[drive] = 1;
24342472      else
2435         x68k_sys.fdc.disk_inserted[drive] = 0;
2473         state->fdc.disk_inserted[drive] = 0;
24362474   }
24372475
24382476   // initialise CRTC, set registers to defaults for the standard text mode (768x512)
2439   x68k_sys.crtc.reg[0] = 137;  // Horizontal total  (in characters)
2440   x68k_sys.crtc.reg[1] = 14;   // Horizontal sync end
2441   x68k_sys.crtc.reg[2] = 28;   // Horizontal start
2442   x68k_sys.crtc.reg[3] = 124;  // Horizontal end
2443   x68k_sys.crtc.reg[4] = 567;  // Vertical total
2444   x68k_sys.crtc.reg[5] = 5;    // Vertical sync end
2445   x68k_sys.crtc.reg[6] = 40;   // Vertical start
2446   x68k_sys.crtc.reg[7] = 552;  // Vertical end
2447   x68k_sys.crtc.reg[8] = 27;   // Horizontal adjust
2477   state->crtc.reg[0] = 137;  // Horizontal total  (in characters)
2478   state->crtc.reg[1] = 14;   // Horizontal sync end
2479   state->crtc.reg[2] = 28;   // Horizontal start
2480   state->crtc.reg[3] = 124;  // Horizontal end
2481   state->crtc.reg[4] = 567;  // Vertical total
2482   state->crtc.reg[5] = 5;    // Vertical sync end
2483   state->crtc.reg[6] = 40;   // Vertical start
2484   state->crtc.reg[7] = 552;  // Vertical end
2485   state->crtc.reg[8] = 27;   // Horizontal adjust
24482486
2449   mfp_init();
2487   mfp_init(machine);
24502488
2451   x68k_scanline = machine->primary_screen->vpos();// = x68k_sys.crtc.reg[6];  // Vertical start
2489   state->scanline = machine->primary_screen->vpos();// = state->crtc.reg[6];  // Vertical start
24522490
24532491   // start VBlank timer
2454   x68k_sys.crtc.vblank = 1;
2455   irq_time = machine->primary_screen->time_until_pos(x68k_sys.crtc.reg[6],2);
2456   timer_adjust_oneshot(x68k_vblank_irq, irq_time, 0);
2492   state->crtc.vblank = 1;
2493   irq_time = machine->primary_screen->time_until_pos(state->crtc.reg[6],2);
2494   timer_adjust_oneshot(state->vblank_irq, irq_time, 0);
24572495
24582496   // start HBlank timer
2459   timer_adjust_oneshot(x68k_scanline_timer, machine->primary_screen->scan_period(), 1);
2497   timer_adjust_oneshot(state->scanline_timer, machine->primary_screen->scan_period(), 1);
24602498
2461   x68k_sys.mfp.gpio = 0xfb;
2499   state->mfp.gpio = 0xfb;
24622500
24632501   // reset output values
24642502   output_set_value("key_led_kana",1);
r9669r9670
24862524   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
24872525   x68k_state *state = machine->driver_data<x68k_state>();
24882526   /*  Install RAM handlers  */
2489   x68k_spriteram = (UINT16*)memory_region(machine, "user1");
2527   state->spriteram = (UINT16*)memory_region(machine, "user1");
24902528   memory_install_read16_handler(space,0x000000,0xbffffb,0xffffffff,0,(read16_space_func)x68k_emptyram_r);
24912529   memory_install_write16_handler(space,0x000000,0xbffffb,0xffffffff,0,(write16_space_func)x68k_emptyram_w);
24922530   memory_install_readwrite_bank(space,0x000000,messram_get_size(machine->device("messram"))-1,0xffffffff,0,"bank1");
24932531   memory_set_bankptr(machine, "bank1",messram_get_ptr(machine->device("messram")));
24942532   memory_install_read16_handler(space,0xc00000,0xdfffff,0xffffffff,0,x68k_gvram_r);
24952533   memory_install_write16_handler(space,0xc00000,0xdfffff,0xffffffff,0,x68k_gvram_w);
2496   memory_set_bankptr(machine, "bank2",x68k_gvram);  // so that code in VRAM is executable - needed for Terra Cresta
2534   memory_set_bankptr(machine, "bank2",state->gvram);  // so that code in VRAM is executable - needed for Terra Cresta
24972535   memory_install_read16_handler(space,0xe00000,0xe7ffff,0xffffffff,0,x68k_tvram_r);
24982536   memory_install_write16_handler(space,0xe00000,0xe7ffff,0xffffffff,0,x68k_tvram_w);
2499   memory_set_bankptr(machine, "bank3",x68k_tvram);  // so that code in VRAM is executable - needed for Terra Cresta
2537   memory_set_bankptr(machine, "bank3",state->tvram);  // so that code in VRAM is executable - needed for Terra Cresta
25002538   memory_install_read16_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram_r);
25012539   memory_install_write16_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram_w);
25022540   memory_set_bankptr(machine, "bank4",state->m_nvram);  // so that code in SRAM is executable, there is an option for booting from SRAM
25032541
25042542   // start keyboard timer
2505   timer_adjust_periodic(kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5));  // every 5ms
2543   timer_adjust_periodic(state->kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5));  // every 5ms
25062544
25072545   // start mouse timer
2508   timer_adjust_periodic(mouse_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1));  // a guess for now
2509   x68k_sys.mouse.inputtype = 0;
2546   timer_adjust_periodic(state->mouse_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1));  // a guess for now
2547   state->mouse.inputtype = 0;
25102548
25112549   // start LED timer
2512   timer_adjust_periodic(led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400));
2550   timer_adjust_periodic(state->led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400));
25132551}
25142552
25152553static MACHINE_START( x68030 )
r9669r9670
25172555   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
25182556   x68k_state *state = machine->driver_data<x68k_state>();
25192557   /*  Install RAM handlers  */
2520   x68k_spriteram = (UINT16*)memory_region(machine, "user1");
2558   state->spriteram = (UINT16*)memory_region(machine, "user1");
25212559   memory_install_read32_handler(space,0x000000,0xbffffb,0xffffffff,0,(read32_space_func)x68k_rom0_r);
25222560   memory_install_write32_handler(space,0x000000,0xbffffb,0xffffffff,0,(write32_space_func)x68k_rom0_w);
25232561   memory_install_readwrite_bank(space,0x000000,messram_get_size(machine->device("messram"))-1,0xffffffff,0,"bank1");
r9669r9670
25272565   memory_set_bankptr(machine, "bank5",messram_get_ptr(machine->device("messram")));
25282566   memory_install_read32_handler(space,0xc00000,0xdfffff,0xffffffff,0,x68k_gvram32_r);
25292567   memory_install_write32_handler(space,0xc00000,0xdfffff,0xffffffff,0,x68k_gvram32_w);
2530   memory_set_bankptr(machine, "bank2",x68k_gvram);  // so that code in VRAM is executable - needed for Terra Cresta
2568   memory_set_bankptr(machine, "bank2",state->gvram);  // so that code in VRAM is executable - needed for Terra Cresta
25312569   memory_install_read32_handler(space,0xe00000,0xe7ffff,0xffffffff,0,x68k_tvram32_r);
25322570   memory_install_write32_handler(space,0xe00000,0xe7ffff,0xffffffff,0,x68k_tvram32_w);
2533   memory_set_bankptr(machine, "bank3",x68k_tvram);  // so that code in VRAM is executable - needed for Terra Cresta
2571   memory_set_bankptr(machine, "bank3",state->tvram);  // so that code in VRAM is executable - needed for Terra Cresta
25342572   memory_install_read32_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram32_r);
25352573   memory_install_write32_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram32_w);
25362574   memory_set_bankptr(machine, "bank4",state->m_nvram);  // so that code in SRAM is executable, there is an option for booting from SRAM
25372575
25382576   // start keyboard timer
2539   timer_adjust_periodic(kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5));  // every 5ms
2577   timer_adjust_periodic(state->kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5));  // every 5ms
25402578
25412579   // start mouse timer
2542   timer_adjust_periodic(mouse_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1));  // a guess for now
2543   x68k_sys.mouse.inputtype = 0;
2580   timer_adjust_periodic(state->mouse_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1));  // a guess for now
2581   state->mouse.inputtype = 0;
25442582
25452583   // start LED timer
2546   timer_adjust_periodic(led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400));
2584   timer_adjust_periodic(state->led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400));
25472585}
25482586
25492587static DRIVER_INIT( x68000 )
25502588{
2589   x68k_state *state = machine->driver_data<x68k_state>();
25512590   unsigned char* rom = memory_region(machine, "maincpu");
25522591   unsigned char* user2 = memory_region(machine, "user2");
2553   x68k_gvram = auto_alloc_array(machine, UINT16, 0x080000/sizeof(UINT16));
2554   x68k_tvram = auto_alloc_array(machine, UINT16, 0x080000/sizeof(UINT16));
2555   sram = auto_alloc_array(machine, UINT16, 0x4000/sizeof(UINT16));
2592   state->gvram = auto_alloc_array(machine, UINT16, 0x080000/sizeof(UINT16));
2593   state->tvram = auto_alloc_array(machine, UINT16, 0x080000/sizeof(UINT16));
2594   state->sram = auto_alloc_array(machine, UINT16, 0x4000/sizeof(UINT16));
25562595
2557   x68k_spritereg = auto_alloc_array_clear(machine, UINT16, 0x8000/sizeof(UINT16));
2596   state->spritereg = auto_alloc_array_clear(machine, UINT16, 0x8000/sizeof(UINT16));
25582597
25592598#ifdef USE_PREDEFINED_SRAM
25602599   {
25612600      unsigned char* ramptr = memory_region(machine, "user3");
2562      memcpy(sram,ramptr,0x4000);
2601      memcpy(state->sram,ramptr,0x4000);
25632602   }
25642603#endif
25652604
25662605   // copy last half of BIOS to a user region, to use for inital startup
25672606   memcpy(user2,(rom+0xff0000),0x10000);
25682607
2569   memset(&x68k_sys,0,sizeof(x68k_sys));
2608   mfp_init(machine);
25702609
2571   mfp_init();
2572
25732610   cpu_set_irq_callback(machine->device("maincpu"), x68k_int_ack);
25742611
25752612   // init keyboard
2576   x68k_sys.keyboard.delay = 500;  // 3*100+200
2577   x68k_sys.keyboard.repeat = 110;  // 4^2*5+30
2578   kb_timer = timer_alloc(machine, x68k_keyboard_poll,NULL);
2579   x68k_scanline_timer = timer_alloc(machine, x68k_hsync,NULL);
2580   x68k_raster_irq = timer_alloc(machine, x68k_crtc_raster_irq,NULL);
2581   x68k_vblank_irq = timer_alloc(machine, x68k_crtc_vblank_irq,NULL);
2582   mouse_timer = timer_alloc(machine, x68k_scc_ack,NULL);
2583   led_timer = timer_alloc(machine, x68k_led_callback,NULL);
2613   state->keyboard.delay = 500;  // 3*100+200
2614   state->keyboard.repeat = 110;  // 4^2*5+30
2615   state->kb_timer = timer_alloc(machine, x68k_keyboard_poll,NULL);
2616   state->scanline_timer = timer_alloc(machine, x68k_hsync,NULL);
2617   state->raster_irq = timer_alloc(machine, x68k_crtc_raster_irq,NULL);
2618   state->vblank_irq = timer_alloc(machine, x68k_crtc_vblank_irq,NULL);
2619   state->mouse_timer = timer_alloc(machine, x68k_scc_ack,NULL);
2620   state->led_timer = timer_alloc(machine, x68k_led_callback,NULL);
25842621
25852622   // Initialise timers for 6-button MD controllers
25862623   md_6button_init(machine);
25872624
2588   x68k_sys.sysport.cputype = 0xff;  // 68000, 10MHz
2625   state->sysport.cputype = 0xff;  // 68000, 10MHz
25892626}
25902627
25912628static DRIVER_INIT( x68kxvi )
25922629{
2630   x68k_state *state = machine->driver_data<x68k_state>();
25932631   DRIVER_INIT_CALL( x68000 );
2594   x68k_sys.sysport.cputype = 0xfe; // 68000, 16MHz
2632   state->sysport.cputype = 0xfe; // 68000, 16MHz
25952633}
25962634
25972635static DRIVER_INIT( x68030 )
25982636{
2637   x68k_state *state = machine->driver_data<x68k_state>();
25992638   DRIVER_INIT_CALL( x68000 );
2600   x68k_sys.sysport.cputype = 0xdc; // 68030, 25MHz
2639   state->sysport.cputype = 0xdc; // 68030, 25MHz
26012640}
26022641
26032642static MACHINE_CONFIG_START( x68000, x68k_state )
src/mess/drivers/vc4000.c
r9669r9670
241241   return IMAGE_INIT_PASS;
242242}
243243
244static MACHINE_CONFIG_START( vc4000, driver_device )
244static MACHINE_CONFIG_START( vc4000, vc4000_state )
245245   /* basic machine hardware */
246246//  MDRV_CPU_ADD("maincpu", S2650, 865000)        /* 3550000/4, 3580000/3, 4430000/3 */
247247   MDRV_CPU_ADD("maincpu", S2650, 3546875/4)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team