1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Commodore 64 16KB EPROM cartridge emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "16kb.h"
11 
12 
13 
14 //**************************************************************************
15 //  DEVICE DEFINITIONS
16 //**************************************************************************
17 
18 DEFINE_DEVICE_TYPE(C64_16KB, c64_16kb_cartridge_device, "c64_16kb", "C64 16KB EPROM cartridge")
19 
20 
21 //-------------------------------------------------
22 //  device_add_mconfig - add device configuration
23 //-------------------------------------------------
24 
device_add_mconfig(machine_config & config)25 void c64_16kb_cartridge_device::device_add_mconfig(machine_config &config)
26 {
27 	GENERIC_CARTSLOT(config, m_low, generic_linear_slot, nullptr, "rom,bin,80");
28 
29 	GENERIC_CARTSLOT(config, m_high, generic_linear_slot, nullptr, "rom,bin,a0,e0");
30 }
31 
32 
33 //-------------------------------------------------
34 //  INPUT_PORTS( c64_16kb )
35 //-------------------------------------------------
36 
37 static INPUT_PORTS_START( c64_16kb )
38 	PORT_START("SW1")
39 	PORT_DIPNAME( 0x03, 0x00, "Mode" )
40 	PORT_DIPSETTING(    0x03, "Off" )
41 	PORT_DIPSETTING(    0x02, "8 KB" )
42 	PORT_DIPSETTING(    0x00, "16 KB" )
43 	PORT_DIPSETTING(    0x01, "Ultimax" )
44 INPUT_PORTS_END
45 
46 
47 //-------------------------------------------------
48 //  input_ports - device-specific input ports
49 //-------------------------------------------------
50 
device_input_ports() const51 ioport_constructor c64_16kb_cartridge_device::device_input_ports() const
52 {
53 	return INPUT_PORTS_NAME( c64_16kb );
54 }
55 
56 
57 //**************************************************************************
58 //  LIVE DEVICE
59 //**************************************************************************
60 
61 //-------------------------------------------------
62 //  c64_16kb_cartridge_device - constructor
63 //-------------------------------------------------
64 
c64_16kb_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)65 c64_16kb_cartridge_device::c64_16kb_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
66 	device_t(mconfig, C64_16KB, tag, owner, clock),
67 	device_c64_expansion_card_interface(mconfig, *this),
68 	m_sw1(*this, "SW1"),
69 	m_low(*this, "roml"),
70 	m_high(*this, "romh")
71 {
72 }
73 
74 
75 //-------------------------------------------------
76 //  device_start - device-specific startup
77 //-------------------------------------------------
78 
device_start()79 void c64_16kb_cartridge_device::device_start()
80 {
81 }
82 
83 
84 //-------------------------------------------------
85 //  device_reset - device-specific reset
86 //-------------------------------------------------
87 
device_reset()88 void c64_16kb_cartridge_device::device_reset()
89 {
90 	uint8_t mode = m_sw1->read();
91 
92 	m_exrom = BIT(mode, 0);
93 	m_game = BIT(mode, 1);
94 }
95 
96 
97 //-------------------------------------------------
98 //  c64_cd_r - cartridge data read
99 //-------------------------------------------------
100 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)101 uint8_t c64_16kb_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
102 {
103 	if (!roml)
104 	{
105 		data = m_low->read_rom(offset & 0x1fff);
106 	}
107 	else if (!romh)
108 	{
109 		data = m_high->read_rom(offset & 0x1fff);
110 	}
111 
112 	return data;
113 }
114