- 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++)
- {
- int xx = (left + x) % MAX_BUF_XSIZE;
- int yy = (top + y) % MAX_BUF_YSIZE;
-
- if (redraw[xx][yy])
- BlitBitmap(screenBitmap, window,
- xx * TILEX, yy * TILEY, TILEX, TILEY,
- SX + x * TILEX, SY + y * TILEY);
- }
- }
- }
-
- FlushDisplay();
-
- for (x = 0; x < MAX_BUF_XSIZE; x++)
- for (y = 0; y < MAX_BUF_YSIZE; y++)
- redraw[x][y] = FALSE;
- redraw_tiles = 0;
-
- scrolling_last = scrolling;
-}
-
-
-void DDScrollBuffer_Blt_Ext(Bitmap *target_bitmap)
-{
- MyRECT DR, SR;
-#if 1
- long tX, tY;
-#else
- long tX, tY, L;
-#endif
- int sX, sY;
- // RECT ERect;
- // long Restore;
-
- if (NoDisplayFlag)
- return;
-
-#if 1
- DR.left = 0;
- DR.top = 0;
- DR.right = SCR_FIELDX * TILEX;
- DR.bottom = SCR_FIELDY * TILEY;
-#else
- // --- On Error GoTo BltEH
- DirectX.GetWindowRect(mhWnd, DR);
- // --- On Error GoTo 0
-#endif
-
- {
- tX = (DR.right - DR.left) / Stretch;
- tY = (DR.bottom - DR.top) / Stretch;
- }
-
- {
- SR.left = mScrollX + mDestXOff;
- SR.top = mScrollY + mDestYOff;
-
- SR.right = SR.left + tX;
- SR.bottom = SR.top + tY;
-
- // If mWidth < SR.right Then
- // SR.right = mWidth
- // DR.right = DR.left + Stretch * (SR.right - SR.left)
- // End If
- // If mHeight < SR.bottom Then
- // SR.bottom = mHeight
- // DR.bottom = DR.top + Stretch * (SR.bottom - SR.top)
- // End If
- // If (mScrollX + mDestXOff) < 0 Then
- // SR.left = 0
- // DR.left = DR.left - Stretch * (mScrollX + mDestXOff)
- // End If
- // If (mScrollY + mDestYOff) < 0 Then
- // SR.top = 0
- // DR.top = DR.top - Stretch * (mScrollY + mDestYOff)
- // End If
- }
-
-#if 1
- SR.left = (SR.left < 0 ? 0 : SR.left);
- SR.top = (SR.top < 0 ? 0 : SR.top);
-#endif
-
-#if 1
- {
- int full_xsize = (FieldWidth - (menBorder.Checked ? 0 : 1)) * TILEX;
- int full_ysize = (FieldHeight - (menBorder.Checked ? 0 : 1)) * TILEY;
- int sxsize = SCR_FIELDX * TILEX;
- int sysize = SCR_FIELDY * TILEY;
-
- tX = (full_xsize < sxsize ? full_xsize : tX);
- tY = (full_ysize < sysize ? full_ysize : tY);
- sX = SX + (full_xsize < sxsize ? (sxsize - full_xsize) / 2 : 0);
- sY = SY + (full_ysize < sysize ? (sysize - full_ysize) / 2 : 0);
- }
-#endif
-
-#if 1
- if (!menBorder.Checked)
- {
- SR.left += TILEX / 2;
- SR.top += TILEY / 2;
- }
-#endif
-
-#if 1
-
-#if 1
- printf("::: DDScrollBuffer.c: DDScrollBuffer_Blt(): blit from %d, %d [%ld, %ld] [%ld, %ld] [%ld, %ld]\n",
- SR.left, SR.top, mScrollX, mScrollY, mDestXOff, mDestYOff, tX, tY);
-#endif
-
-#if 0
- /* !!! quick and dirty -- FIX THIS !!! */
- if (tape.playing && tape.fast_forward &&
- target_bitmap == window &&
- (FrameCounter % 2) != 0)
- printf("::: FrameCounter == %d\n", FrameCounter);
-#endif
-
-#if 1
- SyncDisplay();
-#endif
-
-#if 1
- BlitBitmap(screenBitmap, target_bitmap,
- SR.left, SR.top, tX, tY, sX, sY);
-#else
- BlitBitmap(screenBitmap, target_bitmap,
- SR.left, SR.top,
- SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
-#endif
-
-#if 1
- FlushDisplay();
-#endif
-
- return;
-
-#endif
-
- // DDraw.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, 0
- if (IS_NOTHING(&Buffer, sizeof(Buffer)))
- return;
-
-#if 0
- if (IS_NOTHING(&PrimarySurface, sizeof(PrimarySurface)))
- return;
-#endif
-
-#if 0
-
- L = PrimarySurface.Blt(DR, &Buffer, SR, DDBLT_WAIT);
- if (L != DD_OK)
- {
- switch (L)
- {
-#if 0
- case DDERR_GENERIC:
- Debug.Assert(False);
- break;
-
- case DDERR_INVALIDCLIPLIST:
- Debug.Assert(False);
- break;
-
- case DDERR_INVALIDOBJECT:
- Debug.Assert(False);
- break;
-
- case DDERR_INVALIDPARAMS:
- Debug.Assert(False);
- break;
-
- case DDERR_INVALIDRECT:
- Debug.Assert(False);
- break;
-
- case DDERR_NOALPHAHW:
- Debug.Assert(False);
- break;
-
- case DDERR_NOBLTHW:
- Debug.Assert(False);
- break;
-
- case DDERR_NOCLIPLIST:
- Debug.Assert(False);
- break;
-
- case DDERR_NODDROPSHW:
- Debug.Assert(False);
- break;
-
- case DDERR_NOMIRRORHW:
- Debug.Assert(False);
- break;
-
- case DDERR_NORASTEROPHW:
- Debug.Assert(False);
- break;
-
- case DDERR_NOROTATIONHW:
- Debug.Assert(False);
- break;
-
- case DDERR_NOSTRETCHHW:
- Debug.Assert(False);
- break;
-
- case DDERR_NOZBUFFERHW:
- Debug.Assert(False);
- break;
-
- case DDERR_SURFACEBUSY:
- Debug.Assert(False);
- break;
-#endif
-
-#if 0
- case DDERR_SURFACELOST:
- DDraw.RestoreAllSurfaces();
- if (! PrimarySurface.isLost())
- {
- subDisplayLevel();
- // Blt();
- }
-
- // RestorePrimarySurface
- // ClipToWindow 0
- break;
-#endif
-
-#if 0
- case DDERR_UNSUPPORTED:
- Debug.Assert(False);
- break;
-
- case DDERR_WASSTILLDRAWING:
- Debug.Assert(False);
- break;
-
- default:
- Debug.Assert(False);
- break;
-#endif
- }
- }
-
-#endif
-
-#if 0
- // Buffer.UpdateOverlay SR, PrimarySurface, DR, DDOVER_SHOW
- if (EditFlag)
- FMark.RefreshMarker();
-#endif
-
- // BltEH:
-}
-
-void DDScrollBuffer_Blt()
-{
-#if 1
-
-#if 1
- BackToFront_SP();
-#else
- /* !!! TEST ONLY !!! */
- BlitBitmap(screenBitmap, window,
- 0, 0, SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
-#endif
-
-#else
- DDScrollBuffer_Blt_Ext(window);
-#endif