1 /*****************************************************************************/
5 /* 6502 register tracking info */
9 /* (C) 2001-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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 /*****************************************************************************/
44 /*****************************************************************************/
46 /*****************************************************************************/
50 void RC_Invalidate (RegContents* C)
51 /* Invalidate all registers */
53 C->RegA = UNKNOWN_REGVAL;
54 C->RegX = UNKNOWN_REGVAL;
55 C->RegY = UNKNOWN_REGVAL;
56 C->SRegLo = UNKNOWN_REGVAL;
57 C->SRegHi = UNKNOWN_REGVAL;
58 C->Ptr1Lo = UNKNOWN_REGVAL;
59 C->Ptr1Hi = UNKNOWN_REGVAL;
60 C->Tmp1 = UNKNOWN_REGVAL;
65 void RC_InvalidateZP (RegContents* C)
66 /* Invalidate all ZP registers */
68 C->SRegLo = UNKNOWN_REGVAL;
69 C->SRegHi = UNKNOWN_REGVAL;
70 C->Ptr1Lo = UNKNOWN_REGVAL;
71 C->Ptr1Hi = UNKNOWN_REGVAL;
72 C->Tmp1 = UNKNOWN_REGVAL;
77 static void RC_Dump1 (FILE* F, const char* Desc, short Val)
78 /* Dump one register value */
80 if (RegValIsKnown (Val)) {
81 fprintf (F, "%s=$%02X ", Desc, Val);
83 fprintf (F, "%s=$XX ", Desc);
89 void RC_Dump (FILE* F, const RegContents* RC)
90 /* Dump the contents of the given RegContents struct */
92 RC_Dump1 (F, "A", RC->RegA);
93 RC_Dump1 (F, "X", RC->RegX);
94 RC_Dump1 (F, "Y", RC->RegY);
95 RC_Dump1 (F, "SREG", RC->SRegLo);
96 RC_Dump1 (F, "SREG+1", RC->SRegHi);
97 RC_Dump1 (F, "PTR1", RC->Ptr1Lo);
98 RC_Dump1 (F, "PTR1+1", RC->Ptr1Hi);
99 RC_Dump1 (F, "TMP1", RC->Tmp1);
105 RegInfo* NewRegInfo (const RegContents* RC)
106 /* Allocate a new register info, initialize and return it. If RC is not
107 * a NULL pointer, it is used to initialize both, the input and output
108 * registers. If the pointer is NULL, all registers are set to unknown.
111 /* Allocate memory */
112 RegInfo* RI = xmalloc (sizeof (RegInfo));
114 /* Initialize the registers */
120 RC_Invalidate (&RI->In);
121 RC_Invalidate (&RI->Out);
122 RC_Invalidate (&RI->Out2);
125 /* Return the new struct */
131 void FreeRegInfo (RegInfo* RI)
132 /* Free a RegInfo struct */
139 void DumpRegInfo (const char* Desc, const RegInfo* RI)
140 /* Dump the register info for debugging */
142 fprintf (stdout, "%s:\n", Desc);
143 fprintf (stdout, "In: ");
144 RC_Dump (stdout, &RI->In);
145 fprintf (stdout, "Out: ");
146 RC_Dump (stdout, &RI->Out);