OpenCores
URL https://opencores.org/ocsvn/xulalx25soc/xulalx25soc/trunk

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [ttybus.cpp] - Diff between revs 25 and 46

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 25 Rev 46
Line 73... Line 73...
// #define      DBGPRINTF       filedump
// #define      DBGPRINTF       filedump
 
 
void    null(...) {}
void    null(...) {}
#include <stdarg.h>
#include <stdarg.h>
// #include <varargs.h>
// #include <varargs.h>
#if (DBGPRINTF != null)
/*
static void     filedump(const char *fmt, ...) {
void    filedump(const char *fmt, ...) {
        static  FILE *dbgfp = NULL;
        static  FILE *dbgfp = NULL;
        va_list args;
        va_list args;
 
 
        if (!dbgfp)
        if (!dbgfp)
                dbgfp = fopen("debug.txt", "w");
                dbgfp = fopen("debug.txt", "w");
        va_start(args, fmt);
        va_start(args, fmt);
        vfprintf(dbgfp, fmt, args);
        vfprintf(dbgfp, fmt, args);
        va_end(args);
        va_end(args);
        fflush(dbgfp);
        fflush(dbgfp);
}
}
#endif
*/
 
 
char    TTYBUS::charenc(const int sixbitval) {
char    TTYBUS::charenc(const int sixbitval) const {
        if (sixbitval < 10)
        if (sixbitval < 10)
                return '0' + sixbitval;
                return '0' + sixbitval;
        else if (sixbitval < 10+26)
        else if (sixbitval < 10+26)
                return 'A' - 10 + sixbitval;
                return 'A' - 10 + sixbitval;
        else if (sixbitval < 10+26+26)
        else if (sixbitval < 10+26+26)
Line 104... Line 104...
        fprintf(stderr, "INTERNAL ERR: SIXBITVAL isn\'t!!!! sixbitval = %08x\n", sixbitval);
        fprintf(stderr, "INTERNAL ERR: SIXBITVAL isn\'t!!!! sixbitval = %08x\n", sixbitval);
        assert((sixbitval & (~0x03f))==0);
        assert((sixbitval & (~0x03f))==0);
        return 0;
        return 0;
}
}
 
 
unsigned        TTYBUS::chardec(const char b) {
unsigned        TTYBUS::chardec(const char b) const {
        if ((b >= '0')&&(b <= '9'))
        if ((b >= '0')&&(b <= '9'))
                return b-'0';
                return b-'0';
        else if ((b >= 'A')&&(b <= 'Z'))
        else if ((b >= 'A')&&(b <= 'Z'))
                return b-'A'+10;
                return b-'A'+10;
        else if ((b >= 'a')&&(b <= 'z'))
        else if ((b >= 'a')&&(b <= 'z'))
Line 145... Line 145...
                delete[] m_buf;
                delete[] m_buf;
        m_buflen = (len&(-0x3f))+0x40;
        m_buflen = (len&(-0x3f))+0x40;
        m_buf = new char[m_buflen];
        m_buf = new char[m_buflen];
}
}
 
 
void    TTYBUS::encode(const int hb, const BUSW val, char *buf) {
void    TTYBUS::encode(const int hb, const BUSW val, char *buf) const {
        buf[0] = charenc( (hb<<2)|((val>>30)&0x03) );
        buf[0] = charenc( (hb<<2)|((val>>30)&0x03) );
        buf[1] = charenc( (val>>24)&0x3f);
        buf[1] = charenc( (val>>24)&0x3f);
        buf[2] = charenc( (val>>18)&0x3f);
        buf[2] = charenc( (val>>18)&0x3f);
        buf[3] = charenc( (val>>12)&0x3f);
        buf[3] = charenc( (val>>12)&0x3f);
        buf[4] = charenc( (val>> 6)&0x3f);
        buf[4] = charenc( (val>> 6)&0x3f);
        buf[5] = charenc( (val    )&0x3f);
        buf[5] = charenc( (val    )&0x3f);
}
}
 
 
unsigned        TTYBUS::decodestr(const char *buf) {
unsigned        TTYBUS::decodestr(const char *buf) const {
        unsigned        r;
        unsigned        r;
 
 
        r = chardec(buf[0]) & 0x03;
        r = chardec(buf[0]) & 0x03;
        r = (r<<6) | (chardec(buf[1]) & 0x03f);
        r = (r<<6) | (chardec(buf[1]) & 0x03f);
        r = (r<<6) | (chardec(buf[2]) & 0x03f);
        r = (r<<6) | (chardec(buf[2]) & 0x03f);
Line 167... Line 167...
        r = (r<<6) | (chardec(buf[5]) & 0x03f);
        r = (r<<6) | (chardec(buf[5]) & 0x03f);
 
 
        return r;
        return r;
}
}
 
 
int     TTYBUS::decodehex(const char hx) {
int     TTYBUS::decodehex(const char hx) const {
        if ((hx >= '0')&&(hx <= '9'))
        if ((hx >= '0')&&(hx <= '9'))
                return hx-'0';
                return hx-'0';
        else if ((hx >= 'A')&&(hx <= 'Z'))
        else if ((hx >= 'A')&&(hx <= 'Z'))
                return hx-'A'+10;
                return hx-'A'+10;
        else if ((hx >= 'a')&&(hx <= 'z'))
        else if ((hx >= 'a')&&(hx <= 'z'))
Line 534... Line 534...
                        found_start = true;
                        found_start = true;
        } while(!found_start);
        } while(!found_start);
 
 
        int     rdaddr;
        int     rdaddr;
 
 
 
        DBGPRINTF("READ-WORD() -- sixbits = %02x\n", sixbits);
        if (0x06 == (sixbits & 0x03e)) { // Tbl read, last value
        if (0x06 == (sixbits & 0x03e)) { // Tbl read, last value
                rdaddr = (m_rdaddr-1)&0x03ff;
                rdaddr = (m_rdaddr-1)&0x03ff;
                val = m_readtbl[rdaddr];
                val = m_readtbl[rdaddr];
                m_lastaddr += (sixbits&1);
                m_lastaddr += (sixbits&1);
 
                DBGPRINTF("READ-WORD() -- repeat last value, %08x\n", val);
        } else if (0x10 == (sixbits & 0x030)) { // Tbl read, up to 521 into past
        } else if (0x10 == (sixbits & 0x030)) { // Tbl read, up to 521 into past
                int     idx;
                int     idx;
                do {
                do {
                        nr += lclreadcode(&m_buf[nr], 2-nr);
                        nr += lclreadcode(&m_buf[nr], 2-nr);
                } while (nr < 2);
                } while (nr < 2);
Line 549... Line 551...
                idx = (chardec(m_buf[0])>>1) & 0x07;
                idx = (chardec(m_buf[0])>>1) & 0x07;
                idx = ((idx<<6) | (chardec(m_buf[1]) & 0x03f)) + 2 + 8;
                idx = ((idx<<6) | (chardec(m_buf[1]) & 0x03f)) + 2 + 8;
                rdaddr = (m_rdaddr-idx)&0x03ff;
                rdaddr = (m_rdaddr-idx)&0x03ff;
                val = m_readtbl[rdaddr];
                val = m_readtbl[rdaddr];
                m_lastaddr += (sixbits&1);
                m_lastaddr += (sixbits&1);
 
                DBGPRINTF("READ-WORD() -- long table value[%3d], %08x\n", idx, val);
        } else if (0x20 == (sixbits & 0x030)) { // Tbl read, 2-9 into past
        } else if (0x20 == (sixbits & 0x030)) { // Tbl read, 2-9 into past
                rdaddr = (m_rdaddr - (((sixbits>>1)&0x07)+2)) & 0x03ff;
                rdaddr = (m_rdaddr - (((sixbits>>1)&0x07)+2)) & 0x03ff;
                val = m_readtbl[rdaddr];
                val = m_readtbl[rdaddr];
                m_lastaddr += (sixbits&1);
                m_lastaddr += (sixbits&1);
 
                DBGPRINTF("READ-WORD() -- short table value[%3d], %08x\n", rdaddr, val);
        } else if (0x38 == (sixbits & 0x038)) { // Raw read
        } else if (0x38 == (sixbits & 0x038)) { // Raw read
 
                DBGPRINTF("READ-WORD() -- RAW-READ, nr = %d\n", nr);
                do {
                do {
                        nr += lclreadcode(&m_buf[nr], 6-nr);
                        nr += lclreadcode(&m_buf[nr], 6-nr);
                } while (nr < 6);
                } while (nr < 6);
 
 
                val = (chardec(m_buf[0])>>1) & 0x03;
                val = (chardec(m_buf[0])>>1) & 0x03;
Line 567... Line 572...
                val = (val<<6) | (chardec(m_buf[4]) & 0x03f);
                val = (val<<6) | (chardec(m_buf[4]) & 0x03f);
                val = (val<<6) | (chardec(m_buf[5]) & 0x03f);
                val = (val<<6) | (chardec(m_buf[5]) & 0x03f);
 
 
                m_readtbl[m_rdaddr++] = val; m_rdaddr &= 0x03ff;
                m_readtbl[m_rdaddr++] = val; m_rdaddr &= 0x03ff;
                m_lastaddr += (sixbits&1);
                m_lastaddr += (sixbits&1);
        }
                DBGPRINTF("READ-WORD() -- RAW-READ %02x:%02x:%02x:%02x:%02x:%02x -- %08x\n",
 
                        m_buf[0], m_buf[1], m_buf[2], m_buf[3],
 
                        m_buf[4], m_buf[5], val);
 
        } else
 
                DBGPRINTF("READ-WORD() -- Unknown character, %02x\n", sixbits);
 
 
        return val;
        return val;
}
}
 
 
void    TTYBUS::usleep(unsigned ms) {
void    TTYBUS::usleep(unsigned ms) {

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.