Example #1
0
        void _WriteReg(int addr, byte val)
        {
            //Console.WriteLine("{0:X4} = {1:X2}", addr, val);
            int index   = addr - 0x4000;
            int reg     = index & 3;
            int channel = index >> 2;

            switch (channel)
            {
            case 0:
                pulse[0].WriteReg(reg, val);
                break;

            case 1:
                pulse[1].WriteReg(reg, val);
                break;

            case 2:
                triangle.WriteReg(reg, val);
                break;

            case 3:
                noise.WriteReg(reg, val);
                break;

            case 4:
                dmc.WriteReg(reg, val);
                break;

            case 5:
                if (addr == 0x4015)
                {
                    pulse[0].set_lenctr_en(val & 1);
                    pulse[1].set_lenctr_en((val >> 1) & 1);
                    triangle.set_lenctr_en((val >> 2) & 1);
                    noise.set_lenctr_en((val >> 3) & 1);
                    dmc.set_lenctr_en(val.Bit(4));
                }
                else if (addr == 0x4017)
                {
                    //Console.WriteLine("apu 4017 = {0:X2}", val);
                    sequencer_mode        = (val >> 7) & 1;
                    sequencer_irq_inhibit = (val >> 6) & 1;
                    if (sequencer_irq_inhibit == 1)
                    {
                        sequencer_irq_clear_pending = true;
                    }
                    sequence_reset_pending = true;
                    break;
                }
                break;
            }
        }
Example #2
0
		void _WriteReg(int addr, byte val)
		{
			//Console.WriteLine("{0:X4} = {1:X2}", addr, val);
			int index = addr - 0x4000;
			int reg = index & 3;
			int channel = index >> 2;
			switch (channel)
			{
				case 0:
					pulse[0].WriteReg(reg, val);
					break;
				case 1:
					pulse[1].WriteReg(reg, val);
					break;
				case 2:
					triangle.WriteReg(reg, val);
					break;
				case 3:
					noise.WriteReg(reg, val);
					break;
				case 4:
					dmc.WriteReg(reg, val);
					break;
				case 5:
					if (addr == 0x4015)
					{
						pulse[0].set_lenctr_en(val & 1);
						pulse[1].set_lenctr_en((val >> 1) & 1);
						triangle.set_lenctr_en((val >> 2) & 1);
						noise.set_lenctr_en((val >> 3) & 1);
						dmc.set_lenctr_en(val.Bit(4));

					}
					else if (addr == 0x4017)
					{
						if (dmc.timer%2==0)
						{
							seq_tick = 3;

						} else
						{
							seq_tick = 4;
						}
						
						seq_val = val;
					}
					break;
			}
		}