// Automatically generated C++ file on Wed Oct 23 09:39:23 2024 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD sw0008_x1.cpp kernel32.lib 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 In #undef OutA #undef OutB #define OUT_A_HI 2 #define OUT_B_HI 2 #define INPUT_LOGIC_THRESHOLD 0.5 int lastclk = 0, flag = 0; extern "C" __declspec(dllexport) void sw0008_x1(void **opaque, double t, union uData *data) { double In = data[0].d; // input int &OutA = data[1].i; // output int &OutB = data[2].i; // output // int lastclk = 0, flag = 0; // Implement module evaluation code here: if (In <= INPUT_LOGIC_THRESHOLD && lastclk == 1) { OutA = 0; OutB = 0; lastclk = 0; } else if (In > INPUT_LOGIC_THRESHOLD && lastclk == 0) { lastclk = 1; if (flag) { OutA = OUT_A_HI; flag = 1; } else { OutB = OUT_B_HI; flag = 0; } } }