dbgif_ttycomm.c
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
#ifdef __sgi__
#include <bstring.h>
#endif
#include <string.h>
#include <unistd.h>
#include "dbgif.h"
#include "rkfsn.h"
#include "dbgproto.h"
static enum {
READ_ASCII,
READ_BLOCK,
READ_BLOCK_LEN,
READ_CSI,
READ_DSR
} ttyReadMode = READ_ASCII;
unsigned char ttyBuf[4096];
unsigned char* ttyBufp = &ttyBuf[0];
unsigned char* ttyBufEnd = &ttyBuf[4096];
unsigned int cellBuf[1024];
unsigned char printBuf[4096];
unsigned char* printBufp = &printBuf[0];
unsigned char* printBufEnd = &printBuf[4096];
static int ttyBlockLen;
extern int useBProtocol;
extern int useEmulatorIF;
extern int useUltra64IF;
void flushPrintBuf(void)
{
int n = printBufp - printBuf;
int i, newn;
if (n) {
/* write to stdout */
write(1, printBuf, n);
/* now write to log file with \r, \0, and \b pre-processed */
if (consolelog && consfp) {
i = n;
for (i = 0; i < n; i++) {
switch(printBuf[i]) {
default:
continue;
case '\010':
/* erase previous carhacracter if possible */
if (i > 1) {
memmove(&printBuf[i-1], &printBuf[i+1], n-i);
n -= 2;
if (i < n)
i -= 2;
continue;
}
/* else just consume back space and fall through */
case '\r':
case '\0':
/* drop null and cr */
memmove(&printBuf[i], &printBuf[i+1], n-i);
n--;
if (i < n)
i--;
break;
}
}
fwrite(printBuf, 1, n, consfp);
fflush(consfp);
}
printBufp = printBuf;
}
}
static char* ctoa(int c)
{
static char buf[8];
char* bp = buf;
if (c & 0x80) {
*bp++ = 'M';
*bp++ = '-';
c &= 0x7f;
}
if (c == 0x7f) {
*bp++ = '^';
*bp++ = '?';
}
if (c < 32) {
*bp++ = '^';
*bp++ = c + '@';
} else {
*bp++ = c;
}
*bp++ = 0;
return buf;
}
void SendBlock(void* src, int len)
{
int retVal;
retVal = write(ttyFD,src,len);
if(retVal != len)
printf("Failure writing data to Nintendo 64\n");
}