38
static UINT8 *decrypt;
39
static int adpcm_data_offs;
40
static int adpcm_data_end;
44
static int coin_mech_latch[2];
45
static int stfight_coin_mech_query_active = 0;
46
static int stfight_coin_mech_query;
50
39
DRIVER_INIT( empcity )
52
address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
53
UINT8 *rom = machine->region("maincpu")->base();
41
stfight_state *state = machine.driver_data<stfight_state>();
42
address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
43
UINT8 *rom = machine.region("maincpu")->base();
56
decrypt = auto_alloc_array(machine, UINT8, 0x8000);
57
space->set_decrypted_region(0x0000, 0x7fff, decrypt);
46
state->m_decrypt = auto_alloc_array(machine, UINT8, 0x8000);
47
space->set_decrypted_region(0x0000, 0x7fff, state->m_decrypt);
59
49
for (A = 0;A < 0x8000;A++)
61
51
UINT8 src = rom[A];
66
56
( ( ( ( src << 2 ) ^ src ) << 3 ) & 0x40 ) |
67
57
( ~( ( src ^ ( A >> 1 ) ) >> 2 ) & 0x10 ) |
81
71
DRIVER_INIT( stfight )
73
stfight_state *state = machine.driver_data<stfight_state>();
83
74
DRIVER_INIT_CALL(empcity);
85
76
/* patch out a tight loop during startup - is the code waiting */
86
77
/* for NMI to wake it up? */
78
state->m_decrypt[0xb1] = 0x00;
79
state->m_decrypt[0xb2] = 0x00;
80
state->m_decrypt[0xb3] = 0x00;
81
state->m_decrypt[0xb4] = 0x00;
82
state->m_decrypt[0xb5] = 0x00;
94
85
MACHINE_RESET( stfight )
96
address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
97
adpcm_data_offs = adpcm_data_end = 0;
100
coin_mech_latch[0] = 0x02;
101
coin_mech_latch[1] = 0x01;
87
stfight_state *state = machine.driver_data<stfight_state>();
88
address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
89
state->m_adpcm_data_offs = state->m_adpcm_data_end = 0;
92
state->m_coin_mech_latch[0] = 0x02;
93
state->m_coin_mech_latch[1] = 0x01;
103
stfight_coin_mech_query_active = 0;
104
stfight_coin_mech_query = 0;
95
state->m_coin_mech_query_active = 0;
96
state->m_coin_mech_query = 0;
106
98
// initialise rom bank
107
99
stfight_bank_w( space, 0, 0 );
111
103
// - in fact I don't even know how/where it's switched in!
112
104
static WRITE8_HANDLER( stfight_bank_w )
114
UINT8 *ROM2 = space->machine->region("maincpu")->base() + 0x10000;
106
UINT8 *ROM2 = space->machine().region("maincpu")->base() + 0x10000;
116
memory_set_bankptr(space->machine, "bank1", &ROM2[data<<14] );
108
memory_set_bankptr(space->machine(), "bank1", &ROM2[data<<14] );
129
121
INTERRUPT_GEN( stfight_vb_interrupt )
132
cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0xd7);
133
timer_set(device->machine, ATTOTIME_IN_HZ(120), NULL, 0, stfight_interrupt_1);
124
device_set_input_line_and_vector(device, 0, HOLD_LINE, 0xd7);
125
device->machine().scheduler().timer_set(attotime::from_hz(120), FUNC(stfight_interrupt_1));
140
132
// Perhaps define dipswitches as active low?
141
133
READ8_HANDLER( stfight_dsw_r )
143
return( ~input_port_read(space->machine, offset ? "DSW1" : "DSW0") );
135
return( ~input_port_read(space->machine(), offset ? "DSW1" : "DSW0") );
146
138
READ8_HANDLER( stfight_coin_r )
140
stfight_state *state = space->machine().driver_data<stfight_state>();
148
141
int coin_mech_data;
151
144
// Was the coin mech queried by software?
152
if( stfight_coin_mech_query_active )
145
if( state->m_coin_mech_query_active )
154
stfight_coin_mech_query_active = 0;
155
return( (~stfight_coin_mech_query) & 0x03 );
147
state->m_coin_mech_query_active = 0;
148
return( (~state->m_coin_mech_query) & 0x03 );
162
155
* since it's read by the 30Hz interrupt ISR
165
coin_mech_data = input_port_read(space->machine, "COIN");
158
coin_mech_data = input_port_read(space->machine(), "COIN");
167
160
for( i=0; i<2; i++ )
169
162
/* Only valid on signal edge */
170
if( ( coin_mech_data & (1<<i) ) != coin_mech_latch[i] )
171
coin_mech_latch[i] = coin_mech_data & (1<<i);
163
if( ( coin_mech_data & (1<<i) ) != state->m_coin_mech_latch[i] )
164
state->m_coin_mech_latch[i] = coin_mech_data & (1<<i);
173
166
coin_mech_data |= coin_mech_data & (1<<i);
179
172
WRITE8_HANDLER( stfight_coin_w )
174
stfight_state *state = space->machine().driver_data<stfight_state>();
181
175
// interrogate coin mech
182
stfight_coin_mech_query_active = 1;
183
stfight_coin_mech_query = data;
176
state->m_coin_mech_query_active = 1;
177
state->m_coin_mech_query = data;
200
194
void stfight_adpcm_int(device_t *device)
202
UINT8 *SAMPLES = device->machine->region("adpcm")->base();
203
int adpcm_data = SAMPLES[adpcm_data_offs & 0x7fff];
196
stfight_state *state = device->machine().driver_data<stfight_state>();
197
UINT8 *SAMPLES = device->machine().region("adpcm")->base();
198
int adpcm_data = SAMPLES[state->m_adpcm_data_offs & 0x7fff];
205
200
// finished playing sample?
206
if( adpcm_data_offs == adpcm_data_end )
201
if( state->m_adpcm_data_offs == state->m_adpcm_data_end )
208
203
msm5205_reset_w( device, 1 );
207
if( state->m_toggle == 0 )
213
208
msm5205_data_w( device, ( adpcm_data >> 4 ) & 0x0f );
216
211
msm5205_data_w( device, adpcm_data & 0x0f );
212
state->m_adpcm_data_offs++;
215
state->m_toggle ^= 1;
223
218
WRITE8_DEVICE_HANDLER( stfight_adpcm_control_w )
220
stfight_state *state = device->machine().driver_data<stfight_state>();
225
221
if( data < 0x08 )
227
adpcm_data_offs = sampleLimits[data];
228
adpcm_data_end = sampleLimits[data+1];
223
state->m_adpcm_data_offs = sampleLimits[data];
224
state->m_adpcm_data_end = sampleLimits[data+1];
231
227
msm5205_reset_w( device, data & 0x08 ? 1 : 0 );
242
238
WRITE8_HANDLER( stfight_fm_w )
240
stfight_state *state = space->machine().driver_data<stfight_state>();
244
241
// the sound cpu ignores any fm data without bit 7 set
245
fm_data = 0x80 | data;
242
state->m_fm_data = 0x80 | data;
248
245
READ8_HANDLER( stfight_fm_r )
247
stfight_state *state = space->machine().driver_data<stfight_state>();
248
int data = state->m_fm_data;
252
250
// clear the latch?!?
251
state->m_fm_data &= 0x7f;