Previous 15994 Revisions Next

r7365 Tuesday 16th February, 2010 at 01:38:31 UTC by Fabio Priuli
[CBM] wip:
- split vic4567 (VIC III) emulation from vic6567 (VIC II), and converted it to be a device
- removed old vic6567 (VIC II) code and converted the newer implementation to be a device
- added preliminary emulation of the c64dtv v2 (dump courtesy of The Guru), it lacks proper bankswitch at the moment
[docs]messnew.txt
[src/mess]mess.mak messdriv.c
[src/mess/drivers]c128.c c64.c c65.c cbmb.c
[src/mess/includes]c128.h c65.h cbmb.h
[src/mess/machine]c128.c c64.c c65.c cbmb.c
[src/mess/video]vic4567.c vic4567.h vic6567.c vic6567.h

src/mess/video/vic4567.c
r7364r7365
1// don't include this into the makefile
2// it is included in vic6567.c yet
1/***************************************************************************
32
3    Video Interface Chip (4567)
4
5    original emulation by PeT (mess@utanet.at)
6
7    2010-02: converted to be a device and split from vic II
8
9    TODO:
10      - plenty of cleanups
11      - emulate variants of the vic chip
12      - update vic III to use the new vic6567.c code for the vic II comaptibility
13
14***************************************************************************/
15
416#include "emu.h"
5#include "vic4567.h"
17#include "video/vic4567.h"
618
19#define SPRITE_BASE_X_SIZE      24
20#define SPRITE_BASE_Y_SIZE      21
21
22struct vic3_sprite
23{
24   int x, y;   
25
26   int repeat;                         /* expand, line once drawn */
27   int line;                           /* 0 not painting, else painting */
28
29   /* buffer for currently painted line */
30   int paintedline[8];
31   UINT8 bitmap[8][SPRITE_BASE_X_SIZE * 2 / 8 + 1  /*for simplier sprite collision detection*/];
32};
33
34typedef struct _vic3_state  vic3_state;
35struct _vic3_state
36{
37   vic3_type  type;
38
39   running_device *main_screen;         // screen which sets bitmap properties
40
41   running_device *cpu;
42
43   UINT8 reg[0x80];
44   int on;                        /* rastering of the screen */
45
46   int lines;
47
48   UINT16 chargenaddr, videoaddr, bitmapaddr;
49
50   bitmap_t *bitmap;
51   int x_begin, x_end;
52   int y_begin, y_end;
53
54   UINT16 c64_bitmap[2], bitmapmulti[4], mono[2], multi[4], ecmcolor[2], colors[4], spritemulti[4];
55
56   int lastline, rasterline;
57
58   int interlace;
59   int columns, rows;
60
61   /* background/foreground for sprite collision */
62   UINT8 *screen[216], shift[216];
63
64   /* convert multicolor byte to background/foreground for sprite collision */
65   UINT8 foreground[256];
66   UINT16 expandx[256];
67   UINT16 expandx_multi[256];
68
69   /* converts sprite multicolor info to info for background collision checking */
70   UINT8 multi_collision[256];
71
72   vic3_sprite sprites[8];
73
74   /* DMA */
75   vic3_dma_read          dma_read;
76   vic3_dma_read_color    dma_read_color;
77
78   /* IRQ */
79   vic3_irq               interrupt;
80
81   /* Port Changed */
82   vic3_port_changed_callback      port_changed;
83
84   /* lightpen */
85   vic3_lightpen_button_callback lightpen_button_cb;
86   vic3_lightpen_x_callback lightpen_x_cb;
87   vic3_lightpen_y_callback lightpen_y_cb;
88
89   /* C64 memory access */
90   vic3_c64mem_callback      c64_mem_r;
91
92   /* palette - vic3 specific items (the ones above are used for VIC II as well) */
93   UINT8 palette_red[0x100];
94   UINT8 palette_green[0x100];
95   UINT8 palette_blue[0x100];
96   int palette_dirty;
97};
98
99/*****************************************************************************
100    CONSTANTS
101*****************************************************************************/
102
7103#define VERBOSE_LEVEL 0
8104#define DBG_LOG(N,M,A) \
9105   do { \
10106      if(VERBOSE_LEVEL >= N) \
11107      { \
12108         if( M ) \
13            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(machine)), (char*) M ); \
109            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(device->machine)), (char*) M ); \
14110         logerror A; \
15111      } \
16112   } while (0)
17113
114#define VREFRESHINLINES         28
18115
19#define OPTIMIZE
116#define VIC2_YPOS            50
117#define RASTERLINE_2_C64(a)      (a)
118#define C64_2_RASTERLINE(a)      (a)
119#define XPOS            (VIC2_STARTVISIBLECOLUMNS + (VIC2_VISIBLECOLUMNS - VIC2_HSIZE) / 2)
120#define YPOS            (VIC2_STARTVISIBLELINES /* + (VIC2_VISIBLELINES - VIC2_VSIZE) / 2 */)
121#define FIRSTLINE            10 /* 36 ((VIC2_VISIBLELINES - VIC2_VSIZE)/2) */
122#define FIRSTCOLUMN         50
20123
21#define VIC3_BITPLANES_MASK (vic2.reg[0x32])
124/* 2008-05 FP: lightpen code needs to read input port from c64.c and cbmb.c */
125
126#define LIGHTPEN_BUTTON      (vic3->lightpen_button_cb(machine))
127#define LIGHTPEN_X_VALUE   (vic3->lightpen_x_cb(machine))
128#define LIGHTPEN_Y_VALUE   (vic3->lightpen_y_cb(machine))
129
130/* lightpen delivers values from internal counters; they do not start with the visual area or frame area */
131#define VIC2_MAME_XPOS         0
132#define VIC2_MAME_YPOS         0
133#define VIC6567_X_BEGIN         38
134#define VIC6567_Y_BEGIN         -6            /* first 6 lines after retrace not for lightpen! */
135#define VIC6569_X_BEGIN         38
136#define VIC6569_Y_BEGIN         -6
137#define VIC2_X_BEGIN         ((vic3->type == VIC4567_PAL) ? VIC6569_X_BEGIN : VIC6567_X_BEGIN)
138#define VIC2_Y_BEGIN         ((vic3->type == VIC4567_PAL) ? VIC6569_Y_BEGIN : VIC6567_Y_BEGIN)
139#define VIC2_X_VALUE         ((LIGHTPEN_X_VALUE + VIC2_X_BEGIN + VIC2_MAME_XPOS) / 2)
140#define VIC2_Y_VALUE         ((LIGHTPEN_Y_VALUE + VIC2_Y_BEGIN + VIC2_MAME_YPOS))
141
142#define VIC2E_K0_LEVEL         (vic3->reg[0x2f] & 0x01)
143#define VIC2E_K1_LEVEL         (vic3->reg[0x2f] & 0x02)
144#define VIC2E_K2_LEVEL         (vic3->reg[0x2f] & 0x04)
145
146/*#define VIC3_P5_LEVEL (vic3->reg[0x30] & 0x20) */
147#define VIC3_BITPLANES         (vic3->reg[0x31] & 0x10)
148#define VIC3_80COLUMNS         (vic3->reg[0x31] & 0x80)
149#define VIC3_LINES         ((vic3->reg[0x31] & 0x19) == 0x19 ? 400 : 200)
150#define VIC3_BITPLANES_WIDTH       (vic3->reg[0x31] & 0x80 ? 640 : 320)
151
152/*#define VIC2E_TEST (vic2[0x30] & 2) */
153#define DOUBLE_CLOCK         (vic3->reg[0x30] & 0x01)
154
155/* sprites 0 .. 7 */
156#define SPRITEON(nr)         (vic3->reg[0x15] & (1 << nr))
157#define SPRITE_Y_EXPAND(nr)      (vic3->reg[0x17] & (1 << nr))
158#define SPRITE_Y_SIZE(nr)      (SPRITE_Y_EXPAND(nr) ? 2 * 21 : 21)
159#define SPRITE_X_EXPAND(nr)      (vic3->reg[0x1d] & (1 << nr))
160#define SPRITE_X_SIZE(nr)      (SPRITE_X_EXPAND(nr) ? 2 * 24 : 24)
161#define SPRITE_X_POS(nr)      ((vic3->reg[(nr) * 2] | (vic3->reg[0x10] & (1 <<(nr)) ? 0x100 : 0)) - 24 + XPOS)
162#define SPRITE_X_POS2(nr)      (vic3->reg[(nr) * 2] | (vic3->reg[0x10] & (1 <<(nr)) ? 0x100 : 0))
163#define SPRITE_Y_POS(nr)      (vic3->reg[1+2*(nr)] - 50 + YPOS)
164#define SPRITE_Y_POS2(nr)      (vic3->reg[1 + 2 *(nr)])
165#define SPRITE_MULTICOLOR(nr)      (vic3->reg[0x1c] & (1 << nr))
166#define SPRITE_PRIORITY(nr)      (vic3->reg[0x1b] & (1 << nr))
167#define SPRITE_MULTICOLOR1      (vic3->reg[0x25] & 0x0f)
168#define SPRITE_MULTICOLOR2      (vic3->reg[0x26] & 0x0f)
169#define SPRITE_COLOR(nr)      (vic3->reg[0x27+nr] & 0x0f)
170#define SPRITE_ADDR(nr)         (vic3->videoaddr | 0x3f8 | nr)
171#define SPRITE_BG_COLLISION(nr)   (vic3->reg[0x1f] & (1 << nr))
172#define SPRITE_COLLISION(nr)      (vic3->reg[0x1e] & (1 << nr))
173#define SPRITE_SET_BG_COLLISION(nr) (vic3->reg[0x1f] |= (1 << nr))
174#define SPRITE_SET_COLLISION(nr)   (vic3->reg[0x1e] |= (1 << nr))
175#define SPRITE_COLL         (vic3->reg[0x1e])
176#define SPRITE_BG_COLL         (vic3->reg[0x1f])
177
178#define GFXMODE            ((vic3->reg[0x11] & 0x60) | (vic3->reg[0x16] & 0x10)) >> 4
179#define SCREENON            (vic3->reg[0x11] & 0x10)
180#define VERTICALPOS         (vic3->reg[0x11] & 0x07)
181#define HORIZONTALPOS         (vic3->reg[0x16] & 0x07)
182#define ECMON            (vic3->reg[0x11] & 0x40)
183#define HIRESON            (vic3->reg[0x11] & 0x20)
184#define MULTICOLORON         (vic3->reg[0x16] & 0x10)
185#define LINES25            (vic3->reg[0x11] & 0x08)         /* else 24 Lines */
186#define LINES            (LINES25 ? 25 : 24)
187#define YSIZE            (LINES * 8)
188#define COLUMNS40            (vic3->reg[0x16] & 0x08)         /* else 38 Columns */
189#define COLUMNS            (COLUMNS40 ? 40 : 38)
190#define XSIZE            (COLUMNS * 8)
191
192#define VIDEOADDR            ((vic3->reg[0x18] & 0xf0) << (10 - 4))
193#define CHARGENADDR         ((vic3->reg[0x18] & 0x0e) << 10)
194#define BITMAPADDR         ((data & 0x08) << 10)
195
196#define RASTERLINE         (((vic3->reg[0x11] & 0x80) << 1) | vic3->reg[0x12])
197
198#define FRAMECOLOR         (vic3->reg[0x20] & 0x0f)
199#define BACKGROUNDCOLOR         (vic3->reg[0x21] & 0x0f)
200#define MULTICOLOR1         (vic3->reg[0x22] & 0x0f)
201#define MULTICOLOR2         (vic3->reg[0x23] & 0x0f)
202#define FOREGROUNDCOLOR         (vic3->reg[0x24] & 0x0f)
203
204
205#define VIC2_LINES      (vic3->type == VIC4567_PAL ? VIC6569_LINES : VIC6567_LINES)
206#define VIC2_VISIBLELINES   (vic3->type == VIC4567_PAL ? VIC6569_VISIBLELINES : VIC6567_VISIBLELINES)
207#define VIC2_VISIBLECOLUMNS   (vic3->type == VIC4567_PAL ? VIC6569_VISIBLECOLUMNS : VIC6567_VISIBLECOLUMNS)
208#define VIC2_STARTVISIBLELINES ((VIC2_LINES - VIC2_VISIBLELINES)/2)
209#define VIC2_FIRSTRASTERLINE  (vic3->type == VIC4567_PAL ? VIC6569_FIRSTRASTERLINE : VIC6567_FIRSTRASTERLINE)
210#define VIC2_COLUMNS          (vic3->type == VIC4567_PAL ? VIC6569_COLUMNS : VIC6567_COLUMNS)
211#define VIC2_STARTVISIBLECOLUMNS ((VIC2_COLUMNS - VIC2_VISIBLECOLUMNS)/2)
212
213#define VIC3_BITPLANES_MASK (vic3->reg[0x32])
22214/* bit 0, 4 not used !?*/
23215/* I think hinibbles contains the banknumbers for interlaced modes */
24216/* if hinibble set then x&1==0 should be in bank1 (0x10000), x&1==1 in bank 0 */
25#define VIC3_BITPLANE_ADDR_HELPER(x)  ( (vic2.reg[0x33+x]&0xf) <<12)
26#define VIC3_BITPLANE_ADDR(x) ( x&1 ? VIC3_BITPLANE_ADDR_HELPER(x)+0x10000 \
27                        : VIC3_BITPLANE_ADDR_HELPER(x) )
28#define VIC3_BITPLANE_IADDR_HELPER(x)  ( (vic2.reg[0x33+x]&0xf0) <<8)
29#define VIC3_BITPLANE_IADDR(x) ( x&1 ? VIC3_BITPLANE_IADDR_HELPER(x)+0x10000 \
30                        : VIC3_BITPLANE_IADDR_HELPER(x) )
217#define VIC3_BITPLANE_ADDR_HELPER(x)  ((vic3->reg[0x33 + x] & 0x0f) << 12)
218#define VIC3_BITPLANE_ADDR(x) (x & 1 ? VIC3_BITPLANE_ADDR_HELPER(x) + 0x10000 : VIC3_BITPLANE_ADDR_HELPER(x) )
219#define VIC3_BITPLANE_IADDR_HELPER(x)  ((vic3->reg[0x33 + x] & 0xf0) << 8)
220#define VIC3_BITPLANE_IADDR(x) (x & 1 ? VIC3_BITPLANE_IADDR_HELPER(x) + 0x10000 : VIC3_BITPLANE_IADDR_HELPER(x))
31221
32const unsigned char vic3_palette[0x100*3]={0};
33222
34static struct {
35   struct {
36      UINT8 red, green, blue;
37   } palette[0x100];
38   int palette_dirty;
39} vic3;
223/*****************************************************************************
224    INLINE FUNCTIONS
225*****************************************************************************/
40226
41WRITE8_HANDLER( vic3_palette_w )
227INLINE vic3_state *get_safe_token( running_device *device )
42228{
43   if (offset<0x100) vic3.palette[offset].red=data;
44   else if (offset<0x200) vic3.palette[offset&0xff].green=data;
45   else vic3.palette[offset&0xff].blue=data;
46   vic3.palette_dirty=1;
229   assert(device != NULL);
230   assert(device->token != NULL);
231   assert(device->type == VIC3);
232
233   return (vic3_state *)device->token;
47234}
48235
49void vic4567_init(running_machine *machine, int pal, int (*dma_read)(running_machine *, int),
50                    int (*dma_read_color)(running_machine *, int), void (*irq) (running_machine *, int),
51                    void (*param_port_changed)(running_machine *, int))
236INLINE const vic3_interface *get_interface( running_device *device )
52237{
53   memset(&vic2, 0, sizeof(vic2));
238   assert(device != NULL);
239   assert((device->type == VIC3));
240   return (const vic3_interface *) device->baseconfig().static_config;
241}
54242
55   vic2.totalcycles = 63;
56   vic2.lines = VIC2_LINES;
57   vic2.vic3 = TRUE;
243/*****************************************************************************
244    IMPLEMENTATION
245*****************************************************************************/
58246
59   vic2.dma_read = dma_read;
60   vic2.dma_read_color = dma_read_color;
61   vic2.interrupt = irq;
62   vic2.pal = pal;
63   vic2.port_changed = param_port_changed;
64   vic2.on = TRUE;
247INLINE int vic3_getforeground( running_device *device, int y, int x )
248{
249    vic3_state *vic3 = get_safe_token(device);
250   return ((vic3->screen[y][x >> 3] << 8) | (vic3->screen[y][(x >> 3) + 1])) >> (8 - (x & 7));
251}
65252
66   state_save_register_global_array(machine, vic2.reg);
253INLINE int vic3_getforeground16(running_device *device, int y, int x )
254{
255    vic3_state *vic3 = get_safe_token(device);
256   return ((vic3->screen[y][x >> 3] << 16) | (vic3->screen[y][(x >> 3) + 1] << 8) | (vic3->screen[y][(x >> 3) + 2])) >> (8 - (x & 7));
67257}
68258
69WRITE8_HANDLER ( vic3_port_w )
259static void vic3_set_interrupt( running_machine *machine, int mask, vic3_state *vic3 )
70260{
71   running_machine *machine = space->machine;
72   DBG_LOG (2, "vic write", ("%.2x:%.2x\n", offset, data));
73   offset &= 0x7f;
74   switch (offset)
261   if (((vic3->reg[0x19] ^ mask) & vic3->reg[0x1a] & 0xf))
75262   {
76   case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
77   case 8: case 9: case 0xa: case 0xb: case 0xc: case 0xd: case 0xe: case 0xf:
78   case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
79   case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
80   case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
81   case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e:
82      vic2_port_w(space, offset,data);
83      break;
84   case 0x2f:
85      DBG_LOG (2, "vic write", ("%.2x:%.2x\n", offset, data));
86      vic2.reg[offset] = data;
87      break;
88   case 0x30:
89      vic2.reg[offset] = data;
90      if (vic2.port_changed!=NULL) {
91         DBG_LOG (2, "vic write", ("%.2x:%.2x\n", offset, data));
92         vic2.reg[offset] = data;
93         vic2.port_changed(machine, data);
263      if (!(vic3->reg[0x19] & 0x80))
264      {
265         //DBG_LOG(2, "vic2", ("irq start %.2x\n", mask));
266         vic3->reg[0x19] |= 0x80;
267         vic3->interrupt(machine, 1);
94268      }
95      break;
96   case 0x31:
97      vic2.reg[offset] = data;
98      if (data&0x40) cpu_set_clockscale(space->cpu, 1.0);
99      else cpu_set_clockscale(space->cpu, 1.0/3.5);
100      break;
101   case 0x32:
102   case 0x33:
103   case 0x34:
104   case 0x35:
105   case 0x36:
106   case 0x37:
107   case 0x38:
108   case 0x39:
109   case 0x3a:
110   case 0x3b:
111   case 0x3c:
112   case 0x3d:
113   case 0x3e:
114   case 0x3f:
115      vic2.reg[offset] = data;
116      DBG_LOG (2, "vic write", ("%.2x:%.2x\n", offset, data));
117      break;
118   case 0x40:
119   case 0x41:
120   case 0x42:
121   case 0x43:
122   case 0x44:
123   case 0x45:
124   case 0x46:
125   case 0x47:
126      DBG_LOG (2, "vic plane write", ("%.2x:%.2x\n", offset, data));
127      break;
128   default:
129      vic2.reg[offset] = data;
130      break;
131269   }
270   vic3->reg[0x19] |= mask;
132271}
133272
134READ8_HANDLER ( vic3_port_r )
273static void vic3_clear_interrupt( running_machine *machine, int mask, vic3_state *vic3 )
135274{
136   running_machine *machine = space->machine;
137   int val = 0;
138   offset &= 0x7f;
139   switch (offset)
275   vic3->reg[0x19] &= ~mask;
276   if ((vic3->reg[0x19] & 0x80) && !(vic3->reg[0x19] & vic3->reg[0x1a] & 0xf))
140277   {
141   case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
142   case 8: case 9: case 0xa: case 0xb: case 0xc: case 0xd: case 0xe: case 0xf:
143   case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
144   case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
145   case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
146   case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e:
147      return vic2_port_r(space, offset);
148   case 0x2f:
149   case 0x30:
150      val = vic2.reg[offset];
151      DBG_LOG (2, "vic read", ("%.2x:%.2x\n", offset, val));
278      //DBG_LOG(2, "vic2", ("irq end %.2x\n", mask));
279      vic3->reg[0x19] &= ~0x80;
280      vic3->interrupt(machine, 0);
281   }
282}
283
284static TIMER_CALLBACK(vic3_timer_timeout)
285{
286    vic3_state *vic3 = (vic3_state *)ptr;
287   int which = param;
288   //DBG_LOG(3, "vic3 ", ("timer %d timeout\n", which));
289   switch (which)
290   {
291   case 1:                     /* light pen */
292      /* and diode must recognize light */
293      if (1)
294      {
295         vic3->reg[0x13] = VIC2_X_VALUE;
296         vic3->reg[0x14] = VIC2_Y_VALUE;
297      }
298      vic3_set_interrupt(machine, 8, vic3);
152299      break;
153   case 0x31:
154   case 0x32:
155   case 0x33:
156   case 0x34:
157   case 0x35:
158   case 0x36:
159   case 0x37:
160   case 0x38:
161   case 0x39:
162   case 0x3a:
163   case 0x3b:
164   case 0x3c:
165   case 0x3d:
166   case 0x3e:
167   case 0x3f:                     /* not used */
168      val = vic2.reg[offset];
169      DBG_LOG (2, "vic read", ("%.2x:%.2x\n", offset, val));
170      break;
171   case 0x40:
172   case 0x41:
173   case 0x42:
174   case 0x43:
175   case 0x44:
176   case 0x45:
177   case 0x46:
178   case 0x47:
179      DBG_LOG (2, "vic3 plane read", ("%.2x:%.2x\n", offset, val));
180      break;
181   default:
182      val = vic2.reg[offset];
183300   }
184   return val;
185301}
302static void vic3_draw_character( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, UINT16 *color, int start_x, int end_x )
303{
304    vic3_state *vic3 = get_safe_token(device);
305   int y, code;
186306
187static void vic3_drawlines (running_machine *machine, int first, int last, int start_x, int end_x)
307   for (y = ybegin; y <= yend; y++)
308   {
309      code = vic3->dma_read(device->machine, vic3->chargenaddr + ch * 8 + y);
310      vic3->screen[y + yoff][xoff >> 3] = code;
311      if ((xoff + 0 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 0) = color[code >> 7];
312      if ((xoff + 1 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 1) = color[(code >> 6) & 1];
313      if ((xoff + 2 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 2) = color[(code >> 5) & 1];
314      if ((xoff + 3 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 3) = color[(code >> 4) & 1];
315      if ((xoff + 4 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 4) = color[(code >> 3) & 1];
316      if ((xoff + 5 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 5) = color[(code >> 2) & 1];
317      if ((xoff + 6 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 6) = color[(code >> 1) & 1];
318      if ((xoff + 7 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 7) = color[code & 1];
319   }
320}
321
322static void vic3_draw_character_multi( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, int start_x, int end_x )
188323{
324    vic3_state *vic3 = get_safe_token(device);
325   int y, code;
326
327   for (y = ybegin; y <= yend; y++)
328   {
329      code = vic3->dma_read(device->machine, vic3->chargenaddr + ch * 8 + y);
330      vic3->screen[y + yoff][xoff >> 3] = vic3->foreground[code];
331      if ((xoff + 0 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 0) = vic3->multi[code >> 6];
332      if ((xoff + 1 > start_x) && (xoff + 1 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 1) = vic3->multi[code >> 6];
333      if ((xoff + 2 > start_x) && (xoff + 2 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 2) = vic3->multi[(code >> 4) & 3];
334      if ((xoff + 3 > start_x) && (xoff + 3 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 3) = vic3->multi[(code >> 4) & 3];
335      if ((xoff + 4 > start_x) && (xoff + 4 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 4) = vic3->multi[(code >> 2) & 3];
336      if ((xoff + 5 > start_x) && (xoff + 5 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 5) = vic3->multi[(code >> 2) & 3];
337      if ((xoff + 6 > start_x) && (xoff + 6 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 6) = vic3->multi[code & 3];
338      if ((xoff + 7 > start_x) && (xoff + 7 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 7) = vic3->multi[code & 3];
339   }
340}
341
342static void vic3_draw_bitmap( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, int start_x, int end_x )
343{
344    vic3_state *vic3 = get_safe_token(device);
345   int y, code;
346
347   for (y = ybegin; y <= yend; y++)
348   {
349      code = vic3->dma_read(device->machine, (vic3->chargenaddr & 0x2000) + ch * 8 + y);
350      vic3->screen[y + yoff][xoff >> 3] = code;
351      if ((xoff + 0 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 0) = vic3->c64_bitmap[code >> 7];
352      if ((xoff + 1 > start_x) && (xoff + 1 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 1) = vic3->c64_bitmap[(code >> 6) & 1];
353      if ((xoff + 2 > start_x) && (xoff + 2 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 2) = vic3->c64_bitmap[(code >> 5) & 1];
354      if ((xoff + 3 > start_x) && (xoff + 3 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 3) = vic3->c64_bitmap[(code >> 4) & 1];
355      if ((xoff + 4 > start_x) && (xoff + 4 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 4) = vic3->c64_bitmap[(code >> 3) & 1];
356      if ((xoff + 5 > start_x) && (xoff + 5 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 5) = vic3->c64_bitmap[(code >> 2) & 1];
357      if ((xoff + 6 > start_x) && (xoff + 6 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 6) = vic3->c64_bitmap[(code >> 1) & 1];
358      if ((xoff + 7 > start_x) && (xoff + 7 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 7) = vic3->c64_bitmap[code & 1];
359   }
360}
361
362static void vic3_draw_bitmap_multi( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, int start_x, int end_x )
363{
364    vic3_state *vic3 = get_safe_token(device);
365   int y, code;
366
367   for (y = ybegin; y <= yend; y++)
368   {
369      code = vic3->dma_read(device->machine, (vic3->chargenaddr & 0x2000) + ch * 8 + y);
370      vic3->screen[y + yoff][xoff >> 3] = vic3->foreground[code];
371      if ((xoff + 0 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 0) = vic3->bitmapmulti[code >> 6];
372      if ((xoff + 1 > start_x) && (xoff + 1 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 1) = vic3->bitmapmulti[code >> 6];
373      if ((xoff + 2 > start_x) && (xoff + 2 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 2) = vic3->bitmapmulti[(code >> 4) & 3];
374      if ((xoff + 3 > start_x) && (xoff + 3 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 3) = vic3->bitmapmulti[(code >> 4) & 3];
375      if ((xoff + 4 > start_x) && (xoff + 4 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 4) = vic3->bitmapmulti[(code >> 2) & 3];
376      if ((xoff + 5 > start_x) && (xoff + 5 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 5) = vic3->bitmapmulti[(code >> 2) & 3];
377      if ((xoff + 6 > start_x) && (xoff + 6 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 6) = vic3->bitmapmulti[code & 3];
378      if ((xoff + 7 > start_x) && (xoff + 7 < end_x)) *BITMAP_ADDR16(vic3->bitmap, y + yoff + FIRSTLINE, xoff + 7) = vic3->bitmapmulti[code & 3];
379   }
380}
381
382static void vic3_draw_sprite_code( running_device *device, int y, int xbegin, int code, int color, int start_x, int end_x )
383{
384    vic3_state *vic3 = get_safe_token(device);
385   register int mask, x;
386
387   if ((y < YPOS) || (y >= (VIC2_STARTVISIBLELINES + VIC2_VISIBLELINES)) || (xbegin <= 1) || (xbegin >= (VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS)))
388      return;
389
390   for (x = 0, mask = 0x80; x < 8; x++, mask >>= 1)
391   {
392      if (code & mask)
393      {
394         if ((xbegin + x > start_x) && (xbegin + x < end_x))
395            *BITMAP_ADDR16(vic3->bitmap, y + FIRSTLINE, xbegin + x) = color;
396      }
397   }
398}
399
400static void vic3_draw_sprite_code_multi( running_device *device, int y, int xbegin, int code, int prior, int start_x, int end_x )
401{
402    vic3_state *vic3 = get_safe_token(device);
403   register int x, mask, shift;
404
405   if ((y < YPOS) || (y >= (VIC2_STARTVISIBLELINES + VIC2_VISIBLELINES)) || (xbegin <= 1) || (xbegin >= (VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS)))
406      {
407         return;
408      }
409
410   for (x = 0, mask = 0xc0, shift = 6; x < 8; x += 2, mask >>= 2, shift -= 2)
411   {
412      if (code & mask)
413      {
414         switch ((prior & mask) >> shift)
415         {
416         case 1:
417            if ((xbegin + x + 1 > start_x) && (xbegin + x + 1 < end_x))
418               *BITMAP_ADDR16(vic3->bitmap, y + FIRSTLINE, xbegin + x + 1) = vic3->spritemulti[(code >> shift) & 3];
419            break;
420         case 2:
421            if ((xbegin + x > start_x) && (xbegin + x < end_x))
422               *BITMAP_ADDR16(vic3->bitmap, y + FIRSTLINE, xbegin + x) = vic3->spritemulti[(code >> shift) & 3];
423            break;
424         case 3:
425            if ((xbegin + x > start_x) && (xbegin + x < end_x))
426               *BITMAP_ADDR16(vic3->bitmap, y + FIRSTLINE, xbegin + x) = vic3->spritemulti[(code >> shift) & 3];
427            if ((xbegin + x + 1> start_x) && (xbegin + x + 1< end_x))
428               *BITMAP_ADDR16(vic3->bitmap, y + FIRSTLINE, xbegin + x + 1) = vic3->spritemulti[(code >> shift) & 3];
429            break;
430         }
431      }
432   }
433}
434
435static void vic3_sprite_collision( running_device *device, int nr, int y, int x, int mask )
436{
437    vic3_state *vic3 = get_safe_token(device);
438   int i, value, xdiff;
439
440   for (i = 7; i > nr; i--)
441   {
442      if (!SPRITEON(i) || !vic3->sprites[i].paintedline[y] || (SPRITE_COLLISION(i) && SPRITE_COLLISION(nr)))
443         continue;
444
445      if ((x + 7 < SPRITE_X_POS(i)) || (x >= SPRITE_X_POS(i) + SPRITE_X_SIZE(i)))
446         continue;
447
448      xdiff = x - SPRITE_X_POS(i);
449
450      if ((x & 7) == (SPRITE_X_POS(i) & 7))
451         value = vic3->sprites[i].bitmap[y][xdiff >> 3];
452      else if (xdiff < 0)
453         value = vic3->sprites[i].bitmap[y][0] >> (-xdiff);
454      else {
455         UINT8 *vp = vic3->sprites[i].bitmap[y]+(xdiff >> 3);
456         value = ((vp[1] | (*vp << 8)) >> (8 - (xdiff & 7) )) & 0xff;
457      }
458
459      if (value & mask)
460      {
461         SPRITE_SET_COLLISION(i);
462         SPRITE_SET_COLLISION(nr);
463         vic3_set_interrupt(device->machine, 4, vic3);
464      }
465   }
466}
467
468static void vic3_draw_sprite( running_device *device, int nr, int yoff, int ybegin, int yend, int start_x, int end_x )
469{
470    vic3_state *vic3 = get_safe_token(device);
471   int y, i, addr, xbegin, color, prior, collision;
472   int value, value3 = 0;
473
474   xbegin = SPRITE_X_POS(nr);
475   addr = vic3->dma_read(device->machine, SPRITE_ADDR(nr)) << 6;
476   color = SPRITE_COLOR(nr);
477   prior = SPRITE_PRIORITY(nr);
478   collision = SPRITE_BG_COLLISION(nr);
479
480   if (SPRITE_X_EXPAND(nr))
481   {
482      for (y = ybegin; y <= yend; y++)
483      {
484         vic3->sprites[nr].paintedline[y] = 1;
485         for (i = 0; i < 3; i++)
486         {
487            value = vic3->expandx[vic3->dma_read(device->machine, addr + vic3->sprites[nr].line * 3 + i)];
488            vic3->sprites[nr].bitmap[y][i * 2] = value >> 8;
489            vic3->sprites[nr].bitmap[y][i * 2 + 1] = value & 0xff;
490            vic3_sprite_collision(device, nr, y, xbegin + i * 16, value >> 8);
491            vic3_sprite_collision(device, nr, y, xbegin + i * 16 + 8, value & 0xff);
492            if (prior || !collision)
493               value3 = vic3_getforeground16(device, yoff + y, xbegin + i * 16 - 7);
494            if (!collision && (value & value3))
495            {
496               collision = 1;
497               SPRITE_SET_BG_COLLISION(nr);
498               vic3_set_interrupt(device->machine, 2, vic3);
499            }
500            if (prior)
501               value &= ~value3;
502            vic3_draw_sprite_code(device, yoff + y, xbegin + i * 16, value >> 8, color, start_x, end_x);
503            vic3_draw_sprite_code(device, yoff + y, xbegin + i * 16 + 8, value & 0xff, color, start_x, end_x);
504         }
505         vic3->sprites[nr].bitmap[y][i * 2]=0; //easier sprite collision detection
506         if (SPRITE_Y_EXPAND(nr))
507         {
508            if (vic3->sprites[nr].repeat)
509            {
510               vic3->sprites[nr].line++;
511               vic3->sprites[nr].repeat = 0;
512            }
513            else
514               vic3->sprites[nr].repeat = 1;
515         }
516         else
517         {
518            vic3->sprites[nr].line++;
519         }
520      }
521   }
522   else
523   {
524      for (y = ybegin; y <= yend; y++)
525      {
526         vic3->sprites[nr].paintedline[y] = 1;
527         for (i = 0; i < 3; i++)
528         {
529            value = vic3->dma_read(device->machine, addr + vic3->sprites[nr].line * 3 + i);
530            vic3->sprites[nr].bitmap[y][i] = value;
531            vic3_sprite_collision(device, nr, y, xbegin + i * 8, value);
532            if (prior || !collision)
533               value3 = vic3_getforeground(device, yoff + y, xbegin + i * 8 - 7);
534            if (!collision && (value & value3))
535            {
536               collision = 1;
537               SPRITE_SET_BG_COLLISION(nr);
538               vic3_set_interrupt(device->machine, 2, vic3);
539            }
540            if (prior)
541               value &= ~value3;
542            vic3_draw_sprite_code(device, yoff + y, xbegin + i * 8, value, color, start_x, end_x);
543         }
544         vic3->sprites[nr].bitmap[y][i]=0; //easier sprite collision detection
545         if (SPRITE_Y_EXPAND(nr))
546         {
547            if (vic3->sprites[nr].repeat)
548            {
549               vic3->sprites[nr].line++;
550               vic3->sprites[nr].repeat = 0;
551            }
552            else
553               vic3->sprites[nr].repeat = 1;
554         }
555         else
556         {
557            vic3->sprites[nr].line++;
558         }
559      }
560   }
561}
562
563static void vic3_draw_sprite_multi( running_device *device, int nr, int yoff, int ybegin, int yend, int start_x, int end_x )
564{
565    vic3_state *vic3 = get_safe_token(device);
566   int y, i, prior, addr, xbegin, collision;
567   int value, value2, value3 = 0, bg, color[2];
568
569   xbegin = SPRITE_X_POS(nr);
570   addr = vic3->dma_read(device->machine, SPRITE_ADDR(nr)) << 6;
571   vic3->spritemulti[2] = SPRITE_COLOR(nr);
572   prior = SPRITE_PRIORITY(nr);
573   collision = SPRITE_BG_COLLISION(nr);
574   color[0] = 0;
575   color[1] = 1;
576
577   if (SPRITE_X_EXPAND(nr))
578   {
579      for (y = ybegin; y <= yend; y++)
580      {
581         vic3->sprites[nr].paintedline[y] = 1;
582         for (i = 0; i < 3; i++)
583         {
584            value = vic3->expandx_multi[bg = vic3->dma_read(device->machine, addr + vic3->sprites[nr].line * 3 + i)];
585            value2 = vic3->expandx[vic3->multi_collision[bg]];
586            vic3->sprites[nr].bitmap[y][i * 2] = value2 >> 8;
587            vic3->sprites[nr].bitmap[y][i * 2 + 1] = value2 & 0xff;
588            vic3_sprite_collision(device, nr, y, xbegin + i * 16, value2 >> 8);
589            vic3_sprite_collision(device, nr, y, xbegin + i * 16 + 8, value2 & 0xff);
590            if (prior || !collision)
591            {
592               value3 = vic3_getforeground16(device, yoff + y, xbegin + i * 16 - 7);
593            }
594            if (!collision && (value2 & value3))
595            {
596               collision = 1;
597               SPRITE_SET_BG_COLLISION(nr);
598               vic3_set_interrupt(device->machine, 2, vic3);
599            }
600            if (prior)
601            {
602               vic3_draw_sprite_code_multi(device, yoff + y, xbegin + i * 16, value >> 8, (value3 >> 8) ^ 0xff, start_x, end_x);
603               vic3_draw_sprite_code_multi(device, yoff + y, xbegin + i * 16 + 8, value & 0xff, (value3 & 0xff) ^ 0xff, start_x, end_x);
604            }
605            else
606            {
607               vic3_draw_sprite_code_multi(device, yoff + y, xbegin + i * 16, value >> 8, 0xff, start_x, end_x);
608               vic3_draw_sprite_code_multi(device, yoff + y, xbegin + i * 16 + 8, value & 0xff, 0xff, start_x, end_x);
609            }
610         }
611         vic3->sprites[nr].bitmap[y][i * 2]=0; //easier sprite collision detection
612         if (SPRITE_Y_EXPAND(nr))
613         {
614            if (vic3->sprites[nr].repeat)
615            {
616               vic3->sprites[nr].line++;
617               vic3->sprites[nr].repeat = 0;
618            }
619            else
620               vic3->sprites[nr].repeat = 1;
621         }
622         else
623         {
624            vic3->sprites[nr].line++;
625         }
626      }
627   }
628   else
629   {
630      for (y = ybegin; y <= yend; y++)
631      {
632         vic3->sprites[nr].paintedline[y] = 1;
633         for (i = 0; i < 3; i++)
634         {
635            value = vic3->dma_read(device->machine, addr + vic3->sprites[nr].line * 3 + i);
636            vic3->sprites[nr].bitmap[y][i] = value2 = vic3->multi_collision[value];
637            vic3_sprite_collision(device, nr, y, xbegin + i * 8, value2);
638            if (prior || !collision)
639            {
640               value3 = vic3_getforeground(device, yoff + y, xbegin + i * 8 - 7);
641            }
642            if (!collision && (value2 & value3))
643            {
644               collision = 1;
645               SPRITE_SET_BG_COLLISION(nr);
646               vic3_set_interrupt(device->machine, 2, vic3);
647            }
648            if (prior)
649            {
650               vic3_draw_sprite_code_multi(device, yoff + y, xbegin + i * 8, value, value3 ^ 0xff, start_x, end_x);
651            }
652            else
653            {
654               vic3_draw_sprite_code_multi(device, yoff + y, xbegin + i * 8, value, 0xff, start_x, end_x);
655            }
656         }
657         vic3->sprites[nr].bitmap[y][i] = 0; //easier sprite collision detection
658         if (SPRITE_Y_EXPAND(nr))
659         {
660            if (vic3->sprites[nr].repeat)
661            {
662               vic3->sprites[nr].line++;
663               vic3->sprites[nr].repeat = 0;
664            }
665            else
666               vic3->sprites[nr].repeat = 1;
667         }
668         else
669         {
670            vic3->sprites[nr].line++;
671         }
672      }
673   }
674}
675
676static void vic3_drawlines( running_device *device, int first, int last, int start_x, int end_x )
677{
678    vic3_state *vic3 = get_safe_token(device);
189679   int line, vline, end;
190680   int attr, ch, ecm;
191681   int syend;
r7364r7365
195685
196686   if (first == last)
197687      return;
198   vic2.lastline = last;
199   if (video_skip_this_frame ())
200      return;
688   vic3->lastline = last;
201689
202690   /* top part of display not rastered */
203691   first -= VIC2_YPOS - YPOS;
r7364r7365
205693   if ((first >= last) || (last <= 0))
206694   {
207695      for (i = 0; i < 8; i++)
208         vic2.sprites[i].repeat = vic2.sprites[i].line = 0;
696         vic3->sprites[i].repeat = vic3->sprites[i].line = 0;
209697      return;
210698   }
211699   if (first < 0)
r7364r7365
213701
214702   if (!SCREENON)
215703   {
216      for (line = first; (line < last) && (line < vic2.bitmap->height); line++)
704      for (line = first; (line < last) && (line < vic3->bitmap->height); line++)
217705      {
218         memset16 (BITMAP_ADDR16(vic2.bitmap, line + FIRSTLINE, 0), 0, vic2.bitmap->width);
706         memset16(BITMAP_ADDR16(vic3->bitmap, line + FIRSTLINE, 0), 0, vic3->bitmap->width);
219707      }
220708      return;
221709   }
r7364r7365
224712   else
225713      xbegin = XPOS + 7, xend = xbegin + 624;
226714
227   if (last < vic2.y_begin)
715   if (last < vic3->y_begin)
228716      end = last;
229717   else
230      end = vic2.y_begin + YPOS;
718      end = vic3->y_begin + YPOS;
231719
232720   for (line = first; line < end; line++)
233721   {
234      memset16 (BITMAP_ADDR16(vic2.bitmap, line + FIRSTLINE, 0), FRAMECOLOR, vic2.bitmap->width);
722      memset16(BITMAP_ADDR16(vic3->bitmap, line + FIRSTLINE, 0), FRAMECOLOR, vic3->bitmap->width);
235723   }
236724
237725   if (LINES25)
238726   {
239      vline = line - vic2.y_begin - YPOS;
727      vline = line - vic3->y_begin - YPOS;
240728   }
241729   else
242730   {
243      vline = line - vic2.y_begin - YPOS + 8 - VERTICALPOS;
731      vline = line - vic3->y_begin - YPOS + 8 - VERTICALPOS;
244732   }
245   if (last < vic2.y_end + YPOS)
733   if (last < vic3->y_end + YPOS)
246734      end = last;
247735   else
248      end = vic2.y_end + YPOS;
249   x_end2=vic2.x_end*2;
736      end = vic3->y_end + YPOS;
737   x_end2 = vic3->x_end * 2;
250738   for (; line < end; vline = (vline + 8) & ~7, line = line + 1 + yend - ybegin)
251739   {
252740      offs = (vline >> 3) * 80;
r7364r7365
255743      yend = (yoff + 7 < end) ? 7 : (end - yoff - 1);
256744      /* rendering 39 characters */
257745      /* left and right borders are overwritten later */
258      vic2.shift[line] = HORIZONTALPOS;
746      vic3->shift[line] = HORIZONTALPOS;
259747
260      for (xoff = vic2.x_begin + XPOS; xoff < x_end2 + XPOS; xoff += 8, offs++)
748      for (xoff = vic3->x_begin + XPOS; xoff < x_end2 + XPOS; xoff += 8, offs++)
261749      {
262         ch = vic2.dma_read(machine, vic2.videoaddr + offs);
263         attr = vic2.dma_read_color(machine, vic2.videoaddr + offs);
750         ch = vic3->dma_read(device->machine, vic3->videoaddr + offs);
751         attr = vic3->dma_read_color(device->machine, vic3->videoaddr + offs);
264752         if (HIRESON)
265753         {
266            vic2.bitmapmulti[1] = vic2.c64_bitmap[1] = ch >> 4;
267            vic2.bitmapmulti[2] = vic2.c64_bitmap[0] = ch & 0xf;
754            vic3->bitmapmulti[1] = vic3->c64_bitmap[1] = ch >> 4;
755            vic3->bitmapmulti[2] = vic3->c64_bitmap[0] = ch & 0xf;
268756            if (MULTICOLORON)
269757            {
270               vic2.bitmapmulti[3] = attr;
271               vic2_draw_bitmap_multi(machine, ybegin, yend, offs, yoff, xoff, start_x, end_x);
758               vic3->bitmapmulti[3] = attr;
759               vic3_draw_bitmap_multi(device, ybegin, yend, offs, yoff, xoff, start_x, end_x);
272760            }
273761            else
274762            {
275               vic2_draw_bitmap(machine, ybegin, yend, offs, yoff, xoff, start_x, end_x);
763               vic3_draw_bitmap(device, ybegin, yend, offs, yoff, xoff, start_x, end_x);
276764            }
277765         }
278766         else if (ECMON)
279767         {
280768            ecm = ch >> 6;
281            vic2.ecmcolor[0] = vic2.colors[ecm];
282            vic2.ecmcolor[1] = attr;
283            vic2_draw_character(machine, ybegin, yend, ch & ~0xC0, yoff, xoff, vic2.ecmcolor, start_x, end_x);
769            vic3->ecmcolor[0] = vic3->colors[ecm];
770            vic3->ecmcolor[1] = attr;
771            vic3_draw_character(device, ybegin, yend, ch & ~0xC0, yoff, xoff, vic3->ecmcolor, start_x, end_x);
284772         }
285773         else if (MULTICOLORON && (attr & 8))
286774         {
287            vic2.multi[3] = attr & 7;
288            vic2_draw_character_multi(machine, ybegin, yend, ch, yoff, xoff, start_x, end_x);
775            vic3->multi[3] = attr & 7;
776            vic3_draw_character_multi(device, ybegin, yend, ch, yoff, xoff, start_x, end_x);
289777         }
290778         else
291779         {
292            vic2.mono[1] = attr;
293            vic2_draw_character(machine, ybegin, yend, ch, yoff, xoff, vic2.mono, start_x, end_x);
780            vic3->mono[1] = attr;
781            vic3_draw_character(device, ybegin, yend, ch, yoff, xoff, vic3->mono, start_x, end_x);
294782         }
295783      }
296784      /* sprite priority, sprite overwrites lowerprior pixels */
297785      for (i = 7; i >= 0; i--)
298786      {
299         if (vic2.sprites[i].line || vic2.sprites[i].repeat)
787         if (vic3->sprites[i].line || vic3->sprites[i].repeat)
300788         {
301789            syend = yend;
302            if (SPRITE_Y_EXPAND (i))
790            if (SPRITE_Y_EXPAND(i))
303791            {
304               if ((21 - vic2.sprites[i].line) * 2 - vic2.sprites[i].repeat < yend - ybegin + 1)
305                  syend = ybegin + (21 - vic2.sprites[i].line) * 2 - vic2.sprites[i].repeat - 1;
792               if ((21 - vic3->sprites[i].line) * 2 - vic3->sprites[i].repeat < yend - ybegin + 1)
793                  syend = ybegin + (21 - vic3->sprites[i].line) * 2 - vic3->sprites[i].repeat - 1;
306794            }
307795            else
308796            {
309               if (vic2.sprites[i].line + yend - ybegin + 1 > 20)
310                  syend = ybegin + 20 - vic2.sprites[i].line;
797               if (vic3->sprites[i].line + yend - ybegin + 1 > 20)
798                  syend = ybegin + 20 - vic3->sprites[i].line;
311799            }
312800            if (yoff + syend > YPOS + 200)
313801               syend = YPOS + 200 - yoff - 1;
314            if (SPRITE_MULTICOLOR (i))
315               vic2_draw_sprite_multi (machine, i, yoff, ybegin, syend, start_x, end_x);
802            if (SPRITE_MULTICOLOR(i))
803               vic3_draw_sprite_multi(device, i, yoff, ybegin, syend, start_x, end_x);
316804            else
317               vic2_draw_sprite (machine, i, yoff, ybegin, syend, start_x, end_x);
318            if ((syend != yend) || (vic2.sprites[i].line > 20))
805               vic3_draw_sprite(device, i, yoff, ybegin, syend, start_x, end_x);
806            if ((syend != yend) || (vic3->sprites[i].line > 20))
319807            {
320               vic2.sprites[i].line = vic2.sprites[i].repeat = 0;
808               vic3->sprites[i].line = vic3->sprites[i].repeat = 0;
321809               for (j = syend; j <= yend; j++)
322                  vic2.sprites[i].paintedline[j] = 0;
810                  vic3->sprites[i].paintedline[j] = 0;
323811            }
324812         }
325813         // sprite wrap y at the top of the screen
326         else if (SPRITEON (i) && (yoff == 1 + yend - ybegin) && (SPRITE_Y_POS (i) < 1 + yend - ybegin))
814         else if (SPRITEON(i) && (yoff == 1 + yend - ybegin) && (SPRITE_Y_POS(i) < 1 + yend - ybegin))
327815         {
328            int wrapped = 1 + yend - ybegin - SPRITE_Y_POS (i);
816            int wrapped = 1 + yend - ybegin - SPRITE_Y_POS(i);
329817            syend = yend;
330818
331            if (SPRITE_Y_EXPAND (i))
819            if (SPRITE_Y_EXPAND(i))
332820            {
333               if (wrapped & 1) vic2.sprites[i].repeat = 1;
821               if (wrapped & 1) vic3->sprites[i].repeat = 1;
334822               wrapped >>= 1;
335823               syend = 21 * 2 - 1 - wrapped * 2;
336824               if (syend > (yend - ybegin)) syend = yend - ybegin;
r7364r7365
341829               if (syend > (yend - ybegin)) syend = yend - ybegin;
342830            }
343831
344            vic2.sprites[i].line = wrapped;
832            vic3->sprites[i].line = wrapped;
345833
346            if (SPRITE_MULTICOLOR (i))
347               vic2_draw_sprite_multi (machine, i, yoff, 0 , syend, start_x, end_x);
834            if (SPRITE_MULTICOLOR(i))
835               vic3_draw_sprite_multi(device, i, yoff, 0 , syend, start_x, end_x);
348836            else
349               vic2_draw_sprite (machine, i, yoff, 0 , syend, start_x, end_x);
837               vic3_draw_sprite(device, i, yoff, 0 , syend, start_x, end_x);
350838
351            if ((syend != yend) || (vic2.sprites[i].line > 20))
839            if ((syend != yend) || (vic3->sprites[i].line > 20))
352840            {
353841               for (j = syend; j <= yend; j++)
354                  vic2.sprites[i].paintedline[j] = 0;
355               vic2.sprites[i].line = vic2.sprites[i].repeat = 0;
842                  vic3->sprites[i].paintedline[j] = 0;
843               vic3->sprites[i].line = vic3->sprites[i].repeat = 0;
356844            }
357845         }
358         else if (SPRITEON (i) && (yoff + ybegin <= SPRITE_Y_POS (i))
359                && (yoff + yend >= SPRITE_Y_POS (i)))
846         else if (SPRITEON(i) && (yoff + ybegin <= SPRITE_Y_POS(i))
847                && (yoff + yend >= SPRITE_Y_POS(i)))
360848         {
361849            syend = yend;
362            if (SPRITE_Y_EXPAND (i))
850            if (SPRITE_Y_EXPAND(i))
363851            {
364852               if (21 * 2 < yend - ybegin + 1)
365853                  syend = ybegin + 21 * 2 - 1;
r7364r7365
371859            }
372860            if (yoff + syend >= YPOS + 200)
373861               syend = YPOS + 200 - yoff - 1;
374            for (j = 0; j < SPRITE_Y_POS (i) - yoff; j++)
375               vic2.sprites[i].paintedline[j] = 0;
376            if (SPRITE_MULTICOLOR (i))
377               vic2_draw_sprite_multi (machine, i, yoff, SPRITE_Y_POS (i) - yoff, syend, start_x, end_x);
862            for (j = 0; j < SPRITE_Y_POS(i) - yoff; j++)
863               vic3->sprites[i].paintedline[j] = 0;
864            if (SPRITE_MULTICOLOR(i))
865               vic3_draw_sprite_multi(device, i, yoff, SPRITE_Y_POS(i) - yoff, syend, start_x, end_x);
378866            else
379               vic2_draw_sprite (machine, i, yoff, SPRITE_Y_POS (i) - yoff, syend, start_x, end_x);
380            if ((syend != yend) || (vic2.sprites[i].line > 20))
867               vic3_draw_sprite(device, i, yoff, SPRITE_Y_POS(i) - yoff, syend, start_x, end_x);
868            if ((syend != yend) || (vic3->sprites[i].line > 20))
381869            {
382870               for (j = syend; j <= yend; j++)
383                  vic2.sprites[i].paintedline[j] = 0;
384               vic2.sprites[i].line = vic2.sprites[i].repeat = 0;
871                  vic3->sprites[i].paintedline[j] = 0;
872               vic3->sprites[i].line = vic3->sprites[i].repeat = 0;
385873            }
386874         }
387875         else
388876         {
389            memset (vic2.sprites[i].paintedline, 0, sizeof (vic2.sprites[i].paintedline));
877            memset (vic3->sprites[i].paintedline, 0, sizeof (vic3->sprites[i].paintedline));
390878         }
391879      }
392880
393881      for (i = ybegin; i <= yend; i++)
394882      {
395         plot_box(vic2.bitmap, 0, yoff + ybegin + FIRSTLINE, xbegin, yend-ybegin+1, FRAMECOLOR);
396         plot_box(vic2.bitmap, xend, yoff + ybegin + FIRSTLINE, vic2.bitmap->width - xend, yend-ybegin+1, FRAMECOLOR);
883         plot_box(vic3->bitmap, 0, yoff + ybegin + FIRSTLINE, xbegin, yend-ybegin+1, FRAMECOLOR);
884         plot_box(vic3->bitmap, xend, yoff + ybegin + FIRSTLINE, vic3->bitmap->width - xend, yend-ybegin+1, FRAMECOLOR);
397885      }
398886   }
399   if (last < vic2.bitmap->height)
887   if (last < vic3->bitmap->height)
400888      end = last;
401889   else
402      end = vic2.bitmap->height;
890      end = vic3->bitmap->height;
403891
404892   for (; line < end; line++)
405893   {
406      memset16 (BITMAP_ADDR16(vic2.bitmap, line + FIRSTLINE, 0), FRAMECOLOR, vic2.bitmap->width);
894      memset16 (BITMAP_ADDR16(vic3->bitmap, line + FIRSTLINE, 0), FRAMECOLOR, vic3->bitmap->width);
407895   }
408896}
409897
410#ifndef OPTIMIZE
411INLINE UINT8 vic3_bitplane_to_packed(UINT8 *latch, int mask, int number)
898static void vic2_drawlines( running_device *device, int first, int last, int start_x, int end_x )
412899{
413   UINT8 color=0;
414   if ( (mask&1)&&(latch[0]&(1<<number)) ) color|=1;
415   if ( (mask&2)&&(latch[1]&(1<<number)) ) color|=2;
416   if ( (mask&4)&&(latch[2]&(1<<number)) ) color|=4;
417   if ( (mask&8)&&(latch[3]&(1<<number)) ) color|=8;
418   if ( (mask&0x10)&&(latch[4]&(1<<number)) ) color|=0x10;
419   if ( (mask&0x20)&&(latch[5]&(1<<number)) ) color|=0x20;
420   if ( (mask&0x40)&&(latch[6]&(1<<number)) ) color|=0x40;
421   if ( (mask&0x80)&&(latch[7]&(1<<number)) ) color|=0x80;
422   return color;
423}
900    vic3_state *vic3 = get_safe_token(device);
901   int line, vline, end;
902   int attr, ch, ecm;
903   int syend;
904   int offs, yoff, xoff, ybegin, yend, xbegin, xend;
905   int i;
424906
907   if (VIC3_BITPLANES)
908      return ;
425909
426INLINE void vic3_block_2_color(int offset, UINT8 colors[8])
427{
428   if (VIC3_BITPLANES_MASK&1) {
429      colors[0]=c64_memory[VIC3_BITPLANE_ADDR(0)+offset];
910   /* temporary allowing vic3 displaying 80 columns */
911   if (vic3->reg[0x31] & 0x80)
912   {
913      vic3_drawlines(device, first, first + 1, start_x, end_x);
914      return;
430915   }
431   if (VIC3_BITPLANES_MASK&2) {
432      colors[1]=c64_memory[VIC3_BITPLANE_ADDR(1)+offset];
916
917   /* otherwise, draw VIC II output (currently using the old code, not the new one from vic6567.c) */
918
919   /* top part of display not rastered */
920   first -= VIC2_YPOS - YPOS;
921
922   xbegin = VIC2_STARTVISIBLECOLUMNS;
923   xend = xbegin + VIC2_VISIBLECOLUMNS;
924   if (!SCREENON)
925   {
926      xbegin = VIC2_STARTVISIBLECOLUMNS;
927      xend = xbegin + VIC2_VISIBLECOLUMNS;
928      if ((start_x <= xbegin) && (end_x >= xend))
929         plot_box(vic3->bitmap, xbegin, first + FIRSTLINE, xend - xbegin, 1, FRAMECOLOR);
930      if ((start_x > xbegin) && (end_x >= xend))
931         plot_box(vic3->bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, xend - start_x, 1, FRAMECOLOR);
932      if ((start_x <= xbegin) && (end_x < xend))
933         plot_box(vic3->bitmap, xbegin, first + FIRSTLINE, end_x - xbegin , 1, FRAMECOLOR);
934      if ((start_x > xbegin) && (end_x < xend))
935         plot_box(vic3->bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
936      return;
433937   }
434   if (VIC3_BITPLANES_MASK&4) {
435      colors[2]=c64_memory[VIC3_BITPLANE_ADDR(2)+offset];
938
939   if (COLUMNS40)
940   {
941      xbegin = XPOS;
942      xend = xbegin + 320;
436943   }
437   if (VIC3_BITPLANES_MASK&8) {
438      colors[3]=c64_memory[VIC3_BITPLANE_ADDR(3)+offset];
944   else
945   {
946      xbegin = XPOS + 7;
947      xend = xbegin + 304;
439948   }
440   if (VIC3_BITPLANES_MASK&0x10) {
441      colors[4]=c64_memory[VIC3_BITPLANE_ADDR(4)+offset];
949
950   if (first + 1 < vic3->y_begin)
951      end = first + 1;
952   else
953      end = vic3->y_begin + YPOS;
954
955   line = first;
956   // top border
957   if (line < end)
958   {
959      if ((start_x <= xbegin) && (end_x >= xend))
960         plot_box(vic3->bitmap, xbegin, first + FIRSTLINE, xend - xbegin, 1, FRAMECOLOR);
961      if ((start_x > xbegin) && (end_x >= xend))
962         plot_box(vic3->bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, xend - start_x, 1, FRAMECOLOR);
963      if ((start_x <= xbegin) && (end_x < xend))
964         plot_box(vic3->bitmap, xbegin, first + FIRSTLINE, end_x - xbegin , 1, FRAMECOLOR);
965      if ((start_x > xbegin) && (end_x < xend))
966         plot_box(vic3->bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
967      line = end;
442968   }
443   if (VIC3_BITPLANES_MASK&0x20) {
444      colors[5]=c64_memory[VIC3_BITPLANE_ADDR(5)+offset];
969
970   vline = line - YPOS + 3 - VERTICALPOS;
971
972   if (first + 1 < vic3->y_end + YPOS)
973      end = first + 1;
974   else
975      end = vic3->y_end + YPOS;
976
977   if (line < end)
978   {
979      offs = (vline >> 3) * 40;
980      ybegin = vline & 7;
981      yoff = line - ybegin;
982      yend = (yoff + 7 < end) ? 7 : (end - yoff - 1);
983
984      /* rendering 39 characters */
985      /* left and right borders are overwritten later */
986
987      vic3->shift[line] = HORIZONTALPOS;
988      for (xoff = vic3->x_begin + XPOS; xoff < vic3->x_end + XPOS; xoff += 8, offs++)
989      {
990         ch = vic3->dma_read(device->machine, vic3->videoaddr + offs);
991#if 0
992         attr = vic3->dma_read_color(device->machine, vic3->videoaddr + offs);
993#else
994         /* temporaery until vic3 finished */
995         attr = vic3->dma_read_color(device->machine, (vic3->videoaddr + offs)&0x3ff)&0x0f;
996#endif
997         if (HIRESON)
998         {
999            vic3->bitmapmulti[1] = vic3->c64_bitmap[1] = ch >> 4;
1000            vic3->bitmapmulti[2] = vic3->c64_bitmap[0] = ch & 0xf;
1001            if (MULTICOLORON)
1002            {
1003               vic3->bitmapmulti[3] = attr;
1004               vic3_draw_bitmap_multi(device, ybegin, yend, offs, yoff, xoff, start_x, end_x);
1005            }
1006            else
1007            {
1008               vic3_draw_bitmap(device, ybegin, yend, offs, yoff, xoff, start_x, end_x);
1009            }
1010         }
1011         else if (ECMON)
1012         {
1013            ecm = ch >> 6;
1014            vic3->ecmcolor[0] = vic3->colors[ecm];
1015            vic3->ecmcolor[1] = attr;
1016            vic3_draw_character(device, ybegin, yend, ch & ~0xC0, yoff, xoff, vic3->ecmcolor, start_x, end_x);
1017         }
1018         else if (MULTICOLORON && (attr & 8))
1019         {
1020            vic3->multi[3] = attr & 7;
1021            vic3_draw_character_multi(device, ybegin, yend, ch, yoff, xoff, start_x, end_x);
1022         }
1023         else
1024         {
1025            vic3->mono[1] = attr;
1026            vic3_draw_character(device, ybegin, yend, ch, yoff, xoff, vic3->mono, start_x, end_x);
1027         }
1028      }
1029
1030      /* sprite priority, sprite overwrites lowerprior pixels */
1031      for (i = 7; i >= 0; i--)
1032      {
1033         if (SPRITEON (i) &&
1034               (yoff + ybegin >= SPRITE_Y_POS (i)) &&
1035               (yoff + ybegin - SPRITE_Y_POS (i) < (SPRITE_Y_EXPAND (i)? 21 * 2 : 21 )) &&
1036               (SPRITE_Y_POS (i) < 0))
1037         {
1038            int wrapped = - SPRITE_Y_POS (i) + 6;
1039
1040            syend = yend;
1041
1042            if (SPRITE_Y_EXPAND (i))
1043            {
1044               if (wrapped & 1) vic3->sprites[i].repeat = 1;
1045               wrapped >>= 1;
1046               syend = 21 * 2 - 1 - wrapped * 2;
1047               if (syend > (yend - ybegin)) syend = yend - ybegin;
1048            }
1049            else
1050            {
1051               syend = 21 - 1 - wrapped;
1052               if (syend > (yend - ybegin)) syend = yend - ybegin;
1053            }
1054
1055            vic3->sprites[i].line = wrapped;
1056
1057            if (SPRITE_MULTICOLOR (i))
1058               vic3_draw_sprite_multi(device, i, 0, 0 , syend, start_x, end_x);
1059            else
1060               vic3_draw_sprite(device, i, 0, 0 , syend, start_x, end_x);
1061         }
1062         else if    (SPRITEON (i) &&
1063               (yoff + ybegin >= SPRITE_Y_POS (i)) &&
1064               (yoff + ybegin - SPRITE_Y_POS (i) < (SPRITE_Y_EXPAND (i)? 21 * 2 : 21 )) &&
1065               (SPRITE_Y_POS (i) >= 0))
1066         {
1067            int wrapped = yoff + ybegin - SPRITE_Y_POS (i);
1068
1069            syend = yend;
1070
1071            if (SPRITE_Y_EXPAND (i))
1072            {
1073               if (wrapped & 1) vic3->sprites[i].repeat = 1;
1074               wrapped >>= 1;
1075               syend = 21 * 2 - 1 - wrapped * 2;
1076               if (syend > (yend - ybegin)) syend = yend - ybegin;
1077            }
1078            else
1079            {
1080               syend = 21 - 1 - wrapped;
1081               if (syend > (yend - ybegin)) syend = yend - ybegin;
1082            }
1083
1084            vic3->sprites[i].line = wrapped;
1085
1086            if (SPRITE_MULTICOLOR (i))
1087               vic3_draw_sprite_multi(device, i, yoff + ybegin, 0, 0, start_x, end_x);
1088            else
1089               vic3_draw_sprite(device, i, yoff + ybegin, 0, 0, start_x, end_x);
1090         }
1091         else
1092         {
1093            memset (vic3->sprites[i].paintedline, 0, sizeof (vic3->sprites[i].paintedline));
1094         }
1095      }
1096      line += 1 + yend - ybegin;
4451097   }
446   if (VIC3_BITPLANES_MASK&0x40) {
447      colors[6]=c64_memory[VIC3_BITPLANE_ADDR(6)+offset];
1098
1099   // left border
1100   if ((start_x <= VIC2_STARTVISIBLECOLUMNS) && (end_x >= xbegin))
1101      plot_box(vic3->bitmap, VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, xbegin - VIC2_STARTVISIBLECOLUMNS, 1, FRAMECOLOR);
1102   else if ((start_x > VIC2_STARTVISIBLECOLUMNS) && (end_x >= xbegin))
1103      plot_box(vic3->bitmap, start_x, first + FIRSTLINE, xbegin - start_x, 1, FRAMECOLOR);
1104   else if ((start_x <= VIC2_STARTVISIBLECOLUMNS) && (end_x < xbegin))
1105      plot_box(vic3->bitmap, VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, end_x, 1, FRAMECOLOR);
1106   else if ((start_x > VIC2_STARTVISIBLECOLUMNS) && (end_x < xbegin))
1107      plot_box(vic3->bitmap, start_x, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
1108
1109   // right border
1110   if ((start_x <= xend) && (end_x >= VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS))
1111      plot_box(vic3->bitmap, xend, first + FIRSTLINE, VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS - xend, 1, FRAMECOLOR);
1112   else if ((start_x > xend) && (end_x >= VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS))
1113      plot_box(vic3->bitmap, start_x, first + FIRSTLINE, VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS - start_x, 1, FRAMECOLOR);
1114   else if ((start_x <= xend) && (end_x < VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS))
1115      plot_box(vic3->bitmap, xend, first + FIRSTLINE, end_x - xend, 1, FRAMECOLOR);
1116   else if ((start_x > VIC2_STARTVISIBLECOLUMNS) && (end_x < xbegin))
1117      plot_box(vic3->bitmap, start_x, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
1118
1119   if (first + 1 < vic3->bitmap->height)
1120      end = first + 1;
1121   else
1122      end = vic3->bitmap->height;
1123
1124   // bottom border
1125   if (line < end)
1126   {
1127      if ((start_x <= xbegin) && (end_x >= xend))
1128         plot_box(vic3->bitmap, xbegin, first + FIRSTLINE, xend - xbegin, 1, FRAMECOLOR);
1129      if ((start_x > xbegin) && (end_x >= xend))
1130         plot_box(vic3->bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, xend - start_x, 1, FRAMECOLOR);
1131      if ((start_x <= xbegin) && (end_x < xend))
1132         plot_box(vic3->bitmap, xbegin, first + FIRSTLINE, end_x - xbegin , 1, FRAMECOLOR);
1133      if ((start_x > xbegin) && (end_x < xend))
1134         plot_box(vic3->bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
1135      line = end;
4481136   }
449   if (VIC3_BITPLANES_MASK&0x80) {
450      colors[7]=c64_memory[VIC3_BITPLANE_ADDR(7)+offset];
451   }
4521137}
4531138
454INLINE void vic3_interlace_block_2_color(int offset, UINT8 colors[8])
1139/*****************************************************************************
1140    I/O HANDLERS
1141*****************************************************************************/
1142
1143WRITE8_DEVICE_HANDLER( vic3_palette_w )
4551144{
1145    vic3_state *vic3 = get_safe_token(device);
4561146
457   if (VIC3_BITPLANES_MASK&1) {
458      colors[0]=c64_memory[VIC3_BITPLANE_IADDR(0)+offset];
1147   if (offset < 0x100)
1148      vic3->palette_red[offset] = data;
1149   else if (offset < 0x200)
1150      vic3->palette_green[offset & 0xff] = data;
1151   else
1152      vic3->palette_blue[offset & 0xff] = data;
1153
1154   vic3->palette_dirty = 1;
1155}
1156
1157
1158WRITE8_DEVICE_HANDLER( vic3_port_w )
1159{
1160    vic3_state *vic3 = get_safe_token(device);
1161
1162   DBG_LOG(2, "vic write", ("%.2x:%.2x\n", offset, data));
1163   offset &= 0x7f;
1164
1165   /* offsets 0x00 -> 0x2e coincide with VICII */
1166   switch (offset)
1167   {
1168   case 0x01:
1169   case 0x03:
1170   case 0x05:
1171   case 0x07:
1172   case 0x09:
1173   case 0x0b:
1174   case 0x0d:
1175   case 0x0f:
1176                           /* sprite y positions */
1177      if (vic3->reg[offset] != data)
1178      {
1179         vic3->reg[offset] = data;
1180         vic3->sprites[offset / 2].y = SPRITE_Y_POS(offset / 2);
1181      }
1182      break;
1183
1184   case 0x00:
1185   case 0x02:
1186   case 0x04:
1187   case 0x06:
1188   case 0x08:
1189   case 0x0a:
1190   case 0x0c:
1191   case 0x0e:
1192                           /* sprite x positions */
1193      if (vic3->reg[offset] != data)
1194      {
1195         vic3->reg[offset] = data;
1196         vic3->sprites[offset / 2].x = SPRITE_X_POS(offset / 2);
1197      }
1198      break;
1199
1200   case 0x10:                     /* sprite x positions */
1201      if (vic3->reg[offset] != data)
1202      {
1203         vic3->reg[offset] = data;
1204         vic3->sprites[0].x = SPRITE_X_POS(0);
1205         vic3->sprites[1].x = SPRITE_X_POS(1);
1206         vic3->sprites[2].x = SPRITE_X_POS(2);
1207         vic3->sprites[3].x = SPRITE_X_POS(3);
1208         vic3->sprites[4].x = SPRITE_X_POS(4);
1209         vic3->sprites[5].x = SPRITE_X_POS(5);
1210         vic3->sprites[6].x = SPRITE_X_POS(6);
1211         vic3->sprites[7].x = SPRITE_X_POS(7);
1212      }
1213      break;
1214
1215   case 0x17:                     /* sprite y size */
1216      if (vic3->reg[offset] != data)
1217      {
1218         vic3->reg[offset] = data;
1219      }
1220      break;
1221
1222   case 0x1d:                     /* sprite x size */
1223      if (vic3->reg[offset] != data)
1224      {
1225         vic3->reg[offset] = data;
1226      }
1227      break;
1228
1229   case 0x1b:                     /* sprite background priority */
1230      if (vic3->reg[offset] != data)
1231      {
1232         vic3->reg[offset] = data;
1233      }
1234      break;
1235
1236   case 0x1c:                     /* sprite multicolor mode select */
1237      if (vic3->reg[offset] != data)
1238      {
1239         vic3->reg[offset] = data;
1240      }
1241      break;
1242
1243   case 0x27:
1244   case 0x28:
1245   case 0x29:
1246   case 0x2a:
1247   case 0x2b:
1248   case 0x2c:
1249   case 0x2d:
1250   case 0x2e:
1251                           /* sprite colors */
1252      if (vic3->reg[offset] != data)
1253      {
1254         vic3->reg[offset] = data;
1255      }
1256      break;
1257
1258   case 0x25:                     /* sprite multicolor */
1259      if (vic3->reg[offset] != data)
1260      {
1261         vic3->reg[offset] = data;
1262         vic3->spritemulti[1] = SPRITE_MULTICOLOR1;
1263      }
1264      break;
1265
1266   case 0x26:                     /* sprite multicolor */
1267      if (vic3->reg[offset] != data)
1268      {
1269         vic3->reg[offset] = data;
1270         vic3->spritemulti[3] = SPRITE_MULTICOLOR2;
1271      }
1272      break;
1273
1274   case 0x19:
1275      vic3_clear_interrupt(device->machine, data & 0x0f, vic3);
1276      break;
1277
1278   case 0x1a:                     /* irq mask */
1279      vic3->reg[offset] = data;
1280      vic3_set_interrupt(device->machine, 0, vic3);    // beamrider needs this
1281      break;
1282
1283   case 0x11:
1284      if (vic3->reg[offset] != data)
1285      {
1286         vic3->reg[offset] = data;
1287         if (LINES25)
1288         {
1289            vic3->y_begin = 0;
1290            vic3->y_end = vic3->y_begin + 200;
1291         }
1292         else
1293         {
1294            vic3->y_begin = 4;
1295            vic3->y_end = vic3->y_begin + 192;
1296         }
1297      }
1298      break;
1299
1300   case 0x12:
1301      if (data != vic3->reg[offset])
1302      {
1303         vic3->reg[offset] = data;
1304      }
1305      break;
1306
1307   case 0x16:
1308      if (vic3->reg[offset] != data)
1309      {
1310         vic3->reg[offset] = data;
1311         vic3->x_begin = HORIZONTALPOS;
1312         vic3->x_end = vic3->x_begin + 320;
1313      }
1314      break;
1315
1316   case 0x18:
1317      if (vic3->reg[offset] != data)
1318      {
1319         vic3->reg[offset] = data;
1320         vic3->videoaddr = VIDEOADDR;
1321         vic3->chargenaddr = CHARGENADDR;
1322         vic3->bitmapaddr = BITMAPADDR;
1323      }
1324      break;
1325
1326   case 0x21:                     /* background color */
1327      if (vic3->reg[offset] != data)
1328      {
1329         vic3->reg[offset] = data;
1330         vic3->mono[0] = vic3->bitmapmulti[0] = vic3->multi[0] = vic3->colors[0] = BACKGROUNDCOLOR;
1331      }
1332      break;
1333
1334   case 0x22:                     /* background color 1 */
1335      if (vic3->reg[offset] != data)
1336      {
1337         vic3->reg[offset] = data;
1338         vic3->multi[1] = vic3->colors[1] = MULTICOLOR1;
1339      }
1340      break;
1341
1342   case 0x23:                     /* background color 2 */
1343      if (vic3->reg[offset] != data)
1344      {
1345         vic3->reg[offset] = data;
1346         vic3->multi[2] = vic3->colors[2] = MULTICOLOR2;
1347      }
1348      break;
1349
1350   case 0x24:                     /* background color 3 */
1351      if (vic3->reg[offset] != data)
1352      {
1353         vic3->reg[offset] = data;
1354         vic3->colors[3] = FOREGROUNDCOLOR;
1355      }
1356      break;
1357
1358   case 0x20:                     /* framecolor */
1359      if (vic3->reg[offset] != data)
1360      {
1361         vic3->reg[offset] = data;
1362      }
1363      break;
1364
1365   case 0x2f:
1366      DBG_LOG(2, "vic write", ("%.2x:%.2x\n", offset, data));
1367      vic3->reg[offset] = data;
1368      break;
1369   case 0x30:
1370      vic3->reg[offset] = data;
1371      if (vic3->port_changed!=NULL) {
1372         DBG_LOG(2, "vic write", ("%.2x:%.2x\n", offset, data));
1373         vic3->reg[offset] = data;
1374         vic3->port_changed(device->machine, data);
1375      }
1376      break;
1377   case 0x31:
1378      vic3->reg[offset] = data;
1379      if (data & 0x40)
1380         cpu_set_clockscale(vic3->cpu, 1.0);
1381      else
1382         cpu_set_clockscale(vic3->cpu, 1.0/3.5);
1383      break;
1384   case 0x32:
1385   case 0x33:
1386   case 0x34:
1387   case 0x35:
1388   case 0x36:
1389   case 0x37:
1390   case 0x38:
1391   case 0x39:
1392   case 0x3a:
1393   case 0x3b:
1394   case 0x3c:
1395   case 0x3d:
1396   case 0x3e:
1397   case 0x3f:
1398      vic3->reg[offset] = data;
1399      DBG_LOG(2, "vic write", ("%.2x:%.2x\n", offset, data));
1400      break;
1401   case 0x40:
1402   case 0x41:
1403   case 0x42:
1404   case 0x43:
1405   case 0x44:
1406   case 0x45:
1407   case 0x46:
1408   case 0x47:
1409      DBG_LOG(2, "vic plane write", ("%.2x:%.2x\n", offset, data));
1410      break;
1411   default:
1412      vic3->reg[offset] = data;
1413      break;
4591414   }
460   if (VIC3_BITPLANES_MASK&2) {
461      colors[1]=c64_memory[VIC3_BITPLANE_IADDR(1)+offset];
462   }
463   if (VIC3_BITPLANES_MASK&4) {
464      colors[2]=c64_memory[VIC3_BITPLANE_IADDR(2)+offset];
465   }
466   if (VIC3_BITPLANES_MASK&8) {
467      colors[3]=c64_memory[VIC3_BITPLANE_IADDR(3)+offset];
468   }
469   if (VIC3_BITPLANES_MASK&0x10) {
470      colors[4]=c64_memory[VIC3_BITPLANE_IADDR(4)+offset];
471   }
472   if (VIC3_BITPLANES_MASK&0x20) {
473      colors[5]=c64_memory[VIC3_BITPLANE_IADDR(5)+offset];
474   }
475   if (VIC3_BITPLANES_MASK&0x40) {
476      colors[6]=c64_memory[VIC3_BITPLANE_IADDR(6)+offset];
477   }
478   if (VIC3_BITPLANES_MASK&0x80) {
479      colors[7]=c64_memory[VIC3_BITPLANE_IADDR(7)+offset];
480   }
4811415}
4821416
483INLINE void vic3_draw_block(int x, int y, UINT8 colors[8])
1417READ8_DEVICE_HANDLER( vic3_port_r )
4841418{
485   vic2.bitmap->line[YPOS+y][XPOS+x]=
486      vic3_bitplane_to_packed(colors, vic2.reg[0x32], 7);
487   vic2.bitmap->line[YPOS+y][XPOS+x+1]=
488      vic3_bitplane_to_packed(colors, vic2.reg[0x32], 6);
489   vic2.bitmap->line[YPOS+y][XPOS+x+2]=
490      vic3_bitplane_to_packed(colors, vic2.reg[0x32], 5);
491   vic2.bitmap->line[YPOS+y][XPOS+x+3]=
492      vic3_bitplane_to_packed(colors, vic2.reg[0x32], 4);
493   vic2.bitmap->line[YPOS+y][XPOS+x+4]=
494      vic3_bitplane_to_packed(colors, vic2.reg[0x32], 3);
495   vic2.bitmap->line[YPOS+y][XPOS+x+5]=
496      vic3_bitplane_to_packed(colors, vic2.reg[0x32], 2);
497   vic2.bitmap->line[YPOS+y][XPOS+x+6]=
498      vic3_bitplane_to_packed(colors, vic2.reg[0x32], 1);
499   vic2.bitmap->line[YPOS+y][XPOS+x+7]=
500      vic3_bitplane_to_packed(colors, vic2.reg[0x32], 0);
1419    vic3_state *vic3 = get_safe_token(device);
1420   int val = 0;
1421   offset &= 0x7f;
1422
1423   /* offsets 0x00 -> 0x2e coincide with VICII */
1424   switch (offset)
1425   {
1426   case 0x11:
1427      val = (vic3->reg[offset] & ~0x80) | ((vic3->rasterline & 0x100) >> 1);
1428      break;
1429
1430   case 0x12:
1431      val = vic3->rasterline & 0xff;
1432      break;
1433
1434   case 0x16:
1435      val = vic3->reg[offset] | 0xc0;
1436      break;
1437
1438   case 0x18:
1439      val = vic3->reg[offset] | 0x01;
1440      break;
1441
1442   case 0x19:                     /* interrupt flag register */
1443      /* vic2_clear_interrupt(0xf); */
1444      val = vic3->reg[offset] | 0x70;
1445      break;
1446
1447   case 0x1a:
1448      val = vic3->reg[offset] | 0xf0;
1449      break;
1450
1451   case 0x1e:                     /* sprite to sprite collision detect */
1452      val = vic3->reg[offset];
1453      vic3->reg[offset] = 0;
1454      vic3_clear_interrupt(device->machine, 4, vic3);
1455      break;
1456
1457   case 0x1f:                     /* sprite to background collision detect */
1458      val = vic3->reg[offset];
1459      vic3->reg[offset] = 0;
1460      vic3_clear_interrupt(device->machine, 2, vic3);
1461      break;
1462
1463   case 0x20:
1464   case 0x21:
1465   case 0x22:
1466   case 0x23:
1467   case 0x24:
1468      val = vic3->reg[offset];
1469      break;
1470
1471   case 0x00:
1472   case 0x01:
1473   case 0x02:
1474   case 0x03:
1475   case 0x04:
1476   case 0x05:
1477   case 0x06:
1478   case 0x07:
1479   case 0x08:
1480   case 0x09:
1481   case 0x0a:
1482   case 0x0b:
1483   case 0x0c:
1484   case 0x0d:
1485   case 0x0e:
1486   case 0x0f:
1487   case 0x10:
1488   case 0x17:
1489   case 0x1b:
1490   case 0x1c:
1491   case 0x1d:
1492   case 0x25:
1493   case 0x26:
1494   case 0x27:
1495   case 0x28:
1496   case 0x29:
1497   case 0x2a:
1498   case 0x2b:
1499   case 0x2c:
1500   case 0x2d:
1501   case 0x2e:
1502      val = vic3->reg[offset];
1503      break;
1504
1505   case 0x2f:
1506   case 0x30:
1507      val = vic3->reg[offset];
1508      DBG_LOG(2, "vic read", ("%.2x:%.2x\n", offset, val));
1509      break;
1510   case 0x31:
1511   case 0x32:
1512   case 0x33:
1513   case 0x34:
1514   case 0x35:
1515   case 0x36:
1516   case 0x37:
1517   case 0x38:
1518   case 0x39:
1519   case 0x3a:
1520   case 0x3b:
1521   case 0x3c:
1522   case 0x3d:
1523   case 0x3e:
1524   case 0x3f:                     /* not used */
1525      val = vic3->reg[offset];
1526      DBG_LOG(2, "vic read", ("%.2x:%.2x\n", offset, val));
1527      break;
1528   case 0x40:
1529   case 0x41:
1530   case 0x42:
1531   case 0x43:
1532   case 0x44:
1533   case 0x45:
1534   case 0x46:
1535   case 0x47:
1536      DBG_LOG(2, "vic3 plane read", ("%.2x:%.2x\n", offset, val));
1537      break;
1538   default:
1539      val = vic3->reg[offset];
1540   }
1541   return val;
5011542}
5021543
503#else
504/* very recognizable SPEED improvement */
1544
5051545#define VIC3_MASK(M)                                            \
5061546    if (M)                                                      \
5071547    {                                                           \
508        if (M & 0x01)                                    \
509            colors[0] = c64_memory[VIC3_ADDR(0)+offset];        \
1548        if (M & 0x01)                                           \
1549            colors[0] = vic3->c64_mem_r(VIC3_ADDR(0) + offset);        \
5101550        if (M & 0x02)                                           \
511            colors[1] = c64_memory[VIC3_ADDR(1)+offset]<<1;     \
512        if (M & 0x04)                                    \
513            colors[2] = c64_memory[VIC3_ADDR(2)+offset]<<2;     \
1551            colors[1] = vic3->c64_mem_r(VIC3_ADDR(1) + offset) << 1;     \
1552        if (M & 0x04)                                           \
1553            colors[2] = vic3->c64_mem_r(VIC3_ADDR(2) + offset) << 2;     \
5141554        if (M & 0x08)                                           \
515            colors[3] = c64_memory[VIC3_ADDR(3)+offset]<<3;     \
1555            colors[3] = vic3->c64_mem_r(VIC3_ADDR(3) + offset) << 3;     \
5161556        if (M & 0x10)                                           \
517            colors[4] = c64_memory[VIC3_ADDR(4)+offset]<<4;     \
1557            colors[4] = vic3->c64_mem_r(VIC3_ADDR(4) + offset) << 4;     \
5181558        if (M & 0x20)                                           \
519            colors[5] = c64_memory[VIC3_ADDR(5)+offset]<<5;     \
1559            colors[5] = vic3->c64_mem_r(VIC3_ADDR(5) + offset) << 5;     \
5201560        if (M & 0x40)                                           \
521            colors[6] = c64_memory[VIC3_ADDR(6)+offset]<<6;     \
1561            colors[6] = vic3->c64_mem_r(VIC3_ADDR(6) + offset) << 6;     \
5221562        if (M & 0x80)                                           \
523            colors[7] = c64_memory[VIC3_ADDR(7)+offset]<<7;     \
524        for (i=7; i >= 0; i--)                                  \
1563            colors[7] = vic3->c64_mem_r(VIC3_ADDR(7) + offset) << 7;     \
1564        for (i = 7; i >= 0; i--)                                \
5251565        {                                                       \
5261566            p = 0;                                              \
527            if (M & 0x01)                                \
1567            if (M & 0x01)                                       \
5281568            {                                                   \
5291569                p = colors[0] & 0x01;                           \
5301570                colors[0] >>= 1;                                \
5311571            }                                                   \
5321572            if (M & 0x02)                                       \
5331573            {                                                   \
534                p |= colors[1] & 0x02;                      \
1574                p |= colors[1] & 0x02;                          \
5351575                colors[1] >>= 1;                                \
5361576            }                                                   \
5371577            if (M & 0x04)                                       \
5381578            {                                                   \
539                p |= colors[2] & 0x04;                      \
1579                p |= colors[2] & 0x04;                          \
5401580                colors[2] >>= 1;                                \
5411581            }                                                   \
5421582            if (M & 0x08)                                       \
5431583            {                                                   \
544                p |= colors[3] & 0x08;                      \
1584                p |= colors[3] & 0x08;                          \
5451585                colors[3] >>= 1;                                \
5461586            }                                                   \
5471587            if (M & 0x10)                                       \
5481588            {                                                   \
549                p |= colors[4] & 0x10;                      \
1589                p |= colors[4] & 0x10;                          \
5501590                colors[4] >>= 1;                                \
5511591            }                                                   \
5521592            if (M & 0x20)                                       \
5531593            {                                                   \
554                p |= colors[5] & 0x20;                      \
1594                p |= colors[5] & 0x20;                          \
5551595                colors[5] >>= 1;                                \
5561596            }                                                   \
5571597            if (M & 0x40)                                       \
5581598            {                                                   \
559                p |= colors[6] & 0x40;                      \
1599                p |= colors[6] & 0x40;                          \
5601600                colors[6] >>= 1;                                \
5611601            }                                                   \
5621602            if (M & 0x80)                                       \
5631603            {                                                   \
564                p |= colors[7] & 0x80;                      \
1604                p |= colors[7] & 0x80;                          \
5651605                colors[7] >>= 1;                                \
5661606            }                                                   \
567            *BITMAP_ADDR16(vic2.bitmap, YPOS+y, XPOS+x+i) = p; \
1607            *BITMAP_ADDR16(vic3->bitmap, YPOS + y, XPOS + x + i) = p; \
5681608        }                                                       \
5691609    }
5701610
5711611#define VIC3_ADDR(a) VIC3_BITPLANE_IADDR(a)
572static void vic3_interlace_draw_block(running_machine *machine, int x, int y, int offset)
1612static void vic3_interlace_draw_block( running_device *device, int x, int y, int offset )
5731613{
574   int colors[8]={0};
1614    vic3_state *vic3 = get_safe_token(device);
1615   int colors[8] = {0};
5751616   int i, p;
5761617
577   switch (VIC3_BITPLANES_MASK) {
1618   switch (VIC3_BITPLANES_MASK)
1619   {
5781620   case 0x05:
5791621      VIC3_MASK(0x05)
5801622      break;
581    case 0x07:
1623   case 0x07:
5821624      VIC3_MASK(0x07)
5831625      break;
584    case 0x0f:
1626   case 0x0f:
5851627      VIC3_MASK(0x0f)
5861628      break;
587    case 0x1f:
1629   case 0x1f:
5881630      VIC3_MASK(0x1f)
5891631      break;
590    case 0x7f:
1632   case 0x7f:
5911633      VIC3_MASK(0x7f)
5921634      break;
593    case 0xff:
1635   case 0xff:
5941636      VIC3_MASK(0xff)
5951637      break;
5961638   default:
597      if (VIC3_BITPLANES_MASK&1) {
598         colors[0]=c64_memory[VIC3_BITPLANE_IADDR(0)+offset];
1639      if (VIC3_BITPLANES_MASK & 0x01)
1640         colors[0] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(0) + offset);
1641
1642      if (VIC3_BITPLANES_MASK & 0x02)
1643         colors[1] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(1) + offset) << 1;
1644
1645      if (VIC3_BITPLANES_MASK & 0x04)
1646         colors[2] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(2) + offset) << 2;
1647
1648      if (VIC3_BITPLANES_MASK & 0x08)
1649         colors[3] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(3) + offset) << 3;
1650
1651      if (VIC3_BITPLANES_MASK & 0x10)
1652         colors[4] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(4) + offset) << 4;
1653
1654      if (VIC3_BITPLANES_MASK & 0x20)
1655         colors[5] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(5) + offset) << 5;
1656
1657      if (VIC3_BITPLANES_MASK & 0x40)
1658         colors[6] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(6) + offset) << 6;
1659
1660      if (VIC3_BITPLANES_MASK & 0x80)
1661         colors[7] = vic3->c64_mem_r(VIC3_BITPLANE_IADDR(7) + offset) << 7;
1662
1663      for (i = 7; i >= 0; i--)
1664      {
1665         *BITMAP_ADDR16(vic3->bitmap, YPOS + y, XPOS + x + i) =
1666            (colors[0] & 0x01) | (colors[1] & 0x02)
1667                      | (colors[2] & 0x04) | (colors[3] & 0x08)
1668                      | (colors[4] & 0x10) | (colors[5] & 0x20)
1669                      | (colors[6] & 0x40) | (colors[7] & 0x80);
1670         colors[0] >>= 1;
1671         colors[1] >>= 1;
1672         colors[2] >>= 1;
1673         colors[3] >>= 1;
1674         colors[4] >>= 1;
1675         colors[5] >>= 1;
1676         colors[6] >>= 1;
1677         colors[7] >>= 1;
5991678      }
600      if (VIC3_BITPLANES_MASK&2) {
601         colors[1]=c64_memory[VIC3_BITPLANE_IADDR(1)+offset]<<1;
602      }
603      if (VIC3_BITPLANES_MASK&4) {
604         colors[2]=c64_memory[VIC3_BITPLANE_IADDR(2)+offset]<<2;
605      }
606      if (VIC3_BITPLANES_MASK&8) {
607         colors[3]=c64_memory[VIC3_BITPLANE_IADDR(3)+offset]<<3;
608      }
609      if (VIC3_BITPLANES_MASK&0x10) {
610         colors[4]=c64_memory[VIC3_BITPLANE_IADDR(4)+offset]<<4;
611      }
612      if (VIC3_BITPLANES_MASK&0x20) {
613         colors[5]=c64_memory[VIC3_BITPLANE_IADDR(5)+offset]<<5;
614      }
615      if (VIC3_BITPLANES_MASK&0x40) {
616         colors[6]=c64_memory[VIC3_BITPLANE_IADDR(6)+offset]<<6;
617      }
618      if (VIC3_BITPLANES_MASK&0x80) {
619         colors[7]=c64_memory[VIC3_BITPLANE_IADDR(7)+offset]<<7;
620      }
621      for (i=7;i>=0;i--) {
622         *BITMAP_ADDR16(vic2.bitmap, YPOS+y, XPOS+x+i) =
623            (colors[0]&1)|(colors[1]&2)
624                      |(colors[2]&4)|(colors[3]&8)
625                      |(colors[4]&0x10)|(colors[5]&0x20)
626                      |(colors[6]&0x40)|(colors[7]&0x80);
627         colors[0]>>=1;
628         colors[1]>>=1;
629         colors[2]>>=1;
630         colors[3]>>=1;
631         colors[4]>>=1;
632         colors[5]>>=1;
633         colors[6]>>=1;
634         colors[7]>>=1;
635      }
6361679   }
6371680}
6381681
6391682#undef VIC3_ADDR
6401683#define VIC3_ADDR(a) VIC3_BITPLANE_ADDR(a)
641static void vic3_draw_block(running_machine *machine, int x, int y, int offset)
1684static void vic3_draw_block( running_device *device, int x, int y, int offset )
6421685{
643   int colors[8]={0};
1686    vic3_state *vic3 = get_safe_token(device);
1687   int colors[8] = {0};
6441688   int i, p;
6451689
646   switch (VIC3_BITPLANES_MASK) {
1690   switch (VIC3_BITPLANES_MASK)
1691   {
6471692   case 5:
6481693      VIC3_MASK(0x05)
6491694      break;
6501695   case 7:
6511696      VIC3_MASK(0x07)
652        break;
1697      break;
6531698   case 0xf:
6541699      VIC3_MASK(0x0f)
655        break;
1700      break;
6561701   case 0x1f:
6571702      VIC3_MASK(0x1f)
658        break;
1703      break;
6591704   case 0x7f:
6601705      VIC3_MASK(0x7f)
661        break;
1706      break;
6621707   case 0xff:
6631708      VIC3_MASK(0xff)
664        break;
1709      break;
6651710   default:
666      if (VIC3_BITPLANES_MASK&1) {
667         colors[0]=c64_memory[VIC3_BITPLANE_ADDR(0)+offset];
1711      if (VIC3_BITPLANES_MASK & 0x01)
1712         colors[0] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(0) + offset);
1713
1714      if (VIC3_BITPLANES_MASK & 0x02)
1715         colors[1] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(1) + offset) << 1;
1716
1717      if (VIC3_BITPLANES_MASK & 0x04)
1718         colors[2] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(2) + offset) << 2;
1719
1720      if (VIC3_BITPLANES_MASK & 0x08)
1721         colors[3] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(3) + offset) << 3;
1722
1723      if (VIC3_BITPLANES_MASK & 0x10)
1724         colors[4] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(4) + offset) << 4;
1725
1726      if (VIC3_BITPLANES_MASK & 0x20)
1727         colors[5] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(5) + offset) << 5;
1728
1729      if (VIC3_BITPLANES_MASK & 0x40)
1730         colors[6] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(6) + offset) << 6;
1731
1732      if (VIC3_BITPLANES_MASK & 0x80)
1733         colors[7] = vic3->c64_mem_r(VIC3_BITPLANE_ADDR(7) + offset) << 7;
1734
1735      for (i = 7; i >= 0; i--)
1736      {
1737         *BITMAP_ADDR16(vic3->bitmap, YPOS + y, XPOS + x + i) =
1738            (colors[0] & 0x01) | (colors[1] & 0x02)
1739                      | (colors[2] & 0x04) | (colors[3] & 0x08)
1740                      | (colors[4] & 0x10) | (colors[5] & 0x20)
1741                      | (colors[6] & 0x40) | (colors[7] & 0x80);
1742         colors[0] >>= 1;
1743         colors[1] >>= 1;
1744         colors[2] >>= 1;
1745         colors[3] >>= 1;
1746         colors[4] >>= 1;
1747         colors[5] >>= 1;
1748         colors[6] >>= 1;
1749         colors[7] >>= 1;
6681750      }
669      if (VIC3_BITPLANES_MASK&2) {
670         colors[1]=c64_memory[VIC3_BITPLANE_ADDR(1)+offset]<<1;
671      }
672      if (VIC3_BITPLANES_MASK&4) {
673         colors[2]=c64_memory[VIC3_BITPLANE_ADDR(2)+offset]<<2;
674      }
675      if (VIC3_BITPLANES_MASK&8) {
676         colors[3]=c64_memory[VIC3_BITPLANE_ADDR(3)+offset]<<3;
677      }
678      if (VIC3_BITPLANES_MASK&0x10) {
679         colors[4]=c64_memory[VIC3_BITPLANE_ADDR(4)+offset]<<4;
680      }
681      if (VIC3_BITPLANES_MASK&0x20) {
682         colors[5]=c64_memory[VIC3_BITPLANE_ADDR(5)+offset]<<5;
683      }
684      if (VIC3_BITPLANES_MASK&0x40) {
685         colors[6]=c64_memory[VIC3_BITPLANE_ADDR(6)+offset]<<6;
686      }
687      if (VIC3_BITPLANES_MASK&0x80) {
688         colors[7]=c64_memory[VIC3_BITPLANE_ADDR(7)+offset]<<7;
689      }
690      for (i=7;i>=0;i--) {
691         *BITMAP_ADDR16(vic2.bitmap, YPOS+y, XPOS+x+i) =
692            (colors[0]&1)|(colors[1]&2)
693                      |(colors[2]&4)|(colors[3]&8)
694                      |(colors[4]&0x10)|(colors[5]&0x20)
695                      |(colors[6]&0x40)|(colors[7]&0x80);
696         colors[0]>>=1;
697         colors[1]>>=1;
698         colors[2]>>=1;
699         colors[3]>>=1;
700         colors[4]>>=1;
701         colors[5]>>=1;
702         colors[6]>>=1;
703         colors[7]>>=1;
704      }
7051751   }
7061752}
707#endif
7081753
709static void vic3_draw_bitplanes(running_machine *machine)
1754
1755static void vic3_draw_bitplanes( running_device *device )
7101756{
711   static int interlace=0;
1757    vic3_state *vic3 = get_safe_token(device);
7121758   int x, y, y1s, offset;
713#ifndef OPTIMIZE
714   UINT8 colors[8];
715#endif
7161759   rectangle vis;
717   running_device *screen = video_screen_first(machine);
718   const rectangle *visarea = video_screen_get_visible_area(screen);
1760   const rectangle *visarea = video_screen_get_visible_area(vic3->main_screen);
7191761
720   if (VIC3_LINES==400) { /* interlaced! */
721      for ( y1s=0, offset=0; y1s<400; y1s+=16) {
722         for (x=0; x<VIC3_BITPLANES_WIDTH; x+=8) {
723            for ( y=y1s; y<y1s+16; y+=2, offset++) {
724#ifndef OPTIMIZE
725               if (interlace) {
726                  vic3_block_2_color(offset,colors);
727                  vic3_draw_block(machine,x,y,colors);
728               } else {
729                  vic3_interlace_block_2_color(offset,colors);
730                  vic3_draw_block(machine,x,y+1,colors);
731               }
732#else
733               if (interlace)
734                  vic3_draw_block(machine,x,y,offset);
1762   if (VIC3_LINES == 400)
1763   { /* interlaced! */
1764      for (y1s = 0, offset = 0; y1s < 400; y1s += 16)
1765      {
1766         for (x = 0; x < VIC3_BITPLANES_WIDTH; x += 8)
1767         {
1768            for (y = y1s; y < y1s + 16; y += 2, offset++)
1769            {
1770               if (vic3->interlace)
1771                  vic3_draw_block(device, x, y, offset);
7351772               else
736                  vic3_interlace_draw_block(machine,x,y+1,offset);
737#endif
1773                  vic3_interlace_draw_block(device, x, y + 1, offset);
7381774            }
7391775         }
7401776      }
741      interlace^=1;
742   } else {
743      for ( y1s=0, offset=0; y1s<200; y1s+=8) {
744         for (x=0; x<VIC3_BITPLANES_WIDTH; x+=8) {
745            for ( y=y1s; y<y1s+8; y++, offset++) {
746#ifndef OPTIMIZE
747               vic3_block_2_color(offset,colors);
748               vic3_draw_block(machine,x,y,colors);
749#else
750               vic3_draw_block(machine,x,y,offset);
751#endif
1777      vic3->interlace ^= 1;
1778   }
1779   else
1780   {
1781      for (y1s = 0, offset = 0; y1s < 200; y1s += 8)
1782      {
1783         for (x = 0; x < VIC3_BITPLANES_WIDTH; x += 8)
1784         {
1785            for (y = y1s; y < y1s + 8; y++, offset++)
1786            {
1787               vic3_draw_block(device, x, y, offset);
7521788            }
7531789         }
7541790      }
7551791   }
756   if (XPOS>0) {
1792
1793   if (XPOS > 0)
1794   {
7571795      vis.min_x = 0;
758      vis.max_x = XPOS-1;
1796      vis.max_x = XPOS - 1;
7591797      vis.min_y = 0;
7601798      vis.max_y = visarea->max_y;
761      bitmap_fill(vic2.bitmap, &vis,FRAMECOLOR);
1799      bitmap_fill(vic3->bitmap, &vis, FRAMECOLOR);
7621800   }
763   if (XPOS+VIC3_BITPLANES_WIDTH<visarea->max_x) {
764      vis.min_x = XPOS+VIC3_BITPLANES_WIDTH;
1801
1802   if (XPOS + VIC3_BITPLANES_WIDTH < visarea->max_x)
1803   {
1804      vis.min_x = XPOS + VIC3_BITPLANES_WIDTH;
7651805      vis.max_x = visarea->max_x;
7661806      vis.min_y = 0;
7671807      vis.max_y = visarea->max_y;
768      bitmap_fill(vic2.bitmap, &vis,FRAMECOLOR);
1808      bitmap_fill(vic3->bitmap, &vis, FRAMECOLOR);
7691809   }
770   if (YPOS>0)
1810
1811   if (YPOS > 0)
7711812   {
7721813      vis.min_y = 0;
773      vis.max_y = YPOS-1;
1814      vis.max_y = YPOS - 1;
7741815      vis.min_x = 0;
7751816      vis.max_x = visarea->max_x;
776      bitmap_fill(vic2.bitmap, &vis,FRAMECOLOR);
1817      bitmap_fill(vic3->bitmap, &vis, FRAMECOLOR);
7771818   }
778   if (YPOS+VIC3_LINES<visarea->max_y) {
779      vis.min_y = YPOS+VIC3_LINES;
1819
1820   if (YPOS + VIC3_LINES < visarea->max_y)
1821   {
1822      vis.min_y = YPOS + VIC3_LINES;
7801823      vis.max_y = visarea->max_y;
7811824      vis.min_x = 0;
7821825      vis.max_x = visarea->max_x;
783      bitmap_fill(vic2.bitmap, &vis,FRAMECOLOR);
1826      bitmap_fill(vic3->bitmap, &vis, FRAMECOLOR);
7841827   }
7851828}
7861829
787INTERRUPT_GEN( vic3_raster_irq )
1830void vic3_raster_interrupt_gen( running_device *device )
7881831{
789   static int columns = 640, raws = 200;
790   int new_columns, new_raws;
1832    vic3_state *vic3 = get_safe_token(device);
1833   running_machine *machine = device->machine;
1834   int new_columns, new_rows;
7911835   int i;
792   running_machine *machine = device->machine;
7931836
794   vic2.rasterline++;
795   if (vic2.rasterline >= vic2.lines)
1837   vic3->rasterline++;
1838   if (vic3->rasterline >= vic3->lines)
7961839   {
797      vic2.rasterline = 0;
798      if (vic3.palette_dirty)
799         for (i=0; i<256; i++)
800            palette_set_color_rgb(machine, i,vic3.palette[i].red<<4, vic3.palette[i].green<<4, vic3.palette[i].blue<<4);
1840      vic3->rasterline = 0;
1841      if (vic3->palette_dirty)
1842         for (i = 0; i < 256; i++)
1843            palette_set_color_rgb(machine, i, vic3->palette_red[i] << 4, vic3->palette_green[i] << 4, vic3->palette_blue[i] << 4);
8011844
802      if (vic3.palette_dirty) {
803         vic2.spritemulti[1] = SPRITE_MULTICOLOR1;
804         vic2.spritemulti[3] = SPRITE_MULTICOLOR2;
805         vic2.mono[0] = vic2.bitmapmulti[0] = vic2.multi[0] = vic2.colors[0] = BACKGROUNDCOLOR;
806         vic2.multi[1] = vic2.colors[1] = MULTICOLOR1;
807         vic2.multi[2] = vic2.colors[2] = MULTICOLOR2;
808         vic2.colors[3] = FOREGROUNDCOLOR;
809         vic3.palette_dirty = 0;
1845      if (vic3->palette_dirty)
1846      {
1847         vic3->spritemulti[1] = SPRITE_MULTICOLOR1;
1848         vic3->spritemulti[3] = SPRITE_MULTICOLOR2;
1849         vic3->mono[0] = vic3->bitmapmulti[0] = vic3->multi[0] = vic3->colors[0] = BACKGROUNDCOLOR;
1850         vic3->multi[1] = vic3->colors[1] = MULTICOLOR1;
1851         vic3->multi[2] = vic3->colors[2] = MULTICOLOR2;
1852         vic3->colors[3] = FOREGROUNDCOLOR;
1853         vic3->palette_dirty = 0;
8101854      }
811      new_raws=200;
1855
1856      new_rows = 200;
1857
8121858      if (VIC3_BITPLANES)
8131859      {
814         new_columns=VIC3_BITPLANES_WIDTH;
1860         new_columns = VIC3_BITPLANES_WIDTH;
8151861         if (new_columns < 320)
8161862            new_columns = 320; /*sprites resolution about 320x200 */
817         new_raws=VIC3_LINES;
1863         new_rows = VIC3_LINES;
8181864      }
8191865      else if (VIC3_80COLUMNS)
8201866      {
821         new_columns=640;
1867         new_columns = 640;
8221868      }
8231869      else
8241870      {
825         new_columns=320;
1871         new_columns = 320;
8261872      }
827      if ((new_columns!=columns)||(new_raws!=raws))
1873      if ((new_columns != vic3->columns) || (new_rows != vic3->rows))
8281874      {
829         raws=new_raws;
830         columns=new_columns;
831         if (c64_pal)
832            video_screen_set_visarea(   machine->primary_screen,
1875         vic3->rows = new_rows;
1876         vic3->columns = new_columns;
1877         if (vic3->type == VIC4567_PAL)
1878            video_screen_set_visarea(   vic3->main_screen,
8331879                           VIC2_STARTVISIBLECOLUMNS + 32,
834                           VIC2_STARTVISIBLECOLUMNS + 32 + columns + 16 - 1,
1880                           VIC2_STARTVISIBLECOLUMNS + 32 + vic3->columns + 16 - 1,
8351881                           VIC2_STARTVISIBLELINES + 34,
836                           VIC2_STARTVISIBLELINES + 34 + raws + 16 - 1);
1882                           VIC2_STARTVISIBLELINES + 34 + vic3->rows + 16 - 1);
8371883         else
838            video_screen_set_visarea(   machine->primary_screen,
1884            video_screen_set_visarea(   vic3->main_screen,
8391885                           VIC2_STARTVISIBLECOLUMNS + 34,
840                           VIC2_STARTVISIBLECOLUMNS + 34 + columns + 16 - 1,
1886                           VIC2_STARTVISIBLECOLUMNS + 34 + vic3->columns + 16 - 1,
8411887                           VIC2_STARTVISIBLELINES + 10,
842                           VIC2_STARTVISIBLELINES + 10 + raws + 16 - 1);
1888                           VIC2_STARTVISIBLELINES + 10 + vic3->rows + 16 - 1);
8431889      }
8441890      if (VIC3_BITPLANES)
8451891      {
846         if (!video_skip_this_frame ())
847            vic3_draw_bitplanes(device->machine);
848      } else {
849         if (c64_pal)
1892         vic3_draw_bitplanes(device);
1893      }
1894      else
1895      {
1896         if (vic3->type == VIC4567_PAL)
8501897         {
851            if (vic2.on) vic2_drawlines (device->machine, vic2.lastline, vic2.lines, VIC2_STARTVISIBLECOLUMNS + 32, VIC2_STARTVISIBLECOLUMNS + 32 + columns + 16 - 1);
1898            if (vic3->on)
1899               vic2_drawlines(device, vic3->lastline, vic3->lines, VIC2_STARTVISIBLECOLUMNS + 32, VIC2_STARTVISIBLECOLUMNS + 32 + vic3->columns + 16 - 1);
8521900         }
8531901         else
8541902         {
855            if (vic2.on) vic2_drawlines (device->machine, vic2.lastline, vic2.lines, VIC2_STARTVISIBLECOLUMNS + 34, VIC2_STARTVISIBLECOLUMNS + 34 + columns + 16 - 1);
1903            if (vic3->on)
1904               vic2_drawlines(device, vic3->lastline, vic3->lines, VIC2_STARTVISIBLECOLUMNS + 34, VIC2_STARTVISIBLECOLUMNS + 34 + vic3->columns + 16 - 1);
8561905         }
8571906      }
1907
8581908      for (i = 0; i < 8; i++)
859         vic2.sprites[i].repeat = vic2.sprites[i].line = 0;
860      vic2.lastline = 0;
1909         vic3->sprites[i].repeat = vic3->sprites[i].line = 0;
1910
1911      vic3->lastline = 0;
1912
8611913      if (LIGHTPEN_BUTTON)
8621914      {
863         /* lightpen timer starten */
864         timer_set (device->machine, attotime_make(0, 0), NULL, 1, vic2_timer_timeout);
1915         /* lightpen timer start */
1916         timer_set(machine, attotime_make(0, 0), vic3, 1, vic3_timer_timeout);
8651917      }
866      //state_display(vic2.bitmap);
1918
8671919   }
868   if (vic2.rasterline == C64_2_RASTERLINE (RASTERLINE))
1920
1921   if (vic3->rasterline == C64_2_RASTERLINE(RASTERLINE))
8691922   {
870      vic2_set_interrupt (device->machine, 1);
1923      vic3_set_interrupt(machine, 1, vic3);
8711924   }
872   if (vic2.on)
873      if ((vic2.rasterline >= VIC2_FIRSTRASTERLINE) && (vic2.rasterline < (VIC2_FIRSTRASTERLINE + VIC2_VISIBLELINES)))
1925
1926   if (vic3->on)
1927      if ((vic3->rasterline >= VIC2_FIRSTRASTERLINE) && (vic3->rasterline < (VIC2_FIRSTRASTERLINE + VIC2_VISIBLELINES)))
8741928      {
875         if (c64_pal)
1929         if (vic3->type == VIC4567_PAL)
8761930         {
877            if (vic2.on) vic2_drawlines (device->machine, vic2.rasterline-1, vic2.rasterline, VIC2_STARTVISIBLECOLUMNS + 32, VIC2_STARTVISIBLECOLUMNS + 32 + columns + 16 - 1);
1931            if (vic3->on)
1932               vic2_drawlines(device, vic3->rasterline - 1, vic3->rasterline, VIC2_STARTVISIBLECOLUMNS + 32, VIC2_STARTVISIBLECOLUMNS + 32 + vic3->columns + 16 - 1);
8781933         }
8791934         else
8801935         {
881            if (vic2.on) vic2_drawlines (device->machine, vic2.rasterline-1, vic2.rasterline, VIC2_STARTVISIBLECOLUMNS + 34, VIC2_STARTVISIBLECOLUMNS + 34 + columns + 16 - 1);
1936            if (vic3->on)
1937               vic2_drawlines(device, vic3->rasterline - 1, vic3->rasterline, VIC2_STARTVISIBLECOLUMNS + 34, VIC2_STARTVISIBLECOLUMNS + 34 + vic3->columns + 16 - 1);
8821938         }
8831939      }
8841940}
8851941
1942UINT32 vic3_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect )
1943{
1944   vic3_state *vic3 = get_safe_token(device);
8861945
1946   copybitmap(bitmap, vic3->bitmap, 0, 0, 0, 0, cliprect);
1947   return 0;
1948}
1949
1950/*****************************************************************************
1951    DEVICE INTERFACE
1952*****************************************************************************/
1953
1954static DEVICE_START( vic3 )
1955{
1956   vic3_state *vic3 = get_safe_token(device);
1957   const vic3_interface *intf = (vic3_interface *)device->baseconfig().static_config;
1958   int width, height;
1959   int i;
1960
1961   vic3->cpu = devtag_get_device(device->machine, intf->cpu);
1962
1963   vic3->main_screen = devtag_get_device(device->machine, intf->screen);
1964   width = video_screen_get_width(vic3->main_screen);
1965   height = video_screen_get_height(vic3->main_screen);
1966
1967   vic3->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
1968
1969   vic3->type = intf->type;
1970
1971   vic3->dma_read = intf->dma_read;
1972   vic3->dma_read_color = intf->dma_read_color;
1973   vic3->interrupt = intf->irq;
1974
1975   vic3->port_changed = intf->port_changed;
1976
1977   vic3->c64_mem_r = intf->c64_mem_r;
1978
1979   vic3->lightpen_button_cb = intf->button_cb;
1980   vic3->lightpen_x_cb = intf->x_cb;
1981   vic3->lightpen_y_cb = intf->y_cb;
1982
1983   vic3->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
1984
1985   vic3->screen[0] = auto_alloc_array(device->machine, UINT8, 216 * 656 / 8);
1986
1987   for (i = 1; i < 216; i++)
1988      vic3->screen[i] = vic3->screen[i - 1] + 656 / 8;
1989
1990   for (i = 0; i < 256; i++)
1991   {
1992      vic3->foreground[i] = 0;
1993      if ((i & 3) > 1)
1994         vic3->foreground[i] |= 0x3;
1995      if ((i & 0xc) > 0x4)
1996         vic3->foreground[i] |= 0xc;
1997      if ((i & 0x30) > 0x10)
1998         vic3->foreground[i] |= 0x30;
1999      if ((i & 0xc0) > 0x40)
2000         vic3->foreground[i] |= 0xc0;
2001   }
2002
2003   for (i = 0; i < 256; i++)
2004   {
2005      vic3->expandx[i] = 0;
2006      if (i & 1)
2007         vic3->expandx[i] |= 3;
2008      if (i & 2)
2009         vic3->expandx[i] |= 0xc;
2010      if (i & 4)
2011         vic3->expandx[i] |= 0x30;
2012      if (i & 8)
2013         vic3->expandx[i] |= 0xc0;
2014      if (i & 0x10)
2015         vic3->expandx[i] |= 0x300;
2016      if (i & 0x20)
2017         vic3->expandx[i] |= 0xc00;
2018      if (i & 0x40)
2019         vic3->expandx[i] |= 0x3000;
2020      if (i & 0x80)
2021         vic3->expandx[i] |= 0xc000;
2022   }
2023
2024   for (i = 0; i < 256; i++)
2025   {
2026      vic3->expandx_multi[i] = 0;
2027      if (i & 1)
2028         vic3->expandx_multi[i] |= 5;
2029      if (i & 2)
2030         vic3->expandx_multi[i] |= 0xa;
2031      if (i & 4)
2032         vic3->expandx_multi[i] |= 0x50;
2033      if (i & 8)
2034         vic3->expandx_multi[i] |= 0xa0;
2035      if (i & 0x10)
2036         vic3->expandx_multi[i] |= 0x500;
2037      if (i & 0x20)
2038         vic3->expandx_multi[i] |= 0xa00;
2039      if (i & 0x40)
2040         vic3->expandx_multi[i] |= 0x5000;
2041      if (i & 0x80)
2042         vic3->expandx_multi[i] |= 0xa000;
2043   }
2044
2045   state_save_register_device_item_array(device, 0, vic3->reg);
2046
2047   state_save_register_device_item(device, 0, vic3->on);
2048
2049   state_save_register_device_item_bitmap(device, 0, vic3->bitmap);
2050
2051   state_save_register_device_item(device, 0, vic3->lines);
2052
2053   state_save_register_device_item(device, 0, vic3->chargenaddr);
2054   state_save_register_device_item(device, 0, vic3->videoaddr);
2055   state_save_register_device_item(device, 0, vic3->bitmapaddr);
2056
2057   state_save_register_device_item(device, 0, vic3->x_begin);
2058   state_save_register_device_item(device, 0, vic3->x_end);
2059   state_save_register_device_item(device, 0, vic3->y_begin);
2060   state_save_register_device_item(device, 0, vic3->y_end);
2061
2062   state_save_register_device_item_array(device, 0, vic3->c64_bitmap);
2063   state_save_register_device_item_array(device, 0, vic3->bitmapmulti);
2064   state_save_register_device_item_array(device, 0, vic3->mono);
2065   state_save_register_device_item_array(device, 0, vic3->multi);
2066   state_save_register_device_item_array(device, 0, vic3->ecmcolor);
2067   state_save_register_device_item_array(device, 0, vic3->colors);
2068   state_save_register_device_item_array(device, 0, vic3->spritemulti);
2069
2070   state_save_register_device_item(device, 0, vic3->lastline);
2071   state_save_register_device_item(device, 0, vic3->rasterline);
2072   state_save_register_device_item(device, 0, vic3->interlace);
2073
2074   state_save_register_device_item(device, 0, vic3->columns);
2075   state_save_register_device_item(device, 0, vic3->rows);
2076
2077   state_save_register_device_item_array(device, 0, vic3->shift);
2078   state_save_register_device_item_array(device, 0, vic3->foreground);
2079   state_save_register_device_item_array(device, 0, vic3->multi_collision);
2080
2081   state_save_register_device_item_array(device, 0, vic3->palette_red);
2082   state_save_register_device_item_array(device, 0, vic3->palette_green);
2083   state_save_register_device_item_array(device, 0, vic3->palette_blue);
2084   state_save_register_device_item(device, 0, vic3->palette_dirty);
2085
2086   for (i = 0; i < 8; i++)
2087   {
2088      state_save_register_device_item(device, i, vic3->sprites[i].x);
2089      state_save_register_device_item(device, i, vic3->sprites[i].y);
2090      state_save_register_device_item(device, i, vic3->sprites[i].repeat);
2091      state_save_register_device_item(device, i, vic3->sprites[i].line);
2092      state_save_register_device_item_array(device, i, vic3->sprites[i].paintedline);
2093      state_save_register_device_item_array(device, i, vic3->sprites[i].bitmap[0]);
2094      state_save_register_device_item_array(device, i, vic3->sprites[i].bitmap[1]);
2095      state_save_register_device_item_array(device, i, vic3->sprites[i].bitmap[2]);
2096      state_save_register_device_item_array(device, i, vic3->sprites[i].bitmap[3]);
2097      state_save_register_device_item_array(device, i, vic3->sprites[i].bitmap[4]);
2098      state_save_register_device_item_array(device, i, vic3->sprites[i].bitmap[5]);
2099      state_save_register_device_item_array(device, i, vic3->sprites[i].bitmap[6]);
2100      state_save_register_device_item_array(device, i, vic3->sprites[i].bitmap[7]);
2101   }
2102}
2103
2104static DEVICE_RESET( vic3 )
2105{
2106   vic3_state *vic3 = get_safe_token(device);
2107   int i;
2108
2109   memset(vic3->reg, 0, ARRAY_LENGTH(vic3->reg));
2110
2111   vic3->on = 1;
2112
2113   vic3->interlace = 0;
2114   vic3->columns = 640;
2115   vic3->rows = 200;
2116   vic3->lines = VIC2_LINES;
2117
2118   memset(&vic3->sprites, 0, sizeof(vic3->sprites));
2119
2120   vic3->chargenaddr = 0;
2121   vic3->videoaddr = 0;
2122   vic3->bitmapaddr = 0;
2123
2124   vic3->x_begin = 0;
2125   vic3->x_end = 0;
2126   vic3->y_begin = 0;
2127   vic3->y_end = 0;
2128
2129   for (i = 0; i < 2; i++)
2130   {
2131      vic3->c64_bitmap[i] = 0;
2132      vic3->mono[i] = 0;
2133      vic3->ecmcolor[i] = 0;
2134   }
2135
2136   for (i = 0; i < 4; i++)
2137   {
2138      vic3->bitmapmulti[i] = 0;
2139      vic3->multi[i] = 0;
2140      vic3->colors[i] = 0;
2141      vic3->spritemulti[i] = 0;
2142   }
2143
2144   vic3->lastline = 0;
2145   vic3->rasterline = 0;
2146
2147   memset(vic3->shift, 0, ARRAY_LENGTH(vic3->shift));
2148   memset(vic3->multi_collision, 0, ARRAY_LENGTH(vic3->multi_collision));
2149   memset(vic3->palette_red, 0, ARRAY_LENGTH(vic3->palette_red));
2150   memset(vic3->palette_green, 0, ARRAY_LENGTH(vic3->palette_green));
2151   memset(vic3->palette_blue, 0, ARRAY_LENGTH(vic3->palette_blue));
2152
2153   vic3->palette_dirty = 0;
2154}
2155
2156
2157/*-------------------------------------------------
2158    device definition
2159-------------------------------------------------*/
2160
2161static const char DEVTEMPLATE_SOURCE[] = __FILE__;
2162
2163#define DEVTEMPLATE_ID(p,s)            p##vic3##s
2164#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
2165#define DEVTEMPLATE_NAME            "4567 VIC III"
2166#define DEVTEMPLATE_FAMILY            "4567 VIC III"
2167#include "devtempl.h"
src/mess/video/vic4567.h
r7364r7365
44 *
55 ****************************************************************************/
66
7#ifndef VIC4567_H_
8#define VIC4567_H_
7#ifndef __VIC4567_H__
8#define __VIC4567_H__
99
10#include "devcb.h"
1011
11/*----------- defined in video/vic4567.c -----------*/
1212
13extern const unsigned char vic3_palette[0x100 * 3];
13/***************************************************************************
14    TYPE DEFINITIONS
15***************************************************************************/
1416
15extern void vic4567_init (running_machine *machine, int pal, int (*dma_read)(running_machine *, int),
16                    int (*dma_read_color)(running_machine *, int), void (*irq)(running_machine *, int),
17                    void (*param_port_changed)(running_machine *, int));
17typedef UINT8 (*vic3_lightpen_x_callback)(running_machine *machine);
18typedef UINT8 (*vic3_lightpen_y_callback)(running_machine *machine);
19typedef UINT8 (*vic3_lightpen_button_callback)(running_machine *machine);
1820
19extern INTERRUPT_GEN( vic3_raster_irq );
21typedef int (*vic3_dma_read)(running_machine *machine, int);
22typedef int (*vic3_dma_read_color)(running_machine *machine, int);
23typedef void (*vic3_irq) (running_machine *, int);
2024
25typedef void (*vic3_port_changed_callback) (running_machine *, int);
26
27typedef UINT8 (*vic3_c64mem_callback)(int offset);
28
29typedef enum
30{
31   VIC4567_NTSC,
32   VIC4567_PAL
33} vic3_type;
34
35typedef struct _vic3_interface vic3_interface;
36struct _vic3_interface
37{
38   const char         *screen;
39   const char         *cpu;
40
41   vic3_type type;
42
43   vic3_lightpen_x_callback        x_cb;
44   vic3_lightpen_y_callback        y_cb;
45   vic3_lightpen_button_callback   button_cb;
46
47   vic3_dma_read          dma_read;
48   vic3_dma_read_color    dma_read_color;
49   vic3_irq               irq;
50
51   vic3_port_changed_callback        port_changed;
52
53   vic3_c64mem_callback      c64_mem_r;
54};
55
56/***************************************************************************
57    CONSTANTS
58***************************************************************************/
59
60#define VIC6567_CLOCK      (1022700 /* = 8181600 / 8) */ )
61#define VIC6569_CLOCK      ( 985248 /* = 7881984 / 8) */ )
62
63#define VIC6567_CYCLESPERLINE   65
64#define VIC6569_CYCLESPERLINE   63
65
66#define VIC6567_LINES      263
67#define VIC6569_LINES      312
68
69#define VIC6567_VRETRACERATE   (59.8245100906698 /* = 1022700 / (65 * 263) */ )
70#define VIC6569_VRETRACERATE   (50.1245421245421 /* =  985248 / (63 * 312) */ )
71
72#define VIC6567_HRETRACERATE   (VIC6567_CLOCK / VIC6567_CYCLESPERLINE)
73#define VIC6569_HRETRACERATE   (VIC6569_CLOCK / VIC6569_CYCLESPERLINE)
74
75#define VIC2_HSIZE      320
76#define VIC2_VSIZE      200
77
78#define VIC6567_VISIBLELINES   235
79#define VIC6569_VISIBLELINES   284
80
81#define VIC6567_FIRST_DMA_LINE   0x30
82#define VIC6569_FIRST_DMA_LINE   0x30
83
84#define VIC6567_LAST_DMA_LINE   0xf7
85#define VIC6569_LAST_DMA_LINE   0xf7
86
87#define VIC6567_FIRST_DISP_LINE   0x29
88#define VIC6569_FIRST_DISP_LINE   0x10
89
90#define VIC6567_LAST_DISP_LINE   (VIC6567_FIRST_DISP_LINE + VIC6567_VISIBLELINES - 1)
91#define VIC6569_LAST_DISP_LINE   (VIC6569_FIRST_DISP_LINE + VIC6569_VISIBLELINES - 1)
92
93#define VIC6567_RASTER_2_EMU(a) ((a >= VIC6567_FIRST_DISP_LINE) ? (a - VIC6567_FIRST_DISP_LINE) : (a + 222))
94#define VIC6569_RASTER_2_EMU(a) (a - VIC6569_FIRST_DISP_LINE)
95
96#define VIC6567_FIRSTCOLUMN   50
97#define VIC6569_FIRSTCOLUMN   50
98
99#define VIC6567_VISIBLECOLUMNS   418
100#define VIC6569_VISIBLECOLUMNS   403
101
102#define VIC6567_X_2_EMU(a)   (a)
103#define VIC6569_X_2_EMU(a)   (a)
104
105#define VIC6567_STARTVISIBLELINES ((VIC6567_LINES - VIC6567_VISIBLELINES)/2)
106#define VIC6569_STARTVISIBLELINES 16 /* ((VIC6569_LINES - VIC6569_VISIBLELINES)/2) */
107
108#define VIC6567_FIRSTRASTERLINE 34
109#define VIC6569_FIRSTRASTERLINE 0
110
111#define VIC6567_COLUMNS 512
112#define VIC6569_COLUMNS 504
113
114
115#define VIC6567_STARTVISIBLECOLUMNS ((VIC6567_COLUMNS - VIC6567_VISIBLECOLUMNS)/2)
116#define VIC6569_STARTVISIBLECOLUMNS ((VIC6569_COLUMNS - VIC6569_VISIBLECOLUMNS)/2)
117
118#define VIC6567_FIRSTRASTERCOLUMNS 412
119#define VIC6569_FIRSTRASTERCOLUMNS 404
120
121#define VIC6569_FIRST_X 0x194
122#define VIC6567_FIRST_X 0x19c
123
124#define VIC6569_FIRST_VISIBLE_X 0x1e0
125#define VIC6567_FIRST_VISIBLE_X 0x1e8
126
127#define VIC6569_MAX_X 0x1f7
128#define VIC6567_MAX_X 0x1ff
129
130#define VIC6569_LAST_VISIBLE_X 0x17c
131#define VIC6567_LAST_VISIBLE_X 0x184
132
133#define VIC6569_LAST_X 0x193
134#define VIC6567_LAST_X 0x19b
135
136/***************************************************************************
137    FUNCTION PROTOTYPES
138***************************************************************************/
139
140DEVICE_GET_INFO( vic3 );
141
142/***************************************************************************
143    DEVICE CONFIGURATION MACROS
144***************************************************************************/
145
146#define VIC3 DEVICE_GET_INFO_NAME( vic3 )
147
148#define MDRV_VIC3_ADD(_tag, _interface) \
149   MDRV_DEVICE_ADD(_tag, VIC3, 0) \
150   MDRV_DEVICE_CONFIG(_interface)
151
152
153/*----------- defined in video/vic4567.c -----------*/
154
21155/* to be called when writting to port */
22extern WRITE8_HANDLER ( vic3_port_w );
23WRITE8_HANDLER( vic3_palette_w );
156WRITE8_DEVICE_HANDLER( vic3_port_w );
157WRITE8_DEVICE_HANDLER( vic3_palette_w );
24158
25159/* to be called when reading from port */
26extern  READ8_HANDLER ( vic3_port_r );
160READ8_DEVICE_HANDLER( vic3_port_r );
161READ8_DEVICE_HANDLER( vic3_palette_red_r );
162READ8_DEVICE_HANDLER( vic3_palette_green_r );
163READ8_DEVICE_HANDLER( vic3_palette_blue_r );
27164
165void vic3_raster_interrupt_gen( running_device *device );
166UINT32 vic3_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect );
28167
29#endif /* VIC4567_H_ */
168
169#endif /* __VIC4567_H__ */
src/mess/video/vic6567.c
r7364r7365
11/***************************************************************************
22
33    Video Interface Chip (6567R8 for NTSC system and 6569 for PAL system)
4    PeT mess@utanet.at
54
5    original emulation by PeT (mess@utanet.at)
6
67    A part of the code (cycle routine and drawing routines) is a modified version of the vic ii emulation used in
78    commodore 64 emulator "frodo" by Christian Bauer
89
r7364r7365
1213    Permission to use it for non-commercial purposes is hereby granted als long as my copyright notice remains in the program.
1314    You are not allowed to use the source to create and distribute a modified version of Frodo.
1415
16    2010-02: converted to be a device and split vic III emulation (which still uses old cycle & drawing routines)
17
18    TODO:
19      - plenty of cleanups
20      - emulate variants of the vic chip
21      - update vic III to use new code for the vic II compatibility
22
1523***************************************************************************/
1624/* mos videochips
1725  vic (6560 NTSC, 6561 PAL)
r7364r7365
6270  complete different to above chips
6371*/
6472
65#include <math.h>
66#include <stdio.h>
67#include <assert.h>
6873
6974#include "emu.h"
70#include "vic6567.h"
71#include "vic4567.h"
72#include "utils.h"
75#include "video/vic6567.h"
7376
74#ifdef UNUSED_FUNCTION
75static TIMER_CALLBACK( line_timer_callback );
76#endif
77static TIMER_CALLBACK( PAL_timer_callback );
78static TIMER_CALLBACK( NTSC_timer_callback );
77typedef struct _vic2_state  vic2_state;
78struct _vic2_state
79{
80   vic2_type  type;
7981
82   running_device *screen;         // screen which sets bitmap properties
83   running_device *cpu;
8084
81/* lightpen values */
82#include "includes/c64.h"
85   UINT8 reg[0x80];
8386
87   int on;                        /* rastering of the screen */
88
89   UINT16 chargenaddr, videoaddr, bitmapaddr;
90
91   bitmap_t *bitmap;
92
93   UINT16 colors[4], spritemulti[4];
94
95   int rasterline;
96   UINT64 cycles_counter;
97   UINT8 cycle;
98   UINT16 raster_x;
99   UINT16 graphic_x;
100
101   /* convert multicolor byte to background/foreground for sprite collision */
102   UINT16 expandx[256];
103   UINT16 expandx_multi[256];
104
105   /* Display */
106   UINT16 dy_start;
107   UINT16 dy_stop;
108
109   /* GFX */
110   UINT8 draw_this_line;
111   UINT8 is_bad_line;
112   UINT8 bad_lines_enabled;
113   UINT8 display_state;
114   UINT8 char_data;
115   UINT8 gfx_data;
116   UINT8 color_data;
117   UINT8 last_char_data;
118   UINT8 matrix_line[40];                  // Buffer for video line, read in Bad Lines
119   UINT8 color_line[40];                  // Buffer for color line, read in Bad Lines
120   UINT8 vblanking;
121   UINT16 ml_index;
122   UINT8 rc;
123   UINT16 vc;
124   UINT16 vc_base;
125   UINT8 ref_cnt;
126
127   /* Sprites */
128   UINT8 spr_coll_buf[0x400];               // Buffer for sprite-sprite collisions and priorities
129   UINT8 fore_coll_buf[0x400];               // Buffer for foreground-sprite collisions and priorities
130   UINT8 spr_draw_data[8][4];               // Sprite data for drawing
131   UINT8 spr_exp_y;
132   UINT8 spr_dma_on;
133   UINT8 spr_draw;
134   UINT8 spr_disp_on;
135   UINT16 spr_ptr[8];
136   UINT8 spr_data[8][4];
137   UINT16 mc_base[8];                  // Sprite data counter bases
138   UINT16 mc[8];                     // Sprite data counters
139
140   /* Border */
141   UINT8 border_on;
142   UINT8 ud_border_on;
143   UINT8 border_on_sample[5];
144   UINT8 border_color_sample[0x400 / 8];         // Samples of border color at each "displayed" cycle
145
146   /* Cycles */
147   UINT64 first_ba_cycle;
148   UINT8 cpu_suspended;
149
150   /* DMA */
151   vic2_dma_read          dma_read;
152   vic2_dma_read_color    dma_read_color;
153
154   /* IRQ */
155   vic2_irq               interrupt;
156
157   /* RDY */
158   vic2_rdy_callback      rdy_workaround_cb;
159
160   /* lightpen */
161   vic2_lightpen_button_callback lightpen_button_cb;
162   vic2_lightpen_x_callback lightpen_x_cb;
163   vic2_lightpen_y_callback lightpen_y_cb;
164};
165
166
167/*****************************************************************************
168    CONSTANTS
169*****************************************************************************/
170
84171#define VERBOSE_LEVEL 0
85172#define DBG_LOG(N,M,A) \
86173   do { \
r7364r7365
92179      } \
93180   } while (0)
94181
95// Display
96#define ROW25_YSTART 0x33
97#define ROW25_YSTOP 0xfb
98#define ROW24_YSTART 0x37
99#define ROW24_YSTOP 0xf7
182#define ROW25_YSTART      0x33
183#define ROW25_YSTOP       0xfb
184#define ROW24_YSTART      0x37
185#define ROW24_YSTOP       0xf7
100186
101static UINT16 dy_start = ROW24_YSTART;
102static UINT16 dy_stop = ROW24_YSTOP;
103
104// GFX
105static UINT8 draw_this_line = 0;
106static UINT8 is_bad_line = 0;
107static UINT8 bad_lines_enabled = 0;
108static UINT8 display_state = 0;
109static UINT8 char_data = 0;
110static UINT8 gfx_data = 0;
111static UINT8 color_data = 0;
112static UINT8 last_char_data = 0;
113static UINT8 matrix_line[40];                  // Buffer for video line, read in Bad Lines
114static UINT8 color_line[40];                  // Buffer for color line, read in Bad Lines
115static UINT8 vblanking = 0;
116static UINT16 ml_index = 0;
117static UINT8 rc = 0;
118static UINT16 vc = 0;
119static UINT16 vc_base = 0;
120static UINT8 ref_cnt = 0;
121
122// Sprites
123static UINT8 spr_coll_buf[0x400];               // Buffer for sprite-sprite collisions and priorities
124static UINT8 fore_coll_buf[0x400];               // Buffer for foreground-sprite collisions and priorities
125static UINT8 spr_draw_data[8][4];               // Sprite data for drawing
126static UINT8 spr_exp_y = 0;
127static UINT8 spr_dma_on;
128static UINT8 spr_draw = 0;
129static UINT8 spr_disp_on = 0;
130static UINT16 spr_ptr[8];
131static UINT8 spr_data[8][4];
132static UINT16 mc_base[8];                  // Sprite data counter bases
133static UINT16 mc[8];                     // Sprite data counters
134
135// Border
136static UINT8 border_on = 0;
137static UINT8 ud_border_on = 0;
138static UINT8 border_on_sample[5];
139static UINT8 border_color_sample[0x400 / 8];         // Samples of border color at each "displayed" cycle
140
141// Cycles
142static UINT64 first_ba_cycle;
143static UINT8 cpu_suspended = 0;
144
145#define VREFRESHINLINES         28
146
147#define VIC2_YPOS            50
148187#define RASTERLINE_2_C64(a)      (a)
149188#define C64_2_RASTERLINE(a)      (a)
150189#define XPOS            (VIC2_STARTVISIBLECOLUMNS + (VIC2_VISIBLECOLUMNS - VIC2_HSIZE) / 2)
151190#define YPOS            (VIC2_STARTVISIBLELINES /* + (VIC2_VISIBLELINES - VIC2_VSIZE) / 2 */)
152#define FIRSTLINE            10 /* 36 ((VIC2_VISIBLELINES - VIC2_VSIZE)/2) */
153191#define FIRSTCOLUMN         50
154192
155193/* 2008-05 FP: lightpen code needs to read input port from c64.c and cbmb.c */
156#define LIGHTPEN_BUTTON         (input_port_read(machine, "OTHER") & 0x04)
157#define LIGHTPEN_X_VALUE      (input_port_read(machine, "LIGHTX") & ~0x01)
158#define LIGHTPEN_Y_VALUE      (input_port_read(machine, "LIGHTY") & ~0x01)
159194
195#define LIGHTPEN_BUTTON      (vic2->lightpen_button_cb(machine))
196#define LIGHTPEN_X_VALUE   (vic2->lightpen_x_cb(machine))
197#define LIGHTPEN_Y_VALUE   (vic2->lightpen_y_cb(machine))
198
160199/* lightpen delivers values from internal counters; they do not start with the visual area or frame area */
161200#define VIC2_MAME_XPOS         0
162201#define VIC2_MAME_YPOS         0
r7364r7365
164203#define VIC6567_Y_BEGIN         -6            /* first 6 lines after retrace not for lightpen! */
165204#define VIC6569_X_BEGIN         38
166205#define VIC6569_Y_BEGIN         -6
167#define VIC2_X_BEGIN         (vic2.pal ? VIC6569_X_BEGIN : VIC6567_X_BEGIN)
168#define VIC2_Y_BEGIN         (vic2.pal ? VIC6569_Y_BEGIN : VIC6567_Y_BEGIN)
169#define VIC2_X_VALUE         ((LIGHTPEN_X_VALUE+VIC2_X_BEGIN + VIC2_MAME_XPOS) / 2)
170#define VIC2_Y_VALUE         ((LIGHTPEN_Y_VALUE+VIC2_Y_BEGIN + VIC2_MAME_YPOS))
206#define VIC2_X_BEGIN         ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_X_BEGIN : VIC6567_X_BEGIN)
207#define VIC2_Y_BEGIN         ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_Y_BEGIN : VIC6567_Y_BEGIN)
208#define VIC2_X_VALUE         ((LIGHTPEN_X_VALUE + VIC2_X_BEGIN + VIC2_MAME_XPOS) / 2)
209#define VIC2_Y_VALUE         ((LIGHTPEN_Y_VALUE + VIC2_Y_BEGIN + VIC2_MAME_YPOS))
171210
172#define VIC2E_K0_LEVEL         (vic2.reg[0x2f] & 0x01)
173#define VIC2E_K1_LEVEL         (vic2.reg[0x2f] & 0x02)
174#define VIC2E_K2_LEVEL         (vic2.reg[0x2f] & 0x04)
211#define VIC2E_K0_LEVEL         (vic2->reg[0x2f] & 0x01)
212#define VIC2E_K1_LEVEL         (vic2->reg[0x2f] & 0x02)
213#define VIC2E_K2_LEVEL         (vic2->reg[0x2f] & 0x04)
175214
176/*#define VIC3_P5_LEVEL (vic2.reg[0x30] & 0x20) */
177#define VIC3_BITPLANES         (vic2.reg[0x31] & 0x10)
178#define VIC3_80COLUMNS         (vic2.reg[0x31] & 0x80)
179#define VIC3_LINES         ((vic2.reg[0x31] & 0x19) == 0x19 ? 400 : 200)
180#define VIC3_BITPLANES_WIDTH       (vic2.reg[0x31] & 0x80 ? 640 : 320)
181215
182/*#define VIC2E_TEST (vic2[0x30] & 2) */
183#define DOUBLE_CLOCK         (vic2.reg[0x30] & 0x01)
184
185216/* sprites 0 .. 7 */
186#define SPRITE_BASE_X_SIZE      24
187#define SPRITE_BASE_Y_SIZE      21
188#define SPRITEON(nr)         (vic2.reg[0x15] & (1 << nr))
189#define SPRITE_Y_EXPAND(nr)      (vic2.reg[0x17] & (1 << nr))
217#define SPRITEON(nr)         (vic2->reg[0x15] & (1 << nr))
218#define SPRITE_Y_EXPAND(nr)      (vic2->reg[0x17] & (1 << nr))
190219#define SPRITE_Y_SIZE(nr)      (SPRITE_Y_EXPAND(nr) ? 2 * 21 : 21)
191#define SPRITE_X_EXPAND(nr)      (vic2.reg[0x1d] & (1 << nr))
220#define SPRITE_X_EXPAND(nr)      (vic2->reg[0x1d] & (1 << nr))
192221#define SPRITE_X_SIZE(nr)      (SPRITE_X_EXPAND(nr) ? 2 * 24 : 24)
193#define SPRITE_X_POS(nr)      ((vic2.reg[(nr) * 2] | (vic2.reg[0x10] & (1 << (nr)) ? 0x100 : 0)) - 24 + XPOS)
194#define SPRITE_X_POS2(nr)      (vic2.reg[(nr) * 2] | (vic2.reg[0x10] & (1 << (nr)) ? 0x100 : 0))
195#define SPRITE_Y_POS(nr)      (vic2.reg[1+2*(nr)] - 50 + YPOS)
196#define SPRITE_Y_POS2(nr)      (vic2.reg[1 + 2 * (nr)])
197#define SPRITE_MULTICOLOR(nr)      (vic2.reg[0x1c] & (1 << nr))
198#define SPRITE_PRIORITY(nr)      (vic2.reg[0x1b] & (1 << nr))
199#define SPRITE_MULTICOLOR1      (vic2.reg[0x25] & 0x0f)
200#define SPRITE_MULTICOLOR2      (vic2.reg[0x26] & 0x0f)
201#define SPRITE_COLOR(nr)      (vic2.reg[0x27+nr] & 0x0f)
202#define SPRITE_ADDR(nr)         (vic2.videoaddr | 0x3f8 | nr)
203#define SPRITE_BG_COLLISION(nr)   (vic2.reg[0x1f] & (1 << nr))
204#define SPRITE_COLLISION(nr)      (vic2.reg[0x1e] & (1 << nr))
205#define SPRITE_SET_BG_COLLISION(nr) (vic2.reg[0x1f] |= (1 << nr))
206#define SPRITE_SET_COLLISION(nr)   (vic2.reg[0x1e] |= (1 << nr))
207#define SPRITE_COLL         (vic2.reg[0x1e])
208#define SPRITE_BG_COLL         (vic2.reg[0x1f])
222#define SPRITE_X_POS(nr)      (vic2->reg[(nr) * 2] | (vic2->reg[0x10] & (1 << (nr)) ? 0x100 : 0))
223#define SPRITE_Y_POS(nr)      (vic2->reg[1 + 2 * (nr)])
224#define SPRITE_MULTICOLOR(nr)      (vic2->reg[0x1c] & (1 << nr))
225#define SPRITE_PRIORITY(nr)      (vic2->reg[0x1b] & (1 << nr))
226#define SPRITE_MULTICOLOR1      (vic2->reg[0x25] & 0x0f)
227#define SPRITE_MULTICOLOR2      (vic2->reg[0x26] & 0x0f)
228#define SPRITE_COLOR(nr)      (vic2->reg[0x27+nr] & 0x0f)
229#define SPRITE_ADDR(nr)         (vic2->videoaddr | 0x3f8 | nr)
230#define SPRITE_COLL         (vic2->reg[0x1e])
231#define SPRITE_BG_COLL         (vic2->reg[0x1f])
209232
210#define GFXMODE            ((vic2.reg[0x11] & 0x60) | (vic2.reg[0x16] & 0x10)) >> 4
211#define SCREENON            (vic2.reg[0x11] & 0x10)
212#define VERTICALPOS         (vic2.reg[0x11] & 0x07)
213#define HORIZONTALPOS         (vic2.reg[0x16] & 0x07)
214#define ECMON            (vic2.reg[0x11] & 0x40)
215#define HIRESON            (vic2.reg[0x11] & 0x20)
216#define MULTICOLORON         (vic2.reg[0x16] & 0x10)
217#define LINES25            (vic2.reg[0x11] & 0x08)         /* else 24 Lines */
218#define LINES            (LINES25 ? 25 : 24)
219#define YSIZE            (LINES * 8)
220#define COLUMNS40            (vic2.reg[0x16] & 0x08)         /* else 38 Columns */
221#define COLUMNS            (COLUMNS40 ? 40 : 38)
222#define XSIZE            (COLUMNS * 8)
233#define GFXMODE            ((vic2->reg[0x11] & 0x60) | (vic2->reg[0x16] & 0x10)) >> 4
234#define SCREENON            (vic2->reg[0x11] & 0x10)
235#define VERTICALPOS         (vic2->reg[0x11] & 0x07)
236#define HORIZONTALPOS         (vic2->reg[0x16] & 0x07)
237#define ECMON            (vic2->reg[0x11] & 0x40)
238#define HIRESON            (vic2->reg[0x11] & 0x20)
239#define COLUMNS40            (vic2->reg[0x16] & 0x08)         /* else 38 Columns */
223240
224#define VIDEOADDR            ((vic2.reg[0x18] & 0xf0) << (10 - 4))
225#define CHARGENADDR         ((vic2.reg[0x18] & 0x0e) << 10)
241#define VIDEOADDR            ((vic2->reg[0x18] & 0xf0) << (10 - 4))
242#define CHARGENADDR         ((vic2->reg[0x18] & 0x0e) << 10)
226243#define BITMAPADDR         ((data & 0x08) << 10)
227244
228#define RASTERLINE         (((vic2.reg[0x11] & 0x80) << 1) | vic2.reg[0x12])
245#define RASTERLINE         (((vic2->reg[0x11] & 0x80) << 1) | vic2->reg[0x12])
229246
230#define FRAMECOLOR         (vic2.reg[0x20] & 0x0f)
231#define BACKGROUNDCOLOR         (vic2.reg[0x21] & 0x0f)
232#define MULTICOLOR1         (vic2.reg[0x22] & 0x0f)
233#define MULTICOLOR2         (vic2.reg[0x23] & 0x0f)
234#define FOREGROUNDCOLOR         (vic2.reg[0x24] & 0x0f)
247#define FRAMECOLOR         (vic2->reg[0x20] & 0x0f)
248#define BACKGROUNDCOLOR         (vic2->reg[0x21] & 0x0f)
249#define MULTICOLOR1         (vic2->reg[0x22] & 0x0f)
250#define MULTICOLOR2         (vic2->reg[0x23] & 0x0f)
251#define FOREGROUNDCOLOR         (vic2->reg[0x24] & 0x0f)
235252
236const unsigned char vic2_palette[] =
237{
238/* black, white, red, cyan */
239/* purple, green, blue, yellow */
240/* orange, brown, light red, dark gray, */
241/* medium gray, light green, light blue, light gray */
242/* taken from the vice emulator */
243   0x00, 0x00, 0x00,  0xfd, 0xfe, 0xfc,  0xbe, 0x1a, 0x24,  0x30, 0xe6, 0xc6,
244   0xb4, 0x1a, 0xe2,  0x1f, 0xd2, 0x1e,  0x21, 0x1b, 0xae,  0xdf, 0xf6, 0x0a,
245   0xb8, 0x41, 0x04,  0x6a, 0x33, 0x04,  0xfe, 0x4a, 0x57,  0x42, 0x45, 0x40,
246   0x70, 0x74, 0x6f,  0x59, 0xfe, 0x59,  0x5f, 0x53, 0xfe,  0xa4, 0xa7, 0xa2
247};
253#define VIC2_LINES      ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_LINES : VIC6567_LINES)
254#define VIC2_FIRST_DMA_LINE   ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_FIRST_DMA_LINE : VIC6567_FIRST_DMA_LINE)
255#define VIC2_LAST_DMA_LINE   ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_LAST_DMA_LINE : VIC6567_LAST_DMA_LINE)
256#define VIC2_FIRST_DISP_LINE   ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_FIRST_DISP_LINE : VIC6567_FIRST_DISP_LINE)
257#define VIC2_LAST_DISP_LINE   ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_LAST_DISP_LINE : VIC6567_LAST_DISP_LINE)
258#define VIC2_RASTER_2_EMU(a)   ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_RASTER_2_EMU(a) : VIC6567_RASTER_2_EMU(a))
259#define VIC2_FIRSTCOLUMN   ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_FIRSTCOLUMN : VIC6567_FIRSTCOLUMN)
260#define VIC2_X_2_EMU(a)      ((vic2->type == VIC6569 || vic2->type == VIC8566) ? VIC6569_X_2_EMU(a) : VIC6567_X_2_EMU(a))
248261
249static struct {
250   UINT8 reg[0x80];
251   int pal;
252   int vic2e;                        /* version with some port lines */
253   int vic3;
254   int on;                        /* rastering of the screen */
262/*****************************************************************************
263    INLINE FUNCTIONS
264*****************************************************************************/
255265
256   int (*dma_read)(running_machine *, int);
257   int (*dma_read_color)(running_machine *, int);
258   void (*interrupt) (running_machine *, int);
259   void (*port_changed)(running_machine *, int);
260
261   int lines;
262
263   UINT16 chargenaddr, videoaddr, bitmapaddr;
264
265   bitmap_t *bitmap;
266   int x_begin, x_end;
267   int y_begin, y_end;
268
269   UINT16 c64_bitmap[2], bitmapmulti[4], mono[2], multi[4], ecmcolor[2], colors[4], spritemulti[4];
270
271   int lastline, rasterline, raster_mod;
272   UINT64 rasterline_start_cpu_cycles, totalcycles, cycles_counter;
273   UINT8 rasterX, cycle;
274   UINT16 raster_x;
275   UINT16 graphic_x;
276
277   /* background/foreground for sprite collision */
278   UINT8 *screen[216], shift[216];
279
280   /* convert multicolor byte to background/foreground for sprite collision */
281   UINT8 foreground[256];
282   UINT16 expandx[256];
283   UINT16 expandx_multi[256];
284
285   /* converts sprite multicolor info to info for background collision checking */
286   UINT8 multi_collision[256];
287
288   struct
289   {
290      int on, x, y, xexpand, yexpand;
291
292      int repeat;                     /* expand, line once drawn */
293      int line;                     /* 0 not painting, else painting */
294
295      /* buffer for currently painted line */
296      int paintedline[8];
297      UINT8 bitmap[8][SPRITE_BASE_X_SIZE * 2 / 8 + 1   /*for simplier sprite collision detection*/];
298   } sprites[8];
299} vic2;
300
301INLINE int vic2_getforeground (register int y, register int x)
266INLINE vic2_state *get_safe_token( running_device *device )
302267{
303    return ((vic2.screen[y][x >> 3] << 8)
304       | (vic2.screen[y][(x >> 3) + 1])) >> (8 - (x & 7));
305}
268   assert(device != NULL);
269   assert(device->token != NULL);
270   assert(device->type == VIC2);
306271
307INLINE int vic2_getforeground16 (register int y, register int x)
308{
309   return ((vic2.screen[y][x >> 3] << 16)
310         | (vic2.screen[y][(x >> 3) + 1] << 8)
311         | (vic2.screen[y][(x >> 3) + 2])) >> (8 - (x & 7));
272   return (vic2_state *)device->token;
312273}
313274
314#if 0
315static void vic2_setforeground (int y, int x, int value)
275INLINE const vic2_interface *get_interface( running_device *device )
316276{
317   vic2.screen[y][x >> 3] = value;
277   assert(device != NULL);
278   assert((device->type == VIC2));
279   return (const vic2_interface *) device->baseconfig().static_config;
318280}
319#endif
320281
321static void vic2_drawlines (running_machine *machine, int first, int last, int start_x, int end_x);
282/*****************************************************************************
283    IMPLEMENTATION
284*****************************************************************************/
322285
323void vic6567_init (int chip_vic2e, int pal,
324               int (*dma_read) (running_machine *, int), int (*dma_read_color) (running_machine *, int),
325               void (*irq) (running_machine *, int))
286static void vic2_set_interrupt( running_machine *machine, int mask, vic2_state *vic2 )
326287{
327   memset(&vic2, 0, sizeof(vic2));
328
329   vic2.cycles_counter = 0;            // total cycles
330   vic2.cycle = 63;                  // first cycle
331   vic2.pal = pal;
332   vic2.lines = VIC2_LINES;
333
334   vic2.dma_read = dma_read;
335   vic2.dma_read_color = dma_read_color;
336   vic2.interrupt = irq;
337   vic2.vic2e = chip_vic2e;
338
339   vic2.on = TRUE;
340}
341
342void vic2_set_rastering(int onoff)
343{
344   vic2.on=onoff;
345}
346
347int vic2e_k0_r (void)
348{
349   return VIC2E_K0_LEVEL;
350}
351
352int vic2e_k1_r (void)
353{
354   return VIC2E_K1_LEVEL;
355}
356
357int vic2e_k2_r (void)
358{
359   return VIC2E_K2_LEVEL;
360}
361
362#if 0
363int vic3_p5_r (void)
364{
365   return VIC3_P5_LEVEL;
366}
367#endif
368
369static void vic2_set_interrupt(running_machine *machine, int mask)
370{
371   if (((vic2.reg[0x19] ^ mask) & vic2.reg[0x1a] & 0xf))
288   if (((vic2->reg[0x19] ^ mask) & vic2->reg[0x1a] & 0xf))
372289   {
373      if (!(vic2.reg[0x19] & 0x80))
290      if (!(vic2->reg[0x19] & 0x80))
374291      {
375         DBG_LOG (2, "vic2", ("irq start %.2x\n", mask));
376         vic2.reg[0x19] |= 0x80;
377         vic2.interrupt (machine, 1);
292         DBG_LOG(2, "vic2", ("irq start %.2x\n", mask));
293         vic2->reg[0x19] |= 0x80;
294         vic2->interrupt(machine, 1);
378295      }
379296   }
380   vic2.reg[0x19] |= mask;
297   vic2->reg[0x19] |= mask;
381298}
382299
383static void vic2_clear_interrupt (running_machine *machine, int mask)
300static void vic2_clear_interrupt( running_machine *machine, int mask, vic2_state *vic2 )
384301{
385   vic2.reg[0x19] &= ~mask;
386   if ((vic2.reg[0x19] & 0x80) && !(vic2.reg[0x19] & vic2.reg[0x1a] & 0xf))
302   vic2->reg[0x19] &= ~mask;
303   if ((vic2->reg[0x19] & 0x80) && !(vic2->reg[0x19] & vic2->reg[0x1a] & 0xf))
387304   {
388      DBG_LOG (2, "vic2", ("irq end %.2x\n", mask));
389      vic2.reg[0x19] &= ~0x80;
390      vic2.interrupt (machine, 0);
305      DBG_LOG(2, "vic2", ("irq end %.2x\n", mask));
306      vic2->reg[0x19] &= ~0x80;
307      vic2->interrupt(machine, 0);
391308   }
392309}
393310
394void vic2_lightpen_write (int level)
311void vic2_lightpen_write( running_device *device, int level )
395312{
396313   /* calculate current position, write it and raise interrupt */
397314}
398315
399static TIMER_CALLBACK(vic2_timer_timeout)
316static TIMER_CALLBACK( vic2_timer_timeout )
400317{
318    vic2_state *vic2 = (vic2_state *)ptr;
401319   int which = param;
402   DBG_LOG (3, "vic2 ", ("timer %d timeout\n", which));
320
321   DBG_LOG(3, "vic2 ", ("timer %d timeout\n", which));
322
403323   switch (which)
404324   {
405325   case 1:                     /* light pen */
406326      /* and diode must recognize light */
407327      if (1)
408328      {
409         vic2.reg[0x13] = VIC2_X_VALUE;
410         vic2.reg[0x14] = VIC2_Y_VALUE;
329         vic2->reg[0x13] = VIC2_X_VALUE;
330         vic2->reg[0x14] = VIC2_Y_VALUE;
411331      }
412      vic2_set_interrupt(machine, 8);
332      vic2_set_interrupt(machine, 8, vic2);
413333      break;
414334   }
415335}
416336
417INTERRUPT_GEN( vic2_frame_interrupt )
337
338// modified VIC II emulation by Christian Bauer starts here...
339
340// Idle access
341INLINE void vic2_idle_access( running_machine *machine, vic2_state *vic2 )
418342{
343   vic2->dma_read(machine, 0x3fff);
419344}
420345
421WRITE8_HANDLER ( vic2_port_w )
346// Fetch sprite data pointer
347INLINE void vic2_spr_ptr_access( running_machine *machine, vic2_state *vic2, int num )
422348{
423   running_machine *machine = space->machine;
424   DBG_LOG (2, "vic write", ("%.2x:%.2x\n", offset, data));
425   offset &= 0x3f;
349   vic2->spr_ptr[num] = vic2->dma_read(machine, SPRITE_ADDR(num)) << 6;
350}
426351
427   switch (offset)
352// Fetch sprite data, increment data counter
353INLINE void vic2_spr_data_access( running_machine *machine, vic2_state *vic2, int num, int bytenum )
354{
355   if (vic2->spr_dma_on & (1 << num))
428356   {
429   case 0x01:
430   case 0x03:
431   case 0x05:
432   case 0x07:
433   case 0x09:
434   case 0x0b:
435   case 0x0d:
436   case 0x0f:
437                           /* sprite y positions */
438      if (vic2.reg[offset] != data)
439      {
440         vic2.reg[offset] = data;
441         vic2.sprites[offset / 2].y = SPRITE_Y_POS(offset / 2);
442      }
443      break;
444
445   case 0x00:
446   case 0x02:
447   case 0x04:
448   case 0x06:
449   case 0x08:
450   case 0x0a:
451   case 0x0c:
452   case 0x0e:
453                           /* sprite x positions */
454      if (vic2.reg[offset] != data)
455      {
456         vic2.reg[offset] = data;
457         vic2.sprites[offset / 2].x = SPRITE_X_POS(offset / 2);
458      }
459      break;
460
461   case 0x10:                     /* sprite x positions */
462      if (vic2.reg[offset] != data)
463      {
464         vic2.reg[offset] = data;
465         vic2.sprites[0].x = SPRITE_X_POS(0);
466         vic2.sprites[1].x = SPRITE_X_POS(1);
467         vic2.sprites[2].x = SPRITE_X_POS(2);
468         vic2.sprites[3].x = SPRITE_X_POS(3);
469         vic2.sprites[4].x = SPRITE_X_POS(4);
470         vic2.sprites[5].x = SPRITE_X_POS(5);
471         vic2.sprites[6].x = SPRITE_X_POS(6);
472         vic2.sprites[7].x = SPRITE_X_POS(7);
473      }
474      break;
475
476   case 0x17:                     /* sprite y size */
477      spr_exp_y |= ~data;
478      if (vic2.reg[offset] != data)
479      {
480         vic2.reg[offset] = data;
481      }
482      break;
483
484   case 0x1d:                     /* sprite x size */
485      if (vic2.reg[offset] != data)
486      {
487         vic2.reg[offset] = data;
488      }
489      break;
490
491   case 0x1b:                     /* sprite background priority */
492      if (vic2.reg[offset] != data)
493      {
494         vic2.reg[offset] = data;
495      }
496      break;
497
498   case 0x1c:                     /* sprite multicolor mode select */
499      if (vic2.reg[offset] != data)
500      {
501         vic2.reg[offset] = data;
502      }
503      break;
504
505   case 0x27:
506   case 0x28:
507   case 0x29:
508   case 0x2a:
509   case 0x2b:
510   case 0x2c:
511   case 0x2d:
512   case 0x2e:
513                           /* sprite colors */
514      if (vic2.reg[offset] != data)
515      {
516         vic2.reg[offset] = data;
517      }
518      break;
519
520   case 0x25:                     /* sprite multicolor */
521      if (vic2.reg[offset] != data)
522      {
523         vic2.reg[offset] = data;
524         vic2.spritemulti[1] = SPRITE_MULTICOLOR1;
525      }
526      break;
527
528   case 0x26:                     /* sprite multicolor */
529      if (vic2.reg[offset] != data)
530      {
531         vic2.reg[offset] = data;
532         vic2.spritemulti[3] = SPRITE_MULTICOLOR2;
533      }
534      break;
535
536   case 0x19:
537      vic2_clear_interrupt(space->machine, data & 0x0f);
538      break;
539
540   case 0x1a:                     /* irq mask */
541      vic2.reg[offset] = data;
542      vic2_set_interrupt(space->machine, 0);    // beamrider needs this
543      break;
544
545   case 0x11:
546      if (vic2.reg[offset] != data)
547      {
548         vic2.reg[offset] = data;
549         if (LINES25)
550         {
551            vic2.y_begin = 0;
552            vic2.y_end = vic2.y_begin + 200;
553         }
554         else
555         {
556            vic2.y_begin = 4;
557            vic2.y_end = vic2.y_begin + 192;
558         }
559         if (data & 8) {
560            dy_start = ROW25_YSTART;
561            dy_stop = ROW25_YSTOP;
562         } else {
563            dy_start = ROW24_YSTART;
564            dy_stop = ROW24_YSTOP;
565         }
566      }
567      break;
568
569   case 0x12:
570      if (data != vic2.reg[offset])
571      {
572         vic2.reg[offset] = data;
573      }
574      break;
575
576   case 0x16:
577      if (vic2.reg[offset] != data)
578      {
579         vic2.reg[offset] = data;
580         vic2.x_begin = HORIZONTALPOS;
581         vic2.x_end = vic2.x_begin + 320;
582      }
583      break;
584
585   case 0x18:
586      if (vic2.reg[offset] != data)
587      {
588         vic2.reg[offset] = data;
589         vic2.videoaddr = VIDEOADDR;
590         vic2.chargenaddr = CHARGENADDR;
591         vic2.bitmapaddr = BITMAPADDR;
592      }
593      break;
594
595   case 0x21:                     /* background color */
596      if (vic2.reg[offset] != data)
597      {
598         vic2.reg[offset] = data;
599         vic2.mono[0] = vic2.bitmapmulti[0] = vic2.multi[0] = vic2.colors[0] = BACKGROUNDCOLOR;
600      }
601      break;
602
603   case 0x22:                     /* background color 1 */
604      if (vic2.reg[offset] != data)
605      {
606         vic2.reg[offset] = data;
607         vic2.multi[1] = vic2.colors[1] = MULTICOLOR1;
608      }
609      break;
610
611   case 0x23:                     /* background color 2 */
612      if (vic2.reg[offset] != data)
613      {
614         vic2.reg[offset] = data;
615         vic2.multi[2] = vic2.colors[2] = MULTICOLOR2;
616      }
617      break;
618
619   case 0x24:                     /* background color 3 */
620      if (vic2.reg[offset] != data)
621      {
622         vic2.reg[offset] = data;
623         vic2.colors[3] = FOREGROUNDCOLOR;
624      }
625      break;
626
627   case 0x20:                     /* framecolor */
628      if (vic2.reg[offset] != data)
629      {
630         vic2.reg[offset] = data;
631      }
632      break;
633
634   case 0x2f:
635      if (vic2.vic2e)
636      {
637         DBG_LOG (2, "vic write", ("%.2x:%.2x\n", offset, data));
638         vic2.reg[offset] = data;
639      }
640      break;
641
642   case 0x30:
643      if (vic2.vic2e)
644      {
645         vic2.reg[offset] = data;
646      }
647      break;
648
649   case 0x31:
650   case 0x32:
651   case 0x33:
652   case 0x34:
653   case 0x35:
654   case 0x36:
655   case 0x37:
656   case 0x38:
657   case 0x39:
658   case 0x3a:
659   case 0x3b:
660   case 0x3c:
661   case 0x3d:
662   case 0x3e:
663   case 0x3f:
664      vic2.reg[offset] = data;
665      DBG_LOG (2, "vic write", ("%.2x:%.2x\n", offset, data));
666      break;
667
668   default:
669      vic2.reg[offset] = data;
670      break;
357      vic2->spr_data[num][bytenum] = vic2->dma_read(machine, (vic2->mc[num] & 0x3f) | vic2->spr_ptr[num]);
358      vic2->mc[num]++;
671359   }
360   else
361      if (bytenum == 1)
362         vic2_idle_access(machine, vic2);
672363}
673364
674READ8_HANDLER ( vic2_port_r )
365// Turn on display if Bad Line
366INLINE void vic2_display_if_bad_line( vic2_state *vic2 )
675367{
676   running_machine *machine = space->machine;
677   int val = 0;
678   offset &= 0x3f;
368   if (vic2->is_bad_line)
369      vic2->display_state = 1;
370}
679371
680   switch (offset)
372// Suspend CPU
373INLINE void vic2_suspend_cpu( running_machine *machine, vic2_state *vic2 )
374{
375   if (vic2->cpu_suspended == 0)
681376   {
682   case 0x11:
683      val = (vic2.reg[offset] & ~0x80) | ((vic2.rasterline & 0x100) >> 1);
684      break;
685
686   case 0x12:
687      val = vic2.rasterline & 0xff;
688      break;
689
690   case 0x16:
691      val = vic2.reg[offset] | 0xc0;
692      break;
693
694   case 0x18:
695      val = vic2.reg[offset] | 0x01;
696      break;
697
698   case 0x19:                     /* interrupt flag register */
699      /* vic2_clear_interrupt(0xf); */
700      val = vic2.reg[offset] | 0x70;
701      break;
702
703   case 0x1a:
704      val = vic2.reg[offset] | 0xf0;
705      break;
706
707   case 0x1e:                     /* sprite to sprite collision detect */
708      val = vic2.reg[offset];
709      vic2.reg[offset] = 0;
710      vic2_clear_interrupt(space->machine, 4);
711      break;
712
713   case 0x1f:                     /* sprite to background collision detect */
714      val = vic2.reg[offset];
715      vic2.reg[offset] = 0;
716      vic2_clear_interrupt(space->machine, 2);
717      break;
718
719   case 0x20:
720   case 0x21:
721   case 0x22:
722   case 0x23:
723   case 0x24:
724      val = vic2.reg[offset];
725      break;
726
727   case 0x00:
728   case 0x01:
729   case 0x02:
730   case 0x03:
731   case 0x04:
732   case 0x05:
733   case 0x06:
734   case 0x07:
735   case 0x08:
736   case 0x09:
737   case 0x0a:
738   case 0x0b:
739   case 0x0c:
740   case 0x0d:
741   case 0x0e:
742   case 0x0f:
743   case 0x10:
744   case 0x17:
745   case 0x1b:
746   case 0x1c:
747   case 0x1d:
748   case 0x25:
749   case 0x26:
750   case 0x27:
751   case 0x28:
752   case 0x29:
753   case 0x2a:
754   case 0x2b:
755   case 0x2c:
756   case 0x2d:
757   case 0x2e:
758      val = vic2.reg[offset];
759      break;
760
761   case 0x2f:
762   case 0x30:
763      if (vic2.vic2e)
764      {
765         val = vic2.reg[offset];
766         DBG_LOG (2, "vic read", ("%.2x:%.2x\n", offset, val));
767      }
768      else
769         val = 0xff;
770      break;
771
772   case 0x31:
773   case 0x32:
774   case 0x33:
775   case 0x34:
776   case 0x35:
777   case 0x36:
778   case 0x37:
779   case 0x38:
780   case 0x39:
781   case 0x3a:
782   case 0x3b:
783   case 0x3c:
784   case 0x3d:
785   case 0x3e:
786   case 0x3f:                     /* not used */
787      // val = vic2.reg[offset]; //
788      val = 0xff;
789      DBG_LOG (2, "vic read", ("%.2x:%.2x\n", offset, val));
790      break;
791
792   default:
793      val = vic2.reg[offset];
377      vic2->first_ba_cycle = vic2->cycles_counter;
378      if (vic2->rdy_workaround_cb != NULL && vic2->rdy_workaround_cb(machine))
379         cpu_suspend(machine->firstcpu, SUSPEND_REASON_SPIN, 0);
380      vic2->cpu_suspended = 1;
794381   }
795
796   if ((offset != 0x11) && (offset != 0x12))
797      DBG_LOG (2, "vic read", ("%.2x:%.2x\n", offset, val));
798   return val;
799382}
800383
801VIDEO_START( vic2 )
384// Resume CPU
385INLINE void vic2_resume_cpu( running_machine *machine, vic2_state *vic2 )
802386{
803   int i;
804   running_device *screen = video_screen_first(machine);
805   int width = video_screen_get_width(screen);
806   int height = video_screen_get_height(screen);
807
808   for (i = 0; i < ARRAY_LENGTH(mc); i++)
809      mc[i] = 63;
810
811   vic2.bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
812
813   if (vic2.vic3) {
814      vic2.screen[0] = auto_alloc_array(machine, UINT8, 216 * 656 / 8);
815
816      for (i = 1; i < 216; i++)
817         vic2.screen[i] = vic2.screen[i - 1] + 656 / 8;
818   } else {
819      vic2.screen[0] = auto_alloc_array(machine, UINT8, 216 * 336 / 8);
820
821      for (i = 1; i < 216; i++)
822         vic2.screen[i] = vic2.screen[i - 1] + 336 / 8;
823   }
824
825   for (i = 0; i < 256; i++)
387   if (vic2->cpu_suspended == 1)
826388   {
827      vic2.foreground[i] = 0;
828      if ((i & 3) > 1)
829         vic2.foreground[i] |= 0x3;
830      if ((i & 0xc) > 0x4)
831         vic2.foreground[i] |= 0xc;
832      if ((i & 0x30) > 0x10)
833         vic2.foreground[i] |= 0x30;
834      if ((i & 0xc0) > 0x40)
835         vic2.foreground[i] |= 0xc0;
389      if (vic2->rdy_workaround_cb != NULL && vic2->rdy_workaround_cb(machine))
390         cpu_resume(machine->firstcpu, SUSPEND_REASON_SPIN);
391      vic2->cpu_suspended = 0;
836392   }
837   for (i = 0; i < 256; i++)
838   {
839      vic2.expandx[i] = 0;
840      if (i & 1)
841         vic2.expandx[i] |= 3;
842      if (i & 2)
843         vic2.expandx[i] |= 0xc;
844      if (i & 4)
845         vic2.expandx[i] |= 0x30;
846      if (i & 8)
847         vic2.expandx[i] |= 0xc0;
848      if (i & 0x10)
849         vic2.expandx[i] |= 0x300;
850      if (i & 0x20)
851         vic2.expandx[i] |= 0xc00;
852      if (i & 0x40)
853         vic2.expandx[i] |= 0x3000;
854      if (i & 0x80)
855         vic2.expandx[i] |= 0xc000;
856   }
857   for (i = 0; i < 256; i++)
858   {
859      vic2.expandx_multi[i] = 0;
860      if (i & 1)
861         vic2.expandx_multi[i] |= 5;
862      if (i & 2)
863         vic2.expandx_multi[i] |= 0xa;
864      if (i & 4)
865         vic2.expandx_multi[i] |= 0x50;
866      if (i & 8)
867         vic2.expandx_multi[i] |= 0xa0;
868      if (i & 0x10)
869         vic2.expandx_multi[i] |= 0x500;
870      if (i & 0x20)
871         vic2.expandx_multi[i] |= 0xa00;
872      if (i & 0x40)
873         vic2.expandx_multi[i] |= 0x5000;
874      if (i & 0x80)
875         vic2.expandx_multi[i] |= 0xa000;
876   }
877   for (i = 0; i < 256; i++)
878   {
879      vic2.multi_collision[i] = 0;
880      if (i & 3)
881         vic2.multi_collision[i] |= 3;
882      if (i & 0xc)
883         vic2.multi_collision[i] |= 0xc;
884      if (i & 0x30)
885         vic2.multi_collision[i] |= 0x30;
886      if (i & 0xc0)
887         vic2.multi_collision[i] |= 0xc0;
888   }
393}
889394
890   // from 0 to 311 (0 first, PAL) or from 0 to 261 (? first, NTSC 6567R56A) or from 0 to 262 (? first, NTSC 6567R8)
891   vic2.rasterline = 0; // VIC2_LINES - 1;
395// Refresh access
396INLINE void vic2_refresh_access( running_machine *machine, vic2_state *vic2 )
397{
398   vic2->dma_read(machine, 0x3f00 | vic2->ref_cnt--);
399}
892400
893   // from 1 to 63 (PAL) or from 1 to 65 (NTSC)
894   vic2.rasterX = 63;
895401
896   // immediately call the timer to handle the first line
897   if (vic2.pal)
898      timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 0), NULL, 0, PAL_timer_callback);
899   else
900      timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 0), NULL, 0, NTSC_timer_callback);
402INLINE void vic2_fetch_if_bad_line( vic2_state *vic2 )
403{
404   if (vic2->is_bad_line)
405      vic2->display_state = 1;
901406}
902407
903static void vic2_draw_character (running_machine *machine, int ybegin, int yend, int ch, int yoff, int xoff, UINT16 *color, int start_x, int end_x)
904{
905   int y, code;
906408
907   for (y = ybegin; y <= yend; y++)
409// Turn on display and matrix access and reset RC if Bad Line
410INLINE void vic2_rc_if_bad_line( vic2_state *vic2 )
411{
412   if (vic2->is_bad_line)
908413   {
909      code = vic2.dma_read(machine, vic2.chargenaddr + ch * 8 + y);
910      vic2.screen[y + yoff][xoff >> 3] = code;
911      if ((xoff + 0 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 0) = color[code >> 7];
912      if ((xoff + 1 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 1) = color[(code >> 6) & 1];
913      if ((xoff + 2 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 2) = color[(code >> 5) & 1];
914      if ((xoff + 3 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 3) = color[(code >> 4) & 1];
915      if ((xoff + 4 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 4) = color[(code >> 3) & 1];
916      if ((xoff + 5 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 5) = color[(code >> 2) & 1];
917      if ((xoff + 6 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 6) = color[(code >> 1) & 1];
918      if ((xoff + 7 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 7) = color[code & 1];
414      vic2->display_state = 1;
415      vic2->rc = 0;
919416   }
920417}
921418
922static void vic2_draw_character_multi(running_machine *machine, int ybegin, int yend, int ch, int yoff, int xoff, int start_x, int end_x )
419// Sample border color and increment vic2->graphic_x
420INLINE void vic2_sample_border( vic2_state *vic2 )
923421{
924   int y, code;
925
926   for (y = ybegin; y <= yend; y++)
422   if (vic2->draw_this_line)
927423   {
928      code = vic2.dma_read(machine, vic2.chargenaddr + ch * 8 + y);
929      vic2.screen[y + yoff][xoff >> 3] = vic2.foreground[code];
930      if ((xoff + 0 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 0) = vic2.multi[code >> 6];
931      if ((xoff + 1 > start_x) && (xoff + 1 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 1) = vic2.multi[code >> 6];
932      if ((xoff + 2 > start_x) && (xoff + 2 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 2) = vic2.multi[(code >> 4) & 3];
933      if ((xoff + 3 > start_x) && (xoff + 3 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 3) = vic2.multi[(code >> 4) & 3];
934      if ((xoff + 4 > start_x) && (xoff + 4 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 4) = vic2.multi[(code >> 2) & 3];
935      if ((xoff + 5 > start_x) && (xoff + 5 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 5) = vic2.multi[(code >> 2) & 3];
936      if ((xoff + 6 > start_x) && (xoff + 6 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 6) = vic2.multi[code & 3];
937      if ((xoff + 7 > start_x) && (xoff + 7 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 7) = vic2.multi[code & 3];
424      if (vic2->border_on)
425         vic2->border_color_sample[vic2->cycle - 13] = FRAMECOLOR;
426      vic2->graphic_x += 8;
938427   }
939428}
940429
941static void vic2_draw_bitmap(running_machine *machine, int ybegin, int yend, int ch, int yoff, int xoff, int start_x, int end_x)
430
431// Turn on sprite DMA if necessary
432INLINE void vic2_check_sprite_dma( vic2_state *vic2 )
942433{
943   int y, code;
434   int i;
435   UINT8 mask = 1;
944436
945   for (y = ybegin; y <= yend; y++)
437   for (i = 0; i < 8; i++, mask <<= 1)
438      if (SPRITEON(i) && ((vic2->rasterline & 0xff) == SPRITE_Y_POS(i)))
439      {
440         vic2->spr_dma_on |= mask;
441         vic2->mc_base[i] = 0;
442         if (SPRITE_Y_EXPAND(i))
443            vic2->spr_exp_y &= ~mask;
444      }
445}
446
447// Video matrix access
448INLINE void vic2_matrix_access( running_machine *machine, vic2_state *vic2 )
449{
450   if (vic2->cpu_suspended == 1)
946451   {
947      code = vic2.dma_read(machine, (vic2.chargenaddr&0x2000) + ch * 8 + y);
948      vic2.screen[y + yoff][xoff >> 3] = code;
949      if ((xoff + 0 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 0) = vic2.c64_bitmap[code >> 7];
950      if ((xoff + 1 > start_x) && (xoff + 1 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 1) = vic2.c64_bitmap[(code >> 6) & 1];
951      if ((xoff + 2 > start_x) && (xoff + 2 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 2) = vic2.c64_bitmap[(code >> 5) & 1];
952      if ((xoff + 3 > start_x) && (xoff + 3 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 3) = vic2.c64_bitmap[(code >> 4) & 1];
953      if ((xoff + 4 > start_x) && (xoff + 4 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 4) = vic2.c64_bitmap[(code >> 3) & 1];
954      if ((xoff + 5 > start_x) && (xoff + 5 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 5) = vic2.c64_bitmap[(code >> 2) & 1];
955      if ((xoff + 6 > start_x) && (xoff + 6 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 6) = vic2.c64_bitmap[(code >> 1) & 1];
956      if ((xoff + 7 > start_x) && (xoff + 7 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 7) = vic2.c64_bitmap[code & 1];
452      if ((vic2->cycles_counter - vic2->first_ba_cycle) < 0)
453         vic2->matrix_line[vic2->ml_index] = vic2->color_line[vic2->ml_index] = 0xff;
454      else
455      {
456         UINT16 adr = (vic2->vc & 0x03ff) | VIDEOADDR;
457         vic2->matrix_line[vic2->ml_index] = vic2->dma_read(machine, adr); \
458         vic2->color_line[vic2->ml_index] = vic2->dma_read_color(machine, (adr & 0x03ff)); \
459      }
957460   }
958461}
959462
960static void vic2_draw_bitmap_multi(running_machine *machine, int ybegin, int yend, int ch, int yoff, int xoff, int start_x, int end_x)
463// Graphics data access
464INLINE void vic2_graphics_access( running_machine *machine, vic2_state *vic2 )
961465{
962   int y, code;
963
964   for (y = ybegin; y <= yend; y++)
466   if (vic2->display_state == 1)
965467   {
966      code = vic2.dma_read(machine, (vic2.chargenaddr&0x2000) + ch * 8 + y);
967      vic2.screen[y + yoff][xoff >> 3] = vic2.foreground[code];
968      if ((xoff + 0 > start_x) && (xoff + 0 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 0) = vic2.bitmapmulti[code >> 6];
969      if ((xoff + 1 > start_x) && (xoff + 1 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 1) = vic2.bitmapmulti[code >> 6];
970      if ((xoff + 2 > start_x) && (xoff + 2 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 2) = vic2.bitmapmulti[(code >> 4) & 3];
971      if ((xoff + 3 > start_x) && (xoff + 3 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 3) = vic2.bitmapmulti[(code >> 4) & 3];
972      if ((xoff + 4 > start_x) && (xoff + 4 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 4) = vic2.bitmapmulti[(code >> 2) & 3];
973      if ((xoff + 5 > start_x) && (xoff + 5 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 5) = vic2.bitmapmulti[(code >> 2) & 3];
974      if ((xoff + 6 > start_x) && (xoff + 6 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 6) = vic2.bitmapmulti[code & 3];
975      if ((xoff + 7 > start_x) && (xoff + 7 < end_x)) *BITMAP_ADDR16(vic2.bitmap, y + yoff + FIRSTLINE, xoff + 7) = vic2.bitmapmulti[code & 3];
468      UINT16 adr;
469      if (HIRESON)
470         adr = ((vic2->vc & 0x03ff) << 3) | vic2->bitmapaddr | vic2->rc;
471      else
472         adr = (vic2->matrix_line[vic2->ml_index] << 3) | vic2->chargenaddr | vic2->rc;
473      if (ECMON)
474         adr &= 0xf9ff;
475      vic2->gfx_data = vic2->dma_read(machine, adr);
476      vic2->char_data = vic2->matrix_line[vic2->ml_index];
477      vic2->color_data = vic2->color_line[vic2->ml_index];
478      vic2->ml_index++;
479      vic2->vc++;
976480   }
481   else
482   {
483      vic2->gfx_data = vic2->dma_read(machine, (ECMON ? 0x39ff : 0x3fff));
484      vic2->char_data = 0;
485   }
977486}
978487
979static void vic2_draw_sprite_code_multi(running_machine *machine, int y, int xbegin, int code, int prior, int start_x, int end_x)
488INLINE void vic2_draw_background( vic2_state *vic2 )
980489{
981   register int x, mask, shift;
490   if (vic2->draw_this_line)
491   {
492      UINT8 c;
982493
983   if ((y < YPOS) || (y >= (VIC2_STARTVISIBLELINES + VIC2_VISIBLELINES)) || (xbegin <= 1) || (xbegin >= (VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS)))
494      switch (GFXMODE)
984495      {
985         return;
986      }
987
988   for (x = 0, mask = 0xc0, shift = 6; x < 8; x += 2, mask >>= 2, shift -= 2)
989   {
990      if (code & mask)
991      {
992         switch ((prior & mask) >> shift)
993         {
496         case 0:
994497         case 1:
995            if ((xbegin + x + 1 > start_x) && (xbegin + x + 1 < end_x))
996               *BITMAP_ADDR16(vic2.bitmap, y + FIRSTLINE, xbegin + x + 1) = vic2.spritemulti[(code >> shift) & 3];
498         case 3:
499            c = vic2->colors[0];
997500            break;
998501         case 2:
999            if ((xbegin + x > start_x) && (xbegin + x < end_x))
1000               *BITMAP_ADDR16(vic2.bitmap, y + FIRSTLINE, xbegin + x) = vic2.spritemulti[(code >> shift) & 3];
502            c = vic2->last_char_data & 0x0f;
1001503            break;
1002         case 3:
1003            if ((xbegin + x > start_x) && (xbegin + x < end_x))
1004               *BITMAP_ADDR16(vic2.bitmap, y + FIRSTLINE, xbegin + x) = vic2.spritemulti[(code >> shift) & 3];
1005            if ((xbegin + x + 1> start_x) && (xbegin + x + 1< end_x))
1006               *BITMAP_ADDR16(vic2.bitmap, y + FIRSTLINE, xbegin + x + 1) = vic2.spritemulti[(code >> shift) & 3];
504         case 4:
505            if (vic2->last_char_data & 0x80)
506               if (vic2->last_char_data & 0x40)
507                  c = vic2->colors[3];
508               else
509                  c = vic2->colors[2];
510            else
511               if (vic2->last_char_data & 0x40)
512                  c = vic2->colors[1];
513               else
514                  c = vic2->colors[0];
1007515            break;
1008         }
516         default:
517            c = 0;
518            break;
1009519      }
520      plot_box(vic2->bitmap, vic2->graphic_x, VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, c);
1010521   }
1011522}
1012523
1013static void vic2_draw_sprite_code (int y, int xbegin, int code, int color, int start_x, int end_x)
524INLINE void vic2_draw_mono( vic2_state *vic2, UINT16 p, UINT8 c0, UINT8 c1 )
1014525{
1015   register int mask, x;
526   UINT8 c[2];
527   UINT8 data = vic2->gfx_data;
1016528
1017   if ((y < YPOS) || (y >= (VIC2_STARTVISIBLELINES + VIC2_VISIBLELINES)) || (xbegin <= 1) || (xbegin >= (VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS)))
1018      return;
529   c[0] = c0;
530   c[1] = c1;
1019531
1020   for (x = 0, mask = 0x80; x < 8; x++, mask >>= 1)
1021   {
1022      if (code & mask)
1023      {
1024         if ((xbegin + x > start_x) && (xbegin + x < end_x))
1025            *BITMAP_ADDR16(vic2.bitmap, y + FIRSTLINE, xbegin + x) = color;
1026      }
1027   }
532   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 7) = c[data & 1];
533   vic2->fore_coll_buf[p + 7] = data & 1; data >>= 1;
534   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 6) = c[data & 1];
535   vic2->fore_coll_buf[p + 6] = data & 1; data >>= 1;
536   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 5) = c[data & 1];
537   vic2->fore_coll_buf[p + 5] = data & 1; data >>= 1;
538   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 4) = c[data & 1];
539   vic2->fore_coll_buf[p + 4] = data & 1; data >>= 1;
540   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 3) = c[data & 1];
541   vic2->fore_coll_buf[p + 3] = data & 1; data >>= 1;
542   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 2) = c[data & 1];
543   vic2->fore_coll_buf[p + 2] = data & 1; data >>= 1;
544   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 1) = c[data & 1];
545   vic2->fore_coll_buf[p + 1] = data & 1; data >>= 1;
546   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 0) = c[data];
547   vic2->fore_coll_buf[p + 0] = data & 1;
1028548}
1029549
1030static void vic2_sprite_collision (running_machine *machine, int nr, int y, int x, int mask)
550INLINE void vic2_draw_multi( vic2_state *vic2, UINT16 p, UINT8 c0, UINT8 c1, UINT8 c2, UINT8 c3 )
1031551{
1032   int i, value, xdiff;
552   UINT8 c[4];
553   UINT8 data = vic2->gfx_data;
1033554
1034   for (i = 7; i > nr; i--)
1035   {
1036      if (!SPRITEON (i)
1037         || !vic2.sprites[i].paintedline[y]
1038         || (SPRITE_COLLISION (i) && SPRITE_COLLISION (nr)))
1039         continue;
1040      if ((x + 7 < SPRITE_X_POS (i))
1041         || (x >= SPRITE_X_POS (i) + SPRITE_X_SIZE (i)))
1042         continue;
1043      xdiff = x - SPRITE_X_POS (i);
1044      if ((x & 7) == (SPRITE_X_POS (i) & 7))
1045         value = vic2.sprites[i].bitmap[y][xdiff >> 3];
1046      else if (xdiff < 0)
1047         value = vic2.sprites[i].bitmap[y][0] >> (-xdiff);
1048      else {
1049         UINT8 *vp = vic2.sprites[i].bitmap[y]+(xdiff>>3);
1050         value = ((vp[1] | (*vp << 8)) >> (8 - (xdiff&7) )) & 0xff;
1051      }
1052      if (value & mask)
1053      {
1054         SPRITE_SET_COLLISION (i);
1055         SPRITE_SET_COLLISION (nr);
1056         vic2_set_interrupt(machine, 4);
1057      }
1058   }
555   c[0] = c0;
556   c[1] = c1;
557   c[2] = c2;
558   c[3] = c3;
559
560   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 7) = c[data & 3];
561   vic2->fore_coll_buf[p + 7] = data & 2;
562   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 6) = c[data & 3];
563   vic2->fore_coll_buf[p + 6] = data & 2; data >>= 2;
564   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 5) = c[data & 3];
565   vic2->fore_coll_buf[p + 5] = data & 2;
566   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 4) = c[data & 3];
567   vic2->fore_coll_buf[p + 4] = data & 2; data >>= 2;
568   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 3) = c[data & 3];
569   vic2->fore_coll_buf[p + 3] = data & 2;
570   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 2) = c[data & 3];
571   vic2->fore_coll_buf[p + 2] = data & 2; data >>= 2;
572   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 1) = c[data];
573   vic2->fore_coll_buf[p + 1] = data & 2;
574   *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 0) = c[data];
575   vic2->fore_coll_buf[p + 0] = data & 2;
1059576}
1060577
1061static void vic2_draw_sprite_multi(running_machine *machine, int nr, int yoff, int ybegin, int yend, int start_x, int end_x)
578// Graphics display (8 pixels)
579static void vic2_draw_graphics( vic2_state *vic2 )
1062580{
1063   int y, i, prior, addr, xbegin, collision;
1064   int value, value2, value3 = 0, bg, color[2];
1065
1066   xbegin = SPRITE_X_POS (nr);
1067   addr = vic2.dma_read(machine, SPRITE_ADDR (nr)) << 6;
1068   vic2.spritemulti[2] = SPRITE_COLOR (nr);
1069   prior = SPRITE_PRIORITY (nr);
1070   collision = SPRITE_BG_COLLISION (nr);
1071   color[0] = 0;
1072   color[1] = 1;
1073
1074   if (SPRITE_X_EXPAND (nr))
581   if (vic2->draw_this_line == 0)
1075582   {
1076      for (y = ybegin; y <= yend; y++)
1077      {
1078         vic2.sprites[nr].paintedline[y] = 1;
1079         for (i = 0; i < 3; i++)
1080         {
1081            value = vic2.expandx_multi[bg = vic2.dma_read(machine, addr + vic2.sprites[nr].line * 3 + i)];
1082            value2 = vic2.expandx[vic2.multi_collision[bg]];
1083            vic2.sprites[nr].bitmap[y][i*2] = value2 >> 8;
1084            vic2.sprites[nr].bitmap[y][i*2+1] = value2 & 0xff;
1085            vic2_sprite_collision(machine, nr, y, xbegin + i * 16, value2 >> 8);
1086            vic2_sprite_collision(machine, nr, y, xbegin + i * 16 + 8, value2 & 0xff);
1087            if (prior || !collision)
1088            {
1089               value3 = vic2_getforeground16 (yoff + y, xbegin + i * 16 - 7);
1090            }
1091            if (!collision && (value2 & value3))
1092            {
1093               collision = 1;
1094               SPRITE_SET_BG_COLLISION (nr);
1095               vic2_set_interrupt(machine, 2);
1096            }
1097            if (prior)
1098            {
1099               vic2_draw_sprite_code_multi (machine, yoff + y, xbegin + i * 16, value >> 8, (value3 >> 8) ^ 0xff, start_x, end_x);
1100               vic2_draw_sprite_code_multi (machine, yoff + y, xbegin + i * 16 + 8, value & 0xff, (value3 & 0xff) ^ 0xff, start_x, end_x);
1101            }
1102            else
1103            {
1104               vic2_draw_sprite_code_multi (machine, yoff + y, xbegin + i * 16, value >> 8, 0xff, start_x, end_x);
1105               vic2_draw_sprite_code_multi (machine, yoff + y, xbegin + i * 16 + 8, value & 0xff, 0xff, start_x, end_x);
1106            }
1107         }
1108         vic2.sprites[nr].bitmap[y][i*2]=0; //easier sprite collision detection
1109         if (SPRITE_Y_EXPAND (nr))
1110         {
1111            if (vic2.sprites[nr].repeat)
1112            {
1113               vic2.sprites[nr].line++;
1114               vic2.sprites[nr].repeat = 0;
1115            }
1116            else
1117               vic2.sprites[nr].repeat = 1;
1118         }
1119         else
1120         {
1121            vic2.sprites[nr].line++;
1122         }
1123      }
583      UINT16 p = vic2->graphic_x + HORIZONTALPOS;
584      vic2->fore_coll_buf[p + 7] = 0;
585      vic2->fore_coll_buf[p + 6] = 0;
586      vic2->fore_coll_buf[p + 5] = 0;
587      vic2->fore_coll_buf[p + 4] = 0;
588      vic2->fore_coll_buf[p + 3] = 0;
589      vic2->fore_coll_buf[p + 2] = 0;
590      vic2->fore_coll_buf[p + 1] = 0;
591      vic2->fore_coll_buf[p + 0] = 0;
1124592   }
1125   else
593   else if (vic2->ud_border_on)
1126594   {
1127      for (y = ybegin; y <= yend; y++)
1128      {
1129         vic2.sprites[nr].paintedline[y] = 1;
1130         for (i = 0; i < 3; i++)
1131         {
1132            value = vic2.dma_read(machine, addr + vic2.sprites[nr].line * 3 + i);
1133            vic2.sprites[nr].bitmap[y][i] =
1134               value2 = vic2.multi_collision[value];
1135            vic2_sprite_collision(machine, nr, y, xbegin + i * 8, value2);
1136            if (prior || !collision)
1137            {
1138               value3 = vic2_getforeground (yoff + y, xbegin + i * 8 - 7);
1139            }
1140            if (!collision && (value2 & value3))
1141            {
1142               collision = 1;
1143               SPRITE_SET_BG_COLLISION (nr);
1144               vic2_set_interrupt(machine, 2);
1145            }
1146            if (prior)
1147            {
1148               vic2_draw_sprite_code_multi(machine, yoff + y, xbegin + i * 8, value, value3 ^ 0xff, start_x, end_x);
1149            }
1150            else
1151            {
1152               vic2_draw_sprite_code_multi(machine, yoff + y, xbegin + i * 8, value, 0xff, start_x, end_x);
1153            }
1154         }
1155         vic2.sprites[nr].bitmap[y][i]=0; //easier sprite collision detection
1156         if (SPRITE_Y_EXPAND (nr))
1157         {
1158            if (vic2.sprites[nr].repeat)
1159            {
1160               vic2.sprites[nr].line++;
1161               vic2.sprites[nr].repeat = 0;
1162            }
1163            else
1164               vic2.sprites[nr].repeat = 1;
1165         }
1166         else
1167         {
1168            vic2.sprites[nr].line++;
1169         }
1170      }
595      UINT16 p = vic2->graphic_x + HORIZONTALPOS;
596      vic2->fore_coll_buf[p + 7] = 0;
597      vic2->fore_coll_buf[p + 6] = 0;
598      vic2->fore_coll_buf[p + 5] = 0;
599      vic2->fore_coll_buf[p + 4] = 0;
600      vic2->fore_coll_buf[p + 3] = 0;
601      vic2->fore_coll_buf[p + 2] = 0;
602      vic2->fore_coll_buf[p + 1] = 0;
603      vic2->fore_coll_buf[p + 0] = 0;
604      vic2_draw_background(vic2);
1171605   }
1172}
1173
1174static void vic2_draw_sprite(running_machine *machine, int nr, int yoff, int ybegin, int yend, int start_x, int end_x)
1175{
1176   int y, i, addr, xbegin, color, prior, collision;
1177   int value, value3 = 0;
1178
1179   xbegin = SPRITE_X_POS (nr);
1180   addr = vic2.dma_read(machine, SPRITE_ADDR (nr)) << 6;
1181   color = SPRITE_COLOR (nr);
1182   prior = SPRITE_PRIORITY (nr);
1183   collision = SPRITE_BG_COLLISION (nr);
1184
1185   if (SPRITE_X_EXPAND (nr))
1186   {
1187      for (y = ybegin; y <= yend; y++)
1188      {
1189         vic2.sprites[nr].paintedline[y] = 1;
1190         for (i = 0; i < 3; i++)
1191         {
1192            value = vic2.expandx[vic2.dma_read(machine, addr + vic2.sprites[nr].line * 3 + i)];
1193            vic2.sprites[nr].bitmap[y][i*2] = value>>8;
1194            vic2.sprites[nr].bitmap[y][i*2+1] = value&0xff;
1195            vic2_sprite_collision(machine, nr, y, xbegin + i * 16, value >> 8);
1196            vic2_sprite_collision(machine, nr, y, xbegin + i * 16 + 8, value & 0xff);
1197            if (prior || !collision)
1198               value3 = vic2_getforeground16 (yoff + y, xbegin + i * 16 - 7);
1199            if (!collision && (value & value3))
1200            {
1201               collision = 1;
1202               SPRITE_SET_BG_COLLISION (nr);
1203               vic2_set_interrupt(machine, 2);
1204            }
1205            if (prior)
1206               value &= ~value3;
1207            vic2_draw_sprite_code (yoff + y, xbegin + i * 16, value >> 8, color, start_x, end_x);
1208            vic2_draw_sprite_code (yoff + y, xbegin + i * 16 + 8, value & 0xff, color, start_x, end_x);
1209         }
1210         vic2.sprites[nr].bitmap[y][i*2]=0; //easier sprite collision detection
1211         if (SPRITE_Y_EXPAND (nr))
1212         {
1213            if (vic2.sprites[nr].repeat)
1214            {
1215               vic2.sprites[nr].line++;
1216               vic2.sprites[nr].repeat = 0;
1217            }
1218            else
1219               vic2.sprites[nr].repeat = 1;
1220         }
1221         else
1222         {
1223            vic2.sprites[nr].line++;
1224         }
1225      }
1226   }
1227606   else
1228607   {
1229      for (y = ybegin; y <= yend; y++)
608      UINT8 tmp_col;
609      UINT16 p = vic2->graphic_x + HORIZONTALPOS;
610      switch (GFXMODE)
1230611      {
1231         vic2.sprites[nr].paintedline[y] = 1;
1232         for (i = 0; i < 3; i++)
1233         {
1234            value = vic2.dma_read(machine, addr + vic2.sprites[nr].line * 3 + i);
1235            vic2.sprites[nr].bitmap[y][i] = value;
1236            vic2_sprite_collision(machine, nr, y, xbegin + i * 8, value);
1237            if (prior || !collision)
1238               value3 = vic2_getforeground (yoff + y, xbegin + i * 8 - 7);
1239            if (!collision && (value & value3))
1240            {
1241               collision = 1;
1242               SPRITE_SET_BG_COLLISION (nr);
1243               vic2_set_interrupt(machine, 2);
1244            }
1245            if (prior)
1246               value &= ~value3;
1247            vic2_draw_sprite_code (yoff + y, xbegin + i * 8, value, color, start_x, end_x);
1248         }
1249         vic2.sprites[nr].bitmap[y][i]=0; //easier sprite collision detection
1250         if (SPRITE_Y_EXPAND (nr))
1251         {
1252            if (vic2.sprites[nr].repeat)
1253            {
1254               vic2.sprites[nr].line++;
1255               vic2.sprites[nr].repeat = 0;
1256            }
612         case 0:
613            vic2_draw_mono(vic2, p, vic2->colors[0], vic2->color_data & 0x0f);
614            break;
615         case 1:
616            if (vic2->color_data & 0x08)
617               vic2_draw_multi(vic2, p, vic2->colors[0], vic2->colors[1], vic2->colors[2], vic2->color_data & 0x07);
1257618            else
1258               vic2.sprites[nr].repeat = 1;
1259         }
1260         else
1261         {
1262            vic2.sprites[nr].line++;
1263         }
619               vic2_draw_mono(vic2, p, vic2->colors[0], vic2->color_data & 0x0f);
620            break;
621         case 2:
622            vic2_draw_mono(vic2, p, vic2->char_data & 0x0f, vic2->char_data >> 4);
623            break;
624         case 3:
625            vic2_draw_multi(vic2, p, vic2->colors[0], vic2->char_data >> 4, vic2->char_data & 0x0f, vic2->color_data & 0x0f);
626            break;
627         case 4:
628            if (vic2->char_data & 0x80)
629               if (vic2->char_data & 0x40)
630                  tmp_col = vic2->colors[3];
631               else
632                  tmp_col = vic2->colors[2];
633            else
634               if (vic2->char_data & 0x40)
635                  tmp_col = vic2->colors[1];
636               else
637                  tmp_col = vic2->colors[0];
638            vic2_draw_mono(vic2, p, tmp_col, vic2->color_data & 0x0f);
639            break;
640         case 5:
641            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 7) = 0;
642            vic2->fore_coll_buf[p + 7] = 0;
643            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 6) = 0;
644            vic2->fore_coll_buf[p + 6] = 0;
645            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 5) = 0;
646            vic2->fore_coll_buf[p + 5] = 0;
647            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 4) = 0;
648            vic2->fore_coll_buf[p + 4] = 0;
649            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 3) = 0;
650            vic2->fore_coll_buf[p + 3] = 0;
651            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 2) = 0;
652            vic2->fore_coll_buf[p + 2] = 0;
653            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 1) = 0;
654            vic2->fore_coll_buf[p + 1] = 0;
655            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 0) = 0;
656            vic2->fore_coll_buf[p + 0] = 0;
657            break;
658         case 6:
659            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 7) = 0;
660            vic2->fore_coll_buf[p + 7] = 0;
661            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 6) = 0;
662            vic2->fore_coll_buf[p + 6] = 0;
663            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 5) = 0;
664            vic2->fore_coll_buf[p + 5] = 0;
665            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 4) = 0;
666            vic2->fore_coll_buf[p + 4] = 0;
667            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 3) = 0;
668            vic2->fore_coll_buf[p + 3] = 0;
669            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 2) = 0;
670            vic2->fore_coll_buf[p + 2] = 0;
671            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 1) = 0;
672            vic2->fore_coll_buf[p + 1] = 0;
673            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 0) = 0;
674            vic2->fore_coll_buf[p + 0] = 0;
675            break;
676         case 7:
677            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 7) = 0;
678            vic2->fore_coll_buf[p + 7] = 0;
679            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 6) = 0;
680            vic2->fore_coll_buf[p + 6] = 0;
681            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 5) = 0;
682            vic2->fore_coll_buf[p + 5] = 0;
683            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 4) = 0;
684            vic2->fore_coll_buf[p + 4] = 0;
685            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 3) = 0;
686            vic2->fore_coll_buf[p + 3] = 0;
687            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 2) = 0;
688            vic2->fore_coll_buf[p + 2] = 0;
689            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 1) = 0;
690            vic2->fore_coll_buf[p + 1] = 0;
691            *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + 0) = 0;
692            vic2->fore_coll_buf[p + 0] = 0;
693            break;
1264694      }
1265695   }
1266696}
1267697
1268static void vic3_drawlines (running_machine *machine, int first, int last, int start_x, int end_x);
1269
1270static void vic2_drawlines (running_machine *machine, int first, int last, int start_x, int end_x)
698static void vic2_draw_sprites( running_machine *machine, vic2_state *vic2 )
1271699{
1272   int line, vline, end;
1273   int attr, ch, ecm;
1274   int syend;
1275   int offs, yoff, xoff, ybegin, yend, xbegin, xend;
1276700   int i;
701   UINT8 snum, sbit;
702   UINT8 spr_coll = 0, gfx_coll = 0;
703   UINT32 plane0_l, plane0_r, plane1_l, plane1_r;
704   UINT32 sdata_l = 0, sdata_r = 0;
1277705
1278   if (vic2.vic3 && VIC3_BITPLANES) return ;
706   for (i = 0; i < 0x400; i++)
707      vic2->spr_coll_buf[i] = 0;
1279708
1280   /* temporary allowing vic3 displaying 80 columns */
1281   if (vic2.vic3 && (vic2.reg[0x31] & 0x80))
709   for (snum = 0, sbit = 1; snum < 8; snum++, sbit <<= 1)
1282710   {
1283      vic3_drawlines(machine, first, first + 1, start_x, end_x);
1284      return;
1285   }
711      if ((vic2->spr_draw & sbit) && (SPRITE_X_POS(snum) <= (403 - (VIC2_FIRSTCOLUMN + 1))))
712      {
713         UINT16 p = SPRITE_X_POS(snum) + VIC2_X_2_EMU(0) + 8;
714         UINT8 color = SPRITE_COLOR(snum);
715         UINT32 sdata = (vic2->spr_draw_data[snum][0] << 24) | (vic2->spr_draw_data[snum][1] << 16) | (vic2->spr_draw_data[snum][2] << 8);
1286716
1287   if (video_skip_this_frame ())
1288      return;
717         if (SPRITE_X_EXPAND(snum))
718         {
719            if (SPRITE_X_POS(snum) > (403 - 24 - (VIC2_FIRSTCOLUMN + 1)))
720               continue;
1289721
1290   /* top part of display not rastered */
1291   first -= VIC2_YPOS - YPOS;
722            if (SPRITE_MULTICOLOR(snum))
723            {
724               sdata_l = (vic2->expandx_multi[(sdata >> 24) & 0xff] << 16) | vic2->expandx_multi[(sdata >> 16) & 0xff];
725               sdata_r = vic2->expandx_multi[(sdata >> 8) & 0xff] << 16;
726               plane0_l = (sdata_l & 0x55555555) | (sdata_l & 0x55555555) << 1;
727               plane1_l = (sdata_l & 0xaaaaaaaa) | (sdata_l & 0xaaaaaaaa) >> 1;
728               plane0_r = (sdata_r & 0x55555555) | (sdata_r & 0x55555555) << 1;
729               plane1_r = (sdata_r & 0xaaaaaaaa) | (sdata_r & 0xaaaaaaaa) >> 1;
730               for (i = 0; i < 32; i++, plane0_l <<= 1, plane1_l <<= 1)
731               {
732                  UINT8 col;
1292733
1293   xbegin = VIC2_STARTVISIBLECOLUMNS;
1294   xend = xbegin + VIC2_VISIBLECOLUMNS;
1295   if (!SCREENON)
1296   {
1297      xbegin = VIC2_STARTVISIBLECOLUMNS;
1298      xend = xbegin + VIC2_VISIBLECOLUMNS;
1299      if ((start_x <= xbegin) && (end_x >= xend))
1300         plot_box(vic2.bitmap, xbegin, first + FIRSTLINE, xend - xbegin, 1, FRAMECOLOR);
1301      if ((start_x > xbegin) && (end_x >= xend))
1302         plot_box(vic2.bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, xend - start_x, 1, FRAMECOLOR);
1303      if ((start_x <= xbegin) && (end_x < xend))
1304         plot_box(vic2.bitmap, xbegin, first + FIRSTLINE, end_x - xbegin , 1, FRAMECOLOR);
1305      if ((start_x > xbegin) && (end_x < xend))
1306         plot_box(vic2.bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
1307      return;
1308   }
734                  if (plane1_l & 0x80000000)
735                  {
736                     if (vic2->fore_coll_buf[p + i])
737                     {
738                        gfx_coll |= sbit;
739                     }
740                     if (plane0_l & 0x80000000)
741                        col = vic2->spritemulti[3];
742                     else
743                        col = color;
744                  }
745                  else
746                  {
747                     if (plane0_l & 0x80000000)
748                     {
749                        if (vic2->fore_coll_buf[p + i])
750                        {
751                           gfx_coll |= sbit;
752                        }
753                        col = vic2->spritemulti[1];
754                     }
755                     else
756                        continue;
757                  }
1309758
1310   if (COLUMNS40)
1311   {
1312      xbegin = XPOS;
1313      xend = xbegin + 320;
1314   }
1315   else
1316   {
1317      xbegin = XPOS + 7;
1318      xend = xbegin + 304;
1319   }
759                  if (vic2->spr_coll_buf[p + i])
760                     spr_coll |= vic2->spr_coll_buf[p + i] | sbit;
761                  else
762                  {
763                     if (SPRITE_PRIORITY(snum))
764                     {
765                        if (vic2->fore_coll_buf[p + i] == 0)
766                           *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = col;
767                        vic2->spr_coll_buf[p + i] = sbit;
768                     }
769                     else
770                     {
771                        *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = col;
772                        vic2->spr_coll_buf[p + i] = sbit;
773                     }
774                  }
775               }
1320776
1321   if (first + 1 < vic2.y_begin)
1322      end = first + 1;
1323   else
1324      end = vic2.y_begin + YPOS;
777               for (; i < 48; i++, plane0_r <<= 1, plane1_r <<= 1)
778               {
779                  UINT8 col;
1325780
1326   line = first;
1327   // top border
1328   if (line < end)
1329   {
1330      if ((start_x <= xbegin) && (end_x >= xend))
1331         plot_box(vic2.bitmap, xbegin, first + FIRSTLINE, xend - xbegin, 1, FRAMECOLOR);
1332      if ((start_x > xbegin) && (end_x >= xend))
1333         plot_box(vic2.bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, xend - start_x, 1, FRAMECOLOR);
1334      if ((start_x <= xbegin) && (end_x < xend))
1335         plot_box(vic2.bitmap, xbegin, first + FIRSTLINE, end_x - xbegin , 1, FRAMECOLOR);
1336      if ((start_x > xbegin) && (end_x < xend))
1337         plot_box(vic2.bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
1338      line = end;
1339   }
781                  if(plane1_r & 0x80000000)
782                  {
783                     if (vic2->fore_coll_buf[p + i])
784                     {
785                        gfx_coll |= sbit;
786                     }
1340787
1341   vline = line - YPOS + 3 - VERTICALPOS;
788                     if (plane0_r & 0x80000000)
789                        col = vic2->spritemulti[3];
790                     else
791                        col = color;
792                  }
793                  else
794                  {
795                     if (plane0_r & 0x80000000)
796                     {
797                        if (vic2->fore_coll_buf[p + i])
798                        {
799                           gfx_coll |= sbit;
800                        }
801                        col =  vic2->spritemulti[1];
802                     }
803                     else
804                        continue;
805                  }
1342806
1343   if (first + 1 < vic2.y_end + YPOS)
1344      end = first + 1;
1345   else
1346      end = vic2.y_end + YPOS;
807                  if (vic2->spr_coll_buf[p + i])
808                     spr_coll |= vic2->spr_coll_buf[p + i] | sbit;
809                  else
810                  {
811                     if (SPRITE_PRIORITY(snum))
812                     {
813                        if (vic2->fore_coll_buf[p + i] == 0)
814                           *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = col;
815                        vic2->spr_coll_buf[p + i] = sbit;
816                     }
817                     else
818                     {
819                        *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = col;
820                        vic2->spr_coll_buf[p + i] = sbit;
821                     }
822                  }
823               }
824            }
825            else
826            {
827               sdata_l = (vic2->expandx[(sdata >> 24) & 0xff] << 16) | vic2->expandx[(sdata >> 16) & 0xff];
828               sdata_r = vic2->expandx[(sdata >> 8) & 0xff] << 16;
1347829
1348   if (line < end)
1349   {
1350      offs = (vline >> 3) * 40;
1351      ybegin = vline & 7;
1352      yoff = line - ybegin;
1353      yend = (yoff + 7 < end) ? 7 : (end - yoff - 1);
830               for (i = 0; i < 32; i++, sdata_l <<= 1)
831                  if (sdata_l & 0x80000000)
832                  {
833                     if (vic2->fore_coll_buf[p + i])
834                     {
835                        gfx_coll |= sbit;
836                     }
1354837
1355      /* rendering 39 characters */
1356      /* left and right borders are overwritten later */
838                     if (vic2->spr_coll_buf[p + i])
839                        spr_coll |= vic2->spr_coll_buf[p + i] | sbit;
840                     else
841                     {
842                        if (SPRITE_PRIORITY(snum))
843                        {
844                           if (vic2->fore_coll_buf[p + i] == 0)
845                              *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = color;
846                           vic2->spr_coll_buf[p + i] = sbit;
847                        }
848                        else
849                        {
850                           *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = color;
851                           vic2->spr_coll_buf[p + i] = sbit;
852                        }
853                     }
854                  }
1357855
1358      vic2.shift[line] = HORIZONTALPOS;
1359      for (xoff = vic2.x_begin + XPOS; xoff < vic2.x_end + XPOS; xoff += 8, offs++)
1360      {
1361         ch = vic2.dma_read(machine, vic2.videoaddr + offs);
1362#if 0
1363         attr = vic2.dma_read_color(machine, vic2.videoaddr + offs);
1364#else
1365         /* temporaery until vic3 finished */
1366         attr = vic2.dma_read_color(machine, (vic2.videoaddr + offs)&0x3ff)&0x0f;
1367#endif
1368         if (HIRESON)
1369         {
1370            vic2.bitmapmulti[1] = vic2.c64_bitmap[1] = ch >> 4;
1371            vic2.bitmapmulti[2] = vic2.c64_bitmap[0] = ch & 0xf;
1372            if (MULTICOLORON)
1373            {
1374                vic2.bitmapmulti[3] = attr;
1375               vic2_draw_bitmap_multi(machine, ybegin, yend, offs, yoff, xoff, start_x, end_x);
856               for (; i < 48; i++, sdata_r <<= 1)
857                  if (sdata_r & 0x80000000)
858                  {
859                     if (vic2->fore_coll_buf[p + i])
860                     {
861                        gfx_coll |= sbit;
862                     }
863
864                     if (vic2->spr_coll_buf[p + i])
865                        spr_coll |= vic2->spr_coll_buf[p + i] | sbit;
866                     else
867                     {
868                        if (SPRITE_PRIORITY(snum))
869                        {
870                           if (vic2->fore_coll_buf[p + i] == 0)
871                              *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = color;
872                           vic2->spr_coll_buf[p + i] = sbit;
873                        }
874                        else
875                        {
876                           *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = color;
877                           vic2->spr_coll_buf[p + i] = sbit;
878                        }
879                     }
880                  }
1376881            }
1377            else
1378            {
1379               vic2_draw_bitmap(machine, ybegin, yend, offs, yoff, xoff, start_x, end_x);
1380            }
1381882         }
1382         else if (ECMON)
1383         {
1384            ecm = ch >> 6;
1385            vic2.ecmcolor[0] = vic2.colors[ecm];
1386            vic2.ecmcolor[1] = attr;
1387            vic2_draw_character(machine, ybegin, yend, ch & ~0xC0, yoff, xoff, vic2.ecmcolor, start_x, end_x);
1388         }
1389         else if (MULTICOLORON && (attr & 8))
1390         {
1391            vic2.multi[3] = attr & 7;
1392            vic2_draw_character_multi(machine, ybegin, yend, ch, yoff, xoff, start_x, end_x);
1393         }
1394883         else
1395884         {
1396            vic2.mono[1] = attr;
1397            vic2_draw_character(machine, ybegin, yend, ch, yoff, xoff, vic2.mono, start_x, end_x);
1398         }
1399      }
1400
1401      /* sprite priority, sprite overwrites lowerprior pixels */
1402      for (i = 7; i >= 0; i--)
1403      {
1404         if (SPRITEON (i) &&
1405               (yoff + ybegin >= SPRITE_Y_POS (i)) &&
1406               (yoff + ybegin - SPRITE_Y_POS (i) < (SPRITE_Y_EXPAND (i)? 21 * 2 : 21 )) &&
1407               (SPRITE_Y_POS (i) < 0))
1408         {
1409            int wrapped = - SPRITE_Y_POS (i) + 6;
1410
1411            syend = yend;
1412
1413            if (SPRITE_Y_EXPAND (i))
885            if (SPRITE_MULTICOLOR(snum))
1414886            {
1415               if (wrapped & 1) vic2.sprites[i].repeat = 1;
1416               wrapped >>= 1;
1417               syend = 21 * 2 - 1 - wrapped * 2;
1418               if (syend > (yend - ybegin)) syend = yend - ybegin;
1419            }
1420            else
1421            {
1422               syend = 21 - 1 - wrapped;
1423               if (syend > (yend - ybegin)) syend = yend - ybegin;
1424            }
887               UINT32 plane0 = (sdata & 0x55555555) | (sdata & 0x55555555) << 1;
888               UINT32 plane1 = (sdata & 0xaaaaaaaa) | (sdata & 0xaaaaaaaa) >> 1;
1425889
1426            vic2.sprites[i].line = wrapped;
890               for (i = 0; i < 24; i++, plane0 <<= 1, plane1 <<= 1)
891               {
892                  UINT8 col;
1427893
1428            if (SPRITE_MULTICOLOR (i))
1429               vic2_draw_sprite_multi(machine, i, 0, 0 , syend, start_x, end_x);
1430            else
1431               vic2_draw_sprite(machine, i, 0, 0 , syend, start_x, end_x);
1432         }
1433         else if    (SPRITEON (i) &&
1434               (yoff + ybegin >= SPRITE_Y_POS (i)) &&
1435               (yoff + ybegin - SPRITE_Y_POS (i) < (SPRITE_Y_EXPAND (i)? 21 * 2 : 21 )) &&
1436               (SPRITE_Y_POS (i) >= 0))
1437         {
1438            int wrapped = yoff + ybegin - SPRITE_Y_POS (i);
894                  if (plane1 & 0x80000000)
895                  {
896                     if (vic2->fore_coll_buf[p + i])
897                     {
898                        gfx_coll |= sbit;
899                     }
1439900
1440            syend = yend;
901                     if (plane0 & 0x80000000)
902                        col = vic2->spritemulti[3];
903                     else
904                        col = color;
905                  }
906                  else
907                  {
908                     if (vic2->fore_coll_buf[p + i])
909                     {
910                        gfx_coll |= sbit;
911                     }
1441912
1442            if (SPRITE_Y_EXPAND (i))
1443            {
1444               if (wrapped & 1) vic2.sprites[i].repeat = 1;
1445               wrapped >>= 1;
1446               syend = 21 * 2 - 1 - wrapped * 2;
1447               if (syend > (yend - ybegin)) syend = yend - ybegin;
913                     if (plane0 & 0x80000000)
914                        col = vic2->spritemulti[1];
915                     else
916                        continue;
917                  }
918
919                  if (vic2->spr_coll_buf[p + i])
920                     spr_coll |= vic2->spr_coll_buf[p + i] | sbit;
921                  else
922                  {
923                     if (SPRITE_PRIORITY(snum))
924                     {
925                        if (vic2->fore_coll_buf[p + i] == 0)
926                           *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = col;
927                        vic2->spr_coll_buf[p + i] = sbit;
928                     }
929                     else
930                     {
931                        *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = col;
932                        vic2->spr_coll_buf[p + i] = sbit;
933                     }
934                  }
935               }
1448936            }
1449937            else
1450938            {
1451               syend = 21 - 1 - wrapped;
1452               if (syend > (yend - ybegin)) syend = yend - ybegin;
939               for (i = 0; i < 24; i++, sdata <<= 1)
940               {
941                  if (sdata & 0x80000000)
942                  {
943                     if (vic2->fore_coll_buf[p + i])
944                     {
945                        gfx_coll |= sbit;
946                     }
947                     if (vic2->spr_coll_buf[p + i])
948                     {
949                        spr_coll |= vic2->spr_coll_buf[p + i] | sbit;
950                     }
951                     else
952                     {
953                        if (SPRITE_PRIORITY(snum))
954                        {
955                           if (vic2->fore_coll_buf[p + i] == 0)
956                              *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = color;
957                           vic2->spr_coll_buf[p + i] = sbit;
958                        }
959                        else
960                        {
961                           *BITMAP_ADDR16(vic2->bitmap, VIC2_RASTER_2_EMU(vic2->rasterline), p + i) = color;
962                           vic2->spr_coll_buf[p + i] = sbit;
963                        }
964                     }
965                  }
966               }
1453967            }
1454
1455            vic2.sprites[i].line = wrapped;
1456
1457            if (SPRITE_MULTICOLOR (i))
1458               vic2_draw_sprite_multi(machine, i, yoff + ybegin, 0, 0, start_x, end_x);
1459            else
1460               vic2_draw_sprite(machine, i, yoff + ybegin, 0, 0, start_x, end_x);
1461968         }
1462         else
1463         {
1464            memset (vic2.sprites[i].paintedline, 0, sizeof (vic2.sprites[i].paintedline));
1465         }
1466969      }
1467      line += 1 + yend - ybegin;
1468970   }
1469971
1470   // left border
1471   if ((start_x <= VIC2_STARTVISIBLECOLUMNS) && (end_x >= xbegin))
1472      plot_box(vic2.bitmap, VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, xbegin - VIC2_STARTVISIBLECOLUMNS, 1, FRAMECOLOR);
1473   else if ((start_x > VIC2_STARTVISIBLECOLUMNS) && (end_x >= xbegin))
1474      plot_box(vic2.bitmap, start_x, first + FIRSTLINE, xbegin - start_x, 1, FRAMECOLOR);
1475   else if ((start_x <= VIC2_STARTVISIBLECOLUMNS) && (end_x < xbegin))
1476      plot_box(vic2.bitmap, VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, end_x, 1, FRAMECOLOR);
1477   else if ((start_x > VIC2_STARTVISIBLECOLUMNS) && (end_x < xbegin))
1478      plot_box(vic2.bitmap, start_x, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
1479
1480   // right border
1481   if ((start_x <= xend) && (end_x >= VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS))
1482      plot_box(vic2.bitmap, xend, first + FIRSTLINE, VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS - xend, 1, FRAMECOLOR);
1483   else if ((start_x > xend) && (end_x >= VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS))
1484      plot_box(vic2.bitmap, start_x, first + FIRSTLINE, VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS - start_x, 1, FRAMECOLOR);
1485   else if ((start_x <= xend) && (end_x < VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS))
1486      plot_box(vic2.bitmap, xend, first + FIRSTLINE, end_x - xend, 1, FRAMECOLOR);
1487   else if ((start_x > VIC2_STARTVISIBLECOLUMNS) && (end_x < xbegin))
1488      plot_box(vic2.bitmap, start_x, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
1489
1490   if (first + 1 < vic2.bitmap->height)
1491      end = first + 1;
972   if (SPRITE_COLL)
973      SPRITE_COLL |= spr_coll;
1492974   else
1493      end = vic2.bitmap->height;
1494
1495   // bottom border
1496   if (line < end)
1497975   {
1498      if ((start_x <= xbegin) && (end_x >= xend))
1499         plot_box(vic2.bitmap, xbegin, first + FIRSTLINE, xend - xbegin, 1, FRAMECOLOR);
1500      if ((start_x > xbegin) && (end_x >= xend))
1501         plot_box(vic2.bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, xend - start_x, 1, FRAMECOLOR);
1502      if ((start_x <= xbegin) && (end_x < xend))
1503         plot_box(vic2.bitmap, xbegin, first + FIRSTLINE, end_x - xbegin , 1, FRAMECOLOR);
1504      if ((start_x > xbegin) && (end_x < xend))
1505         plot_box(vic2.bitmap, start_x - VIC2_STARTVISIBLECOLUMNS, first + FIRSTLINE, end_x - start_x, 1, FRAMECOLOR);
1506      line = end;
976      SPRITE_COLL = spr_coll;
977      if (SPRITE_COLL)
978         vic2_set_interrupt(machine, 4, vic2);
1507979   }
1508}
1509980
1510#include "vic4567.c"
1511
1512#ifdef UNUSED_FUNCTION
1513static TIMER_CALLBACK( line_timer_callback )
1514{
1515   int i,j;
1516
1517   switch(vic2.rasterX)
981   if (SPRITE_BG_COLL)
982      SPRITE_BG_COLL |= gfx_coll;
983   else
1518984   {
1519
1520   case 1:
1521      if (vic2.rasterline == vic2.lines)
1522      {
1523         vic2.rasterline = 0;
1524
1525         for (i = 0; i < 8; i++)
1526         {
1527            vic2.sprites[i].repeat = vic2.sprites[i].line = 0;
1528            for (j = 0; j < 256; j++)
1529               vic2.sprites[i].paintedline[j] = 0;
1530         }
1531
1532         if (LIGHTPEN_BUTTON)
1533         {
1534            /* lightpen timer starten */
1535            timer_set (machine, attotime_make(0, 0), NULL, 1, vic2_timer_timeout);
1536         }
1537      }
1538
1539      if (vic2.rasterline == RASTERLINE)
1540      {
1541         vic2_set_interrupt(machine, 1);
1542      }
1543
1544      vic2.rasterX++;
1545      break;
1546
1547   case 60:
1548      vic2.rasterX++;
1549
1550      if (!c64_pal)
1551         if (vic2.rasterline < VIC2_FIRSTRASTERLINE + VIC2_VISIBLELINES - vic2.lines)
1552            vic2_drawlines (machine, vic2.rasterline + vic2.lines, vic2.rasterline + vic2.lines + 1, VIC2_STARTVISIBLECOLUMNS, VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS);
1553
1554      if (vic2.on)
1555         if ((vic2.rasterline >= VIC6569_STARTVISIBLELINES ) && (vic2.rasterline < VIC6569_STARTVISIBLELINES + VIC2_VISIBLELINES))
1556            vic2_drawlines (machine, vic2.rasterline, vic2.rasterline + 1, VIC2_STARTVISIBLECOLUMNS, VIC2_STARTVISIBLECOLUMNS + VIC2_VISIBLECOLUMNS);
1557
1558      break;
1559
1560   case 63:
1561      vic2.rasterline++;
1562      vic2.rasterX = 1;
1563
1564      break;
1565
1566   default:
1567      vic2.rasterX++;
1568
1569      break;
985      SPRITE_BG_COLL = gfx_coll;
986      if (SPRITE_BG_COLL)
987         vic2_set_interrupt(machine, 2, vic2);
1570988   }
1571
1572   timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, line_timer_callback);
1573989}
1574#endif
1575990
1576// modified VIC II emulation by Christian Bauer starts here...
1577991
1578// Idle access
1579#define IdleAccess \
1580   vic2.dma_read(machine, 0x3fff)
1581
1582// Fetch sprite data pointer
1583#define SprPtrAccess(num) \
1584   spr_ptr[num] = vic2.dma_read(machine, SPRITE_ADDR(num)) << 6
1585
1586// Fetch sprite data, increment data counter
1587#define SprDataAccess(num, bytenum) \
1588   if (spr_dma_on & (1 << num)) \
1589   { \
1590      spr_data[num][bytenum] = vic2.dma_read(machine, (mc[num] & 0x3f) | spr_ptr[num]); \
1591      mc[num]++; \
1592   } \
1593   else \
1594      if (bytenum == 1) \
1595         IdleAccess;
1596
1597// Turn on display if Bad Line
1598#define DisplayIfBadLine \
1599   if (is_bad_line) \
1600      display_state = 1;
1601
1602// Suspend CPU
1603#define SuspendCPU \
1604   { \
1605      if (cpu_suspended == 0) \
1606      { \
1607         first_ba_cycle = vic2.cycles_counter; \
1608         if (input_port_read(machine, "CTRLSEL") & 0x08) cpu_suspend(machine->firstcpu, SUSPEND_REASON_SPIN, 0); \
1609         cpu_suspended = 1; \
1610      } \
1611   }
1612
1613// Resume CPU
1614#define ResumeCPU \
1615   { \
1616      if (cpu_suspended == 1) \
1617      { \
1618         if (input_port_read(machine, "CTRLSEL") & 0x08) cpu_resume(machine->firstcpu, SUSPEND_REASON_SPIN); \
1619         cpu_suspended = 0; \
1620      } \
1621   }
1622
1623
1624// Refresh access
1625#define RefreshAccess \
1626   { \
1627      vic2.dma_read(machine, 0x3f00 | ref_cnt--); \
1628   }
1629
1630#define FetchIfBadLine \
1631   if (is_bad_line) \
1632   { \
1633      display_state = 1; \
1634   }
1635
1636// Turn on display and matrix access and reset RC if Bad Line
1637#define RCIfBadLine \
1638   if (is_bad_line) \
1639   { \
1640      display_state = 1; \
1641      rc = 0; \
1642   }
1643
1644// Sample border color and increment vic2.graphic_x
1645#define SampleBorder \
1646   if (draw_this_line) \
1647   { \
1648      if (border_on) \
1649         border_color_sample[vic2.cycle - 13] = FRAMECOLOR; \
1650      vic2.graphic_x += 8; \
1651   }
1652
1653// Turn on sprite DMA if necessary
1654#define CheckSpriteDMA \
1655   mask = 1; \
1656   for (i = 0; i < 8; i++, mask <<= 1) \
1657      if (SPRITEON(i) && ((vic2.rasterline & 0xff) == SPRITE_Y_POS2(i))) \
1658      { \
1659         spr_dma_on |= mask; \
1660         mc_base[i] = 0; \
1661         if (SPRITE_Y_EXPAND(i)) \
1662            spr_exp_y &= ~mask; \
1663      }
1664
1665// Video matrix access
1666#define MatrixAccess \
1667{ \
1668   if (cpu_suspended == 1) \
1669   { \
1670      if ((vic2.cycles_counter - first_ba_cycle) < 0) \
1671         matrix_line[ml_index] = color_line[ml_index] = 0xff; \
1672      else \
1673      { \
1674         UINT16 adr = (vc & 0x03ff) | VIDEOADDR; \
1675         matrix_line[ml_index] = vic2.dma_read(machine, adr); \
1676         color_line[ml_index] = vic2.dma_read_color(machine, (adr & 0x03ff)); \
1677      } \
1678   } \
1679}
1680
1681// Graphics data access
1682#define GraphicsAccess \
1683{ \
1684   if (display_state == 1) \
1685   { \
1686      UINT16 adr; \
1687      if (HIRESON) \
1688         adr = ((vc & 0x03ff) << 3) | vic2.bitmapaddr | rc; \
1689      else \
1690         adr = (matrix_line[ml_index] << 3) | vic2.chargenaddr | rc; \
1691      if (ECMON) \
1692         adr &= 0xf9ff; \
1693      gfx_data = vic2.dma_read(machine, adr); \
1694      char_data = matrix_line[ml_index]; \
1695      color_data = color_line[ml_index]; \
1696      ml_index++; \
1697      vc++; \
1698   } \
1699   else \
1700   { \
1701      gfx_data = vic2.dma_read(machine, (ECMON ? 0x39ff : 0x3fff)); \
1702      char_data = 0; \
1703   } \
1704}
1705
1706#define DrawBackground \
1707   if (draw_this_line) \
1708   { \
1709      UINT8 c; \
1710      switch (GFXMODE) \
1711      { \
1712         case 0: \
1713         case 1: \
1714         case 3: \
1715            c = vic2.colors[0]; \
1716            break; \
1717         case 2: \
1718            c = last_char_data & 0x0f; \
1719            break; \
1720         case 4: \
1721            if (last_char_data & 0x80) \
1722               if (last_char_data & 0x40) \
1723                  c = vic2.colors[3]; \
1724               else \
1725                  c = vic2.colors[2]; \
1726            else \
1727               if (last_char_data & 0x40) \
1728                  c = vic2.colors[1]; \
1729               else \
1730                  c = vic2.colors[0]; \
1731            break; \
1732         default: \
1733            c = 0; \
1734            break; \
1735      } \
1736      plot_box(vic2.bitmap, vic2.graphic_x, VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, c); \
1737   }
1738
1739#define DrawMono \
1740   data = gfx_data; \
1741   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 7) = c[data & 1]; \
1742   fore_coll_buf[p + 7] = data & 1; data >>= 1; \
1743   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 6) = c[data & 1]; \
1744   fore_coll_buf[p + 6] = data & 1; data >>= 1; \
1745   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 5) = c[data & 1]; \
1746   fore_coll_buf[p + 5] = data & 1; data >>= 1; \
1747   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 4) = c[data & 1]; \
1748   fore_coll_buf[p + 4] = data & 1; data >>= 1; \
1749   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 3) = c[data & 1]; \
1750   fore_coll_buf[p + 3] = data & 1; data >>= 1; \
1751   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 2) = c[data & 1]; \
1752   fore_coll_buf[p + 2] = data & 1; data >>= 1; \
1753   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 1) = c[data & 1]; \
1754   fore_coll_buf[p + 1] = data & 1; data >>= 1; \
1755   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 0) = c[data]; \
1756   fore_coll_buf[p + 0] = data & 1; \
1757
1758#define DrawMulti \
1759   data = gfx_data; \
1760   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 7) = c[data & 3]; \
1761   fore_coll_buf[p + 7] = data & 2; \
1762   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 6) = c[data & 3]; \
1763   fore_coll_buf[p + 6] = data & 2; data >>= 2; \
1764   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 5) = c[data & 3]; \
1765   fore_coll_buf[p + 5] = data & 2; \
1766   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 4) = c[data & 3]; \
1767   fore_coll_buf[p + 4] = data & 2; data >>= 2; \
1768   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 3) = c[data & 3]; \
1769   fore_coll_buf[p + 3] = data & 2; \
1770   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 2) = c[data & 3]; \
1771   fore_coll_buf[p + 2] = data & 2; data >>= 2; \
1772   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 1) = c[data]; \
1773   fore_coll_buf[p + 1] = data & 2; \
1774   *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 0) = c[data]; \
1775   fore_coll_buf[p + 0] = data & 2; \
1776
1777// Graphics display (8 pixels)
1778#define DrawGraphics \
1779   if (draw_this_line == 0) \
1780   { \
1781      UINT16 p = vic2.graphic_x + HORIZONTALPOS; \
1782      fore_coll_buf[p + 7] = 0; \
1783      fore_coll_buf[p + 6] = 0; \
1784      fore_coll_buf[p + 5] = 0; \
1785      fore_coll_buf[p + 4] = 0; \
1786      fore_coll_buf[p + 3] = 0; \
1787      fore_coll_buf[p + 2] = 0; \
1788      fore_coll_buf[p + 1] = 0; \
1789      fore_coll_buf[p + 0] = 0; \
1790   } \
1791   else if (ud_border_on) \
1792   { \
1793      UINT16 p = vic2.graphic_x + HORIZONTALPOS; \
1794      fore_coll_buf[p + 7] = 0; \
1795      fore_coll_buf[p + 6] = 0; \
1796      fore_coll_buf[p + 5] = 0; \
1797      fore_coll_buf[p + 4] = 0; \
1798      fore_coll_buf[p + 3] = 0; \
1799      fore_coll_buf[p + 2] = 0; \
1800      fore_coll_buf[p + 1] = 0; \
1801      fore_coll_buf[p + 0] = 0; \
1802      DrawBackground; \
1803   } \
1804   else \
1805   { \
1806      UINT8 c[4], data; \
1807      UINT16 p = vic2.graphic_x + HORIZONTALPOS; \
1808      switch (GFXMODE) \
1809      { \
1810         case 0: \
1811            c[0] = vic2.colors[0]; \
1812            c[1] = color_data & 0x0f; \
1813            DrawMono; \
1814            break; \
1815         case 1: \
1816            if (color_data & 0x08) \
1817            { \
1818               c[0] = vic2.colors[0]; \
1819               c[1] = vic2.colors[1]; \
1820               c[2] = vic2.colors[2]; \
1821               c[3] = color_data & 0x07; \
1822               DrawMulti; \
1823            } \
1824            else \
1825            { \
1826               c[0] = vic2.colors[0]; \
1827               c[1] = color_data & 0x0f; \
1828               DrawMono; \
1829            } \
1830            break; \
1831         case 2: \
1832            c[0] = char_data & 0x0f; \
1833            c[1] = char_data >> 4; \
1834            DrawMono; \
1835            break; \
1836         case 3: \
1837            c[0] = vic2.colors[0]; \
1838            c[1] = char_data >> 4; \
1839            c[2] = char_data & 0x0f; \
1840            c[3] = color_data & 0x0f; \
1841            DrawMulti; \
1842            break; \
1843         case 4: \
1844            if (char_data & 0x80) \
1845               if (char_data & 0x40) \
1846                  c[0] = vic2.colors[3]; \
1847               else \
1848                  c[0] = vic2.colors[2]; \
1849            else \
1850               if (char_data & 0x40) \
1851                  c[0] = vic2.colors[1]; \
1852               else \
1853                  c[0] = vic2.colors[0]; \
1854            c[1] = color_data & 0x0f; \
1855            DrawMono; \
1856            break; \
1857         case 5: \
1858            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 7) = 0; \
1859            fore_coll_buf[p + 7] = 0; \
1860            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 6) = 0; \
1861            fore_coll_buf[p + 6] = 0; \
1862            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 5) = 0; \
1863            fore_coll_buf[p + 5] = 0; \
1864            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 4) = 0; \
1865            fore_coll_buf[p + 4] = 0; \
1866            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 3) = 0; \
1867            fore_coll_buf[p + 3] = 0; \
1868            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 2) = 0; \
1869            fore_coll_buf[p + 2] = 0; \
1870            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 1) = 0; \
1871            fore_coll_buf[p + 1] = 0; \
1872            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 0) = 0; \
1873            fore_coll_buf[p + 0] = 0; \
1874            break; \
1875         case 6: \
1876            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 7) = 0; \
1877            fore_coll_buf[p + 7] = 0; \
1878            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 6) = 0; \
1879            fore_coll_buf[p + 6] = 0; \
1880            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 5) = 0; \
1881            fore_coll_buf[p + 5] = 0; \
1882            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 4) = 0; \
1883            fore_coll_buf[p + 4] = 0; \
1884            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 3) = 0; \
1885            fore_coll_buf[p + 3] = 0; \
1886            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 2) = 0; \
1887            fore_coll_buf[p + 2] = 0; \
1888            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 1) = 0; \
1889            fore_coll_buf[p + 1] = 0; \
1890            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 0) = 0; \
1891            fore_coll_buf[p + 0] = 0; \
1892            break; \
1893         case 7: \
1894            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 7) = 0; \
1895            fore_coll_buf[p + 7] = 0; \
1896            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 6) = 0; \
1897            fore_coll_buf[p + 6] = 0; \
1898            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 5) = 0; \
1899            fore_coll_buf[p + 5] = 0; \
1900            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 4) = 0; \
1901            fore_coll_buf[p + 4] = 0; \
1902            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 3) = 0; \
1903            fore_coll_buf[p + 3] = 0; \
1904            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 2) = 0; \
1905            fore_coll_buf[p + 2] = 0; \
1906            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 1) = 0; \
1907            fore_coll_buf[p + 1] = 0; \
1908            *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + 0) = 0; \
1909            fore_coll_buf[p + 0] = 0; \
1910            break; \
1911      } \
1912   }
1913
1914#define DrawSprites \
1915   { \
1916      int i; \
1917      UINT8 snum, sbit; \
1918      UINT8 spr_coll = 0, gfx_coll = 0; \
1919      UINT32 plane0_l, plane0_r, plane1_l, plane1_r; \
1920      UINT32 sdata_l = 0, sdata_r = 0; \
1921      for (i = 0; i < 0x400; i++) \
1922         spr_coll_buf[i] = 0; \
1923      for (snum = 0, sbit = 1; snum < 8; snum++, sbit <<= 1) \
1924      { \
1925         if ((spr_draw & sbit) && (SPRITE_X_POS2(snum) <= (403 - (VIC2_FIRSTCOLUMN + 1)))) \
1926         { \
1927            UINT16     p =    SPRITE_X_POS2(snum) + VIC2_X_2_EMU(0) + 8; \
1928            UINT8  color =    SPRITE_COLOR(snum); \
1929            UINT32 sdata =   (spr_draw_data[snum][0] << 24) | \
1930                     (spr_draw_data[snum][1] << 16) | \
1931                     (spr_draw_data[snum][2] << 8); \
1932            if (SPRITE_X_EXPAND(snum)) \
1933            { \
1934               if (SPRITE_X_POS2(snum) > (403 - 24 - (VIC2_FIRSTCOLUMN + 1))) \
1935                  continue; \
1936               if (SPRITE_MULTICOLOR(snum)) \
1937               { \
1938                  sdata_l = (vic2.expandx_multi[(sdata >> 24) & 0xff] << 16) | vic2.expandx_multi[(sdata >> 16) & 0xff]; \
1939                  sdata_r = vic2.expandx_multi[(sdata >> 8) & 0xff] << 16; \
1940                  plane0_l = (sdata_l & 0x55555555) | (sdata_l & 0x55555555) << 1; \
1941                  plane1_l = (sdata_l & 0xaaaaaaaa) | (sdata_l & 0xaaaaaaaa) >> 1; \
1942                  plane0_r = (sdata_r & 0x55555555) | (sdata_r & 0x55555555) << 1; \
1943                  plane1_r = (sdata_r & 0xaaaaaaaa) | (sdata_r & 0xaaaaaaaa) >> 1; \
1944                  for (i = 0; i < 32; i++, plane0_l <<= 1, plane1_l <<= 1) \
1945                  { \
1946                     UINT8 col; \
1947                     if (plane1_l & 0x80000000) \
1948                     { \
1949                        if (fore_coll_buf[p + i]) \
1950                        { \
1951                           gfx_coll |= sbit; \
1952                        } \
1953                        if (plane0_l & 0x80000000) \
1954                           col = vic2.spritemulti[3]; \
1955                        else \
1956                           col = color; \
1957                     } \
1958                     else \
1959                     { \
1960                        if (plane0_l & 0x80000000) \
1961                        { \
1962                           if (fore_coll_buf[p + i]) \
1963                           { \
1964                              gfx_coll |= sbit; \
1965                           } \
1966                           col = vic2.spritemulti[1]; \
1967                        } \
1968                        else \
1969                           continue; \
1970                     } \
1971                     if (spr_coll_buf[p + i]) \
1972                        spr_coll |= spr_coll_buf[p + i] | sbit; \
1973                     else \
1974                     { \
1975                        if (SPRITE_PRIORITY(snum)) \
1976                        { \
1977                           if (fore_coll_buf[p + i] == 0) \
1978                              *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = col; \
1979                           spr_coll_buf[p + i] = sbit; \
1980                        } \
1981                        else \
1982                        { \
1983                           *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = col; \
1984                           spr_coll_buf[p + i] = sbit; \
1985                        } \
1986                     } \
1987                  } \
1988                  for (; i < 48; i++, plane0_r <<= 1, plane1_r <<= 1) \
1989                  { \
1990                     UINT8 col; \
1991                     if(plane1_r & 0x80000000) \
1992                     { \
1993                        if (fore_coll_buf[p + i]) \
1994                        { \
1995                           gfx_coll |= sbit; \
1996                        } \
1997                        if (plane0_r & 0x80000000) \
1998                           col = vic2.spritemulti[3]; \
1999                        else \
2000                           col = color; \
2001                     } \
2002                     else \
2003                     { \
2004                        if (plane0_r & 0x80000000) \
2005                        { \
2006                           if (fore_coll_buf[p + i]) \
2007                           { \
2008                              gfx_coll |= sbit; \
2009                           } \
2010                           col =  vic2.spritemulti[1]; \
2011                        } \
2012                        else \
2013                           continue; \
2014                     } \
2015                     if (spr_coll_buf[p + i]) \
2016                        spr_coll |= spr_coll_buf[p + i] | sbit; \
2017                     else \
2018                     { \
2019                        if (SPRITE_PRIORITY(snum)) \
2020                        { \
2021                           if (fore_coll_buf[p + i] == 0) \
2022                              *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = col; \
2023                           spr_coll_buf[p + i] = sbit; \
2024                        } \
2025                        else \
2026                        { \
2027                           *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = col; \
2028                           spr_coll_buf[p + i] = sbit; \
2029                        } \
2030                     } \
2031                  } \
2032               } \
2033               else \
2034               { \
2035                  sdata_l = (vic2.expandx[(sdata >> 24) & 0xff] << 16) | vic2.expandx[(sdata >> 16) & 0xff]; \
2036                  sdata_r = vic2.expandx[(sdata >> 8) & 0xff] << 16; \
2037                  for (i = 0; i < 32; i++, sdata_l <<= 1) \
2038                     if (sdata_l & 0x80000000) \
2039                     { \
2040                        if (fore_coll_buf[p + i]) \
2041                        { \
2042                           gfx_coll |= sbit; \
2043                        } \
2044                        if(spr_coll_buf[p + i]) \
2045                           spr_coll |= spr_coll_buf[p + i] | sbit; \
2046                        else \
2047                        { \
2048                           if (SPRITE_PRIORITY(snum)) \
2049                           { \
2050                              if (fore_coll_buf[p + i] == 0) \
2051                                 *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = color; \
2052                              spr_coll_buf[p + i] = sbit; \
2053                           } \
2054                           else \
2055                           { \
2056                              *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = color; \
2057                              spr_coll_buf[p + i] = sbit; \
2058                           } \
2059                        } \
2060                     } \
2061                  for (; i < 48; i++, sdata_r <<= 1) \
2062                     if (sdata_r & 0x80000000) \
2063                     { \
2064                        if (fore_coll_buf[p + i]) \
2065                        { \
2066                           gfx_coll |= sbit; \
2067                        } \
2068                        if(spr_coll_buf[p + i]) \
2069                           spr_coll |= spr_coll_buf[p + i] | sbit; \
2070                        else \
2071                        { \
2072                           if (SPRITE_PRIORITY(snum)) \
2073                           { \
2074                              if (fore_coll_buf[p + i] == 0) \
2075                                 *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = color; \
2076                              spr_coll_buf[p + i] = sbit; \
2077                           } \
2078                           else \
2079                           { \
2080                              *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = color; \
2081                              spr_coll_buf[p + i] = sbit; \
2082                           } \
2083                        } \
2084                     } \
2085               } \
2086            } \
2087            else \
2088            { \
2089               if (SPRITE_MULTICOLOR(snum)) \
2090               { \
2091                  UINT32 plane0, plane1; \
2092                  plane0 = (sdata & 0x55555555) | (sdata & 0x55555555) << 1; \
2093                  plane1 = (sdata & 0xaaaaaaaa) | (sdata & 0xaaaaaaaa) >> 1; \
2094                  for (i = 0; i < 24; i++, plane0 <<= 1, plane1 <<= 1) \
2095                  { \
2096                     UINT8 col; \
2097                     if (plane1 & 0x80000000) \
2098                     { \
2099                        if (fore_coll_buf[p + i]) \
2100                        { \
2101                           gfx_coll |= sbit; \
2102                        } \
2103                        if (plane0 & 0x80000000) \
2104                           col = vic2.spritemulti[3]; \
2105                        else \
2106                           col = color; \
2107                     } \
2108                     else \
2109                     { \
2110                        if (fore_coll_buf[p + i]) \
2111                        { \
2112                           gfx_coll |= sbit; \
2113                        } \
2114                        if (plane0 & 0x80000000) \
2115                           col = vic2.spritemulti[1]; \
2116                        else \
2117                           continue; \
2118                     } \
2119                     if (spr_coll_buf[p + i]) \
2120                        spr_coll |= spr_coll_buf[p + i] | sbit; \
2121                     else \
2122                     { \
2123                        if (SPRITE_PRIORITY(snum)) \
2124                        { \
2125                           if (fore_coll_buf[p + i] == 0) \
2126                              *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = col; \
2127                           spr_coll_buf[p + i] = sbit; \
2128                        } \
2129                        else \
2130                        { \
2131                           *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = col; \
2132                           spr_coll_buf[p + i] = sbit; \
2133                        } \
2134                     } \
2135                  } \
2136               } \
2137               else \
2138               { \
2139                  for (i = 0; i < 24; i++, sdata <<= 1) \
2140                  { \
2141                     if (sdata & 0x80000000) \
2142                     { \
2143                        if (fore_coll_buf[p + i]) \
2144                        { \
2145                           gfx_coll |= sbit; \
2146                        } \
2147                        if (spr_coll_buf[p + i]) \
2148                        { \
2149                           spr_coll |= spr_coll_buf[p + i] | sbit; \
2150                        } \
2151                        else \
2152                        { \
2153                           if (SPRITE_PRIORITY(snum)) \
2154                           { \
2155                              if (fore_coll_buf[p + i] == 0) \
2156                                 *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = color; \
2157                              spr_coll_buf[p + i] = sbit; \
2158                           } \
2159                           else \
2160                           { \
2161                              *BITMAP_ADDR16(vic2.bitmap, VIC2_RASTER_2_EMU(vic2.rasterline), p + i) = color; \
2162                              spr_coll_buf[p + i] = sbit; \
2163                           } \
2164                        } \
2165                     } \
2166                  } \
2167               } \
2168            } \
2169         } \
2170      } \
2171      if (SPRITE_COLL) \
2172         SPRITE_COLL |= spr_coll; \
2173      else \
2174      { \
2175         SPRITE_COLL = spr_coll; \
2176         if (SPRITE_COLL) vic2_set_interrupt(machine, 4); \
2177      } \
2178      if (SPRITE_BG_COLL) \
2179         SPRITE_BG_COLL |= gfx_coll; \
2180      else \
2181      { \
2182         SPRITE_BG_COLL = gfx_coll; \
2183         if (SPRITE_BG_COLL) vic2_set_interrupt(machine, 2); \
2184      } \
2185   }
2186
2187static TIMER_CALLBACK( PAL_timer_callback )
992static TIMER_CALLBACK( pal_timer_callback )
2188993{
994   vic2_state *vic2 = (vic2_state *)ptr;
2189995   int i;
2190996   UINT8 mask;
2191   vic2.cycles_counter++;
997   vic2->cycles_counter++;
2192998
2193   switch(vic2.cycle)
999   switch(vic2->cycle)
21941000   {
21951001
21961002   // Sprite 3, raster counter, raster IRQ, bad line
21971003   case 1:
2198      if (vic2.rasterline == (VIC2_LINES - 1))
1004      if (vic2->rasterline == (VIC2_LINES - 1))
21991005      {
2200         vblanking = 1;
1006         vic2->vblanking = 1;
22011007
22021008         if (LIGHTPEN_BUTTON)
22031009         {
2204            /* lightpen timer starten */
2205            timer_set (machine, attotime_make(0, 0), NULL, 1, vic2_timer_timeout);
1010            /* lightpen timer start */
1011            timer_set(machine, attotime_make(0, 0), vic2, 1, vic2_timer_timeout);
22061012         }
22071013      }
22081014      else
22091015      {
2210         vic2.rasterline++;
1016         vic2->rasterline++;
22111017
2212         if (vic2.rasterline == RASTERLINE)
1018         if (vic2->rasterline == RASTERLINE)
22131019         {
2214            vic2_set_interrupt(machine, 1);
1020            vic2_set_interrupt(machine, 1, vic2);
22151021         }
22161022
2217         if (vic2.rasterline == VIC2_FIRST_DMA_LINE)
2218            bad_lines_enabled = SCREENON;
1023         if (vic2->rasterline == VIC2_FIRST_DMA_LINE)
1024            vic2->bad_lines_enabled = SCREENON;
22191025
2220         is_bad_line =    ((vic2.rasterline >= VIC2_FIRST_DMA_LINE) &&
2221                  (vic2.rasterline <= VIC2_LAST_DMA_LINE) &&
2222                  ((vic2.rasterline & 0x07) == VERTICALPOS) &&
2223                  bad_lines_enabled);
1026         vic2->is_bad_line = ((vic2->rasterline >= VIC2_FIRST_DMA_LINE) && (vic2->rasterline <= VIC2_LAST_DMA_LINE) &&
1027                  ((vic2->rasterline & 0x07) == VERTICALPOS) && vic2->bad_lines_enabled);
22241028
2225         draw_this_line =   ((VIC2_RASTER_2_EMU(vic2.rasterline) >= VIC2_RASTER_2_EMU(VIC2_FIRST_DISP_LINE)) &&
2226                  (VIC2_RASTER_2_EMU(vic2.rasterline ) <= VIC2_RASTER_2_EMU(VIC2_LAST_DISP_LINE)));
1029         vic2->draw_this_line =   ((VIC2_RASTER_2_EMU(vic2->rasterline) >= VIC2_RASTER_2_EMU(VIC2_FIRST_DISP_LINE)) &&
1030                  (VIC2_RASTER_2_EMU(vic2->rasterline ) <= VIC2_RASTER_2_EMU(VIC2_LAST_DISP_LINE)));
22271031      }
22281032
2229      border_on_sample[0] = border_on;
2230      SprPtrAccess(3);
2231      SprDataAccess(3, 0);
2232      DisplayIfBadLine;
1033      vic2->border_on_sample[0] = vic2->border_on;
1034      vic2_spr_ptr_access(machine, vic2, 3);
1035      vic2_spr_data_access(machine, vic2, 3, 0);
1036      vic2_display_if_bad_line(vic2);
22331037
2234      if(spr_dma_on & 0x08)
2235         SuspendCPU
1038      if (vic2->spr_dma_on & 0x08)
1039         vic2_suspend_cpu(machine, vic2);
22361040      else
2237         ResumeCPU
1041         vic2_resume_cpu(machine, vic2);
22381042
2239      vic2.cycle++;
1043      vic2->cycle++;
22401044      break;
22411045
22421046   // Sprite 3
22431047   case 2:
2244      if (vblanking)
1048      if (vic2->vblanking)
22451049      {
22461050         // Vertical blank, reset counters
2247         vic2.rasterline = vc_base = 0;
2248         ref_cnt = 0xff;
2249         vblanking = 0;
1051         vic2->rasterline = vic2->vc_base = 0;
1052         vic2->ref_cnt = 0xff;
1053         vic2->vblanking = 0;
22501054
22511055         // Trigger raster IRQ if IRQ in line 0
22521056         if (RASTERLINE == 0)
22531057         {
2254            vic2_set_interrupt(machine, 1);
1058            vic2_set_interrupt(machine, 1, vic2);
22551059         }
22561060      }
22571061
2258      vic2.graphic_x = VIC2_X_2_EMU(0);
1062      vic2->graphic_x = VIC2_X_2_EMU(0);
22591063
2260      SprDataAccess(3, 1);
2261      SprDataAccess(3, 2);
2262      DisplayIfBadLine;
1064      vic2_spr_data_access(machine, vic2, 3, 1);
1065      vic2_spr_data_access(machine, vic2, 3, 2);
1066      vic2_display_if_bad_line(vic2);
22631067
2264      vic2.cycle++;
1068      vic2->cycle++;
22651069      break;
22661070
22671071   // Sprite 4
22681072   case 3:
2269      SprPtrAccess(4);
2270      SprDataAccess(4, 0);
2271      DisplayIfBadLine;
1073      vic2_spr_ptr_access(machine, vic2, 4);
1074      vic2_spr_data_access(machine, vic2, 4, 0);
1075      vic2_display_if_bad_line(vic2);
22721076
2273      if(spr_dma_on & 0x10)
2274         SuspendCPU
1077      if (vic2->spr_dma_on & 0x10)
1078         vic2_suspend_cpu(machine, vic2);
22751079      else
2276         ResumeCPU
1080         vic2_resume_cpu(machine, vic2);
22771081
2278      vic2.cycle++;
1082      vic2->cycle++;
22791083      break;
22801084
22811085   // Sprite 4
22821086   case 4:
2283      SprDataAccess(4, 1);
2284      SprDataAccess(4, 2);
2285      DisplayIfBadLine;
1087      vic2_spr_data_access(machine, vic2, 4, 1);
1088      vic2_spr_data_access(machine, vic2, 4, 2);
1089      vic2_display_if_bad_line(vic2);
22861090
2287      vic2.cycle++;
1091      vic2->cycle++;
22881092      break;
22891093
22901094   // Sprite 5
22911095   case 5:
2292      SprPtrAccess(5);
2293      SprDataAccess(5, 0);
2294      DisplayIfBadLine;
1096      vic2_spr_ptr_access(machine, vic2, 5);
1097      vic2_spr_data_access(machine, vic2, 5, 0);
1098      vic2_display_if_bad_line(vic2);
22951099
2296      if(spr_dma_on & 0x20)
2297         SuspendCPU
1100      if (vic2->spr_dma_on & 0x20)
1101         vic2_suspend_cpu(machine, vic2);
22981102      else
2299         ResumeCPU
1103         vic2_resume_cpu(machine, vic2);
23001104
2301      vic2.cycle++;
1105      vic2->cycle++;
23021106      break;
23031107
23041108   // Sprite 5
23051109   case 6:
2306      SprDataAccess(5, 1);
2307      SprDataAccess(5, 2);
2308      DisplayIfBadLine;
1110      vic2_spr_data_access(machine, vic2, 5, 1);
1111      vic2_spr_data_access(machine, vic2, 5, 2);
1112      vic2_display_if_bad_line(vic2);
23091113
2310      vic2.cycle++;
1114      vic2->cycle++;
23111115      break;
23121116
23131117   // Sprite 6
23141118   case 7:
2315      SprPtrAccess(6);
2316      SprDataAccess(6, 0);
2317      DisplayIfBadLine;
1119      vic2_spr_ptr_access(machine, vic2, 6);
1120      vic2_spr_data_access(machine, vic2, 6, 0);
1121      vic2_display_if_bad_line(vic2);
23181122
2319      if(spr_dma_on & 0x40)
2320         SuspendCPU
1123      if (vic2->spr_dma_on & 0x40)
1124         vic2_suspend_cpu(machine, vic2);
23211125      else
2322         ResumeCPU
1126         vic2_resume_cpu(machine, vic2);
23231127
2324      vic2.cycle++;
1128      vic2->cycle++;
23251129      break;
23261130
23271131   // Sprite 6
23281132   case 8:
2329      SprDataAccess(6, 1);
2330      SprDataAccess(6, 2);
2331      DisplayIfBadLine;
1133      vic2_spr_data_access(machine, vic2, 6, 1);
1134      vic2_spr_data_access(machine, vic2, 6, 2);
1135      vic2_display_if_bad_line(vic2);
23321136
2333      vic2.cycle++;
1137      vic2->cycle++;
23341138      break;
23351139
23361140   // Sprite 7
23371141   case 9:
2338      SprPtrAccess(7);
2339      SprDataAccess(7, 0);
2340      DisplayIfBadLine;
1142      vic2_spr_ptr_access(machine, vic2, 7);
1143      vic2_spr_data_access(machine, vic2, 7, 0);
1144      vic2_display_if_bad_line(vic2);
23411145
2342      if(spr_dma_on & 0x80)
2343         SuspendCPU
1146      if (vic2->spr_dma_on & 0x80)
1147         vic2_suspend_cpu(machine, vic2);
23441148      else
2345         ResumeCPU
1149         vic2_resume_cpu(machine, vic2);
23461150
2347      vic2.cycle++;
1151      vic2->cycle++;
23481152      break;
23491153
23501154   // Sprite 7
23511155   case 10:
2352      SprDataAccess(7, 1);
2353      SprDataAccess(7, 2);
2354      DisplayIfBadLine;
1156      vic2_spr_data_access(machine, vic2, 7, 1);
1157      vic2_spr_data_access(machine, vic2, 7, 2);
1158      vic2_display_if_bad_line(vic2);
23551159
2356      vic2.cycle++;
1160      vic2->cycle++;
23571161      break;
23581162
23591163   // Refresh
23601164   case 11:
2361      RefreshAccess;
2362      DisplayIfBadLine;
1165      vic2_refresh_access(machine, vic2);
1166      vic2_display_if_bad_line(vic2);
23631167
2364      ResumeCPU
1168      vic2_resume_cpu(machine, vic2);
23651169
2366      vic2.cycle++;
1170      vic2->cycle++;
23671171      break;
23681172
23691173   // Refresh, fetch if bad line
23701174   case 12:
2371      RefreshAccess;
2372      FetchIfBadLine;
1175      vic2_refresh_access(machine, vic2);
1176      vic2_fetch_if_bad_line(vic2);
23731177
2374      vic2.cycle++;
1178      vic2->cycle++;
23751179      break;
23761180
23771181   // Refresh, fetch if bad line, raster_x
23781182   case 13:
2379      DrawBackground;
2380      SampleBorder;
2381      RefreshAccess;
2382      FetchIfBadLine;
1183      vic2_draw_background(vic2);
1184      vic2_sample_border(vic2);
1185      vic2_refresh_access(machine, vic2);
1186      vic2_fetch_if_bad_line(vic2);
23831187
2384      vic2.raster_x = 0xfffc;
1188      vic2->raster_x = 0xfffc;
23851189
2386      vic2.cycle++;
1190      vic2->cycle++;
23871191      break;
23881192
23891193   // Refresh, fetch if bad line, RC, VC
23901194   case 14:
2391      DrawBackground;
2392      SampleBorder;
2393      RefreshAccess;
2394      RCIfBadLine;
1195      vic2_draw_background(vic2);
1196      vic2_sample_border(vic2);
1197      vic2_refresh_access(machine, vic2);
1198      vic2_rc_if_bad_line(vic2);
23951199
2396      vc = vc_base;
1200      vic2->vc = vic2->vc_base;
23971201
2398      vic2.cycle++;
1202      vic2->cycle++;
23991203      break;
24001204
24011205   // Refresh, fetch if bad line, sprite y expansion
24021206   case 15:
2403      DrawBackground;
2404      SampleBorder;
2405      RefreshAccess;
2406      FetchIfBadLine;
1207      vic2_draw_background(vic2);
1208      vic2_sample_border(vic2);
1209      vic2_refresh_access(machine, vic2);
1210      vic2_fetch_if_bad_line(vic2);
24071211
24081212      for (i = 0; i < 8; i++)
2409         if (spr_exp_y & (1 << i))
2410            mc_base[i] += 2;
1213         if (vic2->spr_exp_y & (1 << i))
1214            vic2->mc_base[i] += 2;
24111215
2412      if (is_bad_line)
2413         SuspendCPU
1216      if (vic2->is_bad_line)
1217         vic2_suspend_cpu(machine, vic2);
24141218
2415      ml_index = 0;
2416      MatrixAccess;
1219      vic2->ml_index = 0;
1220      vic2_matrix_access(machine, vic2);
24171221
2418      vic2.cycle++;
1222      vic2->cycle++;
24191223      break;
24201224
24211225   // Graphics, sprite y expansion, sprite DMA
24221226   case 16:
2423      DrawBackground;
2424      SampleBorder;
2425      GraphicsAccess;
2426      FetchIfBadLine;
1227      vic2_draw_background(vic2);
1228      vic2_sample_border(vic2);
1229      vic2_graphics_access(machine, vic2);
1230      vic2_fetch_if_bad_line(vic2);
24271231
24281232      mask = 1;
24291233      for (i = 0; i < 8; i++, mask <<= 1)
24301234      {
2431         if (spr_exp_y & mask)
2432            mc_base[i]++;
2433         if ((mc_base[i] & 0x3f) == 0x3f)
2434            spr_dma_on &= ~mask;
1235         if (vic2->spr_exp_y & mask)
1236            vic2->mc_base[i]++;
1237         if ((vic2->mc_base[i] & 0x3f) == 0x3f)
1238            vic2->spr_dma_on &= ~mask;
24351239      }
24361240
2437      MatrixAccess;
1241      vic2_matrix_access(machine, vic2);
24381242
2439      vic2.cycle++;
1243      vic2->cycle++;
24401244      break;
24411245
24421246   // Graphics, check border
24431247   case 17:
24441248      if (COLUMNS40)
24451249      {
2446         if (vic2.rasterline == dy_stop)
2447            ud_border_on = 1;
1250         if (vic2->rasterline == vic2->dy_stop)
1251            vic2->ud_border_on = 1;
24481252         else
24491253         {
24501254            if (SCREENON)
24511255            {
2452               if (vic2.rasterline == dy_start)
2453                  border_on = ud_border_on = 0;
1256               if (vic2->rasterline == vic2->dy_start)
1257                  vic2->border_on = vic2->ud_border_on = 0;
24541258               else
2455                  if (ud_border_on == 0)
2456                     border_on = 0;
1259                  if (vic2->ud_border_on == 0)
1260                     vic2->border_on = 0;
24571261            } else
2458               if (ud_border_on == 0)
2459                  border_on = 0;
1262               if (vic2->ud_border_on == 0)
1263                  vic2->border_on = 0;
24601264         }
24611265      }
24621266
24631267      // Second sample of border state
2464      border_on_sample[1] = border_on;
1268      vic2->border_on_sample[1] = vic2->border_on;
24651269
2466      DrawBackground;
2467      DrawGraphics;
2468      SampleBorder;
2469      GraphicsAccess;
2470      FetchIfBadLine;
2471      MatrixAccess;
1270      vic2_draw_background(vic2);
1271      vic2_draw_graphics(vic2);
1272      vic2_sample_border(vic2);
1273      vic2_graphics_access(machine, vic2);
1274      vic2_fetch_if_bad_line(vic2);
1275      vic2_matrix_access(machine, vic2);
24721276
2473      vic2.cycle++;
1277      vic2->cycle++;
24741278      break;
24751279
24761280   // Check border
24771281   case 18:
24781282      if (!COLUMNS40)
24791283      {
2480         if (vic2.rasterline == dy_stop)
2481            ud_border_on = 1;
1284         if (vic2->rasterline == vic2->dy_stop)
1285            vic2->ud_border_on = 1;
24821286         else
24831287         {
24841288            if (SCREENON)
24851289            {
2486               if (vic2.rasterline == dy_start)
2487                  border_on = ud_border_on = 0;
1290               if (vic2->rasterline == vic2->dy_start)
1291                  vic2->border_on = vic2->ud_border_on = 0;
24881292               else
2489                  if (ud_border_on == 0)
2490                     border_on = 0;
1293                  if (vic2->ud_border_on == 0)
1294                     vic2->border_on = 0;
24911295            } else
2492               if (ud_border_on == 0)
2493                  border_on = 0;
1296               if (vic2->ud_border_on == 0)
1297                  vic2->border_on = 0;
24941298         }
24951299      }
24961300
24971301      // Third sample of border state
2498      border_on_sample[2] = border_on;
1302      vic2->border_on_sample[2] = vic2->border_on;
24991303
25001304   // Graphics
25011305
r7364r7365
25351339   case 52:
25361340   case 53:
25371341   case 54:
2538      DrawGraphics;
2539      SampleBorder;
2540      GraphicsAccess;
2541      FetchIfBadLine;
2542      MatrixAccess;
2543      last_char_data = char_data;
1342      vic2_draw_graphics(vic2);
1343      vic2_sample_border(vic2);
1344      vic2_graphics_access(machine, vic2);
1345      vic2_fetch_if_bad_line(vic2);
1346      vic2_matrix_access(machine, vic2);
1347      vic2->last_char_data = vic2->char_data;
25441348
2545      vic2.cycle++;
1349      vic2->cycle++;
25461350      break;
25471351
25481352   // Graphics, sprite y expansion, sprite DMA
25491353   case 55:
2550      DrawGraphics;
2551      SampleBorder;
2552      GraphicsAccess;
2553      DisplayIfBadLine;
1354      vic2_draw_graphics(vic2);
1355      vic2_sample_border(vic2);
1356      vic2_graphics_access(machine, vic2);
1357      vic2_display_if_bad_line(vic2);
25541358
25551359      // sprite y expansion
25561360      mask = 1;
25571361      for (i = 0; i < 8; i++, mask <<= 1)
25581362         if (SPRITE_Y_EXPAND (i))
2559            spr_exp_y ^= mask;
1363            vic2->spr_exp_y ^= mask;
25601364
2561      CheckSpriteDMA;
1365      vic2_check_sprite_dma(vic2);
25621366
2563      ResumeCPU
1367      vic2_resume_cpu(machine, vic2);
25641368
2565      vic2.cycle++;
1369      vic2->cycle++;
25661370      break;
25671371
25681372   // Check border, sprite DMA
25691373   case 56:
25701374      if (!COLUMNS40)
2571         border_on = 1;
1375         vic2->border_on = 1;
25721376
25731377      // Fourth sample of border state
2574      border_on_sample[3] = border_on;
1378      vic2->border_on_sample[3] = vic2->border_on;
25751379
2576      DrawGraphics;
2577      SampleBorder;
2578      IdleAccess;
2579      DisplayIfBadLine;
2580      CheckSpriteDMA;
1380      vic2_draw_graphics(vic2);
1381      vic2_sample_border(vic2);
1382      vic2_idle_access(machine, vic2);
1383      vic2_display_if_bad_line(vic2);
1384      vic2_check_sprite_dma(vic2);
25811385
2582      vic2.cycle++;
1386      vic2->cycle++;
25831387      break;
25841388
25851389   // Check border, sprites
25861390   case 57:
25871391      if (COLUMNS40)
2588         border_on = 1;
1392         vic2->border_on = 1;
25891393
25901394      // Fifth sample of border state
2591      border_on_sample[4] = border_on;
1395      vic2->border_on_sample[4] = vic2->border_on;
25921396
25931397      // Sample spr_disp_on and spr_data for sprite drawing
2594      spr_draw = spr_disp_on;
2595      if (spr_draw)
2596         memcpy(spr_draw_data, spr_data, 8 * 4);
1398      vic2->spr_draw = vic2->spr_disp_on;
1399      if (vic2->spr_draw)
1400         memcpy(vic2->spr_draw_data, vic2->spr_data, 8 * 4);
25971401
25981402      mask = 1;
25991403      for (i = 0; i < 8; i++, mask <<= 1)
2600         if ((spr_disp_on & mask) && !(spr_dma_on & mask))
2601            spr_disp_on &= ~mask;
1404         if ((vic2->spr_disp_on & mask) && !(vic2->spr_dma_on & mask))
1405            vic2->spr_disp_on &= ~mask;
26021406
2603      DrawBackground;
2604      SampleBorder;
2605      IdleAccess;
2606      DisplayIfBadLine;
1407      vic2_draw_background(vic2);
1408      vic2_sample_border(vic2);
1409      vic2_idle_access(machine, vic2);
1410      vic2_display_if_bad_line(vic2);
26071411
2608      vic2.cycle++;
1412      vic2->cycle++;
26091413      break;
26101414
26111415   // Sprite 0, sprite DMA, MC, RC
26121416   case 58:
2613      DrawBackground;
2614      SampleBorder;
1417      vic2_draw_background(vic2);
1418      vic2_sample_border(vic2);
26151419
26161420      mask = 1;
26171421      for (i = 0; i < 8; i++, mask <<= 1)
26181422      {
2619         mc[i] = mc_base[i];
2620         if ((spr_dma_on & mask) && ((vic2.rasterline & 0xff) == SPRITE_Y_POS2(i)))
2621            spr_disp_on |= mask;
1423         vic2->mc[i] = vic2->mc_base[i];
1424         if ((vic2->spr_dma_on & mask) && ((vic2->rasterline & 0xff) == SPRITE_Y_POS(i)))
1425            vic2->spr_disp_on |= mask;
26221426      }
26231427
2624      SprPtrAccess(0);
2625      SprDataAccess(0, 0);
1428      vic2_spr_ptr_access(machine, vic2, 0);
1429      vic2_spr_data_access(machine, vic2, 0, 0);
26261430
2627      if (rc == 7)
1431      if (vic2->rc == 7)
26281432      {
2629         vc_base = vc;
2630         display_state = 0;
1433         vic2->vc_base = vic2->vc;
1434         vic2->display_state = 0;
26311435      }
26321436
2633      if (is_bad_line || display_state)
1437      if (vic2->is_bad_line || vic2->display_state)
26341438      {
2635         display_state = 1;
2636         rc = (rc + 1) & 7;
1439         vic2->display_state = 1;
1440         vic2->rc = (vic2->rc + 1) & 7;
26371441      }
26381442
2639      if(spr_dma_on & 0x01)
2640         SuspendCPU
1443      if (vic2->spr_dma_on & 0x01)
1444         vic2_suspend_cpu(machine, vic2);
26411445      else
2642         ResumeCPU
1446         vic2_resume_cpu(machine, vic2);
26431447
2644      vic2.cycle++;
1448      vic2->cycle++;
26451449      break;
26461450
26471451   // Sprite 0
26481452   case 59:
2649      DrawBackground;
2650      SampleBorder;
2651      SprDataAccess(0, 1);
2652      SprDataAccess(0, 2);
2653      DisplayIfBadLine;
1453      vic2_draw_background(vic2);
1454      vic2_sample_border(vic2);
1455      vic2_spr_data_access(machine, vic2, 0, 1);
1456      vic2_spr_data_access(machine, vic2, 0, 2);
1457      vic2_display_if_bad_line(vic2);
26541458
2655      vic2.cycle++;
1459      vic2->cycle++;
26561460      break;
26571461
26581462   // Sprite 1, draw
26591463   case 60:
2660      DrawBackground;
2661      SampleBorder;
1464      vic2_draw_background(vic2);
1465      vic2_sample_border(vic2);
26621466
2663      if (draw_this_line)
1467      if (vic2->draw_this_line)
26641468      {
2665         DrawSprites;
1469         vic2_draw_sprites(machine, vic2);
26661470
2667         if (border_on_sample[0])
1471         if (vic2->border_on_sample[0])
26681472            for (i = 0; i < 4; i++)
2669               plot_box(vic2.bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[i]);
1473               plot_box(vic2->bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[i]);
26701474
2671         if (border_on_sample[1])
2672            plot_box(vic2.bitmap, VIC2_X_2_EMU(4 * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[4]);
1475         if (vic2->border_on_sample[1])
1476            plot_box(vic2->bitmap, VIC2_X_2_EMU(4 * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[4]);
26731477
2674         if (border_on_sample[2])
1478         if (vic2->border_on_sample[2])
26751479            for (i = 5; i < 43; i++)
2676               plot_box(vic2.bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[i]);
1480               plot_box(vic2->bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[i]);
26771481
2678         if (border_on_sample[3])
2679            plot_box(vic2.bitmap, VIC2_X_2_EMU(43 * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[43]);
1482         if (vic2->border_on_sample[3])
1483            plot_box(vic2->bitmap, VIC2_X_2_EMU(43 * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[43]);
26801484
2681         if (border_on_sample[4])
1485         if (vic2->border_on_sample[4])
26821486         {
26831487            for (i = 44; i < 48; i++)
2684               plot_box(vic2.bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[i]);
1488               plot_box(vic2->bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[i]);
26851489            for (i = 48; i < 51; i++)
2686               plot_box(vic2.bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[47]);
1490               plot_box(vic2->bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[47]);
26871491         }
26881492      }
26891493
2690      SprPtrAccess(1);
2691      SprDataAccess(1, 0);
2692      DisplayIfBadLine;
1494      vic2_spr_ptr_access(machine, vic2, 1);
1495      vic2_spr_data_access(machine, vic2, 1, 0);
1496      vic2_display_if_bad_line(vic2);
26931497
2694      if(spr_dma_on & 0x02)
2695         SuspendCPU
1498      if (vic2->spr_dma_on & 0x02)
1499         vic2_suspend_cpu(machine, vic2);
26961500      else
2697         ResumeCPU
1501         vic2_resume_cpu(machine, vic2);
26981502
2699      vic2.cycle++;
1503      vic2->cycle++;
27001504      break;
27011505
27021506   // Sprite 1
27031507   case 61:
2704      SprDataAccess(1, 1);
2705      SprDataAccess(1, 2);
2706      DisplayIfBadLine;
1508      vic2_spr_data_access(machine, vic2, 1, 1);
1509      vic2_spr_data_access(machine, vic2, 1, 2);
1510      vic2_display_if_bad_line(vic2);
27071511
2708      vic2.cycle++;
1512      vic2->cycle++;
27091513      break;
27101514
27111515   // Sprite 2
27121516   case 62:
2713      SprPtrAccess(2);
2714      SprDataAccess(2, 0);
2715      DisplayIfBadLine;
1517      vic2_spr_ptr_access(machine, vic2, 2);
1518      vic2_spr_data_access(machine, vic2, 2, 0);
1519      vic2_display_if_bad_line(vic2);
27161520
2717      if(spr_dma_on & 0x04)
2718         SuspendCPU
1521      if (vic2->spr_dma_on & 0x04)
1522         vic2_suspend_cpu(machine, vic2);
27191523      else
2720         ResumeCPU
1524         vic2_resume_cpu(machine, vic2);
27211525
2722      vic2.cycle++;
1526      vic2->cycle++;
27231527      break;
27241528
27251529   // Sprite 2
27261530   case 63:
2727      SprDataAccess(2, 1);
2728      SprDataAccess(2, 2);
2729      DisplayIfBadLine;
1531      vic2_spr_data_access(machine, vic2, 2, 1);
1532      vic2_spr_data_access(machine, vic2, 2, 2);
1533      vic2_display_if_bad_line(vic2);
27301534
2731      if (vic2.rasterline == dy_stop)
2732         ud_border_on = 1;
1535      if (vic2->rasterline == vic2->dy_stop)
1536         vic2->ud_border_on = 1;
27331537      else
2734         if (SCREENON && (vic2.rasterline == dy_start))
2735            ud_border_on = 0;
1538         if (SCREENON && (vic2->rasterline == vic2->dy_start))
1539            vic2->ud_border_on = 0;
27361540
27371541      // Last cycle
2738      vic2.cycle = 1;
1542      vic2->cycle = 1;
27391543   }
27401544
2741   vic2.raster_x += 8;
2742   timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, PAL_timer_callback);
1545   vic2->raster_x += 8;
1546   timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 1), vic2, 0, pal_timer_callback);
27431547}
27441548
2745static TIMER_CALLBACK( NTSC_timer_callback )
1549static TIMER_CALLBACK( ntsc_timer_callback )
27461550{
1551   vic2_state *vic2 = (vic2_state *)ptr;
27471552   int i;
27481553   UINT8 mask;
2749   vic2.cycles_counter++;
1554   vic2->cycles_counter++;
27501555
2751   switch(vic2.cycle)
1556   switch (vic2->cycle)
27521557   {
27531558
27541559   // Sprite 3, raster counter, raster IRQ, bad line
27551560   case 1:
2756      if (vic2.rasterline == (VIC2_LINES - 1))
1561      if (vic2->rasterline == (VIC2_LINES - 1))
27571562      {
2758         vblanking = 1;
1563         vic2->vblanking = 1;
27591564
27601565         if (LIGHTPEN_BUTTON)
27611566         {
27621567            /* lightpen timer starten */
2763            timer_set (machine, attotime_make(0, 0), NULL, 1, vic2_timer_timeout);
1568            timer_set(machine, attotime_make(0, 0), vic2, 1, vic2_timer_timeout);
27641569         }
27651570      }
27661571      else
27671572      {
2768         vic2.rasterline++;
1573         vic2->rasterline++;
27691574
2770         if (vic2.rasterline == RASTERLINE)
1575         if (vic2->rasterline == RASTERLINE)
27711576         {
2772            vic2_set_interrupt(machine, 1);
1577            vic2_set_interrupt(machine, 1, vic2);
27731578         }
27741579
2775         if (vic2.rasterline == VIC2_FIRST_DMA_LINE)
2776            bad_lines_enabled = SCREENON;
1580         if (vic2->rasterline == VIC2_FIRST_DMA_LINE)
1581            vic2->bad_lines_enabled = SCREENON;
27771582
2778         is_bad_line =    ((vic2.rasterline >= VIC2_FIRST_DMA_LINE) &&
2779                  (vic2.rasterline <= VIC2_LAST_DMA_LINE) &&
2780                  ((vic2.rasterline & 0x07) == VERTICALPOS) &&
2781                  bad_lines_enabled);
1583         vic2->is_bad_line = ((vic2->rasterline >= VIC2_FIRST_DMA_LINE) && (vic2->rasterline <= VIC2_LAST_DMA_LINE) &&
1584                  ((vic2->rasterline & 0x07) == VERTICALPOS) && vic2->bad_lines_enabled);
27821585
2783         draw_this_line =   ((VIC2_RASTER_2_EMU(vic2.rasterline) >= VIC2_RASTER_2_EMU(VIC2_FIRST_DISP_LINE)) &&
2784                  (VIC2_RASTER_2_EMU(vic2.rasterline ) <= VIC2_RASTER_2_EMU(VIC2_LAST_DISP_LINE)));
1586         vic2->draw_this_line = ((VIC2_RASTER_2_EMU(vic2->rasterline) >= VIC2_RASTER_2_EMU(VIC2_FIRST_DISP_LINE)) &&
1587                  (VIC2_RASTER_2_EMU(vic2->rasterline ) <= VIC2_RASTER_2_EMU(VIC2_LAST_DISP_LINE)));
27851588      }
27861589
2787      border_on_sample[0] = border_on;
2788      SprPtrAccess(3);
2789      SprDataAccess(3, 0);
2790      DisplayIfBadLine;
1590      vic2->border_on_sample[0] = vic2->border_on;
1591      vic2_spr_ptr_access(machine, vic2, 3);
1592      vic2_spr_data_access(machine, vic2, 3, 0);
1593      vic2_display_if_bad_line(vic2);
27911594
2792      if(spr_dma_on & 0x08)
2793         SuspendCPU
1595      if (vic2->spr_dma_on & 0x08)
1596         vic2_suspend_cpu(machine, vic2);
27941597      else
2795         ResumeCPU
1598         vic2_resume_cpu(machine, vic2);
27961599
2797      vic2.cycle++;
1600      vic2->cycle++;
27981601      break;
27991602
28001603   // Sprite 3
28011604   case 2:
2802      if (vblanking)
1605      if (vic2->vblanking)
28031606      {
28041607         // Vertical blank, reset counters
2805         vic2.rasterline = vc_base = 0;
2806         ref_cnt = 0xff;
2807         vblanking = 0;
1608         vic2->rasterline = vic2->vc_base = 0;
1609         vic2->ref_cnt = 0xff;
1610         vic2->vblanking = 0;
28081611
28091612         // Trigger raster IRQ if IRQ in line 0
28101613         if (RASTERLINE == 0)
28111614         {
2812            vic2_set_interrupt(machine, 1);
1615            vic2_set_interrupt(machine, 1, vic2);
28131616         }
28141617      }
28151618
2816      vic2.graphic_x = VIC2_X_2_EMU(0);
1619      vic2->graphic_x = VIC2_X_2_EMU(0);
28171620
2818      SprDataAccess(3, 1);
2819      SprDataAccess(3, 2);
2820      DisplayIfBadLine;
1621      vic2_spr_data_access(machine, vic2, 3, 1);
1622      vic2_spr_data_access(machine, vic2, 3, 2);
1623      vic2_display_if_bad_line(vic2);
28211624
2822      vic2.cycle++;
1625      vic2->cycle++;
28231626      break;
28241627
28251628   // Sprite 4
28261629   case 3:
2827      SprPtrAccess(4);
2828      SprDataAccess(4, 0);
2829      DisplayIfBadLine;
1630      vic2_spr_ptr_access(machine, vic2, 4);
1631      vic2_spr_data_access(machine, vic2, 4, 0);
1632      vic2_display_if_bad_line(vic2);
28301633
2831      if(spr_dma_on & 0x10)
2832         SuspendCPU
1634      if (vic2->spr_dma_on & 0x10)
1635         vic2_suspend_cpu(machine, vic2);
28331636      else
2834         ResumeCPU
1637         vic2_resume_cpu(machine, vic2);
28351638
2836      vic2.cycle++;
1639      vic2->cycle++;
28371640      break;
28381641
28391642   // Sprite 4
28401643   case 4:
2841      SprDataAccess(4, 1);
2842      SprDataAccess(4, 2);
2843      DisplayIfBadLine;
1644      vic2_spr_data_access(machine, vic2, 4, 1);
1645      vic2_spr_data_access(machine, vic2, 4, 2);
1646      vic2_display_if_bad_line(vic2);
28441647
2845      vic2.cycle++;
1648      vic2->cycle++;
28461649      break;
28471650
28481651   // Sprite 5
28491652   case 5:
2850      SprPtrAccess(5);
2851      SprDataAccess(5, 0);
2852      DisplayIfBadLine;
1653      vic2_spr_ptr_access(machine, vic2, 5);
1654      vic2_spr_data_access(machine, vic2, 5, 0);
1655      vic2_display_if_bad_line(vic2);
28531656
2854      if(spr_dma_on & 0x20)
2855         SuspendCPU
1657      if (vic2->spr_dma_on & 0x20)
1658         vic2_suspend_cpu(machine, vic2);
28561659      else
2857         ResumeCPU
1660         vic2_resume_cpu(machine, vic2);
28581661
2859      vic2.cycle++;
1662      vic2->cycle++;
28601663      break;
28611664
28621665   // Sprite 5
28631666   case 6:
2864      SprDataAccess(5, 1);
2865      SprDataAccess(5, 2);
2866      DisplayIfBadLine;
1667      vic2_spr_data_access(machine, vic2, 5, 1);
1668      vic2_spr_data_access(machine, vic2, 5, 2);
1669      vic2_display_if_bad_line(vic2);
28671670
2868      vic2.cycle++;
1671      vic2->cycle++;
28691672      break;
28701673
28711674   // Sprite 6
28721675   case 7:
2873      SprPtrAccess(6);
2874      SprDataAccess(6, 0);
2875      DisplayIfBadLine;
1676      vic2_spr_ptr_access(machine, vic2, 6);
1677      vic2_spr_data_access(machine, vic2, 6, 0);
1678      vic2_display_if_bad_line(vic2);
28761679
2877      if(spr_dma_on & 0x40)
2878         SuspendCPU
1680      if (vic2->spr_dma_on & 0x40)
1681         vic2_suspend_cpu(machine, vic2);
28791682      else
2880         ResumeCPU
1683         vic2_resume_cpu(machine, vic2);
28811684
2882      vic2.cycle++;
1685      vic2->cycle++;
28831686      break;
28841687
28851688   // Sprite 6
28861689   case 8:
2887      SprDataAccess(6, 1);
2888      SprDataAccess(6, 2);
2889      DisplayIfBadLine;
1690      vic2_spr_data_access(machine, vic2, 6, 1);
1691      vic2_spr_data_access(machine, vic2, 6, 2);
1692      vic2_display_if_bad_line(vic2);
28901693
2891      vic2.cycle++;
1694      vic2->cycle++;
28921695      break;
28931696
28941697   // Sprite 7
28951698   case 9:
2896      SprPtrAccess(7);
2897      SprDataAccess(7, 0);
2898      DisplayIfBadLine;
1699      vic2_spr_ptr_access(machine, vic2, 7);
1700      vic2_spr_data_access(machine, vic2, 7, 0);
1701      vic2_display_if_bad_line(vic2);
28991702
2900      if(spr_dma_on & 0x80)
2901         SuspendCPU
1703      if (vic2->spr_dma_on & 0x80)
1704         vic2_suspend_cpu(machine, vic2);
29021705      else
2903         ResumeCPU
1706         vic2_resume_cpu(machine, vic2);
29041707
2905      vic2.cycle++;
1708      vic2->cycle++;
29061709      break;
29071710
29081711   // Sprite 7
29091712   case 10:
2910      SprDataAccess(7, 1);
2911      SprDataAccess(7, 2);
2912      DisplayIfBadLine;
1713      vic2_spr_data_access(machine, vic2, 7, 1);
1714      vic2_spr_data_access(machine, vic2, 7, 2);
1715      vic2_display_if_bad_line(vic2);
29131716
2914      vic2.cycle++;
1717      vic2->cycle++;
29151718      break;
29161719
29171720   // Refresh
29181721   case 11:
2919      RefreshAccess;
2920      DisplayIfBadLine;
1722      vic2_refresh_access(machine, vic2);
1723      vic2_display_if_bad_line(vic2);
29211724
2922      ResumeCPU
1725      vic2_resume_cpu(machine, vic2);
29231726
2924      vic2.cycle++;
1727      vic2->cycle++;
29251728      break;
29261729
29271730   // Refresh, fetch if bad line
29281731   case 12:
2929      RefreshAccess;
2930      FetchIfBadLine;
1732      vic2_refresh_access(machine, vic2);
1733      vic2_fetch_if_bad_line(vic2);
29311734
2932      vic2.cycle++;
1735      vic2->cycle++;
29331736      break;
29341737
29351738   // Refresh, fetch if bad line, raster_x
29361739   case 13:
2937      DrawBackground;
2938      SampleBorder;
2939      RefreshAccess;
2940      FetchIfBadLine;
1740      vic2_draw_background(vic2);
1741      vic2_sample_border(vic2);
1742      vic2_refresh_access(machine, vic2);
1743      vic2_fetch_if_bad_line(vic2);
29411744
2942      vic2.raster_x = 0xfffc;
1745      vic2->raster_x = 0xfffc;
29431746
2944      vic2.cycle++;
1747      vic2->cycle++;
29451748      break;
29461749
29471750   // Refresh, fetch if bad line, RC, VC
29481751   case 14:
2949      DrawBackground;
2950      SampleBorder;
2951      RefreshAccess;
2952      RCIfBadLine;
1752      vic2_draw_background(vic2);
1753      vic2_sample_border(vic2);
1754      vic2_refresh_access(machine, vic2);
1755      vic2_rc_if_bad_line(vic2);
29531756
2954      vc = vc_base;
1757      vic2->vc = vic2->vc_base;
29551758
2956      vic2.cycle++;
1759      vic2->cycle++;
29571760      break;
29581761
29591762   // Refresh, fetch if bad line, sprite y expansion
29601763   case 15:
2961      DrawBackground;
2962      SampleBorder;
2963      RefreshAccess;
2964      FetchIfBadLine;
1764      vic2_draw_background(vic2);
1765      vic2_sample_border(vic2);
1766      vic2_refresh_access(machine, vic2);
1767      vic2_fetch_if_bad_line(vic2);
29651768
29661769      for (i = 0; i < 8; i++)
2967         if (spr_exp_y & (1 << i))
2968            mc_base[i] += 2;
1770         if (vic2->spr_exp_y & (1 << i))
1771            vic2->mc_base[i] += 2;
29691772
2970      if (is_bad_line)
2971         SuspendCPU
1773      if (vic2->is_bad_line)
1774         vic2_suspend_cpu(machine, vic2);
29721775
2973      ml_index = 0;
2974      MatrixAccess;
1776      vic2->ml_index = 0;
1777      vic2_matrix_access(machine, vic2);
29751778
2976      vic2.cycle++;
1779      vic2->cycle++;
29771780      break;
29781781
29791782   // Graphics, sprite y expansion, sprite DMA
29801783   case 16:
2981      DrawBackground;
2982      SampleBorder;
2983      GraphicsAccess;
2984      FetchIfBadLine;
1784      vic2_draw_background(vic2);
1785      vic2_sample_border(vic2);
1786      vic2_graphics_access(machine, vic2);
1787      vic2_fetch_if_bad_line(vic2);
29851788
29861789      mask = 1;
29871790      for (i = 0; i < 8; i++, mask <<= 1)
29881791      {
2989         if (spr_exp_y & mask)
2990            mc_base[i]++;
2991         if ((mc_base[i] & 0x3f) == 0x3f)
2992            spr_dma_on &= ~mask;
1792         if (vic2->spr_exp_y & mask)
1793            vic2->mc_base[i]++;
1794         if ((vic2->mc_base[i] & 0x3f) == 0x3f)
1795            vic2->spr_dma_on &= ~mask;
29931796      }
29941797
2995      MatrixAccess;
1798      vic2_matrix_access(machine, vic2);
29961799
2997      vic2.cycle++;
1800      vic2->cycle++;
29981801      break;
29991802
30001803   // Graphics, check border
30011804   case 17:
30021805      if (COLUMNS40)
30031806      {
3004         if (vic2.rasterline == dy_stop)
3005            ud_border_on = 1;
1807         if (vic2->rasterline == vic2->dy_stop)
1808            vic2->ud_border_on = 1;
30061809         else
30071810         {
30081811            if (SCREENON)
30091812            {
3010               if (vic2.rasterline == dy_start)
3011                  border_on = ud_border_on = 0;
1813               if (vic2->rasterline == vic2->dy_start)
1814                  vic2->border_on = vic2->ud_border_on = 0;
30121815               else
3013                  if (ud_border_on == 0)
3014                     border_on = 0;
3015            } else
3016               if (ud_border_on == 0)
3017                  border_on = 0;
1816                  if (vic2->ud_border_on == 0)
1817                     vic2->border_on = 0;
1818            }
1819            else
1820               if (vic2->ud_border_on == 0)
1821                  vic2->border_on = 0;
30181822         }
30191823      }
30201824
30211825      // Second sample of border state
3022      border_on_sample[1] = border_on;
1826      vic2->border_on_sample[1] = vic2->border_on;
30231827
3024      DrawBackground;
3025      DrawGraphics;
3026      SampleBorder;
3027      GraphicsAccess;
3028      FetchIfBadLine;
3029      MatrixAccess;
1828      vic2_draw_background(vic2);
1829      vic2_draw_graphics(vic2);
1830      vic2_sample_border(vic2);
1831      vic2_graphics_access(machine, vic2);
1832      vic2_fetch_if_bad_line(vic2);
1833      vic2_matrix_access(machine, vic2);
30301834
3031      vic2.cycle++;
1835      vic2->cycle++;
30321836      break;
30331837
30341838   // Check border
30351839   case 18:
30361840      if (!COLUMNS40)
30371841      {
3038         if (vic2.rasterline == dy_stop)
3039            ud_border_on = 1;
1842         if (vic2->rasterline == vic2->dy_stop)
1843            vic2->ud_border_on = 1;
30401844         else
30411845         {
30421846            if (SCREENON)
30431847            {
3044               if (vic2.rasterline == dy_start)
3045                  border_on = ud_border_on = 0;
1848               if (vic2->rasterline == vic2->dy_start)
1849                  vic2->border_on = vic2->ud_border_on = 0;
30461850               else
3047                  if (ud_border_on == 0)
3048                     border_on = 0;
3049            } else
3050               if (ud_border_on == 0)
3051                  border_on = 0;
1851                  if (vic2->ud_border_on == 0)
1852                     vic2->border_on = 0;
1853            }
1854            else
1855               if (vic2->ud_border_on == 0)
1856                  vic2->border_on = 0;
30521857         }
30531858      }
30541859
30551860      // Third sample of border state
3056      border_on_sample[2] = border_on;
1861      vic2->border_on_sample[2] = vic2->border_on;
30571862
30581863   // Graphics
30591864
r7364r7365
30931898   case 52:
30941899   case 53:
30951900   case 54:
3096      DrawGraphics;
3097      SampleBorder;
3098      GraphicsAccess;
3099      FetchIfBadLine;
3100      MatrixAccess;
3101      last_char_data = char_data;
1901      vic2_draw_graphics(vic2);
1902      vic2_sample_border(vic2);
1903      vic2_graphics_access(machine, vic2);
1904      vic2_fetch_if_bad_line(vic2);
1905      vic2_matrix_access(machine, vic2);
1906      vic2->last_char_data = vic2->char_data;
31021907
3103      vic2.cycle++;
1908      vic2->cycle++;
31041909      break;
31051910
31061911   // Graphics, sprite y expansion, sprite DMA
31071912   case 55:
3108      DrawGraphics;
3109      SampleBorder;
3110      GraphicsAccess;
3111      DisplayIfBadLine;
1913      vic2_draw_graphics(vic2);
1914      vic2_sample_border(vic2);
1915      vic2_graphics_access(machine, vic2);
1916      vic2_display_if_bad_line(vic2);
31121917
31131918      // sprite y expansion
31141919      mask = 1;
31151920      for (i = 0; i < 8; i++, mask <<= 1)
31161921         if (SPRITE_Y_EXPAND (i))
3117            spr_exp_y ^= mask;
1922            vic2->spr_exp_y ^= mask;
31181923
3119      CheckSpriteDMA;
1924      vic2_check_sprite_dma(vic2);
31201925
3121      ResumeCPU
1926      vic2_resume_cpu(machine, vic2);
31221927
3123      vic2.cycle++;
1928      vic2->cycle++;
31241929      break;
31251930
31261931   // Check border, sprite DMA
31271932   case 56:
31281933      if (!COLUMNS40)
3129         border_on = 1;
1934         vic2->border_on = 1;
31301935
31311936      // Fourth sample of border state
3132      border_on_sample[3] = border_on;
1937      vic2->border_on_sample[3] = vic2->border_on;
31331938
3134      DrawGraphics;
3135      SampleBorder;
3136      IdleAccess;
3137      DisplayIfBadLine;
3138      CheckSpriteDMA;
1939      vic2_draw_graphics(vic2);
1940      vic2_sample_border(vic2);
1941      vic2_idle_access(machine, vic2);
1942      vic2_display_if_bad_line(vic2);
1943      vic2_check_sprite_dma(vic2);
31391944
3140      vic2.cycle++;
1945      vic2->cycle++;
31411946      break;
31421947
31431948   // Check border, sprites
31441949   case 57:
31451950      if (COLUMNS40)
3146         border_on = 1;
1951         vic2->border_on = 1;
31471952
31481953      // Fifth sample of border state
3149      border_on_sample[4] = border_on;
1954      vic2->border_on_sample[4] = vic2->border_on;
31501955
31511956      // Sample spr_disp_on and spr_data for sprite drawing
3152      spr_draw = spr_disp_on;
3153      if (spr_draw)
3154         memcpy(spr_draw_data, spr_data, 8 * 4);
1957      vic2->spr_draw = vic2->spr_disp_on;
1958      if (vic2->spr_draw)
1959         memcpy(vic2->spr_draw_data, vic2->spr_data, 8 * 4);
31551960
31561961      mask = 1;
31571962      for (i = 0; i < 8; i++, mask <<= 1)
3158         if ((spr_disp_on & mask) && !(spr_dma_on & mask))
3159            spr_disp_on &= ~mask;
1963         if ((vic2->spr_disp_on & mask) && !(vic2->spr_dma_on & mask))
1964            vic2->spr_disp_on &= ~mask;
31601965
3161      DrawBackground;
3162      SampleBorder;
3163      IdleAccess;
3164      DisplayIfBadLine;
1966      vic2_draw_background(vic2);
1967      vic2_sample_border(vic2);
1968      vic2_idle_access(machine, vic2);
1969      vic2_display_if_bad_line(vic2);
31651970
3166      vic2.cycle++;
1971      vic2->cycle++;
31671972      break;
31681973
31691974   // for NTSC 6567R8
31701975   case 58:
3171      DrawBackground;
3172      SampleBorder;
3173      IdleAccess;
3174      DisplayIfBadLine;
1976      vic2_draw_background(vic2);
1977      vic2_sample_border(vic2);
1978      vic2_idle_access(machine, vic2);
1979      vic2_display_if_bad_line(vic2);
31751980
3176      vic2.cycle++;
1981      vic2->cycle++;
31771982      break;
31781983
31791984   // for NTSC 6567R8
31801985   case 59:
3181      DrawBackground;
3182      SampleBorder;
3183      IdleAccess;
3184      DisplayIfBadLine;
1986      vic2_draw_background(vic2);
1987      vic2_sample_border(vic2);
1988      vic2_idle_access(machine, vic2);
1989      vic2_display_if_bad_line(vic2);
31851990
3186      vic2.cycle++;
1991      vic2->cycle++;
31871992      break;
31881993
31891994   // Sprite 0, sprite DMA, MC, RC
31901995   case 60:
3191      DrawBackground;
3192      SampleBorder;
1996      vic2_draw_background(vic2);
1997      vic2_sample_border(vic2);
31931998
31941999      mask = 1;
31952000      for (i = 0; i < 8; i++, mask <<= 1)
31962001      {
3197         mc[i] = mc_base[i];
3198         if ((spr_dma_on & mask) && ((vic2.rasterline & 0xff) == SPRITE_Y_POS2(i)))
3199            spr_disp_on |= mask;
2002         vic2->mc[i] = vic2->mc_base[i];
2003         if ((vic2->spr_dma_on & mask) && ((vic2->rasterline & 0xff) == SPRITE_Y_POS(i)))
2004            vic2->spr_disp_on |= mask;
32002005      }
32012006
3202      SprPtrAccess(0);
3203      SprDataAccess(0, 0);
2007      vic2_spr_ptr_access(machine, vic2, 0);
2008      vic2_spr_data_access(machine, vic2, 0, 0);
32042009
3205      if (rc == 7)
2010      if (vic2->rc == 7)
32062011      {
3207         vc_base = vc;
3208         display_state = 0;
2012         vic2->vc_base = vic2->vc;
2013         vic2->display_state = 0;
32092014      }
32102015
3211      if (is_bad_line || display_state)
2016      if (vic2->is_bad_line || vic2->display_state)
32122017      {
3213         display_state = 1;
3214         rc = (rc + 1) & 7;
2018         vic2->display_state = 1;
2019         vic2->rc = (vic2->rc + 1) & 7;
32152020      }
32162021
3217      if(spr_dma_on & 0x01)
3218         SuspendCPU
2022      if (vic2->spr_dma_on & 0x01)
2023         vic2_suspend_cpu(machine, vic2);
32192024      else
3220         ResumeCPU
2025         vic2_resume_cpu(machine, vic2);
32212026
3222      vic2.cycle++;
2027      vic2->cycle++;
32232028      break;
32242029
32252030   // Sprite 0
32262031   case 61:
3227      DrawBackground;
3228      SampleBorder;
3229      SprDataAccess(0, 1);
3230      SprDataAccess(0, 2);
3231      DisplayIfBadLine;
2032      vic2_draw_background(vic2);
2033      vic2_sample_border(vic2);
2034      vic2_spr_data_access(machine, vic2, 0, 1);
2035      vic2_spr_data_access(machine, vic2, 0, 2);
2036      vic2_display_if_bad_line(vic2);
32322037
3233      vic2.cycle++;
2038      vic2->cycle++;
32342039      break;
32352040
32362041   // Sprite 1, draw
32372042   case 62:
3238      DrawBackground;
3239      SampleBorder;
2043      vic2_draw_background(vic2);
2044      vic2_sample_border(vic2);
32402045
3241      if (draw_this_line)
2046      if (vic2->draw_this_line)
32422047      {
3243         DrawSprites;
2048         vic2_draw_sprites(machine, vic2);
32442049
3245         if (border_on_sample[0])
2050         if (vic2->border_on_sample[0])
32462051            for (i = 0; i < 4; i++)
3247               plot_box(vic2.bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[i]);
2052               plot_box(vic2->bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[i]);
32482053
3249         if (border_on_sample[1])
3250            plot_box(vic2.bitmap, VIC2_X_2_EMU(4 * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[4]);
2054         if (vic2->border_on_sample[1])
2055            plot_box(vic2->bitmap, VIC2_X_2_EMU(4 * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[4]);
32512056
3252         if (border_on_sample[2])
2057         if (vic2->border_on_sample[2])
32532058            for (i = 5; i < 43; i++)
3254               plot_box(vic2.bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[i]);
2059               plot_box(vic2->bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[i]);
32552060
3256         if (border_on_sample[3])
3257            plot_box(vic2.bitmap, VIC2_X_2_EMU(43 * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[43]);
2061         if (vic2->border_on_sample[3])
2062            plot_box(vic2->bitmap, VIC2_X_2_EMU(43 * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[43]);
32582063
3259         if (border_on_sample[4])
2064         if (vic2->border_on_sample[4])
32602065         {
32612066            for (i = 44; i < 48; i++)
3262               plot_box(vic2.bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[i]);
2067               plot_box(vic2->bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[i]);
32632068            for (i = 48; i < 53; i++)
3264               plot_box(vic2.bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2.rasterline), 8, 1, border_color_sample[47]);
2069               plot_box(vic2->bitmap, VIC2_X_2_EMU(i * 8), VIC2_RASTER_2_EMU(vic2->rasterline), 8, 1, vic2->border_color_sample[47]);
32652070         }
32662071      }
32672072
3268      SprPtrAccess(1);
3269      SprDataAccess(1, 0);
3270      DisplayIfBadLine;
2073      vic2_spr_ptr_access(machine, vic2, 1);
2074      vic2_spr_data_access(machine, vic2, 1, 0);
2075      vic2_display_if_bad_line(vic2);
32712076
3272      if(spr_dma_on & 0x02)
3273         SuspendCPU
2077      if (vic2->spr_dma_on & 0x02)
2078         vic2_suspend_cpu(machine, vic2);
32742079      else
3275         ResumeCPU
2080         vic2_resume_cpu(machine, vic2);
32762081
3277      vic2.cycle++;
2082      vic2->cycle++;
32782083      break;
32792084
32802085   // Sprite 1
32812086   case 63:
3282      SprDataAccess(1, 1);
3283      SprDataAccess(1, 2);
3284      DisplayIfBadLine;
2087      vic2_spr_data_access(machine, vic2, 1, 1);
2088      vic2_spr_data_access(machine, vic2, 1, 2);
2089      vic2_display_if_bad_line(vic2);
32852090
3286      vic2.cycle++;
2091      vic2->cycle++;
32872092      break;
32882093
32892094   // Sprite 2
32902095   case 64:
3291      SprPtrAccess(2);
3292      SprDataAccess(2, 0);
3293      DisplayIfBadLine;
2096      vic2_spr_ptr_access(machine, vic2, 2);
2097      vic2_spr_data_access(machine, vic2, 2, 0);
2098      vic2_display_if_bad_line(vic2);
32942099
3295      if(spr_dma_on & 0x04)
3296         SuspendCPU
2100      if (vic2->spr_dma_on & 0x04)
2101         vic2_suspend_cpu(machine, vic2);
32972102      else
3298         ResumeCPU
2103         vic2_resume_cpu(machine, vic2);
32992104
3300      vic2.cycle++;
2105      vic2->cycle++;
33012106      break;
33022107
33032108   // Sprite 2
33042109   case 65:
3305      SprDataAccess(2, 1);
3306      SprDataAccess(2, 2);
3307      DisplayIfBadLine;
2110      vic2_spr_data_access(machine, vic2, 2, 1);
2111      vic2_spr_data_access(machine, vic2, 2, 2);
2112      vic2_display_if_bad_line(vic2);
33082113
3309      if (vic2.rasterline == dy_stop)
3310         ud_border_on = 1;
2114      if (vic2->rasterline == vic2->dy_stop)
2115         vic2->ud_border_on = 1;
33112116      else
3312         if (SCREENON && (vic2.rasterline == dy_start))
3313            ud_border_on = 0;
2117         if (SCREENON && (vic2->rasterline == vic2->dy_start))
2118            vic2->ud_border_on = 0;
33142119
33152120      // Last cycle
3316      vic2.cycle = 1;
2121      vic2->cycle = 1;
33172122   }
33182123
3319   vic2.raster_x += 8;
3320   timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, NTSC_timer_callback);
2124   vic2->raster_x += 8;
2125   timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 1), vic2, 0, ntsc_timer_callback);
33212126}
33222127
3323VIDEO_UPDATE( vic2 )
2128
2129/*****************************************************************************
2130    I/O HANDLERS
2131*****************************************************************************/
2132
2133void vic2_set_rastering( running_device *device, int onoff )
33242134{
3325   if (vic2.on)
3326      copybitmap(bitmap, vic2.bitmap, 0, 0, 0, 0, cliprect);
2135    vic2_state *vic2 = get_safe_token(device);
2136   vic2->on = onoff;
2137}
2138
2139int vic2e_k0_r( running_device *device )
2140{
2141    vic2_state *vic2 = get_safe_token(device);
2142   return VIC2E_K0_LEVEL;
2143}
2144
2145int vic2e_k1_r( running_device *device )
2146{
2147    vic2_state *vic2 = get_safe_token(device);
2148   return VIC2E_K1_LEVEL;
2149}
2150
2151int vic2e_k2_r( running_device *device )
2152{
2153    vic2_state *vic2 = get_safe_token(device);
2154   return VIC2E_K2_LEVEL;
2155}
2156
2157
2158WRITE8_DEVICE_HANDLER( vic2_port_w )
2159{
2160    vic2_state *vic2 = get_safe_token(device);
2161   running_machine *machine = device->machine;
2162
2163   DBG_LOG(2, "vic write", ("%.2x:%.2x\n", offset, data));
2164   offset &= 0x3f;
2165
2166   switch (offset)
2167   {
2168   case 0x01:
2169   case 0x03:
2170   case 0x05:
2171   case 0x07:
2172   case 0x09:
2173   case 0x0b:
2174   case 0x0d:
2175   case 0x0f:
2176      vic2->reg[offset] = data;      /* sprite y positions */
2177      break;
2178
2179   case 0x00:
2180   case 0x02:
2181   case 0x04:
2182   case 0x06:
2183   case 0x08:
2184   case 0x0a:
2185   case 0x0c:
2186   case 0x0e:
2187      vic2->reg[offset] = data;      /* sprite x positions */
2188      break;
2189
2190   case 0x10:
2191      vic2->reg[offset] = data;      /* sprite x positions */
2192      break;
2193
2194   case 0x17:                     /* sprite y size */
2195      vic2->spr_exp_y |= ~data;
2196      if (vic2->reg[offset] != data)
2197      {
2198         vic2->reg[offset] = data;
2199      }
2200      break;
2201
2202   case 0x1d:                     /* sprite x size */
2203      if (vic2->reg[offset] != data)
2204      {
2205         vic2->reg[offset] = data;
2206      }
2207      break;
2208
2209   case 0x1b:                     /* sprite background priority */
2210      if (vic2->reg[offset] != data)
2211      {
2212         vic2->reg[offset] = data;
2213      }
2214      break;
2215
2216   case 0x1c:                     /* sprite multicolor mode select */
2217      if (vic2->reg[offset] != data)
2218      {
2219         vic2->reg[offset] = data;
2220      }
2221      break;
2222
2223   case 0x27:
2224   case 0x28:
2225   case 0x29:
2226   case 0x2a:
2227   case 0x2b:
2228   case 0x2c:
2229   case 0x2d:
2230   case 0x2e:
2231                           /* sprite colors */
2232      if (vic2->reg[offset] != data)
2233      {
2234         vic2->reg[offset] = data;
2235      }
2236      break;
2237
2238   case 0x25:                     /* sprite multicolor */
2239      if (vic2->reg[offset] != data)
2240      {
2241         vic2->reg[offset] = data;
2242         vic2->spritemulti[1] = SPRITE_MULTICOLOR1;
2243      }
2244      break;
2245
2246   case 0x26:                     /* sprite multicolor */
2247      if (vic2->reg[offset] != data)
2248      {
2249         vic2->reg[offset] = data;
2250         vic2->spritemulti[3] = SPRITE_MULTICOLOR2;
2251      }
2252      break;
2253
2254   case 0x19:
2255      vic2_clear_interrupt(machine, data & 0x0f, vic2);
2256      break;
2257
2258   case 0x1a:                     /* irq mask */
2259      vic2->reg[offset] = data;
2260      vic2_set_interrupt(machine, 0, vic2);    // beamrider needs this
2261      break;
2262
2263   case 0x11:
2264      if (vic2->reg[offset] != data)
2265      {
2266         vic2->reg[offset] = data;
2267         if (data & 8)
2268         {
2269            vic2->dy_start = ROW25_YSTART;
2270            vic2->dy_stop = ROW25_YSTOP;
2271         }
2272         else
2273         {
2274            vic2->dy_start = ROW24_YSTART;
2275            vic2->dy_stop = ROW24_YSTOP;
2276         }
2277      }
2278      break;
2279
2280   case 0x12:
2281      if (data != vic2->reg[offset])
2282      {
2283         vic2->reg[offset] = data;
2284      }
2285      break;
2286
2287   case 0x16:
2288      if (vic2->reg[offset] != data)
2289      {
2290         vic2->reg[offset] = data;
2291      }
2292      break;
2293
2294   case 0x18:
2295      if (vic2->reg[offset] != data)
2296      {
2297         vic2->reg[offset] = data;
2298         vic2->videoaddr = VIDEOADDR;
2299         vic2->chargenaddr = CHARGENADDR;
2300         vic2->bitmapaddr = BITMAPADDR;
2301      }
2302      break;
2303
2304   case 0x21:                     /* background color */
2305      if (vic2->reg[offset] != data)
2306      {
2307         vic2->reg[offset] = data;
2308         vic2->colors[0] = BACKGROUNDCOLOR;
2309      }
2310      break;
2311
2312   case 0x22:                     /* background color 1 */
2313      if (vic2->reg[offset] != data)
2314      {
2315         vic2->reg[offset] = data;
2316         vic2->colors[1] = MULTICOLOR1;
2317      }
2318      break;
2319
2320   case 0x23:                     /* background color 2 */
2321      if (vic2->reg[offset] != data)
2322      {
2323         vic2->reg[offset] = data;
2324         vic2->colors[2] = MULTICOLOR2;
2325      }
2326      break;
2327
2328   case 0x24:                     /* background color 3 */
2329      if (vic2->reg[offset] != data)
2330      {
2331         vic2->reg[offset] = data;
2332         vic2->colors[3] = FOREGROUNDCOLOR;
2333      }
2334      break;
2335
2336   case 0x20:                     /* framecolor */
2337      if (vic2->reg[offset] != data)
2338      {
2339         vic2->reg[offset] = data;
2340      }
2341      break;
2342
2343   case 0x2f:
2344      if (vic2->type == VIC8564 || vic2->type == VIC8566)
2345      {
2346         DBG_LOG(2, "vic write", ("%.2x:%.2x\n", offset, data));
2347         vic2->reg[offset] = data;
2348      }
2349      break;
2350
2351   case 0x30:
2352      if (vic2->type == VIC8564 || vic2->type == VIC8566)
2353      {
2354         vic2->reg[offset] = data;
2355      }
2356      break;
2357
2358   case 0x31:
2359   case 0x32:
2360   case 0x33:
2361   case 0x34:
2362   case 0x35:
2363   case 0x36:
2364   case 0x37:
2365   case 0x38:
2366   case 0x39:
2367   case 0x3a:
2368   case 0x3b:
2369   case 0x3c:
2370   case 0x3d:
2371   case 0x3e:
2372   case 0x3f:
2373      vic2->reg[offset] = data;
2374      DBG_LOG(2, "vic write", ("%.2x:%.2x\n", offset, data));
2375      break;
2376
2377   default:
2378      vic2->reg[offset] = data;
2379      break;
2380   }
2381}
2382
2383READ8_DEVICE_HANDLER( vic2_port_r )
2384{
2385    vic2_state *vic2 = get_safe_token(device);
2386   running_machine *machine = device->machine;
2387   int val = 0;
2388
2389   offset &= 0x3f;
2390
2391   switch (offset)
2392   {
2393   case 0x11:
2394      val = (vic2->reg[offset] & ~0x80) | ((vic2->rasterline & 0x100) >> 1);
2395      break;
2396
2397   case 0x12:
2398      val = vic2->rasterline & 0xff;
2399      break;
2400
2401   case 0x16:
2402      val = vic2->reg[offset] | 0xc0;
2403      break;
2404
2405   case 0x18:
2406      val = vic2->reg[offset] | 0x01;
2407      break;
2408
2409   case 0x19:                     /* interrupt flag register */
2410      /* vic2_clear_interrupt(0xf); */
2411      val = vic2->reg[offset] | 0x70;
2412      break;
2413
2414   case 0x1a:
2415      val = vic2->reg[offset] | 0xf0;
2416      break;
2417
2418   case 0x1e:                     /* sprite to sprite collision detect */
2419      val = vic2->reg[offset];
2420      vic2->reg[offset] = 0;
2421      vic2_clear_interrupt(machine, 4, vic2);
2422      break;
2423
2424   case 0x1f:                     /* sprite to background collision detect */
2425      val = vic2->reg[offset];
2426      vic2->reg[offset] = 0;
2427      vic2_clear_interrupt(machine, 2, vic2);
2428      break;
2429
2430   case 0x20:
2431   case 0x21:
2432   case 0x22:
2433   case 0x23:
2434   case 0x24:
2435      val = vic2->reg[offset];
2436      break;
2437
2438   case 0x00:
2439   case 0x01:
2440   case 0x02:
2441   case 0x03:
2442   case 0x04:
2443   case 0x05:
2444   case 0x06:
2445   case 0x07:
2446   case 0x08:
2447   case 0x09:
2448   case 0x0a:
2449   case 0x0b:
2450   case 0x0c:
2451   case 0x0d:
2452   case 0x0e:
2453   case 0x0f:
2454   case 0x10:
2455   case 0x17:
2456   case 0x1b:
2457   case 0x1c:
2458   case 0x1d:
2459   case 0x25:
2460   case 0x26:
2461   case 0x27:
2462   case 0x28:
2463   case 0x29:
2464   case 0x2a:
2465   case 0x2b:
2466   case 0x2c:
2467   case 0x2d:
2468   case 0x2e:
2469      val = vic2->reg[offset];
2470      break;
2471
2472   case 0x2f:
2473   case 0x30:
2474      if (vic2->type == VIC8564 || vic2->type == VIC8566)
2475      {
2476         val = vic2->reg[offset];
2477         DBG_LOG(2, "vic read", ("%.2x:%.2x\n", offset, val));
2478      }
2479      else
2480         val = 0xff;
2481      break;
2482
2483   case 0x31:
2484   case 0x32:
2485   case 0x33:
2486   case 0x34:
2487   case 0x35:
2488   case 0x36:
2489   case 0x37:
2490   case 0x38:
2491   case 0x39:
2492   case 0x3a:
2493   case 0x3b:
2494   case 0x3c:
2495   case 0x3d:
2496   case 0x3e:
2497   case 0x3f:                     /* not used */
2498      // val = vic2->reg[offset]; //
2499      val = 0xff;
2500      DBG_LOG(2, "vic read", ("%.2x:%.2x\n", offset, val));
2501      break;
2502
2503   default:
2504      val = vic2->reg[offset];
2505   }
2506
2507   if ((offset != 0x11) && (offset != 0x12))
2508      DBG_LOG(2, "vic read", ("%.2x:%.2x\n", offset, val));
2509   return val;
2510}
2511
2512UINT32 vic2_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect )
2513{
2514   vic2_state *vic2 = get_safe_token(device);
2515
2516   if (vic2->on)
2517      copybitmap(bitmap, vic2->bitmap, 0, 0, 0, 0, cliprect);
33272518   return 0;
33282519}
33292520
3330static PALETTE_INIT( vic2 )
2521/*****************************************************************************
2522    DEVICE INTERFACE
2523*****************************************************************************/
2524
2525static DEVICE_START( vic2 )
33312526{
2527   vic2_state *vic2 = get_safe_token(device);
2528   const vic2_interface *intf = (vic2_interface *)device->baseconfig().static_config;
2529   int width, height;
33322530   int i;
33332531
3334   for ( i = 0; i < sizeof(vic2_palette) / 3; i++ ) {
3335      palette_set_color_rgb(machine, i, vic2_palette[i*3], vic2_palette[i*3+1], vic2_palette[i*3+2]);
2532   vic2->cpu = devtag_get_device(device->machine, intf->cpu);
2533
2534   vic2->screen = devtag_get_device(device->machine, intf->screen);
2535   width = video_screen_get_width(vic2->screen);
2536   height = video_screen_get_height(vic2->screen);
2537
2538   vic2->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
2539
2540   vic2->type = intf->type;
2541
2542   vic2->dma_read = intf->dma_read;
2543   vic2->dma_read_color = intf->dma_read_color;
2544   vic2->interrupt = intf->irq;
2545
2546   vic2->rdy_workaround_cb = intf->rdy_cb;
2547
2548   vic2->lightpen_button_cb = intf->button_cb;
2549   vic2->lightpen_x_cb = intf->x_cb;
2550   vic2->lightpen_y_cb = intf->y_cb;
2551
2552   vic2->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
2553
2554   // immediately call the timer to handle the first line
2555   if (vic2->type == VIC6569 || vic2->type == VIC8566)
2556      timer_set(device->machine, cpu_clocks_to_attotime(vic2->cpu, 0), vic2, 0, pal_timer_callback);
2557   else
2558      timer_set(device->machine, cpu_clocks_to_attotime(vic2->cpu, 0), vic2, 0, ntsc_timer_callback);
2559
2560   for (i = 0; i < 256; i++)
2561   {
2562      vic2->expandx[i] = 0;
2563      if (i & 1)
2564         vic2->expandx[i] |= 3;
2565      if (i & 2)
2566         vic2->expandx[i] |= 0xc;
2567      if (i & 4)
2568         vic2->expandx[i] |= 0x30;
2569      if (i & 8)
2570         vic2->expandx[i] |= 0xc0;
2571      if (i & 0x10)
2572         vic2->expandx[i] |= 0x300;
2573      if (i & 0x20)
2574         vic2->expandx[i] |= 0xc00;
2575      if (i & 0x40)
2576         vic2->expandx[i] |= 0x3000;
2577      if (i & 0x80)
2578         vic2->expandx[i] |= 0xc000;
33362579   }
2580
2581   for (i = 0; i < 256; i++)
2582   {
2583      vic2->expandx_multi[i] = 0;
2584      if (i & 1)
2585         vic2->expandx_multi[i] |= 5;
2586      if (i & 2)
2587         vic2->expandx_multi[i] |= 0xa;
2588      if (i & 4)
2589         vic2->expandx_multi[i] |= 0x50;
2590      if (i & 8)
2591         vic2->expandx_multi[i] |= 0xa0;
2592      if (i & 0x10)
2593         vic2->expandx_multi[i] |= 0x500;
2594      if (i & 0x20)
2595         vic2->expandx_multi[i] |= 0xa00;
2596      if (i & 0x40)
2597         vic2->expandx_multi[i] |= 0x5000;
2598      if (i & 0x80)
2599         vic2->expandx_multi[i] |= 0xa000;
2600   }
2601
2602   state_save_register_device_item_array(device, 0, vic2->reg);
2603
2604   state_save_register_device_item(device, 0, vic2->on);
2605
2606   state_save_register_device_item_bitmap(device, 0, vic2->bitmap);
2607
2608   state_save_register_device_item(device, 0, vic2->chargenaddr);
2609   state_save_register_device_item(device, 0, vic2->videoaddr);
2610   state_save_register_device_item(device, 0, vic2->bitmapaddr);
2611
2612   state_save_register_device_item_array(device, 0, vic2->colors);
2613   state_save_register_device_item_array(device, 0, vic2->spritemulti);
2614
2615   state_save_register_device_item(device, 0, vic2->rasterline);
2616   state_save_register_device_item(device, 0, vic2->cycles_counter);
2617   state_save_register_device_item(device, 0, vic2->cycle);
2618   state_save_register_device_item(device, 0, vic2->raster_x);
2619   state_save_register_device_item(device, 0, vic2->graphic_x);
2620
2621   state_save_register_device_item(device, 0, vic2->dy_start);
2622   state_save_register_device_item(device, 0, vic2->dy_stop);
2623
2624   state_save_register_device_item(device, 0, vic2->draw_this_line);
2625   state_save_register_device_item(device, 0, vic2->is_bad_line);
2626   state_save_register_device_item(device, 0, vic2->bad_lines_enabled);
2627   state_save_register_device_item(device, 0, vic2->display_state);
2628   state_save_register_device_item(device, 0, vic2->char_data);
2629   state_save_register_device_item(device, 0, vic2->gfx_data);
2630   state_save_register_device_item(device, 0, vic2->color_data);
2631   state_save_register_device_item(device, 0, vic2->last_char_data);
2632   state_save_register_device_item_array(device, 0, vic2->matrix_line);
2633   state_save_register_device_item_array(device, 0, vic2->color_line);
2634   state_save_register_device_item(device, 0, vic2->vblanking);
2635   state_save_register_device_item(device, 0, vic2->ml_index);
2636   state_save_register_device_item(device, 0, vic2->rc);
2637   state_save_register_device_item(device, 0, vic2->vc);
2638   state_save_register_device_item(device, 0, vic2->vc_base);
2639   state_save_register_device_item(device, 0, vic2->ref_cnt);
2640
2641   state_save_register_device_item_array(device, 0, vic2->spr_coll_buf);
2642   state_save_register_device_item_array(device, 0, vic2->fore_coll_buf);
2643   state_save_register_device_item(device, 0, vic2->spr_exp_y);
2644   state_save_register_device_item(device, 0, vic2->spr_dma_on);
2645   state_save_register_device_item(device, 0, vic2->spr_draw);
2646   state_save_register_device_item(device, 0, vic2->spr_disp_on);
2647   state_save_register_device_item_array(device, 0, vic2->spr_ptr);
2648   state_save_register_device_item_array(device, 0, vic2->mc_base);
2649   state_save_register_device_item_array(device, 0, vic2->mc);
2650
2651   for (i = 0; i < 8; i++)
2652   {
2653      state_save_register_device_item_array(device, i, vic2->spr_data[i]);
2654      state_save_register_device_item_array(device, i, vic2->spr_draw_data[i]);
2655   }
2656
2657   state_save_register_device_item(device, 0, vic2->border_on);
2658   state_save_register_device_item(device, 0, vic2->ud_border_on);
2659   state_save_register_device_item_array(device, 0, vic2->border_on_sample);
2660   state_save_register_device_item_array(device, 0, vic2->border_color_sample);
2661
2662   state_save_register_device_item(device, 0, vic2->first_ba_cycle);
2663   state_save_register_device_item(device, 0, vic2->cpu_suspended);
33372664}
33382665
3339MACHINE_DRIVER_START( vh_vic2 )
3340   MDRV_SCREEN_ADD("screen", RASTER)
3341   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
3342   MDRV_SCREEN_SIZE(VIC6567_COLUMNS, VIC6567_LINES)
3343   MDRV_SCREEN_VISIBLE_AREA(0, VIC6567_VISIBLECOLUMNS - 1, 0, VIC6567_VISIBLELINES - 1)
3344   MDRV_PALETTE_INIT( vic2 )
3345   MDRV_PALETTE_LENGTH(ARRAY_LENGTH(vic2_palette) / 3)
3346   MDRV_VIDEO_START( vic2 )
3347   MDRV_VIDEO_UPDATE( vic2 )
3348MACHINE_DRIVER_END
2666static DEVICE_RESET( vic2 )
2667{
2668   vic2_state *vic2 = get_safe_token(device);
2669   int i, j;
33492670
3350MACHINE_DRIVER_START( vh_vic2_pal )
3351   MDRV_SCREEN_ADD("screen", RASTER)
3352   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
3353   MDRV_SCREEN_SIZE(VIC6569_COLUMNS, VIC6569_LINES)
3354   MDRV_SCREEN_VISIBLE_AREA(0, VIC6569_VISIBLECOLUMNS - 1, 0, VIC6569_VISIBLELINES - 1)
3355   MDRV_PALETTE_INIT( vic2 )
3356   MDRV_PALETTE_LENGTH(ARRAY_LENGTH(vic2_palette) / 3)
3357   MDRV_VIDEO_START( vic2 )
3358   MDRV_VIDEO_UPDATE( vic2 )
3359MACHINE_DRIVER_END
2671   memset(vic2->reg, 0, ARRAY_LENGTH(vic2->reg));
33602672
2673   for (i = 0; i < ARRAY_LENGTH(vic2->mc); i++)
2674      vic2->mc[i] = 63;
2675
2676   // from 0 to 311 (0 first, PAL) or from 0 to 261 (? first, NTSC 6567R56A) or from 0 to 262 (? first, NTSC 6567R8)
2677   vic2->rasterline = 0; // VIC2_LINES - 1;
2678
2679   vic2->cycles_counter = 0;
2680   vic2->cycle = 63;
2681
2682   vic2->on = 1;
2683
2684   vic2->dy_start = ROW24_YSTART;
2685   vic2->dy_stop = ROW24_YSTOP;
2686
2687   vic2->draw_this_line = 0;
2688   vic2->is_bad_line = 0;
2689   vic2->bad_lines_enabled = 0;
2690   vic2->display_state = 0;
2691   vic2->char_data = 0;
2692   vic2->gfx_data = 0;
2693   vic2->color_data = 0;
2694   vic2->last_char_data = 0;
2695   vic2->vblanking = 0;
2696   vic2->ml_index = 0;
2697   vic2->rc = 0;
2698   vic2->vc = 0;
2699   vic2->vc_base = 0;
2700   vic2->ref_cnt = 0;
2701
2702   vic2->spr_exp_y = 0;
2703   vic2->spr_dma_on = 0;
2704   vic2->spr_draw = 0;
2705   vic2->spr_disp_on = 0;
2706
2707
2708   vic2->border_on = 0;
2709   vic2->ud_border_on = 0;
2710
2711   vic2->first_ba_cycle = 0;
2712   vic2->cpu_suspended = 0;
2713
2714   memset(vic2->matrix_line, 0, ARRAY_LENGTH(vic2->matrix_line));
2715   memset(vic2->color_line, 0, ARRAY_LENGTH(vic2->color_line));
2716
2717   memset(vic2->spr_coll_buf, 0, ARRAY_LENGTH(vic2->spr_coll_buf));
2718   memset(vic2->fore_coll_buf, 0, ARRAY_LENGTH(vic2->fore_coll_buf));
2719   memset(vic2->border_on_sample, 0, ARRAY_LENGTH(vic2->border_on_sample));
2720   memset(vic2->border_color_sample, 0, ARRAY_LENGTH(vic2->border_color_sample));
2721
2722   for (i = 0; i < 8; i++)
2723   {
2724      vic2->spr_ptr[i] = 0;
2725      vic2->mc_base[i] = 0;
2726      vic2->mc[i] = 0;
2727      for (j = 0; j < 4; j++)
2728      {
2729         vic2->spr_draw_data[i][j] = 0;
2730         vic2->spr_data[i][j] = 0;
2731      }
2732   }
2733
2734}
2735
2736
2737/*-------------------------------------------------
2738    device definition
2739-------------------------------------------------*/
2740
2741static const char DEVTEMPLATE_SOURCE[] = __FILE__;
2742
2743#define DEVTEMPLATE_ID(p,s)            p##vic2##s
2744#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
2745#define DEVTEMPLATE_NAME            "6567 / 6569 VIC II"
2746#define DEVTEMPLATE_FAMILY            "6567 / 6569 VIC II"
2747#include "devtempl.h"
src/mess/video/vic6567.h
r7364r7365
22 *
33 * video/vic6567.h
44 *
5 * if you need this chip in another mame/mess emulation than let it me know
6 * I will split this from the c64 driver
7 * peter.trauner@jk.uni-linz.ac.at
8 * 1. 1. 2000
9 * look at mess/drivers/c64.c and mess/machine/c64.c
10 * on how to use it
11 *
125 ****************************************************************************/
136
14// there're many chips; we use for PAL: 6569 and for NTSC 6567R8
7#ifndef __VIC6567_H__
8#define __VIC6567_H__
159
16#ifndef VIC6567_H_
17#define VIC6567_H_
10#include "devcb.h"
1811
12
13/***************************************************************************
14    TYPE DEFINITIONS
15***************************************************************************/
16
17typedef UINT8 (*vic2_lightpen_x_callback)(running_machine *machine);
18typedef UINT8 (*vic2_lightpen_y_callback)(running_machine *machine);
19typedef UINT8 (*vic2_lightpen_button_callback)(running_machine *machine);
20
21typedef int (*vic2_dma_read)(running_machine *machine, int);
22typedef int (*vic2_dma_read_color)(running_machine *machine, int);
23typedef void (*vic2_irq) (running_machine *, int);
24
25typedef UINT8 (*vic2_rdy_callback)(running_machine *machine);
26
27typedef enum
28{
29   VIC6567,   // VIC II NTSC
30   VIC6569,   // VIC II PAL
31      VIC8564,   // VIC IIe NTSC
32      VIC8566   // VIC IIe PAL
33} vic2_type;
34
35typedef struct _vic2_interface vic2_interface;
36struct _vic2_interface
37{
38   const char         *screen;
39   const char         *cpu;
40
41   vic2_type type;
42
43   vic2_lightpen_x_callback        x_cb;
44   vic2_lightpen_y_callback        y_cb;
45   vic2_lightpen_button_callback   button_cb;
46
47   vic2_dma_read          dma_read;
48   vic2_dma_read_color    dma_read_color;
49   vic2_irq               irq;
50
51   vic2_rdy_callback        rdy_cb;
52};
53
54/***************************************************************************
55    CONSTANTS
56***************************************************************************/
57
1958#define VIC6567_CLOCK      (1022700 /* = 8181600 / 8) */ )
2059#define VIC6569_CLOCK      ( 985248 /* = 7881984 / 8) */ )
21#define VIC2_CLOCK      (vic2.pal ? VIC6569_CLOCK : VIC6567_CLOCK)
2260
2361#define VIC6567_CYCLESPERLINE   65
2462#define VIC6569_CYCLESPERLINE   63
25#define VIC2_CYCLESPERLINE   (vic2.pal ? VIC6569_CYCLESPERLINE : VIC6567_CYCLESPERLINE)
2663
2764#define VIC6567_LINES      263
2865#define VIC6569_LINES      312
29#define VIC2_LINES      (vic2.pal ? VIC6569_LINES : VIC6567_LINES)
3066
3167#define VIC6567_VRETRACERATE   (59.8245100906698 /* = 1022700 / (65 * 263) */ )
3268#define VIC6569_VRETRACERATE   (50.1245421245421 /* =  985248 / (63 * 312) */ )
33#define VIC2_VRETRACERATE   (VIC2_CLOCK / (VIC2_CYCLESPERLINE * VIC2_LINES))
3469
3570#define VIC6567_HRETRACERATE   (VIC6567_CLOCK / VIC6567_CYCLESPERLINE)
3671#define VIC6569_HRETRACERATE   (VIC6569_CLOCK / VIC6569_CYCLESPERLINE)
37#define VIC2_HRETRACERATE   (VIC2_CLOCK / VIC2_CYCLESPERLINE)
3872
3973#define VIC2_HSIZE      320
4074#define VIC2_VSIZE      200
4175
4276#define VIC6567_VISIBLELINES   235
4377#define VIC6569_VISIBLELINES   284
44#define VIC2_VISIBLELINES   (vic2.pal ? VIC6569_VISIBLELINES : VIC6567_VISIBLELINES)
4578
4679#define VIC6567_FIRST_DMA_LINE   0x30
4780#define VIC6569_FIRST_DMA_LINE   0x30
48#define VIC2_FIRST_DMA_LINE   (vic2.pal ? VIC6569_FIRST_DMA_LINE : VIC6567_FIRST_DMA_LINE)
4981
5082#define VIC6567_LAST_DMA_LINE   0xf7
5183#define VIC6569_LAST_DMA_LINE   0xf7
52#define VIC2_LAST_DMA_LINE   (vic2.pal ? VIC6569_LAST_DMA_LINE : VIC6567_LAST_DMA_LINE)
5384
5485#define VIC6567_FIRST_DISP_LINE   0x29
5586#define VIC6569_FIRST_DISP_LINE   0x10
56#define VIC2_FIRST_DISP_LINE   (vic2.pal ? VIC6569_FIRST_DISP_LINE : VIC6567_FIRST_DISP_LINE)
5787
5888#define VIC6567_LAST_DISP_LINE   (VIC6567_FIRST_DISP_LINE + VIC6567_VISIBLELINES - 1)
5989#define VIC6569_LAST_DISP_LINE   (VIC6569_FIRST_DISP_LINE + VIC6569_VISIBLELINES - 1)
60#define VIC2_LAST_DISP_LINE   (vic2.pal ? VIC6569_LAST_DISP_LINE : VIC6567_LAST_DISP_LINE)
6190
6291#define VIC6567_RASTER_2_EMU(a) ((a >= VIC6567_FIRST_DISP_LINE) ? (a - VIC6567_FIRST_DISP_LINE) : (a + 222))
6392#define VIC6569_RASTER_2_EMU(a) (a - VIC6569_FIRST_DISP_LINE)
64#define VIC2_RASTER_2_EMU(a)   (vic2.pal ? VIC6569_RASTER_2_EMU(a) : VIC6567_RASTER_2_EMU(a))
6593
6694#define VIC6567_FIRSTCOLUMN   50
6795#define VIC6569_FIRSTCOLUMN   50
68#define VIC2_FIRSTCOLUMN   (vic2.pal ? VIC6569_FIRSTCOLUMN : VIC6567_FIRSTCOLUMN)
6996
7097#define VIC6567_VISIBLECOLUMNS   418
7198#define VIC6569_VISIBLECOLUMNS   403
72#define VIC2_VISIBLECOLUMNS   (vic2.pal ? VIC6569_VISIBLECOLUMNS : VIC6567_VISIBLECOLUMNS)
7399
74100#define VIC6567_X_2_EMU(a)   (a)
75101#define VIC6569_X_2_EMU(a)   (a)
76#define VIC2_X_2_EMU(a)      (vic2.pal ? VIC6569_X_2_EMU(a) : VIC6567_X_2_EMU(a))
77102
78103#define VIC6567_STARTVISIBLELINES ((VIC6567_LINES - VIC6567_VISIBLELINES)/2)
79104#define VIC6569_STARTVISIBLELINES 16 /* ((VIC6569_LINES - VIC6569_VISIBLELINES)/2) */
80#define VIC2_STARTVISIBLELINES ((VIC2_LINES - VIC2_VISIBLELINES)/2)
81105
82106#define VIC6567_FIRSTRASTERLINE 34
83107#define VIC6569_FIRSTRASTERLINE 0
84#define VIC2_FIRSTRASTERLINE (vic2.pal?VIC6569_FIRSTRASTERLINE:VIC6567_FIRSTRASTERLINE)
85108
86109#define VIC6567_COLUMNS 512
87110#define VIC6569_COLUMNS 504
88#define VIC2_COLUMNS (vic2.pal?VIC6569_COLUMNS:VIC6567_COLUMNS)
89111
90112
91
92113#define VIC6567_STARTVISIBLECOLUMNS ((VIC6567_COLUMNS - VIC6567_VISIBLECOLUMNS)/2)
93114#define VIC6569_STARTVISIBLECOLUMNS ((VIC6569_COLUMNS - VIC6569_VISIBLECOLUMNS)/2)
94#define VIC2_STARTVISIBLECOLUMNS ((VIC2_COLUMNS - VIC2_VISIBLECOLUMNS)/2)
95115
96116#define VIC6567_FIRSTRASTERCOLUMNS 412
97117#define VIC6569_FIRSTRASTERCOLUMNS 404
98#define VIC2_FIRSTRASTERCOLUMNS (vic2.pal?VIC6569_FIRSTRASTERCOLUMNS:VIC6567_FIRSTRASTERCOLUMNS)
99118
100119#define VIC6569_FIRST_X 0x194
101120#define VIC6567_FIRST_X 0x19c
102#define VIC2_FIRST_X (vic2.pal?VIC6569_FIRST_X:VIC6567_FIRST_X)
103121
104122#define VIC6569_FIRST_VISIBLE_X 0x1e0
105123#define VIC6567_FIRST_VISIBLE_X 0x1e8
106#define VIC2_FIRST_VISIBLE_X (vic2.pal?VIC6569_FIRST_VISIBLE_X:VIC6567_FIRST_VISIBLE_X)
107124
108125#define VIC6569_MAX_X 0x1f7
109126#define VIC6567_MAX_X 0x1ff
110#define VIC2_MAX_X (vic2.pal?VIC6569_MAX_X:VIC6567_MAX_X)
111127
112128#define VIC6569_LAST_VISIBLE_X 0x17c
113129#define VIC6567_LAST_VISIBLE_X 0x184
114#define VIC2_LAST_VISIBLE_X (vic2.pal?VIC6569_LAST_VISIBLE_X:VIC6567_LAST_VISIBLE_X)
115130
116131#define VIC6569_LAST_X 0x193
117132#define VIC6567_LAST_X 0x19b
118#define VIC2_LAST_X (vic2.pal?VIC6569_LAST_X:VIC6567_LAST_X)
119133
120134
121/*----------- defined in video/vic6567.c -----------*/
135/***************************************************************************
136    FUNCTION PROTOTYPES
137***************************************************************************/
122138
123/* call to init videodriver */
124/* dma_read: videochip fetched 1 byte data from system bus */
125extern void vic6567_init(int vic2e, int pal, int (*dma_read)(running_machine *, int), int (*dma_read_color)(running_machine *, int), void (*irq)(running_machine *,int));
139DEVICE_GET_INFO( vic2 );
126140
127extern void vic2_set_rastering(int onoff);
141/***************************************************************************
142    DEVICE CONFIGURATION MACROS
143***************************************************************************/
128144
129MACHINE_DRIVER_EXTERN( vh_vic2 );
130MACHINE_DRIVER_EXTERN( vh_vic2_pal );
131extern VIDEO_START( vic2 );
132extern VIDEO_UPDATE( vic2 );
133// extern INTERRUPT_GEN( vic2_raster_irq );
134// extern emu_timer *vicii_scanline_timer;
135// extern TIMER_CALLBACK( vicii_scanline_interrupt );
145#define VIC2 DEVICE_GET_INFO_NAME( vic2 )
136146
137extern const unsigned char vic2_palette[16 * 3];
147#define MDRV_VIC2_ADD(_tag, _interface) \
148   MDRV_DEVICE_ADD(_tag, VIC2, 0) \
149   MDRV_DEVICE_CONFIG(_interface)
138150
139/* to be called when writting to port */
140extern WRITE8_HANDLER ( vic2_port_w );
141151
142/* to be called when reading from port */
143extern  READ8_HANDLER ( vic2_port_r );
152/*----------- defined in video/vic6567.c -----------*/
144153
145extern void vic2_lightpen_write (int level);
154WRITE8_DEVICE_HANDLER ( vic2_port_w );
155READ8_DEVICE_HANDLER ( vic2_port_r );
146156
147int vic2e_k0_r (void);
148int vic2e_k1_r (void);
149int vic2e_k2_r (void);
157int vic2e_k0_r(running_device *device);
158int vic2e_k1_r(running_device *device);
159int vic2e_k2_r(running_device *device);
150160
151/* to be called each vertical retrace */
152extern INTERRUPT_GEN( vic2_frame_interrupt );
161void vic2_raster_interrupt_gen( running_device *device );
162UINT32 vic2_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect );
153163
154/* private area */
155164
156/*extern UINT8 vic2[]; */
157/*extern int vic2_pal; */
165extern void vic2_set_rastering(running_device *device, int onoff);
166extern void vic2_lightpen_write(running_device *device, int level);
158167
159#endif /* VIC6567_H_ */
168
169
170#endif /* __VIC6567_H__ */
src/mess/includes/c65.h
r7364r7365
2323void c65_bankswitch (running_machine *machine);
2424void c65_colorram_write (int offset, int value);
2525
26int c65_dma_read(running_machine *machine, int offset);
27int c65_dma_read_color(running_machine *machine, int offset);
28void c65_vic_interrupt(running_machine *machine, int level);
29void c65_bankswitch_interface(running_machine *machine, int value);
30
2631DRIVER_INIT( c65 );
2732DRIVER_INIT( c65pal );
2833MACHINE_START( c65 );
src/mess/includes/cbmb.h
r7364r7365
5454READ8_DEVICE_HANDLER( cbmb_keyboard_line_c );
5555void cbmb_irq(running_device *device, int level);
5656
57int cbmb_dma_read(running_machine *machine, int offset);
58int cbmb_dma_read_color(running_machine *machine, int offset);
59
5760WRITE8_DEVICE_HANDLER( cbmb_change_font );
5861
5962DRIVER_INIT( p500 );
src/mess/includes/c128.h
r7364r7365
5757extern VIDEO_START( c128 );
5858extern VIDEO_UPDATE( c128 );
5959
60void c128_bankswitch_64 (running_machine *machine, int reset);
60void c128_bankswitch_64(running_machine *machine, int reset);
6161
62int c128_dma_read(running_machine *machine, int offset);
63int c128_dma_read_color(running_machine *machine, int offset);
64void c128_vic_interrupt(running_machine *machine, int level);
65
6266UINT8 c128_m6510_port_read(running_device *device, UINT8 direction);
6367void c128_m6510_port_write(running_device *device, UINT8 direction, UINT8 data);
6468
src/mess/messdriv.c
r7364r7365
494494   DRIVER( c64cpal )   /* Commodore 64C (PAL)     */
495495   DRIVER( c64g )     /* Commodore 64G (PAL)     */
496496   DRIVER( c64gs )    /* Commodore 64 Games System   */
497   DRIVER( c64dtv )    /* Commodore 64 Direct-to-TV   */
497498   DRIVER( clcd )     /* Commodore LCD   */
498499
499500   DRIVER( b500 )     /* Commodore B500      */
src/mess/machine/c65.c
r7364r7365
1414#include "sound/sid6581.h"
1515#include "machine/6526cia.h"
1616#include "machine/cbmiec.h"
17#include "devices/messram.h"
1718#include "video/vic4567.h"
18#include "devices/messram.h"
1919
2020#define VERBOSE_LEVEL 0
2121#define DBG_LOG( MACHINE, N, M, A ) \
r7364r7365
8686
8787static READ8_DEVICE_HANDLER( c65_cia0_port_b_r )
8888{
89    UINT8 value = 0xff;
89   UINT8 value = 0xff;
9090   UINT8 cia0porta = mos6526_pa_r(devtag_get_device(device->machine, "cia_0"), 0);
9191
9292   value &= cbm_common_cia0_port_b_r(device, cia0porta);
r7364r7365
9494   if (!(c65_6511_port & 0x02))
9595      value &= c65_keyline;
9696
97    return value;
97   return value;
9898}
9999
100100static WRITE8_DEVICE_HANDLER( c65_cia0_port_b_w )
101101{
102102//  was there lightpen support in c65 video chip?
103//  vic2_lightpen_write(data & 0x10);
103//  running_device *vic3 = devtag_get_device(device->machine, "vic3");
104//  vic3_lightpen_write(vic3, data & 0x10);
104105}
105106
106107static void c65_irq( running_machine *machine, int level )
r7364r7365
122123}
123124
124125/* is this correct for c65 as well as c64? */
125static void c65_vic_interrupt( running_machine *machine, int level )
126void c65_vic_interrupt( running_machine *machine, int level )
126127{
127128   running_device *cia_0 = devtag_get_device(machine, "cia_0");
128129#if 1
r7364r7365
693694{
694695   running_device *sid_0 = devtag_get_device(space->machine, "sid_r");
695696   running_device *sid_1 = devtag_get_device(space->machine, "sid_l");
697   running_device *vic3 = devtag_get_device(space->machine, "vic3");
696698
697699   switch (offset & 0xf00)
698700   {
699701   case 0x000:
700702      if (offset < 0x80)
701         vic3_port_w(space, offset & 0x7f, data);
703         vic3_port_w(vic3, offset & 0x7f, data);
702704      else if (offset < 0xa0)
703705         c65_fdc_w(space->machine, offset&0x1f,data);
704706      else
r7364r7365
710712   case 0x100:
711713   case 0x200:
712714   case 0x300:
713      vic3_palette_w(space, offset-0x100,data);
715      vic3_palette_w(vic3, offset - 0x100, data);
714716      break;
715717   case 0x400:
716718      if (offset<0x420) /* maybe 0x20 */
r7364r7365
756758{
757759   running_device *sid_0 = devtag_get_device(space->machine, "sid_r");
758760   running_device *sid_1 = devtag_get_device(space->machine, "sid_l");
761   running_device *vic3 = devtag_get_device(space->machine, "vic3");
759762
760763   switch (offset & 0xf00)
761764   {
762765   case 0x000:
763766      if (offset < 0x80)
764         return vic3_port_r(space, offset & 0x7f);
767         return vic3_port_r(vic3, offset & 0x7f);
765768      if (offset < 0xa0)
766769         return c65_fdc_r(space->machine, offset&0x1f);
767770      else
r7364r7365
824827/* bit 1 external sync enable (genlock)
825828   bit 2 palette enable
826829   bit 6 vic3 c65 character set */
827static void c65_bankswitch_interface( running_machine *machine, int value )
830void c65_bankswitch_interface( running_machine *machine, int value )
828831{
829832   static int old = 0;
830833
r7364r7365
975978 * a15 and a14 portlines
976979 * 0x1000-0x1fff, 0x9000-0x9fff char rom
977980 */
978static int c65_dma_read( running_machine *machine, int offset )
981int c65_dma_read( running_machine *machine, int offset )
979982{
980983   if (!c64_game && c64_exrom)
981984   {
r7364r7365
9981001   return c64_vicaddr[offset & 0x3fff];
9991002}
10001003
1001static int c65_dma_read_color( running_machine *machine, int offset )
1004int c65_dma_read_color( running_machine *machine, int offset )
10021005{
10031006   if (c64mode)
10041007      return c64_colorram[offset & 0x3ff] & 0xf;
r7364r7365
10221025   c64_tape_on = 0;
10231026
10241027   /*memset(c64_memory + 0x40000, 0, 0x800000 - 0x40000); */
1025
1026   vic4567_init(machine, c64_pal, c65_dma_read, c65_dma_read_color, c65_vic_interrupt, c65_bankswitch_interface);
10271028}
10281029
10291030DRIVER_INIT( c65 )
src/mess/machine/cbmb.c
r7364r7365
1111#include "machine/6526cia.h"
1212
1313#include "includes/cbm.h"
14#include "video/vic6567.h"
1514#include "machine/ieee488.h"
1615
1716#include "includes/cbmb.h"
r7364r7365
291290   cbmb_colorram[offset] = data | 0xf0;
292291}
293292
294static int cbmb_dma_read( running_machine *machine, int offset )
293int cbmb_dma_read( running_machine *machine, int offset )
295294{
296295   if (offset >= 0x1000)
297296      return cbmb_videoram[offset & 0x3ff];
r7364r7365
299298      return cbmb_chargen[offset & 0xfff];
300299}
301300
302static int cbmb_dma_read_color( running_machine *machine, int offset )
301int cbmb_dma_read_color( running_machine *machine, int offset )
303302{
304303   return cbmb_colorram[offset & 0x3ff];
305304}
r7364r7365
359358   cbmb_common_driver_init(machine);
360359   state->p500 = 1;
361360   state->cbm_ntsc = 1;
362   vic6567_init(0, 0, cbmb_dma_read, cbmb_dma_read_color, NULL);
363361}
364362
365363MACHINE_RESET( cbmb )
src/mess/machine/c128.c
r7364r7365
157157{
158158   UINT8 value = 0xff;
159159   UINT8 cia0porta = mos6526_pa_r(devtag_get_device(device->machine, "cia_0"), 0);
160   running_device *vic2e = devtag_get_device(device->machine, "vic2e");
160161
161162   value &= cbm_common_cia0_port_b_r(device, cia0porta);
162163
163   if (!vic2e_k0_r())
164   if (!vic2e_k0_r(vic2e))
164165      value &= c128_keyline[0];
165   if (!vic2e_k1_r())
166   if (!vic2e_k1_r(vic2e))
166167      value &= c128_keyline[1];
167   if (!vic2e_k2_r())
168   if (!vic2e_k2_r(vic2e))
168169      value &= c128_keyline[2];
169170
170171    return value;
r7364r7365
172173
173174static WRITE8_DEVICE_HANDLER( c128_cia0_port_b_w )
174175{
175    vic2_lightpen_write(data & 0x10);
176   running_device *vic2e = devtag_get_device(device->machine, "vic2e");
177   vic2_lightpen_write(vic2e, data & 0x10);
176178}
177179
178180static void c128_irq( running_machine *machine, int level )
r7364r7365
198200
199201static void c128_cia0_interrupt( running_device *device, int level )
200202{
201   c128_irq (device->machine, level || vicirq);
203   c128_irq(device->machine, level || vicirq);
202204}
203205
204static void c128_vic_interrupt( running_machine *machine, int level )
206void c128_vic_interrupt( running_machine *machine, int level )
205207{
206208   running_device *cia_0 = devtag_get_device(machine, "cia_0");
207209#if 1
r7364r7365
399401   running_device *cia_0 = devtag_get_device(space->machine, "cia_0");
400402   running_device *cia_1 = devtag_get_device(space->machine, "cia_1");
401403   running_device *sid = devtag_get_device(space->machine, "sid6581");
404   running_device *vic2e = devtag_get_device(space->machine, "vic2e");
402405
403406   UINT8 c64_port6510 = (UINT8) space->machine->device("maincpu")->get_runtime_int(CPUINFO_INT_M6510_PORT);
404407
r7364r7365
414417      switch ((offset&0xf00)>>8)
415418      {
416419      case 0:case 1: case 2: case 3:
417         vic2_port_w(space, offset & 0x3ff, data);
420         vic2_port_w(vic2e, offset & 0x3ff, data);
418421         break;
419422      case 4:
420423         sid6581_w(sid, offset & 0x3f, data);
r7364r7365
454457   running_device *cia_0 = devtag_get_device(space->machine, "cia_0");
455458   running_device *cia_1 = devtag_get_device(space->machine, "cia_1");
456459   running_device *sid = devtag_get_device(space->machine, "sid6581");
460   running_device *vic2e= devtag_get_device(space->machine, "vic2e");
457461
458462   if (offset < 0x400)
459      return vic2_port_r(space, offset & 0x3ff);
463      return vic2_port_r(vic2e, offset & 0x3ff);
460464   else if (offset < 0x500)
461465      return sid6581_r(sid, offset & 0xff);
462466   else if (offset < 0x600)
r7364r7365
10191023 * a15 and a14 portlines
10201024 * 0x1000-0x1fff, 0x9000-0x9fff char rom
10211025 */
1022static int c128_dma_read(running_machine *machine, int offset)
1026int c128_dma_read(running_machine *machine, int offset)
10231027{
10241028   UINT8 c64_port6510 = (UINT8) machine->device("maincpu")->get_runtime_int(CPUINFO_INT_M6510_PORT);
10251029
r7364r7365
10361040         return c64_chargen[offset & 0xfff];
10371041      return c64_vicaddr[offset];
10381042   }
1039   if (!(c64_port6510&4)
1040       && (((c128_vicaddr - c64_memory + offset) & 0x7000) == 0x1000))
1043   if (!(c64_port6510 & 4) && (((c128_vicaddr - c64_memory + offset) & 0x7000) == 0x1000))
10411044      return c128_chargen[offset & 0xfff];
10421045   return c128_vicaddr[offset];
10431046}
10441047
1045static int c128_dma_read_color(running_machine *machine, int offset)
1048int c128_dma_read_color(running_machine *machine, int offset)
10461049{
10471050   UINT8 c64_port6510 = (UINT8) machine->device("maincpu")->get_runtime_int(CPUINFO_INT_M6510_PORT);
10481051
10491052   if (c64mode)
10501053      return c64_colorram[offset & 0x3ff] & 0xf;
10511054   else
1052      return c64_colorram[(offset & 0x3ff)|((c64_port6510&0x3)<<10)] & 0xf;
1055      return c64_colorram[(offset & 0x3ff)|((c64_port6510 & 0x3) << 10)] & 0xf;
10531056}
10541057
10551058/* 2008-09-01
r7364r7365
11561159
11571160DRIVER_INIT( c128 )
11581161{
1162   running_device *vic2e = devtag_get_device(machine, "vic2e");
1163
11591164   c64_tape_on = 1;
11601165   c64_pal = 0;
11611166   c128_common_driver_init(machine);
1162   vic6567_init(1, c64_pal, c128_dma_read, c128_dma_read_color, c128_vic_interrupt);
1163   vic2_set_rastering(0);
1167   vic2_set_rastering(vic2e, 0);
11641168   vdc8563_init(0);
11651169   vdc8563_set_rastering(1);
11661170}
11671171
11681172DRIVER_INIT( c128pal )
11691173{
1174   running_device *vic2e = devtag_get_device(machine, "vic2e");
1175
11701176   c64_tape_on = 1;
11711177   c64_pal = 1;
11721178   c128_common_driver_init(machine);
1173   vic6567_init(1, c64_pal, c128_dma_read, c128_dma_read_color, c128_vic_interrupt);
1174   vic2_set_rastering(1);
1179   vic2_set_rastering(vic2e, 1);
11751180   vdc8563_init(0);
11761181   vdc8563_set_rastering(0);
11771182}
r7364r7365
12241229   static int monitor = -1;
12251230   static const char *const c128ports[] = { "KP0", "KP1", "KP2" };
12261231   int i, value;
1232   running_device *vic2e = devtag_get_device(device->machine, "vic2e");
12271233
12281234   c128_nmi(device->machine);
12291235
r7364r7365
12311237   {
12321238      if (input_port_read(device->machine, "SPECIAL") & 0x08)
12331239      {
1234         vic2_set_rastering(0);
1240         vic2_set_rastering(vic2e, 0);
12351241         vdc8563_set_rastering(1);
12361242         video_screen_set_visarea(device->machine->primary_screen, 0, 655, 0, 215);
12371243      }
12381244      else
12391245      {
1240         vic2_set_rastering(1);
1246         vic2_set_rastering(vic2e, 1);
12411247         vdc8563_set_rastering(0);
12421248         if (c64_pal)
12431249            video_screen_set_visarea(device->machine->primary_screen, 0, VIC6569_VISIBLECOLUMNS - 1, 0, VIC6569_VISIBLELINES - 1);
r7364r7365
12691275VIDEO_START( c128 )
12701276{
12711277   VIDEO_START_CALL(vdc8563);
1272   VIDEO_START_CALL(vic2);
12731278}
12741279
12751280VIDEO_UPDATE( c128 )
12761281{
1282   running_device *vic2e = devtag_get_device(screen->machine, "vic2e");
1283
12771284   VIDEO_UPDATE_CALL(vdc8563);
1278   VIDEO_UPDATE_CALL(vic2);
1285   vic2_video_update(vic2e, bitmap, cliprect);
12791286   return 0;
12801287}
src/mess/machine/c64.c
r7364r7365
2121#include "machine/6526cia.h"
2222#include "machine/cbmiec.h"
2323#include "video/vic6567.h"
24#include "video/vdc8563.h"
2524
2625#include "includes/cbm.h"
2726#include "includes/c64.h"
r7364r7365
116115
117116static WRITE8_DEVICE_HANDLER( c64_cia0_port_b_w )
118117{
119    vic2_lightpen_write(data & 0x10);
118   running_device *vic2 = devtag_get_device(device->machine, "vic2");
119   vic2_lightpen_write(vic2, data & 0x10);
120120}
121121
122122static void c64_irq( running_machine *machine, int level )
r7364r7365
142142#if 1
143143   if (level != vicirq)
144144   {
145      c64_irq (machine, level || mos6526_irq_r(cia_0));
145      c64_irq(machine, level || mos6526_irq_r(cia_0));
146146      vicirq = level;
147147   }
148148#endif
r7364r7365
268268   running_device *cia_0 = devtag_get_device(space->machine, "cia_0");
269269   running_device *cia_1 = devtag_get_device(space->machine, "cia_1");
270270   running_device *sid = devtag_get_device(space->machine, "sid6581");
271   running_device *vic2 = devtag_get_device(space->machine, "vic2");
271272
272273   c64_io_mirror[offset] = data;
273274   if (offset < 0x400)
274      vic2_port_w(space, offset & 0x3ff, data);
275      vic2_port_w(vic2, offset & 0x3ff, data);
275276   else if (offset < 0x800)
276277      sid6581_w(sid, offset & 0x3ff, data);
277278   else if (offset < 0xc00)
r7364r7365
304305   running_device *cia_0 = devtag_get_device(space->machine, "cia_0");
305306   running_device *cia_1 = devtag_get_device(space->machine, "cia_1");
306307   running_device *sid = devtag_get_device(space->machine, "sid6581");
308   running_device *vic2 = devtag_get_device(space->machine, "vic2");
307309
308310   if (offset < 0x400)
309      return vic2_port_r(space, offset & 0x3ff);
311      return vic2_port_r(vic2, offset & 0x3ff);
310312
311313   else if (offset < 0x800)
312314      return sid6581_r(sid, offset & 0x3ff);
r7364r7365
742744   c64_colorram[offset & 0x3ff] = data | 0xf0;
743745}
744746
745/*
746 * only 14 address lines
747 * a15 and a14 portlines
748 * 0x1000-0x1fff, 0x9000-0x9fff char rom
749 */
750static int c64_dma_read( running_machine *machine, int offset )
751{
752   if (!c64_game && c64_exrom)
753   {
754      if (offset < 0x3000)
755         return c64_memory[offset];
756
757      return c64_romh[offset & 0x1fff];
758   }
759
760   if (((c64_vicaddr - c64_memory + offset) & 0x7000) == 0x1000)
761      return c64_chargen[offset & 0xfff];
762
763   return c64_vicaddr[offset];
764}
765
766static int c64_dma_read_ultimax( running_machine *machine, int offset )
767{
768   if (offset < 0x3000)
769      return c64_memory[offset];
770
771   return c64_romh[offset & 0x1fff];
772}
773
774static int c64_dma_read_color( running_machine *machine, int offset )
775{
776   return c64_colorram[offset & 0x3ff] & 0xf;
777}
778
779747TIMER_CALLBACK( c64_tape_timer )
780748{
781749   double tmp = cassette_input(devtag_get_device(machine, "cassette"));
r7364r7365
800768   if (c64_tape_on)
801769      datasette_timer = timer_alloc(machine, c64_tape_timer, NULL);
802770
803   if (ultimax)
804      vic6567_init(0, c64_pal, c64_dma_read_ultimax, c64_dma_read_color, c64_vic_interrupt);
805   else
806      vic6567_init(0, c64_pal, c64_dma_read, c64_dma_read_color, c64_vic_interrupt);
807
808771   // "cyberload" tape loader check the e000-ffff ram; the init ram need to return different value
809772   {
810773      int i;
src/mess/mess.mak
r7364r7365
735735   $(MESS_MACHINE)/c128.o      \
736736   $(MESS_VIDEO)/vdc8563.o      \
737737   $(MESS_VIDEO)/vic6567.o      \
738   $(MESS_VIDEO)/vic4567.o      \
738739
739740$(MESSOBJ)/cccp.a:            \
740741   $(MESS_VIDEO)/lviv.o      \
src/mess/drivers/c65.c
r7364r7365
5858
5959#include "machine/cbmipt.h"
6060#include "video/vic4567.h"
61#include "video/vic6567.h"
6261
6362/* devices config */
6463#include "includes/cbm.h"
r7364r7365
8483   AM_RANGE(0x0dc00, 0x0dfff) AM_READ_BANK("bank8") AM_WRITE_BANK("bank9")
8584   AM_RANGE(0x0e000, 0x0ffff) AM_READ_BANK("bank10") AM_WRITE_BANK("bank15")
8685   AM_RANGE(0x10000, 0x1f7ff) AM_RAM
87   AM_RANGE(0x1f800, 0x1ffff) AM_RAM AM_BASE( &c64_colorram)
86   AM_RANGE(0x1f800, 0x1ffff) AM_RAM AM_BASE(&c64_colorram)
8887
8988   AM_RANGE(0x20000, 0x23fff) AM_ROM /* &c65_dos,     maps to 0x8000    */
9089   AM_RANGE(0x24000, 0x28fff) AM_ROM /* reserved */
91   AM_RANGE(0x29000, 0x29fff) AM_ROM AM_BASE( &c65_chargen)
92   AM_RANGE(0x2a000, 0x2bfff) AM_ROM AM_BASE( &c64_basic)
93   AM_RANGE(0x2c000, 0x2cfff) AM_ROM AM_BASE( &c65_interface)
94   AM_RANGE(0x2d000, 0x2dfff) AM_ROM AM_BASE( &c64_chargen)
95   AM_RANGE(0x2e000, 0x2ffff) AM_ROM AM_BASE( &c64_kernal)
90   AM_RANGE(0x29000, 0x29fff) AM_ROM AM_BASE(&c65_chargen)
91   AM_RANGE(0x2a000, 0x2bfff) AM_ROM AM_BASE(&c64_basic)
92   AM_RANGE(0x2c000, 0x2cfff) AM_ROM AM_BASE(&c65_interface)
93   AM_RANGE(0x2d000, 0x2dfff) AM_ROM AM_BASE(&c64_chargen)
94   AM_RANGE(0x2e000, 0x2ffff) AM_ROM AM_BASE(&c64_kernal)
9695
9796   AM_RANGE(0x30000, 0x31fff) AM_ROM /*&c65_monitor,     monitor maps to 0x6000    */
9897   AM_RANGE(0x32000, 0x37fff) AM_ROM /*&c65_basic, */
r7364r7365
177176 *
178177 *************************************/
179178
180
181179static PALETTE_INIT( c65 )
182180{
183181   int i;
184182
185   for ( i = 0; i < sizeof(vic3_palette) / 3; i++ ) {
186      palette_set_color_rgb(machine, i, vic3_palette[i*3], vic3_palette[i*3+1], vic3_palette[i*3+2]);
183   for ( i = 0; i < 0x100; i++ )
184   {
185      palette_set_color_rgb(machine, i, 0, 0, 0);
187186   }
188187}
189188
r7364r7365
194193 *
195194 *************************************/
196195
197
198196static const sid6581_interface c65_sound_interface =
199197{
200198   c64_paddle_read
r7364r7365
207205   { NULL}
208206};
209207
208
210209/*************************************
211210 *
211 *  VIC III interfaces
212 *
213 *************************************/
214
215static VIDEO_UPDATE( c65 )
216{
217   running_device *vic3 = devtag_get_device(screen->machine, "vic3");
218
219   vic3_video_update(vic3, bitmap, cliprect);
220   return 0;
221}
222
223static UINT8 c65_lightpen_x_cb( running_machine *machine )
224{
225   return input_port_read(machine, "LIGHTX") & ~0x01;
226}
227
228static UINT8 c65_lightpen_y_cb( running_machine *machine )
229{
230   return input_port_read(machine, "LIGHTY") & ~0x01;
231}
232
233static UINT8 c65_lightpen_button_cb( running_machine *machine )
234{
235   return input_port_read(machine, "OTHER") & 0x04;
236}
237
238static UINT8 c65_c64_mem_r( int offset )
239{
240   return c64_memory[offset];
241}
242
243static const vic3_interface c65_vic3_ntsc_intf = {
244   "screen",
245   "maincpu",
246   VIC4567_NTSC,
247   c65_lightpen_x_cb,
248   c65_lightpen_y_cb,
249   c65_lightpen_button_cb,
250   c65_dma_read,
251   c65_dma_read_color,
252   c65_vic_interrupt,
253   c65_bankswitch_interface,
254   c65_c64_mem_r
255};
256
257static const vic3_interface c65_vic3_pal_intf = {
258   "screen",
259   "maincpu",
260   VIC4567_PAL,
261   c65_lightpen_x_cb,
262   c65_lightpen_y_cb,
263   c65_lightpen_button_cb,
264   c65_dma_read,
265   c65_dma_read_color,
266   c65_vic_interrupt,
267   c65_bankswitch_interface,
268   c65_c64_mem_r
269};
270
271static INTERRUPT_GEN( vic3_raster_irq )
272{
273   running_device *vic3 = devtag_get_device(device->machine, "vic3");
274
275   vic3_raster_interrupt_gen(vic3);
276}
277
278/*************************************
279 *
212280 *  Machine driver
213281 *
214282 *************************************/
215283
216
217284static MACHINE_DRIVER_START( c65 )
218285   /* basic machine hardware */
219286   MDRV_CPU_ADD("maincpu", M4510, 3500000)  /* or VIC6567_CLOCK, */
r7364r7365
224291   MDRV_MACHINE_START( c65 )
225292
226293   /* video hardware */
227   MDRV_IMPORT_FROM( vh_vic2 )
228   MDRV_SCREEN_MODIFY("screen")
294   MDRV_SCREEN_ADD("screen", RASTER)
295   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
229296   MDRV_SCREEN_REFRESH_RATE(VIC6567_VRETRACERATE)
230297   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
231298   MDRV_SCREEN_SIZE(525 * 2, 520 * 2)
232299   MDRV_SCREEN_VISIBLE_AREA(VIC6567_STARTVISIBLECOLUMNS ,(VIC6567_STARTVISIBLECOLUMNS + VIC6567_VISIBLECOLUMNS - 1) * 2, VIC6567_STARTVISIBLELINES, VIC6567_STARTVISIBLELINES + VIC6567_VISIBLELINES - 1)
233   MDRV_PALETTE_LENGTH(ARRAY_LENGTH(vic3_palette) / 3)
300
301   MDRV_PALETTE_LENGTH(0x100)
234302   MDRV_PALETTE_INIT( c65 )
235303
304   MDRV_VIDEO_UPDATE( c65 )
305
306   MDRV_VIC3_ADD("vic3", c65_vic3_ntsc_intf)
307
236308   /* sound hardware */
237309   MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
238310   MDRV_SOUND_ADD("sid_r", SID8580, 985248)
r7364r7365
266338   MDRV_SCREEN_SIZE(625 * 2, 520 * 2)
267339   MDRV_SCREEN_VISIBLE_AREA(VIC6569_STARTVISIBLECOLUMNS, (VIC6569_STARTVISIBLECOLUMNS + VIC6569_VISIBLECOLUMNS - 1) * 2, VIC6569_STARTVISIBLELINES, VIC6569_STARTVISIBLELINES + VIC6569_VISIBLELINES - 1)
268340
341   MDRV_DEVICE_REMOVE("vic3")
342   MDRV_VIC3_ADD("vic3", c65_vic3_pal_intf)
343
269344   /* sound hardware */
270345   MDRV_SOUND_REPLACE("sid_r", SID8580, 1022727)
271346   MDRV_SOUND_CONFIG(c65_sound_interface)
r7364r7365
281356MACHINE_DRIVER_END
282357
283358
284
285359/*************************************
286360 *
287361 *  ROM definition(s)
src/mess/drivers/cbmb.c
r7364r7365
162162   AM_RANGE(0xf8000, 0xfbfff) AM_ROM AM_BASE(&cbmb_basic)
163163   AM_RANGE(0xfd000, 0xfd3ff) AM_RAM AM_BASE(&cbmb_videoram)      /* videoram */
164164   AM_RANGE(0xfd400, 0xfd7ff) AM_RAM_WRITE(cbmb_colorram_w) AM_BASE(&cbmb_colorram)      /* colorram */
165   AM_RANGE(0xfd800, 0xfd8ff) AM_READWRITE(vic2_port_r, vic2_port_w)
165   AM_RANGE(0xfd800, 0xfd8ff) AM_DEVREADWRITE("vic6567", vic2_port_r, vic2_port_w)
166166   /* disk units */
167167   AM_RANGE(0xfda00, 0xfdaff) AM_DEVREADWRITE("sid6581", sid6581_r, sid6581_w)
168168   /* db00 coprocessor */
r7364r7365
311311   NULL
312312};
313313
314/* p500 uses a VIC II chip */
314315
316static const unsigned char p500_palette[] =
317{
318/* black, white, red, cyan */
319/* purple, green, blue, yellow */
320/* orange, brown, light red, dark gray, */
321/* medium gray, light green, light blue, light gray */
322/* taken from the vice emulator */
323   0x00, 0x00, 0x00,  0xfd, 0xfe, 0xfc,  0xbe, 0x1a, 0x24,  0x30, 0xe6, 0xc6,
324   0xb4, 0x1a, 0xe2,  0x1f, 0xd2, 0x1e,  0x21, 0x1b, 0xae,  0xdf, 0xf6, 0x0a,
325   0xb8, 0x41, 0x04,  0x6a, 0x33, 0x04,  0xfe, 0x4a, 0x57,  0x42, 0x45, 0x40,
326   0x70, 0x74, 0x6f,  0x59, 0xfe, 0x59,  0x5f, 0x53, 0xfe,  0xa4, 0xa7, 0xa2
327};
328
329static PALETTE_INIT( p500 )
330{
331   int i;
332
333   for (i = 0; i < sizeof(p500_palette) / 3; i++)
334   {
335      palette_set_color_rgb(machine, i, p500_palette[i * 3], p500_palette[i * 3 + 1], p500_palette[i * 3 + 2]);
336   }
337}
338
339static VIDEO_UPDATE( p500 )
340{
341   running_device *vic2 = devtag_get_device(screen->machine, "vic6567");
342
343   vic2_video_update(vic2, bitmap, cliprect);
344   return 0;
345}
346
347static UINT8 cbmb_lightpen_x_cb( running_machine *machine )
348{
349   return input_port_read(machine, "LIGHTX") & ~0x01;
350}
351
352static UINT8 cbmb_lightpen_y_cb( running_machine *machine )
353{
354   return input_port_read(machine, "LIGHTY") & ~0x01;
355}
356
357static UINT8 cbmb_lightpen_button_cb( running_machine *machine )
358{
359   return input_port_read(machine, "OTHER") & 0x04;
360}
361
362static UINT8 cbmb_rdy_cb( running_machine *machine )
363{
364   return input_port_read(machine, "CTRLSEL") & 0x08;
365}
366
367
368static const vic2_interface p500_vic2_intf = {
369   "screen",
370   "maincpu",
371   VIC6567,
372   cbmb_lightpen_x_cb,
373   cbmb_lightpen_y_cb,
374   cbmb_lightpen_button_cb,
375   cbmb_dma_read,
376   cbmb_dma_read_color,
377   NULL,
378   cbmb_rdy_cb
379};
380
315381/*************************************
316382 *
317383 *  Machine driver
r7364r7365
444510   MDRV_MACHINE_RESET( cbmb )
445511
446512   /* video hardware */
447   MDRV_IMPORT_FROM( vh_vic2 )
448   MDRV_SCREEN_MODIFY("screen")
513   MDRV_SCREEN_ADD("screen", RASTER)
514   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
515   MDRV_SCREEN_SIZE(VIC6567_COLUMNS, VIC6567_LINES)
516   MDRV_SCREEN_VISIBLE_AREA(0, VIC6567_VISIBLECOLUMNS - 1, 0, VIC6567_VISIBLELINES - 1)
449517   MDRV_SCREEN_REFRESH_RATE(VIC6567_VRETRACERATE)
450518   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
451519
520   MDRV_PALETTE_INIT( p500 )
521   MDRV_PALETTE_LENGTH(ARRAY_LENGTH(p500_palette) / 3)
522
523   MDRV_VIDEO_UPDATE( p500 )
524
525   MDRV_VIC2_ADD("vic6567", p500_vic2_intf)
526
452527   /* sound hardware */
453528   MDRV_SPEAKER_STANDARD_MONO("mono")
454529   MDRV_SOUND_ADD("sid6581", SID6581, 1000000)
src/mess/drivers/c128.c
r7364r7365
252252
253253static ADDRESS_MAP_START( c128_z80_io , ADDRESS_SPACE_IO, 8)
254254   AM_RANGE(0x1000, 0x13ff) AM_READWRITE(c64_colorram_read, c64_colorram_write)
255   AM_RANGE(0xd000, 0xd3ff) AM_READWRITE(vic2_port_r, vic2_port_w)
255   AM_RANGE(0xd000, 0xd3ff) AM_DEVREADWRITE("vic2e", vic2_port_r, vic2_port_w)
256256   AM_RANGE(0xd400, 0xd4ff) AM_DEVREADWRITE("sid6581", sid6581_r, sid6581_w)
257257   AM_RANGE(0xd500, 0xd5ff) AM_READWRITE(c128_mmu8722_port_r, c128_mmu8722_port_w)
258258   AM_RANGE(0xd600, 0xd7ff) AM_READWRITE(vdc8563_port_r, vdc8563_port_w)
r7364r7365
509509 *
510510 *************************************/
511511
512static const unsigned char vic2_palette[] =
513{
514/* black, white, red, cyan */
515/* purple, green, blue, yellow */
516/* orange, brown, light red, dark gray, */
517/* medium gray, light green, light blue, light gray */
518/* taken from the vice emulator */
519   0x00, 0x00, 0x00,  0xfd, 0xfe, 0xfc,  0xbe, 0x1a, 0x24,  0x30, 0xe6, 0xc6,
520   0xb4, 0x1a, 0xe2,  0x1f, 0xd2, 0x1e,  0x21, 0x1b, 0xae,  0xdf, 0xf6, 0x0a,
521   0xb8, 0x41, 0x04,  0x6a, 0x33, 0x04,  0xfe, 0x4a, 0x57,  0x42, 0x45, 0x40,
522   0x70, 0x74, 0x6f,  0x59, 0xfe, 0x59,  0x5f, 0x53, 0xfe,  0xa4, 0xa7, 0xa2
523};
512524
513525static PALETTE_INIT( c128 )
514526{
515527   int i;
516528
517   for ( i = 0; i < sizeof(vic2_palette) / 3; i++ ) {
518      palette_set_color_rgb(machine, i, vic2_palette[i*3], vic2_palette[i*3+1], vic2_palette[i*3+2]);
529   for (i = 0; i < sizeof(vic2_palette) / 3; i++)
530   {
531      palette_set_color_rgb(machine, i, vic2_palette[i * 3], vic2_palette[i * 3 + 1], vic2_palette[i * 3 + 2]);
519532   }
520533
521   for ( i = 0; i < sizeof(vdc8563_palette) / 3; i++ ) {
522      palette_set_color_rgb(machine, i + sizeof(vic2_palette) / 3, vdc8563_palette[i*3], vdc8563_palette[i*3+1], vdc8563_palette[i*3+2]);
534   for (i = 0; i < sizeof(vdc8563_palette) / 3; i++)
535   {
536      palette_set_color_rgb(machine, i + sizeof(vic2_palette) / 3, vdc8563_palette[i * 3], vdc8563_palette[i * 3 + 1], vdc8563_palette[i * 3 + 2]);
523537   }
524538}
525539
r7364r7365
597611
598612/*************************************
599613 *
614 *  VIC II interfaces
615 *
616 *************************************/
617
618static UINT8 c128_lightpen_x_cb( running_machine *machine )
619{
620   return input_port_read(machine, "LIGHTX") & ~0x01;
621}
622
623static UINT8 c128_lightpen_y_cb( running_machine *machine )
624{
625   return input_port_read(machine, "LIGHTY") & ~0x01;
626}
627
628static UINT8 c128_lightpen_button_cb( running_machine *machine )
629{
630   return input_port_read(machine, "OTHER") & 0x04;
631}
632
633static UINT8 c128_rdy_cb( running_machine *machine )
634{
635   return input_port_read(machine, "CTRLSEL") & 0x08;
636}
637
638static const vic2_interface c128_vic2_ntsc_intf = {
639   "screen",
640   "maincpu",
641   VIC8564,
642   c128_lightpen_x_cb,
643   c128_lightpen_y_cb,
644   c128_lightpen_button_cb,
645   c128_dma_read,
646   c128_dma_read_color,
647   c128_vic_interrupt,
648   c128_rdy_cb
649};
650
651static const vic2_interface c128_vic2_pal_intf = {
652   "screen",
653   "maincpu",
654   VIC8566,
655   c128_lightpen_x_cb,
656   c128_lightpen_y_cb,
657   c128_lightpen_button_cb,
658   c128_dma_read,
659   c128_dma_read_color,
660   c128_vic_interrupt,
661   c128_rdy_cb
662};
663
664/*************************************
665
666 *
600667 *  Machine driver
601668 *
602669 *************************************/
r7364r7365
618685   MDRV_MACHINE_START( c128 )
619686   MDRV_MACHINE_RESET( c128 )
620687
621    /* video hardware */
688   /* video hardware */
622689   MDRV_SCREEN_ADD("screen", RASTER)
623690   MDRV_SCREEN_REFRESH_RATE(VIC6567_VRETRACERATE)
624691   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
r7364r7365
633700   MDRV_VIDEO_START( c128 )
634701   MDRV_VIDEO_UPDATE( c128 )
635702
703   MDRV_VIC2_ADD("vic2e", c128_vic2_ntsc_intf)
704
636705   /* sound hardware */
637706   MDRV_SPEAKER_STANDARD_MONO("mono")
638707   MDRV_SOUND_ADD("sid6581", SID6581, VIC6567_CLOCK)
r7364r7365
691760   MDRV_SCREEN_SIZE(VIC6569_COLUMNS * 2, VIC6569_LINES)
692761   MDRV_SCREEN_VISIBLE_AREA(0, VIC6569_VISIBLECOLUMNS - 1, 0, VIC6569_VISIBLELINES - 1)
693762
763   MDRV_DEVICE_REMOVE("vic2e")
764   MDRV_VIC2_ADD("vic2e", c128_vic2_pal_intf)
765
694766   /* sound hardware */
695767   MDRV_SOUND_REPLACE("sid6581", SID6581, VIC6569_CLOCK)
696768   MDRV_SOUND_CONFIG(c128_sound_interface)
src/mess/drivers/c64.c
r7364r7365
320320- What's the difference between Educator 64-1 and Educator 64-2? My guess
321321is that Edu64-1 was a standard PET64/CBMB4064 with a different name, while
322322the Edu64-1 used the full C64 BIOS. Confirmations are needed, anyway.
323
324
325
326C64DTV TODO:
327  - basically everything! it needs proper bankswitch and specific hardware bits!
323328 */
324329
325330#include "emu.h"
r7364r7365
395400static ADDRESS_MAP_START(ultimax_mem , ADDRESS_SPACE_PROGRAM, 8)
396401   AM_RANGE(0x0000, 0x0fff) AM_RAM AM_BASE(&c64_memory)
397402   AM_RANGE(0x8000, 0x9fff) AM_ROM AM_BASE(&c64_roml)
398   AM_RANGE(0xd000, 0xd3ff) AM_READWRITE(vic2_port_r, vic2_port_w)
403   AM_RANGE(0xd000, 0xd3ff) AM_DEVREADWRITE("vic2", vic2_port_r, vic2_port_w)
399404   AM_RANGE(0xd400, 0xd7ff) AM_DEVREADWRITE("sid6581", sid6581_r, sid6581_w)
400405   AM_RANGE(0xd800, 0xdbff) AM_RAM_WRITE( c64_colorram_write) AM_BASE(&c64_colorram) /* colorram  */
401406   AM_RANGE(0xdc00, 0xdcff) AM_DEVREADWRITE("cia_0", mos6526_r, mos6526_w)
r7364r7365
494499 *
495500 *************************************/
496501
502static const unsigned char c64_palette[] =
503{
504/* black, white, red, cyan */
505/* purple, green, blue, yellow */
506/* orange, brown, light red, dark gray, */
507/* medium gray, light green, light blue, light gray */
508/* taken from the vice emulator */
509   0x00, 0x00, 0x00,  0xfd, 0xfe, 0xfc,  0xbe, 0x1a, 0x24,  0x30, 0xe6, 0xc6,
510   0xb4, 0x1a, 0xe2,  0x1f, 0xd2, 0x1e,  0x21, 0x1b, 0xae,  0xdf, 0xf6, 0x0a,
511   0xb8, 0x41, 0x04,  0x6a, 0x33, 0x04,  0xfe, 0x4a, 0x57,  0x42, 0x45, 0x40,
512   0x70, 0x74, 0x6f,  0x59, 0xfe, 0x59,  0x5f, 0x53, 0xfe,  0xa4, 0xa7, 0xa2
513};
497514
515static PALETTE_INIT( c64 )
516{
517   int i;
518
519   for (i = 0; i < sizeof(c64_palette) / 3; i++)
520   {
521      palette_set_color_rgb(machine, i, c64_palette[i * 3], c64_palette[i * 3 + 1], c64_palette[i * 3 + 2]);
522   }
523}
524
498525static PALETTE_INIT( pet64 )
499526{
500527   int i;
501528   for (i = 0; i < 16; i++)
502      palette_set_color_rgb(machine, i, 0, vic2_palette[i * 3 + 1], 0);
529      palette_set_color_rgb(machine, i, 0, c64_palette[i * 3 + 1], 0);
503530}
504531
505532
r7364r7365
531558   { NULL}
532559};
533560
561
534562/*************************************
535563 *
564 *  VIC II interfaces
565 *
566 *************************************/
567
568static VIDEO_UPDATE( c64 )
569{
570   running_device *vic2 = devtag_get_device(screen->machine, "vic2");
571
572   vic2_video_update(vic2, bitmap, cliprect);
573   return 0;
574}
575
576static UINT8 c64_lightpen_x_cb( running_machine *machine )
577{
578   return input_port_read(machine, "LIGHTX") & ~0x01;
579}
580
581static UINT8 c64_lightpen_y_cb( running_machine *machine )
582{
583   return input_port_read(machine, "LIGHTY") & ~0x01;
584}
585
586static UINT8 c64_lightpen_button_cb( running_machine *machine )
587{
588   return input_port_read(machine, "OTHER") & 0x04;
589}
590
591static int c64_dma_read( running_machine *machine, int offset )
592{
593   if (!c64_game && c64_exrom)
594   {
595      if (offset < 0x3000)
596         return c64_memory[offset];
597
598      return c64_romh[offset & 0x1fff];
599   }
600
601   if (((c64_vicaddr - c64_memory + offset) & 0x7000) == 0x1000)
602      return c64_chargen[offset & 0xfff];
603
604   return c64_vicaddr[offset];
605}
606
607static int c64_dma_read_ultimax( running_machine *machine, int offset )
608{
609   if (offset < 0x3000)
610      return c64_memory[offset];
611
612   return c64_romh[offset & 0x1fff];
613}
614
615static int c64_dma_read_color( running_machine *machine, int offset )
616{
617   return c64_colorram[offset & 0x3ff] & 0xf;
618}
619
620static UINT8 c64_rdy_cb( running_machine *machine )
621{
622   return input_port_read(machine, "CTRLSEL") & 0x08;
623}
624
625static const vic2_interface c64_vic2_ntsc_intf = {
626   "screen",
627   "maincpu",
628   VIC6567,
629   c64_lightpen_x_cb,
630   c64_lightpen_y_cb,
631   c64_lightpen_button_cb,
632   c64_dma_read,
633   c64_dma_read_color,
634   c64_vic_interrupt,
635   c64_rdy_cb
636};
637
638static const vic2_interface c64_vic2_pal_intf = {
639   "screen",
640   "maincpu",
641   VIC6569,
642   c64_lightpen_x_cb,
643   c64_lightpen_y_cb,
644   c64_lightpen_button_cb,
645   c64_dma_read,
646   c64_dma_read_color,
647   c64_vic_interrupt,
648   c64_rdy_cb
649};
650
651static const vic2_interface ultimax_vic2_intf = {
652   "screen",
653   "maincpu",
654   VIC6567,
655   c64_lightpen_x_cb,
656   c64_lightpen_y_cb,
657   c64_lightpen_button_cb,
658   c64_dma_read_ultimax,
659   c64_dma_read_color,
660   c64_vic_interrupt,
661   c64_rdy_cb
662};
663
664
665/*************************************
666 *
536667 *  Machine driver
537668 *
538669 *************************************/
r7364r7365
550681   MDRV_MACHINE_RESET( c64 )
551682
552683   /* video hardware */
553   MDRV_IMPORT_FROM( vh_vic2 )
554   MDRV_SCREEN_MODIFY("screen")
684   MDRV_SCREEN_ADD("screen", RASTER)
555685   MDRV_SCREEN_REFRESH_RATE(VIC6567_VRETRACERATE)
556686   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) /* not accurate */
687   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
688   MDRV_SCREEN_SIZE(VIC6567_COLUMNS, VIC6567_LINES)
689   MDRV_SCREEN_VISIBLE_AREA(0, VIC6567_VISIBLECOLUMNS - 1, 0, VIC6567_VISIBLELINES - 1)
557690
691   MDRV_PALETTE_INIT( c64 )
692   MDRV_PALETTE_LENGTH(ARRAY_LENGTH(c64_palette) / 3)
693
694   MDRV_VIDEO_UPDATE( c64 )
695
696   MDRV_VIC2_ADD("vic2", c64_vic2_ntsc_intf)
697
558698   /* sound hardware */
559699   MDRV_SPEAKER_STANDARD_MONO("mono")
560700   MDRV_SOUND_ADD("sid6581", SID6581, VIC6567_CLOCK)
r7364r7365
592732   MDRV_MACHINE_RESET( c64 )
593733
594734   /* video hardware */
595   MDRV_IMPORT_FROM( vh_vic2_pal )
596   MDRV_SCREEN_MODIFY("screen")
735   MDRV_SCREEN_ADD("screen", RASTER)
597736   MDRV_SCREEN_REFRESH_RATE(VIC6569_VRETRACERATE)
598737   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) /* 2500 not accurate */
738   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
739   MDRV_SCREEN_SIZE(VIC6569_COLUMNS, VIC6569_LINES)
740   MDRV_SCREEN_VISIBLE_AREA(0, VIC6569_VISIBLECOLUMNS - 1, 0, VIC6569_VISIBLELINES - 1)
599741
742   MDRV_PALETTE_INIT( c64 )
743   MDRV_PALETTE_LENGTH(ARRAY_LENGTH(c64_palette) / 3)
744
745   MDRV_VIDEO_UPDATE( c64 )
746
747   MDRV_VIC2_ADD("vic2", c64_vic2_pal_intf)
748
600749   /* sound hardware */
601750   MDRV_SPEAKER_STANDARD_MONO("mono")
602751   MDRV_SOUND_ADD("sid6581", SID6581, VIC6569_CLOCK)
r7364r7365
632781   MDRV_SOUND_CONFIG(c64_sound_interface)
633782   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
634783
784   MDRV_DEVICE_REMOVE("vic2")
785   MDRV_VIC2_ADD("vic2", ultimax_vic2_intf)
786
635787   MDRV_DEVICE_REMOVE("iec")
636788   MDRV_DEVICE_REMOVE("c1541")
637789   MDRV_DEVICE_REMOVE("cart1")
r7364r7365
788940   ROM_REGION( 0x80000, "cart", ROMREGION_ERASE00 )
789941ROM_END
790942
943
944// BASIC sits at 0xa000-0xc000, chargen-like chunks sit at 0x1000-0x2000, 0x9000-0xa000 and 0xd000-0xe000
945// kernel sits at 0xe000
946// from 0x10000 on there are the games
947ROM_START( c64dtv )
948   ROM_REGION( 0x220000, "maincpu", 0 )
949   ROM_LOAD( "flash.u2", 0x020000, 0x200000, CRC(b820375a) SHA1(b9f88919e2bed825eb2b2cb605977d55971b423b) )
950   // the code below is just for testing purpose... we should implement properly the rom banking!
951   ROM_COPY("maincpu", 0x2a000, 0x10000, 0x2000)
952   ROM_COPY("maincpu", 0x2e000, 0x12000, 0x2000)
953   ROM_COPY("maincpu", 0x2d000, 0x14000, 0x1000)
954ROM_END
955
956
791957/***************************************************************************
792958
793959  Game driver(s)
r7364r7365
796962
797963/*   YEAR  NAME   PARENT COMPAT MACHINE  INPUT    INIT     COMPANY                            FULLNAME */
798964
799COMP(1982, max,       0,    0,    ultimax, c64,     ultimax, "Commodore Business Machines Co.", "Commodore Max Machine", 0)
965COMP(1982, max,     0,    0,    ultimax, c64,     ultimax, "Commodore Business Machines Co.", "Commodore Max Machine", 0)
800966
801967COMP(1982, c64,     0,    0,    c64,     c64,     c64,     "Commodore Business Machines Co.", "Commodore 64 (NTSC)", 0)
802968COMP(1982, c64pal,  c64,  0,    c64pal,  c64,     c64pal,  "Commodore Business Machines Co.", "Commodore 64 (PAL)",  0)
r7364r7365
804970COMP(1982, vic64s,  c64,  0,    c64pal,  vic64s,  c64pal,  "Commodore Business Machines Co.", "VIC 64S", 0)
805971COMP(1982, c64swe,  c64,  0,    c64pal,  vic64s,  c64pal,  "Commodore Business Machines Co.", "Commodore 64 (Sweden/Finland)", 0)
806972
807COMP(1983, pet64,   c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines Co.", "PET 64 (NTSC)", 0)
973COMP(1983, pet64,     c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines Co.", "PET 64 (NTSC)", 0)
808974COMP(1983, cbm4064, c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines Co.", "CBM 4064 (NTSC)", 0)
809975COMP(1983, edu64,   c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines Co.", "Educator 64 (NTSC)", 0) // maybe different palette?
810976
r7364r7365
817983COMP(1986, c64g,    c64,  0,    c64pal,  c64,     c64pal,  "Commodore Business Machines Co.", "Commodore 64G (PAL)", 0)
818984
819985CONS(1990, c64gs,   c64,  0,    c64gs,   c64gs,   c64gs,   "Commodore Business Machines Co.", "Commodore 64 Games System (PAL)", 0)
986
987CONS(2005, c64dtv,  c64,  0,    c64,     c64,     c64,     "The Toy:Lobster Company", "Commodore 64 Direct-to-TV (Version 2 050711)", GAME_NOT_WORKING)
docs/messnew.txt
r7364r7365
1212- MK-88 [Miodrag Milanovic]
1313- Poisk-1, Poisk-2 [Miodrag Milanovic]
1414- PK8020 Neiva, PK8020 Kontur [Miodrag Milanovic]
15- C64 Direct-to-TV (not working) [Guru, Fabio Priuli]
1516
1617
1718

Previous 15994 Revisions Next


© 1998-2018 The MESS Team