|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
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)" |
| #define BL_INTHANDLER | ( | entry, | |
| cfunc, | |||
| old ) |
| #define CIABPRA (*riser_ciab) |
| #define CUSTOMREG | ( | type, | |
| off ) |
| #define INTENA CUSTOMREG(UWORD, 0x9a) |
| #define INTENAR CUSTOMREG(UWORD, 0x1c) |
| #define INTREQ CUSTOMREG(UWORD, 0x9c) |
| #define SERCLOCK 3546895UL |
| #define SERDAT CUSTOMREG(UWORD, 0x30) |
| #define SERDATR_LO CUSTOMREG(UBYTE, 0x19) /* the received byte */ |
| #define SERPER CUSTOMREG(UWORD, 0x32) |
| void _abortxfer | ( | void | ) |
| void _buffcount | ( | void | ) |
| void _buffcount2 | ( | void | ) |
| void _buffpos | ( | void | ) |
| void _closeserial | ( | void | ) |
| void _flushser | ( | void | ) |
| void _openserial | ( | void | ) |
| void _openserial2 | ( | void | ) |
| void _readlong | ( | void | ) |
| void _readser | ( | void | ) |
| void _readserialstring | ( | void | ) |
| void _sendserialstring | ( | void | ) |
| void _serreceive | ( | void | ) |
| void _sersend | ( | void | ) |
| void _setbaud | ( | void | ) |
| void _showloc | ( | void | ) |
| void _writelong | ( | void | ) |
| void _writeser | ( | void | ) |
| BL_INTHANDLER | ( | readint | , |
| c_readint | , | ||
| riser_oldint5 | ) |
| BL_INTHANDLER | ( | writeint | , |
| c_writeint | , | ||
| riser_oldint1 | ) |
| 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).
| 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.
| ULONG c_buffcount2 | ( | void | ) |
SerialWait: waits for a byte and reads it (SerialRead).
| ULONG c_buffpos | ( | void | ) |
SerialProgress: the remaining count of the last send (or receive) block.
| 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.
| 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).
| ULONG c_info | ( | void | ) |
SerialVersion: the version of the library.
| 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).
| void c_openserial2 | ( | ULONG | rate | ) |
SerialOpen baudrate: SerialBaud baudrate, then SerialOpen.
| rate | d0: the baud rate |
| 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.
| 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).
| 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).
| 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).
| sbuf | a0: strings1lib's init value, the string work area (memlib globalloc: its block length, size + 8, at -4) |
| 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).
| str | d0: the string |
| argstack | a2: the argument stack (the length at -4) |
| 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).
| addr | d0: the address |
| len | d1: the length |
| 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.
| addr | d0: the address |
| len | d1: the length |
| 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).
| rate | d0: the baud rate (also kept for SerialOpen) |
| ULONG c_showloc | ( | void | ) |
SerialBuffer: the address of the receive ring (256 bytes; its two index words lie in front of it).
| ULONG c_writeint | ( | void | ) |
The transmit interrupt (level 1): one word of the ring when SERDATR shows TBE.
| 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).
| longword | d0: the long |
| 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.
| value | d0: the byte (low byte) |
|
static |
| void info | ( | void | ) |
|
static |
| void readint | ( | void | ) |
|
static |
|
static |
| void riseriallib_libfinit | ( | void | ) |
|
static |
| void writeint | ( | void | ) |
|
static |
|
static |
| volatile UWORD big |
| UBYTE buf[1024] |
|
static |
|
static |
| volatile UWORD end |
|
static |
|
static |
|
static |
|
static |
| struct { ... } rd |
| volatile UBYTE* riser_ciab = (volatile UBYTE *)0xbfd000 |
| volatile UBYTE* riser_custom = (volatile UBYTE *)0xdff000 |
| ULONG riser_oldint1 = 0xffffffff |
| ULONG riser_oldint5 = 0xffffffff |
|
static |
|
static |
|
static |
| struct { ... } wr |