summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a2bus/booti.cpp
blob: 734282e7302ebc59627a87324c25367128992c6d (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
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/*********************************************************************

    booti.cpp

    Implementation of the BOOTI card

    The BOOTI is an Apple II interface to the CH376 USB module.
    The CH376 is intended for use with small microcontrollers (or,
    you know, the 6502) to give them access to FAT-formatted
    flash drives.  See ch376.cpp for details.

    C0n0: read/write data to CH376
    C0n1: read status/write command to CH376
    C0n4: $C800 ROM bank (0-3)

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

#include "emu.h"
#include "booti.h"

#include "machine/at28c64b.h"
#include "machine/ch376.h"


namespace {

/***************************************************************************
    PARAMETERS
***************************************************************************/

ROM_START( booti )
	ROM_REGION(0x2000, "flash", 0)
	ROM_LOAD( "bootifw09l.bin", 0x000000, 0x002000, CRC(be3f21ff) SHA1(f505ad4685cd44e4cce5b8d6d27b9c4fea159f11) )
ROM_END

//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

class a2bus_booti_device:
	public device_t,
	public device_a2bus_card_interface
{
public:
	// construction/destruction
	a2bus_booti_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);

protected:
	a2bus_booti_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, const XTAL &clock);

	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual const tiny_rom_entry *device_rom_region() const override;

	// overrides of standard a2bus slot functions
	virtual uint8_t read_c0nx(uint8_t offset) override;
	virtual void write_c0nx(uint8_t offset, uint8_t data) override;
	virtual uint8_t read_cnxx(uint8_t offset) override;
	virtual void write_cnxx(uint8_t offset, uint8_t data) override;
	virtual uint8_t read_c800(uint16_t offset) override;
	virtual void write_c800(uint16_t offset, uint8_t data) override;

private:
	required_device<at28c64b_device> m_flash;
	required_device<ch376_device> m_ch376;

	int m_rombank;
};

/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/

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

void a2bus_booti_device::device_add_mconfig(machine_config &config)
{
	AT28C64B(config, "flash");

	CH376(config, "ch376");
}

//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

const tiny_rom_entry *a2bus_booti_device::device_rom_region() const
{
	return ROM_NAME( booti );
}

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

a2bus_booti_device::a2bus_booti_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, const XTAL &clock) :
	device_t(mconfig, type, tag, owner, clock),
	device_a2bus_card_interface(mconfig, *this),
	m_flash(*this, "flash"),
	m_ch376(*this, "ch376"),
	m_rombank(0)
{
}

a2bus_booti_device::a2bus_booti_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock) :
	a2bus_booti_device(mconfig, A2BUS_BOOTI, tag, owner, clock)
{
}

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

void a2bus_booti_device::device_start()
{
	save_item(NAME(m_rombank));
}

void a2bus_booti_device::device_reset()
{
	m_rombank = 0;
}


/*-------------------------------------------------
    read_c0nx - called for reads from this card's c0nx space
-------------------------------------------------*/

uint8_t a2bus_booti_device::read_c0nx(uint8_t offset)
{
	switch (offset)
	{
		case 0:
		case 1:
			return m_ch376->read(offset);

		case 4:
			return m_rombank / 0x800;
	}
	return 0xff;
}


/*-------------------------------------------------
    write_c0nx - called for writes to this card's c0nx space
-------------------------------------------------*/

void a2bus_booti_device::write_c0nx(uint8_t offset, uint8_t data)
{
	switch (offset)
	{
		case 0:
		case 1:
			m_ch376->write(offset, data);
			break;

		case 4:
			m_rombank = 0x800 * (data & 3);
			break;

		default:
			printf("Write %02x to c0n%x (%s)\n", data, offset, machine().describe_context().c_str());
			break;
	}
}

/*-------------------------------------------------
    read_cnxx - called for reads from this card's cnxx space
-------------------------------------------------*/

uint8_t a2bus_booti_device::read_cnxx(uint8_t offset)
{
	// slot image at 0
	return m_flash->read(offset);
}

void a2bus_booti_device::write_cnxx(uint8_t offset, uint8_t data)
{
}

/*-------------------------------------------------
    read_c800 - called for reads from this card's c800 space
-------------------------------------------------*/

uint8_t a2bus_booti_device::read_c800(uint16_t offset)
{
	return m_flash->read(offset + m_rombank);
}

/*-------------------------------------------------
    write_c800 - called for writes to this card's c800 space
-------------------------------------------------*/
void a2bus_booti_device::write_c800(uint16_t offset, uint8_t data)
{
	// the card appears not to pass writes to $CFFF to the EEPROM,
	// otherwise there's a false read of the next opcode after a $CFFF write and we crash.
	if (offset < 0x7ff)
	{
		m_flash->write(offset + m_rombank, data);
	}
}

} // anonymous namespace


//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

DEFINE_DEVICE_TYPE_PRIVATE(A2BUS_BOOTI, device_a2bus_card_interface, a2bus_booti_device, "a2booti", "Booti Card")