-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathi_video.c
343 lines (309 loc) · 9.35 KB
/
i_video.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
* Last updated: Jun 22, 2008
* ~Keripo
*
* Copyright (C) 2008 Keripo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
static const char
rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
#include "hotdog.h"
#include "i_video.h"
#include <stdlib.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <linux/kd.h>
#include <sys/ioctl.h>
#include "m_swap.h"
#include "doomstat.h"
#include "i_system.h"
#include "v_video.h"
#include "m_argv.h"
#include "d_main.h"
#include "doomdef.h"
// iPod stuff
static uint16 *ipod_screen_colour; //RGB565
static uint8 *ipod_screen_mono; //Y'UV - Y only
static uint16 *colour_palette;
static int monochrome = -1;
int IPOD_HW_VER, IPOD_LCD_TYPE;
static int IPOD_WIDTH, IPOD_HEIGHT;
static int console;
static struct termios stored_settings;
void I_ShutdownGraphics(void)
{
close(console);
free(ipod_screen_mono);
free(ipod_screen_colour);
free(colour_palette);
HD_LCD_Quit();
}
//
// I_StartFrame
//
void I_StartFrame (void)
{
// er?
}
static inline int ipod_get_keypress()
{
int press = 0;
if (read(console, &press, 1) != 1)
return KEY_NULL;
return press;
}
// For wheel scrolling
#define SCROLL_MOD_NUM 4 // Arbitrary number via experimentation
static int scroll_count_l = 0;
static int scroll_count_r = 0;
#define cancel_scroll() \
scroll_count_l = 0; \
scroll_count_r = 0
#define SCROLL_MOD_L(n) \
({ \
scroll_count_r = 0; \
int use_l = 0; \
if (++scroll_count_l >= n) { \
scroll_count_l -= n; \
use_l = 1; \
} \
(use_l == 1); \
})
#define SCROLL_MOD_R(n) \
({ \
scroll_count_l = 0; \
int use_r = 0; \
if (++scroll_count_r >= n) { \
scroll_count_r -= n; \
use_r = 1; \
} \
(use_r == 1); \
})
void I_GetEvent(void)
{
int input;
while ((input = ipod_get_keypress())!= KEY_NULL) {
event_t event;
if (KEYSTATE(input)) { // Key up/lifted
event.type = ev_keyup;
input = KEYCODE(input);
switch(input) { // In numeric order for speed
case KEY_REWIND:
event.data1 = KEY_LEFTARROW;
D_PostEvent(&event);
break;
case KEY_ACTION:
event.data1 = ' ';
D_PostEvent(&event);
break;
case KEY_PLAY:
event.data1 = KEY_RCTRL;
D_PostEvent(&event);
break;
case KEY_FORWARD:
event.data1 = KEY_RIGHTARROW;
D_PostEvent(&event);
break;
case KEY_HOLD:
event.data1 = KEY_ESCAPE;
D_PostEvent(&event);
break;
case KEY_MENU:
event.data1 = KEY_UPARROW;
D_PostEvent(&event);
break;
default:
break;
}
} else {
event.type = ev_keydown;
input = KEYCODE(input);
switch(input) { // In numeric order for speed
case KEY_REWIND:
cancel_scroll();
event.data1 = KEY_LEFTARROW;
D_PostEvent(&event);
break;
case SCROLL_R:
if (SCROLL_MOD_R(SCROLL_MOD_NUM)) {
event.data1 = '.';
D_PostEvent(&event);
} else {
event.type = ev_keyup;
event.data1 = '.';
D_PostEvent(&event);
event.data1 = ',';
D_PostEvent(&event);
}
break;
case KEY_ACTION:
cancel_scroll();
event.data1 = ' ';
D_PostEvent(&event);
break;
case KEY_PLAY:
cancel_scroll();
event.data1 = KEY_RCTRL;
D_PostEvent(&event);
break;
case KEY_FORWARD:
cancel_scroll();
event.data1 = KEY_RIGHTARROW;
D_PostEvent(&event);
break;
case KEY_HOLD:
cancel_scroll();
event.data1 = KEY_ESCAPE;
D_PostEvent(&event);
break;
case SCROLL_L:
if (SCROLL_MOD_L(SCROLL_MOD_NUM)) {
event.data1 = ',';
D_PostEvent(&event);
} else {
event.type = ev_keyup;
event.data1 = '.';
D_PostEvent(&event);
event.data1 = ',';
D_PostEvent(&event);
}
break;
case KEY_MENU:
cancel_scroll();
event.data1 = KEY_UPARROW;
D_PostEvent(&event);
break;
default:
break;
}
}
}
}
//
// I_StartTic
//
void I_StartTic (void)
{
I_GetEvent();
}
//
// I_UpdateNoBlit
//
void I_UpdateNoBlit (void)
{
// what is this?
}
//
// I_FinishUpdate
//
void I_FinishUpdate (void)
{
if (monochrome) { // Untested - mono owners please contact Keripo!
int x, y, p_ipod, p_src;
for (y = 0; y < IPOD_HEIGHT; y++) {
for (x = 0; x < IPOD_WIDTH; x++) {
p_ipod = x + y * IPOD_WIDTH;
p_src = x * SCREENWIDTH / IPOD_WIDTH
+ (y * SCREENHEIGHT / IPOD_HEIGHT) * SCREENWIDTH;
ipod_screen_mono[p_ipod] = screens[0][p_src];
} // ^ probably doesn't work and needs palette->RGB565->Y'UV's Y
}
HD_LCD_Update(ipod_screen_mono, 0, 0, IPOD_WIDTH, IPOD_HEIGHT);
} else {
int x, y, p_ipod, p_src;
uint16 p1, p2, p3;
for (y = 0; y < IPOD_HEIGHT; y++) {
for (x = 0; x < IPOD_WIDTH; x++) {
p_ipod = x + y * IPOD_WIDTH;
p_src = x * SCREENWIDTH / IPOD_WIDTH
+ (y * SCREENHEIGHT / IPOD_HEIGHT) * SCREENWIDTH;
// Blending is cooler
//ipod_screen_colour[p_ipod] = colour_palette[screens[0][p_src]];
p1 = colour_palette[screens[0][p_src]];
p2 = colour_palette[screens[0][p_src + 1]];
p3 = colour_palette[screens[0][p_src + SCREENWIDTH]];
ipod_screen_colour[p_ipod] = blend_pixels_4_RGB565(p1, p2, p3);
}
}
HD_LCD_Update(ipod_screen_colour, 0, 0, IPOD_WIDTH, IPOD_HEIGHT);
}
}
//
// I_ReadScreen
//
void I_ReadScreen (byte* scr)
{
memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT);
}
//
// I_SetPalette
//
void I_SetPalette (byte* palette)
{
if (!monochrome) {
int i;
for ( i=0; i<256; ++i ) {
uint8 r, g, b;
r = gammatable[usegamma][*palette++];
g = gammatable[usegamma][*palette++];
b = gammatable[usegamma][*palette++];
colour_palette[i] = RGB565(r, g, b);
}
}
}
void ipod_init_input()
{
struct termios new_settings;
console = open("/dev/console", O_RDONLY | O_NONBLOCK);
tcgetattr(console, &stored_settings);
new_settings = stored_settings;
new_settings.c_lflag &= ~(ICANON | ECHO | ISIG);
new_settings.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON | BRKINT);
new_settings.c_cc[VTIME] = 0;
new_settings.c_cc[VMIN] = 0;
tcsetattr(console, TCSAFLUSH, &new_settings);
ioctl(console, KDSKBMODE, K_MEDIUMRAW);
}
void I_InitGraphics(void)
{
static int firsttime=1;
if (!firsttime)
return;
firsttime = 0;
printf("\n");
printf("======================\n");
printf(" hDoom 1.10 K1\n");
printf(" for iPodLinux\n");
printf(" by Keripo\n");
printf("======================\n");
printf("\n");
ipod_init_input();
HD_LCD_Init();
HD_LCD_GetInfo(&IPOD_HW_VER, &IPOD_WIDTH, &IPOD_HEIGHT, &IPOD_LCD_TYPE);
if (IPOD_LCD_TYPE == 2 || IPOD_LCD_TYPE == 3) { // monochromes (1-4G & minis)
monochrome = 1;
ipod_screen_mono = malloc(IPOD_WIDTH * IPOD_HEIGHT * 2);
ipod_screen_colour = NULL;
colour_palette = NULL;
} else {
monochrome = 0;
ipod_screen_mono = NULL;
ipod_screen_colour = malloc(IPOD_WIDTH * IPOD_HEIGHT * 2);
colour_palette = (uint16 *)malloc(256 * sizeof(uint16));
}
screens[0] = (uint8 *)malloc(SCREENWIDTH * SCREENHEIGHT);
}