BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
riseriallib.c File Reference
#include "blitzlib.h"
#include "blitzexec.h"

Macros

#define CUSTOMREG(type, off)
#define SERDATR_HI   CUSTOMREG(UBYTE, 0x18) /* TBE = bit 5 */
#define SERDATR_LO   CUSTOMREG(UBYTE, 0x19) /* the received byte */
#define INTENAR   CUSTOMREG(UWORD, 0x1c)
#define INTREQR_HI   CUSTOMREG(UBYTE, 0x1e) /* RBF = bit 3 (11) */
#define INTREQR_LO   CUSTOMREG(UBYTE, 0x1f) /* TBE = bit 0 */
#define SERDAT   CUSTOMREG(UWORD, 0x30)
#define SERPER   CUSTOMREG(UWORD, 0x32)
#define INTENA   CUSTOMREG(UWORD, 0x9a)
#define INTREQ   CUSTOMREG(UWORD, 0x9c)
#define CIABPRA   (*riser_ciab)
#define SERCLOCK   3546895UL
#define VEC_TBE   vector(vecbase + 0x64)
#define VEC_RBF   vector(vecbase + 0x74)
#define BUMP(w, n)
#define BL_INTHANDLER(entry, cfunc, old)

Functions

void _setbaud (void)
void _openserial (void)
void _openserial2 (void)
void _closeserial (void)
void _readser (void)
void _writeser (void)
void info (void)
void _showloc (void)
void _sersend (void)
void _serreceive (void)
void _flushser (void)
void _sendserialstring (void)
void _readserialstring (void)
void _buffpos (void)
void _readlong (void)
void _writelong (void)
void _abortxfer (void)
void _buffcount (void)
void _buffcount2 (void)
void riseriallib_libfinit (void)
void readint (void)
void writeint (void)
static volatile ULONG * vector (ULONG a)
static ULONG getvbr (void)
static ULONG readvbr (void)
static ULONG readser (void)
static ULONG writeser (ULONG value)
static ULONG openserial (ULONG value)
void c_setbaud (ULONG rate)
 SerialBaud rate: sets the baud rate (SERPER = 3546895 / rate - 1, bit 15 cleared).
void c_openserial (void)
 SerialOpen: installs the library's receive and transmit interrupts (see openserial).
void c_openserial2 (ULONG rate)
 SerialOpen baudrate: SerialBaud baudrate, then SerialOpen.
void c_closeserial (void)
 SerialClose (and finit): restores the vectors, CIA-B PRA $FF and the interrupts.
ULONG c_readser (void)
 SerialRead: the next received byte.
void c_writeser (ULONG value)
 SerialWrite byte: puts the byte (with a stop bit) into the transmit ring; TBE is requested when the ring was empty.
ULONG c_info (void)
 SerialVersion: the version of the library.
ULONG c_showloc (void)
 SerialBuffer: the address of the receive ring (256 bytes; its two index words lie in front of it).
void c_sersend (ULONG addr, ULONG len)
 SerialSendBlock address,length: sends a block byte by byte.
void c_serreceive (ULONG addr, ULONG len)
 SerialReceiveBlock address,length: receives a block byte by byte.
void c_flushser (void)
 SerialFlush: reads until the receive buffer is empty.
void c_sendserialstring (const UBYTE *str, const ULONG *argstack)
 SerialSendString a$: meant to send a string.
ULONG c_readserialstring (const UBYTE *sbuf)
 SerialReadString: received bytes up to a 0, at a3.
ULONG c_buffpos (void)
 SerialProgress: the remaining count of the last send (or receive) block.
ULONG c_readlong (void)
 SerialReadLong: reads a long, the low byte first.
void c_writelong (ULONG longword)
 SerialWriteLong longword: sends a long, the low byte first.
void c_abortxfer (void)
 SerialStop: ends a block transfer (sets the stop flag).
ULONG c_buffcount (void)
 SerialGot: the number of bytes waiting in the receive ring.
ULONG c_buffcount2 (void)
 SerialWait: waits for a byte and reads it (SerialRead).
ULONG c_readint (void)
 The receive interrupt (level 5): SERDATR's byte into the ring.
ULONG c_writeint (void)
 The transmit interrupt (level 1): one word of the ring when SERDATR shows TBE.
 BL_INTHANDLER (readint, c_readint, riser_oldint5)
 BL_INTHANDLER (writeint, c_writeint, riser_oldint1)

Variables

volatile UBYTE * riser_custom = (volatile UBYTE *)0xdff000
volatile UBYTE * riser_ciab = (volatile UBYTE *)0xbfd000
static ULONG vecbase
static ULONG buffstart
static ULONG bufflength
static ULONG baudrate = 2400
static volatile ULONG quitflag
static UWORD openflag
static UWORD oldint
ULONG riser_oldint1 = 0xffffffff
ULONG riser_oldint5 = 0xffffffff
struct { 
   volatile UWORD   big 
   volatile UWORD   end 
   UBYTE   buf [1024] 
} rd
struct { 
   volatile UWORD   big 
   volatile UWORD   end 
   UBYTE   buf [1024] 
} wr
static ULONG numchars
static const UBYTE server = 1
static const char version [] = "$VER: Serial-Library v1.0 (7.3.1994)"

Macro Definition Documentation

◆ BL_INTHANDLER

#define BL_INTHANDLER ( entry,
cfunc,
old )
Value:
BLITZ_ASM_BLOCK(entry, " .globl _" #entry "\n" \
"_" #entry ":\n" \
" movem.l d0-d1/a0-a1,-(sp)\n" \
" jsr _" #cfunc "\n" \
" tst.l d0\n" \
" movem.l (sp)+,d0-d1/a0-a1\n" \
" beq.s 1f\n" \
" rte\n" \
"1: move.l _" #old ",-(sp)\n" \
" rts\n")
#define BLITZ_ASM_BLOCK(name, text)
Definition blitzlib.h:981
static struct snowfield * entry(ULONG n)
Definition risnowlib.c:205

◆ BUMP

#define BUMP ( w,
n )
Value:
(((volatile UBYTE *)&(w))[1] += (n))
ULONG WORD UWORD UWORD border ULONG ULONG struct bb_bitmap *dst void UWORD n
Definition 2dlib.c:2498
struct TagItem w
Definition asllib.c:192

◆ CIABPRA

#define CIABPRA   (*riser_ciab)

◆ CUSTOMREG

#define CUSTOMREG ( type,
off )
Value:
(*(volatile type *)(riser_custom + (off)))
UWORD type
Definition editlib.c:263
volatile UBYTE * riser_custom
Definition riseriallib.c:293

◆ INTENA

#define INTENA   CUSTOMREG(UWORD, 0x9a)

◆ INTENAR

#define INTENAR   CUSTOMREG(UWORD, 0x1c)

◆ INTREQ

#define INTREQ   CUSTOMREG(UWORD, 0x9c)

◆ INTREQR_HI

#define INTREQR_HI   CUSTOMREG(UBYTE, 0x1e) /* RBF = bit 3 (11) */

◆ INTREQR_LO

#define INTREQR_LO   CUSTOMREG(UBYTE, 0x1f) /* TBE = bit 0 */

◆ SERCLOCK

#define SERCLOCK   3546895UL

◆ SERDAT

#define SERDAT   CUSTOMREG(UWORD, 0x30)

◆ SERDATR_HI

#define SERDATR_HI   CUSTOMREG(UBYTE, 0x18) /* TBE = bit 5 */

◆ SERDATR_LO

#define SERDATR_LO   CUSTOMREG(UBYTE, 0x19) /* the received byte */

◆ SERPER

#define SERPER   CUSTOMREG(UWORD, 0x32)

◆ VEC_RBF

#define VEC_RBF   vector(vecbase + 0x74)

◆ VEC_TBE

#define VEC_TBE   vector(vecbase + 0x64)

Function Documentation

◆ _abortxfer()

void _abortxfer ( void )

◆ _buffcount()

void _buffcount ( void )

◆ _buffcount2()

void _buffcount2 ( void )

◆ _buffpos()

void _buffpos ( void )

◆ _closeserial()

void _closeserial ( void )

◆ _flushser()

void _flushser ( void )

◆ _openserial()

void _openserial ( void )

◆ _openserial2()

void _openserial2 ( void )

◆ _readlong()

void _readlong ( void )

◆ _readser()

void _readser ( void )

◆ _readserialstring()

void _readserialstring ( void )

◆ _sendserialstring()

void _sendserialstring ( void )

◆ _serreceive()

void _serreceive ( void )

◆ _sersend()

void _sersend ( void )

◆ _setbaud()

void _setbaud ( void )

◆ _showloc()

void _showloc ( void )

◆ _writelong()

void _writelong ( void )

◆ _writeser()

void _writeser ( void )

◆ BL_INTHANDLER() [1/2]

BL_INTHANDLER ( readint ,
c_readint ,
riser_oldint5  )

◆ BL_INTHANDLER() [2/2]

BL_INTHANDLER ( writeint ,
c_writeint ,
riser_oldint1  )

◆ c_abortxfer()

void c_abortxfer ( void )

SerialStop: ends a block transfer (sets the stop flag).

The block and string commands clear the flag at their start (fixed (#1162): the original left it set after a SerialStop outside a transfer, so the next block stopped at once).

◆ c_buffcount()

ULONG c_buffcount ( void )

SerialGot: the number of bytes waiting in the receive ring.

Fixed (#802): the count the help text promises ("returns num chars in serial buffer"); the original returned -1 when a byte was waiting, else 0.

Returns
d0: the count, 0-255 (a word)

◆ c_buffcount2()

ULONG c_buffcount2 ( void )

SerialWait: waits for a byte and reads it (SerialRead).

Returns
d0: the byte (fixed (#797): alone, as SerialRead)

◆ c_buffpos()

ULONG c_buffpos ( void )

SerialProgress: the remaining count of the last send (or receive) block.

Returns
d0: the count

◆ c_closeserial()

void c_closeserial ( void )

SerialClose (and finit): restores the vectors, CIA-B PRA $FF and the interrupts.

Fixed (#790): only RBF and TBE are switched off, and those of them that were on at SerialOpen on again; the original switched every interrupt off (INTENA $7FFF) and then on those that were on at SerialOpen, with the master bit. Nothing if not open.

◆ c_flushser()

void c_flushser ( void )

SerialFlush: reads until the receive buffer is empty.

Opens the port when it is closed (fixed (#792): the original never did).

◆ c_info()

ULONG c_info ( void )

SerialVersion: the version of the library.

Returns
d0: 1

◆ c_openserial()

void c_openserial ( void )

SerialOpen: installs the library's receive and transmit interrupts (see openserial).

The vectors at VBR + $64/$74 (fixed (#804): the original wrote them at $64/$74 whatever the VBR of a 68010+ was). BUG(orig) (#791): the original put the old ones into the operands of two JMPs without clearing the instruction cache (the C port keeps them in variables).

◆ c_openserial2()

void c_openserial2 ( ULONG rate)

SerialOpen baudrate: SerialBaud baudrate, then SerialOpen.

Parameters
rated0: the baud rate

◆ c_readint()

ULONG c_readint ( void )

The receive interrupt (level 5): SERDATR's byte into the ring.

Fixed (#1160): a byte that does not fit (255 unread bytes) is dropped; the original stored every byte, so with 256 unread ones rend met rbig and the ring counted as empty.

Returns
d0: 1 = RBF handled (RTE), 0 = not ours (on to the old vector)

◆ c_readlong()

ULONG c_readlong ( void )

SerialReadLong: reads a long, the low byte first.

Waits for four bytes; the first is the low byte (the mirror of SerialWriteLong). Fixed (#794): the original never returned (the loop counter was taken back from the stack every time: it read bytes without end) and rotated the long the wrong way (ROL). Opens the port when it is closed (fixed (#792): the original always ran SerialOpen's code).

Returns
d0: the long

◆ c_readser()

ULONG c_readser ( void )

SerialRead: the next received byte.

Fixed (#797): the byte alone; the original kept the upper word of d0 at the call in the result (a byte $FF with $FFFF there read as -1).

Returns
d0: the byte (0-255), -1 if the buffer is empty

◆ c_readserialstring()

ULONG c_readserialstring ( const UBYTE * sbuf)

SerialReadString: received bytes up to a 0, at a3.

Stores up to and including the 0, a3 ends on the 0 (fixed, #795: the original left it behind the 0). Fixed (#796): it returns normally and counts every call from 0 (the original reset the count only when the port was open, and there it returned to the d0 of the call, which it had pushed). Fixed (#797): the loop ends at a 0 (the original only if the upper word of d0 at the call was 0 and no wait came before). Opens the port when it is closed (fixed (#793): the original called SerialOpen's code only when the port was open). At most as many characters as fit in front of the end of the string work area with the 0 behind them; the rest stays in the ring (fixed (#1161): the original had no limit).

Parameters
sbufa0: strings1lib's init value, the string work area (memlib globalloc: its block length, size + 8, at -4)
Returns
d0: the number of characters (the string's length)

◆ c_sendserialstring()

void c_sendserialstring ( const UBYTE * str,
const ULONG * argstack )

SerialSendString a$: meant to send a string.

Its characters, the length from the a2 stack (MOVE.l -4(a2): a2 unchanged, as in all C ports), no 0 behind them (decided, R10 P2-4: a program that reads with SerialReadString on the other side sends the 0 itself). Fixed (#801): the original sent the low byte of the string's address (with the stop bit) once for every long it read from the a2 stack, down to one with a low byte 0. Opens the port when it is closed (fixed (#793): the original called SerialOpen's code only when the port was open).

Parameters
strd0: the string
argstacka2: the argument stack (the length at -4)

◆ c_serreceive()

void c_serreceive ( ULONG addr,
ULONG len )

SerialReceiveBlock address,length: receives a block byte by byte.

Opens the port when it is closed (fixed (#792): the original never did). The bytes in the ring at the call are the first of the block (fixed (#798): the original threw them away first; SerialFlush before empties the ring). The count is tested before every byte (fixed (#799): the original stored the first byte and counted the rest down to 0, so a length of 1 received without end). SerialStop ends it after the next byte with a normal return (fixed (#803): the original popped its return address into d7 and returned to the long above it).

Parameters
addrd0: the address
lend1: the length

◆ c_sersend()

void c_sersend ( ULONG addr,
ULONG len )

SerialSendBlock address,length: sends a block byte by byte.

SerialStop ends it; SerialProgress gives the remaining count. Opens the port when it is closed (fixed (#792): the original never did). Fixed (#800): a length of 0 or less sends nothing (the remaining count -1, as after a whole block); the original sent the first byte before it looked at the length.

Parameters
addrd0: the address
lend1: the length

◆ c_setbaud()

void c_setbaud ( ULONG rate)

SerialBaud rate: sets the baud rate (SERPER = 3546895 / rate - 1, bit 15 cleared).

Rate 0 divides by 0 through ldivlib (a defined result, no defect).

Parameters
rated0: the baud rate (also kept for SerialOpen)

◆ c_showloc()

ULONG c_showloc ( void )

SerialBuffer: the address of the receive ring (256 bytes; its two index words lie in front of it).

Returns
d0: the address

◆ c_writeint()

ULONG c_writeint ( void )

The transmit interrupt (level 1): one word of the ring when SERDATR shows TBE.

Returns
d0: 1 = TBE handled (RTE), 0 = not ours (on to the old vector)

◆ c_writelong()

void c_writelong ( ULONG longword)

SerialWriteLong longword: sends a long, the low byte first.

Fixed (#805): the original sent the low byte, then three times $01 (it rotated the register SerialWrite had changed). Opens the port when it is closed (fixed (#792): the original always ran SerialOpen's code).

Parameters
longwordd0: the long

◆ c_writeser()

void c_writeser ( ULONG value)

SerialWrite byte: puts the byte (with a stop bit) into the transmit ring; TBE is requested when the ring was empty.

Parameters
valued0: the byte (low byte)

◆ getvbr()

ULONG getvbr ( void )
static

◆ info()

void info ( void )

◆ openserial()

ULONG openserial ( ULONG value)
static

◆ readint()

void readint ( void )

◆ readser()

ULONG readser ( void )
static

◆ readvbr()

ULONG readvbr ( void )
static

◆ riseriallib_libfinit()

void riseriallib_libfinit ( void )

◆ vector()

volatile ULONG * vector ( ULONG a)
static

◆ writeint()

void writeint ( void )

◆ writeser()

ULONG writeser ( ULONG value)
static

Variable Documentation

◆ baudrate

ULONG baudrate = 2400
static

◆ big

volatile UWORD big

◆ buf

UBYTE buf[1024]

◆ bufflength

ULONG bufflength
static

◆ buffstart

ULONG buffstart
static

◆ end

volatile UWORD end

◆ numchars

ULONG numchars
static

◆ oldint

UWORD oldint ( void )
static

◆ openflag

UWORD openflag
static

◆ quitflag

volatile ULONG quitflag
static

◆ [struct]

struct { ... } rd

◆ riser_ciab

volatile UBYTE* riser_ciab = (volatile UBYTE *)0xbfd000

◆ riser_custom

volatile UBYTE* riser_custom = (volatile UBYTE *)0xdff000

◆ riser_oldint1

ULONG riser_oldint1 = 0xffffffff

◆ riser_oldint5

ULONG riser_oldint5 = 0xffffffff

◆ server

const UBYTE server = 1
static

◆ vecbase

ULONG vecbase
static

◆ version

const char version[] = "$VER: Serial-Library v1.0 (7.3.1994)"
static

◆ [struct]

struct { ... } wr