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);
61 //SetPriorityClass (GetCurrentProcess(),HIGH_PRIORITY_CLASS);
68 printf("arch_init successfully completed\n");
76 int gr_check_mode(int mode)
78 if (mode == SM_320x200C)
84 int gr_set_mode(int mode)
88 if (mode == SM_ORIGINAL)
94 w = 320; r = 320; h = 200; t=BM_LINEAR;//BM_DIRECTX;;
102 memset( grd_curscreen, 0, sizeof(grs_screen));
103 grd_curscreen->sc_mode = mode;
104 grd_curscreen->sc_w = w;
105 grd_curscreen->sc_h = h;
106 grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
107 gr_init_canvas(&grd_curscreen->sc_canvas, (unsigned char *)BM_D3D_DISPLAY, t, w, h);
108 gr_set_current_canvas(NULL);
111 if (!(backbuffer = createdib()))
114 grd_curscreen->sc_canvas.cv_bitmap.bm_data = backbuffer;
115 grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR;
116 grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
117 grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
118 grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
119 grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
120 grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w;
122 gamefont_choose_game_font(w,h);
127 int gr_init(int mode)
133 // Only do this function once!
137 MALLOC( grd_curscreen,grs_screen,1 );
138 memset( grd_curscreen, 0, sizeof(grs_screen));
141 if ((retcode=gr_set_mode(mode)))
146 // Set all the screen, canvas, and bitmap variables that
147 // aren't set by the gr_set_mode call:
148 grd_curscreen->sc_canvas.cv_color = 0;
149 grd_curscreen->sc_canvas.cv_drawmode = 0;
150 grd_curscreen->sc_canvas.cv_font = NULL;
151 grd_curscreen->sc_canvas.cv_font_fg_color = 0;
152 grd_curscreen->sc_canvas.cv_font_bg_color = 0;
153 gr_set_current_canvas( &grd_curscreen->sc_canvas );
155 // Set flags indicating that this is installed.
161 void gr_upixel( int x, int y )
163 gr_bm_upixel(&grd_curcanv->cv_bitmap, x, y, (unsigned char)COLOR);
165 grs_bitmap * bm = &grd_curcanv->cv_bitmap;
167 //x + bm->bm_x, y + bm->bm_y,
168 //x + bm->bm_x, y + bm->bm_y,
174 void gr_bm_upixel( grs_bitmap * bm, int x, int y, unsigned char color )
179 bm->bm_data[ bm->bm_rowsize*y+x ] = color;
184 unsigned char *p = gr_current_pal + color * 3;
187 //x + bm->bm_x, y + bm->bm_y,
188 //x + bm->bm_x, y + bm->bm_y,
189 (int)bm->bm_data, color);
199 RGBQUAD w32lastrgb[256];
208 for (i = 0; i < 256; i++) {
209 w32lastrgb[i].rgbRed = *p++ * 4;
210 w32lastrgb[i].rgbGreen = *p++ * 4;
211 w32lastrgb[i].rgbBlue = *p++ * 4;
213 hdc = CreateCompatibleDC(NULL);
214 SelectObject(hdc, screen_bitmap);
215 SetDIBColorTable(hdc, 0, 256, w32lastrgb);
221 void show_dd_error(HRESULT hr, char *loc)
228 sprintf(buf + len, "%x", hr);
230 GetDDErrorString(hr, buf + len, sizeof(buf) - len);
235 unsigned char *createdib(void)
241 unsigned char *buffer;
243 if (!(bmHdr = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD))))
246 memset(bmHdr, 0, sizeof(*bmHdr));
247 bmHdr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
248 bmHdr->bmiHeader.biWidth = grd_curscreen->sc_canvas.cv_bitmap.bm_w;
249 bmHdr->bmiHeader.biHeight = -grd_curscreen->sc_canvas.cv_bitmap.bm_h;
250 bmHdr->bmiHeader.biPlanes = 1;
251 bmHdr->bmiHeader.biBitCount = 8;
252 bmHdr->bmiHeader.biCompression = BI_RGB;
255 for (i = 0; i < 256; i++) {
257 ((short *)bmHdr->bmiColors)[i] = i;
259 bmHdr->bmiColors[i].rgbRed = (*p++) << 2;
260 bmHdr->bmiColors[i].rgbGreen = (*p++) << 2;
261 bmHdr->bmiColors[i].rgbBlue = (*p++) << 2;
262 bmHdr->bmiColors[i].rgbReserved = 0;
265 hdc = CreateCompatibleDC(NULL);
266 if (!(screen_bitmap = CreateDIBSection(hdc, bmHdr, DIB_RGB_COLORS,
267 &buffer, NULL, 0))) {
268 int err = GetLastError();
270 sprintf(buf, "CreateDISection():%d", err);
271 MessageBox(g_hWnd, buf, NULL, MB_OK);
278 void Win32_BlitLinearToDirectX_bm(grs_bitmap *bm, int sx, int sy,
279 int w, int h, int dx, int dy, int masked) {
281 unsigned char *src, *dest, *rle_w;
284 dest = backbuffer + dy * 320 + dx;
286 if (bm->bm_flags & BM_FLAG_RLE) {
287 src = bm->bm_data + 4 + bm->bm_h;
288 rle_w = bm->bm_data + 4;
290 src += (int)*rle_w++;
293 gr_rle_expand_scanline_masked(dest, src, sx, sx + w - 1);
294 src += (int)*rle_w++;
299 gr_rle_expand_scanline(dest, src, sx, sx + w - 1);
300 src += (int)*rle_w++;
305 src = bm->bm_data + sy * bm->bm_rowsize + sx;
308 gr_linear_rep_movsdm(src, dest, w);
309 src += bm->bm_rowsize;
314 gr_linear_movsd(src, dest, w);
315 src += bm->bm_rowsize;
320 hdc = CreateCompatibleDC(NULL);
321 SelectObject(hdc, screen_bitmap);
322 SetDIBColorTable(hdc, 0, 256, w32lastrgb);
323 BlitToPrimaryRect(hdc, dx, dy, w, h, grd_curcanv->cv_bitmap.bm_data);
327 void Win32_MakePalVisible(void) {
331 void Win32_InvalidatePages(void) {