vi.c 22.2 KB
1 2 3 4 5 6 7 8 9 10 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 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 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
#include <sys/types.h>
#ifdef __sgi__
#include <sys/sbd.h>
#endif
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __sgi__
#include <sys/sema.h>
#endif
#include <netinet/in.h>

#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <getopt.h>
#include <math.h>
#include <string.h>

#include "diag.h"
#include "dbg_comm.h"

#define TEST_VI_REG 1
#define TEST_VI_DISPLAY 2

#define NTSC 0
#define PAL 1

#define DEFAULT_START_ADDRESS 0x100000
#define DEFAULT_FORMAT 0
#define DEFAULT_SATURATION 75
#define DEFAULT_VIDEO NTSC
#define STRING_SIZE 80
#define WORD_SIZE 32

/* video formats */
#define VI_NTSC_LPN1 0
#define VI_NTSC_LPF1 1
#define VI_NTSC_LAN1 2
#define VI_NTSC_LAF1 3
#define VI_NTSC_LPN2 4
#define VI_NTSC_LPF2 5
#define VI_NTSC_LAN2 6
#define VI_NTSC_LAF2 7
#define VI_NTSC_HPN1 8
#define VI_NTSC_HPF1 9
#define VI_NTSC_HAN1 10
#define VI_NTSC_HAF1 11
#define VI_NTSC_HPN2 12
#define VI_NTSC_HPF2 13

#define VI_PAL_LPN1  14
#define VI_PAL_LPF1  15
#define VI_PAL_LAN1  16
#define VI_PAL_LAF1  17
#define VI_PAL_LPN2  18
#define VI_PAL_LPF2  19
#define VI_PAL_LAN2  20
#define VI_PAL_LAF2  21
#define VI_PAL_HPN1  22
#define VI_PAL_HPF1  23
#define VI_PAL_HAN1  24
#define VI_PAL_HAF1  25
#define VI_PAL_HPN2  26
#define VI_PAL_HPF2  27

struct DISPLAY_STRUCT {
  char *filename;
  int format;
};

static const struct DISPLAY_STRUCT DISPLAY_LIST_NTSC_75[] = {
  {"colorbar_w320h240s75d16.image", VI_NTSC_LPN1},
  {"colorbar_w320h240s75d16.image", VI_NTSC_LPF1},
  {"colorbar_w320h240s75d16.image", VI_NTSC_LAN1},
  {"colorbar_w320h240s75d16.image", VI_NTSC_LAF1},
  {"colorbar_w320h240s75d32.image", VI_NTSC_LPN2},
  {"colorbar_w320h240s75d32.image", VI_NTSC_LPF2},
  {"colorbar_w320h240s75d32.image", VI_NTSC_LAN2},
  {"colorbar_w320h240s75d32.image", VI_NTSC_LAF2},

  {"colorbar_w640h480s75d16.image", VI_NTSC_HPN1},
  {"colorbar_w640h480s75d16.image", VI_NTSC_HPF1},
  {"colorbar_w640h480s75d16.image", VI_NTSC_HAN1},
  {"colorbar_w640h480s75d16.image", VI_NTSC_HAF1},
  {"colorbar_w640h480s75d32.image", VI_NTSC_HPN2},
  {"colorbar_w640h480s75d32.image", VI_NTSC_HPF2},

  {NULL, 0}
};

static const struct DISPLAY_STRUCT DISPLAY_LIST_PAL_75[] = {
  {"colorbar_w320h240s75d16.image", VI_PAL_LPN1},
  {"colorbar_w320h240s75d16.image", VI_PAL_LPF1},
  {"colorbar_w320h240s75d16.image", VI_PAL_LAN1},
  {"colorbar_w320h240s75d16.image", VI_PAL_LAF1},
  {"colorbar_w320h240s75d32.image", VI_PAL_LPN2},
  {"colorbar_w320h240s75d32.image", VI_PAL_LPF2},
  {"colorbar_w320h240s75d32.image", VI_PAL_LAN2},
  {"colorbar_w320h240s75d32.image", VI_PAL_LAF2},

  {"colorbar_w640h480s75d16.image", VI_PAL_HPN1},
  {"colorbar_w640h480s75d16.image", VI_PAL_HPF1},
  {"colorbar_w640h480s75d16.image", VI_PAL_HAN1},
  {"colorbar_w640h480s75d16.image", VI_PAL_HAF1},
  {"colorbar_w640h480s75d32.image", VI_PAL_HPN2},
  {"colorbar_w640h480s75d32.image", VI_PAL_HPF2},

  {NULL, 0}
};

static const struct DISPLAY_STRUCT DISPLAY_LIST_NTSC_100[] = {
  {"colorbar_w320h240s100d16.image", VI_NTSC_LPN1},
  {"colorbar_w320h240s100d16.image", VI_NTSC_LPF1},
  {"colorbar_w320h240s100d16.image", VI_NTSC_LAN1},
  {"colorbar_w320h240s100d16.image", VI_NTSC_LAF1},
  {"colorbar_w320h240s100d32.image", VI_NTSC_LPN2},
  {"colorbar_w320h240s100d32.image", VI_NTSC_LPF2},
  {"colorbar_w320h240s100d32.image", VI_NTSC_LAN2},
  {"colorbar_w320h240s100d32.image", VI_NTSC_LAF2},

  {"colorbar_w640h480s100d16.image", VI_NTSC_HPN1},
  {"colorbar_w640h480s100d16.image", VI_NTSC_HPF1},
  {"colorbar_w640h480s100d16.image", VI_NTSC_HAN1},
  {"colorbar_w640h480s100d16.image", VI_NTSC_HAF1},
  {"colorbar_w640h480s100d32.image", VI_NTSC_HPN2},
  {"colorbar_w640h480s100d32.image", VI_NTSC_HPF2},

  {NULL, 0}
};

static const struct DISPLAY_STRUCT DISPLAY_LIST_PAL_100[] = {
  {"colorbar_w320h240s100d16.image", VI_PAL_LPN1},
  {"colorbar_w320h240s100d16.image", VI_PAL_LPF1},
  {"colorbar_w320h240s100d16.image", VI_PAL_LAN1},
  {"colorbar_w320h240s100d16.image", VI_PAL_LAF1},
  {"colorbar_w320h240s100d32.image", VI_PAL_LPN2},
  {"colorbar_w320h240s100d32.image", VI_PAL_LPF2},
  {"colorbar_w320h240s100d32.image", VI_PAL_LAN2},
  {"colorbar_w320h240s100d32.image", VI_PAL_LAF2},

  {"colorbar_w640h480s100d16.image", VI_PAL_HPN1},
  {"colorbar_w640h480s100d16.image", VI_PAL_HPF1},
  {"colorbar_w640h480s100d16.image", VI_PAL_HAN1},
  {"colorbar_w640h480s100d16.image", VI_PAL_HAF1},
  {"colorbar_w640h480s100d32.image", VI_PAL_HPN2},
  {"colorbar_w640h480s100d32.image", VI_PAL_HPF2},

  {NULL, 0}
};


static int test_reg(void);
static int test_display(void);

static int init(void);
static int run(TEST_REF *test_ref);
static int display(const char *filename, int format, int start_address);

/* IDE test interface */
static TEST_REF Test_Refs[] = {
  {"VI reg test", TEST_VI_REG, test_reg},
  {"VI display test", TEST_VI_DISPLAY, test_display},
  {"", 0, 0}
};

static int Initialize;
static int Failed;
static int Register_1_Valid, Register_1;
static int Register_2_Valid, Register_2;
static int Register_3_Valid, Register_3;
static int Filename_Valid;
static char Filename[STRING_SIZE];
static int Saturation;
static int Video;

void
vi(void)
{
  int c;
  extern char *optarg;
  extern int optind;

  Initialize = 1;
  Failed = 0;
  Register_1_Valid = 0;
  Register_2_Valid = 0;
  Register_3_Valid = 0;
  Saturation = DEFAULT_SATURATION;
  Video = DEFAULT_VIDEO;

  while ((c = getopt(pGlobalComm->argc, pGlobalComm->argv, "ht:I1:2:3:f:s:v:")) != EOF) {
    switch(c) {

    case 'h':
      dgListSubTests(Test_Refs);
      return;
      
    case 't':
      pGlobalComm->entryNum = -atoi(optarg);
      break;
      
    case 'I':
      Initialize = 0;
      break;

    case 's':
      Saturation = atoi(optarg);
      break;

    case 'v':
      Video = atoi(optarg);
      break;

    case '1':
      Register_1_Valid = 1;
      Register_1 = atoi(optarg);
      break;

    case '2':
      Register_2_Valid = 1;
      Register_2 = atoi(optarg);
      break;

    case '3':
      Register_3_Valid = 1;
      Register_3 = atoi(optarg);
      break;

    case 'f':
      Filename_Valid = 1;
      strncpy(Filename, optarg, STRING_SIZE);
      break;

    default:
      return;
    }
  }

  diaginit(Test_Refs, init, run);

  if (Failed) {
    errlog(INFO, "test %s FAILED", ideTestName);
  } else {
    errlog(INFO, "test %s PASSED", ideTestName);
  }
  return;
}


static int
init(void)
{
  errlog(INFO, "starting test %s", ideTestName);
  return 0;
}


static int
run(TEST_REF *test_ref)
{
  int rc;
  int error_count;

  errlog(INFO, "--- starting subtest %s (%d)", test_ref->name, test_ref->num);

  /* reset the target system, if necessary */
  if (Initialize) {
    errlog(DEBUG, "initializing target");
    dgInitComm();
  }

  if (error_count = test_ref->fnc()) {
    Failed = 1;
    errlog(INFO, "--- subtest %s FAILED, %d failures",
	   test_ref->name, error_count);
  } else {
    errlog(INFO, "--- subtest %s PASSED", test_ref->name);
  }
  return 0;
}


int
test_reg(void) {
  int error_count = 0;

  if (dgTestReg(0x04400000, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400000, 0xffffffff, 0x0001ffff)) error_count++;
  if (dgTestReg(0x04400004, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400004, 0xffffffff, 0x00ffffff)) error_count++;
  if (dgTestReg(0x04400008, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400008, 0xffffffff, 0x00000fff)) error_count++;
  if (dgTestReg(0x0440000c, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x0440000c, 0xffffffff, 0x000003ff)) error_count++;
  if (dgTestReg(0x04400014, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400014, 0xffffffff, 0x3fffffff)) error_count++;
  if (dgTestReg(0x04400018, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400018, 0xffffffff, 0x000003ff)) error_count++;
  if (dgTestReg(0x0440001c, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x0440001c, 0xffffffff, 0x001f0fff)) error_count++;
  if (dgTestReg(0x04400020, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400020, 0xffffffff, 0x0fff0fff)) error_count++;
  if (dgTestReg(0x04400024, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400024, 0xffffffff, 0x03ff03ff)) error_count++;
  if (dgTestReg(0x04400028, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400028, 0xffffffff, 0x03ff03ff)) error_count++;
  if (dgTestReg(0x0440002c, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x0440002c, 0xffffffff, 0x03ff03ff)) error_count++;
  if (dgTestReg(0x04400030, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400030, 0xffffffff, 0x0fff0fff)) error_count++;
  if (dgTestReg(0x04400034, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400034, 0xffffffff, 0x0fff0fff)) error_count++;
  if (dgTestReg(0x04400038, 0x00000000, 0x00000000)) error_count++;
  if (dgTestReg(0x04400038, 0xffffffff, 0x0000007f)) error_count++;
  return error_count;
}


int
test_display(void) {
  int start_address;
  int error_count = 0;

  start_address = Register_1_Valid ? Register_1 : DEFAULT_START_ADDRESS;

  if (Filename_Valid) {
    int format = Register_2_Valid ? Register_2 : DEFAULT_FORMAT;
    return display(Filename, format, start_address);
  } else {
    const struct DISPLAY_STRUCT *display_list;

    if (Saturation == 75)
      if (Video == NTSC) {
	display_list = DISPLAY_LIST_NTSC_75;
	errlog(INFO, "--- NTSC video at 75%% saturation");
      }
      else if (Video == PAL) {
	display_list = DISPLAY_LIST_PAL_75;
	errlog(INFO, "--- PAL video at 75%% saturation");
      }
      else {
	errlog(ERR_SEVERE, "Video must be %0d for NTSC or %0d for PAL - %d",
	       NTSC, PAL, Video);
	return 1;
      }
    else if (Saturation == 100)
      if (Video == NTSC) {
	display_list = DISPLAY_LIST_NTSC_100;
	errlog(INFO, "--- NTSC video at 100%% saturation");
      }
      else if (Video == PAL) {
	display_list = DISPLAY_LIST_PAL_100;
	errlog(INFO, "--- PAL video at 100%% saturation");
      }
      else {
	errlog(ERR_SEVERE, "Video must be %0d for NTSC or %0d for PAL - %d",
	       NTSC, PAL, Video);
	return 1;
      }
    else {
      errlog(ERR_SEVERE, "Saturation must be either 75 or 100 - %0d",
             Saturation);
      return 1;
      }


    errlog (INFO,"Prepare to Observe Color Bars on the Video Monitor");
    while (display_list->filename != NULL) {
      error_count += display(display_list->filename, display_list->format,
			     start_address);
      display_list++;
    }
  }
}

int display(const char *filename,
	    int format,
	    int start_address)
{

  FILE *file_p;
  int frame_width;
  int frame_height;
  int frame_depth;
  int header;
  int c;
  int scanline;
  int address;
  unsigned int pixel;
  unsigned int pixel_word;
  int pixel_count;
  int pixels_per_word;
  unsigned char filepath[256];

  if (commtype == DG_VERILOG) {
    errlog(INFO, "Video display test not supported in verilog.");
    return 0;
  }

  errlog(DEBUG, "loading file %s", filename);

  if (! dgFindFile(filepath, "/PR/diags/vi", filename)) {

    if (! dgFindFile(filepath, "/usr/diags/data", filename)) {

      errlog(ERR_SEVERE, "Could not locate file %s",filename);
    }
  }

  if ((file_p = fopen(filepath, "r")) == NULL) {
    errlog(ERR_SEVERE, "could not open file %s", filepath);
      return 1;
    }

  header = 1;
  while (header) {
    c = fgetc(file_p);
    switch (c) {

    case EOF:
      errlog(ERR_SEVERE, "unexpected EOF on file %s", filename);
      return 1;

    case ' ':
    case '\t':
    case '\n':
      /* skip whitespace */
      break;

    case '#': {
      char command_string[STRING_SIZE];
      /* process commands */
      fscanf(file_p, "%s", command_string);
      if (strcmp(command_string, "width") == 0) {
	fscanf(file_p, "%d", &frame_width);
      }
      else if (strcmp(command_string, "height") == 0) {
	fscanf(file_p, "%d", &frame_height);
      }
      else if (strcmp(command_string, "depth") == 0) {
	fscanf(file_p, "%d", &frame_depth);
      }
      else if (strcmp(command_string, "scanline") == 0) {
	fscanf(file_p, "%d", &scanline);
	header = 0;
      }
      /* scan to end of line */
      while (c != '\n' && c != EOF) {
	c = fgetc(file_p);
      }
      break;
    }

    default:
      errlog(ERR_SEVERE, "unreconized data in file %s", filename);
      return 1;
    }
  }

  /* set the number of pixes per frame buffer word */
  switch (frame_depth) {
  case 16:
    pixels_per_word = 2;
    break;

  case 32:
    pixels_per_word = 1;
    break;

  default:
    errlog(ERR_SEVERE, "unsupported pixel size - %d", frame_depth);
    return 1;
  }
    
  errlog(DEBUG, "width = %d, height = %d, depth = %d, format = %d",
	 frame_width, frame_height, frame_depth, format);

  address = start_address;
  while (c != EOF) {
    c = fgetc(file_p);

    switch (c) {

    case EOF:
    case ' ':
    case '\t':
    case '\n':
      /* skip whitespace */
      break;

    case '#': {
      char command_string[STRING_SIZE];

      /* process imbeaded commands */
      fscanf(file_p, "%s", command_string);
      if (strcmp(command_string, "scanline") == 0) {
	fscanf(file_p, "%d", &scanline);
	pixel_count = pixels_per_word - 1;
	pixel_word = 0;
      }
      /* scan to end of line */
      while (c != '\n' && c != EOF) {
	c = fgetc(file_p);
      }
      break;
    }

    default:
      /* read pixel from file and write to frame buffer */
      ungetc(c, file_p);
      fscanf(file_p, "%x", &pixel);
      pixel_word |= pixel << (pixel_count * (WORD_SIZE / pixels_per_word));
      if (!pixel_count) {
	dgWriteWord(address, pixel_word);
	address += 4;
	pixel_count = pixels_per_word - 1;
	pixel_word = 0;
      } else {
	pixel_count--;
      }
      break;
    }
  }

  fclose(file_p);

  /* program the VI and enable */
  dgWriteWord(0x04400004, start_address);
  dgWriteWord(0x0440000c, 0x000003ff);
  dgWriteWord(0x04400010, 0x00000000);

  /* set ntsc/pal parameters */
  switch (format) {
  case VI_NTSC_LPN1:
  case VI_NTSC_LPF1:
  case VI_NTSC_LAN1:
  case VI_NTSC_LAF1:
  case VI_NTSC_LPN2:
  case VI_NTSC_LPF2:
  case VI_NTSC_LAN2:
  case VI_NTSC_LAF2:
  case VI_NTSC_HPN1:
  case VI_NTSC_HPF1:
  case VI_NTSC_HAN1:
  case VI_NTSC_HAF1:
  case VI_NTSC_HPN2:
  case VI_NTSC_HPF2:
    dgWriteWord(0x04400014, 0x03e52239);
    dgWriteWord(0x0440001c, 0x00000c15);
    dgWriteWord(0x04400020, 0x0c150c15);
    dgWriteWord(0x04400024, 0x007402f4);
    dgWriteWord(0x04400028, 0x002d0207);
    dgWriteWord(0x0440002c, 0x000e0204);
    break;

  case VI_PAL_LPN1:
  case VI_PAL_LPF1:
  case VI_PAL_LAN1:
  case VI_PAL_LAF1:
  case VI_PAL_LPN2:
  case VI_PAL_LPF2:
  case VI_PAL_LAN2:
  case VI_PAL_LAF2:
  case VI_PAL_HPN1:
  case VI_PAL_HPF1:
  case VI_PAL_HAN1:
  case VI_PAL_HAF1:
  case VI_PAL_HPN2:
  case VI_PAL_HPF2:
    dgWriteWord(0x04400014, 0x0404233a);
    dgWriteWord(0x0440001c, 0x00150c69);
    dgWriteWord(0x04400020, 0x0c6f0c6e);
    dgWriteWord(0x04400024, 0x00800300);
    dgWriteWord(0x04400028, 0x005f0239);
    dgWriteWord(0x0440002c, 0x00110267);
    break;
  }

  /* set VI_WIDTH */
  switch (format) {
  case VI_NTSC_LPN1:
  case VI_NTSC_LPF1:
  case VI_NTSC_LAN1:
  case VI_NTSC_LAF1:
  case VI_NTSC_LPN2:
  case VI_NTSC_LPF2:
  case VI_NTSC_LAN2:
  case VI_NTSC_LAF2:
  case VI_PAL_LPN1:
  case VI_PAL_LPF1:
  case VI_PAL_LAN1:
  case VI_PAL_LAF1:
  case VI_PAL_LPN2:
  case VI_PAL_LPF2:
  case VI_PAL_LAN2:
  case VI_PAL_LAF2:
    dgWriteWord(0x04400008, 0x00000140);
    break;

  case VI_NTSC_HPN1:
  case VI_NTSC_HAN1:
  case VI_NTSC_HPN2:
  case VI_PAL_HPN1:
  case VI_PAL_HAN1:
  case VI_PAL_HPN2:
    dgWriteWord(0x04400008, 0x00000500);
    break;

  case VI_NTSC_HPF1:
  case VI_NTSC_HAF1:
  case VI_NTSC_HPF2:
  case VI_PAL_HPF1:
  case VI_PAL_HAF1:
  case VI_PAL_HPF2:
    dgWriteWord(0x04400008, 0x00000280);
    break;
  }

  /* set VI_V_SYNC */
  switch (format) {
  case VI_NTSC_LPN1:
  case VI_NTSC_LAN1:
  case VI_NTSC_LPN2:
  case VI_NTSC_LAN2:
    dgWriteWord(0x04400018, 0x0000020d);
    break;

  case VI_NTSC_LPF1:
  case VI_NTSC_LAF1:
  case VI_NTSC_LPF2:
  case VI_NTSC_LAF2:
  case VI_NTSC_HPN1:
  case VI_NTSC_HAN1:
  case VI_NTSC_HPN2:
  case VI_NTSC_HPF1:
  case VI_NTSC_HAF1:
  case VI_NTSC_HPF2:
    dgWriteWord(0x04400018, 0x0000020c);
    break;

  case VI_PAL_LPN1:
  case VI_PAL_LAN1:
  case VI_PAL_LPN2:
  case VI_PAL_LAN2:
    dgWriteWord(0x04400018, 0x00000271);
    break;

  case VI_PAL_LPF1:
  case VI_PAL_LAF1:
  case VI_PAL_LPF2:
  case VI_PAL_LAF2:
  case VI_PAL_HPN1:
  case VI_PAL_HAN1:
  case VI_PAL_HPN2:
  case VI_PAL_HPF1:
  case VI_PAL_HAF1:
  case VI_PAL_HPF2:
    dgWriteWord(0x04400018, 0x00000270);
    break;
  }

  /* set VI_X_SCALE & VI_Y_SCALE */
  switch (format) {
  case VI_NTSC_LPN1:
  case VI_NTSC_LAN1:
  case VI_NTSC_LPN2:
  case VI_NTSC_LAN2:
  case VI_PAL_LPN1:
  case VI_PAL_LAN1:
  case VI_PAL_LPN2:
  case VI_PAL_LAN2:
    dgWriteWord(0x04400030, 0x00000200);
    dgWriteWord(0x04400034, 0x00000400);
    break;

  case VI_NTSC_LPF1:
  case VI_NTSC_LAF1:
  case VI_NTSC_LPF2:
  case VI_NTSC_LAF2:
  case VI_PAL_LPF1:
  case VI_PAL_LAF1:
  case VI_PAL_LPF2:
  case VI_PAL_LAF2:
    dgWriteWord(0x04400030, 0x00000200);
    dgWriteWord(0x04400034, 0x02000400);
    break;

  case VI_NTSC_HPN1:
  case VI_NTSC_HAN1:
  case VI_NTSC_HPN2:
  case VI_PAL_HPN1:
  case VI_PAL_HAN1:
  case VI_PAL_HPN2:
    dgWriteWord(0x04400030, 0x00000400);
    dgWriteWord(0x04400034, 0x00000400);
    break;

  case VI_NTSC_HPF1:
  case VI_NTSC_HAF1:
  case VI_NTSC_HPF2:
  case VI_PAL_HPF1:
  case VI_PAL_HAF1:
  case VI_PAL_HPF2:
    dgWriteWord(0x04400030, 0x00000400);
    dgWriteWord(0x04400034, 0x02000800);
    break;
  }

  /* set VI_CTRL */
  switch (format) {
  case VI_NTSC_LPN1:
    /* ntsc, 320 x 240, 16 bit, point-sampled, non-interlaced */
    dgWriteWord(0x04400000, 0x0000320e);
    dgWait("vi_ntsc_lpn1 colorbars.");
    break;

  case VI_NTSC_LPF1:
    /* ntsc, 320 x 240, 16 bit, point-sampled, interlaced */
    dgWriteWord(0x04400000, 0x0000324e);
    dgWait("vi_ntsc_lpf1 colorbars.");
    break;

  case VI_NTSC_LAN1:
    /* ntsc, 320 x 240, 16 bit, anti-aliased, non-interlaced */
    dgWriteWord(0x04400000, 0x0000311e);
    dgWait("vi_ntsc_lan1 colorbars.");
    break;

  case VI_NTSC_LAF1:
    /* ntsc, 320 x 240, 16 bit, anti-aliased, interlaced */
    dgWriteWord(0x04400000, 0x0000305e);
    dgWait("vi_ntsc_laf1 colorbars.");
    break;

  case VI_NTSC_LPN2:
    /* ntsc, 320 x 240, 32 bit, point-sampled, non-interlaced */
    dgWriteWord(0x04400000, 0x0000330f);
    dgWait("vi_ntsc_lpn2 colorbars.");
    break;

  case VI_NTSC_LPF2:
    /* ntsc, 320 x 240, 32 bit, point-sampled, interlaced */
    dgWriteWord(0x04400000, 0x0000324f);
    dgWait("vi_ntsc_lpf2 colorbars.");
    break;

  case VI_NTSC_LAN2:
    /* ntsc, 320 x 240, 32 bit, anti-aliased, non-interlaced */
    dgWriteWord(0x04400000, 0x0000301f);
    dgWait("vi_ntsc_lan2 colorbars.");
    break;

  case VI_NTSC_LAF2:
    /* ntsc, 320 x 240, 32 bit, anti-aliased, interlaced */
    dgWriteWord(0x04400000, 0x0000305f);
    dgWait("vi_ntsc_laf2 colorbars.");
    break;

  case VI_NTSC_HPN1:
    /* ntsc, 640 x 480, 16 bit, point-sampled, non-interlaced */
    dgWriteWord(0x04400000, 0x0000334e);
    dgWait("vi_ntsc_hpn1 colorbars.");
    break;

  case VI_NTSC_HPF1:
    /* ntsc, 640 x 480, 16 bit, point-sampled, interlaced */
    dgWriteWord(0x04400000, 0x0000324e);
    dgWait("vi_ntsc_hpf1 colorbars.");
    break;

  case VI_NTSC_HAN1:
    /* ntsc, 640 x 480, 16 bit, anti-aliased, non-interlaced */
    dgWriteWord(0x04400000, 0x0000305e);
    dgWait("vi_ntsc_han1 colorbars.");
    break;

  case VI_NTSC_HAF1:
    /* ntsc, 640 x 480, 16 bit, anti-aliased, interlaced */
    dgWriteWord(0x04400000, 0x0000305e);
    dgWait("vi_ntsc_haf1 colorbars.");
    break;

  case VI_NTSC_HPN2:
    /* ntsc, 640 x 480, 32 bit, point-sampled, non-interlaced */
    dgWriteWord(0x04400000, 0x0000334f);
    dgWait("vi_ntsc_hpn2 colorbars.");
    break;

  case VI_NTSC_HPF2:
    /* ntsc, 640 x 480, 32 bit, point-sampled, interlaced */
    dgWriteWord(0x04400000, 0x0000324f);
    dgWait("vi_ntsc_hpf2 colorbars.");
    break;

  case VI_PAL_LPN1:
    /* pal, 320 x 240, 16 bit, point-sampled, non-interlaced */
    dgWriteWord(0x04400000, 0x0000320e);
    dgWait("vi_pal_lpn1 colorbars.");
    break;

  case VI_PAL_LPF1:
    /* pal, 320 x 240, 16 bit, point-sampled, interlaced */
    dgWriteWord(0x04400000, 0x0000324e);
    dgWait("vi_pal_lpf1 colorbars.");
    break;

  case VI_PAL_LAN1:
    /* pal, 320 x 240, 16 bit, anti-aliased, non-interlaced */
    dgWriteWord(0x04400000, 0x0000311e);
    dgWait("vi_pal_lan1 colorbars.");
    break;

  case VI_PAL_LAF1:
    /* pal, 320 x 240, 16 bit, anti-aliased, interlaced */
    dgWriteWord(0x04400000, 0x0000305e);
    dgWait("vi_pal_laf1 colorbars.");
    break;

  case VI_PAL_LPN2:
    /* pal, 320 x 240, 32 bit, point-sampled, non-interlaced */
    dgWriteWord(0x04400000, 0x0000330f);
    dgWait("vi_pal_lpn2 colorbars.");
    break;

  case VI_PAL_LPF2:
    /* pal, 320 x 240, 32 bit, point-sampled, interlaced */
    dgWriteWord(0x04400000, 0x0000324f);
    dgWait("vi_pal_lpf2 colorbars.");
    break;

  case VI_PAL_LAN2:
    /* pal, 320 x 240, 32 bit, anti-aliased, non-interlaced */
    dgWriteWord(0x04400000, 0x0000301f);
    dgWait("vi_pal_lan2 colorbars.");
    break;

  case VI_PAL_LAF2:
    /* pal, 320 x 240, 32 bit, anti-aliased, interlaced */
    dgWriteWord(0x04400000, 0x0000305f);
    dgWait("vi_pal_laf2 colorbars.");
    break;

  case VI_PAL_HPN1:
    /* pal, 640 x 480, 16 bit, point-sampled, non-interlaced */
    dgWriteWord(0x04400000, 0x0000334e);
    dgWait("vi_pal_hpn1 colorbars.");
    break;

  case VI_PAL_HPF1:
    /* pal, 640 x 480, 16 bit, point-sampled, interlaced */
    dgWriteWord(0x04400000, 0x0000324e);
    dgWait("vi_pal_hpf1 colorbars.");
    break;

  case VI_PAL_HAN1:
    /* pal, 640 x 480, 16 bit, anti-aliased, non-interlaced */
    dgWriteWord(0x04400000, 0x0000305e);
    dgWait("vi_pal_han1 colorbars.");
    break;

  case VI_PAL_HAF1:
    /* pal, 640 x 480, 16 bit, anti-aliased, interlaced */
    dgWriteWord(0x04400000, 0x0000305e);
    dgWait("vi_pal_haf1 colorbars.");
    break;

  case VI_PAL_HPN2:
    /* pal, 640 x 480, 32 bit, point-sampled, non-interlaced */
    dgWriteWord(0x04400000, 0x0000334f);
    dgWait("vi_pal_hpn2 colorbars.");
    break;

  case VI_PAL_HPF2:
    /* pal, 640 x 480, 32 bit, point-sampled, interlaced */
    dgWriteWord(0x04400000, 0x0000324f);
    dgWait("vi_pal_hpf2 colorbars.");
    break;

  default:
    errlog(ERR_SEVERE, "unsupported video format - %d", format);
    return 1;
  }
  return 0;
}