FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
gfx_vgaemu.c
Go to the documentation of this file.
1
/* VGA in/out emulation */
2
3
#include "
fb_gfx.h
"
4
5
static
int
idx
= 0,
shift
= 2,
color
= 0;
6
7
int
fb_GfxIn
(
unsigned
short
port)
8
{
9
int
value = -1;
10
11
if
(!
__fb_gfx
)
12
return
-1;
13
14
switch
(port) {
15
16
case
0x3C9:
17
if
(
__fb_gfx
->
depth
> 8)
18
break
;
19
value = (
__fb_gfx
->
device_palette
[
idx
] >>
shift
) & 0x3F;
20
shift
+= 8;
21
if
(
shift
> 18) {
22
shift
= 2;
23
idx
++;
24
idx
&= (
__fb_gfx
->
default_palette
->
colors
- 1);
25
}
26
break
;
27
28
case
0x3DA:
29
if
(
__fb_gfx
->
driver
->
wait_vsync
)
30
__fb_gfx
->
driver
->
wait_vsync
();
31
value = 8;
32
break
;
33
}
34
35
return
value;
36
}
37
38
int
fb_GfxOut
(
unsigned
short
port,
unsigned
char
value)
39
{
40
int
i, r, g, b;
41
42
if
((!
__fb_gfx
) || (
__fb_gfx
->
depth
> 8))
43
return
-1;
44
45
switch
(port) {
46
47
case
0x3C7:
48
case
0x3C8:
49
idx
= value & (
__fb_gfx
->
default_palette
->
colors
- 1);
50
shift
= 2;
51
color
= 0;
52
break
;
53
54
case
0x3C9:
55
color
|= ((value & 0x3F) << shift);
56
shift += 8;
57
if
(shift > 18) {
58
if
(
__fb_gfx
->
default_palette
== &
__fb_palette
[
FB_PALETTE_256
])
59
fb_GfxPalette
(
idx
, (
color
>> 2) & 0x3F3F3F, -1, -1);
60
else
{
61
DRIVER_LOCK
();
62
r =
color
& 0xFF;
63
g = (
color
>> 8) & 0xFF;
64
b = (
color
>> 16) & 0xFF;
65
__fb_gfx
->
palette
[
idx
] =
color
;
66
for
(i = 0; i < (1 <<
__fb_gfx
->
depth
); i++) {
67
if
(
__fb_gfx
->
color_association
[i] ==
idx
) {
68
__fb_gfx
->
device_palette
[i] =
color
;
69
if
(
__fb_gfx
->
driver
->
set_palette
)
70
__fb_gfx
->
driver
->
set_palette
(i, r, g, b);
71
}
72
}
73
fb_hMemSet
(
__fb_gfx
->
dirty
,
TRUE
,
__fb_gfx
->
h
);
74
DRIVER_UNLOCK
();
75
}
76
shift = 2;
77
color
= 0;
78
idx
++;
79
idx
&= (
__fb_gfx
->
default_palette
->
colors
- 1);
80
}
81
break
;
82
83
default
:
84
return
-1;
85
}
86
87
return
0;
88
}
gfxlib2
gfx_vgaemu.c
Generated on Thu Jan 23 2014 19:40:06 for FreeBASIC by
1.8.4