Subversion Repositories Kolibri OS

Rev

Rev 300 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 300 Rev 333
Line 24... Line 24...
24
static const char
24
static const char
25
rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
25
rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
Line 26... Line 26...
26
 
26
 
Line 27... Line -...
27
#include 
-
 
28
 
-
 
29
//#include "SDL.h"
27
#include 
30
 
28
 
31
//#include "m_swap.h"
29
#include "m_swap.h"
32
#include "doomstat.h"
30
#include "doomstat.h"
33
#include "i_system.h"
31
#include "i_system.h"
34
#include "v_video.h"
32
#include "v_video.h"
Line 35... Line 33...
35
#include "m_argv.h"
33
#include "m_argv.h"
-
 
34
#include "d_main.h"
36
#include "d_main.h"
35
 
-
 
36
#include "doomdef.h"
37
 
37
 
Line 38... Line 38...
38
#include "doomdef.h"
38
#include "kolibri.h"
39
#define WIN32_LEAN_AND_MEAN
39
 
-
 
40
void BlitDIB();
40
#include 
41
 
41
 
42
typedef struct SURFACE
42
typedef struct SURFACE
-
 
43
{
43
{
44
	int w, h;		
44
        unsigned char *pixels;  
Line 45... Line 45...
45
	int pitch;		
45
        int w, h;               
Line 56... Line 56...
56
// replace each 320x200 pixel with multiply*multiply pixels.
56
// replace each 320x200 pixel with multiply*multiply pixels.
57
// According to Dave Taylor, it still is a bonehead thing
57
// According to Dave Taylor, it still is a bonehead thing
58
// to use ....
58
// to use ....
59
static int	multiply=2;
59
static int      multiply=2;
Line 60... Line 60...
60
 
60
 
Line -... Line 61...
-
 
61
static int disableVerticalMouse = 0;
-
 
62
 
-
 
63
static int scr_w =0;
-
 
64
static int scr_h =0;
Line 61... Line -...
61
void WinError(char *msg);
-
 
62
 
-
 
63
 
-
 
64
int BPP;
-
 
65
byte *hicolortable;
-
 
66
short hicolortransmask1,hicolortransmask2;
-
 
67
int		X_width;
-
 
68
int		X_height;
-
 
Line 69... Line 65...
69
static int disableVerticalMouse = 0;
65
static int win_x, win_y;
70
static int closed=0;
-
 
71
static int windowActive = 0;
-
 
72
 
-
 
73
HWND win;
-
 
74
static HINSTANCE inst;
-
 
75
static HDC dibDC;
-
 
76
static LOGPALETTE *palette;
-
 
77
static HPALETTE dibPal;
66
static int win_w, win_h;
Line 78... Line 67...
78
BITMAPINFO *bminfo;
67
 
79
static unsigned char *dibData;
68
 
80
static int bits8;
69
 
81
int palette_color[256];
-
 
82
 
-
 
83
 
-
 
84
static int	lastmousex = 0;
-
 
85
static int	lastmousey = 0;
-
 
86
boolean		mousemoved = false;
-
 
87
boolean		shmFinished;
-
 
Line 88... Line -...
88
 
-
 
89
 
-
 
90
 
-
 
91
//
-
 
92
//  Translates the key 
-
 
93
//
-
 
94
 
-
 
95
/*******
-
 
96
int xlatekey(SDL_keysym *key)
-
 
97
{
-
 
98
 
-
 
99
    int rc;
-
 
100
 
-
 
101
    switch(key->sym)
-
 
102
    {
-
 
103
      case SDLK_LEFT:	rc = KEY_LEFTARROW;	break;
-
 
104
      case SDLK_RIGHT:	rc = KEY_RIGHTARROW;	break;
-
 
105
      case SDLK_DOWN:	rc = KEY_DOWNARROW;	break;
-
 
106
      case SDLK_UP:	rc = KEY_UPARROW;	break;
-
 
107
      case SDLK_ESCAPE:	rc = KEY_ESCAPE;	break;
-
 
108
      case SDLK_RETURN:	rc = KEY_ENTER;		break;
-
 
109
      case SDLK_TAB:	rc = KEY_TAB;		break;
-
 
110
      case SDLK_F1:	rc = KEY_F1;		break;
-
 
111
      case SDLK_F2:	rc = KEY_F2;		break;
-
 
112
      case SDLK_F3:	rc = KEY_F3;		break;
-
 
113
      case SDLK_F4:	rc = KEY_F4;		break;
-
 
114
      case SDLK_F5:	rc = KEY_F5;		break;
-
 
115
      case SDLK_F6:	rc = KEY_F6;		break;
-
 
116
      case SDLK_F7:	rc = KEY_F7;		break;
-
 
117
      case SDLK_F8:	rc = KEY_F8;		break;
-
 
118
      case SDLK_F9:	rc = KEY_F9;		break;
-
 
119
      case SDLK_F10:	rc = KEY_F10;		break;
-
 
120
      case SDLK_F11:	rc = KEY_F11;		break;
-
 
121
      case SDLK_F12:	rc = KEY_F12;		break;
-
 
122
	
-
 
123
      case SDLK_BACKSPACE:
-
 
124
      case SDLK_DELETE:	rc = KEY_BACKSPACE;	break;
-
 
125
 
-
 
126
      case SDLK_PAUSE:	rc = KEY_PAUSE;		break;
-
 
127
 
-
 
128
      case SDLK_EQUALS:	rc = KEY_EQUALS;	break;
-
 
129
 
-
 
130
      case SDLK_KP_MINUS:
-
 
131
      case SDLK_MINUS:	rc = KEY_MINUS;		break;
-
 
132
 
-
 
133
      case SDLK_LSHIFT:
-
 
134
      case SDLK_RSHIFT:
-
 
135
	rc = KEY_RSHIFT;
-
 
136
	break;
-
 
137
	
-
 
138
      case 'z':
-
 
139
      case SDLK_LCTRL:
-
 
140
      case SDLK_RCTRL:
-
 
141
	rc = KEY_RCTRL;
-
 
142
	break;
-
 
143
	
-
 
144
      case SDLK_LALT:
-
 
145
      case SDLK_LMETA:
-
 
146
      case SDLK_RALT:
-
 
147
      case SDLK_RMETA:
-
 
148
	rc = KEY_RALT;
-
 
149
	break;
-
 
150
	
-
 
151
      default:
-
 
152
        rc = key->sym;
-
 
Line 153... Line 70...
153
	break;
70
//int palette_color[256];
154
    }
71
 
155
 
72
 
156
    return rc;
73
static int      lastmousex = 0;
Line 157... Line 74...
157
 
74
static int      lastmousey = 0;
Line 170... Line 87...
170
//
87
//
171
void I_StartFrame (void)
88
void I_StartFrame (void)
172
{
89
{
173
    // er?
90
    // er?
Line 174... Line -...
174
 
-
 
-
 
91
    
Line 175... Line -...
175
}
-
 
176
 
-
 
177
/* This processes SDL events */
-
 
178
/*****
-
 
179
void I_GetEvent(SDL_Event *Event)
-
 
180
{
-
 
181
    Uint8 buttonstate;
-
 
182
    event_t event;
-
 
183
 
-
 
184
    switch (Event->type)
-
 
185
    {
-
 
186
      case SDL_KEYDOWN:
-
 
187
	event.type = ev_keydown;
-
 
188
	event.data1 = xlatekey(&Event->key.keysym);
-
 
189
	D_PostEvent(&event);
-
 
190
        break;
-
 
191
      case SDL_KEYUP:
-
 
192
	event.type = ev_keyup;
-
 
193
	event.data1 = xlatekey(&Event->key.keysym);
-
 
194
	D_PostEvent(&event);
-
 
195
	break;
-
 
196
      case SDL_QUIT:
-
 
197
	I_Quit();
-
 
198
	break;
92
   //printf("start new frame\n\r" );
Line -... Line 93...
-
 
93
 
-
 
94
}
199
    }
95
 
-
 
96
int test_for_event(void)
-
 
97
{ int retval;
-
 
98
  _asm
-
 
99
 {   push ebx
-
 
100
     push ecx
-
 
101
     push edx
-
 
102
     push esi
-
 
103
     push edi
-
 
104
     mov  eax,11
-
 
105
     int  0x40
-
 
106
     mov [retval], eax
-
 
107
     pop edi
-
 
108
     pop esi
200
}
109
     pop edx
-
 
110
     pop ecx
201
 
111
     pop ebx 
Line 202... Line 112...
202
*******/
112
 };
203
 
113
 return retval; 
204
 
-
 
205
 
-
 
206
 
-
 
207
void I_GetEvent(void)
-
 
208
{
114
}; 
209
    MSG msg;
115
 
210
    POINT point;
116
 
211
    static LONG prevX, prevY;
-
 
212
    static int hadMouse = 0;
-
 
213
    event_t event;
-
 
214
    RECT rect;
-
 
215
    int lb, rb;
-
 
216
    static int prevlb = 0, prevrb = 0;
117
void I_GetEvent(void)
217
    
-
 
218
    /* Dispatch all messages: */
118
{
219
    while ( PeekMessage(&msg, NULL, 0, 0xFFFFFFFF, PM_REMOVE) )
-
 
220
    {
-
 
221
        TranslateMessage (&msg) ;
119
  event_t evnt;
222
        DispatchMessage (&msg) ;
-
 
223
    }
-
 
224
 
-
 
225
    /* Check mouse and generate events if necessary: */
-
 
226
    if ( !GetCursorPos(&point) )
-
 
227
        WinError("GetCursorPos() failed");
-
 
228
    if ( hadMouse && windowActive)
-
 
229
    {
-
 
230
        lb = (GetAsyncKeyState(VK_LBUTTON) < 0);
120
  int val;
231
        rb = (GetAsyncKeyState(VK_RBUTTON) < 0);
-
 
232
            
-
 
233
        if ( (prevX != point.x) || (prevY != point.y) ||
-
 
234
             (prevlb != lb) || (prevrb != rb) )
-
 
235
        {
121
  int key;
236
            event.type = ev_mouse;
122
  //printf("begin get_event()\n\r");
237
            event.data1 = lb | (rb << 1);
123
  do
238
            event.data2 = (point.x - prevX)*9;
-
 
239
            if ( disableVerticalMouse )
-
 
240
                event.data3 = 0;
124
  { val= test_for_event();
241
            else
125
    switch(val)
242
                event.data3 = (prevY - point.y)*9;
-
 
243
            prevX = point.x;
126
    { case EV_REDRAW:
244
            prevY = point.y;
127
        BeginDraw();
245
            prevlb = lb;
-
 
246
            prevrb = rb;
128
        DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0);
247
            D_PostEvent(&event);
129
        EndDraw();
248
        }
-
 
249
 
-
 
250
        if ( grabMouse )
-
 
251
        {
-
 
252
            GetWindowRect(win, &rect);
-
 
253
            if ( !SetCursorPos((rect.left + rect.right) / 2,
-
 
254
                               (rect.top + rect.bottom) / 2) )
-
 
255
                WinError("SetCursorPos() failed");
-
 
256
            prevX = (rect.left + rect.right) / 2;
130
        BlitDIB();
-
 
131
        break;
-
 
132
 
257
            prevY = (rect.top + rect.bottom) / 2;
133
      case EV_KEY:
258
        }
134
        if(!get_key(&key))
259
    }
135
        { 
-
 
136
          switch(key)
-
 
137
          {  case 0xE0:
-
 
138
             case 0xE1:
260
    else
139
               continue;
-
 
140
             default:
-
 
141
               if(key&0x80)
-
 
142
               { //printf("key released\n\r");
-
 
143
                 evnt.type = ev_keyup; 
-
 
144
               }
-
 
145
               else
-
 
146
               { //printf("key pressed %x\n\r",key);
-
 
147
                 evnt.type = ev_keydown; 
-
 
148
               };
-
 
149
               key&=0x7F; 
-
 
150
               evnt.data1=remap_key(key);
-
 
151
               if ( evnt.data1 != 0 )
-
 
152
                 D_PostEvent(&evnt);
-
 
153
               continue;
-
 
154
          };     
-
 
155
        };  
-
 
156
        continue;
-
 
157
 
-
 
158
      case EV_BUTTON:
-
 
159
        switch(get_button_id())
-
 
160
        {  case 1:
-
 
161
             return;
261
    {
162
             
Line 262... Line 163...
262
        prevX = point.x;
163
          default:;
263
        prevY = point.y;
164
        };
264
        hadMouse = 1;
165
    };   
265
    }        
166
  }while(val);
266
}
167
}
267
 
-
 
268
 
-
 
269
 
-
 
270
//
-
 
271
// I_StartTic
168
 
Line 272... Line 169...
272
//
169
 
Line 300... Line 197...
300
 
197
 
301
//
198
//
302
// I_SetPalette
199
// I_SetPalette
Line 303... Line -...
303
//
-
 
304
 
-
 
305
typedef struct SDL_Color
-
 
306
{
-
 
307
	byte r;
-
 
308
	byte g;
-
 
309
	byte b;
-
 
310
	byte unused;
-
 
311
} SDL_Color; 
200
//
Line 312... Line 201...
312
 
201
 
313
SDL_Color colors[256];
202
unsigned int colors[256];
314
 
203
 
315
void I_SetPalette (byte* palette)
204
void I_SetPalette (byte* palette)
316
{
-
 
317
    int i;
-
 
318
    RGBQUAD *rgb;
205
{
319
 
-
 
320
// 
-
 
321
//    for ( i=0; i<256; ++i ) {
-
 
322
//	colors[i].r = gammatable[usegamma][*palette++];
206
    int i;
323
//	colors[i].g = gammatable[usegamma][*palette++];
-
 
324
//	colors[i].b = gammatable[usegamma][*palette++];
-
 
325
//	colors[i].unused = 0;
207
    unsigned int r;
326
//    }
-
 
327
//    SDL_SetColors(screen, colors, 0, 256);
208
    unsigned int g;
328
 
209
    unsigned int b;
329
    rgb = bminfo->bmiColors;
210
    
330
    for ( i = 0; i < 256; i++ )
211
    for ( i=0; i<256; ++i )
331
    {
212
    {
332
      rgb->rgbRed = gammatable[usegamma][*palette++];
213
          r = gammatable[usegamma][*palette++];
333
      rgb->rgbGreen = gammatable[usegamma][*palette++];
-
 
334
      rgb->rgbBlue = gammatable[usegamma][*palette++];
-
 
335
      rgb->rgbReserved = 0;
-
 
336
      rgb++;
-
 
337
    };
214
          g = gammatable[usegamma][*palette++];
338
 
-
 
339
 
-
 
340
}
-
 
341
 
-
 
342
 
-
 
343
 
-
 
344
int makecol(int r, int g, int b)
-
 
345
{
-
 
346
  //  assert(BPP==2);
-
 
347
    return (b >> 3) | ((g >> 3) << 5) | ((r >> 3) << 10);
-
 
348
}
-
 
349
 
-
 
350
int TranslateKey(unsigned k)
-
 
351
{
-
 
352
/*wtf?    if ( (k >= VK_0) && (k <= VK_9) )*/
-
 
353
    if ( (k >= 0x30) && (k <= 0x39) )
-
 
354
        return (k - 0x30 + '0');
-
 
355
    if ( (k >= 0x41) && (k <= 0x5a) )
-
 
356
        return (k - 0x41 + 'a');
-
 
357
 
-
 
358
#define K(a,b) case a: return b;    
-
 
359
    switch ( k )
-
 
360
    {
-
 
361
        K(VK_LEFT, KEY_LEFTARROW);
-
 
362
        K(VK_RIGHT, KEY_RIGHTARROW);
-
 
363
        K(VK_UP, KEY_UPARROW);
-
 
364
        K(VK_DOWN, KEY_DOWNARROW);
-
 
365
        K(VK_BACK, KEY_BACKSPACE);
-
 
366
        K(VK_TAB, KEY_TAB);
-
 
367
        K(VK_RETURN, KEY_ENTER);
-
 
368
        K(VK_SHIFT, KEY_RSHIFT);
-
 
369
        K(VK_CONTROL, KEY_RCTRL);
-
 
370
        K(VK_MENU, KEY_RALT);
-
 
371
        K(VK_PAUSE, KEY_PAUSE);
-
 
372
        K(VK_ESCAPE, KEY_ESCAPE);
-
 
373
        K(VK_SPACE, ' ');
-
 
374
        K(VK_DELETE, KEY_BACKSPACE);
-
 
375
        K(VK_ADD, '+');
-
 
376
        K(VK_SUBTRACT, KEY_MINUS);
-
 
377
        K(0xBC, ',');
-
 
378
        K(0xBE, '.');
-
 
379
        K(VK_F1, KEY_F1);
-
 
380
        K(VK_F2, KEY_F2);
-
 
381
        K(VK_F3, KEY_F3);
-
 
382
        K(VK_F4, KEY_F4);
-
 
383
        K(VK_F5, KEY_F5);
-
 
384
        K(VK_F6, KEY_F6);
-
 
385
        K(VK_F7, KEY_F7);
-
 
386
        K(VK_F8, KEY_F8);
-
 
387
        K(VK_F9, KEY_F9);
-
 
388
        K(VK_F10, KEY_F10);
-
 
389
        K(VK_F11, KEY_F11);
-
 
390
        K(VK_F12, KEY_F12);
-
 
391
    }
-
 
392
 
-
 
393
    return 0;
-
 
394
}
-
 
395
 
-
 
396
void WinError(char *msg)
-
 
397
{
215
          b = gammatable[usegamma][*palette++];
Line 398... Line -...
398
    printf("Windows Error: %s, GetLastError(): %u\n", msg, GetLastError());
-
 
399
    exit(EXIT_FAILURE);
-
 
400
}
-
 
401
 
216
          colors[i]= b|(g<<8)|(r<<16);
402
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
217
    }
403
                                WPARAM wparam, LPARAM lparam);
218
}
404
 
-
 
405
void BlitDIB(void)
219
 
406
{
-
 
407
    RECT rect;
-
 
408
 
-
 
409
    GetClientRect(win, &rect);
220
void BeginDraw()
410
    if ( StretchDIBits(dibDC, rect.left, rect.top, rect.right-rect.left,
221
{ _asm
411
                       rect.bottom-rect.top, 0, 0, SCREENWIDTH*2,
222
  { push ebx
412
                       SCREENHEIGHT*2, dibData, bminfo, DIB_RGB_COLORS,
223
    mov   eax,12
413
                         SRCCOPY)
-
 
414
             == GDI_ERROR )
224
    mov   ebx, 1
Line -... Line 225...
-
 
225
    int   0x40
-
 
226
    pop ebx
-
 
227
  };  
-
 
228
};
-
 
229
 
-
 
230
void EndDraw()
-
 
231
{ _asm
-
 
232
  { push ebx
-
 
233
    mov   eax,12
Line 415... Line 234...
415
          WinError("StrecthDIBits failed");
234
    mov   ebx, 2
416
        
235
    int   0x40
417
    GdiFlush();    
236
    pop ebx
Line 418... Line -...
418
}
-
 
419
 
-
 
420
 
-
 
421
void I_InitGraphics(void)
-
 
422
{
-
 
423
    static int firsttime=1;
237
  };  
424
    
-
 
425
    WNDCLASS wc;
-
 
426
    unsigned i, x, y, j;
-
 
427
    WORD *d;
-
 
Line 428... Line 238...
428
    unsigned char *b;
238
};
429
    int bits;
239
 
430
    int frameX, frameY, capY;
240
void I_InitGraphics(void)
Line 444... Line 254...
444
	multiply = 3;
254
        multiply = 3;
Line 445... Line 255...
445
 
255
 
446
    if (M_CheckParm("-4"))
256
    if (M_CheckParm("-4"))
Line 447... Line 257...
447
	multiply = 4;
257
        multiply = 4;
448
 
258
 
Line 449... Line 259...
449
    X_width = SCREENWIDTH * multiply;
259
    win_w = SCREENWIDTH * multiply;
450
    X_height = SCREENHEIGHT * multiply;
260
    win_h = SCREENHEIGHT * multiply;
Line 451... Line 261...
451
 
261
 
452
    // check if the user wants to grab the mouse (quite unnice)
262
    // check if the user wants to grab the mouse (quite unnice)
453
    grabMouse = !!M_CheckParm("-grabmouse");
263
    grabMouse = !!M_CheckParm("-grabmouse");
Line 454... Line 264...
454
 
264
 
Line 455... Line -...
455
    /* [Petteri] New: Option to disable mouse vertical movement - useful
-
 
456
       for players used to Quake: */
-
 
457
    disableVerticalMouse = !!M_CheckParm("-novertmouse");
-
 
458
 
-
 
459
    /* Build and initialize the window: */
-
 
460
    
-
 
461
    inst = (HINSTANCE) GetModuleHandle(NULL);
-
 
462
 
-
 
463
    frameX = GetSystemMetrics(SM_CXFRAME);
-
 
464
    frameY = GetSystemMetrics(SM_CYFRAME);
265
    /* [Petteri] New: Option to disable mouse vertical movement - useful
465
    capY = GetSystemMetrics(SM_CYCAPTION);
-
 
466
 
266
       for players used to Quake: */
467
    wc.style = CS_HREDRAW | CS_VREDRAW;
-
 
468
    wc.lpfnWndProc = WndProc;
-
 
469
    wc.cbClsExtra = 0;
-
 
470
    wc.cbWndExtra = 0;
-
 
471
    wc.hInstance = inst;
-
 
472
    wc.hIcon = NULL;
-
 
473
    if ( grabMouse )
-
 
474
        wc.hCursor = LoadCursor( 0, IDC_ARROW );
-
 
475
    else
-
 
476
        wc.hCursor = LoadCursor( 0, IDC_ARROW );
-
 
Line -... Line 267...
-
 
267
    disableVerticalMouse = !!M_CheckParm("-novertmouse");
477
    /*wc.hbrBackground = GetStockObject( WHITE_BRUSH );*/
268
 
478
    wc.hbrBackground = NULL;    
269
    /* Build and initialize the window: */
Line 479... Line -...
479
    wc.lpszMenuName = NULL;
-
 
480
    wc.lpszClassName = "DoomWindowClass";
-
 
481
 
270
    
Line 482... Line 271...
482
    retval= RegisterClass(&wc);
271
    frameX = 0;
483
 
-
 
484
    width = X_width + 2*frameX;
-
 
Line 485... Line -...
485
    height = X_height + 2*frameY + capY;
-
 
486
 
-
 
487
    win = CreateWindow("DoomWindowClass", "NTDOOM",
-
 
488
                       WS_OVERLAPPEDWINDOW | WS_VISIBLE, 200, 200, width, height,
-
 
489
                       NULL, NULL, inst, NULL);
-
 
490
 
-
 
491
    /* Display the window: */
-
 
492
    ShowWindow(win, SW_SHOW);
-
 
493
    UpdateWindow(win);
-
 
494
 
-
 
495
    GetClientRect(win, &rect);
-
 
496
    printf("I_InitGraphics: Client area: %ux%u\n",
-
 
497
            rect.right-rect.left, rect.bottom-rect.top);
-
 
498
 
-
 
499
    if ( (rect.right-rect.left) != X_width )
-
 
500
    {
-
 
501
        printf("I_InitGraphics: Fixing width\n");
-
 
502
        width += X_width - (rect.right-rect.left);
-
 
503
        MoveWindow(win, 0, 0, width, height, TRUE);
-
 
504
    }
-
 
505
    if ( (rect.bottom-rect.top) != X_height )
-
 
506
    {
-
 
507
        printf("I_InitGraphics: Fixing height\n");
-
 
508
        height += X_height - (rect.bottom-rect.top);
-
 
509
        MoveWindow(win, 0, 0, width, height, TRUE);
-
 
510
    }
-
 
511
 
-
 
512
    GetClientRect(win, &rect);
-
 
513
    printf("I_InitGraphics: Client area: %ux%u\n",
-
 
514
            rect.right-rect.left, rect.bottom-rect.top);    
-
 
515
        
-
 
516
    dibDC = GetDC(win);
-
 
517
    BPP=1;
-
 
518
    bits = 8; //GetDeviceCaps(dibDC, BITSPIXEL);
-
 
519
    printf("I_InitGraphics: %i bpp screen\n", bits);
-
 
520
 
-
 
521
    if ( BPP == 1 )
-
 
522
        bminfo = malloc(sizeof(BITMAPINFOHEADER) + 4*256);
-
 
523
    else
-
 
524
        bminfo = malloc(sizeof(BITMAPINFOHEADER));
-
 
525
        
-
 
526
 
-
 
527
    if ( BPP == 1 )
-
 
528
    {
-
 
529
       rgb = bminfo->bmiColors;
-
 
530
       for ( i = 0; i < 256; i++ )
-
 
531
       {
-
 
532
          rgb->rgbRed = i;
-
 
533
          rgb->rgbGreen = i;
-
 
534
          rgb->rgbBlue = i;
-
 
535
          rgb->rgbReserved = 0;
-
 
536
          rgb++;
-
 
537
       }
-
 
538
    }
-
 
539
    
-
 
540
    bminfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-
 
541
    bminfo->bmiHeader.biWidth = 640; X_width;
-
 
542
    bminfo->bmiHeader.biHeight = -400 ;X_height;
-
 
543
    bminfo->bmiHeader.biPlanes = 1;
-
 
544
    if ( BPP == 1 )
-
 
545
        bminfo->bmiHeader.biBitCount = 8;
-
 
546
    else
-
 
547
        bminfo->bmiHeader.biBitCount = 16;
-
 
548
    bminfo->bmiHeader.biCompression = BI_RGB;
-
 
549
    bminfo->bmiHeader.biSizeImage = 0;
272
    frameY = 18;
550
    bminfo->bmiHeader.biXPelsPerMeter = 0;
273
    
551
    bminfo->bmiHeader.biYPelsPerMeter = 0;
274
    GetScreenSize(&scr_w, &scr_h);
552
    bminfo->bmiHeader.biClrUsed = 0;
275
    win_x = (scr_w-win_w)/2;
Line 553... Line 276...
553
    bminfo->bmiHeader.biClrImportant = 0;
276
    win_y = (scr_h-win_h)/2;
554
    
-
 
555
    dibData = malloc(640*400*BPP);
277
      
556
 
278
 //   hCursor = LoadCursor( 0, IDC_ARROW );
557
//    BlitDIB();
-
 
558
 
-
 
559
    screen.pixels=(unsigned char *) (dibData);
-
 
560
    screen.h=400;
-
 
Line 561... Line -...
561
    screen.w=640;
-
 
562
    screen.pitch=640;
-
 
563
       
-
 
564
  //  screens[0] = malloc(320*200);
-
 
565
 
-
 
566
    /* Build magic highcolor table: */
-
 
567
    if (BPP==2)
279
    
568
    {
-
 
569
        byte *tempptr, *tempptr2;
-
 
570
 
-
 
571
        tempptr=hicolortable=(byte *)malloc(256*32*9);
-
 
572
        
-
 
573
        for (i=0;i<32;i++)
-
 
574
        {
-
 
575
            for (j=0;j<256;j++)
-
 
576
            {
-
 
577
                *tempptr=j*gammatable[3][i*(256/32)]/256;
-
 
578
                tempptr++;
-
 
579
            }
-
 
580
        }
-
 
581
        for (i=1;i<=8;i++)
-
 
582
        {
-
 
583
            tempptr2=hicolortable;
-
 
584
            for (j=0;j<(256*32);j++)
-
 
585
            {
-
 
586
                *tempptr=(byte)(((int)(*tempptr2))*(8-i)/8);
-
 
587
                tempptr++; tempptr2++;
-
 
Line 588... Line -...
588
            }
-
 
589
        }
-
 
590
        hicolortransmask1=makecol(127,127,127);
-
 
591
        hicolortransmask2=makecol(63,63,63);
-
 
592
    }    
-
 
593
}
-
 
594
 
-
 
595
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
-
 
596
                                WPARAM wparam, LPARAM lparam)
-
 
597
{
-
 
598
    event_t event;
-
 
599
    RECT rect;
-
 
Line 600... Line -...
600
    
-
 
601
    switch ( message )
-
 
602
    {        
-
 
603
        case WM_DESTROY:
-
 
604
            if ( grabMouse )
280
    printf("I_InitGraphics: Client area: %ux%u\n\r", win_w, win_h);
605
            {
-
 
Line 606... Line -...
606
                ClipCursor(NULL);
-
 
607
                ShowCursor(TRUE);
-
 
608
            }
-
 
609
            printf("WM_DESTROY\n");
281
 
610
            PostQuitMessage(0);
-
 
611
            closed = 1;
-
 
612
            break;
-
 
613
 
-
 
614
        case WM_MOVE:
-
 
615
            GetWindowRect(win, &rect);
-
 
616
            printf("%u,%u - %u, %u\n",
-
 
617
                    rect.left,rect.top,rect.right,rect.bottom);
-
 
618
            ClipCursor(&rect);
-
 
619
            break;
-
 
620
 
-
 
621
        case WM_ACTIVATE:
-
 
622
            printf("WM_ACTIVATE %u\n", (unsigned) LOWORD(wparam));
-
 
623
            if ( LOWORD(wparam) )
-
 
624
            {
-
 
625
                if ( !windowActive )
-
 
626
                {
-
 
627
                    if ( grabMouse )
-
 
628
                    {
-
 
629
                        ClipCursor(NULL); /* helps with Win95? */
-
 
630
                        GetWindowRect(win, &rect);
-
 
631
                        printf("%u,%u - %u, %u\n",
-
 
632
                                rect.left,rect.top,rect.right,rect.bottom);
-
 
633
                        ClipCursor(&rect);
-
 
634
                        ShowCursor(FALSE);
-
 
635
                    }                    
-
 
636
                }
282
    screen.pixels= (byte*) UserAlloc(640*400*4);
637
                windowActive = 1;
-
 
638
                if ( bits8 )
-
 
639
                {
283
    screen.h = win_w;
640
                    if ( SetPaletteEntries(dibPal, 0, 256, palette->palPalEntry) != 256 )
-
 
641
                        WinError("SetPaletteEntries failed");
284
    screen.w = win_h;
642
                    if ( !UnrealizeObject(dibPal) )
-
 
643
                        WinError("UnrealizeObject failed");
-
 
644
                    if ( SelectPalette(dibDC, dibPal, FALSE) == NULL )
285
    screen.pitch=640;
645
                        WinError("SelectPalette failed");
-
 
646
                }
-
 
647
            }
-
 
648
            else
-
 
649
            {
286
    
650
                if ( grabMouse )
-
 
651
                {
287
    BeginDraw();
652
                    ClipCursor(NULL);
288
    DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0);
653
                    ShowCursor(TRUE);
-
 
654
                }
289
    EndDraw();
655
                windowActive = 0;
290
 
656
            }
291
}
657
            return DefWindowProc(hwnd, message, wparam, lparam);
-
 
658
 
292
 
659
        case WM_KEYDOWN:
-
 
660
            event.type = ev_keydown;
293
 
661
            event.data1 = TranslateKey(wparam);
-
 
662
            if ( event.data1 != 0 )
294
void conv(char *dst, char *src);
663
                D_PostEvent(&event);
295
 
-
 
296
void BlitDIB()
Line 664... Line 297...
664
            break;
297
{
665
 
298
  _asm
666
        case WM_KEYUP:
299
  {  push ebx
667
            event.type = ev_keyup;
300
     push ecx
668
            event.data1 = TranslateKey(wparam);
301
     push edx 
669
            if ( event.data1 != 0 )
-
 
670
                D_PostEvent(&event);
302
     mov eax, 7
671
            break;            
303
     mov ebx, dword ptr [screen]
672
            
-
 
673
        default:
-
 
674
            return(DefWindowProc(hwnd, message, wparam, lparam));
-
 
675
    }
-
 
676
 
-
 
677
    return 0;
-
 
678
}
-
 
679
 
-
 
680
//
-
 
681
// I_FinishUpdate
304
     mov ecx, 0x02800190
682
//
-
 
683
void I_FinishUpdate (void)
-
 
684
{
-
 
685
 
-
 
686
    static int	lasttic;
-
 
687
    int		tics;
-
 
688
    int		i;
305
     xor edx, edx
689
 
-
 
690
    // draws little dots on the bottom of the screen
-
 
691
    if (devparm)
-
 
692
    { i = I_GetTime();
-
 
693
	
-
 
694
	  tics = i - lasttic;
306
     int 0x40
695
	  lasttic = i;
307
     pop edx
696
	  if (tics > 20)
-
 
697
	    tics = 20;
308
     pop ecx
698
 
-
 
699
	  for (i=0 ; i
-
 
700
	    screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0xff;
-
 
701
	  for ( ; i<20*2 ; i+=2)
-
 
702
	    screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0;
-
 
703
    }
309
     pop ebx
704
 
310
  } 
705
    // scales the screen size before blitting it
-
 
706
    if (multiply == 1)
-
 
707
    {
-
 
708
	  unsigned char *olineptr;
-
 
709
	  unsigned char *ilineptr;
-
 
710
	  int y;
-
 
711
 
-
 
712
	  ilineptr = (unsigned char *) screens[0];
-
 
713
	  olineptr = (unsigned char *) screen.pixels;
-
 
714
 
-
 
715
	  y = SCREENHEIGHT;
-
 
716
	  while (y--)
-
 
717
	  {
-
 
718
	    memcpy(olineptr, ilineptr, screen.w);
-
 
719
	    ilineptr += SCREENWIDTH;
-
 
720
	    olineptr += screen.pitch;
-
 
721
	  }
-
 
722
    }
311
};
723
    else if (multiply == 2)
312
 
724
    {
313
//
725
	unsigned int *olineptrs[2];
314
// I_FinishUpdate
726
	unsigned int *ilineptr;
-
 
727
	int x, y, i;
-
 
728
	unsigned int twoopixels;
-
 
729
	unsigned int twomoreopixels;
-
 
730
	unsigned int fouripixels;
-
 
731
 
-
 
732
	ilineptr = (unsigned int *) (screens[0]);
-
 
733
	for (i=0 ; i<2 ; i++) {
-
 
734
	    olineptrs[i] =
-
 
735
		(unsigned int *)&((byte *)screen.pixels)[i*screen.pitch];
-
 
736
        }
-
 
737
 
-
 
738
	y = SCREENHEIGHT;
-
 
739
	while (y--)
315
// 
740
	{
-
 
741
	    x = SCREENWIDTH;
-
 
742
	    do
-
 
743
	    {
-
 
744
		fouripixels = *ilineptr++;
-
 
745
		twoopixels =	(fouripixels & 0xff000000)
-
 
746
		    |	((fouripixels>>8) & 0xffff00)
-
 
747
		    |	((fouripixels>>16) & 0xff);
-
 
748
		twomoreopixels =	((fouripixels<<16) & 0xff000000)
-
 
749
		    |	((fouripixels<<8) & 0xffff00)
-
 
750
		    |	(fouripixels & 0xff);
-
 
751
		*olineptrs[0]++ = twomoreopixels;
-
 
752
		*olineptrs[1]++ = twomoreopixels;
-
 
753
		*olineptrs[0]++ = twoopixels;
-
 
754
		*olineptrs[1]++ = twoopixels;
-
 
755
	    } while (x-=4);
-
 
756
	    olineptrs[0] += screen.pitch/4;
-
 
757
	    olineptrs[1] += screen.pitch/4;
316
void I_FinishUpdate (void)
758
	}
-
 
759
 
-
 
760
    }
-
 
761
    else if (multiply == 3)
-
 
762
    {
317
{
763
	unsigned int *olineptrs[3];
-
 
764
	unsigned int *ilineptr;
-
 
765
	int x, y, i;
-
 
766
	unsigned int fouropixels[3];
-
 
767
	unsigned int fouripixels;
-
 
768
 
-
 
769
	ilineptr = (unsigned int *) (screens[0]);
-
 
770
	for (i=0 ; i<3 ; i++) {
-
 
771
	    olineptrs[i] = 
-
 
772
		(unsigned int *)&((byte *)screen.pixels)[i*screen.pitch];
-
 
773
        }
-
 
774
 
-
 
775
	y = SCREENHEIGHT;
-
 
776
	while (y--)
-
 
777
	{
-
 
778
	    x = SCREENWIDTH;
-
 
779
	    do
-
 
780
	    {
-
 
781
		fouripixels = *ilineptr++;
-
 
782
		fouropixels[0] = (fouripixels & 0xff000000)
-
 
783
		    |	((fouripixels>>8) & 0xff0000)
-
 
784
		    |	((fouripixels>>16) & 0xffff);
318
    char *dst0;
785
		fouropixels[1] = ((fouripixels<<8) & 0xff000000)
-
 
786
		    |	(fouripixels & 0xffff00)
-
 
787
		    |	((fouripixels>>8) & 0xff);
-
 
788
		fouropixels[2] = ((fouripixels<<16) & 0xffff0000)
-
 
789
		    |	((fouripixels<<8) & 0xff00)
-
 
790
		    |	(fouripixels & 0xff);
319
    char *dst1;
791
		*olineptrs[0]++ = fouropixels[2];
320
    char *src;
792
		*olineptrs[1]++ = fouropixels[2];
321
        
Line 793... Line -...
793
		*olineptrs[2]++ = fouropixels[2];
-
 
794
		*olineptrs[0]++ = fouropixels[1];
-
 
795
		*olineptrs[1]++ = fouropixels[1];
-
 
796
		*olineptrs[2]++ = fouropixels[1];
-
 
797
		*olineptrs[0]++ = fouropixels[0];
322
    int x, y;
798
		*olineptrs[1]++ = fouropixels[0];
323
    
-
 
324
    dst0 = &((char *)screen.pixels)[0];
-
 
325
    dst1 = dst0+640*3;
-
 
326
    src= (char*)screens[0];
-
 
327
    y = SCREENHEIGHT;
-
 
328
    while (y--)
-
 
329
    {
-
 
330
      x = SCREENWIDTH;
-
 
331
      conv(dst0,src);
-
 
332
      src+=320;
-
 
333
      dst0+=640*3*2;
-
 
334
      dst1+=640*3*2;
-
 
335
    }
-
 
336
    BlitDIB();
-
 
337
}
-
 
338
 
-
 
339
void conv(char *dst, char *src)
-
 
340
{
-
 
341
   _asm
-
 
342
   {
-
 
343
     push ebx
-
 
344
     push ecx
-
 
345
     push esi
-
 
346
     push edi
-
 
347
     
-
 
348
     mov ecx, 320
-
 
349
     mov esi, [src]
-
 
350
     mov edi, [dst]
-
 
351
     cld
-
 
352
l1:     
-
 
353
     lodsb
-
 
354
     movzx eax, al
-
 
355
     mov eax, [colors+eax*4]
-
 
356
     mov ebx, eax
-
 
357
     bswap ebx
Line 799... Line -...
799
		*olineptrs[2]++ = fouropixels[0];
-
 
800
	    } while (x-=4);
-
 
801
	    olineptrs[0] += 2*screen.pitch/4;
-
 
802
	    olineptrs[1] += 2*screen.pitch/4;
-
 
803
	    olineptrs[2] += 2*screen.pitch/4;
-
 
804
	}
-
 
805
 
-
 
806
    }
-
 
807
   BlitDIB();
-
 
808
}
-
 
809
 
-
 
810
 
-
 
811
 
-
 
812
 
-
 
813
/**
-
 
Line 814... Line -...
814
void I_InitGraphics(void)
-
 
815
{
-
 
Line 816... Line -...
816
 
-
 
817
    static int	firsttime=1;
-
 
Line 818... Line -...
818
    int video_w, video_h, w, h;
-
 
819
    byte video_bpp;
-
 
820
    unsigned int video_flags;
-
 
821
 
-
 
822
    if (!firsttime)
-
 
823
	return;
-
 
824
    firsttime = 0;
-
 
825
 
-
 
826
    video_flags = (SDL_SWSURFACE|SDL_HWPALETTE);
-
 
827
    if (!!M_CheckParm("-fullscreen"))
-
 
828
        video_flags |= SDL_FULLSCREEN;
-
 
829
 
-
 
830
    if (M_CheckParm("-2"))
-
 
831
	multiply = 2;
-
 
832
 
-
 
833
    if (M_CheckParm("-3"))
-
 
834
	multiply = 3;
-
 
835
 
-
 
836
    // check if the user wants to grab the mouse (quite unnice)
-
 
837
    grabMouse = !!M_CheckParm("-grabmouse");
-
 
838
 
-
 
839
    video_w = w = SCREENWIDTH * multiply;
-
 
840
    video_h = h = SCREENHEIGHT * multiply;
-
 
841
    video_bpp = 8;
-
 
842
 
-
 
843
 
-
 
844
    if ( multiply > 3 ) {
-
 
845
        I_Error("Smallest available mode (%dx%d) is too large!",
-
 
846
						video_w, video_h);
358
     and ebx, 0xFF000000