-void DDScrollBuffer_Let_DestXOff(long NewVal)
-{
- mDestXOff = NewVal;
-}
-
-long DDScrollBuffer_Get_DestXOff()
-{
- long DestXOff;
-
- DestXOff = mDestXOff;
-
- return DestXOff;
-}
-
-void DDScrollBuffer_Let_DestYOff(long NewVal)
-{
- mDestYOff = NewVal;
-}
-
-long DDScrollBuffer_Get_DestYOff()
-{
- long DestYOff;
-
- DestYOff = mDestYOff;
-
- return DestYOff;
-}
-
-DirectDrawSurface7 DDScrollBuffer_Get_Surface()
-{
- DirectDrawSurface7 Surface;
-
- Surface = Buffer;
-
- return Surface;
-}
-
-long DDScrollBuffer_Get_Width()
-{
- long Width;
-
- Width = mWidth;
-
- return Width;
-}
-
-int DDScrollBuffer_Get_Height()
-{
- int Height;
-
- Height = mHeight;
-
- return Height;
-}
-
-long DDScrollBuffer_CreateAtSize(long Width, long Height, long hWndViewPort)
-{
- long CreateAtSize;
-
- DDSURFACEDESC2 SD;
-
- CreateAtSize = 0;
- mhWnd = hWndViewPort;
- // Create ScrollBuffer:
- {
- SD.lFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
- SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY;
- // SD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
- SD.LWidth = Width;
- SD.LHeight = Height;
- }
-
- // --- On Error Resume Next
- Buffer = DDraw.CreateSurface(SD);
- if (Err.Number != 0)
- return CreateAtSize;
-
- // --- On Error GoTo 0
-
- mWidth = Width;
- mHeight = Height;
- mScrollX = 0;
- mScrollY = 0;
- CreateAtSize = -1;
-
- return CreateAtSize;
-}
-
-void DDScrollBuffer_Cls(int BackColor)
-{
- RECT EmptyRect;
-
- if (NoDisplayFlag)
- return;
-
- Buffer.BltColorFill(EmptyRect, BackColor);
-}
-
-
-/* copy the entire screen to the window at the scroll position */
-
-void BlitScreenToBitmap_SP(Bitmap *target_bitmap)
-{
- int px = 2 * TILEX + (mScrollX - mScrollX_last) % TILEX;
- int py = 2 * TILEY + (mScrollY - mScrollY_last) % TILEY;
- int sx, sy, sxsize, sysize;
-
-#if 1
- int xsize = SXSIZE;
- int ysize = SYSIZE;
- int full_xsize = (FieldWidth - (menBorder.Checked ? 0 : 1)) * TILEX;
- int full_ysize = (FieldHeight - (menBorder.Checked ? 0 : 1)) * TILEY;
-
- sxsize = (full_xsize < xsize ? full_xsize : xsize);
- sysize = (full_ysize < ysize ? full_ysize : ysize);
- sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0);
- sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
-#endif
-
-#if 0
- {
- static int mScrollX_tmp = -1;
- static int mScrollY_tmp = -1;
-
- if (mScrollX != mScrollX_tmp || mScrollY != mScrollY_tmp)
- {
- printf("::: %ld, %ld\n", mScrollX, mScrollY);
-
- mScrollX_tmp = mScrollX;
- mScrollY_tmp = mScrollY;
- }
- }
-#endif
-
-#if 0
- {
- static boolean x = 0;
-
- if (x == 0)
- {
- printf("::: %d, %d (%d, %d) (%d, %d) [%ld, %ld] [%ld, %ld] \n",
- sx, sy, xsize, ysize, full_xsize, full_ysize,
- mScrollX, mScrollY, mScrollX_last, mScrollY_last);
-
- x = 1;
- }
- }
-#endif
-
-#if 1
- if (!menBorder.Checked)
- {
- px += TILEX / 2;
- py += TILEY / 2;
- }
-#endif
-
-#if 0
- if (mScrollX >= 0 && mScrollX <= 16)
- {
- px -= mScrollX;
- }
-#if 0
- else if (mScrollX >= 352 && mScrollX <= 368)
- {
- px -= mScrollX;
- }
-#endif
- else if (mScrollX >= 16) // && mScrollX <= 352)
- {
- px -= TILEX / 2;
- }
-#endif
-
-#if 0
- /* !!! TEST ONLY !!! */
- px = py = 0;
- sx = sy = SX;
-#endif
-
- BlitBitmap(screenBitmap, target_bitmap, px, py, sxsize, sysize, sx, sy);
-}
-
-void OLD_BlitScreenToBitmap_SP(Bitmap *target_bitmap)
-{
- int x = mScrollX % (MAX_BUF_XSIZE * TILEX);
- int y = mScrollY % (MAX_BUF_YSIZE * TILEY);
-
- if (x < 2 * TILEX && y < 2 * TILEY)
- {
- BlitBitmap(screenBitmap, target_bitmap, x, y,
- SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
- }
- else if (x < 2 * TILEX && y >= 2 * TILEY)
- {
- BlitBitmap(screenBitmap, target_bitmap, x, y,
- SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
- SX, SY);
- BlitBitmap(screenBitmap, target_bitmap, x, 0,
- SCR_FIELDX * TILEX, 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, SCR_FIELDY * TILEY,
- SX, SY);
- BlitBitmap(screenBitmap, target_bitmap, 0, y,
- x - 2 * TILEX, SCR_FIELDY * TILEY,
- 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_SP(void)
-{
- static boolean scrolling_last = FALSE;
- int left = mScrollX / TILEX;
- int top = mScrollY / TILEY;
- boolean scrolling = (mScrollX % TILEX != 0 || mScrollY % TILEY != 0);
- int x, y;
-
- SyncDisplay();
-
- if (1 ||
- redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
- {
-#if 1
- BlitScreenToBitmap_SP(window);
-#else
- /* blit all (up to four) parts of the scroll buffer to the backbuffer */
- BlitScreenToBitmap_SP(backbuffer);
-
- /* blit the completely updated backbuffer to the window (in one blit) */
- BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
-#endif
- }
- else
- {
- for (x = 0; x < SCR_FIELDX; x++)
- {
- for (y = 0; y < SCR_FIELDY; y++)