-
Notifications
You must be signed in to change notification settings - Fork 0
/
Synth.asl
138 lines (120 loc) · 3.86 KB
/
Synth.asl
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
state("snes9x"){}
state("snes9x-x64"){}
state("bsnes"){}
state("retroarch"){}
state("higan"){}
state("snes9x-rr"){}
state("emuhawk"){}
startup {
vars.ready = false;
vars.running = false;
vars.ticksUntilShowHist = 500;
vars.ticksUntilRecheckGame = 20;
vars.tick = 0;
int maxLagMs = 100;
int minStartDurationMs = 1000;
string recPath = "C:/Users/thedo/Git/kaizosplits/runs"; // Folder to write recorded runs to
byte[] bytes = File.ReadAllBytes("Components/SMW.dll");
Assembly asm = Assembly.Load(bytes);
vars.e = Activator.CreateInstance(asm.GetType("SNES.Emu"));
vars.t = Activator.CreateInstance(asm.GetType("SMW.Timer"));
vars.d = Activator.CreateInstance(asm.GetType("SMW.Debugger"));
vars.ss = Activator.CreateInstance(asm.GetType("SMW.Settings"));
vars.ws = Activator.CreateInstance(asm.GetType("SMW.Watchers"));
vars.r = Activator.CreateInstance(asm.GetType("SMW.Recorder"));
vars.ss.Init(maxLagMs, minStartDurationMs);
vars.ws.Init(vars.ss.UsedMemory());
vars.r.Init(recPath);
vars.ranges = new Dictionary<int, int>() {};
vars.settingsDict = new Dictionary<string, bool>();
foreach (var entry in vars.ss.entries) {
string k = entry.Key;
var v = entry.Value;
bool on = v.Item1;
string name = v.Item2;
string tooltip = v.Item3;
string parent = v.Item4;
settings.Add(k, on, name, parent);
settings.SetToolTip(k, tooltip);
}
}
init {
vars.e.Init(game);
}
update {
var t = vars.t; var d = vars.d; var e = vars.e; var w = vars.ws; var s = vars.ss; var r = vars.r;
// Stuff that should happen after split or start or reset but before real update
t.HistEnd();
if (vars.tick % vars.ticksUntilShowHist == 0) print(t.ToString());
if (d.HasLines()) print(d.ClearLines());
vars.tick++;
bool recheck = vars.tick % vars.ticksUntilRecheckGame == 0;
if (!vars.ready || recheck) {
try {
e.Ready();
} catch (Exception ex) {
d.DbgOnce(ex);
vars.ready = false;
return vars.running; // Return vars.running for opposite behaviour in Start vs Reset
}
}
d.DbgOnce("SMC: " + e.Smc(), "smc");
if (vars.ready) {
// The order here matters (for Spawn recording)
w.UpdateAll(game);
var sd = vars.settingsDict;
sd.Clear();
foreach (string k in s.keys) {
sd[k] = settings[k];
}
s.Update(sd, w);
d.Update(w);
w.UpdateState();
// MONITOR HERE for monitoring even while not in a run
//d.Monitor(w.roomNum, w);
//d.Monitor(w.levelNum, w);
//d.Monitor(w.io, w);
//d.Monitor(w.overworldTile, w);
} else {
try {
var offset = e.GetOffset();
w.SetMemoryOffset(offset, vars.ranges);
vars.memFoundTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
vars.ready = true;
} catch (Exception ex) {
d.DbgOnce(ex);
return false;
}
}
t.HistMid();
}
start {
var d = vars.d; var s = vars.ss; var r = vars.r;
var startDuration = DateTimeOffset.Now.ToUnixTimeMilliseconds() - vars.memFoundTime;
if (s.StartStatus(startDuration)) {
d.Dbg("Start: " + s.StartReasons());
r.StartReasons(s.StartReasons());
return true;
}
}
reset {
var d = vars.d; var s = vars.ss; var e = vars.e; var r = vars.r;
bool smcChanged = e.SmcChanged();
if (s.ResetStatus(vars.ready, smcChanged)) {
var reasons = s.ResetReasons(vars.ready, smcChanged);
r.ResetReasons(reasons);
d.Dbg("Reset: " + reasons);
vars.ready = false;
return true;
}
}
split {
}
onStart {
vars.running = true;
}
onReset {
var r = vars.rec;
r.WriteRun();
vars.running = false;
}