Esempio n. 1
0
        //private NES_AUDIO_HANDLER[] heshes_audio_handler = new NES_AUDIO_HANDLER[]{
        //    { 0, ExecuteHES, 0, },
        //    { 3, HESSoundRenderMono, HESSoundRenderStereo },
        //    { 0, 0, 0, },
        //};

        private void HESHESVolume(NEZ_PLAY pNezPlay, UInt32 v)
        {
            if (((NEZ_PLAY)pNezPlay).heshes != null)
            {
                volume((HESHES)((NEZ_PLAY)pNezPlay).heshes, v);
            }
        }
Esempio n. 2
0
        //private NES_VOLUME_HANDLER[] heshes_volume_handler = new NES_VOLUME_HANDLER[]{
        //    { HESHESVolume, },
        //    { 0, },
        //};

        public void HESHESReset(NEZ_PLAY pNezPlay)
        {
            if (((NEZ_PLAY)pNezPlay).heshes != null)
            {
                reset((NEZ_PLAY)pNezPlay);
            }
        }
Esempio n. 3
0
        //private NES_TERMINATE_HANDLER[] heshes_terminate_handler = new NES_TERMINATE_HANDLER[] {
        //    { HESHESTerminate, },
        //    { 0, },
        //};

        public UInt32 HESLoad(NEZ_PLAY pNezPlay, byte[] pData, UInt32 uSize)
        {
            UInt32 ret;
            HESHES THIS_;

            //if (pNezPlay.heshes!=0) ((byte[])(0)) = 0;    /* ASSERT */
            //THIS_ = (HESHES)XMALLOC(sizeof(HESHES));
            THIS_ = new HESHES();
            if (THIS_ == null)
            {
                return((UInt32)NESERR.SHORTOFMEMORY);
            }
            ret = load(pNezPlay, THIS_, pData, uSize);
            if (ret != 0)
            {
                terminate(THIS_);
                return(ret);
            }
            pNezPlay.heshes = THIS_;
            //NESAudioHandlerInstall(pNezPlay, heshes_audio_handler);
            //NESVolumeHandlerInstall(pNezPlay, heshes_volume_handler);
            //NESResetHandlerInstall(pNezPlay.nrh, heshes_reset_handler);
            //NESTerminateHandlerInstall(pNezPlay.nth, heshes_terminate_handler);
            return(ret);
        }
Esempio n. 4
0
        //private NES_RESET_HANDLER[] heshes_reset_handler = new NES_RESET_HANDLER[] {
        //    { NES_RESET_SYS_LAST, HESHESReset, },
        //    { 0,                  0, },
        //};

        private void HESHESTerminate(NEZ_PLAY pNezPlay)
        {
            if (((NEZ_PLAY)pNezPlay).heshes != null)
            {
                terminate((HESHES)((NEZ_PLAY)pNezPlay).heshes);
                ((NEZ_PLAY)pNezPlay).heshes = null;
            }
        }
Esempio n. 5
0
 public Int32 HESSoundRenderMono(NEZ_PLAY pNezPlay)
 {
     Int32[] d = new Int32[2] {
         0, 0
     };
     synth((HESHES)((NEZ_PLAY)pNezPlay).heshes, d);
     //#if (((-1) >> 1) == -1)
     //	return (d[0] + d[1]) >> 1;
     //#else
     return((d[0] + d[1]) / 2);
     //#endif
 }
Esempio n. 6
0
 public void HESSoundRenderStereo(NEZ_PLAY pNezPlay, Int32[] d)
 {
     synth((HESHES)((NEZ_PLAY)pNezPlay).heshes, d);
 }
Esempio n. 7
0
 public Int32 ExecuteHES(NEZ_PLAY pNezPlay)
 {
     return(((NEZ_PLAY)pNezPlay).heshes != null?execute((HESHES)((NEZ_PLAY)pNezPlay).heshes) : 0);
 }
Esempio n. 8
0
        private UInt32 load(NEZ_PLAY pNezPlay, HESHES THIS_, byte[] pData, UInt32 uSize)
        {
            UInt32 i, p;

            //XMEMSET(THIS_, 0, sizeof(HESHES));
            //THIS_ = new HESHES();
            //THIS_.hessnd = 0;
            //THIS_.hespcm = 0;
            for (i = 0; i < 0x100; i++)
            {
                THIS_.memmap[i] = null;
            }

            if (uSize < 0x20)
            {
                return((UInt32)NESERR.FORMAT);
            }
            pNezPlay.song.startsongno = (UInt32)(pData[5] + 1);
            pNezPlay.song.songno      = (UInt32)256;
            pNezPlay.song.channel     = (UInt32)2;
            pNezPlay.song.extdevice   = (UInt32)0;
            for (i = 0; i < 8; i++)
            {
                THIS_.firstmpr[i] = pData[8 + i];
            }
            THIS_.playerromaddr       = 0x1ff0;
            THIS_.initaddr            = GetWordLE(pData, 0x06);
            pNezPlay.song.initaddress = THIS_.initaddr;
            pNezPlay.song.playaddress = 0;

            _songinfodata.detail = string.Format(
                @"Type           : HES
Start Song: {0:X2}
Init Address: {1:X4}
First Mapper 0 : {0:X2}
First Mapper 1 : {0:X2}
First Mapper 2 : {0:X2}
First Mapper 3 : {0:X2}
First Mapper 4 : {0:X2}
First Mapper 5 : {0:X2}
First Mapper 6 : {0:X2}
First Mapper 7 : {0:X2}"
                , pData[5], THIS_.initaddr
                , pData[0x8]
                , pData[0x9]
                , pData[0xa]
                , pData[0xb]
                , pData[0xc]
                , pData[0xd]
                , pData[0xe]
                , pData[0xf]
                );

            if (alloc_physical_address(THIS_, 0xf8 << 13, 0x2000) == 0) /* RAM */
            {
                return((UInt32)NESERR.SHORTOFMEMORY);
            }
            if (alloc_physical_address(THIS_, 0xf9 << 13, 0x2000) == 0) /* SGX-RAM */
            {
                return((UInt32)NESERR.SHORTOFMEMORY);
            }
            if (alloc_physical_address(THIS_, 0xfa << 13, 0x2000) == 0) /* SGX-RAM */
            {
                return((UInt32)NESERR.SHORTOFMEMORY);
            }
            if (alloc_physical_address(THIS_, 0xfb << 13, 0x2000) == 0) /* SGX-RAM */
            {
                return((UInt32)NESERR.SHORTOFMEMORY);
            }
            if (alloc_physical_address(THIS_, 0x00 << 13, 0x2000) == 0) /* IPL-ROM */
            {
                return((UInt32)NESERR.SHORTOFMEMORY);
            }
            for (p = 0x10; p + 0x10 < uSize; p += 0x10 + GetDwordLE(pData, p + 4))
            {
                if (GetDwordLE(pData, p) == 0x41544144)     /* 'DATA' */
                {
                    UInt32 a, l;
                    l = GetDwordLE(pData, p + 4);
                    a = GetDwordLE(pData, p + 8);
                    if (alloc_physical_address(THIS_, a, l) == 0)
                    {
                        return((UInt32)NESERR.SHORTOFMEMORY);
                    }
                    if (l > uSize - p - 0x10)
                    {
                        l = uSize - p - 0x10;
                    }
                    UInt32 q = p + 0x10;
                    copy_physical_address(THIS_, a, l, pData, ref q);
                    p = q;
                }
            }
            //THIS_.hessnd = HESSoundAlloc();
            //if (THIS_.hessnd == 0) return NESERR_SHORTOFMEMORY;
            THIS_.hespcm = (new s_hesad()).HESAdPcmAlloc();
            if (THIS_.hespcm == null)
            {
                return((UInt32)NESERR.SHORTOFMEMORY);
            }

            return((UInt32)NESERR.NOERROR);
        }
Esempio n. 9
0
        //----------
        //extern Uint32 pce_ioview_ioread_bf(Uint32);

        //public delegate UInt32 dump_DEV_HUC6230(UInt32 a, byte[] mem);
        //private UInt32 dump_DEV_HUC6230_bf(UInt32 menu, byte[] mem)
        //{
        //    Int32 i;
        //    switch (menu)
        //    {
        //        case 1://Register 1
        //            for (i = 0; i < 0x0a; i++)
        //                mem[i] = pce_ioview_ioread_bf(i);
        //            return (UInt32)i;

        //        case 2://Register 2
        //            for (i = 0; i < 0x60; i++)
        //                mem[i] = pce_ioview_ioread_bf(i + 0x22);
        //            return (UInt32)i;

        //        case 3://Wave Data - CH1
        //        case 4://Wave Data - CH2
        //        case 5://Wave Data - CH3
        //        case 6://Wave Data - CH4
        //        case 7://Wave Data - CH5
        //        case 8://Wave Data - CH6
        //            for (i = 0; i < 0x20; i++)
        //                mem[i] = pce_ioview_ioread_bf(i + 0x100 + (menu - 3) * 0x20);
        //            return (UInt32)i;
        //    }
        //    return (UInt32)0xfffffffe;// (-2);
        //}
        //----------
        //extern Uint32 (* ioview_ioread_DEV_ADPCM) (Uint32 a);
        //extern Uint32 (* ioview_ioread_DEV_ADPCM2) (Uint32 a);

        //public delegate UInt32 dump_DEV_ADPCM(UInt32 a, byte[] mem);
        //private UInt32 dump_DEV_ADPCM_bf(UInt32 menu, byte[] mem)
        //{
        //    Int32 i;
        //    switch (menu)
        //    {
        //        case 1://Register 1
        //            for (i = 0; i < 0x8; i++)
        //                mem[i] = ioview_ioread_DEV_ADPCM(i + 8);
        //            return (UInt32)i;
        //        case 2://Register 2[ADR/LEN]
        //            for (i = 0; i < 0x6; i++)
        //                mem[i] = ioview_ioread_DEV_ADPCM(i + 0x10);
        //            return (UInt32)i;
        //        case 3://Memory
        //            for (i = 0; i < 0x10000; i++)
        //            {
        //                if (ioview_ioread_DEV_ADPCM2(i) == 0x100) break;
        //                mem[i] = ioview_ioread_DEV_ADPCM2(i);
        //            }
        //            return (UInt32)i;

        //    }
        //    return (UInt32)0xfffffffe;// (-2);
        //}
        //----------

        private void reset(NEZ_PLAY pNezPlay)
        {
            HESHES THIS_ = pNezPlay.heshes;
            UInt32 i, initbreak;
            //UInt32 freq = NESAudioFrequencyGet(pNezPlay);
            UInt32 freq = 44100;

            //THIS_.hessnd.reset(THIS_.hessnd.ctx, HES_BASECYCLES, freq);
            THIS_.hespcm.reset(THIS_.hespcm.ctx, HES_BASECYCLES, freq);
            kmevent.kmevent_init(THIS_.kme);

            /* RAM CLEAR */
            for (i = 0xf8; i <= 0xfb; i++)
            {
                if (THIS_.memmap[i] != null)
                {
                    //XMEMSET(THIS_.memmap[i], 0, 0x2000);
                    THIS_.memmap[i] = new byte[0x2000];
                }
            }

            THIS_.cps           = DivFix(HES_BASECYCLES, freq, SHIFT_CPS);
            THIS_.ctx           = new km6280.K6280_Context();
            THIS_.ctx.user      = THIS_;
            THIS_.ctx.ReadByte  = read_event;
            THIS_.ctx.WriteByte = write_event;
            THIS_.ctx.ReadMPR   = readmpr_event;
            THIS_.ctx.WriteMPR  = writempr_event;
            THIS_.ctx.Write6270 = write6270_event;

            THIS_.vsync = kmevent.kmevent_alloc(THIS_.kme);
            THIS_.timer = kmevent.kmevent_alloc(THIS_.kme);
            kmevent.kmevent_setevent(THIS_.kme, THIS_.vsync, vsync_event, THIS_);
            kmevent.kmevent_setevent(THIS_.kme, THIS_.timer, timer_event, THIS_);

            THIS_.bp = THIS_.playerromaddr + 3;
            for (i = 0; i < 8; i++)
            {
                THIS_.mpr[i] = THIS_.firstmpr[i];
            }

            THIS_.breaked = 0;
            THIS_.cpsrem  = THIS_.cpsgap = THIS_.total_cycles = 0;

            //THIS_.ctx.A = (SONGINFO_GetSongNo(pNezPlay.song) - 1) & 0xff;
            THIS_.ctx.A = (UInt32)((pNezPlay.song.songno - 1) & 0xff);
            //THIS_.ctx.A = (UInt32)((49 - 1) & 0xff);
            THIS_.ctx.P            = (UInt32)km6280.K6280_FLAGS.K6280_Z_FLAG + (UInt32)km6280.K6280_FLAGS.K6280_I_FLAG;
            THIS_.ctx.X            = THIS_.ctx.Y = 0;
            THIS_.ctx.S            = 0xFF;
            THIS_.ctx.PC           = THIS_.playerromaddr;
            THIS_.ctx.iRequest     = 0;
            THIS_.ctx.iMask        = 0xffffffff;// ~0;
            THIS_.ctx.lowClockMode = 0;

            THIS_.playerrom[0x00] = 0x20;  /* JSR */
            THIS_.playerrom[0x01] = (byte)((THIS_.initaddr >> 0) & 0xff);
            THIS_.playerrom[0x02] = (byte)((THIS_.initaddr >> 8) & 0xff);
            THIS_.playerrom[0x03] = 0x4c;  /* JMP */
            THIS_.playerrom[0x04] = (byte)(((THIS_.playerromaddr + 3) >> 0) & 0xff);
            THIS_.playerrom[0x05] = (byte)(((THIS_.playerromaddr + 3) >> 8) & 0xff);

            THIS_.hesvdc_STATUS = 0;
            THIS_.hesvdc_CR     = 0;
            THIS_.hesvdc_ADR    = 0;
            vsync_setup(THIS_);
            THIS_.hestim_RELOAD = THIS_.hestim_COUNTER = THIS_.hestim_START = 0;
            timer_setup(THIS_);

            /* request execute(5sec) */
            initbreak = 5 << 8;
            while (THIS_.breaked == 0 && --initbreak != 0)
            {
                km6280_exec(THIS_.ctx, HES_BASECYCLES >> 8);
            }

            if (THIS_.breaked != 0)
            {
                THIS_.breaked = 0;
                THIS_.ctx.P  &= 0xfffffffb;// ~km6280.K6280_FLAGS.K6280_I_FLAG;
            }

            THIS_.cpsrem = THIS_.cpsgap = THIS_.total_cycles = 0;

            //ここからメモリービュアー設定
            //memview_context = THIS_;
            //MEM_MAX = 0xffff;
            //MEM_IO = 0x0000;
            //MEM_RAM = 0x2000;
            //MEM_ROM = 0x4000;
            //memview_memread = memview_memread_hes;
            //ここまでメモリービュアー設定

            //ここからダンプ設定
            //pNezPlayDump = pNezPlay;
            //dump_MEM_PCE = dump_MEM_PCE_bf;
            //dump_DEV_HUC6230 = dump_DEV_HUC6230_bf;
            //dump_DEV_ADPCM = dump_DEV_ADPCM_bf;
            //ここまでダンプ設定
        }