comparison table.c @ 0:4410c9c7750d

Initial import.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 24 Feb 2015 18:53:52 +0200
parents
children ec2f8f6f1dc9
comparison
equal deleted inserted replaced
-1:000000000000 0:4410c9c7750d
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 /* table.c */
33 #define _TABLE_C_
34
35 #include <stdlib.h>
36 #include "proto.h"
37
38 static unsigned int firstunused = 0;
39
40 #ifndef __STDC__
41 table *
42 FindNextEntryType (entry, andmask, eormask)
43 table *entry;
44 unsigned char andmask;
45 unsigned char eormask;
46 #else
47 table *FindNextEntryType (table *entry, unsigned char andmask,
48 unsigned char eormask)
49 #endif
50 {
51 if (!scantable) return NULL;
52
53 if (!entry || entry >= &scantable[entrycount])
54 entry = scantable;
55 else if (++entry >= &scantable[entrycount])
56 return NULL;
57
58 for (; entry < &scantable[entrycount]; entry++)
59 if (entry->type && !((entry->type & andmask) ^ eormask))
60 return entry;
61
62 return NULL;
63 }
64
65 #ifndef __STDC__
66 table *
67 FindNextEntryTypeParent (entry, parent, andmask, eormask)
68 table *entry;
69 ADDR_T parent;
70 unsigned char andmask;
71 unsigned char eormask;
72 #else
73 table *FindNextEntryTypeParent (table *entry, ADDR_T parent,
74 unsigned char andmask, unsigned char eormask)
75 #endif
76 {
77 if (!scantable) return NULL;
78
79
80 if (!entry || entry >= &scantable[entrycount])
81 entry = scantable;
82 else if (++entry >= &scantable[entrycount])
83 return NULL;
84
85 for (; entry < &scantable[entrycount]; entry++)
86 if (entry->parent == parent && entry->type &&
87 !((entry->type & andmask) ^ eormask))
88 return entry;
89
90 return NULL;
91 }
92
93 #ifndef __STDC__
94 table *
95 FindNextEntry (entry, address, andmask, eormask)
96 table *entry;
97 ADDR_T address;
98 unsigned char andmask;
99 unsigned char eormask;
100 #else
101 table *FindNextEntry (table *entry, ADDR_T address,
102 unsigned char andmask, unsigned char eormask)
103 #endif
104 {
105 if (!scantable) return NULL;
106
107 if (!entry || entry >= &scantable[entrycount])
108 entry = scantable;
109 else if (++entry >= &scantable[entrycount])
110 return NULL;
111
112 for (; entry < &scantable[entrycount]; entry++)
113 if (entry->address == address && entry->type &&
114 !((entry->type & andmask) ^ eormask))
115 return entry;
116
117 return NULL;
118 }
119
120 #ifndef __STDC__
121 void
122 AddEntry (address, parent, type)
123 ADDR_T address;
124 ADDR_T parent;
125 unsigned char type;
126 #else
127 void AddEntry (ADDR_T address, ADDR_T parent, unsigned char type)
128 #endif
129 {
130 if (firstunused < entrycount) {
131 scantable[firstunused].address = address;
132 scantable[firstunused].parent = parent;
133 scantable[firstunused].type = type;
134
135 while (++firstunused < entrycount && scantable[firstunused].type);
136 }
137 else {
138 scantable = scantable ?
139 realloc (scantable, (entrycount + 1) * sizeof *scantable) :
140 malloc (sizeof *scantable);
141
142 scantable[entrycount].address = address;
143 scantable[entrycount].parent = parent;
144 scantable[entrycount].type = type;
145
146 firstunused = ++entrycount;
147 }
148 }
149
150 #ifndef __STDC__
151 void
152 DeleteEntry (entry)
153 table *entry;
154 #else
155 void DeleteEntry (table *entry)
156 #endif
157 {
158 entry -> type = TBL_DELETED;
159
160 if (firstunused > entry - scantable)
161 firstunused = entry - scantable;
162 }