public static void VibrationSound()
        {
            //consider writing the bit that makes the text flash
            Microsoft.Xna.Framework.Audio.SoundEffect sound = SoundEffect.FromStream(TitleContainer.OpenStream("Assets/sound.wav"));

            AppSettings settings = new AppSettings();

            if (settings.ToggleSwitchVibration)
            {
                Microsoft.Devices.VibrateController testVibrateController = Microsoft.Devices.VibrateController.Default;
                testVibrateController.Start(TimeSpan.FromSeconds(3));
            }
            if (settings.ToggleSwitchSound)
            {
                FrameworkDispatcher.Update();
                sound.Play();
            }
        }
        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            // maybe use some pretty reflection mechanism to find all syscall implementations here..
            syscalls.maCheckInterfaceVersion = delegate(int hash)
            {
                if (MoSync.Constants.MoSyncHash != (uint)hash)
                    MoSync.Util.CriticalError("Invalid hash!");
                return hash;
            };

            syscalls.maPanic = delegate(int code, int str)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(str);
                MoSync.Util.CriticalError(message + "\ncode: " + code);
            };

            syscalls.maExit = delegate(int res)
            {
                MoSync.Util.Exit(res);
            };

            DateTime startDate = System.DateTime.Now;
            syscalls.maGetMilliSecondCount = delegate()
            {
                System.TimeSpan offset = (System.DateTime.Now - startDate);

                return offset.Milliseconds + (offset.Seconds + (offset.Minutes + (offset.Hours + offset.Days * 24) * 60) * 60) * 1000;
            };

            syscalls.maTime = delegate()
            {
                return (int)Util.ToUnixTimeUtc(System.DateTime.Now);
            };

            syscalls.maLocalTime = delegate()
            {
                return (int)Util.ToUnixTime(System.DateTime.Now);
            };

            syscalls.maCreatePlaceholder = delegate()
            {
                Resource res = new Resource(null, MoSync.Constants.RT_PLACEHOLDER, true);
                return runtime.AddResource(res);
            };

            syscalls.maDestroyPlaceholder = delegate(int res)
            {
                if (!runtime.GetResource(0, res).IsDynamicPlaceholder())
                    MoSync.Util.CriticalError("maDestroyPlaceholder can only be used on handles created by maCreatePlaceholder.");
                runtime.RemoveResource(res);
            };

            syscalls.maFindLabel = delegate(int _name)
            {
                String name = core.GetDataMemory().ReadStringAtAddress(_name);
                int res;
                if (runtime.mLabels.TryGetValue(name, out res))
                    return res;
                else
                    return -1;
            };

            syscalls.maResetBacklight = delegate()
            {
            };

            syscalls.maVibrate = delegate(int _ms)
            {
                if (mVibrateController == null)
                    mVibrateController = Microsoft.Devices.VibrateController.Default;

                if (_ms < 0)
                    return _ms;
                else if (_ms == 0)
                    mVibrateController.Stop();
                else
                    mVibrateController.Start(TimeSpan.FromMilliseconds(_ms));

                return 0;
            };

            syscalls.maLoadProgram = delegate(int _data, int _reload)
            {
            #if REBUILD
                throw new Exception("maLoadProgram not available in rebuild mode");
            #else
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                //Memory mem = (Memory)res.GetInternalObject();
                Stream mem = (Stream)res.GetInternalObject();
                MoSync.Machine.SetLoadProgram(mem, _reload != 0);
                throw new Util.ExitException(0);
            #endif
            };
        }
        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            // maybe use some pretty reflection mechanism to find all syscall implementations here..
            syscalls.maCheckInterfaceVersion = delegate(int hash)
            {
                if (MoSync.Constants.MoSyncHash != (uint)hash)
                    MoSync.Util.CriticalError("Invalid hash!");
                return hash;
            };

            syscalls.maPanic = delegate(int code, int str)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(str);
                MoSync.Util.CriticalError(message + "\ncode: " + code);
            };

            syscalls.maExit = delegate(int res)
            {
                mCore.Stop();
            };

            DateTime startDate = System.DateTime.Now;
            syscalls.maGetMilliSecondCount = delegate()
            {
                System.TimeSpan offset = (System.DateTime.Now - startDate);

                return offset.Milliseconds + (offset.Seconds + (offset.Minutes + (offset.Hours + offset.Days * 24) * 60) * 60) * 1000;
            };

            syscalls.maTime = delegate()
            {
                return (int)Util.ToUnixTimeUtc(System.DateTime.Now);
            };

            syscalls.maLocalTime = delegate()
            {
                return (int)Util.ToUnixTime(System.DateTime.Now);
            };

            syscalls.maCreatePlaceholder = delegate()
            {
                Resource res = new Resource(null, MoSync.Constants.RT_PLACEHOLDER, true);
                return runtime.AddResource(res);
            };

            syscalls.maDestroyPlaceholder = delegate(int res)
            {
                if (!runtime.GetResource(0, res).IsDynamicPlaceholder())
                    MoSync.Util.CriticalError("maDestroyPlaceholder can only be used on handles created by maCreatePlaceholder.");
                runtime.RemoveResource(res);
            };

            syscalls.maFindLabel = delegate(int _name)
            {
                String name = core.GetDataMemory().ReadStringAtAddress(_name);
                int res;
                if (runtime.mLabels.TryGetValue(name, out res))
                    return res;
                else
                    return -1;
            };

            /*
             * PhoneApplicationService.Current.UserIdleDetectionMode
             * Disabling this will stop the screen from timing out and locking.
             * Discussion: this needs to be re-enabled for the backlight to work
             *             so an maStartBacklight should be needed for WP7;
             *             what about maToggleBacklight(bool)?
             *
             * We have maWakeLock instead on Windows Phone, Android, iOS.
             */
            syscalls.maResetBacklight = delegate()
            {
            };

            syscalls.maVibrate = delegate(int _ms)
            {
                if (mVibrateController == null)
                    mVibrateController = Microsoft.Devices.VibrateController.Default;

                // more than 5 seconds aren't allowed..
                if (_ms > 5000)
                    _ms = 5000;

                if (_ms < 0)
                    return _ms;
                else if (_ms == 0)
                    mVibrateController.Stop();
                else
                    mVibrateController.Start(TimeSpan.FromMilliseconds(_ms));

                return 1;
            };

            syscalls.maLoadProgram = delegate(int _data, int _reload)
            {
            #if REBUILD
                throw new Exception("maLoadProgram not available in rebuild mode");
            #elif !LIB
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                //Memory mem = (Memory)res.GetInternalObject();
                Stream mem = (Stream)res.GetInternalObject();
                MoSync.Machine.SetLoadProgram(mem, _reload != 0);
                throw new Util.ExitException(0);
            #endif
            };
        }
Exemple #4
0
        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            // maybe use some pretty reflection mechanism to find all syscall implementations here..
            syscalls.maCheckInterfaceVersion = delegate(int hash)
            {
                if (MoSync.Constants.MoSyncHash != (uint)hash)
                {
                    MoSync.Util.CriticalError("Invalid hash!");
                }
                return(hash);
            };

            syscalls.maPanic = delegate(int code, int str)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(str);
                MoSync.Util.CriticalError(message + "\ncode: " + code);
            };

            syscalls.maExit = delegate(int res)
            {
                MoSync.Util.Exit(res);
            };

            DateTime startDate = System.DateTime.Now;

            syscalls.maGetMilliSecondCount = delegate()
            {
                System.TimeSpan offset = (System.DateTime.Now - startDate);

                return(offset.Milliseconds + (offset.Seconds + (offset.Minutes + (offset.Hours + offset.Days * 24) * 60) * 60) * 1000);
            };

            syscalls.maTime = delegate()
            {
                return((int)Util.ToUnixTimeUtc(System.DateTime.Now));
            };

            syscalls.maLocalTime = delegate()
            {
                return((int)Util.ToUnixTime(System.DateTime.Now));
            };

            syscalls.maCreatePlaceholder = delegate()
            {
                Resource res = new Resource(null, MoSync.Constants.RT_PLACEHOLDER, true);
                return(runtime.AddResource(res));
            };

            syscalls.maDestroyPlaceholder = delegate(int res)
            {
                if (!runtime.GetResource(0, res).IsDynamicPlaceholder())
                {
                    MoSync.Util.CriticalError("maDestroyPlaceholder can only be used on handles created by maCreatePlaceholder.");
                }
                runtime.RemoveResource(res);
            };

            syscalls.maFindLabel = delegate(int _name)
            {
                String name = core.GetDataMemory().ReadStringAtAddress(_name);
                int    res;
                if (runtime.mLabels.TryGetValue(name, out res))
                {
                    return(res);
                }
                else
                {
                    return(-1);
                }
            };

            /*
             * PhoneApplicationService.Current.UserIdleDetectionMode
             * Disabling this will stop the screen from timing out and locking.
             * Discussion: this needs to be re-enabled for the backlight to work
             *             so an maStartBacklight should be needed for WP7;
             *             what about maToggleBacklight(bool)?
             *
             * We have maWakeLock instead on Windows Phone, Android, iOS.
             */
            syscalls.maResetBacklight = delegate()
            {
            };

            syscalls.maVibrate = delegate(int _ms)
            {
                if (mVibrateController == null)
                {
                    mVibrateController = Microsoft.Devices.VibrateController.Default;
                }

                // more than 5 seconds aren't allowed..
                if (_ms > 5000)
                {
                    _ms = 5000;
                }

                if (_ms < 0)
                {
                    return(_ms);
                }
                else if (_ms == 0)
                {
                    mVibrateController.Stop();
                }
                else
                {
                    mVibrateController.Start(TimeSpan.FromMilliseconds(_ms));
                }

                return(1);
            };

            syscalls.maLoadProgram = delegate(int _data, int _reload)
            {
#if REBUILD
                throw new Exception("maLoadProgram not available in rebuild mode");
#else
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                //Memory mem = (Memory)res.GetInternalObject();
                Stream mem = (Stream)res.GetInternalObject();
                MoSync.Machine.SetLoadProgram(mem, _reload != 0);
                throw new Util.ExitException(0);
#endif
            };
        }