matrox_bes.c 20.4 KB
Newer Older
1 2
/*
   (c) Copyright 2000-2002  convergence integrated media GmbH.
3 4
   (c) Copyright 2002-2004  convergence GmbH.

5 6 7
   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>,
8 9 10
              Andreas Hundt <andi@fischlustig.de>,
              Sven Neumann <neo@directfb.org> and
              Ville Syrjl <syrjala@sci.fi>.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#include <sys/mman.h>
#include <fcntl.h>
#include <sys/ioctl.h>

#include <linux/fb.h>

#include <directfb.h>

40 41 42
#include <direct/messages.h>

#include <fusion/shmalloc.h>
43

44
#include <core/accelerators.h>
45 46 47
#include <core/coredefs.h>
#include <core/coretypes.h>
#include <core/gfxcard.h>
48
#include <core/layer_control.h>
49
#include <core/layers.h>
50
#include <core/screen.h>
51 52 53 54
#include <core/surfaces.h>
#include <core/system.h>
#include <core/windows.h>

55
#include <direct/mem.h>
56 57 58 59 60 61 62


#include "regs.h"
#include "mmio.h"
#include "matrox.h"

typedef struct {
63
     CoreLayerRegionConfig config;
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

     /* Stored registers */
     struct {
          /* BES */
          __u32 besGLOBCTL;
          __u32 besA1ORG;
          __u32 besA2ORG;
          __u32 besA1CORG;
          __u32 besA2CORG;
          __u32 besA1C3ORG;
          __u32 besA2C3ORG;
          __u32 besCTL;

          __u32 besCTL_field;

          __u32 besHCOORD;
          __u32 besVCOORD;

          __u32 besHSRCST;
          __u32 besHSRCEND;
          __u32 besHSRCLST;

          __u32 besPITCH;

          __u32 besV1WGHT;
          __u32 besV2WGHT;

          __u32 besV1SRCLST;
          __u32 besV2SRCLST;

          __u32 besVISCAL;
          __u32 besHISCAL;

          __u8  xKEYOPMODE;
     } regs;
} MatroxBesLayerData;

static void bes_set_regs( MatroxDriverData *mdrv, MatroxBesLayerData *mbes,
                          bool onsync );
static void bes_calc_regs( MatroxDriverData *mdrv, MatroxBesLayerData *mbes,
104
                           CoreLayerRegionConfig *config, CoreSurface *surface );
105 106 107 108 109 110 111 112 113 114 115

#define BES_SUPPORTED_OPTIONS   (DLOP_DEINTERLACING | DLOP_DST_COLORKEY)


/**********************/

static int
besLayerDataSize()
{
     return sizeof(MatroxBesLayerData);
}
116

117
static DFBResult
118
besInitLayer( CoreLayer                  *layer,
119
              void                       *driver_data,
120 121 122 123
              void                       *layer_data,
              DFBDisplayLayerDescription *description,
              DFBDisplayLayerConfig      *config,
              DFBColorAdjustment         *adjustment )
124 125 126
{
     MatroxDriverData   *mdrv = (MatroxDriverData*) driver_data;
     volatile __u8      *mmio = mdrv->mmio_base;
127

128
     /* set capabilities and type */
129 130 131 132
     description->caps = DLCAPS_SCREEN_LOCATION | DLCAPS_SURFACE |
                         DLCAPS_BRIGHTNESS | DLCAPS_CONTRAST |
                         DLCAPS_DEINTERLACING | DLCAPS_DST_COLORKEY;
     description->type = DLTF_GRAPHICS | DLTF_VIDEO | DLTF_STILL_PICTURE;
133 134

     /* set name */
135
     snprintf( description->name,
136 137 138
               DFB_DISPLAY_LAYER_DESC_NAME_LENGTH, "Matrox Backend Scaler" );

     /* fill out the default configuration */
139 140 141 142 143 144 145 146
     config->flags       = DLCONF_WIDTH | DLCONF_HEIGHT |
                           DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE |
                           DLCONF_OPTIONS;
     config->width       = 640;
     config->height      = 480;
     config->pixelformat = DSPF_YUY2;
     config->buffermode  = DLBM_FRONTONLY;
     config->options     = DLOP_NONE;
147 148 149

     /* fill out default color adjustment,
        only fields set in flags will be accepted from applications */
150 151 152 153
     adjustment->flags      = DCAF_BRIGHTNESS | DCAF_CONTRAST;
     adjustment->brightness = 0x8000;
     adjustment->contrast   = 0x8000;

154 155
     /* disable backend scaler */
     mga_out32( mmio, 0, BESCTL );
156

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
     /* set defaults */
     mga_out_dac( mmio, XKEYOPMODE, 0x00 ); /* keying off */

     mga_out_dac( mmio, XCOLMSK0RED,   0xFF ); /* full mask */
     mga_out_dac( mmio, XCOLMSK0GREEN, 0xFF );
     mga_out_dac( mmio, XCOLMSK0BLUE,  0xFF );

     mga_out_dac( mmio, XCOLKEY0RED,   0x00 ); /* default to black */
     mga_out_dac( mmio, XCOLKEY0GREEN, 0x00 );
     mga_out_dac( mmio, XCOLKEY0BLUE,  0x00 );

     mga_out32( mmio, 0x80, BESLUMACTL );

     return DFB_OK;
}

static DFBResult
174 175 176 177 178
besTestRegion( CoreLayer                  *layer,
               void                       *driver_data,
               void                       *layer_data,
               CoreLayerRegionConfig      *config,
               CoreLayerRegionConfigFlags *failed )
179 180
{
     MatroxDriverData           *mdrv      = (MatroxDriverData*) driver_data;
181 182 183
     MatroxDeviceData           *mdev      = mdrv->device_data;
     int                         max_width = mdev->g450_matrox ? 2048 : 1024;
     CoreLayerRegionConfigFlags  fail      = 0;
184 185

     if (config->options & ~BES_SUPPORTED_OPTIONS)
186
          fail |= CLRCF_OPTIONS;
187

188
     switch (config->format) {
189
          case DSPF_YUY2:
190 191
          case DSPF_NV12:
          case DSPF_NV21:
192 193 194
               break;

          case DSPF_RGB32:
195 196
               if (!mdev->g450_matrox)
                    max_width = 512;
197 198 199 200 201 202 203 204 205
          case DSPF_ARGB1555:
          case DSPF_RGB16:
          case DSPF_UYVY:
          case DSPF_I420:
          case DSPF_YV12:
               /* these formats are not supported by G200 */
               if (mdrv->accelerator != FB_ACCEL_MATROX_MGAG200)
                    break;
          default:
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
               fail |= CLRCF_FORMAT;
     }

     switch (config->format) {
          case DSPF_I420:
          case DSPF_YV12:
          case DSPF_NV12:
          case DSPF_NV21:
               if (config->height & 1)
                    fail |= CLRCF_HEIGHT;
          case DSPF_YUY2:
          case DSPF_UYVY:
               if (config->width & 1)
                    fail |= CLRCF_WIDTH;
          default:
               break;
222 223 224
     }

     if (config->width > max_width || config->width < 1)
225
          fail |= CLRCF_WIDTH;
226 227

     if (config->height > 1024 || config->height < 1)
228
          fail |= CLRCF_HEIGHT;
229 230 231 232 233 234 235 236 237 238 239

     if (failed)
          *failed = fail;

     if (fail)
          return DFB_UNSUPPORTED;

     return DFB_OK;
}

static DFBResult
240 241 242 243 244 245 246 247
besSetRegion( CoreLayer                  *layer,
              void                       *driver_data,
              void                       *layer_data,
              void                       *region_data,
              CoreLayerRegionConfig      *config,
              CoreLayerRegionConfigFlags  updated,
              CoreSurface                *surface,
              CorePalette                *palette )
248 249 250
{
     MatroxDriverData   *mdrv = (MatroxDriverData*) driver_data;
     MatroxBesLayerData *mbes = (MatroxBesLayerData*) layer_data;
251
     volatile __u8      *mmio = mdrv->mmio_base;
252 253 254 255

     /* remember configuration */
     mbes->config = *config;

256 257 258 259 260 261 262
     /* set main configuration */
     if (updated & (CLRCF_WIDTH | CLRCF_HEIGHT | CLRCF_FORMAT |
                    CLRCF_OPTIONS | CLRCF_DEST | CLRCF_OPACITY | CLRCF_SOURCE))
     {
          bes_calc_regs( mdrv, mbes, config, surface );
          bes_set_regs( mdrv, mbes, true );
     }
263

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
     /* set color key */
     if (updated & CLRCF_DSTKEY) {
          DFBColor key = config->dst_key;

          switch (dfb_primary_layer_pixelformat()) {
               case DSPF_ARGB1555:
                    key.r >>= 3;
                    key.g >>= 3;
                    key.b >>= 3;
                    break;

               case DSPF_RGB16:
                    key.r >>= 3;
                    key.g >>= 2;
                    key.b >>= 3;
                    break;

               default:
                    ;
          }

          mga_out_dac( mmio, XCOLKEY0RED,   key.r );
          mga_out_dac( mmio, XCOLKEY0GREEN, key.g );
          mga_out_dac( mmio, XCOLKEY0BLUE,  key.b );
288 289 290 291 292 293
     }

     return DFB_OK;
}

static DFBResult
294 295 296 297
besRemoveRegion( CoreLayer *layer,
                 void      *driver_data,
                 void      *layer_data,
                 void      *region_data )
298 299 300
{
     MatroxDriverData   *mdrv = (MatroxDriverData*) driver_data;

301 302
     /* disable backend scaler */
     mga_out32( mdrv->mmio_base, 0, BESCTL );
303 304 305 306 307

     return DFB_OK;
}

static DFBResult
308 309 310 311 312 313
besFlipRegion( CoreLayer           *layer,
               void                *driver_data,
               void                *layer_data,
               void                *region_data,
               CoreSurface         *surface,
               DFBSurfaceFlipFlags  flags )
314
{
315 316 317 318 319 320
     MatroxDriverData   *mdrv = (MatroxDriverData*) driver_data;
     MatroxBesLayerData *mbes = (MatroxBesLayerData*) layer_data;

     dfb_surface_flip_buffers( surface, false );

     bes_calc_regs( mdrv, mbes, &mbes->config, surface );
321 322 323
     bes_set_regs( mdrv, mbes, flags & DSFLIP_ONSYNC );

     if (flags & DSFLIP_WAIT)
324
          dfb_screen_wait_vsync( mdrv->primary );
325 326 327 328 329

     return DFB_OK;
}

static DFBResult
330
besSetColorAdjustment( CoreLayer          *layer,
331 332 333 334 335 336
                       void               *driver_data,
                       void               *layer_data,
                       DFBColorAdjustment *adj )
{
     MatroxDriverData *mdrv = (MatroxDriverData*) driver_data;
     volatile __u8    *mmio = mdrv->mmio_base;
337

338 339 340
     mga_out32( mmio, (adj->contrast >> 8) |
                      ((__u8)(((int)adj->brightness >> 8) - 128)) << 16,
                BESLUMACTL );
341

342 343 344 345
     return DFB_OK;
}

static DFBResult
346 347 348 349 350
besSetInputField( CoreLayer *layer,
                  void      *driver_data,
                  void      *layer_data,
                  void      *region_data,
                  int        field )
351 352 353
{
     MatroxDriverData   *mdrv = (MatroxDriverData*) driver_data;
     MatroxBesLayerData *mbes = (MatroxBesLayerData*) layer_data;
354

355 356 357 358
     mbes->regs.besCTL_field = field ? 0x2000000 : 0;

     mga_out32( mdrv->mmio_base,
                mbes->regs.besCTL | mbes->regs.besCTL_field, BESCTL );
359

360 361 362 363 364 365
     return DFB_OK;
}

DisplayLayerFuncs matroxBesFuncs = {
     LayerDataSize:      besLayerDataSize,
     InitLayer:          besInitLayer,
366 367 368 369 370 371

     TestRegion:         besTestRegion,
     SetRegion:          besSetRegion,
     RemoveRegion:       besRemoveRegion,
     FlipRegion:         besFlipRegion,

372
     SetColorAdjustment: besSetColorAdjustment,
373
     SetInputField:      besSetInputField
374 375 376 377 378 379 380 381 382 383 384 385 386 387
};


/* internal */

static void bes_set_regs( MatroxDriverData *mdrv, MatroxBesLayerData *mbes,
                          bool onsync )
{
     int            line = 0;
     volatile __u8 *mmio = mdrv->mmio_base;

     if (!onsync) {
          VideoMode *current_mode = dfb_system_current_mode();

388 389 390 391
          /* FIXME: I don't think this should be NULL ever. */
          if (!current_mode)
               return;

392 393 394 395 396
          line = mga_in32( mmio, MGAREG_VCOUNT ) + 48;

          if (line > current_mode->yres)
               line = current_mode->yres;
     }
397

398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
     mga_out32( mmio, mbes->regs.besGLOBCTL | (line << 16), BESGLOBCTL);

     mga_out32( mmio, mbes->regs.besA1ORG, BESA1ORG );
     mga_out32( mmio, mbes->regs.besA2ORG, BESA2ORG );
     mga_out32( mmio, mbes->regs.besA1CORG, BESA1CORG );
     mga_out32( mmio, mbes->regs.besA2CORG, BESA2CORG );

     if (mdrv->accelerator != FB_ACCEL_MATROX_MGAG200) {
          mga_out32( mmio, mbes->regs.besA1C3ORG, BESA1C3ORG );
          mga_out32( mmio, mbes->regs.besA2C3ORG, BESA2C3ORG );
     }

     mga_out32( mmio, mbes->regs.besCTL | mbes->regs.besCTL_field, BESCTL );

     mga_out32( mmio, mbes->regs.besHCOORD, BESHCOORD );
     mga_out32( mmio, mbes->regs.besVCOORD, BESVCOORD );

     mga_out32( mmio, mbes->regs.besHSRCST, BESHSRCST );
     mga_out32( mmio, mbes->regs.besHSRCEND, BESHSRCEND );
     mga_out32( mmio, mbes->regs.besHSRCLST, BESHSRCLST );

     mga_out32( mmio, mbes->regs.besPITCH, BESPITCH );

     mga_out32( mmio, mbes->regs.besV1WGHT, BESV1WGHT );
     mga_out32( mmio, mbes->regs.besV2WGHT, BESV2WGHT );

     mga_out32( mmio, mbes->regs.besV1SRCLST, BESV1SRCLST );
     mga_out32( mmio, mbes->regs.besV2SRCLST, BESV2SRCLST );

     mga_out32( mmio, mbes->regs.besVISCAL, BESVISCAL );
     mga_out32( mmio, mbes->regs.besHISCAL, BESHISCAL );

     mga_out_dac( mmio, XKEYOPMODE, mbes->regs.xKEYOPMODE );
}

433 434 435 436
static void bes_calc_regs( MatroxDriverData      *mdrv,
                           MatroxBesLayerData    *mbes,
                           CoreLayerRegionConfig *config,
                           CoreSurface           *surface )
437
{
438 439 440 441
     MatroxDeviceData *mdev = mdrv->device_data;
     int cropleft, cropright, croptop, cropbot, croptop_uv;
     int pitch, tmp, hzoom, intrep, field_height;
     DFBRectangle   source, dest;
442 443 444 445
     DFBRegion      dstBox;
     SurfaceBuffer *front_buffer = surface->front_buffer;
     VideoMode     *current_mode = dfb_system_current_mode();

446 447 448 449 450 451 452
     if (!current_mode) {
          current_mode = dfb_system_modes();
          if (!current_mode) {
               D_BUG( "No current and no default mode" );
               return;
          }
     }
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483

     source = config->source;
     dest   = config->dest;

     if (!mdev->g450_matrox && surface->format == DSPF_RGB32)
          dest.w = source.w;

     pitch = front_buffer->video.pitch;

     field_height = surface->height;

     if (config->options & DLOP_DEINTERLACING) {
          field_height /= 2;
          source.y /= 2;
          source.h /= 2;
          pitch    *= 2;
     } else
          mbes->regs.besCTL_field = 0;

     /* calculate destination cropping */
     cropleft  = -dest.x;
     croptop   = -dest.y;
     cropright = dest.x + dest.w - current_mode->xres;
     cropbot   = dest.y + dest.h - current_mode->yres;

     cropleft   = cropleft > 0 ? cropleft : 0;
     croptop    = croptop > 0 ? croptop : 0;
     cropright  = cropright > 0 ? cropright : 0;
     cropbot    = cropbot > 0 ? cropbot : 0;
     croptop_uv = croptop;

484
     /* destination box */
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
     dstBox.x1 = dest.x + cropleft;
     dstBox.y1 = dest.y + croptop;
     dstBox.x2 = dest.x + dest.w - 1 - cropright;
     dstBox.y2 = dest.y + dest.h - 1 - cropbot;

     /* scale crop values to source dimensions */
     if (cropleft)
          cropleft = ((__u64) (source.w << 16) * cropleft / dest.w) & ~0x3;
     if (croptop)
          croptop = ((__u64) (source.h << 16) * croptop / dest.h) & ~0x3;
     if (cropright)
          cropright = ((__u64) (source.w << 16) * cropright / dest.w) & ~0x3;
     if (cropbot)
          cropbot = ((__u64) (source.h << 16) * cropbot / dest.h) & ~0x3;
     if (croptop_uv)
          croptop_uv = ((__u64) ((source.h/2) << 16) * croptop_uv / dest.h) & ~0x3;

502
     /* should horizontal zoom be used? */
503 504 505 506
     if (mdev->g450_matrox)
          hzoom = (1000000/current_mode->pixclock >= 234) ? 1 : 0;
     else
          hzoom = (1000000/current_mode->pixclock >= 135) ? 1 : 0;
507 508 509 510

     /* initialize */
     mbes->regs.besGLOBCTL = 0;

511 512
     /* enable/disable depending on opacity */
     mbes->regs.besCTL = config->opacity ? 1 : 0;
513 514 515 516

     /* pixel format settings */
     switch (surface->format) {
          case DSPF_YV12:
517 518 519 520
               mbes->regs.besGLOBCTL |= BESCORDER;
               /* fall through */

          case DSPF_I420:
521 522 523 524
               mbes->regs.besGLOBCTL |= BESPROCAMP | BES3PLANE;
               mbes->regs.besCTL     |= BESHFEN | BESVFEN | BESCUPS | BES420PL;
               break;

525 526 527 528 529 530 531 532 533
          case DSPF_NV21:
               mbes->regs.besGLOBCTL |= BESCORDER;
               /* fall through */

          case DSPF_NV12:
               mbes->regs.besGLOBCTL |= BESPROCAMP;
               mbes->regs.besCTL     |= BESHFEN | BESVFEN | BESCUPS | BES420PL;
               break;

534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
          case DSPF_UYVY:
               mbes->regs.besGLOBCTL |= BESUYVYFMT;
               /* fall through */

          case DSPF_YUY2:
               mbes->regs.besGLOBCTL |= BESPROCAMP;
               mbes->regs.besCTL     |= BESHFEN | BESVFEN | BESCUPS;
               break;

          case DSPF_ARGB1555:
               mbes->regs.besGLOBCTL |= BESRGB15;
               break;

          case DSPF_RGB16:
               mbes->regs.besGLOBCTL |= BESRGB16;
               break;

          case DSPF_RGB32:
               mbes->regs.besGLOBCTL |= BESRGB32;
               break;

          default:
556
               D_BUG( "unexpected pixelformat" );
557 558 559 560
               return;
     }

     mbes->regs.besGLOBCTL |= 3*hzoom | (current_mode->yres & 0xFFF) << 16;
561 562 563 564 565 566 567 568

     mbes->regs.besPITCH = pitch / DFB_BYTES_PER_PIXEL(surface->format);

     /* buffer offsets */
     mbes->regs.besA1ORG = front_buffer->video.offset +
                           pitch * (source.y + (croptop >> 16));
     mbes->regs.besA2ORG = mbes->regs.besA1ORG +
                           front_buffer->video.pitch;
569 570

     switch (surface->format) {
571 572 573 574 575
          case DSPF_NV12:
          case DSPF_NV21:
               mbes->regs.besA1CORG  = front_buffer->video.offset +
                                       surface->height * front_buffer->video.pitch +
                                       pitch * (source.y/2 + (croptop_uv >> 16));
576
               mbes->regs.besA2CORG  = mbes->regs.besA1CORG +
577
                                       front_buffer->video.pitch;
578 579
               break;

580
          case DSPF_I420:
581
          case DSPF_YV12:
582 583 584 585
               mbes->regs.besA1CORG  = front_buffer->video.offset +
                                       surface->height * front_buffer->video.pitch +
                                       pitch/2 * (source.y/2 + (croptop_uv >> 16));
               mbes->regs.besA2CORG  = mbes->regs.besA1CORG +
586 587
                                       front_buffer->video.pitch/2;

588 589 590
               mbes->regs.besA1C3ORG = mbes->regs.besA1CORG +
                                       surface->height/2 * front_buffer->video.pitch/2;
               mbes->regs.besA2C3ORG = mbes->regs.besA1C3ORG +
591 592 593 594 595 596 597
                                       front_buffer->video.pitch/2;
               break;

          default:
               ;
     }

598 599
     mbes->regs.besHCOORD   = (dstBox.x1 << 16) | dstBox.x2;
     mbes->regs.besVCOORD   = (dstBox.y1 << 16) | dstBox.y2;
600

601 602
     mbes->regs.besHSRCST   = (source.x << 16) + cropleft;
     mbes->regs.besHSRCEND  = ((source.x + source.w - 1) << 16) - cropright;
603 604
     mbes->regs.besHSRCLST  = (surface->width - 1) << 16;

605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
     /* vertical starting weights */
     tmp = croptop & 0xfffc;
     mbes->regs.besV1WGHT = tmp;
     if (tmp >= 0x8000) {
          tmp = tmp - 0x8000;
          /* fields start on the same line */
          if ((source.y + (croptop >> 16)) & 1)
               mbes->regs.besCTL |= BESV1SRCSTP | BESV2SRCSTP;
     } else {
          tmp = 0x10000 | (0x8000 - tmp);
          /* fields start on alternate lines */
          if ((source.y + (croptop >> 16)) & 1)
               mbes->regs.besCTL |= BESV1SRCSTP;
          else
               mbes->regs.besCTL |= BESV2SRCSTP;
620
     }
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
     mbes->regs.besV2WGHT = tmp;

     mbes->regs.besV1SRCLST = mbes->regs.besV2SRCLST =
          field_height - 1 - source.y - (croptop >> 16);

     /* horizontal scaling */
     if (!mdev->g450_matrox && surface->format == DSPF_RGB32) {
          mbes->regs.besHISCAL   = 0x20000 << hzoom;
          mbes->regs.besHSRCST  *= 2;
          mbes->regs.besHSRCEND *= 2;
          mbes->regs.besHSRCLST *= 2;
          mbes->regs.besPITCH   *= 2;
     } else {
          intrep = ((mbes->regs.besCTL & BESHFEN) || (source.w > dest.w)) ? 1 : 0;
          if ((dest.w == source.w) || (dest.w < 2))
               intrep = 0;
          tmp = (((source.w - intrep) << 16) / (dest.w - intrep)) << hzoom;
638 639 640 641
          if (tmp >= (32 << 16))
               tmp = (32 << 16) - 1;
          mbes->regs.besHISCAL = tmp & 0x001ffffc;
     }
642 643 644 645 646 647

     /* vertical scaling */
     intrep = ((mbes->regs.besCTL & BESVFEN) || (source.h > dest.h)) ? 1 : 0;
     if ((dest.h == source.h) || (dest.h < 2))
          intrep = 0;
     tmp = ((source.h - intrep) << 16) / (dest.h - intrep);
648 649 650 651 652 653 654
     if(tmp >= (32 << 16))
          tmp = (32 << 16) - 1;
     mbes->regs.besVISCAL = tmp & 0x001ffffc;

     /* enable color keying? */
     mbes->regs.xKEYOPMODE = (config->options & DLOP_DST_COLORKEY) ? 1 : 0;
}