+void blitscreen(void)
+{
+ BackToFront_EM();
+}
+
+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 / TILESIZE;
+
+ 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;
+
+ /* do not draw fields that are outside the visible screen area */
+ if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
+ y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
+ return;
+
+ x1 %= MAX_BUF_XSIZE * TILEX;
+ y1 %= MAX_BUF_YSIZE * TILEY;
+
+ if (draw_masked)
+ {
+ /* draw the player to current location */
+ dst_x = x1;
+ dst_y = y1;
+ BlitBitmapMasked(g->bitmap, screenBitmap,
+ src_x, src_y, TILEX, TILEY, dst_x, dst_y);
+
+ /* draw the player to opposite wrap-around column */
+ dst_x = x1 - MAX_BUF_XSIZE * TILEX;
+ dst_y = y1;
+ BlitBitmapMasked(g->bitmap, screenBitmap,
+ g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
+
+ /* draw the player to opposite wrap-around row */
+ dst_x = x1;
+ dst_y = y1 - MAX_BUF_YSIZE * TILEY;
+ BlitBitmapMasked(g->bitmap, screenBitmap,
+ g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
+ }
+ else
+ {
+ /* draw the player to current location */
+ dst_x = x1;
+ dst_y = y1;
+ BlitBitmap(g->bitmap, screenBitmap,
+ g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
+
+ /* draw the player to opposite wrap-around column */
+ dst_x = x1 - MAX_BUF_XSIZE * TILEX;
+ dst_y = y1;
+ BlitBitmap(g->bitmap, screenBitmap,
+ g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
+
+ /* draw the player to opposite wrap-around row */
+ dst_x = x1;
+ dst_y = y1 - MAX_BUF_YSIZE * TILEY;
+ BlitBitmap(g->bitmap, screenBitmap,
+ g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
+ }
+}