@@ -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,13 +131,27 @@ 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 ()
136147{
148+ #ifdef OBSOLETE
137149 SYSTEM_BUS.write (' N' );
138150 SYSTEM_BUS.flushOutput ();
139151 Debug_println (" NAK!" );
152+ #else
153+ rs232_error ();
154+ #endif /* OBSOLETE */
140155}
141156
142157// RS232 ACK
@@ -165,10 +180,13 @@ void virtualDevice::rs232_complete()
165180// RS232 ERROR
166181void virtualDevice::rs232_error ()
167182{
168- abort ();
183+ # ifdef OBSOLETE
169184 fnSystem.delay_microseconds (DELAY_T5);
170185 SYSTEM_BUS.write (' E' );
171186 Debug_println (" ERROR!" );
187+ #else
188+ SYSTEM_BUS.sendReplyPacket (_devnum, false , nullptr , 0 );
189+ #endif /* OBSOLETE */
172190}
173191
174192#ifdef OBSOLETE
@@ -219,6 +237,12 @@ void systemBus::_rs232_process_cmd()
219237 tempFrame->device (), tempFrame->command (),
220238 tempFrame->data () ? tempFrame->data ()->size () : -1 );
221239
240+ // FIXME - This is a terrible hack to allow devices to continue
241+ // directly read/write the bus instead of upgrading them to work
242+ // with packets.
243+ _lastPacketReceived = tempFrame.get ();
244+ _lastReadPosition = 0 ;
245+
222246 if (tempFrame->device () == FUJI_DEVICEID_DISK && _fujiDev != nullptr
223247 && _fujiDev->boot_config )
224248 {
@@ -500,8 +524,20 @@ void systemBus::sendReplyPacket(fujiDeviceID_t source, bool ack, void *data, siz
500524/* Convert direct bus access into bus packets? */
501525size_t systemBus::read (void *buffer, size_t length)
502526{
503- abort ();
504- return _port->read (buffer, length);
527+ // FIXME - This is a terrible hack to allow devices to continue
528+ // directly read/write the bus instead of upgrading them to work
529+ // with packets.
530+ // Assuming 'data()' returns the optional:
531+ auto optional_data = _lastPacketReceived->data ();
532+
533+ if (!optional_data.has_value ())
534+ return 0 ;
535+
536+ size_t avail = optional_data.value ().size () - _lastReadPosition;
537+ avail = std::min (avail, (size_t ) length);
538+ memcpy (buffer, optional_data.value ().data () + _lastReadPosition, avail);
539+ _lastReadPosition += avail;
540+ return avail;
505541}
506542
507543size_t systemBus::read ()
0 commit comments