1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     StarPoint Software StarDOS cartridge emulation
6 
7 **********************************************************************/
8 
9 /*
10 
11     PCB Layout
12     ----------
13 
14     |===========================|
15     |=|                         |
16     |=|   LS30                  |
17     |=|               LS157     |
18     |=|          LS00           |
19     |=|   ROM                   |
20     |=|          7407           |
21     |=|                         |
22     |=|                      SW1|
23     |===========================|
24 
25     ROM     - Toshiba TMM271128D-25 16Kx8 EPROM
26 
27 */
28 
29 #include "emu.h"
30 #include "stardos.h"
31 
32 
33 
34 //**************************************************************************
35 //  MACROS/CONSTANTS
36 //**************************************************************************
37 
38 #define IO1_FULL_CHARGE     27
39 #define IO2_FULL_CHARGE     42
40 
41 
42 
43 //**************************************************************************
44 //  DEVICE DEFINITIONS
45 //**************************************************************************
46 
47 DEFINE_DEVICE_TYPE(C64_STARDOS, c64_stardos_cartridge_device, "c64_stardos", "C64 StarDOS cartridge")
48 
49 
50 //-------------------------------------------------
51 //  INPUT_PORTS( c64_stardos )
52 //-------------------------------------------------
53 
INPUT_PORTS_START(c64_stardos)54 static INPUT_PORTS_START( c64_stardos )
55 	PORT_START("RESET")
56 	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)
57 INPUT_PORTS_END
58 
59 
60 //-------------------------------------------------
61 //  input_ports - device-specific input ports
62 //-------------------------------------------------
63 
64 ioport_constructor c64_stardos_cartridge_device::device_input_ports() const
65 {
66 	return INPUT_PORTS_NAME( c64_stardos );
67 }
68 
69 
70 
71 //**************************************************************************
72 //  INLINE HELPERS
73 //**************************************************************************
74 
75 //-------------------------------------------------
76 //  charge_io1_capacitor -
77 //-------------------------------------------------
78 
charge_io1_capacitor()79 inline void c64_stardos_cartridge_device::charge_io1_capacitor()
80 {
81 	m_io1_charge++;
82 
83 	if (m_io1_charge >= IO1_FULL_CHARGE)
84 	{
85 		m_exrom = 0;
86 		m_io1_charge = 0;
87 	}
88 }
89 
90 
91 //-------------------------------------------------
92 //  charge_io2_capacitor -
93 //-------------------------------------------------
94 
charge_io2_capacitor()95 void c64_stardos_cartridge_device::charge_io2_capacitor()
96 {
97 	m_io2_charge++;
98 
99 	if (m_io2_charge >= IO2_FULL_CHARGE)
100 	{
101 		m_exrom = 1;
102 		m_io2_charge = 0;
103 	}
104 }
105 
106 
107 
108 //**************************************************************************
109 //  LIVE DEVICE
110 //**************************************************************************
111 
112 //-------------------------------------------------
113 //  c64_stardos_cartridge_device - constructor
114 //-------------------------------------------------
115 
c64_stardos_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)116 c64_stardos_cartridge_device::c64_stardos_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
117 	device_t(mconfig, C64_STARDOS, tag, owner, clock),
118 	device_c64_expansion_card_interface(mconfig, *this),
119 	m_io1_charge(0),
120 	m_io2_charge(0)
121 {
122 }
123 
124 
125 //-------------------------------------------------
126 //  device_start - device-specific startup
127 //-------------------------------------------------
128 
device_start()129 void c64_stardos_cartridge_device::device_start()
130 {
131 	// state saving
132 	save_item(NAME(m_io1_charge));
133 	save_item(NAME(m_io2_charge));
134 }
135 
136 
137 //-------------------------------------------------
138 //  c64_cd_r - cartridge data read
139 //-------------------------------------------------
140 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)141 uint8_t c64_stardos_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
142 {
143 	if (!roml || !romh)
144 	{
145 		// TODO bitswap<8>(7,6,5,4,3,1,2,0) ?
146 		data = m_roml[offset & 0x3fff];
147 	}
148 	else if (!io1)
149 	{
150 		charge_io1_capacitor();
151 	}
152 	else if (!io2)
153 	{
154 		charge_io2_capacitor();
155 	}
156 
157 	return data;
158 }
159 
160 
161 //-------------------------------------------------
162 //  c64_cd_w - cartridge data write
163 //-------------------------------------------------
164 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)165 void c64_stardos_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
166 {
167 	if (!io1)
168 	{
169 		charge_io1_capacitor();
170 	}
171 	else if (!io2)
172 	{
173 		charge_io2_capacitor();
174 	}
175 }
176 
177 
178 //-------------------------------------------------
179 //  c64_game_r - GAME read
180 //-------------------------------------------------
181 
c64_game_r(offs_t offset,int sphi2,int ba,int rw)182 int c64_stardos_cartridge_device::c64_game_r(offs_t offset, int sphi2, int ba, int rw)
183 {
184 	return !(sphi2 && ba & rw & ((offset & 0xe000) == 0xe000) & m_slot->hiram());
185 }
186 
187 
188 //-------------------------------------------------
189 //  c64_exrom_r - EXROM read
190 //-------------------------------------------------
191 
c64_exrom_r(offs_t offset,int sphi2,int ba,int rw)192 int c64_stardos_cartridge_device::c64_exrom_r(offs_t offset, int sphi2, int ba, int rw)
193 {
194 	return (BIT(offset, 13)) ? 1 : m_exrom;
195 }
196