1/*****************************************************************************/
2/* */
3/* reginfo.c */
4/* */
5/* 6502 register tracking info */
6/* */
7/* */
8/* */
9/* (C) 2001-2003 Ullrich von Bassewitz */
10/* Roemerstrasse 52 */
11/* D-70794 Filderstadt */
12/* EMail: uz@cc65.org */
13/* */
14/* */
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. */
18/* */
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: */
22/* */
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 */
30/* distribution. */
31/* */
32/*****************************************************************************/
33
34
35
36/* common */
37#include "xmalloc.h"
38
39/* cc65 */
40#include "reginfo.h"
41
42
43
44/*****************************************************************************/
45/* Code */
46/*****************************************************************************/
47
48
49
50void RC_Invalidate (RegContents* C)
51/* Invalidate all registers */
52{
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;
61}
62
63
64
65void RC_InvalidateZP (RegContents* C)
66/* Invalidate all ZP registers */
67{
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;
73}
74
75
76
77static void RC_Dump1 (FILE* F, const char* Desc, short Val)
78/* Dump one register value */
79{
80 if (RegValIsKnown (Val)) {
81 fprintf (F, "%s=$%02X ", Desc, Val);
82 } else {
83 fprintf (F, "%s=$XX ", Desc);
84 }
85}
86
87
88
89void RC_Dump (FILE* F, const RegContents* RC)
90/* Dump the contents of the given RegContents struct */
91{
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);
100 fprintf (F, "\n");
101}
102
103
104
105RegInfo* 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.
109*/
110{
111 /* Allocate memory */
112 RegInfo* RI = xmalloc (sizeof (RegInfo));
113
114 /* Initialize the registers */
115 if (RC) {
116 RI->In = *RC;
117 RI->Out = *RC;
118 RI->Out2 = *RC;
119 } else {
120 RC_Invalidate (&RI->In);
121 RC_Invalidate (&RI->Out);
122 RC_Invalidate (&RI->Out2);
123 }
124
125 /* Return the new struct */
126 return RI;
127}
128
129
130
131void FreeRegInfo (RegInfo* RI)
132/* Free a RegInfo struct */
133{
134 xfree (RI);
135}
136
137
138
139void DumpRegInfo (const char* Desc, const RegInfo* RI)
140/* Dump the register info for debugging */
141{
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);
147}
148