+void renderer_finish(void)
+{
+ if (gpu.enhancement_bufer != NULL)
+ munmap(gpu.enhancement_bufer, ENHANCEMENT_BUF_SIZE);
+ gpu.enhancement_bufer = NULL;
+ egpu.enhancement_buf_ptr = NULL;
+}
+
+static __attribute__((noinline)) void
+sync_enhancement_buffers(int x, int y, int w, int h)
+{
+ int xt = egpu.enhancement_x_threshold;
+ u16 *src, *dst;
+ int wb, i;
+
+ w += x & 7;
+ x &= ~7;
+ w = (w + 7) & ~7;
+ if (y + h > 512)
+ h = 512 - y;
+
+ for (i = 0; i < 4 && w > 0; i++) {
+ if (x < 512) {
+ wb = w;
+ if (x + w > 512)
+ wb = 512 - x;
+ src = gpu.vram + xt * i + y * 1024 + x;
+ dst = egpu.enhancement_buf_ptr +
+ (1024*1024 + xt * 2) * i + (y * 1024 + x) * 2;
+ scale2x_tiles8(dst, src, wb / 8, h);
+ }
+
+ x -= xt;
+ if (x < 0) {
+ w += x;
+ x = 0;
+ }
+ }
+}
+