Previous 15994 Revisions Next

r7394 Wednesday 17th February, 2010 at 17:22:32 UTC by Fabio Priuli
[CBM] wip:
- Moved MOS6560 emulation to MAME (for attckufo, which uses a downgraded version of the same chip)
- Made some cosmetic cleanups
- Updated vic20 to use the new code.
[src/emu/sound]mos6560.c* mos6560.h* sound.mak
[src/mess]mess.mak
[src/mess/audio]vic6560.c vic6560.h
[src/mess/drivers]vic20.c
[src/mess/includes]vic20.h

src/emu/sound/mos6560.c
r0r7394
1/***************************************************************************
2
3    MOS 6560 / 6561 Video Interface Chip
4
5
6    Original code by PeT (mess@utanet.at), 1999
7
8
9    2010 FP: converted to a device and merged the video & sound components
10
11    TODO:
12      - plenty of cleanups!
13      - investigate attckufo chip features (no invert mode, no multicolor, 16 col chars)
14      - investigate why some vic20 carts crash emulation
15
16****************************************************************************
17
18    Original notes:
19
20    2 Versions
21    6560 NTSC
22    6561 PAL
23    14 bit addr bus
24    12 bit data bus
25    (16 8 bit registers)
26    alternates with MOS 6502 on the address bus
27    fetch 8 bit characternumber and 4 bit color
28    high bit of 4 bit color value determines:
29    0: 2 color mode
30    1: 4 color mode
31    than fetch characterbitmap for characternumber
32    2 color mode:
33    set bit in characterbitmap gives pixel in color of the lower 3 color bits
34    cleared bit gives pixel in backgroundcolor
35    4 color mode:
36    2 bits in the characterbitmap are viewed together
37    00: backgroundcolor
38    11: colorram
39    01: helpercolor
40    10: framecolor
41    advance to next character in videorram until line is full
42    repeat this 8 or 16 lines, before moving to next line in videoram
43    screen ratio ntsc, pal 4/3
44
45    pal version:
46    can contain greater visible areas
47    expects other sync position (so ntsc modules may be displayed at
48    the upper left corner of the tv screen)
49    pixel ratio seems to be different on pal and ntsc
50
51    commodore vic20 notes
52    6560 adress line 13 is connected inverted to address line 15 of the board
53    1 K 4 bit ram at 0x9400 is additional connected as 4 higher bits
54    of the 6560 (colorram) without decoding the 6560 address line a8..a13
55
56*****************************************************************************/
57
58
59#include "emu.h"
60#include "streams.h"
61#include "sound/mos6560.h"
62
63/***************************************************************************
64 TYPE DEFINITIONS
65***************************************************************************/
66
67typedef struct _mos6560_state  mos6560_state;
68struct _mos6560_state
69{
70   mos6560_type  type;
71
72   running_device *screen;
73
74   UINT8 reg[16];
75
76   bitmap_t *bitmap;
77
78   int rasterline, lastline;
79   double lightpenreadtime;
80
81   int charheight, matrix8x16, inverted;
82   int chars_x, chars_y;
83   int xsize, ysize, xpos, ypos;
84   int chargenaddr, videoaddr;
85
86   /* values in videoformat */
87   UINT16 backgroundcolor, framecolor, helpercolor;
88
89   /* arrays for bit to color conversion without condition checking */
90   UINT16 mono[2], monoinverted[2], multi[4], multiinverted[4];
91
92   /* video chip settings */
93   int total_xsize, total_ysize, total_lines, total_vretracerate;
94
95   /* DMA */
96   mos6560_dma_read          dma_read;
97   mos6560_dma_read_color    dma_read_color;
98
99   /* lightpen */
100   mos6560_lightpen_button_callback lightpen_button_cb;
101   mos6560_lightpen_x_callback lightpen_x_cb;
102   mos6560_lightpen_y_callback lightpen_y_cb;
103
104   /* paddles */
105   mos6560_paddle_callback        paddle_cb[2];
106
107   /* sound part */
108   int tone1pos, tone2pos, tone3pos,
109   tonesize, tone1samples, tone2samples, tone3samples,
110   noisesize,        /* number of samples */
111   noisepos,         /* pos of tone */
112   noisesamples;     /* count of samples to give out per tone */
113
114   sound_stream *channel;
115   INT16 *tone;
116   INT8 *noise;
117};
118
119/*****************************************************************************
120    INLINE FUNCTIONS
121*****************************************************************************/
122
123INLINE mos6560_state *get_safe_token( running_device *device )
124{
125   assert(device != NULL);
126   assert(device->token != NULL);
127   assert(device->type == MOS6560);
128
129   return (mos6560_state *)device->token;
130}
131
132INLINE const mos6560_interface *get_interface( running_device *device )
133{
134   assert(device != NULL);
135   assert((device->type == MOS6560));
136   return (const mos6560_interface *) device->baseconfig().static_config;
137}
138
139/*****************************************************************************
140    PARAMETERS
141*****************************************************************************/
142
143#define VERBOSE_LEVEL 0
144#define DBG_LOG(N,M,A) \
145   do { \
146      if(VERBOSE_LEVEL >= N) \
147      { \
148         if( M ) \
149            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(device->machine)), (char*) M ); \
150         logerror A; \
151      } \
152   } while (0)
153
154
155/* 2008-05 FP: lightpen code needs to read input port from vc20.c */
156
157#define LIGHTPEN_BUTTON      ((mos6560->lightpen_button_cb != NULL) ? mos6560->lightpen_button_cb(device->machine) : 0)
158#define LIGHTPEN_X_VALUE   ((mos6560->lightpen_x_cb != NULL) ? mos6560->lightpen_x_cb(device->machine) : 0)
159#define LIGHTPEN_Y_VALUE   ((mos6560->lightpen_y_cb != NULL) ? mos6560->lightpen_y_cb(device->machine) : 0)
160
161/* lightpen delivers values from internal counters
162 * they do not start with the visual area or frame area */
163#define MOS6560_X_BEGIN 38
164#define MOS6560_Y_BEGIN -6            /* first 6 lines after retrace not for lightpen! */
165#define MOS6561_X_BEGIN 38
166#define MOS6561_Y_BEGIN -6
167#define MOS656X_X_BEGIN ((mos6560->type == MOS6561) ? MOS6561_X_BEGIN : MOS6560_X_BEGIN)
168#define MOS656X_Y_BEGIN ((mos6560->type == MOS6561) ? MOS6561_Y_BEGIN : MOS6560_Y_BEGIN)
169
170#define MOS656X_MAME_XPOS ((mos6560->type == MOS6561) ? MOS6561_MAME_XPOS : MOS6560_MAME_XPOS)
171#define MOS656X_MAME_YPOS ((mos6560->type == MOS6561) ? MOS6561_MAME_YPOS : MOS6560_MAME_YPOS)
172
173/* lightpen behaviour in pal or mono multicolor not tested */
174#define MOS656X_X_VALUE ((LIGHTPEN_X_VALUE + MOS656X_X_BEGIN + MOS656X_MAME_XPOS)/2)
175#define MOS656X_Y_VALUE ((LIGHTPEN_Y_VALUE + MOS656X_Y_BEGIN + MOS656X_MAME_YPOS)/2)
176
177#define MOS656X_VRETRACERATE ((mos6560->type == MOS6561) ? MOS6561_VRETRACERATE : MOS6560_VRETRACERATE)
178
179/* ntsc 1 - 8 */
180/* pal 5 - 19 */
181#define XPOS (((int)mos6560->reg[0] & 0x7f) * 4)
182#define YPOS ((int)mos6560->reg[1] * 2)
183
184/* ntsc values >= 31 behave like 31 */
185/* pal value >= 32 behave like 32 */
186#define CHARS_X ((int)mos6560->reg[2] & 0x7f)
187#define CHARS_Y (((int)mos6560->reg[3] & 0x7e) >> 1)
188
189/* colorram and backgroundcolor are changed */
190#define INVERTED (!(mos6560->reg[0x0f] & 8))
191
192#define CHARGENADDR (((int)mos6560->reg[5] & 0x0f) << 10)
193#define VIDEOADDR ((((int)mos6560->reg[5] & 0xf0) << (10 - 4)) | (((int)mos6560->reg[2] & 0x80) << (9-7)))
194#define VIDEORAMSIZE (YSIZE * XSIZE)
195#define CHARGENSIZE (256 * HEIGHTPIXEL)
196
197#define HELPERCOLOR (mos6560->reg[0x0e] >> 4)
198#define BACKGROUNDCOLOR (mos6560->reg[0x0f] >> 4)
199#define FRAMECOLOR (mos6560->reg[0x0f] & 0x07)
200
201/*****************************************************************************
202    IMPLEMENTATION
203*****************************************************************************/
204
205static void mos6560_soundport_w( running_device *device, int offset, int data );
206
207/*-------------------------------------------------
208 mos6560_draw_character
209-------------------------------------------------*/
210
211static void mos6560_draw_character( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, UINT16 *color )
212{
213   mos6560_state *mos6560 = get_safe_token(device);
214   int y, code;
215
216   for (y = ybegin; y <= yend; y++)
217   {
218      code = mos6560->dma_read(device->machine, (mos6560->chargenaddr + ch * mos6560->charheight + y) & 0x3fff);
219      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 0) = color[code >> 7];
220      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 1) = color[(code >> 6) & 1];
221      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 2) = color[(code >> 5) & 1];
222      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 3) = color[(code >> 4) & 1];
223      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 4) = color[(code >> 3) & 1];
224      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 5) = color[(code >> 2) & 1];
225      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 6) = color[(code >> 1) & 1];
226      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 7) = color[code & 1];
227   }
228}
229
230
231/*-------------------------------------------------
232 mos6560_draw_character_multi
233-------------------------------------------------*/
234
235static void mos6560_draw_character_multi( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, UINT16 *color )
236{
237   mos6560_state *mos6560 = get_safe_token(device);
238   int y, code;
239
240   for (y = ybegin; y <= yend; y++)
241   {
242      code = mos6560->dma_read(device->machine, (mos6560->chargenaddr + ch * mos6560->charheight + y) & 0x3fff);
243      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 0) =
244         *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 1) = color[code >> 6];
245      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 2) =
246         *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 3) = color[(code >> 4) & 3];
247      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 4) =
248         *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 5) = color[(code >> 2) & 3];
249      *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 6) =
250         *BITMAP_ADDR16(mos6560->bitmap, y + yoff, xoff + 7) = color[code & 3];
251   }
252}
253
254
255/*-------------------------------------------------
256 mos6560_drawlines - draw a certain numer of lines
257-------------------------------------------------*/
258
259static void mos6560_drawlines( running_device *device, int first, int last )
260{
261   mos6560_state *mos6560 = get_safe_token(device);
262   int line, vline;
263   int offs, yoff, xoff, ybegin, yend, i, j;
264   int attr, ch;
265
266   mos6560->lastline = last;
267   if (first >= last)
268      return;
269
270   for (line = first; (line < mos6560->ypos) && (line < last); line++)
271   {
272      for (j = 0; j < mos6560->total_xsize; j++)
273         *BITMAP_ADDR16(mos6560->bitmap, line, j) = mos6560->framecolor;
274   }
275
276   for (vline = line - mos6560->ypos; (line < last) && (line < mos6560->ypos + mos6560->ysize);)
277   {
278      if (mos6560->matrix8x16)
279      {
280         offs = (vline >> 4) * mos6560->chars_x;
281         yoff = (vline & ~0xf) + mos6560->ypos;
282         ybegin = vline & 0xf;
283         yend = (vline + 0xf < last - mos6560->ypos) ? 0xf : ((last - line) & 0xf) + ybegin;
284      }
285      else
286      {
287         offs = (vline >> 3) * mos6560->chars_x;
288         yoff = (vline & ~7) + mos6560->ypos;
289         ybegin = vline & 7;
290         yend = (vline + 7 < last - mos6560->ypos) ? 7 : ((last - line) & 7) + ybegin;
291      }
292
293      if (mos6560->xpos > 0)
294      {
295         for (i = ybegin; i <= yend; i++)
296            for (j = 0; j < mos6560->xpos; j++)
297               *BITMAP_ADDR16(mos6560->bitmap, yoff + i, j) = mos6560->framecolor;
298      }
299
300      for (xoff = mos6560->xpos; (xoff < mos6560->xpos + mos6560->xsize) && (xoff < mos6560->total_xsize); xoff += 8, offs++)
301      {
302         ch = mos6560->dma_read(device->machine, (mos6560->videoaddr + offs) & 0x3fff);
303         attr = (mos6560->dma_read_color(device->machine, (mos6560->videoaddr + offs) & 0x3fff)) & 0xf;
304
305         if (mos6560->type == MOS6560_ATTACKUFO)
306         {
307            /* the mos6560 variant used in attckufo only has only one draw mode */
308            mos6560->mono[1] = attr;
309            mos6560_draw_character(device, ybegin, yend, ch, yoff, xoff, mos6560->mono);
310         }
311         else if (mos6560->inverted)
312         {
313            if (attr & 8)
314            {
315               mos6560->multiinverted[0] = attr & 7;
316               mos6560_draw_character_multi(device, ybegin, yend, ch, yoff, xoff, mos6560->multiinverted);
317            }
318            else
319            {
320               mos6560->monoinverted[0] = attr;
321               mos6560_draw_character(device, ybegin, yend, ch, yoff, xoff, mos6560->monoinverted);
322            }
323         }
324         else
325         {
326            if (attr & 8)
327            {
328               mos6560->multi[2] = attr & 7;
329               mos6560_draw_character_multi(device, ybegin, yend, ch, yoff, xoff, mos6560->multi);
330            }
331            else
332            {
333               mos6560->mono[1] = attr;
334               mos6560_draw_character(device, ybegin, yend, ch, yoff, xoff, mos6560->mono);
335            }
336         }
337      }
338
339      if (xoff < mos6560->total_xsize)
340      {
341         for (i = ybegin; i <= yend; i++)
342            for (j = xoff; j < mos6560->total_xsize; j++)
343               *BITMAP_ADDR16(mos6560->bitmap, yoff + i, j) = mos6560->framecolor;
344      }
345
346      if (mos6560->matrix8x16)
347      {
348         vline = (vline + 16) & ~0xf;
349         line = vline + mos6560->ypos;
350      }
351      else
352      {
353         vline = (vline + 8) & ~7;
354         line = vline + mos6560->ypos;
355      }
356   }
357
358   for (; line < last; line++)
359      for (j = 0; j < mos6560->total_xsize; j++)
360         *BITMAP_ADDR16(mos6560->bitmap, line, j) = mos6560->framecolor;
361}
362
363
364/*-------------------------------------------------
365 mos6560_port_w - write to regs
366-------------------------------------------------*/
367
368WRITE8_DEVICE_HANDLER( mos6560_port_w )
369{
370   mos6560_state *mos6560 = get_safe_token(device);
371
372   DBG_LOG(1, "mos6560_port_w", ("%.4x:%.2x\n", offset, data));
373
374   switch (offset)
375   {
376   case 0xa:
377   case 0xb:
378   case 0xc:
379   case 0xd:
380   case 0xe:
381      mos6560_soundport_w(device, offset, data);
382      break;
383   }
384
385   if (mos6560->reg[offset] != data)
386   {
387      switch (offset)
388      {
389      case 0:
390      case 1:
391      case 2:
392      case 3:
393      case 5:
394      case 0xe:
395      case 0xf:
396         mos6560_drawlines(device, mos6560->lastline, mos6560->rasterline);
397         break;
398      }
399      mos6560->reg[offset] = data;
400
401      switch (offset)
402      {
403      case 0:
404         if ((mos6560->type != MOS6560_ATTACKUFO))
405            mos6560->xpos = XPOS;
406         break;
407      case 1:
408         if ((mos6560->type != MOS6560_ATTACKUFO))
409            mos6560->ypos = YPOS;
410         break;
411      case 2:
412         /* ntsc values >= 31 behave like 31 */
413         /* pal value >= 32 behave like 32 */
414         mos6560->chars_x = CHARS_X;
415         mos6560->videoaddr = VIDEOADDR;
416         mos6560->xsize = CHARS_X * 8;
417         break;
418      case 3:
419         if ((mos6560->type != MOS6560_ATTACKUFO))
420         {
421            mos6560->matrix8x16 = data & 0x01;
422            mos6560->charheight = mos6560->matrix8x16 ? 16 : 8;
423         }
424         mos6560->chars_y = CHARS_Y;
425         mos6560->ysize = CHARS_Y * mos6560->charheight;
426         break;
427      case 5:
428         mos6560->chargenaddr = CHARGENADDR;
429         mos6560->videoaddr = VIDEOADDR;
430         break;
431      case 0xe:
432         mos6560->multi[3] = mos6560->multiinverted[3] = mos6560->helpercolor = HELPERCOLOR;
433         break;
434      case 0xf:
435         if ((mos6560->type != MOS6560_ATTACKUFO))
436            mos6560->inverted = INVERTED;
437         mos6560->multi[1] = mos6560->multiinverted[1] = mos6560->framecolor = FRAMECOLOR;
438         mos6560->mono[0] = mos6560->monoinverted[1] = mos6560->multi[0] = mos6560->multiinverted[2] = mos6560->backgroundcolor = BACKGROUNDCOLOR;
439         break;
440      }
441   }
442}
443
444/*-------------------------------------------------
445 mos6560_port_r - read from regs
446-------------------------------------------------*/
447
448READ8_DEVICE_HANDLER( mos6560_port_r )
449{
450   mos6560_state *mos6560 = get_safe_token(device);
451   int val;
452
453   switch (offset)
454   {
455   case 3:
456      val = ((mos6560->rasterline & 1) << 7) | (mos6560->reg[offset] & 0x7f);
457      break;
458   case 4:                     /*rasterline */
459      mos6560_drawlines(device, mos6560->lastline, mos6560->rasterline);
460      val = (mos6560->rasterline / 2) & 0xff;
461      break;
462   case 6:                     /*lightpen horizontal */
463   case 7:                     /*lightpen vertical */
464      if (LIGHTPEN_BUTTON && ((attotime_to_double(timer_get_time(device->machine)) - mos6560->lightpenreadtime) * MOS656X_VRETRACERATE >= 1))
465      {
466         /* only 1 update each frame */
467         /* and diode must recognize light */
468         if (1)
469         {
470            mos6560->reg[6] = MOS656X_X_VALUE;
471            mos6560->reg[7] = MOS656X_Y_VALUE;
472         }
473         mos6560->lightpenreadtime = attotime_to_double(timer_get_time(device->machine));
474      }
475      val = mos6560->reg[offset];
476      break;
477   case 8:                     /* poti 1 */
478   case 9:                     /* poti 2 */
479      val = (mos6560->paddle_cb != NULL) ? mos6560->paddle_cb[offset - 8](device->machine) : mos6560->reg[offset];
480      break;
481   default:
482      val = mos6560->reg[offset];
483      break;
484   }
485   DBG_LOG(3, "mos6560_port_r", ("%.4x:%.2x\n", offset, val));
486   return val;
487}
488
489
490/*-------------------------------------------------
491 mos6560_raster_interrupt_gen
492-------------------------------------------------*/
493
494void mos6560_raster_interrupt_gen( running_device *device )
495{
496   mos6560_state *mos6560 = get_safe_token(device);
497
498   mos6560->rasterline++;
499   if (mos6560->rasterline >= mos6560->total_lines)
500   {
501      mos6560->rasterline = 0;
502      mos6560_drawlines(device, mos6560->lastline, mos6560->total_lines);
503      mos6560->lastline = 0;
504   }
505}
506
507
508/*-------------------------------------------------
509 mos6560_video_update - copy the VIC bitmap to
510     main screen bitmap
511-------------------------------------------------*/
512
513UINT32 mos6560_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect )
514{
515   mos6560_state *mos6560 = get_safe_token(device);
516
517   copybitmap(bitmap, mos6560->bitmap, 0, 0, 0, 0, cliprect);
518   return 0;
519}
520
521/*****************************************************************************
522    SOUND IMPLEMENTATION
523*****************************************************************************/
524
525/*
526 * assumed model:
527 * each write to a ton/noise generated starts it new
528 * each generator behaves like an timer
529 * when it reaches 0, the next samplevalue is given out
530 */
531
532/*
533 * noise channel
534 * based on a document by diku0748@diku.dk (Asger Alstrup Nielsen)
535 *
536 * 23 bit shift register
537 * initial value (0x7ffff8)
538 * after shift bit 0 is set to bit 22 xor bit 17
539 * dac sample bit22 bit20 bit16 bit13 bit11 bit7 bit4 bit2(lsb)
540 *
541 * emulation:
542 * allocate buffer for 5 sec sampledata (fastest played frequency)
543 * and fill this buffer in init with the required sample
544 * fast turning off channel, immediate change of frequency
545 */
546
547#define NOISE_BUFFER_SIZE_SEC 5
548
549#define TONE1_ON (mos6560->reg[0x0a] & 0x80)
550#define TONE2_ON (mos6560->reg[0x0b] & 0x80)
551#define TONE3_ON (mos6560->reg[0x0c] & 0x80)
552#define NOISE_ON (mos6560->reg[0x0d] & 0x80)
553#define VOLUME (mos6560->reg[0x0e] & 0x0f)
554
555#define MOS656X_CLOCK ((mos6560->type == MOS6561) ? MOS6561_CLOCK : MOS6560_CLOCK)
556
557#define TONE_FREQUENCY_MIN  (MOS656X_CLOCK/256/128)
558
559#define TONE1_VALUE (8 * (128 - ((mos6560->reg[0x0a] + 1) & 0x7f)))
560#define TONE1_FREQUENCY (MOS656X_CLOCK/32/TONE1_VALUE)
561
562#define TONE2_VALUE (4 * (128 - ((mos6560->reg[0x0b] + 1) & 0x7f)))
563#define TONE2_FREQUENCY (MOS656X_CLOCK/32/TONE2_VALUE)
564
565#define TONE3_VALUE (2 * (128 - ((mos6560->reg[0x0c] + 1) & 0x7f)))
566#define TONE3_FREQUENCY (MOS656X_CLOCK/32/TONE3_VALUE)
567
568#define NOISE_VALUE (32 * (128 - ((mos6560->reg[0x0d] + 1) & 0x7f)))
569#define NOISE_FREQUENCY (MOS656X_CLOCK/NOISE_VALUE)
570
571#define NOISE_FREQUENCY_MAX (MOS656X_CLOCK/32/1)
572
573
574/*-------------------------------------------------
575 mos6560_soundport_w - write to regs
576-------------------------------------------------*/
577
578static void mos6560_soundport_w( running_device *device, int offset, int data )
579{
580   mos6560_state *mos6560 = get_safe_token(device);
581   int old = mos6560->reg[offset];
582   stream_update(mos6560->channel);
583
584   switch (offset)
585   {
586   case 0x0a:
587      mos6560->reg[offset] = data;
588      if (!(old & 0x80) && TONE1_ON)
589      {
590         mos6560->tone1pos = 0;
591         mos6560->tone1samples = device->machine->sample_rate / TONE1_FREQUENCY;
592         if (!mos6560->tone1samples == 0)
593            mos6560->tone1samples = 1;
594      }
595      DBG_LOG(1, "mos6560", ("tone1 %.2x %d\n", data, TONE1_FREQUENCY));
596      break;
597   case 0x0b:
598      mos6560->reg[offset] = data;
599      if (!(old & 0x80) && TONE2_ON)
600      {
601         mos6560->tone2pos = 0;
602         mos6560->tone2samples = device->machine->sample_rate / TONE2_FREQUENCY;
603         if (mos6560->tone2samples == 0)
604            mos6560->tone2samples = 1;
605      }
606      DBG_LOG(1, "mos6560", ("tone2 %.2x %d\n", data, TONE2_FREQUENCY));
607      break;
608   case 0x0c:
609      mos6560->reg[offset] = data;
610      if (!(old & 0x80) && TONE3_ON)
611      {
612         mos6560->tone3pos = 0;
613         mos6560->tone3samples = device->machine->sample_rate / TONE3_FREQUENCY;
614         if (mos6560->tone3samples == 0)
615            mos6560->tone3samples = 1;
616      }
617      DBG_LOG(1, "mos6560", ("tone3 %.2x %d\n", data, TONE3_FREQUENCY));
618      break;
619   case 0x0d:
620      mos6560->reg[offset] = data;
621      if (NOISE_ON)
622      {
623         mos6560->noisesamples = (int) ((double) NOISE_FREQUENCY_MAX * device->machine->sample_rate
624                          * NOISE_BUFFER_SIZE_SEC / NOISE_FREQUENCY);
625         DBG_LOG (1, "mos6560", ("noise %.2x %d sample:%d\n",
626                           data, NOISE_FREQUENCY, mos6560->noisesamples));
627         if ((double) mos6560->noisepos / mos6560->noisesamples >= 1.0)
628         {
629            mos6560->noisepos = 0;
630         }
631      }
632      else
633      {
634         mos6560->noisepos = 0;
635      }
636      break;
637   case 0x0e:
638      mos6560->reg[offset] = (old & ~0x0f) | (data & 0x0f);
639      DBG_LOG (3, "mos6560", ("volume %d\n", data & 0x0f));
640      break;
641   }
642}
643
644
645/*-------------------------------------------------
646 mos6560_update - update audio stream
647-------------------------------------------------*/
648
649static STREAM_UPDATE( mos6560_update )
650{
651   mos6560_state *mos6560 = get_safe_token(device);
652   int i, v;
653   stream_sample_t *buffer = outputs[0];
654
655   for (i = 0; i < samples; i++)
656   {
657      v = 0;
658      if (TONE1_ON /*||(mos6560->tone1pos != 0) */ )
659      {
660         v += mos6560->tone[mos6560->tone1pos * mos6560->tonesize / mos6560->tone1samples];
661         mos6560->tone1pos++;
662#if 0
663         mos6560->tone1pos %= mos6560->tone1samples;
664#else
665         if (mos6560->tone1pos >= mos6560->tone1samples)
666         {
667            mos6560->tone1pos = 0;
668            mos6560->tone1samples = device->machine->sample_rate / TONE1_FREQUENCY;
669            if (mos6560->tone1samples == 0)
670               mos6560->tone1samples = 1;
671         }
672#endif
673      }
674      if (TONE2_ON /*||(mos6560->tone2pos != 0) */ )
675      {
676         v += mos6560->tone[mos6560->tone2pos * mos6560->tonesize / mos6560->tone2samples];
677         mos6560->tone2pos++;
678#if 0
679         mos6560->tone2pos %= mos6560->tone2samples;
680#else
681         if (mos6560->tone2pos >= mos6560->tone2samples)
682         {
683            mos6560->tone2pos = 0;
684            mos6560->tone2samples = device->machine->sample_rate / TONE2_FREQUENCY;
685            if (mos6560->tone2samples == 0)
686               mos6560->tone2samples = 1;
687         }
688#endif
689      }
690      if (TONE3_ON /*||(mos6560->tone3pos != 0) */ )
691      {
692         v += mos6560->tone[mos6560->tone3pos * mos6560->tonesize / mos6560->tone3samples];
693         mos6560->tone3pos++;
694#if 0
695         mos6560->tone3pos %= mos6560->tone3samples;
696#else
697         if (mos6560->tone3pos >= mos6560->tone3samples)
698         {
699            mos6560->tone3pos = 0;
700            mos6560->tone3samples = device->machine->sample_rate / TONE3_FREQUENCY;
701            if (mos6560->tone3samples == 0)
702               mos6560->tone3samples = 1;
703         }
704#endif
705      }
706      if (NOISE_ON)
707      {
708         v += mos6560->noise[(int) ((double) mos6560->noisepos * mos6560->noisesize / mos6560->noisesamples)];
709         mos6560->noisepos++;
710         if ((double) mos6560->noisepos / mos6560->noisesamples >= 1.0)
711         {
712            mos6560->noisepos = 0;
713         }
714      }
715      v = (v * VOLUME) << 2;
716      if (v > 32767)
717         buffer[i] = 32767;
718      else if (v < -32767)
719         buffer[i] = -32767;
720      else
721         buffer[i] = v;
722
723
724
725   }
726}
727
728
729/*****************************************************************************
730    DEVICE INTERFACE
731*****************************************************************************/
732
733/*-------------------------------------------------
734 mos6560_sound_start - start audio emulation
735     (to be called at device start)
736-------------------------------------------------*/
737
738static void mos6560_sound_start( running_device *device )
739{
740   mos6560_state *mos6560 = get_safe_token(device);
741   int i;
742
743   mos6560->channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, mos6560_update);
744
745   /* buffer for fastest played sample for 5 second so we have enough data for min 5 second */
746   mos6560->noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC;
747   mos6560->noise = auto_alloc_array(device->machine, INT8, mos6560->noisesize);
748   {
749      int noiseshift = 0x7ffff8;
750      char data;
751
752      for (i = 0; i < mos6560->noisesize; i++)
753      {
754         data = 0;
755         if (noiseshift & 0x400000)
756            data |= 0x80;
757         if (noiseshift & 0x100000)
758            data |= 0x40;
759         if (noiseshift & 0x010000)
760            data |= 0x20;
761         if (noiseshift & 0x002000)
762            data |= 0x10;
763         if (noiseshift & 0x000800)
764            data |= 0x08;
765         if (noiseshift & 0x000080)
766            data |= 0x04;
767         if (noiseshift & 0x000010)
768            data |= 0x02;
769         if (noiseshift & 0x000004)
770            data |= 0x01;
771         mos6560->noise[i] = data;
772         if (((noiseshift & 0x400000) == 0) != ((noiseshift & 0x002000) == 0))
773            noiseshift = (noiseshift << 1) | 1;
774         else
775            noiseshift <<= 1;
776      }
777   }
778   mos6560->tonesize = device->machine->sample_rate / TONE_FREQUENCY_MIN;
779
780   if (mos6560->tonesize > 0)
781   {
782      mos6560->tone = auto_alloc_array(device->machine, INT16, mos6560->tonesize);
783
784      for (i = 0; i < mos6560->tonesize; i++)
785      {
786         mos6560->tone[i] = (INT16)(sin (2 * M_PI * i / mos6560->tonesize) * 127 + 0.5);
787      }
788   }
789   else
790   {
791      mos6560->tone = NULL;
792   }
793}
794
795
796/*-------------------------------------------------
797 DEVICE_START( mos6560 )
798-------------------------------------------------*/
799
800static DEVICE_START( mos6560 )
801{
802   mos6560_state *mos6560 = get_safe_token(device);
803   const mos6560_interface *intf = (mos6560_interface *)device->baseconfig().static_config;
804   int width, height;
805
806   mos6560->screen = devtag_get_device(device->machine, intf->screen);
807   width = video_screen_get_width(mos6560->screen);
808   height = video_screen_get_height(mos6560->screen);
809
810   mos6560->type = intf->type;
811
812   mos6560->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
813
814   assert(intf->dma_read != NULL);
815   assert(intf->dma_read_color != NULL);
816
817   mos6560->dma_read = intf->dma_read;
818   mos6560->dma_read_color = intf->dma_read_color;
819
820   mos6560->lightpen_button_cb = intf->button_cb;
821   mos6560->lightpen_x_cb = intf->x_cb;
822   mos6560->lightpen_y_cb = intf->y_cb;
823
824   mos6560->paddle_cb[0] = intf->paddle0_cb;
825   mos6560->paddle_cb[1] = intf->paddle1_cb;
826
827   switch (mos6560->type)
828   {
829   case MOS6560:
830      mos6560->total_xsize = MOS6560_XSIZE;
831      mos6560->total_ysize = MOS6560_YSIZE;
832      mos6560->total_lines = MOS6560_LINES;
833      mos6560->total_vretracerate = MOS6560_VRETRACERATE;
834      break;
835   case MOS6560_ATTACKUFO:
836      mos6560->total_xsize = 23 * 8;
837      mos6560->total_ysize = 22 * 8;
838      mos6560->total_lines = MOS6560_LINES;
839      mos6560->total_vretracerate = MOS6560_VRETRACERATE;
840      break;
841   case MOS6561:
842      mos6560->total_xsize = MOS6561_XSIZE;
843      mos6560->total_ysize = MOS6561_YSIZE;
844      mos6560->total_lines = MOS6561_LINES;
845      mos6560->total_vretracerate = MOS6561_VRETRACERATE;
846      break;
847   }
848
849   mos6560_sound_start(device);
850
851   state_save_register_device_item(device, 0, mos6560->lightpenreadtime);
852   state_save_register_device_item(device, 0, mos6560->rasterline);
853   state_save_register_device_item(device, 0, mos6560->lastline);
854
855   state_save_register_device_item(device, 0, mos6560->charheight);
856   state_save_register_device_item(device, 0, mos6560->matrix8x16);
857   state_save_register_device_item(device, 0, mos6560->inverted);
858   state_save_register_device_item(device, 0, mos6560->chars_x);
859   state_save_register_device_item(device, 0, mos6560->chars_y);
860   state_save_register_device_item(device, 0, mos6560->xsize);
861   state_save_register_device_item(device, 0, mos6560->ysize);
862   state_save_register_device_item(device, 0, mos6560->xpos);
863   state_save_register_device_item(device, 0, mos6560->ypos);
864   state_save_register_device_item(device, 0, mos6560->chargenaddr);
865   state_save_register_device_item(device, 0, mos6560->videoaddr);
866
867   state_save_register_device_item(device, 0, mos6560->backgroundcolor);
868   state_save_register_device_item(device, 0, mos6560->framecolor);
869   state_save_register_device_item(device, 0, mos6560->helpercolor);
870
871   state_save_register_device_item_array(device, 0, mos6560->reg);
872
873   state_save_register_device_item_array(device, 0, mos6560->mono);
874   state_save_register_device_item_array(device, 0, mos6560->monoinverted);
875   state_save_register_device_item_array(device, 0, mos6560->multi);
876   state_save_register_device_item_array(device, 0, mos6560->multiinverted);
877
878   state_save_register_device_item_bitmap(device, 0, mos6560->bitmap);
879
880   state_save_register_device_item(device, 0, mos6560->tone1pos);
881   state_save_register_device_item(device, 0, mos6560->tone2pos);
882   state_save_register_device_item(device, 0, mos6560->tone3pos);
883   state_save_register_device_item(device, 0, mos6560->tone1samples);
884   state_save_register_device_item(device, 0, mos6560->tone2samples);
885   state_save_register_device_item(device, 0, mos6560->tone3samples);
886   state_save_register_device_item(device, 0, mos6560->noisepos);
887   state_save_register_device_item(device, 0, mos6560->noisesamples);
888}
889
890/*-------------------------------------------------
891 DEVICE_RESET( mos6560 )
892-------------------------------------------------*/
893
894static DEVICE_RESET( mos6560 )
895{
896   mos6560_state *mos6560 = get_safe_token(device);
897
898   mos6560->lightpenreadtime = 0.0;
899   mos6560->rasterline = 0;
900   mos6560->lastline = 0;
901
902   memset(mos6560->reg, 0, 16);
903
904   mos6560->charheight = 8;
905   mos6560->matrix8x16 = 0;
906   mos6560->inverted = 0;
907   mos6560->chars_x = 0;
908   mos6560->chars_y = 0;
909   mos6560->xsize = 0;
910   mos6560->ysize = 0;
911   mos6560->xpos = 0;
912   mos6560->ypos = 0;
913   mos6560->chargenaddr = 0;
914   mos6560->videoaddr = 0;
915
916   mos6560->backgroundcolor = 0;
917   mos6560->framecolor = 0;
918   mos6560->helpercolor = 0;
919
920   mos6560->mono[0] = 0;
921   mos6560->mono[1] = 0;
922   mos6560->monoinverted[0] = 0;
923   mos6560->monoinverted[1] = 0;
924   mos6560->multi[0] = 0;
925   mos6560->multi[1] = 0;
926   mos6560->multi[2] = 0;
927   mos6560->multi[3] = 0;
928   mos6560->multiinverted[0] = 0;
929   mos6560->multiinverted[1] = 0;
930   mos6560->multiinverted[2] = 0;
931   mos6560->multiinverted[3] = 0;
932
933   mos6560->tone1pos = 0;
934   mos6560->tone2pos = 0;
935   mos6560->tone3pos = 0;
936   mos6560->tone1samples = 1;
937   mos6560->tone2samples = 1;
938   mos6560->tone3samples = 1;
939   mos6560->noisepos = 0;
940   mos6560->noisesamples = 1;
941}
942
943
944/*-------------------------------------------------
945 Device definition
946-------------------------------------------------*/
947
948static const char DEVTEMPLATE_SOURCE[] = __FILE__;
949
950#define DEVTEMPLATE_ID(p,s)            p##mos6560##s
951#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
952#define DEVTEMPLATE_NAME            "MOS 6560 / 6561 VIC"
953#define DEVTEMPLATE_FAMILY            "MOS Video Interface Chip"
954#include "devtempl.h"
src/emu/sound/mos6560.h
r0r7394
1/*****************************************************************************
2 *
3 * audio/vic6560.h
4 *
5 ****************************************************************************/
6
7#ifndef __MOS6560_H__
8#define __MOS6560_H__
9
10#include "devcb.h"
11
12
13/***************************************************************************
14    TYPE DEFINITIONS
15***************************************************************************/
16
17typedef UINT8 (*mos6560_lightpen_x_callback)(running_machine *machine);
18typedef UINT8 (*mos6560_lightpen_y_callback)(running_machine *machine);
19typedef UINT8 (*mos6560_lightpen_button_callback)(running_machine *machine);
20typedef UINT8 (*mos6560_paddle_callback)(running_machine *machine);
21
22typedef int (*mos6560_dma_read)(running_machine *machine, int);
23typedef int (*mos6560_dma_read_color)(running_machine *machine, int);
24
25
26typedef enum
27{
28   MOS6560_ATTACKUFO,        // this is a 6560VIC derivative, missing some of the features
29   MOS6560,                  // this is the NTSC version
30   MOS6561                   // this is the PAL version
31} mos6560_type;
32
33typedef struct _mos6560_interface mos6560_interface;
34struct _mos6560_interface
35{
36   const char         *screen;
37
38   mos6560_type type;
39
40   mos6560_lightpen_x_callback        x_cb;
41   mos6560_lightpen_y_callback        y_cb;
42   mos6560_lightpen_button_callback   button_cb;
43
44   mos6560_paddle_callback        paddle0_cb, paddle1_cb;
45
46   mos6560_dma_read          dma_read;
47   mos6560_dma_read_color    dma_read_color;
48};
49
50/***************************************************************************
51    CONSTANTS
52***************************************************************************/
53
54#define MOS6560_VRETRACERATE 60
55#define MOS6561_VRETRACERATE 50
56#define MOS656X_HRETRACERATE 15625
57
58#define MOS6560_MAME_XPOS  4         /* xleft not displayed */
59#define MOS6560_MAME_YPOS  10         /* y up not displayed */
60#define MOS6561_MAME_XPOS  20
61#define MOS6561_MAME_YPOS  10
62#define MOS6560_MAME_XSIZE   200
63#define MOS6560_MAME_YSIZE   248
64#define MOS6561_MAME_XSIZE   224
65#define MOS6561_MAME_YSIZE   296
66/* real values */
67
68#define MOS6560_LINES 261
69#define MOS6561_LINES 312
70
71#define MOS6560_XSIZE   (4+201)         /* 4 left not visible */
72#define MOS6560_YSIZE   (10+251)      /* 10 not visible */
73/* cycles 65 */
74
75#define MOS6561_XSIZE   (20+229)      /* 20 left not visible */
76#define MOS6561_YSIZE   (10+302)      /* 10 not visible */
77/* cycles 71 */
78
79
80/* the following values depend on the VIC clock,
81 * but to achieve TV-frequency the clock must have a fix frequency */
82#define MOS6560_CLOCK   (14318181/14)
83#define MOS6561_CLOCK   (4433618/4)
84
85
86/***************************************************************************
87    INFO PROTOTYPES
88***************************************************************************/
89
90DEVICE_GET_INFO( mos6560 );
91
92/***************************************************************************
93    DEVICE CONFIGURATION MACROS
94***************************************************************************/
95
96#define MOS656X DEVICE_GET_INFO_NAME( mos6560 )
97#define SOUND_MOS656X MOS656X
98
99#define MDRV_MOS656X_ADD(_tag, _interface) \
100   MDRV_DEVICE_ADD(_tag, SOUND, 0) \
101   MDRV_DEVICE_CONFIG_DATAPTR(sound_config, type, SOUND_MOS656X) \
102   MDRV_DEVICE_CONFIG(_interface)
103
104
105/***************************************************************************
106    I/O PROTOTYPES
107***************************************************************************/
108
109WRITE8_DEVICE_HANDLER( mos6560_port_w );
110READ8_DEVICE_HANDLER( mos6560_port_r );
111
112void mos6560_raster_interrupt_gen( running_device *device );
113UINT32 mos6560_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect );
114
115
116#endif /* __MOS6560_H__ */
src/emu/sound/sound.mak
r7393r7394
271271
272272
273273#-------------------------------------------------
274# MOS 6560VIC
275#-------------------------------------------------
276
277ifneq ($(filter MOS656X,$(SOUNDS)),)
278SOUNDOBJS += $(SOUNDOBJ)/mos6560.o
279endif
280
281
282
283#-------------------------------------------------
274284# Namco custom sound chips
275285#-------------------------------------------------
276286
src/mess/audio/vic6560.c
r7393r7394
1/***************************************************************************
2
3    MOS video interface chip 6560
4    PeT mess@utanet.at
5
6
7    2010 FP: converted to a device and merged the sound code
8
9    TODO:
10      - plenty of cleanups!
11      - investigate why some vic20 carts crash emulation
12
13***************************************************************************/
14
15#include "emu.h"
16#include "streams.h"
17
18#include "audio/vic6560.h"
19
20
21typedef struct _vic656x_state  vic656x_state;
22struct _vic656x_state
23{
24   vic656x_type  type;
25
26   running_device *screen;
27
28   UINT8 reg[16];
29
30   bitmap_t *bitmap;
31
32   int rasterline, lastline;
33   double lightpenreadtime;
34
35   int charheight, matrix8x16, inverted;
36   int chars_x, chars_y;
37   int xsize, ysize, xpos, ypos;
38   int chargenaddr, videoaddr;
39
40   /* values in videoformat */
41   UINT16 backgroundcolor, framecolor, helpercolor;
42
43   /* arrays for bit to color conversion without condition checking */
44   UINT16 mono[2], monoinverted[2], multi[4], multiinverted[4];
45
46   /* video chip settings */
47   int total_xsize, total_ysize, total_lines, total_vretracerate;
48
49   /* DMA */
50   vic656x_dma_read          dma_read;
51   vic656x_dma_read_color    dma_read_color;
52
53   /* lightpen */
54   vic656x_lightpen_button_callback lightpen_button_cb;
55   vic656x_lightpen_x_callback lightpen_x_cb;
56   vic656x_lightpen_y_callback lightpen_y_cb;
57
58   /* paddles */
59   vic656x_paddle_callback        paddle_cb[2];
60
61   /* sound part */
62   int tone1pos, tone2pos, tone3pos,
63   tonesize, tone1samples, tone2samples, tone3samples,
64   noisesize,        /* number of samples */
65   noisepos,         /* pos of tone */
66   noisesamples;     /* count of samples to give out per tone */
67
68   sound_stream *channel;
69   INT16 *tone;
70
71   INT8 *noise;
72};
73
74/*****************************************************************************
75    CONSTANTS
76*****************************************************************************/
77
78#define VERBOSE_LEVEL 0
79#define DBG_LOG(N,M,A) \
80   do { \
81      if(VERBOSE_LEVEL >= N) \
82      { \
83         if( M ) \
84            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(device->machine)), (char*) M ); \
85         logerror A; \
86      } \
87   } while (0)
88
89
90/*****************************************************************************
91    INLINE FUNCTIONS
92*****************************************************************************/
93
94INLINE vic656x_state *get_safe_token( running_device *device )
95{
96   assert(device != NULL);
97   assert(device->token != NULL);
98   assert(device->type == VIC656X);
99
100   return (vic656x_state *)device->token;
101}
102
103INLINE const vic656x_interface *get_interface( running_device *device )
104{
105   assert(device != NULL);
106   assert((device->type == VIC656X));
107   return (const vic656x_interface *) device->baseconfig().static_config;
108}
109
110/*****************************************************************************
111    IMPLEMENTATION
112*****************************************************************************/
113
114static void vic6560_soundport_w( running_device *device, int offset, int data );
115
116
117/* 2008-05 FP: lightpen code needs to read input port from vc20.c */
118
119#define LIGHTPEN_BUTTON      (vic6560->lightpen_button_cb(device->machine))
120#define LIGHTPEN_X_VALUE   (vic6560->lightpen_x_cb(device->machine))
121#define LIGHTPEN_Y_VALUE   (vic6560->lightpen_y_cb(device->machine))
122
123/* lightpen delivers values from internal counters
124 * they do not start with the visual area or frame area */
125#define VIC6560_X_BEGIN 38
126#define VIC6560_Y_BEGIN -6            /* first 6 lines after retrace not for lightpen! */
127#define VIC6561_X_BEGIN 38
128#define VIC6561_Y_BEGIN -6
129#define VIC656X_X_BEGIN ((vic6560->type == VIC6561) ? VIC6561_X_BEGIN : VIC6560_X_BEGIN)
130#define VIC656X_Y_BEGIN ((vic6560->type == VIC6561) ? VIC6561_Y_BEGIN : VIC6560_Y_BEGIN)
131
132#define VIC656X_MAME_XPOS ((vic6560->type == VIC6561) ? VIC6561_MAME_XPOS : VIC6560_MAME_XPOS)
133#define VIC656X_MAME_YPOS ((vic6560->type == VIC6561) ? VIC6561_MAME_YPOS : VIC6560_MAME_YPOS)
134
135/* lightpen behaviour in pal or mono multicolor not tested */
136#define VIC6560_X_VALUE ((LIGHTPEN_X_VALUE + VIC656X_X_BEGIN + VIC656X_MAME_XPOS)/2)
137#define VIC6560_Y_VALUE ((LIGHTPEN_Y_VALUE + VIC656X_Y_BEGIN + VIC656X_MAME_YPOS)/2)
138
139/* ntsc 1 - 8 */
140/* pal 5 - 19 */
141#define XPOS (((int)vic6560->reg[0] & 0x7f) * 4)
142#define YPOS ((int)vic6560->reg[1] * 2)
143
144/* ntsc values >= 31 behave like 31 */
145/* pal value >= 32 behave like 32 */
146#define CHARS_X ((int)vic6560->reg[2] & 0x7f)
147#define CHARS_Y (((int)vic6560->reg[3] & 0x7e) >> 1)
148
149#define MATRIX8X16 (vic6560->reg[3] & 0x01)      /* else 8x8 */
150#define CHARHEIGHT (MATRIX8X16 ? 16 : 8)
151#define XSIZE (CHARS_X * 8)
152#define YSIZE (CHARS_Y * CHARHEIGHT)
153
154/* colorram and backgroundcolor are changed */
155#define INVERTED (!(vic6560->reg[0x0f] & 8))
156
157#define CHARGENADDR (((int)vic6560->reg[5] & 0x0f) << 10)
158#define VIDEOADDR ((((int)vic6560->reg[5] & 0xf0) << (10 - 4)) | (((int)vic6560->reg[2] & 0x80) << (9-7)))
159#define VIDEORAMSIZE (YSIZE * XSIZE)
160#define CHARGENSIZE (256 * HEIGHTPIXEL)
161
162#define HELPERCOLOR (vic6560->reg[0x0e] >> 4)
163#define BACKGROUNDCOLOR (vic6560->reg[0x0f] >> 4)
164#define FRAMECOLOR (vic6560->reg[0x0f] & 0x07)
165
166static void vic6560_draw_character( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, UINT16 *color )
167{
168   vic656x_state *vic6560 = get_safe_token(device);
169   int y, code;
170
171   for (y = ybegin; y <= yend; y++)
172   {
173      code = vic6560->dma_read(device->machine, (vic6560->chargenaddr + ch * vic6560->charheight + y) & 0x3fff);
174      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 0) = color[code >> 7];
175      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 1) = color[(code >> 6) & 1];
176      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 2) = color[(code >> 5) & 1];
177      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 3) = color[(code >> 4) & 1];
178      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 4) = color[(code >> 3) & 1];
179      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 5) = color[(code >> 2) & 1];
180      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 6) = color[(code >> 1) & 1];
181      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 7) = color[code & 1];
182   }
183}
184
185static void vic6560_draw_character_multi( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, UINT16 *color )
186{
187   vic656x_state *vic6560 = get_safe_token(device);
188   int y, code;
189
190   for (y = ybegin; y <= yend; y++)
191   {
192      code = vic6560->dma_read(device->machine, (vic6560->chargenaddr + ch * vic6560->charheight + y) & 0x3fff);
193      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 0) =
194         *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 1) = color[code >> 6];
195      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 2) =
196         *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 3) = color[(code >> 4) & 3];
197      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 4) =
198         *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 5) = color[(code >> 2) & 3];
199      *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 6) =
200         *BITMAP_ADDR16(vic6560->bitmap, y + yoff, xoff + 7) = color[code & 3];
201   }
202}
203
204static void vic6560_drawlines( running_device *device, int first, int last )
205{
206   vic656x_state *vic6560 = get_safe_token(device);
207   int line, vline;
208   int offs, yoff, xoff, ybegin, yend, i;
209   int attr, ch;
210
211   vic6560->lastline = last;
212   if (first >= last)
213      return;
214
215   for (line = first; (line < vic6560->ypos) && (line < last); line++)
216   {
217      memset16(BITMAP_ADDR16(vic6560->bitmap, line, 0), vic6560->framecolor, vic6560->total_xsize);
218   }
219
220   for (vline = line - vic6560->ypos; (line < last) && (line < vic6560->ypos + vic6560->ysize);)
221   {
222      if (vic6560->matrix8x16)
223      {
224         offs = (vline >> 4) * vic6560->chars_x;
225         yoff = (vline & ~0xf) + vic6560->ypos;
226         ybegin = vline & 0xf;
227         yend = (vline + 0xf < last - vic6560->ypos) ? 0xf : ((last - line) & 0xf) + ybegin;
228      }
229      else
230      {
231         offs = (vline >> 3) * vic6560->chars_x;
232         yoff = (vline & ~7) + vic6560->ypos;
233         ybegin = vline & 7;
234         yend = (vline + 7 < last - vic6560->ypos) ? 7 : ((last - line) & 7) + ybegin;
235      }
236
237      if (vic6560->xpos > 0)
238      {
239         for (i = ybegin; i <= yend; i++)
240            memset16(BITMAP_ADDR16(vic6560->bitmap, yoff + i, 0), vic6560->framecolor, vic6560->xpos);
241      }
242      for (xoff = vic6560->xpos; (xoff < vic6560->xpos + vic6560->xsize) && (xoff < vic6560->total_xsize); xoff += 8, offs++)
243      {
244         ch = vic6560->dma_read(device->machine, (vic6560->videoaddr + offs) & 0x3fff);
245         attr = (vic6560->dma_read_color(device->machine, (vic6560->videoaddr + offs) & 0x3fff)) & 0xf;
246         if (vic6560->inverted)
247         {
248            if (attr & 8)
249            {
250               vic6560->multiinverted[0] = attr & 7;
251               vic6560_draw_character_multi(device, ybegin, yend, ch, yoff, xoff, vic6560->multiinverted);
252            }
253            else
254            {
255               vic6560->monoinverted[0] = attr;
256               vic6560_draw_character(device, ybegin, yend, ch, yoff, xoff, vic6560->monoinverted);
257            }
258         }
259         else
260         {
261            if (attr & 8)
262            {
263               vic6560->multi[2] = attr & 7;
264               vic6560_draw_character_multi(device, ybegin, yend, ch, yoff, xoff, vic6560->multi);
265            }
266            else
267            {
268               vic6560->mono[1] = attr;
269               vic6560_draw_character(device, ybegin, yend, ch, yoff, xoff, vic6560->mono);
270            }
271         }
272      }
273      if (xoff < vic6560->total_xsize)
274      {
275         for (i = ybegin; i <= yend; i++)
276         {
277            memset16(BITMAP_ADDR16(vic6560->bitmap, yoff + i, xoff), vic6560->framecolor, vic6560->total_xsize - xoff);
278         }
279      }
280      if (vic6560->matrix8x16)
281      {
282         vline = (vline + 16) & ~0xf;
283         line = vline + vic6560->ypos;
284      }
285      else
286      {
287         vline = (vline + 8) & ~7;
288         line = vline + vic6560->ypos;
289      }
290   }
291
292   for (; line < last; line++)
293   {
294      memset16(BITMAP_ADDR16(vic6560->bitmap, line, 0), vic6560->framecolor, vic6560->total_xsize);
295   }
296}
297
298
299
300WRITE8_DEVICE_HANDLER( vic6560_port_w )
301{
302   vic656x_state *vic6560 = get_safe_token(device);
303
304   DBG_LOG(1, "vic6560_port_w", ("%.4x:%.2x\n", offset, data));
305
306   switch (offset)
307   {
308   case 0xa:
309   case 0xb:
310   case 0xc:
311   case 0xd:
312   case 0xe:
313      vic6560_soundport_w(device, offset, data);
314      break;
315   }
316
317   if (vic6560->reg[offset] != data)
318   {
319      switch (offset)
320      {
321      case 0:
322      case 1:
323      case 2:
324      case 3:
325      case 5:
326      case 0xe:
327      case 0xf:
328         vic6560_drawlines(device, vic6560->lastline, vic6560->rasterline);
329         break;
330      }
331      vic6560->reg[offset] = data;
332
333      switch (offset)
334      {
335      case 0:
336         vic6560->xpos = XPOS;
337         break;
338      case 1:
339         vic6560->ypos = YPOS;
340         break;
341      case 2:
342         /* ntsc values >= 31 behave like 31 */
343         /* pal value >= 32 behave like 32 */
344         vic6560->chars_x = CHARS_X;
345         vic6560->videoaddr = VIDEOADDR;
346         vic6560->xsize = XSIZE;
347         break;
348      case 3:
349         vic6560->matrix8x16 = MATRIX8X16;
350         vic6560->charheight = CHARHEIGHT;
351         vic6560->chars_y = CHARS_Y;
352         vic6560->ysize = YSIZE;
353         break;
354      case 5:
355         vic6560->chargenaddr = CHARGENADDR;
356         vic6560->videoaddr = VIDEOADDR;
357         break;
358      case 0xe:
359         vic6560->multi[3] = vic6560->multiinverted[3] = vic6560->helpercolor = HELPERCOLOR;
360         break;
361      case 0xf:
362         vic6560->inverted = INVERTED;
363         vic6560->multi[1] = vic6560->multiinverted[1] = vic6560->framecolor = FRAMECOLOR;
364         vic6560->mono[0] = vic6560->monoinverted[1] = vic6560->multi[0] = vic6560->multiinverted[2] = vic6560->backgroundcolor = BACKGROUNDCOLOR;
365         break;
366      }
367   }
368}
369
370READ8_DEVICE_HANDLER( vic6560_port_r )
371{
372   vic656x_state *vic6560 = get_safe_token(device);
373   int val;
374
375   switch (offset)
376   {
377   case 3:
378      val = ((vic6560->rasterline & 1) << 7) | (vic6560->reg[offset] & 0x7f);
379      break;
380   case 4:                     /*rasterline */
381      vic6560_drawlines(device, vic6560->lastline, vic6560->rasterline);
382      val = (vic6560->rasterline / 2) & 0xff;
383      break;
384   case 6:                     /*lightpen horizontal */
385   case 7:                     /*lightpen vertical */
386      if (LIGHTPEN_BUTTON && ((attotime_to_double(timer_get_time(device->machine)) - vic6560->lightpenreadtime) * VIC6560_VRETRACERATE >= 1))
387      {
388         /* only 1 update each frame */
389         /* and diode must recognize light */
390         if (1)
391         {
392            vic6560->reg[6] = VIC6560_X_VALUE;
393            vic6560->reg[7] = VIC6560_Y_VALUE;
394         }
395         vic6560->lightpenreadtime = attotime_to_double(timer_get_time(device->machine));
396      }
397      val = vic6560->reg[offset];
398      break;
399   case 8:                     /* poti 1 */
400   case 9:                     /* poti 2 */
401      val = vic6560->paddle_cb[offset - 8](device->machine);
402      break;
403   default:
404      val = vic6560->reg[offset];
405      break;
406   }
407   DBG_LOG(3, "vic6560_port_r", ("%.4x:%.2x\n", offset, val));
408   return val;
409}
410
411
412void vic656x_raster_interrupt_gen( running_device *device )
413{
414   vic656x_state *vic6560 = get_safe_token(device);
415
416   vic6560->rasterline++;
417   if (vic6560->rasterline >= vic6560->total_lines)
418   {
419      vic6560->rasterline = 0;
420      vic6560_drawlines(device, vic6560->lastline, vic6560->total_lines);
421      vic6560->lastline = 0;
422   }
423}
424
425UINT32 vic656x_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect )
426{
427   vic656x_state *vic6560 = get_safe_token(device);
428
429   copybitmap(bitmap, vic6560->bitmap, 0, 0, 0, 0, cliprect);
430   return 0;
431}
432
433/* Sound emulation of the chip */
434
435/*
436 * assumed model:
437 * each write to a ton/noise generated starts it new
438 * each generator behaves like an timer
439 * when it reaches 0, the next samplevalue is given out
440 */
441
442/*
443 * noise channel
444 * based on a document by diku0748@diku.dk (Asger Alstrup Nielsen)
445 *
446 * 23 bit shift register
447 * initial value (0x7ffff8)
448 * after shift bit 0 is set to bit 22 xor bit 17
449 * dac sample bit22 bit20 bit16 bit13 bit11 bit7 bit4 bit2(lsb)
450 *
451 * emulation:
452 * allocate buffer for 5 sec sampledata (fastest played frequency)
453 * and fill this buffer in init with the required sample
454 * fast turning off channel, immediate change of frequency
455 */
456
457#define NOISE_BUFFER_SIZE_SEC 5
458
459#define TONE1_ON (vic6560->reg[0x0a] & 0x80)
460#define TONE2_ON (vic6560->reg[0x0b] & 0x80)
461#define TONE3_ON (vic6560->reg[0x0c] & 0x80)
462#define NOISE_ON (vic6560->reg[0x0d] & 0x80)
463#define VOLUME (vic6560->reg[0x0e] & 0x0f)
464
465#define VIC656X_CLOCK ((vic6560->type == VIC6561) ? VIC6561_CLOCK : VIC6560_CLOCK)
466
467#define TONE_FREQUENCY_MIN  (VIC656X_CLOCK/256/128)
468
469#define TONE1_VALUE (8 * (128 - ((vic6560->reg[0x0a] + 1) & 0x7f)))
470#define TONE1_FREQUENCY (VIC656X_CLOCK/32/TONE1_VALUE)
471
472#define TONE2_VALUE (4 * (128 - ((vic6560->reg[0x0b] + 1) & 0x7f)))
473#define TONE2_FREQUENCY (VIC656X_CLOCK/32/TONE2_VALUE)
474
475#define TONE3_VALUE (2 * (128 - ((vic6560->reg[0x0c] + 1) & 0x7f)))
476#define TONE3_FREQUENCY (VIC656X_CLOCK/32/TONE3_VALUE)
477
478#define NOISE_VALUE (32 * (128 - ((vic6560->reg[0x0d] + 1) & 0x7f)))
479#define NOISE_FREQUENCY (VIC656X_CLOCK/NOISE_VALUE)
480
481#define NOISE_FREQUENCY_MAX (VIC656X_CLOCK/32/1)
482
483
484static void vic6560_soundport_w( running_device *device, int offset, int data )
485{
486   vic656x_state *vic6560 = get_safe_token(device);
487   int old = vic6560->reg[offset];
488   stream_update(vic6560->channel);
489
490   switch (offset)
491   {
492   case 0x0a:
493      vic6560->reg[offset] = data;
494      if (!(old & 0x80) && TONE1_ON)
495      {
496         vic6560->tone1pos = 0;
497         vic6560->tone1samples = device->machine->sample_rate / TONE1_FREQUENCY;
498         if (!vic6560->tone1samples == 0)
499            vic6560->tone1samples = 1;
500      }
501      DBG_LOG(1, "vic6560", ("tone1 %.2x %d\n", data, TONE1_FREQUENCY));
502      break;
503   case 0x0b:
504      vic6560->reg[offset] = data;
505      if (!(old & 0x80) && TONE2_ON)
506      {
507         vic6560->tone2pos = 0;
508         vic6560->tone2samples = device->machine->sample_rate / TONE2_FREQUENCY;
509         if (vic6560->tone2samples == 0)
510            vic6560->tone2samples = 1;
511      }
512      DBG_LOG(1, "vic6560", ("tone2 %.2x %d\n", data, TONE2_FREQUENCY));
513      break;
514   case 0x0c:
515      vic6560->reg[offset] = data;
516      if (!(old & 0x80) && TONE3_ON)
517      {
518         vic6560->tone3pos = 0;
519         vic6560->tone3samples = device->machine->sample_rate / TONE3_FREQUENCY;
520         if (vic6560->tone3samples == 0)
521            vic6560->tone3samples = 1;
522      }
523      DBG_LOG(1, "vic6560", ("tone3 %.2x %d\n", data, TONE3_FREQUENCY));
524      break;
525   case 0x0d:
526      vic6560->reg[offset] = data;
527      if (NOISE_ON)
528      {
529         vic6560->noisesamples = (int) ((double) NOISE_FREQUENCY_MAX * device->machine->sample_rate
530                          * NOISE_BUFFER_SIZE_SEC / NOISE_FREQUENCY);
531         DBG_LOG (1, "vic6560", ("noise %.2x %d sample:%d\n",
532                           data, NOISE_FREQUENCY, vic6560->noisesamples));
533         if ((double) vic6560->noisepos / vic6560->noisesamples >= 1.0)
534         {
535            vic6560->noisepos = 0;
536         }
537      }
538      else
539      {
540         vic6560->noisepos = 0;
541      }
542      break;
543   case 0x0e:
544      vic6560->reg[offset] = (old & ~0x0f) | (data & 0x0f);
545      DBG_LOG (3, "vic6560", ("volume %d\n", data & 0x0f));
546      break;
547   }
548}
549
550/************************************/
551/* Sound handler update             */
552/************************************/
553
554static STREAM_UPDATE( vic6560_update )
555{
556   vic656x_state *vic6560 = get_safe_token(device);
557   int i, v;
558   stream_sample_t *buffer = outputs[0];
559
560   for (i = 0; i < samples; i++)
561   {
562      v = 0;
563      if (TONE1_ON /*||(vic6560->tone1pos != 0) */ )
564      {
565         v += vic6560->tone[vic6560->tone1pos * vic6560->tonesize / vic6560->tone1samples];
566         vic6560->tone1pos++;
567#if 0
568         vic6560->tone1pos %= vic6560->tone1samples;
569#else
570         if (vic6560->tone1pos >= vic6560->tone1samples)
571         {
572            vic6560->tone1pos = 0;
573            vic6560->tone1samples = device->machine->sample_rate / TONE1_FREQUENCY;
574            if (vic6560->tone1samples == 0)
575               vic6560->tone1samples = 1;
576         }
577#endif
578      }
579      if (TONE2_ON /*||(vic6560->tone2pos != 0) */ )
580      {
581         v += vic6560->tone[vic6560->tone2pos * vic6560->tonesize / vic6560->tone2samples];
582         vic6560->tone2pos++;
583#if 0
584         vic6560->tone2pos %= vic6560->tone2samples;
585#else
586         if (vic6560->tone2pos >= vic6560->tone2samples)
587         {
588            vic6560->tone2pos = 0;
589            vic6560->tone2samples = device->machine->sample_rate / TONE2_FREQUENCY;
590            if (vic6560->tone2samples == 0)
591               vic6560->tone2samples = 1;
592         }
593#endif
594      }
595      if (TONE3_ON /*||(vic6560->tone3pos != 0) */ )
596      {
597         v += vic6560->tone[vic6560->tone3pos * vic6560->tonesize / vic6560->tone3samples];
598         vic6560->tone3pos++;
599#if 0
600         vic6560->tone3pos %= vic6560->tone3samples;
601#else
602         if (vic6560->tone3pos >= vic6560->tone3samples)
603         {
604            vic6560->tone3pos = 0;
605            vic6560->tone3samples = device->machine->sample_rate / TONE3_FREQUENCY;
606            if (vic6560->tone3samples == 0)
607               vic6560->tone3samples = 1;
608         }
609#endif
610      }
611      if (NOISE_ON)
612      {
613         v += vic6560->noise[(int) ((double) vic6560->noisepos * vic6560->noisesize / vic6560->noisesamples)];
614         vic6560->noisepos++;
615         if ((double) vic6560->noisepos / vic6560->noisesamples >= 1.0)
616         {
617            vic6560->noisepos = 0;
618         }
619      }
620      v = (v * VOLUME) << 2;
621      if (v > 32767)
622         buffer[i] = 32767;
623      else if (v < -32767)
624         buffer[i] = -32767;
625      else
626         buffer[i] = v;
627
628
629
630   }
631}
632
633
634/*****************************************************************************
635    DEVICE INTERFACE
636*****************************************************************************/
637
638/************************************/
639/* Sound handler start          */
640/************************************/
641
642static void vic656x_sound_start( running_device *device )
643{
644   vic656x_state *vic6560 = get_safe_token(device);
645   int i;
646
647   vic6560->channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, vic6560_update);
648
649   /* buffer for fastest played sample for 5 second so we have enough data for min 5 second */
650   vic6560->noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC;
651   vic6560->noise = auto_alloc_array(device->machine, INT8, vic6560->noisesize);
652   {
653      int noiseshift = 0x7ffff8;
654      char data;
655
656      for (i = 0; i < vic6560->noisesize; i++)
657      {
658         data = 0;
659         if (noiseshift & 0x400000)
660            data |= 0x80;
661         if (noiseshift & 0x100000)
662            data |= 0x40;
663         if (noiseshift & 0x010000)
664            data |= 0x20;
665         if (noiseshift & 0x002000)
666            data |= 0x10;
667         if (noiseshift & 0x000800)
668            data |= 0x08;
669         if (noiseshift & 0x000080)
670            data |= 0x04;
671         if (noiseshift & 0x000010)
672            data |= 0x02;
673         if (noiseshift & 0x000004)
674            data |= 0x01;
675         vic6560->noise[i] = data;
676         if (((noiseshift & 0x400000) == 0) != ((noiseshift & 0x002000) == 0))
677            noiseshift = (noiseshift << 1) | 1;
678         else
679            noiseshift <<= 1;
680      }
681   }
682   vic6560->tonesize = device->machine->sample_rate / TONE_FREQUENCY_MIN;
683
684   if (vic6560->tonesize > 0)
685   {
686      vic6560->tone = auto_alloc_array(device->machine, INT16, vic6560->tonesize);
687
688      for (i = 0; i < vic6560->tonesize; i++)
689      {
690         vic6560->tone[i] = (INT16)(sin (2 * M_PI * i / vic6560->tonesize) * 127 + 0.5);
691      }
692   }
693   else
694   {
695      vic6560->tone = NULL;
696   }
697}
698
699static DEVICE_START( vic656x )
700{
701   vic656x_state *vic6560 = get_safe_token(device);
702   const vic656x_interface *intf = (vic656x_interface *)device->baseconfig().static_config;
703   int width, height;
704
705   vic6560->screen = devtag_get_device(device->machine, intf->screen);
706   width = video_screen_get_width(vic6560->screen);
707   height = video_screen_get_height(vic6560->screen);
708
709   vic6560->type = intf->type;
710
711   vic6560->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
712
713   vic6560->dma_read = intf->dma_read;
714   vic6560->dma_read_color = intf->dma_read_color;
715
716   vic6560->lightpen_button_cb = intf->button_cb;
717   vic6560->lightpen_x_cb = intf->x_cb;
718   vic6560->lightpen_y_cb = intf->y_cb;
719
720   vic6560->paddle_cb[0] = intf->paddle0_cb;
721   vic6560->paddle_cb[1] = intf->paddle1_cb;
722
723   switch (vic6560->type)
724   {
725   case VIC6560:
726      vic6560->total_xsize = VIC6560_XSIZE;
727      vic6560->total_ysize = VIC6560_YSIZE;
728      vic6560->total_lines = VIC6560_LINES;
729      vic6560->total_vretracerate = VIC6560_VRETRACERATE;
730      break;
731   case VIC6561:
732      vic6560->total_xsize = VIC6561_XSIZE;
733      vic6560->total_ysize = VIC6561_YSIZE;
734      vic6560->total_lines = VIC6561_LINES;
735      vic6560->total_vretracerate = VIC6561_VRETRACERATE;
736      break;
737   }
738
739   vic656x_sound_start(device);
740
741   state_save_register_device_item(device, 0, vic6560->lightpenreadtime);
742   state_save_register_device_item(device, 0, vic6560->rasterline);
743   state_save_register_device_item(device, 0, vic6560->lastline);
744
745   state_save_register_device_item(device, 0, vic6560->charheight);
746   state_save_register_device_item(device, 0, vic6560->matrix8x16);
747   state_save_register_device_item(device, 0, vic6560->inverted);
748   state_save_register_device_item(device, 0, vic6560->chars_x);
749   state_save_register_device_item(device, 0, vic6560->chars_y);
750   state_save_register_device_item(device, 0, vic6560->xsize);
751   state_save_register_device_item(device, 0, vic6560->ysize);
752   state_save_register_device_item(device, 0, vic6560->xpos);
753   state_save_register_device_item(device, 0, vic6560->ypos);
754   state_save_register_device_item(device, 0, vic6560->chargenaddr);
755   state_save_register_device_item(device, 0, vic6560->videoaddr);
756
757   state_save_register_device_item(device, 0, vic6560->backgroundcolor);
758   state_save_register_device_item(device, 0, vic6560->framecolor);
759   state_save_register_device_item(device, 0, vic6560->helpercolor);
760
761   state_save_register_device_item_array(device, 0, vic6560->reg);
762
763   state_save_register_device_item_array(device, 0, vic6560->mono);
764   state_save_register_device_item_array(device, 0, vic6560->monoinverted);
765   state_save_register_device_item_array(device, 0, vic6560->multi);
766   state_save_register_device_item_array(device, 0, vic6560->multiinverted);
767
768   state_save_register_device_item_bitmap(device, 0, vic6560->bitmap);
769
770   state_save_register_device_item(device, 0, vic6560->tone1pos);
771   state_save_register_device_item(device, 0, vic6560->tone2pos);
772   state_save_register_device_item(device, 0, vic6560->tone3pos);
773   state_save_register_device_item(device, 0, vic6560->tone1samples);
774   state_save_register_device_item(device, 0, vic6560->tone2samples);
775   state_save_register_device_item(device, 0, vic6560->tone3samples);
776   state_save_register_device_item(device, 0, vic6560->noisepos);
777   state_save_register_device_item(device, 0, vic6560->noisesamples);
778}
779
780static DEVICE_RESET( vic656x )
781{
782   vic656x_state *vic6560 = get_safe_token(device);
783
784   vic6560->lightpenreadtime = 0.0;
785   vic6560->rasterline = 0;
786   vic6560->lastline = 0;
787
788   memset(vic6560->reg, 0, 16);
789
790   vic6560->charheight = 0;
791   vic6560->matrix8x16 = 0;
792   vic6560->inverted = 0;
793   vic6560->chars_x = 0;
794   vic6560->chars_y = 0;
795   vic6560->xsize = 0;
796   vic6560->ysize = 0;
797   vic6560->xpos = 0;
798   vic6560->ypos = 0;
799   vic6560->chargenaddr = 0;
800   vic6560->videoaddr = 0;
801
802   vic6560->backgroundcolor = 0;
803   vic6560->framecolor = 0;
804   vic6560->helpercolor = 0;
805
806   vic6560->mono[0] = 0;
807   vic6560->mono[1] = 0;
808   vic6560->monoinverted[0] = 0;
809   vic6560->monoinverted[1] = 0;
810   vic6560->multi[0] = 0;
811   vic6560->multi[1] = 0;
812   vic6560->multi[2] = 0;
813   vic6560->multi[3] = 0;
814   vic6560->multiinverted[0] = 0;
815   vic6560->multiinverted[1] = 0;
816   vic6560->multiinverted[2] = 0;
817   vic6560->multiinverted[3] = 0;
818
819   vic6560->tone1pos = 0;
820   vic6560->tone2pos = 0;
821   vic6560->tone3pos = 0;
822   vic6560->tone1samples = 1;
823   vic6560->tone2samples = 1;
824   vic6560->tone3samples = 1;
825   vic6560->noisepos = 0;
826   vic6560->noisesamples = 1;
827}
828
829
830/*-------------------------------------------------
831    device definition
832-------------------------------------------------*/
833
834static const char DEVTEMPLATE_SOURCE[] = __FILE__;
835
836#define DEVTEMPLATE_ID(p,s)            p##vic656x##s
837#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
838#define DEVTEMPLATE_NAME            "6560 / 6561 VIC"
839#define DEVTEMPLATE_FAMILY            "6560 / 6561 VIC"
840#include "devtempl.h"
src/mess/audio/vic6560.h
r7393r7394
1/*****************************************************************************
2 *
3 * video/vic6560.h
4 *
5 * MOS video interface chip 6560, 6561
6 *
7 * if you need this chip in another mame/mess emulation than let it me know
8 * I will split this from the vc20 driver
9 * peter.trauner@jk.uni-linz.ac.at
10 * 16. november 1999
11 * look at mess/drivers/vc20.c and mess/machine/vc20.c
12 * on how to use it
13 *
14 * 2 Versions
15 * 6560 NTSC
16 * 6561 PAL
17 * 14 bit addr bus
18 * 12 bit data bus
19 * (16 8 bit registers)
20 * alternates with MOS 6502 on the address bus
21 * fetch 8 bit characternumber and 4 bit color
22 * high bit of 4 bit color value determines:
23 * 0: 2 color mode
24 * 1: 4 color mode
25 * than fetch characterbitmap for characternumber
26 * 2 color mode:
27 * set bit in characterbitmap gives pixel in color of the lower 3 color bits
28 * cleared bit gives pixel in backgroundcolor
29 * 4 color mode:
30 * 2 bits in the characterbitmap are viewed together
31 * 00: backgroundcolor
32 * 11: colorram
33 * 01: helpercolor
34 * 10: framecolor
35 * advance to next character in videorram until line is full
36 * repeat this 8 or 16 lines, before moving to next line in videoram
37 * screen ratio ntsc, pal 4/3
38 *
39 * pal version:
40 * can contain greater visible areas
41 * expects other sync position (so ntsc modules may be displayed at
42 * the upper left corner of the tv screen)
43 * pixel ratio seems to be different on pal and ntsc
44 *
45 * commodore vic20 notes
46 * 6560 adress line 13 is connected inverted to address line 15 of the board
47 * 1 K 4 bit ram at 0x9400 is additional connected as 4 higher bits
48 * of the 6560 (colorram) without decoding the 6560 address line a8..a13
49 *
50 ****************************************************************************/
51
52#ifndef __VIC6560_H__
53#define __VIC6560_H__
54
55#include "devcb.h"
56
57
58/***************************************************************************
59    TYPE DEFINITIONS
60***************************************************************************/
61
62typedef UINT8 (*vic656x_lightpen_x_callback)(running_machine *machine);
63typedef UINT8 (*vic656x_lightpen_y_callback)(running_machine *machine);
64typedef UINT8 (*vic656x_lightpen_button_callback)(running_machine *machine);
65typedef UINT8 (*vic656x_paddle_callback)(running_machine *machine);
66
67typedef int (*vic656x_dma_read)(running_machine *machine, int);
68typedef int (*vic656x_dma_read_color)(running_machine *machine, int);
69
70
71typedef enum
72{
73   VIC6560,
74   VIC6561
75} vic656x_type;
76
77typedef struct _vic656x_interface vic656x_interface;
78struct _vic656x_interface
79{
80   const char         *screen;
81
82   vic656x_type type;
83
84   vic656x_lightpen_x_callback        x_cb;
85   vic656x_lightpen_y_callback        y_cb;
86   vic656x_lightpen_button_callback   button_cb;
87
88   vic656x_paddle_callback        paddle0_cb, paddle1_cb;
89
90   vic656x_dma_read          dma_read;
91   vic656x_dma_read_color    dma_read_color;
92};
93
94/***************************************************************************
95    CONSTANTS
96***************************************************************************/
97
98#define VIC6560_VRETRACERATE 60
99#define VIC6561_VRETRACERATE 50
100#define VIC656X_HRETRACERATE 15625
101
102#define VIC6560_MAME_XPOS  4         /* xleft not displayed */
103#define VIC6560_MAME_YPOS  10         /* y up not displayed */
104#define VIC6561_MAME_XPOS  20
105#define VIC6561_MAME_YPOS  10
106#define VIC6560_MAME_XSIZE   200
107#define VIC6560_MAME_YSIZE   248
108#define VIC6561_MAME_XSIZE   224
109#define VIC6561_MAME_YSIZE   296
110/* real values */
111#define VIC6560_LINES 261
112#define VIC6561_LINES 312
113/*#define VREFRESHINLINES 9 */
114#define VIC6560_XSIZE   (4+201)         /* 4 left not visible */
115#define VIC6560_YSIZE   (10+251)      /* 10 not visible */
116/* cycles 65 */
117#define VIC6561_XSIZE   (20+229)      /* 20 left not visible */
118#define VIC6561_YSIZE   (10+302)      /* 10 not visible */
119/* cycles 71 */
120
121
122/* the following values depend on the VIC clock,
123 * but to achieve TV-frequency the clock must have a fix frequency */
124#define VIC6560_CLOCK   (14318181/14)
125#define VIC6561_CLOCK   (4433618/4)
126
127
128/***************************************************************************
129    FUNCTION PROTOTYPES
130***************************************************************************/
131
132DEVICE_GET_INFO( vic656x );
133
134/***************************************************************************
135    DEVICE CONFIGURATION MACROS
136***************************************************************************/
137
138#define VIC656X DEVICE_GET_INFO_NAME( vic656x )
139#define SOUND_VIC656X VIC656X
140
141#define MDRV_VIC656X_ADD(_tag, _interface) \
142   MDRV_DEVICE_ADD(_tag, SOUND, 0) \
143   MDRV_DEVICE_CONFIG_DATAPTR(sound_config, type, SOUND_VIC656X) \
144   MDRV_DEVICE_CONFIG(_interface)
145
146
147/*----------- defined in video/vic6560.c -----------*/
148
149WRITE8_DEVICE_HANDLER( vic6560_port_w );
150READ8_DEVICE_HANDLER( vic6560_port_r );
151
152void vic656x_raster_interrupt_gen( running_device *device );
153UINT32 vic656x_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect );
154
155
156#endif /* __VIC6560_H__ */
src/mess/includes/vic20.h
r7393r7394
2525   running_device *via1;
2626   running_device *iec;
2727   running_device *cassette;
28   running_device *vic6560;
28   running_device *mos6560;
2929 
3030   /* timers */
3131   running_device *cassette_timer;
src/mess/mess.mak
r7393r7394
239239#SOUNDS += TMC0281
240240#SOUNDS += TMS5100
241241#SOUNDS += TMS5110A
242SOUNDS += MOS656X
242243
243244
244245#-------------------------------------------------
r7393r7394
698699   $(MESS_DRIVERS)/pet.o      \
699700   $(MESS_MACHINE)/pet.o      \
700701   $(MESS_DRIVERS)/c64.o      \
701   $(MESS_AUDIO)/vic6560.o      \
702702   $(MESS_DRIVERS)/vic20.o      \
703703   $(MESS_MACHINE)/vic1112.o   \
704704   $(MESS_AUDIO)/ted7360.o      \
src/mess/drivers/vic20.c
r7393r7394
5757    TODO:
5858 
5959    - C1540 is unreliable (VIA timing issues?)
60    - devicify VIC6560/6561
6160    - clean up inputs
6261    - clean up VIA interface
63    - access violation in vic6560.c
62    - access violation in mos6560.c
6463        * In the Chips (Japan, USA).60
6564        * K-Star Patrol (Europe).60
6665        * Seafox (Japan, USA).60
r7393r7394
8483#include "machine/ieee488.h"
8584#include "machine/vic1112.h"
8685#include "machine/cbmipt.h"
87#include "audio/vic6560.h"
86#include "sound/mos6560.h"
8887#include "sound/dac.h"
8988 
9089/* Memory Maps */
r7393r7394
9998//  AM_RANGE(0x4000, 0x5fff) BLK2
10099//  AM_RANGE(0x6000, 0x7fff) BLK3
101100   AM_RANGE(0x8000, 0x8fff) AM_ROM
102   AM_RANGE(0x9000, 0x900f) AM_DEVREADWRITE(M6560_TAG, vic6560_port_r, vic6560_port_w)
101   AM_RANGE(0x9000, 0x900f) AM_DEVREADWRITE(M6560_TAG, mos6560_port_r, mos6560_port_w)
103102   AM_RANGE(0x9110, 0x911f) AM_DEVREADWRITE(M6522_0_TAG, via_r, via_w)
104103   AM_RANGE(0x9120, 0x912f) AM_DEVREADWRITE(M6522_1_TAG, via_r, via_w)
105104   AM_RANGE(0x9400, 0x97ff) AM_RAM
r7393r7394
114113#ifdef UNUSED_FUNCTION
115114static INPUT_PORTS_START( vic_lightpen_6560 )
116115   PORT_START( "LIGHTX" )
117   PORT_BIT( 0xff, 0, IPT_PADDLE ) PORT_NAME("Lightpen X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,(VIC6560_MAME_XSIZE - 1)) PORT_CATEGORY(12) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH)
116   PORT_BIT( 0xff, 0, IPT_PADDLE ) PORT_NAME("Lightpen X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,(MOS6560_MAME_XSIZE - 1)) PORT_CATEGORY(12) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH)
118117 
119118   PORT_START( "LIGHTY" )
120   PORT_BIT( 0xff, 0, IPT_PADDLE ) PORT_NAME("Lightpen Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,(VIC6560_MAME_YSIZE - 1)) PORT_CATEGORY(12) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)
119   PORT_BIT( 0xff, 0, IPT_PADDLE ) PORT_NAME("Lightpen Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,(MOS6560_MAME_YSIZE - 1)) PORT_CATEGORY(12) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)
121120INPUT_PORTS_END
122121 
123122 
124123static INPUT_PORTS_START( vic_lightpen_6561 )
125124   PORT_START( "LIGHTX" )
126   PORT_BIT( 0xff, 0, IPT_PADDLE ) PORT_NAME("Lightpen X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,(VIC6560_MAME_XSIZE - 1)) PORT_CATEGORY(12) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH)
125   PORT_BIT( 0xff, 0, IPT_PADDLE ) PORT_NAME("Lightpen X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,(MOS6560_MAME_XSIZE - 1)) PORT_CATEGORY(12) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH)
127126 
128127   PORT_START( "LIGHTY" )
129   PORT_BIT( 0x1ff, 0, IPT_PADDLE ) PORT_NAME("Lightpen Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,(VIC6561_MAME_YSIZE - 1)) PORT_CATEGORY(12) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)
128   PORT_BIT( 0x1ff, 0, IPT_PADDLE ) PORT_NAME("Lightpen Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(2) PORT_MINMAX(0,(MOS6561_MAME_YSIZE - 1)) PORT_CATEGORY(12) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)
130129INPUT_PORTS_END
131130#endif
132131 
r7393r7394
449448   { NULL}
450449};
451450 
452/* VIC6560 Interface */
451/* MOS6560 Interface */
453452 
454#define VC20ADDR2VIC6560ADDR(a) (((a) > 0x8000) ? ((a) & 0x1fff) : ((a) | 0x2000))
455#define VIC6560ADDR2VC20ADDR(a) (((a) > 0x2000) ? ((a) & 0x1fff) : ((a) | 0x8000))
453#define VC20ADDR2MOS6560ADDR(a) (((a) > 0x8000) ? ((a) & 0x1fff) : ((a) | 0x2000))
454#define MOS6560ADDR2VC20ADDR(a) (((a) > 0x2000) ? ((a) & 0x1fff) : ((a) | 0x8000))
456455 
457static int vic6560_dma_read_color( running_machine *machine, int offset )
456static int vic20_dma_read_color( running_machine *machine, int offset )
458457{
459458   const address_space *program = cputag_get_address_space(machine, M6502_TAG, ADDRESS_SPACE_PROGRAM);
460459 
461460   return memory_read_byte(program, 0x9400 | (offset & 0x3ff));
462461}
463462 
464static int vic6560_dma_read( running_machine *machine, int offset )
463static int vic20_dma_read( running_machine *machine, int offset )
465464{
466465   const address_space *program = cputag_get_address_space(machine, M6502_TAG, ADDRESS_SPACE_PROGRAM);
467466 
468   return memory_read_byte(program, VIC6560ADDR2VC20ADDR(offset));
467   return memory_read_byte(program, MOS6560ADDR2VC20ADDR(offset));
469468}
470469 
471470static UINT8 vic20_lightx_cb( running_machine *machine )
r7393r7394
493492   return input_port_read(machine, "PADDLE1");
494493}
495494 
496static const vic656x_interface vic20_6560_intf =
495static const mos6560_interface vic20_6560_intf =
497496{
498497   "screen",   /* screen */
499   VIC6560,
498   MOS6560,
500499   vic20_lightx_cb, vic20_lighty_cb, vic20_lightbut_cb,   /* lightgun cb */
501500   vic20_paddle0_cb, vic20_paddle1_cb,      /* paddle cb */
502   vic6560_dma_read, vic6560_dma_read_color   /* DMA */
501   vic20_dma_read, vic20_dma_read_color   /* DMA */
503502};
504503 
505static const vic656x_interface vic20_6561_intf =
504static const mos6560_interface vic20_6561_intf =
506505{
507506   "screen",   /* screen */
508   VIC6561,
507   MOS6561,
509508   vic20_lightx_cb, vic20_lighty_cb, vic20_lightbut_cb,   /* lightgun cb */
510509   vic20_paddle0_cb, vic20_paddle1_cb,      /* paddle cb */
511   vic6560_dma_read, vic6560_dma_read_color   /* DMA */
510   vic20_dma_read, vic20_dma_read_color   /* DMA */
512511};
513512 
514513 
r7393r7394
525524   state->iec = devtag_get_device(machine, IEC_TAG);
526525   state->cassette = devtag_get_device(machine, CASSETTE_TAG);
527526   state->cassette_timer = devtag_get_device(machine, TIMER_C1530_TAG);
528   state->vic6560 = devtag_get_device(machine, M6560_TAG);
527   state->mos6560 = devtag_get_device(machine, M6560_TAG);
529528 
530529   /* set VIA clocks */
531530   state->via0->set_clock(cputag_get_clock(machine, M6502_TAG));
r7393r7394
597596 
598597/* Graphics Definitions and Video Emulation */
599598 
600static const unsigned char vic6560_palette[] =
599static const unsigned char mos6560_palette[] =
601600{
602601/* ripped from vice, a very excellent emulator */
603602/* black, white, red, cyan */
r7393r7394
614613{
615614   int i;
616615 
617   for (i = 0; i < sizeof(vic6560_palette) / 3; i++)
616   for (i = 0; i < sizeof(mos6560_palette) / 3; i++)
618617   {
619      palette_set_color_rgb(machine, i, vic6560_palette[i * 3], vic6560_palette[i * 3 + 1], vic6560_palette[i * 3 + 2]);
618      palette_set_color_rgb(machine, i, mos6560_palette[i * 3], mos6560_palette[i * 3 + 1], mos6560_palette[i * 3 + 2]);
620619   }
621620}
622621 
623622static VIDEO_UPDATE( vic20 )
624623{
625624   vic20_state *state = (vic20_state *)screen->machine->driver_data;
626   vic656x_video_update(state->vic6560, bitmap, cliprect);
625   mos6560_video_update(state->mos6560, bitmap, cliprect);
627626   return 0;
628627}
629628 
r7393r7394
632631static INTERRUPT_GEN( vic20_raster_interrupt )
633632{
634633   vic20_state *state = (vic20_state *)device->machine->driver_data;
635   vic656x_raster_interrupt_gen(state->vic6560);
634   mos6560_raster_interrupt_gen(state->mos6560);
636635}
637636 
638637static MACHINE_DRIVER_START( vic20_common )
r7393r7394
668667   MDRV_IMPORT_FROM( vic20_common )
669668 
670669   /* basic machine hardware */
671   MDRV_CPU_ADD(M6502_TAG, M6502, VIC6560_CLOCK)
670   MDRV_CPU_ADD(M6502_TAG, M6502, MOS6560_CLOCK)
672671   MDRV_CPU_PROGRAM_MAP(vic20_mem)
673   MDRV_CPU_PERIODIC_INT(vic20_raster_interrupt, VIC656X_HRETRACERATE)
672   MDRV_CPU_PERIODIC_INT(vic20_raster_interrupt, MOS656X_HRETRACERATE)
674673 
675674   MDRV_MACHINE_START(vic20)
676675 
677676   /* video hardware */
678677   MDRV_SCREEN_ADD("screen", RASTER)
679   MDRV_SCREEN_REFRESH_RATE(VIC6560_VRETRACERATE)
678   MDRV_SCREEN_REFRESH_RATE(MOS6560_VRETRACERATE)
680679   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
681680   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
682   MDRV_SCREEN_SIZE((VIC6560_XSIZE + 7) & ~7, VIC6560_YSIZE)
683   MDRV_SCREEN_VISIBLE_AREA(VIC6560_MAME_XPOS, VIC6560_MAME_XPOS + VIC6560_MAME_XSIZE - 1, VIC6560_MAME_YPOS, VIC6560_MAME_YPOS + VIC6560_MAME_YSIZE - 1)
681   MDRV_SCREEN_SIZE((MOS6560_XSIZE + 7) & ~7, MOS6560_YSIZE)
682   MDRV_SCREEN_VISIBLE_AREA(MOS6560_MAME_XPOS, MOS6560_MAME_XPOS + MOS6560_MAME_XSIZE - 1, MOS6560_MAME_YPOS, MOS6560_MAME_YPOS + MOS6560_MAME_YSIZE - 1)
684683 
685684   MDRV_PALETTE_LENGTH(16)
686685   MDRV_PALETTE_INIT( vic20 )
r7393r7394
689688 
690689   /* sound hardware */
691690   MDRV_SPEAKER_STANDARD_MONO("mono")
692   MDRV_VIC656X_ADD(M6560_TAG, vic20_6560_intf)
691   MDRV_MOS656X_ADD(M6560_TAG, vic20_6560_intf)
693692   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
694693   MDRV_SOUND_ADD("dac", DAC, 0)
695694   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
r7393r7394
699698   MDRV_IMPORT_FROM( vic20_common )
700699 
701700   /* basic machine hardware */
702   MDRV_CPU_ADD(M6502_TAG, M6502, VIC6561_CLOCK)
701   MDRV_CPU_ADD(M6502_TAG, M6502, MOS6561_CLOCK)
703702   MDRV_CPU_PROGRAM_MAP(vic20_mem)
704   MDRV_CPU_PERIODIC_INT(vic20_raster_interrupt, VIC656X_HRETRACERATE)
703   MDRV_CPU_PERIODIC_INT(vic20_raster_interrupt, MOS656X_HRETRACERATE)
705704 
706705   MDRV_MACHINE_START(vic20)
707706 
708707   /* video hardware */
709708   MDRV_SCREEN_ADD("screen", RASTER)
710   MDRV_SCREEN_REFRESH_RATE(VIC6561_VRETRACERATE)
709   MDRV_SCREEN_REFRESH_RATE(MOS6561_VRETRACERATE)
711710   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
712711   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
713   MDRV_SCREEN_SIZE((VIC6561_XSIZE + 7) & ~7, VIC6561_YSIZE)
714   MDRV_SCREEN_VISIBLE_AREA(VIC6561_MAME_XPOS, VIC6561_MAME_XPOS + VIC6561_MAME_XSIZE - 1, VIC6561_MAME_YPOS, VIC6561_MAME_YPOS + VIC6561_MAME_YSIZE - 1)
712   MDRV_SCREEN_SIZE((MOS6561_XSIZE + 7) & ~7, MOS6561_YSIZE)
713   MDRV_SCREEN_VISIBLE_AREA(MOS6561_MAME_XPOS, MOS6561_MAME_XPOS + MOS6561_MAME_XSIZE - 1, MOS6561_MAME_YPOS, MOS6561_MAME_YPOS + MOS6561_MAME_YSIZE - 1)
715714 
716715   MDRV_PALETTE_LENGTH(16)
717716   MDRV_PALETTE_INIT( vic20 )
r7393r7394
720719 
721720   /* sound hardware */
722721   MDRV_SPEAKER_STANDARD_MONO("mono")
723   MDRV_VIC656X_ADD(M6560_TAG, vic20_6561_intf)
722   MDRV_MOS656X_ADD(M6560_TAG, vic20_6561_intf)
724723   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
725724   MDRV_SOUND_ADD("dac", DAC, 0)
726725   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team