The Relogix translation

Note: This is a 100% automatic translation, with no human intervention or cleaning-up of the code. Relogix has automatically chosen the function prototype, has detected the use of structures and pointers, has chosen the variable names itself, and has placed the assembler comments in the translated source allowing for the re-arrangement of the code flow. Note that parameters passed to other subroutines either in registers (eg oscall_seteve) or on the stack (eg oscall_blkmove) are correctly handled. In a real translation project, the translation could be further improved by providing user-defined header files to tune the names and types of variables, and the function prototypes.


/*
*************************************************************************
* echo_reply                                                            *
*************************************************************************
*
*
* 	ECHO_REPLY - Echo Reply received		
*
* 	Entry :	A0 -> ICMP Echo Reply message
* 		D1 =  Length of complete datagram + header (bytes)
* 		D2 =  Internet address of sender
*
* Parameters:
*
*    long length_copy_verify                                  [Originally in d1; In]
*    long d2                                                  [Originally in d2; In]
*    struct icm *icm_ptr                                      [Originally in a0; In]
*/
static void echo_reply (long length_copy_verify, long d2, struct icm *icm_ptr)
{
    long save;                                             /* [Originally in d4] */
    short number_entries;                                  /* [Originally in d3] */
    struct ping *next_table_entry;                         /* [Originally in a3] */
    long packet_length1;                                   /* [Originally in d0] */
    char *user_ping_packet1;                               /* [Originally in a2] */
    char *ping_reply1;                                     /* [Originally in a1] */
    short packet_length2;                                  /* [Originally in d0] */
    char *user_ping_packet2;                               /* [Originally in a2] */
    char *ping_reply2;                                     /* [Originally in a1] */
    Boolean is_equal;                                      /* [Originally condition EQ] */
    long upto_buffer_size;                                 /* [Originally in d0] */
    Boolean EXEC_NO_CHECK;
    Boolean EXEC_WAKEUP_TASK;

    save = oscall_millmid ();                              /* Get time reply was received 
                                                              Save it in D4 */
    icmp_ping_replies++;
    next_table_entry = (struct ping *) &ping_table [-sizeof (struct ping)];

    for (number_entries = 0; number_entries < PINGTAB_ENTS; number_entries++) {
        next_table_entry++;                                /* A3 -> next table entry  */
        EXEC_NO_CHECK = False;
        EXEC_WAKEUP_TASK = True;

        /* Echo reply satisfies this request ?
           Check TID of waiting task */
        if (d2 == next_table_entry->ping_tpa && next_table_entry->ping_tid != 0) {
            next_table_entry->ping_tim = save;             /* Plug time packet was received  */
            length_copy_verify -= offsetof (struct icm, icm_iph);
                                                           /* Calculate length of packet data  */

            /* Correct length ? */
            if (length_copy_verify != next_table_entry->ping_len) {
                /* Room for whole packet ? */
                if ((unsigned long) length_copy_verify > *(unsigned long *) &next_table_entry->ping_len) {
                    upto_buffer_size = next_table_entry->ping_len;
                                                           /* No, only copy upto buffer size  */
                    next_table_entry->ping_len = length_copy_verify;
                                                           /* Plug bad packet length  */
                    length_copy_verify = upto_buffer_size; /* D1 = length to copy/verify  */
                }
                next_table_entry->ping_err |= PE_LEN;      /* Flag task that length was bad  */
            }

            /* Check the reply packet, or maybe
               copy the data ? */
            if (next_table_entry->ping_flg & (PNG_CHK + PNG_COPY)) {
                /* Verify it then ? */
                if ((next_table_entry->ping_flg & PNG_CHK) == 0)
                    EXEC_NO_CHECK = True;
                else {
                    packet_length2 = (short) length_copy_verify - 1;
                                                           /* D0 = packet length 
                                                              Adjust for DBRA */
                    user_ping_packet2 = next_table_entry->ping_buf;
                                                           /* A2 -> user's ping packet  */
                    ping_reply2 = icm_ptr->icm_iph;        /* A1 -> ping reply  */
                    do {
                        is_equal = *user_ping_packet2++ == *ping_reply2++;
                                                           /* Packets the same ?  */
                        if (!is_equal)
                            break;
                    } while (packet_length2-- != 0);

                    if (!is_equal) {
                        next_table_entry->ping_err |= PE_CKS;
                                                           /* No !  */
                        EXEC_NO_CHECK = True;
                    }
                }
            }
        } else
            EXEC_WAKEUP_TASK = False;

        if (EXEC_NO_CHECK) {
            /* Copy it ? */
            if (next_table_entry->ping_flg & PNG_COPY) {
                packet_length1 = length_copy_verify;       /* D0 = packet length  */
                user_ping_packet1 = next_table_entry->ping_buf;
                                                           /* A2 -> user's ping packet  */
                ping_reply1 = icm_ptr->icm_iph;            /* A1 -> ping reply  */
                oscall_psched ();

                /* Woken up with timeout since we
                   started processing reply ? */
                if (next_table_entry->ping_tid != 0)
                    oscall_blkmove (packet_length1, ping_reply1, user_ping_packet1);
                                                           /* Copy the received packet  */
                oscall_asched ();
            }
        }

        if (EXEC_WAKEUP_TASK)
            oscall_seteve (next_table_entry->ping_tid, JE_DEV);
                                                           /* Get TID of waiting task 
                                                              Wake task up */
    }

}