src/mame/machine/archimds.c
| r8793 | r8794 | |
| 30 | 30 | #include "cpu/arm/arm.h" |
| 31 | 31 | #include "sound/dac.h" |
| 32 | 32 | #include "includes/archimds.h" |
| 33 | #include "machine/i2cmem.h" |
| 33 | 34 | |
| 34 | 35 | #ifdef MESS |
| 35 | 36 | #include "machine/wd17xx.h" |
| r8793 | r8794 | |
| 40 | 41 | UINT32 *archimedes_memc_physmem; |
| 41 | 42 | static UINT32 memc_pagesize; |
| 42 | 43 | static int memc_latchrom; |
| 43 | | static INT16 memc_pages[(32*1024*1024)/(4096)]; // the logical RAM area is 32 megs, and the smallest page size is 4k |
| 44 | | static UINT32 vidc_regs[256]; |
| 45 | | static UINT8 ioc_regs[0x80/4]; |
| 44 | INT16 memc_pages[(32*1024*1024)/(4096)]; // the logical RAM area is 32 megs, and the smallest page size is 4k |
| 45 | UINT32 vidc_regs[256]; |
| 46 | UINT8 ioc_regs[0x80/4]; |
| 46 | 47 | static UINT32 ioc_timercnt[4], ioc_timerout[4]; |
| 47 | 48 | static UINT32 vidc_sndstart, vidc_sndend, vidc_sndcur; |
| 49 | UINT8 i2c_clk; |
| 48 | 50 | |
| 49 | | static emu_timer *vbl_timer, *timer[4], *snd_timer; |
| 51 | static emu_timer *timer[4], *snd_timer; |
| 52 | emu_timer *vbl_timer; |
| 50 | 53 | |
| 54 | #define CONTROL 0 |
| 55 | #define IRQ_STATUS_A 4 |
| 56 | #define IRQ_MASK_A 6 |
| 57 | #define IRQ_STATUS_B 8 |
| 58 | #define IRQ_MASK_B 10 |
| 59 | #define FIQ_STATUS 12 |
| 60 | #define FIQ_MASK 14 |
| 61 | |
| 51 | 62 | void archimedes_request_irq_a(running_machine *machine, int mask) |
| 52 | 63 | { |
| 53 | | ioc_regs[4] |= mask; |
| 64 | ioc_regs[IRQ_STATUS_A] |= mask; |
| 54 | 65 | |
| 55 | | if (ioc_regs[6] & mask) |
| 66 | if (ioc_regs[IRQ_MASK_A] & mask) |
| 56 | 67 | { |
| 57 | 68 | cputag_set_input_line(machine, "maincpu", ARM_IRQ_LINE, ASSERT_LINE); |
| 58 | 69 | } |
| r8793 | r8794 | |
| 60 | 71 | |
| 61 | 72 | void archimedes_request_irq_b(running_machine *machine, int mask) |
| 62 | 73 | { |
| 63 | | ioc_regs[8] |= mask; |
| 74 | ioc_regs[IRQ_STATUS_B] |= mask; |
| 64 | 75 | |
| 65 | | if (ioc_regs[10] & mask) |
| 76 | if (ioc_regs[IRQ_MASK_B] & mask) |
| 66 | 77 | { |
| 67 | 78 | generic_pulse_irq_line(machine->device("maincpu"), ARM_IRQ_LINE); |
| 68 | 79 | } |
| r8793 | r8794 | |
| 70 | 81 | |
| 71 | 82 | void archimedes_request_fiq(running_machine *machine, int mask) |
| 72 | 83 | { |
| 73 | | ioc_regs[12] |= mask; |
| 84 | ioc_regs[FIQ_STATUS] |= mask; |
| 74 | 85 | |
| 75 | | if (ioc_regs[14] & mask) |
| 86 | if (ioc_regs[FIQ_MASK] & mask) |
| 76 | 87 | { |
| 77 | 88 | generic_pulse_irq_line(machine->device("maincpu"), ARM_FIRQ_LINE); |
| 78 | 89 | } |
| r8793 | r8794 | |
| 80 | 91 | |
| 81 | 92 | void archimedes_clear_irq_a(running_machine *machine, int mask) |
| 82 | 93 | { |
| 83 | | ioc_regs[4] &= ~mask; |
| 94 | ioc_regs[IRQ_STATUS_A] &= ~mask; |
| 84 | 95 | } |
| 85 | 96 | |
| 86 | 97 | void archimedes_clear_irq_b(running_machine *machine, int mask) |
| 87 | 98 | { |
| 88 | | ioc_regs[8] &= ~mask; |
| 99 | ioc_regs[IRQ_STATUS_B] &= ~mask; |
| 89 | 100 | } |
| 90 | 101 | |
| 91 | 102 | void archimedes_clear_fiq(running_machine *machine, int mask) |
| 92 | 103 | { |
| 93 | | ioc_regs[12] &= ~mask; |
| 104 | ioc_regs[FIQ_STATUS] &= ~mask; |
| 94 | 105 | } |
| 95 | 106 | |
| 96 | 107 | static TIMER_CALLBACK( vidc_vblank ) |
| r8793 | r8794 | |
| 103 | 114 | |
| 104 | 115 | static TIMER_CALLBACK( a310_audio_tick ) |
| 105 | 116 | { |
| 117 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 118 | |
| 119 | dac_signed_data_w(space->machine->device("dac"), 0x80 | (memory_read_byte(space,vidc_sndcur))); |
| 120 | |
| 106 | 121 | vidc_sndcur++; |
| 107 | 122 | |
| 108 | 123 | if (vidc_sndcur >= vidc_sndend) |
| 109 | 124 | { |
| 110 | 125 | archimedes_request_irq_b(machine, ARCHIMEDES_IRQB_SOUND_EMPTY); |
| 126 | timer_adjust_oneshot(snd_timer, attotime_never, 0); |
| 127 | dac_signed_data_w(space->machine->device("dac"), 0x80); |
| 111 | 128 | } |
| 112 | 129 | } |
| 113 | 130 | |
| r8793 | r8794 | |
| 118 | 135 | if(ioc_timercnt[tmr] != 0) // FIXME: dmdtouch does a divide by zero? |
| 119 | 136 | { |
| 120 | 137 | freq = 2000000.0 / (double)ioc_timercnt[tmr]; |
| 121 | | // logerror("IOC: starting timer %d, %d ticks, freq %f Hz\n", tmr, ioc_timercnt[tmr], freq); |
| 138 | // logerror("IOC: starting timer %d, %d ticks, freq %f Hz\n", tmr, ioc_timercnt[tmr], freq); |
| 122 | 139 | timer_adjust_oneshot(timer[tmr], ATTOTIME_IN_HZ(freq), tmr); |
| 123 | 140 | } |
| 124 | 141 | } |
| r8793 | r8794 | |
| 154 | 171 | memc_pages[i] = -1; // indicate unmapped |
| 155 | 172 | } |
| 156 | 173 | |
| 157 | | ioc_regs[4] = 0x10; //set up POR (Power On Reset) at start-up |
| 158 | | ioc_regs[8] = 0x02; //set up IL[1] On |
| 174 | ioc_regs[IRQ_STATUS_A] = 0x10 | 0x80; //set up POR (Power On Reset) and Force IRQ at start-up |
| 175 | ioc_regs[IRQ_STATUS_B] = 0x02; //set up IL[1] On |
| 176 | ioc_regs[FIQ_STATUS] = 0x80; //set up Force FIQ |
| 177 | |
| 178 | /* Aristocrat MK-5 tests this inside the CPU check routine *without* firing a latch command in the POST, could be open bus, fixed value or undefined behaviour, |
| 179 | almost surely something checked as an anti-cheat measure */ |
| 180 | ioc_timerout[1] = 0xf5; |
| 159 | 181 | } |
| 160 | 182 | |
| 161 | 183 | void archimedes_init(running_machine *machine) |
| r8793 | r8794 | |
| 205 | 227 | } |
| 206 | 228 | else |
| 207 | 229 | { |
| 208 | | logerror("ARCHIMEDES_MEMC: Reading unmapped page, what do we do?\n"); |
| 230 | logerror("ARCHIMEDES_MEMC: Reading unmapped page %02x\n",page); |
| 231 | return 0xdeadbeef; |
| 209 | 232 | } |
| 210 | 233 | } |
| 211 | 234 | |
| r8793 | r8794 | |
| 235 | 258 | } |
| 236 | 259 | else |
| 237 | 260 | { |
| 238 | | logerror("ARCHIMEDES_MEMC: Writing unmapped page, what do we do?\n"); |
| 261 | logerror("ARCHIMEDES_MEMC: Writing unmapped page %02x, what do we do?\n",page); |
| 239 | 262 | } |
| 240 | 263 | } |
| 241 | 264 | } |
| r8793 | r8794 | |
| 324 | 347 | #endif |
| 325 | 348 | if (offset*4 >= 0x200000 && offset*4 < 0x300000) |
| 326 | 349 | { |
| 350 | logerror("IOC: R %s = %02x (PC=%x) %02x\n", ioc_regnames[offset&0x1f], ioc_regs[offset&0x1f], cpu_get_pc( space->cpu ),offset & 0x1f); |
| 351 | |
| 327 | 352 | switch (offset & 0x1f) |
| 328 | 353 | { |
| 354 | case CONTROL: |
| 355 | { |
| 356 | UINT8 i2c_data; |
| 357 | |
| 358 | i2c_data = (i2cmem_sda_read(space->machine->device("i2cmem")) & 1); |
| 359 | |
| 360 | return (ioc_regs[CONTROL] & 0xfc) | (i2c_clk<<1) | i2c_data; |
| 361 | } |
| 362 | |
| 329 | 363 | case 1: // keyboard read |
| 330 | 364 | archimedes_request_irq_b(space->machine, ARCHIMEDES_IRQB_KBD_XMIT_EMPTY); |
| 331 | 365 | break; |
| 332 | 366 | |
| 367 | case IRQ_STATUS_A: |
| 368 | return (ioc_regs[IRQ_STATUS_A] & 0x7f) | 0x80; // Force IRQ is always '1' |
| 369 | |
| 370 | case FIQ_STATUS: |
| 371 | return (ioc_regs[FIQ_STATUS] & 0x7f) | 0x80; // Force FIQ is always '1' |
| 372 | |
| 333 | 373 | case 16: // timer 0 read |
| 334 | 374 | return ioc_timerout[0]&0xff; |
| 335 | 375 | case 17: |
| r8793 | r8794 | |
| 348 | 388 | return (ioc_timerout[3]>>8)&0xff; |
| 349 | 389 | } |
| 350 | 390 | |
| 351 | | logerror("IOC: R %s = %02x (PC=%x) %02x\n", ioc_regnames[offset&0x1f], ioc_regs[offset&0x1f], cpu_get_pc( space->cpu ),offset & 0x1f); |
| 352 | 391 | return ioc_regs[offset&0x1f]; |
| 353 | 392 | } |
| 354 | 393 | #ifdef MESS |
| r8793 | r8794 | |
| 375 | 414 | |
| 376 | 415 | if (offset*4 >= 0x200000 && offset*4 < 0x300000) |
| 377 | 416 | { |
| 378 | | // logerror("IOC: W %02x @ reg %s (PC=%x)\n", data&0xff, ioc_regnames[offset&0x1f], cpu_get_pc( space->cpu )); |
| 417 | logerror("IOC: W %02x @ reg %s (PC=%x)\n", data&0xff, ioc_regnames[offset&0x1f], cpu_get_pc( space->cpu )); |
| 379 | 418 | |
| 380 | 419 | switch (offset&0x1f) |
| 381 | 420 | { |
| 382 | 421 | case 0: // I2C bus control |
| 383 | 422 | //logerror("IOC I2C: CLK %d DAT %d\n", (data>>1)&1, data&1); |
| 423 | i2cmem_sda_write(space->machine->device("i2cmem"), data & 0x01); |
| 424 | i2cmem_scl_write(space->machine->device("i2cmem"), (data & 0x02) >> 1); |
| 425 | i2c_clk = (data & 2) >> 1; |
| 384 | 426 | break; |
| 385 | 427 | |
| 428 | case IRQ_MASK_A: |
| 429 | ioc_regs[IRQ_MASK_A] = data & 0xff; |
| 430 | |
| 431 | if(data & 0x80) //force an IRQ |
| 432 | archimedes_request_irq_a(space->machine,ARCHIMEDES_IRQA_FORCE); |
| 433 | |
| 434 | break; |
| 435 | |
| 436 | case FIQ_MASK: |
| 437 | ioc_regs[FIQ_MASK] = data & 0xff; |
| 438 | |
| 439 | if(data & 0x80) //force a FIRQ |
| 440 | archimedes_request_fiq(space->machine,ARCHIMEDES_FIQ_FORCE); |
| 441 | |
| 442 | break; |
| 443 | |
| 386 | 444 | case 5: // IRQ clear A |
| 387 | | ioc_regs[4] &= ~(data&0xff); |
| 445 | ioc_regs[IRQ_STATUS_A] &= ~(data&0xff); |
| 388 | 446 | |
| 389 | 447 | // if that did it, clear the IRQ |
| 390 | | if (ioc_regs[4] == 0) |
| 448 | if (ioc_regs[IRQ_STATUS_A] == 0) |
| 391 | 449 | { |
| 392 | 450 | cputag_set_input_line(space->machine, "maincpu", ARM_IRQ_LINE, CLEAR_LINE); |
| 393 | 451 | } |
| r8793 | r8794 | |
| 526 | 584 | }; |
| 527 | 585 | #endif |
| 528 | 586 | |
| 587 | |
| 529 | 588 | // 0x00 - 0x3c Video Palette Logical Colors (16 colors) |
| 530 | 589 | // 0x40 Border Color |
| 531 | 590 | // 0x44 - 0x4c Cursor Palette Logical Colors |
| r8793 | r8794 | |
| 604 | 663 | { |
| 605 | 664 | double sndhz; |
| 606 | 665 | |
| 607 | | sndhz = 250000.0 / (double)((vidc_regs[0xc0]&0xff)+2); |
| 666 | /* FIXME: is the frequency correct? */ |
| 667 | sndhz = (125000.0 / 2) / (double)((vidc_regs[0xc0]&0xff)+2); |
| 608 | 668 | |
| 609 | 669 | logerror("MEMC: Starting audio DMA at %f Hz, buffer from %x to %x\n", sndhz, vidc_sndstart, vidc_sndend); |
| 610 | 670 | |
| r8793 | r8794 | |
| 614 | 674 | } |
| 615 | 675 | else |
| 616 | 676 | { |
| 617 | | timer_adjust_oneshot(snd_timer, attotime_never, 0); |
| 618 | | dac_signed_data_w(space->machine->device("dac"), 0x80); |
| 677 | //timer_adjust_oneshot(snd_timer, attotime_never, 0); |
| 678 | //dac_signed_data_w(space->machine->device("dac"), 0x80); |
| 619 | 679 | } |
| 620 | 680 | break; |
| 621 | 681 | |