annotate main.c @ 15:89183953bddc

Delete trailing whitespace.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 14 Oct 2021 01:40:24 +0300
parents 84c0facfc43c
children a2a81589380d
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 /*\
5
b91c47026822 Make version information a compile-time define.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
2 * dxa -- symbolic 65xx disassembler
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Based on d65 Copyright (C) 1993, 1994 Marko M\"akel\"a
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
5 * Changes for dxa (C) 2005-2019 Cameron Kaiser
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
6 * Modifications for ++ version (c) 2015-2021 Matti 'ccr' Hamalainen <ccr@tnsp.org>
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 * (at your option) any later version.
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 * GNU General Public License for more details.
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 * Marko does not maintain dxa, so questions specific to dxa should be
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
23 * sent to me at ckaiser@floodgap.com.
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 *
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 \*/
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #define _MAIN_C_
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #include <stdio.h>
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #include <stdlib.h>
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 #include <string.h>
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #ifdef __GNUC__
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #include <unistd.h>
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 #endif
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #ifdef LONG_OPTIONS
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #include <getopt.h>
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 #endif /* __GNUC__ */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 #include "proto.h"
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 #include "options.h"
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 #include "opcodes.h"
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
2
ec2f8f6f1dc9 Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
41
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 int main (int argc, char **argv)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 FILE *file;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 unsigned address1, address2;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 #ifdef LONG_OPTIONS
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 int option_index;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 #endif
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 int fFinished = FALSE, fType;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 char labelname[MAXLINE], strig[MAXLINE], *scanner;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 extern char *optarg;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 extern int optind;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 #ifdef LONG_OPTIONS
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 static struct option cmd_options [] = {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 { "datablock", 1, 0, 'b' }, /* an address range to be marked
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 as a data block */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 { "datablocks", 1, 0, 'B' },/* a file containing the address ranges
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 to be marked as data blocks */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 { "labels", 1, 0, 'l' }, /* a file containing labels to be translated
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 in the output phase */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 { "routine", 1, 0, 'r' }, /* an address of a routine */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 { "routines", 1, 0, 'R' }, /* a file containing the addresses */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 { "listing-width", 1, 0, 'L' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 /* maximum number of dumped bytes per line */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 { "addresses", 1, 0, 'a' }, /* dumping addresses in the output phase */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 { "datablock-detection", 1, 0, 'd' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 /* data block detection options */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 { "processor", 1, 0, 'p' }, /* instruction set */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 { "no-colon-newline", 0, 0, 'n' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 { "colon-newline", 0, 0, 'N' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 { "no-external-labels", 0, 0, 'e' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 { "external-labels", 0, 0, 'E' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 { "address-tables", 0, 0, 't' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 { "no-address-statements", 0, 0, 's' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 { "address-statements", 0, 0, 'S' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 { "suspect-jsr", 0, 0, 'J' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 { "no-suspect-jsr", 0, 0, 'j' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 { "one-byte-routines", 0, 0, 'O' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 { "no-one-byte-routines", 0, 0, 'o' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 { "stupid-jumps", 0, 0, 'M' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 { "no-stupid-jumps", 0, 0, 'm' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 { "allow-brk", 0, 0, 'W' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 { "no-allow-brk", 0, 0, 'w' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 { "suspect-branches", 0, 0, 'C' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 { "no-suspect-branches", 0, 0, 'c' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 { "cross-reference", 0, 0, 'X' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 { "no-cross-reference", 0, 0, 'x' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 { "verbose", 0, 0, 'v' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 { "help", 0, 0, '?' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 { "word-sa", 0, 0, 'Q' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 { "no-word-sa", 0, 0, 'q' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 { "get-sa", 0, 0, 'G' },
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 { "no-get-sa", 0, 0, 'g' },
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
97 { "detect-basic", 0, 0, 'U' },
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
98 { "no-detect-basic", 0, 0, 'u' },
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 { NULL, 0, 0, 0 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 };
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 #endif /* LONG_OPTIONS */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 opset = standard_nmos6502;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 StartAddress = 0;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 Options = O_ADR_ADR_DMP | B_LBL_ALWAYS | O_TBL_NOEXT |
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 B_STM_DETECT | B_STK_BALANCE | B_RSC_STRICT | O_DBL_STRICT |
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 B_JMP_STRICT | B_BRK_REJECT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 /* dxa defaults */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 Options = (Options & ~M_ADDRESSES) | O_ADR_NOTHING;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 Options = (Options & ~M_DATA_BLOCKS) | O_DBL_IGNORE;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 Options &= ~B_LBL_ALWAYS;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 Options &= ~B_LABCOL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 Options |= B_SA_WORD;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 Options |= B_GET_SA;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 for (address1 = sizeof MemType / sizeof *MemType; address1--;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 MemType[address1] = 0);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 for (address1 = sizeof MemFlag / sizeof *MemFlag; address1--;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 MemFlag[address1] = MemLabel[address1] = 0);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 for (address1 = sizeof LowByte / sizeof *LowByte; address1--;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 HighByte[address1] = LowByte[address1] = 0);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
11
fe4d840c13eb Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
127 for (address1 = sizeof MemReferenced / sizeof *MemReferenced; address1--;
fe4d840c13eb Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
128 MemReferenced[address1] = 0);
fe4d840c13eb Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
129
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 for (prog = *argv; *prog; prog++);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 for (;prog > *argv; prog--)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 if (*prog == '/') {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 prog++;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 while (!fFinished)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 #ifdef LONG_OPTIONS
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 switch (getopt_long (argc, argv,
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
140 "?b:B:L:r:R:h:l:a:d:p:g:t:eEnNsSjJoOcCmMvVwWxXqQGuU",
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 cmd_options, &option_index)) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 #else
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 switch (getopt (argc, argv,
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
144 "?b:B:L:r:R:h:l:a:d:p:g:t:eEnNsSjJoOcCmMvVwWxXqQGuU")){
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 #endif /* LONG_OPTIONS */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 case -1:
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 case ':':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 fFinished = TRUE;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 case '?':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 case 'V':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 case 'b':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 if (*optarg == '!') {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 fType = MEM_PARAMETER;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 optarg++;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 else if (*optarg == '?') {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 fType = MEM_UNPROCESSED;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 optarg++;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 else
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 fType = MEM_DATA;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 if (!sscanf (optarg, "%X-%X", &address1, &address2) ||
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 address1 > 65535 || address2 > 65535) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 fprintf (stderr, "%s: Error in data block address range `%s'.\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 for (; (ADDR_T)address1 != address2; address1++) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 SetMemType (address1, fType);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 SetMemFlag (address1);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 SetMemType (address1, fType);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 SetMemFlag (address1);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 case 'B':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 if (!((file = fopen (optarg, "rt")))) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 fprintf (stderr, "%s: Could not open %s.\n", prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 return 2;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 while (!feof (file)) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 if ('!' == (fType = fgetc (file)))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 fType = MEM_PARAMETER;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 else if ('?' == fType)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 fType = MEM_UNPROCESSED;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 else {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 ungetc (fType, file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 fType = MEM_DATA;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 if (!fscanf (file, "%X-%X\n", &address1, &address2) ||
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 address1 > 65535 || address2 > 65535) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 fprintf (stderr, "%s: Error in data block address file %s.\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 fclose (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 return 3;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 for (; (ADDR_T)address1 != address2; address1++) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 SetMemType (address1, fType);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 SetMemFlag (address1);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 SetMemType (address1, fType);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 SetMemFlag (address1);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 fclose (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 case 'r':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 if (!sscanf (optarg, "%X", &address1) || address1 > 65535) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 fprintf (stderr, "%s: Error in routine address `%s'.\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 AddEntry (address1, address1, RTN_SURE);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 case 'R':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 if (!((file = fopen (optarg, "rt")))) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 fprintf (stderr, "%s: Could not open %s.\n", prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 return 2;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 while (!feof (file)) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 if (!fscanf (file, "%X\n", &address1) || address1 > 65535) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 fprintf (stderr, "%s: Error in data block address file `%s'.\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 fclose (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 return 3;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 AddEntry (address1, address1, RTN_SURE);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 fclose (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 case 'L':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 if (0 > (listwidth = atoi (optarg))) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 fprintf (stderr, "%s: Illegal listing width specified.\n\n", prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 case 'a':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 if (!strcmp (optarg, "disabled"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 Options = (Options & ~M_ADDRESSES) | O_ADR_NOTHING;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 else if (!strcmp (optarg, "enabled"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 Options = (Options & ~M_ADDRESSES) | O_ADR_ADRPFIX;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 else if (!strcmp (optarg, "dump"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 Options = (Options & ~M_ADDRESSES) | O_ADR_ADR_DMP;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 else {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 fprintf (stderr, "%s: Unrecognized option for dumping addresses.\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 case 'd':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 if (!strcmp (optarg, "poor"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 Options = (Options & ~M_DATA_BLOCKS) | O_DBL_IGNORE;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 else if (!strcmp (optarg, "extended"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 Options = (Options & ~M_DATA_BLOCKS) | O_DBL_DETECT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 else if (!strcmp (optarg, "skip-scanning"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 Options = (Options & ~M_DATA_BLOCKS) | O_DBL_NOSCAN;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 else if (!strcmp (optarg, "strict"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 Options = (Options & ~M_DATA_BLOCKS) | O_DBL_STRICT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 else {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 fprintf (stderr,
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 "%s: Unrecognized option for detecting data blocks.\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 case 'p':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 if (!strcmp (optarg, "all-nmos6502"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 opset = all_nmos6502;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 else if (!strcmp (optarg, "rational-nmos6502"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 opset = rational_nmos6502;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 else if (!strcmp (optarg, "useful-nmos6502"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 opset = useful_nmos6502;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 else if (!strcmp (optarg, "traditional-nmos6502"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 opset = traditional_nmos6502;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 else if (!strcmp (optarg, "r65c02"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 opset = r65c02;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 else if (!strcmp (optarg, "standard-nmos6502"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 opset = standard_nmos6502;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 else {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 fprintf (stderr, "%s: Unsupported instruction set `%s'.\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 case 'e':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 Options &= ~B_LBL_ALWAYS;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 case 'E':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 Options |= B_LBL_ALWAYS;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 case 't':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 if (!strcmp (optarg, "ignore"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 Options = (Options & ~M_ADR_TABLES) | O_TBL_IGNORE;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 else if (!strcmp (optarg, "detect-all"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 Options = (Options & ~M_ADR_TABLES) | O_TBL_DETECT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 else if (!strcmp (optarg, "detect-internal"))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 Options = (Options & ~M_ADR_TABLES) | O_TBL_NOEXT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 else {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 fprintf (stderr,
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 "%s: Unknown address table detection option `%s'.\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 case 's':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 Options &= ~B_STM_DETECT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 case 'S':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 Options |= B_STM_DETECT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 case 'J':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 Options &= ~B_STK_BALANCE;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 case 'j':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 Options |= B_STK_BALANCE;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 case 'o':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 Options &= ~B_RSC_STRICT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 case 'O':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 Options |= B_RSC_STRICT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 case 'c':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 Options &= ~B_SCEPTIC;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 case 'C':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 Options |= B_SCEPTIC;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 case 'M':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 Options &= ~B_JMP_STRICT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 case 'm':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 Options |= B_JMP_STRICT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 case 'v':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 fVerbose = TRUE;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 case 'W':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 Options &= ~B_BRK_REJECT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 case 'w':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 Options |= B_BRK_REJECT;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 case 'x':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 Options &= ~B_CROSSREF;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 case 'X':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 Options |= B_CROSSREF;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 /* new or altered dxa options */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 case 'n':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 Options &= ~B_LABCOL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 case 'N':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 Options |= B_LABCOL;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 case 'q':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 Options &= ~B_SA_WORD;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 case 'Q':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 Options |= B_SA_WORD;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 break;
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
399 case 'u':
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
400 Options &= ~B_DETECT_BASIC;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
401 break;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
402 case 'U':
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
403 Options |= B_DETECT_BASIC;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
404 break;
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 case 'G':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 Options |= B_GET_SA;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 case 'g':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 Options &= ~B_GET_SA;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 if (!sscanf (optarg, "%X", &address1) || address1 > 65535) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 fprintf (stderr, "%s: Error specifying starting address `%s'.\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 StartAddress = address1;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 case 'l':
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 if (!((file = fopen (optarg, "rt")))) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 fprintf (stderr,
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 "%s: Label file %s could not be opened for reading.\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 goto Usage;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 while (!feof (file)) {
4
0990d9322fc8 Implement address-ranged labels. Breaks compatibility of label files.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
427 int tmp;
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 fType = fgetc (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 if (feof (file))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 break;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 ungetc (fType, file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 /* This is the xa-compatible label scanner. */
4
0990d9322fc8 Implement address-ranged labels. Breaks compatibility of label files.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
436 if (!fscanf(file, "%s%i,%i,%i", labelname, &address1, &tmp, &address2) ||
0990d9322fc8 Implement address-ranged labels. Breaks compatibility of label files.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
437 address1 > 65535 ||
0990d9322fc8 Implement address-ranged labels. Breaks compatibility of label files.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
438 !fgets(strig, sizeof strig, file)) {
0990d9322fc8 Implement address-ranged labels. Breaks compatibility of label files.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
439
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 LabelError:
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 fprintf (stderr, "%s: Error in label file %s.\n", prog, optarg);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 fprintf (stderr, "Address(?): 0x%x ... Label(?): \"%s\"\n\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 address1, labelname);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 fclose (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 return 3;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 for (scanner = labelname; *scanner; scanner++);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 #if(0)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 if (scanner[-1] != '\n') goto LabelError; /* line too long */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 #endif
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 while (--scanner > labelname && (
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 *(unsigned char *)scanner < 32 ||
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 *(unsigned char *)scanner == 44)) /* and commas */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 *scanner = 0; /* remove trailing control characters */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 for (scanner = labelname; *(unsigned char *)scanner < 32; scanner++)
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 if (!*scanner) goto LabelError; /* label name missing */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461
4
0990d9322fc8 Implement address-ranged labels. Breaks compatibility of label files.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
462 AddLabel (address1, scanner, address2 != 0, address2);
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 fclose (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 if (argc - optind > 1) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 Usage:
5
b91c47026822 Make version information a compile-time define.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
470 fprintf (stderr, "dxa %s -- symbolic 65xx disassembler\n", DXA_VERSION);
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 fprintf (stderr, "Based on d65 copyright (C) 1993-4 Marko M\"akel\"a\n");
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
472 fprintf (stderr, "Changes for dxa copyright (c) 2006-19 Cameron Kaiser\n\n");
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
473 fprintf (stderr, "Modifications for ++ version (c) 2015-2021 Matti 'ccr' Hamalainen <ccr@tnsp.org>\n\n");
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 fprintf (stderr, "Usage: %s [options] [filename]\n", prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 return 1;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 /* Fix, Need "rb" (binary mode) on Windows to avoid termintating on $1A */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 if (!(file = (argc - optind) ? fopen (argv[argc - 1], "rb") : stdin)) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 fprintf (stderr, "%s: Couldn't open input file.\n", prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 return 2;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 if (Options & B_GET_SA) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 StartAddress = (unsigned)fgetc (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 StartAddress |= (unsigned)fgetc (file) << 8;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 if (feof (file)) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 fprintf (stderr, "%s: Error reading the file.\n", prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 return 3;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 /* this doesn't work so well */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 /* AddEntry (StartAddress, StartAddress, RTN_SURE); */
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 EndAddress = StartAddress + fread (&Memory[StartAddress], sizeof (char),
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 65536 - StartAddress, file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 if (!feof (file)) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 if ((EndAddress = fread (Memory, sizeof (char), StartAddress, file)))
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 fprintf (stderr, "%s: Warning: Input file caused an address overflow.\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 if (!feof (file)) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 fprintf (stderr, "%s: Error: Input file is longer than 64 kilobytes.\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 fclose (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 return 3;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 fclose (file);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
514 BasicHeaderLength = 0;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
515 if ((Options & B_DETECT_BASIC) && ((EndAddress - StartAddress) > 11) && (0 ||
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
516 StartAddress == 0x0401 || /* PET */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
517 StartAddress == 0x0801 || /* C64 */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
518 StartAddress == 0x1001 || /* VIC, 16, +4 */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
519 StartAddress == 0x1c01 || /* 128 */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
520 0)) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
521 /* If this file starts at a typical BASIC starting address, try to mark
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
522 that as data. Bonus points for turning SYS xxxx into an entry point.
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
523 For example, 1010 SYS 2061 comes out like this:
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
524 .byt $0b,$08,$0a
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
525 .byt $0a,$9e,$32
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
526 .byt $30,$36,$31
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
527 .byt $00,$00,$00
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
528 */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
529
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
530 /* Heuristic: try to validate the line link address. If it seems sane,
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
531 process further. */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
532 ADDR_T ll = Memory[StartAddress] + (Memory[StartAddress+1] << 8);
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
533 if ((ll > StartAddress) && (ll < EndAddress - 2) && Memory[ll] == 0) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
534 ADDR_T offs = StartAddress + 5; /* byte after presumed first token */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
535 ADDR_T val = 0;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
536 ADDR_T i = 0;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
537 int ok = 0;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
538
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
539 /* See if there is an encoded SYS address in the first line. */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
540 if (Memory[StartAddress+4] == 0x9e /* SYS */) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
541 for(; offs < StartAddress + 11; offs++) { /* stop overrun */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
542 if (Memory[offs] == 0x00) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
543 ok = 1;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
544 break;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
545 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
546 if (Memory[offs] == 32) /* space */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
547 continue;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
548 if (Memory[offs] < 48 || Memory[offs] > 57) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
549 ok = 0;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
550 break;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
551 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
552 if (val > 6553 || (val == 6553 && Memory[offs] > 53)) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
553 ok = 0; /* imminent overflow */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
554 break;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
555 }
15
89183953bddc Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
556 val = (val * 10) + (Memory[offs] - 48);
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
557 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
558
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
559 if (ok && val > StartAddress && val < EndAddress) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
560 /* Address validates; mark it as an entry point. */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
561 AddEntry (val, val, RTN_SURE);
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
562 if (fVerbose)
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
563 fprintf(stderr, "%s: SYS %d found, marking as entry point\n", prog, val);
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
564 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
565 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
566
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
567 /* Try to find the end of BASIC text. Three nulls needed. */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
568 ok = 0;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
569 for(; offs < EndAddress; offs++) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
570 if (Memory[offs] == 0) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
571 ok++;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
572 if (ok == 3) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
573 BasicHeaderLength = (offs - StartAddress) + 1;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
574
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
575 /* Mark entire length of BASIC text as dead. */
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
576 for(i = StartAddress; i < offs; i++) {
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
577 SetMemType(i, MEM_UNPROCESSED);
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
578 SetMemFlag(i);
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
579 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
580 if (fVerbose)
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
581 fprintf(stderr, "%s: BASIC text marked as dead through $%04x\n", prog, offs);
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
582 break;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
583 } else
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
584 continue;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
585 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
586 ok = 0;
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
587 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
588 if (ok < 3 && fVerbose)
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
589 fprintf(stderr, "%s: warning: couldn't find a valid end of BASIC text\n", prog);
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
590
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
591 } else if (fVerbose)
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
592 fprintf(stderr, "%s: warning: BASIC starting address $%04x, but invalid line\n",
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
593 prog, StartAddress);
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
594
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
595 }
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
596
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 if (fVerbose)
14
84c0facfc43c Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
598 fprintf (stderr, "%s: disassembling $%04x-$%04x\n", prog,
0
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 StartAddress, EndAddress);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 if (ScanSpecified ()) {
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602 fprintf (stderr, "\n%s: Invalid routine address(es) specified. Stop.\n",
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
603 prog);
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 return 4;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 }
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608 ScanPotentials ();
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 ScanTheRest ();
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 Collect ();
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 SearchVectors ();
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 Dump ();
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 return 0;
4410c9c7750d Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 }