Skip to content

Commit

Permalink
Merge pull request #626 from FozzTexx/master
Browse files Browse the repository at this point in the history
Fix sending all bytes of file and don't abort if ATN is asserted immediately after EOI
  • Loading branch information
idolpx committed Jul 4, 2023
2 parents 07842a4 + d86cb00 commit e5618b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
8 changes: 4 additions & 4 deletions lib/bus/iec/protocol/iecProtocolSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ int16_t IecProtocolSerial::receiveByte()
// happened. If EOI was sent or received in this last transmission, both talker and listener "letgo." After a suitable pause,
// the Clock and Data lines are RELEASED to false and transmission stops.

if ( IEC.flags & EOI_RECVD )
if ( IEC.flags & EOI_RECVD
&& wait ( TIMING_Tfr )
&& (IEC.status( PIN_IEC_ATN ) == RELEASED) )
{
// EOI Received
if ( !wait ( TIMING_Tfr ) ) return -1;
IEC.release ( PIN_IEC_DATA_OUT );
IEC.release ( PIN_IEC_DATA_OUT );
}

timeoutWait( PIN_IEC_CLK_IN, RELEASED, TIMING_Tbb);
Expand Down
39 changes: 24 additions & 15 deletions lib/device/iec/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ void iecDisk::sendListing()

bool iecDisk::sendFile()
{
size_t i = 0;
size_t count = 0;
bool success_rx = true;
bool success_tx = true;

Expand Down Expand Up @@ -1018,15 +1018,14 @@ bool iecDisk::sendFile()
if( IEC.data.channel == CHANNEL_LOAD )
{
// Get/Send file load address
i = 2;
count = 2;
istream->read(&b, 1);
success_tx = IEC.sendByte(b);
load_address = b & 0x00FF; // low byte
sys_address = b;
istream->read(&b, 1);
success_tx = IEC.sendByte(b);
load_address = load_address | b << 8; // high byte
sys_address += b * 256;
sys_address = load_address;
Debug_printv( "load_address[$%.4X] sys_address[%d]", load_address, sys_address );

// Get SYSLINE
Expand All @@ -1051,14 +1050,13 @@ bool iecDisk::sendFile()
}
#endif
// Send Byte
avail = istream->available();
if ( !avail || !success_rx )
if ( count + 1 == avail || !success_rx )
{
//Debug_printv("b[%02X] EOI", b);
//Debug_printv("b[%02X] EOI %i", b, count);
success_tx = IEC.sendByte(b, true); // indicate end of file.
if ( !success_tx )
Debug_printv("tx fail");

break;
}
else
Expand All @@ -1069,10 +1067,10 @@ bool iecDisk::sendFile()
Debug_printv("tx fail");
//break;
}

}
b = nb; // byte = next byte
i++;
count++;

#ifdef DATA_STREAM
// Show ASCII Data
Expand All @@ -1083,13 +1081,13 @@ bool iecDisk::sendFile()

if(bi == 8)
{
uint32_t t = (i * 100) / len;
Debug_printf(" %s (%d %d%%) [%d]\r\n", ba, i, t, avail);
uint32_t t = (count * 100) / len;
Debug_printf(" %s (%d %d%%) [%d]\r\n", ba, count, t, avail);
bi = 0;
}
#else
uint32_t t = (i * 100) / len;
Debug_printf("\rTransferring %d%% [%d, %d] ", t, i, avail);
uint32_t t = (count * 100) / len;
Debug_printf("\rTransferring %d%% [%d, %d] ", t, count, avail);
#endif

// Exit if ATN is PULLED while sending
Expand All @@ -1110,7 +1108,18 @@ bool iecDisk::sendFile()
// fnLedManager.toggle(eLed::LED_BUS);
// }
}
Debug_printf("\r\n=================================\r\n%d bytes sent of %d [SYS%d]\r\n", i, avail, sys_address);

#ifdef DATA_STREAM
if (bi)
{
uint32_t t = (count * 100) / len;
ba[bi] = 0;
Debug_printf(" %s (%d %d%%) [%d]\r\n", ba, count, t, avail);
bi = 0;
}
#endif

Debug_printf("\r\n=================================\r\n%d bytes sent of %d [SYS%d]\r\n", count, avail, sys_address);

//Debug_printv("len[%d] avail[%d] success_rx[%d]", len, avail, success_rx);

Expand Down

0 comments on commit e5618b2

Please sign in to comment.