45
45
static WRITE8_HANDLER( rom_bank_select_w )
47
memory_set_bank(space->machine, "bank1", data & 15);
47
memory_set_bank(space->machine(), "bank1", data & 15);
51
51
static MACHINE_START( crgolf )
53
crgolf_state *state = machine->driver_data<crgolf_state>();
53
crgolf_state *state = machine.driver_data<crgolf_state>();
55
state->maincpu = machine->device("maincpu");
56
state->audiocpu = machine->device("audiocpu");
55
state->m_maincpu = machine.device("maincpu");
56
state->m_audiocpu = machine.device("audiocpu");
58
58
/* configure the banking */
59
memory_configure_bank(machine, "bank1", 0, 16, machine->region("maincpu")->base() + 0x10000, 0x2000);
59
memory_configure_bank(machine, "bank1", 0, 16, machine.region("maincpu")->base() + 0x10000, 0x2000);
60
60
memory_set_bank(machine, "bank1", 0);
62
62
/* register for save states */
63
state_save_register_global(machine, state->port_select);
64
state_save_register_global(machine, state->main_to_sound_data);
65
state_save_register_global(machine, state->sound_to_main_data);
66
state_save_register_global(machine, state->sample_offset);
67
state_save_register_global(machine, state->sample_count);
63
state->save_item(NAME(state->m_port_select));
64
state->save_item(NAME(state->m_main_to_sound_data));
65
state->save_item(NAME(state->m_sound_to_main_data));
66
state->save_item(NAME(state->m_sample_offset));
67
state->save_item(NAME(state->m_sample_count));
71
71
static MACHINE_RESET( crgolf )
73
crgolf_state *state = machine->driver_data<crgolf_state>();
73
crgolf_state *state = machine.driver_data<crgolf_state>();
75
state->port_select = 0;
76
state->main_to_sound_data = 0;
77
state->sound_to_main_data = 0;
78
state->sample_offset = 0;
79
state->sample_count = 0;
75
state->m_port_select = 0;
76
state->m_main_to_sound_data = 0;
77
state->m_sound_to_main_data = 0;
78
state->m_sample_offset = 0;
79
state->m_sample_count = 0;
89
89
static READ8_HANDLER( switch_input_r )
91
91
static const char *const portnames[] = { "IN0", "IN1", "P1", "P2", "DSW", "UNUSED0", "UNUSED1" };
92
crgolf_state *state = space->machine->driver_data<crgolf_state>();
92
crgolf_state *state = space->machine().driver_data<crgolf_state>();
94
return input_port_read(space->machine, portnames[state->port_select]);
94
return input_port_read(space->machine(), portnames[state->m_port_select]);
98
98
static READ8_HANDLER( analog_input_r )
100
return ((input_port_read(space->machine, "STICK0") >> 4) | (input_port_read(space->machine, "STICK1") & 0xf0)) ^ 0x88;
100
return ((input_port_read(space->machine(), "STICK0") >> 4) | (input_port_read(space->machine(), "STICK1") & 0xf0)) ^ 0x88;
104
104
static WRITE8_HANDLER( switch_input_select_w )
106
crgolf_state *state = space->machine->driver_data<crgolf_state>();
106
crgolf_state *state = space->machine().driver_data<crgolf_state>();
108
if (!(data & 0x40)) state->port_select = 6;
109
if (!(data & 0x20)) state->port_select = 5;
110
if (!(data & 0x10)) state->port_select = 4;
111
if (!(data & 0x08)) state->port_select = 3;
112
if (!(data & 0x04)) state->port_select = 2;
113
if (!(data & 0x02)) state->port_select = 1;
114
if (!(data & 0x01)) state->port_select = 0;
108
if (!(data & 0x40)) state->m_port_select = 6;
109
if (!(data & 0x20)) state->m_port_select = 5;
110
if (!(data & 0x10)) state->m_port_select = 4;
111
if (!(data & 0x08)) state->m_port_select = 3;
112
if (!(data & 0x04)) state->m_port_select = 2;
113
if (!(data & 0x02)) state->m_port_select = 1;
114
if (!(data & 0x01)) state->m_port_select = 0;
118
118
static WRITE8_HANDLER( unknown_w )
120
logerror("%04X:unknown_w = %02X\n", cpu_get_pc(space->cpu), data);
120
logerror("%04X:unknown_w = %02X\n", cpu_get_pc(&space->device()), data);
131
131
static TIMER_CALLBACK( main_to_sound_callback )
133
crgolf_state *state = machine->driver_data<crgolf_state>();
133
crgolf_state *state = machine.driver_data<crgolf_state>();
135
cpu_set_input_line(state->audiocpu, INPUT_LINE_NMI, ASSERT_LINE);
136
state->main_to_sound_data = param;
135
device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, ASSERT_LINE);
136
state->m_main_to_sound_data = param;
140
140
static WRITE8_HANDLER( main_to_sound_w )
142
timer_call_after_resynch(space->machine, NULL, data, main_to_sound_callback);
142
space->machine().scheduler().synchronize(FUNC(main_to_sound_callback), data);
146
146
static READ8_HANDLER( main_to_sound_r )
148
crgolf_state *state = space->machine->driver_data<crgolf_state>();
148
crgolf_state *state = space->machine().driver_data<crgolf_state>();
150
cpu_set_input_line(state->audiocpu, INPUT_LINE_NMI, CLEAR_LINE);
151
return state->main_to_sound_data;
150
device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, CLEAR_LINE);
151
return state->m_main_to_sound_data;
162
162
static TIMER_CALLBACK( sound_to_main_callback )
164
crgolf_state *state = machine->driver_data<crgolf_state>();
164
crgolf_state *state = machine.driver_data<crgolf_state>();
166
cpu_set_input_line(state->maincpu, INPUT_LINE_NMI, ASSERT_LINE);
167
state->sound_to_main_data = param;
166
device_set_input_line(state->m_maincpu, INPUT_LINE_NMI, ASSERT_LINE);
167
state->m_sound_to_main_data = param;
171
171
static WRITE8_HANDLER( sound_to_main_w )
173
timer_call_after_resynch(space->machine, NULL, data, sound_to_main_callback);
173
space->machine().scheduler().synchronize(FUNC(sound_to_main_callback), data);
177
177
static READ8_HANDLER( sound_to_main_r )
179
crgolf_state *state = space->machine->driver_data<crgolf_state>();
179
crgolf_state *state = space->machine().driver_data<crgolf_state>();
181
cpu_set_input_line(state->maincpu, INPUT_LINE_NMI, CLEAR_LINE);
182
return state->sound_to_main_data;
181
device_set_input_line(state->m_maincpu, INPUT_LINE_NMI, CLEAR_LINE);
182
return state->m_sound_to_main_data;
193
193
static void vck_callback( device_t *device )
195
crgolf_state *state = device->machine->driver_data<crgolf_state>();
195
crgolf_state *state = device->machine().driver_data<crgolf_state>();
197
197
/* only play back if we have data remaining */
198
if (state->sample_count != 0xff)
198
if (state->m_sample_count != 0xff)
200
UINT8 data = device->machine->region("adpcm")->base()[state->sample_offset >> 1];
200
UINT8 data = device->machine().region("adpcm")->base()[state->m_sample_offset >> 1];
202
202
/* write the next nibble and advance */
203
msm5205_data_w(device, (data >> (4 * (~state->sample_offset & 1))) & 0x0f);
204
state->sample_offset++;
203
msm5205_data_w(device, (data >> (4 * (~state->m_sample_offset & 1))) & 0x0f);
204
state->m_sample_offset++;
206
206
/* every 256 clocks, we decrement the length */
207
if (!(state->sample_offset & 0xff))
207
if (!(state->m_sample_offset & 0xff))
209
state->sample_count--;
209
state->m_sample_count--;
211
211
/* if we hit 0xff, automatically turn off playback */
212
if (state->sample_count == 0xff)
212
if (state->m_sample_count == 0xff)
213
213
msm5205_reset_w(device, 1);
230
230
/* offset 1 is the length/256 nibbles */
232
state->sample_count = data;
232
state->m_sample_count = data;
235
235
/* offset 2 is the offset/256 nibbles */
237
state->sample_offset = data << 8;
237
state->m_sample_offset = data << 8;
240
240
/* offset 3 turns on playback */
253
253
*************************************/
255
static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
255
static ADDRESS_MAP_START( main_map, AS_PROGRAM, 8 )
256
256
AM_RANGE(0x0000, 0x3fff) AM_ROM
257
257
AM_RANGE(0x4000, 0x5fff) AM_RAM
258
258
AM_RANGE(0x6000, 0x7fff) AM_ROMBANK("bank1")
259
AM_RANGE(0x8003, 0x8003) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, color_select)
260
AM_RANGE(0x8004, 0x8004) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, screen_flip)
261
AM_RANGE(0x8005, 0x8005) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, screen_select)
262
AM_RANGE(0x8006, 0x8006) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, screenb_enable)
263
AM_RANGE(0x8007, 0x8007) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, screena_enable)
259
AM_RANGE(0x8003, 0x8003) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, m_color_select)
260
AM_RANGE(0x8004, 0x8004) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, m_screen_flip)
261
AM_RANGE(0x8005, 0x8005) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, m_screen_select)
262
AM_RANGE(0x8006, 0x8006) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, m_screenb_enable)
263
AM_RANGE(0x8007, 0x8007) AM_WRITEONLY AM_BASE_MEMBER(crgolf_state, m_screena_enable)
264
264
AM_RANGE(0x8800, 0x8800) AM_READWRITE(sound_to_main_r, main_to_sound_w)
265
265
AM_RANGE(0x9000, 0x9000) AM_WRITE(rom_bank_select_w)
266
266
AM_RANGE(0xa000, 0xffff) AM_READWRITE(crgolf_videoram_r, crgolf_videoram_w)
275
275
*************************************/
277
static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 8 )
277
static ADDRESS_MAP_START( sound_map, AS_PROGRAM, 8 )
278
278
AM_RANGE(0x0000, 0x7fff) AM_ROM
279
279
AM_RANGE(0x8000, 0x87ff) AM_RAM
280
280
AM_RANGE(0xc000, 0xc001) AM_DEVWRITE("aysnd", ay8910_address_data_w)
600
600
static DRIVER_INIT( crgolfhi )
602
device_t *msm = machine->device("msm");
603
memory_install_write8_device_handler(cputag_get_address_space(machine, "audiocpu", ADDRESS_SPACE_PROGRAM), msm, 0xa000, 0xa003, 0, 0, crgolfhi_sample_w);
602
device_t *msm = machine.device("msm");
603
machine.device("audiocpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(*msm, 0xa000, 0xa003, FUNC(crgolfhi_sample_w));