1{****************************************************************************** 2 3 Free Pascal conversion (c) 1999 Sebastian Guenther 4 5 LibGGI API interface 6 7 Copyright (C) 1997 Jason McMullan [jmcc@ggi-project.org] 8 Copyright (C) 1997 Steffen Seeger [seeger@ggi-project.org] 9 Copyright (C) 1998 Andrew Apted [andrew@ggi-project.org] 10 Copyright (C) 1998 Andreas Beck [becka@ggi-project.org] 11 Copyright (C) 1998-1999 Marcus Sundberg [marcus@ggi-project.org] 12 13 Permission is hereby granted, free of charge, to any person obtaining a 14 copy of this software and associated documentation files (the "Software"), 15 to deal in the Software without restriction, including without limitation 16 the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 and/or sell copies of the Software, and to permit persons to whom the 18 Software is furnished to do so, subject to the following conditions: 19 20 The above copyright notice and this permission notice shall be included in 21 all copies or substantial portions of the Software. 22 23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 27 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 28 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 30****************************************************************************** 31*} 32 33 34{$MODE objfpc} 35{$PACKRECORDS C} 36{$LINKLIB c} 37 38unit GGI; 39 40interface 41 42uses GII; 43 44const 45 46 libggi = 'ggi'; 47 48 49{****************************************************************************** 50 LibGGI datatypes and structures 51 ******************************************************************************} 52 53 GGI_AUTO = 0; 54 55type 56 57 TGGICoord = record 58 x, y: SmallInt; 59 end; 60 61 TGGIPixel = LongWord; 62 63 TGGIAttr = LongWord; 64 65const 66 67 ATTR_FGCOLOR = $0000FF00; // fgcolor clut index 68 ATTR_BGCOLOR = $000000FF; // bgcolor clut index 69 ATTR_NORMAL = $00000000; // normal style 70 ATTR_HALF = $00010000; // half intensity 71 ATTR_BRIGHT = $00020000; // high intensity 72 ATTR_INTENSITY = $00030000; // mask to get intensity 73 ATTR_UNDERLINE = $00040000; // underline attribute 74 ATTR_BOLD = $00080000; // bold style 75 ATTR_ITALIC = $00100000; // italic style 76 ATTR_REVERSE = $00200000; // reverse fg/bg 77 ATTR_BLINK = $00800000; // enable blinking 78 ATTR_FONT = $FF000000; // font table 79 80function ATTR_COLOR(fg, bg: Integer): Integer; 81 82type 83 84 PGGIColor = ^TGGIColor; 85 86 TGGIColor = record 87 r, g, b, a: Word; 88 end; 89 90 PGGIClut = ^TGGIClut; 91 92 TGGIClut = record 93 size: Word; 94 data: PGGIColor; 95 end; 96 97const GGI_COLOR_PRECISION = 16; // 16 bit per R,G, B value 98 99// Graphtypes 100 101type TGGIGraphType = LongWord; 102 103const 104 105 GT_DEPTH_SHIFT = 0; 106 GT_SIZE_SHIFT = 8; 107 GT_SUBSCHEME_SHIFT = 16; 108 GT_SCHEME_SHIFT = 24; 109 110 GT_DEPTH_MASK = $ff shl GT_DEPTH_SHIFT; 111 GT_SIZE_MASK = $ff shl GT_SIZE_SHIFT; 112 GT_SUBSCHEME_MASK = $ff shl GT_SUBSCHEME_SHIFT; 113 GT_SCHEME_MASK = $ff shl GT_SCHEME_SHIFT; 114 115// Macros to extract info from a ggi_graphtype. 116 117function GT_DEPTH(x: Integer): Integer; 118function GT_SIZE(x: Integer): Integer; 119function GT_SUBSCHEME(x: Integer): Integer; 120function GT_SCHEME(x: Integer): Integer; 121 122{procedure GT_SETDEPTH(gt, x: Integer); 123procedure GT_SETSIZE(gt, x: Integer); 124procedure GT_SETSUBSCHEME(gt, x: Integer); 125procedure GT_SETSCHEME(gt, x: Integer);} 126 127 128const 129 130// Enumerated schemes 131 132 GT_TEXT = 1 shl GT_SCHEME_SHIFT; 133 GT_TRUECOLOR = 2 shl GT_SCHEME_SHIFT; 134 GT_GREYSCALE = 3 shl GT_SCHEME_SHIFT; 135 GT_PALETTE = 4 shl GT_SCHEME_SHIFT; 136 GT_STATIC_PALETTE = 5 shl GT_SCHEME_SHIFT; 137 138// Subschemes 139 GT_SUB_REVERSE_ENDIAN = 1 shl GT_SUBSCHEME_SHIFT; 140 GT_SUB_HIGHBIT_RIGHT = 2 shl GT_SUBSCHEME_SHIFT; 141 GT_SUB_PACKED_GETPUT = 4 shl GT_SUBSCHEME_SHIFT; 142 143// Macro that constructs a graphtype 144function GT_CONSTRUCT(depth, scheme, size: Integer): Integer; 145 146 147const 148 149// Common graphtypes 150 151 GT_TEXT16 = 4 or GT_TEXT or (16 shl GT_SIZE_SHIFT); 152 GT_TEXT32 = 8 or GT_TEXT or (32 shl GT_SIZE_SHIFT); 153 GT_1BIT = 1 or GT_PALETTE or (1 shl GT_SIZE_SHIFT); 154 GT_2BIT = 2 or GT_PALETTE or (2 shl GT_SIZE_SHIFT); 155 GT_4BIT = 4 or GT_PALETTE or (4 shl GT_SIZE_SHIFT); 156 GT_8BIT = 8 or GT_PALETTE or (8 shl GT_SIZE_SHIFT); 157 GT_15BIT = 15 or GT_TRUECOLOR or (16 shl GT_SIZE_SHIFT); 158 GT_16BIT = 16 or GT_TRUECOLOR or (16 shl GT_SIZE_SHIFT); 159 GT_24BIT = 24 or GT_TRUECOLOR or (24 shl GT_SIZE_SHIFT); 160 GT_32BIT = 24 or GT_TRUECOLOR or (32 shl GT_SIZE_SHIFT); 161 GT_AUTO = 0; 162 GT_INVALID = $ffffffff; 163 164// ggi_mode structure 165 166type 167 168 TGGIMode = record // requested by user and changed by driver 169 Frames: LongInt; // frames needed 170 Visible: TGGICoord; // vis. pixels, may change slightly 171 Virt: TGGICoord; // virtual pixels, may change 172 Size: TGGICoord; // size of visible in mm 173 GraphType: TGGIGraphType; // which mode ? 174 dpp: TGGICoord; // dots per pixel 175 end; 176 177 178{****************************************************************************** 179 LibGGI specific events 180 ******************************************************************************} 181 182const 183 184 GGI_CMDFLAG_LIBGGI = GII_CMDFLAG_EXTERNAL shr 1; 185 186 { Tell target that the application should not/should be halted when the 187 display is unmapped. The default is to halt the application.} 188 189 GGICMD_NOHALT_ON_UNMAP = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 1; 190 GGICMD_HALT_ON_UNMAP = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 2; 191 192 { Requests the application to switch target/mode, or to stop drawing on 193 the visual. 194 The latter is only sent if the application has explicitly requested 195 GGICMD_NOHALT_ON_UNMAP. When a GGI_REQSW_UNMAP request is sent the 196 application should respond by sending a GGICMD_ACKNOWLEDGE_SWITCH event 197 as quickly as possible. After the acknowledge event is sent the 198 application must not draw onto the visual until it recieves an evExpose 199 event, which tells the application that the visual is mapped back again. 200 } 201 202 GGICMD_REQUEST_SWITCH = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or 1; 203 204 // Used for 'request' field in ggi_cmddata_switchrequest 205 GGI_REQSW_UNMAP = 1; 206 GGI_REQSW_MODE = 2; 207 GGI_REQSW_TARGET = 4; 208 209type 210 211 TGGICmdDataSwitchRequest = record 212 Request: LongWord; 213 Mode: TGGIMode; 214 target: array[0..63] of Char; 215 end; 216 217const 218 219 GGICMD_ACKNOWLEDGE_SWITCH = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 3; 220 221 222type 223 224 TGGIVisual = Pointer; 225 TGGIResource = Pointer; 226 227 228// Flags and frames 229 230 TGGIFlags = LongWord; 231 232const 233 234 GGIFLAG_ASYNC = 1; 235 236{****************************************************************************** 237 Misc macros 238 ******************************************************************************} 239 240// Swap the bytes in a 16 respective 32 bit unsigned number 241function GGI_BYTEREV16(x: Integer): Integer; 242function GGI_BYTEREV32(x: LongWord): LongWord; 243 244// Swap the bitgroups in an 8 bit unsigned number 245function GGI_BITREV4(x: Integer): Integer; 246function GGI_BITREV2(x: Integer): Integer; 247function GGI_BITREV1(x: Integer): Integer; 248 249 250{****************************************************************************** 251 Information that can be returned to user apps 252 ******************************************************************************} 253 254// Bitmeaning defines 255 256const 257 258 GGI_BM_TYPE_NONE = 0; // This bit is not in use 259 260 261 // Bit influences color of displayed pixel 262 263 GGI_BM_TYPE_COLOR = $010000; 264 265 GGI_BM_SUB_RED = $0100; 266 GGI_BM_SUB_GREEN = $0200; 267 GGI_BM_SUB_BLUE = $0300; 268 269 GGI_BM_SUB_CYAN = $1000; 270 GGI_BM_SUB_MAGENTA = $1100; 271 GGI_BM_SUB_YELLOW = $1200; 272 GGI_BM_SUB_K = $1300; 273 274 GGI_BM_SUB_Y = $2000; 275 GGI_BM_SUB_U = $2100; 276 GGI_BM_SUB_V = $2200; 277 278 GGI_BM_SUB_CLUT = $f000; // This bit Color or attrib ? 279 280 281 // Bit changes appearance of pixel/glyph 282 283 GGI_BM_TYPE_ATTRIB = $020000; 284 285 GGI_BM_SUB_ALPHA = $0100; 286 287 GGI_BM_SUB_BLINK = $1000; 288 GGI_BM_SUB_INTENSITY = $1100; 289 GGI_BM_SUB_UNDERLINE = $1200; 290 GGI_BM_SUB_BOLD = $1300; 291 GGI_BM_SUB_ITALIC = $1400; 292 293 GGI_BM_SUB_FGCOL = $2000; 294 GGI_BM_SUB_BGCOL = $2100; 295 296 GGI_BM_SUB_TEXNUM = $3000; 297 GGI_BM_SUB_FONTSEL = $3100; // select different font banks 298 GGI_BM_SUB_PALSEL = $3200; // select different palettes 299 GGI_BM_SUB_MODESEL = $3300; // select different palettes 300 301 // Bit that influence drawing logic 302 303 GGI_BM_TYPE_LOGIC = $030000; 304 305 GGI_BM_SUB_ZBUFFER = $0100; 306 GGI_BM_SUB_WRITEPROT = $1000; 307 GGI_BM_SUB_WINDOWID = $2000; 308 309 310 311 312// Pixelformat for ggiGet/Put* buffers and pixellinearbuffers */ 313 314type 315 316 PGGIPixelFormat = ^TGGIPixelFormat; 317 318 TGGIPixelFormat = record 319 depth: Integer; // Number of significant bits 320 size: Integer; // Physical size in bits 321 322 323 {* Simple and common things first : 324 * 325 * Usage of the mask/shift pairs: 326 * If new_value is the _sizeof(ggi_pixel)*8bit_ value of the thing 327 * you want to set, you do 328 * 329 * *pointer &= ~???_mask; // Mask out old bits 330 * *pointer |= (new_value>>shift) & ???_mask; 331 * 332 * The reason to use 32 bit and "downshifting" is alignment 333 * and extensibility. You can easily adjust to other datasizes 334 * with a simple addition ... 335 *} 336 337 // Simple colors: 338 red_mask: TGGIPixel; // Bitmask of red bits 339 red_shift: Integer; // Shift for red bits 340 341 green_mask: TGGIPixel; // Bitmask of green bits 342 green_shift: Integer; // Shift for green bits 343 344 blue_mask: TGGIPixel; // Bitmask of blue bits 345 blue_shift: Integer; // Shift for blue bits 346 347 // A few common attributes: 348 alpha_mask: TGGIPixel; // Bitmask of alphachannel bits 349 alpha_shift: Integer; // Shift for alpha bits 350 351 clut_mask: TGGIPixel; // Bitmask of bits for the clut 352 clut_shift: Integer; // Shift for bits for the clut 353 354 fg_mask: TGGIPixel; // Bitmask of foreground color 355 fg_shift: Integer; // Shift for foreground color 356 357 bg_mask: TGGIPixel; // Bitmask of background color 358 bg_shift: Integer; // Shift for background color 359 360 texture_mask: TGGIPixel; // Bitmask of the texture (for 361 // textmodes - the actual character) 362 texture_shift: Integer; // Shift for texture 363 364 // Now if this does not suffice you might want to parse the following 365 // to find out what each bit does: 366 bitmeaning: array[0..SizeOf(TGGIPixel) * 8 - 1] of LongWord; 367 368 // Shall we keep those? 369 flags: LongWord; // Pixelformat flags 370 371 stdformat: LongWord; // Standard format identifier 372 373 {* This one has only one use for the usermode application: 374 * To quickly check, if two buffers are identical. If both 375 * stdformats are the same and _NOT_ 0 (which means "WEIRD"), 376 * you may use things like memcpy between them which will have 377 * the desired effect ... 378 *} 379end; 380 381const 382 383 // Pixelformat flags 384 GGI_PF_REVERSE_ENDIAN = 1; 385 GGI_PF_HIGHBIT_RIGHT = 2; 386 GGI_PF_HAM = 4; 387 GGI_PF_EXTENDED = 8; 388 389 390{****************************************************************************** 391 DirectBuffer 392 ******************************************************************************} 393 394type 395 396 TGGIBufferLayout = ( 397 blPixelLinearBuffer, 398 blPixelPlanarBuffer, 399 blExtended, 400 401 blLastBufferLayout 402 ); 403 404 405 PGGIPixelLinearBuffer = ^TGGIPixelLinearBuffer; 406 407 TGGIPixelLinearBuffer = record 408 stride: Integer; // bytes per row 409 pixelformat: PGGIPixelFormat; // format of the pixels 410 end; 411 412 413 PGGIPixelPlanarBuffer = ^TGGIPixelPlanarBuffer; 414 415 TGGIPixelPlanarBuffer = record 416 next_line: Integer; // bytes until next line 417 next_plane: Integer; // bytes until next plane 418 pixelformat: PGGIPixelFormat; // format of the pixels 419 end; 420 421// Buffer types 422 423const 424 425 GGI_DB_NORMAL = 1; // "frame" is valid when set 426 GGI_DB_EXTENDED = 2; 427 GGI_DB_MULTI_LEFT = 4; 428 GGI_DB_MULTI_RIGHT = 8; 429 430 // Flags that may be 'or'ed with the buffer type 431 GGI_DB_SIMPLE_PLB = $01000000; 432 { GGI_DB_SIMPLE_PLB means that the buffer has the following properties: 433 type = GGI_DB_NORMAL 434 read = write 435 noaccess = 0 436 align = 0 437 layout = blPixelLinearBuffer 438 } 439 440type 441 442 PGGIDirectBuffer = ^TGGIDirectBuffer; 443 444 TGGIDirectBuffer = record 445 BufferType: LongWord; // buffer type 446 frame: Integer; // framenumber (GGI_DB_NORMAL) 447 448 // access info 449 resource: TGGIResource; // If non-NULL you must acquire the 450 // buffer before using it 451 read: Pointer; // buffer address for reads 452 write:Pointer; // buffer address for writes 453 page_size: LongWord; // zero for true linear buffers 454 455 noaccess: LongWord; 456 {bitfield. bit x set means you may _not_ access this DB at the 457 width of 2^x bytes. Usually 0, but _check_ it.} 458 459 align: LongWord; 460 {bitfield. bit x set means you may only access this DB at the 461 width of 2^x bytes, when the access is aligned to a multiple 462 of 2^x. Note that bit 0 is a bit bogus here, but it should 463 be always 0, as then ((noaccess|align)==0) is a quick check 464 for "no restrictions". } 465 466 layout: TGGIBufferLayout; 467 468 // The actual buffer info. Depends on layout. 469 buffer: record 470 case Integer of 471 0: (plb: TGGIPixelLinearBuffer); 472 1: (plan: TGGIPixelPlanarBuffer); 473 2: (extended: Pointer); 474 end; 475 end; 476 477 478{****************************************************************************** 479 Resource management 480 ******************************************************************************} 481 482// Access types 483 484const 485 486 GGI_ACTYPE_READ = 1 shl 0; 487 GGI_ACTYPE_WRITE = 1 shl 1; 488 489 490{****************************************************************************** 491 LibGGI function definitions 492******************************************************************************} 493 494// Enter and leave the library 495 496function ggiInit: Integer; cdecl; external libggi; 497procedure ggiExit; cdecl; external libggi; 498procedure ggiPanic(format: PChar; args: array of const); cdecl; external libggi; 499 500 501// Open a new visual - use display 'NULL' for the default visual 502function ggiOpen(display: PChar; args: array of const): TGGIVisual; cdecl; external libggi; 503function ggiClose(vis: TGGIVisual): Integer; cdecl; external libggi; 504 505// Get/Set info 506function ggiSetFlags(vis: TGGIVisual; flags: TGGIFlags): Integer; cdecl; external libggi; 507function ggiGetFlags(vis: TGGIVisual): TGGIFlags; cdecl; external libggi; 508 509function ggiAddFlags(vis: TGGIVisual; flags: TGGIFlags): Integer; 510function ggiRemoveFlags(vis: TGGIVisual; flags: TGGIFlags): Integer; 511 512function ggiGetPixelFormat(vis: TGGIVisual): PGGIPixelFormat; cdecl; external libggi; 513 514 515// DirectBuffer (DB) functions 516function ggiDBGetNumBuffers(vis: TGGIVisual): Integer; cdecl; external libggi; 517function ggiDBGetBuffer(vis: TGGIVisual; bufnum: Integer): PGGIDirectBuffer; cdecl; external libggi; 518 519// Resource functions 520function ggiResourceAcquire(res: TGGIResource; actype: LongWord): Integer; 521function ggiResourceRelease(res: TGGIResource): Integer; 522function ggiResourceFastAcquire(res: TGGIResource; actype: LongWord): Integer; cdecl; external libggi; 523function ggiResourceFastRelease(res: TGGIResource): Integer; cdecl; external libggi; 524 525 526// Library management 527 528const GGI_MAX_APILEN = 1024; 529 530function ggiGetAPI(vis: TGGIVisual; num: Integer; APIName, arguments: PChar): Integer; cdecl; external libggi; 531 532const GGI_CHG_APILIST = 1; 533 534function ggiIndicateChange(vis: TGGIVisual; WhatChanged: Integer): Integer; cdecl; external libggi; 535 536 537// Mode management 538 539function ggiSetMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi; 540function ggiGetMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi; 541function ggiCheckMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi; 542function ggiSetTextMode(visual: TGGIVisual; cols, rows, vcols, vrows, fontx, fonty: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi; 543function ggiCheckTextMode(visual: TGGIVisual; cols, rows, vcols, vrows, fontx, fonty: Integer; var SuggestedMode: TGGIMode): Integer; cdecl; external libggi; 544function ggiSetGraphMode(visual: TGGIVisual; x, y, xv, yv: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi; 545function ggiCheckGraphMode(visual: TGGIVisual; x, y, xv, yv: Integer; AType: TGGIGraphType; var SuggestedMode: TGGIMode): Integer; cdecl; external libggi; 546function ggiSetSimpleMode(visual: TGGIVisual; xsize, ysize, frames: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi; 547function ggiCheckSimpleMode(visual: TGGIVisual; xsize, ysize, frames: Integer; AType: TGGIGraphType; var md: TGGIMode): Integer; cdecl; external libggi; 548 549 550// Print all members of the mode struct 551 552function ggiSPrintMode(s: PChar; var m: TGGIMode): Integer; cdecl; external libggi; 553// function ggiFPrintMode(s: PFile; var m: TGGIMode): Integer; cdecl; external libggi; 554// #define ggiPrintMode(m) ggiFPrintMode(stdout,(m)) 555 556 557// Fill a mode struct from the text string s 558 559function ggiParseMode(s: PChar; var m: TGGIMode): Integer; cdecl; external libggi; 560 561 562// Flush all pending operations to the display device 563 564// Normal flush 565function ggiFlush(vis: TGGIVisual): Integer; cdecl; external libggi; 566 567// Flush only the specified region if it would improve performance 568function ggiFlushRegion(vis: TGGIVisual; x, y, w, h: Integer): Integer; cdecl; external libggi; 569 570 571// Graphics context 572 573function ggiSetGCForeground(vis: TGGIVisual; const Color: TGGIPixel): Integer; cdecl; external libggi; 574function ggiGetGCForeground(vis: TGGIVisual; var Color: TGGIPixel): Integer; cdecl; external libggi; 575function ggiSetGCBackground(vis: TGGIVisual; const Color: TGGIPixel): Integer; cdecl; external libggi; 576function ggiGetGCBackground(vis: TGGIVisual; var Color: TGGIPixel): Integer; cdecl; external libggi; 577function ggiSetGCClipping(vis: TGGIVisual; left, top, right, bottom: Integer): Integer; cdecl; external libggi; 578function ggiGetGCClipping(vis: TGGIVisual; var left, top, right, bottom: Integer): Integer; cdecl; external libggi; 579 580 581// Color palette manipulation 582function ggiMapColor(vis: TGGIVisual; var Color: TGGIColor): TGGIPixel; cdecl; external libggi; 583function ggiUnmapPixel(vis: TGGIVisual; pixel: TGGIPixel; var Color: TGGIColor): Integer; cdecl; external libggi; 584function ggiPackColors(vis: TGGIVisual; var buf; var cols: TGGIColor; len: Integer): Integer; cdecl; external libggi; 585function ggiUnpackPixels(vis: TGGIVisual; var buf; var cols: TGGIColor; len: Integer): Integer; cdecl; external libggi; 586function ggiGetPalette(vis: TGGIVisual; s, len: Integer; var cmap: TGGIColor): Integer; cdecl; external libggi; 587function ggiSetPalette(vis: TGGIVisual; s, len: Integer; var cmap: TGGIColor): Integer; cdecl; external libggi; 588function ggiSetColorfulPalette(vis: TGGIVisual): Integer; cdecl; external libggi; 589 590const GGI_PALETTE_DONTCARE = -1; 591 592 593// Gamma map manipulation 594 595function ggiGetGamma(vis: TGGIVisual; var r, g, b: Double): Integer; cdecl; external libggi; 596function ggiSetGamma(vis: TGGIVisual; r, g, b: Double): Integer; cdecl; external libggi; 597function ggiGetGammaMap(vis: TGGIVisual; s, len: Integer; var gammamap: TGGIColor): Integer; cdecl; external libggi; 598function ggiSetGammaMap(vis: TGGIVisual; s, len: Integer; var gammamap: TGGIColor): Integer; cdecl; external libggi; 599 600 601// Origin handling 602 603function ggiSetOrigin(vis: TGGIVisual; x, y: Integer): Integer; cdecl; external libggi; 604function ggiGetOrigin(vis: TGGIVisual; var x, y: Integer): Integer; cdecl; external libggi; 605 606 607// Frame handling 608 609function ggiSetDisplayFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi; 610function ggiSetReadFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi; 611function ggiSetWriteFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi; 612 613function ggiGetDisplayFrame(vis: TGGIVisual): Integer; cdecl; external libggi; 614function ggiGetReadFrame(vis: TGGIVisual): Integer; cdecl; external libggi; 615function ggiGetWriteFrame(vis: TGGIVisual): Integer; cdecl; external libggi; 616 617 618// Generic drawing routines 619 620function ggiFillscreen(vis: TGGIVisual): Integer; cdecl; external libggi; 621 622function ggiDrawPixel(vis: TGGIVisual; x, y: Integer): Integer; cdecl; external libggi; 623function ggiPutPixel(vis: TGGIVisual; x, y: Integer; pixel: TGGIPixel): Integer; cdecl; external libggi; 624function ggiGetPixel(vis: TGGIVisual; x, y: Integer; var pixel: TGGIPixel): Integer; cdecl; external libggi; 625 626function ggiDrawLine(vis: TGGIVisual; x, y, xe, ye: Integer): Integer; cdecl; external libggi; 627function ggiDrawHLine(vis: TGGIVisual; x, y, w: Integer): Integer; cdecl; external libggi; 628function ggiPutHLine(vis: TGGIVisual; x, y, w: Integer; var buf): Integer; cdecl; external libggi; 629function ggiGetHLine(vis: TGGIVisual; x, y, w: Integer; var buf): Integer; cdecl; external libggi; 630 631function ggiDrawVLine(vis: TGGIVisual; x, y, h: Integer): Integer; cdecl; external libggi; 632function ggiPutVLine(vis: TGGIVisual; x, y, h: Integer; var buf): Integer; cdecl; external libggi; 633function ggiGetVLine(vis: TGGIVisual; x, y, h: Integer; var buf): Integer; cdecl; external libggi; 634 635function ggiDrawBox(vis: TGGIVisual; x, y, w, h: Integer): Integer; cdecl; external libggi; 636function ggiPutBox(vis: TGGIVisual; x, y, w, h: Integer; var buffer): Integer; cdecl; external libggi; 637function ggiGetBox(vis: TGGIVisual; x, y, w, h: Integer; var buffer): Integer; cdecl; external libggi; 638function ggiCopyBox(vis: TGGIVisual; x, y, w, h, nx, ny: Integer): Integer; cdecl; external libggi; 639function ggiCrossBlit(src: TGGIVisual; sx, sy, w, h: Integer; dst: TGGIVisual; dx, dy: Integer): Integer; cdecl; external libggi; 640 641 642// Text drawing routines 643 644function ggiPutc(vis: TGGIVisual; x, y: Integer; c: Char): Integer; cdecl; external libggi; 645function ggiPuts(vis: TGGIVisual; x, y: Integer; str: PChar): Integer; cdecl; external libggi; 646function ggiGetCharSize(vis: TGGIVisual; var width, height: Integer): Integer; cdecl; external libggi; 647 648 649// Event handling 650 651//###function ggiEventPoll(vis: TGGIVisual; mask: TGIIEventMask; var t: TTimeVal): TGIIEventMask; cdecl; external libggi; 652function ggiEventsQueued(vis: TGGIVisual; mask: TGIIEventMask): Integer; cdecl; external libggi; 653function ggiEventRead(vis: TGGIVisual; var Event: TGIIEvent; mask: TGIIEventMask): Integer; cdecl; external libggi; 654function ggiSetEventMask(vis: TGGIVisual; EventMask: TGIIEventMask): Integer; cdecl; external libggi; 655function ggiGetEventMask(vis: TGGIVisual): TGIIEventMask; cdecl; external libggi; 656function ggiEventSend(vis: TGGIVisual; var Event: TGIIEvent): Integer; cdecl; external libggi; 657function ggiJoinInputs(vis: TGGIVisual; Input: TGIIInput): TGIIInput; cdecl; external libggi; 658 659function ggiAddEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer; 660function ggiRemoveEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer; 661 662 663// Convenience functions 664 665function ggiKbhit(vis: TGGIVisual): Integer; cdecl; external libggi; 666function ggiGetc(vis: TGGIVisual): Integer; cdecl; external libggi; 667 668 669// Extension handling 670 671type 672 TGGILibID = Pointer; 673 TGGIExtID = Integer; {Don't rely on that !} 674 TGGIParamChangeProc = function(Visual: TGGIVisual; WhatChanged: Integer): Integer; 675 676function ggiExtensionRegister(name: PChar; size: Integer; 677 ParamChange: TGGIParamChangeProc): TGGIExtID; cdecl; external libggi; 678function ggiExtensionUnregister(id: TGGIExtID): Integer; cdecl; external libggi; 679function ggiExtensionAttach(Visual: TGGIVisual; id: TGGIExtID): Integer; cdecl; external libggi; 680function ggiExtensionDetach(Visual: TGGIVisual; id: TGGIExtID): Integer; cdecl; external libggi; 681function ggiExtensionLoadDL(Visual: TGGIVisual; filename, args: PChar; ArgPtr: Pointer): TGGILibID; cdecl; external libggi; 682 683 684 685// =================================================================== 686// =================================================================== 687 688implementation 689 690 691function ATTR_COLOR(fg, bg: Integer): Integer; 692begin 693 Result := (bg and $ff) or ((fg and $ff) shl 8); 694end; 695 696function GT_DEPTH(x: Integer): Integer; 697begin 698 Result := (x and GT_DEPTH_MASK) shr GT_DEPTH_SHIFT; 699end; 700 701function GT_SIZE(x: Integer): Integer; 702begin 703 Result := (x and GT_SIZE_MASK) shr GT_SIZE_SHIFT; 704end; 705 706function GT_SUBSCHEME(x: Integer): Integer; 707begin 708 Result := x and GT_SUBSCHEME_MASK; 709end; 710 711function GT_SCHEME(x: Integer): Integer; 712begin 713 Result := x and GT_SCHEME_MASK; 714end; 715 716function GT_CONSTRUCT(depth, scheme, size: Integer): Integer; 717begin 718 Result := depth or scheme or (size shl GT_SIZE_SHIFT); 719end; 720 721 722 723function GGI_BYTEREV16(x: Integer): Integer; 724begin 725 Result := (x shl 8) or (x shr 8); 726end; 727 728function GGI_BYTEREV32(x: LongWord): LongWord; 729begin 730 Result := (x shl 24) or ((x and $ff00) shl 8) or 731 ((x and $ff0000) shr 8) or (x shr 24); 732end; 733 734function GGI_BITREV4(x: Integer): Integer; 735begin 736 Result := (x shr 4) or (x shl 4); 737end; 738 739function GGI_BITREV2(x: Integer): Integer; 740begin 741 Result := (x shr 6) or ((x and $30) shr 2) or ((x and $0c) shl 2) or (x shl 6); 742end; 743 744function GGI_BITREV1(x: Integer): Integer; 745begin 746 Result := (x shr 7) or ((x and $40) shr 5) or ((x and $20) shr 3) or 747 ((x and $10) shr 1) or ((x and 8) shl 1) or ((x and 4) shl 3) or 748 ((x and 2) shl 4) or (x shl 7); 749end; 750 751function ggiAddFlags(vis: TGGIVisual; flags: TGGIFlags): Integer; 752begin 753 Result := ggiSetFlags(vis, ggiGetFlags(vis) or flags); 754end; 755 756function ggiRemoveFlags(vis: TGGIVisual; flags: TGGIFlags): Integer; 757begin 758 Result := ggiSetFlags(vis, ggiGetFlags(vis) and not flags); 759end; 760 761function ggiResourceAcquire(res: TGGIResource; actype: LongWord): Integer; 762begin 763 if res = nil then Result := 0 764 else Result := ggiResourceFastAcquire(res, actype); 765end; 766 767function ggiResourceRelease(res: TGGIResource): Integer; 768begin 769 if res = nil then Result := 0 770 else Result := ggiResourceFastRelease(res); 771end; 772 773function ggiAddEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer; 774begin 775 Result := ggiSetEventMask(vis, ggiGetEventMask(vis) or mask); 776end; 777 778function ggiRemoveEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer; 779begin 780 Result := ggiSetEventMask(vis, ggiGetEventMask(vis) and not mask); 781end; 782 783 784end. 785