Пример #1
0
    void BootGame()
    {
        _disk = new DiskImage(diskImageName);

        // No filename, open first file in directory
        FileHandle bootFile = _disk.OpenFile(null);

        if (bootFile != null)
        {
            ushort loadAddress = (ushort)(_disk.ReadByte(bootFile) + _disk.ReadByte(bootFile) * 256);
            ushort address     = loadAddress;
            while (bootFile.Open)
            {
                _ram[address++] = _disk.ReadByte(bootFile);
            }
            // Set end address on zero page
            _ram[0x2d] = (byte)(address & 0xff);
            _ram[0x2e] = (byte)(address >> 8);
            _ram[0xae] = (byte)(address & 0xff);
            _ram[0xaf] = (byte)(address >> 8);
            // Set RESET vector to CLALL (autostart), otherwise assume sys2061
            if (loadAddress <= 0x32c)
            {
                _ram[0xfffc] = _ram[0x32c];
                _ram[0xfffd] = _ram[0x32d];
            }
            else
            {
                _ram[0xfffc] = 0xd;
                _ram[0xfffd] = 0x8;
            }
        }
    }
Пример #2
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
        }
    }