annotate table.c @ 0:4410c9c7750d

Initial import.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 24 Feb 2015 18:53:52 +0200
parents
children ec2f8f6f1dc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*\
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * dxa v0.1.1 -- symbolic 65xx disassembler
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Copyright (C) 1993, 1994 Marko M\"akel\"a
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 * (at your option) any later version.
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 * GNU General Public License for more details.
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 * Contacting the author:
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 * Via Internet E-mail:
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 * <Marko.Makela@FTP.FUNET.FI>
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 * Via Snail Mail:
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 * Marko M\"akel\"a
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 * Sillitie 10 A
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 * FIN-01480 VANTAA
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 * Finland
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 \*/
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 /* table.c */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 #define _TABLE_C_
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #include <stdlib.h>
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 #include "proto.h"
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 static unsigned int firstunused = 0;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 #ifndef __STDC__
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 table *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 FindNextEntryType (entry, andmask, eormask)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 table *entry;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 unsigned char andmask;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 unsigned char eormask;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 #else
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 table *FindNextEntryType (table *entry, unsigned char andmask,
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 unsigned char eormask)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 #endif
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 if (!scantable) return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 if (!entry || entry >= &scantable[entrycount])
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 entry = scantable;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 else if (++entry >= &scantable[entrycount])
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 for (; entry < &scantable[entrycount]; entry++)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 if (entry->type && !((entry->type & andmask) ^ eormask))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 return entry;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 #ifndef __STDC__
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 table *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 FindNextEntryTypeParent (entry, parent, andmask, eormask)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 table *entry;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 ADDR_T parent;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 unsigned char andmask;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 unsigned char eormask;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 #else
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 table *FindNextEntryTypeParent (table *entry, ADDR_T parent,
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 unsigned char andmask, unsigned char eormask)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 #endif
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 if (!scantable) return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 if (!entry || entry >= &scantable[entrycount])
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 entry = scantable;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 else if (++entry >= &scantable[entrycount])
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 for (; entry < &scantable[entrycount]; entry++)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 if (entry->parent == parent && entry->type &&
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 !((entry->type & andmask) ^ eormask))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 return entry;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 #ifndef __STDC__
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 table *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 FindNextEntry (entry, address, andmask, eormask)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 table *entry;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 ADDR_T address;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 unsigned char andmask;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 unsigned char eormask;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 #else
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 table *FindNextEntry (table *entry, ADDR_T address,
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 unsigned char andmask, unsigned char eormask)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 #endif
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 if (!scantable) return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 if (!entry || entry >= &scantable[entrycount])
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 entry = scantable;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 else if (++entry >= &scantable[entrycount])
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 for (; entry < &scantable[entrycount]; entry++)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 if (entry->address == address && entry->type &&
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 !((entry->type & andmask) ^ eormask))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 return entry;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 return NULL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 #ifndef __STDC__
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 void
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 AddEntry (address, parent, type)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 ADDR_T address;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 ADDR_T parent;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 unsigned char type;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 #else
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 void AddEntry (ADDR_T address, ADDR_T parent, unsigned char type)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 #endif
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 if (firstunused < entrycount) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 scantable[firstunused].address = address;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 scantable[firstunused].parent = parent;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 scantable[firstunused].type = type;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 while (++firstunused < entrycount && scantable[firstunused].type);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 else {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 scantable = scantable ?
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 realloc (scantable, (entrycount + 1) * sizeof *scantable) :
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 malloc (sizeof *scantable);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 scantable[entrycount].address = address;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 scantable[entrycount].parent = parent;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 scantable[entrycount].type = type;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 firstunused = ++entrycount;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 #ifndef __STDC__
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 void
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 DeleteEntry (entry)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 table *entry;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 #else
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 void DeleteEntry (table *entry)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 #endif
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 entry -> type = TBL_DELETED;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 if (firstunused > entry - scantable)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 firstunused = entry - scantable;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }