dbgif_ttycomm.c 2.01 KB
#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");

}