/*
 * Source generated with ARexxBox 1.12 (May 18 1993)
 * which is Copyright (c) 1992,1993 Michael Balzer
 */

#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <rexx/storage.h>
#include <rexx/rxslib.h>

#ifdef __GNUC__
/* GCC needs all struct defs */
#include <dos/exall.h>
#include <graphics/graphint.h>
#include <intuition/classes.h>
#include <devices/keymap.h>
#include <exec/semaphores.h>
#endif

#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/rexxsyslib_protos.h>

#ifndef __NO_PRAGMAS

#ifdef AZTEC_C
#include <pragmas/exec_lib.h>
#include <pragmas/dos_lib.h>
#include <pragmas/rexxsyslib_lib.h>
#endif

#ifdef LATTICE
#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/rexxsyslib_pragmas.h>
#endif

#endif /* __NO_PRAGMAS */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#ifdef LATTICE
#undef toupper
#define inline __inline
#endif

#ifdef __GNUC__
#undef toupper
static inline char toupper( char c )
{
	return( islower(c) ? c - 'a' + 'A' : c );
}
#endif

#ifdef AZTEC_C
#define inline
#endif

#include "Render.h"


extern struct ExecBase *SysBase;
extern struct DosLibrary *DOSBase;
extern struct RxsLib *RexxSysBase;


/* $ARB: I 727904502 */


/* $ARB: B 8 GETATTR */
/****** MPRender/--background-- *********************************************
*
*  The default portname for MPRender is MPRENDER. This can be overidden by
*  the PORTNAME parameter. However you should never need to address the port
*  directly as all commands should only be run from PRESCRIPT scripts which
*  will automatically use the correct port.
*
*  If 'OPTIONS RESULTS' is on then when an error is returned then RC2 will
*  hold a supplementary error (number or text).
*
*  Shortened unique formats of commands can be used.
*
*****************************************************************************
*
*/
/****** MPRender/GETATTR *************************************************
*
*   NAME   
*  GETATTR -- Gets the attributes of a variable
*
*   SYNOPSIS
*  GETATTR( VAR/K,STEM/K,BASEADDRESS/A,NAME/A ) => VALUE
*
*   FUNCTION
*  Returns the current value of a specified field.
*
*   INPUTS
*  VAR         - Variable to return result rather than RESULT.
*  STEM        - Stem variable for result.
*  BASEADDRESS - As returned by - parse arg Base -.
*  NAME        - Name of variable to get attributes of:
*                Frame    - Current frame number - starting at 1
*                              (0 for first frame);
*                TotalFrames - total number of frames;
*                Single   - the type of morph
*                              0 - Morph, 1 - Warp
*                              2 - AnimMorph, 3 - AnimWarp;
*                Movement - 0 to 1024 - the proportion of movement
*                              from the first image to the second image;
*                Red1     - 0 to 1024 the proportion of image 1 Red to use;
*                Green1   - As Red1 for Green;
*                Blue1    - As Red1 for Blue;
*                Red2     - 0 to 1024 the proportion of image 2 Red to use;
*                Green2   - As Red2 for Green;
*                Blue2    - As Red2 for Blue;
*                Produce  - 1 to render the frame - 0 to skip;
*                RPlus    - 0 to 255 to add to Red in rendered image;
*                GPlus    - As RPlus for Green;
*                BPlus    - As RPlus for Blue;
*                RMinus   - 0 to 255 to subtract from Red in rendered image;
*                GMinus   - As RMinus for Green;
*                BMinus   - As RMinus for Blue;
*                DX       - 0 to ? - X amount to skip;
*                DY       - 0 to ? - Y amount to skip;
*                Start    - Starting from number.
*
*   RESULT
*  If STEM is provided then result is returned in stem.value, otherwise
*  if VAR is provided then result is in var, otherwise result is in
*  RESULT;
*
*  Returns error 10 if no memory or invalid NAME.
*
*   EXAMPLE
*  parse arg Base;options results;getattr Base Frame var f;say f
*
*   NOTES
*  Should only be called from PRESCRIPT scripts.
*  It is a good idea to call - Numeric digits 12 - for correct processing
*  of BASEADDRESS.
*
*   BUGS
*  Does not validate that a valid BASADDRESS is passed.
*
*   SEE ALSO
*  SETATTR().
*
*****************************************************************************
*
*/
extern long *GetRx(char *);
void rx_getattr( struct RexxHost *host, struct rxd_getattr **rxd, long action, struct RexxMsg *rexxmsg )
{
	struct rxd_getattr *rd = *rxd;
	ULONG *place;
	char val[10];

	switch( action )
	{
		case RXIF_INIT:
			*rxd = AllocVec( sizeof *rd, MEMF_CLEAR );
			if( rd = *rxd )
			{
				/* set your DEFAULTS here */
			}
			break;
			
		case RXIF_ACTION:
			/* Insert your CODE here */
			if (place = GetRx(rd->arg.name)) {
				sprintf(val,"%ld",*place);
				if (rd->res.value = AllocVec(strlen(val)+1,MEMF_ANY)) {
					strcpy(rd->res.value,val);
				}
				else {
					rd->rc = 10;
					rd->rc2 = ERROR_NO_FREE_STORE;
					return;
				}
			}
			else {
				rd->rc = -10;
				rd->rc2 = (long)"Invalid name";
			}
			break;
		
		case RXIF_FREE:
			/* FREE your local data here */
			if (rd->res.value) {
				FreeVec(rd->res.value);
			}
			FreeVec( rd );
			break;
	}
	return;
}
/* $ARB: E 8 GETATTR */

/* $ARB: B 12 SETATTR */
/****** MPRender/SETATTR ***********************************************
*
*   NAME   
*  SETATTR -- Sets the attributes of a variable etc.
*
*   SYNOPSIS
*  SETATTR( BASEADDRESS/A,NAME/A,VALUE/A )
*
*   FUNCTION
*  Sets the current value of a specified field.
*
*   INPUTS
*  BASEADDRESS - As returned by - parse arg Base -.
*  NAME        - Name of variable to set attributes for:
*                Movement - 0 to 1024 - the proportion of movement
*                              from the first image to the second image;
*                Red1     - 0 to 1024 the proportion of image 1 Red to use;
*                Green1   - As Red1 for Green;
*                Blue1    - As Red1 for Blue;
*                Red2     - 0 to 1024 the proportion of image 2 Red to use;
*                Green2   - As Red2 for Green;
*                Blue2    - As Red2 for Blue;
*                Produce  - 1 to render the frame - 0 to skip;
*                RPlus    - 0 to 255 to add to Red in rendered image;
*                GPlus    - As RPlus for Green;
*                BPlus    - As RPlus for Blue;
*                RMinus   - 0 to 255 to subtract from Red in rendered image;
*                GMinus   - As RMinus for Green;
*                BMinus   - As RMinus for Blue;
*                DX       - 0 to ? - X amount to skip;
*                DY       - 0 to ? - Y amount to skip.
*  VALUE       - Value to use.
*
*   RESULT
*  Returns error 10 if invalid NAME.
*
*   EXAMPLE
*  parse arg Base;SetAttr Base RMinus 12
*
*   NOTES
*  Should only be called from PRESCRIPT scripts.
*  It is a good idea to call - Numeric digits 12 - for correct processing
*  of BASEADDRESS.
*
*   BUGS
*  Allows setting of read only variables (i.e. those listed in GETATTR()
*  which are not listed here). Does not validate that a valid BASADDRESS
*  is passed.
*
*   SEE ALSO
*  GETATTR().
*
*****************************************************************************
*
*/
void rx_setattr( struct RexxHost *host, struct rxd_setattr **rxd, long action, struct RexxMsg *rexxmsg )
{
	struct rxd_setattr *rd = *rxd;
	ULONG *place;

	switch( action )
	{
		case RXIF_INIT:
			*rxd = AllocVec( sizeof *rd, MEMF_CLEAR );
			if( rd = *rxd )
			{
				/* set your DEFAULTS here */
			}
			break;
			
		case RXIF_ACTION:
			/* Insert your CODE here */
			if (place = GetRx(rd->arg.name)) {
				*place = atol(rd->arg.value);
				rd->rc = 0;
			}
			else {
				rd->rc = -10;
				rd->rc2 = (long)"Invalid name";
			}
			break;
		
		case RXIF_FREE:
			/* FREE your local data here */
			FreeVec( rd );
			break;
	}
	return;
}
/* $ARB: E 12 SETATTR */


#ifndef RX_ALIAS_C
char *ExpandRXCommand( struct RexxHost *host, char *command )
{
	/* Insert your ALIAS-HANDLER here */
	return( NULL );
}
#endif

