~ubuntu-branches/debian/wheezy/mame/wheezy

« back to all changes in this revision

Viewing changes to src/mame/video/neogeo.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Emmanuel Kasper, Félix Arreola Rodríguez, Jordi Mallach
  • Date: 2011-05-11 21:06:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110511210650-jizvh8a6x117y9hr
Tags: 0.142-1
[ Emmanuel Kasper ]
* New upstream release
* Set NOWERROR=1 to allow compiling with gcc-4.6
* Remove fix_powerpc_build.patch, as upstream has taken it in this release
* Add gnome-video-arcade front end as a suggested package

[ Félix Arreola Rodríguez ]
* Add kfreebsd-build.patch to quilt series, to fix build on kfreebsd

[ Jordi Mallach ]
* Remove unneeded and bogus addition of --with-quilt to the dh invocation.
* Add Cesare Falco (long time Ubuntu maintainer) to Uploaders, and wrap
  them into multiple lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 *************************************/
20
20
 
21
 
static void set_videoram_offset( running_machine *machine, UINT16 data )
 
21
static void set_videoram_offset( running_machine &machine, UINT16 data )
22
22
{
23
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
24
 
        state->videoram_offset = data;
 
23
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
24
        state->m_videoram_offset = data;
25
25
 
26
26
        /* the read happens right away */
27
 
        state->videoram_read_buffer = state->videoram[state->videoram_offset];
28
 
}
29
 
 
30
 
 
31
 
static UINT16 get_videoram_data( running_machine *machine )
32
 
{
33
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
34
 
        return state->videoram_read_buffer;
35
 
}
36
 
 
37
 
 
38
 
static void set_videoram_data( running_machine *machine, UINT16 data)
39
 
{
40
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
41
 
        state->videoram[state->videoram_offset] = data;
 
27
        state->m_videoram_read_buffer = state->m_videoram[state->m_videoram_offset];
 
28
}
 
29
 
 
30
 
 
31
static UINT16 get_videoram_data( running_machine &machine )
 
32
{
 
33
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
34
        return state->m_videoram_read_buffer;
 
35
}
 
36
 
 
37
 
 
38
static void set_videoram_data( running_machine &machine, UINT16 data)
 
39
{
 
40
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
41
        state->m_videoram[state->m_videoram_offset] = data;
42
42
 
43
43
        /* auto increment/decrement the current offset - A15 is NOT effected */
44
 
        state->videoram_offset = (state->videoram_offset & 0x8000) | ((state->videoram_offset + state->videoram_modulo) & 0x7fff);
 
44
        state->m_videoram_offset = (state->m_videoram_offset & 0x8000) | ((state->m_videoram_offset + state->m_videoram_modulo) & 0x7fff);
45
45
 
46
46
        /* read next value right away */
47
 
        state->videoram_read_buffer = state->videoram[state->videoram_offset];
48
 
}
49
 
 
50
 
 
51
 
static void set_videoram_modulo( running_machine *machine, UINT16 data)
52
 
{
53
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
54
 
        state->videoram_modulo = data;
55
 
}
56
 
 
57
 
 
58
 
static UINT16 get_videoram_modulo( running_machine *machine )
59
 
{
60
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
61
 
        return state->videoram_modulo;
 
47
        state->m_videoram_read_buffer = state->m_videoram[state->m_videoram_offset];
 
48
}
 
49
 
 
50
 
 
51
static void set_videoram_modulo( running_machine &machine, UINT16 data)
 
52
{
 
53
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
54
        state->m_videoram_modulo = data;
 
55
}
 
56
 
 
57
 
 
58
static UINT16 get_videoram_modulo( running_machine &machine )
 
59
{
 
60
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
61
        return state->m_videoram_modulo;
62
62
}
63
63
 
64
64
 
69
69
 *
70
70
 *************************************/
71
71
 
72
 
static void compute_rgb_weights( running_machine *machine )
 
72
static void compute_rgb_weights( running_machine &machine )
73
73
{
74
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
74
        neogeo_state *state = machine.driver_data<neogeo_state>();
75
75
        static const int resistances[] = { 220, 470, 1000, 2200, 3900 };
76
76
 
77
77
        /* compute four sets of weights - with or without the pulldowns -
78
78
       ensuring that we use the same scaler for all */
79
79
 
80
80
        double scaler = compute_resistor_weights(0, 0xff, -1,
81
 
                                                         5, resistances, state->rgb_weights_normal, 0, 0,
82
 
                                                         0, 0, 0, 0, 0,
83
 
                                                         0, 0, 0, 0, 0);
84
 
 
85
 
        compute_resistor_weights(0, 0xff, scaler,
86
 
                                                         5, resistances, state->rgb_weights_normal_bit15, 8200, 0,
87
 
                                                         0, 0, 0, 0, 0,
88
 
                                                         0, 0, 0, 0, 0);
89
 
 
90
 
        compute_resistor_weights(0, 0xff, scaler,
91
 
                                                         5, resistances, state->rgb_weights_dark, 150, 0,
92
 
                                                         0, 0, 0, 0, 0,
93
 
                                                         0, 0, 0, 0, 0);
94
 
 
95
 
        compute_resistor_weights(0, 0xff, scaler,
96
 
                                                         5, resistances, state->rgb_weights_dark_bit15, 1 / ((1.0 / 8200) + (1.0 / 150)), 0,
 
81
                                                         5, resistances, state->m_rgb_weights_normal, 0, 0,
 
82
                                                         0, 0, 0, 0, 0,
 
83
                                                         0, 0, 0, 0, 0);
 
84
 
 
85
        compute_resistor_weights(0, 0xff, scaler,
 
86
                                                         5, resistances, state->m_rgb_weights_normal_bit15, 8200, 0,
 
87
                                                         0, 0, 0, 0, 0,
 
88
                                                         0, 0, 0, 0, 0);
 
89
 
 
90
        compute_resistor_weights(0, 0xff, scaler,
 
91
                                                         5, resistances, state->m_rgb_weights_dark, 150, 0,
 
92
                                                         0, 0, 0, 0, 0,
 
93
                                                         0, 0, 0, 0, 0);
 
94
 
 
95
        compute_resistor_weights(0, 0xff, scaler,
 
96
                                                         5, resistances, state->m_rgb_weights_dark_bit15, 1 / ((1.0 / 8200) + (1.0 / 150)), 0,
97
97
                                                         0, 0, 0, 0, 0,
98
98
                                                         0, 0, 0, 0, 0);
99
99
}
100
100
 
101
101
 
102
 
static pen_t get_pen( running_machine *machine, UINT16 data )
 
102
static pen_t get_pen( running_machine &machine, UINT16 data )
103
103
{
104
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
104
        neogeo_state *state = machine.driver_data<neogeo_state>();
105
105
        double *weights;
106
106
        UINT8 r, g, b;
107
107
 
108
 
        if (state->screen_dark)
 
108
        if (state->m_screen_dark)
109
109
        {
110
110
                if (data & 0x8000)
111
 
                        weights = state->rgb_weights_dark_bit15;
 
111
                        weights = state->m_rgb_weights_dark_bit15;
112
112
                else
113
 
                        weights = state->rgb_weights_dark;
 
113
                        weights = state->m_rgb_weights_dark;
114
114
        }
115
115
        else
116
116
        {
117
117
                if (data & 0x8000)
118
 
                        weights = state->rgb_weights_normal_bit15;
 
118
                        weights = state->m_rgb_weights_normal_bit15;
119
119
                else
120
 
                        weights = state->rgb_weights_normal;
 
120
                        weights = state->m_rgb_weights_normal;
121
121
        }
122
122
 
123
123
        r = combine_5_weights(weights,
147
147
 
148
148
static STATE_POSTLOAD( regenerate_pens )
149
149
{
150
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
150
        neogeo_state *state = machine.driver_data<neogeo_state>();
151
151
        int i;
152
152
 
153
153
        for (i = 0; i < NUM_PENS; i++)
154
 
                state->pens[i] = get_pen(machine, state->palettes[state->palette_bank][i]);
 
154
                state->m_pens[i] = get_pen(machine, state->m_palettes[state->m_palette_bank][i]);
155
155
}
156
156
 
157
157
 
158
 
void neogeo_set_palette_bank( running_machine *machine, UINT8 data )
 
158
void neogeo_set_palette_bank( running_machine &machine, UINT8 data )
159
159
{
160
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
161
 
        if (data != state->palette_bank)
 
160
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
161
        if (data != state->m_palette_bank)
162
162
        {
163
 
                state->palette_bank = data;
 
163
                state->m_palette_bank = data;
164
164
 
165
165
                regenerate_pens(machine, NULL);
166
166
        }
167
167
}
168
168
 
169
169
 
170
 
void neogeo_set_screen_dark( running_machine *machine, UINT8 data )
 
170
void neogeo_set_screen_dark( running_machine &machine, UINT8 data )
171
171
{
172
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
173
 
        if (data != state->screen_dark)
 
172
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
173
        if (data != state->m_screen_dark)
174
174
        {
175
 
                state->screen_dark = data;
 
175
                state->m_screen_dark = data;
176
176
 
177
177
                regenerate_pens(machine, NULL);
178
178
        }
181
181
 
182
182
READ16_HANDLER( neogeo_paletteram_r )
183
183
{
184
 
        neogeo_state *state = space->machine->driver_data<neogeo_state>();
185
 
        return state->palettes[state->palette_bank][offset];
 
184
        neogeo_state *state = space->machine().driver_data<neogeo_state>();
 
185
        return state->m_palettes[state->m_palette_bank][offset];
186
186
}
187
187
 
188
188
 
189
189
WRITE16_HANDLER( neogeo_paletteram_w )
190
190
{
191
 
        neogeo_state *state = space->machine->driver_data<neogeo_state>();
192
 
        UINT16 *addr = &state->palettes[state->palette_bank][offset];
 
191
        neogeo_state *state = space->machine().driver_data<neogeo_state>();
 
192
        UINT16 *addr = &state->m_palettes[state->m_palette_bank][offset];
193
193
 
194
194
        COMBINE_DATA(addr);
195
195
 
196
 
        state->pens[offset] = get_pen(space->machine, *addr);
 
196
        state->m_pens[offset] = get_pen(space->machine(), *addr);
197
197
}
198
198
 
199
199
 
204
204
 *
205
205
 *************************************/
206
206
 
207
 
static void set_auto_animation_speed( running_machine *machine, UINT8 data)
208
 
{
209
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
210
 
        state->auto_animation_speed = data;
211
 
}
212
 
 
213
 
 
214
 
static void set_auto_animation_disabled( running_machine *machine, UINT8 data)
215
 
{
216
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
217
 
        state->auto_animation_disabled = data;
218
 
}
219
 
 
220
 
 
221
 
UINT8 neogeo_get_auto_animation_counter( running_machine *machine )
222
 
{
223
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
224
 
        return state->auto_animation_counter;
 
207
static void set_auto_animation_speed( running_machine &machine, UINT8 data)
 
208
{
 
209
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
210
        state->m_auto_animation_speed = data;
 
211
}
 
212
 
 
213
 
 
214
static void set_auto_animation_disabled( running_machine &machine, UINT8 data)
 
215
{
 
216
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
217
        state->m_auto_animation_disabled = data;
 
218
}
 
219
 
 
220
 
 
221
UINT8 neogeo_get_auto_animation_counter( running_machine &machine )
 
222
{
 
223
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
224
        return state->m_auto_animation_counter;
225
225
}
226
226
 
227
227
 
228
228
static TIMER_CALLBACK( auto_animation_timer_callback )
229
229
{
230
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
231
 
        if (state->auto_animation_frame_counter == 0)
 
230
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
231
        if (state->m_auto_animation_frame_counter == 0)
232
232
        {
233
 
                state->auto_animation_frame_counter = state->auto_animation_speed;
234
 
                state->auto_animation_counter += 1;
 
233
                state->m_auto_animation_frame_counter = state->m_auto_animation_speed;
 
234
                state->m_auto_animation_counter += 1;
235
235
        }
236
236
        else
237
 
                state->auto_animation_frame_counter = state->auto_animation_frame_counter - 1;
238
 
 
239
 
        timer_adjust_oneshot(state->auto_animation_timer, machine->primary_screen->time_until_pos(NEOGEO_VSSTART), 0);
240
 
}
241
 
 
242
 
 
243
 
static void create_auto_animation_timer( running_machine *machine )
244
 
{
245
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
246
 
        state->auto_animation_timer = timer_alloc(machine, auto_animation_timer_callback, NULL);
247
 
}
248
 
 
249
 
 
250
 
static void start_auto_animation_timer( running_machine *machine )
251
 
{
252
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
253
 
        timer_adjust_oneshot(state->auto_animation_timer, machine->primary_screen->time_until_pos(NEOGEO_VSSTART), 0);
 
237
                state->m_auto_animation_frame_counter = state->m_auto_animation_frame_counter - 1;
 
238
 
 
239
        state->m_auto_animation_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VSSTART));
 
240
}
 
241
 
 
242
 
 
243
static void create_auto_animation_timer( running_machine &machine )
 
244
{
 
245
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
246
        state->m_auto_animation_timer = machine.scheduler().timer_alloc(FUNC(auto_animation_timer_callback));
 
247
}
 
248
 
 
249
 
 
250
static void start_auto_animation_timer( running_machine &machine )
 
251
{
 
252
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
253
        state->m_auto_animation_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VSSTART));
254
254
}
255
255
 
256
256
 
261
261
 *
262
262
 *************************************/
263
263
 
264
 
void neogeo_set_fixed_layer_source( running_machine *machine, UINT8 data )
 
264
void neogeo_set_fixed_layer_source( running_machine &machine, UINT8 data )
265
265
{
266
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
267
 
        state->fixed_layer_source = data;
 
266
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
267
        state->m_fixed_layer_source = data;
268
268
}
269
269
 
270
270
 
271
 
static void draw_fixed_layer( running_machine *machine, bitmap_t *bitmap, int scanline )
 
271
static void draw_fixed_layer( running_machine &machine, bitmap_t *bitmap, int scanline )
272
272
{
273
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
273
        neogeo_state *state = machine.driver_data<neogeo_state>();
274
274
        int x;
275
275
 
276
 
        UINT8* gfx_base = machine->region(state->fixed_layer_source ? "fixed" : "fixedbios")->base();
277
 
        UINT32 addr_mask = machine->region(state->fixed_layer_source ? "fixed" : "fixedbios")->bytes() - 1;
278
 
        UINT16 *video_data = &state->videoram[0x7000 | (scanline >> 3)];
 
276
        UINT8* gfx_base = machine.region(state->m_fixed_layer_source ? "fixed" : "fixedbios")->base();
 
277
        UINT32 addr_mask = machine.region(state->m_fixed_layer_source ? "fixed" : "fixedbios")->bytes() - 1;
 
278
        UINT16 *video_data = &state->m_videoram[0x7000 | (scanline >> 3)];
279
279
        UINT32 *pixel_addr = BITMAP_ADDR32(bitmap, scanline, NEOGEO_HBEND);
280
280
 
281
281
        int garouoffsets[32];
282
 
        int banked = state->fixed_layer_source && (addr_mask > 0x1ffff);
 
282
        int banked = state->m_fixed_layer_source && (addr_mask > 0x1ffff);
283
283
 
284
284
        /* thanks to Mr K for the garou & kof2000 banking info */
285
285
        /* Build line banking table for Garou & MS3 before starting render */
286
 
        if (banked && state->fixed_layer_bank_type == 1)
 
286
        if (banked && state->m_fixed_layer_bank_type == 1)
287
287
        {
288
288
                int garoubank = 0;
289
289
                int k = 0;
290
290
                int y = 0;
291
291
                while (y < 32)
292
292
                {
293
 
                        if (state->videoram[0x7500 + k] == 0x0200 && (state->videoram[0x7580 + k] & 0xff00) == 0xff00)
 
293
                        if (state->m_videoram[0x7500 + k] == 0x0200 && (state->m_videoram[0x7580 + k] & 0xff00) == 0xff00)
294
294
                        {
295
 
                                garoubank = state->videoram[0x7580 + k] & 3;
 
295
                                garoubank = state->m_videoram[0x7580 + k] & 3;
296
296
                                garouoffsets[y++] = garoubank;
297
297
                        }
298
298
                        garouoffsets[y++] = garoubank;
308
308
                if (banked)
309
309
                {
310
310
                        int y = scanline >> 3;
311
 
                        switch (state->fixed_layer_bank_type)
 
311
                        switch (state->m_fixed_layer_bank_type)
312
312
                        {
313
313
                        case 1:
314
314
                                /* Garou, MSlug 3 */
315
315
                                code += 0x1000 * (garouoffsets[(y - 2) & 31] ^ 3);
316
316
                                break;
317
317
                        case 2:
318
 
                                code += 0x1000 * (((state->videoram[0x7500 + ((y - 1) & 31) + 32 * (x / 6)] >> (5 - (x % 6)) * 2) & 3) ^ 3);
 
318
                                code += 0x1000 * (((state->m_videoram[0x7500 + ((y - 1) & 31) + 32 * (x / 6)] >> (5 - (x % 6)) * 2) & 3) ^ 3);
319
319
                                break;
320
320
                        }
321
321
                }
325
325
                        int i;
326
326
 
327
327
                        UINT8 *gfx = &gfx_base[((code << 5) | (scanline & 0x07)) & addr_mask];
328
 
                        pen_t *char_pens = &state->pens[code_and_palette >> 12 << 4];
 
328
                        pen_t *char_pens = &state->m_pens[code_and_palette >> 12 << 4];
329
329
 
330
330
                        for (i = 0; i < 4; i++)
331
331
                        {
401
401
}
402
402
 
403
403
 
404
 
static void draw_sprites( running_machine *machine, bitmap_t *bitmap, int scanline )
 
404
static void draw_sprites( running_machine &machine, bitmap_t *bitmap, int scanline )
405
405
{
406
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
406
        neogeo_state *state = machine.driver_data<neogeo_state>();
407
407
        int sprite_index;
408
408
        int max_sprite_index;
409
409
 
416
416
 
417
417
        /* select the active list */
418
418
        if (scanline & 0x01)
419
 
                sprite_list = &state->videoram[0x8680];
 
419
                sprite_list = &state->m_videoram[0x8680];
420
420
        else
421
 
                sprite_list = &state->videoram[0x8600];
 
421
                sprite_list = &state->m_videoram[0x8600];
422
422
 
423
423
        /* optimization -- find last non-zero entry and only draw that many +1
424
424
       sprite.  This is not 100% correct as the hardware will keep drawing
436
436
        for (sprite_index = 0; sprite_index <= max_sprite_index; sprite_index++)
437
437
        {
438
438
                UINT16 sprite_number = sprite_list[sprite_index] & 0x01ff;
439
 
                UINT16 y_control = state->videoram[0x8200 | sprite_number];
440
 
                UINT16 zoom_control = state->videoram[0x8000 | sprite_number];
 
439
                UINT16 y_control = state->m_videoram[0x8200 | sprite_number];
 
440
                UINT16 zoom_control = state->m_videoram[0x8000 | sprite_number];
441
441
 
442
442
                /* if chained, go to next X coordinate and get new X zoom */
443
443
                if (y_control & 0x40)
449
449
                else
450
450
                {
451
451
                        y = 0x200 - (y_control >> 7);
452
 
                        x = state->videoram[0x8400 | sprite_number] >> 7;
 
452
                        x = state->m_videoram[0x8400 | sprite_number] >> 7;
453
453
                        zoom_y = zoom_control & 0xff;
454
454
                        zoom_x = (zoom_control >> 8) & 0x0f;
455
455
                        rows = y_control & 0x3f;
492
492
                                }
493
493
                        }
494
494
 
495
 
                        sprite_y_and_tile = state->region_zoomy[(zoom_y << 8) | zoom_line];
 
495
                        sprite_y_and_tile = state->m_region_zoomy[(zoom_y << 8) | zoom_line];
496
496
                        sprite_y = sprite_y_and_tile & 0x0f;
497
497
                        tile = sprite_y_and_tile >> 4;
498
498
 
503
503
                        }
504
504
 
505
505
                        attr_and_code_offs = (sprite_number << 6) | (tile << 1);
506
 
                        attr = state->videoram[attr_and_code_offs + 1];
507
 
                        code = ((attr << 12) & 0x70000) | state->videoram[attr_and_code_offs];
 
506
                        attr = state->m_videoram[attr_and_code_offs + 1];
 
507
                        code = ((attr << 12) & 0x70000) | state->m_videoram[attr_and_code_offs];
508
508
 
509
509
                        /* substitute auto animation bits */
510
 
                        if (!state->auto_animation_disabled)
 
510
                        if (!state->m_auto_animation_disabled)
511
511
                        {
512
512
                                if (attr & 0x0008)
513
 
                                        code = (code & ~0x07) | (state->auto_animation_counter & 0x07);
 
513
                                        code = (code & ~0x07) | (state->m_auto_animation_counter & 0x07);
514
514
                                else if (attr & 0x0004)
515
 
                                        code = (code & ~0x03) | (state->auto_animation_counter & 0x03);
 
515
                                        code = (code & ~0x03) | (state->m_auto_animation_counter & 0x03);
516
516
                        }
517
517
 
518
518
                        /* vertical flip? */
522
522
                        zoom_x_table = zoom_x_tables[zoom_x];
523
523
 
524
524
                        /* compute offset in gfx ROM and mask it to the number of bits available */
525
 
                        gfx = &state->sprite_gfx[((code << 8) | (sprite_y << 4)) & state->sprite_gfx_address_mask];
 
525
                        gfx = &state->m_sprite_gfx[((code << 8) | (sprite_y << 4)) & state->m_sprite_gfx_address_mask];
526
526
 
527
 
                        line_pens = &state->pens[attr >> 8 << 4];
 
527
                        line_pens = &state->m_pens[attr >> 8 << 4];
528
528
 
529
529
                        /* horizontal flip? */
530
530
                        if (attr & 0x0001)
590
590
}
591
591
 
592
592
 
593
 
static void parse_sprites( running_machine *machine, int scanline )
 
593
static void parse_sprites( running_machine &machine, int scanline )
594
594
{
595
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
595
        neogeo_state *state = machine.driver_data<neogeo_state>();
596
596
        UINT16 sprite_number;
597
597
        int y = 0;
598
598
        int rows = 0;
602
602
 
603
603
        /* select the active list */
604
604
        if (scanline & 0x01)
605
 
                sprite_list = &state->videoram[0x8680];
 
605
                sprite_list = &state->m_videoram[0x8680];
606
606
        else
607
 
                sprite_list = &state->videoram[0x8600];
 
607
                sprite_list = &state->m_videoram[0x8600];
608
608
 
609
609
        /* scan all sprites */
610
610
        for (sprite_number = 0; sprite_number < MAX_SPRITES_PER_SCREEN; sprite_number++)
611
611
        {
612
 
                UINT16 y_control = state->videoram[0x8200 | sprite_number];
 
612
                UINT16 y_control = state->m_videoram[0x8200 | sprite_number];
613
613
 
614
614
                /* if not chained, get Y position and height, otherwise use previous values */
615
615
                if (~y_control & 0x40)
644
644
 
645
645
static TIMER_CALLBACK( sprite_line_timer_callback )
646
646
{
647
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
647
        neogeo_state *state = machine.driver_data<neogeo_state>();
648
648
        int scanline = param;
649
649
 
650
650
        /* we are at the beginning of a scanline -
651
651
       we need to draw the previous scanline and parse the sprites on the current one */
652
652
        if (scanline != 0)
653
 
                machine->primary_screen->update_partial(scanline - 1);
 
653
                machine.primary_screen->update_partial(scanline - 1);
654
654
 
655
655
        parse_sprites(machine, scanline);
656
656
 
657
657
        /* let's come back at the beginning of the next line */
658
658
        scanline = (scanline + 1) % NEOGEO_VTOTAL;
659
659
 
660
 
        timer_adjust_oneshot(state->sprite_line_timer, machine->primary_screen->time_until_pos(scanline), scanline);
661
 
}
662
 
 
663
 
 
664
 
static void create_sprite_line_timer( running_machine *machine )
665
 
{
666
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
667
 
        state->sprite_line_timer = timer_alloc(machine, sprite_line_timer_callback, NULL);
668
 
}
669
 
 
670
 
 
671
 
static void start_sprite_line_timer( running_machine *machine )
672
 
{
673
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
674
 
        timer_adjust_oneshot(state->sprite_line_timer, machine->primary_screen->time_until_pos(0), 0);
675
 
}
676
 
 
677
 
 
678
 
static void optimize_sprite_data( running_machine *machine )
679
 
{
680
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
660
        state->m_sprite_line_timer->adjust(machine.primary_screen->time_until_pos(scanline), scanline);
 
661
}
 
662
 
 
663
 
 
664
static void create_sprite_line_timer( running_machine &machine )
 
665
{
 
666
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
667
        state->m_sprite_line_timer = machine.scheduler().timer_alloc(FUNC(sprite_line_timer_callback));
 
668
}
 
669
 
 
670
 
 
671
static void start_sprite_line_timer( running_machine &machine )
 
672
{
 
673
        neogeo_state *state = machine.driver_data<neogeo_state>();
 
674
        state->m_sprite_line_timer->adjust(machine.primary_screen->time_until_pos(0));
 
675
}
 
676
 
 
677
 
 
678
static void optimize_sprite_data( running_machine &machine )
 
679
{
 
680
        neogeo_state *state = machine.driver_data<neogeo_state>();
681
681
 
682
682
        /* convert the sprite graphics data into a format that
683
683
       allows faster blitting */
689
689
 
690
690
        /* get mask based on the length rounded up to the nearest
691
691
       power of 2 */
692
 
        state->sprite_gfx_address_mask = 0xffffffff;
 
692
        state->m_sprite_gfx_address_mask = 0xffffffff;
693
693
 
694
 
        len = machine->region("sprites")->bytes();
 
694
        len = machine.region("sprites")->bytes();
695
695
 
696
696
        for (bit = 0x80000000; bit != 0; bit >>= 1)
697
697
        {
698
698
                if (((len * 2) - 1) & bit)
699
699
                        break;
700
700
 
701
 
                state->sprite_gfx_address_mask >>= 1;
 
701
                state->m_sprite_gfx_address_mask >>= 1;
702
702
        }
703
703
 
704
 
        state->sprite_gfx = auto_alloc_array_clear(machine, UINT8, state->sprite_gfx_address_mask + 1);
 
704
        state->m_sprite_gfx = auto_alloc_array_clear(machine, UINT8, state->m_sprite_gfx_address_mask + 1);
705
705
 
706
 
        src = machine->region("sprites")->base();
707
 
        dest = state->sprite_gfx;
 
706
        src = machine.region("sprites")->base();
 
707
        dest = state->m_sprite_gfx;
708
708
 
709
709
        for (i = 0; i < len; i += 0x80, src += 0x80)
710
710
        {
741
741
 *
742
742
 *************************************/
743
743
 
744
 
static UINT16 get_video_control( running_machine *machine )
 
744
static UINT16 get_video_control( running_machine &machine )
745
745
{
746
746
        UINT16 ret;
747
747
        UINT16 v_counter;
768
768
    */
769
769
 
770
770
        /* the vertical counter chain goes from 0xf8 - 0x1ff */
771
 
        v_counter = machine->primary_screen->vpos() + 0x100;
 
771
        v_counter = machine.primary_screen->vpos() + 0x100;
772
772
 
773
773
        if (v_counter >= 0x200)
774
774
                v_counter = v_counter - NEOGEO_VTOTAL;
775
775
 
776
776
        ret = (v_counter << 7) | (neogeo_get_auto_animation_counter(machine) & 0x0007);
777
777
 
778
 
        if (VERBOSE) logerror("%s: video_control read (%04x)\n", cpuexec_describe_context(machine), ret);
 
778
        if (VERBOSE) logerror("%s: video_control read (%04x)\n", machine.describe_context(), ret);
779
779
 
780
780
        return ret;
781
781
}
782
782
 
783
783
 
784
 
static void set_video_control( running_machine *machine, UINT16 data )
 
784
static void set_video_control( running_machine &machine, UINT16 data )
785
785
{
786
786
        /* this does much more than this, but I'm not sure exactly what */
787
 
        if (VERBOSE) logerror("%s: video control write %04x\n", cpuexec_describe_context(machine), data);
 
787
        if (VERBOSE) logerror("%s: video control write %04x\n", machine.describe_context(), data);
788
788
 
789
789
        set_auto_animation_speed(machine, data >> 8);
790
790
        set_auto_animation_disabled(machine, data & 0x0008);
806
806
                {
807
807
                default:
808
808
                case 0x00:
809
 
                case 0x01: ret = get_videoram_data(space->machine); break;
810
 
                case 0x02: ret = get_videoram_modulo(space->machine); break;
811
 
                case 0x03: ret = get_video_control(space->machine); break;
 
809
                case 0x01: ret = get_videoram_data(space->machine()); break;
 
810
                case 0x02: ret = get_videoram_modulo(space->machine()); break;
 
811
                case 0x03: ret = get_video_control(space->machine()); break;
812
812
                }
813
813
        }
814
814
 
827
827
 
828
828
                switch (offset)
829
829
                {
830
 
                case 0x00: set_videoram_offset(space->machine, data); break;
831
 
                case 0x01: set_videoram_data(space->machine, data); break;
832
 
                case 0x02: set_videoram_modulo(space->machine, data); break;
833
 
                case 0x03: set_video_control(space->machine, data); break;
 
830
                case 0x00: set_videoram_offset(space->machine(), data); break;
 
831
                case 0x01: set_videoram_data(space->machine(), data); break;
 
832
                case 0x02: set_videoram_modulo(space->machine(), data); break;
 
833
                case 0x03: set_video_control(space->machine(), data); break;
834
834
                case 0x04: neogeo_set_display_counter_msb(space, data); break;
835
835
                case 0x05: neogeo_set_display_counter_lsb(space, data); break;
836
 
                case 0x06: neogeo_acknowledge_interrupt(space->machine, data); break;
 
836
                case 0x06: neogeo_acknowledge_interrupt(space->machine(), data); break;
837
837
                case 0x07: break; /* unknown, see get_video_control */
838
838
                }
839
839
        }
849
849
 
850
850
VIDEO_START( neogeo )
851
851
{
852
 
        neogeo_state *state = machine->driver_data<neogeo_state>();
 
852
        neogeo_state *state = machine.driver_data<neogeo_state>();
853
853
 
854
854
        /* allocate memory not directly mapped */
855
 
        state->palettes[0] = auto_alloc_array(machine, UINT16, NUM_PENS);
856
 
        state->palettes[1] = auto_alloc_array(machine, UINT16, NUM_PENS);
857
 
        state->pens = auto_alloc_array(machine, pen_t, NUM_PENS);
858
 
        state->videoram = auto_alloc_array(machine, UINT16, 0x20000/2);
 
855
        state->m_palettes[0] = auto_alloc_array(machine, UINT16, NUM_PENS);
 
856
        state->m_palettes[1] = auto_alloc_array(machine, UINT16, NUM_PENS);
 
857
        state->m_pens = auto_alloc_array(machine, pen_t, NUM_PENS);
 
858
        state->m_videoram = auto_alloc_array(machine, UINT16, 0x20000/2);
859
859
 
860
860
        /* clear allocated memory */
861
 
        memset(state->palettes[0], 0x00, NUM_PENS * sizeof(UINT16));
862
 
        memset(state->palettes[1], 0x00, NUM_PENS * sizeof(UINT16));
863
 
        memset(state->pens, 0x00, NUM_PENS * sizeof(pen_t));
864
 
        memset(state->videoram, 0x00, 0x20000);
 
861
        memset(state->m_palettes[0], 0x00, NUM_PENS * sizeof(UINT16));
 
862
        memset(state->m_palettes[1], 0x00, NUM_PENS * sizeof(UINT16));
 
863
        memset(state->m_pens, 0x00, NUM_PENS * sizeof(pen_t));
 
864
        memset(state->m_videoram, 0x00, 0x20000);
865
865
 
866
866
        compute_rgb_weights(machine);
867
867
        create_sprite_line_timer(machine);
869
869
        optimize_sprite_data(machine);
870
870
 
871
871
        /* initialize values that are not modified on a reset */
872
 
        state->videoram_read_buffer = 0;
873
 
        state->videoram_offset = 0;
874
 
        state->videoram_modulo = 0;
875
 
        state->auto_animation_speed = 0;
876
 
        state->auto_animation_disabled = 0;
877
 
        state->auto_animation_counter = 0;
878
 
        state->auto_animation_frame_counter = 0;
 
872
        state->m_videoram_read_buffer = 0;
 
873
        state->m_videoram_offset = 0;
 
874
        state->m_videoram_modulo = 0;
 
875
        state->m_auto_animation_speed = 0;
 
876
        state->m_auto_animation_disabled = 0;
 
877
        state->m_auto_animation_counter = 0;
 
878
        state->m_auto_animation_frame_counter = 0;
879
879
 
880
880
        /* register for state saving */
881
 
        state_save_register_global_pointer(machine, state->palettes[0], NUM_PENS);
882
 
        state_save_register_global_pointer(machine, state->palettes[1], NUM_PENS);
883
 
        state_save_register_global_pointer(machine, state->videoram, 0x20000/2);
884
 
        state_save_register_global(machine, state->videoram_read_buffer);
885
 
        state_save_register_global(machine, state->videoram_modulo);
886
 
        state_save_register_global(machine, state->videoram_offset);
887
 
        state_save_register_global(machine, state->fixed_layer_source);
888
 
        state_save_register_global(machine, state->screen_dark);
889
 
        state_save_register_global(machine, state->palette_bank);
890
 
        state_save_register_global(machine, state->auto_animation_speed);
891
 
        state_save_register_global(machine, state->auto_animation_disabled);
892
 
        state_save_register_global(machine, state->auto_animation_counter);
893
 
        state_save_register_global(machine, state->auto_animation_frame_counter);
894
 
 
895
 
        state_save_register_postload(machine, regenerate_pens, NULL);
896
 
 
897
 
        state->region_zoomy = machine->region("zoomy")->base();
 
881
        state->save_pointer(NAME(state->m_palettes[0]), NUM_PENS);
 
882
        state->save_pointer(NAME(state->m_palettes[1]), NUM_PENS);
 
883
        state->save_pointer(NAME(state->m_videoram), 0x20000/2);
 
884
        state->save_item(NAME(state->m_videoram_read_buffer));
 
885
        state->save_item(NAME(state->m_videoram_modulo));
 
886
        state->save_item(NAME(state->m_videoram_offset));
 
887
        state->save_item(NAME(state->m_fixed_layer_source));
 
888
        state->save_item(NAME(state->m_screen_dark));
 
889
        state->save_item(NAME(state->m_palette_bank));
 
890
        state->save_item(NAME(state->m_auto_animation_speed));
 
891
        state->save_item(NAME(state->m_auto_animation_disabled));
 
892
        state->save_item(NAME(state->m_auto_animation_counter));
 
893
        state->save_item(NAME(state->m_auto_animation_frame_counter));
 
894
 
 
895
        machine.state().register_postload(regenerate_pens, NULL);
 
896
 
 
897
        state->m_region_zoomy = machine.region("zoomy")->base();
898
898
}
899
899
 
900
900
 
920
920
 *
921
921
 *************************************/
922
922
 
923
 
VIDEO_UPDATE( neogeo )
 
923
SCREEN_UPDATE( neogeo )
924
924
{
925
 
        neogeo_state *state = screen->machine->driver_data<neogeo_state>();
 
925
        neogeo_state *state = screen->machine().driver_data<neogeo_state>();
926
926
 
927
927
        /* fill with background color first */
928
 
        bitmap_fill(bitmap, cliprect, state->pens[0x0fff]);
929
 
 
930
 
        draw_sprites(screen->machine, bitmap, cliprect->min_y);
931
 
 
932
 
        draw_fixed_layer(screen->machine, bitmap, cliprect->min_y);
 
928
        bitmap_fill(bitmap, cliprect, state->m_pens[0x0fff]);
 
929
 
 
930
        draw_sprites(screen->machine(), bitmap, cliprect->min_y);
 
931
 
 
932
        draw_fixed_layer(screen->machine(), bitmap, cliprect->min_y);
933
933
 
934
934
        return 0;
935
935
}