mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-20 04:48:53 +00:00
60 lines
2.3 KiB
C#
60 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Cosmos.IL2CPU.Debug;
|
|
|
|
namespace Cosmos.Build.Windows {
|
|
public abstract class DebugConnector {
|
|
protected delegate void PacketReceivedDelegate(byte[] aBytes);
|
|
public delegate void ConnectionLostDelegate(Exception ex);
|
|
public delegate void CmdTextDelegate(string aText);
|
|
|
|
//TODO: These should not be this way and should in fact
|
|
// be checked or better yet done by constructor arguments
|
|
// but that puts a restriction on where the sub classes
|
|
// are created.
|
|
public ConnectionLostDelegate ConnectionLost;
|
|
public Action<UInt32> CmdTrace;
|
|
public CmdTextDelegate CmdText;
|
|
|
|
protected abstract void SendData(byte[] aBytes);
|
|
protected abstract void Next(int aPacketSize, PacketReceivedDelegate aCompleted);
|
|
protected abstract void PacketTracePoint(byte[] aPacket);
|
|
protected abstract void PacketText(byte[] aPacket);
|
|
|
|
public void SendCommand(byte aCmd) {
|
|
var xData = new byte[1];
|
|
xData[0] = aCmd;
|
|
SendData(xData);
|
|
}
|
|
|
|
protected UInt32 GetUInt32(byte[] aBytes, int aOffset) {
|
|
return (UInt32)((aBytes[aOffset + 3] << 24) | (aBytes[aOffset + 2] << 16)
|
|
| (aBytes[aOffset + 1] << 8) | aBytes[aOffset + 0]);
|
|
}
|
|
|
|
protected UInt16 GetUInt16(byte[] aBytes, int aOffset) {
|
|
return (UInt16)((aBytes[aOffset + 1] << 8) | aBytes[aOffset + 0]);
|
|
}
|
|
|
|
protected void PacketCommand(byte[] aPacket) {
|
|
// Could change to an array, but really not much benefit
|
|
switch ((MsgType)aPacket[0]) {
|
|
case MsgType.TracePoint:
|
|
Next(4, PacketTracePoint);
|
|
break;
|
|
case MsgType.Text:
|
|
Next(2, PacketTextSize);
|
|
break;
|
|
default:
|
|
throw new Exception("Unknown debug command");
|
|
}
|
|
}
|
|
|
|
protected void PacketTextSize(byte[] aPacket) {
|
|
Next(GetUInt16(aPacket, 0), PacketText);
|
|
}
|
|
|
|
}
|
|
}
|