// Automatically generated C++ file on Mon May 18 07:21:37 2026 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD -o classd.cpp kernel32.lib #include #include // Uncomment if any of these are desired // extern "C" __declspec(dllexport) void (*Display)(const char *format, ...) = 0; // works like printf() // extern "C" __declspec(dllexport) void (*EXIT)(const char *format, ...) = 0; // print message like printf() but exit(0) afterward // extern "C" __declspec(dllexport) const double *DegreesC = 0; // pointer to current circuit temperature // extern "C" __declspec(dllexport) const int *StepNumber = 0; // pointer to current step number // extern "C" __declspec(dllexport) const int *NumberSteps = 0; // pointer to estimated number of steps // extern "C" __declspec(dllexport) const char* const *InstanceName = 0; // pointer to address of instance name // extern "C" __declspec(dllexport) const char *QUX = 0; // path to QUX.exe // extern "C" __declspec(dllexport) const bool *ForKeeps = 0; // pointer to whether being evaluated non-hypothetically // extern "C" __declspec(dllexport) const bool *HoldICs = 0; // pointer to whether instance initial conditions are being held // extern "C" __declspec(dllexport) const void *GUI_HWND = 0; // pointer to Window handle of QUX.exe // extern "C" __declspec(dllexport) const double *CKTtime = 0; // extern "C" __declspec(dllexport) const double *CKTdelta = 0; // extern "C" __declspec(dllexport) const int *IntegrationOrder = 0; // extern "C" __declspec(dllexport) const char *InstallDirectory = 0; // extern "C" __declspec(dllexport) double (*EngAtof)(const char **string) = 0; // extern "C" __declspec(dllexport) const char *(*BinaryFormat)(unsigned int data) = 0; // BinaryFormat(0x1C) returns "0b00011100" // extern "C" __declspec(dllexport) const char *(*EngFormat )(double x, const char *units, int numDgts) = 0; // EngFormat(1e-6, "s", 6) returns "1µs" // extern "C" __declspec(dllexport) int (*DFFT)(struct sComplex *u, bool inv, unsigned int N, double scale) = 0; // Discrete Fast Fourier Transform // extern "C" __declspec(dllexport) void (*bzero)(void *ptr, unsigned int count) = 0; union uData { bool b; char c; unsigned char uc; short s; unsigned short us; int i; unsigned int ui; float f; double d; long long int i64; unsigned long long int ui64; char *str; unsigned char *bytes; }; int __stdcall DllMain(void *module, unsigned int reason, void *reserved) { return 1; } struct sCLASSD { bool PHI1, PHI2, direction; double maxstep; }; double compress(double V) { if(V < -1.) return -1. + tanh(V + 1.); if(V > 1.) return 1. + tanh(V - 1.); return V; } extern "C" __declspec(dllexport) void classd(struct sCLASSD **opaque, double t, union uData *data) { const double IN = compress(data[0].d); // input, compressed const double CLK = data[1].d; // input parameter double &PHI1 = data[2].d; // output double &PHI2 = data[3].d; // output if(!*opaque) { *opaque = (struct sCLASSD *) calloc(1, sizeof(struct sCLASSD)); (*opaque)->maxstep = .05 / double(CLK); // so it doesn't accidentally step over a CLK period } struct sCLASSD *inst = *opaque; const double Tstart = CLK * t - floor(t * CLK); const double triangle = 8. * ((inst->direction = Tstart < .5) ? Tstart : 1. - Tstart) - 2.; // triangle wave from -2V to +2V PHI1 = inst->PHI1 = triangle > IN; PHI2 = inst->PHI2 = triangle > -IN; } extern "C" __declspec(dllexport) double MaxExtStepSize(struct sCLASSD *inst, double t) { return inst->maxstep; } extern "C" __declspec(dllexport) void Trunc(struct sCLASSD *inst, double t, union uData *data, double *timestep) { const double ttol = 1e-11; if(*timestep > ttol) { struct sCLASSD tmp = *inst; classd(&(&tmp), t, data); if((tmp.PHI1 != inst->PHI1) || (tmp.PHI2 != inst->PHI2) || (tmp.direction != inst->direction)) *timestep = ttol; } } extern "C" __declspec(dllexport) void Destroy(struct sCLASSD *inst) { free(inst); }