aboutsummaryrefslogtreecommitdiff
path: root/src/KINDLE/i_video.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/KINDLE/i_video.c')
-rw-r--r--src/KINDLE/i_video.c529
1 files changed, 529 insertions, 0 deletions
diff --git a/src/KINDLE/i_video.c b/src/KINDLE/i_video.c
new file mode 100644
index 0000000..6e926d2
--- /dev/null
+++ b/src/KINDLE/i_video.c
@@ -0,0 +1,529 @@
1/* Emacs style mode select -*- C++ -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2006 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * DOOM graphics stuff for SDL
31 *
32 *-----------------------------------------------------------------------------
33 */
34
35#ifdef HAVE_CONFIG_H
36#include "config.h"
37#endif
38
39#include <stdlib.h>
40
41#ifdef HAVE_UNISTD_H
42#include <unistd.h>
43#include <errno.h>
44#include <sys/mman.h>
45#include <sys/types.h>
46#include <sys/stat.h>
47#include <fcntl.h>
48#include <sys/ioctl.h>
49#endif
50
51
52#include "m_argv.h"
53#include "doomstat.h"
54#include "doomdef.h"
55#include "doomtype.h"
56#include "v_video.h"
57#include "r_draw.h"
58#include "d_main.h"
59#include "d_event.h"
60#include "i_joy.h"
61#include "i_video.h"
62#include "z_zone.h"
63#include "s_sound.h"
64#include "sounds.h"
65#include "w_wad.h"
66#include "st_stuff.h"
67#include "lprintf.h"
68
69int gl_colorbuffer_bits=16;
70int gl_depthbuffer_bits=16;
71
72extern void M_QuitDOOM(int choice);
73#ifdef DISABLE_DOUBLEBUFFER
74int use_doublebuffer = 0;
75#else
76int use_doublebuffer = 1; // Included not to break m_misc, but not relevant to SDL
77#endif
78int use_fullscreen;
79int desired_fullscreen;
80static byte *screen;
81static int fbFd;
82static int kindleKeysFd;
83static int kindleKeysFd2;
84
85typedef struct {
86 int truc1;
87 int truc2;
88 unsigned short truc3;
89 unsigned short keyCode;
90 int status;
91} kindle_key_t;
92
93static kindle_key_t kkey;
94
95#define SCREEN_WIDTH 600
96#define SCREEN_HEIGHT 800
97
98/////////// FRAMEBUFFER STUFF
99static void init_framebuffer() {
100 fbFd = open("/dev/fb0", O_RDWR);
101 if (fbFd == -1) {
102 perror("open(/dev/fb0)");
103 exit(1);
104 }
105}
106
107static void update_framebuffer(int full) {
108 if (full) {
109 ioctl(fbFd, 0x46db, 1);
110 } else {
111 ioctl(fbFd, 0x46db, 0);
112 }
113}
114
115static void clear_framebuffer() {
116 ioctl(fbFd, 0x46e1, 0);
117}
118
119
120////// KINDLE EVENTS
121
122static void init_kindle_keys() {
123 kindleKeysFd = open("/dev/input/event1", O_RDONLY|O_NONBLOCK);
124 if (kindleKeysFd == -1) {
125 perror("open(/dev/input/event1)");
126 exit(1);
127 }
128
129 kindleKeysFd2 = open("/dev/input/event0", O_RDONLY|O_NONBLOCK);
130 if (kindleKeysFd2 == -1) {
131 perror("open(/dev/input/event0)");
132 exit(1);
133 }
134}
135
136static int kindle_poll_keys(kindle_key_t *k) {
137 int retval = read(kindleKeysFd, k, sizeof(kindle_key_t));
138 if (retval == -1) {
139 if (errno != EAGAIN) {
140 perror("read()");
141 exit(1);
142 }
143 } else if (retval > 0) {
144 return 1;
145 }
146
147 // This SHOULD NOT WORK: /dev/input/event0 doesn't have the same structure as event1
148 // For some reason it matches for the HOME key, but it's a kludge and doesn't allow us to detect the other buttons
149 retval = read(kindleKeysFd2, k, sizeof(kindle_key_t));
150 if (retval == -1) {
151 if (errno != EAGAIN) {
152 perror("read()");
153 exit(1);
154 }
155 } else if (retval > 0) {
156 return 1;
157 }
158
159 return 0;
160}
161
162////////////////////////////////////////////////////////////////////////////
163// Input code
164int leds_always_off = 0; // Expected by m_misc, not relevant
165
166// Mouse handling
167extern int usemouse; // config file var
168static boolean mouse_enabled; // usemouse, but can be overriden by -nomouse
169static boolean mouse_currently_grabbed;
170
171/////////////////////////////////////////////////////////////////////////////////
172// Keyboard handling
173
174//
175// Translates the key currently in key
176//
177
178#define KINDLE_LEFT 105
179#define KINDLE_RIGHT 106
180#define KINDLE_UP 103
181#define KINDLE_DOWN 108
182#define KINDE_OK 194
183#define KINDLE_HOME 102
184#define KINDLE_MENU 139
185#define KINDLE_BACK 158
186
187static int I_TranslateKey(unsigned short code)
188{
189 int rc = 0;
190
191 switch (code) {
192 case KINDLE_LEFT: rc = KEYD_LEFTARROW; break;
193 case KINDLE_RIGHT: rc = KEYD_RIGHTARROW; break;
194 case KINDLE_UP: rc = KEYD_UPARROW; break;
195 case KINDLE_DOWN: rc = KEYD_DOWNARROW; break;
196 case KINDE_OK: rc = KEYD_RCTRL; break;
197 default: break;
198 }
199
200
201 return rc;
202
203}
204
205/////////////////////////////////////////////////////////////////////////////////
206// Main input code
207
208/* cph - pulled out common button code logic */
209static int I_SDLtoDoomMouseState(int buttonstate)
210{
211 return 0;
212}
213
214static void I_GetEvent(kindle_key_t k)
215{
216 event_t event;
217
218 if (k.keyCode == 102 && k.status == 1) {
219 // Press HOME
220 exit(0);
221 }
222
223 switch (k.status) {
224 case 1: // SDL_KEYDOWN
225 event.type = ev_keydown;
226 event.data1 = I_TranslateKey(k.keyCode);
227 D_PostEvent(&event);
228 break;
229
230 case 0: // SDL_KEYUP
231 {
232 event.type = ev_keyup;
233 event.data1 = I_TranslateKey(k.keyCode);
234 D_PostEvent(&event);
235 }
236 break;
237
238 default:
239 break;
240 }
241}
242
243
244//
245// I_StartTic
246//
247
248void I_StartTic (void)
249{
250 while ( kindle_poll_keys(&kkey)) {
251 //printf("Keycode: %d // Status: %d\n", kkey.keyCode, kkey.status);
252 I_GetEvent(kkey);
253 }
254}
255
256//
257// I_StartFrame
258//
259void I_StartFrame (void)
260{
261}
262
263//
264// I_InitInputs
265//
266
267static void I_InitInputs(void)
268{
269 init_kindle_keys();
270}
271/////////////////////////////////////////////////////////////////////////////
272
273// I_SkipFrame
274//
275// Returns true if it thinks we can afford to skip this frame
276
277inline static boolean I_SkipFrame(void)
278{
279 static int frameno;
280
281 frameno++;
282 switch (gamestate) {
283 case GS_LEVEL:
284 if (!paused)
285 return false;
286 default:
287 // Skip odd frames
288 return (frameno & 1) ? true : false;
289 }
290}
291
292///////////////////////////////////////////////////////////
293// Palette stuff.
294//
295static void I_UploadNewPalette(int pal)
296{
297}
298
299//////////////////////////////////////////////////////////////////////////////
300// Graphics API
301
302void I_ShutdownGraphics(void)
303{
304}
305
306//
307// I_UpdateNoBlit
308//
309void I_UpdateNoBlit (void)
310{
311}
312
313//
314// I_FinishUpdate
315//
316static int newpal = 0;
317#define NO_PALETTE_CHANGE 1000
318
319void I_FinishUpdate (void)
320{
321 if (I_SkipFrame()) return;
322
323
324 int h;
325 byte *src;
326 byte *dest;
327
328
329 dest=screen;
330 src=screens[0].data;
331 h=SCREEN_HEIGHT;
332 for (; h>0; h--)
333 {
334 memcpy(dest,src,SCREENWIDTH); //*V_GetPixelDepth()
335 for (byte* off=dest; off < dest+SCREENWIDTH; off++) {
336 *off = ~*off; // Invert pixel color, 0xFF == black on the e-ink display
337 }
338 dest+=SCREEN_WIDTH;
339 src+=screens[0].byte_pitch;
340 }
341
342
343 update_framebuffer(0);
344}
345
346//
347// I_ScreenShot - moved to i_sshot.c
348//
349
350//
351// I_SetPalette
352//
353void I_SetPalette (int pal)
354{
355 newpal = pal;
356}
357
358// I_PreInitGraphics
359
360static void I_ShutdownSDL(void)
361{
362 clear_framebuffer();
363 close(fbFd);
364 return;
365}
366
367void I_PreInitGraphics(void)
368{
369 init_framebuffer();
370
371 atexit(I_ShutdownSDL);
372}
373
374// e6y
375// GLBoom use this function for trying to set the closest supported resolution if the requested mode can't be set correctly.
376// For example glboom.exe -geom 1025x768 -nowindow will set 1024x768.
377// It should be used only for fullscreen modes.
378static void I_ClosestResolution (int *width, int *height, int flags)
379{
380 *width=600;
381 *height=800;
382}
383
384// CPhipps -
385// I_CalculateRes
386// Calculates the screen resolution, possibly using the supplied guide
387void I_CalculateRes(unsigned int width, unsigned int height)
388{
389 // e6y: how about 1680x1050?
390 /*
391 SCREENWIDTH = (width+3) & ~3;
392 SCREENHEIGHT = (height+3) & ~3;
393 */
394
395// e6y
396// GLBoom will try to set the closest supported resolution
397// if the requested mode can't be set correctly.
398// For example glboom.exe -geom 1025x768 -nowindow will set 1024x768.
399// It affects only fullscreen modes.
400 if (V_GetMode() == VID_MODEGL) {
401 if ( desired_fullscreen )
402 {
403 I_ClosestResolution(&width, &height, 0);
404 }
405 SCREENWIDTH = width;
406 SCREENHEIGHT = height;
407 SCREENPITCH = SCREENWIDTH;
408 } else {
409 SCREENWIDTH = 600;//(width+15) & ~15;
410 SCREENHEIGHT = height;
411 if (!(SCREENWIDTH % 1024)) {
412 SCREENPITCH = SCREENWIDTH*V_GetPixelDepth()+32;
413 } else {
414 SCREENPITCH = SCREENWIDTH*V_GetPixelDepth();
415 }
416 }
417}
418
419// CPhipps -
420// I_SetRes
421// Sets the screen resolution
422void I_SetRes(void)
423{
424 int i;
425
426 I_CalculateRes(SCREENWIDTH, SCREENHEIGHT);
427
428 // set first three to standard values
429 for (i=0; i<3; i++) {
430 screens[i].width = SCREENWIDTH;
431 screens[i].height = SCREENHEIGHT;
432 screens[i].byte_pitch = SCREENPITCH;
433 screens[i].short_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE16);
434 screens[i].int_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE32);
435 }
436
437 // statusbar
438 screens[4].width = SCREENWIDTH;
439 screens[4].height = (ST_SCALED_HEIGHT+1);
440 screens[4].byte_pitch = SCREENPITCH;
441 screens[4].short_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE16);
442 screens[4].int_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE32);
443
444 lprintf(LO_INFO,"I_SetRes: Using resolution %dx%d\n", SCREENWIDTH, SCREENHEIGHT);
445}
446
447void I_InitGraphics(void)
448{
449 char titlebuffer[2048];
450 static int firsttime=1;
451
452 if (firsttime)
453 {
454 firsttime = 0;
455
456 atexit(I_ShutdownGraphics);
457 lprintf(LO_INFO, "I_InitGraphics: %dx%d\n", SCREENWIDTH, SCREENHEIGHT);
458
459 /* Set the video mode */
460 I_UpdateVideoMode();
461
462 /* Setup the window title */
463 strcpy(titlebuffer,PACKAGE);
464 strcat(titlebuffer," ");
465 strcat(titlebuffer,VERSION);
466 printf("Title: %s\n", titlebuffer);
467
468 /* Initialize the input system */
469 I_InitInputs();
470 }
471}
472
473int I_GetModeFromString(const char *modestr)
474{
475 video_mode_t mode;
476
477
478 mode = VID_MODE8;
479
480 return mode;
481}
482
483void I_UpdateVideoMode(void)
484{
485 int init_flags;
486 int i;
487 video_mode_t mode;
488
489 lprintf(LO_INFO, "I_UpdateVideoMode: %dx%d (%s)\n", SCREENWIDTH, SCREENHEIGHT, desired_fullscreen ? "fullscreen" : "nofullscreen");
490
491 mode = I_GetModeFromString(default_videomode);
492 if ((i=M_CheckParm("-vidmode")) && i<myargc-1) {
493 mode = I_GetModeFromString(myargv[i+1]);
494 }
495
496 V_InitMode(mode);
497 V_DestroyUnusedTrueColorPalettes();
498 V_FreeScreens();
499
500 I_SetRes();
501
502
503 screen = mmap(NULL, 600 * 800, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fbFd, 0);
504
505 if(screen == NULL) {
506 I_Error("Couldn't set %dx%d video mode", SCREENWIDTH, SCREENHEIGHT);
507 }
508
509 lprintf(LO_INFO, "I_UpdateVideoMode: 0x%x, %s, %s\n", init_flags, "", "");
510
511 mouse_currently_grabbed = false;
512
513 // Get the info needed to render to the display
514
515 screens[0].not_on_heap = true;
516 screens[0].data = (unsigned char *) (screen);
517 screens[0].byte_pitch = SCREEN_WIDTH;
518 screens[0].short_pitch = SCREEN_WIDTH; // screen->pitch / V_GetModePixelDepth(VID_MODE16);
519 screens[0].int_pitch = SCREEN_WIDTH; // screen->pitch / V_GetModePixelDepth(VID_MODE32);
520
521
522 V_AllocScreens();
523
524 // Hide pointer while over this window
525 //SDL_ShowCursor(0);
526
527 R_InitBuffer(SCREENWIDTH, SCREENHEIGHT);
528
529}