summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/drivers/ssystem3.c
blob: ee4a97bc05823d0d873f5fc86f6772ef7e2707c2 (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/******************************************************************************

  ssystem3.c

Driver file to handle emulation of the Chess Champion Super System III / Chess
Champion MK III
by PeT mess@utanet.at November 2000, march 2008

Hardware descriptions:
- A 6502 CPU
- A 6522 VIA ($6000?) (PB6 and PB7 are tied)
- 2 x 2114  1kx4 SRAM to provide 1KB of RAM ($0000)
- 2xXXKB ROM (both connected to the same pins!,
  look into mess source mess/messroms/rddil24.c for notes)
  - signetics 7947e c19081e ss-3-lrom
  - signetics 7945e c19082 ss-3-hrom ($d000??)

optional printer (special serial connection)
optional board display (special serial connection)
internal expansion/cartridge port
 (special power saving pack)


todo:
not sure about lcd signs and their assignments
not sure about all buttons and switches
playfield displayment currently based on simulation and on screen
not check for audio yet
convert to new artwork system

needed:
artwork for board display
backup of playfield rom and picture/description of its board
*/

#include "emu.h"

#include "includes/ssystem3.h"
#include "machine/6522via.h"
#include "cpu/m6502/m6502.h"
#include "sound/dac.h"


// in my opinion own cpu to display lcd field and to handle own buttons
void ssystem3_state::ssystem3_playfield_getfigure(int x, int y, int *figure, int *black)
{
	int d;
	if (x&1)
	d=m_playfield.u.s.field[y][x/2]&0xf;
	else
	d=m_playfield.u.s.field[y][x/2]>>4;

	*figure=d&7;
	*black=d&8;
}

void ssystem3_state::ssystem3_playfield_reset()
{
	memset(&m_playfield, 0, sizeof(m_playfield));
	m_playfield.signal=FALSE;
	//  m_playfield.on=TRUE; //ioport("Configuration")->read()&1;
}

void ssystem3_state::ssystem3_playfield_write(int reset, int signal)
{
	int d=FALSE;

	if (!reset) {
	m_playfield.count=0;
	m_playfield.bit=0;
	m_playfield.started=FALSE;
	m_playfield.signal=signal;
	m_playfield.time=machine().time();
	}
	if (!signal && m_playfield.signal) {
	attotime t=machine().time();
	m_playfield.high_time=t - m_playfield.time;
	m_playfield.time=t;

	//    logerror("%.4x playfield %d lowtime %s hightime %s\n",(int)activecpu_get_pc(), m_playfield.count,
	//       m_playfield.low_time.as_string(7), m_playfield.high_time.as_string(7) );

	if (m_playfield.started) {
		// 0 twice as long low
		// 1 twice as long high
		if (m_playfield.low_time > m_playfield.high_time) d=TRUE;

		m_playfield.data&=~(1<<(m_playfield.bit^7));
		if (d) m_playfield.data|=1<<(m_playfield.bit^7);
		m_playfield.bit++;
		if (m_playfield.bit==8) {
	logerror("%.4x playfield wrote %d %02x\n", (int)machine().device("maincpu")->safe_pc(), m_playfield.count, m_playfield.data);
	m_playfield.u.data[m_playfield.count]=m_playfield.data;
	m_playfield.bit=0;
	m_playfield.count=(m_playfield.count+1)%ARRAY_LENGTH(m_playfield.u.data);
	if (m_playfield.count==0) m_playfield.started=FALSE;
		}
	}

	} else if (signal && !m_playfield.signal) {
	attotime t=machine().time();
	m_playfield.low_time= t - m_playfield.time;
	m_playfield.time=t;
	m_playfield.started=TRUE;
	}
	m_playfield.signal=signal;
}

void ssystem3_state::ssystem3_playfield_read(int *on, int *ready)
{
	*on=!(ioport("Configuration")->read()&1);
	//  *on=!m_playfield.on;
	*ready=FALSE;
}

WRITE8_MEMBER(ssystem3_state::ssystem3_via_write_a)
{
	m_porta=data;
	//  logerror("%.4x via port a write %02x\n",(int)activecpu_get_pc(), data);
}

READ8_MEMBER(ssystem3_state::ssystem3_via_read_a)
{
	UINT8 data=0xff;
#if 1 // time switch
	if (!(m_porta&0x10)) data&=ioport("matrix1")->read()|0xf1;
	if (!(m_porta&0x20)) data&=ioport("matrix2")->read()|0xf1;
	if (!(m_porta&0x40)) data&=ioport("matrix3")->read()|0xf1;
	if (!(m_porta&0x80)) data&=ioport("matrix4")->read()|0xf1;
#else
	if (!(m_porta&0x10)) data&=ioport("matrix1")->read()|0xf0;
	if (!(m_porta&0x20)) data&=ioport("matrix2")->read()|0xf0;
	if (!(m_porta&0x40)) data&=ioport("matrix3")->read()|0xf0;
	if (!(m_porta&0x80)) data&=ioport("matrix4")->read()|0xf0;
#endif
	if (!(m_porta&1)) {
	if (!(ioport("matrix1")->read()&1)) data&=~0x10;
	if (!(ioport("matrix2")->read()&1)) data&=~0x20;
	if (!(ioport("matrix3")->read()&1)) data&=~0x40;
	if (!(ioport("matrix4")->read()&1)) data&=~0x80;
	}
	if (!(m_porta&2)) {
	if (!(ioport("matrix1")->read()&2)) data&=~0x10;
	if (!(ioport("matrix2")->read()&2)) data&=~0x20;
	if (!(ioport("matrix3")->read()&2)) data&=~0x40;
	if (!(ioport("matrix4")->read()&2)) data&=~0x80;
	}
	if (!(m_porta&4)) {
	if (!(ioport("matrix1")->read()&4)) data&=~0x10;
	if (!(ioport("matrix2")->read()&4)) data&=~0x20;
	if (!(ioport("matrix3")->read()&4)) data&=~0x40;
	if (!(ioport("matrix4")->read()&4)) data&=~0x80;
	}
	if (!(m_porta&8)) {
	if (!(ioport("matrix1")->read()&8)) data&=~0x10;
	if (!(ioport("matrix2")->read()&8)) data&=~0x20;
	if (!(ioport("matrix3")->read()&8)) data&=~0x40;
	if (!(ioport("matrix4")->read()&8)) data&=~0x80;
	}
	//  logerror("%.4x via port a read %02x\n",(int)activecpu_get_pc(), data);
	return data;
}


/*
  port b
   bit 0: output opt device reset?

    hi speed serial 1 (d7d7 transfers 40 bit $2e)
   bit 1: output data
   bit 2: output clock (hi data is taken)

   bit 3: output opt data read
   bit 4: input low opt data available
   bit 5: input low opt device available


    bit 6: input clocks!?

  port a:
   bit 7: input low x/$37 2
   bit 6: input low x/$37 3
   bit 5: input low x/$37 4 (else 1)

 */
READ8_MEMBER(ssystem3_state::ssystem3_via_read_b)
{
	UINT8 data=0xff;
	int on, ready;
	ssystem3_playfield_read(&on, &ready);
	if (!on) data&=~0x20;
	if (!ready) data&=~0x10;
	return data;
}

WRITE8_MEMBER(ssystem3_state::ssystem3_via_write_b)
{
	ssystem3_playfield_write(data&1, data&8);
	ssystem3_lcd_write(data&4, data&2);

	// TODO: figure out what this is trying to achieve
	via6522_device *via_0 = machine().device<via6522_device>("via6522_0");
	UINT8 d=ssystem3_via_read_b(space, 0, mem_mask)&~0x40;
	if (data&0x80) d|=0x40;
	//  d&=~0x8f;
	via_0->write_pb0((d>>0)&1);
	via_0->write_pb1((d>>1)&1);
	via_0->write_pb2((d>>2)&1);
	via_0->write_pb3((d>>3)&1);
	via_0->write_pb4((d>>4)&1);
	via_0->write_pb5((d>>5)&1);
	via_0->write_pb6((d>>6)&1);
	via_0->write_pb7((d>>7)&1);
}

DRIVER_INIT_MEMBER(ssystem3_state,ssystem3)
{
	ssystem3_playfield_reset();
	ssystem3_lcd_reset();
}

static ADDRESS_MAP_START( ssystem3_map , AS_PROGRAM, 8, ssystem3_state )
	AM_RANGE( 0x0000, 0x03ff) AM_RAM
					/*
67-de playfield ($40 means white, $80 black)
					*/
//  AM_RANGE( 0x4000, 0x40ff) AM_NOP
/*
  probably zusatzger??t memory (battery powered ram 256x4? at 0x4000)
  $40ff low nibble ram if playfield module (else init with normal playfield)
 */
	AM_RANGE( 0x6000, 0x600f) AM_DEVREADWRITE("via6522_0", via6522_device, read, write)
#if 1
	AM_RANGE( 0xc000, 0xdfff) AM_ROM
	AM_RANGE( 0xf000, 0xffff) AM_ROM
#else
	AM_RANGE( 0xc000, 0xffff) AM_ROM
#endif
ADDRESS_MAP_END

static INPUT_PORTS_START( ssystem3 )
/*
  switches: light(hardware?) sound time power(hardware!)

  new game (hardware?)
*/


	PORT_START( "Switches" )
//PORT_BIT(0x001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("NEW GAME") PORT_CODE(KEYCODE_F3) // seems to be direct wired to reset
//  PORT_BIT(0x002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("?CLEAR") PORT_CODE(KEYCODE_F1)
//  PORT_BIT(0x004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("?ENTER") PORT_CODE(KEYCODE_ENTER)
	PORT_START( "matrix1" )
		PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("?1") PORT_CODE(KEYCODE_1_PAD)
		PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("9   C SQ     EP") PORT_CODE(KEYCODE_9)
		PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("ENTER?") PORT_CODE(KEYCODE_ENTER)
		PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("0   C BOARD  MD") PORT_CODE(KEYCODE_0)
	PORT_START( "matrix2" )
		PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("?2") PORT_CODE(KEYCODE_2_PAD)
		PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("6 F springer zeitvorgabe") PORT_CODE(KEYCODE_6)  PORT_CODE(KEYCODE_F)
		PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("5 E laeufer ruecknahme") PORT_CODE(KEYCODE_5) PORT_CODE(KEYCODE_E)
		PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CE  interrupt") PORT_CODE(KEYCODE_BACKSPACE)
	PORT_START( "matrix3" )
		PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("?3") PORT_CODE(KEYCODE_3_PAD)
		PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("7 G bauer zugvorschlaege") PORT_CODE(KEYCODE_7) PORT_CODE(KEYCODE_G)
		PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("4 D turm #") PORT_CODE(KEYCODE_4) PORT_CODE(KEYCODE_D)
		PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("1 A white") PORT_CODE(KEYCODE_1) PORT_CODE(KEYCODE_A)
	PORT_START( "matrix4" )
		PORT_DIPNAME( 0x01, 0, "Time") PORT_CODE(KEYCODE_T) PORT_TOGGLE PORT_DIPSETTING( 0, DEF_STR(Off) ) PORT_DIPSETTING( 0x01, DEF_STR( On ) )
		PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("8 H black") PORT_CODE(KEYCODE_8) PORT_CODE(KEYCODE_H)
		PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("3 C dame #50") PORT_CODE(KEYCODE_3) PORT_CODE(KEYCODE_C)
		PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("2 B koenig FP") PORT_CODE(KEYCODE_2) PORT_CODE(KEYCODE_B)
	PORT_START( "Configuration" )
		PORT_DIPNAME( 0x0001, 0, "Schachbrett") PORT_TOGGLE
		PORT_DIPSETTING( 0, DEF_STR( Off ) )
		PORT_DIPSETTING( 1, "angeschlossen" )
#if 0
	PORT_DIPNAME( 0x0002, 0, "Memory") PORT_TOGGLE
	PORT_DIPSETTING( 0, DEF_STR( Off ) )
	PORT_DIPSETTING( 2, "angeschlossen" )
	PORT_DIPNAME( 0x0004, 0, "Drucker") PORT_TOGGLE
	PORT_DIPSETTING( 0, DEF_STR( Off ) )
	PORT_DIPSETTING( 4, "angeschlossen" )
#endif
INPUT_PORTS_END



static MACHINE_CONFIG_START( ssystem3, ssystem3_state )
	/* basic machine hardware */
	MCFG_CPU_ADD("maincpu", M6502, 1000000)
	MCFG_CPU_PROGRAM_MAP(ssystem3_map)
	MCFG_QUANTUM_TIME(attotime::from_hz(60))

	/* video hardware */
	MCFG_SCREEN_ADD("screen", LCD)
	MCFG_SCREEN_REFRESH_RATE(LCD_FRAMES_PER_SECOND)
	MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
	MCFG_SCREEN_SIZE(728, 437)
	MCFG_SCREEN_VISIBLE_AREA(0, 728-1, 0, 437-1)
	MCFG_SCREEN_UPDATE_DRIVER(ssystem3_state, screen_update_ssystem3)
	MCFG_SCREEN_PALETTE("palette")

	MCFG_PALETTE_ADD("palette", 242 + 32768)
	MCFG_PALETTE_INIT_OWNER(ssystem3_state, ssystem3)

	/* sound hardware */
	MCFG_SPEAKER_STANDARD_MONO("mono")
	MCFG_SOUND_ADD("dac", DAC, 0)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)

	/* via */
	MCFG_DEVICE_ADD("via6522_0", VIA6522, 0)
	MCFG_VIA6522_READPA_HANDLER(READ8(ssystem3_state,ssystem3_via_read_a))
	MCFG_VIA6522_READPB_HANDLER(READ8(ssystem3_state,ssystem3_via_read_b))
	MCFG_VIA6522_WRITEPA_HANDLER(WRITE8(ssystem3_state,ssystem3_via_write_a))
	MCFG_VIA6522_WRITEPB_HANDLER(WRITE8(ssystem3_state,ssystem3_via_write_b))
MACHINE_CONFIG_END


ROM_START(ssystem3)
	ROM_REGION(0x10000,"maincpu",0)
	ROM_LOAD("ss3lrom", 0xc000, 0x1000, CRC(9ea46ed3) SHA1(34eef85b356efbea6ddac1d1705b104fc8e2731a) )
//  ROM_RELOAD(0xe000, 0x1000)
	ROM_LOAD("ss3hrom", 0xf000, 0x1000, CRC(52741e0b) SHA1(2a7b950f9810c5a14a1b9d5e6b2bd93da621662e) )
	ROM_RELOAD(0xd000, 0x1000)
ROM_END

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

  Game driver(s)

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

/*    YEAR  NAME      PARENT    COMPAT  MACHINE   INPUT     INIT        COMPANY     FULLNAME */
CONS( 1979, ssystem3, 0,        0,      ssystem3, ssystem3, ssystem3_state, ssystem3,   "NOVAG Industries Ltd",  "Chess Champion Super System III", GAME_NOT_WORKING | GAME_NO_SOUND)
//chess champion MK III in germany