summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/electron/cart/abr.cpp
blob: 0c82ca65782b0c403c0ece087c8f7298b3332987 (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/***************************************************************************

    Advanced Battery-Backed RAM

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

#include "emu.h"
#include "abr.h"


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

DEFINE_DEVICE_TYPE(ELECTRON_ABR, electron_abr_device, "electron_abr", "Electron Advanced Battery-Backed RAM cartridge")


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

//-------------------------------------------------
//  electron_abr_device - constructor
//-------------------------------------------------

electron_abr_device::electron_abr_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, ELECTRON_ABR, tag, owner, clock)
	, device_electron_cart_interface(mconfig, *this)
{
}

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

void electron_abr_device::device_start()
{
	m_bank_locked[0] = false;
	m_bank_locked[1] = false;

	// register for save states
	save_item(NAME(m_bank_locked));
}


//-------------------------------------------------
//  read - cartridge data read
//-------------------------------------------------

uint8_t electron_abr_device::read(offs_t offset, int infc, int infd, int romqa, int oe, int oe2)
{
	uint8_t data = 0xff;

	if (oe)
	{
		data = m_nvram[(offset & 0x3fff) | (romqa << 14)];
	}

	return data;
}

//-------------------------------------------------
//  write - cartridge data write
//-------------------------------------------------

void electron_abr_device::write(offs_t offset, uint8_t data, int infc, int infd, int romqa, int oe, int oe2)
{
	if (infc)
	{
		switch (offset & 0xff)
		{
		case 0xdc:
			m_bank_locked[0] = false;
			break;
		case 0xdd:
			m_bank_locked[0] = true;
			break;
		case 0xde:
			m_bank_locked[1] = false;
			break;
		case 0xdf:
			m_bank_locked[1] = true;
			break;
		}
	}
	else if (oe)
	{
		if (!m_bank_locked[romqa])
		{
			m_nvram[(offset & 0x3fff) | (romqa << 14)] = data;
		}
	}
}