Line 15... |
Line 15... |
// Creator: Dan Gisselquist, Ph.D.
|
// Creator: Dan Gisselquist, Ph.D.
|
// Gisselquist Technology, LLC
|
// Gisselquist Technology, LLC
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
|
//
|
//
|
// This program is free software (firmware): you can redistribute it and/or
|
// This program is free software (firmware): you can redistribute it and/or
|
// modify it under the terms of the GNU General Public License as published
|
// modify it under the terms of the GNU General Public License as published
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
// your option) any later version.
|
// your option) any later version.
|
Line 28... |
Line 28... |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for more details.
|
// for more details.
|
//
|
//
|
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
|
// target there if the PDF file isn't present.) If not, see
|
// target there if the PDF file isn't present.) If not, see
|
// <http://www.gnu.org/licenses/> for a copy.
|
// <http://www.gnu.org/licenses/> for a copy.
|
//
|
//
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// http://www.gnu.org/licenses/gpl.html
|
// http://www.gnu.org/licenses/gpl.html
|
Line 78... |
Line 78... |
#else
|
#else
|
#warning "TTYBUS DEBUG IS TURNED ON"
|
#warning "TTYBUS DEBUG IS TURNED ON"
|
#endif
|
#endif
|
|
|
void null(...) {}
|
void null(...) {}
|
|
|
#include <stdarg.h> // replaces the (defunct) varargs.h include file
|
#include <stdarg.h> // replaces the (defunct) varargs.h include file
|
void filedump(const char *fmt, ...) {
|
void filedump(const char *fmt, ...) {
|
static FILE *dbgfp = NULL;
|
static FILE *dbgfp = NULL;
|
va_list args;
|
va_list args;
|
|
|
Line 264... |
Line 265... |
if (m_wraddr == 0) {
|
if (m_wraddr == 0) {
|
m_wrloaded = true;
|
m_wrloaded = true;
|
}
|
}
|
}
|
}
|
|
|
if (p == 1) m_lastaddr++;
|
if (p == 1) m_lastaddr+=4;
|
}
|
}
|
// *ptr++ = charenc(0x2e);
|
// *ptr++ = charenc(0x2e);
|
if (ln == len-nw)
|
if (ln == len-nw)
|
*ptr++ = '\n';
|
*ptr++ = '\n';
|
*ptr = '\0';
|
*ptr = '\0';
|
Line 325... |
Line 326... |
|
|
return v;
|
return v;
|
}
|
}
|
|
|
char *TTYBUS::encode_address(const TTYBUS::BUSW a) {
|
char *TTYBUS::encode_address(const TTYBUS::BUSW a) {
|
TTYBUS::BUSW addr = a;
|
TTYBUS::BUSW addr = a>>2;
|
char *ptr = m_buf;
|
char *ptr = m_buf;
|
|
|
|
// Double check that we are aligned
|
|
if ((a&3)!=0) {
|
|
throw BUSERR(a);
|
|
}
|
|
|
if ((m_addr_set)&&(a == m_lastaddr))
|
if ((m_addr_set)&&(a == m_lastaddr))
|
return ptr;
|
return ptr;
|
|
|
if (m_addr_set) {
|
if (m_addr_set) {
|
// Encode a difference address
|
// Encode a difference address
|
int diffaddr = addr - m_lastaddr;
|
int diffaddr = (a - m_lastaddr)>>2;
|
ptr = m_buf;
|
ptr = m_buf;
|
if ((diffaddr >= -32)&&(diffaddr < 32)) {
|
if ((diffaddr >= -32)&&(diffaddr < 32)) {
|
*ptr++ = charenc(0x09);
|
*ptr++ = charenc(0x09);
|
*ptr++ = charenc(diffaddr & 0x03f);
|
*ptr++ = charenc(diffaddr & 0x03f);
|
} else if ((diffaddr >= -2048)&&(diffaddr < 2048)) {
|
} else if ((diffaddr >= -2048)&&(diffaddr < 2048)) {
|
Line 461... |
Line 467... |
while(nread<len) {
|
while(nread<len) {
|
buf[nread++] = readword();
|
buf[nread++] = readword();
|
}
|
}
|
} catch(BUSERR b) {
|
} catch(BUSERR b) {
|
DBGPRINTF("READV::BUSERR trying to read %08x\n", a+((inc)?nread:0));
|
DBGPRINTF("READV::BUSERR trying to read %08x\n", a+((inc)?nread:0));
|
throw BUSERR(a+((inc)?nread:0));
|
throw BUSERR(a+((inc)?(nread<<2):0));
|
}
|
}
|
|
|
if ((unsigned)m_lastaddr != (a+((inc)?(len):0))) {
|
if ((unsigned)m_lastaddr != (a+((inc)?(len<<2):0))) {
|
DBGPRINTF("TTYBUS::READV(a=%08x,inc=%d,len=%4x,x) ERR: (Last) %08x != %08x + %08x (Expected)\n", a, inc, len, m_lastaddr, a, (inc)?(len):0);
|
DBGPRINTF("TTYBUS::READV(a=%08x,inc=%d,len=%4x,x) ERR: (Last) %08x != %08x + %08x (Expected)\n", a, inc, len<<2, m_lastaddr, a, (inc)?(len<<2):0);
|
printf("TTYBUS::READV(a=%08x,inc=%d,len=%4x,x) ERR: (Last) %08x != %08x + %08x (Expected)\n", a, inc, len, m_lastaddr, a, (inc)?(len):0);
|
printf("TTYBUS::READV(a=%08x,inc=%d,len=%4x,x) ERR: (Last) %08x != %08x + %08x (Expected)\n", a, inc, len<<2, m_lastaddr, a, (inc)?(len<<2):0);
|
sleep(1);
|
sleep(1);
|
assert((int)m_lastaddr == (a+(inc)?(len):0));
|
assert((int)m_lastaddr == (a+(inc)?(len<<2):0));
|
exit(-3);
|
exit(-3);
|
}
|
}
|
|
|
DBGPRINTF("READV::COMPLETE\n");
|
DBGPRINTF("READV::COMPLETE\n");
|
}
|
}
|
Line 536... |
Line 542... |
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
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_addr_set = true;
|
m_addr_set = true;
|
m_lastaddr = val;
|
m_lastaddr = val<<2;
|
|
|
DBGPRINTF("RCVD ADDR: 0x%08x\n", val);
|
DBGPRINTF("RCVD ADDR: 0x%08x\n", val<<2);
|
} else if (0x0c == (sixbits & 0x03c)) { // Set 32-bit address,compressed
|
} else if (0x0c == (sixbits & 0x03c)) { // Set 32-bit address,compressed
|
int nw = (sixbits & 0x03) + 2;
|
int nw = (sixbits & 0x03) + 2;
|
do {
|
do {
|
nr += lclreadcode(&m_buf[nr], nw-nr);
|
nr += lclreadcode(&m_buf[nr], nw-nr);
|
} while (nr < nw);
|
} while (nr < nw);
|
Line 562... |
Line 568... |
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
val = (val<<6) | (chardec(m_buf[4]) & 0x03f);
|
val = (val<<6) | (chardec(m_buf[4]) & 0x03f);
|
}
|
}
|
|
|
m_addr_set = true;
|
m_addr_set = true;
|
m_lastaddr = val;
|
m_lastaddr = val<<2;
|
DBGPRINTF("RCVD ADDR: 0x%08x (%d bytes)\n", val, nw+1);
|
DBGPRINTF("RCVD ADDR: 0x%08x (%d bytes)\n", val<<2, nw+1);
|
} else
|
} else
|
found_start = true;
|
found_start = true;
|
} while(!found_start);
|
} while(!found_start);
|
|
|
int rdaddr;
|
int rdaddr;
|
|
|
DBGPRINTF("READ-WORD() -- sixbits = %02x\n", sixbits);
|
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)?4:0;
|
DBGPRINTF("READ-WORD() -- repeat last value, %08x, A= %08x\n", val, m_lastaddr);
|
DBGPRINTF("READ-WORD() -- repeat last value, %08x, A= %08x\n", val, m_lastaddr);
|
} 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);
|
Line 586... |
Line 592... |
|
|
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)?4:0;
|
DBGPRINTF("READ-WORD() -- long table value[%3d], %08x, A=%08x\n", idx, val, m_lastaddr);
|
DBGPRINTF("READ-WORD() -- long table value[%3d], %08x, A=%08x\n", idx, val, m_lastaddr);
|
} else if (0x20 == (sixbits & 0x030)) { // Tbl read, 2-9 into past
|
} else if (0x20 == (sixbits & 0x030)) { // Tbl read, 2-9 into past
|
int idx;
|
int idx;
|
idx = (((sixbits>>1)&0x07)+2);
|
idx = (((sixbits>>1)&0x07)+2);
|
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)?4:0;
|
DBGPRINTF("READ-WORD() -- short table value[%3d], %08x, A=%08x\n", idx, val, m_lastaddr);
|
DBGPRINTF("READ-WORD() -- short table value[%3d], %08x, A=%08x\n", idx, val, m_lastaddr);
|
} else if (0x38 == (sixbits & 0x038)) { // Raw read
|
} else if (0x38 == (sixbits & 0x038)) { // Raw read
|
// DBGPRINTF("READ-WORD() -- RAW-READ, nr = %d\n", nr);
|
// 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);
|
Line 609... |
Line 615... |
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
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)?4:0;
|
DBGPRINTF("READ-WORD() -- RAW-READ %02x:%02x:%02x:%02x:%02x:%02x -- %08x, A=%08x\n",
|
DBGPRINTF("READ-WORD() -- RAW-READ %02x:%02x:%02x:%02x:%02x:%02x -- %08x, A=%08x\n",
|
m_buf[0], m_buf[1], m_buf[2], m_buf[3],
|
m_buf[0], m_buf[1], m_buf[2], m_buf[3],
|
m_buf[4], m_buf[5], val, m_lastaddr);
|
m_buf[4], m_buf[5], val, m_lastaddr);
|
} else
|
} else
|
DBGPRINTF("READ-WORD() -- Unknown character, %02x\n", sixbits);
|
DBGPRINTF("READ-WORD() -- Unknown character, %02x\n", sixbits);
|
Line 717... |
Line 723... |
|
|
DBGPRINTF("READ-IDLE() PANIC! -- sixbits = %02x\n", sixbits);
|
DBGPRINTF("READ-IDLE() PANIC! -- 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)?4:0;
|
DBGPRINTF("READ-IDLE() -- repeat last value, %08x\n", val);
|
DBGPRINTF("READ-IDLE() -- 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);
|
Line 729... |
Line 735... |
|
|
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)?4:0;
|
DBGPRINTF("READ-IDLE() -- long table value[%3d], %08x\n", idx, val);
|
DBGPRINTF("READ-IDLE() -- 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)?4:0;
|
DBGPRINTF("READ-IDLE() -- short table value[%3d], %08x\n", rdaddr, val);
|
DBGPRINTF("READ-IDLE() -- short table value[%3d], %08x\n", rdaddr, val);
|
} else if (0x38 == (sixbits & 0x038)) { // Raw read
|
} else if (0x38 == (sixbits & 0x038)) { // Raw read
|
do {
|
do {
|
nr += lclreadcode(&m_buf[nr], 6-nr);
|
nr += lclreadcode(&m_buf[nr], 6-nr);
|
} while (nr < 6);
|
} while (nr < 6);
|
Line 749... |
Line 755... |
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
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)?4:0;
|
DBGPRINTF("READ-IDLE() -- RAW-READ %02x:%02x:%02x:%02x:%02x:%02x -- %08x\n",
|
DBGPRINTF("READ-IDLE() -- RAW-READ %02x:%02x:%02x:%02x:%02x:%02x -- %08x\n",
|
m_buf[0], m_buf[1], m_buf[2], m_buf[3],
|
m_buf[0], m_buf[1], m_buf[2], m_buf[3],
|
m_buf[4], m_buf[5], val);
|
m_buf[4], m_buf[5], val);
|
} else
|
} else
|
DBGPRINTF("READ-IDLE() -- Unknown character, %02x\n", sixbits);
|
DBGPRINTF("READ-IDLE() -- Unknown character, %02x\n", sixbits);
|