From: Szász G. <sz...@hu...> - 2020-12-07 18:30:35
|
On Mon, Dec 07, 2020 at 01:14:54PM +0100, Niccolo Rigacci wrote: > After several years of oblivion I revived my ZX-Spectrum software > files. In the '90s I purchased an emulator by Gerton Lunter > (great sofware for the MS-DOS!), but today I installed Fuse GTK > on my Linux box. > > It turned out that the serial files that I saved with the old > emulator does not load in Fuse. If I try to load a BASIC program > with > > LOAD *"b" > > I get the error: > > Wrong file type, 0:1 > > After some hours of hunting, I discovered that adding an 0x2A > byte after every 0x00 byte into the stream solved the problem. > > Why is that required? > > Is the serial format handled directly by Fuse or is it handled > via libspectrum? > > Btw, a big thank you to everyone who made this software! > Hello Niccolo, The serial (RS232) 'stream' is not just a plain byte stream of sended/received bytes, because RS232 has some handshake mechanism to synchronise the receiver and the sender machines. ZX spectrum uses only 4 lines to communicate: DTR, CTS, TX, RX I cannot blah-blah because you can found a lot of detailed description about RS232 on the net... if you interested ever ;-) ------ We can try to emulate the handshake stuff, so we connect two fuse with named pipes over RS232, and it works well. We use escape sequencies to insert handshake information into byte stream: 0 0 -> DTR goes low 0 1 -> DTR goes high 0 2 -> CTS goes low 0 3 -> CTS goes high 0 42 -> real 0 So 0 byte is the escape character and you emit a real 0 byte if you send a 0 and 42 (*) in hex 0x2a And yes, if you have a bare stream of bytes from an RS232 communication you have to change every 0x00 with 0x00 0xa2 Here is some description from if1.c file: RS232: DTR -> Data Terminal Ready (DTE -> DCE) CTS -> Clear To Send (DCE -> DTE) TX -> Transmitted Data (DTE -> DCE) RX -> Received Data (DCE -> DTE) The IF1 serial behaves not as a DTE (Data Terminal Equipment, e.g. a computer) but as a DCE (Data Communications Equipment, e.g. a modem) If we were to consider the ZX Spectrum a DTE, we would rename the lines: DTR := DSR (Data Set Ready) CTS := RTS (Request To Send) TX := RX RX := TX On the communication channels: Bytes interpreted as is, except: 0x00 0x00 --> DTR ~~\__ 0x00 0x01 --> DTR __/~~ 0x00 0x02 --> CTS ~~\__ 0x00 0x03 --> CTS __/~~ 0x00 ? --> lost 0x00 * --> 0x00 Additionally: if fuse read 0x00 0x00 => DTR = 0 ~~\__ if fuse read 0x00 0x01 => DTR = 1 __/~~ if CTS = ~~\__ fuse send 0x00 0x02 if CTS = __/~~ fuse send 0x00 0x03 if fuse lost send 0x00 + 0x3f (?) every other 0x00 + 0x## are discarded Best regards, Gergely |