// Automatically generated C++ file on Thu Oct 19 12:36:41 2023 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD bustest_x1.cpp kernel32.lib #include #include #include #include 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; } void display(const char *fmt, ...) { // for diagnostic print statements msleep(30); fflush(stdout); va_list args = {0}; va_start(args, fmt); vprintf(fmt, args); va_end(args); fflush(stdout); msleep(30); } void bzero(void *ptr, unsigned int count) { unsigned char *first = (unsigned char *)ptr; unsigned char *last = first + count; while (first < last) *first++ = '\0'; } // #undef pin names lest they collide with names in any header file(s) you might // include. #undef In #undef Bus_0_ #undef Bus_1_ #undef Bus_2_ struct sBUSTEST_X1 { // declare the structure here bool lastClk; union { int val; struct { bool b0 : 1; bool b1 : 1; bool b2 : 1; }; } ctr; }; extern "C" __declspec(dllexport) void bustest_x1( struct sBUSTEST_X1 **opaque, double t, union uData *data) { double In = data[0].d; // input bool &B0 = data[1].b; // output bool &B1 = data[2].b; // output bool &B2 = data[3].b; // output if (!*opaque) { *opaque = (struct sBUSTEST_X1 *)malloc(sizeof(struct sBUSTEST_X1)); bzero(*opaque, sizeof(struct sBUSTEST_X1)); } struct sBUSTEST_X1 *inst = *opaque; // Implement module evaluation code here: if (In && !inst->lastClk) { inst->ctr.val = ++inst->ctr.val % 0x7; B0 = inst->ctr.b0; B1 = inst->ctr.b1; B2 = inst->ctr.b2; } inst->lastClk = In; } extern "C" __declspec(dllexport) void Destroy(struct sBUSTEST_X1 *inst) { free(inst); }