2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 // адрес экранного буфера
36 //unsigned char *scra;
39 //unsigned char scrbuf[64000];
43 char fullscreen
= OFF
;
46 byte mixmap
[256][256];
49 static SDL_Surface
* screen
= NULL
;
50 static int cx1
,cx2
,cy1
,cy2
;
51 static byte flametab
[16] = {
52 0xBC,0xBA,0xB8,0xB6,0xB4,0xB2,0xB0,0xD5,0xD6,0xD7,0xA1,0xA0,0xE3,0xE2,0xE1,0xE0
59 vgaimg
*V_getvgaimg (int id
) {
60 int loaded
= M_was_locked(id
);
61 vgaimg
*v
= M_lock(id
);
62 if (v
!= NULL
&& !loaded
) {
63 v
->w
= short2host(v
->w
);
64 v
->h
= short2host(v
->h
);
65 v
->sx
= short2host(v
->sx
);
66 v
->sy
= short2host(v
->sy
);
71 vgaimg
*V_loadvgaimg (char *name
) {
72 return V_getvgaimg(F_getresid(name
));
76 Uint32 flags
= SDL_SWSURFACE
|SDL_DOUBLEBUF
|SDL_HWPALETTE
;
77 if (fullscreen
) flags
= flags
| SDL_FULLSCREEN
;
78 screen
= SDL_SetVideoMode(SCRW
, SCRH
, 8, flags
);
79 if (!screen
) ERR_failinit("Unable to set video mode: %s\n", SDL_GetError());
85 // переключение в текстовый режим
90 static void draw_rect (int x
, int y
, int w
, int h
, int c
) {
96 SDL_FillRect(screen
, &dstrect
, c
);
99 // установить область вывода
100 void V_setrect (short x
,short w
,short y
,short h
) {
106 SDL_SetClipRect(screen
, &r
);
107 SDL_GetClipRect(screen
, &r
);
113 if (cx2
>=SCRW
) cx2
=SCRW
-1;
115 if (cy2
>=SCRH
) cy2
=SCRH
-1;
118 static void putpixel (int x
, int y
, Uint8 color
) {
119 if(x
>=cx1
&& x
<=cx2
&& y
>=cy1
&& y
<=cy2
) {
122 Uint8
*p
= (Uint8
*)screen
->pixels
+ y
*screen
->pitch
+ x
;
131 static byte
getpixel (int x
, int y
) {
132 if(x
>=cx1
&& x
<=cx2
&& y
>=cy1
&& y
<=cy2
) {
135 return *((Uint8
*)screen
->pixels
+ y
*screen
->pitch
+ x
);
140 static void mappixel (int x
, int y
, byte
* cmap
) {
141 byte c
= getpixel(x
,y
);
142 putpixel(x
,y
,cmap
[c
]);
145 void V_center (int f
) {
146 if (f
) V_offset(SCRW
/2-320/2, SCRH
/2-200/2);
150 void V_offset (int ox
, int oy
) {
155 static void draw_spr (short x
, short y
, vgaimg
*i
, int d
, int c
) {
159 if (d
& 1) x
=x
-i
->w
+i
->sx
; else x
-=i
->sx
;
160 if (d
& 2) y
=y
-i
->h
+i
->sy
; else y
-=i
->sy
;
161 if(x
+i
->w
>=cx1
&& x
<=cx2
&& y
+i
->h
>=cy1
&& y
<=cy2
) {
163 byte
*p
= (byte
*)i
+ sizeof(vgaimg
);
164 for (ly
=0; ly
<i
->h
; ly
++) {
165 for(lx
=0; lx
<i
->w
; lx
++) {
167 rx
= (d
& 1) ? (i
->w
-lx
-1) : (rx
=lx
);
168 ry
= (d
& 2) ? (i
->h
-ly
-1) : (ry
=ly
);
171 if (c
) if (t
>=0x70 && t
<=0x7F) t
=t
-0x70+c
;
172 putpixel(x
+rx
,y
+ry
,t
);
180 void V_rotspr (int x
, int y
, vgaimg
* i
, int d
) {
186 void V_pic (short x
, short y
, vgaimg
*i
) {
187 draw_spr(x
, y
, i
, 0, 0);
190 void V_manspr (int x
, int y
, void *p
, unsigned char c
) {
191 draw_spr(x
, y
, p
, 0, c
);
194 void V_manspr2(int x
,int y
,void *p
, unsigned char c
) {
195 draw_spr(x
, y
, p
, 1, c
);
198 // вывести точку цвета c в координатах (x,y)
199 void V_dot (short x
,short y
, unsigned char c
) {
203 void smoke_sprf (int x
, int y
, byte c
) {
204 byte t
= getpixel(x
,y
);
208 putpixel(x
,y
,mixmap
[c
][t
]);
211 void flame_sprf (int x
, int y
, byte c
) {
212 byte t
= getpixel(x
,y
);
214 putpixel(x
,y
,flametab
[c
]);
217 void V_sprf (short x
,short y
,vgaimg
*i
,spr_f
*f
) {
224 for (cy
=y
; cy
<y
+i
->h
; cy
++) {
225 for(cx
=x
; cx
<x
+i
->w
; cx
++) {
234 void V_spr (short x
, short y
, vgaimg
*i
) {
235 draw_spr(x
, y
, i
, 0, 0);
238 void V_spr2 (short x
, short y
, vgaimg
*i
) {
242 void V_clr (short x
, short w
, short y
, short h
, unsigned char c
) {
243 draw_rect(x
, y
, w
, h
, c
);
246 // установить n цветов, начиная с f, из массива p
247 static void VP_set (void *p
, short f
, short n
) {
248 byte
*ptr
= (byte
*)p
;
249 SDL_Color colors
[256];
253 colors
[i
].r
=ptr
[0]*4;
254 colors
[i
].g
=ptr
[1]*4;
255 colors
[i
].b
=ptr
[2]*4;
258 SDL_SetPalette(screen
, SDL_LOGPAL
|SDL_PHYSPAL
, colors
, f
, n
);
261 // установить палитру из массива p
262 void VP_setall (void *p
) {
266 // установить адрес экранного буфера
267 // NULL - реальный экран
268 void V_setscr (void *p
) {
269 if (screen
) SDL_Flip(screen
);
272 // скопировать прямоугольник на экран
273 void V_copytoscr (short x
, short w
, short y
, short h
) {
274 x
*=HQ
; y
*=HQ
; w
*=HQ
; h
*=HQ
;
275 SDL_UpdateRect(screen
, x
, y
, w
, h
);
278 void V_maptoscr (int x
, int w
, int y
, int h
, void *cmap
) {
280 for (cx
=x
; cx
<x
+w
; cx
++)
281 for (cy
=y
; cy
<y
+h
; cy
++)
282 mappixel(cx
,cy
,(byte
*)cmap
);
283 V_copytoscr(x
,w
,y
,h
);
286 void V_remap_rect (int x
, int y
, int w
, int h
, byte
*cmap
) {
288 for (cx
=x
; cx
<x
+w
; cx
++)
289 for (cy
=y
; cy
<y
+h
; cy
++)
290 mappixel(cx
,cy
,cmap
);
293 void V_toggle (void) {
294 if (!SDL_WM_ToggleFullScreen(screen
)) {
295 int ncolors
= screen
->format
->palette
->ncolors
;
296 SDL_Color colors
[256];
298 for (i
=0; i
<ncolors
; i
++) {
299 colors
[i
].r
= screen
->format
->palette
->colors
[i
].r
;
300 colors
[i
].g
= screen
->format
->palette
->colors
[i
].g
;
301 colors
[i
].b
= screen
->format
->palette
->colors
[i
].b
;
304 Uint32 flags
= screen
->flags
;
306 SDL_FreeSurface(screen
);
308 screen
= SDL_SetVideoMode(0, 0, 0, flags
^ SDL_FULLSCREEN
);
310 ERR_fatal("Unable to set video mode\n");
314 SDL_SetPalette(screen
, SDL_LOGPAL
|SDL_PHYSPAL
, colors
, 0, ncolors
);