1 /**
2 ** BCC2GRX - Interfacing Borland based graphics programs to LIBGRX
3 ** Copyright (C) 1993-97 by Hartmut Schirmer
4 **
5 **
6 ** Contact : Hartmut Schirmer
7 ** Feldstrasse 118
8 ** D-24105 Kiel
9 ** Germany
10 **
11 ** e-mail : hsc@techfak.uni-kiel.de
12 **
13 ** This file is part of the GRX graphics library.
14 **
15 ** The GRX graphics library is free software; you can redistribute it
16 ** and/or modify it under some conditions; see the "copying.grx" file
17 ** for details.
18 **
19 ** This library is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 **/
24
25 #include "bccgrx00.h"
26
27 #define DEFAULT_PALETTE \
28 { /*size:*/16, \
29 /*colors:*/ {EGA_BLACK, EGA_BLUE, EGA_GREEN, EGA_CYAN, EGA_RED, \
30 EGA_MAGENTA, EGA_BROWN, EGA_LIGHTGRAY, EGA_DARKGRAY, \
31 EGA_LIGHTBLUE, EGA_LIGHTGREEN, EGA_LIGHTCYAN, \
32 EGA_LIGHTRED, EGA_LIGHTMAGENTA, EGA_YELLOW, EGA_WHITE} }
33
34 struct palettetype __gr_EGAdef = DEFAULT_PALETTE;
35 static struct palettetype UsrPal = DEFAULT_PALETTE;
36
37 /* ----------------------------------------------------------------- */
38
__gr_setpalette(int colornum,int color)39 void __gr_setpalette(int colornum, int color)
40 {
41 #ifdef __DJGPP__
42 # include <dpmi.h>
43 //# include <go32.h>
44 _go32_dpmi_registers regs;
45
46 _DO_INIT_CHECK;
47 colornum &= 0x0f;
48 color &= 0x3f;
49 UsrPal.colors[colornum] = color;
50
51 memset(®s, 0, sizeof(regs));
52 regs.x.ax = 0x1000;
53 regs.x.bx = colornum | (color << 8);
54 /* real mode interruts may be called by
55 _go32_dpmi_simulate_int() (v1 & v2)
56 and
57 __dpmi_simulate_real_mode_interrupt() (v2 only)
58
59 Under v2 the _go32_dpmi_simulate_int is actually a macro
60 referencing __dpmi_simulate_real_mode_interrupt(). Undefining
61 this macro makes the library linkable under both DJGPP v1 and
62 v2 since there _is_ a compatible _go32_dpmi_simulate_int() in
63 the v2 library! Don't worry about the compiler warning here ! */
64 #undef _go32_dpmi_simulate_int
65 _go32_dpmi_simulate_int(0x10,®s);
66 #endif
67 }
68 /* ----------------------------------------------------------------- */
getpalette(struct palettetype * palette)69 void getpalette(struct palettetype *palette)
70 {
71 _DO_INIT_CHECK;
72 *palette = UsrPal;
73 }
74
75 /* ----------------------------------------------------------------- */
setallpalette(const struct palettetype * palette)76 void setallpalette(const struct palettetype *palette)
77 {
78 int i, col;
79
80 _DO_INIT_CHECK;
81 if (palette == NULL)
82 return;
83 for (i=0; i < palette->size; ++i)
84 if ( (col = palette->colors[i]) >= 0)
85 __gr_setpalette( i, col);
86 }
87