/**************
 ******##****** Filename:                 >> AAP_GLOB.C <<
 *****####***** Edit Date: 03.10.92
 ****######****
 ***##*##*##*** By: Wolfgang Hofer,
 **##**##**##**     Play Anim from Anim struct and/or diskfile
 ******##******
 ******##****** Compiler: AztecC 5.0
 ******##****** Link:     see makefile
 ************** Computer: AMIGA 500
 **************
 ************** This File contains Global Data for both AAP and AAC
 */


/* -------------------------------------
 * Predefine not-int-returning Functions
 * -------------------------------------
 */

/* System Functions */

struct ColorMap    *GetColorMap();
struct FileHandle  *Open();
void               *OpenLibrary();

/* My Functions */

void   AAP_VBLANC();

void (*g_WaitSwap)();


/* -------------------------------------
 * Global Data
 * -------------------------------------
 */


/* Base Pointers for System Libs */
struct IntuitionBase *IntuitionBase = NULL;
struct GfxBase       *GfxBase       = NULL;


/* ----------------------- global Data used in VBlanc INTERRUPT */

struct Interrupt g_VBlanc;

long   g_A4Base;        /* copy of AztecC Baseadress register a4 */
long   g_VB_delay = 0;  /* Counter for VBLANC delay timing */
short  g_frame_ready;   /* 0..frame in progress, 1 ..ready for display */
short  g_scroll_req;    /* != 0 .. scroll request */


struct  cprlist *g_LOFCprList[3];   /* 3 Sets of LongFrame Cprlists */
struct  cprlist *g_SHFCprList[3];   /* 3 Sets of ShortFrame Cprlists */
                                    /* why 3 ??? 2 diplays and
                                     *           1 extra set for scrolling
                                     */

struct BitMap   *g_bm_dbuf[2];      /* Pointers for two BitMap structs */
struct BitMap   *g_bm;              /* Pointer to current write BitMap */
struct BitMap    g_bm_work;         /* current BitMap of my Rastport */
short            g_dbuf;            /* Index of current write BitMap */
short            g_extra;           /* Index of extra cprlist (at scroll) */

struct View      g_view;
struct ViewPort  g_vp ;
struct RasInfo   g_ri;
struct RastPort  g_rp;
struct ColorMap *g_cm = NULL;

struct Window   *g_win_dummy = NULL;
struct NewWindow g_nw_dummy = {
	0,0,    /* window XY origin relative to TopLeft of screen */
	16,16,  /* window width and height */
	0,1,    /* detail and block pens */
	0,      /* IDCMP flags */
	BACKDROP+BORDERLESS+ACTIVATE+NOCAREREFRESH+RMBTRAP,  /* flags */
	NULL,   /* first gadget in gadget list */
	NULL,   /* custom CHECKMARK imagery */
	NULL,   /* window title */
	NULL,   /* custom screen pointer (!sc_tim!)*/
	NULL,   /* custom bitmap (!Bitmap von sc_tim!)*/
	16,16,  /* minimum width and height */
	16,16,  /* maximum width and height */
	WBENCHSCREEN    /* destination screen type */
};

struct Screen  *g_sc_dummy = NULL;
struct NewScreen g_ns_dummy = {
  0,    /* LeftEdge */
  0,    /* TopEdge  */
  320,  /* Width    */
  64,   /* Height   */
  2,    /* Depth    */
  1,    /* DetailPen */
  0,    /* BlockPen  */
  0,    /* ViewModes */
  CUSTOMSCREEN,        /* Type */
  NULL, /* Font         */
  NULL, /* DefaultTitle */
  NULL, /* Gadgets      */
  NULL  /* CustomBitMap */
};




/* -------------------  my other globals */

struct View     *g_old_view_ptr;    /* save ptr to View */

short g_view_changes = 2; /* 0..view has not changed, reuse old CprList
			   * 2..have to make a new CprList for this frame
			   *    and for the next frame too.
			   * 1..have to make a new CprList for this frame
			   */

struct FrameInfo *g_info_ptr = NULL;
long   g_cmap_ptr = 0;

long g_vdx = 0;           /* no extra horizontal View offset */
long g_vdy = 0;           /* no extra vertical View offset */


LONG   g_default_time = 50; /* default time for Picture Frames (jiffies) */
LONG   g_frame_time;    /* time for the a Frame to be dislayed (jiffies)*/
LONG   g_master_time;   /* == 0  .. use frame timing of anim files
			 * >  0 .. use master_time for each frame (jiffies)
			 */
LONG   g_first_delay = 0;  /* no extra delay on 1.st frame */


struct Preferences *g_SysPrefs = NULL;	/* Preferences at begin */
struct Preferences *g_MyPrefs  = NULL;	/* Prefs with no MousePointer */

UWORD *g_dmacon = (UWORD *)0xdff096;
#define ON_SPRITE   *(g_dmacon) = 0x8020;
#define OFF_SPRITE  *(g_dmacon) = 0x0020;


int   g_cli;                /* 0 ... do not print msg to stdout !! */
long  g_listing    = 0;     /* 0 ... dont type script while analyzing it */
long  g_dbug_print = 0;     /* 0 ... dont print debug messages */
char *g_arg_file   = NULL;

ULONG  g_secret_code = 0;   /* 0 is used for UNcoded files */
long   g_exit = 0;          /* g_exit != 0 means break current anim */

/* size of the biggest frame of all used anims/pictures */
long   g_max_disp_plsize;   /* largest BitPlanesize in Bytes */
long   g_max_disp_depth;
long   g_first_bpr = 0;     /* BytesPerRow of the 1. frame of all */
ULONG  g_first_modes;       /* ViewModes of the 1. frame of all */


long   g_stencil_size = 0;
UBYTE  *g_stencil = NULL;

UBYTE *g_frame_buf = NULL;  /* Buffer for one frame CHunk */
long   g_max_frame_len;     /* Alloc size of frame_buf */
UWORD *g_cmap_buf  = NULL;  /* Buffer for one CMAP Chunk */
long   g_max_cmap_len;      /* Alloc size of cmap Chunk */
char  *g_script_buf = NULL; /* Script buffer */
long   g_script_len = 16000;
long   g_script_end = 0;    /* real script length of ascii_script */

/* this dummy is needed if a label occurs as 1.st script command */
struct Script g_script_before_step1;

struct Label  *g_LabelList    = NULL;
struct Script *g_last_script  = NULL;
struct Script *g_script_stack = NULL;
struct Script *g_script_list  = NULL;
struct Anim   *g_anim_list    = NULL;
long   g_preload_flag = 1;   /* 0 .. dont preload files, 1 load them */
long   g_tasks_off;          /* 0.. operate in Mutitasking System
			      * 1.. Forbid other Tasks
			      */


struct FileHandle *g_fh = NULL;
ULONG              g_ram_base = 0;  /* points to Buffer if current file
                                     * was preloaded,
                                     * NULL when playing from diskfile
                                     */
long               g_file_pos = 0;

long g_key_break = 0;       /* 0 .. break at ESC-key, else on any key */
long g_retcode = 0;         /* exit code at program termination */

/* errormessage format strings */
char *g_IntErr       = "Inernal Error, Proc: %s\n";
char *g_MemErr       = "Cant alloc Memory for %s \n";
char *g_OpenErr      = "cant open %s\n";
char *g_EofErr       = "Unexpected EOF found in File %s\n";
char *g_BadFileErr   = "No Frames found in File %s\n";
char *g_SyntaxErr    = "==> ERROR in scriptfile : %s \n";


UBYTE  *g_RawKey  = (UBYTE *)0xbfec01;
UBYTE  *g_Buttons = (UBYTE *)0xbfe001;
UWORD  *g_Potinp  = (UWORD *)(0xdff000 + 0x16);


struct BitMap g_bm_sc;      /* Copy of initial BitMap in intui screen */
struct Screen *g_sc = NULL;

long   g_freq_hz = 50;  /* 50 Hz PAL   or  60 Hz NTSC */


#define C_RD_FILENAME 100L
char  g_rd_filename[C_RD_FILENAME];


#ifdef AAC_MAIN

/*
 * --------------------
 * extra data for AAC
 * --------------------
 */

char  g_basename[100];
long  g_frames_in_file = 0;
long  g_DPANoffset = 0;
long  g_file_count = 0;   /* counts outputfiles (part of out filenames) */
long  g_compress   = 1;   /* 0 ..BODY as is, 1 .. RLC compress */
short g_out_anim   = 1;   /* 0..pictureseq, 1 .. anim */
short g_dta_size   = 4;   /* 4 for longwords, 2 for short, 1 for Byte */
short g_frame0_dlta = 0;  /* 0..frame#0 should be BODY,
			   * 1 .. should be DLTA to a Blackframe
			   */

UBYTE *g_opc_buff;   /* pointer to allocated buffers opc/dta */
UBYTE *g_dta_buff;
long   g_opc_len;    /* size of allocated buffers in bytes  */
long   g_dta_len;

long               g_wr_pos = 0;
struct FileHandle *g_wr_fh  = NULL;

/* two extra Bitmaps for recording Animations */
struct BitMap  *g_bm_two_back = NULL;
struct BitMap  *g_bm_one_back = NULL;

#endif
