summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/msx_slot/panasonic08.cpp
blob: 046309825318e04a65ab075f92ac5d88162a436f (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
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol
/*

  Emulation of the firmware mapper as found in Panasonic FS-A1WX andFS-A1WSX machines.

Todo:
- Anything besides the basic mapping
- SRAM?
*/

#include "emu.h"
#include "panasonic08.h"


DEFINE_DEVICE_TYPE(MSX_SLOT_PANASONIC08, msx_slot_panasonic08_device, "msx_slot_panasonic08", "MSX Internal Panasonic08")


msx_slot_panasonic08_device::msx_slot_panasonic08_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, MSX_SLOT_PANASONIC08, tag, owner, clock)
	, msx_internal_slot_interface()
	, m_nvram(*this, "nvram")
	, m_rom_region(*this, finder_base::DUMMY_TAG)
	, m_region_offset(0)
	, m_rom(nullptr)
	, m_control(0)
{
	for (int i = 0; i < 8; i++)
	{
		m_selected_bank[i] = 0;
		m_bank_base[i] = nullptr;
	}
}


MACHINE_CONFIG_START(msx_slot_panasonic08_device::device_add_mconfig)
	MCFG_NVRAM_ADD_0FILL("nvram")
MACHINE_CONFIG_END


void msx_slot_panasonic08_device::device_start()
{
	// Sanity checks
	if (m_rom_region->bytes() < m_region_offset + 0x200000)
	{
		fatalerror("Memory region '%s' is too small for the FS4600 firmware\n", m_rom_region.finder_tag());
	}

	m_sram.resize(0x4000);

	m_nvram->set_base(&m_sram[0], 0x4000);

	m_rom = m_rom_region->base() + m_region_offset;

	save_item(NAME(m_selected_bank));
	save_item(NAME(m_control));

	machine().save().register_postload(save_prepost_delegate(FUNC(msx_slot_panasonic08_device::restore_banks), this));

	restore_banks();
}


void msx_slot_panasonic08_device::map_bank(int bank)
{
	if (m_selected_bank[bank] >= 0x80 && m_selected_bank[bank] < 0x84)   // Are these banks were sram is present? Mirroring?
	{
		logerror("panasonic08: mapping bank %d to sram\n", bank);
		m_bank_base[bank] = &m_sram[((m_selected_bank[bank] & 0x7f) * 0x2000) & 0x3fff];
	}
	else
	{
		m_bank_base[bank] = m_rom + ( ( m_selected_bank[bank] * 0x2000 ) & 0x1fffff );
	}
}


void msx_slot_panasonic08_device::restore_banks()
{
	for (int i = 0; i < 8; i++)
	{
		map_bank(i);
	}
}


READ8_MEMBER(msx_slot_panasonic08_device::read)
{
	if (m_control & 0x04)
	{
		// 7ff0 - 6000
		// 7ff1 - 6400
		// 7ff2 - 6800
		// 7ff3 - 6c00
		// 7ff4 - 7000
		// 7ff5 - 7800
		if (offset >= 0x7ff0 && offset < 0x7ff6)     // maybe 7ff8 would make more sense here??
		{
			return m_selected_bank[offset - 0x7ff0];
		}
	}
	return m_bank_base[offset >> 13][offset & 0x1fff];
}


WRITE8_MEMBER(msx_slot_panasonic08_device::write)
{
	if ((offset & 0xc000) == 0x8000 || (offset & 0xc000) == 0x0000)
	{
		uint8_t bank = m_selected_bank[offset >> 13];
		if (bank >= 0x80 && bank < 0x84)   // Are these banks were sram is present? Mirroring?
		{
			logerror("msx_slot_panasonic08: writing %02x to sram %04x, bank = %02x\n", data, offset & 0x1fff, bank);
			m_sram[((bank & 0x01) * 0x2000) + (offset & 0x1fff)] = data;
		}
		return;
	}

	switch (offset)
	{
		case 0x6000:    /* Switched 0x0000-0x1FFF */
			m_selected_bank[0] = data;
			map_bank(0);
			break;

		case 0x6400:    /* Switches 0x2000-0x3FFF */
			m_selected_bank[1] = data;
			map_bank(1);
			break;

		case 0x6800:    /* Switches 0x4000-0x5FFF */
			m_selected_bank[2] = data;
			map_bank(2);
			break;

		case 0x6c00:    /* Switches 0x6000-0x7FFF */
			m_selected_bank[3] = data;
			map_bank(3);
			break;

		case 0x7000:    /* Switches 0x8000-0x9FFF */
			m_selected_bank[4] = data;
			map_bank(4);
			break;

		case 0x7800:    /* Switches 0xA000-0xBFFF */
			m_selected_bank[5] = data;
			map_bank(5);
			break;

		case 0x7ff9:
			m_control = data;
			break;

		default:
			logerror("msx_slot_panasonic08: Unhandled write %02x to %04x\n", data, offset);
			break;
	}
}