*copyc OSD$DEFAULT_PRAGMATS

MODULE iim$block_management_utilities;

?? PUSH (LISTEXT := ON) ??
*copyc IIT$CONNECTION_DESCRIPTION
*copyc MLD$MEMORY_LINK_DECLARATIONS
*copyc OSV$170_OS_TYPE
?? POP ??


?? TITLE := 'PROCEDURE iip$build_super_msg_skeleton', EJECT ??

  PROCEDURE [XDCL, #GATE] iip$build_super_msg_skeleton (posm:
    ^iit$output_supervisory_message;
    osm_type: iit$supervisory_message_type;
    osm_length: iit$text_length);

{  PURPOSE:
{    The purpose of this procedure is to build a skeleton output supervisory
{    message containing the standard output supervisory message information.
{

    posm^.header.block_type := iic$supervisory_block;
    posm^.header.address := iic$supervisory_connection_num;
    posm^.header.character_type := iic$60_bit_characters;
    posm^.message_type := osm_type;
    posm^.header.text_length := osm_length;

  PROCEND iip$build_super_msg_skeleton;

?? TITLE := 'PROCEDURE iip$build_data_msg_skeleton', EJECT ??

  PROCEDURE [XDCL, #GATE] iip$build_data_msg_skeleton (podm: ^iit$output_data_message;
    odm_length: iit$text_length);

{  PURPOSE:
{    The purpose of this procedure is to build a skeleton output data message
{    containing the stanard output data message information.
{
    VAR
      status: ost$status;

    podm^.header.block_type := iic$continued_block;

{  Application character type 2 will be used with NOS dual state systems.
{  Application character type 3 will be used with NOS/BE dual state systems.

    IF osv$170_os_type = osc$ot7_dual_state_nos_be THEN
      podm^.header.character_type := iic$8_of_12_bit_characters;
    ELSE
      podm^.header.character_type := iic$8_bit_characters;
    IFEND;

    podm^.header.suppress_echo := FALSE;
    podm^.header.auto_input := FALSE;
    podm^.header.text_length := odm_length;

  PROCEND iip$build_data_msg_skeleton;

?? TITLE := 'PROCEDURE iip$convert_downline_block', EJECT ??

  PROCEDURE [XDCL, #GATE] iip$convert_downline_block (pib: ^cell;
    pob: ^cell;
    input_block_length: mlt$message_length;
    VAR output_block_length: mlt$message_length);

{  PURPOSE:
{    The purpose of this procedure is to convert a C180 Downline Block
{    to a C170 Downline Block which can be sent to the NAM.
{  DESIGN:
{    The conversion is accomplished by moving 4 bits at a time from the
{    C180 Downline Block to the C170 Downline Block while inserting the
{    upper 4 bits of each C170 word.
{

    VAR
      pins,
      pons: ^iit$nibble_string,
      i,
      j: integer;

    pins := pib;
    pons := pob;

    IF osv$170_os_type = osc$ot7_dual_state_nos_be THEN
{   Copy header word into the C170 downline block.}

      FOR i := 1 TO 15 DO
        pons^ [i] := pins^ [i];
      FOREND;

{   Move 4 bits at a time from C180 block to C170 block inserting 4 zero
{   bits at the front of each word and each 8-of-12 character.

      i := 16;
      j := 16;
      WHILE i <= 2 * input_block_length DO
        IF j MOD 16 = 0 THEN
          pons^ [j] := 0;
          j := j + 1;
        IFEND;
        pons^ [j] := 0;
        pons^ [j + 1] := pins^ [i];
        pons^ [j + 2] := pins^ [i + 1];
        j := j + 3;
        i := i + 2;
      WHILEND
    ELSE

      j := 1;

      FOR i := 1 TO 2 * input_block_length DO
        IF j MOD 16 = 0 THEN
          pons^ [j] := 0;
          j := j + 1;
        IFEND;
        pons^ [j] := pins^ [i];
        j := j + 1;
      FOREND;
    IFEND;

    output_block_length := (j + 1) DIV 2;

  PROCEND iip$convert_downline_block;

MODEND iim$block_management_utilities;
