1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Epyx Fast Load cartridge emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "epyx_fast_load.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_EPYX_FAST_LOAD, c64_epyx_fast_load_cartridge_device, "c64_epyx_fast_load", "C64 Epyx Fast Load cartridge")
29 
30 
31 
32 //**************************************************************************
33 //  LIVE DEVICE
34 //**************************************************************************
35 
36 //-------------------------------------------------
37 //  c64_epyx_fast_load_cartridge_device - constructor
38 //-------------------------------------------------
39 
c64_epyx_fast_load_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)40 c64_epyx_fast_load_cartridge_device::c64_epyx_fast_load_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
41 	device_t(mconfig, C64_EPYX_FAST_LOAD, tag, owner, clock),
42 	device_c64_expansion_card_interface(mconfig, *this), m_exrom_timer(nullptr)
43 {
44 }
45 
46 
47 //-------------------------------------------------
48 //  device_start - device-specific startup
49 //-------------------------------------------------
50 
device_start()51 void c64_epyx_fast_load_cartridge_device::device_start()
52 {
53 	// allocate timer
54 	m_exrom_timer = timer_alloc();
55 }
56 
57 
58 //-------------------------------------------------
59 //  device_reset - device-specific reset
60 //-------------------------------------------------
61 
device_reset()62 void c64_epyx_fast_load_cartridge_device::device_reset()
63 {
64 	m_exrom = 0;
65 	m_exrom_timer->adjust(attotime::from_usec(TIMER_PERIOD), 0);
66 }
67 
68 
69 //-------------------------------------------------
70 //  device_timer - handler timer events
71 //-------------------------------------------------
72 
device_timer(emu_timer & timer,device_timer_id id,int param,void * ptr)73 void c64_epyx_fast_load_cartridge_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
74 {
75 	m_exrom = 1;
76 }
77 
78 
79 //-------------------------------------------------
80 //  c64_cd_r - cartridge data read
81 //-------------------------------------------------
82 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)83 uint8_t c64_epyx_fast_load_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
84 {
85 	if (!roml)
86 	{
87 		m_exrom = 0;
88 		m_exrom_timer->adjust(attotime::from_usec(TIMER_PERIOD), 0);
89 
90 		data = m_roml[offset & 0x1fff];
91 	}
92 	else if (!io1)
93 	{
94 		m_exrom = 0;
95 		m_exrom_timer->adjust(attotime::from_usec(TIMER_PERIOD), 0);
96 	}
97 	else if (!io2)
98 	{
99 		data = m_roml[offset & 0x1fff];
100 	}
101 
102 	return data;
103 }
104 
105 
106 //-------------------------------------------------
107 //  c64_cd_w - cartridge data write
108 //-------------------------------------------------
109 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)110 void c64_epyx_fast_load_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
111 {
112 	if (!io1)
113 	{
114 		m_exrom = 0;
115 		m_exrom_timer->adjust(attotime::from_usec(TIMER_PERIOD), 0);
116 	}
117 }
118