18
18
VIDEO_START( ccastles )
20
ccastles_state *state = machine->driver_data<ccastles_state>();
20
ccastles_state *state = machine.driver_data<ccastles_state>();
21
21
static const int resistances[3] = { 22000, 10000, 4700 };
23
23
/* get pointers to our PROMs */
24
state->syncprom = machine->region("proms")->base() + 0x000;
25
state->wpprom = machine->region("proms")->base() + 0x200;
26
state->priprom = machine->region("proms")->base() + 0x300;
24
state->m_syncprom = machine.region("proms")->base() + 0x000;
25
state->m_wpprom = machine.region("proms")->base() + 0x200;
26
state->m_priprom = machine.region("proms")->base() + 0x300;
28
28
/* compute the color output resistor weights at startup */
29
29
compute_resistor_weights(0, 255, -1.0,
30
3, resistances, state->rweights, 1000, 0,
31
3, resistances, state->gweights, 1000, 0,
32
3, resistances, state->bweights, 1000, 0);
30
3, resistances, state->m_rweights, 1000, 0,
31
3, resistances, state->m_gweights, 1000, 0,
32
3, resistances, state->m_bweights, 1000, 0);
34
34
/* allocate a bitmap for drawing sprites */
35
state->spritebitmap = machine->primary_screen->alloc_compatible_bitmap();
35
state->m_spritebitmap = machine.primary_screen->alloc_compatible_bitmap();
37
37
/* register for savestates */
38
state_save_register_global_array(machine, state->video_control);
39
state_save_register_global_array(machine, state->bitmode_addr);
40
state_save_register_global(machine, state->hscroll);
41
state_save_register_global(machine, state->vscroll);
38
state->save_item(NAME(state->m_video_control));
39
state->save_item(NAME(state->m_bitmode_addr));
40
state->save_item(NAME(state->m_hscroll));
41
state->save_item(NAME(state->m_vscroll));
52
52
WRITE8_HANDLER( ccastles_hscroll_w )
54
ccastles_state *state = space->machine->driver_data<ccastles_state>();
55
space->machine->primary_screen->update_partial(space->machine->primary_screen->vpos());
56
state->hscroll = data;
54
ccastles_state *state = space->machine().driver_data<ccastles_state>();
55
space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos());
56
state->m_hscroll = data;
60
60
WRITE8_HANDLER( ccastles_vscroll_w )
62
ccastles_state *state = space->machine->driver_data<ccastles_state>();
63
state->vscroll = data;
62
ccastles_state *state = space->machine().driver_data<ccastles_state>();
63
state->m_vscroll = data;
67
67
WRITE8_HANDLER( ccastles_video_control_w )
69
ccastles_state *state = space->machine->driver_data<ccastles_state>();
69
ccastles_state *state = space->machine().driver_data<ccastles_state>();
70
70
/* only D3 matters */
71
state->video_control[offset] = (data >> 3) & 1;
71
state->m_video_control[offset] = (data >> 3) & 1;
94
94
bit0 = (~r >> 0) & 0x01;
95
95
bit1 = (~r >> 1) & 0x01;
96
96
bit2 = (~r >> 2) & 0x01;
97
r = combine_3_weights(state->rweights, bit0, bit1, bit2);
97
r = combine_3_weights(state->m_rweights, bit0, bit1, bit2);
99
99
/* green component (inverted) */
100
100
bit0 = (~g >> 0) & 0x01;
101
101
bit1 = (~g >> 1) & 0x01;
102
102
bit2 = (~g >> 2) & 0x01;
103
g = combine_3_weights(state->gweights, bit0, bit1, bit2);
103
g = combine_3_weights(state->m_gweights, bit0, bit1, bit2);
105
105
/* blue component (inverted) */
106
106
bit0 = (~b >> 0) & 0x01;
107
107
bit1 = (~b >> 1) & 0x01;
108
108
bit2 = (~b >> 2) & 0x01;
109
b = combine_3_weights(state->bweights, bit0, bit1, bit2);
109
b = combine_3_weights(state->m_bweights, bit0, bit1, bit2);
111
palette_set_color(space->machine, offset & 0x1f, MAKE_RGB(r, g, b));
111
palette_set_color(space->machine(), offset & 0x1f, MAKE_RGB(r, g, b));
121
121
*************************************/
123
INLINE void ccastles_write_vram( running_machine *machine, UINT16 addr, UINT8 data, UINT8 bitmd, UINT8 pixba )
123
INLINE void ccastles_write_vram( running_machine &machine, UINT16 addr, UINT8 data, UINT8 bitmd, UINT8 pixba )
125
ccastles_state *state = machine->driver_data<ccastles_state>();
126
UINT8 *dest = &state->videoram[addr & 0x7ffe];
125
ccastles_state *state = machine.driver_data<ccastles_state>();
126
UINT8 *dest = &state->m_videoram[addr & 0x7ffe];
127
127
UINT8 promaddr = 0;
168
168
*************************************/
170
INLINE void bitmode_autoinc( running_machine *machine )
170
INLINE void bitmode_autoinc( running_machine &machine )
172
ccastles_state *state = machine->driver_data<ccastles_state>();
172
ccastles_state *state = machine.driver_data<ccastles_state>();
174
174
/* auto increment in the x-direction if it's enabled */
175
if (!state->video_control[0]) /* /AX */
175
if (!state->m_video_control[0]) /* /AX */
177
if (!state->video_control[2]) /* /XINC */
178
state->bitmode_addr[0]++;
177
if (!state->m_video_control[2]) /* /XINC */
178
state->m_bitmode_addr[0]++;
180
state->bitmode_addr[0]--;
180
state->m_bitmode_addr[0]--;
183
183
/* auto increment in the y-direction if it's enabled */
184
if (!state->video_control[1]) /* /AY */
184
if (!state->m_video_control[1]) /* /AY */
186
if (!state->video_control[3]) /* /YINC */
187
state->bitmode_addr[1]++;
186
if (!state->m_video_control[3]) /* /YINC */
187
state->m_bitmode_addr[1]++;
189
state->bitmode_addr[1]--;
189
state->m_bitmode_addr[1]--;
201
201
WRITE8_HANDLER( ccastles_videoram_w )
203
203
/* direct writes to VRAM go through the write protect PROM as well */
204
ccastles_write_vram(space->machine, offset, data, 0, 0);
204
ccastles_write_vram(space->machine(), offset, data, 0, 0);
215
215
READ8_HANDLER( ccastles_bitmode_r )
217
ccastles_state *state = space->machine->driver_data<ccastles_state>();
217
ccastles_state *state = space->machine().driver_data<ccastles_state>();
219
219
/* in bitmode, the address comes from the autoincrement latches */
220
UINT16 addr = (state->bitmode_addr[1] << 7) | (state->bitmode_addr[0] >> 1);
220
UINT16 addr = (state->m_bitmode_addr[1] << 7) | (state->m_bitmode_addr[0] >> 1);
222
222
/* the appropriate pixel is selected into the upper 4 bits */
223
UINT8 result = state->videoram[addr] << ((~state->bitmode_addr[0] & 1) * 4);
223
UINT8 result = state->m_videoram[addr] << ((~state->m_bitmode_addr[0] & 1) * 4);
225
225
/* autoincrement because /BITMD was selected */
226
bitmode_autoinc(space->machine);
226
bitmode_autoinc(space->machine());
228
228
/* the low 4 bits of the data lines are not driven so make them all 1's */
229
229
return result | 0x0f;
233
233
WRITE8_HANDLER( ccastles_bitmode_w )
235
ccastles_state *state = space->machine->driver_data<ccastles_state>();
235
ccastles_state *state = space->machine().driver_data<ccastles_state>();
237
237
/* in bitmode, the address comes from the autoincrement latches */
238
UINT16 addr = (state->bitmode_addr[1] << 7) | (state->bitmode_addr[0] >> 1);
238
UINT16 addr = (state->m_bitmode_addr[1] << 7) | (state->m_bitmode_addr[0] >> 1);
240
240
/* the upper 4 bits of data are replicated to the lower 4 bits */
241
241
data = (data & 0xf0) | (data >> 4);
243
243
/* write through the generic VRAM routine, passing the low 2 X bits as PIXB/PIXA */
244
ccastles_write_vram(space->machine, addr, data, 1, state->bitmode_addr[0] & 3);
244
ccastles_write_vram(space->machine(), addr, data, 1, state->m_bitmode_addr[0] & 3);
246
246
/* autoincrement because /BITMD was selected */
247
bitmode_autoinc(space->machine);
247
bitmode_autoinc(space->machine());
251
251
WRITE8_HANDLER( ccastles_bitmode_addr_w )
253
ccastles_state *state = space->machine->driver_data<ccastles_state>();
253
ccastles_state *state = space->machine().driver_data<ccastles_state>();
255
255
/* write through to video RAM and also to the addressing latches */
256
ccastles_write_vram(space->machine, offset, data, 0, 0);
257
state->bitmode_addr[offset] = data;
256
ccastles_write_vram(space->machine(), offset, data, 0, 0);
257
state->m_bitmode_addr[offset] = data;
266
266
*************************************/
268
VIDEO_UPDATE( ccastles )
268
SCREEN_UPDATE( ccastles )
270
ccastles_state *state = screen->machine->driver_data<ccastles_state>();
271
UINT8 *spriteaddr = &state->spriteram[state->video_control[7] * 0x100]; /* BUF1/BUF2 */
272
int flip = state->video_control[4] ? 0xff : 0x00; /* PLAYER2 */
273
pen_t black = get_black_pen(screen->machine);
270
ccastles_state *state = screen->machine().driver_data<ccastles_state>();
271
UINT8 *spriteaddr = &state->m_spriteram[state->m_video_control[7] * 0x100]; /* BUF1/BUF2 */
272
int flip = state->m_video_control[4] ? 0xff : 0x00; /* PLAYER2 */
273
pen_t black = get_black_pen(screen->machine());
276
276
/* draw the sprites */
277
bitmap_fill(state->spritebitmap, cliprect, 0x0f);
277
bitmap_fill(state->m_spritebitmap, cliprect, 0x0f);
278
278
for (offs = 0; offs < 320/2; offs += 4)
280
280
int x = spriteaddr[offs + 3];
282
282
int which = spriteaddr[offs];
283
283
int color = spriteaddr[offs + 2] >> 7;
285
drawgfx_transpen(state->spritebitmap, cliprect, screen->machine->gfx[0], which, color, flip, flip, x, y, 7);
285
drawgfx_transpen(state->m_spritebitmap, cliprect, screen->machine().gfx[0], which, color, flip, flip, x, y, 7);
288
288
/* draw the bitmap to the screen, looping over Y */
300
300
/* non-VBLANK region: merge the sprites and the bitmap */
303
UINT16 *mosrc = (UINT16 *)state->spritebitmap->base + y * state->spritebitmap->rowpixels;
304
int effy = (((y - state->vblank_end) + (flip ? 0 : state->vscroll)) ^ flip) & 0xff;
303
UINT16 *mosrc = (UINT16 *)state->m_spritebitmap->base + y * state->m_spritebitmap->rowpixels;
304
int effy = (((y - state->m_vblank_end) + (flip ? 0 : state->m_vscroll)) ^ flip) & 0xff;
307
307
/* the "POTATO" chip does some magic here; this is just a guess */
310
src = &state->videoram[effy * 128];
310
src = &state->m_videoram[effy * 128];
312
312
/* loop over X */
313
313
for (x = cliprect->min_x; x <= cliprect->max_x; x++)