Previous 199869 Revisions Next

r22539 Thursday 25th April, 2013 at 10:14:13 UTC by Fabio Priuli
(MESS) NES IRQ clean up part 2: Konami IRQs are now implemented based on the docs
and not kludged (in particular, now they are cycle based too). nw.
+ a minor fix for NT restore...
[src/mess/machine]nes_konami.c nes_konami.h nes_slot.c nes_sunsoft.c

trunk/src/mess/machine/nes_sunsoft.c
r22538r22539
314314         break;
315315      case 0x6800:
316316         switch (data & 3)
317      {
318         case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
319         case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
320         case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
321         case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
322      }
317         {
318            case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
319            case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
320            case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
321            case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
322         }
323323         break;
324324      case 0x7800:
325325         prg16_89ab(data);
trunk/src/mess/machine/nes_konami.c
r22538r22539
6262{
6363}
6464
65nes_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)
65nes_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__)
6767{
6868}
6969
70nes_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__)
70nes_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)
7272{
7373}
7474
7575nes_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__)
7777{
7878}
7979
8080nes_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__)
8282{
8383}
8484
8585nes_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__)
8787{
8888}
8989
r22538r22539
126126void nes_konami_vrc3_device::device_start()
127127{
128128   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));
129133   save_item(NAME(m_irq_enable));
130134   save_item(NAME(m_irq_enable_latch));
131135   save_item(NAME(m_irq_count));
r22538r22539
139143   prg16_cdef(m_prg_chunks - 1);
140144   chr8(0, m_chr_source);
141145
146   m_irq_mode = 0;
142147   m_irq_enable = 0;
143148   m_irq_enable_latch = 0;
144149   m_irq_count = 0;
r22538r22539
149154void nes_konami_vrc4_device::device_start()
150155{
151156   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   
152160   save_item(NAME(m_irq_mode));
161   save_item(NAME(m_irq_prescale));
153162   save_item(NAME(m_irq_enable));
154163   save_item(NAME(m_irq_enable_latch));
155164   save_item(NAME(m_irq_count));
r22538r22539
167176   chr8(0, m_chr_source);
168177
169178   m_irq_mode = 0;
179   m_irq_prescale = 341;
170180   m_irq_enable = 0;
171181   m_irq_enable_latch = 0;
172182   m_irq_count = 0;
r22538r22539
182192   m_ym2413 = device().subdevice("ym");
183193
184194   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));
185200   save_item(NAME(m_irq_enable));
186201   save_item(NAME(m_irq_enable_latch));
187202   save_item(NAME(m_irq_count));
r22538r22539
197212   prg8_ef(0xff);
198213   chr8(0, m_chr_source);
199214
215   m_irq_mode = 0;
216   m_irq_prescale = 341;
200217   m_irq_enable = 0;
201218   m_irq_enable_latch = 0;
202219   m_irq_count = 0;
r22538r22539
333350
334351 iNES: mapper 73
335352
336 In MESS: Supported. It also uses konami_irq.
353 In MESS: Supported.
337354
338355 -------------------------------------------------*/
339356
340void nes_konami_vrc3_device::hblank_irq(int scanline, int vblank, int blanked)
357void nes_konami_vrc3_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
341358{
342   /* Increment & check the IRQ scanline counter */
343   if (m_irq_enable && (++m_irq_count == 0x100))
359   if (id == TIMER_IRQ)
344360   {
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      }
348384   }
349385}
350386
r22538r22539
355391   switch (offset & 0x7000)
356392   {
357393      case 0x0000:
394         m_irq_count_latch = (m_irq_count_latch & 0xfff0) | ((data & 0x0f) << 0);
395         break;
358396      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);
362398         break;
363399      case 0x2000:
364         m_irq_enable = data;
400         m_irq_count_latch = (m_irq_count_latch & 0xf0ff) | ((data & 0x0f) << 8);
365401         break;
366402      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);
369404         break;
370405      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;
373411         break;
412      case 0x5000:
413         m_irq_enable = m_irq_enable_latch;
414         break;
374415      case 0x7000:
375416         prg16_89ab(data);
376417         break;
r22538r22539
388429
389430 -------------------------------------------------*/
390431
432void 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
443void 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
391468void nes_konami_vrc4_device::set_prg()
392469{
393470   if (m_latch & 0x02)
trunk/src/mess/machine/nes_slot.c
r22538r22539
734734      chr1_x(i, m_chr_orig[i] / 0x400, m_chr_src[i]);
735735
736736   for (int i = 0; i < 4; i++)
737      set_nt_page(i, m_nt_src[i], m_nt_orig[i], m_nt_writable[i]);
737      set_nt_page(i, m_nt_src[i], m_nt_orig[i] / 0x400, m_nt_writable[i]);
738738
739739   set_nt_mirroring(m_mirroring);
740740}
trunk/src/mess/machine/nes_konami.h
r22538r22539
5151{
5252public:
5353   // 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);
5554   nes_konami_vrc3_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
5655
5756   // device-level overrides
5857   virtual void device_start();
58   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
5959   virtual DECLARE_WRITE8_MEMBER(write_h);
6060
61   virtual void hblank_irq(int scanline, int vblank, int blanked);
6261   virtual void pcb_reset();
6362
64protected:
63private:
6564   UINT16 m_irq_count, m_irq_count_latch;
6665   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;
6870};
6971
7072
7173// ======================> nes_konami_vrc4_device
7274
73class nes_konami_vrc4_device : public nes_konami_vrc3_device
75class nes_konami_vrc4_device : public nes_nrom_device
7476{
7577public:
7678   // 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);
7780   nes_konami_vrc4_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
7881
7982   // device-level overrides
8083   virtual void device_start();
84   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
8185   virtual DECLARE_WRITE8_MEMBER(write_h);
8286
8387   virtual void pcb_reset();
8488
85private:
89protected:
8690   void set_prg();
8791   UINT8 m_mmc_vrom_bank[8];
8892   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;
89102};
90103
91104
92105// ======================> nes_konami_vrc6_device
93106
94class nes_konami_vrc6_device : public nes_konami_vrc3_device
107class nes_konami_vrc6_device : public nes_konami_vrc4_device
95108{
96109public:
97110   // construction/destruction
r22538r22539
106119
107120// ======================> nes_konami_vrc7_device
108121
109class nes_konami_vrc7_device : public nes_konami_vrc3_device
122class nes_konami_vrc7_device : public nes_konami_vrc4_device
110123{
111124public:
112125   // construction/destruction

Previous 199869 Revisions Next


© 1997-2024 The MAME Team