-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagc_disassembler.c
287 lines (270 loc) · 8.51 KB
/
agc_disassembler.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
Copyright 2003-2006 Ronald S. Burkey <[email protected]>,
2008 Onno Hommes
This file is part of yaAGC.
yaAGC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
yaAGC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with yaAGC; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
In addition, as a special exception, permission is given to
link the code of this program with the Orbiter SDK library (or with
modified versions of the Orbiter SDK library that use the same license as
the Orbiter SDK library), and distribute linked combinations including
the two. You must obey the GNU General Public License in all respects for
all of the code used other than the Orbiter SDK library. If you modify
this file, you may extend this exception to your version of the file,
but you are not obligated to do so. If you do not wish to do so, delete
this exception statement from your version.
Filename: agc_disassembler.h
Purpose: Source file for AGC Disassembler.
Contact: Onno Hommes
Reference: http://www.ibiblio.org/apollo
Mods: 08/31/08 OH. Began.
*/
#include <stdio.h>
#include "agc_engine.h"
#include "agc_symtab.h"
#include "agc_disassembler.h"
#include "agc_debugger.h"
/*
* Displays the current address and its contents.
*/
static int sCurrentZ, sBank, sValue, sErasable, sFixed;
static char ShowAddressBuffer[17];
static char* ShowAddressContents (agc_t *State)
{
sErasable = sFixed = 0;
sCurrentZ = (State->Erasable[0][RegZ] & 07777);
// Print the address.
if (sCurrentZ < 01400)
{
sErasable = 1;
sprintf (ShowAddressBuffer, " %05o ", sCurrentZ);
sBank = sCurrentZ / 0400;
sValue = State->Erasable[sBank][sCurrentZ & 0377];
}
else if (sCurrentZ >= 04000)
{
sFixed = 1;
sprintf (ShowAddressBuffer, " %05o ", sCurrentZ);
sBank = 2 + (sCurrentZ - 04000) / 02000;
sValue = State->Fixed[sBank][sCurrentZ & 01777];
}
else if (sCurrentZ < 02000)
{
sErasable = 1;
sBank = 7 & State->Erasable[0][RegBB];
sprintf (ShowAddressBuffer, "E%o,%05o ", sBank, 01400 + (sCurrentZ & 0377));
sValue = State->Erasable[sBank][sCurrentZ & 0377];
}
else
{
sFixed = 1;
sBank = 037 & (State->Erasable[0][RegBB] >> 10);
if (sBank >= 030 && State->OutputChannel7 & 0100)
sBank += 010;
sprintf (ShowAddressBuffer, "%02o,%05o ", sBank, 02000 + (sCurrentZ & 01777));
sValue = State->Fixed[sBank][sCurrentZ & 01777];
}
sValue &= 077777;
// Print the octal value stored at the address.
sprintf (&ShowAddressBuffer[9], "%05o ", sValue);
return (ShowAddressBuffer);
}
void DasPrintInstruction(int ExtraCode,int sValue)
{
/* Disassemble the instruction at the address. */
if (ExtraCode == 0)
{
if (sValue == 040000) printf ("COM\n");
else if (sValue == 020001) printf ("DDOUBL\n");
else if (sValue == 060000) printf ("DOUBLE\n");
else if (sValue == 052006) printf ("DTCB\n");
else if (sValue == 052005) printf ("DTCF\n");
else if (sValue == 6) printf ("EXTEND\n");
else if (sValue == 4) printf ("INHINT\n");
else if (sFixed && sValue == sCurrentZ + 1 &&
sValue != 10000) printf ("NOOP\n");
else if (sErasable && sValue == 030000) printf ("NOOP\n");
else if (sValue == 054000) printf ("OVSK\n");
else if (sValue == 3)printf ("RELINT\n");
else if (sValue == 050017) printf ("RESUME\n");
else if (sValue == 2) printf ("RETURN\n");
else if (sValue == 054005) printf ("TCAA\n");
else if (sValue == 1) printf ("XLQ\n");
else if (sValue == 0) printf ("XXALQ\n");
else if (sValue == 022007) printf ("ZL\n");
else switch (sValue & 0x7000)
{
case 0x0000:
printf ("TC\t%04o\n", sValue & 0xFFF);
break;
case 0x1000:
if (0 == (sValue & 0x0C00)) printf ("CCS\t%04o\n",sValue&0x3FF);
else printf ("TCF\t%04o\n", sValue & 0xFFF);
break;
case 0x2000:
switch (sValue & 0x0C00)
{
case 0x000:
printf ("DAS\t%04o\n", (sValue - 1) & 0x3FF);
break;
case 0x400:
printf ("LXCH\t%04o\n", sValue & 0x3FF);
break;
case 0x800:
printf ("INCR\t%04o\n", sValue & 0x3FF);
break;
case 0xC00:
printf ("ADS\t%04o\n", sValue & 0x3FF);
break;
}
break;
case 0x3000:
printf ("CA\t%04o\n", sValue & 0xFFF);
break;
case 0x4000:
printf ("CS\t%04o\n", sValue & 0xFFF);
break;
case 0x5000:
switch (sValue & 0x0C00)
{
case 0x000:
printf ("INDEX\t%04o\n", sValue & 0x3FF);
break;
case 0x400:
printf ("DXCH\t%04o\n", (sValue - 1) & 0x3FF);
break;
case 0x800:
printf ("TS\t%04o\n", sValue & 0x3FF);
break;
case 0xC00:
printf ("XCH\t%04o\n", sValue & 0x3FF);
break;
}
break;
case 0x6000:
printf ("AD\t%04o\n", sValue & 0xFFF);
break;
case 0x7000:
printf ("MASK\t%04o\n", sValue & 0xFFF);
break;
}
}
else
{
if (sValue == 040001) printf ("DCOM\n");
else if (sValue == 050017) printf ("RESUME\n");
else if (sValue == 070000) printf ("SQUARE\n");
else if (sValue == 022007) printf ("ZQ\n");
else switch (sValue & 0x7000)
{
case 0x0000:
switch (sValue & 0x0E00)
{
case 0x0000:
printf ("READ\t%03o\n", sValue & 0777);
break;
case 0x0200:
printf ("WRITE\t%03o\n", sValue & 0777);
break;
case 0x0400:
printf ("RAND\t%03o\n", sValue & 0777);
break;
case 0x0600:
printf ("WAND\t%03o\n", sValue & 0777);
break;
case 0x0800:
printf ("ROR\t%03o\n", sValue & 0777);
break;
case 0x0A00:
printf ("WOR\t%03o\n", sValue & 0777);
break;
case 0x0C00:
printf ("RXOR\t%03o\n", sValue & 0777);
break;
case 0x0E00:
printf ("EDRUPT\t%03o\n", sValue & 0777);
break;
}
break;
case 0x1000:
if (0 == (sValue & 0x0C00)) printf ("DV\t%04o\n", sValue & 0x3FF);
else printf ("BZF\t%04o\n", sValue & 0xFFF);
break;
case 0x2000:
switch (sValue & 0x0C00)
{
case 0x000:
printf ("MSU\t%04o\n", sValue & 0x3FF);
break;
case 0x400:
printf ("QXCH\t%04o\n", sValue & 0x3FF);
break;
case 0x800:
printf ("AUG\t%04o\n", sValue & 0x3FF);
break;
case 0xC00:
printf ("DIM\t%04o\n", sValue & 0x3FF);
break;
}
break;
case 0x3000:
printf ("DCA\t%04o\n", (sValue - 1) & 0xFFF);
break;
case 0x4000:
printf ("DCS\t%04o\n", (sValue - 1) & 0xFFF);
break;
case 0x5000:
printf ("INDEX\t%04o\n", sValue & 0xFFF);
break;
case 0x6000:
if (0 == (sValue & 0x0C00))
printf ("SU\t%04o\n", sValue & 0x3FF);
else
printf ("BZMF\t%04o\n", sValue & 0xFFF);
break;
case 0x7000:
printf ("MP\t%04o\n", sValue & 0xFFF);
break;
}
}
}
/*
* Displays a disassembly of the current address.
*/
void Disassemble (agc_t * State)
{
/* The following also sets all of the global variables like sValue, etc. */
printf ("%s", ShowAddressContents (State));
/* Account for the index value. */
if (State->SubstituteInstruction)
{
sValue = (State->Erasable[0][RegBB] & 077777);
printf ("sub\t");
}
else if (State->IndexValue != 0)
{
/* The following calculation doesn't overflow-correct the instruction,
whereas the agc_engine DOES overflow-correct. */
if (0 == (040000 & State->IndexValue)) sValue += (State->IndexValue & 077777);
else sValue -= (~State->IndexValue & 077777);
printf ("w/i:\t");
}
DasPrintInstruction(State->ExtraCode,sValue);
}
void DasPrintInstructionAtAddr(unsigned short LinearAddress)
{
int Value;
int ExtraCode = 0;
Value = DbgGetValueByAddress(LinearAddress);
if ((DbgGetValueByAddress(LinearAddress-1)) == 6) ExtraCode = 1;
DasPrintInstruction(ExtraCode,Value);
}