misc cleanups in Emulation.Cores

This commit is contained in:
adelikat 2017-04-17 15:23:04 -05:00
parent 28da1e215f
commit 94f152d1d1
7 changed files with 253 additions and 211 deletions

View File

@ -120,16 +120,19 @@ namespace BizHawk.Emulation.Cores.Calculators
} }
} }
public IMemoryCallbackSystem MemoryCallbacks { get; private set; } public IMemoryCallbackSystem MemoryCallbacks { get; }
[FeatureNotImplemented] [FeatureNotImplemented]
public void Step(StepType type) { throw new NotImplementedException(); } public void Step(StepType type)
public bool CanStep(StepType type) { return false; }
public int TotalExecutedCycles
{ {
get { return Cpu.TotalExecutedCycles; } throw new NotImplementedException();
} }
public bool CanStep(StepType type)
{
return false;
}
public int TotalExecutedCycles => Cpu.TotalExecutedCycles;
} }
} }

View File

@ -14,7 +14,7 @@ namespace BizHawk.Emulation.Cores.Calculators
set { _lagCount = value; } set { _lagCount = value; }
} }
public IInputCallbackSystem InputCallbacks { get; private set; } public IInputCallbackSystem InputCallbacks { get; } = new InputCallbackSystem();
public bool IsLagFrame public bool IsLagFrame
{ {

View File

@ -2,13 +2,13 @@
namespace BizHawk.Emulation.Cores.Calculators namespace BizHawk.Emulation.Cores.Calculators
{ {
public partial class TI83 : IVideoProvider public partial class TI83 : IVideoProvider
{ {
public int VirtualWidth{ get { return 96; } } public int VirtualWidth => 96;
public int VirtualHeight { get { return 64; } } public int VirtualHeight => 64;
public int BufferWidth { get { return 96; } } public int BufferWidth => 96;
public int BufferHeight { get { return 64; } } public int BufferHeight => 64;
public int BackgroundColor { get { return 0; } } public int BackgroundColor => 0;
public int[] GetVideoBuffer() public int[] GetVideoBuffer()
{ {
@ -19,19 +19,21 @@ namespace BizHawk.Emulation.Cores.Calculators
{ {
for (int x = 0; x < 96; x++) for (int x = 0; x < 96; x++)
{ {
int offset = y * 96 + x; int offset = (y * 96) + x;
int bufbyte = offset >> 3; int bufbyte = offset >> 3;
int bufbit = offset & 7; int bufbit = offset & 7;
int bit = ((_vram[bufbyte] >> (7 - bufbit)) & 1); int bit = (_vram[bufbyte] >> (7 - bufbit)) & 1;
if (bit == 0) if (bit == 0)
{ {
unchecked { pixels[i++] = (int)Settings.BGColor; } unchecked
{
pixels[i++] = (int)Settings.BGColor;
}
} }
else else
{ {
pixels[i++] = (int)Settings.ForeColor; pixels[i++] = (int)Settings.ForeColor;
} }
} }
} }

View File

@ -5,7 +5,6 @@ using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Components.Z80; using BizHawk.Emulation.Cores.Components.Z80;
// http://www.ticalc.org/pub/text/calcinfo/ // http://www.ticalc.org/pub/text/calcinfo/
namespace BizHawk.Emulation.Cores.Calculators namespace BizHawk.Emulation.Cores.Calculators
{ {
[CoreAttributes( [CoreAttributes(
@ -21,8 +20,6 @@ namespace BizHawk.Emulation.Cores.Calculators
public TI83(CoreComm comm, GameInfo game, byte[] rom, object Settings) public TI83(CoreComm comm, GameInfo game, byte[] rom, object Settings)
{ {
ServiceProvider = new BasicServiceProvider(this); ServiceProvider = new BasicServiceProvider(this);
InputCallbacks = new InputCallbackSystem();
MemoryCallbacks = new MemoryCallbackSystem();
PutSettings((TI83Settings)Settings ?? new TI83Settings()); PutSettings((TI83Settings)Settings ?? new TI83Settings());
CoreComm = comm; CoreComm = comm;
@ -57,7 +54,7 @@ namespace BizHawk.Emulation.Cores.Calculators
serviceProvider.Register<IDisassemblable>(new Disassembler()); serviceProvider.Register<IDisassemblable>(new Disassembler());
} }
private readonly ITraceable Tracer; private readonly TraceBuffer Tracer;
// hardware // hardware
private const ushort RamSizeMask = 0x7FFF; private const ushort RamSizeMask = 0x7FFF;
@ -83,24 +80,23 @@ namespace BizHawk.Emulation.Cores.Calculators
private ushort _startPC; private ushort _startPC;
// Link Cable // Link Cable
public TI83LinkPort LinkPort { get; private set; } public TI83LinkPort LinkPort { get; }
internal bool LinkActive; internal bool LinkActive;
internal int LinkOutput, LinkInput; internal int LinkOutput, LinkInput;
internal int LinkState internal int LinkState => (LinkOutput | LinkInput) ^ 3;
{
get { return (LinkOutput | LinkInput) ^ 3; }
}
private static readonly ControllerDefinition TI83Controller = private static readonly ControllerDefinition TI83Controller =
new ControllerDefinition new ControllerDefinition
{ {
Name = "TI83 Controller", Name = "TI83 Controller",
BoolButtons = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","DOT", BoolButtons =
"ON","ENTER", {
"DOWN","LEFT","UP","RIGHT", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","DOT",
"PLUS","MINUS","MULTIPLY","DIVIDE", "ON", "ENTER",
"DOWN", "LEFT", "UP", "RIGHT",
"PLUS", "MINUS", "MULTIPLY", "DIVIDE",
"CLEAR", "EXP", "DASH", "PARACLOSE", "TAN", "VARS", "PARAOPEN", "CLEAR", "EXP", "DASH", "PARACLOSE", "TAN", "VARS", "PARAOPEN",
"COS", "PRGM", "STAT", "COMMA", "SIN", "MATRIX", "X", "COS", "PRGM", "STAT", "COMMA", "SIN", "MATRIX", "X",
"STO", "LN", "LOG", "SQUARED", "NEG1", "MATH", "ALPHA", "STO", "LN", "LOG", "SQUARED", "NEG1", "MATH", "ALPHA",
@ -112,14 +108,14 @@ namespace BizHawk.Emulation.Cores.Calculators
{ {
byte ret; byte ret;
int romPage = _romPageLow3Bits | (_romPageHighBit << 3); int romPage = _romPageLow3Bits | (_romPageHighBit << 3);
//Console.WriteLine("read memory: {0:X4}", addr);
if (addr < 0x4000) if (addr < 0x4000)
{ {
ret = Rom[addr]; //ROM zero-page ret = Rom[addr]; // ROM zero-page
} }
else if (addr < 0x8000) else if (addr < 0x8000)
{ {
ret = Rom[romPage * 0x4000 + addr - 0x4000]; //other rom page ret = Rom[(romPage * 0x4000) + addr - 0x4000]; // other rom page
} }
else else
{ {
@ -133,11 +129,11 @@ namespace BizHawk.Emulation.Cores.Calculators
{ {
if (addr < 0x4000) if (addr < 0x4000)
{ {
return; //ROM zero-page return; // ROM zero-page
} }
else if (addr < 0x8000) else if (addr < 0x8000)
{ {
return; //other rom page return; // other rom page
} }
else else
{ {
@ -149,35 +145,38 @@ namespace BizHawk.Emulation.Cores.Calculators
{ {
switch (addr) switch (addr)
{ {
case 0: //PORT_LINK case 0: // PORT_LINK
_romPageHighBit = (value >> 4) & 1; _romPageHighBit = (value >> 4) & 1;
LinkOutput = value & 3; LinkOutput = value & 3;
if (LinkActive) if (LinkActive)
{ {
//Prevent rom calls from disturbing link port activity // Prevent rom calls from disturbing link port activity
if (LinkActive && Cpu.RegisterPC < 0x4000) if (LinkActive && Cpu.RegisterPC < 0x4000)
{
return; return;
}
LinkPort.Update(); LinkPort.Update();
} }
break; break;
case 1: //PORT_KEYBOARD: case 1: // PORT_KEYBOARD:
_lagged = false; _lagged = false;
_keyboardMask = value; _keyboardMask = value;
//Console.WriteLine("write PORT_KEYBOARD {0:X2}",value); //Console.WriteLine("write PORT_KEYBOARD {0:X2}",value);
break; break;
case 2: //PORT_ROMPAGE case 2: // PORT_ROMPAGE
_romPageLow3Bits = value & 0x7; _romPageLow3Bits = value & 0x7;
break; break;
case 3: //PORT_STATUS case 3: // PORT_STATUS
_maskOn = (byte)(value & 1); _maskOn = (byte)(value & 1);
break; break;
case 16: //PORT_DISPCTRL case 16: // PORT_DISPCTRL
//Console.WriteLine("write PORT_DISPCTRL {0}",value); //Console.WriteLine("write PORT_DISPCTRL {0}",value);
WriteDispCtrl(value); WriteDispCtrl(value);
break; break;
case 17: //PORT_DISPDATA case 17: // PORT_DISPDATA
//Console.WriteLine("write PORT_DISPDATA {0}",value); //Console.WriteLine("write PORT_DISPDATA {0}",value);
WriteDispData(value); WriteDispData(value);
break; break;
@ -188,17 +187,17 @@ namespace BizHawk.Emulation.Cores.Calculators
{ {
switch (addr) switch (addr)
{ {
case 0: //PORT_LINK case 0: // PORT_LINK
LinkPort.Update(); LinkPort.Update();
return (byte)((_romPageHighBit << 4) | (LinkState << 2) | LinkOutput); return (byte)((_romPageHighBit << 4) | (LinkState << 2) | LinkOutput);
case 1: //PORT_KEYBOARD: case 1: // PORT_KEYBOARD:
//Console.WriteLine("read PORT_KEYBOARD"); //Console.WriteLine("read PORT_KEYBOARD");
return ReadKeyboard(); return ReadKeyboard();
case 2: //PORT_ROMPAGE case 2: // PORT_ROMPAGE
return (byte)_romPageLow3Bits; return (byte)_romPageLow3Bits;
case 3: //PORT_STATUS case 3: // PORT_STATUS
{ {
//Console.WriteLine("read PORT_STATUS"); // Console.WriteLine("read PORT_STATUS");
// Bits: // Bits:
// 0 - Set if ON key is down and ON key is trapped // 0 - Set if ON key is down and ON key is trapped
// 1 - Update things (keyboard etc) // 1 - Update things (keyboard etc)
@ -210,15 +209,15 @@ namespace BizHawk.Emulation.Cores.Calculators
return (byte)((Controller.IsPressed("ON") ? _maskOn : 8) | (LinkActive ? 0 : 2)); return (byte)((Controller.IsPressed("ON") ? _maskOn : 8) | (LinkActive ? 0 : 2));
} }
case 4: //PORT_INTCTRL case 4: // PORT_INTCTRL
//Console.WriteLine("read PORT_INTCTRL"); //Console.WriteLine("read PORT_INTCTRL");
return 0xFF; return 0xFF;
case 16: //PORT_DISPCTRL case 16: // PORT_DISPCTRL
//Console.WriteLine("read DISPCTRL"); //Console.WriteLine("read DISPCTRL");
break; break;
case 17: //PORT_DISPDATA case 17: // PORT_DISPDATA
return ReadDispData(); return ReadDispData();
} }
return 0xFF; return 0xFF;
@ -238,6 +237,7 @@ namespace BizHawk.Emulation.Cores.Calculators
if (Controller.IsPressed("RIGHT")) ret ^= 4; if (Controller.IsPressed("RIGHT")) ret ^= 4;
if (Controller.IsPressed("UP")) ret ^= 8; if (Controller.IsPressed("UP")) ret ^= 8;
} }
if ((_keyboardMask & 2) == 0) if ((_keyboardMask & 2) == 0)
{ {
if (Controller.IsPressed("ENTER")) ret ^= 1; if (Controller.IsPressed("ENTER")) ret ^= 1;
@ -248,6 +248,7 @@ namespace BizHawk.Emulation.Cores.Calculators
if (Controller.IsPressed("EXP")) ret ^= 32; if (Controller.IsPressed("EXP")) ret ^= 32;
if (Controller.IsPressed("CLEAR")) ret ^= 64; if (Controller.IsPressed("CLEAR")) ret ^= 64;
} }
if ((_keyboardMask & 4) == 0) if ((_keyboardMask & 4) == 0)
{ {
if (Controller.IsPressed("DASH")) ret ^= 1; if (Controller.IsPressed("DASH")) ret ^= 1;
@ -258,6 +259,7 @@ namespace BizHawk.Emulation.Cores.Calculators
if (Controller.IsPressed("TAN")) ret ^= 32; if (Controller.IsPressed("TAN")) ret ^= 32;
if (Controller.IsPressed("VARS")) ret ^= 64; if (Controller.IsPressed("VARS")) ret ^= 64;
} }
if ((_keyboardMask & 8) == 0) if ((_keyboardMask & 8) == 0)
{ {
if (Controller.IsPressed("DOT")) ret ^= 1; if (Controller.IsPressed("DOT")) ret ^= 1;
@ -269,6 +271,7 @@ namespace BizHawk.Emulation.Cores.Calculators
if (Controller.IsPressed("PRGM")) ret ^= 64; if (Controller.IsPressed("PRGM")) ret ^= 64;
if (Controller.IsPressed("STAT")) ret ^= 128; if (Controller.IsPressed("STAT")) ret ^= 128;
} }
if ((_keyboardMask & 16) == 0) if ((_keyboardMask & 16) == 0)
{ {
if (Controller.IsPressed("0")) ret ^= 1; if (Controller.IsPressed("0")) ret ^= 1;
@ -313,13 +316,13 @@ namespace BizHawk.Emulation.Cores.Calculators
if (_cursorMoved) if (_cursorMoved)
{ {
_cursorMoved = false; _cursorMoved = false;
return 0x00; //not accurate this should be stale data or something return 0x00; // not accurate this should be stale data or something
} }
byte ret; byte ret;
if (_displayMode == 1) if (_displayMode == 1)
{ {
ret = _vram[_displayY * 12 + _displayX]; ret = _vram[(_displayY * 12) + _displayX];
} }
else else
{ {
@ -349,8 +352,8 @@ namespace BizHawk.Emulation.Cores.Calculators
{ {
int shift = column & 7; int shift = column & 7;
int mask = ~(252 >> shift); int mask = ~(252 >> shift);
int Data = value << 2; int data = value << 2;
_vram[offset] = (byte)(_vram[offset] & mask | (Data >> shift)); _vram[offset] = (byte)(_vram[offset] & mask | (data >> shift));
if (shift > 2 && offset < 0x2ff) if (shift > 2 && offset < 0x2ff)
{ {
offset++; offset++;
@ -358,7 +361,7 @@ namespace BizHawk.Emulation.Cores.Calculators
shift = 8 - shift; shift = 8 - shift;
mask = ~(252 << shift); mask = ~(252 << shift);
_vram[offset] = (byte)(_vram[offset] & mask | (Data << shift)); _vram[offset] = (byte)(_vram[offset] & mask | (data << shift));
} }
} }
} }
@ -376,7 +379,7 @@ namespace BizHawk.Emulation.Cores.Calculators
case 3: _displayX++; break; case 3: _displayX++; break;
} }
_displayX &= 0xF; //0xF or 0x1F? dunno _displayX &= 0xF; // 0xF or 0x1F? dunno
_displayY &= 0x3F; _displayY &= 0x3F;
} }
@ -392,7 +395,7 @@ namespace BizHawk.Emulation.Cores.Calculators
} }
else if ((value & 0xC0) == 0x40) else if ((value & 0xC0) == 0x40)
{ {
//hardware scroll // hardware scroll
} }
else if ((value & 0xE0) == 0x20) else if ((value & 0xE0) == 0x20)
{ {
@ -406,7 +409,7 @@ namespace BizHawk.Emulation.Cores.Calculators
} }
else if ((value & 0xC0) == 0xC0) else if ((value & 0xC0) == 0xC0)
{ {
//contrast // contrast
} }
else if (value == 2) else if (value == 2)
{ {
@ -421,7 +424,7 @@ namespace BizHawk.Emulation.Cores.Calculators
private void IRQCallback() private void IRQCallback()
{ {
//Console.WriteLine("IRQ with vec {0} and cpu.InterruptMode {1}", cpu.RegisterI, cpu.InterruptMode); // Console.WriteLine("IRQ with vec {0} and cpu.InterruptMode {1}", cpu.RegisterI, cpu.InterruptMode);
Cpu.Interrupt = false; Cpu.Interrupt = false;
} }
@ -436,7 +439,10 @@ namespace BizHawk.Emulation.Cores.Calculators
Cpu.Reset(); Cpu.Reset();
_ram = new byte[0x8000]; _ram = new byte[0x8000];
for (int i = 0; i < 0x8000; i++) for (int i = 0; i < 0x8000; i++)
{
_ram[i] = 0xFF; _ram[i] = 0xFF;
}
Cpu.RegisterPC = _startPC; Cpu.RegisterPC = _startPC;
Cpu.IFF1 = false; Cpu.IFF1 = false;

View File

@ -10,20 +10,20 @@ namespace BizHawk.Emulation.Cores.Calculators
// See http://www.ticalc.org/archives/files/fileinfo/294/29418.html for documentation // See http://www.ticalc.org/archives/files/fileinfo/294/29418.html for documentation
// Note: Each hardware read/write to the link port calls tthe update method. // Note: Each hardware read/write to the link port calls tthe update method.
readonly TI83 Parent; private readonly TI83 Parent;
private readonly Queue<byte> CurrentData = new Queue<byte>();
private FileStream CurrentFile; private FileStream _currentFile;
//private int FileBytesLeft; private byte[] _variableData;
private byte[] VariableData;
private Action NextStep; private Action _nextStep;
private Queue<byte> CurrentData = new Queue<byte>();
private ushort BytesToSend; private ushort _bytesToSend;
private byte BitsLeft; private byte _bitsLeft;
private byte CurrentByte; private byte _currentByte;
private byte StepsLeft; private byte _stepsLeft;
private Status CurrentStatus = Status.Inactive; private Status _currentStatus = Status.Inactive;
private enum Status private enum Status
{ {
@ -34,226 +34,252 @@ namespace BizHawk.Emulation.Cores.Calculators
Send Send
} }
public TI83LinkPort(TI83 Parent) public TI83LinkPort(TI83 parent)
{ {
this.Parent = Parent; Parent = parent;
} }
public void Update() public void Update()
{ {
if (CurrentStatus == Status.PrepareReceive) if (_currentStatus == Status.PrepareReceive)
{ {
//Get the first byte, and start sending it. // Get the first byte, and start sending it.
CurrentByte = CurrentData.Dequeue(); _currentByte = CurrentData.Dequeue();
CurrentStatus = Status.Receive; _currentStatus = Status.Receive;
BitsLeft = 8; _bitsLeft = 8;
StepsLeft = 5; _stepsLeft = 5;
} }
if (CurrentStatus == Status.PrepareSend && Parent.LinkState != 3) if (_currentStatus == Status.PrepareSend && Parent.LinkState != 3)
{ {
CurrentStatus = Status.Send; _currentStatus = Status.Send;
BitsLeft = 8; _bitsLeft = 8;
StepsLeft = 5; _stepsLeft = 5;
CurrentByte = 0; _currentByte = 0;
} }
if (CurrentStatus == Status.Receive) if (_currentStatus == Status.Receive)
{ {
switch (StepsLeft) switch (_stepsLeft)
{ {
case 5: case 5:
//Receive step 1: Lower the other device's line. // Receive step 1: Lower the other device's line.
Parent.LinkInput = ((CurrentByte & 1) == 1) ? 2 : 1; Parent.LinkInput = ((_currentByte & 1) == 1) ? 2 : 1;
CurrentByte >>= 1; _currentByte >>= 1;
StepsLeft--; _stepsLeft--;
break; break;
case 4: case 4:
//Receive step 2: Wait for the calc to lower the other line. // Receive step 2: Wait for the calc to lower the other line.
if ((Parent.LinkState & 3) == 0) if ((Parent.LinkState & 3) == 0)
StepsLeft--; {
_stepsLeft--;
}
break; break;
case 3: case 3:
//Receive step 3: Raise the other device's line back up. // Receive step 3: Raise the other device's line back up.
Parent.LinkInput = 0; Parent.LinkInput = 0;
StepsLeft--; _stepsLeft--;
break; break;
case 2: case 2:
//Receive step 4: Wait for the calc to raise its line back up. // Receive step 4: Wait for the calc to raise its line back up.
if ((Parent.LinkState & 3) == 3) if ((Parent.LinkState & 3) == 3)
StepsLeft--; {
_stepsLeft--;
}
break; break;
case 1: case 1:
//Receive step 5: Finish. // Receive step 5: Finish.
BitsLeft--; _bitsLeft--;
if (BitsLeft == 0) if (_bitsLeft == 0)
{ {
if (CurrentData.Count > 0) if (CurrentData.Count > 0)
CurrentStatus = Status.PrepareReceive; {
_currentStatus = Status.PrepareReceive;
}
else else
{ {
CurrentStatus = Status.Inactive; _currentStatus = Status.Inactive;
if (NextStep != null) _nextStep?.Invoke();
NextStep();
} }
} }
else else
//next bit in the current byte. {
StepsLeft = 5; // Next bit in the current byte.
_stepsLeft = 5;
}
break; break;
} }
} }
else if (CurrentStatus == Status.Send) else if (_currentStatus == Status.Send)
{ {
switch (StepsLeft) switch (_stepsLeft)
{ {
case 5: case 5:
//Send step 1: Calc lowers a line. // Send step 1: Calc lowers a line.
if (Parent.LinkState != 3) if (Parent.LinkState != 3)
{ {
int Bit = Parent.LinkState & 1; int bit = Parent.LinkState & 1;
int Shift = 8 - BitsLeft; int shift = 8 - _bitsLeft;
CurrentByte |= (byte)(Bit << Shift); _currentByte |= (byte)(bit << shift);
StepsLeft--; _stepsLeft--;
} }
break; break;
case 4: case 4:
//send step 2: Lower our line. // Send step 2: Lower our line.
Parent.LinkInput = Parent.LinkOutput ^ 3; Parent.LinkInput = Parent.LinkOutput ^ 3;
StepsLeft--; _stepsLeft--;
break; break;
case 3: case 3:
//Send step 3: wait for the calc to raise its line. // Send step 3: wait for the calc to raise its line.
if ((Parent.LinkOutput & 3) == 0) if ((Parent.LinkOutput & 3) == 0)
StepsLeft--; {
_stepsLeft--;
}
break; break;
case 2: case 2:
//Send step 4: raise the other devices lines. // Send step 4: raise the other devices lines.
Parent.LinkInput = 0; Parent.LinkInput = 0;
StepsLeft--; _stepsLeft--;
break; break;
case 1: case 1:
//Send step 5: Finish // Send step 5: Finish
BitsLeft--; _bitsLeft--;
if (BitsLeft == 0) if (_bitsLeft == 0)
{ {
BytesToSend--; _bytesToSend--;
CurrentData.Enqueue(CurrentByte); CurrentData.Enqueue(_currentByte);
if (BytesToSend > 0) if (_bytesToSend > 0)
CurrentStatus = Status.PrepareSend; {
_currentStatus = Status.PrepareSend;
}
else else
{ {
CurrentStatus = Status.Inactive; _currentStatus = Status.Inactive;
if (NextStep != null) _nextStep?.Invoke();
NextStep();
} }
} }
else else
{ {
//next bit in the current byte. // Next bit in the current byte.
StepsLeft = 5; _stepsLeft = 5;
} }
break; break;
} }
} }
} }
public void SendFileToCalc(FileStream FS, bool Verify) public void SendFileToCalc(FileStream fs, bool verify)
{ {
if (Verify) if (verify)
VerifyFile(FS); {
VerifyFile(fs);
}
FS.Seek(55, SeekOrigin.Begin); fs.Seek(55, SeekOrigin.Begin);
CurrentFile = FS; _currentFile = fs;
SendNextFile(); SendNextFile();
} }
private void VerifyFile(FileStream FS) private void VerifyFile(FileStream fs)
{ {
//Verify the file format. // Verify the file format.
byte[] Expected = new byte[] { 0x2a, 0x2a, 0x54, 0x49, 0x38, 0x33, 0x2a, 0x2a, 0x1a, 0x0a, 0x00 }; byte[] expected = { 0x2a, 0x2a, 0x54, 0x49, 0x38, 0x33, 0x2a, 0x2a, 0x1a, 0x0a, 0x00 };
byte[] Actual = new byte[11]; byte[] actual = new byte[11];
FS.Seek(0, SeekOrigin.Begin); fs.Seek(0, SeekOrigin.Begin);
FS.Read(Actual, 0, 11); fs.Read(actual, 0, 11);
//Check the header. // Check the header.
for (int n = 0; n < 11; n++) for (int n = 0; n < 11; n++)
if (Expected[n] != Actual[n]) {
if (expected[n] != actual[n])
{ {
FS.Close(); fs.Close();
throw new IOException("Invalid Header."); throw new IOException("Invalid Header.");
} }
}
//Seek to the end of the comment. // Seek to the end of the comment.
FS.Seek(53, SeekOrigin.Begin); fs.Seek(53, SeekOrigin.Begin);
int Size = FS.ReadByte() + FS.ReadByte() * 256; int size = fs.ReadByte() + (fs.ReadByte() * 256);
if (FS.Length != Size + 57) if (fs.Length != size + 57)
{ {
FS.Close(); fs.Close();
throw new IOException("Invalid file length."); throw new IOException("Invalid file length.");
} }
//Verify the checksum. // Verify the checksum.
ushort Checksum = 0; ushort checksum = 0;
for (int n = 0; n < Size; n++) for (int n = 0; n < size; n++)
Checksum += (ushort)FS.ReadByte();
ushort ActualChecksum = (ushort)(FS.ReadByte() + FS.ReadByte() * 256);
if (Checksum != ActualChecksum)
{ {
FS.Close(); checksum += (ushort)fs.ReadByte();
}
ushort actualChecksum = (ushort)(fs.ReadByte() + (fs.ReadByte() * 256));
if (checksum != actualChecksum)
{
fs.Close();
throw new IOException("Invalid Checksum."); throw new IOException("Invalid Checksum.");
} }
} }
private void SendNextFile() private void SendNextFile()
{ {
byte[] Header = new byte[13]; byte[] header = new byte[13];
if (!CurrentFile.CanRead || CurrentFile.Read(Header, 0, 13) != 13) if (!_currentFile.CanRead || _currentFile.Read(header, 0, 13) != 13)
{ {
//End of file. // End of file.
CurrentFile.Close(); _currentFile.Close();
return; return;
} }
int Size = Header[2] + Header[3] * 256; int size = header[2] + (header[3] * 256);
VariableData = new byte[Size + 2]; _variableData = new byte[size + 2];
CurrentFile.Read(VariableData, 0, Size + 2); _currentFile.Read(_variableData, 0, size + 2);
//Request to send the file. // Request to send the file.
CurrentData.Clear(); CurrentData.Clear();
CurrentData.Enqueue(0x03); CurrentData.Enqueue(0x03);
CurrentData.Enqueue(0xC9); CurrentData.Enqueue(0xC9);
foreach (byte B in Header) foreach (byte b in header)
CurrentData.Enqueue(B); {
CurrentData.Enqueue(b);
}
//Calculate the checksum for the command. // Calculate the checksum for the command.
ushort Checksum = 0; ushort checksum = 0;
for (int n = 2; n < Header.Length; n++) for (int n = 2; n < header.Length; n++)
Checksum += Header[n]; {
checksum += header[n];
}
CurrentData.Enqueue((byte)(Checksum % 256)); CurrentData.Enqueue((byte)(checksum % 256));
CurrentData.Enqueue((byte)(Checksum / 256)); CurrentData.Enqueue((byte)(checksum / 256));
//Finalize the command. // Finalize the command.
CurrentStatus = Status.PrepareReceive; _currentStatus = Status.PrepareReceive;
NextStep = ReceiveReqAck; _nextStep = ReceiveReqAck;
Parent.LinkActive = true; Parent.LinkActive = true;
} }
@ -263,9 +289,9 @@ namespace BizHawk.Emulation.Cores.Calculators
CurrentData.Clear(); CurrentData.Clear();
// Prepare to receive the Aknowledgement response from the calculator. // Prepare to receive the Aknowledgement response from the calculator.
BytesToSend = 8; _bytesToSend = 8;
CurrentStatus = Status.PrepareSend; _currentStatus = Status.PrepareSend;
NextStep = SendVariableData; _nextStep = SendVariableData;
} }
private void SendVariableData() private void SendVariableData()
@ -293,20 +319,24 @@ namespace BizHawk.Emulation.Cores.Calculators
CurrentData.Enqueue(0x03); CurrentData.Enqueue(0x03);
CurrentData.Enqueue(0x15); CurrentData.Enqueue(0x15);
//Add variable data. // Add variable data.
foreach (byte B in VariableData) foreach (byte b in _variableData)
CurrentData.Enqueue(B); {
CurrentData.Enqueue(b);
}
//Calculate the checksum. // Calculate the checksum.
ushort Checksum = 0; ushort checksum = 0;
for (int n = 2; n < VariableData.Length; n++) for (int n = 2; n < _variableData.Length; n++)
Checksum += VariableData[n]; {
checksum += _variableData[n];
}
CurrentData.Enqueue((byte)(Checksum % 256)); CurrentData.Enqueue((byte)(checksum % 256));
CurrentData.Enqueue((byte)(Checksum / 256)); CurrentData.Enqueue((byte)(checksum / 256));
CurrentStatus = Status.PrepareReceive; _currentStatus = Status.PrepareReceive;
NextStep = ReceiveDataAck; _nextStep = ReceiveDataAck;
Parent.LinkActive = true; Parent.LinkActive = true;
} }
} }
@ -317,9 +347,9 @@ namespace BizHawk.Emulation.Cores.Calculators
CurrentData.Clear(); CurrentData.Clear();
// Prepare to receive the Aknowledgement response from the calculator. // Prepare to receive the Aknowledgement response from the calculator.
BytesToSend = 4; _bytesToSend = 4;
CurrentStatus = Status.PrepareSend; _currentStatus = Status.PrepareSend;
NextStep = EndTransmission; _nextStep = EndTransmission;
} }
private void EndTransmission() private void EndTransmission()
@ -332,21 +362,21 @@ namespace BizHawk.Emulation.Cores.Calculators
CurrentData.Enqueue(0x00); CurrentData.Enqueue(0x00);
CurrentData.Enqueue(0x00); CurrentData.Enqueue(0x00);
CurrentStatus = Status.PrepareReceive; _currentStatus = Status.PrepareReceive;
NextStep = FinalizeFile; _nextStep = FinalizeFile;
Parent.LinkActive = true; Parent.LinkActive = true;
} }
private void OutOfMemory() private void OutOfMemory()
{ {
CurrentFile.Close(); _currentFile.Close();
Parent.LinkActive = false; Parent.LinkActive = false;
CurrentData.Clear(); CurrentData.Clear();
// Prepare to receive the Aknowledgement response from the calculator. // Prepare to receive the Aknowledgement response from the calculator.
BytesToSend = 3; _bytesToSend = 3;
CurrentStatus = Status.PrepareSend; _currentStatus = Status.PrepareSend;
NextStep = EndOutOfMemory; _nextStep = EndOutOfMemory;
} }
private void EndOutOfMemory() private void EndOutOfMemory()
@ -359,8 +389,8 @@ namespace BizHawk.Emulation.Cores.Calculators
CurrentData.Enqueue(0x01); CurrentData.Enqueue(0x01);
CurrentData.Enqueue(0x00); CurrentData.Enqueue(0x00);
CurrentStatus = Status.PrepareReceive; _currentStatus = Status.PrepareReceive;
NextStep = FinalizeFile; _nextStep = FinalizeFile;
Parent.LinkActive = true; Parent.LinkActive = true;
} }
@ -369,7 +399,7 @@ namespace BizHawk.Emulation.Cores.Calculators
// Resets the link software, and checks to see if there is an additional file to send. // Resets the link software, and checks to see if there is an additional file to send.
CurrentData.Clear(); CurrentData.Clear();
Parent.LinkActive = false; Parent.LinkActive = false;
NextStep = null; _nextStep = null;
SendNextFile(); SendNextFile();
} }
} }

View File

@ -51,8 +51,8 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
_machine.BizInitialize(); _machine.BizInitialize();
//make a writeable memory stream cloned from the rom. // make a writeable memory stream cloned from the rom.
//for junk.dsk the .dsk is important because it determines the format from that // for junk.dsk the .dsk is important because it determines the format from that
InitDisk(); InitDisk();
ser.Register<ITraceable>(Tracer); ser.Register<ITraceable>(Tracer);
@ -64,14 +64,13 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
PutSettings(settings ?? new Settings()); PutSettings(settings ?? new Settings());
} }
private List<GameInfo> GameInfoSet { get; set; }
public List<GameInfo> GameInfoSet { get; private set; }
private readonly List<byte[]> RomSet = new List<byte[]>(); private readonly List<byte[]> RomSet = new List<byte[]>();
public int CurrentDisk { get; private set; } public int CurrentDisk { get; private set; }
public int DiskCount { get { return RomSet.Count; } } public int DiskCount => RomSet.Count;
private ITraceable Tracer { get; set; } private ITraceable Tracer { get; }
public void SetDisk(int discNum) public void SetDisk(int discNum)
{ {
@ -106,8 +105,8 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
{ {
_disk1 = RomSet[CurrentDisk]; _disk1 = RomSet[CurrentDisk];
//make a writeable memory stream cloned from the rom. // make a writeable memory stream cloned from the rom.
//for junk.dsk the .dsk is important because it determines the format from that // for junk.dsk the .dsk is important because it determines the format from that
_machine.BootDiskII.Drives[0].InsertDisk("junk.dsk", (byte[])_disk1.Clone(), false); _machine.BootDiskII.Drives[0].InsertDisk("junk.dsk", (byte[])_disk1.Clone(), false);
} }

View File

@ -29,7 +29,9 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=II/@EntryIndexedValue">II</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=II/@EntryIndexedValue">II</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IO/@EntryIndexedValue">IO</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IO/@EntryIndexedValue">IO</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPS/@EntryIndexedValue">IPS</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPS/@EntryIndexedValue">IPS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IRQ/@EntryIndexedValue">IRQ</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NES/@EntryIndexedValue">NES</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NES/@EntryIndexedValue">NES</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NMI/@EntryIndexedValue">NMI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OR/@EntryIndexedValue">OR</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OR/@EntryIndexedValue">OR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PC/@EntryIndexedValue">PC</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PC/@EntryIndexedValue">PC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PCECD/@EntryIndexedValue">PCECD</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PCECD/@EntryIndexedValue">PCECD</s:String>