summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/samcoupe/drive/atom.cpp
blob: 3755463e3072360911816076c9760faea2cb2fc5 (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
// license: GPL-2.0+
// copyright-holders: Dirk Best
/***************************************************************************

    ATOM hard disk interface for SAM Coupe

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

#include "emu.h"
#include "atom.h"


//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(SAM_ATOM_HDD, sam_atom_hdd_device, "sam_atom_hdd", "SAM Coupe ATOM HDD interface")

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void sam_atom_hdd_device::device_add_mconfig(machine_config &config)
{
	ATA_INTERFACE(config, m_ata).options(ata_devices, nullptr, nullptr, false);
}


//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  sam_atom_hdd_device - constructor
//-------------------------------------------------

sam_atom_hdd_device::sam_atom_hdd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, SAM_ATOM_HDD, tag, owner, clock),
	device_samcoupe_drive_interface(mconfig, *this),
	m_ata(*this, "ata"),
	m_address_latch(0),
	m_read_latch(0x00), m_write_latch(0x00)
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void sam_atom_hdd_device::device_start()
{
}


//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

uint8_t sam_atom_hdd_device::read(offs_t offset)
{
	uint8_t data = 0xff;

	switch (offset)
	{
		// high byte
		case 0x06:
			if (BIT(m_address_latch, 5))
			{
				uint16_t result = 0;

				if (BIT(m_address_latch, 3) == 0)
					result = m_ata->cs0_r(m_address_latch & 0x07);
				if (BIT(m_address_latch, 4) == 0)
					result = m_ata->cs1_r(m_address_latch & 0x07);

				m_read_latch = result;
				data = result >> 8;
			}
			break;

		// low byte
		case 0x07:
			data = m_read_latch;
			break;
	}

	return data;
}

void sam_atom_hdd_device::write(offs_t offset, uint8_t data)
{
	switch (offset)
	{
		// control
		case 0x05:
			if (BIT(data, 5))
				m_address_latch = data;
			break;

		// high byte
		case 0x06:
			m_write_latch = data;
			break;

		// low byte
		case 0x07:
			if (BIT(m_address_latch, 5))
			{
				if (BIT(m_address_latch, 3) == 0)
					m_ata->cs0_w(m_address_latch & 0x07, (m_write_latch << 8) | data);
				if (BIT(m_address_latch, 4) == 0)
					m_ata->cs1_w(m_address_latch & 0x07, (m_write_latch << 8) | data);
			}
			break;
	}
}