Example #1
0
        public void nes_set_mute_mask(byte ChipID, UInt32 MuteMask)
        {
            if (NESAPUData[ChipID] == null)
            {
                return;
            }

            nes_state info = NESAPUData[ChipID];

            //    switch (EMU_CORE)
            //    {
            //# ifdef ENABLE_ALL_CORES
            //        case EC_MAME:
            //            nesapu_set_mute_mask(info->chip_apu, MuteMask);
            //            break;
            //#endif
            //        case EC_NSFPLAY:
            if (nes_apu != null && info.chip_apu != null)
            {
                nes_apu.NES_APU_np_SetMask(info.chip_apu, (Int32)((MuteMask & 0x03) >> 0));
            }
            if (nes_dmc != null && info.chip_dmc != null)
            {
                nes_dmc.NES_DMC_np_SetMask(info.chip_dmc, (Int32)((MuteMask & 0x1C) >> 2));
            }
            //        break;
            //}
            if (nes_fds != null && info.chip_fds != null)
            {
                nes_fds.NES_FDS_SetMask(info.chip_fds, (Int32)((MuteMask & 0x20) >> 5));
            }

            return;
        }
Example #2
0
        private void device_stop_nes(byte ChipID)
        {
            nes_state info = NESAPUData[ChipID];

            //            switch (EMU_CORE)
            //            {
            //# ifdef ENABLE_ALL_CORES
            //                case EC_MAME:
            //                    device_stop_nesapu(info->chip_apu);
            //                    break;
            //#endif
            //                case EC_NSFPLAY:
            nes_apu.NES_APU_np_Destroy(info.chip_apu);
            nes_dmc.NES_DMC_np_Destroy(info.chip_dmc);
            //                    break;
            //            }
            if (info.chip_fds != null)
            {
                nes_fds.NES_FDS_Destroy(info.chip_fds);
            }

            if (info.Memory != null)
            {
                //free(info.Memory);
                info.Memory = null;
            }
            info.chip_apu = null;
            info.chip_dmc = null;
            info.chip_fds = null;

            return;
        }
Example #3
0
        public void nes_write_ram(byte ChipID, Int32 DataStart, Int32 DataLength, byte[] RAMData, Int32 RAMDataStartAdr)
        {
            nes_state info = NESAPUData[ChipID];
            UInt32    RemainBytes;
            UInt32    ptrRAMData = 0;

            if (DataStart >= 0x10000)
            {
                return;
            }

            if (DataStart < 0x8000)
            {
                if (DataStart + DataLength <= 0x8000)
                {
                    return;
                }

                RemainBytes = (UInt32)(0x8000 - DataStart);
                DataStart   = 0x8000;
                //RAMData += RemainBytes;
                ptrRAMData  = RemainBytes;
                DataLength -= (Int32)RemainBytes;
            }

            RemainBytes = 0x00;
            if (DataStart + DataLength > 0x10000)
            {
                RemainBytes  = (UInt32)DataLength;
                DataLength   = 0x10000 - DataStart;
                RemainBytes -= (UInt32)DataLength;
            }

            //memcpy(info.Memory + (DataStart - 0x8000), RAMData, DataLength);
            for (int i = 0; i < DataLength; i++)
            {
                info.Memory[(DataStart - 0x8000) + i] = RAMData[ptrRAMData + i + RAMDataStartAdr];
            }

            if (RemainBytes != 0)
            {
                if (RemainBytes > 0x8000)
                {
                    RemainBytes = 0x8000;
                }
                //memcpy(info->Memory, RAMData + DataLength, RemainBytes);
                for (int i = 0; i < RemainBytes; i++)
                {
                    info.Memory[ptrRAMData + DataLength + i] = RAMData[ptrRAMData + DataLength + i + RAMDataStartAdr];
                }
            }

            return;
        }
Example #4
0
        private void nes_set_chip_option(byte ChipID)
        {
            nes_state info = NESAPUData[ChipID];
            byte      CurOpt;

            if ((NesOptions & 0x8000) != 0)
            {
                return;
            }

            //    switch (EMU_CORE)
            //    {
            //# ifdef ENABLE_ALL_CORES
            //        case EC_MAME:
            //            // no options for MAME's NES core
            //            break;
            //#endif
            //        case EC_NSFPLAY:
            // shared APU/DMC options
            for (CurOpt = 0; CurOpt < 2; CurOpt++)
            {
                nes_apu.NES_APU_np_SetOption(info.chip_apu, CurOpt, (NesOptions >> CurOpt) & 0x01);
                nes_dmc.NES_DMC_np_SetOption(info.chip_dmc, CurOpt, (NesOptions >> CurOpt) & 0x01);
            }
            // APU-only options
            for (; CurOpt < 4; CurOpt++)
            {
                nes_apu.NES_APU_np_SetOption(info.chip_apu, CurOpt - 2 + 2, (NesOptions >> CurOpt) & 0x01);
            }
            // DMC-only options
            for (; CurOpt < 10; CurOpt++)
            {
                nes_dmc.NES_DMC_np_SetOption(info.chip_dmc, CurOpt - 4 + 2, (NesOptions >> CurOpt) & 0x01);
            }
            //            break;
            //    }
            if (info.chip_fds != null)
            {
                // FDS options
                // I skip the Cutoff frequency here, since it's not a boolean value.
                for (CurOpt = 12; CurOpt < 14; CurOpt++)
                {
                    nes_fds.NES_FDS_SetOption(info.chip_fds, CurOpt - 12 + 1, (NesOptions >> CurOpt) & 0x01);
                }
            }

            return;
        }
Example #5
0
        private void nes_w(byte ChipID, Int32 offset, byte data)
        {
            nes_state info = NESAPUData[ChipID];

            switch (offset & 0xE0)
            {
            case 0x00:      // NES APU
                            //                    switch (EMU_CORE)
                            //                    {
                            //# ifdef ENABLE_ALL_CORES
                            //                        case EC_MAME:
                            //                            nes_psg_w(info->chip_apu, offset, data);
                            //                            break;
                            //#endif
                            //                        case EC_NSFPLAY:
                            // NES_APU handles the sqaure waves, NES_DMC the rest
                nes_apu.NES_APU_np_Write(info.chip_apu, (UInt32)(0x4000 | offset), data);
                nes_dmc.NES_DMC_np_Write(info.chip_dmc, (UInt32)(0x4000 | offset), data);
                //                            break;
                //                    }
                break;

            case 0x20:      // FDS register
                if (info.chip_fds == null)
                {
                    break;
                }
                if (offset == 0x3F)
                {
                    nes_fds.NES_FDS_Write(info.chip_fds, 0x4023, data);
                }
                else
                {
                    nes_fds.NES_FDS_Write(info.chip_fds, (UInt32)(0x4080 | (offset & 0x1F)), data);
                }
                break;

            case 0x40:      // FDS wave RAM
            case 0x60:
                if (info.chip_fds == null)
                {
                    break;
                }
                nes_fds.NES_FDS_Write(info.chip_fds, (UInt32)(0x4000 | offset), data);
                break;
            }
        }
Example #6
0
        //static void nes_set_chip_option(UINT8 ChipID);

        public void nes_stream_update(byte ChipID, Int32[][] outputs, Int32 samples)
        {
            nes_state info = NESAPUData[ChipID];
            int       CurSmpl;

            Int32[] BufferA = new Int32[2];
            Int32[] BufferD = new Int32[2];
            Int32[] BufferF = new Int32[2];

            //            switch (EMU_CORE)
            //            {
            //# ifdef ENABLE_ALL_CORES
            //                case EC_MAME:
            //                    nes_psg_update_sound(info->chip_apu, outputs, samples);
            //                   break;
            //#endif
            //                case EC_NSFPLAY:
            for (CurSmpl = 0x00; CurSmpl < samples; CurSmpl++)
            {
                nes_apu.NES_APU_np_Render(info.chip_apu, BufferA);
                nes_dmc.NES_DMC_np_Render(info.chip_dmc, BufferD);
                outputs[0][CurSmpl]       = (short)((Limit(BufferA[0], 0x7fff, -0x8000) * apuVolume) >> 14);
                outputs[1][CurSmpl]       = (short)((Limit(BufferA[1], 0x7fff, -0x8000) * apuVolume) >> 14);
                outputs[0][CurSmpl]      += (short)((Limit(BufferD[0], 0x7fff, -0x8000) * dmcVolume) >> 14);
                outputs[1][CurSmpl]      += (short)((Limit(BufferD[1], 0x7fff, -0x8000) * dmcVolume) >> 14);
                MDSound.np_nes_apu_volume = Math.Abs(BufferA[0]);
                MDSound.np_nes_dmc_volume = Math.Abs(BufferD[0]);
            }
            //                    break;
            //            }

            if (info.chip_fds != null)
            {
                for (CurSmpl = 0x00; CurSmpl < samples; CurSmpl++)
                {
                    nes_fds.NES_FDS_Render(info.chip_fds, BufferF);
                    outputs[0][CurSmpl]      += (short)((Limit(BufferF[0], 0x7fff, -0x8000) * fdsVolume) >> 14);
                    outputs[1][CurSmpl]      += (short)((Limit(BufferF[1], 0x7fff, -0x8000) * fdsVolume) >> 14);
                    MDSound.np_nes_fds_volume = Math.Abs(BufferF[0]);
                }
            }

            return;
        }
Example #7
0
        private void device_reset_nes(byte ChipID)
        {
            nes_state info = NESAPUData[ChipID];

            //            switch (EMU_CORE)
            //            {
            //# ifdef ENABLE_ALL_CORES
            //                case EC_MAME:
            //                    device_reset_nesapu(info->chip_apu);
            //                    break;
            //#endif
            //                case EC_NSFPLAY:
            nes_apu.NES_APU_np_Reset(info.chip_apu);
            nes_dmc.NES_DMC_np_Reset(info.chip_dmc);
            //                    break;
            //            }
            if (info.chip_fds != null)
            {
                nes_fds.NES_FDS_Reset(info.chip_fds);
            }
        }
Example #8
0
        //static void nes_set_chip_option(UINT8 ChipID);

        public void nes_stream_update(byte ChipID, Int32[][] outputs, Int32 samples)
        {
            nes_state info = NESAPUData[ChipID];
            int       CurSmpl;

            Int32[] BufferA = new Int32[2];
            Int32[] BufferD = new Int32[2];
            Int32[] BufferF = new Int32[2];

            //            switch (EMU_CORE)
            //            {
            //# ifdef ENABLE_ALL_CORES
            //                case EC_MAME:
            //                    nes_psg_update_sound(info->chip_apu, outputs, samples);
            //                   break;
            //#endif
            //                case EC_NSFPLAY:
            for (CurSmpl = 0x00; CurSmpl < samples; CurSmpl++)
            {
                nes_apu.NES_APU_np_Render(info.chip_apu, BufferA);
                nes_dmc.NES_DMC_np_Render(info.chip_dmc, BufferD);
                outputs[0][CurSmpl] = BufferA[0] + BufferD[0];
                outputs[1][CurSmpl] = BufferA[1] + BufferD[1];
            }
            //                    break;
            //            }

            if (info.chip_fds != null)
            {
                for (CurSmpl = 0x00; CurSmpl < samples; CurSmpl++)
                {
                    nes_fds.NES_FDS_Render(info.chip_fds, BufferF);
                    outputs[0][CurSmpl] += BufferF[0];
                    outputs[1][CurSmpl] += BufferF[1];
                }
            }

            return;
        }