~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/mame/machine/balsente.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:
16
16
 
17
17
 
18
18
/* local prototypes */
19
 
static void poly17_init(running_machine *machine);
20
 
static void counter_set_out(running_machine *machine, int which, int gate);
21
 
static void update_grudge_steering(running_machine *machine);
 
19
static void poly17_init(running_machine &machine);
 
20
static void counter_set_out(running_machine &machine, int which, int gate);
 
21
static void update_grudge_steering(running_machine &machine);
22
22
 
23
23
 
24
24
 
37
37
 
38
38
TIMER_DEVICE_CALLBACK( balsente_interrupt_timer )
39
39
{
40
 
        balsente_state *state = timer.machine->driver_data<balsente_state>();
 
40
        balsente_state *state = timer.machine().driver_data<balsente_state>();
41
41
 
42
42
        /* next interrupt after scanline 256 is scanline 64 */
43
43
        if (param == 256)
44
 
                state->scanline_timer->adjust(timer.machine->primary_screen->time_until_pos(64), 64);
 
44
                state->m_scanline_timer->adjust(timer.machine().primary_screen->time_until_pos(64), 64);
45
45
        else
46
 
                state->scanline_timer->adjust(timer.machine->primary_screen->time_until_pos(param + 64), param + 64);
 
46
                state->m_scanline_timer->adjust(timer.machine().primary_screen->time_until_pos(param + 64), param + 64);
47
47
 
48
48
        /* IRQ starts on scanline 0, 64, 128, etc. */
49
 
        cputag_set_input_line(timer.machine, "maincpu", M6809_IRQ_LINE, ASSERT_LINE);
 
49
        cputag_set_input_line(timer.machine(), "maincpu", M6809_IRQ_LINE, ASSERT_LINE);
50
50
 
51
51
        /* it will turn off on the next HBLANK */
52
 
        timer_set(timer.machine, timer.machine->primary_screen->time_until_pos(param, BALSENTE_HBSTART), NULL, 0, irq_off);
 
52
        timer.machine().scheduler().timer_set(timer.machine().primary_screen->time_until_pos(param, BALSENTE_HBSTART), FUNC(irq_off));
53
53
 
54
54
        /* if this is Grudge Match, update the steering */
55
 
        if (state->grudge_steering_result & 0x80)
56
 
                update_grudge_steering(timer.machine);
 
55
        if (state->m_grudge_steering_result & 0x80)
 
56
                update_grudge_steering(timer.machine());
57
57
 
58
58
        /* if we're a shooter, we do a little more work */
59
 
        if (state->shooter)
 
59
        if (state->m_shooter)
60
60
        {
61
61
                UINT8 tempx, tempy;
62
62
 
63
63
                /* we latch the beam values on the first interrupt after VBLANK */
64
64
                if (param == 64)
65
65
                {
66
 
                        state->shooter_x = input_port_read(timer.machine, "FAKEX");
67
 
                        state->shooter_y = input_port_read(timer.machine, "FAKEY");
 
66
                        state->m_shooter_x = input_port_read(timer.machine(), "FAKEX");
 
67
                        state->m_shooter_y = input_port_read(timer.machine(), "FAKEY");
68
68
                }
69
69
 
70
70
                /* which bits get returned depends on which scanline we're at */
71
 
                tempx = state->shooter_x << ((param - 64) / 64);
72
 
                tempy = state->shooter_y << ((param - 64) / 64);
73
 
                state->nstocker_bits = ((tempx >> 4) & 0x08) | ((tempx >> 1) & 0x04) |
 
71
                tempx = state->m_shooter_x << ((param - 64) / 64);
 
72
                tempy = state->m_shooter_y << ((param - 64) / 64);
 
73
                state->m_nstocker_bits = ((tempx >> 4) & 0x08) | ((tempx >> 1) & 0x04) |
74
74
                                                                ((tempy >> 6) & 0x02) | ((tempy >> 3) & 0x01);
75
75
        }
76
76
}
78
78
 
79
79
MACHINE_START( balsente )
80
80
{
81
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
81
        balsente_state *state = machine.driver_data<balsente_state>();
82
82
        int i;
83
83
 
84
 
        state->cem_device[0] = state->m_cem1;
85
 
        state->cem_device[1] = state->m_cem2;
86
 
        state->cem_device[2] = state->m_cem3;
87
 
        state->cem_device[3] = state->m_cem4;
88
 
        state->cem_device[4] = state->m_cem5;
89
 
        state->cem_device[5] = state->m_cem6;
 
84
        state->m_cem_device[0] = state->m_cem1;
 
85
        state->m_cem_device[1] = state->m_cem2;
 
86
        state->m_cem_device[2] = state->m_cem3;
 
87
        state->m_cem_device[3] = state->m_cem4;
 
88
        state->m_cem_device[4] = state->m_cem5;
 
89
        state->m_cem_device[5] = state->m_cem6;
90
90
 
91
91
        /* create the polynomial tables */
92
92
        poly17_init(machine);
94
94
        /* register for saving */
95
95
        for (i = 0; i < 3; i++)
96
96
        {
97
 
                state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].timer_active);
98
 
                state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].initial);
99
 
                state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].count);
100
 
                state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].gate);
101
 
                state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].out);
102
 
                state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].mode);
103
 
                state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].readbyte);
104
 
                state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].writebyte);
 
97
                state_save_register_item(machine, "8253counter", NULL, i, state->m_counter[i].timer_active);
 
98
                state_save_register_item(machine, "8253counter", NULL, i, state->m_counter[i].initial);
 
99
                state_save_register_item(machine, "8253counter", NULL, i, state->m_counter[i].count);
 
100
                state_save_register_item(machine, "8253counter", NULL, i, state->m_counter[i].gate);
 
101
                state_save_register_item(machine, "8253counter", NULL, i, state->m_counter[i].out);
 
102
                state_save_register_item(machine, "8253counter", NULL, i, state->m_counter[i].mode);
 
103
                state_save_register_item(machine, "8253counter", NULL, i, state->m_counter[i].readbyte);
 
104
                state_save_register_item(machine, "8253counter", NULL, i, state->m_counter[i].writebyte);
105
105
        }
106
106
 
107
 
        state_save_register_global(machine, state->counter_control);
108
 
        state_save_register_global(machine, state->counter_0_ff);
109
 
        state_save_register_global(machine, state->counter_0_timer_active);
110
 
 
111
 
        state_save_register_global_array(machine, state->analog_input_data);
112
 
        state_save_register_global(machine, state->adc_value);
113
 
 
114
 
        state_save_register_global(machine, state->dac_value);
115
 
        state_save_register_global(machine, state->dac_register);
116
 
        state_save_register_global(machine, state->chip_select);
117
 
 
118
 
        state_save_register_global(machine, state->m6850_status);
119
 
        state_save_register_global(machine, state->m6850_control);
120
 
        state_save_register_global(machine, state->m6850_input);
121
 
        state_save_register_global(machine, state->m6850_output);
122
 
        state_save_register_global(machine, state->m6850_data_ready);
123
 
 
124
 
        state_save_register_global(machine, state->m6850_sound_status);
125
 
        state_save_register_global(machine, state->m6850_sound_control);
126
 
        state_save_register_global(machine, state->m6850_sound_input);
127
 
        state_save_register_global(machine, state->m6850_sound_output);
128
 
 
129
 
        state_save_register_global_array(machine, state->noise_position);
130
 
 
131
 
        state_save_register_global(machine, state->nstocker_bits);
132
 
        state_save_register_global(machine, state->spiker_expand_color);
133
 
        state_save_register_global(machine, state->spiker_expand_bgcolor);
134
 
        state_save_register_global(machine, state->spiker_expand_bits);
135
 
        state_save_register_global(machine, state->grudge_steering_result);
136
 
        state_save_register_global_array(machine, state->grudge_last_steering);
 
107
        state->save_item(NAME(state->m_counter_control));
 
108
        state->save_item(NAME(state->m_counter_0_ff));
 
109
        state->save_item(NAME(state->m_counter_0_timer_active));
 
110
 
 
111
        state->save_item(NAME(state->m_analog_input_data));
 
112
        state->save_item(NAME(state->m_adc_value));
 
113
 
 
114
        state->save_item(NAME(state->m_dac_value));
 
115
        state->save_item(NAME(state->m_dac_register));
 
116
        state->save_item(NAME(state->m_chip_select));
 
117
 
 
118
        state->save_item(NAME(state->m_m6850_status));
 
119
        state->save_item(NAME(state->m_m6850_control));
 
120
        state->save_item(NAME(state->m_m6850_input));
 
121
        state->save_item(NAME(state->m_m6850_output));
 
122
        state->save_item(NAME(state->m_m6850_data_ready));
 
123
 
 
124
        state->save_item(NAME(state->m_m6850_sound_status));
 
125
        state->save_item(NAME(state->m_m6850_sound_control));
 
126
        state->save_item(NAME(state->m_m6850_sound_input));
 
127
        state->save_item(NAME(state->m_m6850_sound_output));
 
128
 
 
129
        state->save_item(NAME(state->m_noise_position));
 
130
 
 
131
        state->save_item(NAME(state->m_nstocker_bits));
 
132
        state->save_item(NAME(state->m_spiker_expand_color));
 
133
        state->save_item(NAME(state->m_spiker_expand_bgcolor));
 
134
        state->save_item(NAME(state->m_spiker_expand_bits));
 
135
        state->save_item(NAME(state->m_grudge_steering_result));
 
136
        state->save_item(NAME(state->m_grudge_last_steering));
137
137
}
138
138
 
139
139
 
140
140
MACHINE_RESET( balsente )
141
141
{
142
 
        address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
143
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
142
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
 
143
        balsente_state *state = machine.driver_data<balsente_state>();
144
144
        int numbanks;
145
145
 
146
146
        /* reset counters; counter 2's gate is tied high */
147
 
        memset(state->counter, 0, sizeof(state->counter));
148
 
        state->counter[1].timer = machine->device<timer_device>("8253_1_timer");
149
 
        state->counter[2].timer = machine->device<timer_device>("8253_2_timer");
150
 
        state->counter[2].gate = 1;
 
147
        memset(state->m_counter, 0, sizeof(state->m_counter));
 
148
        state->m_counter[1].timer = machine.device<timer_device>("8253_1_timer");
 
149
        state->m_counter[2].timer = machine.device<timer_device>("8253_2_timer");
 
150
        state->m_counter[2].gate = 1;
151
151
 
152
152
        /* reset the manual counter 0 clock */
153
 
        state->counter_control = 0x00;
154
 
        state->counter_0_ff = 0;
155
 
        state->counter_0_timer_active = 0;
 
153
        state->m_counter_control = 0x00;
 
154
        state->m_counter_0_ff = 0;
 
155
        state->m_counter_0_timer_active = 0;
156
156
 
157
157
        /* reset the ADC states */
158
 
        state->adc_value = 0;
 
158
        state->m_adc_value = 0;
159
159
 
160
160
        /* reset the CEM3394 I/O states */
161
 
        state->dac_value = 0;
162
 
        state->dac_register = 0;
163
 
        state->chip_select = 0x3f;
 
161
        state->m_dac_value = 0;
 
162
        state->m_dac_register = 0;
 
163
        state->m_chip_select = 0x3f;
164
164
 
165
165
        /* reset game-specific states */
166
 
        state->grudge_steering_result = 0;
 
166
        state->m_grudge_steering_result = 0;
167
167
 
168
168
        /* reset the 6850 chips */
169
169
        balsente_m6850_w(space, 0, 3);
170
170
        balsente_m6850_sound_w(space, 0, 3);
171
171
 
172
172
        /* reset the noise generator */
173
 
        memset(state->noise_position, 0, sizeof(state->noise_position));
 
173
        memset(state->m_noise_position, 0, sizeof(state->m_noise_position));
174
174
 
175
175
        /* point the banks to bank 0 */
176
 
        numbanks = (machine->region("maincpu")->bytes() > 0x40000) ? 16 : 8;
177
 
        memory_configure_bank(machine, "bank1", 0, numbanks, &machine->region("maincpu")->base()[0x10000], 0x6000);
178
 
        memory_configure_bank(machine, "bank2", 0, numbanks, &machine->region("maincpu")->base()[0x12000], 0x6000);
179
 
        memory_set_bank(space->machine, "bank1", 0);
180
 
        memory_set_bank(space->machine, "bank2", 0);
181
 
        machine->device("maincpu")->reset();
 
176
        numbanks = (machine.region("maincpu")->bytes() > 0x40000) ? 16 : 8;
 
177
        memory_configure_bank(machine, "bank1", 0, numbanks, &machine.region("maincpu")->base()[0x10000], 0x6000);
 
178
        memory_configure_bank(machine, "bank2", 0, numbanks, &machine.region("maincpu")->base()[0x12000], 0x6000);
 
179
        memory_set_bank(space->machine(), "bank1", 0);
 
180
        memory_set_bank(space->machine(), "bank2", 0);
 
181
        machine.device("maincpu")->reset();
182
182
 
183
183
        /* start a timer to generate interrupts */
184
 
        state->scanline_timer->adjust(machine->primary_screen->time_until_pos(0));
 
184
        state->m_scanline_timer->adjust(machine.primary_screen->time_until_pos(0));
185
185
}
186
186
 
187
187
 
195
195
 *
196
196
 *************************************/
197
197
 
198
 
static void poly17_init(running_machine *machine)
 
198
static void poly17_init(running_machine &machine)
199
199
{
200
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
200
        balsente_state *state = machine.driver_data<balsente_state>();
201
201
        UINT32 i, x = 0;
202
202
        UINT8 *p, *r;
203
203
 
204
204
        /* allocate memory */
205
 
        p = state->poly17;
206
 
        r = state->rand17;
 
205
        p = state->m_poly17;
 
206
        r = state->m_rand17;
207
207
 
208
208
        /* generate the polynomial */
209
209
        for (i = 0; i < POLY17_SIZE; i++)
220
220
 
221
221
void balsente_noise_gen(device_t *device, int count, short *buffer)
222
222
{
223
 
        balsente_state *state = device->machine->driver_data<balsente_state>();
 
223
        balsente_state *state = device->machine().driver_data<balsente_state>();
224
224
        int chip;
225
225
        UINT32 step, noise_counter;
226
226
 
227
227
        /* find the chip we are referring to */
228
 
        for (chip = 0; chip < ARRAY_LENGTH(state->cem_device); chip++)
229
 
                if (device == state->cem_device[chip])
 
228
        for (chip = 0; chip < ARRAY_LENGTH(state->m_cem_device); chip++)
 
229
                if (device == state->m_cem_device[chip])
230
230
                        break;
231
 
        assert(chip < ARRAY_LENGTH(state->cem_device));
 
231
        assert(chip < ARRAY_LENGTH(state->m_cem_device));
232
232
 
233
233
        /* noise generator runs at 100kHz */
234
234
        step = (100000 << 14) / CEM3394_SAMPLE_RATE;
235
 
        noise_counter = state->noise_position[chip];
 
235
        noise_counter = state->m_noise_position[chip];
236
236
 
237
237
        while (count--)
238
238
        {
239
 
                *buffer++ = state->poly17[(noise_counter >> 14) & POLY17_SIZE] << 12;
 
239
                *buffer++ = state->m_poly17[(noise_counter >> 14) & POLY17_SIZE] << 12;
240
240
                noise_counter += step;
241
241
        }
242
242
 
243
243
        /* remember the noise position */
244
 
        state->noise_position[chip] = noise_counter;
 
244
        state->m_noise_position[chip] = noise_counter;
245
245
}
246
246
 
247
247
 
260
260
 
261
261
READ8_HANDLER( balsente_random_num_r )
262
262
{
263
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
263
        balsente_state *state = space->machine().driver_data<balsente_state>();
264
264
        UINT32 cc;
265
265
 
266
266
        /* CPU runs at 1.25MHz, noise source at 100kHz --> multiply by 12.5 */
267
 
        cc = space->machine->firstcpu->total_cycles();
 
267
        cc = space->machine().firstcpu->total_cycles();
268
268
 
269
269
        /* 12.5 = 8 + 4 + 0.5 */
270
270
        cc = (cc << 3) + (cc << 2) + (cc >> 1);
271
 
        return state->rand17[cc & POLY17_SIZE];
 
271
        return state->m_rand17[cc & POLY17_SIZE];
272
272
}
273
273
 
274
274
 
282
282
WRITE8_HANDLER( balsente_rombank_select_w )
283
283
{
284
284
        /* the bank number comes from bits 4-6 */
285
 
        memory_set_bank(space->machine, "bank1", (data >> 4) & 7);
286
 
        memory_set_bank(space->machine, "bank2", (data >> 4) & 7);
 
285
        memory_set_bank(space->machine(), "bank1", (data >> 4) & 7);
 
286
        memory_set_bank(space->machine(), "bank2", (data >> 4) & 7);
287
287
}
288
288
 
289
289
 
293
293
        int bank = data & 7;
294
294
 
295
295
        /* top bit controls which half of the ROMs to use (Name that Tune only) */
296
 
        if (space->machine->region("maincpu")->bytes() > 0x40000) bank |= (data >> 4) & 8;
 
296
        if (space->machine().region("maincpu")->bytes() > 0x40000) bank |= (data >> 4) & 8;
297
297
 
298
298
        /* when they set the AB bank, it appears as though the CD bank is reset */
299
299
        if (data & 0x20)
300
300
        {
301
 
                memory_set_bank(space->machine, "bank1", bank);
302
 
                memory_set_bank(space->machine, "bank2", 6);
 
301
                memory_set_bank(space->machine(), "bank1", bank);
 
302
                memory_set_bank(space->machine(), "bank2", 6);
303
303
        }
304
304
 
305
305
        /* set both banks */
306
306
        else
307
307
        {
308
 
                memory_set_bank(space->machine, "bank1", bank);
309
 
                memory_set_bank(space->machine, "bank2", bank);
 
308
                memory_set_bank(space->machine(), "bank1", bank);
 
309
                memory_set_bank(space->machine(), "bank2", bank);
310
310
        }
311
311
}
312
312
 
331
331
        }
332
332
        else
333
333
        {
334
 
//      set_led_status(space->machine, offset, data);
 
334
//      set_led_status(space->machine(), offset, data);
335
335
        }
336
336
}
337
337
 
343
343
 *
344
344
 *************************************/
345
345
 
346
 
static void m6850_update_io(running_machine *machine)
 
346
static void m6850_update_io(running_machine &machine)
347
347
{
348
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
348
        balsente_state *state = machine.driver_data<balsente_state>();
349
349
        UINT8 new_state;
350
350
 
351
351
        /* sound -> main CPU communications */
352
 
        if (!(state->m6850_sound_status & 0x02))
 
352
        if (!(state->m_m6850_sound_status & 0x02))
353
353
        {
354
354
                /* set the overrun bit if the data in the destination hasn't been read yet */
355
 
                if (state->m6850_status & 0x01)
356
 
                        state->m6850_status |= 0x20;
 
355
                if (state->m_m6850_status & 0x01)
 
356
                        state->m_m6850_status |= 0x20;
357
357
 
358
358
                /* copy the sound's output to our input */
359
 
                state->m6850_input = state->m6850_sound_output;
 
359
                state->m_m6850_input = state->m_m6850_sound_output;
360
360
 
361
361
                /* set the receive register full bit */
362
 
                state->m6850_status |= 0x01;
 
362
                state->m_m6850_status |= 0x01;
363
363
 
364
364
                /* set the sound's trasmitter register empty bit */
365
 
                state->m6850_sound_status |= 0x02;
 
365
                state->m_m6850_sound_status |= 0x02;
366
366
        }
367
367
 
368
368
        /* main -> sound CPU communications */
369
 
        if (state->m6850_data_ready)
 
369
        if (state->m_m6850_data_ready)
370
370
        {
371
371
                /* set the overrun bit if the data in the destination hasn't been read yet */
372
 
                if (state->m6850_sound_status & 0x01)
373
 
                        state->m6850_sound_status |= 0x20;
 
372
                if (state->m_m6850_sound_status & 0x01)
 
373
                        state->m_m6850_sound_status |= 0x20;
374
374
 
375
375
                /* copy the main CPU's output to our input */
376
 
                state->m6850_sound_input = state->m6850_output;
 
376
                state->m_m6850_sound_input = state->m_m6850_output;
377
377
 
378
378
                /* set the receive register full bit */
379
 
                state->m6850_sound_status |= 0x01;
 
379
                state->m_m6850_sound_status |= 0x01;
380
380
 
381
381
                /* set the main CPU's trasmitter register empty bit */
382
 
                state->m6850_status |= 0x02;
383
 
                state->m6850_data_ready = 0;
 
382
                state->m_m6850_status |= 0x02;
 
383
                state->m_m6850_data_ready = 0;
384
384
        }
385
385
 
386
386
        /* check for reset states */
387
 
        if ((state->m6850_control & 3) == 3)
 
387
        if ((state->m_m6850_control & 3) == 3)
388
388
        {
389
 
                state->m6850_status = 0x02;
390
 
                state->m6850_data_ready = 0;
 
389
                state->m_m6850_status = 0x02;
 
390
                state->m_m6850_data_ready = 0;
391
391
        }
392
 
        if ((state->m6850_sound_control & 3) == 3)
393
 
                state->m6850_sound_status = 0x02;
 
392
        if ((state->m_m6850_sound_control & 3) == 3)
 
393
                state->m_m6850_sound_status = 0x02;
394
394
 
395
395
        /* check for transmit/receive IRQs on the main CPU */
396
396
        new_state = 0;
397
 
        if ((state->m6850_control & 0x80) && (state->m6850_status & 0x21)) new_state = 1;
398
 
        if ((state->m6850_control & 0x60) == 0x20 && (state->m6850_status & 0x02)) new_state = 1;
 
397
        if ((state->m_m6850_control & 0x80) && (state->m_m6850_status & 0x21)) new_state = 1;
 
398
        if ((state->m_m6850_control & 0x60) == 0x20 && (state->m_m6850_status & 0x02)) new_state = 1;
399
399
 
400
400
        /* apply the change */
401
 
        if (new_state && !(state->m6850_status & 0x80))
 
401
        if (new_state && !(state->m_m6850_status & 0x80))
402
402
        {
403
403
                cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, ASSERT_LINE);
404
 
                state->m6850_status |= 0x80;
 
404
                state->m_m6850_status |= 0x80;
405
405
        }
406
 
        else if (!new_state && (state->m6850_status & 0x80))
 
406
        else if (!new_state && (state->m_m6850_status & 0x80))
407
407
        {
408
408
                cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, CLEAR_LINE);
409
 
                state->m6850_status &= ~0x80;
 
409
                state->m_m6850_status &= ~0x80;
410
410
        }
411
411
 
412
412
        /* check for transmit/receive IRQs on the sound CPU */
413
413
        new_state = 0;
414
 
        if ((state->m6850_sound_control & 0x80) && (state->m6850_sound_status & 0x21)) new_state = 1;
415
 
        if ((state->m6850_sound_control & 0x60) == 0x20 && (state->m6850_sound_status & 0x02)) new_state = 1;
416
 
        if (!(state->counter_control & 0x20)) new_state = 0;
 
414
        if ((state->m_m6850_sound_control & 0x80) && (state->m_m6850_sound_status & 0x21)) new_state = 1;
 
415
        if ((state->m_m6850_sound_control & 0x60) == 0x20 && (state->m_m6850_sound_status & 0x02)) new_state = 1;
 
416
        if (!(state->m_counter_control & 0x20)) new_state = 0;
417
417
 
418
418
        /* apply the change */
419
 
        if (new_state && !(state->m6850_sound_status & 0x80))
 
419
        if (new_state && !(state->m_m6850_sound_status & 0x80))
420
420
        {
421
421
                cputag_set_input_line(machine, "audiocpu", INPUT_LINE_NMI, ASSERT_LINE);
422
 
                state->m6850_sound_status |= 0x80;
 
422
                state->m_m6850_sound_status |= 0x80;
423
423
        }
424
 
        else if (!new_state && (state->m6850_sound_status & 0x80))
 
424
        else if (!new_state && (state->m_m6850_sound_status & 0x80))
425
425
        {
426
426
                cputag_set_input_line(machine, "audiocpu", INPUT_LINE_NMI, CLEAR_LINE);
427
 
                state->m6850_sound_status &= ~0x80;
 
427
                state->m_m6850_sound_status &= ~0x80;
428
428
        }
429
429
}
430
430
 
438
438
 
439
439
READ8_HANDLER( balsente_m6850_r )
440
440
{
441
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
441
        balsente_state *state = space->machine().driver_data<balsente_state>();
442
442
        int result;
443
443
 
444
444
        /* status register is at offset 0 */
445
445
        if (offset == 0)
446
446
        {
447
 
                result = state->m6850_status;
 
447
                result = state->m_m6850_status;
448
448
        }
449
449
 
450
450
        /* input register is at offset 1 */
451
451
        else
452
452
        {
453
 
                result = state->m6850_input;
 
453
                result = state->m_m6850_input;
454
454
 
455
455
                /* clear the overrun and receive buffer full bits */
456
 
                state->m6850_status &= ~0x21;
457
 
                m6850_update_io(space->machine);
 
456
                state->m_m6850_status &= ~0x21;
 
457
                m6850_update_io(space->machine());
458
458
        }
459
459
 
460
460
        return result;
463
463
 
464
464
static TIMER_CALLBACK( m6850_data_ready_callback )
465
465
{
466
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
466
        balsente_state *state = machine.driver_data<balsente_state>();
467
467
 
468
468
        /* set the output data byte and indicate that we're ready to go */
469
 
        state->m6850_output = param;
470
 
        state->m6850_data_ready = 1;
 
469
        state->m_m6850_output = param;
 
470
        state->m_m6850_data_ready = 1;
471
471
        m6850_update_io(machine);
472
472
}
473
473
 
474
474
 
475
475
static TIMER_CALLBACK( m6850_w_callback )
476
476
{
477
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
477
        balsente_state *state = machine.driver_data<balsente_state>();
478
478
 
479
479
        /* indicate that the transmit buffer is no longer empty and update the I/O state */
480
 
        state->m6850_status &= ~0x02;
 
480
        state->m_m6850_status &= ~0x02;
481
481
        m6850_update_io(machine);
482
482
 
483
483
        /* set a timer for 500usec later to actually transmit the data */
484
484
        /* (this is very important for several games, esp Snacks'n Jaxson) */
485
 
        timer_set(machine, ATTOTIME_IN_USEC(500), NULL, param, m6850_data_ready_callback);
 
485
        machine.scheduler().timer_set(attotime::from_usec(500), FUNC(m6850_data_ready_callback), param);
486
486
}
487
487
 
488
488
 
489
489
WRITE8_HANDLER( balsente_m6850_w )
490
490
{
491
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
491
        balsente_state *state = space->machine().driver_data<balsente_state>();
492
492
 
493
493
        /* control register is at offset 0 */
494
494
        if (offset == 0)
495
495
        {
496
 
                state->m6850_control = data;
 
496
                state->m_m6850_control = data;
497
497
 
498
498
                /* re-update since interrupt enables could have been modified */
499
 
                m6850_update_io(space->machine);
 
499
                m6850_update_io(space->machine());
500
500
        }
501
501
 
502
502
        /* output register is at offset 1; set a timer to synchronize the CPUs */
503
503
        else
504
 
                timer_call_after_resynch(space->machine, NULL, data, m6850_w_callback);
 
504
                space->machine().scheduler().synchronize(FUNC(m6850_w_callback), data);
505
505
}
506
506
 
507
507
 
514
514
 
515
515
READ8_HANDLER( balsente_m6850_sound_r )
516
516
{
517
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
517
        balsente_state *state = space->machine().driver_data<balsente_state>();
518
518
        int result;
519
519
 
520
520
        /* status register is at offset 0 */
521
521
        if (offset == 0)
522
522
        {
523
 
                result = state->m6850_sound_status;
 
523
                result = state->m_m6850_sound_status;
524
524
        }
525
525
 
526
526
        /* input register is at offset 1 */
527
527
        else
528
528
        {
529
 
                result = state->m6850_sound_input;
 
529
                result = state->m_m6850_sound_input;
530
530
 
531
531
                /* clear the overrun and receive buffer full bits */
532
 
                state->m6850_sound_status &= ~0x21;
533
 
                m6850_update_io(space->machine);
 
532
                state->m_m6850_sound_status &= ~0x21;
 
533
                m6850_update_io(space->machine());
534
534
        }
535
535
 
536
536
        return result;
539
539
 
540
540
WRITE8_HANDLER( balsente_m6850_sound_w )
541
541
{
542
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
542
        balsente_state *state = space->machine().driver_data<balsente_state>();
543
543
 
544
544
        /* control register is at offset 0 */
545
545
        if (offset == 0)
546
 
                state->m6850_sound_control = data;
 
546
                state->m_m6850_sound_control = data;
547
547
 
548
548
        /* output register is at offset 1 */
549
549
        else
550
550
        {
551
 
                state->m6850_sound_output = data;
552
 
                state->m6850_sound_status &= ~0x02;
 
551
                state->m_m6850_sound_output = data;
 
552
                state->m_m6850_sound_status &= ~0x02;
553
553
        }
554
554
 
555
555
        /* re-update since interrupt enables could have been modified */
556
 
        m6850_update_io(space->machine);
 
556
        m6850_update_io(space->machine());
557
557
}
558
558
 
559
559
 
566
566
 
567
567
INTERRUPT_GEN( balsente_update_analog_inputs )
568
568
{
569
 
        balsente_state *state = device->machine->driver_data<balsente_state>();
 
569
        balsente_state *state = device->machine().driver_data<balsente_state>();
570
570
        int i;
571
571
        static const char *const analog[] = { "AN0", "AN1", "AN2", "AN3" };
572
572
 
575
575
        /* ports are read once a frame, just at varying intervals. To get around this, we */
576
576
        /* read all the analog inputs at VBLANK time and just return the cached values. */
577
577
        for (i = 0; i < 4; i++)
578
 
                state->analog_input_data[i] = input_port_read(device->machine, analog[i]);
 
578
                state->m_analog_input_data[i] = input_port_read(device->machine(), analog[i]);
579
579
}
580
580
 
581
581
 
582
582
static TIMER_CALLBACK( adc_finished )
583
583
{
584
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
584
        balsente_state *state = machine.driver_data<balsente_state>();
585
585
        int which = param;
586
586
 
587
587
        /* analog controls are read in two pieces; the lower port returns the sign */
588
588
        /* and the upper port returns the absolute value of the magnitude */
589
 
        int val = state->analog_input_data[which / 2] << state->adc_shift;
 
589
        int val = state->m_analog_input_data[which / 2] << state->m_adc_shift;
590
590
 
591
591
        /* special case for Stompin'/Shrike Avenger */
592
 
        if (state->adc_shift == 32)
 
592
        if (state->m_adc_shift == 32)
593
593
        {
594
 
                state->adc_value = state->analog_input_data[which];
 
594
                state->m_adc_value = state->m_analog_input_data[which];
595
595
                return;
596
596
        }
597
597
 
606
606
 
607
607
        /* return the sign */
608
608
        if (!(which & 1))
609
 
                state->adc_value = (val < 0) ? 0xff : 0x00;
 
609
                state->m_adc_value = (val < 0) ? 0xff : 0x00;
610
610
 
611
611
        /* return the magnitude */
612
612
        else
613
 
                state->adc_value = (val < 0) ? -val : val;
 
613
                state->m_adc_value = (val < 0) ? -val : val;
614
614
}
615
615
 
616
616
 
617
617
READ8_HANDLER( balsente_adc_data_r )
618
618
{
619
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
619
        balsente_state *state = space->machine().driver_data<balsente_state>();
620
620
 
621
621
        /* just return the last value read */
622
 
        return state->adc_value;
 
622
        return state->m_adc_value;
623
623
}
624
624
 
625
625
 
628
628
        /* set a timer to go off and read the value after 50us */
629
629
        /* it's important that we do this for Mini Golf */
630
630
logerror("adc_select %d\n", offset & 7);
631
 
        timer_set(space->machine, ATTOTIME_IN_USEC(50), NULL, offset & 7, adc_finished);
 
631
        space->machine().scheduler().timer_set(attotime::from_usec(50), FUNC(adc_finished), offset & 7);
632
632
}
633
633
 
634
634
 
647
647
        if (which != 0)
648
648
        {
649
649
                /* only start a timer if we're gated and there is none already */
650
 
                if (state->counter[which].gate && !state->counter[which].timer_active)
 
650
                if (state->m_counter[which].gate && !state->m_counter[which].timer_active)
651
651
                {
652
 
                        state->counter[which].timer_active = 1;
653
 
                        state->counter[which].timer->adjust(attotime_mul(ATTOTIME_IN_HZ(2000000), state->counter[which].count), which);
 
652
                        state->m_counter[which].timer_active = 1;
 
653
                        state->m_counter[which].timer->adjust(attotime::from_hz(2000000) * state->m_counter[which].count, which);
654
654
                }
655
655
        }
656
656
}
659
659
INLINE void counter_stop(balsente_state *state, int which)
660
660
{
661
661
        /* only stop the timer if it exists */
662
 
        if (state->counter[which].timer_active)
663
 
                state->counter[which].timer->reset();
664
 
        state->counter[which].timer_active = 0;
 
662
        if (state->m_counter[which].timer_active)
 
663
                state->m_counter[which].timer->reset();
 
664
        state->m_counter[which].timer_active = 0;
665
665
}
666
666
 
667
667
 
668
668
INLINE void counter_update_count(balsente_state *state, int which)
669
669
{
670
670
        /* only update if the timer is running */
671
 
        if (state->counter[which].timer_active)
 
671
        if (state->m_counter[which].timer_active)
672
672
        {
673
673
                /* determine how many 2MHz cycles are remaining */
674
 
                int count = attotime_to_double(attotime_mul(state->counter[which].timer->time_left(), 2000000));
675
 
                state->counter[which].count = (count < 0) ? 0 : count;
 
674
                int count = (state->m_counter[which].timer->time_left() * 2000000).as_double();
 
675
                state->m_counter[which].count = (count < 0) ? 0 : count;
676
676
        }
677
677
}
678
678
 
686
686
 *
687
687
 *************************************/
688
688
 
689
 
static void counter_set_gate(running_machine *machine, int which, int gate)
 
689
static void counter_set_gate(running_machine &machine, int which, int gate)
690
690
{
691
 
        balsente_state *state = machine->driver_data<balsente_state>();
692
 
        int oldgate = state->counter[which].gate;
 
691
        balsente_state *state = machine.driver_data<balsente_state>();
 
692
        int oldgate = state->m_counter[which].gate;
693
693
 
694
694
        /* remember the gate state */
695
 
        state->counter[which].gate = gate;
 
695
        state->m_counter[which].gate = gate;
696
696
 
697
697
        /* if the counter is being halted, update the count and remove the system timer */
698
698
        if (!gate && oldgate)
705
705
        else if (gate && !oldgate)
706
706
        {
707
707
                /* mode 1 waits for the gate to trigger the counter */
708
 
                if (state->counter[which].mode == 1)
 
708
                if (state->m_counter[which].mode == 1)
709
709
                {
710
710
                        counter_set_out(machine, which, 0);
711
711
 
712
712
                        /* add one to the count; technically, OUT goes low on the next clock pulse */
713
713
                        /* and then starts counting down; it's important that we don't count the first one */
714
 
                        state->counter[which].count = state->counter[which].initial + 1;
 
714
                        state->m_counter[which].count = state->m_counter[which].initial + 1;
715
715
                }
716
716
 
717
717
                /* start the counter */
720
720
}
721
721
 
722
722
 
723
 
static void counter_set_out(running_machine *machine, int which, int out)
 
723
static void counter_set_out(running_machine &machine, int which, int out)
724
724
{
725
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
725
        balsente_state *state = machine.driver_data<balsente_state>();
726
726
 
727
727
        /* OUT on counter 2 is hooked to the /INT line on the Z80 */
728
728
        if (which == 2)
733
733
                counter_set_gate(machine, 1, !out);
734
734
 
735
735
        /* remember the out state */
736
 
        state->counter[which].out = out;
 
736
        state->m_counter[which].out = out;
737
737
}
738
738
 
739
739
 
740
740
TIMER_DEVICE_CALLBACK( balsente_counter_callback )
741
741
{
742
 
        balsente_state *state = timer.machine->driver_data<balsente_state>();
 
742
        balsente_state *state = timer.machine().driver_data<balsente_state>();
743
743
 
744
744
        /* reset the counter and the count */
745
 
        state->counter[param].timer_active = 0;
746
 
        state->counter[param].count = 0;
 
745
        state->m_counter[param].timer_active = 0;
 
746
        state->m_counter[param].count = 0;
747
747
 
748
748
        /* set the state of the OUT line */
749
749
        /* mode 0 and 1: when firing, transition OUT to high */
750
 
        if (state->counter[param].mode == 0 || state->counter[param].mode == 1)
751
 
                counter_set_out(timer.machine, param, 1);
 
750
        if (state->m_counter[param].mode == 0 || state->m_counter[param].mode == 1)
 
751
                counter_set_out(timer.machine(), param, 1);
752
752
 
753
753
        /* no other modes handled currently */
754
754
}
765
765
 
766
766
READ8_HANDLER( balsente_counter_8253_r )
767
767
{
768
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
768
        balsente_state *state = space->machine().driver_data<balsente_state>();
769
769
        int which;
770
770
 
771
771
        switch (offset & 3)
780
780
                        counter_update_count(state, which);
781
781
 
782
782
                        /* return the LSB */
783
 
                        if (state->counter[which].readbyte == 0)
 
783
                        if (state->m_counter[which].readbyte == 0)
784
784
                        {
785
 
                                state->counter[which].readbyte = 1;
786
 
                                return state->counter[which].count & 0xff;
 
785
                                state->m_counter[which].readbyte = 1;
 
786
                                return state->m_counter[which].count & 0xff;
787
787
                        }
788
788
 
789
789
                        /* write the MSB and reset the counter */
790
790
                        else
791
791
                        {
792
 
                                state->counter[which].readbyte = 0;
793
 
                                return (state->counter[which].count >> 8) & 0xff;
 
792
                                state->m_counter[which].readbyte = 0;
 
793
                                return (state->m_counter[which].count >> 8) & 0xff;
794
794
                        }
795
795
                        break;
796
796
        }
800
800
 
801
801
WRITE8_HANDLER( balsente_counter_8253_w )
802
802
{
803
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
803
        balsente_state *state = space->machine().driver_data<balsente_state>();
804
804
        int which;
805
805
 
806
806
        switch (offset & 3)
812
812
                        which = offset & 3;
813
813
 
814
814
                        /* if the counter is in mode 0, a write here will reset the OUT state */
815
 
                        if (state->counter[which].mode == 0)
816
 
                                counter_set_out(space->machine, which, 0);
 
815
                        if (state->m_counter[which].mode == 0)
 
816
                                counter_set_out(space->machine(), which, 0);
817
817
 
818
818
                        /* write the LSB */
819
 
                        if (state->counter[which].writebyte == 0)
 
819
                        if (state->m_counter[which].writebyte == 0)
820
820
                        {
821
 
                                state->counter[which].count = (state->counter[which].count & 0xff00) | (data & 0x00ff);
822
 
                                state->counter[which].initial = (state->counter[which].initial & 0xff00) | (data & 0x00ff);
823
 
                                state->counter[which].writebyte = 1;
 
821
                                state->m_counter[which].count = (state->m_counter[which].count & 0xff00) | (data & 0x00ff);
 
822
                                state->m_counter[which].initial = (state->m_counter[which].initial & 0xff00) | (data & 0x00ff);
 
823
                                state->m_counter[which].writebyte = 1;
824
824
                        }
825
825
 
826
826
                        /* write the MSB and reset the counter */
827
827
                        else
828
828
                        {
829
 
                                state->counter[which].count = (state->counter[which].count & 0x00ff) | ((data << 8) & 0xff00);
830
 
                                state->counter[which].initial = (state->counter[which].initial & 0x00ff) | ((data << 8) & 0xff00);
831
 
                                state->counter[which].writebyte = 0;
 
829
                                state->m_counter[which].count = (state->m_counter[which].count & 0x00ff) | ((data << 8) & 0xff00);
 
830
                                state->m_counter[which].initial = (state->m_counter[which].initial & 0x00ff) | ((data << 8) & 0xff00);
 
831
                                state->m_counter[which].writebyte = 0;
832
832
 
833
833
                                /* treat 0 as $10000 */
834
 
                                if (state->counter[which].count == 0) state->counter[which].count = state->counter[which].initial = 0x10000;
 
834
                                if (state->m_counter[which].count == 0) state->m_counter[which].count = state->m_counter[which].initial = 0x10000;
835
835
 
836
836
                                /* remove any old timer and set a new one */
837
837
                                counter_stop(state, which);
838
838
 
839
839
                                /* note that in mode 1, we have to wait for a rising edge of a gate */
840
 
                                if (state->counter[which].mode == 0)
 
840
                                if (state->m_counter[which].mode == 0)
841
841
                                        counter_start(state, which);
842
842
 
843
843
                                /* if the counter is in mode 1, a write here will set the OUT state */
844
 
                                if (state->counter[which].mode == 1)
845
 
                                        counter_set_out(space->machine, which, 1);
 
844
                                if (state->m_counter[which].mode == 1)
 
845
                                        counter_set_out(space->machine(), which, 1);
846
846
                        }
847
847
                        break;
848
848
 
852
852
                        if (which == 3) break;
853
853
 
854
854
                        /* if the counter was in mode 0, a write here will reset the OUT state */
855
 
                        if (((state->counter[which].mode >> 1) & 7) == 0)
856
 
                                counter_set_out(space->machine, which, 0);
 
855
                        if (((state->m_counter[which].mode >> 1) & 7) == 0)
 
856
                                counter_set_out(space->machine(), which, 0);
857
857
 
858
858
                        /* set the mode */
859
 
                        state->counter[which].mode = (data >> 1) & 7;
 
859
                        state->m_counter[which].mode = (data >> 1) & 7;
860
860
 
861
861
                        /* if the counter is in mode 0, a write here will reset the OUT state */
862
 
                        if (state->counter[which].mode == 0)
863
 
                                counter_set_out(space->machine, which, 0);
 
862
                        if (state->m_counter[which].mode == 0)
 
863
                                counter_set_out(space->machine(), which, 0);
864
864
                        break;
865
865
        }
866
866
}
875
875
 
876
876
static void set_counter_0_ff(timer_device &timer, int newstate)
877
877
{
878
 
        balsente_state *state = timer.machine->driver_data<balsente_state>();
 
878
        balsente_state *state = timer.machine().driver_data<balsente_state>();
879
879
 
880
880
        /* the flip/flop output is inverted, so if we went high to low, that's a clock */
881
 
        if (state->counter_0_ff && !newstate)
 
881
        if (state->m_counter_0_ff && !newstate)
882
882
        {
883
883
                /* only count if gated and non-zero */
884
 
                if (state->counter[0].count > 0 && state->counter[0].gate)
 
884
                if (state->m_counter[0].count > 0 && state->m_counter[0].gate)
885
885
                {
886
 
                        state->counter[0].count--;
887
 
                        if (state->counter[0].count == 0)
 
886
                        state->m_counter[0].count--;
 
887
                        if (state->m_counter[0].count == 0)
888
888
                                balsente_counter_callback(timer, NULL, 0);
889
889
                }
890
890
        }
891
891
 
892
892
        /* remember the new state */
893
 
        state->counter_0_ff = newstate;
 
893
        state->m_counter_0_ff = newstate;
894
894
}
895
895
 
896
896
 
897
897
TIMER_DEVICE_CALLBACK( balsente_clock_counter_0_ff )
898
898
{
899
 
        balsente_state *state = timer.machine->driver_data<balsente_state>();
 
899
        balsente_state *state = timer.machine().driver_data<balsente_state>();
900
900
 
901
901
        /* clock the D value through the flip-flop */
902
 
        set_counter_0_ff(timer, (state->counter_control >> 3) & 1);
 
902
        set_counter_0_ff(timer, (state->m_counter_control >> 3) & 1);
903
903
}
904
904
 
905
905
 
909
909
        int i;
910
910
 
911
911
        /* if there's already a timer, remove it */
912
 
        if (state->counter_0_timer_active)
913
 
                state->counter_0_timer->reset();
914
 
        state->counter_0_timer_active = 0;
 
912
        if (state->m_counter_0_timer_active)
 
913
                state->m_counter_0_timer->reset();
 
914
        state->m_counter_0_timer_active = 0;
915
915
 
916
916
        /* find the counter with the maximum frequency */
917
917
        /* this is used to calibrate the timers at startup */
918
918
        for (i = 0; i < 6; i++)
919
 
                if (cem3394_get_parameter(state->cem_device[i], CEM3394_FINAL_GAIN) < 10.0)
 
919
                if (cem3394_get_parameter(state->m_cem_device[i], CEM3394_FINAL_GAIN) < 10.0)
920
920
                {
921
921
                        double tempfreq;
922
922
 
923
923
                        /* if the filter resonance is high, then they're calibrating the filter frequency */
924
 
                        if (cem3394_get_parameter(state->cem_device[i], CEM3394_FILTER_RESONANCE) > 0.9)
925
 
                                tempfreq = cem3394_get_parameter(state->cem_device[i], CEM3394_FILTER_FREQENCY);
 
924
                        if (cem3394_get_parameter(state->m_cem_device[i], CEM3394_FILTER_RESONANCE) > 0.9)
 
925
                                tempfreq = cem3394_get_parameter(state->m_cem_device[i], CEM3394_FILTER_FREQENCY);
926
926
 
927
927
                        /* otherwise, they're calibrating the VCO frequency */
928
928
                        else
929
 
                                tempfreq = cem3394_get_parameter(state->cem_device[i], CEM3394_VCO_FREQUENCY);
 
929
                                tempfreq = cem3394_get_parameter(state->m_cem_device[i], CEM3394_VCO_FREQUENCY);
930
930
 
931
931
                        if (tempfreq > maxfreq) maxfreq = tempfreq;
932
932
                }
934
934
        /* reprime the timer */
935
935
        if (maxfreq > 0.0)
936
936
        {
937
 
                state->counter_0_timer_active = 1;
938
 
                state->counter_0_timer->adjust(ATTOTIME_IN_HZ(maxfreq), 0, ATTOTIME_IN_HZ(maxfreq));
 
937
                state->m_counter_0_timer_active = 1;
 
938
                state->m_counter_0_timer->adjust(attotime::from_hz(maxfreq), 0, attotime::from_hz(maxfreq));
939
939
        }
940
940
}
941
941
 
949
949
 
950
950
READ8_HANDLER( balsente_counter_state_r )
951
951
{
952
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
952
        balsente_state *state = space->machine().driver_data<balsente_state>();
953
953
 
954
954
        /* bit D0 is the inverse of the flip-flop state */
955
 
        int result = !state->counter_0_ff;
 
955
        int result = !state->m_counter_0_ff;
956
956
 
957
957
        /* bit D1 is the OUT value from counter 0 */
958
 
        if (state->counter[0].out) result |= 0x02;
 
958
        if (state->m_counter[0].out) result |= 0x02;
959
959
 
960
960
        return result;
961
961
}
963
963
 
964
964
WRITE8_HANDLER( balsente_counter_control_w )
965
965
{
966
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
967
 
        UINT8 diff_counter_control = state->counter_control ^ data;
 
966
        balsente_state *state = space->machine().driver_data<balsente_state>();
 
967
        UINT8 diff_counter_control = state->m_counter_control ^ data;
968
968
 
969
969
        /* set the new global value */
970
 
        state->counter_control = data;
 
970
        state->m_counter_control = data;
971
971
 
972
972
        /* bit D0 enables/disables audio */
973
973
        if (diff_counter_control & 0x01)
974
974
        {
975
975
                int ch;
976
976
                for (ch = 0; ch < 6; ch++)
977
 
                        sound_set_output_gain(state->cem_device[ch], 0, (data & 0x01) ? 1.0 : 0);
 
977
                        state->m_cem_device[ch]->set_output_gain(0, (data & 0x01) ? 1.0 : 0);
978
978
        }
979
979
 
980
980
        /* bit D1 is hooked to counter 0's gate */
981
981
        /* if we gate on, start a pulsing timer to clock it */
982
 
        if (!state->counter[0].gate && (data & 0x02) && !state->counter_0_timer_active)
 
982
        if (!state->m_counter[0].gate && (data & 0x02) && !state->m_counter_0_timer_active)
983
983
        {
984
984
                update_counter_0_timer(state);
985
985
        }
986
986
 
987
987
        /* if we gate off, remove the timer */
988
 
        else if (state->counter[0].gate && !(data & 0x02) && state->counter_0_timer_active)
 
988
        else if (state->m_counter[0].gate && !(data & 0x02) && state->m_counter_0_timer_active)
989
989
        {
990
 
                state->counter_0_timer->reset();
991
 
                state->counter_0_timer_active = 0;
 
990
                state->m_counter_0_timer->reset();
 
991
                state->m_counter_0_timer_active = 0;
992
992
        }
993
993
 
994
994
        /* set the actual gate afterwards, since we need to know the old value above */
995
 
        counter_set_gate(space->machine, 0, (data >> 1) & 1);
 
995
        counter_set_gate(space->machine(), 0, (data >> 1) & 1);
996
996
 
997
997
        /* bits D2 and D4 control the clear/reset flags on the flip-flop that feeds counter 0 */
998
 
        if (!(data & 0x04)) set_counter_0_ff(*state->counter_0_timer, 1);
999
 
        if (!(data & 0x10)) set_counter_0_ff(*state->counter_0_timer, 0);
 
998
        if (!(data & 0x04)) set_counter_0_ff(*state->m_counter_0_timer, 1);
 
999
        if (!(data & 0x10)) set_counter_0_ff(*state->m_counter_0_timer, 0);
1000
1000
 
1001
1001
        /* bit 5 clears the NMI interrupt; recompute the I/O state now */
1002
 
        m6850_update_io(space->machine);
 
1002
        m6850_update_io(space->machine());
1003
1003
}
1004
1004
 
1005
1005
 
1024
1024
                CEM3394_WAVE_SELECT
1025
1025
        };
1026
1026
 
1027
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
1028
 
        double voltage = (double)state->dac_value * (8.0 / 4096.0) - 4.0;
1029
 
        int diffchip = data ^ state->chip_select, i;
1030
 
        int reg = register_map[state->dac_register];
 
1027
        balsente_state *state = space->machine().driver_data<balsente_state>();
 
1028
        double voltage = (double)state->m_dac_value * (8.0 / 4096.0) - 4.0;
 
1029
        int diffchip = data ^ state->m_chip_select, i;
 
1030
        int reg = register_map[state->m_dac_register];
1031
1031
 
1032
1032
        /* remember the new select value */
1033
 
        state->chip_select = data;
 
1033
        state->m_chip_select = data;
1034
1034
 
1035
1035
        /* check all six chip enables */
1036
1036
        for (i = 0; i < 6; i++)
1042
1042
                        /* remember the previous value */
1043
1043
                        temp =
1044
1044
#endif
1045
 
                                cem3394_get_parameter(state->cem_device[i], reg);
 
1045
                                cem3394_get_parameter(state->m_cem_device[i], reg);
1046
1046
 
1047
1047
                        /* set the voltage */
1048
 
                        cem3394_set_voltage(state->cem_device[i], reg, voltage);
 
1048
                        cem3394_set_voltage(state->m_cem_device[i], reg, voltage);
1049
1049
 
1050
1050
                        /* only log changes */
1051
1051
#if LOG_CEM_WRITES
1052
 
                        if (temp != cem3394_get_parameter(state->cem_device[i], reg))
 
1052
                        if (temp != cem3394_get_parameter(state->m_cem_device[i], reg))
1053
1053
                        {
1054
1054
                                static const char *const names[] =
1055
1055
                                {
1062
1062
                                        "PULSE_WIDTH",
1063
1063
                                        "WAVE_SELECT"
1064
1064
                                };
1065
 
                                logerror("s%04X:   CEM#%d:%s=%f\n", cpu_get_previouspc(space->cpu), i, names[state->dac_register], voltage);
 
1065
                                logerror("s%04X:   CEM#%d:%s=%f\n", cpu_get_previouspc(&space->device()), i, names[state->m_dac_register], voltage);
1066
1066
                        }
1067
1067
#endif
1068
1068
                }
1069
1069
 
1070
1070
        /* if a timer for counter 0 is running, recompute */
1071
 
        if (state->counter_0_timer_active)
 
1071
        if (state->m_counter_0_timer_active)
1072
1072
                update_counter_0_timer(state);
1073
1073
}
1074
1074
 
1076
1076
 
1077
1077
WRITE8_HANDLER( balsente_dac_data_w )
1078
1078
{
1079
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
1079
        balsente_state *state = space->machine().driver_data<balsente_state>();
1080
1080
 
1081
1081
        /* LSB or MSB? */
1082
1082
        if (offset & 1)
1083
 
                state->dac_value = (state->dac_value & 0xfc0) | ((data >> 2) & 0x03f);
 
1083
                state->m_dac_value = (state->m_dac_value & 0xfc0) | ((data >> 2) & 0x03f);
1084
1084
        else
1085
 
                state->dac_value = (state->dac_value & 0x03f) | ((data << 6) & 0xfc0);
 
1085
                state->m_dac_value = (state->m_dac_value & 0x03f) | ((data << 6) & 0xfc0);
1086
1086
 
1087
1087
        /* if there are open channels, force the values in */
1088
 
        if ((state->chip_select & 0x3f) != 0x3f)
 
1088
        if ((state->m_chip_select & 0x3f) != 0x3f)
1089
1089
        {
1090
 
                UINT8 temp = state->chip_select;
 
1090
                UINT8 temp = state->m_chip_select;
1091
1091
                balsente_chip_select_w(space, 0, 0x3f);
1092
1092
                balsente_chip_select_w(space, 0, temp);
1093
1093
        }
1096
1096
 
1097
1097
WRITE8_HANDLER( balsente_register_addr_w )
1098
1098
{
1099
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
1100
 
        state->dac_register = data & 7;
 
1099
        balsente_state *state = space->machine().driver_data<balsente_state>();
 
1100
        state->m_dac_register = data & 7;
1101
1101
}
1102
1102
 
1103
1103
 
1110
1110
 
1111
1111
CUSTOM_INPUT( nstocker_bits_r )
1112
1112
{
1113
 
        balsente_state *state = field->port->machine->driver_data<balsente_state>();
1114
 
        return state->nstocker_bits;
 
1113
        balsente_state *state = field->port->machine().driver_data<balsente_state>();
 
1114
        return state->m_nstocker_bits;
1115
1115
}
1116
1116
 
1117
1117
 
1118
1118
WRITE8_HANDLER( spiker_expand_w )
1119
1119
{
1120
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
1120
        balsente_state *state = space->machine().driver_data<balsente_state>();
1121
1121
 
1122
1122
        /* offset 0 is the bit pattern */
1123
1123
        if (offset == 0)
1124
 
                state->spiker_expand_bits = data;
 
1124
                state->m_spiker_expand_bits = data;
1125
1125
 
1126
1126
        /* offset 1 is the background color (cleared on each read) */
1127
1127
        else if (offset == 1)
1128
 
                state->spiker_expand_bgcolor = data;
 
1128
                state->m_spiker_expand_bgcolor = data;
1129
1129
 
1130
1130
        /* offset 2 is the color */
1131
1131
        else if (offset == 2)
1132
 
                state->spiker_expand_color = data;
 
1132
                state->m_spiker_expand_color = data;
1133
1133
}
1134
1134
 
1135
1135
 
1136
1136
READ8_HANDLER( spiker_expand_r )
1137
1137
{
1138
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
1138
        balsente_state *state = space->machine().driver_data<balsente_state>();
1139
1139
        UINT8 left, right;
1140
1140
 
1141
1141
        /* first rotate each nibble */
1142
 
        state->spiker_expand_bits = ((state->spiker_expand_bits << 1) & 0xee) | ((state->spiker_expand_bits >> 3) & 0x11);
 
1142
        state->m_spiker_expand_bits = ((state->m_spiker_expand_bits << 1) & 0xee) | ((state->m_spiker_expand_bits >> 3) & 0x11);
1143
1143
 
1144
1144
        /* compute left and right pixels */
1145
 
        left  = (state->spiker_expand_bits & 0x10) ? state->spiker_expand_color : state->spiker_expand_bgcolor;
1146
 
        right = (state->spiker_expand_bits & 0x01) ? state->spiker_expand_color : state->spiker_expand_bgcolor;
 
1145
        left  = (state->m_spiker_expand_bits & 0x10) ? state->m_spiker_expand_color : state->m_spiker_expand_bgcolor;
 
1146
        right = (state->m_spiker_expand_bits & 0x01) ? state->m_spiker_expand_color : state->m_spiker_expand_bgcolor;
1147
1147
 
1148
1148
        /* reset the background color */
1149
 
        state->spiker_expand_bgcolor = 0;
 
1149
        state->m_spiker_expand_bgcolor = 0;
1150
1150
 
1151
1151
        /* return the combined result */
1152
1152
        return (left & 0xf0) | (right & 0x0f);
1153
1153
}
1154
1154
 
1155
1155
 
1156
 
static void update_grudge_steering(running_machine *machine)
 
1156
static void update_grudge_steering(running_machine &machine)
1157
1157
{
1158
 
        balsente_state *state = machine->driver_data<balsente_state>();
 
1158
        balsente_state *state = machine.driver_data<balsente_state>();
1159
1159
        UINT8 wheel[3];
1160
1160
        INT8 diff[3];
1161
1161
 
1165
1165
        wheel[2] = input_port_read(machine, "AN2");
1166
1166
 
1167
1167
        /* diff the values */
1168
 
        diff[0] = wheel[0] - state->grudge_last_steering[0];
1169
 
        diff[1] = wheel[1] - state->grudge_last_steering[1];
1170
 
        diff[2] = wheel[2] - state->grudge_last_steering[2];
 
1168
        diff[0] = wheel[0] - state->m_grudge_last_steering[0];
 
1169
        diff[1] = wheel[1] - state->m_grudge_last_steering[1];
 
1170
        diff[2] = wheel[2] - state->m_grudge_last_steering[2];
1171
1171
 
1172
1172
        /* update the last values */
1173
 
        state->grudge_last_steering[0] += diff[0];
1174
 
        state->grudge_last_steering[1] += diff[1];
1175
 
        state->grudge_last_steering[2] += diff[2];
 
1173
        state->m_grudge_last_steering[0] += diff[0];
 
1174
        state->m_grudge_last_steering[1] += diff[1];
 
1175
        state->m_grudge_last_steering[2] += diff[2];
1176
1176
 
1177
1177
        /* compute the result */
1178
 
        state->grudge_steering_result = 0xff;
 
1178
        state->m_grudge_steering_result = 0xff;
1179
1179
        if (diff[0])
1180
1180
        {
1181
 
                state->grudge_steering_result ^= 0x01;
1182
 
                if (diff[0] > 0) state->grudge_steering_result ^= 0x02;
 
1181
                state->m_grudge_steering_result ^= 0x01;
 
1182
                if (diff[0] > 0) state->m_grudge_steering_result ^= 0x02;
1183
1183
        }
1184
1184
        if (diff[1])
1185
1185
        {
1186
 
                state->grudge_steering_result ^= 0x04;
1187
 
                if (diff[1] > 0) state->grudge_steering_result ^= 0x08;
 
1186
                state->m_grudge_steering_result ^= 0x04;
 
1187
                if (diff[1] > 0) state->m_grudge_steering_result ^= 0x08;
1188
1188
        }
1189
1189
        if (diff[2])
1190
1190
        {
1191
 
                state->grudge_steering_result ^= 0x10;
1192
 
                if (diff[2] > 0) state->grudge_steering_result ^= 0x20;
 
1191
                state->m_grudge_steering_result ^= 0x10;
 
1192
                if (diff[2] > 0) state->m_grudge_steering_result ^= 0x20;
1193
1193
        }
1194
1194
        logerror("Recomputed steering\n");
1195
1195
}
1197
1197
 
1198
1198
READ8_HANDLER( grudge_steering_r )
1199
1199
{
1200
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
1201
 
        logerror("%04X:grudge_steering_r(@%d)\n", cpu_get_pc(space->cpu), space->machine->primary_screen->vpos());
1202
 
        state->grudge_steering_result |= 0x80;
1203
 
        return state->grudge_steering_result;
 
1200
        balsente_state *state = space->machine().driver_data<balsente_state>();
 
1201
        logerror("%04X:grudge_steering_r(@%d)\n", cpu_get_pc(&space->device()), space->machine().primary_screen->vpos());
 
1202
        state->m_grudge_steering_result |= 0x80;
 
1203
        return state->m_grudge_steering_result;
1204
1204
}
1205
1205
 
1206
1206
 
1213
1213
 
1214
1214
READ8_HANDLER( shrike_shared_6809_r )
1215
1215
{
1216
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
1216
        balsente_state *state = space->machine().driver_data<balsente_state>();
1217
1217
        UINT16 mem_mask = offset & 1 ? 0xff00 : 0x00ff;
1218
1218
 
1219
1219
        switch( offset )
1221
1221
                case 6: // return OK for 68k status register until motors hooked up
1222
1222
                        return 0;
1223
1223
                default:
1224
 
                        return ( state->shrike_shared[offset >> 1] & ~mem_mask ) >> ( mem_mask & 8 );
 
1224
                        return ( state->m_shrike_shared[offset >> 1] & ~mem_mask ) >> ( mem_mask & 8 );
1225
1225
        }
1226
1226
}
1227
1227
 
1228
1228
 
1229
1229
WRITE8_HANDLER( shrike_shared_6809_w )
1230
1230
{
1231
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
 
1231
        balsente_state *state = space->machine().driver_data<balsente_state>();
1232
1232
        UINT16 mem_mask = offset & 1 ? 0xff00 : 0x00ff;
1233
 
        state->shrike_shared[offset >> 1] = ( state->shrike_shared[offset >> 1] & mem_mask ) | ( data << ( mem_mask & 0x8 ) );
 
1233
        state->m_shrike_shared[offset >> 1] = ( state->m_shrike_shared[offset >> 1] & mem_mask ) | ( data << ( mem_mask & 0x8 ) );
1234
1234
}
1235
1235
 
1236
1236
// uses movep, so writes even 8 bit addresses to odd 16 bit addresses, reads as 16 bit from odd addresses
1237
1237
// i.e. write 0xdeadbeef to 10000, read 0xde from 10001, 0xad from 10003, 0xbe from 10005...
1238
1238
WRITE16_HANDLER( shrike_io_68k_w )
1239
1239
{
1240
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
1241
 
        COMBINE_DATA( &state->shrike_io[offset] );
 
1240
        balsente_state *state = space->machine().driver_data<balsente_state>();
 
1241
        COMBINE_DATA( &state->m_shrike_io[offset] );
1242
1242
}
1243
1243
 
1244
1244
READ16_HANDLER( shrike_io_68k_r )
1245
1245
{
1246
 
        balsente_state *state = space->machine->driver_data<balsente_state>();
1247
 
        return ( state->shrike_io[offset] & mem_mask ) >> ( 8 & ~mem_mask );
 
1246
        balsente_state *state = space->machine().driver_data<balsente_state>();
 
1247
        return ( state->m_shrike_io[offset] & mem_mask ) >> ( 8 & ~mem_mask );
1248
1248
}
1249
1249