ic.h 9.93 KB
/*====================================================================
 * ic.h
 *
 * Synopsis:
 *
 * Copyright 1993, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <libaudio.h>

#define FALSE	0
#define TRUE	1

#define	MIN(a,b) (((a)<(b))?(a):(b))
#define	MAX(a,b) (((a)>(b))?(a):(b))

#define ICBANK          1
#define ICINST          2
#define ICSOUND         3
#define ICKEYMAP        4
#define ICWAVE          5
#define ICLOOP          6
#define ICBANKFILE      7
#define ICENVELOPE      8
#define ICBOOK          9

typedef struct id {
  char 		*name;
  int 		lextype;
} Id;

typedef struct decl {
    int                 declclass;
    int                 id;             /* object id                    */
    int                 size;           /* size of object in bytes      */
    void                *offset;        /* offset in the file image     */
    
    int	                value;	    
} Decl;

typedef struct ste {
  struct id	*name;
  struct decl	*decl;
  struct ste	*prev;
} STE;

/*
 * symtab.c
 */
extern struct ste **stacktop;	/* top of scope stack */
extern struct ste **globalscope;/* stacktop in global scope */
extern int        *offsettop;	/* pointer to stack of offsets. */

int             inglobalscope(void);

void            pushscope(void);
struct ste      *popscope(void);

void            declare(struct id *idptr, struct decl *declptr);
void            declareglobal(struct id *idptr, struct decl *declptr);

struct decl     *finddecl(struct id *idptr, struct ste *steptr);
struct decl     *findcurrentdecl(struct id *idptr);
struct decl     *testglobaldecl(struct id *idptr);
void            checkredecl(struct id *idptr);

void            initsymtab(void);
struct id       *findname(struct decl *decl);

/*
 * hash.c
 */
struct id *enter(int lextype, char *str, int len);

/*
 * declreps.c
 */
extern int objectID;

void    declInit(void);
int     declSize(Decl *d);
void    declPrint(Decl *d);

extern struct decl *makeenumconstdecl(int value);
extern struct decl *makerealconstdecl();
extern struct decl *makevardecl();
extern struct decl *maketypedecl(void);
extern struct decl *makebankfiledecl(void);
extern struct decl *makebankdecl(void);
extern struct decl *makeinstdecl(void);
extern struct decl *makesounddecl(void);
extern struct decl *makeenvdecl(void);
extern struct decl *makekeydecl(void);
extern struct decl *makefiledecl(char *s);

/*  typecheck.c */

extern struct decl *getbasetype();
extern void checkiscompareabletype();
extern struct decl *checkfunctioncall();
extern struct decl *lesstype();
extern struct decl *plustype();
extern struct decl *divtype();
extern struct decl *andtype();
extern struct decl *slashtype();
extern struct decl *minustype();
extern struct decl *nottype();
extern void checkassignment();
extern struct decl *arrayindextype();
extern struct decl *recordaccesstype();
extern void matchforward();


/*
 * main.c
 */
void    initLex(void);

extern FILE             *tblFile;
extern struct decl      *insttype;
extern struct decl      *banktype;
extern struct decl      *sndtype;

extern struct decl	*inttype; 
extern struct decl	*realtype; 
extern struct decl	*booltype; 
extern struct decl	*voidtype; 
extern struct decl      *errortype;
extern struct decl      *errorvar;

extern struct id	*returnid;
extern int verbose;
extern int boundcheck;

/*
 * output.c
 */
void    doPrint(void);
void    doLayOut(void);
void    doWrite(FILE *file);

/*
 * list.c
 */
typedef struct Node_s {
    struct Node_s       *next;
    void                *data;
    int                 flags;
} Node;

typedef struct {
    Node *head;
    Node *tail;
} List;

void listNew(List *l);
void listAppend(List *l, void *data);
void listPrepend(List *l, void *data);

/*
 * wavetable.c
 */
typedef struct {
    Decl        decl;           /* object declaration params    */
    ALWaveTable *wave;
    char        *base;
    int         len;  
    int         rate; 
    char        channels;
    char        size;
    char        format;
    struct ICLoop_s     *loop;
    struct ICBook_s     *book;
} ICWave;

void    waveNew(ICWave *w);
void    waveSetTable(ICWave *w, char *base, int len);
void    waveSetRate(ICWave *w, int rate);
void    waveSetChannels(ICWave *w, char channels);
void    waveSetSize(ICWave *w, char size);
void    waveSetFormat(ICWave *w, char format);
void    waveLayOut(ICWave *w);
void    wavePrint(ICWave *w);
void    waveWrite(ICWave *w, FILE *file);

/*
 * loop.c
 */

typedef short ICLoopState[ADPCMFSIZE];

typedef struct {
    ICLoopState state;
    u_long      start;
    u_long      end;
    u_long      count;
    u_long      pad1;
} Aloop;

typedef struct ICLoop_s {
    Decl        decl;
    Aloop       *loop;
    u_long      start;
    u_long      end;
    u_long      count;
    ICLoopState state;
} ICLoop;

void    loopNew(ICLoop *l);
void    loopSetPoints(ICLoop *l, u_long start, u_long end, u_long count,
                      ICLoopState state);
void    loopLayOut(ICLoop *l);
void    loopPrint(ICLoop *l);
void    loopWrite(ICLoop *l, FILE *file);
char    *ReadPString(FILE *ifile);

/*
 * book.c
 */

typedef struct ICBook_s{
    Decl        decl;
    ALADPCMBook   *bookp;
    u_long      order;
    u_long      npredictors;
    short       book[1];        /* ** Wrong! Actually variable size */
} ICBook;

void bookNew(ICBook *b, int order, int npredictors);
void bookLayOut(ICBook *icb);
void bookPrint(ICBook *icb);
void bookWrite(ICBook *b, FILE *file);

/*
 * envelope.c
 */
typedef struct {
    Decl        decl;
    ALEnvelope  *envelope;
    int         attackTime;
    short       attackVol;
    int         decayTime;
    short       decayVol;
    int         releaseTime;
    short       releaseVol;
} ICEnvelope;

extern ICEnvelope *curEnvelope;

void    envNew(ICEnvelope *env);
void    envSetAttackTime(ICEnvelope *e, int t);
void    envSetAttackVol(ICEnvelope *e, short v);
void    envSetDecayTime(ICEnvelope *e, int t);
void    envSetDecayVol(ICEnvelope *e, short v);
void    envSetReleaseTime(ICEnvelope *e, int t);
void    envSetReleaseVol(ICEnvelope *e, short v);

void    envLayOut(ICEnvelope *env);
void    envPrint(ICEnvelope *env);
void    envWrite(ICEnvelope *env, FILE *file);

/*
 * keymap.c
 */
typedef struct {
    Decl        decl;           /* object declaration params    */
    ALKeyMap    *map;           /* file representation          */
    char        velocityMin;
    char        velocityMax;
    char        keyMin;
    char        keyMax;
    char        keyBase;
    char        detune;
} ICKeyMap;

extern ICKeyMap *curKeyMap;

void    keyNew(ICKeyMap *k);
void    keySetKeyMin(ICKeyMap *k, int min);
void    keySetKeyMax(ICKeyMap *k, int max);
void    keySetKeyBase(ICKeyMap *k, int base);
void    keySetVelMin(ICKeyMap *k, int value);	
void    keySetVelMax(ICKeyMap *k, int value);	
void    keySetDetune(ICKeyMap *k, int value);	
void    keyLayOut(ICKeyMap *k);
void    keyPrint(ICKeyMap *k);
void    keyWrite(ICKeyMap *k, FILE *file);

/*
 * sound.c
 */
typedef struct {
    Decl        decl;
    ALSound     *sound;    
    char        samplePan;
    char        sampleVolume;
    ICEnvelope  *envelope;
    ICKeyMap    *keymap;
    int         waveCount;
    ICWave      *wave;
} ICSound;

extern ICSound *curSound;

void    soundNew(ICSound *s);
void    soundSetPan(ICSound *s, int pan);
void    soundSetVol(ICSound *s, int vol);
void    soundFromFile(ICSound *s, char *file);
void    soundAddKeyMap(ICSound *s, ICKeyMap *map);
void    soundAddEnvelope(ICSound *s, ICEnvelope *env);
void    soundLayOut(ICSound *s);
void    soundPrint(ICSound *s);
void    soundWrite(ICSound *s, FILE *file);

/*
 * instrument.c
 */
typedef struct {
    Decl                decl;
    ALInstrument        *inst;
    List                soundList;
    char                volume;
    char                pan;
    int                 soundCount;
} ICInst;

extern ICInst *curInstrument;

void    instNew(ICInst *i);
void    instAddSound(ICInst *i, ICSound *s, int number);
void    instSetPan(ICInst *i, int pan);
void    instSetVol(ICInst *i, int vol);
void    instLayOut(ICInst *i);
void    instPrint(ICInst *i);
void    instWrite(ICInst *i, FILE *file);

/*
 * bank.c
 */
typedef struct {
    Decl        decl;           /* object declaration           */
    ALBank      *bank;          /* file representation          */
    List        progList;       /* list of assigned instruments */
    int         maxPrograms;    /* maximum number of programs   */
} ICBank;

extern  ICBank *curBank;

void    bankNew(ICBank *b);
void    bankAddProgram(ICBank *b, ICInst *i, int number);
void    bankLayOut(ICBank *b);
void    bankPrint(ICBank *b);
void    bankWrite(ICBank *b, FILE *file);

/*
 * bankfile.c
 */
typedef struct {
    Decl        decl;
    ALBankFile  *bankfile;
    List        bankList;
    int         bankCount;
    int         version;
} ICBankFile;
extern  ICBankFile  *curBankFile;

void    bankfNew(ICBankFile *b);
void    bankfAddBank(ICBankFile *icb, ICBank *b, int number);
void    bankfLayOut(ICBankFile *b);
void    bankfPrint(ICBankFile *b);
void    bankfWrite(ICBankFile *b, FILE *file);

/* LEX, YACC  interface */

extern int      yylineno;
extern char     yytext[];
extern void     yyerror(char *msg);
extern int      yyparse(void);
extern int      yylex(void);

extern List *objectList;