src/emu/cpu/drcbeut.c
| r10048 | r10049 | |
| 4 | 4 | |
| 5 | 5 | Utility functions for dynamic recompiling backends. |
| 6 | 6 | |
| 7 | **************************************************************************** |
| 8 | |
| 7 | 9 | Copyright Aaron Giles |
| 8 | | Released for general non-commercial use under the MAME license |
| 9 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 10 | All rights reserved. |
| 10 | 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are |
| 14 | met: |
| 15 | |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in |
| 20 | the documentation and/or other materials provided with the |
| 21 | distribution. |
| 22 | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | used to endorse or promote products derived from this software |
| 24 | without specific prior written permission. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | |
| 11 | 38 | ***************************************************************************/ |
| 12 | 39 | |
| 13 | 40 | #include "emu.h" |
| 14 | 41 | #include "drcbeut.h" |
| 15 | 42 | |
| 16 | 43 | |
| 17 | | /*************************************************************************** |
| 18 | | DEBUGGING |
| 19 | | ***************************************************************************/ |
| 44 | //************************************************************************** |
| 45 | // DEBUGGING |
| 46 | //************************************************************************** |
| 20 | 47 | |
| 21 | 48 | #define LOG_RECOVER (0) |
| 22 | 49 | |
| 23 | 50 | |
| 24 | | /*************************************************************************** |
| 25 | | TYPE DEFINITIONS |
| 26 | | ***************************************************************************/ |
| 27 | 51 | |
| 28 | | /* structure holding information about a single label */ |
| 29 | | typedef struct _drcmap_entry drcmap_entry; |
| 30 | | struct _drcmap_entry |
| 31 | | { |
| 32 | | drcmap_entry * next; /* pointer to next map entry */ |
| 33 | | drccodeptr codeptr; /* pointer to the relevant code */ |
| 34 | | UINT32 mapvar; /* map variable id */ |
| 35 | | UINT32 newval; /* value of the variable starting at codeptr */ |
| 36 | | }; |
| 52 | //************************************************************************** |
| 53 | // DRC HASH TABLE |
| 54 | //************************************************************************** |
| 37 | 55 | |
| 56 | //------------------------------------------------- |
| 57 | // drc_hash_table - constructor |
| 58 | //------------------------------------------------- |
| 38 | 59 | |
| 39 | | /* structure describing the state of the code map */ |
| 40 | | struct _drcmap_state |
| 60 | drc_hash_table::drc_hash_table(drc_cache &cache, UINT32 modes, UINT8 addrbits, UINT8 ignorebits) |
| 61 | : m_cache(cache), |
| 62 | m_modes(modes), |
| 63 | m_nocodeptr(NULL), |
| 64 | m_l1bits((addrbits - ignorebits) / 2), |
| 65 | m_l2bits((addrbits - ignorebits) - m_l1bits), |
| 66 | m_l1shift(ignorebits + m_l2bits), |
| 67 | m_l2shift(ignorebits), |
| 68 | m_l1mask((1 << m_l1bits) - 1), |
| 69 | m_l2mask((1 << m_l2bits) - 1), |
| 70 | m_base(reinterpret_cast<drccodeptr ***>(cache.alloc(modes * sizeof(**m_base)))), |
| 71 | m_emptyl1(NULL), |
| 72 | m_emptyl2(NULL) |
| 41 | 73 | { |
| 42 | | drccache * cache; /* pointer to the cache */ |
| 43 | | UINT64 uniquevalue; /* unique value used to find the table */ |
| 44 | | drcmap_entry * head; /* head of the live list */ |
| 45 | | drcmap_entry ** tailptr; /* pointer to tail of the live list */ |
| 46 | | UINT32 numvalues; /* number of values in the list */ |
| 47 | | UINT32 mapvalue[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0]; /* array of current values */ |
| 48 | | }; |
| 49 | | |
| 50 | | |
| 51 | | /* structure holding information about a single label */ |
| 52 | | typedef struct _drclabel drclabel; |
| 53 | | struct _drclabel |
| 54 | | { |
| 55 | | drclabel * next; /* pointer to next label */ |
| 56 | | drcuml_codelabel label; /* the label specified */ |
| 57 | | drccodeptr codeptr; /* pointer to the relevant code */ |
| 58 | | }; |
| 59 | | |
| 60 | | |
| 61 | | /* structure holding a live list of labels */ |
| 62 | | struct _drclabel_list |
| 63 | | { |
| 64 | | drccache * cache; /* pointer to the cache */ |
| 65 | | drclabel * head; /* head of the live list */ |
| 66 | | }; |
| 67 | | |
| 68 | | |
| 69 | | |
| 70 | | /*************************************************************************** |
| 71 | | FUNCTION PROTOTYPES |
| 72 | | ***************************************************************************/ |
| 73 | | |
| 74 | | static void label_list_reset(drclabel_list *list, int fatal_on_leftovers); |
| 75 | | static drclabel *label_find_or_allocate(drclabel_list *list, drcuml_codelabel label); |
| 76 | | static void label_oob_callback(drccodeptr *codeptr, void *param1, void *param2, void *param3); |
| 77 | | |
| 78 | | |
| 79 | | |
| 80 | | /*************************************************************************** |
| 81 | | HASH TABLE MANAGEMENT |
| 82 | | ***************************************************************************/ |
| 83 | | |
| 84 | | /*------------------------------------------------- |
| 85 | | drchash_alloc - allocate memory in the cache |
| 86 | | for the hash table tracker (it auto-frees |
| 87 | | with the cache) |
| 88 | | -------------------------------------------------*/ |
| 89 | | |
| 90 | | drchash_state *drchash_alloc(drccache *cache, int modes, int addrbits, int ignorebits) |
| 91 | | { |
| 92 | | int effaddrbits = addrbits - ignorebits; |
| 93 | | drchash_state *drchash; |
| 94 | | |
| 95 | | /* allocate permanent state from the cache */ |
| 96 | | drchash = (drchash_state *)drccache_memory_alloc(cache, sizeof(*drchash) + modes * sizeof(drchash->base[0])); |
| 97 | | if (drchash == NULL) |
| 98 | | return NULL; |
| 99 | | memset(drchash, 0, sizeof(*drchash) + modes * sizeof(drchash->base[0])); |
| 100 | | |
| 101 | | /* copy in parameters */ |
| 102 | | drchash->cache = cache; |
| 103 | | drchash->modes = modes; |
| 104 | | |
| 105 | | /* compute the sizes of the tables */ |
| 106 | | drchash->l1bits = effaddrbits / 2; |
| 107 | | drchash->l2bits = effaddrbits - drchash->l1bits; |
| 108 | | drchash->l1shift = ignorebits + drchash->l2bits; |
| 109 | | drchash->l2shift = ignorebits; |
| 110 | | drchash->l1mask = (1 << drchash->l1bits) - 1; |
| 111 | | drchash->l2mask = (1 << drchash->l2bits) - 1; |
| 112 | | |
| 113 | | /* reset the hash table, which allocates any subsequent tables */ |
| 114 | | if (!drchash_reset(drchash)) |
| 115 | | return NULL; |
| 116 | | |
| 117 | | return drchash; |
| 74 | reset(); |
| 118 | 75 | } |
| 119 | 76 | |
| 120 | 77 | |
| 121 | | /*------------------------------------------------- |
| 122 | | drchash_reset - flush existing hash tables and |
| 123 | | create new ones |
| 124 | | -------------------------------------------------*/ |
| 78 | //------------------------------------------------- |
| 79 | // reset - flush existing hash tables and create |
| 80 | // new ones |
| 81 | //------------------------------------------------- |
| 125 | 82 | |
| 126 | | int drchash_reset(drchash_state *drchash) |
| 83 | bool drc_hash_table::reset() |
| 127 | 84 | { |
| 128 | | int modenum, entry; |
| 85 | // allocate an empty l2 hash table |
| 86 | m_emptyl2 = (drccodeptr *)m_cache.alloc_temporary(sizeof(drccodeptr) << m_l2bits); |
| 87 | if (m_emptyl2 == NULL) |
| 88 | return false; |
| 129 | 89 | |
| 130 | | /* allocate an empty l2 hash table */ |
| 131 | | drchash->emptyl2 = (drccodeptr *)drccache_memory_alloc_temporary(drchash->cache, sizeof(drccodeptr) << drchash->l2bits); |
| 132 | | if (drchash->emptyl2 == NULL) |
| 133 | | return FALSE; |
| 90 | // populate it with pointers to the recompile_exit code |
| 91 | for (int entry = 0; entry < (1 << m_l2bits); entry++) |
| 92 | m_emptyl2[entry] = m_nocodeptr; |
| 134 | 93 | |
| 135 | | /* populate it with pointers to the recompile_exit code */ |
| 136 | | for (entry = 0; entry < (1 << drchash->l2bits); entry++) |
| 137 | | drchash->emptyl2[entry] = drchash->nocodeptr; |
| 94 | // allocate an empty l1 hash table |
| 95 | m_emptyl1 = (drccodeptr **)m_cache.alloc_temporary(sizeof(drccodeptr *) << m_l1bits); |
| 96 | if (m_emptyl1 == NULL) |
| 97 | return false; |
| 138 | 98 | |
| 139 | | /* allocate an empty l1 hash table */ |
| 140 | | drchash->emptyl1 = (drccodeptr **)drccache_memory_alloc_temporary(drchash->cache, sizeof(drccodeptr *) << drchash->l1bits); |
| 141 | | if (drchash->emptyl1 == NULL) |
| 142 | | return FALSE; |
| 99 | // populate it with pointers to the empty l2 table |
| 100 | for (int entry = 0; entry < (1 << m_l1bits); entry++) |
| 101 | m_emptyl1[entry] = m_emptyl2; |
| 143 | 102 | |
| 144 | | /* populate it with pointers to the empty l2 table */ |
| 145 | | for (entry = 0; entry < (1 << drchash->l1bits); entry++) |
| 146 | | drchash->emptyl1[entry] = drchash->emptyl2; |
| 103 | // reset the hash tables |
| 104 | for (int modenum = 0; modenum < m_modes; modenum++) |
| 105 | m_base[modenum] = m_emptyl1; |
| 147 | 106 | |
| 148 | | /* reset the hash tables */ |
| 149 | | for (modenum = 0; modenum < drchash->modes; modenum++) |
| 150 | | drchash->base[modenum] = drchash->emptyl1; |
| 151 | | |
| 152 | | return TRUE; |
| 107 | return true; |
| 153 | 108 | } |
| 154 | 109 | |
| 155 | 110 | |
| 156 | | /*------------------------------------------------- |
| 157 | | drchash_block_begin - note the beginning of a |
| 158 | | block |
| 159 | | -------------------------------------------------*/ |
| 111 | //------------------------------------------------- |
| 112 | // block_begin - note the beginning of a block |
| 113 | //------------------------------------------------- |
| 160 | 114 | |
| 161 | | void drchash_block_begin(drchash_state *drchash, drcuml_block *block, const drcuml_instruction *instlist, UINT32 numinst) |
| 115 | void drc_hash_table::block_begin(drcuml_block &block, const drcuml_instruction *instlist, UINT32 numinst) |
| 162 | 116 | { |
| 163 | | int inum; |
| 164 | | |
| 165 | | /* before generating code, pre-allocate any hash entries; we do this by setting dummy hash values */ |
| 166 | | for (inum = 0; inum < numinst; inum++) |
| 117 | // before generating code, pre-allocate any hash entries; we do this by setting dummy hash values |
| 118 | for (int inum = 0; inum < numinst; inum++) |
| 167 | 119 | { |
| 168 | | const drcuml_instruction *inst = &instlist[inum]; |
| 120 | const drcuml_instruction &inst = instlist[inum]; |
| 169 | 121 | |
| 170 | | /* if the opcode is a hash, verify that it makes sense and then set a NULL entry */ |
| 171 | | if (inst->opcode == DRCUML_OP_HASH) |
| 122 | // if the opcode is a hash, verify that it makes sense and then set a NULL entry |
| 123 | if (inst.opcode == DRCUML_OP_HASH) |
| 172 | 124 | { |
| 173 | | assert(inst->numparams == 2); |
| 174 | | assert(inst->param[0].type == DRCUML_PTYPE_IMMEDIATE); |
| 175 | | assert(inst->param[1].type == DRCUML_PTYPE_IMMEDIATE); |
| 125 | assert(inst.numparams == 2); |
| 126 | assert(inst.param[0].type == DRCUML_PTYPE_IMMEDIATE); |
| 127 | assert(inst.param[1].type == DRCUML_PTYPE_IMMEDIATE); |
| 176 | 128 | |
| 177 | | /* if we fail to allocate, we must abort the block */ |
| 178 | | if (!drchash_set_codeptr(drchash, inst->param[0].value, inst->param[1].value, NULL)) |
| 179 | | drcuml_block_abort(block); |
| 129 | // if we fail to allocate, we must abort the block |
| 130 | if (!set_codeptr(inst.param[0].value, inst.param[1].value, NULL)) |
| 131 | drcuml_block_abort(&block); |
| 180 | 132 | } |
| 181 | 133 | |
| 182 | | /* if the opcode is a hashjmp to a fixed location, make sure we preallocate the tables */ |
| 183 | | if (inst->opcode == DRCUML_OP_HASHJMP && inst->param[0].type == DRCUML_PTYPE_IMMEDIATE && inst->param[1].type == DRCUML_PTYPE_IMMEDIATE) |
| 134 | // if the opcode is a hashjmp to a fixed location, make sure we preallocate the tables |
| 135 | if (inst.opcode == DRCUML_OP_HASHJMP && inst.param[0].type == DRCUML_PTYPE_IMMEDIATE && inst.param[1].type == DRCUML_PTYPE_IMMEDIATE) |
| 184 | 136 | { |
| 185 | | /* if we fail to allocate, we must abort the block */ |
| 186 | | drccodeptr code = drchash_get_codeptr(drchash, inst->param[0].value, inst->param[1].value); |
| 187 | | if (!drchash_set_codeptr(drchash, inst->param[0].value, inst->param[1].value, code)) |
| 188 | | drcuml_block_abort(block); |
| 137 | // if we fail to allocate, we must abort the block |
| 138 | drccodeptr code = get_codeptr(inst.param[0].value, inst.param[1].value); |
| 139 | if (!set_codeptr(inst.param[0].value, inst.param[1].value, code)) |
| 140 | drcuml_block_abort(&block); |
| 189 | 141 | } |
| 190 | 142 | } |
| 191 | 143 | } |
| 192 | 144 | |
| 193 | 145 | |
| 194 | | /*------------------------------------------------- |
| 195 | | drchash_block_end - note the end of a block |
| 196 | | -------------------------------------------------*/ |
| 146 | //------------------------------------------------- |
| 147 | // block_end - note the end of a block |
| 148 | //------------------------------------------------- |
| 197 | 149 | |
| 198 | | void drchash_block_end(drchash_state *drchash, drcuml_block *block) |
| 150 | void drc_hash_table::block_end(drcuml_block &block) |
| 199 | 151 | { |
| 200 | | /* nothing to do here, yet */ |
| 152 | // nothing to do here, yet |
| 201 | 153 | } |
| 202 | 154 | |
| 203 | 155 | |
| 204 | | /*------------------------------------------------- |
| 205 | | drchash_set_default_codeptr - change the |
| 206 | | default codeptr |
| 207 | | -------------------------------------------------*/ |
| 156 | //------------------------------------------------- |
| 157 | // set_default_codeptr - change the default |
| 158 | // codeptr |
| 159 | //------------------------------------------------- |
| 208 | 160 | |
| 209 | | void drchash_set_default_codeptr(drchash_state *drchash, drccodeptr nocodeptr) |
| 161 | void drc_hash_table::set_default_codeptr(drccodeptr nocodeptr) |
| 210 | 162 | { |
| 211 | | drccodeptr old = drchash->nocodeptr; |
| 212 | | int modenum, l1entry, l2entry; |
| 213 | | |
| 214 | | /* nothing to do if the same */ |
| 163 | // nothing to do if the same |
| 164 | drccodeptr old = m_nocodeptr; |
| 215 | 165 | if (old == nocodeptr) |
| 216 | 166 | return; |
| 217 | | drchash->nocodeptr = nocodeptr; |
| 167 | m_nocodeptr = nocodeptr; |
| 218 | 168 | |
| 219 | | /* update the empty L2 table first */ |
| 220 | | for (l2entry = 0; l2entry < (1 << drchash->l2bits); l2entry++) |
| 221 | | drchash->emptyl2[l2entry] = nocodeptr; |
| 169 | // update the empty L2 table first |
| 170 | for (int l2entry = 0; l2entry < (1 << m_l2bits); l2entry++) |
| 171 | m_emptyl2[l2entry] = nocodeptr; |
| 222 | 172 | |
| 223 | | /* now scan all existing hashtables for entries */ |
| 224 | | for (modenum = 0; modenum < drchash->modes; modenum++) |
| 225 | | if (drchash->base[modenum] != drchash->emptyl1) |
| 226 | | for (l1entry = 0; l1entry < (1 << drchash->l1bits); l1entry++) |
| 227 | | if (drchash->base[modenum][l1entry] != drchash->emptyl2) |
| 228 | | for (l2entry = 0; l2entry < (1 << drchash->l2bits); l2entry++) |
| 229 | | if (drchash->base[modenum][l1entry][l2entry] == old) |
| 230 | | drchash->base[modenum][l1entry][l2entry] = nocodeptr; |
| 173 | // now scan all existing hashtables for entries |
| 174 | for (int modenum = 0; modenum < m_modes; modenum++) |
| 175 | if (m_base[modenum] != m_emptyl1) |
| 176 | for (int l1entry = 0; l1entry < (1 << m_l1bits); l1entry++) |
| 177 | if (m_base[modenum][l1entry] != m_emptyl2) |
| 178 | for (int l2entry = 0; l2entry < (1 << m_l2bits); l2entry++) |
| 179 | if (m_base[modenum][l1entry][l2entry] == old) |
| 180 | m_base[modenum][l1entry][l2entry] = nocodeptr; |
| 231 | 181 | } |
| 232 | 182 | |
| 233 | 183 | |
| 234 | | /*------------------------------------------------- |
| 235 | | drchash_set_codeptr - set the codeptr for the |
| 236 | | given mode/pc |
| 237 | | -------------------------------------------------*/ |
| 184 | //------------------------------------------------- |
| 185 | // set_codeptr - set the codeptr for the given |
| 186 | // mode/pc |
| 187 | //------------------------------------------------- |
| 238 | 188 | |
| 239 | | int drchash_set_codeptr(drchash_state *drchash, UINT32 mode, UINT32 pc, drccodeptr code) |
| 189 | bool drc_hash_table::set_codeptr(UINT32 mode, UINT32 pc, drccodeptr code) |
| 240 | 190 | { |
| 241 | | UINT32 l1 = (pc >> drchash->l1shift) & drchash->l1mask; |
| 242 | | UINT32 l2 = (pc >> drchash->l2shift) & drchash->l2mask; |
| 243 | | |
| 244 | | assert(mode < drchash->modes); |
| 245 | | |
| 246 | | /* copy-on-write for the l1 hash table */ |
| 247 | | if (drchash->base[mode] == drchash->emptyl1) |
| 191 | // copy-on-write for the l1 hash table |
| 192 | assert(mode < m_modes); |
| 193 | if (m_base[mode] == m_emptyl1) |
| 248 | 194 | { |
| 249 | | drccodeptr **newtable = (drccodeptr **)drccache_memory_alloc_temporary(drchash->cache, sizeof(drccodeptr *) << drchash->l1bits); |
| 195 | drccodeptr **newtable = (drccodeptr **)m_cache.alloc_temporary(sizeof(drccodeptr *) << m_l1bits); |
| 250 | 196 | if (newtable == NULL) |
| 251 | | return FALSE; |
| 252 | | memcpy(newtable, drchash->emptyl1, sizeof(drccodeptr *) << drchash->l1bits); |
| 253 | | drchash->base[mode] = newtable; |
| 197 | return false; |
| 198 | memcpy(newtable, m_emptyl1, sizeof(drccodeptr *) << m_l1bits); |
| 199 | m_base[mode] = newtable; |
| 254 | 200 | } |
| 255 | 201 | |
| 256 | | /* copy-on-write for the l2 hash table */ |
| 257 | | if (drchash->base[mode][l1] == drchash->emptyl2) |
| 202 | // copy-on-write for the l2 hash table |
| 203 | UINT32 l1 = (pc >> m_l1shift) & m_l1mask; |
| 204 | if (m_base[mode][l1] == m_emptyl2) |
| 258 | 205 | { |
| 259 | | drccodeptr *newtable = (drccodeptr *)drccache_memory_alloc_temporary(drchash->cache, sizeof(drccodeptr) << drchash->l2bits); |
| 206 | drccodeptr *newtable = (drccodeptr *)m_cache.alloc_temporary(sizeof(drccodeptr) << m_l2bits); |
| 260 | 207 | if (newtable == NULL) |
| 261 | | return FALSE; |
| 262 | | memcpy(newtable, drchash->emptyl2, sizeof(drccodeptr) << drchash->l2bits); |
| 263 | | drchash->base[mode][l1] = newtable; |
| 208 | return false; |
| 209 | memcpy(newtable, m_emptyl2, sizeof(drccodeptr) << m_l2bits); |
| 210 | m_base[mode][l1] = newtable; |
| 264 | 211 | } |
| 265 | 212 | |
| 266 | | /* set the new entry */ |
| 267 | | drchash->base[mode][l1][l2] = code; |
| 268 | | return TRUE; |
| 213 | // set the new entry |
| 214 | UINT32 l2 = (pc >> m_l2shift) & m_l2mask; |
| 215 | m_base[mode][l1][l2] = code; |
| 216 | return true; |
| 269 | 217 | } |
| 270 | 218 | |
| 271 | 219 | |
| 272 | 220 | |
| 273 | | /*************************************************************************** |
| 274 | | CODE MAP MANAGEMENT |
| 275 | | ***************************************************************************/ |
| 221 | //************************************************************************** |
| 222 | // DRC MAP VARIABLES |
| 223 | //************************************************************************** |
| 276 | 224 | |
| 277 | | /*------------------------------------------------- |
| 278 | | drcmap_alloc - allocate memory in the cache |
| 279 | | for the code mapper (it auto-frees with the |
| 280 | | cache) |
| 281 | | -------------------------------------------------*/ |
| 225 | //------------------------------------------------- |
| 226 | // drc_map_variables - constructor |
| 227 | //------------------------------------------------- |
| 282 | 228 | |
| 283 | | drcmap_state *drcmap_alloc(drccache *cache, UINT64 uniquevalue) |
| 229 | drc_map_variables::drc_map_variables(drc_cache &cache, UINT64 uniquevalue) |
| 230 | : m_cache(cache), |
| 231 | m_uniquevalue(uniquevalue) |
| 284 | 232 | { |
| 285 | | drcmap_state *drcmap; |
| 233 | memset(m_mapvalue, 0, sizeof(m_mapvalue)); |
| 234 | } |
| 286 | 235 | |
| 287 | | /* allocate permanent state from the cache */ |
| 288 | | drcmap = (drcmap_state *)drccache_memory_alloc(cache, sizeof(*drcmap)); |
| 289 | | if (drcmap == NULL) |
| 290 | | return NULL; |
| 291 | | memset(drcmap, 0, sizeof(*drcmap)); |
| 292 | 236 | |
| 293 | | /* remember the cache */ |
| 294 | | drcmap->cache = cache; |
| 295 | | drcmap->tailptr = &drcmap->head; |
| 237 | //------------------------------------------------- |
| 238 | // ~drc_map_variables - destructor |
| 239 | //------------------------------------------------- |
| 296 | 240 | |
| 297 | | return drcmap; |
| 241 | drc_map_variables::~drc_map_variables() |
| 242 | { |
| 243 | // must detach all items from the entry list so that the list object |
| 244 | // doesn't try to free them on exit |
| 245 | m_entry_list.detach_all(); |
| 298 | 246 | } |
| 299 | 247 | |
| 300 | 248 | |
| 301 | | /*------------------------------------------------- |
| 302 | | drcmap_block_begin - note the beginning of a |
| 303 | | block |
| 304 | | -------------------------------------------------*/ |
| 249 | //------------------------------------------------- |
| 250 | // block_begin - note the beginning of a block |
| 251 | //------------------------------------------------- |
| 305 | 252 | |
| 306 | | void drcmap_block_begin(drcmap_state *drcmap, drcuml_block *block) |
| 253 | void drc_map_variables::block_begin(drcuml_block &block) |
| 307 | 254 | { |
| 308 | | /* release any remaining live entries */ |
| 309 | | while (drcmap->head != NULL) |
| 310 | | { |
| 311 | | drcmap_entry *entry = drcmap->head; |
| 312 | | drcmap->head = entry->next; |
| 313 | | drccache_memory_free(drcmap->cache, entry, sizeof(*entry)); |
| 314 | | } |
| 255 | // release any remaining live entries |
| 256 | map_entry *entry; |
| 257 | while ((entry = m_entry_list.detach_head()) != NULL) |
| 258 | m_cache.dealloc(entry, sizeof(*entry)); |
| 315 | 259 | |
| 316 | | /* reset the tailptr and count */ |
| 317 | | drcmap->tailptr = &drcmap->head; |
| 318 | | drcmap->numvalues = 0; |
| 319 | | |
| 320 | | /* reset the variable values */ |
| 321 | | memset(drcmap->mapvalue, 0, sizeof(drcmap->mapvalue)); |
| 260 | // reset the variable values |
| 261 | memset(m_mapvalue, 0, sizeof(m_mapvalue)); |
| 322 | 262 | } |
| 323 | 263 | |
| 324 | 264 | |
| 325 | | /*------------------------------------------------- |
| 326 | | drcmap_block_end - note the end of a block |
| 327 | | -------------------------------------------------*/ |
| 265 | //------------------------------------------------- |
| 266 | // block_end - note the end of a block |
| 267 | //------------------------------------------------- |
| 328 | 268 | |
| 329 | | void drcmap_block_end(drcmap_state *drcmap, drcuml_block *block) |
| 269 | void drc_map_variables::block_end(drcuml_block &block) |
| 330 | 270 | { |
| 331 | | UINT32 curvalue[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0] = { 0 }; |
| 332 | | UINT8 changed[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0] = { 0 }; |
| 333 | | drcmap_entry *entry; |
| 334 | | drccodeptr lastptr; |
| 335 | | drccodeptr *top; |
| 336 | | UINT32 *dest; |
| 337 | | |
| 338 | | /* only process if we have data */ |
| 339 | | if (drcmap->head == NULL) |
| 271 | // only process if we have data |
| 272 | if (m_entry_list.first() == NULL) |
| 340 | 273 | return; |
| 341 | 274 | |
| 342 | | /* begin "code generation" aligned to an 8-byte boundary */ |
| 343 | | top = drccache_begin_codegen(drcmap->cache, sizeof(UINT64) + sizeof(UINT32) + 2 * sizeof(UINT32) * drcmap->numvalues); |
| 275 | // begin "code generation" aligned to an 8-byte boundary |
| 276 | drccodeptr *top = m_cache.begin_codegen(sizeof(UINT64) + sizeof(UINT32) + 2 * sizeof(UINT32) * m_entry_list.count()); |
| 344 | 277 | if (top == NULL) |
| 345 | | drcuml_block_abort(block); |
| 346 | | dest = (UINT32 *)(((FPTR)*top + 7) & ~7); |
| 278 | drcuml_block_abort(&block); |
| 279 | UINT32 *dest = (UINT32 *)(((FPTR)*top + 7) & ~7); |
| 347 | 280 | |
| 348 | | /* store the cookie first */ |
| 349 | | *(UINT64 *)dest = drcmap->uniquevalue; |
| 281 | // store the cookie first |
| 282 | *(UINT64 *)dest = m_uniquevalue; |
| 350 | 283 | dest += 2; |
| 351 | 284 | |
| 352 | | /* get the pointer to the first item and store an initial backwards offset */ |
| 353 | | lastptr = drcmap->head->codeptr; |
| 285 | // get the pointer to the first item and store an initial backwards offset |
| 286 | drccodeptr lastptr = m_entry_list.first()->m_codeptr; |
| 354 | 287 | *dest = (drccodeptr)dest - lastptr; |
| 355 | 288 | dest++; |
| 356 | 289 | |
| 357 | | /* now iterate over entries and store them */ |
| 358 | | for (entry = drcmap->head; entry != NULL; entry = entry->next) |
| 290 | // now iterate over entries and store them |
| 291 | UINT32 curvalue[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0] = { 0 }; |
| 292 | bool changed[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0] = { false }; |
| 293 | for (map_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next()) |
| 359 | 294 | { |
| 360 | | /* update the current value of the variable and detect changes */ |
| 361 | | if (curvalue[entry->mapvar] != entry->newval) |
| 295 | // update the current value of the variable and detect changes |
| 296 | if (curvalue[entry->m_mapvar] != entry->m_newval) |
| 362 | 297 | { |
| 363 | | curvalue[entry->mapvar] = entry->newval; |
| 364 | | changed[entry->mapvar] = TRUE; |
| 298 | curvalue[entry->m_mapvar] = entry->m_newval; |
| 299 | changed[entry->m_mapvar] = true; |
| 365 | 300 | } |
| 366 | 301 | |
| 367 | | /* if the next code pointer is different, or if we're at the end, flush changes */ |
| 368 | | if (entry->next == NULL || entry->next->codeptr != entry->codeptr) |
| 302 | // if the next code pointer is different, or if we're at the end, flush changes |
| 303 | if (entry->next() == NULL || entry->next()->m_codeptr != entry->m_codeptr) |
| 369 | 304 | { |
| 370 | | UINT32 codedelta = entry->codeptr - lastptr; |
| 305 | // build a mask of changed variables |
| 306 | int numchanged = 0; |
| 371 | 307 | UINT32 varmask = 0; |
| 372 | | int numchanged; |
| 373 | | int varnum; |
| 374 | | |
| 375 | | /* build a mask of changed variables */ |
| 376 | | for (numchanged = varnum = 0; varnum < ARRAY_LENGTH(changed); varnum++) |
| 308 | for (int varnum = 0; varnum < ARRAY_LENGTH(changed); varnum++) |
| 377 | 309 | if (changed[varnum]) |
| 378 | 310 | { |
| 379 | | changed[varnum] = FALSE; |
| 311 | changed[varnum] = false; |
| 380 | 312 | varmask |= 1 << varnum; |
| 381 | 313 | numchanged++; |
| 382 | 314 | } |
| 383 | 315 | |
| 384 | | /* if nothing really changed, skip it */ |
| 316 | // if nothing really changed, skip it |
| 385 | 317 | if (numchanged == 0) |
| 386 | 318 | continue; |
| 387 | 319 | |
| 388 | | /* first word is a code delta plus mask of changed variables */ |
| 320 | // first word is a code delta plus mask of changed variables |
| 321 | UINT32 codedelta = entry->m_codeptr - lastptr; |
| 389 | 322 | while (codedelta > 0xffff) |
| 390 | 323 | { |
| 391 | 324 | *dest++ = 0xffff << 16; |
| r10048 | r10049 | |
| 393 | 326 | } |
| 394 | 327 | *dest++ = (codedelta << 16) | (varmask << 4) | numchanged; |
| 395 | 328 | |
| 396 | | /* now output updated variable values */ |
| 397 | | for (varnum = 0; varnum < ARRAY_LENGTH(changed); varnum++) |
| 329 | // now output updated variable values |
| 330 | for (int varnum = 0; varnum < ARRAY_LENGTH(changed); varnum++) |
| 398 | 331 | if ((varmask >> varnum) & 1) |
| 399 | 332 | *dest++ = curvalue[varnum]; |
| 400 | 333 | |
| 401 | | /* remember our lastptr */ |
| 402 | | lastptr = entry->codeptr; |
| 334 | // remember our lastptr |
| 335 | lastptr = entry->m_codeptr; |
| 403 | 336 | } |
| 404 | 337 | } |
| 405 | 338 | |
| 406 | | /* add a terminator */ |
| 339 | // add a terminator |
| 407 | 340 | *dest++ = 0; |
| 408 | 341 | |
| 409 | | /* complete codegen */ |
| 342 | // complete codegen |
| 410 | 343 | *top = (drccodeptr)dest; |
| 411 | | drccache_end_codegen(drcmap->cache); |
| 344 | m_cache.end_codegen(); |
| 412 | 345 | } |
| 413 | 346 | |
| 414 | 347 | |
| 415 | | /*------------------------------------------------- |
| 416 | | drcmap_set_value - set a map value for the |
| 417 | | given code pointer |
| 418 | | -------------------------------------------------*/ |
| 348 | //------------------------------------------------- |
| 349 | // set_value - set a map value for the given |
| 350 | // code pointer |
| 351 | //------------------------------------------------- |
| 419 | 352 | |
| 420 | | void drcmap_set_value(drcmap_state *drcmap, drccodeptr codebase, UINT32 mapvar, UINT32 newvalue) |
| 353 | void drc_map_variables::set_value(drccodeptr codebase, UINT32 mapvar, UINT32 newvalue) |
| 421 | 354 | { |
| 422 | | drcmap_entry *entry; |
| 423 | | |
| 424 | 355 | assert(mapvar >= DRCUML_MAPVAR_M0 && mapvar < DRCUML_MAPVAR_END); |
| 425 | 356 | |
| 426 | | /* if this value isn't different, skip it */ |
| 427 | | if (drcmap->mapvalue[mapvar - DRCUML_MAPVAR_M0] == newvalue) |
| 357 | // if this value isn't different, skip it |
| 358 | if (m_mapvalue[mapvar - DRCUML_MAPVAR_M0] == newvalue) |
| 428 | 359 | return; |
| 429 | 360 | |
| 430 | | /* allocate a new entry and fill it in */ |
| 431 | | entry = (drcmap_entry *)drccache_memory_alloc(drcmap->cache, sizeof(*entry)); |
| 432 | | entry->next = NULL; |
| 433 | | entry->codeptr = codebase; |
| 434 | | entry->mapvar = mapvar - DRCUML_MAPVAR_M0; |
| 435 | | entry->newval = newvalue; |
| 361 | // allocate a new entry and fill it in |
| 362 | map_entry *entry = (map_entry *)m_cache.alloc(sizeof(*entry)); |
| 363 | entry->m_next = NULL; |
| 364 | entry->m_codeptr = codebase; |
| 365 | entry->m_mapvar = mapvar - DRCUML_MAPVAR_M0; |
| 366 | entry->m_newval = newvalue; |
| 436 | 367 | |
| 437 | | /* hook us into the end of the list */ |
| 438 | | *drcmap->tailptr = entry; |
| 439 | | drcmap->tailptr = &entry->next; |
| 368 | // hook us into the end of the list |
| 369 | m_entry_list.append(*entry); |
| 440 | 370 | |
| 441 | | /* update our state in the table as well */ |
| 442 | | drcmap->mapvalue[mapvar - DRCUML_MAPVAR_M0] = newvalue; |
| 443 | | |
| 444 | | /* and increment the count */ |
| 445 | | drcmap->numvalues++; |
| 371 | // update our state in the table as well |
| 372 | m_mapvalue[mapvar - DRCUML_MAPVAR_M0] = newvalue; |
| 446 | 373 | } |
| 447 | 374 | |
| 448 | 375 | |
| 449 | | /*------------------------------------------------- |
| 450 | | drcmap_get_value - return a map value for the |
| 451 | | given code pointer |
| 452 | | -------------------------------------------------*/ |
| 376 | //------------------------------------------------- |
| 377 | // get_value - return a map value for the given |
| 378 | // code pointer |
| 379 | //------------------------------------------------- |
| 453 | 380 | |
| 454 | | UINT32 drcmap_get_value(drcmap_state *drcmap, drccodeptr codebase, UINT32 mapvar) |
| 381 | UINT32 drc_map_variables::get_value(drccodeptr codebase, UINT32 mapvar) const |
| 455 | 382 | { |
| 456 | | UINT64 *endscan = (UINT64 *)drccache_top(drcmap->cache); |
| 457 | | UINT32 varmask = 0x10 << mapvar; |
| 458 | | drccodeptr curcode; |
| 459 | | UINT32 result = 0; |
| 460 | | UINT64 *curscan; |
| 461 | | UINT32 *data; |
| 462 | | |
| 463 | 383 | assert(mapvar >= DRCUML_MAPVAR_M0 && mapvar < DRCUML_MAPVAR_END); |
| 464 | 384 | mapvar -= DRCUML_MAPVAR_M0; |
| 465 | 385 | |
| 466 | | /* get an aligned pointer to start scanning */ |
| 467 | | curscan = (UINT64 *)(((FPTR)codebase | 7) + 1); |
| 386 | // get an aligned pointer to start scanning |
| 387 | UINT64 *curscan = (UINT64 *)(((FPTR)codebase | 7) + 1); |
| 388 | UINT64 *endscan = (UINT64 *)m_cache.top(); |
| 468 | 389 | |
| 469 | | /* look for the signature */ |
| 470 | | while (curscan < endscan && *curscan++ != drcmap->uniquevalue) ; |
| 390 | // look for the signature |
| 391 | while (curscan < endscan && *curscan++ != m_uniquevalue) ; |
| 471 | 392 | if (curscan >= endscan) |
| 472 | 393 | return 0; |
| 473 | 394 | |
| 474 | | /* switch to 32-bit pointers for processing the rest */ |
| 475 | | data = (UINT32 *)curscan; |
| 395 | // switch to 32-bit pointers for processing the rest |
| 396 | UINT32 *data = (UINT32 *)curscan; |
| 476 | 397 | |
| 477 | | /* first get the 32-bit starting offset to the code */ |
| 478 | | curcode = (drccodeptr)data - *data; |
| 398 | // first get the 32-bit starting offset to the code |
| 399 | drccodeptr curcode = (drccodeptr)data - *data; |
| 479 | 400 | data++; |
| 480 | 401 | |
| 481 | | /* now loop until we advance past our target */ |
| 482 | | while (TRUE) |
| 402 | // now loop until we advance past our target |
| 403 | UINT32 varmask = 0x10 << mapvar; |
| 404 | UINT32 result = 0; |
| 405 | while (true) |
| 483 | 406 | { |
| 407 | // a 0 is a terminator |
| 484 | 408 | UINT32 controlword = *data++; |
| 485 | | |
| 486 | | /* a 0 is a terminator */ |
| 487 | 409 | if (controlword == 0) |
| 488 | 410 | break; |
| 489 | 411 | |
| 490 | | /* update the codeptr; if this puts us past the end, we're done */ |
| 412 | // update the codeptr; if this puts us past the end, we're done |
| 491 | 413 | curcode += (controlword >> 16) & 0xffff; |
| 492 | 414 | if (curcode > codebase) |
| 493 | 415 | break; |
| 494 | 416 | |
| 495 | | /* if our mapvar has changed, process this word */ |
| 417 | // if our mapvar has changed, process this word |
| 496 | 418 | if ((controlword & varmask) != 0) |
| 497 | 419 | { |
| 420 | // count how many words precede the one we care about |
| 498 | 421 | int dataoffs = 0; |
| 499 | | UINT32 skipmask; |
| 500 | | |
| 501 | | /* count how many words precede the one we care about */ |
| 502 | | for (skipmask = (controlword & (varmask - 1)) >> 4; skipmask != 0; skipmask = skipmask & (skipmask - 1)) |
| 422 | for (UINT32 skipmask = (controlword & (varmask - 1)) >> 4; skipmask != 0; skipmask = skipmask & (skipmask - 1)) |
| 503 | 423 | dataoffs++; |
| 504 | 424 | |
| 505 | | /* fetch the one we want */ |
| 425 | // fetch the one we want |
| 506 | 426 | result = data[dataoffs]; |
| 507 | 427 | } |
| 508 | 428 | |
| 509 | | /* low 4 bits contain the total number of words of data */ |
| 429 | // low 4 bits contain the total number of words of data |
| 510 | 430 | data += controlword & 0x0f; |
| 511 | 431 | } |
| 512 | 432 | if (LOG_RECOVER) |
| r10048 | r10049 | |
| 514 | 434 | return result; |
| 515 | 435 | } |
| 516 | 436 | |
| 437 | UINT32 drc_map_variables::static_get_value(drc_map_variables &map, drccodeptr codebase, UINT32 mapvar) |
| 438 | { |
| 439 | return map.get_value(codebase, mapvar); |
| 440 | } |
| 517 | 441 | |
| 518 | | /*------------------------------------------------- |
| 519 | | drcmap_get_last_value - return the most |
| 520 | | recently set map value |
| 521 | | -------------------------------------------------*/ |
| 522 | 442 | |
| 523 | | UINT32 drcmap_get_last_value(drcmap_state *drcmap, UINT32 mapvar) |
| 443 | |
| 444 | //------------------------------------------------- |
| 445 | // get_last_value - return the most recently set |
| 446 | // map value |
| 447 | //------------------------------------------------- |
| 448 | |
| 449 | UINT32 drc_map_variables::get_last_value(UINT32 mapvar) |
| 524 | 450 | { |
| 525 | 451 | assert(mapvar >= DRCUML_MAPVAR_M0 && mapvar < DRCUML_MAPVAR_END); |
| 526 | | return drcmap->mapvalue[mapvar - DRCUML_MAPVAR_M0]; |
| 452 | return m_mapvalue[mapvar - DRCUML_MAPVAR_M0]; |
| 527 | 453 | } |
| 528 | 454 | |
| 529 | 455 | |
| 530 | 456 | |
| 531 | | /*************************************************************************** |
| 532 | | LABEL MANAGEMENT |
| 533 | | ***************************************************************************/ |
| 457 | //************************************************************************** |
| 458 | // DRC LABEL LIST |
| 459 | //************************************************************************** |
| 534 | 460 | |
| 535 | | /*------------------------------------------------- |
| 536 | | drclabel_list_alloc - allocate a label |
| 537 | | list within the cache (it auto-frees with the |
| 538 | | cache) |
| 539 | | -------------------------------------------------*/ |
| 461 | //------------------------------------------------- |
| 462 | // drc_label_list - constructor |
| 463 | //------------------------------------------------- |
| 540 | 464 | |
| 541 | | drclabel_list *drclabel_list_alloc(drccache *cache) |
| 465 | drc_label_list::drc_label_list(drc_cache &cache) |
| 466 | : m_cache(cache) |
| 542 | 467 | { |
| 543 | | drclabel_list *list; |
| 468 | } |
| 544 | 469 | |
| 545 | | /* allocate permanent state from the cache */ |
| 546 | | list = (drclabel_list *)drccache_memory_alloc(cache, sizeof(*list)); |
| 547 | | if (list == NULL) |
| 548 | | return NULL; |
| 549 | | memset(list, 0, sizeof(*list)); |
| 550 | 470 | |
| 551 | | /* remember the cache */ |
| 552 | | list->cache = cache; |
| 471 | //------------------------------------------------- |
| 472 | // ~drc_label_list - destructor |
| 473 | //------------------------------------------------- |
| 553 | 474 | |
| 554 | | return list; |
| 475 | drc_label_list::~drc_label_list() |
| 476 | { |
| 477 | // must detach all items from the entry list so that the list object |
| 478 | // doesn't try to free them on exit |
| 479 | m_list.detach_all(); |
| 555 | 480 | } |
| 556 | 481 | |
| 557 | 482 | |
| 558 | | /*------------------------------------------------- |
| 559 | | drclabel_block_begin - note the beginning of |
| 560 | | a block |
| 561 | | -------------------------------------------------*/ |
| 483 | //------------------------------------------------- |
| 484 | // block_begin - note the beginning of a block |
| 485 | //------------------------------------------------- |
| 562 | 486 | |
| 563 | | void drclabel_block_begin(drclabel_list *list, drcuml_block *block) |
| 487 | void drc_label_list::block_begin(drcuml_block &block) |
| 564 | 488 | { |
| 565 | | /* make sure the label list is clear, but don't fatalerror */ |
| 566 | | label_list_reset(list, FALSE); |
| 489 | // make sure the label list is clear, but don't fatalerror |
| 490 | reset(false); |
| 567 | 491 | } |
| 568 | 492 | |
| 569 | 493 | |
| 570 | | /*------------------------------------------------- |
| 571 | | drclabel_block_end - note the end of a block |
| 572 | | -------------------------------------------------*/ |
| 494 | //------------------------------------------------- |
| 495 | // block_end - note the end of a block |
| 496 | //------------------------------------------------- |
| 573 | 497 | |
| 574 | | void drclabel_block_end(drclabel_list *list, drcuml_block *block) |
| 498 | void drc_label_list::block_end(drcuml_block &block) |
| 575 | 499 | { |
| 576 | | /* make sure the label list is clear, and fatalerror if we missed anything */ |
| 577 | | label_list_reset(list, TRUE); |
| 500 | // make sure the label list is clear, and fatalerror if we missed anything |
| 501 | reset(true); |
| 578 | 502 | } |
| 579 | 503 | |
| 580 | 504 | |
| 581 | | /*------------------------------------------------- |
| 582 | | drclabel_get_codeptr - find or allocate a new |
| 583 | | label; returns NULL and requests an OOB |
| 584 | | callback if undefined |
| 585 | | -------------------------------------------------*/ |
| 505 | //------------------------------------------------- |
| 506 | // get_codeptr - find or allocate a new label; |
| 507 | // returns NULL and requests an OOB callback if |
| 508 | // undefined |
| 509 | //------------------------------------------------- |
| 586 | 510 | |
| 587 | | drccodeptr drclabel_get_codeptr(drclabel_list *list, drcuml_codelabel label, drclabel_fixup_func fixup, void *param) |
| 511 | drccodeptr drc_label_list::get_codeptr(drcuml_codelabel label, fixup_func fixup, void *param) |
| 588 | 512 | { |
| 589 | | drclabel *curlabel = label_find_or_allocate(list, label); |
| 513 | label_entry *curlabel = find_or_allocate(label); |
| 590 | 514 | |
| 591 | | /* if no code pointer, request an OOB callback */ |
| 592 | | if (curlabel->codeptr == NULL && fixup != NULL) |
| 593 | | drccache_request_oob_codegen(list->cache, label_oob_callback, curlabel, (void *)fixup, param); |
| 515 | // if no code pointer, request an OOB callback |
| 516 | if (curlabel->m_codeptr == NULL && fixup != NULL) |
| 517 | m_cache.request_oob_codegen(oob_callback, curlabel, (void *)fixup, param); |
| 594 | 518 | |
| 595 | | return curlabel->codeptr; |
| 519 | return curlabel->m_codeptr; |
| 596 | 520 | } |
| 597 | 521 | |
| 598 | 522 | |
| 599 | | /*------------------------------------------------- |
| 600 | | drclabel_set_codeptr - set the pointer to a new |
| 601 | | label |
| 602 | | -------------------------------------------------*/ |
| 523 | //------------------------------------------------- |
| 524 | // set_codeptr - set the pointer to a new label |
| 525 | //------------------------------------------------- |
| 603 | 526 | |
| 604 | | void drclabel_set_codeptr(drclabel_list *list, drcuml_codelabel label, drccodeptr codeptr) |
| 527 | void drc_label_list::set_codeptr(drcuml_codelabel label, drccodeptr codeptr) |
| 605 | 528 | { |
| 606 | | /* set the code pointer */ |
| 607 | | drclabel *curlabel = label_find_or_allocate(list, label); |
| 608 | | assert(curlabel->codeptr == NULL); |
| 609 | | curlabel->codeptr = codeptr; |
| 529 | // set the code pointer |
| 530 | label_entry *curlabel = find_or_allocate(label); |
| 531 | assert(curlabel->m_codeptr == NULL); |
| 532 | curlabel->m_codeptr = codeptr; |
| 610 | 533 | } |
| 611 | 534 | |
| 612 | 535 | |
| 536 | //------------------------------------------------- |
| 537 | // reset - reset a label list (add all entries to |
| 538 | // the free list) |
| 539 | //------------------------------------------------- |
| 613 | 540 | |
| 614 | | /*************************************************************************** |
| 615 | | LABEL MANAGEMENT |
| 616 | | ***************************************************************************/ |
| 617 | | |
| 618 | | /*------------------------------------------------- |
| 619 | | label_list_reset - reset a label |
| 620 | | list (add all entries to the free list) |
| 621 | | -------------------------------------------------*/ |
| 622 | | |
| 623 | | static void label_list_reset(drclabel_list *list, int fatal_on_leftovers) |
| 541 | void drc_label_list::reset(bool fatal_on_leftovers) |
| 624 | 542 | { |
| 625 | | /* loop until out of labels */ |
| 626 | | while (list->head != NULL) |
| 543 | // loop until out of labels |
| 544 | label_entry *curlabel; |
| 545 | while ((curlabel = m_list.detach_head()) != NULL) |
| 627 | 546 | { |
| 628 | | /* remove from the list */ |
| 629 | | drclabel *label = list->head; |
| 630 | | list->head = label->next; |
| 547 | // fatal if we were a leftover |
| 548 | if (fatal_on_leftovers && curlabel->m_codeptr == NULL) |
| 549 | fatalerror("Label %08X never defined!", curlabel->m_label); |
| 631 | 550 | |
| 632 | | /* fatal if we were a leftover */ |
| 633 | | if (fatal_on_leftovers && label->codeptr == NULL) |
| 634 | | fatalerror("Label %08X never defined!", label->label); |
| 635 | | |
| 636 | | /* free the label */ |
| 637 | | drccache_memory_free(list->cache, label, sizeof(*label)); |
| 551 | // free the label |
| 552 | m_cache.dealloc(curlabel, sizeof(*curlabel)); |
| 638 | 553 | } |
| 639 | 554 | } |
| 640 | 555 | |
| 641 | 556 | |
| 642 | | /*------------------------------------------------- |
| 643 | | label_find_or_allocate - look up a label and |
| 644 | | allocate a new one if not found |
| 645 | | -------------------------------------------------*/ |
| 557 | //------------------------------------------------- |
| 558 | // find_or_allocate - look up a label and |
| 559 | // allocate a new one if not found |
| 560 | //------------------------------------------------- |
| 646 | 561 | |
| 647 | | static drclabel *label_find_or_allocate(drclabel_list *list, drcuml_codelabel label) |
| 562 | drc_label_list::label_entry *drc_label_list::find_or_allocate(drcuml_codelabel label) |
| 648 | 563 | { |
| 649 | | drclabel *curlabel; |
| 650 | | |
| 651 | | /* find the label, or else allocate a new one */ |
| 652 | | for (curlabel = list->head; curlabel != NULL; curlabel = curlabel->next) |
| 653 | | if (curlabel->label == label) |
| 564 | // find the label, or else allocate a new one |
| 565 | label_entry *curlabel; |
| 566 | for (curlabel = m_list.first(); curlabel != NULL; curlabel = curlabel->next()) |
| 567 | if (curlabel->m_label == label) |
| 654 | 568 | break; |
| 655 | 569 | |
| 656 | | /* if none found, allocate */ |
| 570 | // if none found, allocate |
| 657 | 571 | if (curlabel == NULL) |
| 658 | 572 | { |
| 659 | | curlabel = (drclabel *)drccache_memory_alloc(list->cache, sizeof(*curlabel)); |
| 660 | | curlabel->next = list->head; |
| 661 | | curlabel->label = label; |
| 662 | | curlabel->codeptr = NULL; |
| 663 | | list->head = curlabel; |
| 573 | curlabel = (label_entry *)m_cache.alloc(sizeof(*curlabel)); |
| 574 | curlabel->m_label = label; |
| 575 | curlabel->m_codeptr = NULL; |
| 576 | m_list.append(*curlabel); |
| 664 | 577 | } |
| 665 | | |
| 666 | 578 | return curlabel; |
| 667 | 579 | } |
| 668 | 580 | |
| 669 | 581 | |
| 670 | | /*------------------------------------------------- |
| 671 | | label_oob_callback - out-of-band codegen |
| 672 | | callback for labels |
| 673 | | -------------------------------------------------*/ |
| 582 | //------------------------------------------------- |
| 583 | // oob_callback - out-of-band codegen callback |
| 584 | // for labels |
| 585 | //------------------------------------------------- |
| 674 | 586 | |
| 675 | | static void label_oob_callback(drccodeptr *codeptr, void *param1, void *param2, void *param3) |
| 587 | void drc_label_list::oob_callback(drccodeptr *codeptr, void *param1, void *param2, void *param3) |
| 676 | 588 | { |
| 677 | | drclabel *label = (drclabel *)param1; |
| 678 | | drclabel_fixup_func callback = (drclabel_fixup_func)param2; |
| 589 | label_entry *label = (label_entry *)param1; |
| 590 | fixup_func callback = (fixup_func)param2; |
| 679 | 591 | |
| 680 | | (*callback)(param3, label->codeptr); |
| 592 | (*callback)(param3, label->m_codeptr); |
| 681 | 593 | } |
src/emu/sound/disc_mth.c
| r10048 | r10049 | |
| 49 | 49 | |
| 50 | 50 | #include <float.h> |
| 51 | 51 | |
| 52 | | struct dst_comp_adder_context |
| 53 | | { |
| 54 | | double total[256]; |
| 55 | | }; |
| 56 | 52 | |
| 57 | | struct dst_bits_decode_context |
| 58 | | { |
| 59 | | int count; |
| 60 | | int decode_x_time; |
| 61 | | int from; |
| 62 | | int last_val; |
| 63 | | int last_had_x_time; |
| 64 | | }; |
| 65 | 53 | |
| 66 | | struct dst_dac_r1_context |
| 67 | | { |
| 68 | | double exponent; |
| 69 | | double last_v; |
| 70 | | double v_step[256]; |
| 71 | | int has_c_filter; |
| 72 | | }; |
| 73 | | |
| 74 | | struct dst_diode_mix_context |
| 75 | | { |
| 76 | | int size; |
| 77 | | double v_junction[8]; |
| 78 | | }; |
| 79 | | |
| 80 | | struct dst_flipflop_context |
| 81 | | { |
| 82 | | int last_clk; |
| 83 | | }; |
| 84 | | |
| 85 | | struct dst_integrate_context |
| 86 | | { |
| 87 | | double change; |
| 88 | | double v_max_in; /* v1 - norton VBE */ |
| 89 | | double v_max_in_d; /* v1 - norton VBE - diode drop */ |
| 90 | | double v_max_out; |
| 91 | | }; |
| 92 | | |
| 93 | | #define DISC_MIXER_MAX_INPS 8 |
| 94 | | |
| 95 | | struct dst_mixer_context |
| 96 | | { |
| 97 | | int type; |
| 98 | | int size; |
| 99 | | int r_node_bit_flag; |
| 100 | | int c_bit_flag; |
| 101 | | double r_total; |
| 102 | | double *r_node[DISC_MIXER_MAX_INPS]; /* Either pointer to resistance node output OR NULL */ |
| 103 | | double r_last[DISC_MIXER_MAX_INPS]; |
| 104 | | double exponent_rc[DISC_MIXER_MAX_INPS]; /* For high pass filtering cause by cIn */ |
| 105 | | double v_cap[DISC_MIXER_MAX_INPS]; /* cap voltage of each input */ |
| 106 | | double exponent_c_f; /* Low pass on mixed inputs */ |
| 107 | | double exponent_c_amp; /* Final high pass caused by out cap and amp input impedance */ |
| 108 | | double v_cap_f; /* cap voltage of cF */ |
| 109 | | double v_cap_amp; /* cap voltage of cAmp */ |
| 110 | | double gain; /* used for DISC_MIXER_IS_OP_AMP_WITH_RI */ |
| 111 | | }; |
| 112 | | |
| 113 | | struct dst_oneshot_context |
| 114 | | { |
| 115 | | double countdown; |
| 116 | | int state; |
| 117 | | int last_trig; |
| 118 | | int type; |
| 119 | | }; |
| 120 | | |
| 121 | | struct dst_ramp_context |
| 122 | | { |
| 123 | | double step; |
| 124 | | int dir; /* 1 if End is higher then Start */ |
| 125 | | int last_en; /* Keep track of the last enable value */ |
| 126 | | }; |
| 127 | | |
| 128 | | struct dst_samphold_context |
| 129 | | { |
| 130 | | double last_input; |
| 131 | | int clocktype; |
| 132 | | }; |
| 133 | | |
| 134 | | struct dst_shift_context |
| 135 | | { |
| 136 | | double t_left; /* time unused during last sample in seconds */ |
| 137 | | UINT32 shift_data; |
| 138 | | UINT32 bit_mask; |
| 139 | | UINT8 clock_type; |
| 140 | | UINT8 reset_on_high; |
| 141 | | UINT8 shift_r; |
| 142 | | UINT8 last; |
| 143 | | }; |
| 144 | | |
| 145 | | struct dst_size_context |
| 146 | | { |
| 147 | | int size; |
| 148 | | }; |
| 149 | | |
| 150 | | struct dst_op_amp_context |
| 151 | | { |
| 152 | | UINT8 has_cap; |
| 153 | | UINT8 has_r1; |
| 154 | | UINT8 has_r4; |
| 155 | | double v_max; |
| 156 | | double i_fixed; |
| 157 | | double v_cap; |
| 158 | | double exponent; |
| 159 | | }; |
| 160 | | |
| 161 | | struct dst_op_amp_1sht_context |
| 162 | | { |
| 163 | | double i_fixed; |
| 164 | | double v_max; |
| 165 | | double r34ratio; |
| 166 | | double v_cap1; |
| 167 | | double v_cap2; |
| 168 | | double exponent1c; |
| 169 | | double exponent1d; |
| 170 | | double exponent2; |
| 171 | | }; |
| 172 | | |
| 173 | | struct dst_tvca_op_amp_context |
| 174 | | { |
| 175 | | double v_out_max; /* Maximum output voltage */ |
| 176 | | double v_trig[2]; /* Voltage used to charge cap1 based on function F3 */ |
| 177 | | double v_trig2; /* Voltage used to charge cap2 */ |
| 178 | | double v_trig3; /* Voltage used to charge cap3 */ |
| 179 | | double i_fixed; /* Fixed current going into - input */ |
| 180 | | double exponent_c[2]; /* Charge exponents based on function F3 */ |
| 181 | | double exponent_d[2]; /* Discharge exponents based on function F3 */ |
| 182 | | double exponent2[2]; /* Discharge/charge exponents based on function F4 */ |
| 183 | | double exponent3[2]; /* Discharge/charge exponents based on function F5 */ |
| 184 | | double exponent4; /* Discharge/charge exponents for c4 */ |
| 185 | | double v_cap1; /* charge on cap c1 */ |
| 186 | | double v_cap2; /* charge on cap c2 */ |
| 187 | | double v_cap3; /* charge on cap c3 */ |
| 188 | | double v_cap4; /* charge on cap c4 */ |
| 189 | | double r67; /* = r6 + r7 (for easy use later) */ |
| 190 | | UINT8 has_c4; |
| 191 | | UINT8 has_r4; |
| 192 | | }; |
| 193 | | |
| 194 | | |
| 195 | 54 | /************************************************************************ |
| 196 | 55 | * |
| 197 | 56 | * DST_ADDER - This is a 4 channel input adder with enable function |
| r10048 | r10049 | |
| 213 | 72 | { |
| 214 | 73 | if(DST_ADDER__ENABLE) |
| 215 | 74 | { |
| 216 | | node->output[0] = DST_ADDER__IN0 + DST_ADDER__IN1 + DST_ADDER__IN2 + DST_ADDER__IN3; |
| 75 | this->output[0] = DST_ADDER__IN0 + DST_ADDER__IN1 + DST_ADDER__IN2 + DST_ADDER__IN3; |
| 217 | 76 | } |
| 218 | 77 | else |
| 219 | 78 | { |
| 220 | | node->output[0]=0; |
| 79 | this->output[0]=0; |
| 221 | 80 | } |
| 222 | 81 | } |
| 223 | 82 | |
| r10048 | r10049 | |
| 236 | 95 | |
| 237 | 96 | DISCRETE_STEP(dst_comp_adder) |
| 238 | 97 | { |
| 239 | | DISCRETE_DECLARE_CONTEXT(dst_comp_adder) |
| 240 | 98 | int select; |
| 241 | 99 | |
| 242 | 100 | select = (int)DST_COMP_ADDER__SELECT; |
| 243 | 101 | assert(select < 256); |
| 244 | | node->output[0] = context->total[select]; |
| 102 | this->output[0] = m_total[select]; |
| 245 | 103 | } |
| 246 | 104 | |
| 247 | 105 | DISCRETE_RESET(dst_comp_adder) |
| 248 | 106 | { |
| 249 | | DISCRETE_DECLARE_CONTEXT(dst_comp_adder) |
| 250 | 107 | DISCRETE_DECLARE_INFO(discrete_comp_adder_table) |
| 251 | 108 | |
| 252 | 109 | int i, bit; |
| r10048 | r10049 | |
| 261 | 118 | switch (info->type) |
| 262 | 119 | { |
| 263 | 120 | case DISC_COMP_P_CAPACITOR: |
| 264 | | context->total[i] = info->cDefault; |
| 121 | m_total[i] = info->cDefault; |
| 265 | 122 | for(bit = 0; bit < bit_length; bit++) |
| 266 | 123 | { |
| 267 | 124 | if (i & (1 << bit)) |
| 268 | | context->total[i] += info->c[bit]; |
| 125 | m_total[i] += info->c[bit]; |
| 269 | 126 | } |
| 270 | 127 | break; |
| 271 | 128 | case DISC_COMP_P_RESISTOR: |
| 272 | | context->total[i] = (info->cDefault != 0) ? 1.0 / info->cDefault : 0; |
| 129 | m_total[i] = (info->cDefault != 0) ? 1.0 / info->cDefault : 0; |
| 273 | 130 | for(bit = 0; bit < bit_length; bit++) |
| 274 | 131 | { |
| 275 | 132 | if ((i & (1 << bit)) && (info->c[bit] != 0)) |
| 276 | | context->total[i] += 1.0 / info->c[bit]; |
| 133 | m_total[i] += 1.0 / info->c[bit]; |
| 277 | 134 | } |
| 278 | | if (context->total[i] != 0) |
| 279 | | context->total[i] = 1.0 / context->total[i]; |
| 135 | if (m_total[i] != 0) |
| 136 | m_total[i] = 1.0 / m_total[i]; |
| 280 | 137 | break; |
| 281 | 138 | } |
| 282 | 139 | } |
| 283 | | node->output[0] = context->total[0]; |
| 140 | this->output[0] = m_total[0]; |
| 284 | 141 | } |
| 285 | 142 | |
| 286 | 143 | /************************************************************************ |
| r10048 | r10049 | |
| 298 | 155 | |
| 299 | 156 | DISCRETE_STEP(dst_clamp) |
| 300 | 157 | { |
| 301 | | if (DST_CLAMP__IN < DST_CLAMP__MIN) node->output[0] = DST_CLAMP__MIN; |
| 302 | | else if (DST_CLAMP__IN > DST_CLAMP__MAX) node->output[0] = DST_CLAMP__MAX; |
| 303 | | else node->output[0]= DST_CLAMP__IN; |
| 158 | if (DST_CLAMP__IN < DST_CLAMP__MIN) this->output[0] = DST_CLAMP__MIN; |
| 159 | else if (DST_CLAMP__IN > DST_CLAMP__MAX) this->output[0] = DST_CLAMP__MAX; |
| 160 | else this->output[0]= DST_CLAMP__IN; |
| 304 | 161 | } |
| 305 | 162 | |
| 306 | 163 | |
| r10048 | r10049 | |
| 321 | 178 | |
| 322 | 179 | DISCRETE_STEP(dst_dac_r1) |
| 323 | 180 | { |
| 324 | | DISCRETE_DECLARE_CONTEXT(dst_dac_r1) |
| 325 | | |
| 326 | 181 | int data = (int)DST_DAC_R1__DATA; |
| 327 | | double v = context->v_step[data]; |
| 182 | double v = m_v_step[data]; |
| 328 | 183 | double x_time = DST_DAC_R1__DATA - data; |
| 329 | | double last_v = context->last_v; |
| 184 | double last_v = m_last_v; |
| 330 | 185 | |
| 331 | | context->last_v = v; |
| 186 | m_last_v = v; |
| 332 | 187 | |
| 333 | 188 | if (x_time > 0) |
| 334 | 189 | v = x_time * (v - last_v) + last_v; |
| 335 | 190 | |
| 336 | 191 | /* Filter if needed, else just output voltage */ |
| 337 | | if (context->has_c_filter) |
| 192 | if (m_has_c_filter) |
| 338 | 193 | { |
| 339 | | double out = node->output[0]; |
| 194 | double out = this->output[0]; |
| 340 | 195 | double v_diff = v - out; |
| 341 | 196 | /* optimization - if charged close enough to voltage */ |
| 342 | 197 | if (fabs(v_diff) < 0.000001) |
| 343 | | node->output[0] = v; |
| 198 | this->output[0] = v; |
| 344 | 199 | else |
| 345 | 200 | { |
| 346 | | out += v_diff * context->exponent; |
| 347 | | node->output[0] = out; |
| 201 | out += v_diff * m_exponent; |
| 202 | this->output[0] = out; |
| 348 | 203 | } |
| 349 | 204 | } |
| 350 | 205 | else |
| 351 | | node->output[0] = v; |
| 206 | this->output[0] = v; |
| 352 | 207 | } |
| 353 | 208 | |
| 354 | 209 | DISCRETE_RESET(dst_dac_r1) |
| 355 | 210 | { |
| 356 | | DISCRETE_DECLARE_CONTEXT(dst_dac_r1) |
| 357 | 211 | DISCRETE_DECLARE_INFO(discrete_dac_r1_ladder) |
| 358 | 212 | |
| 359 | 213 | int bit; |
| r10048 | r10049 | |
| 363 | 217 | double i_bias; |
| 364 | 218 | double v_on = DST_DAC_R1__VON; |
| 365 | 219 | |
| 366 | | context->last_v = 0; |
| 220 | m_last_v = 0; |
| 367 | 221 | |
| 368 | 222 | /* Calculate the Millman current of the bias circuit */ |
| 369 | 223 | if (info->rBias > 0) |
| r10048 | r10049 | |
| 379 | 233 | if (ladderLength < 2 && info->rBias == 0 && info->rGnd == 0) |
| 380 | 234 | { |
| 381 | 235 | /* You need at least 2 resistors for a ladder */ |
| 382 | | discrete_log(node->info, "dst_dac_r1_reset - Ladder length too small"); |
| 236 | this->device->discrete_log("dst_dac_r1_reset - Ladder length too small"); |
| 383 | 237 | } |
| 384 | 238 | if (ladderLength > DISC_LADDER_MAXRES ) |
| 385 | 239 | { |
| 386 | | discrete_log(node->info, "dst_dac_r1_reset - Ladder length exceeds DISC_LADDER_MAXRES"); |
| 240 | this->device->discrete_log("dst_dac_r1_reset - Ladder length exceeds DISC_LADDER_MAXRES"); |
| 387 | 241 | } |
| 388 | 242 | |
| 389 | 243 | /* |
| r10048 | r10049 | |
| 400 | 254 | if (info->rGnd > 0) r_total += 1.0 / info->rGnd; |
| 401 | 255 | r_total = 1.0 / r_total; |
| 402 | 256 | |
| 403 | | node->output[0] = 0; |
| 257 | this->output[0] = 0; |
| 404 | 258 | |
| 405 | 259 | if (info->cFilter > 0) |
| 406 | 260 | { |
| 407 | | context->has_c_filter = 1; |
| 261 | m_has_c_filter = 1; |
| 408 | 262 | /* Setup filter constant */ |
| 409 | | context->exponent = RC_CHARGE_EXP(r_total * info->cFilter); |
| 263 | m_exponent = RC_CHARGE_EXP_CLASS(r_total * info->cFilter); |
| 410 | 264 | } |
| 411 | 265 | else |
| 412 | | context->has_c_filter = 0; |
| 266 | m_has_c_filter = 0; |
| 413 | 267 | |
| 414 | 268 | /* pre-calculate all possible values to speed up step routine */ |
| 415 | 269 | for(int i = 0; i < total_steps; i++) |
| r10048 | r10049 | |
| 432 | 286 | i_total += i_bit; |
| 433 | 287 | } |
| 434 | 288 | } |
| 435 | | context->v_step[i] = i_total * r_total; |
| 289 | m_v_step[i] = i_total * r_total; |
| 436 | 290 | } |
| 437 | 291 | } |
| 438 | 292 | |
| r10048 | r10049 | |
| 451 | 305 | |
| 452 | 306 | DISCRETE_STEP(dst_diode_mix) |
| 453 | 307 | { |
| 454 | | DISCRETE_DECLARE_CONTEXT(dst_diode_mix) |
| 455 | | |
| 456 | 308 | double val, max = 0; |
| 457 | 309 | int addr; |
| 458 | 310 | |
| 459 | | for (addr = 0; addr < context->size; addr++) |
| 311 | for (addr = 0; addr < m_size; addr++) |
| 460 | 312 | { |
| 461 | | val = DST_DIODE_MIX__INP(addr) - context->v_junction[addr]; |
| 313 | val = DST_DIODE_MIX__INP(addr) - m_v_junction[addr]; |
| 462 | 314 | if (val > max) max = val; |
| 463 | 315 | } |
| 464 | 316 | if (max < 0) max = 0; |
| 465 | | node->output[0] = max; |
| 317 | this->output[0] = max; |
| 466 | 318 | } |
| 467 | 319 | |
| 468 | 320 | DISCRETE_RESET(dst_diode_mix) |
| 469 | 321 | { |
| 470 | | DISCRETE_DECLARE_CONTEXT(dst_diode_mix) |
| 471 | 322 | DISCRETE_DECLARE_INFO(double) |
| 472 | 323 | |
| 473 | 324 | int addr; |
| 474 | 325 | |
| 475 | | context->size = node->active_inputs() - DST_DIODE_MIX_INP_OFFSET; |
| 476 | | assert(context->size <= 8); |
| 326 | m_size = this->active_inputs() - DST_DIODE_MIX_INP_OFFSET; |
| 327 | assert(m_size <= 8); |
| 477 | 328 | |
| 478 | | for (addr = 0; addr < context->size; addr++) |
| 329 | for (addr = 0; addr < m_size; addr++) |
| 479 | 330 | { |
| 480 | 331 | if (info == NULL) |
| 481 | 332 | { |
| 482 | 333 | /* setup default junction voltage */ |
| 483 | | context->v_junction[addr] = 0.5; |
| 334 | m_v_junction[addr] = 0.5; |
| 484 | 335 | } |
| 485 | 336 | else |
| 486 | 337 | { |
| 487 | 338 | /* use supplied junction voltage */ |
| 488 | | context->v_junction[addr] = *info++; |
| 339 | m_v_junction[addr] = *info++; |
| 489 | 340 | } |
| 490 | 341 | } |
| 491 | | DISCRETE_STEP_CALL(dst_diode_mix); |
| 342 | this->step(); |
| 492 | 343 | } |
| 493 | 344 | |
| 494 | 345 | |
| r10048 | r10049 | |
| 511 | 362 | { |
| 512 | 363 | if(DST_DIVIDE__DIV == 0) |
| 513 | 364 | { |
| 514 | | node->output[0 ]= DBL_MAX; /* Max out but don't break */ |
| 515 | | discrete_log(node->info, "dst_divider_step() - Divide by Zero attempted in NODE_%02d.\n",node->index()); |
| 365 | this->output[0 ]= DBL_MAX; /* Max out but don't break */ |
| 366 | this->device->discrete_log("dst_divider_step() - Divide by Zero attempted in NODE_%02d.\n",this->index()); |
| 516 | 367 | } |
| 517 | 368 | else |
| 518 | 369 | { |
| 519 | | node->output[0]= DST_DIVIDE__IN / DST_DIVIDE__DIV; |
| 370 | this->output[0]= DST_DIVIDE__IN / DST_DIVIDE__DIV; |
| 520 | 371 | } |
| 521 | 372 | } |
| 522 | 373 | else |
| 523 | 374 | { |
| 524 | | node->output[0]=0; |
| 375 | this->output[0]=0; |
| 525 | 376 | } |
| 526 | 377 | } |
| 527 | 378 | |
| r10048 | r10049 | |
| 541 | 392 | |
| 542 | 393 | DISCRETE_STEP(dst_gain) |
| 543 | 394 | { |
| 544 | | node->output[0] = DST_GAIN__IN * DST_GAIN__GAIN + DST_GAIN__OFFSET; |
| 395 | this->output[0] = DST_GAIN__IN * DST_GAIN__GAIN + DST_GAIN__OFFSET; |
| 545 | 396 | } |
| 546 | 397 | |
| 547 | 398 | |
| r10048 | r10049 | |
| 595 | 446 | |
| 596 | 447 | DISCRETE_STEP(dst_integrate) |
| 597 | 448 | { |
| 598 | | DISCRETE_DECLARE_CONTEXT(dst_integrate) |
| 599 | 449 | DISCRETE_DECLARE_INFO(discrete_integrate_info) |
| 600 | 450 | |
| 601 | 451 | int trig0, trig1; |
| r10048 | r10049 | |
| 610 | 460 | /* This forces the cap to completely charge, |
| 611 | 461 | * and the output to go to it's max value. |
| 612 | 462 | */ |
| 613 | | node->output[0] = context->v_max_out; |
| 463 | this->output[0] = m_v_max_out; |
| 614 | 464 | return; |
| 615 | 465 | } |
| 616 | | node->output[0] -= context->change; |
| 466 | this->output[0] -= m_change; |
| 617 | 467 | break; |
| 618 | 468 | |
| 619 | 469 | case DISC_INTEGRATE_OP_AMP_1 | DISC_OP_AMP_IS_NORTON: |
| 620 | | i_neg = context->v_max_in / info->r1; |
| 470 | i_neg = m_v_max_in / info->r1; |
| 621 | 471 | i_pos = (DST_INTEGRATE__TRG0 - OP_AMP_NORTON_VBE) / info->r2; |
| 622 | 472 | if (i_pos < 0) i_pos = 0; |
| 623 | | node->output[0] += (i_pos - i_neg) / node->info->sample_rate / info->c; |
| 473 | this->output[0] += (i_pos - i_neg) / this->sample_rate() / info->c; |
| 624 | 474 | break; |
| 625 | 475 | |
| 626 | 476 | case DISC_INTEGRATE_OP_AMP_2 | DISC_OP_AMP_IS_NORTON: |
| 627 | 477 | trig0 = (int)DST_INTEGRATE__TRG0; |
| 628 | 478 | trig1 = (int)DST_INTEGRATE__TRG1; |
| 629 | | i_neg = dst_trigger_function(trig0, trig1, 0, info->f0) ? context->v_max_in_d / info->r1 : 0; |
| 630 | | i_pos = dst_trigger_function(trig0, trig1, 0, info->f1) ? context->v_max_in / info->r2 : 0; |
| 631 | | i_pos += dst_trigger_function(trig0, trig1, 0, info->f2) ? context->v_max_in_d / info->r3 : 0; |
| 632 | | node->output[0] += (i_pos - i_neg) / node->info->sample_rate / info->c; |
| 479 | i_neg = dst_trigger_function(trig0, trig1, 0, info->f0) ? m_v_max_in_d / info->r1 : 0; |
| 480 | i_pos = dst_trigger_function(trig0, trig1, 0, info->f1) ? m_v_max_in / info->r2 : 0; |
| 481 | i_pos += dst_trigger_function(trig0, trig1, 0, info->f2) ? m_v_max_in_d / info->r3 : 0; |
| 482 | this->output[0] += (i_pos - i_neg) / this->sample_rate() / info->c; |
| 633 | 483 | break; |
| 634 | 484 | } |
| 635 | 485 | |
| 636 | 486 | /* Clip the output. */ |
| 637 | | if (node->output[0] < 0) node->output[0] = 0; |
| 638 | | if (node->output[0] > context->v_max_out) node->output[0] = context->v_max_out; |
| 487 | if (this->output[0] < 0) this->output[0] = 0; |
| 488 | if (this->output[0] > m_v_max_out) this->output[0] = m_v_max_out; |
| 639 | 489 | } |
| 640 | 490 | |
| 641 | 491 | DISCRETE_RESET(dst_integrate) |
| 642 | 492 | { |
| 643 | | DISCRETE_DECLARE_CONTEXT(dst_integrate) |
| 644 | 493 | DISCRETE_DECLARE_INFO(discrete_integrate_info) |
| 645 | 494 | |
| 646 | 495 | double i, v; |
| 647 | 496 | |
| 648 | 497 | if (info->type & DISC_OP_AMP_IS_NORTON) |
| 649 | 498 | { |
| 650 | | context->v_max_out = info->vP - OP_AMP_NORTON_VBE; |
| 651 | | context->v_max_in = info->v1 - OP_AMP_NORTON_VBE; |
| 652 | | context->v_max_in_d = context->v_max_in - OP_AMP_NORTON_VBE; |
| 499 | m_v_max_out = info->vP - OP_AMP_NORTON_VBE; |
| 500 | m_v_max_in = info->v1 - OP_AMP_NORTON_VBE; |
| 501 | m_v_max_in_d = m_v_max_in - OP_AMP_NORTON_VBE; |
| 653 | 502 | } |
| 654 | 503 | else |
| 655 | 504 | { |
| 656 | | context->v_max_out = info->vP - OP_AMP_VP_RAIL_OFFSET; |
| 505 | m_v_max_out = info->vP - OP_AMP_VP_RAIL_OFFSET; |
| 657 | 506 | |
| 658 | 507 | v = info->v1 * info->r3 / (info->r2 + info->r3); /* vRef */ |
| 659 | 508 | v = info->v1 - v; /* actual charging voltage */ |
| 660 | 509 | i = v / info->r1; |
| 661 | | context->change = i / node->info->sample_rate / info->c; |
| 510 | m_change = i / this->sample_rate() / info->c; |
| 662 | 511 | } |
| 663 | | node->output[0] = 0; |
| 512 | this->output[0] = 0; |
| 664 | 513 | } |
| 665 | 514 | |
| 666 | 515 | |
| r10048 | r10049 | |
| 676 | 525 | |
| 677 | 526 | DISCRETE_STEP(dst_logic_inv) |
| 678 | 527 | { |
| 679 | | node->output[0] = DST_LOGIC_INV__IN ? 0.0 : 1.0; |
| 528 | this->output[0] = DST_LOGIC_INV__IN ? 0.0 : 1.0; |
| 680 | 529 | } |
| 681 | 530 | |
| 682 | 531 | /************************************************************************ |
| r10048 | r10049 | |
| 691 | 540 | |
| 692 | 541 | DISCRETE_STEP(dst_bits_decode) |
| 693 | 542 | { |
| 694 | | DISCRETE_DECLARE_CONTEXT(dst_bits_decode) |
| 695 | | |
| 696 | 543 | int new_val = DST_BITS_DECODE__IN; |
| 697 | | int last_val = context->last_val; |
| 698 | | int last_had_x_time = context->last_had_x_time; |
| 544 | int last_val = m_last_val; |
| 545 | int last_had_x_time = m_last_had_x_time; |
| 699 | 546 | |
| 700 | 547 | if (last_val != new_val || last_had_x_time) |
| 701 | 548 | { |
| 702 | 549 | int i, new_bit, last_bit, last_bit_had_x_time, bit_changed; |
| 703 | 550 | double x_time = DST_BITS_DECODE__IN - new_val; |
| 704 | | int from = context->from; |
| 705 | | int count = context->count; |
| 706 | | int decode_x_time = context->decode_x_time; |
| 551 | int from = m_from; |
| 552 | int count = m_count; |
| 553 | int decode_x_time = m_decode_x_time; |
| 707 | 554 | int has_x_time = x_time > 0 ? 1 : 0; |
| 708 | 555 | double out = 0; |
| 709 | 556 | double v_out = DST_BITS_DECODE__VOUT; |
| r10048 | r10049 | |
| 737 | 584 | else |
| 738 | 585 | out *= new_bit; |
| 739 | 586 | } |
| 740 | | node->output[i] = out; |
| 587 | this->output[i] = out; |
| 741 | 588 | if (has_x_time && bit_changed) |
| 742 | 589 | /* set */ |
| 743 | | context->last_had_x_time |= 1 << (i + from); |
| 590 | m_last_had_x_time |= 1 << (i + from); |
| 744 | 591 | else |
| 745 | 592 | /* clear */ |
| 746 | | context->last_had_x_time &= ~(1 << (i + from)); |
| 593 | m_last_had_x_time &= ~(1 << (i + from)); |
| 747 | 594 | } |
| 748 | | context->last_val = new_val; |
| 595 | m_last_val = new_val; |
| 749 | 596 | } |
| 750 | 597 | } |
| 751 | 598 | |
| 752 | 599 | DISCRETE_RESET(dst_bits_decode) |
| 753 | 600 | { |
| 754 | | DISCRETE_DECLARE_CONTEXT(dst_bits_decode) |
| 755 | | |
| 756 | | context->from = DST_BITS_DECODE__FROM; |
| 757 | | context->count = DST_BITS_DECODE__TO - context->from + 1; |
| 601 | m_from = DST_BITS_DECODE__FROM; |
| 602 | m_count = DST_BITS_DECODE__TO - m_from + 1; |
| 758 | 603 | if (DST_BITS_DECODE__VOUT == 0) |
| 759 | | context->decode_x_time = 1; |
| 604 | m_decode_x_time = 1; |
| 760 | 605 | else |
| 761 | | context->decode_x_time = 0; |
| 762 | | context->last_had_x_time = 0; |
| 606 | m_decode_x_time = 0; |
| 607 | m_last_had_x_time = 0; |
| 763 | 608 | |
| 764 | | DISCRETE_STEP_CALL(dst_bits_decode); |
| 609 | this->step(); |
| 765 | 610 | } |
| 766 | 611 | |
| 767 | 612 | |
| r10048 | r10049 | |
| 782 | 627 | |
| 783 | 628 | DISCRETE_STEP(dst_logic_and) |
| 784 | 629 | { |
| 785 | | node->output[0] = (DST_LOGIC_AND__IN0 && DST_LOGIC_AND__IN1 && DST_LOGIC_AND__IN2 && DST_LOGIC_AND__IN3)? 1.0 : 0.0; |
| 630 | this->output[0] = (DST_LOGIC_AND__IN0 && DST_LOGIC_AND__IN1 && DST_LOGIC_AND__IN2 && DST_LOGIC_AND__IN3)? 1.0 : 0.0; |
| 786 | 631 | } |
| 787 | 632 | |
| 788 | 633 | /************************************************************************ |
| r10048 | r10049 | |
| 802 | 647 | |
| 803 | 648 | DISCRETE_STEP(dst_logic_nand) |
| 804 | 649 | { |
| 805 | | node->output[0]= (DST_LOGIC_NAND__IN0 && DST_LOGIC_NAND__IN1 && DST_LOGIC_NAND__IN2 && DST_LOGIC_NAND__IN3)? 0.0 : 1.0; |
| 650 | this->output[0]= (DST_LOGIC_NAND__IN0 && DST_LOGIC_NAND__IN1 && DST_LOGIC_NAND__IN2 && DST_LOGIC_NAND__IN3)? 0.0 : 1.0; |
| 806 | 651 | } |
| 807 | 652 | |
| 808 | 653 | /************************************************************************ |
| r10048 | r10049 | |
| 822 | 667 | |
| 823 | 668 | DISCRETE_STEP(dst_logic_or) |
| 824 | 669 | { |
| 825 | | node->output[0] = (DST_LOGIC_OR__IN0 || DST_LOGIC_OR__IN1 || DST_LOGIC_OR__IN2 || DST_LOGIC_OR__IN3) ? 1.0 : 0.0; |
| 670 | this->output[0] = (DST_LOGIC_OR__IN0 || DST_LOGIC_OR__IN1 || DST_LOGIC_OR__IN2 || DST_LOGIC_OR__IN3) ? 1.0 : 0.0; |
| 826 | 671 | } |
| 827 | 672 | |
| 828 | 673 | /************************************************************************ |
| r10048 | r10049 | |
| 842 | 687 | |
| 843 | 688 | DISCRETE_STEP(dst_logic_nor) |
| 844 | 689 | { |
| 845 | | node->output[0] = (DST_LOGIC_NOR__IN0 || DST_LOGIC_NOR__IN1 || DST_LOGIC_NOR__IN2 || DST_LOGIC_NOR__IN3) ? 0.0 : 1.0; |
| 690 | this->output[0] = (DST_LOGIC_NOR__IN0 || DST_LOGIC_NOR__IN1 || DST_LOGIC_NOR__IN2 || DST_LOGIC_NOR__IN3) ? 0.0 : 1.0; |
| 846 | 691 | } |
| 847 | 692 | |
| 848 | 693 | /************************************************************************ |
| r10048 | r10049 | |
| 858 | 703 | |
| 859 | 704 | DISCRETE_STEP(dst_logic_xor) |
| 860 | 705 | { |
| 861 | | node->output[0] = ((DST_LOGIC_XOR__IN0 && !DST_LOGIC_XOR__IN1) || (!DST_LOGIC_XOR__IN0 && DST_LOGIC_XOR__IN1)) ? 1.0 : 0.0; |
| 706 | this->output[0] = ((DST_LOGIC_XOR__IN0 && !DST_LOGIC_XOR__IN1) || (!DST_LOGIC_XOR__IN0 && DST_LOGIC_XOR__IN1)) ? 1.0 : 0.0; |
| 862 | 707 | } |
| 863 | 708 | |
| 864 | 709 | /************************************************************************ |
| r10048 | r10049 | |
| 874 | 719 | |
| 875 | 720 | DISCRETE_STEP(dst_logic_nxor) |
| 876 | 721 | { |
| 877 | | node->output[0] = ((DST_LOGIC_XNOR__IN0 && !DST_LOGIC_XNOR__IN1) || (!DST_LOGIC_XNOR__IN0 && DST_LOGIC_XNOR__IN1)) ? 0.0 : 1.0; |
| 722 | this->output[0] = ((DST_LOGIC_XNOR__IN0 && !DST_LOGIC_XNOR__IN1) || (!DST_LOGIC_XNOR__IN0 && DST_LOGIC_XNOR__IN1)) ? 0.0 : 1.0; |
| 878 | 723 | } |
| 879 | 724 | |
| 880 | 725 | |
| r10048 | r10049 | |
| 895 | 740 | |
| 896 | 741 | DISCRETE_STEP(dst_logic_dff) |
| 897 | 742 | { |
| 898 | | DISCRETE_DECLARE_CONTEXT(dst_flipflop) |
| 899 | | |
| 900 | 743 | int clk = (int)DST_LOGIC_DFF__CLOCK; |
| 901 | 744 | |
| 902 | 745 | if (DST_LOGIC_DFF__RESET) |
| 903 | | node->output[0] = 0; |
| 746 | this->output[0] = 0; |
| 904 | 747 | else if (DST_LOGIC_DFF__SET) |
| 905 | | node->output[0] = 1; |
| 906 | | else if (!context->last_clk && clk) /* low to high */ |
| 907 | | node->output[0] = DST_LOGIC_DFF__DATA; |
| 908 | | context->last_clk = clk; |
| 748 | this->output[0] = 1; |
| 749 | else if (!m_last_clk && clk) /* low to high */ |
| 750 | this->output[0] = DST_LOGIC_DFF__DATA; |
| 751 | m_last_clk = clk; |
| 909 | 752 | } |
| 910 | 753 | |
| 911 | | DISCRETE_RESET(dst_logic_ff) |
| 754 | DISCRETE_RESET(dst_logic_dff) |
| 912 | 755 | { |
| 913 | | DISCRETE_DECLARE_CONTEXT(dst_flipflop) |
| 914 | | |
| 915 | | |
| 916 | | context->last_clk = 0; |
| 917 | | node->output[0] = 0; |
| 756 | m_last_clk = 0; |
| 757 | this->output[0] = 0; |
| 918 | 758 | } |
| 919 | 759 | |
| 920 | 760 | |
| r10048 | r10049 | |
| 937 | 777 | |
| 938 | 778 | DISCRETE_STEP(dst_logic_jkff) |
| 939 | 779 | { |
| 940 | | DISCRETE_DECLARE_CONTEXT(dst_flipflop) |
| 941 | | |
| 942 | 780 | int clk = (int)DST_LOGIC_JKFF__CLOCK; |
| 943 | 781 | int j = (int)DST_LOGIC_JKFF__J; |
| 944 | 782 | int k = (int)DST_LOGIC_JKFF__K; |
| 945 | 783 | |
| 946 | 784 | if (DST_LOGIC_JKFF__RESET) |
| 947 | | node->output[0] = 0; |
| 785 | this->output[0] = 0; |
| 948 | 786 | else if (DST_LOGIC_JKFF__SET) |
| 949 | | node->output[0] = 1; |
| 950 | | else if (context->last_clk && !clk) /* high to low */ |
| 787 | this->output[0] = 1; |
| 788 | else if (m_last_clk && !clk) /* high to low */ |
| 951 | 789 | { |
| 952 | 790 | if (!j) |
| 953 | 791 | { |
| 954 | 792 | /* J=0, K=0 - Hold */ |
| 955 | 793 | if (k) |
| 956 | 794 | /* J=0, K=1 - Reset */ |
| 957 | | node->output[0] = 0; |
| 795 | this->output[0] = 0; |
| 958 | 796 | } |
| 959 | 797 | else |
| 960 | 798 | { |
| 961 | 799 | if (!k) |
| 962 | 800 | /* J=1, K=0 - Set */ |
| 963 | | node->output[0] = 1; |
| 801 | this->output[0] = 1; |
| 964 | 802 | else |
| 965 | 803 | /* J=1, K=1 - Toggle */ |
| 966 | | node->output[0] = !(int)node->output[0]; |
| 804 | this->output[0] = !(int)this->output[0]; |
| 967 | 805 | } |
| 968 | 806 | } |
| 969 | | context->last_clk = clk; |
| 807 | m_last_clk = clk; |
| 970 | 808 | } |
| 971 | 809 | |
| 810 | DISCRETE_RESET(dst_logic_jkff) |
| 811 | { |
| 812 | m_last_clk = 0; |
| 813 | this->output[0] = 0; |
| 814 | } |
| 972 | 815 | |
| 973 | 816 | /************************************************************************ |
| 974 | 817 | * |
| r10048 | r10049 | |
| 983 | 826 | |
| 984 | 827 | DISCRETE_STEP(dst_logic_shift) |
| 985 | 828 | { |
| 986 | | DISCRETE_DECLARE_CONTEXT(dst_shift) |
| 987 | | |
| 988 | 829 | double cycles; |
| 989 | 830 | double ds_clock; |
| 990 | 831 | int clock = 0, inc = 0; |
| 991 | 832 | |
| 992 | 833 | int input_bit = (DST_LOGIC_SHIFT__IN != 0) ? 1 : 0; |
| 993 | 834 | ds_clock = DST_LOGIC_SHIFT__CLK; |
| 994 | | if (context->clock_type == DISC_CLK_IS_FREQ) |
| 835 | if (m_clock_type == DISC_CLK_IS_FREQ) |
| 995 | 836 | { |
| 996 | 837 | /* We need to keep clocking the internal clock even if in reset. */ |
| 997 | | cycles = (context->t_left + node->info->sample_time) * ds_clock; |
| 838 | cycles = (m_t_left + this->sample_time()) * ds_clock; |
| 998 | 839 | inc = (int)cycles; |
| 999 | | context->t_left = (cycles - inc) / ds_clock; |
| 840 | m_t_left = (cycles - inc) / ds_clock; |
| 1000 | 841 | } |
| 1001 | 842 | else |
| 1002 | 843 | { |
| r10048 | r10049 | |
| 1004 | 845 | } |
| 1005 | 846 | |
| 1006 | 847 | /* If reset enabled then set output to the reset value. No x_time in reset. */ |
| 1007 | | if(((DST_LOGIC_SHIFT__RESET == 0) ? 0 : 1) == context->reset_on_high) |
| 848 | if(((DST_LOGIC_SHIFT__RESET == 0) ? 0 : 1) == m_reset_on_high) |
| 1008 | 849 | { |
| 1009 | | context->shift_data = 0; |
| 1010 | | node->output[0] = 0; |
| 850 | m_shift_data = 0; |
| 851 | this->output[0] = 0; |
| 1011 | 852 | return; |
| 1012 | 853 | } |
| 1013 | 854 | |
| 1014 | 855 | /* increment clock */ |
| 1015 | | switch (context->clock_type) |
| 856 | switch (m_clock_type) |
| 1016 | 857 | { |
| 1017 | 858 | case DISC_CLK_ON_F_EDGE: |
| 1018 | 859 | case DISC_CLK_ON_R_EDGE: |
| 1019 | 860 | /* See if the clock has toggled to the proper edge */ |
| 1020 | 861 | clock = (clock != 0); |
| 1021 | | if (context->last != clock) |
| 862 | if (m_last != clock) |
| 1022 | 863 | { |
| 1023 | | context->last = clock; |
| 1024 | | if (context->clock_type == clock) |
| 864 | m_last = clock; |
| 865 | if (m_clock_type == clock) |
| 1025 | 866 | { |
| 1026 | 867 | /* Toggled */ |
| 1027 | 868 | inc = 1; |
| r10048 | r10049 | |
| 1037 | 878 | |
| 1038 | 879 | if (inc > 0) |
| 1039 | 880 | { |
| 1040 | | if (context->shift_r) |
| 881 | if (m_shift_r) |
| 1041 | 882 | { |
| 1042 | | context->shift_data >>= 1; |
| 1043 | | context->shift_data |= input_bit << ((int)DST_LOGIC_SHIFT__SIZE - 1); |
| 883 | m_shift_data >>= 1; |
| 884 | m_shift_data |= input_bit << ((int)DST_LOGIC_SHIFT__SIZE - 1); |
| 1044 | 885 | inc--; |
| 1045 | | context->shift_data >>= inc; |
| 886 | m_shift_data >>= inc; |
| 1046 | 887 | } |
| 1047 | 888 | else |
| 1048 | 889 | { |
| 1049 | | context->shift_data <<= 1; |
| 1050 | | context->shift_data |= input_bit; |
| 890 | m_shift_data <<= 1; |
| 891 | m_shift_data |= input_bit; |
| 1051 | 892 | inc--; |
| 1052 | | context->shift_data <<= inc; |
| 893 | m_shift_data <<= inc; |
| 1053 | 894 | } |
| 1054 | | context->shift_data &= context->bit_mask; |
| 895 | m_shift_data &= m_bit_mask; |
| 1055 | 896 | } |
| 1056 | 897 | |
| 1057 | | node->output[0] = context->shift_data; |
| 898 | this->output[0] = m_shift_data; |
| 1058 | 899 | } |
| 1059 | 900 | |
| 1060 | 901 | DISCRETE_RESET(dst_logic_shift) |
| 1061 | 902 | { |
| 1062 | | DISCRETE_DECLARE_CONTEXT(dst_shift) |
| 903 | m_bit_mask = (1 << (int)DST_LOGIC_SHIFT__SIZE) - 1; |
| 904 | m_clock_type = (int)DST_LOGIC_SHIFT__OPTIONS & DISC_CLK_MASK; |
| 905 | m_reset_on_high = ((int)DST_LOGIC_SHIFT__OPTIONS & DISC_LOGIC_SHIFT__RESET_H) ? 1 : 0; |
| 906 | m_shift_r = ((int)DST_LOGIC_SHIFT__OPTIONS & DISC_LOGIC_SHIFT__RIGHT) ? 1 : 0; |
| 1063 | 907 | |
| 1064 | | context->bit_mask = (1 << (int)DST_LOGIC_SHIFT__SIZE) - 1; |
| 1065 | | context->clock_type = (int)DST_LOGIC_SHIFT__OPTIONS & DISC_CLK_MASK; |
| 1066 | | context->reset_on_high = ((int)DST_LOGIC_SHIFT__OPTIONS & DISC_LOGIC_SHIFT__RESET_H) ? 1 : 0; |
| 1067 | | context->shift_r = ((int)DST_LOGIC_SHIFT__OPTIONS & DISC_LOGIC_SHIFT__RIGHT) ? 1 : 0; |
| 1068 | | |
| 1069 | | context->t_left = 0; |
| 1070 | | context->last = 0; |
| 1071 | | context->shift_data = 0; |
| 1072 | | node->output[0] = 0; |
| 908 | m_t_left = 0; |
| 909 | m_last = 0; |
| 910 | m_shift_data = 0; |
| 911 | this->output[0] = 0; |
| 1073 | 912 | } |
| 1074 | 913 | |
| 1075 | 914 | /************************************************************************ |
| r10048 | r10049 | |
| 1093 | 932 | int addr = DST_LOOKUP_TABLE__IN; |
| 1094 | 933 | |
| 1095 | 934 | if (addr < 0 || addr >= DST_LOOKUP_TABLE__SIZE) |
| 1096 | | node->output[0] = 0; |
| 935 | this->output[0] = 0; |
| 1097 | 936 | else |
| 1098 | | node->output[0] = info[addr]; |
| 937 | this->output[0] = info[addr]; |
| 1099 | 938 | } |
| 1100 | 939 | |
| 1101 | 940 | |
| r10048 | r10049 | |
| 1154 | 993 | |
| 1155 | 994 | DISCRETE_STEP(dst_mixer) |
| 1156 | 995 | { |
| 1157 | | DISCRETE_DECLARE_CONTEXT(dst_mixer) |
| 1158 | 996 | DISCRETE_DECLARE_INFO(discrete_mixer_desc) |
| 1159 | 997 | |
| 1160 | 998 | double v, vTemp, r_total, rTemp, rTemp2 = 0; |
| r10048 | r10049 | |
| 1162 | 1000 | int bit, connected; |
| 1163 | 1001 | |
| 1164 | 1002 | /* put commonly used stuff in local variables for speed */ |
| 1165 | | int r_node_bit_flag = context->r_node_bit_flag; |
| 1166 | | int c_bit_flag = context->c_bit_flag; |
| 1003 | int r_node_bit_flag = m_r_node_bit_flag; |
| 1004 | int c_bit_flag = m_c_bit_flag; |
| 1167 | 1005 | int bit_mask = 1; |
| 1168 | 1006 | int has_rF = (info->rF != 0); |
| 1169 | | int type = context->type; |
| 1007 | int type = m_type; |
| 1170 | 1008 | double v_ref = info->vRef; |
| 1171 | 1009 | double rI = info->rI; |
| 1172 | 1010 | |
| 1173 | 1011 | if (EXPECTED(DST_MIXER__ENABLE)) |
| 1174 | 1012 | { |
| 1175 | | r_total = context->r_total; |
| 1013 | r_total = m_r_total; |
| 1176 | 1014 | |
| 1177 | | if (UNEXPECTED(context->r_node_bit_flag != 0)) |
| 1015 | if (UNEXPECTED(m_r_node_bit_flag != 0)) |
| 1178 | 1016 | { |
| 1179 | 1017 | /* loop and do any high pass filtering for connected caps */ |
| 1180 | 1018 | /* but first see if there is an r_node for the current path */ |
| 1181 | 1019 | /* if so, then the exponents need to be re-calculated */ |
| 1182 | | for (bit = 0; bit < context->size; bit++) |
| 1020 | for (bit = 0; bit < m_size; bit++) |
| 1183 | 1021 | { |
| 1184 | 1022 | rTemp = info->r[bit]; |
| 1185 | 1023 | connected = 1; |
| r10048 | r10049 | |
| 1189 | 1027 | if (r_node_bit_flag & bit_mask) |
| 1190 | 1028 | { |
| 1191 | 1029 | /* a node has the possibility of being disconnected from the circuit. */ |
| 1192 | | if (*context->r_node[bit] == 0) |
| 1030 | if (*m_r_node[bit] == 0) |
| 1193 | 1031 | connected = 0; |
| 1194 | 1032 | else |
| 1195 | 1033 | { |
| 1196 | 1034 | /* value currently holds resistance */ |
| 1197 | | rTemp += *context->r_node[bit]; |
| 1035 | rTemp += *m_r_node[bit]; |
| 1198 | 1036 | r_total += 1.0 / rTemp; |
| 1199 | 1037 | /* is there a capacitor? */ |
| 1200 | 1038 | if (c_bit_flag & bit_mask) |
| r10048 | r10049 | |
| 1217 | 1055 | break; |
| 1218 | 1056 | } |
| 1219 | 1057 | /* Re-calculate exponent if resistor is a node and has changed value */ |
| 1220 | | if (*context->r_node[bit] != context->r_last[bit]) |
| 1058 | if (*m_r_node[bit] != m_r_last[bit]) |
| 1221 | 1059 | { |
| 1222 | | context->exponent_rc[bit] = RC_CHARGE_EXP(rTemp2 * info->c[bit]); |
| 1223 | | context->r_last[bit] = *context->r_node[bit]; |
| 1060 | m_exponent_rc[bit] = RC_CHARGE_EXP_CLASS(rTemp2 * info->c[bit]); |
| 1061 | m_r_last[bit] = *m_r_node[bit]; |
| 1224 | 1062 | } |
| 1225 | 1063 | } |
| 1226 | 1064 | } |
| r10048 | r10049 | |
| 1232 | 1070 | if (c_bit_flag & bit_mask) |
| 1233 | 1071 | { |
| 1234 | 1072 | /* do input high pass filtering if needed. */ |
| 1235 | | context->v_cap[bit] += (vTemp - v_ref - context->v_cap[bit]) * context->exponent_rc[bit]; |
| 1236 | | vTemp -= context->v_cap[bit]; |
| 1073 | m_v_cap[bit] += (vTemp - v_ref - m_v_cap[bit]) * m_exponent_rc[bit]; |
| 1074 | vTemp -= m_v_cap[bit]; |
| 1237 | 1075 | } |
| 1238 | 1076 | i += ((type == DISC_MIXER_IS_OP_AMP) ? v_ref - vTemp : vTemp) / rTemp; |
| 1239 | 1077 | } |
| r10048 | r10049 | |
| 1243 | 1081 | else if (UNEXPECTED(c_bit_flag != 0)) |
| 1244 | 1082 | { |
| 1245 | 1083 | /* no r_nodes, so just do high pass filtering */ |
| 1246 | | for (bit = 0; bit < context->size; bit++) |
| 1084 | for (bit = 0; bit < m_size; bit++) |
| 1247 | 1085 | { |
| 1248 | 1086 | vTemp = DST_MIXER__IN(bit); |
| 1249 | 1087 | |
| 1250 | 1088 | if (c_bit_flag & (1 << bit)) |
| 1251 | 1089 | { |
| 1252 | 1090 | /* do input high pass filtering if needed. */ |
| 1253 | | context->v_cap[bit] += (vTemp - v_ref - context->v_cap[bit]) * context->exponent_rc[bit]; |
| 1254 | | vTemp -= context->v_cap[bit]; |
| 1091 | m_v_cap[bit] += (vTemp - v_ref - m_v_cap[bit]) * m_exponent_rc[bit]; |
| 1092 | vTemp -= m_v_cap[bit]; |
| 1255 | 1093 | } |
| 1256 | 1094 | i += ((type == DISC_MIXER_IS_OP_AMP) ? v_ref - vTemp : vTemp) / info->r[bit]; |
| 1257 | 1095 | } |
| r10048 | r10049 | |
| 1261 | 1099 | /* no r_nodes or c_nodes, mixing only */ |
| 1262 | 1100 | if (UNEXPECTED(type == DISC_MIXER_IS_OP_AMP)) |
| 1263 | 1101 | { |
| 1264 | | for (bit = 0; bit < context->size; bit++) |
| 1102 | for (bit = 0; bit < m_size; bit++) |
| 1265 | 1103 | i += ( v_ref - DST_MIXER__IN(bit) ) / info->r[bit]; |
| 1266 | 1104 | } |
| 1267 | 1105 | else |
| 1268 | 1106 | { |
| 1269 | | for (bit = 0; bit < context->size; bit++) |
| 1107 | for (bit = 0; bit < m_size; bit++) |
| 1270 | 1108 | i += DST_MIXER__IN(bit) / info->r[bit]; |
| 1271 | 1109 | } |
| 1272 | 1110 | } |
| r10048 | r10049 | |
| 1281 | 1119 | v = i * ((type == DISC_MIXER_IS_OP_AMP) ? info->rF : r_total); |
| 1282 | 1120 | |
| 1283 | 1121 | if (UNEXPECTED(type == DISC_MIXER_IS_OP_AMP_WITH_RI)) |
| 1284 | | v = v_ref + (context->gain * (v_ref - v)); |
| 1122 | v = v_ref + (m_gain * (v_ref - v)); |
| 1285 | 1123 | |
| 1286 | 1124 | /* Do the low pass filtering for cF */ |
| 1287 | 1125 | if (EXPECTED(info->cF != 0)) |
| r10048 | r10049 | |
| 1289 | 1127 | if (UNEXPECTED(r_node_bit_flag != 0)) |
| 1290 | 1128 | { |
| 1291 | 1129 | /* Re-calculate exponent if resistor nodes are used */ |
| 1292 | | context->exponent_c_f = RC_CHARGE_EXP(r_total * info->cF); |
| 1130 | m_exponent_c_f = RC_CHARGE_EXP_CLASS(r_total * info->cF); |
| 1293 | 1131 | } |
| 1294 | | context->v_cap_f += (v - v_ref - context->v_cap_f) * context->exponent_c_f; |
| 1295 | | v = context->v_cap_f; |
| 1132 | m_v_cap_f += (v - v_ref - m_v_cap_f) * m_exponent_c_f; |
| 1133 | v = m_v_cap_f; |
| 1296 | 1134 | } |
| 1297 | 1135 | |
| 1298 | 1136 | /* Do the high pass filtering for cAmp */ |
| 1299 | 1137 | if (EXPECTED(info->cAmp != 0)) |
| 1300 | 1138 | { |
| 1301 | | context->v_cap_amp += (v - context->v_cap_amp) * context->exponent_c_amp; |
| 1302 | | v -= context->v_cap_amp; |
| 1139 | m_v_cap_amp += (v - m_v_cap_amp) * m_exponent_c_amp; |
| 1140 | v -= m_v_cap_amp; |
| 1303 | 1141 | } |
| 1304 | | node->output[0] = v * info->gain; |
| 1142 | this->output[0] = v * info->gain; |
| 1305 | 1143 | } |
| 1306 | 1144 | else |
| 1307 | 1145 | { |
| 1308 | | node->output[0] = 0; |
| 1146 | this->output[0] = 0; |
| 1309 | 1147 | } |
| 1310 | 1148 | } |
| 1311 | 1149 | |
| 1312 | 1150 | |
| 1313 | 1151 | DISCRETE_RESET(dst_mixer) |
| 1314 | 1152 | { |
| 1315 | | DISCRETE_DECLARE_CONTEXT(dst_mixer) |
| 1316 | 1153 | DISCRETE_DECLARE_INFO(discrete_mixer_desc) |
| 1317 | 1154 | |
| 1318 | | node_description *r_node; |
| 1155 | discrete_base_node *r_node; |
| 1319 | 1156 | |
| 1320 | 1157 | int bit; |
| 1321 | 1158 | double rTemp = 0; |
| 1322 | 1159 | |
| 1323 | 1160 | /* link to r_node outputs */ |
| 1324 | | context->r_node_bit_flag = 0; |
| 1161 | m_r_node_bit_flag = 0; |
| 1325 | 1162 | for (bit = 0; bit < 8; bit++) |
| 1326 | 1163 | { |
| 1327 | | r_node = discrete_find_node(node->info, info->r_node[bit]); |
| 1164 | r_node = this->device->discrete_find_node(info->r_node[bit]); |
| 1328 | 1165 | if (r_node != NULL) |
| 1329 | 1166 | { |
| 1330 | | context->r_node[bit] = &(r_node->output[NODE_CHILD_NODE_NUM(info->r_node[bit])]); |
| 1331 | | context->r_node_bit_flag |= 1 << bit; |
| 1167 | m_r_node[bit] = &(r_node->output[NODE_CHILD_NODE_NUM(info->r_node[bit])]); |
| 1168 | m_r_node_bit_flag |= 1 << bit; |
| 1332 | 1169 | } |
| 1333 | 1170 | else |
| 1334 | | context->r_node[bit] = NULL; |
| 1171 | m_r_node[bit] = NULL; |
| 1335 | 1172 | |
| 1336 | 1173 | /* flag any caps */ |
| 1337 | 1174 | if (info->c[bit] != 0) |
| 1338 | | context->c_bit_flag |= 1 << bit; |
| 1175 | m_c_bit_flag |= 1 << bit; |
| 1339 | 1176 | } |
| 1340 | 1177 | |
| 1341 | | context->size = node->active_inputs() - 1; |
| 1178 | m_size = this->active_inputs() - 1; |
| 1342 | 1179 | |
| 1343 | 1180 | /* |
| 1344 | 1181 | * THERE IS NO ERROR CHECKING!!!!!!!!! |
| r10048 | r10049 | |
| 1346 | 1183 | * then you deserve a crash. |
| 1347 | 1184 | */ |
| 1348 | 1185 | |
| 1349 | | context->type = info->type; |
| 1186 | m_type = info->type; |
| 1350 | 1187 | if ((info->type == DISC_MIXER_IS_OP_AMP) && (info->rI != 0)) |
| 1351 | | context->type = DISC_MIXER_IS_OP_AMP_WITH_RI; |
| 1188 | m_type = DISC_MIXER_IS_OP_AMP_WITH_RI; |
| 1352 | 1189 | |
| 1353 | 1190 | /* |
| 1354 | 1191 | * Calculate the total of all resistors in parallel. |
| 1355 | 1192 | * This is the combined resistance of the voltage sources. |
| 1356 | 1193 | * Also calculate the exponents while we are here. |
| 1357 | 1194 | */ |
| 1358 | | context->r_total = 0; |
| 1359 | | for(bit = 0; bit < context->size; bit++) |
| 1195 | m_r_total = 0; |
| 1196 | for(bit = 0; bit < m_size; bit++) |
| 1360 | 1197 | { |
| 1361 | 1198 | if ((info->r[bit] != 0) && !info->r_node[bit] ) |
| 1362 | 1199 | { |
| 1363 | | context->r_total += 1.0 / info->r[bit]; |
| 1200 | m_r_total += 1.0 / info->r[bit]; |
| 1364 | 1201 | } |
| 1365 | 1202 | |
| 1366 | | context->v_cap[bit] = 0; |
| 1367 | | context->exponent_rc[bit] = 0; |
| 1203 | m_v_cap[bit] = 0; |
| 1204 | m_exponent_rc[bit] = 0; |
| 1368 | 1205 | if ((info->c[bit] != 0) && !info->r_node[bit]) |
| 1369 | 1206 | { |
| 1370 | | switch (context->type) |
| 1207 | switch (m_type) |
| 1371 | 1208 | { |
| 1372 | 1209 | case DISC_MIXER_IS_RESISTOR: |
| 1373 | 1210 | /* is there an rF? */ |
| r10048 | r10049 | |
| 1385 | 1222 | break; |
| 1386 | 1223 | } |
| 1387 | 1224 | /* Setup filter constants */ |
| 1388 | | context->exponent_rc[bit] = RC_CHARGE_EXP(rTemp * info->c[bit]); |
| 1225 | m_exponent_rc[bit] = RC_CHARGE_EXP_CLASS(rTemp * info->c[bit]); |
| 1389 | 1226 | } |
| 1390 | 1227 | } |
| 1391 | 1228 | |
| 1392 | 1229 | if (info->rF != 0) |
| 1393 | 1230 | { |
| 1394 | | if (context->type == DISC_MIXER_IS_RESISTOR) context->r_total += 1.0 / info->rF; |
| 1231 | if (m_type == DISC_MIXER_IS_RESISTOR) m_r_total += 1.0 / info->rF; |
| 1395 | 1232 | } |
| 1396 | | if (context->type == DISC_MIXER_IS_OP_AMP_WITH_RI) context->r_total += 1.0 / info->rI; |
| 1233 | if (m_type == DISC_MIXER_IS_OP_AMP_WITH_RI) m_r_total += 1.0 / info->rI; |
| 1397 | 1234 | |
| 1398 | | context->v_cap_f = 0; |
| 1399 | | context->exponent_c_f = 0; |
| 1235 | m_v_cap_f = 0; |
| 1236 | m_exponent_c_f = 0; |
| 1400 | 1237 | if (info->cF != 0) |
| 1401 | 1238 | { |
| 1402 | 1239 | /* Setup filter constants */ |
| 1403 | | context->exponent_c_f = RC_CHARGE_EXP(((info->type == DISC_MIXER_IS_OP_AMP) ? info->rF : (1.0 / context->r_total)) * info->cF); |
| 1240 | m_exponent_c_f = RC_CHARGE_EXP_CLASS(((info->type == DISC_MIXER_IS_OP_AMP) ? info->rF : (1.0 / m_r_total)) * info->cF); |
| 1404 | 1241 | } |
| 1405 | 1242 | |
| 1406 | | context->v_cap_amp = 0; |
| 1407 | | context->exponent_c_amp = 0; |
| 1243 | m_v_cap_amp = 0; |
| 1244 | m_exponent_c_amp = 0; |
| 1408 | 1245 | if (info->cAmp != 0) |
| 1409 | 1246 | { |
| 1410 | 1247 | /* Setup filter constants */ |
| 1411 | 1248 | /* We will use 100k ohms as an average final stage impedance. */ |
| 1412 | 1249 | /* Your amp/speaker system will have more effect on incorrect filtering then any value used here. */ |
| 1413 | | context->exponent_c_amp = RC_CHARGE_EXP(RES_K(100) * info->cAmp); |
| 1250 | m_exponent_c_amp = RC_CHARGE_EXP_CLASS(RES_K(100) * info->cAmp); |
| 1414 | 1251 | } |
| 1415 | 1252 | |
| 1416 | | if (context->type == DISC_MIXER_IS_OP_AMP_WITH_RI) context->gain = info->rF / info->rI; |
| 1253 | if (m_type == DISC_MIXER_IS_OP_AMP_WITH_RI) m_gain = info->rF / info->rI; |
| 1417 | 1254 | |
| 1418 | | node->output[0] = 0; |
| 1255 | this->output[0] = 0; |
| 1419 | 1256 | } |
| 1420 | 1257 | |
| 1421 | 1258 | |
| r10048 | r10049 | |
| 1435 | 1272 | |
| 1436 | 1273 | DISCRETE_STEP(dst_multiplex) |
| 1437 | 1274 | { |
| 1438 | | DISCRETE_DECLARE_CONTEXT(dst_size) |
| 1439 | | |
| 1440 | 1275 | int addr; |
| 1441 | 1276 | |
| 1442 | 1277 | addr = DST_MULTIPLEX__ADDR; /* FP to INT */ |
| 1443 | | if ((addr >= 0) && (addr < context->size)) |
| 1278 | if ((addr >= 0) && (addr < m_size)) |
| 1444 | 1279 | { |
| 1445 | | node->output[0] = DST_MULTIPLEX__INP(addr); |
| 1280 | this->output[0] = DST_MULTIPLEX__INP(addr); |
| 1446 | 1281 | } |
| 1447 | 1282 | else |
| 1448 | 1283 | { |
| 1449 | 1284 | /* Bad address. We will leave the output alone. */ |
| 1450 | | discrete_log(node->info, "NODE_%02d - Address = %d. Out of bounds\n", node->index(), addr); |
| 1285 | this->device->discrete_log("NODE_%02d - Address = %d. Out of bounds\n", this->index(), addr); |
| 1451 | 1286 | } |
| 1452 | 1287 | } |
| 1453 | 1288 | |
| 1454 | 1289 | DISCRETE_RESET(dst_multiplex) |
| 1455 | 1290 | { |
| 1456 | | DISCRETE_DECLARE_CONTEXT(dst_size) |
| 1291 | m_size = this->active_inputs() - 1; |
| 1457 | 1292 | |
| 1458 | | context->size = node->active_inputs() - 1; |
| 1459 | | |
| 1460 | | DISCRETE_STEP_CALL(dst_multiplex); |
| 1293 | this->step(); |
| 1461 | 1294 | } |
| 1462 | 1295 | |
| 1463 | 1296 | |
| r10048 | r10049 | |
| 1481 | 1314 | |
| 1482 | 1315 | DISCRETE_STEP(dst_oneshot) |
| 1483 | 1316 | { |
| 1484 | | DISCRETE_DECLARE_CONTEXT(dst_oneshot) |
| 1485 | | |
| 1486 | 1317 | int trigger = (DST_ONESHOT__TRIG != 0); |
| 1487 | 1318 | |
| 1488 | 1319 | /* If the state is triggered we will need to countdown later */ |
| 1489 | | int do_count = context->state; |
| 1320 | int do_count = m_state; |
| 1490 | 1321 | |
| 1491 | 1322 | if (UNEXPECTED(DST_ONESHOT__RESET)) |
| 1492 | 1323 | { |
| 1493 | 1324 | /* Hold in Reset */ |
| 1494 | | node->output[0] = 0; |
| 1495 | | context->state = 0; |
| 1325 | this->output[0] = 0; |
| 1326 | m_state = 0; |
| 1496 | 1327 | } |
| 1497 | 1328 | else |
| 1498 | 1329 | { |
| 1499 | 1330 | /* are we at an edge? */ |
| 1500 | | if (UNEXPECTED(trigger != context->last_trig)) |
| 1331 | if (UNEXPECTED(trigger != m_last_trig)) |
| 1501 | 1332 | { |
| 1502 | 1333 | /* There has been a trigger edge */ |
| 1503 | | context->last_trig = trigger; |
| 1334 | m_last_trig = trigger; |
| 1504 | 1335 | |
| 1505 | 1336 | /* Is it the proper edge trigger */ |
| 1506 | | if ((context->type & DISC_ONESHOT_REDGE) ? trigger : !trigger) |
| 1337 | if ((m_type & DISC_ONESHOT_REDGE) ? trigger : !trigger) |
| 1507 | 1338 | { |
| 1508 | | if (!context->state) |
| 1339 | if (!m_state) |
| 1509 | 1340 | { |
| 1510 | 1341 | /* We have first trigger */ |
| 1511 | | context->state = 1; |
| 1512 | | node->output[0] = (context->type & DISC_OUT_ACTIVE_LOW) ? 0 : DST_ONESHOT__AMP; |
| 1513 | | context->countdown = DST_ONESHOT__WIDTH; |
| 1342 | m_state = 1; |
| 1343 | this->output[0] = (m_type & DISC_OUT_ACTIVE_LOW) ? 0 : DST_ONESHOT__AMP; |
| 1344 | m_countdown = DST_ONESHOT__WIDTH; |
| 1514 | 1345 | } |
| 1515 | 1346 | else |
| 1516 | 1347 | { |
| 1517 | 1348 | /* See if we retrigger */ |
| 1518 | | if (context->type & DISC_ONESHOT_RETRIG) |
| 1349 | if (m_type & DISC_ONESHOT_RETRIG) |
| 1519 | 1350 | { |
| 1520 | 1351 | /* Retrigger */ |
| 1521 | | context->countdown = DST_ONESHOT__WIDTH; |
| 1352 | m_countdown = DST_ONESHOT__WIDTH; |
| 1522 | 1353 | do_count = 0; |
| 1523 | 1354 | } |
| 1524 | 1355 | } |
| r10048 | r10049 | |
| 1527 | 1358 | |
| 1528 | 1359 | if (UNEXPECTED(do_count)) |
| 1529 | 1360 | { |
| 1530 | | context->countdown -= node->info->sample_time; |
| 1531 | | if(context->countdown <= 0.0) |
| 1361 | m_countdown -= this->sample_time(); |
| 1362 | if(m_countdown <= 0.0) |
| 1532 | 1363 | { |
| 1533 | | node->output[0] = (context->type & DISC_OUT_ACTIVE_LOW) ? DST_ONESHOT__AMP : 0; |
| 1534 | | context->countdown = 0; |
| 1535 | | context->state = 0; |
| 1364 | this->output[0] = (m_type & DISC_OUT_ACTIVE_LOW) ? DST_ONESHOT__AMP : 0; |
| 1365 | m_countdown = 0; |
| 1366 | m_state = 0; |
| 1536 | 1367 | } |
| 1537 | 1368 | } |
| 1538 | 1369 | } |
| r10048 | r10049 | |
| 1541 | 1372 | |
| 1542 | 1373 | DISCRETE_RESET(dst_oneshot) |
| 1543 | 1374 | { |
| 1544 | | DISCRETE_DECLARE_CONTEXT(dst_oneshot) |
| 1375 | m_countdown = 0; |
| 1376 | m_state = 0; |
| 1545 | 1377 | |
| 1546 | | context->countdown = 0; |
| 1547 | | context->state = 0; |
| 1378 | m_last_trig = 0; |
| 1379 | m_type = DST_ONESHOT__TYPE; |
| 1548 | 1380 | |
| 1549 | | context->last_trig = 0; |
| 1550 | | context->type = DST_ONESHOT__TYPE; |
| 1551 | | |
| 1552 | | node->output[0] = (context->type & DISC_OUT_ACTIVE_LOW) ? DST_ONESHOT__AMP : 0; |
| 1381 | this->output[0] = (m_type & DISC_OUT_ACTIVE_LOW) ? DST_ONESHOT__AMP : 0; |
| 1553 | 1382 | } |
| 1554 | 1383 | |
| 1555 | 1384 | |
| r10048 | r10049 | |
| 1574 | 1403 | |
| 1575 | 1404 | DISCRETE_STEP(dst_ramp) |
| 1576 | 1405 | { |
| 1577 | | DISCRETE_DECLARE_CONTEXT(dst_ramp) |
| 1578 | | |
| 1579 | 1406 | if(DST_RAMP__ENABLE) |
| 1580 | 1407 | { |
| 1581 | | if (!context->last_en) |
| 1408 | if (!m_last_en) |
| 1582 | 1409 | { |
| 1583 | | context->last_en = 1; |
| 1584 | | node->output[0] = DST_RAMP__START; |
| 1410 | m_last_en = 1; |
| 1411 | this->output[0] = DST_RAMP__START; |
| 1585 | 1412 | } |
| 1586 | | if(context->dir ? DST_RAMP__DIR : !DST_RAMP__DIR) node->output[0]+=context->step; |
| 1587 | | else node->output[0] -= context->step; |
| 1413 | if(m_dir ? DST_RAMP__DIR : !DST_RAMP__DIR) this->output[0]+=m_step; |
| 1414 | else this->output[0] -= m_step; |
| 1588 | 1415 | /* Clamp to min/max */ |
| 1589 | | if(context->dir ? (node->output[0] < DST_RAMP__START) |
| 1590 | | : (node->output[0] > DST_RAMP__START)) node->output[0] = DST_RAMP__START; |
| 1591 | | if(context->dir ? (node->output[0] > DST_RAMP__END) |
| 1592 | | : (node->output[0] < DST_RAMP__END)) node->output[0] = DST_RAMP__END; |
| 1416 | if(m_dir ? (this->output[0] < DST_RAMP__START) |
| 1417 | : (this->output[0] > DST_RAMP__START)) this->output[0] = DST_RAMP__START; |
| 1418 | if(m_dir ? (this->output[0] > DST_RAMP__END) |
| 1419 | : (this->output[0] < DST_RAMP__END)) this->output[0] = DST_RAMP__END; |
| 1593 | 1420 | } |
| 1594 | 1421 | else |
| 1595 | 1422 | { |
| 1596 | | context->last_en = 0; |
| 1423 | m_last_en = 0; |
| 1597 | 1424 | /* Disabled so clamp to output */ |
| 1598 | | node->output[0] = DST_RAMP__CLAMP; |
| 1425 | this->output[0] = DST_RAMP__CLAMP; |
| 1599 | 1426 | } |
| 1600 | 1427 | } |
| 1601 | 1428 | |
| 1602 | 1429 | DISCRETE_RESET(dst_ramp) |
| 1603 | 1430 | { |
| 1604 | | DISCRETE_DECLARE_CONTEXT(dst_ramp) |
| 1605 | | |
| 1606 | | node->output[0] = DST_RAMP__CLAMP; |
| 1607 | | context->step = DST_RAMP__GRAD / node->info->sample_rate; |
| 1608 | | context->dir = ((DST_RAMP__END - DST_RAMP__START) == abs(DST_RAMP__END - DST_RAMP__START)); |
| 1609 | | context->last_en = 0; |
| 1431 | this->output[0] = DST_RAMP__CLAMP; |
| 1432 | m_step = DST_RAMP__GRAD / this->sample_rate(); |
| 1433 | m_dir = ((DST_RAMP__END - DST_RAMP__START) == abs(DST_RAMP__END - DST_RAMP__START)); |
| 1434 | m_last_en = 0; |
| 1610 | 1435 | } |
| 1611 | 1436 | |
| 1612 | 1437 | |
| r10048 | r10049 | |
| 1625 | 1450 | |
| 1626 | 1451 | DISCRETE_STEP(dst_samphold) |
| 1627 | 1452 | { |
| 1628 | | DISCRETE_DECLARE_CONTEXT(dst_samphold) |
| 1629 | | |
| 1630 | | switch(context->clocktype) |
| 1453 | switch(m_clocktype) |
| 1631 | 1454 | { |
| 1632 | 1455 | case DISC_SAMPHOLD_REDGE: |
| 1633 | 1456 | /* Clock the whole time the input is rising */ |
| 1634 | | if (DST_SAMPHOLD__CLOCK > context->last_input) node->output[0] = DST_SAMPHOLD__IN0; |
| 1457 | if (DST_SAMPHOLD__CLOCK > m_last_input) this->output[0] = DST_SAMPHOLD__IN0; |
| 1635 | 1458 | break; |
| 1636 | 1459 | case DISC_SAMPHOLD_FEDGE: |
| 1637 | 1460 | /* Clock the whole time the input is falling */ |
| 1638 | | if(DST_SAMPHOLD__CLOCK < context->last_input) node->output[0] = DST_SAMPHOLD__IN0; |
| 1461 | if(DST_SAMPHOLD__CLOCK < m_last_input) this->output[0] = DST_SAMPHOLD__IN0; |
| 1639 | 1462 | break; |
| 1640 | 1463 | case DISC_SAMPHOLD_HLATCH: |
| 1641 | 1464 | /* Output follows input if clock != 0 */ |
| 1642 | | if( DST_SAMPHOLD__CLOCK) node->output[0] = DST_SAMPHOLD__IN0; |
| 1465 | if( DST_SAMPHOLD__CLOCK) this->output[0] = DST_SAMPHOLD__IN0; |
| 1643 | 1466 | break; |
| 1644 | 1467 | case DISC_SAMPHOLD_LLATCH: |
| 1645 | 1468 | /* Output follows input if clock == 0 */ |
| 1646 | | if (DST_SAMPHOLD__CLOCK == 0) node->output[0] = DST_SAMPHOLD__IN0; |
| 1469 | if (DST_SAMPHOLD__CLOCK == 0) this->output[0] = DST_SAMPHOLD__IN0; |
| 1647 | 1470 | break; |
| 1648 | 1471 | default: |
| 1649 | | discrete_log(node->info, "dst_samphold_step - Invalid clocktype passed"); |
| 1472 | this->device->discrete_log("dst_samphold_step - Invalid clocktype passed"); |
| 1650 | 1473 | break; |
| 1651 | 1474 | } |
| 1652 | 1475 | /* Save the last value */ |
| 1653 | | context->last_input = DST_SAMPHOLD__CLOCK; |
| 1476 | m_last_input = DST_SAMPHOLD__CLOCK; |
| 1654 | 1477 | } |
| 1655 | 1478 | |
| 1656 | 1479 | DISCRETE_RESET(dst_samphold) |
| 1657 | 1480 | { |
| 1658 | | DISCRETE_DECLARE_CONTEXT(dst_samphold) |
| 1659 | | |
| 1660 | | node->output[0] = 0; |
| 1661 | | context->last_input = -1; |
| 1481 | this->output[0] = 0; |
| 1482 | m_last_input = -1; |
| 1662 | 1483 | /* Only stored in here to speed up and save casting in the step function */ |
| 1663 | | context->clocktype = (int)DST_SAMPHOLD__TYPE; |
| 1664 | | DISCRETE_STEP_CALL(dst_samphold); |
| 1484 | m_clocktype = (int)DST_SAMPHOLD__TYPE; |
| 1485 | this->step(); |
| 1665 | 1486 | } |
| 1666 | 1487 | |
| 1667 | 1488 | |
| r10048 | r10049 | |
| 1684 | 1505 | { |
| 1685 | 1506 | if(DST_SWITCH__ENABLE) |
| 1686 | 1507 | { |
| 1687 | | node->output[0] = DST_SWITCH__SWITCH ? DST_SWITCH__IN1 : DST_SWITCH__IN0; |
| 1508 | this->output[0] = DST_SWITCH__SWITCH ? DST_SWITCH__IN1 : DST_SWITCH__IN0; |
| 1688 | 1509 | } |
| 1689 | 1510 | else |
| 1690 | 1511 | { |
| 1691 | | node->output[0] = 0; |
| 1512 | this->output[0] = 0; |
| 1692 | 1513 | } |
| 1693 | 1514 | } |
| 1694 | 1515 | |
| r10048 | r10049 | |
| 1708 | 1529 | |
| 1709 | 1530 | DISCRETE_STEP(dst_aswitch) |
| 1710 | 1531 | { |
| 1711 | | node->output[0] = DST_ASWITCH__CTRL > DST_ASWITCH__THRESHOLD ? DST_ASWITCH__IN : 0; |
| 1532 | this->output[0] = DST_ASWITCH__CTRL > DST_ASWITCH__THRESHOLD ? DST_ASWITCH__IN : 0; |
| 1712 | 1533 | } |
| 1713 | 1534 | |
| 1714 | 1535 | /************************************************************************ |
| r10048 | r10049 | |
| 1751 | 1572 | double number1,top; |
| 1752 | 1573 | int trans_stack_ptr = 0; |
| 1753 | 1574 | |
| 1754 | | const char *fPTR = (const char *)node->custom_data(); |
| 1575 | const char *fPTR = (const char *)this->custom_data(); |
| 1755 | 1576 | |
| 1756 | 1577 | top = HUGE_VAL; |
| 1757 | 1578 | |
| r10048 | r10049 | |
| 1832 | 1653 | top = (int)number1 ^ (int)top; |
| 1833 | 1654 | break; |
| 1834 | 1655 | default: |
| 1835 | | discrete_log(node->info, "dst_transform_step - Invalid function type/variable passed: %s",(const char *)node->custom_data()); |
| 1656 | this->device->discrete_log("dst_transform_step - Invalid function type/variable passed: %s",(const char *)this->custom_data()); |
| 1836 | 1657 | /* that is enough to fatalerror */ |
| 1837 | | fatalerror("dst_transform_step - Invalid function type/variable passed: %s", (const char *)node->custom_data()); |
| 1658 | fatalerror("dst_transform_step - Invalid function type/variable passed: %s", (const char *)this->custom_data()); |
| 1838 | 1659 | break; |
| 1839 | 1660 | } |
| 1840 | 1661 | } |
| 1841 | | node->output[0] = top; |
| 1662 | this->output[0] = top; |
| 1842 | 1663 | } |
| 1843 | 1664 | |
| 1844 | 1665 | |
| r10048 | r10049 | |
| 1860 | 1681 | |
| 1861 | 1682 | DISCRETE_STEP(dst_op_amp) |
| 1862 | 1683 | { |
| 1863 | | DISCRETE_DECLARE_CONTEXT(dst_op_amp) |
| 1864 | 1684 | DISCRETE_DECLARE_INFO(discrete_op_amp_info) |
| 1865 | 1685 | |
| 1866 | 1686 | double i_pos = 0; |
| r10048 | r10049 | |
| 1873 | 1693 | { |
| 1874 | 1694 | case DISC_OP_AMP_IS_NORTON: |
| 1875 | 1695 | /* work out neg pin current */ |
| 1876 | | if (context->has_r1) |
| 1696 | if (m_has_r1) |
| 1877 | 1697 | { |
| 1878 | 1698 | i_neg = (DST_OP_AMP__INP0 - OP_AMP_NORTON_VBE) / info->r1; |
| 1879 | 1699 | if (i_neg < 0) i_neg = 0; |
| 1880 | 1700 | } |
| 1881 | | i_neg += context->i_fixed; |
| 1701 | i_neg += m_i_fixed; |
| 1882 | 1702 | |
| 1883 | 1703 | /* work out neg pin current */ |
| 1884 | 1704 | i_pos = (DST_OP_AMP__INP1 - OP_AMP_NORTON_VBE) / info->r2; |
| r10048 | r10049 | |
| 1887 | 1707 | /* work out current across r4 */ |
| 1888 | 1708 | i = i_pos - i_neg; |
| 1889 | 1709 | |
| 1890 | | if (context->has_cap) |
| 1710 | if (m_has_cap) |
| 1891 | 1711 | { |
| 1892 | | if (context->has_r4) |
| 1712 | if (m_has_r4) |
| 1893 | 1713 | { |
| 1894 | 1714 | /* voltage across r4 charging cap */ |
| 1895 | 1715 | i *= info->r4; |
| 1896 | 1716 | /* exponential charge */ |
| 1897 | | context->v_cap += (i - context->v_cap) * context->exponent; |
| 1717 | m_v_cap += (i - m_v_cap) * m_exponent; |
| 1898 | 1718 | } |
| 1899 | 1719 | else |
| 1900 | 1720 | /* linear charge */ |
| 1901 | | context->v_cap += i / context->exponent; |
| 1902 | | node->output[0] = context->v_cap; |
| 1721 | m_v_cap += i / m_exponent; |
| 1722 | this->output[0] = m_v_cap; |
| 1903 | 1723 | } |
| 1904 | 1724 | else |
| 1905 | | if (context->has_r4) |
| 1906 | | node->output[0] = i * info->r4; |
| 1725 | if (m_has_r4) |
| 1726 | this->output[0] = i * info->r4; |
| 1907 | 1727 | else |
| 1908 | 1728 | /* output just swings to rail when there is no r4 */ |
| 1909 | 1729 | if (i > 0) |
| 1910 | | node->output[0] = context->v_max; |
| 1730 | this->output[0] = m_v_max; |
| 1911 | 1731 | else |
| 1912 | | node->output[0] = 0; |
| 1732 | this->output[0] = 0; |
| 1913 | 1733 | |
| 1914 | 1734 | /* clamp output */ |
| 1915 | | if (node->output[0] > context->v_max) node->output[0] = context->v_max; |
| 1916 | | else if (node->output[0] < info->vN) node->output[0] = info->vN; |
| 1917 | | context->v_cap = node->output[0]; |
| 1735 | if (this->output[0] > m_v_max) this->output[0] = m_v_max; |
| 1736 | else if (this->output[0] < info->vN) this->output[0] = info->vN; |
| 1737 | m_v_cap = this->output[0]; |
| 1918 | 1738 | break; |
| 1919 | 1739 | |
| 1920 | 1740 | default: |
| 1921 | | node->output[0] = 0; |
| 1741 | this->output[0] = 0; |
| 1922 | 1742 | } |
| 1923 | 1743 | } |
| 1924 | 1744 | else |
| 1925 | | node->output[0] = 0; |
| 1745 | this->output[0] = 0; |
| 1926 | 1746 | } |
| 1927 | 1747 | |
| 1928 | 1748 | DISCRETE_RESET(dst_op_amp) |
| 1929 | 1749 | { |
| 1930 | | DISCRETE_DECLARE_CONTEXT(dst_op_amp) |
| 1931 | 1750 | DISCRETE_DECLARE_INFO(discrete_op_amp_info) |
| 1932 | 1751 | |
| 1933 | | context->has_r1 = info->r1 > 0; |
| 1934 | | context->has_r4 = info->r4 > 0; |
| 1752 | m_has_r1 = info->r1 > 0; |
| 1753 | m_has_r4 = info->r4 > 0; |
| 1935 | 1754 | |
| 1936 | | context->v_max = info->vP - OP_AMP_NORTON_VBE; |
| 1755 | m_v_max = info->vP - OP_AMP_NORTON_VBE; |
| 1937 | 1756 | |
| 1938 | | context->v_cap = 0; |
| 1757 | m_v_cap = 0; |
| 1939 | 1758 | if (info->c > 0) |
| 1940 | 1759 | { |
| 1941 | | context->has_cap = 1; |
| 1760 | m_has_cap = 1; |
| 1942 | 1761 | /* Setup filter constants */ |
| 1943 | | if (context->has_r4) |
| 1762 | if (m_has_r4) |
| 1944 | 1763 | { |
| 1945 | 1764 | /* exponential charge */ |
| 1946 | | context->exponent = RC_CHARGE_EXP(info->r4 * info->c); |
| 1765 | m_exponent = RC_CHARGE_EXP_CLASS(info->r4 * info->c); |
| 1947 | 1766 | } |
| 1948 | 1767 | else |
| 1949 | 1768 | /* linear charge */ |
| 1950 | | context->exponent = node->info->sample_rate * info->c; |
| 1769 | m_exponent = this->sample_rate() * info->c; |
| 1951 | 1770 | } |
| 1952 | 1771 | |
| 1953 | 1772 | if (info->r3 > 0) |
| 1954 | | context->i_fixed = (info->vP - OP_AMP_NORTON_VBE) / info->r3; |
| 1773 | m_i_fixed = (info->vP - OP_AMP_NORTON_VBE) / info->r3; |
| 1955 | 1774 | else |
| 1956 | | context->i_fixed = 0; |
| 1775 | m_i_fixed = 0; |
| 1957 | 1776 | } |
| 1958 | 1777 | |
| 1959 | 1778 | |
| r10048 | r10049 | |
| 1971 | 1790 | |
| 1972 | 1791 | DISCRETE_STEP(dst_op_amp_1sht) |
| 1973 | 1792 | { |
| 1974 | | DISCRETE_DECLARE_CONTEXT(dst_op_amp_1sht) |
| 1975 | 1793 | DISCRETE_DECLARE_INFO(discrete_op_amp_1sht_info) |
| 1976 | 1794 | |
| 1977 | 1795 | double i_pos; |
| r10048 | r10049 | |
| 1979 | 1797 | double v; |
| 1980 | 1798 | |
| 1981 | 1799 | /* update trigger circuit */ |
| 1982 | | i_pos = (DST_OP_AMP_1SHT__TRIGGER - context->v_cap2) / info->r2; |
| 1983 | | i_pos += node->output[0] / info->r5; |
| 1984 | | context->v_cap2 += (DST_OP_AMP_1SHT__TRIGGER - context->v_cap2) * context->exponent2; |
| 1800 | i_pos = (DST_OP_AMP_1SHT__TRIGGER - m_v_cap2) / info->r2; |
| 1801 | i_pos += this->output[0] / info->r5; |
| 1802 | m_v_cap2 += (DST_OP_AMP_1SHT__TRIGGER - m_v_cap2) * m_exponent2; |
| 1985 | 1803 | |
| 1986 | 1804 | /* calculate currents and output */ |
| 1987 | | i_neg = (context->v_cap1 - OP_AMP_NORTON_VBE) / info->r3; |
| 1805 | i_neg = (m_v_cap1 - OP_AMP_NORTON_VBE) / info->r3; |
| 1988 | 1806 | if (i_neg < 0) i_neg = 0; |
| 1989 | | i_neg += context->i_fixed; |
| 1807 | i_neg += m_i_fixed; |
| 1990 | 1808 | |
| 1991 | | if (i_pos > i_neg) node->output[0] = context->v_max; |
| 1992 | | else node->output[0] = info->vN; |
| 1809 | if (i_pos > i_neg) this->output[0] = m_v_max; |
| 1810 | else this->output[0] = info->vN; |
| 1993 | 1811 | |
| 1994 | 1812 | /* update c1 */ |
| 1995 | 1813 | /* rough value of voltage at anode of diode if discharging */ |
| 1996 | | v = node->output[0] + 0.6; |
| 1997 | | if (context->v_cap1 > node->output[0]) |
| 1814 | v = this->output[0] + 0.6; |
| 1815 | if (m_v_cap1 > this->output[0]) |
| 1998 | 1816 | { |
| 1999 | 1817 | /* discharge */ |
| 2000 | | if (context->v_cap1 > v) |
| 1818 | if (m_v_cap1 > v) |
| 2001 | 1819 | /* immediate discharge through diode */ |
| 2002 | | context->v_cap1 = v; |
| 1820 | m_v_cap1 = v; |
| 2003 | 1821 | else |
| 2004 | 1822 | /* discharge through r4 */ |
| 2005 | | context->v_cap1 += (node->output[0] - context->v_cap1) * context->exponent1d; |
| 1823 | m_v_cap1 += (this->output[0] - m_v_cap1) * m_exponent1d; |
| 2006 | 1824 | } |
| 2007 | 1825 | else |
| 2008 | 1826 | /* charge */ |
| 2009 | | context->v_cap1 += ((node->output[0] - OP_AMP_NORTON_VBE) * context->r34ratio + OP_AMP_NORTON_VBE - context->v_cap1) * context->exponent1c; |
| 1827 | m_v_cap1 += ((this->output[0] - OP_AMP_NORTON_VBE) * m_r34ratio + OP_AMP_NORTON_VBE - m_v_cap1) * m_exponent1c; |
| 2010 | 1828 | } |
| 2011 | 1829 | |
| 2012 | 1830 | DISCRETE_RESET(dst_op_amp_1sht) |
| 2013 | 1831 | { |
| 2014 | | DISCRETE_DECLARE_CONTEXT(dst_op_amp_1sht) |
| 2015 | 1832 | DISCRETE_DECLARE_INFO(discrete_op_amp_1sht_info) |
| 2016 | 1833 | |
| 2017 | | context->exponent1c = RC_CHARGE_EXP(RES_2_PARALLEL(info->r3, info->r4) * info->c1); |
| 2018 | | context->exponent1d = RC_CHARGE_EXP(info->r4 * info->c1); |
| 2019 | | context->exponent2 = RC_CHARGE_EXP(info->r2 * info->c2); |
| 2020 | | context->i_fixed = (info->vP - OP_AMP_NORTON_VBE) / info->r1; |
| 2021 | | context->v_cap1 = context->v_cap2 = 0; |
| 2022 | | context->v_max = info->vP - OP_AMP_NORTON_VBE; |
| 2023 | | context->r34ratio = info->r3 / (info->r3 + info->r4); |
| 1834 | m_exponent1c = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(info->r3, info->r4) * info->c1); |
| 1835 | m_exponent1d = RC_CHARGE_EXP_CLASS(info->r4 * info->c1); |
| 1836 | m_exponent2 = RC_CHARGE_EXP_CLASS(info->r2 * info->c2); |
| 1837 | m_i_fixed = (info->vP - OP_AMP_NORTON_VBE) / info->r1; |
| 1838 | m_v_cap1 = m_v_cap2 = 0; |
| 1839 | m_v_max = info->vP - OP_AMP_NORTON_VBE; |
| 1840 | m_r34ratio = info->r3 / (info->r3 + info->r4); |
| 2024 | 1841 | } |
| 2025 | 1842 | |
| 2026 | 1843 | |
| r10048 | r10049 | |
| 2046 | 1863 | |
| 2047 | 1864 | DISCRETE_STEP(dst_tvca_op_amp) |
| 2048 | 1865 | { |
| 2049 | | DISCRETE_DECLARE_CONTEXT(dst_tvca_op_amp) |
| 2050 | 1866 | DISCRETE_DECLARE_INFO(discrete_op_amp_tvca_info) |
| 2051 | 1867 | |
| 2052 | 1868 | int trig0, trig1, trig2, f3; |
| r10048 | r10049 | |
| 2077 | 1893 | } |
| 2078 | 1894 | |
| 2079 | 1895 | /* Calculate current going in to - input. */ |
| 2080 | | i_neg = context->i_fixed + i2 + i3; |
| 1896 | i_neg = m_i_fixed + i2 + i3; |
| 2081 | 1897 | |
| 2082 | 1898 | /* Update the c1 cap voltage. */ |
| 2083 | 1899 | if (dst_trigger_function(trig0, trig1, trig2, info->f2)) |
| 2084 | 1900 | { |
| 2085 | 1901 | /* F2 is not grounding the circuit so we charge the cap. */ |
| 2086 | | context->v_cap1 += (context->v_trig[f3] - context->v_cap1) * context->exponent_c[f3]; |
| 1902 | m_v_cap1 += (m_v_trig[f3] - m_v_cap1) * m_exponent_c[f3]; |
| 2087 | 1903 | } |
| 2088 | 1904 | else |
| 2089 | 1905 | { |
| r10048 | r10049 | |
| 2091 | 1907 | * So now the discharge rate is dependent upon F3. |
| 2092 | 1908 | * If F3 is at ground then we discharge to 0V through r6. |
| 2093 | 1909 | * If F3 is out of circuit then we discharge to OP_AMP_NORTON_VBE through r6+r7. */ |
| 2094 | | context->v_cap1 += ((f3 ? OP_AMP_NORTON_VBE : 0.0) - context->v_cap1) * context->exponent_d[f3]; |
| 1910 | m_v_cap1 += ((f3 ? OP_AMP_NORTON_VBE : 0.0) - m_v_cap1) * m_exponent_d[f3]; |
| 2095 | 1911 | } |
| 2096 | 1912 | |
| 2097 | 1913 | /* Calculate c1 current going in to + input. */ |
| 2098 | | i_pos = (context->v_cap1 - OP_AMP_NORTON_VBE) / context->r67; |
| 1914 | i_pos = (m_v_cap1 - OP_AMP_NORTON_VBE) / m_r67; |
| 2099 | 1915 | if ((i_pos < 0) || !f3) i_pos = 0; |
| 2100 | 1916 | |
| 2101 | 1917 | /* Update the c2 cap voltage and current. */ |
| 2102 | 1918 | if (info->r9 != 0) |
| 2103 | 1919 | { |
| 2104 | 1920 | f3 = dst_trigger_function(trig0, trig1, trig2, info->f4); |
| 2105 | | context->v_cap2 += ((f3 ? context->v_trig2 : 0) - context->v_cap2) * context->exponent2[f3]; |
| 2106 | | i_pos += context->v_cap2 / info->r9; |
| 1921 | m_v_cap2 += ((f3 ? m_v_trig2 : 0) - m_v_cap2) * m_exponent2[f3]; |
| 1922 | i_pos += m_v_cap2 / info->r9; |
| 2107 | 1923 | } |
| 2108 | 1924 | |
| 2109 | 1925 | /* Update the c3 cap voltage and current. */ |
| 2110 | 1926 | if (info->r11 != 0) |
| 2111 | 1927 | { |
| 2112 | 1928 | f3 = dst_trigger_function(trig0, trig1, trig2, info->f5); |
| 2113 | | context->v_cap3 += ((f3 ? context->v_trig3 : 0) - context->v_cap3) * context->exponent3[f3]; |
| 2114 | | i_pos += context->v_cap3 / info->r11; |
| 1929 | m_v_cap3 += ((f3 ? m_v_trig3 : 0) - m_v_cap3) * m_exponent3[f3]; |
| 1930 | i_pos += m_v_cap3 / info->r11; |
| 2115 | 1931 | } |
| 2116 | 1932 | |
| 2117 | 1933 | /* Calculate output current. */ |
| r10048 | r10049 | |
| 2119 | 1935 | if (i_out < 0) i_out = 0; |
| 2120 | 1936 | |
| 2121 | 1937 | /* Convert to voltage for final output. */ |
| 2122 | | if (context->has_c4) |
| 1938 | if (m_has_c4) |
| 2123 | 1939 | { |
| 2124 | | if (context->has_r4) |
| 1940 | if (m_has_r4) |
| 2125 | 1941 | { |
| 2126 | 1942 | /* voltage across r4 charging cap */ |
| 2127 | 1943 | i_out *= info->r4; |
| 2128 | 1944 | /* exponential charge */ |
| 2129 | | context->v_cap4 += (i_out - context->v_cap4) * context->exponent4; |
| 1945 | m_v_cap4 += (i_out - m_v_cap4) * m_exponent4; |
| 2130 | 1946 | } |
| 2131 | 1947 | else |
| 2132 | 1948 | /* linear charge */ |
| 2133 | | context->v_cap4 += i_out / context->exponent4; |
| 2134 | | if (context->v_cap4 < 0) |
| 2135 | | context->v_cap4 = 0; |
| 2136 | | node->output[0] = context->v_cap4; |
| 1949 | m_v_cap4 += i_out / m_exponent4; |
| 1950 | if (m_v_cap4 < 0) |
| 1951 | m_v_cap4 = 0; |
| 1952 | this->output[0] = m_v_cap4; |
| 2137 | 1953 | } |
| 2138 | 1954 | else |
| 2139 | | node->output[0] = i_out * info->r4; |
| 1955 | this->output[0] = i_out * info->r4; |
| 2140 | 1956 | |
| 2141 | 1957 | |
| 2142 | 1958 | |
| 2143 | 1959 | /* Clip the output if needed. */ |
| 2144 | | if (node->output[0] > context->v_out_max) node->output[0] = context->v_out_max; |
| 1960 | if (this->output[0] > m_v_out_max) this->output[0] = m_v_out_max; |
| 2145 | 1961 | } |
| 2146 | 1962 | |
| 2147 | 1963 | DISCRETE_RESET(dst_tvca_op_amp) |
| 2148 | 1964 | { |
| 2149 | | DISCRETE_DECLARE_CONTEXT(dst_tvca_op_amp) |
| 2150 | 1965 | DISCRETE_DECLARE_INFO(discrete_op_amp_tvca_info) |
| 2151 | 1966 | |
| 2152 | | context->r67 = info->r6 + info->r7; |
| 1967 | m_r67 = info->r6 + info->r7; |
| 2153 | 1968 | |
| 2154 | | context->v_out_max = info->vP - OP_AMP_NORTON_VBE; |
| 1969 | m_v_out_max = info->vP - OP_AMP_NORTON_VBE; |
| 2155 | 1970 | /* This is probably overkill because R5 is usually much lower then r6 or r7, |
| 2156 | 1971 | * but it is better to play it safe. */ |
| 2157 | | context->v_trig[0] = (info->v1 - 0.6) * RES_VOLTAGE_DIVIDER(info->r5, info->r6); |
| 2158 | | context->v_trig[1] = (info->v1 - 0.6 - OP_AMP_NORTON_VBE) * RES_VOLTAGE_DIVIDER(info->r5, context->r67) + OP_AMP_NORTON_VBE; |
| 2159 | | context->i_fixed = context->v_out_max / info->r1; |
| 1972 | m_v_trig[0] = (info->v1 - 0.6) * RES_VOLTAGE_DIVIDER(info->r5, info->r6); |
| 1973 | m_v_trig[1] = (info->v1 - 0.6 - OP_AMP_NORTON_VBE) * RES_VOLTAGE_DIVIDER(info->r5, m_r67) + OP_AMP_NORTON_VBE; |
| 1974 | m_i_fixed = m_v_out_max / info->r1; |
| 2160 | 1975 | |
| 2161 | | context->v_cap1 = 0; |
| 1976 | m_v_cap1 = 0; |
| 2162 | 1977 | /* Charge rate thru r5 */ |
| 2163 | 1978 | /* There can be a different charge rates depending on function F3. */ |
| 2164 | | context->exponent_c[0] = RC_CHARGE_EXP(RES_2_PARALLEL(info->r5, info->r6) * info->c1); |
| 2165 | | context->exponent_c[1] = RC_CHARGE_EXP(RES_2_PARALLEL(info->r5, context->r67) * info->c1); |
| 1979 | m_exponent_c[0] = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(info->r5, info->r6) * info->c1); |
| 1980 | m_exponent_c[1] = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(info->r5, m_r67) * info->c1); |
| 2166 | 1981 | /* Discharge rate thru r6 + r7 */ |
| 2167 | | context->exponent_d[1] = RC_CHARGE_EXP(context->r67 * info->c1); |
| 1982 | m_exponent_d[1] = RC_CHARGE_EXP_CLASS(m_r67 * info->c1); |
| 2168 | 1983 | /* Discharge rate thru r6 */ |
| 2169 | 1984 | if (info->r6 != 0) |
| 2170 | 1985 | { |
| 2171 | | context->exponent_d[0] = RC_CHARGE_EXP(info->r6 * info->c1); |
| 1986 | m_exponent_d[0] = RC_CHARGE_EXP_CLASS(info->r6 * info->c1); |
| 2172 | 1987 | } |
| 2173 | | context->v_cap2 = 0; |
| 2174 | | context->v_trig2 = (info->v2 - 0.6 - OP_AMP_NORTON_VBE) * RES_VOLTAGE_DIVIDER(info->r8, info->r9); |
| 2175 | | context->exponent2[0] = RC_CHARGE_EXP(info->r9 * info->c2); |
| 2176 | | context->exponent2[1] = RC_CHARGE_EXP(RES_2_PARALLEL(info->r8, info->r9) * info->c2); |
| 2177 | | context->v_cap3 = 0; |
| 2178 | | context->v_trig3 = (info->v3 - 0.6 - OP_AMP_NORTON_VBE) * RES_VOLTAGE_DIVIDER(info->r10, info->r11); |
| 2179 | | context->exponent3[0] = RC_CHARGE_EXP(info->r11 * info->c3); |
| 2180 | | context->exponent3[1] = RC_CHARGE_EXP(RES_2_PARALLEL(info->r10, info->r11) * info->c3); |
| 2181 | | context->v_cap4 = 0; |
| 2182 | | if (info->r4 != 0) context->has_r4 = 1; |
| 2183 | | if (info->c4 != 0) context->has_c4 = 1; |
| 2184 | | if (context->has_r4 && context->has_c4) |
| 2185 | | context->exponent4 = RC_CHARGE_EXP(info->r4 * info->c4); |
| 1988 | m_v_cap2 = 0; |
| 1989 | m_v_trig2 = (info->v2 - 0.6 - OP_AMP_NORTON_VBE) * RES_VOLTAGE_DIVIDER(info->r8, info->r9); |
| 1990 | m_exponent2[0] = RC_CHARGE_EXP_CLASS(info->r9 * info->c2); |
| 1991 | m_exponent2[1] = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(info->r8, info->r9) * info->c2); |
| 1992 | m_v_cap3 = 0; |
| 1993 | m_v_trig3 = (info->v3 - 0.6 - OP_AMP_NORTON_VBE) * RES_VOLTAGE_DIVIDER(info->r10, info->r11); |
| 1994 | m_exponent3[0] = RC_CHARGE_EXP_CLASS(info->r11 * info->c3); |
| 1995 | m_exponent3[1] = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(info->r10, info->r11) * info->c3); |
| 1996 | m_v_cap4 = 0; |
| 1997 | if (info->r4 != 0) m_has_r4 = 1; |
| 1998 | if (info->c4 != 0) m_has_c4 = 1; |
| 1999 | if (m_has_r4 && m_has_c4) |
| 2000 | m_exponent4 = RC_CHARGE_EXP_CLASS(info->r4 * info->c4); |
| 2186 | 2001 | |
| 2187 | | DISCRETE_STEP_CALL(dst_tvca_op_amp); |
| 2002 | this->step(); |
| 2188 | 2003 | } |
| 2189 | 2004 | |
| 2190 | 2005 | |
| r10048 | r10049 | |
| 2246 | 2061 | { |
| 2247 | 2062 | double diff = out_high - out_low; |
| 2248 | 2063 | diff = out ? diff * x_time : diff * (1.0 - x_time); |
| 2249 | | node->output[0] = out_low + diff; |
| 2064 | this->output[0] = out_low + diff; |
| 2250 | 2065 | } |
| 2251 | 2066 | else |
| 2252 | | node->output[0] = out ? out_high : out_low; |
| 2067 | this->output[0] = out ? out_high : out_low; |
| 2253 | 2068 | } |
| 2254 | 2069 | else |
| 2255 | | node->output[0] = out + x_time; |
| 2070 | this->output[0] = out + x_time; |
| 2256 | 2071 | } |
| 2257 | 2072 | |
| 2258 | 2073 | |
| r10048 | r10049 | |
| 2466 | 2281 | { |
| 2467 | 2282 | double diff = out_high - out_low; |
| 2468 | 2283 | diff = out ? diff * x_time : diff * (1.0 - x_time); |
| 2469 | | node->output[0] = out_low + diff; |
| 2284 | this->output[0] = out_low + diff; |
| 2470 | 2285 | } |
| 2471 | 2286 | else |
| 2472 | | node->output[0] = out ? out_high : out_low; |
| 2287 | this->output[0] = out ? out_high : out_low; |
| 2473 | 2288 | } |
| 2474 | 2289 | else |
| 2475 | | node->output[0] = out + x_time; |
| 2290 | this->output[0] = out + x_time; |
| 2476 | 2291 | } |
| 2477 | 2292 | |
| 2478 | 2293 | |
| r10048 | r10049 | |
| 2691 | 2506 | { |
| 2692 | 2507 | double diff = out_high - out_low; |
| 2693 | 2508 | diff = out ? diff * x_time : diff * (1.0 - x_time); |
| 2694 | | node->output[0] = out_low + diff; |
| 2509 | this->output[0] = out_low + diff; |
| 2695 | 2510 | } |
| 2696 | 2511 | else |
| 2697 | | node->output[0] = out ? out_high : out_low; |
| 2512 | this->output[0] = out ? out_high : out_low; |
| 2698 | 2513 | } |
| 2699 | 2514 | else |
| 2700 | | node->output[0] = out + x_time; |
| 2515 | this->output[0] = out + x_time; |
| 2701 | 2516 | } |
| 2702 | 2517 | |
| 2703 | 2518 | |
| r10048 | r10049 | |
| 2952 | 2767 | { |
| 2953 | 2768 | double diff = out_high - out_low; |
| 2954 | 2769 | diff = out ? diff * x_time : diff * (1.0 - x_time); |
| 2955 | | node->output[0] = out_low + diff; |
| 2770 | this->output[0] = out_low + diff; |
| 2956 | 2771 | } |
| 2957 | 2772 | else |
| 2958 | | node->output[0] = out ? out_high : out_low; |
| 2773 | this->output[0] = out ? out_high : out_low; |
| 2959 | 2774 | } |
| 2960 | 2775 | else |
| 2961 | | node->output[0] = out + x_time; |
| 2776 | this->output[0] = out + x_time; |
| 2962 | 2777 | } |
src/emu/sound/discrete.c
| r10048 | r10049 | |
| 39 | 39 | #include "discrete.h" |
| 40 | 40 | |
| 41 | 41 | |
| 42 | |
| 42 | 43 | /************************************* |
| 43 | 44 | * |
| 44 | 45 | * Performance |
| r10048 | r10049 | |
| 56 | 57 | * Values > 500 have a slightly worse performace (too much cache misses?). |
| 57 | 58 | */ |
| 58 | 59 | |
| 59 | | #define MAX_SAMPLES_PER_TASK_SLICE (240) |
| 60 | #define MAX_SAMPLES_PER_TASK_SLICE (960/4) |
| 60 | 61 | |
| 61 | 62 | /************************************* |
| 62 | 63 | * |
| r10048 | r10049 | |
| 77 | 78 | |
| 78 | 79 | /************************************* |
| 79 | 80 | * |
| 80 | | * Prototypes |
| 81 | * Internal classes |
| 81 | 82 | * |
| 82 | 83 | *************************************/ |
| 83 | 84 | |
| 84 | | static void init_nodes(discrete_info *info, const linked_list_entry *block_list, device_t *device); |
| 85 | | static node_description *discrete_find_node(const discrete_info *info, int node); |
| 86 | | //static DEVICE_RESET( discrete ); |
| 87 | | //static STREAM_UPDATE( discrete_stream_update ); |
| 88 | | static STREAM_UPDATE( buffer_stream_update ); |
| 85 | typedef struct |
| 86 | { |
| 87 | const discrete_task *task; |
| 88 | const double *ptr; |
| 89 | int output_node; |
| 90 | double buffer; |
| 91 | } discrete_source_node; |
| 92 | typedef linked_list_t<discrete_source_node *> source_node_list_t; |
| 89 | 93 | |
| 90 | | static int profiling = 0; |
| 94 | class discrete_task |
| 95 | { |
| 96 | friend class discrete_device; |
| 97 | public: |
| 98 | virtual ~discrete_task(void) { } |
| 91 | 99 | |
| 100 | inline void step_nodes(void); |
| 101 | inline bool lock_threadid(INT32 threadid) |
| 102 | { |
| 103 | INT32 prev_id; |
| 104 | prev_id = compare_exchange32(&m_threadid, -1, threadid); |
| 105 | return (prev_id == -1 && m_threadid == threadid); |
| 106 | } |
| 107 | inline void unlock(void) { m_threadid = -1; } |
| 108 | |
| 109 | discrete_device *device; |
| 110 | //const linked_list_entry *list; |
| 111 | node_step_list_t step_list; |
| 112 | |
| 113 | /* list of source nodes */ |
| 114 | source_node_list_t source_list; /* discrete_source_node */ |
| 115 | |
| 116 | int task_group; |
| 117 | |
| 118 | double *m_ptr[DISCRETE_MAX_TASK_OUTPUTS]; |
| 119 | |
| 120 | protected: |
| 121 | discrete_task(discrete_device *pdev) |
| 122 | : device(pdev), task_group(0), m_threadid(-1), m_numbuffered(0) |
| 123 | { |
| 124 | source_list.reset(); |
| 125 | step_list.reset(); |
| 126 | } |
| 127 | |
| 128 | static void *task_callback(void *param, int threadid); |
| 129 | inline bool process(void); |
| 130 | |
| 131 | void check(discrete_task *dest_task); |
| 132 | void prepare_for_queue(int samples); |
| 133 | |
| 134 | double *m_node_buf[DISCRETE_MAX_TASK_OUTPUTS]; |
| 135 | |
| 136 | private: |
| 137 | volatile INT32 m_threadid; |
| 138 | int m_numbuffered; |
| 139 | volatile int m_samples; |
| 140 | |
| 141 | const double *m_source[DISCRETE_MAX_TASK_OUTPUTS]; |
| 142 | discrete_base_node *m_nodes[DISCRETE_MAX_TASK_OUTPUTS]; |
| 143 | }; |
| 144 | |
| 145 | |
| 92 | 146 | /************************************* |
| 93 | 147 | * |
| 94 | | * Debug logging |
| 148 | * Included simulation objects |
| 95 | 149 | * |
| 96 | 150 | *************************************/ |
| 97 | 151 | |
| 98 | | static void CLIB_DECL ATTR_PRINTF(2,3) discrete_log(const discrete_info *disc_info, const char *text, ...) |
| 99 | | { |
| 100 | | if (DISCRETE_DEBUGLOG) |
| 101 | | { |
| 102 | | va_list arg; |
| 103 | | va_start(arg, text); |
| 152 | #include "disc_sys.c" /* discrete core modules and support functions */ |
| 153 | #include "disc_wav.c" /* Wave sources - SINE/SQUARE/NOISE/etc */ |
| 154 | #include "disc_mth.c" /* Math Devices - ADD/GAIN/etc */ |
| 155 | #include "disc_inp.c" /* Input Devices - INPUT/CONST/etc */ |
| 156 | #include "disc_flt.c" /* Filter Devices - RCF/HPF/LPF */ |
| 157 | #include "disc_dev.c" /* Popular Devices - NE555/etc */ |
| 104 | 158 | |
| 105 | | if(disc_info->disclogfile) |
| 106 | | { |
| 107 | | vfprintf(disc_info->disclogfile, text, arg); |
| 108 | | fprintf(disc_info->disclogfile, "\n"); |
| 109 | | fflush(disc_info->disclogfile); |
| 110 | | } |
| 111 | | |
| 112 | | va_end(arg); |
| 113 | | } |
| 114 | | } |
| 115 | | |
| 116 | 159 | /************************************* |
| 117 | 160 | * |
| 118 | 161 | * INLINEs |
| 119 | 162 | * |
| 120 | 163 | *************************************/ |
| 121 | 164 | |
| 122 | | INLINE void linked_list_tail_add(const discrete_info *info, linked_list_entry ***list_tail_ptr, const void *ptr) |
| 165 | INLINE void linked_list_tail_add(const discrete_device *info, linked_list_entry ***list_tail_ptr, const void *ptr) |
| 123 | 166 | { |
| 124 | | **list_tail_ptr = auto_alloc(info->device->machine, linked_list_entry); |
| 167 | **list_tail_ptr = auto_alloc(info->machine, linked_list_entry); |
| 125 | 168 | (**list_tail_ptr)->ptr = ptr; |
| 126 | 169 | (**list_tail_ptr)->next = NULL; |
| 127 | 170 | *list_tail_ptr = &((**list_tail_ptr)->next); |
| r10048 | r10049 | |
| 138 | 181 | return cnt; |
| 139 | 182 | } |
| 140 | 183 | |
| 141 | | INLINE void linked_list_add(const discrete_info *info, linked_list_entry **list, const void *ptr) |
| 184 | INLINE void linked_list_add(const discrete_device *info, linked_list_entry **list, const void *ptr) |
| 142 | 185 | { |
| 143 | 186 | linked_list_entry *entry; |
| 144 | 187 | |
| 145 | 188 | if (*list == NULL) |
| 146 | 189 | { |
| 147 | | *list = auto_alloc(info->device->machine, linked_list_entry); |
| 190 | *list = auto_alloc(info->machine, linked_list_entry); |
| 148 | 191 | (*list)->ptr = ptr; |
| 149 | 192 | (*list)->next = NULL; |
| 150 | 193 | } |
| r10048 | r10049 | |
| 152 | 195 | { |
| 153 | 196 | for (entry = *list; entry != NULL && entry->next != NULL; entry = entry->next) |
| 154 | 197 | ; |
| 155 | | entry->next = auto_alloc(info->device->machine, linked_list_entry); |
| 198 | entry->next = auto_alloc(info->machine, linked_list_entry); |
| 156 | 199 | entry->next->ptr = ptr; |
| 157 | 200 | entry->next->next = NULL; |
| 158 | 201 | } |
| r10048 | r10049 | |
| 160 | 203 | |
| 161 | 204 | /************************************* |
| 162 | 205 | * |
| 163 | | * Included simulation objects |
| 206 | * Task implementation |
| 164 | 207 | * |
| 165 | 208 | *************************************/ |
| 166 | 209 | |
| 167 | | #include "disc_sys.c" /* discrete core modules and support functions */ |
| 168 | | #include "disc_wav.c" /* Wave sources - SINE/SQUARE/NOISE/etc */ |
| 169 | | #include "disc_mth.c" /* Math Devices - ADD/GAIN/etc */ |
| 170 | | #include "disc_inp.c" /* Input Devices - INPUT/CONST/etc */ |
| 171 | | #include "disc_flt.c" /* Filter Devices - RCF/HPF/LPF */ |
| 172 | | #include "disc_dev.c" /* Popular Devices - NE555/etc */ |
| 210 | inline void discrete_task::step_nodes(void) |
| 211 | { |
| 173 | 212 | |
| 213 | for_each(discrete_source_node *, sn, &source_list) |
| 214 | { |
| 215 | sn.item()->buffer = *sn.item()->ptr++; |
| 216 | } |
| 174 | 217 | |
| 218 | if (EXPECTED(!device->profiling())) |
| 219 | { |
| 220 | for_each(discrete_step_interface *, entry, &step_list) |
| 221 | { |
| 222 | /* Now step the node */ |
| 223 | entry.item()->step(); |
| 224 | } |
| 225 | } |
| 226 | else |
| 227 | { |
| 228 | osd_ticks_t last = get_profile_ticks(); |
| 175 | 229 | |
| 176 | | /************************************* |
| 177 | | * |
| 178 | | * Master module list |
| 179 | | * |
| 180 | | *************************************/ |
| 230 | for_each(discrete_step_interface *, entry, &step_list) |
| 231 | { |
| 232 | discrete_step_interface *node = entry.item(); |
| 181 | 233 | |
| 182 | | static const discrete_module module_list[] = |
| 183 | | { |
| 184 | | { DSO_OUTPUT ,"DSO_OUTPUT" , 0 ,0 ,dso_output_reset ,dso_output_step ,NULL ,NULL }, |
| 185 | | { DSO_CSVLOG ,"DSO_CSVLOG" , 0 ,sizeof(struct dso_csvlog_context) ,NULL ,dso_csvlog_step ,dso_csvlog_start ,dso_csvlog_stop }, |
| 186 | | { DSO_WAVELOG ,"DSO_WAVELOG" , 0 ,sizeof(struct dso_wavlog_context) ,NULL ,dso_wavlog_step ,dso_wavlog_start ,dso_wavlog_stop }, |
| 187 | | { DSO_IMPORT ,"DSO_IMPORT" , 0 ,0 ,NULL ,NULL ,NULL ,NULL }, |
| 234 | node->run_time -= last; |
| 235 | node->step(); |
| 236 | last = get_profile_ticks(); |
| 237 | node->run_time += last; |
| 238 | } |
| 239 | } |
| 188 | 240 | |
| 189 | | /* parallel modules */ |
| 190 | | { DSO_TASK_START ,"DSO_TASK_START" , 0 ,0 ,dso_task_reset ,dso_task_start_step ,dso_task_start_start ,NULL }, |
| 191 | | { DSO_TASK_END ,"DSO_TASK_END" , 0 ,0 ,dso_task_reset ,dso_task_end_step ,NULL ,NULL }, |
| 192 | | { DSO_TASK_SYNC ,"DSO_TASK_SYNC" , 0 ,0 ,NULL ,NULL ,NULL ,NULL }, |
| 241 | for (int i = 0; i < m_numbuffered; i++) |
| 242 | *(m_ptr[i]++) = *m_source[i]; |
| 243 | } |
| 193 | 244 | |
| 194 | | /* nop */ |
| 195 | | { DSS_NOP ,"DSS_NOP" , 0 ,0 ,NULL ,NULL ,NULL ,NULL }, |
| 245 | void *discrete_task::task_callback(void *param, int threadid) |
| 246 | { |
| 247 | task_list_t *list = (task_list_t *) param; |
| 248 | do |
| 249 | { |
| 250 | for_each(discrete_task *, task, list) |
| 251 | { |
| 252 | /* try to lock */ |
| 253 | if (task.item()->lock_threadid(threadid)) |
| 254 | { |
| 255 | if (!task.item()->process()) |
| 256 | return NULL; |
| 257 | task.item()->unlock(); |
| 258 | } |
| 259 | } |
| 260 | } while (1); |
| 196 | 261 | |
| 197 | | /* from disc_inp.c */ |
| 198 | | { DSS_ADJUSTMENT ,"DSS_ADJUSTMENT" , 1 ,sizeof(struct dss_adjustment_context) ,dss_adjustment_reset ,dss_adjustment_step ,NULL ,NULL }, |
| 199 | | { DSS_CONSTANT ,"DSS_CONSTANT" , 1 ,0 ,dss_constant_reset ,NULL ,NULL ,NULL }, |
| 200 | | { DSS_INPUT_DATA ,"DSS_INPUT_DATA" , 1 ,sizeof(struct dss_input_context) ,dss_input_reset ,NULL ,NULL ,NULL }, |
| 201 | | { DSS_INPUT_LOGIC ,"DSS_INPUT_LOGIC" , 1 ,sizeof(struct dss_input_context) ,dss_input_reset ,NULL ,NULL ,NULL }, |
| 202 | | { DSS_INPUT_NOT ,"DSS_INPUT_NOT" , 1 ,sizeof(struct dss_input_context) ,dss_input_reset ,NULL ,NULL ,NULL }, |
| 203 | | { DSS_INPUT_PULSE ,"DSS_INPUT_PULSE" , 1 ,sizeof(struct dss_input_context) ,dss_input_reset ,dss_input_pulse_step ,NULL ,NULL }, |
| 204 | | { DSS_INPUT_STREAM,"DSS_INPUT_STREAM", 1 ,sizeof(struct dss_input_context) ,dss_input_stream_reset,dss_input_stream_step,dss_input_stream_start,NULL }, |
| 205 | | { DSS_INPUT_BUFFER,"DSS_INPUT_BUFFER", 1 ,sizeof(struct dss_input_context) ,dss_input_stream_reset,dss_input_stream_step,dss_input_stream_start,NULL }, |
| 262 | return NULL; |
| 263 | } |
| 206 | 264 | |
| 207 | | /* from disc_wav.c */ |
| 208 | | /* Generic modules */ |
| 209 | | { DSS_COUNTER ,"DSS_COUNTER" , 1 ,sizeof(struct dss_counter_context) ,dss_counter_reset ,dss_counter_step ,NULL ,NULL }, |
| 210 | | { DSS_LFSR_NOISE ,"DSS_LFSR_NOISE" , 2 ,sizeof(struct dss_lfsr_context) ,dss_lfsr_reset ,dss_lfsr_step ,NULL ,NULL }, |
| 211 | | { DSS_NOISE ,"DSS_NOISE" , 1 ,sizeof(struct dss_noise_context) ,dss_noise_reset ,dss_noise_step ,NULL ,NULL }, |
| 212 | | { DSS_NOTE ,"DSS_NOTE" , 1 ,sizeof(struct dss_note_context) ,dss_note_reset ,dss_note_step ,NULL ,NULL }, |
| 213 | | { DSS_SAWTOOTHWAVE,"DSS_SAWTOOTHWAVE", 1 ,sizeof(struct dss_sawtoothwave_context),dss_sawtoothwave_reset,dss_sawtoothwave_step,NULL ,NULL }, |
| 214 | | { DSS_SINEWAVE ,"DSS_SINEWAVE" , 1 ,sizeof(struct dss_sinewave_context) ,dss_sinewave_reset ,dss_sinewave_step ,NULL ,NULL }, |
| 215 | | { DSS_SQUAREWAVE ,"DSS_SQUAREWAVE" , 1 ,sizeof(struct dss_squarewave_context) ,dss_squarewave_reset ,dss_squarewave_step ,NULL ,NULL }, |
| 216 | | { DSS_SQUAREWFIX ,"DSS_SQUAREWFIX" , 1 ,sizeof(struct dss_squarewfix_context) ,dss_squarewfix_reset ,dss_squarewfix_step ,NULL ,NULL }, |
| 217 | | { DSS_SQUAREWAVE2 ,"DSS_SQUAREWAVE2" , 1 ,sizeof(struct dss_squarewave_context) ,dss_squarewave2_reset ,dss_squarewave2_step ,NULL ,NULL }, |
| 218 | | { DSS_TRIANGLEWAVE,"DSS_TRIANGLEWAVE", 1 ,sizeof(struct dss_trianglewave_context),dss_trianglewave_reset,dss_trianglewave_step,NULL ,NULL }, |
| 219 | | /* Component specific modules */ |
| 220 | | { DSS_INVERTER_OSC ,"DSS_INVERTER_OSC" , 1 ,sizeof(struct dss_inverter_osc_context) ,dss_inverter_osc_reset ,dss_inverter_osc_step ,NULL ,NULL }, |
| 221 | | { DSS_OP_AMP_OSC ,"DSS_OP_AMP_OSC" , 1 ,sizeof(struct dss_op_amp_osc_context) ,dss_op_amp_osc_reset ,dss_op_amp_osc_step ,NULL ,NULL }, |
| 222 | | { DSS_SCHMITT_OSC ,"DSS_SCHMITT_OSC" , 1 ,sizeof(struct dss_schmitt_osc_context) ,dss_schmitt_osc_reset ,dss_schmitt_osc_step ,NULL ,NULL }, |
| 223 | | /* Not yet implemented */ |
| 224 | | { DSS_ADSR ,"DSS_ADSR" , 1 ,sizeof(struct dss_adsr_context) ,dss_adsrenv_reset ,dss_adsrenv_step ,NULL ,NULL }, |
| 265 | bool discrete_task::process(void) |
| 266 | { |
| 267 | int samples = MIN(m_samples, MAX_SAMPLES_PER_TASK_SLICE); |
| 225 | 268 | |
| 226 | | /* from disc_mth.c */ |
| 227 | | /* Generic modules */ |
| 228 | | { DST_ADDER ,"DST_ADDER" , 1 ,0 ,NULL ,dst_adder_step ,NULL ,NULL }, |
| 229 | | { DST_CLAMP ,"DST_CLAMP" , 1 ,0 ,NULL ,dst_clamp_step ,NULL ,NULL }, |
| 230 | | { DST_DIVIDE ,"DST_DIVIDE" , 1 ,0 ,NULL ,dst_divide_step ,NULL ,NULL }, |
| 231 | | { DST_GAIN ,"DST_GAIN" , 1 ,0 ,NULL ,dst_gain_step ,NULL ,NULL }, |
| 232 | | { DST_LOGIC_INV ,"DST_LOGIC_INV" , 1 ,0 ,NULL ,dst_logic_inv_step ,NULL ,NULL }, |
| 233 | | { DST_BITS_DECODE ,"DST_BITS_DECODE" , 8 ,sizeof(struct dst_bits_decode_context) ,dst_bits_decode_reset ,dst_bits_decode_step ,NULL ,NULL }, |
| 234 | | { DST_LOGIC_AND ,"DST_LOGIC_AND" , 1 ,0 ,NULL ,dst_logic_and_step ,NULL ,NULL }, |
| 235 | | { DST_LOGIC_NAND ,"DST_LOGIC_NAND" , 1 ,0 ,NULL ,dst_logic_nand_step ,NULL ,NULL }, |
| 236 | | { DST_LOGIC_OR ,"DST_LOGIC_OR" , 1 ,0 ,NULL ,dst_logic_or_step ,NULL ,NULL }, |
| 237 | | { DST_LOGIC_NOR ,"DST_LOGIC_NOR" , 1 ,0 ,NULL ,dst_logic_nor_step ,NULL ,NULL }, |
| 238 | | { DST_LOGIC_XOR ,"DST_LOGIC_XOR" , 1 ,0 ,NULL ,dst_logic_xor_step ,NULL ,NULL }, |
| 239 | | { DST_LOGIC_NXOR ,"DST_LOGIC_NXOR" , 1 ,0 ,NULL ,dst_logic_nxor_step ,NULL ,NULL }, |
| 240 | | { DST_LOGIC_DFF ,"DST_LOGIC_DFF" , 1 ,sizeof(struct dst_flipflop_context) ,dst_logic_ff_reset ,dst_logic_dff_step ,NULL ,NULL }, |
| 241 | | { DST_LOGIC_JKFF ,"DST_LOGIC_JKFF" , 1 ,sizeof(struct dst_flipflop_context) ,dst_logic_ff_reset ,dst_logic_jkff_step ,NULL ,NULL }, |
| 242 | | { DST_LOGIC_SHIFT ,"DST_LOGIC_SHIFT" , 1 ,sizeof(struct dst_shift_context) ,dst_logic_shift_reset ,dst_logic_shift_step ,NULL ,NULL }, |
| 243 | | { DST_LOOKUP_TABLE,"DST_LOOKUP_TABLE", 1 ,0 ,NULL ,dst_lookup_table_step,NULL ,NULL }, |
| 244 | | { DST_MULTIPLEX ,"DST_MULTIPLEX" , 1 ,sizeof(struct dst_size_context) ,dst_multiplex_reset ,dst_multiplex_step ,NULL ,NULL }, |
| 245 | | { DST_ONESHOT ,"DST_ONESHOT" , 1 ,sizeof(struct dst_oneshot_context) ,dst_oneshot_reset ,dst_oneshot_step ,NULL ,NULL }, |
| 246 | | { DST_RAMP ,"DST_RAMP" , 1 ,sizeof(struct dst_ramp_context) ,dst_ramp_reset ,dst_ramp_step ,NULL ,NULL }, |
| 247 | | { DST_SAMPHOLD ,"DST_SAMPHOLD" , 1 ,sizeof(struct dst_samphold_context) ,dst_samphold_reset ,dst_samphold_step ,NULL ,NULL }, |
| 248 | | { DST_SWITCH ,"DST_SWITCH" , 1 ,0 ,NULL ,dst_switch_step ,NULL ,NULL }, |
| 249 | | { DST_ASWITCH ,"DST_ASWITCH" , 1 ,0 ,NULL ,dst_aswitch_step ,NULL ,NULL }, |
| 250 | | { DST_TRANSFORM ,"DST_TRANSFORM" , 1 ,0 ,NULL ,dst_transform_step ,NULL ,NULL }, |
| 251 | | /* Component specific */ |
| 252 | | { DST_COMP_ADDER ,"DST_COMP_ADDER" , 1 ,sizeof(struct dst_comp_adder_context) ,dst_comp_adder_reset ,dst_comp_adder_step ,NULL ,NULL }, |
| 253 | | { DST_DAC_R1 ,"DST_DAC_R1" , 1 ,sizeof(struct dst_dac_r1_context) ,dst_dac_r1_reset ,dst_dac_r1_step ,NULL ,NULL }, |
| 254 | | { DST_DIODE_MIX ,"DST_DIODE_MIX" , 1 ,sizeof(struct dst_diode_mix_context) ,dst_diode_mix_reset ,dst_diode_mix_step ,NULL ,NULL }, |
| 255 | | { DST_INTEGRATE ,"DST_INTEGRATE" , 1 ,sizeof(struct dst_integrate_context) ,dst_integrate_reset ,dst_integrate_step ,NULL ,NULL }, |
| 256 | | { DST_MIXER ,"DST_MIXER" , 1 ,sizeof(struct dst_mixer_context) ,dst_mixer_reset ,dst_mixer_step ,NULL ,NULL }, |
| 257 | | { DST_OP_AMP ,"DST_OP_AMP" , 1 ,sizeof(struct dst_op_amp_context) ,dst_op_amp_reset ,dst_op_amp_step ,NULL ,NULL }, |
| 258 | | { DST_OP_AMP_1SHT ,"DST_OP_AMP_1SHT" , 1 ,sizeof(struct dst_op_amp_1sht_context) ,dst_op_amp_1sht_reset ,dst_op_amp_1sht_step ,NULL ,NULL }, |
| 259 | | { DST_TVCA_OP_AMP ,"DST_TVCA_OP_AMP" , 1 ,sizeof(struct dst_tvca_op_amp_context) ,dst_tvca_op_amp_reset ,dst_tvca_op_amp_step ,NULL ,NULL }, |
| 260 | | { DST_VCA ,"DST_VCA" , 1 ,0 ,NULL ,NULL ,NULL ,NULL }, |
| 261 | | { DST_XTIME_BUFFER,"DST_XTIME_BUFFER", 1 ,0 ,NULL ,dst_xtime_buffer_step,NULL ,NULL }, |
| 262 | | { DST_XTIME_AND ,"DST_XTIME_AND" , 1 ,0 ,NULL ,dst_xtime_and_step ,NULL ,NULL }, |
| 263 | | { DST_XTIME_OR ,"DST_XTIME_OR" , 1 ,0 ,NULL ,dst_xtime_or_step ,NULL ,NULL }, |
| 264 | | { DST_XTIME_XOR ,"DST_XTIME_XOR" , 1 ,0 ,NULL ,dst_xtime_xor_step ,NULL ,NULL }, |
| 269 | /* check dependencies */ |
| 270 | for_each(discrete_source_node *, sn, &source_list) |
| 271 | { |
| 272 | int avail; |
| 265 | 273 | |
| 266 | | /* from disc_flt.c */ |
| 267 | | /* Generic modules */ |
| 268 | | { DST_FILTER1 ,"DST_FILTER1" , 1 ,sizeof(struct dst_filter1_context) ,dst_filter1_reset ,dst_filter1_step ,NULL ,NULL }, |
| 269 | | { DST_FILTER2 ,"DST_FILTER2" , 1 ,sizeof(struct dst_filter2_context) ,dst_filter2_reset ,dst_filter2_step ,NULL ,NULL }, |
| 270 | | /* Component specific modules */ |
| 271 | | { DST_SALLEN_KEY ,"DST_SALLEN_KEY" , 1 ,sizeof(struct dst_filter2_context) ,dst_sallen_key_reset ,dst_sallen_key_step ,NULL ,NULL }, |
| 272 | | { DST_CRFILTER ,"DST_CRFILTER" , 1 ,sizeof(struct dst_rcfilter_context) ,dst_crfilter_reset ,dst_crfilter_step ,NULL ,NULL }, |
| 273 | | { DST_OP_AMP_FILT ,"DST_OP_AMP_FILT" , 1 ,sizeof(struct dst_op_amp_filt_context) ,dst_op_amp_filt_reset ,dst_op_amp_filt_step ,NULL ,NULL }, |
| 274 | | { DST_RC_CIRCUIT_1,"DST_RC_CIRCUIT_1", 1 ,sizeof(struct dst_rc_circuit_1_context),dst_rc_circuit_1_reset,dst_rc_circuit_1_step,NULL ,NULL }, |
| 275 | | { DST_RCDISC ,"DST_RCDISC" , 1 ,sizeof(struct dst_rcdisc_context) ,dst_rcdisc_reset ,dst_rcdisc_step ,NULL ,NULL }, |
| 276 | | { DST_RCDISC2 ,"DST_RCDISC2" , 1 ,sizeof(struct dst_rcdisc_context) ,dst_rcdisc2_reset ,dst_rcdisc2_step ,NULL ,NULL }, |
| 277 | | { DST_RCDISC3 ,"DST_RCDISC3" , 1 ,sizeof(struct dst_rcdisc_context) ,dst_rcdisc3_reset ,dst_rcdisc3_step ,NULL ,NULL }, |
| 278 | | { DST_RCDISC4 ,"DST_RCDISC4" , 1 ,sizeof(struct dst_rcdisc4_context) ,dst_rcdisc4_reset ,dst_rcdisc4_step ,NULL ,NULL }, |
| 279 | | { DST_RCDISC5 ,"DST_RCDISC5" , 1 ,sizeof(struct dst_rcdisc_context) ,dst_rcdisc5_reset ,dst_rcdisc5_step ,NULL ,NULL }, |
| 280 | | { DST_RCINTEGRATE ,"DST_RCINTEGRATE" , 1 ,sizeof(struct dst_rcintegrate_context) ,dst_rcintegrate_reset ,dst_rcintegrate_step ,NULL ,NULL }, |
| 281 | | { DST_RCDISC_MOD ,"DST_RCDISC_MOD" , 1 ,sizeof(struct dst_rcdisc_mod_context) ,dst_rcdisc_mod_reset ,dst_rcdisc_mod_step ,NULL ,NULL }, |
| 282 | | { DST_RCFILTER ,"DST_RCFILTER" , 1 ,sizeof(struct dst_rcfilter_context) ,dst_rcfilter_reset ,dst_rcfilter_step ,NULL ,NULL }, |
| 283 | | { DST_RCFILTER_SW ,"DST_RCFILTER_SW" , 1 ,sizeof(struct dst_rcfilter_sw_context) ,dst_rcfilter_sw_reset ,dst_rcfilter_sw_step ,NULL ,NULL }, |
| 284 | | /* For testing - seem to be buggered. Use versions not ending in N. */ |
| 285 | | { DST_RCFILTERN ,"DST_RCFILTERN" , 1 ,sizeof(struct dst_filter1_context) ,dst_rcfilterN_reset ,dst_filter1_step ,NULL ,NULL }, |
| 286 | | { DST_RCDISCN ,"DST_RCDISCN" , 1 ,sizeof(struct dst_filter1_context) ,dst_rcdiscN_reset ,dst_rcdiscN_step ,NULL ,NULL }, |
| 287 | | { DST_RCDISC2N ,"DST_RCDISC2N" , 1 ,sizeof(struct dst_rcdisc2_context) ,dst_rcdisc2N_reset ,dst_rcdisc2N_step ,NULL ,NULL }, |
| 274 | avail = sn.item()->task->m_ptr[sn.item()->output_node] - sn.item()->ptr; |
| 275 | assert_always(avail >= 0, "task_callback: available samples are negative"); |
| 276 | if (avail < samples) |
| 277 | samples = avail; |
| 278 | } |
| 288 | 279 | |
| 289 | | /* from disc_dev.c */ |
| 290 | | /* generic modules */ |
| 291 | | { DST_CUSTOM ,"DST_CUSTOM" , 8 ,0 ,NULL ,NULL ,NULL ,NULL }, |
| 292 | | /* Component specific modules */ |
| 293 | | { DSD_555_ASTBL ,"DSD_555_ASTBL" , 1 ,sizeof(struct dsd_555_astbl_context) ,dsd_555_astbl_reset ,dsd_555_astbl_step ,NULL ,NULL }, |
| 294 | | { DSD_555_MSTBL ,"DSD_555_MSTBL" , 1 ,sizeof(struct dsd_555_mstbl_context) ,dsd_555_mstbl_reset ,dsd_555_mstbl_step ,NULL ,NULL }, |
| 295 | | { DSD_555_CC ,"DSD_555_CC" , 1 ,sizeof(struct dsd_555_cc_context) ,dsd_555_cc_reset ,dsd_555_cc_step ,NULL ,NULL }, |
| 296 | | { DSD_555_VCO1 ,"DSD_555_VCO1" , 1 ,sizeof(struct dsd_555_vco1_context) ,dsd_555_vco1_reset ,dsd_555_vco1_step ,NULL ,NULL }, |
| 297 | | { DSD_566 ,"DSD_566" , 1 ,sizeof(struct dsd_566_context) ,dsd_566_reset ,dsd_566_step ,NULL ,NULL }, |
| 298 | | { DSD_LS624 ,"DSD_LS624" , 1 ,sizeof(struct dsd_ls624_context) ,dsd_ls624_reset ,dsd_ls624_step ,NULL ,NULL }, |
| 299 | | /* must be the last one */ |
| 300 | | { DSS_NULL ,"DSS_NULL" , 0 ,0 ,NULL ,NULL ,NULL ,NULL } |
| 301 | | }; |
| 280 | m_samples -= samples; |
| 281 | assert_always(m_samples >=0, "task_callback: task_samples got negative"); |
| 282 | while (samples > 0) |
| 283 | { |
| 284 | /* step */ |
| 285 | step_nodes(); |
| 286 | samples--; |
| 287 | } |
| 288 | if (m_samples == 0) |
| 289 | { |
| 290 | /* return and keep the task locked so it is not picked up by other worker threads */ |
| 291 | return false; |
| 292 | } |
| 293 | return true; |
| 294 | } |
| 302 | 295 | |
| 303 | | INLINE void step_nodes_in_list(node_list_t &list) |
| 296 | void discrete_task::prepare_for_queue(int samples) |
| 304 | 297 | { |
| 298 | m_samples = samples; |
| 299 | /* set up task buffers */ |
| 300 | for (int i = 0; i < m_numbuffered; i++) |
| 301 | m_ptr[i] = m_node_buf[i]; |
| 305 | 302 | |
| 306 | | if (EXPECTED(!profiling)) |
| 303 | /* initialize sources */ |
| 304 | for_each(discrete_source_node *, sn, &source_list) |
| 307 | 305 | { |
| 308 | | for_each(node_description *, entry, &list) |
| 309 | | { |
| 310 | | /* Now step the node */ |
| 311 | | (*entry.item()->step)(entry.item()); |
| 312 | | } |
| 306 | sn.item()->ptr = sn.item()->task->m_node_buf[sn.item()->output_node]; |
| 313 | 307 | } |
| 314 | | else |
| 308 | } |
| 309 | |
| 310 | void discrete_task::check(discrete_task *dest_task) |
| 311 | { |
| 312 | int inputnum; |
| 313 | |
| 314 | /* Determine, which nodes in the task are referenced by nodes in dest_task |
| 315 | * and add them to the list of nodes to be buffered for further processing |
| 316 | */ |
| 317 | for_each(discrete_step_interface *, node_entry, &step_list) |
| 315 | 318 | { |
| 316 | | osd_ticks_t last = get_profile_ticks(); |
| 317 | 319 | |
| 318 | | for_each(node_description *, entry, &list) |
| 320 | discrete_base_node *task_node = node_entry.item()->self; |
| 321 | |
| 322 | for_each(discrete_step_interface *, step_entry, &dest_task->step_list) |
| 319 | 323 | { |
| 320 | | node_description *node = entry.item(); |
| 324 | discrete_base_node *dest_node = step_entry.item()->self; |
| 321 | 325 | |
| 322 | | node->run_time -= last; |
| 323 | | (*node->step)(node); |
| 324 | | last = get_profile_ticks(); |
| 325 | | node->run_time += last; |
| 326 | /* loop over all active inputs */ |
| 327 | for (inputnum = 0; inputnum < dest_node->active_inputs(); inputnum++) |
| 328 | { |
| 329 | int inputnode = dest_node->input_node(inputnum); |
| 330 | if IS_VALUE_A_NODE(inputnode) |
| 331 | { |
| 332 | if (NODE_DEFAULT_NODE(task_node->block_node()) == NODE_DEFAULT_NODE(inputnode)) |
| 333 | { |
| 334 | discrete_source_node *source; |
| 335 | int i, found = -1; |
| 336 | |
| 337 | for (i = 0; i < m_numbuffered; i++) |
| 338 | if (m_nodes[i]->block_node() == inputnode) |
| 339 | { |
| 340 | found = i; |
| 341 | break; |
| 342 | } |
| 343 | |
| 344 | if (found<0) |
| 345 | { |
| 346 | if (m_numbuffered >= DISCRETE_MAX_TASK_OUTPUTS) |
| 347 | fatalerror("dso_task_start - Number of maximum buffered nodes exceeded"); |
| 348 | |
| 349 | m_node_buf[m_numbuffered] = auto_alloc_array(task_node->device->machine, double, |
| 350 | ((task_node->sample_rate() + STREAMS_UPDATE_FREQUENCY) / STREAMS_UPDATE_FREQUENCY)); |
| 351 | m_source[m_numbuffered] = (double *) dest_node->input[inputnum]; |
| 352 | m_nodes[m_numbuffered] = task_node->device->discrete_find_node(inputnode); |
| 353 | i = m_numbuffered; |
| 354 | m_numbuffered++; |
| 355 | } |
| 356 | device->discrete_log("dso_task_start - buffering %d(%d) in task %p group %d referenced by %d group %d", NODE_INDEX(inputnode), NODE_CHILD_NODE_NUM(inputnode), this, task_group, dest_node->index(), dest_task->task_group); |
| 357 | |
| 358 | /* register into source list */ |
| 359 | source = auto_alloc(dest_node->device->machine, discrete_source_node); |
| 360 | dest_task->source_list.add_tail(source); |
| 361 | source->task = this; |
| 362 | source->output_node = i; |
| 363 | |
| 364 | /* point the input to a buffered location */ |
| 365 | dest_node->input[inputnum] = &source->buffer; |
| 366 | |
| 367 | } |
| 368 | } |
| 369 | } |
| 326 | 370 | } |
| 327 | 371 | } |
| 328 | 372 | } |
| 329 | 373 | |
| 330 | 374 | /************************************* |
| 331 | 375 | * |
| 332 | | * Find a given node |
| 376 | * Base node implementation |
| 333 | 377 | * |
| 334 | 378 | *************************************/ |
| 335 | 379 | |
| 336 | | static node_description *discrete_find_node(const discrete_info *info, int node) |
| 380 | discrete_base_node::discrete_base_node() : |
| 381 | m_step_intf(NULL), |
| 382 | m_input_intf(NULL) |
| 337 | 383 | { |
| 384 | output[0] = 0.0; |
| 385 | } |
| 386 | |
| 387 | |
| 388 | discrete_base_node::~discrete_base_node(void) |
| 389 | { |
| 390 | /* currently noting */ |
| 391 | } |
| 392 | |
| 393 | void discrete_base_node::init(discrete_device * pdev, const discrete_sound_block *xblock) |
| 394 | { |
| 395 | device = pdev; |
| 396 | m_block = xblock; |
| 397 | |
| 398 | m_custom = m_block->custom; |
| 399 | m_active_inputs = m_block->active_inputs; |
| 400 | |
| 401 | m_step_intf = dynamic_cast<discrete_step_interface *>(this); |
| 402 | m_input_intf = dynamic_cast<discrete_input_interface *>(this); |
| 403 | m_output_intf = dynamic_cast<discrete_output_interface *>(this); |
| 404 | |
| 405 | if (m_step_intf) |
| 406 | { |
| 407 | m_step_intf->run_time = 0; |
| 408 | m_step_intf->self = this; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | void discrete_base_node::start(void) |
| 413 | { |
| 414 | } |
| 415 | |
| 416 | int discrete_base_node::index(void) |
| 417 | { |
| 418 | return NODE_INDEX(m_block->node); |
| 419 | } |
| 420 | |
| 421 | void discrete_base_node::save_state(device_t *device) |
| 422 | { |
| 423 | if (m_block->node != NODE_SPECIAL) |
| 424 | state_save_register_device_item_array(device, m_block->node, output); |
| 425 | } |
| 426 | |
| 427 | discrete_base_node *discrete_device::discrete_find_node(int node) |
| 428 | { |
| 338 | 429 | if (node < NODE_START || node > NODE_END) return NULL; |
| 339 | | return info->indexed_node[NODE_INDEX(node)]; |
| 430 | return m_indexed_node[NODE_INDEX(node)]; |
| 340 | 431 | } |
| 341 | 432 | |
| 433 | void discrete_base_node::find_input_nodes(void) |
| 434 | { |
| 435 | int inputnum; |
| 436 | |
| 437 | /* loop over all active inputs */ |
| 438 | for (inputnum = 0; inputnum < m_active_inputs; inputnum++) |
| 439 | { |
| 440 | int inputnode = m_block->input_node[inputnum]; |
| 441 | |
| 442 | /* if this input is node-based, find the node in the indexed list */ |
| 443 | if IS_VALUE_A_NODE(inputnode) |
| 444 | { |
| 445 | discrete_base_node *node_ref = device->m_indexed_node[NODE_INDEX(inputnode)]; |
| 446 | if (!node_ref) |
| 447 | fatalerror("discrete_start - NODE_%02d referenced a non existent node NODE_%02d", index(), NODE_INDEX(inputnode)); |
| 448 | |
| 449 | if ((NODE_CHILD_NODE_NUM(inputnode) >= node_ref->max_output()) /*&& (node_ref->module_type() != DST_CUSTOM)*/) |
| 450 | fatalerror("discrete_start - NODE_%02d referenced non existent output %d on node NODE_%02d", index(), NODE_CHILD_NODE_NUM(inputnode), NODE_INDEX(inputnode)); |
| 451 | |
| 452 | input[inputnum] = &(node_ref->output[NODE_CHILD_NODE_NUM(inputnode)]); /* Link referenced node out to input */ |
| 453 | m_input_is_node |= 1 << inputnum; /* Bit flag if input is node */ |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | /* warn if trying to use a node for an input that can only be static */ |
| 458 | if IS_VALUE_A_NODE(m_block->initial[inputnum]) |
| 459 | { |
| 460 | device->discrete_log("Warning - discrete_start - NODE_%02d trying to use a node on static input %d", index(), inputnum); |
| 461 | /* also report it in the error log so it is not missed */ |
| 462 | logerror("Warning - discrete_start - NODE_%02d trying to use a node on static input %d", index(), inputnum); |
| 463 | } |
| 464 | else |
| 465 | { |
| 466 | input[inputnum] = &(m_block->initial[inputnum]); |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | for (inputnum = m_active_inputs; inputnum < DISCRETE_MAX_INPUTS; inputnum++) |
| 471 | { |
| 472 | /* FIXME: Check that no nodes follow ! */ |
| 473 | input[inputnum] = &(m_block->initial[inputnum]); |
| 474 | } |
| 475 | } |
| 476 | |
| 342 | 477 | /************************************* |
| 343 | 478 | * |
| 344 | | * Build import list |
| 479 | * Device implementation |
| 345 | 480 | * |
| 346 | 481 | *************************************/ |
| 347 | 482 | |
| 348 | | static void discrete_build_list(discrete_info *info, const discrete_sound_block *intf, linked_list_entry ***current) |
| 483 | |
| 484 | //------------------------------------------------- |
| 485 | // discrete_log: Debug logging |
| 486 | //------------------------------------------------- |
| 487 | |
| 488 | void CLIB_DECL ATTR_PRINTF(2,3) discrete_device::discrete_log(const char *text, ...) const |
| 349 | 489 | { |
| 490 | if (DISCRETE_DEBUGLOG) |
| 491 | { |
| 492 | va_list arg; |
| 493 | va_start(arg, text); |
| 494 | |
| 495 | if(m_disclogfile) |
| 496 | { |
| 497 | vfprintf(m_disclogfile, text, arg); |
| 498 | fprintf(m_disclogfile, "\n"); |
| 499 | fflush(m_disclogfile); |
| 500 | } |
| 501 | |
| 502 | va_end(arg); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | //------------------------------------------------- |
| 507 | // discrete_build_list: Build import list |
| 508 | //------------------------------------------------- |
| 509 | |
| 510 | void discrete_device::discrete_build_list(const discrete_sound_block *intf, linked_list_entry ***current) |
| 511 | { |
| 350 | 512 | int node_count = 0; |
| 351 | 513 | |
| 352 | 514 | for (; intf[node_count].type != DSS_NULL; ) |
| r10048 | r10049 | |
| 354 | 516 | /* scan imported */ |
| 355 | 517 | if (intf[node_count].type == DSO_IMPORT) |
| 356 | 518 | { |
| 357 | | discrete_log(info, "discrete_build_list() - DISCRETE_IMPORT @ NODE_%02d", NODE_INDEX(intf[node_count].node) ); |
| 358 | | discrete_build_list(info, (discrete_sound_block *) intf[node_count].custom, current); |
| 519 | discrete_log("discrete_build_list() - DISCRETE_IMPORT @ NODE_%02d", NODE_INDEX(intf[node_count].node) ); |
| 520 | discrete_build_list((discrete_sound_block *) intf[node_count].custom, current); |
| 359 | 521 | } |
| 360 | 522 | else if (intf[node_count].type == DSO_REPLACE) |
| 361 | 523 | { |
| r10048 | r10049 | |
| 365 | 527 | if (intf[node_count].type == DSS_NULL) |
| 366 | 528 | fatalerror("discrete_build_list: DISCRETE_REPLACE at end of node_list"); |
| 367 | 529 | |
| 368 | | for (entry = info->block_list; entry != NULL; entry = entry->next) |
| 530 | for (entry = m_block_list; entry != NULL; entry = entry->next) |
| 369 | 531 | { |
| 370 | 532 | discrete_sound_block *block = (discrete_sound_block *) entry->ptr; |
| 371 | 533 | |
| r10048 | r10049 | |
| 373 | 535 | if (block->node == intf[node_count].node) |
| 374 | 536 | { |
| 375 | 537 | entry->ptr = (void *) &intf[node_count]; |
| 376 | | discrete_log(info, "discrete_build_list() - DISCRETE_REPLACE @ NODE_%02d", NODE_INDEX(intf[node_count].node) ); |
| 538 | discrete_log("discrete_build_list() - DISCRETE_REPLACE @ NODE_%02d", NODE_INDEX(intf[node_count].node) ); |
| 377 | 539 | break; |
| 378 | 540 | } |
| 379 | 541 | } |
| r10048 | r10049 | |
| 387 | 549 | linked_list_entry *entry, *last; |
| 388 | 550 | |
| 389 | 551 | last = NULL; |
| 390 | | for (entry = info->block_list; entry != NULL; last = entry, entry = entry->next) |
| 552 | for (entry = m_block_list; entry != NULL; last = entry, entry = entry->next) |
| 391 | 553 | { |
| 392 | 554 | discrete_sound_block *block = (discrete_sound_block *) entry->ptr; |
| 393 | 555 | |
| 394 | 556 | if ((block->node >= intf[node_count].input_node[0]) && |
| 395 | 557 | (block->node <= intf[node_count].input_node[1])) |
| 396 | 558 | { |
| 397 | | discrete_log(info, "discrete_build_list() - DISCRETE_DELETE deleted NODE_%02d", NODE_INDEX(block->node) ); |
| 559 | discrete_log("discrete_build_list() - DISCRETE_DELETE deleted NODE_%02d", NODE_INDEX(block->node) ); |
| 398 | 560 | if (last != NULL) |
| 399 | 561 | last->next = entry->next; |
| 400 | 562 | else |
| 401 | | info->block_list = entry->next; |
| 563 | m_block_list = entry->next; |
| 402 | 564 | } |
| 403 | 565 | } |
| 404 | 566 | } |
| 405 | 567 | else |
| 406 | 568 | { |
| 407 | | discrete_log(info, "discrete_build_list() - adding node %d (*current %p)\n", node_count, *current); |
| 408 | | linked_list_tail_add(info, current, &intf[node_count]); |
| 569 | discrete_log("discrete_build_list() - adding node %d (*current %p)\n", node_count, *current); |
| 570 | linked_list_tail_add(this, current, &intf[node_count]); |
| 409 | 571 | } |
| 410 | 572 | |
| 411 | 573 | node_count++; |
| 412 | 574 | } |
| 413 | 575 | } |
| 414 | 576 | |
| 415 | | /************************************* |
| 416 | | * |
| 417 | | * Sanity check list |
| 418 | | * |
| 419 | | *************************************/ |
| 577 | //------------------------------------------------- |
| 578 | // discrete_sanity_check: Sanity check list |
| 579 | //------------------------------------------------- |
| 420 | 580 | |
| 421 | | static void discrete_sanity_check(const discrete_info *info) |
| 581 | void discrete_device::discrete_sanity_check(void) |
| 422 | 582 | { |
| 423 | 583 | const linked_list_entry *entry; |
| 424 | 584 | int node_count = 0; |
| 425 | 585 | |
| 426 | | discrete_log(info, "discrete_start() - Doing node list sanity check"); |
| 427 | | for (entry = info->block_list; entry != NULL; entry = entry->next) |
| 586 | discrete_log("discrete_start() - Doing node list sanity check"); |
| 587 | for (entry = m_block_list; entry != NULL; entry = entry->next) |
| 428 | 588 | { |
| 429 | 589 | discrete_sound_block *block = (discrete_sound_block *) entry->ptr; |
| 430 | 590 | |
| r10048 | r10049 | |
| 446 | 606 | |
| 447 | 607 | node_count++; |
| 448 | 608 | } |
| 449 | | discrete_log(info, "discrete_start() - Sanity check counted %d nodes", node_count); |
| 609 | discrete_log("discrete_start() - Sanity check counted %d nodes", node_count); |
| 450 | 610 | |
| 451 | 611 | } |
| 452 | 612 | |
| 613 | //------------------------------------------------- |
| 614 | // discrete_sanity_check: Sanity check list |
| 615 | //------------------------------------------------- |
| 616 | |
| 453 | 617 | /************************************* |
| 454 | 618 | * |
| 455 | 619 | * Master discrete system start |
| 456 | 620 | * |
| 457 | 621 | *************************************/ |
| 458 | | #if 0 |
| 459 | | static DEVICE_START( discrete ) |
| 460 | | { |
| 461 | | linked_list_entry **intf; |
| 462 | | const discrete_sound_block *intf_start = (discrete_sound_block *)device->baseconfig().static_config(); |
| 463 | | discrete_info *info = get_safe_token(device); |
| 464 | | char name[32]; |
| 465 | 622 | |
| 466 | | info->device = device; |
| 467 | 623 | |
| 468 | | /* If a clock is specified we will use it, otherwise run at the audio sample rate. */ |
| 469 | | if (device->clock()) |
| 470 | | info->sample_rate = device->clock(); |
| 471 | | else |
| 472 | | info->sample_rate = device->machine->sample_rate; |
| 473 | | info->sample_time = 1.0 / info->sample_rate; |
| 474 | | info->neg_sample_time = - info->sample_time; |
| 475 | | |
| 476 | | info->total_samples = 0; |
| 477 | | info->total_stream_updates = 0; |
| 478 | | |
| 479 | | /* create the logfile */ |
| 480 | | sprintf(name, "discrete%s.log", device->tag()); |
| 481 | | if (DISCRETE_DEBUGLOG) |
| 482 | | info->disclogfile = fopen(name, "w"); |
| 483 | | |
| 484 | | /* enable profiling */ |
| 485 | | if (getenv("DISCRETE_PROFILING")) |
| 486 | | profiling = atoi(getenv("DISCRETE_PROFILING")); |
| 487 | | |
| 488 | | /* Build the final block list */ |
| 489 | | info->block_list = NULL; |
| 490 | | intf = &info->block_list; |
| 491 | | discrete_build_list(info, intf_start, &intf); |
| 492 | | |
| 493 | | /* first pass through the nodes: sanity check, fill in the indexed_nodes, and make a total count */ |
| 494 | | discrete_sanity_check(info); |
| 495 | | |
| 496 | | /* Start with empty lists */ |
| 497 | | info->node_list.reset(); |
| 498 | | info->output_list.reset(); |
| 499 | | info->input_list.reset(); |
| 500 | | |
| 501 | | /* allocate memory to hold pointers to nodes by index */ |
| 502 | | info->indexed_node = auto_alloc_array_clear(device->machine, node_description *, DISCRETE_MAX_NODES); |
| 503 | | |
| 504 | | /* initialize the node data */ |
| 505 | | init_nodes(info, info->block_list, device); |
| 506 | | |
| 507 | | /* now go back and find pointers to all input nodes */ |
| 508 | | for_each(node_description *, node, &info->node_list) |
| 509 | | { |
| 510 | | node.item()->find_input_nodes(); |
| 511 | | } |
| 512 | | |
| 513 | | /* initialize the stream(s) */ |
| 514 | | info->discrete_stream = stream_create(device,info->input_list.count(), info->output_list.count(), info->sample_rate, info, discrete_stream_update); |
| 515 | | |
| 516 | | /* allocate a queue */ |
| 517 | | |
| 518 | | info->queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ); |
| 519 | | |
| 520 | | /* Process nodes which have a start func */ |
| 521 | | |
| 522 | | for_each(node_description *, node, &info->node_list) |
| 523 | | { |
| 524 | | if (node.item()->module->start) |
| 525 | | (*node.item()->module->start)(node.item()); |
| 526 | | } |
| 527 | | |
| 528 | | } |
| 529 | | #endif |
| 530 | | |
| 531 | | |
| 532 | 624 | /************************************* |
| 533 | 625 | * |
| 534 | 626 | * Master discrete system stop |
| r10048 | r10049 | |
| 539 | 631 | { |
| 540 | 632 | UINT64 total = 0; |
| 541 | 633 | |
| 542 | | for_each(node_description *, node, &list) |
| 634 | for_each(discrete_base_node *, node, &list) |
| 543 | 635 | { |
| 636 | discrete_step_interface *step; |
| 637 | if (node.item()->interface(step)) |
| 638 | total += step->run_time; |
| 639 | } |
| 640 | return total; |
| 641 | } |
| 642 | |
| 643 | static UINT64 step_list_run_time(const node_step_list_t &list) |
| 644 | { |
| 645 | UINT64 total = 0; |
| 646 | |
| 647 | for_each(discrete_step_interface *, node, &list) |
| 648 | { |
| 544 | 649 | total += node.item()->run_time; |
| 545 | 650 | } |
| 546 | 651 | return total; |
| 547 | 652 | } |
| 548 | 653 | |
| 549 | | static void display_profiling(const discrete_info *info) |
| 654 | void discrete_device::display_profiling(void) |
| 550 | 655 | { |
| 551 | 656 | int count; |
| 552 | 657 | UINT64 total; |
| r10048 | r10049 | |
| 554 | 659 | double tt; |
| 555 | 660 | |
| 556 | 661 | /* calculate total time */ |
| 557 | | total = list_run_time(info->node_list); |
| 558 | | count = info->node_list.count(); |
| 662 | total = list_run_time(m_node_list); |
| 663 | count = m_node_list.count(); |
| 559 | 664 | /* print statistics */ |
| 560 | | printf("Total Samples : %16" I64FMT "d\n", info->total_samples); |
| 665 | printf("Total Samples : %16" I64FMT "d\n", m_total_samples); |
| 561 | 666 | tresh = total / count; |
| 562 | | printf("Threshold (mean): %16" I64FMT "d\n", tresh / info->total_samples ); |
| 563 | | for_each(node_description *, node, &info->node_list) |
| 667 | printf("Threshold (mean): %16" I64FMT "d\n", tresh / m_total_samples ); |
| 668 | for_each(discrete_base_node *, node, &m_node_list) |
| 564 | 669 | { |
| 565 | | if (node.item()->run_time > tresh) |
| 566 | | printf("%3d: %20s %8.2f %10.2f\n", node.item()->index(), node.item()->module->name, (float) node.item()->run_time / (float) total * 100.0, ((float) node.item()->run_time) / (float) info->total_samples); |
| 670 | discrete_step_interface *step; |
| 671 | if (node.item()->interface(step)) |
| 672 | if (step->run_time > tresh) |
| 673 | printf("%3d: %20s %8.2f %10.2f\n", node.item()->index(), node.item()->module_name(), (float) step->run_time / (float) total * 100.0, ((float) step->run_time) / (float) m_total_samples); |
| 567 | 674 | } |
| 568 | 675 | |
| 569 | 676 | /* Task information */ |
| 570 | | for_each(discrete_task *, task, &info->task_list) |
| 677 | for_each(discrete_task *, task, &task_list) |
| 571 | 678 | { |
| 572 | | tt = list_run_time(task.item()->list); |
| 679 | tt = step_list_run_time(task.item()->step_list); |
| 573 | 680 | |
| 574 | | printf("Task(%d): %8.2f %15.2f\n", task.item()->task_group, tt / (double) total * 100.0, tt / (double) info->total_samples); |
| 681 | printf("Task(%d): %8.2f %15.2f\n", task.item()->task_group, tt / (double) total * 100.0, tt / (double) m_total_samples); |
| 575 | 682 | } |
| 576 | 683 | |
| 577 | | printf("Average samples/stream_update: %8.2f\n", (double) info->total_samples / (double) info->total_stream_updates); |
| 684 | printf("Average samples/stream_update: %8.2f\n", (double) m_total_samples / (double) m_total_stream_updates); |
| 578 | 685 | } |
| 579 | 686 | |
| 580 | | #if 0 |
| 581 | | static DEVICE_STOP( discrete ) |
| 582 | | { |
| 583 | | discrete_info *info = get_safe_token(device); |
| 584 | 687 | |
| 585 | | osd_work_queue_free(info->queue); |
| 586 | 688 | |
| 587 | | if (profiling) |
| 588 | | { |
| 589 | | display_profiling(info); |
| 590 | | } |
| 591 | | |
| 592 | | /* Process nodes which have a stop func */ |
| 593 | | |
| 594 | | for_each(node_description *, node, &info->node_list) |
| 595 | | { |
| 596 | | if (node.item()->module->stop) |
| 597 | | (*node.item()->module->stop)(node.item()); |
| 598 | | } |
| 599 | | |
| 600 | | if (DISCRETE_DEBUGLOG) |
| 601 | | { |
| 602 | | /* close the debug log */ |
| 603 | | if (info->disclogfile) |
| 604 | | fclose(info->disclogfile); |
| 605 | | info->disclogfile = NULL; |
| 606 | | } |
| 607 | | } |
| 608 | | #endif |
| 609 | | |
| 610 | | |
| 611 | 689 | /************************************* |
| 612 | 690 | * |
| 613 | 691 | * Master reset of all nodes |
| 614 | 692 | * |
| 615 | 693 | *************************************/ |
| 616 | | #if 0 |
| 617 | | static DEVICE_RESET( discrete ) |
| 618 | | { |
| 619 | | const discrete_info *info = get_safe_token(device); |
| 620 | 694 | |
| 621 | | /* loop over all nodes */ |
| 622 | | for_each (node_description *, node, &info->node_list) |
| 623 | | { |
| 624 | | node.item()->output[0] = 0; |
| 625 | | |
| 626 | | /* if the node has a reset function, call it */ |
| 627 | | if (node.item()->module->reset) |
| 628 | | (*node.item()->module->reset)(node.item()); |
| 629 | | |
| 630 | | /* otherwise, just step it */ |
| 631 | | else if (node.item()->step) |
| 632 | | (*node.item()->step)(node.item()); |
| 633 | | } |
| 634 | | } |
| 635 | | #endif |
| 636 | | |
| 637 | 695 | /************************************* |
| 638 | 696 | * |
| 639 | 697 | * Stream update functions |
| 640 | 698 | * |
| 641 | 699 | *************************************/ |
| 642 | 700 | |
| 643 | | static void *task_callback(void *param, int threadid) |
| 644 | | { |
| 645 | | task_list_t *list = (task_list_t *) param; |
| 646 | | int samples; |
| 647 | 701 | |
| 648 | | do |
| 649 | | { |
| 650 | | for_each(discrete_task *, task, list) |
| 651 | | { |
| 652 | | /* try to lock */ |
| 653 | | if (task.item()->lock_threadid(threadid)) |
| 654 | | { |
| 655 | | samples = MIN(task.item()->samples, MAX_SAMPLES_PER_TASK_SLICE); |
| 656 | 702 | |
| 657 | | /* check dependencies */ |
| 658 | | for_each(discrete_source_node *, sn, &task.item()->source_list) |
| 659 | | { |
| 660 | | int avail; |
| 661 | 703 | |
| 662 | | avail = sn.item()->task->ptr[sn.item()->output_node] - sn.item()->ptr; |
| 663 | | assert_always(avail >= 0, "task_callback: available samples are negative"); |
| 664 | | if (avail < samples) |
| 665 | | samples = avail; |
| 666 | | } |
| 667 | 704 | |
| 668 | | task.item()->samples -= samples; |
| 669 | | assert_always(task.item()->samples >=0, "task_callback: task_samples got negative"); |
| 670 | | while (samples > 0) |
| 671 | | { |
| 672 | | /* step */ |
| 673 | | step_nodes_in_list(task.item()->list); |
| 674 | | samples--; |
| 675 | | } |
| 676 | | if (task.item()->samples == 0) |
| 677 | | { |
| 678 | | /* return and keep the task locked so it is not picked up by other worker threads */ |
| 679 | | return NULL; |
| 680 | | } |
| 681 | | task.item()->unlock(); |
| 682 | | } |
| 683 | | } |
| 684 | | } while (1); |
| 685 | | |
| 686 | | return NULL; |
| 687 | | } |
| 688 | | |
| 689 | | |
| 690 | | static STREAM_UPDATE( buffer_stream_update ) |
| 691 | | { |
| 692 | | const node_description *node = (node_description *) param; |
| 693 | | const struct dss_input_context *context = (struct dss_input_context *)node->context; |
| 694 | | stream_sample_t *ptr = outputs[0]; |
| 695 | | int data = context->data; |
| 696 | | int samplenum = samples; |
| 697 | | |
| 698 | | while (samplenum-- > 0) |
| 699 | | *(ptr++) = data; |
| 700 | | } |
| 701 | | |
| 702 | | #if 0 |
| 703 | | static STREAM_UPDATE( discrete_stream_update ) |
| 704 | | { |
| 705 | | discrete_info *info = (discrete_info *)param; |
| 706 | | int outputnum; |
| 707 | | //, task_group; |
| 708 | | |
| 709 | | if (samples == 0) |
| 710 | | return; |
| 711 | | |
| 712 | | /* Setup any output streams */ |
| 713 | | outputnum = 0; |
| 714 | | for_each(node_description *, node, &info->output_list) |
| 715 | | { |
| 716 | | node.item()->context = (void *) outputs[outputnum]; |
| 717 | | outputnum++; |
| 718 | | } |
| 719 | | |
| 720 | | /* Setup any input streams */ |
| 721 | | for_each(node_description *, node, &info->input_list) |
| 722 | | { |
| 723 | | struct dss_input_context *context = (struct dss_input_context *) node.item()->context; |
| 724 | | context->ptr = (stream_sample_t *) inputs[context->stream_in_number]; |
| 725 | | } |
| 726 | | |
| 727 | | /* Setup tasks */ |
| 728 | | for_each(discrete_task *, task, &info->task_list) |
| 729 | | { |
| 730 | | int i; |
| 731 | | |
| 732 | | task.item()->samples = samples; |
| 733 | | /* unlock the thread */ |
| 734 | | task.item()->unlock(); |
| 735 | | |
| 736 | | /* set up task buffers */ |
| 737 | | for (i = 0; i < task.item()->numbuffered; i++) |
| 738 | | task.item()->ptr[i] = task.item()->node_buf[i]; |
| 739 | | |
| 740 | | /* initialize sources */ |
| 741 | | for_each(discrete_source_node *, sn, &task.item()->source_list) |
| 742 | | { |
| 743 | | sn.item()->ptr = sn.item()->task->node_buf[sn.item()->output_node]; |
| 744 | | } |
| 745 | | } |
| 746 | | |
| 747 | | for_each(discrete_task *, task, &info->task_list) |
| 748 | | { |
| 749 | | /* Fire a work item for each task */ |
| 750 | | osd_work_item_queue(info->queue, task_callback, (void *) &info->task_list, WORK_ITEM_FLAG_AUTO_RELEASE); |
| 751 | | } |
| 752 | | osd_work_queue_wait(info->queue, osd_ticks_per_second()*10); |
| 753 | | |
| 754 | | if (profiling) |
| 755 | | { |
| 756 | | info->total_samples += samples; |
| 757 | | info->total_stream_updates++; |
| 758 | | } |
| 759 | | |
| 760 | | } |
| 761 | | #endif |
| 762 | | |
| 763 | | |
| 764 | 705 | /************************************* |
| 765 | 706 | * |
| 766 | 707 | * First pass init of nodes |
| r10048 | r10049 | |
| 768 | 709 | *************************************/ |
| 769 | 710 | |
| 770 | 711 | |
| 771 | | static void init_nodes(discrete_info *info, const linked_list_entry *block_list, device_t *device) |
| 712 | void discrete_device::init_nodes(const linked_list_entry *block_list) |
| 772 | 713 | { |
| 773 | 714 | const linked_list_entry *entry; |
| 774 | 715 | discrete_task *task = NULL; |
| r10048 | r10049 | |
| 788 | 729 | /* make sure we have one simple task |
| 789 | 730 | * No need to create a node since there are no dependencies. |
| 790 | 731 | */ |
| 791 | | task = auto_alloc_clear(info->device->machine, discrete_task); |
| 792 | | info->task_list.add_tail(task); |
| 732 | task = auto_alloc_clear(machine, discrete_task(this)); |
| 733 | task_list.add_tail(task); |
| 793 | 734 | } |
| 794 | 735 | |
| 795 | 736 | /* loop over all nodes */ |
| 796 | 737 | for (entry = block_list; entry != NULL; entry = entry->next) |
| 797 | 738 | { |
| 798 | 739 | const discrete_sound_block *block = (discrete_sound_block *) entry->ptr; |
| 799 | | int modulenum; |
| 740 | //int modulenum; |
| 800 | 741 | |
| 801 | | /* find the requested module */ |
| 802 | | for (modulenum = 0; module_list[modulenum].type != DSS_NULL; modulenum++) |
| 803 | | if (module_list[modulenum].type == block->type) |
| 804 | | break; |
| 805 | | if (module_list[modulenum].type != block->type) |
| 806 | | fatalerror("init_nodes() - Unable to find discrete module type %d for NODE_%02d", block->type, NODE_INDEX(block->node)); |
| 807 | | |
| 808 | | node_description *node = auto_alloc_clear(info->device->machine, node_description(info, &module_list[modulenum], block)); |
| 809 | | |
| 742 | discrete_base_node *node = block->factory->Create(this, block); |
| 810 | 743 | /* keep track of special nodes */ |
| 811 | 744 | if (block->node == NODE_SPECIAL) |
| 812 | 745 | { |
| r10048 | r10049 | |
| 814 | 747 | { |
| 815 | 748 | /* Output Node */ |
| 816 | 749 | case DSO_OUTPUT: |
| 817 | | info->output_list.add_tail(node); |
| 750 | /* nothing -> handled later */ |
| 818 | 751 | break; |
| 819 | 752 | |
| 820 | 753 | /* CSVlog Node for debugging */ |
| r10048 | r10049 | |
| 829 | 762 | case DSO_TASK_START: |
| 830 | 763 | if (task != NULL) |
| 831 | 764 | fatalerror("init_nodes() - Nested DISCRETE_START_TASK."); |
| 832 | | task = auto_alloc_clear(info->device->machine, discrete_task); |
| 833 | | node->context = task; |
| 765 | task = auto_alloc_clear(machine, discrete_task(this)); |
| 766 | task->task_group = block->initial[0]; |
| 767 | if (task->task_group < 0 || task->task_group >= DISCRETE_MAX_TASK_GROUPS) |
| 768 | fatalerror("discrete_dso_task: illegal task_group %d", task->task_group); |
| 769 | //printf("task group %d\n", task->task_group); |
| 770 | task_list.add_tail(task); |
| 834 | 771 | break; |
| 835 | 772 | |
| 836 | 773 | case DSO_TASK_END: |
| 837 | 774 | if (task == NULL) |
| 838 | 775 | fatalerror("init_nodes() - NO DISCRETE_START_TASK."); |
| 839 | | task->numbuffered = 0; |
| 840 | | task->task_group = -1; /* will be set later */ |
| 841 | | task->source_list.reset(); |
| 842 | | info->task_list.add_tail(task); |
| 843 | | node->context = task; |
| 844 | | //task = NULL; |
| 845 | 776 | break; |
| 846 | 777 | |
| 847 | 778 | default: |
| r10048 | r10049 | |
| 852 | 783 | /* otherwise, make sure we are not a duplicate, and put ourselves into the indexed list */ |
| 853 | 784 | else |
| 854 | 785 | { |
| 855 | | if (info->indexed_node[NODE_INDEX(block->node)]) |
| 786 | if (m_indexed_node[NODE_INDEX(block->node)]) |
| 856 | 787 | fatalerror("init_nodes() - Duplicate entries for NODE_%02d", NODE_INDEX(block->node)); |
| 857 | | info->indexed_node[NODE_INDEX(block->node)] = node; |
| 788 | m_indexed_node[NODE_INDEX(block->node)] = node; |
| 858 | 789 | } |
| 859 | 790 | |
| 860 | 791 | /* if we are an stream input node, track that */ |
| 861 | | if (block->type == DSS_INPUT_STREAM) |
| 792 | discrete_dss_input_stream_node *input_stream = dynamic_cast<discrete_dss_input_stream_node *>(node); |
| 793 | if (input_stream != NULL) |
| 862 | 794 | { |
| 863 | | info->input_list.add_tail(node); |
| 795 | m_input_stream_list.add_tail(input_stream); |
| 864 | 796 | } |
| 865 | | else if (block->type == DSS_INPUT_BUFFER) |
| 866 | | { |
| 867 | | info->input_list.add_tail(node); |
| 868 | | } |
| 869 | 797 | |
| 870 | 798 | /* add to node list */ |
| 871 | | info->node_list.add_tail(node); |
| 799 | m_node_list.add_tail(node); |
| 872 | 800 | |
| 873 | 801 | /* our running order just follows the order specified */ |
| 874 | 802 | /* does the node step ? */ |
| 875 | | if (node->step != NULL) |
| 803 | discrete_step_interface *step; |
| 804 | if (node->interface(step)) |
| 876 | 805 | { |
| 877 | 806 | /* do we belong to a task? */ |
| 878 | 807 | if (task == NULL) |
| 879 | | fatalerror("init_nodes() - found node outside of task."); |
| 808 | fatalerror("init_nodes() - found node outside of task: %s", node->module_name() ); |
| 880 | 809 | else |
| 881 | | task->list.add_tail(node); |
| 810 | task->step_list.add_tail(step); |
| 882 | 811 | } |
| 883 | 812 | |
| 813 | /* if this is an output interface, add it the output list */ |
| 814 | discrete_output_interface *out; |
| 815 | if (node->interface(out)) |
| 816 | m_output_list.add_tail(out); |
| 817 | |
| 818 | |
| 884 | 819 | if (block->type == DSO_TASK_END) |
| 885 | 820 | { |
| 886 | 821 | task = NULL; |
| 887 | 822 | } |
| 888 | 823 | |
| 889 | 824 | /* and register save state */ |
| 890 | | node->save_state(device); |
| 825 | node->save_state(this); |
| 891 | 826 | } |
| 892 | 827 | |
| 893 | 828 | if (!has_tasks) |
| r10048 | r10049 | |
| 895 | 830 | } |
| 896 | 831 | |
| 897 | 832 | /* if no outputs, give an error */ |
| 898 | | if (info->output_list.count() == 0) |
| 833 | if (m_output_list.count() == 0) |
| 899 | 834 | fatalerror("init_nodes() - Couldn't find an output node"); |
| 900 | 835 | } |
| 901 | 836 | |
| r10048 | r10049 | |
| 906 | 841 | * |
| 907 | 842 | *************************************/ |
| 908 | 843 | |
| 909 | | node_description::node_description(const discrete_info * xinfo, const discrete_module *xmodule, const discrete_sound_block *xblock) : |
| 910 | | context(NULL), |
| 911 | | module(xmodule), |
| 912 | | info(xinfo), |
| 913 | | run_time(0), |
| 914 | | m_block(xblock) |
| 915 | | { |
| 916 | | output[0] = 0.0; |
| 917 | | m_custom = m_block->custom; |
| 918 | | m_active_inputs = m_block->active_inputs; |
| 919 | 844 | |
| 920 | | /* setup module if custom */ |
| 921 | | if (m_block->type == DST_CUSTOM) |
| 922 | | { |
| 923 | | const discrete_custom_info *custom = (const discrete_custom_info *)m_custom; |
| 924 | | module = &custom->module; |
| 925 | | m_custom = custom->custom; |
| 926 | | } |
| 927 | | |
| 928 | | /* copy initial / default step function */ |
| 929 | | step = module->step; |
| 930 | | |
| 931 | | /* allocate memory if necessary */ |
| 932 | | if (module->contextsize) |
| 933 | | context = global_alloc_array(UINT8, module->contextsize); |
| 934 | | } |
| 935 | | |
| 936 | | node_description::~node_description(void) |
| 845 | int discrete_device::same_module_index(discrete_base_node &node) |
| 937 | 846 | { |
| 938 | | if (module->contextsize) |
| 939 | | global_free(context); |
| 940 | | } |
| 941 | | |
| 942 | | int node_description::index(void) |
| 943 | | { |
| 944 | | return NODE_INDEX(m_block->node); |
| 945 | | } |
| 946 | | |
| 947 | | void node_description::save_state(device_t *device) |
| 948 | | { |
| 949 | | if (m_block->node != NODE_SPECIAL) |
| 950 | | state_save_register_device_item_array(device, m_block->node, output); |
| 951 | | } |
| 952 | | |
| 953 | | void node_description::find_input_nodes(void) |
| 954 | | { |
| 955 | | int inputnum; |
| 956 | | |
| 957 | | /* loop over all active inputs */ |
| 958 | | for (inputnum = 0; inputnum < m_active_inputs; inputnum++) |
| 959 | | { |
| 960 | | int inputnode = m_block->input_node[inputnum]; |
| 961 | | |
| 962 | | /* if this input is node-based, find the node in the indexed list */ |
| 963 | | if IS_VALUE_A_NODE(inputnode) |
| 964 | | { |
| 965 | | const node_description *node_ref = info->indexed_node[NODE_INDEX(inputnode)]; |
| 966 | | if (!node_ref) |
| 967 | | fatalerror("discrete_start - NODE_%02d referenced a non existent node NODE_%02d", index(), NODE_INDEX(inputnode)); |
| 968 | | |
| 969 | | if ((NODE_CHILD_NODE_NUM(inputnode) >= node_ref->module->num_output) && (node_ref->module->type != DST_CUSTOM)) |
| 970 | | fatalerror("discrete_start - NODE_%02d referenced non existent output %d on node NODE_%02d", index(), NODE_CHILD_NODE_NUM(inputnode), NODE_INDEX(inputnode)); |
| 971 | | |
| 972 | | input[inputnum] = &(node_ref->output[NODE_CHILD_NODE_NUM(inputnode)]); /* Link referenced node out to input */ |
| 973 | | m_input_is_node |= 1 << inputnum; /* Bit flag if input is node */ |
| 974 | | } |
| 975 | | else |
| 976 | | { |
| 977 | | /* warn if trying to use a node for an input that can only be static */ |
| 978 | | if IS_VALUE_A_NODE(m_block->initial[inputnum]) |
| 979 | | { |
| 980 | | discrete_log(info, "Warning - discrete_start - NODE_%02d trying to use a node on static input %d", index(), inputnum); |
| 981 | | /* also report it in the error log so it is not missed */ |
| 982 | | logerror("Warning - discrete_start - NODE_%02d trying to use a node on static input %d", index(), inputnum); |
| 983 | | } |
| 984 | | else |
| 985 | | { |
| 986 | | input[inputnum] = &(m_block->initial[inputnum]); |
| 987 | | //node->input[inputnum] = getDoublePtr(node->block->initial[inputnum]); |
| 988 | | } |
| 989 | | } |
| 990 | | } |
| 991 | | for (inputnum = m_active_inputs; inputnum < DISCRETE_MAX_INPUTS; inputnum++) |
| 992 | | { |
| 993 | | /* FIXME: Check that no nodes follow ! */ |
| 994 | | input[inputnum] = &(m_block->initial[inputnum]); |
| 995 | | } |
| 996 | | } |
| 997 | | |
| 998 | | int node_description::same_module_index(const node_list_t &list) |
| 999 | | { |
| 1000 | 847 | int index = 0; |
| 1001 | 848 | |
| 1002 | | for_each(node_description *, n, &list) |
| 849 | for_each(discrete_base_node *, n, &m_node_list) |
| 1003 | 850 | { |
| 1004 | | if (n.item() == this) |
| 851 | if (n.item() == &node) |
| 1005 | 852 | return index; |
| 1006 | | if (n.item()->module->type == this->module->type) |
| 853 | if (n.item()->module_type() == node.module_type()) |
| 1007 | 854 | index++; |
| 1008 | 855 | } |
| 1009 | 856 | return -1; |
| 1010 | 857 | } |
| 1011 | 858 | |
| 1012 | | #if 0 |
| 1013 | | /************************************************************************** |
| 1014 | | * Generic get_info |
| 1015 | | **************************************************************************/ |
| 1016 | 859 | |
| 1017 | | DEVICE_GET_INFO( discrete ) |
| 1018 | | { |
| 1019 | | switch (state) |
| 1020 | | { |
| 1021 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1022 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(discrete_info); break; |
| 1023 | | |
| 1024 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1025 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( discrete ); break; |
| 1026 | | case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME( discrete ); break; |
| 1027 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( discrete ); break; |
| 1028 | | |
| 1029 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1030 | | case DEVINFO_STR_NAME: strcpy(info->s, "Discrete"); break; |
| 1031 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Analog"); break; |
| 1032 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.1"); break; |
| 1033 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1034 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; |
| 1035 | | } |
| 1036 | | } |
| 1037 | | |
| 1038 | | |
| 1039 | | DEFINE_LEGACY_SOUND_DEVICE(DISCRETE, discrete); |
| 1040 | | #endif |
| 1041 | | |
| 1042 | 860 | //************************************************************************** |
| 1043 | 861 | // GLOBAL VARIABLES |
| 1044 | 862 | //************************************************************************** |
| r10048 | r10049 | |
| 1049 | 867 | // DEVICE CONFIGURATION |
| 1050 | 868 | //************************************************************************** |
| 1051 | 869 | |
| 1052 | | #if 0 |
| 1053 | 870 | //------------------------------------------------- |
| 1054 | | // static_set_type - configuration helper to set |
| 1055 | | // the chip type |
| 871 | // static_set_intf - configuration helper to set |
| 872 | // the interface |
| 1056 | 873 | //------------------------------------------------- |
| 1057 | 874 | |
| 1058 | | void discrete_device_config::static_set_type(device_config *device, int type) |
| 875 | void discrete_device_config::static_set_intf(device_config *device, const discrete_sound_block *intf) |
| 1059 | 876 | { |
| 1060 | | discrete_device_config *asc = downcast<discrete_device_config *>(device); |
| 1061 | | asc->m_type = type; |
| 877 | discrete_device_config *disc = downcast<discrete_device_config *>(device); |
| 878 | disc->m_intf = intf; |
| 1062 | 879 | } |
| 1063 | 880 | |
| 1064 | 881 | //------------------------------------------------- |
| 1065 | | // static_set_type - configuration helper to set |
| 1066 | | // the IRQ callback |
| 1067 | | //------------------------------------------------- |
| 1068 | | |
| 1069 | | |
| 1070 | | void discrete_device_config::static_set_irqf(device_config *device, void (*irqf)(device_t *device, int state)) |
| 1071 | | { |
| 1072 | | discrete_device_config *asc = downcast<discrete_device_config *>(device); |
| 1073 | | asc->m_irq_func = irqf; |
| 1074 | | } |
| 1075 | | #endif |
| 1076 | | |
| 1077 | | //------------------------------------------------- |
| 1078 | 882 | // discrete_device_config - constructor |
| 1079 | 883 | //------------------------------------------------- |
| 1080 | 884 | |
| 1081 | 885 | discrete_device_config::discrete_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 1082 | 886 | : device_config(mconfig, static_alloc_device_config, "DISCRETE", tag, owner, clock), |
| 1083 | | device_config_sound_interface(mconfig, *this) |
| 887 | device_config_sound_interface(mconfig, *this), m_intf(NULL) |
| 1084 | 888 | { |
| 1085 | 889 | } |
| 1086 | 890 | |
| r10048 | r10049 | |
| 1121 | 925 | |
| 1122 | 926 | discrete_device::~discrete_device(void) |
| 1123 | 927 | { |
| 1124 | | discrete_info *info = &m_info; |
| 928 | osd_work_queue_free(m_queue); |
| 1125 | 929 | |
| 1126 | | osd_work_queue_free(info->queue); |
| 1127 | | |
| 1128 | | if (profiling) |
| 930 | if (m_profiling) |
| 1129 | 931 | { |
| 1130 | | display_profiling(info); |
| 932 | display_profiling(); |
| 1131 | 933 | } |
| 1132 | 934 | |
| 1133 | 935 | /* Process nodes which have a stop func */ |
| 1134 | 936 | |
| 1135 | | for_each(node_description *, node, &info->node_list) |
| 937 | for_each(discrete_base_node *, node, &m_node_list) |
| 1136 | 938 | { |
| 1137 | | if (node.item()->module->stop) |
| 1138 | | (*node.item()->module->stop)(node.item()); |
| 939 | node.item()->stop(); |
| 1139 | 940 | } |
| 1140 | 941 | |
| 1141 | 942 | if (DISCRETE_DEBUGLOG) |
| 1142 | 943 | { |
| 1143 | 944 | /* close the debug log */ |
| 1144 | | if (info->disclogfile) |
| 1145 | | fclose(info->disclogfile); |
| 1146 | | info->disclogfile = NULL; |
| 945 | if (m_disclogfile) |
| 946 | fclose(m_disclogfile); |
| 947 | m_disclogfile = NULL; |
| 1147 | 948 | } |
| 1148 | 949 | } |
| 1149 | 950 | |
| r10048 | r10049 | |
| 1157 | 958 | //m_stream = stream_create(this, 0, 2, 22257, this, static_stream_generate); |
| 1158 | 959 | |
| 1159 | 960 | linked_list_entry **intf; |
| 1160 | | const discrete_sound_block *intf_start = (discrete_sound_block *) baseconfig().static_config(); |
| 1161 | | discrete_info *info = &m_info; |
| 961 | const discrete_sound_block *intf_start = (m_config.m_intf != NULL) ? m_config.m_intf : (discrete_sound_block *) baseconfig().static_config(); |
| 1162 | 962 | char name[32]; |
| 1163 | 963 | |
| 1164 | | info->device = this; |
| 1165 | | |
| 1166 | 964 | /* If a clock is specified we will use it, otherwise run at the audio sample rate. */ |
| 1167 | 965 | if (this->clock()) |
| 1168 | | info->sample_rate = this->clock(); |
| 966 | m_sample_rate = this->clock(); |
| 1169 | 967 | else |
| 1170 | | info->sample_rate = this->machine->sample_rate; |
| 1171 | | info->sample_time = 1.0 / info->sample_rate; |
| 1172 | | info->neg_sample_time = - info->sample_time; |
| 968 | m_sample_rate = this->machine->sample_rate; |
| 969 | m_sample_time = 1.0 / m_sample_rate; |
| 970 | m_neg_sample_time = - m_sample_time; |
| 1173 | 971 | |
| 1174 | | info->total_samples = 0; |
| 1175 | | info->total_stream_updates = 0; |
| 972 | m_total_samples = 0; |
| 973 | m_total_stream_updates = 0; |
| 1176 | 974 | |
| 1177 | 975 | /* create the logfile */ |
| 1178 | 976 | sprintf(name, "discrete%s.log", this->tag()); |
| 1179 | 977 | if (DISCRETE_DEBUGLOG) |
| 1180 | | info->disclogfile = fopen(name, "w"); |
| 978 | m_disclogfile = fopen(name, "w"); |
| 1181 | 979 | |
| 1182 | 980 | /* enable profiling */ |
| 981 | m_profiling = 0; |
| 1183 | 982 | if (getenv("DISCRETE_PROFILING")) |
| 1184 | | profiling = atoi(getenv("DISCRETE_PROFILING")); |
| 983 | m_profiling = atoi(getenv("DISCRETE_PROFILING")); |
| 1185 | 984 | |
| 1186 | 985 | /* Build the final block list */ |
| 1187 | | info->block_list = NULL; |
| 1188 | | intf = &info->block_list; |
| 1189 | | discrete_build_list(info, intf_start, &intf); |
| 986 | m_block_list = NULL; |
| 987 | intf = &m_block_list; |
| 988 | discrete_build_list(intf_start, &intf); |
| 1190 | 989 | |
| 1191 | 990 | /* first pass through the nodes: sanity check, fill in the indexed_nodes, and make a total count */ |
| 1192 | | discrete_sanity_check(info); |
| 991 | discrete_sanity_check(); |
| 1193 | 992 | |
| 1194 | 993 | /* Start with empty lists */ |
| 1195 | | info->node_list.reset(); |
| 1196 | | info->output_list.reset(); |
| 1197 | | info->input_list.reset(); |
| 994 | m_node_list.reset(); |
| 995 | m_output_list.reset(); |
| 996 | m_input_stream_list.reset(); |
| 1198 | 997 | |
| 1199 | 998 | /* allocate memory to hold pointers to nodes by index */ |
| 1200 | | info->indexed_node = auto_alloc_array_clear(this->machine, node_description *, DISCRETE_MAX_NODES); |
| 999 | m_indexed_node = auto_alloc_array_clear(this->machine, discrete_base_node *, DISCRETE_MAX_NODES); |
| 1201 | 1000 | |
| 1202 | 1001 | /* initialize the node data */ |
| 1203 | | init_nodes(info, info->block_list, this); |
| 1002 | init_nodes(m_block_list); |
| 1204 | 1003 | |
| 1205 | 1004 | /* now go back and find pointers to all input nodes */ |
| 1206 | | for_each(node_description *, node, &info->node_list) |
| 1005 | for_each(discrete_base_node *, node, &m_node_list) |
| 1207 | 1006 | { |
| 1208 | 1007 | node.item()->find_input_nodes(); |
| 1209 | 1008 | } |
| 1210 | 1009 | |
| 1211 | 1010 | /* initialize the stream(s) */ |
| 1212 | | info->discrete_stream = stream_create(this,info->input_list.count(), info->output_list.count(), info->sample_rate, this, static_stream_generate); |
| 1011 | m_stream = stream_create(this,m_input_stream_list.count(), m_output_list.count(), m_sample_rate, this, static_stream_generate); |
| 1213 | 1012 | |
| 1214 | 1013 | /* allocate a queue */ |
| 1215 | 1014 | |
| 1216 | | info->queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ); |
| 1015 | m_queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ); |
| 1217 | 1016 | |
| 1218 | 1017 | /* Process nodes which have a start func */ |
| 1219 | 1018 | |
| 1220 | | for_each(node_description *, node, &info->node_list) |
| 1019 | for_each(discrete_base_node *, node, &m_node_list) |
| 1221 | 1020 | { |
| 1222 | | if (node.item()->module->start) |
| 1223 | | (*node.item()->module->start)(node.item()); |
| 1021 | node.item()->start(); |
| 1224 | 1022 | } |
| 1023 | |
| 1024 | /* Now set up tasks */ |
| 1025 | |
| 1026 | for_each(discrete_task *, task, &task_list) |
| 1027 | { |
| 1028 | for_each(discrete_task *, dest_task, &task_list) |
| 1029 | { |
| 1030 | if (task.item()->task_group > dest_task.item()->task_group) |
| 1031 | dest_task.item()->check(task.item()); |
| 1032 | } |
| 1033 | } |
| 1225 | 1034 | } |
| 1226 | 1035 | |
| 1227 | 1036 | |
| r10048 | r10049 | |
| 1232 | 1041 | void discrete_device::device_reset() |
| 1233 | 1042 | { |
| 1234 | 1043 | |
| 1235 | | const discrete_info *info = &m_info; |
| 1236 | | stream_update(info->discrete_stream); |
| 1044 | update(); |
| 1237 | 1045 | |
| 1238 | 1046 | /* loop over all nodes */ |
| 1239 | | for_each (node_description *, node, &info->node_list) |
| 1047 | for_each (discrete_base_node *, node, &m_node_list) |
| 1240 | 1048 | { |
| 1241 | 1049 | node.item()->output[0] = 0; |
| 1242 | 1050 | |
| 1243 | | /* if the node has a reset function, call it */ |
| 1244 | | if (node.item()->module->reset) |
| 1245 | | (*node.item()->module->reset)(node.item()); |
| 1246 | | |
| 1247 | | /* otherwise, just step it */ |
| 1248 | | else if (node.item()->step) |
| 1249 | | (*node.item()->step)(node.item()); |
| 1051 | node.item()->reset(); |
| 1250 | 1052 | } |
| 1251 | 1053 | } |
| 1252 | 1054 | |
| r10048 | r10049 | |
| 1262 | 1064 | |
| 1263 | 1065 | void discrete_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 1264 | 1066 | { |
| 1265 | | discrete_info *info = &m_info; |
| 1266 | 1067 | int outputnum; |
| 1267 | 1068 | //, task_group; |
| 1268 | 1069 | |
| r10048 | r10049 | |
| 1270 | 1071 | return; |
| 1271 | 1072 | /* Setup any output streams */ |
| 1272 | 1073 | outputnum = 0; |
| 1273 | | for_each(node_description *, node, &info->output_list) |
| 1074 | for_each(discrete_output_interface *, node, &m_output_list) |
| 1274 | 1075 | { |
| 1275 | | node.item()->context = (void *) outputs[outputnum]; |
| 1076 | node.item()->set_output(outputs[outputnum]); |
| 1276 | 1077 | outputnum++; |
| 1277 | 1078 | } |
| 1278 | 1079 | |
| 1279 | 1080 | /* Setup any input streams */ |
| 1280 | | for_each(node_description *, node, &info->input_list) |
| 1081 | for_each(discrete_dss_input_stream_node *, node, &m_input_stream_list) |
| 1281 | 1082 | { |
| 1282 | | struct dss_input_context *context = (struct dss_input_context *) node.item()->context; |
| 1283 | | context->ptr = (stream_sample_t *) inputs[context->stream_in_number]; |
| 1083 | node.item()->m_ptr = (stream_sample_t *) inputs[node.item()->m_stream_in_number]; |
| 1284 | 1084 | } |
| 1285 | 1085 | |
| 1286 | 1086 | /* Setup tasks */ |
| 1287 | | for_each(discrete_task *, task, &info->task_list) |
| 1087 | for_each(discrete_task *, task, &task_list) |
| 1288 | 1088 | { |
| 1289 | | int i; |
| 1290 | | |
| 1291 | | task.item()->samples = samples; |
| 1292 | 1089 | /* unlock the thread */ |
| 1293 | 1090 | task.item()->unlock(); |
| 1294 | 1091 | |
| 1295 | | /* set up task buffers */ |
| 1296 | | for (i = 0; i < task.item()->numbuffered; i++) |
| 1297 | | task.item()->ptr[i] = task.item()->node_buf[i]; |
| 1298 | | |
| 1299 | | /* initialize sources */ |
| 1300 | | for_each(discrete_source_node *, sn, &task.item()->source_list) |
| 1301 | | { |
| 1302 | | sn.item()->ptr = sn.item()->task->node_buf[sn.item()->output_node]; |
| 1303 | | } |
| 1092 | task.item()->prepare_for_queue(samples); |
| 1304 | 1093 | } |
| 1305 | 1094 | |
| 1306 | | for_each(discrete_task *, task, &info->task_list) |
| 1095 | for_each(discrete_task *, task, &task_list) |
| 1307 | 1096 | { |
| 1308 | 1097 | /* Fire a work item for each task */ |
| 1309 | | osd_work_item_queue(info->queue, task_callback, (void *) &info->task_list, WORK_ITEM_FLAG_AUTO_RELEASE); |
| 1098 | osd_work_item_queue(m_queue, discrete_task::task_callback, (void *) &task_list, WORK_ITEM_FLAG_AUTO_RELEASE); |
| 1310 | 1099 | } |
| 1311 | | osd_work_queue_wait(info->queue, osd_ticks_per_second()*10); |
| 1100 | osd_work_queue_wait(m_queue, osd_ticks_per_second()*10); |
| 1312 | 1101 | |
| 1313 | | if (profiling) |
| 1102 | if (m_profiling) |
| 1314 | 1103 | { |
| 1315 | | info->total_samples += samples; |
| 1316 | | info->total_stream_updates++; |
| 1104 | m_total_samples += samples; |
| 1105 | m_total_stream_updates++; |
| 1317 | 1106 | } |
| 1318 | 1107 | } |
| 1319 | 1108 | |
| r10048 | r10049 | |
| 1323 | 1112 | |
| 1324 | 1113 | READ8_MEMBER( discrete_device::read ) |
| 1325 | 1114 | { |
| 1326 | | discrete_info *info = &m_info; |
| 1327 | | node_description *node = discrete_find_node(info, offset); |
| 1115 | discrete_base_node *node = discrete_find_node(offset); |
| 1328 | 1116 | |
| 1329 | 1117 | UINT8 data = 0; |
| 1330 | 1118 | |
| r10048 | r10049 | |
| 1332 | 1120 | if (node) |
| 1333 | 1121 | { |
| 1334 | 1122 | /* Bring the system up to now */ |
| 1335 | | stream_update(info->discrete_stream); |
| 1123 | stream_update(m_stream); |
| 1336 | 1124 | |
| 1337 | 1125 | data = (UINT8) node->output[NODE_CHILD_NODE_NUM(offset)]; |
| 1338 | 1126 | } |
| r10048 | r10049 | |
| 1348 | 1136 | |
| 1349 | 1137 | WRITE8_MEMBER( discrete_device::write ) |
| 1350 | 1138 | { |
| 1351 | | discrete_info *info = &m_info; |
| 1352 | | node_description *node = discrete_find_node(info, offset); |
| 1139 | discrete_base_node *node = discrete_find_node(offset); |
| 1353 | 1140 | |
| 1354 | 1141 | /* Update the node input value if it's a proper input node */ |
| 1355 | 1142 | if (node) |
| 1356 | 1143 | { |
| 1357 | | struct dss_input_context *context = (struct dss_input_context *)node->context; |
| 1358 | | UINT8 new_data = 0; |
| 1359 | | |
| 1360 | | switch (node->module->type) |
| 1361 | | { |
| 1362 | | case DSS_INPUT_DATA: |
| 1363 | | case DSS_INPUT_BUFFER: |
| 1364 | | new_data = data; |
| 1365 | | break; |
| 1366 | | case DSS_INPUT_LOGIC: |
| 1367 | | case DSS_INPUT_PULSE: |
| 1368 | | new_data = data ? 1 : 0; |
| 1369 | | break; |
| 1370 | | case DSS_INPUT_NOT: |
| 1371 | | new_data = data ? 0 : 1; |
| 1372 | | break; |
| 1373 | | } |
| 1374 | | |
| 1375 | | if (context->data != new_data) |
| 1376 | | { |
| 1377 | | if (context->is_buffered) |
| 1378 | | { |
| 1379 | | /* Bring the system up to now */ |
| 1380 | | stream_update(context->buffer_stream); |
| 1381 | | |
| 1382 | | context->data = new_data; |
| 1383 | | } |
| 1384 | | else |
| 1385 | | { |
| 1386 | | /* Bring the system up to now */ |
| 1387 | | stream_update(info->discrete_stream); |
| 1388 | | |
| 1389 | | context->data = new_data; |
| 1390 | | |
| 1391 | | /* Update the node output here so we don't have to do it each step */ |
| 1392 | | node->output[0] = new_data * context->gain + context->offset; |
| 1393 | | } |
| 1394 | | } |
| 1144 | discrete_input_interface *intf; |
| 1145 | if (node->interface(intf)) |
| 1146 | intf->input_write(0, data); |
| 1147 | else |
| 1148 | discrete_log("discrete_sound_w write to non-input NODE_%02d\n", offset-NODE_00); |
| 1395 | 1149 | } |
| 1396 | 1150 | else |
| 1397 | 1151 | { |
| 1398 | | discrete_log(info, "discrete_sound_w write to non-existent NODE_%02d\n", offset-NODE_00); |
| 1152 | discrete_log("discrete_sound_w write to non-existent NODE_%02d\n", offset-NODE_00); |
| 1399 | 1153 | } |
| 1400 | 1154 | } |
src/emu/sound/discrete.h
| r10048 | r10049 | |
| 3 | 3 | #ifndef __DISCRETE_H__ |
| 4 | 4 | #define __DISCRETE_H__ |
| 5 | 5 | |
| 6 | | //#include "devlegcy.h" |
| 7 | 6 | #include "machine/rescap.h" |
| 8 | 7 | |
| 9 | 8 | /*********************************************************************** |
| r10048 | r10049 | |
| 3477 | 3476 | *************************************/ |
| 3478 | 3477 | |
| 3479 | 3478 | /* calculate charge exponent using discrete sample time */ |
| 3480 | | #define RC_CHARGE_EXP(rc) (1.0 - exp((node)->info->neg_sample_time / (rc))) |
| 3479 | #define RC_CHARGE_EXP(rc) (1.0 - exp(-(node)->sample_time() / (rc))) |
| 3480 | #define RC_CHARGE_EXP_CLASS(rc) (1.0 - exp(-this->sample_time() / (rc))) |
| 3481 | 3481 | /* calculate charge exponent using given sample time */ |
| 3482 | 3482 | #define RC_CHARGE_EXP_DT(rc, dt) (1.0 - exp(-(dt) / (rc))) |
| 3483 | 3483 | #define RC_CHARGE_NEG_EXP_DT(rc, dt) (1.0 - exp((dt) / (rc))) |
| 3484 | 3484 | |
| 3485 | 3485 | /* calculate discharge exponent using discrete sample time */ |
| 3486 | | #define RC_DISCHARGE_EXP(rc) (exp((node)->info->neg_sample_time / (rc))) |
| 3486 | #define RC_DISCHARGE_EXP(rc) (exp(-(node)->sample_time() / (rc))) |
| 3487 | #define RC_DISCHARGE_EXP_CLASS(rc) (exp(-this->sample_time() / (rc))) |
| 3487 | 3488 | /* calculate discharge exponent using given sample time */ |
| 3488 | 3489 | #define RC_DISCHARGE_EXP_DT(rc, dt) (exp(-(dt) / (rc))) |
| 3489 | 3490 | #define RC_DISCHARGE_NEG_EXP_DT(rc, dt) (exp((dt) / (rc))) |
| r10048 | r10049 | |
| 3496 | 3497 | * |
| 3497 | 3498 | *************************************/ |
| 3498 | 3499 | |
| 3499 | | #define DISCRETE_STEP_NAME( _func ) _func ## _step |
| 3500 | | #define DISCRETE_RESET_NAME( _func ) _func ## _reset |
| 3501 | | #define DISCRETE_START_NAME( _func ) _func ## _start |
| 3502 | | #define DISCRETE_STOP_NAME( _func ) _func ## _stop |
| 3500 | #define DISCRETE_CLASS_FUNC(_class, _func) DISCRETE_CLASS_NAME(_class) :: _func |
| 3503 | 3501 | |
| 3504 | | #define DISCRETE_FUNC(_func) void _func (node_description *node) |
| 3502 | #define DISCRETE_STEP(_class) void DISCRETE_CLASS_FUNC(_class, step)(void) |
| 3503 | #define DISCRETE_RESET(_class) void DISCRETE_CLASS_FUNC(_class, reset)(void) |
| 3504 | #define DISCRETE_START(_class) void DISCRETE_CLASS_FUNC(_class, start)(void) |
| 3505 | #define DISCRETE_STOP(_class) void DISCRETE_CLASS_FUNC(_class, stop)(void) |
| 3506 | #define DISCRETE_IS_STEPPING(_class) bool DISCRETE_CLASS_FUNC(_class, is_stepping)(void) |
| 3505 | 3507 | |
| 3506 | | #define DISCRETE_STEP(_func) static DISCRETE_FUNC(DISCRETE_STEP_NAME(_func)) |
| 3507 | | #define DISCRETE_RESET(_func) static DISCRETE_FUNC(DISCRETE_RESET_NAME(_func)) |
| 3508 | | #define DISCRETE_START(_func) static DISCRETE_FUNC(DISCRETE_START_NAME(_func)) |
| 3509 | | #define DISCRETE_STOP(_func) static DISCRETE_FUNC(DISCRETE_STOP_NAME(_func)) |
| 3508 | #define DISCRETE_DECLARE_CONTEXT(_name) struct _name##_context *context = (struct _name##_context *)this->m_context; |
| 3509 | #define DISCRETE_DECLARE_INFO(_name) const _name *info = (const _name *)this->custom_data(); |
| 3510 | 3510 | |
| 3511 | | #define DISCRETE_STEP_CALL(_func) DISCRETE_STEP_NAME(_func) (node) |
| 3512 | | #define DISCRETE_RESET_CALL(_func) DISCRETE_RESET_NAME(_func) (node) |
| 3513 | | #define DISCRETE_START_CALL(_func) DISCRETE_START_NAME(_func) (node) |
| 3514 | | #define DISCRETE_STOP_CALL(_func) DISCRETE_STOP_NAME(_func) (node) |
| 3511 | #define DISCRETE_INPUT(_num) (*(this->input[_num])) |
| 3515 | 3512 | |
| 3516 | | #define DISCRETE_DECLARE_CONTEXT(_name) struct _name##_context *context = (struct _name##_context *)node->context; |
| 3517 | | #define DISCRETE_DECLARE_INFO(_name) const _name *info = (const _name *)node->custom_data(); |
| 3518 | | |
| 3519 | | #define DISCRETE_CUSTOM_MODULE(_basename, _context_type) \ |
| 3520 | | { DST_CUSTOM, "CUSTOM", 1, sizeof(_context_type), DISCRETE_RESET_NAME(_basename), DISCRETE_STEP_NAME(_basename) } |
| 3521 | | |
| 3522 | | #define DISCRETE_INPUT(_num) (*(node->input[_num])) |
| 3523 | | |
| 3524 | 3513 | /************************************* |
| 3525 | 3514 | * |
| 3526 | 3515 | * Core constants |
| r10048 | r10049 | |
| 3771 | 3760 | template<class T> class enumerator_t |
| 3772 | 3761 | { |
| 3773 | 3762 | public: |
| 3774 | | enumerator_t(linked_list_entry *first) : m_cur(first) { } |
| 3775 | | ~enumerator_t() { } |
| 3763 | enumerator_t(linked_list_entry *first, resource_pool &pool = global_resource_pool) : m_cur(first) { } |
| 3764 | virtual ~enumerator_t() { } |
| 3776 | 3765 | |
| 3766 | //inline void set_first(linked_list_entry *first) { m_cur = first; } |
| 3777 | 3767 | inline T item(void) { return (T) m_cur->ptr; } |
| 3778 | 3768 | inline void next(void) { m_cur = m_cur->next; } |
| 3779 | 3769 | inline bool has_item(void) { return (m_cur != NULL); } |
| 3770 | protected: |
| 3780 | 3771 | private: |
| 3781 | 3772 | linked_list_entry *m_cur; |
| 3782 | 3773 | }; |
| r10048 | r10049 | |
| 3843 | 3834 | } |
| 3844 | 3835 | return cnt; |
| 3845 | 3836 | } |
| 3846 | | inline enumerator_t<T> enumerator(void) const {enumerator_t<T> r(m_first); return r; } |
| 3837 | inline enumerator_t<T> enumerator(void) const { enumerator_t<T> r(m_first); return r; } |
| 3847 | 3838 | private: |
| 3848 | 3839 | linked_list_entry *m_first; |
| 3849 | 3840 | linked_list_entry *m_last; |
| r10048 | r10049 | |
| 3851 | 3842 | |
| 3852 | 3843 | /************************************* |
| 3853 | 3844 | * |
| 3854 | | * The discrete sound blocks as |
| 3855 | | * defined in the drivers |
| 3856 | | * |
| 3857 | | *************************************/ |
| 3858 | | |
| 3859 | | struct _discrete_sound_block |
| 3860 | | { |
| 3861 | | int node; /* Output node number */ |
| 3862 | | int type; /* see defines below */ |
| 3863 | | int active_inputs; /* Number of active inputs on this node type */ |
| 3864 | | int input_node[DISCRETE_MAX_INPUTS];/* input/control nodes */ |
| 3865 | | double initial[DISCRETE_MAX_INPUTS]; /* Initial values */ |
| 3866 | | const void * custom; /* Custom function specific initialisation data */ |
| 3867 | | const char * name; /* Node Name */ |
| 3868 | | }; |
| 3869 | | typedef struct _discrete_sound_block discrete_sound_block; |
| 3870 | | |
| 3871 | | /************************************* |
| 3872 | | * |
| 3873 | | * Internal structure of a node |
| 3874 | | * |
| 3875 | | *************************************/ |
| 3876 | | |
| 3877 | | typedef struct _discrete_module discrete_module; |
| 3878 | | typedef struct _discrete_info discrete_info; |
| 3879 | | |
| 3880 | | |
| 3881 | | class node_description; |
| 3882 | | typedef linked_list_t<node_description *> node_list_t; |
| 3883 | | |
| 3884 | | |
| 3885 | | class node_description |
| 3886 | | { |
| 3887 | | public: |
| 3888 | | node_description(const discrete_info * info, const discrete_module *module, const discrete_sound_block *block); |
| 3889 | | |
| 3890 | | ~node_description(void); |
| 3891 | | |
| 3892 | | /* Return the node index, i.e. X from NODE(X) */ |
| 3893 | | int index(void); |
| 3894 | | /* Return the node number, i.e. NODE(X) */ |
| 3895 | | inline int block_node(void) { return m_block->node; } |
| 3896 | | /* Return the node type */ |
| 3897 | | inline int block_type(void) { return m_block->type; } |
| 3898 | | /* Custom function specific initialisation data */ |
| 3899 | | inline const void *custom_data(void) { return m_custom; } |
| 3900 | | |
| 3901 | | void find_input_nodes(void); |
| 3902 | | void save_state(device_t *device); |
| 3903 | | |
| 3904 | | inline int input_node(int inputnum) { return m_block->input_node[inputnum]; } |
| 3905 | | |
| 3906 | | /* FIXME: this is used by csv and wav logs - going forward, ids should be explicitly passed */ |
| 3907 | | int same_module_index(const node_list_t &list); |
| 3908 | | |
| 3909 | | /* The node's last output value */ |
| 3910 | | double output[DISCRETE_MAX_OUTPUTS]; |
| 3911 | | |
| 3912 | | /* Called to execute one time delta of output update */ |
| 3913 | | DISCRETE_FUNC((*step)); |
| 3914 | | |
| 3915 | | /* Contextual information specific to this node type */ |
| 3916 | | void * context; |
| 3917 | | |
| 3918 | | const double * input[DISCRETE_MAX_INPUTS]; /* Addresses of Input values */ |
| 3919 | | /* Number of active inputs on this node type */ |
| 3920 | | inline int active_inputs(void) { return m_active_inputs; } |
| 3921 | | /* Bit Flags. 1 in bit location means input_is_node */ |
| 3922 | | inline int input_is_node(void) { return m_input_is_node; }; |
| 3923 | | |
| 3924 | | const discrete_module *module; /* Node's module info */ |
| 3925 | | const discrete_info *info; /* Points to the parent */ |
| 3926 | | |
| 3927 | | osd_ticks_t run_time; |
| 3928 | | protected: |
| 3929 | | private: |
| 3930 | | const discrete_sound_block *m_block; /* Points to the node's setup block. */ |
| 3931 | | int m_active_inputs; /* Number of active inputs on this node type */ |
| 3932 | | /* Custom function specific initialisation data */ |
| 3933 | | const void * m_custom; |
| 3934 | | int m_input_is_node; |
| 3935 | | |
| 3936 | | }; |
| 3937 | | |
| 3938 | | |
| 3939 | | /************************************* |
| 3940 | | * |
| 3941 | | * Discrete module definition |
| 3942 | | * |
| 3943 | | *************************************/ |
| 3944 | | |
| 3945 | | struct _discrete_module |
| 3946 | | { |
| 3947 | | int type; |
| 3948 | | const char * name; |
| 3949 | | int num_output; /* Total number of output nodes, i.e. Master node + 1 */ |
| 3950 | | size_t contextsize; |
| 3951 | | DISCRETE_FUNC((*reset)); /* Called to reset a node after creation or system reset */ |
| 3952 | | DISCRETE_FUNC((*step)); /* Called to execute one time delta of output update */ |
| 3953 | | DISCRETE_FUNC((*start)); /* Called to execute at device start */ |
| 3954 | | DISCRETE_FUNC((*stop)); /* Called to execute at device stop */ |
| 3955 | | }; |
| 3956 | | |
| 3957 | | /************************************* |
| 3958 | | * |
| 3959 | | * Core runtime info |
| 3960 | | * |
| 3961 | | * this structure is exposed mainly |
| 3962 | | * to read the sample rate info |
| 3963 | | * and possibly context info |
| 3964 | | * |
| 3965 | | *************************************/ |
| 3966 | | |
| 3967 | | |
| 3968 | | typedef struct _discrete_source_node discrete_source_node; |
| 3969 | | |
| 3970 | | typedef linked_list_t<discrete_source_node *> source_node_list_t; |
| 3971 | | |
| 3972 | | class discrete_task |
| 3973 | | { |
| 3974 | | public: |
| 3975 | | discrete_task(void) |
| 3976 | | : numbuffered(0), task_group(0), m_threadid(-1) |
| 3977 | | { |
| 3978 | | source_list.reset(); |
| 3979 | | list.reset(); |
| 3980 | | } |
| 3981 | | |
| 3982 | | ~discrete_task(void) { } |
| 3983 | | |
| 3984 | | //const linked_list_entry *list; |
| 3985 | | node_list_t list; |
| 3986 | | |
| 3987 | | volatile int samples; |
| 3988 | | |
| 3989 | | /* list of source nodes */ |
| 3990 | | source_node_list_t source_list; /* discrete_source_node */ |
| 3991 | | |
| 3992 | | int numbuffered; |
| 3993 | | int task_group; |
| 3994 | | double *ptr[DISCRETE_MAX_TASK_OUTPUTS]; |
| 3995 | | const double *source[DISCRETE_MAX_TASK_OUTPUTS]; |
| 3996 | | |
| 3997 | | double *node_buf[DISCRETE_MAX_TASK_OUTPUTS]; |
| 3998 | | node_description *nodes[DISCRETE_MAX_TASK_OUTPUTS]; |
| 3999 | | |
| 4000 | | inline bool lock_threadid(INT32 threadid) |
| 4001 | | { |
| 4002 | | INT32 prev_id; |
| 4003 | | prev_id = compare_exchange32(&m_threadid, -1, threadid); |
| 4004 | | return (prev_id == -1 && m_threadid == threadid); |
| 4005 | | } |
| 4006 | | inline void unlock(void) { m_threadid = -1; } |
| 4007 | | private: |
| 4008 | | volatile INT32 m_threadid; |
| 4009 | | }; |
| 4010 | | |
| 4011 | | typedef linked_list_t<discrete_task *> task_list_t; |
| 4012 | | |
| 4013 | | struct _discrete_source_node |
| 4014 | | { |
| 4015 | | const discrete_task *task; |
| 4016 | | const double *ptr; |
| 4017 | | int output_node; |
| 4018 | | double buffer; |
| 4019 | | }; |
| 4020 | | |
| 4021 | | struct _discrete_info |
| 4022 | | { |
| 4023 | | device_t *device; |
| 4024 | | |
| 4025 | | /* emulation info */ |
| 4026 | | int sample_rate; |
| 4027 | | double sample_time; |
| 4028 | | double neg_sample_time; |
| 4029 | | |
| 4030 | | /* internal node tracking */ |
| 4031 | | node_description **indexed_node; |
| 4032 | | |
| 4033 | | /* list of all nodes */ |
| 4034 | | node_list_t node_list; /* node_description * */ |
| 4035 | | |
| 4036 | | /* list of discrete blocks after prescan (IMPORT, DELETE, REPLACE) */ |
| 4037 | | linked_list_entry *block_list; /* discrete_sound_block * */ |
| 4038 | | |
| 4039 | | /* tasks */ |
| 4040 | | task_list_t task_list; /* discrete_task_context * */ |
| 4041 | | |
| 4042 | | /* the input streams */ |
| 4043 | | node_list_t input_list; |
| 4044 | | |
| 4045 | | /* output node tracking */ |
| 4046 | | node_list_t output_list; |
| 4047 | | |
| 4048 | | /* the output stream */ |
| 4049 | | sound_stream *discrete_stream; |
| 4050 | | |
| 4051 | | /* debugging statistics */ |
| 4052 | | FILE *disclogfile; |
| 4053 | | |
| 4054 | | /* parallel tasks */ |
| 4055 | | osd_work_queue *queue; |
| 4056 | | |
| 4057 | | /* profiling */ |
| 4058 | | UINT64 total_samples; |
| 4059 | | UINT64 total_stream_updates; |
| 4060 | | }; |
| 4061 | | |
| 4062 | | |
| 4063 | | /************************************* |
| 4064 | | * |
| 4065 | 3845 | * Node-specific struct types |
| 4066 | 3846 | * |
| 4067 | 3847 | *************************************/ |
| r10048 | r10049 | |
| 4306 | 4086 | }; |
| 4307 | 4087 | |
| 4308 | 4088 | |
| 4309 | | typedef struct _discrete_custom_info discrete_custom_info; |
| 4310 | | struct _discrete_custom_info |
| 4311 | | { |
| 4312 | | const discrete_module module; |
| 4313 | | const void *custom; /* Custom function specific initialisation data */ |
| 4314 | | }; |
| 4315 | | |
| 4316 | | |
| 4317 | 4089 | // Taken from the transfer characteristerics diagram in CD4049UB datasheet (TI) |
| 4318 | 4090 | // There is no default trigger point and vI-vO is a continuous function |
| 4319 | 4091 | |
| r10048 | r10049 | |
| 4425 | 4197 | * |
| 4426 | 4198 | *************************************/ |
| 4427 | 4199 | |
| 4428 | | enum |
| 4200 | typedef enum |
| 4429 | 4201 | { |
| 4430 | 4202 | DSS_NULL, /* Nothing, nill, zippo, only to be used as terminating node */ |
| 4431 | 4203 | DSS_NOP, /* just do nothing, placeholder for potential DISCRETE_REPLACE in parent block */ |
| 4432 | 4204 | |
| 4433 | | /* from disc_inp.c */ |
| 4434 | | DSS_ADJUSTMENT, /* Adjustment node */ |
| 4435 | | DSS_CONSTANT, /* Constant node */ |
| 4436 | | /* Do not change or add to the next 4 without also modifying disc_inp.c */ |
| 4437 | | DSS_INPUT_DATA, /* Input node */ |
| 4438 | | DSS_INPUT_LOGIC, /* Input node */ |
| 4439 | | DSS_INPUT_NOT, /* Input node */ |
| 4440 | | DSS_INPUT_PULSE, /* Input node, single pulsed version */ |
| 4441 | | DSS_INPUT_STREAM, /* Stream Input */ |
| 4442 | | DSS_INPUT_BUFFER, /* Buffer Input node, for high freq inputs like DAC */ |
| 4205 | /* standard node */ |
| 4443 | 4206 | |
| 4444 | | /* from disc_wav.c */ |
| 4445 | | /* generic modules */ |
| 4446 | | DSS_COUNTER, /* External clock Binary Counter */ |
| 4447 | | DSS_COUNTER_FIX, /* Fixed frequency Binary Counter */ |
| 4448 | | DSS_LFSR_NOISE, /* Cyclic/Resetable LFSR based Noise generator */ |
| 4449 | | DSS_NOTE, /* Note Generator */ |
| 4450 | | DSS_NOISE, /* Random Noise generator */ |
| 4451 | | DSS_SAWTOOTHWAVE, /* Sawtooth wave generator */ |
| 4452 | | DSS_SINEWAVE, /* Sine Wave generator */ |
| 4453 | | DSS_SQUAREWAVE, /* Square Wave generator, adjustable frequency based */ |
| 4454 | | DSS_SQUAREWFIX, /* Square Wave generator, fixed frequency based (faster) */ |
| 4455 | | DSS_SQUAREWAVE2, /* Square Wave generator, time based */ |
| 4456 | | DSS_INVERTER_OSC, /* Oscillator based on inverter circuits */ |
| 4457 | | DSS_TRIANGLEWAVE, /* Triangle wave generator, frequency based */ |
| 4458 | | /* Component specific */ |
| 4459 | | DSS_OP_AMP_OSC, /* Op Amp Oscillator */ |
| 4460 | | DSS_SCHMITT_OSC, /* Schmitt Feedback Oscillator */ |
| 4461 | | /* Not yet implemented */ |
| 4462 | | DSS_ADSR, /* ADSR Envelope generator */ |
| 4207 | DSS_NODE, /* a standard node */ |
| 4463 | 4208 | |
| 4464 | | /* from disc_mth.c */ |
| 4465 | | /* generic modules */ |
| 4466 | | DST_ADDER, /* C = A+B */ |
| 4467 | | DST_CLAMP, /* Signal Clamp */ |
| 4468 | | DST_DIVIDE, /* Gain Block, C = A/B */ |
| 4469 | | DST_GAIN, /* Gain Block, D = (A*B) + C*/ |
| 4470 | | DST_BITS_DECODE, /* Decode bits from input value */ |
| 4471 | | DST_LOGIC_INV, |
| 4472 | | DST_LOGIC_AND, |
| 4473 | | DST_LOGIC_NAND, |
| 4474 | | DST_LOGIC_OR, |
| 4475 | | DST_LOGIC_NOR, |
| 4476 | | DST_LOGIC_XOR, |
| 4477 | | DST_LOGIC_NXOR, |
| 4478 | | DST_LOGIC_DFF, |
| 4479 | | DST_LOGIC_JKFF, |
| 4480 | | DST_LOGIC_SHIFT, |
| 4481 | | DST_LOOKUP_TABLE, /* return value from lookup table */ |
| 4482 | | DST_MULTIPLEX, /* 1 of x multiplexer */ |
| 4483 | | DST_ONESHOT, /* One-shot pulse generator */ |
| 4484 | | DST_RAMP, /* Ramp up/down simulation */ |
| 4485 | | DST_SAMPHOLD, /* Sample & hold transform */ |
| 4486 | | DST_SWITCH, /* C = A or B */ |
| 4487 | | DST_ASWITCH, /* Analog switch */ |
| 4488 | | DST_TRANSFORM, /* Muliply math functions based on string */ |
| 4489 | | /* Component specific */ |
| 4490 | | DST_COMP_ADDER, /* Selectable Parallel Component Adder */ |
| 4491 | | DST_DAC_R1, /* R1 Ladder DAC with cap smoothing */ |
| 4492 | | DST_DIODE_MIX, /* Diode mixer */ |
| 4493 | | DST_INTEGRATE, /* Various Integration circuits */ |
| 4494 | | DST_MIXER, /* Final Mixing Stage */ |
| 4495 | | DST_OP_AMP, /* Op Amp circuits */ |
| 4496 | | DST_OP_AMP_1SHT, /* Op Amp One Shot */ |
| 4497 | | DST_TVCA_OP_AMP, /* Triggered Op Amp Voltage controlled amplifier circuits */ |
| 4498 | | DST_VCA, /* IC Voltage controlled amplifiers */ |
| 4499 | | DST_XTIME_BUFFER, |
| 4500 | | DST_XTIME_AND, |
| 4501 | | DST_XTIME_OR, |
| 4502 | | DST_XTIME_XOR, |
| 4503 | | |
| 4504 | | /* from disc_flt.c */ |
| 4505 | | /* generic modules */ |
| 4506 | | DST_FILTER1, /* 1st Order Filter, Low or High Pass */ |
| 4507 | | DST_FILTER2, /* 2nd Order Filter, Low, High, or Band Pass */ |
| 4508 | | /* Component specific */ |
| 4509 | | DST_SALLEN_KEY, /* Sallen key filters */ |
| 4510 | | DST_CRFILTER, /* RC Bypass Filter (High Pass) */ |
| 4511 | | DST_OP_AMP_FILT, /* Op Amp filters */ |
| 4512 | | DST_RC_CIRCUIT_1, |
| 4513 | | DST_RCDISC, /* Simple RC discharge */ |
| 4514 | | DST_RCDISC2, /* Switched 2 Input RC discharge */ |
| 4515 | | DST_RCDISC3, /* Charge/discharge with diode */ |
| 4516 | | DST_RCDISC4, /* various Charge/discharge circuits */ |
| 4517 | | DST_RCDISC5, /* Diode in series with R//C */ |
| 4518 | | DST_RCINTEGRATE, /* NPN RC charge/discharge network */ |
| 4519 | | DST_RCDISC_MOD, /* Two diode mixer with Transistor and charge/discharge network */ |
| 4520 | | DST_RCFILTER, /* Simple RC Filter network */ |
| 4521 | | DST_RCFILTER_SW, /* Switcheable RC Filter network */ |
| 4522 | | /* For testing - seem to be buggered. Use versions not ending in N. */ |
| 4523 | | DST_RCFILTERN, /* Simple RC Filter network */ |
| 4524 | | DST_RCDISCN, /* Simple RC discharge */ |
| 4525 | | DST_RCDISC2N, /* Switched 2 Input RC discharge */ |
| 4526 | | |
| 4527 | | /* from disc_dev.c */ |
| 4528 | | /* Component specific */ |
| 4529 | | DSD_555_ASTBL, /* NE555 Astable Emulation */ |
| 4530 | | DSD_555_MSTBL, /* NE555 Monostable Emulation */ |
| 4531 | | DSD_555_CC, /* Constant Current 555 circuit (VCO)*/ |
| 4532 | | DSD_555_VCO1, /* Op-Amp linear ramp based 555 VCO */ |
| 4533 | | DSD_566, /* NE566 Emulation */ |
| 4534 | | DSD_LS624, /* 74LS624 Emulation */ |
| 4535 | | |
| 4536 | 4209 | /* Custom */ |
| 4537 | 4210 | DST_CUSTOM, /* whatever you want */ |
| 4538 | 4211 | |
| r10048 | r10049 | |
| 4543 | 4216 | /* Parallel execution */ |
| 4544 | 4217 | DSO_TASK_START, /* start of parallel task */ |
| 4545 | 4218 | DSO_TASK_END, /* end of parallel task */ |
| 4546 | | DSO_TASK_SYNC, /* wait for all parallel tasks to finish */ |
| 4547 | 4219 | |
| 4548 | 4220 | /* Output Node -- this must be the last entry in this enum! */ |
| 4549 | 4221 | DSO_OUTPUT, /* The final output node */ |
| r10048 | r10049 | |
| 4555 | 4227 | |
| 4556 | 4228 | /* Marks end of this enum -- must be last entry ! */ |
| 4557 | 4229 | DSO_LAST |
| 4558 | | }; |
| 4230 | } discrete_node_type; |
| 4559 | 4231 | |
| 4560 | | |
| 4561 | | |
| 4562 | 4232 | /************************************* |
| 4563 | 4233 | * |
| 4564 | | * Encapsulation macros for defining |
| 4565 | | * your simulation |
| 4234 | * Forward declarations |
| 4566 | 4235 | * |
| 4567 | 4236 | *************************************/ |
| 4568 | 4237 | |
| 4569 | | #define MCFG_SOUND_CONFIG_DISCRETE(name) MCFG_SOUND_CONFIG(name##_discrete_interface) |
| 4238 | typedef struct _discrete_sound_block discrete_sound_block; |
| 4239 | class discrete_node_base_factory; |
| 4240 | class discrete_task; |
| 4241 | class discrete_base_node; |
| 4242 | class discrete_dss_input_stream_node; |
| 4243 | class discrete_device; |
| 4244 | typedef linked_list_t<discrete_base_node *> node_list_t; |
| 4245 | typedef linked_list_t<discrete_dss_input_stream_node *> input_stream_node_list_t; |
| 4246 | typedef linked_list_t<discrete_task *> task_list_t; |
| 4570 | 4247 | |
| 4571 | | #define DISCRETE_SOUND_EXTERN(name) extern const discrete_sound_block name##_discrete_interface[] |
| 4572 | | #define DISCRETE_SOUND_START(name) const discrete_sound_block name##_discrete_interface[] = { |
| 4573 | 4248 | |
| 4574 | | #define DSC_SND_ENTRY(_nod, _dss, _num, _iact, _iinit, _custom, _name) { _nod, _dss, _num, _iact, _iinit, _custom, _name } |
| 4249 | /************************************* |
| 4250 | * |
| 4251 | * Discrete module definition |
| 4252 | * |
| 4253 | *************************************/ |
| 4575 | 4254 | |
| 4576 | 4255 | |
| 4577 | | #define DISCRETE_SOUND_END DSC_SND_ENTRY( NODE_00, DSS_NULL , 0, DSE( NODE_NC ), DSE( 0 ) ,NULL ,"DISCRETE_SOUND_END" ) }; |
| 4578 | | #define DSE( ... ) { __VA_ARGS__ } |
| 4256 | /************************************* |
| 4257 | * |
| 4258 | * The discrete sound blocks as |
| 4259 | * defined in the drivers |
| 4260 | * |
| 4261 | *************************************/ |
| 4579 | 4262 | |
| 4580 | | /* Module Name out, enum value, #in, {variable inputs}, {static inputs}, data pointer, "name" */ |
| 4263 | struct _discrete_sound_block |
| 4264 | { |
| 4265 | int node; /* Output node number */ |
| 4266 | discrete_node_base_factory *factory; |
| 4267 | int type; /* see defines below */ |
| 4268 | int active_inputs; /* Number of active inputs on this node type */ |
| 4269 | int input_node[DISCRETE_MAX_INPUTS];/* input/control nodes */ |
| 4270 | double initial[DISCRETE_MAX_INPUTS]; /* Initial values */ |
| 4271 | const void * custom; /* Custom function specific initialisation data */ |
| 4272 | const char * name; /* Node Name */ |
| 4273 | const char * mod_name; /* Module / class name */ |
| 4274 | }; |
| 4581 | 4275 | |
| 4582 | | /* from disc_inp.c */ |
| 4583 | | #define DISCRETE_ADJUSTMENT(NODE,MIN,MAX,LOGLIN,TAG) DSC_SND_ENTRY( NODE, DSS_ADJUSTMENT , 7, DSE( NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( MIN,MAX,LOGLIN,0 ,0 ,100 ), TAG , "DISCRETE_ADJUSTMENT" ), |
| 4584 | | #define DISCRETE_ADJUSTMENTX(NODE,MIN,MAX,LOGLIN,TAG,PMIN,PMAX) DSC_SND_ENTRY( NODE, DSS_ADJUSTMENT , 7, DSE( NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( MIN,MAX,LOGLIN,0 ,PMIN,PMAX ), TAG , "DISCRETE_ADJUSTMENTX" ), |
| 4585 | | #define DISCRETE_CONSTANT(NODE,CONST) DSC_SND_ENTRY( NODE, DSS_CONSTANT , 1, DSE( NODE_NC ), DSE( CONST ) ,NULL ,"DISCRETE_CONSTANT" ), |
| 4586 | | #define DISCRETE_INPUT_DATA(NODE) DSC_SND_ENTRY( NODE, DSS_INPUT_DATA , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), NULL, "DISCRETE_INPUT_DATA" ), |
| 4587 | | #define DISCRETE_INPUTX_DATA(NODE,GAIN,OFFSET,INIT) DSC_SND_ENTRY( NODE, DSS_INPUT_DATA , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), NULL, "DISCRETE_INPUTX_DATA" ), |
| 4588 | | #define DISCRETE_INPUT_LOGIC(NODE) DSC_SND_ENTRY( NODE, DSS_INPUT_LOGIC , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), NULL, "DISCRETE_INPUT_LOGIC" ), |
| 4589 | | #define DISCRETE_INPUTX_LOGIC(NODE,GAIN,OFFSET,INIT) DSC_SND_ENTRY( NODE, DSS_INPUT_LOGIC , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), NULL, "DISCRETE_INPUTX_LOGIC" ), |
| 4590 | | #define DISCRETE_INPUT_NOT(NODE) DSC_SND_ENTRY( NODE, DSS_INPUT_NOT , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), NULL, "DISCRETE_INPUT_NOT" ), |
| 4591 | | #define DISCRETE_INPUTX_NOT(NODE,GAIN,OFFSET,INIT) DSC_SND_ENTRY( NODE, DSS_INPUT_NOT , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), NULL, "DISCRETE_INPUTX_NOT" ), |
| 4592 | | #define DISCRETE_INPUT_PULSE(NODE,INIT) DSC_SND_ENTRY( NODE, DSS_INPUT_PULSE , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,INIT ), NULL, "DISCRETE_INPUT_PULSE" ), |
| 4276 | /************************************* |
| 4277 | * |
| 4278 | * Node interfaces |
| 4279 | * |
| 4280 | *************************************/ |
| 4593 | 4281 | |
| 4594 | | #define DISCRETE_INPUT_STREAM(NODE, NUM) DSC_SND_ENTRY( NODE, DSS_INPUT_STREAM, 3, DSE( NUM,NODE_NC,NODE_NC ), DSE( NUM,1,0 ), NULL, "DISCRETE_INPUT_STREAM" ), |
| 4595 | | #define DISCRETE_INPUTX_STREAM(NODE, NUM, GAIN,OFFSET) DSC_SND_ENTRY( NODE, DSS_INPUT_STREAM, 3, DSE( NUM,NODE_NC,NODE_NC ), DSE( NUM,GAIN,OFFSET ), NULL, "DISCRETE_INPUTX_STREAM" ), |
| 4282 | class discrete_step_interface |
| 4283 | { |
| 4284 | public: |
| 4285 | virtual ~discrete_step_interface() { } |
| 4596 | 4286 | |
| 4597 | | #define DISCRETE_INPUT_BUFFER(NODE, NUM) DSC_SND_ENTRY( NODE, DSS_INPUT_BUFFER, 3, DSE( NUM,NODE_NC,NODE_NC ), DSE( NUM,1,0 ), NULL, "DISCRETE_INPUT_BUFFER" ), |
| 4287 | virtual void step(void) = 0; |
| 4288 | osd_ticks_t run_time; |
| 4289 | discrete_base_node * self; |
| 4290 | }; |
| 4291 | typedef linked_list_t<discrete_step_interface *> node_step_list_t; |
| 4598 | 4292 | |
| 4599 | | /* from disc_wav.c */ |
| 4600 | | /* generic modules */ |
| 4601 | | #define DISCRETE_COUNTER(NODE,ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE) DSC_SND_ENTRY( NODE, DSS_COUNTER , 8, DSE( ENAB,RESET,CLK,NODE_NC,NODE_NC,DIR,INIT0,NODE_NC ), DSE( ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE ), NULL, "DISCRETE_COUNTER" ), |
| 4602 | | #define DISCRETE_COUNTER_7492(NODE,ENAB,RESET,CLK,CLKTYPE) DSC_SND_ENTRY( NODE, DSS_COUNTER , 8, DSE( ENAB,RESET,CLK,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,RESET,CLK,CLKTYPE,0,1,0,DISC_COUNTER_IS_7492 ), NULL, "DISCRETE_COUNTER_7492" ), |
| 4603 | | #define DISCRETE_LFSR_NOISE(NODE,ENAB,RESET,CLK,AMPL,FEED,BIAS,LFSRTB) DSC_SND_ENTRY( NODE, DSS_LFSR_NOISE , 6, DSE( ENAB,RESET,CLK,AMPL,FEED,BIAS ), DSE( ENAB,RESET,CLK,AMPL,FEED,BIAS ), LFSRTB, "DISCRETE_LFSR_NOISE" ), |
| 4604 | | #define DISCRETE_NOISE(NODE,ENAB,FREQ,AMPL,BIAS) DSC_SND_ENTRY( NODE, DSS_NOISE , 4, DSE( ENAB,FREQ,AMPL,BIAS ), DSE( ENAB,FREQ,AMPL,BIAS ), NULL, "DISCRETE_NOISE" ), |
| 4605 | | #define DISCRETE_NOTE(NODE,ENAB,CLK,DATA,MAX1,MAX2,CLKTYPE) DSC_SND_ENTRY( NODE, DSS_NOTE , 6, DSE( ENAB,CLK,DATA,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,CLK,DATA,MAX1,MAX2,CLKTYPE ), NULL, "DISCRETE_NOTE" ), |
| 4606 | | #define DISCRETE_SAWTOOTHWAVE(NODE,ENAB,FREQ,AMPL,BIAS,GRAD,PHASE) DSC_SND_ENTRY( NODE, DSS_SAWTOOTHWAVE, 6, DSE( ENAB,FREQ,AMPL,BIAS,NODE_NC,NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,GRAD,PHASE ), NULL, "DISCRETE_SAWTOOTHWAVE" ), |
| 4607 | | #define DISCRETE_SINEWAVE(NODE,ENAB,FREQ,AMPL,BIAS,PHASE) DSC_SND_ENTRY( NODE, DSS_SINEWAVE , 5, DSE( ENAB,FREQ,AMPL,BIAS,NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,PHASE ), NULL, "DISCRETE_SINEWAVE" ), |
| 4608 | | #define DISCRETE_SQUAREWAVE(NODE,ENAB,FREQ,AMPL,DUTY,BIAS,PHASE) DSC_SND_ENTRY( NODE, DSS_SQUAREWAVE , 6, DSE( ENAB,FREQ,AMPL,DUTY,BIAS,NODE_NC ), DSE( ENAB,FREQ,AMPL,DUTY,BIAS,PHASE ), NULL, "DISCRETE_SQUAREWAVE" ), |
| 4609 | | #define DISCRETE_SQUAREWFIX(NODE,ENAB,FREQ,AMPL,DUTY,BIAS,PHASE) DSC_SND_ENTRY( NODE, DSS_SQUAREWFIX , 6, DSE( ENAB,FREQ,AMPL,DUTY,BIAS,NODE_NC ), DSE( ENAB,FREQ,AMPL,DUTY,BIAS,PHASE ), NULL, "DISCRETE_SQUAREWFIX" ), |
| 4610 | | #define DISCRETE_SQUAREWAVE2(NODE,ENAB,AMPL,T_OFF,T_ON,BIAS,TSHIFT) DSC_SND_ENTRY( NODE, DSS_SQUAREWAVE2 , 6, DSE( ENAB,AMPL,T_OFF,T_ON,BIAS,NODE_NC ), DSE( ENAB,AMPL,T_OFF,T_ON,BIAS,TSHIFT ), NULL, "DISCRETE_SQUAREWAVE2" ), |
| 4611 | | #define DISCRETE_TRIANGLEWAVE(NODE,ENAB,FREQ,AMPL,BIAS,PHASE) DSC_SND_ENTRY( NODE, DSS_TRIANGLEWAVE, 5, DSE( ENAB,FREQ,AMPL,BIAS,NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,PHASE ), NULL, "DISCRETE_TRIANGLEWAVE" ), |
| 4612 | | /* Component specific */ |
| 4613 | | #define DISCRETE_INVERTER_OSC(NODE,ENAB,MOD,RCHARGE,RP,C,R2,INFO) DSC_SND_ENTRY( NODE, DSS_INVERTER_OSC, 6, DSE( ENAB,MOD,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,MOD,RCHARGE,RP,C,R2 ), INFO, "DISCRETE_INVERTER_OSC" ), |
| 4614 | | #define DISCRETE_OP_AMP_OSCILLATOR(NODE,ENAB,INFO) DSC_SND_ENTRY( NODE, DSS_OP_AMP_OSC , 1, DSE( ENAB ), DSE( ENAB ), INFO, "DISCRETE_OP_AMP_OSCILLATOR" ), |
| 4615 | | #define DISCRETE_OP_AMP_VCO1(NODE,ENAB,VMOD1,INFO) DSC_SND_ENTRY( NODE, DSS_OP_AMP_OSC , 2, DSE( ENAB,VMOD1 ), DSE( ENAB,VMOD1 ), INFO, "DISCRETE_OP_AMP_VCO1" ), |
| 4616 | | #define DISCRETE_OP_AMP_VCO2(NODE,ENAB,VMOD1,VMOD2,INFO) DSC_SND_ENTRY( NODE, DSS_OP_AMP_OSC , 3, DSE( ENAB,VMOD1,VMOD2 ), DSE( ENAB,VMOD1,VMOD2 ), INFO, "DISCRETE_OP_AMP_VCO2" ), |
| 4617 | | #define DISCRETE_SCHMITT_OSCILLATOR(NODE,ENAB,INP0,AMPL,TABLE) DSC_SND_ENTRY( NODE, DSS_SCHMITT_OSC , 3, DSE( ENAB,INP0,AMPL ), DSE( ENAB,INP0,AMPL ), TABLE, "DISCRETE_SCHMITT_OSCILLATOR" ), |
| 4618 | | /* Not yet implemented */ |
| 4619 | | #define DISCRETE_ADSR_ENV(NODE,ENAB,TRIGGER,GAIN,ADSRTB) DSC_SND_ENTRY( NODE, DSS_ADSR , 3, DSE( ENAB,TRIGGER,GAIN ), DSE( ENAB,TRIGGER,GAIN ), ADSRTB, "DISCRETE_ADSR_ENV" ), |
| 4293 | class discrete_input_interface |
| 4294 | { |
| 4295 | public: |
| 4296 | virtual ~discrete_input_interface() { } |
| 4620 | 4297 | |
| 4621 | | /* from disc_mth.c */ |
| 4622 | | /* generic modules */ |
| 4623 | | #define DISCRETE_ADDER2(NODE,ENAB,INP0,INP1) DSC_SND_ENTRY( NODE, DST_ADDER , 3, DSE( ENAB,INP0,INP1 ), DSE( ENAB,INP0,INP1 ), NULL, "DISCRETE_ADDER2" ), |
| 4624 | | #define DISCRETE_ADDER3(NODE,ENAB,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, DST_ADDER , 4, DSE( ENAB,INP0,INP1,INP2 ), DSE( ENAB,INP0,INP1,INP2 ), NULL, "DISCRETE_ADDER3" ), |
| 4625 | | #define DISCRETE_ADDER4(NODE,ENAB,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, DST_ADDER , 5, DSE( ENAB,INP0,INP1,INP2,INP3 ), DSE( ENAB,INP0,INP1,INP2,INP3 ), NULL, "DISCRETE_ADDER4" ), |
| 4626 | | #define DISCRETE_CLAMP(NODE,INP0,MIN,MAX) DSC_SND_ENTRY( NODE, DST_CLAMP , 3, DSE( INP0,MIN,MAX ), DSE( INP0,MIN,MAX ), NULL, "DISCRETE_CLAMP" ), |
| 4627 | | #define DISCRETE_DIVIDE(NODE,ENAB,INP0,INP1) DSC_SND_ENTRY( NODE, DST_DIVIDE , 3, DSE( ENAB,INP0,INP1 ), DSE( ENAB,INP0,INP1 ), NULL, "DISCRETE_DIVIDE" ), |
| 4628 | | #define DISCRETE_GAIN(NODE,INP0,GAIN) DSC_SND_ENTRY( NODE, DST_GAIN , 3, DSE( INP0,NODE_NC,NODE_NC ), DSE( INP0,GAIN,0 ), NULL, "DISCRETE_GAIN" ), |
| 4629 | | #define DISCRETE_INVERT(NODE,INP0) DSC_SND_ENTRY( NODE, DST_GAIN , 3, DSE( INP0,NODE_NC,NODE_NC ), DSE( INP0,-1,0 ), NULL, "DISCRETE_INVERT" ), |
| 4630 | | #define DISCRETE_LOGIC_INVERT(NODE,INP0) DSC_SND_ENTRY( NODE, DST_LOGIC_INV , 1, DSE( INP0 ), DSE( INP0 ), NULL, "DISCRETE_LOGIC_INVERT" ), |
| 4298 | virtual void input_write(int sub_node, UINT8 data ) = 0; |
| 4299 | }; |
| 4631 | 4300 | |
| 4632 | | #define DISCRETE_BIT_DECODE(NODE, INP, BIT_N, VOUT) DSC_SND_ENTRY( NODE, DST_BITS_DECODE , 4, DSE( INP,NODE_NC,NODE_NC,NODE_NC ), DSE( INP,BIT_N,BIT_N,VOUT ), NULL, "DISCRETE_BIT_DECODE" ), |
| 4633 | | #define DISCRETE_BITS_DECODE(NODE, INP, BIT_FROM, BIT_TO, VOUT) DSC_SND_ENTRY( NODE, DST_BITS_DECODE , 4, DSE( INP,NODE_NC,NODE_NC,NODE_NC ), DSE( INP,BIT_FROM,BIT_TO,VOUT ), NULL, "DISCRETE_BITS_DECODE" ), |
| 4301 | class discrete_output_interface |
| 4302 | { |
| 4303 | public: |
| 4304 | virtual ~discrete_output_interface() { } |
| 4634 | 4305 | |
| 4635 | | #define DISCRETE_LOGIC_AND(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, DST_LOGIC_AND , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,1.0,1.0 ), NULL, "DISCRETE_LOGIC_AND" ), |
| 4636 | | #define DISCRETE_LOGIC_AND3(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, DST_LOGIC_AND , 4, DSE( INP0,INP1,INP2,NODE_NC ), DSE( INP0,INP1,INP2,1.0 ), NULL, "DISCRETE_LOGIC_AND3" ), |
| 4637 | | #define DISCRETE_LOGIC_AND4(NODE,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, DST_LOGIC_AND , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ) ,NULL, "DISCRETE_LOGIC_AND4" ), |
| 4638 | | #define DISCRETE_LOGIC_NAND(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, DST_LOGIC_NAND , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,1.0,1.0 ), NULL, "DISCRETE_LOGIC_NAND" ), |
| 4639 | | #define DISCRETE_LOGIC_NAND3(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, DST_LOGIC_NAND , 4, DSE( INP0,INP1,INP2,NODE_NC ), DSE( INP0,INP1,INP2,1.0 ), NULL, "DISCRETE_LOGIC_NAND3" ), |
| 4640 | | #define DISCRETE_LOGIC_NAND4(NODE,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, DST_LOGIC_NAND , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ), NULL, ")DISCRETE_LOGIC_NAND4" ), |
| 4641 | | #define DISCRETE_LOGIC_OR(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, DST_LOGIC_OR , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,0.0,0.0 ), NULL, "DISCRETE_LOGIC_OR" ), |
| 4642 | | #define DISCRETE_LOGIC_OR3(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, DST_LOGIC_OR , 4, DSE( INP0,INP1,INP2,NODE_NC ), DSE( INP0,INP1,INP2,0.0 ), NULL, "DISCRETE_LOGIC_OR3" ), |
| 4643 | | #define DISCRETE_LOGIC_OR4(NODE,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, DST_LOGIC_OR , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ), NULL, "DISCRETE_LOGIC_OR4" ), |
| 4644 | | #define DISCRETE_LOGIC_NOR(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, DST_LOGIC_NOR , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,0.0,0.0 ), NULL, "DISCRETE_LOGIC_NOR" ), |
| 4645 | | #define DISCRETE_LOGIC_NOR3(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, DST_LOGIC_NOR , 4, DSE( INP0,INP1,INP2,NODE_NC ), DSE( INP0,INP1,INP2,0.0 ), NULL, "DISCRETE_LOGIC_NOR3" ), |
| 4646 | | #define DISCRETE_LOGIC_NOR4(NODE,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, DST_LOGIC_NOR , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ), NULL, "DISCRETE_LOGIC_NOR4" ), |
| 4647 | | #define DISCRETE_LOGIC_XOR(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, DST_LOGIC_XOR , 2, DSE( INP0,INP1 ), DSE( INP0,INP1 ), NULL, "DISCRETE_LOGIC_XOR" ), |
| 4648 | | #define DISCRETE_LOGIC_XNOR(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, DST_LOGIC_NXOR , 2, DSE( INP0,INP1 ), DSE( INP0,INP1 ), NULL, "DISCRETE_LOGIC_XNOR" ), |
| 4649 | | #define DISCRETE_LOGIC_DFLIPFLOP(NODE,RESET,SET,CLK,INP) DSC_SND_ENTRY( NODE, DST_LOGIC_DFF , 4, DSE( RESET,SET,CLK,INP ), DSE( RESET,SET,CLK,INP ), NULL, "DISCRETE_LOGIC_DFLIPFLOP" ), |
| 4650 | | #define DISCRETE_LOGIC_JKFLIPFLOP(NODE,RESET,SET,CLK,J,K) DSC_SND_ENTRY( NODE, DST_LOGIC_JKFF , 5, DSE( RESET,SET,CLK,J,K ), DSE( RESET,SET,CLK,J,K ), NULL, "DISCRETE_LOGIC_JKFLIPFLOP" ), |
| 4651 | | #define DISCRETE_LOGIC_SHIFT(NODE,INP0,RESET,CLK,SIZE,OPTIONS) DSC_SND_ENTRY( NODE, DST_LOGIC_SHIFT , 5, DSE( INP0,RESET,CLK,NODE_NC,NODE_NC ), DSE( INP0,RESET,CLK,SIZE,OPTIONS ), NULL, "DISCRETE_LOGIC_SHIFT" ), |
| 4652 | | #define DISCRETE_LOOKUP_TABLE(NODE,ADDR,SIZE,TABLE) DSC_SND_ENTRY( NODE, DST_LOOKUP_TABLE, 2, DSE( ADDR,NODE_NC ), DSE( ADDR,SIZE ), TABLE, "DISCRETE_LOOKUP_TABLE" ), |
| 4653 | | #define DISCRETE_MULTIPLEX2(NODE,ADDR,INP0,INP1) DSC_SND_ENTRY( NODE, DST_MULTIPLEX , 3, DSE( ADDR,INP0,INP1 ), DSE( ADDR,INP0,INP1 ), NULL, "DISCRETE_MULTIPLEX2" ), |
| 4654 | | #define DISCRETE_MULTIPLEX4(NODE,ADDR,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, DST_MULTIPLEX , 5, DSE( ADDR,INP0,INP1,INP2,INP3 ), DSE( ADDR,INP0,INP1,INP2,INP3 ), NULL, "DISCRETE_MULTIPLEX4" ), |
| 4655 | | #define DISCRETE_MULTIPLEX8(NODE,ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7) DSC_SND_ENTRY( NODE, DST_MULTIPLEX, 9, DSE( ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7 ), DSE( ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7 ), NULL, "DISCRETE_MULTIPLEX8" ), |
| 4656 | | #define DISCRETE_MULTIPLY(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, DST_GAIN , 3, DSE( INP0,INP1,NODE_NC ), DSE( INP0,INP1,0 ), NULL, "DISCRETE_MULTIPLY" ), |
| 4657 | | #define DISCRETE_MULTADD(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, DST_GAIN , 3, DSE( INP0,INP1,INP2 ), DSE( INP0,INP1,INP2 ), NULL, "DISCRETE_MULTADD" ), |
| 4658 | | #define DISCRETE_ONESHOT(NODE,TRIG,AMPL,WIDTH,TYPE) DSC_SND_ENTRY( NODE, DST_ONESHOT , 5, DSE( 0,TRIG,AMPL,WIDTH,NODE_NC ), DSE( 0,TRIG,AMPL,WIDTH,TYPE ), NULL, "DISCRETE_ONESHOT" ), |
| 4659 | | #define DISCRETE_ONESHOTR(NODE,RESET,TRIG,AMPL,WIDTH,TYPE) DSC_SND_ENTRY( NODE, DST_ONESHOT , 5, DSE( RESET,TRIG,AMPL,WIDTH,NODE_NC ), DSE( RESET,TRIG,AMPL,WIDTH,TYPE ), NULL, "One Shot Resetable" ), |
| 4660 | | #define DISCRETE_ONOFF(NODE,ENAB,INP0) DSC_SND_ENTRY( NODE, DST_GAIN , 3, DSE( ENAB,INP0,NODE_NC ), DSE( 0,1,0 ), NULL, "DISCRETE_ONOFF" ), |
| 4661 | | #define DISCRETE_RAMP(NODE,ENAB,RAMP,GRAD,START,END,CLAMP) DSC_SND_ENTRY( NODE, DST_RAMP , 6, DSE( ENAB,RAMP,GRAD,START,END,CLAMP ), DSE( ENAB,RAMP,GRAD,START,END,CLAMP ), NULL, "DISCRETE_RAMP" ), |
| 4662 | | #define DISCRETE_SAMPLHOLD(NODE,INP0,CLOCK,CLKTYPE) DSC_SND_ENTRY( NODE, DST_SAMPHOLD , 3, DSE( INP0,CLOCK,NODE_NC ), DSE( INP0,CLOCK,CLKTYPE ), NULL, "DISCRETE_SAMPLHOLD" ), |
| 4663 | | #define DISCRETE_SWITCH(NODE,ENAB,SWITCH,INP0,INP1) DSC_SND_ENTRY( NODE, DST_SWITCH , 4, DSE( ENAB,SWITCH,INP0,INP1 ), DSE( ENAB,SWITCH,INP0,INP1 ), NULL, "DISCRETE_SWITCH" ), |
| 4664 | | #define DISCRETE_ASWITCH(NODE,CTRL,INP,THRESHOLD) DSC_SND_ENTRY( NODE, DST_ASWITCH , 3, DSE( CTRL,INP,THRESHOLD ), DSE( CTRL,INP, THRESHOLD), NULL, "Analog Switch" ), |
| 4665 | | #define DISCRETE_TRANSFORM2(NODE,INP0,INP1,FUNCT) DSC_SND_ENTRY( NODE, DST_TRANSFORM , 2, DSE( INP0,INP1 ), DSE( INP0,INP1 ), FUNCT, "DISCRETE_TRANSFORM2" ), |
| 4666 | | #define DISCRETE_TRANSFORM3(NODE,INP0,INP1,INP2,FUNCT) DSC_SND_ENTRY( NODE, DST_TRANSFORM , 3, DSE( INP0,INP1,INP2 ), DSE( INP0,INP1,INP2 ), FUNCT, "DISCRETE_TRANSFORM3" ), |
| 4667 | | #define DISCRETE_TRANSFORM4(NODE,INP0,INP1,INP2,INP3,FUNCT) DSC_SND_ENTRY( NODE, DST_TRANSFORM , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ), FUNCT, "DISCRETE_TRANSFORM4" ), |
| 4668 | | #define DISCRETE_TRANSFORM5(NODE,INP0,INP1,INP2,INP3,INP4,FUNCT) DSC_SND_ENTRY( NODE, DST_TRANSFORM , 5, DSE( INP0,INP1,INP2,INP3,INP4 ), DSE( INP0,INP1,INP2,INP3,INP4 ), FUNCT, "DISCRETE_TRANSFORM5" ), |
| 4669 | | /* Component specific */ |
| 4670 | | #define DISCRETE_COMP_ADDER(NODE,DATA,TABLE) DSC_SND_ENTRY( NODE, DST_COMP_ADDER , 1, DSE( DATA ), DSE( DATA ), TABLE, "DISCRETE_COMP_ADDER" ), |
| 4671 | | #define DISCRETE_DAC_R1(NODE,DATA,VDATA,LADDER) DSC_SND_ENTRY( NODE, DST_DAC_R1 , 2, DSE( DATA,NODE_NC ), DSE( DATA,VDATA ), LADDER, "DISCRETE_DAC_R1" ), |
| 4672 | | #define DISCRETE_DIODE_MIXER2(NODE,IN0,IN1,TABLE) DSC_SND_ENTRY( NODE, DST_DIODE_MIX , 3, DSE( IN0,IN1 ), DSE( IN0,IN1 ), TABLE, "DISCRETE_DIODE_MIXER2" ), |
| 4673 | | #define DISCRETE_DIODE_MIXER3(NODE,IN0,IN1,IN2,TABLE) DSC_SND_ENTRY( NODE, DST_DIODE_MIX , 4, DSE( IN0,IN1,IN2 ), DSE( IN0,IN1,IN2 ), TABLE, "DISCRETE_DIODE_MIXER3" ), |
| 4674 | | #define DISCRETE_DIODE_MIXER4(NODE,IN0,IN1,IN2,IN3,TABLE) DSC_SND_ENTRY( NODE, DST_DIODE_MIX , 5, DSE( IN0,IN1,IN2,IN3 ), DSE( IN0,IN1,IN2,IN3 ), TABLE, "DISCRETE_DIODE_MIXER4" ), |
| 4675 | | #define DISCRETE_INTEGRATE(NODE,TRG0,TRG1,INFO) DSC_SND_ENTRY( NODE, DST_INTEGRATE , 2, DSE( TRG0,TRG1 ), DSE( TRG0,TRG1 ), INFO, "DISCRETE_INTEGRATE" ), |
| 4676 | | #define DISCRETE_MIXER2(NODE,ENAB,IN0,IN1,INFO) DSC_SND_ENTRY( NODE, DST_MIXER , 3, DSE( ENAB,IN0,IN1 ), DSE( ENAB,IN0,IN1 ), INFO, "DISCRETE_MIXER2" ), |
| 4677 | | #define DISCRETE_MIXER3(NODE,ENAB,IN0,IN1,IN2,INFO) DSC_SND_ENTRY( NODE, DST_MIXER , 4, DSE( ENAB,IN0,IN1,IN2 ), DSE( ENAB,IN0,IN1,IN2 ), INFO, "DISCRETE_MIXER3" ), |
| 4678 | | #define DISCRETE_MIXER4(NODE,ENAB,IN0,IN1,IN2,IN3,INFO) DSC_SND_ENTRY( NODE, DST_MIXER , 5, DSE( ENAB,IN0,IN1,IN2,IN3 ), DSE( ENAB,IN0,IN1,IN2,IN3 ), INFO, "DISCRETE_MIXER4" ), |
| 4679 | | #define DISCRETE_MIXER5(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,INFO) DSC_SND_ENTRY( NODE, DST_MIXER , 6, DSE( ENAB,IN0,IN1,IN2,IN3,IN4 ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4 ), INFO, "DISCRETE_MIXER5" ), |
| 4680 | | #define DISCRETE_MIXER6(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,INFO) DSC_SND_ENTRY( NODE, DST_MIXER , 7, DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5 ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5 ), INFO, "DISCRETE_MIXER6" ), |
| 4681 | | #define DISCRETE_MIXER7(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,INFO) DSC_SND_ENTRY( NODE, DST_MIXER , 8, DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), INFO, "DISCRETE_MIXER7" ), |
| 4682 | | #define DISCRETE_MIXER8(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,INFO) DSC_SND_ENTRY( NODE, DST_MIXER , 9, DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), INFO, "DISCRETE_MIXER8" ), |
| 4683 | | #define DISCRETE_OP_AMP(NODE,ENAB,IN0,IN1,INFO) DSC_SND_ENTRY( NODE, DST_OP_AMP , 3, DSE( ENAB,IN0,IN1 ), DSE( ENAB,IN0,IN1 ), INFO, "DISCRETE_OP_AMP" ), |
| 4684 | | #define DISCRETE_OP_AMP_ONESHOT(NODE,TRIG,INFO) DSC_SND_ENTRY( NODE, DST_OP_AMP_1SHT , 1, DSE( TRIG ), DSE( TRIG ), INFO, "DISCRETE_OP_AMP_ONESHOT" ), |
| 4685 | | #define DISCRETE_OP_AMP_TRIG_VCA(NODE,TRG0,TRG1,TRG2,IN0,IN1,INFO) DSC_SND_ENTRY( NODE, DST_TVCA_OP_AMP , 5, DSE( TRG0,TRG1,TRG2,IN0,IN1 ), DSE( TRG0,TRG1,TRG2,IN0,IN1 ), INFO, "DISCRETE_OP_AMP_TRIG_VCA" ), |
| 4686 | | #define DISCRETE_VCA(NODE,ENAB,IN0,CTRL,TYPE) DSC_SND_ENTRY( NODE, DST_VCA , 4, DSE( ENAB,IN0,CTRL,NODE_NC ), DSE( ENAB,IN0,CTRL,TYPE ), NULL, "DISCRETE_VCA" ), |
| 4687 | | #define DISCRETE_XTIME_BUFFER(NODE,IN0,LOW,HIGH) DSC_SND_ENTRY( NODE, DST_XTIME_BUFFER, 4, DSE( IN0,LOW,HIGH,NODE_NC ), DSE( IN0,LOW,HIGH,0 ), NULL, "DISCRETE_XTIME_BUFFER" ), |
| 4688 | | #define DISCRETE_XTIME_INVERTER(NODE,IN0,LOW,HIGH) DSC_SND_ENTRY( NODE, DST_XTIME_BUFFER, 4, DSE( IN0,LOW,HIGH,NODE_NC ), DSE( IN0,LOW,HIGH,1 ), NULL, "DISCRETE_XTIME_INVERTER" ), |
| 4689 | | #define DISCRETE_XTIME_AND(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, DST_XTIME_AND, 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), NULL, "DISCRETE_XTIME_AND" ), |
| 4690 | | #define DISCRETE_XTIME_NAND(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, DST_XTIME_AND, 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), NULL, "DISCRETE_XTIME_NAND" ), |
| 4691 | | #define DISCRETE_XTIME_OR(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, DST_XTIME_OR, 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), NULL, "DISCRETE_XTIME_OR" ), |
| 4692 | | #define DISCRETE_XTIME_NOR(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, DST_XTIME_OR, 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), NULL, "DISCRETE_XTIME_NOR" ), |
| 4693 | | #define DISCRETE_XTIME_XOR(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, DST_XTIME_XOR, 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), NULL, "DISCRETE_XTIME_XOR" ), |
| 4694 | | #define DISCRETE_XTIME_XNOR(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, DST_XTIME_XNOR, 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), NULL, "DISCRETE_XTIME_XNOR" ), |
| 4306 | virtual void set_output(stream_sample_t *ptr) = 0; |
| 4307 | }; |
| 4695 | 4308 | |
| 4696 | | /* from disc_flt.c */ |
| 4697 | | /* generic modules */ |
| 4698 | | #define DISCRETE_FILTER1(NODE,ENAB,INP0,FREQ,TYPE) DSC_SND_ENTRY( NODE, DST_FILTER1 , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,FREQ,TYPE ), NULL, "DISCRETE_FILTER1" ), |
| 4699 | | #define DISCRETE_FILTER2(NODE,ENAB,INP0,FREQ,DAMP,TYPE) DSC_SND_ENTRY( NODE, DST_FILTER2 , 5, DSE( ENAB,INP0,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,FREQ,DAMP,TYPE ), NULL, "DISCRETE_FILTER2" ), |
| 4700 | | /* Component specific */ |
| 4701 | | #define DISCRETE_SALLEN_KEY_FILTER(NODE,ENAB,INP0,TYPE,INFO) DSC_SND_ENTRY( NODE, DST_SALLEN_KEY , 3, DSE( ENAB,INP0,NODE_NC ), DSE( ENAB,INP0,TYPE ), INFO, "DISCRETE_SALLEN_KEY_FILTER" ), |
| 4702 | | #define DISCRETE_CRFILTER(NODE,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, DST_CRFILTER , 4, DSE( INP0,RVAL,CVAL ), DSE( INP0,RVAL,CVAL ), NULL, "DISCRETE_CRFILTER" ), |
| 4703 | | #define DISCRETE_CRFILTER_VREF(NODE,INP0,RVAL,CVAL,VREF) DSC_SND_ENTRY( NODE, DST_CRFILTER , 5, DSE( INP0,RVAL,CVAL,VREF ), DSE( INP0,RVAL,CVAL,VREF ), NULL, "DISCRETE_CRFILTER_VREF" ), |
| 4704 | | #define DISCRETE_OP_AMP_FILTER(NODE,ENAB,INP0,INP1,TYPE,INFO) DSC_SND_ENTRY( NODE, DST_OP_AMP_FILT , 4, DSE( ENAB,INP0,INP1,NODE_NC ), DSE( ENAB,INP0,INP1,TYPE ), INFO, "DISCRETE_OP_AMP_FILTER" ), |
| 4705 | | #define DISCRETE_RC_CIRCUIT_1(NODE,INP0,INP1,RVAL,CVAL) DSC_SND_ENTRY( NODE, DST_RC_CIRCUIT_1, 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,RVAL,CVAL ), NULL, "DISCRETE_RC_CIRCUIT_1" ), |
| 4706 | | #define DISCRETE_RCDISC(NODE,ENAB,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, DST_RCDISC , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), NULL, "DISCRETE_RCDISC" ), |
| 4707 | | #define DISCRETE_RCDISC2(NODE,SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL) DSC_SND_ENTRY( NODE, DST_RCDISC2 , 6, DSE( SWITCH,INP0,NODE_NC,INP1,NODE_NC,NODE_NC ), DSE( SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL ), NULL, "DISCRETE_RCDISC2" ), |
| 4708 | | #define DISCRETE_RCDISC3(NODE,ENAB,INP0,RVAL0,RVAL1,CVAL,DJV) DSC_SND_ENTRY( NODE, DST_RCDISC3 , 6, DSE( ENAB,INP0,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL0,RVAL1,CVAL,DJV ), NULL, "DISCRETE_RCDISC3" ), |
| 4709 | | #define DISCRETE_RCDISC4(NODE,ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,VP,TYPE) DSC_SND_ENTRY( NODE, DST_RCDISC4 , 8, DSE( ENAB,INP0,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,VP,TYPE ), NULL, "DISCRETE_RCDISC4" ), |
| 4710 | | #define DISCRETE_RCDISC5(NODE,ENAB,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, DST_RCDISC5 , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), NULL, "DISCRETE_RCDISC5" ), |
| 4711 | | #define DISCRETE_RCDISC_MODULATED(NODE,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP) DSC_SND_ENTRY( NODE, DST_RCDISC_MOD, 8, DSE( INP0,INP1,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP ), NULL, "DISCRETE_RCDISC_MODULATED" ), |
| 4712 | | #define DISCRETE_RCFILTER(NODE,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, DST_RCFILTER , 3, DSE( INP0,RVAL,CVAL ), DSE( INP0,RVAL,CVAL ), NULL, "DISCRETE_RCFILTER" ), |
| 4713 | | #define DISCRETE_RCFILTER_VREF(NODE,INP0,RVAL,CVAL,VREF) DSC_SND_ENTRY( NODE, DST_RCFILTER , 4, DSE( INP0,RVAL,CVAL,VREF ), DSE( INP0,RVAL,CVAL,VREF ), NULL, "DISCRETE_RCFILTER_VREF" ), |
| 4714 | | #define DISCRETE_RCFILTER_SW(NODE,ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4) DSC_SND_ENTRY( NODE, DST_RCFILTER_SW, 8, DSE( ENAB,INP0,SW,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4 ), NULL, "DISCRETE_RCFILTER_SW" ), |
| 4715 | | #define DISCRETE_RCINTEGRATE(NODE,INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE) DSC_SND_ENTRY( NODE, DST_RCINTEGRATE , 7, DSE( INP0,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE ), NULL, "DISCRETE_RCINTEGRATE" ), |
| 4716 | | /* For testing - seem to be buggered. Use versions not ending in N. */ |
| 4717 | | #define DISCRETE_RCDISCN(NODE,ENAB,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, DST_RCDISCN , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), NULL, "DISCRETE_RCDISCN" ), |
| 4718 | | #define DISCRETE_RCDISC2N(NODE,SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL) DSC_SND_ENTRY( NODE, DST_RCDISC2N , 6, DSE( SWITCH,INP0,NODE_NC,INP1,NODE_NC,NODE_NC ), DSE( SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL ), NULL, "DISCRETE_RCDISC2N" ), |
| 4719 | | #define DISCRETE_RCFILTERN(NODE,ENAB,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, DST_RCFILTERN , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), NULL, "DISCRETE_RCFILTERN" ), |
| 4720 | 4309 | |
| 4721 | | /* from disc_dev.c */ |
| 4722 | | /* generic modules */ |
| 4723 | | #define DISCRETE_CUSTOM1(NODE,IN0,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 1, DSE( IN0 ), DSE( IN0 ), INFO, "DISCRETE_CUSTOM1" ), |
| 4724 | | #define DISCRETE_CUSTOM2(NODE,IN0,IN1,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 2, DSE( IN0,IN1 ), DSE( IN0,IN1 ), INFO, "DISCRETE_CUSTOM2" ), |
| 4725 | | #define DISCRETE_CUSTOM3(NODE,IN0,IN1,IN2,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 3, DSE( IN0,IN1,IN2 ), DSE( IN0,IN1,IN2 ), INFO, "DISCRETE_CUSTOM3" ), |
| 4726 | | #define DISCRETE_CUSTOM4(NODE,IN0,IN1,IN2,IN3,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 4, DSE( IN0,IN1,IN2,IN3 ), DSE( IN0,IN1,IN2,IN3 ), INFO, "DISCRETE_CUSTOM4" ), |
| 4727 | | #define DISCRETE_CUSTOM5(NODE,IN0,IN1,IN2,IN3,IN4,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 5, DSE( IN0,IN1,IN2,IN3,IN4 ), DSE( IN0,IN1,IN2,IN3,IN4 ), INFO, "DISCRETE_CUSTOM5" ), |
| 4728 | | #define DISCRETE_CUSTOM6(NODE,IN0,IN1,IN2,IN3,IN4,IN5,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 6, DSE( IN0,IN1,IN2,IN3,IN4,IN5 ), DSE( IN0,IN1,IN2,IN3,IN4,IN5 ), INFO, "DISCRETE_CUSTOM6" ), |
| 4729 | | #define DISCRETE_CUSTOM7(NODE,IN0,IN1,IN2,IN3,IN4,IN5,IN6,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 7, DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), INFO, "DISCRETE_CUSTOM7" ), |
| 4730 | | #define DISCRETE_CUSTOM8(NODE,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 8, DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), INFO, "DISCRETE_CUSTOM8" ), |
| 4731 | | #define DISCRETE_CUSTOM9(NODE,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8,INFO) DSC_SND_ENTRY( NODE, DST_CUSTOM , 9, DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8 ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8 ), INFO, "DISCRETE_CUSTOM9" ), |
| 4732 | | /* Component specific */ |
| 4733 | | #define DISCRETE_555_ASTABLE(NODE,RESET,R1,R2,C,OPTIONS) DSC_SND_ENTRY( NODE, DSD_555_ASTBL , 5, DSE( RESET,R1,R2,C,NODE_NC ), DSE( RESET,R1,R2,C,-1 ), OPTIONS, "DISCRETE_555_ASTABLE" ), |
| 4734 | | #define DISCRETE_555_ASTABLE_CV(NODE,RESET,R1,R2,C,CTRLV,OPTIONS) DSC_SND_ENTRY( NODE, DSD_555_ASTBL , 5, DSE( RESET,R1,R2,C,CTRLV ), DSE( RESET,R1,R2,C,CTRLV ), OPTIONS, "DISCRETE_555_ASTABLE_CV" ), |
| 4735 | | #define DISCRETE_555_MSTABLE(NODE,RESET,TRIG,R,C,OPTIONS) DSC_SND_ENTRY( NODE, DSD_555_MSTBL , 4, DSE( RESET,TRIG,R,C ), DSE( RESET,TRIG,R,C ), OPTIONS, "DISCRETE_555_MSTABLE" ), |
| 4736 | | #define DISCRETE_555_CC(NODE,RESET,VIN,R,C,RBIAS,RGND,RDIS,OPTIONS) DSC_SND_ENTRY( NODE, DSD_555_CC , 7, DSE( RESET,VIN,R,C,RBIAS,RGND,RDIS ), DSE( RESET,VIN,R,C,RBIAS,RGND,RDIS ), OPTIONS, "DISCRETE_555_CC" ), |
| 4737 | | #define DISCRETE_555_VCO1(NODE,RESET,VIN,OPTIONS) DSC_SND_ENTRY( NODE, DSD_555_VCO1 , 3, DSE( RESET,VIN,NODE_NC ), DSE( RESET,VIN,-1 ), OPTIONS, "DISCRETE_555_VCO1" ), |
| 4738 | | #define DISCRETE_555_VCO1_CV(NODE,RESET,VIN,CTRLV,OPTIONS) DSC_SND_ENTRY( NODE, DSD_555_VCO1 , 3, DSE( RESET,VIN,CTRLV ), DSE( RESET,VIN,CTRLV ), OPTIONS, "DISCRETE_555_VCO1_CV" ), |
| 4739 | | #define DISCRETE_566(NODE,VMOD,R,C,VPOS,VNEG,VCHARGE,OPTIONS) DSC_SND_ENTRY( NODE, DSD_566 , 7, DSE( VMOD,R,C,NODE_NC,NODE_NC,VCHARGE,NODE_NC ), DSE( VMOD,R,C,VPOS,VNEG,VCHARGE,OPTIONS ), NULL, "DISCRETE_566" ), |
| 4740 | | #define DISCRETE_74LS624(NODE,ENAB,VMOD,VRNG,C,R_FREQ_IN,C_FREQ_IN,R_RNG_IN,OUTTYPE) DSC_SND_ENTRY( NODE, DSD_LS624 , 8, DSE( ENAB,VMOD,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,VMOD,VRNG,C,R_FREQ_IN,C_FREQ_IN,R_RNG_IN,OUTTYPE ), NULL, "DISCRETE_74LS624" ), |
| 4741 | | |
| 4742 | | /* NOP */ |
| 4743 | | #define DISCRETE_NOP(NODE) DSC_SND_ENTRY( NODE, DSS_NOP , 0, DSE( 0 ), DSE( 0 ), NULL, "DISCRETE_NOP" ), |
| 4744 | | |
| 4745 | | /* logging */ |
| 4746 | | #define DISCRETE_CSVLOG1(NODE1) DSC_SND_ENTRY( NODE_SPECIAL, DSO_CSVLOG , 1, DSE( NODE1 ), DSE( NODE1 ), NULL, "DISCRETE_CSVLOG1" ), |
| 4747 | | #define DISCRETE_CSVLOG2(NODE1,NODE2) DSC_SND_ENTRY( NODE_SPECIAL, DSO_CSVLOG , 2, DSE( NODE1,NODE2 ), DSE( NODE1,NODE2 ), NULL, "DISCRETE_CSVLOG2" ), |
| 4748 | | #define DISCRETE_CSVLOG3(NODE1,NODE2,NODE3) DSC_SND_ENTRY( NODE_SPECIAL, DSO_CSVLOG , 3, DSE( NODE1,NODE2,NODE3 ), DSE( NODE1,NODE2,NODE3 ), NULL, "DISCRETE_CSVLOG3" ), |
| 4749 | | #define DISCRETE_CSVLOG4(NODE1,NODE2,NODE3,NODE4) DSC_SND_ENTRY( NODE_SPECIAL, DSO_CSVLOG , 4, DSE( NODE1,NODE2,NODE3,NODE4 ), DSE( NODE1,NODE2,NODE3,NODE4 ), NULL, "DISCRETE_CSVLOG4" ), |
| 4750 | | #define DISCRETE_CSVLOG5(NODE1,NODE2,NODE3,NODE4,NODE5) DSC_SND_ENTRY( NODE_SPECIAL, DSO_CSVLOG , 5, DSE( NODE1,NODE2,NODE3,NODE4,NODE5 ), DSE( NODE1,NODE2,NODE3,NODE4,NODE5 ), NULL, "DISCRETE_CSVLOG5" ), |
| 4751 | | #define DISCRETE_WAVLOG1(NODE1,GAIN1) DSC_SND_ENTRY( NODE_SPECIAL, DSO_WAVELOG , 2, DSE( NODE1,NODE_NC ), DSE( NODE1,GAIN1 ), NULL, "DISCRETE_WAVLOG1" ), |
| 4752 | | #define DISCRETE_WAVLOG2(NODE1,GAIN1,NODE2,GAIN2) DSC_SND_ENTRY( NODE_SPECIAL, DSO_WAVELOG , 4, DSE( NODE1,NODE_NC,NODE2,NODE_NC ), DSE( NODE1,GAIN1,NODE2,GAIN2 ), NULL, "DISCRETE_WAVLOG2" ), |
| 4753 | | |
| 4754 | | /* import */ |
| 4755 | | #define DISCRETE_IMPORT(INFO) DSC_SND_ENTRY( NODE_SPECIAL, DSO_IMPORT , 0, DSE( 0 ), DSE( 0 ), &(INFO##_discrete_interface), "DISCRETE_IMPORT" ), |
| 4756 | | #define DISCRETE_DELETE(NODE_FROM, NODE_TO) DSC_SND_ENTRY( NODE_SPECIAL, DSO_DELETE , 2, DSE( NODE_FROM, NODE_TO ), DSE( NODE_FROM, NODE_TO ), NULL, "DISCRETE_DELETE" ), |
| 4757 | | #define DISCRETE_REPLACE DSC_SND_ENTRY( NODE_SPECIAL, DSO_REPLACE , 0, DSE( 0 ), DSE( 0 ), NULL, "DISCRETE_REPLACE" ), |
| 4758 | | |
| 4759 | | /* parallel tasks */ |
| 4760 | | |
| 4761 | | #define DISCRETE_TASK_START(TASK_GROUP) DSC_SND_ENTRY( NODE_SPECIAL, DSO_TASK_START,1, DSE( NODE_NC, NODE_NC ), DSE( TASK_GROUP, 0 ), NULL, "DISCRETE_TASK_START" ), |
| 4762 | | #define DISCRETE_TASK_END() DSC_SND_ENTRY( NODE_SPECIAL, DSO_TASK_END , 1, DSE( 0 ), DSE( 0 ), NULL, "DISCRETE_TASK_END" ), |
| 4763 | | //#define DISCRETE_TASK_SYNC() DSC_SND_ENTRY( NODE_SPECIAL, DSO_TASK_SYNC, 0, DSE( 0 ), DSE( 0 ), NULL, "DISCRETE_TASK_SYNC" ), |
| 4764 | | |
| 4765 | | /* output */ |
| 4766 | | #define DISCRETE_OUTPUT(OPNODE,GAIN) DSC_SND_ENTRY( NODE_SPECIAL, DSO_OUTPUT , 2, DSE( OPNODE,NODE_NC ), DSE( 0,GAIN ), NULL, "DISCRETE_OUTPUT" ), |
| 4767 | | |
| 4768 | | |
| 4769 | 4310 | /************************************* |
| 4770 | 4311 | * |
| 4771 | 4312 | * Interface to the external world |
| r10048 | r10049 | |
| 4778 | 4319 | //************************************************************************** |
| 4779 | 4320 | // INTERFACE CONFIGURATION MACROS |
| 4780 | 4321 | //************************************************************************** |
| 4781 | | //FIXME: Later |
| 4782 | | #if 0 |
| 4783 | | #define MCFG_DISCRETE_ADD(_tag, _clock, _type, _irqf) \ |
| 4784 | | MCFG_DEVICE_ADD(_tag, ASC, _clock) \ |
| 4785 | | MCFG_DISCRETE_TYPE(_type) \ |
| 4786 | | MCFG_IRQ_FUNC(_irqf) |
| 4787 | 4322 | |
| 4788 | | #define MCFG_DISCRETE_REPLACE(_tag, _clock, _type, _irqf) \ |
| 4789 | | MCFG_DEVICE_REPLACE(_tag, ASC, _clock) \ |
| 4790 | | MCFG_DISCRETE_TYPE(_type) \ |
| 4791 | | MCFG_IRQ_FUNC(_irqf) |
| 4323 | #define MCFG_DISCRETE_ADD(_tag, _clock, _intf) \ |
| 4324 | MCFG_DEVICE_ADD(_tag, DISCRETE, _clock) \ |
| 4325 | MCFG_DISCRETE_INTF(_intf) |
| 4792 | 4326 | |
| 4793 | | #define MCFG_DISCRETE_TYPE(_type) \ |
| 4794 | | DISCRETE_device_config::static_set_type(device, _type); \ |
| 4327 | #define MCFG_DISCRETE_REPLACE(_tag, _clock, _intf) \ |
| 4328 | MCFG_DEVICE_REPLACE(_tag, DISCRETE, _clock) \ |
| 4329 | MCFG_DISCRETE_INTF(_intf) |
| 4795 | 4330 | |
| 4796 | | #define MCFG_IRQ_FUNC(_irqf) \ |
| 4797 | | DISCRETE_device_config::static_set_irqf(device, _irqf); \ |
| 4331 | #define MCFG_DISCRETE_INTF(_intf) \ |
| 4332 | discrete_device_config::static_set_intf(device, (const discrete_sound_block *)&(_intf##_discrete_interface)); \ |
| 4798 | 4333 | |
| 4799 | | #endif |
| 4800 | 4334 | |
| 4335 | #define MCFG_SOUND_CONFIG_DISCRETE(name) MCFG_SOUND_CONFIG(name##_discrete_interface) |
| 4336 | |
| 4801 | 4337 | //************************************************************************** |
| 4802 | 4338 | // TYPE DEFINITIONS |
| 4803 | 4339 | //************************************************************************** |
| r10048 | r10049 | |
| 4817 | 4353 | virtual device_t *alloc_device(running_machine &machine) const; |
| 4818 | 4354 | |
| 4819 | 4355 | // inline configuration helpers |
| 4820 | | //static void static_set_type(device_config *device, int type); |
| 4821 | | //static void static_set_irqf(device_config *device, void (*irqf)(device_t *device, int state)); |
| 4356 | static void static_set_intf(device_config *device, const discrete_sound_block *intf); |
| 4822 | 4357 | |
| 4823 | 4358 | protected: |
| 4359 | const discrete_sound_block *m_intf; |
| 4824 | 4360 | // inline data |
| 4825 | 4361 | }; |
| 4826 | 4362 | |
| 4363 | class discrete_output_interface; |
| 4364 | typedef linked_list_t<discrete_output_interface *> node_output_list_t; |
| 4827 | 4365 | |
| 4828 | 4366 | |
| 4829 | 4367 | // ======================> discrete_device |
| r10048 | r10049 | |
| 4831 | 4369 | class discrete_device : public device_t, public device_sound_interface |
| 4832 | 4370 | { |
| 4833 | 4371 | friend class discrete_device_config; |
| 4372 | friend class discrete_base_node; |
| 4373 | friend class discrete_dss_input_stream_node; |
| 4834 | 4374 | |
| 4835 | 4375 | // construction/destruction |
| 4836 | 4376 | discrete_device(running_machine &_machine, const discrete_device_config &config); |
| r10048 | r10049 | |
| 4841 | 4381 | //sound_stream *m_stream; |
| 4842 | 4382 | virtual ~discrete_device(void); |
| 4843 | 4383 | |
| 4384 | /* --------------------------------- */ |
| 4385 | void CLIB_DECL ATTR_PRINTF(2,3) discrete_log(const char *text, ...) const; |
| 4386 | discrete_base_node *discrete_find_node(int node); |
| 4387 | /* FIXME: this is used by csv and wav logs - going forward, identifiers should be explicitly passed */ |
| 4388 | int same_module_index(discrete_base_node &node); |
| 4389 | inline int profiling(void) { return m_profiling; } |
| 4390 | void update(void) { stream_update(m_stream); } |
| 4391 | |
| 4392 | /* FIXME: theses should be protected */ |
| 4393 | /* tasks */ |
| 4394 | task_list_t task_list; /* discrete_task_context * */ |
| 4395 | /* the input streams */ |
| 4396 | input_stream_node_list_t m_input_stream_list; |
| 4397 | |
| 4398 | |
| 4844 | 4399 | protected: |
| 4845 | 4400 | |
| 4846 | 4401 | // device-level overrides |
| r10048 | r10049 | |
| 4854 | 4409 | // internal state |
| 4855 | 4410 | const discrete_device_config &m_config; |
| 4856 | 4411 | |
| 4857 | | /* all for now */ |
| 4858 | | discrete_info m_info; |
| 4412 | /* --------------------------------- */ |
| 4859 | 4413 | |
| 4414 | /* the output stream */ |
| 4415 | sound_stream *m_stream; |
| 4416 | |
| 4417 | /* emulation info */ |
| 4418 | int m_sample_rate; |
| 4419 | double m_sample_time; |
| 4420 | double m_neg_sample_time; |
| 4421 | |
| 4422 | |
| 4860 | 4423 | private: |
| 4424 | void discrete_build_list(const discrete_sound_block *intf, linked_list_entry ***current); |
| 4425 | void discrete_sanity_check(void); |
| 4426 | void display_profiling(void); |
| 4427 | void init_nodes(const linked_list_entry *block_list); |
| 4861 | 4428 | |
| 4429 | /* internal node tracking */ |
| 4430 | discrete_base_node **m_indexed_node; |
| 4862 | 4431 | |
| 4863 | | }; |
| 4432 | /* list of all nodes */ |
| 4433 | node_list_t m_node_list; /* node_description * */ |
| 4864 | 4434 | |
| 4435 | /* list of discrete blocks after prescan (IMPORT, DELETE, REPLACE) */ |
| 4436 | linked_list_entry *m_block_list; /* discrete_sound_block * */ |
| 4865 | 4437 | |
| 4438 | /* output node tracking */ |
| 4439 | node_output_list_t m_output_list; |
| 4440 | |
| 4441 | /* debugging statistics */ |
| 4442 | FILE *m_disclogfile; |
| 4443 | |
| 4444 | /* parallel tasks */ |
| 4445 | osd_work_queue *m_queue; |
| 4446 | |
| 4447 | /* profiling */ |
| 4448 | int m_profiling; |
| 4449 | UINT64 m_total_samples; |
| 4450 | UINT64 m_total_stream_updates; |
| 4451 | |
| 4452 | }; |
| 4453 | |
| 4866 | 4454 | // device type definition |
| 4867 | 4455 | extern const device_type DISCRETE; |
| 4868 | 4456 | |
| 4457 | /************************************* |
| 4458 | * |
| 4459 | * Node class |
| 4460 | * |
| 4461 | *************************************/ |
| 4869 | 4462 | |
| 4870 | | //DECLARE_LEGACY_SOUND_DEVICE(DISCRETE, discrete); |
| 4463 | class discrete_base_node |
| 4464 | { |
| 4465 | friend class discrete_device; |
| 4466 | template <class C> friend class discrete_node_factory; |
| 4467 | friend class discrete_task; |
| 4871 | 4468 | |
| 4469 | public: |
| 4470 | |
| 4471 | virtual void reset(void) { } |
| 4472 | virtual void start(void); |
| 4473 | virtual void stop(void) { } |
| 4474 | |
| 4475 | inline bool interface(discrete_step_interface *&intf) { intf = m_step_intf; return (intf != NULL); } |
| 4476 | inline bool interface(discrete_input_interface *&intf) { intf = m_input_intf; return (intf != NULL); } |
| 4477 | inline bool interface(discrete_output_interface *&intf) { intf = m_output_intf; return (intf != NULL); } |
| 4478 | |
| 4479 | virtual int max_output(void) { return 1; }; |
| 4480 | |
| 4481 | /* Return the node index, i.e. X from NODE(X) */ |
| 4482 | int index(void); |
| 4483 | /* Return the node number, i.e. NODE(X) */ |
| 4484 | inline int block_node(void) { return m_block->node; } |
| 4485 | /* Custom function specific initialisation data */ |
| 4486 | inline const void *custom_data(void) { return m_custom; } |
| 4487 | |
| 4488 | void find_input_nodes(void); |
| 4489 | void save_state(device_t *device); |
| 4490 | |
| 4491 | inline int input_node(int inputnum) { return m_block->input_node[inputnum]; } |
| 4492 | |
| 4493 | /* The node's last output value */ |
| 4494 | double output[DISCRETE_MAX_OUTPUTS]; |
| 4495 | |
| 4496 | const double * input[DISCRETE_MAX_INPUTS]; /* Addresses of Input values */ |
| 4497 | |
| 4498 | /* Number of active inputs on this node type */ |
| 4499 | inline int active_inputs(void) { return m_active_inputs; } |
| 4500 | /* Bit Flags. 1 in bit location means input_is_node */ |
| 4501 | inline int input_is_node(void) { return m_input_is_node; }; |
| 4502 | |
| 4503 | inline double sample_time(void) { return device->m_sample_time; } |
| 4504 | inline int sample_rate(void) { return device->m_sample_rate; } |
| 4505 | |
| 4506 | const char * module_name(void) { return m_block->mod_name; } |
| 4507 | inline int module_type(void) { return m_block->type; } |
| 4508 | |
| 4509 | discrete_device *device; /* Points to the parent */ |
| 4510 | |
| 4511 | protected: |
| 4512 | |
| 4513 | discrete_base_node(); |
| 4514 | virtual ~discrete_base_node(); |
| 4515 | |
| 4516 | |
| 4517 | /* finish node setup after allocation is complete */ |
| 4518 | void init(discrete_device * pdev, const discrete_sound_block *block); |
| 4519 | |
| 4520 | private: |
| 4521 | const discrete_sound_block *m_block; /* Points to the node's setup block. */ |
| 4522 | int m_active_inputs; /* Number of active inputs on this node type */ |
| 4523 | /* Custom function specific initialisation data */ |
| 4524 | const void * m_custom; |
| 4525 | int m_input_is_node; |
| 4526 | discrete_step_interface *m_step_intf; |
| 4527 | discrete_input_interface *m_input_intf; |
| 4528 | discrete_output_interface *m_output_intf; |
| 4529 | }; |
| 4530 | |
| 4531 | class discrete_node_base_factory |
| 4532 | { |
| 4533 | public: |
| 4534 | virtual discrete_base_node *Create(discrete_device * pdev, const discrete_sound_block *block) = 0; |
| 4535 | virtual ~discrete_node_base_factory() {} |
| 4536 | }; |
| 4537 | |
| 4538 | template <class C> |
| 4539 | class discrete_node_factory : public discrete_node_base_factory |
| 4540 | { |
| 4541 | discrete_base_node *Create(discrete_device * pdev, const discrete_sound_block *block); |
| 4542 | }; |
| 4543 | |
| 4544 | template <class C> |
| 4545 | discrete_base_node * discrete_node_factory<C>::Create(discrete_device * pdev, const discrete_sound_block *block) |
| 4546 | { |
| 4547 | discrete_base_node *r = auto_alloc_clear(pdev->machine, C); |
| 4548 | |
| 4549 | r->init(pdev, block); |
| 4550 | return r; |
| 4551 | } |
| 4552 | |
| 4553 | /************************************* |
| 4554 | * |
| 4555 | * Class definitions for nodes |
| 4556 | * |
| 4557 | *************************************/ |
| 4558 | |
| 4559 | #include "disc_cls.h" |
| 4560 | |
| 4561 | /************************************* |
| 4562 | * |
| 4563 | * Encapsulation macros for defining |
| 4564 | * your simulation |
| 4565 | * |
| 4566 | *************************************/ |
| 4567 | |
| 4568 | #define DISCRETE_SOUND_EXTERN(name) extern const discrete_sound_block name##_discrete_interface[] |
| 4569 | #define DISCRETE_SOUND_START(name) const discrete_sound_block name##_discrete_interface[] = { |
| 4570 | |
| 4571 | #define DSC_SND_ENTRY(_nod, _class, _dss, _num, _iact, _iinit, _custom, _name) { _nod, new discrete_node_factory< DISCRETE_CLASS_NAME(_class) >, _dss, _num, _iact, _iinit, _custom, _name, # _class } |
| 4572 | |
| 4573 | |
| 4574 | #define DISCRETE_SOUND_END DSC_SND_ENTRY( NODE_00, special, DSS_NULL , 0, DSE( NODE_NC ), DSE( 0 ) ,NULL ,"DISCRETE_SOUND_END" ) }; |
| 4575 | #define DSE( ... ) { __VA_ARGS__ } |
| 4576 | |
| 4577 | /* Module Name out, enum value, #in, {variable inputs}, {static inputs}, data pointer, "name" */ |
| 4578 | |
| 4579 | /* from disc_inp.c */ |
| 4580 | #define DISCRETE_ADJUSTMENT(NODE,MIN,MAX,LOGLIN,TAG) DSC_SND_ENTRY( NODE, dss_adjustment , DSS_NODE , 7, DSE( NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( MIN,MAX,LOGLIN,0 ,0 ,100 ), TAG , "DISCRETE_ADJUSTMENT" ), |
| 4581 | #define DISCRETE_ADJUSTMENTX(NODE,MIN,MAX,LOGLIN,TAG,PMIN,PMAX) DSC_SND_ENTRY( NODE, dss_adjustment , DSS_NODE , 7, DSE( NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( MIN,MAX,LOGLIN,0 ,PMIN,PMAX ), TAG , "DISCRETE_ADJUSTMENTX" ), |
| 4582 | #define DISCRETE_CONSTANT(NODE,CONST) DSC_SND_ENTRY( NODE, dss_constant , DSS_NODE , 1, DSE( NODE_NC ), DSE( CONST ) ,NULL ,"DISCRETE_CONSTANT" ), |
| 4583 | #define DISCRETE_INPUT_DATA(NODE) DSC_SND_ENTRY( NODE, dss_input_data , DSS_NODE , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), NULL, "DISCRETE_INPUT_DATA" ), |
| 4584 | #define DISCRETE_INPUTX_DATA(NODE,GAIN,OFFSET,INIT) DSC_SND_ENTRY( NODE, dss_input_data , DSS_NODE , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), NULL, "DISCRETE_INPUTX_DATA" ), |
| 4585 | #define DISCRETE_INPUT_LOGIC(NODE) DSC_SND_ENTRY( NODE, dss_input_logic , DSS_NODE , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), NULL, "DISCRETE_INPUT_LOGIC" ), |
| 4586 | #define DISCRETE_INPUTX_LOGIC(NODE,GAIN,OFFSET,INIT) DSC_SND_ENTRY( NODE, dss_input_logic , DSS_NODE , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), NULL, "DISCRETE_INPUTX_LOGIC" ), |
| 4587 | #define DISCRETE_INPUT_NOT(NODE) DSC_SND_ENTRY( NODE, dss_input_not , DSS_NODE , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), NULL, "DISCRETE_INPUT_NOT" ), |
| 4588 | #define DISCRETE_INPUTX_NOT(NODE,GAIN,OFFSET,INIT) DSC_SND_ENTRY( NODE, dss_input_not , DSS_NODE , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), NULL, "DISCRETE_INPUTX_NOT" ), |
| 4589 | #define DISCRETE_INPUT_PULSE(NODE,INIT) DSC_SND_ENTRY( NODE, dss_input_pulse , DSS_NODE , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,INIT ), NULL, "DISCRETE_INPUT_PULSE" ), |
| 4590 | |
| 4591 | #define DISCRETE_INPUT_STREAM(NODE, NUM) DSC_SND_ENTRY( NODE, dss_input_stream, DSS_NODE , 3, DSE( NUM,NODE_NC,NODE_NC ), DSE( NUM,1,0 ), NULL, "DISCRETE_INPUT_STREAM" ), |
| 4592 | #define DISCRETE_INPUTX_STREAM(NODE, NUM, GAIN,OFFSET) DSC_SND_ENTRY( NODE, dss_input_stream, DSS_NODE , 3, DSE( NUM,NODE_NC,NODE_NC ), DSE( NUM,GAIN,OFFSET ), NULL, "DISCRETE_INPUTX_STREAM" ), |
| 4593 | |
| 4594 | #define DISCRETE_INPUT_BUFFER(NODE, NUM) DSC_SND_ENTRY( NODE, dss_input_buffer, DSS_NODE , 3, DSE( NUM,NODE_NC,NODE_NC ), DSE( NUM,1,0 ), NULL, "DISCRETE_INPUT_BUFFER" ), |
| 4595 | |
| 4596 | /* from disc_wav.c */ |
| 4597 | /* generic modules */ |
| 4598 | #define DISCRETE_COUNTER(NODE,ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE) DSC_SND_ENTRY( NODE, dss_counter , DSS_NODE , 8, DSE( ENAB,RESET,CLK,NODE_NC,NODE_NC,DIR,INIT0,NODE_NC ), DSE( ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE ), NULL, "DISCRETE_COUNTER" ), |
| 4599 | #define DISCRETE_COUNTER_7492(NODE,ENAB,RESET,CLK,CLKTYPE) DSC_SND_ENTRY( NODE, dss_counter , DSS_NODE , 8, DSE( ENAB,RESET,CLK,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,RESET,CLK,CLKTYPE,0,1,0,DISC_COUNTER_IS_7492 ), NULL, "DISCRETE_COUNTER_7492" ), |
| 4600 | #define DISCRETE_LFSR_NOISE(NODE,ENAB,RESET,CLK,AMPL,FEED,BIAS,LFSRTB) DSC_SND_ENTRY( NODE, dss_lfsr_noise , DSS_NODE , 6, DSE( ENAB,RESET,CLK,AMPL,FEED,BIAS ), DSE( ENAB,RESET,CLK,AMPL,FEED,BIAS ), LFSRTB, "DISCRETE_LFSR_NOISE" ), |
| 4601 | #define DISCRETE_NOISE(NODE,ENAB,FREQ,AMPL,BIAS) DSC_SND_ENTRY( NODE, dss_noise , DSS_NODE , 4, DSE( ENAB,FREQ,AMPL,BIAS ), DSE( ENAB,FREQ,AMPL,BIAS ), NULL, "DISCRETE_NOISE" ), |
| 4602 | #define DISCRETE_NOTE(NODE,ENAB,CLK,DATA,MAX1,MAX2,CLKTYPE) DSC_SND_ENTRY( NODE, dss_note , DSS_NODE , 6, DSE( ENAB,CLK,DATA,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,CLK,DATA,MAX1,MAX2,CLKTYPE ), NULL, "DISCRETE_NOTE" ), |
| 4603 | #define DISCRETE_SAWTOOTHWAVE(NODE,ENAB,FREQ,AMPL,BIAS,GRAD,PHASE) DSC_SND_ENTRY( NODE, dss_sawtoothwave, DSS_NODE , 6, DSE( ENAB,FREQ,AMPL,BIAS,NODE_NC,NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,GRAD,PHASE ), NULL, "DISCRETE_SAWTOOTHWAVE" ), |
| 4604 | #define DISCRETE_SINEWAVE(NODE,ENAB,FREQ,AMPL,BIAS,PHASE) DSC_SND_ENTRY( NODE, dss_sinewave , DSS_NODE , 5, DSE( ENAB,FREQ,AMPL,BIAS,NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,PHASE ), NULL, "DISCRETE_SINEWAVE" ), |
| 4605 | #define DISCRETE_SQUAREWAVE(NODE,ENAB,FREQ,AMPL,DUTY,BIAS,PHASE) DSC_SND_ENTRY( NODE, dss_squarewave , DSS_NODE , 6, DSE( ENAB,FREQ,AMPL,DUTY,BIAS,NODE_NC ), DSE( ENAB,FREQ,AMPL,DUTY,BIAS,PHASE ), NULL, "DISCRETE_SQUAREWAVE" ), |
| 4606 | #define DISCRETE_SQUAREWFIX(NODE,ENAB,FREQ,AMPL,DUTY,BIAS,PHASE) DSC_SND_ENTRY( NODE, dss_squarewfix , DSS_NODE , 6, DSE( ENAB,FREQ,AMPL,DUTY,BIAS,NODE_NC ), DSE( ENAB,FREQ,AMPL,DUTY,BIAS,PHASE ), NULL, "DISCRETE_SQUAREWFIX" ), |
| 4607 | #define DISCRETE_SQUAREWAVE2(NODE,ENAB,AMPL,T_OFF,T_ON,BIAS,TSHIFT) DSC_SND_ENTRY( NODE, dss_squarewave2 , DSS_NODE , 6, DSE( ENAB,AMPL,T_OFF,T_ON,BIAS,NODE_NC ), DSE( ENAB,AMPL,T_OFF,T_ON,BIAS,TSHIFT ), NULL, "DISCRETE_SQUAREWAVE2" ), |
| 4608 | #define DISCRETE_TRIANGLEWAVE(NODE,ENAB,FREQ,AMPL,BIAS,PHASE) DSC_SND_ENTRY( NODE, dss_trianglewave, DSS_NODE , 5, DSE( ENAB,FREQ,AMPL,BIAS,NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,PHASE ), NULL, "DISCRETE_TRIANGLEWAVE" ), |
| 4609 | /* Component specific */ |
| 4610 | #define DISCRETE_INVERTER_OSC(NODE,ENAB,MOD,RCHARGE,RP,C,R2,INFO) DSC_SND_ENTRY( NODE, dss_inverter_osc, DSS_NODE , 6, DSE( ENAB,MOD,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,MOD,RCHARGE,RP,C,R2 ), INFO, "DISCRETE_INVERTER_OSC" ), |
| 4611 | #define DISCRETE_OP_AMP_OSCILLATOR(NODE,ENAB,INFO) DSC_SND_ENTRY( NODE, dss_op_amp_osc , DSS_NODE , 1, DSE( ENAB ), DSE( ENAB ), INFO, "DISCRETE_OP_AMP_OSCILLATOR" ), |
| 4612 | #define DISCRETE_OP_AMP_VCO1(NODE,ENAB,VMOD1,INFO) DSC_SND_ENTRY( NODE, dss_op_amp_osc , DSS_NODE , 2, DSE( ENAB,VMOD1 ), DSE( ENAB,VMOD1 ), INFO, "DISCRETE_OP_AMP_VCO1" ), |
| 4613 | #define DISCRETE_OP_AMP_VCO2(NODE,ENAB,VMOD1,VMOD2,INFO) DSC_SND_ENTRY( NODE, dss_op_amp_osc , DSS_NODE , 3, DSE( ENAB,VMOD1,VMOD2 ), DSE( ENAB,VMOD1,VMOD2 ), INFO, "DISCRETE_OP_AMP_VCO2" ), |
| 4614 | #define DISCRETE_SCHMITT_OSCILLATOR(NODE,ENAB,INP0,AMPL,TABLE) DSC_SND_ENTRY( NODE, dss_schmitt_osc , DSS_NODE , 3, DSE( ENAB,INP0,AMPL ), DSE( ENAB,INP0,AMPL ), TABLE, "DISCRETE_SCHMITT_OSCILLATOR" ), |
| 4615 | /* Not yet implemented */ |
| 4616 | #define DISCRETE_ADSR_ENV(NODE,ENAB,TRIGGER,GAIN,ADSRTB) DSC_SND_ENTRY( NODE, dss_adsr , DSS_NODE , 3, DSE( ENAB,TRIGGER,GAIN ), DSE( ENAB,TRIGGER,GAIN ), ADSRTB, "DISCRETE_ADSR_ENV" ), |
| 4617 | |
| 4618 | /* from disc_mth.c */ |
| 4619 | /* generic modules */ |
| 4620 | #define DISCRETE_ADDER2(NODE,ENAB,INP0,INP1) DSC_SND_ENTRY( NODE, dst_adder , DSS_NODE , 3, DSE( ENAB,INP0,INP1 ), DSE( ENAB,INP0,INP1 ), NULL, "DISCRETE_ADDER2" ), |
| 4621 | #define DISCRETE_ADDER3(NODE,ENAB,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, dst_adder , DSS_NODE , 4, DSE( ENAB,INP0,INP1,INP2 ), DSE( ENAB,INP0,INP1,INP2 ), NULL, "DISCRETE_ADDER3" ), |
| 4622 | #define DISCRETE_ADDER4(NODE,ENAB,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, dst_adder , DSS_NODE , 5, DSE( ENAB,INP0,INP1,INP2,INP3 ), DSE( ENAB,INP0,INP1,INP2,INP3 ), NULL, "DISCRETE_ADDER4" ), |
| 4623 | #define DISCRETE_CLAMP(NODE,INP0,MIN,MAX) DSC_SND_ENTRY( NODE, dst_clamp , DSS_NODE , 3, DSE( INP0,MIN,MAX ), DSE( INP0,MIN,MAX ), NULL, "DISCRETE_CLAMP" ), |
| 4624 | #define DISCRETE_DIVIDE(NODE,ENAB,INP0,INP1) DSC_SND_ENTRY( NODE, dst_divide , DSS_NODE , 3, DSE( ENAB,INP0,INP1 ), DSE( ENAB,INP0,INP1 ), NULL, "DISCRETE_DIVIDE" ), |
| 4625 | #define DISCRETE_GAIN(NODE,INP0,GAIN) DSC_SND_ENTRY( NODE, dst_gain , DSS_NODE , 3, DSE( INP0,NODE_NC,NODE_NC ), DSE( INP0,GAIN,0 ), NULL, "DISCRETE_GAIN" ), |
| 4626 | #define DISCRETE_INVERT(NODE,INP0) DSC_SND_ENTRY( NODE, dst_gain , DSS_NODE , 3, DSE( INP0,NODE_NC,NODE_NC ), DSE( INP0,-1,0 ), NULL, "DISCRETE_INVERT" ), |
| 4627 | #define DISCRETE_LOGIC_INVERT(NODE,INP0) DSC_SND_ENTRY( NODE, dst_logic_inv , DSS_NODE , 1, DSE( INP0 ), DSE( INP0 ), NULL, "DISCRETE_LOGIC_INVERT" ), |
| 4628 | |
| 4629 | #define DISCRETE_BIT_DECODE(NODE, INP, BIT_N, VOUT) DSC_SND_ENTRY( NODE, dst_bits_decode , DSS_NODE , 4, DSE( INP,NODE_NC,NODE_NC,NODE_NC ), DSE( INP,BIT_N,BIT_N,VOUT ), NULL, "DISCRETE_BIT_DECODE" ), |
| 4630 | #define DISCRETE_BITS_DECODE(NODE, INP, BIT_FROM, BIT_TO, VOUT) DSC_SND_ENTRY( NODE, dst_bits_decode , DSS_NODE , 4, DSE( INP,NODE_NC,NODE_NC,NODE_NC ), DSE( INP,BIT_FROM,BIT_TO,VOUT ), NULL, "DISCRETE_BITS_DECODE" ), |
| 4631 | |
| 4632 | #define DISCRETE_LOGIC_AND(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, dst_logic_and , DSS_NODE , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,1.0,1.0 ), NULL, "DISCRETE_LOGIC_AND" ), |
| 4633 | #define DISCRETE_LOGIC_AND3(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, dst_logic_and , DSS_NODE , 4, DSE( INP0,INP1,INP2,NODE_NC ), DSE( INP0,INP1,INP2,1.0 ), NULL, "DISCRETE_LOGIC_AND3" ), |
| 4634 | #define DISCRETE_LOGIC_AND4(NODE,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, dst_logic_and , DSS_NODE , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ) ,NULL, "DISCRETE_LOGIC_AND4" ), |
| 4635 | #define DISCRETE_LOGIC_NAND(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, dst_logic_nand , DSS_NODE , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,1.0,1.0 ), NULL, "DISCRETE_LOGIC_NAND" ), |
| 4636 | #define DISCRETE_LOGIC_NAND3(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, dst_logic_nand , DSS_NODE , 4, DSE( INP0,INP1,INP2,NODE_NC ), DSE( INP0,INP1,INP2,1.0 ), NULL, "DISCRETE_LOGIC_NAND3" ), |
| 4637 | #define DISCRETE_LOGIC_NAND4(NODE,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, dst_logic_nand , DSS_NODE , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ), NULL, ")DISCRETE_LOGIC_NAND4" ), |
| 4638 | #define DISCRETE_LOGIC_OR(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, dst_logic_or , DSS_NODE , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,0.0,0.0 ), NULL, "DISCRETE_LOGIC_OR" ), |
| 4639 | #define DISCRETE_LOGIC_OR3(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, dst_logic_or , DSS_NODE , 4, DSE( INP0,INP1,INP2,NODE_NC ), DSE( INP0,INP1,INP2,0.0 ), NULL, "DISCRETE_LOGIC_OR3" ), |
| 4640 | #define DISCRETE_LOGIC_OR4(NODE,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, dst_logic_or , DSS_NODE , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ), NULL, "DISCRETE_LOGIC_OR4" ), |
| 4641 | #define DISCRETE_LOGIC_NOR(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, dst_logic_nor , DSS_NODE , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,0.0,0.0 ), NULL, "DISCRETE_LOGIC_NOR" ), |
| 4642 | #define DISCRETE_LOGIC_NOR3(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, dst_logic_nor , DSS_NODE , 4, DSE( INP0,INP1,INP2,NODE_NC ), DSE( INP0,INP1,INP2,0.0 ), NULL, "DISCRETE_LOGIC_NOR3" ), |
| 4643 | #define DISCRETE_LOGIC_NOR4(NODE,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, dst_logic_nor , DSS_NODE , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ), NULL, "DISCRETE_LOGIC_NOR4" ), |
| 4644 | #define DISCRETE_LOGIC_XOR(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, dst_logic_xor , DSS_NODE , 2, DSE( INP0,INP1 ), DSE( INP0,INP1 ), NULL, "DISCRETE_LOGIC_XOR" ), |
| 4645 | #define DISCRETE_LOGIC_XNOR(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, dst_logic_nxor , DSS_NODE , 2, DSE( INP0,INP1 ), DSE( INP0,INP1 ), NULL, "DISCRETE_LOGIC_XNOR" ), |
| 4646 | #define DISCRETE_LOGIC_DFLIPFLOP(NODE,RESET,SET,CLK,INP) DSC_SND_ENTRY( NODE, dst_logic_dff , DSS_NODE , 4, DSE( RESET,SET,CLK,INP ), DSE( RESET,SET,CLK,INP ), NULL, "DISCRETE_LOGIC_DFLIPFLOP" ), |
| 4647 | #define DISCRETE_LOGIC_JKFLIPFLOP(NODE,RESET,SET,CLK,J,K) DSC_SND_ENTRY( NODE, dst_logic_jkff , DSS_NODE , 5, DSE( RESET,SET,CLK,J,K ), DSE( RESET,SET,CLK,J,K ), NULL, "DISCRETE_LOGIC_JKFLIPFLOP" ), |
| 4648 | #define DISCRETE_LOGIC_SHIFT(NODE,INP0,RESET,CLK,SIZE,OPTIONS) DSC_SND_ENTRY( NODE, dst_logic_shift , DSS_NODE , 5, DSE( INP0,RESET,CLK,NODE_NC,NODE_NC ), DSE( INP0,RESET,CLK,SIZE,OPTIONS ), NULL, "DISCRETE_LOGIC_SHIFT" ), |
| 4649 | #define DISCRETE_LOOKUP_TABLE(NODE,ADDR,SIZE,TABLE) DSC_SND_ENTRY( NODE, dst_lookup_table, DSS_NODE , 2, DSE( ADDR,NODE_NC ), DSE( ADDR,SIZE ), TABLE, "DISCRETE_LOOKUP_TABLE" ), |
| 4650 | #define DISCRETE_MULTIPLEX2(NODE,ADDR,INP0,INP1) DSC_SND_ENTRY( NODE, dst_multiplex , DSS_NODE , 3, DSE( ADDR,INP0,INP1 ), DSE( ADDR,INP0,INP1 ), NULL, "DISCRETE_MULTIPLEX2" ), |
| 4651 | #define DISCRETE_MULTIPLEX4(NODE,ADDR,INP0,INP1,INP2,INP3) DSC_SND_ENTRY( NODE, dst_multiplex , DSS_NODE , 5, DSE( ADDR,INP0,INP1,INP2,INP3 ), DSE( ADDR,INP0,INP1,INP2,INP3 ), NULL, "DISCRETE_MULTIPLEX4" ), |
| 4652 | #define DISCRETE_MULTIPLEX8(NODE,ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7) DSC_SND_ENTRY( NODE, dst_multiplex, DSS_NODE , 9, DSE( ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7 ), DSE( ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7 ), NULL, "DISCRETE_MULTIPLEX8" ), |
| 4653 | #define DISCRETE_MULTIPLY(NODE,INP0,INP1) DSC_SND_ENTRY( NODE, dst_gain , DSS_NODE , 3, DSE( INP0,INP1,NODE_NC ), DSE( INP0,INP1,0 ), NULL, "DISCRETE_MULTIPLY" ), |
| 4654 | #define DISCRETE_MULTADD(NODE,INP0,INP1,INP2) DSC_SND_ENTRY( NODE, dst_gain , DSS_NODE , 3, DSE( INP0,INP1,INP2 ), DSE( INP0,INP1,INP2 ), NULL, "DISCRETE_MULTADD" ), |
| 4655 | #define DISCRETE_ONESHOT(NODE,TRIG,AMPL,WIDTH,TYPE) DSC_SND_ENTRY( NODE, dst_oneshot , DSS_NODE , 5, DSE( 0,TRIG,AMPL,WIDTH,NODE_NC ), DSE( 0,TRIG,AMPL,WIDTH,TYPE ), NULL, "DISCRETE_ONESHOT" ), |
| 4656 | #define DISCRETE_ONESHOTR(NODE,RESET,TRIG,AMPL,WIDTH,TYPE) DSC_SND_ENTRY( NODE, dst_oneshot , DSS_NODE , 5, DSE( RESET,TRIG,AMPL,WIDTH,NODE_NC ), DSE( RESET,TRIG,AMPL,WIDTH,TYPE ), NULL, "One Shot Resetable" ), |
| 4657 | #define DISCRETE_ONOFF(NODE,ENAB,INP0) DSC_SND_ENTRY( NODE, dst_gain , DSS_NODE , 3, DSE( ENAB,INP0,NODE_NC ), DSE( 0,1,0 ), NULL, "DISCRETE_ONOFF" ), |
| 4658 | #define DISCRETE_RAMP(NODE,ENAB,RAMP,GRAD,START,END,CLAMP) DSC_SND_ENTRY( NODE, dst_ramp , DSS_NODE , 6, DSE( ENAB,RAMP,GRAD,START,END,CLAMP ), DSE( ENAB,RAMP,GRAD,START,END,CLAMP ), NULL, "DISCRETE_RAMP" ), |
| 4659 | #define DISCRETE_SAMPLHOLD(NODE,INP0,CLOCK,CLKTYPE) DSC_SND_ENTRY( NODE, dst_samphold , DSS_NODE , 3, DSE( INP0,CLOCK,NODE_NC ), DSE( INP0,CLOCK,CLKTYPE ), NULL, "DISCRETE_SAMPLHOLD" ), |
| 4660 | #define DISCRETE_SWITCH(NODE,ENAB,SWITCH,INP0,INP1) DSC_SND_ENTRY( NODE, dst_switch , DSS_NODE , 4, DSE( ENAB,SWITCH,INP0,INP1 ), DSE( ENAB,SWITCH,INP0,INP1 ), NULL, "DISCRETE_SWITCH" ), |
| 4661 | #define DISCRETE_ASWITCH(NODE,CTRL,INP,THRESHOLD) DSC_SND_ENTRY( NODE, dst_aswitch , DSS_NODE , 3, DSE( CTRL,INP,THRESHOLD ), DSE( CTRL,INP, THRESHOLD), NULL, "Analog Switch" ), |
| 4662 | #define DISCRETE_TRANSFORM2(NODE,INP0,INP1,FUNCT) DSC_SND_ENTRY( NODE, dst_transform , DSS_NODE , 2, DSE( INP0,INP1 ), DSE( INP0,INP1 ), FUNCT, "DISCRETE_TRANSFORM2" ), |
| 4663 | #define DISCRETE_TRANSFORM3(NODE,INP0,INP1,INP2,FUNCT) DSC_SND_ENTRY( NODE, dst_transform , DSS_NODE , 3, DSE( INP0,INP1,INP2 ), DSE( INP0,INP1,INP2 ), FUNCT, "DISCRETE_TRANSFORM3" ), |
| 4664 | #define DISCRETE_TRANSFORM4(NODE,INP0,INP1,INP2,INP3,FUNCT) DSC_SND_ENTRY( NODE, dst_transform , DSS_NODE , 4, DSE( INP0,INP1,INP2,INP3 ), DSE( INP0,INP1,INP2,INP3 ), FUNCT, "DISCRETE_TRANSFORM4" ), |
| 4665 | #define DISCRETE_TRANSFORM5(NODE,INP0,INP1,INP2,INP3,INP4,FUNCT) DSC_SND_ENTRY( NODE, dst_transform , DSS_NODE , 5, DSE( INP0,INP1,INP2,INP3,INP4 ), DSE( INP0,INP1,INP2,INP3,INP4 ), FUNCT, "DISCRETE_TRANSFORM5" ), |
| 4666 | /* Component specific */ |
| 4667 | #define DISCRETE_COMP_ADDER(NODE,DATA,TABLE) DSC_SND_ENTRY( NODE, dst_comp_adder , DSS_NODE , 1, DSE( DATA ), DSE( DATA ), TABLE, "DISCRETE_COMP_ADDER" ), |
| 4668 | #define DISCRETE_DAC_R1(NODE,DATA,VDATA,LADDER) DSC_SND_ENTRY( NODE, dst_dac_r1 , DSS_NODE , 2, DSE( DATA,NODE_NC ), DSE( DATA,VDATA ), LADDER, "DISCRETE_DAC_R1" ), |
| 4669 | #define DISCRETE_DIODE_MIXER2(NODE,IN0,IN1,TABLE) DSC_SND_ENTRY( NODE, dst_diode_mix , DSS_NODE , 3, DSE( IN0,IN1 ), DSE( IN0,IN1 ), TABLE, "DISCRETE_DIODE_MIXER2" ), |
| 4670 | #define DISCRETE_DIODE_MIXER3(NODE,IN0,IN1,IN2,TABLE) DSC_SND_ENTRY( NODE, dst_diode_mix , DSS_NODE , 4, DSE( IN0,IN1,IN2 ), DSE( IN0,IN1,IN2 ), TABLE, "DISCRETE_DIODE_MIXER3" ), |
| 4671 | #define DISCRETE_DIODE_MIXER4(NODE,IN0,IN1,IN2,IN3,TABLE) DSC_SND_ENTRY( NODE, dst_diode_mix , DSS_NODE , 5, DSE( IN0,IN1,IN2,IN3 ), DSE( IN0,IN1,IN2,IN3 ), TABLE, "DISCRETE_DIODE_MIXER4" ), |
| 4672 | #define DISCRETE_INTEGRATE(NODE,TRG0,TRG1,INFO) DSC_SND_ENTRY( NODE, dst_integrate , DSS_NODE , 2, DSE( TRG0,TRG1 ), DSE( TRG0,TRG1 ), INFO, "DISCRETE_INTEGRATE" ), |
| 4673 | #define DISCRETE_MIXER2(NODE,ENAB,IN0,IN1,INFO) DSC_SND_ENTRY( NODE, dst_mixer , DSS_NODE , 3, DSE( ENAB,IN0,IN1 ), DSE( ENAB,IN0,IN1 ), INFO, "DISCRETE_MIXER2" ), |
| 4674 | #define DISCRETE_MIXER3(NODE,ENAB,IN0,IN1,IN2,INFO) DSC_SND_ENTRY( NODE, dst_mixer , DSS_NODE , 4, DSE( ENAB,IN0,IN1,IN2 ), DSE( ENAB,IN0,IN1,IN2 ), INFO, "DISCRETE_MIXER3" ), |
| 4675 | #define DISCRETE_MIXER4(NODE,ENAB,IN0,IN1,IN2,IN3,INFO) DSC_SND_ENTRY( NODE, dst_mixer , DSS_NODE , 5, DSE( ENAB,IN0,IN1,IN2,IN3 ), DSE( ENAB,IN0,IN1,IN2,IN3 ), INFO, "DISCRETE_MIXER4" ), |
| 4676 | #define DISCRETE_MIXER5(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,INFO) DSC_SND_ENTRY( NODE, dst_mixer , DSS_NODE , 6, DSE( ENAB,IN0,IN1,IN2,IN3,IN4 ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4 ), INFO, "DISCRETE_MIXER5" ), |
| 4677 | #define DISCRETE_MIXER6(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,INFO) DSC_SND_ENTRY( NODE, dst_mixer , DSS_NODE , 7, DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5 ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5 ), INFO, "DISCRETE_MIXER6" ), |
| 4678 | #define DISCRETE_MIXER7(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,INFO) DSC_SND_ENTRY( NODE, dst_mixer , DSS_NODE , 8, DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), INFO, "DISCRETE_MIXER7" ), |
| 4679 | #define DISCRETE_MIXER8(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,INFO) DSC_SND_ENTRY( NODE, dst_mixer , DSS_NODE , 9, DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), INFO, "DISCRETE_MIXER8" ), |
| 4680 | #define DISCRETE_OP_AMP(NODE,ENAB,IN0,IN1,INFO) DSC_SND_ENTRY( NODE, dst_op_amp , DSS_NODE , 3, DSE( ENAB,IN0,IN1 ), DSE( ENAB,IN0,IN1 ), INFO, "DISCRETE_OP_AMP" ), |
| 4681 | #define DISCRETE_OP_AMP_ONESHOT(NODE,TRIG,INFO) DSC_SND_ENTRY( NODE, dst_op_amp_1sht , DSS_NODE , 1, DSE( TRIG ), DSE( TRIG ), INFO, "DISCRETE_OP_AMP_ONESHOT" ), |
| 4682 | #define DISCRETE_OP_AMP_TRIG_VCA(NODE,TRG0,TRG1,TRG2,IN0,IN1,INFO) DSC_SND_ENTRY( NODE, dst_tvca_op_amp , DSS_NODE , 5, DSE( TRG0,TRG1,TRG2,IN0,IN1 ), DSE( TRG0,TRG1,TRG2,IN0,IN1 ), INFO, "DISCRETE_OP_AMP_TRIG_VCA" ), |
| 4683 | #define DISCRETE_VCA(NODE,ENAB,IN0,CTRL,TYPE) DSC_SND_ENTRY( NODE, dst_vca , DSS_NODE , 4, DSE( ENAB,IN0,CTRL,NODE_NC ), DSE( ENAB,IN0,CTRL,TYPE ), NULL, "DISCRETE_VCA" ), |
| 4684 | #define DISCRETE_XTIME_BUFFER(NODE,IN0,LOW,HIGH) DSC_SND_ENTRY( NODE, dst_xtime_buffer, DSS_NODE , 4, DSE( IN0,LOW,HIGH,NODE_NC ), DSE( IN0,LOW,HIGH,0 ), NULL, "DISCRETE_XTIME_BUFFER" ), |
| 4685 | #define DISCRETE_XTIME_INVERTER(NODE,IN0,LOW,HIGH) DSC_SND_ENTRY( NODE, dst_xtime_buffer, DSS_NODE , 4, DSE( IN0,LOW,HIGH,NODE_NC ), DSE( IN0,LOW,HIGH,1 ), NULL, "DISCRETE_XTIME_INVERTER" ), |
| 4686 | #define DISCRETE_XTIME_AND(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, dst_xtime_and , DSS_NODE , 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), NULL, "DISCRETE_XTIME_AND" ), |
| 4687 | #define DISCRETE_XTIME_NAND(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, dst_xtime_and , DSS_NODE , 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), NULL, "DISCRETE_XTIME_NAND" ), |
| 4688 | #define DISCRETE_XTIME_OR(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, dst_xtime_or , DSS_NODE , 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), NULL, "DISCRETE_XTIME_OR" ), |
| 4689 | #define DISCRETE_XTIME_NOR(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, dst_xtime_or , DSS_NODE , 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), NULL, "DISCRETE_XTIME_NOR" ), |
| 4690 | #define DISCRETE_XTIME_XOR(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, dst_xtime_xor , DSS_NODE , 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), NULL, "DISCRETE_XTIME_XOR" ), |
| 4691 | #define DISCRETE_XTIME_XNOR(NODE,IN0,IN1,LOW,HIGH) DSC_SND_ENTRY( NODE, dst_xtime_xnor , DSS_NODE , 5, DSE( IN0,IN1,LOW,HIGH,NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), NULL, "DISCRETE_XTIME_XNOR" ), |
| 4692 | |
| 4693 | /* from disc_flt.c */ |
| 4694 | /* generic modules */ |
| 4695 | #define DISCRETE_FILTER1(NODE,ENAB,INP0,FREQ,TYPE) DSC_SND_ENTRY( NODE, dst_filter1 , DSS_NODE , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,FREQ,TYPE ), NULL, "DISCRETE_FILTER1" ), |
| 4696 | #define DISCRETE_FILTER2(NODE,ENAB,INP0,FREQ,DAMP,TYPE) DSC_SND_ENTRY( NODE, dst_filter2 , DSS_NODE , 5, DSE( ENAB,INP0,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,FREQ,DAMP,TYPE ), NULL, "DISCRETE_FILTER2" ), |
| 4697 | /* Component specific */ |
| 4698 | #define DISCRETE_SALLEN_KEY_FILTER(NODE,ENAB,INP0,TYPE,INFO) DSC_SND_ENTRY( NODE, dst_sallen_key , DSS_NODE , 3, DSE( ENAB,INP0,NODE_NC ), DSE( ENAB,INP0,TYPE ), INFO, "DISCRETE_SALLEN_KEY_FILTER" ), |
| 4699 | #define DISCRETE_CRFILTER(NODE,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, dst_crfilter , DSS_NODE , 4, DSE( INP0,RVAL,CVAL ), DSE( INP0,RVAL,CVAL ), NULL, "DISCRETE_CRFILTER" ), |
| 4700 | #define DISCRETE_CRFILTER_VREF(NODE,INP0,RVAL,CVAL,VREF) DSC_SND_ENTRY( NODE, dst_crfilter , DSS_NODE , 5, DSE( INP0,RVAL,CVAL,VREF ), DSE( INP0,RVAL,CVAL,VREF ), NULL, "DISCRETE_CRFILTER_VREF" ), |
| 4701 | #define DISCRETE_OP_AMP_FILTER(NODE,ENAB,INP0,INP1,TYPE,INFO) DSC_SND_ENTRY( NODE, dst_op_amp_filt , DSS_NODE , 4, DSE( ENAB,INP0,INP1,NODE_NC ), DSE( ENAB,INP0,INP1,TYPE ), INFO, "DISCRETE_OP_AMP_FILTER" ), |
| 4702 | #define DISCRETE_RC_CIRCUIT_1(NODE,INP0,INP1,RVAL,CVAL) DSC_SND_ENTRY( NODE, dst_rc_circuit_1, DSS_NODE , 4, DSE( INP0,INP1,NODE_NC,NODE_NC ), DSE( INP0,INP1,RVAL,CVAL ), NULL, "DISCRETE_RC_CIRCUIT_1" ), |
| 4703 | #define DISCRETE_RCDISC(NODE,ENAB,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, dst_rcdisc , DSS_NODE , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), NULL, "DISCRETE_RCDISC" ), |
| 4704 | #define DISCRETE_RCDISC2(NODE,SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL) DSC_SND_ENTRY( NODE, dst_rcdisc2 , DSS_NODE , 6, DSE( SWITCH,INP0,NODE_NC,INP1,NODE_NC,NODE_NC ), DSE( SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL ), NULL, "DISCRETE_RCDISC2" ), |
| 4705 | #define DISCRETE_RCDISC3(NODE,ENAB,INP0,RVAL0,RVAL1,CVAL,DJV) DSC_SND_ENTRY( NODE, dst_rcdisc3 , DSS_NODE , 6, DSE( ENAB,INP0,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL0,RVAL1,CVAL,DJV ), NULL, "DISCRETE_RCDISC3" ), |
| 4706 | #define DISCRETE_RCDISC4(NODE,ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,VP,TYPE) DSC_SND_ENTRY( NODE, dst_rcdisc4 , DSS_NODE , 8, DSE( ENAB,INP0,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,VP,TYPE ), NULL, "DISCRETE_RCDISC4" ), |
| 4707 | #define DISCRETE_RCDISC5(NODE,ENAB,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, dst_rcdisc5 , DSS_NODE , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), NULL, "DISCRETE_RCDISC5" ), |
| 4708 | #define DISCRETE_RCDISC_MODULATED(NODE,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP) DSC_SND_ENTRY( NODE, dst_rcdisc_mod, DSS_NODE , 8, DSE( INP0,INP1,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP ), NULL, "DISCRETE_RCDISC_MODULATED" ), |
| 4709 | #define DISCRETE_RCFILTER(NODE,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, dst_rcfilter , DSS_NODE , 3, DSE( INP0,RVAL,CVAL ), DSE( INP0,RVAL,CVAL ), NULL, "DISCRETE_RCFILTER" ), |
| 4710 | #define DISCRETE_RCFILTER_VREF(NODE,INP0,RVAL,CVAL,VREF) DSC_SND_ENTRY( NODE, dst_rcfilter , DSS_NODE , 4, DSE( INP0,RVAL,CVAL,VREF ), DSE( INP0,RVAL,CVAL,VREF ), NULL, "DISCRETE_RCFILTER_VREF" ), |
| 4711 | #define DISCRETE_RCFILTER_SW(NODE,ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4) DSC_SND_ENTRY( NODE, dst_rcfilter_sw, DSS_NODE , 8, DSE( ENAB,INP0,SW,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4 ), NULL, "DISCRETE_RCFILTER_SW" ), |
| 4712 | #define DISCRETE_RCINTEGRATE(NODE,INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE) DSC_SND_ENTRY( NODE, dst_rcintegrate , DSS_NODE , 7, DSE( INP0,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE ), NULL, "DISCRETE_RCINTEGRATE" ), |
| 4713 | /* For testing - seem to be buggered. Use versions not ending in N. */ |
| 4714 | #define DISCRETE_RCDISCN(NODE,ENAB,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, dst_rcdiscn , DSS_NODE , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), NULL, "DISCRETE_RCDISCN" ), |
| 4715 | #define DISCRETE_RCDISC2N(NODE,SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL) DSC_SND_ENTRY( NODE, dst_rcdisc2n , DSS_NODE , 6, DSE( SWITCH,INP0,NODE_NC,INP1,NODE_NC,NODE_NC ), DSE( SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL ), NULL, "DISCRETE_RCDISC2N" ), |
| 4716 | #define DISCRETE_RCFILTERN(NODE,ENAB,INP0,RVAL,CVAL) DSC_SND_ENTRY( NODE, dst_rcfiltern , DSS_NODE , 4, DSE( ENAB,INP0,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), NULL, "DISCRETE_RCFILTERN" ), |
| 4717 | |
| 4718 | /* from disc_dev.c */ |
| 4719 | /* generic modules */ |
| 4720 | #define DISCRETE_CUSTOM1(NODE,CLASS,IN0,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 1, DSE( IN0 ), DSE( IN0 ), INFO, "DISCRETE_CUSTOM1" ), |
| 4721 | #define DISCRETE_CUSTOM2(NODE,CLASS,IN0,IN1,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 2, DSE( IN0,IN1 ), DSE( IN0,IN1 ), INFO, "DISCRETE_CUSTOM2" ), |
| 4722 | #define DISCRETE_CUSTOM3(NODE,CLASS,IN0,IN1,IN2,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 3, DSE( IN0,IN1,IN2 ), DSE( IN0,IN1,IN2 ), INFO, "DISCRETE_CUSTOM3" ), |
| 4723 | #define DISCRETE_CUSTOM4(NODE,CLASS,IN0,IN1,IN2,IN3,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 4, DSE( IN0,IN1,IN2,IN3 ), DSE( IN0,IN1,IN2,IN3 ), INFO, "DISCRETE_CUSTOM4" ), |
| 4724 | #define DISCRETE_CUSTOM5(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 5, DSE( IN0,IN1,IN2,IN3,IN4 ), DSE( IN0,IN1,IN2,IN3,IN4 ), INFO, "DISCRETE_CUSTOM5" ), |
| 4725 | #define DISCRETE_CUSTOM6(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,IN5,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 6, DSE( IN0,IN1,IN2,IN3,IN4,IN5 ), DSE( IN0,IN1,IN2,IN3,IN4,IN5 ), INFO, "DISCRETE_CUSTOM6" ), |
| 4726 | #define DISCRETE_CUSTOM7(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,IN5,IN6,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 7, DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), INFO, "DISCRETE_CUSTOM7" ), |
| 4727 | #define DISCRETE_CUSTOM8(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 8, DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), INFO, "DISCRETE_CUSTOM8" ), |
| 4728 | #define DISCRETE_CUSTOM9(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM , 9, DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8 ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8 ), INFO, "DISCRETE_CUSTOM9" ), |
| 4729 | |
| 4730 | /* Component specific */ |
| 4731 | #define DISCRETE_555_ASTABLE(NODE,RESET,R1,R2,C,OPTIONS) DSC_SND_ENTRY( NODE, dsd_555_astbl , DSS_NODE , 5, DSE( RESET,R1,R2,C,NODE_NC ), DSE( RESET,R1,R2,C,-1 ), OPTIONS, "DISCRETE_555_ASTABLE" ), |
| 4732 | #define DISCRETE_555_ASTABLE_CV(NODE,RESET,R1,R2,C,CTRLV,OPTIONS) DSC_SND_ENTRY( NODE, dsd_555_astbl , DSS_NODE , 5, DSE( RESET,R1,R2,C,CTRLV ), DSE( RESET,R1,R2,C,CTRLV ), OPTIONS, "DISCRETE_555_ASTABLE_CV" ), |
| 4733 | #define DISCRETE_555_MSTABLE(NODE,RESET,TRIG,R,C,OPTIONS) DSC_SND_ENTRY( NODE, dsd_555_mstbl , DSS_NODE , 4, DSE( RESET,TRIG,R,C ), DSE( RESET,TRIG,R,C ), OPTIONS, "DISCRETE_555_MSTABLE" ), |
| 4734 | #define DISCRETE_555_CC(NODE,RESET,VIN,R,C,RBIAS,RGND,RDIS,OPTIONS) DSC_SND_ENTRY( NODE, dsd_555_cc , DSS_NODE , 7, DSE( RESET,VIN,R,C,RBIAS,RGND,RDIS ), DSE( RESET,VIN,R,C,RBIAS,RGND,RDIS ), OPTIONS, "DISCRETE_555_CC" ), |
| 4735 | #define DISCRETE_555_VCO1(NODE,RESET,VIN,OPTIONS) DSC_SND_ENTRY( NODE, dsd_555_vco1 , DSS_NODE , 3, DSE( RESET,VIN,NODE_NC ), DSE( RESET,VIN,-1 ), OPTIONS, "DISCRETE_555_VCO1" ), |
| 4736 | #define DISCRETE_555_VCO1_CV(NODE,RESET,VIN,CTRLV,OPTIONS) DSC_SND_ENTRY( NODE, dsd_555_vco1 , DSS_NODE , 3, DSE( RESET,VIN,CTRLV ), DSE( RESET,VIN,CTRLV ), OPTIONS, "DISCRETE_555_VCO1_CV" ), |
| 4737 | #define DISCRETE_566(NODE,VMOD,R,C,VPOS,VNEG,VCHARGE,OPTIONS) DSC_SND_ENTRY( NODE, dsd_566 , DSS_NODE , 7, DSE( VMOD,R,C,NODE_NC,NODE_NC,VCHARGE,NODE_NC ), DSE( VMOD,R,C,VPOS,VNEG,VCHARGE,OPTIONS ), NULL, "DISCRETE_566" ), |
| 4738 | #define DISCRETE_74LS624(NODE,ENAB,VMOD,VRNG,C,R_FREQ_IN,C_FREQ_IN,R_RNG_IN,OUTTYPE) DSC_SND_ENTRY( NODE, dsd_ls624 , DSS_NODE , 8, DSE( ENAB,VMOD,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,VMOD,VRNG,C,R_FREQ_IN,C_FREQ_IN,R_RNG_IN,OUTTYPE ), NULL, "DISCRETE_74LS624" ), |
| 4739 | |
| 4740 | /* NOP */ |
| 4741 | #define DISCRETE_NOP(NODE) DSC_SND_ENTRY( NODE, dss_nop , DSS_NOP , 0, DSE( 0 ), DSE( 0 ), NULL, "DISCRETE_NOP" ), |
| 4742 | |
| 4743 | /* logging */ |
| 4744 | #define DISCRETE_CSVLOG1(NODE1) DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog , DSO_CSVLOG , 1, DSE( NODE1 ), DSE( NODE1 ), NULL, "DISCRETE_CSVLOG1" ), |
| 4745 | #define DISCRETE_CSVLOG2(NODE1,NODE2) DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog , DSO_CSVLOG , 2, DSE( NODE1,NODE2 ), DSE( NODE1,NODE2 ), NULL, "DISCRETE_CSVLOG2" ), |
| 4746 | #define DISCRETE_CSVLOG3(NODE1,NODE2,NODE3) DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog , DSO_CSVLOG , 3, DSE( NODE1,NODE2,NODE3 ), DSE( NODE1,NODE2,NODE3 ), NULL, "DISCRETE_CSVLOG3" ), |
| 4747 | #define DISCRETE_CSVLOG4(NODE1,NODE2,NODE3,NODE4) DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog , DSO_CSVLOG , 4, DSE( NODE1,NODE2,NODE3,NODE4 ), DSE( NODE1,NODE2,NODE3,NODE4 ), NULL, "DISCRETE_CSVLOG4" ), |
| 4748 | #define DISCRETE_CSVLOG5(NODE1,NODE2,NODE3,NODE4,NODE5) DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog , DSO_CSVLOG , 5, DSE( NODE1,NODE2,NODE3,NODE4,NODE5 ), DSE( NODE1,NODE2,NODE3,NODE4,NODE5 ), NULL, "DISCRETE_CSVLOG5" ), |
| 4749 | #define DISCRETE_WAVLOG1(NODE1,GAIN1) DSC_SND_ENTRY( NODE_SPECIAL, dso_wavelog , DSO_WAVELOG , 2, DSE( NODE1,NODE_NC ), DSE( NODE1,GAIN1 ), NULL, "DISCRETE_WAVLOG1" ), |
| 4750 | #define DISCRETE_WAVLOG2(NODE1,GAIN1,NODE2,GAIN2) DSC_SND_ENTRY( NODE_SPECIAL, dso_wavelog , DSO_WAVELOG , 4, DSE( NODE1,NODE_NC,NODE2,NODE_NC ), DSE( NODE1,GAIN1,NODE2,GAIN2 ), NULL, "DISCRETE_WAVLOG2" ), |
| 4751 | |
| 4752 | /* import */ |
| 4753 | #define DISCRETE_IMPORT(INFO) DSC_SND_ENTRY( NODE_SPECIAL, special , DSO_IMPORT , 0, DSE( 0 ), DSE( 0 ), &(INFO##_discrete_interface), "DISCRETE_IMPORT" ), |
| 4754 | #define DISCRETE_DELETE(NODE_FROM, NODE_TO) DSC_SND_ENTRY( NODE_SPECIAL, special , DSO_DELETE , 2, DSE( NODE_FROM, NODE_TO ), DSE( NODE_FROM, NODE_TO ), NULL, "DISCRETE_DELETE" ), |
| 4755 | #define DISCRETE_REPLACE DSC_SND_ENTRY( NODE_SPECIAL, special , DSO_REPLACE , 0, DSE( 0 ), DSE( 0 ), NULL, "DISCRETE_REPLACE" ), |
| 4756 | |
| 4757 | /* parallel tasks */ |
| 4758 | |
| 4759 | #define DISCRETE_TASK_START(TASK_GROUP) DSC_SND_ENTRY( NODE_SPECIAL, special , DSO_TASK_START,1, DSE( NODE_NC, NODE_NC ), DSE( TASK_GROUP, 0 ), NULL, "DISCRETE_TASK_START" ), |
| 4760 | #define DISCRETE_TASK_END() DSC_SND_ENTRY( NODE_SPECIAL, special , DSO_TASK_END , 1, DSE( 0 ), DSE( 0 ), NULL, "DISCRETE_TASK_END" ), |
| 4761 | //#define DISCRETE_TASK_SYNC() DSC_SND_ENTRY( NODE_SPECIAL, DSO_TASK_SYNC, 0, DSE( 0 ), DSE( 0 ), NULL, "DISCRETE_TASK_SYNC" ), |
| 4762 | |
| 4763 | /* output */ |
| 4764 | #define DISCRETE_OUTPUT(OPNODE,GAIN) DSC_SND_ENTRY( NODE_SPECIAL, dso_output , DSO_OUTPUT ,2, DSE( OPNODE,NODE_NC ), DSE( 0,GAIN ), NULL, "DISCRETE_OUTPUT" ), |
| 4765 | |
| 4766 | |
| 4767 | |
| 4872 | 4768 | #endif /* __DISCRETE_H__ */ |
src/emu/sound/disc_dev.c
| r10048 | r10049 | |
| 26 | 26 | |
| 27 | 27 | #define DEFAULT_555_BLEED_R RES_M(10) |
| 28 | 28 | |
| 29 | | struct dsd_555_astbl_context |
| 30 | | { |
| 31 | | int use_ctrlv; |
| 32 | | int output_type; |
| 33 | | int output_is_ac; |
| 34 | | double ac_shift; /* DC shift needed to make waveform ac */ |
| 35 | | int flip_flop; /* 555 flip/flop output state */ |
| 36 | | double cap_voltage; /* voltage on cap */ |
| 37 | | double threshold; |
| 38 | | double trigger; |
| 39 | | double v_out_high; /* Logic 1 voltage level */ |
| 40 | | double v_charge; |
| 41 | | double *v_charge_node; /* point to output of node */ |
| 42 | | int has_rc_nodes; |
| 43 | | double exp_bleed; |
| 44 | | double exp_charge; |
| 45 | | double exp_discharge; |
| 46 | | double t_rc_bleed; |
| 47 | | double t_rc_charge; |
| 48 | | double t_rc_discharge; |
| 49 | | double last_r1; |
| 50 | | double last_r2; |
| 51 | | double last_c; |
| 52 | | }; |
| 53 | | |
| 54 | | struct dsd_555_mstbl_context |
| 55 | | { |
| 56 | | int trig_is_logic; |
| 57 | | int trig_discharges_cap; |
| 58 | | int output_type; |
| 59 | | double ac_shift; /* DC shift needed to make waveform ac */ |
| 60 | | int flip_flop; /* 555 flip/flop output state */ |
| 61 | | int has_rc_nodes; |
| 62 | | double exp_charge; |
| 63 | | double cap_voltage; /* voltage on cap */ |
| 64 | | double threshold; |
| 65 | | double trigger; |
| 66 | | double v_out_high; /* Logic 1 voltage level */ |
| 67 | | double v_charge; |
| 68 | | }; |
| 69 | | |
| 70 | | struct dsd_555_cc_context |
| 71 | | { |
| 72 | | unsigned int type; /* type of 555cc circuit */ |
| 73 | | int output_type; |
| 74 | | int output_is_ac; |
| 75 | | double ac_shift; /* DC shift needed to make waveform ac */ |
| 76 | | int flip_flop; /* 555 flip/flop output state */ |
| 77 | | double cap_voltage; /* voltage on cap */ |
| 78 | | double threshold; |
| 79 | | double trigger; |
| 80 | | double v_out_high; /* Logic 1 voltage level */ |
| 81 | | double v_cc_source; |
| 82 | | int has_rc_nodes; |
| 83 | | double exp_bleed; |
| 84 | | double exp_charge; |
| 85 | | double exp_discharge; |
| 86 | | double exp_discharge_01; |
| 87 | | double exp_discharge_no_i; |
| 88 | | double t_rc_charge; |
| 89 | | double t_rc_discharge; |
| 90 | | double t_rc_discharge_01; |
| 91 | | double t_rc_discharge_no_i; |
| 92 | | }; |
| 93 | | |
| 94 | | struct dsd_555_vco1_context |
| 95 | | { |
| 96 | | int ctrlv_is_node; |
| 97 | | int output_type; |
| 98 | | int output_is_ac; |
| 99 | | double ac_shift; /* DC shift needed to make waveform ac */ |
| 100 | | int flip_flop; /* flip/flop output state */ |
| 101 | | double v_out_high; /* 555 high voltage */ |
| 102 | | double threshold; /* falling threshold */ |
| 103 | | double trigger; /* rising threshold */ |
| 104 | | double i_charge; /* charge current */ |
| 105 | | double i_discharge; /* discharge current */ |
| 106 | | double cap_voltage; /* current capacitor voltage */ |
| 107 | | }; |
| 108 | | |
| 109 | | struct dsd_566_context |
| 110 | | { |
| 111 | | unsigned int state[2]; /* keeps track of excess flip_flop changes during the current step */ |
| 112 | | int flip_flop; /* 566 flip/flop output state */ |
| 113 | | double cap_voltage; /* voltage on cap */ |
| 114 | | double v_sqr_low; /* voltage for a squarewave at low */ |
| 115 | | double v_sqr_high; /* voltage for a squarewave at high */ |
| 116 | | double v_sqr_diff; |
| 117 | | double threshold_low; /* falling threshold */ |
| 118 | | double threshold_high; /* rising threshold */ |
| 119 | | double ac_shift; /* used to fake AC */ |
| 120 | | double v_osc_stable; |
| 121 | | double v_osc_stop; |
| 122 | | int fake_ac; |
| 123 | | int out_type; |
| 124 | | }; |
| 125 | | |
| 126 | | struct dsd_ls624_context |
| 127 | | { |
| 128 | | double exponent; |
| 129 | | double t_used; |
| 130 | | double v_cap_freq_in; |
| 131 | | double v_freq_scale; |
| 132 | | double v_rng_scale; |
| 133 | | int flip_flop; |
| 134 | | int has_freq_in_cap; |
| 135 | | int out_type; |
| 136 | | }; |
| 137 | | |
| 138 | | |
| 139 | 29 | /************************************************************************ |
| 140 | 30 | * |
| 141 | 31 | * DSD_555_ASTBL - - 555 Astable simulation |
| r10048 | r10049 | |
| 167 | 57 | |
| 168 | 58 | DISCRETE_STEP(dsd_555_astbl) |
| 169 | 59 | { |
| 170 | | DISCRETE_DECLARE_CONTEXT(dsd_555_astbl) |
| 171 | 60 | DISCRETE_DECLARE_INFO(discrete_555_desc) |
| 172 | 61 | |
| 173 | 62 | int count_f = 0; |
| 174 | 63 | int count_r = 0; |
| 175 | 64 | double dt; /* change in time */ |
| 176 | 65 | double x_time = 0; /* time since change happened */ |
| 177 | | double v_cap = context->cap_voltage; /* Current voltage on capacitor, before dt */ |
| 66 | double v_cap = m_cap_voltage; /* Current voltage on capacitor, before dt */ |
| 178 | 67 | double v_cap_next = 0; /* Voltage on capacitor, after dt */ |
| 179 | 68 | double v_charge, exponent = 0; |
| 180 | | UINT8 flip_flop = context->flip_flop; |
| 69 | UINT8 flip_flop = m_flip_flop; |
| 181 | 70 | UINT8 update_exponent = 0; |
| 182 | 71 | |
| 183 | 72 | /* put commonly used stuff in local variables for speed */ |
| 184 | | double threshold = context->threshold; |
| 185 | | double trigger = context->trigger; |
| 73 | double threshold = m_threshold; |
| 74 | double trigger = m_trigger; |
| 186 | 75 | |
| 187 | 76 | if(DSD_555_ASTBL__RESET) |
| 188 | 77 | { |
| 189 | 78 | /* We are in RESET */ |
| 190 | | node->output[0] = 0; |
| 191 | | context->flip_flop = 1; |
| 192 | | context->cap_voltage = 0; |
| 79 | this->output[0] = 0; |
| 80 | m_flip_flop = 1; |
| 81 | m_cap_voltage = 0; |
| 193 | 82 | return; |
| 194 | 83 | } |
| 195 | 84 | |
| 196 | 85 | /* Check: if the Control Voltage node is connected. */ |
| 197 | | if (context->use_ctrlv) |
| 86 | if (m_use_ctrlv) |
| 198 | 87 | { |
| 199 | 88 | /* If CV is less then .25V, the circuit will oscillate way out of range. |
| 200 | 89 | * So we will just ignore it when it happens. */ |
| r10048 | r10049 | |
| 217 | 106 | } |
| 218 | 107 | |
| 219 | 108 | /* get the v_charge and update each step if it is a node */ |
| 220 | | if (context->v_charge_node != NULL) |
| 109 | if (m_v_charge_node != NULL) |
| 221 | 110 | { |
| 222 | | v_charge = *context->v_charge_node; |
| 111 | v_charge = *m_v_charge_node; |
| 223 | 112 | if (info->options & DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE) v_charge -= 0.5; |
| 224 | 113 | } |
| 225 | 114 | else |
| 226 | | v_charge = context->v_charge; |
| 115 | v_charge = m_v_charge; |
| 227 | 116 | |
| 228 | 117 | |
| 229 | 118 | /* Calculate future capacitor voltage. |
| r10048 | r10049 | |
| 244 | 133 | * dt = R*C(log(1/(1-(Vc/Vr)))) |
| 245 | 134 | */ |
| 246 | 135 | |
| 247 | | dt = node->info->sample_time; |
| 136 | dt = this->sample_time(); |
| 248 | 137 | |
| 249 | 138 | /* Sometimes a switching network is used to setup the capacitance. |
| 250 | 139 | * These may select no capacitor, causing oscillation to stop. |
| r10048 | r10049 | |
| 255 | 144 | /* The voltage goes high because the cap circuit is open. */ |
| 256 | 145 | v_cap_next = v_charge; |
| 257 | 146 | v_cap = v_charge; |
| 258 | | context->cap_voltage = 0; |
| 147 | m_cap_voltage = 0; |
| 259 | 148 | } |
| 260 | 149 | else |
| 261 | 150 | { |
| 262 | 151 | /* Update charge contstants and exponents if nodes changed */ |
| 263 | | if (context->has_rc_nodes && (DSD_555_ASTBL__R1 != context->last_r1 || DSD_555_ASTBL__C != context->last_c || DSD_555_ASTBL__R2 != context->last_r2)) |
| 152 | if (m_has_rc_nodes && (DSD_555_ASTBL__R1 != m_last_r1 || DSD_555_ASTBL__C != m_last_c || DSD_555_ASTBL__R2 != m_last_r2)) |
| 264 | 153 | { |
| 265 | | context->t_rc_bleed = DSD_555_ASTBL_T_RC_BLEED; |
| 266 | | context->t_rc_charge = DSD_555_ASTBL_T_RC_CHARGE; |
| 267 | | context->t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE; |
| 268 | | context->exp_bleed = RC_CHARGE_EXP(context->t_rc_bleed); |
| 269 | | context->exp_charge = RC_CHARGE_EXP(context->t_rc_charge); |
| 270 | | context->exp_discharge = RC_CHARGE_EXP(context->t_rc_discharge); |
| 271 | | context->last_r1 = DSD_555_ASTBL__R1; |
| 272 | | context->last_r2 = DSD_555_ASTBL__R2; |
| 273 | | context->last_c = DSD_555_ASTBL__C; |
| 154 | m_t_rc_bleed = DSD_555_ASTBL_T_RC_BLEED; |
| 155 | m_t_rc_charge = DSD_555_ASTBL_T_RC_CHARGE; |
| 156 | m_t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE; |
| 157 | m_exp_bleed = RC_CHARGE_EXP_CLASS(m_t_rc_bleed); |
| 158 | m_exp_charge = RC_CHARGE_EXP_CLASS(m_t_rc_charge); |
| 159 | m_exp_discharge = RC_CHARGE_EXP_CLASS(m_t_rc_discharge); |
| 160 | m_last_r1 = DSD_555_ASTBL__R1; |
| 161 | m_last_r2 = DSD_555_ASTBL__R2; |
| 162 | m_last_c = DSD_555_ASTBL__C; |
| 274 | 163 | } |
| 275 | 164 | /* Keep looping until all toggling in time sample is used up. */ |
| 276 | 165 | do |
| r10048 | r10049 | |
| 282 | 171 | /* Oscillation disabled because there is no longer any charge resistor. */ |
| 283 | 172 | /* Bleed the cap due to circuit losses. */ |
| 284 | 173 | if (update_exponent) |
| 285 | | exponent = RC_CHARGE_EXP_DT(context->t_rc_bleed, dt); |
| 174 | exponent = RC_CHARGE_EXP_DT(m_t_rc_bleed, dt); |
| 286 | 175 | else |
| 287 | | exponent = context->exp_bleed; |
| 176 | exponent = m_exp_bleed; |
| 288 | 177 | v_cap_next = v_cap - (v_cap * exponent); |
| 289 | 178 | dt = 0; |
| 290 | 179 | } |
| r10048 | r10049 | |
| 292 | 181 | { |
| 293 | 182 | /* Charging */ |
| 294 | 183 | if (update_exponent) |
| 295 | | exponent = RC_CHARGE_EXP_DT(context->t_rc_charge, dt); |
| 184 | exponent = RC_CHARGE_EXP_DT(m_t_rc_charge, dt); |
| 296 | 185 | else |
| 297 | | exponent = context->exp_charge; |
| 186 | exponent = m_exp_charge; |
| 298 | 187 | v_cap_next = v_cap + ((v_charge - v_cap) * exponent); |
| 299 | 188 | dt = 0; |
| 300 | 189 | |
| r10048 | r10049 | |
| 302 | 191 | if (v_cap_next >= threshold) |
| 303 | 192 | { |
| 304 | 193 | /* calculate the overshoot time */ |
| 305 | | dt = context->t_rc_charge * log(1.0 / (1.0 - ((v_cap_next - threshold) / (v_charge - v_cap)))); |
| 194 | dt = m_t_rc_charge * log(1.0 / (1.0 - ((v_cap_next - threshold) / (v_charge - v_cap)))); |
| 306 | 195 | x_time = dt; |
| 307 | 196 | v_cap_next = threshold; |
| 308 | 197 | flip_flop = 0; |
| r10048 | r10049 | |
| 317 | 206 | if(DSD_555_ASTBL__R2 != 0) |
| 318 | 207 | { |
| 319 | 208 | if (update_exponent) |
| 320 | | exponent = RC_CHARGE_EXP_DT(context->t_rc_discharge, dt); |
| 209 | exponent = RC_CHARGE_EXP_DT(m_t_rc_discharge, dt); |
| 321 | 210 | else |
| 322 | | exponent = context->exp_discharge; |
| 211 | exponent = m_exp_discharge; |
| 323 | 212 | v_cap_next = v_cap - (v_cap * exponent); |
| 324 | 213 | dt = 0; |
| 325 | 214 | } |
| r10048 | r10049 | |
| 334 | 223 | { |
| 335 | 224 | /* calculate the overshoot time */ |
| 336 | 225 | if (v_cap_next < trigger) |
| 337 | | dt = context->t_rc_discharge * log(1.0 / (1.0 - ((trigger - v_cap_next) / v_cap))); |
| 226 | dt = m_t_rc_discharge * log(1.0 / (1.0 - ((trigger - v_cap_next) / v_cap))); |
| 338 | 227 | x_time = dt; |
| 339 | 228 | v_cap_next = trigger; |
| 340 | 229 | flip_flop = 1; |
| r10048 | r10049 | |
| 345 | 234 | v_cap = v_cap_next; |
| 346 | 235 | } while(dt); |
| 347 | 236 | |
| 348 | | context->cap_voltage = v_cap; |
| 237 | m_cap_voltage = v_cap; |
| 349 | 238 | } |
| 350 | 239 | |
| 351 | 240 | /* Convert last switch time to a ratio */ |
| 352 | | x_time = x_time / node->info->sample_time; |
| 241 | x_time = x_time / this->sample_time(); |
| 353 | 242 | |
| 354 | | switch (context->output_type) |
| 243 | switch (m_output_type) |
| 355 | 244 | { |
| 356 | 245 | case DISC_555_OUT_SQW: |
| 357 | 246 | if (count_f + count_r >= 2) |
| 358 | 247 | /* force at least 1 toggle */ |
| 359 | | node->output[0] = context->flip_flop ? 0 : context->v_out_high; |
| 248 | this->output[0] = m_flip_flop ? 0 : m_v_out_high; |
| 360 | 249 | else |
| 361 | | node->output[0] = flip_flop * context->v_out_high; |
| 362 | | node->output[0] += context->ac_shift; |
| 250 | this->output[0] = flip_flop * m_v_out_high; |
| 251 | this->output[0] += m_ac_shift; |
| 363 | 252 | break; |
| 364 | 253 | case DISC_555_OUT_CAP: |
| 365 | | node->output[0] = v_cap; |
| 254 | this->output[0] = v_cap; |
| 366 | 255 | /* Fake it to AC if needed */ |
| 367 | | if (context->output_is_ac) |
| 368 | | node->output[0] -= threshold * 3.0 /4.0; |
| 256 | if (m_output_is_ac) |
| 257 | this->output[0] -= threshold * 3.0 /4.0; |
| 369 | 258 | break; |
| 370 | 259 | case DISC_555_OUT_ENERGY: |
| 371 | 260 | if (x_time == 0) x_time = 1.0; |
| 372 | | node->output[0] = context->v_out_high * (flip_flop ? x_time : (1.0 - x_time)); |
| 373 | | node->output[0] += context->ac_shift; |
| 261 | this->output[0] = m_v_out_high * (flip_flop ? x_time : (1.0 - x_time)); |
| 262 | this->output[0] += m_ac_shift; |
| 374 | 263 | break; |
| 375 | 264 | case DISC_555_OUT_LOGIC_X: |
| 376 | | node->output[0] = flip_flop + x_time; |
| 265 | this->output[0] = flip_flop + x_time; |
| 377 | 266 | break; |
| 378 | 267 | case DISC_555_OUT_COUNT_F_X: |
| 379 | | node->output[0] = count_f ? count_f + x_time : count_f; |
| 268 | this->output[0] = count_f ? count_f + x_time : count_f; |
| 380 | 269 | break; |
| 381 | 270 | case DISC_555_OUT_COUNT_R_X: |
| 382 | | node->output[0] = count_r ? count_r + x_time : count_r; |
| 271 | this->output[0] = count_r ? count_r + x_time : count_r; |
| 383 | 272 | break; |
| 384 | 273 | case DISC_555_OUT_COUNT_F: |
| 385 | | node->output[0] = count_f; |
| 274 | this->output[0] = count_f; |
| 386 | 275 | break; |
| 387 | 276 | case DISC_555_OUT_COUNT_R: |
| 388 | | node->output[0] = count_r; |
| 277 | this->output[0] = count_r; |
| 389 | 278 | break; |
| 390 | 279 | } |
| 391 | | context->flip_flop = flip_flop; |
| 280 | m_flip_flop = flip_flop; |
| 392 | 281 | } |
| 393 | 282 | |
| 394 | 283 | DISCRETE_RESET(dsd_555_astbl) |
| 395 | 284 | { |
| 396 | | DISCRETE_DECLARE_CONTEXT(dsd_555_astbl) |
| 397 | 285 | DISCRETE_DECLARE_INFO(discrete_555_desc) |
| 398 | 286 | |
| 399 | | node_description *v_charge_node; |
| 287 | discrete_base_node *v_charge_node; |
| 400 | 288 | |
| 401 | | context->use_ctrlv = (node->input_is_node() >> 4) & 1; |
| 402 | | context->output_type = info->options & DISC_555_OUT_MASK; |
| 289 | m_use_ctrlv = (this->input_is_node() >> 4) & 1; |
| 290 | m_output_type = info->options & DISC_555_OUT_MASK; |
| 403 | 291 | |
| 404 | 292 | /* Use the defaults or supplied values. */ |
| 405 | | context->v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; |
| 293 | m_v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; |
| 406 | 294 | |
| 407 | 295 | /* setup v_charge or node */ |
| 408 | | v_charge_node = discrete_find_node(node->info, info->v_charge); |
| 296 | v_charge_node = this->device->discrete_find_node(info->v_charge); |
| 409 | 297 | if (v_charge_node) |
| 410 | | context->v_charge_node = &(v_charge_node->output[NODE_CHILD_NODE_NUM(info->v_charge)]); |
| 298 | m_v_charge_node = &(v_charge_node->output[NODE_CHILD_NODE_NUM(info->v_charge)]); |
| 411 | 299 | else |
| 412 | 300 | { |
| 413 | | context->v_charge = (info->v_charge == DEFAULT_555_CHARGE) ? info->v_pos : info->v_charge; |
| 414 | | context->v_charge_node = NULL; |
| 301 | m_v_charge = (info->v_charge == DEFAULT_555_CHARGE) ? info->v_pos : info->v_charge; |
| 302 | m_v_charge_node = NULL; |
| 415 | 303 | |
| 416 | | if (info->options & DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE) context->v_charge -= 0.5; |
| 304 | if (info->options & DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE) m_v_charge -= 0.5; |
| 417 | 305 | } |
| 418 | 306 | |
| 419 | | if ((DSD_555_ASTBL__CTRLV != -1) && !context->use_ctrlv) |
| 307 | if ((DSD_555_ASTBL__CTRLV != -1) && !m_use_ctrlv) |
| 420 | 308 | { |
| 421 | 309 | /* Setup based on supplied Control Voltage static value */ |
| 422 | | context->threshold = DSD_555_ASTBL__CTRLV; |
| 423 | | context->trigger = DSD_555_ASTBL__CTRLV / 2.0; |
| 310 | m_threshold = DSD_555_ASTBL__CTRLV; |
| 311 | m_trigger = DSD_555_ASTBL__CTRLV / 2.0; |
| 424 | 312 | } |
| 425 | 313 | else |
| 426 | 314 | { |
| 427 | 315 | /* Setup based on v_pos power source */ |
| 428 | | context->threshold = info->v_pos * 2.0 / 3.0; |
| 429 | | context->trigger = info->v_pos / 3.0; |
| 316 | m_threshold = info->v_pos * 2.0 / 3.0; |
| 317 | m_trigger = info->v_pos / 3.0; |
| 430 | 318 | } |
| 431 | 319 | |
| 432 | 320 | /* optimization if none of the values are nodes */ |
| 433 | | context->has_rc_nodes = 0; |
| 434 | | if (node->input_is_node() & DSD_555_ASTBL_RC_MASK) |
| 435 | | context->has_rc_nodes = 1; |
| 321 | m_has_rc_nodes = 0; |
| 322 | if (this->input_is_node() & DSD_555_ASTBL_RC_MASK) |
| 323 | m_has_rc_nodes = 1; |
| 436 | 324 | else |
| 437 | 325 | { |
| 438 | | context->t_rc_bleed = DSD_555_ASTBL_T_RC_BLEED; |
| 439 | | context->exp_bleed = RC_CHARGE_EXP(context->t_rc_bleed); |
| 440 | | context->t_rc_charge = DSD_555_ASTBL_T_RC_CHARGE; |
| 441 | | context->exp_charge = RC_CHARGE_EXP(context->t_rc_charge); |
| 442 | | context->t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE; |
| 443 | | context->exp_discharge = RC_CHARGE_EXP(context->t_rc_discharge); |
| 326 | m_t_rc_bleed = DSD_555_ASTBL_T_RC_BLEED; |
| 327 | m_exp_bleed = RC_CHARGE_EXP_CLASS(m_t_rc_bleed); |
| 328 | m_t_rc_charge = DSD_555_ASTBL_T_RC_CHARGE; |
| 329 | m_exp_charge = RC_CHARGE_EXP_CLASS(m_t_rc_charge); |
| 330 | m_t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE; |
| 331 | m_exp_discharge = RC_CHARGE_EXP_CLASS(m_t_rc_discharge); |
| 444 | 332 | } |
| 445 | 333 | |
| 446 | | context->output_is_ac = info->options & DISC_555_OUT_AC; |
| 334 | m_output_is_ac = info->options & DISC_555_OUT_AC; |
| 447 | 335 | /* Calculate DC shift needed to make squarewave waveform AC */ |
| 448 | | context->ac_shift = context->output_is_ac ? -context->v_out_high / 2.0 : 0; |
| 336 | m_ac_shift = m_output_is_ac ? -m_v_out_high / 2.0 : 0; |
| 449 | 337 | |
| 450 | | context->flip_flop = 1; |
| 451 | | context->cap_voltage = 0; |
| 338 | m_flip_flop = 1; |
| 339 | m_cap_voltage = 0; |
| 452 | 340 | |
| 453 | 341 | /* Step to set the output */ |
| 454 | | DISCRETE_STEP_CALL(dsd_555_astbl); |
| 342 | this->step(); |
| 455 | 343 | } |
| 456 | 344 | |
| 457 | 345 | |
| r10048 | r10049 | |
| 478 | 366 | |
| 479 | 367 | DISCRETE_STEP(dsd_555_mstbl) |
| 480 | 368 | { |
| 481 | | DISCRETE_DECLARE_CONTEXT(dsd_555_mstbl) |
| 482 | 369 | DISCRETE_DECLARE_INFO(discrete_555_desc) |
| 483 | 370 | |
| 484 | 371 | double v_cap; /* Current voltage on capacitor, before dt */ |
| r10048 | r10049 | |
| 487 | 374 | double out = 0; |
| 488 | 375 | int trigger = 0; |
| 489 | 376 | int trigger_type; |
| 490 | | int update_exponent = context->has_rc_nodes; |
| 377 | int update_exponent = m_has_rc_nodes; |
| 491 | 378 | int flip_flop; |
| 492 | 379 | |
| 493 | 380 | if(UNEXPECTED(DSD_555_MSTBL__RESET)) |
| 494 | 381 | { |
| 495 | 382 | /* We are in RESET */ |
| 496 | | node->output[0] = 0; |
| 497 | | context->flip_flop = 0; |
| 498 | | context->cap_voltage = 0; |
| 383 | this->output[0] = 0; |
| 384 | m_flip_flop = 0; |
| 385 | m_cap_voltage = 0; |
| 499 | 386 | return; |
| 500 | 387 | } |
| 501 | 388 | |
| 502 | | dt = node->info->sample_time; |
| 503 | | flip_flop = context->flip_flop; |
| 389 | dt = this->sample_time(); |
| 390 | flip_flop = m_flip_flop; |
| 504 | 391 | trigger_type = info->options; |
| 505 | | v_cap = context->cap_voltage; |
| 392 | v_cap = m_cap_voltage; |
| 506 | 393 | |
| 507 | 394 | switch (trigger_type & DSD_555_TRIGGER_TYPE_MASK) |
| 508 | 395 | { |
| r10048 | r10049 | |
| 512 | 399 | x_time = 1.0 - DSD_555_MSTBL__TRIGGER; |
| 513 | 400 | break; |
| 514 | 401 | case DISC_555_TRIGGER_IS_VOLTAGE: |
| 515 | | trigger = (int)(DSD_555_MSTBL__TRIGGER < context->trigger); |
| 402 | trigger = (int)(DSD_555_MSTBL__TRIGGER < m_trigger); |
| 516 | 403 | break; |
| 517 | 404 | case DISC_555_TRIGGER_IS_COUNT: |
| 518 | 405 | trigger = (int)DSD_555_MSTBL__TRIGGER; |
| r10048 | r10049 | |
| 530 | 417 | x_time = 0; |
| 531 | 418 | |
| 532 | 419 | if ((trigger_type & DISC_555_TRIGGER_DISCHARGES_CAP) && trigger) |
| 533 | | context->cap_voltage = 0; |
| 420 | m_cap_voltage = 0; |
| 534 | 421 | |
| 535 | 422 | /* Wait for trigger */ |
| 536 | 423 | if (UNEXPECTED(!flip_flop && trigger)) |
| 537 | 424 | { |
| 538 | 425 | flip_flop = 1; |
| 539 | | context->flip_flop = 1; |
| 426 | m_flip_flop = 1; |
| 540 | 427 | } |
| 541 | 428 | |
| 542 | 429 | if (flip_flop) |
| r10048 | r10049 | |
| 549 | 436 | /* The trigger voltage goes high because the cap circuit is open. |
| 550 | 437 | * and the cap discharges */ |
| 551 | 438 | v_cap = info->v_pos; /* needed for cap output type */ |
| 552 | | context->cap_voltage = 0; |
| 439 | m_cap_voltage = 0; |
| 553 | 440 | |
| 554 | 441 | if (!trigger) |
| 555 | 442 | { |
| 556 | 443 | flip_flop = 0; |
| 557 | | context->flip_flop = 0; |
| 444 | m_flip_flop = 0; |
| 558 | 445 | } |
| 559 | 446 | } |
| 560 | 447 | else |
| 561 | 448 | { |
| 562 | 449 | /* Charging */ |
| 563 | | double v_diff = context->v_charge - v_cap; |
| 450 | double v_diff = m_v_charge - v_cap; |
| 564 | 451 | |
| 565 | 452 | if (UNEXPECTED(update_exponent)) |
| 566 | 453 | exponent = RC_CHARGE_EXP_DT(DSD_555_MSTBL__R * DSD_555_MSTBL__C, dt); |
| 567 | 454 | else |
| 568 | | exponent = context->exp_charge; |
| 455 | exponent = m_exp_charge; |
| 569 | 456 | v_cap += v_diff * exponent; |
| 570 | 457 | |
| 571 | 458 | /* Has it charged past upper limit? */ |
| 572 | 459 | /* If trigger is still enabled, then we keep charging, |
| 573 | 460 | * regardless of threshold. */ |
| 574 | | if (UNEXPECTED((v_cap >= context->threshold) && !trigger)) |
| 461 | if (UNEXPECTED((v_cap >= m_threshold) && !trigger)) |
| 575 | 462 | { |
| 576 | | dt = DSD_555_MSTBL__R * DSD_555_MSTBL__C * log(1.0 / (1.0 - ((v_cap - context->threshold) / v_diff))); |
| 577 | | x_time = 1.0 - dt / node->info->sample_time; |
| 463 | dt = DSD_555_MSTBL__R * DSD_555_MSTBL__C * log(1.0 / (1.0 - ((v_cap - m_threshold) / v_diff))); |
| 464 | x_time = 1.0 - dt / this->sample_time(); |
| 578 | 465 | v_cap = 0; |
| 579 | 466 | flip_flop = 0; |
| 580 | | context->flip_flop = 0; |
| 467 | m_flip_flop = 0; |
| 581 | 468 | } |
| 582 | | context->cap_voltage = v_cap; |
| 469 | m_cap_voltage = v_cap; |
| 583 | 470 | } |
| 584 | 471 | } |
| 585 | 472 | |
| 586 | | switch (context->output_type) |
| 473 | switch (m_output_type) |
| 587 | 474 | { |
| 588 | 475 | case DISC_555_OUT_SQW: |
| 589 | | out = flip_flop * context->v_out_high - context->ac_shift; |
| 476 | out = flip_flop * m_v_out_high - m_ac_shift; |
| 590 | 477 | break; |
| 591 | 478 | case DISC_555_OUT_CAP: |
| 592 | 479 | if (x_time > 0) |
| r10048 | r10049 | |
| 594 | 481 | else |
| 595 | 482 | out = v_cap; |
| 596 | 483 | |
| 597 | | out -= context->ac_shift; |
| 484 | out -= m_ac_shift; |
| 598 | 485 | break; |
| 599 | 486 | case DISC_555_OUT_ENERGY: |
| 600 | 487 | if (x_time > 0) |
| 601 | | out = context->v_out_high * x_time; |
| 488 | out = m_v_out_high * x_time; |
| 602 | 489 | else if (flip_flop) |
| 603 | | out = context->v_out_high; |
| 490 | out = m_v_out_high; |
| 604 | 491 | else |
| 605 | 492 | out = 0; |
| 606 | 493 | |
| 607 | | out -= context->ac_shift; |
| 494 | out -= m_ac_shift; |
| 608 | 495 | break; |
| 609 | 496 | } |
| 610 | | node->output[0] = out; |
| 497 | this->output[0] = out; |
| 611 | 498 | } |
| 612 | 499 | |
| 613 | 500 | DISCRETE_RESET(dsd_555_mstbl) |
| 614 | 501 | { |
| 615 | | DISCRETE_DECLARE_CONTEXT(dsd_555_mstbl) |
| 616 | 502 | DISCRETE_DECLARE_INFO(discrete_555_desc) |
| 617 | 503 | |
| 618 | | context->output_type = info->options & DISC_555_OUT_MASK; |
| 619 | | if ((context->output_type == DISC_555_OUT_COUNT_F) || (context->output_type == DISC_555_OUT_COUNT_R)) |
| 504 | m_output_type = info->options & DISC_555_OUT_MASK; |
| 505 | if ((m_output_type == DISC_555_OUT_COUNT_F) || (m_output_type == DISC_555_OUT_COUNT_R)) |
| 620 | 506 | { |
| 621 | | discrete_log(node->info, "Invalid Output type in NODE_%d.\n", node->index()); |
| 622 | | context->output_type = DISC_555_OUT_SQW; |
| 507 | this->device->discrete_log("Invalid Output type in NODE_%d.\n", this->index()); |
| 508 | m_output_type = DISC_555_OUT_SQW; |
| 623 | 509 | } |
| 624 | 510 | |
| 625 | 511 | /* Use the defaults or supplied values. */ |
| 626 | | context->v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; |
| 627 | | context->v_charge = (info->v_charge == DEFAULT_555_CHARGE) ? info->v_pos : info->v_charge; |
| 512 | m_v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; |
| 513 | m_v_charge = (info->v_charge == DEFAULT_555_CHARGE) ? info->v_pos : info->v_charge; |
| 628 | 514 | |
| 629 | 515 | /* Setup based on v_pos power source */ |
| 630 | | context->threshold = info->v_pos * 2.0 / 3.0; |
| 631 | | context->trigger = info->v_pos / 3.0; |
| 516 | m_threshold = info->v_pos * 2.0 / 3.0; |
| 517 | m_trigger = info->v_pos / 3.0; |
| 632 | 518 | |
| 633 | 519 | /* Calculate DC shift needed to make waveform AC */ |
| 634 | 520 | if (info->options & DISC_555_OUT_AC) |
| 635 | 521 | { |
| 636 | | if (context->output_type == DISC_555_OUT_CAP) |
| 637 | | context->ac_shift = context->threshold * 3.0 /4.0; |
| 522 | if (m_output_type == DISC_555_OUT_CAP) |
| 523 | m_ac_shift = m_threshold * 3.0 /4.0; |
| 638 | 524 | else |
| 639 | | context->ac_shift = context->v_out_high / 2.0; |
| 525 | m_ac_shift = m_v_out_high / 2.0; |
| 640 | 526 | } |
| 641 | 527 | else |
| 642 | | context->ac_shift = 0; |
| 528 | m_ac_shift = 0; |
| 643 | 529 | |
| 644 | | context->trig_is_logic = (info->options & DISC_555_TRIGGER_IS_VOLTAGE) ? 0: 1; |
| 645 | | context->trig_discharges_cap = (info->options & DISC_555_TRIGGER_DISCHARGES_CAP) ? 1: 0; |
| 530 | m_trig_is_logic = (info->options & DISC_555_TRIGGER_IS_VOLTAGE) ? 0: 1; |
| 531 | m_trig_discharges_cap = (info->options & DISC_555_TRIGGER_DISCHARGES_CAP) ? 1: 0; |
| 646 | 532 | |
| 647 | | context->flip_flop = 0; |
| 648 | | context->cap_voltage = 0; |
| 533 | m_flip_flop = 0; |
| 534 | m_cap_voltage = 0; |
| 649 | 535 | |
| 650 | 536 | /* optimization if none of the values are nodes */ |
| 651 | | context->has_rc_nodes = 0; |
| 652 | | if (node->input_is_node() & DSD_555_MSTBL_RC_MASK) |
| 653 | | context->has_rc_nodes = 1; |
| 537 | m_has_rc_nodes = 0; |
| 538 | if (this->input_is_node() & DSD_555_MSTBL_RC_MASK) |
| 539 | m_has_rc_nodes = 1; |
| 654 | 540 | else |
| 655 | | context->exp_charge = RC_CHARGE_EXP(DSD_555_MSTBL__R * DSD_555_MSTBL__C); |
| 541 | m_exp_charge = RC_CHARGE_EXP_CLASS(DSD_555_MSTBL__R * DSD_555_MSTBL__C); |
| 656 | 542 | |
| 657 | | node->output[0] = 0; |
| 543 | this->output[0] = 0; |
| 658 | 544 | } |
| 659 | 545 | |
| 660 | 546 | |
| r10048 | r10049 | |
| 695 | 581 | |
| 696 | 582 | DISCRETE_STEP(dsd_555_cc) |
| 697 | 583 | { |
| 698 | | DISCRETE_DECLARE_CONTEXT(dsd_555_cc) |
| 699 | 584 | DISCRETE_DECLARE_INFO(discrete_555_cc_desc) |
| 700 | 585 | |
| 701 | 586 | int count_f = 0; |
| r10048 | r10049 | |
| 715 | 600 | double r_temp; /* play thing */ |
| 716 | 601 | double exponent; |
| 717 | 602 | UINT8 update_exponent, update_t_rc; |
| 718 | | UINT8 flip_flop = context->flip_flop; |
| 603 | UINT8 flip_flop = m_flip_flop; |
| 719 | 604 | |
| 720 | 605 | |
| 721 | 606 | if (UNEXPECTED(DSD_555_CC__RESET)) |
| 722 | 607 | { |
| 723 | 608 | /* We are in RESET */ |
| 724 | | node->output[0] = 0; |
| 725 | | context->flip_flop = 1; |
| 726 | | context->cap_voltage = 0; |
| 609 | this->output[0] = 0; |
| 610 | m_flip_flop = 1; |
| 611 | m_cap_voltage = 0; |
| 727 | 612 | return; |
| 728 | 613 | } |
| 729 | 614 | |
| 730 | | dt = node->info->sample_time; /* Change in time */ |
| 731 | | v_cap = context->cap_voltage; /* Set to voltage before change */ |
| 615 | dt = this->sample_time(); /* Change in time */ |
| 616 | v_cap = m_cap_voltage; /* Set to voltage before change */ |
| 732 | 617 | v_vcharge_limit = DSD_555_CC__VIN + info->v_cc_junction; /* the max v_cap can be and still be charged by i */ |
| 733 | 618 | /* Calculate charging current */ |
| 734 | | i = (context->v_cc_source - v_vcharge_limit) / DSD_555_CC__R; |
| 619 | i = (m_v_cc_source - v_vcharge_limit) / DSD_555_CC__R; |
| 735 | 620 | if ( i < 0) i = 0; |
| 736 | 621 | |
| 737 | 622 | if (info->options & DISCRETE_555_CC_TO_CAP) |
| r10048 | r10049 | |
| 740 | 625 | } |
| 741 | 626 | else |
| 742 | 627 | { |
| 743 | | switch (context->type) /* see dsd_555_cc_reset for descriptions */ |
| 628 | switch (m_type) /* see dsd_555_cc_reset for descriptions */ |
| 744 | 629 | { |
| 745 | 630 | case 1: |
| 746 | 631 | r_discharge = DSD_555_CC__RDIS; |
| r10048 | r10049 | |
| 781 | 666 | } |
| 782 | 667 | |
| 783 | 668 | /* Keep looping until all toggling in time sample is used up. */ |
| 784 | | update_t_rc = context->has_rc_nodes; |
| 669 | update_t_rc = m_has_rc_nodes; |
| 785 | 670 | update_exponent = update_t_rc; |
| 786 | 671 | do |
| 787 | 672 | { |
| 788 | | if (context->type <= 1) |
| 673 | if (m_type <= 1) |
| 789 | 674 | { |
| 790 | 675 | /* Standard constant current charge */ |
| 791 | 676 | if (flip_flop) |
| r10048 | r10049 | |
| 801 | 686 | exponent = RC_CHARGE_EXP_DT(t_rc, dt); |
| 802 | 687 | } |
| 803 | 688 | else |
| 804 | | exponent = context->exp_bleed; |
| 689 | exponent = m_exp_bleed; |
| 805 | 690 | v_cap_next = v_cap - (v_cap * exponent); |
| 806 | 691 | dt = 0; |
| 807 | 692 | } |
| r10048 | r10049 | |
| 819 | 704 | dt = 0; |
| 820 | 705 | |
| 821 | 706 | /* has it charged past upper limit? */ |
| 822 | | if (v_cap_next >= context->threshold) |
| 707 | if (v_cap_next >= m_threshold) |
| 823 | 708 | { |
| 824 | 709 | /* calculate the overshoot time */ |
| 825 | | dt = DSD_555_CC__C * (v_cap_next - context->threshold) / i; |
| 710 | dt = DSD_555_CC__C * (v_cap_next - m_threshold) / i; |
| 826 | 711 | x_time = dt; |
| 827 | | v_cap_next = context->threshold; |
| 712 | v_cap_next = m_threshold; |
| 828 | 713 | flip_flop = 0; |
| 829 | 714 | count_f++; |
| 830 | 715 | update_exponent = 1; |
| r10048 | r10049 | |
| 837 | 722 | if (update_t_rc) |
| 838 | 723 | t_rc = DSD_555_CC_T_RC_DISCHARGE_01; |
| 839 | 724 | else |
| 840 | | t_rc = context->t_rc_discharge_01; |
| 725 | t_rc = m_t_rc_discharge_01; |
| 841 | 726 | if (update_exponent) |
| 842 | 727 | exponent = RC_CHARGE_EXP_DT(t_rc, dt); |
| 843 | 728 | else |
| 844 | | exponent = context->exp_discharge_01; |
| 729 | exponent = m_exp_discharge_01; |
| 845 | 730 | |
| 846 | 731 | if (info->options & DISCRETE_555_CC_TO_CAP) |
| 847 | 732 | { |
| r10048 | r10049 | |
| 859 | 744 | |
| 860 | 745 | dt = 0; |
| 861 | 746 | /* has it discharged past lower limit? */ |
| 862 | | if (v_cap_next <= context->trigger) |
| 747 | if (v_cap_next <= m_trigger) |
| 863 | 748 | { |
| 864 | | dt = t_rc * log(1.0 / (1.0 - ((context->trigger - v_cap_next) / v_cap))); |
| 749 | dt = t_rc * log(1.0 / (1.0 - ((m_trigger - v_cap_next) / v_cap))); |
| 865 | 750 | x_time = dt; |
| 866 | | v_cap_next = context->trigger; |
| 751 | v_cap_next = m_trigger; |
| 867 | 752 | flip_flop = 1; |
| 868 | 753 | count_r++; |
| 869 | 754 | update_exponent = 1; |
| r10048 | r10049 | |
| 872 | 757 | else /* Immediate discharge. No change in dt. */ |
| 873 | 758 | { |
| 874 | 759 | x_time = dt; |
| 875 | | v_cap_next = context->trigger; |
| 760 | v_cap_next = m_trigger; |
| 876 | 761 | flip_flop = 1; |
| 877 | 762 | count_r++; |
| 878 | 763 | } |
| r10048 | r10049 | |
| 890 | 775 | if (update_t_rc) |
| 891 | 776 | t_rc = DSD_555_CC_T_RC_DISCHARGE_NO_I; |
| 892 | 777 | else |
| 893 | | t_rc = context->t_rc_discharge_no_i; |
| 778 | t_rc = m_t_rc_discharge_no_i; |
| 894 | 779 | if (update_exponent) |
| 895 | 780 | exponent = RC_CHARGE_EXP_DT(t_rc, dt); |
| 896 | 781 | else |
| 897 | | exponent = context->exp_discharge_no_i; |
| 782 | exponent = m_exp_discharge_no_i; |
| 898 | 783 | |
| 899 | 784 | v_cap_next = v_cap - (v_cap * exponent); |
| 900 | 785 | dt = 0; |
| r10048 | r10049 | |
| 906 | 791 | * then only the bias voltage will charge the cap. */ |
| 907 | 792 | v = v_bias; |
| 908 | 793 | if (v_cap < v_vcharge_limit) v += vi; |
| 909 | | else if (context->type <= 3) v = v_vcharge_limit; |
| 794 | else if (m_type <= 3) v = v_vcharge_limit; |
| 910 | 795 | |
| 911 | 796 | if (update_t_rc) |
| 912 | 797 | t_rc = DSD_555_CC_T_RC_CHARGE; |
| 913 | 798 | else |
| 914 | | t_rc = context->t_rc_charge; |
| 799 | t_rc = m_t_rc_charge; |
| 915 | 800 | if (update_exponent) |
| 916 | 801 | exponent = RC_CHARGE_EXP_DT(t_rc, dt); |
| 917 | 802 | else |
| 918 | | exponent = context->exp_charge; |
| 803 | exponent = m_exp_charge; |
| 919 | 804 | |
| 920 | 805 | v_cap_next = v_cap + ((v - v_cap) * exponent); |
| 921 | 806 | dt = 0; |
| 922 | 807 | |
| 923 | 808 | /* has it charged past upper limit? */ |
| 924 | | if (v_cap_next >= context->threshold) |
| 809 | if (v_cap_next >= m_threshold) |
| 925 | 810 | { |
| 926 | 811 | /* calculate the overshoot time */ |
| 927 | | dt = t_rc * log(1.0 / (1.0 - ((v_cap_next - context->threshold) / (v - v_cap)))); |
| 812 | dt = t_rc * log(1.0 / (1.0 - ((v_cap_next - m_threshold) / (v - v_cap)))); |
| 928 | 813 | x_time = dt; |
| 929 | | v_cap_next = context->threshold; |
| 814 | v_cap_next = m_threshold; |
| 930 | 815 | flip_flop = 0; |
| 931 | 816 | count_f++; |
| 932 | 817 | update_exponent = 1; |
| r10048 | r10049 | |
| 939 | 824 | if (update_t_rc) |
| 940 | 825 | t_rc = DSD_555_CC_T_RC_DISCHARGE; |
| 941 | 826 | else |
| 942 | | t_rc = context->t_rc_discharge; |
| 827 | t_rc = m_t_rc_discharge; |
| 943 | 828 | if (update_exponent) |
| 944 | 829 | exponent = RC_CHARGE_EXP_DT(t_rc, dt); |
| 945 | 830 | else |
| 946 | | exponent = context->exp_discharge; |
| 831 | exponent = m_exp_discharge; |
| 947 | 832 | |
| 948 | 833 | v_cap_next = v_cap - (v_cap * exponent); |
| 949 | 834 | dt = 0; |
| 950 | 835 | |
| 951 | 836 | /* has it discharged past lower limit? */ |
| 952 | | if (v_cap_next <= context->trigger) |
| 837 | if (v_cap_next <= m_trigger) |
| 953 | 838 | { |
| 954 | 839 | /* calculate the overshoot time */ |
| 955 | | dt = t_rc * log(1.0 / (1.0 - ((context->trigger - v_cap_next) / v_cap))); |
| 840 | dt = t_rc * log(1.0 / (1.0 - ((m_trigger - v_cap_next) / v_cap))); |
| 956 | 841 | x_time = dt; |
| 957 | | v_cap_next = context->trigger; |
| 842 | v_cap_next = m_trigger; |
| 958 | 843 | flip_flop = 1; |
| 959 | 844 | count_r++; |
| 960 | 845 | update_exponent = 1; |
| r10048 | r10049 | |
| 963 | 848 | else /* Immediate discharge. No change in dt. */ |
| 964 | 849 | { |
| 965 | 850 | x_time = dt; |
| 966 | | v_cap_next = context->trigger; |
| 851 | v_cap_next = m_trigger; |
| 967 | 852 | flip_flop = 1; |
| 968 | 853 | count_r++; |
| 969 | 854 | } |
| r10048 | r10049 | |
| 971 | 856 | v_cap = v_cap_next; |
| 972 | 857 | } while(dt); |
| 973 | 858 | |
| 974 | | context->cap_voltage = v_cap; |
| 859 | m_cap_voltage = v_cap; |
| 975 | 860 | |
| 976 | 861 | /* Convert last switch time to a ratio */ |
| 977 | | x_time = x_time / node->info->sample_time; |
| 862 | x_time = x_time / this->sample_time(); |
| 978 | 863 | |
| 979 | | switch (context->output_type) |
| 864 | switch (m_output_type) |
| 980 | 865 | { |
| 981 | 866 | case DISC_555_OUT_SQW: |
| 982 | 867 | if (count_f + count_r >= 2) |
| 983 | 868 | /* force at least 1 toggle */ |
| 984 | | node->output[0] = context->flip_flop ? 0 : context->v_out_high; |
| 869 | this->output[0] = m_flip_flop ? 0 : m_v_out_high; |
| 985 | 870 | else |
| 986 | | node->output[0] = flip_flop * context->v_out_high; |
| 871 | this->output[0] = flip_flop * m_v_out_high; |
| 987 | 872 | /* Fake it to AC if needed */ |
| 988 | | node->output[0] += context->ac_shift; |
| 873 | this->output[0] += m_ac_shift; |
| 989 | 874 | break; |
| 990 | 875 | case DISC_555_OUT_CAP: |
| 991 | | node->output[0] = v_cap + context->ac_shift; |
| 876 | this->output[0] = v_cap + m_ac_shift; |
| 992 | 877 | break; |
| 993 | 878 | case DISC_555_OUT_ENERGY: |
| 994 | 879 | if (x_time == 0) x_time = 1.0; |
| 995 | | node->output[0] = context->v_out_high * (flip_flop ? x_time : (1.0 - x_time)); |
| 996 | | node->output[0] += context->ac_shift; |
| 880 | this->output[0] = m_v_out_high * (flip_flop ? x_time : (1.0 - x_time)); |
| 881 | this->output[0] += m_ac_shift; |
| 997 | 882 | break; |
| 998 | 883 | case DISC_555_OUT_LOGIC_X: |
| 999 | | node->output[0] = flip_flop + x_time; |
| 884 | this->output[0] = flip_flop + x_time; |
| 1000 | 885 | break; |
| 1001 | 886 | case DISC_555_OUT_COUNT_F_X: |
| 1002 | | node->output[0] = count_f ? count_f + x_time : count_f; |
| 887 | this->output[0] = count_f ? count_f + x_time : count_f; |
| 1003 | 888 | break; |
| 1004 | 889 | case DISC_555_OUT_COUNT_R_X: |
| 1005 | | node->output[0] = count_r ? count_r + x_time : count_r; |
| 890 | this->output[0] = count_r ? count_r + x_time : count_r; |
| 1006 | 891 | break; |
| 1007 | 892 | case DISC_555_OUT_COUNT_F: |
| 1008 | | node->output[0] = count_f; |
| 893 | this->output[0] = count_f; |
| 1009 | 894 | break; |
| 1010 | 895 | case DISC_555_OUT_COUNT_R: |
| 1011 | | node->output[0] = count_r; |
| 896 | this->output[0] = count_r; |
| 1012 | 897 | break; |
| 1013 | 898 | } |
| 1014 | | context->flip_flop = flip_flop; |
| 899 | m_flip_flop = flip_flop; |
| 1015 | 900 | } |
| 1016 | 901 | |
| 1017 | 902 | DISCRETE_RESET(dsd_555_cc) |
| 1018 | 903 | { |
| 1019 | | DISCRETE_DECLARE_CONTEXT(dsd_555_cc) |
| 1020 | 904 | DISCRETE_DECLARE_INFO(discrete_555_cc_desc) |
| 1021 | 905 | |
| 1022 | 906 | double r_temp, r_discharge = 0, r_charge = 0; |
| 1023 | 907 | |
| 1024 | | context->flip_flop = 1; |
| 1025 | | context->cap_voltage = 0; |
| 908 | m_flip_flop = 1; |
| 909 | m_cap_voltage = 0; |
| 1026 | 910 | |
| 1027 | | context->output_type = info->options & DISC_555_OUT_MASK; |
| 911 | m_output_type = info->options & DISC_555_OUT_MASK; |
| 1028 | 912 | |
| 1029 | 913 | /* Use the defaults or supplied values. */ |
| 1030 | | context->v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; |
| 1031 | | context->v_cc_source = (info->v_cc_source == DEFAULT_555_CC_SOURCE) ? info->v_pos : info->v_cc_source; |
| 914 | m_v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; |
| 915 | m_v_cc_source = (info->v_cc_source == DEFAULT_555_CC_SOURCE) ? info->v_pos : info->v_cc_source; |
| 1032 | 916 | |
| 1033 | 917 | /* Setup based on v_pos power source */ |
| 1034 | | context->threshold = info->v_pos * 2.0 / 3.0; |
| 1035 | | context->trigger = info->v_pos / 3.0; |
| 918 | m_threshold = info->v_pos * 2.0 / 3.0; |
| 919 | m_trigger = info->v_pos / 3.0; |
| 1036 | 920 | |
| 1037 | | context->output_is_ac = info->options & DISC_555_OUT_AC; |
| 921 | m_output_is_ac = info->options & DISC_555_OUT_AC; |
| 1038 | 922 | /* Calculate DC shift needed to make squarewave waveform AC */ |
| 1039 | | context->ac_shift = context->output_is_ac ? -context->v_out_high / 2.0 : 0; |
| 923 | m_ac_shift = m_output_is_ac ? -m_v_out_high / 2.0 : 0; |
| 1040 | 924 | |
| 1041 | 925 | /* There are 8 different types of basic oscillators |
| 1042 | 926 | * depending on the resistors used. We will determine |
| 1043 | 927 | * the type of circuit at reset, because the ciruit type |
| 1044 | 928 | * is constant. See Below. |
| 1045 | 929 | */ |
| 1046 | | context->type = (DSD_555_CC__RDIS > 0) | ((DSD_555_CC__RGND > 0) << 1) | ((DSD_555_CC__RBIAS > 0) << 2); |
| 930 | m_type = (DSD_555_CC__RDIS > 0) | ((DSD_555_CC__RGND > 0) << 1) | ((DSD_555_CC__RBIAS > 0) << 2); |
| 1047 | 931 | |
| 1048 | 932 | /* optimization if none of the values are nodes */ |
| 1049 | | context->has_rc_nodes = 0; |
| 1050 | | if (node->input_is_node() & DSD_555_CC_RC_MASK) |
| 1051 | | context->has_rc_nodes = 1; |
| 933 | m_has_rc_nodes = 0; |
| 934 | if (this->input_is_node() & DSD_555_CC_RC_MASK) |
| 935 | m_has_rc_nodes = 1; |
| 1052 | 936 | else |
| 1053 | 937 | { |
| 1054 | | switch (context->type) /* see dsd_555_cc_reset for descriptions */ |
| 938 | switch (m_type) /* see dsd_555_cc_reset for descriptions */ |
| 1055 | 939 | { |
| 1056 | 940 | case 1: |
| 1057 | 941 | r_discharge = DSD_555_CC__RDIS; |
| r10048 | r10049 | |
| 1079 | 963 | break; |
| 1080 | 964 | } |
| 1081 | 965 | |
| 1082 | | context->exp_bleed = RC_CHARGE_EXP(DSD_555_CC_T_RC_BLEED); |
| 1083 | | context->t_rc_discharge_01 = DSD_555_CC_T_RC_DISCHARGE_01; |
| 1084 | | context->exp_discharge_01 = RC_CHARGE_EXP(context->t_rc_discharge_01); |
| 1085 | | context->t_rc_discharge_no_i = DSD_555_CC_T_RC_DISCHARGE_NO_I; |
| 1086 | | context->exp_discharge_no_i = RC_CHARGE_EXP(context->t_rc_discharge_no_i); |
| 1087 | | context->t_rc_charge = DSD_555_CC_T_RC_CHARGE; |
| 1088 | | context->exp_charge = RC_CHARGE_EXP(context->t_rc_charge); |
| 1089 | | context->t_rc_discharge = DSD_555_CC_T_RC_DISCHARGE; |
| 1090 | | context->exp_discharge = RC_CHARGE_EXP(context->t_rc_discharge); |
| 966 | m_exp_bleed = RC_CHARGE_EXP_CLASS(DSD_555_CC_T_RC_BLEED); |
| 967 | m_t_rc_discharge_01 = DSD_555_CC_T_RC_DISCHARGE_01; |
| 968 | m_exp_discharge_01 = RC_CHARGE_EXP_CLASS(m_t_rc_discharge_01); |
| 969 | m_t_rc_discharge_no_i = DSD_555_CC_T_RC_DISCHARGE_NO_I; |
| 970 | m_exp_discharge_no_i = RC_CHARGE_EXP_CLASS(m_t_rc_discharge_no_i); |
| 971 | m_t_rc_charge = DSD_555_CC_T_RC_CHARGE; |
| 972 | m_exp_charge = RC_CHARGE_EXP_CLASS(m_t_rc_charge); |
| 973 | m_t_rc_discharge = DSD_555_CC_T_RC_DISCHARGE; |
| 974 | m_exp_discharge = RC_CHARGE_EXP_CLASS(m_t_rc_discharge); |
| 1091 | 975 | } |
| 1092 | 976 | |
| 1093 | 977 | /* Step to set the output */ |
| 1094 | | DISCRETE_STEP_CALL(dsd_555_cc); |
| 978 | this->step(); |
| 1095 | 979 | |
| 1096 | 980 | /* |
| 1097 | 981 | * TYPES: |
| r10048 | r10049 | |
| 1246 | 1130 | |
| 1247 | 1131 | DISCRETE_STEP(dsd_555_vco1) |
| 1248 | 1132 | { |
| 1249 | | DISCRETE_DECLARE_CONTEXT(dsd_555_vco1) |
| 1250 | 1133 | DISCRETE_DECLARE_INFO(discrete_555_vco1_desc) |
| 1251 | 1134 | |
| 1252 | 1135 | int count_f = 0; |
| r10048 | r10049 | |
| 1256 | 1139 | double v_cap; /* Current voltage on capacitor, before dt */ |
| 1257 | 1140 | double v_cap_next = 0; /* Voltage on capacitor, after dt */ |
| 1258 | 1141 | |
| 1259 | | dt = node->info->sample_time; /* Change in time */ |
| 1260 | | v_cap = context->cap_voltage; |
| 1142 | dt = this->sample_time(); /* Change in time */ |
| 1143 | v_cap = m_cap_voltage; |
| 1261 | 1144 | |
| 1262 | 1145 | /* Check: if the Control Voltage node is connected. */ |
| 1263 | | if (context->ctrlv_is_node && DSD_555_VCO1__RESET) /* reset active low */ |
| 1146 | if (m_ctrlv_is_node && DSD_555_VCO1__RESET) /* reset active low */ |
| 1264 | 1147 | { |
| 1265 | 1148 | /* If CV is less then .25V, the circuit will oscillate way out of range. |
| 1266 | 1149 | * So we will just ignore it when it happens. */ |
| 1267 | 1150 | if (DSD_555_VCO1__VIN2 < .25) return; |
| 1268 | 1151 | /* If it is a node then calculate thresholds based on Control Voltage */ |
| 1269 | | context->threshold = DSD_555_VCO1__VIN2; |
| 1270 | | context->trigger = DSD_555_VCO1__VIN2 / 2.0; |
| 1152 | m_threshold = DSD_555_VCO1__VIN2; |
| 1153 | m_trigger = DSD_555_VCO1__VIN2 / 2.0; |
| 1271 | 1154 | /* Since the thresholds may have changed we need to update the FF */ |
| 1272 | | if (v_cap >= context->threshold) |
| 1155 | if (v_cap >= m_threshold) |
| 1273 | 1156 | { |
| 1274 | 1157 | x_time = dt; |
| 1275 | | context->flip_flop = 0; |
| 1158 | m_flip_flop = 0; |
| 1276 | 1159 | count_f++; |
| 1277 | 1160 | } |
| 1278 | 1161 | else |
| 1279 | | if (v_cap <= context->trigger) |
| 1162 | if (v_cap <= m_trigger) |
| 1280 | 1163 | { |
| 1281 | 1164 | x_time = dt; |
| 1282 | | context->flip_flop = 1; |
| 1165 | m_flip_flop = 1; |
| 1283 | 1166 | count_r++; |
| 1284 | 1167 | } |
| 1285 | 1168 | } |
| r10048 | r10049 | |
| 1287 | 1170 | /* Keep looping until all toggling in time sample is used up. */ |
| 1288 | 1171 | do |
| 1289 | 1172 | { |
| 1290 | | if (context->flip_flop) |
| 1173 | if (m_flip_flop) |
| 1291 | 1174 | { |
| 1292 | 1175 | /* if we are in reset then toggle f/f and discharge */ |
| 1293 | 1176 | if (!DSD_555_VCO1__RESET) /* reset active low */ |
| 1294 | 1177 | { |
| 1295 | | context->flip_flop = 0; |
| 1178 | m_flip_flop = 0; |
| 1296 | 1179 | count_f++; |
| 1297 | 1180 | } |
| 1298 | 1181 | else |
| 1299 | 1182 | { |
| 1300 | 1183 | /* Charging */ |
| 1301 | 1184 | /* iC=C*dv/dt works out to dv=iC*dt/C */ |
| 1302 | | v_cap_next = v_cap + (context->i_charge * dt / info->c); |
| 1185 | v_cap_next = v_cap + (m_i_charge * dt / info->c); |
| 1303 | 1186 | dt = 0; |
| 1304 | 1187 | |
| 1305 | 1188 | /* has it charged past upper limit? */ |
| 1306 | | if (v_cap_next >= context->threshold) |
| 1189 | if (v_cap_next >= m_threshold) |
| 1307 | 1190 | { |
| 1308 | 1191 | /* calculate the overshoot time */ |
| 1309 | | dt = info->c * (v_cap_next - context->threshold) / context->i_charge; |
| 1310 | | v_cap = context->threshold; |
| 1192 | dt = info->c * (v_cap_next - m_threshold) / m_i_charge; |
| 1193 | v_cap = m_threshold; |
| 1311 | 1194 | x_time = dt; |
| 1312 | | context->flip_flop = 0; |
| 1195 | m_flip_flop = 0; |
| 1313 | 1196 | count_f++; |
| 1314 | 1197 | } |
| 1315 | 1198 | } |
| r10048 | r10049 | |
| 1318 | 1201 | { |
| 1319 | 1202 | /* Discharging */ |
| 1320 | 1203 | /* iC=C*dv/dt works out to dv=iC*dt/C */ |
| 1321 | | v_cap_next = v_cap - (context->i_discharge * dt / info->c); |
| 1204 | v_cap_next = v_cap - (m_i_discharge * dt / info->c); |
| 1322 | 1205 | |
| 1323 | 1206 | /* if we are in reset, then the cap can discharge to 0 */ |
| 1324 | 1207 | if (!DSD_555_VCO1__RESET) /* reset active low */ |
| r10048 | r10049 | |
| 1330 | 1213 | { |
| 1331 | 1214 | /* if we are out of reset and the cap voltage is less then |
| 1332 | 1215 | * the lower threshold, toggle f/f and start charging */ |
| 1333 | | if (v_cap <= context->trigger) |
| 1216 | if (v_cap <= m_trigger) |
| 1334 | 1217 | { |
| 1335 | | if (context->flip_flop == 0) |
| 1218 | if (m_flip_flop == 0) |
| 1336 | 1219 | { |
| 1337 | 1220 | /* don't need to track x_time here */ |
| 1338 | | context->flip_flop = 1; |
| 1221 | m_flip_flop = 1; |
| 1339 | 1222 | count_r++; |
| 1340 | 1223 | } |
| 1341 | 1224 | } |
| r10048 | r10049 | |
| 1343 | 1226 | { |
| 1344 | 1227 | dt = 0; |
| 1345 | 1228 | /* has it discharged past lower limit? */ |
| 1346 | | if (v_cap_next <= context->trigger) |
| 1229 | if (v_cap_next <= m_trigger) |
| 1347 | 1230 | { |
| 1348 | 1231 | /* calculate the overshoot time */ |
| 1349 | | dt = info->c * (v_cap_next - context->trigger) / context->i_discharge; |
| 1350 | | v_cap = context->trigger; |
| 1232 | dt = info->c * (v_cap_next - m_trigger) / m_i_discharge; |
| 1233 | v_cap = m_trigger; |
| 1351 | 1234 | x_time = dt; |
| 1352 | | context->flip_flop = 1; |
| 1235 | m_flip_flop = 1; |
| 1353 | 1236 | count_r++; |
| 1354 | 1237 | } |
| 1355 | 1238 | } |
| r10048 | r10049 | |
| 1357 | 1240 | } |
| 1358 | 1241 | } while(dt); |
| 1359 | 1242 | |
| 1360 | | context->cap_voltage = v_cap_next; |
| 1243 | m_cap_voltage = v_cap_next; |
| 1361 | 1244 | |
| 1362 | 1245 | /* Convert last switch time to a ratio. No x_time in reset. */ |
| 1363 | | x_time = x_time / node->info->sample_time; |
| 1246 | x_time = x_time / this->sample_time(); |
| 1364 | 1247 | if (!DSD_555_VCO1__RESET) x_time = 0; |
| 1365 | 1248 | |
| 1366 | | switch (context->output_type) |
| 1249 | switch (m_output_type) |
| 1367 | 1250 | { |
| 1368 | 1251 | case DISC_555_OUT_SQW: |
| 1369 | | node->output[0] = context->flip_flop * context->v_out_high + context->ac_shift; |
| 1252 | this->output[0] = m_flip_flop * m_v_out_high + m_ac_shift; |
| 1370 | 1253 | break; |
| 1371 | 1254 | case DISC_555_OUT_CAP: |
| 1372 | | node->output[0] = v_cap_next; |
| 1255 | this->output[0] = v_cap_next; |
| 1373 | 1256 | /* Fake it to AC if needed */ |
| 1374 | | if (context->output_is_ac) |
| 1375 | | node->output[0] -= context->threshold * 3.0 /4.0; |
| 1257 | if (m_output_is_ac) |
| 1258 | this->output[0] -= m_threshold * 3.0 /4.0; |
| 1376 | 1259 | break; |
| 1377 | 1260 | case DISC_555_OUT_ENERGY: |
| 1378 | 1261 | if (x_time == 0) x_time = 1.0; |
| 1379 | | node->output[0] = context->v_out_high * (context->flip_flop ? x_time : (1.0 - x_time)); |
| 1380 | | node->output[0] += context->ac_shift; |
| 1262 | this->output[0] = m_v_out_high * (m_flip_flop ? x_time : (1.0 - x_time)); |
| 1263 | this->output[0] += m_ac_shift; |
| 1381 | 1264 | break; |
| 1382 | 1265 | case DISC_555_OUT_LOGIC_X: |
| 1383 | | node->output[0] = context->flip_flop + x_time; |
| 1266 | this->output[0] = m_flip_flop + x_time; |
| 1384 | 1267 | break; |
| 1385 | 1268 | case DISC_555_OUT_COUNT_F_X: |
| 1386 | | node->output[0] = count_f ? count_f + x_time : count_f; |
| 1269 | this->output[0] = count_f ? count_f + x_time : count_f; |
| 1387 | 1270 | break; |
| 1388 | 1271 | case DISC_555_OUT_COUNT_R_X: |
| 1389 | | node->output[0] = count_r ? count_r + x_time : count_r; |
| 1272 | this->output[0] = count_r ? count_r + x_time : count_r; |
| 1390 | 1273 | break; |
| 1391 | 1274 | case DISC_555_OUT_COUNT_F: |
| 1392 | | node->output[0] = count_f; |
| 1275 | this->output[0] = count_f; |
| 1393 | 1276 | break; |
| 1394 | 1277 | case DISC_555_OUT_COUNT_R: |
| 1395 | | node->output[0] = count_r; |
| 1278 | this->output[0] = count_r; |
| 1396 | 1279 | break; |
| 1397 | 1280 | } |
| 1398 | 1281 | } |
| 1399 | 1282 | |
| 1400 | 1283 | DISCRETE_RESET(dsd_555_vco1) |
| 1401 | 1284 | { |
| 1402 | | DISCRETE_DECLARE_CONTEXT(dsd_555_vco1) |
| 1403 | 1285 | DISCRETE_DECLARE_INFO(discrete_555_vco1_desc) |
| 1404 | 1286 | |
| 1405 | 1287 | double v_ratio_r3, v_ratio_r4_1, r_in_1; |
| 1406 | 1288 | |
| 1407 | | context->output_type = info->options & DISC_555_OUT_MASK; |
| 1408 | | context->output_is_ac = info->options & DISC_555_OUT_AC; |
| 1289 | m_output_type = info->options & DISC_555_OUT_MASK; |
| 1290 | m_output_is_ac = info->options & DISC_555_OUT_AC; |
| 1409 | 1291 | |
| 1410 | 1292 | /* Setup op-amp parameters */ |
| 1411 | 1293 | |
| r10048 | r10049 | |
| 1423 | 1305 | |
| 1424 | 1306 | /* Now that we know the voltages entering the op amp and the resistance for the |
| 1425 | 1307 | * FF states, we can predetermine the ratios for the charge/discharge currents. */ |
| 1426 | | context->i_discharge = (1 - v_ratio_r3) / info->r1; |
| 1427 | | context->i_charge = (v_ratio_r3 - v_ratio_r4_1) / r_in_1; |
| 1308 | m_i_discharge = (1 - v_ratio_r3) / info->r1; |
| 1309 | m_i_charge = (v_ratio_r3 - v_ratio_r4_1) / r_in_1; |
| 1428 | 1310 | |
| 1429 | 1311 | /* the cap starts off discharged */ |
| 1430 | | context->cap_voltage = 0; |
| 1312 | m_cap_voltage = 0; |
| 1431 | 1313 | |
| 1432 | 1314 | /* Setup 555 parameters */ |
| 1433 | 1315 | |
| 1434 | 1316 | /* There is no charge on the cap so the 555 goes high at init. */ |
| 1435 | | context->flip_flop = 1; |
| 1436 | | context->ctrlv_is_node = (node->input_is_node() >> 2) & 1; |
| 1437 | | context->v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; |
| 1317 | m_flip_flop = 1; |
| 1318 | m_ctrlv_is_node = (this->input_is_node() >> 2) & 1; |
| 1319 | m_v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; |
| 1438 | 1320 | |
| 1439 | 1321 | /* Calculate 555 thresholds. |
| 1440 | 1322 | * If the Control Voltage is a node, then the thresholds will be calculated each step. |
| 1441 | 1323 | * If the Control Voltage is a fixed voltage, then the thresholds will be calculated |
| 1442 | 1324 | * from that. Otherwise we will use thresholds based on v_pos. */ |
| 1443 | | if (!context->ctrlv_is_node && (DSD_555_VCO1__VIN2 != -1)) |
| 1325 | if (!m_ctrlv_is_node && (DSD_555_VCO1__VIN2 != -1)) |
| 1444 | 1326 | { |
| 1445 | 1327 | /* Setup based on supplied Control Voltage static value */ |
| 1446 | | context->threshold = DSD_555_VCO1__VIN2; |
| 1447 | | context->trigger = DSD_555_VCO1__VIN2 / 2.0; |
| 1328 | m_threshold = DSD_555_VCO1__VIN2; |
| 1329 | m_trigger = DSD_555_VCO1__VIN2 / 2.0; |
| 1448 | 1330 | } |
| 1449 | 1331 | else |
| 1450 | 1332 | { |
| 1451 | 1333 | /* Setup based on v_pos power source */ |
| 1452 | | context->threshold = info->v_pos * 2.0 / 3.0; |
| 1453 | | context->trigger = info->v_pos / 3.0; |
| 1334 | m_threshold = info->v_pos * 2.0 / 3.0; |
| 1335 | m_trigger = info->v_pos / 3.0; |
| 1454 | 1336 | } |
| 1455 | 1337 | |
| 1456 | 1338 | /* Calculate DC shift needed to make squarewave waveform AC */ |
| 1457 | | context->ac_shift = context->output_is_ac ? -context->v_out_high / 2.0 : 0; |
| 1339 | m_ac_shift = m_output_is_ac ? -m_v_out_high / 2.0 : 0; |
| 1458 | 1340 | } |
| 1459 | 1341 | |
| 1460 | 1342 | |
| r10048 | r10049 | |
| 1537 | 1419 | |
| 1538 | 1420 | DISCRETE_STEP(dsd_566) |
| 1539 | 1421 | { |
| 1540 | | DISCRETE_DECLARE_CONTEXT(dsd_566) |
| 1541 | | |
| 1542 | 1422 | double i = 0; /* Charging current created by vIn */ |
| 1543 | 1423 | double i_rise; /* non-linear rise charge current */ |
| 1544 | 1424 | double dt; /* change in time */ |
| r10048 | r10049 | |
| 1546 | 1426 | double v_cap; /* Current voltage on capacitor, before dt */ |
| 1547 | 1427 | int count_f = 0, count_r = 0; |
| 1548 | 1428 | |
| 1549 | | dt = node->info->sample_time; /* Change in time */ |
| 1550 | | v_cap = context->cap_voltage; /* Set to voltage before change */ |
| 1429 | dt = this->sample_time(); /* Change in time */ |
| 1430 | v_cap = m_cap_voltage; /* Set to voltage before change */ |
| 1551 | 1431 | |
| 1552 | 1432 | /* Calculate charging current if it is in range */ |
| 1553 | | if (EXPECTED(DSD_566__VMOD > context->v_osc_stop)) |
| 1433 | if (EXPECTED(DSD_566__VMOD > m_v_osc_stop)) |
| 1554 | 1434 | { |
| 1555 | 1435 | double v_charge = DSD_566__VCHARGE - DSD_566__VMOD - 0.1; |
| 1556 | 1436 | if (v_charge > 0) |
| 1557 | 1437 | { |
| 1558 | 1438 | i = (v_charge * .95) / DSD_566__R; |
| 1559 | | if (DSD_566__VMOD < context->v_osc_stable) |
| 1439 | if (DSD_566__VMOD < m_v_osc_stable) |
| 1560 | 1440 | { |
| 1561 | 1441 | /* no where near correct calculation of non linear range */ |
| 1562 | | i_rise = ((DSD_566__VCHARGE - context->v_osc_stable - 0.1) * .95) / DSD_566__R; |
| 1563 | | i_rise *= 1.0 - (context->v_osc_stable - DSD_566__VMOD) / (context->v_osc_stable - context->v_osc_stop); |
| 1442 | i_rise = ((DSD_566__VCHARGE - m_v_osc_stable - 0.1) * .95) / DSD_566__R; |
| 1443 | i_rise *= 1.0 - (m_v_osc_stable - DSD_566__VMOD) / (m_v_osc_stable - m_v_osc_stop); |
| 1564 | 1444 | } |
| 1565 | 1445 | else |
| 1566 | 1446 | i_rise = i; |
| r10048 | r10049 | |
| 1573 | 1453 | /* Keep looping until all toggling in this time sample is used up. */ |
| 1574 | 1454 | do |
| 1575 | 1455 | { |
| 1576 | | if (context->flip_flop) |
| 1456 | if (m_flip_flop) |
| 1577 | 1457 | { |
| 1578 | 1458 | /* Discharging */ |
| 1579 | 1459 | v_cap -= i * dt / DSD_566__C; |
| 1580 | 1460 | dt = 0; |
| 1581 | 1461 | |
| 1582 | 1462 | /* has it discharged past lower limit? */ |
| 1583 | | if (UNEXPECTED(v_cap < context->threshold_low)) |
| 1463 | if (UNEXPECTED(v_cap < m_threshold_low)) |
| 1584 | 1464 | { |
| 1585 | 1465 | /* calculate the overshoot time */ |
| 1586 | | dt = DSD_566__C * (context->threshold_low - v_cap) / i; |
| 1587 | | v_cap = context->threshold_low; |
| 1588 | | context->flip_flop = 0; |
| 1466 | dt = DSD_566__C * (m_threshold_low - v_cap) / i; |
| 1467 | v_cap = m_threshold_low; |
| 1468 | m_flip_flop = 0; |
| 1589 | 1469 | count_f++; |
| 1590 | 1470 | x_time = dt; |
| 1591 | 1471 | } |
| r10048 | r10049 | |
| 1604 | 1484 | if (UNEXPECTED(v_cap > DSD_566__VMOD)) v_cap = DSD_566__VMOD; |
| 1605 | 1485 | |
| 1606 | 1486 | /* has it charged past upper limit? */ |
| 1607 | | if (UNEXPECTED(v_cap > context->threshold_high)) |
| 1487 | if (UNEXPECTED(v_cap > m_threshold_high)) |
| 1608 | 1488 | { |
| 1609 | 1489 | /* calculate the overshoot time */ |
| 1610 | | dt = DSD_566__C * (v_cap - context->threshold_high) / i; |
| 1611 | | v_cap = context->threshold_high; |
| 1612 | | context->flip_flop = 1; |
| 1490 | dt = DSD_566__C * (v_cap - m_threshold_high) / i; |
| 1491 | v_cap = m_threshold_high; |
| 1492 | m_flip_flop = 1; |
| 1613 | 1493 | count_r++; |
| 1614 | 1494 | x_time = dt; |
| 1615 | 1495 | } |
| 1616 | 1496 | } |
| 1617 | 1497 | } while(dt); |
| 1618 | 1498 | |
| 1619 | | context->cap_voltage = v_cap; |
| 1499 | m_cap_voltage = v_cap; |
| 1620 | 1500 | |
| 1621 | 1501 | /* Convert last switch time to a ratio */ |
| 1622 | | x_time /= node->info->sample_time; |
| 1502 | x_time /= this->sample_time(); |
| 1623 | 1503 | |
| 1624 | | switch (context->out_type) |
| 1504 | switch (m_out_type) |
| 1625 | 1505 | { |
| 1626 | 1506 | case DISC_566_OUT_SQUARE: |
| 1627 | | node->output[0] = context->flip_flop ? context->v_sqr_high : context->v_sqr_low; |
| 1628 | | if (context->fake_ac) |
| 1629 | | node->output[0] += context->ac_shift; |
| 1507 | this->output[0] = m_flip_flop ? m_v_sqr_high : m_v_sqr_low; |
| 1508 | if (m_fake_ac) |
| 1509 | this->output[0] += m_ac_shift; |
| 1630 | 1510 | break; |
| 1631 | 1511 | case DISC_566_OUT_ENERGY: |
| 1632 | 1512 | if (x_time == 0) x_time = 1.0; |
| 1633 | | node->output[0] = context->v_sqr_low + context->v_sqr_diff * (context->flip_flop ? x_time : (1.0 - x_time)); |
| 1634 | | if (context->fake_ac) |
| 1635 | | node->output[0] += context->ac_shift; |
| 1513 | this->output[0] = m_v_sqr_low + m_v_sqr_diff * (m_flip_flop ? x_time : (1.0 - x_time)); |
| 1514 | if (m_fake_ac) |
| 1515 | this->output[0] += m_ac_shift; |
| 1636 | 1516 | break; |
| 1637 | 1517 | case DISC_566_OUT_LOGIC: |
| 1638 | | node->output[0] = context->flip_flop; |
| 1518 | this->output[0] = m_flip_flop; |
| 1639 | 1519 | break; |
| 1640 | 1520 | case DISC_566_OUT_TRIANGLE: |
| 1641 | | node->output[0] = v_cap; |
| 1642 | | if (context->fake_ac) |
| 1643 | | node->output[0] += context->ac_shift; |
| 1521 | this->output[0] = v_cap; |
| 1522 | if (m_fake_ac) |
| 1523 | this->output[0] += m_ac_shift; |
| 1644 | 1524 | break; |
| 1645 | 1525 | case DISC_566_OUT_COUNT_F_X: |
| 1646 | | node->output[0] = count_f ? count_f + x_time : count_f; |
| 1526 | this->output[0] = count_f ? count_f + x_time : count_f; |
| 1647 | 1527 | break; |
| 1648 | 1528 | case DISC_566_OUT_COUNT_R_X: |
| 1649 | | node->output[0] = count_r ? count_r + x_time : count_r; |
| 1529 | this->output[0] = count_r ? count_r + x_time : count_r; |
| 1650 | 1530 | break; |
| 1651 | 1531 | case DISC_566_OUT_COUNT_F: |
| 1652 | | node->output[0] = count_f; |
| 1532 | this->output[0] = count_f; |
| 1653 | 1533 | break; |
| 1654 | 1534 | case DISC_566_OUT_COUNT_R: |
| 1655 | | node->output[0] = count_r; |
| 1535 | this->output[0] = count_r; |
| 1656 | 1536 | break; |
| 1657 | 1537 | } |
| 1658 | 1538 | } |
| 1659 | 1539 | |
| 1660 | 1540 | DISCRETE_RESET(dsd_566) |
| 1661 | 1541 | { |
| 1662 | | DISCRETE_DECLARE_CONTEXT(dsd_566) |
| 1663 | | |
| 1664 | 1542 | int v_int; |
| 1665 | 1543 | double v_float; |
| 1666 | 1544 | |
| 1667 | | context->out_type = (int)DSD_566__OPTIONS & DISC_566_OUT_MASK; |
| 1668 | | context->fake_ac = (int)DSD_566__OPTIONS & DISC_566_OUT_AC; |
| 1545 | m_out_type = (int)DSD_566__OPTIONS & DISC_566_OUT_MASK; |
| 1546 | m_fake_ac = (int)DSD_566__OPTIONS & DISC_566_OUT_AC; |
| 1669 | 1547 | |
| 1670 | 1548 | if (DSD_566__VNEG >= DSD_566__VPOS) |
| 1671 | | fatalerror("[v_neg >= v_pos] in NODE_%d!\n", node->index()); |
| 1549 | fatalerror("[v_neg >= v_pos] in NODE_%d!\n", this->index()); |
| 1672 | 1550 | |
| 1673 | 1551 | v_float = DSD_566__VPOS - DSD_566__VNEG; |
| 1674 | 1552 | v_int = (int)v_float; |
| 1675 | 1553 | if ( v_float < 10 || v_float > 15 ) |
| 1676 | | fatalerror("v_neg and/or v_pos out of range in NODE_%d\n", node->index()); |
| 1554 | fatalerror("v_neg and/or v_pos out of range in NODE_%d\n", this->index()); |
| 1677 | 1555 | if ( v_float != v_int ) |
| 1678 | 1556 | /* fatal for now. */ |
| 1679 | | fatalerror("Power should be integer in NODE_%d\n", node->index()); |
| 1557 | fatalerror("Power should be integer in NODE_%d\n", this->index()); |
| 1680 | 1558 | |
| 1681 | | context->flip_flop = 0; |
| 1682 | | context->cap_voltage = 0; |
| 1559 | m_flip_flop = 0; |
| 1560 | m_cap_voltage = 0; |
| 1683 | 1561 | |
| 1684 | 1562 | v_int -= 10; |
| 1685 | | context->threshold_high = ne566.c_high[v_int] + DSD_566__VNEG; |
| 1686 | | context->threshold_low = ne566.c_low[v_int] + DSD_566__VNEG; |
| 1687 | | context->v_sqr_high = DSD_566__VPOS - 1; |
| 1688 | | context->v_sqr_low = ne566.sqr_low[v_int] + DSD_566__VNEG; |
| 1689 | | context->v_sqr_diff = context->v_sqr_high - context->v_sqr_low; |
| 1690 | | context->v_osc_stable = ne566.osc_stable[v_int] + DSD_566__VNEG; |
| 1691 | | context->v_osc_stop = ne566.osc_stop[v_int] + DSD_566__VNEG; |
| 1563 | m_threshold_high = ne566.c_high[v_int] + DSD_566__VNEG; |
| 1564 | m_threshold_low = ne566.c_low[v_int] + DSD_566__VNEG; |
| 1565 | m_v_sqr_high = DSD_566__VPOS - 1; |
| 1566 | m_v_sqr_low = ne566.sqr_low[v_int] + DSD_566__VNEG; |
| 1567 | m_v_sqr_diff = m_v_sqr_high - m_v_sqr_low; |
| 1568 | m_v_osc_stable = ne566.osc_stable[v_int] + DSD_566__VNEG; |
| 1569 | m_v_osc_stop = ne566.osc_stop[v_int] + DSD_566__VNEG; |
| 1692 | 1570 | |
| 1693 | | context->ac_shift = 0; |
| 1694 | | if (context->fake_ac) |
| 1571 | m_ac_shift = 0; |
| 1572 | if (m_fake_ac) |
| 1695 | 1573 | { |
| 1696 | | if (context->out_type == DISC_566_OUT_TRIANGLE) |
| 1697 | | context->ac_shift = (context->threshold_high - context->threshold_low) / 2 - context->threshold_high; |
| 1574 | if (m_out_type == DISC_566_OUT_TRIANGLE) |
| 1575 | m_ac_shift = (m_threshold_high - m_threshold_low) / 2 - m_threshold_high; |
| 1698 | 1576 | else |
| 1699 | | context->ac_shift = context->v_sqr_diff / 2 - context->v_sqr_high; |
| 1577 | m_ac_shift = m_v_sqr_diff / 2 - m_v_sqr_high; |
| 1700 | 1578 | } |
| 1701 | 1579 | |
| 1702 | 1580 | /* Step the output */ |
| 1703 | | DISCRETE_STEP_CALL(dsd_566); |
| 1581 | this->step(); |
| 1704 | 1582 | } |
| 1705 | 1583 | |
| 1706 | 1584 | |
| r10048 | r10049 | |
| 1760 | 1638 | |
| 1761 | 1639 | DISCRETE_STEP(dsd_ls624) |
| 1762 | 1640 | { |
| 1763 | | DISCRETE_DECLARE_CONTEXT(dsd_ls624) |
| 1764 | | |
| 1765 | 1641 | double x_time = 0; |
| 1766 | 1642 | double freq, t1; |
| 1767 | 1643 | double v_freq_2, v_freq_3, v_freq_4; |
| 1768 | | double t_used = context->t_used; |
| 1769 | | double dt = node->info->sample_time;; |
| 1644 | double t_used = m_t_used; |
| 1645 | double dt = this->sample_time();; |
| 1770 | 1646 | double v_freq = DSD_LS624__VMOD; |
| 1771 | 1647 | double v_rng = DSD_LS624__VRNG; |
| 1772 | 1648 | int count_f = 0, count_r = 0; |
| r10048 | r10049 | |
| 1787 | 1663 | return; |
| 1788 | 1664 | |
| 1789 | 1665 | /* scale due to input resistance */ |
| 1790 | | v_freq *= context->v_freq_scale; |
| 1791 | | v_rng *= context->v_rng_scale; |
| 1666 | v_freq *= m_v_freq_scale; |
| 1667 | v_rng *= m_v_rng_scale; |
| 1792 | 1668 | |
| 1793 | 1669 | /* apply cap if needed */ |
| 1794 | | if (context->has_freq_in_cap) |
| 1670 | if (m_has_freq_in_cap) |
| 1795 | 1671 | { |
| 1796 | | context->v_cap_freq_in += (v_freq - context->v_cap_freq_in) * context->exponent; |
| 1797 | | v_freq = context->v_cap_freq_in; |
| 1672 | m_v_cap_freq_in += (v_freq - m_v_cap_freq_in) * m_exponent; |
| 1673 | v_freq = m_v_cap_freq_in; |
| 1798 | 1674 | } |
| 1799 | 1675 | |
| 1800 | 1676 | /* Polyfunctional3D_model created by zunzun.com using sum of squared absolute error */ |
| r10048 | r10049 | |
| 1815 | 1691 | freq *= CAP_U(0.1) / DSD_LS624__C; |
| 1816 | 1692 | |
| 1817 | 1693 | t1 = 0.5 / freq ; |
| 1818 | | t_used += node->info->sample_time; |
| 1694 | t_used += this->sample_time(); |
| 1819 | 1695 | do |
| 1820 | 1696 | { |
| 1821 | 1697 | dt = 0; |
| r10048 | r10049 | |
| 1823 | 1699 | { |
| 1824 | 1700 | /* calculate the overshoot time */ |
| 1825 | 1701 | t_used -= t1; |
| 1826 | | context->flip_flop ^= 1; |
| 1827 | | if (context->flip_flop) |
| 1702 | m_flip_flop ^= 1; |
| 1703 | if (m_flip_flop) |
| 1828 | 1704 | count_r++; |
| 1829 | 1705 | else |
| 1830 | 1706 | count_f++; |
| 1831 | 1707 | /* fix up any frequency increase change errors */ |
| 1832 | | while(t_used > node->info->sample_time) |
| 1833 | | t_used -= node->info->sample_time; |
| 1708 | while(t_used > this->sample_time()) |
| 1709 | t_used -= this->sample_time(); |
| 1834 | 1710 | x_time = t_used; |
| 1835 | 1711 | dt = t_used; |
| 1836 | 1712 | } |
| 1837 | 1713 | }while(dt); |
| 1838 | 1714 | |
| 1839 | | context->t_used = t_used; |
| 1715 | m_t_used = t_used; |
| 1840 | 1716 | |
| 1841 | 1717 | /* Convert last switch time to a ratio */ |
| 1842 | | x_time = x_time / node->info->sample_time; |
| 1718 | x_time = x_time / this->sample_time(); |
| 1843 | 1719 | |
| 1844 | | switch (context->out_type) |
| 1720 | switch (m_out_type) |
| 1845 | 1721 | { |
| 1846 | 1722 | case DISC_LS624_OUT_LOGIC_X: |
| 1847 | | node->output[0] = context->flip_flop + x_time; |
| 1723 | this->output[0] = m_flip_flop + x_time; |
| 1848 | 1724 | break; |
| 1849 | 1725 | case DISC_LS624_OUT_COUNT_F_X: |
| 1850 | | node->output[0] = count_f ? count_f + x_time : count_f; |
| 1726 | this->output[0] = count_f ? count_f + x_time : count_f; |
| 1851 | 1727 | break; |
| 1852 | 1728 | case DISC_LS624_OUT_COUNT_R_X: |
| 1853 | | node->output[0] = count_r ? count_r + x_time : count_r; |
| 1729 | this->output[0] = count_r ? count_r + x_time : count_r; |
| 1854 | 1730 | break; |
| 1855 | 1731 | case DISC_LS624_OUT_COUNT_F: |
| 1856 | | node->output[0] = count_f; |
| 1732 | this->output[0] = count_f; |
| 1857 | 1733 | break; |
| 1858 | 1734 | case DISC_LS624_OUT_COUNT_R: |
| 1859 | | node->output[0] = count_r; |
| 1735 | this->output[0] = count_r; |
| 1860 | 1736 | break; |
| 1861 | 1737 | case DISC_LS624_OUT_ENERGY: |
| 1862 | 1738 | if (x_time == 0) x_time = 1.0; |
| 1863 | | node->output[0] = LS624_OUT_HIGH * (context->flip_flop ? x_time : (1.0 - x_time)); |
| 1739 | this->output[0] = LS624_OUT_HIGH * (m_flip_flop ? x_time : (1.0 - x_time)); |
| 1864 | 1740 | break; |
| 1865 | 1741 | case DISC_LS624_OUT_LOGIC: |
| 1866 | | node->output[0] = context->flip_flop; |
| 1742 | this->output[0] = m_flip_flop; |
| 1867 | 1743 | break; |
| 1868 | 1744 | case DISC_LS624_OUT_SQUARE: |
| 1869 | | node->output[0] = context->flip_flop ? LS624_OUT_HIGH : 0; |
| 1745 | this->output[0] = m_flip_flop ? LS624_OUT_HIGH : 0; |
| 1870 | 1746 | break; |
| 1871 | 1747 | } |
| 1872 | 1748 | } |
| 1873 | 1749 | |
| 1874 | 1750 | DISCRETE_RESET(dsd_ls624) |
| 1875 | 1751 | { |
| 1876 | | struct dsd_ls624_context *context = (struct dsd_ls624_context *)node->context; |
| 1752 | m_out_type = (int)DSD_LS624__OUTTYPE; |
| 1877 | 1753 | |
| 1878 | | context->out_type = (int)DSD_LS624__OUTTYPE; |
| 1879 | | |
| 1880 | | context->flip_flop = 0; |
| 1881 | | context->t_used = 0; |
| 1882 | | context->v_freq_scale = LS624_IN_R / (DSD_LS624__R_FREQ_IN + LS624_IN_R); |
| 1883 | | context->v_rng_scale = LS624_IN_R / (DSD_LS624__R_RNG_IN + LS624_IN_R); |
| 1754 | m_flip_flop = 0; |
| 1755 | m_t_used = 0; |
| 1756 | m_v_freq_scale = LS624_IN_R / (DSD_LS624__R_FREQ_IN + LS624_IN_R); |
| 1757 | m_v_rng_scale = LS624_IN_R / (DSD_LS624__R_RNG_IN + LS624_IN_R); |
| 1884 | 1758 | if (DSD_LS624__C_FREQ_IN > 0) |
| 1885 | 1759 | { |
| 1886 | | context->has_freq_in_cap = 1; |
| 1887 | | context->exponent = RC_CHARGE_EXP(RES_2_PARALLEL(DSD_LS624__R_FREQ_IN, LS624_IN_R) * DSD_LS624__C_FREQ_IN); |
| 1888 | | context->v_cap_freq_in = 0; |
| 1760 | m_has_freq_in_cap = 1; |
| 1761 | m_exponent = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(DSD_LS624__R_FREQ_IN, LS624_IN_R) * DSD_LS624__C_FREQ_IN); |
| 1762 | m_v_cap_freq_in = 0; |
| 1889 | 1763 | } |
| 1890 | 1764 | else |
| 1891 | | context->has_freq_in_cap = 0; |
| 1765 | m_has_freq_in_cap = 0; |
| 1892 | 1766 | |
| 1893 | | node->output[0] = 0; |
| 1767 | this->output[0] = 0; |
| 1894 | 1768 | } |
src/emu/sound/disc_wav.c
| r10048 | r10049 | |
| 1 | 1 | /************************************************************************ |
| 2 | 2 | * |
| 3 | 3 | * MAME - Discrete sound system emulation library |
| 4 | | * |
| 5 | 4 | * Written by Keith Wilkins (mame@esplexo.co.uk) |
| 6 | 5 | * |
| 7 | 6 | * (c) K.Wilkins 2000 |
| r10048 | r10049 | |
| 23 | 22 | * |
| 24 | 23 | ************************************************************************/ |
| 25 | 24 | |
| 26 | | struct dss_adsr_context |
| 27 | | { |
| 28 | | double phase; |
| 29 | | }; |
| 30 | 25 | |
| 31 | | struct dss_counter_context |
| 32 | | { |
| 33 | | int clock_type; |
| 34 | | int out_type; |
| 35 | | int is_7492; |
| 36 | | int last_clock; |
| 37 | | UINT32 last_count; |
| 38 | | UINT32 last; /* Last clock state */ |
| 39 | | UINT32 min; |
| 40 | | UINT32 max; |
| 41 | | UINT32 diff; |
| 42 | | double t_left; /* time unused during last sample in seconds */ |
| 43 | | }; |
| 44 | 26 | |
| 45 | | #define DSS_INV_TAB_SIZE 500 |
| 46 | 27 | |
| 47 | | struct dss_inverter_osc_context |
| 48 | | { |
| 49 | | double v_cap; |
| 50 | | double v_g2_old; |
| 51 | | double w; |
| 52 | | double wc; |
| 53 | | double rp; |
| 54 | | double r1; |
| 55 | | double r2; |
| 56 | | double c; |
| 57 | | double tf_a; |
| 58 | | double tf_b; |
| 59 | | double tf_tab[DSS_INV_TAB_SIZE]; |
| 60 | | }; |
| 61 | 28 | |
| 62 | | struct dss_lfsr_context |
| 63 | | { |
| 64 | | unsigned int lfsr_reg; |
| 65 | | int last; /* Last clock state */ |
| 66 | | double t_clock; /* fixed counter clock in seconds */ |
| 67 | | double t_left; /* time unused during last sample in seconds */ |
| 68 | | double sample_step; |
| 69 | | double t; |
| 70 | | UINT8 reset_on_high; |
| 71 | | UINT8 invert_output; |
| 72 | | UINT8 out_is_f0; |
| 73 | | UINT8 out_lfsr_reg; |
| 74 | | }; |
| 75 | 29 | |
| 76 | | struct dss_noise_context |
| 77 | | { |
| 78 | | double phase; |
| 79 | | }; |
| 80 | 30 | |
| 81 | | struct dss_note_context |
| 82 | | { |
| 83 | | int clock_type; |
| 84 | | int out_type; |
| 85 | | int last; /* Last clock state */ |
| 86 | | double t_clock; /* fixed counter clock in seconds */ |
| 87 | | double t_left; /* time unused during last sample in seconds */ |
| 88 | | int max1; /* Max 1 Count stored as int for easy use. */ |
| 89 | | int max2; /* Max 2 Count stored as int for easy use. */ |
| 90 | | int count1; /* current count1 */ |
| 91 | | int count2; /* current count2 */ |
| 92 | | }; |
| 93 | | |
| 94 | | struct dss_op_amp_osc_context |
| 95 | | { |
| 96 | | const double *r1; /* pointers to resistor values */ |
| 97 | | const double *r2; |
| 98 | | const double *r3; |
| 99 | | const double *r4; |
| 100 | | const double *r5; |
| 101 | | const double *r6; |
| 102 | | const double *r7; |
| 103 | | const double *r8; |
| 104 | | int type; |
| 105 | | UINT8 flip_flop; /* flip/flop output state */ |
| 106 | | UINT8 flip_flop_xor; /* flip_flop ^ flip_flop_xor, 0 = discharge, 1 = charge */ |
| 107 | | UINT8 output_type; |
| 108 | | UINT8 has_enable; |
| 109 | | double v_out_high; |
| 110 | | double threshold_low; /* falling threshold */ |
| 111 | | double threshold_high; /* rising threshold */ |
| 112 | | double v_cap; /* current capacitor voltage */ |
| 113 | | double r_total; /* all input resistors in parallel */ |
| 114 | | double i_fixed; /* fixed current at the input */ |
| 115 | | double i_enable; /* fixed current at the input if enabled */ |
| 116 | | double temp1; /* Multi purpose */ |
| 117 | | double temp2; /* Multi purpose */ |
| 118 | | double temp3; /* Multi purpose */ |
| 119 | | double is_linear_charge; |
| 120 | | double charge_rc[2]; |
| 121 | | double charge_exp[2]; |
| 122 | | double charge_v[2]; |
| 123 | | }; |
| 124 | | |
| 125 | | struct dss_sawtoothwave_context |
| 126 | | { |
| 127 | | double phase; |
| 128 | | int type; |
| 129 | | }; |
| 130 | | |
| 131 | | struct dss_schmitt_osc_context |
| 132 | | { |
| 133 | | double ration_in; /* ratio of total charging voltage that comes from the input */ |
| 134 | | double ratio_feedback; /* ratio of total charging voltage that comes from the feedback */ |
| 135 | | double v_cap; /* current capacitor voltage */ |
| 136 | | double rc; /* r*c */ |
| 137 | | double exponent; |
| 138 | | int state; /* state of the output */ |
| 139 | | int enable_type; |
| 140 | | UINT8 input_is_voltage; |
| 141 | | }; |
| 142 | | |
| 143 | | struct dss_sinewave_context |
| 144 | | { |
| 145 | | double phase; |
| 146 | | }; |
| 147 | | |
| 148 | | struct dss_squarewave_context |
| 149 | | { |
| 150 | | double phase; |
| 151 | | double trigger; |
| 152 | | }; |
| 153 | | |
| 154 | | struct dss_squarewfix_context |
| 155 | | { |
| 156 | | int flip_flop; |
| 157 | | double sample_step; |
| 158 | | double t_left; |
| 159 | | double t_off; |
| 160 | | double t_on; |
| 161 | | }; |
| 162 | | |
| 163 | | struct dss_trianglewave_context |
| 164 | | { |
| 165 | | double phase; |
| 166 | | }; |
| 167 | | |
| 168 | | |
| 169 | 31 | /************************************************************************ |
| 170 | 32 | * |
| 171 | 33 | * DSS_COUNTER - External clock Binary Counter |
| r10048 | r10049 | |
| 194 | 56 | |
| 195 | 57 | DISCRETE_STEP(dss_counter) |
| 196 | 58 | { |
| 197 | | DISCRETE_DECLARE_CONTEXT(dss_counter) |
| 198 | | |
| 199 | 59 | double cycles; |
| 200 | 60 | double ds_clock; |
| 201 | 61 | int clock = 0, inc = 0; |
| 202 | | UINT32 last_count = context->last_count; /* it is different then output in 7492 */ |
| 62 | UINT32 last_count = m_last_count; /* it is different then output in 7492 */ |
| 203 | 63 | double x_time = 0; |
| 204 | 64 | UINT32 count = last_count; |
| 205 | 65 | |
| 206 | 66 | ds_clock = DSS_COUNTER__CLOCK; |
| 207 | | if (UNEXPECTED(context->clock_type == DISC_CLK_IS_FREQ)) |
| 67 | if (UNEXPECTED(m_clock_type == DISC_CLK_IS_FREQ)) |
| 208 | 68 | { |
| 209 | 69 | /* We need to keep clocking the internal clock even if disabled. */ |
| 210 | | cycles = (context->t_left + node->info->sample_time) * ds_clock; |
| 70 | cycles = (m_t_left + this->sample_time()) * ds_clock; |
| 211 | 71 | inc = (int)cycles; |
| 212 | | context->t_left = (cycles - inc) / ds_clock; |
| 213 | | if (inc) x_time = context->t_left / node->info->sample_time; |
| 72 | m_t_left = (cycles - inc) / ds_clock; |
| 73 | if (inc) x_time = m_t_left / this->sample_time(); |
| 214 | 74 | } |
| 215 | 75 | else |
| 216 | 76 | { |
| r10048 | r10049 | |
| 223 | 83 | /* If reset enabled then set output to the reset value. No x_time in reset. */ |
| 224 | 84 | if (UNEXPECTED(DSS_COUNTER__RESET)) |
| 225 | 85 | { |
| 226 | | context->last_count = (int)DSS_COUNTER__INIT; |
| 227 | | node->output[0] = (int)DSS_COUNTER__INIT; |
| 86 | m_last_count = (int)DSS_COUNTER__INIT; |
| 87 | this->output[0] = (int)DSS_COUNTER__INIT; |
| 228 | 88 | return; |
| 229 | 89 | } |
| 230 | 90 | |
| r10048 | r10049 | |
| 234 | 94 | */ |
| 235 | 95 | if (EXPECTED(DSS_COUNTER__ENABLE)) |
| 236 | 96 | { |
| 237 | | switch (context->clock_type) |
| 97 | switch (m_clock_type) |
| 238 | 98 | { |
| 239 | 99 | case DISC_CLK_ON_F_EDGE: |
| 240 | 100 | case DISC_CLK_ON_R_EDGE: |
| 241 | 101 | /* See if the clock has toggled to the proper edge */ |
| 242 | 102 | clock = (clock != 0); |
| 243 | | if (context->last_clock != clock) |
| 103 | if (m_last_clock != clock) |
| 244 | 104 | { |
| 245 | | context->last_clock = clock; |
| 246 | | if (context->clock_type == clock) |
| 105 | m_last_clock = clock; |
| 106 | if (m_clock_type == clock) |
| 247 | 107 | { |
| 248 | 108 | /* Toggled */ |
| 249 | 109 | inc = 1; |
| r10048 | r10049 | |
| 261 | 121 | if (DSS_COUNTER__DIR) |
| 262 | 122 | { |
| 263 | 123 | count += inc; |
| 264 | | while (count > context->max) |
| 124 | while (count > m_max) |
| 265 | 125 | { |
| 266 | | count -= context->diff; |
| 126 | count -= m_diff; |
| 267 | 127 | } |
| 268 | 128 | } |
| 269 | 129 | else |
| 270 | 130 | { |
| 271 | 131 | count -= inc; |
| 272 | | while (count < context->min) |
| 132 | while (count < m_min) |
| 273 | 133 | { |
| 274 | | count += context->diff; |
| 134 | count += m_diff; |
| 275 | 135 | } |
| 276 | 136 | } |
| 277 | 137 | |
| 278 | | context->last_count = count; |
| 279 | | node->output[0] = context->is_7492 ? disc_7492_count[count] : count; |
| 138 | m_last_count = count; |
| 139 | this->output[0] = m_is_7492 ? disc_7492_count[count] : count; |
| 280 | 140 | |
| 281 | 141 | if (UNEXPECTED(count != last_count)) |
| 282 | 142 | { |
| 283 | 143 | /* the x_time is only output if the output changed. */ |
| 284 | | switch (context->out_type) |
| 144 | switch (m_out_type) |
| 285 | 145 | { |
| 286 | 146 | case DISC_OUT_HAS_XTIME: |
| 287 | | node->output[0] += x_time; |
| 147 | this->output[0] += x_time; |
| 288 | 148 | break; |
| 289 | 149 | case DISC_OUT_IS_ENERGY: |
| 290 | 150 | if (x_time == 0) x_time = 1.0; |
| 291 | | node->output[0] = last_count; |
| 151 | this->output[0] = last_count; |
| 292 | 152 | if (count > last_count) |
| 293 | | node->output[0] += (count - last_count) * x_time; |
| 153 | this->output[0] += (count - last_count) * x_time; |
| 294 | 154 | else |
| 295 | | node->output[0] -= (last_count - count) * x_time; |
| 155 | this->output[0] -= (last_count - count) * x_time; |
| 296 | 156 | break; |
| 297 | 157 | } |
| 298 | 158 | } |
| r10048 | r10049 | |
| 301 | 161 | |
| 302 | 162 | DISCRETE_RESET(dss_counter) |
| 303 | 163 | { |
| 304 | | DISCRETE_DECLARE_CONTEXT(dss_counter) |
| 305 | 164 | |
| 306 | 165 | if ((int)DSS_COUNTER__CLOCK_TYPE & DISC_COUNTER_IS_7492) |
| 307 | 166 | { |
| 308 | | context->is_7492 = 1; |
| 309 | | context->clock_type = DSS_7492__CLOCK_TYPE; |
| 310 | | context->max = 5; |
| 311 | | context->min = 0; |
| 312 | | context->diff = 6; |
| 167 | m_is_7492 = 1; |
| 168 | m_clock_type = DSS_7492__CLOCK_TYPE; |
| 169 | m_max = 5; |
| 170 | m_min = 0; |
| 171 | m_diff = 6; |
| 313 | 172 | } |
| 314 | 173 | else |
| 315 | 174 | { |
| 316 | | context->is_7492 = 0; |
| 317 | | context->clock_type = DSS_COUNTER__CLOCK_TYPE; |
| 318 | | context->max = DSS_COUNTER__MAX; |
| 319 | | context->min = DSS_COUNTER__MIN; |
| 320 | | context->diff = context->max - context->min + 1; |
| 175 | m_is_7492 = 0; |
| 176 | m_clock_type = DSS_COUNTER__CLOCK_TYPE; |
| 177 | m_max = DSS_COUNTER__MAX; |
| 178 | m_min = DSS_COUNTER__MIN; |
| 179 | m_diff = m_max - m_min + 1; |
| 321 | 180 | } |
| 322 | 181 | |
| 323 | 182 | |
| 324 | | if (!context->is_7492 && (DSS_COUNTER__MAX < DSS_COUNTER__MIN)) |
| 325 | | fatalerror("MAX < MIN in NODE_%02d", node->index()); |
| 183 | if (!m_is_7492 && (DSS_COUNTER__MAX < DSS_COUNTER__MIN)) |
| 184 | fatalerror("MAX < MIN in NODE_%02d", this->index()); |
| 326 | 185 | |
| 327 | | context->out_type = context->clock_type & DISC_OUT_MASK; |
| 328 | | context->clock_type &= DISC_CLK_MASK; |
| 186 | m_out_type = m_clock_type & DISC_OUT_MASK; |
| 187 | m_clock_type &= DISC_CLK_MASK; |
| 329 | 188 | |
| 330 | | context->t_left = 0; |
| 331 | | context->last_count = 0; |
| 332 | | context->last_clock = 0; |
| 333 | | node->output[0] = DSS_COUNTER__INIT; /* count starts at reset value */ |
| 189 | m_t_left = 0; |
| 190 | m_last_count = 0; |
| 191 | m_last_clock = 0; |
| 192 | this->output[0] = DSS_COUNTER__INIT; /* count starts at reset value */ |
| 334 | 193 | } |
| 335 | 194 | |
| 336 | 195 | |
| r10048 | r10049 | |
| 355 | 214 | #define DSS_LFSR_NOISE__FEED DISCRETE_INPUT(4) |
| 356 | 215 | #define DSS_LFSR_NOISE__BIAS DISCRETE_INPUT(5) |
| 357 | 216 | |
| 358 | | INLINE int dss_lfsr_function(const discrete_info *disc_info, int myfunc, int in0, int in1, int bitmask) |
| 217 | INLINE int dss_lfsr_function(discrete_device *dev, int myfunc, int in0, int in1, int bitmask) |
| 359 | 218 | { |
| 360 | 219 | int retval; |
| 361 | 220 | |
| r10048 | r10049 | |
| 410 | 269 | retval = retval ^ in0; /* xor in0 */ |
| 411 | 270 | break; |
| 412 | 271 | default: |
| 413 | | discrete_log(disc_info, "dss_lfsr_function - Invalid function type passed"); |
| 272 | dev->discrete_log("dss_lfsr_function - Invalid function type passed"); |
| 414 | 273 | retval=0; |
| 415 | 274 | break; |
| 416 | 275 | } |
| 417 | 276 | return retval; |
| 418 | 277 | } |
| 419 | 278 | |
| 420 | | /* reset prototype so that it can be used in init function */ |
| 421 | | DISCRETE_RESET(dss_lfsr); |
| 422 | 279 | |
| 423 | | DISCRETE_STEP(dss_lfsr) |
| 280 | DISCRETE_STEP(dss_lfsr_noise) |
| 424 | 281 | { |
| 425 | | DISCRETE_DECLARE_CONTEXT(dss_lfsr) |
| 426 | 282 | DISCRETE_DECLARE_INFO(discrete_lfsr_desc) |
| 427 | 283 | |
| 428 | 284 | double cycles; |
| r10048 | r10049 | |
| 432 | 288 | if (info->clock_type == DISC_CLK_IS_FREQ) |
| 433 | 289 | { |
| 434 | 290 | /* We need to keep clocking the internal clock even if disabled. */ |
| 435 | | cycles = (context->t_left + node->info->sample_time) / context->t_clock; |
| 291 | cycles = (m_t_left + this->sample_time()) / m_t_clock; |
| 436 | 292 | inc = (int)cycles; |
| 437 | | context->t_left = (cycles - inc) * context->t_clock; |
| 293 | m_t_left = (cycles - inc) * m_t_clock; |
| 438 | 294 | } |
| 439 | 295 | |
| 440 | 296 | /* Reset everything if necessary */ |
| 441 | | if(((DSS_LFSR_NOISE__RESET == 0) ? 0 : 1) == context->reset_on_high) |
| 297 | if(((DSS_LFSR_NOISE__RESET == 0) ? 0 : 1) == m_reset_on_high) |
| 442 | 298 | { |
| 443 | | DISCRETE_RESET_CALL(dss_lfsr); |
| 299 | this->reset(); |
| 444 | 300 | return; |
| 445 | 301 | } |
| 446 | 302 | |
| r10048 | r10049 | |
| 450 | 306 | case DISC_CLK_ON_R_EDGE: |
| 451 | 307 | /* See if the clock has toggled to the proper edge */ |
| 452 | 308 | clock = (DSS_LFSR_NOISE__CLOCK != 0); |
| 453 | | if (context->last != clock) |
| 309 | if (m_last != clock) |
| 454 | 310 | { |
| 455 | | context->last = clock; |
| 311 | m_last = clock; |
| 456 | 312 | if (info->clock_type == clock) |
| 457 | 313 | { |
| 458 | 314 | /* Toggled */ |
| r10048 | r10049 | |
| 473 | 329 | for (clock = 0; clock < inc; clock++) |
| 474 | 330 | { |
| 475 | 331 | /* Fetch the last feedback result */ |
| 476 | | fbresult = (context->lfsr_reg >> info->bitlength) & 0x01; |
| 332 | fbresult = (m_lfsr_reg >> info->bitlength) & 0x01; |
| 477 | 333 | |
| 478 | 334 | /* Stage 2 feedback combine fbresultNew with infeed bit */ |
| 479 | | fbresult = dss_lfsr_function(node->info, info->feedback_function1, fbresult, noise_feed, 0x01); |
| 335 | fbresult = dss_lfsr_function(this->device, info->feedback_function1, fbresult, noise_feed, 0x01); |
| 480 | 336 | |
| 481 | 337 | /* Stage 3 first we setup where the bit is going to be shifted into */ |
| 482 | 338 | fbresult = fbresult * info->feedback_function2_mask; |
| 483 | 339 | /* Then we left shift the register, */ |
| 484 | | context->lfsr_reg = context->lfsr_reg << 1; |
| 340 | m_lfsr_reg = m_lfsr_reg << 1; |
| 485 | 341 | /* Now move the fbresult into the shift register and mask it to the bitlength */ |
| 486 | | context->lfsr_reg = dss_lfsr_function(node->info, info->feedback_function2, fbresult, context->lfsr_reg, (1 << info->bitlength) - 1 ); |
| 342 | m_lfsr_reg = dss_lfsr_function(this->device, info->feedback_function2, fbresult, m_lfsr_reg, (1 << info->bitlength) - 1 ); |
| 487 | 343 | |
| 488 | 344 | /* Now get and store the new feedback result */ |
| 489 | 345 | /* Fetch the feedback bits */ |
| 490 | | fb0 = (context->lfsr_reg >> info->feedback_bitsel0) & 0x01; |
| 491 | | fb1 = (context->lfsr_reg >> info->feedback_bitsel1) & 0x01; |
| 346 | fb0 = (m_lfsr_reg >> info->feedback_bitsel0) & 0x01; |
| 347 | fb1 = (m_lfsr_reg >> info->feedback_bitsel1) & 0x01; |
| 492 | 348 | /* Now do the combo on them */ |
| 493 | | fbresult = dss_lfsr_function(node->info, info->feedback_function0, fb0, fb1, 0x01); |
| 494 | | context->lfsr_reg = dss_lfsr_function(node->info, DISC_LFSR_REPLACE, context->lfsr_reg, fbresult << info->bitlength, (2 << info->bitlength) - 1); |
| 349 | fbresult = dss_lfsr_function(this->device, info->feedback_function0, fb0, fb1, 0x01); |
| 350 | m_lfsr_reg = dss_lfsr_function(this->device, DISC_LFSR_REPLACE, m_lfsr_reg, fbresult << info->bitlength, (2 << info->bitlength) - 1); |
| 495 | 351 | |
| 496 | 352 | } |
| 497 | 353 | /* Now select the output bit */ |
| 498 | | if (context->out_is_f0) |
| 499 | | node->output[0] = fbresult & 0x01; |
| 354 | if (m_out_is_f0) |
| 355 | this->output[0] = fbresult & 0x01; |
| 500 | 356 | else |
| 501 | | node->output[0] = (context->lfsr_reg >> info->output_bit) & 0x01; |
| 357 | this->output[0] = (m_lfsr_reg >> info->output_bit) & 0x01; |
| 502 | 358 | |
| 503 | 359 | /* Final inversion if required */ |
| 504 | | if (context->invert_output) node->output[0] = node->output[0] ? 0 : 1; |
| 360 | if (m_invert_output) this->output[0] = this->output[0] ? 0 : 1; |
| 505 | 361 | |
| 506 | 362 | /* Gain stage */ |
| 507 | | node->output[0] = node->output[0] ? DSS_LFSR_NOISE__AMP / 2 : -DSS_LFSR_NOISE__AMP / 2; |
| 363 | this->output[0] = this->output[0] ? DSS_LFSR_NOISE__AMP / 2 : -DSS_LFSR_NOISE__AMP / 2; |
| 508 | 364 | /* Bias input as required */ |
| 509 | | node->output[0] = node->output[0] + DSS_LFSR_NOISE__BIAS; |
| 365 | this->output[0] = this->output[0] + DSS_LFSR_NOISE__BIAS; |
| 510 | 366 | |
| 511 | 367 | /* output the lfsr reg ?*/ |
| 512 | | if (context->out_lfsr_reg) |
| 513 | | node->output[1] = (double) context->lfsr_reg; |
| 368 | if (m_out_lfsr_reg) |
| 369 | this->output[1] = (double) m_lfsr_reg; |
| 514 | 370 | |
| 515 | 371 | } |
| 516 | 372 | if(!DSS_LFSR_NOISE__ENABLE) |
| 517 | 373 | { |
| 518 | | node->output[0] = 0; |
| 374 | this->output[0] = 0; |
| 519 | 375 | } |
| 520 | 376 | } |
| 521 | 377 | |
| 522 | | DISCRETE_RESET(dss_lfsr) |
| 378 | DISCRETE_RESET(dss_lfsr_noise) |
| 523 | 379 | { |
| 524 | | DISCRETE_DECLARE_CONTEXT(dss_lfsr) |
| 525 | 380 | DISCRETE_DECLARE_INFO(discrete_lfsr_desc) |
| 526 | 381 | |
| 527 | 382 | int fb0 , fb1, fbresult; |
| 528 | 383 | |
| 529 | | context->reset_on_high = (info->flags & DISC_LFSR_FLAG_RESET_TYPE_H) ? 1 : 0; |
| 530 | | context->invert_output = info->flags & DISC_LFSR_FLAG_OUT_INVERT; |
| 531 | | context->out_is_f0 = (info->flags & DISC_LFSR_FLAG_OUTPUT_F0) ? 1 : 0; |
| 532 | | context->out_lfsr_reg = (info->flags & DISC_LFSR_FLAG_OUTPUT_SR_SN1) ? 1 : 0; |
| 384 | m_reset_on_high = (info->flags & DISC_LFSR_FLAG_RESET_TYPE_H) ? 1 : 0; |
| 385 | m_invert_output = info->flags & DISC_LFSR_FLAG_OUT_INVERT; |
| 386 | m_out_is_f0 = (info->flags & DISC_LFSR_FLAG_OUTPUT_F0) ? 1 : 0; |
| 387 | m_out_lfsr_reg = (info->flags & DISC_LFSR_FLAG_OUTPUT_SR_SN1) ? 1 : 0; |
| 533 | 388 | |
| 534 | 389 | if ((info->clock_type < DISC_CLK_ON_F_EDGE) || (info->clock_type > DISC_CLK_IS_FREQ)) |
| 535 | | discrete_log(node->info, "Invalid clock type passed in NODE_%d\n", node->index()); |
| 390 | this->device->discrete_log("Invalid clock type passed in NODE_%d\n", this->index()); |
| 536 | 391 | |
| 537 | | context->last = (DSS_COUNTER__CLOCK != 0); |
| 538 | | if (info->clock_type == DISC_CLK_IS_FREQ) context->t_clock = 1.0 / DSS_LFSR_NOISE__CLOCK; |
| 539 | | context->t_left = 0; |
| 392 | m_last = (DSS_COUNTER__CLOCK != 0); |
| 393 | if (info->clock_type == DISC_CLK_IS_FREQ) m_t_clock = 1.0 / DSS_LFSR_NOISE__CLOCK; |
| 394 | m_t_left = 0; |
| 540 | 395 | |
| 541 | | context->lfsr_reg = info->reset_value; |
| 396 | m_lfsr_reg = info->reset_value; |
| 542 | 397 | |
| 543 | 398 | /* Now get and store the new feedback result */ |
| 544 | 399 | /* Fetch the feedback bits */ |
| 545 | | fb0 = (context->lfsr_reg >> info->feedback_bitsel0) & 0x01; |
| 546 | | fb1=(context->lfsr_reg >> info->feedback_bitsel1) & 0x01; |
| 400 | fb0 = (m_lfsr_reg >> info->feedback_bitsel0) & 0x01; |
| 401 | fb1=(m_lfsr_reg >> info->feedback_bitsel1) & 0x01; |
| 547 | 402 | /* Now do the combo on them */ |
| 548 | | fbresult = dss_lfsr_function(node->info, info->feedback_function0, fb0, fb1, 0x01); |
| 549 | | context->lfsr_reg=dss_lfsr_function(node->info, DISC_LFSR_REPLACE, context->lfsr_reg, fbresult << info->bitlength, (2<< info->bitlength ) - 1); |
| 403 | fbresult = dss_lfsr_function(this->device, info->feedback_function0, fb0, fb1, 0x01); |
| 404 | m_lfsr_reg=dss_lfsr_function(this->device, DISC_LFSR_REPLACE, m_lfsr_reg, fbresult << info->bitlength, (2<< info->bitlength ) - 1); |
| 550 | 405 | |
| 551 | 406 | /* Now select and setup the output bit */ |
| 552 | | node->output[0] = (context->lfsr_reg >> info->output_bit) & 0x01; |
| 407 | this->output[0] = (m_lfsr_reg >> info->output_bit) & 0x01; |
| 553 | 408 | |
| 554 | 409 | /* Final inversion if required */ |
| 555 | | if(info->flags & DISC_LFSR_FLAG_OUT_INVERT) node->output[0] = node->output[0] ? 0 : 1; |
| 410 | if(info->flags & DISC_LFSR_FLAG_OUT_INVERT) this->output[0] = this->output[0] ? 0 : 1; |
| 556 | 411 | |
| 557 | 412 | /* Gain stage */ |
| 558 | | node->output[0] = node->output[0] ? DSS_LFSR_NOISE__AMP / 2 : -DSS_LFSR_NOISE__AMP / 2; |
| 413 | this->output[0] = this->output[0] ? DSS_LFSR_NOISE__AMP / 2 : -DSS_LFSR_NOISE__AMP / 2; |
| 559 | 414 | /* Bias input as required */ |
| 560 | | node->output[0] = node->output[0] + DSS_LFSR_NOISE__BIAS; |
| 415 | this->output[0] = this->output[0] + DSS_LFSR_NOISE__BIAS; |
| 561 | 416 | } |
| 562 | 417 | |
| 563 | 418 | |
| r10048 | r10049 | |
| 578 | 433 | |
| 579 | 434 | DISCRETE_STEP(dss_noise) |
| 580 | 435 | { |
| 581 | | DISCRETE_DECLARE_CONTEXT(dss_noise) |
| 582 | | |
| 583 | 436 | if(DSS_NOISE__ENABLE) |
| 584 | 437 | { |
| 585 | 438 | /* Only sample noise on rollover to next cycle */ |
| 586 | | if(context->phase > (2.0 * M_PI)) |
| 439 | if(m_phase > (2.0 * M_PI)) |
| 587 | 440 | { |
| 588 | 441 | /* GCC's rand returns a RAND_MAX value of 0x7fff */ |
| 589 | | int newval = (node->info->device->machine->rand() & 0x7fff) - 16384; |
| 442 | int newval = (this->device->machine->rand() & 0x7fff) - 16384; |
| 590 | 443 | |
| 591 | 444 | /* make sure the peak to peak values are the amplitude */ |
| 592 | | node->output[0] = DSS_NOISE__AMP / 2; |
| 445 | this->output[0] = DSS_NOISE__AMP / 2; |
| 593 | 446 | if (newval > 0) |
| 594 | | node->output[0] *= ((double)newval / 16383); |
| 447 | this->output[0] *= ((double)newval / 16383); |
| 595 | 448 | else |
| 596 | | node->output[0] *= ((double)newval / 16384); |
| 449 | this->output[0] *= ((double)newval / 16384); |
| 597 | 450 | |
| 598 | 451 | /* Add DC Bias component */ |
| 599 | | node->output[0] += DSS_NOISE__BIAS; |
| 452 | this->output[0] += DSS_NOISE__BIAS; |
| 600 | 453 | } |
| 601 | 454 | } |
| 602 | 455 | else |
| 603 | 456 | { |
| 604 | | node->output[0] = 0; |
| 457 | this->output[0] = 0; |
| 605 | 458 | } |
| 606 | 459 | |
| 607 | 460 | /* Keep the new phasor in the 2Pi range.*/ |
| 608 | | context->phase = fmod(context->phase, 2.0 * M_PI); |
| 461 | m_phase = fmod(m_phase, 2.0 * M_PI); |
| 609 | 462 | |
| 610 | 463 | /* The enable input only curtails output, phase rotation still occurs. */ |
| 611 | 464 | /* We allow the phase to exceed 2Pi here, so we can tell when to sample the noise. */ |
| 612 | | context->phase += ((2.0 * M_PI * DSS_NOISE__FREQ) / node->info->sample_rate); |
| 465 | m_phase += ((2.0 * M_PI * DSS_NOISE__FREQ) / this->sample_rate()); |
| 613 | 466 | } |
| 614 | 467 | |
| 615 | 468 | |
| 616 | 469 | DISCRETE_RESET(dss_noise) |
| 617 | 470 | { |
| 618 | | DISCRETE_DECLARE_CONTEXT(dss_noise) |
| 619 | | |
| 620 | | context->phase=0; |
| 621 | | DISCRETE_STEP_CALL( dss_noise ); |
| 471 | m_phase=0; |
| 472 | this->step(); |
| 622 | 473 | } |
| 623 | 474 | |
| 624 | 475 | |
| r10048 | r10049 | |
| 644 | 495 | |
| 645 | 496 | DISCRETE_STEP(dss_note) |
| 646 | 497 | { |
| 647 | | DISCRETE_DECLARE_CONTEXT(dss_note) |
| 648 | | |
| 649 | 498 | double cycles; |
| 650 | 499 | int clock = 0, last_count2, inc = 0; |
| 651 | 500 | double x_time = 0; |
| 652 | 501 | |
| 653 | | if (context->clock_type == DISC_CLK_IS_FREQ) |
| 502 | if (m_clock_type == DISC_CLK_IS_FREQ) |
| 654 | 503 | { |
| 655 | 504 | /* We need to keep clocking the internal clock even if disabled. */ |
| 656 | | cycles = (context->t_left + node->info->sample_time) / context->t_clock; |
| 505 | cycles = (m_t_left + this->sample_time()) / m_t_clock; |
| 657 | 506 | inc = (int)cycles; |
| 658 | | context->t_left = (cycles - inc) * context->t_clock; |
| 659 | | if (inc) x_time = context->t_left / node->info->sample_time; |
| 507 | m_t_left = (cycles - inc) * m_t_clock; |
| 508 | if (inc) x_time = m_t_left / this->sample_time(); |
| 660 | 509 | } |
| 661 | 510 | else |
| 662 | 511 | { |
| r10048 | r10049 | |
| 667 | 516 | |
| 668 | 517 | if (DSS_NOTE__ENABLE) |
| 669 | 518 | { |
| 670 | | last_count2 = context->count2; |
| 519 | last_count2 = m_count2; |
| 671 | 520 | |
| 672 | | switch (context->clock_type) |
| 521 | switch (m_clock_type) |
| 673 | 522 | { |
| 674 | 523 | case DISC_CLK_ON_F_EDGE: |
| 675 | 524 | case DISC_CLK_ON_R_EDGE: |
| 676 | 525 | /* See if the clock has toggled to the proper edge */ |
| 677 | 526 | clock = (clock != 0); |
| 678 | | if (context->last != clock) |
| 527 | if (m_last != clock) |
| 679 | 528 | { |
| 680 | | context->last = clock; |
| 681 | | if (context->clock_type == clock) |
| 529 | m_last = clock; |
| 530 | if (m_clock_type == clock) |
| 682 | 531 | { |
| 683 | 532 | /* Toggled */ |
| 684 | 533 | inc = 1; |
| r10048 | r10049 | |
| 697 | 546 | { |
| 698 | 547 | for (clock = 0; clock < inc; clock++) |
| 699 | 548 | { |
| 700 | | context->count1++; |
| 701 | | if (context->count1 > context->max1) |
| 549 | m_count1++; |
| 550 | if (m_count1 > m_max1) |
| 702 | 551 | { |
| 703 | 552 | /* Max 1 count reached. Load Data into counter. */ |
| 704 | | context->count1 = (int)DSS_NOTE__DATA; |
| 705 | | context->count2 += 1; |
| 706 | | if (context->count2 > context->max2) context->count2 = 0; |
| 553 | m_count1 = (int)DSS_NOTE__DATA; |
| 554 | m_count2 += 1; |
| 555 | if (m_count2 > m_max2) m_count2 = 0; |
| 707 | 556 | } |
| 708 | 557 | } |
| 709 | 558 | } |
| 710 | 559 | |
| 711 | | node->output[0] = context->count2; |
| 712 | | if (context->count2 != last_count2) |
| 560 | this->output[0] = m_count2; |
| 561 | if (m_count2 != last_count2) |
| 713 | 562 | { |
| 714 | 563 | /* the x_time is only output if the output changed. */ |
| 715 | | switch (context->out_type) |
| 564 | switch (m_out_type) |
| 716 | 565 | { |
| 717 | 566 | case DISC_OUT_IS_ENERGY: |
| 718 | 567 | if (x_time == 0) x_time = 1.0; |
| 719 | | node->output[0] = last_count2; |
| 720 | | if (context->count2 > last_count2) |
| 721 | | node->output[0] += (context->count2 - last_count2) * x_time; |
| 568 | this->output[0] = last_count2; |
| 569 | if (m_count2 > last_count2) |
| 570 | this->output[0] += (m_count2 - last_count2) * x_time; |
| 722 | 571 | else |
| 723 | | node->output[0] -= (last_count2 - context->count2) * x_time; |
| 572 | this->output[0] -= (last_count2 - m_count2) * x_time; |
| 724 | 573 | break; |
| 725 | 574 | case DISC_OUT_HAS_XTIME: |
| 726 | | node->output[0] += x_time; |
| 575 | this->output[0] += x_time; |
| 727 | 576 | break; |
| 728 | 577 | } |
| 729 | 578 | } |
| 730 | 579 | } |
| 731 | 580 | else |
| 732 | | node->output[0] = 0; |
| 581 | this->output[0] = 0; |
| 733 | 582 | } |
| 734 | 583 | |
| 735 | 584 | DISCRETE_RESET(dss_note) |
| 736 | 585 | { |
| 737 | | DISCRETE_DECLARE_CONTEXT(dss_note) |
| 586 | m_clock_type = (int)DSS_NOTE__CLOCK_TYPE & DISC_CLK_MASK; |
| 587 | m_out_type = (int)DSS_NOTE__CLOCK_TYPE & DISC_OUT_MASK; |
| 738 | 588 | |
| 739 | | context->clock_type = (int)DSS_NOTE__CLOCK_TYPE & DISC_CLK_MASK; |
| 740 | | context->out_type = (int)DSS_NOTE__CLOCK_TYPE & DISC_OUT_MASK; |
| 589 | m_last = (DSS_NOTE__CLOCK != 0); |
| 590 | m_t_left = 0; |
| 591 | m_t_clock = 1.0 / DSS_NOTE__CLOCK; |
| 741 | 592 | |
| 742 | | context->last = (DSS_NOTE__CLOCK != 0); |
| 743 | | context->t_left = 0; |
| 744 | | context->t_clock = 1.0 / DSS_NOTE__CLOCK; |
| 745 | | |
| 746 | | context->count1 = (int)DSS_NOTE__DATA; |
| 747 | | context->count2 = 0; |
| 748 | | context->max1 = (int)DSS_NOTE__MAX1; |
| 749 | | context->max2 = (int)DSS_NOTE__MAX2; |
| 750 | | node->output[0] = 0; |
| 593 | m_count1 = (int)DSS_NOTE__DATA; |
| 594 | m_count2 = 0; |
| 595 | m_max1 = (int)DSS_NOTE__MAX1; |
| 596 | m_max2 = (int)DSS_NOTE__MAX2; |
| 597 | this->output[0] = 0; |
| 751 | 598 | } |
| 752 | 599 | |
| 753 | 600 | /************************************************************************ |
| r10048 | r10049 | |
| 769 | 616 | /* The inputs on a norton op-amp are (info->vP - OP_AMP_NORTON_VBE) */ |
| 770 | 617 | /* which is the same as the output high voltage. We will define them */ |
| 771 | 618 | /* the same to save a calculation step */ |
| 772 | | #define DSS_OP_AMP_OSC_NORTON_VP_IN context->v_out_high |
| 619 | #define DSS_OP_AMP_OSC_NORTON_VP_IN m_v_out_high |
| 773 | 620 | |
| 774 | 621 | DISCRETE_STEP(dss_op_amp_osc) |
| 775 | 622 | { |
| 776 | | DISCRETE_DECLARE_CONTEXT(dss_op_amp_osc) |
| 777 | 623 | DISCRETE_DECLARE_INFO(discrete_op_amp_osc_info) |
| 778 | 624 | |
| 779 | 625 | double i = 0; /* Charging current created by vIn */ |
| r10048 | r10049 | |
| 787 | 633 | UINT8 force_charge = 0; |
| 788 | 634 | UINT8 enable = DSS_OP_AMP_OSC__ENABLE; |
| 789 | 635 | UINT8 update_exponent = 0; |
| 790 | | UINT8 flip_flop = context->flip_flop; |
| 636 | UINT8 flip_flop = m_flip_flop; |
| 791 | 637 | int count_f = 0; |
| 792 | 638 | int count_r = 0; |
| 793 | 639 | |
| 794 | | dt = node->info->sample_time; /* Change in time */ |
| 795 | | v_cap = context->v_cap; /* Set to voltage before change */ |
| 640 | dt = this->sample_time(); /* Change in time */ |
| 641 | v_cap = m_v_cap; /* Set to voltage before change */ |
| 796 | 642 | |
| 797 | 643 | /* work out the charge currents/voltages. */ |
| 798 | | switch (context->type) |
| 644 | switch (m_type) |
| 799 | 645 | { |
| 800 | 646 | case DISC_OP_AMP_OSCILLATOR_VCO_1: |
| 801 | 647 | /* Work out the charge rates. */ |
| 802 | 648 | /* i is not a current. It is being used as a temp variable. */ |
| 803 | | i = DSS_OP_AMP_OSC__VMOD1 * context->temp1; |
| 649 | i = DSS_OP_AMP_OSC__VMOD1 * m_temp1; |
| 804 | 650 | charge[0] = (DSS_OP_AMP_OSC__VMOD1 - i) / info->r1; |
| 805 | | charge[1] = (i - (DSS_OP_AMP_OSC__VMOD1 * context->temp2)) / context->temp3; |
| 651 | charge[1] = (i - (DSS_OP_AMP_OSC__VMOD1 * m_temp2)) / m_temp3; |
| 806 | 652 | break; |
| 807 | 653 | |
| 808 | 654 | case DISC_OP_AMP_OSCILLATOR_1 | DISC_OP_AMP_IS_NORTON: |
| r10048 | r10049 | |
| 810 | 656 | /* resistors can be nodes, so everything needs updating */ |
| 811 | 657 | double i1, i2; |
| 812 | 658 | /* add in enable current if using real enable */ |
| 813 | | if (context->has_enable) |
| 659 | if (m_has_enable) |
| 814 | 660 | { |
| 815 | 661 | if (enable) |
| 816 | | i = context->i_enable; |
| 662 | i = m_i_enable; |
| 817 | 663 | enable = 1; |
| 818 | 664 | } |
| 819 | 665 | /* Work out the charge rates. */ |
| 820 | | charge[0] = DSS_OP_AMP_OSC_NORTON_VP_IN / *context->r1 - i; |
| 821 | | charge[1] = (context->v_out_high - OP_AMP_NORTON_VBE) / *context->r2 - charge[0]; |
| 666 | charge[0] = DSS_OP_AMP_OSC_NORTON_VP_IN / *m_r1 - i; |
| 667 | charge[1] = (m_v_out_high - OP_AMP_NORTON_VBE) / *m_r2 - charge[0]; |
| 822 | 668 | /* Work out the Inverting Schmitt thresholds. */ |
| 823 | | i1 = DSS_OP_AMP_OSC_NORTON_VP_IN / *context->r5; |
| 824 | | i2 = (0.0 - OP_AMP_NORTON_VBE) / *context->r4; |
| 825 | | context->threshold_low = (i1 + i2) * *context->r3 + OP_AMP_NORTON_VBE; |
| 826 | | i2 = (context->v_out_high - OP_AMP_NORTON_VBE) / *context->r4; |
| 827 | | context->threshold_high = (i1 + i2) * *context->r3 + OP_AMP_NORTON_VBE; |
| 669 | i1 = DSS_OP_AMP_OSC_NORTON_VP_IN / *m_r5; |
| 670 | i2 = (0.0 - OP_AMP_NORTON_VBE) / *m_r4; |
| 671 | m_threshold_low = (i1 + i2) * *m_r3 + OP_AMP_NORTON_VBE; |
| 672 | i2 = (m_v_out_high - OP_AMP_NORTON_VBE) / *m_r4; |
| 673 | m_threshold_high = (i1 + i2) * *m_r3 + OP_AMP_NORTON_VBE; |
| 828 | 674 | break; |
| 829 | 675 | } |
| 830 | 676 | |
| r10048 | r10049 | |
| 838 | 684 | else |
| 839 | 685 | { |
| 840 | 686 | /* we need to mix any bias and all modulation voltages together. */ |
| 841 | | i = context->i_fixed; |
| 687 | i = m_i_fixed; |
| 842 | 688 | i += DSS_OP_AMP_OSC__VMOD1 / info->r7; |
| 843 | 689 | if (info->r8 != 0) |
| 844 | 690 | i += DSS_OP_AMP_OSC__VMOD2 / info->r8; |
| 845 | | v = i * context->r_total; |
| 691 | v = i * m_r_total; |
| 846 | 692 | } |
| 847 | 693 | |
| 848 | 694 | /* Work out the charge rates. */ |
| r10048 | r10049 | |
| 858 | 704 | case DISC_OP_AMP_OSCILLATOR_VCO_2 | DISC_OP_AMP_IS_NORTON: |
| 859 | 705 | /* Work out the charge rates. */ |
| 860 | 706 | i = DSS_OP_AMP_OSC__VMOD1 / info->r1; |
| 861 | | charge[0] = i - context->temp1; |
| 862 | | charge[1] = context->temp2 - i; |
| 707 | charge[0] = i - m_temp1; |
| 708 | charge[1] = m_temp2 - i; |
| 863 | 709 | /* if the negative pin current is less then the positive pin current, */ |
| 864 | 710 | /* then the osc is disabled and the cap keeps charging */ |
| 865 | 711 | if (charge[0] < 0) |
| r10048 | r10049 | |
| 871 | 717 | |
| 872 | 718 | case DISC_OP_AMP_OSCILLATOR_VCO_3 | DISC_OP_AMP_IS_NORTON: |
| 873 | 719 | /* start with fixed bias */ |
| 874 | | charge[0] = context->i_fixed; |
| 720 | charge[0] = m_i_fixed; |
| 875 | 721 | /* add in enable current if using real enable */ |
| 876 | | if (context->has_enable) |
| 722 | if (m_has_enable) |
| 877 | 723 | { |
| 878 | 724 | if (enable) |
| 879 | | charge[0] -= context->i_enable; |
| 725 | charge[0] -= m_i_enable; |
| 880 | 726 | enable = 1; |
| 881 | 727 | } |
| 882 | 728 | /* we need to mix any bias and all modulation voltages together. */ |
| r10048 | r10049 | |
| 888 | 734 | v = DSS_OP_AMP_OSC__VMOD2 - OP_AMP_NORTON_VBE; |
| 889 | 735 | charge[0] += v / info->r6; |
| 890 | 736 | } |
| 891 | | charge[1] = context->temp1 - charge[0]; |
| 737 | charge[1] = m_temp1 - charge[0]; |
| 892 | 738 | break; |
| 893 | 739 | } |
| 894 | 740 | |
| 895 | 741 | if (!enable) |
| 896 | 742 | { |
| 897 | 743 | /* we will just output 0 for oscillators that have no real enable. */ |
| 898 | | node->output[0] = 0; |
| 744 | this->output[0] = 0; |
| 899 | 745 | return; |
| 900 | 746 | } |
| 901 | 747 | |
| 902 | 748 | /* Keep looping until all toggling in time sample is used up. */ |
| 903 | 749 | do |
| 904 | 750 | { |
| 905 | | if (context->is_linear_charge) |
| 751 | if (m_is_linear_charge) |
| 906 | 752 | { |
| 907 | | if ((flip_flop ^ context->flip_flop_xor) || force_charge) |
| 753 | if ((flip_flop ^ m_flip_flop_xor) || force_charge) |
| 908 | 754 | { |
| 909 | 755 | /* Charging */ |
| 910 | 756 | /* iC=C*dv/dt works out to dv=iC*dt/C */ |
| r10048 | r10049 | |
| 912 | 758 | dt = 0; |
| 913 | 759 | |
| 914 | 760 | /* has it charged past upper limit? */ |
| 915 | | if (v_cap_next > context->threshold_high) |
| 761 | if (v_cap_next > m_threshold_high) |
| 916 | 762 | { |
| 917 | | flip_flop = context->flip_flop_xor; |
| 763 | flip_flop = m_flip_flop_xor; |
| 918 | 764 | if (flip_flop) |
| 919 | 765 | count_r++; |
| 920 | 766 | else |
| r10048 | r10049 | |
| 922 | 768 | if (force_charge) |
| 923 | 769 | { |
| 924 | 770 | /* we need to keep charging the cap to the max thereby disabling the circuit */ |
| 925 | | if (v_cap_next > context->v_out_high) |
| 926 | | v_cap_next = context->v_out_high; |
| 771 | if (v_cap_next > m_v_out_high) |
| 772 | v_cap_next = m_v_out_high; |
| 927 | 773 | } |
| 928 | 774 | else |
| 929 | 775 | { |
| 930 | 776 | /* calculate the overshoot time */ |
| 931 | | dt = info->c * (v_cap_next - context->threshold_high) / charge[1]; |
| 777 | dt = info->c * (v_cap_next - m_threshold_high) / charge[1]; |
| 932 | 778 | x_time = dt; |
| 933 | | v_cap_next = context->threshold_high; |
| 779 | v_cap_next = m_threshold_high; |
| 934 | 780 | } |
| 935 | 781 | } |
| 936 | 782 | } |
| r10048 | r10049 | |
| 941 | 787 | dt = 0; |
| 942 | 788 | |
| 943 | 789 | /* has it discharged past lower limit? */ |
| 944 | | if (v_cap_next < context->threshold_low) |
| 790 | if (v_cap_next < m_threshold_low) |
| 945 | 791 | { |
| 946 | | flip_flop = !context->flip_flop_xor; |
| 792 | flip_flop = !m_flip_flop_xor; |
| 947 | 793 | if (flip_flop) |
| 948 | 794 | count_r++; |
| 949 | 795 | else |
| 950 | 796 | count_f++; |
| 951 | 797 | /* calculate the overshoot time */ |
| 952 | | dt = info->c * (context->threshold_low - v_cap_next) / charge[0]; |
| 798 | dt = info->c * (m_threshold_low - v_cap_next) / charge[0]; |
| 953 | 799 | x_time = dt; |
| 954 | | v_cap_next = context->threshold_low; |
| 800 | v_cap_next = m_threshold_low; |
| 955 | 801 | } |
| 956 | 802 | } |
| 957 | 803 | } |
| 958 | 804 | else /* non-linear charge */ |
| 959 | 805 | { |
| 960 | 806 | if (update_exponent) |
| 961 | | exponent = RC_CHARGE_EXP_DT(context->charge_rc[flip_flop], dt); |
| 807 | exponent = RC_CHARGE_EXP_DT(m_charge_rc[flip_flop], dt); |
| 962 | 808 | else |
| 963 | | exponent = context->charge_exp[flip_flop]; |
| 809 | exponent = m_charge_exp[flip_flop]; |
| 964 | 810 | |
| 965 | | v_cap_next = v_cap + ((context->charge_v[flip_flop] - v_cap) * exponent); |
| 811 | v_cap_next = v_cap + ((m_charge_v[flip_flop] - v_cap) * exponent); |
| 966 | 812 | dt = 0; |
| 967 | 813 | |
| 968 | 814 | if (flip_flop) |
| 969 | 815 | { |
| 970 | 816 | /* Has it charged past upper limit? */ |
| 971 | | if (v_cap_next > context->threshold_high) |
| 817 | if (v_cap_next > m_threshold_high) |
| 972 | 818 | { |
| 973 | | dt = context->charge_rc[1] * log(1.0 / (1.0 - ((v_cap_next - context->threshold_high) / (context->v_out_high - v_cap)))); |
| 819 | dt = m_charge_rc[1] * log(1.0 / (1.0 - ((v_cap_next - m_threshold_high) / (m_v_out_high - v_cap)))); |
| 974 | 820 | x_time = dt; |
| 975 | | v_cap_next = context->threshold_high; |
| 821 | v_cap_next = m_threshold_high; |
| 976 | 822 | flip_flop = 0; |
| 977 | 823 | count_f++; |
| 978 | 824 | update_exponent = 1; |
| r10048 | r10049 | |
| 981 | 827 | else |
| 982 | 828 | { |
| 983 | 829 | /* has it discharged past lower limit? */ |
| 984 | | if (v_cap_next < context->threshold_low) |
| 830 | if (v_cap_next < m_threshold_low) |
| 985 | 831 | { |
| 986 | | dt = context->charge_rc[0] * log(1.0 / (1.0 - ((context->threshold_low - v_cap_next) / v_cap))); |
| 832 | dt = m_charge_rc[0] * log(1.0 / (1.0 - ((m_threshold_low - v_cap_next) / v_cap))); |
| 987 | 833 | x_time = dt; |
| 988 | | v_cap_next = context->threshold_low; |
| 834 | v_cap_next = m_threshold_low; |
| 989 | 835 | flip_flop = 1; |
| 990 | 836 | count_r++; |
| 991 | 837 | update_exponent = 1; |
| r10048 | r10049 | |
| 994 | 840 | } |
| 995 | 841 | v_cap = v_cap_next; |
| 996 | 842 | } while(dt); |
| 997 | | if (v_cap > context->v_out_high) |
| 998 | | v_cap = context->v_out_high; |
| 843 | if (v_cap > m_v_out_high) |
| 844 | v_cap = m_v_out_high; |
| 999 | 845 | if (v_cap < 0) |
| 1000 | 846 | v_cap = 0; |
| 1001 | | context->v_cap = v_cap; |
| 847 | m_v_cap = v_cap; |
| 1002 | 848 | |
| 1003 | | x_time = dt / node->info->sample_time; |
| 849 | x_time = dt / this->sample_time(); |
| 1004 | 850 | |
| 1005 | | switch (context->output_type) |
| 851 | switch (m_output_type) |
| 1006 | 852 | { |
| 1007 | 853 | case DISC_OP_AMP_OSCILLATOR_OUT_CAP: |
| 1008 | | node->output[0] = v_cap; |
| 854 | this->output[0] = v_cap; |
| 1009 | 855 | break; |
| 1010 | 856 | case DISC_OP_AMP_OSCILLATOR_OUT_ENERGY: |
| 1011 | 857 | if (x_time == 0) x_time = 1.0; |
| 1012 | | node->output[0] = context->v_out_high * (flip_flop ? x_time : (1.0 - x_time)); |
| 858 | this->output[0] = m_v_out_high * (flip_flop ? x_time : (1.0 - x_time)); |
| 1013 | 859 | break; |
| 1014 | 860 | case DISC_OP_AMP_OSCILLATOR_OUT_SQW: |
| 1015 | 861 | if (count_f + count_r >= 2) |
| 1016 | 862 | /* force at least 1 toggle */ |
| 1017 | | node->output[0] = context->flip_flop ? 0 : context->v_out_high; |
| 863 | this->output[0] = m_flip_flop ? 0 : m_v_out_high; |
| 1018 | 864 | else |
| 1019 | | node->output[0] = flip_flop * context->v_out_high; |
| 865 | this->output[0] = flip_flop * m_v_out_high; |
| 1020 | 866 | break; |
| 1021 | 867 | case DISC_OP_AMP_OSCILLATOR_OUT_COUNT_F_X: |
| 1022 | | node->output[0] = count_f ? count_f + x_time : count_f; |
| 868 | this->output[0] = count_f ? count_f + x_time : count_f; |
| 1023 | 869 | break; |
| 1024 | 870 | case DISC_OP_AMP_OSCILLATOR_OUT_COUNT_R_X: |
| 1025 | | node->output[0] = count_r ? count_r + x_time : count_r; |
| 871 | this->output[0] = count_r ? count_r + x_time : count_r; |
| 1026 | 872 | break; |
| 1027 | 873 | case DISC_OP_AMP_OSCILLATOR_OUT_LOGIC_X: |
| 1028 | | node->output[0] = context->flip_flop + x_time; |
| 874 | this->output[0] = m_flip_flop + x_time; |
| 1029 | 875 | break; |
| 1030 | 876 | } |
| 1031 | | context->flip_flop = flip_flop; |
| 877 | m_flip_flop = flip_flop; |
| 1032 | 878 | } |
| 1033 | 879 | |
| 1034 | 880 | #define DIODE_DROP 0.7 |
| 1035 | 881 | |
| 1036 | 882 | DISCRETE_RESET(dss_op_amp_osc) |
| 1037 | 883 | { |
| 1038 | | DISCRETE_DECLARE_CONTEXT(dss_op_amp_osc) |
| 1039 | 884 | DISCRETE_DECLARE_INFO(discrete_op_amp_osc_info) |
| 1040 | 885 | |
| 1041 | 886 | const double *r_info_ptr; |
| 1042 | 887 | const double **r_context_ptr; |
| 1043 | 888 | int loop; |
| 1044 | | node_description *r_node; |
| 889 | discrete_base_node *r_node; |
| 1045 | 890 | |
| 1046 | 891 | double i1 = 0; /* inverting input current */ |
| 1047 | 892 | double i2 = 0; /* non-inverting input current */ |
| 1048 | 893 | |
| 1049 | 894 | /* link to resistor static or node values */ |
| 1050 | 895 | r_info_ptr = &info->r1; |
| 1051 | | r_context_ptr = &context->r1; |
| 896 | r_context_ptr = &m_r1; |
| 1052 | 897 | for (loop = 0; loop < 8; loop ++) |
| 1053 | 898 | { |
| 1054 | 899 | if IS_VALUE_A_NODE(*r_info_ptr) |
| 1055 | 900 | { |
| 1056 | | r_node = discrete_find_node(node->info, *r_info_ptr); |
| 901 | r_node = this->device->discrete_find_node(*r_info_ptr); |
| 1057 | 902 | *r_context_ptr = &(r_node->output[NODE_CHILD_NODE_NUM((int)*r_info_ptr)]); |
| 1058 | 903 | } |
| 1059 | 904 | else |
| r10048 | r10049 | |
| 1062 | 907 | r_context_ptr++; |
| 1063 | 908 | } |
| 1064 | 909 | |
| 1065 | | context->is_linear_charge = 1; |
| 1066 | | context->output_type = info->type & DISC_OP_AMP_OSCILLATOR_OUT_MASK; |
| 1067 | | context->type = info->type & DISC_OP_AMP_OSCILLATOR_TYPE_MASK; |
| 1068 | | context->charge_rc[0] = 0; |
| 1069 | | context->charge_rc[1] = 0; |
| 1070 | | context->charge_v[0] = 0; |
| 1071 | | context->charge_v[1] = 0; |
| 1072 | | context->i_fixed = 0; |
| 1073 | | context->has_enable = 0; |
| 910 | m_is_linear_charge = 1; |
| 911 | m_output_type = info->type & DISC_OP_AMP_OSCILLATOR_OUT_MASK; |
| 912 | m_type = info->type & DISC_OP_AMP_OSCILLATOR_TYPE_MASK; |
| 913 | m_charge_rc[0] = 0; |
| 914 | m_charge_rc[1] = 0; |
| 915 | m_charge_v[0] = 0; |
| 916 | m_charge_v[1] = 0; |
| 917 | m_i_fixed = 0; |
| 918 | m_has_enable = 0; |
| 1074 | 919 | |
| 1075 | | switch (context->type) |
| 920 | switch (m_type) |
| 1076 | 921 | { |
| 1077 | 922 | case DISC_OP_AMP_OSCILLATOR_VCO_1: |
| 1078 | 923 | /* The charge rates vary depending on vMod so they are not precalculated. */ |
| 1079 | 924 | /* Charges while FlipFlop High */ |
| 1080 | | context->flip_flop_xor = 0; |
| 925 | m_flip_flop_xor = 0; |
| 1081 | 926 | /* Work out the Non-inverting Schmitt thresholds. */ |
| 1082 | | context->temp1 = (info->vP / 2) / info->r4; |
| 1083 | | context->temp2 = (info->vP - OP_AMP_VP_RAIL_OFFSET) / info->r3; |
| 1084 | | context->temp3 = 1.0 / (1.0 / info->r3 + 1.0 / info->r4); |
| 1085 | | context->threshold_low = context->temp1 * context->temp3; |
| 1086 | | context->threshold_high = (context->temp1 + context->temp2) * context->temp3; |
| 927 | m_temp1 = (info->vP / 2) / info->r4; |
| 928 | m_temp2 = (info->vP - OP_AMP_VP_RAIL_OFFSET) / info->r3; |
| 929 | m_temp3 = 1.0 / (1.0 / info->r3 + 1.0 / info->r4); |
| 930 | m_threshold_low = m_temp1 * m_temp3; |
| 931 | m_threshold_high = (m_temp1 + m_temp2) * m_temp3; |
| 1087 | 932 | /* There is no charge on the cap so the schmitt goes high at init. */ |
| 1088 | | context->flip_flop = 1; |
| 933 | m_flip_flop = 1; |
| 1089 | 934 | /* Setup some commonly used stuff */ |
| 1090 | | context->temp1 = info->r5 / (info->r2 + info->r5); /* voltage ratio across r5 */ |
| 1091 | | context->temp2 = info->r6 / (info->r1 + info->r6); /* voltage ratio across r6 */ |
| 1092 | | context->temp3 = 1.0 / (1.0 / info->r1 + 1.0 / info->r6); /* input resistance when r6 switched in */ |
| 935 | m_temp1 = info->r5 / (info->r2 + info->r5); /* voltage ratio across r5 */ |
| 936 | m_temp2 = info->r6 / (info->r1 + info->r6); /* voltage ratio across r6 */ |
| 937 | m_temp3 = 1.0 / (1.0 / info->r1 + 1.0 / info->r6); /* input resistance when r6 switched in */ |
| 1093 | 938 | break; |
| 1094 | 939 | |
| 1095 | 940 | case DISC_OP_AMP_OSCILLATOR_1 | DISC_OP_AMP_IS_NORTON: |
| 1096 | 941 | /* Charges while FlipFlop High */ |
| 1097 | | context->flip_flop_xor = 0; |
| 942 | m_flip_flop_xor = 0; |
| 1098 | 943 | /* There is no charge on the cap so the schmitt inverter goes high at init. */ |
| 1099 | | context->flip_flop = 1; |
| 944 | m_flip_flop = 1; |
| 1100 | 945 | /* setup current if using real enable */ |
| 1101 | 946 | if (info->r6 > 0) |
| 1102 | 947 | { |
| 1103 | | context->has_enable = 1; |
| 1104 | | context->i_enable = (info->vP - OP_AMP_NORTON_VBE) / (info->r6 + RES_K(1)); |
| 948 | m_has_enable = 1; |
| 949 | m_i_enable = (info->vP - OP_AMP_NORTON_VBE) / (info->r6 + RES_K(1)); |
| 1105 | 950 | } |
| 1106 | 951 | break; |
| 1107 | 952 | |
| 1108 | 953 | case DISC_OP_AMP_OSCILLATOR_2 | DISC_OP_AMP_IS_NORTON: |
| 1109 | | context->is_linear_charge = 0; |
| 954 | m_is_linear_charge = 0; |
| 1110 | 955 | /* First calculate the parallel charge resistors and volatges. */ |
| 1111 | 956 | /* We can cheat and just calcuate the charges in the working area. */ |
| 1112 | 957 | /* The thresholds are well past the effect of the voltage drop */ |
| 1113 | 958 | /* and the component tolerances far exceed the .5V charge difference */ |
| 1114 | 959 | if (info->r1 != 0) |
| 1115 | 960 | { |
| 1116 | | context->charge_rc[0] = 1.0 / info->r1; |
| 1117 | | context->charge_rc[1] = 1.0 / info->r1; |
| 1118 | | context->charge_v[1] = (info->vP - OP_AMP_NORTON_VBE) / info->r1; |
| 961 | m_charge_rc[0] = 1.0 / info->r1; |
| 962 | m_charge_rc[1] = 1.0 / info->r1; |
| 963 | m_charge_v[1] = (info->vP - OP_AMP_NORTON_VBE) / info->r1; |
| 1119 | 964 | } |
| 1120 | 965 | if (info->r5 != 0) |
| 1121 | 966 | { |
| 1122 | | context->charge_rc[0] += 1.0 / info->r5; |
| 1123 | | context->charge_v[0] = DIODE_DROP / info->r5; |
| 967 | m_charge_rc[0] += 1.0 / info->r5; |
| 968 | m_charge_v[0] = DIODE_DROP / info->r5; |
| 1124 | 969 | } |
| 1125 | 970 | if (info->r6 != 0) |
| 1126 | 971 | { |
| 1127 | | context->charge_rc[1] += 1.0 / info->r6; |
| 1128 | | context->charge_v[1] += (info->vP - OP_AMP_NORTON_VBE - DIODE_DROP) / info->r6; |
| 972 | m_charge_rc[1] += 1.0 / info->r6; |
| 973 | m_charge_v[1] += (info->vP - OP_AMP_NORTON_VBE - DIODE_DROP) / info->r6; |
| 1129 | 974 | } |
| 1130 | | context->charge_rc[0] += 1.0 / info->r2; |
| 1131 | | context->charge_rc[0] = 1.0 / context->charge_rc[0]; |
| 1132 | | context->charge_v[0] += OP_AMP_NORTON_VBE / info->r2; |
| 1133 | | context->charge_v[0] *= context->charge_rc[0]; |
| 1134 | | context->charge_rc[1] += 1.0 / info->r2; |
| 1135 | | context->charge_rc[1] = 1.0 / context->charge_rc[1]; |
| 1136 | | context->charge_v[1] += OP_AMP_NORTON_VBE / info->r2; |
| 1137 | | context->charge_v[1] *= context->charge_rc[1]; |
| 975 | m_charge_rc[0] += 1.0 / info->r2; |
| 976 | m_charge_rc[0] = 1.0 / m_charge_rc[0]; |
| 977 | m_charge_v[0] += OP_AMP_NORTON_VBE / info->r2; |
| 978 | m_charge_v[0] *= m_charge_rc[0]; |
| 979 | m_charge_rc[1] += 1.0 / info->r2; |
| 980 | m_charge_rc[1] = 1.0 / m_charge_rc[1]; |
| 981 | m_charge_v[1] += OP_AMP_NORTON_VBE / info->r2; |
| 982 | m_charge_v[1] *= m_charge_rc[1]; |
| 1138 | 983 | |
| 1139 | | context->charge_rc[0] *= info->c; |
| 1140 | | context->charge_rc[1] *= info->c; |
| 1141 | | context->charge_exp[0] = RC_CHARGE_EXP(context->charge_rc[0]); |
| 1142 | | context->charge_exp[1] = RC_CHARGE_EXP(context->charge_rc[1]); |
| 1143 | | context->threshold_low = (info->vP - OP_AMP_NORTON_VBE) / info->r4; |
| 1144 | | context->threshold_high = context->threshold_low + (info->vP - 2 * OP_AMP_NORTON_VBE) / info->r3;; |
| 1145 | | context->threshold_low = context->threshold_low * info->r2 + OP_AMP_NORTON_VBE; |
| 1146 | | context->threshold_high = context->threshold_high * info->r2 + OP_AMP_NORTON_VBE; |
| 984 | m_charge_rc[0] *= info->c; |
| 985 | m_charge_rc[1] *= info->c; |
| 986 | m_charge_exp[0] = RC_CHARGE_EXP_CLASS(m_charge_rc[0]); |
| 987 | m_charge_exp[1] = RC_CHARGE_EXP_CLASS(m_charge_rc[1]); |
| 988 | m_threshold_low = (info->vP - OP_AMP_NORTON_VBE) / info->r4; |
| 989 | m_threshold_high = m_threshold_low + (info->vP - 2 * OP_AMP_NORTON_VBE) / info->r3;; |
| 990 | m_threshold_low = m_threshold_low * info->r2 + OP_AMP_NORTON_VBE; |
| 991 | m_threshold_high = m_threshold_high * info->r2 + OP_AMP_NORTON_VBE; |
| 1147 | 992 | |
| 1148 | 993 | /* There is no charge on the cap so the schmitt inverter goes high at init. */ |
| 1149 | | context->flip_flop = 1; |
| 994 | m_flip_flop = 1; |
| 1150 | 995 | break; |
| 1151 | 996 | |
| 1152 | 997 | case DISC_OP_AMP_OSCILLATOR_VCO_1 | DISC_OP_AMP_IS_NORTON: |
| 1153 | 998 | /* Charges while FlipFlop Low */ |
| 1154 | | context->flip_flop_xor = 1; |
| 999 | m_flip_flop_xor = 1; |
| 1155 | 1000 | /* There is no charge on the cap so the schmitt goes low at init. */ |
| 1156 | | context->flip_flop = 0; |
| 1001 | m_flip_flop = 0; |
| 1157 | 1002 | /* The charge rates vary depending on vMod so they are not precalculated. */ |
| 1158 | 1003 | /* But we can precalculate the fixed currents. */ |
| 1159 | | if (info->r6 != 0) context->i_fixed += info->vP / info->r6; |
| 1160 | | context->i_fixed += OP_AMP_NORTON_VBE / info->r1; |
| 1161 | | context->i_fixed += OP_AMP_NORTON_VBE / info->r2; |
| 1004 | if (info->r6 != 0) m_i_fixed += info->vP / info->r6; |
| 1005 | m_i_fixed += OP_AMP_NORTON_VBE / info->r1; |
| 1006 | m_i_fixed += OP_AMP_NORTON_VBE / info->r2; |
| 1162 | 1007 | /* Work out the input resistance to be used later to calculate the Millman voltage. */ |
| 1163 | | context->r_total = 1.0 / info->r1 + 1.0 / info->r2 + 1.0 / info->r7; |
| 1164 | | if (info->r6) context->r_total += 1.0 / info->r6; |
| 1165 | | if (info->r8) context->r_total += 1.0 / info->r8; |
| 1166 | | context->r_total = 1.0 / context->r_total; |
| 1008 | m_r_total = 1.0 / info->r1 + 1.0 / info->r2 + 1.0 / info->r7; |
| 1009 | if (info->r6) m_r_total += 1.0 / info->r6; |
| 1010 | if (info->r8) m_r_total += 1.0 / info->r8; |
| 1011 | m_r_total = 1.0 / m_r_total; |
| 1167 | 1012 | /* Work out the Non-inverting Schmitt thresholds. */ |
| 1168 | 1013 | i1 = (info->vP - OP_AMP_NORTON_VBE) / info->r5; |
| 1169 | 1014 | i2 = (info->vP - OP_AMP_NORTON_VBE - OP_AMP_NORTON_VBE) / info->r4; |
| 1170 | | context->threshold_low = (i1 - i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1015 | m_threshold_low = (i1 - i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1171 | 1016 | i2 = (0.0 - OP_AMP_NORTON_VBE) / info->r4; |
| 1172 | | context->threshold_high = (i1 - i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1017 | m_threshold_high = (i1 - i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1173 | 1018 | break; |
| 1174 | 1019 | |
| 1175 | 1020 | case DISC_OP_AMP_OSCILLATOR_VCO_2 | DISC_OP_AMP_IS_NORTON: |
| 1176 | 1021 | /* Charges while FlipFlop High */ |
| 1177 | | context->flip_flop_xor = 0; |
| 1022 | m_flip_flop_xor = 0; |
| 1178 | 1023 | /* There is no charge on the cap so the schmitt inverter goes high at init. */ |
| 1179 | | context->flip_flop = 1; |
| 1024 | m_flip_flop = 1; |
| 1180 | 1025 | /* Work out the charge rates. */ |
| 1181 | | context->temp1 = (info->vP - OP_AMP_NORTON_VBE) / info->r2; |
| 1182 | | context->temp2 = (info->vP - OP_AMP_NORTON_VBE) * (1.0 / info->r2 + 1.0 / info->r6); |
| 1026 | m_temp1 = (info->vP - OP_AMP_NORTON_VBE) / info->r2; |
| 1027 | m_temp2 = (info->vP - OP_AMP_NORTON_VBE) * (1.0 / info->r2 + 1.0 / info->r6); |
| 1183 | 1028 | /* Work out the Inverting Schmitt thresholds. */ |
| 1184 | 1029 | i1 = (info->vP - OP_AMP_NORTON_VBE) / info->r5; |
| 1185 | 1030 | i2 = (0.0 - OP_AMP_NORTON_VBE) / info->r4; |
| 1186 | | context->threshold_low = (i1 + i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1031 | m_threshold_low = (i1 + i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1187 | 1032 | i2 = (info->vP - OP_AMP_NORTON_VBE - OP_AMP_NORTON_VBE) / info->r4; |
| 1188 | | context->threshold_high = (i1 + i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1033 | m_threshold_high = (i1 + i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1189 | 1034 | break; |
| 1190 | 1035 | |
| 1191 | 1036 | case DISC_OP_AMP_OSCILLATOR_VCO_3 | DISC_OP_AMP_IS_NORTON: |
| 1192 | 1037 | /* Charges while FlipFlop High */ |
| 1193 | | context->flip_flop_xor = 0; |
| 1038 | m_flip_flop_xor = 0; |
| 1194 | 1039 | /* There is no charge on the cap so the schmitt inverter goes high at init. */ |
| 1195 | | context->flip_flop = 1; |
| 1040 | m_flip_flop = 1; |
| 1196 | 1041 | /* setup current if using real enable */ |
| 1197 | 1042 | if (info->r8 > 0) |
| 1198 | 1043 | { |
| 1199 | | context->has_enable = 1; |
| 1200 | | context->i_enable = (info->vP - OP_AMP_NORTON_VBE) / (info->r8 + RES_K(1)); |
| 1044 | m_has_enable = 1; |
| 1045 | m_i_enable = (info->vP - OP_AMP_NORTON_VBE) / (info->r8 + RES_K(1)); |
| 1201 | 1046 | } |
| 1202 | 1047 | /* Work out the charge rates. */ |
| 1203 | 1048 | /* The charge rates vary depending on vMod so they are not precalculated. */ |
| 1204 | 1049 | /* But we can precalculate the fixed currents. */ |
| 1205 | | if (info->r7 != 0) context->i_fixed = (info->vP - OP_AMP_NORTON_VBE) / info->r7; |
| 1206 | | context->temp1 = (info->vP - OP_AMP_NORTON_VBE - OP_AMP_NORTON_VBE) / info->r2; |
| 1050 | if (info->r7 != 0) m_i_fixed = (info->vP - OP_AMP_NORTON_VBE) / info->r7; |
| 1051 | m_temp1 = (info->vP - OP_AMP_NORTON_VBE - OP_AMP_NORTON_VBE) / info->r2; |
| 1207 | 1052 | /* Work out the Inverting Schmitt thresholds. */ |
| 1208 | 1053 | i1 = (info->vP - OP_AMP_NORTON_VBE) / info->r5; |
| 1209 | 1054 | i2 = (0.0 - OP_AMP_NORTON_VBE) / info->r4; |
| 1210 | | context->threshold_low = (i1 + i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1055 | m_threshold_low = (i1 + i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1211 | 1056 | i2 = (info->vP - OP_AMP_NORTON_VBE - OP_AMP_NORTON_VBE) / info->r4; |
| 1212 | | context->threshold_high = (i1 + i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1057 | m_threshold_high = (i1 + i2) * info->r3 + OP_AMP_NORTON_VBE; |
| 1213 | 1058 | break; |
| 1214 | 1059 | } |
| 1215 | 1060 | |
| 1216 | | context->v_out_high = info->vP - ((context->type & DISC_OP_AMP_IS_NORTON) ? OP_AMP_NORTON_VBE : OP_AMP_VP_RAIL_OFFSET); |
| 1217 | | context->v_cap = 0; |
| 1061 | m_v_out_high = info->vP - ((m_type & DISC_OP_AMP_IS_NORTON) ? OP_AMP_NORTON_VBE : OP_AMP_VP_RAIL_OFFSET); |
| 1062 | m_v_cap = 0; |
| 1218 | 1063 | |
| 1219 | | DISCRETE_STEP_CALL(dss_op_amp_osc); |
| 1064 | this->step(); |
| 1220 | 1065 | } |
| 1221 | 1066 | |
| 1222 | 1067 | |
| r10048 | r10049 | |
| 1241 | 1086 | |
| 1242 | 1087 | DISCRETE_STEP(dss_sawtoothwave) |
| 1243 | 1088 | { |
| 1244 | | DISCRETE_DECLARE_CONTEXT(dss_sawtoothwave) |
| 1245 | | |
| 1246 | 1089 | if(DSS_SAWTOOTHWAVE__ENABLE) |
| 1247 | 1090 | { |
| 1248 | | node->output[0] = (context->type == 0) ? context->phase * (DSS_SAWTOOTHWAVE__AMP / (2.0 * M_PI)) : DSS_SAWTOOTHWAVE__AMP - (context->phase * (DSS_SAWTOOTHWAVE__AMP / (2.0 * M_PI))); |
| 1249 | | node->output[0] -= DSS_SAWTOOTHWAVE__AMP / 2.0; |
| 1091 | this->output[0] = (m_type == 0) ? m_phase * (DSS_SAWTOOTHWAVE__AMP / (2.0 * M_PI)) : DSS_SAWTOOTHWAVE__AMP - (m_phase * (DSS_SAWTOOTHWAVE__AMP / (2.0 * M_PI))); |
| 1092 | this->output[0] -= DSS_SAWTOOTHWAVE__AMP / 2.0; |
| 1250 | 1093 | /* Add DC Bias component */ |
| 1251 | | node->output[0] = node->output[0] + DSS_SAWTOOTHWAVE__BIAS; |
| 1094 | this->output[0] = this->output[0] + DSS_SAWTOOTHWAVE__BIAS; |
| 1252 | 1095 | } |
| 1253 | 1096 | else |
| 1254 | 1097 | { |
| 1255 | | node->output[0] = 0; |
| 1098 | this->output[0] = 0; |
| 1256 | 1099 | } |
| 1257 | 1100 | |
| 1258 | 1101 | /* Work out the phase step based on phase/freq & sample rate */ |
| r10048 | r10049 | |
| 1262 | 1105 | /* boils out to */ |
| 1263 | 1106 | /* phase step = (2Pi*output freq)/sample freq) */ |
| 1264 | 1107 | /* Also keep the new phasor in the 2Pi range. */ |
| 1265 | | context->phase = fmod((context->phase + ((2.0 * M_PI * DSS_SAWTOOTHWAVE__FREQ) / node->info->sample_rate)), 2.0 * M_PI); |
| 1108 | m_phase = fmod((m_phase + ((2.0 * M_PI * DSS_SAWTOOTHWAVE__FREQ) / this->sample_rate())), 2.0 * M_PI); |
| 1266 | 1109 | } |
| 1267 | 1110 | |
| 1268 | 1111 | DISCRETE_RESET(dss_sawtoothwave) |
| 1269 | 1112 | { |
| 1270 | | DISCRETE_DECLARE_CONTEXT(dss_sawtoothwave) |
| 1271 | | |
| 1272 | 1113 | double start; |
| 1273 | 1114 | |
| 1274 | 1115 | /* Establish starting phase, convert from degrees to radians */ |
| 1275 | 1116 | start = (DSS_SAWTOOTHWAVE__PHASE / 360.0) * (2.0 * M_PI); |
| 1276 | 1117 | /* Make sure its always mod 2Pi */ |
| 1277 | | context->phase = fmod(start, 2.0 * M_PI); |
| 1118 | m_phase = fmod(start, 2.0 * M_PI); |
| 1278 | 1119 | |
| 1279 | 1120 | /* Invert gradient depending on sawtooth type /|/|/|/|/| or |\|\|\|\|\ */ |
| 1280 | | context->type = (DSS_SAWTOOTHWAVE__GRAD) ? 1 : 0; |
| 1121 | m_type = (DSS_SAWTOOTHWAVE__GRAD) ? 1 : 0; |
| 1281 | 1122 | |
| 1282 | 1123 | /* Step the node to set the output */ |
| 1283 | | DISCRETE_STEP_CALL(dss_sawtoothwave); |
| 1124 | this->step(); |
| 1284 | 1125 | } |
| 1285 | 1126 | |
| 1286 | 1127 | |
| r10048 | r10049 | |
| 1302 | 1143 | |
| 1303 | 1144 | DISCRETE_STEP(dss_schmitt_osc) |
| 1304 | 1145 | { |
| 1305 | | DISCRETE_DECLARE_CONTEXT(dss_schmitt_osc) |
| 1306 | 1146 | DISCRETE_DECLARE_INFO(discrete_schmitt_osc_desc) |
| 1307 | 1147 | |
| 1308 | 1148 | double supply, v_cap, new_vCap, t, exponent; |
| 1309 | 1149 | |
| 1310 | 1150 | /* We will always oscillate. The enable just affects the output. */ |
| 1311 | | v_cap = context->v_cap; |
| 1312 | | exponent = context->exponent; |
| 1151 | v_cap = m_v_cap; |
| 1152 | exponent = m_exponent; |
| 1313 | 1153 | |
| 1314 | 1154 | /* Keep looping until all toggling in time sample is used up. */ |
| 1315 | 1155 | do |
| r10048 | r10049 | |
| 1321 | 1161 | * use vGate as its voltage. Note that ration_in is just the ratio of the total |
| 1322 | 1162 | * voltage and needs to be multipled by the input voltage. ratio_feedback has |
| 1323 | 1163 | * already been multiplied by vGate to save time because that voltage never changes. */ |
| 1324 | | supply = context->input_is_voltage ? context->ration_in * DSS_SCHMITT_OSC__VIN : (DSS_SCHMITT_OSC__VIN ? context->ration_in * info->vGate : 0); |
| 1325 | | supply += (context->state ? context->ratio_feedback : 0); |
| 1164 | supply = m_input_is_voltage ? m_ration_in * DSS_SCHMITT_OSC__VIN : (DSS_SCHMITT_OSC__VIN ? m_ration_in * info->vGate : 0); |
| 1165 | supply += (m_state ? m_ratio_feedback : 0); |
| 1326 | 1166 | new_vCap = v_cap + ((supply - v_cap) * exponent); |
| 1327 | | if (context->state) |
| 1167 | if (m_state) |
| 1328 | 1168 | { |
| 1329 | 1169 | /* Charging */ |
| 1330 | 1170 | /* has it charged past upper limit? */ |
| 1331 | 1171 | if (new_vCap > info->trshRise) |
| 1332 | 1172 | { |
| 1333 | 1173 | /* calculate the overshoot time */ |
| 1334 | | t = context->rc * log(1.0 / (1.0 - ((new_vCap - info->trshRise) / (info->vGate - v_cap)))); |
| 1174 | t = m_rc * log(1.0 / (1.0 - ((new_vCap - info->trshRise) / (info->vGate - v_cap)))); |
| 1335 | 1175 | /* calculate new exponent because of reduced time */ |
| 1336 | | exponent = RC_CHARGE_EXP_DT(context->rc, t); |
| 1176 | exponent = RC_CHARGE_EXP_DT(m_rc, t); |
| 1337 | 1177 | v_cap = new_vCap = info->trshRise; |
| 1338 | | context->state = 0; |
| 1178 | m_state = 0; |
| 1339 | 1179 | } |
| 1340 | 1180 | } |
| 1341 | 1181 | else |
| r10048 | r10049 | |
| 1345 | 1185 | if (new_vCap < info->trshFall) |
| 1346 | 1186 | { |
| 1347 | 1187 | /* calculate the overshoot time */ |
| 1348 | | t = context->rc * log(1.0 / (1.0 - ((info->trshFall - new_vCap) / v_cap))); |
| 1188 | t = m_rc * log(1.0 / (1.0 - ((info->trshFall - new_vCap) / v_cap))); |
| 1349 | 1189 | /* calculate new exponent because of reduced time */ |
| 1350 | | exponent = RC_CHARGE_EXP_DT(context->rc, t); |
| 1190 | exponent = RC_CHARGE_EXP_DT(m_rc, t); |
| 1351 | 1191 | v_cap = new_vCap = info->trshFall; |
| 1352 | | context->state = 1; |
| 1192 | m_state = 1; |
| 1353 | 1193 | } |
| 1354 | 1194 | } |
| 1355 | 1195 | } while(t); |
| 1356 | 1196 | |
| 1357 | | context->v_cap = new_vCap; |
| 1197 | m_v_cap = new_vCap; |
| 1358 | 1198 | |
| 1359 | | switch (context->enable_type) |
| 1199 | switch (m_enable_type) |
| 1360 | 1200 | { |
| 1361 | 1201 | case DISC_SCHMITT_OSC_ENAB_IS_AND: |
| 1362 | | node->output[0] = DSS_SCHMITT_OSC__ENABLE && context->state; |
| 1202 | this->output[0] = DSS_SCHMITT_OSC__ENABLE && m_state; |
| 1363 | 1203 | break; |
| 1364 | 1204 | case DISC_SCHMITT_OSC_ENAB_IS_NAND: |
| 1365 | | node->output[0] = !(DSS_SCHMITT_OSC__ENABLE && context->state); |
| 1205 | this->output[0] = !(DSS_SCHMITT_OSC__ENABLE && m_state); |
| 1366 | 1206 | break; |
| 1367 | 1207 | case DISC_SCHMITT_OSC_ENAB_IS_OR: |
| 1368 | | node->output[0] = DSS_SCHMITT_OSC__ENABLE || context->state; |
| 1208 | this->output[0] = DSS_SCHMITT_OSC__ENABLE || m_state; |
| 1369 | 1209 | break; |
| 1370 | 1210 | case DISC_SCHMITT_OSC_ENAB_IS_NOR: |
| 1371 | | node->output[0] = !(DSS_SCHMITT_OSC__ENABLE || context->state); |
| 1211 | this->output[0] = !(DSS_SCHMITT_OSC__ENABLE || m_state); |
| 1372 | 1212 | break; |
| 1373 | 1213 | } |
| 1374 | | node->output[0] *= DSS_SCHMITT_OSC__AMP; |
| 1214 | this->output[0] *= DSS_SCHMITT_OSC__AMP; |
| 1375 | 1215 | } |
| 1376 | 1216 | |
| 1377 | 1217 | DISCRETE_RESET(dss_schmitt_osc) |
| 1378 | 1218 | { |
| 1379 | | DISCRETE_DECLARE_CONTEXT(dss_schmitt_osc) |
| 1380 | 1219 | DISCRETE_DECLARE_INFO(discrete_schmitt_osc_desc) |
| 1381 | 1220 | |
| 1382 | 1221 | double rSource; |
| 1383 | 1222 | |
| 1384 | | context->enable_type = info->options & DISC_SCHMITT_OSC_ENAB_MASK; |
| 1385 | | context->input_is_voltage = (info->options & DISC_SCHMITT_OSC_IN_IS_VOLTAGE) ? 1 : 0; |
| 1223 | m_enable_type = info->options & DISC_SCHMITT_OSC_ENAB_MASK; |
| 1224 | m_input_is_voltage = (info->options & DISC_SCHMITT_OSC_IN_IS_VOLTAGE) ? 1 : 0; |
| 1386 | 1225 | |
| 1387 | 1226 | /* The 2 resistors make a voltage divider, so their ratios add together |
| 1388 | 1227 | * to make the charging voltage. */ |
| 1389 | | context->ration_in = info->rFeedback / (info->rIn + info->rFeedback); |
| 1390 | | context->ratio_feedback = info->rIn / (info->rIn + info->rFeedback) * info->vGate; |
| 1228 | m_ration_in = info->rFeedback / (info->rIn + info->rFeedback); |
| 1229 | m_ratio_feedback = info->rIn / (info->rIn + info->rFeedback) * info->vGate; |
| 1391 | 1230 | |
| 1392 | 1231 | /* The voltage source resistance works out to the 2 resistors in parallel. |
| 1393 | 1232 | * So use this for the RC charge constant. */ |
| 1394 | 1233 | rSource = 1.0 / ((1.0 / info->rIn) + (1.0 / info->rFeedback)); |
| 1395 | | context->rc = rSource * info->c; |
| 1396 | | context->exponent = RC_CHARGE_EXP(context->rc); |
| 1234 | m_rc = rSource * info->c; |
| 1235 | m_exponent = RC_CHARGE_EXP_CLASS(m_rc); |
| 1397 | 1236 | |
| 1398 | 1237 | /* Cap is at 0V on power up. Causing output to be high. */ |
| 1399 | | context->v_cap = 0; |
| 1400 | | context->state = 1; |
| 1238 | m_v_cap = 0; |
| 1239 | m_state = 1; |
| 1401 | 1240 | |
| 1402 | | node->output[0] = info->options ? 0 : DSS_SCHMITT_OSC__AMP; |
| 1241 | this->output[0] = info->options ? 0 : DSS_SCHMITT_OSC__AMP; |
| 1403 | 1242 | } |
| 1404 | 1243 | |
| 1405 | 1244 | |
| r10048 | r10049 | |
| 1422 | 1261 | |
| 1423 | 1262 | DISCRETE_STEP(dss_sinewave) |
| 1424 | 1263 | { |
| 1425 | | DISCRETE_DECLARE_CONTEXT(dss_sinewave) |
| 1426 | | |
| 1427 | 1264 | /* Set the output */ |
| 1428 | 1265 | if(DSS_SINEWAVE__ENABLE) |
| 1429 | 1266 | { |
| 1430 | | node->output[0] = (DSS_SINEWAVE__AMPL / 2.0) * sin(context->phase); |
| 1267 | this->output[0] = (DSS_SINEWAVE__AMPL / 2.0) * sin(m_phase); |
| 1431 | 1268 | /* Add DC Bias component */ |
| 1432 | | node->output[0] = node->output[0] + DSS_SINEWAVE__BIAS; |
| 1269 | this->output[0] = this->output[0] + DSS_SINEWAVE__BIAS; |
| 1433 | 1270 | } |
| 1434 | 1271 | else |
| 1435 | 1272 | { |
| 1436 | | node->output[0] = 0; |
| 1273 | this->output[0] = 0; |
| 1437 | 1274 | } |
| 1438 | 1275 | |
| 1439 | 1276 | /* Work out the phase step based on phase/freq & sample rate */ |
| r10048 | r10049 | |
| 1443 | 1280 | /* boils out to */ |
| 1444 | 1281 | /* phase step = (2Pi*output freq)/sample freq) */ |
| 1445 | 1282 | /* Also keep the new phasor in the 2Pi range. */ |
| 1446 | | context->phase=fmod((context->phase + ((2.0 * M_PI * DSS_SINEWAVE__FREQ) / node->info->sample_rate)), 2.0 * M_PI); |
| 1283 | m_phase=fmod((m_phase + ((2.0 * M_PI * DSS_SINEWAVE__FREQ) / this->sample_rate())), 2.0 * M_PI); |
| 1447 | 1284 | } |
| 1448 | 1285 | |
| 1449 | 1286 | DISCRETE_RESET(dss_sinewave) |
| 1450 | 1287 | { |
| 1451 | | DISCRETE_DECLARE_CONTEXT(dss_sinewave) |
| 1452 | | |
| 1453 | 1288 | double start; |
| 1454 | 1289 | |
| 1455 | 1290 | /* Establish starting phase, convert from degrees to radians */ |
| 1456 | 1291 | start = (DSS_SINEWAVE__PHASE / 360.0) * (2.0 * M_PI); |
| 1457 | 1292 | /* Make sure its always mod 2Pi */ |
| 1458 | | context->phase = fmod(start, 2.0 * M_PI); |
| 1293 | m_phase = fmod(start, 2.0 * M_PI); |
| 1459 | 1294 | /* Step the output to make it correct */ |
| 1460 | | DISCRETE_STEP_CALL(dss_sinewave); |
| 1295 | this->step(); |
| 1461 | 1296 | } |
| 1462 | 1297 | |
| 1463 | 1298 | |
| r10048 | r10049 | |
| 1482 | 1317 | |
| 1483 | 1318 | DISCRETE_STEP(dss_squarewave) |
| 1484 | 1319 | { |
| 1485 | | DISCRETE_DECLARE_CONTEXT(dss_squarewave) |
| 1486 | | |
| 1487 | 1320 | /* Establish trigger phase from duty */ |
| 1488 | | context->trigger=((100-DSS_SQUAREWAVE__DUTY)/100)*(2.0*M_PI); |
| 1321 | m_trigger=((100-DSS_SQUAREWAVE__DUTY)/100)*(2.0*M_PI); |
| 1489 | 1322 | |
| 1490 | 1323 | /* Set the output */ |
| 1491 | 1324 | if(DSS_SQUAREWAVE__ENABLE) |
| 1492 | 1325 | { |
| 1493 | | if(context->phase>context->trigger) |
| 1494 | | node->output[0] = DSS_SQUAREWAVE__AMP /2.0; |
| 1326 | if(m_phase>m_trigger) |
| 1327 | this->output[0] = DSS_SQUAREWAVE__AMP /2.0; |
| 1495 | 1328 | else |
| 1496 | | node->output[0] =- DSS_SQUAREWAVE__AMP / 2.0; |
| 1329 | this->output[0] =- DSS_SQUAREWAVE__AMP / 2.0; |
| 1497 | 1330 | |
| 1498 | 1331 | /* Add DC Bias component */ |
| 1499 | | node->output[0] = node->output[0] + DSS_SQUAREWAVE__BIAS; |
| 1332 | this->output[0] = this->output[0] + DSS_SQUAREWAVE__BIAS; |
| 1500 | 1333 | } |
| 1501 | 1334 | else |
| 1502 | 1335 | { |
| 1503 | | node->output[0] = 0; |
| 1336 | this->output[0] = 0; |
| 1504 | 1337 | } |
| 1505 | 1338 | |
| 1506 | 1339 | /* Work out the phase step based on phase/freq & sample rate */ |
| r10048 | r10049 | |
| 1510 | 1343 | /* boils out to */ |
| 1511 | 1344 | /* phase step = (2Pi*output freq)/sample freq) */ |
| 1512 | 1345 | /* Also keep the new phasor in the 2Pi range. */ |
| 1513 | | context->phase=fmod(context->phase + ((2.0 * M_PI * DSS_SQUAREWAVE__FREQ) / node->info->sample_rate), 2.0 * M_PI); |
| 1346 | m_phase=fmod(m_phase + ((2.0 * M_PI * DSS_SQUAREWAVE__FREQ) / this->sample_rate()), 2.0 * M_PI); |
| 1514 | 1347 | } |
| 1515 | 1348 | |
| 1516 | 1349 | DISCRETE_RESET(dss_squarewave) |
| 1517 | 1350 | { |
| 1518 | | DISCRETE_DECLARE_CONTEXT(dss_squarewave) |
| 1519 | | |
| 1520 | 1351 | double start; |
| 1521 | 1352 | |
| 1522 | 1353 | /* Establish starting phase, convert from degrees to radians */ |
| 1523 | 1354 | start = (DSS_SQUAREWAVE__PHASE / 360.0) * (2.0 * M_PI); |
| 1524 | 1355 | /* Make sure its always mod 2Pi */ |
| 1525 | | context->phase = fmod(start, 2.0 * M_PI); |
| 1356 | m_phase = fmod(start, 2.0 * M_PI); |
| 1526 | 1357 | |
| 1527 | 1358 | /* Step the output */ |
| 1528 | | DISCRETE_STEP_CALL(dss_squarewave); |
| 1359 | this->step(); |
| 1529 | 1360 | } |
| 1530 | 1361 | |
| 1531 | 1362 | /************************************************************************ |
| r10048 | r10049 | |
| 1549 | 1380 | |
| 1550 | 1381 | DISCRETE_STEP(dss_squarewfix) |
| 1551 | 1382 | { |
| 1552 | | DISCRETE_DECLARE_CONTEXT(dss_squarewfix) |
| 1383 | m_t_left -= m_sample_step; |
| 1553 | 1384 | |
| 1554 | | context->t_left -= context->sample_step; |
| 1555 | | |
| 1556 | 1385 | /* The enable input only curtails output, phase rotation still occurs */ |
| 1557 | | while (context->t_left <= 0) |
| 1386 | while (m_t_left <= 0) |
| 1558 | 1387 | { |
| 1559 | | context->flip_flop = context->flip_flop ? 0 : 1; |
| 1560 | | context->t_left += context->flip_flop ? context->t_on : context->t_off; |
| 1388 | m_flip_flop = m_flip_flop ? 0 : 1; |
| 1389 | m_t_left += m_flip_flop ? m_t_on : m_t_off; |
| 1561 | 1390 | } |
| 1562 | 1391 | |
| 1563 | 1392 | if(DSS_SQUAREWFIX__ENABLE) |
| 1564 | 1393 | { |
| 1565 | 1394 | /* Add gain and DC Bias component */ |
| 1566 | 1395 | |
| 1567 | | context->t_off = 1.0 / DSS_SQUAREWFIX__FREQ; /* cycle time */ |
| 1568 | | context->t_on = context->t_off * (DSS_SQUAREWFIX__DUTY / 100.0); |
| 1569 | | context->t_off -= context->t_on; |
| 1396 | m_t_off = 1.0 / DSS_SQUAREWFIX__FREQ; /* cycle time */ |
| 1397 | m_t_on = m_t_off * (DSS_SQUAREWFIX__DUTY / 100.0); |
| 1398 | m_t_off -= m_t_on; |
| 1570 | 1399 | |
| 1571 | | node->output[0] = (context->flip_flop ? DSS_SQUAREWFIX__AMP / 2.0 : -(DSS_SQUAREWFIX__AMP / 2.0)) + DSS_SQUAREWFIX__BIAS; |
| 1400 | this->output[0] = (m_flip_flop ? DSS_SQUAREWFIX__AMP / 2.0 : -(DSS_SQUAREWFIX__AMP / 2.0)) + DSS_SQUAREWFIX__BIAS; |
| 1572 | 1401 | } |
| 1573 | 1402 | else |
| 1574 | 1403 | { |
| 1575 | | node->output[0]=0; |
| 1404 | this->output[0]=0; |
| 1576 | 1405 | } |
| 1577 | 1406 | } |
| 1578 | 1407 | |
| 1579 | 1408 | DISCRETE_RESET(dss_squarewfix) |
| 1580 | 1409 | { |
| 1581 | | DISCRETE_DECLARE_CONTEXT(dss_squarewfix) |
| 1410 | m_sample_step = 1.0 / this->sample_rate(); |
| 1411 | m_flip_flop = 1; |
| 1582 | 1412 | |
| 1583 | | context->sample_step = 1.0 / node->info->sample_rate; |
| 1584 | | context->flip_flop = 1; |
| 1585 | | |
| 1586 | 1413 | /* Do the intial time shift and convert freq to off/on times */ |
| 1587 | | context->t_off = 1.0 / DSS_SQUAREWFIX__FREQ; /* cycle time */ |
| 1588 | | context->t_left = DSS_SQUAREWFIX__PHASE / 360.0; /* convert start phase to % */ |
| 1589 | | context->t_left = context->t_left - (int)context->t_left; /* keep % between 0 & 1 */ |
| 1590 | | context->t_left = (context->t_left < 0) ? 1.0 + context->t_left : context->t_left; /* if - then flip to + phase */ |
| 1591 | | context->t_left *= context->t_off; |
| 1592 | | context->t_on = context->t_off * (DSS_SQUAREWFIX__DUTY / 100.0); |
| 1593 | | context->t_off -= context->t_on; |
| 1414 | m_t_off = 1.0 / DSS_SQUAREWFIX__FREQ; /* cycle time */ |
| 1415 | m_t_left = DSS_SQUAREWFIX__PHASE / 360.0; /* convert start phase to % */ |
| 1416 | m_t_left = m_t_left - (int)m_t_left; /* keep % between 0 & 1 */ |
| 1417 | m_t_left = (m_t_left < 0) ? 1.0 + m_t_left : m_t_left; /* if - then flip to + phase */ |
| 1418 | m_t_left *= m_t_off; |
| 1419 | m_t_on = m_t_off * (DSS_SQUAREWFIX__DUTY / 100.0); |
| 1420 | m_t_off -= m_t_on; |
| 1594 | 1421 | |
| 1595 | | context->t_left = -context->t_left; |
| 1422 | m_t_left = -m_t_left; |
| 1596 | 1423 | |
| 1597 | 1424 | /* toggle output and work out intial time shift */ |
| 1598 | | while (context->t_left <= 0) |
| 1425 | while (m_t_left <= 0) |
| 1599 | 1426 | { |
| 1600 | | context->flip_flop = context->flip_flop ? 0 : 1; |
| 1601 | | context->t_left += context->flip_flop ? context->t_on : context->t_off; |
| 1427 | m_flip_flop = m_flip_flop ? 0 : 1; |
| 1428 | m_t_left += m_flip_flop ? m_t_on : m_t_off; |
| 1602 | 1429 | } |
| 1603 | 1430 | |
| 1604 | 1431 | /* Step the output */ |
| 1605 | | DISCRETE_STEP_CALL(dss_squarewfix); |
| 1432 | this->step(); |
| 1606 | 1433 | } |
| 1607 | 1434 | |
| 1608 | 1435 | |
| r10048 | r10049 | |
| 1627 | 1454 | |
| 1628 | 1455 | DISCRETE_STEP(dss_squarewave2) |
| 1629 | 1456 | { |
| 1630 | | DISCRETE_DECLARE_CONTEXT(dss_squarewave) |
| 1631 | | |
| 1632 | 1457 | double newphase; |
| 1633 | 1458 | |
| 1634 | 1459 | if(DSS_SQUAREWAVE2__ENABLE) |
| 1635 | 1460 | { |
| 1636 | 1461 | /* Establish trigger phase from time periods */ |
| 1637 | | context->trigger = (DSS_SQUAREWAVE2__T_OFF / (DSS_SQUAREWAVE2__T_OFF + DSS_SQUAREWAVE2__T_ON)) * (2.0 * M_PI); |
| 1462 | m_trigger = (DSS_SQUAREWAVE2__T_OFF / (DSS_SQUAREWAVE2__T_OFF + DSS_SQUAREWAVE2__T_ON)) * (2.0 * M_PI); |
| 1638 | 1463 | |
| 1639 | 1464 | /* Work out the phase step based on phase/freq & sample rate */ |
| 1640 | 1465 | /* The enable input only curtails output, phase rotation */ |
| r10048 | r10049 | |
| 1643 | 1468 | /* phase step = 2Pi/(output period/sample period) */ |
| 1644 | 1469 | /* boils out to */ |
| 1645 | 1470 | /* phase step = 2Pi/(output period*sample freq) */ |
| 1646 | | newphase = context->phase + ((2.0 * M_PI) / ((DSS_SQUAREWAVE2__T_OFF + DSS_SQUAREWAVE2__T_ON) * node->info->sample_rate)); |
| 1471 | newphase = m_phase + ((2.0 * M_PI) / ((DSS_SQUAREWAVE2__T_OFF + DSS_SQUAREWAVE2__T_ON) * this->sample_rate())); |
| 1647 | 1472 | /* Keep the new phasor in the 2Pi range.*/ |
| 1648 | | context->phase = fmod(newphase, 2.0 * M_PI); |
| 1473 | m_phase = fmod(newphase, 2.0 * M_PI); |
| 1649 | 1474 | |
| 1650 | | if(context->phase>context->trigger) |
| 1651 | | node->output[0] = DSS_SQUAREWAVE2__AMP / 2.0; |
| 1475 | if(m_phase>m_trigger) |
| 1476 | this->output[0] = DSS_SQUAREWAVE2__AMP / 2.0; |
| 1652 | 1477 | else |
| 1653 | | node->output[0] = -DSS_SQUAREWAVE2__AMP / 2.0; |
| 1478 | this->output[0] = -DSS_SQUAREWAVE2__AMP / 2.0; |
| 1654 | 1479 | |
| 1655 | 1480 | /* Add DC Bias component */ |
| 1656 | | node->output[0] = node->output[0] + DSS_SQUAREWAVE2__BIAS; |
| 1481 | this->output[0] = this->output[0] + DSS_SQUAREWAVE2__BIAS; |
| 1657 | 1482 | } |
| 1658 | 1483 | else |
| 1659 | 1484 | { |
| 1660 | | node->output[0] = 0; |
| 1485 | this->output[0] = 0; |
| 1661 | 1486 | } |
| 1662 | 1487 | } |
| 1663 | 1488 | |
| 1664 | 1489 | DISCRETE_RESET(dss_squarewave2) |
| 1665 | 1490 | { |
| 1666 | | DISCRETE_DECLARE_CONTEXT(dss_squarewave) |
| 1667 | | |
| 1668 | 1491 | double start; |
| 1669 | 1492 | |
| 1670 | 1493 | /* Establish starting phase, convert from degrees to radians */ |
| r10048 | r10049 | |
| 1674 | 1497 | else |
| 1675 | 1498 | start = 0.0; |
| 1676 | 1499 | /* Make sure its always mod 2Pi */ |
| 1677 | | context->phase = fmod(start, 2.0 * M_PI); |
| 1500 | m_phase = fmod(start, 2.0 * M_PI); |
| 1678 | 1501 | |
| 1679 | 1502 | /* Step the output */ |
| 1680 | | DISCRETE_STEP_CALL(dss_squarewave2); |
| 1503 | this->step(); |
| 1681 | 1504 | } |
| 1682 | 1505 | |
| 1683 | 1506 | /************************************************************************ |
| r10048 | r10049 | |
| 1698 | 1521 | #define DSS_INVERTER_OSC__C DISCRETE_INPUT(4) |
| 1699 | 1522 | #define DSS_INVERTER_OSC__R2 DISCRETE_INPUT(5) |
| 1700 | 1523 | |
| 1701 | | INLINE double dss_inverter_tftab(node_description *node, double x) |
| 1524 | |
| 1525 | /* FIXME: Make the following two static members of dss_inverter_osc */ |
| 1526 | inline double DISCRETE_CLASS_FUNC(dss_inverter_osc, tftab)(double x) |
| 1702 | 1527 | { |
| 1703 | | DISCRETE_DECLARE_CONTEXT(dss_inverter_osc) |
| 1704 | 1528 | DISCRETE_DECLARE_INFO(discrete_inverter_osc_desc) |
| 1705 | 1529 | |
| 1706 | 1530 | x = x / info->vB; |
| 1707 | 1531 | if (x > 0) |
| 1708 | | return info->vB * exp(-context->tf_a * pow(x, context->tf_b)); |
| 1532 | return info->vB * exp(-mc_tf_a * pow(x, mc_tf_b)); |
| 1709 | 1533 | else |
| 1710 | 1534 | return info->vB; |
| 1711 | 1535 | } |
| 1712 | 1536 | |
| 1713 | | INLINE double dss_inverter_tf(node_description *node, double x) |
| 1537 | inline double DISCRETE_CLASS_FUNC(dss_inverter_osc, tf)(double x) |
| 1714 | 1538 | { |
| 1715 | | DISCRETE_DECLARE_CONTEXT(dss_inverter_osc) |
| 1716 | 1539 | DISCRETE_DECLARE_INFO(discrete_inverter_osc_desc) |
| 1717 | 1540 | |
| 1718 | 1541 | if (x < 0.0) |
| 1719 | 1542 | return info->vB; |
| 1720 | 1543 | else if (x <= info->vB) |
| 1721 | | return context->tf_tab[(int)((double)(DSS_INV_TAB_SIZE - 1) * x / info->vB)]; |
| 1544 | return mc_tf_tab[(int)((double)(DSS_INV_TAB_SIZE - 1) * x / info->vB)]; |
| 1722 | 1545 | else |
| 1723 | | return context->tf_tab[DSS_INV_TAB_SIZE - 1]; |
| 1546 | return mc_tf_tab[DSS_INV_TAB_SIZE - 1]; |
| 1724 | 1547 | } |
| 1725 | 1548 | |
| 1726 | 1549 | DISCRETE_STEP(dss_inverter_osc) |
| 1727 | 1550 | { |
| 1728 | | DISCRETE_DECLARE_CONTEXT(dss_inverter_osc) |
| 1729 | 1551 | DISCRETE_DECLARE_INFO(discrete_inverter_osc_desc) |
| 1730 | | |
| 1731 | 1552 | double diff, vG1, vG2, vG3, vI; |
| 1732 | 1553 | double vMix, rMix; |
| 1733 | 1554 | int clamped; |
| 1734 | 1555 | |
| 1735 | 1556 | /* Get new state */ |
| 1736 | | vI = context->v_cap + context->v_g2_old; |
| 1557 | vI = mc_v_cap + mc_v_g2_old; |
| 1737 | 1558 | switch (info->options & DISC_OSC_INVERTER_TYPE_MASK) |
| 1738 | 1559 | { |
| 1739 | 1560 | case DISC_OSC_INVERTER_IS_TYPE1: |
| 1740 | 1561 | case DISC_OSC_INVERTER_IS_TYPE3: |
| 1741 | | vG1 = dss_inverter_tf(node, vI); |
| 1742 | | vG2 = dss_inverter_tf(node, vG1); |
| 1743 | | vG3 = dss_inverter_tf(node, vG2); |
| 1562 | vG1 = this->tf(vI); |
| 1563 | vG2 = this->tf(vG1); |
| 1564 | vG3 = this->tf(vG2); |
| 1744 | 1565 | break; |
| 1745 | 1566 | case DISC_OSC_INVERTER_IS_TYPE2: |
| 1746 | 1567 | vG1 = 0; |
| 1747 | | vG3 = dss_inverter_tf(node, vI); |
| 1748 | | vG2 = dss_inverter_tf(node, vG3); |
| 1568 | vG3 = this->tf(vI); |
| 1569 | vG2 = this->tf(vG3); |
| 1749 | 1570 | break; |
| 1750 | 1571 | case DISC_OSC_INVERTER_IS_TYPE4: |
| 1751 | 1572 | vI = MIN(DSS_INVERTER_OSC__ENABLE, vI + 0.7); |
| 1752 | 1573 | vG1 = 0; |
| 1753 | | vG3 = dss_inverter_tf(node, vI); |
| 1754 | | vG2 = dss_inverter_tf(node, vG3); |
| 1574 | vG3 = this->tf(vI); |
| 1575 | vG2 = this->tf(vG3); |
| 1755 | 1576 | break; |
| 1756 | 1577 | case DISC_OSC_INVERTER_IS_TYPE5: |
| 1757 | 1578 | vI = MAX(DSS_INVERTER_OSC__ENABLE, vI - 0.7); |
| 1758 | 1579 | vG1 = 0; |
| 1759 | | vG3 = dss_inverter_tf(node,vI); |
| 1760 | | vG2 = dss_inverter_tf(node,vG3); |
| 1580 | vG3 = this->tf(vI); |
| 1581 | vG2 = this->tf(vG3); |
| 1761 | 1582 | break; |
| 1762 | 1583 | default: |
| 1763 | | fatalerror("DISCRETE_INVERTER_OSC - Wrong type on NODE_%02d", node->index()); |
| 1584 | fatalerror("DISCRETE_INVERTER_OSC - Wrong type on NODE_%02d", this->index()); |
| 1764 | 1585 | } |
| 1765 | 1586 | |
| 1766 | 1587 | clamped = 0; |
| r10048 | r10049 | |
| 1785 | 1606 | case DISC_OSC_INVERTER_IS_TYPE3: |
| 1786 | 1607 | if (clamped) |
| 1787 | 1608 | { |
| 1788 | | double ratio = context->rp / (context->rp + context->r1); |
| 1609 | double ratio = mc_rp / (mc_rp + mc_r1); |
| 1789 | 1610 | diff = vG3 * (ratio) |
| 1790 | | - (context->v_cap + vG2) |
| 1611 | - (mc_v_cap + vG2) |
| 1791 | 1612 | + vI * (1.0 - ratio); |
| 1792 | | diff = diff - diff * context->wc; |
| 1613 | diff = diff - diff * mc_wc; |
| 1793 | 1614 | } |
| 1794 | 1615 | else |
| 1795 | 1616 | { |
| 1796 | | diff = vG3 - (context->v_cap + vG2); |
| 1797 | | diff = diff - diff * context->w; |
| 1617 | diff = vG3 - (mc_v_cap + vG2); |
| 1618 | diff = diff - diff * mc_w; |
| 1798 | 1619 | } |
| 1799 | 1620 | break; |
| 1800 | 1621 | case DISC_OSC_INVERTER_IS_TYPE4: |
| 1801 | 1622 | /* FIXME handle r2 = 0 */ |
| 1802 | | rMix = (context->r1 * context->r2) / (context->r1 + context->r2); |
| 1803 | | vMix = rMix* ((vG3 - vG2) / context->r1 + (DSS_INVERTER_OSC__MOD-vG2) / context->r2); |
| 1623 | rMix = (mc_r1 * mc_r2) / (mc_r1 + mc_r2); |
| 1624 | vMix = rMix* ((vG3 - vG2) / mc_r1 + (DSS_INVERTER_OSC__MOD-vG2) / mc_r2); |
| 1804 | 1625 | if (vMix < (vI-vG2-0.7)) |
| 1805 | 1626 | { |
| 1806 | | rMix = 1.0 / rMix + 1.0 / context->rp; |
| 1627 | rMix = 1.0 / rMix + 1.0 / mc_rp; |
| 1807 | 1628 | rMix = 1.0 / rMix; |
| 1808 | | vMix = rMix* ( (vG3-vG2) / context->r1 + (DSS_INVERTER_OSC__MOD-vG2) / context->r2 |
| 1809 | | + (vI - 0.7 - vG2) / context->rp); |
| 1629 | vMix = rMix* ( (vG3-vG2) / mc_r1 + (DSS_INVERTER_OSC__MOD-vG2) / mc_r2 |
| 1630 | + (vI - 0.7 - vG2) / mc_rp); |
| 1810 | 1631 | } |
| 1811 | | diff = vMix - context->v_cap; |
| 1812 | | diff = diff - diff * exp(-node->info->sample_time / (context->c * rMix)); |
| 1632 | diff = vMix - mc_v_cap; |
| 1633 | diff = diff - diff * exp(-this->sample_time() / (mc_c * rMix)); |
| 1813 | 1634 | break; |
| 1814 | 1635 | case DISC_OSC_INVERTER_IS_TYPE5: |
| 1815 | 1636 | /* FIXME handle r2 = 0 */ |
| 1816 | | rMix = (context->r1 * context->r2) / (context->r1 + context->r2); |
| 1817 | | vMix = rMix* ((vG3 - vG2) / context->r1 + (DSS_INVERTER_OSC__MOD - vG2) / context->r2); |
| 1637 | rMix = (mc_r1 * mc_r2) / (mc_r1 + mc_r2); |
| 1638 | vMix = rMix* ((vG3 - vG2) / mc_r1 + (DSS_INVERTER_OSC__MOD - vG2) / mc_r2); |
| 1818 | 1639 | if (vMix > (vI -vG2 + 0.7)) |
| 1819 | 1640 | { |
| 1820 | | rMix = 1.0 / rMix + 1.0 / context->rp; |
| 1641 | rMix = 1.0 / rMix + 1.0 / mc_rp; |
| 1821 | 1642 | rMix = 1.0 / rMix; |
| 1822 | | vMix = rMix * ( (vG3 - vG2) / context->r1 + (DSS_INVERTER_OSC__MOD - vG2) / context->r2 |
| 1823 | | + (vI + 0.7 - vG2) / context->rp); |
| 1643 | vMix = rMix * ( (vG3 - vG2) / mc_r1 + (DSS_INVERTER_OSC__MOD - vG2) / mc_r2 |
| 1644 | + (vI + 0.7 - vG2) / mc_rp); |
| 1824 | 1645 | } |
| 1825 | | diff = vMix - context->v_cap; |
| 1826 | | diff = diff - diff * exp(-node->info->sample_time/(context->c * rMix)); |
| 1646 | diff = vMix - mc_v_cap; |
| 1647 | diff = diff - diff * exp(-this->sample_time()/(mc_c * rMix)); |
| 1827 | 1648 | break; |
| 1828 | 1649 | default: |
| 1829 | | fatalerror("DISCRETE_INVERTER_OSC - Wrong type on NODE_%02d", node->index()); |
| 1650 | fatalerror("DISCRETE_INVERTER_OSC - Wrong type on NODE_%02d", this->index()); |
| 1830 | 1651 | } |
| 1831 | | context->v_cap += diff; |
| 1832 | | context->v_g2_old = vG2; |
| 1652 | mc_v_cap += diff; |
| 1653 | mc_v_g2_old = vG2; |
| 1833 | 1654 | if ((info->options & DISC_OSC_INVERTER_TYPE_MASK) == DISC_OSC_INVERTER_IS_TYPE3) |
| 1834 | | node->output[0] = vG1; |
| 1655 | this->output[0] = vG1; |
| 1835 | 1656 | else |
| 1836 | | node->output[0] = vG3; |
| 1657 | this->output[0] = vG3; |
| 1837 | 1658 | if (info->options & DISC_OSC_INVERTER_OUT_IS_LOGIC) |
| 1838 | | node->output[0] = (node->output[0] > info->vInFall); |
| 1659 | this->output[0] = (this->output[0] > info->vInFall); |
| 1839 | 1660 | } |
| 1840 | 1661 | |
| 1841 | 1662 | DISCRETE_RESET(dss_inverter_osc) |
| 1842 | 1663 | { |
| 1843 | | DISCRETE_DECLARE_CONTEXT(dss_inverter_osc) |
| 1844 | 1664 | DISCRETE_DECLARE_INFO(discrete_inverter_osc_desc) |
| 1845 | 1665 | |
| 1846 | 1666 | int i; |
| 1847 | 1667 | |
| 1848 | 1668 | /* exponent */ |
| 1849 | | context->w = exp(-node->info->sample_time / (DSS_INVERTER_OSC__RC * DSS_INVERTER_OSC__C)); |
| 1850 | | context->wc = exp(-node->info->sample_time / ((DSS_INVERTER_OSC__RC * DSS_INVERTER_OSC__RP) / (DSS_INVERTER_OSC__RP + DSS_INVERTER_OSC__RC) * DSS_INVERTER_OSC__C)); |
| 1851 | | node->output[0] = 0; |
| 1852 | | context->v_cap = 0; |
| 1853 | | context->v_g2_old = 0; |
| 1854 | | context->rp = DSS_INVERTER_OSC__RP; |
| 1855 | | context->r1 = DSS_INVERTER_OSC__RC; |
| 1856 | | context->r2 = DSS_INVERTER_OSC__R2; |
| 1857 | | context->c = DSS_INVERTER_OSC__C; |
| 1858 | | context->tf_b = (log(0.0 - log(info->vOutLow/info->vB)) - log(0.0 - log((info->vOutHigh/info->vB))) ) / log(info->vInRise / info->vInFall); |
| 1859 | | context->tf_a = log(0.0 - log(info->vOutLow/info->vB)) - context->tf_b * log(info->vInRise/info->vB); |
| 1860 | | context->tf_a = exp(context->tf_a); |
| 1669 | mc_w = exp(-this->sample_time() / (DSS_INVERTER_OSC__RC * DSS_INVERTER_OSC__C)); |
| 1670 | mc_wc = exp(-this->sample_time() / ((DSS_INVERTER_OSC__RC * DSS_INVERTER_OSC__RP) / (DSS_INVERTER_OSC__RP + DSS_INVERTER_OSC__RC) * DSS_INVERTER_OSC__C)); |
| 1671 | this->output[0] = 0; |
| 1672 | mc_v_cap = 0; |
| 1673 | mc_v_g2_old = 0; |
| 1674 | mc_rp = DSS_INVERTER_OSC__RP; |
| 1675 | mc_r1 = DSS_INVERTER_OSC__RC; |
| 1676 | mc_r2 = DSS_INVERTER_OSC__R2; |
| 1677 | mc_c = DSS_INVERTER_OSC__C; |
| 1678 | mc_tf_b = (log(0.0 - log(info->vOutLow/info->vB)) - log(0.0 - log((info->vOutHigh/info->vB))) ) / log(info->vInRise / info->vInFall); |
| 1679 | mc_tf_a = log(0.0 - log(info->vOutLow/info->vB)) - mc_tf_b * log(info->vInRise/info->vB); |
| 1680 | mc_tf_a = exp(mc_tf_a); |
| 1861 | 1681 | |
| 1862 | 1682 | for (i = 0; i < DSS_INV_TAB_SIZE; i++) |
| 1863 | 1683 | { |
| 1864 | | context->tf_tab[i] = dss_inverter_tftab(node, (double)i / (double)(DSS_INV_TAB_SIZE - 1) * info->vB); |
| 1684 | mc_tf_tab[i] = this->tftab((double)i / (double)(DSS_INV_TAB_SIZE - 1) * info->vB); |
| 1865 | 1685 | } |
| 1866 | 1686 | } |
| 1867 | 1687 | |
| r10048 | r10049 | |
| 1884 | 1704 | |
| 1885 | 1705 | DISCRETE_STEP(dss_trianglewave) |
| 1886 | 1706 | { |
| 1887 | | DISCRETE_DECLARE_CONTEXT(dss_trianglewave) |
| 1888 | | |
| 1889 | 1707 | if(DSS_TRIANGLEWAVE__ENABLE) |
| 1890 | 1708 | { |
| 1891 | | node->output[0] = context->phase < M_PI ? (DSS_TRIANGLEWAVE__AMP * (context->phase / (M_PI / 2.0) - 1.0)) / 2.0 : |
| 1892 | | (DSS_TRIANGLEWAVE__AMP * (3.0 - context->phase / (M_PI / 2.0))) / 2.0 ; |
| 1709 | this->output[0] = m_phase < M_PI ? (DSS_TRIANGLEWAVE__AMP * (m_phase / (M_PI / 2.0) - 1.0)) / 2.0 : |
| 1710 | (DSS_TRIANGLEWAVE__AMP * (3.0 - m_phase / (M_PI / 2.0))) / 2.0 ; |
| 1893 | 1711 | |
| 1894 | 1712 | /* Add DC Bias component */ |
| 1895 | | node->output[0] = node->output[0] + DSS_TRIANGLEWAVE__BIAS; |
| 1713 | this->output[0] = this->output[0] + DSS_TRIANGLEWAVE__BIAS; |
| 1896 | 1714 | } |
| 1897 | 1715 | else |
| 1898 | 1716 | { |
| 1899 | | node->output[0] = 0; |
| 1717 | this->output[0] = 0; |
| 1900 | 1718 | } |
| 1901 | 1719 | |
| 1902 | 1720 | /* Work out the phase step based on phase/freq & sample rate */ |
| r10048 | r10049 | |
| 1906 | 1724 | /* boils out to */ |
| 1907 | 1725 | /* phase step = (2Pi*output freq)/sample freq) */ |
| 1908 | 1726 | /* Also keep the new phasor in the 2Pi range. */ |
| 1909 | | context->phase=fmod((context->phase + ((2.0 * M_PI * DSS_TRIANGLEWAVE__FREQ) / node->info->sample_rate)), 2.0 * M_PI); |
| 1727 | m_phase=fmod((m_phase + ((2.0 * M_PI * DSS_TRIANGLEWAVE__FREQ) / this->sample_rate())), 2.0 * M_PI); |
| 1910 | 1728 | } |
| 1911 | 1729 | |
| 1912 | 1730 | DISCRETE_RESET(dss_trianglewave) |
| 1913 | 1731 | { |
| 1914 | | DISCRETE_DECLARE_CONTEXT(dss_trianglewave) |
| 1915 | | |
| 1916 | 1732 | double start; |
| 1917 | 1733 | |
| 1918 | 1734 | /* Establish starting phase, convert from degrees to radians */ |
| 1919 | 1735 | start = (DSS_TRIANGLEWAVE__PHASE / 360.0) * (2.0 * M_PI); |
| 1920 | 1736 | /* Make sure its always mod 2Pi */ |
| 1921 | | context->phase=fmod(start, 2.0 * M_PI); |
| 1737 | m_phase=fmod(start, 2.0 * M_PI); |
| 1922 | 1738 | |
| 1923 | 1739 | /* Step to set the output */ |
| 1924 | | DISCRETE_STEP_CALL(dss_trianglewave); |
| 1740 | this->step(); |
| 1925 | 1741 | } |
| 1926 | 1742 | |
| 1927 | 1743 | |
| r10048 | r10049 | |
| 1940 | 1756 | { |
| 1941 | 1757 | if(DSS_ADSR__ENABLE) |
| 1942 | 1758 | { |
| 1943 | | node->output[0] = 0; |
| 1759 | this->output[0] = 0; |
| 1944 | 1760 | } |
| 1945 | 1761 | else |
| 1946 | 1762 | { |
| 1947 | | node->output[0] = 0; |
| 1763 | this->output[0] = 0; |
| 1948 | 1764 | } |
| 1949 | 1765 | } |
| 1950 | 1766 | |
| 1951 | 1767 | |
| 1952 | 1768 | DISCRETE_RESET(dss_adsrenv) |
| 1953 | 1769 | { |
| 1954 | | DISCRETE_STEP_CALL(dss_adsrenv); |
| 1770 | this->step(); |
| 1955 | 1771 | } |
src/emu/sound/disc_flt.c
| r10048 | r10049 | |
| 27 | 27 | * |
| 28 | 28 | ************************************************************************/ |
| 29 | 29 | |
| 30 | | struct dst_filter1_context |
| 31 | | { |
| 32 | | double x1; /* x[k-1], previous input value */ |
| 33 | | double y1; /* y[k-1], previous output value */ |
| 34 | | double a1; /* digital filter coefficients, denominator */ |
| 35 | | double b0, b1; /* digital filter coefficients, numerator */ |
| 36 | | }; |
| 37 | 30 | |
| 38 | | struct dst_filter2_context |
| 39 | | { |
| 40 | | double x1, x2; /* x[k-1], x[k-2], previous 2 input values */ |
| 41 | | double y1, y2; /* y[k-1], y[k-2], previous 2 output values */ |
| 42 | | double a1, a2; /* digital filter coefficients, denominator */ |
| 43 | | double b0, b1, b2; /* digital filter coefficients, numerator */ |
| 44 | | }; |
| 45 | | |
| 46 | | struct dst_op_amp_filt_context |
| 47 | | { |
| 48 | | int type; /* What kind of filter */ |
| 49 | | int is_norton; /* 1 = Norton op-amps */ |
| 50 | | double vRef; |
| 51 | | double vP; |
| 52 | | double vN; |
| 53 | | double rTotal; /* All input resistance in parallel. */ |
| 54 | | double iFixed; /* Current supplied by r3 & r4 if used. */ |
| 55 | | double exponentC1; |
| 56 | | double exponentC2; |
| 57 | | double exponentC3; |
| 58 | | double rRatio; /* divide ratio of resistance network */ |
| 59 | | double vC1; /* Charge on C1 */ |
| 60 | | double vC1b; /* Charge on C1, part of C1 charge if needed */ |
| 61 | | double vC2; /* Charge on C2 */ |
| 62 | | double vC3; /* Charge on C2 */ |
| 63 | | double gain; /* Gain of the filter */ |
| 64 | | double x1, x2; /* x[k-1], x[k-2], previous 2 input values */ |
| 65 | | double y1, y2; /* y[k-1], y[k-2], previous 2 output values */ |
| 66 | | double a1,a2; /* digital filter coefficients, denominator */ |
| 67 | | double b0,b1,b2; /* digital filter coefficients, numerator */ |
| 68 | | }; |
| 69 | | |
| 70 | | struct dst_rc_circuit_1_context |
| 71 | | { |
| 72 | | double v_cap; |
| 73 | | double v_charge_1_2; |
| 74 | | double v_drop; |
| 75 | | double exp_1; |
| 76 | | double exp_1_2; |
| 77 | | double exp_2; |
| 78 | | }; |
| 79 | | |
| 80 | | struct dst_rcdisc_context |
| 81 | | { |
| 82 | | int state; |
| 83 | | double t; /* time */ |
| 84 | | double exponent0; |
| 85 | | double exponent1; |
| 86 | | double v_cap; /* rcdisc5 */ |
| 87 | | double v_diode; /* rcdisc3 */ |
| 88 | | }; |
| 89 | | |
| 90 | | struct dst_rcdisc_mod_context |
| 91 | | { |
| 92 | | double v_cap; |
| 93 | | double exp_low[2]; |
| 94 | | double exp_high[4]; |
| 95 | | double gain[2]; |
| 96 | | double vd_gain[4]; |
| 97 | | }; |
| 98 | | |
| 99 | | struct dst_rcdisc4_context |
| 100 | | { |
| 101 | | int type; |
| 102 | | double max_out; |
| 103 | | double vC1; |
| 104 | | double v[2]; |
| 105 | | double exp[2]; |
| 106 | | }; |
| 107 | | |
| 108 | | struct dst_rcfilter_context |
| 109 | | { |
| 110 | | double vCap; |
| 111 | | double rc; |
| 112 | | double exponent; |
| 113 | | UINT8 has_rc_nodes; |
| 114 | | }; |
| 115 | | |
| 116 | | struct dst_rcfilter_sw_context |
| 117 | | { |
| 118 | | double vCap[4]; |
| 119 | | double exp[4]; |
| 120 | | double exp0; /* fast case bit 0 */ |
| 121 | | double exp1; /* fast case bit 1 */ |
| 122 | | double factor; /* fast case */ |
| 123 | | double f1[16]; |
| 124 | | double f2[16]; |
| 125 | | }; |
| 126 | | |
| 127 | | struct dst_rcintegrate_context |
| 128 | | { |
| 129 | | int type; |
| 130 | | double gain_r1_r2; |
| 131 | | double f; /* r2,r3 gain */ |
| 132 | | double vCap; |
| 133 | | double vCE; |
| 134 | | double exponent0; |
| 135 | | double exponent1; |
| 136 | | double exp_exponent0; |
| 137 | | double exp_exponent1; |
| 138 | | double c_exp0; |
| 139 | | double c_exp1; |
| 140 | | }; |
| 141 | | |
| 142 | 31 | /************************************************************************ |
| 143 | 32 | * |
| 144 | 33 | * DST_CRFILTER - Usage of node_description values for CR filter |
| r10048 | r10049 | |
| 157 | 46 | |
| 158 | 47 | DISCRETE_STEP(dst_crfilter) |
| 159 | 48 | { |
| 160 | | DISCRETE_DECLARE_CONTEXT(dst_rcfilter) |
| 161 | | |
| 162 | | if (UNEXPECTED(context->has_rc_nodes)) |
| 49 | if (UNEXPECTED(m_has_rc_nodes)) |
| 163 | 50 | { |
| 164 | 51 | double rc = DST_CRFILTER__R * DST_CRFILTER__C; |
| 165 | | if (rc != context->rc) |
| 52 | if (rc != m_rc) |
| 166 | 53 | { |
| 167 | | context->rc = rc; |
| 168 | | context->exponent = RC_CHARGE_EXP(rc); |
| 54 | m_rc = rc; |
| 55 | m_exponent = RC_CHARGE_EXP_CLASS(rc); |
| 169 | 56 | } |
| 170 | 57 | } |
| 171 | 58 | |
| 172 | | double v_out = DST_CRFILTER__IN - context->vCap; |
| 59 | double v_out = DST_CRFILTER__IN - m_vCap; |
| 173 | 60 | double v_diff = v_out - DST_CRFILTER__VREF; |
| 174 | | node->output[0] = v_out; |
| 175 | | context->vCap += v_diff * context->exponent; |
| 61 | this->output[0] = v_out; |
| 62 | m_vCap += v_diff * m_exponent; |
| 176 | 63 | } |
| 177 | 64 | |
| 178 | 65 | DISCRETE_RESET(dst_crfilter) |
| 179 | 66 | { |
| 180 | | DISCRETE_DECLARE_CONTEXT(dst_rcfilter) |
| 181 | | |
| 182 | | context->has_rc_nodes = node->input_is_node() & 0x6; |
| 183 | | context->rc = DST_CRFILTER__R * DST_CRFILTER__C; |
| 184 | | context->exponent = RC_CHARGE_EXP(context->rc); |
| 185 | | context->vCap = 0; |
| 186 | | node->output[0] = DST_CRFILTER__IN; |
| 67 | m_has_rc_nodes = this->input_is_node() & 0x6; |
| 68 | m_rc = DST_CRFILTER__R * DST_CRFILTER__C; |
| 69 | m_exponent = RC_CHARGE_EXP_CLASS(m_rc); |
| 70 | m_vCap = 0; |
| 71 | this->output[0] = DST_CRFILTER__IN; |
| 187 | 72 | } |
| 188 | 73 | |
| 189 | 74 | |
| r10048 | r10049 | |
| 202 | 87 | #define DST_FILTER1__FREQ DISCRETE_INPUT(2) |
| 203 | 88 | #define DST_FILTER1__TYPE DISCRETE_INPUT(3) |
| 204 | 89 | |
| 205 | | static void calculate_filter1_coefficients(const discrete_info *disc_info, double fc, double type, |
| 206 | | double *a1, double *b0, double *b1) |
| 90 | static void calculate_filter1_coefficients(discrete_base_node *node, double fc, double type, |
| 91 | struct discrete_filter_coeff &coeff) |
| 207 | 92 | { |
| 208 | 93 | double den, w, two_over_T; |
| 209 | 94 | |
| 210 | 95 | /* calculate digital filter coefficents */ |
| 211 | 96 | /*w = 2.0*M_PI*fc; no pre-warping */ |
| 212 | | w = disc_info->sample_rate*2.0*tan(M_PI*fc/disc_info->sample_rate); /* pre-warping */ |
| 213 | | two_over_T = 2.0*disc_info->sample_rate; |
| 97 | w = node->sample_rate()*2.0*tan(M_PI*fc/node->sample_rate()); /* pre-warping */ |
| 98 | two_over_T = 2.0*node->sample_rate(); |
| 214 | 99 | |
| 215 | 100 | den = w + two_over_T; |
| 216 | | *a1 = (w - two_over_T)/den; |
| 101 | coeff.a1 = (w - two_over_T)/den; |
| 217 | 102 | if (type == DISC_FILTER_LOWPASS) |
| 218 | 103 | { |
| 219 | | *b0 = *b1 = w/den; |
| 104 | coeff.b0 = coeff.b1 = w/den; |
| 220 | 105 | } |
| 221 | 106 | else if (type == DISC_FILTER_HIGHPASS) |
| 222 | 107 | { |
| 223 | | *b0 = two_over_T/den; |
| 224 | | *b1 = -(*b0); |
| 108 | coeff.b0 = two_over_T/den; |
| 109 | coeff.b1 = -(coeff.b0); |
| 225 | 110 | } |
| 226 | 111 | else |
| 227 | 112 | { |
| 228 | | discrete_log(disc_info, "calculate_filter1_coefficients() - Invalid filter type for 1st order filter."); |
| 113 | node->device->discrete_log("calculate_filter1_coefficients() - Invalid filter type for 1st order filter."); |
| 229 | 114 | } |
| 230 | 115 | } |
| 231 | 116 | |
| 232 | 117 | DISCRETE_STEP(dst_filter1) |
| 233 | 118 | { |
| 234 | | DISCRETE_DECLARE_CONTEXT(dst_filter1) |
| 235 | | |
| 236 | 119 | double gain = 1.0; |
| 237 | 120 | |
| 238 | 121 | if (DST_FILTER1__ENABLE == 0.0) |
| r10048 | r10049 | |
| 240 | 123 | gain = 0.0; |
| 241 | 124 | } |
| 242 | 125 | |
| 243 | | node->output[0] = -context->a1*context->y1 + context->b0*gain*DST_FILTER1__IN + context->b1*context->x1; |
| 126 | this->output[0] = -m_fc.a1*m_fc.y1 + m_fc.b0*gain*DST_FILTER1__IN + m_fc.b1*m_fc.x1; |
| 244 | 127 | |
| 245 | | context->x1 = gain*DST_FILTER1__IN; |
| 246 | | context->y1 = node->output[0]; |
| 128 | m_fc.x1 = gain*DST_FILTER1__IN; |
| 129 | m_fc.y1 = this->output[0]; |
| 247 | 130 | } |
| 248 | 131 | |
| 249 | 132 | DISCRETE_RESET(dst_filter1) |
| 250 | 133 | { |
| 251 | | DISCRETE_DECLARE_CONTEXT(dst_filter1) |
| 252 | | |
| 253 | | calculate_filter1_coefficients(node->info, DST_FILTER1__FREQ, DST_FILTER1__TYPE, &context->a1, &context->b0, &context->b1); |
| 254 | | node->output[0] = 0; |
| 134 | calculate_filter1_coefficients(this, DST_FILTER1__FREQ, DST_FILTER1__TYPE, m_fc); |
| 135 | this->output[0] = 0; |
| 255 | 136 | } |
| 256 | 137 | |
| 257 | 138 | |
| r10048 | r10049 | |
| 272 | 153 | #define DST_FILTER2__DAMP DISCRETE_INPUT(3) |
| 273 | 154 | #define DST_FILTER2__TYPE DISCRETE_INPUT(4) |
| 274 | 155 | |
| 275 | | static void calculate_filter2_coefficients(const discrete_info *disc_info, |
| 156 | static void calculate_filter2_coefficients(discrete_base_node *node, |
| 276 | 157 | double fc, double d, double type, |
| 277 | | double *a1, double *a2, |
| 278 | | double *b0, double *b1, double *b2) |
| 158 | struct discrete_filter_coeff &coeff) |
| 279 | 159 | { |
| 280 | 160 | double w; /* cutoff freq, in radians/sec */ |
| 281 | 161 | double w_squared; |
| 282 | 162 | double den; /* temp variable */ |
| 283 | | double two_over_T = 2 * disc_info->sample_rate; |
| 163 | double two_over_T = 2 * node->sample_rate(); |
| 284 | 164 | double two_over_T_squared = two_over_T * two_over_T; |
| 285 | 165 | |
| 286 | 166 | /* calculate digital filter coefficents */ |
| 287 | 167 | /*w = 2.0*M_PI*fc; no pre-warping */ |
| 288 | | w = disc_info->sample_rate * 2.0 * tan(M_PI * fc / disc_info->sample_rate); /* pre-warping */ |
| 168 | w = node->sample_rate() * 2.0 * tan(M_PI * fc / node->sample_rate()); /* pre-warping */ |
| 289 | 169 | w_squared = w * w; |
| 290 | 170 | |
| 291 | 171 | den = two_over_T_squared + d*w*two_over_T + w_squared; |
| 292 | 172 | |
| 293 | | *a1 = 2.0 * (-two_over_T_squared + w_squared) / den; |
| 294 | | *a2 = (two_over_T_squared - d * w * two_over_T + w_squared) / den; |
| 173 | coeff.a1 = 2.0 * (-two_over_T_squared + w_squared) / den; |
| 174 | coeff.a2 = (two_over_T_squared - d * w * two_over_T + w_squared) / den; |
| 295 | 175 | |
| 296 | 176 | if (type == DISC_FILTER_LOWPASS) |
| 297 | 177 | { |
| 298 | | *b0 = *b2 = w_squared/den; |
| 299 | | *b1 = 2.0 * (*b0); |
| 178 | coeff.b0 = coeff.b2 = w_squared/den; |
| 179 | coeff.b1 = 2.0 * (coeff.b0); |
| 300 | 180 | } |
| 301 | 181 | else if (type == DISC_FILTER_BANDPASS) |
| 302 | 182 | { |
| 303 | | *b0 = d * w * two_over_T / den; |
| 304 | | *b1 = 0.0; |
| 305 | | *b2 = -(*b0); |
| 183 | coeff.b0 = d * w * two_over_T / den; |
| 184 | coeff.b1 = 0.0; |
| 185 | coeff.b2 = -(coeff.b0); |
| 306 | 186 | } |
| 307 | 187 | else if (type == DISC_FILTER_HIGHPASS) |
| 308 | 188 | { |
| 309 | | *b0 = *b2 = two_over_T_squared / den; |
| 310 | | *b1 = -2.0 * (*b0); |
| 189 | coeff.b0 = coeff.b2 = two_over_T_squared / den; |
| 190 | coeff.b1 = -2.0 * (coeff.b0); |
| 311 | 191 | } |
| 312 | 192 | else |
| 313 | 193 | { |
| 314 | | discrete_log(disc_info, "calculate_filter2_coefficients() - Invalid filter type for 2nd order filter."); |
| 194 | node->device->discrete_log("calculate_filter2_coefficients() - Invalid filter type for 2nd order filter."); |
| 315 | 195 | } |
| 316 | 196 | } |
| 317 | 197 | |
| 318 | 198 | DISCRETE_STEP(dst_filter2) |
| 319 | 199 | { |
| 320 | | DISCRETE_DECLARE_CONTEXT(dst_filter2) |
| 321 | | |
| 322 | 200 | double gain = 1.0; |
| 323 | 201 | |
| 324 | 202 | if (DST_FILTER2__ENABLE == 0.0) |
| r10048 | r10049 | |
| 326 | 204 | gain = 0.0; |
| 327 | 205 | } |
| 328 | 206 | |
| 329 | | node->output[0] = -context->a1 * context->y1 - context->a2 * context->y2 + |
| 330 | | context->b0 * gain * DST_FILTER2__IN + context->b1 * context->x1 + context->b2 * context->x2; |
| 207 | this->output[0] = -m_fc.a1 * m_fc.y1 - m_fc.a2 * m_fc.y2 + |
| 208 | m_fc.b0 * gain * DST_FILTER2__IN + m_fc.b1 * m_fc.x1 + m_fc.b2 * m_fc.x2; |
| 331 | 209 | |
| 332 | | context->x2 = context->x1; |
| 333 | | context->x1 = gain * DST_FILTER2__IN; |
| 334 | | context->y2 = context->y1; |
| 335 | | context->y1 = node->output[0]; |
| 210 | m_fc.x2 = m_fc.x1; |
| 211 | m_fc.x1 = gain * DST_FILTER2__IN; |
| 212 | m_fc.y2 = m_fc.y1; |
| 213 | m_fc.y1 = this->output[0]; |
| 336 | 214 | } |
| 337 | 215 | |
| 338 | 216 | DISCRETE_RESET(dst_filter2) |
| 339 | 217 | { |
| 340 | | DISCRETE_DECLARE_CONTEXT(dst_filter2) |
| 341 | | |
| 342 | | calculate_filter2_coefficients(node->info, DST_FILTER2__FREQ, DST_FILTER2__DAMP, DST_FILTER2__TYPE, |
| 343 | | &context->a1, &context->a2, |
| 344 | | &context->b0, &context->b1, &context->b2); |
| 345 | | node->output[0] = 0; |
| 218 | calculate_filter2_coefficients(this, DST_FILTER2__FREQ, DST_FILTER2__DAMP, DST_FILTER2__TYPE, |
| 219 | m_fc); |
| 220 | this->output[0] = 0; |
| 346 | 221 | } |
| 347 | 222 | |
| 348 | 223 | |
| r10048 | r10049 | |
| 366 | 241 | |
| 367 | 242 | DISCRETE_STEP(dst_op_amp_filt) |
| 368 | 243 | { |
| 369 | | DISCRETE_DECLARE_CONTEXT(dst_op_amp_filt) |
| 370 | 244 | DISCRETE_DECLARE_INFO(discrete_op_amp_filt_info) |
| 371 | 245 | |
| 372 | 246 | double i, v = 0; |
| 373 | 247 | |
| 374 | 248 | if (DST_OP_AMP_FILT__ENABLE) |
| 375 | 249 | { |
| 376 | | if (context->is_norton) |
| 250 | if (m_is_norton) |
| 377 | 251 | { |
| 378 | 252 | v = DST_OP_AMP_FILT__INP1 - OP_AMP_NORTON_VBE; |
| 379 | 253 | if (v < 0) v = 0; |
| r10048 | r10049 | |
| 381 | 255 | else |
| 382 | 256 | { |
| 383 | 257 | /* Millman the input voltages. */ |
| 384 | | i = context->iFixed; |
| 385 | | switch (context->type) |
| 258 | i = m_iFixed; |
| 259 | switch (m_type) |
| 386 | 260 | { |
| 387 | 261 | case DISC_OP_AMP_FILTER_IS_LOW_PASS_1_A: |
| 388 | 262 | i += (DST_OP_AMP_FILT__INP1 - DST_OP_AMP_FILT__INP2) / info->r1; |
| 389 | 263 | if (info->r2 != 0) |
| 390 | | i += (context->vP - DST_OP_AMP_FILT__INP2) / info->r2; |
| 264 | i += (m_vP - DST_OP_AMP_FILT__INP2) / info->r2; |
| 391 | 265 | if (info->r3 != 0) |
| 392 | | i += (context->vN - DST_OP_AMP_FILT__INP2) / info->r3; |
| 266 | i += (m_vN - DST_OP_AMP_FILT__INP2) / info->r3; |
| 393 | 267 | break; |
| 394 | 268 | default: |
| 395 | | i += (DST_OP_AMP_FILT__INP1 - context->vRef) / info->r1; |
| 269 | i += (DST_OP_AMP_FILT__INP1 - m_vRef) / info->r1; |
| 396 | 270 | if (info->r2 != 0) |
| 397 | | i += (DST_OP_AMP_FILT__INP2 - context->vRef) / info->r2; |
| 271 | i += (DST_OP_AMP_FILT__INP2 - m_vRef) / info->r2; |
| 398 | 272 | break; |
| 399 | 273 | } |
| 400 | | v = i * context->rTotal; |
| 274 | v = i * m_rTotal; |
| 401 | 275 | } |
| 402 | 276 | |
| 403 | | switch (context->type) |
| 277 | switch (m_type) |
| 404 | 278 | { |
| 405 | 279 | case DISC_OP_AMP_FILTER_IS_LOW_PASS_1: |
| 406 | | context->vC1 += (v - context->vC1) * context->exponentC1; |
| 407 | | node->output[0] = context->vC1 * context->gain + info->vRef; |
| 280 | m_vC1 += (v - m_vC1) * m_exponentC1; |
| 281 | this->output[0] = m_vC1 * m_gain + info->vRef; |
| 408 | 282 | break; |
| 409 | 283 | |
| 410 | 284 | case DISC_OP_AMP_FILTER_IS_LOW_PASS_1_A: |
| 411 | | context->vC1 += (v - context->vC1) * context->exponentC1; |
| 412 | | node->output[0] = context->vC1 * context->gain + DST_OP_AMP_FILT__INP2; |
| 285 | m_vC1 += (v - m_vC1) * m_exponentC1; |
| 286 | this->output[0] = m_vC1 * m_gain + DST_OP_AMP_FILT__INP2; |
| 413 | 287 | break; |
| 414 | 288 | |
| 415 | 289 | case DISC_OP_AMP_FILTER_IS_HIGH_PASS_1: |
| 416 | | node->output[0] = (v - context->vC1) * context->gain + info->vRef; |
| 417 | | context->vC1 += (v - context->vC1) * context->exponentC1; |
| 290 | this->output[0] = (v - m_vC1) * m_gain + info->vRef; |
| 291 | m_vC1 += (v - m_vC1) * m_exponentC1; |
| 418 | 292 | break; |
| 419 | 293 | |
| 420 | 294 | case DISC_OP_AMP_FILTER_IS_BAND_PASS_1: |
| 421 | | node->output[0] = (v - context->vC2); |
| 422 | | context->vC2 += (v - context->vC2) * context->exponentC2; |
| 423 | | context->vC1 += (node->output[0] - context->vC1) * context->exponentC1; |
| 424 | | node->output[0] = context->vC1 * context->gain + info->vRef; |
| 295 | this->output[0] = (v - m_vC2); |
| 296 | m_vC2 += (v - m_vC2) * m_exponentC2; |
| 297 | m_vC1 += (this->output[0] - m_vC1) * m_exponentC1; |
| 298 | this->output[0] = m_vC1 * m_gain + info->vRef; |
| 425 | 299 | break; |
| 426 | 300 | |
| 427 | 301 | case DISC_OP_AMP_FILTER_IS_BAND_PASS_0 | DISC_OP_AMP_IS_NORTON: |
| 428 | | context->vC1 += (v - context->vC1) * context->exponentC1; |
| 429 | | context->vC2 += (context->vC1 - context->vC2) * context->exponentC2; |
| 430 | | v = context->vC2; |
| 431 | | node->output[0] = v - context->vC3; |
| 432 | | context->vC3 += (v - context->vC3) * context->exponentC3; |
| 433 | | i = node->output[0] / context->rTotal; |
| 434 | | node->output[0] = (context->iFixed - i) * info->rF; |
| 302 | m_vC1 += (v - m_vC1) * m_exponentC1; |
| 303 | m_vC2 += (m_vC1 - m_vC2) * m_exponentC2; |
| 304 | v = m_vC2; |
| 305 | this->output[0] = v - m_vC3; |
| 306 | m_vC3 += (v - m_vC3) * m_exponentC3; |
| 307 | i = this->output[0] / m_rTotal; |
| 308 | this->output[0] = (m_iFixed - i) * info->rF; |
| 435 | 309 | break; |
| 436 | 310 | |
| 437 | 311 | case DISC_OP_AMP_FILTER_IS_HIGH_PASS_0 | DISC_OP_AMP_IS_NORTON: |
| 438 | | node->output[0] = v - context->vC1; |
| 439 | | context->vC1 += (v - context->vC1) * context->exponentC1; |
| 440 | | i = node->output[0] / context->rTotal; |
| 441 | | node->output[0] = (context->iFixed - i) * info->rF; |
| 312 | this->output[0] = v - m_vC1; |
| 313 | m_vC1 += (v - m_vC1) * m_exponentC1; |
| 314 | i = this->output[0] / m_rTotal; |
| 315 | this->output[0] = (m_iFixed - i) * info->rF; |
| 442 | 316 | break; |
| 443 | 317 | |
| 444 | 318 | case DISC_OP_AMP_FILTER_IS_BAND_PASS_1M: |
| 445 | 319 | case DISC_OP_AMP_FILTER_IS_BAND_PASS_1M | DISC_OP_AMP_IS_NORTON: |
| 446 | | node->output[0] = -context->a1 * context->y1 - context->a2 * context->y2 + |
| 447 | | context->b0 * v + context->b1 * context->x1 + context->b2 * context->x2 + |
| 448 | | context->vRef; |
| 449 | | context->x2 = context->x1; |
| 450 | | context->x1 = v; |
| 451 | | context->y2 = context->y1; |
| 320 | this->output[0] = -m_fc.a1 * m_fc.y1 - m_fc.a2 * m_fc.y2 + |
| 321 | m_fc.b0 * v + m_fc.b1 * m_fc.x1 + m_fc.b2 * m_fc.x2 + |
| 322 | m_vRef; |
| 323 | m_fc.x2 = m_fc.x1; |
| 324 | m_fc.x1 = v; |
| 325 | m_fc.y2 = m_fc.y1; |
| 452 | 326 | break; |
| 453 | 327 | } |
| 454 | 328 | |
| 455 | 329 | /* Clip the output to the voltage rails. |
| 456 | 330 | * This way we get the original distortion in all it's glory. |
| 457 | 331 | */ |
| 458 | | if (node->output[0] > context->vP) node->output[0] = context->vP; |
| 459 | | if (node->output[0] < context->vN) node->output[0] = context->vN; |
| 460 | | context->y1 = node->output[0] - context->vRef; |
| 332 | if (this->output[0] > m_vP) this->output[0] = m_vP; |
| 333 | if (this->output[0] < m_vN) this->output[0] = m_vN; |
| 334 | m_fc.y1 = this->output[0] - m_vRef; |
| 461 | 335 | } |
| 462 | 336 | else |
| 463 | | node->output[0] = 0; |
| 337 | this->output[0] = 0; |
| 464 | 338 | |
| 465 | 339 | } |
| 466 | 340 | |
| 467 | 341 | DISCRETE_RESET(dst_op_amp_filt) |
| 468 | 342 | { |
| 469 | | DISCRETE_DECLARE_CONTEXT(dst_op_amp_filt) |
| 470 | 343 | DISCRETE_DECLARE_INFO(discrete_op_amp_filt_info) |
| 471 | 344 | |
| 472 | 345 | /* Convert the passed filter type into an int for easy use. */ |
| 473 | | context->type = (int)DST_OP_AMP_FILT__TYPE & DISC_OP_AMP_FILTER_TYPE_MASK; |
| 474 | | context->is_norton = (int)DST_OP_AMP_FILT__TYPE & DISC_OP_AMP_IS_NORTON; |
| 346 | m_type = (int)DST_OP_AMP_FILT__TYPE & DISC_OP_AMP_FILTER_TYPE_MASK; |
| 347 | m_is_norton = (int)DST_OP_AMP_FILT__TYPE & DISC_OP_AMP_IS_NORTON; |
| 475 | 348 | |
| 476 | | if (context->is_norton) |
| 349 | if (m_is_norton) |
| 477 | 350 | { |
| 478 | | context->vRef = 0; |
| 479 | | context->rTotal = info->r1; |
| 480 | | if (context->type == (DISC_OP_AMP_FILTER_IS_BAND_PASS_0 | DISC_OP_AMP_IS_NORTON)) |
| 481 | | context->rTotal += info->r2 + info->r3; |
| 351 | m_vRef = 0; |
| 352 | m_rTotal = info->r1; |
| 353 | if (m_type == (DISC_OP_AMP_FILTER_IS_BAND_PASS_0 | DISC_OP_AMP_IS_NORTON)) |
| 354 | m_rTotal += info->r2 + info->r3; |
| 482 | 355 | |
| 483 | 356 | /* Setup the current to the + input. */ |
| 484 | | context->iFixed = (info->vP - OP_AMP_NORTON_VBE) / info->r4; |
| 357 | m_iFixed = (info->vP - OP_AMP_NORTON_VBE) / info->r4; |
| 485 | 358 | |
| 486 | 359 | /* Set the output max. */ |
| 487 | | context->vP = info->vP - OP_AMP_NORTON_VBE; |
| 488 | | context->vN = info->vN; |
| 360 | m_vP = info->vP - OP_AMP_NORTON_VBE; |
| 361 | m_vN = info->vN; |
| 489 | 362 | } |
| 490 | 363 | else |
| 491 | 364 | { |
| 492 | | context->vRef = info->vRef; |
| 365 | m_vRef = info->vRef; |
| 493 | 366 | /* Set the output max. */ |
| 494 | | context->vP = info->vP - OP_AMP_VP_RAIL_OFFSET; |
| 495 | | context->vN = info->vN; |
| 367 | m_vP = info->vP - OP_AMP_VP_RAIL_OFFSET; |
| 368 | m_vN = info->vN; |
| 496 | 369 | |
| 497 | 370 | /* Work out the input resistance. It is all input and bias resistors in parallel. */ |
| 498 | | context->rTotal = 1.0 / info->r1; /* There has to be an R1. Otherwise the table is wrong. */ |
| 499 | | if (info->r2 != 0) context->rTotal += 1.0 / info->r2; |
| 500 | | if (info->r3 != 0) context->rTotal += 1.0 / info->r3; |
| 501 | | context->rTotal = 1.0 / context->rTotal; |
| 371 | m_rTotal = 1.0 / info->r1; /* There has to be an R1. Otherwise the table is wrong. */ |
| 372 | if (info->r2 != 0) m_rTotal += 1.0 / info->r2; |
| 373 | if (info->r3 != 0) m_rTotal += 1.0 / info->r3; |
| 374 | m_rTotal = 1.0 / m_rTotal; |
| 502 | 375 | |
| 503 | | context->iFixed = 0; |
| 376 | m_iFixed = 0; |
| 504 | 377 | |
| 505 | | context->rRatio = info->rF / (context->rTotal + info->rF); |
| 506 | | context->gain = -info->rF / context->rTotal; |
| 378 | m_rRatio = info->rF / (m_rTotal + info->rF); |
| 379 | m_gain = -info->rF / m_rTotal; |
| 507 | 380 | } |
| 508 | 381 | |
| 509 | | switch (context->type) |
| 382 | switch (m_type) |
| 510 | 383 | { |
| 511 | 384 | case DISC_OP_AMP_FILTER_IS_LOW_PASS_1: |
| 512 | 385 | case DISC_OP_AMP_FILTER_IS_LOW_PASS_1_A: |
| 513 | | context->exponentC1 = RC_CHARGE_EXP(info->rF * info->c1); |
| 514 | | context->exponentC2 = 0; |
| 386 | m_exponentC1 = RC_CHARGE_EXP_CLASS(info->rF * info->c1); |
| 387 | m_exponentC2 = 0; |
| 515 | 388 | break; |
| 516 | 389 | case DISC_OP_AMP_FILTER_IS_HIGH_PASS_1: |
| 517 | | context->exponentC1 = RC_CHARGE_EXP(context->rTotal * info->c1); |
| 518 | | context->exponentC2 = 0; |
| 390 | m_exponentC1 = RC_CHARGE_EXP_CLASS(m_rTotal * info->c1); |
| 391 | m_exponentC2 = 0; |
| 519 | 392 | break; |
| 520 | 393 | case DISC_OP_AMP_FILTER_IS_BAND_PASS_1: |
| 521 | | context->exponentC1 = RC_CHARGE_EXP(info->rF * info->c1); |
| 522 | | context->exponentC2 = RC_CHARGE_EXP(context->rTotal * info->c2); |
| 394 | m_exponentC1 = RC_CHARGE_EXP_CLASS(info->rF * info->c1); |
| 395 | m_exponentC2 = RC_CHARGE_EXP_CLASS(m_rTotal * info->c2); |
| 523 | 396 | break; |
| 524 | 397 | case DISC_OP_AMP_FILTER_IS_BAND_PASS_1M | DISC_OP_AMP_IS_NORTON: |
| 525 | 398 | if (info->r2 == 0) |
| 526 | | context->rTotal = info->r1; |
| 399 | m_rTotal = info->r1; |
| 527 | 400 | else |
| 528 | | context->rTotal = RES_2_PARALLEL(info->r1, info->r2); |
| 401 | m_rTotal = RES_2_PARALLEL(info->r1, info->r2); |
| 529 | 402 | case DISC_OP_AMP_FILTER_IS_BAND_PASS_1M: |
| 530 | 403 | { |
| 531 | | double fc = 1.0 / (2 * M_PI * sqrt(context->rTotal * info->rF * info->c1 * info->c2)); |
| 532 | | double d = (info->c1 + info->c2) / sqrt(info->rF / context->rTotal * info->c1 * info->c2); |
| 533 | | double gain = -info->rF / context->rTotal * info->c2 / (info->c1 + info->c2); |
| 404 | double fc = 1.0 / (2 * M_PI * sqrt(m_rTotal * info->rF * info->c1 * info->c2)); |
| 405 | double d = (info->c1 + info->c2) / sqrt(info->rF / m_rTotal * info->c1 * info->c2); |
| 406 | double gain = -info->rF / m_rTotal * info->c2 / (info->c1 + info->c2); |
| 534 | 407 | |
| 535 | | calculate_filter2_coefficients(node->info, fc, d, DISC_FILTER_BANDPASS, |
| 536 | | &context->a1, &context->a2, |
| 537 | | &context->b0, &context->b1, &context->b2); |
| 538 | | context->b0 *= gain; |
| 539 | | context->b1 *= gain; |
| 540 | | context->b2 *= gain; |
| 408 | calculate_filter2_coefficients(this, fc, d, DISC_FILTER_BANDPASS, m_fc); |
| 409 | m_fc.b0 *= gain; |
| 410 | m_fc.b1 *= gain; |
| 411 | m_fc.b2 *= gain; |
| 541 | 412 | |
| 542 | | if (context->is_norton) |
| 543 | | context->vRef = (info->vP - OP_AMP_NORTON_VBE) / info->r3 * info->rF; |
| 413 | if (m_is_norton) |
| 414 | m_vRef = (info->vP - OP_AMP_NORTON_VBE) / info->r3 * info->rF; |
| 544 | 415 | else |
| 545 | | context->vRef = info->vRef; |
| 416 | m_vRef = info->vRef; |
| 546 | 417 | |
| 547 | 418 | break; |
| 548 | 419 | } |
| 549 | 420 | case DISC_OP_AMP_FILTER_IS_BAND_PASS_0 | DISC_OP_AMP_IS_NORTON: |
| 550 | | context->exponentC1 = RC_CHARGE_EXP(RES_2_PARALLEL(info->r1, info->r2 + info->r3 + info->r4) * info->c1); |
| 551 | | context->exponentC2 = RC_CHARGE_EXP(RES_2_PARALLEL(info->r1 + info->r2, info->r3 + info->r4) * info->c2); |
| 552 | | context->exponentC3 = RC_CHARGE_EXP((info->r1 + info->r2 + info->r3 + info->r4) * info->c3); |
| 421 | m_exponentC1 = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(info->r1, info->r2 + info->r3 + info->r4) * info->c1); |
| 422 | m_exponentC2 = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(info->r1 + info->r2, info->r3 + info->r4) * info->c2); |
| 423 | m_exponentC3 = RC_CHARGE_EXP_CLASS((info->r1 + info->r2 + info->r3 + info->r4) * info->c3); |
| 553 | 424 | break; |
| 554 | 425 | case DISC_OP_AMP_FILTER_IS_HIGH_PASS_0 | DISC_OP_AMP_IS_NORTON: |
| 555 | | context->exponentC1 = RC_CHARGE_EXP(info->r1 * info->c1); |
| 426 | m_exponentC1 = RC_CHARGE_EXP_CLASS(info->r1 * info->c1); |
| 556 | 427 | break; |
| 557 | 428 | } |
| 558 | 429 | |
| 559 | 430 | /* At startup there is no charge on the caps and output is 0V in relation to vRef. */ |
| 560 | | context->vC1 = 0; |
| 561 | | context->vC1b = 0; |
| 562 | | context->vC2 = 0; |
| 563 | | context->vC3 = 0; |
| 431 | m_vC1 = 0; |
| 432 | m_vC1b = 0; |
| 433 | m_vC2 = 0; |
| 434 | m_vC3 = 0; |
| 564 | 435 | |
| 565 | | node->output[0] = info->vRef; |
| 436 | this->output[0] = info->vRef; |
| 566 | 437 | } |
| 567 | 438 | |
| 568 | 439 | |
| r10048 | r10049 | |
| 580 | 451 | |
| 581 | 452 | DISCRETE_STEP( dst_rc_circuit_1 ) |
| 582 | 453 | { |
| 583 | | DISCRETE_DECLARE_CONTEXT(dst_rc_circuit_1) |
| 584 | | |
| 585 | 454 | if (DST_RC_CIRCUIT_1__IN0 == 0) |
| 586 | 455 | if (DST_RC_CIRCUIT_1__IN1 == 0) |
| 587 | 456 | /* cap is floating and does not change charge */ |
| 588 | 457 | /* output is pulled to ground */ |
| 589 | | node->output[0] = 0; |
| 458 | this->output[0] = 0; |
| 590 | 459 | else |
| 591 | 460 | { |
| 592 | 461 | /* cap is discharged */ |
| 593 | | context->v_cap -= context->v_cap * context->exp_2; |
| 594 | | node->output[0] = context->v_cap * context->v_drop; |
| 462 | m_v_cap -= m_v_cap * m_exp_2; |
| 463 | this->output[0] = m_v_cap * m_v_drop; |
| 595 | 464 | } |
| 596 | 465 | else |
| 597 | 466 | if (DST_RC_CIRCUIT_1__IN1 == 0) |
| 598 | 467 | { |
| 599 | 468 | /* cap is charged */ |
| 600 | | context->v_cap += (5.0 - context->v_cap) * context->exp_1; |
| 469 | m_v_cap += (5.0 - m_v_cap) * m_exp_1; |
| 601 | 470 | /* output is pulled to ground */ |
| 602 | | node->output[0] = 0; |
| 471 | this->output[0] = 0; |
| 603 | 472 | } |
| 604 | 473 | else |
| 605 | 474 | { |
| 606 | 475 | /* cap is charged slightly less */ |
| 607 | | context->v_cap += (context->v_charge_1_2 - context->v_cap) * context->exp_1_2; |
| 608 | | node->output[0] = context->v_cap * context->v_drop; |
| 476 | m_v_cap += (m_v_charge_1_2 - m_v_cap) * m_exp_1_2; |
| 477 | this->output[0] = m_v_cap * m_v_drop; |
| 609 | 478 | } |
| 610 | 479 | } |
| 611 | 480 | |
| 612 | 481 | DISCRETE_RESET( dst_rc_circuit_1 ) |
| 613 | 482 | { |
| 614 | | DISCRETE_DECLARE_CONTEXT(dst_rc_circuit_1) |
| 615 | | |
| 616 | 483 | /* the charging voltage across the cap based on in2*/ |
| 617 | | context->v_drop = RES_VOLTAGE_DIVIDER(CD4066_R_ON, CD4066_R_ON + DST_RC_CIRCUIT_1__R); |
| 618 | | context->v_charge_1_2 = 5.0 * context->v_drop; |
| 619 | | context->v_cap = 0; |
| 484 | m_v_drop = RES_VOLTAGE_DIVIDER(CD4066_R_ON, CD4066_R_ON + DST_RC_CIRCUIT_1__R); |
| 485 | m_v_charge_1_2 = 5.0 * m_v_drop; |
| 486 | m_v_cap = 0; |
| 620 | 487 | |
| 621 | 488 | /* precalculate charging exponents */ |
| 622 | 489 | /* discharge cap - in1 = 0, in2 = 1*/ |
| 623 | | context->exp_2 = RC_CHARGE_EXP((CD4066_R_ON + DST_RC_CIRCUIT_1__R) * DST_RC_CIRCUIT_1__C); |
| 490 | m_exp_2 = RC_CHARGE_EXP_CLASS((CD4066_R_ON + DST_RC_CIRCUIT_1__R) * DST_RC_CIRCUIT_1__C); |
| 624 | 491 | /* charge cap - in1 = 1, in2 = 0 */ |
| 625 | | context->exp_1 = RC_CHARGE_EXP(CD4066_R_ON * DST_RC_CIRCUIT_1__C); |
| 492 | m_exp_1 = RC_CHARGE_EXP_CLASS(CD4066_R_ON * DST_RC_CIRCUIT_1__C); |
| 626 | 493 | /* charge cap - in1 = 1, in2 = 1 */ |
| 627 | | context->exp_1_2 = RC_CHARGE_EXP(RES_2_PARALLEL(CD4066_R_ON, CD4066_R_ON + DST_RC_CIRCUIT_1__R) * DST_RC_CIRCUIT_1__C); |
| 494 | m_exp_1_2 = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(CD4066_R_ON, CD4066_R_ON + DST_RC_CIRCUIT_1__R) * DST_RC_CIRCUIT_1__C); |
| 628 | 495 | |
| 629 | 496 | /* starts at 0 until cap starts charging */ |
| 630 | | node->output[0] = 0; |
| 497 | this->output[0] = 0; |
| 631 | 498 | } |
| 632 | 499 | |
| 633 | 500 | /************************************************************************ |
| r10048 | r10049 | |
| 648 | 515 | |
| 649 | 516 | DISCRETE_STEP(dst_rcdisc) |
| 650 | 517 | { |
| 651 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc) |
| 652 | | |
| 653 | | switch (context->state) |
| 518 | switch (m_state) |
| 654 | 519 | { |
| 655 | 520 | case 0: /* waiting for trigger */ |
| 656 | 521 | if(DST_RCDISC__ENABLE) |
| 657 | 522 | { |
| 658 | | context->state = 1; |
| 659 | | context->t = 0; |
| 523 | m_state = 1; |
| 524 | m_t = 0; |
| 660 | 525 | } |
| 661 | | node->output[0] = 0; |
| 526 | this->output[0] = 0; |
| 662 | 527 | break; |
| 663 | 528 | |
| 664 | 529 | case 1: |
| 665 | 530 | if (DST_RCDISC__ENABLE) |
| 666 | 531 | { |
| 667 | | node->output[0] = DST_RCDISC__IN * exp(context->t / context->exponent0); |
| 668 | | context->t += node->info->sample_time; |
| 532 | this->output[0] = DST_RCDISC__IN * exp(m_t / m_exponent0); |
| 533 | m_t += this->sample_time(); |
| 669 | 534 | } else |
| 670 | 535 | { |
| 671 | | context->state = 0; |
| 536 | m_state = 0; |
| 672 | 537 | } |
| 673 | 538 | } |
| 674 | 539 | } |
| 675 | 540 | |
| 676 | 541 | DISCRETE_RESET(dst_rcdisc) |
| 677 | 542 | { |
| 678 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc) |
| 543 | this->output[0] = 0; |
| 679 | 544 | |
| 680 | | node->output[0] = 0; |
| 681 | | |
| 682 | | context->state = 0; |
| 683 | | context->t = 0; |
| 684 | | context->exponent0=-1.0 * DST_RCDISC__R * DST_RCDISC__C; |
| 545 | m_state = 0; |
| 546 | m_t = 0; |
| 547 | m_exponent0=-1.0 * DST_RCDISC__R * DST_RCDISC__C; |
| 685 | 548 | } |
| 686 | 549 | |
| 687 | 550 | |
| r10048 | r10049 | |
| 707 | 570 | |
| 708 | 571 | DISCRETE_STEP(dst_rcdisc2) |
| 709 | 572 | { |
| 710 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc) |
| 711 | | |
| 712 | 573 | double diff; |
| 713 | 574 | |
| 714 | 575 | /* Works differently to other as we are always on, no enable */ |
| 715 | 576 | /* exponential based in difference between input/output */ |
| 716 | 577 | |
| 717 | | diff = ((DST_RCDISC2__ENABLE == 0) ? DST_RCDISC2__IN0 : DST_RCDISC2__IN1) - node->output[0]; |
| 718 | | diff = diff - (diff * ((DST_RCDISC2__ENABLE == 0) ? context->exponent0 : context->exponent1)); |
| 719 | | node->output[0] += diff; |
| 578 | diff = ((DST_RCDISC2__ENABLE == 0) ? DST_RCDISC2__IN0 : DST_RCDISC2__IN1) - this->output[0]; |
| 579 | diff = diff - (diff * ((DST_RCDISC2__ENABLE == 0) ? m_exponent0 : m_exponent1)); |
| 580 | this->output[0] += diff; |
| 720 | 581 | } |
| 721 | 582 | |
| 722 | 583 | DISCRETE_RESET(dst_rcdisc2) |
| 723 | 584 | { |
| 724 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc) |
| 585 | this->output[0] = 0; |
| 725 | 586 | |
| 726 | | node->output[0] = 0; |
| 727 | | |
| 728 | | context->state = 0; |
| 729 | | context->t = 0; |
| 730 | | context->exponent0 = RC_DISCHARGE_EXP(DST_RCDISC2__R0 * DST_RCDISC2__C); |
| 731 | | context->exponent1 = RC_DISCHARGE_EXP(DST_RCDISC2__R1 * DST_RCDISC2__C); |
| 587 | m_state = 0; |
| 588 | m_t = 0; |
| 589 | m_exponent0 = RC_DISCHARGE_EXP_CLASS(DST_RCDISC2__R0 * DST_RCDISC2__C); |
| 590 | m_exponent1 = RC_DISCHARGE_EXP_CLASS(DST_RCDISC2__R1 * DST_RCDISC2__C); |
| 732 | 591 | } |
| 733 | 592 | |
| 734 | 593 | /************************************************************************ |
| r10048 | r10049 | |
| 753 | 612 | |
| 754 | 613 | DISCRETE_STEP(dst_rcdisc3) |
| 755 | 614 | { |
| 756 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc) |
| 757 | | |
| 758 | 615 | double diff; |
| 759 | 616 | |
| 760 | 617 | /* Exponential based in difference between input/output */ |
| 761 | 618 | |
| 762 | 619 | if(DST_RCDISC3__ENABLE) |
| 763 | 620 | { |
| 764 | | diff = DST_RCDISC3__IN - node->output[0]; |
| 765 | | if (context->v_diode > 0) |
| 621 | diff = DST_RCDISC3__IN - this->output[0]; |
| 622 | if (m_v_diode > 0) |
| 766 | 623 | { |
| 767 | 624 | if (diff > 0) |
| 768 | 625 | { |
| 769 | | diff = diff * context->exponent0; |
| 626 | diff = diff * m_exponent0; |
| 770 | 627 | } |
| 771 | | else if (diff < -context->v_diode) |
| 628 | else if (diff < -m_v_diode) |
| 772 | 629 | { |
| 773 | | diff = diff * context->exponent1; |
| 630 | diff = diff * m_exponent1; |
| 774 | 631 | } |
| 775 | 632 | else |
| 776 | 633 | { |
| 777 | | diff = diff * context->exponent0; |
| 634 | diff = diff * m_exponent0; |
| 778 | 635 | } |
| 779 | 636 | } |
| 780 | 637 | else |
| 781 | 638 | { |
| 782 | 639 | if (diff < 0) |
| 783 | 640 | { |
| 784 | | diff = diff * context->exponent0; |
| 641 | diff = diff * m_exponent0; |
| 785 | 642 | } |
| 786 | | else if (diff > -context->v_diode) |
| 643 | else if (diff > -m_v_diode) |
| 787 | 644 | { |
| 788 | | diff = diff * context->exponent1; |
| 645 | diff = diff * m_exponent1; |
| 789 | 646 | } |
| 790 | 647 | else |
| 791 | 648 | { |
| 792 | | diff = diff * context->exponent0; |
| 649 | diff = diff * m_exponent0; |
| 793 | 650 | } |
| 794 | 651 | } |
| 795 | | node->output[0] += diff; |
| 652 | this->output[0] += diff; |
| 796 | 653 | } |
| 797 | 654 | else |
| 798 | 655 | { |
| 799 | | node->output[0] = 0; |
| 656 | this->output[0] = 0; |
| 800 | 657 | } |
| 801 | 658 | } |
| 802 | 659 | |
| 803 | 660 | DISCRETE_RESET(dst_rcdisc3) |
| 804 | 661 | { |
| 805 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc) |
| 662 | this->output[0] = 0; |
| 806 | 663 | |
| 807 | | node->output[0] = 0; |
| 808 | | |
| 809 | | context->state = 0; |
| 810 | | context->t = 0; |
| 811 | | context->v_diode = DST_RCDISC3__DJV; |
| 812 | | context->exponent0 = RC_CHARGE_EXP(DST_RCDISC3__R1 * DST_RCDISC3__C); |
| 813 | | context->exponent1 = RC_CHARGE_EXP(RES_2_PARALLEL(DST_RCDISC3__R1, DST_RCDISC3__R2) * DST_RCDISC3__C); |
| 664 | m_state = 0; |
| 665 | m_t = 0; |
| 666 | m_v_diode = DST_RCDISC3__DJV; |
| 667 | m_exponent0 = RC_CHARGE_EXP_CLASS(DST_RCDISC3__R1 * DST_RCDISC3__C); |
| 668 | m_exponent1 = RC_CHARGE_EXP_CLASS(RES_2_PARALLEL(DST_RCDISC3__R1, DST_RCDISC3__R2) * DST_RCDISC3__C); |
| 814 | 669 | } |
| 815 | 670 | |
| 816 | 671 | |
| r10048 | r10049 | |
| 838 | 693 | |
| 839 | 694 | DISCRETE_STEP(dst_rcdisc4) |
| 840 | 695 | { |
| 841 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc4) |
| 842 | | |
| 843 | 696 | int inp1 = (DST_RCDISC4__IN == 0) ? 0 : 1; |
| 844 | 697 | |
| 845 | 698 | if (DST_RCDISC4__ENABLE == 0) |
| 846 | 699 | { |
| 847 | | node->output[0] = 0; |
| 700 | this->output[0] = 0; |
| 848 | 701 | return; |
| 849 | 702 | } |
| 850 | 703 | |
| 851 | | switch (context->type) |
| 704 | switch (m_type) |
| 852 | 705 | { |
| 853 | 706 | case 1: |
| 854 | 707 | case 3: |
| 855 | | context->vC1 += ((context->v[inp1] - context->vC1) * context->exp[inp1]); |
| 856 | | node->output[0] = context->vC1; |
| 708 | m_vC1 += ((m_v[inp1] - m_vC1) * m_exp[inp1]); |
| 709 | this->output[0] = m_vC1; |
| 857 | 710 | break; |
| 858 | 711 | } |
| 859 | 712 | |
| 860 | 713 | /* clip output */ |
| 861 | | if (node->output[0] > context->max_out) node->output[0] = context->max_out; |
| 862 | | if (node->output[0] < 0) node->output[0] = 0; |
| 714 | if (this->output[0] > m_max_out) this->output[0] = m_max_out; |
| 715 | if (this->output[0] < 0) this->output[0] = 0; |
| 863 | 716 | } |
| 864 | 717 | |
| 865 | 718 | DISCRETE_RESET( dst_rcdisc4) |
| 866 | 719 | { |
| 867 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc4) |
| 868 | | |
| 869 | 720 | double v, i, r, rT; |
| 870 | 721 | |
| 871 | | context->type = 0; |
| 722 | m_type = 0; |
| 872 | 723 | /* some error checking. */ |
| 873 | | if (DST_RCDISC4__R1 <= 0 || DST_RCDISC4__R2 <= 0 || DST_RCDISC4__C1 <= 0 || (DST_RCDISC4__R3 <= 0 && context->type == 1)) |
| 724 | if (DST_RCDISC4__R1 <= 0 || DST_RCDISC4__R2 <= 0 || DST_RCDISC4__C1 <= 0 || (DST_RCDISC4__R3 <= 0 && m_type == 1)) |
| 874 | 725 | { |
| 875 | | discrete_log(node->info, "Invalid component values in NODE_%d.\n", node->index()); |
| 726 | this->device->discrete_log("Invalid component values in NODE_%d.\n", this->index()); |
| 876 | 727 | return; |
| 877 | 728 | } |
| 878 | 729 | if (DST_RCDISC4__VP < 3) |
| 879 | 730 | { |
| 880 | | discrete_log(node->info, "vP must be >= 3V in NODE_%d.\n", node->index()); |
| 731 | this->device->discrete_log("vP must be >= 3V in NODE_%d.\n", this->index()); |
| 881 | 732 | return; |
| 882 | 733 | } |
| 883 | 734 | if (DST_RCDISC4__TYPE < 1 || DST_RCDISC4__TYPE > 3) |
| 884 | 735 | { |
| 885 | | discrete_log(node->info, "Invalid circuit type in NODE_%d.\n", node->index()); |
| 736 | this->device->discrete_log("Invalid circuit type in NODE_%d.\n", this->index()); |
| 886 | 737 | return; |
| 887 | 738 | } |
| 888 | 739 | |
| 889 | | context->vC1 = 0; |
| 740 | m_vC1 = 0; |
| 890 | 741 | /* store type as integer */ |
| 891 | | context->type = (int)DST_RCDISC4__TYPE; |
| 742 | m_type = (int)DST_RCDISC4__TYPE; |
| 892 | 743 | /* setup the maximum op-amp output. */ |
| 893 | | context->max_out = DST_RCDISC4__VP - OP_AMP_VP_RAIL_OFFSET; |
| 744 | m_max_out = DST_RCDISC4__VP - OP_AMP_VP_RAIL_OFFSET; |
| 894 | 745 | |
| 895 | | switch (context->type) |
| 746 | switch (m_type) |
| 896 | 747 | { |
| 897 | 748 | case 1: |
| 898 | 749 | /* We will simulate this as a voltage divider with 2 states depending |
| r10048 | r10049 | |
| 904 | 755 | r = RES_2_PARALLEL(DST_RCDISC4__R1, DST_RCDISC4__R3); |
| 905 | 756 | rT = DST_RCDISC4__R2 + r; |
| 906 | 757 | i = v / rT; |
| 907 | | context->v[1] = i * r + .5; |
| 758 | m_v[1] = i * r + .5; |
| 908 | 759 | rT = RES_2_PARALLEL(DST_RCDISC4__R2, r); |
| 909 | | context->exp[1] = RC_CHARGE_EXP(rT * DST_RCDISC4__C1); |
| 760 | m_exp[1] = RC_CHARGE_EXP_CLASS(rT * DST_RCDISC4__C1); |
| 910 | 761 | |
| 911 | 762 | /* When the input is 0, R1 is out of circuit. */ |
| 912 | 763 | rT = DST_RCDISC4__R2 + DST_RCDISC4__R3; |
| 913 | 764 | i = v / rT; |
| 914 | | context->v[0] = i * DST_RCDISC4__R3 + .5; |
| 765 | m_v[0] = i * DST_RCDISC4__R3 + .5; |
| 915 | 766 | rT = RES_2_PARALLEL(DST_RCDISC4__R2, DST_RCDISC4__R3); |
| 916 | | context->exp[0] = RC_CHARGE_EXP(rT * DST_RCDISC4__C1); |
| 767 | m_exp[0] = RC_CHARGE_EXP_CLASS(rT * DST_RCDISC4__C1); |
| 917 | 768 | break; |
| 918 | 769 | |
| 919 | 770 | case 3: |
| r10048 | r10049 | |
| 922 | 773 | * resistance, so we will just use .5k in series with R1. |
| 923 | 774 | */ |
| 924 | 775 | r = 500.0 + DST_RCDISC4__R1; |
| 925 | | context->v[1] = RES_VOLTAGE_DIVIDER(r, DST_RCDISC4__R2) * (5.0 - 0.5); |
| 776 | m_v[1] = RES_VOLTAGE_DIVIDER(r, DST_RCDISC4__R2) * (5.0 - 0.5); |
| 926 | 777 | rT = RES_2_PARALLEL(r, DST_RCDISC4__R2); |
| 927 | | context->exp[1] = RC_CHARGE_EXP(rT * DST_RCDISC4__C1); |
| 778 | m_exp[1] = RC_CHARGE_EXP_CLASS(rT * DST_RCDISC4__C1); |
| 928 | 779 | |
| 929 | 780 | /* When the input is 0, R1 is out of circuit. */ |
| 930 | | context->v[0] = 0; |
| 931 | | context->exp[0] = RC_CHARGE_EXP(DST_RCDISC4__R2 * DST_RCDISC4__C1); |
| 781 | m_v[0] = 0; |
| 782 | m_exp[0] = RC_CHARGE_EXP_CLASS(DST_RCDISC4__R2 * DST_RCDISC4__C1); |
| 932 | 783 | break; |
| 933 | 784 | } |
| 934 | 785 | } |
| r10048 | r10049 | |
| 950 | 801 | |
| 951 | 802 | DISCRETE_STEP( dst_rcdisc5) |
| 952 | 803 | { |
| 953 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc) |
| 954 | | |
| 955 | 804 | double diff,u; |
| 956 | 805 | |
| 957 | 806 | /* Exponential based in difference between input/output */ |
| r10048 | r10049 | |
| 960 | 809 | if( u < 0) |
| 961 | 810 | u = 0; |
| 962 | 811 | |
| 963 | | diff = u - context->v_cap; |
| 812 | diff = u - m_v_cap; |
| 964 | 813 | |
| 965 | 814 | if(DST_RCDISC5__ENABLE) |
| 966 | 815 | { |
| 967 | 816 | if(diff < 0) |
| 968 | | diff = diff * context->exponent0; |
| 817 | diff = diff * m_exponent0; |
| 969 | 818 | |
| 970 | | context->v_cap += diff; |
| 971 | | node->output[0] = context->v_cap; |
| 819 | m_v_cap += diff; |
| 820 | this->output[0] = m_v_cap; |
| 972 | 821 | } |
| 973 | 822 | else |
| 974 | 823 | { |
| 975 | 824 | if(diff > 0) |
| 976 | | context->v_cap = u; |
| 825 | m_v_cap = u; |
| 977 | 826 | |
| 978 | | node->output[0] = 0; |
| 827 | this->output[0] = 0; |
| 979 | 828 | } |
| 980 | 829 | } |
| 981 | 830 | |
| 982 | 831 | DISCRETE_RESET( dst_rcdisc5) |
| 983 | 832 | { |
| 984 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc) |
| 833 | this->output[0] = 0; |
| 985 | 834 | |
| 986 | | node->output[0] = 0; |
| 987 | | |
| 988 | | context->state = 0; |
| 989 | | context->t = 0; |
| 990 | | context->v_cap = 0; |
| 991 | | context->exponent0 = RC_CHARGE_EXP(DST_RCDISC5__R * DST_RCDISC5__C); |
| 835 | m_state = 0; |
| 836 | m_t = 0; |
| 837 | m_v_cap = 0; |
| 838 | m_exponent0 = RC_CHARGE_EXP_CLASS(DST_RCDISC5__R * DST_RCDISC5__C); |
| 992 | 839 | } |
| 993 | 840 | |
| 994 | 841 | |
| r10048 | r10049 | |
| 1018 | 865 | |
| 1019 | 866 | DISCRETE_STEP(dst_rcdisc_mod) |
| 1020 | 867 | { |
| 1021 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc_mod) |
| 1022 | | |
| 1023 | 868 | double diff, v_cap, u, vD; |
| 1024 | 869 | int mod_state, mod1_state, mod2_state; |
| 1025 | 870 | |
| 1026 | 871 | /* Exponential based in difference between input/output */ |
| 1027 | | v_cap = context->v_cap; |
| 872 | v_cap = m_v_cap; |
| 1028 | 873 | |
| 1029 | 874 | mod1_state = DST_RCDISC_MOD__IN1 > 0.5; |
| 1030 | 875 | mod2_state = DST_RCDISC_MOD__IN2 > 0.6; |
| r10048 | r10049 | |
| 1033 | 878 | u = mod1_state ? 0 : DST_RCDISC_MOD__VP; |
| 1034 | 879 | /* Clamp */ |
| 1035 | 880 | diff = u - v_cap; |
| 1036 | | vD = diff * context->vd_gain[mod_state]; |
| 881 | vD = diff * m_vd_gain[mod_state]; |
| 1037 | 882 | if (vD < -0.6) |
| 1038 | 883 | { |
| 1039 | 884 | diff = u + 0.6 - v_cap; |
| 1040 | | diff -= diff * context->exp_low[mod1_state]; |
| 885 | diff -= diff * m_exp_low[mod1_state]; |
| 1041 | 886 | v_cap += diff; |
| 1042 | | node->output[0] = mod2_state ? 0 : -0.6; |
| 887 | this->output[0] = mod2_state ? 0 : -0.6; |
| 1043 | 888 | } |
| 1044 | 889 | else |
| 1045 | 890 | { |
| 1046 | | diff -= diff * context->exp_high[mod_state]; |
| 891 | diff -= diff * m_exp_high[mod_state]; |
| 1047 | 892 | v_cap += diff; |
| 1048 | 893 | /* neglecting current through R3 drawn by next8 node */ |
| 1049 | | node->output[0] = mod2_state ? 0: (u - v_cap) * context->gain[mod1_state]; |
| 894 | this->output[0] = mod2_state ? 0: (u - v_cap) * m_gain[mod1_state]; |
| 1050 | 895 | } |
| 1051 | | context->v_cap = v_cap; |
| 896 | m_v_cap = v_cap; |
| 1052 | 897 | } |
| 1053 | 898 | |
| 1054 | 899 | DISCRETE_RESET(dst_rcdisc_mod) |
| 1055 | 900 | { |
| 1056 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc_mod) |
| 1057 | | |
| 1058 | 901 | double rc[2], rc2[2]; |
| 1059 | 902 | |
| 1060 | 903 | /* pre-calculate fixed values */ |
| 1061 | 904 | /* DST_RCDISC_MOD__IN1 <= 0.5 */ |
| 1062 | 905 | rc[0] = DST_RCDISC_MOD__R1 + DST_RCDISC_MOD__R2; |
| 1063 | 906 | if (rc[0] < 1) rc[0] = 1; |
| 1064 | | context->exp_low[0] = RC_DISCHARGE_EXP(DST_RCDISC_MOD__C * rc[0]); |
| 1065 | | context->gain[0] = RES_VOLTAGE_DIVIDER(rc[0], DST_RCDISC_MOD__R4); |
| 907 | m_exp_low[0] = RC_DISCHARGE_EXP_CLASS(DST_RCDISC_MOD__C * rc[0]); |
| 908 | m_gain[0] = RES_VOLTAGE_DIVIDER(rc[0], DST_RCDISC_MOD__R4); |
| 1066 | 909 | /* DST_RCDISC_MOD__IN1 > 0.5 */ |
| 1067 | 910 | rc[1] = DST_RCDISC_MOD__R2; |
| 1068 | 911 | if (rc[1] < 1) rc[1] = 1; |
| 1069 | | context->exp_low[1] = RC_DISCHARGE_EXP(DST_RCDISC_MOD__C * rc[1]); |
| 1070 | | context->gain[1] = RES_VOLTAGE_DIVIDER(rc[1], DST_RCDISC_MOD__R4); |
| 912 | m_exp_low[1] = RC_DISCHARGE_EXP_CLASS(DST_RCDISC_MOD__C * rc[1]); |
| 913 | m_gain[1] = RES_VOLTAGE_DIVIDER(rc[1], DST_RCDISC_MOD__R4); |
| 1071 | 914 | /* DST_RCDISC_MOD__IN2 <= 0.6 */ |
| 1072 | 915 | rc2[0] = DST_RCDISC_MOD__R4; |
| 1073 | 916 | /* DST_RCDISC_MOD__IN2 > 0.6 */ |
| 1074 | 917 | rc2[1] = RES_2_PARALLEL(DST_RCDISC_MOD__R3, DST_RCDISC_MOD__R4); |
| 1075 | 918 | /* DST_RCDISC_MOD__IN1 <= 0.5 && DST_RCDISC_MOD__IN2 <= 0.6 */ |
| 1076 | | context->exp_high[0] = RC_DISCHARGE_EXP(DST_RCDISC_MOD__C * (rc[0] + rc2[0])); |
| 1077 | | context->vd_gain[0] = RES_VOLTAGE_DIVIDER(rc[0], rc2[0]); |
| 919 | m_exp_high[0] = RC_DISCHARGE_EXP_CLASS(DST_RCDISC_MOD__C * (rc[0] + rc2[0])); |
| 920 | m_vd_gain[0] = RES_VOLTAGE_DIVIDER(rc[0], rc2[0]); |
| 1078 | 921 | /* DST_RCDISC_MOD__IN1 > 0.5 && DST_RCDISC_MOD__IN2 <= 0.6 */ |
| 1079 | | context->exp_high[1] = RC_DISCHARGE_EXP(DST_RCDISC_MOD__C * (rc[1] + rc2[0])); |
| 1080 | | context->vd_gain[1] = RES_VOLTAGE_DIVIDER(rc[1], rc2[0]); |
| 922 | m_exp_high[1] = RC_DISCHARGE_EXP_CLASS(DST_RCDISC_MOD__C * (rc[1] + rc2[0])); |
| 923 | m_vd_gain[1] = RES_VOLTAGE_DIVIDER(rc[1], rc2[0]); |
| 1081 | 924 | /* DST_RCDISC_MOD__IN1 <= 0.5 && DST_RCDISC_MOD__IN2 > 0.6 */ |
| 1082 | | context->exp_high[2] = RC_DISCHARGE_EXP(DST_RCDISC_MOD__C * (rc[0] + rc2[1])); |
| 1083 | | context->vd_gain[2] = RES_VOLTAGE_DIVIDER(rc[0], rc2[1]); |
| 925 | m_exp_high[2] = RC_DISCHARGE_EXP_CLASS(DST_RCDISC_MOD__C * (rc[0] + rc2[1])); |
| 926 | m_vd_gain[2] = RES_VOLTAGE_DIVIDER(rc[0], rc2[1]); |
| 1084 | 927 | /* DST_RCDISC_MOD__IN1 > 0.5 && DST_RCDISC_MOD__IN2 > 0.6 */ |
| 1085 | | context->exp_high[3] = RC_DISCHARGE_EXP(DST_RCDISC_MOD__C * (rc[1] + rc2[1])); |
| 1086 | | context->vd_gain[3] = RES_VOLTAGE_DIVIDER(rc[1], rc2[1]); |
| 928 | m_exp_high[3] = RC_DISCHARGE_EXP_CLASS(DST_RCDISC_MOD__C * (rc[1] + rc2[1])); |
| 929 | m_vd_gain[3] = RES_VOLTAGE_DIVIDER(rc[1], rc2[1]); |
| 1087 | 930 | |
| 1088 | | context->v_cap = 0; |
| 1089 | | node->output[0] = 0; |
| 931 | m_v_cap = 0; |
| 932 | this->output[0] = 0; |
| 1090 | 933 | } |
| 1091 | 934 | |
| 1092 | 935 | /************************************************************************ |
| r10048 | r10049 | |
| 1107 | 950 | |
| 1108 | 951 | DISCRETE_STEP(dst_rcfilter) |
| 1109 | 952 | { |
| 1110 | | DISCRETE_DECLARE_CONTEXT(dst_rcfilter) |
| 1111 | | |
| 1112 | | if (UNEXPECTED(context->has_rc_nodes)) |
| 953 | if (EXPECTED(m_is_fast)) |
| 954 | this->output[0] += ((DST_RCFILTER__VIN - this->output[0]) * m_exponent); |
| 955 | else |
| 1113 | 956 | { |
| 1114 | | double rc = DST_RCFILTER__R * DST_RCFILTER__C; |
| 1115 | | if (rc != context->rc) |
| 957 | if (UNEXPECTED(m_has_rc_nodes)) |
| 1116 | 958 | { |
| 1117 | | context->rc = rc; |
| 1118 | | context->exponent = RC_CHARGE_EXP(rc); |
| 959 | double rc = DST_RCFILTER__R * DST_RCFILTER__C; |
| 960 | if (rc != m_rc) |
| 961 | { |
| 962 | m_rc = rc; |
| 963 | m_exponent = RC_CHARGE_EXP_CLASS(rc); |
| 964 | } |
| 1119 | 965 | } |
| 1120 | | } |
| 1121 | 966 | |
| 1122 | | /************************************************************************/ |
| 1123 | | /* Next Value = PREV + (INPUT_VALUE - PREV)*(1-(EXP(-TIMEDELTA/RC))) */ |
| 1124 | | /************************************************************************/ |
| 967 | /************************************************************************/ |
| 968 | /* Next Value = PREV + (INPUT_VALUE - PREV)*(1-(EXP(-TIMEDELTA/RC))) */ |
| 969 | /************************************************************************/ |
| 1125 | 970 | |
| 1126 | | context->vCap += ((DST_RCFILTER__VIN - node->output[0]) * context->exponent); |
| 1127 | | node->output[0] = context->vCap + DST_RCFILTER__VREF; |
| 971 | m_vCap += ((DST_RCFILTER__VIN - this->output[0]) * m_exponent); |
| 972 | this->output[0] = m_vCap + DST_RCFILTER__VREF; |
| 973 | } |
| 1128 | 974 | } |
| 1129 | 975 | |
| 1130 | | DISCRETE_STEP(dst_rcfilter_fast) |
| 1131 | | { |
| 1132 | | DISCRETE_DECLARE_CONTEXT(dst_rcfilter) |
| 1133 | 976 | |
| 1134 | | node->output[0] += ((DST_RCFILTER__VIN - node->output[0]) * context->exponent); |
| 1135 | | } |
| 1136 | | |
| 1137 | 977 | DISCRETE_RESET(dst_rcfilter) |
| 1138 | 978 | { |
| 1139 | | DISCRETE_DECLARE_CONTEXT(dst_rcfilter) |
| 1140 | | |
| 1141 | | context->has_rc_nodes = node->input_is_node() & 0x6; |
| 1142 | | context->rc = DST_RCFILTER__R * DST_RCFILTER__C; |
| 1143 | | context->exponent = RC_CHARGE_EXP(context->rc); |
| 1144 | | context->vCap = 0; |
| 1145 | | node->output[0] = 0; |
| 1146 | | if (!context->has_rc_nodes && DST_RCFILTER__VREF == 0) |
| 1147 | | node->step = DISCRETE_STEP_NAME(dst_rcfilter_fast); |
| 979 | m_has_rc_nodes = this->input_is_node() & 0x6; |
| 980 | m_rc = DST_RCFILTER__R * DST_RCFILTER__C; |
| 981 | m_exponent = RC_CHARGE_EXP_CLASS(m_rc); |
| 982 | m_vCap = 0; |
| 983 | this->output[0] = 0; |
| 984 | /* FIXME --> we really need another class here */ |
| 985 | if (!m_has_rc_nodes && DST_RCFILTER__VREF == 0) |
| 986 | m_is_fast = 1; |
| 987 | else |
| 988 | m_is_fast = 0; |
| 1148 | 989 | } |
| 1149 | 990 | |
| 1150 | 991 | /************************************************************************ |
| r10048 | r10049 | |
| 1177 | 1018 | // FIXME: This needs optimization ! |
| 1178 | 1019 | DISCRETE_STEP(dst_rcfilter_sw) |
| 1179 | 1020 | { |
| 1180 | | DISCRETE_DECLARE_CONTEXT(dst_rcfilter_sw) |
| 1181 | | |
| 1182 | 1021 | int i; |
| 1183 | 1022 | int bits = (int)DST_RCFILTER_SW__SWITCH; |
| 1184 | 1023 | double us = 0; |
| r10048 | r10049 | |
| 1189 | 1028 | switch (bits) |
| 1190 | 1029 | { |
| 1191 | 1030 | case 0: |
| 1192 | | node->output[0] = vIn; |
| 1031 | this->output[0] = vIn; |
| 1193 | 1032 | break; |
| 1194 | 1033 | case 1: |
| 1195 | | context->vCap[0] += (vIn - context->vCap[0]) * context->exp0; |
| 1196 | | node->output[0] = context->vCap[0] + (vIn - context->vCap[0]) * context->factor; |
| 1034 | m_vCap[0] += (vIn - m_vCap[0]) * m_exp0; |
| 1035 | this->output[0] = m_vCap[0] + (vIn - m_vCap[0]) * m_factor; |
| 1197 | 1036 | break; |
| 1198 | 1037 | case 2: |
| 1199 | | context->vCap[1] += (vIn - context->vCap[1]) * context->exp1; |
| 1200 | | node->output[0] = context->vCap[1] + (vIn - context->vCap[1]) * context->factor; |
| 1038 | m_vCap[1] += (vIn - m_vCap[1]) * m_exp1; |
| 1039 | this->output[0] = m_vCap[1] + (vIn - m_vCap[1]) * m_factor; |
| 1201 | 1040 | break; |
| 1202 | 1041 | default: |
| 1203 | 1042 | for (i = 0; i < 4; i++) |
| 1204 | 1043 | { |
| 1205 | 1044 | if (( bits & (1 << i)) != 0) |
| 1206 | | us += context->vCap[i]; |
| 1045 | us += m_vCap[i]; |
| 1207 | 1046 | } |
| 1208 | | node->output[0] = context->f1[bits] * vIn + context->f2[bits] * us; |
| 1047 | this->output[0] = m_f1[bits] * vIn + m_f2[bits] * us; |
| 1209 | 1048 | for (i = 0; i < 4; i++) |
| 1210 | 1049 | { |
| 1211 | 1050 | if (( bits & (1 << i)) != 0) |
| 1212 | | context->vCap[i] += (node->output[0] - context->vCap[i]) * context->exp[i]; |
| 1051 | m_vCap[i] += (this->output[0] - m_vCap[i]) * m_exp[i]; |
| 1213 | 1052 | } |
| 1214 | 1053 | } |
| 1215 | 1054 | } |
| 1216 | 1055 | else |
| 1217 | 1056 | { |
| 1218 | | node->output[0] = 0; |
| 1057 | this->output[0] = 0; |
| 1219 | 1058 | } |
| 1220 | 1059 | } |
| 1221 | 1060 | |
| 1222 | 1061 | DISCRETE_RESET(dst_rcfilter_sw) |
| 1223 | 1062 | { |
| 1224 | | DISCRETE_DECLARE_CONTEXT(dst_rcfilter_sw) |
| 1225 | | |
| 1226 | 1063 | int i, bits; |
| 1227 | 1064 | |
| 1228 | 1065 | for (i = 0; i < 4; i++) |
| 1229 | 1066 | { |
| 1230 | | context->vCap[i] = 0; |
| 1231 | | context->exp[i] = RC_CHARGE_EXP( CD4066_ON_RES * DST_RCFILTER_SW__C(i)); |
| 1067 | m_vCap[i] = 0; |
| 1068 | m_exp[i] = RC_CHARGE_EXP_CLASS( CD4066_ON_RES * DST_RCFILTER_SW__C(i)); |
| 1232 | 1069 | } |
| 1233 | 1070 | |
| 1234 | 1071 | for (bits=0; bits < 15; bits++) |
| r10048 | r10049 | |
| 1240 | 1077 | if (( bits & (1 << i)) != 0) |
| 1241 | 1078 | rs += DST_RCFILTER_SW__R; |
| 1242 | 1079 | } |
| 1243 | | context->f1[bits] = RES_VOLTAGE_DIVIDER(rs, CD4066_ON_RES); |
| 1244 | | context->f2[bits] = DST_RCFILTER_SW__R / (CD4066_ON_RES + rs); |
| 1080 | m_f1[bits] = RES_VOLTAGE_DIVIDER(rs, CD4066_ON_RES); |
| 1081 | m_f2[bits] = DST_RCFILTER_SW__R / (CD4066_ON_RES + rs); |
| 1245 | 1082 | } |
| 1246 | 1083 | |
| 1247 | 1084 | |
| 1248 | 1085 | /* fast cases */ |
| 1249 | | context->exp0 = RC_CHARGE_EXP((CD4066_ON_RES + DST_RCFILTER_SW__R) * DST_RCFILTER_SW__C(0)); |
| 1250 | | context->exp1 = RC_CHARGE_EXP((CD4066_ON_RES + DST_RCFILTER_SW__R) * DST_RCFILTER_SW__C(1)); |
| 1251 | | context->factor = RES_VOLTAGE_DIVIDER(DST_RCFILTER_SW__R, CD4066_ON_RES); |
| 1086 | m_exp0 = RC_CHARGE_EXP_CLASS((CD4066_ON_RES + DST_RCFILTER_SW__R) * DST_RCFILTER_SW__C(0)); |
| 1087 | m_exp1 = RC_CHARGE_EXP_CLASS((CD4066_ON_RES + DST_RCFILTER_SW__R) * DST_RCFILTER_SW__C(1)); |
| 1088 | m_factor = RES_VOLTAGE_DIVIDER(DST_RCFILTER_SW__R, CD4066_ON_RES); |
| 1252 | 1089 | |
| 1253 | | node->output[0] = 0; |
| 1090 | this->output[0] = 0; |
| 1254 | 1091 | } |
| 1255 | 1092 | |
| 1256 | 1093 | |
| r10048 | r10049 | |
| 1293 | 1130 | |
| 1294 | 1131 | DISCRETE_STEP( dst_rcintegrate) |
| 1295 | 1132 | { |
| 1296 | | DISCRETE_DECLARE_CONTEXT(dst_rcintegrate) |
| 1297 | | |
| 1298 | 1133 | double diff, u, iQ, iQc, iC, RG, vE; |
| 1299 | 1134 | double vP; |
| 1300 | 1135 | |
| 1301 | 1136 | u = DST_RCINTEGRATE__IN1; |
| 1302 | 1137 | vP = DST_RCINTEGRATE__VP; |
| 1303 | 1138 | |
| 1304 | | if ( u - 0.7 < context->vCap * context->gain_r1_r2) |
| 1139 | if ( u - 0.7 < m_vCap * m_gain_r1_r2) |
| 1305 | 1140 | { |
| 1306 | 1141 | /* discharge .... */ |
| 1307 | | diff = 0.0 - context->vCap; |
| 1308 | | iC = context->c_exp1 * diff; /* iC */ |
| 1309 | | diff -= diff * context->exp_exponent1; |
| 1310 | | context->vCap += diff; |
| 1142 | diff = 0.0 - m_vCap; |
| 1143 | iC = m_c_exp1 * diff; /* iC */ |
| 1144 | diff -= diff * m_exp_exponent1; |
| 1145 | m_vCap += diff; |
| 1311 | 1146 | iQ = 0; |
| 1312 | | vE = context->vCap * context->gain_r1_r2; |
| 1147 | vE = m_vCap * m_gain_r1_r2; |
| 1313 | 1148 | RG = vE / iC; |
| 1314 | 1149 | } |
| 1315 | 1150 | else |
| 1316 | 1151 | { |
| 1317 | 1152 | /* charging */ |
| 1318 | | diff = (vP - context->vCE) * context->f - context->vCap; |
| 1319 | | iC = 0.0 - context->c_exp0 * diff; /* iC */ |
| 1320 | | diff -= diff * context->exp_exponent0; |
| 1321 | | context->vCap += diff; |
| 1322 | | iQ = iC + (iC * DST_RCINTEGRATE__R1 + context->vCap) / DST_RCINTEGRATE__R2; |
| 1323 | | RG = (vP - context->vCE) / iQ; |
| 1324 | | vE = (RG - DST_RCINTEGRATE__R3) / RG * (vP - context->vCE); |
| 1153 | diff = (vP - m_vCE) * m_f - m_vCap; |
| 1154 | iC = 0.0 - m_c_exp0 * diff; /* iC */ |
| 1155 | diff -= diff * m_exp_exponent0; |
| 1156 | m_vCap += diff; |
| 1157 | iQ = iC + (iC * DST_RCINTEGRATE__R1 + m_vCap) / DST_RCINTEGRATE__R2; |
| 1158 | RG = (vP - m_vCE) / iQ; |
| 1159 | vE = (RG - DST_RCINTEGRATE__R3) / RG * (vP - m_vCE); |
| 1325 | 1160 | } |
| 1326 | 1161 | |
| 1327 | 1162 | |
| r10048 | r10049 | |
| 1329 | 1164 | if (u > 0.7 + vE) |
| 1330 | 1165 | vE = u - 0.7; |
| 1331 | 1166 | iQc = EM_IC(u - vE); |
| 1332 | | context->vCE = MIN(vP - 0.1, vP - RG * iQc); |
| 1167 | m_vCE = MIN(vP - 0.1, vP - RG * iQc); |
| 1333 | 1168 | |
| 1334 | 1169 | /* Avoid oscillations |
| 1335 | 1170 | * The method tends to largely overshoot - no wonder without |
| 1336 | 1171 | * iterative solution approximation |
| 1337 | 1172 | */ |
| 1338 | 1173 | |
| 1339 | | context->vCE = MAX(context->vCE, 0.1 ); |
| 1340 | | context->vCE = 0.1 * context->vCE + 0.9 * (vP - vE - iQ * DST_RCINTEGRATE__R3); |
| 1174 | m_vCE = MAX(m_vCE, 0.1 ); |
| 1175 | m_vCE = 0.1 * m_vCE + 0.9 * (vP - vE - iQ * DST_RCINTEGRATE__R3); |
| 1341 | 1176 | |
| 1342 | | switch (context->type) |
| 1177 | switch (m_type) |
| 1343 | 1178 | { |
| 1344 | 1179 | case DISC_RC_INTEGRATE_TYPE1: |
| 1345 | | node->output[0] = context->vCap; |
| 1180 | this->output[0] = m_vCap; |
| 1346 | 1181 | break; |
| 1347 | 1182 | case DISC_RC_INTEGRATE_TYPE2: |
| 1348 | | node->output[0] = vE; |
| 1183 | this->output[0] = vE; |
| 1349 | 1184 | break; |
| 1350 | 1185 | case DISC_RC_INTEGRATE_TYPE3: |
| 1351 | | node->output[0] = MAX(0, vP - iQ * DST_RCINTEGRATE__R3); |
| 1186 | this->output[0] = MAX(0, vP - iQ * DST_RCINTEGRATE__R3); |
| 1352 | 1187 | break; |
| 1353 | 1188 | } |
| 1354 | 1189 | } |
| 1190 | |
| 1355 | 1191 | DISCRETE_RESET(dst_rcintegrate) |
| 1356 | 1192 | { |
| 1357 | | DISCRETE_DECLARE_CONTEXT(dst_rcintegrate) |
| 1358 | | |
| 1359 | 1193 | double r; |
| 1360 | | double dt = node->info->sample_time; |
| 1194 | double dt = this->sample_time(); |
| 1361 | 1195 | |
| 1362 | | context->type = DST_RCINTEGRATE__TYPE; |
| 1196 | m_type = DST_RCINTEGRATE__TYPE; |
| 1363 | 1197 | |
| 1364 | | context->vCap = 0; |
| 1365 | | context->vCE = 0; |
| 1198 | m_vCap = 0; |
| 1199 | m_vCE = 0; |
| 1366 | 1200 | |
| 1367 | 1201 | /* pre-calculate fixed values */ |
| 1368 | | context->gain_r1_r2 = RES_VOLTAGE_DIVIDER(DST_RCINTEGRATE__R1, DST_RCINTEGRATE__R2); |
| 1202 | m_gain_r1_r2 = RES_VOLTAGE_DIVIDER(DST_RCINTEGRATE__R1, DST_RCINTEGRATE__R2); |
| 1369 | 1203 | |
| 1370 | 1204 | r = DST_RCINTEGRATE__R1 / DST_RCINTEGRATE__R2 * DST_RCINTEGRATE__R3 + DST_RCINTEGRATE__R1 + DST_RCINTEGRATE__R3; |
| 1371 | 1205 | |
| 1372 | | context->f = RES_VOLTAGE_DIVIDER(DST_RCINTEGRATE__R3, DST_RCINTEGRATE__R2); |
| 1373 | | context->exponent0 = -1.0 * r * context->f * DST_RCINTEGRATE__C; |
| 1374 | | context->exponent1 = -1.0 * (DST_RCINTEGRATE__R1 + DST_RCINTEGRATE__R2) * DST_RCINTEGRATE__C; |
| 1375 | | context->exp_exponent0 = exp(dt / context->exponent0); |
| 1376 | | context->exp_exponent1 = exp(dt / context->exponent1); |
| 1377 | | context->c_exp0 = DST_RCINTEGRATE__C / context->exponent0 * context->exp_exponent0; |
| 1378 | | context->c_exp1 = DST_RCINTEGRATE__C / context->exponent1 * context->exp_exponent1; |
| 1206 | m_f = RES_VOLTAGE_DIVIDER(DST_RCINTEGRATE__R3, DST_RCINTEGRATE__R2); |
| 1207 | m_exponent0 = -1.0 * r * m_f * DST_RCINTEGRATE__C; |
| 1208 | m_exponent1 = -1.0 * (DST_RCINTEGRATE__R1 + DST_RCINTEGRATE__R2) * DST_RCINTEGRATE__C; |
| 1209 | m_exp_exponent0 = exp(dt / m_exponent0); |
| 1210 | m_exp_exponent1 = exp(dt / m_exponent1); |
| 1211 | m_c_exp0 = DST_RCINTEGRATE__C / m_exponent0 * m_exp_exponent0; |
| 1212 | m_c_exp1 = DST_RCINTEGRATE__C / m_exponent1 * m_exp_exponent1; |
| 1379 | 1213 | |
| 1380 | | node->output[0] = 0; |
| 1214 | this->output[0] = 0; |
| 1381 | 1215 | } |
| 1382 | 1216 | |
| 1383 | 1217 | /************************************************************************ |
| r10048 | r10049 | |
| 1398 | 1232 | |
| 1399 | 1233 | DISCRETE_STEP(dst_sallen_key) |
| 1400 | 1234 | { |
| 1401 | | DISCRETE_DECLARE_CONTEXT(dst_filter2) |
| 1402 | | |
| 1403 | 1235 | double gain = 1.0; |
| 1404 | 1236 | |
| 1405 | 1237 | if (DST_SALLEN_KEY__ENABLE == 0.0) |
| r10048 | r10049 | |
| 1407 | 1239 | gain = 0.0; |
| 1408 | 1240 | } |
| 1409 | 1241 | |
| 1410 | | node->output[0] = -context->a1 * context->y1 - context->a2 * context->y2 + |
| 1411 | | context->b0 * gain * DST_SALLEN_KEY__INP0 + context->b1 * context->x1 + context->b2 * context->x2; |
| 1242 | this->output[0] = -m_fc.a1 * m_fc.y1 - m_fc.a2 * m_fc.y2 + |
| 1243 | m_fc.b0 * gain * DST_SALLEN_KEY__INP0 + m_fc.b1 * m_fc.x1 + m_fc.b2 * m_fc.x2; |
| 1412 | 1244 | |
| 1413 | | context->x2 = context->x1; |
| 1414 | | context->x1 = gain * DST_SALLEN_KEY__INP0; |
| 1415 | | context->y2 = context->y1; |
| 1416 | | context->y1 = node->output[0]; |
| 1245 | m_fc.x2 = m_fc.x1; |
| 1246 | m_fc.x1 = gain * DST_SALLEN_KEY__INP0; |
| 1247 | m_fc.y2 = m_fc.y1; |
| 1248 | m_fc.y1 = this->output[0]; |
| 1417 | 1249 | } |
| 1418 | 1250 | |
| 1419 | 1251 | DISCRETE_RESET(dst_sallen_key) |
| 1420 | 1252 | { |
| 1421 | | DISCRETE_DECLARE_CONTEXT(dst_filter2) |
| 1422 | 1253 | DISCRETE_DECLARE_INFO(discrete_op_amp_filt_info) |
| 1423 | 1254 | |
| 1424 | 1255 | double freq, q; |
| r10048 | r10049 | |
| 1433 | 1264 | fatalerror("Unknown sallen key filter type"); |
| 1434 | 1265 | } |
| 1435 | 1266 | |
| 1436 | | calculate_filter2_coefficients(node->info, freq, 1.0 / q, DISC_FILTER_LOWPASS, |
| 1437 | | &context->a1, &context->a2, |
| 1438 | | &context->b0, &context->b1, &context->b2); |
| 1439 | | node->output[0] = 0; |
| 1267 | calculate_filter2_coefficients(this, freq, 1.0 / q, DISC_FILTER_LOWPASS, m_fc); |
| 1268 | this->output[0] = 0; |
| 1440 | 1269 | } |
| 1441 | 1270 | |
| 1442 | 1271 | |
| r10048 | r10049 | |
| 1458 | 1287 | #define DST_RCFILTERN__R DISCRETE_INPUT(2) |
| 1459 | 1288 | #define DST_RCFILTERN__C DISCRETE_INPUT(3) |
| 1460 | 1289 | |
| 1290 | #if 0 |
| 1461 | 1291 | DISCRETE_RESET(dst_rcfilterN) |
| 1462 | 1292 | { |
| 1463 | 1293 | #if 0 |
| r10048 | r10049 | |
| 1466 | 1296 | /* !!!!!!!!!!!!!! CAN'T CHEAT LIKE THIS !!!!!!!!!!!!!!!! */ |
| 1467 | 1297 | /* Put this stuff in a context */ |
| 1468 | 1298 | |
| 1469 | | node->input[2] = f; |
| 1470 | | node->input[3] = DISC_FILTER_LOWPASS; |
| 1299 | this->input[2] = f; |
| 1300 | this->input[3] = DISC_FILTER_LOWPASS; |
| 1471 | 1301 | |
| 1472 | 1302 | /* Use first order filter */ |
| 1473 | 1303 | dst_filter1_reset(node); |
| 1474 | 1304 | #endif |
| 1475 | 1305 | } |
| 1306 | #endif |
| 1476 | 1307 | |
| 1477 | | |
| 1478 | 1308 | /************************************************************************ |
| 1479 | 1309 | * |
| 1480 | 1310 | * DST_RCDISCN - Usage of node_description values for RC discharge |
| r10048 | r10049 | |
| 1499 | 1329 | /* !!!!!!!!!!!!!! CAN'T CHEAT LIKE THIS !!!!!!!!!!!!!!!! */ |
| 1500 | 1330 | /* Put this stuff in a context */ |
| 1501 | 1331 | |
| 1502 | | node->input[2] = f; |
| 1503 | | node->input[3] = DISC_FILTER_LOWPASS; |
| 1332 | this->input[2] = f; |
| 1333 | this->input[3] = DISC_FILTER_LOWPASS; |
| 1504 | 1334 | |
| 1505 | 1335 | /* Use first order filter */ |
| 1506 | 1336 | dst_filter1_reset(node); |
| r10048 | r10049 | |
| 1509 | 1339 | |
| 1510 | 1340 | DISCRETE_STEP(dst_rcdiscN) |
| 1511 | 1341 | { |
| 1512 | | DISCRETE_DECLARE_CONTEXT(dst_filter1) |
| 1513 | | |
| 1514 | 1342 | double gain = 1.0; |
| 1515 | 1343 | |
| 1516 | 1344 | if (DST_RCDISCN__ENABLE == 0.0) |
| r10048 | r10049 | |
| 1520 | 1348 | |
| 1521 | 1349 | /* A rise in the input signal results in an instant charge, */ |
| 1522 | 1350 | /* else discharge through the RC to zero */ |
| 1523 | | if (gain* DST_RCDISCN__IN > context->x1) |
| 1524 | | node->output[0] = gain* DST_RCDISCN__IN; |
| 1351 | if (gain* DST_RCDISCN__IN > m_x1) |
| 1352 | this->output[0] = gain* DST_RCDISCN__IN; |
| 1525 | 1353 | else |
| 1526 | | node->output[0] = -context->a1*context->y1; |
| 1354 | this->output[0] = -m_a1*m_y1; |
| 1527 | 1355 | |
| 1528 | | context->x1 = gain* DST_RCDISCN__IN; |
| 1529 | | context->y1 = node->output[0]; |
| 1356 | m_x1 = gain* DST_RCDISCN__IN; |
| 1357 | m_y1 = this->output[0]; |
| 1530 | 1358 | } |
| 1531 | 1359 | |
| 1532 | 1360 | |
| r10048 | r10049 | |
| 1543 | 1371 | * input[5] - Capacitor Value (initialization only) |
| 1544 | 1372 | * |
| 1545 | 1373 | ************************************************************************/ |
| 1546 | | #define DST_RCDISC2N__ENABLE DISCRETE_INPUT(0) |
| 1374 | #define DST_RCDISC2N__ENABLE DISCRETE_INPUT(0) |
| 1547 | 1375 | #define DST_RCDISC2N__IN0 DISCRETE_INPUT(1) |
| 1548 | 1376 | #define DST_RCDISC2N__R0 DISCRETE_INPUT(2) |
| 1549 | 1377 | #define DST_RCDISC2N__IN1 DISCRETE_INPUT(3) |
| 1550 | 1378 | #define DST_RCDISC2N__R1 DISCRETE_INPUT(4) |
| 1551 | 1379 | #define DST_RCDISC2N__C DISCRETE_INPUT(5) |
| 1552 | 1380 | |
| 1553 | | struct dst_rcdisc2_context |
| 1554 | | { |
| 1555 | | double x1; /* x[k-1], last input value */ |
| 1556 | | double y1; /* y[k-1], last output value */ |
| 1557 | | double a1_0, b0_0, b1_0; /* digital filter coefficients, filter #1 */ |
| 1558 | | double a1_1, b0_1, b1_1; /* digital filter coefficients, filter #2 */ |
| 1559 | | }; |
| 1560 | 1381 | |
| 1561 | 1382 | DISCRETE_STEP(dst_rcdisc2N) |
| 1562 | 1383 | { |
| 1563 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc2) |
| 1564 | | |
| 1565 | 1384 | double input = ((DST_RCDISC2N__ENABLE == 0) ? DST_RCDISC2N__IN0 : DST_RCDISC2N__IN1); |
| 1566 | 1385 | |
| 1567 | 1386 | if (DST_RCDISC2N__ENABLE == 0) |
| 1568 | | node->output[0] = -context->a1_0*context->y1 + context->b0_0*input + context->b1_0*context->x1; |
| 1387 | this->output[0] = -m_fc0.a1*m_y1 + m_fc0.b0*input + m_fc0.b1 * m_x1; |
| 1569 | 1388 | else |
| 1570 | | node->output[0] = -context->a1_1*context->y1 + context->b0_1*input + context->b1_1*context->x1; |
| 1389 | this->output[0] = -m_fc1.a1*m_y1 + m_fc1.b0*input + m_fc1.b1*m_x1; |
| 1571 | 1390 | |
| 1572 | | context->x1 = input; |
| 1573 | | context->y1 = node->output[0]; |
| 1391 | m_x1 = input; |
| 1392 | m_y1 = this->output[0]; |
| 1574 | 1393 | } |
| 1575 | 1394 | |
| 1576 | 1395 | DISCRETE_RESET(dst_rcdisc2N) |
| 1577 | 1396 | { |
| 1578 | | DISCRETE_DECLARE_CONTEXT(dst_rcdisc2) |
| 1579 | 1397 | double f1,f2; |
| 1580 | 1398 | |
| 1581 | 1399 | f1 = 1.0 / (2 * M_PI * DST_RCDISC2N__R0 * DST_RCDISC2N__C); |
| 1582 | 1400 | f2 = 1.0 / (2 * M_PI * DST_RCDISC2N__R1 * DST_RCDISC2N__C); |
| 1583 | 1401 | |
| 1584 | | calculate_filter1_coefficients(node->info, f1, DISC_FILTER_LOWPASS, &context->a1_0, &context->b0_0, &context->b1_0); |
| 1585 | | calculate_filter1_coefficients(node->info, f2, DISC_FILTER_LOWPASS, &context->a1_1, &context->b0_1, &context->b1_1); |
| 1402 | calculate_filter1_coefficients(this, f1, DISC_FILTER_LOWPASS, m_fc0); |
| 1403 | calculate_filter1_coefficients(this, f2, DISC_FILTER_LOWPASS, m_fc1); |
| 1586 | 1404 | |
| 1587 | 1405 | /* Initialize the object */ |
| 1588 | | node->output[0] = 0; |
| 1406 | this->output[0] = 0; |
| 1589 | 1407 | } |