trunk/src/mess/machine/nes_konami.c
| r22538 | r22539 | |
| 62 | 62 | { |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | | nes_konami_vrc3_device::nes_konami_vrc3_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) |
| 66 | | : nes_nrom_device(mconfig, type, name, tag, owner, clock, shortname, source) |
| 65 | nes_konami_vrc3_device::nes_konami_vrc3_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 66 | : nes_nrom_device(mconfig, NES_VRC3, "NES Cart Konami VRC-3 PCB", tag, owner, clock, "nes_vrc3", __FILE__) |
| 67 | 67 | { |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | | nes_konami_vrc3_device::nes_konami_vrc3_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 71 | | : nes_nrom_device(mconfig, NES_VRC3, "NES Cart Konami VRC-3 PCB", tag, owner, clock, "nes_vrc3", __FILE__) |
| 70 | nes_konami_vrc4_device::nes_konami_vrc4_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) |
| 71 | : nes_nrom_device(mconfig, type, name, tag, owner, clock, shortname, source) |
| 72 | 72 | { |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | nes_konami_vrc4_device::nes_konami_vrc4_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 76 | | : nes_konami_vrc3_device(mconfig, NES_VRC4, "NES Cart Konami VRC-4 PCB", tag, owner, clock, "nes_vrc4", __FILE__) |
| 76 | : nes_nrom_device(mconfig, NES_VRC4, "NES Cart Konami VRC-4 PCB", tag, owner, clock, "nes_vrc4", __FILE__) |
| 77 | 77 | { |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | nes_konami_vrc6_device::nes_konami_vrc6_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 81 | | : nes_konami_vrc3_device(mconfig, NES_VRC6, "NES Cart Konami VRC-6 PCB", tag, owner, clock, "nes_vrc6", __FILE__) |
| 81 | : nes_konami_vrc4_device(mconfig, NES_VRC6, "NES Cart Konami VRC-6 PCB", tag, owner, clock, "nes_vrc6", __FILE__) |
| 82 | 82 | { |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | nes_konami_vrc7_device::nes_konami_vrc7_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 86 | | : nes_konami_vrc3_device(mconfig, NES_VRC7, "NES Cart Konami VRC-7 PCB", tag, owner, clock, "nes_vrc7", __FILE__) |
| 86 | : nes_konami_vrc4_device(mconfig, NES_VRC7, "NES Cart Konami VRC-7 PCB", tag, owner, clock, "nes_vrc7", __FILE__) |
| 87 | 87 | { |
| 88 | 88 | } |
| 89 | 89 | |
| r22538 | r22539 | |
| 126 | 126 | void nes_konami_vrc3_device::device_start() |
| 127 | 127 | { |
| 128 | 128 | common_start(); |
| 129 | irq_timer = timer_alloc(TIMER_IRQ); |
| 130 | irq_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1)); |
| 131 | |
| 132 | save_item(NAME(m_irq_mode)); |
| 129 | 133 | save_item(NAME(m_irq_enable)); |
| 130 | 134 | save_item(NAME(m_irq_enable_latch)); |
| 131 | 135 | save_item(NAME(m_irq_count)); |
| r22538 | r22539 | |
| 139 | 143 | prg16_cdef(m_prg_chunks - 1); |
| 140 | 144 | chr8(0, m_chr_source); |
| 141 | 145 | |
| 146 | m_irq_mode = 0; |
| 142 | 147 | m_irq_enable = 0; |
| 143 | 148 | m_irq_enable_latch = 0; |
| 144 | 149 | m_irq_count = 0; |
| r22538 | r22539 | |
| 149 | 154 | void nes_konami_vrc4_device::device_start() |
| 150 | 155 | { |
| 151 | 156 | common_start(); |
| 157 | irq_timer = timer_alloc(TIMER_IRQ); |
| 158 | irq_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1)); |
| 159 | |
| 152 | 160 | save_item(NAME(m_irq_mode)); |
| 161 | save_item(NAME(m_irq_prescale)); |
| 153 | 162 | save_item(NAME(m_irq_enable)); |
| 154 | 163 | save_item(NAME(m_irq_enable_latch)); |
| 155 | 164 | save_item(NAME(m_irq_count)); |
| r22538 | r22539 | |
| 167 | 176 | chr8(0, m_chr_source); |
| 168 | 177 | |
| 169 | 178 | m_irq_mode = 0; |
| 179 | m_irq_prescale = 341; |
| 170 | 180 | m_irq_enable = 0; |
| 171 | 181 | m_irq_enable_latch = 0; |
| 172 | 182 | m_irq_count = 0; |
| r22538 | r22539 | |
| 182 | 192 | m_ym2413 = device().subdevice("ym"); |
| 183 | 193 | |
| 184 | 194 | common_start(); |
| 195 | irq_timer = timer_alloc(TIMER_IRQ); |
| 196 | irq_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1)); |
| 197 | |
| 198 | save_item(NAME(m_irq_mode)); |
| 199 | save_item(NAME(m_irq_prescale)); |
| 185 | 200 | save_item(NAME(m_irq_enable)); |
| 186 | 201 | save_item(NAME(m_irq_enable_latch)); |
| 187 | 202 | save_item(NAME(m_irq_count)); |
| r22538 | r22539 | |
| 197 | 212 | prg8_ef(0xff); |
| 198 | 213 | chr8(0, m_chr_source); |
| 199 | 214 | |
| 215 | m_irq_mode = 0; |
| 216 | m_irq_prescale = 341; |
| 200 | 217 | m_irq_enable = 0; |
| 201 | 218 | m_irq_enable_latch = 0; |
| 202 | 219 | m_irq_count = 0; |
| r22538 | r22539 | |
| 333 | 350 | |
| 334 | 351 | iNES: mapper 73 |
| 335 | 352 | |
| 336 | | In MESS: Supported. It also uses konami_irq. |
| 353 | In MESS: Supported. |
| 337 | 354 | |
| 338 | 355 | -------------------------------------------------*/ |
| 339 | 356 | |
| 340 | | void nes_konami_vrc3_device::hblank_irq(int scanline, int vblank, int blanked) |
| 357 | void nes_konami_vrc3_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 341 | 358 | { |
| 342 | | /* Increment & check the IRQ scanline counter */ |
| 343 | | if (m_irq_enable && (++m_irq_count == 0x100)) |
| 359 | if (id == TIMER_IRQ) |
| 344 | 360 | { |
| 345 | | m_irq_count = m_irq_count_latch; |
| 346 | | m_irq_enable = m_irq_enable_latch; |
| 347 | | machine().device("maincpu")->execute().set_input_line(M6502_IRQ_LINE, HOLD_LINE); |
| 361 | if (m_irq_enable) |
| 362 | { |
| 363 | if (m_irq_mode) // 8bits mode |
| 364 | { |
| 365 | if ((m_irq_count & 0x00ff) == 0xff) |
| 366 | { |
| 367 | machine().device("maincpu")->execute().set_input_line(M6502_IRQ_LINE, HOLD_LINE); |
| 368 | m_irq_count = m_irq_count_latch; |
| 369 | } |
| 370 | else |
| 371 | m_irq_count = (m_irq_count & 0xff00) | ((m_irq_count & 0x00ff) + 1); |
| 372 | } |
| 373 | else // 16bits mode |
| 374 | { |
| 375 | if (m_irq_count == 0xffff) |
| 376 | { |
| 377 | machine().device("maincpu")->execute().set_input_line(M6502_IRQ_LINE, HOLD_LINE); |
| 378 | m_irq_count = m_irq_count_latch; |
| 379 | } |
| 380 | else |
| 381 | m_irq_count++; |
| 382 | } |
| 383 | } |
| 348 | 384 | } |
| 349 | 385 | } |
| 350 | 386 | |
| r22538 | r22539 | |
| 355 | 391 | switch (offset & 0x7000) |
| 356 | 392 | { |
| 357 | 393 | case 0x0000: |
| 394 | m_irq_count_latch = (m_irq_count_latch & 0xfff0) | ((data & 0x0f) << 0); |
| 395 | break; |
| 358 | 396 | case 0x1000: |
| 359 | | /* dunno which address controls these */ |
| 360 | | m_irq_count_latch = data; |
| 361 | | m_irq_enable_latch = data; |
| 397 | m_irq_count_latch = (m_irq_count_latch & 0xff0f) | ((data & 0x0f) << 4); |
| 362 | 398 | break; |
| 363 | 399 | case 0x2000: |
| 364 | | m_irq_enable = data; |
| 400 | m_irq_count_latch = (m_irq_count_latch & 0xf0ff) | ((data & 0x0f) << 8); |
| 365 | 401 | break; |
| 366 | 402 | case 0x3000: |
| 367 | | m_irq_count &= ~0x0f; |
| 368 | | m_irq_count |= data & 0x0f; |
| 403 | m_irq_count_latch = (m_irq_count_latch & 0x0fff) | ((data & 0x0f) << 12); |
| 369 | 404 | break; |
| 370 | 405 | case 0x4000: |
| 371 | | m_irq_count &= ~0xf0; |
| 372 | | m_irq_count |= (data & 0x0f) << 4; |
| 406 | m_irq_mode = data & 0x04; |
| 407 | m_irq_enable = data & 0x02; |
| 408 | m_irq_enable_latch = data & 0x01; |
| 409 | if (data & 0x02) |
| 410 | m_irq_count = m_irq_count_latch; |
| 373 | 411 | break; |
| 412 | case 0x5000: |
| 413 | m_irq_enable = m_irq_enable_latch; |
| 414 | break; |
| 374 | 415 | case 0x7000: |
| 375 | 416 | prg16_89ab(data); |
| 376 | 417 | break; |
| r22538 | r22539 | |
| 388 | 429 | |
| 389 | 430 | -------------------------------------------------*/ |
| 390 | 431 | |
| 432 | void nes_konami_vrc4_device::irq_tick() |
| 433 | { |
| 434 | if (m_irq_count == 0xff) |
| 435 | { |
| 436 | m_irq_count = m_irq_count_latch; |
| 437 | machine().device("maincpu")->execute().set_input_line(M6502_IRQ_LINE, HOLD_LINE); |
| 438 | } |
| 439 | else |
| 440 | m_irq_count++; |
| 441 | } |
| 442 | |
| 443 | void nes_konami_vrc4_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 444 | { |
| 445 | if (id == TIMER_IRQ) |
| 446 | { |
| 447 | if (m_irq_enable) |
| 448 | { |
| 449 | if (m_irq_mode) // cycle mode |
| 450 | irq_tick(); |
| 451 | else // scanline mode |
| 452 | { |
| 453 | // A prescaler divides the passing CPU cycles by 114, 114, then 113 (and repeats that order). |
| 454 | // This approximates 113+2/3 CPU cycles, which is one NTSC scanline. |
| 455 | // Since this is a CPU-based IRQ, though, it is triggered also during non visible scanlines... |
| 456 | if (m_irq_prescale < 3) |
| 457 | { |
| 458 | m_irq_prescale += 341; |
| 459 | irq_tick(); |
| 460 | } |
| 461 | |
| 462 | m_irq_prescale -= 3; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 391 | 468 | void nes_konami_vrc4_device::set_prg() |
| 392 | 469 | { |
| 393 | 470 | if (m_latch & 0x02) |
trunk/src/mess/machine/nes_konami.h
| r22538 | r22539 | |
| 51 | 51 | { |
| 52 | 52 | public: |
| 53 | 53 | // construction/destruction |
| 54 | | nes_konami_vrc3_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); |
| 55 | 54 | nes_konami_vrc3_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 56 | 55 | |
| 57 | 56 | // device-level overrides |
| 58 | 57 | virtual void device_start(); |
| 58 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 59 | 59 | virtual DECLARE_WRITE8_MEMBER(write_h); |
| 60 | 60 | |
| 61 | | virtual void hblank_irq(int scanline, int vblank, int blanked); |
| 62 | 61 | virtual void pcb_reset(); |
| 63 | 62 | |
| 64 | | protected: |
| 63 | private: |
| 65 | 64 | UINT16 m_irq_count, m_irq_count_latch; |
| 66 | 65 | int m_irq_enable, m_irq_enable_latch; |
| 67 | | int m_irq_mode; // used by VRC-4, VRC-6 & VRC-7. currently not implemented: 0 = prescaler mode / 1 = CPU mode |
| 66 | int m_irq_mode; |
| 67 | |
| 68 | static const device_timer_id TIMER_IRQ = 0; |
| 69 | emu_timer *irq_timer; |
| 68 | 70 | }; |
| 69 | 71 | |
| 70 | 72 | |
| 71 | 73 | // ======================> nes_konami_vrc4_device |
| 72 | 74 | |
| 73 | | class nes_konami_vrc4_device : public nes_konami_vrc3_device |
| 75 | class nes_konami_vrc4_device : public nes_nrom_device |
| 74 | 76 | { |
| 75 | 77 | public: |
| 76 | 78 | // construction/destruction |
| 79 | nes_konami_vrc4_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); |
| 77 | 80 | nes_konami_vrc4_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 78 | 81 | |
| 79 | 82 | // device-level overrides |
| 80 | 83 | virtual void device_start(); |
| 84 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 81 | 85 | virtual DECLARE_WRITE8_MEMBER(write_h); |
| 82 | 86 | |
| 83 | 87 | virtual void pcb_reset(); |
| 84 | 88 | |
| 85 | | private: |
| 89 | protected: |
| 86 | 90 | void set_prg(); |
| 87 | 91 | UINT8 m_mmc_vrom_bank[8]; |
| 88 | 92 | UINT8 m_latch, m_mmc_prg_bank; |
| 93 | |
| 94 | void irq_tick(); |
| 95 | UINT16 m_irq_count, m_irq_count_latch; |
| 96 | int m_irq_enable, m_irq_enable_latch; |
| 97 | int m_irq_mode; |
| 98 | int m_irq_prescale; |
| 99 | |
| 100 | static const device_timer_id TIMER_IRQ = 0; |
| 101 | emu_timer *irq_timer; |
| 89 | 102 | }; |
| 90 | 103 | |
| 91 | 104 | |
| 92 | 105 | // ======================> nes_konami_vrc6_device |
| 93 | 106 | |
| 94 | | class nes_konami_vrc6_device : public nes_konami_vrc3_device |
| 107 | class nes_konami_vrc6_device : public nes_konami_vrc4_device |
| 95 | 108 | { |
| 96 | 109 | public: |
| 97 | 110 | // construction/destruction |
| r22538 | r22539 | |
| 106 | 119 | |
| 107 | 120 | // ======================> nes_konami_vrc7_device |
| 108 | 121 | |
| 109 | | class nes_konami_vrc7_device : public nes_konami_vrc3_device |
| 122 | class nes_konami_vrc7_device : public nes_konami_vrc4_device |
| 110 | 123 | { |
| 111 | 124 | public: |
| 112 | 125 | // construction/destruction |