2007-01-28 05:53:06 +03:00
|
|
|
// Emacs style mode select -*- C++ -*-
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// $Id:$
|
|
|
|
//
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
//
|
|
|
|
// This source is available for distribution and/or modification
|
|
|
|
// only under the terms of the DOOM Source Code License as
|
|
|
|
// published by id Software. All rights reserved.
|
|
|
|
//
|
|
|
|
// The source is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
// $Log:$
|
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
2007-02-09 01:53:29 +03:00
|
|
|
// DOOM graphics stuff for SDL library
|
2007-01-28 05:53:06 +03:00
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static const char
|
|
|
|
rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
#include "m_swap.h"
|
2007-01-28 05:53:06 +03:00
|
|
|
#include "doomstat.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "m_argv.h"
|
|
|
|
#include "d_main.h"
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
2007-02-09 01:53:29 +03:00
|
|
|
|
|
|
|
#include "kolibri.h"
|
|
|
|
|
|
|
|
void BlitDIB();
|
|
|
|
|
|
|
|
typedef struct SURFACE
|
|
|
|
{
|
|
|
|
unsigned char *pixels;
|
|
|
|
int w, h;
|
|
|
|
int pitch;
|
|
|
|
int offset;
|
|
|
|
} SURFACE;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
SURFACE screen;
|
|
|
|
|
|
|
|
// Fake mouse handling.
|
2007-02-09 01:53:29 +03:00
|
|
|
boolean grabMouse;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
// Blocky mode,
|
|
|
|
// replace each 320x200 pixel with multiply*multiply pixels.
|
|
|
|
// According to Dave Taylor, it still is a bonehead thing
|
|
|
|
// to use ....
|
2007-02-09 01:53:29 +03:00
|
|
|
static int multiply=2;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
static int disableVerticalMouse = 0;
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
static int scr_w =0;
|
|
|
|
static int scr_h =0;
|
|
|
|
static int win_x, win_y;
|
|
|
|
static int win_w, win_h;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
//int palette_color[256];
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
static int lastmousex = 0;
|
|
|
|
static int lastmousey = 0;
|
|
|
|
boolean mousemoved = false;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
void I_ShutdownGraphics(void)
|
|
|
|
{
|
2007-02-09 01:53:29 +03:00
|
|
|
|
2007-01-28 05:53:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// I_StartFrame
|
|
|
|
//
|
|
|
|
void I_StartFrame (void)
|
|
|
|
{
|
|
|
|
// er?
|
2007-02-09 01:53:29 +03:00
|
|
|
|
|
|
|
//printf("start new frame\n\r" );
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
int test_for_event(void)
|
|
|
|
{ int retval;
|
|
|
|
_asm
|
|
|
|
{ push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
mov eax,11
|
|
|
|
int 0x40
|
|
|
|
mov [retval], eax
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
};
|
|
|
|
return retval;
|
|
|
|
};
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
void I_GetEvent(void)
|
|
|
|
{
|
2007-02-09 01:53:29 +03:00
|
|
|
event_t evnt;
|
|
|
|
int val;
|
|
|
|
int key;
|
|
|
|
//printf("begin get_event()\n\r");
|
|
|
|
do
|
|
|
|
{ val= test_for_event();
|
|
|
|
switch(val)
|
|
|
|
{ case EV_REDRAW:
|
|
|
|
BeginDraw();
|
|
|
|
DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0);
|
|
|
|
EndDraw();
|
|
|
|
BlitDIB();
|
|
|
|
break;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
case EV_KEY:
|
|
|
|
if(!get_key(&key))
|
|
|
|
{
|
|
|
|
switch(key)
|
|
|
|
{ case 0xE0:
|
|
|
|
case 0xE1:
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
if(key&0x80)
|
|
|
|
{ //printf("key released\n\r");
|
|
|
|
evnt.type = ev_keyup;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //printf("key pressed %x\n\r",key);
|
|
|
|
evnt.type = ev_keydown;
|
|
|
|
};
|
|
|
|
key&=0x7F;
|
|
|
|
evnt.data1=remap_key(key);
|
|
|
|
if ( evnt.data1 != 0 )
|
|
|
|
D_PostEvent(&evnt);
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case EV_BUTTON:
|
|
|
|
switch(get_button_id())
|
|
|
|
{ case 1:
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}while(val);
|
2007-01-28 05:53:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// I_StartTic
|
|
|
|
//
|
|
|
|
void I_StartTic (void)
|
|
|
|
{
|
|
|
|
I_GetEvent();
|
2007-02-09 01:53:29 +03:00
|
|
|
|
2007-01-28 05:53:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// I_UpdateNoBlit
|
|
|
|
//
|
|
|
|
void I_UpdateNoBlit (void)
|
|
|
|
{
|
|
|
|
// what is this?
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// I_ReadScreen
|
|
|
|
//
|
|
|
|
void I_ReadScreen (byte* scr)
|
|
|
|
{
|
|
|
|
memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// I_SetPalette
|
|
|
|
//
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
unsigned int colors[256];
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
void I_SetPalette (byte* palette)
|
|
|
|
{
|
|
|
|
int i;
|
2007-02-09 01:53:29 +03:00
|
|
|
unsigned int r;
|
|
|
|
unsigned int g;
|
|
|
|
unsigned int b;
|
|
|
|
|
|
|
|
for ( i=0; i<256; ++i )
|
2007-01-28 05:53:06 +03:00
|
|
|
{
|
2007-02-09 01:53:29 +03:00
|
|
|
r = gammatable[usegamma][*palette++];
|
|
|
|
g = gammatable[usegamma][*palette++];
|
|
|
|
b = gammatable[usegamma][*palette++];
|
|
|
|
colors[i]= b|(g<<8)|(r<<16);
|
2007-01-28 05:53:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
void BeginDraw()
|
|
|
|
{ _asm
|
|
|
|
{ push ebx
|
|
|
|
mov eax,12
|
|
|
|
mov ebx, 1
|
|
|
|
int 0x40
|
|
|
|
pop ebx
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void EndDraw()
|
|
|
|
{ _asm
|
|
|
|
{ push ebx
|
|
|
|
mov eax,12
|
|
|
|
mov ebx, 2
|
|
|
|
int 0x40
|
|
|
|
pop ebx
|
|
|
|
};
|
|
|
|
};
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
void I_InitGraphics(void)
|
|
|
|
{
|
|
|
|
static int firsttime=1;
|
2007-02-09 01:53:29 +03:00
|
|
|
|
|
|
|
int frameX, frameY;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
if (!firsttime)
|
2007-02-09 01:53:29 +03:00
|
|
|
return;
|
2007-01-28 05:53:06 +03:00
|
|
|
firsttime = 0;
|
|
|
|
|
|
|
|
if (M_CheckParm("-2"))
|
2007-02-09 01:53:29 +03:00
|
|
|
multiply = 2;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
if (M_CheckParm("-3"))
|
2007-02-09 01:53:29 +03:00
|
|
|
multiply = 3;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
if (M_CheckParm("-4"))
|
2007-02-09 01:53:29 +03:00
|
|
|
multiply = 4;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
win_w = SCREENWIDTH * multiply;
|
|
|
|
win_h = SCREENHEIGHT * multiply;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
// check if the user wants to grab the mouse (quite unnice)
|
|
|
|
grabMouse = !!M_CheckParm("-grabmouse");
|
|
|
|
|
|
|
|
/* [Petteri] New: Option to disable mouse vertical movement - useful
|
|
|
|
for players used to Quake: */
|
|
|
|
disableVerticalMouse = !!M_CheckParm("-novertmouse");
|
|
|
|
|
|
|
|
/* Build and initialize the window: */
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
frameX = 0;
|
|
|
|
frameY = 18;
|
2007-01-28 05:53:06 +03:00
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
GetScreenSize(&scr_w, &scr_h);
|
|
|
|
win_x = (scr_w-win_w)/2;
|
|
|
|
win_y = (scr_h-win_h)/2;
|
|
|
|
|
|
|
|
// hCursor = LoadCursor( 0, IDC_ARROW );
|
2007-01-28 05:53:06 +03:00
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
printf("I_InitGraphics: Client area: %ux%u\n\r", win_w, win_h);
|
2007-01-28 05:53:06 +03:00
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
screen.pixels= (byte*) UserAlloc(640*400*4);
|
|
|
|
screen.h = win_w;
|
|
|
|
screen.w = win_h;
|
2007-01-28 05:53:06 +03:00
|
|
|
screen.pitch=640;
|
2007-02-09 01:53:29 +03:00
|
|
|
|
|
|
|
BeginDraw();
|
|
|
|
DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0);
|
|
|
|
EndDraw();
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
void conv(char *dst, char *src);
|
|
|
|
|
|
|
|
void BlitDIB()
|
|
|
|
{
|
|
|
|
_asm
|
|
|
|
{ push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
mov eax, 7
|
|
|
|
mov ebx, dword ptr [screen]
|
|
|
|
mov ecx, 0x02800190
|
|
|
|
xor edx, edx
|
|
|
|
int 0x40
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
}
|
|
|
|
};
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// I_FinishUpdate
|
2007-02-09 01:53:29 +03:00
|
|
|
//
|
2007-01-28 05:53:06 +03:00
|
|
|
void I_FinishUpdate (void)
|
|
|
|
{
|
2007-02-09 01:53:29 +03:00
|
|
|
char *dst0;
|
|
|
|
char *dst1;
|
|
|
|
char *src;
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
dst0 = &((char *)screen.pixels)[0];
|
|
|
|
dst1 = dst0+640*3;
|
|
|
|
src= (char*)screens[0];
|
|
|
|
y = SCREENHEIGHT;
|
|
|
|
while (y--)
|
2007-01-28 05:53:06 +03:00
|
|
|
{
|
2007-02-09 01:53:29 +03:00
|
|
|
x = SCREENWIDTH;
|
|
|
|
conv(dst0,src);
|
|
|
|
src+=320;
|
|
|
|
dst0+=640*3*2;
|
|
|
|
dst1+=640*3*2;
|
2007-01-28 05:53:06 +03:00
|
|
|
}
|
2007-02-09 01:53:29 +03:00
|
|
|
BlitDIB();
|
2007-01-28 05:53:06 +03:00
|
|
|
}
|
|
|
|
|
2007-02-09 01:53:29 +03:00
|
|
|
void conv(char *dst, char *src)
|
2007-01-28 05:53:06 +03:00
|
|
|
{
|
2007-02-09 01:53:29 +03:00
|
|
|
_asm
|
|
|
|
{
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
mov ecx, 320
|
|
|
|
mov esi, [src]
|
|
|
|
mov edi, [dst]
|
|
|
|
cld
|
|
|
|
l1:
|
|
|
|
lodsb
|
|
|
|
movzx eax, al
|
|
|
|
mov eax, [colors+eax*4]
|
|
|
|
mov ebx, eax
|
|
|
|
bswap ebx
|
|
|
|
and ebx, 0xFF000000
|
|
|
|
or eax, ebx
|
|
|
|
mov [edi],eax
|
|
|
|
mov [edi+640*3], eax
|
|
|
|
shr eax, 8
|
|
|
|
mov [edi+4], ax
|
|
|
|
mov [edi+640*3+4], ax
|
|
|
|
add edi, 6
|
|
|
|
dec ecx
|
|
|
|
jnz l1
|
|
|
|
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-01-28 05:53:06 +03:00
|
|
|
|
|
|
|
|