summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/wpc_lamp.cpp
blob: d40bc033b03ea0ca9c55ef55ab0accc5777e1cb9 (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
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert

#include "emu.h"
#include "wpc_lamp.h"

const device_type WPC_LAMP = device_creator<wpc_lamp_device>;

wpc_lamp_device::wpc_lamp_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, WPC_LAMP, "Williams Pinball Controller Lamp Control", tag, owner, clock, "wpc_lamp", __FILE__)
{
	names = nullptr;
}

wpc_lamp_device::~wpc_lamp_device()
{
}

void wpc_lamp_device::set_names(const char *const *_names)
{
	names = _names;
}

void wpc_lamp_device::update()
{
	for(int i=0; i<8; i++)
		if(row & (1 << i))
			for(int j=0; j<8; j++)
				if(col & (1 << j))
					state[(j<<3)|i] |= 0x80;
}

WRITE8_MEMBER(wpc_lamp_device::row_w)
{
	row = data;
	update();
}

WRITE8_MEMBER(wpc_lamp_device::col_w)
{
	col = data;
	update();
}

void wpc_lamp_device::device_start()
{
	save_item(NAME(state));
	save_item(NAME(col));
	save_item(NAME(row));

	timer = timer_alloc(0);
}

void wpc_lamp_device::device_reset()
{
	memset(state, 0x00, 64);
	timer->adjust(attotime::from_hz(60), 0, attotime::from_hz(60));
}

void wpc_lamp_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	for(int i=0; i<64; i++) {
		uint8_t s = state[i];
		state[i] = s >> 1;
		if((s & 0xc0) == 0x40 || (s & 0xc0) == 0x80) {
			char buffer[256];
			if(names && names[i])
				sprintf(buffer, "l:%s", names[i]);
			else
				sprintf(buffer, "l:%d%d", 1+(i >> 3), 1 + (i & 7));
			machine().output().set_value(buffer, (s & 0xc0) == 0x80);
		}
	}
}