summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/lpc-rtc.cpp
blob: e584d96cd6cf142a58c6c542ce96bce5b6fd4045 (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
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
#include "emu.h"
#include "lpc-rtc.h"

DEFINE_DEVICE_TYPE(LPC_RTC, lpc_rtc_device, "lpc_rpc", "LPC RTC")

void lpc_rtc_device::map(address_map &map)
{
	map(0x70, 0x77).rw(FUNC(lpc_rtc_device::index_r), FUNC(lpc_rtc_device::index_w)).umask32(0x00ff00ff);
	map(0x70, 0x77).rw(FUNC(lpc_rtc_device::target_r), FUNC(lpc_rtc_device::target_w)).umask32(0xff00ff00);
}

void lpc_rtc_device::extmap(address_map &map)
{
	map(0x70, 0x77).rw(FUNC(lpc_rtc_device::extindex_r), FUNC(lpc_rtc_device::extindex_w)).umask32(0x00ff0000);
	map(0x70, 0x77).rw(FUNC(lpc_rtc_device::exttarget_r), FUNC(lpc_rtc_device::exttarget_w)).umask32(0xff000000);
}

lpc_rtc_device::lpc_rtc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: lpc_device(mconfig, LPC_RTC, tag, owner, clock), cur_index(0), cur_extindex(0)
{
}

void lpc_rtc_device::map_device(uint64_t memory_window_start, uint64_t memory_window_end, uint64_t memory_offset, address_space *memory_space,
									uint64_t io_window_start, uint64_t io_window_end, uint64_t io_offset, address_space *io_space)
{
	io_space->install_device(io_offset, io_window_end, *this, &lpc_rtc_device::map);
}

void lpc_rtc_device::map_extdevice(uint64_t memory_window_start, uint64_t memory_window_end, uint64_t memory_offset, address_space *memory_space,
									uint64_t io_window_start, uint64_t io_window_end, uint64_t io_offset, address_space *io_space)
{
	io_space->install_device(io_offset, io_window_end, *this, &lpc_rtc_device::extmap);
}

void lpc_rtc_device::device_start()
{
	memset(ram, 0, 256);

	save_item(NAME(cur_index));
	save_item(NAME(cur_extindex));
	save_item(NAME(ram));
}

void lpc_rtc_device::device_reset()
{
}

uint8_t lpc_rtc_device::index_r()
{
	return cur_index;
}

void lpc_rtc_device::index_w(uint8_t data)
{
	cur_index = data & 0x7f;
}

uint8_t lpc_rtc_device::target_r()
{
	return ram[cur_index];
}

void lpc_rtc_device::target_w(uint8_t data)
{
	ram[cur_index] = data;
	logerror("%s: ram[%02x] = %02x\n", tag(), cur_index, data);
}

uint8_t lpc_rtc_device::extindex_r()
{
	return cur_extindex;
}

void lpc_rtc_device::extindex_w(uint8_t data)
{
	cur_extindex = data & 0x7f;
}

uint8_t lpc_rtc_device::exttarget_r()
{
	return ram[cur_extindex|128];
}

void lpc_rtc_device::exttarget_w(uint8_t data)
{
	ram[cur_extindex|128] = data;
	logerror("%s: ram[%02x] = %02x\n", tag(), cur_extindex|128, data);
}