Previous 15994 Revisions Next

r7425 Friday 19th February, 2010 at 11:11:39 UTC by Fabio Priuli
[CBM] added driver_data struct to c16.c and cleaned up a few things
[src/mess/audio]ted7360.c
[src/mess/drivers]c16.c
[src/mess/includes]c16.h
[src/mess/machine]c16.c

src/mess/audio/ted7360.c
r7424r7425
14451445
14461446   memset(ted7360->reg, 0, ARRAY_LENGTH(ted7360->reg));
14471447
1448   ted7360->rom = 1;   // FIXME: at start should be RAM or ROM?
1448   ted7360->rom = 1;   // FIXME: at start should be RAM or ROM? old c16 code set it to ROM at init: is it correct?
14491449
14501450   ted7360->lines = TED7360_LINES;
14511451   ted7360->chargenaddr = ted7360->bitmapaddr = ted7360->videoaddr = 0;
src/mess/includes/c16.h
r7424r7425
77#ifndef __C16_H__
88#define __C16_H__
99
10typedef struct _c16_state c16_state;
11struct _c16_state
12{
13   /* memory pointers */
14   UINT8 *      mem10000;
15   UINT8 *      mem14000;
16   UINT8 *      mem18000;
17   UINT8 *      mem1c000;
18   UINT8 *      mem20000;
19   UINT8 *      mem24000;
20   UINT8 *      mem28000;
21   UINT8 *      mem2c000;
22
23   /* misc */
24   UINT8        keyline[10];
25   UINT8        port6529;
26   int          lowrom, highrom;
27   int          old_level;
28
29   int          sidcard, pal;
30
31   /* devices */
32   running_device *maincpu;
33   running_device *ted7360;
34   running_device *serbus;
35   running_device *cassette;
36   running_device *messram;
37   running_device *sid;
38};
39
40
1041/*----------- defined in machine/c16.c -----------*/
1142
1243UINT8 c16_m7501_port_read(running_device *device, UINT8 direction);
src/mess/machine/c16.c
r7424r7425
1010
1111#include "emu.h"
1212#include "image.h"
13#include "cpu/m6502/m6502.h"
14#include "sound/sid6581.h"
15
1613#include "audio/ted7360.h"
17#include "machine/cbmiec.h"
18
19#include "includes/c16.h"
20
14#include "cpu/m6502/m6502.h"
2115#include "devices/cassette.h"
2216#include "devices/cartslot.h"
23
2417#include "devices/messram.h"
18#include "includes/c16.h"
19#include "machine/cbmiec.h"
20#include "sound/sid6581.h"
2521
2622#define VERBOSE_LEVEL 0
2723#define DBG_LOG( MACHINE, N, M, A ) \
r7424r7425
3430      } \
3531   } while (0)
3632
37static UINT8 keyline[10] =
38{
39   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
40};
4133
4234/*
4335 * tia6523
r7424r7425
5244 * 7 ack input edge ready for next datum
5345 */
5446
55static int c16_has_sid, c16_pal;
56
57static UINT8 port6529;
58
59static int lowrom, highrom;
60
61static UINT8 *c16_memory_10000;
62static UINT8 *c16_memory_14000;
63static UINT8 *c16_memory_18000;
64static UINT8 *c16_memory_1c000;
65static UINT8 *c16_memory_20000;
66static UINT8 *c16_memory_24000;
67static UINT8 *c16_memory_28000;
68static UINT8 *c16_memory_2c000;
69
7047/*
7148  ddr bit 1 port line is output
7249  port bit 1 port line is high
r7424r7425
9370
9471void c16_m7501_port_write( running_device *device, UINT8 direction, UINT8 data )
9572{
96   running_device *serbus = devtag_get_device(device->machine, "iec");
73   c16_state *state = (c16_state *)device->machine->driver_data;
9774
9875   /* bit zero then output 0 */
99   cbm_iec_atn_w(serbus, device, !(data & 0x04));
100   cbm_iec_clk_w(serbus, device, !(data & 0x02));
101   cbm_iec_data_w(serbus, device, !(data & 0x01));
76   cbm_iec_atn_w(state->serbus, device, !BIT(data, 2));
77   cbm_iec_clk_w(state->serbus, device, !BIT(data, 1));
78   cbm_iec_data_w(state->serbus, device, !BIT(data, 0));
10279
103   cassette_output(devtag_get_device(device->machine, "cassette"), !(data & 0x02) ? -(0x5a9e >> 1) : +(0x5a9e >> 1));
80   cassette_output(state->cassette, !BIT(data, 1) ? -(0x5a9e >> 1) : +(0x5a9e >> 1));
10481
105   cassette_change_state(devtag_get_device(device->machine, "cassette"), (data & 0x08) ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR);
82   cassette_change_state(state->cassette, BIT(data, 7) ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR);
10683}
10784
10885UINT8 c16_m7501_port_read( running_device *device, UINT8 direction )
10986{
87   c16_state *state = (c16_state *)device->machine->driver_data;
11088   UINT8 data = 0xff;
111   UINT8 c16_port7501 = (UINT8) device->machine->device("maincpu")->get_runtime_int(CPUINFO_INT_M6510_PORT);
112   running_device *serbus = devtag_get_device(device->machine, "iec");
89   UINT8 c16_port7501 = (UINT8) state->maincpu->get_runtime_int(CPUINFO_INT_M6510_PORT);
11390
114   if ((c16_port7501 & 0x01) || !cbm_iec_data_r(serbus))
91   if (BIT(c16_port7501, 0) || !cbm_iec_data_r(state->serbus))
11592      data &= ~0x80;
11693
117   if ((c16_port7501 & 0x02) || !cbm_iec_clk_r(serbus))
94   if (BIT(c16_port7501, 1) || !cbm_iec_clk_r(state->serbus))
11895      data &= ~0x40;
11996
12097//  data &= ~0x20; // port bit not in pinout
12198
122   if (cassette_input(devtag_get_device(device->machine, "cassette")) > +0.0)
99   if (cassette_input(state->cassette) > +0.0)
123100      data |=  0x10;
124101   else
125102      data &= ~0x10;
r7424r7425
129106
130107static void c16_bankswitch( running_machine *machine )
131108{
109   c16_state *state = (c16_state *)machine->driver_data;
132110   UINT8 *rom = memory_region(machine, "maincpu");
133   memory_set_bankptr(machine, "bank9", messram_get_ptr(devtag_get_device(machine, "messram")));
111   memory_set_bankptr(machine, "bank9", messram_get_ptr(state->messram));
134112
135   switch (lowrom)
113   switch (state->lowrom)
136114   {
137115   case 0:
138116      memory_set_bankptr(machine, "bank2", rom + 0x10000);
r7424r7425
148126      break;
149127   }
150128
151   switch (highrom)
129   switch (state->highrom)
152130   {
153131   case 0:
154132      memory_set_bankptr(machine, "bank3", rom + 0x14000);
r7424r7425
172150
173151WRITE8_HANDLER( c16_switch_to_rom )
174152{
175   running_device *ted7360 = devtag_get_device(space->machine, "ted7360");
153   c16_state *state = (c16_state *)space->machine->driver_data;
176154
177   ted7360_rom_switch_w(ted7360, 1);
155   ted7360_rom_switch_w(state->ted7360, 1);
178156   c16_bankswitch(space->machine);
179157}
180158
r7424r7425
193171 * 1  1  c2 high */
194172WRITE8_HANDLER( c16_select_roms )
195173{
196   running_device *ted7360 = devtag_get_device(space->machine, "ted7360");
174   c16_state *state = (c16_state *)space->machine->driver_data;
197175
198   lowrom = offset & 0x03;
199   highrom = (offset & 0x0c) >> 2;
200   if (ted7360_rom_switch_r(ted7360))
176   state->lowrom = offset & 0x03;
177   state->highrom = (offset & 0x0c) >> 2;
178   if (ted7360_rom_switch_r(state->ted7360))
201179      c16_bankswitch(space->machine);
202180}
203181
204182WRITE8_HANDLER( c16_switch_to_ram )
205183{
206   running_device *ted7360 = devtag_get_device(space->machine, "ted7360");
184   c16_state *state = (c16_state *)space->machine->driver_data;
207185
208   ted7360_rom_switch_w(ted7360, 0);
186   ted7360_rom_switch_w(state->ted7360, 0);
209187
210   memory_set_bankptr(space->machine, "bank2", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0x8000 % messram_get_size(devtag_get_device(space->machine, "messram"))));
211   memory_set_bankptr(space->machine, "bank3", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xc000 % messram_get_size(devtag_get_device(space->machine, "messram"))));
212   memory_set_bankptr(space->machine, "bank4", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xfc00 % messram_get_size(devtag_get_device(space->machine, "messram"))));
213   memory_set_bankptr(space->machine, "bank8", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xff20 % messram_get_size(devtag_get_device(space->machine, "messram"))));
188   memory_set_bankptr(space->machine, "bank2", messram_get_ptr(state->messram) + (0x8000 % messram_get_size(state->messram)));
189   memory_set_bankptr(space->machine, "bank3", messram_get_ptr(state->messram) + (0xc000 % messram_get_size(state->messram)));
190   memory_set_bankptr(space->machine, "bank4", messram_get_ptr(state->messram) + (0xfc00 % messram_get_size(state->messram)));
191   memory_set_bankptr(space->machine, "bank8", messram_get_ptr(state->messram) + (0xff20 % messram_get_size(state->messram)));
214192}
215193
216194UINT8 c16_read_keyboard( running_machine *machine, int databus )
217195{
196   c16_state *state = (c16_state *)machine->driver_data;
218197   UINT8 value = 0xff;
198   int i;
219199
220   if (!(port6529 & 0x01))
221      value &= keyline[0];
200   for (i = 0; i < 8; i++)
201   {
202      if (!BIT(state->port6529, i))
203         value &= state->keyline[i];
204   }
222205
223   if (!(port6529 & 0x02))
224      value &= keyline[1];
225
226   if (!(port6529 & 0x04))
227      value &= keyline[2];
228
229   if (!(port6529 & 0x08))
230      value &= keyline[3];
231
232   if (!(port6529 & 0x10))
233      value &= keyline[4];
234
235   if (!(port6529 & 0x20))
236      value &= keyline[5];
237
238   if (!(port6529 & 0x40))
239      value &= keyline[6];
240
241   if (!(port6529 & 0x80))
242      value &= keyline[7];
243
244206   /* looks like joy 0 needs dataline2 low
245207     * and joy 1 needs dataline1 low
246208     * write to 0xff08 (value on databus) reloads latches */
247   if (!(databus & 0x04))
248      value &= keyline[8];
209   if (!BIT(databus, 2))
210      value &= state->keyline[8];
249211
250   if (!(databus & 0x02))
251      value &= keyline[9];
212   if (!BIT(databus, 1))
213      value &= state->keyline[9];
252214
253215   return value;
254216}
r7424r7425
266228 */
267229WRITE8_HANDLER( c16_6529_port_w )
268230{
269   port6529 = data;
231   c16_state *state = (c16_state *)space->machine->driver_data;
232   state->port6529 = data;
270233}
271234
272235READ8_HANDLER( c16_6529_port_r )
273236{
274   return port6529 & (c16_read_keyboard (space->machine, 0xff /*databus */ ) | (port6529 ^ 0xff));
237   c16_state *state = (c16_state *)space->machine->driver_data;
238   return state->port6529 & (c16_read_keyboard (space->machine, 0xff /*databus */ ) | (state->port6529 ^ 0xff));
275239}
276240
277241/*
r7424r7425
290254
291255READ8_HANDLER( plus4_6529_port_r )
292256{
257   c16_state *state = (c16_state *)space->machine->driver_data;
293258   int data = 0x00;
294259
295   if ((cassette_get_state(devtag_get_device(space->machine, "cassette")) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED)
260   if ((cassette_get_state(state->cassette) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED)
296261      data &= ~0x04;
297262   else
298263      data |=  0x04;
r7424r7425
302267
303268READ8_HANDLER( c16_fd1x_r )
304269{
270   c16_state *state = (c16_state *)space->machine->driver_data;
305271   int data = 0x00;
306272
307   if ((cassette_get_state(devtag_get_device(space->machine, "cassette")) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED)
273   if ((cassette_get_state(state->cassette) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED)
308274      data &= ~0x04;
309275   else
310276      data |=  0x04;
r7424r7425
351317  */
352318WRITE8_HANDLER( c16_6551_port_w )
353319{
320   c16_state *state = (c16_state *)space->machine->driver_data;
321
354322   offset &= 0x03;
355323   DBG_LOG(space->machine, 3, "6551", ("port write %.2x %.2x\n", offset, data));
356   port6529 = data;
324   state->port6529 = data;
357325}
358326
359327READ8_HANDLER( c16_6551_port_r )
r7424r7425
367335
368336int c16_dma_read( running_machine *machine, int offset )
369337{
370   return messram_get_ptr(devtag_get_device(machine, "messram"))[offset % messram_get_size(devtag_get_device(machine, "messram"))];
338   c16_state *state = (c16_state *)machine->driver_data;
339   return messram_get_ptr(state->messram)[offset % messram_get_size(state->messram)];
371340}
372341
373342int c16_dma_read_rom( running_machine *machine, int offset )
374343{
344   c16_state *state = (c16_state *)machine->driver_data;
345
375346   /* should read real c16 system bus from 0xfd00 -ff1f */
376347   if (offset >= 0xc000)
377348   {                           /* rom address in rom */
378349      if ((offset >= 0xfc00) && (offset < 0xfd00))
379         return c16_memory_10000[offset];
350         return state->mem10000[offset];
380351
381      switch (highrom)
352      switch (state->highrom)
382353      {
383354         case 0:
384            return c16_memory_10000[offset & 0x7fff];
355            return state->mem10000[offset & 0x7fff];
385356         case 1:
386            return c16_memory_18000[offset & 0x7fff];
357            return state->mem18000[offset & 0x7fff];
387358         case 2:
388            return c16_memory_20000[offset & 0x7fff];
359            return state->mem20000[offset & 0x7fff];
389360         case 3:
390            return c16_memory_28000[offset & 0x7fff];
361            return state->mem28000[offset & 0x7fff];
391362      }
392363   }
393364
394365   if (offset >= 0x8000)
395366   {                           /* rom address in rom */
396      switch (lowrom)
367      switch (state->lowrom)
397368      {
398369         case 0:
399            return c16_memory_10000[offset & 0x7fff];
370            return state->mem10000[offset & 0x7fff];
400371         case 1:
401            return c16_memory_18000[offset & 0x7fff];
372            return state->mem18000[offset & 0x7fff];
402373         case 2:
403            return c16_memory_20000[offset & 0x7fff];
374            return state->mem20000[offset & 0x7fff];
404375         case 3:
405            return c16_memory_28000[offset & 0x7fff];
376            return state->mem28000[offset & 0x7fff];
406377      }
407378   }
408379
409   return messram_get_ptr(devtag_get_device(machine, "messram"))[offset % messram_get_size(devtag_get_device(machine, "messram"))];
380   return messram_get_ptr(state->messram)[offset % messram_get_size(state->messram)];
410381}
411382
412383void c16_interrupt( running_machine *machine, int level )
413384{
414   static int old_level;
385   c16_state *state = (c16_state *)machine->driver_data;
415386
416   if (level != old_level)
387   if (level != state->old_level)
417388   {
418389      DBG_LOG(machine, 3, "mos7501", ("irq %s\n", level ? "start" : "end"));
419      cputag_set_input_line(machine, "maincpu", M6510_IRQ_LINE, level);
420      old_level = level;
390      cpu_set_input_line(state->maincpu, M6510_IRQ_LINE, level);
391      state->old_level = level;
421392   }
422393}
423394
424395static void c16_common_driver_init( running_machine *machine )
425396{
426   UINT8 *rom;
397   c16_state *state = (c16_state *)machine->driver_data;
398   UINT8 *rom = memory_region(machine, "maincpu");
427399
428   lowrom = 0;
429   highrom = 0;
400   /* initial bankswitch (notice that TED7360 is init to ROM) */
401   memory_set_bankptr(machine, "bank2", rom + 0x10000);
402   memory_set_bankptr(machine, "bank3", rom + 0x14000);
403   memory_set_bankptr(machine, "bank4", rom + 0x17c00);
404   memory_set_bankptr(machine, "bank8", rom + 0x17f20);
430405
431   c16_select_roms (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), 0, 0);
432   c16_switch_to_rom (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), 0, 0);
433
434   rom = memory_region(machine, "maincpu");
435
436   c16_memory_10000 = rom + 0x10000;
437   c16_memory_14000 = rom + 0x14000;
438   c16_memory_18000 = rom + 0x18000;
439   c16_memory_1c000 = rom + 0x1c000;
440   c16_memory_20000 = rom + 0x20000;
441   c16_memory_24000 = rom + 0x24000;
442   c16_memory_28000 = rom + 0x28000;
443   c16_memory_2c000 = rom + 0x2c000;
406   state->mem10000 = rom + 0x10000;
407   state->mem14000 = rom + 0x14000;
408   state->mem18000 = rom + 0x18000;
409   state->mem1c000 = rom + 0x1c000;
410   state->mem20000 = rom + 0x20000;
411   state->mem24000 = rom + 0x24000;
412   state->mem28000 = rom + 0x28000;
413   state->mem2c000 = rom + 0x2c000;
444414}
445415
446416DRIVER_INIT( c16 )
447417{
418   c16_state *state = (c16_state *)machine->driver_data;
448419   c16_common_driver_init(machine);
449420
450   c16_has_sid = 0;
451   c16_pal = 1;
421   state->sidcard = 0;
422   state->pal = 1;
452423}
453424
454425DRIVER_INIT( plus4 )
455426{
427   c16_state *state = (c16_state *)machine->driver_data;
456428   c16_common_driver_init(machine);
457429
458   c16_has_sid = 0;
459   c16_pal = 0;
430   state->sidcard = 0;
431   state->pal = 0;
460432}
461433
462434DRIVER_INIT( c16sid )
463435{
436   c16_state *state = (c16_state *)machine->driver_data;
464437   c16_common_driver_init(machine);
465438
466   c16_has_sid = 1;
467   c16_pal = 1;
439   state->sidcard = 1;
440   state->pal = 1;
468441}
469442
470443DRIVER_INIT( plus4sid )
471444{
445   c16_state *state = (c16_state *)machine->driver_data;
472446   c16_common_driver_init(machine);
473447
474   c16_has_sid = 1;
475   c16_pal = 0;
448   state->sidcard = 1;
449   state->pal = 0;
476450}
477451
478452MACHINE_RESET( c16 )
479453{
480454   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
455   c16_state *state = (c16_state *)machine->driver_data;
481456
482   if (c16_pal)
457   memset(state->keyline, 0xff, ARRAY_LENGTH(state->keyline));
458
459   state->lowrom = 0;
460   state->highrom = 0;
461   state->old_level = 0;
462   state->port6529 = 0;
463
464   if (state->pal)
483465   {
484      memory_set_bankptr(machine, "bank1", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x4000 % messram_get_size(devtag_get_device(machine, "messram"))));
466      memory_set_bankptr(machine, "bank1", messram_get_ptr(state->messram) + (0x4000 % messram_get_size(state->messram)));
485467
486      memory_set_bankptr(machine, "bank5", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x4000 % messram_get_size(devtag_get_device(machine, "messram"))));
487      memory_set_bankptr(machine, "bank6", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x8000 % messram_get_size(devtag_get_device(machine, "messram"))));
488      memory_set_bankptr(machine, "bank7", messram_get_ptr(devtag_get_device(machine, "messram")) + (0xc000 % messram_get_size(devtag_get_device(machine, "messram"))));
468      memory_set_bankptr(machine, "bank5", messram_get_ptr(state->messram) + (0x4000 % messram_get_size(state->messram)));
469      memory_set_bankptr(machine, "bank6", messram_get_ptr(state->messram) + (0x8000 % messram_get_size(state->messram)));
470      memory_set_bankptr(machine, "bank7", messram_get_ptr(state->messram) + (0xc000 % messram_get_size(state->messram)));
489471
490472      memory_install_write_bank(space, 0xff20, 0xff3d, 0, 0,"bank10");
491473      memory_install_write_bank(space, 0xff40, 0xffff, 0, 0, "bank11");
492      memory_set_bankptr(machine, "bank10", messram_get_ptr(devtag_get_device(machine, "messram")) + (0xff20 % messram_get_size(devtag_get_device(machine, "messram"))));
493      memory_set_bankptr(machine, "bank11", messram_get_ptr(devtag_get_device(machine, "messram")) + (0xff40 % messram_get_size(devtag_get_device(machine, "messram"))));
474      memory_set_bankptr(machine, "bank10", messram_get_ptr(state->messram) + (0xff20 % messram_get_size(state->messram)));
475      memory_set_bankptr(machine, "bank11", messram_get_ptr(state->messram) + (0xff40 % messram_get_size(state->messram)));
494476   }
495477   else
496478   {
497479      memory_install_write_bank(space, 0x4000, 0xfcff, 0, 0, "bank10");
498      memory_set_bankptr(machine, "bank10", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x4000 % messram_get_size(devtag_get_device(machine, "messram"))));
480      memory_set_bankptr(machine, "bank10", messram_get_ptr(state->messram) + (0x4000 % messram_get_size(state->messram)));
499481   }
500482}
501483
r7424r7425
505487// would a real SID Card allow for this? If not, this should be removed completely
506488static WRITE8_HANDLER( c16_sidcart_16k )
507489{
508   running_device *sid = devtag_get_device(space->machine, "sid");
490   c16_state *state = (c16_state *)space->machine->driver_data;
509491
510   messram_get_ptr(devtag_get_device(space->machine, "messram"))[0x1400 + offset] = data;
511   messram_get_ptr(devtag_get_device(space->machine, "messram"))[0x5400 + offset] = data;
512   messram_get_ptr(devtag_get_device(space->machine, "messram"))[0x9400 + offset] = data;
513   messram_get_ptr(devtag_get_device(space->machine, "messram"))[0xd400 + offset] = data;
492   messram_get_ptr(state->messram)[0x1400 + offset] = data;
493   messram_get_ptr(state->messram)[0x5400 + offset] = data;
494   messram_get_ptr(state->messram)[0x9400 + offset] = data;
495   messram_get_ptr(state->messram)[0xd400 + offset] = data;
514496
515   sid6581_w(sid, offset, data);
497   sid6581_w(state->sid, offset, data);
516498}
517499
518500static WRITE8_HANDLER( c16_sidcart_64k )
519501{
520   running_device *sid = devtag_get_device(space->machine, "sid");
502   c16_state *state = (c16_state *)space->machine->driver_data;
521503
522   messram_get_ptr(devtag_get_device(space->machine, "messram"))[0xd400 + offset] = data;
504   messram_get_ptr(state->messram)[0xd400 + offset] = data;
523505
524   sid6581_w(sid, offset, data);
506   sid6581_w(state->sid, offset, data);
525507}
526508
527509static TIMER_CALLBACK( c16_sidhack_tick )
528510{
529511   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
512   c16_state *state = (c16_state *)space->machine->driver_data;
530513
531514   if (input_port_read_safe(machine, "SID", 0x00) & 0x02)
532515   {
533      if (c16_pal)
516      if (state->pal)
534517         memory_install_write8_handler(space, 0xd400, 0xd41f, 0, 0, c16_sidcart_16k);
535518      else
536519         memory_install_write8_handler(space, 0xd400, 0xd41f, 0, 0, c16_sidcart_64k);
r7424r7425
544527
545528static TIMER_CALLBACK( c16_sidcard_tick )
546529{
547   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
548   running_device *sid = devtag_get_device(machine, "sid");
530   c16_state *state = (c16_state *)machine->driver_data;
531   const address_space *space = cpu_get_address_space(state->maincpu, ADDRESS_SPACE_PROGRAM);
549532
550533   if (input_port_read_safe(machine, "SID", 0x00) & 0x01)
551   {
552      memory_install_readwrite8_device_handler(space, sid, 0xfe80, 0xfe9f, 0, 0, sid6581_r, sid6581_w);
553   }
534      memory_install_readwrite8_device_handler(space, state->sid, 0xfe80, 0xfe9f, 0, 0, sid6581_r, sid6581_w);
554535   else
555   {
556      memory_install_readwrite8_device_handler(space, sid, 0xfd40, 0xfd5f, 0, 0, sid6581_r, sid6581_w);
557   }
536      memory_install_readwrite8_device_handler(space, state->sid, 0xfd40, 0xfd5f, 0, 0, sid6581_r, sid6581_w);
558537}
559538
560539INTERRUPT_GEN( c16_frame_interrupt )
561540{
562   running_device *ted7360 = devtag_get_device(device->machine, "ted7360");
541   c16_state *state = (c16_state *)device->machine->driver_data;
563542   int value, i;
564543   static const char *const c16ports[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7" };
565544
r7424r7425
573552      if ((i == 1) && (input_port_read(device->machine, "SPECIAL") & 0x80))
574553         value &= ~0x80;
575554
576      keyline[i] = value;
555      state->keyline[i] = value;
577556   }
578557
579558   if (input_port_read(device->machine, "CTRLSEL") & 0x01)
r7424r7425
590569      value &= ~(input_port_read(device->machine, "JOY0") & 0x0f);   /* Other Inputs Joypad1 */
591570
592571      if (input_port_read(device->machine, "SPECIAL") & 0x40)
593         keyline[9] = value;
572         state->keyline[9] = value;
594573      else
595         keyline[8] = value;
574         state->keyline[8] = value;
596575   }
597576
598577   if (input_port_read(device->machine, "CTRLSEL") & 0x10)
r7424r7425
609588      value &= ~(input_port_read(device->machine, "JOY1") & 0x0f);   /* Other Inputs Joypad2 */
610589
611590      if (input_port_read(device->machine, "SPECIAL") & 0x40)
612         keyline[8] = value;
591         state->keyline[8] = value;
613592      else
614         keyline[9] = value;
593         state->keyline[9] = value;
615594   }
616595
617   ted7360_frame_interrupt_gen(ted7360);
596   ted7360_frame_interrupt_gen(state->ted7360);
618597
619   if (c16_has_sid)
598   if (state->sidcard)
620599   {
621600      /* if we are emulating the SID card, check which memory area should be accessed */
622601      timer_set(device->machine, attotime_zero, NULL, 0, c16_sidcard_tick);
src/mess/drivers/c16.c
r7424r7425
113113
114114
115115#include "emu.h"
116#include "cpu/m6502/m6502.h"
117#include "sound/sid6581.h"
118
119116#include "audio/ted7360.h"
120117#include "audio/t6721.h"
121#include "machine/cbmipt.h"
118#include "cpu/m6502/m6502.h"
122119#include "devices/messram.h"
120#include "includes/cbm.h"
121#include "includes/c16.h"
123122#include "machine/c1541.h"
124123#include "machine/c1551.h"
125
126/* devices config */
127#include "includes/cbm.h"
128124#include "machine/cbmiec.h"
125#include "machine/cbmipt.h"
126#include "sound/sid6581.h"
129127
130#include "includes/c16.h"
131128
132129/*************************************
133130 *
r7424r7425
434431
435432static VIDEO_UPDATE( c16 )
436433{
437   running_device *ted7360 = devtag_get_device(screen->machine, "ted7360");
438   ted7360_video_update(ted7360, bitmap, cliprect);
434   c16_state *state = (c16_state *)screen->machine->driver_data;
435   ted7360_video_update(state->ted7360, bitmap, cliprect);
439436   return 0;
440437}
441438
442439static INTERRUPT_GEN( c16_raster_interrupt )
443440{
444   running_device *ted7360 = devtag_get_device(device->machine, "ted7360");
445   ted7360_raster_interrupt_gen(ted7360);
441   c16_state *state = (c16_state *)device->machine->driver_data;
442   ted7360_raster_interrupt_gen(state->ted7360);
446443}
447444
448445
446static MACHINE_START( c16 )
447{
448   c16_state *state = (c16_state *)machine->driver_data;
449
450   state->maincpu = devtag_get_device(machine, "maincpu");
451   state->ted7360 = devtag_get_device(machine, "ted7360");
452   state->serbus = devtag_get_device(machine, "iec");
453   state->cassette = devtag_get_device(machine, "cassette");
454   state->messram = devtag_get_device(machine, "messram");
455   state->sid = devtag_get_device(machine, "sid");
456
457   state_save_register_global(machine, state->old_level);
458   state_save_register_global(machine, state->lowrom);
459   state_save_register_global(machine, state->highrom);
460   state_save_register_global(machine, state->port6529);
461   state_save_register_global_array(machine, state->keyline);
462}
463
449464static MACHINE_DRIVER_START( c16 )
465
466   /* driver data */
467   MDRV_DRIVER_DATA(c16_state)
468
450469   /* basic machine hardware */
451470   MDRV_CPU_ADD("maincpu", M7501, XTAL_17_73447MHz/20)
452471   MDRV_CPU_PROGRAM_MAP(c16_map)
r7424r7425
455474   MDRV_CPU_PERIODIC_INT(c16_raster_interrupt, TED7360_HRETRACERATE)
456475   MDRV_QUANTUM_TIME(HZ(60))
457476
477   MDRV_MACHINE_START( c16 )
458478   MDRV_MACHINE_RESET( c16 )
459479
460480   /* video hardware */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team