summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/vectrex/rom.cpp
blob: 273d9d55b4feae64444c2c3727ec8f049694f128 (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
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/***********************************************************************************************************


 GCE Vectrex cart emulation

 TODO:
   - better understand how much SRAM is expected to be present by the homebrew using
     this cart type and use a RAM array instead of the ROM region for writes

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


#include "emu.h"
#include "rom.h"


//-------------------------------------------------
//  vectrex_rom_device - constructor
//-------------------------------------------------

DEFINE_DEVICE_TYPE(VECTREX_ROM_STD,  vectrex_rom_device,    "vectrex_rom",  "Vectrex Standard Carts")
DEFINE_DEVICE_TYPE(VECTREX_ROM_64K,  vectrex_rom64k_device, "vectrex_64k",  "Vectrex Carts w/Bankswitch")
DEFINE_DEVICE_TYPE(VECTREX_ROM_SRAM, vectrex_sram_device,   "vectrex_sram", "Vectrex Carts w/SRAM")


vectrex_rom_device::vectrex_rom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, type, tag, owner, clock), device_vectrex_cart_interface(mconfig, *this)
{
}

vectrex_rom_device::vectrex_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: vectrex_rom_device(mconfig, VECTREX_ROM_STD, tag, owner, clock)
{
}

vectrex_rom64k_device::vectrex_rom64k_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: vectrex_rom_device(mconfig, VECTREX_ROM_64K, tag, owner, clock), m_bank(0)
{
}

vectrex_sram_device::vectrex_sram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: vectrex_rom_device(mconfig, VECTREX_ROM_SRAM, tag, owner, clock)
{
}


void vectrex_rom64k_device::device_start()
{
	save_item(NAME(m_bank));
}

void vectrex_rom64k_device::device_reset()
{
	// Resetting to 1 instead of 0 fixes 64KiB cartridges that don't have a workaround
	// for the fact that MAME does not currently emulate the pull-up resistor on the 6522's PB6 line.
	// TODO: correctly emulate PB6 pull-up behavior (line should be high whenever PB6 set to input).
	m_bank = 1;
}


/*-------------------------------------------------
 mapper specific handlers
 -------------------------------------------------*/

READ8_MEMBER(vectrex_rom_device::read_rom)
{
	if (offset < m_rom_size)
		return m_rom[offset];
	else
		return 0xff;
}


READ8_MEMBER(vectrex_rom64k_device::read_rom)
{
	return m_rom[(offset + m_bank * 0x8000) & (m_rom_size - 1)];
}

void vectrex_rom64k_device::write_bank(uint8_t data)
{
	m_bank = data >> 6;
}

WRITE8_MEMBER(vectrex_sram_device::write_ram)
{
	m_rom[offset & (m_rom_size - 1)] = data;
}