1 #define WIN32_LEAN_AND_MEAN
22 void gr_linear_rep_movsdm(ubyte *src, ubyte *dest, int num_pixels);
24 void show_dd_error(HRESULT hr, char *loc);
25 void GetDDErrorString(HRESULT hr, char *buf, int size);
27 void BlitToPrimary(HDC hSrcDC);
28 void BlitToPrimaryRect(HDC hSrcDC, int x, int y, int w, int h,
33 void mouse_init(void);
36 unsigned char *createdib(void);
38 static unsigned char *backbuffer, *screenbuffer;
39 static int screensize;
40 static HBITMAP screen_bitmap;
42 void arch_init_start()
46 if (FindArg("-memdbg"))
47 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF |
48 /* _CRTDBG_CHECK_CRT_DF | */
49 _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
56 //SetPriorityClass (GetCurrentProcess(),HIGH_PRIORITY_CLASS);
63 printf("arch_init successfully completed\n");
67 int vid_installed = 0;
70 int vid_check_mode(uint32_t mode)
72 if (mode == SM(320, 200))
79 int vid_set_mode(uint32_t mode)
83 if (mode == SM_ORIGINAL)
89 w = 320; r = 320; h = 200; t=BM_LINEAR;//BM_DIRECTX;;
97 if (!(backbuffer = createdib()))
100 gr_init_screen(BM_LINEAR, w, h, 0, 0, w, backbuffer);
102 gamefont_choose_game_font(w,h);
108 int vid_init(int mode)
114 // Only do this function once!
115 if (vid_installed == 1)
119 if ((retcode = vid_set_mode(mode)))
122 // Set flags indicating that this is installed.
128 void gr_upixel( int x, int y )
130 gr_bm_upixel(&grd_curcanv->cv_bitmap, x, y, (unsigned char)COLOR);
132 grs_bitmap * bm = &grd_curcanv->cv_bitmap;
134 //x + bm->bm_x, y + bm->bm_y,
135 //x + bm->bm_x, y + bm->bm_y,
141 void gr_bm_upixel( grs_bitmap * bm, int x, int y, unsigned char color )
146 bm->bm_data[ bm->bm_rowsize*y+x ] = color;
151 unsigned char *p = gr_current_pal + color * 3;
154 //x + bm->bm_x, y + bm->bm_y,
155 //x + bm->bm_x, y + bm->bm_y,
156 (int)bm->bm_data, color);
166 RGBQUAD w32lastrgb[256];
176 for (i = 0; i < 256; i++) {
177 w32lastrgb[i].rgbRed = *p++ * 4;
178 w32lastrgb[i].rgbGreen = *p++ * 4;
179 w32lastrgb[i].rgbBlue = *p++ * 4;
181 hdc = CreateCompatibleDC(NULL);
182 SelectObject(hdc, screen_bitmap);
183 SetDIBColorTable(hdc, 0, 256, w32lastrgb);
189 void show_dd_error(HRESULT hr, char *loc)
196 sprintf(buf + len, "%x", hr);
198 GetDDErrorString(hr, buf + len, sizeof(buf) - len);
203 unsigned char *createdib(void)
209 unsigned char *buffer;
211 if (!(bmHdr = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD))))
214 memset(bmHdr, 0, sizeof(*bmHdr));
215 bmHdr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
216 bmHdr->bmiHeader.biWidth = grd_curscreen->sc_canvas.cv_bitmap.bm_w;
217 bmHdr->bmiHeader.biHeight = -grd_curscreen->sc_canvas.cv_bitmap.bm_h;
218 bmHdr->bmiHeader.biPlanes = 1;
219 bmHdr->bmiHeader.biBitCount = 8;
220 bmHdr->bmiHeader.biCompression = BI_RGB;
223 for (i = 0; i < 256; i++) {
225 ((short *)bmHdr->bmiColors)[i] = i;
227 bmHdr->bmiColors[i].rgbRed = (*p++) << 2;
228 bmHdr->bmiColors[i].rgbGreen = (*p++) << 2;
229 bmHdr->bmiColors[i].rgbBlue = (*p++) << 2;
230 bmHdr->bmiColors[i].rgbReserved = 0;
233 hdc = CreateCompatibleDC(NULL);
234 if (!(screen_bitmap = CreateDIBSection(hdc, bmHdr, DIB_RGB_COLORS,
235 &buffer, NULL, 0))) {
236 int err = GetLastError();
238 sprintf(buf, "CreateDISection():%d", err);
239 MessageBox(g_hWnd, buf, NULL, MB_OK);
246 void Win32_BlitLinearToDirectX_bm(grs_bitmap *bm, int sx, int sy,
247 int w, int h, int dx, int dy, int masked) {
249 unsigned char *src, *dest, *rle_w;
252 dest = backbuffer + dy * 320 + dx;
254 if (bm->bm_flags & BM_FLAG_RLE) {
255 src = bm->bm_data + 4 + bm->bm_h;
256 rle_w = bm->bm_data + 4;
258 src += (int)*rle_w++;
261 gr_rle_expand_scanline_masked(dest, src, sx, sx + w - 1);
262 src += (int)*rle_w++;
267 gr_rle_expand_scanline(dest, src, sx, sx + w - 1);
268 src += (int)*rle_w++;
273 src = bm->bm_data + sy * bm->bm_rowsize + sx;
276 gr_linear_rep_movsdm(src, dest, w);
277 src += bm->bm_rowsize;
282 gr_linear_movsd(src, dest, w);
283 src += bm->bm_rowsize;
288 hdc = CreateCompatibleDC(NULL);
289 SelectObject(hdc, screen_bitmap);
290 SetDIBColorTable(hdc, 0, 256, w32lastrgb);
291 BlitToPrimaryRect(hdc, dx, dy, w, h, grd_curcanv->cv_bitmap.bm_data);
295 void Win32_MakePalVisible(void) {
299 void Win32_InvalidatePages(void) {