annotate sw/sniff-dec/atr.c @ 44:74330513121e

simtrace3-sniff-dec: initial cosmetic fixes
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 08:55:34 +0000
parents 118a12e9483b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement ATR decoding.
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "state.h"
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern char linebuf[];
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int lineno;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern unsigned rx_byte;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int state;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #define MAX_ATR_BYTES 33
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #define SUBST_TS 0
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #define SUBST_T0 1
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #define SUBST_TAn 2
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #define SUBST_TBn 3
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #define SUBST_TCn 4
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #define SUBST_TDn 5
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 #define SUBST_HIST 6
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 #define SUBST_TCK 7
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static char atr_start_timestamp[18];
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 static int atr_start_line;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static int substate;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 static u_char atr_bytes[MAX_ATR_BYTES];
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 static unsigned byte_count;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 static u_char latch_y, latch_k, have_tck;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 void
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 atr_begin()
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 substate = SUBST_TS;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 byte_count = 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 static int
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 advance_state()
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (substate == SUBST_TAn) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (latch_y & 0x10)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 substate = SUBST_TBn;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (substate == SUBST_TBn) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (latch_y & 0x20)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 return 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 substate = SUBST_TCn;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (substate == SUBST_TCn) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (latch_y & 0x40)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 substate = SUBST_TDn;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (substate == SUBST_TDn) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (latch_y & 0x80)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 substate = SUBST_HIST;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (substate == SUBST_HIST) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (latch_k)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 return 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 substate = SUBST_TCK;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (substate == SUBST_TCK) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (have_tck)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return 1;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 fprintf(stderr, "BUG in ATR decoder: bad state in advance_state()\n");
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 abort();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 static void
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 check_tck()
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 unsigned n, xor;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 xor = 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 for (n = 1; n < byte_count; n++)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 xor ^= atr_bytes[n];
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 printf(" TCK is %s\n", xor ? "bad!" : "correct");
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 static void
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 atr_finish()
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 unsigned n;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 printf("%s line %d: ATR\n", atr_start_timestamp, atr_start_line);
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 for (n = 0; n < byte_count; n++)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 printf(" %02X", atr_bytes[n]);
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 putchar('\n');
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 if (have_tck)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 check_tck();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 state = STATE_READY_FOR_CMD;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 void
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 atr_byte_in()
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 atr_bytes[byte_count++] = rx_byte;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 switch (substate) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 case SUBST_TS:
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 substate = SUBST_T0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 case SUBST_T0:
44
74330513121e simtrace3-sniff-dec: initial cosmetic fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
113 strcpy(atr_start_timestamp, linebuf);
74330513121e simtrace3-sniff-dec: initial cosmetic fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
114 atr_start_line = lineno;
41
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 latch_y = rx_byte & 0xF0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 latch_k = rx_byte & 0x0F;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 have_tck = 0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 substate = SUBST_TAn;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if (advance_state()) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 atr_finish();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 case SUBST_TAn:
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 substate = SUBST_TBn;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (advance_state()) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 atr_finish();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 break;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 case SUBST_TBn:
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 substate = SUBST_TCn;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 if (advance_state()) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 atr_finish();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 break;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 case SUBST_TCn:
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 substate = SUBST_TDn;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 if (advance_state()) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 atr_finish();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 break;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 case SUBST_TDn:
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 latch_y = rx_byte & 0xF0;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 if (rx_byte & 0x0F)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 have_tck = 1;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 substate = SUBST_TAn;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 if (advance_state()) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 atr_finish();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 break;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 case SUBST_HIST:
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 latch_k--;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 if (advance_state()) {
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 atr_finish();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 break;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 case SUBST_TCK:
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 atr_finish();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 default:
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 fprintf(stderr,
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 "BUG in ATR decoder: bad state in atr_byte_in()\n");
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 abort();
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 }
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 if (byte_count < MAX_ATR_BYTES)
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 return;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 printf("%s line %d: ERROR: ATR is too long\n", atr_start_timestamp,
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 atr_start_line);
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 state = STATE_ERROR;
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }