]> git.sur5r.net Git - cc65/blob - src/cc65/coptc02.c
Allow to set character translations at compile time
[cc65] / src / cc65 / coptc02.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 coptc02.h                                 */
4 /*                                                                           */
5 /*                       65C02 specific optimizations                        */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
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 #include <string.h>
37
38 /* cc65 */
39 #include "codeent.h"
40 #include "codeinfo.h"
41 #include "error.h"
42 #include "coptc02.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Data                                    */
48 /*****************************************************************************/
49
50
51
52 /*****************************************************************************/
53 /*                             Helper functions                              */
54 /*****************************************************************************/
55
56
57
58 /*****************************************************************************/
59 /*                                   Code                                    */
60 /*****************************************************************************/
61
62
63
64 unsigned Opt65C02Ind (CodeSeg* S)
65 /* Try to use the indirect addressing mode where possible */
66 {
67     unsigned Changes = 0;
68     unsigned I;
69
70     /* Generate register info for this step */
71     CS_GenRegInfo (S);
72
73     /* Walk over the entries */
74     I = 0;
75     while (I < CS_GetEntryCount (S)) {
76
77         /* Get next entry */
78         CodeEntry* E = CS_GetEntry (S, I);
79
80         /* Check for addressing mode indirect indexed Y where Y is zero. 
81          * Note: All opcodes that are available as (zp),y are also available
82          * as (zp), so we can ignore the actual opcode here.
83          */
84         if (E->AM == AM65_ZP_INDY && E->RI->In.RegY == 0) {
85
86             /* Replace it by indirect addressing mode */
87             CodeEntry* X = NewCodeEntry (E->OPC, AM65_ZP_IND, E->Arg, 0, E->LI);
88             CS_InsertEntry (S, X, I+1);
89             CS_DelEntry (S, I);
90
91             /* We had changes */
92             ++Changes;
93
94         }
95
96         /* Next entry */
97         ++I;
98
99     }
100
101     /* Free register info */
102     CS_FreeRegInfo (S);
103
104     /* Return the number of changes made */
105     return Changes;
106 }
107
108
109
110