Mercurial > hg > forks > dxa
annotate label.c @ 2:ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 24 Feb 2015 20:28:57 +0200 |
parents | cfcae2ef1c2b |
children | 0990d9322fc8 |
rev | line source |
---|---|
0 | 1 /*\ |
2 * dxa v0.1.1 -- symbolic 65xx disassembler | |
3 * | |
4 * Copyright (C) 1993, 1994 Marko M\"akel\"a | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 * | |
20 * Contacting the author: | |
21 * | |
22 * Via Internet E-mail: | |
23 * <Marko.Makela@FTP.FUNET.FI> | |
24 * | |
25 * Via Snail Mail: | |
26 * Marko M\"akel\"a | |
27 * Sillitie 10 A | |
28 * FIN-01480 VANTAA | |
29 * Finland | |
30 \*/ | |
31 | |
32 #define _LABEL_C_ | |
33 | |
34 #include <stdlib.h> | |
35 #include <stdio.h> | |
36 #include <string.h> | |
37 | |
38 #include "proto.h" | |
39 #include "options.h" | |
40 #include "opcodes.h" | |
41 | |
42 label *labeltable; | |
1 | 43 char defaultlabel[6]; |
0 | 44 unsigned numLabels = 0; |
45 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
46 |
0 | 47 void AddLabel (ADDR_T address, char *name) |
48 { | |
49 label *entry; | |
50 char *buffer; | |
51 | |
1 | 52 if (!((buffer = malloc (strlen (name) + 1)))) |
0 | 53 return; |
54 | |
55 entry = numLabels ? | |
56 realloc (labeltable, (numLabels + 1) * sizeof *entry) : | |
57 malloc (sizeof *entry); | |
58 | |
59 if (!entry) return; | |
60 | |
61 labeltable = entry; | |
62 entry = &labeltable[numLabels++]; | |
63 | |
64 entry->address = address; | |
65 entry->name = buffer; | |
66 while ((*buffer++ = *name++)); | |
67 } | |
68 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
69 |
0 | 70 char *Label (ADDR_T address, int admode) |
71 { | |
72 label *entry; | |
73 | |
74 if (!IsLabeled (address)) { | |
75 | |
76 /* dirty kludge to allow zero page stuff to still work. this sometimes | |
77 guesses wrong */ | |
78 if (admode == zp) | |
79 sprintf (defaultlabel, "$%02x", address); | |
80 else | |
81 sprintf (defaultlabel, "$%04x", address); | |
82 return defaultlabel; | |
83 } | |
84 | |
85 for (entry = &labeltable[numLabels]; entry-- > labeltable;) | |
86 if (entry->address == address) | |
87 return entry->name; | |
88 | |
89 sprintf (defaultlabel, "l%x", address); | |
90 | |
91 return defaultlabel; | |
92 } | |
93 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
94 |
0 | 95 void Collect (void) |
96 { | |
97 unsigned counter = 0; | |
98 table *entry = NULL, *entry2; | |
99 label *labels; | |
100 | |
101 if (fVerbose) | |
102 fprintf (stderr, "%s: collecting garbage.\n", prog); | |
103 | |
104 while ((entry = entry2 = FindNextEntryType (entry, 0, 0))) { | |
105 counter++; | |
106 | |
107 PutLabel (entry->address); | |
108 PutLowByte (entry->address); | |
109 PutHighByte (entry->address); | |
110 | |
111 while ((entry2 = FindNextEntry (entry2, entry->address, | |
112 ~0, entry->type))) | |
113 DeleteEntry (entry2); /* remove duplicate warnings */ | |
114 } | |
115 | |
116 if ((entry = malloc (counter * sizeof *entry))) { /* compact the table */ | |
117 entrycount = counter; | |
118 | |
119 for (entry2 = scantable; counter; entry2++) { | |
120 if (!entry2->type) continue; | |
121 | |
122 memcpy (&entry[--counter], entry2, sizeof *entry); | |
123 } | |
124 | |
125 free (scantable); | |
126 scantable = entry; | |
127 } | |
128 | |
129 for (labels = &labeltable[numLabels]; labels-- > labeltable;) | |
130 if ((ADDR_T)(labels->address - StartAddress) < | |
131 (ADDR_T)(EndAddress - StartAddress)) { | |
132 PutLabel (labels->address); | |
133 PutLowByte (labels->address); | |
134 PutHighByte (labels->address); | |
135 } | |
136 } |