1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4
5 Berkeley Softworks GeoRAM emulation
6
7 **********************************************************************/
8
9 #include "emu.h"
10 #include "georam.h"
11
12
13
14 //**************************************************************************
15 // DEVICE DEFINITIONS
16 //**************************************************************************
17
18 DEFINE_DEVICE_TYPE(C64_GEORAM, c64_georam_cartridge_device, "c64_georam", "C64 GeoRAM cartridge")
19
20
21
22 //**************************************************************************
23 // LIVE DEVICE
24 //**************************************************************************
25
26 //-------------------------------------------------
27 // c64_georam_cartridge_device - constructor
28 //-------------------------------------------------
29
c64_georam_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)30 c64_georam_cartridge_device::c64_georam_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
31 device_t(mconfig, C64_GEORAM, tag, owner, clock),
32 device_c64_expansion_card_interface(mconfig, *this),
33 m_ram(*this, "ram"),
34 m_bank(0)
35 {
36 }
37
38
39 //-------------------------------------------------
40 // device_start - device-specific startup
41 //-------------------------------------------------
42
device_start()43 void c64_georam_cartridge_device::device_start()
44 {
45 // allocate memory
46 m_ram.allocate(0x80000);
47
48 // state saving
49 save_item(NAME(m_bank));
50 }
51
52
53 //-------------------------------------------------
54 // device_reset - device-specific reset
55 //-------------------------------------------------
56
device_reset()57 void c64_georam_cartridge_device::device_reset()
58 {
59 m_bank = 0;
60 }
61
62
63 //-------------------------------------------------
64 // c64_cd_r - cartridge data read
65 //-------------------------------------------------
66
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)67 uint8_t c64_georam_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
68 {
69 if (!io1)
70 {
71 offs_t addr = (m_bank << 8) | (offset & 0xff);
72 data = m_ram[addr];
73 }
74
75 return data;
76 }
77
78
79 //-------------------------------------------------
80 // c64_cd_w - cartridge data write
81 //-------------------------------------------------
82
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)83 void c64_georam_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
84 {
85 if (!io1)
86 {
87 offs_t addr = (m_bank << 8) | (offset & 0xff);
88 m_ram[addr] = data;
89 }
90 else if (!io2)
91 {
92 if (BIT(offset, 0))
93 {
94 m_bank = ((data & 0x1f) << 6) | (m_bank & 0x3f);
95 }
96 else
97 {
98 m_bank = (m_bank & 0x7c0) | (data & 0x3f);
99 }
100 }
101 }
102