-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAsmCreation.cs
More file actions
73 lines (59 loc) · 1.92 KB
/
AsmCreation.cs
File metadata and controls
73 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Collections.Generic;
using System.Linq;
using Diz.Core.Interfaces;
using Diz.Core.util;
using Diz.LogWriter.assemblyGenerators;
using Diz.LogWriter.util;
namespace Diz.LogWriter;
public interface IAsmCreationStep
{
bool Enabled { get; set; }
void Generate();
}
public abstract class AsmCreationBase : IAsmCreationStep
{
public LogCreator LogCreator { get; init; }
public bool Enabled { get; set; } = true;
public ILogCreatorDataSource<IData> Data => LogCreator?.Data;
public void Generate()
{
if (!Enabled)
return;
Execute();
}
protected abstract void Execute();
}
public class AsmDefinesGenerator : AsmCreationBase
{
public Dictionary<string, string> Defines { get; init; }
protected override void Execute()
{
LogCreator.SwitchOutputStream("defines.asm");
LogCreator.WriteLine("; contains any auto-generated defines from Diz.");
LogCreator.WriteLine("; auto-generated file DON'T edit");
var sortedDefines = Defines
.OrderBy (x => x.Key);
foreach (var (defineName, value) in sortedDefines) {
LogCreator.WriteLine($"{defineName} = {Util.ChopExtraZeroesFromHexStr(value)}");
}
}
}
public class AsmCreationMainBankIncludes : AsmCreationBase
{
protected override void Execute()
{
LogCreator.SwitchOutputStream(LogCreatorStreamOutput.MainStreamFilename);
LogCreator.WriteIncludeFileDirective("defines.asm");
LogCreator.UniqueVisitedBanks.ForEach(LogCreator.WriteIncSrcLineForBank);
LogCreator.WriteIncludeFileDirective("labels.asm");
}
}
public class AsmCreationRomMap : AsmCreationBase
{
protected override void Execute()
{
LogCreator.SwitchOutputStream(LogCreatorStreamOutput.MainStreamFilename);
LogCreator.WriteSpecialLine("map");
LogCreator.WriteEmptyLine();
}
}