public override GR.Memory.ByteBuffer Compile() { _LastError = ""; GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer(); // C64-TAPE-RAW result.AppendHex("4336342D544150452D524157"); // version (0 or 1) result.AppendU8(0); // reserved result.AppendU8(0); result.AppendU8(0); result.AppendU8(0); // size result.AppendU32(0); foreach (FileEntry file in TapFiles) { AppendFile(result, file); } result.SetU32At(16, result.Length - 20); return(result); }
private void btnImportBinary_Click(object sender, EventArgs e) { if (!Clipboard.ContainsText()) { return; } string text = Clipboard.GetText().Replace(" ", ""); GR.Memory.ByteBuffer data = new GR.Memory.ByteBuffer(); if (!data.AppendHex(text)) { return; } m_Disassembler.SetData(data); m_DisassemblyProject.Data = data; SetHexData(data); UpdateDisassembly(); }
public bool HasBASICJumpAddress(int DataStartAddress, out int SysAddress) { SysAddress = 0; if ((DataStartAddress == 0x0801) || (DataStartAddress == 0x0800)) { // validate basic header, look for jump address // 00 08 00 0C 08 0A 00 9E 32 30 36 34 00 00 00 int dataPos = 0x0801 - DataStartAddress; ushort pointerToNextLine = m_SourceData.UInt16At(dataPos); ushort lineNumber = m_SourceData.UInt16At(dataPos + 2); byte sysInstruction = m_SourceData.ByteAt(dataPos + 4); if (sysInstruction != 0x9e) { // not a SYS command return(false); } string sysAddress = ""; dataPos += 5; while ((dataPos < m_SourceData.Length) && (m_SourceData.ByteAt(dataPos) != 0)) { sysAddress += m_SourceData.ByteAt(dataPos).ToString("X2"); ++dataPos; } GR.Memory.ByteBuffer sysAddrData = new GR.Memory.ByteBuffer(); if (!sysAddrData.AppendHex(sysAddress)) { return(false); } SysAddress = GR.Convert.ToI32(sysAddrData.ToAsciiString()); return(true); } return(false); }
public bool ExportMapExtraDataAsAssembly(out string MapData, string LabelPrefix, bool WrapData, int WrapByteCount, string DataByteDirective) { bool hasExtraData = false; foreach (var map in Maps) { if (map.ExtraDataText.Length > 0) { hasExtraData = true; break; } } StringBuilder sbMaps = new StringBuilder(); sbMaps.Append(LabelPrefix); sbMaps.Append("NUM_MAPS = "); sbMaps.AppendLine(Maps.Count.ToString()); if (hasExtraData) { sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_EXTRA_DATA_LIST_LO"); for (int i = 0; i < Maps.Count; ++i) { sbMaps.Append(DataByteDirective); sbMaps.Append(' '); sbMaps.AppendLine("<" + LabelPrefix + "MAP_EXTRA_DATA_" + Maps[i].Name.ToUpper().Replace(' ', '_')); } sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_EXTRA_DATA_LIST_HI"); for (int i = 0; i < Maps.Count; ++i) { sbMaps.Append(DataByteDirective); sbMaps.Append(' '); sbMaps.AppendLine(">" + LabelPrefix + "MAP_EXTRA_DATA_" + Maps[i].Name.ToUpper().Replace(' ', '_')); } sbMaps.AppendLine(); } for (int i = 0; i < Maps.Count; ++i) { var map = Maps[i]; if ((hasExtraData) && (map.ExtraDataText.Length > 0)) { sbMaps.AppendLine(";extra data"); sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_EXTRA_DATA_" + map.Name.ToUpper().Replace(' ', '_')); // clean extra data GR.Memory.ByteBuffer extraData = new GR.Memory.ByteBuffer(); string[] lines = map.ExtraDataText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { string tempLine = line.Trim().Replace(" ", ""); if ((!tempLine.StartsWith(";")) && (!tempLine.StartsWith("#")) && (!tempLine.StartsWith("//"))) { extraData.AppendHex(tempLine); } } sbMaps.Append(Util.ToASMData(extraData, WrapData, WrapByteCount, DataByteDirective)); sbMaps.AppendLine(); } } MapData = sbMaps.ToString(); return(true); }
public bool ExportMapsAsAssembly(bool Vertical, out string MapData, string LabelPrefix, bool WrapData, int WrapByteCount, string DataByteDirective) { bool hasExtraData = false; foreach (var map in Maps) { if (map.ExtraDataText.Length > 0) { hasExtraData = true; break; } } StringBuilder sbMaps = new StringBuilder(); sbMaps.Append(LabelPrefix); sbMaps.Append("NUM_MAPS = "); sbMaps.AppendLine(Maps.Count.ToString()); sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_LIST_LO"); for (int i = 0; i < Maps.Count; ++i) { sbMaps.Append(DataByteDirective); sbMaps.Append(' '); sbMaps.AppendLine("<" + LabelPrefix + "MAP_" + NormalizeAsLabel(Maps[i].Name.ToUpper())); } sbMaps.AppendLine(); sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_LIST_HI"); for (int i = 0; i < Maps.Count; ++i) { sbMaps.Append(DataByteDirective); sbMaps.Append(' '); sbMaps.AppendLine(">" + LabelPrefix + "MAP_" + NormalizeAsLabel(Maps[i].Name.ToUpper())); } sbMaps.AppendLine(); if (hasExtraData) { sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_EXTRA_DATA_LIST_LO"); for (int i = 0; i < Maps.Count; ++i) { sbMaps.Append(DataByteDirective); sbMaps.Append(' '); sbMaps.AppendLine("<" + LabelPrefix + "MAP_EXTRA_DATA_" + NormalizeAsLabel(Maps[i].Name.ToUpper())); } sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_EXTRA_DATA_LIST_HI"); for (int i = 0; i < Maps.Count; ++i) { sbMaps.Append(DataByteDirective); sbMaps.Append(' '); sbMaps.AppendLine(">" + LabelPrefix + "MAP_EXTRA_DATA_" + NormalizeAsLabel(Maps[i].Name.ToUpper())); } sbMaps.AppendLine(); } for (int i = 0; i < Maps.Count; ++i) { var map = Maps[i]; sbMaps.AppendLine(); sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_" + NormalizeAsLabel(map.Name.ToUpper())); GR.Memory.ByteBuffer mapDataBuffer = new GR.Memory.ByteBuffer((uint)(map.Tiles.Width * map.Tiles.Height)); if (Vertical) { for (int y = 0; y < map.Tiles.Height; ++y) { for (int x = 0; x < map.Tiles.Width; ++x) { mapDataBuffer.SetU8At(x * map.Tiles.Height + y, (byte)map.Tiles[x, y]); } } } else { for (int y = 0; y < map.Tiles.Height; ++y) { for (int x = 0; x < map.Tiles.Width; ++x) { mapDataBuffer.SetU8At(x + y * map.Tiles.Width, (byte)map.Tiles[x, y]); } } } sbMaps.AppendLine(); sbMaps.Append(Util.ToASMData(mapDataBuffer, WrapData, WrapByteCount, DataByteDirective)); if ((hasExtraData) && (map.ExtraDataText.Length > 0)) { sbMaps.AppendLine(";extra data"); sbMaps.Append(LabelPrefix); sbMaps.AppendLine("MAP_EXTRA_DATA_" + NormalizeAsLabel(map.Name.ToUpper())); // clean extra data GR.Memory.ByteBuffer extraData = new GR.Memory.ByteBuffer(); string[] lines = map.ExtraDataText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { string tempLine = line.Trim().Replace(" ", ""); if ((!tempLine.StartsWith(";")) && (!tempLine.StartsWith("#")) && (!tempLine.StartsWith("//"))) { extraData.AppendHex(tempLine); } } sbMaps.Append(Util.ToASMData(extraData, WrapData, WrapByteCount, DataByteDirective)); sbMaps.AppendLine(); } } MapData = sbMaps.ToString(); return(true); }