Skip to content

Commit

Permalink
Allow for external binary inclusion using incbin
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenretriverYT committed Jun 24, 2023
1 parent b06f2d7 commit 08b8dfa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion source/XSharp/XSharp/Assembler/Gen1/DataMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ public class DataMember : BaseAssemblerElement, IComparable<DataMember>
private string Size;
private string StringValue;
private Type Type;
private bool isIncBin;

// Hack for not to emit raw data. See RawAsm
public DataMember()
{
Name = "Dummy";
}

public DataMember(string aName, string aValue, bool noConvert = false)
public DataMember(string aName, string aValue, bool noConvert = false, bool isIncBin = false)
{
this.isIncBin = isIncBin;

if (noConvert)
{
Name = aName;
Expand Down Expand Up @@ -154,6 +157,13 @@ public override void WriteText(Assembler aAssembler, TextWriter aOutput)
return;
}

if(isIncBin) {
aOutput.Write(Name);
aOutput.WriteLine(":");
aOutput.WriteLine("incbin \"" + StringValue + "\"");
return;
}

if (RawDefaultValue != null)
{
if (RawDefaultValue.Length == 0)
Expand Down
4 changes: 4 additions & 0 deletions source/XSharp/XSharp/Gen1/XS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ public static void DataMember(string name, string value)
Assembler.Assembler.CurrentInstance.DataMembers.Add(new DataMember(name, value));
}

public static void DataMember(string name, string value, bool isIncBin) {
Assembler.Assembler.CurrentInstance.DataMembers.Add(new DataMember(name, value, true, isIncBin));
}

public static void DataMemberBytes(string name, byte[] value)
{
Assembler.Assembler.CurrentInstance.DataMembers.Add(new DataMember(name, value));
Expand Down

0 comments on commit 08b8dfa

Please sign in to comment.