/* Header for module A2player, generated by p2c 1.21alpha-07.Dec.93 */
#ifndef A2PLAYER_H
#define A2PLAYER_H


#ifdef A2PLAYER_G
# define vextern
#else
# define vextern extern
#endif


#define MAX_IRQ_FREQ    1000


#define BYTE_NULL       0xff

#define WORD_NULL       0xffffL
/* p2c: typconst.inc, line 4: Warning: Mismatched '$' signs [241] */

#define DWORD_NULL      0
/* p2c: typconst.inc, line 4: 
 * Warning: Expected a semicolon, found 'ffffffff' [227] */


typedef uchar tCHAR8x8[256][8];
typedef uchar tCHAR8x16[256][16];


typedef struct tRGB {
  uchar r, g, b;
} tRGB;

typedef tRGB tRGB_PALETTE[256];


#define ef_Arpeggio     0
#define ef_FSlideUp     1
#define ef_FSlideDown   2
#define ef_TonePortamento  3
#define ef_Vibrato      4
#define ef_TPortamVolSlide  5
#define ef_VibratoVolSlide  6
#define ef_FSlideUpFine  7
#define ef_FSlideDownFine  8
#define ef_SetModulatorVol  9
#define ef_VolSlide     10
#define ef_PositionJump  11
#define ef_SetInsVolume  12
#define ef_PatternBreak  13
#define ef_SetTempo     14
#define ef_SetSpeed     15
#define ef_TPortamVSlideFine  16
#define ef_VibratoVSlideFine  17
#define ef_SetCarrierVol  18
#define ef_SetWaveform  19
#define ef_VolSlideFine  20
#define ef_RetrigNote   21
#define ef_Tremolo      22
#define ef_Tremor       23
#define ef_ArpggVSlide  24
#define ef_ArpggVSlideFine  25
#define ef_MultiRetrigNote  26
#define ef_FSlideUpVSlide  27
#define ef_FSlideDownVSlide  28
#define ef_FSlUpFineVSlide  29
#define ef_FSlDownFineVSlide  30
#define ef_FSlUpVSlF    31
#define ef_FSlDownVSlF  32
#define ef_FSlUpFineVSlF  33
#define ef_FSlDownFineVSlF  34
#define ef_Extended     35
#define ef_Extended2    36
#define ef_SetGlobalVolume  37
#define ef_SwapArpeggio  38
#define ef_SwapVibrato  39
#define ef_ForceInsVolume  40
#define ef_Extended3    41
#define ef_ExtraFineArpeggio  42
#define ef_ExtraFineVibrato  43
#define ef_ExtraFineTremolo  44
#define ef_SetCustomSpeedTab  45
#define ef_GlobalFSlideUp  46
#define ef_GlobalFSlideDown  47
#define ef_ex_SetTremDepth  0
#define ef_ex_SetVibDepth  1
#define ef_ex_SetAttckRateM  2
#define ef_ex_SetDecayRateM  3
#define ef_ex_SetSustnLevelM  4
#define ef_ex_SetRelRateM  5
#define ef_ex_SetAttckRateC  6
#define ef_ex_SetDecayRateC  7
#define ef_ex_SetSustnLevelC  8
#define ef_ex_SetRelRateC  9
#define ef_ex_SetFeedback  10
#define ef_ex_SetPanningPos  11
#define ef_ex_PatternLoop  12
#define ef_ex_PatternLoopRec  13
#define ef_ex_MacroKOffLoop  14
#define ef_ex_ExtendedCmd  15
#define ef_ex_cmd_RSS   0
#define ef_ex_cmd_ResetVol  1
#define ef_ex_cmd_LockVol  2
#define ef_ex_cmd_UnlockVol  3
#define ef_ex_cmd_LockVP  4
#define ef_ex_cmd_UnlockVP  5
#define ef_ex_cmd_VSlide_mod  6
#define ef_ex_cmd_VSlide_car  7
#define ef_ex_cmd_VSlide_def  8
#define ef_ex_cmd_LockPan  9
#define ef_ex_cmd_UnlockPan  10
#define ef_ex_cmd_VibrOff  11
#define ef_ex_cmd_TremOff  12
#define ef_ex_cmd_FVib_FGFS  13
#define ef_ex_cmd_FTrm_XFGFS  14
#define ef_ex_cmd_NoRestart  15
#define ef_ex2_PatDelayFrame  0
#define ef_ex2_PatDelayRow  1
#define ef_ex2_NoteDelay  2
#define ef_ex2_NoteCut  3
#define ef_ex2_FineTuneUp  4
#define ef_ex2_FineTuneDown  5
#define ef_ex2_GlVolSlideUp  6
#define ef_ex2_GlVolSlideDn  7
#define ef_ex2_GlVolSlideUpF  8
#define ef_ex2_GlVolSlideDnF  9
#define ef_ex2_GlVolSldUpXF  10
#define ef_ex2_GlVolSldDnXF  11
#define ef_ex2_VolSlideUpXF  12
#define ef_ex2_VolSlideDnXF  13
#define ef_ex2_FreqSlideUpXF  14
#define ef_ex2_FreqSlideDnXF  15
#define ef_ex3_SetConnection  0
#define ef_ex3_SetMultipM  1
#define ef_ex3_SetKslM  2
#define ef_ex3_SetTremoloM  3
#define ef_ex3_SetVibratoM  4
#define ef_ex3_SetKsrM  5
#define ef_ex3_SetSustainM  6
#define ef_ex3_SetMultipC  7
#define ef_ex3_SetKslC  8
#define ef_ex3_SetTremoloC  9
#define ef_ex3_SetVibratoC  10
#define ef_ex3_SetKsrC  11
#define ef_ex3_SetSustainC  12


#define ef_fix1         0x80
#define ef_fix2         0x90



typedef struct tFM_INST_DATA {
  uchar AM_VIB_EG_modulator, AM_VIB_EG_carrier, KSL_VOLUM_modulator,
	KSL_VOLUM_carrier, ATTCK_DEC_modulator, ATTCK_DEC_carrier,
	SUSTN_REL_modulator, SUSTN_REL_carrier, WAVEFORM_modulator,
	WAVEFORM_carrier, FEEDBACK_FM;
} tFM_INST_DATA;


typedef struct tADTRACK2_INS {
  tFM_INST_DATA fm_data;
  uchar panning;
  short fine_tune;
  uchar perc_voice;
} tADTRACK2_INS;


typedef struct tARPEGGIO_TABLE {
  uchar length, speed, loop_begin, loop_length, keyoff_pos;
  uchar data[255];
} tARPEGGIO_TABLE;


typedef struct tVIBRATO_TABLE {
  uchar length, speed, delay, loop_begin, loop_length, keyoff_pos;
  short data[255];
} tVIBRATO_TABLE;


typedef struct tREGISTER_TABLE_DEF {
  tFM_INST_DATA fm_data;
/* p2c: a2player.pas, line 192:
 * Warning: Symbol 'SMALLINT' is not defined [221] */
  long freq_slide;
  uchar panning, duration;
} tREGISTER_TABLE_DEF;

typedef long Smallint;


typedef struct tREGISTER_TABLE {
  uchar length, loop_begin, loop_length, keyoff_pos, arpeggio_table,
	vibrato_table;
  tREGISTER_TABLE_DEF data[255];
} tREGISTER_TABLE;


typedef struct tMACRO_TABLE {
  tARPEGGIO_TABLE arpeggio;
  tVIBRATO_TABLE vibrato;
} tMACRO_TABLE;


typedef struct tFM_PARAMETER_TABLE {
  struct {
    uchar attck, dec, sustn, rel, wform;
  } adsrw_car, adsrw_mod;
  uchar connect, feedb, multipM, kslM, tremM, vibrM, ksrM, sustM, multipC,
	kslC, tremC, vibrC, ksrC, sustC;
} tFM_PARAMETER_TABLE;


typedef struct tADTRACK2_EVENT {
  uchar note, instr_def, effect_def, effect, effect_def2, effect2;
} tADTRACK2_EVENT;


typedef boolean tDIS_FMREG_COL[28];


typedef struct tFIXED_SONGDATA {
  Char songname[43];
  Char composer[43];
  Char instr_names[255][43];
  tADTRACK2_INS instr_data[255];
  tREGISTER_TABLE instr_macros[255];
  tMACRO_TABLE macro_table[255];
  uchar pattern_order[0x80];
  uchar tempo, speed, common_flag;
  unsigned short patt_len;
  uchar nm_tracks;
  unsigned short macro_speedup;
  uchar flag_4op;
  uchar lock_flags[20];
  Char pattern_names[0x80][43];
  tDIS_FMREG_COL dis_fmreg_col[255];
} tFIXED_SONGDATA;


typedef enum {
  isPlaying, isPaused, isStopped
} tPLAY_STATUS;


typedef tADTRACK2_EVENT tVARIABLE_DATA[8][20][0x100];


typedef tVARIABLE_DATA tPATTERN_DATA[16];


typedef uchar tDUMMY_BUFF[655350L];


typedef struct tOLD_ADTRACK2_INS {
  tFM_INST_DATA fm_data;
  uchar panning;
  short fine_tune;
} tOLD_ADTRACK2_INS;


typedef struct tOLD_FIXED_SONGDATA {
  Char songname[43];
  Char composer[43];
  Char instr_names[250][33];
  tOLD_ADTRACK2_INS instr_data[250];
  uchar pattern_order[0x80];
  uchar tempo, speed, common_flag;
} tOLD_FIXED_SONGDATA;


typedef struct tOLD_CHUNK {
  uchar note, instr_def, effect_def, effect;
} tOLD_CHUNK;


typedef tADTRACK2_EVENT tCHUNK;


typedef tOLD_CHUNK tOLD_VARIABLE_DATA1[0x10][0x40][9];


typedef tOLD_CHUNK tOLD_VARIABLE_DATA2[8][18][0x40];


typedef long tByteSet[9];


#define INSTRUMENT_SIZE  (sizeof(tADTRACK2_INS))
#define CHUNK_SIZE      (sizeof(tADTRACK2_EVENT))
#define PATTERN_SIZE    (CHUNK_SIZE * 5120)


typedef struct tDECAY_BAR {
  short dir;
  double lvl, max_lvl;
} tDECAY_BAR;


extern unsigned short opl3port;
extern short error_code;
extern uchar current_order, current_pattern, current_line, tempo, speed;
extern unsigned short macro_speedup;
extern boolean irq_mode;
extern uchar max_patterns;
extern boolean fast_forward;
extern uchar overall_volume, global_volume;
extern unsigned short song_timer, song_timer_tenths;

vextern unsigned short timer_temp, timer_det;
vextern long ticks, tick0, tickD, tickXF;
vextern boolean limit_exceeded;

vextern double time_playing;
vextern tVARIABLE_DATA *pattdata;
vextern tFIXED_SONGDATA songdata;
vextern tOLD_FIXED_SONGDATA old_songdata;
vextern tOLD_VARIABLE_DATA1 old_hash_buffer;
vextern tOLD_VARIABLE_DATA2 hash_buffer;
vextern uchar buffer[sizeof(tVARIABLE_DATA)];
extern Void (*external_irq_hook) PV();
extern long _delay_counter;
extern unsigned short irq_freq;
extern boolean irq_initialized, timer_fix, pattern_break, pattern_delay;
extern uchar next_line;
extern tPLAY_STATUS play_status;
extern boolean replay_forbidden, force_macro_keyon;
vextern tDECAY_BAR decay_bar[96];


extern Void start_playing PV();
extern Void set_overall_volume PP((int level));
extern Void stop_playing PV();
extern Void init_old_songdata PV();
extern Void init_songdata PV();
extern Void init_irq PV();
extern Void done_irq PV();
extern Void get_chunk PP((int pattern, int line, int channel,
			  tADTRACK2_EVENT *chunk));
extern Void put_chunk PP((int pattern, int line, int channel,
			  tADTRACK2_EVENT chunk));
extern Void count_order PP((uchar *entries));
extern Void timer_poll_proc PV();
extern Void opl3exp PP((int data));

extern short calc_following_order PP((int order));
extern Char *asciiz_string PP((Char *Result, Char *str));


#undef vextern

#endif /*A2PLAYER_H*/

/* End. */
