-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmix-wasm.c
197 lines (168 loc) · 3.89 KB
/
mmix-wasm.c
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <setjmp.h>
#include <stdio.h>
#include <string.h>
#include "emscripten.h"
#include "abstime.h"
#include "libconfig.h"
#include "libtype.h"
#include "libglobals.h"
#include "mmixlib.h"
int mmixal(char[], char[], char[]);
EMSCRIPTEN_KEEPALIVE int mmixal_wasm()
{
return mmixal("y2k.mms", "y2k.mmo", "y2k.mml");
}
EMSCRIPTEN_KEEPALIVE bool get_halted()
{
return halted;
}
EMSCRIPTEN_KEEPALIVE void set_halted(bool v)
{
halted = v;
}
EMSCRIPTEN_KEEPALIVE int get_breakpoint()
{
return breakpoint;
}
EMSCRIPTEN_KEEPALIVE void set_breakpoint(int v)
{
breakpoint = v;
}
EMSCRIPTEN_KEEPALIVE bool get_interrupt()
{
return interrupt;
}
EMSCRIPTEN_KEEPALIVE void set_interrupt(bool v)
{
interrupt = v;
}
EMSCRIPTEN_KEEPALIVE bool get_resuming()
{
return resuming;
}
EMSCRIPTEN_KEEPALIVE void set_resuming(bool v)
{
resuming = v;
}
EMSCRIPTEN_KEEPALIVE bool get_interacting()
{
return interacting;
}
EMSCRIPTEN_KEEPALIVE void set_interacting(bool v)
{
interacting = v;
}
EMSCRIPTEN_KEEPALIVE bool get_interact_after_break()
{
return interact_after_break;
}
EMSCRIPTEN_KEEPALIVE void set_interact_after_break(bool v)
{
interact_after_break = v;
}
EMSCRIPTEN_KEEPALIVE bool get_profiling()
{
return profiling;
}
EMSCRIPTEN_KEEPALIVE void set_profiling(bool v)
{
profiling = v;
}
EMSCRIPTEN_KEEPALIVE bool get_showing_stats()
{
return showing_stats;
}
EMSCRIPTEN_KEEPALIVE void set_showing_stats(bool v)
{
showing_stats = v;
}
EMSCRIPTEN_KEEPALIVE int get_trace_bit()
{
// this is actually a preprocessor builtin
// defined bitmask (1<<3)
// Therefor, no setter
return trace_bit;
}
EMSCRIPTEN_KEEPALIVE int print_mystr(char *mystr)
{
printf("%s", mystr);
return strlen(mystr);
}
EMSCRIPTEN_KEEPALIVE void y2k_mmix_load_file()
{
mmix_load_file("y2k.mmo");
}
EMSCRIPTEN_KEEPALIVE unsigned int get_general_register(int reg_number,
bool high)
{
octa z;
if (reg_number >= G)
z = g[reg_number];
else if (reg_number < L)
z = l[(O + reg_number) & lring_mask];
if (high) {
return z.h;
} else {
return z.l;
}
}
EMSCRIPTEN_KEEPALIVE int mmix_sim()
{
mmix_lib_initialize();
/* g[255].h= 0; */
/* g[255].l= 0; */
mmix_initialize();
boot:
mmix_boot();
mmix_load_file("y2k.mmo");
/* mmix_commandline(argc,argv); */
/* set_breakpoint(0); */
/* if(get_interacting()) */
/* mmix_interact(); */
while (true) {
/* if(get_interrupt()&&!get_breakpoint()) */
/* { */
/* set_breakpoint(breakpoint | trace_bit); */
/* set_interacting(true); */
/* set_interrupt(false); */
/* } */
/* else */
/* { */
/* set_breakpoint(0); */
/* if(get_interacting()) */
/* mmix_interact(); */
/* } */
if (get_halted()) {
printf("zasd");
break;
}
do {
if (!get_resuming())
mmix_fetch_instruction();
mmix_perform_instruction();
mmix_trace();
mmix_dynamic_trap();
if (get_resuming() && op != RESUME)
set_resuming(false);
}
while (get_resuming() || (!get_interrupt() && !get_breakpoint()));
/* if(get_interact_after_break()) */
/* { */
/* set_interacting(true); */
/* set_interact_after_break(false); */
/* } */
/* if(g[rQ].l&g[rK].l&RE_BIT) */
/* { */
/* set_breakpoint(get_breakpoint() | get_trace_bit()); */
/* goto boot; */
/* } */
}
end_simulation:
if (get_profiling())
mmix_profile();
if (get_interacting() || get_profiling() || get_showing_stats())
show_stats(true);
show_stats(true);
mmix_finalize();
return g[255].l;
}