示例#1
0
        unsafe void chd64_cmd(byte *d64name)
        {
            using (BytePtr str = new BytePtr(IEC.NAMEBUF_LENGTH))
            {
                byte *p = str;

                // Convert .d64 file name
                for (int i = 0; i < IEC.NAMEBUF_LENGTH && (*p++ = conv_from_64(*d64name++, false)) != 0; i++)
                {
                    ;
                }

                close_all_channels();

                // G:. resets the .d64 file name to its original setting
                if (str[0] == '.' && str[1] == 0)
                {
                    open_close_d64_file(orig_d64_name);
                }
                else
                {
                    open_close_d64_file(str.ToString());
                }

                // Read BAM
                read_sector(18, 0, (byte *)bam);
            }
        }
示例#2
0
        void find_first_file(BytePtr aName)
        {
            DirectoryInfo dir = new DirectoryInfo(dir_path);

            if (!dir.Exists)
            {
                return;
            }

            FileInfo[] files = dir.GetFiles();

            string name = aName.ToString();

            IEnumerator fenum = files.GetEnumerator();

            while (fenum.MoveNext() && (((FileInfo)fenum.Current).Name == "." || ((FileInfo)fenum.Current).Name == ".."))
            {
                ;
            }

            do
            {
                FileInfo fi = (FileInfo)fenum.Current;

                // Match found? Then copy real file name
                if (match(name, fi.Name))
                {
                    CharFunctions.strncpy(aName, fi.Name);
                    return;
                }
            } while (fenum.MoveNext());
        }
示例#3
0
        byte open_file(int channel, BytePtr filename)
        {
            using (BytePtr plainname = new BytePtr(256))
            {
                FileAccessMode filemode = FileAccessMode.FMODE_READ;
                FileType filetype = FileType.FTYPE_PRG;
                bool wildflag = false;
                FileMode fmode = FileMode.Open;
                FileAccess faccess = FileAccess.Read;

                unsafe
                {
                    convert_filename(filename, plainname, ref filemode, ref filetype, ref wildflag);
                }

                // Channel 0 is READ PRG, channel 1 is WRITE PRG
                if (channel == 0)
                {
                    filemode = FileAccessMode.FMODE_READ;
                    filetype = FileType.FTYPE_PRG;
                }
                else if (channel == 1)
                {
                    filemode = FileAccessMode.FMODE_WRITE;
                    filetype = FileType.FTYPE_PRG;
                }

                // Wildcards are only allowed on reading
                if (wildflag)
                {
                    if (filemode != FileAccessMode.FMODE_READ)
                    {
                        set_error(ErrorCode1541.ERR_SYNTAX33);
                        return (byte)C64StatusCode.ST_OK;
                    }

                    find_first_file(plainname);
                }

                // Select fopen() mode according to file mode
                switch (filemode)
                {
                    case FileAccessMode.FMODE_READ:
                        fmode = FileMode.Open;
                        faccess = FileAccess.Read;
                        break;
                    case FileAccessMode.FMODE_WRITE:
                        fmode = FileMode.OpenOrCreate;
                        faccess = FileAccess.ReadWrite;
                        break;
                    case FileAccessMode.FMODE_APPEND:
                        fmode = FileMode.Append;
                        faccess = FileAccess.ReadWrite;
                        break;
                }

                try
                {
                    string fullpath = Path.Combine(dir_path, plainname.ToString());

                    file[channel] = new FileStream(fullpath, fmode, faccess);

                    if (filemode == FileAccessMode.FMODE_READ)	// Read and buffer first byte
                        read_char[channel] = (byte)file[channel].ReadByte();
                    else
                        Environment.CurrentDirectory = Assembly.GetExecutingAssembly().Location;
                }
                catch (DirectoryNotFoundException)
                {
                    set_error(ErrorCode1541.ERR_NOTREADY);
                }
                catch (FileNotFoundException)
                {
                    set_error(ErrorCode1541.ERR_FILENOTFOUND);
                }
            }

            return (byte)C64StatusCode.ST_OK;
        }
示例#4
0
        unsafe byte open_directory(int channel, byte* filename)
        {
            using (BytePtr buf = new BytePtr(Encoding.ASCII.GetBytes("\u0001\u0004\u0001\u0001\u0000\u0000\u0012\u0022                \u0022 00 2A\0")),
                pattern = new BytePtr(IEC.NAMEBUF_LENGTH))
            {
                //char str[NAMEBUF_LENGTH];
                byte* p, q;
                int i;
                FileAccessMode filemode = FileAccessMode.FMODE_READ;
                FileType filetype = FileType.FTYPE_PRG;
                bool wildflag = false;
                string str;

                // Special treatment for "$0"
                if (filename[0] == '0' && filename[1] == 0)
                    filename += 1;

                // Convert filename ('$' already stripped), filemode/type are ignored
                convert_filename(filename, pattern, ref filemode, ref filetype, ref wildflag);

                DirectoryInfo dir = new DirectoryInfo(dir_path);
                if (!dir.Exists)
                {
                    set_error(ErrorCode1541.ERR_NOTREADY);
                    return (byte)C64StatusCode.ST_OK;
                }

                FileSystemInfo[] files = dir.GetFileSystemInfos();

                file[channel] = new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate, FileAccess.ReadWrite);

                p = (byte*)buf.Pointer + 8;

                for (i = 0; i < 16 & i < dir_title.Length; i++)
                {
                    *p++ = conv_to_64((byte)dir_title[i], false);
                }

                file[channel].Write(buf, 0, 32);

                IEnumerator fenum = files.GetEnumerator();
                while (fenum.MoveNext() && (((FileSystemInfo)fenum.Current).Name == "." || ((FileSystemInfo)fenum.Current).Name == "..")) ;

                do
                {
                    FileSystemInfo fsi = (FileSystemInfo)fenum.Current;

                    if (match(pattern.ToString(), fsi.Name))
                    {
                        // Clear line with spaces and terminate with null byte
                        for (i = 0; i < buf.Length; i++)
                            buf[i] = (byte)' ';

                        buf[31] = 0;

                        p = buf;
                        *p++ = 0x01;	// Dummy line link
                        *p++ = 0x01;

                        if (fsi is FileInfo)
                        {
                            FileInfo fi = (FileInfo)fsi;

                            // Calculate size in blocks (254 bytes each)
                            i = (int)((fi.Length + 254) / 254);
                            *p++ = (byte)(i & 0xff);
                            *p++ = (byte)((i >> 8) & 0xff);

                            p++;
                            if (i < 10) p++;	// Less than 10: add one space
                            if (i < 100) p++;	// Less than 100: add another space

                            str = fi.Name;
                            // Convert and insert file name
                            *p++ = (byte)'\"';
                            q = p;
                            for (i = 0; i < 16 && i < str.Length; i++)
                                *q++ = conv_to_64((byte)str[i], true);
                            *q++ = (byte)'\"';
                            p += 18;
                        }
                        // File type
                        if (fsi is DirectoryInfo)
                        {
                            *p++ = (byte)'D';
                            *p++ = (byte)'I';
                            *p++ = (byte)'R';
                        }
                        else
                        {
                            *p++ = (byte)'P';
                            *p++ = (byte)'R';
                            *p++ = (byte)'G';
                        }

                        // Write line
                        file[channel].Write(buf, 0, 32);
                    }

                } while (fenum.MoveNext());
            }

            // Final line

            file[channel].Write(Encoding.ASCII.GetBytes("\u0001\u0001\0\0BLOCKS FREE.             \0\0\0"), 0, 32);

            file[channel].Position = 0;
            read_char[channel] = (byte)file[channel].ReadByte();

            return (byte)C64StatusCode.ST_OK;
        }
示例#5
0
        void find_first_file(BytePtr aName)
        {
            DirectoryInfo dir = new DirectoryInfo(dir_path);

            if (!dir.Exists)
                return;

            FileInfo[] files = dir.GetFiles();

            string name = aName.ToString();

            IEnumerator fenum = files.GetEnumerator();
            while (fenum.MoveNext() && (((FileInfo)fenum.Current).Name == "." || ((FileInfo)fenum.Current).Name == "..")) ;

            do
            {
                FileInfo fi = (FileInfo)fenum.Current;

                // Match found? Then copy real file name
                if (match(name, fi.Name))
                {
                    CharFunctions.strncpy(aName, fi.Name);
                    return;
                }

            } while (fenum.MoveNext());
        }
示例#6
0
        unsafe void chd64_cmd(byte* d64name)
        {
            using (BytePtr str = new BytePtr(IEC.NAMEBUF_LENGTH))
            {
                byte* p = str;

                // Convert .d64 file name
                for (int i = 0; i < IEC.NAMEBUF_LENGTH && (*p++ = conv_from_64(*d64name++, false)) != 0; i++) ;

                close_all_channels();

                // G:. resets the .d64 file name to its original setting
                if (str[0] == '.' && str[1] == 0)
                    open_close_d64_file(orig_d64_name);
                else
                    open_close_d64_file(str.ToString());

                // Read BAM
                read_sector(18, 0, (byte*)bam);
            }
        }
示例#7
0
        unsafe byte open_directory(int channel, byte *filename)
        {
            using (BytePtr buf = new BytePtr(Encoding.ASCII.GetBytes("\u0001\u0004\u0001\u0001\u0000\u0000\u0012\u0022                \u0022 00 2A\0")),
                   pattern = new BytePtr(IEC.NAMEBUF_LENGTH))
            {
                //char str[NAMEBUF_LENGTH];
                byte *         p, q;
                int            i;
                FileAccessMode filemode = FileAccessMode.FMODE_READ;
                FileType       filetype = FileType.FTYPE_PRG;
                bool           wildflag = false;
                string         str;

                // Special treatment for "$0"
                if (filename[0] == '0' && filename[1] == 0)
                {
                    filename += 1;
                }

                // Convert filename ('$' already stripped), filemode/type are ignored
                convert_filename(filename, pattern, ref filemode, ref filetype, ref wildflag);

                DirectoryInfo dir = new DirectoryInfo(dir_path);
                if (!dir.Exists)
                {
                    set_error(ErrorCode1541.ERR_NOTREADY);
                    return((byte)C64StatusCode.ST_OK);
                }

                FileSystemInfo[] files = dir.GetFileSystemInfos();

                file[channel] = new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate, FileAccess.ReadWrite);

                p = (byte *)buf.Pointer + 8;

                for (i = 0; i < 16 & i < dir_title.Length; i++)
                {
                    *p++ = conv_to_64((byte)dir_title[i], false);
                }

                file[channel].Write(buf, 0, 32);

                IEnumerator fenum = files.GetEnumerator();
                while (fenum.MoveNext() && (((FileSystemInfo)fenum.Current).Name == "." || ((FileSystemInfo)fenum.Current).Name == ".."))
                {
                    ;
                }

                do
                {
                    FileSystemInfo fsi = (FileSystemInfo)fenum.Current;

                    if (match(pattern.ToString(), fsi.Name))
                    {
                        // Clear line with spaces and terminate with null byte
                        for (i = 0; i < buf.Length; i++)
                        {
                            buf[i] = (byte)' ';
                        }

                        buf[31] = 0;

                        p = buf;
                        *p++ = 0x01;    // Dummy line link
                        *p++ = 0x01;

                        if (fsi is FileInfo)
                        {
                            FileInfo fi = (FileInfo)fsi;

                            // Calculate size in blocks (254 bytes each)
                            i = (int)((fi.Length + 254) / 254);
                            *p++ = (byte)(i & 0xff);
                            *p++ = (byte)((i >> 8) & 0xff);

                            p++;
                            if (i < 10)
                            {
                                p++;            // Less than 10: add one space
                            }
                            if (i < 100)
                            {
                                p++;            // Less than 100: add another space
                            }
                            str = fi.Name;
                            // Convert and insert file name
                            *p++ = (byte)'\"';
                            q = p;
                            for (i = 0; i < 16 && i < str.Length; i++)
                            {
                                *q++ = conv_to_64((byte)str[i], true);
                            }
                            *q++ = (byte)'\"';
                            p   += 18;
                        }
                        // File type
                        if (fsi is DirectoryInfo)
                        {
                            *p++ = (byte)'D';
                            *p++ = (byte)'I';
                            *p++ = (byte)'R';
                        }
                        else
                        {
                            *p++ = (byte)'P';
                            *p++ = (byte)'R';
                            *p++ = (byte)'G';
                        }

                        // Write line
                        file[channel].Write(buf, 0, 32);
                    }
                } while (fenum.MoveNext());
            }

            // Final line

            file[channel].Write(Encoding.ASCII.GetBytes("\u0001\u0001\0\0BLOCKS FREE.             \0\0\0"), 0, 32);

            file[channel].Position = 0;
            read_char[channel]     = (byte)file[channel].ReadByte();

            return((byte)C64StatusCode.ST_OK);
        }
示例#8
0
        byte open_file(int channel, BytePtr filename)
        {
            using (BytePtr plainname = new BytePtr(256))
            {
                FileAccessMode filemode = FileAccessMode.FMODE_READ;
                FileType       filetype = FileType.FTYPE_PRG;
                bool           wildflag = false;
                FileMode       fmode    = FileMode.Open;
                FileAccess     faccess  = FileAccess.Read;

                unsafe
                {
                    convert_filename(filename, plainname, ref filemode, ref filetype, ref wildflag);
                }

                // Channel 0 is READ PRG, channel 1 is WRITE PRG
                if (channel == 0)
                {
                    filemode = FileAccessMode.FMODE_READ;
                    filetype = FileType.FTYPE_PRG;
                }
                else if (channel == 1)
                {
                    filemode = FileAccessMode.FMODE_WRITE;
                    filetype = FileType.FTYPE_PRG;
                }

                // Wildcards are only allowed on reading
                if (wildflag)
                {
                    if (filemode != FileAccessMode.FMODE_READ)
                    {
                        set_error(ErrorCode1541.ERR_SYNTAX33);
                        return((byte)C64StatusCode.ST_OK);
                    }

                    find_first_file(plainname);
                }

                // Select fopen() mode according to file mode
                switch (filemode)
                {
                case FileAccessMode.FMODE_READ:
                    fmode   = FileMode.Open;
                    faccess = FileAccess.Read;
                    break;

                case FileAccessMode.FMODE_WRITE:
                    fmode   = FileMode.OpenOrCreate;
                    faccess = FileAccess.ReadWrite;
                    break;

                case FileAccessMode.FMODE_APPEND:
                    fmode   = FileMode.Append;
                    faccess = FileAccess.ReadWrite;
                    break;
                }

                try
                {
                    string fullpath = Path.Combine(dir_path, plainname.ToString());

                    file[channel] = new FileStream(fullpath, fmode, faccess);

                    if (filemode == FileAccessMode.FMODE_READ)  // Read and buffer first byte
                    {
                        read_char[channel] = (byte)file[channel].ReadByte();
                    }
                    else
                    {
                        Environment.CurrentDirectory = Assembly.GetExecutingAssembly().Location;
                    }
                }
                catch (DirectoryNotFoundException)
                {
                    set_error(ErrorCode1541.ERR_NOTREADY);
                }
                catch (FileNotFoundException)
                {
                    set_error(ErrorCode1541.ERR_FILENOTFOUND);
                }
            }

            return((byte)C64StatusCode.ST_OK);
        }