コード例 #1
0
        /*-----------------------------------------------------------------------------
        *   osd_file::open: open a new file.
        *
        *   Parameters:
        *
        *       path - path to the file to open
        *
        *       openflags - some combination of:
        *
        *           OPEN_FLAG_READ - open the file for read access
        *           OPEN_FLAG_WRITE - open the file for write access
        *           OPEN_FLAG_CREATE - create/truncate the file when opening
        *           OPEN_FLAG_CREATE_PATHS - specifies that non-existant paths
        *                   should be created if necessary
        *
        *       file - reference to an osd_file::ptr to receive the newly-opened file
        *           handle; this is only valid if the function returns FILERR_NONE
        *
        *       filesize - reference to a UINT64 to receive the size of the opened
        *           file; this is only valid if the function returns FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while opening
        *       the file, or FILERR_NONE if no error occurred
        *
        *   Notes:
        *
        *       This function is called by core_fopen and several other places in
        *       the core to access files. These functions will construct paths by
        *       concatenating various search paths held in the options.c options
        *       database with partial paths specified by the core. The core assumes
        *       that the path separator is the first character of the string
        *       PATH_SEPARATOR, but does not interpret any path separators in the
        *       search paths, so if you use a different path separator in a search
        *       path, you may get a mixture of PATH_SEPARATORs (from the core) and
        *       alternate path separators (specified by users and placed into the
        *       options database).
        *  -----------------------------------------------------------------------------*/
        public override std.error_condition open(string path, UInt32 openflags, out osd_file file, out UInt64 filesize)
        {
            m_file = null;
            file   = this;
            try
            {
                if ((openflags & OPEN_FLAG_WRITE) != 0)
                {
                    FileMode fileMode = FileMode.Open;
                    if ((openflags & OPEN_FLAG_CREATE) != 0)
                    {
                        fileMode = FileMode.Create;
                    }

                    m_file = File.Open(path, fileMode);
                }
                else
                {
                    if (File.Exists(path))
                    {
                        m_file = File.OpenRead(path);
                    }
                    else
                    {
                        // try the path next to the executable
                        string exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);  // path to the exe
                        string newPath = Path.Combine(exePath, path);
                        if (File.Exists(newPath))
                        {
                            m_file = File.OpenRead(newPath);
                        }
                        else
                        {
                            // try the path two folders up, if eg, we're running from the \bin\Release folder
                            newPath = Path.Combine(exePath, @"..\..\");
                            newPath = Path.Combine(newPath, path);
                            if (File.Exists(newPath))
                            {
                                m_file = File.OpenRead(newPath);
                            }
                            else
                            {
                                filesize = 0;
                                return(std.errc.no_such_file_or_directory);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                m_file   = null;
                filesize = 0;
                return(std.errc.no_such_file_or_directory);
            }

            filesize = (UInt64)m_file.Length;
            return(new std.error_condition());
        }
コード例 #2
0
ファイル: osdcore_Unity.cs プロジェクト: kwanboy/mcs
        /*-----------------------------------------------------------------------------
        *   osd_close: close an open file
        *
        *   Parameters:
        *
        *       file - handle to a file previously opened via osd_open
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while closing
        *       the file, or FILERR_NONE if no error occurred
        *  -----------------------------------------------------------------------------*/
        public osd_file.error osd_close(ref osd_file file)
        {
            throw new emu_fatalerror("TODO - Fix inheritence");

            //osd_file_Unity fileWinForms = (osd_file_Unity)file;
            //
            ////if (fileWinForms.m_file != null)
            ////    fileWinForms.m_file.Close();
            //
            //file = null;
            //return osd_file.error.NONE;
        }
コード例 #3
0
        /*-----------------------------------------------------------------------------
        *   osd_close: close an open file
        *
        *   Parameters:
        *
        *       file - handle to a file previously opened via osd_open
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while closing
        *       the file, or FILERR_NONE if no error occurred
        *  -----------------------------------------------------------------------------*/
        public osd_file.error osd_close(ref osd_file file)
        {
            throw new emu_fatalerror("Fix inheritence");

            osd_file_WinForms fileWinForms = (osd_file_WinForms)file;

            if (fileWinForms.m_file != null)
            {
                fileWinForms.m_file.Close();
            }

            file = null;
            return(osd_file.error.NONE);
        }
コード例 #4
0
        /*-----------------------------------------------------------------------------
        *   osd_close: close an open file
        *
        *   Parameters:
        *
        *       file - handle to a file previously opened via osd_open
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while closing
        *       the file, or FILERR_NONE if no error occurred
        *  -----------------------------------------------------------------------------*/
        public std.error_condition osd_close(ref osd_file file)
        {
            throw new emu_fatalerror("Fix inheritence");

            osd_file_WinForms fileWinForms = (osd_file_WinForms)file;

            if (fileWinForms.m_file != null)
            {
                fileWinForms.m_file.Close();
            }

            file = null;
            return(new std.error_condition());
        }
コード例 #5
0
        /*-----------------------------------------------------------------------------
        *   osd_file::open: open a new file.
        *
        *   Parameters:
        *
        *       path - path to the file to open
        *
        *       openflags - some combination of:
        *
        *           OPEN_FLAG_READ - open the file for read access
        *           OPEN_FLAG_WRITE - open the file for write access
        *           OPEN_FLAG_CREATE - create/truncate the file when opening
        *           OPEN_FLAG_CREATE_PATHS - specifies that non-existant paths
        *                   should be created if necessary
        *
        *       file - reference to an osd_file::ptr to receive the newly-opened file
        *           handle; this is only valid if the function returns FILERR_NONE
        *
        *       filesize - reference to a UINT64 to receive the size of the opened
        *           file; this is only valid if the function returns FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while opening
        *       the file, or FILERR_NONE if no error occurred
        *
        *   Notes:
        *
        *       This function is called by core_fopen and several other places in
        *       the core to access files. These functions will construct paths by
        *       concatenating various search paths held in the options.c options
        *       database with partial paths specified by the core. The core assumes
        *       that the path separator is the first character of the string
        *       PATH_SEPARATOR, but does not interpret any path separators in the
        *       search paths, so if you use a different path separator in a search
        *       path, you may get a mixture of PATH_SEPARATORs (from the core) and
        *       alternate path separators (specified by users and placed into the
        *       options database).
        *  -----------------------------------------------------------------------------*/
        public override error open(string path, UInt32 openflags, out osd_file file, out UInt64 filesize)
        {
            m_file = null;
            file   = this;
            try
            {
                if (File.Exists(path))
                {
                    m_file = File.OpenRead(path);
                }
                else
                {
                    // try the path next to the executable
                    string exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);  // path to the exe
                    string newPath = Path.Combine(exePath, path);
                    if (File.Exists(newPath))
                    {
                        m_file = File.OpenRead(newPath);
                    }
                    else
                    {
                        // try the path two folders up, if eg, we're running from the \bin\Release folder
                        newPath = Path.Combine(exePath, @"..\..\");
                        newPath = Path.Combine(newPath, path);
                        if (File.Exists(newPath))
                        {
                            m_file = File.OpenRead(newPath);
                        }
                        else
                        {
                            filesize = 0;
                            return(osd_file.error.NOT_FOUND);
                        }
                    }
                }
            }
            catch (Exception)
            {
                m_file   = null;
                filesize = 0;
                return(osd_file.error.NOT_FOUND);
            }

            filesize = (UInt64)m_file.Length;
            return(osd_file.error.NONE);
        }
コード例 #6
0
ファイル: osdcore_Unity.cs プロジェクト: kwanboy/mcs
        /*-----------------------------------------------------------------------------
        *   osd_open: open a new file.
        *
        *   Parameters:
        *
        *       path - path to the file to open
        *
        *       openflags - some combination of:
        *
        *           OPEN_FLAG_READ - open the file for read access
        *           OPEN_FLAG_WRITE - open the file for write access
        *           OPEN_FLAG_CREATE - create/truncate the file when opening
        *           OPEN_FLAG_CREATE_PATHS - specifies that non-existant paths
        *                   should be created if necessary
        *
        *       file - pointer to an osd_file * to receive the newly-opened file
        *           handle; this is only valid if the function returns FILERR_NONE
        *
        *       filesize - pointer to a UINT64 to receive the size of the opened
        *           file; this is only valid if the function returns FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while opening
        *       the file, or FILERR_NONE if no error occurred
        *
        *   Notes:
        *
        *       This function is called by core_fopen and several other places in
        *       the core to access files. These functions will construct paths by
        *       concatenating various search paths held in the options.c options
        *       database with partial paths specified by the core. The core assumes
        *       that the path separator is the first character of the string
        *       PATH_SEPARATOR, but does not interpret any path separators in the
        *       search paths, so if you use a different path separator in a search
        *       path, you may get a mixture of PATH_SEPARATORs (from the core) and
        *       alternate path separators (specified by users and placed into the
        *       options database).
        *  -----------------------------------------------------------------------------*/
        public osd_file.error osd_open(string path, UInt32 openflags, out osd_file file, out UInt64 filesize)
        {
            throw new emu_fatalerror("TODO - Fix inheritence");

            //osd_file_Unity fileWinForms = new osd_file_Unity();
            //file = fileWinForms;
            //try
            //{
            //    //fileWinForms.m_file = File.OpenRead(path);
            //}
            //catch (Exception)
            //{
            //    filesize = 0;
            //    return osd_file.error.NOT_FOUND;
            //}
            //
            ////filesize = (UInt64)fileWinForms.m_file.Length;
            //return osd_file.error.NONE;
        }
コード例 #7
0
        /*-----------------------------------------------------------------------------
        *   osd_open: open a new file.
        *
        *   Parameters:
        *
        *       path - path to the file to open
        *
        *       openflags - some combination of:
        *
        *           OPEN_FLAG_READ - open the file for read access
        *           OPEN_FLAG_WRITE - open the file for write access
        *           OPEN_FLAG_CREATE - create/truncate the file when opening
        *           OPEN_FLAG_CREATE_PATHS - specifies that non-existant paths
        *                   should be created if necessary
        *
        *       file - pointer to an osd_file * to receive the newly-opened file
        *           handle; this is only valid if the function returns FILERR_NONE
        *
        *       filesize - pointer to a UINT64 to receive the size of the opened
        *           file; this is only valid if the function returns FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while opening
        *       the file, or FILERR_NONE if no error occurred
        *
        *   Notes:
        *
        *       This function is called by core_fopen and several other places in
        *       the core to access files. These functions will construct paths by
        *       concatenating various search paths held in the options.c options
        *       database with partial paths specified by the core. The core assumes
        *       that the path separator is the first character of the string
        *       PATH_SEPARATOR, but does not interpret any path separators in the
        *       search paths, so if you use a different path separator in a search
        *       path, you may get a mixture of PATH_SEPARATORs (from the core) and
        *       alternate path separators (specified by users and placed into the
        *       options database).
        *  -----------------------------------------------------------------------------*/
        public osd_file.error osd_open(string path, UInt32 openflags, out osd_file file, out UInt64 filesize)
        {
            throw new emu_fatalerror("Fix inheritence");

            osd_file_WinForms fileWinForms = new osd_file_WinForms();

            file = fileWinForms;
            try
            {
                fileWinForms.m_file = File.OpenRead(path);
            }
            catch (Exception)
            {
                filesize = 0;
                return(osd_file.error.NOT_FOUND);
            }

            filesize = (UInt64)fileWinForms.m_file.Length;
            return(osd_file.error.NONE);
        }
コード例 #8
0
        /*-----------------------------------------------------------------------------
        *   osd_open: open a new file.
        *
        *   Parameters:
        *
        *       path - path to the file to open
        *
        *       openflags - some combination of:
        *
        *           OPEN_FLAG_READ - open the file for read access
        *           OPEN_FLAG_WRITE - open the file for write access
        *           OPEN_FLAG_CREATE - create/truncate the file when opening
        *           OPEN_FLAG_CREATE_PATHS - specifies that non-existant paths
        *                   should be created if necessary
        *
        *       file - pointer to an osd_file * to receive the newly-opened file
        *           handle; this is only valid if the function returns FILERR_NONE
        *
        *       filesize - pointer to a UINT64 to receive the size of the opened
        *           file; this is only valid if the function returns FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while opening
        *       the file, or FILERR_NONE if no error occurred
        *
        *   Notes:
        *
        *       This function is called by core_fopen and several other places in
        *       the core to access files. These functions will construct paths by
        *       concatenating various search paths held in the options.c options
        *       database with partial paths specified by the core. The core assumes
        *       that the path separator is the first character of the string
        *       PATH_SEPARATOR, but does not interpret any path separators in the
        *       search paths, so if you use a different path separator in a search
        *       path, you may get a mixture of PATH_SEPARATORs (from the core) and
        *       alternate path separators (specified by users and placed into the
        *       options database).
        *  -----------------------------------------------------------------------------*/
        public std.error_condition osd_open(string path, UInt32 openflags, out osd_file file, out UInt64 filesize)
        {
            throw new emu_fatalerror("Fix inheritence");

            osd_file_WinForms fileWinForms = new osd_file_WinForms();

            file = fileWinForms;
            try
            {
                fileWinForms.m_file = File.OpenRead(path);
            }
            catch (Exception)
            {
                filesize = 0;
                return(std.errc.no_such_file_or_directory);
            }

            filesize = (UInt64)fileWinForms.m_file.Length;
            return(new std.error_condition());
        }
コード例 #9
0
ファイル: osdcore_Unity.cs プロジェクト: kwanboy/mcs
        /*-----------------------------------------------------------------------------
        *   osd_read: read from an open file
        *
        *   Parameters:
        *
        *       file - handle to a file previously opened via osd_open
        *
        *       buffer - pointer to memory that will receive the data read
        *
        *       offset - offset within the file to read from
        *
        *       length - number of bytes to read from the file
        *
        *       actual - pointer to a UINT32 to receive the number of bytes actually
        *           read during the operation; valid only if the function returns
        *           FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while reading
        *       from the file, or FILERR_NONE if no error occurred
        *  -----------------------------------------------------------------------------*/
        public osd_file.error osd_read(osd_file file, ListBytesPointer buffer, UInt64 offset, UInt32 length, out UInt32 actual)
        {
            throw new emu_fatalerror("TODO - Fix inheritence");

            //osd_file_Unity fileWinForms = (osd_file_Unity)file;
            //
            ////fileWinForms.m_file.Position = 0;
            //
            //// read until we get to the correct offset (HACK)
            ////while (offset-- > 0)
            ////    fileWinForms.m_file.ReadByte();
            //
            //// read one byte at a time (HACK)
            //for (UInt32 i = 0; i < length; i++)
            //{
            //    //buffer[i] = (byte)fileWinForms.m_file.ReadByte();
            //}
            //
            //actual = length;
            //return osd_file.error.NONE;
        }
コード例 #10
0
        /*-----------------------------------------------------------------------------
        *   osd_read: read from an open file
        *
        *   Parameters:
        *
        *       file - handle to a file previously opened via osd_open
        *
        *       buffer - pointer to memory that will receive the data read
        *
        *       offset - offset within the file to read from
        *
        *       length - number of bytes to read from the file
        *
        *       actual - pointer to a UINT32 to receive the number of bytes actually
        *           read during the operation; valid only if the function returns
        *           FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while reading
        *       from the file, or FILERR_NONE if no error occurred
        *  -----------------------------------------------------------------------------*/
        public osd_file.error osd_read(osd_file file, ListBytesPointer buffer, UInt64 offset, UInt32 length, out UInt32 actual)
        {
            throw new emu_fatalerror("Fix inheritence");

            osd_file_WinForms fileWinForms = (osd_file_WinForms)file;

            fileWinForms.m_file.Position = 0;

            // read until we get to the correct offset (HACK)
            while (offset-- > 0)
            {
                fileWinForms.m_file.ReadByte();
            }

            // read one byte at a time (HACK)
            for (UInt32 i = 0; i < length; i++)
            {
                buffer[i] = (byte)fileWinForms.m_file.ReadByte();
            }

            actual = length;
            return(osd_file.error.NONE);
        }
コード例 #11
0
ファイル: osdcore_Unity.cs プロジェクト: kwanboy/mcs
        /*-----------------------------------------------------------------------------
        *   osd_file::open: open a new file.
        *
        *   Parameters:
        *
        *       path - path to the file to open
        *
        *       openflags - some combination of:
        *
        *           OPEN_FLAG_READ - open the file for read access
        *           OPEN_FLAG_WRITE - open the file for write access
        *           OPEN_FLAG_CREATE - create/truncate the file when opening
        *           OPEN_FLAG_CREATE_PATHS - specifies that non-existant paths
        *                   should be created if necessary
        *
        *       file - reference to an osd_file::ptr to receive the newly-opened file
        *           handle; this is only valid if the function returns FILERR_NONE
        *
        *       filesize - reference to a UINT64 to receive the size of the opened
        *           file; this is only valid if the function returns FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while opening
        *       the file, or FILERR_NONE if no error occurred
        *
        *   Notes:
        *
        *       This function is called by core_fopen and several other places in
        *       the core to access files. These functions will construct paths by
        *       concatenating various search paths held in the options.c options
        *       database with partial paths specified by the core. The core assumes
        *       that the path separator is the first character of the string
        *       PATH_SEPARATOR, but does not interpret any path separators in the
        *       search paths, so if you use a different path separator in a search
        *       path, you may get a mixture of PATH_SEPARATORs (from the core) and
        *       alternate path separators (specified by users and placed into the
        *       options database).
        *  -----------------------------------------------------------------------------*/
        public override error open(string path, UInt32 openflags, out osd_file file, out UInt64 filesize)
        {
            // path "roms/digdug/dd1a.1" string

            file = this;
            try
            {
                m_data = null;

                string dirPath  = Path.GetDirectoryName(path);
                string filename = Path.GetFileName(path);

                //UnityEngine.Debug.LogFormat("osdcore_Unity() path: {0}", dirPath);

                if (Main.m_synchronizeInvoke == null)
                {
                    filesize = 0;
                    return(osd_file.error.NOT_FOUND);
                }

                /*var retObj =*/ Main.m_synchronizeInvoke.Invoke((System.Func <string>)(() =>
                {
                    UnityEngine.GameObject romGameObject = UnityEngine.GameObject.Find(dirPath);

                    if (romGameObject != null)
                    {
                        Rom romComponent = romGameObject.GetComponent <Rom>();
                        if (romComponent != null)
                        {
                            foreach (UnityEngine.TextAsset r in romComponent.m_roms)
                            {
                                if (r.name == filename)
                                {
                                    m_data = r.bytes;

                                    //UnityEngine.Debug.LogFormat("osdcore_Unity() - Found: {0}", path);
                                    break;
                                }
                            }
                        }
                    }

                    return("");
                }), null);

                //UnityEngine.Debug.LogFormat("osd_file_Unity.open() - '{0}' {1} {2} {3}", retObj as string, m_position, m_path, m_name);

                if (m_data == null)
                {
                    filesize = 0;
                    return(osd_file.error.NOT_FOUND);
                }

                filesize = (UInt64)m_data.Length;
                return(osd_file.error.NONE);
            }
            catch (Exception)
            {
                filesize = 0;
                return(osd_file.error.NOT_FOUND);
            }
        }
コード例 #12
0
ファイル: osdcore_Unity.cs プロジェクト: kwanboy/mcs
 /*-----------------------------------------------------------------------------
 *   osd_file::openpty: create a new PTY pair
 *
 *   Parameters:
 *
 *       file - reference to an osd_file::ptr to receive the handle of the master
 *           side of the newly-created PTY; this is only valid if the function
 *           returns FILERR_NONE
 *
 *       name - reference to string where slave filename will be stored
 *
 *   Return value:
 *
 *       a file_error describing any error that occurred while creating the
 *       PTY, or FILERR_NONE if no error occurred
 *  -----------------------------------------------------------------------------*/
 protected override error openpty(out osd_file file, out string name)
 {
     throw new emu_unimplemented();
 }
コード例 #13
0
 public CSzFile()
 {
     currfpos = 0;
     length   = 0;
     osdfile  = null;
 }
コード例 #14
0
 /*-----------------------------------------------------------------------------
 *   osd_file::openpty: create a new PTY pair
 *
 *   Parameters:
 *
 *       file - reference to an osd_file::ptr to receive the handle of the master
 *           side of the newly-created PTY; this is only valid if the function
 *           returns FILERR_NONE
 *
 *       name - reference to string where slave filename will be stored
 *
 *   Return value:
 *
 *       a file_error describing any error that occurred while creating the
 *       PTY, or FILERR_NONE if no error occurred
 *  -----------------------------------------------------------------------------*/
 protected override std.error_condition openpty(out osd_file file, out string name)
 {
     throw new emu_unimplemented();
 }