Event struct via registers
    Vitaliy Fadeev 
    vital.fadeev at gmail.com
       
    Sat Aug 10 08:04:10 UTC 2024
    
    
  
On Saturday, 10 August 2024 at 07:46:46 UTC, Vitaliy Fadeev wrote:
> ## Trouble 1
>
> Pass the structure through registers ?
>
> ## Trouble 2
>
> Wrap the registries in a structure ?
> How to implement on D?
I try:
```
import std.stdio;
void
main() {
	Event_1 event_1;
	event (event_1);
	Event_2 event_2;
	event (event_2);
}
struct
Event_1 {
     ushort type  = 1;
     ushort code  = 2;
     uint   value = 3;
}
struct
Event_2 {
     ushort type  = 1;
     ushort code  = 2;
     uint   value = 3;
     float  x = 4.0;
     float  y = 5.0;
}
void
event (EVENT) (/* R this, */ EVENT e) {
     enum REG_SIZE = (void*).sizeof; // Bytes
     pragma (msg, EVENT, " : ", EVENT.sizeof);
     pragma (msg, "REG_SIZE: ", REG_SIZE);
     static if (EVENT.sizeof == 0) {
         //
     }
     else
     static if (EVENT.sizeof <= REG_SIZE) {  //  64 bit
         _event (/* this, */
             * cast (REG*) &e,
             //* cast (REG*) cast (ubyte*) &e,
             //cast (REG) *(
             //  (cast (ubyte*) &e)[0..EVENT.sizeof].ptr
             //),
             0,
             0);
     }
     else
     static if (EVENT.sizeof <= 2*REG_SIZE) {  // 128 bit
         _event (/* this, */
             cast (REG) *(
                 (cast (ubyte*) &e)[0..REG_SIZE].ptr
             ),
             cast (REG) *(
                 (cast (ubyte*) &e)[REG_SIZE..EVENT.sizeof].ptr
             ),
             0);
     }
     else
         static assert (0, "Event sizeof too much");
}
alias REG = ulong;
void
_event (/* REG this, */ REG type_code_value, REG r3, REG r4) {
     //switch (type_code_value.type) {
     //    case Event.Type.GUI: gui.event (type_code_value, r3, 
r4); break;
     //    default:
     //}
     writeln ("type_code_value: ", type_code_value);
     writeln ("r3: ", r3);
     writeln ("r4: ", r4);
     Event_1 event_1;
     event_1 = * cast (Event_1*) &type_code_value;
     writeln ("  event_1 :", event_1);
     if (r3 != 0) {
         writeln ("  event_2 :", r3);
     }
}
```
But i have 0 in r3.
I need help converting the structure `Event_2` into 2 `ulong` 
parameters `type_code_value`, `r3`.
    
    
More information about the Digitalmars-d-learn
mailing list