예제 #1
0
        unsafe bool retro_environment(LibRetro.RETRO_ENVIRONMENT cmd, IntPtr data)
        {
            Console.WriteLine(cmd);
            switch (cmd)
            {
            case LibRetro.RETRO_ENVIRONMENT.SET_ROTATION:
            {
                var rotation = (LibRetro.RETRO_ROTATION)(*(int *)data.ToPointer());
                if (rotation == LibRetro.RETRO_ROTATION.ROTATION_0_CCW)
                {
                    environmentInfo.Rotation_CCW = 0;
                }
                if (rotation == LibRetro.RETRO_ROTATION.ROTATION_90_CCW)
                {
                    environmentInfo.Rotation_CCW = 90;
                }
                if (rotation == LibRetro.RETRO_ROTATION.ROTATION_180_CCW)
                {
                    environmentInfo.Rotation_CCW = 180;
                }
                if (rotation == LibRetro.RETRO_ROTATION.ROTATION_270_CCW)
                {
                    environmentInfo.Rotation_CCW = 270;
                }
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.GET_OVERSCAN:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_CAN_DUPE:
                //gambatte requires this
                *(bool *)data.ToPointer() = true;
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_MESSAGE:
            {
                LibRetro.retro_message msg = new LibRetro.retro_message();
                Marshal.PtrToStructure(data, msg);
                if (!string.IsNullOrEmpty(msg.msg))
                {
                    Console.WriteLine("LibRetro Message: {0}", msg.msg);
                }
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.SHUTDOWN:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_PERFORMANCE_LEVEL:
                Console.WriteLine("Core suggested SET_PERFORMANCE_LEVEL {0}", *(uint *)data.ToPointer());
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.GET_SYSTEM_DIRECTORY:
                //mednafen NGP neopop fails to launch with no system directory
                Directory.CreateDirectory(SystemDirectory);                         //just to be safe, it seems likely that cores will crash without a created system directory
                Console.WriteLine("returning system directory: " + SystemDirectory);
                *((IntPtr *)data.ToPointer()) = SystemDirectoryAtom;
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_PIXEL_FORMAT:
            {
                LibRetro.RETRO_PIXEL_FORMAT fmt = 0;
                int[] tmp = new int[1];
                Marshal.Copy(data, tmp, 0, 1);
                fmt = (LibRetro.RETRO_PIXEL_FORMAT)tmp[0];
                switch (fmt)
                {
                case LibRetro.RETRO_PIXEL_FORMAT.RGB565:
                case LibRetro.RETRO_PIXEL_FORMAT.XRGB1555:
                case LibRetro.RETRO_PIXEL_FORMAT.XRGB8888:
                    pixelfmt = fmt;
                    Console.WriteLine("New pixel format set: {0}", pixelfmt);
                    return(true);

                default:
                    Console.WriteLine("Unrecognized pixel format: {0}", (int)pixelfmt);
                    return(false);
                }
            }

            case LibRetro.RETRO_ENVIRONMENT.SET_INPUT_DESCRIPTORS:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_KEYBOARD_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_DISK_CONTROL_INTERFACE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_HW_RENDER:
            {
                //mupen64plus needs this, as well as 3dengine
                LibRetro.retro_hw_render_callback *info = (LibRetro.retro_hw_render_callback *)data.ToPointer();
                Console.WriteLine("SET_HW_RENDER: {0}, version={1}.{2}, dbg/cache={3}/{4}, depth/stencil = {5}/{6}{7}", info->context_type, info->version_minor, info->version_major, info->debug_context, info->cache_context, info->depth, info->stencil, info->bottom_left_origin ? " (bottomleft)" : "");
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.GET_VARIABLE:
            {
                void **variables = (void **)data.ToPointer();
                IntPtr pKey      = new IntPtr(*variables++);
                string key       = Marshal.PtrToStringAnsi(pKey);
                Console.WriteLine("Requesting variable: {0}", key);
                //always return default
                //TODO: cache settings atoms
                if (!Description.Variables.ContainsKey(key))
                {
                    return(false);
                }
                //HACK: return pointer for desmume mouse, i want to implement that first
                if (key == "desmume_pointer_type")
                {
                    *variables = unmanagedResources.StringToHGlobalAnsi("touch").ToPointer();
                    return(true);
                }
                *variables = unmanagedResources.StringToHGlobalAnsi(Description.Variables[key].DefaultOption).ToPointer();
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.SET_VARIABLES:
            {
                void **variables = (void **)data.ToPointer();
                for (; ;)
                {
                    IntPtr pKey   = new IntPtr(*variables++);
                    IntPtr pValue = new IntPtr(*variables++);
                    if (pKey == IntPtr.Zero)
                    {
                        break;
                    }
                    string key   = Marshal.PtrToStringAnsi(pKey);
                    string value = Marshal.PtrToStringAnsi(pValue);
                    var    vd    = new VariableDescription()
                    {
                        Name = key
                    };
                    var parts = value.Split(';');
                    vd.Description = parts[0];
                    vd.Options     = parts[1].TrimStart(' ').Split('|');
                    Description.Variables[vd.Name] = vd;
                }
            }
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_VARIABLE_UPDATE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_SUPPORT_NO_GAME:
                environmentInfo.SupportNoGame = true;
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_LIBRETRO_PATH:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_AUDIO_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_FRAME_TIME_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_RUMBLE_INTERFACE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_INPUT_DEVICE_CAPABILITIES:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_LOG_INTERFACE:
                *(IntPtr *)data = Marshal.GetFunctionPointerForDelegate(retro_log_printf_cb);
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.GET_PERF_INTERFACE:
                //some builds of fmsx core crash without this set
                Marshal.StructureToPtr(retro_perf_callback, data, false);
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.GET_LOCATION_INTERFACE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_CORE_ASSETS_DIRECTORY:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_SAVE_DIRECTORY:
                //supposedly optional like everything else here, but without it ?? crashes (please write which case)
                //this will suffice for now. if we find evidence later it's needed we can stash a string with
                //unmanagedResources and CoreFileProvider
                //mednafen NGP neopop, desmume, and others, request this, and falls back on the system directory if it isn't provided
                //desmume crashes if the directory doesn't exist
                Directory.CreateDirectory(SaveDirectory);
                Console.WriteLine("returning save directory: " + SaveDirectory);
                *((IntPtr *)data.ToPointer()) = SaveDirectoryAtom;
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_CONTROLLER_INFO:
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_MEMORY_MAPS:
                return(false);

            default:
                Console.WriteLine("Unknkown retro_environment command {0}", (int)cmd);
                return(false);
            }
        }
예제 #2
0
        bool retro_environment(LibRetro.RETRO_ENVIRONMENT cmd, IntPtr data)
        {
            switch (cmd)
            {
            case LibRetro.RETRO_ENVIRONMENT.SET_ROTATION:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_OVERSCAN:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_CAN_DUPE:
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_MESSAGE:
            {
                LibRetro.retro_message msg = new LibRetro.retro_message();
                Marshal.PtrToStructure(data, msg);
                if (!string.IsNullOrEmpty(msg.msg))
                {
                    Console.WriteLine("LibRetro Message: {0}", msg.msg);
                }
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.SHUTDOWN:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_PERFORMANCE_LEVEL:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_SYSTEM_DIRECTORY:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_PIXEL_FORMAT:
            {
                LibRetro.RETRO_PIXEL_FORMAT fmt = 0;
                int[] tmp = new int[1];
                Marshal.Copy(data, tmp, 0, 1);
                fmt = (LibRetro.RETRO_PIXEL_FORMAT)tmp[0];
                switch (fmt)
                {
                case LibRetro.RETRO_PIXEL_FORMAT.RGB565:
                case LibRetro.RETRO_PIXEL_FORMAT.XRGB1555:
                case LibRetro.RETRO_PIXEL_FORMAT.XRGB8888:
                    pixelfmt = fmt;
                    Console.WriteLine("New pixel format set: {0}", pixelfmt);
                    return(true);

                default:
                    Console.WriteLine("Unrecognized pixel format: {0}", (int)pixelfmt);
                    return(false);
                }
            }

            case LibRetro.RETRO_ENVIRONMENT.SET_INPUT_DESCRIPTORS:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_KEYBOARD_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_DISK_CONTROL_INTERFACE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_HW_RENDER:
                // this can be done in principle, but there's no reason to right now
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_VARIABLE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_VARIABLES:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_VARIABLE_UPDATE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_SUPPORT_NO_GAME:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_LIBRETRO_PATH:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_AUDIO_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_FRAME_TIME_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_RUMBLE_INTERFACE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_INPUT_DEVICE_CAPABILITIES:
                return(false);

            default:
                Console.WriteLine("Unknkown retro_environment command {0}", (int)cmd);
                return(false);
            }
        }
예제 #3
0
 bool retro_environment(LibRetro.RETRO_ENVIRONMENT cmd, IntPtr data)
 {
     switch (cmd)
     {
         case LibRetro.RETRO_ENVIRONMENT.SET_ROTATION:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.GET_OVERSCAN:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.GET_CAN_DUPE:
             return true;
         case LibRetro.RETRO_ENVIRONMENT.SET_MESSAGE:
             {
                 LibRetro.retro_message msg = new LibRetro.retro_message();
                 Marshal.PtrToStructure(data, msg);
                 if (!string.IsNullOrEmpty(msg.msg))
                     Console.WriteLine("LibRetro Message: {0}", msg.msg);
                 return true;
             }
         case LibRetro.RETRO_ENVIRONMENT.SHUTDOWN:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_PERFORMANCE_LEVEL:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.GET_SYSTEM_DIRECTORY:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_PIXEL_FORMAT:
             {
                 LibRetro.RETRO_PIXEL_FORMAT fmt = 0;
                 int[] tmp = new int[1];
                 Marshal.Copy(data, tmp, 0, 1);
                 fmt = (LibRetro.RETRO_PIXEL_FORMAT)tmp[0];
                 switch (fmt)
                 {
                     case LibRetro.RETRO_PIXEL_FORMAT.RGB565:
                     case LibRetro.RETRO_PIXEL_FORMAT.XRGB1555:
                     case LibRetro.RETRO_PIXEL_FORMAT.XRGB8888:
                         pixelfmt = fmt;
                         Console.WriteLine("New pixel format set: {0}", pixelfmt);
                         return true;
                     default:
                         Console.WriteLine("Unrecognized pixel format: {0}", (int)pixelfmt);
                         return false;
                 }
             }
         case LibRetro.RETRO_ENVIRONMENT.SET_INPUT_DESCRIPTORS:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_KEYBOARD_CALLBACK:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_DISK_CONTROL_INTERFACE:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_HW_RENDER:
             // this can be done in principle, but there's no reason to right now
             return false;
         case LibRetro.RETRO_ENVIRONMENT.GET_VARIABLE:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_VARIABLES:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.GET_VARIABLE_UPDATE:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_SUPPORT_NO_GAME:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.GET_LIBRETRO_PATH:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_AUDIO_CALLBACK:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.SET_FRAME_TIME_CALLBACK:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.GET_RUMBLE_INTERFACE:
             return false;
         case LibRetro.RETRO_ENVIRONMENT.GET_INPUT_DEVICE_CAPABILITIES:
             return false;
         default:
             Console.WriteLine("Unknkown retro_environment command {0}", (int)cmd);
             return false;
     }
 }