1 /* 2 * ============================================================================ 3 * Title: AY-8910 family Programmable Sound Generator 4 * Author: J. Zbiciak 5 * ============================================================================ 6 * This module implements the AY-8910 sound chip. 7 * ============================================================================ 8 * 9 * ============================================================================ 10 */ 11 12 #ifndef AY8910_H_ 13 #define AY8910_H_ 14 15 /* 16 * ============================================================================ 17 * AY8910_T -- PSG structure 18 * ============================================================================ 19 */ 20 21 #define AY8910_STCK (4) /* Samples per tick. */ 22 23 struct ay8910_t 24 { 25 periph_t periph; /* Yup, it's a peripheral. Go figure. */ 26 uint16_t reg[14]; /* The AY-891x's 14 internal registers. */ 27 int max[5]; /* Up-count cutoff: A, B, C, N, E. */ 28 int cnt[6]; /* Counter registers. These behave as */ 29 /* upcounters that compare against */ 30 /* cnt_max[], but really they're down */ 31 /* counters. */ 32 33 snd_buf_t snd_buf; /* Sound circular buffer. */ 34 35 int16_t *cur_buf; /* Current sound buffer. */ 36 int cur_len; /* Fullness of current sound buffer. */ 37 38 uint32_t noise_rng; /* Random-number generator for noise. */ 39 40 int env_cont; /* Envelope CONTINUE flag */ 41 int env_atak; /* Envelope ATTACK flag */ 42 int env_altr; /* Envelope ALTERNATE flag */ 43 int env_hold; /* Envelope HOLD flag */ 44 int env_vol; /* Last envelope volume. */ 45 int env_samp; /* Envelope sample count remainder. */ 46 int demo_env_hit; /* Flag for demo rec: Hit env reg. */ 47 48 int chan[3]; /* Last channel state (on/off) */ 49 50 int *window; /* Sliding Window. */ 51 int wind_sum; /* Window sum. */ 52 int wind_ptr; /* Window pointer. */ 53 int rate, wind; /* Sample rate, Window size. */ 54 int sys_clock; /* System clock rate */ 55 double time_scale; 56 double scale_frc; 57 58 /* Dynamic Digital Analyzer approach for matching sample rates. */ 59 int sample_frc; /* Fractional error term. */ 60 61 uint64_t sound_current; /* Sound is calc'd up until this time. */ 62 uint64_t unaccounted; 63 uint64_t accutick; /* min time when simulating on write */ 64 uint64_t *cpu_time; /* don't get ahead of CPU (HACK!) */ 65 66 char *trace_filename; /* Register trace file name */ 67 FILE *trace; /* Register trace file pointer */ 68 }; 69 70 71 #ifndef AY8910_T_ 72 #define AY8910_T_ 1 73 typedef struct ay8910_t ay8910_t; 74 #endif 75 76 77 /* 78 * ============================================================================ 79 * AY8910_READ -- Read from device. 80 * ============================================================================ 81 */ 82 uint32_t ay8910_read 83 ( 84 periph_t *bus, /* Peripheral bus being read. */ 85 periph_t *req, /* Peripheral requesting read. */ 86 uint32_t addr, /* Address being read. */ 87 uint32_t data /* Current state of data being read. */ 88 ); 89 90 /* 91 * ============================================================================ 92 * AY8910_WRITE -- Write to device. 93 * ============================================================================ 94 */ 95 void ay8910_write 96 ( 97 periph_t *bus, /* Peripheral bus being written. */ 98 periph_t *req, /* Peripheral requesting write. */ 99 uint32_t addr, /* Address being written. */ 100 uint32_t data /* Data being written. */ 101 ); 102 103 /* 104 * ============================================================================ 105 * AY8910_TICK -- Tick the device. 106 * ============================================================================ 107 */ 108 uint32_t ay8910_tick 109 ( 110 periph_t *bus, /* Peripheral bus being ticked. */ 111 uint32_t len 112 ); 113 114 115 /* 116 * ============================================================================ 117 * AY8910_INIT -- Makes a new PSG. 118 * ============================================================================ 119 */ 120 121 int ay8910_init 122 ( 123 ay8910_t *ay8910, /* Structure to initialize. */ 124 uint32_t addr, /* Base address of ay8910. */ 125 snd_t *snd, /* Sound device to register w/. */ 126 int rate, /* Sampling rate. */ 127 int wind, /* Averaging window. */ 128 int accutick, /* Averaging window. */ 129 double time_scale, /* for --macho */ 130 int pal_mode, /* 0 == NTSC, 1 == PAL */ 131 uint64_t *cpu_time /* HACK: don't get ahead of CPU */ 132 ); 133 134 135 #endif 136 137 /* ======================================================================== */ 138 /* This program is free software; you can redistribute it and/or modify */ 139 /* it under the terms of the GNU General Public License as published by */ 140 /* the Free Software Foundation; either version 2 of the License, or */ 141 /* (at your option) any later version. */ 142 /* */ 143 /* This program is distributed in the hope that it will be useful, */ 144 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 145 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 146 /* General Public License for more details. */ 147 /* */ 148 /* You should have received a copy of the GNU General Public License along */ 149 /* with this program; if not, write to the Free Software Foundation, Inc., */ 150 /* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ 151 /* ======================================================================== */ 152 /* Copyright (c) 1998-1999, Joseph Zbiciak */ 153 /* ======================================================================== */ 154 155