@@ -97,6 +97,7 @@ void virtualDevice::bus_to_computer(uint8_t *buf, uint16_t len, bool err)
9797 len = length
9898 Returns checksum
9999*/
100+ #ifdef OBSOLETE
100101uint8_t virtualDevice::bus_to_peripheral (uint8_t *buf, unsigned short len)
101102{
102103 // Retrieve data frame from computer
@@ -130,6 +131,16 @@ uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len)
130131
131132 return ck_rcv;
132133}
134+ #else
135+ uint8_t virtualDevice::bus_to_peripheral (uint8_t *buf, unsigned short len)
136+ {
137+ // FIXME - This is a terrible hack to allow devices to continue
138+ // directly read/write the bus instead of upgrading them to work
139+ // with packets.
140+ size_t rlen = SYSTEM_BUS.read (buf, len);
141+ return rs232_checksum (buf, rlen);
142+ }
143+ #endif /* OBSOLETE */
133144
134145// RS232 NAK
135146void virtualDevice::rs232_nak ()
@@ -219,6 +230,12 @@ void systemBus::_rs232_process_cmd()
219230 tempFrame->device (), tempFrame->command (),
220231 tempFrame->data () ? tempFrame->data ()->size () : -1 );
221232
233+ // FIXME - This is a terrible hack to allow devices to continue
234+ // directly read/write the bus instead of upgrading them to work
235+ // with packets.
236+ _lastPacketReceived = tempFrame.get ();
237+ _lastReadPosition = 0 ;
238+
222239 if (tempFrame->device () == FUJI_DEVICEID_DISK && _fujiDev != nullptr
223240 && _fujiDev->boot_config )
224241 {
@@ -500,8 +517,20 @@ void systemBus::sendReplyPacket(fujiDeviceID_t source, bool ack, void *data, siz
500517/* Convert direct bus access into bus packets? */
501518size_t systemBus::read (void *buffer, size_t length)
502519{
503- abort ();
504- return _port->read (buffer, length);
520+ // FIXME - This is a terrible hack to allow devices to continue
521+ // directly read/write the bus instead of upgrading them to work
522+ // with packets.
523+ // Assuming 'data()' returns the optional:
524+ auto optional_data = _lastPacketReceived->data ();
525+
526+ if (!optional_data.has_value ())
527+ return 0 ;
528+
529+ size_t avail = optional_data.value ().size () - _lastReadPosition;
530+ avail = std::min (avail, (size_t ) length);
531+ memcpy (buffer, optional_data.value ().data () + _lastReadPosition, avail);
532+ _lastReadPosition += avail;
533+ return avail;
505534}
506535
507536size_t systemBus::read ()
0 commit comments