src/mess/machine/c16.c
| r7424 | r7425 | |
| 10 | 10 | |
| 11 | 11 | #include "emu.h" |
| 12 | 12 | #include "image.h" |
| 13 | | #include "cpu/m6502/m6502.h" |
| 14 | | #include "sound/sid6581.h" |
| 15 | | |
| 16 | 13 | #include "audio/ted7360.h" |
| 17 | | #include "machine/cbmiec.h" |
| 18 | | |
| 19 | | #include "includes/c16.h" |
| 20 | | |
| 14 | #include "cpu/m6502/m6502.h" |
| 21 | 15 | #include "devices/cassette.h" |
| 22 | 16 | #include "devices/cartslot.h" |
| 23 | | |
| 24 | 17 | #include "devices/messram.h" |
| 18 | #include "includes/c16.h" |
| 19 | #include "machine/cbmiec.h" |
| 20 | #include "sound/sid6581.h" |
| 25 | 21 | |
| 26 | 22 | #define VERBOSE_LEVEL 0 |
| 27 | 23 | #define DBG_LOG( MACHINE, N, M, A ) \ |
| r7424 | r7425 | |
| 34 | 30 | } \ |
| 35 | 31 | } while (0) |
| 36 | 32 | |
| 37 | | static UINT8 keyline[10] = |
| 38 | | { |
| 39 | | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 40 | | }; |
| 41 | 33 | |
| 42 | 34 | /* |
| 43 | 35 | * tia6523 |
| r7424 | r7425 | |
| 52 | 44 | * 7 ack input edge ready for next datum |
| 53 | 45 | */ |
| 54 | 46 | |
| 55 | | static int c16_has_sid, c16_pal; |
| 56 | | |
| 57 | | static UINT8 port6529; |
| 58 | | |
| 59 | | static int lowrom, highrom; |
| 60 | | |
| 61 | | static UINT8 *c16_memory_10000; |
| 62 | | static UINT8 *c16_memory_14000; |
| 63 | | static UINT8 *c16_memory_18000; |
| 64 | | static UINT8 *c16_memory_1c000; |
| 65 | | static UINT8 *c16_memory_20000; |
| 66 | | static UINT8 *c16_memory_24000; |
| 67 | | static UINT8 *c16_memory_28000; |
| 68 | | static UINT8 *c16_memory_2c000; |
| 69 | | |
| 70 | 47 | /* |
| 71 | 48 | ddr bit 1 port line is output |
| 72 | 49 | port bit 1 port line is high |
| r7424 | r7425 | |
| 93 | 70 | |
| 94 | 71 | void c16_m7501_port_write( running_device *device, UINT8 direction, UINT8 data ) |
| 95 | 72 | { |
| 96 | | running_device *serbus = devtag_get_device(device->machine, "iec"); |
| 73 | c16_state *state = (c16_state *)device->machine->driver_data; |
| 97 | 74 | |
| 98 | 75 | /* bit zero then output 0 */ |
| 99 | | cbm_iec_atn_w(serbus, device, !(data & 0x04)); |
| 100 | | cbm_iec_clk_w(serbus, device, !(data & 0x02)); |
| 101 | | cbm_iec_data_w(serbus, device, !(data & 0x01)); |
| 76 | cbm_iec_atn_w(state->serbus, device, !BIT(data, 2)); |
| 77 | cbm_iec_clk_w(state->serbus, device, !BIT(data, 1)); |
| 78 | cbm_iec_data_w(state->serbus, device, !BIT(data, 0)); |
| 102 | 79 | |
| 103 | | cassette_output(devtag_get_device(device->machine, "cassette"), !(data & 0x02) ? -(0x5a9e >> 1) : +(0x5a9e >> 1)); |
| 80 | cassette_output(state->cassette, !BIT(data, 1) ? -(0x5a9e >> 1) : +(0x5a9e >> 1)); |
| 104 | 81 | |
| 105 | | cassette_change_state(devtag_get_device(device->machine, "cassette"), (data & 0x08) ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR); |
| 82 | cassette_change_state(state->cassette, BIT(data, 7) ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR); |
| 106 | 83 | } |
| 107 | 84 | |
| 108 | 85 | UINT8 c16_m7501_port_read( running_device *device, UINT8 direction ) |
| 109 | 86 | { |
| 87 | c16_state *state = (c16_state *)device->machine->driver_data; |
| 110 | 88 | UINT8 data = 0xff; |
| 111 | | UINT8 c16_port7501 = (UINT8) device->machine->device("maincpu")->get_runtime_int(CPUINFO_INT_M6510_PORT); |
| 112 | | running_device *serbus = devtag_get_device(device->machine, "iec"); |
| 89 | UINT8 c16_port7501 = (UINT8) state->maincpu->get_runtime_int(CPUINFO_INT_M6510_PORT); |
| 113 | 90 | |
| 114 | | if ((c16_port7501 & 0x01) || !cbm_iec_data_r(serbus)) |
| 91 | if (BIT(c16_port7501, 0) || !cbm_iec_data_r(state->serbus)) |
| 115 | 92 | data &= ~0x80; |
| 116 | 93 | |
| 117 | | if ((c16_port7501 & 0x02) || !cbm_iec_clk_r(serbus)) |
| 94 | if (BIT(c16_port7501, 1) || !cbm_iec_clk_r(state->serbus)) |
| 118 | 95 | data &= ~0x40; |
| 119 | 96 | |
| 120 | 97 | // data &= ~0x20; // port bit not in pinout |
| 121 | 98 | |
| 122 | | if (cassette_input(devtag_get_device(device->machine, "cassette")) > +0.0) |
| 99 | if (cassette_input(state->cassette) > +0.0) |
| 123 | 100 | data |= 0x10; |
| 124 | 101 | else |
| 125 | 102 | data &= ~0x10; |
| r7424 | r7425 | |
| 129 | 106 | |
| 130 | 107 | static void c16_bankswitch( running_machine *machine ) |
| 131 | 108 | { |
| 109 | c16_state *state = (c16_state *)machine->driver_data; |
| 132 | 110 | UINT8 *rom = memory_region(machine, "maincpu"); |
| 133 | | memory_set_bankptr(machine, "bank9", messram_get_ptr(devtag_get_device(machine, "messram"))); |
| 111 | memory_set_bankptr(machine, "bank9", messram_get_ptr(state->messram)); |
| 134 | 112 | |
| 135 | | switch (lowrom) |
| 113 | switch (state->lowrom) |
| 136 | 114 | { |
| 137 | 115 | case 0: |
| 138 | 116 | memory_set_bankptr(machine, "bank2", rom + 0x10000); |
| r7424 | r7425 | |
| 148 | 126 | break; |
| 149 | 127 | } |
| 150 | 128 | |
| 151 | | switch (highrom) |
| 129 | switch (state->highrom) |
| 152 | 130 | { |
| 153 | 131 | case 0: |
| 154 | 132 | memory_set_bankptr(machine, "bank3", rom + 0x14000); |
| r7424 | r7425 | |
| 172 | 150 | |
| 173 | 151 | WRITE8_HANDLER( c16_switch_to_rom ) |
| 174 | 152 | { |
| 175 | | running_device *ted7360 = devtag_get_device(space->machine, "ted7360"); |
| 153 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 176 | 154 | |
| 177 | | ted7360_rom_switch_w(ted7360, 1); |
| 155 | ted7360_rom_switch_w(state->ted7360, 1); |
| 178 | 156 | c16_bankswitch(space->machine); |
| 179 | 157 | } |
| 180 | 158 | |
| r7424 | r7425 | |
| 193 | 171 | * 1 1 c2 high */ |
| 194 | 172 | WRITE8_HANDLER( c16_select_roms ) |
| 195 | 173 | { |
| 196 | | running_device *ted7360 = devtag_get_device(space->machine, "ted7360"); |
| 174 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 197 | 175 | |
| 198 | | lowrom = offset & 0x03; |
| 199 | | highrom = (offset & 0x0c) >> 2; |
| 200 | | if (ted7360_rom_switch_r(ted7360)) |
| 176 | state->lowrom = offset & 0x03; |
| 177 | state->highrom = (offset & 0x0c) >> 2; |
| 178 | if (ted7360_rom_switch_r(state->ted7360)) |
| 201 | 179 | c16_bankswitch(space->machine); |
| 202 | 180 | } |
| 203 | 181 | |
| 204 | 182 | WRITE8_HANDLER( c16_switch_to_ram ) |
| 205 | 183 | { |
| 206 | | running_device *ted7360 = devtag_get_device(space->machine, "ted7360"); |
| 184 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 207 | 185 | |
| 208 | | ted7360_rom_switch_w(ted7360, 0); |
| 186 | ted7360_rom_switch_w(state->ted7360, 0); |
| 209 | 187 | |
| 210 | | memory_set_bankptr(space->machine, "bank2", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0x8000 % messram_get_size(devtag_get_device(space->machine, "messram")))); |
| 211 | | memory_set_bankptr(space->machine, "bank3", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xc000 % messram_get_size(devtag_get_device(space->machine, "messram")))); |
| 212 | | memory_set_bankptr(space->machine, "bank4", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xfc00 % messram_get_size(devtag_get_device(space->machine, "messram")))); |
| 213 | | memory_set_bankptr(space->machine, "bank8", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xff20 % messram_get_size(devtag_get_device(space->machine, "messram")))); |
| 188 | memory_set_bankptr(space->machine, "bank2", messram_get_ptr(state->messram) + (0x8000 % messram_get_size(state->messram))); |
| 189 | memory_set_bankptr(space->machine, "bank3", messram_get_ptr(state->messram) + (0xc000 % messram_get_size(state->messram))); |
| 190 | memory_set_bankptr(space->machine, "bank4", messram_get_ptr(state->messram) + (0xfc00 % messram_get_size(state->messram))); |
| 191 | memory_set_bankptr(space->machine, "bank8", messram_get_ptr(state->messram) + (0xff20 % messram_get_size(state->messram))); |
| 214 | 192 | } |
| 215 | 193 | |
| 216 | 194 | UINT8 c16_read_keyboard( running_machine *machine, int databus ) |
| 217 | 195 | { |
| 196 | c16_state *state = (c16_state *)machine->driver_data; |
| 218 | 197 | UINT8 value = 0xff; |
| 198 | int i; |
| 219 | 199 | |
| 220 | | if (!(port6529 & 0x01)) |
| 221 | | value &= keyline[0]; |
| 200 | for (i = 0; i < 8; i++) |
| 201 | { |
| 202 | if (!BIT(state->port6529, i)) |
| 203 | value &= state->keyline[i]; |
| 204 | } |
| 222 | 205 | |
| 223 | | if (!(port6529 & 0x02)) |
| 224 | | value &= keyline[1]; |
| 225 | | |
| 226 | | if (!(port6529 & 0x04)) |
| 227 | | value &= keyline[2]; |
| 228 | | |
| 229 | | if (!(port6529 & 0x08)) |
| 230 | | value &= keyline[3]; |
| 231 | | |
| 232 | | if (!(port6529 & 0x10)) |
| 233 | | value &= keyline[4]; |
| 234 | | |
| 235 | | if (!(port6529 & 0x20)) |
| 236 | | value &= keyline[5]; |
| 237 | | |
| 238 | | if (!(port6529 & 0x40)) |
| 239 | | value &= keyline[6]; |
| 240 | | |
| 241 | | if (!(port6529 & 0x80)) |
| 242 | | value &= keyline[7]; |
| 243 | | |
| 244 | 206 | /* looks like joy 0 needs dataline2 low |
| 245 | 207 | * and joy 1 needs dataline1 low |
| 246 | 208 | * write to 0xff08 (value on databus) reloads latches */ |
| 247 | | if (!(databus & 0x04)) |
| 248 | | value &= keyline[8]; |
| 209 | if (!BIT(databus, 2)) |
| 210 | value &= state->keyline[8]; |
| 249 | 211 | |
| 250 | | if (!(databus & 0x02)) |
| 251 | | value &= keyline[9]; |
| 212 | if (!BIT(databus, 1)) |
| 213 | value &= state->keyline[9]; |
| 252 | 214 | |
| 253 | 215 | return value; |
| 254 | 216 | } |
| r7424 | r7425 | |
| 266 | 228 | */ |
| 267 | 229 | WRITE8_HANDLER( c16_6529_port_w ) |
| 268 | 230 | { |
| 269 | | port6529 = data; |
| 231 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 232 | state->port6529 = data; |
| 270 | 233 | } |
| 271 | 234 | |
| 272 | 235 | READ8_HANDLER( c16_6529_port_r ) |
| 273 | 236 | { |
| 274 | | return port6529 & (c16_read_keyboard (space->machine, 0xff /*databus */ ) | (port6529 ^ 0xff)); |
| 237 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 238 | return state->port6529 & (c16_read_keyboard (space->machine, 0xff /*databus */ ) | (state->port6529 ^ 0xff)); |
| 275 | 239 | } |
| 276 | 240 | |
| 277 | 241 | /* |
| r7424 | r7425 | |
| 290 | 254 | |
| 291 | 255 | READ8_HANDLER( plus4_6529_port_r ) |
| 292 | 256 | { |
| 257 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 293 | 258 | int data = 0x00; |
| 294 | 259 | |
| 295 | | if ((cassette_get_state(devtag_get_device(space->machine, "cassette")) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED) |
| 260 | if ((cassette_get_state(state->cassette) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED) |
| 296 | 261 | data &= ~0x04; |
| 297 | 262 | else |
| 298 | 263 | data |= 0x04; |
| r7424 | r7425 | |
| 302 | 267 | |
| 303 | 268 | READ8_HANDLER( c16_fd1x_r ) |
| 304 | 269 | { |
| 270 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 305 | 271 | int data = 0x00; |
| 306 | 272 | |
| 307 | | if ((cassette_get_state(devtag_get_device(space->machine, "cassette")) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED) |
| 273 | if ((cassette_get_state(state->cassette) & CASSETTE_MASK_UISTATE) != CASSETTE_STOPPED) |
| 308 | 274 | data &= ~0x04; |
| 309 | 275 | else |
| 310 | 276 | data |= 0x04; |
| r7424 | r7425 | |
| 351 | 317 | */ |
| 352 | 318 | WRITE8_HANDLER( c16_6551_port_w ) |
| 353 | 319 | { |
| 320 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 321 | |
| 354 | 322 | offset &= 0x03; |
| 355 | 323 | DBG_LOG(space->machine, 3, "6551", ("port write %.2x %.2x\n", offset, data)); |
| 356 | | port6529 = data; |
| 324 | state->port6529 = data; |
| 357 | 325 | } |
| 358 | 326 | |
| 359 | 327 | READ8_HANDLER( c16_6551_port_r ) |
| r7424 | r7425 | |
| 367 | 335 | |
| 368 | 336 | int c16_dma_read( running_machine *machine, int offset ) |
| 369 | 337 | { |
| 370 | | return messram_get_ptr(devtag_get_device(machine, "messram"))[offset % messram_get_size(devtag_get_device(machine, "messram"))]; |
| 338 | c16_state *state = (c16_state *)machine->driver_data; |
| 339 | return messram_get_ptr(state->messram)[offset % messram_get_size(state->messram)]; |
| 371 | 340 | } |
| 372 | 341 | |
| 373 | 342 | int c16_dma_read_rom( running_machine *machine, int offset ) |
| 374 | 343 | { |
| 344 | c16_state *state = (c16_state *)machine->driver_data; |
| 345 | |
| 375 | 346 | /* should read real c16 system bus from 0xfd00 -ff1f */ |
| 376 | 347 | if (offset >= 0xc000) |
| 377 | 348 | { /* rom address in rom */ |
| 378 | 349 | if ((offset >= 0xfc00) && (offset < 0xfd00)) |
| 379 | | return c16_memory_10000[offset]; |
| 350 | return state->mem10000[offset]; |
| 380 | 351 | |
| 381 | | switch (highrom) |
| 352 | switch (state->highrom) |
| 382 | 353 | { |
| 383 | 354 | case 0: |
| 384 | | return c16_memory_10000[offset & 0x7fff]; |
| 355 | return state->mem10000[offset & 0x7fff]; |
| 385 | 356 | case 1: |
| 386 | | return c16_memory_18000[offset & 0x7fff]; |
| 357 | return state->mem18000[offset & 0x7fff]; |
| 387 | 358 | case 2: |
| 388 | | return c16_memory_20000[offset & 0x7fff]; |
| 359 | return state->mem20000[offset & 0x7fff]; |
| 389 | 360 | case 3: |
| 390 | | return c16_memory_28000[offset & 0x7fff]; |
| 361 | return state->mem28000[offset & 0x7fff]; |
| 391 | 362 | } |
| 392 | 363 | } |
| 393 | 364 | |
| 394 | 365 | if (offset >= 0x8000) |
| 395 | 366 | { /* rom address in rom */ |
| 396 | | switch (lowrom) |
| 367 | switch (state->lowrom) |
| 397 | 368 | { |
| 398 | 369 | case 0: |
| 399 | | return c16_memory_10000[offset & 0x7fff]; |
| 370 | return state->mem10000[offset & 0x7fff]; |
| 400 | 371 | case 1: |
| 401 | | return c16_memory_18000[offset & 0x7fff]; |
| 372 | return state->mem18000[offset & 0x7fff]; |
| 402 | 373 | case 2: |
| 403 | | return c16_memory_20000[offset & 0x7fff]; |
| 374 | return state->mem20000[offset & 0x7fff]; |
| 404 | 375 | case 3: |
| 405 | | return c16_memory_28000[offset & 0x7fff]; |
| 376 | return state->mem28000[offset & 0x7fff]; |
| 406 | 377 | } |
| 407 | 378 | } |
| 408 | 379 | |
| 409 | | return messram_get_ptr(devtag_get_device(machine, "messram"))[offset % messram_get_size(devtag_get_device(machine, "messram"))]; |
| 380 | return messram_get_ptr(state->messram)[offset % messram_get_size(state->messram)]; |
| 410 | 381 | } |
| 411 | 382 | |
| 412 | 383 | void c16_interrupt( running_machine *machine, int level ) |
| 413 | 384 | { |
| 414 | | static int old_level; |
| 385 | c16_state *state = (c16_state *)machine->driver_data; |
| 415 | 386 | |
| 416 | | if (level != old_level) |
| 387 | if (level != state->old_level) |
| 417 | 388 | { |
| 418 | 389 | DBG_LOG(machine, 3, "mos7501", ("irq %s\n", level ? "start" : "end")); |
| 419 | | cputag_set_input_line(machine, "maincpu", M6510_IRQ_LINE, level); |
| 420 | | old_level = level; |
| 390 | cpu_set_input_line(state->maincpu, M6510_IRQ_LINE, level); |
| 391 | state->old_level = level; |
| 421 | 392 | } |
| 422 | 393 | } |
| 423 | 394 | |
| 424 | 395 | static void c16_common_driver_init( running_machine *machine ) |
| 425 | 396 | { |
| 426 | | UINT8 *rom; |
| 397 | c16_state *state = (c16_state *)machine->driver_data; |
| 398 | UINT8 *rom = memory_region(machine, "maincpu"); |
| 427 | 399 | |
| 428 | | lowrom = 0; |
| 429 | | highrom = 0; |
| 400 | /* initial bankswitch (notice that TED7360 is init to ROM) */ |
| 401 | memory_set_bankptr(machine, "bank2", rom + 0x10000); |
| 402 | memory_set_bankptr(machine, "bank3", rom + 0x14000); |
| 403 | memory_set_bankptr(machine, "bank4", rom + 0x17c00); |
| 404 | memory_set_bankptr(machine, "bank8", rom + 0x17f20); |
| 430 | 405 | |
| 431 | | c16_select_roms (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), 0, 0); |
| 432 | | c16_switch_to_rom (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), 0, 0); |
| 433 | | |
| 434 | | rom = memory_region(machine, "maincpu"); |
| 435 | | |
| 436 | | c16_memory_10000 = rom + 0x10000; |
| 437 | | c16_memory_14000 = rom + 0x14000; |
| 438 | | c16_memory_18000 = rom + 0x18000; |
| 439 | | c16_memory_1c000 = rom + 0x1c000; |
| 440 | | c16_memory_20000 = rom + 0x20000; |
| 441 | | c16_memory_24000 = rom + 0x24000; |
| 442 | | c16_memory_28000 = rom + 0x28000; |
| 443 | | c16_memory_2c000 = rom + 0x2c000; |
| 406 | state->mem10000 = rom + 0x10000; |
| 407 | state->mem14000 = rom + 0x14000; |
| 408 | state->mem18000 = rom + 0x18000; |
| 409 | state->mem1c000 = rom + 0x1c000; |
| 410 | state->mem20000 = rom + 0x20000; |
| 411 | state->mem24000 = rom + 0x24000; |
| 412 | state->mem28000 = rom + 0x28000; |
| 413 | state->mem2c000 = rom + 0x2c000; |
| 444 | 414 | } |
| 445 | 415 | |
| 446 | 416 | DRIVER_INIT( c16 ) |
| 447 | 417 | { |
| 418 | c16_state *state = (c16_state *)machine->driver_data; |
| 448 | 419 | c16_common_driver_init(machine); |
| 449 | 420 | |
| 450 | | c16_has_sid = 0; |
| 451 | | c16_pal = 1; |
| 421 | state->sidcard = 0; |
| 422 | state->pal = 1; |
| 452 | 423 | } |
| 453 | 424 | |
| 454 | 425 | DRIVER_INIT( plus4 ) |
| 455 | 426 | { |
| 427 | c16_state *state = (c16_state *)machine->driver_data; |
| 456 | 428 | c16_common_driver_init(machine); |
| 457 | 429 | |
| 458 | | c16_has_sid = 0; |
| 459 | | c16_pal = 0; |
| 430 | state->sidcard = 0; |
| 431 | state->pal = 0; |
| 460 | 432 | } |
| 461 | 433 | |
| 462 | 434 | DRIVER_INIT( c16sid ) |
| 463 | 435 | { |
| 436 | c16_state *state = (c16_state *)machine->driver_data; |
| 464 | 437 | c16_common_driver_init(machine); |
| 465 | 438 | |
| 466 | | c16_has_sid = 1; |
| 467 | | c16_pal = 1; |
| 439 | state->sidcard = 1; |
| 440 | state->pal = 1; |
| 468 | 441 | } |
| 469 | 442 | |
| 470 | 443 | DRIVER_INIT( plus4sid ) |
| 471 | 444 | { |
| 445 | c16_state *state = (c16_state *)machine->driver_data; |
| 472 | 446 | c16_common_driver_init(machine); |
| 473 | 447 | |
| 474 | | c16_has_sid = 1; |
| 475 | | c16_pal = 0; |
| 448 | state->sidcard = 1; |
| 449 | state->pal = 0; |
| 476 | 450 | } |
| 477 | 451 | |
| 478 | 452 | MACHINE_RESET( c16 ) |
| 479 | 453 | { |
| 480 | 454 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 455 | c16_state *state = (c16_state *)machine->driver_data; |
| 481 | 456 | |
| 482 | | if (c16_pal) |
| 457 | memset(state->keyline, 0xff, ARRAY_LENGTH(state->keyline)); |
| 458 | |
| 459 | state->lowrom = 0; |
| 460 | state->highrom = 0; |
| 461 | state->old_level = 0; |
| 462 | state->port6529 = 0; |
| 463 | |
| 464 | if (state->pal) |
| 483 | 465 | { |
| 484 | | memory_set_bankptr(machine, "bank1", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x4000 % messram_get_size(devtag_get_device(machine, "messram")))); |
| 466 | memory_set_bankptr(machine, "bank1", messram_get_ptr(state->messram) + (0x4000 % messram_get_size(state->messram))); |
| 485 | 467 | |
| 486 | | memory_set_bankptr(machine, "bank5", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x4000 % messram_get_size(devtag_get_device(machine, "messram")))); |
| 487 | | memory_set_bankptr(machine, "bank6", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x8000 % messram_get_size(devtag_get_device(machine, "messram")))); |
| 488 | | memory_set_bankptr(machine, "bank7", messram_get_ptr(devtag_get_device(machine, "messram")) + (0xc000 % messram_get_size(devtag_get_device(machine, "messram")))); |
| 468 | memory_set_bankptr(machine, "bank5", messram_get_ptr(state->messram) + (0x4000 % messram_get_size(state->messram))); |
| 469 | memory_set_bankptr(machine, "bank6", messram_get_ptr(state->messram) + (0x8000 % messram_get_size(state->messram))); |
| 470 | memory_set_bankptr(machine, "bank7", messram_get_ptr(state->messram) + (0xc000 % messram_get_size(state->messram))); |
| 489 | 471 | |
| 490 | 472 | memory_install_write_bank(space, 0xff20, 0xff3d, 0, 0,"bank10"); |
| 491 | 473 | memory_install_write_bank(space, 0xff40, 0xffff, 0, 0, "bank11"); |
| 492 | | memory_set_bankptr(machine, "bank10", messram_get_ptr(devtag_get_device(machine, "messram")) + (0xff20 % messram_get_size(devtag_get_device(machine, "messram")))); |
| 493 | | memory_set_bankptr(machine, "bank11", messram_get_ptr(devtag_get_device(machine, "messram")) + (0xff40 % messram_get_size(devtag_get_device(machine, "messram")))); |
| 474 | memory_set_bankptr(machine, "bank10", messram_get_ptr(state->messram) + (0xff20 % messram_get_size(state->messram))); |
| 475 | memory_set_bankptr(machine, "bank11", messram_get_ptr(state->messram) + (0xff40 % messram_get_size(state->messram))); |
| 494 | 476 | } |
| 495 | 477 | else |
| 496 | 478 | { |
| 497 | 479 | memory_install_write_bank(space, 0x4000, 0xfcff, 0, 0, "bank10"); |
| 498 | | memory_set_bankptr(machine, "bank10", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x4000 % messram_get_size(devtag_get_device(machine, "messram")))); |
| 480 | memory_set_bankptr(machine, "bank10", messram_get_ptr(state->messram) + (0x4000 % messram_get_size(state->messram))); |
| 499 | 481 | } |
| 500 | 482 | } |
| 501 | 483 | |
| r7424 | r7425 | |
| 505 | 487 | // would a real SID Card allow for this? If not, this should be removed completely |
| 506 | 488 | static WRITE8_HANDLER( c16_sidcart_16k ) |
| 507 | 489 | { |
| 508 | | running_device *sid = devtag_get_device(space->machine, "sid"); |
| 490 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 509 | 491 | |
| 510 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[0x1400 + offset] = data; |
| 511 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[0x5400 + offset] = data; |
| 512 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[0x9400 + offset] = data; |
| 513 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[0xd400 + offset] = data; |
| 492 | messram_get_ptr(state->messram)[0x1400 + offset] = data; |
| 493 | messram_get_ptr(state->messram)[0x5400 + offset] = data; |
| 494 | messram_get_ptr(state->messram)[0x9400 + offset] = data; |
| 495 | messram_get_ptr(state->messram)[0xd400 + offset] = data; |
| 514 | 496 | |
| 515 | | sid6581_w(sid, offset, data); |
| 497 | sid6581_w(state->sid, offset, data); |
| 516 | 498 | } |
| 517 | 499 | |
| 518 | 500 | static WRITE8_HANDLER( c16_sidcart_64k ) |
| 519 | 501 | { |
| 520 | | running_device *sid = devtag_get_device(space->machine, "sid"); |
| 502 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 521 | 503 | |
| 522 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[0xd400 + offset] = data; |
| 504 | messram_get_ptr(state->messram)[0xd400 + offset] = data; |
| 523 | 505 | |
| 524 | | sid6581_w(sid, offset, data); |
| 506 | sid6581_w(state->sid, offset, data); |
| 525 | 507 | } |
| 526 | 508 | |
| 527 | 509 | static TIMER_CALLBACK( c16_sidhack_tick ) |
| 528 | 510 | { |
| 529 | 511 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 512 | c16_state *state = (c16_state *)space->machine->driver_data; |
| 530 | 513 | |
| 531 | 514 | if (input_port_read_safe(machine, "SID", 0x00) & 0x02) |
| 532 | 515 | { |
| 533 | | if (c16_pal) |
| 516 | if (state->pal) |
| 534 | 517 | memory_install_write8_handler(space, 0xd400, 0xd41f, 0, 0, c16_sidcart_16k); |
| 535 | 518 | else |
| 536 | 519 | memory_install_write8_handler(space, 0xd400, 0xd41f, 0, 0, c16_sidcart_64k); |
| r7424 | r7425 | |
| 544 | 527 | |
| 545 | 528 | static TIMER_CALLBACK( c16_sidcard_tick ) |
| 546 | 529 | { |
| 547 | | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 548 | | running_device *sid = devtag_get_device(machine, "sid"); |
| 530 | c16_state *state = (c16_state *)machine->driver_data; |
| 531 | const address_space *space = cpu_get_address_space(state->maincpu, ADDRESS_SPACE_PROGRAM); |
| 549 | 532 | |
| 550 | 533 | if (input_port_read_safe(machine, "SID", 0x00) & 0x01) |
| 551 | | { |
| 552 | | memory_install_readwrite8_device_handler(space, sid, 0xfe80, 0xfe9f, 0, 0, sid6581_r, sid6581_w); |
| 553 | | } |
| 534 | memory_install_readwrite8_device_handler(space, state->sid, 0xfe80, 0xfe9f, 0, 0, sid6581_r, sid6581_w); |
| 554 | 535 | else |
| 555 | | { |
| 556 | | memory_install_readwrite8_device_handler(space, sid, 0xfd40, 0xfd5f, 0, 0, sid6581_r, sid6581_w); |
| 557 | | } |
| 536 | memory_install_readwrite8_device_handler(space, state->sid, 0xfd40, 0xfd5f, 0, 0, sid6581_r, sid6581_w); |
| 558 | 537 | } |
| 559 | 538 | |
| 560 | 539 | INTERRUPT_GEN( c16_frame_interrupt ) |
| 561 | 540 | { |
| 562 | | running_device *ted7360 = devtag_get_device(device->machine, "ted7360"); |
| 541 | c16_state *state = (c16_state *)device->machine->driver_data; |
| 563 | 542 | int value, i; |
| 564 | 543 | static const char *const c16ports[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7" }; |
| 565 | 544 | |
| r7424 | r7425 | |
| 573 | 552 | if ((i == 1) && (input_port_read(device->machine, "SPECIAL") & 0x80)) |
| 574 | 553 | value &= ~0x80; |
| 575 | 554 | |
| 576 | | keyline[i] = value; |
| 555 | state->keyline[i] = value; |
| 577 | 556 | } |
| 578 | 557 | |
| 579 | 558 | if (input_port_read(device->machine, "CTRLSEL") & 0x01) |
| r7424 | r7425 | |
| 590 | 569 | value &= ~(input_port_read(device->machine, "JOY0") & 0x0f); /* Other Inputs Joypad1 */ |
| 591 | 570 | |
| 592 | 571 | if (input_port_read(device->machine, "SPECIAL") & 0x40) |
| 593 | | keyline[9] = value; |
| 572 | state->keyline[9] = value; |
| 594 | 573 | else |
| 595 | | keyline[8] = value; |
| 574 | state->keyline[8] = value; |
| 596 | 575 | } |
| 597 | 576 | |
| 598 | 577 | if (input_port_read(device->machine, "CTRLSEL") & 0x10) |
| r7424 | r7425 | |
| 609 | 588 | value &= ~(input_port_read(device->machine, "JOY1") & 0x0f); /* Other Inputs Joypad2 */ |
| 610 | 589 | |
| 611 | 590 | if (input_port_read(device->machine, "SPECIAL") & 0x40) |
| 612 | | keyline[8] = value; |
| 591 | state->keyline[8] = value; |
| 613 | 592 | else |
| 614 | | keyline[9] = value; |
| 593 | state->keyline[9] = value; |
| 615 | 594 | } |
| 616 | 595 | |
| 617 | | ted7360_frame_interrupt_gen(ted7360); |
| 596 | ted7360_frame_interrupt_gen(state->ted7360); |
| 618 | 597 | |
| 619 | | if (c16_has_sid) |
| 598 | if (state->sidcard) |
| 620 | 599 | { |
| 621 | 600 | /* if we are emulating the SID card, check which memory area should be accessed */ |
| 622 | 601 | timer_set(device->machine, attotime_zero, NULL, 0, c16_sidcard_tick); |