InputPort[] input_port_allocate(InputPortTiny[] src) { int dst; int sidx = 0; InputPort[] _base; uint total; total = input_port_count(src); _base = new InputPort[total]; dst = 0; while (src[sidx].type != (int)ports.inptports.IPT_END) { int type = (int)(src[sidx].type & ~ports.IPF_MASK); int ext; int src_end; InputCode seq_default; if (type > (int)ports.inptports.IPT_ANALOG_START && type < (int)ports.inptports.IPT_ANALOG_END) src_end = sidx + 2; else src_end = sidx + 1; switch (type) { case (int)ports.inptports.IPT_END: case (int)ports.inptports.IPT_PORT: case (int)ports.inptports.IPT_DIPSWITCH_NAME: case (int)ports.inptports.IPT_DIPSWITCH_SETTING: seq_default = (int)InputCodes.CODE_NONE; break; default: seq_default = (int)InputCodes.CODE_DEFAULT; break; } ext = src_end; while (sidx < src_end) { _base[dst] = new InputPort(); _base[dst].type = src[sidx].type; _base[dst].mask = src[sidx].mask; _base[dst].default_value = src[sidx].default_value; _base[dst].name = src[sidx].name; if (src[ext].type == (int)ports.inptports.IPT_EXTENSION) { InputCode or1 = IP_GET_CODE_OR1(src[ext]); InputCode or2 = IP_GET_CODE_OR2(src[ext]); if (or1 < (int)InputCodes.__code_max) { if (or2 < (int)InputCodes.__code_max) seq_set_3(_base[dst].seq, or1, (int)InputCodes.CODE_OR, or2); else seq_set_1(_base[dst].seq, or1); } else { if (or1 == (int)InputCodes.CODE_NONE) seq_set_1(_base[dst].seq, or2); else seq_set_1(_base[dst].seq, or1); } ++ext; } else { seq_set_1(_base[dst].seq, seq_default); } ++sidx; ++dst; } sidx = ext; } _base[dst] = new InputPort(); _base[dst].type = (int)ports.inptports.IPT_END; return _base; }
InputCode IP_GET_CODE_OR1(InputPortTiny port) { return port.mask; }
InputCode IP_GET_CODE_OR2(InputPortTiny port) { return port.default_value; }
uint input_port_count(InputPortTiny[] src) { uint total; int sidx = 0; total = 0; while (src[sidx].type != (int)ports.inptports.IPT_END) { int type = (int)(src[sidx].type & ~ports.IPF_MASK); if (type > (int)ports.inptports.IPT_ANALOG_START && type < (int)ports.inptports.IPT_ANALOG_END) total += 2; else if (type != (int)ports.inptports.IPT_EXTENSION) ++total; ++sidx; } ++total; /* for IPT_END */ return total; }