summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/slapfght.cpp
blob: 6b50153923aaf4caa4b9699eff401e7fa24597e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// license:BSD-3-Clause
// copyright-holders:K.Wilkins,Stephane Humbert
/***************************************************************************

  Toaplan Slap Fight hardware

  Functions to emulate (and simulate) the MCU

***************************************************************************/

#include "emu.h"
#include "includes/slapfght.h"


/**************************************************************************/

READ8_MEMBER(slapfght_state::tigerh_mcu_status_r)
{
	return
			(m_screen->vblank() ? 0x01 : 0x00) |
			((m_bmcu && (CLEAR_LINE == m_bmcu->host_semaphore_r())) ? 0x02 : 0x00) |
			((m_bmcu && (CLEAR_LINE == m_bmcu->mcu_semaphore_r())) ? 0x04 : 0x00);
}

WRITE8_MEMBER(slapfght_state::scroll_from_mcu_w)
{
	switch (offset)
	{
	case 0x01: m_scrollx_lo = data; break;  // PB3
	case 0x02: m_scrollx_hi = data; break;  // PB4
	}
}

/***************************************************************************

    Get Star MCU simulation :(

***************************************************************************/

READ8_MEMBER(slapfght_state::getstar_mcusim_status_r)
{
	static const int states[3]={ 0xc7, 0x55, 0x00 };

	m_getstar_status = states[m_getstar_status_state];

	m_getstar_status_state++;
	if (m_getstar_status_state > 2) m_getstar_status_state = 0;

	return m_getstar_status;
}

READ8_MEMBER(slapfght_state::getstar_mcusim_r)
{
	uint8_t getstar_val = 0;
	uint8_t lives_lookup_table[] = {0x03, 0x05, 0x01, 0x02};                                     /* table at 0x0e62 in 'getstarb1' */
	uint8_t lgsb2_lookup_table[] = {0x00, 0x03, 0x04, 0x05};                                     /* fake tanle for "test mode" in 'getstarb2' */

	switch (m_getstar_id)
	{
		case GETSTARB1:
			/* value isn't computed by the bootleg but we want to please the "test mode" */
			if (m_maincpu->pc() == 0x6b04) return (lives_lookup_table[m_gs_a]);
			break;
		case GETSTARB2:
			/*
			056B: 21 03 E8      ld   hl,$E803
			056E: 7E            ld   a,(hl)
			056F: BE            cp   (hl)
			0570: 28 FD         jr   z,$056F
			0572: C6 05         add  a,$05
			0574: EE 56         xor  $56
			0576: BE            cp   (hl)
			0577: C2 6E 05      jp   nz,$056E
			*/
			if (m_maincpu->pc() == 0x056e) return (getstar_val);
			if (m_maincpu->pc() == 0x0570) return (getstar_val+1);
			if (m_maincpu->pc() == 0x0577) return ((getstar_val+0x05) ^ 0x56);
			/* value isn't computed by the bootleg but we want to please the "test mode" */
			if (m_maincpu->pc() == 0x6b04) return (lgsb2_lookup_table[m_gs_a]);
			break;
		default:
			logerror("%04x: getstar_mcusim_r - cmd = %02x - unknown set !\n",m_maincpu->pc(),m_getstar_cmd);
			break;
	}
	return getstar_val;
}

WRITE8_MEMBER(slapfght_state::getstar_mcusim_w)
{
	/* due to code at 0x108d (GUARDIAN) or 0x1152 (GETSTARJ), register C is a unaltered copy of register A */
	#define GS_SAVE_REGS  m_gs_a = m_maincpu->state_int(Z80_BC) >> 0; \
		m_gs_d = m_maincpu->state_int(Z80_DE) >> 8; \
		m_gs_e = m_maincpu->state_int(Z80_DE) >> 0;

	#define GS_RESET_REGS m_gs_a = 0; \
		m_gs_d = 0; \
		m_gs_e = 0;

	switch (m_getstar_id)
	{
		case GETSTARB1:
			/* "Test mode" doesn't compute the lives value :
			    6ADA: 3E 23         ld   a,$23
			    6ADC: CD 52 11      call $1152
			    6ADF: 32 03 E8      ld   ($E803),a
			    6AE2: DB 00         in   a,($00)
			    6AE4: CB 4F         bit  1,a
			    6AE6: 28 FA         jr   z,$6AE2
			    6AE8: 3A 0A C8      ld   a,($C80A)
			    6AEB: E6 03         and  $03
			    6AED: CD 52 11      call $1152
			    6AF0: 32 03 E8      ld   ($E803),a
			    6AF3: DB 00         in   a,($00)
			    6AF5: CB 57         bit  2,a
			    6AF7: 20 FA         jr   nz,$6AF3
			    6AF9: 00            nop
			    6AFA: 00            nop
			    6AFB: 00            nop
			    6AFC: 00            nop
			    6AFD: 00            nop
			    6AFE: 00            nop
			    6AFF: 00            nop
			    6B00: 00            nop
			    6B01: 3A 03 E8      ld   a,($E803)
			   We save the regs though to hack it in 'getstar_mcusim_r' read handler.
			*/
			if (m_maincpu->pc() == 0x6ae2)
			{
				m_getstar_cmd = 0x00;
				GS_RESET_REGS
			}
			if (m_maincpu->pc() == 0x6af3)
			{
				m_getstar_cmd = 0x00;
				GS_SAVE_REGS
			}
			break;
		case GETSTARB2:
			/* "Test mode" doesn't compute the lives value :
			    6ADA: 3E 23         ld   a,$23
			    6ADC: CD 52 11      call $1152
			    6ADF: 32 03 E8      ld   ($E803),a
			    6AE2: DB 00         in   a,($00)
			    6AE4: CB 4F         bit  1,a
			    6AE6: 00            nop
			    6AE7: 00            nop
			    6AE8: 3A 0A C8      ld   a,($C80A)
			    6AEB: E6 03         and  $03
			    6AED: CD 52 11      call $1152
			    6AF0: 32 03 E8      ld   ($E803),a
			    6AF3: DB 00         in   a,($00)
			    6AF5: CB 57         bit  2,a
			    6AF7: 00            nop
			    6AF8: 00            nop
			    6AF9: 00            nop
			    6AFA: 00            nop
			    6AFB: 00            nop
			    6AFC: 00            nop
			    6AFD: 00            nop
			    6AFE: 00            nop
			    6AFF: 00            nop
			    6B00: 00            nop
			    6B01: 3A 03 E8      ld   a,($E803)
			   We save the regs though to hack it in 'getstar_mcusim_r' read handler.
			*/
			if (m_maincpu->pc() == 0x6ae2)
			{
				m_getstar_cmd = 0x00;
				GS_RESET_REGS
			}
			if (m_maincpu->pc() == 0x6af3)
			{
				m_getstar_cmd = 0x00;
				GS_SAVE_REGS
			}
			break;
		default:
			logerror("%04x: getstar_mcusim_w - data = %02x - unknown set !\n",m_maincpu->pc(),data);
			break;
	}
}



/***************************************************************************

    Protection kludges for some bootleg sets

***************************************************************************/

READ8_MEMBER(slapfght_state::tigerhb1_prot_r)
{
	uint8_t tigerhb_val = 0;
	switch (m_tigerhb_cmd)
	{
		case 0x73:  /* avoid "BAD HW" message */
			tigerhb_val = 0x83;
			break;
		default:
			logerror("%04x: tigerhb1_prot_r - cmd = %02x\n", m_maincpu->pc(), m_getstar_cmd);
			break;
	}
	return tigerhb_val;
}

WRITE8_MEMBER(slapfght_state::tigerhb1_prot_w)
{
	switch (data)
	{
		/* hardware test */
		case 0x73:
			m_tigerhb_cmd = 0x73;
			break;
		default:
			logerror("%04x: tigerhb1_prot_w - data = %02x\n",m_maincpu->pc(),data);
			m_tigerhb_cmd = 0x00;
			break;
	}
}


/**************************************************************************/

READ8_MEMBER(slapfght_state::getstarb1_prot_r)
{
	/* The bootleg has it's own 'protection' on startup ?
	    6D1A: 06 04         ld   b,$04
	    6D1C: DB 00         in   a,($00)
	    6D1E: E6 06         and  $06
	    6D20: 20 FA         jr   nz,$6D1C
	    6D22: DB 00         in   a,($00)
	    6D24: E6 06         and  $06
	    6D26: FE 06         cp   $06
	    6D28: 20 F8         jr   nz,$6D22
	    6D2A: DB 00         in   a,($00)
	    6D2C: E6 06         and  $06
	    6D2E: FE 02         cp   $02
	    6D30: 20 F8         jr   nz,$6D2A
	    6D32: DB 00         in   a,($00)
	    6D34: E6 06         and  $06
	    6D36: FE 04         cp   $04
	    6D38: 20 F8         jr   nz,$6D32
	    6D3A: 10 E0         djnz $6D1C
	*/
	if (m_maincpu->pc() == 0x6d1e) return 0;
	if (m_maincpu->pc() == 0x6d24) return 6;
	if (m_maincpu->pc() == 0x6d2c) return 2;
	if (m_maincpu->pc() == 0x6d34) return 4;

	/* The bootleg hangs in the "test mode" before diplaying (wrong) lives settings :
	    6AD4: DB 00         in   a,($00)
	    6AD6: CB 4F         bit  1,a
	    6AD8: 28 FA         jr   z,$6AD4
	    6ADA: 3E 23         ld   a,$23
	    6ADC: CD 52 11      call $1152
	    6ADF: 32 03 E8      ld   ($E803),a
	    6AE2: DB 00         in   a,($00)
	    6AE4: CB 4F         bit  1,a
	    6AE6: 28 FA         jr   z,$6AE2
	    6AE8: 3A 0A C8      ld   a,($C80A)
	    6AEB: E6 03         and  $03
	    6AED: CD 52 11      call $1152
	    6AF0: 32 03 E8      ld   ($E803),a
	    6AF3: DB 00         in   a,($00)
	    6AF5: CB 57         bit  2,a
	    6AF7: 20 FA         jr   nz,$6AF3
	   This seems to be what used to be the MCU status.
	*/
	if (m_maincpu->pc() == 0x6ad6) return 2; /* bit 1 must be ON */
	if (m_maincpu->pc() == 0x6ae4) return 2; /* bit 1 must be ON */
	if (m_maincpu->pc() == 0x6af5) return 0; /* bit 2 must be OFF */

	logerror("Port Read PC=%04x\n",m_maincpu->pc());

	return 0;
}