Line 16... |
Line 16... |
// Creator: Dan Gisselquist, Ph.D.
|
// Creator: Dan Gisselquist, Ph.D.
|
// Gisselquist Technology, LLC
|
// Gisselquist Technology, LLC
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
// Copyright (C) 2015-2016, 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 187... |
Line 187... |
}
|
}
|
|
|
void TTYBUS::writev(const BUSW a, const int p, const int len, const BUSW *buf) {
|
void TTYBUS::writev(const BUSW a, const int p, const int len, const BUSW *buf) {
|
char *ptr;
|
char *ptr;
|
|
|
|
// We'll never be called with more than MAXWRLEN words to write at once.
|
|
// This is a configurable option length, set at the top of this file.
|
|
// (currently set at 32, but subject to change ...) This is important,
|
|
// as the return channel *must* be capable of holding at least this many
|
|
// acknowledgments in its buffer.
|
|
//
|
|
// assert(len <= MAXWRLEN);
|
|
|
// Allocate a buffer of six bytes per word, one for addr, plus
|
// Allocate a buffer of six bytes per word, one for addr, plus
|
// six more
|
// six more
|
bufalloc((len+2)*6);
|
bufalloc((len+2)*6);
|
|
|
DBGPRINTF("WRITEV(%08x,%d,#%d,0x%08x ...)\n", a, p, len, buf[0]);
|
DBGPRINTF("WRITEV(%08x,%d,#%d,0x%08x ...)\n", a, p, len, buf[0]);
|
Line 212... |
Line 220... |
caddr = ( m_wraddr- tstaddr ) & 0x0ff;
|
caddr = ( m_wraddr- tstaddr ) & 0x0ff;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
if (caddr != 0)
|
/*
|
DBGPRINTF("WR[%08x] = %08x (= TBL[%4x] <= %4x)\n", m_lastaddr, val, caddr, m_wraddr);
|
if (caddr != 0)
|
else
|
DBGPRINTF("WR[%08x] = %08x (= TBL[%4x] <= %4x)\n", m_lastaddr, val, caddr, m_wraddr);
|
DBGPRINTF("WR[%08x] = %08x\n", m_lastaddr, val);
|
else
|
|
DBGPRINTF("WR[%08x] = %08x\n", m_lastaddr, val);
|
|
*/
|
|
|
if (caddr != 0) {
|
if (caddr != 0) {
|
*ptr++ = charenc( (((caddr>>6)&0x03)<<1) + (p?1:0) + 0x010);
|
*ptr++ = charenc( (((caddr>>6)&0x03)<<1) + (p?1:0) + 0x010);
|
*ptr++ = charenc( caddr &0x3f );
|
*ptr++ = charenc( caddr &0x3f );
|
|
|
Line 245... |
Line 255... |
*ptr++ = '\n'; *ptr = '\0';
|
*ptr++ = '\n'; *ptr = '\0';
|
m_dev->write(m_buf, ptr-m_buf);
|
m_dev->write(m_buf, ptr-m_buf);
|
|
|
DBGPRINTF(">> %s\n", m_buf);
|
DBGPRINTF(">> %s\n", m_buf);
|
DBGPRINTF("WR: LAST ADDRESS LEFT AT %08x\n", m_lastaddr);
|
DBGPRINTF("WR: LAST ADDRESS LEFT AT %08x\n", m_lastaddr);
|
|
|
|
// Need to clear the incoming queue ... if there's anything there.
|
|
// We could do a ...
|
|
// readacks(len);
|
|
// to clear a known number of acks (up to half the length of our buffer
|
|
// which we can let just sit for speed ...), or we could do a ...
|
|
// readtilidle(void);
|
|
// Then, upon startup we could also start with a readtilidle(); command.
|
|
// This would help to clear out the problems between programs, where
|
|
// one program doesn't finish reading, and the next gets a confusing
|
|
// message.
|
|
readidle();
|
}
|
}
|
|
|
void TTYBUS::writez(const BUSW a, const int len, const BUSW *buf) {
|
void TTYBUS::writez(const BUSW a, const int len, const BUSW *buf) {
|
int ln = len;
|
int ln = len;
|
const TTYBUS::BUSW *bptr = buf;
|
const TTYBUS::BUSW *bptr = buf;
|
Line 406... |
Line 428... |
|
|
if (len <= 0)
|
if (len <= 0)
|
return;
|
return;
|
DBGPRINTF("READV(%08x,%d,#%4d)\n", a, inc, len);
|
DBGPRINTF("READV(%08x,%d,#%4d)\n", a, inc, len);
|
|
|
|
// m_addr_set = false;
|
ptr = encode_address(a);
|
ptr = encode_address(a);
|
try {
|
try {
|
while(cmdrd < len) {
|
while(cmdrd < len) {
|
// ptr = m_buf;
|
// ptr = m_buf;
|
do {
|
do {
|
Line 539... |
Line 562... |
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);
|
DBGPRINTF("READ-WORD() -- repeat last value, %08x\n", val);
|
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);
|
} while (nr < 2);
|
} while (nr < 2);
|
Line 551... |
Line 574... |
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);
|
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
|
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);
|
DBGPRINTF("READ-WORD() -- short table value[%3d], %08x, A=%08x\n", rdaddr, 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);
|
} while (nr < 6);
|
} while (nr < 6);
|
Line 572... |
Line 595... |
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",
|
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_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);
|
|
|
return val;
|
return val;
|
}
|
}
|
|
|
|
void TTYBUS::readidle(void) {
|
|
TTYBUS::BUSW val = 0;
|
|
int nr;
|
|
unsigned sixbits;
|
|
bool found_start = false;
|
|
|
|
DBGPRINTF("READ-IDLE()\n");
|
|
|
|
while((!found_start)&&(m_dev->available())
|
|
&&((nr=lclreadcode(&m_buf[0], 1))>0)) {
|
|
nr = lclreadcode(&m_buf[0], 1);
|
|
sixbits = chardec(m_buf[0]);
|
|
|
|
if (sixbits&(~0x03f)) {
|
|
// Ignore new lines, unprintables, and characters
|
|
// not a part of our code
|
|
;
|
|
} else if (sixbits < 6) {
|
|
switch(sixbits) {
|
|
case 0: break; // Idle -- ignore
|
|
case 1: break; // Idle, but the bus is busy
|
|
case 2: break; // Write acknowledgement, ignore it here
|
|
case 3:
|
|
m_bus_err = true;
|
|
DBGPRINTF("READ-IDLE() - BUSERR\n");
|
|
throw BUSERR(0);
|
|
break;
|
|
case 4:
|
|
m_interrupt_flag = true;
|
|
break;
|
|
case 5:
|
|
m_bus_err = true;
|
|
DBGPRINTF("READ-IDLE() - BUS RESET\n");
|
|
throw BUSERR(0);
|
|
break;
|
|
}
|
|
} else if (0x08 == (sixbits & 0x3c)) { // Set 32-bit address
|
|
do {
|
|
nr += lclreadcode(&m_buf[nr], 6-nr);
|
|
} while (nr < 6);
|
|
|
|
val = chardec(m_buf[0]) & 0x03;
|
|
val = (val<<6) | (chardec(m_buf[1]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[2]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[4]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[5]) & 0x03f);
|
|
|
|
/* Ignore the address, as we are in readidle();
|
|
m_addr_set = true;
|
|
m_lastaddr = val;
|
|
*/
|
|
|
|
DBGPRINTF("RCVD IDLE-ADDR: 0x%08x\n", val);
|
|
} else if (0x0c == (sixbits & 0x03c)) { // Set 32-bit address,compressed
|
|
int nw = (sixbits & 0x03) + 2;
|
|
do {
|
|
nr += lclreadcode(&m_buf[nr], nw-nr);
|
|
} while (nr < nw);
|
|
|
|
if (nw == 2) {
|
|
val = chardec(m_buf[1]);
|
|
} else if (nw == 3) {
|
|
val = chardec(m_buf[1]);
|
|
val = (val<<6) | (chardec(m_buf[2]) & 0x03f);
|
|
} else if (nw == 4) {
|
|
val = chardec(m_buf[1]);
|
|
val = (val<<6) | (chardec(m_buf[2]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
|
} else { // if (nw == 5)
|
|
val = chardec(m_buf[1]);
|
|
val = (val<<6) | (chardec(m_buf[2]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[4]) & 0x03f);
|
|
}
|
|
|
|
/* Ignore address, we are in readidle();
|
|
m_addr_set = true;
|
|
m_lastaddr = val;
|
|
*/
|
|
DBGPRINTF("RCVD IDLE-ADDR: 0x%08x (%d bytes)\n", val, nw+1);
|
|
} else
|
|
found_start = true;
|
|
}
|
|
|
|
if (found_start) {
|
|
// We're in readidle(). We don't expect to find any data.
|
|
// But ... we did. So, just read it off and ignore it.
|
|
int rdaddr;
|
|
|
|
// DBGPRINTF("READ-WORD() -- sixbits = %02x\n", sixbits);
|
|
if (0x06 == (sixbits & 0x03e)) { // Tbl read, last value
|
|
rdaddr = (m_rdaddr-1)&0x03ff;
|
|
val = m_readtbl[rdaddr];
|
|
m_lastaddr += (sixbits&1);
|
|
DBGPRINTF("READ-IDLE() -- repeat last value, %08x\n", val);
|
|
} else if (0x10 == (sixbits & 0x030)) { // Tbl read, up to 521 into past
|
|
int idx;
|
|
do {
|
|
nr += lclreadcode(&m_buf[nr], 2-nr);
|
|
} while (nr < 2);
|
|
|
|
idx = (chardec(m_buf[0])>>1) & 0x07;
|
|
idx = ((idx<<6) | (chardec(m_buf[1]) & 0x03f)) + 2 + 8;
|
|
rdaddr = (m_rdaddr-idx)&0x03ff;
|
|
val = m_readtbl[rdaddr];
|
|
m_lastaddr += (sixbits&1);
|
|
DBGPRINTF("READ-IDLE() -- long table value[%3d], %08x\n", idx, val);
|
|
} else if (0x20 == (sixbits & 0x030)) { // Tbl read, 2-9 into past
|
|
rdaddr = (m_rdaddr - (((sixbits>>1)&0x07)+2)) & 0x03ff;
|
|
val = m_readtbl[rdaddr];
|
|
m_lastaddr += (sixbits&1);
|
|
DBGPRINTF("READ-IDLE() -- short table value[%3d], %08x\n", rdaddr, val);
|
|
} else if (0x38 == (sixbits & 0x038)) { // Raw read
|
|
DBGPRINTF("READ-IDLE() -- RAW-READ, nr = %d\n", nr);
|
|
do {
|
|
nr += lclreadcode(&m_buf[nr], 6-nr);
|
|
} while (nr < 6);
|
|
|
|
val = (chardec(m_buf[0])>>1) & 0x03;
|
|
val = (val<<6) | (chardec(m_buf[1]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[2]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[3]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[4]) & 0x03f);
|
|
val = (val<<6) | (chardec(m_buf[5]) & 0x03f);
|
|
|
|
m_readtbl[m_rdaddr++] = val; m_rdaddr &= 0x03ff;
|
|
m_lastaddr += (sixbits&1);
|
|
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[4], m_buf[5], val);
|
|
} else
|
|
DBGPRINTF("READ-IDLE() -- Unknown character, %02x\n", sixbits);
|
|
|
|
}
|
|
}
|
|
|
void TTYBUS::usleep(unsigned ms) {
|
void TTYBUS::usleep(unsigned ms) {
|
if (m_dev->poll(ms)) {
|
if (m_dev->poll(ms)) {
|
int nr;
|
int nr;
|
nr = m_dev->read(m_buf, 16);
|
nr = m_dev->read(m_buf, 16);
|
if (nr == 0) {
|
if (nr == 0) {
|