/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* modex.h */

/*
 * Internal definitions used by ScreenModes module.
 */


/*
 * The 6 field framing parameters for each direction, horizontal and
 * vertical.  In horizontal case, the parameters are measured in VIDC
 * pixel times; for vertical, VIDC raster times.
 */
#define FR_SYNC         0               /* sync pulse width */
#define FR_BPCH         1               /* back porch */
#define FR_BDR1         2               /* top (V) / left (H) border height/width */
#define FR_DISP         3               /* active data display height/width  */
#define FR_BDR2         4               /* bottom (V) / right (H) border height/width */
#define FR_FPCH         5               /* front porch */
#define FR__COUNT       6               /* how many parameters altogether */

/*
 * The video control list parameter index for indicating DPMS state
 */

/**Added by WT 13-1-95 for Stork **/
#define LCDMODE_INDEX   01
    #define LCDMODE_VALUE       1       /*Enable*/
#define LCDDUAL_INDEX   02
    #define LCDDUAL_VALUE       1       /*Enable*/
#define LCDOFF0_INDEX   03
    #define LCDOFF0_VALUE       6       /*Defining a 640x480 dual-panel LCD as used in Stork*/
#define LCDOFF1_INDEX   04
    #define LCDOFF1_VALUE       129     /*Defining a 640x480 dual-panel LCD as used in Stork*/
#define DACCTRL_INDEX   06
    #define DACCTRL_VALUE       1       /*Enable - testing only*/
/**End of additions**/

#define DPMS_INDEX       11
#define INTERLACED_INDEX 12


/* Two-word structure in a mode selector or VIDC list */
typedef struct
{
    int32 index;                        /* -1 as index is invalid & marks end of list */
    int32 value;
} ModeParam;

typedef struct
{
    uns32 bit0:1, format:7, flags:24;
    uns32 xresol;
    uns32 yresol;
    uns32 depth;                        /* as log2(bpp) */
    int32 framerate;                    /* in integer Hz */
    ModeParam param[1];                 /* minimum case + 1 word: may be 0 params + 1 term */
} ModeSelector, *ModeSelectorRef;

/* VIDC list as filled in when handling Service_ModeExtension */
typedef struct
{
    uns32 format;                       /* type 3 for Medusa */
    uns32 depth;                        /* log code, 0=1bpp to 5=32bpp */
    uns32 hpar[FR__COUNT];              /* horizontal parameters */
    uns32 vpar[FR__COUNT];              /* vertical parameters */
    uns32 pixelrate;                    /* pixel rate measured in kHz */
    uns32 syncpol:2, :0;                /* sync polarity code, 0..3 */
    ModeParam vcparam[8];               /* Holds VCparameters: LCD mode, LCD dual-panel, LCD offsets(2), DAC control, -1
    					 * with optional DPMS and/or Interlaced fields
    					 */
} VIDCList, *VIDCListRef;

/* Mode information block as filled in when handling Service_EnumerateScreenModes */
typedef struct
{
    uns32 blocksize;                    /* size of this block in bytes */
    uns32 bit0:1, format:7, flags:24;
    uns32 xresol;                       /* user-pixels */
    uns32 yresol;                       /* user-lines */
    uns32 depth;                        /* as log2(bpp) */
    uns32 framerate;                    /* to nearest whole Hz value */
    char name[1];                       /* name starts here (dummy size for struct def) */
} ModeInfoBlock, *ModeInfoBlockRef;

#define IS_MODE_NUMBER(p) ((uns32)(p) < 256)
#define IS_MODE_SEL_PTR(p) (!IS_MODE_NUMBER(p))

#define MODESEL(p) ((ModeSelectorRef)(p))

/*
 * Monitor & modes description as loaded from ModeInfo file: note,
 * this does not include pixel depth.
 */
#define MAXMONITORNAME 100              /* for now */
#define MAXMODENAME 19                  /* for now */

typedef struct
{
    char name[MAXMODENAME+1];
    uns32 xres;				/* User quoted xres (may differ from hpar[FR_DISP], especially in interlaced modes) */
    uns32 yres;				/* User quoted yres (may differ from vpar[FR_DISP], ... */
    uns16 hpar[FR__COUNT];              /* H. framing in vidc pixel times */
    uns16 vpar[FR__COUNT];              /* V. framing in vidc raster times */
    uns32 pixel_khz;                    /* vidc pixel rate in kHz */
    uns8 syncpol;                       /* sync polarity code (0..3 for now) */
    uns8 interlaced;			/* whether mode is interlaced (0 or 1) */
    uns8 spare1, spare2; 	        /* explicit padding so struct is N*4 bytes long */
} ModeDefinition;

/* As stored internally by ScreenModes module */

typedef struct mode_description_
{
    struct mode_description_ *next;     /* in list built during file parsing */
    ModeDefinition definition;          /* as extracted from the file */
    /* The following are computed once the mode definition is read in from the file */
    uns32 line_hz;                      /* line rate in Hz (for diagnostics only) */
    uns32 frame_hz:8;                   /* frame rate in Hz, for user frame rate selection */
    uns32 frame_mhz:24;                 /* also in mHz (millihertz), for more precise cmp */
} ModeDescription, *ModeDescriptionRef;

/* Description of a monitor & its associated modes */
typedef struct
{
    char name[MAXMONITORNAME];
    ModeDescriptionRef modelist;
    uns32 dpms_state;                   /* value specified by DPMS_state keyword, or 0 if none */
    uns32 lcd_support;                  /* 0=>modefile is CRT, 1=>LCD single-panel, 2=>LCD dual panel [WT13-01-95] */
} MonitorDescription, *MonitorDescriptionRef;

/* EOF modex.h */