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

Functions

void finalscheck (void)
 finalscheck ($C300) - at program end a7 must be where it was at init (ostack).
void retchk (void)
 retchk ($C305) - Return: the Gosub frame (return address, "gS") must be on the stack; pop it and return there.
void nextchkw (void)
 nextchkw/nextchkl ($C306/$C307) - Next: the For frame ("fO") must be on the stack (at 12(a7) for a word loop, 16(a7) for a long one).
void nextchkl (void)
void stackchk (void)
 stackchk ($C308) - out of stack: a7 below maxstack (not while in supervisor mode, supernest <> 0).
void arrerr (void)
void maxerr (void)
void gosuper (void)
 gosuper ($C30B) - the start of a SetInt routine (the compiler calls it there, in front of the routine's TRAP #2, only with runtime error checking): no stack check (supernest + 1), and the CPU's TRAP #0-#5 vectors lead to the program's trap handler while the routine runs.
void gouser (void)
 gouser ($C30C) - the end of a SetInt routine: supernest - 1, and the six vectors saved by gosuper back into the CPU's table (fixed (#1069), see gosuper). The saved vectors are taken from the stack. Keeps all registers.
void sarraychk (void)
void aarraychk (void)
void datachk (void)
void bmodechk (void)
 bmodechk/amodechk ($C311/$C312) - Blitz / Amiga mode only: the caller has just tested the mode flag (N set = Blitz mode).
void amodechk (void)
void casechkw (void)
 casechkw/casechkl ($C313/$C314) - End Select, Case, Default: the Select frame ("sE") must be on the stack (6(a7) / 8(a7)).
void casechkl (void)
void currentchk (void)
void ltobover (void)
void wtobover (void)
void ltowover (void)
void qtobover (void)
void ftobover (void)
void ftowover (void)
void ftolover (void)
void getvbr (void)
void getcpu (void)
void runerrlib_codeinit (void)
void ctrlcend (void)
 ctrlcend ($C321) - end the program with return code 20 (fixed, #43: Ctrl-C at an input or output on the console).
static void codefinit (void)
 Library finit: restore the task's trap handler.
void data (void)
static void ltob (LONG v)
static void ltow (LONG v)
static void ltobover_c (LONG v)
 ltobover ($C316) - long to byte: -128..127.
static void wtobover_c (LONG v)
 wtobover ($C317) - word to byte (CMP.w): -128..127.
static void ltowover_c (LONG v)
 ltowover ($C318) - long to word: -32768..32767.
static void qtobover_c (ULONG v)
 qtobover ($C319) - quick (16.16 fixed point) to byte: the integer part is the upper word (SWAP d0:CMP.w), -128..127.
static LONG spfix (ULONG x, APTR base, UBYTE *v)
static void ftobover_c (ULONG f, APTR ffp)
 ftobover ($C31A) - float to byte: SPFix must not overflow and the integer must be -128..127.
static void ftowover_c (ULONG f, APTR ffp)
 ftowover ($C31B) - float to word: SPFix must not overflow and the integer must be -32768..32767.
static void ftolover_c (ULONG f, APTR ffp)
 ftolover ($C31C) - float to long: SPFix must not overflow (V flag).
static void sarraychk_c (ULONG d)
 sarraychk ($C30E) - an array dimension (its highest index) must be < 65535.
static void aarraychk_c (ULONG d)
 aarraychk ($C30F) - as sarraychk, the dimension in d1 (the check of each dimension of Dim and Dim List).
static void datachk_c (ULONG type)
 datachk ($C310) - Read: the data item at a3 must be "D" + type.
static void currentchk_c (APTR item)
 currentchk ($C315) - a list command needs a current item.
static ULONG getvbr_c (void)
 getvbr ($C31D) - the vector base register as read by the init.
static UWORD getcpu_c (void)
 getcpu ($C31E) - the CPU type.
static void codeinit_c (UBYTE *sp, ULONG stack)
 Library init: stack limits, trap handler, CPU and VBR.

Variables

UWORD cpu_
UWORD supernest
ULONG vbr_
UBYTE * ostack
UBYTE * maxstack
APTR oldtrap
struct Task * ourtask
const char overmess []
const char sarraymess []
const char datamess []
const char currentmess []
char trapper []

Function Documentation

◆ aarraychk()

void aarraychk ( void )

◆ aarraychk_c()

void aarraychk_c ( ULONG d)
static

aarraychk ($C30F) - as sarraychk, the dimension in d1 (the check of each dimension of Dim and Dim List).

Fixed (#1037): refuses 65535 too, as sarraychk.

Errors: "Array Dimension out of Range".

Parameters
dd1: the dimension

◆ amodechk()

void amodechk ( void )

◆ arrerr()

void arrerr ( void )

◆ bmodechk()

void bmodechk ( void )

bmodechk/amodechk ($C311/$C312) - Blitz / Amiga mode only: the caller has just tested the mode flag (N set = Blitz mode).

Errors: "Command only available in BLITZ mode!" / "... AMIGA mode!".

◆ casechkl()

void casechkl ( void )

◆ casechkw()

void casechkw ( void )

casechkw/casechkl ($C313/$C314) - End Select, Case, Default: the Select frame ("sE") must be on the stack (6(a7) / 8(a7)).

Errors: "End Select/Case/Default without Select".

◆ codefinit()

void codefinit ( void )
static

Library finit: restore the task's trap handler.

The handler the program started with: since #1069 also the end of the handlers of debuglib, rundebuglib and errtraplib, which init after runerrlib and put theirs in front (debuglib and rundebuglib leave theirs until here, for SetInt routines that run until intlib's finit).

◆ codeinit_c()

void codeinit_c ( UBYTE * sp,
ULONG stack )
static

Library init: stack limits, trap handler, CPU and VBR.

maxstack = the lowest allowed stack pointer (with 1K reserve), ostack = the stack pointer expected at the end; trapper becomes the task's tc_TrapCode (CPU exceptions become runtime errors "GURU! - ..."); the CPU type from AttnFlags and, from a 68010 on, the VBR (MOVEC in supervisor state). The original returns d2 = VBR (and changes d0-d1/a0/a6); the thunk keeps everything.

Fixed (intended deviation, #42): the original reads the VBR only from a 68020 on, though a 68010 has one too.

Parameters
spa0: the stack pointer at entry (pointing to the return address; the thunk computes it)
stackd2: the stack size

◆ ctrlcend()

void ctrlcend ( void )

ctrlcend ($C321) - end the program with return code 20 (fixed, #43: Ctrl-C at an input or output on the console).

Called by inputoutputlib's Ctrl-C checks, which only error check code calls. The program's return address (the long above the stack of its main code: ostack + 4, the level finalscheck compares) is replaced by rc20, then exitslib's endjmp ends the program as End does: the finits run and the end code's moveq #0,d0:rts returns to rc20, which sets the return code 20 (that of a C program after Ctrl-C) and goes on to the caller. Without a change of the end code every program has, which would change every executable. Assembler: it works on the program's stack. Does not return.

◆ currentchk()

void currentchk ( void )

◆ currentchk_c()

void currentchk_c ( APTR item)
static

currentchk ($C315) - a list command needs a current item.

Errors: "No Current List Item".

Parameters
itema2: the current item (0 = none)

◆ data()

void data ( void )

◆ datachk()

void datachk ( void )

◆ datachk_c()

void datachk_c ( ULONG type)
static

datachk ($C310) - Read: the data item at a3 must be "D" + type.

a3 is advanced over both bytes. (The original leaves the "D" in d1.b, the thunk keeps d1.)

Errors: "Data type mismatch".

Parameters
typed0.b: the type the Read expects

◆ finalscheck()

void finalscheck ( void )

finalscheck ($C300) - at program end a7 must be where it was at init (ostack).

Errors: "Stack Error on Exit - Unterminated Gosub or For?".

◆ ftobover()

void ftobover ( void )

◆ ftobover_c()

void ftobover_c ( ULONG f,
APTR ffp )
static

ftobover ($C31A) - float to byte: SPFix must not overflow and the integer must be -128..127.

Errors: "OverFlow Error".

Parameters
fd0: the FFP float
ffpa6: mathffp.library (from ffplib)

◆ ftolover()

void ftolover ( void )

◆ ftolover_c()

void ftolover_c ( ULONG f,
APTR ffp )
static

ftolover ($C31C) - float to long: SPFix must not overflow (V flag).

Errors: "OverFlow Error".

Parameters
fd0: the FFP float
ffpa6: mathffp.library (from ffplib)

◆ ftowover()

void ftowover ( void )

◆ ftowover_c()

void ftowover_c ( ULONG f,
APTR ffp )
static

ftowover ($C31B) - float to word: SPFix must not overflow and the integer must be -32768..32767.

Errors: "OverFlow Error".

Parameters
fd0: the FFP float
ffpa6: mathffp.library (from ffplib)

◆ getcpu()

void getcpu ( void )

◆ getcpu_c()

UWORD getcpu_c ( void )
static

getcpu ($C31E) - the CPU type.

The number of the highest AttnFlags bit of 68010..68040.

Returns
d0.w: 0 = 68000 ... 4 = 68040; the upper word is kept

◆ getvbr()

void getvbr ( void )

◆ getvbr_c()

ULONG getvbr_c ( void )
static

getvbr ($C31D) - the vector base register as read by the init.

Keeps d0-d1/a1 (the thunk moves the result to a0).

Fixed (intended deviation, #42): also on a 68010 (the original gives 0 there, though a 68010 has a VBR).

Returns
a0: the VBR (0 on a 68000)

◆ gosuper()

void gosuper ( void )

gosuper ($C30B) - the start of a SetInt routine (the compiler calls it there, in front of the routine's TRAP #2, only with runtime error checking): no stack check (supernest + 1), and the CPU's TRAP #0-#5 vectors lead to the program's trap handler while the routine runs.

Fixed (#1069): debuglib, rundebuglib and errtraplib take the traps of their program through its task's trap handler (tc_TrapCode), not the CPU's vector table, which belongs to the whole machine. exec passes only a trap of user mode to tc_TrapCode; one in supervisor mode (an interrupt) is a dead end. So gosuper saves the six vectors on the stack (24 bytes, the vector of TRAP #0 first, left there for gouser) and sets stubs that hand the trap to the program's handler as exec does for user mode (the trap number as a long on the stack, then the exception frame). No other task runs while an interrupt routine runs, and nested interrupts restore in reverse order, so nothing else sees the stubs. rundebuglib reads the saved vectors there (its more2). The original only counted supernest; the CPU's vectors were the libraries' all the time. Keeps all registers.

◆ gouser()

void gouser ( void )

gouser ($C30C) - the end of a SetInt routine: supernest - 1, and the six vectors saved by gosuper back into the CPU's table (fixed (#1069), see gosuper). The saved vectors are taken from the stack. Keeps all registers.

◆ ltob()

void ltob ( LONG v)
static

◆ ltobover()

void ltobover ( void )

◆ ltobover_c()

void ltobover_c ( LONG v)
static

ltobover ($C316) - long to byte: -128..127.

Errors: "OverFlow Error".

Parameters
vd0: the value

◆ ltow()

void ltow ( LONG v)
static

◆ ltowover()

void ltowover ( void )

◆ ltowover_c()

void ltowover_c ( LONG v)
static

ltowover ($C318) - long to word: -32768..32767.

Errors: "OverFlow Error".

Parameters
vd0: the value

◆ maxerr()

void maxerr ( void )

◆ nextchkl()

void nextchkl ( void )

◆ nextchkw()

void nextchkw ( void )

nextchkw/nextchkl ($C306/$C307) - Next: the For frame ("fO") must be on the stack (at 12(a7) for a word loop, 16(a7) for a long one).

Errors: "Next without For".

◆ qtobover()

void qtobover ( void )

◆ qtobover_c()

void qtobover_c ( ULONG v)
static

qtobover ($C319) - quick (16.16 fixed point) to byte: the integer part is the upper word (SWAP d0:CMP.w), -128..127.

Errors: "OverFlow Error".

Parameters
vd0: the quick value

◆ retchk()

void retchk ( void )

retchk ($C305) - Return: the Gosub frame (return address, "gS") must be on the stack; pop it and return there.

Errors: "Return without Gosub".

◆ runerrlib_codeinit()

void runerrlib_codeinit ( void )

◆ sarraychk()

void sarraychk ( void )

◆ sarraychk_c()

void sarraychk_c ( ULONG d)
static

sarraychk ($C30E) - an array dimension (its highest index) must be < 65535.

An array or list has at most 65535 elements: arrmult counts the elements of a dimension as a word (highest index + 1). Fixed (#1037): the highest index 65535 is refused too (the original refused only 65536 and more; 65535 gave 0 elements, every access outside the block).

Errors: "Array Dimension out of Range".

Parameters
dd0: the dimension

◆ spfix()

LONG spfix ( ULONG x,
APTR base,
UBYTE * v )
static

◆ stackchk()

void stackchk ( void )

stackchk ($C308) - out of stack: a7 below maxstack (not while in supervisor mode, supernest <> 0).

Errors: "Out of Stack Space".

◆ wtobover()

void wtobover ( void )

◆ wtobover_c()

void wtobover_c ( LONG v)
static

wtobover ($C317) - word to byte (CMP.w): -128..127.

Errors: "OverFlow Error".

Parameters
vd0.w: the value

Variable Documentation

◆ cpu_

UWORD cpu_
extern

◆ currentmess

const char currentmess[]

◆ datamess

const char datamess[]

◆ maxstack

UBYTE* maxstack
extern

◆ oldtrap

APTR oldtrap
extern

◆ ostack

UBYTE* ostack
extern

◆ ourtask

struct Task* ourtask
extern

◆ overmess

const char overmess[]
extern

◆ sarraymess

const char sarraymess[]

◆ supernest

UWORD supernest

◆ trapper

void trapper ( )
extern

◆ vbr_

ULONG vbr_
extern