1 /*****************************************************************************/
5 /* Opcode handler functions for the disassembler */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
52 /*****************************************************************************/
53 /* Helper functions */
54 /*****************************************************************************/
58 static void Mnemonic (const char* M)
59 /* Indent and output a mnemonic */
67 static void OneLine (const OpcDesc* D, const char* Arg, ...) attribute ((format(printf, 2, 3)));
68 static void OneLine (const OpcDesc* D, const char* Arg, ...)
69 /* Output one line with the given mnemonic and argument */
79 xvsprintf (Buf, sizeof (Buf), Arg, ap);
84 /* Add the code stuff as comment */
85 LineComment (PC, D->Size);
93 static const char* GetAddrArg (const OpcDesc* D, unsigned Addr)
94 /* Return an address argument - a label if we have one, or the address itself */
96 const char* Label = 0;
97 if (D->LabelFlag & lfUseLabel) {
98 Label = GetLabel (Addr);
103 static char Buf [32];
105 xsprintf (Buf, sizeof (Buf), "$%02X", Addr);
107 xsprintf (Buf, sizeof (Buf), "$%04X", Addr);
115 static void GenerateLabel (const OpcDesc* D, unsigned Addr)
116 /* Generate a label in pass one if requested */
118 if (Pass == 1 && !HaveLabel (Addr)) {
119 if ((D->LabelFlag & lfGenLabel) != 0 ||
120 ((D->LabelFlag & lfUseLabel) != 0 && Addr >= CodeStart && Addr <= CodeEnd)) {
121 AddLabel (Addr, atIntLabel, MakeLabelName (Addr));
128 /*****************************************************************************/
130 /*****************************************************************************/
134 void OH_Accumulator (const OpcDesc* D)
141 void OH_Implicit (const OpcDesc* D)
144 LineComment (PC, D->Size);
150 void OH_Immidiate (const OpcDesc* D)
152 OneLine (D, "#$%02X", GetCodeByte (PC+1));
157 void OH_Direct (const OpcDesc* D)
159 /* Get the operand */
160 unsigned Addr = GetCodeByte (PC+1);
162 /* Generate a label in pass 1 */
163 GenerateLabel (D, Addr);
165 /* Output the line */
166 OneLine (D, "%s", GetAddrArg (D, Addr));
171 void OH_DirectX (const OpcDesc* D)
173 /* Get the operand */
174 unsigned Addr = GetCodeByte (PC+1);
176 /* Generate a label in pass 1 */
177 GenerateLabel (D, Addr);
179 /* Output the line */
180 OneLine (D, "%s,y", GetAddrArg (D, Addr));
185 void OH_DirectY (const OpcDesc* D)
187 /* Get the operand */
188 unsigned Addr = GetCodeByte (PC+1);
190 /* Generate a label in pass 1 */
191 GenerateLabel (D, Addr);
193 /* Output the line */
194 OneLine (D, "%s,y", GetAddrArg (D, Addr));
199 void OH_Absolute (const OpcDesc* D)
201 /* Get the operand */
202 unsigned Addr = GetCodeWord (PC+1);
204 /* Generate a label in pass 1 */
205 GenerateLabel (D, Addr);
207 /* Output the line */
208 OneLine (D, "%s", GetAddrArg (D, Addr));
213 void OH_AbsoluteX (const OpcDesc* D)
215 /* Get the operand */
216 unsigned Addr = GetCodeWord (PC+1);
218 /* Generate a label in pass 1 */
219 GenerateLabel (D, Addr);
221 /* Output the line */
222 OneLine (D, "%s,x", GetAddrArg (D, Addr));
227 void OH_AbsoluteY (const OpcDesc* D)
229 /* Get the operand */
230 unsigned Addr = GetCodeWord (PC+1);
232 /* Generate a label in pass 1 */
233 GenerateLabel (D, Addr);
235 /* Output the line */
236 OneLine (D, "%s,y", GetAddrArg (D, Addr));
241 void OH_AbsoluteLong (const OpcDesc* D attribute ((unused)))
243 Error ("Not implemented");
248 void OH_AbsoluteLongX (const OpcDesc* D attribute ((unused)))
250 Error ("Not implemented");
255 void OH_Relative (const OpcDesc* D)
257 /* Get the operand */
258 signed char Offs = GetCodeByte (PC+1);
260 /* Calculate the target address */
261 unsigned Addr = (unsigned) (((int) PC+2) + Offs);
263 /* Generate a label in pass 1 */
264 GenerateLabel (D, Addr);
266 /* Output the line */
267 OneLine (D, "%s", GetAddrArg (D, Addr));
272 void OH_RelativeLong (const OpcDesc* D attribute ((unused)))
274 Error ("Not implemented");
279 void OH_DirectIndirect (const OpcDesc* D)
281 /* Get the operand */
282 unsigned Addr = GetCodeByte (PC+1);
284 /* Generate a label in pass 1 */
285 GenerateLabel (D, Addr);
287 /* Output the line */
288 OneLine (D, "(%s)", GetAddrArg (D, Addr));
293 void OH_DirectIndirectY (const OpcDesc* D)
295 /* Get the operand */
296 unsigned Addr = GetCodeByte (PC+1);
298 /* Generate a label in pass 1 */
299 GenerateLabel (D, Addr);
301 /* Output the line */
302 OneLine (D, "(%s),y", GetAddrArg (D, Addr));
307 void OH_DirectXIndirect (const OpcDesc* D)
309 /* Get the operand */
310 unsigned Addr = GetCodeByte (PC+1);
312 /* Generate a label in pass 1 */
313 GenerateLabel (D, Addr);
315 /* Output the line */
316 OneLine (D, "(%s,x)", GetAddrArg (D, Addr));
321 void OH_AbsoluteIndirect (const OpcDesc* D)
323 /* Get the operand */
324 unsigned Addr = GetCodeWord (PC+1);
326 /* Generate a label in pass 1 */
327 GenerateLabel (D, Addr);
329 /* Output the line */
330 OneLine (D, "(%s)", GetAddrArg (D, Addr));
335 void OH_StackRelative (const OpcDesc* D attribute ((unused)))
337 Error ("Not implemented");
342 void OH_DirectIndirectLongX (const OpcDesc* D attribute ((unused)))
344 Error ("Not implemented");
349 void OH_StackRelativeIndirectY (const OpcDesc* D attribute ((unused)))
351 Error ("Not implemented");
356 void OH_DirectIndirectLong (const OpcDesc* D attribute ((unused)))
358 Error ("Not implemented");
363 void OH_DirectIndirectLongY (const OpcDesc* D attribute ((unused)))
365 Error ("Not implemented");
370 void OH_BlockMove (const OpcDesc* D attribute ((unused)))
372 Error ("Not implemented");
377 void OH_AbsoluteXIndirect (const OpcDesc* D attribute ((unused)))
379 Error ("Not implemented");
384 void OH_Rts (const OpcDesc* D)
392 void OH_JmpAbsolute (const OpcDesc* D)
400 void OH_JmpAbsoluteIndirect (const OpcDesc* D)
402 OH_AbsoluteIndirect (D);