/** Syswbscr.c
  *
  *   Find out the size of the Workbench
  *
  *   AUTHOR/DATE:  W.G.J. Langeveld, November 1987.
  *   ============
  *
  *	CURRENT VERSION:
  *
  *	This version has been converted to SAS C 6.5 format. It has been modified
  *	for modern definition sequences for ANSI compilation. This no longer works
  *	with OS versions prior to 2.04.
  *
  *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  *   ============
  *
  **/

#include <functions.h>
#include "ralprotos.h"
#include <exec/types.h>
#include <exec/exec.h>
#include <libraries/dos.h>
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

extern struct GfxBase *GfxBase;
extern struct IntuitionBase *IntuitionBase;

#define PSIZE ((long) sizeof(struct Preferences))
	
/**
 *
 *   GetWBRows() returns the number of rows of the Workbench screen, not corrected
 *   for interlace (i.e. the real number is twice as large if the Workbench is
 *   interlaced). If an error is encountered, 0 is returned.
 *
**/
int GetWBRows( void )
{
	int scr_rows = 0;
	
	scr_rows = GfxBase->NormalDisplayRows;
	
	return(scr_rows);
}


/**
 *
 *   GetWBCols() returns the number of columns of the Workbench screen, or
 *   0 on error.
 *
**/
int GetWBCols( void )
{
	int scr_cols = 0;
	
	scr_cols = GfxBase->NormalDisplayColumns;
	
	return(scr_cols);
}

/**
 *
 *   GetWBLace() returns 0 if the Workbench is not interlaced
 *   and 1 if the Workbench is interlaced, and -1 on error.
 *
**/
int GetWBLace( void )
{
	int lace = 0, retcode = 0;
	struct Preferences *prefs = NULL, *nprefs = NULL;
	
	/*
	 *   Check preferences for interlace:
	 *   Allocate a Preferences structure
	 */
	prefs = (struct Preferences *) AllocMem(PSIZE, NULL);
	if (!prefs)
		goto cleanup;
	/*
	 *   Get Preferences and read WB interlace mode from it.
	 */
	nprefs = GetPrefs(prefs, PSIZE);
	if (!nprefs)
		goto cleanup;
	
	if (nprefs->LaceWB & LACEWB)
		lace = 1;
	
	retcode = 1;
	
	cleanup:
	if (prefs)
		FreeMem(prefs, PSIZE);
	
	if (retcode)
		return(lace);
	else
		return(-1);
}
