+ ret->Side[0].BackPtr = ret;
+ ret->Side[1].BackPtr = ret;
+
+ return (udi_channel_t)&ret->Side[0].BackPtr;
+}
+
+udi_channel_t UDI_CreateChannel_Linked(udi_channel_t orig, udi_ubit8_t spawn_idx)
+{
+ tUDI_Channel *ch = *(tUDI_Channel**)orig;
+ ASSERT(ch);
+ ASSERTC(spawn_idx, <, MAX_SPAWN_IDX);
+ // TODO: mutex
+ if( ch->SpawnBinds[spawn_idx] ) {
+ tUDI_Channel *ret = ch->SpawnBinds[spawn_idx];
+ ch->SpawnBinds[spawn_idx] = NULL;
+ // TODO: mutex
+ return (udi_channel_t)&ret->Side[1].BackPtr;
+ }
+ udi_channel_t ret = UDI_CreateChannel_Blank( ch->MetaLang );
+ ch->SpawnBinds[spawn_idx] = *(tUDI_Channel**)ret;
+ // TODO: Mutex
+ return ret;
+}
+
+struct sUDI_ChannelSide *UDI_int_ChannelGetSide(udi_channel_t channel, bool other_side)
+{
+ tUDI_Channel *ch = *(tUDI_Channel**)channel;
+ if(!ch) return NULL;
+
+ int side_idx = (channel == (udi_channel_t)&ch->Side[0].BackPtr) ? 0 : 1;
+ if( other_side )
+ side_idx = 1 - side_idx;
+
+ return &ch->Side[side_idx];
+}
+
+int UDI_BindChannel_Raw(udi_channel_t channel, bool other_side, tUDI_DriverInstance *inst, udi_index_t region_idx, udi_index_t meta_ops_num, void *context, const void *ops)
+{
+ struct sUDI_ChannelSide *side = UDI_int_ChannelGetSide(channel, other_side);
+ side->Instance = inst;
+ side->RegionIdx = region_idx;
+ side->Context = context;
+ side->MetaOpsNum = meta_ops_num;
+ side->Ops = ops;
+ return 0;
+}
+
+int UDI_BindChannel(udi_channel_t channel, bool other_side, tUDI_DriverInstance *inst, udi_index_t ops_idx, udi_index_t region, void *context, bool is_child_bind, udi_ubit32_t child_ID)
+{
+ tUDI_Channel *ch = *(tUDI_Channel**)channel;
+
+ tUDI_DriverRegion *rgn = inst->Regions[region];
+
+ udi_ops_init_t *ops = UDI_int_GetOps(inst, ops_idx);
+ if( !ops ) {
+ Log_Warning("UDI", "Ops ID invalid for '%s' (%i)", inst->Module, ops_idx);
+ return 1;
+ }
+
+ tUDI_MetaLang *ops_ml = UDI_int_GetMetaLang(inst->Module, ops->meta_idx);
+ if( ops_ml != ch->MetaLang ) {
+ Log_Warning("UDI", "Attempt by %s to bind with mismatched channel '%s' op '%s' channel",
+ inst->Module, ops_ml->Name, ch->MetaLang->Name);
+ return 3;
+ }
+
+ if( context ) {
+ // Use provided context pointer
+ LOG("context = provided %p", context);
+ }
+ else if( ops->chan_context_size )