-
Notifications
You must be signed in to change notification settings - Fork 2
/
m68ksim.cc
221 lines (188 loc) · 4.39 KB
/
m68ksim.cc
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <list>
#include "blocks.h"
#include "sched.h"
cstate ref;
void init(cstate &s)
{
memset(&s, 0, sizeof(s));
ref = s;
s.first = true;
s.svtime = -6;
s.bus_delay = true;
}
void update(cstate &s)
{
for(;;) {
std::list<void (*)(cstate &)> f;
compute_sched(ref, s, f, s.first);
s.first = false;
ref = s;
if(f.empty())
break;
for(std::list<void (*)(cstate &)>::const_iterator i = f.begin(); i != f.end(); i++)
(*i)(s);
}
}
void show_state(const cstate &s)
{
printf("%8ld: %4d clk=%d iclk=%d i_reset=%d eu_prw=%c%c%c nano=%x.%08x.%08x ma0=%03x ma1=%03x ma2=%03x ma3=%03x madr=%03x marom=%03x\n",
s.ctime, s.svtime, s.clk, s.iclk,
s.internal_reset,
s.eu_p ? 'p' : '-', s.eu_r ? 'r' : '-', s.eu_w ? 'w' : '-',
s.l_nano1^0xf, ~s.l_nano2 ^ 0x82feffc2, ~s.l_nano3 ^ 0x1ffd7d7e,
s.ma0, s.ma1, s.ma2, s.ma3, s.madr^0x3ff, s.marom
);
printf(" eu=(%04x %04x %04x %04x %04x %04x) alu=%04x%04x au=%04x%04x pc=%04x%04x aob=%04x%04x\n",
s.eu_ah, s.eu_dh, s.eu_al, s.eu_dl, s.eu_ad, s.eu_dd,
s.eu_aluh, s.eu_alul, s.eu_auh, s.eu_aul, s.eu_pch, s.eu_pcl, s.eu_aobh, s.eu_aobl);
}
void show_euconfig(const cstate &s)
{
printf(" -");
if(!s.euc_hd_sense_amp_keep)
printf(" dh=sgn(dl)");
if(!s.euc_ha_sense_amp_keep)
printf(" ah=sgn(al)");
if(s.eu_aluh_ab_in)
printf(" alu=a+d");
else if(s.eu_alul_bit_2p) {
int delta = (s.eu_alul_bit_2p ? 0 : -4)+(s.eu_alul_bit_1 ? 0 : 2)+(s.eu_alul_bit_0 ? 0 : 1)+(s.eu_alul_add1 ? 0 : 1);
if(!delta)
printf(" alu=d");
else if(delta > 0)
printf(" alu=d+%d", delta);
else
printf(" alu=d-%d", delta);
}
if(s.eu_auh_aluh_w)
printf(" au=alu");
if(s.eu_auh_a_w)
printf(" a=au");
if(s.eu_auh_d_w)
printf(" d=au");
if(s.eu_aobh_auh_w)
printf(" aob=au");
if(s.eu_aobh_a_w)
printf(" aob=a");
if(s.eu_aobh_d_w)
printf(" aob=d");
if(s.eu_pch_auh_w)
printf(" pch=auh");
if(s.eu_pch_d_w)
printf(" pch=dh");
if(s.eu_pch_a_w)
printf(" pch=ah");
if(s.eu_hl_a_connect)
printf(" ah=al");
if(s.eu_hl_d_connect)
printf(" dh=al");
if(s.eu_ld_a_connect)
printf(" al=ad");
if(s.eu_ld_d_connect)
printf(" dl=dd");
if(s.trace_srt_w)
printf(" tr=sr.t");
if(s.trace_clear_w)
printf(" tr=0");
if(s.euc_ibuf_rw && s.euc_ibuf_d)
printf(" ibuf=d");
if(s.euc_ibuf_rw && s.euc_ibuf_a)
printf(" ibuf=a");
if(!s.euc_ibuf_rw && s.euc_ibuf_d)
printf(" d=ibuf");
if(!s.euc_ibuf_rw && s.euc_ibuf_a)
printf(" a=ibuf");
if(s.euc_ibuf_to_ib)
printf(" ib=ibuf");
if(s.euc_ib_to_ibuf)
printf(" ibuf=ib");
if(s.ipl_sr_w)
printf(" sr.i=iplb");
if(s.srt_clear_w)
printf(" sr.t=0");
if(s.eu_ib_sr_r)
printf(" ib=sr");
if(s.ib_ib1_w)
printf(" ib=ib1");
if(s.ib1_status_w)
printf(" ib1=status");
printf(" || disp=%x", s.disp);
printf("\n");
// printf(" . tri=%d ab_in=%d 2p=%d 1=%d 0=%d +1=%d\n\n",
// ln(s, 51, 50, 49), s.eu_alul_ab_in, s.eu_alul_bit_2p, s.eu_alul_bit_1, s.eu_alul_bit_0, s.eu_alul_add1);
printf("\n");
}
void step(cstate &s, bool verbose)
{
s.clk = false;
s.iclk = false;
s.eu_r = false;
s.eu_w = false;
s.romarray_clear = false;
update(s);
s.clk = true;
s.iclk = false;
update(s);
if(s.eu_p_gate)
s.eu_p = true;
if(s.romarray_precharge_gate)
s.romarray_precharge = true;
update(s);
if(s.eu_p && s.eu_ld_sense_amp_keep) {
s.eu_ld_sense_amp_keep = false;
update(s);
}
if(verbose)
show_state(s);
if(verbose)
show_euconfig(s);
if(s.eu_p)
s.svtime++;
s.svtime ++;
s.clk = false;
s.iclk = false;
s.eu_p = false;
s.romarray_precharge = false;
update(s);
s.clk = false;
s.iclk = true;
update(s);
if(s.eu_r_gate)
s.eu_r = true;
if(s.eu_w_gate)
s.eu_w = true;
if(s.romarray_clear_gate)
s.romarray_clear = true;
update(s);
if(s.eu_r && !s.eu_ld_sense_amp_keep) {
s.eu_ld_sense_amp_keep = true;
update(s);
}
if(verbose)
show_state(s);
if(verbose)
show_euconfig(s);
if(s.eu_r)
s.svtime++;
s.svtime++;
s.ctime++;
}
int main()
{
cstate s;
init(s);
s.p_reset = false;
s.p_halt = false;
for(int i=0; i<6; i++)
step(s, false);
s.p_reset = true;
s.p_halt = true;
for(int i=0; i<6; i++)
step(s, false);
for(int i=0; i<24; i++)
step(s, true);
return 0;
}