Skip to content

rifastseriallib

This library is meant for games that link two Amigas with a serial cable and need to exchange data quickly. It drives the serial port hardware directly, without serial.device and without interrupts: every command waits for the port itself until a byte can be sent or has arrived. While the library is in use, no other program may use the serial port. A program that does not need the speed should use serial.device instead.

InitSerialIO sets the baud rate and the two buffers and switches off the system’s serial interrupts. One machine is the master and the other the slave: SyncSerial decides that between the two and SetSerialMode sets it by hand. DoSerialIO then exchanges the buffers, byte for byte, the master sending first and the slave receiving first. PutSerial, GetSerial, SyncPut and SyncGet move single bytes or blocks.

FinitSerialIO, also at the end of the program, switches the serial interrupts back on, so that serial.device works again. The commands that use the port do nothing before InitSerialIO. Both machines of a link should run programs built with the same library.

Dim inb.b(63),outb.b(63)
InitSerialIO 19200,64,&inb(0),&outb(0)
master=SyncSerial(42)
SetSerialMode master
DoSerialIO
FinitSerialIO

Based on the RI FastSerial Lib guide by Red When Excited.

Library number 36.

Commands

CheckSerial

The byte waiting at the serial port, or -1 if there is none or InitSerialIO was not called. It does not wait.

Function, result .w. No help text.
No arguments.

DoSerialIO

Exchanges the buffers of InitSerialIO with the other machine, byte for byte. Without an argument it transfers the number of bytes given to InitSerialIO or to the last SetIOSize, nothing for 0; with an argument, that number plus 1.

Statement. Help text: [numbytes-1]
2 forms:

  • no arguments
  • .w

Both machines must call it at the same time, one as the master and one as the slave (SetSerialMode). Nothing happens before InitSerialIO.

EndSerialIO

Does nothing.

Statement. Help text: - disable serial read/write
No arguments.

FinitSerialIO

Ends the serial transfers started with InitSerialIO and switches the system’s serial interrupts that were on before back on; it is called by itself when the program ends.

Statement. No help text.
No arguments.

FlushSerialIO

Throws away a byte waiting at the serial port.

Statement. Help text: - make sure serial port is empty
No arguments.

GetSerial

Without arguments, waits for a byte and returns it. With address,bytes, waits for that many bytes, stores them from address on and returns -1.

Statement or function, result .b. Help text: [address,bytes]
2 forms:

  • no arguments
  • .l, .l

Before InitSerialIO both forms return 0 at once, and the block form also for a block of 0 bytes.

InitSerialIO

Prepares the serial port for the library - sets the baud rate, the number of bytes DoSerialIO exchanges and the input and output buffers, and switches the system’s serial interrupts off. As a function it returns -1 if it set the port up, else 0.

Statement or function, result .l. Help text: baud,numbytes,inbuf,outbuf
Arguments: .l, .w, .l, .l

A second call without FinitSerialIO in between does nothing and returns 0, and so does a baud rate outside 109 to 3546895.

PutSerial

Sends one byte, or bytes bytes from address, waiting until the port can take each one. Nothing is sent before InitSerialIO.

Statement. Help text: address,bytes | byte
2 forms:

  • .b
  • .l, .l

A block of 0 bytes sends nothing.

SetIOBuffers

Sets the input and output buffers that DoSerialIO uses.

Statement. Help text: inbuf,outbuf
Arguments: .l, .l

SetIOSize

Sets the number of bytes that DoSerialIO without an argument transfers.

Statement. Help text: bytes
Arguments: .w

SetIOSpeed

Changes the baud rate after InitSerialIO; before it, nothing happens.

Statement. Help text: baudrate
Arguments: .w

A baud rate outside 109 to 3546895 is refused.

SetSerialMode

Makes this machine the master (-1) or the slave (0) for DoSerialIO. The master sends each byte before it receives one, the slave the other way round.

Statement. Help text: mode -- determine master/slave
Arguments: .b

SyncGet

Receives bytes bytes to address, answering each one, as the partner of SyncPut.

Statement. Help text: address,bytes
Arguments: .l, .l

A block of 0 bytes receives nothing.

SyncPut

Sends bytes bytes from address, waiting after each one for the other machine’s answer, so that a slow receiver loses nothing. The other machine receives them with SyncGet.

Statement. Help text: address,bytes
Arguments: .l, .l

A block of 0 bytes sends nothing.

SyncSerial

Synchronises with the other machine on the byte syncbyte and decides which is the master. Returns -1 if this machine is the master and 0 if it is the slave.

Statement or function, result .w. Help text: syncbyte
Arguments: .b

The machine that is started second, and finds the other’s sync byte already waiting, becomes the slave. Kept from the original: when both start at the same moment, both become the master (#655).