summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/src/video/fbcon
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/src/video/fbcon')
-rw-r--r--apps/plugins/sdl/src/video/fbcon/3dfx_mmio.h56
-rw-r--r--apps/plugins/sdl/src/video/fbcon/3dfx_regs.h83
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fb3dfx.c215
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fb3dfx.h29
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbelo.c442
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbelo.h55
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbevents.c1254
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbevents_c.h38
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbkeys.h139
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbmatrox.c280
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbmatrox.h29
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbmouse.c33
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbmouse_c.h26
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbriva.c222
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbriva.h36
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbvideo.c1982
-rw-r--r--apps/plugins/sdl/src/video/fbcon/SDL_fbvideo.h200
-rw-r--r--apps/plugins/sdl/src/video/fbcon/matrox_mmio.h51
-rw-r--r--apps/plugins/sdl/src/video/fbcon/matrox_regs.h376
-rw-r--r--apps/plugins/sdl/src/video/fbcon/riva_mmio.h449
-rw-r--r--apps/plugins/sdl/src/video/fbcon/riva_regs.h43
21 files changed, 0 insertions, 6038 deletions
diff --git a/apps/plugins/sdl/src/video/fbcon/3dfx_mmio.h b/apps/plugins/sdl/src/video/fbcon/3dfx_mmio.h
deleted file mode 100644
index b641454809..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/3dfx_mmio.h
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* 3Dfx register definitions */
25
26#include "3dfx_regs.h"
27
28/* 3Dfx control macros */
29
30#define tdfx_in8(reg) *(volatile Uint8 *)(mapped_io + (reg))
31#define tdfx_in32(reg) *(volatile Uint32 *)(mapped_io + (reg))
32
33#define tdfx_out8(reg,v) *(volatile Uint8 *)(mapped_io + (reg)) = v;
34#define tdfx_out32(reg,v) *(volatile Uint32 *)(mapped_io + (reg)) = v;
35
36
37/* Wait for fifo space */
38#define tdfx_wait(space) \
39{ \
40 while ( (tdfx_in8(TDFX_STATUS) & 0x1F) < space ) \
41 ; \
42}
43
44
45/* Wait for idle accelerator */
46#define tdfx_waitidle() \
47{ \
48 int i = 0; \
49 \
50 tdfx_wait(1); \
51 tdfx_out32(COMMAND_3D, COMMAND_3D_NOP); \
52 do { \
53 i = (tdfx_in32(TDFX_STATUS) & STATUS_BUSY) ? 0 : i + 1; \
54 } while ( i != 3 ); \
55}
56
diff --git a/apps/plugins/sdl/src/video/fbcon/3dfx_regs.h b/apps/plugins/sdl/src/video/fbcon/3dfx_regs.h
deleted file mode 100644
index e86f727b30..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/3dfx_regs.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef _3DFX_REGS_H
25#define _3DFX_REGS_H
26
27/* This information comes from the public 3Dfx specs for the Voodoo 3000 */
28
29/* mapped_io register offsets */
30#define TDFX_STATUS 0x00
31
32#define INTCTRL (0x00100000 + 0x04)
33#define CLIP0MIN (0x00100000 + 0x08)
34#define CLIP0MAX (0x00100000 + 0x0c)
35#define DSTBASE (0x00100000 + 0x10)
36#define DSTFORMAT (0x00100000 + 0x14)
37#define SRCCOLORKEYMIN (0x00100000 + 0x18)
38#define SRCCOLORKEYMAX (0x00100000 + 0x1c)
39#define DSTCOLORKEYMIN (0x00100000 + 0x20)
40#define DSTCOLORKEYMAX (0x00100000 + 0x24)
41#define BRESERROR0 (0x00100000 + 0x28)
42#define BRESERROR1 (0x00100000 + 0x2c)
43#define ROP_2D (0x00100000 + 0x30)
44#define SRCBASE (0x00100000 + 0x34)
45#define COMMANDEXTRA_2D (0x00100000 + 0x38)
46#define PATTERN0 (0x00100000 + 0x44)
47#define PATTERN1 (0x00100000 + 0x48)
48#define CLIP1MIN (0x00100000 + 0x4c)
49#define CLIP1MAX (0x00100000 + 0x50)
50#define SRCFORMAT (0x00100000 + 0x54)
51#define SRCSIZE (0x00100000 + 0x58)
52#define SRCXY (0x00100000 + 0x5c)
53#define COLORBACK (0x00100000 + 0x60)
54#define COLORFORE (0x00100000 + 0x64)
55#define DSTSIZE (0x00100000 + 0x68)
56#define DSTXY (0x00100000 + 0x6c)
57#define COMMAND_2D (0x00100000 + 0x70)
58#define LAUNCH_2D (0x00100000 + 0x80)
59#define PATTERNBASE (0x00100000 + 0x100)
60
61#define COMMAND_3D (0x00200000 + 0x120)
62
63/* register bitfields (not all, only as needed) */
64
65#define BIT(x) (1UL << (x))
66
67#define COMMAND_2D_BITBLT 0x01
68#define COMMAND_2D_FILLRECT 0x05
69#define COMMAND_2D_LINE 0x06
70#define COMMAND_2D_POLYGON_FILL 0x08
71#define COMMAND_2D_INITIATE BIT(8)
72#define COMMAND_2D_REVERSELINE BIT(9)
73#define COMMAND_2D_STIPPLELINE BIT(12)
74#define COMMAND_2D_MONOCHROME_PATT BIT(13)
75#define COMMAND_2D_MONOCHROME_TRANSP BIT(16)
76
77#define COMMAND_3D_NOP 0x00
78
79#define STATUS_RETRACE BIT(6)
80#define STATUS_BUSY BIT(9)
81
82#endif /* _3DFX_REGS_H */
83
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fb3dfx.c b/apps/plugins/sdl/src/video/fbcon/SDL_fb3dfx.c
deleted file mode 100644
index eb083b85ab..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fb3dfx.c
+++ /dev/null
@@ -1,215 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_video.h"
25#include "../SDL_blit.h"
26#include "SDL_fb3dfx.h"
27#include "3dfx_mmio.h"
28
29
30/* Wait for vertical retrace */
31static void WaitVBL(_THIS)
32{
33 /* find start of retrace */
34 tdfx_waitidle();
35 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == STATUS_RETRACE )
36 ;
37 /* wait until we're past the start */
38 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0 )
39 ;
40}
41static void WaitIdle(_THIS)
42{
43 tdfx_waitidle();
44}
45
46/* Sets video mem colorkey and accelerated blit function */
47static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
48{
49 return(0);
50}
51
52static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color)
53{
54 int bpp;
55 Uint32 dst_base;
56 Uint32 format;
57 int dstX, dstY;
58
59 /* Don't blit to the display surface when switched away */
60 if ( switched_away ) {
61 return -2; /* no hardware access */
62 }
63 if ( dst == this->screen ) {
64 SDL_mutexP(hw_lock);
65 }
66
67 /* Set the destination pixel format */
68 dst_base = ((char *)dst->pixels - mapped_mem);
69 bpp = dst->format->BitsPerPixel;
70 format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13);
71
72 /* Calculate source and destination base coordinates */
73 dstX = rect->x;
74 dstY = rect->y;
75
76 /* Execute the fill command */
77 tdfx_wait(6);
78 tdfx_out32(DSTBASE, dst_base);
79 tdfx_out32(DSTFORMAT, format);
80 tdfx_out32(COLORFORE, color);
81 tdfx_out32(COMMAND_2D, COMMAND_2D_FILLRECT);
82 tdfx_out32(DSTSIZE, rect->w | (rect->h << 16));
83 tdfx_out32(LAUNCH_2D, dstX | (dstY << 16));
84
85 FB_AddBusySurface(dst);
86
87 if ( dst == this->screen ) {
88 SDL_mutexV(hw_lock);
89 }
90 return(0);
91}
92
93static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
94 SDL_Surface *dst, SDL_Rect *dstrect)
95{
96 SDL_VideoDevice *this = current_video;
97 int bpp;
98 Uint32 src_format;
99 Uint32 src_base;
100 Uint32 dst_base;
101 int srcX, srcY;
102 int dstX, dstY;
103 Uint32 blitop;
104 Uint32 use_colorkey;
105
106 /* Don't blit to the display surface when switched away */
107 if ( switched_away ) {
108 return -2; /* no hardware access */
109 }
110 if ( dst == this->screen ) {
111 SDL_mutexP(hw_lock);
112 }
113
114 /* Set the source and destination pixel format */
115 src_base = ((char *)src->pixels - mapped_mem);
116 bpp = src->format->BitsPerPixel;
117 src_format = src->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13);
118 dst_base = ((char *)dst->pixels - mapped_mem);
119 bpp = dst->format->BitsPerPixel;
120
121 srcX = srcrect->x;
122 srcY = srcrect->y;
123 dstX = dstrect->x;
124 dstY = dstrect->y;
125
126 /* Assemble the blit operation */
127 blitop = COMMAND_2D_BITBLT | (0xCC << 24);
128 if ( srcX <= dstX ) {
129 blitop |= BIT(14);
130 srcX += (dstrect->w - 1);
131 dstX += (dstrect->w - 1);
132 }
133 if ( srcY <= dstY ) {
134 blitop |= BIT(15);
135 srcY += (dstrect->h - 1);
136 dstY += (dstrect->h - 1);
137 }
138
139 /* Perform the blit! */
140 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
141 tdfx_wait(3);
142 tdfx_out32(SRCCOLORKEYMIN, src->format->colorkey);
143 tdfx_out32(SRCCOLORKEYMAX, src->format->colorkey);
144 tdfx_out32(ROP_2D, 0xAA00);
145 use_colorkey = 1;
146 } else {
147 use_colorkey = 0;
148 }
149 tdfx_wait(9);
150 tdfx_out32(SRCBASE, (Uint32)src_base);
151 tdfx_out32(SRCFORMAT, src_format);
152 tdfx_out32(DSTBASE, (Uint32)dst_base);
153 tdfx_out32(DSTFORMAT, src_format);
154 tdfx_out32(COMMAND_2D, blitop);
155 tdfx_out32(COMMANDEXTRA_2D, use_colorkey);
156 tdfx_out32(DSTSIZE, dstrect->w | (dstrect->h << 16));
157 tdfx_out32(DSTXY, dstX | (dstY << 16));
158 tdfx_out32(LAUNCH_2D, srcX | (srcY << 16));
159
160 FB_AddBusySurface(src);
161 FB_AddBusySurface(dst);
162
163 if ( dst == this->screen ) {
164 SDL_mutexV(hw_lock);
165 }
166 return(0);
167}
168
169static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
170{
171 int accelerated;
172
173 /* Set initial acceleration on */
174 src->flags |= SDL_HWACCEL;
175
176 /* Set the surface attributes */
177 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
178 if ( ! this->info.blit_hw_A ) {
179 src->flags &= ~SDL_HWACCEL;
180 }
181 }
182 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
183 if ( ! this->info.blit_hw_CC ) {
184 src->flags &= ~SDL_HWACCEL;
185 }
186 }
187
188 /* Check to see if final surface blit is accelerated */
189 accelerated = !!(src->flags & SDL_HWACCEL);
190 if ( accelerated ) {
191 src->map->hw_blit = HWAccelBlit;
192 }
193 return(accelerated);
194}
195
196void FB_3DfxAccel(_THIS, __u32 card)
197{
198 /* We have hardware accelerated surface functions */
199 this->CheckHWBlit = CheckHWBlit;
200 wait_vbl = WaitVBL;
201 wait_idle = WaitIdle;
202
203 /* Reset the 3Dfx controller */
204 tdfx_out32(BRESERROR0, 0);
205 tdfx_out32(BRESERROR1, 0);
206
207 /* The 3Dfx has an accelerated color fill */
208 this->info.blit_fill = 1;
209 this->FillHWRect = FillHWRect;
210
211 /* The 3Dfx has accelerated normal and colorkey blits */
212 this->info.blit_hw = 1;
213 this->info.blit_hw_CC = 1;
214 this->SetHWColorKey = SetHWColorKey;
215}
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fb3dfx.h b/apps/plugins/sdl/src/video/fbcon/SDL_fb3dfx.h
deleted file mode 100644
index 4a59de9d80..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fb3dfx.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* 3Dfx hardware acceleration for the SDL framebuffer console driver */
25
26#include "SDL_fbvideo.h"
27
28/* Set up the driver for 3Dfx acceleration */
29extern void FB_3DfxAccel(_THIS, __u32 card);
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbelo.c b/apps/plugins/sdl/src/video/fbcon/SDL_fbelo.c
deleted file mode 100644
index 63dff87ce6..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbelo.c
+++ /dev/null
@@ -1,442 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include <unistd.h>
25#include <sys/time.h>
26#include <ctype.h>
27
28#include "SDL_stdinc.h"
29#include "SDL_fbvideo.h"
30#include "SDL_fbelo.h"
31
32/*
33 calibration default values
34 values are read from the following environment variables:
35
36 SDL_ELO_MIN_X
37 SDL_ELO_MAX_X
38 SDL_ELO_MIN_Y
39 SDL_ELO_MAX_Y
40*/
41
42static int ELO_MIN_X = 400;
43static int ELO_MAX_X = 3670;
44static int ELO_MIN_Y = 500;
45static int ELO_MAX_Y = 3540;
46
47#define ELO_SNAP_SIZE 6
48#define ELO_TOUCH_BYTE 'T'
49#define ELO_ID 'I'
50#define ELO_MODE 'M'
51#define ELO_PARAMETER 'P'
52#define ELO_REPORT 'B'
53#define ELO_ACK 'A'
54
55#define ELO_INIT_CHECKSUM 0xAA
56
57#define ELO_BTN_PRESS 0x01
58#define ELO_STREAM 0x02
59#define ELO_BTN_RELEASE 0x04
60
61#define ELO_TOUCH_MODE 0x01
62#define ELO_STREAM_MODE 0x02
63#define ELO_UNTOUCH_MODE 0x04
64#define ELO_RANGE_CHECK_MODE 0x40
65#define ELO_TRIM_MODE 0x02
66#define ELO_CALIB_MODE 0x04
67#define ELO_SCALING_MODE 0x08
68#define ELO_TRACKING_MODE 0x40
69
70#define ELO_SERIAL_MASK 0xF8
71
72#define ELO_SERIAL_IO '0'
73
74#define ELO_MAX_TRIALS 3
75#define ELO_MAX_WAIT 100000
76#define ELO_UNTOUCH_DELAY 5
77#define ELO_REPORT_DELAY 1
78
79/* eloParsePacket
80*/
81int eloParsePacket(unsigned char* mousebuf, int* dx, int* dy, int* button_state) {
82 static int elo_button = 0;
83 static int last_x = 0;
84 static int last_y = 0;
85 int x,y;
86
87 /* Check if we have a touch packet */
88 if (mousebuf[1] != ELO_TOUCH_BYTE) {
89 return 0;
90 }
91
92 x = ((mousebuf[4] << 8) | mousebuf[3]);
93 y = ((mousebuf[6] << 8) | mousebuf[5]);
94
95 if((SDL_abs(x - last_x) > ELO_SNAP_SIZE) || (SDL_abs(y - last_y) > ELO_SNAP_SIZE)) {
96 *dx = ((mousebuf[4] << 8) | mousebuf[3]);
97 *dy = ((mousebuf[6] << 8) | mousebuf[5]);
98 }
99 else {
100 *dx = last_x;
101 *dy = last_y;
102 }
103
104 last_x = *dx;
105 last_y = *dy;
106
107 if ( (mousebuf[2] & 0x07) == ELO_BTN_PRESS ) {
108 elo_button = 1;
109 }
110 if ( (mousebuf[2] & 0x07) == ELO_BTN_RELEASE ) {
111 elo_button = 0;
112 }
113
114 *button_state = elo_button;
115 return 1;
116}
117
118/* Convert the raw coordinates from the ELO controller
119 to a screen position.
120*/
121void eloConvertXY(_THIS, int *dx, int *dy) {
122 int input_x = *dx;
123 int input_y = *dy;
124 int width = ELO_MAX_X - ELO_MIN_X;
125 int height = ELO_MAX_Y - ELO_MIN_Y;
126
127 *dx = ((int)cache_vinfo.xres - ((int)cache_vinfo.xres * (input_x - ELO_MIN_X)) / width);
128 *dy = (cache_vinfo.yres * (input_y - ELO_MIN_Y)) / height;
129}
130
131
132/* eloGetPacket
133*/
134int eloGetPacket(unsigned char* buffer, int* buffer_p, int* checksum, int fd) {
135 int num_bytes;
136 int ok;
137
138 if(fd == 0) {
139 num_bytes = ELO_PACKET_SIZE;
140 }
141 else {
142 num_bytes = read(fd,
143 (char *) (buffer + *buffer_p),
144 ELO_PACKET_SIZE - *buffer_p);
145 }
146
147 if (num_bytes < 0) {
148#ifdef DEBUG_MOUSE
149 fprintf(stderr, "System error while reading from Elographics touchscreen.\n");
150#endif
151 return 0;
152 }
153
154 while (num_bytes) {
155 if ((*buffer_p == 0) && (buffer[0] != ELO_START_BYTE)) {
156 SDL_memcpy(&buffer[0], &buffer[1], num_bytes-1);
157 }
158 else {
159 if (*buffer_p < ELO_PACKET_SIZE-1) {
160 *checksum = *checksum + buffer[*buffer_p];
161 *checksum = *checksum % 256;
162 }
163 (*buffer_p)++;
164 }
165 num_bytes--;
166 }
167
168 if (*buffer_p == ELO_PACKET_SIZE) {
169 ok = (*checksum == buffer[ELO_PACKET_SIZE-1]);
170 *checksum = ELO_INIT_CHECKSUM;
171 *buffer_p = 0;
172
173 if (!ok) {
174 return 0;
175 }
176
177 return 1;
178 }
179 else {
180 return 0;
181 }
182}
183
184/* eloSendPacket
185*/
186
187int eloSendPacket(unsigned char* packet, int fd)
188{
189 int i, result;
190 int sum = ELO_INIT_CHECKSUM;
191
192 packet[0] = ELO_START_BYTE;
193 for (i = 0; i < ELO_PACKET_SIZE-1; i++) {
194 sum += packet[i];
195 sum &= 0xFF;
196 }
197 packet[ELO_PACKET_SIZE-1] = sum;
198
199 result = write(fd, packet, ELO_PACKET_SIZE);
200
201 if (result != ELO_PACKET_SIZE) {
202#ifdef DEBUG_MOUSE
203 printf("System error while sending to Elographics touchscreen.\n");
204#endif
205 return 0;
206 }
207 else {
208 return 1;
209 }
210}
211
212
213/* eloWaitForInput
214 */
215int eloWaitForInput(int fd, int timeout)
216{
217 fd_set readfds;
218 struct timeval to;
219 int r;
220
221 FD_ZERO(&readfds);
222 FD_SET(fd, &readfds);
223 to.tv_sec = 0;
224 to.tv_usec = timeout;
225
226 r = select(FD_SETSIZE, &readfds, NULL, NULL, &to);
227 return r;
228}
229
230/* eloWaitReply
231 */
232int eloWaitReply(unsigned char type, unsigned char *reply, int fd) {
233 int ok;
234 int i, result;
235 int reply_p = 0;
236 int sum = ELO_INIT_CHECKSUM;
237
238 i = ELO_MAX_TRIALS;
239 do {
240 ok = 0;
241
242 result = eloWaitForInput(fd, ELO_MAX_WAIT);
243
244 if (result > 0) {
245 ok = eloGetPacket(reply, &reply_p, &sum, fd);
246
247 if (ok && reply[1] != type && type != ELO_PARAMETER) {
248#ifdef DEBUG_MOUSE
249 fprintf(stderr, "Wrong reply received\n");
250#endif
251 ok = 0;
252 }
253 }
254 else {
255#ifdef DEBUG_MOUSE
256 fprintf(stderr, "No input!\n");
257#endif
258 }
259
260 if (result == 0) {
261 i--;
262 }
263 } while(!ok && (i>0));
264
265 return ok;
266}
267
268
269/* eloWaitAck
270 */
271
272int eloWaitAck(int fd) {
273 unsigned char packet[ELO_PACKET_SIZE];
274 int i, nb_errors;
275
276 if (eloWaitReply(ELO_ACK, packet, fd)) {
277 for (i = 0, nb_errors = 0; i < 4; i++) {
278 if (packet[2 + i] != '0') {
279 nb_errors++;
280 }
281 }
282
283 if (nb_errors != 0) {
284#ifdef DEBUG_MOUSE
285 fprintf(stderr, "Elographics acknowledge packet reports %d errors\n", nb_errors);
286#endif
287 }
288 return 1;
289 }
290 else {
291 return 0;
292 }
293}
294
295
296/* eloSendQuery --
297*/
298int eloSendQuery(unsigned char *request, unsigned char* reply, int fd) {
299 int ok;
300
301 if (eloSendPacket(request, fd)) {
302 ok = eloWaitReply(toupper(request[1]), reply, fd);
303 if (ok) {
304 ok = eloWaitAck(fd);
305 }
306 return ok;
307 }
308 else {
309 return 0;
310 }
311}
312
313
314/* eloSendControl
315*/
316int eloSendControl(unsigned char* control, int fd) {
317 if (eloSendPacket(control, fd)) {
318 return eloWaitAck(fd);
319 }
320 else {
321 return 0;
322 }
323}
324
325/* eloInitController
326*/
327int eloInitController(int fd) {
328 unsigned char req[ELO_PACKET_SIZE];
329 unsigned char reply[ELO_PACKET_SIZE];
330 const char *buffer = NULL;
331 int result = 0;
332
333 struct termios mouse_termios;
334
335 /* try to read the calibration values */
336 buffer = SDL_getenv("SDL_ELO_MIN_X");
337 if(buffer) {
338 ELO_MIN_X = SDL_atoi(buffer);
339 }
340 buffer = SDL_getenv("SDL_ELO_MAX_X");
341 if(buffer) {
342 ELO_MAX_X = SDL_atoi(buffer);
343 }
344 buffer = SDL_getenv("SDL_ELO_MIN_Y");
345 if(buffer) {
346 ELO_MIN_Y = SDL_atoi(buffer);
347 }
348 buffer = SDL_getenv("SDL_ELO_MAX_Y");
349 if(buffer) {
350 ELO_MAX_Y = SDL_atoi(buffer);
351 }
352
353#ifdef DEBUG_MOUSE
354 fprintf( stderr, "ELO calibration values:\nmin_x: %i\nmax_x: %i\nmin_y: %i\nmax_y: %i\n",
355 ELO_MIN_X,
356 ELO_MAX_X,
357 ELO_MIN_Y,
358 ELO_MAX_Y);
359#endif
360
361 /* set comm params */
362 SDL_memset(&mouse_termios, 0, sizeof(mouse_termios));
363 mouse_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
364 mouse_termios.c_cc[VMIN] = 1;
365 result = tcsetattr(fd, TCSANOW, &mouse_termios);
366
367 if (result < 0) {
368#ifdef DEBUG_MOUSE
369 fprintf( stderr, "Unable to configure Elographics touchscreen port\n");
370#endif
371 return 0;
372 }
373
374 SDL_memset(req, 0, ELO_PACKET_SIZE);
375 req[1] = tolower(ELO_PARAMETER);
376 if (!eloSendQuery(req, reply, fd)) {
377#ifdef DEBUG_MOUSE
378 fprintf( stderr, "Not at the specified rate or model 2310, will continue\n");
379#endif
380 }
381
382 SDL_memset(req, 0, ELO_PACKET_SIZE);
383 req[1] = tolower(ELO_ID);
384 if (eloSendQuery(req, reply, fd)) {
385#ifdef DEBUG_MOUSE
386 fprintf(stderr, "Ok, controller configured!\n");
387#endif
388 }
389 else {
390#ifdef DEBUG_MOUSE
391 fprintf( stderr, "Unable to ask Elographics touchscreen identification\n");
392#endif
393 return 0;
394 }
395
396 SDL_memset(req, 0, ELO_PACKET_SIZE);
397 req[1] = ELO_MODE;
398 req[3] = ELO_TOUCH_MODE | ELO_STREAM_MODE | ELO_UNTOUCH_MODE;
399 req[4] = ELO_TRACKING_MODE;
400 if (!eloSendControl(req, fd)) {
401#ifdef DEBUG_MOUSE
402 fprintf( stderr, "Unable to change Elographics touchscreen operating mode\n");
403#endif
404 return 0;
405 }
406
407 SDL_memset(req, 0, ELO_PACKET_SIZE);
408 req[1] = ELO_REPORT;
409 req[2] = ELO_UNTOUCH_DELAY;
410 req[3] = ELO_REPORT_DELAY;
411 if (!eloSendControl(req, fd)) {
412#ifdef DEBUG_MOUSE
413 fprintf( stderr, "Unable to change Elographics touchscreen reports timings\n");
414#endif
415 return 0;
416 }
417
418 return 1;
419}
420
421int eloReadPosition(_THIS, int fd, int* x, int* y, int* button_state, int* realx, int* realy) {
422 unsigned char buffer[ELO_PACKET_SIZE];
423 int pointer = 0;
424 int checksum = ELO_INIT_CHECKSUM;
425
426 while(pointer < ELO_PACKET_SIZE) {
427 if(eloGetPacket(buffer, &pointer, &checksum, fd)) {
428 break;
429 }
430 }
431
432 if(!eloParsePacket(buffer, realx, realy, button_state)) {
433 return 0;
434 }
435
436 *x = *realx;
437 *y = *realy;
438
439 eloConvertXY(this, x, y);
440
441 return 1;
442}
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbelo.h b/apps/plugins/sdl/src/video/fbcon/SDL_fbelo.h
deleted file mode 100644
index e7fde4ff2f..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbelo.h
+++ /dev/null
@@ -1,55 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef SDL_fbelo_h
25#define SDL_fbelo_h
26
27#include "SDL_fbvideo.h"
28
29/* ELO */
30#define ELO_PACKET_SIZE 10
31#define ELO_START_BYTE 'U'
32
33/* eloConvertXY
34 Convert the raw coordinates from the ELO controller
35 to a screen position.
36*/
37void eloConvertXY(_THIS, int *dx, int *dy);
38
39/* eloInitController(int fd)
40 Initialize the ELO serial touchscreen controller
41*/
42int eloInitController(int fd);
43
44/* eloParsePacket
45 extract position and button state from a packet
46*/
47int eloParsePacket(unsigned char* mousebuf, int* dx, int* dy, int* button_state);
48
49/* eloReadPosition
50 read a packet and get the cursor position
51*/
52
53int eloReadPosition(_THIS, int fd, int* x, int* y, int* button_state, int* realx, int* realy);
54
55#endif /* SDL_fbelo_h */
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbevents.c b/apps/plugins/sdl/src/video/fbcon/SDL_fbevents.c
deleted file mode 100644
index 5e369a4a89..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbevents.c
+++ /dev/null
@@ -1,1254 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* Handle the event stream, converting console events into SDL events */
25
26#include <stdio.h>
27#include <sys/types.h>
28#include <sys/time.h>
29#include <sys/ioctl.h>
30#include <unistd.h>
31#include <fcntl.h>
32#include <errno.h>
33#include <limits.h>
34
35/* For parsing /proc */
36#include <dirent.h>
37#include <ctype.h>
38
39#include <linux/vt.h>
40#include <linux/kd.h>
41#include <linux/keyboard.h>
42
43#include "SDL_timer.h"
44#include "SDL_mutex.h"
45#include "../SDL_sysvideo.h"
46#include "../../events/SDL_sysevents.h"
47#include "../../events/SDL_events_c.h"
48#include "SDL_fbvideo.h"
49#include "SDL_fbevents_c.h"
50#include "SDL_fbkeys.h"
51
52#include "SDL_fbelo.h"
53
54#ifndef GPM_NODE_FIFO
55#define GPM_NODE_FIFO "/dev/gpmdata"
56#endif
57
58/*#define DEBUG_KEYBOARD*/
59/*#define DEBUG_MOUSE*/
60
61/* The translation tables from a console scancode to a SDL keysym */
62#define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT)
63static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS];
64static SDLKey keymap[128];
65static Uint16 keymap_temp[128]; /* only used at startup */
66static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym);
67
68/* Ugh, we have to duplicate the kernel's keysym mapping code...
69 Oh, it's not so bad. :-)
70
71 FIXME: Add keyboard LED handling code
72 */
73static void FB_vgainitkeymaps(int fd)
74{
75 struct kbentry entry;
76 int map, i;
77
78 /* Don't do anything if we are passed a closed keyboard */
79 if ( fd < 0 ) {
80 return;
81 }
82
83 /* Load all the keysym mappings */
84 for ( map=0; map<NUM_VGAKEYMAPS; ++map ) {
85 SDL_memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16));
86 for ( i=0; i<NR_KEYS; ++i ) {
87 entry.kb_table = map;
88 entry.kb_index = i;
89 if ( ioctl(fd, KDGKBENT, &entry) == 0 ) {
90 /* fill keytemp. This replaces SDL_fbkeys.h */
91 if ( (map == 0) && (i<128) ) {
92 keymap_temp[i] = entry.kb_value;
93 }
94 /* The "Enter" key is a special case */
95 if ( entry.kb_value == K_ENTER ) {
96 entry.kb_value = K(KT_ASCII,13);
97 }
98 /* Handle numpad specially as well */
99 if ( KTYP(entry.kb_value) == KT_PAD ) {
100 switch ( entry.kb_value ) {
101 case K_P0:
102 case K_P1:
103 case K_P2:
104 case K_P3:
105 case K_P4:
106 case K_P5:
107 case K_P6:
108 case K_P7:
109 case K_P8:
110 case K_P9:
111 vga_keymap[map][i]=entry.kb_value;
112 vga_keymap[map][i]+= '0';
113 break;
114 case K_PPLUS:
115 vga_keymap[map][i]=K(KT_ASCII,'+');
116 break;
117 case K_PMINUS:
118 vga_keymap[map][i]=K(KT_ASCII,'-');
119 break;
120 case K_PSTAR:
121 vga_keymap[map][i]=K(KT_ASCII,'*');
122 break;
123 case K_PSLASH:
124 vga_keymap[map][i]=K(KT_ASCII,'/');
125 break;
126 case K_PENTER:
127 vga_keymap[map][i]=K(KT_ASCII,'\r');
128 break;
129 case K_PCOMMA:
130 vga_keymap[map][i]=K(KT_ASCII,',');
131 break;
132 case K_PDOT:
133 vga_keymap[map][i]=K(KT_ASCII,'.');
134 break;
135 default:
136 break;
137 }
138 }
139 /* Do the normal key translation */
140 if ( (KTYP(entry.kb_value) == KT_LATIN) ||
141 (KTYP(entry.kb_value) == KT_ASCII) ||
142 (KTYP(entry.kb_value) == KT_LETTER) ) {
143 vga_keymap[map][i] = entry.kb_value;
144 }
145 }
146 }
147 }
148}
149
150int FB_InGraphicsMode(_THIS)
151{
152 return((keyboard_fd >= 0) && (saved_kbd_mode >= 0));
153}
154
155int FB_EnterGraphicsMode(_THIS)
156{
157 struct termios keyboard_termios;
158
159 /* Set medium-raw keyboard mode */
160 if ( (keyboard_fd >= 0) && !FB_InGraphicsMode(this) ) {
161
162 /* Switch to the correct virtual terminal */
163 if ( current_vt > 0 ) {
164 struct vt_stat vtstate;
165
166 if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
167 saved_vt = vtstate.v_active;
168 }
169 if ( ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0 ) {
170 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt);
171 }
172 }
173
174 /* Set the terminal input mode */
175 if ( tcgetattr(keyboard_fd, &saved_kbd_termios) < 0 ) {
176 SDL_SetError("Unable to get terminal attributes");
177 if ( keyboard_fd > 0 ) {
178 close(keyboard_fd);
179 }
180 keyboard_fd = -1;
181 return(-1);
182 }
183 if ( ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0 ) {
184 SDL_SetError("Unable to get current keyboard mode");
185 if ( keyboard_fd > 0 ) {
186 close(keyboard_fd);
187 }
188 keyboard_fd = -1;
189 return(-1);
190 }
191 keyboard_termios = saved_kbd_termios;
192 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG);
193 keyboard_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
194 keyboard_termios.c_cc[VMIN] = 0;
195 keyboard_termios.c_cc[VTIME] = 0;
196 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) {
197 FB_CloseKeyboard(this);
198 SDL_SetError("Unable to set terminal attributes");
199 return(-1);
200 }
201 /* This will fail if we aren't root or this isn't our tty */
202 if ( ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0 ) {
203 FB_CloseKeyboard(this);
204 SDL_SetError("Unable to set keyboard in raw mode");
205 return(-1);
206 }
207 if ( ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0 ) {
208 FB_CloseKeyboard(this);
209 SDL_SetError("Unable to set keyboard in graphics mode");
210 return(-1);
211 }
212 /* Prevent switching the virtual terminal */
213 ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
214 }
215 return(keyboard_fd);
216}
217
218void FB_LeaveGraphicsMode(_THIS)
219{
220 if ( FB_InGraphicsMode(this) ) {
221 ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
222 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode);
223 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios);
224 saved_kbd_mode = -1;
225
226 /* Head back over to the original virtual terminal */
227 ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
228 if ( saved_vt > 0 ) {
229 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt);
230 }
231 }
232}
233
234void FB_CloseKeyboard(_THIS)
235{
236 if ( keyboard_fd >= 0 ) {
237 FB_LeaveGraphicsMode(this);
238 if ( keyboard_fd > 0 ) {
239 close(keyboard_fd);
240 }
241 }
242 keyboard_fd = -1;
243}
244
245int FB_OpenKeyboard(_THIS)
246{
247 /* Open only if not already opened */
248 if ( keyboard_fd < 0 ) {
249 static const char * const tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
250 static const char * const vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
251 int i, tty0_fd;
252
253 /* Try to query for a free virtual terminal */
254 tty0_fd = -1;
255 for ( i=0; tty0[i] && (tty0_fd < 0); ++i ) {
256 tty0_fd = open(tty0[i], O_WRONLY, 0);
257 }
258 if ( tty0_fd < 0 ) {
259 tty0_fd = dup(0); /* Maybe stdin is a VT? */
260 }
261 ioctl(tty0_fd, VT_OPENQRY, &current_vt);
262 close(tty0_fd);
263 if ( (geteuid() == 0) && (current_vt > 0) ) {
264 for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) {
265 char vtpath[12];
266
267 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], current_vt);
268 keyboard_fd = open(vtpath, O_RDWR, 0);
269#ifdef DEBUG_KEYBOARD
270 fprintf(stderr, "vtpath = %s, fd = %d\n",
271 vtpath, keyboard_fd);
272#endif /* DEBUG_KEYBOARD */
273
274 /* This needs to be our controlling tty
275 so that the kernel ioctl() calls work
276 */
277 if ( keyboard_fd >= 0 ) {
278 tty0_fd = open("/dev/tty", O_RDWR, 0);
279 if ( tty0_fd >= 0 ) {
280 ioctl(tty0_fd, TIOCNOTTY, 0);
281 close(tty0_fd);
282 }
283 }
284 }
285 }
286 if ( keyboard_fd < 0 ) {
287 /* Last resort, maybe our tty is a usable VT */
288 struct vt_stat vtstate;
289
290 keyboard_fd = open("/dev/tty", O_RDWR);
291
292 if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
293 current_vt = vtstate.v_active;
294 } else {
295 current_vt = 0;
296 }
297 }
298#ifdef DEBUG_KEYBOARD
299 fprintf(stderr, "Current VT: %d\n", current_vt);
300#endif
301 saved_kbd_mode = -1;
302
303 /* Make sure that our input is a console terminal */
304 { int dummy;
305 if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) {
306 close(keyboard_fd);
307 keyboard_fd = -1;
308 SDL_SetError("Unable to open a console terminal");
309 }
310 }
311
312 /* Set up keymap */
313 FB_vgainitkeymaps(keyboard_fd);
314 }
315 return(keyboard_fd);
316}
317
318static enum {
319 MOUSE_NONE = -1,
320 MOUSE_MSC, /* Note: GPM uses the MSC protocol */
321 MOUSE_PS2,
322 MOUSE_IMPS2,
323 MOUSE_MS,
324 MOUSE_BM,
325 MOUSE_ELO,
326 MOUSE_TSLIB,
327 NUM_MOUSE_DRVS
328} mouse_drv = MOUSE_NONE;
329
330void FB_CloseMouse(_THIS)
331{
332#if SDL_INPUT_TSLIB
333 if (ts_dev != NULL) {
334 ts_close(ts_dev);
335 ts_dev = NULL;
336 mouse_fd = -1;
337 }
338#endif /* SDL_INPUT_TSLIB */
339 if ( mouse_fd > 0 ) {
340 close(mouse_fd);
341 }
342 mouse_fd = -1;
343}
344
345/* Returns processes listed in /proc with the desired name */
346static int find_pid(DIR *proc, const char *wanted_name)
347{
348 struct dirent *entry;
349 int pid;
350
351 /* First scan proc for the gpm process */
352 pid = 0;
353 while ( (pid == 0) && ((entry=readdir(proc)) != NULL) ) {
354 if ( isdigit(entry->d_name[0]) ) {
355 FILE *status;
356 char path[PATH_MAX];
357 char name[PATH_MAX];
358
359 SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name);
360 status=fopen(path, "r");
361 if ( status ) {
362 int matches = 0;
363 name[0] = '\0';
364 matches = fscanf(status, "Name: %s", name);
365 if ( (matches == 1) && (SDL_strcmp(name, wanted_name) == 0) ) {
366 pid = SDL_atoi(entry->d_name);
367 }
368 fclose(status);
369 }
370 }
371 }
372 return pid;
373}
374
375/* Returns true if /dev/gpmdata is being written to by gpm */
376static int gpm_available(char *proto, size_t protolen)
377{
378 int available;
379 DIR *proc;
380 int pid;
381 int cmdline, len, arglen;
382 char path[PATH_MAX];
383 char args[PATH_MAX], *arg;
384
385 /* Don't bother looking if the fifo isn't there */
386#ifdef DEBUG_MOUSE
387 fprintf(stderr,"testing gpm\n");
388#endif
389 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) {
390 return(0);
391 }
392
393 available = 0;
394 proc = opendir("/proc");
395 if ( proc ) {
396 char raw_proto[10] = { '\0' };
397 char repeat_proto[10] = { '\0' };
398 while ( !available && (pid=find_pid(proc, "gpm")) > 0 ) {
399 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
400 cmdline = open(path, O_RDONLY, 0);
401 if ( cmdline >= 0 ) {
402 len = read(cmdline, args, sizeof(args));
403 arg = args;
404 while ( len > 0 ) {
405 arglen = SDL_strlen(arg)+1;
406#ifdef DEBUG_MOUSE
407 fprintf(stderr,"gpm arg %s len %d\n",arg,arglen);
408#endif
409 if ( SDL_strcmp(arg, "-t") == 0) {
410 /* protocol string, keep it for later */
411 char *t, *s;
412 t = arg + arglen;
413 s = SDL_strchr(t, ' ');
414 if (s) *s = 0;
415 SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto));
416 if (s) *s = ' ';
417 }
418 if ( SDL_strncmp(arg, "-R", 2) == 0 ) {
419 char *t, *s;
420 available = 1;
421 t = arg + 2;
422 s = SDL_strchr(t, ' ');
423 if (s) *s = 0;
424 SDL_strlcpy(repeat_proto, t, SDL_arraysize(repeat_proto));
425 if (s) *s = ' ';
426 }
427 len -= arglen;
428 arg += arglen;
429 }
430 close(cmdline);
431 }
432 }
433 closedir(proc);
434
435 if ( available ) {
436 if ( SDL_strcmp(repeat_proto, "raw") == 0 ) {
437 SDL_strlcpy(proto, raw_proto, protolen);
438 } else if ( *repeat_proto ) {
439 SDL_strlcpy(proto, repeat_proto, protolen);
440 } else {
441 SDL_strlcpy(proto, "msc", protolen);
442 }
443 }
444 }
445 return available;
446}
447
448
449/* rcg06112001 Set up IMPS/2 mode, if possible. This gives
450 * us access to the mousewheel, etc. Returns zero if
451 * writes to device failed, but you still need to query the
452 * device to see which mode it's actually in.
453 */
454static int set_imps2_mode(int fd)
455{
456 /* If you wanted to control the mouse mode (and we do :) ) ...
457 Set IMPS/2 protocol:
458 {0xf3,200,0xf3,100,0xf3,80}
459 Reset mouse device:
460 {0xFF}
461 */
462 Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};
463 /*Uint8 reset = 0xff;*/
464 fd_set fdset;
465 struct timeval tv;
466 int retval = 0;
467
468 if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) {
469 /* Don't reset it, that'll clear IMPS/2 mode on some mice
470 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) {
471 retval = 1;
472 }
473 */
474 }
475
476 /* Get rid of any chatter from the above */
477 FD_ZERO(&fdset);
478 FD_SET(fd, &fdset);
479 tv.tv_sec = 0;
480 tv.tv_usec = 0;
481 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
482 char temp[32];
483 if (read(fd, temp, sizeof(temp)) <= 0) {
484 break;
485 }
486 }
487
488 return retval;
489}
490
491
492/* Returns true if the mouse uses the IMPS/2 protocol */
493static int detect_imps2(int fd)
494{
495 int imps2;
496
497 imps2 = 0;
498
499 if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) {
500 imps2 = 1;
501 }
502 if ( ! imps2 ) {
503 Uint8 query_ps2 = 0xF2;
504 fd_set fdset;
505 struct timeval tv;
506
507 /* Get rid of any mouse motion noise */
508 FD_ZERO(&fdset);
509 FD_SET(fd, &fdset);
510 tv.tv_sec = 0;
511 tv.tv_usec = 0;
512 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
513 char temp[32];
514 if (read(fd, temp, sizeof(temp)) <= 0) {
515 break;
516 }
517 }
518
519 /* Query for the type of mouse protocol */
520 if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) {
521 Uint8 ch = 0;
522
523 /* Get the mouse protocol response */
524 do {
525 FD_ZERO(&fdset);
526 FD_SET(fd, &fdset);
527 tv.tv_sec = 1;
528 tv.tv_usec = 0;
529 if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) {
530 break;
531 }
532 } while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) &&
533 ((ch == 0xFA) || (ch == 0xAA)) );
534
535 /* Experimental values (Logitech wheelmouse) */
536#ifdef DEBUG_MOUSE
537fprintf(stderr, "Last mouse mode: 0x%x\n", ch);
538#endif
539 if ( (ch == 3) || (ch == 4) ) {
540 imps2 = 1;
541 }
542 }
543 }
544 return imps2;
545}
546
547int FB_OpenMouse(_THIS)
548{
549 int i;
550 const char *mousedev;
551 const char *mousedrv;
552
553 mousedrv = SDL_getenv("SDL_MOUSEDRV");
554 mousedev = SDL_getenv("SDL_MOUSEDEV");
555 mouse_fd = -1;
556
557#if SDL_INPUT_TSLIB
558 if ( mousedrv && (SDL_strcmp(mousedrv, "TSLIB") == 0) ) {
559 if (mousedev == NULL) mousedev = SDL_getenv("TSLIB_TSDEVICE");
560 if (mousedev != NULL) {
561 ts_dev = ts_open(mousedev, 1);
562 if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) {
563#ifdef DEBUG_MOUSE
564 fprintf(stderr, "Using tslib touchscreen\n");
565#endif
566 mouse_drv = MOUSE_TSLIB;
567 mouse_fd = ts_fd(ts_dev);
568 return mouse_fd;
569 }
570 }
571 mouse_drv = MOUSE_NONE;
572 return mouse_fd;
573 }
574#endif /* SDL_INPUT_TSLIB */
575
576 /* ELO TOUCHSCREEN SUPPORT */
577
578 if ( mousedrv && (SDL_strcmp(mousedrv, "ELO") == 0) ) {
579 mouse_fd = open(mousedev, O_RDWR);
580 if ( mouse_fd >= 0 ) {
581 if(eloInitController(mouse_fd)) {
582#ifdef DEBUG_MOUSE
583fprintf(stderr, "Using ELO touchscreen\n");
584#endif
585 mouse_drv = MOUSE_ELO;
586 }
587
588 }
589 else if ( mouse_fd < 0 ) {
590 mouse_drv = MOUSE_NONE;
591 }
592
593 return(mouse_fd);
594 }
595
596 /* STD MICE */
597
598 if ( mousedev == NULL ) {
599 /* FIXME someday... allow multiple mice in this driver */
600 static const char *ps2mice[] = {
601 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL
602 };
603 /* First try to use GPM in repeater mode */
604 if ( mouse_fd < 0 ) {
605 char proto[10];
606 if ( gpm_available(proto, SDL_arraysize(proto)) ) {
607 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);
608 if ( mouse_fd >= 0 ) {
609 if ( SDL_strcmp(proto, "msc") == 0 ) {
610 mouse_drv = MOUSE_MSC;
611 } else if ( SDL_strcmp(proto, "ps2") == 0 ) {
612 mouse_drv = MOUSE_PS2;
613 } else if ( SDL_strcmp(proto, "imps2") == 0 ) {
614 mouse_drv = MOUSE_IMPS2;
615 } else if ( SDL_strcmp(proto, "ms") == 0 ||
616 SDL_strcmp(proto, "bare") == 0 ) {
617 mouse_drv = MOUSE_MS;
618 } else if ( SDL_strcmp(proto, "bm") == 0 ) {
619 mouse_drv = MOUSE_BM;
620 } else {
621 /* Unknown protocol... */
622#ifdef DEBUG_MOUSE
623 fprintf(stderr, "GPM mouse using unknown protocol = %s\n", proto);
624#endif
625 close(mouse_fd);
626 mouse_fd = -1;
627 }
628 }
629#ifdef DEBUG_MOUSE
630 if ( mouse_fd >= 0 ) {
631 fprintf(stderr, "Using GPM mouse, protocol = %s\n", proto);
632 }
633#endif /* DEBUG_MOUSE */
634 }
635 }
636 /* Now try to use a modern PS/2 mouse */
637 for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) {
638 mouse_fd = open(ps2mice[i], O_RDWR, 0);
639 if (mouse_fd < 0) {
640 mouse_fd = open(ps2mice[i], O_RDONLY, 0);
641 }
642 if (mouse_fd >= 0) {
643 /* rcg06112001 Attempt to set IMPS/2 mode */
644 set_imps2_mode(mouse_fd);
645 if (detect_imps2(mouse_fd)) {
646#ifdef DEBUG_MOUSE
647fprintf(stderr, "Using IMPS2 mouse\n");
648#endif
649 mouse_drv = MOUSE_IMPS2;
650 } else {
651#ifdef DEBUG_MOUSE
652fprintf(stderr, "Using PS2 mouse\n");
653#endif
654 mouse_drv = MOUSE_PS2;
655 }
656 }
657 }
658 /* Next try to use a PPC ADB port mouse */
659 if ( mouse_fd < 0 ) {
660 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0);
661 if ( mouse_fd >= 0 ) {
662#ifdef DEBUG_MOUSE
663fprintf(stderr, "Using ADB mouse\n");
664#endif
665 mouse_drv = MOUSE_BM;
666 }
667 }
668 }
669 /* Default to a serial Microsoft mouse */
670 if ( mouse_fd < 0 ) {
671 if ( mousedev == NULL ) {
672 mousedev = "/dev/mouse";
673 }
674 mouse_fd = open(mousedev, O_RDONLY, 0);
675 if ( mouse_fd >= 0 ) {
676 struct termios mouse_termios;
677
678 /* Set the sampling speed to 1200 baud */
679 tcgetattr(mouse_fd, &mouse_termios);
680 mouse_termios.c_iflag = IGNBRK | IGNPAR;
681 mouse_termios.c_oflag = 0;
682 mouse_termios.c_lflag = 0;
683 mouse_termios.c_line = 0;
684 mouse_termios.c_cc[VTIME] = 0;
685 mouse_termios.c_cc[VMIN] = 1;
686 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL;
687 mouse_termios.c_cflag |= CS8;
688 mouse_termios.c_cflag |= B1200;
689 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios);
690 if ( mousedrv && (SDL_strcmp(mousedrv, "PS2") == 0) ) {
691#ifdef DEBUG_MOUSE
692fprintf(stderr, "Using (user specified) PS2 mouse on %s\n", mousedev);
693#endif
694 mouse_drv = MOUSE_PS2;
695 } else {
696#ifdef DEBUG_MOUSE
697fprintf(stderr, "Using (default) MS mouse on %s\n", mousedev);
698#endif
699 mouse_drv = MOUSE_MS;
700 }
701 }
702 }
703 if ( mouse_fd < 0 ) {
704 mouse_drv = MOUSE_NONE;
705 }
706 return(mouse_fd);
707}
708
709static int posted = 0;
710
711void FB_vgamousecallback(int button, int relative, int dx, int dy)
712{
713 int button_1, button_3;
714 int button_state;
715 int state_changed;
716 int i;
717 Uint8 state;
718
719 if ( dx || dy ) {
720 posted += SDL_PrivateMouseMotion(0, relative, dx, dy);
721 }
722
723 /* Swap button 1 and 3 */
724 button_1 = (button & 0x04) >> 2;
725 button_3 = (button & 0x01) << 2;
726 button &= ~0x05;
727 button |= (button_1|button_3);
728
729 /* See what changed */
730 button_state = SDL_GetMouseState(NULL, NULL);
731 state_changed = button_state ^ button;
732 for ( i=0; i<8; ++i ) {
733 if ( state_changed & (1<<i) ) {
734 if ( button & (1<<i) ) {
735 state = SDL_PRESSED;
736 } else {
737 state = SDL_RELEASED;
738 }
739 posted += SDL_PrivateMouseButton(state, i+1, 0, 0);
740 }
741 }
742}
743
744/* Handle input from tslib */
745#if SDL_INPUT_TSLIB
746static void handle_tslib(_THIS)
747{
748 struct ts_sample sample;
749 int button;
750
751 while (ts_read(ts_dev, &sample, 1) > 0) {
752 button = (sample.pressure > 0) ? 1 : 0;
753 button <<= 2; /* must report it as button 3 */
754 FB_vgamousecallback(button, 0, sample.x, sample.y);
755 }
756 return;
757}
758#endif /* SDL_INPUT_TSLIB */
759
760/* For now, use MSC, PS/2, and MS protocols
761 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.)
762 */
763static void handle_mouse(_THIS)
764{
765 static int start = 0;
766 static unsigned char mousebuf[BUFSIZ];
767 static int relative = 1;
768
769 int i, nread;
770 int button = 0;
771 int dx = 0, dy = 0;
772 int packetsize = 0;
773 int realx, realy;
774
775 /* Figure out the mouse packet size */
776 switch (mouse_drv) {
777 case MOUSE_NONE:
778 break; /* carry on to read from device and discard it. */
779 case MOUSE_MSC:
780 packetsize = 5;
781 break;
782 case MOUSE_IMPS2:
783 packetsize = 4;
784 break;
785 case MOUSE_PS2:
786 case MOUSE_MS:
787 case MOUSE_BM:
788 packetsize = 3;
789 break;
790 case MOUSE_ELO:
791 /* try to read the next packet */
792 if(eloReadPosition(this, mouse_fd, &dx, &dy, &button, &realx, &realy)) {
793 button = (button & 0x01) << 2;
794 FB_vgamousecallback(button, 0, dx, dy);
795 }
796 return; /* nothing left to do */
797 case MOUSE_TSLIB:
798#if SDL_INPUT_TSLIB
799 handle_tslib(this);
800#endif
801 return; /* nothing left to do */
802 default:
803 /* Uh oh.. */
804 packetsize = 0;
805 break;
806 }
807
808 /* Special handling for the quite sensitive ELO controller */
809 if (mouse_drv == MOUSE_ELO) {
810
811 }
812
813 /* Read as many packets as possible */
814 nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start);
815 if ( nread < 0 ) {
816 return;
817 }
818
819 if (mouse_drv == MOUSE_NONE) {
820 return; /* we're done; just draining the input queue. */
821 }
822
823 nread += start;
824#ifdef DEBUG_MOUSE
825 fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start);
826#endif
827
828 for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) {
829 switch (mouse_drv) {
830 case MOUSE_NONE: /* shouldn't actually hit this. */
831 break; /* just throw everything away. */
832 case MOUSE_MSC:
833 /* MSC protocol has 0x80 in high byte */
834 if ( (mousebuf[i] & 0xF8) != 0x80 ) {
835 /* Go to next byte */
836 i -= (packetsize-1);
837 continue;
838 }
839 /* Get current mouse state */
840 button = (~mousebuf[i]) & 0x07;
841 dx = (signed char)(mousebuf[i+1]) +
842 (signed char)(mousebuf[i+3]);
843 dy = -((signed char)(mousebuf[i+2]) +
844 (signed char)(mousebuf[i+4]));
845 break;
846 case MOUSE_PS2:
847 /* PS/2 protocol has nothing in high byte */
848 if ( (mousebuf[i] & 0xC0) != 0 ) {
849 /* Go to next byte */
850 i -= (packetsize-1);
851 continue;
852 }
853 /* Get current mouse state */
854 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/
855 (mousebuf[i] & 0x02) >> 1 | /*Right*/
856 (mousebuf[i] & 0x01) << 2; /*Left*/
857 dx = (mousebuf[i] & 0x10) ?
858 mousebuf[i+1] - 256 : mousebuf[i+1];
859 dy = (mousebuf[i] & 0x20) ?
860 -(mousebuf[i+2] - 256) : -mousebuf[i+2];
861 break;
862 case MOUSE_IMPS2:
863 /* Get current mouse state */
864 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/
865 (mousebuf[i] & 0x02) >> 1 | /*Right*/
866 (mousebuf[i] & 0x01) << 2 | /*Left*/
867 (mousebuf[i] & 0x40) >> 3 | /* 4 */
868 (mousebuf[i] & 0x80) >> 3; /* 5 */
869 dx = (mousebuf[i] & 0x10) ?
870 mousebuf[i+1] - 256 : mousebuf[i+1];
871 dy = (mousebuf[i] & 0x20) ?
872 -(mousebuf[i+2] - 256) : -mousebuf[i+2];
873 switch (mousebuf[i+3]&0x0F) {
874 case 0x0E: /* DX = +1 */
875 case 0x02: /* DX = -1 */
876 break;
877 case 0x0F: /* DY = +1 (map button 4) */
878 FB_vgamousecallback(button | (1<<3),
879 1, 0, 0);
880 break;
881 case 0x01: /* DY = -1 (map button 5) */
882 FB_vgamousecallback(button | (1<<4),
883 1, 0, 0);
884 break;
885 }
886 break;
887 case MOUSE_MS:
888 /* Microsoft protocol has 0x40 in high byte */
889 if ( (mousebuf[i] & 0x40) != 0x40 ) {
890 /* Go to next byte */
891 i -= (packetsize-1);
892 continue;
893 }
894 /* Get current mouse state */
895 button = ((mousebuf[i] & 0x20) >> 3) |
896 ((mousebuf[i] & 0x10) >> 4);
897 dx = (signed char)(((mousebuf[i] & 0x03) << 6) |
898 (mousebuf[i + 1] & 0x3F));
899 dy = (signed char)(((mousebuf[i] & 0x0C) << 4) |
900 (mousebuf[i + 2] & 0x3F));
901 break;
902 case MOUSE_BM:
903 /* BusMouse protocol has 0xF8 in high byte */
904 if ( (mousebuf[i] & 0xF8) != 0x80 ) {
905 /* Go to next byte */
906 i -= (packetsize-1);
907 continue;
908 }
909 /* Get current mouse state */
910 button = (~mousebuf[i]) & 0x07;
911 dx = (signed char)mousebuf[i+1];
912 dy = -(signed char)mousebuf[i+2];
913 break;
914 default:
915 /* Uh oh.. */
916 dx = 0;
917 dy = 0;
918 break;
919 }
920 FB_vgamousecallback(button, relative, dx, dy);
921 }
922 if ( i < nread ) {
923 SDL_memcpy(mousebuf, &mousebuf[i], (nread-i));
924 start = (nread-i);
925 } else {
926 start = 0;
927 }
928 return;
929}
930
931/* Handle switching to another VC, returns when our VC is back */
932static void switch_vt_prep(_THIS)
933{
934 SDL_Surface *screen = SDL_VideoSurface;
935
936 SDL_PrivateAppActive(0, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
937
938 /* Save the contents of the screen, and go to text mode */
939 wait_idle(this);
940 screen_arealen = ((screen->h + (2*this->offset_y)) * screen->pitch);
941 screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
942 if ( screen_contents ) {
943 SDL_memcpy(screen_contents, screen->pixels, screen_arealen);
944 }
945 FB_SavePaletteTo(this, 256, screen_palette);
946 ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo);
947 ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
948 ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
949}
950static void switch_vt_done(_THIS)
951{
952 SDL_Surface *screen = SDL_VideoSurface;
953
954 /* Restore graphics mode and the contents of the screen */
955 ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
956 ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
957 ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo);
958 FB_RestorePaletteFrom(this, 256, screen_palette);
959 if ( screen_contents ) {
960 SDL_memcpy(screen->pixels, screen_contents, screen_arealen);
961 SDL_free(screen_contents);
962 screen_contents = NULL;
963 }
964
965 /* Get updates to the shadow surface while switched away */
966 if ( SDL_ShadowSurface ) {
967 SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
968 }
969
970 SDL_PrivateAppActive(1, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
971}
972static void switch_vt(_THIS, unsigned short which)
973{
974 struct vt_stat vtstate;
975
976 /* Figure out whether or not we're switching to a new console */
977 if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
978 (which == vtstate.v_active) ) {
979 return;
980 }
981
982 /* New console, switch to it */
983 SDL_mutexP(hw_lock);
984 switch_vt_prep(this);
985 if ( ioctl(keyboard_fd, VT_ACTIVATE, which) == 0 ) {
986 ioctl(keyboard_fd, VT_WAITACTIVE, which);
987 switched_away = 1;
988 } else {
989 switch_vt_done(this);
990 }
991 SDL_mutexV(hw_lock);
992}
993
994static void handle_keyboard(_THIS)
995{
996 unsigned char keybuf[BUFSIZ];
997 int i, nread;
998 int pressed;
999 int scancode;
1000 SDL_keysym keysym;
1001
1002 nread = read(keyboard_fd, keybuf, BUFSIZ);
1003 for ( i=0; i<nread; ++i ) {
1004 scancode = keybuf[i] & 0x7F;
1005 if ( keybuf[i] & 0x80 ) {
1006 pressed = SDL_RELEASED;
1007 } else {
1008 pressed = SDL_PRESSED;
1009 }
1010 TranslateKey(scancode, &keysym);
1011 /* Handle Ctrl-Alt-FN for vt switch */
1012 switch (keysym.sym) {
1013 case SDLK_F1:
1014 case SDLK_F2:
1015 case SDLK_F3:
1016 case SDLK_F4:
1017 case SDLK_F5:
1018 case SDLK_F6:
1019 case SDLK_F7:
1020 case SDLK_F8:
1021 case SDLK_F9:
1022 case SDLK_F10:
1023 case SDLK_F11:
1024 case SDLK_F12:
1025 if ( (SDL_GetModState() & KMOD_CTRL) &&
1026 (SDL_GetModState() & KMOD_ALT) ) {
1027 if ( pressed ) {
1028 switch_vt(this, (keysym.sym-SDLK_F1)+1);
1029 }
1030 break;
1031 }
1032 /* Fall through to normal processing */
1033 default:
1034 posted += SDL_PrivateKeyboard(pressed, &keysym);
1035 break;
1036 }
1037 }
1038}
1039
1040void FB_PumpEvents(_THIS)
1041{
1042 fd_set fdset;
1043 int max_fd;
1044 static struct timeval zero;
1045
1046 do {
1047 if ( switched_away ) {
1048 struct vt_stat vtstate;
1049
1050 SDL_mutexP(hw_lock);
1051 if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) &&
1052 vtstate.v_active == current_vt ) {
1053 switched_away = 0;
1054 switch_vt_done(this);
1055 }
1056 SDL_mutexV(hw_lock);
1057 }
1058
1059 posted = 0;
1060
1061 FD_ZERO(&fdset);
1062 max_fd = 0;
1063 if ( keyboard_fd >= 0 ) {
1064 FD_SET(keyboard_fd, &fdset);
1065 if ( max_fd < keyboard_fd ) {
1066 max_fd = keyboard_fd;
1067 }
1068 }
1069 if ( mouse_fd >= 0 ) {
1070 FD_SET(mouse_fd, &fdset);
1071 if ( max_fd < mouse_fd ) {
1072 max_fd = mouse_fd;
1073 }
1074 }
1075 if ( select(max_fd+1, &fdset, NULL, NULL, &zero) > 0 ) {
1076 if ( keyboard_fd >= 0 ) {
1077 if ( FD_ISSET(keyboard_fd, &fdset) ) {
1078 handle_keyboard(this);
1079 }
1080 }
1081 if ( mouse_fd >= 0 ) {
1082 if ( FD_ISSET(mouse_fd, &fdset) ) {
1083 handle_mouse(this);
1084 }
1085 }
1086 }
1087 } while ( posted );
1088}
1089
1090void FB_InitOSKeymap(_THIS)
1091{
1092 int i;
1093
1094 /* Initialize the Linux key translation table */
1095
1096 /* First get the ascii keys and others not well handled */
1097 for (i=0; i<SDL_arraysize(keymap); ++i) {
1098 switch(i) {
1099 /* These aren't handled by the x86 kernel keymapping (?) */
1100 case SCANCODE_PRINTSCREEN:
1101 keymap[i] = SDLK_PRINT;
1102 break;
1103 case SCANCODE_BREAK:
1104 keymap[i] = SDLK_BREAK;
1105 break;
1106 case SCANCODE_BREAK_ALTERNATIVE:
1107 keymap[i] = SDLK_PAUSE;
1108 break;
1109 case SCANCODE_LEFTSHIFT:
1110 keymap[i] = SDLK_LSHIFT;
1111 break;
1112 case SCANCODE_RIGHTSHIFT:
1113 keymap[i] = SDLK_RSHIFT;
1114 break;
1115 case SCANCODE_LEFTCONTROL:
1116 keymap[i] = SDLK_LCTRL;
1117 break;
1118 case SCANCODE_RIGHTCONTROL:
1119 keymap[i] = SDLK_RCTRL;
1120 break;
1121 case SCANCODE_RIGHTWIN:
1122 keymap[i] = SDLK_RSUPER;
1123 break;
1124 case SCANCODE_LEFTWIN:
1125 keymap[i] = SDLK_LSUPER;
1126 break;
1127 case SCANCODE_LEFTALT:
1128 keymap[i] = SDLK_LALT;
1129 break;
1130 case SCANCODE_RIGHTALT:
1131 keymap[i] = SDLK_RALT;
1132 break;
1133 case 127:
1134 keymap[i] = SDLK_MENU;
1135 break;
1136 /* this should take care of all standard ascii keys */
1137 default:
1138 keymap[i] = KVAL(vga_keymap[0][i]);
1139 break;
1140 }
1141 }
1142 for (i=0; i<SDL_arraysize(keymap); ++i) {
1143 switch(keymap_temp[i]) {
1144 case K_F1: keymap[i] = SDLK_F1; break;
1145 case K_F2: keymap[i] = SDLK_F2; break;
1146 case K_F3: keymap[i] = SDLK_F3; break;
1147 case K_F4: keymap[i] = SDLK_F4; break;
1148 case K_F5: keymap[i] = SDLK_F5; break;
1149 case K_F6: keymap[i] = SDLK_F6; break;
1150 case K_F7: keymap[i] = SDLK_F7; break;
1151 case K_F8: keymap[i] = SDLK_F8; break;
1152 case K_F9: keymap[i] = SDLK_F9; break;
1153 case K_F10: keymap[i] = SDLK_F10; break;
1154 case K_F11: keymap[i] = SDLK_F11; break;
1155 case K_F12: keymap[i] = SDLK_F12; break;
1156
1157 case K_DOWN: keymap[i] = SDLK_DOWN; break;
1158 case K_LEFT: keymap[i] = SDLK_LEFT; break;
1159 case K_RIGHT: keymap[i] = SDLK_RIGHT; break;
1160 case K_UP: keymap[i] = SDLK_UP; break;
1161
1162 case K_P0: keymap[i] = SDLK_KP0; break;
1163 case K_P1: keymap[i] = SDLK_KP1; break;
1164 case K_P2: keymap[i] = SDLK_KP2; break;
1165 case K_P3: keymap[i] = SDLK_KP3; break;
1166 case K_P4: keymap[i] = SDLK_KP4; break;
1167 case K_P5: keymap[i] = SDLK_KP5; break;
1168 case K_P6: keymap[i] = SDLK_KP6; break;
1169 case K_P7: keymap[i] = SDLK_KP7; break;
1170 case K_P8: keymap[i] = SDLK_KP8; break;
1171 case K_P9: keymap[i] = SDLK_KP9; break;
1172 case K_PPLUS: keymap[i] = SDLK_KP_PLUS; break;
1173 case K_PMINUS: keymap[i] = SDLK_KP_MINUS; break;
1174 case K_PSTAR: keymap[i] = SDLK_KP_MULTIPLY; break;
1175 case K_PSLASH: keymap[i] = SDLK_KP_DIVIDE; break;
1176 case K_PENTER: keymap[i] = SDLK_KP_ENTER; break;
1177 case K_PDOT: keymap[i] = SDLK_KP_PERIOD; break;
1178
1179 case K_SHIFT: if ( keymap[i] != SDLK_RSHIFT )
1180 keymap[i] = SDLK_LSHIFT;
1181 break;
1182 case K_SHIFTL: keymap[i] = SDLK_LSHIFT; break;
1183 case K_SHIFTR: keymap[i] = SDLK_RSHIFT; break;
1184 case K_CTRL: if ( keymap[i] != SDLK_RCTRL )
1185 keymap[i] = SDLK_LCTRL;
1186 break;
1187 case K_CTRLL: keymap[i] = SDLK_LCTRL; break;
1188 case K_CTRLR: keymap[i] = SDLK_RCTRL; break;
1189 case K_ALT: keymap[i] = SDLK_LALT; break;
1190 case K_ALTGR: keymap[i] = SDLK_RALT; break;
1191
1192 case K_INSERT: keymap[i] = SDLK_INSERT; break;
1193 case K_REMOVE: keymap[i] = SDLK_DELETE; break;
1194 case K_PGUP: keymap[i] = SDLK_PAGEUP; break;
1195 case K_PGDN: keymap[i] = SDLK_PAGEDOWN; break;
1196 case K_FIND: keymap[i] = SDLK_HOME; break;
1197 case K_SELECT: keymap[i] = SDLK_END; break;
1198
1199 case K_NUM: keymap[i] = SDLK_NUMLOCK; break;
1200 case K_CAPS: keymap[i] = SDLK_CAPSLOCK; break;
1201
1202 case K_F13: keymap[i] = SDLK_PRINT; break;
1203 case K_HOLD: keymap[i] = SDLK_SCROLLOCK; break;
1204 case K_PAUSE: keymap[i] = SDLK_PAUSE; break;
1205
1206 case 127: keymap[i] = SDLK_BACKSPACE; break;
1207
1208 default: break;
1209 }
1210 }
1211}
1212
1213static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
1214{
1215 /* Set the keysym information */
1216 keysym->scancode = scancode;
1217 keysym->sym = keymap[scancode];
1218 keysym->mod = KMOD_NONE;
1219
1220 /* If UNICODE is on, get the UNICODE value for the key */
1221 keysym->unicode = 0;
1222 if ( SDL_TranslateUNICODE ) {
1223 int map;
1224 SDLMod modstate;
1225
1226 modstate = SDL_GetModState();
1227 map = 0;
1228 if ( modstate & KMOD_SHIFT ) {
1229 map |= (1<<KG_SHIFT);
1230 }
1231 if ( modstate & KMOD_CTRL ) {
1232 map |= (1<<KG_CTRL);
1233 }
1234 if ( modstate & KMOD_LALT ) {
1235 map |= (1<<KG_ALT);
1236 }
1237 if ( modstate & KMOD_RALT ) {
1238 map |= (1<<KG_ALTGR);
1239 }
1240 if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) {
1241 if ( modstate & KMOD_CAPS ) {
1242 map ^= (1<<KG_SHIFT);
1243 }
1244 }
1245 if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) {
1246 if ( modstate & KMOD_NUM ) {
1247 keysym->unicode=KVAL(vga_keymap[map][scancode]);
1248 }
1249 } else {
1250 keysym->unicode = KVAL(vga_keymap[map][scancode]);
1251 }
1252 }
1253 return(keysym);
1254}
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbevents_c.h b/apps/plugins/sdl/src/video/fbcon/SDL_fbevents_c.h
deleted file mode 100644
index fe8b09cab3..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbevents_c.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_fbvideo.h"
25
26/* Variables and functions exported by SDL_sysevents.c to other parts
27 of the native video subsystem (SDL_sysvideo.c)
28*/
29extern int FB_OpenKeyboard(_THIS);
30extern void FB_CloseKeyboard(_THIS);
31extern int FB_OpenMouse(_THIS);
32extern void FB_CloseMouse(_THIS);
33extern int FB_EnterGraphicsMode(_THIS);
34extern int FB_InGraphicsMode(_THIS);
35extern void FB_LeaveGraphicsMode(_THIS);
36
37extern void FB_InitOSKeymap(_THIS);
38extern void FB_PumpEvents(_THIS);
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbkeys.h b/apps/plugins/sdl/src/video/fbcon/SDL_fbkeys.h
deleted file mode 100644
index 2b01b6b2e3..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbkeys.h
+++ /dev/null
@@ -1,139 +0,0 @@
1
2/* Scancodes for the Linux framebuffer console
3 - Taken with thanks from SVGAlib 1.4.0
4*/
5
6#define SCANCODE_ESCAPE 1
7
8#define SCANCODE_1 2
9#define SCANCODE_2 3
10#define SCANCODE_3 4
11#define SCANCODE_4 5
12#define SCANCODE_5 6
13#define SCANCODE_6 7
14#define SCANCODE_7 8
15#define SCANCODE_8 9
16#define SCANCODE_9 10
17#define SCANCODE_0 11
18
19#define SCANCODE_MINUS 12
20#define SCANCODE_EQUAL 13
21
22#define SCANCODE_BACKSPACE 14
23#define SCANCODE_TAB 15
24
25#define SCANCODE_Q 16
26#define SCANCODE_W 17
27#define SCANCODE_E 18
28#define SCANCODE_R 19
29#define SCANCODE_T 20
30#define SCANCODE_Y 21
31#define SCANCODE_U 22
32#define SCANCODE_I 23
33#define SCANCODE_O 24
34#define SCANCODE_P 25
35#define SCANCODE_BRACKET_LEFT 26
36#define SCANCODE_BRACKET_RIGHT 27
37
38#define SCANCODE_ENTER 28
39
40#define SCANCODE_LEFTCONTROL 29
41
42#define SCANCODE_A 30
43#define SCANCODE_S 31
44#define SCANCODE_D 32
45#define SCANCODE_F 33
46#define SCANCODE_G 34
47#define SCANCODE_H 35
48#define SCANCODE_J 36
49#define SCANCODE_K 37
50#define SCANCODE_L 38
51#define SCANCODE_SEMICOLON 39
52#define SCANCODE_APOSTROPHE 40
53#define SCANCODE_GRAVE 41
54
55#define SCANCODE_LEFTSHIFT 42
56#define SCANCODE_BACKSLASH 43
57
58#define SCANCODE_Z 44
59#define SCANCODE_X 45
60#define SCANCODE_C 46
61#define SCANCODE_V 47
62#define SCANCODE_B 48
63#define SCANCODE_N 49
64#define SCANCODE_M 50
65#define SCANCODE_COMMA 51
66#define SCANCODE_PERIOD 52
67#define SCANCODE_SLASH 53
68
69#define SCANCODE_RIGHTSHIFT 54
70#define SCANCODE_KEYPADMULTIPLY 55
71
72#define SCANCODE_LEFTALT 56
73#define SCANCODE_SPACE 57
74#define SCANCODE_CAPSLOCK 58
75
76#define SCANCODE_F1 59
77#define SCANCODE_F2 60
78#define SCANCODE_F3 61
79#define SCANCODE_F4 62
80#define SCANCODE_F5 63
81#define SCANCODE_F6 64
82#define SCANCODE_F7 65
83#define SCANCODE_F8 66
84#define SCANCODE_F9 67
85#define SCANCODE_F10 68
86
87#define SCANCODE_NUMLOCK 69
88#define SCANCODE_SCROLLLOCK 70
89
90#define SCANCODE_KEYPAD7 71
91#define SCANCODE_CURSORUPLEFT 71
92#define SCANCODE_KEYPAD8 72
93#define SCANCODE_CURSORUP 72
94#define SCANCODE_KEYPAD9 73
95#define SCANCODE_CURSORUPRIGHT 73
96#define SCANCODE_KEYPADMINUS 74
97#define SCANCODE_KEYPAD4 75
98#define SCANCODE_CURSORLEFT 75
99#define SCANCODE_KEYPAD5 76
100#define SCANCODE_KEYPAD6 77
101#define SCANCODE_CURSORRIGHT 77
102#define SCANCODE_KEYPADPLUS 78
103#define SCANCODE_KEYPAD1 79
104#define SCANCODE_CURSORDOWNLEFT 79
105#define SCANCODE_KEYPAD2 80
106#define SCANCODE_CURSORDOWN 80
107#define SCANCODE_KEYPAD3 81
108#define SCANCODE_CURSORDOWNRIGHT 81
109#define SCANCODE_KEYPAD0 82
110#define SCANCODE_KEYPADPERIOD 83
111
112#define SCANCODE_LESS 86
113
114#define SCANCODE_F11 87
115#define SCANCODE_F12 88
116
117#define SCANCODE_KEYPADENTER 96
118#define SCANCODE_RIGHTCONTROL 97
119#define SCANCODE_CONTROL 97
120#define SCANCODE_KEYPADDIVIDE 98
121#define SCANCODE_PRINTSCREEN 99
122#define SCANCODE_RIGHTALT 100
123#define SCANCODE_BREAK 101 /* Beware: is 119 */
124#define SCANCODE_BREAK_ALTERNATIVE 119 /* on some keyboards! */
125
126#define SCANCODE_HOME 102
127#define SCANCODE_CURSORBLOCKUP 103 /* Cursor key block */
128#define SCANCODE_PAGEUP 104
129#define SCANCODE_CURSORBLOCKLEFT 105 /* Cursor key block */
130#define SCANCODE_CURSORBLOCKRIGHT 106 /* Cursor key block */
131#define SCANCODE_END 107
132#define SCANCODE_CURSORBLOCKDOWN 108 /* Cursor key block */
133#define SCANCODE_PAGEDOWN 109
134#define SCANCODE_INSERT 110
135#define SCANCODE_REMOVE 111
136
137#define SCANCODE_RIGHTWIN 126
138#define SCANCODE_LEFTWIN 125
139
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbmatrox.c b/apps/plugins/sdl/src/video/fbcon/SDL_fbmatrox.c
deleted file mode 100644
index 04b90b05da..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbmatrox.c
+++ /dev/null
@@ -1,280 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_video.h"
25#include "../SDL_blit.h"
26#include "SDL_fbmatrox.h"
27#include "matrox_mmio.h"
28
29
30/* Wait for vertical retrace - taken from the XFree86 Matrox driver */
31static void WaitVBL(_THIS)
32{
33 int count;
34
35 /* find start of retrace */
36 mga_waitidle();
37 while ( (mga_in8(0x1FDA) & 0x08) )
38 ;
39 while ( !(mga_in8(0x1FDA) & 0x08) )
40 ;
41 /* wait until we're past the start */
42 count = mga_in32(0x1E20) + 2;
43 while ( mga_in32(0x1E20) < count )
44 ;
45}
46static void WaitIdle(_THIS)
47{
48 mga_waitidle();
49}
50
51/* Sets video mem colorkey and accelerated blit function */
52static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
53{
54 return(0);
55}
56
57/* Sets per surface hardware alpha value */
58#if 0
59static int SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value)
60{
61 return(0);
62}
63#endif
64
65static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color)
66{
67 int dstX, dstY;
68 Uint32 fxbndry;
69 Uint32 ydstlen;
70 Uint32 fillop;
71
72 /* Don't blit to the display surface when switched away */
73 if ( switched_away ) {
74 return -2; /* no hardware access */
75 }
76 if ( dst == this->screen ) {
77 SDL_mutexP(hw_lock);
78 }
79
80 switch (dst->format->BytesPerPixel) {
81 case 1:
82 color |= (color<<8);
83 case 2:
84 color |= (color<<16);
85 break;
86 }
87
88 /* Set up the X/Y base coordinates */
89 FB_dst_to_xy(this, dst, &dstX, &dstY);
90
91 /* Adjust for the current rectangle */
92 dstX += rect->x;
93 dstY += rect->y;
94
95 /* Set up the X boundaries */
96 fxbndry = (dstX | ((dstX+rect->w) << 16));
97
98 /* Set up the Y boundaries */
99 ydstlen = (rect->h | (dstY << 16));
100
101 /* Set up for color fill operation */
102 fillop = MGADWG_TRAP | MGADWG_SOLID |
103 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO;
104
105 /* Execute the operations! */
106 mga_wait(5);
107 mga_out32(MGAREG_DWGCTL, fillop | MGADWG_REPLACE);
108 mga_out32(MGAREG_FCOL, color);
109 mga_out32(MGAREG_FXBNDRY, fxbndry);
110 mga_out32(MGAREG_YDSTLEN + MGAREG_EXEC, ydstlen);
111
112 FB_AddBusySurface(dst);
113
114 if ( dst == this->screen ) {
115 SDL_mutexV(hw_lock);
116 }
117 return(0);
118}
119
120static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
121 SDL_Surface *dst, SDL_Rect *dstrect)
122{
123 SDL_VideoDevice *this = current_video;
124 int pitch, w, h;
125 int srcX, srcY;
126 int dstX, dstY;
127 Uint32 sign;
128 Uint32 start, stop;
129 int skip;
130 Uint32 blitop;
131
132 /* FIXME: For now, only blit to display surface */
133 if ( dst->pitch != SDL_VideoSurface->pitch ) {
134 return(src->map->sw_blit(src, srcrect, dst, dstrect));
135 }
136
137 /* Don't blit to the display surface when switched away */
138 if ( switched_away ) {
139 return -2; /* no hardware access */
140 }
141 if ( dst == this->screen ) {
142 SDL_mutexP(hw_lock);
143 }
144
145 /* Calculate source and destination base coordinates (in pixels) */
146 w = dstrect->w;
147 h = dstrect->h;
148 FB_dst_to_xy(this, src, &srcX, &srcY);
149 FB_dst_to_xy(this, dst, &dstX, &dstY);
150
151 /* Adjust for the current blit rectangles */
152 srcX += srcrect->x;
153 srcY += srcrect->y;
154 dstX += dstrect->x;
155 dstY += dstrect->y;
156 pitch = dst->pitch/dst->format->BytesPerPixel;
157
158 /* Set up the blit direction (sign) flags */
159 sign = 0;
160 if ( srcX < dstX ) {
161 sign |= 1;
162 }
163 if ( srcY < dstY ) {
164 sign |= 4;
165 srcY += (h - 1);
166 dstY += (h - 1);
167 }
168
169 /* Set up the blit source row start, end, and skip (in pixels) */
170 stop = start = (srcY * pitch) + srcX;
171 if ( srcX < dstX ) {
172 start += (w - 1);
173 } else {
174 stop += (w - 1);
175 }
176 if ( srcY < dstY ) {
177 skip = -pitch;
178 } else {
179 skip = pitch;
180 }
181
182 /* Set up the blit operation */
183 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
184 Uint32 colorkey;
185
186 blitop = MGADWG_BFCOL | MGADWG_BITBLT |
187 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16) |
188 MGADWG_TRANSC;
189
190 colorkey = src->format->colorkey;
191 switch (dst->format->BytesPerPixel) {
192 case 1:
193 colorkey |= (colorkey<<8);
194 case 2:
195 colorkey |= (colorkey<<16);
196 break;
197 }
198 mga_wait(2);
199 mga_out32(MGAREG_FCOL, colorkey);
200 mga_out32(MGAREG_BCOL, 0xFFFFFFFF);
201 } else {
202 blitop = MGADWG_BFCOL | MGADWG_BITBLT |
203 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16);
204 }
205 mga_wait(7);
206 mga_out32(MGAREG_SGN, sign);
207 mga_out32(MGAREG_AR3, start);
208 mga_out32(MGAREG_AR0, stop);
209 mga_out32(MGAREG_AR5, skip);
210 mga_out32(MGAREG_FXBNDRY, (dstX | ((dstX + w-1) << 16)));
211 mga_out32(MGAREG_YDSTLEN, (dstY << 16) | h);
212 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop);
213
214 FB_AddBusySurface(src);
215 FB_AddBusySurface(dst);
216
217 if ( dst == this->screen ) {
218 SDL_mutexV(hw_lock);
219 }
220 return(0);
221}
222
223static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
224{
225 int accelerated;
226
227 /* Set initial acceleration on */
228 src->flags |= SDL_HWACCEL;
229
230 /* Set the surface attributes */
231 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
232 if ( ! this->info.blit_hw_A ) {
233 src->flags &= ~SDL_HWACCEL;
234 }
235 }
236 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
237 if ( ! this->info.blit_hw_CC ) {
238 src->flags &= ~SDL_HWACCEL;
239 }
240 }
241
242 /* Check to see if final surface blit is accelerated */
243 accelerated = !!(src->flags & SDL_HWACCEL);
244 if ( accelerated ) {
245 src->map->hw_blit = HWAccelBlit;
246 }
247 return(accelerated);
248}
249
250void FB_MatroxAccel(_THIS, __u32 card)
251{
252 /* We have hardware accelerated surface functions */
253 this->CheckHWBlit = CheckHWBlit;
254 wait_vbl = WaitVBL;
255 wait_idle = WaitIdle;
256
257 /* The Matrox has an accelerated color fill */
258 this->info.blit_fill = 1;
259 this->FillHWRect = FillHWRect;
260
261 /* The Matrox has accelerated normal and colorkey blits. */
262 this->info.blit_hw = 1;
263 /* The Millenium I appears to do the colorkey test a word
264 at a time, and the transparency is intverted. (?)
265 */
266 if ( card != FB_ACCEL_MATROX_MGA2064W ) {
267 this->info.blit_hw_CC = 1;
268 this->SetHWColorKey = SetHWColorKey;
269 }
270
271#if 0 /* Not yet implemented? */
272 /* The Matrox G200/G400 has an accelerated alpha blit */
273 if ( (card == FB_ACCEL_MATROX_MGAG200)
274 || (card == FB_ACCEL_MATROX_MGAG400)
275 ) {
276 this->info.blit_hw_A = 1;
277 this->SetHWAlpha = SetHWAlpha;
278 }
279#endif
280}
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbmatrox.h b/apps/plugins/sdl/src/video/fbcon/SDL_fbmatrox.h
deleted file mode 100644
index f7d41b0240..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbmatrox.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* Matrox hardware acceleration for the SDL framebuffer console driver */
25
26#include "SDL_fbvideo.h"
27
28/* Set up the driver for Matrox acceleration */
29extern void FB_MatroxAccel(_THIS, __u32 card);
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbmouse.c b/apps/plugins/sdl/src/video/fbcon/SDL_fbmouse.c
deleted file mode 100644
index d65f27ece5..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbmouse.c
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_mouse.h"
25#include "../../events/SDL_events_c.h"
26#include "SDL_fbvideo.h"
27#include "SDL_fbmouse_c.h"
28
29
30/* The implementation dependent data for the window manager cursor */
31struct WMcursor {
32 int unused;
33};
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbmouse_c.h b/apps/plugins/sdl/src/video/fbcon/SDL_fbmouse_c.h
deleted file mode 100644
index fbb031d1f7..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbmouse_c.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_fbvideo.h"
25
26/* Functions to be exported */
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbriva.c b/apps/plugins/sdl/src/video/fbcon/SDL_fbriva.c
deleted file mode 100644
index eb4b71f1bb..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbriva.c
+++ /dev/null
@@ -1,222 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_video.h"
25#include "../SDL_blit.h"
26#include "SDL_fbriva.h"
27#include "riva_mmio.h"
28#include "riva_regs.h"
29
30
31static int FifoEmptyCount = 0;
32static int FifoFreeCount = 0;
33
34/* Wait for vertical retrace */
35static void WaitVBL(_THIS)
36{
37 volatile Uint8 *port = (Uint8 *)(mapped_io + PCIO_OFFSET + 0x3DA);
38
39 while ( (*port & 0x08) )
40 ;
41 while ( !(*port & 0x08) )
42 ;
43}
44static void NV3WaitIdle(_THIS)
45{
46 RivaRop *Rop = (RivaRop *)(mapped_io + ROP_OFFSET);
47 while ( (Rop->FifoFree < FifoEmptyCount) ||
48 (*(mapped_io + PGRAPH_OFFSET + 0x000006B0) & 0x01) )
49 ;
50}
51static void NV4WaitIdle(_THIS)
52{
53 RivaRop *Rop = (RivaRop *)(mapped_io + ROP_OFFSET);
54 while ( (Rop->FifoFree < FifoEmptyCount) ||
55 (*(mapped_io + PGRAPH_OFFSET + 0x00000700) & 0x01) )
56 ;
57}
58
59#if 0 /* Not yet implemented? */
60/* Sets video mem colorkey and accelerated blit function */
61static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
62{
63 return(0);
64}
65
66/* Sets per surface hardware alpha value */
67static int SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value)
68{
69 return(0);
70}
71#endif /* Not yet implemented */
72
73static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color)
74{
75 int dstX, dstY;
76 int dstW, dstH;
77 RivaBitmap *Bitmap = (RivaBitmap *)(mapped_io + BITMAP_OFFSET);
78
79 /* Don't blit to the display surface when switched away */
80 if ( switched_away ) {
81 return -2; /* no hardware access */
82 }
83 if ( dst == this->screen ) {
84 SDL_mutexP(hw_lock);
85 }
86
87 /* Set up the X/Y base coordinates */
88 dstW = rect->w;
89 dstH = rect->h;
90 FB_dst_to_xy(this, dst, &dstX, &dstY);
91
92 /* Adjust for the current rectangle */
93 dstX += rect->x;
94 dstY += rect->y;
95
96 RIVA_FIFO_FREE(Bitmap, 1);
97 Bitmap->Color1A = color;
98
99 RIVA_FIFO_FREE(Bitmap, 2);
100 Bitmap->UnclippedRectangle[0].TopLeft = (dstX << 16) | dstY;
101 Bitmap->UnclippedRectangle[0].WidthHeight = (dstW << 16) | dstH;
102
103 FB_AddBusySurface(dst);
104
105 if ( dst == this->screen ) {
106 SDL_mutexV(hw_lock);
107 }
108 return(0);
109}
110
111static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
112 SDL_Surface *dst, SDL_Rect *dstrect)
113{
114 SDL_VideoDevice *this = current_video;
115 int srcX, srcY;
116 int dstX, dstY;
117 int dstW, dstH;
118 RivaScreenBlt *Blt = (RivaScreenBlt *)(mapped_io + BLT_OFFSET);
119
120 /* FIXME: For now, only blit to display surface */
121 if ( dst->pitch != SDL_VideoSurface->pitch ) {
122 return(src->map->sw_blit(src, srcrect, dst, dstrect));
123 }
124
125 /* Don't blit to the display surface when switched away */
126 if ( switched_away ) {
127 return -2; /* no hardware access */
128 }
129 if ( dst == this->screen ) {
130 SDL_mutexP(hw_lock);
131 }
132
133 /* Calculate source and destination base coordinates (in pixels) */
134 dstW = dstrect->w;
135 dstH = dstrect->h;
136 FB_dst_to_xy(this, src, &srcX, &srcY);
137 FB_dst_to_xy(this, dst, &dstX, &dstY);
138
139 /* Adjust for the current blit rectangles */
140 srcX += srcrect->x;
141 srcY += srcrect->y;
142 dstX += dstrect->x;
143 dstY += dstrect->y;
144
145 RIVA_FIFO_FREE(Blt, 3);
146 Blt->TopLeftSrc = (srcY << 16) | srcX;
147 Blt->TopLeftDst = (dstY << 16) | dstX;
148 Blt->WidthHeight = (dstH << 16) | dstW;
149
150 FB_AddBusySurface(src);
151 FB_AddBusySurface(dst);
152
153 if ( dst == this->screen ) {
154 SDL_mutexV(hw_lock);
155 }
156 return(0);
157}
158
159static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
160{
161 int accelerated;
162
163 /* Set initial acceleration on */
164 src->flags |= SDL_HWACCEL;
165
166 /* Set the surface attributes */
167 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
168 if ( ! this->info.blit_hw_A ) {
169 src->flags &= ~SDL_HWACCEL;
170 }
171 }
172 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
173 if ( ! this->info.blit_hw_CC ) {
174 src->flags &= ~SDL_HWACCEL;
175 }
176 }
177
178 /* Check to see if final surface blit is accelerated */
179 accelerated = !!(src->flags & SDL_HWACCEL);
180 if ( accelerated ) {
181 src->map->hw_blit = HWAccelBlit;
182 }
183 return(accelerated);
184}
185
186void FB_RivaAccel(_THIS, __u32 card)
187{
188 RivaRop *Rop = (RivaRop *)(mapped_io + ROP_OFFSET);
189
190 /* We have hardware accelerated surface functions */
191 this->CheckHWBlit = CheckHWBlit;
192 wait_vbl = WaitVBL;
193 switch (card) {
194 case FB_ACCEL_NV3:
195 wait_idle = NV3WaitIdle;
196 break;
197 case FB_ACCEL_NV4:
198 wait_idle = NV4WaitIdle;
199 break;
200 default:
201 /* Hmm... FIXME */
202 break;
203 }
204 FifoEmptyCount = Rop->FifoFree;
205
206 /* The Riva has an accelerated color fill */
207 this->info.blit_fill = 1;
208 this->FillHWRect = FillHWRect;
209
210 /* The Riva has accelerated normal and colorkey blits. */
211 this->info.blit_hw = 1;
212#if 0 /* Not yet implemented? */
213 this->info.blit_hw_CC = 1;
214 this->SetHWColorKey = SetHWColorKey;
215#endif
216
217#if 0 /* Not yet implemented? */
218 /* The Riva has an accelerated alpha blit */
219 this->info.blit_hw_A = 1;
220 this->SetHWAlpha = SetHWAlpha;
221#endif
222}
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbriva.h b/apps/plugins/sdl/src/video/fbcon/SDL_fbriva.h
deleted file mode 100644
index c78682e8a5..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbriva.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* Riva hardware acceleration for the SDL framebuffer console driver */
25
26#include "SDL_fbvideo.h"
27
28#ifndef FB_ACCEL_NV3
29#define FB_ACCEL_NV3 27
30#endif
31#ifndef FB_ACCEL_NV4
32#define FB_ACCEL_NV4 28
33#endif
34
35/* Set up the driver for Riva acceleration */
36extern void FB_RivaAccel(_THIS, __u32 card);
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbvideo.c b/apps/plugins/sdl/src/video/fbcon/SDL_fbvideo.c
deleted file mode 100644
index 5e5880908d..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbvideo.c
+++ /dev/null
@@ -1,1982 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* Framebuffer console based SDL video driver implementation.
25*/
26
27#include <stdio.h>
28#include <fcntl.h>
29#include <unistd.h>
30#include <sys/ioctl.h>
31#include <sys/mman.h>
32
33#ifndef HAVE_GETPAGESIZE
34#include <asm/page.h> /* For definition of PAGE_SIZE */
35#endif
36
37#include <linux/vt.h>
38
39#include "SDL_video.h"
40#include "SDL_mouse.h"
41#include "../SDL_sysvideo.h"
42#include "../SDL_pixels_c.h"
43#include "../../events/SDL_events_c.h"
44#include "SDL_fbvideo.h"
45#include "SDL_fbmouse_c.h"
46#include "SDL_fbevents_c.h"
47#include "SDL_fb3dfx.h"
48#include "SDL_fbmatrox.h"
49#include "SDL_fbriva.h"
50
51/*#define FBCON_DEBUG*/
52
53#if defined(i386) && defined(FB_TYPE_VGA_PLANES)
54#define VGA16_FBCON_SUPPORT
55#include <sys/io.h> /* For ioperm() */
56#ifndef FB_AUX_VGA_PLANES_VGA4
57#define FB_AUX_VGA_PLANES_VGA4 0
58#endif
59/*
60static inline void outb (unsigned char value, unsigned short port)
61{
62 __asm__ __volatile__ ("outb %b0,%w1"::"a" (value), "Nd" (port));
63}
64*/
65#endif /* FB_TYPE_VGA_PLANES */
66
67/* A list of video resolutions that we query for (sorted largest to smallest) */
68static const SDL_Rect checkres[] = {
69 { 0, 0, 1600, 1200 }, /* 16 bpp: 0x11E, or 286 */
70 { 0, 0, 1408, 1056 }, /* 16 bpp: 0x19A, or 410 */
71 { 0, 0, 1280, 1024 }, /* 16 bpp: 0x11A, or 282 */
72 { 0, 0, 1152, 864 }, /* 16 bpp: 0x192, or 402 */
73 { 0, 0, 1024, 768 }, /* 16 bpp: 0x117, or 279 */
74 { 0, 0, 960, 720 }, /* 16 bpp: 0x18A, or 394 */
75 { 0, 0, 800, 600 }, /* 16 bpp: 0x114, or 276 */
76 { 0, 0, 768, 576 }, /* 16 bpp: 0x182, or 386 */
77 { 0, 0, 720, 576 }, /* PAL */
78 { 0, 0, 720, 480 }, /* NTSC */
79 { 0, 0, 640, 480 }, /* 16 bpp: 0x111, or 273 */
80 { 0, 0, 640, 400 }, /* 8 bpp: 0x100, or 256 */
81 { 0, 0, 512, 384 },
82 { 0, 0, 320, 240 },
83 { 0, 0, 320, 200 }
84};
85static const struct {
86 int xres;
87 int yres;
88 int pixclock;
89 int left;
90 int right;
91 int upper;
92 int lower;
93 int hslen;
94 int vslen;
95 int sync;
96 int vmode;
97} vesa_timings[] = {
98#ifdef USE_VESA_TIMINGS /* Only tested on Matrox Millenium I */
99 { 640, 400, 39771, 48, 16, 39, 8, 96, 2, 2, 0 }, /* 70 Hz */
100 { 640, 480, 39683, 48, 16, 33, 10, 96, 2, 0, 0 }, /* 60 Hz */
101 { 768, 576, 26101, 144, 16, 28, 6, 112, 4, 0, 0 }, /* 60 Hz */
102 { 800, 600, 24038, 144, 24, 28, 8, 112, 6, 0, 0 }, /* 60 Hz */
103 { 960, 720, 17686, 144, 24, 28, 8, 112, 4, 0, 0 }, /* 60 Hz */
104 { 1024, 768, 15386, 160, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */
105 { 1152, 864, 12286, 192, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */
106 { 1280, 1024, 9369, 224, 32, 32, 4, 136, 4, 0, 0 }, /* 60 Hz */
107 { 1408, 1056, 8214, 256, 40, 32, 5, 144, 5, 0, 0 }, /* 60 Hz */
108 { 1600, 1200,/*?*/0, 272, 48, 32, 5, 152, 5, 0, 0 }, /* 60 Hz */
109#else
110 /* You can generate these timings from your XF86Config file using
111 the 'modeline2fb' perl script included with the fbset package.
112 These timings were generated for Matrox Millenium I, 15" monitor.
113 */
114 { 320, 200, 79440, 16, 16, 20, 4, 48, 1, 0, 2 }, /* 70 Hz */
115 { 320, 240, 63492, 16, 16, 16, 4, 48, 2, 0, 2 }, /* 72 Hz */
116 { 512, 384, 49603, 48, 16, 16, 1, 64, 3, 0, 0 }, /* 78 Hz */
117 { 640, 400, 31746, 96, 32, 41, 1, 64, 3, 2, 0 }, /* 85 Hz */
118 { 640, 480, 31746, 120, 16, 16, 1, 64, 3, 0, 0 }, /* 75 Hz */
119 { 768, 576, 26101, 144, 16, 28, 6, 112, 4, 0, 0 }, /* 60 Hz */
120 { 800, 600, 20000, 64, 56, 23, 37, 120, 6, 3, 0 }, /* 72 Hz */
121 { 960, 720, 17686, 144, 24, 28, 8, 112, 4, 0, 0 }, /* 60 Hz */
122 { 1024, 768, 13333, 144, 24, 29, 3, 136, 6, 0, 0 }, /* 70 Hz */
123 { 1152, 864, 12286, 192, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */
124 { 1280, 1024, 9369, 224, 32, 32, 4, 136, 4, 0, 0 }, /* 60 Hz */
125 { 1408, 1056, 8214, 256, 40, 32, 5, 144, 5, 0, 0 }, /* 60 Hz */
126 { 1600, 1200,/*?*/0, 272, 48, 32, 5, 152, 5, 0, 0 }, /* 60 Hz */
127#endif
128};
129enum {
130 FBCON_ROTATE_NONE = 0,
131 FBCON_ROTATE_CCW = 90,
132 FBCON_ROTATE_UD = 180,
133 FBCON_ROTATE_CW = 270
134};
135
136#define min(a,b) ((a)<(b)?(a):(b))
137
138/* Initialization/Query functions */
139static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat);
140static SDL_Rect **FB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
141static SDL_Surface *FB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
142#ifdef VGA16_FBCON_SUPPORT
143static SDL_Surface *FB_SetVGA16Mode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
144#endif
145static int FB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
146static void FB_VideoQuit(_THIS);
147
148/* Hardware surface functions */
149static int FB_InitHWSurfaces(_THIS, SDL_Surface *screen, char *base, int size);
150static void FB_FreeHWSurfaces(_THIS);
151static int FB_AllocHWSurface(_THIS, SDL_Surface *surface);
152static int FB_LockHWSurface(_THIS, SDL_Surface *surface);
153static void FB_UnlockHWSurface(_THIS, SDL_Surface *surface);
154static void FB_FreeHWSurface(_THIS, SDL_Surface *surface);
155static void FB_WaitVBL(_THIS);
156static void FB_WaitIdle(_THIS);
157static int FB_FlipHWSurface(_THIS, SDL_Surface *surface);
158
159/* Internal palette functions */
160static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo,
161 struct fb_var_screeninfo *vinfo);
162static void FB_RestorePalette(_THIS);
163
164/* Shadow buffer functions */
165static FB_bitBlit FB_blit16;
166static FB_bitBlit FB_blit16blocked;
167
168static int SDL_getpagesize(void)
169{
170#ifdef HAVE_GETPAGESIZE
171 return getpagesize();
172#elif defined(PAGE_SIZE)
173 return PAGE_SIZE;
174#else
175#error Can not determine system page size.
176 return 4096; /* this is what it USED to be in Linux... */
177#endif
178}
179
180
181/* Small wrapper for mmap() so we can play nicely with no-mmu hosts
182 * (non-mmu hosts disallow the MAP_SHARED flag) */
183
184static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
185{
186 void *ret;
187 ret = mmap(start, length, prot, flags, fd, offset);
188 if ( ret == (char *)-1 && (flags & MAP_SHARED) ) {
189 ret = mmap(start, length, prot,
190 (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
191 }
192 return ret;
193}
194
195/* FB driver bootstrap functions */
196
197static int FB_Available(void)
198{
199 int console = -1;
200 /* Added check for /fb/0 (devfs) */
201 /* but - use environment variable first... if it fails, still check defaults */
202 int idx = 0;
203 const char *SDL_fbdevs[4] = { NULL, "/dev/fb0", "/dev/fb/0", NULL };
204
205 SDL_fbdevs[0] = SDL_getenv("SDL_FBDEV");
206 if( !SDL_fbdevs[0] )
207 idx++;
208 for( ; SDL_fbdevs[idx]; idx++ )
209 {
210 console = open(SDL_fbdevs[idx], O_RDWR, 0);
211 if ( console >= 0 ) {
212 close(console);
213 break;
214 }
215 }
216 return(console >= 0);
217}
218
219static void FB_DeleteDevice(SDL_VideoDevice *device)
220{
221 SDL_free(device->hidden);
222 SDL_free(device);
223}
224
225static SDL_VideoDevice *FB_CreateDevice(int devindex)
226{
227 SDL_VideoDevice *this;
228
229 /* Initialize all variables that we clean on shutdown */
230 this = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
231 if ( this ) {
232 SDL_memset(this, 0, (sizeof *this));
233 this->hidden = (struct SDL_PrivateVideoData *)
234 SDL_malloc((sizeof *this->hidden));
235 }
236 if ( (this == NULL) || (this->hidden == NULL) ) {
237 SDL_OutOfMemory();
238 if ( this ) {
239 SDL_free(this);
240 }
241 return(0);
242 }
243 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
244 wait_vbl = FB_WaitVBL;
245 wait_idle = FB_WaitIdle;
246 mouse_fd = -1;
247 keyboard_fd = -1;
248
249 /* Set the function pointers */
250 this->VideoInit = FB_VideoInit;
251 this->ListModes = FB_ListModes;
252 this->SetVideoMode = FB_SetVideoMode;
253 this->SetColors = FB_SetColors;
254 this->UpdateRects = NULL;
255 this->VideoQuit = FB_VideoQuit;
256 this->AllocHWSurface = FB_AllocHWSurface;
257 this->CheckHWBlit = NULL;
258 this->FillHWRect = NULL;
259 this->SetHWColorKey = NULL;
260 this->SetHWAlpha = NULL;
261 this->LockHWSurface = FB_LockHWSurface;
262 this->UnlockHWSurface = FB_UnlockHWSurface;
263 this->FlipHWSurface = FB_FlipHWSurface;
264 this->FreeHWSurface = FB_FreeHWSurface;
265 this->SetCaption = NULL;
266 this->SetIcon = NULL;
267 this->IconifyWindow = NULL;
268 this->GrabInput = NULL;
269 this->GetWMInfo = NULL;
270 this->InitOSKeymap = FB_InitOSKeymap;
271 this->PumpEvents = FB_PumpEvents;
272
273 this->free = FB_DeleteDevice;
274
275 return this;
276}
277
278VideoBootStrap FBCON_bootstrap = {
279 "fbcon", "Linux Framebuffer Console",
280 FB_Available, FB_CreateDevice
281};
282
283#define FB_MODES_DB "/etc/fb.modes"
284
285static int read_fbmodes_line(FILE*f, char* line, int length)
286{
287 int blank;
288 char* c;
289 int i;
290
291 blank=0;
292 /* find a relevant line */
293 do
294 {
295 if (!fgets(line,length,f))
296 return 0;
297 c=line;
298 while(((*c=='\t')||(*c==' '))&&(*c!=0))
299 c++;
300
301 if ((*c=='\n')||(*c=='#')||(*c==0))
302 blank=1;
303 else
304 blank=0;
305 }
306 while(blank);
307 /* remove whitespace at the begining of the string */
308 i=0;
309 do
310 {
311 line[i]=c[i];
312 i++;
313 }
314 while(c[i]!=0);
315 return 1;
316}
317
318static int read_fbmodes_mode(FILE *f, struct fb_var_screeninfo *vinfo)
319{
320 char line[1024];
321 char option[256];
322
323 /* Find a "geometry" */
324 do {
325 if (read_fbmodes_line(f, line, sizeof(line))==0)
326 return 0;
327 if (SDL_strncmp(line,"geometry",8)==0)
328 break;
329 }
330 while(1);
331
332 SDL_sscanf(line, "geometry %d %d %d %d %d", &vinfo->xres, &vinfo->yres,
333 &vinfo->xres_virtual, &vinfo->yres_virtual, &vinfo->bits_per_pixel);
334 if (read_fbmodes_line(f, line, sizeof(line))==0)
335 return 0;
336
337 SDL_sscanf(line, "timings %d %d %d %d %d %d %d", &vinfo->pixclock,
338 &vinfo->left_margin, &vinfo->right_margin, &vinfo->upper_margin,
339 &vinfo->lower_margin, &vinfo->hsync_len, &vinfo->vsync_len);
340
341 vinfo->sync=0;
342 vinfo->vmode=FB_VMODE_NONINTERLACED;
343
344 /* Parse misc options */
345 do {
346 if (read_fbmodes_line(f, line, sizeof(line))==0)
347 return 0;
348
349 if (SDL_strncmp(line,"hsync",5)==0) {
350 SDL_sscanf(line,"hsync %s",option);
351 if (SDL_strncmp(option,"high",4)==0)
352 vinfo->sync |= FB_SYNC_HOR_HIGH_ACT;
353 }
354 else if (SDL_strncmp(line,"vsync",5)==0) {
355 SDL_sscanf(line,"vsync %s",option);
356 if (SDL_strncmp(option,"high",4)==0)
357 vinfo->sync |= FB_SYNC_VERT_HIGH_ACT;
358 }
359 else if (SDL_strncmp(line,"csync",5)==0) {
360 SDL_sscanf(line,"csync %s",option);
361 if (SDL_strncmp(option,"high",4)==0)
362 vinfo->sync |= FB_SYNC_COMP_HIGH_ACT;
363 }
364 else if (SDL_strncmp(line,"extsync",5)==0) {
365 SDL_sscanf(line,"extsync %s",option);
366 if (SDL_strncmp(option,"true",4)==0)
367 vinfo->sync |= FB_SYNC_EXT;
368 }
369 else if (SDL_strncmp(line,"laced",5)==0) {
370 SDL_sscanf(line,"laced %s",option);
371 if (SDL_strncmp(option,"true",4)==0)
372 vinfo->vmode |= FB_VMODE_INTERLACED;
373 }
374 else if (SDL_strncmp(line,"double",6)==0) {
375 SDL_sscanf(line,"double %s",option);
376 if (SDL_strncmp(option,"true",4)==0)
377 vinfo->vmode |= FB_VMODE_DOUBLE;
378 }
379 }
380 while(SDL_strncmp(line,"endmode",7)!=0);
381
382 return 1;
383}
384
385static int FB_CheckMode(_THIS, struct fb_var_screeninfo *vinfo,
386 int index, unsigned int *w, unsigned int *h)
387{
388 int mode_okay;
389
390 mode_okay = 0;
391 vinfo->bits_per_pixel = (index+1)*8;
392 vinfo->xres = *w;
393 vinfo->xres_virtual = *w;
394 vinfo->yres = *h;
395 vinfo->yres_virtual = *h;
396 vinfo->activate = FB_ACTIVATE_TEST;
397 if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, vinfo) == 0 ) {
398#ifdef FBCON_DEBUG
399 fprintf(stderr, "Checked mode %dx%d at %d bpp, got mode %dx%d at %d bpp\n", *w, *h, (index+1)*8, vinfo->xres, vinfo->yres, vinfo->bits_per_pixel);
400#endif
401 if ( (((vinfo->bits_per_pixel+7)/8)-1) == index ) {
402 *w = vinfo->xres;
403 *h = vinfo->yres;
404 mode_okay = 1;
405 }
406 }
407 return mode_okay;
408}
409
410static int FB_AddMode(_THIS, int index, unsigned int w, unsigned int h, int check_timings)
411{
412 SDL_Rect *mode;
413 int i;
414 int next_mode;
415
416 /* Check to see if we already have this mode */
417 if ( SDL_nummodes[index] > 0 ) {
418 mode = SDL_modelist[index][SDL_nummodes[index]-1];
419 if ( (mode->w == w) && (mode->h == h) ) {
420#ifdef FBCON_DEBUG
421 fprintf(stderr, "We already have mode %dx%d at %d bytes per pixel\n", w, h, index+1);
422#endif
423 return(0);
424 }
425 }
426
427 /* Only allow a mode if we have a valid timing for it */
428 if ( check_timings ) {
429 int found_timing = 0;
430 for ( i=0; i<(sizeof(vesa_timings)/sizeof(vesa_timings[0])); ++i ) {
431 if ( (w == vesa_timings[i].xres) &&
432 (h == vesa_timings[i].yres) && vesa_timings[i].pixclock ) {
433 found_timing = 1;
434 break;
435 }
436 }
437 if ( !found_timing ) {
438#ifdef FBCON_DEBUG
439 fprintf(stderr, "No valid timing line for mode %dx%d\n", w, h);
440#endif
441 return(0);
442 }
443 }
444
445 /* Set up the new video mode rectangle */
446 mode = (SDL_Rect *)SDL_malloc(sizeof *mode);
447 if ( mode == NULL ) {
448 SDL_OutOfMemory();
449 return(-1);
450 }
451 mode->x = 0;
452 mode->y = 0;
453 mode->w = w;
454 mode->h = h;
455#ifdef FBCON_DEBUG
456 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, index+1);
457#endif
458
459 /* Allocate the new list of modes, and fill in the new mode */
460 next_mode = SDL_nummodes[index];
461 SDL_modelist[index] = (SDL_Rect **)
462 SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
463 if ( SDL_modelist[index] == NULL ) {
464 SDL_OutOfMemory();
465 SDL_nummodes[index] = 0;
466 SDL_free(mode);
467 return(-1);
468 }
469 SDL_modelist[index][next_mode] = mode;
470 SDL_modelist[index][next_mode+1] = NULL;
471 SDL_nummodes[index]++;
472
473 return(0);
474}
475
476static int cmpmodes(const void *va, const void *vb)
477{
478 const SDL_Rect *a = *(const SDL_Rect**)va;
479 const SDL_Rect *b = *(const SDL_Rect**)vb;
480 if ( a->h == b->h )
481 return b->w - a->w;
482 else
483 return b->h - a->h;
484}
485
486static void FB_SortModes(_THIS)
487{
488 int i;
489 for ( i=0; i<NUM_MODELISTS; ++i ) {
490 if ( SDL_nummodes[i] > 0 ) {
491 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
492 }
493 }
494}
495
496static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat)
497{
498 const int pagesize = SDL_getpagesize();
499 struct fb_fix_screeninfo finfo;
500 struct fb_var_screeninfo vinfo;
501 int i, j;
502 int current_index;
503 unsigned int current_w;
504 unsigned int current_h;
505 const char *SDL_fbdev;
506 const char *rotation;
507 FILE *modesdb;
508
509 /* Initialize the library */
510 SDL_fbdev = SDL_getenv("SDL_FBDEV");
511 if ( SDL_fbdev == NULL ) {
512 SDL_fbdev = "/dev/fb0";
513 }
514 console_fd = open(SDL_fbdev, O_RDWR, 0);
515 if ( console_fd < 0 ) {
516 SDL_SetError("Unable to open %s", SDL_fbdev);
517 return(-1);
518 }
519
520#if !SDL_THREADS_DISABLED
521 /* Create the hardware surface lock mutex */
522 hw_lock = SDL_CreateMutex();
523 if ( hw_lock == NULL ) {
524 SDL_SetError("Unable to create lock mutex");
525 FB_VideoQuit(this);
526 return(-1);
527 }
528#endif
529
530 /* Get the type of video hardware */
531 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
532 SDL_SetError("Couldn't get console hardware info");
533 FB_VideoQuit(this);
534 return(-1);
535 }
536 switch (finfo.type) {
537 case FB_TYPE_PACKED_PIXELS:
538 /* Supported, no worries.. */
539 break;
540#ifdef VGA16_FBCON_SUPPORT
541 case FB_TYPE_VGA_PLANES:
542 /* VGA16 is supported, but that's it */
543 if ( finfo.type_aux == FB_AUX_VGA_PLANES_VGA4 ) {
544 if ( ioperm(0x3b4, 0x3df - 0x3b4 + 1, 1) < 0 ) {
545 SDL_SetError("No I/O port permissions");
546 FB_VideoQuit(this);
547 return(-1);
548 }
549 this->SetVideoMode = FB_SetVGA16Mode;
550 break;
551 }
552 /* Fall through to unsupported case */
553#endif /* VGA16_FBCON_SUPPORT */
554 default:
555 SDL_SetError("Unsupported console hardware");
556 FB_VideoQuit(this);
557 return(-1);
558 }
559 switch (finfo.visual) {
560 case FB_VISUAL_TRUECOLOR:
561 case FB_VISUAL_PSEUDOCOLOR:
562 case FB_VISUAL_STATIC_PSEUDOCOLOR:
563 case FB_VISUAL_DIRECTCOLOR:
564 break;
565 default:
566 SDL_SetError("Unsupported console hardware");
567 FB_VideoQuit(this);
568 return(-1);
569 }
570
571 /* Check if the user wants to disable hardware acceleration */
572 { const char *fb_accel;
573 fb_accel = SDL_getenv("SDL_FBACCEL");
574 if ( fb_accel ) {
575 finfo.accel = SDL_atoi(fb_accel);
576 }
577 }
578
579 /* Memory map the device, compensating for buggy PPC mmap() */
580 mapped_offset = (((long)finfo.smem_start) -
581 (((long)finfo.smem_start)&~(pagesize-1)));
582 mapped_memlen = finfo.smem_len+mapped_offset;
583 mapped_mem = do_mmap(NULL, mapped_memlen,
584 PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
585 if ( mapped_mem == (char *)-1 ) {
586 SDL_SetError("Unable to memory map the video hardware");
587 mapped_mem = NULL;
588 FB_VideoQuit(this);
589 return(-1);
590 }
591
592 /* Determine the current screen depth */
593 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
594 SDL_SetError("Couldn't get console pixel format");
595 FB_VideoQuit(this);
596 return(-1);
597 }
598 vformat->BitsPerPixel = vinfo.bits_per_pixel;
599 if ( vformat->BitsPerPixel < 8 ) {
600 /* Assuming VGA16, we handle this via a shadow framebuffer */
601 vformat->BitsPerPixel = 8;
602 }
603 for ( i=0; i<vinfo.red.length; ++i ) {
604 vformat->Rmask <<= 1;
605 vformat->Rmask |= (0x00000001<<vinfo.red.offset);
606 }
607 for ( i=0; i<vinfo.green.length; ++i ) {
608 vformat->Gmask <<= 1;
609 vformat->Gmask |= (0x00000001<<vinfo.green.offset);
610 }
611 for ( i=0; i<vinfo.blue.length; ++i ) {
612 vformat->Bmask <<= 1;
613 vformat->Bmask |= (0x00000001<<vinfo.blue.offset);
614 }
615 saved_vinfo = vinfo;
616
617 /* Save hardware palette, if needed */
618 FB_SavePalette(this, &finfo, &vinfo);
619
620 /* If the I/O registers are available, memory map them so we
621 can take advantage of any supported hardware acceleration.
622 */
623 vinfo.accel_flags = 0; /* Temporarily reserve registers */
624 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
625 if ( finfo.accel && finfo.mmio_len ) {
626 mapped_iolen = finfo.mmio_len;
627 mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
628 MAP_SHARED, console_fd, mapped_memlen);
629 if ( mapped_io == (char *)-1 ) {
630 /* Hmm, failed to memory map I/O registers */
631 mapped_io = NULL;
632 }
633 }
634
635 rotate = FBCON_ROTATE_NONE;
636 rotation = SDL_getenv("SDL_VIDEO_FBCON_ROTATION");
637 if (rotation != NULL) {
638 if (SDL_strlen(rotation) == 0) {
639 shadow_fb = 0;
640 rotate = FBCON_ROTATE_NONE;
641#ifdef FBCON_DEBUG
642 printf("Not rotating, no shadow\n");
643#endif
644 } else if (!SDL_strcmp(rotation, "NONE")) {
645 shadow_fb = 1;
646 rotate = FBCON_ROTATE_NONE;
647#ifdef FBCON_DEBUG
648 printf("Not rotating, but still using shadow\n");
649#endif
650 } else if (!SDL_strcmp(rotation, "CW")) {
651 shadow_fb = 1;
652 rotate = FBCON_ROTATE_CW;
653#ifdef FBCON_DEBUG
654 printf("Rotating screen clockwise\n");
655#endif
656 } else if (!SDL_strcmp(rotation, "CCW")) {
657 shadow_fb = 1;
658 rotate = FBCON_ROTATE_CCW;
659#ifdef FBCON_DEBUG
660 printf("Rotating screen counter clockwise\n");
661#endif
662 } else if (!SDL_strcmp(rotation, "UD")) {
663 shadow_fb = 1;
664 rotate = FBCON_ROTATE_UD;
665#ifdef FBCON_DEBUG
666 printf("Rotating screen upside down\n");
667#endif
668 } else {
669 SDL_SetError("\"%s\" is not a valid value for "
670 "SDL_VIDEO_FBCON_ROTATION", rotation);
671 return(-1);
672 }
673 }
674
675 if (rotate == FBCON_ROTATE_CW || rotate == FBCON_ROTATE_CCW) {
676 current_w = vinfo.yres;
677 current_h = vinfo.xres;
678 } else {
679 current_w = vinfo.xres;
680 current_h = vinfo.yres;
681 }
682
683 /* Query for the list of available video modes */
684 current_index = ((vinfo.bits_per_pixel+7)/8)-1;
685 modesdb = fopen(FB_MODES_DB, "r");
686 for ( i=0; i<NUM_MODELISTS; ++i ) {
687 SDL_nummodes[i] = 0;
688 SDL_modelist[i] = NULL;
689 }
690 if ( SDL_getenv("SDL_FB_BROKEN_MODES") != NULL ) {
691 FB_AddMode(this, current_index, current_w, current_h, 0);
692 } else if(modesdb) {
693 while ( read_fbmodes_mode(modesdb, &vinfo) ) {
694 for ( i=0; i<NUM_MODELISTS; ++i ) {
695 unsigned int w, h;
696
697 if (rotate == FBCON_ROTATE_CW || rotate == FBCON_ROTATE_CCW) {
698 w = vinfo.yres;
699 h = vinfo.xres;
700 } else {
701 w = vinfo.xres;
702 h = vinfo.yres;
703 }
704 /* See if we are querying for the current mode */
705 if ( i == current_index ) {
706 if ( (current_w > w) || (current_h > h) ) {
707 /* Only check once */
708 FB_AddMode(this, i, current_w, current_h, 0);
709 current_index = -1;
710 }
711 }
712 if ( FB_CheckMode(this, &vinfo, i, &w, &h) ) {
713 FB_AddMode(this, i, w, h, 0);
714 }
715 }
716 }
717 fclose(modesdb);
718 FB_SortModes(this);
719 } else {
720 for ( i=0; i<NUM_MODELISTS; ++i ) {
721 for ( j=0; j<(sizeof(checkres)/sizeof(checkres[0])); ++j ) {
722 unsigned int w, h;
723
724 if (rotate == FBCON_ROTATE_CW || rotate == FBCON_ROTATE_CCW) {
725 w = checkres[j].h;
726 h = checkres[j].w;
727 } else {
728 w = checkres[j].w;
729 h = checkres[j].h;
730 }
731 /* See if we are querying for the current mode */
732 if ( i == current_index ) {
733 if ( (current_w > w) || (current_h > h) ) {
734 /* Only check once */
735 FB_AddMode(this, i, current_w, current_h, 0);
736 current_index = -1;
737 }
738 }
739 if ( FB_CheckMode(this, &vinfo, i, &w, &h) ) {
740 FB_AddMode(this, i, w, h, 1);
741 }
742 }
743 }
744 }
745
746 this->info.current_w = current_w;
747 this->info.current_h = current_h;
748 this->info.wm_available = 0;
749 this->info.hw_available = !shadow_fb;
750 this->info.video_mem = shadow_fb ? 0 : finfo.smem_len/1024;
751 /* Fill in our hardware acceleration capabilities */
752 if ( mapped_io ) {
753 switch (finfo.accel) {
754 case FB_ACCEL_MATROX_MGA2064W:
755 case FB_ACCEL_MATROX_MGA1064SG:
756 case FB_ACCEL_MATROX_MGA2164W:
757 case FB_ACCEL_MATROX_MGA2164W_AGP:
758 case FB_ACCEL_MATROX_MGAG100:
759 /*case FB_ACCEL_MATROX_MGAG200: G200 acceleration broken! */
760 case FB_ACCEL_MATROX_MGAG400:
761#ifdef FBACCEL_DEBUG
762 printf("Matrox hardware accelerator!\n");
763#endif
764 FB_MatroxAccel(this, finfo.accel);
765 break;
766 case FB_ACCEL_3DFX_BANSHEE:
767#ifdef FBACCEL_DEBUG
768 printf("3DFX hardware accelerator!\n");
769#endif
770 FB_3DfxAccel(this, finfo.accel);
771 break;
772 case FB_ACCEL_NV3:
773 case FB_ACCEL_NV4:
774#ifdef FBACCEL_DEBUG
775 printf("NVidia hardware accelerator!\n");
776#endif
777 FB_RivaAccel(this, finfo.accel);
778 break;
779 default:
780#ifdef FBACCEL_DEBUG
781 printf("Unknown hardware accelerator.\n");
782#endif
783 break;
784 }
785 }
786
787 if (shadow_fb) {
788 shadow_mem = (char *)SDL_malloc(mapped_memlen);
789 if (shadow_mem == NULL) {
790 SDL_SetError("No memory for shadow");
791 return (-1);
792 }
793 }
794
795 /* Enable mouse and keyboard support */
796 if ( FB_OpenKeyboard(this) < 0 ) {
797 FB_VideoQuit(this);
798 return(-1);
799 }
800 if ( FB_OpenMouse(this) < 0 ) {
801 const char *sdl_nomouse;
802
803 sdl_nomouse = SDL_getenv("SDL_NOMOUSE");
804 if ( ! sdl_nomouse ) {
805 SDL_SetError("Unable to open mouse");
806 FB_VideoQuit(this);
807 return(-1);
808 }
809 }
810
811 /* We're done! */
812 return(0);
813}
814
815static SDL_Rect **FB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
816{
817 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
818}
819
820/* Various screen update functions available */
821static void FB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
822#ifdef VGA16_FBCON_SUPPORT
823static void FB_VGA16Update(_THIS, int numrects, SDL_Rect *rects);
824#endif
825
826#ifdef FBCON_DEBUG
827static void print_vinfo(struct fb_var_screeninfo *vinfo)
828{
829 fprintf(stderr, "Printing vinfo:\n");
830 fprintf(stderr, "\txres: %d\n", vinfo->xres);
831 fprintf(stderr, "\tyres: %d\n", vinfo->yres);
832 fprintf(stderr, "\txres_virtual: %d\n", vinfo->xres_virtual);
833 fprintf(stderr, "\tyres_virtual: %d\n", vinfo->yres_virtual);
834 fprintf(stderr, "\txoffset: %d\n", vinfo->xoffset);
835 fprintf(stderr, "\tyoffset: %d\n", vinfo->yoffset);
836 fprintf(stderr, "\tbits_per_pixel: %d\n", vinfo->bits_per_pixel);
837 fprintf(stderr, "\tgrayscale: %d\n", vinfo->grayscale);
838 fprintf(stderr, "\tnonstd: %d\n", vinfo->nonstd);
839 fprintf(stderr, "\tactivate: %d\n", vinfo->activate);
840 fprintf(stderr, "\theight: %d\n", vinfo->height);
841 fprintf(stderr, "\twidth: %d\n", vinfo->width);
842 fprintf(stderr, "\taccel_flags: %d\n", vinfo->accel_flags);
843 fprintf(stderr, "\tpixclock: %d\n", vinfo->pixclock);
844 fprintf(stderr, "\tleft_margin: %d\n", vinfo->left_margin);
845 fprintf(stderr, "\tright_margin: %d\n", vinfo->right_margin);
846 fprintf(stderr, "\tupper_margin: %d\n", vinfo->upper_margin);
847 fprintf(stderr, "\tlower_margin: %d\n", vinfo->lower_margin);
848 fprintf(stderr, "\thsync_len: %d\n", vinfo->hsync_len);
849 fprintf(stderr, "\tvsync_len: %d\n", vinfo->vsync_len);
850 fprintf(stderr, "\tsync: %d\n", vinfo->sync);
851 fprintf(stderr, "\tvmode: %d\n", vinfo->vmode);
852 fprintf(stderr, "\tred: %d/%d\n", vinfo->red.length, vinfo->red.offset);
853 fprintf(stderr, "\tgreen: %d/%d\n", vinfo->green.length, vinfo->green.offset);
854 fprintf(stderr, "\tblue: %d/%d\n", vinfo->blue.length, vinfo->blue.offset);
855 fprintf(stderr, "\talpha: %d/%d\n", vinfo->transp.length, vinfo->transp.offset);
856}
857static void print_finfo(struct fb_fix_screeninfo *finfo)
858{
859 fprintf(stderr, "Printing finfo:\n");
860 fprintf(stderr, "\tsmem_start = %p\n", (char *)finfo->smem_start);
861 fprintf(stderr, "\tsmem_len = %d\n", finfo->smem_len);
862 fprintf(stderr, "\ttype = %d\n", finfo->type);
863 fprintf(stderr, "\ttype_aux = %d\n", finfo->type_aux);
864 fprintf(stderr, "\tvisual = %d\n", finfo->visual);
865 fprintf(stderr, "\txpanstep = %d\n", finfo->xpanstep);
866 fprintf(stderr, "\typanstep = %d\n", finfo->ypanstep);
867 fprintf(stderr, "\tywrapstep = %d\n", finfo->ywrapstep);
868 fprintf(stderr, "\tline_length = %d\n", finfo->line_length);
869 fprintf(stderr, "\tmmio_start = %p\n", (char *)finfo->mmio_start);
870 fprintf(stderr, "\tmmio_len = %d\n", finfo->mmio_len);
871 fprintf(stderr, "\taccel = %d\n", finfo->accel);
872}
873#endif
874
875static int choose_fbmodes_mode(struct fb_var_screeninfo *vinfo)
876{
877 int matched;
878 FILE *modesdb;
879 struct fb_var_screeninfo cinfo;
880
881 matched = 0;
882 modesdb = fopen(FB_MODES_DB, "r");
883 if ( modesdb ) {
884 /* Parse the mode definition file */
885 while ( read_fbmodes_mode(modesdb, &cinfo) ) {
886 if ( (vinfo->xres == cinfo.xres && vinfo->yres == cinfo.yres) &&
887 (!matched || (vinfo->bits_per_pixel == cinfo.bits_per_pixel)) ) {
888 vinfo->pixclock = cinfo.pixclock;
889 vinfo->left_margin = cinfo.left_margin;
890 vinfo->right_margin = cinfo.right_margin;
891 vinfo->upper_margin = cinfo.upper_margin;
892 vinfo->lower_margin = cinfo.lower_margin;
893 vinfo->hsync_len = cinfo.hsync_len;
894 vinfo->vsync_len = cinfo.vsync_len;
895 if ( matched ) {
896 break;
897 }
898 matched = 1;
899 }
900 }
901 fclose(modesdb);
902 }
903 return(matched);
904}
905
906static int choose_vesa_mode(struct fb_var_screeninfo *vinfo)
907{
908 int matched;
909 int i;
910
911 /* Check for VESA timings */
912 matched = 0;
913 for ( i=0; i<(sizeof(vesa_timings)/sizeof(vesa_timings[0])); ++i ) {
914 if ( (vinfo->xres == vesa_timings[i].xres) &&
915 (vinfo->yres == vesa_timings[i].yres) ) {
916#ifdef FBCON_DEBUG
917 fprintf(stderr, "Using VESA timings for %dx%d\n",
918 vinfo->xres, vinfo->yres);
919#endif
920 if ( vesa_timings[i].pixclock ) {
921 vinfo->pixclock = vesa_timings[i].pixclock;
922 }
923 vinfo->left_margin = vesa_timings[i].left;
924 vinfo->right_margin = vesa_timings[i].right;
925 vinfo->upper_margin = vesa_timings[i].upper;
926 vinfo->lower_margin = vesa_timings[i].lower;
927 vinfo->hsync_len = vesa_timings[i].hslen;
928 vinfo->vsync_len = vesa_timings[i].vslen;
929 vinfo->sync = vesa_timings[i].sync;
930 vinfo->vmode = vesa_timings[i].vmode;
931 matched = 1;
932 break;
933 }
934 }
935 return(matched);
936}
937
938#ifdef VGA16_FBCON_SUPPORT
939static SDL_Surface *FB_SetVGA16Mode(_THIS, SDL_Surface *current,
940 int width, int height, int bpp, Uint32 flags)
941{
942 struct fb_fix_screeninfo finfo;
943 struct fb_var_screeninfo vinfo;
944
945 /* Set the terminal into graphics mode */
946 if ( FB_EnterGraphicsMode(this) < 0 ) {
947 return(NULL);
948 }
949
950 /* Restore the original palette */
951 FB_RestorePalette(this);
952
953 /* Set the video mode and get the final screen format */
954 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
955 SDL_SetError("Couldn't get console screen info");
956 return(NULL);
957 }
958 cache_vinfo = vinfo;
959#ifdef FBCON_DEBUG
960 fprintf(stderr, "Printing actual vinfo:\n");
961 print_vinfo(&vinfo);
962#endif
963 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
964 return(NULL);
965 }
966 current->format->palette->ncolors = 16;
967
968 /* Get the fixed information about the console hardware.
969 This is necessary since finfo.line_length changes.
970 */
971 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
972 SDL_SetError("Couldn't get console hardware info");
973 return(NULL);
974 }
975#ifdef FBCON_DEBUG
976 fprintf(stderr, "Printing actual finfo:\n");
977 print_finfo(&finfo);
978#endif
979
980 /* Save hardware palette, if needed */
981 FB_SavePalette(this, &finfo, &vinfo);
982
983 /* Set up the new mode framebuffer */
984 current->flags = SDL_FULLSCREEN;
985 current->w = vinfo.xres;
986 current->h = vinfo.yres;
987 current->pitch = current->w;
988 current->pixels = SDL_malloc(current->h*current->pitch);
989
990 /* Set the update rectangle function */
991 this->UpdateRects = FB_VGA16Update;
992
993 /* We're done */
994 return(current);
995}
996#endif /* VGA16_FBCON_SUPPORT */
997
998static SDL_Surface *FB_SetVideoMode(_THIS, SDL_Surface *current,
999 int width, int height, int bpp, Uint32 flags)
1000{
1001 struct fb_fix_screeninfo finfo;
1002 struct fb_var_screeninfo vinfo;
1003 int i;
1004 Uint32 Rmask;
1005 Uint32 Gmask;
1006 Uint32 Bmask;
1007 char *surfaces_mem;
1008 int surfaces_len;
1009
1010 /* Set the terminal into graphics mode */
1011 if ( FB_EnterGraphicsMode(this) < 0 ) {
1012 return(NULL);
1013 }
1014
1015 /* Restore the original palette */
1016 FB_RestorePalette(this);
1017
1018 /* Set the video mode and get the final screen format */
1019 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
1020 SDL_SetError("Couldn't get console screen info");
1021 return(NULL);
1022 }
1023#ifdef FBCON_DEBUG
1024 fprintf(stderr, "Printing original vinfo:\n");
1025 print_vinfo(&vinfo);
1026#endif
1027 /* Do not use double buffering with shadow buffer */
1028 if (shadow_fb) {
1029 flags &= ~SDL_DOUBLEBUF;
1030 }
1031
1032 if ( (vinfo.xres != width) || (vinfo.yres != height) ||
1033 (vinfo.bits_per_pixel != bpp) || (flags & SDL_DOUBLEBUF) ) {
1034 vinfo.activate = FB_ACTIVATE_NOW;
1035 vinfo.accel_flags = 0;
1036 vinfo.bits_per_pixel = bpp;
1037 vinfo.xres = width;
1038 vinfo.xres_virtual = width;
1039 vinfo.yres = height;
1040 if ( flags & SDL_DOUBLEBUF ) {
1041 vinfo.yres_virtual = height*2;
1042 } else {
1043 vinfo.yres_virtual = height;
1044 }
1045 vinfo.xoffset = 0;
1046 vinfo.yoffset = 0;
1047 vinfo.red.length = vinfo.red.offset = 0;
1048 vinfo.green.length = vinfo.green.offset = 0;
1049 vinfo.blue.length = vinfo.blue.offset = 0;
1050 vinfo.transp.length = vinfo.transp.offset = 0;
1051 if ( ! choose_fbmodes_mode(&vinfo) ) {
1052 choose_vesa_mode(&vinfo);
1053 }
1054#ifdef FBCON_DEBUG
1055 fprintf(stderr, "Printing wanted vinfo:\n");
1056 print_vinfo(&vinfo);
1057#endif
1058 if ( !shadow_fb &&
1059 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) {
1060 vinfo.yres_virtual = height;
1061 if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) {
1062 SDL_SetError("Couldn't set console screen info");
1063 return(NULL);
1064 }
1065 }
1066 } else {
1067 int maxheight;
1068
1069 /* Figure out how much video memory is available */
1070 if ( flags & SDL_DOUBLEBUF ) {
1071 maxheight = height*2;
1072 } else {
1073 maxheight = height;
1074 }
1075 if ( vinfo.yres_virtual > maxheight ) {
1076 vinfo.yres_virtual = maxheight;
1077 }
1078 }
1079 cache_vinfo = vinfo;
1080#ifdef FBCON_DEBUG
1081 fprintf(stderr, "Printing actual vinfo:\n");
1082 print_vinfo(&vinfo);
1083#endif
1084 Rmask = 0;
1085 for ( i=0; i<vinfo.red.length; ++i ) {
1086 Rmask <<= 1;
1087 Rmask |= (0x00000001<<vinfo.red.offset);
1088 }
1089 Gmask = 0;
1090 for ( i=0; i<vinfo.green.length; ++i ) {
1091 Gmask <<= 1;
1092 Gmask |= (0x00000001<<vinfo.green.offset);
1093 }
1094 Bmask = 0;
1095 for ( i=0; i<vinfo.blue.length; ++i ) {
1096 Bmask <<= 1;
1097 Bmask |= (0x00000001<<vinfo.blue.offset);
1098 }
1099 if ( ! SDL_ReallocFormat(current, vinfo.bits_per_pixel,
1100 Rmask, Gmask, Bmask, 0) ) {
1101 return(NULL);
1102 }
1103
1104 /* Get the fixed information about the console hardware.
1105 This is necessary since finfo.line_length changes.
1106 */
1107 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
1108 SDL_SetError("Couldn't get console hardware info");
1109 return(NULL);
1110 }
1111
1112 /* Save hardware palette, if needed */
1113 FB_SavePalette(this, &finfo, &vinfo);
1114
1115 if (shadow_fb) {
1116 if (vinfo.bits_per_pixel == 16) {
1117 blitFunc = (rotate == FBCON_ROTATE_NONE ||
1118 rotate == FBCON_ROTATE_UD) ?
1119 FB_blit16 : FB_blit16blocked;
1120 } else {
1121#ifdef FBCON_DEBUG
1122 fprintf(stderr, "Init vinfo:\n");
1123 print_vinfo(&vinfo);
1124#endif
1125 SDL_SetError("Using software buffer, but no blitter "
1126 "function is available for %d bpp.",
1127 vinfo.bits_per_pixel);
1128 return(NULL);
1129 }
1130 }
1131
1132 /* Set up the new mode framebuffer */
1133 current->flags &= SDL_FULLSCREEN;
1134 if (shadow_fb) {
1135 current->flags |= SDL_SWSURFACE;
1136 } else {
1137 current->flags |= SDL_HWSURFACE;
1138 }
1139 current->w = vinfo.xres;
1140 current->h = vinfo.yres;
1141 if (shadow_fb) {
1142 current->pitch = current->w * ((vinfo.bits_per_pixel + 7) / 8);
1143 current->pixels = shadow_mem;
1144 physlinebytes = finfo.line_length;
1145 } else {
1146 current->pitch = finfo.line_length;
1147 current->pixels = mapped_mem+mapped_offset;
1148 }
1149
1150 /* Set up the information for hardware surfaces */
1151 surfaces_mem = (char *)current->pixels +
1152 vinfo.yres_virtual*current->pitch;
1153 surfaces_len = (shadow_fb) ?
1154 0 : (mapped_memlen-(surfaces_mem-mapped_mem));
1155
1156 FB_FreeHWSurfaces(this);
1157 FB_InitHWSurfaces(this, current, surfaces_mem, surfaces_len);
1158
1159 /* Let the application know we have a hardware palette */
1160 switch (finfo.visual) {
1161 case FB_VISUAL_PSEUDOCOLOR:
1162 current->flags |= SDL_HWPALETTE;
1163 break;
1164 default:
1165 break;
1166 }
1167
1168 /* Update for double-buffering, if we can */
1169 if ( flags & SDL_DOUBLEBUF ) {
1170 if ( vinfo.yres_virtual == (height*2) ) {
1171 current->flags |= SDL_DOUBLEBUF;
1172 flip_page = 0;
1173 flip_address[0] = (char *)current->pixels;
1174 flip_address[1] = (char *)current->pixels+
1175 current->h*current->pitch;
1176 this->screen = current;
1177 FB_FlipHWSurface(this, current);
1178 this->screen = NULL;
1179 }
1180 }
1181
1182 /* Set the update rectangle function */
1183 this->UpdateRects = FB_DirectUpdate;
1184
1185 /* We're done */
1186 return(current);
1187}
1188
1189#ifdef FBCON_DEBUG
1190void FB_DumpHWSurfaces(_THIS)
1191{
1192 vidmem_bucket *bucket;
1193
1194 printf("Memory left: %d (%d total)\n", surfaces_memleft, surfaces_memtotal);
1195 printf("\n");
1196 printf(" Base Size\n");
1197 for ( bucket=&surfaces; bucket; bucket=bucket->next ) {
1198 printf("Bucket: %p, %d (%s)\n", bucket->base, bucket->size, bucket->used ? "used" : "free");
1199 if ( bucket->prev ) {
1200 if ( bucket->base != bucket->prev->base+bucket->prev->size ) {
1201 printf("Warning, corrupt bucket list! (prev)\n");
1202 }
1203 } else {
1204 if ( bucket != &surfaces ) {
1205 printf("Warning, corrupt bucket list! (!prev)\n");
1206 }
1207 }
1208 if ( bucket->next ) {
1209 if ( bucket->next->base != bucket->base+bucket->size ) {
1210 printf("Warning, corrupt bucket list! (next)\n");
1211 }
1212 }
1213 }
1214 printf("\n");
1215}
1216#endif
1217
1218static int FB_InitHWSurfaces(_THIS, SDL_Surface *screen, char *base, int size)
1219{
1220 vidmem_bucket *bucket;
1221
1222 surfaces_memtotal = size;
1223 surfaces_memleft = size;
1224
1225 if ( surfaces_memleft > 0 ) {
1226 bucket = (vidmem_bucket *)SDL_malloc(sizeof(*bucket));
1227 if ( bucket == NULL ) {
1228 SDL_OutOfMemory();
1229 return(-1);
1230 }
1231 bucket->prev = &surfaces;
1232 bucket->used = 0;
1233 bucket->dirty = 0;
1234 bucket->base = base;
1235 bucket->size = size;
1236 bucket->next = NULL;
1237 } else {
1238 bucket = NULL;
1239 }
1240
1241 surfaces.prev = NULL;
1242 surfaces.used = 1;
1243 surfaces.dirty = 0;
1244 surfaces.base = screen->pixels;
1245 surfaces.size = (unsigned int)((long)base - (long)surfaces.base);
1246 surfaces.next = bucket;
1247 screen->hwdata = (struct private_hwdata *)&surfaces;
1248 return(0);
1249}
1250static void FB_FreeHWSurfaces(_THIS)
1251{
1252 vidmem_bucket *bucket, *freeable;
1253
1254 bucket = surfaces.next;
1255 while ( bucket ) {
1256 freeable = bucket;
1257 bucket = bucket->next;
1258 SDL_free(freeable);
1259 }
1260 surfaces.next = NULL;
1261}
1262
1263static int FB_AllocHWSurface(_THIS, SDL_Surface *surface)
1264{
1265 vidmem_bucket *bucket;
1266 int size;
1267 int extra;
1268
1269/* Temporarily, we only allow surfaces the same width as display.
1270 Some blitters require the pitch between two hardware surfaces
1271 to be the same. Others have interesting alignment restrictions.
1272 Until someone who knows these details looks at the code...
1273*/
1274if ( surface->pitch > SDL_VideoSurface->pitch ) {
1275 SDL_SetError("Surface requested wider than screen");
1276 return(-1);
1277}
1278surface->pitch = SDL_VideoSurface->pitch;
1279 size = surface->h * surface->pitch;
1280#ifdef FBCON_DEBUG
1281 fprintf(stderr, "Allocating bucket of %d bytes\n", size);
1282#endif
1283
1284 /* Quick check for available mem */
1285 if ( size > surfaces_memleft ) {
1286 SDL_SetError("Not enough video memory");
1287 return(-1);
1288 }
1289
1290 /* Search for an empty bucket big enough */
1291 for ( bucket=&surfaces; bucket; bucket=bucket->next ) {
1292 if ( ! bucket->used && (size <= bucket->size) ) {
1293 break;
1294 }
1295 }
1296 if ( bucket == NULL ) {
1297 SDL_SetError("Video memory too fragmented");
1298 return(-1);
1299 }
1300
1301 /* Create a new bucket for left-over memory */
1302 extra = (bucket->size - size);
1303 if ( extra ) {
1304 vidmem_bucket *newbucket;
1305
1306#ifdef FBCON_DEBUG
1307 fprintf(stderr, "Adding new free bucket of %d bytes\n", extra);
1308#endif
1309 newbucket = (vidmem_bucket *)SDL_malloc(sizeof(*newbucket));
1310 if ( newbucket == NULL ) {
1311 SDL_OutOfMemory();
1312 return(-1);
1313 }
1314 newbucket->prev = bucket;
1315 newbucket->used = 0;
1316 newbucket->base = bucket->base+size;
1317 newbucket->size = extra;
1318 newbucket->next = bucket->next;
1319 if ( bucket->next ) {
1320 bucket->next->prev = newbucket;
1321 }
1322 bucket->next = newbucket;
1323 }
1324
1325 /* Set the current bucket values and return it! */
1326 bucket->used = 1;
1327 bucket->size = size;
1328 bucket->dirty = 0;
1329#ifdef FBCON_DEBUG
1330 fprintf(stderr, "Allocated %d bytes at %p\n", bucket->size, bucket->base);
1331#endif
1332 surfaces_memleft -= size;
1333 surface->flags |= SDL_HWSURFACE;
1334 surface->pixels = bucket->base;
1335 surface->hwdata = (struct private_hwdata *)bucket;
1336 return(0);
1337}
1338static void FB_FreeHWSurface(_THIS, SDL_Surface *surface)
1339{
1340 vidmem_bucket *bucket, *freeable;
1341
1342 /* Look for the bucket in the current list */
1343 for ( bucket=&surfaces; bucket; bucket=bucket->next ) {
1344 if ( bucket == (vidmem_bucket *)surface->hwdata ) {
1345 break;
1346 }
1347 }
1348 if ( bucket && bucket->used ) {
1349 /* Add the memory back to the total */
1350#ifdef DGA_DEBUG
1351 printf("Freeing bucket of %d bytes\n", bucket->size);
1352#endif
1353 surfaces_memleft += bucket->size;
1354
1355 /* Can we merge the space with surrounding buckets? */
1356 bucket->used = 0;
1357 if ( bucket->next && ! bucket->next->used ) {
1358#ifdef DGA_DEBUG
1359 printf("Merging with next bucket, for %d total bytes\n", bucket->size+bucket->next->size);
1360#endif
1361 freeable = bucket->next;
1362 bucket->size += bucket->next->size;
1363 bucket->next = bucket->next->next;
1364 if ( bucket->next ) {
1365 bucket->next->prev = bucket;
1366 }
1367 SDL_free(freeable);
1368 }
1369 if ( bucket->prev && ! bucket->prev->used ) {
1370#ifdef DGA_DEBUG
1371 printf("Merging with previous bucket, for %d total bytes\n", bucket->prev->size+bucket->size);
1372#endif
1373 freeable = bucket;
1374 bucket->prev->size += bucket->size;
1375 bucket->prev->next = bucket->next;
1376 if ( bucket->next ) {
1377 bucket->next->prev = bucket->prev;
1378 }
1379 SDL_free(freeable);
1380 }
1381 }
1382 surface->pixels = NULL;
1383 surface->hwdata = NULL;
1384}
1385
1386static int FB_LockHWSurface(_THIS, SDL_Surface *surface)
1387{
1388 if ( switched_away ) {
1389 return -2; /* no hardware access */
1390 }
1391 if ( surface == this->screen ) {
1392 SDL_mutexP(hw_lock);
1393 if ( FB_IsSurfaceBusy(surface) ) {
1394 FB_WaitBusySurfaces(this);
1395 }
1396 } else {
1397 if ( FB_IsSurfaceBusy(surface) ) {
1398 FB_WaitBusySurfaces(this);
1399 }
1400 }
1401 return(0);
1402}
1403static void FB_UnlockHWSurface(_THIS, SDL_Surface *surface)
1404{
1405 if ( surface == this->screen ) {
1406 SDL_mutexV(hw_lock);
1407 }
1408}
1409
1410static void FB_WaitVBL(_THIS)
1411{
1412#ifdef FBIOWAITRETRACE /* Heheh, this didn't make it into the main kernel */
1413 ioctl(console_fd, FBIOWAITRETRACE, 0);
1414#endif
1415 return;
1416}
1417
1418static void FB_WaitIdle(_THIS)
1419{
1420 return;
1421}
1422
1423static int FB_FlipHWSurface(_THIS, SDL_Surface *surface)
1424{
1425 if ( switched_away ) {
1426 return -2; /* no hardware access */
1427 }
1428
1429 /* Wait for vertical retrace and then flip display */
1430 cache_vinfo.yoffset = flip_page*surface->h;
1431 if ( FB_IsSurfaceBusy(this->screen) ) {
1432 FB_WaitBusySurfaces(this);
1433 }
1434 wait_vbl(this);
1435 if ( ioctl(console_fd, FBIOPAN_DISPLAY, &cache_vinfo) < 0 ) {
1436 SDL_SetError("ioctl(FBIOPAN_DISPLAY) failed");
1437 return(-1);
1438 }
1439 flip_page = !flip_page;
1440
1441 surface->pixels = flip_address[flip_page];
1442 return(0);
1443}
1444
1445static void FB_blit16(Uint8 *byte_src_pos, int src_right_delta, int src_down_delta,
1446 Uint8 *byte_dst_pos, int dst_linebytes, int width, int height)
1447{
1448 int w;
1449 Uint16 *src_pos = (Uint16 *)byte_src_pos;
1450 Uint16 *dst_pos = (Uint16 *)byte_dst_pos;
1451
1452 while (height) {
1453 Uint16 *src = src_pos;
1454 Uint16 *dst = dst_pos;
1455 for (w = width; w != 0; w--) {
1456 *dst = *src;
1457 src += src_right_delta;
1458 dst++;
1459 }
1460 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes);
1461 src_pos += src_down_delta;
1462 height--;
1463 }
1464}
1465
1466#define BLOCKSIZE_W 32
1467#define BLOCKSIZE_H 32
1468
1469static void FB_blit16blocked(Uint8 *byte_src_pos, int src_right_delta, int src_down_delta,
1470 Uint8 *byte_dst_pos, int dst_linebytes, int width, int height)
1471{
1472 int w;
1473 Uint16 *src_pos = (Uint16 *)byte_src_pos;
1474 Uint16 *dst_pos = (Uint16 *)byte_dst_pos;
1475
1476 while (height > 0) {
1477 Uint16 *src = src_pos;
1478 Uint16 *dst = dst_pos;
1479 for (w = width; w > 0; w -= BLOCKSIZE_W) {
1480 FB_blit16((Uint8 *)src,
1481 src_right_delta,
1482 src_down_delta,
1483 (Uint8 *)dst,
1484 dst_linebytes,
1485 min(w, BLOCKSIZE_W),
1486 min(height, BLOCKSIZE_H));
1487 src += src_right_delta * BLOCKSIZE_W;
1488 dst += BLOCKSIZE_W;
1489 }
1490 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes * BLOCKSIZE_H);
1491 src_pos += src_down_delta * BLOCKSIZE_H;
1492 height -= BLOCKSIZE_H;
1493 }
1494}
1495
1496static void FB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
1497{
1498 int width = cache_vinfo.xres;
1499 int height = cache_vinfo.yres;
1500 int bytes_per_pixel = (cache_vinfo.bits_per_pixel + 7) / 8;
1501 int i;
1502
1503 if (!shadow_fb) {
1504 /* The application is already updating the visible video memory */
1505 return;
1506 }
1507
1508 if (cache_vinfo.bits_per_pixel != 16) {
1509 SDL_SetError("Shadow copy only implemented for 16 bpp");
1510 return;
1511 }
1512
1513 for (i = 0; i < numrects; i++) {
1514 int x1, y1, x2, y2;
1515 int scr_x1, scr_y1, scr_x2, scr_y2;
1516 int sha_x1, sha_y1;
1517 int shadow_right_delta; /* Address change when moving right in dest */
1518 int shadow_down_delta; /* Address change when moving down in dest */
1519 char *src_start;
1520 char *dst_start;
1521
1522 x1 = rects[i].x;
1523 y1 = rects[i].y;
1524 x2 = x1 + rects[i].w;
1525 y2 = y1 + rects[i].h;
1526
1527 if (x1 < 0) {
1528 x1 = 0;
1529 } else if (x1 > width) {
1530 x1 = width;
1531 }
1532 if (x2 < 0) {
1533 x2 = 0;
1534 } else if (x2 > width) {
1535 x2 = width;
1536 }
1537 if (y1 < 0) {
1538 y1 = 0;
1539 } else if (y1 > height) {
1540 y1 = height;
1541 }
1542 if (y2 < 0) {
1543 y2 = 0;
1544 } else if (y2 > height) {
1545 y2 = height;
1546 }
1547 if (x2 <= x1 || y2 <= y1) {
1548 continue;
1549 }
1550
1551 switch (rotate) {
1552 case FBCON_ROTATE_NONE:
1553 sha_x1 = scr_x1 = x1;
1554 sha_y1 = scr_y1 = y1;
1555 scr_x2 = x2;
1556 scr_y2 = y2;
1557 shadow_right_delta = 1;
1558 shadow_down_delta = width;
1559 break;
1560 case FBCON_ROTATE_CCW:
1561 scr_x1 = y1;
1562 scr_y1 = width - x2;
1563 scr_x2 = y2;
1564 scr_y2 = width - x1;
1565 sha_x1 = x2 - 1;
1566 sha_y1 = y1;
1567 shadow_right_delta = width;
1568 shadow_down_delta = -1;
1569 break;
1570 case FBCON_ROTATE_UD:
1571 scr_x1 = width - x2;
1572 scr_y1 = height - y2;
1573 scr_x2 = width - x1;
1574 scr_y2 = height - y1;
1575 sha_x1 = x2 - 1;
1576 sha_y1 = y2 - 1;
1577 shadow_right_delta = -1;
1578 shadow_down_delta = -width;
1579 break;
1580 case FBCON_ROTATE_CW:
1581 scr_x1 = height - y2;
1582 scr_y1 = x1;
1583 scr_x2 = height - y1;
1584 scr_y2 = x2;
1585 sha_x1 = x1;
1586 sha_y1 = y2 - 1;
1587 shadow_right_delta = -width;
1588 shadow_down_delta = 1;
1589 break;
1590 default:
1591 SDL_SetError("Unknown rotation");
1592 return;
1593 }
1594
1595 src_start = shadow_mem +
1596 (sha_y1 * width + sha_x1) * bytes_per_pixel;
1597 dst_start = mapped_mem + mapped_offset + scr_y1 * physlinebytes +
1598 scr_x1 * bytes_per_pixel;
1599
1600 blitFunc((Uint8 *) src_start,
1601 shadow_right_delta,
1602 shadow_down_delta,
1603 (Uint8 *) dst_start,
1604 physlinebytes,
1605 scr_x2 - scr_x1,
1606 scr_y2 - scr_y1);
1607 }
1608}
1609
1610#ifdef VGA16_FBCON_SUPPORT
1611/* Code adapted with thanks from the XFree86 VGA16 driver! :) */
1612#define writeGr(index, value) \
1613outb(index, 0x3CE); \
1614outb(value, 0x3CF);
1615#define writeSeq(index, value) \
1616outb(index, 0x3C4); \
1617outb(value, 0x3C5);
1618
1619static void FB_VGA16Update(_THIS, int numrects, SDL_Rect *rects)
1620{
1621 SDL_Surface *screen;
1622 int width, height, FBPitch, left, i, j, SRCPitch, phase;
1623 register Uint32 m;
1624 Uint8 s1, s2, s3, s4;
1625 Uint32 *src, *srcPtr;
1626 Uint8 *dst, *dstPtr;
1627
1628 if ( switched_away ) {
1629 return; /* no hardware access */
1630 }
1631
1632 screen = this->screen;
1633 FBPitch = screen->w >> 3;
1634 SRCPitch = screen->pitch >> 2;
1635
1636 writeGr(0x03, 0x00);
1637 writeGr(0x05, 0x00);
1638 writeGr(0x01, 0x00);
1639 writeGr(0x08, 0xFF);
1640
1641 while(numrects--) {
1642 left = rects->x & ~7;
1643 width = (rects->w + 7) >> 3;
1644 height = rects->h;
1645 src = (Uint32*)screen->pixels + (rects->y * SRCPitch) + (left >> 2);
1646 dst = (Uint8*)mapped_mem + (rects->y * FBPitch) + (left >> 3);
1647
1648 if((phase = (long)dst & 3L)) {
1649 phase = 4 - phase;
1650 if(phase > width) phase = width;
1651 width -= phase;
1652 }
1653
1654 while(height--) {
1655 writeSeq(0x02, 1 << 0);
1656 dstPtr = dst;
1657 srcPtr = src;
1658 i = width;
1659 j = phase;
1660 while(j--) {
1661 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4);
1662 *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);
1663 srcPtr += 2;
1664 }
1665 while(i >= 4) {
1666 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4);
1667 s1 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);
1668 m = (srcPtr[3] & 0x01010101) | ((srcPtr[2] & 0x01010101) << 4);
1669 s2 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);
1670 m = (srcPtr[5] & 0x01010101) | ((srcPtr[4] & 0x01010101) << 4);
1671 s3 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);
1672 m = (srcPtr[7] & 0x01010101) | ((srcPtr[6] & 0x01010101) << 4);
1673 s4 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);
1674 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);
1675 srcPtr += 8;
1676 dstPtr += 4;
1677 i -= 4;
1678 }
1679 while(i--) {
1680 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4);
1681 *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);
1682 srcPtr += 2;
1683 }
1684
1685 writeSeq(0x02, 1 << 1);
1686 dstPtr = dst;
1687 srcPtr = src;
1688 i = width;
1689 j = phase;
1690 while(j--) {
1691 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4);
1692 *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);
1693 srcPtr += 2;
1694 }
1695 while(i >= 4) {
1696 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4);
1697 s1 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);
1698 m = (srcPtr[3] & 0x02020202) | ((srcPtr[2] & 0x02020202) << 4);
1699 s2 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);
1700 m = (srcPtr[5] & 0x02020202) | ((srcPtr[4] & 0x02020202) << 4);
1701 s3 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);
1702 m = (srcPtr[7] & 0x02020202) | ((srcPtr[6] & 0x02020202) << 4);
1703 s4 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);
1704 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);
1705 srcPtr += 8;
1706 dstPtr += 4;
1707 i -= 4;
1708 }
1709 while(i--) {
1710 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4);
1711 *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);
1712 srcPtr += 2;
1713 }
1714
1715 writeSeq(0x02, 1 << 2);
1716 dstPtr = dst;
1717 srcPtr = src;
1718 i = width;
1719 j = phase;
1720 while(j--) {
1721 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4);
1722 *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);
1723 srcPtr += 2;
1724 }
1725 while(i >= 4) {
1726 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4);
1727 s1 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);
1728 m = (srcPtr[3] & 0x04040404) | ((srcPtr[2] & 0x04040404) << 4);
1729 s2 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);
1730 m = (srcPtr[5] & 0x04040404) | ((srcPtr[4] & 0x04040404) << 4);
1731 s3 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);
1732 m = (srcPtr[7] & 0x04040404) | ((srcPtr[6] & 0x04040404) << 4);
1733 s4 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);
1734 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);
1735 srcPtr += 8;
1736 dstPtr += 4;
1737 i -= 4;
1738 }
1739 while(i--) {
1740 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4);
1741 *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);
1742 srcPtr += 2;
1743 }
1744
1745 writeSeq(0x02, 1 << 3);
1746 dstPtr = dst;
1747 srcPtr = src;
1748 i = width;
1749 j = phase;
1750 while(j--) {
1751 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4);
1752 *dstPtr++ = (m >> 27) | (m >> 18) | (m >> 9) | m;
1753 srcPtr += 2;
1754 }
1755 while(i >= 4) {
1756 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4);
1757 s1 = (m >> 27) | (m >> 18) | (m >> 9) | m;
1758 m = (srcPtr[3] & 0x08080808) | ((srcPtr[2] & 0x08080808) << 4);
1759 s2 = (m >> 27) | (m >> 18) | (m >> 9) | m;
1760 m = (srcPtr[5] & 0x08080808) | ((srcPtr[4] & 0x08080808) << 4);
1761 s3 = (m >> 27) | (m >> 18) | (m >> 9) | m;
1762 m = (srcPtr[7] & 0x08080808) | ((srcPtr[6] & 0x08080808) << 4);
1763 s4 = (m >> 27) | (m >> 18) | (m >> 9) | m;
1764 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);
1765 srcPtr += 8;
1766 dstPtr += 4;
1767 i -= 4;
1768 }
1769 while(i--) {
1770 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4);
1771 *dstPtr++ = (m >> 27) | (m >> 18) | (m >> 9) | m;
1772 srcPtr += 2;
1773 }
1774
1775 dst += FBPitch;
1776 src += SRCPitch;
1777 }
1778 rects++;
1779 }
1780}
1781#endif /* VGA16_FBCON_SUPPORT */
1782
1783void FB_SavePaletteTo(_THIS, int palette_len, __u16 *area)
1784{
1785 struct fb_cmap cmap;
1786
1787 cmap.start = 0;
1788 cmap.len = palette_len;
1789 cmap.red = &area[0*palette_len];
1790 cmap.green = &area[1*palette_len];
1791 cmap.blue = &area[2*palette_len];
1792 cmap.transp = NULL;
1793 ioctl(console_fd, FBIOGETCMAP, &cmap);
1794}
1795
1796void FB_RestorePaletteFrom(_THIS, int palette_len, __u16 *area)
1797{
1798 struct fb_cmap cmap;
1799
1800 cmap.start = 0;
1801 cmap.len = palette_len;
1802 cmap.red = &area[0*palette_len];
1803 cmap.green = &area[1*palette_len];
1804 cmap.blue = &area[2*palette_len];
1805 cmap.transp = NULL;
1806 ioctl(console_fd, FBIOPUTCMAP, &cmap);
1807}
1808
1809static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo,
1810 struct fb_var_screeninfo *vinfo)
1811{
1812 int i;
1813
1814 /* Save hardware palette, if needed */
1815 if ( finfo->visual == FB_VISUAL_PSEUDOCOLOR ) {
1816 saved_cmaplen = 1<<vinfo->bits_per_pixel;
1817 saved_cmap=(__u16 *)SDL_malloc(3*saved_cmaplen*sizeof(*saved_cmap));
1818 if ( saved_cmap != NULL ) {
1819 FB_SavePaletteTo(this, saved_cmaplen, saved_cmap);
1820 }
1821 }
1822
1823 /* Added support for FB_VISUAL_DIRECTCOLOR.
1824 With this mode pixel information is passed through the palette...
1825 Neat fading and gamma correction effects can be had by simply
1826 fooling around with the palette instead of changing the pixel
1827 values themselves... Very neat!
1828
1829 Adam Meyerowitz 1/19/2000
1830 ameyerow@optonline.com
1831 */
1832 if ( finfo->visual == FB_VISUAL_DIRECTCOLOR ) {
1833 __u16 new_entries[3*256];
1834
1835 /* Save the colormap */
1836 saved_cmaplen = 256;
1837 saved_cmap=(__u16 *)SDL_malloc(3*saved_cmaplen*sizeof(*saved_cmap));
1838 if ( saved_cmap != NULL ) {
1839 FB_SavePaletteTo(this, saved_cmaplen, saved_cmap);
1840 }
1841
1842 /* Allocate new identity colormap */
1843 for ( i=0; i<256; ++i ) {
1844 new_entries[(0*256)+i] =
1845 new_entries[(1*256)+i] =
1846 new_entries[(2*256)+i] = (i<<8)|i;
1847 }
1848 FB_RestorePaletteFrom(this, 256, new_entries);
1849 }
1850}
1851
1852static void FB_RestorePalette(_THIS)
1853{
1854 /* Restore the original palette */
1855 if ( saved_cmap ) {
1856 FB_RestorePaletteFrom(this, saved_cmaplen, saved_cmap);
1857 SDL_free(saved_cmap);
1858 saved_cmap = NULL;
1859 }
1860}
1861
1862static int FB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
1863{
1864 int i;
1865 __u16 r[256];
1866 __u16 g[256];
1867 __u16 b[256];
1868 struct fb_cmap cmap;
1869
1870 /* Set up the colormap */
1871 for (i = 0; i < ncolors; i++) {
1872 r[i] = colors[i].r << 8;
1873 g[i] = colors[i].g << 8;
1874 b[i] = colors[i].b << 8;
1875 }
1876 cmap.start = firstcolor;
1877 cmap.len = ncolors;
1878 cmap.red = r;
1879 cmap.green = g;
1880 cmap.blue = b;
1881 cmap.transp = NULL;
1882
1883 if( (ioctl(console_fd, FBIOPUTCMAP, &cmap) < 0) ||
1884 !(this->screen->flags & SDL_HWPALETTE) ) {
1885 colors = this->screen->format->palette->colors;
1886 ncolors = this->screen->format->palette->ncolors;
1887 cmap.start = 0;
1888 cmap.len = ncolors;
1889 SDL_memset(r, 0, sizeof(r));
1890 SDL_memset(g, 0, sizeof(g));
1891 SDL_memset(b, 0, sizeof(b));
1892 if ( ioctl(console_fd, FBIOGETCMAP, &cmap) == 0 ) {
1893 for ( i=ncolors-1; i>=0; --i ) {
1894 colors[i].r = (r[i]>>8);
1895 colors[i].g = (g[i]>>8);
1896 colors[i].b = (b[i]>>8);
1897 }
1898 }
1899 return(0);
1900 }
1901 return(1);
1902}
1903
1904/* Note: If we are terminated, this could be called in the middle of
1905 another SDL video routine -- notably UpdateRects.
1906*/
1907static void FB_VideoQuit(_THIS)
1908{
1909 int i, j;
1910
1911 if ( this->screen ) {
1912 /* Clear screen and tell SDL not to free the pixels */
1913
1914 const char *dontClearPixels = SDL_getenv("SDL_FBCON_DONT_CLEAR");
1915
1916 /* If the framebuffer is not to be cleared, make sure that we won't
1917 * display the previous frame when disabling double buffering. */
1918 if ( dontClearPixels && flip_page == 0 ) {
1919 SDL_memcpy(flip_address[0], flip_address[1], this->screen->pitch * this->screen->h);
1920 }
1921
1922 if ( !dontClearPixels && this->screen->pixels && FB_InGraphicsMode(this) ) {
1923#if defined(__powerpc__) || defined(__ia64__) /* SIGBUS when using SDL_memset() ?? */
1924 Uint8 *rowp = (Uint8 *)this->screen->pixels;
1925 int left = this->screen->pitch*this->screen->h;
1926 while ( left-- ) { *rowp++ = 0; }
1927#else
1928 SDL_memset(this->screen->pixels,0,this->screen->h*this->screen->pitch);
1929#endif
1930 }
1931 /* This test fails when using the VGA16 shadow memory */
1932 if ( ((char *)this->screen->pixels >= mapped_mem) &&
1933 ((char *)this->screen->pixels < (mapped_mem+mapped_memlen)) ) {
1934 this->screen->pixels = NULL;
1935 }
1936 }
1937
1938 /* Clear the lock mutex */
1939 if ( hw_lock ) {
1940 SDL_DestroyMutex(hw_lock);
1941 hw_lock = NULL;
1942 }
1943
1944 /* Clean up defined video modes */
1945 for ( i=0; i<NUM_MODELISTS; ++i ) {
1946 if ( SDL_modelist[i] != NULL ) {
1947 for ( j=0; SDL_modelist[i][j]; ++j ) {
1948 SDL_free(SDL_modelist[i][j]);
1949 }
1950 SDL_free(SDL_modelist[i]);
1951 SDL_modelist[i] = NULL;
1952 }
1953 }
1954
1955 /* Clean up the memory bucket list */
1956 FB_FreeHWSurfaces(this);
1957
1958 /* Close console and input file descriptors */
1959 if ( console_fd > 0 ) {
1960 /* Unmap the video framebuffer and I/O registers */
1961 if ( mapped_mem ) {
1962 munmap(mapped_mem, mapped_memlen);
1963 mapped_mem = NULL;
1964 }
1965 if ( mapped_io ) {
1966 munmap(mapped_io, mapped_iolen);
1967 mapped_io = NULL;
1968 }
1969
1970 /* Restore the original video mode and palette */
1971 if ( FB_InGraphicsMode(this) ) {
1972 FB_RestorePalette(this);
1973 ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo);
1974 }
1975
1976 /* We're all done with the framebuffer */
1977 close(console_fd);
1978 console_fd = -1;
1979 }
1980 FB_CloseMouse(this);
1981 FB_CloseKeyboard(this);
1982}
diff --git a/apps/plugins/sdl/src/video/fbcon/SDL_fbvideo.h b/apps/plugins/sdl/src/video/fbcon/SDL_fbvideo.h
deleted file mode 100644
index 1443d2b251..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/SDL_fbvideo.h
+++ /dev/null
@@ -1,200 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef _SDL_fbvideo_h
25#define _SDL_fbvideo_h
26
27#include <sys/types.h>
28#include <termios.h>
29#include <linux/fb.h>
30
31#include "SDL_mouse.h"
32#include "SDL_mutex.h"
33#include "../SDL_sysvideo.h"
34#if SDL_INPUT_TSLIB
35#include "tslib.h"
36#endif
37
38/* Hidden "this" pointer for the video functions */
39#define _THIS SDL_VideoDevice *this
40
41typedef void FB_bitBlit(
42 Uint8 *src_pos,
43 int src_right_delta, /* pixels, not bytes */
44 int src_down_delta, /* pixels, not bytes */
45 Uint8 *dst_pos,
46 int dst_linebytes,
47 int width,
48 int height);
49
50/* This is the structure we use to keep track of video memory */
51typedef struct vidmem_bucket {
52 struct vidmem_bucket *prev;
53 int used;
54 int dirty;
55 char *base;
56 unsigned int size;
57 struct vidmem_bucket *next;
58} vidmem_bucket;
59
60/* Private display data */
61struct SDL_PrivateVideoData {
62 int console_fd;
63 struct fb_var_screeninfo cache_vinfo;
64 struct fb_var_screeninfo saved_vinfo;
65 int saved_cmaplen;
66 __u16 *saved_cmap;
67
68 int current_vt;
69 int saved_vt;
70 int keyboard_fd;
71 int saved_kbd_mode;
72 struct termios saved_kbd_termios;
73
74 int mouse_fd;
75#if SDL_INPUT_TSLIB
76 struct tsdev *ts_dev;
77#endif
78
79 char *mapped_mem;
80 char *shadow_mem;
81 int mapped_memlen;
82 int mapped_offset;
83 char *mapped_io;
84 long mapped_iolen;
85 int flip_page;
86 char *flip_address[2];
87 int rotate;
88 int shadow_fb; /* Tells whether a shadow is being used. */
89 FB_bitBlit *blitFunc;
90 int physlinebytes; /* Length of a line in bytes in physical fb */
91
92#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
93 int SDL_nummodes[NUM_MODELISTS];
94 SDL_Rect **SDL_modelist[NUM_MODELISTS];
95
96 vidmem_bucket surfaces;
97 int surfaces_memtotal;
98 int surfaces_memleft;
99
100 SDL_mutex *hw_lock;
101 int switched_away;
102 struct fb_var_screeninfo screen_vinfo;
103 Uint32 screen_arealen;
104 Uint8 *screen_contents;
105 __u16 screen_palette[3*256];
106
107 void (*wait_vbl)(_THIS);
108 void (*wait_idle)(_THIS);
109};
110/* Old variable names */
111#define console_fd (this->hidden->console_fd)
112#define current_vt (this->hidden->current_vt)
113#define saved_vt (this->hidden->saved_vt)
114#define keyboard_fd (this->hidden->keyboard_fd)
115#define saved_kbd_mode (this->hidden->saved_kbd_mode)
116#define saved_kbd_termios (this->hidden->saved_kbd_termios)
117#define mouse_fd (this->hidden->mouse_fd)
118#if SDL_INPUT_TSLIB
119#define ts_dev (this->hidden->ts_dev)
120#endif
121#define cache_vinfo (this->hidden->cache_vinfo)
122#define saved_vinfo (this->hidden->saved_vinfo)
123#define saved_cmaplen (this->hidden->saved_cmaplen)
124#define saved_cmap (this->hidden->saved_cmap)
125#define mapped_mem (this->hidden->mapped_mem)
126#define shadow_mem (this->hidden->shadow_mem)
127#define mapped_memlen (this->hidden->mapped_memlen)
128#define mapped_offset (this->hidden->mapped_offset)
129#define mapped_io (this->hidden->mapped_io)
130#define mapped_iolen (this->hidden->mapped_iolen)
131#define flip_page (this->hidden->flip_page)
132#define flip_address (this->hidden->flip_address)
133#define rotate (this->hidden->rotate)
134#define shadow_fb (this->hidden->shadow_fb)
135#define blitFunc (this->hidden->blitFunc)
136#define physlinebytes (this->hidden->physlinebytes)
137#define SDL_nummodes (this->hidden->SDL_nummodes)
138#define SDL_modelist (this->hidden->SDL_modelist)
139#define surfaces (this->hidden->surfaces)
140#define surfaces_memtotal (this->hidden->surfaces_memtotal)
141#define surfaces_memleft (this->hidden->surfaces_memleft)
142#define hw_lock (this->hidden->hw_lock)
143#define switched_away (this->hidden->switched_away)
144#define screen_vinfo (this->hidden->screen_vinfo)
145#define screen_arealen (this->hidden->screen_arealen)
146#define screen_contents (this->hidden->screen_contents)
147#define screen_palette (this->hidden->screen_palette)
148#define wait_vbl (this->hidden->wait_vbl)
149#define wait_idle (this->hidden->wait_idle)
150
151/* Accelerator types that are supported by the driver, but are not
152 necessarily in the kernel headers on the system we compile on.
153*/
154#ifndef FB_ACCEL_MATROX_MGAG400
155#define FB_ACCEL_MATROX_MGAG400 26 /* Matrox G400 */
156#endif
157#ifndef FB_ACCEL_3DFX_BANSHEE
158#define FB_ACCEL_3DFX_BANSHEE 31 /* 3Dfx Banshee */
159#endif
160
161/* These functions are defined in SDL_fbvideo.c */
162extern void FB_SavePaletteTo(_THIS, int palette_len, __u16 *area);
163extern void FB_RestorePaletteFrom(_THIS, int palette_len, __u16 *area);
164
165/* These are utility functions for working with video surfaces */
166
167static __inline__ void FB_AddBusySurface(SDL_Surface *surface)
168{
169 ((vidmem_bucket *)surface->hwdata)->dirty = 1;
170}
171
172static __inline__ int FB_IsSurfaceBusy(SDL_Surface *surface)
173{
174 return ((vidmem_bucket *)surface->hwdata)->dirty;
175}
176
177static __inline__ void FB_WaitBusySurfaces(_THIS)
178{
179 vidmem_bucket *bucket;
180
181 /* Wait for graphic operations to complete */
182 wait_idle(this);
183
184 /* Clear all surface dirty bits */
185 for ( bucket=&surfaces; bucket; bucket=bucket->next ) {
186 bucket->dirty = 0;
187 }
188}
189
190static __inline__ void FB_dst_to_xy(_THIS, SDL_Surface *dst, int *x, int *y)
191{
192 *x = (long)((char *)dst->pixels - mapped_mem)%this->screen->pitch;
193 *y = (long)((char *)dst->pixels - mapped_mem)/this->screen->pitch;
194 if ( dst == this->screen ) {
195 *x += this->offset_x;
196 *y += this->offset_y;
197 }
198}
199
200#endif /* _SDL_fbvideo_h */
diff --git a/apps/plugins/sdl/src/video/fbcon/matrox_mmio.h b/apps/plugins/sdl/src/video/fbcon/matrox_mmio.h
deleted file mode 100644
index a1cf203ea5..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/matrox_mmio.h
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* MGA register definitions */
25
26#include "matrox_regs.h"
27
28/* MGA control macros */
29
30#define mga_in8(reg) *(volatile Uint8 *)(mapped_io + (reg))
31#define mga_in32(reg) *(volatile Uint32 *)(mapped_io + (reg))
32
33#define mga_out8(reg,v) *(volatile Uint8 *)(mapped_io + (reg)) = v;
34#define mga_out32(reg,v) *(volatile Uint32 *)(mapped_io + (reg)) = v;
35
36
37/* Wait for fifo space */
38#define mga_wait(space) \
39{ \
40 while ( mga_in8(MGAREG_FIFOSTATUS) < space ) \
41 ; \
42}
43
44
45/* Wait for idle accelerator */
46#define mga_waitidle() \
47{ \
48 while ( mga_in32(MGAREG_STATUS) & 0x10000 ) \
49 ; \
50}
51
diff --git a/apps/plugins/sdl/src/video/fbcon/matrox_regs.h b/apps/plugins/sdl/src/video/fbcon/matrox_regs.h
deleted file mode 100644
index d570b0c9b0..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/matrox_regs.h
+++ /dev/null
@@ -1,376 +0,0 @@
1
2/*
3 * MGA Millennium (MGA2064W) functions
4 * MGA Mystique (MGA1064SG) functions
5 *
6 * Copyright 1996 The XFree86 Project, Inc.
7 *
8 * Authors
9 * Dirk Hohndel
10 * hohndel@XFree86.Org
11 * David Dawes
12 * dawes@XFree86.Org
13 * Contributors:
14 * Guy DESBIEF, Aix-en-provence, France
15 * g.desbief@aix.pacwan.net
16 * MGA1064SG Mystique register file
17 */
18
19
20#ifndef _MGA_REG_H_
21#define _MGA_REG_H_
22
23#define MGAREG_DWGCTL 0x1c00
24#define MGAREG_MACCESS 0x1c04
25/* the following is a mystique only register */
26#define MGAREG_MCTLWTST 0x1c08
27#define MGAREG_ZORG 0x1c0c
28
29#define MGAREG_PAT0 0x1c10
30#define MGAREG_PAT1 0x1c14
31#define MGAREG_PLNWT 0x1c1c
32
33#define MGAREG_BCOL 0x1c20
34#define MGAREG_FCOL 0x1c24
35
36#define MGAREG_SRC0 0x1c30
37#define MGAREG_SRC1 0x1c34
38#define MGAREG_SRC2 0x1c38
39#define MGAREG_SRC3 0x1c3c
40
41#define MGAREG_XYSTRT 0x1c40
42#define MGAREG_XYEND 0x1c44
43
44#define MGAREG_SHIFT 0x1c50
45/* the following is a mystique only register */
46#define MGAREG_DMAPAD 0x1c54
47#define MGAREG_SGN 0x1c58
48#define MGAREG_LEN 0x1c5c
49
50#define MGAREG_AR0 0x1c60
51#define MGAREG_AR1 0x1c64
52#define MGAREG_AR2 0x1c68
53#define MGAREG_AR3 0x1c6c
54#define MGAREG_AR4 0x1c70
55#define MGAREG_AR5 0x1c74
56#define MGAREG_AR6 0x1c78
57
58#define MGAREG_CXBNDRY 0x1c80
59#define MGAREG_FXBNDRY 0x1c84
60#define MGAREG_YDSTLEN 0x1c88
61#define MGAREG_PITCH 0x1c8c
62
63#define MGAREG_YDST 0x1c90
64#define MGAREG_YDSTORG 0x1c94
65#define MGAREG_YTOP 0x1c98
66#define MGAREG_YBOT 0x1c9c
67
68#define MGAREG_CXLEFT 0x1ca0
69#define MGAREG_CXRIGHT 0x1ca4
70#define MGAREG_FXLEFT 0x1ca8
71#define MGAREG_FXRIGHT 0x1cac
72
73#define MGAREG_XDST 0x1cb0
74
75#define MGAREG_DR0 0x1cc0
76#define MGAREG_DR1 0x1cc4
77#define MGAREG_DR2 0x1cc8
78#define MGAREG_DR3 0x1ccc
79
80#define MGAREG_DR4 0x1cd0
81#define MGAREG_DR5 0x1cd4
82#define MGAREG_DR6 0x1cd8
83#define MGAREG_DR7 0x1cdc
84
85#define MGAREG_DR8 0x1ce0
86#define MGAREG_DR9 0x1ce4
87#define MGAREG_DR10 0x1ce8
88#define MGAREG_DR11 0x1cec
89
90#define MGAREG_DR12 0x1cf0
91#define MGAREG_DR13 0x1cf4
92#define MGAREG_DR14 0x1cf8
93#define MGAREG_DR15 0x1cfc
94
95#define MGAREG_SRCORG 0x2cb4
96#define MGAREG_DSTORG 0x2cb8
97
98/* add or or this to one of the previous "power registers" to start
99 the drawing engine */
100
101#define MGAREG_EXEC 0x0100
102
103#define MGAREG_FIFOSTATUS 0x1e10
104#define MGAREG_STATUS 0x1e14
105#define MGAREG_ICLEAR 0x1e18
106#define MGAREG_IEN 0x1e1c
107
108#define MGAREG_VCOUNT 0x1e20
109
110#define MGAREG_Reset 0x1e40
111
112#define MGAREG_OPMODE 0x1e54
113
114/* OPMODE register additives */
115
116#define MGAOPM_DMA_GENERAL (0x00 << 2)
117#define MGAOPM_DMA_BLIT (0x01 << 2)
118#define MGAOPM_DMA_VECTOR (0x10 << 2)
119
120/* DWGCTL register additives */
121
122/* Lines */
123
124#define MGADWG_LINE_OPEN 0x00
125#define MGADWG_AUTOLINE_OPEN 0x01
126#define MGADWG_LINE_CLOSE 0x02
127#define MGADWG_AUTOLINE_CLOSE 0x03
128
129/* Trapezoids */
130#define MGADWG_TRAP 0x04
131#define MGADWG_TEXTURE_TRAP 0x05
132
133/* BitBlts */
134
135#define MGADWG_BITBLT 0x08
136#define MGADWG_FBITBLT 0x0c
137#define MGADWG_ILOAD 0x09
138#define MGADWG_ILOAD_SCALE 0x0d
139#define MGADWG_ILOAD_FILTER 0x0f
140#define MGADWG_IDUMP 0x0a
141
142/* atype access to WRAM */
143
144#define MGADWG_RPL ( 0x00 << 4 )
145#define MGADWG_RSTR ( 0x01 << 4 )
146#define MGADWG_ZI ( 0x03 << 4 )
147#define MGADWG_BLK ( 0x04 << 4 )
148#define MGADWG_I ( 0x07 << 4 )
149
150/* specifies whether bit blits are linear or xy */
151#define MGADWG_LINEAR ( 0x01 << 7 )
152
153/* z drawing mode. use MGADWG_NOZCMP for always */
154
155#define MGADWG_NOZCMP ( 0x00 << 8 )
156#define MGADWG_ZE ( 0x02 << 8 )
157#define MGADWG_ZNE ( 0x03 << 8 )
158#define MGADWG_ZLT ( 0x04 << 8 )
159#define MGADWG_ZLTE ( 0x05 << 8 )
160#define MGADWG_GT ( 0x06 << 8 )
161#define MGADWG_GTE ( 0x07 << 8 )
162
163/* use this to force colour expansion circuitry to do its stuff */
164
165#define MGADWG_SOLID ( 0x01 << 11 )
166
167/* ar register at zero */
168
169#define MGADWG_ARZERO ( 0x01 << 12 )
170
171#define MGADWG_SGNZERO ( 0x01 << 13 )
172
173#define MGADWG_SHIFTZERO ( 0x01 << 14 )
174
175/* See table on 4-43 for bop ALU operations */
176
177/* See table on 4-44 for translucidity masks */
178
179#define MGADWG_BMONOLEF ( 0x00 << 25 )
180#define MGADWG_BMONOWF ( 0x04 << 25 )
181#define MGADWG_BPLAN ( 0x01 << 25 )
182
183/* note that if bfcol is specified and you're doing a bitblt, it causes
184 a fbitblt to be performed, so check that you obey the fbitblt rules */
185
186#define MGADWG_BFCOL ( 0x02 << 25 )
187#define MGADWG_BUYUV ( 0x0e << 25 )
188#define MGADWG_BU32BGR ( 0x03 << 25 )
189#define MGADWG_BU32RGB ( 0x07 << 25 )
190#define MGADWG_BU24BGR ( 0x0b << 25 )
191#define MGADWG_BU24RGB ( 0x0f << 25 )
192
193#define MGADWG_REPLACE 0x000C0000 /* From Linux kernel sources */
194#define MGADWG_PATTERN ( 0x01 << 29 )
195#define MGADWG_TRANSC ( 0x01 << 30 )
196#define MGADWG_NOCLIP ( 0x01 << 31 )
197#define MGAREG_MISC_WRITE 0x3c2
198#define MGAREG_MISC_READ 0x3cc
199#define MGAREG_MISC_IOADSEL (0x1 << 0)
200#define MGAREG_MISC_RAMMAPEN (0x1 << 1)
201#define MGAREG_MISC_CLK_SEL_VGA25 (0x0 << 2)
202#define MGAREG_MISC_CLK_SEL_VGA28 (0x1 << 2)
203#define MGAREG_MISC_CLK_SEL_MGA_PIX (0x2 << 2)
204#define MGAREG_MISC_CLK_SEL_MGA_MSK (0x3 << 2)
205#define MGAREG_MISC_VIDEO_DIS (0x1 << 4)
206#define MGAREG_MISC_HIGH_PG_SEL (0x1 << 5)
207
208/* MMIO VGA registers */
209#define MGAREG_CRTC_INDEX 0x1fd4
210#define MGAREG_CRTC_DATA 0x1fd5
211#define MGAREG_CRTCEXT_INDEX 0x1fde
212#define MGAREG_CRTCEXT_DATA 0x1fdf
213
214
215/* MGA bits for registers PCI_OPTION_REG */
216#define MGA1064_OPT_SYS_CLK_PCI ( 0x00 << 0 )
217#define MGA1064_OPT_SYS_CLK_PLL ( 0x01 << 0 )
218#define MGA1064_OPT_SYS_CLK_EXT ( 0x02 << 0 )
219#define MGA1064_OPT_SYS_CLK_MSK ( 0x03 << 0 )
220
221#define MGA1064_OPT_SYS_CLK_DIS ( 0x01 << 2 )
222#define MGA1064_OPT_G_CLK_DIV_1 ( 0x01 << 3 )
223#define MGA1064_OPT_M_CLK_DIV_1 ( 0x01 << 4 )
224
225#define MGA1064_OPT_SYS_PLL_PDN ( 0x01 << 5 )
226#define MGA1064_OPT_VGA_ION ( 0x01 << 8 )
227
228/* MGA registers in PCI config space */
229#define PCI_MGA_INDEX 0x44
230#define PCI_MGA_DATA 0x48
231#define PCI_MGA_OPTION2 0x50
232#define PCI_MGA_OPTION3 0x54
233
234#define RAMDAC_OFFSET 0x3c00
235
236/* TVP3026 direct registers */
237
238#define TVP3026_INDEX 0x00
239#define TVP3026_WADR_PAL 0x00
240#define TVP3026_COL_PAL 0x01
241#define TVP3026_PIX_RD_MSK 0x02
242#define TVP3026_RADR_PAL 0x03
243#define TVP3026_CUR_COL_ADDR 0x04
244#define TVP3026_CUR_COL_DATA 0x05
245#define TVP3026_DATA 0x0a
246#define TVP3026_CUR_RAM 0x0b
247#define TVP3026_CUR_XLOW 0x0c
248#define TVP3026_CUR_XHI 0x0d
249#define TVP3026_CUR_YLOW 0x0e
250#define TVP3026_CUR_YHI 0x0f
251
252/* TVP3026 indirect registers */
253
254#define TVP3026_SILICON_REV 0x01
255#define TVP3026_CURSOR_CTL 0x06
256#define TVP3026_LATCH_CTL 0x0f
257#define TVP3026_TRUE_COLOR_CTL 0x18
258#define TVP3026_MUX_CTL 0x19
259#define TVP3026_CLK_SEL 0x1a
260#define TVP3026_PAL_PAGE 0x1c
261#define TVP3026_GEN_CTL 0x1d
262#define TVP3026_MISC_CTL 0x1e
263#define TVP3026_GEN_IO_CTL 0x2a
264#define TVP3026_GEN_IO_DATA 0x2b
265#define TVP3026_PLL_ADDR 0x2c
266#define TVP3026_PIX_CLK_DATA 0x2d
267#define TVP3026_MEM_CLK_DATA 0x2e
268#define TVP3026_LOAD_CLK_DATA 0x2f
269#define TVP3026_KEY_RED_LOW 0x32
270#define TVP3026_KEY_RED_HI 0x33
271#define TVP3026_KEY_GREEN_LOW 0x34
272#define TVP3026_KEY_GREEN_HI 0x35
273#define TVP3026_KEY_BLUE_LOW 0x36
274#define TVP3026_KEY_BLUE_HI 0x37
275#define TVP3026_KEY_CTL 0x38
276#define TVP3026_MCLK_CTL 0x39
277#define TVP3026_SENSE_TEST 0x3a
278#define TVP3026_TEST_DATA 0x3b
279#define TVP3026_CRC_LSB 0x3c
280#define TVP3026_CRC_MSB 0x3d
281#define TVP3026_CRC_CTL 0x3e
282#define TVP3026_ID 0x3f
283#define TVP3026_RESET 0xff
284
285
286/* MGA1064 DAC Register file */
287/* MGA1064 direct registers */
288
289#define MGA1064_INDEX 0x00
290#define MGA1064_WADR_PAL 0x00
291#define MGA1064_COL_PAL 0x01
292#define MGA1064_PIX_RD_MSK 0x02
293#define MGA1064_RADR_PAL 0x03
294#define MGA1064_DATA 0x0a
295
296#define MGA1064_CUR_XLOW 0x0c
297#define MGA1064_CUR_XHI 0x0d
298#define MGA1064_CUR_YLOW 0x0e
299#define MGA1064_CUR_YHI 0x0f
300
301/* MGA1064 indirect registers */
302#define MGA1064_CURSOR_BASE_ADR_LOW 0x04
303#define MGA1064_CURSOR_BASE_ADR_HI 0x05
304#define MGA1064_CURSOR_CTL 0x06
305#define MGA1064_CURSOR_COL0_RED 0x08
306#define MGA1064_CURSOR_COL0_GREEN 0x09
307#define MGA1064_CURSOR_COL0_BLUE 0x0a
308
309#define MGA1064_CURSOR_COL1_RED 0x0c
310#define MGA1064_CURSOR_COL1_GREEN 0x0d
311#define MGA1064_CURSOR_COL1_BLUE 0x0e
312
313#define MGA1064_CURSOR_COL2_RED 0x010
314#define MGA1064_CURSOR_COL2_GREEN 0x011
315#define MGA1064_CURSOR_COL2_BLUE 0x012
316
317#define MGA1064_VREF_CTL 0x018
318
319#define MGA1064_MUL_CTL 0x19
320#define MGA1064_MUL_CTL_8bits 0x0
321#define MGA1064_MUL_CTL_15bits 0x01
322#define MGA1064_MUL_CTL_16bits 0x02
323#define MGA1064_MUL_CTL_24bits 0x03
324#define MGA1064_MUL_CTL_32bits 0x04
325#define MGA1064_MUL_CTL_2G8V16bits 0x05
326#define MGA1064_MUL_CTL_G16V16bits 0x06
327#define MGA1064_MUL_CTL_32_24bits 0x07
328
329#define MGAGDAC_XVREFCTRL 0x18
330#define MGA1064_PIX_CLK_CTL 0x1a
331#define MGA1064_PIX_CLK_CTL_CLK_DIS ( 0x01 << 2 )
332#define MGA1064_PIX_CLK_CTL_CLK_POW_DOWN ( 0x01 << 3 )
333#define MGA1064_PIX_CLK_CTL_SEL_PCI ( 0x00 << 0 )
334#define MGA1064_PIX_CLK_CTL_SEL_PLL ( 0x01 << 0 )
335#define MGA1064_PIX_CLK_CTL_SEL_EXT ( 0x02 << 0 )
336#define MGA1064_PIX_CLK_CTL_SEL_MSK ( 0x03 << 0 )
337
338#define MGA1064_GEN_CTL 0x1d
339#define MGA1064_MISC_CTL 0x1e
340#define MGA1064_MISC_CTL_DAC_POW_DN ( 0x01 << 0 )
341#define MGA1064_MISC_CTL_VGA ( 0x01 << 1 )
342#define MGA1064_MISC_CTL_DIS_CON ( 0x03 << 1 )
343#define MGA1064_MISC_CTL_MAFC ( 0x02 << 1 )
344#define MGA1064_MISC_CTL_VGA8 ( 0x01 << 3 )
345#define MGA1064_MISC_CTL_DAC_RAM_CS ( 0x01 << 4 )
346
347#define MGA1064_GEN_IO_CTL 0x2a
348#define MGA1064_GEN_IO_DATA 0x2b
349#define MGA1064_SYS_PLL_M 0x2c
350#define MGA1064_SYS_PLL_N 0x2d
351#define MGA1064_SYS_PLL_P 0x2e
352#define MGA1064_SYS_PLL_STAT 0x2f
353#define MGA1064_ZOOM_CTL 0x38
354#define MGA1064_SENSE_TST 0x3a
355
356#define MGA1064_CRC_LSB 0x3c
357#define MGA1064_CRC_MSB 0x3d
358#define MGA1064_CRC_CTL 0x3e
359#define MGA1064_COL_KEY_MSK_LSB 0x40
360#define MGA1064_COL_KEY_MSK_MSB 0x41
361#define MGA1064_COL_KEY_LSB 0x42
362#define MGA1064_COL_KEY_MSB 0x43
363#define MGA1064_PIX_PLLA_M 0x44
364#define MGA1064_PIX_PLLA_N 0x45
365#define MGA1064_PIX_PLLA_P 0x46
366#define MGA1064_PIX_PLLB_M 0x48
367#define MGA1064_PIX_PLLB_N 0x49
368#define MGA1064_PIX_PLLB_P 0x4a
369#define MGA1064_PIX_PLLC_M 0x4c
370#define MGA1064_PIX_PLLC_N 0x4d
371#define MGA1064_PIX_PLLC_P 0x4e
372
373#define MGA1064_PIX_PLL_STAT 0x4f
374
375#endif
376
diff --git a/apps/plugins/sdl/src/video/fbcon/riva_mmio.h b/apps/plugins/sdl/src/video/fbcon/riva_mmio.h
deleted file mode 100644
index e9261677b1..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/riva_mmio.h
+++ /dev/null
@@ -1,449 +0,0 @@
1/***************************************************************************\
2|* *|
3|* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
4|* *|
5|* NOTICE TO USER: The source code is copyrighted under U.S. and *|
6|* international laws. Users and possessors of this source code are *|
7|* hereby granted a nonexclusive, royalty-free copyright license to *|
8|* use this code in individual and commercial software. *|
9|* *|
10|* Any use of this source code must include, in the user documenta- *|
11|* tion and internal comments to the code, notices to the end user *|
12|* as follows: *|
13|* *|
14|* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
15|* *|
16|* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
17|* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
18|* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
19|* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
20|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
21|* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
22|* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
23|* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
24|* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
25|* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
26|* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
27|* *|
28|* U.S. Government End Users. This source code is a "commercial *|
29|* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
30|* consisting of "commercial computer software" and "commercial *|
31|* computer software documentation," as such terms are used in *|
32|* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
33|* ment only as a commercial end item. Consistent with 48 C.F.R. *|
34|* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
35|* all U.S. Government End Users acquire the source code with only *|
36|* those rights set forth herein. *|
37|* *|
38\***************************************************************************/
39
40#ifndef __RIVA_HW_H__
41#define __RIVA_HW_H__
42#define RIVA_SW_VERSION 0x00010003
43
44/*
45 * Typedefs to force certain sized values.
46 */
47typedef Uint8 U008;
48typedef Uint16 U016;
49typedef Uint32 U032;
50
51/*
52 * HW access macros.
53 */
54#define NV_WR08(p,i,d) (((U008 *)(p))[i]=(d))
55#define NV_RD08(p,i) (((U008 *)(p))[i])
56#define NV_WR16(p,i,d) (((U016 *)(p))[(i)/2]=(d))
57#define NV_RD16(p,i) (((U016 *)(p))[(i)/2])
58#define NV_WR32(p,i,d) (((U032 *)(p))[(i)/4]=(d))
59#define NV_RD32(p,i) (((U032 *)(p))[(i)/4])
60#define VGA_WR08(p,i,d) NV_WR08(p,i,d)
61#define VGA_RD08(p,i) NV_RD08(p,i)
62
63/*
64 * Define supported architectures.
65 */
66#define NV_ARCH_03 0x03
67#define NV_ARCH_04 0x04
68#define NV_ARCH_10 0x10
69/***************************************************************************\
70* *
71* FIFO registers. *
72* *
73\***************************************************************************/
74
75/*
76 * Raster OPeration. Windows style ROP3.
77 */
78typedef volatile struct
79{
80 U032 reserved00[4];
81 U016 FifoFree;
82 U016 Nop;
83 U032 reserved01[0x0BB];
84 U032 Rop3;
85} RivaRop;
86/*
87 * 8X8 Monochrome pattern.
88 */
89typedef volatile struct
90{
91 U032 reserved00[4];
92 U016 FifoFree;
93 U016 Nop;
94 U032 reserved01[0x0BD];
95 U032 Shape;
96 U032 reserved03[0x001];
97 U032 Color0;
98 U032 Color1;
99 U032 Monochrome[2];
100} RivaPattern;
101/*
102 * Scissor clip rectangle.
103 */
104typedef volatile struct
105{
106 U032 reserved00[4];
107 U016 FifoFree;
108 U016 Nop;
109 U032 reserved01[0x0BB];
110 U032 TopLeft;
111 U032 WidthHeight;
112} RivaClip;
113/*
114 * 2D filled rectangle.
115 */
116typedef volatile struct
117{
118 U032 reserved00[4];
119 U016 FifoFree;
120 U016 Nop[1];
121 U032 reserved01[0x0BC];
122 U032 Color;
123 U032 reserved03[0x03E];
124 U032 TopLeft;
125 U032 WidthHeight;
126} RivaRectangle;
127/*
128 * 2D screen-screen BLT.
129 */
130typedef volatile struct
131{
132 U032 reserved00[4];
133 U016 FifoFree;
134 U016 Nop;
135 U032 reserved01[0x0BB];
136 U032 TopLeftSrc;
137 U032 TopLeftDst;
138 U032 WidthHeight;
139} RivaScreenBlt;
140/*
141 * 2D pixel BLT.
142 */
143typedef volatile struct
144{
145 U032 reserved00[4];
146 U016 FifoFree;
147 U016 Nop[1];
148 U032 reserved01[0x0BC];
149 U032 TopLeft;
150 U032 WidthHeight;
151 U032 WidthHeightIn;
152 U032 reserved02[0x03C];
153 U032 Pixels;
154} RivaPixmap;
155/*
156 * Filled rectangle combined with monochrome expand. Useful for glyphs.
157 */
158typedef volatile struct
159{
160 U032 reserved00[4];
161 U016 FifoFree;
162 U016 Nop;
163 U032 reserved01[0x0BB];
164 U032 reserved03[(0x040)-1];
165 U032 Color1A;
166 struct
167 {
168 U032 TopLeft;
169 U032 WidthHeight;
170 } UnclippedRectangle[64];
171 U032 reserved04[(0x080)-3];
172 struct
173 {
174 U032 TopLeft;
175 U032 BottomRight;
176 } ClipB;
177 U032 Color1B;
178 struct
179 {
180 U032 TopLeft;
181 U032 BottomRight;
182 } ClippedRectangle[64];
183 U032 reserved05[(0x080)-5];
184 struct
185 {
186 U032 TopLeft;
187 U032 BottomRight;
188 } ClipC;
189 U032 Color1C;
190 U032 WidthHeightC;
191 U032 PointC;
192 U032 MonochromeData1C;
193 U032 reserved06[(0x080)+121];
194 struct
195 {
196 U032 TopLeft;
197 U032 BottomRight;
198 } ClipD;
199 U032 Color1D;
200 U032 WidthHeightInD;
201 U032 WidthHeightOutD;
202 U032 PointD;
203 U032 MonochromeData1D;
204 U032 reserved07[(0x080)+120];
205 struct
206 {
207 U032 TopLeft;
208 U032 BottomRight;
209 } ClipE;
210 U032 Color0E;
211 U032 Color1E;
212 U032 WidthHeightInE;
213 U032 WidthHeightOutE;
214 U032 PointE;
215 U032 MonochromeData01E;
216} RivaBitmap;
217/*
218 * 3D textured, Z buffered triangle.
219 */
220typedef volatile struct
221{
222 U032 reserved00[4];
223 U016 FifoFree;
224 U016 Nop;
225 U032 reserved01[0x0BC];
226 U032 TextureOffset;
227 U032 TextureFormat;
228 U032 TextureFilter;
229 U032 FogColor;
230/* This is a problem on LynxOS */
231#ifdef Control
232#undef Control
233#endif
234 U032 Control;
235 U032 AlphaTest;
236 U032 reserved02[0x339];
237 U032 FogAndIndex;
238 U032 Color;
239 float ScreenX;
240 float ScreenY;
241 float ScreenZ;
242 float EyeM;
243 float TextureS;
244 float TextureT;
245} RivaTexturedTriangle03;
246typedef volatile struct
247{
248 U032 reserved00[4];
249 U016 FifoFree;
250 U016 Nop;
251 U032 reserved01[0x0BB];
252 U032 ColorKey;
253 U032 TextureOffset;
254 U032 TextureFormat;
255 U032 TextureFilter;
256 U032 Blend;
257/* This is a problem on LynxOS */
258#ifdef Control
259#undef Control
260#endif
261 U032 Control;
262 U032 FogColor;
263 U032 reserved02[0x39];
264 struct
265 {
266 float ScreenX;
267 float ScreenY;
268 float ScreenZ;
269 float EyeM;
270 U032 Color;
271 U032 Specular;
272 float TextureS;
273 float TextureT;
274 } Vertex[16];
275 U032 DrawTriangle3D;
276} RivaTexturedTriangle05;
277/*
278 * 2D line.
279 */
280typedef volatile struct
281{
282 U032 reserved00[4];
283 U016 FifoFree;
284 U016 Nop[1];
285 U032 reserved01[0x0BC];
286 U032 Color; /* source color 0304-0307*/
287 U032 Reserved02[0x03e];
288 struct { /* start aliased methods in array 0400- */
289 U032 point0; /* y_x S16_S16 in pixels 0- 3*/
290 U032 point1; /* y_x S16_S16 in pixels 4- 7*/
291 } Lin[16]; /* end of aliased methods in array -047f*/
292 struct { /* start aliased methods in array 0480- */
293 U032 point0X; /* in pixels, 0 at left 0- 3*/
294 U032 point0Y; /* in pixels, 0 at top 4- 7*/
295 U032 point1X; /* in pixels, 0 at left 8- b*/
296 U032 point1Y; /* in pixels, 0 at top c- f*/
297 } Lin32[8]; /* end of aliased methods in array -04ff*/
298 U032 PolyLin[32]; /* y_x S16_S16 in pixels 0500-057f*/
299 struct { /* start aliased methods in array 0580- */
300 U032 x; /* in pixels, 0 at left 0- 3*/
301 U032 y; /* in pixels, 0 at top 4- 7*/
302 } PolyLin32[16]; /* end of aliased methods in array -05ff*/
303 struct { /* start aliased methods in array 0600- */
304 U032 color; /* source color 0- 3*/
305 U032 point; /* y_x S16_S16 in pixels 4- 7*/
306 } ColorPolyLin[16]; /* end of aliased methods in array -067f*/
307} RivaLine;
308/*
309 * 2D/3D surfaces
310 */
311typedef volatile struct
312{
313 U032 reserved00[4];
314 U016 FifoFree;
315 U016 Nop;
316 U032 reserved01[0x0BE];
317 U032 Offset;
318} RivaSurface;
319typedef volatile struct
320{
321 U032 reserved00[4];
322 U016 FifoFree;
323 U016 Nop;
324 U032 reserved01[0x0BD];
325 U032 Pitch;
326 U032 RenderBufferOffset;
327 U032 ZBufferOffset;
328} RivaSurface3D;
329
330/***************************************************************************\
331* *
332* Virtualized RIVA H/W interface. *
333* *
334\***************************************************************************/
335
336struct _riva_hw_inst;
337struct _riva_hw_state;
338/*
339 * Virtialized chip interface. Makes RIVA 128 and TNT look alike.
340 */
341typedef struct _riva_hw_inst
342{
343 /*
344 * Chip specific settings.
345 */
346 U032 Architecture;
347 U032 Version;
348 U032 CrystalFreqKHz;
349 U032 RamAmountKBytes;
350 U032 MaxVClockFreqKHz;
351 U032 RamBandwidthKBytesPerSec;
352 U032 EnableIRQ;
353 U032 IO;
354 U032 VBlankBit;
355 U032 FifoFreeCount;
356 U032 FifoEmptyCount;
357 /*
358 * Non-FIFO registers.
359 */
360 volatile U032 *PCRTC;
361 volatile U032 *PRAMDAC;
362 volatile U032 *PFB;
363 volatile U032 *PFIFO;
364 volatile U032 *PGRAPH;
365 volatile U032 *PEXTDEV;
366 volatile U032 *PTIMER;
367 volatile U032 *PMC;
368 volatile U032 *PRAMIN;
369 volatile U032 *FIFO;
370 volatile U032 *CURSOR;
371 volatile U032 *CURSORPOS;
372 volatile U032 *VBLANKENABLE;
373 volatile U032 *VBLANK;
374 volatile U008 *PCIO;
375 volatile U008 *PVIO;
376 volatile U008 *PDIO;
377 /*
378 * Common chip functions.
379 */
380 int (*Busy)(struct _riva_hw_inst *);
381 void (*CalcStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *,int,int,int,int,int,int,int,int,int,int,int,int,int);
382 void (*LoadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *);
383 void (*UnloadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *);
384 void (*SetStartAddress)(struct _riva_hw_inst *,U032);
385 void (*SetSurfaces2D)(struct _riva_hw_inst *,U032,U032);
386 void (*SetSurfaces3D)(struct _riva_hw_inst *,U032,U032);
387 int (*ShowHideCursor)(struct _riva_hw_inst *,int);
388 void (*LockUnlock)(struct _riva_hw_inst *, int);
389 /*
390 * Current extended mode settings.
391 */
392 struct _riva_hw_state *CurrentState;
393 /*
394 * FIFO registers.
395 */
396 RivaRop *Rop;
397 RivaPattern *Patt;
398 RivaClip *Clip;
399 RivaPixmap *Pixmap;
400 RivaScreenBlt *Blt;
401 RivaBitmap *Bitmap;
402 RivaLine *Line;
403 RivaTexturedTriangle03 *Tri03;
404 RivaTexturedTriangle05 *Tri05;
405} RIVA_HW_INST;
406/*
407 * Extended mode state information.
408 */
409typedef struct _riva_hw_state
410{
411 U032 bpp;
412 U032 width;
413 U032 height;
414 U032 repaint0;
415 U032 repaint1;
416 U032 screen;
417 U032 pixel;
418 U032 horiz;
419 U032 arbitration0;
420 U032 arbitration1;
421 U032 vpll;
422 U032 pllsel;
423 U032 general;
424 U032 config;
425 U032 cursor0;
426 U032 cursor1;
427 U032 cursor2;
428 U032 offset0;
429 U032 offset1;
430 U032 offset2;
431 U032 offset3;
432 U032 pitch0;
433 U032 pitch1;
434 U032 pitch2;
435 U032 pitch3;
436} RIVA_HW_STATE;
437
438/*
439 * FIFO Free Count. Should attempt to yield processor if RIVA is busy.
440 */
441
442#define RIVA_FIFO_FREE(hwptr,cnt) \
443{ \
444 while (FifoFreeCount < (cnt)) \
445 FifoFreeCount = hwptr->FifoFree >> 2; \
446 FifoFreeCount -= (cnt); \
447}
448#endif /* __RIVA_HW_H__ */
449
diff --git a/apps/plugins/sdl/src/video/fbcon/riva_regs.h b/apps/plugins/sdl/src/video/fbcon/riva_regs.h
deleted file mode 100644
index 5324562ecd..0000000000
--- a/apps/plugins/sdl/src/video/fbcon/riva_regs.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef _RIVA_REGS_H
25#define _RIVA_REGS_H
26
27/* This information comes from the XFree86 NVidia hardware driver */
28
29/* mapped_io register offsets */
30#define PGRAPH_OFFSET 0x00400000
31#define FIFO_OFFSET 0x00800000
32#define ROP_OFFSET FIFO_OFFSET+0x00000000
33#define CLIP_OFFSET FIFO_OFFSET+0x00002000
34#define PATT_OFFSET FIFO_OFFSET+0x00004000
35#define PIXMAP_OFFSET FIFO_OFFSET+0x00006000
36#define BLT_OFFSET FIFO_OFFSET+0x00008000
37#define BITMAP_OFFSET FIFO_OFFSET+0x0000A000
38#define LINE_OFFSET FIFO_OFFSET+0x0000C000
39#define TRI03_OFFSET FIFO_OFFSET+0x0000E000
40#define PCIO_OFFSET 0x00601000
41
42#endif /* _RIVA_REGS_H */
43