1 #define WIN32_LEAN_AND_MEAN
27 void gr_linear_rep_movsdm(ubyte *src, ubyte *dest, int num_pixels);
29 void show_dd_error(HRESULT hr, char *loc);
30 void GetDDErrorString(HRESULT hr, char *buf, int size);
32 void BlitToPrimary(HDC hSrcDC);
33 void BlitToPrimaryRect(HDC hSrcDC, int x, int y, int w, int h,
38 void mouse_init(void);
41 unsigned char *createdib(void);
43 static unsigned char *backbuffer, *screenbuffer;
44 static int screensize;
45 static HBITMAP screen_bitmap;
47 void arch_init_start()
51 if (FindArg("-memdbg"))
52 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF |
53 /* _CRTDBG_CHECK_CRT_DF | */
54 _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
63 //SetPriorityClass (GetCurrentProcess(),HIGH_PRIORITY_CLASS);
69 printf("arch_init successfully completed\n");
77 int gr_check_mode(int mode)
79 if (mode == SM_320x200C)
85 int gr_set_mode(int mode)
89 if (mode == SM_ORIGINAL)
95 w = 320; r = 320; h = 200; t=BM_LINEAR;//BM_DIRECTX;;
103 memset( grd_curscreen, 0, sizeof(grs_screen));
104 grd_curscreen->sc_mode = mode;
105 grd_curscreen->sc_w = w;
106 grd_curscreen->sc_h = h;
107 grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
108 gr_init_canvas(&grd_curscreen->sc_canvas, (unsigned char *)BM_D3D_DISPLAY, t, w, h);
109 gr_set_current_canvas(NULL);
112 if (!(backbuffer = createdib()))
115 grd_curscreen->sc_canvas.cv_bitmap.bm_data = backbuffer;
116 grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR;
117 grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
118 grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
119 grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
120 grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
121 grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w;
123 gamefont_choose_game_font(w,h);
128 int gr_init(int mode)
134 // Only do this function once!
138 MALLOC( grd_curscreen,grs_screen,1 );
139 memset( grd_curscreen, 0, sizeof(grs_screen));
142 if ((retcode=gr_set_mode(mode)))
147 // Set all the screen, canvas, and bitmap variables that
148 // aren't set by the gr_set_mode call:
149 grd_curscreen->sc_canvas.cv_color = 0;
150 grd_curscreen->sc_canvas.cv_drawmode = 0;
151 grd_curscreen->sc_canvas.cv_font = NULL;
152 grd_curscreen->sc_canvas.cv_font_fg_color = 0;
153 grd_curscreen->sc_canvas.cv_font_bg_color = 0;
154 gr_set_current_canvas( &grd_curscreen->sc_canvas );
156 // Set flags indicating that this is installed.
162 void gr_upixel( int x, int y )
164 gr_bm_upixel(&grd_curcanv->cv_bitmap, x, y, (unsigned char)COLOR);
166 grs_bitmap * bm = &grd_curcanv->cv_bitmap;
168 //x + bm->bm_x, y + bm->bm_y,
169 //x + bm->bm_x, y + bm->bm_y,
175 void gr_bm_upixel( grs_bitmap * bm, int x, int y, unsigned char color )
180 bm->bm_data[ bm->bm_rowsize*y+x ] = color;
185 unsigned char *p = gr_current_pal + color * 3;
188 //x + bm->bm_x, y + bm->bm_y,
189 //x + bm->bm_x, y + bm->bm_y,
190 (int)bm->bm_data, color);
200 RGBQUAD w32lastrgb[256];
209 for (i = 0; i < 256; i++) {
210 w32lastrgb[i].rgbRed = *p++ * 4;
211 w32lastrgb[i].rgbGreen = *p++ * 4;
212 w32lastrgb[i].rgbBlue = *p++ * 4;
214 hdc = CreateCompatibleDC(NULL);
215 SelectObject(hdc, screen_bitmap);
216 SetDIBColorTable(hdc, 0, 256, w32lastrgb);
222 void show_dd_error(HRESULT hr, char *loc)
229 sprintf(buf + len, "%x", hr);
231 GetDDErrorString(hr, buf + len, sizeof(buf) - len);
236 unsigned char *createdib(void)
242 unsigned char *buffer;
244 if (!(bmHdr = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD))))
247 memset(bmHdr, 0, sizeof(*bmHdr));
248 bmHdr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
249 bmHdr->bmiHeader.biWidth = grd_curscreen->sc_canvas.cv_bitmap.bm_w;
250 bmHdr->bmiHeader.biHeight = -grd_curscreen->sc_canvas.cv_bitmap.bm_h;
251 bmHdr->bmiHeader.biPlanes = 1;
252 bmHdr->bmiHeader.biBitCount = 8;
253 bmHdr->bmiHeader.biCompression = BI_RGB;
256 for (i = 0; i < 256; i++) {
258 ((short *)bmHdr->bmiColors)[i] = i;
260 bmHdr->bmiColors[i].rgbRed = (*p++) << 2;
261 bmHdr->bmiColors[i].rgbGreen = (*p++) << 2;
262 bmHdr->bmiColors[i].rgbBlue = (*p++) << 2;
263 bmHdr->bmiColors[i].rgbReserved = 0;
266 hdc = CreateCompatibleDC(NULL);
267 if (!(screen_bitmap = CreateDIBSection(hdc, bmHdr, DIB_RGB_COLORS,
268 &buffer, NULL, 0))) {
269 int err = GetLastError();
271 sprintf(buf, "CreateDISection():%d", err);
272 MessageBox(g_hWnd, buf, NULL, MB_OK);
279 void Win32_BlitLinearToDirectX_bm(grs_bitmap *bm, int sx, int sy,
280 int w, int h, int dx, int dy, int masked) {
282 unsigned char *src, *dest, *rle_w;
285 dest = backbuffer + dy * 320 + dx;
287 if (bm->bm_flags & BM_FLAG_RLE) {
288 src = bm->bm_data + 4 + bm->bm_h;
289 rle_w = bm->bm_data + 4;
291 src += (int)*rle_w++;
294 gr_rle_expand_scanline_masked(dest, src, sx, sx + w - 1);
295 src += (int)*rle_w++;
300 gr_rle_expand_scanline(dest, src, sx, sx + w - 1);
301 src += (int)*rle_w++;
306 src = bm->bm_data + sy * bm->bm_rowsize + sx;
309 gr_linear_rep_movsdm(src, dest, w);
310 src += bm->bm_rowsize;
315 gr_linear_movsd(src, dest, w);
316 src += bm->bm_rowsize;
321 hdc = CreateCompatibleDC(NULL);
322 SelectObject(hdc, screen_bitmap);
323 SetDIBColorTable(hdc, 0, 256, w32lastrgb);
324 BlitToPrimaryRect(hdc, dx, dy, w, h, grd_curcanv->cv_bitmap.bm_data);
328 void Win32_MakePalVisible(void) {
332 void Win32_InvalidatePages(void) {