Previous 15994 Revisions Next

r10049 Saturday 15th January, 2011 at 15:13:28 UTC by Miodrag Milanović
Sync with MAME core
[src/emu]ui.c
[src/emu/cpu]cpu.mak drcbec.c drcbeut.c drcbeut.h drcbex64.c drcbex86.c drccache.c drccache.h drcuml.c drcuml.h
[src/emu/cpu/arm7]arm7exec.c
[src/emu/cpu/h83002]h8_16.c h8_8.c
[src/emu/cpu/mips]mips3drc.c
[src/emu/cpu/nec]necpriv.h
[src/emu/cpu/powerpc]ppcdrc.c
[src/emu/cpu/rsp]rspdrc.c
[src/emu/cpu/sh2]sh2comn.h sh2drc.c
[src/emu/debug]debugcpu.c
[src/emu/sound]disc_cls.h* disc_dev.c disc_dev.h* disc_flt.c disc_flt.h* disc_inp.c disc_mth.c disc_mth.h* disc_sys.c disc_wav.c disc_wav.h* discrete.c discrete.h
[src/osd/sdl]draw13.c drawsdl.c osdsdl.h sdl.mak sdlmain.c sdlos_os2.c sdlptty_os2.c* sdlsync.h sdlsync_ntc.c sdlsync_tc.c sdlsync_win32.c video.c watchdog.c* watchdog.h*
[src/tools]unidasm.c

src/tools/unidasm.c
r10048r10049
9797CPU_DISASSEMBLE( cop410 );
9898CPU_DISASSEMBLE( cop420 );
9999CPU_DISASSEMBLE( cop444 );
100CPU_DISASSEMBLE( cosmac );
100101CPU_DISASSEMBLE( cp1610 );
101102CPU_DISASSEMBLE( cquestsnd );
102103CPU_DISASSEMBLE( cquestrot );
r10048r10049
104105CPU_DISASSEMBLE( dsp32c );
105106CPU_DISASSEMBLE( dsp56k );
106107CPU_DISASSEMBLE( hyperstone_generic );
108CPU_DISASSEMBLE( hd61700 );
107109CPU_DISASSEMBLE( esrip );
108110CPU_DISASSEMBLE( f8 );
109111CPU_DISASSEMBLE( g65816_generic );
r10048r10049
220222   { "cop410",      _8bit,  0, CPU_DISASSEMBLE_NAME(cop410) },
221223   { "cop420",      _8bit,  0, CPU_DISASSEMBLE_NAME(cop420) },
222224   { "cop444",      _8bit,  0, CPU_DISASSEMBLE_NAME(cop444) },
225   { "cosmac",      _8bit,  0, CPU_DISASSEMBLE_NAME(cosmac) },
223226   { "cp1610",      _16be, -1, CPU_DISASSEMBLE_NAME(cp1610) },
224227   { "cquestsnd",   _64be, -3, CPU_DISASSEMBLE_NAME(cquestsnd) },
225228   { "cquestrot",   _64be, -3, CPU_DISASSEMBLE_NAME(cquestrot) },
r10048r10049
227230   { "dsp32c",      _32le,  0, CPU_DISASSEMBLE_NAME(dsp32c) },
228231   { "dsp56k",      _16le, -1, CPU_DISASSEMBLE_NAME(dsp56k) },
229232   { "hyperstone",   _16be,  0, CPU_DISASSEMBLE_NAME(hyperstone_generic) },
233   { "hd61700",   _8bit,  0, CPU_DISASSEMBLE_NAME(hd61700) },
230234   { "esrip",      _64be,  0, CPU_DISASSEMBLE_NAME(esrip) },
231235   { "f8",         _8bit,  0, CPU_DISASSEMBLE_NAME(f8) },
232236   { "g65816",      _8bit,  0, CPU_DISASSEMBLE_NAME(g65816_generic) },
src/osd/sdl/sdlos_os2.c
r10048r10049
1616#include <string.h>
1717#include <ctype.h>
1818#include <stdlib.h>
19#include <sys/stat.h>
1920
2021#define INCL_DOS
2122#include <os2.h>
r10048r10049
240241
241242   return result;
242243}
244
245//============================================================
246//  osd_stat
247//============================================================
248
249osd_directory_entry *osd_stat(const char *path)
250{
251   int err;
252   osd_directory_entry *result = NULL;
253   struct stat st;
254
255   err = stat(path, &st);
256
257   if( err == -1) return NULL;
258
259   // create an osd_directory_entry; be sure to make sure that the caller can
260   // free all resources by just freeing the resulting osd_directory_entry
261   result = (osd_directory_entry *) osd_malloc(sizeof(*result) + strlen(path)
262 1);
263   strcpy(((char *) result) + sizeof(*result), path);
264   result->name = ((char *) result) + sizeof(*result);
265   result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
266   result->size = (UINT64)st.st_size;
267
268   return result;
269}
270
271//============================================================
272//  osd_get_volume_name
273//============================================================
274
275const char *osd_get_volume_name(int idx)
276{
277   static char szDrive[] = "A:\\";
278
279   ULONG ulCurDisk;
280   ULONG ulDriveMap;
281
282   DosQueryCurrentDisk(&ulCurDisk, &ulDriveMap);
283
284   szDrive[ 0 ] = 'A';
285   while(idx--) {
286      do
287      {
288         ulDriveMap >>= 1;
289         szDrive[ 0 ]++;
290      } while(ulDriveMap && (ulDriveMap & 1) == 0);
291      if (!ulDriveMap) return NULL;
292   }
293
294   return szDrive;
295}
296
297//============================================================
298//  osd_get_full_path
299//============================================================
300
301file_error osd_get_full_path(char **dst, const char *path)
302{
303   *dst = (char *)osd_malloc(CCHMAXPATH + 1);
304   if (*dst == NULL)
305      return FILERR_OUT_OF_MEMORY;
306
307   _abspath(*dst, path, CCHMAXPATH + 1);
308   return FILERR_NONE;
src/osd/sdl/sdl.mak
r10048r10049
282282   $(SDLOBJ)/video.o \
283283   $(SDLOBJ)/drawsdl.o \
284284   $(SDLOBJ)/window.o \
285   $(SDLOBJ)/output.o
285   $(SDLOBJ)/output.o \
286   $(SDLOBJ)/watchdog.o
286287
287288# Add SDL1.3 support
288289ifdef SDL_INSTALL_ROOT
r10048r10049
347348endif
348349
349350ifndef SDL_INSTALL_ROOT
350INCPATH += `sdl-config --cflags  | sed 's:/SDL::'`
351INCPATH += `sdl-config --cflags  | sed -e 's:/SDL::' -e 's:\(-D[^ ]*\)::g'`
352CCOMFLAGS += `sdl-config --cflags  | sed -e 's:/SDL::' -e 's:\(-I[^ ]*\)::g'`
351353LIBS += -lm `sdl-config --libs`
352354
353355else
r10048r10049
566568zip:
567569   zip -rq ../mame_$(BUILD_VERSION).zip $(DISTFILES) $(EXCLUDES)
568570
569DEPENDFILE = .depend_$(EMULATOR)
570
571makedepend:
572   @echo Generating $(DEPENDFILE)
573   rm -f $(DEPENDFILE)
574   @for i in `find src -name "*.c"` ; do \
575      echo processing $$i; \
576      mt=`echo $$i | sed -e "s/\\.c/\\.o/" -e "s!^src/!$(OBJ)/!"` ; \
577      g++ -MM -MT $$mt $(CDEFS) $(CCOMFLAGS) $$i 2>/dev/null \
578      | sed -e "s!$$i!!g" >> $(DEPENDFILE) ; \
579   done
580
581-include $(DEPENDFILE)
582
583571endif
src/osd/sdl/sdlptty_os2.c
r0r10049
1//============================================================
2//
3//  sdlptty_os2 - SDL psuedo tty access functions
4//  (OS/2 has no pttys - maybe named pipes?)
5//
6//  Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
7//  Visit http://mamedev.org for licensing and usage restrictions.
8//
9//  SDLMAME by Olivier Galibert and R. Belmont
10//
11//============================================================
12
13#include "sdlfile.h"
14
15const char *sdlfile_ptty_identifier  = "";
16
17file_error sdl_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize)
18{
19   return FILERR_ACCESS_DENIED;
20}
21
22file_error sdl_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
23{
24   return FILERR_ACCESS_DENIED;
25}
26
27file_error sdl_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
28{
29   return FILERR_ACCESS_DENIED;
30}
31
32file_error sdl_close_ptty(osd_file *file)
33{
34   return FILERR_ACCESS_DENIED;
35}
src/osd/sdl/drawsdl.c
r10048r10049
7474
7575struct _sdl_scale_mode
7676{
77   const char *name;
78   int      is_scale;         /* Scale mode?           */
79   int      is_yuv;            /* Yuv mode?             */
80   int      mult_w;            /* Width multiplier      */
81   int      mult_h;            /* Height multiplier     */
77   const char       *name;
78   int            is_scale;         /* Scale mode?           */
79   int            is_yuv;            /* Yuv mode?             */
80   int            mult_w;            /* Width multiplier      */
81   int            mult_h;            /* Height multiplier     */
8282#if (!SDL_VERSION_ATLEAST(1,3,0))
83   int      extra_flags;      /* Texture/surface flags */
83   int            extra_flags;      /* Texture/surface flags */
8484#else
85   int      sdl_scale_mode;      /* sdl 1.3 scale mode    */
85   SDL_ScaleMode   sdl_scale_mode;      /* sdl 1.3 scale mode    */
8686#endif
87   int      pixel_format;      /* Pixel/Overlay format  */
88   void    (*yuv_blit)(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
87   int            pixel_format;      /* Pixel/Overlay format  */
88   void          (*yuv_blit)(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
8989};
9090
9191//============================================================
r10048r10049
145145#else
146146static const sdl_scale_mode scale_modes[] =
147147{
148      { "none",    0, 0, 0, 0, SDL_TEXTURESCALEMODE_NONE, 0, 0 },
149      { "hwblit",  1, 0, 1, 1, SDL_TEXTURESCALEMODE_FAST, 0, 0 },
150      { "hwbest",  1, 0, 1, 1, SDL_TEXTURESCALEMODE_BEST, 0, 0 },
151      { "yv12",    1, 1, 1, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12 },
152      { "yv12x2",  1, 1, 2, 2, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12X2 },
153      { "yuy2",    1, 1, 1, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2 },
154      { "yuy2x2",  1, 1, 2, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2X2 },
148      { "none",    0, 0, 0, 0, SDL_SCALEMODE_NONE, 0, 0 },
149      { "hwblit",  1, 0, 1, 1, SDL_SCALEMODE_FAST, 0, 0 },
150      { "hwbest",  1, 0, 1, 1, SDL_SCALEMODE_BEST, 0, 0 },
151      { "yv12",    1, 1, 1, 1, SDL_SCALEMODE_NONE, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12 },
152      { "yv12x2",  1, 1, 2, 2, SDL_SCALEMODE_NONE, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12X2 },
153      { "yuy2",    1, 1, 1, 1, SDL_SCALEMODE_NONE, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2 },
154      { "yuy2x2",  1, 1, 2, 1, SDL_SCALEMODE_NONE, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2X2 },
155155      { NULL }
156156};
157157#endif
src/osd/sdl/watchdog.c
r0r10049
1//============================================================
2//
3//  watchdog.h - watchdog handling
4//
5//  Copyright (c) 1996-2011, Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//  SDLMAME by Olivier Galibert and R. Belmont
9//
10//============================================================
11
12#include "osdcomm.h"
13#include "osdcore.h"
14#include "osinline.h"
15
16#include "watchdog.h"
17
18static void *watchdog_thread(void *param)
19{
20   watchdog *thiz = (watchdog *) param;
21
22   while (TRUE)
23   {
24      if (osd_event_wait(thiz->event(), thiz->getTimeout()))
25      {
26         if (thiz->do_exit())
27            break;
28         else
29         {
30            osd_event_reset(thiz->event());
31            continue;
32         }
33      }
34      else
35      {
36         fprintf(stderr, "Terminating due to watchdog timeout\n");
37
38         osd_process_kill();
39      }
40   }
41   return NULL;
42}
43
44watchdog::watchdog(void)
45{
46   m_do_exit = 0;
47   m_event = osd_event_alloc(1, 0);
48   m_thread = osd_thread_create(watchdog_thread, this);
49   m_timeout = 60 * osd_ticks_per_second();
50}
51
52watchdog::~watchdog(void)
53{
54   atomic_exchange32(&m_do_exit, 1);
55   osd_event_set(m_event);
56   osd_thread_wait_free(m_thread);
57   osd_event_free(m_event);
58}
59
60void watchdog::setTimeout(int timeout)
61{
62   m_timeout = timeout * osd_ticks_per_second();
63   this->reset();
64}
src/osd/sdl/draw13.c
r10048r10049
109109
110110   copy_info         *copyinfo;
111111   Uint32            sdl_access;
112   Uint32            sdl_blendmode;
112   SDL_BlendMode      sdl_blendmode;
113113   quad_setup_data      setup;
114114   int               is_rotated;
115115
r10048r10049
310310   return (HashT)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
311311}
312312
313INLINE Uint32 map_blendmode(int blendmode)
313INLINE SDL_BlendMode map_blendmode(int blendmode)
314314{
315315   switch (blendmode)
316316   {
r10048r10049
377377      texture->copyinfo->time -= osd_ticks();
378378      if ((PRIMFLAG_GET_SCREENTEX(prim->flags)) && video_config.filter)
379379      {
380         SDL_SetTextureScaleMode(texture->texture_id,  SDL_TEXTURESCALEMODE_BEST);
380         SDL_SetTextureScaleMode(texture->texture_id,  SDL_SCALEMODE_BEST);
381381      }
382382      else
383383      {
384         SDL_SetTextureScaleMode(texture->texture_id,  SDL_TEXTURESCALEMODE_NONE);
384         SDL_SetTextureScaleMode(texture->texture_id,  SDL_SCALEMODE_NONE);
385385      }
386386      SDL_SetTextureBlendMode(texture_id, texture->sdl_blendmode);
387387      set_coloralphamode(texture_id, &prim->color);
src/osd/sdl/sdlsync_tc.c
r10048r10049
3131
3232#include <pthread.h>
3333#include <errno.h>
34#include <signal.h>
3435#include <sys/time.h>
3536
3637typedef struct _hidden_mutex_t hidden_mutex_t;
r10048r10049
378379   free(thread);
379380}
380381
382//============================================================
383//  osd_process_kill
384//============================================================
385
386void osd_process_kill(void)
387{
388   kill(getpid(), SIGKILL);
389}
src/osd/sdl/watchdog.h
r0r10049
1#ifndef _watchdog_h_
2#define _watchdog_h_
3//============================================================
4//
5//  watchdog.h - watchdog handling
6//
7//  Copyright (c) 1996-2011, Nicola Salmoria and the MAME Team.
8//  Visit http://mamedev.org for licensing and usage restrictions.
9//
10//  SDLMAME by Olivier Galibert and R. Belmont
11//
12//============================================================
13
14#include "sdlsync.h"
15
16class watchdog
17{
18public:
19   watchdog(void);
20   ~watchdog(void);
21
22   void reset() { osd_event_set(m_event); }
23
24   osd_event *      event(void) { return m_event; }
25   INT32         do_exit(void) { return m_do_exit; }
26   osd_ticks_t      getTimeout(void) { return m_timeout; }
27   void         setTimeout(int timeout);
28private:
29   osd_event *      m_event;
30   osd_thread *   m_thread;
31   volatile INT32   m_do_exit;
32
33   osd_ticks_t      m_timeout;
34};
35#endif
src/osd/sdl/video.c
r10048r10049
333333{
334334   sdl_window_info *window;
335335
336   if (m_watchdog != NULL)
337      m_watchdog->reset();
338
336339   // if we're not skipping this redraw, update all windows
337340   if (!skip_redraw)
338341   {
src/osd/sdl/sdlsync.h
r10048r10049
174174-----------------------------------------------------------------------------*/
175175void osd_thread_wait_free(osd_thread *thread);
176176
177/*-----------------------------------------------------------------------------
178    osd_process_kill: kill the current process
177179
180    Parameters:
181
182        None.
183
184    Return value:
185
186        None.
187-----------------------------------------------------------------------------*/
188void osd_process_kill(void);
189
178190//============================================================
179191//  Scalable Locks
180192//============================================================
src/osd/sdl/sdlmain.c
r10048r10049
5353#include <X11/Xutil.h>
5454#endif
5555
56#include "watchdog.h"
57
5658//============================================================
5759//  OPTIONS
5860//============================================================
r10048r10049
8587   // debugging options
8688   { NULL,                                   NULL,       OPTION_HEADER,     "DEBUGGING OPTIONS" },
8789   { SDLOPTION_OSLOG,                        "0",        OPTION_BOOLEAN,    "output error.log data to the system debugger" },
90   { SDLOPTION_WATCHDOG ";wdog",             "0",        0,                 "force the program to terminate if no updates within specified number of seconds" },
8891
8992   // performance options
9093   { NULL,                                   NULL,       OPTION_HEADER,     "PERFORMANCE OPTIONS" },
9194   { SDLOPTION_MULTITHREADING ";mt",         "0",        OPTION_BOOLEAN,    "enable multithreading; this enables rendering and blitting on a separate thread" },
9295   { SDLOPTION_NUMPROCESSORS ";np",         "auto",      0,             "number of processors; this overrides the number the system reports" },
9396   { SDLOPTION_SDLVIDEOFPS,                  "0",        OPTION_BOOLEAN,    "show sdl video performance" },
97   { SDLOPTION_BENCH,                        "0",        0,                 "benchmark for the given number of emulated seconds; implies -video none -nosound -nothrottle" },
9498   // video options
9599   { NULL,                                   NULL,       OPTION_HEADER,     "VIDEO OPTIONS" },
96100// OS X can be trusted to have working hardware OpenGL, so default to it on for the best user experience
r10048r10049
369373
370374sdl_osd_interface::sdl_osd_interface()
371375{
376   m_watchdog = NULL;
372377}
373378
374379
r10048r10049
520525
521526   const char *stemp;
522527
528   // determine if we are benchmarking, and adjust options appropriately
529   int bench = options_get_int(machine.options(), SDLOPTION_BENCH);
530   if (bench > 0)
531   {
532      options_set_bool(machine.options(), OPTION_THROTTLE, false, OPTION_PRIORITY_MAXIMUM);
533      options_set_bool(machine.options(), OPTION_SOUND, false, OPTION_PRIORITY_MAXIMUM);
534      options_set_string(machine.options(), SDLOPTION_VIDEO, "none", OPTION_PRIORITY_MAXIMUM);
535      options_set_int(machine.options(), OPTION_SECONDS_TO_RUN, bench, OPTION_PRIORITY_MAXIMUM);
536   }
537
523538   // Some driver options - must be before audio init!
524539   stemp = options_get_string(machine.options(), SDLOPTION_AUDIODRIVER);
525540   if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
r10048r10049
617632   if (options_get_bool(machine.options(), SDLOPTION_OSLOG))
618633      machine.add_logerror_callback(output_oslog);
619634
635   /* now setup watchdog */
636
637   int watchdog_timeout = options_get_int(machine.options(), SDLOPTION_WATCHDOG);
638   int str = options_get_int(machine.options(), OPTION_SECONDS_TO_RUN);
639
640   /* only enable watchdog if seconds_to_run is enabled *and* relatively short (time taken from ui.c) */
641   if ((watchdog_timeout != 0) && (str > 0) && (str < 60*5 ))
642   {
643      m_watchdog = auto_alloc(&machine, watchdog);
644      m_watchdog->setTimeout(watchdog_timeout);
645   }
646
620647#if (SDL_VERSION_ATLEAST(1,3,0))
621648   SDL_EventState(SDL_TEXTINPUT, SDL_TRUE);
622649#else
src/osd/sdl/osdsdl.h
r10048r10049
33
44#include <SDL/SDL.h>
55
6#include "watchdog.h"
7
68//============================================================
79//  Temporary SDL 1.3 defines
810//============================================================
r10048r10049
6769#define SDLOPTION_PRESCALE            "prescale"
6870
6971#define SDLOPTION_SCALEMODE            "scalemode"
72
7073#define SDLOPTION_MULTITHREADING      "multithreading"
74#define SDLOPTION_BENCH               "bench"
7175#define SDLOPTION_NUMPROCESSORS         "numprocessors"
76
7277#define SDLOPTION_WAITVSYNC            "waitvsync"
7378#define SDLOPTION_KEYMAP            "keymap"
7479#define SDLOPTION_KEYMAP_FILE         "keymap_file"
7580#define SDLOPTION_UIMODEKEY            "uimodekey"
7681#define SDLOPTION_OSLOG               "oslog"
82#define SDLOPTION_WATCHDOG            "watchdog"
7783
7884#define SDLOPTION_SIXAXIS            "sixaxis"
7985#define SDLOPTION_JOYINDEX            "joy_idx"
r10048r10049
162168
163169private:
164170   static void osd_exit(running_machine &machine);
171
172   watchdog *m_watchdog;
173
165174};
166175
167176
src/osd/sdl/sdlsync_win32.c
r10048r10049
221221   return TRUE;
222222}
223223
224//============================================================
225//  osd_process_kill
226//============================================================
227
228void osd_process_kill(void)
229{
230   TerminateProcess(GetCurrentProcess(), -1);
231}
src/osd/sdl/sdlsync_ntc.c
r10048r10049
1717
1818#ifdef SDLMAME_MACOSX
1919#include <mach/mach.h>
20#include <signal.h>
2021#endif
2122
2223// standard C headers
r10048r10049
512513   pthread_join(thread->thread, NULL);
513514   free(thread);
514515}
516
517//============================================================
518//  osd_process_kill
519//============================================================
520
521void osd_process_kill(void)
522{
523   kill(getpid(), SIGKILL);
524}
src/emu/debug/debugcpu.c
r10048r10049
5151#include "xmlfile.h"
5252#include <ctype.h>
5353#include <zlib.h>
54#ifdef SDLMAME_FREEBSD
54#if defined(SDLMAME_FREEBSD) || defined(SDLMAME_OS2)
5555# undef tolower
5656#endif
5757
src/emu/cpu/h83002/h8_16.c
r10048r10049
101101
102102static char *h8_get_ccr_str(h83xx_state *h8)
103103{
104   static char res[8];
104   static char res[10];
105105
106   memset(res, 0, 8);
106   memset(res, 0, sizeof(res));
107107   if(h8->h8iflag) strcat(res, "I"); else strcat(res, "i");
108108   if(h8->h8uiflag)strcat(res, "U"); else strcat(res, "u");
109109   if(h8->h8hflag) strcat(res, "H"); else strcat(res, "h");
src/emu/cpu/h83002/h8_8.c
r10048r10049
117117
118118static char *h8_get_ccr_str(h83xx_state *h8)
119119{
120   static char res[8];
120   static char res[10];
121121
122   memset(res, 0, 8);
122   memset(res, 0, sizeof(res));
123123   if(h8->h8iflag) strcat(res, "I"); else strcat(res, "i");
124124   if(h8->h8uiflag)strcat(res, "U"); else strcat(res, "u");
125125   if(h8->h8hflag) strcat(res, "H"); else strcat(res, "h");
src/emu/cpu/cpu.mak
r10048r10049
17851785$(CPUOBJ)/pps4/pps4.o:   $(CPUSRC)/pps4/pps4.c \
17861786                     $(CPUSRC)/pps4/pps4.h
17871787
1788
1789
17901788#-------------------------------------------------
17911789# Hitachi HD61700
17921790#-------------------------------------------------
r10048r10049
17991797
18001798$(CPUOBJ)/hd61700/hd61700.o:   $(CPUSRC)/hd61700/hd61700.c \
18011799                        $(CPUSRC)/hd61700/hd61700.h
1802
src/emu/cpu/drcuml.c
r10048r10049
136136struct _drcuml_state
137137{
138138   device_t *   device;            /* CPU device we are associated with */
139   drccache *            cache;            /* pointer to the codegen cache */
139   drc_cache *            cache;            /* pointer to the codegen cache */
140140   drcuml_block *         blocklist;         /* list of active blocks */
141141   const drcbe_interface *   beintf;            /* backend interface pointer */
142142   drcbe_state *         bestate;         /* pointer to the back-end state */
r10048r10049
538538    generator and initialize the back-end
539539-------------------------------------------------*/
540540
541drcuml_state *drcuml_alloc(device_t *device, drccache *cache, UINT32 flags, int modes, int addrbits, int ignorebits)
541drcuml_state *drcuml_alloc(device_t *device, drc_cache *cache, UINT32 flags, int modes, int addrbits, int ignorebits)
542542{
543543   drcuml_state *drcuml;
544544   int opnum;
545545
546546   /* allocate state */
547   drcuml = (drcuml_state *)drccache_memory_alloc(cache, sizeof(*drcuml));
547   drcuml = (drcuml_state *)cache->alloc(sizeof(*drcuml));
548548   if (drcuml == NULL)
549549      return NULL;
550550   memset(drcuml, 0, sizeof(*drcuml));
r10048r10049
597597   jmp_buf errorbuf;
598598
599599   /* flush the cache */
600   drccache_flush(drcuml->cache);
600   drcuml->cache->flush();
601601
602602   /* if we error here, we are screwed */
603603   if (setjmp(errorbuf) != 0)
r10048r10049
946946   char *string;
947947
948948   /* allocate space for a copy of the string */
949   string = (char *)drccache_memory_alloc(drcuml->cache, strlen(name) + 1);
949   string = (char *)drcuml->cache->alloc(strlen(name) + 1);
950950   if (string == NULL)
951951      return NULL;
952952   strcpy(string, name);
953953
954954   /* allocate a new handle info */
955   handle = (drcuml_codehandle *)drccache_memory_alloc_near(drcuml->cache, sizeof(*handle));
955   handle = (drcuml_codehandle *)drcuml->cache->alloc_near(sizeof(*handle));
956956   if (handle == NULL)
957957   {
958      drccache_memory_free(drcuml->cache, string, strlen(name) + 1);
958      drcuml->cache->dealloc(string, strlen(name) + 1);
959959      return NULL;
960960   }
961961   memset(handle, 0, sizeof(*handle));
r10048r10049
11131113   va_end(va);
11141114
11151115   /* allocate space in the cache to hold the comment */
1116   comment = (char *)drccache_memory_alloc_temporary(block->drcuml->cache, strlen(buffer) + 1);
1116   comment = (char *)block->drcuml->cache->alloc_temporary(strlen(buffer) + 1);
11171117   if (comment == NULL)
11181118      return;
11191119   strcpy(comment, buffer);
r10048r10049
12631263            }
12641264
12651265            /* cache memory */
1266            else if (drcuml != NULL && drccache_contains_pointer(drcuml->cache, (void *)(FPTR)param->value))
1267               dest += sprintf(dest, "[+$%X]", (UINT32)(FPTR)((drccodeptr)(FPTR)param->value - drccache_near(drcuml->cache)));
1266            else if (drcuml != NULL && drcuml->cache->contains_pointer((void *)(FPTR)param->value))
1267               dest += sprintf(dest, "[+$%X]", (UINT32)(FPTR)((drccodeptr)(FPTR)param->value - drcuml->cache->near()));
12681268
12691269            /* general memory */
12701270            else
r10048r10049
21812181   int numparams;
21822182
21832183   /* allocate memory for parameters */
2184   parammem = (UINT64 *)drccache_memory_alloc_near(drcuml->cache, sizeof(UINT64) * (ARRAY_LENGTH(test->param) + 1));
2184   parammem = (UINT64 *)drcuml->cache->alloc_near(sizeof(UINT64) * (ARRAY_LENGTH(test->param) + 1));
21852185
21862186   /* flush the cache */
21872187   drcuml_reset(drcuml);
r10048r10049
22372237   bevalidate_verify_state(drcuml, &istate, &fstate, test, *(UINT32 *)&parammem[ARRAY_LENGTH(test->param)], params, &testinst, handles[1]->code, handles[2]->code, flagmask);
22382238
22392239   /* free memory */
2240   drccache_memory_free(drcuml->cache, parammem, sizeof(UINT64) * (ARRAY_LENGTH(test->param) + 1));
2240   drcuml->cache->dealloc(parammem, sizeof(UINT64) * (ARRAY_LENGTH(test->param) + 1));
22412241}
22422242
22432243
src/emu/cpu/drcuml.h
r10048r10049
417417
418418
419419/* typedefs for back-end callback functions */
420typedef drcbe_state *(*drcbe_alloc_func)(drcuml_state *drcuml, drccache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits);
420typedef drcbe_state *(*drcbe_alloc_func)(drcuml_state *drcuml, drc_cache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits);
421421typedef void (*drcbe_free_func)(drcbe_state *state);
422422typedef void (*drcbe_reset_func)(drcbe_state *state);
423423typedef int   (*drcbe_execute_func)(drcbe_state *state, drcuml_codehandle *entry);
r10048r10049
448448/* ----- initialization/teardown ----- */
449449
450450/* allocate state for the code generator and initialize the back-end */
451drcuml_state *drcuml_alloc(device_t *device, drccache *cache, UINT32 flags, int modes, int addrbits, int ignorebits);
451drcuml_state *drcuml_alloc(device_t *device, drc_cache *cache, UINT32 flags, int modes, int addrbits, int ignorebits);
452452
453453/* return information about the back-end */
454454void drcuml_get_backend_info(drcuml_state *drcuml, drcbe_info *info);
src/emu/cpu/drcbex64.c
r10048r10049
264264{
265265   device_t *   device;               /* CPU device we are associated with */
266266   drcuml_state *         drcuml;               /* pointer back to our owner */
267   drccache *            cache;               /* pointer to the cache */
267   drc_cache *            cache;               /* pointer to the cache */
268268   drcuml_machine_state   state;               /* state of the machine */
269   drchash_state *         hash;               /* hash table state */
270   drcmap_state *         map;               /* code map */
271   drclabel_list *         labels;                 /* label list */
269   drc_hash_table *      hash;               /* hash table state */
270   drc_map_variables *      map;               /* code map */
271   drc_label_list *      labels;                 /* label list */
272272
273273   x86_entry_point_func   entry;               /* entry point */
274274   x86code *            exit;               /* exit point */
r10048r10049
307307***************************************************************************/
308308
309309/* primary back-end callbacks */
310static drcbe_state *drcbex64_alloc(drcuml_state *drcuml, drccache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits);
310static drcbe_state *drcbex64_alloc(drcuml_state *drcuml, drc_cache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits);
311311static void drcbex64_free(drcbe_state *drcbe);
312312static void drcbex64_reset(drcbe_state *drcbe);
313313static int drcbex64_execute(drcbe_state *drcbe, drcuml_codehandle *entry);
r10048r10049
686686    state
687687-------------------------------------------------*/
688688
689static drcbe_state *drcbex64_alloc(drcuml_state *drcuml, drccache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits)
689static drcbe_state *drcbex64_alloc(drcuml_state *drcuml, drc_cache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits)
690690{
691691   /* SSE control register mapping */
692692   static const UINT32 sse_control[4] =
r10048r10049
701701   int spacenum;
702702
703703   /* allocate space in the cache for our state */
704   drcbe = (drcbe_state *)drccache_memory_alloc_near(cache, sizeof(*drcbe));
704   drcbe = (drcbe_state *)cache->alloc_near(sizeof(*drcbe));
705705   if (drcbe == NULL)
706706      return NULL;
707707   memset(drcbe, 0, sizeof(*drcbe));
r10048r10049
710710   drcbe->device = device;
711711   drcbe->drcuml = drcuml;
712712   drcbe->cache = cache;
713   drcbe->rbpvalue = drccache_near(cache) + 0x80;
713   drcbe->rbpvalue = cache->near() + 0x80;
714714
715715   /* get address spaces and accessors */
716716   for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
r10048r10049
722722
723723   /* build up necessary arrays */
724724   memcpy(drcbe->ssecontrol, sse_control, sizeof(drcbe->ssecontrol));
725   drcbe->absmask32 = (UINT32 *)drccache_memory_alloc_near(cache, 16*2 + 15);
725   drcbe->absmask32 = (UINT32 *)cache->alloc_near(16*2 + 15);
726726   drcbe->absmask32 = (UINT32 *)(((FPTR)drcbe->absmask32 + 15) & ~15);
727727   drcbe->absmask32[0] = drcbe->absmask32[1] = drcbe->absmask32[2] = drcbe->absmask32[3] = 0x7fffffff;
728728   drcbe->absmask64 = (UINT64 *)&drcbe->absmask32[4];
r10048r10049
737737      drcbe->debug_log_hashjmp = (x86code *)debug_log_hashjmp;
738738      drcbe->debug_log_hashjmp_fail = (x86code *)debug_log_hashjmp_fail;
739739   }
740   drcbe->drcmap_get_value = (x86code *)drcmap_get_value;
740   drcbe->drcmap_get_value = (x86code *)&drc_map_variables::static_get_value;
741741
742742   /* allocate hash tables */
743   drcbe->hash = drchash_alloc(cache, modes, addrbits, ignorebits);
744   if (drcbe->hash == NULL)
745      return NULL;
743   drcbe->hash = auto_alloc(device->machine, drc_hash_table(*cache, modes, addrbits, ignorebits));
746744
747745   /* allocate code map */
748   drcbe->map = drcmap_alloc(cache, 0);
749   if (drcbe->map == NULL)
750      return NULL;
746   drcbe->map = auto_alloc(device->machine, drc_map_variables(*cache, 0));
751747
752748   /* allocate a label tracker */
753   drcbe->labels = drclabel_list_alloc(cache);
754   if (drcbe->labels == NULL)
755      return NULL;
749   drcbe->labels = auto_alloc(device->machine, drc_label_list(*cache));
756750
757751   /* build the opcode table (static but it doesn't hurt to regenerate it) */
758752   for (opnum = 0; opnum < ARRAY_LENGTH(opcode_table_source); opnum++)
r10048r10049
814808      x86log_printf(drcbe->log, "\n\n===========\nCACHE RESET\n===========\n\n");
815809
816810   /* generate a little bit of glue code to set up the environment */
817   dst = (x86code **)drccache_begin_codegen(drcbe->cache, 500);
811   dst = (x86code **)drcbe->cache->begin_codegen(500);
818812   if (dst == NULL)
819813      fatalerror("Out of cache space after a reset!");
820814
r10048r10049
874868      x86log_disasm_code_range(drcbe->log, "nocode", drcbe->nocode, *dst);
875869
876870   /* finish up codegen */
877   drccache_end_codegen(drcbe->cache);
871   drcbe->cache->end_codegen();
878872
879873   /* reset our hash tables */
880   drchash_reset(drcbe->hash);
881   drchash_set_default_codeptr(drcbe->hash, drcbe->nocode);
874   drcbe->hash->reset();
875   drcbe->hash->set_default_codeptr(drcbe->nocode);
882876}
883877
884878
r10048r10049
908902   int inum;
909903
910904   /* tell all of our utility objects that a block is beginning */
911   drchash_block_begin(drcbe->hash, block, instlist, numinst);
912   drclabel_block_begin(drcbe->labels, block);
913   drcmap_block_begin(drcbe->map, block);
905   drcbe->hash->block_begin(*block, instlist, numinst);
906   drcbe->labels->block_begin(*block);
907   drcbe->map->block_begin(*block);
914908
915909   /* begin codegen; fail if we can't */
916   cachetop = drccache_begin_codegen(drcbe->cache, numinst * 8 * 4);
910   cachetop = drcbe->cache->begin_codegen(numinst * 8 * 4);
917911   if (cachetop == NULL)
918912      drcuml_block_abort(block);
919913
r10048r10049
953947
954948   /* complete codegen */
955949   *cachetop = (drccodeptr)dst;
956   drccache_end_codegen(drcbe->cache);
950   drcbe->cache->end_codegen();
957951
958952   /* log it */
959953   if (drcbe->log != NULL)
960      x86log_disasm_code_range(drcbe->log, (blockname == NULL) ? "Unknown block" : blockname, base, drccache_top(drcbe->cache));
954      x86log_disasm_code_range(drcbe->log, (blockname == NULL) ? "Unknown block" : blockname, base, drcbe->cache->top());
961955
962956   /* tell all of our utility objects that the block is finished */
963   drchash_block_end(drcbe->hash, block);
964   drclabel_block_end(drcbe->labels, block);
965   drcmap_block_end(drcbe->map, block);
957   drcbe->hash->block_end(*block);
958   drcbe->labels->block_end(*block);
959   drcbe->map->block_end(*block);
966960}
967961
968962
r10048r10049
973967
974968static int drcbex64_hash_exists(drcbe_state *drcbe, UINT32 mode, UINT32 pc)
975969{
976   return drchash_code_exists(drcbe->hash, mode, pc);
970   return drcbe->hash->code_exists(mode, pc);
977971}
978972
979973
r10048r10049
30493043   assert(inst->param[1].type == DRCUML_PTYPE_IMMEDIATE);
30503044
30513045   /* register the current pointer for the mode/PC */
3052   drchash_set_codeptr(drcbe->hash, inst->param[0].value, inst->param[1].value, dst);
3046   drcbe->hash->set_codeptr(inst->param[0].value, inst->param[1].value, dst);
30533047   return dst;
30543048}
30553049
r10048r10049
30663060   assert(inst->param[0].type == DRCUML_PTYPE_IMMEDIATE);
30673061
30683062   /* register the current pointer for the label */
3069   drclabel_set_codeptr(drcbe->labels, inst->param[0].value, dst);
3063   drcbe->labels->set_codeptr(inst->param[0].value, dst);
30703064   return dst;
30713065}
30723066
r10048r10049
31003094   assert(inst->param[1].type == DRCUML_PTYPE_IMMEDIATE);
31013095
31023096   /* set the value of the specified mapvar */
3103   drcmap_set_value(drcbe->map, dst, inst->param[0].value, inst->param[1].value);
3097   drcbe->map->set_value(dst, inst->param[0].value, inst->param[1].value);
31043098   return dst;
31053099}
31063100
r10048r10049
32123206   emit_mov_r64_m64(&dst, REG_RSP, MABS(drcbe, &drcbe->hashstacksave));            // mov   rsp,[hashstacksave]
32133207
32143208   /* fixed mode cases */
3215   if (modep.type == DRCUML_PTYPE_IMMEDIATE && drcbe->hash->base[modep.value] != drcbe->hash->emptyl1)
3209   if (modep.type == DRCUML_PTYPE_IMMEDIATE && drcbe->hash->is_mode_populated(modep.value))
32163210   {
32173211      /* a straight immediate jump is direct, though we need the PC in EAX in case of failure */
32183212      if (pcp.type == DRCUML_PTYPE_IMMEDIATE)
32193213      {
3220         UINT32 l1val = (pcp.value >> drcbe->hash->l1shift) & drcbe->hash->l1mask;
3221         UINT32 l2val = (pcp.value >> drcbe->hash->l2shift) & drcbe->hash->l2mask;
3222         emit_call_m64(&dst, MABS(drcbe, &drcbe->hash->base[modep.value][l1val][l2val]));
3214         UINT32 l1val = (pcp.value >> drcbe->hash->l1shift()) & drcbe->hash->l1mask();
3215         UINT32 l2val = (pcp.value >> drcbe->hash->l2shift()) & drcbe->hash->l2mask();
3216         emit_call_m64(&dst, MABS(drcbe, &drcbe->hash->base()[modep.value][l1val][l2val]));
32233217                                                                  // call  hash[modep][l1val][l2val]
32243218      }
32253219
r10048r10049
32283222      {
32293223         emit_mov_r32_p32(drcbe, &dst, REG_EAX, &pcp);                        // mov   eax,pcp
32303224         emit_mov_r32_r32(&dst, REG_EDX, REG_EAX);                           // mov   edx,eax
3231         emit_shr_r32_imm(&dst, REG_EDX, drcbe->hash->l1shift);                  // shr   edx,l1shift
3232         emit_and_r32_imm(&dst, REG_EAX, drcbe->hash->l2mask << drcbe->hash->l2shift);// and  eax,l2mask << l2shift
3233         emit_mov_r64_m64(&dst, REG_RDX, MBISD(REG_RBP, REG_RDX, 8, offset_from_rbp(drcbe, (FPTR)&drcbe->hash->base[modep.value][0])));
3225         emit_shr_r32_imm(&dst, REG_EDX, drcbe->hash->l1shift());               // shr   edx,l1shift
3226         emit_and_r32_imm(&dst, REG_EAX, drcbe->hash->l2mask() << drcbe->hash->l2shift());// and  eax,l2mask << l2shift
3227         emit_mov_r64_m64(&dst, REG_RDX, MBISD(REG_RBP, REG_RDX, 8, offset_from_rbp(drcbe, (FPTR)&drcbe->hash->base()[modep.value][0])));
32343228                                                                  // mov   rdx,hash[modep+edx*8]
3235         emit_call_m64(&dst, MBISD(REG_RDX, REG_RAX, 8 >> drcbe->hash->l2shift, 0));   // call  [rdx+rax*shift]
3229         emit_call_m64(&dst, MBISD(REG_RDX, REG_RAX, 8 >> drcbe->hash->l2shift(), 0));// call  [rdx+rax*shift]
32363230      }
32373231   }
32383232   else
r10048r10049
32403234      /* variable mode */
32413235      int modereg = param_select_register(REG_ECX, &modep, NULL);
32423236      emit_mov_r32_p32(drcbe, &dst, modereg, &modep);                           // mov   modereg,modep
3243      emit_mov_r64_m64(&dst, REG_RCX, MBISD(REG_RBP, modereg, 8, offset_from_rbp(drcbe, (FPTR)&drcbe->hash->base[0])));
3237      emit_mov_r64_m64(&dst, REG_RCX, MBISD(REG_RBP, modereg, 8, offset_from_rbp(drcbe, (FPTR)drcbe->hash->base())));
32443238                                                                  // mov   rcx,hash[modereg*8]
32453239
32463240      /* fixed PC */
32473241      if (pcp.type == DRCUML_PTYPE_IMMEDIATE)
32483242      {
3249         UINT32 l1val = (pcp.value >> drcbe->hash->l1shift) & drcbe->hash->l1mask;
3250         UINT32 l2val = (pcp.value >> drcbe->hash->l2shift) & drcbe->hash->l2mask;
3243         UINT32 l1val = (pcp.value >> drcbe->hash->l1shift()) & drcbe->hash->l1mask();
3244         UINT32 l2val = (pcp.value >> drcbe->hash->l2shift()) & drcbe->hash->l2mask();
32513245         emit_mov_r64_m64(&dst, REG_RDX, MBD(REG_RCX, l1val*8));                  // mov   rdx,[rcx+l1val*8]
32523246         emit_call_m64(&dst, MBD(REG_RDX, l2val*8));                           // call  [l2val*8]
32533247      }
r10048r10049
32573251      {
32583252         emit_mov_r32_p32(drcbe, &dst, REG_EAX, &pcp);                        // mov   eax,pcp
32593253         emit_mov_r32_r32(&dst, REG_EDX, REG_EAX);                           // mov   edx,eax
3260         emit_shr_r32_imm(&dst, REG_EDX, drcbe->hash->l1shift);                  // shr   edx,l1shift
3254         emit_shr_r32_imm(&dst, REG_EDX, drcbe->hash->l1shift());                  // shr   edx,l1shift
32613255         emit_mov_r64_m64(&dst, REG_RDX, MBISD(REG_RCX, REG_RDX, 8, 0));            // mov   rdx,[rcx+rdx*8]
3262         emit_and_r32_imm(&dst, REG_EAX, drcbe->hash->l2mask << drcbe->hash->l2shift);// and  eax,l2mask << l2shift
3263         emit_call_m64(&dst, MBISD(REG_RDX, REG_RAX, 8 >> drcbe->hash->l2shift, 0));   // call  [rdx+rax*shift]
3256         emit_and_r32_imm(&dst, REG_EAX, drcbe->hash->l2mask() << drcbe->hash->l2shift());// and  eax,l2mask << l2shift
3257         emit_call_m64(&dst, MBISD(REG_RDX, REG_RAX, 8 >> drcbe->hash->l2shift(), 0));   // call  [rdx+rax*shift]
32643258      }
32653259   }
32663260
r10048r10049
32943288   param_normalize_1(drcbe, inst, &labelp, PTYPE_I);
32953289
32963290   /* look up the jump target and jump there */
3297   jmptarget = (x86code *)drclabel_get_codeptr(drcbe->labels, labelp.value, fixup_label, dst);
3291   jmptarget = (x86code *)drcbe->labels->get_codeptr(labelp.value, fixup_label, dst);
32983292   if (jmptarget == NULL)
32993293      jmptarget = dst + 0x7ffffff0;
33003294   if (inst->condition == DRCUML_COND_ALWAYS)
r10048r10049
33403334   else
33413335   {
33423336      emit_jcc(&dst, X86_CONDITION(inst->condition), dst + 0x7ffffff0);            // jcc   exception
3343      drccache_request_oob_codegen(drcbe->cache, fixup_exception, drcbe, dst, (void *)inst);
3337      drcbe->cache->request_oob_codegen(fixup_exception, drcbe, dst, (void *)inst);
33443338   }
33453339   return dst;
33463340}
src/emu/cpu/drcbec.c
r10048r10049
215215   device_t *   device;               /* CPU device we are associated with */
216216   address_space *   space[ADDRESS_SPACES];   /* pointers to CPU's address space */
217217   drcuml_state *         drcuml;               /* pointer back to our owner */
218   drccache *            cache;               /* pointer to the cache */
218   drc_cache *            cache;               /* pointer to the cache */
219219   drcuml_machine_state   state;               /* state of the machine */
220   drchash_state *         hash;               /* hash table state */
221   drcmap_state *         map;               /* code map */
222   drclabel_list *         labels;                 /* label list */
220   drc_hash_table *      hash;               /* hash table state */
221   drc_map_variables *      map;               /* code map */
222   drc_label_list *      labels;                 /* label list */
223223};
224224
225225
r10048r10049
254254***************************************************************************/
255255
256256/* primary back-end callbacks */
257static drcbe_state *drcbec_alloc(drcuml_state *drcuml, drccache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits);
257static drcbe_state *drcbec_alloc(drcuml_state *drcuml, drc_cache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits);
258258static void drcbec_free(drcbe_state *drcbe);
259259static void drcbec_reset(drcbe_state *drcbe);
260260static int drcbec_execute(drcbe_state *state, drcuml_codehandle *entry);
r10048r10049
340340    state
341341-------------------------------------------------*/
342342
343static drcbe_state *drcbec_alloc(drcuml_state *drcuml, drccache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits)
343static drcbe_state *drcbec_alloc(drcuml_state *drcuml, drc_cache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits)
344344{
345345   int spacenum;
346346
347347   /* allocate space in the cache for our state */
348   drcbe_state *drcbe = (drcbe_state *)drccache_memory_alloc(cache, sizeof(*drcbe));
348   drcbe_state *drcbe = (drcbe_state *)cache->alloc(sizeof(*drcbe));
349349   if (drcbe == NULL)
350350      return NULL;
351351   memset(drcbe, 0, sizeof(*drcbe));
r10048r10049
358358   drcbe->cache = cache;
359359
360360   /* allocate hash tables */
361   drcbe->hash = drchash_alloc(cache, modes, addrbits, ignorebits);
362   if (drcbe->hash == NULL)
363      return NULL;
361   drcbe->hash = auto_alloc(device->machine, drc_hash_table(*cache, modes, addrbits, ignorebits));
364362
365363   /* allocate code map */
366   drcbe->map = drcmap_alloc(cache, 0);
367   if (drcbe->map == NULL)
368      return NULL;
364   drcbe->map = auto_alloc(device->machine, drc_map_variables(*cache, 0));
369365
370366   /* allocate a label tracker */
371   drcbe->labels = drclabel_list_alloc(cache);
372   if (drcbe->labels == NULL)
373      return NULL;
367   drcbe->labels = auto_alloc(device->machine, drc_label_list(*cache));
374368
375369   return drcbe;
376370}
r10048r10049
392386static void drcbec_reset(drcbe_state *drcbe)
393387{
394388   /* reset our hash tables */
395   drchash_reset(drcbe->hash);
396   drchash_set_default_codeptr(drcbe->hash, NULL);
389   drcbe->hash->reset();
390   drcbe->hash->set_default_codeptr(NULL);
397391}
398392
399393
r10048r10049
409403   int inum;
410404
411405   /* tell all of our utility objects that a block is beginning */
412   drchash_block_begin(drcbe->hash, block, instlist, numinst);
413   drclabel_block_begin(drcbe->labels, block);
414   drcmap_block_begin(drcbe->map, block);
406   drcbe->hash->block_begin(*block, instlist, numinst);
407   drcbe->labels->block_begin(*block);
408   drcbe->map->block_begin(*block);
415409
416410   /* begin codegen; fail if we can't */
417   cachetop = drccache_begin_codegen(drcbe->cache, numinst * sizeof(drcbec_instruction) * 4);
411   cachetop = drcbe->cache->begin_codegen(numinst * sizeof(drcbec_instruction) * 4);
418412   if (cachetop == NULL)
419413      drcuml_block_abort(block);
420414
r10048r10049
445439         /* when we hit a HASH opcode, register the current pointer for the mode/PC */
446440         case DRCUML_OP_HASH:
447441            /* we already verified the parameter count and types above */
448            drchash_set_codeptr(drcbe->hash, inst->param[0].value, inst->param[1].value, (drccodeptr)dst);
442            drcbe->hash->set_codeptr(inst->param[0].value, inst->param[1].value, (drccodeptr)dst);
449443            break;
450444
451445         /* when we hit a LABEL opcode, register the current pointer for the label */
452446         case DRCUML_OP_LABEL:
453447            assert(inst->numparams == 1);
454448            assert(inst->param[0].type == DRCUML_PTYPE_IMMEDIATE);
455            drclabel_set_codeptr(drcbe->labels, inst->param[0].value, (drccodeptr)dst);
449            drcbe->labels->set_codeptr(inst->param[0].value, (drccodeptr)dst);
456450            break;
457451
458452         /* ignore COMMENT and NOP opcodes */
r10048r10049
465459            assert(inst->numparams == 2);
466460            assert(inst->param[0].type == DRCUML_PTYPE_MAPVAR);
467461            assert(inst->param[1].type == DRCUML_PTYPE_IMMEDIATE);
468            drcmap_set_value(drcbe->map, (drccodeptr)dst, inst->param[0].value, inst->param[1].value);
462            drcbe->map->set_value((drccodeptr)dst, inst->param[0].value, inst->param[1].value);
469463            break;
470464
471465         /* JMP instructions need to resolve their labels */
r10048r10049
473467            assert(inst->numparams == 1);
474468            assert(inst->param[0].type == DRCUML_PTYPE_IMMEDIATE);
475469            (dst++)->i = MAKE_OPCODE_FULL(opcode, inst->size, inst->condition, inst->flags, 1);
476            dst->inst = (drcbec_instruction *)drclabel_get_codeptr(drcbe->labels, inst->param[0].value, fixup_label, dst);
470            dst->inst = (drcbec_instruction *)drcbe->labels->get_codeptr(inst->param[0].value, fixup_label, dst);
477471            dst++;
478472            break;
479473
r10048r10049
559553
560554   /* complete codegen */
561555   *cachetop = (drccodeptr)dst;
562   drccache_end_codegen(drcbe->cache);
556   drcbe->cache->end_codegen();
563557
564558   /* tell all of our utility objects that the block is finished */
565   drchash_block_end(drcbe->hash, block);
566   drclabel_block_end(drcbe->labels, block);
567   drcmap_block_end(drcbe->map, block);
559   drcbe->hash->block_end(*block);
560   drcbe->labels->block_end(*block);
561   drcbe->map->block_end(*block);
568562}
569563
570564
r10048r10049
575569
576570static int drcbec_hash_exists(drcbe_state *state, UINT32 mode, UINT32 pc)
577571{
578   return drchash_code_exists(state->hash, mode, pc);
572   return state->hash->code_exists(mode, pc);
579573}
580574
581575
r10048r10049
641635
642636         case MAKE_OPCODE_SHORT(DRCUML_OP_HASHJMP, 4, 0):   /* HASHJMP mode,pc,handle         */
643637            sp = 0;
644            newinst = (const drcbec_instruction *)drchash_get_codeptr(drcbe->hash, PARAM0, PARAM1);
638            newinst = (const drcbec_instruction *)drcbe->hash->get_codeptr(PARAM0, PARAM1);
645639            if (newinst == NULL)
646640            {
647641               assert(sp < ARRAY_LENGTH(callstack));
r10048r10049
722716
723717         case MAKE_OPCODE_SHORT(DRCUML_OP_RECOVER, 4, 0):   /* RECOVER dst,mapvar             */
724718            assert(sp > 0);
725            PARAM0 = drcmap_get_value(drcbe->map, (drccodeptr)callstack[0], PARAM1);
719            PARAM0 = drcbe->map->get_value((drccodeptr)callstack[0], PARAM1);
726720            break;
727721
728722
r10048r10049
21892183   {
21902184      /* convert mapvars to immediates */
21912185      case DRCUML_PTYPE_MAPVAR:
2192         temp_param.value = drcmap_get_last_value(drcbe->map, param->value);
2186         temp_param.value = drcbe->map->get_last_value(param->value);
21932187         param = &temp_param;
21942188         /* fall through to immediate case */
21952189
src/emu/cpu/rsp/rspdrc.c
r10048r10049
104104struct _rspimp_state
105105{
106106   /* core state */
107   drccache *         cache;                  /* pointer to the DRC code cache */
107   drc_cache *         cache;                  /* pointer to the DRC code cache */
108108   drcuml_state *      drcuml;                  /* DRC UML generator state */
109109   rsp_frontend *      drcfe;                  /* pointer to the DRC front-end state */
110110   UINT32            drcoptions;               /* configurable DRC options */
r10048r10049
604604static CPU_INIT( rsp )
605605{
606606   rsp_state *rsp;
607   drccache *cache;
607   drc_cache *cache;
608608   UINT32 flags = 0;
609609   int regnum;
610610   //int elnum;
611611
612612   /* allocate enough space for the cache and the core */
613   cache = (drccache *)drccache_alloc(CACHE_SIZE + sizeof(*rsp));
614   if (cache == NULL)
615   {
616      fatalerror("Unable to allocate cache of size %d", (UINT32)(CACHE_SIZE + sizeof(*rsp)));
617   }
613   cache = auto_alloc(device->machine, drc_cache(CACHE_SIZE + sizeof(*rsp)));
618614
619615   /* allocate the core memory */
620   *(rsp_state **)device->token() = rsp = (rsp_state *)drccache_memory_alloc_near(cache, sizeof(*rsp));
616   *(rsp_state **)device->token() = rsp = (rsp_state *)cache->alloc_near(sizeof(*rsp));
621617   memset(rsp, 0, sizeof(*rsp));
622618
623619   rspcom_init(rsp, device, irqcallback);
624620
625621   /* allocate the implementation-specific state from the full cache */
626   rsp->impstate = (rspimp_state *)drccache_memory_alloc_near(cache, sizeof(*rsp->impstate));
622   rsp->impstate = (rspimp_state *)cache->alloc_near(sizeof(*rsp->impstate));
627623   memset(rsp->impstate, 0, sizeof(*rsp->impstate));
628624   rsp->impstate->cache = cache;
629625
r10048r10049
712708   /* clean up the DRC */
713709   auto_free(device->machine, rsp->impstate->drcfe);
714710   drcuml_free(rsp->impstate->drcuml);
715   drccache_free(rsp->impstate->cache);
711   auto_free(device->machine, rsp->impstate->cache);
716712}
717713
718714
src/emu/cpu/drccache.c
r10048r10049
11/***************************************************************************
22
3    drccache.h
3    drccache.c
44
55    Universal dynamic recompiler cache management.
66
7****************************************************************************
8
79    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.
1011
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:
1215
13#include "emu.h"
14#include "drccache.h"
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.
1525
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.
1637
17
18/***************************************************************************
19    CONSTANTS
2038***************************************************************************/
2139
22/* largest block of code that can be generated at once */
23#define CODEGEN_MAX_BYTES      65536
40#include "emu.h"
41#include "drccache.h"
2442
25/* minimum alignment, in bytes (must be power of 2) */
26#define CACHE_ALIGNMENT         8
2743
28/* largest permanent allocation we allow */
29#define MAX_PERMANENT_ALLOC      1024
3044
31/* size of "near" area at the base of the cache */
32#define NEAR_CACHE_SIZE         65536
45//**************************************************************************
46//  MACROS
47//**************************************************************************
3348
34
35
36/***************************************************************************
37    MACROS
38***************************************************************************/
39
40/* ensure that all memory allocated is aligned to an 8-byte boundary */
49// ensure that all memory allocated is aligned to an 8-byte boundary
4150#define ALIGN_PTR_UP(p)         ((void *)(((FPTR)(p) + (CACHE_ALIGNMENT - 1)) & ~(CACHE_ALIGNMENT - 1)))
4251#define ALIGN_PTR_DOWN(p)      ((void *)((FPTR)(p) & ~(CACHE_ALIGNMENT - 1)))
4352
4453
4554
46/***************************************************************************
47    TYPE DEFINITIONS
48***************************************************************************/
55//**************************************************************************
56//  DRC CACHE
57//**************************************************************************
4958
50/* out-of-bounds codegen handlers */
51typedef struct _oob_handler oob_handler;
52struct _oob_handler
53{
54   oob_handler *      next;            /* next handler */
55   drccache_oob_func   callback;         /* callback function */
56   void *            param1;            /* 1st pointer parameter */
57   void *            param2;            /* 2nd pointer parameter */
58   void *            param3;            /* 3rd pointer parameter */
59};
59//-------------------------------------------------
60//  drc_cache - constructor
61//-------------------------------------------------
6062
61
62/* a linked list of free items */
63typedef struct _free_link free_link;
64struct _free_link
63drc_cache::drc_cache(size_t bytes)
64   : m_near((drccodeptr)osd_alloc_executable(bytes)),
65     m_neartop(m_near),
66     m_base(m_near + NEAR_CACHE_SIZE),
67     m_top(m_base),
68     m_end(m_near + bytes),
69     m_codegen(0),
70     m_size(bytes)
6571{
66   free_link *         next;            /* pointer to the next guy */
67};
68
69
70/* cache state */
71struct _drccache
72{
73   /* core parameters */
74   drccodeptr         near;            /* pointer to the near part of the cache */
75   drccodeptr         neartop;         /* top of the near part of the cache */
76   drccodeptr         base;            /* base pointer to the compiler cache */
77   drccodeptr         top;            /* current top of cache */
78   drccodeptr         end;            /* end of cache memory */
79   drccodeptr         codegen;         /* start of generated code */
80   size_t            size;            /* size of the cache in bytes */
81
82   /* oob management */
83   oob_handler *      ooblist;         /* list of oob handlers */
84   oob_handler **      oobtail;         /* pointer to tail oob pointer */
85
86   /* free lists */
87   free_link *         free[MAX_PERMANENT_ALLOC / CACHE_ALIGNMENT];
88   free_link *         nearfree[MAX_PERMANENT_ALLOC / CACHE_ALIGNMENT];
89};
90
91
92
93/***************************************************************************
94    INITIALIZATION/TEARDOWN
95***************************************************************************/
96
97/*-------------------------------------------------
98    drccache_alloc - allocate the cache itself
99-------------------------------------------------*/
100
101drccache *drccache_alloc(size_t bytes)
102{
103   drccache cache, *cacheptr;
104
105   assert(bytes >= sizeof(cache) + NEAR_CACHE_SIZE);
106
107   /* build a local structure first */
108   memset(&cache, 0, sizeof(cache));
109   cache.near = (drccodeptr)osd_alloc_executable(bytes);
110   cache.neartop = cache.near;
111   cache.base = cache.near + NEAR_CACHE_SIZE;
112   cache.top = cache.base;
113   cache.end = cache.near + bytes;
114   cache.size = bytes;
115
116   /* now allocate the cache structure itself from that */
117   cacheptr = (drccache *)drccache_memory_alloc(&cache, sizeof(cache));
118   *cacheptr = cache;
119
120   /* return the allocated result */
121   return cacheptr;
72   memset(m_free, 0, sizeof(m_free));
73   memset(m_nearfree, 0, sizeof(m_nearfree));
12274}
12375
12476
125/*-------------------------------------------------
126    drccache_free - free the cache
127-------------------------------------------------*/
77//-------------------------------------------------
78//  ~drc_cache - destructor
79//-------------------------------------------------
12880
129void drccache_free(drccache *cache)
81drc_cache::~drc_cache()
13082{
131   /* release the memory; this includes the cache object itself */
132   osd_free_executable(cache->near, cache->size);
83   // release the memory
84   osd_free_executable(m_near, m_size);
13385}
13486
13587
13688
137/***************************************************************************
138    CACHE INFORMATION
139***************************************************************************/
89//-------------------------------------------------
90//  flush - flush the cache contents
91//-------------------------------------------------
14092
141/*-------------------------------------------------
142    drccache_contains_pointer - return true if a
143    pointer is within the cache
144-------------------------------------------------*/
145
146int drccache_contains_pointer(drccache *cache, const void *ptr)
93void drc_cache::flush()
14794{
148   return ((const drccodeptr)ptr >= cache->near && (const drccodeptr)ptr < cache->near + cache->size);
149}
95   // can't flush in the middle of codegen
96   assert(m_codegen == NULL);
15097
151
152/*-------------------------------------------------
153    drccache_contains_near_pointer - return true
154    if a pointer is within the cache
155-------------------------------------------------*/
156
157int drccache_contains_near_pointer(drccache *cache, const void *ptr)
158{
159   return ((const drccodeptr)ptr >= cache->near && (const drccodeptr)ptr < cache->neartop);
98   // just reset the top back to the base and re-seed
99   m_top = m_base;
160100}
161101
162102
163/*-------------------------------------------------
164    drccache_near - return a pointer to the near
165    part of the cache
166-------------------------------------------------*/
103//-------------------------------------------------
104//  alloc - allocate permanent memory from the
105//  cache
106//-------------------------------------------------
167107
168drccodeptr drccache_near(drccache *cache)
108void *drc_cache::alloc(size_t bytes)
169109{
170   return cache->near;
171}
172
173
174/*-------------------------------------------------
175    drccache_base - return a pointer to the base
176    of the cache
177-------------------------------------------------*/
178
179drccodeptr drccache_base(drccache *cache)
180{
181   return cache->base;
182}
183
184
185/*-------------------------------------------------
186    drccache_top - return the current top of the
187    cache
188-------------------------------------------------*/
189
190drccodeptr drccache_top(drccache *cache)
191{
192   return cache->top;
193}
194
195
196
197/***************************************************************************
198    MEMORY MANAGEMENT
199***************************************************************************/
200
201/*-------------------------------------------------
202    drccache_flush - flush the cache contents
203-------------------------------------------------*/
204
205void drccache_flush(drccache *cache)
206{
207   /* can't flush in the middle of codegen */
208   assert(cache->codegen == NULL);
209
210   /* just reset the top back to the base and re-seed */
211   cache->top = cache->base;
212}
213
214
215/*-------------------------------------------------
216    drccache_memory_alloc - allocate permanent
217    memory from the cache
218-------------------------------------------------*/
219
220void *drccache_memory_alloc(drccache *cache, size_t bytes)
221{
222   drccodeptr ptr;
223
224110   assert(bytes > 0);
225111
226   /* pick first from the free list */
112   // pick first from the free list
227113   if (bytes < MAX_PERMANENT_ALLOC)
228114   {
229      free_link **linkptr = &cache->free[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
115      free_link **linkptr = &m_free[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
230116      free_link *link = *linkptr;
231117      if (link != NULL)
232118      {
233         *linkptr = link->next;
119         *linkptr = link->m_next;
234120         return link;
235121      }
236122   }
237123
238   /* if no space, we just fail */
239   ptr = (drccodeptr)ALIGN_PTR_DOWN(cache->end - bytes);
240   if (cache->top > ptr)
124   // if no space, we just fail
125   drccodeptr ptr = (drccodeptr)ALIGN_PTR_DOWN(m_end - bytes);
126   if (m_top > ptr)
241127      return NULL;
242128
243   /* otherwise update the end of the cache */
244   cache->end = ptr;
129   // otherwise update the end of the cache
130   m_end = ptr;
245131   return ptr;
246132}
247133
248134
249/*-------------------------------------------------
250    drccache_memory_alloc_near - allocate
251    permanent memory from the near part of the
252    cache
253-------------------------------------------------*/
135//-------------------------------------------------
136//  alloc_near - allocate permanent memory from
137//  the near part of the cache
138//-------------------------------------------------
254139
255void *drccache_memory_alloc_near(drccache *cache, size_t bytes)
140void *drc_cache::alloc_near(size_t bytes)
256141{
257   drccodeptr ptr;
258
259142   assert(bytes > 0);
260143
261   /* pick first from the free list */
144   // pick first from the free list
262145   if (bytes < MAX_PERMANENT_ALLOC)
263146   {
264      free_link **linkptr = &cache->nearfree[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
147      free_link **linkptr = &m_nearfree[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
265148      free_link *link = *linkptr;
266149      if (link != NULL)
267150      {
268         *linkptr = link->next;
151         *linkptr = link->m_next;
269152         return link;
270153      }
271154   }
272155
273   /* if no space, we just fail */
274   ptr = (drccodeptr)ALIGN_PTR_UP(cache->neartop);
275   if (ptr + bytes > cache->base)
156   // if no space, we just fail
157   drccodeptr ptr = (drccodeptr)ALIGN_PTR_UP(m_neartop);
158   if (ptr + bytes > m_base)
276159      return NULL;
277160
278   /* otherwise update the top of the near part of the cache */
279   cache->neartop = ptr + bytes;
161   // otherwise update the top of the near part of the cache
162   m_neartop = ptr + bytes;
280163   return ptr;
281164}
282165
283166
284/*-------------------------------------------------
285    drccache_memory_free - release permanent
286    memory allocated from the cache
287-------------------------------------------------*/
167//-------------------------------------------------
168//  alloc_temporary - allocate temporary memory
169//  from the cache
170//-------------------------------------------------
288171
289void drccache_memory_free(drccache *cache, void *memory, size_t bytes)
172void *drc_cache::alloc_temporary(size_t bytes)
290173{
291   free_link **linkptr;
292   free_link *link = (free_link *)memory;
174   // can't allocate in the middle of codegen
175   assert(m_codegen == NULL);
293176
294   assert(bytes < MAX_PERMANENT_ALLOC);
295   assert(((drccodeptr)memory >= cache->near && (drccodeptr)memory < cache->base) || ((drccodeptr)memory >= cache->end && (drccodeptr)memory < cache->near + cache->size));
177   // if no space, we just fail
178   drccodeptr ptr = m_top;
179   if (ptr + bytes >= m_end)
180      return NULL;
296181
297   /* determine which free list to add to */
298   if ((drccodeptr)memory < cache->base)
299      linkptr = &cache->nearfree[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
300   else
301      linkptr = &cache->free[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
302
303   /* link is into the free list for our size */
304   link->next = *linkptr;
305   *linkptr = link;
182   // otherwise, update the cache top
183   m_top = (drccodeptr)ALIGN_PTR_UP(ptr + bytes);
184   return ptr;
306185}
307186
308187
309/*-------------------------------------------------
310    drccache_memory_alloc_temporary - allocate
311    temporary memory from the cache
312-------------------------------------------------*/
188//-------------------------------------------------
189//  free - release permanent memory allocated from
190//  the cache
191//-------------------------------------------------
313192
314void *drccache_memory_alloc_temporary(drccache *cache, size_t bytes)
193void drc_cache::dealloc(void *memory, size_t bytes)
315194{
316   drccodeptr ptr = cache->top;
195   assert(bytes < MAX_PERMANENT_ALLOC);
196   assert(((drccodeptr)memory >= m_near && (drccodeptr)memory < m_base) || ((drccodeptr)memory >= m_end && (drccodeptr)memory < m_near + m_size));
317197
318   /* can't allocate in the middle of codegen */
319   assert(cache->codegen == NULL);
198   // determine which free list to add to
199   free_link **linkptr;
200   if ((drccodeptr)memory < m_base)
201      linkptr = &m_nearfree[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
202   else
203      linkptr = &m_free[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
320204
321   /* if no space, we just fail */
322   if (ptr + bytes >= cache->end)
323      return NULL;
324
325   /* otherwise, update the cache top */
326   cache->top = (drccodeptr)ALIGN_PTR_UP(ptr + bytes);
327   return ptr;
205   // link is into the free list for our size
206   free_link *link = (free_link *)memory;
207   link->m_next = *linkptr;
208   *linkptr = link;
328209}
329210
330211
212//-------------------------------------------------
213//  begin_codegen - begin code generation
214//-------------------------------------------------
331215
332/***************************************************************************
333    CODE GENERATION
334***************************************************************************/
335
336/*-------------------------------------------------
337    drccache_begin_codegen - begin code
338    generation
339-------------------------------------------------*/
340
341drccodeptr *drccache_begin_codegen(drccache *cache, UINT32 reserve_bytes)
216drccodeptr *drc_cache::begin_codegen(UINT32 reserve_bytes)
342217{
343   drccodeptr ptr = cache->top;
218   // can't restart in the middle of codegen
219   assert(m_codegen == NULL);
220   assert(m_ooblist.first() == NULL);
344221
345   /* can't restart in the middle of codegen */
346   assert(cache->codegen == NULL);
347   assert(cache->ooblist == NULL);
348
349   /* if still no space, we just fail */
350   if (ptr + reserve_bytes >= cache->end)
222   // if still no space, we just fail
223   drccodeptr ptr = m_top;
224   if (ptr + reserve_bytes >= m_end)
351225      return NULL;
352226
353   /* otherwise, return a pointer to the cache top */
354   cache->codegen = cache->top;
355   cache->oobtail = &cache->ooblist;
356   return &cache->top;
227   // otherwise, return a pointer to the cache top
228   m_codegen = m_top;
229   return &m_top;
357230}
358231
359232
360/*-------------------------------------------------
361    drccache_end_codegen - complete code
362    generation
363-------------------------------------------------*/
233//-------------------------------------------------
234//  end_codegen - complete code generation
235//-------------------------------------------------
364236
365drccodeptr drccache_end_codegen(drccache *cache)
237drccodeptr drc_cache::end_codegen()
366238{
367   drccodeptr result = cache->codegen;
239   drccodeptr result = m_codegen;
368240
369   /* run the OOB handlers */
370   while (cache->ooblist != NULL)
241   // run the OOB handlers
242   oob_handler *oob;
243   while ((oob = m_ooblist.detach_head()) != NULL)
371244   {
372      /* remove us from the list */
373      oob_handler *oob = cache->ooblist;
374      cache->ooblist = oob->next;
245      // call the callback
246      (*oob->m_callback)(&m_top, oob->m_param1, oob->m_param2, oob->m_param3);
247      assert(m_top - m_codegen < CODEGEN_MAX_BYTES);
375248
376      /* call the callback */
377      (*oob->callback)(&cache->top, oob->param1, oob->param2, oob->param3);
378      assert(cache->top - cache->codegen < CODEGEN_MAX_BYTES);
379
380      /* release our memory */
381      drccache_memory_free(cache, oob, sizeof(*oob));
249      // release our memory
250      dealloc(oob, sizeof(*oob));
382251   }
383252
384   /* update the cache top */
385   cache->top = (drccodeptr)ALIGN_PTR_UP(cache->top);
386   cache->codegen = NULL;
253   // update the cache top
254   m_top = (drccodeptr)ALIGN_PTR_UP(m_top);
255   m_codegen = NULL;
387256
388257   return result;
389258}
390259
391260
392/*-------------------------------------------------
393    drccache_request_oob_codegen - request
394    callback for out-of-band codegen
395-------------------------------------------------*/
261//-------------------------------------------------
262//  request_oob_codegen - request callback for
263//  out-of-band codegen
264//-------------------------------------------------
396265
397void drccache_request_oob_codegen(drccache *cache, drccache_oob_func callback, void *param1, void *param2, void *param3)
266void drc_cache::request_oob_codegen(oob_func callback, void *param1, void *param2, void *param3)
398267{
399   oob_handler *oob;
268   assert(m_codegen != NULL);
400269
401   assert(cache->codegen != NULL);
402
403   /* pull an item from the free list */
404   oob = (oob_handler *)drccache_memory_alloc(cache, sizeof(*oob));
270   // pull an item from the free list
271   oob_handler *oob = (oob_handler *)alloc(sizeof(*oob));
405272   assert(oob != NULL);
406273
407   /* fill it in */
408   oob->next = NULL;
409   oob->callback = callback;
410   oob->param1 = param1;
411   oob->param2 = param2;
412   oob->param3 = param3;
274   // fill it in
275   oob->m_callback = callback;
276   oob->m_param1 = param1;
277   oob->m_param2 = param2;
278   oob->m_param3 = param3;
413279
414   /* add to the tail */
415   *cache->oobtail = oob;
416   cache->oobtail = &oob->next;
280   // add to the tail
281   m_ooblist.append(*oob);
417282}
src/emu/cpu/powerpc/ppcdrc.c
r10048r10049
163163struct _ppcimp_state
164164{
165165   /* core state */
166   drccache *         cache;                  /* pointer to the DRC code cache */
166   drc_cache *         cache;                  /* pointer to the DRC code cache */
167167   drcuml_state *      drcuml;                  /* DRC UML generator state */
168168   ppc_frontend *      drcfe;                  /* pointer to the DRC front-end state */
169169   UINT32            drcoptions;               /* configurable DRC options */
r10048r10049
551551   powerpc_state *ppc;
552552   drcbe_info beinfo;
553553   UINT32 flags = 0;
554   drccache *cache;
554   drc_cache *cache;
555555   int regnum;
556556
557557   /* allocate enough space for the cache and the core */
558   cache = drccache_alloc(CACHE_SIZE + sizeof(*ppc));
559   if (cache == NULL)
560      fatalerror("Unable to allocate cache of size %d", (UINT32)(CACHE_SIZE + sizeof(*ppc)));
558   cache = auto_alloc(device->machine, drc_cache(CACHE_SIZE + sizeof(*ppc)));
561559
562560   /* allocate the core from the near cache */
563   *(powerpc_state **)device->token() = ppc = (powerpc_state *)drccache_memory_alloc_near(cache, sizeof(*ppc));
561   *(powerpc_state **)device->token() = ppc = (powerpc_state *)cache->alloc_near(sizeof(*ppc));
564562   memset(ppc, 0, sizeof(*ppc));
565563
566564   /* initialize the core */
567565   ppccom_init(ppc, flavor, cap, tb_divisor, device, irqcallback);
568566
569567   /* allocate the implementation-specific state from the full cache */
570   ppc->impstate = (ppcimp_state *)drccache_memory_alloc_near(cache, sizeof(*ppc->impstate));
568   ppc->impstate = (ppcimp_state *)cache->alloc_near(sizeof(*ppc->impstate));
571569   memset(ppc->impstate, 0, sizeof(*ppc->impstate));
572570   ppc->impstate->cache = cache;
573571
r10048r10049
731729   /* clean up the DRC */
732730   auto_free(device->machine, ppc->impstate->drcfe);
733731   drcuml_free(ppc->impstate->drcuml);
734   drccache_free(ppc->impstate->cache);
732   auto_free(device->machine, ppc->impstate->cache);
735733}
736734
737735
src/emu/cpu/drccache.h
r10048r10049
44
55    Universal dynamic recompiler cache management.
66
7****************************************************************************
8
79    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.
1011
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
1138***************************************************************************/
1239
1340#pragma once
r10048r10049
1744
1845
1946
20/***************************************************************************
21    MACROS
22***************************************************************************/
47//**************************************************************************
48//  MACROS
49//**************************************************************************
2350
24/* ensure that a given pointer is within the cache boundaries */
25#define assert_in_cache(c,p)      assert(drccache_contains_pointer(c, p))
26#define assert_in_near_cache(c,p)   assert(drccache_contains_near_pointer(c, p))
51// ensure that a given pointer is within the cache boundaries
52#define assert_in_cache(c,p)      assert((c)->contains_pointer(p))
53#define assert_in_near_cache(c,p)   assert((c)->contains_near_pointer(p))
2754
2855
2956
30/***************************************************************************
31    TYPE DEFINITIONS
32***************************************************************************/
57//**************************************************************************
58//  TYPE DEFINITIONS
59//**************************************************************************
3360
34/* generic code pointer */
61// generic code pointer
3562typedef UINT8 *drccodeptr;
3663
37/* opaque cache state */
38typedef struct _drccache drccache;
64// drc_cache
65class drc_cache
66{
67public:
68   // out of band codegen callback
69   typedef void (*oob_func)(drccodeptr *codeptr, void *param1, void *param2, void *param3);
3970
40/* out of band codegen callback */
41typedef void (*drccache_oob_func)(drccodeptr *codeptr, void *param1, void *param2, void *param3);
71   // construction/destruction
72   drc_cache(size_t bytes);
73   ~drc_cache();
74   
75   // getters
76   drccodeptr near() const { return m_near; }
77   drccodeptr base() const { return m_base; }
78   drccodeptr top() const { return m_top; }
79   
80   // pointer checking
81   bool contains_pointer(const void *ptr) const { return ((const drccodeptr)ptr >= m_near && (const drccodeptr)ptr < m_near + m_size); }
82   bool contains_near_pointer(const void *ptr) const { return ((const drccodeptr)ptr >= m_near && (const drccodeptr)ptr < m_neartop); }
4283
84   // memory management
85   void flush();
86   void *alloc(size_t bytes);
87   void *alloc_near(size_t bytes);
88   void *alloc_temporary(size_t bytes);
89   void dealloc(void *memory, size_t bytes);
4390
91   // codegen helpers
92   drccodeptr *begin_codegen(UINT32 reserve_bytes);
93   drccodeptr end_codegen();
94   void request_oob_codegen(oob_func callback, void *param1 = NULL, void *param2 = NULL, void *param3 = NULL);
4495
45/***************************************************************************
46    FUNCTION PROTOTYPES
47***************************************************************************/
96private:
97   // largest block of code that can be generated at once
98   static const size_t CODEGEN_MAX_BYTES = 65536;
4899
49/* ----- initialization/teardown ----- */
100   // minimum alignment, in bytes (must be power of 2)
101   static const size_t CACHE_ALIGNMENT = 8;
50102
51/* allocate the cache itself */
52drccache *drccache_alloc(size_t bytes);
103   // largest permanent allocation we allow
104   static const size_t MAX_PERMANENT_ALLOC = 1024;
53105
54/* free the cache */
55void drccache_free(drccache *cache);
106   // size of "near" area at the base of the cache
107   static const size_t NEAR_CACHE_SIZE = 65536;
56108
109   // core parameters
110   drccodeptr         m_near;            // pointer to the near part of the cache
111   drccodeptr         m_neartop;         // top of the near part of the cache
112   drccodeptr         m_base;            // base pointer to the compiler cache
113   drccodeptr         m_top;            // current top of cache
114   drccodeptr         m_end;            // end of cache memory
115   drccodeptr         m_codegen;         // start of generated code
116   size_t            m_size;            // size of the cache in bytes
57117
118   // oob management
119   struct oob_handler
120   {
121      oob_handler *next() const { return m_next; }
122     
123      oob_handler *   m_next;            // next handler
124      oob_func      m_callback;         // callback function
125      void *         m_param1;         // 1st pointer parameter
126      void *         m_param2;         // 2nd pointer parameter
127      void *         m_param3;         // 3rd pointer parameter
128   };
129   simple_list<oob_handler> m_ooblist;      // list of oob handlers
58130
59/* ----- cache information ----- */
131   // free lists
132   struct free_link
133   {
134      free_link *         m_next;         // pointer to the next guy
135   };
136   free_link *         m_free[MAX_PERMANENT_ALLOC / CACHE_ALIGNMENT];
137   free_link *         m_nearfree[MAX_PERMANENT_ALLOC / CACHE_ALIGNMENT];
138};
60139
61/* return true if a pointer is within the cache */
62int drccache_contains_pointer(drccache *cache, const void *ptr);
63140
64/* return true if a pointer is within the near area of the cache */
65int drccache_contains_near_pointer(drccache *cache, const void *ptr);
66
67/* return a pointer to the near part of the cache */
68drccodeptr drccache_near(drccache *cache);
69
70/* return a pointer to the base of the cache, which is where code generation starts */
71drccodeptr drccache_base(drccache *cache);
72
73/* return the current top of the cache, which is where the next code will be generated */
74drccodeptr drccache_top(drccache *cache);
75
76
77
78/* ----- memory management ----- */
79
80/* flush the cache contents */
81void drccache_flush(drccache *cache);
82
83/* allocate permanent memory from the cache */
84void *drccache_memory_alloc(drccache *cache, size_t bytes);
85
86/* allocate permanent memory from the near portion of the cache */
87void *drccache_memory_alloc_near(drccache *cache, size_t bytes);
88
89/* release permanent memory allocated from the cache */
90void drccache_memory_free(drccache *cache, void *memory, size_t bytes);
91
92/* allocate temporary memory from the cache (released on a reset) */
93void *drccache_memory_alloc_temporary(drccache *cache, size_t bytes);
94
95
96
97/* ----- code generation ----- */
98
99/* begin code generation */
100drccodeptr *drccache_begin_codegen(drccache *cache, UINT32 reserve_bytes);
101
102/* complete code generation */
103drccodeptr drccache_end_codegen(drccache *cache);
104
105/* request callback for out-of-band codegen */
106void drccache_request_oob_codegen(drccache *cache, drccache_oob_func callback, void *param1, void *param2, void *param3);
107
108
109141#endif /* __DRCCACHE_H__ */
src/emu/cpu/sh2/sh2comn.h
r10048r10049
154154   void   (*ftcsr_read_callback)(UINT32 data);
155155
156156#ifdef USE_SH2DRC
157   drccache *         cache;                /* pointer to the DRC code cache */
157   drc_cache *         cache;                /* pointer to the DRC code cache */
158158   drcuml_state *      drcuml;               /* DRC UML generator state */
159159   sh2_frontend *      drcfe;               /* pointer to the DRC front-end state */
160160   UINT32            drcoptions;         /* configurable DRC options */
src/emu/cpu/sh2/sh2drc.c
r10048r10049
675675static CPU_INIT( sh2 )
676676{
677677   sh2_state *sh2 = get_safe_token(device);
678   drccache *cache;
678   drc_cache *cache;
679679   drcbe_info beinfo;
680680   UINT32 flags = 0;
681681   int regnum;
682682
683683   /* allocate enough space for the cache and the core */
684   cache = drccache_alloc(CACHE_SIZE + sizeof(sh2_state));
685   if (cache == NULL)
686      fatalerror("Unable to allocate cache of size %d", (UINT32)(CACHE_SIZE + sizeof(sh2_state)));
684   cache = auto_alloc(device->machine, drc_cache(CACHE_SIZE + sizeof(sh2_state)));
687685
688686   /* allocate the core memory */
689   *(sh2_state **)device->token() = sh2 = (sh2_state *)drccache_memory_alloc_near(cache, sizeof(sh2_state));
687   *(sh2_state **)device->token() = sh2 = (sh2_state *)cache->alloc_near(sizeof(sh2_state));
690688   memset(sh2, 0, sizeof(sh2_state));
691689
692690   /* initialize the common core parts */
r10048r10049
772770   /* clean up the DRC */
773771   auto_free(device->machine, sh2->drcfe);
774772   drcuml_free(sh2->drcuml);
775   drccache_free(sh2->cache);
773   auto_free(device->machine, sh2->cache);
776774}
777775
778776
src/emu/cpu/nec/necpriv.h
r10048r10049
171171#define CLKR(v20o,v30o,v33o,v20e,v30e,v33e,vall,addr) { const UINT32 ocount=(v20o<<16)|(v30o<<8)|v33o, ecount=(v20e<<16)|(v30e<<8)|v33e; if (ModRM >=0xc0) nec_state->icount-=vall; else nec_state->icount-=(addr&1)?((ocount>>nec_state->chip_type)&0x7f):((ecount>>nec_state->chip_type)&0x7f); }
172172
173173/************************************************************************/
174#define CompressFlags() (WORD)(CF | 0x02 | (PF << 2) | (AF << 4) | (ZF << 6) \
175            | (SF << 7) | (nec_state->TF << 8) | (nec_state->IF << 9) \
176            | (nec_state->DF << 10) | (OF << 11) | (nec_state->MF << 15))
174#define CompressFlags() (WORD)(int(CF) | 0x02 | (int(PF) << 2) | (int(AF) << 4) | (int(ZF) << 6) \
175            | (int(SF) << 7) | (nec_state->TF << 8) | (nec_state->IF << 9) \
176            | (nec_state->DF << 10) | (int(OF) << 11) | (nec_state->MF << 15))
177177
178178#define ExpandFlags(f) \
179179{ \
src/emu/cpu/mips/mips3drc.c
r10048r10049
184184struct _mips3imp_state
185185{
186186   /* core state */
187   drccache *         cache;                  /* pointer to the DRC code cache */
187   drc_cache *         cache;                  /* pointer to the DRC code cache */
188188   drcuml_state *      drcuml;                  /* DRC UML generator state */
189189   mips3_frontend *   drcfe;                  /* pointer to the DRC front-end state */
190190   UINT32            drcoptions;               /* configurable DRC options */
r10048r10049
388388static void mips3_init(mips3_flavor flavor, int bigendian, legacy_cpu_device *device, device_irq_callback irqcallback)
389389{
390390   mips3_state *mips3;
391   drccache *cache;
391   drc_cache *cache;
392392   drcbe_info beinfo;
393393   UINT32 flags = 0;
394394   int regnum;
395395
396396   /* allocate enough space for the cache and the core */
397   cache = (drccache *)drccache_alloc(CACHE_SIZE + sizeof(*mips3));
397   cache = auto_alloc(device->machine, drc_cache(CACHE_SIZE + sizeof(*mips3)));
398398   if (cache == NULL)
399399      fatalerror("Unable to allocate cache of size %d", (UINT32)(CACHE_SIZE + sizeof(*mips3)));
400400
401401   /* allocate the core memory */
402   *(mips3_state **)device->token() = mips3 = (mips3_state *)drccache_memory_alloc_near(cache, sizeof(*mips3));
402   *(mips3_state **)device->token() = mips3 = (mips3_state *)cache->alloc_near(sizeof(*mips3));
403403   memset(mips3, 0, sizeof(*mips3));
404404
405405   /* initialize the core */
406406   mips3com_init(mips3, flavor, bigendian, device, irqcallback);
407407
408408   /* allocate the implementation-specific state from the full cache */
409   mips3->impstate = (mips3imp_state *)drccache_memory_alloc_near(cache, sizeof(*mips3->impstate));
409   mips3->impstate = (mips3imp_state *)cache->alloc_near(sizeof(*mips3->impstate));
410410   memset(mips3->impstate, 0, sizeof(*mips3->impstate));
411411   mips3->impstate->cache = cache;
412412
r10048r10049
566566   /* clean up the DRC */
567567   auto_free(device->machine, mips3->impstate->drcfe);
568568   drcuml_free(mips3->impstate->drcuml);
569   drccache_free(mips3->impstate->cache);
569   auto_free(device->machine, mips3->impstate->cache);
570570}
571571
572572
src/emu/cpu/drcbeut.c
r10048r10049
44
55    Utility functions for dynamic recompiling backends.
66
7****************************************************************************
8
79    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.
1011
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
1138***************************************************************************/
1239
1340#include "emu.h"
1441#include "drcbeut.h"
1542
1643
17/***************************************************************************
18    DEBUGGING
19***************************************************************************/
44//**************************************************************************
45//  DEBUGGING
46//**************************************************************************
2047
2148#define LOG_RECOVER         (0)
2249
2350
24/***************************************************************************
25    TYPE DEFINITIONS
26***************************************************************************/
2751
28/* structure holding information about a single label */
29typedef struct _drcmap_entry drcmap_entry;
30struct _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//**************************************************************************
3755
56//-------------------------------------------------
57//  drc_hash_table - constructor
58//-------------------------------------------------
3859
39/* structure describing the state of the code map */
40struct _drcmap_state
60drc_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)
4173{
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 */
52typedef struct _drclabel drclabel;
53struct _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 */
62struct _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
74static void label_list_reset(drclabel_list *list, int fatal_on_leftovers);
75static drclabel *label_find_or_allocate(drclabel_list *list, drcuml_codelabel label);
76static 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
90drchash_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();
11875}
11976
12077
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//-------------------------------------------------
12582
126int drchash_reset(drchash_state *drchash)
83bool drc_hash_table::reset()
12784{
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;
12989
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;
13493
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;
13898
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;
143102
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;
147106
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;
153108}
154109
155110
156/*-------------------------------------------------
157    drchash_block_begin - note the beginning of a
158    block
159-------------------------------------------------*/
111//-------------------------------------------------
112//  block_begin - note the beginning of a block
113//-------------------------------------------------
160114
161void drchash_block_begin(drchash_state *drchash, drcuml_block *block, const drcuml_instruction *instlist, UINT32 numinst)
115void drc_hash_table::block_begin(drcuml_block &block, const drcuml_instruction *instlist, UINT32 numinst)
162116{
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++)
167119   {
168      const drcuml_instruction *inst = &instlist[inum];
120      const drcuml_instruction &inst = instlist[inum];
169121
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)
172124      {
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);
176128
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);
180132      }
181133
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)
184136      {
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);
189141      }
190142   }
191143}
192144
193145
194/*-------------------------------------------------
195    drchash_block_end - note the end of a block
196-------------------------------------------------*/
146//-------------------------------------------------
147//  block_end - note the end of a block
148//-------------------------------------------------
197149
198void drchash_block_end(drchash_state *drchash, drcuml_block *block)
150void drc_hash_table::block_end(drcuml_block &block)
199151{
200   /* nothing to do here, yet */
152   // nothing to do here, yet
201153}
202154
203155
204/*-------------------------------------------------
205    drchash_set_default_codeptr - change the
206    default codeptr
207-------------------------------------------------*/
156//-------------------------------------------------
157//  set_default_codeptr - change the default
158//  codeptr
159//-------------------------------------------------
208160
209void drchash_set_default_codeptr(drchash_state *drchash, drccodeptr nocodeptr)
161void drc_hash_table::set_default_codeptr(drccodeptr nocodeptr)
210162{
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;
215165   if (old == nocodeptr)
216166      return;
217   drchash->nocodeptr = nocodeptr;
167   m_nocodeptr = nocodeptr;
218168
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;
222172
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;
231181}
232182
233183
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//-------------------------------------------------
238188
239int drchash_set_codeptr(drchash_state *drchash, UINT32 mode, UINT32 pc, drccodeptr code)
189bool drc_hash_table::set_codeptr(UINT32 mode, UINT32 pc, drccodeptr code)
240190{
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)
248194   {
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);
250196      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;
254200   }
255201
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)
258205   {
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);
260207      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;
264211   }
265212
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;
269217}
270218
271219
272220
273/***************************************************************************
274    CODE MAP MANAGEMENT
275***************************************************************************/
221//**************************************************************************
222//  DRC MAP VARIABLES
223//**************************************************************************
276224
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//-------------------------------------------------
282228
283drcmap_state *drcmap_alloc(drccache *cache, UINT64 uniquevalue)
229drc_map_variables::drc_map_variables(drc_cache &cache, UINT64 uniquevalue)
230   : m_cache(cache),
231     m_uniquevalue(uniquevalue)
284232{
285   drcmap_state *drcmap;
233   memset(m_mapvalue, 0, sizeof(m_mapvalue));
234}
286235
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));
292236
293   /* remember the cache */
294   drcmap->cache = cache;
295   drcmap->tailptr = &drcmap->head;
237//-------------------------------------------------
238//  ~drc_map_variables - destructor
239//-------------------------------------------------
296240
297   return drcmap;
241drc_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();
298246}
299247
300248
301/*-------------------------------------------------
302    drcmap_block_begin - note the beginning of a
303    block
304-------------------------------------------------*/
249//-------------------------------------------------
250//  block_begin - note the beginning of a block
251//-------------------------------------------------
305252
306void drcmap_block_begin(drcmap_state *drcmap, drcuml_block *block)
253void drc_map_variables::block_begin(drcuml_block &block)
307254{
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));
315259
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));
322262}
323263
324264
325/*-------------------------------------------------
326    drcmap_block_end - note the end of a block
327-------------------------------------------------*/
265//-------------------------------------------------
266//  block_end - note the end of a block
267//-------------------------------------------------
328268
329void drcmap_block_end(drcmap_state *drcmap, drcuml_block *block)
269void drc_map_variables::block_end(drcuml_block &block)
330270{
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)
340273      return;
341274
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());
344277   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);
347280
348   /* store the cookie first */
349   *(UINT64 *)dest = drcmap->uniquevalue;
281   // store the cookie first
282   *(UINT64 *)dest = m_uniquevalue;
350283   dest += 2;
351284
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;
354287   *dest = (drccodeptr)dest - lastptr;
355288   dest++;
356289
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())
359294   {
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)
362297      {
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;
365300      }
366301
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)
369304      {
370         UINT32 codedelta = entry->codeptr - lastptr;
305         // build a mask of changed variables
306         int numchanged = 0;
371307         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++)
377309            if (changed[varnum])
378310            {
379               changed[varnum] = FALSE;
311               changed[varnum] = false;
380312               varmask |= 1 << varnum;
381313               numchanged++;
382314            }
383315
384         /* if nothing really changed, skip it */
316         // if nothing really changed, skip it
385317         if (numchanged == 0)
386318            continue;
387319
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;
389322         while (codedelta > 0xffff)
390323         {
391324            *dest++ = 0xffff << 16;
r10048r10049
393326         }
394327         *dest++ = (codedelta << 16) | (varmask << 4) | numchanged;
395328
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++)
398331            if ((varmask >> varnum) & 1)
399332               *dest++ = curvalue[varnum];
400333
401         /* remember our lastptr */
402         lastptr = entry->codeptr;
334         // remember our lastptr
335         lastptr = entry->m_codeptr;
403336      }
404337   }
405338
406   /* add a terminator */
339   // add a terminator
407340   *dest++ = 0;
408341
409   /* complete codegen */
342   // complete codegen
410343   *top = (drccodeptr)dest;
411   drccache_end_codegen(drcmap->cache);
344   m_cache.end_codegen();
412345}
413346
414347
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//-------------------------------------------------
419352
420void drcmap_set_value(drcmap_state *drcmap, drccodeptr codebase, UINT32 mapvar, UINT32 newvalue)
353void drc_map_variables::set_value(drccodeptr codebase, UINT32 mapvar, UINT32 newvalue)
421354{
422   drcmap_entry *entry;
423
424355   assert(mapvar >= DRCUML_MAPVAR_M0 && mapvar < DRCUML_MAPVAR_END);
425356
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)
428359      return;
429360
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;
436367
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);
440370
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;
446373}
447374
448375
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//-------------------------------------------------
453380
454UINT32 drcmap_get_value(drcmap_state *drcmap, drccodeptr codebase, UINT32 mapvar)
381UINT32 drc_map_variables::get_value(drccodeptr codebase, UINT32 mapvar) const
455382{
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
463383   assert(mapvar >= DRCUML_MAPVAR_M0 && mapvar < DRCUML_MAPVAR_END);
464384   mapvar -= DRCUML_MAPVAR_M0;
465385
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();
468389
469   /* look for the signature */
470   while (curscan < endscan && *curscan++ != drcmap->uniquevalue) ;
390   // look for the signature
391   while (curscan < endscan && *curscan++ != m_uniquevalue) ;
471392   if (curscan >= endscan)
472393      return 0;
473394
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;
476397
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;
479400   data++;
480401
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)
483406   {
407      // a 0 is a terminator
484408      UINT32 controlword = *data++;
485
486      /* a 0 is a terminator */
487409      if (controlword == 0)
488410         break;
489411
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
491413      curcode += (controlword >> 16) & 0xffff;
492414      if (curcode > codebase)
493415         break;
494416
495      /* if our mapvar has changed, process this word */
417      // if our mapvar has changed, process this word
496418      if ((controlword & varmask) != 0)
497419      {
420         // count how many words precede the one we care about
498421         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))
503423            dataoffs++;
504424
505         /* fetch the one we want */
425         // fetch the one we want
506426         result = data[dataoffs];
507427      }
508428
509      /* low 4 bits contain the total number of words of data */
429      // low 4 bits contain the total number of words of data
510430      data += controlword & 0x0f;
511431   }
512432   if (LOG_RECOVER)
r10048r10049
514434   return result;
515435}
516436
437UINT32 drc_map_variables::static_get_value(drc_map_variables &map, drccodeptr codebase, UINT32 mapvar)
438{
439   return map.get_value(codebase, mapvar);
440}
517441
518/*-------------------------------------------------
519    drcmap_get_last_value - return the most
520    recently set map value
521-------------------------------------------------*/
522442
523UINT32 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
449UINT32 drc_map_variables::get_last_value(UINT32 mapvar)
524450{
525451   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];
527453}
528454
529455
530456
531/***************************************************************************
532    LABEL MANAGEMENT
533***************************************************************************/
457//**************************************************************************
458//  DRC LABEL LIST
459//**************************************************************************
534460
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//-------------------------------------------------
540464
541drclabel_list *drclabel_list_alloc(drccache *cache)
465drc_label_list::drc_label_list(drc_cache &cache)
466   : m_cache(cache)
542467{
543   drclabel_list *list;
468}
544469
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));
550470
551   /* remember the cache */
552   list->cache = cache;
471//-------------------------------------------------
472//  ~drc_label_list - destructor
473//-------------------------------------------------
553474
554   return list;
475drc_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();
555480}
556481
557482
558/*-------------------------------------------------
559    drclabel_block_begin - note the beginning of
560    a block
561-------------------------------------------------*/
483//-------------------------------------------------
484//  block_begin - note the beginning of a block
485//-------------------------------------------------
562486
563void drclabel_block_begin(drclabel_list *list, drcuml_block *block)
487void drc_label_list::block_begin(drcuml_block &block)
564488{
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);
567491}
568492
569493
570/*-------------------------------------------------
571    drclabel_block_end - note the end of a block
572-------------------------------------------------*/
494//-------------------------------------------------
495//  block_end - note the end of a block
496//-------------------------------------------------
573497
574void drclabel_block_end(drclabel_list *list, drcuml_block *block)
498void drc_label_list::block_end(drcuml_block &block)
575499{
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);
578502}
579503
580504
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//-------------------------------------------------
586510
587drccodeptr drclabel_get_codeptr(drclabel_list *list, drcuml_codelabel label, drclabel_fixup_func fixup, void *param)
511drccodeptr drc_label_list::get_codeptr(drcuml_codelabel label, fixup_func fixup, void *param)
588512{
589   drclabel *curlabel = label_find_or_allocate(list, label);
513   label_entry *curlabel = find_or_allocate(label);
590514
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);
594518
595   return curlabel->codeptr;
519   return curlabel->m_codeptr;
596520}
597521
598522
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//-------------------------------------------------
603526
604void drclabel_set_codeptr(drclabel_list *list, drcuml_codelabel label, drccodeptr codeptr)
527void drc_label_list::set_codeptr(drcuml_codelabel label, drccodeptr codeptr)
605528{
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;
610533}
611534
612535
536//-------------------------------------------------
537//  reset - reset a label list (add all entries to
538//  the free list)
539//-------------------------------------------------
613540
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
623static void label_list_reset(drclabel_list *list, int fatal_on_leftovers)
541void drc_label_list::reset(bool fatal_on_leftovers)
624542{
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)
627546   {
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);
631550
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));
638553   }
639554}
640555
641556
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//-------------------------------------------------
646561
647static drclabel *label_find_or_allocate(drclabel_list *list, drcuml_codelabel label)
562drc_label_list::label_entry *drc_label_list::find_or_allocate(drcuml_codelabel label)
648563{
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)
654568         break;
655569
656   /* if none found, allocate */
570   // if none found, allocate
657571   if (curlabel == NULL)
658572   {
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);
664577   }
665
666578   return curlabel;
667579}
668580
669581
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//-------------------------------------------------
674586
675static void label_oob_callback(drccodeptr *codeptr, void *param1, void *param2, void *param3)
587void drc_label_list::oob_callback(drccodeptr *codeptr, void *param1, void *param2, void *param3)
676588{
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;
679591
680   (*callback)(param3, label->codeptr);
592   (*callback)(param3, label->m_codeptr);
681593}
src/emu/cpu/drcbeut.h
r10048r10049
44
55    Utility functions for dynamic recompiling backends.
66
7****************************************************************************
8
79    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.
1011
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
1138***************************************************************************/
1239
1340#pragma once
r10048r10049
1845#include "drcuml.h"
1946
2047
21/***************************************************************************
22    TYPE DEFINITIONS
23***************************************************************************/
48//**************************************************************************
49//  TYPE DEFINITIONS
50//**************************************************************************
2451
25/* callback function for forward-referenced labels */
26typedef void (*drclabel_fixup_func)(void *parameter, drccodeptr labelcodeptr);
52// ======================> drc_hash_table
2753
54// common hash table management
55class drc_hash_table
56{
57public:
58   // construction/destruction
59   drc_hash_table(drc_cache &cache, UINT32 modes, UINT8 addrbits, UINT8 ignorebits);
60   
61   // getters
62   drccodeptr ***base() const { return m_base; }
63   UINT8 l1bits() const { return m_l1bits; }
64   UINT8 l2bits() const { return m_l2bits; }
65   UINT8 l1shift() const { return m_l1shift; }
66   UINT8 l2shift() const { return m_l2shift; }
67   offs_t l1mask() const { return m_l1mask; }
68   offs_t l2mask() const { return m_l2mask; }
69   bool is_mode_populated(UINT32 mode) const { return m_base[mode] != m_emptyl1; }
70   
71   // set up and configuration
72   bool reset();
73   void set_default_codeptr(drccodeptr code);
2874
29/* opaque structure representing a managed list of labels */
30typedef struct _drclabel_list drclabel_list;
75   // block begin/end
76   void block_begin(drcuml_block &block, const drcuml_instruction *instlist, UINT32 numinst);
77   void block_end(drcuml_block &block);
3178
79   // code pointer access
80   bool set_codeptr(UINT32 mode, UINT32 pc, drccodeptr code);
81   drccodeptr get_codeptr(UINT32 mode, UINT32 pc) { assert(mode < m_modes); return m_base[mode][(pc >> m_l1shift) & m_l1mask][(pc >> m_l2shift) & m_l2mask]; }
82   bool code_exists(UINT32 mode, UINT32 pc) { return get_codeptr(mode, pc) != m_nocodeptr; }
3283
33/* opaque structure representing a managed code map */
34typedef struct _drcmap_state drcmap_state;
84private:
85   // internal state
86   drc_cache &      m_cache;            // cache where allocations come from
87   UINT32         m_modes;            // number of modes supported
3588
89   drccodeptr      m_nocodeptr;         // pointer to code which will handle missing entries
3690
37/* information about the hash tables used by the UML and backend */
38typedef struct _drchash_state drchash_state;
39struct _drchash_state
40{
41   drccache *      cache;            /* cache where allocations come from */
42   int            modes;            /* number of modes supported */
91   UINT8         m_l1bits;            // bits worth of entries in l1 hash tables
92   UINT8         m_l2bits;            // bits worth of entries in l2 hash tables
93   UINT8         m_l1shift;            // shift to apply to the PC to get the l1 hash entry
94   UINT8         m_l2shift;            // shift to apply to the PC to get the l2 hash entry
95   offs_t         m_l1mask;            // mask to apply after shifting
96   offs_t         m_l2mask;            // mask to apply after shifting
4397
44   drccodeptr      nocodeptr;         /* pointer to code which will handle missing entries */
45
46   UINT8         l1bits;            /* bits worth of entries in l1 hash tables */
47   UINT8         l1shift;         /* shift to apply to the PC to get the l1 hash entry */
48   offs_t         l1mask;            /* mask to apply after shifting */
49   UINT8         l2bits;            /* bits worth of entries in l2 hash tables */
50   UINT8         l2shift;         /* shift to apply to the PC to get the l2 hash entry */
51   offs_t         l2mask;            /* mask to apply after shifting */
52
53   drccodeptr **   emptyl1;         /* pointer to empty l1 hash table */
54   drccodeptr *   emptyl2;         /* pointer to empty l2 hash table */
55
56   drccodeptr **   base[1];         /* pointer to the l1 table for each mode */
98   drccodeptr ***   m_base;               // pointer to the l1 table for each mode
99   drccodeptr **   m_emptyl1;            // pointer to empty l1 hash table
100   drccodeptr *   m_emptyl2;            // pointer to empty l2 hash table
57101};
58102
59103
104// ======================> drc_map_variables
60105
61/***************************************************************************
62    FUNCTION PROTOTYPES
63***************************************************************************/
106// common map variable management
107class drc_map_variables
108{
109public:
110   // construction/destruction
111   drc_map_variables(drc_cache &cache, UINT64 uniquevalue);
112   ~drc_map_variables();
64113
65/* ----- hash table management ----- */
114   // block begin/end
115   void block_begin(drcuml_block &block);
116   void block_end(drcuml_block &block);
66117
67/* allocate memory in the cache for the hash table tracker (it auto-frees with the cache) */
68drchash_state *drchash_alloc(drccache *cache, int modes, int addrbits, int ignorebits);
118   // get/set values
119   void set_value(drccodeptr codebase, UINT32 mapvar, UINT32 newvalue);
120   UINT32 get_value(drccodeptr codebase, UINT32 mapvar) const;
121   UINT32 get_last_value(UINT32 mapvar);
69122
70/* flush existing hash tables and create new ones */
71int drchash_reset(drchash_state *drchash);
123   // static accessors to be called directly by generated code
124   static UINT32 static_get_value(drc_map_variables &map, drccodeptr codebase, UINT32 mapvar);
72125
73/* note the beginning of a block */
74void drchash_block_begin(drchash_state *drchash, drcuml_block *block, const drcuml_instruction *instlist, UINT32 numinst);
126private:
127   // internal state
128   drc_cache &         m_cache;         // pointer to the cache
129   UINT64            m_uniquevalue;      // unique value used to find the table
130   UINT32            m_mapvalue[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0]; // array of current values
75131
76/* note the end of a block */
77void drchash_block_end(drchash_state *drchash, drcuml_block *block);
132   // list of entries
133   struct map_entry
134   {
135      map_entry *next() const { return m_next; }
136      map_entry *      m_next;            // pointer to next map entry
137      drccodeptr      m_codeptr;         // pointer to the relevant code
138      UINT32         m_mapvar;         // map variable id
139      UINT32         m_newval;         // value of the variable starting at codeptr
140   };
141   simple_list<map_entry> m_entry_list;   // list of entries
142};
78143
79/* set the default codeptr for any empty hash entries (defaults to NULL) */
80void drchash_set_default_codeptr(drchash_state *drchash, drccodeptr code);
81144
82/* set the codeptr for the given mode/pc */
83int drchash_set_codeptr(drchash_state *drchash, UINT32 mode, UINT32 pc, drccodeptr code);
145// ======================> drc_label_list
84146
147// structure holding a live list of labels
148class drc_label_list
149{
150   // callback function for forward-referenced labels
151   typedef void (*fixup_func)(void *parameter, drccodeptr labelcodeptr);
85152
153public:
154   // construction/destruction
155   drc_label_list(drc_cache &cache);
156   ~drc_label_list();
86157
87/* ----- code map management ----- */
158   // block begin/end
159   void block_begin(drcuml_block &block);
160   void block_end(drcuml_block &block);
88161
89/* allocate memory in the cache for the code mapper (it auto-frees with the cache) */
90drcmap_state *drcmap_alloc(drccache *cache, UINT64 uniquevalue);
162   // get/set values
163   drccodeptr get_codeptr(drcuml_codelabel label, fixup_func fixup, void *param);
164   void set_codeptr(drcuml_codelabel label, drccodeptr codeptr);
91165
92/* note the beginning of a block */
93void drcmap_block_begin(drcmap_state *drcmap, drcuml_block *block);
166private:
167   struct label_entry
168   {
169      label_entry *next() const { return m_next; }
170      label_entry *      m_next;         // pointer to next label
171      drcuml_codelabel   m_label;      // the label specified
172      drccodeptr         m_codeptr;      // pointer to the relevant code
173   };
94174
95/* note the end of a block */
96void drcmap_block_end(drcmap_state *drcmap, drcuml_block *block);
175   // internal helpers
176   void reset(bool fatal_on_leftovers);
177   label_entry *find_or_allocate(drcuml_codelabel label);
178   static void oob_callback(drccodeptr *codeptr, void *param1, void *param2, void *param3);
97179
98/* set a map value for the given code pointer */
99void drcmap_set_value(drcmap_state *drcmap, drccodeptr codebase, UINT32 mapvar, UINT32 newvalue);
180   // internal state
181   drc_cache &         m_cache;         // pointer to the cache
182   simple_list<label_entry> m_list;      // head of the live list
183};
100184
101/* return a map value for the given code pointer */
102UINT32 drcmap_get_value(drcmap_state *drcmap, drccodeptr codebase, UINT32 mapvar);
103185
104/* return the most recently set map value */
105UINT32 drcmap_get_last_value(drcmap_state *drcmap, UINT32 mapvar);
106
107
108
109/* ----- label management ----- */
110
111/* allocate a label list within the cache (it auto-frees with the cache) */
112drclabel_list *drclabel_list_alloc(drccache *cache);
113
114/* note the beginning of a block */
115void drclabel_block_begin(drclabel_list *drcmap, drcuml_block *block);
116
117/* note the end of a block */
118void drclabel_block_end(drclabel_list *drcmap, drcuml_block *block);
119
120/* find or allocate a new label; returns NULL and requests an OOB callback if undefined */
121drccodeptr drclabel_get_codeptr(drclabel_list *list, drcuml_codelabel label, drclabel_fixup_func fixup, void *param);
122
123/* set the pointer to a new label */
124void drclabel_set_codeptr(drclabel_list *list, drcuml_codelabel label, drccodeptr codeptr);
125
126
127
128/***************************************************************************
129    INLINE FUNCTIONS
130***************************************************************************/
131
132/*-------------------------------------------------
133    drchash_get_codeptr - return the codeptr
134    allocated for the given mode/pc
135-------------------------------------------------*/
136
137INLINE drccodeptr drchash_get_codeptr(drchash_state *drchash, UINT32 mode, UINT32 pc)
138{
139   assert(mode < drchash->modes);
140   return drchash->base[mode][(pc >> drchash->l1shift) & drchash->l1mask][(pc >> drchash->l2shift) & drchash->l2mask];
141}
142
143
144/*-------------------------------------------------
145    drchash_code_exists - return TRUE if there is
146    a matching hash entry for the given mode/pc
147-------------------------------------------------*/
148
149INLINE int drchash_code_exists(drchash_state *drchash, UINT32 mode, UINT32 pc)
150{
151   return (drchash_get_codeptr(drchash, mode, pc) != drchash->nocodeptr);
152}
153
154
155186#endif /* __DRCBEUT_H__ */
src/emu/cpu/arm7/arm7exec.c
r10048r10049
5757            INT32 offs;
5858
5959            pc = R15;
60       raddr = pc & (~1);
60
61         // "In Thumb state, bit [0] is undefined and must be ignored. Bits [31:1] contain the PC."
62         raddr = pc & (~1);
63
6164       if ( COPRO_CTRL & COPRO_CTRL_MMU_EN )
6265       {
6366          raddr = arm7_tlb_translate(cpustate, raddr, ARM7_TLB_ABORT_P);
r10048r10049
11691172        }
11701173        else
11711174        {
1175         UINT32 raddr;
11721176
11731177            /* load 32 bit instruction */
11741178            pc = GET_PC;
1179
1180         // "In ARM state, bits [1:0] of r15 are undefined and must be ignored. Bits [31:2] contain the PC."
1181         raddr = pc & (~3);
1182
11751183       if ( COPRO_CTRL & COPRO_CTRL_MMU_EN )
11761184       {
1177          pc = arm7_tlb_translate(cpustate, pc, ARM7_TLB_ABORT_P);
1185          raddr = arm7_tlb_translate(cpustate, raddr, ARM7_TLB_ABORT_P);
11781186          if (cpustate->pendingAbtP != 0)
11791187          {
11801188             goto skip_exec;
r10048r10049
11911199         }
11921200#endif
11931201
1194            insn = cpustate->direct->read_decrypted_dword(pc);
1202            insn = cpustate->direct->read_decrypted_dword(raddr);
11951203
11961204            /* process condition codes for this instruction */
11971205            switch (insn >> INSN_COND_SHIFT)
src/emu/cpu/drcbex86.c
r10048r10049
156156{
157157   device_t *   device;               /* CPU device we are associated with */
158158   drcuml_state *         drcuml;               /* pointer back to our owner */
159   drccache *            cache;               /* pointer to the cache */
159   drc_cache *            cache;               /* pointer to the cache */
160160   drcuml_machine_state   state;               /* state of the machine */
161   drchash_state *         hash;               /* hash table state */
162   drcmap_state *         map;               /* code map */
163   drclabel_list *         labels;                 /* label list */
161   drc_hash_table *      hash;               /* hash table state */
162   drc_map_variables *      map;               /* code map */
163   drc_label_list *      labels;                 /* label list */
164164
165165   x86_entry_point_func   entry;               /* entry point */
166166   x86code *            exit;               /* exit point */
r10048r10049
201201***************************************************************************/
202202
203203/* primary back-end callbacks */
204static drcbe_state *drcbex86_alloc(drcuml_state *drcuml, drccache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits);
204static drcbe_state *drcbex86_alloc(drcuml_state *drcuml, drc_cache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits);
205205static void drcbex86_free(drcbe_state *drcbe);
206206static void drcbex86_reset(drcbe_state *drcbe);
207207static int drcbex86_execute(drcbe_state *drcbe, drcuml_codehandle *entry);
r10048r10049
614614    state
615615-------------------------------------------------*/
616616
617static drcbe_state *drcbex86_alloc(drcuml_state *drcuml, drccache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits)
617static drcbe_state *drcbex86_alloc(drcuml_state *drcuml, drc_cache *cache, device_t *device, UINT32 flags, int modes, int addrbits, int ignorebits)
618618{
619619   int opnum, regnum, entry, spacenum;
620620   drcbe_state *drcbe;
621621
622622   /* allocate space in the cache for our state */
623   drcbe = (drcbe_state *)drccache_memory_alloc(cache, sizeof(*drcbe));
623   drcbe = (drcbe_state *)cache->alloc(sizeof(*drcbe));
624624   if (drcbe == NULL)
625625      return NULL;
626626   memset(drcbe, 0, sizeof(*drcbe));
r10048r10049
639639   }
640640
641641   /* allocate hash tables */
642   drcbe->hash = drchash_alloc(cache, modes, addrbits, ignorebits);
643   if (drcbe->hash == NULL)
644      return NULL;
642   drcbe->hash = auto_alloc(device->machine, drc_hash_table(*cache, modes, addrbits, ignorebits));
645643
646644   /* allocate code map */
647   drcbe->map = drcmap_alloc(cache, 0);
648   if (drcbe->map == NULL)
649      return NULL;
645   drcbe->map = auto_alloc(device->machine, drc_map_variables(*cache, 0));
650646
651647   /* allocate a label tracker */
652   drcbe->labels = drclabel_list_alloc(cache);
653   if (drcbe->labels == NULL)
654      return NULL;
648   drcbe->labels = auto_alloc(device->machine, drc_label_list(*cache));
655649
656650   /* build the opcode table (static but it doesn't hurt to regenerate it) */
657651   for (opnum = 0; opnum < ARRAY_LENGTH(opcode_table_source); opnum++)
r10048r10049
722716      x86log_printf(drcbe->log, "\n\n===========\nCACHE RESET\n===========\n\n");
723717
724718   /* generate a little bit of glue code to set up the environment */
725   dst = (x86code **)drccache_begin_codegen(drcbe->cache, 500);
719   dst = (x86code **)drcbe->cache->begin_codegen(500);
726720   if (dst == NULL)
727721      fatalerror("Out of cache space after a reset!");
728722
r10048r10049
850844      x86log_disasm_code_range(drcbe->log, "restore", drcbe->restore, *dst);
851845
852846   /* finish up codegen */
853   drccache_end_codegen(drcbe->cache);
847   drcbe->cache->end_codegen();
854848   drcbe->logged_common = TRUE;
855849
856850   /* reset our hash tables */
857   drchash_reset(drcbe->hash);
858   drchash_set_default_codeptr(drcbe->hash, drcbe->nocode);
851   drcbe->hash->reset();
852   drcbe->hash->set_default_codeptr(drcbe->nocode);
859853}
860854
861855
r10048r10049
885879   int inum;
886880
887881   /* tell all of our utility objects that a block is beginning */
888   drchash_block_begin(drcbe->hash, block, instlist, numinst);
889   drclabel_block_begin(drcbe->labels, block);
890   drcmap_block_begin(drcbe->map, block);
882   drcbe->hash->block_begin(*block, instlist, numinst);
883   drcbe->labels->block_begin(*block);
884   drcbe->map->block_begin(*block);
891885
892886   /* begin codegen; fail if we can't */
893   cachetop = drccache_begin_codegen(drcbe->cache, numinst * 8 * 4);
887   cachetop = drcbe->cache->begin_codegen(numinst * 8 * 4);
894888   if (cachetop == NULL)
895889      drcuml_block_abort(block);
896890
r10048r10049
930924
931925   /* complete codegen */
932926   *cachetop = (drccodeptr)dst;
933   drccache_end_codegen(drcbe->cache);
927   drcbe->cache->end_codegen();
934928
935929   /* log it */
936930   if (drcbe->log != NULL)
937      x86log_disasm_code_range(drcbe->log, (blockname == NULL) ? "Unknown block" : blockname, base, drccache_top(drcbe->cache));
931      x86log_disasm_code_range(drcbe->log, (blockname == NULL) ? "Unknown block" : blockname, base, drcbe->cache->top());
938932
939933   /* tell all of our utility objects that the block is finished */
940   drchash_block_end(drcbe->hash, block);
941   drclabel_block_end(drcbe->labels, block);
942   drcmap_block_end(drcbe->map, block);
934   drcbe->hash->block_end(*block);
935   drcbe->labels->block_end(*block);
936   drcbe->map->block_end(*block);
943937}
944938
945939
r10048r10049
950944
951945static int drcbex86_hash_exists(drcbe_state *drcbe, UINT32 mode, UINT32 pc)
952946{
953   return drchash_code_exists(drcbe->hash, mode, pc);
947   return drcbe->hash->code_exists(mode, pc);
954948}
955949
956950
r10048r10049
32613255   assert(inst->param[1].type == DRCUML_PTYPE_IMMEDIATE);
32623256
32633257   /* register the current pointer for the mode/PC */
3264   drchash_set_codeptr(drcbe->hash, inst->param[0].value, inst->param[1].value, dst);
3258   drcbe->hash->set_codeptr(inst->param[0].value, inst->param[1].value, dst);
32653259   reset_last_upper_lower_reg(drcbe);
32663260   return dst;
32673261}
r10048r10049
32793273   assert(inst->param[0].type == DRCUML_PTYPE_IMMEDIATE);
32803274
32813275   /* register the current pointer for the label */
3282   drclabel_set_codeptr(drcbe->labels, inst->param[0].value, dst);
3276   drcbe->labels->set_codeptr(inst->param[0].value, dst);
32833277   reset_last_upper_lower_reg(drcbe);
32843278   return dst;
32853279}
r10048r10049
33143308   assert(inst->param[1].type == DRCUML_PTYPE_IMMEDIATE);
33153309
33163310   /* set the value of the specified mapvar */
3317   drcmap_set_value(drcbe->map, dst, inst->param[0].value, inst->param[1].value);
3311   drcbe->map->set_value(dst, inst->param[0].value, inst->param[1].value);
33183312   return dst;
33193313}
33203314
r10048r10049
34253419   emit_mov_r32_m32(&dst, REG_ESP, MABS(&drcbe->hashstacksave));                  // mov   esp,[hashstacksave]
34263420
34273421   /* fixed mode cases */
3428   if (modep.type == DRCUML_PTYPE_IMMEDIATE && drcbe->hash->base[modep.value] != drcbe->hash->emptyl1)
3422   if (modep.type == DRCUML_PTYPE_IMMEDIATE && drcbe->hash->is_mode_populated(modep.value))
34293423   {
34303424      /* a straight immediate jump is direct, though we need the PC in EAX in case of failure */
34313425      if (pcp.type == DRCUML_PTYPE_IMMEDIATE)
34323426      {
3433         UINT32 l1val = (pcp.value >> drcbe->hash->l1shift) & drcbe->hash->l1mask;
3434         UINT32 l2val = (pcp.value >> drcbe->hash->l2shift) & drcbe->hash->l2mask;
3435         emit_call_m32(&dst, MABS(&drcbe->hash->base[modep.value][l1val][l2val]));   // call  hash[modep][l1val][l2val]
3427         UINT32 l1val = (pcp.value >> drcbe->hash->l1shift()) & drcbe->hash->l1mask();
3428         UINT32 l2val = (pcp.value >> drcbe->hash->l2shift()) & drcbe->hash->l2mask();
3429         emit_call_m32(&dst, MABS(&drcbe->hash->base()[modep.value][l1val][l2val]));   // call  hash[modep][l1val][l2val]
34363430      }
34373431
34383432      /* a fixed mode but variable PC */
r10048r10049
34403434      {
34413435         emit_mov_r32_p32(drcbe, &dst, REG_EAX, &pcp);                        // mov   eax,pcp
34423436         emit_mov_r32_r32(&dst, REG_EDX, REG_EAX);                           // mov   edx,eax
3443         emit_shr_r32_imm(&dst, REG_EDX, drcbe->hash->l1shift);                  // shr   edx,l1shift
3444         emit_and_r32_imm(&dst, REG_EAX, drcbe->hash->l2mask << drcbe->hash->l2shift);// and  eax,l2mask << l2shift
3445         emit_mov_r32_m32(&dst, REG_EDX, MISD(REG_EDX, 4, &drcbe->hash->base[modep.value][0]));
3437         emit_shr_r32_imm(&dst, REG_EDX, drcbe->hash->l1shift());               // shr   edx,l1shift
3438         emit_and_r32_imm(&dst, REG_EAX, drcbe->hash->l2mask() << drcbe->hash->l2shift());// and  eax,l2mask << l2shift
3439         emit_mov_r32_m32(&dst, REG_EDX, MISD(REG_EDX, 4, &drcbe->hash->base()[modep.value][0]));
34463440                                                                  // mov   edx,hash[modep+edx*4]
3447         emit_call_m32(&dst, MBISD(REG_EDX, REG_EAX, 4 >> drcbe->hash->l2shift, 0));   // call  [edx+eax*shift]
3441         emit_call_m32(&dst, MBISD(REG_EDX, REG_EAX, 4 >> drcbe->hash->l2shift(), 0));// call  [edx+eax*shift]
34483442      }
34493443   }
34503444   else
r10048r10049
34523446      /* variable mode */
34533447      int modereg = param_select_register(REG_ECX, &modep, NULL);
34543448      emit_mov_r32_p32(drcbe, &dst, modereg, &modep);                           // mov   modereg,modep
3455      emit_mov_r32_m32(&dst, REG_ECX, MISD(modereg, 4, &drcbe->hash->base[0]));      // mov   ecx,hash[modereg*4]
3449      emit_mov_r32_m32(&dst, REG_ECX, MISD(modereg, 4, drcbe->hash->base()));         // mov   ecx,hash[modereg*4]
34563450
34573451      /* fixed PC */
34583452      if (pcp.type == DRCUML_PTYPE_IMMEDIATE)
34593453      {
3460         UINT32 l1val = (pcp.value >> drcbe->hash->l1shift) & drcbe->hash->l1mask;
3461         UINT32 l2val = (pcp.value >> drcbe->hash->l2shift) & drcbe->hash->l2mask;
3454         UINT32 l1val = (pcp.value >> drcbe->hash->l1shift()) & drcbe->hash->l1mask();
3455         UINT32 l2val = (pcp.value >> drcbe->hash->l2shift()) & drcbe->hash->l2mask();
34623456         emit_mov_r32_m32(&dst, REG_EDX, MBD(REG_ECX, l1val*4));                  // mov   edx,[ecx+l1val*4]
34633457         emit_call_m32(&dst, MBD(REG_EDX, l2val*4));                           // call  [l2val*4]
34643458      }
r10048r10049
34683462      {
34693463         emit_mov_r32_p32(drcbe, &dst, REG_EAX, &pcp);                        // mov   eax,pcp
34703464         emit_mov_r32_r32(&dst, REG_EDX, REG_EAX);                           // mov   edx,eax
3471         emit_shr_r32_imm(&dst, REG_EDX, drcbe->hash->l1shift);                  // shr   edx,l1shift
3465         emit_shr_r32_imm(&dst, REG_EDX, drcbe->hash->l1shift());               // shr   edx,l1shift
34723466         emit_mov_r32_m32(&dst, REG_EDX, MBISD(REG_ECX, REG_EDX, 4, 0));            // mov   edx,[ecx+edx*4]
3473         emit_and_r32_imm(&dst, REG_EAX, drcbe->hash->l2mask << drcbe->hash->l2shift);// and  eax,l2mask << l2shift
3474         emit_call_m32(&dst, MBISD(REG_EDX, REG_EAX, 4 >> drcbe->hash->l2shift, 0));   // call  [edx+eax*shift]
3467         emit_and_r32_imm(&dst, REG_EAX, drcbe->hash->l2mask() << drcbe->hash->l2shift());// and  eax,l2mask << l2shift
3468         emit_call_m32(&dst, MBISD(REG_EDX, REG_EAX, 4 >> drcbe->hash->l2shift(), 0));// call  [edx+eax*shift]
34753469      }
34763470   }
34773471
r10048r10049
35023496   param_normalize_1(drcbe, inst, &labelp, PTYPE_I);
35033497
35043498   /* look up the jump target and jump there */
3505   jmptarget = (x86code *)drclabel_get_codeptr(drcbe->labels, labelp.value, fixup_label, dst);
3499   jmptarget = (x86code *)drcbe->labels->get_codeptr(labelp.value, fixup_label, dst);
35063500   if (inst->condition == DRCUML_COND_ALWAYS)
35073501      emit_jmp(&dst, jmptarget);                                          // jmp   target
35083502   else
r10048r10049
35463540   else
35473541   {
35483542      emit_jcc(&dst, X86_CONDITION(inst->condition), 0);                        // jcc   exception
3549      drccache_request_oob_codegen(drcbe->cache, fixup_exception, drcbe, dst, (void *)inst);
3543      drcbe->cache->request_oob_codegen(fixup_exception, drcbe, dst, (void *)inst);
35503544   }
35513545   return dst;
35523546}
r10048r10049
36743668   emit_mov_m32_imm(&dst, MBD(REG_ESP, 8), inst->param[1].value);                  // mov   [esp+8],param1
36753669   emit_mov_m32_r32(&dst, MBD(REG_ESP, 4), REG_EAX);                           // mov   [esp+4],eax
36763670   emit_mov_m32_imm(&dst, MBD(REG_ESP, 0), (FPTR)drcbe->map);                     // mov   [esp],drcbe->map
3677   emit_call(&dst, (x86code *)drcmap_get_value);                              // call  drcmap_get_value
3671   emit_call(&dst, (x86code *)&drc_map_variables::static_get_value);               // call  drcmap_get_value
36783672   emit_mov_p32_r32(drcbe, &dst, &dstp, REG_EAX);                              // mov   dstp,eax
36793673
36803674   return dst;
src/emu/sound/disc_sys.c
r10048r10049
1616 *
1717 ************************************************************************/
1818
19struct dso_csvlog_context
20{
21   FILE *csv_file;
22   INT64 sample_num;
23   char name[32];
24};
2519
26struct dso_wavlog_context
27{
28   wav_file *wavfile;
29   char name[32];
30};
3120
3221
3322/*************************************
r10048r10049
3625 *
3726 *************************************/
3827
39static void task_check(discrete_task *task, discrete_task *dest_task)
40{
41   int inputnum;
4228
43   /* Determine, which nodes in the task are referenced by nodes in dest_task
44     * and add them to the list of nodes to be buffered for further processing
45     */
46   for_each(node_description *, node_entry, &task->list)
47   {
48      node_description *task_node = node_entry.item();
49
50      for_each(node_description *, step_entry, &dest_task->list)
51      {
52         node_description *dest_node = step_entry.item();
53
54         /* loop over all active inputs */
55         for (inputnum = 0; inputnum < dest_node->active_inputs(); inputnum++)
56         {
57            int inputnode = dest_node->input_node(inputnum);
58            if IS_VALUE_A_NODE(inputnode)
59            {
60               if (NODE_DEFAULT_NODE(task_node->block_node()) == NODE_DEFAULT_NODE(inputnode))
61               {
62                  discrete_source_node *source;
63                  int i, found = -1;
64
65                  for (i = 0; i < task->numbuffered; i++)
66                     if (task->nodes[i]->block_node() == inputnode)
67                     {
68                        found = i;
69                        break;
70                     }
71
72                  if (found<0)
73                  {
74                     if (task->numbuffered >= DISCRETE_MAX_TASK_OUTPUTS)
75                        fatalerror("dso_task_start - Number of maximum buffered nodes exceeded");
76
77                     task->node_buf[task->numbuffered] = auto_alloc_array(task_node->info->device->machine, double,
78                           ((task_node->info->sample_rate + STREAMS_UPDATE_FREQUENCY) / STREAMS_UPDATE_FREQUENCY));
79                     task->source[task->numbuffered] = (double *) dest_node->input[inputnum];
80                     task->nodes[task->numbuffered] = discrete_find_node(task_node->info, inputnode);
81                     i = task->numbuffered;
82                     task->numbuffered++;
83                  }
84                  discrete_log(task_node->info, "dso_task_start - buffering %d(%d) in task %p group %d referenced by %d group %d", NODE_INDEX(inputnode), NODE_CHILD_NODE_NUM(inputnode), task, task->task_group, dest_node->index(), dest_task->task_group);
85
86                  /* register into source list */
87                  source = auto_alloc(dest_node->info->device->machine, discrete_source_node);
88                  dest_task->source_list.add_tail(source);
89                  source->task = task;
90                  source->output_node = i;
91
92                  /* point the input to a buffered location */
93                  dest_node->input[inputnum] = &source->buffer;
94
95               }
96            }
97         }
98      }
99   }
100}
101
102#define DISCRETE_DECLARE_TASK   discrete_task *task = (discrete_task *) node->context;
103
104DISCRETE_START( dso_task_start )
105{
106   DISCRETE_DECLARE_TASK
107
108   task->task_group = (int) DISCRETE_INPUT(0);
109
110   if (task->task_group < 0 || task->task_group >= DISCRETE_MAX_TASK_GROUPS)
111      fatalerror("discrete_dso_task: illegal task_group %d", task->task_group);
112
113   for_each(discrete_task *, dest_task, &node->info->task_list)
114   {
115      if (task->task_group > dest_task.item()->task_group)
116         task_check(dest_task.item(), task);
117   }
118
119}
120
121DISCRETE_STEP( dso_task_end )
122{
123   DISCRETE_DECLARE_TASK
124
125   int i;
126
127   for (i = 0; i < task->numbuffered; i++)
128      *(task->ptr[i]++) = *task->source[i];
129}
130
131DISCRETE_STEP( dso_task_start )
132{
133   DISCRETE_DECLARE_TASK
134
135   /* update source node buffer */
136   for_each(discrete_source_node *, sn, &task->source_list)
137   {
138      sn.item()->buffer = *sn.item()->ptr++;
139   }
140}
141
142
143DISCRETE_RESET( dso_task )
144{
145   /* nothing to do - just avoid being stepped */
146}
147
148DISCRETE_STEP( dso_output )
149{
150   stream_sample_t **output = (stream_sample_t **) &node->context;
151   double val;
152
153   /* Add gain to the output and put into the buffers */
154   /* Clipping will be handled by the main sound system */
155   val = DISCRETE_INPUT(0) * DISCRETE_INPUT(1);
156   **output = val;
157   (*output)++;
158}
159
160DISCRETE_RESET( dso_output )
161{
162   /* nothing to do - just avoid being stepped */
163}
164
16529DISCRETE_START( dso_csvlog )
16630{
167   DISCRETE_DECLARE_CONTEXT(dso_csvlog)
168
16931   int log_num, node_num;
17032
171   log_num = node->same_module_index(node->info->node_list);
172   context->sample_num = 0;
33   log_num = device->same_module_index(*this);
34   m_sample_num = 0;
17335
174   sprintf(context->name, "discrete_%s_%d.csv", node->info->device->tag(), log_num);
175   context->csv_file = fopen(context->name, "w");
36   sprintf(m_name, "discrete_%s_%d.csv", device->tag(), log_num);
37   m_csv_file = fopen(m_name, "w");
17638   /* Output some header info */
177   fprintf(context->csv_file, "\"MAME Discrete System Node Log\"\n");
178   fprintf(context->csv_file, "\"Log Version\", 1.0\n");
179   fprintf(context->csv_file, "\"Sample Rate\", %d\n", node->info->sample_rate);
180   fprintf(context->csv_file, "\n");
181   fprintf(context->csv_file, "\"Sample\"");
182   for (node_num = 0; node_num < node->active_inputs(); node_num++)
39   fprintf(m_csv_file, "\"MAME Discrete System Node Log\"\n");
40   fprintf(m_csv_file, "\"Log Version\", 1.0\n");
41   fprintf(m_csv_file, "\"Sample Rate\", %d\n", this->sample_rate());
42   fprintf(m_csv_file, "\n");
43   fprintf(m_csv_file, "\"Sample\"");
44   for (node_num = 0; node_num < this->active_inputs(); node_num++)
18345   {
184      fprintf(context->csv_file, ", \"NODE_%2d\"", NODE_INDEX(node->input_node(node_num)));
46      fprintf(m_csv_file, ", \"NODE_%2d\"", NODE_INDEX(this->input_node(node_num)));
18547   }
186   fprintf(context->csv_file, "\n");
48   fprintf(m_csv_file, "\n");
18749}
18850
18951DISCRETE_STOP( dso_csvlog )
19052{
191   DISCRETE_DECLARE_CONTEXT(dso_csvlog)
192
19353   /* close any csv files */
194   if (context->csv_file)
195      fclose(context->csv_file);
54   if (m_csv_file)
55      fclose(m_csv_file);
19656}
19757
19858DISCRETE_STEP( dso_csvlog )
19959{
200   DISCRETE_DECLARE_CONTEXT(dso_csvlog)
201
20260   int nodenum;
20361
20462   /* Dump any csv logs */
205   fprintf(context->csv_file, "%" I64FMT "d", ++context->sample_num);
206   for (nodenum = 0; nodenum < node->active_inputs(); nodenum++)
63   fprintf(m_csv_file, "%" I64FMT "d", ++m_sample_num);
64   for (nodenum = 0; nodenum < this->active_inputs(); nodenum++)
20765   {
208      fprintf(context->csv_file, ", %f", *node->input[nodenum]);
66      fprintf(m_csv_file, ", %f", *this->input[nodenum]);
20967   }
210   fprintf(context->csv_file, "\n");
68   fprintf(m_csv_file, "\n");
21169}
21270
213DISCRETE_START( dso_wavlog )
71DISCRETE_RESET( dso_csvlog )
21472{
215   DISCRETE_DECLARE_CONTEXT(dso_wavlog)
73   this->step();
74}
21675
76
77DISCRETE_START( dso_wavlog )
78{
21779   int log_num;
21880
219   log_num = node->same_module_index(node->info->node_list);
220   sprintf(context->name, "discrete_%s_%d.wav", node->info->device->tag(), log_num);
221   context->wavfile = wav_open(context->name, node->info->sample_rate, node->active_inputs()/2);
81   log_num = device->same_module_index(*this);
82   sprintf(m_name, "discrete_%s_%d.wav", device->tag(), log_num);
83   m_wavfile = wav_open(m_name, sample_rate(), active_inputs()/2);
22284}
22385
22486DISCRETE_STOP( dso_wavlog )
22587{
226   DISCRETE_DECLARE_CONTEXT(dso_wavlog)
227
22888   /* close any wave files */
229   if (context->wavfile)
230      wav_close(context->wavfile);
89   if (m_wavfile)
90      wav_close(m_wavfile);
23191}
23292
23393DISCRETE_STEP( dso_wavlog )
23494{
235   DISCRETE_DECLARE_CONTEXT(dso_wavlog)
236
23795   double val;
23896   INT16 wave_data_l, wave_data_r;
23997
r10048r10049
242100   val = DISCRETE_INPUT(0) * DISCRETE_INPUT(1);
243101   val = (val < -32768) ? -32768 : (val > 32767) ? 32767 : val;
244102   wave_data_l = (INT16)val;
245   if (node->active_inputs() == 2)
103   if (this->active_inputs() == 2)
246104   {
247105      /* DISCRETE_WAVLOG1 */
248      wav_add_data_16(context->wavfile, &wave_data_l, 1);
106      wav_add_data_16(m_wavfile, &wave_data_l, 1);
249107   }
250108   else
251109   {
r10048r10049
254112      val = (val < -32768) ? -32768 : (val > 32767) ? 32767 : val;
255113      wave_data_r = (INT16)val;
256114
257      wav_add_data_16lr(context->wavfile, &wave_data_l, &wave_data_r, 1);
115      wav_add_data_16lr(m_wavfile, &wave_data_l, &wave_data_r, 1);
258116   }
259117}
118
119DISCRETE_RESET( dso_wavlog )
120{
121   this->step();
122}
123
src/emu/sound/disc_inp.c
r10048r10049
2020#define DSS_INPUT__OFFSET   DISCRETE_INPUT(1)
2121#define DSS_INPUT__INIT      DISCRETE_INPUT(2)
2222
23
24struct dss_adjustment_context
25{
26   const input_port_config *port;
27   INT32      lastpval;
28   INT32      pmin;
29   double      pscale;
30   double      min;
31   double      scale;
32};
33
34struct dss_input_context
35{
36   stream_sample_t *ptr;         /* current in ptr for stream */
37   double      gain;            /* node gain */
38   double      offset;            /* node offset */
39   UINT8      data;            /* data written */
40   UINT8      is_stream;
41   UINT8      is_buffered;
42   UINT32      stream_in_number;
43   /* the buffer stream */
44   sound_stream *buffer_stream;
45};
46
47#if 0
48INLINE discrete_info *get_safe_token(device_t *device)
49{
50   assert(device != NULL);
51   assert(device->type() == DISCRETE);
52   return (discrete_info *)downcast<legacy_device_base *>(device)->token();
53}
54#endif
55
5623READ8_DEVICE_HANDLER(discrete_sound_r)
5724{
5825   discrete_device *disc_device = downcast<discrete_device *>(device);
r10048r10049
8855
8956DISCRETE_STEP(dss_adjustment)
9057{
91   DISCRETE_DECLARE_CONTEXT(dss_adjustment)
58   INT32  rawportval = input_port_read_direct(m_port);
9259
93   INT32  rawportval = input_port_read_direct(context->port);
94
9560   /* only recompute if the value changed from last time */
96   if (UNEXPECTED(rawportval != context->lastpval))
61   if (UNEXPECTED(rawportval != m_lastpval))
9762   {
98      double portval   = (double)(rawportval - context->pmin) * context->pscale;
99      double scaledval = portval * context->scale + context->min;
63      double portval   = (double)(rawportval - m_pmin) * m_pscale;
64      double scaledval = portval * m_scale + m_min;
10065
101      context->lastpval = rawportval;
66      m_lastpval = rawportval;
10267      if (DSS_ADJUSTMENT__LOG == 0)
103         node->output[0] = scaledval;
68         this->output[0] = scaledval;
10469      else
105         node->output[0] = pow(10, scaledval);
70         this->output[0] = pow(10, scaledval);
10671   }
10772}
10873
10974DISCRETE_RESET(dss_adjustment)
11075{
111   DISCRETE_DECLARE_CONTEXT(dss_adjustment)
112
11376   double min, max;
11477
115   context->port = node->info->device->machine->m_portlist.find((const char *)node->custom_data());
116   if (context->port == NULL)
117      fatalerror("DISCRETE_ADJUSTMENT - NODE_%d has invalid tag", node->index());
78   m_port = device->machine->m_portlist.find((const char *)this->custom_data());
79   if (m_port == NULL)
80      fatalerror("DISCRETE_ADJUSTMENT - NODE_%d has invalid tag", this->index());
11881
119   context->lastpval = 0x7fffffff;
120   context->pmin     = DSS_ADJUSTMENT__PMIN;
121   context->pscale   = 1.0 / (double)(DSS_ADJUSTMENT__PMAX - DSS_ADJUSTMENT__PMIN);
82   m_lastpval = 0x7fffffff;
83   m_pmin     = DSS_ADJUSTMENT__PMIN;
84   m_pscale   = 1.0 / (double)(DSS_ADJUSTMENT__PMAX - DSS_ADJUSTMENT__PMIN);
12285
12386   /* linear scale */
12487   if (DSS_ADJUSTMENT__LOG == 0)
12588   {
126      context->min   = DSS_ADJUSTMENT__MIN;
127      context->scale = DSS_ADJUSTMENT__MAX - DSS_ADJUSTMENT__MIN;
89      m_min   = DSS_ADJUSTMENT__MIN;
90      m_scale = DSS_ADJUSTMENT__MAX - DSS_ADJUSTMENT__MIN;
12891   }
12992
13093   /* logarithmic scale */
r10048r10049
13396      /* force minimum and maximum to be > 0 */
13497      min = (DSS_ADJUSTMENT__MIN > 0) ? DSS_ADJUSTMENT__MIN : 1;
13598      max = (DSS_ADJUSTMENT__MAX > 0) ? DSS_ADJUSTMENT__MAX : 1;
136      context->min   = log10(min);
137      context->scale = log10(max) - log10(min);
99      m_min   = log10(min);
100      m_scale = log10(max) - log10(min);
138101   }
139102
140   DISCRETE_STEP_CALL(dss_adjustment);
103   this->step();
141104}
142105
143106
r10048r10049
152115
153116DISCRETE_RESET(dss_constant)
154117{
155   node->output[0]= DSS_CONSTANT__INIT;
118   this->output[0]= DSS_CONSTANT__INIT;
156119}
157120
158121
r10048r10049
166129 * input[3]    - Current data value
167130 *
168131 ************************************************************************/
169DISCRETE_RESET(dss_input)
132
133DISCRETE_RESET(dss_input_data)
170134{
171   DISCRETE_DECLARE_CONTEXT(dss_input)
135   m_gain = DSS_INPUT__GAIN;
136   m_offset = DSS_INPUT__OFFSET;
172137
173   context->is_buffered = FALSE;
174   context->is_stream = FALSE;
175   context->gain = DSS_INPUT__GAIN;
176   context->offset = DSS_INPUT__OFFSET;
138   m_data = DSS_INPUT__INIT;
139   this->output[0] = m_data * m_gain + m_offset;
140}
177141
178   switch (node->module->type)
142void DISCRETE_CLASS_FUNC(dss_input_data, input_write)(int sub_node, UINT8 data )
143{
144   UINT8 new_data    = 0;
145
146   new_data = data;
147
148   if (m_data != new_data)
179149   {
180      case DSS_INPUT_DATA:
181         context->data = DSS_INPUT__INIT;
182         break;
183      case DSS_INPUT_LOGIC:
184      case DSS_INPUT_PULSE:
185         context->data = (DSS_INPUT__INIT == 0) ? 0 : 1;
186         break;
187      case DSS_INPUT_NOT:
188         context->data = (DSS_INPUT__INIT == 0) ? 1 : 0;
189         break;
150      /* Bring the system up to now */
151      device->update();
152
153      m_data = new_data;
154
155      /* Update the node output here so we don't have to do it each step */
156      this->output[0] = m_data * m_gain + m_offset;
190157   }
191   node->output[0] = context->data * context->gain + context->offset;
192158}
193159
160DISCRETE_RESET(dss_input_logic)
161{
162   m_gain = DSS_INPUT__GAIN;
163   m_offset = DSS_INPUT__OFFSET;
164
165   m_data = (DSS_INPUT__INIT == 0) ? 0 : 1;
166   this->output[0] = m_data * m_gain + m_offset;
167}
168
169void DISCRETE_CLASS_FUNC(dss_input_logic, input_write)(int sub_node, UINT8 data )
170{
171   UINT8 new_data    = 0;
172
173   new_data =  data ? 1 : 0;
174
175   if (m_data != new_data)
176   {
177      /* Bring the system up to now */
178      device->update();
179
180      m_data = new_data;
181
182      /* Update the node output here so we don't have to do it each step */
183      this->output[0] = m_data * m_gain + m_offset;
184   }
185}
186
187DISCRETE_RESET(dss_input_not)
188{
189   m_gain = DSS_INPUT__GAIN;
190   m_offset = DSS_INPUT__OFFSET;
191
192   m_data = (DSS_INPUT__INIT == 0) ? 1 : 0;
193   this->output[0] = m_data * m_gain + m_offset;
194}
195
196void DISCRETE_CLASS_FUNC(dss_input_not, input_write)(int sub_node, UINT8 data )
197{
198   UINT8 new_data    = 0;
199
200   new_data = data ? 0 : 1;
201
202   if (m_data != new_data)
203   {
204      /* Bring the system up to now */
205      device->update();
206
207      m_data = new_data;
208
209      /* Update the node output here so we don't have to do it each step */
210      this->output[0] = m_data * m_gain + m_offset;
211   }
212}
213
194214DISCRETE_STEP(dss_input_pulse)
195215{
196   DISCRETE_DECLARE_CONTEXT(dss_input)
197
198216   /* Set a valid output */
199   node->output[0] = context->data;
217   this->output[0] = m_data;
200218   /* Reset the input to default for the next cycle */
201219   /* node order is now important */
202   context->data = DSS_INPUT__INIT;
220   m_data = DSS_INPUT__INIT;
203221}
204222
223DISCRETE_RESET(dss_input_pulse)
224{
225   m_data = (DSS_INPUT__INIT == 0) ? 0 : 1;
226   this->output[0] = m_data;
227}
205228
229void DISCRETE_CLASS_FUNC(dss_input_pulse, input_write)(int sub_node, UINT8 data )
230{
231   UINT8 new_data    = 0;
232
233   new_data =  data ? 1 : 0;
234
235   if (m_data != new_data)
236   {
237      /* Bring the system up to now */
238      device->update();
239      m_data = new_data;
240   }
241}
242
206243/************************************************************************
207244 *
208245 * DSS_INPUT_STREAM    - Receives input from a routed stream
r10048r10049
216253#define DSS_INPUT_STREAM__GAIN      DISCRETE_INPUT(1)
217254#define DSS_INPUT_STREAM__OFFSET   DISCRETE_INPUT(2)
218255
256STREAM_UPDATE( discrete_dss_input_stream_node::static_stream_generate )
257{
258   reinterpret_cast<discrete_dss_input_stream_node *>(param)->stream_generate(inputs, outputs, samples);
259}
260
261void discrete_dss_input_stream_node::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples)
262{
263   stream_sample_t *ptr = outputs[0];
264   int samplenum = samples;
265
266   while (samplenum-- > 0)
267     *(ptr++) = m_data;
268}
219269DISCRETE_STEP(dss_input_stream)
220270{
221271   /* the context pointer is set to point to the current input stream data in discrete_stream_update */
222   DISCRETE_DECLARE_CONTEXT(dss_input)
223
224   if (EXPECTED(context->ptr))
272   if (EXPECTED(m_ptr))
225273   {
226      node->output[0] = (*context->ptr) * context->gain + context->offset;
227      context->ptr++;
274      this->output[0] = (*m_ptr) * m_gain + m_offset;
275      m_ptr++;
228276   }
229277   else
230      node->output[0] = 0;
278      this->output[0] = 0;
231279}
232280
233281DISCRETE_RESET(dss_input_stream)
234282{
235   DISCRETE_DECLARE_CONTEXT(dss_input)
283   m_ptr = NULL;
284   m_data = 0;
285}
236286
237   context->ptr = NULL;
238   context->data = 0;
287void DISCRETE_CLASS_FUNC(dss_input_stream, input_write)(int sub_node, UINT8 data )
288{
289   UINT8 new_data    = 0;
290
291   new_data =  data;
292
293   if (m_data != new_data)
294   {
295      if (m_is_buffered)
296      {
297         /* Bring the system up to now */
298         stream_update(m_buffer_stream);
299
300         m_data = new_data;
301      }
302      else
303      {
304         /* Bring the system up to now */
305         device->update();
306
307         m_data = new_data;
308
309         /* Update the node output here so we don't have to do it each step */
310         this->output[0] = new_data * m_gain + m_offset;
311      }
312   }
239313}
240314
241315DISCRETE_START(dss_input_stream)
242316{
243   DISCRETE_DECLARE_CONTEXT(dss_input)
317   discrete_base_node::start();
244318
245   //assert(DSS_INPUT_STREAM__STREAM < node->info->input_list.count());
319   assert(DSS_INPUT_STREAM__STREAM < this->device->m_input_stream_list.count());
246320
247   context->is_stream = TRUE;
248321   /* Stream out number is set during start */
249   context->stream_in_number = DSS_INPUT_STREAM__STREAM;
250   context->gain = DSS_INPUT_STREAM__GAIN;
251   context->offset = DSS_INPUT_STREAM__OFFSET;
252   context->ptr = NULL;
253   //context->data = 0;
322   m_stream_in_number = DSS_INPUT_STREAM__STREAM;
323   m_gain = DSS_INPUT_STREAM__GAIN;
324   m_offset = DSS_INPUT_STREAM__OFFSET;
325   m_ptr = NULL;
254326
255   if (node->block_type() == DSS_INPUT_BUFFER)
327   m_is_buffered = is_buffered();
328   if (m_is_buffered)
256329   {
257      context->is_buffered = TRUE;
258      context->buffer_stream = stream_create(node->info->device, 0, 1, node->info->sample_rate, (void *) node, buffer_stream_update);
330      m_buffer_stream = stream_create(this->device, 0, 1, this->sample_rate(), this, static_stream_generate);
259331
260      stream_set_input(node->info->discrete_stream, context->stream_in_number,
261         context->buffer_stream, 0, 1.0);
332      stream_set_input(device->m_stream, m_stream_in_number,
333         m_buffer_stream, 0, 1.0);
262334   }
263335   else
264336   {
265      context->is_buffered = FALSE;
266      context->buffer_stream = NULL;
337      m_buffer_stream = NULL;
267338   }
268339}
340
src/emu/sound/disc_cls.h
r0r10049
1#pragma once
2
3#ifndef __DISC_CLS_H__
4#define __DISC_CLS_H__
5
6/***********************************************************************
7 *
8 *  MAME - Discrete sound system emulation library
9 *
10 *  Written by Keith Wilkins (mame@esplexo.co.uk)
11 *
12 *  (c) K.Wilkins 2000
13 *
14 *  Coding started in November 2000
15 *
16 *  Additions/bugfix February 2003 - D.Renaud, F.Palazzolo, K.Wilkins
17 *  Discrete parallel tasks 2009 - Couriersud
18 *
19 ***********************************************************************/
20
21#define DISCRETE_CLASS_NAME(_name) discrete_ ## _name ## _node
22
23#if 0
24#define DISCRETE_CLASS_CONSTRUCTOR(_name, _base, _ctxsize)            \
25      DISCRETE_CLASS_NAME(_name)(discrete_device * pdev, const discrete_sound_block *block) \
26       : DISCRETE_CLASS_NAME(_base)(pdev, block) { m_context_size = _ctxsize; }
27#else
28#define DISCRETE_CLASS_CONSTRUCTOR(_name, _base)            \
29      DISCRETE_CLASS_NAME(_name)() \
30       : DISCRETE_CLASS_NAME(_base)() { }
31#endif
32#if 1
33#define DISCRETE_CLASS_DESTRUCTOR(_name)                        \
34   public:                                                \
35      virtual ~ DISCRETE_CLASS_NAME(_name)(void) { }
36#else
37#define DISCRETE_CLASS_DESTRUCTOR(_name)
38#endif
39
40#define  DISCRETE_CLASS_STEP_RESETA(_name, _maxout, _priv)            \
41class DISCRETE_CLASS_NAME(_name): public discrete_base_node, public discrete_step_interface         \
42{                                                      \
43public:                                                   \
44   DISCRETE_CLASS_CONSTRUCTOR(_name, base)                        \
45   void step(void);                                       \
46   void reset(void);                                       \
47   int max_output(void) { return _maxout; }                     \
48   DISCRETE_CLASS_DESTRUCTOR(_name)                           \
49private:                                                \
50   _priv                                                \
51}
52
53#define DISCRETE_CLASS_STEPA(_name, _maxout, _priv)                \
54class DISCRETE_CLASS_NAME(_name): public discrete_base_node, public discrete_step_interface            \
55{                                                      \
56public:                                                   \
57   DISCRETE_CLASS_CONSTRUCTOR(_name, base)                        \
58   void step(void);                                       \
59   void reset(void)         { this->step(); }                  \
60   int max_output(void) { return _maxout; }                     \
61   DISCRETE_CLASS_DESTRUCTOR(_name)                           \
62private:                                                \
63   _priv                                                \
64}
65
66#define  DISCRETE_CLASS_RESET(_name, _maxout)             \
67class DISCRETE_CLASS_NAME(_name): public discrete_base_node            \
68{                                                      \
69public:                                                   \
70   DISCRETE_CLASS_CONSTRUCTOR(_name, base)                        \
71   void reset(void);                                       \
72   int max_output(void) { return _maxout; }                     \
73   DISCRETE_CLASS_DESTRUCTOR(_name)                           \
74}
75
76#define  DISCRETE_CLASSA(_name, _maxout, _priv)                   \
77class DISCRETE_CLASS_NAME(_name): public discrete_base_node, public discrete_step_interface            \
78{                                                      \
79public:                                                   \
80   DISCRETE_CLASS_CONSTRUCTOR(_name, base)                        \
81   void step(void);                                       \
82   void reset(void);                                       \
83   void start(void);                                       \
84   void stop(void);                                       \
85   int max_output(void) { return _maxout; }                     \
86   DISCRETE_CLASS_DESTRUCTOR(_name)                           \
87private:                                                \
88   _priv                                                \
89}
90
91class DISCRETE_CLASS_NAME(special): public discrete_base_node
92{
93public:
94   DISCRETE_CLASS_CONSTRUCTOR(special, base)
95   int max_output(void) { return 0; }
96   DISCRETE_CLASS_DESTRUCTOR(special)
97};
98
99class DISCRETE_CLASS_NAME(unimplemented): public discrete_base_node
100{
101public:
102   DISCRETE_CLASS_CONSTRUCTOR(unimplemented, base)
103   int max_output(void) { return 0; }
104   DISCRETE_CLASS_DESTRUCTOR(unimplemented)
105};
106
107struct dst_size_context
108{
109//   int size;
110};
111
112
113/*************************************
114 *
115 *  disc_sys.c
116 *
117 *************************************/
118
119class DISCRETE_CLASS_NAME(dso_output): public discrete_base_node, public discrete_output_interface, public discrete_step_interface
120{
121public:
122   DISCRETE_CLASS_CONSTRUCTOR(dso_output, base)
123   void step(void) {
124      /* Add gain to the output and put into the buffers */
125      /* Clipping will be handled by the main sound system */
126      double val = DISCRETE_INPUT(0) * DISCRETE_INPUT(1);
127      *m_ptr++ = val;
128   }
129   int max_output(void) { return 0; }
130   void set_output(stream_sample_t *ptr) { m_ptr = ptr; }
131   DISCRETE_CLASS_DESTRUCTOR(dso_output)
132private:
133   stream_sample_t      *m_ptr;
134};
135
136DISCRETE_CLASSA(dso_csvlog, 0,
137   FILE *m_csv_file;
138   INT64 m_sample_num;
139   char  m_name[32];
140);
141
142DISCRETE_CLASSA(dso_wavlog, 0,
143   wav_file *m_wavfile;
144   char      m_name[32];
145);
146
147/*************************************
148 *
149 *  disc_inp.c
150 *
151 *************************************/
152
153class DISCRETE_CLASS_NAME(dss_adjustment): public discrete_base_node, public discrete_step_interface
154{
155public:
156   DISCRETE_CLASS_CONSTRUCTOR(dss_adjustment, base)
157   void step(void);
158   void reset(void);
159private:
160   const input_port_config *m_port;
161   INT32               m_lastpval;
162   INT32               m_pmin;
163   double               m_pscale;
164   double               m_min;
165   double               m_scale;
166   DISCRETE_CLASS_DESTRUCTOR(dss_adjustment)
167};
168
169DISCRETE_CLASS_RESET(dss_constant, 1);
170
171class DISCRETE_CLASS_NAME(dss_input_data): public discrete_base_node, public discrete_input_interface
172{
173public:
174   DISCRETE_CLASS_CONSTRUCTOR(dss_input_data, base)
175   void reset(void);
176   void input_write(int sub_node, UINT8 data );
177   DISCRETE_CLASS_DESTRUCTOR(dss_input_data)
178private:
179   double      m_gain;            /* node gain */
180   double      m_offset;         /* node offset */
181   UINT8      m_data;            /* data written */
182};
183
184class DISCRETE_CLASS_NAME(dss_input_logic): public discrete_base_node, public discrete_input_interface
185{
186public:
187   DISCRETE_CLASS_CONSTRUCTOR(dss_input_logic, base)
188   void reset(void);
189   void input_write(int sub_node, UINT8 data );
190   DISCRETE_CLASS_DESTRUCTOR(dss_input_logic)
191private:
192   double      m_gain;            /* node gain */
193   double      m_offset;         /* node offset */
194   UINT8      m_data;            /* data written */
195};
196
197class DISCRETE_CLASS_NAME(dss_input_not): public discrete_base_node, public discrete_input_interface
198{
199public:
200   DISCRETE_CLASS_CONSTRUCTOR(dss_input_not, base)
201   void reset(void);
202   void input_write(int sub_node, UINT8 data );
203   DISCRETE_CLASS_DESTRUCTOR(dss_input_not)
204private:
205   double      m_gain;            /* node gain */
206   double      m_offset;         /* node offset */
207   UINT8      m_data;            /* data written */
208};
209
210class DISCRETE_CLASS_NAME(dss_input_pulse): public discrete_base_node, public discrete_input_interface, public discrete_step_interface
211{
212public:
213   DISCRETE_CLASS_CONSTRUCTOR(dss_input_pulse, base)
214   void step(void);
215   void reset(void);
216   void input_write(int sub_node, UINT8 data );
217   DISCRETE_CLASS_DESTRUCTOR(dss_input_pulse)
218private:
219   double      m_gain;            /* node gain */
220   double      m_offset;         /* node offset */
221   UINT8      m_data;            /* data written */
222};
223
224class DISCRETE_CLASS_NAME(dss_input_stream): public discrete_base_node, public discrete_input_interface, public discrete_step_interface
225{
226public:
227   DISCRETE_CLASS_CONSTRUCTOR(dss_input_stream, base)
228   void step(void);
229   void reset(void);
230   void start(void);
231   void input_write(int sub_node, UINT8 data );
232   virtual bool is_buffered(void) { return false; }
233//protected:
234   UINT32            m_stream_in_number;
235   stream_sample_t      *m_ptr;         /* current in ptr for stream */
236   DISCRETE_CLASS_DESTRUCTOR(dss_input_stream)
237private:
238   static STREAM_UPDATE( static_stream_generate );
239   void stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples);
240
241   double      m_gain;            /* node gain */
242   double      m_offset;         /* node offset */
243   UINT8      m_data;            /* data written */
244   UINT8            m_is_buffered;
245   /* the buffer stream */
246   sound_stream       *m_buffer_stream;
247};
248
249class DISCRETE_CLASS_NAME(dss_input_buffer): public DISCRETE_CLASS_NAME(dss_input_stream)
250{
251public:
252   DISCRETE_CLASS_CONSTRUCTOR(dss_input_buffer, dss_input_stream)
253   bool is_buffered(void) { return true; }
254   DISCRETE_CLASS_DESTRUCTOR(dss_input_buffer)
255};
256
257#include "disc_wav.h"
258#include "disc_mth.h"
259#include "disc_flt.h"
260#include "disc_dev.h"
261
262#endif /* __DISCRETE_H__ */
src/emu/sound/disc_mth.c
r10048r10049
4949
5050#include <float.h>
5151
52struct dst_comp_adder_context
53{
54   double   total[256];
55};
5652
57struct 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};
6553
66struct dst_dac_r1_context
67{
68   double   exponent;
69   double   last_v;
70   double   v_step[256];
71   int      has_c_filter;
72};
73
74struct dst_diode_mix_context
75{
76   int      size;
77   double   v_junction[8];
78};
79
80struct dst_flipflop_context
81{
82   int last_clk;
83};
84
85struct 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
95struct 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
113struct dst_oneshot_context
114{
115   double   countdown;
116   int      state;
117   int      last_trig;
118   int      type;
119};
120
121struct 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
128struct dst_samphold_context
129{
130   double last_input;
131   int clocktype;
132};
133
134struct 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
145struct dst_size_context
146{
147   int size;
148};
149
150struct 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
161struct 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
173struct 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
19554/************************************************************************
19655 *
19756 * DST_ADDER - This is a 4 channel input adder with enable function
r10048r10049
21372{
21473   if(DST_ADDER__ENABLE)
21574   {
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;
21776   }
21877   else
21978   {
220      node->output[0]=0;
79      this->output[0]=0;
22180   }
22281}
22382
r10048r10049
23695
23796DISCRETE_STEP(dst_comp_adder)
23897{
239   DISCRETE_DECLARE_CONTEXT(dst_comp_adder)
24098   int select;
24199
242100   select = (int)DST_COMP_ADDER__SELECT;
243101   assert(select < 256);
244   node->output[0] = context->total[select];
102   this->output[0] = m_total[select];
245103}
246104
247105DISCRETE_RESET(dst_comp_adder)
248106{
249   DISCRETE_DECLARE_CONTEXT(dst_comp_adder)
250107   DISCRETE_DECLARE_INFO(discrete_comp_adder_table)
251108
252109   int i, bit;
r10048r10049
261118      switch (info->type)
262119      {
263120         case DISC_COMP_P_CAPACITOR:
264            context->total[i] = info->cDefault;
121            m_total[i] = info->cDefault;
265122            for(bit = 0; bit < bit_length; bit++)
266123            {
267124               if (i & (1 << bit))
268                  context->total[i] += info->c[bit];
125                  m_total[i] += info->c[bit];
269126            }
270127            break;
271128         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;
273130            for(bit = 0; bit < bit_length; bit++)
274131            {
275132               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];
277134            }
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];
280137            break;
281138      }
282139   }
283   node->output[0] = context->total[0];
140   this->output[0] = m_total[0];
284141}
285142
286143/************************************************************************
r10048r10049
298155
299156DISCRETE_STEP(dst_clamp)
300157{
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;
304161}
305162
306163
r10048r10049
321178
322179DISCRETE_STEP(dst_dac_r1)
323180{
324   DISCRETE_DECLARE_CONTEXT(dst_dac_r1)
325
326181   int      data = (int)DST_DAC_R1__DATA;
327   double   v = context->v_step[data];
182   double   v = m_v_step[data];
328183   double   x_time = DST_DAC_R1__DATA - data;
329   double   last_v = context->last_v;
184   double   last_v = m_last_v;
330185
331   context->last_v = v;
186   m_last_v = v;
332187
333188   if (x_time > 0)
334189      v = x_time * (v - last_v) + last_v;
335190
336191   /* Filter if needed, else just output voltage */
337   if (context->has_c_filter)
192   if (m_has_c_filter)
338193   {
339      double out = node->output[0];
194      double out = this->output[0];
340195      double v_diff = v - out;
341196      /* optimization - if charged close enough to voltage */
342197      if (fabs(v_diff) < 0.000001)
343         node->output[0] = v;
198         this->output[0] = v;
344199      else
345200      {
346         out += v_diff * context->exponent;
347         node->output[0] = out;
201         out += v_diff * m_exponent;
202         this->output[0] = out;
348203      }
349204   }
350205   else
351      node->output[0] = v;
206      this->output[0] = v;
352207}
353208
354209DISCRETE_RESET(dst_dac_r1)
355210{
356   DISCRETE_DECLARE_CONTEXT(dst_dac_r1)
357211   DISCRETE_DECLARE_INFO(discrete_dac_r1_ladder)
358212
359213   int   bit;
r10048r10049
363217   double i_bias;
364218   double v_on = DST_DAC_R1__VON;
365219
366   context->last_v = 0;
220   m_last_v = 0;
367221
368222   /* Calculate the Millman current of the bias circuit */
369223   if (info->rBias > 0)
r10048r10049
379233   if (ladderLength < 2 && info->rBias == 0 && info->rGnd == 0)
380234   {
381235      /* 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");
383237   }
384238   if (ladderLength > DISC_LADDER_MAXRES )
385239   {
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");
387241   }
388242
389243   /*
r10048r10049
400254   if (info->rGnd > 0)  r_total += 1.0 / info->rGnd;
401255   r_total = 1.0 / r_total;
402256
403   node->output[0] = 0;
257   this->output[0] = 0;
404258
405259   if (info->cFilter > 0)
406260   {
407      context->has_c_filter = 1;
261      m_has_c_filter = 1;
408262      /* Setup filter constant */
409      context->exponent = RC_CHARGE_EXP(r_total * info->cFilter);
263      m_exponent = RC_CHARGE_EXP_CLASS(r_total * info->cFilter);
410264   }
411265   else
412      context->has_c_filter = 0;
266      m_has_c_filter = 0;
413267
414268   /* pre-calculate all possible values to speed up step routine */
415269   for(int i = 0; i < total_steps; i++)
r10048r10049
432286            i_total += i_bit;
433287         }
434288      }
435      context->v_step[i] = i_total * r_total;
289      m_v_step[i] = i_total * r_total;
436290   }
437291}
438292
r10048r10049
451305
452306DISCRETE_STEP(dst_diode_mix)
453307{
454   DISCRETE_DECLARE_CONTEXT(dst_diode_mix)
455
456308   double   val, max = 0;
457309   int      addr;
458310
459   for (addr = 0; addr < context->size; addr++)
311   for (addr = 0; addr < m_size; addr++)
460312   {
461      val = DST_DIODE_MIX__INP(addr) - context->v_junction[addr];
313      val = DST_DIODE_MIX__INP(addr) - m_v_junction[addr];
462314      if (val > max) max = val;
463315   }
464316   if (max < 0) max = 0;
465   node->output[0] = max;
317   this->output[0] = max;
466318}
467319
468320DISCRETE_RESET(dst_diode_mix)
469321{
470   DISCRETE_DECLARE_CONTEXT(dst_diode_mix)
471322   DISCRETE_DECLARE_INFO(double)
472323
473324   int      addr;
474325
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);
477328
478   for (addr = 0; addr < context->size; addr++)
329   for (addr = 0; addr < m_size; addr++)
479330   {
480331      if (info == NULL)
481332      {
482333         /* setup default junction voltage */
483         context->v_junction[addr] = 0.5;
334         m_v_junction[addr] = 0.5;
484335      }
485336      else
486337      {
487338         /* use supplied junction voltage */
488         context->v_junction[addr] = *info++;
339         m_v_junction[addr] = *info++;
489340      }
490341   }
491   DISCRETE_STEP_CALL(dst_diode_mix);
342   this->step();
492343}
493344
494345
r10048r10049
511362   {
512363      if(DST_DIVIDE__DIV == 0)
513364      {
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());
516367      }
517368      else
518369      {
519         node->output[0]= DST_DIVIDE__IN / DST_DIVIDE__DIV;
370         this->output[0]= DST_DIVIDE__IN / DST_DIVIDE__DIV;
520371      }
521372   }
522373   else
523374   {
524      node->output[0]=0;
375      this->output[0]=0;
525376   }
526377}
527378
r10048r10049
541392
542393DISCRETE_STEP(dst_gain)
543394{
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;
545396}
546397
547398
r10048r10049
595446
596447DISCRETE_STEP(dst_integrate)
597448{
598   DISCRETE_DECLARE_CONTEXT(dst_integrate)
599449   DISCRETE_DECLARE_INFO(discrete_integrate_info)
600450
601451   int      trig0, trig1;
r10048r10049
610460            /* This forces the cap to completely charge,
611461                 * and the output to go to it's max value.
612462                 */
613            node->output[0] = context->v_max_out;
463            this->output[0] = m_v_max_out;
614464            return;
615465         }
616         node->output[0] -= context->change;
466         this->output[0] -= m_change;
617467         break;
618468
619469      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;
621471         i_pos = (DST_INTEGRATE__TRG0 - OP_AMP_NORTON_VBE) / info->r2;
622472         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;
624474         break;
625475
626476      case DISC_INTEGRATE_OP_AMP_2 | DISC_OP_AMP_IS_NORTON:
627477         trig0  = (int)DST_INTEGRATE__TRG0;
628478         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;
633483         break;
634484   }
635485
636486   /* 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;
639489}
640490
641491DISCRETE_RESET(dst_integrate)
642492{
643   DISCRETE_DECLARE_CONTEXT(dst_integrate)
644493   DISCRETE_DECLARE_INFO(discrete_integrate_info)
645494
646495   double   i, v;
647496
648497   if (info->type & DISC_OP_AMP_IS_NORTON)
649498   {
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;
653502   }
654503   else
655504   {
656      context->v_max_out =  info->vP - OP_AMP_VP_RAIL_OFFSET;
505      m_v_max_out =  info->vP - OP_AMP_VP_RAIL_OFFSET;
657506
658507      v = info->v1 * info->r3 / (info->r2 + info->r3);   /* vRef */
659508      v = info->v1 - v;   /* actual charging voltage */
660509      i = v / info->r1;
661      context->change = i / node->info->sample_rate / info->c;
510      m_change = i / this->sample_rate() / info->c;
662511   }
663   node->output[0] = 0;
512   this->output[0] = 0;
664513}
665514
666515
r10048r10049
676525
677526DISCRETE_STEP(dst_logic_inv)
678527{
679   node->output[0] = DST_LOGIC_INV__IN ? 0.0 : 1.0;
528   this->output[0] = DST_LOGIC_INV__IN ? 0.0 : 1.0;
680529}
681530
682531/************************************************************************
r10048r10049
691540
692541DISCRETE_STEP(dst_bits_decode)
693542{
694   DISCRETE_DECLARE_CONTEXT(dst_bits_decode)
695
696543   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;
699546
700547   if (last_val != new_val || last_had_x_time)
701548   {
702549      int i, new_bit, last_bit, last_bit_had_x_time, bit_changed;
703550      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;
707554      int has_x_time = x_time > 0 ? 1 : 0;
708555      double out = 0;
709556      double v_out = DST_BITS_DECODE__VOUT;
r10048r10049
737584            else
738585               out *= new_bit;
739586         }
740         node->output[i] = out;
587         this->output[i] = out;
741588         if (has_x_time && bit_changed)
742589            /* set */
743            context->last_had_x_time |= 1 << (i + from);
590            m_last_had_x_time |= 1 << (i + from);
744591         else
745592            /* clear */
746            context->last_had_x_time &= ~(1 << (i + from));
593            m_last_had_x_time &= ~(1 << (i + from));
747594      }
748      context->last_val = new_val;
595      m_last_val = new_val;
749596   }
750597}
751598
752599DISCRETE_RESET(dst_bits_decode)
753600{
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;
758603   if (DST_BITS_DECODE__VOUT == 0)
759      context->decode_x_time = 1;
604      m_decode_x_time = 1;
760605   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;
763608
764   DISCRETE_STEP_CALL(dst_bits_decode);
609   this->step();
765610}
766611
767612
r10048r10049
782627
783628DISCRETE_STEP(dst_logic_and)
784629{
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;
786631}
787632
788633/************************************************************************
r10048r10049
802647
803648DISCRETE_STEP(dst_logic_nand)
804649{
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;
806651}
807652
808653/************************************************************************
r10048r10049
822667
823668DISCRETE_STEP(dst_logic_or)
824669{
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;
826671}
827672
828673/************************************************************************
r10048r10049
842687
843688DISCRETE_STEP(dst_logic_nor)
844689{
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;
846691}
847692
848693/************************************************************************
r10048r10049
858703
859704DISCRETE_STEP(dst_logic_xor)
860705{
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;
862707}
863708
864709/************************************************************************
r10048r10049
874719
875720DISCRETE_STEP(dst_logic_nxor)
876721{
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;
878723}
879724
880725
r10048r10049
895740
896741DISCRETE_STEP(dst_logic_dff)
897742{
898   DISCRETE_DECLARE_CONTEXT(dst_flipflop)
899
900743   int clk = (int)DST_LOGIC_DFF__CLOCK;
901744
902745   if (DST_LOGIC_DFF__RESET)
903      node->output[0] = 0;
746      this->output[0] = 0;
904747   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;
909752}
910753
911DISCRETE_RESET(dst_logic_ff)
754DISCRETE_RESET(dst_logic_dff)
912755{
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;
918758}
919759
920760
r10048r10049
937777
938778DISCRETE_STEP(dst_logic_jkff)
939779{
940   DISCRETE_DECLARE_CONTEXT(dst_flipflop)
941
942780   int clk = (int)DST_LOGIC_JKFF__CLOCK;
943781   int j   = (int)DST_LOGIC_JKFF__J;
944782   int k   = (int)DST_LOGIC_JKFF__K;
945783
946784   if (DST_LOGIC_JKFF__RESET)
947      node->output[0] = 0;
785      this->output[0] = 0;
948786   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 */
951789   {
952790      if (!j)
953791      {
954792         /* J=0, K=0 - Hold */
955793         if (k)
956794            /* J=0, K=1 - Reset */
957            node->output[0] = 0;
795            this->output[0] = 0;
958796      }
959797      else
960798      {
961799         if (!k)
962800            /* J=1, K=0 - Set */
963            node->output[0] = 1;
801            this->output[0] = 1;
964802         else
965803            /* J=1, K=1 - Toggle */
966            node->output[0] = !(int)node->output[0];
804            this->output[0] = !(int)this->output[0];
967805      }
968806   }
969   context->last_clk = clk;
807   m_last_clk = clk;
970808}
971809
810DISCRETE_RESET(dst_logic_jkff)
811{
812   m_last_clk = 0;
813   this->output[0]   = 0;
814}
972815
973816/************************************************************************
974817 *
r10048r10049
983826
984827DISCRETE_STEP(dst_logic_shift)
985828{
986   DISCRETE_DECLARE_CONTEXT(dst_shift)
987
988829   double   cycles;
989830   double   ds_clock;
990831   int      clock = 0, inc = 0;
991832
992833   int input_bit = (DST_LOGIC_SHIFT__IN != 0) ? 1 : 0;
993834   ds_clock = DST_LOGIC_SHIFT__CLK;
994   if (context->clock_type == DISC_CLK_IS_FREQ)
835   if (m_clock_type == DISC_CLK_IS_FREQ)
995836   {
996837      /* 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;
998839      inc    = (int)cycles;
999      context->t_left = (cycles - inc) / ds_clock;
840      m_t_left = (cycles - inc) / ds_clock;
1000841   }
1001842   else
1002843   {
r10048r10049
1004845   }
1005846
1006847   /* 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)
1008849   {
1009      context->shift_data = 0;
1010      node->output[0] = 0;
850      m_shift_data = 0;
851      this->output[0] = 0;
1011852      return;
1012853   }
1013854
1014855   /* increment clock */
1015   switch (context->clock_type)
856   switch (m_clock_type)
1016857   {
1017858      case DISC_CLK_ON_F_EDGE:
1018859      case DISC_CLK_ON_R_EDGE:
1019860         /* See if the clock has toggled to the proper edge */
1020861         clock = (clock != 0);
1021         if (context->last != clock)
862         if (m_last != clock)
1022863         {
1023            context->last = clock;
1024            if (context->clock_type == clock)
864            m_last = clock;
865            if (m_clock_type == clock)
1025866            {
1026867               /* Toggled */
1027868               inc = 1;
r10048r10049
1037878
1038879   if (inc > 0)
1039880   {
1040      if (context->shift_r)
881      if (m_shift_r)
1041882      {
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);
1044885         inc--;
1045         context->shift_data >>= inc;
886         m_shift_data >>= inc;
1046887      }
1047888      else
1048889      {
1049         context->shift_data <<= 1;
1050         context->shift_data |= input_bit;
890         m_shift_data <<= 1;
891         m_shift_data |= input_bit;
1051892         inc--;
1052         context->shift_data <<= inc;
893         m_shift_data <<= inc;
1053894      }
1054      context->shift_data &= context->bit_mask;
895      m_shift_data &= m_bit_mask;
1055896   }
1056897
1057   node->output[0] = context->shift_data;
898   this->output[0] = m_shift_data;
1058899}
1059900
1060901DISCRETE_RESET(dst_logic_shift)
1061902{
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;
1063907
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;
1073912}
1074913
1075914/************************************************************************
r10048r10049
1093932   int   addr = DST_LOOKUP_TABLE__IN;
1094933
1095934   if (addr < 0 || addr >= DST_LOOKUP_TABLE__SIZE)
1096      node->output[0] = 0;
935      this->output[0] = 0;
1097936   else
1098      node->output[0] = info[addr];
937      this->output[0] = info[addr];
1099938}
1100939
1101940
r10048r10049
1154993
1155994DISCRETE_STEP(dst_mixer)
1156995{
1157   DISCRETE_DECLARE_CONTEXT(dst_mixer)
1158996   DISCRETE_DECLARE_INFO(discrete_mixer_desc)
1159997
1160998   double   v, vTemp, r_total, rTemp, rTemp2 = 0;
r10048r10049
11621000   int      bit, connected;
11631001
11641002   /* 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;
11671005   int      bit_mask = 1;
11681006   int      has_rF = (info->rF != 0);
1169   int      type = context->type;
1007   int      type = m_type;
11701008   double   v_ref = info->vRef;
11711009   double   rI = info->rI;
11721010
11731011   if (EXPECTED(DST_MIXER__ENABLE))
11741012   {
1175      r_total = context->r_total;
1013      r_total = m_r_total;
11761014
1177      if (UNEXPECTED(context->r_node_bit_flag != 0))
1015      if (UNEXPECTED(m_r_node_bit_flag != 0))
11781016      {
11791017         /* loop and do any high pass filtering for connected caps */
11801018         /* but first see if there is an r_node for the current path */
11811019         /* 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++)
11831021         {
11841022            rTemp     = info->r[bit];
11851023            connected = 1;
r10048r10049
11891027            if (r_node_bit_flag & bit_mask)
11901028            {
11911029               /* 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)
11931031                  connected = 0;
11941032               else
11951033               {
11961034                  /* value currently holds resistance */
1197                  rTemp   += *context->r_node[bit];
1035                  rTemp   += *m_r_node[bit];
11981036                  r_total += 1.0 / rTemp;
11991037                  /* is there a capacitor? */
12001038                  if (c_bit_flag & bit_mask)
r10048r10049
12171055                           break;
12181056                     }
12191057                     /* 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])
12211059                     {
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];
12241062                     }
12251063                  }
12261064               }
r10048r10049
12321070               if (c_bit_flag & bit_mask)
12331071               {
12341072                  /* 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];
12371075               }
12381076               i += ((type == DISC_MIXER_IS_OP_AMP) ? v_ref - vTemp : vTemp) / rTemp;
12391077            }
r10048r10049
12431081      else if (UNEXPECTED(c_bit_flag != 0))
12441082      {
12451083         /* 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++)
12471085         {
12481086            vTemp = DST_MIXER__IN(bit);
12491087
12501088            if (c_bit_flag & (1 << bit))
12511089            {
12521090               /* 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];
12551093            }
12561094            i += ((type == DISC_MIXER_IS_OP_AMP) ? v_ref - vTemp : vTemp) / info->r[bit];
12571095         }
r10048r10049
12611099         /* no r_nodes or c_nodes, mixing only */
12621100         if (UNEXPECTED(type == DISC_MIXER_IS_OP_AMP))
12631101         {
1264            for (bit = 0; bit < context->size; bit++)
1102            for (bit = 0; bit < m_size; bit++)
12651103               i += ( v_ref - DST_MIXER__IN(bit) ) / info->r[bit];
12661104         }
12671105         else
12681106         {
1269            for (bit = 0; bit < context->size; bit++)
1107            for (bit = 0; bit < m_size; bit++)
12701108               i += DST_MIXER__IN(bit) / info->r[bit];
12711109         }
12721110      }
r10048r10049
12811119      v = i * ((type == DISC_MIXER_IS_OP_AMP) ? info->rF : r_total);
12821120
12831121      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));
12851123
12861124      /* Do the low pass filtering for cF */
12871125      if (EXPECTED(info->cF != 0))
r10048r10049
12891127         if (UNEXPECTED(r_node_bit_flag != 0))
12901128         {
12911129            /* 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);
12931131         }
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;
12961134      }
12971135
12981136      /* Do the high pass filtering for cAmp */
12991137      if (EXPECTED(info->cAmp != 0))
13001138      {
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;
13031141      }
1304      node->output[0] = v * info->gain;
1142      this->output[0] = v * info->gain;
13051143   }
13061144   else
13071145   {
1308      node->output[0] = 0;
1146      this->output[0] = 0;
13091147   }
13101148}
13111149
13121150
13131151DISCRETE_RESET(dst_mixer)
13141152{
1315   DISCRETE_DECLARE_CONTEXT(dst_mixer)
13161153   DISCRETE_DECLARE_INFO(discrete_mixer_desc)
13171154
1318   node_description *r_node;
1155   discrete_base_node *r_node;
13191156
13201157   int      bit;
13211158   double   rTemp = 0;
13221159
13231160   /* link to r_node outputs */
1324   context->r_node_bit_flag = 0;
1161   m_r_node_bit_flag = 0;
13251162   for (bit = 0; bit < 8; bit++)
13261163   {
1327      r_node = discrete_find_node(node->info, info->r_node[bit]);
1164      r_node = this->device->discrete_find_node(info->r_node[bit]);
13281165      if (r_node != NULL)
13291166      {
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;
13321169      }
13331170      else
1334         context->r_node[bit] = NULL;
1171         m_r_node[bit] = NULL;
13351172
13361173      /* flag any caps */
13371174      if (info->c[bit] != 0)
1338         context->c_bit_flag |= 1 << bit;
1175         m_c_bit_flag |= 1 << bit;
13391176   }
13401177
1341   context->size = node->active_inputs() - 1;
1178   m_size = this->active_inputs() - 1;
13421179
13431180   /*
13441181     * THERE IS NO ERROR CHECKING!!!!!!!!!
r10048r10049
13461183     * then you deserve a crash.
13471184     */
13481185
1349   context->type = info->type;
1186   m_type = info->type;
13501187   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;
13521189
13531190   /*
13541191     * Calculate the total of all resistors in parallel.
13551192     * This is the combined resistance of the voltage sources.
13561193     * Also calculate the exponents while we are here.
13571194     */
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++)
13601197   {
13611198      if ((info->r[bit] != 0) && !info->r_node[bit] )
13621199      {
1363         context->r_total += 1.0 / info->r[bit];
1200         m_r_total += 1.0 / info->r[bit];
13641201      }
13651202
1366      context->v_cap[bit]       = 0;
1367      context->exponent_rc[bit] = 0;
1203      m_v_cap[bit]       = 0;
1204      m_exponent_rc[bit] = 0;
13681205      if ((info->c[bit] != 0)  && !info->r_node[bit])
13691206      {
1370         switch (context->type)
1207         switch (m_type)
13711208         {
13721209            case DISC_MIXER_IS_RESISTOR:
13731210               /* is there an rF? */
r10048r10049
13851222               break;
13861223         }
13871224         /* 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]);
13891226      }
13901227   }
13911228
13921229   if (info->rF != 0)
13931230   {
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;
13951232   }
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;
13971234
1398   context->v_cap_f      = 0;
1399   context->exponent_c_f = 0;
1235   m_v_cap_f      = 0;
1236   m_exponent_c_f = 0;
14001237   if (info->cF != 0)
14011238   {
14021239      /* 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);
14041241   }
14051242
1406   context->v_cap_amp      = 0;
1407   context->exponent_c_amp = 0;
1243   m_v_cap_amp      = 0;
1244   m_exponent_c_amp = 0;
14081245   if (info->cAmp != 0)
14091246   {
14101247      /* Setup filter constants */
14111248      /* We will use 100k ohms as an average final stage impedance. */
14121249      /* 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);
14141251   }
14151252
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;
14171254
1418   node->output[0] = 0;
1255   this->output[0] = 0;
14191256}
14201257
14211258
r10048r10049
14351272
14361273DISCRETE_STEP(dst_multiplex)
14371274{
1438   DISCRETE_DECLARE_CONTEXT(dst_size)
1439
14401275   int addr;
14411276
14421277   addr = DST_MULTIPLEX__ADDR;   /* FP to INT */
1443   if ((addr >= 0) && (addr < context->size))
1278   if ((addr >= 0) && (addr < m_size))
14441279   {
1445      node->output[0] = DST_MULTIPLEX__INP(addr);
1280      this->output[0] = DST_MULTIPLEX__INP(addr);
14461281   }
14471282   else
14481283   {
14491284      /* 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);
14511286   }
14521287}
14531288
14541289DISCRETE_RESET(dst_multiplex)
14551290{
1456   DISCRETE_DECLARE_CONTEXT(dst_size)
1291   m_size = this->active_inputs() - 1;
14571292
1458   context->size = node->active_inputs() - 1;
1459
1460   DISCRETE_STEP_CALL(dst_multiplex);
1293   this->step();
14611294}
14621295
14631296
r10048r10049
14811314
14821315DISCRETE_STEP(dst_oneshot)
14831316{
1484   DISCRETE_DECLARE_CONTEXT(dst_oneshot)
1485
14861317   int trigger = (DST_ONESHOT__TRIG != 0);
14871318
14881319   /* If the state is triggered we will need to countdown later */
1489   int do_count = context->state;
1320   int do_count = m_state;
14901321
14911322   if (UNEXPECTED(DST_ONESHOT__RESET))
14921323   {
14931324      /* Hold in Reset */
1494      node->output[0] = 0;
1495      context->state  = 0;
1325      this->output[0] = 0;
1326      m_state  = 0;
14961327   }
14971328   else
14981329   {
14991330      /* are we at an edge? */
1500      if (UNEXPECTED(trigger != context->last_trig))
1331      if (UNEXPECTED(trigger != m_last_trig))
15011332      {
15021333         /* There has been a trigger edge */
1503         context->last_trig = trigger;
1334         m_last_trig = trigger;
15041335
15051336         /* Is it the proper edge trigger */
1506         if ((context->type & DISC_ONESHOT_REDGE) ? trigger : !trigger)
1337         if ((m_type & DISC_ONESHOT_REDGE) ? trigger : !trigger)
15071338         {
1508            if (!context->state)
1339            if (!m_state)
15091340            {
15101341               /* 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;
15141345            }
15151346            else
15161347            {
15171348               /* See if we retrigger */
1518               if (context->type & DISC_ONESHOT_RETRIG)
1349               if (m_type & DISC_ONESHOT_RETRIG)
15191350               {
15201351                  /* Retrigger */
1521                  context->countdown = DST_ONESHOT__WIDTH;
1352                  m_countdown = DST_ONESHOT__WIDTH;
15221353                  do_count = 0;
15231354               }
15241355            }
r10048r10049
15271358
15281359      if (UNEXPECTED(do_count))
15291360      {
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)
15321363         {
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;
15361367         }
15371368      }
15381369   }
r10048r10049
15411372
15421373DISCRETE_RESET(dst_oneshot)
15431374{
1544   DISCRETE_DECLARE_CONTEXT(dst_oneshot)
1375   m_countdown = 0;
1376   m_state     = 0;
15451377
1546   context->countdown = 0;
1547   context->state     = 0;
1378   m_last_trig = 0;
1379   m_type = DST_ONESHOT__TYPE;
15481380
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;
15531382}
15541383
15551384
r10048r10049
15741403
15751404DISCRETE_STEP(dst_ramp)
15761405{
1577   DISCRETE_DECLARE_CONTEXT(dst_ramp)
1578
15791406   if(DST_RAMP__ENABLE)
15801407   {
1581      if (!context->last_en)
1408      if (!m_last_en)
15821409      {
1583         context->last_en = 1;
1584         node->output[0]  = DST_RAMP__START;
1410         m_last_en = 1;
1411         this->output[0]  = DST_RAMP__START;
15851412      }
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;
15881415      /* 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;
15931420   }
15941421   else
15951422   {
1596      context->last_en = 0;
1423      m_last_en = 0;
15971424      /* Disabled so clamp to output */
1598      node->output[0] = DST_RAMP__CLAMP;
1425      this->output[0] = DST_RAMP__CLAMP;
15991426   }
16001427}
16011428
16021429DISCRETE_RESET(dst_ramp)
16031430{
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;
16101435}
16111436
16121437
r10048r10049
16251450
16261451DISCRETE_STEP(dst_samphold)
16271452{
1628   DISCRETE_DECLARE_CONTEXT(dst_samphold)
1629
1630   switch(context->clocktype)
1453   switch(m_clocktype)
16311454   {
16321455      case DISC_SAMPHOLD_REDGE:
16331456         /* 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;
16351458         break;
16361459      case DISC_SAMPHOLD_FEDGE:
16371460         /* 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;
16391462         break;
16401463      case DISC_SAMPHOLD_HLATCH:
16411464         /* 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;
16431466         break;
16441467      case DISC_SAMPHOLD_LLATCH:
16451468         /* 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;
16471470         break;
16481471      default:
1649         discrete_log(node->info, "dst_samphold_step - Invalid clocktype passed");
1472         this->device->discrete_log("dst_samphold_step - Invalid clocktype passed");
16501473         break;
16511474   }
16521475   /* Save the last value */
1653   context->last_input = DST_SAMPHOLD__CLOCK;
1476   m_last_input = DST_SAMPHOLD__CLOCK;
16541477}
16551478
16561479DISCRETE_RESET(dst_samphold)
16571480{
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;
16621483   /* 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();
16651486}
16661487
16671488
r10048r10049
16841505{
16851506   if(DST_SWITCH__ENABLE)
16861507   {
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;
16881509   }
16891510   else
16901511   {
1691      node->output[0] = 0;
1512      this->output[0] = 0;
16921513   }
16931514}
16941515
r10048r10049
17081529
17091530DISCRETE_STEP(dst_aswitch)
17101531{
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;
17121533}
17131534
17141535/************************************************************************
r10048r10049
17511572   double   number1,top;
17521573   int      trans_stack_ptr = 0;
17531574
1754   const char *fPTR = (const char *)node->custom_data();
1575   const char *fPTR = (const char *)this->custom_data();
17551576
17561577   top = HUGE_VAL;
17571578
r10048r10049
18321653            top = (int)number1 ^ (int)top;
18331654            break;
18341655         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());
18361657            /* 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());
18381659            break;
18391660      }
18401661   }
1841   node->output[0] = top;
1662   this->output[0] = top;
18421663}
18431664
18441665
r10048r10049
18601681
18611682DISCRETE_STEP(dst_op_amp)
18621683{
1863   DISCRETE_DECLARE_CONTEXT(dst_op_amp)
18641684   DISCRETE_DECLARE_INFO(discrete_op_amp_info)
18651685
18661686   double i_pos = 0;
r10048r10049
18731693      {
18741694         case DISC_OP_AMP_IS_NORTON:
18751695            /* work out neg pin current */
1876            if  (context->has_r1)
1696            if  (m_has_r1)
18771697            {
18781698               i_neg = (DST_OP_AMP__INP0 - OP_AMP_NORTON_VBE) / info->r1;
18791699               if (i_neg < 0) i_neg = 0;
18801700            }
1881            i_neg += context->i_fixed;
1701            i_neg += m_i_fixed;
18821702
18831703            /* work out neg pin current */
18841704            i_pos = (DST_OP_AMP__INP1 - OP_AMP_NORTON_VBE) / info->r2;
r10048r10049
18871707            /* work out current across r4 */
18881708            i = i_pos - i_neg;
18891709
1890            if (context->has_cap)
1710            if (m_has_cap)
18911711            {
1892               if (context->has_r4)
1712               if (m_has_r4)
18931713               {
18941714                  /* voltage across r4 charging cap */
18951715                  i *= info->r4;
18961716                  /* exponential charge */
1897                  context->v_cap += (i - context->v_cap) * context->exponent;
1717                  m_v_cap += (i - m_v_cap) * m_exponent;
18981718               }
18991719               else
19001720                  /* 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;
19031723            }
19041724            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;
19071727               else
19081728                  /* output just swings to rail when there is no r4 */
19091729                  if (i > 0)
1910                     node->output[0] = context->v_max;
1730                     this->output[0] = m_v_max;
19111731                  else
1912                     node->output[0] = 0;
1732                     this->output[0] = 0;
19131733
19141734            /* 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];
19181738            break;
19191739
19201740         default:
1921            node->output[0] = 0;
1741            this->output[0] = 0;
19221742      }
19231743   }
19241744   else
1925      node->output[0] = 0;
1745      this->output[0] = 0;
19261746}
19271747
19281748DISCRETE_RESET(dst_op_amp)
19291749{
1930   DISCRETE_DECLARE_CONTEXT(dst_op_amp)
19311750   DISCRETE_DECLARE_INFO(discrete_op_amp_info)
19321751
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;
19351754
1936   context->v_max = info->vP - OP_AMP_NORTON_VBE;
1755   m_v_max = info->vP - OP_AMP_NORTON_VBE;
19371756
1938   context->v_cap = 0;
1757   m_v_cap = 0;
19391758   if (info->c > 0)
19401759   {
1941      context->has_cap = 1;
1760      m_has_cap = 1;
19421761      /* Setup filter constants */
1943      if (context->has_r4)
1762      if (m_has_r4)
19441763      {
19451764         /* exponential charge */
1946         context->exponent = RC_CHARGE_EXP(info->r4 * info->c);
1765         m_exponent = RC_CHARGE_EXP_CLASS(info->r4 * info->c);
19471766      }
19481767      else
19491768         /* linear charge */
1950         context->exponent = node->info->sample_rate * info->c;
1769         m_exponent = this->sample_rate() * info->c;
19511770   }
19521771
19531772   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;
19551774   else
1956      context->i_fixed = 0;
1775      m_i_fixed = 0;
19571776}
19581777
19591778
r10048r10049
19711790
19721791DISCRETE_STEP(dst_op_amp_1sht)
19731792{
1974   DISCRETE_DECLARE_CONTEXT(dst_op_amp_1sht)
19751793   DISCRETE_DECLARE_INFO(discrete_op_amp_1sht_info)
19761794
19771795   double i_pos;
r10048r10049
19791797   double v;
19801798
19811799   /* 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;
19851803
19861804   /* 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;
19881806   if (i_neg < 0) i_neg = 0;
1989   i_neg += context->i_fixed;
1807   i_neg += m_i_fixed;
19901808
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;
19931811
19941812   /* update c1 */
19951813   /* 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])
19981816   {
19991817      /* discharge */
2000      if (context->v_cap1 > v)
1818      if (m_v_cap1 > v)
20011819         /* immediate discharge through diode */
2002         context->v_cap1 = v;
1820         m_v_cap1 = v;
20031821      else
20041822         /* 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;
20061824   }
20071825   else
20081826      /* 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;
20101828}
20111829
20121830DISCRETE_RESET(dst_op_amp_1sht)
20131831{
2014   DISCRETE_DECLARE_CONTEXT(dst_op_amp_1sht)
20151832   DISCRETE_DECLARE_INFO(discrete_op_amp_1sht_info)
20161833
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);
20241841}
20251842
20261843
r10048r10049
20461863
20471864DISCRETE_STEP(dst_tvca_op_amp)
20481865{
2049   DISCRETE_DECLARE_CONTEXT(dst_tvca_op_amp)
20501866   DISCRETE_DECLARE_INFO(discrete_op_amp_tvca_info)
20511867
20521868   int      trig0, trig1, trig2, f3;
r10048r10049
20771893      }
20781894
20791895   /* Calculate current going in to - input. */
2080   i_neg = context->i_fixed + i2 + i3;
1896   i_neg = m_i_fixed + i2 + i3;
20811897
20821898   /* Update the c1 cap voltage. */
20831899   if (dst_trigger_function(trig0, trig1, trig2, info->f2))
20841900   {
20851901      /* 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];
20871903   }
20881904   else
20891905   {
r10048r10049
20911907         * So now the discharge rate is dependent upon F3.
20921908         * If F3 is at ground then we discharge to 0V through r6.
20931909         * 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];
20951911   }
20961912
20971913   /* 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;
20991915   if ((i_pos < 0) || !f3) i_pos = 0;
21001916
21011917   /* Update the c2 cap voltage and current. */
21021918   if (info->r9 != 0)
21031919   {
21041920      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;
21071923   }
21081924
21091925   /* Update the c3 cap voltage and current. */
21101926   if (info->r11 != 0)
21111927   {
21121928      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;
21151931   }
21161932
21171933   /* Calculate output current. */
r10048r10049
21191935   if (i_out < 0) i_out = 0;
21201936
21211937   /* Convert to voltage for final output. */
2122   if (context->has_c4)
1938   if (m_has_c4)
21231939   {
2124      if (context->has_r4)
1940      if (m_has_r4)
21251941      {
21261942         /* voltage across r4 charging cap */
21271943         i_out *= info->r4;
21281944         /* exponential charge */
2129         context->v_cap4 += (i_out - context->v_cap4) * context->exponent4;
1945         m_v_cap4 += (i_out - m_v_cap4) * m_exponent4;
21301946      }
21311947      else
21321948      /* 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;
21371953   }
21381954   else
2139      node->output[0] = i_out * info->r4;
1955      this->output[0] = i_out * info->r4;
21401956
21411957
21421958
21431959   /* 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;
21451961}
21461962
21471963DISCRETE_RESET(dst_tvca_op_amp)
21481964{
2149   DISCRETE_DECLARE_CONTEXT(dst_tvca_op_amp)
21501965   DISCRETE_DECLARE_INFO(discrete_op_amp_tvca_info)
21511966
2152   context->r67 = info->r6 + info->r7;
1967   m_r67 = info->r6 + info->r7;
21531968
2154   context->v_out_max = info->vP - OP_AMP_NORTON_VBE;
1969   m_v_out_max = info->vP - OP_AMP_NORTON_VBE;
21551970   /* This is probably overkill because R5 is usually much lower then r6 or r7,
21561971     * 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;
21601975
2161   context->v_cap1 = 0;
1976   m_v_cap1 = 0;
21621977   /* Charge rate thru r5 */
21631978   /* 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);
21661981   /* 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);
21681983   /* Discharge rate thru r6 */
21691984   if (info->r6 != 0)
21701985   {
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);
21721987   }
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);
21862001
2187   DISCRETE_STEP_CALL(dst_tvca_op_amp);
2002   this->step();
21882003}
21892004
21902005
r10048r10049
22462061      {
22472062         double diff = out_high - out_low;
22482063         diff = out ? diff * x_time : diff * (1.0 - x_time);
2249         node->output[0] = out_low + diff;
2064         this->output[0] = out_low + diff;
22502065      }
22512066      else
2252         node->output[0] = out ? out_high : out_low;
2067         this->output[0] = out ? out_high : out_low;
22532068   }
22542069   else
2255      node->output[0] = out + x_time;
2070      this->output[0] = out + x_time;
22562071}
22572072
22582073
r10048r10049
24662281      {
24672282         double diff = out_high - out_low;
24682283         diff = out ? diff * x_time : diff * (1.0 - x_time);
2469         node->output[0] = out_low + diff;
2284         this->output[0] = out_low + diff;
24702285      }
24712286      else
2472         node->output[0] = out ? out_high : out_low;
2287         this->output[0] = out ? out_high : out_low;
24732288   }
24742289   else
2475      node->output[0] = out + x_time;
2290      this->output[0] = out + x_time;
24762291}
24772292
24782293
r10048r10049
26912506      {
26922507         double diff = out_high - out_low;
26932508         diff = out ? diff * x_time : diff * (1.0 - x_time);
2694         node->output[0] = out_low + diff;
2509         this->output[0] = out_low + diff;
26952510      }
26962511      else
2697         node->output[0] = out ? out_high : out_low;
2512         this->output[0] = out ? out_high : out_low;
26982513   }
26992514   else
2700      node->output[0] = out + x_time;
2515      this->output[0] = out + x_time;
27012516}
27022517
27032518
r10048r10049
29522767      {
29532768         double diff = out_high - out_low;
29542769         diff = out ? diff * x_time : diff * (1.0 - x_time);
2955         node->output[0] = out_low + diff;
2770         this->output[0] = out_low + diff;
29562771      }
29572772      else
2958         node->output[0] = out ? out_high : out_low;
2773         this->output[0] = out ? out_high : out_low;
29592774   }
29602775   else
2961      node->output[0] = out + x_time;
2776      this->output[0] = out + x_time;
29622777}
src/emu/sound/disc_mth.h
r0r10049
1#pragma once
2
3#ifndef __DISC_MTH_H__
4#define __DISC_MTH_H__
5
6/***********************************************************************
7 *
8 *  MAME - Discrete sound system emulation library
9 *
10 *  Written by Keith Wilkins (mame@esplexo.co.uk)
11 *
12 *  (c) K.Wilkins 2000
13 *
14 *  Coding started in November 2000
15 *
16 *  Additions/bugfix February 2003 - D.Renaud, F.Palazzolo, K.Wilkins
17 *  Discrete parallel tasks 2009 - Couriersud
18 *  Discrete classes 2010       - Couriersud
19 *
20 ***********************************************************************/
21
22#include "discrete.h"
23
24DISCRETE_CLASS_STEPA(dst_adder, 1, /* no context */ );
25
26DISCRETE_CLASS_STEPA(dst_clamp, 1, /* no context */ );
27
28DISCRETE_CLASS_STEPA(dst_divide, 1, /* no context */ );
29
30DISCRETE_CLASS_STEPA(dst_gain, 1, /* no context */ );
31
32DISCRETE_CLASS_STEPA(dst_logic_inv, 1, /* no context */ );
33
34DISCRETE_CLASS_STEP_RESETA(dst_bits_decode, 8,
35   int m_count;
36   int m_decode_x_time;
37   int m_from;
38   int m_last_val;
39   int m_last_had_x_time;
40);
41
42DISCRETE_CLASS_STEPA(dst_logic_and, 1, /* no context */ );
43
44DISCRETE_CLASS_STEPA(dst_logic_nand, 1, /* no context */ );
45
46DISCRETE_CLASS_STEPA(dst_logic_or, 1, /* no context */ );
47
48DISCRETE_CLASS_STEPA(dst_logic_nor, 1, /* no context */ );
49
50DISCRETE_CLASS_STEPA(dst_logic_xor, 1, /* no context */ );
51
52DISCRETE_CLASS_STEPA(dst_logic_nxor, 1, /* no context */ );
53
54DISCRETE_CLASS_STEP_RESETA(dst_logic_dff, 1,
55   int m_last_clk;
56);
57
58DISCRETE_CLASS_STEP_RESETA(dst_logic_jkff, 1,
59   int m_last_clk;
60);
61
62DISCRETE_CLASS_STEP_RESETA(dst_logic_shift, 1,
63   double   m_t_left;      /* time unused during last sample in seconds */
64   UINT32   m_shift_data;
65   UINT32   m_bit_mask;
66   UINT8   m_clock_type;
67   UINT8   m_reset_on_high;
68   UINT8   m_shift_r;
69   UINT8   m_last;
70);
71
72DISCRETE_CLASS_STEPA(dst_lookup_table, 1, /* no context */ );
73
74DISCRETE_CLASS_STEP_RESETA(dst_multiplex, 1,
75   int m_size;
76);
77
78DISCRETE_CLASS_STEP_RESETA(dst_oneshot, 1,
79   double   m_countdown;
80   int      m_state;
81   int      m_last_trig;
82   int      m_type;
83);
84
85DISCRETE_CLASS_STEP_RESETA(dst_ramp, 1,
86   double   m_step;
87   int      m_dir;      /* 1 if End is higher then Start */
88   int      m_last_en;   /* Keep track of the last enable value */
89);
90
91DISCRETE_CLASS_STEP_RESETA(dst_samphold, 1,
92   double m_last_input;
93   int      m_clocktype;
94);
95
96DISCRETE_CLASS_STEPA(dst_switch, 1, /* no context */ );
97
98DISCRETE_CLASS_STEPA(dst_aswitch, 1, /* no context */ );
99
100DISCRETE_CLASS_STEPA(dst_transform, 1, /* no context */ );
101
102/* Component specific */
103
104DISCRETE_CLASS_STEP_RESETA(dst_comp_adder, 1,
105   double   m_total[256];
106);
107
108DISCRETE_CLASS_STEP_RESETA(dst_dac_r1, 1,
109   double   m_exponent;
110   double   m_last_v;
111   double   m_v_step[256];
112   int      m_has_c_filter;
113);
114
115DISCRETE_CLASS_STEP_RESETA(dst_diode_mix, 1,
116   int      m_size;
117   double   m_v_junction[8];
118);
119
120DISCRETE_CLASS_STEP_RESETA(dst_integrate, 1,
121   double   m_change;
122   double   m_v_max_in;   /* v1 - norton VBE */
123   double   m_v_max_in_d;   /* v1 - norton VBE - diode drop */
124   double   m_v_max_out;
125);
126
127#define DISC_MIXER_MAX_INPS   8
128DISCRETE_CLASS_STEP_RESETA(dst_mixer, 1,
129   int      m_type;
130   int      m_size;
131   int      m_r_node_bit_flag;
132   int      m_c_bit_flag;
133   double   m_r_total;
134   double *m_r_node[DISC_MIXER_MAX_INPS];      /* Either pointer to resistance node output OR NULL */
135   double   m_r_last[DISC_MIXER_MAX_INPS];
136   double   m_exponent_rc[DISC_MIXER_MAX_INPS];   /* For high pass filtering cause by cIn */
137   double   m_v_cap[DISC_MIXER_MAX_INPS];         /* cap voltage of each input */
138   double   m_exponent_c_f;         /* Low pass on mixed inputs */
139   double   m_exponent_c_amp;         /* Final high pass caused by out cap and amp input impedance */
140   double   m_v_cap_f;            /* cap voltage of cF */
141   double   m_v_cap_amp;            /* cap voltage of cAmp */
142   double   m_gain;               /* used for DISC_MIXER_IS_OP_AMP_WITH_RI */
143);
144
145DISCRETE_CLASS_STEP_RESETA(dst_op_amp, 1,
146   UINT8   m_has_cap;
147   UINT8   m_has_r1;
148   UINT8   m_has_r4;
149   double   m_v_max;
150   double   m_i_fixed;
151   double   m_v_cap;
152   double   m_exponent;
153);
154
155DISCRETE_CLASS_STEP_RESETA(dst_op_amp_1sht, 1,
156   double   m_i_fixed;
157   double   m_v_max;
158   double   m_r34ratio;
159   double   m_v_cap1;
160   double   m_v_cap2;
161   double   m_exponent1c;
162   double   m_exponent1d;
163   double   m_exponent2;
164);
165
166DISCRETE_CLASS_STEP_RESETA(dst_tvca_op_amp, 1,
167   double   m_v_out_max;      /* Maximum output voltage */
168   double   m_v_trig[2];      /* Voltage used to charge cap1 based on function F3 */
169   double   m_v_trig2;         /* Voltage used to charge cap2 */
170   double   m_v_trig3;         /* Voltage used to charge cap3 */
171   double   m_i_fixed;      /* Fixed current going into - input */
172   double   m_exponent_c[2];   /* Charge exponents based on function F3 */
173   double   m_exponent_d[2];   /* Discharge exponents based on function F3 */
174   double   m_exponent2[2];   /* Discharge/charge exponents based on function F4 */
175   double   m_exponent3[2];   /* Discharge/charge exponents based on function F5 */
176   double   m_exponent4;      /* Discharge/charge exponents for c4 */
177   double   m_v_cap1;         /* charge on cap c1 */
178   double   m_v_cap2;         /* charge on cap c2 */
179   double   m_v_cap3;         /* charge on cap c3 */
180   double   m_v_cap4;         /* charge on cap c4 */
181   double   m_r67;         /* = r6 + r7 (for easy use later) */
182   UINT8   m_has_c4;
183   UINT8   m_has_r4;
184);
185
186DISCRETE_CLASS_STEPA(dst_xtime_buffer, 1, /* no context */ );
187
188DISCRETE_CLASS_STEPA(dst_xtime_and, 1, /* no context */ );
189
190DISCRETE_CLASS_STEPA(dst_xtime_or, 1, /* no context */ );
191
192DISCRETE_CLASS_STEPA(dst_xtime_xor, 1, /* no context */ );
193
194
195#endif /* __DISC_WAV_H__ */
src/emu/sound/discrete.c
r10048r10049
3939#include "discrete.h"
4040
4141
42
4243/*************************************
4344 *
4445 *  Performance
r10048r10049
5657 * Values > 500 have a slightly worse performace (too much cache misses?).
5758 */
5859
59#define MAX_SAMPLES_PER_TASK_SLICE   (240)
60#define MAX_SAMPLES_PER_TASK_SLICE   (960/4)
6061
6162/*************************************
6263 *
r10048r10049
7778
7879/*************************************
7980 *
80 *  Prototypes
81 *  Internal classes
8182 *
8283 *************************************/
8384
84static void init_nodes(discrete_info *info, const linked_list_entry *block_list, device_t *device);
85static node_description *discrete_find_node(const discrete_info *info, int node);
86//static DEVICE_RESET( discrete );
87//static STREAM_UPDATE( discrete_stream_update );
88static STREAM_UPDATE( buffer_stream_update );
85typedef struct
86{
87   const discrete_task   *task;
88   const double      *ptr;
89   int               output_node;
90   double            buffer;
91} discrete_source_node;
92typedef linked_list_t<discrete_source_node *> source_node_list_t;
8993
90static int profiling = 0;
94class discrete_task
95{
96   friend class discrete_device;
97public:
98   virtual ~discrete_task(void) { }
9199
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
120protected:
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
136private:
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
92146/*************************************
93147 *
94 *  Debug logging
148 *  Included simulation objects
95149 *
96150 *************************************/
97151
98static 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 */
104158
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
116159/*************************************
117160 *
118161 *  INLINEs
119162 *
120163 *************************************/
121164
122INLINE void linked_list_tail_add(const discrete_info *info, linked_list_entry ***list_tail_ptr, const void *ptr)
165INLINE void linked_list_tail_add(const discrete_device *info, linked_list_entry ***list_tail_ptr, const void *ptr)
123166{
124   **list_tail_ptr = auto_alloc(info->device->machine, linked_list_entry);
167   **list_tail_ptr = auto_alloc(info->machine, linked_list_entry);
125168   (**list_tail_ptr)->ptr = ptr;
126169   (**list_tail_ptr)->next = NULL;
127170   *list_tail_ptr = &((**list_tail_ptr)->next);
r10048r10049
138181   return cnt;
139182}
140183
141INLINE void linked_list_add(const discrete_info *info, linked_list_entry **list, const void *ptr)
184INLINE void linked_list_add(const discrete_device *info, linked_list_entry **list, const void *ptr)
142185{
143186   linked_list_entry *entry;
144187
145188   if (*list == NULL)
146189   {
147      *list = auto_alloc(info->device->machine, linked_list_entry);
190      *list = auto_alloc(info->machine, linked_list_entry);
148191      (*list)->ptr = ptr;
149192      (*list)->next = NULL;
150193   }
r10048r10049
152195   {
153196      for (entry = *list; entry != NULL && entry->next != NULL; entry = entry->next)
154197         ;
155      entry->next = auto_alloc(info->device->machine, linked_list_entry);
198      entry->next = auto_alloc(info->machine, linked_list_entry);
156199      entry->next->ptr = ptr;
157200      entry->next->next = NULL;
158201   }
r10048r10049
160203
161204/*************************************
162205 *
163 *  Included simulation objects
206 *  Task implementation
164207 *
165208 *************************************/
166209
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 */
210inline void discrete_task::step_nodes(void)
211{
173212
213   for_each(discrete_source_node *, sn, &source_list)
214   {
215      sn.item()->buffer = *sn.item()->ptr++;
216   }
174217
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();
175229
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();
181233
182static 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   }
188240
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}
193244
194   /* nop */
195   { DSS_NOP         ,"DSS_NOP"         , 0 ,0                                      ,NULL                  ,NULL                 ,NULL                  ,NULL                 },
245void *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);
196261
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}
206264
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                 },
265bool discrete_task::process(void)
266{
267   int samples = MIN(m_samples, MAX_SAMPLES_PER_TASK_SLICE);
225268
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;
265273
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   }
288279
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}
302295
303INLINE void step_nodes_in_list(node_list_t &list)
296void discrete_task::prepare_for_queue(int samples)
304297{
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];
305302
306   if (EXPECTED(!profiling))
303   /* initialize sources */
304   for_each(discrete_source_node *, sn, &source_list)
307305   {
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];
313307   }
314   else
308}
309
310void 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)
315318   {
316      osd_ticks_t last = get_profile_ticks();
317319
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)
319323      {
320         node_description *node = entry.item();
324         discrete_base_node *dest_node = step_entry.item()->self;
321325
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         }
326370      }
327371   }
328372}
329373
330374/*************************************
331375 *
332 *  Find a given node
376 *  Base node implementation
333377 *
334378 *************************************/
335379
336static node_description *discrete_find_node(const discrete_info *info, int node)
380discrete_base_node::discrete_base_node() :
381   m_step_intf(NULL),
382   m_input_intf(NULL)
337383{
384   output[0] = 0.0;
385}
386
387
388discrete_base_node::~discrete_base_node(void)
389{
390   /* currently noting */
391}
392
393void 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
412void discrete_base_node::start(void)
413{
414}
415
416int discrete_base_node::index(void)
417{
418   return NODE_INDEX(m_block->node);
419}
420
421void 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
427discrete_base_node *discrete_device::discrete_find_node(int node)
428{
338429   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)];
340431}
341432
433void 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
342477/*************************************
343478 *
344 *  Build import list
479 *  Device implementation
345480 *
346481 *************************************/
347482
348static 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
488void CLIB_DECL ATTR_PRINTF(2,3) discrete_device::discrete_log(const char *text, ...) const
349489{
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
510void discrete_device::discrete_build_list(const discrete_sound_block *intf, linked_list_entry ***current)
511{
350512   int node_count = 0;
351513
352514   for (; intf[node_count].type != DSS_NULL; )
r10048r10049
354516      /* scan imported */
355517      if (intf[node_count].type == DSO_IMPORT)
356518      {
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);
359521      }
360522      else if (intf[node_count].type == DSO_REPLACE)
361523      {
r10048r10049
365527         if (intf[node_count].type == DSS_NULL)
366528            fatalerror("discrete_build_list: DISCRETE_REPLACE at end of node_list");
367529
368         for (entry = info->block_list; entry != NULL; entry = entry->next)
530         for (entry = m_block_list; entry != NULL; entry = entry->next)
369531         {
370532            discrete_sound_block *block = (discrete_sound_block *) entry->ptr;
371533
r10048r10049
373535               if (block->node == intf[node_count].node)
374536               {
375537                  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) );
377539                  break;
378540               }
379541         }
r10048r10049
387549         linked_list_entry *entry, *last;
388550
389551         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)
391553         {
392554            discrete_sound_block *block = (discrete_sound_block *) entry->ptr;
393555
394556            if ((block->node >= intf[node_count].input_node[0]) &&
395557                  (block->node <= intf[node_count].input_node[1]))
396558            {
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) );
398560               if (last != NULL)
399561                  last->next = entry->next;
400562               else
401                  info->block_list = entry->next;
563                  m_block_list = entry->next;
402564            }
403565         }
404566      }
405567      else
406568      {
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]);
409571      }
410572
411573      node_count++;
412574   }
413575}
414576
415/*************************************
416 *
417 *  Sanity check list
418 *
419 *************************************/
577//-------------------------------------------------
578// discrete_sanity_check: Sanity check list
579//-------------------------------------------------
420580
421static void discrete_sanity_check(const discrete_info *info)
581void discrete_device::discrete_sanity_check(void)
422582{
423583   const linked_list_entry *entry;
424584   int node_count = 0;
425585
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)
428588   {
429589      discrete_sound_block *block = (discrete_sound_block *) entry->ptr;
430590
r10048r10049
446606
447607      node_count++;
448608   }
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);
450610
451611}
452612
613//-------------------------------------------------
614// discrete_sanity_check: Sanity check list
615//-------------------------------------------------
616
453617/*************************************
454618 *
455619 *  Master discrete system start
456620 *
457621 *************************************/
458#if 0
459static 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];
465622
466   info->device = device;
467623
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
532624/*************************************
533625 *
534626 *  Master discrete system stop
r10048r10049
539631{
540632   UINT64 total = 0;
541633
542   for_each(node_description *, node, &list)
634   for_each(discrete_base_node *, node, &list)
543635   {
636      discrete_step_interface *step;
637      if (node.item()->interface(step))
638         total += step->run_time;
639   }
640   return total;
641}
642
643static 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   {
544649      total += node.item()->run_time;
545650   }
546651   return total;
547652}
548653
549static void display_profiling(const discrete_info *info)
654void discrete_device::display_profiling(void)
550655{
551656   int count;
552657   UINT64 total;
r10048r10049
554659   double tt;
555660
556661   /* 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();
559664   /* print statistics */
560   printf("Total Samples  : %16" I64FMT "d\n", info->total_samples);
665   printf("Total Samples  : %16" I64FMT "d\n", m_total_samples);
561666   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)
564669   {
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);
567674   }
568675
569676   /* Task information */
570   for_each(discrete_task *, task, &info->task_list)
677   for_each(discrete_task *, task, &task_list)
571678   {
572      tt =  list_run_time(task.item()->list);
679      tt =  step_list_run_time(task.item()->step_list);
573680
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);
575682   }
576683
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);
578685}
579686
580#if 0
581static DEVICE_STOP( discrete )
582{
583   discrete_info *info = get_safe_token(device);
584687
585   osd_work_queue_free(info->queue);
586688
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
611689/*************************************
612690 *
613691 *  Master reset of all nodes
614692 *
615693 *************************************/
616#if 0
617static DEVICE_RESET( discrete )
618{
619   const discrete_info *info = get_safe_token(device);
620694
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
637695/*************************************
638696 *
639697 *  Stream update functions
640698 *
641699 *************************************/
642700
643static void *task_callback(void *param, int threadid)
644{
645   task_list_t *list = (task_list_t *) param;
646   int samples;
647701
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);
656702
657            /* check dependencies */
658            for_each(discrete_source_node *, sn, &task.item()->source_list)
659            {
660               int avail;
661703
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            }
667704
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
690static 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
703static 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
764705/*************************************
765706 *
766707 *  First pass init of nodes
r10048r10049
768709 *************************************/
769710
770711
771static void init_nodes(discrete_info *info, const linked_list_entry *block_list, device_t *device)
712void discrete_device::init_nodes(const linked_list_entry *block_list)
772713{
773714   const linked_list_entry   *entry;
774715   discrete_task *task = NULL;
r10048r10049
788729      /* make sure we have one simple task
789730         * No need to create a node since there are no dependencies.
790731         */
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);
793734   }
794735
795736   /* loop over all nodes */
796737   for (entry = block_list; entry != NULL; entry = entry->next)
797738   {
798739      const discrete_sound_block *block = (discrete_sound_block *) entry->ptr;
799      int modulenum;
740      //int modulenum;
800741
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);
810743      /* keep track of special nodes */
811744      if (block->node == NODE_SPECIAL)
812745      {
r10048r10049
814747         {
815748            /* Output Node */
816749            case DSO_OUTPUT:
817               info->output_list.add_tail(node);
750               /* nothing -> handled later */
818751               break;
819752
820753            /* CSVlog Node for debugging */
r10048r10049
829762            case DSO_TASK_START:
830763               if (task != NULL)
831764                  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);
834771               break;
835772
836773            case DSO_TASK_END:
837774               if (task == NULL)
838775                  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;
845776               break;
846777
847778            default:
r10048r10049
852783      /* otherwise, make sure we are not a duplicate, and put ourselves into the indexed list */
853784      else
854785      {
855         if (info->indexed_node[NODE_INDEX(block->node)])
786         if (m_indexed_node[NODE_INDEX(block->node)])
856787            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;
858789      }
859790
860791      /* 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)
862794      {
863         info->input_list.add_tail(node);
795         m_input_stream_list.add_tail(input_stream);
864796      }
865      else if (block->type == DSS_INPUT_BUFFER)
866      {
867         info->input_list.add_tail(node);
868      }
869797
870798      /* add to node list */
871      info->node_list.add_tail(node);
799      m_node_list.add_tail(node);
872800
873801      /* our running order just follows the order specified */
874802      /* does the node step ? */
875      if (node->step != NULL)
803      discrete_step_interface *step;
804      if (node->interface(step))
876805      {
877806         /* do we belong to a task? */
878807         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() );
880809         else
881            task->list.add_tail(node);
810            task->step_list.add_tail(step);
882811      }
883812
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
884819      if (block->type == DSO_TASK_END)
885820      {
886821         task = NULL;
887822      }
888823
889824      /* and register save state */
890      node->save_state(device);
825      node->save_state(this);
891826   }
892827
893828   if (!has_tasks)
r10048r10049
895830   }
896831
897832   /* if no outputs, give an error */
898   if (info->output_list.count() == 0)
833   if (m_output_list.count() == 0)
899834      fatalerror("init_nodes() - Couldn't find an output node");
900835}
901836
r10048r10049
906841 *
907842 *************************************/
908843
909node_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;
919844
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
936node_description::~node_description(void)
845int discrete_device::same_module_index(discrete_base_node &node)
937846{
938   if (module->contextsize)
939      global_free(context);
940}
941
942int node_description::index(void)
943{
944   return NODE_INDEX(m_block->node);
945}
946
947void 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
953void 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
998int node_description::same_module_index(const node_list_t &list)
999{
1000847   int index = 0;
1001848
1002   for_each(node_description *, n, &list)
849   for_each(discrete_base_node *, n, &m_node_list)
1003850   {
1004      if (n.item() == this)
851      if (n.item() == &node)
1005852         return index;
1006      if (n.item()->module->type == this->module->type)
853      if (n.item()->module_type() == node.module_type())
1007854         index++;
1008855   }
1009856   return -1;
1010857}
1011858
1012#if 0
1013/**************************************************************************
1014 * Generic get_info
1015 **************************************************************************/
1016859
1017DEVICE_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
1039DEFINE_LEGACY_SOUND_DEVICE(DISCRETE, discrete);
1040#endif
1041
1042860//**************************************************************************
1043861//  GLOBAL VARIABLES
1044862//**************************************************************************
r10048r10049
1049867//  DEVICE CONFIGURATION
1050868//**************************************************************************
1051869
1052#if 0
1053870//-------------------------------------------------
1054//  static_set_type - configuration helper to set
1055//  the chip type
871//  static_set_intf - configuration helper to set
872//  the interface
1056873//-------------------------------------------------
1057874
1058void discrete_device_config::static_set_type(device_config *device, int type)
875void discrete_device_config::static_set_intf(device_config *device, const discrete_sound_block *intf)
1059876{
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;
1062879}
1063880
1064881//-------------------------------------------------
1065//  static_set_type - configuration helper to set
1066//  the IRQ callback
1067//-------------------------------------------------
1068
1069
1070void 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//-------------------------------------------------
1078882//  discrete_device_config - constructor
1079883//-------------------------------------------------
1080884
1081885discrete_device_config::discrete_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
1082886   : 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)
1084888{
1085889}
1086890
r10048r10049
1121925
1122926discrete_device::~discrete_device(void)
1123927{
1124   discrete_info *info = &m_info;
928   osd_work_queue_free(m_queue);
1125929
1126   osd_work_queue_free(info->queue);
1127
1128   if (profiling)
930   if (m_profiling)
1129931   {
1130      display_profiling(info);
932      display_profiling();
1131933   }
1132934
1133935   /* Process nodes which have a stop func */
1134936
1135   for_each(node_description *, node, &info->node_list)
937   for_each(discrete_base_node *, node, &m_node_list)
1136938   {
1137      if (node.item()->module->stop)
1138         (*node.item()->module->stop)(node.item());
939      node.item()->stop();
1139940   }
1140941
1141942   if (DISCRETE_DEBUGLOG)
1142943   {
1143944      /* 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;
1147948   }
1148949}
1149950
r10048r10049
1157958   //m_stream = stream_create(this, 0, 2, 22257, this, static_stream_generate);
1158959
1159960   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();
1162962   char name[32];
1163963
1164   info->device = this;
1165
1166964   /* If a clock is specified we will use it, otherwise run at the audio sample rate. */
1167965   if (this->clock())
1168      info->sample_rate = this->clock();
966      m_sample_rate = this->clock();
1169967   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;
1173971
1174   info->total_samples = 0;
1175   info->total_stream_updates = 0;
972   m_total_samples = 0;
973   m_total_stream_updates = 0;
1176974
1177975   /* create the logfile */
1178976   sprintf(name, "discrete%s.log", this->tag());
1179977   if (DISCRETE_DEBUGLOG)
1180      info->disclogfile = fopen(name, "w");
978      m_disclogfile = fopen(name, "w");
1181979
1182980   /* enable profiling */
981   m_profiling = 0;
1183982   if (getenv("DISCRETE_PROFILING"))
1184      profiling = atoi(getenv("DISCRETE_PROFILING"));
983      m_profiling = atoi(getenv("DISCRETE_PROFILING"));
1185984
1186985   /* 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);
1190989
1191990   /* 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();
1193992
1194993   /* 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();
1198997
1199998   /* 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);
12011000
12021001   /* initialize the node data */
1203   init_nodes(info, info->block_list, this);
1002   init_nodes(m_block_list);
12041003
12051004   /* 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)
12071006   {
12081007      node.item()->find_input_nodes();
12091008   }
12101009
12111010   /* 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);
12131012
12141013   /* allocate a queue */
12151014
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);
12171016
12181017   /* Process nodes which have a start func */
12191018
1220   for_each(node_description *, node, &info->node_list)
1019   for_each(discrete_base_node *, node, &m_node_list)
12211020   {
1222      if (node.item()->module->start)
1223         (*node.item()->module->start)(node.item());
1021      node.item()->start();
12241022   }
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   }
12251034}
12261035
12271036
r10048r10049
12321041void discrete_device::device_reset()
12331042{
12341043
1235   const discrete_info *info = &m_info;
1236   stream_update(info->discrete_stream);
1044   update();
12371045
12381046   /* loop over all nodes */
1239   for_each (node_description *, node, &info->node_list)
1047   for_each (discrete_base_node *, node, &m_node_list)
12401048   {
12411049      node.item()->output[0] = 0;
12421050
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();
12501052   }
12511053}
12521054
r10048r10049
12621064
12631065void discrete_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples)
12641066{
1265   discrete_info *info = &m_info;
12661067   int outputnum;
12671068   //, task_group;
12681069
r10048r10049
12701071      return;
12711072   /* Setup any output streams */
12721073   outputnum = 0;
1273   for_each(node_description *, node, &info->output_list)
1074   for_each(discrete_output_interface *, node, &m_output_list)
12741075   {
1275      node.item()->context = (void *) outputs[outputnum];
1076      node.item()->set_output(outputs[outputnum]);
12761077      outputnum++;
12771078   }
12781079
12791080   /* 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)
12811082   {
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];
12841084   }
12851085
12861086   /* Setup tasks */
1287   for_each(discrete_task *, task, &info->task_list)
1087   for_each(discrete_task *, task, &task_list)
12881088   {
1289      int               i;
1290
1291      task.item()->samples = samples;
12921089      /* unlock the thread */
12931090      task.item()->unlock();
12941091
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);
13041093   }
13051094
1306   for_each(discrete_task *, task, &info->task_list)
1095   for_each(discrete_task *, task, &task_list)
13071096   {
13081097      /* 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);
13101099   }
1311   osd_work_queue_wait(info->queue, osd_ticks_per_second()*10);
1100   osd_work_queue_wait(m_queue, osd_ticks_per_second()*10);
13121101
1313   if (profiling)
1102   if (m_profiling)
13141103   {
1315      info->total_samples += samples;
1316      info->total_stream_updates++;
1104      m_total_samples += samples;
1105      m_total_stream_updates++;
13171106   }
13181107}
13191108
r10048r10049
13231112
13241113READ8_MEMBER( discrete_device::read )
13251114{
1326   discrete_info    *info = &m_info;
1327   node_description *node = discrete_find_node(info, offset);
1115   discrete_base_node *node = discrete_find_node(offset);
13281116
13291117   UINT8 data = 0;
13301118
r10048r10049
13321120   if (node)
13331121   {
13341122      /* Bring the system up to now */
1335      stream_update(info->discrete_stream);
1123      stream_update(m_stream);
13361124
13371125      data = (UINT8) node->output[NODE_CHILD_NODE_NUM(offset)];
13381126   }
r10048r10049
13481136
13491137WRITE8_MEMBER( discrete_device::write )
13501138{
1351   discrete_info    *info = &m_info;
1352   node_description *node = discrete_find_node(info, offset);
1139   discrete_base_node *node = discrete_find_node(offset);
13531140
13541141   /* Update the node input value if it's a proper input node */
13551142   if (node)
13561143   {
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);
13951149   }
13961150   else
13971151   {
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);
13991153   }
14001154}
src/emu/sound/discrete.h
r10048r10049
33#ifndef __DISCRETE_H__
44#define __DISCRETE_H__
55
6//#include "devlegcy.h"
76#include "machine/rescap.h"
87
98/***********************************************************************
r10048r10049
34773476 *************************************/
34783477
34793478/* 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)))
34813481/* calculate charge exponent using given sample time */
34823482#define RC_CHARGE_EXP_DT(rc, dt)            (1.0 - exp(-(dt) / (rc)))
34833483#define RC_CHARGE_NEG_EXP_DT(rc, dt)         (1.0 - exp((dt) / (rc)))
34843484
34853485/* 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)))
34873488/* calculate discharge exponent using given sample time */
34883489#define RC_DISCHARGE_EXP_DT(rc, dt)            (exp(-(dt) / (rc)))
34893490#define RC_DISCHARGE_NEG_EXP_DT(rc, dt)         (exp((dt) / (rc)))
r10048r10049
34963497 *
34973498 *************************************/
34983499
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
35033501
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)
35053507
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();
35103510
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]))
35153512
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
35243513/*************************************
35253514 *
35263515 *  Core constants
r10048r10049
37713760template<class T> class enumerator_t
37723761{
37733762public:
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() {  }
37763765
3766   //inline void set_first(linked_list_entry *first) { m_cur = first; }
37773767   inline T item(void) { return (T) m_cur->ptr; }
37783768   inline void next(void) { m_cur = m_cur->next; }
37793769   inline bool has_item(void) { return (m_cur != NULL); }
3770protected:
37803771private:
37813772   linked_list_entry *m_cur;
37823773};
r10048r10049
38433834      }
38443835      return cnt;
38453836   }
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; }
38473838private:
38483839   linked_list_entry *m_first;
38493840   linked_list_entry *m_last;
r10048r10049
38513842
38523843/*************************************
38533844 *
3854 *  The discrete sound blocks as
3855 *  defined in the drivers
3856 *
3857 *************************************/
3858
3859struct _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};
3869typedef struct _discrete_sound_block discrete_sound_block;
3870
3871/*************************************
3872 *
3873 *  Internal structure of a node
3874 *
3875 *************************************/
3876
3877typedef struct _discrete_module discrete_module;
3878typedef struct _discrete_info discrete_info;
3879
3880
3881class node_description;
3882typedef linked_list_t<node_description *> node_list_t;
3883
3884
3885class node_description
3886{
3887public:
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;
3928protected:
3929private:
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
3945struct _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
3968typedef struct _discrete_source_node discrete_source_node;
3969
3970typedef linked_list_t<discrete_source_node *> source_node_list_t;
3971
3972class discrete_task
3973{
3974public:
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; }
4007private:
4008   volatile INT32         m_threadid;
4009};
4010
4011typedef linked_list_t<discrete_task *> task_list_t;
4012
4013struct _discrete_source_node
4014{
4015   const discrete_task   *task;
4016   const double      *ptr;
4017   int               output_node;
4018   double            buffer;
4019};
4020
4021struct _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 *
40653845 *  Node-specific struct types
40663846 *
40673847 *************************************/
r10048r10049
43064086};
43074087
43084088
4309typedef struct _discrete_custom_info discrete_custom_info;
4310struct _discrete_custom_info
4311{
4312   const discrete_module module;
4313   const void *custom;                  /* Custom function specific initialisation data */
4314};
4315
4316
43174089// Taken from the transfer characteristerics diagram in CD4049UB datasheet (TI)
43184090// There is no default trigger point and vI-vO is a continuous function
43194091
r10048r10049
44254197 *
44264198 *************************************/
44274199
4428enum
4200typedef enum
44294201{
44304202   DSS_NULL,         /* Nothing, nill, zippo, only to be used as terminating node */
44314203   DSS_NOP,         /* just do nothing, placeholder for potential DISCRETE_REPLACE in parent block */
44324204
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 */
44434206
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 */
44634208
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
45364209   /* Custom */
45374210   DST_CUSTOM,         /* whatever you want */
45384211
r10048r10049
45434216   /* Parallel execution */
45444217   DSO_TASK_START,   /* start of parallel task */
45454218   DSO_TASK_END,   /* end of parallel task */
4546   DSO_TASK_SYNC,   /* wait for all parallel tasks to finish */
45474219
45484220   /* Output Node -- this must be the last entry in this enum! */
45494221   DSO_OUTPUT,         /* The final output node */
r10048r10049
45554227
45564228   /* Marks end of this enum -- must be last entry ! */
45574229   DSO_LAST
4558};
4230} discrete_node_type;
45594231
4560
4561
45624232/*************************************
45634233 *
4564 *  Encapsulation macros for defining
4565 *  your simulation
4234 *  Forward declarations
45664235 *
45674236 *************************************/
45684237
4569#define MCFG_SOUND_CONFIG_DISCRETE(name) MCFG_SOUND_CONFIG(name##_discrete_interface)
4238typedef struct _discrete_sound_block discrete_sound_block;
4239class discrete_node_base_factory;
4240class discrete_task;
4241class discrete_base_node;
4242class discrete_dss_input_stream_node;
4243class discrete_device;
4244typedef linked_list_t<discrete_base_node *> node_list_t;
4245typedef linked_list_t<discrete_dss_input_stream_node *> input_stream_node_list_t;
4246typedef linked_list_t<discrete_task *> task_list_t;
45704247
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[] = {
45734248
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 *************************************/
45754254
45764255
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 *************************************/
45794262
4580/*      Module Name                                                       out,  enum value,      #in,   {variable inputs},              {static inputs},    data pointer,   "name" */
4263struct _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};
45814275
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 *************************************/
45934281
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" ),
4282class discrete_step_interface
4283{
4284public:
4285   virtual ~discrete_step_interface() { }
45964286
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};
4291typedef linked_list_t<discrete_step_interface *> node_step_list_t;
45984292
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" ),
4293class discrete_input_interface
4294{
4295public:
4296   virtual ~discrete_input_interface() { }
46204297
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};
46314300
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" ),
4301class discrete_output_interface
4302{
4303public:
4304   virtual ~discrete_output_interface() { }
46344305
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};
46954308
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" ),
47204309
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
47694310/*************************************
47704311 *
47714312 *  Interface to the external world
r10048r10049
47784319//**************************************************************************
47794320//  INTERFACE CONFIGURATION MACROS
47804321//**************************************************************************
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)
47874322
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)
47924326
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)
47954330
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)); \
47984333
4799#endif
48004334
4335#define MCFG_SOUND_CONFIG_DISCRETE(name) MCFG_SOUND_CONFIG(name##_discrete_interface)
4336
48014337//**************************************************************************
48024338//  TYPE DEFINITIONS
48034339//**************************************************************************
r10048r10049
48174353   virtual device_t *alloc_device(running_machine &machine) const;
48184354
48194355   // 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);
48224357
48234358protected:
4359   const discrete_sound_block *m_intf;
48244360   // inline data
48254361};
48264362
4363class discrete_output_interface;
4364typedef linked_list_t<discrete_output_interface *> node_output_list_t;
48274365
48284366
48294367// ======================> discrete_device
r10048r10049
48314369class discrete_device : public device_t, public device_sound_interface
48324370{
48334371   friend class discrete_device_config;
4372   friend class discrete_base_node;
4373   friend class discrete_dss_input_stream_node;
48344374
48354375   // construction/destruction
48364376   discrete_device(running_machine &_machine, const discrete_device_config &config);
r10048r10049
48414381   //sound_stream *m_stream;
48424382   virtual ~discrete_device(void);
48434383
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
48444399protected:
48454400
48464401   // device-level overrides
r10048r10049
48544409   // internal state
48554410   const discrete_device_config &m_config;
48564411
4857   /* all for now */
4858   discrete_info m_info;
4412   /* --------------------------------- */
48594413
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
48604423private:
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);
48614428
4429   /* internal node tracking */
4430   discrete_base_node    **m_indexed_node;
48624431
4863};
4432   /* list of all nodes */
4433   node_list_t          m_node_list;      /* node_description * */
48644434
4435   /* list of discrete blocks after prescan (IMPORT, DELETE, REPLACE) */
4436   linked_list_entry    *m_block_list;      /* discrete_sound_block * */
48654437
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
48664454// device type definition
48674455extern const device_type DISCRETE;
48684456
4457/*************************************
4458 *
4459 *  Node class
4460 *
4461 *************************************/
48694462
4870//DECLARE_LEGACY_SOUND_DEVICE(DISCRETE, discrete);
4463class discrete_base_node
4464{
4465   friend class discrete_device;
4466   template <class C> friend class discrete_node_factory;
4467   friend class discrete_task;
48714468
4469public:
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
4511protected:
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
4520private:
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
4531class discrete_node_base_factory
4532{
4533public:
4534    virtual discrete_base_node *Create(discrete_device * pdev, const discrete_sound_block *block) = 0;
4535    virtual ~discrete_node_base_factory() {}
4536};
4537
4538template <class C>
4539class discrete_node_factory : public discrete_node_base_factory
4540{
4541   discrete_base_node *Create(discrete_device * pdev, const discrete_sound_block *block);
4542};
4543
4544template <class C>
4545discrete_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
48724768#endif /* __DISCRETE_H__ */
src/emu/sound/disc_dev.c
r10048r10049
2626
2727#define DEFAULT_555_BLEED_R   RES_M(10)
2828
29struct 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
54struct 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
70struct 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
94struct 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
109struct 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
126struct 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
13929/************************************************************************
14030 *
14131 * DSD_555_ASTBL -  - 555 Astable simulation
r10048r10049
16757
16858DISCRETE_STEP(dsd_555_astbl)
16959{
170   DISCRETE_DECLARE_CONTEXT(dsd_555_astbl)
17160   DISCRETE_DECLARE_INFO(discrete_555_desc)
17261
17362   int      count_f = 0;
17463   int      count_r = 0;
17564   double   dt;                        /* change in time */
17665   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 */
17867   double   v_cap_next = 0;               /* Voltage on capacitor, after dt */
17968   double   v_charge, exponent = 0;
180   UINT8   flip_flop = context->flip_flop;
69   UINT8   flip_flop = m_flip_flop;
18170   UINT8   update_exponent = 0;
18271
18372   /* 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;
18675
18776   if(DSD_555_ASTBL__RESET)
18877   {
18978      /* 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;
19382      return;
19483   }
19584
19685   /* Check: if the Control Voltage node is connected. */
197   if (context->use_ctrlv)
86   if (m_use_ctrlv)
19887   {
19988      /* If CV is less then .25V, the circuit will oscillate way out of range.
20089         * So we will just ignore it when it happens. */
r10048r10049
217106   }
218107
219108   /* 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)
221110   {
222      v_charge = *context->v_charge_node;
111      v_charge = *m_v_charge_node;
223112      if (info->options & DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE) v_charge -= 0.5;
224113   }
225114   else
226      v_charge = context->v_charge;
115      v_charge = m_v_charge;
227116
228117
229118   /* Calculate future capacitor voltage.
r10048r10049
244133     * dt = R*C(log(1/(1-(Vc/Vr))))
245134     */
246135
247   dt = node->info->sample_time;
136   dt = this->sample_time();
248137
249138   /* Sometimes a switching network is used to setup the capacitance.
250139     * These may select no capacitor, causing oscillation to stop.
r10048r10049
255144      /* The voltage goes high because the cap circuit is open. */
256145      v_cap_next = v_charge;
257146      v_cap      = v_charge;
258      context->cap_voltage = 0;
147      m_cap_voltage = 0;
259148   }
260149   else
261150   {
262151      /* 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))
264153      {
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;
274163      }
275164      /* Keep looping until all toggling in time sample is used up. */
276165      do
r10048r10049
282171               /* Oscillation disabled because there is no longer any charge resistor. */
283172               /* Bleed the cap due to circuit losses. */
284173               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);
286175               else
287                  exponent = context->exp_bleed;
176                  exponent = m_exp_bleed;
288177               v_cap_next = v_cap - (v_cap * exponent);
289178               dt = 0;
290179            }
r10048r10049
292181            {
293182               /* Charging */
294183               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);
296185               else
297                  exponent = context->exp_charge;
186                  exponent = m_exp_charge;
298187               v_cap_next = v_cap + ((v_charge - v_cap) * exponent);
299188               dt = 0;
300189
r10048r10049
302191               if (v_cap_next >= threshold)
303192               {
304193                  /* 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))));
306195                  x_time = dt;
307196                  v_cap_next  = threshold;
308197                  flip_flop = 0;
r10048r10049
317206            if(DSD_555_ASTBL__R2 != 0)
318207            {
319208               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);
321210               else
322                  exponent = context->exp_discharge;
211                  exponent = m_exp_discharge;
323212               v_cap_next = v_cap - (v_cap * exponent);
324213               dt = 0;
325214            }
r10048r10049
334223            {
335224               /* calculate the overshoot time */
336225               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)));
338227               x_time = dt;
339228               v_cap_next  = trigger;
340229               flip_flop = 1;
r10048r10049
345234         v_cap = v_cap_next;
346235      } while(dt);
347236
348      context->cap_voltage = v_cap;
237      m_cap_voltage = v_cap;
349238   }
350239
351240   /* Convert last switch time to a ratio */
352   x_time = x_time / node->info->sample_time;
241   x_time = x_time / this->sample_time();
353242
354   switch (context->output_type)
243   switch (m_output_type)
355244   {
356245      case DISC_555_OUT_SQW:
357246         if (count_f + count_r >= 2)
358247            /* 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;
360249         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;
363252         break;
364253      case DISC_555_OUT_CAP:
365         node->output[0] = v_cap;
254         this->output[0] = v_cap;
366255         /* 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;
369258         break;
370259      case DISC_555_OUT_ENERGY:
371260         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;
374263         break;
375264      case DISC_555_OUT_LOGIC_X:
376         node->output[0] = flip_flop + x_time;
265         this->output[0] = flip_flop + x_time;
377266         break;
378267      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;
380269         break;
381270      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;
383272         break;
384273      case DISC_555_OUT_COUNT_F:
385         node->output[0] = count_f;
274         this->output[0] = count_f;
386275         break;
387276      case DISC_555_OUT_COUNT_R:
388         node->output[0] = count_r;
277         this->output[0] = count_r;
389278         break;
390279   }
391   context->flip_flop = flip_flop;
280   m_flip_flop = flip_flop;
392281}
393282
394283DISCRETE_RESET(dsd_555_astbl)
395284{
396   DISCRETE_DECLARE_CONTEXT(dsd_555_astbl)
397285   DISCRETE_DECLARE_INFO(discrete_555_desc)
398286
399   node_description *v_charge_node;
287   discrete_base_node *v_charge_node;
400288
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;
403291
404292   /* 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;
406294
407295   /* 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);
409297   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)]);
411299   else
412300   {
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;
415303
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;
417305   }
418306
419   if ((DSD_555_ASTBL__CTRLV != -1) && !context->use_ctrlv)
307   if ((DSD_555_ASTBL__CTRLV != -1) && !m_use_ctrlv)
420308   {
421309      /* 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;
424312   }
425313   else
426314   {
427315      /* 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;
430318   }
431319
432320   /* 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;
436324   else
437325   {
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);
444332   }
445333
446   context->output_is_ac = info->options & DISC_555_OUT_AC;
334   m_output_is_ac = info->options & DISC_555_OUT_AC;
447335   /* 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;
449337
450   context->flip_flop = 1;
451   context->cap_voltage = 0;
338   m_flip_flop = 1;
339   m_cap_voltage = 0;
452340
453341   /* Step to set the output */
454   DISCRETE_STEP_CALL(dsd_555_astbl);
342   this->step();
455343}
456344
457345
r10048r10049
478366
479367DISCRETE_STEP(dsd_555_mstbl)
480368{
481   DISCRETE_DECLARE_CONTEXT(dsd_555_mstbl)
482369   DISCRETE_DECLARE_INFO(discrete_555_desc)
483370
484371   double v_cap;         /* Current voltage on capacitor, before dt */
r10048r10049
487374   double out = 0;
488375   int trigger = 0;
489376   int trigger_type;
490   int update_exponent = context->has_rc_nodes;
377   int update_exponent = m_has_rc_nodes;
491378   int flip_flop;
492379
493380   if(UNEXPECTED(DSD_555_MSTBL__RESET))
494381   {
495382      /* 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;
499386      return;
500387   }
501388
502   dt = node->info->sample_time;
503   flip_flop = context->flip_flop;
389   dt = this->sample_time();
390   flip_flop = m_flip_flop;
504391   trigger_type = info->options;
505   v_cap = context->cap_voltage;
392   v_cap = m_cap_voltage;
506393
507394   switch (trigger_type & DSD_555_TRIGGER_TYPE_MASK)
508395   {
r10048r10049
512399            x_time = 1.0 - DSD_555_MSTBL__TRIGGER;
513400         break;
514401      case DISC_555_TRIGGER_IS_VOLTAGE:
515         trigger = (int)(DSD_555_MSTBL__TRIGGER < context->trigger);
402         trigger = (int)(DSD_555_MSTBL__TRIGGER < m_trigger);
516403         break;
517404      case DISC_555_TRIGGER_IS_COUNT:
518405         trigger = (int)DSD_555_MSTBL__TRIGGER;
r10048r10049
530417   x_time = 0;
531418
532419   if ((trigger_type & DISC_555_TRIGGER_DISCHARGES_CAP) && trigger)
533      context->cap_voltage = 0;
420      m_cap_voltage = 0;
534421
535422   /* Wait for trigger */
536423   if (UNEXPECTED(!flip_flop && trigger))
537424   {
538425      flip_flop = 1;
539      context->flip_flop = 1;
426      m_flip_flop = 1;
540427   }
541428
542429   if (flip_flop)
r10048r10049
549436         /* The trigger voltage goes high because the cap circuit is open.
550437             * and the cap discharges */
551438         v_cap = info->v_pos;   /* needed for cap output type */
552         context->cap_voltage = 0;
439         m_cap_voltage = 0;
553440
554441         if (!trigger)
555442         {
556443            flip_flop = 0;
557            context->flip_flop = 0;
444            m_flip_flop = 0;
558445         }
559446      }
560447      else
561448      {
562449         /* Charging */
563         double v_diff = context->v_charge - v_cap;
450         double v_diff = m_v_charge - v_cap;
564451
565452         if (UNEXPECTED(update_exponent))
566453            exponent = RC_CHARGE_EXP_DT(DSD_555_MSTBL__R * DSD_555_MSTBL__C, dt);
567454         else
568            exponent = context->exp_charge;
455            exponent = m_exp_charge;
569456         v_cap += v_diff * exponent;
570457
571458         /* Has it charged past upper limit? */
572459         /* If trigger is still enabled, then we keep charging,
573460             * regardless of threshold. */
574         if (UNEXPECTED((v_cap >= context->threshold) && !trigger))
461         if (UNEXPECTED((v_cap >= m_threshold) && !trigger))
575462         {
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();
578465            v_cap  = 0;
579466            flip_flop = 0;
580            context->flip_flop = 0;
467            m_flip_flop = 0;
581468         }
582         context->cap_voltage = v_cap;
469         m_cap_voltage = v_cap;
583470      }
584471   }
585472
586   switch (context->output_type)
473   switch (m_output_type)
587474   {
588475      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;
590477         break;
591478      case DISC_555_OUT_CAP:
592479         if (x_time > 0)
r10048r10049
594481         else
595482            out = v_cap;
596483
597         out -= context->ac_shift;
484         out -= m_ac_shift;
598485         break;
599486      case DISC_555_OUT_ENERGY:
600487         if (x_time > 0)
601            out = context->v_out_high * x_time;
488            out = m_v_out_high * x_time;
602489         else if (flip_flop)
603            out = context->v_out_high;
490            out = m_v_out_high;
604491         else
605492            out = 0;
606493
607         out -= context->ac_shift;
494         out -= m_ac_shift;
608495         break;
609496   }
610   node->output[0] = out;
497   this->output[0] = out;
611498}
612499
613500DISCRETE_RESET(dsd_555_mstbl)
614501{
615   DISCRETE_DECLARE_CONTEXT(dsd_555_mstbl)
616502   DISCRETE_DECLARE_INFO(discrete_555_desc)
617503
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))
620506   {
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;
623509   }
624510
625511   /* 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;
628514
629515   /* 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;
632518
633519   /* Calculate DC shift needed to make waveform AC */
634520   if (info->options & DISC_555_OUT_AC)
635521   {
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;
638524      else
639         context->ac_shift = context->v_out_high / 2.0;
525         m_ac_shift = m_v_out_high / 2.0;
640526   }
641527   else
642      context->ac_shift = 0;
528      m_ac_shift = 0;
643529
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;
646532
647   context->flip_flop   = 0;
648   context->cap_voltage = 0;
533   m_flip_flop   = 0;
534   m_cap_voltage = 0;
649535
650536   /* 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;
654540   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);
656542
657   node->output[0] = 0;
543   this->output[0] = 0;
658544}
659545
660546
r10048r10049
695581
696582DISCRETE_STEP(dsd_555_cc)
697583{
698   DISCRETE_DECLARE_CONTEXT(dsd_555_cc)
699584   DISCRETE_DECLARE_INFO(discrete_555_cc_desc)
700585
701586   int      count_f  = 0;
r10048r10049
715600   double   r_temp;            /* play thing */
716601   double   exponent;
717602   UINT8   update_exponent, update_t_rc;
718   UINT8   flip_flop = context->flip_flop;
603   UINT8   flip_flop = m_flip_flop;
719604
720605
721606   if (UNEXPECTED(DSD_555_CC__RESET))
722607   {
723608      /* 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;
727612      return;
728613   }
729614
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 */
732617   v_vcharge_limit = DSD_555_CC__VIN + info->v_cc_junction;   /* the max v_cap can be and still be charged by i */
733618   /* 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;
735620   if ( i < 0) i = 0;
736621
737622   if (info->options & DISCRETE_555_CC_TO_CAP)
r10048r10049
740625   }
741626   else
742627   {
743      switch (context->type)   /* see dsd_555_cc_reset for descriptions */
628      switch (m_type)   /* see dsd_555_cc_reset for descriptions */
744629      {
745630         case 1:
746631            r_discharge = DSD_555_CC__RDIS;
r10048r10049
781666   }
782667
783668   /* 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;
785670   update_exponent = update_t_rc;
786671   do
787672   {
788      if (context->type <= 1)
673      if (m_type <= 1)
789674      {
790675         /* Standard constant current charge */
791676         if (flip_flop)
r10048r10049
801686                  exponent = RC_CHARGE_EXP_DT(t_rc, dt);
802687               }
803688               else
804                  exponent = context->exp_bleed;
689                  exponent = m_exp_bleed;
805690               v_cap_next = v_cap - (v_cap * exponent);
806691               dt = 0;
807692            }
r10048r10049
819704               dt = 0;
820705
821706               /* has it charged past upper limit? */
822               if (v_cap_next >= context->threshold)
707               if (v_cap_next >= m_threshold)
823708               {
824709                  /* 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;
826711                  x_time = dt;
827                  v_cap_next = context->threshold;
712                  v_cap_next = m_threshold;
828713                  flip_flop = 0;
829714                  count_f++;
830715                  update_exponent = 1;
r10048r10049
837722            if (update_t_rc)
838723               t_rc = DSD_555_CC_T_RC_DISCHARGE_01;
839724            else
840               t_rc = context->t_rc_discharge_01;
725               t_rc = m_t_rc_discharge_01;
841726            if (update_exponent)
842727               exponent = RC_CHARGE_EXP_DT(t_rc, dt);
843728            else
844               exponent = context->exp_discharge_01;
729               exponent = m_exp_discharge_01;
845730
846731            if (info->options & DISCRETE_555_CC_TO_CAP)
847732            {
r10048r10049
859744
860745            dt = 0;
861746            /* has it discharged past lower limit? */
862            if (v_cap_next <= context->trigger)
747            if (v_cap_next <= m_trigger)
863748            {
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)));
865750               x_time = dt;
866               v_cap_next  = context->trigger;
751               v_cap_next  = m_trigger;
867752               flip_flop = 1;
868753               count_r++;
869754               update_exponent = 1;
r10048r10049
872757         else   /* Immediate discharge. No change in dt. */
873758         {
874759            x_time = dt;
875            v_cap_next = context->trigger;
760            v_cap_next = m_trigger;
876761            flip_flop = 1;
877762            count_r++;
878763         }
r10048r10049
890775               if (update_t_rc)
891776                  t_rc = DSD_555_CC_T_RC_DISCHARGE_NO_I;
892777               else
893                  t_rc = context->t_rc_discharge_no_i;
778                  t_rc = m_t_rc_discharge_no_i;
894779               if (update_exponent)
895780                  exponent = RC_CHARGE_EXP_DT(t_rc, dt);
896781               else
897                  exponent = context->exp_discharge_no_i;
782                  exponent = m_exp_discharge_no_i;
898783
899784               v_cap_next = v_cap - (v_cap * exponent);
900785               dt = 0;
r10048r10049
906791                     * then only the bias voltage will charge the cap. */
907792               v = v_bias;
908793               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;
910795
911796               if (update_t_rc)
912797                  t_rc = DSD_555_CC_T_RC_CHARGE;
913798               else
914                  t_rc = context->t_rc_charge;
799                  t_rc = m_t_rc_charge;
915800               if (update_exponent)
916801                  exponent = RC_CHARGE_EXP_DT(t_rc, dt);
917802               else
918                  exponent = context->exp_charge;
803                  exponent = m_exp_charge;
919804
920805               v_cap_next = v_cap + ((v - v_cap) * exponent);
921806               dt         = 0;
922807
923808               /* has it charged past upper limit? */
924               if (v_cap_next >= context->threshold)
809               if (v_cap_next >= m_threshold)
925810               {
926811                  /* 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))));
928813                  x_time = dt;
929                  v_cap_next = context->threshold;
814                  v_cap_next = m_threshold;
930815                  flip_flop = 0;
931816                  count_f++;
932817                  update_exponent = 1;
r10048r10049
939824            if (update_t_rc)
940825               t_rc = DSD_555_CC_T_RC_DISCHARGE;
941826            else
942               t_rc = context->t_rc_discharge;
827               t_rc = m_t_rc_discharge;
943828            if (update_exponent)
944829               exponent = RC_CHARGE_EXP_DT(t_rc, dt);
945830            else
946               exponent = context->exp_discharge;
831               exponent = m_exp_discharge;
947832
948833            v_cap_next = v_cap - (v_cap * exponent);
949834            dt = 0;
950835
951836            /* has it discharged past lower limit? */
952            if (v_cap_next <= context->trigger)
837            if (v_cap_next <= m_trigger)
953838            {
954839               /* 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)));
956841               x_time = dt;
957               v_cap_next = context->trigger;
842               v_cap_next = m_trigger;
958843               flip_flop = 1;
959844               count_r++;
960845               update_exponent = 1;
r10048r10049
963848         else   /* Immediate discharge. No change in dt. */
964849         {
965850            x_time = dt;
966            v_cap_next = context->trigger;
851            v_cap_next = m_trigger;
967852            flip_flop = 1;
968853            count_r++;
969854         }
r10048r10049
971856      v_cap = v_cap_next;
972857   } while(dt);
973858
974   context->cap_voltage = v_cap;
859   m_cap_voltage = v_cap;
975860
976861   /* Convert last switch time to a ratio */
977   x_time = x_time / node->info->sample_time;
862   x_time = x_time / this->sample_time();
978863
979   switch (context->output_type)
864   switch (m_output_type)
980865   {
981866      case DISC_555_OUT_SQW:
982867         if (count_f + count_r >= 2)
983868            /* 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;
985870         else
986            node->output[0] = flip_flop * context->v_out_high;
871            this->output[0] = flip_flop * m_v_out_high;
987872         /* Fake it to AC if needed */
988         node->output[0] += context->ac_shift;
873         this->output[0] += m_ac_shift;
989874         break;
990875      case DISC_555_OUT_CAP:
991         node->output[0] = v_cap + context->ac_shift;
876         this->output[0] = v_cap + m_ac_shift;
992877         break;
993878      case DISC_555_OUT_ENERGY:
994879         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;
997882         break;
998883      case DISC_555_OUT_LOGIC_X:
999         node->output[0] = flip_flop + x_time;
884         this->output[0] = flip_flop + x_time;
1000885         break;
1001886      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;
1003888         break;
1004889      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;
1006891         break;
1007892      case DISC_555_OUT_COUNT_F:
1008         node->output[0] = count_f;
893         this->output[0] = count_f;
1009894         break;
1010895      case DISC_555_OUT_COUNT_R:
1011         node->output[0] = count_r;
896         this->output[0] = count_r;
1012897         break;
1013898   }
1014   context->flip_flop = flip_flop;
899   m_flip_flop = flip_flop;
1015900}
1016901
1017902DISCRETE_RESET(dsd_555_cc)
1018903{
1019   DISCRETE_DECLARE_CONTEXT(dsd_555_cc)
1020904   DISCRETE_DECLARE_INFO(discrete_555_cc_desc)
1021905
1022906   double   r_temp, r_discharge = 0, r_charge = 0;
1023907
1024   context->flip_flop   = 1;
1025   context->cap_voltage = 0;
908   m_flip_flop   = 1;
909   m_cap_voltage = 0;
1026910
1027   context->output_type = info->options & DISC_555_OUT_MASK;
911   m_output_type = info->options & DISC_555_OUT_MASK;
1028912
1029913   /* 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;
1032916
1033917   /* 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;
1036920
1037   context->output_is_ac = info->options & DISC_555_OUT_AC;
921   m_output_is_ac = info->options & DISC_555_OUT_AC;
1038922   /* 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;
1040924
1041925   /* There are 8 different types of basic oscillators
1042926     * depending on the resistors used.  We will determine
1043927     * the type of circuit at reset, because the ciruit type
1044928     * is constant.  See Below.
1045929     */
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);
1047931
1048932   /* 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;
1052936   else
1053937   {
1054      switch (context->type)   /* see dsd_555_cc_reset for descriptions */
938      switch (m_type)   /* see dsd_555_cc_reset for descriptions */
1055939      {
1056940         case 1:
1057941            r_discharge = DSD_555_CC__RDIS;
r10048r10049
1079963            break;
1080964      }
1081965
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);
1091975   }
1092976
1093977   /* Step to set the output */
1094   DISCRETE_STEP_CALL(dsd_555_cc);
978   this->step();
1095979
1096980   /*
1097981     * TYPES:
r10048r10049
12461130
12471131DISCRETE_STEP(dsd_555_vco1)
12481132{
1249   DISCRETE_DECLARE_CONTEXT(dsd_555_vco1)
12501133   DISCRETE_DECLARE_INFO(discrete_555_vco1_desc)
12511134
12521135   int      count_f = 0;
r10048r10049
12561139   double   v_cap;         /* Current voltage on capacitor, before dt */
12571140   double   v_cap_next = 0;   /* Voltage on capacitor, after dt */
12581141
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;
12611144
12621145   /* 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 */
12641147   {
12651148      /* If CV is less then .25V, the circuit will oscillate way out of range.
12661149         * So we will just ignore it when it happens. */
12671150      if (DSD_555_VCO1__VIN2 < .25) return;
12681151      /* 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;
12711154      /* Since the thresholds may have changed we need to update the FF */
1272      if (v_cap >= context->threshold)
1155      if (v_cap >= m_threshold)
12731156      {
12741157         x_time = dt;
1275         context->flip_flop = 0;
1158         m_flip_flop = 0;
12761159         count_f++;
12771160      }
12781161      else
1279      if (v_cap <= context->trigger)
1162      if (v_cap <= m_trigger)
12801163      {
12811164         x_time = dt;
1282         context->flip_flop = 1;
1165         m_flip_flop = 1;
12831166         count_r++;
12841167      }
12851168   }
r10048r10049
12871170   /* Keep looping until all toggling in time sample is used up. */
12881171   do
12891172   {
1290      if (context->flip_flop)
1173      if (m_flip_flop)
12911174      {
12921175         /* if we are in reset then toggle f/f and discharge */
12931176         if (!DSD_555_VCO1__RESET)   /* reset active low */
12941177         {
1295            context->flip_flop = 0;
1178            m_flip_flop = 0;
12961179            count_f++;
12971180         }
12981181         else
12991182         {
13001183            /* Charging */
13011184            /* 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);
13031186            dt         = 0;
13041187
13051188            /* has it charged past upper limit? */
1306            if (v_cap_next >= context->threshold)
1189            if (v_cap_next >= m_threshold)
13071190            {
13081191               /* 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;
13111194               x_time = dt;
1312               context->flip_flop = 0;
1195               m_flip_flop = 0;
13131196               count_f++;
13141197            }
13151198         }
r10048r10049
13181201      {
13191202         /* Discharging */
13201203         /* 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);
13221205
13231206         /* if we are in reset, then the cap can discharge to 0 */
13241207         if (!DSD_555_VCO1__RESET)   /* reset active low */
r10048r10049
13301213         {
13311214            /* if we are out of reset and the cap voltage is less then
13321215                 * the lower threshold, toggle f/f and start charging */
1333            if (v_cap <= context->trigger)
1216            if (v_cap <= m_trigger)
13341217            {
1335               if (context->flip_flop == 0)
1218               if (m_flip_flop == 0)
13361219               {
13371220                  /* don't need to track x_time here */
1338                  context->flip_flop = 1;
1221                  m_flip_flop = 1;
13391222                  count_r++;
13401223               }
13411224            }
r10048r10049
13431226            {
13441227               dt = 0;
13451228               /* has it discharged past lower limit? */
1346               if (v_cap_next <= context->trigger)
1229               if (v_cap_next <= m_trigger)
13471230               {
13481231                  /* 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;
13511234                  x_time = dt;
1352                  context->flip_flop = 1;
1235                  m_flip_flop = 1;
13531236                  count_r++;
13541237               }
13551238            }
r10048r10049
13571240      }
13581241   } while(dt);
13591242
1360   context->cap_voltage = v_cap_next;
1243   m_cap_voltage = v_cap_next;
13611244
13621245   /* 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();
13641247   if (!DSD_555_VCO1__RESET) x_time = 0;
13651248
1366   switch (context->output_type)
1249   switch (m_output_type)
13671250   {
13681251      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;
13701253         break;
13711254      case DISC_555_OUT_CAP:
1372         node->output[0] = v_cap_next;
1255         this->output[0] = v_cap_next;
13731256         /* 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;
13761259         break;
13771260      case DISC_555_OUT_ENERGY:
13781261         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;
13811264         break;
13821265      case DISC_555_OUT_LOGIC_X:
1383         node->output[0] = context->flip_flop + x_time;
1266         this->output[0] = m_flip_flop + x_time;
13841267         break;
13851268      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;
13871270         break;
13881271      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;
13901273         break;
13911274      case DISC_555_OUT_COUNT_F:
1392         node->output[0] = count_f;
1275         this->output[0] = count_f;
13931276         break;
13941277      case DISC_555_OUT_COUNT_R:
1395         node->output[0] = count_r;
1278         this->output[0] = count_r;
13961279         break;
13971280   }
13981281}
13991282
14001283DISCRETE_RESET(dsd_555_vco1)
14011284{
1402   DISCRETE_DECLARE_CONTEXT(dsd_555_vco1)
14031285   DISCRETE_DECLARE_INFO(discrete_555_vco1_desc)
14041286
14051287   double v_ratio_r3, v_ratio_r4_1, r_in_1;
14061288
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;
14091291
14101292   /* Setup op-amp parameters */
14111293
r10048r10049
14231305
14241306   /* Now that we know the voltages entering the op amp and the resistance for the
14251307     * 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;
14281310
14291311   /* the cap starts off discharged */
1430   context->cap_voltage = 0;
1312   m_cap_voltage = 0;
14311313
14321314   /* Setup 555 parameters */
14331315
14341316   /* 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;
14381320
14391321   /* Calculate 555 thresholds.
14401322     * If the Control Voltage is a node, then the thresholds will be calculated each step.
14411323     * If the Control Voltage is a fixed voltage, then the thresholds will be calculated
14421324     * 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))
14441326   {
14451327      /* 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;
14481330   }
14491331   else
14501332   {
14511333      /* 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;
14541336   }
14551337
14561338   /* 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;
14581340}
14591341
14601342
r10048r10049
15371419
15381420DISCRETE_STEP(dsd_566)
15391421{
1540   DISCRETE_DECLARE_CONTEXT(dsd_566)
1541
15421422   double   i = 0;         /* Charging current created by vIn */
15431423   double   i_rise;         /* non-linear rise charge current */
15441424   double   dt;            /* change in time */
r10048r10049
15461426   double   v_cap;         /* Current voltage on capacitor, before dt */
15471427   int      count_f = 0, count_r = 0;
15481428
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 */
15511431
15521432   /* 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))
15541434   {
15551435      double v_charge = DSD_566__VCHARGE - DSD_566__VMOD - 0.1;
15561436      if (v_charge > 0)
15571437      {
15581438         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)
15601440         {
15611441            /* 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);
15641444         }
15651445         else
15661446            i_rise = i;
r10048r10049
15731453   /* Keep looping until all toggling in this time sample is used up. */
15741454   do
15751455   {
1576      if (context->flip_flop)
1456      if (m_flip_flop)
15771457      {
15781458         /* Discharging */
15791459         v_cap -= i * dt / DSD_566__C;
15801460         dt     = 0;
15811461
15821462         /* has it discharged past lower limit? */
1583         if (UNEXPECTED(v_cap < context->threshold_low))
1463         if (UNEXPECTED(v_cap < m_threshold_low))
15841464         {
15851465            /* 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;
15891469            count_f++;
15901470            x_time = dt;
15911471         }
r10048r10049
16041484         if (UNEXPECTED(v_cap > DSD_566__VMOD)) v_cap = DSD_566__VMOD;
16051485
16061486         /* has it charged past upper limit? */
1607         if (UNEXPECTED(v_cap > context->threshold_high))
1487         if (UNEXPECTED(v_cap > m_threshold_high))
16081488         {
16091489            /* 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;
16131493            count_r++;
16141494            x_time = dt;
16151495         }
16161496      }
16171497   } while(dt);
16181498
1619   context->cap_voltage = v_cap;
1499   m_cap_voltage = v_cap;
16201500
16211501   /* Convert last switch time to a ratio */
1622   x_time /= node->info->sample_time;
1502   x_time /= this->sample_time();
16231503
1624   switch (context->out_type)
1504   switch (m_out_type)
16251505   {
16261506      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;
16301510         break;
16311511      case DISC_566_OUT_ENERGY:
16321512         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;
16361516         break;
16371517      case DISC_566_OUT_LOGIC:
1638            node->output[0] = context->flip_flop;
1518            this->output[0] = m_flip_flop;
16391519         break;
16401520      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;
16441524         break;
16451525      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;
16471527         break;
16481528      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;
16501530         break;
16511531      case DISC_566_OUT_COUNT_F:
1652         node->output[0] = count_f;
1532         this->output[0] = count_f;
16531533         break;
16541534      case DISC_566_OUT_COUNT_R:
1655         node->output[0] = count_r;
1535         this->output[0] = count_r;
16561536         break;
16571537   }
16581538}
16591539
16601540DISCRETE_RESET(dsd_566)
16611541{
1662   DISCRETE_DECLARE_CONTEXT(dsd_566)
1663
16641542   int      v_int;
16651543   double   v_float;
16661544
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;
16691547
16701548   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());
16721550
16731551   v_float = DSD_566__VPOS - DSD_566__VNEG;
16741552   v_int = (int)v_float;
16751553   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());
16771555   if ( v_float != v_int )
16781556      /* 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());
16801558
1681   context->flip_flop   = 0;
1682   context->cap_voltage = 0;
1559   m_flip_flop   = 0;
1560   m_cap_voltage = 0;
16831561
16841562   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;
16921570
1693   context->ac_shift = 0;
1694   if (context->fake_ac)
1571   m_ac_shift = 0;
1572   if (m_fake_ac)
16951573   {
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;
16981576      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;
17001578   }
17011579
17021580   /* Step the output */
1703   DISCRETE_STEP_CALL(dsd_566);
1581   this->step();
17041582}
17051583
17061584
r10048r10049
17601638
17611639DISCRETE_STEP(dsd_ls624)
17621640{
1763   DISCRETE_DECLARE_CONTEXT(dsd_ls624)
1764
17651641   double   x_time = 0;
17661642   double   freq, t1;
17671643   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();;
17701646   double   v_freq = DSD_LS624__VMOD;
17711647   double   v_rng = DSD_LS624__VRNG;
17721648   int      count_f = 0, count_r = 0;
r10048r10049
17871663      return;
17881664
17891665   /* 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;
17921668
17931669   /* apply cap if needed */
1794   if (context->has_freq_in_cap)
1670   if (m_has_freq_in_cap)
17951671   {
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;
17981674   }
17991675
18001676   /* Polyfunctional3D_model created by zunzun.com using sum of squared absolute error */
r10048r10049
18151691   freq *= CAP_U(0.1) / DSD_LS624__C;
18161692
18171693   t1 = 0.5 / freq ;
1818   t_used += node->info->sample_time;
1694   t_used += this->sample_time();
18191695   do
18201696   {
18211697      dt = 0;
r10048r10049
18231699      {
18241700         /* calculate the overshoot time */
18251701         t_used -= t1;
1826         context->flip_flop ^= 1;
1827         if (context->flip_flop)
1702         m_flip_flop ^= 1;
1703         if (m_flip_flop)
18281704            count_r++;
18291705         else
18301706            count_f++;
18311707         /* 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();
18341710         x_time = t_used;
18351711         dt = t_used;
18361712      }
18371713   }while(dt);
18381714
1839   context->t_used = t_used;
1715   m_t_used = t_used;
18401716
18411717   /* Convert last switch time to a ratio */
1842   x_time = x_time / node->info->sample_time;
1718   x_time = x_time / this->sample_time();
18431719
1844   switch (context->out_type)
1720   switch (m_out_type)
18451721   {
18461722      case DISC_LS624_OUT_LOGIC_X:
1847            node->output[0] = context->flip_flop  + x_time;
1723            this->output[0] = m_flip_flop  + x_time;
18481724         break;
18491725      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;
18511727         break;
18521728      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;
18541730         break;
18551731      case DISC_LS624_OUT_COUNT_F:
1856         node->output[0] = count_f;
1732         this->output[0] = count_f;
18571733         break;
18581734      case DISC_LS624_OUT_COUNT_R:
1859         node->output[0] = count_r;
1735         this->output[0] = count_r;
18601736         break;
18611737      case DISC_LS624_OUT_ENERGY:
18621738         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));
18641740         break;
18651741      case DISC_LS624_OUT_LOGIC:
1866            node->output[0] = context->flip_flop;
1742            this->output[0] = m_flip_flop;
18671743         break;
18681744      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;
18701746         break;
18711747   }
18721748}
18731749
18741750DISCRETE_RESET(dsd_ls624)
18751751{
1876   struct dsd_ls624_context *context = (struct dsd_ls624_context *)node->context;
1752   m_out_type = (int)DSD_LS624__OUTTYPE;
18771753
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);
18841758   if (DSD_LS624__C_FREQ_IN > 0)
18851759   {
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;
18891763   }
18901764   else
1891      context->has_freq_in_cap = 0;
1765      m_has_freq_in_cap = 0;
18921766
1893   node->output[0] = 0;
1767   this->output[0] = 0;
18941768}
src/emu/sound/disc_dev.h
r0r10049
1#pragma once
2
3#ifndef __DISC_DEV_H__
4#define __DISC_DEV_H__
5
6/***********************************************************************
7 *
8 *  MAME - Discrete sound system emulation library
9 *
10 *  Written by Keith Wilkins (mame@esplexo.co.uk)
11 *
12 *  (c) K.Wilkins 2000
13 *
14 *  Coding started in November 2000
15 *
16 *  Additions/bugfix February 2003 - D.Renaud, F.Palazzolo, K.Wilkins
17 *  Discrete parallel tasks 2009 - Couriersud
18 *  Discrete classes 2010       - Couriersud
19 *
20 ***********************************************************************/
21
22#include "discrete.h"
23
24DISCRETE_CLASS_STEP_RESETA(dsd_555_astbl, 1,
25   int      m_use_ctrlv;
26   int      m_output_type;
27   int      m_output_is_ac;
28   double   m_ac_shift;         /* DC shift needed to make waveform ac */
29   int      m_flip_flop;         /* 555 flip/flop output state */
30   double   m_cap_voltage;      /* voltage on cap */
31   double   m_threshold;
32   double   m_trigger;
33   double   m_v_out_high;         /* Logic 1 voltage level */
34   double   m_v_charge;
35   double *m_v_charge_node;      /* point to output of node */
36   int      m_has_rc_nodes;
37   double   m_exp_bleed;
38   double   m_exp_charge;
39   double   m_exp_discharge;
40   double   m_t_rc_bleed;
41   double   m_t_rc_charge;
42   double   m_t_rc_discharge;
43   double   m_last_r1;
44   double   m_last_r2;
45   double   m_last_c;
46);
47
48DISCRETE_CLASS_STEP_RESETA(dsd_555_mstbl, 1,
49   int      m_trig_is_logic;
50   int      m_trig_discharges_cap;
51   int      m_output_type;
52   double   m_ac_shift;            /* DC shift needed to make waveform ac */
53   int      m_flip_flop;            /* 555 flip/flop output state */
54   int      m_has_rc_nodes;
55   double   m_exp_charge;
56   double   m_cap_voltage;         /* voltage on cap */
57   double   m_threshold;
58   double   m_trigger;
59   double   m_v_out_high;            /* Logic 1 voltage level */
60   double   m_v_charge;
61);
62
63DISCRETE_CLASS_STEP_RESETA(dsd_555_cc, 1,
64   unsigned int   m_type;         /* type of 555cc circuit */
65   int            m_output_type;
66   int            m_output_is_ac;
67   double         m_ac_shift;      /* DC shift needed to make waveform ac */
68   int            m_flip_flop;      /* 555 flip/flop output state */
69   double         m_cap_voltage;   /* voltage on cap */
70   double         m_threshold;
71   double         m_trigger;
72   double         m_v_out_high;      /* Logic 1 voltage level */
73   double         m_v_cc_source;
74   int            m_has_rc_nodes;
75   double         m_exp_bleed;
76   double         m_exp_charge;
77   double         m_exp_discharge;
78   double         m_exp_discharge_01;
79   double         m_exp_discharge_no_i;
80   double         m_t_rc_charge;
81   double         m_t_rc_discharge;
82   double         m_t_rc_discharge_01;
83   double         m_t_rc_discharge_no_i;
84);
85
86DISCRETE_CLASS_STEP_RESETA(dsd_555_vco1, 1,
87   int      m_ctrlv_is_node;
88   int      m_output_type;
89   int      m_output_is_ac;
90   double   m_ac_shift;         /* DC shift needed to make waveform ac */
91   int      m_flip_flop;         /* flip/flop output state */
92   double   m_v_out_high;         /* 555 high voltage */
93   double   m_threshold;         /* falling threshold */
94   double   m_trigger;         /* rising threshold */
95   double   m_i_charge;         /* charge current */
96   double   m_i_discharge;      /* discharge current */
97   double   m_cap_voltage;      /* current capacitor voltage */
98);
99
100DISCRETE_CLASS_STEP_RESETA(dsd_566, 1,
101   unsigned int m_state[2];         /* keeps track of excess flip_flop changes during the current step */
102   int         m_flip_flop;         /* 566 flip/flop output state */
103   double      m_cap_voltage;      /* voltage on cap */
104   double      m_v_sqr_low;         /* voltage for a squarewave at low */
105   double      m_v_sqr_high;         /* voltage for a squarewave at high */
106   double      m_v_sqr_diff;
107   double      m_threshold_low;      /* falling threshold */
108   double      m_threshold_high;      /* rising threshold */
109   double      m_ac_shift;         /* used to fake AC */
110   double      m_v_osc_stable;
111   double      m_v_osc_stop;
112   int         m_fake_ac;
113   int         m_out_type;
114);
115
116DISCRETE_CLASS_STEP_RESETA(dsd_ls624, 1,
117   double   m_exponent;
118   double   m_t_used;
119   double   m_v_cap_freq_in;
120   double   m_v_freq_scale;
121   double   m_v_rng_scale;
122   int      m_flip_flop;
123   int      m_has_freq_in_cap;
124   int      m_out_type;
125);
126
127#endif /* __DISC_WAV_H__ */
src/emu/sound/disc_wav.c
r10048r10049
11/************************************************************************
22 *
33 *  MAME - Discrete sound system emulation library
4 *
54 *  Written by Keith Wilkins (mame@esplexo.co.uk)
65 *
76 *  (c) K.Wilkins 2000
r10048r10049
2322 *
2423 ************************************************************************/
2524
26struct dss_adsr_context
27{
28   double phase;
29};
3025
31struct 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};
4426
45#define DSS_INV_TAB_SIZE   500
4627
47struct 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};
6128
62struct 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};
7529
76struct dss_noise_context
77{
78   double phase;
79};
8030
81struct 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
94struct 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
125struct dss_sawtoothwave_context
126{
127   double   phase;
128   int      type;
129};
130
131struct 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
143struct dss_sinewave_context
144{
145   double phase;
146};
147
148struct dss_squarewave_context
149{
150   double phase;
151   double trigger;
152};
153
154struct 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
163struct dss_trianglewave_context
164{
165   double phase;
166};
167
168
16931/************************************************************************
17032 *
17133 * DSS_COUNTER - External clock Binary Counter
r10048r10049
19456
19557DISCRETE_STEP(dss_counter)
19658{
197   DISCRETE_DECLARE_CONTEXT(dss_counter)
198
19959   double   cycles;
20060   double   ds_clock;
20161   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 */
20363   double   x_time = 0;
20464   UINT32   count = last_count;
20565
20666   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))
20868   {
20969      /* 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;
21171      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();
21474   }
21575   else
21676   {
r10048r10049
22383   /* If reset enabled then set output to the reset value.  No x_time in reset. */
22484   if (UNEXPECTED(DSS_COUNTER__RESET))
22585   {
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;
22888      return;
22989   }
23090
r10048r10049
23494     */
23595   if (EXPECTED(DSS_COUNTER__ENABLE))
23696   {
237      switch (context->clock_type)
97      switch (m_clock_type)
23898      {
23999         case DISC_CLK_ON_F_EDGE:
240100         case DISC_CLK_ON_R_EDGE:
241101            /* See if the clock has toggled to the proper edge */
242102            clock = (clock != 0);
243            if (context->last_clock != clock)
103            if (m_last_clock != clock)
244104            {
245               context->last_clock = clock;
246               if (context->clock_type == clock)
105               m_last_clock = clock;
106               if (m_clock_type == clock)
247107               {
248108                  /* Toggled */
249109                  inc = 1;
r10048r10049
261121      if (DSS_COUNTER__DIR)
262122      {
263123         count += inc;
264         while (count > context->max)
124         while (count > m_max)
265125         {
266            count -= context->diff;
126            count -= m_diff;
267127         }
268128      }
269129      else
270130      {
271131         count -= inc;
272         while (count < context->min)
132         while (count < m_min)
273133         {
274            count += context->diff;
134            count += m_diff;
275135         }
276136      }
277137
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;
280140
281141      if (UNEXPECTED(count != last_count))
282142      {
283143         /* the x_time is only output if the output changed. */
284         switch (context->out_type)
144         switch (m_out_type)
285145         {
286146            case DISC_OUT_HAS_XTIME:
287               node->output[0] += x_time;
147               this->output[0] += x_time;
288148               break;
289149            case DISC_OUT_IS_ENERGY:
290150               if (x_time == 0) x_time = 1.0;
291               node->output[0] = last_count;
151               this->output[0] = last_count;
292152               if (count > last_count)
293                  node->output[0] += (count - last_count) * x_time;
153                  this->output[0] += (count - last_count) * x_time;
294154               else
295                  node->output[0] -= (last_count - count) * x_time;
155                  this->output[0] -= (last_count - count) * x_time;
296156               break;
297157         }
298158      }
r10048r10049
301161
302162DISCRETE_RESET(dss_counter)
303163{
304   DISCRETE_DECLARE_CONTEXT(dss_counter)
305164
306165   if ((int)DSS_COUNTER__CLOCK_TYPE & DISC_COUNTER_IS_7492)
307166   {
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;
313172   }
314173   else
315174   {
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;
321180   }
322181
323182
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());
326185
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;
329188
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 */
334193}
335194
336195
r10048r10049
355214#define DSS_LFSR_NOISE__FEED   DISCRETE_INPUT(4)
356215#define DSS_LFSR_NOISE__BIAS   DISCRETE_INPUT(5)
357216
358INLINE int dss_lfsr_function(const discrete_info *disc_info, int myfunc, int in0, int in1, int bitmask)
217INLINE int dss_lfsr_function(discrete_device *dev, int myfunc, int in0, int in1, int bitmask)
359218{
360219   int retval;
361220
r10048r10049
410269         retval = retval ^ in0;  /* xor in0 */
411270         break;
412271      default:
413         discrete_log(disc_info, "dss_lfsr_function - Invalid function type passed");
272         dev->discrete_log("dss_lfsr_function - Invalid function type passed");
414273         retval=0;
415274         break;
416275   }
417276   return retval;
418277}
419278
420/* reset prototype so that it can be used in init function */
421DISCRETE_RESET(dss_lfsr);
422279
423DISCRETE_STEP(dss_lfsr)
280DISCRETE_STEP(dss_lfsr_noise)
424281{
425   DISCRETE_DECLARE_CONTEXT(dss_lfsr)
426282   DISCRETE_DECLARE_INFO(discrete_lfsr_desc)
427283
428284   double cycles;
r10048r10049
432288   if (info->clock_type == DISC_CLK_IS_FREQ)
433289   {
434290      /* 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;
436292      inc    = (int)cycles;
437      context->t_left = (cycles - inc) * context->t_clock;
293      m_t_left = (cycles - inc) * m_t_clock;
438294   }
439295
440296   /* 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)
442298   {
443      DISCRETE_RESET_CALL(dss_lfsr);
299      this->reset();
444300      return;
445301   }
446302
r10048r10049
450306      case DISC_CLK_ON_R_EDGE:
451307         /* See if the clock has toggled to the proper edge */
452308         clock = (DSS_LFSR_NOISE__CLOCK != 0);
453         if (context->last != clock)
309         if (m_last != clock)
454310         {
455            context->last = clock;
311            m_last = clock;
456312            if (info->clock_type == clock)
457313            {
458314               /* Toggled */
r10048r10049
473329      for (clock = 0; clock < inc; clock++)
474330      {
475331         /* Fetch the last feedback result */
476         fbresult = (context->lfsr_reg >> info->bitlength) & 0x01;
332         fbresult = (m_lfsr_reg >> info->bitlength) & 0x01;
477333
478334         /* 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);
480336
481337         /* Stage 3 first we setup where the bit is going to be shifted into */
482338         fbresult = fbresult * info->feedback_function2_mask;
483339         /* Then we left shift the register, */
484         context->lfsr_reg = context->lfsr_reg << 1;
340         m_lfsr_reg = m_lfsr_reg << 1;
485341         /* 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 );
487343
488344         /* Now get and store the new feedback result */
489345         /* 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;
492348         /* 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);
495351
496352      }
497353      /* 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;
500356      else
501         node->output[0] = (context->lfsr_reg >> info->output_bit) & 0x01;
357         this->output[0] = (m_lfsr_reg >> info->output_bit) & 0x01;
502358
503359      /* 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;
505361
506362      /* 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;
508364      /* 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;
510366
511367      /* 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;
514370
515371   }
516372   if(!DSS_LFSR_NOISE__ENABLE)
517373   {
518      node->output[0] = 0;
374      this->output[0] = 0;
519375   }
520376}
521377
522DISCRETE_RESET(dss_lfsr)
378DISCRETE_RESET(dss_lfsr_noise)
523379{
524   DISCRETE_DECLARE_CONTEXT(dss_lfsr)
525380   DISCRETE_DECLARE_INFO(discrete_lfsr_desc)
526381
527382   int    fb0 , fb1, fbresult;
528383
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;
533388
534389   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());
536391
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;
540395
541   context->lfsr_reg = info->reset_value;
396   m_lfsr_reg = info->reset_value;
542397
543398   /* Now get and store the new feedback result */
544399   /* 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;
547402   /* 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);
550405
551406   /* 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;
553408
554409   /* 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;
556411
557412   /* 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;
559414   /* 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;
561416}
562417
563418
r10048r10049
578433
579434DISCRETE_STEP(dss_noise)
580435{
581   DISCRETE_DECLARE_CONTEXT(dss_noise)
582
583436   if(DSS_NOISE__ENABLE)
584437   {
585438      /* Only sample noise on rollover to next cycle */
586      if(context->phase > (2.0 * M_PI))
439      if(m_phase > (2.0 * M_PI))
587440      {
588441         /* 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;
590443
591444         /* 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;
593446         if (newval > 0)
594            node->output[0] *= ((double)newval / 16383);
447            this->output[0] *= ((double)newval / 16383);
595448         else
596            node->output[0] *= ((double)newval / 16384);
449            this->output[0] *= ((double)newval / 16384);
597450
598451         /* Add DC Bias component */
599         node->output[0] += DSS_NOISE__BIAS;
452         this->output[0] += DSS_NOISE__BIAS;
600453      }
601454   }
602455   else
603456   {
604      node->output[0] = 0;
457      this->output[0] = 0;
605458   }
606459
607460   /* 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);
609462
610463   /* The enable input only curtails output, phase rotation still occurs. */
611464   /* 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());
613466}
614467
615468
616469DISCRETE_RESET(dss_noise)
617470{
618   DISCRETE_DECLARE_CONTEXT(dss_noise)
619
620   context->phase=0;
621   DISCRETE_STEP_CALL( dss_noise );
471   m_phase=0;
472   this->step();
622473}
623474
624475
r10048r10049
644495
645496DISCRETE_STEP(dss_note)
646497{
647   DISCRETE_DECLARE_CONTEXT(dss_note)
648
649498   double   cycles;
650499   int      clock  = 0, last_count2, inc = 0;
651500   double   x_time = 0;
652501
653   if (context->clock_type == DISC_CLK_IS_FREQ)
502   if (m_clock_type == DISC_CLK_IS_FREQ)
654503   {
655504      /* 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;
657506      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();
660509   }
661510   else
662511   {
r10048r10049
667516
668517   if (DSS_NOTE__ENABLE)
669518   {
670      last_count2 = context->count2;
519      last_count2 = m_count2;
671520
672      switch (context->clock_type)
521      switch (m_clock_type)
673522      {
674523         case DISC_CLK_ON_F_EDGE:
675524         case DISC_CLK_ON_R_EDGE:
676525            /* See if the clock has toggled to the proper edge */
677526            clock = (clock != 0);
678            if (context->last != clock)
527            if (m_last != clock)
679528            {
680               context->last = clock;
681               if (context->clock_type == clock)
529               m_last = clock;
530               if (m_clock_type == clock)
682531               {
683532                  /* Toggled */
684533                  inc = 1;
r10048r10049
697546      {
698547         for (clock = 0; clock < inc; clock++)
699548         {
700            context->count1++;
701            if (context->count1 > context->max1)
549            m_count1++;
550            if (m_count1 > m_max1)
702551            {
703552               /* 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;
707556            }
708557         }
709558      }
710559
711      node->output[0] = context->count2;
712      if (context->count2 != last_count2)
560      this->output[0] = m_count2;
561      if (m_count2 != last_count2)
713562      {
714563         /* the x_time is only output if the output changed. */
715         switch (context->out_type)
564         switch (m_out_type)
716565         {
717566            case DISC_OUT_IS_ENERGY:
718567               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;
722571               else
723                  node->output[0] -= (last_count2 - context->count2) * x_time;
572                  this->output[0] -= (last_count2 - m_count2) * x_time;
724573               break;
725574            case DISC_OUT_HAS_XTIME:
726               node->output[0] += x_time;
575               this->output[0] += x_time;
727576               break;
728577         }
729578      }
730579   }
731580   else
732      node->output[0] = 0;
581      this->output[0] = 0;
733582}
734583
735584DISCRETE_RESET(dss_note)
736585{
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;
738588
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;
741592
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;
751598}
752599
753600/************************************************************************
r10048r10049
769616/* The inputs on a norton op-amp are (info->vP - OP_AMP_NORTON_VBE) */
770617/* which is the same as the output high voltage.  We will define them */
771618/* 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
773620
774621DISCRETE_STEP(dss_op_amp_osc)
775622{
776   DISCRETE_DECLARE_CONTEXT(dss_op_amp_osc)
777623   DISCRETE_DECLARE_INFO(discrete_op_amp_osc_info)
778624
779625   double i = 0;            /* Charging current created by vIn */
r10048r10049
787633   UINT8 force_charge = 0;
788634   UINT8 enable = DSS_OP_AMP_OSC__ENABLE;
789635   UINT8 update_exponent = 0;
790   UINT8 flip_flop = context->flip_flop;
636   UINT8 flip_flop = m_flip_flop;
791637   int count_f = 0;
792638   int count_r = 0;
793639
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 */
796642
797643   /* work out the charge currents/voltages. */
798   switch (context->type)
644   switch (m_type)
799645   {
800646      case DISC_OP_AMP_OSCILLATOR_VCO_1:
801647         /* Work out the charge rates. */
802648         /* 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;
804650         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;
806652         break;
807653
808654      case DISC_OP_AMP_OSCILLATOR_1 | DISC_OP_AMP_IS_NORTON:
r10048r10049
810656         /* resistors can be nodes, so everything needs updating */
811657         double i1, i2;
812658         /* add in enable current if using real enable */
813         if (context->has_enable)
659         if (m_has_enable)
814660         {
815661            if (enable)
816               i = context->i_enable;
662               i = m_i_enable;
817663            enable = 1;
818664         }
819665         /* 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];
822668         /* 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;
828674         break;
829675      }
830676
r10048r10049
838684         else
839685         {
840686            /* we need to mix any bias and all modulation voltages together. */
841            i  = context->i_fixed;
687            i  = m_i_fixed;
842688            i += DSS_OP_AMP_OSC__VMOD1 / info->r7;
843689            if (info->r8 != 0)
844690               i += DSS_OP_AMP_OSC__VMOD2 / info->r8;
845            v  = i * context->r_total;
691            v  = i * m_r_total;
846692         }
847693
848694         /* Work out the charge rates. */
r10048r10049
858704      case DISC_OP_AMP_OSCILLATOR_VCO_2 | DISC_OP_AMP_IS_NORTON:
859705         /* Work out the charge rates. */
860706         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;
863709         /* if the negative pin current is less then the positive pin current, */
864710         /* then the osc is disabled and the cap keeps charging */
865711         if (charge[0] < 0)
r10048r10049
871717
872718      case DISC_OP_AMP_OSCILLATOR_VCO_3 | DISC_OP_AMP_IS_NORTON:
873719         /* start with fixed bias */
874         charge[0] = context->i_fixed;
720         charge[0] = m_i_fixed;
875721         /* add in enable current if using real enable */
876         if (context->has_enable)
722         if (m_has_enable)
877723         {
878724            if (enable)
879               charge[0] -= context->i_enable;
725               charge[0] -= m_i_enable;
880726            enable = 1;
881727         }
882728         /* we need to mix any bias and all modulation voltages together. */
r10048r10049
888734            v = DSS_OP_AMP_OSC__VMOD2 - OP_AMP_NORTON_VBE;
889735            charge[0] += v / info->r6;
890736         }
891         charge[1] = context->temp1 - charge[0];
737         charge[1] = m_temp1 - charge[0];
892738         break;
893739   }
894740
895741   if (!enable)
896742   {
897743      /* we will just output 0 for oscillators that have no real enable. */
898      node->output[0] = 0;
744      this->output[0] = 0;
899745      return;
900746   }
901747
902748   /* Keep looping until all toggling in time sample is used up. */
903749   do
904750   {
905      if (context->is_linear_charge)
751      if (m_is_linear_charge)
906752      {
907         if ((flip_flop ^ context->flip_flop_xor) || force_charge)
753         if ((flip_flop ^ m_flip_flop_xor) || force_charge)
908754         {
909755            /* Charging */
910756            /* iC=C*dv/dt  works out to dv=iC*dt/C */
r10048r10049
912758            dt = 0;
913759
914760            /* has it charged past upper limit? */
915            if (v_cap_next > context->threshold_high)
761            if (v_cap_next > m_threshold_high)
916762            {
917               flip_flop = context->flip_flop_xor;
763               flip_flop = m_flip_flop_xor;
918764               if (flip_flop)
919765                  count_r++;
920766               else
r10048r10049
922768               if (force_charge)
923769               {
924770                  /* 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;
927773               }
928774               else
929775               {
930776                  /* 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];
932778                  x_time = dt;
933                  v_cap_next = context->threshold_high;
779                  v_cap_next = m_threshold_high;
934780               }
935781            }
936782         }
r10048r10049
941787            dt     = 0;
942788
943789            /* has it discharged past lower limit? */
944            if (v_cap_next < context->threshold_low)
790            if (v_cap_next < m_threshold_low)
945791            {
946               flip_flop = !context->flip_flop_xor;
792               flip_flop = !m_flip_flop_xor;
947793               if (flip_flop)
948794                  count_r++;
949795               else
950796                  count_f++;
951797               /* 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];
953799               x_time = dt;
954               v_cap_next = context->threshold_low;
800               v_cap_next = m_threshold_low;
955801            }
956802         }
957803      }
958804      else   /* non-linear charge */
959805      {
960806         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);
962808         else
963            exponent = context->charge_exp[flip_flop];
809            exponent = m_charge_exp[flip_flop];
964810
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);
966812         dt = 0;
967813
968814         if (flip_flop)
969815         {
970816            /* Has it charged past upper limit? */
971            if (v_cap_next > context->threshold_high)
817            if (v_cap_next > m_threshold_high)
972818            {
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))));
974820               x_time = dt;
975               v_cap_next = context->threshold_high;
821               v_cap_next = m_threshold_high;
976822               flip_flop = 0;
977823               count_f++;
978824               update_exponent = 1;
r10048r10049
981827         else
982828         {
983829            /* has it discharged past lower limit? */
984            if (v_cap_next < context->threshold_low)
830            if (v_cap_next < m_threshold_low)
985831            {
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)));
987833               x_time = dt;
988               v_cap_next = context->threshold_low;
834               v_cap_next = m_threshold_low;
989835               flip_flop = 1;
990836               count_r++;
991837               update_exponent = 1;
r10048r10049
994840      }
995841      v_cap = v_cap_next;
996842   } 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;
999845   if (v_cap < 0)
1000846      v_cap = 0;
1001   context->v_cap = v_cap;
847   m_v_cap = v_cap;
1002848
1003   x_time = dt / node->info->sample_time;
849   x_time = dt / this->sample_time();
1004850
1005   switch (context->output_type)
851   switch (m_output_type)
1006852   {
1007853      case DISC_OP_AMP_OSCILLATOR_OUT_CAP:
1008         node->output[0] = v_cap;
854         this->output[0] = v_cap;
1009855         break;
1010856      case DISC_OP_AMP_OSCILLATOR_OUT_ENERGY:
1011857         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));
1013859         break;
1014860      case DISC_OP_AMP_OSCILLATOR_OUT_SQW:
1015861         if (count_f + count_r >= 2)
1016862            /* 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;
1018864         else
1019            node->output[0] = flip_flop * context->v_out_high;
865            this->output[0] = flip_flop * m_v_out_high;
1020866         break;
1021867      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;
1023869         break;
1024870      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;
1026872         break;
1027873      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;
1029875         break;
1030876   }
1031   context->flip_flop = flip_flop;
877   m_flip_flop = flip_flop;
1032878}
1033879
1034880#define DIODE_DROP   0.7
1035881
1036882DISCRETE_RESET(dss_op_amp_osc)
1037883{
1038   DISCRETE_DECLARE_CONTEXT(dss_op_amp_osc)
1039884   DISCRETE_DECLARE_INFO(discrete_op_amp_osc_info)
1040885
1041886   const double *r_info_ptr;
1042887   const double **r_context_ptr;
1043888   int loop;
1044   node_description *r_node;
889   discrete_base_node *r_node;
1045890
1046891   double i1 = 0;   /* inverting input current */
1047892   double i2 = 0;   /* non-inverting input current */
1048893
1049894   /* link to resistor static or node values */
1050895   r_info_ptr    = &info->r1;
1051   r_context_ptr = &context->r1;
896   r_context_ptr = &m_r1;
1052897   for (loop = 0; loop < 8; loop ++)
1053898   {
1054899      if IS_VALUE_A_NODE(*r_info_ptr)
1055900      {
1056         r_node = discrete_find_node(node->info, *r_info_ptr);
901         r_node = this->device->discrete_find_node(*r_info_ptr);
1057902         *r_context_ptr = &(r_node->output[NODE_CHILD_NODE_NUM((int)*r_info_ptr)]);
1058903      }
1059904      else
r10048r10049
1062907      r_context_ptr++;
1063908   }
1064909
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;
1074919
1075   switch (context->type)
920   switch (m_type)
1076921   {
1077922      case DISC_OP_AMP_OSCILLATOR_VCO_1:
1078923         /* The charge rates vary depending on vMod so they are not precalculated. */
1079924         /* Charges while FlipFlop High */
1080         context->flip_flop_xor = 0;
925         m_flip_flop_xor = 0;
1081926         /* 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;
1087932         /* There is no charge on the cap so the schmitt goes high at init. */
1088         context->flip_flop = 1;
933         m_flip_flop = 1;
1089934         /* 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 */
1093938         break;
1094939
1095940      case DISC_OP_AMP_OSCILLATOR_1 | DISC_OP_AMP_IS_NORTON:
1096941         /* Charges while FlipFlop High */
1097         context->flip_flop_xor = 0;
942         m_flip_flop_xor = 0;
1098943         /* 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;
1100945         /* setup current if using real enable */
1101946         if (info->r6 > 0)
1102947         {
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));
1105950         }
1106951         break;
1107952
1108953      case DISC_OP_AMP_OSCILLATOR_2 | DISC_OP_AMP_IS_NORTON:
1109         context->is_linear_charge = 0;
954         m_is_linear_charge = 0;
1110955         /* First calculate the parallel charge resistors and volatges. */
1111956         /* We can cheat and just calcuate the charges in the working area. */
1112957         /* The thresholds are well past the effect of the voltage drop */
1113958         /* and the component tolerances far exceed the .5V charge difference */
1114959         if (info->r1 != 0)
1115960         {
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;
1119964         }
1120965         if (info->r5 != 0)
1121966         {
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;
1124969         }
1125970         if (info->r6 != 0)
1126971         {
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;
1129974         }
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];
1138983
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;
1147992
1148993         /* 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;
1150995         break;
1151996
1152997      case DISC_OP_AMP_OSCILLATOR_VCO_1 | DISC_OP_AMP_IS_NORTON:
1153998         /* Charges while FlipFlop Low */
1154         context->flip_flop_xor = 1;
999         m_flip_flop_xor = 1;
11551000         /* There is no charge on the cap so the schmitt goes low at init. */
1156         context->flip_flop = 0;
1001         m_flip_flop = 0;
11571002         /* The charge rates vary depending on vMod so they are not precalculated. */
11581003         /* 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;
11621007         /* 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;
11671012         /* Work out the Non-inverting Schmitt thresholds. */
11681013         i1 = (info->vP - OP_AMP_NORTON_VBE) / info->r5;
11691014         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;
11711016         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;
11731018         break;
11741019
11751020      case DISC_OP_AMP_OSCILLATOR_VCO_2 | DISC_OP_AMP_IS_NORTON:
11761021         /* Charges while FlipFlop High */
1177         context->flip_flop_xor = 0;
1022         m_flip_flop_xor = 0;
11781023         /* 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;
11801025         /* 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);
11831028         /* Work out the Inverting Schmitt thresholds. */
11841029         i1 = (info->vP - OP_AMP_NORTON_VBE) / info->r5;
11851030         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;
11871032         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;
11891034         break;
11901035
11911036      case DISC_OP_AMP_OSCILLATOR_VCO_3 | DISC_OP_AMP_IS_NORTON:
11921037         /* Charges while FlipFlop High */
1193         context->flip_flop_xor = 0;
1038         m_flip_flop_xor = 0;
11941039         /* 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;
11961041         /* setup current if using real enable */
11971042         if (info->r8 > 0)
11981043         {
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));
12011046         }
12021047         /* Work out the charge rates. */
12031048         /* The charge rates vary depending on vMod so they are not precalculated. */
12041049         /* 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;
12071052         /* Work out the Inverting Schmitt thresholds. */
12081053         i1 = (info->vP - OP_AMP_NORTON_VBE) / info->r5;
12091054         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;
12111056         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;
12131058         break;
12141059   }
12151060
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;
12181063
1219   DISCRETE_STEP_CALL(dss_op_amp_osc);
1064   this->step();
12201065}
12211066
12221067
r10048r10049
12411086
12421087DISCRETE_STEP(dss_sawtoothwave)
12431088{
1244   DISCRETE_DECLARE_CONTEXT(dss_sawtoothwave)
1245
12461089   if(DSS_SAWTOOTHWAVE__ENABLE)
12471090   {
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;
12501093      /* Add DC Bias component */
1251      node->output[0] = node->output[0] + DSS_SAWTOOTHWAVE__BIAS;
1094      this->output[0] = this->output[0] + DSS_SAWTOOTHWAVE__BIAS;
12521095   }
12531096   else
12541097   {
1255      node->output[0] = 0;
1098      this->output[0] = 0;
12561099   }
12571100
12581101   /* Work out the phase step based on phase/freq & sample rate */
r10048r10049
12621105   /*                    boils out to                           */
12631106   /*     phase step = (2Pi*output freq)/sample freq)           */
12641107   /* 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);
12661109}
12671110
12681111DISCRETE_RESET(dss_sawtoothwave)
12691112{
1270   DISCRETE_DECLARE_CONTEXT(dss_sawtoothwave)
1271
12721113   double start;
12731114
12741115   /* Establish starting phase, convert from degrees to radians */
12751116   start = (DSS_SAWTOOTHWAVE__PHASE / 360.0) * (2.0 * M_PI);
12761117   /* Make sure its always mod 2Pi */
1277   context->phase = fmod(start, 2.0 * M_PI);
1118   m_phase = fmod(start, 2.0 * M_PI);
12781119
12791120   /* Invert gradient depending on sawtooth type /|/|/|/|/| or |\|\|\|\|\ */
1280   context->type = (DSS_SAWTOOTHWAVE__GRAD) ? 1 : 0;
1121   m_type = (DSS_SAWTOOTHWAVE__GRAD) ? 1 : 0;
12811122
12821123   /* Step the node to set the output */
1283   DISCRETE_STEP_CALL(dss_sawtoothwave);
1124   this->step();
12841125}
12851126
12861127
r10048r10049
13021143
13031144DISCRETE_STEP(dss_schmitt_osc)
13041145{
1305   DISCRETE_DECLARE_CONTEXT(dss_schmitt_osc)
13061146   DISCRETE_DECLARE_INFO(discrete_schmitt_osc_desc)
13071147
13081148   double supply, v_cap, new_vCap, t, exponent;
13091149
13101150   /* 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;
13131153
13141154   /* Keep looping until all toggling in time sample is used up. */
13151155   do
r10048r10049
13211161         * use vGate as its voltage.  Note that ration_in is just the ratio of the total
13221162         * voltage and needs to be multipled by the input voltage.  ratio_feedback has
13231163         * 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);
13261166      new_vCap = v_cap + ((supply - v_cap) * exponent);
1327      if (context->state)
1167      if (m_state)
13281168      {
13291169         /* Charging */
13301170         /* has it charged past upper limit? */
13311171         if (new_vCap > info->trshRise)
13321172         {
13331173            /* 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))));
13351175            /* 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);
13371177            v_cap    = new_vCap = info->trshRise;
1338            context->state = 0;
1178            m_state = 0;
13391179         }
13401180      }
13411181      else
r10048r10049
13451185         if (new_vCap < info->trshFall)
13461186         {
13471187            /* 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)));
13491189            /* 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);
13511191            v_cap    = new_vCap = info->trshFall;
1352            context->state = 1;
1192            m_state = 1;
13531193         }
13541194      }
13551195   } while(t);
13561196
1357   context->v_cap = new_vCap;
1197   m_v_cap = new_vCap;
13581198
1359   switch (context->enable_type)
1199   switch (m_enable_type)
13601200   {
13611201      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;
13631203         break;
13641204      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);
13661206         break;
13671207      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;
13691209         break;
13701210      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);
13721212         break;
13731213   }
1374   node->output[0] *= DSS_SCHMITT_OSC__AMP;
1214   this->output[0] *= DSS_SCHMITT_OSC__AMP;
13751215}
13761216
13771217DISCRETE_RESET(dss_schmitt_osc)
13781218{
1379   DISCRETE_DECLARE_CONTEXT(dss_schmitt_osc)
13801219   DISCRETE_DECLARE_INFO(discrete_schmitt_osc_desc)
13811220
13821221   double rSource;
13831222
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;
13861225
13871226   /* The 2 resistors make a voltage divider, so their ratios add together
13881227     * 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;
13911230
13921231   /* The voltage source resistance works out to the 2 resistors in parallel.
13931232     * So use this for the RC charge constant. */
13941233   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);
13971236
13981237   /* 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;
14011240
1402   node->output[0] = info->options ? 0 : DSS_SCHMITT_OSC__AMP;
1241   this->output[0] = info->options ? 0 : DSS_SCHMITT_OSC__AMP;
14031242}
14041243
14051244
r10048r10049
14221261
14231262DISCRETE_STEP(dss_sinewave)
14241263{
1425   DISCRETE_DECLARE_CONTEXT(dss_sinewave)
1426
14271264   /* Set the output */
14281265   if(DSS_SINEWAVE__ENABLE)
14291266   {
1430      node->output[0] = (DSS_SINEWAVE__AMPL / 2.0) * sin(context->phase);
1267      this->output[0] = (DSS_SINEWAVE__AMPL / 2.0) * sin(m_phase);
14311268      /* Add DC Bias component */
1432      node->output[0] = node->output[0] + DSS_SINEWAVE__BIAS;
1269      this->output[0] = this->output[0] + DSS_SINEWAVE__BIAS;
14331270   }
14341271   else
14351272   {
1436      node->output[0] = 0;
1273      this->output[0] = 0;
14371274   }
14381275
14391276   /* Work out the phase step based on phase/freq & sample rate */
r10048r10049
14431280   /*                    boils out to                           */
14441281   /*     phase step = (2Pi*output freq)/sample freq)           */
14451282   /* 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);
14471284}
14481285
14491286DISCRETE_RESET(dss_sinewave)
14501287{
1451   DISCRETE_DECLARE_CONTEXT(dss_sinewave)
1452
14531288   double start;
14541289
14551290   /* Establish starting phase, convert from degrees to radians */
14561291   start = (DSS_SINEWAVE__PHASE / 360.0) * (2.0 * M_PI);
14571292   /* Make sure its always mod 2Pi */
1458   context->phase = fmod(start, 2.0 * M_PI);
1293   m_phase = fmod(start, 2.0 * M_PI);
14591294   /* Step the output to make it correct */
1460   DISCRETE_STEP_CALL(dss_sinewave);
1295   this->step();
14611296}
14621297
14631298
r10048r10049
14821317
14831318DISCRETE_STEP(dss_squarewave)
14841319{
1485   DISCRETE_DECLARE_CONTEXT(dss_squarewave)
1486
14871320   /* 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);
14891322
14901323   /* Set the output */
14911324   if(DSS_SQUAREWAVE__ENABLE)
14921325   {
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;
14951328      else
1496         node->output[0] =- DSS_SQUAREWAVE__AMP / 2.0;
1329         this->output[0] =- DSS_SQUAREWAVE__AMP / 2.0;
14971330
14981331      /* Add DC Bias component */
1499      node->output[0] = node->output[0] + DSS_SQUAREWAVE__BIAS;
1332      this->output[0] = this->output[0] + DSS_SQUAREWAVE__BIAS;
15001333   }
15011334   else
15021335   {
1503      node->output[0] = 0;
1336      this->output[0] = 0;
15041337   }
15051338
15061339   /* Work out the phase step based on phase/freq & sample rate */
r10048r10049
15101343   /*                    boils out to                           */
15111344   /*     phase step = (2Pi*output freq)/sample freq)           */
15121345   /* 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);
15141347}
15151348
15161349DISCRETE_RESET(dss_squarewave)
15171350{
1518   DISCRETE_DECLARE_CONTEXT(dss_squarewave)
1519
15201351   double start;
15211352
15221353   /* Establish starting phase, convert from degrees to radians */
15231354   start = (DSS_SQUAREWAVE__PHASE / 360.0) * (2.0 * M_PI);
15241355   /* Make sure its always mod 2Pi */
1525   context->phase = fmod(start, 2.0 * M_PI);
1356   m_phase = fmod(start, 2.0 * M_PI);
15261357
15271358   /* Step the output */
1528   DISCRETE_STEP_CALL(dss_squarewave);
1359   this->step();
15291360}
15301361
15311362/************************************************************************
r10048r10049
15491380
15501381DISCRETE_STEP(dss_squarewfix)
15511382{
1552   DISCRETE_DECLARE_CONTEXT(dss_squarewfix)
1383   m_t_left -= m_sample_step;
15531384
1554   context->t_left -= context->sample_step;
1555
15561385   /* The enable input only curtails output, phase rotation still occurs */
1557   while (context->t_left <= 0)
1386   while (m_t_left <= 0)
15581387   {
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;
15611390   }
15621391
15631392   if(DSS_SQUAREWFIX__ENABLE)
15641393   {
15651394      /* Add gain and DC Bias component */
15661395
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;
15701399
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;
15721401   }
15731402   else
15741403   {
1575      node->output[0]=0;
1404      this->output[0]=0;
15761405   }
15771406}
15781407
15791408DISCRETE_RESET(dss_squarewfix)
15801409{
1581   DISCRETE_DECLARE_CONTEXT(dss_squarewfix)
1410   m_sample_step = 1.0 / this->sample_rate();
1411   m_flip_flop   = 1;
15821412
1583   context->sample_step = 1.0 / node->info->sample_rate;
1584   context->flip_flop   = 1;
1585
15861413   /* 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;
15941421
1595   context->t_left = -context->t_left;
1422   m_t_left = -m_t_left;
15961423
15971424   /* toggle output and work out intial time shift */
1598   while (context->t_left <= 0)
1425   while (m_t_left <= 0)
15991426   {
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;
16021429   }
16031430
16041431   /* Step the output */
1605   DISCRETE_STEP_CALL(dss_squarewfix);
1432   this->step();
16061433}
16071434
16081435
r10048r10049
16271454
16281455DISCRETE_STEP(dss_squarewave2)
16291456{
1630   DISCRETE_DECLARE_CONTEXT(dss_squarewave)
1631
16321457   double newphase;
16331458
16341459   if(DSS_SQUAREWAVE2__ENABLE)
16351460   {
16361461      /* 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);
16381463
16391464      /* Work out the phase step based on phase/freq & sample rate */
16401465      /* The enable input only curtails output, phase rotation     */
r10048r10049
16431468      /*     phase step = 2Pi/(output period/sample period)        */
16441469      /*                    boils out to                           */
16451470      /*     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()));
16471472      /* 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);
16491474
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;
16521477      else
1653         node->output[0] = -DSS_SQUAREWAVE2__AMP / 2.0;
1478         this->output[0] = -DSS_SQUAREWAVE2__AMP / 2.0;
16541479
16551480      /* Add DC Bias component */
1656      node->output[0] = node->output[0] + DSS_SQUAREWAVE2__BIAS;
1481      this->output[0] = this->output[0] + DSS_SQUAREWAVE2__BIAS;
16571482   }
16581483   else
16591484   {
1660      node->output[0] = 0;
1485      this->output[0] = 0;
16611486   }
16621487}
16631488
16641489DISCRETE_RESET(dss_squarewave2)
16651490{
1666   DISCRETE_DECLARE_CONTEXT(dss_squarewave)
1667
16681491   double start;
16691492
16701493   /* Establish starting phase, convert from degrees to radians */
r10048r10049
16741497   else
16751498      start = 0.0;
16761499   /* Make sure its always mod 2Pi */
1677   context->phase = fmod(start, 2.0 * M_PI);
1500   m_phase = fmod(start, 2.0 * M_PI);
16781501
16791502   /* Step the output */
1680   DISCRETE_STEP_CALL(dss_squarewave2);
1503   this->step();
16811504}
16821505
16831506/************************************************************************
r10048r10049
16981521#define DSS_INVERTER_OSC__C         DISCRETE_INPUT(4)
16991522#define DSS_INVERTER_OSC__R2      DISCRETE_INPUT(5)
17001523
1701INLINE double dss_inverter_tftab(node_description *node, double x)
1524
1525/* FIXME: Make the following two static members of dss_inverter_osc */
1526inline double DISCRETE_CLASS_FUNC(dss_inverter_osc, tftab)(double x)
17021527{
1703   DISCRETE_DECLARE_CONTEXT(dss_inverter_osc)
17041528   DISCRETE_DECLARE_INFO(discrete_inverter_osc_desc)
17051529
17061530   x = x / info->vB;
17071531   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));
17091533   else
17101534      return info->vB;
17111535}
17121536
1713INLINE double dss_inverter_tf(node_description *node, double x)
1537inline double DISCRETE_CLASS_FUNC(dss_inverter_osc, tf)(double x)
17141538{
1715   DISCRETE_DECLARE_CONTEXT(dss_inverter_osc)
17161539   DISCRETE_DECLARE_INFO(discrete_inverter_osc_desc)
17171540
17181541   if (x < 0.0)
17191542      return info->vB;
17201543   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)];
17221545   else
1723      return context->tf_tab[DSS_INV_TAB_SIZE - 1];
1546      return mc_tf_tab[DSS_INV_TAB_SIZE - 1];
17241547}
17251548
17261549DISCRETE_STEP(dss_inverter_osc)
17271550{
1728   DISCRETE_DECLARE_CONTEXT(dss_inverter_osc)
17291551   DISCRETE_DECLARE_INFO(discrete_inverter_osc_desc)
1730
17311552   double diff, vG1, vG2, vG3, vI;
17321553   double vMix, rMix;
17331554   int   clamped;
17341555
17351556   /* Get new state */
1736   vI = context->v_cap + context->v_g2_old;
1557   vI = mc_v_cap + mc_v_g2_old;
17371558   switch (info->options & DISC_OSC_INVERTER_TYPE_MASK)
17381559   {
17391560      case DISC_OSC_INVERTER_IS_TYPE1:
17401561      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);
17441565         break;
17451566      case DISC_OSC_INVERTER_IS_TYPE2:
17461567         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);
17491570         break;
17501571      case DISC_OSC_INVERTER_IS_TYPE4:
17511572         vI  = MIN(DSS_INVERTER_OSC__ENABLE, vI + 0.7);
17521573         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);
17551576         break;
17561577      case DISC_OSC_INVERTER_IS_TYPE5:
17571578         vI  = MAX(DSS_INVERTER_OSC__ENABLE, vI - 0.7);
17581579         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);
17611582         break;
17621583      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());
17641585   }
17651586
17661587   clamped = 0;
r10048r10049
17851606      case DISC_OSC_INVERTER_IS_TYPE3:
17861607         if (clamped)
17871608         {
1788            double ratio = context->rp / (context->rp + context->r1);
1609            double ratio = mc_rp / (mc_rp + mc_r1);
17891610            diff = vG3 * (ratio)
1790                 - (context->v_cap + vG2)
1611                 - (mc_v_cap + vG2)
17911612                 + vI * (1.0 - ratio);
1792            diff = diff - diff * context->wc;
1613            diff = diff - diff * mc_wc;
17931614         }
17941615         else
17951616         {
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;
17981619         }
17991620         break;
18001621      case DISC_OSC_INVERTER_IS_TYPE4:
18011622         /*  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);
18041625         if (vMix < (vI-vG2-0.7))
18051626         {
1806            rMix = 1.0 / rMix + 1.0 / context->rp;
1627            rMix = 1.0 / rMix + 1.0 / mc_rp;
18071628            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);
18101631         }
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));
18131634         break;
18141635      case DISC_OSC_INVERTER_IS_TYPE5:
18151636         /*  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);
18181639         if (vMix > (vI -vG2 + 0.7))
18191640         {
1820            rMix = 1.0 / rMix + 1.0 / context->rp;
1641            rMix = 1.0 / rMix + 1.0 / mc_rp;
18211642            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);
18241645         }
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));
18271648         break;
18281649      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());
18301651   }
1831   context->v_cap   += diff;
1832   context->v_g2_old = vG2;
1652   mc_v_cap   += diff;
1653   mc_v_g2_old = vG2;
18331654   if ((info->options & DISC_OSC_INVERTER_TYPE_MASK) == DISC_OSC_INVERTER_IS_TYPE3)
1834      node->output[0] = vG1;
1655      this->output[0] = vG1;
18351656   else
1836      node->output[0] = vG3;
1657      this->output[0] = vG3;
18371658   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);
18391660}
18401661
18411662DISCRETE_RESET(dss_inverter_osc)
18421663{
1843   DISCRETE_DECLARE_CONTEXT(dss_inverter_osc)
18441664   DISCRETE_DECLARE_INFO(discrete_inverter_osc_desc)
18451665
18461666   int i;
18471667
18481668   /* 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);
18611681
18621682   for (i = 0; i < DSS_INV_TAB_SIZE; i++)
18631683   {
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);
18651685   }
18661686}
18671687
r10048r10049
18841704
18851705DISCRETE_STEP(dss_trianglewave)
18861706{
1887   DISCRETE_DECLARE_CONTEXT(dss_trianglewave)
1888
18891707   if(DSS_TRIANGLEWAVE__ENABLE)
18901708   {
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 ;
18931711
18941712      /* Add DC Bias component */
1895      node->output[0] = node->output[0] + DSS_TRIANGLEWAVE__BIAS;
1713      this->output[0] = this->output[0] + DSS_TRIANGLEWAVE__BIAS;
18961714   }
18971715   else
18981716   {
1899      node->output[0] = 0;
1717      this->output[0] = 0;
19001718   }
19011719
19021720   /* Work out the phase step based on phase/freq & sample rate */
r10048r10049
19061724   /*                    boils out to                           */
19071725   /*     phase step = (2Pi*output freq)/sample freq)           */
19081726   /* 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);
19101728}
19111729
19121730DISCRETE_RESET(dss_trianglewave)
19131731{
1914   DISCRETE_DECLARE_CONTEXT(dss_trianglewave)
1915
19161732   double start;
19171733
19181734   /* Establish starting phase, convert from degrees to radians */
19191735   start = (DSS_TRIANGLEWAVE__PHASE / 360.0) * (2.0 * M_PI);
19201736   /* Make sure its always mod 2Pi */
1921   context->phase=fmod(start, 2.0 * M_PI);
1737   m_phase=fmod(start, 2.0 * M_PI);
19221738
19231739   /* Step to set the output */
1924   DISCRETE_STEP_CALL(dss_trianglewave);
1740   this->step();
19251741}
19261742
19271743
r10048r10049
19401756{
19411757   if(DSS_ADSR__ENABLE)
19421758   {
1943      node->output[0] = 0;
1759      this->output[0] = 0;
19441760   }
19451761   else
19461762   {
1947      node->output[0] = 0;
1763      this->output[0] = 0;
19481764   }
19491765}
19501766
19511767
19521768DISCRETE_RESET(dss_adsrenv)
19531769{
1954   DISCRETE_STEP_CALL(dss_adsrenv);
1770   this->step();
19551771}
src/emu/sound/disc_wav.h
r0r10049
1#pragma once
2
3#ifndef __DISC_WAV_H__
4#define __DISC_WAV_H__
5
6/***********************************************************************
7 *
8 *  MAME - Discrete sound system emulation library
9 *
10 *  Written by Keith Wilkins (mame@esplexo.co.uk)
11 *
12 *  (c) K.Wilkins 2000
13 *
14 *  Coding started in November 2000
15 *
16 *  Additions/bugfix February 2003 - D.Renaud, F.Palazzolo, K.Wilkins
17 *  Discrete parallel tasks 2009 - Couriersud
18 *  Discrete classes 2010       - Couriersud
19 *
20 ***********************************************************************/
21
22#include "discrete.h"
23
24DISCRETE_CLASS_STEP_RESETA(dss_counter, 1,
25   int      m_clock_type;
26   int      m_out_type;
27   int      m_is_7492;
28   int      m_last_clock;
29   UINT32   m_last_count;
30   UINT32   m_last;      /* Last clock state */
31   UINT32   m_min;
32   UINT32   m_max;
33   UINT32   m_diff;
34   double   m_t_left;      /* time unused during last sample in seconds */
35);
36
37DISCRETE_CLASS_STEP_RESETA(dss_lfsr_noise, 2,
38   unsigned int   m_lfsr_reg;
39   int            m_last;      /* Last clock state */
40   double         m_t_clock;   /* fixed counter clock in seconds */
41   double         m_t_left;      /* time unused during last sample in seconds */
42   double         m_sample_step;
43   double         m_t;
44   UINT8         m_reset_on_high;
45   UINT8         m_invert_output;
46   UINT8         m_out_is_f0;
47   UINT8         m_out_lfsr_reg;
48);
49
50DISCRETE_CLASS_STEP_RESETA(dss_noise, 2,
51   double m_phase;
52);
53
54DISCRETE_CLASS_STEP_RESETA(dss_note, 1,
55   int      m_clock_type;
56   int      m_out_type;
57   int      m_last;      /* Last clock state */
58   double   m_t_clock;   /* fixed counter clock in seconds */
59   double   m_t_left;      /* time unused during last sample in seconds */
60   int      m_max1;      /* Max 1 Count stored as int for easy use. */
61   int      m_max2;      /* Max 2 Count stored as int for easy use. */
62   int      m_count1;      /* current count1 */
63   int      m_count2;      /* current count2 */
64);
65
66DISCRETE_CLASS_STEP_RESETA(dss_sawtoothwave, 1,
67   double   m_phase;
68   int      m_type;
69);
70
71DISCRETE_CLASS_STEP_RESETA(dss_sinewave, 1,
72   double   m_phase;
73);
74
75DISCRETE_CLASS_STEP_RESETA(dss_squarewave, 1,
76   double   m_phase;
77   double   m_trigger;
78);
79DISCRETE_CLASS_STEP_RESETA(dss_squarewfix, 1,
80   int      m_flip_flop;
81   double   m_sample_step;
82   double   m_t_left;
83   double   m_t_off;
84   double   m_t_on;
85);
86
87DISCRETE_CLASS_STEP_RESETA(dss_squarewave2, 1,
88   double   m_phase;
89   double   m_trigger;
90);
91
92DISCRETE_CLASS_STEP_RESETA(dss_trianglewave, 1,
93   double   m_phase;
94);
95/* Component specific modules */
96
97#define DSS_INV_TAB_SIZE   500
98
99class DISCRETE_CLASS_NAME(dss_inverter_osc): public discrete_base_node, public discrete_step_interface
100{
101protected:
102   inline double tftab(double x);
103   inline double tf(double x);
104public:
105   DISCRETE_CLASS_CONSTRUCTOR(dss_inverter_osc, base)
106   void step(void);
107   void reset(void);
108private:
109   double   mc_v_cap;
110   double  mc_v_g2_old;
111   double   mc_w;
112   double  mc_wc;
113   double   mc_rp;
114   double  mc_r1;
115   double  mc_r2;
116   double  mc_c;
117   double   mc_tf_a;
118   double   mc_tf_b;
119   double  mc_tf_tab[DSS_INV_TAB_SIZE];
120};
121
122DISCRETE_CLASS_STEP_RESETA(dss_op_amp_osc, 1,
123   const double *m_r1;      /* pointers to resistor values */
124   const double *m_r2;
125   const double *m_r3;
126   const double *m_r4;
127   const double *m_r5;
128   const double *m_r6;
129   const double *m_r7;
130   const double *m_r8;
131   int         m_type;
132   UINT8      m_flip_flop;      /* flip/flop output state */
133   UINT8      m_flip_flop_xor;   /* flip_flop ^ flip_flop_xor, 0 = discharge, 1 = charge */
134   UINT8      m_output_type;
135   UINT8      m_has_enable;
136   double      m_v_out_high;
137   double      m_threshold_low;   /* falling threshold */
138   double      m_threshold_high;   /* rising threshold */
139   double      m_v_cap;         /* current capacitor voltage */
140   double      m_r_total;      /* all input resistors in parallel */
141   double      m_i_fixed;      /* fixed current at the input */
142   double      m_i_enable;      /* fixed current at the input if enabled */
143   double      m_temp1;         /* Multi purpose */
144   double      m_temp2;         /* Multi purpose */
145   double      m_temp3;         /* Multi purpose */
146   double      m_is_linear_charge;
147   double      m_charge_rc[2];
148   double      m_charge_exp[2];
149   double      m_charge_v[2];
150);
151
152DISCRETE_CLASS_STEP_RESETA(dss_schmitt_osc, 1,
153   double      m_ration_in;         /* ratio of total charging voltage that comes from the input */
154   double      m_ratio_feedback;   /* ratio of total charging voltage that comes from the feedback */
155   double      m_v_cap;            /* current capacitor voltage */
156   double      m_rc;               /* r*c */
157   double      m_exponent;
158   int         m_state;            /* state of the output */
159   int         m_enable_type;
160   UINT8      m_input_is_voltage;
161);
162
163/* Not yet implemented */
164DISCRETE_CLASS_STEP_RESETA(dss_adsrenv,  1,
165   double      m_phase;
166);
167
168
169#endif /* __DISC_WAV_H__ */
src/emu/sound/disc_flt.c
r10048r10049
2727 *
2828 ************************************************************************/
2929
30struct 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};
3730
38struct 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
46struct 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
70struct 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
80struct 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
90struct 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
99struct dst_rcdisc4_context
100{
101   int      type;
102   double   max_out;
103   double   vC1;
104   double   v[2];
105   double   exp[2];
106};
107
108struct dst_rcfilter_context
109{
110   double   vCap;
111   double   rc;
112   double   exponent;
113   UINT8   has_rc_nodes;
114};
115
116struct 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
127struct 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
14231/************************************************************************
14332 *
14433 * DST_CRFILTER - Usage of node_description values for CR filter
r10048r10049
15746
15847DISCRETE_STEP(dst_crfilter)
15948{
160   DISCRETE_DECLARE_CONTEXT(dst_rcfilter)
161
162   if (UNEXPECTED(context->has_rc_nodes))
49   if (UNEXPECTED(m_has_rc_nodes))
16350   {
16451      double rc = DST_CRFILTER__R * DST_CRFILTER__C;
165      if (rc != context->rc)
52      if (rc != m_rc)
16653      {
167         context->rc = rc;
168         context->exponent = RC_CHARGE_EXP(rc);
54         m_rc = rc;
55         m_exponent = RC_CHARGE_EXP_CLASS(rc);
16956      }
17057   }
17158
172   double v_out = DST_CRFILTER__IN - context->vCap;
59   double v_out = DST_CRFILTER__IN - m_vCap;
17360   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;
17663}
17764
17865DISCRETE_RESET(dst_crfilter)
17966{
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;
18772}
18873
18974
r10048r10049
20287#define DST_FILTER1__FREQ   DISCRETE_INPUT(2)
20388#define DST_FILTER1__TYPE   DISCRETE_INPUT(3)
20489
205static void calculate_filter1_coefficients(const discrete_info *disc_info, double fc, double type,
206                                 double *a1, double *b0, double *b1)
90static void calculate_filter1_coefficients(discrete_base_node *node, double fc, double type,
91                                 struct discrete_filter_coeff &coeff)
20792{
20893   double den, w, two_over_T;
20994
21095   /* calculate digital filter coefficents */
21196   /*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();
21499
215100   den = w + two_over_T;
216   *a1 = (w - two_over_T)/den;
101   coeff.a1 = (w - two_over_T)/den;
217102   if (type == DISC_FILTER_LOWPASS)
218103   {
219      *b0 = *b1 = w/den;
104      coeff.b0 = coeff.b1 = w/den;
220105   }
221106   else if (type == DISC_FILTER_HIGHPASS)
222107   {
223      *b0 = two_over_T/den;
224      *b1 = -(*b0);
108      coeff.b0 = two_over_T/den;
109      coeff.b1 = -(coeff.b0);
225110   }
226111   else
227112   {
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.");
229114   }
230115}
231116
232117DISCRETE_STEP(dst_filter1)
233118{
234   DISCRETE_DECLARE_CONTEXT(dst_filter1)
235
236119   double gain = 1.0;
237120
238121   if (DST_FILTER1__ENABLE == 0.0)
r10048r10049
240123      gain = 0.0;
241124   }
242125
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;
244127
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];
247130}
248131
249132DISCRETE_RESET(dst_filter1)
250133{
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;
255136}
256137
257138
r10048r10049
272153#define DST_FILTER2__DAMP   DISCRETE_INPUT(3)
273154#define DST_FILTER2__TYPE   DISCRETE_INPUT(4)
274155
275static void calculate_filter2_coefficients(const discrete_info *disc_info,
156static void calculate_filter2_coefficients(discrete_base_node *node,
276157                                         double fc, double d, double type,
277                                 double *a1, double *a2,
278                                 double *b0, double *b1, double *b2)
158                                         struct discrete_filter_coeff &coeff)
279159{
280160   double w;   /* cutoff freq, in radians/sec */
281161   double w_squared;
282162   double den;   /* temp variable */
283   double two_over_T = 2 * disc_info->sample_rate;
163   double two_over_T = 2 * node->sample_rate();
284164   double two_over_T_squared = two_over_T * two_over_T;
285165
286166   /* calculate digital filter coefficents */
287167   /*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 */
289169   w_squared = w * w;
290170
291171   den = two_over_T_squared + d*w*two_over_T + w_squared;
292172
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;
295175
296176   if (type == DISC_FILTER_LOWPASS)
297177   {
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);
300180   }
301181   else if (type == DISC_FILTER_BANDPASS)
302182   {
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);
306186   }
307187   else if (type == DISC_FILTER_HIGHPASS)
308188   {
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);
311191   }
312192   else
313193   {
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.");
315195   }
316196}
317197
318198DISCRETE_STEP(dst_filter2)
319199{
320   DISCRETE_DECLARE_CONTEXT(dst_filter2)
321
322200   double gain = 1.0;
323201
324202   if (DST_FILTER2__ENABLE == 0.0)
r10048r10049
326204      gain = 0.0;
327205   }
328206
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;
331209
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];
336214}
337215
338216DISCRETE_RESET(dst_filter2)
339217{
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;
346221}
347222
348223
r10048r10049
366241
367242DISCRETE_STEP(dst_op_amp_filt)
368243{
369   DISCRETE_DECLARE_CONTEXT(dst_op_amp_filt)
370244   DISCRETE_DECLARE_INFO(discrete_op_amp_filt_info)
371245
372246   double i, v = 0;
373247
374248   if (DST_OP_AMP_FILT__ENABLE)
375249   {
376      if (context->is_norton)
250      if (m_is_norton)
377251      {
378252         v = DST_OP_AMP_FILT__INP1 - OP_AMP_NORTON_VBE;
379253         if (v < 0) v = 0;
r10048r10049
381255      else
382256      {
383257         /* Millman the input voltages. */
384         i  = context->iFixed;
385         switch (context->type)
258         i  = m_iFixed;
259         switch (m_type)
386260         {
387261            case DISC_OP_AMP_FILTER_IS_LOW_PASS_1_A:
388262               i += (DST_OP_AMP_FILT__INP1 - DST_OP_AMP_FILT__INP2) / info->r1;
389263               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;
391265               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;
393267               break;
394268            default:
395               i += (DST_OP_AMP_FILT__INP1 - context->vRef) / info->r1;
269               i += (DST_OP_AMP_FILT__INP1 - m_vRef) / info->r1;
396270               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;
398272               break;
399273         }
400         v = i * context->rTotal;
274         v = i * m_rTotal;
401275      }
402276
403      switch (context->type)
277      switch (m_type)
404278      {
405279         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;
408282            break;
409283
410284         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;
413287            break;
414288
415289         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;
418292            break;
419293
420294         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;
425299            break;
426300
427301         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;
435309            break;
436310
437311         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;
442316            break;
443317
444318         case DISC_OP_AMP_FILTER_IS_BAND_PASS_1M:
445319         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;
452326            break;
453327      }
454328
455329      /* Clip the output to the voltage rails.
456330         * This way we get the original distortion in all it's glory.
457331         */
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;
461335   }
462336   else
463      node->output[0] = 0;
337      this->output[0] = 0;
464338
465339}
466340
467341DISCRETE_RESET(dst_op_amp_filt)
468342{
469   DISCRETE_DECLARE_CONTEXT(dst_op_amp_filt)
470343   DISCRETE_DECLARE_INFO(discrete_op_amp_filt_info)
471344
472345   /* 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;
475348
476   if (context->is_norton)
349   if (m_is_norton)
477350   {
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;
482355
483356      /* 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;
485358
486359      /* 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;
489362   }
490363   else
491364   {
492      context->vRef = info->vRef;
365      m_vRef = info->vRef;
493366      /* 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;
496369
497370      /* 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;
502375
503      context->iFixed = 0;
376      m_iFixed = 0;
504377
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;
507380   }
508381
509   switch (context->type)
382   switch (m_type)
510383   {
511384      case DISC_OP_AMP_FILTER_IS_LOW_PASS_1:
512385      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;
515388         break;
516389      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;
519392         break;
520393      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);
523396         break;
524397      case DISC_OP_AMP_FILTER_IS_BAND_PASS_1M | DISC_OP_AMP_IS_NORTON:
525398         if (info->r2 == 0)
526            context->rTotal = info->r1;
399            m_rTotal = info->r1;
527400         else
528            context->rTotal = RES_2_PARALLEL(info->r1, info->r2);
401            m_rTotal = RES_2_PARALLEL(info->r1, info->r2);
529402      case DISC_OP_AMP_FILTER_IS_BAND_PASS_1M:
530403      {
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);
534407
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;
541412
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;
544415         else
545            context->vRef = info->vRef;
416            m_vRef = info->vRef;
546417
547418         break;
548419      }
549420      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);
553424         break;
554425      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);
556427         break;
557428   }
558429
559430   /* 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;
564435
565   node->output[0] = info->vRef;
436   this->output[0] = info->vRef;
566437}
567438
568439
r10048r10049
580451
581452DISCRETE_STEP( dst_rc_circuit_1 )
582453{
583   DISCRETE_DECLARE_CONTEXT(dst_rc_circuit_1)
584
585454   if (DST_RC_CIRCUIT_1__IN0 == 0)
586455      if (DST_RC_CIRCUIT_1__IN1 == 0)
587456         /* cap is floating and does not change charge */
588457         /* output is pulled to ground */
589         node->output[0] = 0;
458         this->output[0] = 0;
590459      else
591460      {
592461         /* 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;
595464      }
596465   else
597466      if (DST_RC_CIRCUIT_1__IN1 == 0)
598467      {
599468         /* 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;
601470         /* output is pulled to ground */
602         node->output[0] = 0;
471         this->output[0] = 0;
603472      }
604473      else
605474      {
606475         /* 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;
609478      }
610479}
611480
612481DISCRETE_RESET( dst_rc_circuit_1 )
613482{
614   DISCRETE_DECLARE_CONTEXT(dst_rc_circuit_1)
615
616483   /* 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;
620487
621488   /* precalculate charging exponents */
622489   /* 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);
624491   /* 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);
626493   /* 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);
628495
629496   /* starts at 0 until cap starts charging */
630   node->output[0] = 0;
497   this->output[0] = 0;
631498}
632499
633500/************************************************************************
r10048r10049
648515
649516DISCRETE_STEP(dst_rcdisc)
650517{
651   DISCRETE_DECLARE_CONTEXT(dst_rcdisc)
652
653   switch (context->state)
518   switch (m_state)
654519   {
655520      case 0:     /* waiting for trigger  */
656521         if(DST_RCDISC__ENABLE)
657522         {
658            context->state = 1;
659            context->t = 0;
523            m_state = 1;
524            m_t = 0;
660525         }
661         node->output[0] = 0;
526         this->output[0] = 0;
662527         break;
663528
664529      case 1:
665530         if (DST_RCDISC__ENABLE)
666531         {
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();
669534         } else
670535         {
671            context->state = 0;
536            m_state = 0;
672537         }
673538   }
674539}
675540
676541DISCRETE_RESET(dst_rcdisc)
677542{
678   DISCRETE_DECLARE_CONTEXT(dst_rcdisc)
543   this->output[0] = 0;
679544
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;
685548}
686549
687550
r10048r10049
707570
708571DISCRETE_STEP(dst_rcdisc2)
709572{
710   DISCRETE_DECLARE_CONTEXT(dst_rcdisc)
711
712573   double diff;
713574
714575   /* Works differently to other as we are always on, no enable */
715576   /* exponential based in difference between input/output   */
716577
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;
720581}
721582
722583DISCRETE_RESET(dst_rcdisc2)
723584{
724   DISCRETE_DECLARE_CONTEXT(dst_rcdisc)
585   this->output[0] = 0;
725586
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);
732591}
733592
734593/************************************************************************
r10048r10049
753612
754613DISCRETE_STEP(dst_rcdisc3)
755614{
756   DISCRETE_DECLARE_CONTEXT(dst_rcdisc)
757
758615   double diff;
759616
760617   /* Exponential based in difference between input/output   */
761618
762619   if(DST_RCDISC3__ENABLE)
763620   {
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)
766623      {
767624         if (diff > 0)
768625         {
769            diff = diff * context->exponent0;
626            diff = diff * m_exponent0;
770627         }
771         else if (diff < -context->v_diode)
628         else if (diff < -m_v_diode)
772629         {
773            diff = diff * context->exponent1;
630            diff = diff * m_exponent1;
774631         }
775632         else
776633         {
777            diff = diff * context->exponent0;
634            diff = diff * m_exponent0;
778635         }
779636      }
780637      else
781638      {
782639         if (diff < 0)
783640         {
784            diff = diff * context->exponent0;
641            diff = diff * m_exponent0;
785642         }
786         else if (diff > -context->v_diode)
643         else if (diff > -m_v_diode)
787644         {
788            diff = diff * context->exponent1;
645            diff = diff * m_exponent1;
789646         }
790647         else
791648         {
792            diff = diff * context->exponent0;
649            diff = diff * m_exponent0;
793650         }
794651      }
795      node->output[0] += diff;
652      this->output[0] += diff;
796653   }
797654   else
798655   {
799      node->output[0] = 0;
656      this->output[0] = 0;
800657   }
801658}
802659
803660DISCRETE_RESET(dst_rcdisc3)
804661{
805   DISCRETE_DECLARE_CONTEXT(dst_rcdisc)
662   this->output[0] = 0;
806663
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);
814669}
815670
816671
r10048r10049
838693
839694DISCRETE_STEP(dst_rcdisc4)
840695{
841   DISCRETE_DECLARE_CONTEXT(dst_rcdisc4)
842
843696   int inp1 = (DST_RCDISC4__IN == 0) ? 0 : 1;
844697
845698   if (DST_RCDISC4__ENABLE == 0)
846699   {
847      node->output[0] = 0;
700      this->output[0] = 0;
848701      return;
849702   }
850703
851   switch (context->type)
704   switch (m_type)
852705   {
853706      case 1:
854707      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;
857710         break;
858711   }
859712
860713   /* 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;
863716}
864717
865718DISCRETE_RESET( dst_rcdisc4)
866719{
867   DISCRETE_DECLARE_CONTEXT(dst_rcdisc4)
868
869720   double   v, i, r, rT;
870721
871   context->type = 0;
722   m_type = 0;
872723   /* 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))
874725   {
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());
876727      return;
877728   }
878729   if (DST_RCDISC4__VP < 3)
879730   {
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());
881732      return;
882733   }
883734   if (DST_RCDISC4__TYPE < 1 || DST_RCDISC4__TYPE > 3)
884735   {
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());
886737      return;
887738   }
888739
889   context->vC1 = 0;
740   m_vC1 = 0;
890741   /* store type as integer */
891   context->type = (int)DST_RCDISC4__TYPE;
742   m_type = (int)DST_RCDISC4__TYPE;
892743   /* 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;
894745
895   switch (context->type)
746   switch (m_type)
896747   {
897748      case 1:
898749         /* We will simulate this as a voltage divider with 2 states depending
r10048r10049
904755         r  = RES_2_PARALLEL(DST_RCDISC4__R1, DST_RCDISC4__R3);
905756         rT = DST_RCDISC4__R2 + r;
906757         i  = v / rT;
907         context->v[1] = i * r + .5;
758         m_v[1] = i * r + .5;
908759         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);
910761
911762         /* When the input is 0, R1 is out of circuit. */
912763         rT = DST_RCDISC4__R2 + DST_RCDISC4__R3;
913764         i  = v / rT;
914         context->v[0] = i * DST_RCDISC4__R3 + .5;
765         m_v[0] = i * DST_RCDISC4__R3 + .5;
915766         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);
917768         break;
918769
919770      case 3:
r10048r10049
922773             * resistance, so we will just use .5k in series with R1.
923774             */
924775         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);
926777         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);
928779
929780         /* 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);
932783         break;
933784   }
934785}
r10048r10049
950801
951802DISCRETE_STEP( dst_rcdisc5)
952803{
953   DISCRETE_DECLARE_CONTEXT(dst_rcdisc)
954
955804   double diff,u;
956805
957806   /* Exponential based in difference between input/output   */
r10048r10049
960809   if( u < 0)
961810      u = 0;
962811
963   diff = u - context->v_cap;
812   diff = u - m_v_cap;
964813
965814   if(DST_RCDISC5__ENABLE)
966815   {
967816      if(diff < 0)
968         diff = diff * context->exponent0;
817         diff = diff * m_exponent0;
969818
970      context->v_cap += diff;
971      node->output[0] = context->v_cap;
819      m_v_cap += diff;
820      this->output[0] = m_v_cap;
972821   }
973822   else
974823   {
975824      if(diff > 0)
976         context->v_cap = u;
825         m_v_cap = u;
977826
978      node->output[0] = 0;
827      this->output[0] = 0;
979828   }
980829}
981830
982831DISCRETE_RESET( dst_rcdisc5)
983832{
984   DISCRETE_DECLARE_CONTEXT(dst_rcdisc)
833   this->output[0] = 0;
985834
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);
992839}
993840
994841
r10048r10049
1018865
1019866DISCRETE_STEP(dst_rcdisc_mod)
1020867{
1021   DISCRETE_DECLARE_CONTEXT(dst_rcdisc_mod)
1022
1023868   double   diff, v_cap, u, vD;
1024869   int      mod_state, mod1_state, mod2_state;
1025870
1026871   /* Exponential based in difference between input/output   */
1027   v_cap = context->v_cap;
872   v_cap = m_v_cap;
1028873
1029874   mod1_state = DST_RCDISC_MOD__IN1 > 0.5;
1030875   mod2_state = DST_RCDISC_MOD__IN2 > 0.6;
r10048r10049
1033878   u = mod1_state ? 0 : DST_RCDISC_MOD__VP;
1034879   /* Clamp */
1035880   diff = u - v_cap;
1036   vD = diff * context->vd_gain[mod_state];
881   vD = diff * m_vd_gain[mod_state];
1037882   if (vD < -0.6)
1038883   {
1039884      diff  = u + 0.6 - v_cap;
1040      diff -= diff * context->exp_low[mod1_state];
885      diff -= diff * m_exp_low[mod1_state];
1041886      v_cap += diff;
1042      node->output[0] = mod2_state ? 0 : -0.6;
887      this->output[0] = mod2_state ? 0 : -0.6;
1043888   }
1044889   else
1045890   {
1046      diff  -= diff * context->exp_high[mod_state];
891      diff  -= diff * m_exp_high[mod_state];
1047892      v_cap += diff;
1048893      /* 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];
1050895   }
1051   context->v_cap = v_cap;
896   m_v_cap = v_cap;
1052897}
1053898
1054899DISCRETE_RESET(dst_rcdisc_mod)
1055900{
1056   DISCRETE_DECLARE_CONTEXT(dst_rcdisc_mod)
1057
1058901   double   rc[2], rc2[2];
1059902
1060903   /* pre-calculate fixed values */
1061904   /* DST_RCDISC_MOD__IN1 <= 0.5 */
1062905   rc[0] = DST_RCDISC_MOD__R1 + DST_RCDISC_MOD__R2;
1063906   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);
1066909   /* DST_RCDISC_MOD__IN1 > 0.5 */
1067910   rc[1] = DST_RCDISC_MOD__R2;
1068911   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);
1071914   /* DST_RCDISC_MOD__IN2 <= 0.6 */
1072915   rc2[0] = DST_RCDISC_MOD__R4;
1073916   /* DST_RCDISC_MOD__IN2 > 0.6 */
1074917   rc2[1] = RES_2_PARALLEL(DST_RCDISC_MOD__R3, DST_RCDISC_MOD__R4);
1075918   /* 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]);
1078921   /* 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]);
1081924   /* 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]);
1084927   /* 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]);
1087930
1088   context->v_cap  = 0;
1089   node->output[0] = 0;
931   m_v_cap  = 0;
932   this->output[0] = 0;
1090933}
1091934
1092935/************************************************************************
r10048r10049
1107950
1108951DISCRETE_STEP(dst_rcfilter)
1109952{
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
1113956   {
1114      double rc = DST_RCFILTER__R * DST_RCFILTER__C;
1115      if (rc != context->rc)
957      if (UNEXPECTED(m_has_rc_nodes))
1116958      {
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         }
1119965      }
1120   }
1121966
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      /************************************************************************/
1125970
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   }
1128974}
1129975
1130DISCRETE_STEP(dst_rcfilter_fast)
1131{
1132   DISCRETE_DECLARE_CONTEXT(dst_rcfilter)
1133976
1134   node->output[0] += ((DST_RCFILTER__VIN - node->output[0]) * context->exponent);
1135}
1136
1137977DISCRETE_RESET(dst_rcfilter)
1138978{
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;
1148989}
1149990
1150991/************************************************************************
r10048r10049
11771018// FIXME: This needs optimization !
11781019DISCRETE_STEP(dst_rcfilter_sw)
11791020{
1180   DISCRETE_DECLARE_CONTEXT(dst_rcfilter_sw)
1181
11821021   int i;
11831022   int bits = (int)DST_RCFILTER_SW__SWITCH;
11841023   double us = 0;
r10048r10049
11891028      switch (bits)
11901029      {
11911030      case 0:
1192         node->output[0] = vIn;
1031         this->output[0] = vIn;
11931032         break;
11941033      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;
11971036         break;
11981037      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;
12011040         break;
12021041      default:
12031042         for (i = 0; i < 4; i++)
12041043         {
12051044            if (( bits & (1 << i)) != 0)
1206               us += context->vCap[i];
1045               us += m_vCap[i];
12071046         }
1208         node->output[0] = context->f1[bits] * vIn + context->f2[bits]  * us;
1047         this->output[0] = m_f1[bits] * vIn + m_f2[bits]  * us;
12091048         for (i = 0; i < 4; i++)
12101049         {
12111050            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];
12131052         }
12141053      }
12151054   }
12161055   else
12171056   {
1218      node->output[0] = 0;
1057      this->output[0] = 0;
12191058   }
12201059}
12211060
12221061DISCRETE_RESET(dst_rcfilter_sw)
12231062{
1224   DISCRETE_DECLARE_CONTEXT(dst_rcfilter_sw)
1225
12261063   int i, bits;
12271064
12281065   for (i = 0; i < 4; i++)
12291066   {
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));
12321069   }
12331070
12341071   for (bits=0; bits < 15; bits++)
r10048r10049
12401077         if (( bits & (1 << i)) != 0)
12411078            rs += DST_RCFILTER_SW__R;
12421079      }
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);
12451082   }
12461083
12471084
12481085   /* 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);
12521089
1253   node->output[0] = 0;
1090   this->output[0] = 0;
12541091}
12551092
12561093
r10048r10049
12931130
12941131DISCRETE_STEP( dst_rcintegrate)
12951132{
1296   DISCRETE_DECLARE_CONTEXT(dst_rcintegrate)
1297
12981133   double diff, u, iQ, iQc, iC, RG, vE;
12991134   double vP;
13001135
13011136   u  = DST_RCINTEGRATE__IN1;
13021137   vP = DST_RCINTEGRATE__VP;
13031138
1304   if ( u - 0.7  < context->vCap * context->gain_r1_r2)
1139   if ( u - 0.7  < m_vCap * m_gain_r1_r2)
13051140   {
13061141      /* 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;
13111146      iQ = 0;
1312      vE = context->vCap * context->gain_r1_r2;
1147      vE = m_vCap * m_gain_r1_r2;
13131148      RG = vE / iC;
13141149   }
13151150   else
13161151   {
13171152      /* 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);
13251160   }
13261161
13271162
r10048r10049
13291164   if (u > 0.7 + vE)
13301165      vE = u - 0.7;
13311166   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);
13331168
13341169   /* Avoid oscillations
13351170     * The method tends to largely overshoot - no wonder without
13361171     * iterative solution approximation
13371172     */
13381173
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);
13411176
1342   switch (context->type)
1177   switch (m_type)
13431178   {
13441179      case DISC_RC_INTEGRATE_TYPE1:
1345         node->output[0] = context->vCap;
1180         this->output[0] = m_vCap;
13461181         break;
13471182      case DISC_RC_INTEGRATE_TYPE2:
1348         node->output[0] = vE;
1183         this->output[0] = vE;
13491184         break;
13501185      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);
13521187         break;
13531188   }
13541189}
1190
13551191DISCRETE_RESET(dst_rcintegrate)
13561192{
1357   DISCRETE_DECLARE_CONTEXT(dst_rcintegrate)
1358
13591193   double r;
1360   double dt = node->info->sample_time;
1194   double dt = this->sample_time();
13611195
1362   context->type = DST_RCINTEGRATE__TYPE;
1196   m_type = DST_RCINTEGRATE__TYPE;
13631197
1364   context->vCap = 0;
1365   context->vCE  = 0;
1198   m_vCap = 0;
1199   m_vCE  = 0;
13661200
13671201   /* 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);
13691203
13701204   r = DST_RCINTEGRATE__R1 / DST_RCINTEGRATE__R2 * DST_RCINTEGRATE__R3 + DST_RCINTEGRATE__R1 + DST_RCINTEGRATE__R3;
13711205
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;
13791213
1380   node->output[0] = 0;
1214   this->output[0] = 0;
13811215}
13821216
13831217/************************************************************************
r10048r10049
13981232
13991233DISCRETE_STEP(dst_sallen_key)
14001234{
1401   DISCRETE_DECLARE_CONTEXT(dst_filter2)
1402
14031235   double gain = 1.0;
14041236
14051237   if (DST_SALLEN_KEY__ENABLE == 0.0)
r10048r10049
14071239      gain = 0.0;
14081240   }
14091241
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;
14121244
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];
14171249}
14181250
14191251DISCRETE_RESET(dst_sallen_key)
14201252{
1421   DISCRETE_DECLARE_CONTEXT(dst_filter2)
14221253   DISCRETE_DECLARE_INFO(discrete_op_amp_filt_info)
14231254
14241255   double freq, q;
r10048r10049
14331264         fatalerror("Unknown sallen key filter type");
14341265   }
14351266
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;
14401269}
14411270
14421271
r10048r10049
14581287#define DST_RCFILTERN__R      DISCRETE_INPUT(2)
14591288#define DST_RCFILTERN__C      DISCRETE_INPUT(3)
14601289
1290#if 0
14611291DISCRETE_RESET(dst_rcfilterN)
14621292{
14631293#if 0
r10048r10049
14661296/* !!!!!!!!!!!!!! CAN'T CHEAT LIKE THIS !!!!!!!!!!!!!!!! */
14671297/* Put this stuff in a context */
14681298
1469   node->input[2] = f;
1470   node->input[3] = DISC_FILTER_LOWPASS;
1299   this->input[2] = f;
1300   this->input[3] = DISC_FILTER_LOWPASS;
14711301
14721302   /* Use first order filter */
14731303   dst_filter1_reset(node);
14741304#endif
14751305}
1306#endif
14761307
1477
14781308/************************************************************************
14791309 *
14801310 * DST_RCDISCN -   Usage of node_description values for RC discharge
r10048r10049
14991329/* !!!!!!!!!!!!!! CAN'T CHEAT LIKE THIS !!!!!!!!!!!!!!!! */
15001330/* Put this stuff in a context */
15011331
1502   node->input[2] = f;
1503   node->input[3] = DISC_FILTER_LOWPASS;
1332   this->input[2] = f;
1333   this->input[3] = DISC_FILTER_LOWPASS;
15041334
15051335   /* Use first order filter */
15061336   dst_filter1_reset(node);
r10048r10049
15091339
15101340DISCRETE_STEP(dst_rcdiscN)
15111341{
1512   DISCRETE_DECLARE_CONTEXT(dst_filter1)
1513
15141342   double gain = 1.0;
15151343
15161344   if (DST_RCDISCN__ENABLE == 0.0)
r10048r10049
15201348
15211349   /* A rise in the input signal results in an instant charge, */
15221350   /* 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;
15251353   else
1526      node->output[0] = -context->a1*context->y1;
1354      this->output[0] = -m_a1*m_y1;
15271355
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];
15301358}
15311359
15321360
r10048r10049
15431371 * input[5]    - Capacitor Value (initialization only)
15441372 *
15451373 ************************************************************************/
1546#define DST_RCDISC2N__ENABLE      DISCRETE_INPUT(0)
1374#define DST_RCDISC2N__ENABLE   DISCRETE_INPUT(0)
15471375#define DST_RCDISC2N__IN0      DISCRETE_INPUT(1)
15481376#define DST_RCDISC2N__R0      DISCRETE_INPUT(2)
15491377#define DST_RCDISC2N__IN1      DISCRETE_INPUT(3)
15501378#define DST_RCDISC2N__R1      DISCRETE_INPUT(4)
15511379#define DST_RCDISC2N__C         DISCRETE_INPUT(5)
15521380
1553struct 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};
15601381
15611382DISCRETE_STEP(dst_rcdisc2N)
15621383{
1563   DISCRETE_DECLARE_CONTEXT(dst_rcdisc2)
1564
15651384   double input = ((DST_RCDISC2N__ENABLE == 0) ? DST_RCDISC2N__IN0 : DST_RCDISC2N__IN1);
15661385
15671386   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;
15691388   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;
15711390
1572   context->x1 = input;
1573   context->y1 = node->output[0];
1391   m_x1 = input;
1392   m_y1 = this->output[0];
15741393}
15751394
15761395DISCRETE_RESET(dst_rcdisc2N)
15771396{
1578   DISCRETE_DECLARE_CONTEXT(dst_rcdisc2)
15791397   double f1,f2;
15801398
15811399   f1 = 1.0 / (2 * M_PI * DST_RCDISC2N__R0 * DST_RCDISC2N__C);
15821400   f2 = 1.0 / (2 * M_PI * DST_RCDISC2N__R1 * DST_RCDISC2N__C);
15831401
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);
15861404
15871405   /* Initialize the object */
1588   node->output[0] = 0;
1406   this->output[0] = 0;
15891407}
src/emu/sound/disc_flt.h
r0r10049
1#pragma once
2
3#ifndef __DISC_FLTH__
4#define __DISC_FLT_H__
5
6/***********************************************************************
7 *
8 *  MAME - Discrete sound system emulation library
9 *
10 *  Written by Keith Wilkins (mame@esplexo.co.uk)
11 *
12 *  (c) K.Wilkins 2000
13 *
14 *  Coding started in November 2000
15 *
16 *  Additions/bugfix February 2003 - D.Renaud, F.Palazzolo, K.Wilkins
17 *  Discrete parallel tasks 2009 - Couriersud
18 *  Discrete classes 2010       - Couriersud
19 *
20 ***********************************************************************/
21
22#include "discrete.h"
23
24struct discrete_filter_coeff
25{
26   double x1, x2;      /* x[k-1], x[k-2], previous 2 input values */
27   double y1, y2;      /* y[k-1], y[k-2], previous 2 output values */
28   double a1, a2;      /* digital filter coefficients, denominator */
29   double b0, b1, b2;   /* digital filter coefficients, numerator */
30};
31
32
33DISCRETE_CLASS_STEP_RESETA(dst_filter1, 1,
34   /* uses x1, y1, a1, b0, b1 */
35   struct discrete_filter_coeff m_fc;
36);
37
38DISCRETE_CLASS_STEP_RESETA(dst_filter2, 1,
39   struct discrete_filter_coeff m_fc;
40);
41
42DISCRETE_CLASS_STEP_RESETA(dst_sallen_key, 1,
43   struct discrete_filter_coeff m_fc;
44);
45
46DISCRETE_CLASS_STEP_RESETA(dst_crfilter, 1,
47   double   m_vCap;
48   double   m_rc;
49   double   m_exponent;
50   UINT8   m_has_rc_nodes;
51   UINT8   m_is_fast;
52);
53
54DISCRETE_CLASS_STEP_RESETA(dst_op_amp_filt, 1,
55   int      m_type;      /* What kind of filter */
56   int      m_is_norton;   /* 1 = Norton op-amps */
57   double   m_vRef;
58   double   m_vP;
59   double   m_vN;
60   double   m_rTotal;      /* All input resistance in parallel. */
61   double   m_iFixed;      /* Current supplied by r3 & r4 if used. */
62   double   m_exponentC1;
63   double   m_exponentC2;
64   double   m_exponentC3;
65   double   m_rRatio;      /* divide ratio of resistance network */
66   double   m_vC1;      /* Charge on C1 */
67   double   m_vC1b;      /* Charge on C1, part of C1 charge if needed */
68   double   m_vC2;      /* Charge on C2 */
69   double   m_vC3;      /* Charge on C2 */
70   double   m_gain;      /* Gain of the filter */
71   struct discrete_filter_coeff m_fc;
72);
73
74DISCRETE_CLASS_STEP_RESETA(dst_rc_circuit_1, 1,
75   double    m_v_cap;
76   double    m_v_charge_1_2;
77   double   m_v_drop;
78   double    m_exp_1;
79   double    m_exp_1_2;
80   double    m_exp_2;
81);
82
83DISCRETE_CLASS_STEP_RESETA(dst_rcdisc, 1,
84   int    m_state;
85   double   m_t;           /* time */
86   double    m_exponent0;
87   double    m_exponent1;
88   double    m_v_cap;      /* rcdisc5 */
89   double    m_v_diode;      /* rcdisc3 */
90);
91
92DISCRETE_CLASS_STEP_RESETA(dst_rcdisc2, 1,
93   int    m_state;
94   double   m_t;           /* time */
95   double    m_exponent0;
96   double    m_exponent1;
97   double    m_v_cap;      /* rcdisc5 */
98   double    m_v_diode;      /* rcdisc3 */
99);
100
101DISCRETE_CLASS_STEP_RESETA(dst_rcdisc3, 1,
102   int    m_state;
103   double   m_t;           /* time */
104   double    m_exponent0;
105   double    m_exponent1;
106   double    m_v_cap;      /* rcdisc5 */
107   double    m_v_diode;      /* rcdisc3 */
108);
109
110DISCRETE_CLASS_STEP_RESETA(dst_rcdisc4, 1,
111   int      m_type;
112   double   m_max_out;
113   double   m_vC1;
114   double   m_v[2];
115   double   m_exp[2];
116);
117
118DISCRETE_CLASS_STEP_RESETA(dst_rcdisc5, 1,
119   int    m_state;
120   double    m_t;           /* time */
121   double    m_exponent0;
122   double    m_exponent1;
123   double    m_v_cap;      /* rcdisc5 */
124   double    m_v_diode;      /* rcdisc3 */
125);
126
127DISCRETE_CLASS_STEP_RESETA(dst_rcintegrate, 1,
128   int      m_type;
129   double   m_gain_r1_r2;
130   double   m_f;            /* r2,r3 gain */
131   double   m_vCap;
132   double   m_vCE;
133   double   m_exponent0;
134   double   m_exponent1;
135   double   m_exp_exponent0;
136   double   m_exp_exponent1;
137   double   m_c_exp0;
138   double   m_c_exp1;
139);
140
141DISCRETE_CLASS_STEP_RESETA(dst_rcdisc_mod, 1,
142   double   m_v_cap;
143   double   m_exp_low[2];
144   double   m_exp_high[4];
145   double   m_gain[2];
146   double   m_vd_gain[4];
147);
148
149DISCRETE_CLASS_STEP_RESETA(dst_rcfilter, 1,
150   double   m_vCap;
151   double   m_rc;
152   double   m_exponent;
153   UINT8   m_has_rc_nodes;
154   UINT8   m_is_fast;
155);
156
157DISCRETE_CLASS_STEP_RESETA(dst_rcfilter_sw, 1,
158   double   m_vCap[4];
159   double   m_exp[4];
160   double  m_exp0;   /* fast case bit 0 */
161   double  m_exp1;   /* fast case bit 1 */
162   double  m_factor; /* fast case */
163   double  m_f1[16];
164   double  m_f2[16];
165);
166
167DISCRETE_CLASS_STEP_RESETA(dst_rcdiscN, 1,
168   double m_x1;      /* x[k-1], previous input value */
169   double m_y1;      /* y[k-1], previous output value */
170   double m_a1;      /* digital filter coefficients, denominator */
171   double m_b[2];   /* digital filter coefficients, numerator */
172);
173
174DISCRETE_CLASS_STEP_RESETA(dst_rcdisc2N, 1,
175   struct discrete_filter_coeff m_fc0;
176   struct discrete_filter_coeff m_fc1;
177   double m_x1;
178   double m_y1;
179);
180
181
182#endif /* __DISC_FLT_H__ */
src/emu/ui.c
r10048r10049
307307               ui_set_handler(handler_messagebox_ok, 0);
308308               if (machine->gamedrv->flags & (GAME_WRONG_COLORS | GAME_IMPERFECT_COLORS | GAME_REQUIRES_ARTWORK | GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NO_SOUND))
309309                  messagebox_backcolor = UI_YELLOW_COLOR;
310               if (machine->gamedrv->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION))
310               if (machine->gamedrv->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_MECHANICAL))
311311                  messagebox_backcolor = UI_RED_COLOR;
312312            }
313313            break;
r10048r10049
898898{
899899#define WARNING_FLAGS (   GAME_NOT_WORKING | \
900900                  GAME_UNEMULATED_PROTECTION | \
901                  GAME_MECHANICAL | \
901902                  GAME_WRONG_COLORS | \
902903                  GAME_IMPERFECT_COLORS | \
903904                  GAME_REQUIRES_ARTWORK | \
r10048r10049
905906                  GAME_IMPERFECT_SOUND |  \
906907                  GAME_IMPERFECT_GRAPHICS | \
907908                  GAME_NO_COCKTAIL)
909
908910   int i;
909911
910912   string.reset();
r10048r10049
946948      if (machine->gamedrv->flags & GAME_REQUIRES_ARTWORK)
947949         string.cat("The game requires external artwork files\n");
948950
949      /* if there's a NOT WORKING or UNEMULATED PROTECTION warning, make it stronger */
950      if (machine->gamedrv->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION))
951      /* if there's a NOT WORKING, UNEMULATED PROTECTION or GAME MECHANICAL warning, make it stronger */
952      if (machine->gamedrv->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_MECHANICAL))
951953      {
952954         const game_driver *maindrv;
953955         const game_driver *clone_of;
r10048r10049
957959         if (machine->gamedrv->flags & GAME_UNEMULATED_PROTECTION)
958960            string.cat("The game has protection which isn't fully emulated.\n");
959961         if (machine->gamedrv->flags & GAME_NOT_WORKING)
960            string.cat("THIS " CAPGAMENOUN " DOESN'T WORK. The emulation for this game is not yet complete. "
961                            "There is nothing you can do to fix this problem except wait for the developers to improve the emulation.\n");
962            string.cat("\nTHIS " CAPGAMENOUN " DOESN'T WORK. The emulation for this game is not yet complete. "
963                "There is nothing you can do to fix this problem except wait for the developers to improve the emulation.\n");
964         if (machine->gamedrv->flags & GAME_MECHANICAL)
965            string.cat("\nCertain elements of this " GAMENOUN " cannot be emulated as it requires actual physical interaction or consists of mechanical devices. "
966                "It is not possible to fully play this " GAMENOUN ".\n");
962967
963968         /* find the parent of this driver */
964969         clone_of = driver_get_clone(machine->gamedrv);
r10048r10049
971976         foundworking = FALSE;
972977         for (i = 0; drivers[i] != NULL; i++)
973978            if (drivers[i] == maindrv || driver_get_clone(drivers[i]) == maindrv)
974               if ((drivers[i]->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION)) == 0)
979               if ((drivers[i]->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_MECHANICAL)) == 0)
975980               {
976981                  /* this one works, add a header and display the name of the clone */
977982                  if (!foundworking)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team