//
// Merger
//
// Merger, like splitter, is a hybrid type of device. It behaves
// just like a node, except that it must be clocked to update
// its value before any devices which call upon its value use it.
// See the documentation on Splitter for a description of using
// this sort of device.
//


#import "Merger.h"


@implementation Merger


- initLowBits:(int)lbits			// Number of bits of low-order input.
	low:lnode				// Node containing low-order part.
	highBits:(int)hbits			// Number of bits of higher-order input.
	high:hnode				// Node containing high-order part.
{
    if(lbits < 1) {
        fprintf(stderr, "Merger: Attempt to create a Merger with less than one low-order bit!\n");
	exit(-1);
    }
    
    lowbits = lbits;
    
    if(hbits < 1) {
        fprintf(stderr, "Merger: Attempt to create a Merger with less than one high-order bit!\n");
	exit(-1);
    }
    
    highbits = hbits;
    
    [super initNumBits:(lowbits + highbits)];	// Merger size is sum of merged components.
    
    INITDEVTYPE("Merger");
    
    TESTNODE("LOW", lnode, lowbits);
    TESTNODE("HIGH", hnode, highbits);
    
    LOW = lnode;
    HIGH = hnode;
    
    return self;
}


- cycle
{
    bit		*lowarray = [LOW getBits];
    bit		*higharray = [HIGH getBits];
    int i;
    
    for(i = 0; i < lowbits; i++) {
        data[i] = lowarray[i];
    }
    
    for(i = 0; i < highbits; i++) {
        data[lowbits + i] = higharray[i];
    }
    
    return self;
}


@end


//
// End of file.
//