FromROSLib 20.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/***************************************************/
/* File   : FromROSLib.h                           */
17
/*                                                 */
18 19 20 21 22 23 24 25 26
/* Purpose: The original Customer browser sources */
/*          used RISC_OSLib heavily and some of    */
/*          the functions used are handy to have   */
/*          around. This source file contains      */
/*          a variety of functions from RISC_OSLib */
/*          with modifications where necessary     */
/*          both to fit into the browser more      */
/*          naturally, and to function better      */
/*          under C release 5.                     */
27
/*                                                 */
28 29
/* Authors: Various for original RISC_OSLib source */
/*          This source adapted by A.D.Hodgkinson  */
30 31
/*                                                 */
/* History: 06-Dec-96: Created.                    */
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
/***************************************************/

/* VDU commands */

#define BBC_CharToPrinter  1  /* Send next character to the printer      */
#define BBC_EnablePrinter  2  /* Enable printer                          */
#define BBC_DisablePrinter 3  /* Disable printer                         */
#define BBC_TextToText     4  /* Have separate text and graphics cursors */
#define BBC_TextToGraph    5  /* Join text cursor to graphics cursor     */
#define BBC_EnableVDU      6  /* Enable screen output                    */
#define BBC_Bell           7  /* Bell (beep)                             */
#define BBC_MoveOneBack    8  /* Back space / move left                  */
#define BBC_MoveOneOn      9  /* Horizontal tab / move right             */
#define BBC_MoveDownOne    10 /* Line feed / move down                   */
#define BBC_MoveUpOne      11 /* Vertical tab / move up                  */
#define BBC_ClearText      12 /* Form feed / clear screen                */
#define BBC_MoveToStart    13 /* Carriage return                         */
#define BBC_PageOn         14 /* Page mode on (wait before scrolling)    */
#define BBC_PageOff        15 /* Page mode off                           */
#define BBC_ClearGraph     16 /* Clear current graphics window           */
#define BBC_DefTextColour  17 /* Set text colour                         */
#define BBC_DefGraphColour 18 /* Set graphics colour and plotting action */
#define BBC_DefLogical     19 /* Set palette                             */
#define BBC_RestoreLogical 20 /* Restore default BBC colours             */
#define BBC_DisableVDU     21 /* Disable screen output                   */
#define BBC_ScreenMode     22 /* Change screen mode                      */
#define BBC_MultiPurpose   23 /* Multiple purpose command                */
#define BBC_DefGraphWindow 24 /* Define graphics window                  */
#define BBC_PlotCommand    25 /* Graphics plotting command               */
#define BBC_DefaultWindow  26 /* Give default text and graphics windows  */
                              /* 27 is undefined (it's a no-op)          */
#define BBC_DefTextWindow  28 /* Define text window                      */
#define BBC_DefGraphOrigin 29 /* Set graphics origin                     */
#define BBC_HomeText       30 /* Move cursors to Home (0,0)              */
#define BBC_MoveText       31 /* Position text cursor                    */

/* Graphics plotting commands */

#define BBC_SolidBoth        0x00 /* Solid line including both ends      */
#define BBC_SolidExFinal     0x08 /* Sold line excluding the end point   */
#define BBC_DottedBoth       0x10 /* Dotted line including both ends     */
#define BBC_DottedExFinal    0x18 /* Dotted line excluding the end point */
#define BBC_SolidExInit      0x20 /* Solid line excluding first point    */
#define BBC_SolidExBoth      0x28 /* Solid line excluding both ends      */
#define BBC_DottedExInit     0x30 /* Dotted line excluding first point   */
#define BBC_DottedExBoth     0x38 /* Dotted line excluding both ends     */
#define BBC_Point            0x40 /* Plot a single pixel                 */
#define BBC_HorizLineFillNB  0x48 /* Horizontal line fill (left and      */
                                  /* right) to non-background            */
#define BBC_TriangleFill     0x50 /* Filled triangle                     */
#define BBC_HorizLineFillB   0x58 /* Horizontal line fill (right only)   */
                                  /* to background                       */
#define BBC_RectangleFill    0x60 /* Filled rectangle                    */
#define BBC_HorizLineFillF   0x68 /* Horizontal line fill (left and      */
                                  /* right) to foreground                */
#define BBC_ParallelFill     0x70 /* Filled parallelogram                */
#define BBC_HorizLineFillNF  0x78 /* Horizontal line fill (right only)   */
                                  /* to non-foreground                   */
#define BBC_FloodToBack      0x80 /* Flood fill to non-background        */
#define BBC_FloodToFore      0x88 /* Flood fill to foreground            */
#define BBC_Circle           0x90 /* Circle outline                      */
#define BBC_CircleFill       0x98 /* Filled circle                       */
#define BBC_CircleArc        0xA0 /* Circle arc                          */
#define BBC_Segment          0xA8 /* Circle segment                      */
#define BBC_Sector           0xB0 /* Circle sector                       */

#define BBC_Block            0xB8 /* Block ops (special case, see below) */

#define BBC_Ellipse          0xC0 /* Ellipse outline                     */
#define BBC_EllipseFill      0xC8 /* Filled ellipse                      */
#define BBC_GraphicsChar     0xD0 /* Font printing                       */
#define BBC_SpritePlot       0xE8 /* Sprite plot                         */

/* Graphics plotting modifiers; within each block of eight above, */
/* the offset from the base number has the following meaning      */
/* (unless using the BBC_Block group):                            */

#define BBC_MoveCursorRel    0    /* Move cursor relative                */
#define BBC_DrawRelFore      1    /* Draw relative                       */
#define BBC_DrawRelInverse   2    /* Draw inverted relative              */
#define BBC_DrawRelBack      3    /* Draw background relativey           */
#define BBC_MoveCursorAbs    4    /* Move cursor absolute                */
#define BBC_DrawAbsFore      5    /* Draw absolute                       */
#define BBC_DrawAbsInverse   6    /* Draw inverted absolute              */
#define BBC_DrawAbsBack      7    /* Draw background absolute            */

/* When using the block operations, the modifers work as follows: */

#define BBC_BMoveRel         0    /* Move relative                       */
#define BBC_BMoveRectRel     1    /* Move retangle relative              */
#define BBC_BCopyRectRel     2    /* Copy rectangle relative             */
                                  /* 3 is undefined (same as code 2)     */
#define BBC_BMoveAbs         4    /* Move absolute                       */
#define BBC_BMoveRectAbs     5    /* Move rectangle absolute             */
#define BBC_BCopyRectAbs     6    /* Copy rectangle absolute             */
                                  /* 7 is undefined (same as code 6)     */

/* Local structures and enumerations */

/* VDU variables, as used by OS_ReadVduVariable */

typedef enum
{
  BBC_GWLCol = 128,    /* Graphics window left hand,                                 */
  BBC_GWBRow,          /* bottom,                                                    */
  BBC_GWRCol,          /* right hand, and                                            */
  BBC_GWTRow,          /* top bounding coordinates, all inclusive.                   */
  BBC_TWLCol,          /* Text window lefthand,                                      */
  BBC_TWBRow,          /* bottom,                                                    */
  BBC_TWRCol,          /* right hand, and                                            */
  BBC_TWTRow,          /* top bounding coordinates, all inclusive.                   */
  BBC_OrgX,            /* Graphics origin X,                                         */
  BBC_OrgY,            /* and Y coords (external coords)                             */
  BBC_GCsX,            /* Graphics cursor X,                                         */
  BBC_GCsY,            /* and Y coords (external coords)                             */
  BBC_OlderCsX,        /* Oldest graphics cursor X,                                  */
  BBC_OlderCsY,        /* and Y coords (internal coords)                             */
  BBC_OldCsX,          /* Previous graphics cursor X,                                */
  BBC_OldCsY,          /* and Y coords (internal coords)                             */
  BBC_GCsIX,           /* Graphics cursor X,                                         */
  BBC_GCsIY,           /* and Y coords (internal coords)                             */
  BBC_NewPtX,          /* New point X,                                               */
  BBC_NewPtY,          /* and Y coords (internal coords)                             */
  BBC_ScreenStart,     /* Start of screen memory, as used by VDU drivers             */
  BBC_DisplayStart,    /* Start of screen memory, as used by hardware                */
  BBC_TotalScreenSize, /* Memory currently allocated to screens                      */
  BBC_GPLFMD,          /* GCOL action for foreground colour                          */
  BBC_CPLBMD,          /* GCOL action for background colour                          */
  BBC_GFCOL,           /* Graphics foreground colour                                 */
  BBC_GBCOL,           /* Graphics background colour                                 */
  BBC_TForeCol,        /* Text foreground colour                                     */
  BBC_TBackCol,        /* Text background colour                                     */
  BBC_GFTint,          /* Graphics foreground tint                                   */
  BBC_GBTint,          /* Graphics background tint                                   */
  BBC_TFTint,          /* Text foreground tint                                       */
  BBC_TBTint,          /* Text background tint                                       */
  BBC_MaxMode,         /* Highest old-style (numbered) mode available                */
  BBC_GCharSizeX,      /* VDU 5 system font X size,                                  */
  BBC_GCharSizeY,      /* and Y size in pixels                                       */
  BBC_GCharSpaceX,     /* VDU 5 system font X spacing,                               */
  BBC_GCharSpaceY,     /* and Y spacing in pixels                                    */
  BBC_HLineAddr,       /* Address of horizontal line drawing routine                 */
  BBC_TCharSizeX,      /* VDU 4 system font X size,                                  */
  BBC_TCharSizeY,      /* and Y sized in pixels                                      */
  BBC_TCharSpaceX,     /* VDU 4 system font X spacing,                               */
  BBC_TCharSpaceY      /* and Y spacing in pixels                                    */

} bbc_vduvariable;

/* Mode variables, as used by OS_ReadModeVariable */

typedef enum
{
  BBC_ModeFlags = 0,   /* Bit 0: Non-graphics mode                                   */
                       /* Bit 1: Teletext mode                                       */
                       /* Bit 2: Gap mode (there is a gap between VDU 4 lines)       */
                       /* Bit 3: BBC gap mode (3 and 6)                              */
                       /* Bit 4: Hi-res mono mode                                    */
                       /* Bit 5: Double height VDU chars                             */
                       /* Bit 6: Hardware scroll never used                          */
  BBC_ScrRCol,         /* Maximum text col number                                    */
  BBC_ScrBCol,         /* Maximum text row number                                    */
  BBC_NColour,         /* Maximum logical colour: 1, 3, 15 or 63                     */
  BBC_XEigFactor,      /* OS-unit->pixel shift factor. 0 -> OS-units = pixels,       */
  BBC_YEigFactor,      /* 1 -> 2 OS-units per pixel, 2 -> 4 OS-units per pixel, etc. */
  BBC_LineLength,      /* Bytes per pixel row                                        */
  BBC_ScreenSize,      /* Bytes per screen                                           */
  BBC_YShftFactor,     /* DEPRECATED; Log(2) of LineLength/5                         */
  BBC_Log2BPP,         /* Log base 2 of bits per pixel                               */
  BBC_Log2BPC,         /* Log base 2 of bytes per character                          */
  BBC_XWindLimit,      /* Screen width in pixels, minus 1                            */
  BBC_YWindLimit       /* Screen height in pixels, minus 1                           */

} bbc_modevariable;

/* RISCOS_Lib derived Wimp structure, unions and types */

typedef union           /* The data field in an icon              */
{
  char text[12];        /* Up to 12 bytes of text                 */
  char sprite_name[12]; /* Up to 12 bytes of sprite name          */

  struct
  {
    char * name;
    void * spritearea;  /* 0->use the common sprite area          */
                        /* 1->use the wimp sprite area            */
    int    nameisname;  /* If 0, name is in fact a sprite pointer */

  } indirectsprite;

  struct
  {
    char * buffer;      /* Pointer to text buffer                 */
    char * validstring; /* Pointer to validation string           */
    int    bufflen;     /* Length of text buffer                  */

  } indirecttext;

} wimp_icondata;

typedef struct
{
  char title[12];       /* Menu title (optional)          */
  char tit_fcol;        /* Title foreground colour        */
  char tit_bcol;        /* Title background colour        */
  char work_fcol;       /* Workarea foreground colour     */
  char work_bcol;       /* Workarea background colour     */
  int  width;           /* Width of following menu items  */
  int  height;          /* Height of following menu items */
  int  gap;             /* Vertical gap between items     */

} wimp_menuhdr;

typedef struct
{
  wimp_menuhdr hdr;         /* Followed by 'n' wimp_menuitem structs    */

} wimp_menustr;

typedef struct wimp_menustr * wimp_menuptr;

typedef struct
{
  unsigned int   flags;     /* Menu entry flags                         */
  wimp_menuptr   submenu;   /* Pointer to submenu, or -1 for no submenu */
  unsigned int   iconflags; /* Icon flags for the entry                 */
  wimp_icondata  data;      /* Icon data for the entry                  */

} wimp_menuitem;

/* RISCOS_Lib derived Wimp enumerations */

typedef enum
{
  wimp_MTICK       = 1,
  wimp_MSEPARATE   = 2,
  wimp_MWRITABLE   = 4,
  wimp_MSUBLINKMSG = 8,    /* Show a => flag               */
  wimp_MLAST       = 0x80, /* Signal last item in the menu */
  wimp_MINDIRECTED = 0x100

} wimp_menuflags;

typedef enum
{
  wimp_ITEXT        = 0x00000001, /* Icon contains text                                                */
  wimp_ISPRITE      = 0x00000002, /* Icon is a sprite                                                  */
  wimp_IBORDER      = 0x00000004, /* Icon has a border                                                 */
  wimp_IHCENTRE     = 0x00000008, /* Text is horizontally centred                                      */
  wimp_IVCENTRE     = 0x00000010, /* Text is vertically centred                                        */
  wimp_IFILLED      = 0x00000020, /* Icon has a filled background                                      */
  wimp_IFONT        = 0x00000040, /* Text is an anti-aliased font                                      */
  wimp_IREDRAW      = 0x00000080, /* Redraw needs application's help                                   */
  wimp_INDIRECT     = 0x00000100, /* Icon data is 'indirected'                                         */
  wimp_IRJUST       = 0x00000200, /* Text right justified in box                                       */
  wimp_IESG_NOC     = 0x00000400, /* If selected by right button, don't cancel other icons in same ESG */
  wimp_IHALVESPRITE = 0x00000800, /* Plot sprites half-size                                            */
  wimp_IBTYPE       = 0x00001000, /* 4-bit field: button type                                          */
  wimp_ISELECTED    = 0x00200000, /* Icon selected by user (inverted)                                  */
  wimp_INOSELECT    = 0x00400000, /* Icon cannot be selected (shaded)                                  */
  wimp_IDELETED     = 0x00800000, /* Icon has been deleted                                             */
  wimp_IFORECOL     = 0x01000000, /* 4-bit field: foreground colour                                    */
  wimp_IBACKCOL     = 0x10000000  /* 4-bit field: background colour                                    */

} wimp_iconflags;

typedef enum
{
  wimp_BIGNORE,           /* Ignore all mouse ops                */
  wimp_BNOTIFY,
  wimp_BCLICKAUTO,
  wimp_BCLICKDEBOUNCE,
  wimp_BSELREL,
  wimp_BSELDOUBLE,
  wimp_BDEBOUNCEDRAG,
  wimp_BRELEASEDRAG,
  wimp_BDOUBLEDRAG,
  wimp_BSELNOTIFY,
  wimp_BCLICKDRAGDOUBLE,
  wimp_BCLICKSEL,         /* Useful for on/off and radio buttons */
  wimp_BWRITABLE = 15

} wimp_ibtype;

/* RISCOS_Lib derived key defintions */

#define akbd_Fn        (256 + 128)
#define akbd_Sh        (16)
#define akbd_Ctl       (32)
#define akbd_TabK      (akbd_Fn + 10)
#define akbd_CopyK     (akbd_Fn + 11)
#define akbd_LeftK     (akbd_Fn + 12)
#define akbd_RightK    (akbd_Fn + 13)
#define akbd_DownK     (akbd_Fn + 14)
#define akbd_UpK       (akbd_Fn + 15)
#define akbd_HomeK     (0x01E)
#define akbd_Fn10      (0x1CA)
#define akbd_Fn11      (0x1CB)
#define akbd_Fn12      (0x1CC)
#define akbd_InsertK   (0x1CD)
#define akbd_PrintK    (akbd_Fn + 0)
#define akbd_PageUpK   (akbd_Sh + akbd_UpK)
#define akbd_PageDownK (akbd_Sh + akbd_DownK)

/* Functions that are defined in FromROSLib.s */

_kernel_oserror * bbc_vdu(int);
_kernel_oserror * bbc_vduw(int);

/* Function prototypes */

int               bbc_modevar           (int mode, int varno);
int               bbc_vduvar            (int varno);
_kernel_oserror * bbc_vduvars           (int * vars, int * values);

_kernel_oserror * bbc_vduq              (int c,...);

_kernel_oserror * bbc_clg               (void);
_kernel_oserror * bbc_gwindow           (int xmin, int ymin, int xmax, int ymax);
_kernel_oserror * bbc_origin            (int x, int y);
_kernel_oserror * bbc_gcol              (int a, int b);

_kernel_oserror * bbc_plot              (int n, int x, int y);
_kernel_oserror * bbc_move              (int x, int y);
_kernel_oserror * bbc_moveby            (int x, int y);
_kernel_oserror * bbc_draw              (int x, int y);
_kernel_oserror * bbc_drawby            (int x, int y);
_kernel_oserror * bbc_rectangle         (int x, int y, int w, int h);
_kernel_oserror * bbc_rectanglefill     (int x, int y, int w, int h);
_kernel_oserror * bbc_circle            (int x, int y, int r);
_kernel_oserror * bbc_circlefill        (int x, int y, int r);
364
_kernel_oserror * bbc_trianglefill      (int x1, int y1, int x2, int y2, int x3, int y3);
365 366 367 368 369 370 371 372 373 374 375 376
_kernel_oserror * bbc_fill              (int x, int y);

void              wimpt_read            (void);
int               wimpt_dx              (void);
int               wimpt_dy              (void);

int               coords_x_toscreen     (int x, WimpRedrawWindowBlock * r);
int               coords_y_toscreen     (int y, WimpRedrawWindowBlock * r);
void              coords_box_toscreen   (BBox * b, WimpRedrawWindowBlock * r);
int               coords_x_toworkarea   (int x, WimpRedrawWindowBlock * r);
int               coords_y_toworkarea   (int x, WimpRedrawWindowBlock * r);
void              coords_box_toworkarea (BBox * b, WimpRedrawWindowBlock * r);