1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Super Explode! cartridge emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "super_explode.h"
11 
12 
13 
14 //**************************************************************************
15 //  MACROS/CONSTANTS
16 //**************************************************************************
17 
18 // t = R*C = 3.3K * 0.47uF * 40% Vtr = 792.2905424610516 usec
19 // (3.3K pull-up on the EXROM line inside the C64, PLA Vih min = 2.0V = 40% of 5.0V)
20 #define TIMER_PERIOD    792
21 
22 
23 
24 //**************************************************************************
25 //  DEVICE DEFINITIONS
26 //**************************************************************************
27 
28 DEFINE_DEVICE_TYPE(C64_SUPER_EXPLODE, c64_super_explode_cartridge_device, "c64_super_explode", "C64 Super Explode! cartridge")
29 
30 
31 
32 //**************************************************************************
33 //  LIVE DEVICE
34 //**************************************************************************
35 
36 //-------------------------------------------------
37 //  c64_super_explode_cartridge_device - constructor
38 //-------------------------------------------------
39 
c64_super_explode_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)40 c64_super_explode_cartridge_device::c64_super_explode_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
41 	device_t(mconfig, C64_SUPER_EXPLODE, tag, owner, clock),
42 	device_c64_expansion_card_interface(mconfig, *this), m_bank(0), m_exrom_timer(nullptr)
43 {
44 }
45 
46 
47 //-------------------------------------------------
48 //  device_start - device-specific startup
49 //-------------------------------------------------
50 
device_start()51 void c64_super_explode_cartridge_device::device_start()
52 {
53 	// allocate timer
54 	m_exrom_timer = timer_alloc();
55 
56 	// state saving
57 	save_item(NAME(m_bank));
58 }
59 
60 
61 //-------------------------------------------------
62 //  device_reset - device-specific reset
63 //-------------------------------------------------
64 
device_reset()65 void c64_super_explode_cartridge_device::device_reset()
66 {
67 	m_bank = 0;
68 
69 	m_exrom = 0;
70 	m_exrom_timer->adjust(attotime::from_usec(TIMER_PERIOD), 0);
71 }
72 
73 
74 //-------------------------------------------------
75 //  device_timer - handler timer events
76 //-------------------------------------------------
77 
device_timer(emu_timer & timer,device_timer_id id,int param,void * ptr)78 void c64_super_explode_cartridge_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
79 {
80 	m_exrom = 1;
81 }
82 
83 
84 //-------------------------------------------------
85 //  c64_cd_r - cartridge data read
86 //-------------------------------------------------
87 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)88 uint8_t c64_super_explode_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
89 {
90 	if (!roml)
91 	{
92 		m_exrom = 0;
93 		m_exrom_timer->adjust(attotime::from_usec(TIMER_PERIOD), 0);
94 
95 		data = m_roml[(m_bank << 13) | (offset & 0x1fff)];
96 	}
97 	else if (!io1)
98 	{
99 		m_exrom = 0;
100 		m_exrom_timer->adjust(attotime::from_usec(TIMER_PERIOD), 0);
101 	}
102 	else if (!io2)
103 	{
104 		data = m_roml[(m_bank << 13) | (offset & 0x1fff)];
105 	}
106 
107 	return data;
108 }
109 
110 
111 //-------------------------------------------------
112 //  c64_cd_w - cartridge data write
113 //-------------------------------------------------
114 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)115 void c64_super_explode_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
116 {
117 	if (!io1)
118 	{
119 		m_exrom = 0;
120 		m_exrom_timer->adjust(attotime::from_usec(TIMER_PERIOD), 0);
121 	}
122 	else if (!io2)
123 	{
124 		m_bank = BIT(data, 7);
125 	}
126 }
127