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 } }