- unsigned int x = screen_x % (22 * TILEX);
- unsigned int y = screen_y % (14 * TILEY);
-
- xdebug("blitscreen");
-
-#if 0
- printf("::: %d, %d [%d, %d]\n", x, y, TILEX, TILEY);
-#endif
-
- if (x < 2 * TILEX && y < 2 * TILEY) {
-
-#if 0
- printf("!!! %ld, %ld, %ld, %ld\n",
- display, screenPixmap, xwindow, screenGC);
-#endif
-
- XCopyArea(display, screenPixmap, xwindow, screenGC, x, y, 20 * TILEX, 12 * TILEY, SX, SY);
- } else if (x < 2 * TILEX && y >= 2 * TILEY) {
- XCopyArea(display, screenPixmap, xwindow, screenGC, x, y, 20 * TILEX, 14 * TILEY - y, SX, SY);
- XCopyArea(display, screenPixmap, xwindow, screenGC, x, 0, 20 * TILEX, y - 2 * TILEY, SX, SY + 14 * TILEY - y);
- } else if (x >= 2 * TILEX && y < 2 * TILEY) {
- XCopyArea(display, screenPixmap, xwindow, screenGC, x, y, 22 * TILEX - x, 12 * TILEY, SX, SY);
- XCopyArea(display, screenPixmap, xwindow, screenGC, 0, y, x - 2 * TILEX, 12 * TILEY, SX + 22 * TILEX - x, SY);
- } else {
- XCopyArea(display, screenPixmap, xwindow, screenGC, x, y, 22 * TILEX - x, 14 * TILEY - y, SX, SY);
- XCopyArea(display, screenPixmap, xwindow, screenGC, 0, y, x - 2 * TILEX, 14 * TILEY - y, SX + 22 * TILEX - x, SY);
- XCopyArea(display, screenPixmap, xwindow, screenGC, x, 0, 22 * TILEX - x, y - 2 * TILEY, SX, SY + 14 * TILEY - y);
- XCopyArea(display, screenPixmap, xwindow, screenGC, 0, 0, x - 2 * TILEX, y - 2 * TILEY, SX + 22 * TILEX - x, SY + 14 * TILEY - y);
- }
+ /* blit all (up to four) parts of the scroll buffer to the target bitmap */
+
+ int x = screen_x % (MAX_BUF_XSIZE * TILEX);
+ int y = screen_y % (MAX_BUF_YSIZE * TILEY);
+ int xsize = SXSIZE;
+ int ysize = SYSIZE;
+ int full_xsize = lev.width * TILEX;
+ int full_ysize = lev.height * TILEY;
+ int sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0);
+ int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
+ int sxsize = (full_xsize < xsize ? full_xsize : xsize);
+ int sysize = (full_ysize < ysize ? full_ysize : ysize);
+
+ if (x < 2 * TILEX && y < 2 * TILEY)
+ {
+ BlitBitmap(screenBitmap, target_bitmap, x, y,
+ sxsize, sysize, sx, sy);
+ }
+ else if (x < 2 * TILEX && y >= 2 * TILEY)
+ {
+ BlitBitmap(screenBitmap, target_bitmap, x, y,
+ sxsize, MAX_BUF_YSIZE * TILEY - y,
+ sx, sy);
+ BlitBitmap(screenBitmap, target_bitmap, x, 0,
+ sxsize, y - 2 * TILEY,
+ sx, sy + MAX_BUF_YSIZE * TILEY - y);
+ }
+ else if (x >= 2 * TILEX && y < 2 * TILEY)
+ {
+ BlitBitmap(screenBitmap, target_bitmap, x, y,
+ MAX_BUF_XSIZE * TILEX - x, sysize,
+ sx, sy);
+ BlitBitmap(screenBitmap, target_bitmap, 0, y,
+ x - 2 * TILEX, sysize,
+ sx + MAX_BUF_XSIZE * TILEX - x, sy);
+ }
+ else
+ {
+ BlitBitmap(screenBitmap, target_bitmap, x, y,
+ MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
+ sx, sy);
+ BlitBitmap(screenBitmap, target_bitmap, 0, y,
+ x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
+ sx + MAX_BUF_XSIZE * TILEX - x, sy);
+ BlitBitmap(screenBitmap, target_bitmap, x, 0,
+ MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
+ sx, sy + MAX_BUF_YSIZE * TILEY - y);
+ BlitBitmap(screenBitmap, target_bitmap, 0, 0,
+ x - 2 * TILEX, y - 2 * TILEY,
+ sx + MAX_BUF_XSIZE * TILEX - x, sy + MAX_BUF_YSIZE * TILEY - y);
+ }
+}
+
+void BackToFront_EM(void)
+{
+ BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
+}
+
+static struct GraphicInfo_EM *getObjectGraphic(int x, int y)
+{
+ int tile = Draw[y][x];
+ struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
+
+ if (!game.use_native_emc_graphics_engine)
+ getGraphicSourceObjectExt_EM(g, tile, 7 - frame, x - 2, y - 2);
+
+ return g;
+}
+
+static struct GraphicInfo_EM *getPlayerGraphic(int player_nr, int anim)
+{
+ struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
+
+ if (!game.use_native_emc_graphics_engine)
+ getGraphicSourcePlayerExt_EM(g, player_nr, anim, 7 - frame);
+
+ return g;
+}
+
+static void DrawLevelField_EM(int x, int y, int sx, int sy,
+ boolean draw_masked)
+{
+ struct GraphicInfo_EM *g = getObjectGraphic(x, y);
+ int src_x = g->src_x + g->src_offset_x * TILESIZE_VAR / TILESIZE;
+ int src_y = g->src_y + g->src_offset_y * TILESIZE_VAR / TILESIZE;
+ int dst_x = sx * TILEX + g->dst_offset_x * TILESIZE_VAR / TILESIZE;
+ int dst_y = sy * TILEY + g->dst_offset_y * TILESIZE_VAR / TILESIZE;
+ int width = g->width * TILESIZE_VAR / TILESIZE;
+ int height = g->height * TILESIZE_VAR / TILESIZE;
+ int left = screen_x / TILEX;
+ int top = screen_y / TILEY;
+
+ /* do not draw fields that are outside the visible screen area */
+ if (x < left || x >= left + MAX_BUF_XSIZE ||
+ y < top || y >= top + MAX_BUF_YSIZE)
+ return;
+
+ if (draw_masked)
+ {
+ if (width > 0 && height > 0)
+ BlitBitmapMasked(g->bitmap, screenBitmap,
+ src_x, src_y, width, height, dst_x, dst_y);
+ }
+ else
+ {
+ if ((width != TILEX || height != TILEY) && !g->preserve_background)
+ ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
+
+ if (width > 0 && height > 0)
+ BlitBitmap(g->bitmap, screenBitmap,
+ src_x, src_y, width, height, dst_x, dst_y);
+ }
+}
+
+static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
+ int crm, boolean draw_masked)
+{
+ struct GraphicInfo_EM *g;
+ int crumbled_border_size;
+ int left = screen_x / TILEX;
+ int top = screen_y / TILEY;
+ int i;
+
+ /* do not draw fields that are outside the visible screen area */
+ if (x < left || x >= left + MAX_BUF_XSIZE ||
+ y < top || y >= top + MAX_BUF_YSIZE)
+ return;
+
+ if (crm == 0) /* no crumbled edges for this tile */
+ return;
+
+ g = getObjectGraphic(x, y);
+
+ crumbled_border_size =
+ g->crumbled_border_size * TILESIZE_VAR / g->crumbled_tile_size;
+
+ for (i = 0; i < 4; i++)
+ {
+ if (crm & (1 << i))
+ {
+ int width, height, cx, cy;
+
+ if (i == 1 || i == 2)
+ {
+ width = crumbled_border_size;
+ height = TILEY;
+ cx = (i == 2 ? TILEX - crumbled_border_size : 0);
+ cy = 0;
+ }
+ else
+ {
+ width = TILEX;
+ height = crumbled_border_size;
+ cx = 0;
+ cy = (i == 3 ? TILEY - crumbled_border_size : 0);
+ }
+
+ if (width > 0 && height > 0)
+ {
+ int src_x = g->crumbled_src_x + cx;
+ int src_y = g->crumbled_src_y + cy;
+ int dst_x = sx * TILEX + cx;
+ int dst_y = sy * TILEY + cy;
+
+ if (draw_masked)
+ BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
+ src_x, src_y, width, height, dst_x, dst_y);
+ else
+ BlitBitmap(g->crumbled_bitmap, screenBitmap,
+ src_x, src_y, width, height, dst_x, dst_y);
+ }
+ }
+ }
+}
+
+static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
+ boolean draw_masked)
+{
+ struct GraphicInfo_EM *g = getPlayerGraphic(player_nr, anim);
+ int src_x = g->src_x, src_y = g->src_y;
+ int dst_x, dst_y;