src/mess/machine/c64_ide64.c
| r15014 | r15015 | |
| 7 | 7 | |
| 8 | 8 | **********************************************************************/ |
| 9 | 9 | |
| 10 | /* |
| 11 | |
| 12 | TODO: |
| 13 | |
| 14 | - kill port |
| 15 | - DS1302 |
| 16 | - FT245 |
| 17 | |
| 18 | */ |
| 19 | |
| 10 | 20 | #include "c64_ide64.h" |
| 11 | 21 | |
| 12 | 22 | |
| r15014 | r15015 | |
| 15 | 25 | // MACROS/CONSTANTS |
| 16 | 26 | //************************************************************************** |
| 17 | 27 | |
| 18 | | #define AT29C010_TAG "u3" |
| 28 | #define AT29C010A_TAG "u3" |
| 19 | 29 | #define DS1302_TAG "u4" |
| 30 | #define FT245R_TAG "u21" |
| 20 | 31 | |
| 21 | 32 | |
| 22 | 33 | |
| r15014 | r15015 | |
| 32 | 43 | //------------------------------------------------- |
| 33 | 44 | |
| 34 | 45 | static MACHINE_CONFIG_FRAGMENT( c64_ide64 ) |
| 35 | | MCFG_ATMEL_29C010_ADD(AT29C010_TAG) |
| 46 | MCFG_ATMEL_29C010_ADD(AT29C010A_TAG) |
| 36 | 47 | MCFG_DS1302_ADD(DS1302_TAG) |
| 48 | // TODO FT245R |
| 37 | 49 | // TODO CompactFlash |
| 38 | 50 | |
| 39 | 51 | MCFG_IDE_CONTROLLER_ADD("ide", NULL, ide_image_devices, "hdd", "hdd") |
| r15014 | r15015 | |
| 51 | 63 | } |
| 52 | 64 | |
| 53 | 65 | |
| 66 | //------------------------------------------------- |
| 67 | // INPUT_PORTS( c64_ide64 ) |
| 68 | //------------------------------------------------- |
| 54 | 69 | |
| 70 | static INPUT_PORTS_START( c64_ide64 ) |
| 71 | PORT_START("JP1") |
| 72 | PORT_DIPNAME( 0x01, 0x01, "Flash ROM Write Protect" ) |
| 73 | PORT_DIPSETTING( 0x00, "Disabled" ) |
| 74 | PORT_DIPSETTING( 0x01, "Enabled" ) |
| 75 | INPUT_PORTS_END |
| 76 | |
| 77 | |
| 78 | //------------------------------------------------- |
| 79 | // input_ports - device-specific input ports |
| 80 | //------------------------------------------------- |
| 81 | |
| 82 | ioport_constructor c64_ide64_cartridge_device::device_input_ports() const |
| 83 | { |
| 84 | return INPUT_PORTS_NAME( c64_ide64 ); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | |
| 55 | 89 | //************************************************************************** |
| 56 | 90 | // LIVE DEVICE |
| 57 | 91 | //************************************************************************** |
| r15014 | r15015 | |
| 62 | 96 | |
| 63 | 97 | c64_ide64_cartridge_device::c64_ide64_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 64 | 98 | device_t(mconfig, C64_IDE64, "C64 IDE64 cartridge", tag, owner, clock), |
| 65 | | device_c64_expansion_card_interface(mconfig, *this) |
| 99 | device_c64_expansion_card_interface(mconfig, *this), |
| 100 | m_flash_rom(*this, AT29C010A_TAG), |
| 101 | m_ide(*this, "ide") |
| 66 | 102 | { |
| 67 | 103 | } |
| 68 | 104 | |
| r15014 | r15015 | |
| 75 | 111 | { |
| 76 | 112 | // allocate memory |
| 77 | 113 | c64_ram_pointer(machine(), 0x8000); |
| 114 | |
| 115 | // state saving |
| 116 | save_item(NAME(m_bank)); |
| 117 | save_item(NAME(m_ide_data)); |
| 78 | 118 | } |
| 79 | 119 | |
| 80 | 120 | |
| r15014 | r15015 | |
| 84 | 124 | |
| 85 | 125 | void c64_ide64_cartridge_device::device_reset() |
| 86 | 126 | { |
| 127 | m_bank = 0; |
| 128 | m_game = 1; |
| 129 | m_exrom = 1; |
| 130 | |
| 131 | m_wp = input_port_read(*this, "JP1"); |
| 87 | 132 | } |
| 88 | 133 | |
| 89 | 134 | |
| r15014 | r15015 | |
| 94 | 139 | UINT8 c64_ide64_cartridge_device::c64_cd_r(address_space &space, offs_t offset, int roml, int romh, int io1, int io2) |
| 95 | 140 | { |
| 96 | 141 | UINT8 data = 0; |
| 142 | int rom_oe = 1, ram_oe = 1; |
| 97 | 143 | |
| 98 | | // TODO |
| 144 | if (!m_game && m_exrom) |
| 145 | { |
| 146 | if (offset >= 0x1000 && offset < 0x8000) |
| 147 | { |
| 148 | ram_oe = 0; |
| 149 | } |
| 150 | else if (offset >= 0xa000 && offset < 0xc000) |
| 151 | { |
| 152 | rom_oe = 0; |
| 153 | } |
| 154 | else if (offset >= 0xc000 && offset < 0xd000) |
| 155 | { |
| 156 | ram_oe = 0; |
| 157 | } |
| 158 | else if (!romh) |
| 159 | { |
| 160 | rom_oe = 0; |
| 161 | } |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | if (!roml || !romh) |
| 166 | { |
| 167 | rom_oe = 0; |
| 168 | } |
| 169 | else if (!io1) |
| 170 | { |
| 171 | // 0x20-0x2f IDE |
| 172 | // 0x30-0x37 I/O |
| 173 | // 0x5d-0x5e FT245 |
| 174 | // 0x5f-0x5f DS1302 |
| 175 | // 0x60-0xff ROM |
| 99 | 176 | |
| 177 | UINT8 io1_offset = offset & 0xff; |
| 178 | |
| 179 | if (io1_offset >= 0x20 && io1_offset < 0x30) |
| 180 | { |
| 181 | m_ide_data = ide_bus_r(m_ide, BIT(offset, 3), offset & 0x07); |
| 182 | |
| 183 | data = m_ide_data & 0xff; |
| 184 | } |
| 185 | else if (io1_offset == 0x31) |
| 186 | { |
| 187 | data = m_ide_data >> 8; |
| 188 | } |
| 189 | else if (io1_offset >= 0x60) |
| 190 | { |
| 191 | rom_oe = 0; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if (!rom_oe) |
| 197 | { |
| 198 | offs_t addr = (m_bank << 14) | (offset & 0x3fff); |
| 199 | data = m_flash_rom->read(addr); |
| 200 | } |
| 201 | else if (!ram_oe) |
| 202 | { |
| 203 | data = m_ram[offset & 0x7fff]; |
| 204 | } |
| 205 | |
| 100 | 206 | return data; |
| 101 | 207 | } |
| 102 | 208 | |
| r15014 | r15015 | |
| 107 | 213 | |
| 108 | 214 | void c64_ide64_cartridge_device::c64_cd_w(address_space &space, offs_t offset, UINT8 data, int roml, int romh, int io1, int io2) |
| 109 | 215 | { |
| 110 | | // TODO |
| 216 | if (!m_game && m_exrom) |
| 217 | { |
| 218 | if (offset >= 0x1000 && offset < 0x8000) |
| 219 | { |
| 220 | m_ram[offset & 0x7fff] = data; |
| 221 | } |
| 222 | else if (offset >= 0xc000 && offset < 0xd000) |
| 223 | { |
| 224 | m_ram[offset & 0x7fff] = data; |
| 225 | } |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | if ((offset >= 0x8000 && offset < 0xc000) && !m_wp) |
| 230 | { |
| 231 | offs_t addr = (m_bank << 14) | (offset & 0x3fff); |
| 232 | m_flash_rom->write(addr, data); |
| 233 | } |
| 234 | else if (!io1) |
| 235 | { |
| 236 | // 0x20-0x2f IDE |
| 237 | // 0x30-0x37 I/O |
| 238 | // 0x5d-0x5e FT245 |
| 239 | // 0x5f-0x5f DS1302 |
| 240 | // 0x60-0xff ROM |
| 241 | |
| 242 | UINT8 io1_offset = offset & 0xff; |
| 243 | |
| 244 | if (io1_offset >= 0x20 && io1_offset < 0x30) |
| 245 | { |
| 246 | m_ide_data = (m_ide_data & 0xff00) | data; |
| 247 | |
| 248 | ide_bus_w(m_ide, BIT(offset, 3), offset & 0x07, m_ide_data); |
| 249 | } |
| 250 | else if (io1_offset == 0x31) |
| 251 | { |
| 252 | m_ide_data = (data << 8) | (m_ide_data & 0xff); |
| 253 | } |
| 254 | else if (io1_offset >= 0x32 && io1_offset < 0x36) |
| 255 | { |
| 256 | m_bank = io1_offset - 0x32; |
| 257 | } |
| 258 | else if (io1_offset >= 0x60 && io1_offset < 0x68) |
| 259 | { |
| 260 | m_bank = offset & 0x07; |
| 261 | } |
| 262 | else if (io1_offset >= 0xfc) |
| 263 | { |
| 264 | m_game = BIT(offset, 0); |
| 265 | m_exrom = BIT(offset, 1); |
| 266 | } |
| 267 | } |
| 268 | } |
| 111 | 269 | } |