18
18
VIDEO_START( cloud9 )
20
cloud9_state *state = machine->driver_data<cloud9_state>();
20
cloud9_state *state = machine.driver_data<cloud9_state>();
21
21
static const int resistances[3] = { 22000, 10000, 4700 };
23
23
/* allocate second bank of videoram */
24
state->videoram = auto_alloc_array(machine, UINT8, 0x8000);
25
memory_set_bankptr(machine, "bank1", state->videoram);
24
state->m_videoram = auto_alloc_array(machine, UINT8, 0x8000);
25
memory_set_bankptr(machine, "bank1", state->m_videoram);
27
27
/* get pointers to our PROMs */
28
state->syncprom = machine->region("proms")->base() + 0x000;
29
state->wpprom = machine->region("proms")->base() + 0x200;
30
state->priprom = machine->region("proms")->base() + 0x300;
28
state->m_syncprom = machine.region("proms")->base() + 0x000;
29
state->m_wpprom = machine.region("proms")->base() + 0x200;
30
state->m_priprom = machine.region("proms")->base() + 0x300;
32
32
/* compute the color output resistor weights at startup */
33
33
compute_resistor_weights(0, 255, -1.0,
34
3, resistances, state->rweights, 1000, 0,
35
3, resistances, state->gweights, 1000, 0,
36
3, resistances, state->bweights, 1000, 0);
34
3, resistances, state->m_rweights, 1000, 0,
35
3, resistances, state->m_gweights, 1000, 0,
36
3, resistances, state->m_bweights, 1000, 0);
38
38
/* allocate a bitmap for drawing sprites */
39
state->spritebitmap = machine->primary_screen->alloc_compatible_bitmap();
39
state->m_spritebitmap = machine.primary_screen->alloc_compatible_bitmap();
41
41
/* register for savestates */
42
state_save_register_global_pointer(machine, state->videoram, 0x8000);
43
state_save_register_global_array(machine, state->video_control);
44
state_save_register_global_array(machine, state->bitmode_addr);
42
state->save_pointer(NAME(state->m_videoram), 0x8000);
43
state->save_item(NAME(state->m_video_control));
44
state->save_item(NAME(state->m_bitmode_addr));
83
83
bit0 = (~r >> 0) & 0x01;
84
84
bit1 = (~r >> 1) & 0x01;
85
85
bit2 = (~r >> 2) & 0x01;
86
r = combine_3_weights(state->rweights, bit0, bit1, bit2);
86
r = combine_3_weights(state->m_rweights, bit0, bit1, bit2);
88
88
/* green component (inverted) */
89
89
bit0 = (~g >> 0) & 0x01;
90
90
bit1 = (~g >> 1) & 0x01;
91
91
bit2 = (~g >> 2) & 0x01;
92
g = combine_3_weights(state->gweights, bit0, bit1, bit2);
92
g = combine_3_weights(state->m_gweights, bit0, bit1, bit2);
94
94
/* blue component (inverted) */
95
95
bit0 = (~b >> 0) & 0x01;
96
96
bit1 = (~b >> 1) & 0x01;
97
97
bit2 = (~b >> 2) & 0x01;
98
b = combine_3_weights(state->bweights, bit0, bit1, bit2);
98
b = combine_3_weights(state->m_bweights, bit0, bit1, bit2);
100
palette_set_color(space->machine, offset & 0x3f, MAKE_RGB(r, g, b));
100
palette_set_color(space->machine(), offset & 0x3f, MAKE_RGB(r, g, b));
110
110
*************************************/
112
INLINE void cloud9_write_vram( running_machine *machine, UINT16 addr, UINT8 data, UINT8 bitmd, UINT8 pixba )
112
INLINE void cloud9_write_vram( running_machine &machine, UINT16 addr, UINT8 data, UINT8 bitmd, UINT8 pixba )
114
cloud9_state *state = machine->driver_data<cloud9_state>();
115
UINT8 *dest = &state->videoram[0x0000 | (addr & 0x3fff)];
116
UINT8 *dest2 = &state->videoram[0x4000 | (addr & 0x3fff)];
114
cloud9_state *state = machine.driver_data<cloud9_state>();
115
UINT8 *dest = &state->m_videoram[0x0000 | (addr & 0x3fff)];
116
UINT8 *dest2 = &state->m_videoram[0x4000 | (addr & 0x3fff)];
117
117
UINT8 promaddr = 0;
132
132
promaddr |= bitmd << 7;
133
promaddr |= state->video_control[4] << 6;
134
promaddr |= state->video_control[6] << 5;
133
promaddr |= state->m_video_control[4] << 6;
134
promaddr |= state->m_video_control[6] << 5;
135
135
promaddr |= ((addr & 0xf000) != 0x4000) << 4;
136
136
promaddr |= ((addr & 0x3800) == 0x0000) << 3;
137
137
promaddr |= ((addr & 0x0600) == 0x0600) << 2;
138
138
promaddr |= (pixba << 0);
140
140
/* look up the PROM result */
141
wpbits = state->wpprom[promaddr];
141
wpbits = state->m_wpprom[promaddr];
143
143
/* write to the appropriate parts of VRAM depending on the result */
144
144
if (!(wpbits & 1))
160
160
*************************************/
162
INLINE void bitmode_autoinc( running_machine *machine )
162
INLINE void bitmode_autoinc( running_machine &machine )
164
cloud9_state *state = machine->driver_data<cloud9_state>();
164
cloud9_state *state = machine.driver_data<cloud9_state>();
166
166
/* auto increment in the x-direction if it's enabled */
167
if (!state->video_control[0]) /* /AX */
168
state->bitmode_addr[0]++;
167
if (!state->m_video_control[0]) /* /AX */
168
state->m_bitmode_addr[0]++;
170
170
/* auto increment in the y-direction if it's enabled */
171
if (!state->video_control[1]) /* /AY */
172
state->bitmode_addr[1]++;
171
if (!state->m_video_control[1]) /* /AY */
172
state->m_bitmode_addr[1]++;
183
183
WRITE8_HANDLER( cloud9_videoram_w )
185
185
/* direct writes to VRAM go through the write protect PROM as well */
186
cloud9_write_vram(space->machine, offset, data, 0, 0);
186
cloud9_write_vram(space->machine(), offset, data, 0, 0);
197
197
READ8_HANDLER( cloud9_bitmode_r )
199
cloud9_state *state = space->machine->driver_data<cloud9_state>();
199
cloud9_state *state = space->machine().driver_data<cloud9_state>();
201
201
/* in bitmode, the address comes from the autoincrement latches */
202
UINT16 addr = (state->bitmode_addr[1] << 6) | (state->bitmode_addr[0] >> 2);
202
UINT16 addr = (state->m_bitmode_addr[1] << 6) | (state->m_bitmode_addr[0] >> 2);
204
204
/* the appropriate pixel is selected into the upper 4 bits */
205
UINT8 result = state->videoram[((~state->bitmode_addr[0] & 2) << 13) | addr] << ((state->bitmode_addr[0] & 1) * 4);
205
UINT8 result = state->m_videoram[((~state->m_bitmode_addr[0] & 2) << 13) | addr] << ((state->m_bitmode_addr[0] & 1) * 4);
207
207
/* autoincrement because /BITMD was selected */
208
bitmode_autoinc(space->machine);
208
bitmode_autoinc(space->machine());
210
210
/* the upper 4 bits of the data lines are not driven so make them all 1's */
211
211
return (result >> 4) | 0xf0;
215
215
WRITE8_HANDLER( cloud9_bitmode_w )
217
cloud9_state *state = space->machine->driver_data<cloud9_state>();
217
cloud9_state *state = space->machine().driver_data<cloud9_state>();
219
219
/* in bitmode, the address comes from the autoincrement latches */
220
UINT16 addr = (state->bitmode_addr[1] << 6) | (state->bitmode_addr[0] >> 2);
220
UINT16 addr = (state->m_bitmode_addr[1] << 6) | (state->m_bitmode_addr[0] >> 2);
222
222
/* the lower 4 bits of data are replicated to the upper 4 bits */
223
223
data = (data & 0x0f) | (data << 4);
225
225
/* write through the generic VRAM routine, passing the low 2 X bits as PIXB/PIXA */
226
cloud9_write_vram(space->machine, addr, data, 1, state->bitmode_addr[0] & 3);
226
cloud9_write_vram(space->machine(), addr, data, 1, state->m_bitmode_addr[0] & 3);
228
228
/* autoincrement because /BITMD was selected */
229
bitmode_autoinc(space->machine);
229
bitmode_autoinc(space->machine());
233
233
WRITE8_HANDLER( cloud9_bitmode_addr_w )
235
cloud9_state *state = space->machine->driver_data<cloud9_state>();
235
cloud9_state *state = space->machine().driver_data<cloud9_state>();
237
237
/* write through to video RAM and also to the addressing latches */
238
cloud9_write_vram(space->machine, offset, data, 0, 0);
239
state->bitmode_addr[offset] = data;
238
cloud9_write_vram(space->machine(), offset, data, 0, 0);
239
state->m_bitmode_addr[offset] = data;
248
248
*************************************/
250
VIDEO_UPDATE( cloud9 )
250
SCREEN_UPDATE( cloud9 )
252
cloud9_state *state = screen->machine->driver_data<cloud9_state>();
253
UINT8 *spriteaddr = state->spriteram;
254
int flip = state->video_control[5] ? 0xff : 0x00; /* PLAYER2 */
255
pen_t black = get_black_pen(screen->machine);
252
cloud9_state *state = screen->machine().driver_data<cloud9_state>();
253
UINT8 *spriteaddr = state->m_spriteram;
254
int flip = state->m_video_control[5] ? 0xff : 0x00; /* PLAYER2 */
255
pen_t black = get_black_pen(screen->machine());
258
258
/* draw the sprites */
259
bitmap_fill(state->spritebitmap, cliprect, 0x00);
259
bitmap_fill(state->m_spritebitmap, cliprect, 0x00);
260
260
for (offs = 0; offs < 0x20; offs++)
261
261
if (spriteaddr[offs + 0x00] != 0)
267
267
int which = spriteaddr[offs + 0x20];
270
drawgfx_transpen(state->spritebitmap, cliprect, screen->machine->gfx[0], which, color, xflip, yflip, x, y, 0);
270
drawgfx_transpen(state->m_spritebitmap, cliprect, screen->machine().gfx[0], which, color, xflip, yflip, x, y, 0);
271
271
if (x >= 256 - 16)
272
drawgfx_transpen(state->spritebitmap, cliprect, screen->machine->gfx[0], which, color, xflip, yflip, x - 256, y, 0);
272
drawgfx_transpen(state->m_spritebitmap, cliprect, screen->machine().gfx[0], which, color, xflip, yflip, x - 256, y, 0);
275
275
/* draw the bitmap to the screen, looping over Y */
287
287
/* non-VBLANK region: merge the sprites and the bitmap */
290
UINT16 *mosrc = (UINT16 *)state->spritebitmap->base + y * state->spritebitmap->rowpixels;
290
UINT16 *mosrc = (UINT16 *)state->m_spritebitmap->base + y * state->m_spritebitmap->rowpixels;
291
291
int effy = y ^ flip;
294
294
/* two videoram arrays */
295
src[0] = &state->videoram[0x4000 | (effy * 64)];
296
src[1] = &state->videoram[0x0000 | (effy * 64)];
295
src[0] = &state->m_videoram[0x4000 | (effy * 64)];
296
src[1] = &state->m_videoram[0x0000 | (effy * 64)];
298
298
/* loop over X */
299
299
for (x = cliprect->min_x; x <= cliprect->max_x; x++)