/*
 *          s y s / s y s d e f s . h
 *
 *  Definition of the offsets of system variables used by
 *  QDOS, SMS2, SMSQ and SMSQ/E. 
 *
 *  There are two basic sources of the names that are used
 *  for these system variables, each of which has its own
 *  naming convention for them:
 *
 *  1)  QDOS/SMS Reference Manual       (from Jochen Merz)
 *
 *      This is the more current documentation that is kept
 *      up-to-date with the changes introduced in the new
 *      QDOS clone operating systems such as SMS2, SMSQ and
 *      SMSQ/E.
 *
 *  2)  QL Technical Guide              (from QJump)
 *
 *      This is the original QL documentation that has been
 *      available since early in the life of the QL.  It
 *      does not, however, reflect all the advances that
 *      have taken place since the QL was launched.  This
 *      means that this is only a subset of those defined
 *      in the Jochen Merz document.
 *
 *  This file contains only #define statements, so it is
 *  suitable for inclusion into both C files, and also into
 *  pre-processed assembler files
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  25 Oct 95   DJW   - First version
 */

#ifndef _SYS_SYSDEFS_H
#define _SYS_SYSDEFS_H

/***************************************************
 *
 *      QDOS/SMS REFERENCE MANUAL
 *
 ***************************************************/

#define SYS_IDNT        0x00            /* LONG:  System type identifier */
#define     SYSID_QL        0xd2540000  /*          QL (QDOS) identifier */
#define     SYSID_AT        0x53324154  /*          SMS2 atari 'S2AT' */
#define     SYSID_SMSQ      0x534d5351  /*          SMSQ(/E)   'SMSQ' */
#define SYS_CHPB        0x04            /* LONG:  Common HeaP Base */
#define SYS_CHPF        0x08            /* LONG:  Common HeaP Free space pointer */
#define SYS_FSBB        0x0c            /* LONG:  Fileing system Slave Block are Base */
#define SYS_SBAB        0x10            /* LONG:  QL Suberbasic Area Base */
#define SYS_TPAB        0x14            /* LONG:  Transient Program Area Base */
#define SYS_TPAF        0x18            /* LONG:  Transient Program Area Free space pointer */
#define SYS_RPAB        0x1c            /* LONG:  Resident Procedure Area Base */
#define SYS_RAMT        0x20            /* LONG:  user RAM Top (+1) */
#define SYS_MXFR        0x24            /* LONG:  Maximum return from free memory call [SMS] */
#define SYS_RTC         0x28            /* LONG:  real time (seconds) [SMS] */
#define SYS_RTCF        0x2c            /* WORD:  real time fractional, count down [SMS] */
#define SYS_RAND        0x2e            /* WORD:  RANDom number */
#define SYS_PICT        0x30            /* WORD:  Polling Interval CounT */
#define SYS_DTYP        0x32            /* BYTE:  Display TYPe */
#define     SY_MONITOR      0           /*          Normal */
#define     SY_TV625        1           /*          TV 625 lines */
#define     SY_TV525        2           /*          TV 525 lines */
#define SYS_DFRZ        0x33            /* BYTE:  Display FroZen (T or F) */
#define SYS_QLMR        0x34            /* BYTE:  QL Master chip Register */
#define SYS_QLIR        0x35            /* BYTE:  QL Master Interupt Register */
#define SYS_RSHD        0x36            /* BYTE:  true to reschedule [SMS] */
#define SYS_NNNR        0x37            /* BYTE:  Netowrk Node NumbeR */
#define SYS_EXIL        0x38            /* LONG:  EXternal Interrupt action List */
#define SYS_POLL        0x3c            /* LONG:  POLled action List */
#define SYS_SHDL        0x40            /* LONG:  ScHeDuler loop action List */
#define SYS_IODL        0x44            /* LONG:  IO Driver list */
#define SYS_FSDL        0x48            /* LONG:  Filing System Driver List */
#define SYS_CKYQ        0x4c            /* LONG:  Current KeYboard Queue */
#define SYS_ERTB        0x50            /* LONG:  Exception Redirection Table Base */
#define SYS_SBRP        0x54            /* LONG:  Slave Block Running Pointer */
#define SYS_SBTB        0x58            /* LONG:  Slave Block Table Base */
#define SYS_SBTT        0x5c            /* LONG:  Slave Block Table Top */
#define SYS_JBTG        0x60            /* WORD:  next JoB TaG */
#define SYS_JBTP        0x62            /* WORD:  highest JoB in table (ToP) */
#define SYS_JBPT        0x64            /* LONG:  current JoB PoinTer */
#define SYS_JBTB        0x68            /* LONG:  JoB Table Base */
#define SYS_JBTT        0x6c            /* LONG:  JoB Table Top */
#define SYS_CHTG        0x70            /* WORD:  next CHannel TaG */
#define SYS_CHTP        0x72            /* WORD:  highest CHannel in table (ToP one) */
#define SYS_CHPT        0x74            /* LONG:  CHannel Table PoinTer */
#define SYS_CHTB        0x78            /* LONG:  CHannel Table Base */
#define SYS_CHTT        0x7c            /* LONG:  CHannel Table Top */
#define SYS_FRBL        0x80            /* LONG:  FRee Block List (to be returned to common heap)[SMS] */

#define SYS_CAPS        0x88            /* WORD:  CAPS lock (0=off MSB set = on) */
#define SYS_LCHR        0x8a            /* WORD:  Last CHaracter (for auto-repeat) */
#define SYS_RDEL        0x8c            /* WORD:  Repeat DELay (20ms units) */
#define     SY_RDEL         25
#define SYS_RTIM        0x8e            /* WORD:  Repeat TIMe (20 ms units) */
#define     SY_RTIM         2
#define SYS_RCNT        0x90            /* WORD:  Repeat CouNT (incremented every 20ms) */
#define SYS_SWTC        0x92            /* WORD:  SWiTch queues Character */

#define SYS_QLBP        0x96            /* BYTE:  QL BeePing */

#define SYS_SER1        0x98            /* LONG:  receive channel 1 queue address [QL] */
#define SYS_SER2        0x9c            /* LONG:  receive channel 2 queue address [QL] */
#define SYS_TMOD        0xa0            /* BYTE:  ZX8302 transmit mode (includes baudrate) [QL] */
#define SYS_PTYP        0xa1            /* BYTE:  Processor type */
#define     SY_68000        0x00        /*          68000 or 68008 */
#define     SY_68010        0x10        /*          68010 */
#define     SY_68020        0x20        /*          68020 */
#define     SY_68030        0x30        /*          68030 */
#define     SY_68040        0x40        /*          68040 */
#define     SY_68060        0x60        /*          68060 */
#define SYS_CSUB        0xa2            /* LONG:  subroutine to jump to on capslock */
#define SYS_TMOT        0xa6            /* WORD: ? timeout for switching transmit mode [QL] */
#define SYS_MTYP        0xa7            /* BYTE:  Machine type (if SMSQ(/E) */
#define     SY_ST           0x00        /*          Standard ST */
#define     SY_STBL         0x01        /*          Standard ST with blitter */
#define     SY_MEGA         0x02        /*          Mega ST or ST with RTC */
#define     SY_STACY        0x04        /*          Stacey */
#define     SY_STE          0x06        /*          Standard STE */
#define     SY_STEMEGA      0x08        /*          Mega STE */
#define     SY_GC           0x10        /*          SMSQ/E on Gold Card */
#define     SY_GCH          0x11        /*          SMSQ/E on GC + Hermes */
#define     SY_SGC          0x12        /*          SMSQ/E on Super Gold Card */
#define     SY_SGCH         0x13        /*          SMSQ/E on SGC + Hermes */
#define     SY_FALCON       0x16        /*          Falcon */
#define     SY_TT           0x24        /*          Atari TT */
#define     SY_QXL          0x28        /*          QXL */
#define SYS_FMOV        0xa8            /* WORD:  value of switching timeout (two characters ) */
#define SYS_FSTT        0xaa            /* WORD:  flashing cursor status */
#define SYS_PRGD        0xac            /* LONG:  pointer to PRogGram Default */
#define SYS_DATD        0xb0            /* LONG:  pointer to DATa Default */
#define SYS_DSTS        0xb4            /* LONG:  pointer to DeSTination Default */
#define SYS_THGL        0xb8            /* LONG:  pointer to THinG List */
/*
 *  The following are for FPU support.  The use of the area
 *  has not yet been validated with Tony Tebby, although he
 *  has reserved this area for use by FPU support.
 */
#define SYS_FPHW    0xd0                /* BYTE:  FPU hardware present flag */
#define SYS_FPLK    0xd1                /* BYTE:  FPU register LocK flags */
#define SYS_FPID    0xd4                /* LONG:  FPU active job IDentifier */
#define SYS_FPJB    0xd8                /* LONG:  FPU waiting JoBs list */
#define SYS_FPSV    0xdc                /* LONG:  FPU SaVed jobs list */

#define SYS_MDRN    0xee                /* BYTE:  which microdrive is running [QL] */
#define SYS_MDCT    0xef                /* BYTE:  microdrive run-up run-down counter [QL] */
#define SYS_MDID    0xf0                /* BYTE x 8: drive ID*4 of each microdrive [QL] */
#define SYS_MDST    0xf8                /* BYTE x 8: Status of microdrives */
                                        /*            0 = no pending ops */
#define SYS_FSDD    0x100               /* LONG x 16: Filing System Drive Defintion pointers */
#define SYS_FSDT    0x140               /*            Filing System drive Definition table top */
#define SYS_NFSD        0x10            /*              Max number of Filing System Drive definitions */
#define SYS_FSCH    0x140               /* LONG:  linked list of Filing System CHannel blocks */
#define SYS_XACT    0x144               /* BYTE:  set if XLATE active (QDOS v1.10+) */
#define SYS_XTAB    0x146               /* LONG:  pointer to XLATE table (QDOS v1.10+) */
#define SYS_ERMS    0x14a               /* LONG:  pointer to error messag table (QDOS v1.10+) */

#define SYS_TOP     0x180               /*        TOP of system variables */
                                        /*        (and bottom of Suprvisor Stack */

/***************************************************
 *
 *      QL TECHNICAL GUIDE
 *
 *  And now the QJUMP definitions 
 *
 ***************************************************/

#define SV_IDENT    0x00                /* WORD:  identification word */

#define SV_CHEAP    0x04                /* LONG:  base of common heap area */
#define SV_CHPFR    0x08                /* LONG:  first free space in common heap area */
#define SV_FREE     0x0c                /* LONG:  base of free area */
#define SV_BASIC    0x10                /* LONG:  base of basic area */
#define SV_TRNSP    0x14                /* LONG:  base of transient program area */
#define SV_TRNFR    0x18                /* LONG:  first free space in transient program area */
#define SV_RESPR    0x1c                /* LONG:  base of resident procedure area */
#define SV_RAMT     0x20                /* LONG:  top of ram (+1) */

#define SV_RAND     0x2e                /* WORD:  random number */
#define SV_POLLM    0x30                /* WORD:  count of poll interupts missed */
#define SV_TVMOD    0x32                /* BYTE:  0 if not TV display */
#define SV_SCRST    0x33                /* BYTE:  screen status (0 = active) */
#define SV_MCSTA    0x34                /* BYTE:  current value of display control register */
#define SV_PCINT    0x35                /* BYTE:  current value of interrupt ontrol/mask register */

#define SV_NETNR    0x37                /* BYTE:  network station number */
#define SV_I2LST    0x38                /* LONG:  pointer to list of interrupt 2 drivers */
#define SV_PLIST    0x3c                /* LONG:  pointer to list of polled tasks */
#define SV_SHLST    0x40                /* LONG:  pointer to list of scheduler tasks */
#define SV_DRLST    0x44                /* LONG:  pointer to list of device drivers */
#define SV_DDLST    0x48                /* LONG:  pointer to list of directory device drivers */
#define SV_KEYQ     0x4c                /* LONG:  pointer to a keyboard queue */
#define SV_TRAPV    0x50                /* LONG:  pointer to the trap redirection table */
#define SV_BTPNT    0x54                /* LONG:  pointer to most recent slave block entry */
#define SV_BTBAS    0x58                /* LONG:  pointer to base of slave block table */
#define SV_BTTOP    0x5c                /* LONG:  pointer to top of slave block table */
#define SV_JBTAG    0x60                /* WORD:  current value of job tag */
#define SV_JBMAX    0x62                /* WORD:  highest current job number */
#define SV_JBPNT    0x64                /* LONG:  pointer to current job table entry */
#define SV_JBBAS    0x68                /* LONG:  pointer to base of job table */
#define SV_JBTOP    0x6c                /* LONG:  pointer to top of job table */
#define SV_CHTAG    0x70                /* WORD:  current value of channel tag */
#define SV_CHMAX    0x72                /* WORD:  highest current channel number */
#define SV_CHPNT    0x74                /* LONG:  pointer to last channel checked */
#define SV_CHBAS    0x78                /* LONG:  pointer to base of channel table */
#define SV_CHTOP    0x7c                /* LONG:  pointer to top of channel table */

#define SV_CAPS     0x88                /* WORD:  caps lock */
#define SV_ARBUF    0x8a                /* WORD:  autorepeat buffer */
#define SV_ARDEL    0x8c                /* WORD:  autorepeat delay */
#define SV_ARFRQ    0x8e                /* WORD:  autorepeat 1/freq */
#define SV_ARCNT    0x90                /* WORD:  autorepeat count */
#define SV_CQCH     0x92                /* WORD:  keyboard change queue character */

#define SV_SOUND    0x96                /* WORD:  sound status */
#define SV_SER1C    0x98                /* LONG:  receive channel 1 queue address */
#define SV_SER2C    0x9c                /* LONG:  receive channel 2 queue address */
#define SV_TMODE    0xa0                /* BYTE:  ZX8302 transmit mode (include baudrate) */

#define SV_CSUB     0xa2                /* LONG:  subroutine to jump to on CAPSLOCK */
#define SV_TIMO     0xa6                /* WORD:  timeout for switching transmit mode */
#define SV_TIMOV    0xa8                /* WORD:  value of switching timeout (two characters) */
#define SV_FSTAT    0xaa                /* WORD:  flashing cursor status */

#define SV_MDRUN    0xee                /* BYTE:  which microdrive is running */
#define SV_MDCNT    0xef                /* BYTE:  microdrive run-up/run-down counter */
#define SV_MDDID    0xf0                /* BYTE x 8:  drive ID*4 of each microdrive */
#define SV_MDSTA    0xf8                /* BYTE x 8:  status of each microdrive. 0=no pending ops */
#define SV_FSDEF    0x100               /* LONG x 16: pointers to file system physical definitions */
#define SV_FSLST    0x140               /* LONG:  pointer to list of file channel definitions */

#define SV_TOP      0x180               /*        Top of System variables area */
                                        /*        (Supervisor stack 0x180 to 0x480) */

#endif /* _SYS_SYSDEFS_H */
