Skip to content

Commit bf0244d

Browse files
committed
[atari] Don't forget to sync occasionally during write.
1 parent 841e3d3 commit bf0244d

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

lib/bus/sio/NetSIO.cpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,28 +567,61 @@ void NetSIO::updateFIFO()
567567
return;
568568
}
569569

570+
void NetSIO::handle_write_sync(uint8_t c)
571+
{
572+
// handle pending sync request
573+
if (_sync_write_size < 0)
574+
{
575+
// SYNC RESPONSE
576+
// send byte (should be ACK/NAK) bundled in sync response
577+
sendSyncResponse(NETSIO_ACK_SYNC, c, 0);
578+
return;
579+
}
580+
else
581+
{
582+
// sio_late_ack() was not from whatever reason followed by bus_to_peripheral()
583+
Debug_println("Warn: NetSIO late ACK without bus_to_peripheral");
584+
// send late ACK byte
585+
sendSyncResponse(NETSIO_ACK_SYNC, _sync_ack_byte, _sync_write_size);
586+
}
587+
588+
return;
589+
}
590+
570591
size_t NetSIO::dataOut(const void *buffer, size_t size)
571592
{
572593
int result;
573594
int to_send;
574595
int txbytes = 0;
575596
uint8_t txbuf[513];
597+
uint8_t *ptr = (uint8_t *) buffer;
576598

577599
if (!_initialized)
578600
return 0;
579601

580-
while (txbytes < size)
602+
if (size && _sync_request_num >= 0)
603+
{
604+
handle_write_sync(ptr[0]);
605+
ptr++;
606+
size--;
607+
}
608+
609+
while (size)
581610
{
582611
// send block
583-
to_send = ((size-txbytes) > sizeof(txbuf)-1) ? sizeof(txbuf)-1 : (size-txbytes);
612+
to_send = std::min(size, sizeof(txbuf) - 1);
584613
txbuf[0] = NETSIO_DATA_BLOCK;
585-
memcpy(txbuf+1, ((uint8_t *)buffer)+txbytes, to_send);
614+
memcpy(txbuf+1, ptr+txbytes, to_send);
586615
// ? calculate credit based on amount of data ?
587616
if (!wait_for_credit(1))
588617
break;
589618
result = write_sock(txbuf, to_send+1);
590619
if (result > 0)
591-
txbytes += result-1;
620+
{
621+
result--;
622+
txbytes += result;
623+
size -= result;
624+
}
592625
else if (result < 0)
593626
break;
594627
}

lib/bus/sio/NetSIO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class NetSIO : public IOChannel
7171
// flow control
7272
int _credit;
7373

74+
void handle_write_sync(uint8_t c);
75+
7476
protected:
7577
void suspend(int ms=5000);
7678
bool resume_test();

0 commit comments

Comments
 (0)