#!/bin/sh

# This script was created by Tony 'Nicoya' Mantler <nicoya@apia.dhs.org>
# Run as './mgras-BlockSync.sh XXXxYYY_ZZ' where
# XXX = horizontal resolution (ie: 1280)
# YYY = vertical resolution (ie: 1024)
# ZZ = vertical refresh rate (ie: 76)
# For example: './mgras-BlockSync.sh 1280x1024_76'

# The following lines are the magic voodoo to extract the parameters

ACTIVE_PIXELS=`echo $1 | sed -n 's/\(.*\)x.*_.*/\1/p'`
ACTIVE_LINES=`echo $1 | sed -n  's/.*x\(.*\)_.*/\1/p'`
FPS=`echo $1 | sed -n 's/.*x.*_\(.*\)/\1/p'`

# RSSCOUNT should be set to the number of REs in your boardset.
# Octane SE and SI, Indigo2 SolidIMPACT and HighIMPACT should be 1
# Octane SSE, SSI, MXE and MXI, Indigo2 MaxIMPACT should be 2

# If you are unsure of the RE count of your boardset, execute the
# command 'gfxinfo' and look for a line such as:
#         Product ID 0x0, 2 GEs, 2 REs, 1 TRAM
#                               ^^^^^^^

# When set to 2, the resulting mode file should be stored in
# /usr/gfx/ucode/MGRAS/vof/2RSS/, otherwise the mode should go in
# the usual /usr/gfx/ucode/MGRAS/vof/ directory
RSSCOUNT=1

# DB32 should be set to '1' to enable large double-buffered visuals
DB32=0

# INTERLACED should be set to '1' for interlaced modes, '0' otherwise
INTERLACED=0

# STEREO_FMT should be set to '1' to make a stereo mode, '0' otherwise
STEREO_FMT=0

# OPTIONS can probably safely be left at '0', I have no clue what it does
OPTIONS=0

# ZBUF should be set to '1' to enable Z-Buffered visuals, '0' otherwise
ZBUF=1

# VERT_SERRATION should be set to '1' if your interlaced mode requires
# a serrated vertical sync pulse. (?)
VERT_SERRATION=0

vfc -p "-DRSSCOUNT=$RSSCOUNT" \
    -p "-DDB32=$DB32" \
    -p "-DINTERLACED=$INTERLACED" \
    -p "-DSTEREO_FMT=$STEREO_FMT" \
    -p "-DOPTIONS=$OPTIONS" \
    -p "-DZBUF=$ZBUF" \
    -p "-DVERT_SERRATION=$VERT_SERRATION" \
    \
    -p "-DACTIVE_LINES=$ACTIVE_LINES" \
    -p "-DACTIVE_PIXELS=$ACTIVE_PIXELS" \
    -p "-DFPS=$FPS" \
    -c board=O2_Board.def,chip=O2_Chip.def \
    -o $1.vfo \
    /usr/gfx/ucode/vfc/vfs/BlockSync.vfs
    

