Exemple #1
0
 public void Close()
 {
     if (FileHandle != null)
     {
         FileHandle.Close();
         FileHandle = null;
     }
 }
Exemple #2
0
    public byte ReadByte(FileHandle handle)
    {
        if (!handle.Open)
        {
            return(0);
        }

        byte ret;

        if (handle.reader != null)
        {
            ret = handle.reader.ReadByte();
            if (handle.reader.BaseStream.Position >= handle.reader.BaseStream.Length)
            {
                handle.Close();
            }
            return(ret);
        }

        int sectorStart = GetSectorOffset(handle.track, handle.sector);

        ret = _data[sectorStart + handle.offset];

        // Last sector?
        if (_data[sectorStart] == 0)
        {
            // Last byte read?
            if (handle.offset >= _data[sectorStart + 1])
            {
                handle.track = 0;
            }
            else
            {
                ++handle.offset;
            }
        }
        else
        {
            ++handle.offset;
            if (handle.offset >= 256)
            {
                handle.track  = _data[sectorStart];
                handle.sector = _data[sectorStart + 1];
                handle.offset = 2;
            }
        }

        return(ret);
    }
Exemple #3
0
    void HandleKernalTrap(ushort address)
    {
        // SETNAM
        if (address == 0xffbd)
        {
            //Debug.Log("SetNam");
            // Strip away @0:
            byte   fileNameLength  = _processor.A;
            ushort fileNameAddress = (ushort)(_processor.Y * 256 + _processor.X);
            if (_ram[fileNameAddress] == 0x40 && _ram[(ushort)(fileNameAddress + 1)] == 0x30)
            {
                fileNameAddress += 3;
                fileNameLength  -= 3;
            }

            _fileName = new byte[fileNameLength];
            for (int i = 0; i < _fileName.Length; ++i)
            {
                _fileName[i] = _ram[fileNameAddress++];
            }
        }
        // CHKIN (actually open the file stream)
        else if (address == 0xffc6)
        {
            //Debug.Log("Chkin");
            _fileHandle = _disk.OpenFile(_fileName);
            if (_fileHandle == null)
            {
                Debug.LogWarning("File " + _fileName[0].ToString("X") + " " + _fileName[1].ToString("X") + " not found");
            }
        }
        // CHRIN
        else if (address == 0xffcf)
        {
            if (_fileHandle != null)
            {
                if (_fileHandle.Open)
                {
                    _processor.A = _disk.ReadByte(_fileHandle);
                }
                _ram[0x90] = (byte)(_fileHandle.Open ? 0x00 : 0x40);
            }
            else
            {
                _ram[0x90] = 0x42; // EOF, file not found
            }
        }
        // CHKOUT
        else if (address == 0xffc9)
        {
            _fileHandle = _disk.OpenFileForWrite(_fileName);
            if (_fileHandle == null)
            {
                Debug.LogError("File " + _fileName[0].ToString("X") + " " + _fileName[1].ToString("X") + " failed to open for write");
            }
        }
        // CHROUT
        else if (address == 0xffd2)
        {
            if (_fileHandle != null)
            {
                _disk.WriteByte(_fileHandle, _processor.A);
            }
        }
        // CLOSE
        else if (address == 0xffc3)
        {
            //Debug.Log("Close");
            if (_fileHandle != null)
            {
                _fileHandle.Close();
            }
            _fileHandle = null;
        }
        // CIOUT - loader detection
        else if (address == 0xffa8)
        {
            //Debug.Log("CIOut");
            _ram[0x90] = 0x80; // Error, prevent fastloader from running
        }
    }