/*
 * ============================================================================
 *  Title:    Configuration Manager
 *  Author:   J. Zbiciak
 *  $Id: cfg.h,v 1.4 2001/02/03 02:34:21 im14u2c Exp $
 * ============================================================================
 *  This module manages the machine configuration.  It does commandline
 *  parsing and processes the configuration elements that were read in 
 *  via the config-file parser.
 *
 *  CFG owns the entire machine -- it is encapsulated in a cfg_t.
 * ============================================================================
 *  CFG_INIT     -- Parse command line and get started
 *  CFG_FILE     -- Parse a config file and extend the state of the machine.
 * ============================================================================
 */

#ifndef _CFG_H_
#define _CFG_H_

/*
 * ============================================================================
 *  CFG_EVT_T   -- Human-readable name associations for various jzIntv inputs.
 * ============================================================================
 */
typedef struct cfg_evt_t 
{
    char        *event;         /* Event name.                              */
    v_uint_32   *word;          /* Word modified by input.                  */
    uint_32     and_mask[2];    /* Up/down AND masks.                       */
    uint_32     or_mask [2];    /* Up/down OR masks.                        */
} cfg_evt_t;

/*
 * ============================================================================
 *  CFG_KBD_T   -- Human-readable name associations all possible keyboard
 *                 inputs, along with the associated default bindings.
 *                 The user-specified config file can change these at
 *                 run-time.
 * ============================================================================
 */
typedef struct cfg_kbd_t
{
    char        *key;           /* Name of input.                           */
    char        *event[4];      /* Names of default event bindings.         */
} cfg_kbd_t;

/*
 * ============================================================================
 *  CFG_T            -- The current machine and its configuration
 * ============================================================================
 */
typedef struct cfg_t
{
    /* -------------------------------------------------------------------- */
    /*  Our baby, the Intellivision itself.                                 */
    /* -------------------------------------------------------------------- */
    periph_bus_p intv;          /* Top level Intellivision object.          */

    /* -------------------------------------------------------------------- */
    /*  System 'peripherals' -- these aren't actual hardware devices.       */
    /* -------------------------------------------------------------------- */
    gfx_t       gfx;            /* Graphics interface layer.                */
    snd_t       snd;            /* Sound interface layer.                   */
    speed_t     speed;          /* Rate controller.                         */
    event_t     event;          /* Event subsystem.                         */
    debug_t     debug;          /* Debugger hooks.                          */

    /* -------------------------------------------------------------------- */
    /*  Hardware peripherals -- these model actual pieces of the Intv.      */
    /* -------------------------------------------------------------------- */
    cp1600_t    cp1600;         /* CPU.                                     */
    ay8910_t    psg0;           /* Base unit's Prog. Sound Generator.       */
    ay8910_t    psg1;           /* ECS's Prog. Sound Generator.             */
    ivoice_t    ivoice;         /* SP0256 Emulation.                        */
    stic_t      stic;           /* Standard Television Interface Chip       */
    pad_t       pad0;           /* Base unit's controller pads.             */
    pad_t       pad1;           /* ECS's controller pads.                   */
    pad_intv2pc_t i2pc0,i2pc1;  /* Up to 2 INTV2PCs may be attached.        */
    pad_cgc_t   cgc0, cgc1;     /* Up to 2 CGCs may be attached.            */
    mem_t       exec;           /* EXEC ROM at 0x1000 - 0x1FFF              */
    mem_t       exec2;          /* EXEC2 ROM at 0x0400 - 0x04FF             */
//  mem_t       grom;           /* Graphics ROM at 0x3000 - 0x37FF          */
//  mem_t       gram;           /* Graphics RAM at 0x3800 - 0x3FFF          */
    mem_t       sys_ram;        /* 16-bit System RAM at 0x200 - 0x35F       */
    mem_t       scr_ram;        /* 8-bit Scratchpad RAM at 0x100 - 0x1EF    */
    icart_t     icart;          /* Game program.                            */
    legacy_t    legacy;         /* Legacy BIN+CFG game program              */
    mem_t       game0;
    mem_t       game1;
    mem_t       game2;
    mem_t       ecs0;
    mem_t       ecs1;
    mem_t       ecs2;
    mem_t       ecs_ram;        /* 8-bit Scratchpad RAM at 0x100 - 0x1EF    */

    uint_16     exec_img[4096 + 256];
    uint_16     grom_img[2048      ];
    uint_16     ecs_img [4096 * 3];

    /* -------------------------------------------------------------------- */
    /*  User-modifiable flags, etc.                                         */
    /* -------------------------------------------------------------------- */
    int         audio_rate;     /* Sample rate for audio.  0 == no audio    */
    int         accutick;       /* Min PSG ticks to sim on PSG write.       */
    int         psg_window;     /* Window size for PSG sliding window       */
    int         ecs_enable;     /* ECS enable/disable flag.                 */
    int         ivc_enable;     /* Ivoice enable/disable flag.              */
    int         ivc_window;     /* Window size for Ivoice sliding window.   */
    char        *ivc_tname;     /* Intellivoice sample file name template.  */
    int         full_scr;       /* Full-screen / Windowed display.          */
    int         disp_res;       /* Display resolution.                      */
    uint_32     i2pc0_port;     /* INTV2PC #0 I/O address.                  */
    uint_32     i2pc1_port;     /* INTV2PC #1 I/O address.                  */
    int         cgc0_num;       /* CGC #0's ID number.                      */
    int         cgc1_num;       /* CGC #1's ID number.                      */
    int         debugging;      /* Debugger enabled flag.                   */
    int         rate_ctl;       /* Rate control enabled flag.               */

    char        *fn_exec;       /* File name of EXEC image.                 */
    char        *fn_grom;       /* File name of GROM image.                 */
    char        *fn_game;       /* File name of GAME image.                 */
    char        *fn_ecs;        /* File name of ECS image.                  */

    /* -------------------------------------------------------------------- */
    /*  State flags, such as the global "exit" flag, etc.                   */
    /* -------------------------------------------------------------------- */
    v_uint_32   do_exit;        /* Signal that an exit is requested.        */
    v_uint_32   do_reset;       /* Signal that a RESET is requested.        */
    v_uint_32   do_pause;       /* Signal that we are paused.               */

    /* -------------------------------------------------------------------- */
    /*  Key bindings                                                        */
    /* -------------------------------------------------------------------- */
    cfg_kbd_t   *binding;
} cfg_t;

/* ======================================================================== */
/*  CFG_GET_EVT  -- Convert an event name into an index.  This is a         */
/*                  horrible linear search.  :-P  Hey, it works for now.    */
/* ======================================================================== */
int cfg_get_evt(const char *event);

/* ======================================================================== */
/*  CFG_SETBIND  -- Set all of the key-bindings for the Intellivision.      */
/* ======================================================================== */
void cfg_setbind(cfg_t *cfg, char *kbdhackfile);

/* ======================================================================== */
/*  CFG_INIT     -- Parse command line and get started                      */
/* ======================================================================== */
cfg_t *cfg_init(int argc, char * argv[]);

#endif
/* ======================================================================== */
/*  This program is free software; you can redistribute it and/or modify    */
/*  it under the terms of the GNU General Public License as published by    */
/*  the Free Software Foundation; either version 2 of the License, or       */
/*  (at your option) any later version.                                     */
/*                                                                          */
/*  This program is distributed in the hope that it will be useful,         */
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of          */
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       */
/*  General Public License for more details.                                */
/*                                                                          */
/*  You should have received a copy of the GNU General Public License       */
/*  along with this program; if not, write to the Free Software             */
/*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
/* ======================================================================== */
/*                 Copyright (c) 1998-2001, Joseph Zbiciak                  */
/* ======================================================================== */
