vimodesplit.c 4.86 KB

/**************************************************************************
 *									  *
 *		 Copyright (C) 1995, Silicon Graphics, Inc.		  *
 *									  *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright law.  They  may  not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *									  *
 **************************************************************************/

/**************************************************************************
 *
 *  Module: vimodesplit.c
 *
 *  $Revision: 1.3 $
 *  $Date: 2002/10/29 08:29:08 $
 *  $Author: blythe $
 *  $Source: /root/leakn64/depot/rf/sw/n64os20l/libultra/monegi/vi/vimodesplit.c,v $
 *
 *  Description:
 *      Utility to split the global osViModeTable structure (in vitbl.c) to
 *	individual .c files, each contains a unique VI mode.
 *
 **************************************************************************/


#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "os.h"

/* 
 * This define needs to change if additional TV types are supported 
 * Currently, only 3 types are listed here: NTSC, PAL, MPAL, FPAL 
 */
#define NUM_TV_TYPE		4	

/*
 * Currently, there are 14 different modes (ie., lan1, lan2) for each
 * different TV type
 */
#define VI_MODE_PER_TV_TYPE	14

typedef struct {
    char *tvType;
    char *partFileName;
    int  numOfModes;
} tvModeStruct ;

tvModeStruct tvModeTable[NUM_TV_TYPE] = {
    { "Ntsc", "vimodentsc", VI_MODE_PER_TV_TYPE },
    { "Pal",  "vimodepal",  VI_MODE_PER_TV_TYPE },
    { "Mpal", "vimodempal", VI_MODE_PER_TV_TYPE },
    { "Fpal", "vimodefpal", VI_MODE_PER_TV_TYPE },
};

/* Extern from vitbl.c */
extern OSViMode osViModeTable[];

static char *
viModeNameTable[VI_MODE_PER_TV_TYPE] = {
    "Lpn1", 
    "Lpf1",
    "Lan1",
    "Laf1",
    "Lpn2",
    "Lpf2",
    "Lan2",
    "Laf2",
    "Hpn1",
    "Hpf1",
    "Han1",
    "Haf1",
    "Hpn2",
    "Hpf2",
};


static char *
str2lower(char *name)
{
    int i;
    static char buf[256];
    char *s = name;

    i = 0;
    while (*s) {
        buf[i++] = tolower(*s++);
    }
    buf[i] = '\0';
    return(buf);

}  /* str2lower */


static void
printHeader(FILE *fp, char *type, char *name, OSViMode *me)
{
    fprintf(fp, "/*\n");
    fprintf(fp, " * VI mode: %s\n", name);
    fprintf(fp, " * Created automatically by vimodesplit utility.\n");
    fprintf(fp, " */\n\n");
    fprintf(fp, "#include \"os.h\"\n");
    fprintf(fp, "#include \"rcp.h\"\n\n");
    fprintf(fp, "OSViMode osViMode%s%s = {\n", type, name);

    fprintf(fp, "\t0x%08x,\t/* type */\n", me->type);

}  /* printHeader */


static void
printCommonRegs(FILE *fp, OSViCommonRegs *cr)
{
    fprintf(fp, "\t/* Common regs */\n");
    fprintf(fp, "\t0x%08x,\t/* ctrl */\t0x%08x,\t/* width      */\n",
            cr->ctrl, cr->width);
    fprintf(fp, "\t0x%08x,\t/* burst */\t0x%08x,\t/* vSync      */\n",
            cr->burst, cr->vSync);
    fprintf(fp, "\t0x%08x,\t/* hSync */\t0x%08x,\t/* leap       */\n",
            cr->hSync, cr->leap);
    fprintf(fp, "\t0x%08x,\t/* hStart */\t0x%08x,\t/* xScale     */\n",
            cr->hStart, cr->xScale);
    fprintf(fp, "\t0x%08x,\t/* vCurrent */\n",
            cr->vCurrent);

}    /* printCommonRegs */


static void
printFieldRegs(FILE *fp, int fieldno, OSViFieldRegs *fr)
{
    fprintf(fp, "\t/* Field %d regs */\n", fieldno);
    fprintf(fp, "\t0x%08x,\t/* origin */\t0x%08x,\t/* yScale     */\n",
            fr->origin, fr->yScale);
    fprintf(fp, "\t0x%08x,\t/* vStart */\t0x%08x,\t/* vBurst     */\n",
            fr->vStart, fr->vBurst);
    fprintf(fp, "\t0x%08x,\t/* vIntr */\n",
            fr->vIntr);
}


main(int argc, char **argv)
{
    FILE *fp;
    int i, j, k;
    char fileName[256];
    register char *name;
    tvModeStruct *tvmp;

    /* Create VI mode files */
    for (i = 0; i < NUM_TV_TYPE; i++) {
        tvmp = &tvModeTable[i];
        for (j = 0; j < tvmp->numOfModes; j++) {
            name = viModeNameTable[j];
            sprintf(fileName, "%s%s.c", tvmp->partFileName, str2lower(name));
#ifdef _DEBUG
            printf("Creating file %s...\n", fileName);
#endif
            fp = fopen(fileName, "w+");
            if (fp == NULL) {
                fprintf(stderr, "ERROR: Unable to create file %s\n", fileName);
                exit(1);
            }

            k = (i*tvmp->numOfModes)+j;
            printHeader(fp, tvmp->tvType, name, &osViModeTable[k]);
            printCommonRegs(fp, &(osViModeTable[k].comRegs));
            printFieldRegs(fp, 1, &(osViModeTable[k].fldRegs[0]));
            printFieldRegs(fp, 2, &(osViModeTable[k].fldRegs[1]));

            fprintf(fp, "};\n\n");

            fclose(fp);

        }  /* for */
    }  /* for */
    return 0;

}  /* main */