+ /* render box bounds. y does not need modification, but x and width must be multiple of 4 */\r
+ if (x >= overdraw) rx = (x - overdraw) & (~3);\r
+ else rx = 0;\r
+ if (y >= overdraw) ry = (y - overdraw);\r
+ else ry = 0;\r
+ h = vrl_header->height + overdraw + y - ry;\r
+ w = (x + vrl_header->width + (overdraw*2) + 3/*round up*/ - rx) & (~3);\r
+ if ((rx+w) > vga_state.vga_width) w = vga_state.vga_width-rx;\r
+ if ((ry+h) > vga_state.vga_height) h = vga_state.vga_height-ry;\r
+\r
+ /* replace VGA stride with our own and mem ptr. then sprite rendering at this stage is just (0,0) */\r
+ vga_state.vga_draw_stride_limit = (vga_state.vga_width + 3/*round up*/ - x) >> 2;\r
+ vga_state.vga_draw_stride = w >> 2;\r
+ vga_state.vga_graphics_ram = omemptr + offscreen_ofs;\r
+\r
+ /* first draw pattern corresponding to that part of the screen. this COULD be optimized, obviously, but it's designed for study.\r
+ * also note we don't have to use the same stride as the display! */\r
+ for (i=rx;i < (rx+w);i++) {\r
+ o = (i-rx) >> 2;\r
+ vga_write_sequencer(0x02/*map mask*/,1 << (i&3));\r
+ for (j=ry;j < (ry+h);j++,o += vga_state.vga_draw_stride)\r
+ vga_state.vga_graphics_ram[o] = (i^j)&15; // VRL samples put all colors in first 15!\r
+ }\r
+\r
+ /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */\r
+ draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));\r
+\r
+ /* restore ptr */\r
+ vga_state.vga_graphics_ram = omemptr;\r
+\r
+ /* block copy to visible RAM from offscreen */\r
+ vga_setup_wm1_block_copy();\r
+ o = offscreen_ofs; // source offscreen\r
+ o2 = (ry * vga_state.vga_stride) + (rx >> 2); // dest visible (original stride)\r
+ for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += vga_state.vga_stride) vga_wm1_mem_block_copy(o2,o,w >> 2);\r
+ /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */\r
+ vga_restore_rm0wm0();\r
+\r
+ /* restore stride */\r
+ vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = vga_state.vga_stride;\r
+\r
+ /* step */\r
+ x += xdir;\r
+ y += ydir;\r
+ if (x >= (vga_state.vga_width - 1) || x == 0)\r
+ xdir = -xdir;\r
+ if (y >= (vga_state.vga_height - 1) || y == 0)\r
+ ydir = -ydir;\r
+ }\r