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
37 char fullscreen
= OFF
;
40 byte mixmap
[256][256];
44 static int buf_w
, buf_h
, pitch
;
45 static int offx
, offy
;
46 static int cx1
, cx2
, cy1
, cy2
;
47 static byte flametab
[16] = {
48 0xBC,0xBA,0xB8,0xB6,0xB4,0xB2,0xB0,0xD5,0xD6,0xD7,0xA1,0xA0,0xE3,0xE2,0xE1,0xE0
51 vgaimg
*V_getvgaimg (int id
) {
52 int loaded
= M_was_locked(id
);
53 vgaimg
*v
= M_lock(id
);
54 if (v
!= NULL
&& !loaded
) {
55 v
->w
= short2host(v
->w
);
56 v
->h
= short2host(v
->h
);
57 v
->sx
= short2host(v
->sx
);
58 v
->sy
= short2host(v
->sy
);
63 vgaimg
*V_loadvgaimg (char *name
) {
64 return V_getvgaimg(F_getresid(name
));
68 int flags
= fullscreen
? SYSTEM_USE_FULLSCREEN
: 0;
69 int res
= Y_set_videomode(SCRW
, SCRH
, flags
);
71 ERR_failinit("Unable to set video mode");
73 Y_get_buffer(&buffer
, &buf_w
, &buf_h
, &pitch
);
85 static void draw_rect (int x
, int y
, int w
, int h
, int c
) {
89 int x1
= min(x
+ w
- 1, cx2
);
90 int y1
= min(y
+ h
- 1, cy2
);
92 for (i
= y0
; i
<= y1
; i
++) {
93 memset(&buffer
[i
* pitch
+ x0
], c
, len
);
97 void V_setrect (short x
, short w
, short y
, short h
) {
99 cx2
= min(x
+ w
- 1, SCRW
- 1);
101 cy2
= min(y
+ h
- 1, SCRH
- 1);
104 static void putpixel (int x
, int y
, byte color
) {
105 if (x
>= cx1
&& x
<= cx2
&& y
>= cy1
&& y
<= cy2
) {
106 buffer
[y
* pitch
+ x
] = color
;
110 static byte
getpixel (int x
, int y
) {
111 return x
>= cx1
&& x
<= cx2
&& y
>= cy1
&& y
<= cy2
? buffer
[y
* pitch
+ x
] : 0;
114 static void mappixel (int x
, int y
, byte
*cmap
) {
115 byte c
= getpixel(x
, y
);
116 putpixel(x
, y
, cmap
[c
]);
119 void V_center (int f
) {
121 V_offset(SCRW
/ 2 - 320 / 2, SCRH
/ 2 - 200 / 2);
127 void V_offset (int ox
, int oy
) {
132 static void draw_spr (short x
, short y
, vgaimg
*i
, int d
, int c
) {
136 if (d
& 1) x
=x
-i
->w
+i
->sx
; else x
-=i
->sx
;
137 if (d
& 2) y
=y
-i
->h
+i
->sy
; else y
-=i
->sy
;
138 if(x
+i
->w
>=cx1
&& x
<=cx2
&& y
+i
->h
>=cy1
&& y
<=cy2
) {
140 byte
*p
= (byte
*)i
+ sizeof(vgaimg
);
141 for (ly
=0; ly
<i
->h
; ly
++) {
142 for(lx
=0; lx
<i
->w
; lx
++) {
144 rx
= (d
& 1) ? (i
->w
-lx
-1) : (lx
);
145 ry
= (d
& 2) ? (i
->h
-ly
-1) : (ly
);
148 if (c
) if (t
>=0x70 && t
<=0x7F) t
=t
-0x70+c
;
149 putpixel(x
+rx
,y
+ry
,t
);
157 void V_rotspr (int x
, int y
, vgaimg
* i
, int d
) {
163 void V_pic (short x
, short y
, vgaimg
*i
) {
164 draw_spr(x
, y
, i
, 0, 0);
167 void V_manspr (int x
, int y
, void *p
, unsigned char c
) {
168 draw_spr(x
, y
, p
, 0, c
);
171 void V_manspr2(int x
,int y
,void *p
, unsigned char c
) {
172 draw_spr(x
, y
, p
, 1, c
);
175 void V_dot (short x
, short y
, unsigned char c
) {
179 void smoke_sprf (int x
, int y
, byte c
) {
180 byte t
= getpixel(x
,y
);
184 putpixel(x
,y
,mixmap
[c
][t
]);
187 void flame_sprf (int x
, int y
, byte c
) {
188 byte t
= getpixel(x
,y
);
190 putpixel(x
,y
,flametab
[c
]);
193 void V_sprf (short x
,short y
,vgaimg
*i
,spr_f
*f
) {
200 for (cy
=y
; cy
<y
+i
->h
; cy
++) {
201 for(cx
=x
; cx
<x
+i
->w
; cx
++) {
210 void V_spr (short x
, short y
, vgaimg
*i
) {
211 draw_spr(x
, y
, i
, 0, 0);
214 void V_spr2 (short x
, short y
, vgaimg
*i
) {
218 void V_clr (short x
, short w
, short y
, short h
, unsigned char c
) {
219 draw_rect(x
, y
, w
, h
, c
);
222 void V_setscr (void *p
) {
226 void V_copytoscr (short x
, short w
, short y
, short h
) {
227 Y_repaint_rect(x
, y
, w
, h
);
230 void V_maptoscr (int x
, int w
, int y
, int h
, void *cmap
) {
232 for (cx
=x
; cx
<x
+w
; cx
++)
233 for (cy
=y
; cy
<y
+h
; cy
++)
234 mappixel(cx
,cy
,(byte
*)cmap
);
235 V_copytoscr(x
,w
,y
,h
);
238 void V_remap_rect (int x
, int y
, int w
, int h
, byte
*cmap
) {
240 for (cx
=x
; cx
<x
+w
; cx
++)
241 for (cy
=y
; cy
<y
+h
; cy
++)
242 mappixel(cx
,cy
,cmap
);
245 void V_toggle (void) {
246 fullscreen
= Y_set_fullscreen(!Y_get_fullscreen());