1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Access Software MACH 5 cartridge emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "mach5.h"
11 
12 
13 
14 //**************************************************************************
15 //  DEVICE DEFINITIONS
16 //**************************************************************************
17 
18 DEFINE_DEVICE_TYPE(C64_MACH5, c64_mach5_cartridge_device, "c64_mach5", "C64 MACH5 cartridge")
19 
20 
21 //-------------------------------------------------
22 //  INPUT_PORTS( c64_mach5 )
23 //-------------------------------------------------
24 
INPUT_PORTS_START(c64_mach5)25 static INPUT_PORTS_START( c64_mach5 )
26 	PORT_START("S1")
27 	PORT_DIPNAME( 0x01, 0x00, "Mode" )
28 	PORT_DIPSETTING(    0x00, "C64" )
29 	PORT_DIPSETTING(    0x01, "C128" )
30 
31 	PORT_START("S2")
32 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Reset") PORT_CODE(KEYCODE_F11) PORT_WRITE_LINE_DEVICE_MEMBER(DEVICE_SELF_OWNER, c64_expansion_slot_device, reset_w)
33 INPUT_PORTS_END
34 
35 
36 //-------------------------------------------------
37 //  input_ports - device-specific input ports
38 //-------------------------------------------------
39 
40 ioport_constructor c64_mach5_cartridge_device::device_input_ports() const
41 {
42 	return INPUT_PORTS_NAME( c64_mach5 );
43 }
44 
45 
46 
47 //**************************************************************************
48 //  LIVE DEVICE
49 //**************************************************************************
50 
51 //-------------------------------------------------
52 //  c64_mach5_cartridge_device - constructor
53 //-------------------------------------------------
54 
c64_mach5_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)55 c64_mach5_cartridge_device::c64_mach5_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
56 	device_t(mconfig, C64_MACH5, tag, owner, clock),
57 	device_c64_expansion_card_interface(mconfig, *this),
58 	m_s1(*this, "S1"), m_c128(false)
59 {
60 }
61 
62 
63 //-------------------------------------------------
64 //  device_start - device-specific startup
65 //-------------------------------------------------
66 
device_start()67 void c64_mach5_cartridge_device::device_start()
68 {
69 }
70 
71 
72 //-------------------------------------------------
73 //  device_reset - device-specific reset
74 //-------------------------------------------------
75 
device_reset()76 void c64_mach5_cartridge_device::device_reset()
77 {
78 	m_c128 = m_s1->read();
79 
80 	if (!m_c128)
81 	{
82 		m_exrom = 0;
83 	}
84 }
85 
86 
87 //-------------------------------------------------
88 //  c64_cd_r - cartridge data read
89 //-------------------------------------------------
90 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)91 uint8_t c64_mach5_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
92 {
93 	if (!roml || !romh || !io1 || !io2)
94 	{
95 		data = m_roml[offset & 0x1fff];
96 	}
97 
98 	return data;
99 }
100 
101 
102 //-------------------------------------------------
103 //  c64_cd_w - cartridge data write
104 //-------------------------------------------------
105 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)106 void c64_mach5_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
107 {
108 	if (!m_c128)
109 	{
110 		if (!io1)
111 		{
112 			m_exrom = 0;
113 		}
114 		else if (!io2)
115 		{
116 			m_exrom = 1;
117 		}
118 	}
119 }
120