public static string FilenameToUnicode(GR.Memory.ByteBuffer Filename) { string filename = ""; for (int i = 0; i < Filename.Length; ++i) { if (Filename.ByteAt(i) == 0xa0) { break; } byte petscii = Filename.ByteAt(i); filename += (char)ConstantData.PETSCIIToUnicode[petscii]; } return(filename); }
public void UpdateMemory(VICERemoteDebugger.RequestData Request, GR.Memory.ByteBuffer Data) { int Offset = Request.Parameter1; for (int i = 0; i < Data.Length; ++i) { byte ramByte = Data.ByteAt(i); if (Request.Reason != VICERemoteDebugger.RequestReason.MEMORY_FETCH) { /* * if ( ramByte != Core.Debugging.ActiveMemory.RAM.ByteAt( Offset + i ) ) * { * Core.Debugging.ActiveMemory.RAMChanged[Offset + i] = true; * * hexView.SelectedByteProvider.SetByteSelectionState( Offset + i, true ); * } * else * { * Core.Debugging.ActiveMemory.RAMChanged[Offset + i] = false; * * hexView.SelectedByteProvider.SetByteSelectionState( Offset + i, false ); * }*/ hexView.SelectedByteProvider.SetByteSelectionState(Offset + i, Core.Debugging.ActiveMemory.RAMChanged[Offset + i]); } //Core.Debugging.ActiveMemory.RAM.SetU8At( Offset + i, ramByte ); hexView.ByteProvider.WriteByte(Offset + i, ramByte); } //ValidateMemory( Offset, (int)Data.Length ); hexView.Invalidate(); }
public static string FilenameToUnicode(GR.Memory.ByteBuffer Filename) { string filename = ""; int numShiftSpacesAtEnd = 0; int pos = (int)Filename.Length; while ((pos > 0) && (Filename.ByteAt(pos - 1) == 0xa0)) { --pos; } numShiftSpacesAtEnd = (int)Filename.Length - pos; for (int i = 0; i < Filename.Length - numShiftSpacesAtEnd; ++i) { byte petscii = Filename.ByteAt(i); filename += (char)ConstantData.PETSCIIToUnicode[petscii]; } return(filename); }
private void btnImportFromHex_Click(object sender, EventArgs e) { string binaryText = editDataExport.Text.Replace(" ", "").Replace("\r", "").Replace("\n", ""); GR.Memory.ByteBuffer data = new GR.Memory.ByteBuffer(binaryText); m_Project.ValueTable.Values.Clear(); m_Project.ValueTable.Data = data; for (int i = 0; i < data.Length; ++i) { m_Project.ValueTable.Values.Add(data.ByteAt(i).ToString()); } SetModified(); }
public static string FilenameToReadableUnicode(GR.Memory.ByteBuffer Filename) { string filename = ""; for (int i = 0; i < Filename.Length; ++i) { if (Filename.ByteAt(i) == 0xa0) { break; } byte petscii = Filename.ByteAt(i); char character = ConstantData.PETSCIIToUnicode[petscii]; if ((character >= 32) && (character < 128)) { filename += character; } else { filename += 'X'; } } return(filename); }
internal static string ToBASICHexData(GR.Memory.ByteBuffer Data, int StartLine, int LineOffset, int WrapByteCount) { if (WrapByteCount < 1) { return(ToBASICHexData(Data, StartLine, LineOffset)); } StringBuilder sb = new StringBuilder(); if (LineOffset <= 0) { LineOffset = 1; } if (StartLine < 0) { StartLine = 0; } int dataPos = 0; while (dataPos < Data.Length) { int startLength = sb.Length; sb.Append(StartLine); sb.Append("DATA"); bool firstByte = true; int numBytesInLine = 0; while ((numBytesInLine < WrapByteCount) && (dataPos < Data.Length)) { if (!firstByte) { sb.Append(','); } firstByte = false; sb.Append(Data.ByteAt(dataPos).ToString("X2")); ++dataPos; ++numBytesInLine; } sb.AppendLine(); StartLine += LineOffset; } return(sb.ToString()); }
public byte PaletteRed(int Index) { if (m_PaletteData == null) { return(0); } if ((Index < 0) || (Index >= (int)m_PaletteData.Length / 3)) { return(0); } return(m_PaletteData.ByteAt(Index * 3)); }
internal static string ToBASICData(GR.Memory.ByteBuffer Data, int StartLine, int LineOffset) { StringBuilder sb = new StringBuilder(); if (LineOffset <= 0) { LineOffset = 1; } if (StartLine < 0) { StartLine = 0; } int dataPos = 0; while (dataPos < Data.Length) { int startLength = sb.Length; sb.Append(StartLine); sb.Append("DATA"); bool firstByte = true; while ((sb.Length - startLength < 80) && (dataPos < Data.Length)) { if (!firstByte) { sb.Append(','); } firstByte = false; sb.Append(Data.ByteAt(dataPos)); ++dataPos; } sb.AppendLine(); StartLine += LineOffset; } return(sb.ToString()); }
public void UpdateMemory(RequestData Request, GR.Memory.ByteBuffer Data) { int Offset = Request.Parameter1; for (int i = 0; i < Data.Length; ++i) { byte ramByte = Data.ByteAt(i); if (Request.Reason != RequestReason.MEMORY_FETCH) { /* * if ( ramByte != Core.Debugging.ActiveMemory.RAM.ByteAt( Offset + i ) ) * { * Core.Debugging.ActiveMemory.RAMChanged[Offset + i] = true; * * hexView.SelectedByteProvider.SetByteSelectionState( Offset + i, true ); * } * else * { * Core.Debugging.ActiveMemory.RAMChanged[Offset + i] = false; * * hexView.SelectedByteProvider.SetByteSelectionState( Offset + i, false ); * }*/ bool markAsChanged = (Core.Debugging.ActiveMemory.Flags[Offset + i] & MemoryView.RAMFlag.VALUE_CHANGED) != 0; if ((Core.Debugging.ActiveMemory.Flags[Offset + i] & MemoryView.RAMFlag.VALUE_KNOWN) == 0) { markAsChanged = false; } hexView.SelectedByteProvider.SetByteSelectionState(Offset + i, markAsChanged); } //Core.Debugging.ActiveMemory.RAM.SetU8At( Offset + i, ramByte ); hexView.ByteProvider.WriteByte(Offset + i, ramByte); } //ValidateMemory( Offset, (int)Data.Length ); hexView.Invalidate(); }
private bool ImportChar(GR.Image.FastImage Image, int CharIndex, bool ForceMulticolor) { if (Image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed) { // invalid format return(false); } // Match image data GR.Memory.ByteBuffer Buffer = new GR.Memory.ByteBuffer(m_Charset.Characters[CharIndex].Data); int chosenCharColor = -1; bool isMultiColor = false; unsafe { // determine single/multi color bool[] usedColor = new bool[16]; int numColors = 0; bool hasSinglePixel = false; bool usedBackgroundColor = false; for (int y = 0; y < Image.Height; ++y) { for (int x = 0; x < Image.Width; ++x) { int colorIndex = (int)Image.GetPixelData(x, y) % 16; if (colorIndex >= 16) { return(false); } if ((x % 2) == 0) { if (colorIndex != (int)Image.GetPixelData(x + 1, y) % 16) { // not a double pixel, must be single color then hasSinglePixel = true; } } if (!usedColor[colorIndex]) { if (colorIndex == m_Charset.BackgroundColor) { usedBackgroundColor = true; } usedColor[colorIndex] = true; numColors++; } } } //Debug.Log( "For Char " + CharIndex + ", hasSinglePixel = " + hasSinglePixel + ", numColors = " + numColors + ", usedBackgroundColor = " + usedBackgroundColor ); if ((hasSinglePixel) && (numColors > 2)) { return(false); } if ((hasSinglePixel) && (numColors == 2) && (!usedBackgroundColor)) { return(false); } if ((!hasSinglePixel) && (numColors > 4)) { return(false); } if ((!hasSinglePixel) && (numColors == 4) && (!usedBackgroundColor)) { return(false); } int otherColorIndex = 16; if ((!hasSinglePixel) && (numColors == 2) && (usedBackgroundColor)) { for (int i = 0; i < 16; ++i) { if ((usedColor[i]) && (i != m_Charset.BackgroundColor)) { otherColorIndex = i; break; } } } if ((!ForceMulticolor) && ((hasSinglePixel) || ((numColors == 2) && (usedBackgroundColor) && (otherColorIndex < 8)))) //|| ( numColors == 2 ) ) { // eligible for single color int usedFreeColor = -1; for (int i = 0; i < 16; ++i) { if (usedColor[i]) { if (i != m_Charset.BackgroundColor) { if (usedFreeColor != -1) { return(false); } usedFreeColor = i; } } } for (int y = 0; y < Image.Height; ++y) { for (int x = 0; x < Image.Width; ++x) { int ColorIndex = (int)Image.GetPixelData(x, y) % 16; int BitPattern = 0; if (ColorIndex != m_Charset.BackgroundColor) { BitPattern = 1; } // noch nicht verwendete Farbe if (BitPattern == 1) { chosenCharColor = ColorIndex; } byte byteMask = (byte)(255 - (1 << ((7 - (x % 8))))); Buffer.SetU8At(y + x / 8, (byte)((Buffer.ByteAt(y + x / 8) & byteMask) | (BitPattern << ((7 - (x % 8)))))); } } } else { // multi color isMultiColor = true; int usedMultiColors = 0; int usedFreeColor = -1; for (int i = 0; i < 16; ++i) { if (usedColor[i]) { if ((i == m_Charset.MultiColor1) || (i == m_Charset.MultiColor2) || (i == m_Charset.BackgroundColor)) { ++usedMultiColors; } else { usedFreeColor = i; } } } if (numColors - usedMultiColors > 1) { // only one free color allowed return(false); } for (int y = 0; y < Image.Height; ++y) { for (int x = 0; x < Image.Width / 2; ++x) { int ColorIndex = (int)Image.GetPixelData(2 * x, y) % 16; byte BitPattern = 0; if (ColorIndex == m_Charset.BackgroundColor) { BitPattern = 0x00; } else if (ColorIndex == m_Charset.MultiColor1) { BitPattern = 0x01; } else if (ColorIndex == m_Charset.MultiColor2) { BitPattern = 0x02; } else { // noch nicht verwendete Farbe chosenCharColor = usedFreeColor; BitPattern = 0x03; } byte byteMask = (byte)(255 - (3 << ((3 - (x % 4)) * 2))); Buffer.SetU8At(y + x / 4, (byte)((Buffer.ByteAt(y + x / 4) & byteMask) | (BitPattern << ((3 - (x % 4)) * 2)))); } } } } for (int i = 0; i < 8; ++i) { m_Charset.Characters[CharIndex].Data.SetU8At(i, Buffer.ByteAt(i)); } if (chosenCharColor == -1) { chosenCharColor = 0; } m_Charset.Characters[CharIndex].Color = chosenCharColor; if ((isMultiColor) && (chosenCharColor < 8)) { m_Charset.Characters[CharIndex].Color = chosenCharColor + 8; } m_Charset.Characters[CharIndex].Mode = isMultiColor ? Types.CharsetMode.MULTICOLOR : C64Studio.Types.CharsetMode.HIRES; return(true); }
public static string ToASMData(GR.Memory.ByteBuffer Data, bool WrapData, int WrapByteCount, string DataByteDirective, bool AsHex) { StringBuilder sb = new StringBuilder(); if (WrapData) { sb.Append(DataByteDirective); if (!DataByteDirective.EndsWith(" ")) { sb.Append(' '); } int byteCount = 0; for (int i = 0; i < Data.Length; ++i) { if (AsHex) { sb.Append('$'); sb.Append(Data.ByteAt(i).ToString("x2")); } else { sb.Append(Data.ByteAt(i).ToString()); } ++byteCount; if ((byteCount < WrapByteCount) && (i < Data.Length - 1)) { sb.Append(','); } if (byteCount == WrapByteCount) { byteCount = 0; sb.AppendLine(); if (i < Data.Length - 1) { sb.Append(DataByteDirective); if (!DataByteDirective.EndsWith(" ")) { sb.Append(' '); } } } } } else { sb.Append(DataByteDirective); sb.Append(' '); for (int i = 0; i < Data.Length; ++i) { if (AsHex) { sb.Append('$'); sb.Append(Data.ByteAt(i).ToString("x2")); } else { sb.Append(Data.ByteAt(i).ToString()); } if (i < Data.Length - 1) { sb.Append(','); } } } return(sb.ToString()); }
internal static string ToBASICData(GR.Memory.ByteBuffer Data, int StartLine, int LineOffset, int WrapByteCount, int WrapCharCount) { StringBuilder sb = new StringBuilder(); if (WrapByteCount < 1) { WrapByteCount = 80; } if (WrapCharCount < 20) { WrapCharCount = 20; } if (LineOffset <= 0) { LineOffset = 1; } if (StartLine < 0) { StartLine = 0; } int dataPos = 0; while (dataPos < Data.Length) { int startLength = sb.Length; sb.Append(StartLine); sb.Append("DATA"); bool firstByte = true; int numBytesInLine = 0; if (WrapCharCount > 0) { // length of line number plus token numBytesInLine = StartLine.ToString().Length + 1; while ((numBytesInLine < WrapCharCount) && (dataPos < Data.Length)) { int numCharsToAdd = Data.ByteAt(dataPos).ToString().Length; if (!firstByte) { ++numCharsToAdd; } if (numBytesInLine + numCharsToAdd > WrapCharCount) { break; } if (!firstByte) { sb.Append(','); } firstByte = false; sb.Append(Data.ByteAt(dataPos)); ++dataPos; numBytesInLine += numCharsToAdd; } } else { while ((numBytesInLine < WrapByteCount) && (dataPos < Data.Length)) { if (!firstByte) { sb.Append(','); } firstByte = false; sb.Append(Data.ByteAt(dataPos)); ++dataPos; ++numBytesInLine; } } sb.AppendLine(); StartLine += LineOffset; } return(sb.ToString()); }
public void SetPixel(int X, int Y, uint Value) { if ((X < 0) || (X >= m_Width) || (Y < 0) || (Y >= m_Height)) { return; } if (m_ImageData.Empty()) { return; } switch (BitsPerPixel) { case 1: unsafe { int pitch = (Width + 7) / 8; byte origValue = m_ImageData.ByteAt(Y * pitch + X / 8); byte newValue = origValue; if (Value != 0) { newValue = (byte)(origValue | (128 >> (X % 8))); } else { newValue = (byte)(origValue & (~(128 >> (X % 8)))); } m_ImageData.SetU8At(Y * pitch + X / 8, newValue); } break; case 4: unsafe { int pitch = Width / 2; byte origValue = m_ImageData.ByteAt(Y * pitch + X / 2); byte newValue = 0; if ((X % 2) == 0) { newValue = (byte)((origValue & 0x0f) | ((byte)Value << 4)); } else { newValue = (byte)((origValue & 0xf0) | (byte)Value); } m_ImageData.SetU8At(Y * pitch + X / 2, newValue); }; break; case 8: m_ImageData.SetU8At(Y * m_Width + X, (byte)Value); break; case 16: m_ImageData.SetU16At(2 * (Y * m_Width + X), (ushort)((((Value & 0xff0000) >> 19) << 10) + (((Value & 0x00ff00) >> 11) << 5) + (((Value & 0x0000ff) >> 3)))); break; case 24: m_ImageData.SetU8At(3 * (Y * m_Width + X) + 0, (byte)(Value & 0xff)); m_ImageData.SetU8At(3 * (Y * m_Width + X) + 1, (byte)((Value & 0xff00) >> 8)); m_ImageData.SetU8At(3 * (Y * m_Width + X) + 2, (byte)((Value & 0xff0000) >> 16)); break; case 32: m_ImageData.SetU32At(4 * (Y * m_Width + X), Value); break; default: throw new NotSupportedException("Bitdepth " + BitsPerPixel + " not supported yet"); } }