1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Brown Boxes Double Quick Brown Box emulation
6 
7 **********************************************************************/
8 
9 /*
10 
11     TODO:
12 
13     - 64/128 mode switch
14     - dump of the initial NVRAM contents
15 
16 */
17 
18 #include "emu.h"
19 #include "dqbb.h"
20 
21 
22 
23 //**************************************************************************
24 //  DEVICE DEFINITIONS
25 //**************************************************************************
26 
27 DEFINE_DEVICE_TYPE(C64_DQBB, c64_dqbb_cartridge_device, "c64_dqbb", "C64 Double Quick Brown Box cartridge")
28 
29 
30 
31 //**************************************************************************
32 //  LIVE DEVICE
33 //**************************************************************************
34 
35 //-------------------------------------------------
36 //  c64_dqbb_cartridge_device - constructor
37 //-------------------------------------------------
38 
c64_dqbb_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)39 c64_dqbb_cartridge_device::c64_dqbb_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
40 	device_t(mconfig, C64_DQBB, tag, owner, clock),
41 	device_c64_expansion_card_interface(mconfig, *this),
42 	device_nvram_interface(mconfig, *this),
43 	m_cs(0),
44 	m_we(0)
45 {
46 }
47 
48 
49 //-------------------------------------------------
50 //  device_start - device-specific startup
51 //-------------------------------------------------
52 
device_start()53 void c64_dqbb_cartridge_device::device_start()
54 {
55 	// allocate memory
56 	m_nvram.allocate(0x4000);
57 
58 	// state saving
59 	save_item(NAME(m_cs));
60 	save_item(NAME(m_we));
61 }
62 
63 
64 //-------------------------------------------------
65 //  device_reset - device-specific reset
66 //-------------------------------------------------
67 
device_reset()68 void c64_dqbb_cartridge_device::device_reset()
69 {
70 	m_exrom = 0; // TODO 1 in 128 mode
71 	m_game = 1;
72 	m_cs = 0;
73 	m_we = 0;
74 }
75 
76 
77 //-------------------------------------------------
78 //  c64_cd_r - cartridge data read
79 //-------------------------------------------------
80 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)81 uint8_t c64_dqbb_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
82 {
83 	if (!m_cs && (!roml || !romh))
84 	{
85 		data = m_nvram[offset & 0x3fff];
86 	}
87 
88 	return data;
89 }
90 
91 
92 //-------------------------------------------------
93 //  c64_cd_w - cartridge data write
94 //-------------------------------------------------
95 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)96 void c64_dqbb_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
97 {
98 	if (!m_cs && m_we && (offset >= 0x8000 && offset < 0xc000))
99 	{
100 		m_nvram[offset & 0x3fff] = data;
101 	}
102 	else if (!io1)
103 	{
104 		/*
105 
106 		    bit     description
107 
108 		    0
109 		    1
110 		    2       GAME
111 		    3
112 		    4       WE
113 		    5
114 		    6       EXROM
115 		    7       _CS
116 
117 		*/
118 
119 		m_exrom = !BIT(data, 6);
120 		m_game = !BIT(data, 2);
121 		m_we = BIT(data, 4);
122 		m_cs = BIT(data, 7);
123 	}
124 }
125