gx.c

Go to the documentation of this file.
00001 #include "Buzz_inc.h"
00002 #include <limits.h>
00003 #include <assert.h>
00004 #include "externs.h"
00005 #include "av.h"
00006 #include "utils.h"
00007 #include <SDL.h>
00008 
00009 extern GXHEADER vhptr;
00010 
00011 int
00012 gxVirtualSize (int mode, int w, int h)
00013 {
00014     return w * h;
00015 }
00016 
00017 int
00018 gxCreateVirtual (int mode, GXHEADER *hp,
00019          int gxVGA_mode, int w, int h)
00020 {
00021     assert(hp);
00022     memset(hp, 0, sizeof *hp);
00023     hp->w = w;
00024     hp->h = h;
00025     hp->vptr = xmalloc(w * h);
00026     return gxSUCCESS;
00027 }
00028 
00029 void
00030 gxDestroyVirtual (GXHEADER *hp)
00031 {
00032     assert(hp);
00033     assert(hp->vptr);
00034     free(hp->vptr);
00035     hp->vptr = NULL;
00036 }
00037 
00038 void
00039 gxGetImage (GXHEADER *hp, int x0, int y0, int x1, int y1, int op)
00040 {
00041     int w, h, from_idx, to_idx, row;
00042 
00043     assert(op == 0);
00044     assert(hp);
00045     assert(0 <= x0 && x0 < MAX_X);
00046     assert(0 <= x1 && x1 < MAX_X);
00047     assert(0 <= y0 && y0 < MAX_Y);
00048     assert(0 <= y1 && y1 < MAX_Y);
00049     assert(x0 <= x1);
00050     assert(y0 <= y0);
00051 
00052     w = x1 - x0 + 1;
00053     h = y1 - y0 + 1;
00054 
00055     assert(w <= hp->w);
00056     assert(h <= hp->h);
00057 
00058     for (row = 0; row < h; row++) {
00059         from_idx = (y0 + row) * MAX_X + x0;
00060         to_idx = row * hp->w;
00061         memcpy(&hp->vptr[to_idx], &screen[from_idx], w);
00062     }
00063 }
00064 
00065 void
00066 gxPutImage (GXHEADER *hp, int mode, int x, int y, int op2)
00067 {
00068     int row, col, from_idx, to_idx;
00069     int clip_x, clip_y;
00070     SDL_Rect r;
00071 
00072     assert(op2 == 0);
00073     assert(hp);
00074     assert(mode == gxSET || mode == gxXOR);
00075     assert(0 <= x && x < MAX_X);
00076     assert(0 <= y && y < MAX_Y);
00077 
00078     clip_y = minn(hp->h + y, MAX_Y) - y;
00079     clip_x = minn(hp->w + x, MAX_X) - x;
00080 
00081     switch (mode) {
00082     case gxSET:
00083         for (row = 0; row < clip_y; row++) {
00084             from_idx = row * hp->w;
00085             to_idx = (y + row) * MAX_X + x;
00086             memcpy(&screen[to_idx], &hp->vptr[from_idx], clip_x);
00087         }
00088         break;
00089     case gxXOR:
00090         for (row = 0; row < clip_y; row++) {
00091             from_idx = row * hp->w;
00092             to_idx = (y + row) * MAX_X + x;
00093             for (col = 0; col < clip_x; col++) {
00094                 screen[to_idx+col] ^= hp->vptr[from_idx+col];
00095             }
00096         }
00097         break;
00098     }
00099 
00100     r.x = x; r.y = y;
00101     r.w = clip_x; r.h = clip_y;
00102     av_need_update(&r);
00103     screen_dirty = 1;
00104 }
00105 
00106 void
00107 gxClearDisplay (int a, int b)
00108 {
00109     SDL_Rect r = {0, 0, MAX_X, MAX_Y};
00110     assert(a == 0 && b == 0);
00111 
00112     memset (screen, 0, MAX_X * MAX_Y);
00113     av_need_update(&r);
00114     screen_dirty = 1;
00115 }
00116 
00117 void
00118 gxVirtualDisplay (GXHEADER *hp,
00119           int from_x, int from_y,
00120           int to_x0, int to_y0,
00121           int to_x1, int to_y1,
00122           int always_zero)
00123 {
00124     int row, from_idx, to_idx;
00125     int width, height;
00126     int clip_x, clip_y;
00127     SDL_Rect r;
00128 
00129     assert(hp);
00130     assert(always_zero == 0);
00131     assert(0 <= from_x && from_x < hp->w);
00132     assert(0 <= from_y && from_y < hp->h);
00133     assert(to_x0 <= to_x1);
00134     assert(to_y0 <= to_y1);
00135     assert(0 <= to_x0 && to_x0 < MAX_X);
00136     assert(0 <= to_x1 && to_x1 < MAX_X);
00137     assert(0 <= to_y0 && to_y0 < MAX_Y);
00138     assert(0 <= to_y1 && to_y1 < MAX_Y);
00139 
00140     width  = to_x1 - to_x0 + 1;
00141     height = to_y1 - to_y0 + 1;
00142 
00143     clip_y = minn(height + to_y0, MAX_Y) - to_y0;
00144     clip_x = minn(width  + to_x0, MAX_X) - to_x0;
00145 
00146     for (row = 0; row < clip_y; row++) {
00147         from_idx = (from_y + row) * hp->w + from_x;
00148         to_idx = (to_y0 + row) * MAX_X + to_x0;
00149         memcpy(&screen[to_idx], &hp->vptr[from_idx], clip_x);
00150     }
00151     r.x = to_x0; r.y = to_y0;
00152     r.w = clip_x; r.h = clip_y;
00153     av_need_update(&r);
00154     screen_dirty = 1;
00155 }
00156 
00157 void
00158 gxDisplayVirtual (int from_x0, int from_y0,
00159           int from_x1, int from_y1,
00160           int always_zero,
00161           GXHEADER *hp,
00162           int to_x, int to_y)
00163 {
00164     int row, from_idx, to_idx;
00165     int width, height;
00166 
00167     assert(hp);
00168     assert(always_zero == 0);
00169     assert(0 <= from_x0 && from_x0 < MAX_X);
00170     assert(0 <= from_x1 && from_x1 < MAX_X);
00171     assert(0 <= from_y0 && from_y0 < MAX_Y);
00172     assert(0 <= from_y1 && from_y1 < MAX_Y);
00173     assert(from_x0 <= from_x1);
00174     assert(from_y0 <= from_y0);
00175     assert(0 <= to_x && to_x < hp->w);
00176     assert(0 <= to_y && to_y < hp->h);
00177 
00178     width  = from_x1 - from_x0 + 1;
00179     height = from_y1 - from_y0 + 1;
00180 
00181     assert(width  <= hp->w);
00182     assert(height <= hp->w);
00183 
00184     for (row = 0; row < height; row++) {
00185         from_idx = (from_y0 + row) * MAX_X + from_x0;
00186         to_idx = (to_y + row) * hp->w + to_x;
00187         memcpy(&hp->vptr[to_idx], &screen[from_idx], width);
00188     }
00189 }
00190 
00191 void
00192 gxSetDisplayPalette (char *pal)
00193 {
00194 }
00195 
00196 void
00197 gxVirtualVirtual (GXHEADER *from,
00198           int from_x1, int from_y1,
00199           int from_x2, int from_y2,
00200           GXHEADER *to,
00201           int to_x, int to_y,
00202           int mode)
00203 {
00204     int w, h;
00205     int row;
00206     int from_idx, to_idx;
00207 
00208     assert(from);
00209     assert(to);
00210     assert(0 <= from_x1 && from_x1 < from->w);
00211     assert(0 <= from_y1 && from_y1 < from->h);
00212     assert(0 <= from_x2 && from_x2 < from->w);
00213     assert(0 <= from_y2 && from_y2 < from->h);
00214     assert(0 <= to_x    && to_x    < to->w);
00215     assert(0 <= to_y    && to_y    < to->h);
00216 
00217     w = from_x2 - from_x1 + 1;
00218     h = from_y2 - from_y1 + 1;
00219 
00220     assert(w <= to->w - to_x);
00221     assert(h <= to->h - to_y);
00222 
00223     for (row = 0; row < h; row++) {
00224         from_idx = (from_y1 + row) * from->w + from_x1;
00225         to_idx = (to_y + row) * to->w + to_x;
00226         memcpy(&to->vptr[to_idx], &from->vptr[from_idx], w);
00227     }
00228 }
00229 
00230 void
00231 gxClearVirtual (GXHEADER *hp, int a)
00232 {
00233     assert(hp);
00234     assert(a == 0);
00235     memset (hp->vptr, 0, hp->w * hp->h);
00236 }
00237 
00238 void
00239 gxVirtualScale (GXHEADER *src, GXHEADER *dest)
00240 {
00241     int dest_row, dest_col, dest_idx;
00242     int src_row, src_col, src_idx;
00243 
00244     for (dest_row = 0; dest_row < dest->h; dest_row++) {
00245         src_row = (dest_row * src->h) / dest->h;
00246 
00247         for (dest_col = 0; dest_col < dest->w; dest_col++) {
00248             src_col  = (dest_col * src->w) / dest->w;
00249 
00250             src_idx  = src_row  * src->w  + src_col;
00251             dest_idx = dest_row * dest->w + dest_col;
00252 
00253             dest->vptr[dest_idx] = src->vptr[src_idx];
00254         }
00255     }
00256 }
00257 
00258 /* vim: set noet ts=4 sw=4 tw=77: */

Generated on Fri Sep 28 00:35:45 2007 for raceintospace by  doxygen 1.5.3