Previous 15994 Revisions Next

r7373 Tuesday 16th February, 2010 at 13:04:10 UTC by Fabio Priuli
[CBM] converted vic6560 (VIC I) to be a device and updated vic20 to use the new code
[src/mess]mess.mak
[src/mess/audio]vic6560.c vic6560.h*
[src/mess/drivers]vic20.c
[src/mess/includes]vic20.h
[src/mess/machine]cbmipt.c cbmipt.h
[src/mess/video]vic6560.c vic6560.h

src/mess/audio/vic6560.c
r7372r7373
11/***************************************************************************
22
3  MOS video interface chip 6560 (and sound interface)
4  PeT mess@utanet.at
3    MOS video interface chip 6560
4    PeT mess@utanet.at
55
6  main part in video/
76
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
813***************************************************************************/
914
1015#include "emu.h"
1116#include "streams.h"
1217
13#include "video/vic6560.h"
18#include "audio/vic6560.h"
1419
1520
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
1678#define VERBOSE_LEVEL 0
1779#define DBG_LOG(N,M,A) \
1880   do { \
1981      if(VERBOSE_LEVEL >= N) \
2082      { \
2183         if( M ) \
22            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(machine)), (char*) M ); \
84            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(device->machine)), (char*) M ); \
2385         logerror A; \
2486      } \
2587   } while (0)
2688
2789
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
28435/*
29436 * assumed model:
30437 * each write to a ton/noise generated starts it new
r7372r7373
49456
50457#define NOISE_BUFFER_SIZE_SEC 5
51458
52#define TONE1_ON (vic6560[0xa]&0x80)
53#define TONE2_ON (vic6560[0xb]&0x80)
54#define TONE3_ON (vic6560[0xc]&0x80)
55#define NOISE_ON (vic6560[0xd]&0x80)
56#define VOLUME (vic6560[0xe]&0x0f)
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)
57464
465#define VIC656X_CLOCK ((vic6560->type == VIC6561) ? VIC6561_CLOCK : VIC6560_CLOCK)
466
58467#define TONE_FREQUENCY_MIN  (VIC656X_CLOCK/256/128)
59#define TONE1_VALUE (8*(128-((vic6560[0xa]+1)&0x7f)))
468
469#define TONE1_VALUE (8 * (128 - ((vic6560->reg[0x0a] + 1) & 0x7f)))
60470#define TONE1_FREQUENCY (VIC656X_CLOCK/32/TONE1_VALUE)
61#define TONE2_VALUE (4*(128-((vic6560[0xb]+1)&0x7f)))
471
472#define TONE2_VALUE (4 * (128 - ((vic6560->reg[0x0b] + 1) & 0x7f)))
62473#define TONE2_FREQUENCY (VIC656X_CLOCK/32/TONE2_VALUE)
63#define TONE3_VALUE (2*(128-((vic6560[0xc]+1)&0x7f)))
474
475#define TONE3_VALUE (2 * (128 - ((vic6560->reg[0x0c] + 1) & 0x7f)))
64476#define TONE3_FREQUENCY (VIC656X_CLOCK/32/TONE3_VALUE)
65#define NOISE_VALUE (32*(128-((vic6560[0xd]+1)&0x7f)))
477
478#define NOISE_VALUE (32 * (128 - ((vic6560->reg[0x0d] + 1) & 0x7f)))
66479#define NOISE_FREQUENCY (VIC656X_CLOCK/NOISE_VALUE)
480
67481#define NOISE_FREQUENCY_MAX (VIC656X_CLOCK/32/1)
68482
69static int tone1pos = 0, tone2pos = 0, tone3pos = 0,
70   tonesize, tone1samples = 1, tone2samples = 1, tone3samples = 1,
71   noisesize,        /* number of samples */
72   noisepos = 0,         /* pos of tone */
73   noisesamples = 1;     /* count of samples to give out per tone */
74483
75static sound_stream *channel;
76static INT16 *tone;
77
78static INT8 *noise;
79
80void vic6560_soundport_w (running_machine *machine, int offset, int data)
484static void vic6560_soundport_w( running_device *device, int offset, int data )
81485{
82    int old = vic6560[offset];
83   stream_update(channel);
486   vic656x_state *vic6560 = get_safe_token(device);
487   int old = vic6560->reg[offset];
488   stream_update(vic6560->channel);
84489
85490   switch (offset)
86491   {
87   case 0xa:
88      vic6560[offset] = data;
492   case 0x0a:
493      vic6560->reg[offset] = data;
89494      if (!(old & 0x80) && TONE1_ON)
90495      {
91         tone1pos = 0;
92         tone1samples = machine->sample_rate / TONE1_FREQUENCY;
93         if (tone1samples == 0)
94            tone1samples = 1;
496         vic6560->tone1pos = 0;
497         vic6560->tone1samples = device->machine->sample_rate / TONE1_FREQUENCY;
498         if (!vic6560->tone1samples == 0)
499            vic6560->tone1samples = 1;
95500      }
96      DBG_LOG (1, "vic6560", ("tone1 %.2x %d\n", data, TONE1_FREQUENCY));
501      DBG_LOG(1, "vic6560", ("tone1 %.2x %d\n", data, TONE1_FREQUENCY));
97502      break;
98   case 0xb:
99      vic6560[offset] = data;
503   case 0x0b:
504      vic6560->reg[offset] = data;
100505      if (!(old & 0x80) && TONE2_ON)
101506      {
102         tone2pos = 0;
103         tone2samples = machine->sample_rate / TONE2_FREQUENCY;
104         if (tone2samples == 0)
105            tone2samples = 1;
507         vic6560->tone2pos = 0;
508         vic6560->tone2samples = device->machine->sample_rate / TONE2_FREQUENCY;
509         if (vic6560->tone2samples == 0)
510            vic6560->tone2samples = 1;
106511      }
107      DBG_LOG (1, "vic6560", ("tone2 %.2x %d\n", data, TONE2_FREQUENCY));
512      DBG_LOG(1, "vic6560", ("tone2 %.2x %d\n", data, TONE2_FREQUENCY));
108513      break;
109   case 0xc:
110      vic6560[offset] = data;
514   case 0x0c:
515      vic6560->reg[offset] = data;
111516      if (!(old & 0x80) && TONE3_ON)
112517      {
113         tone3pos = 0;
114         tone3samples = machine->sample_rate / TONE3_FREQUENCY;
115         if (tone2samples == 0)
116            tone2samples = 1;
518         vic6560->tone3pos = 0;
519         vic6560->tone3samples = device->machine->sample_rate / TONE3_FREQUENCY;
520         if (vic6560->tone3samples == 0)
521            vic6560->tone3samples = 1;
117522      }
118      DBG_LOG (1, "vic6560", ("tone3 %.2x %d\n", data, TONE3_FREQUENCY));
523      DBG_LOG(1, "vic6560", ("tone3 %.2x %d\n", data, TONE3_FREQUENCY));
119524      break;
120   case 0xd:
121      vic6560[offset] = data;
525   case 0x0d:
526      vic6560->reg[offset] = data;
122527      if (NOISE_ON)
123528      {
124         noisesamples = (int) ((double) NOISE_FREQUENCY_MAX * machine->sample_rate
529         vic6560->noisesamples = (int) ((double) NOISE_FREQUENCY_MAX * device->machine->sample_rate
125530                          * NOISE_BUFFER_SIZE_SEC / NOISE_FREQUENCY);
126531         DBG_LOG (1, "vic6560", ("noise %.2x %d sample:%d\n",
127                           data, NOISE_FREQUENCY, noisesamples));
128         if ((double) noisepos / noisesamples >= 1.0)
532                           data, NOISE_FREQUENCY, vic6560->noisesamples));
533         if ((double) vic6560->noisepos / vic6560->noisesamples >= 1.0)
129534         {
130            noisepos = 0;
535            vic6560->noisepos = 0;
131536         }
132537      }
133538      else
134539      {
135         noisepos = 0;
540         vic6560->noisepos = 0;
136541      }
137542      break;
138   case 0xe:
139      vic6560[offset] = (old & ~0xf) | (data & 0xf);
140      DBG_LOG (3, "vic6560", ("volume %d\n", data & 0xf));
543   case 0x0e:
544      vic6560->reg[offset] = (old & ~0x0f) | (data & 0x0f);
545      DBG_LOG (3, "vic6560", ("volume %d\n", data & 0x0f));
141546      break;
142547   }
143548}
r7372r7373
145550/************************************/
146551/* Sound handler update             */
147552/************************************/
553
148554static STREAM_UPDATE( vic6560_update )
149555{
556   vic656x_state *vic6560 = get_safe_token(device);
150557   int i, v;
151558   stream_sample_t *buffer = outputs[0];
152559
153560   for (i = 0; i < samples; i++)
154561   {
155562      v = 0;
156      if (TONE1_ON /*||(tone1pos!=0) */ )
563      if (TONE1_ON /*||(vic6560->tone1pos != 0) */ )
157564      {
158         v += tone[tone1pos * tonesize / tone1samples];
159         tone1pos++;
565         v += vic6560->tone[vic6560->tone1pos * vic6560->tonesize / vic6560->tone1samples];
566         vic6560->tone1pos++;
160567#if 0
161         tone1pos %= tone1samples;
568         vic6560->tone1pos %= vic6560->tone1samples;
162569#else
163         if (tone1pos >= tone1samples)
570         if (vic6560->tone1pos >= vic6560->tone1samples)
164571         {
165            tone1pos = 0;
166            tone1samples = device->machine->sample_rate / TONE1_FREQUENCY;
167            if (tone1samples == 0)
168               tone1samples = 1;
572            vic6560->tone1pos = 0;
573            vic6560->tone1samples = device->machine->sample_rate / TONE1_FREQUENCY;
574            if (vic6560->tone1samples == 0)
575               vic6560->tone1samples = 1;
169576         }
170577#endif
171578      }
172      if (TONE2_ON /*||(tone2pos!=0) */ )
579      if (TONE2_ON /*||(vic6560->tone2pos != 0) */ )
173580      {
174         v += tone[tone2pos * tonesize / tone2samples];
175         tone2pos++;
581         v += vic6560->tone[vic6560->tone2pos * vic6560->tonesize / vic6560->tone2samples];
582         vic6560->tone2pos++;
176583#if 0
177         tone2pos %= tone2samples;
584         vic6560->tone2pos %= vic6560->tone2samples;
178585#else
179         if (tone2pos >= tone2samples)
586         if (vic6560->tone2pos >= vic6560->tone2samples)
180587         {
181            tone2pos = 0;
182            tone2samples = device->machine->sample_rate / TONE2_FREQUENCY;
183            if (tone2samples == 0)
184               tone2samples = 1;
588            vic6560->tone2pos = 0;
589            vic6560->tone2samples = device->machine->sample_rate / TONE2_FREQUENCY;
590            if (vic6560->tone2samples == 0)
591               vic6560->tone2samples = 1;
185592         }
186593#endif
187594      }
188      if (TONE3_ON /*||(tone3pos!=0) */ )
595      if (TONE3_ON /*||(vic6560->tone3pos != 0) */ )
189596      {
190         v += tone[tone3pos * tonesize / tone3samples];
191         tone3pos++;
597         v += vic6560->tone[vic6560->tone3pos * vic6560->tonesize / vic6560->tone3samples];
598         vic6560->tone3pos++;
192599#if 0
193         tone3pos %= tone3samples;
600         vic6560->tone3pos %= vic6560->tone3samples;
194601#else
195         if (tone3pos >= tone3samples)
602         if (vic6560->tone3pos >= vic6560->tone3samples)
196603         {
197            tone3pos = 0;
198            tone3samples = device->machine->sample_rate / TONE3_FREQUENCY;
199            if (tone3samples == 0)
200               tone3samples = 1;
604            vic6560->tone3pos = 0;
605            vic6560->tone3samples = device->machine->sample_rate / TONE3_FREQUENCY;
606            if (vic6560->tone3samples == 0)
607               vic6560->tone3samples = 1;
201608         }
202609#endif
203610      }
204611      if (NOISE_ON)
205612      {
206         v += noise[(int) ((double) noisepos * noisesize / noisesamples)];
207         noisepos++;
208         if ((double) noisepos / noisesamples >= 1.0)
613         v += vic6560->noise[(int) ((double) vic6560->noisepos * vic6560->noisesize / vic6560->noisesamples)];
614         vic6560->noisepos++;
615         if ((double) vic6560->noisepos / vic6560->noisesamples >= 1.0)
209616         {
210            noisepos = 0;
617            vic6560->noisepos = 0;
211618         }
212619      }
213620      v = (v * VOLUME) << 2;
r7372r7373
223630   }
224631}
225632
633
634/*****************************************************************************
635    DEVICE INTERFACE
636*****************************************************************************/
637
226638/************************************/
227639/* Sound handler start          */
228640/************************************/
229641
230static DEVICE_START(vic6560_sound)
642static void vic656x_sound_start( running_device *device )
231643{
644   vic656x_state *vic6560 = get_safe_token(device);
232645   int i;
233646
234   channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, vic6560_update);
647   vic6560->channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, vic6560_update);
235648
236   /* buffer for fastest played sample for 5 second
237     * so we have enough data for min 5 second */
238   noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC;
239   noise = auto_alloc_array(device->machine, INT8, noisesize);
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);
240652   {
241653      int noiseshift = 0x7ffff8;
242654      char data;
243655
244      for (i = 0; i < noisesize; i++)
656      for (i = 0; i < vic6560->noisesize; i++)
245657      {
246658         data = 0;
247659         if (noiseshift & 0x400000)
r7372r7373
260672            data |= 0x02;
261673         if (noiseshift & 0x000004)
262674            data |= 0x01;
263         noise[i] = data;
675         vic6560->noise[i] = data;
264676         if (((noiseshift & 0x400000) == 0) != ((noiseshift & 0x002000) == 0))
265677            noiseshift = (noiseshift << 1) | 1;
266678         else
267679            noiseshift <<= 1;
268680      }
269681   }
270   tonesize = device->machine->sample_rate / TONE_FREQUENCY_MIN;
682   vic6560->tonesize = device->machine->sample_rate / TONE_FREQUENCY_MIN;
271683
272   if (tonesize > 0)
684   if (vic6560->tonesize > 0)
273685   {
274      tone = auto_alloc_array(device->machine, INT16, tonesize);
686      vic6560->tone = auto_alloc_array(device->machine, INT16, vic6560->tonesize);
275687
276      for (i = 0; i < tonesize; i++)
688      for (i = 0; i < vic6560->tonesize; i++)
277689      {
278         tone[i] = (INT16)(sin (2 * M_PI * i / tonesize) * 127 + 0.5);
690         vic6560->tone[i] = (INT16)(sin (2 * M_PI * i / vic6560->tonesize) * 127 + 0.5);
279691      }
280692   }
281693   else
282694   {
283      tone = NULL;
695      vic6560->tone = NULL;
284696   }
285697}
286698
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;
287704
288DEVICE_GET_INFO( vic6560_sound )
289{
290   switch (state)
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)
291724   {
292      /* --- the following bits of info are returned as pointers to data or functions --- */
293      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(vic6560_sound);   break;
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   }
294738
295      /* --- the following bits of info are returned as NULL-terminated strings --- */
296      case DEVINFO_STR_NAME:                     strcpy(info->s, "6560 VIC");            break;
297      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                  break;
298   }
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);
299778}
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
r0r7373
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/video/vic6560.c
r7372r7373
1/***************************************************************************
2
3  MOS video interface chip 6560
4  PeT mess@utanet.at
5
6***************************************************************************/
7
8#include <math.h>
9#include <stdio.h>
10#include "emu.h"
11#include "utils.h"
12
13#include "vic6560.h"
14#include "sound/dac.h"
15
16#define VERBOSE_LEVEL 0
17#define DBG_LOG(N,M,A) \
18   do { \
19      if(VERBOSE_LEVEL >= N) \
20      { \
21         if( M ) \
22            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(machine)), (char*) M ); \
23         logerror A; \
24      } \
25   } while (0)
26
27static const unsigned char vic6560_palette[] =
28{
29/* ripped from vice, a very excellent emulator */
30/* black, white, red, cyan */
31   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0xf0,
32/* purple, green, blue, yellow */
33   0x60, 0x00, 0x60, 0x00, 0xa0, 0x00, 0x00, 0x00, 0xf0, 0xd0, 0xd0, 0x00,
34/* orange, light orange, pink, light cyan, */
35   0xc0, 0xa0, 0x00, 0xff, 0xa0, 0x00, 0xf0, 0x80, 0x80, 0x00, 0xff, 0xff,
36/* light violett, light green, light blue, light yellow */
37   0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xa0, 0xff, 0xff, 0xff, 0x00
38};
39
40UINT8 vic6560[16];
41
42/* 2008-05 FP: lightpen code needs to read input port from vc20.c */
43
44#define LIGHTPEN_BUTTON      (((input_port_read(space->machine, "CTRLSEL") & 0xf0) == 0x20) && (input_port_read(space->machine, "JOY") & 0x40))
45#define LIGHTPEN_X_VALUE   (input_port_read(space->machine, "LIGHTX") & ~0x01)
46#define LIGHTPEN_Y_VALUE   (input_port_read(space->machine, "LIGHTY") & ~0x01)
47
48/* lightpen delivers values from internal counters
49 * they do not start with the visual area or frame area */
50#define VIC6560_X_BEGIN 38
51#define VIC6560_Y_BEGIN -6            /* first 6 lines after retrace not for lightpen! */
52#define VIC6561_X_BEGIN 38
53#define VIC6561_Y_BEGIN -6
54#define VIC656X_X_BEGIN (vic6560_pal?VIC6561_X_BEGIN:VIC6560_X_BEGIN)
55#define VIC656X_Y_BEGIN (vic6560_pal?VIC6561_Y_BEGIN:VIC6560_Y_BEGIN)
56/* lightpen behaviour in pal or mono multicolor not tested */
57#define VIC6560_X_VALUE ((LIGHTPEN_X_VALUE+VIC656X_X_BEGIN \
58           +VIC656X_MAME_XPOS)/2)
59#define VIC6560_Y_VALUE ((LIGHTPEN_Y_VALUE+VIC656X_Y_BEGIN \
60           +VIC656X_MAME_YPOS)/2)
61
62#define INTERLACE (vic6560&0x80)      /*only ntsc version */
63/* ntsc 1 - 8 */
64/* pal 5 - 19 */
65#define XPOS (((int)vic6560[0]&0x7f)*4)
66#define YPOS ((int)vic6560[1]*2)
67
68/* ntsc values >= 31 behave like 31 */
69/* pal value >= 32 behave like 32 */
70#define CHARS_X ((int)vic6560[2]&0x7f)
71#define CHARS_Y (((int)vic6560[3]&0x7e)>>1)
72
73#define MATRIX8X16 (vic6560[3]&1)      /* else 8x8 */
74#define CHARHEIGHT (MATRIX8X16?16:8)
75#define XSIZE (CHARS_X*8)
76#define YSIZE (CHARS_Y*CHARHEIGHT)
77
78/* colorram and backgroundcolor are changed */
79#define INVERTED (!(vic6560[0x0f]&8))
80
81#define CHARGENADDR (((int)vic6560[5]&0xf)<<10)
82#define VIDEOADDR ( ( ((int)vic6560[5]&0xf0)<<(10-4))\
83          | ( ((int)vic6560[2]&0x80)<<(9-7)) )
84#define VIDEORAMSIZE (YSIZE*XSIZE)
85#define CHARGENSIZE (256*HEIGHTPIXEL)
86
87#define HELPERCOLOR (vic6560[0xe]>>4)
88#define BACKGROUNDCOLOR (vic6560[0xf]>>4)
89#define FRAMECOLOR (vic6560[0xf]&7)
90
91int vic6560_pal;
92
93static bitmap_t *vic6560_bitmap;
94static int rasterline = 0, lastline = 0;
95static void vic6560_drawlines (running_machine *machine, int start, int last);
96
97static int (*vic_dma_read) (running_machine *machine, int);
98static int (*vic_dma_read_color) (running_machine *machine, int);
99
100static int vic656x_xsize, vic656x_ysize, vic656x_lines, vic656x_vretracerate;
101static int charheight, matrix8x16, inverted;
102static int chars_x, chars_y;
103static int xsize, ysize, xpos, ypos;
104static int chargenaddr, videoaddr;
105
106/* values in videoformat */
107static UINT16 backgroundcolor, framecolor, helpercolor;
108
109/* arrays for bit to color conversion without condition checking */
110static UINT16 mono[2], monoinverted[2], multi[4], multiinverted[4];
111
112static void vic656x_init (void)
113{
114   vic656x_xsize = VIC656X_XSIZE;
115   vic656x_ysize = VIC656X_YSIZE;
116   vic656x_lines = VIC656X_LINES;
117   vic656x_vretracerate = VIC656X_VRETRACERATE;
118}
119
120void vic6560_init (int (*dma_read) (running_machine *machine, int), int (*dma_read_color) (running_machine *machine, int))
121{
122   vic6560_pal = FALSE;
123   vic_dma_read = dma_read;
124   vic_dma_read_color = dma_read_color;
125   vic656x_init ();
126}
127
128void vic6561_init (int (*dma_read) (running_machine *machine, int), int (*dma_read_color) (running_machine *machine, int))
129{
130   vic6560_pal = TRUE;
131   vic_dma_read = dma_read;
132   vic_dma_read_color = dma_read_color;
133   vic656x_init ();
134}
135
136
137static VIDEO_START( vic6560 )
138{
139   running_device *screen = video_screen_first(machine);
140   int width = video_screen_get_width(screen);
141   int height = video_screen_get_height(screen);
142
143   vic6560_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
144}
145
146WRITE8_HANDLER ( vic6560_port_w )
147{
148   running_machine *machine = space->machine;
149   DBG_LOG (1, "vic6560_port_w", ("%.4x:%.2x\n", offset, data));
150   switch (offset)
151   {
152   case 0xa:
153   case 0xb:
154   case 0xc:
155   case 0xd:
156   case 0xe:
157      vic6560_soundport_w (space->machine, offset, data);
158      break;
159   }
160   if (vic6560[offset] != data)
161   {
162      switch (offset)
163      {
164      case 0:
165      case 1:
166      case 2:
167      case 3:
168      case 5:
169      case 0xe:
170      case 0xf:
171         vic6560_drawlines (space->machine, lastline, rasterline);
172         break;
173      }
174      vic6560[offset] = data;
175      switch (offset)
176      {
177      case 0:
178         xpos = XPOS;
179         break;
180      case 1:
181         ypos = YPOS;
182         break;
183      case 2:
184         /* ntsc values >= 31 behave like 31 */
185         /* pal value >= 32 behave like 32 */
186         chars_x = CHARS_X;
187         videoaddr = VIDEOADDR;
188         xsize = XSIZE;
189         break;
190      case 3:
191         matrix8x16 = MATRIX8X16;
192         charheight = CHARHEIGHT;
193         chars_y = CHARS_Y;
194         ysize = YSIZE;
195         break;
196      case 5:
197         chargenaddr = CHARGENADDR;
198         videoaddr = VIDEOADDR;
199         break;
200      case 0xe:
201         multi[3] = multiinverted[3] = helpercolor = HELPERCOLOR;
202         break;
203      case 0xf:
204         inverted = INVERTED;
205         multi[1] = multiinverted[1] = framecolor = FRAMECOLOR;
206         mono[0] = monoinverted[1] =
207            multi[0] = multiinverted[2] = backgroundcolor = BACKGROUNDCOLOR;
208         break;
209      }
210   }
211}
212
213READ8_HANDLER ( vic6560_port_r )
214{
215   running_machine *machine = space->machine;
216   static double lightpenreadtime = 0.0;
217   int val;
218
219   switch (offset)
220   {
221   case 3:
222      val = ((rasterline & 1) << 7) | (vic6560[offset] & 0x7f);
223      break;
224   case 4:                     /*rasterline */
225      vic6560_drawlines (space->machine, lastline, rasterline);
226      val = (rasterline / 2) & 0xff;
227      break;
228   case 6:                     /*lightpen horizontal */
229   case 7:                     /*lightpen vertical */
230      if (LIGHTPEN_BUTTON
231         && ((attotime_to_double(timer_get_time(space->machine)) - lightpenreadtime) * VIC6560_VRETRACERATE >= 1))
232      {
233         /* only 1 update each frame */
234         /* and diode must recognize light */
235         if (1)
236         {
237            vic6560[6] = VIC6560_X_VALUE;
238            vic6560[7] = VIC6560_Y_VALUE;
239         }
240         lightpenreadtime = attotime_to_double(timer_get_time(space->machine));
241      }
242      val = vic6560[offset];
243      break;
244   case 8:                     /* poti 1 */
245      val = input_port_read(space->machine, "PADDLE0");
246      break;
247   case 9:                     /* poti 2 */
248      val = input_port_read(space->machine, "PADDLE1");
249      break;
250   default:
251      val = vic6560[offset];
252      break;
253   }
254   DBG_LOG (3, "vic6560_port_r", ("%.4x:%.2x\n", offset, val));
255   return val;
256}
257
258static void vic6560_draw_character (running_machine *machine, int ybegin, int yend,
259                           int ch, int yoff, int xoff,
260                           UINT16 *color)
261{
262   int y, code;
263
264   for (y = ybegin; y <= yend; y++)
265   {
266      code = vic_dma_read (machine, (chargenaddr + ch * charheight + y) & 0x3fff);
267      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 0) = color[code >> 7];
268      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 1) = color[(code >> 6) & 1];
269      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 2) = color[(code >> 5) & 1];
270      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 3) = color[(code >> 4) & 1];
271      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 4) = color[(code >> 3) & 1];
272      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 5) = color[(code >> 2) & 1];
273      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 6) = color[(code >> 1) & 1];
274      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 7) = color[code & 1];
275   }
276}
277
278static void vic6560_draw_character_multi (running_machine *machine, int ybegin, int yend,
279                                int ch, int yoff, int xoff, UINT16 *color)
280{
281   int y, code;
282
283   for (y = ybegin; y <= yend; y++)
284   {
285      code = vic_dma_read (machine, (chargenaddr + ch * charheight + y) & 0x3fff);
286      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 0) =
287         *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 1) = color[code >> 6];
288      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 2) =
289         *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 3) = color[(code >> 4) & 3];
290      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 4) =
291         *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 5) = color[(code >> 2) & 3];
292      *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 6) =
293         *BITMAP_ADDR16(vic6560_bitmap, y + yoff, xoff + 7) = color[code & 3];
294   }
295}
296
297
298static void vic6560_drawlines (running_machine *machine, int first, int last)
299{
300   int line, vline;
301   int offs, yoff, xoff, ybegin, yend, i;
302   int attr, ch;
303
304   lastline = last;
305   if (first >= last)
306      return;
307
308   for (line = first; (line < ypos) && (line < last); line++)
309   {
310      memset16 (BITMAP_ADDR16(vic6560_bitmap, line, 0), framecolor, vic656x_xsize);
311   }
312
313   for (vline = line - ypos; (line < last) && (line < ypos + ysize);)
314   {
315      if (matrix8x16)
316      {
317         offs = (vline >> 4) * chars_x;
318         yoff = (vline & ~0xf) + ypos;
319         ybegin = vline & 0xf;
320         yend = (vline + 0xf < last - ypos) ? 0xf : ((last - line) & 0xf) + ybegin;
321      }
322      else
323      {
324         offs = (vline >> 3) * chars_x;
325         yoff = (vline & ~7) + ypos;
326         ybegin = vline & 7;
327         yend = (vline + 7 < last - ypos) ? 7 : ((last - line) & 7) + ybegin;
328      }
329
330      if (xpos > 0)
331      {
332         for (i = ybegin; i <= yend; i++)
333            memset16 (BITMAP_ADDR16(vic6560_bitmap, yoff + i, 0), framecolor, xpos);
334      }
335      for (xoff = xpos; (xoff < xpos + xsize) && (xoff < vic656x_xsize); xoff += 8, offs++)
336      {
337         ch = vic_dma_read (machine, (videoaddr + offs) & 0x3fff);
338         attr = (vic_dma_read_color (machine, (videoaddr + offs) & 0x3fff)) & 0xf;
339         if (inverted)
340         {
341            if (attr & 8)
342            {
343               multiinverted[0] = attr & 7;
344               vic6560_draw_character_multi (machine, ybegin, yend, ch, yoff, xoff,
345                                      multiinverted);
346            }
347            else
348            {
349               monoinverted[0] = attr;
350               vic6560_draw_character (machine, ybegin, yend, ch, yoff, xoff, monoinverted);
351            }
352         }
353         else
354         {
355            if (attr & 8)
356            {
357               multi[2] = attr & 7;
358               vic6560_draw_character_multi (machine, ybegin, yend, ch, yoff, xoff, multi);
359            }
360            else
361            {
362               mono[1] = attr;
363               vic6560_draw_character (machine, ybegin, yend, ch, yoff, xoff, mono);
364            }
365         }
366      }
367      if (xoff < vic656x_xsize)
368      {
369         for (i = ybegin; i <= yend; i++)
370         {
371            memset16 (BITMAP_ADDR16(vic6560_bitmap, yoff + i, xoff),
372               framecolor, vic656x_xsize - xoff);
373         }
374      }
375      if (matrix8x16)
376      {
377         vline = (vline + 16) & ~0xf;
378         line = vline + ypos;
379      }
380      else
381      {
382         vline = (vline + 8) & ~7;
383         line = vline + ypos;
384      }
385   }
386
387   for (; line < last; line++)
388   {
389      memset16 (BITMAP_ADDR16(vic6560_bitmap, line, 0), framecolor, vic656x_xsize);
390   }
391}
392
393INTERRUPT_GEN( vic656x_raster_interrupt )
394{
395   rasterline++;
396   if (rasterline >= vic656x_lines)
397   {
398      rasterline = 0;
399      vic6560_drawlines (device->machine, lastline, vic656x_lines);
400      lastline = 0;
401   }
402}
403
404static VIDEO_UPDATE( vic6560 )
405{
406   copybitmap(bitmap, vic6560_bitmap, 0, 0, 0, 0, cliprect);
407   return 0;
408}
409
410static PALETTE_INIT( vic6560 )
411{
412   int i;
413
414   for ( i = 0; i < sizeof(vic6560_palette) / 3; i++ ) {
415      palette_set_color_rgb(machine, i, vic6560_palette[i*3], vic6560_palette[i*3+1], vic6560_palette[i*3+2]);
416   }
417}
418
419MACHINE_DRIVER_START( vic6560_video )
420    /* video hardware */
421   MDRV_SCREEN_ADD("screen", RASTER)
422   MDRV_SCREEN_REFRESH_RATE(VIC6560_VRETRACERATE)
423   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
424   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
425   MDRV_SCREEN_SIZE((VIC6560_XSIZE + 7) & ~7, VIC6560_YSIZE)
426   MDRV_SCREEN_VISIBLE_AREA(VIC6560_MAME_XPOS, VIC6560_MAME_XPOS + VIC6560_MAME_XSIZE - 1, VIC6560_MAME_YPOS, VIC6560_MAME_YPOS + VIC6560_MAME_YSIZE - 1)
427
428   MDRV_PALETTE_LENGTH(16)
429   MDRV_PALETTE_INIT(vic6560)
430
431   MDRV_VIDEO_START(vic6560)
432   MDRV_VIDEO_UPDATE(vic6560)
433
434   /* sound hardware */
435   MDRV_SPEAKER_STANDARD_MONO("mono")
436   MDRV_SOUND_ADD("custom", VIC6560, 0)
437   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
438   MDRV_SOUND_ADD("dac", DAC, 0)
439   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
440MACHINE_DRIVER_END
441
442MACHINE_DRIVER_START( vic6561_video )
443    /* video hardware */
444   MDRV_SCREEN_ADD("screen", RASTER)
445   MDRV_SCREEN_REFRESH_RATE(VIC6561_VRETRACERATE)
446   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
447   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
448   MDRV_SCREEN_SIZE((VIC6561_XSIZE + 7) & ~7, VIC6561_YSIZE)
449   MDRV_SCREEN_VISIBLE_AREA(VIC6561_MAME_XPOS, VIC6561_MAME_XPOS + VIC6561_MAME_XSIZE - 1, VIC6561_MAME_YPOS, VIC6561_MAME_YPOS + VIC6561_MAME_YSIZE - 1)
450
451   MDRV_PALETTE_LENGTH(16)
452   MDRV_PALETTE_INIT(vic6560)
453
454   MDRV_VIDEO_START(vic6560)
455   MDRV_VIDEO_UPDATE(vic6560)
456
457   /* sound hardware */
458   MDRV_SPEAKER_STANDARD_MONO("mono")
459   MDRV_SOUND_ADD("custom", VIC6560, 0)
460   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
461   MDRV_SOUND_ADD("dac", DAC, 0)
462   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
463MACHINE_DRIVER_END
src/mess/video/vic6560.h
r7372r7373
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/* to be inserted in MachineDriver-Structure */
56#define VIC6560_VRETRACERATE 60
57#define VIC6561_VRETRACERATE 50
58#define VIC656X_VRETRACERATE (vic6560_pal?VIC6561_VRETRACERATE:VIC6560_VRETRACERATE)
59#define VIC656X_HRETRACERATE 15625
60
61#define VIC6560_MAME_XPOS  4         /* xleft not displayed */
62#define VIC6560_MAME_YPOS  10         /* y up not displayed */
63#define VIC6561_MAME_XPOS  20
64#define VIC6561_MAME_YPOS  10
65#define VIC656X_MAME_XPOS   (vic6560_pal?VIC6561_MAME_XPOS:VIC6560_MAME_XPOS)
66#define VIC656X_MAME_YPOS   (vic6560_pal?VIC6561_MAME_YPOS:VIC6560_MAME_YPOS)
67#define VIC6560_MAME_XSIZE   200
68#define VIC6560_MAME_YSIZE   248
69#define VIC6561_MAME_XSIZE   224
70#define VIC6561_MAME_YSIZE   296
71#define VIC656X_MAME_XSIZE   (vic6560_pal?VIC6561_MAME_XSIZE:VIC6560_MAME_XSIZE)
72#define VIC656X_MAME_YSIZE   (vic6560_pal?VIC6561_MAME_YSIZE:VIC6560_MAME_YSIZE)
73/* real values */
74#define VIC6560_LINES 261
75#define VIC6561_LINES 312
76#define VIC656X_LINES (vic6560_pal?VIC6561_LINES:VIC6560_LINES)
77/*#define VREFRESHINLINES 9 */
78#define VIC6560_XSIZE   (4+201)         /* 4 left not visible */
79#define VIC6560_YSIZE   (10+251)      /* 10 not visible */
80/* cycles 65 */
81#define VIC6561_XSIZE   (20+229)      /* 20 left not visible */
82#define VIC6561_YSIZE   (10+302)      /* 10 not visible */
83/* cycles 71 */
84#define VIC656X_XSIZE (vic6560_pal?VIC6561_XSIZE:VIC6560_XSIZE)
85#define VIC656X_YSIZE (vic6560_pal?VIC6561_YSIZE:VIC6560_YSIZE)
86
87/* the following values depend on the VIC clock,
88 * but to achieve TV-frequency the clock must have a fix frequency */
89#define VIC6560_CLOCK   (14318181/14)
90#define VIC6561_CLOCK   (4433618/4)
91#define VIC656X_CLOCK   (vic6560_pal?VIC6561_CLOCK:VIC6560_CLOCK)
92
93
94/*----------- defined in video/vic6560.c -----------*/
95
96/* call to init videodriver */
97/* pal version */
98/* dma_read: videochip fetched 12 bit data from system bus */
99void vic6560_init (int (*dma_read) (running_machine *machine, int), int (*dma_read_color) (running_machine *machine, int));
100void vic6561_init (int (*dma_read) (running_machine *machine, int), int (*dma_read_color) (running_machine *machine, int));
101
102/* internal */
103extern int vic6560_pal;
104extern UINT8 vic6560[16];
105
106extern INTERRUPT_GEN( vic656x_raster_interrupt );
107/* to be called when writting to port */
108WRITE8_HANDLER ( vic6560_port_w );
109
110/* to be called when reading from port */
111READ8_HANDLER ( vic6560_port_r );
112
113MACHINE_DRIVER_EXTERN( vic6560_video );
114MACHINE_DRIVER_EXTERN( vic6561_video );
115
116/*----------- defined in audio/vic6560.c -----------*/
117
118#define SOUND_VIC6560      DEVICE_GET_INFO_NAME( vic6560_sound )
119DEVICE_GET_INFO( vic6560_sound );
120void vic6560_soundport_w (running_machine *machine, int mode, int data);
121
122
123#endif /* __VIC6560_H__ */
src/mess/includes/vic20.h
r7372r7373
2525   running_device *via1;
2626   running_device *iec;
2727   running_device *cassette;
28   running_device *vic6560;
2829 
2930   /* timers */
3031   running_device *cassette_timer;
src/mess/machine/cbmipt.c
r7372r7373
939939 *  - vic_keyboard: basic Vic 20 keyboard
940940 *  - vic_special: input port for the Shift Lock Switch
941941 *  - vic_controls: joypads and paddles
942 *  - vic_expansion: RAM expansions
943942 *  - VIC20 also has 2 lightpen ports, vic_lightpen_6560 & vic_lightpen_6561
944 *          currently in vc20.c (they need visible area parameters for centering)
943 *          currently in vic20.c (they need visible area parameters for centering)
945944 *
946945 **********************************************************************************/
947946
r7372r7373
11081107   PORT_START( "PADDLE1" )
11091108   PORT_BIT( 0xff,128,IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0,255) PORT_CATEGORY(11) PORT_CODE_DEC(KEYCODE_END) PORT_CODE_INC(KEYCODE_PGDN) PORT_PLAYER(2) PORT_REVERSE
11101109INPUT_PORTS_END
1111
1112
1113INPUT_PORTS_START( vic_expansion )
1114   PORT_START( "EXP" )
1115   PORT_DIPNAME( 0x07, 0x00, "RAM Cartridge")
1116   PORT_DIPSETTING(   0x00, DEF_STR( None ) )
1117   PORT_DIPSETTING(   0x01, "3k" )
1118   PORT_DIPSETTING(   0x02, "8k" )
1119   PORT_DIPSETTING(   0x03, "16k" )
1120   PORT_DIPSETTING(   0x04, "32k" )
1121   PORT_DIPSETTING(   0x05, "Custom" )
1122   PORT_DIPNAME( 0x08, 0x00, "RAM at 0x0400")
1123   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
1124   PORT_DIPSETTING(   0x08, DEF_STR( Yes ) )
1125   PORT_DIPNAME( 0x10, 0x00, "RAM at 0x2000")
1126   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
1127   PORT_DIPSETTING(   0x10, DEF_STR( Yes ) )
1128   PORT_DIPNAME( 0x20, 0x00, "RAM at 0x4000")
1129   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
1130   PORT_DIPSETTING(   0x20, DEF_STR( Yes ) )
1131   PORT_DIPNAME( 0x40, 0x00, "RAM at 0x6000")
1132   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
1133   PORT_DIPSETTING(   0x40, DEF_STR( Yes ) )
1134   PORT_DIPNAME( 0x80, 0x00, "RAM at 0xa000")
1135   PORT_DIPSETTING(   0x00, DEF_STR( No ) )
1136   PORT_DIPSETTING(   0x80, DEF_STR( Yes ) )
1137INPUT_PORTS_END
src/mess/machine/cbmipt.h
r7372r7373
4545INPUT_PORTS_EXTERN( vic_keyboard );
4646INPUT_PORTS_EXTERN( vic_special );
4747INPUT_PORTS_EXTERN( vic_controls );
48INPUT_PORTS_EXTERN( vic_expansion );
4948
5049
5150#endif /* CBMIPT_H_ */
src/mess/mess.mak
r7372r7373
698698   $(MESS_DRIVERS)/pet.o      \
699699   $(MESS_MACHINE)/pet.o      \
700700   $(MESS_DRIVERS)/c64.o      \
701   $(MESS_AUDIO)/vic6560.o      \
701702   $(MESS_DRIVERS)/vic20.o      \
702703   $(MESS_MACHINE)/vic1112.o   \
703704   $(MESS_AUDIO)/ted7360.o      \
r7372r7373
710711   $(MESS_VIDEO)/cbmb.o      \
711712   $(MESS_DRIVERS)/c65.o      \
712713   $(MESS_DRIVERS)/c128.o      \
713   $(MESS_AUDIO)/vic6560.o      \
714714   $(MESS_VIDEO)/ted7360.o      \
715   $(MESS_VIDEO)/vic6560.o      \
716715   $(MESS_MACHINE)/cbmiec.o   \
717716   $(MESS_MACHINE)/c1541.o      \
718717   $(MESS_MACHINE)/c1551.o      \
src/mess/drivers/vic20.c
r7372r7373
11/*
22 
3[CBM systems which belong to this driver (info to be moved to sysinfo.dat soon)]
4(most of the informations are taken from http://www.zimmers.net/cbmpics/ )
5 
6 
7* VIC-1001 (1981, Japan)
8 
9  The first model released was the Japanese one. It featured support for the
10Japanese katakana character.
11 
12CPU: MOS Technology 6502 (1.01 MHz)
13RAM: 5 kilobytes (Expanded to 21k though an external 16k unit)
14ROM: 20 kilobytes
15Video: MOS Technology 6560 "VIC"(Text: 22 columns, 23 rows; Hires: 176x184
16pixels bitmapped; 8 text colors, 16 background colors)
17Sound: MOS Technology 6560 "VIC" (3 voices -square wave-, noise and volume)
18Ports: 6522 VIA x2 (1 Joystick/Mouse port; CBM Serial port; 'Cartridge /
19    Game / Expansion' port; CBM Monitor port; CBM 'USER' port; Power and
20    reset switches; Power connector)
21Keyboard: Full-sized QWERTY 66 key (8 programmable function keys; 2 sets of
22    Keyboardable graphic characters; 2 key direction cursor-pad)
23 
24 
25* VIC 20 (1981)
26 
27  This system was the first computer to sell more than one million units
28worldwide. It was sold both in Europe and in the US. In Germany the
29computer was renamed as VC 20 (apparently, it stands for 'VolksComputer'
30 
31CPU: MOS Technology 6502A (1.01 MHz)
32RAM: 5 kilobytes (Expanded to 32k)
33ROM: 20 kilobytes
34Video: MOS Technology 6560 "VIC"(Text: 22 columns, 23 rows; Hires: 176x184
35pixels bitmapped; 8 text colors, 16 background colors)
36Sound: MOS Technology 6560 "VIC" (3 voices -square wave-, noise and volume)
37Ports: 6522 VIA x2 (1 Joystick/Mouse port; CBM Serial port; 'Cartridge /
38    Game / Expansion' port; CBM Monitor port; CBM 'USER' port; Power and
39    reset switches; Power connector)
40Keyboard: Full-sized QWERTY 66 key (8 programmable function keys; 2 sets of
41    Keyboardable graphic characters; 2 key direction cursor-pad)
42 
43 
44* VIC 21 (1983)
45 
46  It consists of a VIC 20 with built-in RAM expansion, to reach a RAM
47  capability of 21 kilobytes.
48 
49 
50* VIC 20CR
51 
52  CR stands for Cost Reduced, as it consisted of a board with only 2 (larger)
53block of RAM instead of 8.
54 
55*******************************************************************************
56 
357    TODO:
458 
559    - C1540 is unreliable (VIA timing issues?)
r7372r7373
2983#include "machine/cbmiec.h"
3084#include "machine/ieee488.h"
3185#include "machine/vic1112.h"
32#include "video/vic6560.h"
86#include "machine/cbmipt.h"
87#include "audio/vic6560.h"
88#include "sound/dac.h"
3389 
3490/* Memory Maps */
3591 
r7372r7373
4399//  AM_RANGE(0x4000, 0x5fff) BLK2
44100//  AM_RANGE(0x6000, 0x7fff) BLK3
45101   AM_RANGE(0x8000, 0x8fff) AM_ROM
46   AM_RANGE(0x9000, 0x900f) AM_READWRITE(vic6560_port_r, vic6560_port_w)
102   AM_RANGE(0x9000, 0x900f) AM_DEVREADWRITE(M6560_TAG, vic6560_port_r, vic6560_port_w)
47103   AM_RANGE(0x9110, 0x911f) AM_DEVREADWRITE(M6522_0_TAG, via_r, via_w)
48104   AM_RANGE(0x9120, 0x912f) AM_DEVREADWRITE(M6522_1_TAG, via_r, via_w)
49105   AM_RANGE(0x9400, 0x97ff) AM_RAM
r7372r7373
55111 
56112/* Input Ports */
57113 
58static CUSTOM_INPUT( vic_custom_inputs )
59{
60   int bit_mask = (FPTR)param;
61   UINT8 port = 0;
114#ifdef UNUSED_FUNCTION
115static INPUT_PORTS_START( vic_lightpen_6560 )
116   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)
62118 
63   if ((input_port_read(field->port->machine, "CTRLSEL") & 0xf0) == 0x10)
64      port |= (input_port_read(field->port->machine, "FAKE0") & bit_mask) ? 1 : 0;
119   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)
121INPUT_PORTS_END
65122 
66   if ((input_port_read(field->port->machine, "CTRLSEL") & 0xf0) == 0x00)
67      port |= (input_port_read(field->port->machine, "FAKE1") & bit_mask) ? 1 : 0;
68123 
69   return port;
70}
124static INPUT_PORTS_START( vic_lightpen_6561 )
125   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)
71127 
128   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)
130INPUT_PORTS_END
131#endif
132 
72133static INPUT_PORTS_START( vic20 )
73   PORT_START("ROW0")
74   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Del Inst") PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8) PORT_CHAR(UCHAR_MAMEKEY(INSERT))
75   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR('\xA3')
76   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('+')
77   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')')
78   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
79   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
80   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
81   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
134   PORT_INCLUDE( vic_keyboard )       /* ROW0 -> ROW7 */
82135 
83   PORT_START("ROW1")
84   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Return") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
85   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE) PORT_CHAR('*')
86   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_P) PORT_CHAR('P')
87   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_I) PORT_CHAR('I')
88   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Y) PORT_CHAR('Y')
89   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_R) PORT_CHAR('R')
90   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_W) PORT_CHAR('W')
91   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x90") PORT_CODE(KEYCODE_TILDE) PORT_CHAR(0x2190)
136   PORT_INCLUDE( vic_special )        /* SPECIAL */
92137 
93   PORT_START("ROW2")
94   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Right Left") PORT_CODE(KEYCODE_RCONTROL) PORT_CHAR(UCHAR_MAMEKEY(RIGHT)) PORT_CHAR(UCHAR_MAMEKEY(LEFT))
95   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(';') PORT_CHAR(']')
96   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_L) PORT_CHAR('L')
97   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_J) PORT_CHAR('J')
98   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_G) PORT_CHAR('G')
99   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_D) PORT_CHAR('D')
100   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_A) PORT_CHAR('A')
101   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_TAB) PORT_CHAR(UCHAR_SHIFT_2)
138   PORT_INCLUDE( vic_controls )       /* CTRLSEL, JOY, FAKE0, FAKE1, PADDLE0, PADDLE1 */
139INPUT_PORTS_END
102140 
103   PORT_START("ROW3")
104   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Crsr Down Up") PORT_CODE(KEYCODE_RALT) PORT_CHAR(UCHAR_MAMEKEY(DOWN)) PORT_CHAR(UCHAR_MAMEKEY(UP))
105   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
106   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')
107   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_N) PORT_CHAR('N')
108   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_V) PORT_CHAR('V')
109   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_X) PORT_CHAR('X')
110   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Left)") PORT_CODE(KEYCODE_LSHIFT)
111   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Stop Run") PORT_CODE(KEYCODE_HOME)
112141 
113   PORT_START("ROW4")
114   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1)) PORT_CHAR(UCHAR_MAMEKEY(F2))
115   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
116   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>')
117   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_M) PORT_CHAR('M')
118   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_B) PORT_CHAR('B')
119   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_C) PORT_CHAR('C')
120   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Z) PORT_CHAR('Z')
121   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
142static INPUT_PORTS_START( vic1001 )
143   PORT_INCLUDE( vic20 )
122144 
123   PORT_START("ROW5")
124   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F3)) PORT_CHAR(UCHAR_MAMEKEY(F4))
125   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH) PORT_CHAR('=')
126   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COLON) PORT_CHAR(':') PORT_CHAR('[')
127   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_K) PORT_CHAR('K')
128   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_H) PORT_CHAR('H')
129   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F) PORT_CHAR('F')
130   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_S) PORT_CHAR('S')
131   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("CBM") PORT_CODE(KEYCODE_LCONTROL)
145   PORT_MODIFY( "ROW0" )
146   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('\xA5')
147INPUT_PORTS_END
132148 
133   PORT_START("ROW6")
134   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F5)) PORT_CHAR(UCHAR_MAMEKEY(F6))
135   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("\xE2\x86\x91  Pi") PORT_CODE(KEYCODE_DEL) PORT_CHAR(0x2191) PORT_CHAR(0x03C0)
136   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE)  PORT_CHAR('@')
137   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_O) PORT_CHAR('O')
138   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_U) PORT_CHAR('U')
139   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_T) PORT_CHAR('T')
140   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_E) PORT_CHAR('E')
141   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_Q) PORT_CHAR('Q')
142149 
143   PORT_START("ROW7")
144   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F7)) PORT_CHAR(UCHAR_MAMEKEY(F8))
145   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("Home  Clr") PORT_CODE(KEYCODE_INSERT) PORT_CHAR(UCHAR_MAMEKEY(HOME))
146   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS) PORT_CHAR('-')
147   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_0) PORT_CHAR('0')
148   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(')
149   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
150   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
151   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('"')
152 
153   PORT_START( "SPECIAL" )  /* special keys */
154   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("Restore") PORT_CODE(KEYCODE_PRTSCR) PORT_WRITE_LINE_DEVICE(M6522_0_TAG, via_ca1_w)
155   PORT_DIPNAME( 0x01, 0x00, "Shift Lock (switch)") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE
156   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
157   PORT_DIPSETTING(   0x01, DEF_STR( On ) )
158 
159   PORT_START( "CTRLSEL" )
160   PORT_CATEGORY_CLASS( 0xf0, 0x00, DEF_STR( Controller ) )
161   PORT_CATEGORY_ITEM( 0x00, DEF_STR( Joystick ), 10 )
162   PORT_CATEGORY_ITEM( 0x10, "Paddles", 11 )
163   PORT_CATEGORY_ITEM( 0x20, "Lightpen", 12 )
164 
165   PORT_START( "JOY" )
166   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(vic_custom_inputs, (void *)0x02)
167   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Lightpen Signal") PORT_CODE(KEYCODE_LALT) PORT_CATEGORY(12)
168   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(vic_custom_inputs, (void *)0x01)
169   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_CATEGORY(10)
170   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_CATEGORY(10)
171   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_CATEGORY(10)
172 
173   PORT_START( "FAKE0" )
174   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Paddle 2 Button") PORT_CODE(KEYCODE_DEL) PORT_CATEGORY(11)
175   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Paddle 1 Button") PORT_CODE(KEYCODE_INSERT) PORT_CATEGORY(11)
176 
177   PORT_START( "FAKE1" )
178   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_CATEGORY(10)
179   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_CATEGORY(10)
180 
181   PORT_START( "PADDLE0" )
182   PORT_BIT( 0xff,128,IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0,255) PORT_CATEGORY(11) PORT_CODE_DEC(KEYCODE_HOME) PORT_CODE_INC(KEYCODE_PGUP) PORT_REVERSE
183 
184   PORT_START( "PADDLE1" )
185   PORT_BIT( 0xff,128,IPT_PADDLE) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0,255) PORT_CATEGORY(11) PORT_CODE_DEC(KEYCODE_END) PORT_CODE_INC(KEYCODE_PGDN) PORT_PLAYER(2) PORT_REVERSE
186INPUT_PORTS_END
187 
188150static INPUT_PORTS_START( vic20s )
189151   PORT_INCLUDE( vic20 )
190152 
191153   PORT_MODIFY( "ROW0" )
192   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR(':') PORT_CHAR('*')
193   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-')
194 
154   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH2)      PORT_CHAR(':') PORT_CHAR('*')
155   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-')
195156   PORT_MODIFY( "ROW1" )
196   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE) PORT_CHAR('@')
197 
157   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CLOSEBRACE)      PORT_CHAR('@')
198158   PORT_MODIFY( "ROW2" )
199   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(0x00C4)
200 
159   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR(0x00C4)
201160   PORT_MODIFY( "ROW5" )
202   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH) PORT_CHAR(';') PORT_CHAR('+')
203   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COLON) PORT_CHAR(0x00D6)
204 
161   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_BACKSLASH)      PORT_CHAR(';') PORT_CHAR('+')
162   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_COLON)         PORT_CHAR(0x00D6)
205163   PORT_MODIFY( "ROW6" )
206   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR(0x00C5)
207 
164   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR(0x00C5)
208165   PORT_MODIFY( "ROW7" )
209   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS) PORT_CHAR('=')
166   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_CODE(KEYCODE_EQUALS)         PORT_CHAR('=')
210167INPUT_PORTS_END
211168 
212169/* VIA 0 Interface */
r7372r7373
511468   return memory_read_byte(program, VIC6560ADDR2VC20ADDR(offset));
512469}
513470 
471static UINT8 vic20_lightx_cb( running_machine *machine )
472{
473   return (input_port_read_safe(machine, "LIGHTX", 0) & ~0x01);
474}
475 
476static UINT8 vic20_lighty_cb( running_machine *machine )
477{
478   return (input_port_read_safe(machine, "LIGHTY", 0) & ~0x01);
479}
480 
481static UINT8 vic20_lightbut_cb( running_machine *machine )
482{
483   return (((input_port_read(machine, "CTRLSEL") & 0xf0) == 0x20) && (input_port_read(machine, "JOY") & 0x40));
484}
485 
486static UINT8 vic20_paddle0_cb( running_machine *machine )
487{
488   return input_port_read(machine, "PADDLE0");
489}
490 
491static UINT8 vic20_paddle1_cb( running_machine *machine )
492{
493   return input_port_read(machine, "PADDLE1");
494}
495 
496static const vic656x_interface vic20_6560_intf =
497{
498   "screen",   /* screen */
499   VIC6560,
500   vic20_lightx_cb, vic20_lighty_cb, vic20_lightbut_cb,   /* lightgun cb */
501   vic20_paddle0_cb, vic20_paddle1_cb,      /* paddle cb */
502   vic6560_dma_read, vic6560_dma_read_color   /* DMA */
503};
504 
505static const vic656x_interface vic20_6561_intf =
506{
507   "screen",   /* screen */
508   VIC6561,
509   vic20_lightx_cb, vic20_lighty_cb, vic20_lightbut_cb,   /* lightgun cb */
510   vic20_paddle0_cb, vic20_paddle1_cb,      /* paddle cb */
511   vic6560_dma_read, vic6560_dma_read_color   /* DMA */
512};
513 
514 
514515/* Machine Initialization */
515516 
516static MACHINE_START( vic20_common )
517static MACHINE_START( vic20 )
517518{
518519   vic20_state *state = (vic20_state *)machine->driver_data;
519520   const address_space *program = cputag_get_address_space(machine, M6502_TAG, ADDRESS_SPACE_PROGRAM);
r7372r7373
524525   state->iec = devtag_get_device(machine, IEC_TAG);
525526   state->cassette = devtag_get_device(machine, CASSETTE_TAG);
526527   state->cassette_timer = devtag_get_device(machine, TIMER_C1530_TAG);
528   state->vic6560 = devtag_get_device(machine, M6560_TAG);
527529 
528530   /* set VIA clocks */
529531   state->via0->set_clock(cputag_get_clock(machine, M6502_TAG));
r7372r7373
549551   state_save_register_global(machine, state->key_col);
550552}
551553 
552static MACHINE_START( vic20_ntsc )
553{
554   MACHINE_START_CALL(vic20_common);
555554 
556   /* initialize VIC6560 */
557   vic6560_init(vic6560_dma_read, vic6560_dma_read_color);
558}
559 
560static MACHINE_START( vic20_pal )
561{
562   MACHINE_START_CALL(vic20_common);
563 
564   /* initialize VIC6561 */
565   vic6561_init(vic6560_dma_read, vic6560_dma_read_color);
566}
567 
568555/* Cartridge */
569556 
570557static DEVICE_IMAGE_LOAD( vic20_cart )
r7372r7373
608595   return INIT_PASS;
609596}
610597 
598/* Graphics Definitions and Video Emulation */
599 
600static const unsigned char vic6560_palette[] =
601{
602/* ripped from vice, a very excellent emulator */
603/* black, white, red, cyan */
604   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0xf0,
605/* purple, green, blue, yellow */
606   0x60, 0x00, 0x60, 0x00, 0xa0, 0x00, 0x00, 0x00, 0xf0, 0xd0, 0xd0, 0x00,
607/* orange, light orange, pink, light cyan, */
608   0xc0, 0xa0, 0x00, 0xff, 0xa0, 0x00, 0xf0, 0x80, 0x80, 0x00, 0xff, 0xff,
609/* light violett, light green, light blue, light yellow */
610   0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xa0, 0xff, 0xff, 0xff, 0x00
611};
612 
613static PALETTE_INIT( vic20 )
614{
615   int i;
616 
617   for (i = 0; i < sizeof(vic6560_palette) / 3; i++)
618   {
619      palette_set_color_rgb(machine, i, vic6560_palette[i * 3], vic6560_palette[i * 3 + 1], vic6560_palette[i * 3 + 2]);
620   }
621}
622 
623static VIDEO_UPDATE( vic20 )
624{
625   vic20_state *state = (vic20_state *)screen->machine->driver_data;
626   vic656x_video_update(state->vic6560, bitmap, cliprect);
627   return 0;
628}
629 
611630/* Machine Driver */
612631 
632INTERRUPT_GEN( vic20_raster_interrupt )
633{
634   vic20_state *state = (vic20_state *)device->machine->driver_data;
635   vic656x_raster_interrupt_gen(state->vic6560);
636}
637 
613638static MACHINE_DRIVER_START( vic20_common )
614639   MDRV_DRIVER_DATA(vic20_state)
615640 
r7372r7373
643668   MDRV_IMPORT_FROM( vic20_common )
644669 
645670   /* basic machine hardware */
646    MDRV_CPU_ADD(M6502_TAG, M6502, VIC6560_CLOCK)
647    MDRV_CPU_PROGRAM_MAP(vic20_mem)
648   MDRV_CPU_PERIODIC_INT(vic656x_raster_interrupt, VIC656X_HRETRACERATE)
671   MDRV_CPU_ADD(M6502_TAG, M6502, VIC6560_CLOCK)
672   MDRV_CPU_PROGRAM_MAP(vic20_mem)
673   MDRV_CPU_PERIODIC_INT(vic20_raster_interrupt, VIC656X_HRETRACERATE)
649674 
650    MDRV_MACHINE_START(vic20_ntsc)
675   MDRV_MACHINE_START(vic20)
651676 
652    /* video & sound hardware */
653   MDRV_IMPORT_FROM( vic6560_video )
677   /* video hardware */
678   MDRV_SCREEN_ADD("screen", RASTER)
679   MDRV_SCREEN_REFRESH_RATE(VIC6560_VRETRACERATE)
680   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
681   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)
684 
685   MDRV_PALETTE_LENGTH(16)
686   MDRV_PALETTE_INIT( vic20 )
687 
688   MDRV_VIDEO_UPDATE( vic20 )
689 
690   /* sound hardware */
691   MDRV_SPEAKER_STANDARD_MONO("mono")
692   MDRV_VIC656X_ADD(M6560_TAG, vic20_6560_intf)
693   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
694   MDRV_SOUND_ADD("dac", DAC, 0)
695   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
654696MACHINE_DRIVER_END
655697 
656698static MACHINE_DRIVER_START( vic20_pal )
657699   MDRV_IMPORT_FROM( vic20_common )
658700 
659701   /* basic machine hardware */
660    MDRV_CPU_ADD(M6502_TAG, M6502, VIC6561_CLOCK)
661    MDRV_CPU_PROGRAM_MAP(vic20_mem)
662   MDRV_CPU_PERIODIC_INT(vic656x_raster_interrupt, VIC656X_HRETRACERATE)
702   MDRV_CPU_ADD(M6502_TAG, M6502, VIC6561_CLOCK)
703   MDRV_CPU_PROGRAM_MAP(vic20_mem)
704   MDRV_CPU_PERIODIC_INT(vic20_raster_interrupt, VIC656X_HRETRACERATE)
663705 
664   MDRV_MACHINE_START(vic20_pal)
706   MDRV_MACHINE_START(vic20)
665707 
666    /* video & sound hardware */
667   MDRV_IMPORT_FROM( vic6561_video )
708   /* video hardware */
709   MDRV_SCREEN_ADD("screen", RASTER)
710   MDRV_SCREEN_REFRESH_RATE(VIC6561_VRETRACERATE)
711   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
712   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)
715 
716   MDRV_PALETTE_LENGTH(16)
717   MDRV_PALETTE_INIT( vic20 )
718 
719   MDRV_VIDEO_UPDATE( vic20 )
720 
721   /* sound hardware */
722   MDRV_SPEAKER_STANDARD_MONO("mono")
723   MDRV_VIC656X_ADD(M6560_TAG, vic20_6561_intf)
724   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
725   MDRV_SOUND_ADD("dac", DAC, 0)
726   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
668727MACHINE_DRIVER_END
669728 
670729/* ROMs */
r7372r7373
699758 
700759/* System Drivers */
701760 
702/*    YEAR  NAME        PARENT      COMPAT  MACHINE     INPUT   INIT    COMPANY                         FULLNAME                    FLAGS */
703COMP( 1980, vic1001,   0,         0,      vic20_ntsc,   vic20,   0,      "Commodore Business Machines",   "VIC-1001 (Japan)",         GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
704COMP( 1981, vic20,      vic1001,   0,      vic20_ntsc,   vic20,   0,      "Commodore Business Machines",   "VIC-20 (NTSC)",         GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
705COMP( 1981, vic20p,      vic1001,   0,      vic20_pal,   vic20,   0,      "Commodore Business Machines",   "VIC-20 / VC-20 (PAL)",      GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
706COMP( 1981, vic20s,      vic1001,   0,      vic20_pal,   vic20s,   0,      "Commodore Business Machines",   "VIC-20 (Sweden/Finland)",   GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
761/*    YEAR  NAME        PARENT      COMPAT  MACHINE     INPUT        INIT        COMPANY                             FULLNAME                    FLAGS */
762COMP( 1980, vic1001,    0,          0,      vic20_ntsc,  vic1001,    0,          "Commodore Business Machines",      "VIC-1001 (Japan)",         GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
763COMP( 1981, vic20,      vic1001,    0,      vic20_ntsc,  vic20,      0,          "Commodore Business Machines",      "VIC-20 (NTSC)",            GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
764COMP( 1981, vic20p,     vic1001,    0,      vic20_pal,   vic20,      0,          "Commodore Business Machines",      "VIC-20 / VC-20 (PAL)",     GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
765COMP( 1981, vic20s,     vic1001,    0,      vic20_pal,   vic20s,     0,          "Commodore Business Machines",      "VIC-20 (Sweden/Finland)",  GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team