1 // Emacs style mode select -*- C++ -*-
2 //---------------------------------------------------------------------------
3 //
4 // $Id: vid_vga.c,v 1.1.1.1 2003/02/14 19:03:34 fraggle Exp $
5 //
6 // Copyright(C) 2001-2003 Simon Howard
7 //
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2 of the License, or (at your
11 // option) any later version. This program is distributed in the hope that
12 // it will be useful, but WITHOUT ANY WARRANTY; without even the implied
13 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 // the GNU General Public License for more details. You should have
15 // received a copy of the GNU General Public License along with this
16 // program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 // Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 //---------------------------------------------------------------------------
20 //
21 // Graphics backend for 8-bit (VGA) displays
22 //
23 //---------------------------------------------------------------------------
24
25 #include <string.h>
26
27 #include "video.h"
28 #include "sw.h"
29 #include "swdisp.h"
30 #include "swground.h"
31 #include "swgrpha.h"
32 #include "swmain.h"
33 #include "swsymbol.h"
34 #include "swutil.h"
35
36 // this should be in a header somewhere
37 #define SBAR_HGHT 19
38
39 #define VRAMSIZE (SCR_HGHT * vid_pitch)
40
41 static unsigned char *dispoff = NULL; // current display offset
42
43 unsigned char *vid_vram;
44 unsigned int vid_pitch;
45
46 // sdh 28/10/2001: moved auxdisp here
47
48 unsigned char *auxdisp = NULL;
49
50 /*---------------------------------------------------------------------------
51
52 Update display of ground. Delete previous display of ground by
53 XOR graphics.
54
55 Different routines are used to display/delete ground on colour
56 or monochrome systems.
57
58 ---------------------------------------------------------------------------*/
59
60
Vid_DispGround(GRNDTYPE * gptr)61 void Vid_DispGround(GRNDTYPE *gptr)
62 {
63 register GRNDTYPE *g = gptr;
64 register unsigned char *sptr;
65 register int x, y;
66 register int gc, gl;
67
68 gl = *g;
69
70 sptr = dispoff + (SCR_HGHT-1 - gl) * vid_pitch;
71
72 for (x=SCR_WDTH, g = gptr; x>0; --x) {
73 gc = *g++;
74 if (gl == gc) {
75 *sptr ^= 3;
76 } else if (gc < gl) {
77 for (y = gl - gc; y; --y) {
78 *sptr ^= 3;
79 sptr += vid_pitch;
80 }
81 } else {
82 for (y = gc - gl; y; --y) {
83 *sptr ^= 3;
84 sptr -= vid_pitch;
85 }
86 }
87 gl = gc;
88 ++sptr;
89 }
90 }
91
92
93 // sdh 28/10/2001: solid ground function
94
Vid_DispGround_Solid(GRNDTYPE * gptr)95 void Vid_DispGround_Solid(GRNDTYPE * gptr)
96 {
97 register GRNDTYPE *g = gptr;
98 register unsigned char *sptr;
99 register int x, y;
100 register int gc, gl;
101
102 gl = *g;
103
104 for (x=0, g = gptr; x<SCR_WDTH; ++x) {
105 gc = *g++;
106
107 sptr = dispoff + (SCR_HGHT-SBAR_HGHT-1) * vid_pitch + x;
108
109 for (y = gc-SBAR_HGHT+1; y; --y) {
110 *sptr ^= 3;
111 sptr -= vid_pitch;
112 }
113 }
114 }
115
116
117 /*---------------------------------------------------------------------------
118
119 External calls to display a point of a specified colour at a
120 specified position. The point request may or may not ask for
121 collision detection by returning the old colour of the point.
122
123 Different routines are used to display points on colour or
124 monochrome systems.
125
126 ---------------------------------------------------------------------------*/
127
Vid_PlotPixel(int x,int y,int clr)128 void Vid_PlotPixel(int x, int y, int clr)
129 {
130 register unsigned char *sptr
131 = dispoff + (SCR_HGHT-1 - y) * vid_pitch + x;
132
133 *sptr = clr & 3;
134 }
135
Vid_XorPixel(int x,int y,int clr)136 void Vid_XorPixel(int x, int y, int clr)
137 {
138 register unsigned char *sptr
139 = dispoff + (SCR_HGHT-1 - y) * vid_pitch + x;
140
141 *sptr ^= clr & 3;
142 }
143
Vid_GetPixel(int x,int y)144 int Vid_GetPixel(int x, int y)
145 {
146 register unsigned char *sptr
147 = dispoff + (SCR_HGHT-1 - y) * vid_pitch + x;
148
149 return *sptr;
150 }
151
152
153 /*---------------------------------------------------------------------------
154
155 Display an object's current symbol at a specified screen location
156 Collision detection may or may not be asked for.
157
158 Different routines are used to display symbols on colour or
159 monochrome systems.
160
161 ---------------------------------------------------------------------------*/
162
163 // sdh 27/7/2002: removed collision detection, this is now done
164 // independently of the drawing code (retcode)
165
Vid_DispSymbol(int x,int y,sopsym_t * symbol,int clr)166 void Vid_DispSymbol(int x, int y, sopsym_t *symbol, int clr)
167 {
168 unsigned char *sptr = dispoff + (SCR_HGHT-1 - y) * vid_pitch + x;
169 unsigned char *data = symbol->data;
170 int x1, y1;
171 int w = symbol->w, h = symbol->h;
172 int wrap = x - SCR_WDTH + w;
173
174 if (w == 1 && h == 1) {
175 Vid_XorPixel(x, y, clr);
176 return;
177 }
178
179 if (wrap > 0) {
180 //wrap += 4;
181 w -= wrap;
182 } else {
183 wrap = 0;
184 }
185
186 if (h > y + 1)
187 h = y + 1;
188
189 if (clr == 2) {
190 for (y1=0; y1<h; ++y1) {
191 unsigned char *sptr2 = sptr;
192 for (x1=0; x1<w; ++x1, ++sptr2) {
193 int i = *data++;
194
195 if (i)
196 *sptr2 ^= i ^ 3;
197 }
198 data += wrap;
199 sptr += vid_pitch;
200 }
201 } else {
202 for (y1=0; y1<h; ++y1) {
203 unsigned char *sptr2 = sptr;
204 for (x1=0; x1<w; ++x1, ++sptr2) {
205 unsigned int i = *data++;
206
207 if (i)
208 *sptr2 ^= i;
209 }
210 data += wrap;
211 sptr += vid_pitch;
212 }
213 }
214 }
215
216 // sdh 27/6/2002: box function for drawing filled boxes
217
Vid_Box(int x,int y,int w,int h,int c)218 void Vid_Box(int x, int y, int w, int h, int c)
219 {
220 unsigned char *p = dispoff + (SCR_HGHT-1-y) * vid_pitch + x;
221
222 for (; h >= 0; --h, p += vid_pitch)
223 memset(p, c, w);
224 }
225
226 /*---------------------------------------------------------------------------
227
228 External calls to specify current video ram as screen ram or
229 auxiliary screen area.
230
231 ---------------------------------------------------------------------------*/
232
Vid_SetBuf()233 void Vid_SetBuf()
234 {
235 dispoff = vid_vram;
236 }
237
Vid_SetBuf_Aux()238 void Vid_SetBuf_Aux()
239 {
240 if (!auxdisp)
241 auxdisp = malloc(VRAMSIZE);
242
243 dispoff = auxdisp;
244 }
245
246 // sdh 28/10/2001: moved various auxdisp functions here:
247
Vid_CopyBuf()248 void Vid_CopyBuf()
249 {
250 memset(vid_vram, 0, VRAMSIZE);
251 memcpy(vid_vram + ((SCR_HGHT-SBAR_HGHT) * vid_pitch),
252 auxdisp + ((SCR_HGHT-SBAR_HGHT) * vid_pitch),
253 SBAR_HGHT*vid_pitch);
254 }
255
256
Vid_ClearBuf()257 void Vid_ClearBuf()
258 {
259 memset(vid_vram, 0, VRAMSIZE);
260 }
261
Vid_ClearBuf_Aux()262 void Vid_ClearBuf_Aux()
263 {
264 if (!auxdisp)
265 auxdisp = malloc(VRAMSIZE);
266
267 memset(auxdisp, 0, VRAMSIZE);
268 }
269
270 //---------------------------------------------------------------------------
271 //
272 // $Log: vid_vga.c,v $
273 // Revision 1.1.1.1 2003/02/14 19:03:34 fraggle
274 // Initial Sourceforge CVS import
275 //
276 //
277 // sdh 14/2/2003: change license header to GPL
278 // sdh 27/7/2002: remove collision detection code
279 // sdh 27/6/2002: move to new sopsym_t for symbols
280 // sdh 25/04/2002: rename vga_{pitch,vram} to vid_{pitch,vram}
281 // sdh 26/03/2002: split off platform specific drawing functions here
282 // replaced amiga drawing functions with these generic
283 // 8 bit ones
284 // sdh 28/10/2001: get_type/set_type removed
285 // sdh 28/10/2001: moved auxdisp and auxdisp functions here
286 // sdh 24/10/2001: fix auxdisp buffer
287 // sdh 21/10/2001: use new obtype_t and obstate_t
288 // sdh 21/10/2001: rearranged headers, added cvs tags
289 // sdh 21/10/2001: added #define for solid ground (sopwith 1 style)
290 // sdh 21/10/2001: reformatted with indent, adjusted some code by hand
291 // to make more readable
292 // sdh 19/10/2001: removed extern definitions, these are in headers now
293 // shuffled some functions round to shut up the compiler
294 // sdh 18/10/2001: converted all functions to ANSI-style arguments
295 //
296 // 87-03-09 Microsoft compiler.
297 // 85-11-05 Atari
298 // 84-06-13 PCjr Speed-up
299 // 84-02-21 Development
300 //
301 //---------------------------------------------------------------------------
302
303