// Automatically generated C++ file on Wed Apr 8 14:54:52 2026 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD -o ksk_main.cpp kernel32.lib #include #include "ksk_math.cpp" 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 DllMain() must exist and return 1 for a process to load the .DLL // See https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain for more information. int __stdcall DllMain(void *module, unsigned int reason, void *reserved) { return 1; } // #undef pin names lest they collide with names in any header file(s) you might include. #undef theta #undef duty #undef out1 #undef out2 struct sKSK_MAIN { // declare the structure here }; extern "C" __declspec(dllexport) void ksk_main(struct sKSK_MAIN **opaque, double t, union uData *data) { double theta = data[0].d; // input double duty = data[1].d; // input double fsw = data[2].d; // input parameter double &out1 = data[3].d; // output double &out2 = data[4].d; // output if(!*opaque) { *opaque = (struct sKSK_MAIN *) malloc(sizeof(struct sKSK_MAIN)); bzero(*opaque, sizeof(struct sKSK_MAIN)); } struct sKSK_MAIN *inst = *opaque; // Implement module evaluation code here: out1 = normalize_angle_0_2pi(theta); out2 = comparator(duty,triangle_wave(t,fsw)); } extern "C" __declspec(dllexport) double MaxExtStepSize(struct sKSK_MAIN *inst, double t) { return 1e308; // implement a good choice of max timestep size that depends on struct sKSK_MAIN } extern "C" __declspec(dllexport) void Trunc(struct sKSK_MAIN *inst, double t, union uData *data, double *timestep) { // limit the timestep to a tolerance if the circuit causes a change in struct sKSK_MAIN const double ttol = 1e-9; // 1ns default tolerance if(*timestep > ttol) { struct sKSK_MAIN tmp = *inst; ksk_main(&(&tmp), t, data); // if(tmp != *inst) // implement a meaningful way to detect if the state has changed // *timestep = ttol; } } extern "C" __declspec(dllexport) void Destroy(struct sKSK_MAIN *inst) { free(inst); }