// Standard BCPL header

// Modified by Martin Richards (c) May 2004

/*
11/02/04 MR
Added binwrch, removed packstring, unpackstring and dqpkt
21/10/02 MR
Made compatible with libhdr of the standard BCPL distribution
*/


// Globals used in the standard (single threaded) BCPL Cintcode System
GLOBAL {
globsize:            0
start:               1
stop:                2
sys:                 3  //SYSLIB   MR 18/7/01
clihook:             4
muldiv:              5  //SYSLIB   changed to G:5 MR 6/5/05
changeco:            6  //SYSLIB   MR 6/5/04
currco:              7
colist:              8

rootnode:            9  // For compatibility with native BCPL

result2:            10
returncode:         11
cis:                12
cos:                13
currentdir:         14
level:              15
longjump:           16
createco:           17
deleteco:           18
callco:             19
cowait:             20
resumeco:           21
initco:             22
startco:            23
globin:             24
getvec:             25

freevec:            27
abort:              28
sysabort:           29
packstring:         30
unpackstring:       31
getword:            32
putword:            33
randno:             34
setseed:            35
sardch:             36
sawrch:             37
rdch:               38
binrdch:            39
unrdch:             40
wrch:               41
binwrch:            42
deplete:            43  // MR 10/1/03
readwords:          44
writewords:         45
initio:             46
splitname:          47
findinput:          48
findoutput:         49
findinoutput:       50  // MR 25/3/01
findupdate:         51
findstream:         52
pathfindinput:      53  // MR 8/5/03
getremipaddr:       54
settimeout:         55  // MR 26/3/03
selectinput:        56
selectoutput:       57
input:              58
output:             59
endread:            60
endwrite:           61
endstream:          62
note:               63
point:              64
rewindstream:       65
appendstream:       66
stepstream:         67
setrecordlength:    68
recordpoint:        69
recordnote:         70
get.record:         71
put.record:         72
get.index.record:   73  // Not yet implemented
put.index.record:   74  // Not yet implemented
copyobj:            75
deletefile:         76
renamefile:         77
freeobj:            78
copydir:            79
locatedir:          80
locateobj:          81
createdir:          82
readn:              83
newline:            84
writed:             85
writen:             86
writehex:           87
writeoct:           88
writes:             89
writet:             90
writeu:             91
writez:             92
get.textblib:       93  //BLIB version
get.text:           93  //BLIB overridden version
writef:             94  //BLIB
sawritef:           95
capitalch:          96
compch:             97
compstring:         98
copystring:         99
string.to.number:  100
str2numb:          101
rdargs:            102
rditem:            103
findarg:           104
loadseg:           105
unloadseg:         106
callseg:           107
datstring:         108
datstamp:          109
dat.to.strings:    110
string.to.dat:     111
setbit:            112
testbit:           113
copy.words:        114
clear.words:       115
copy.bytes:        116
setlogname:        117
getlogname:        118
intflag:           119

//##### CLI uses globals 133 - 149 #####
}

MANIFEST {
ug = 200  // First user global

B2Wsh           = 2
//B2Wsh=3  // for a 64 bit implementation
bytesperword    = 1<<B2Wsh
bitsperbyte	= 8
bitsperword	= bitsperbyte * bytesperword
mcaddrinc	= bytesperword
minint          = 1<<(bitsperword-1)  // = #x80....0
maxint          = minint - 1          // = #x7F....F

tickspersecond	= 50 // 1000   MR 19/7/01

endstreamch	= -1  // ch returned at EOF
timeoutch	= -2  // ch returned when none available before timeout
pollingch	= -3  // ch returned when none available when polling

// Object module format types

t_hunk  = 1000 // A hunk in ASCII hex
t_reloc = 1001
t_end   = 1002
t_bhunk = 3000 // A hunk in binary

globword  = #xEFEF0000
stackword = #xABCD1234
sectword  = #x0000FDDF
entryword = #x0000DFDF

// co-routine stackbase offsets

co_pptr   = 0
co_parent = 1
co_list   = 2
co_fn     = 3
co_size   = 4
co_c      = 5

InitObj  = 0  // Initialisation and closing methods for objects
CloseObj = 1

// rootnode manifests

rootnodeaddr = 100  // MR 21/10/02 for compatibility with Cintpos
//rootnode = rootnodeaddr

rtn_tasktab         =     0
rtn_devtab          =     1
rtn_tcblist         =     2
rtn_crntask         =     3
rtn_blklist         =     4
rtn_tallyv          =     5

rtn_clkintson       =     6
rtn_lastch          =     7    // For sadebug polling input
rtn_insadebug       =     8    // Looked at by ttyin device

rtn_bptaddr         =     9    // Breakpoint addresses      ) MR 20/9/02
rtn_bptinstr        =    10    // Breakpoint instructions   )

rtn_clwkq           =    11
rtn_membase         =    12
rtn_memsize         =    13
rtn_info            =    14
rtn_sys             =    15
rtn_boot            =    16  // BOOT code
rtn_klib            =    17  // KLIB code segments
rtn_blib            =    18  // BLIB code segments
rtn_keyboard        =    19
rtn_screen          =    20
rtn_vecstatsv       =    21
rtn_dumpflag        =    22  // =TRUE for memory dump to DUMP.mem
rtn_envlist         =    23  // List of logical name value pairs
                             // used by setlogval and getlogval
rtn_abortcode       =    24  // Latest reason for leaving the interpreter
rtn_context         =    25  // Context of DUMP.mem
                             // 1 SIGINT, 2 SIGSEGV,
                             // 3 fault in BOOT or standalone debug
                             // 4 dump by user calling sys(Sys_quit, -2)
                             // 5 dump caused by non zero user fault code
                             // 6 dump requestested from standalone debug
rtn_lastp      = 26    // Latest setting of p pointer at SIGINT or SIGSEGV
rtn_lastg      = 27    // Latest setting of p pointer at SIGINT or SIGSEGV
rtn_idletcb    = 28    // The IDLE TCB (for debugging)
rtn_adjclock   = 29    // Real time clock adjustment

rtn_upb            =     40     // Leave some unused entries

// SYS functions
Sys_setcount        = (-1)
Sys_quit            =   0
Sys_rti             =   1
Sys_saveregs        =   2
Sys_setst           =   3
Sys_tracing         =   4
Sys_watch           =   5
Sys_tally           =   6
Sys_interpret       =   7

Sys_sardch          =  10
Sys_sawrch          =  11
Sys_read            =  12
Sys_write           =  13
Sys_openread        =  14
Sys_openwrite       =  15
Sys_close           =  16
Sys_deletefile      =  17
Sys_renamefile      =  18

Sys_getvec          =  21
Sys_freevec         =  22
Sys_loadseg         =  23
Sys_globin          =  24
Sys_unloadseg       =  25
Sys_muldiv          =  26
Sys_intflag         =  28
Sys_setraster       =  29
Sys_cputime         =  30
Sys_filemodtime     =  31
Sys_setprefix       =  32
Sys_getprefix       =  33
Sys_graphics        =  34       // Not implemented

Sys_seek            =  38       // MR 10/11/01
Sys_tell            =  39       // MR 10/11/01
Sys_waitirq         =  40       // MR  4/02/02
Sys_lockirq         =  41       // MR 24/02/03
Sys_unlockirq       =  42       // MR 24/02/03
Sys_devcom          =  43       // MR  4/02/02
Sys_ftime           =  44       // MR  5/02/02
Sys_usleep          =  45       // MR  5/02/02
Sys_filesize        =  46       // MR 15/03/02
Sys_openreadwrite   =  47       // MR 19/03/02

Sys_getsysval       =  48       // MR 18/11/02
Sys_putsysval       =  49       // MR 18/11/02
Sys_shellcom        =  50       // MR 13/01/03
Sys_getpid          =  51       // MR  7/10/03
Sys_dumpmem         =  52       // MR 29/10/03 Used only in BOOT.b
Sys_callnative      =  53       // MR 24/04/04

bootregs = 11     // registers used by cintpos to start BOOT
klibregs = 21     // registers used by BOOT to start KLIB
saveregs = 31     // The registers are saved here on interrupt
isrregs  = 41     // Registers for the interrupt service routine

id_inscb	= #x81  // MR 21/10/02
id_outscb	= #x82  // MR 21/10/02
id_inoutscb	= #x83  // MR 21/10/02

scbt_net     =  2  // Non interactive TCP/IP stream
scbt_file    =  1  // Non interactive disc file stream
scbt_ram     =  0  // Non interactive RAM stream
scbt_console = -1  // Interactive -- output triggered by '*n' etc
scbt_mbx     = -2  // Interactive MBX stream
scbt_tcp     = -3  // Interactive TCP/IP stream

scb_id       = 0   // id_inscb, id_outscb or id_inoutscb
scb_type           // <=0 interactive stream, >0 block file
scb_task           // 0 or the task associated with this stream
scb_buf            // 0 or the byte buffer for this stream
scb_pos            // position of next character to be transferred
scb_end            // number of valid bytes in the buffer or -1
scb_rdfn           // zero or function to replenish the buffer
scb_wrfn           // zero or function to deplete the buffer
scb_endfn          // zero or function to close down the stream
scb_block          // Current block number of a disc file
scb_write          // Buf written to but not yet written to disc
scb_bufend         // Size of buf in bytes
scb_lblock         // Number of last block of a disc file
scb_ldata          // Bytes in last block of a disc file
scb_blength        // Length of a disc block in bytes (typically 4096)
scb_reclen         // Record length in bytes for some files
scb_fd             // File or mailbox descriptor MR 18/4/02
scb_timeout        // The stream timeout value in milli-seconds MR 26/3/02
                   // = 0  means no time out is to be applied
                   // =-1  only transfer data that is immediately possible
scb_size
scb_upb = scb_size-1
}

