// CD4014B: 8-stage static shift register, synchronous parallel or serial
// input, serial output.
//
// Ports in pin order, named as in the datasheet.  The power pins, VSS (8)
// and VDD (16), are left out.  Synthesizable.
//
// Everything happens on the rising edge of CLOCK.  With PARALLEL/SERIAL
// CONTROL = 1 the edge loads P1-P8 into the eight stages; with 0 it shifts:
// SERIAL IN goes into stage 1 and every stage takes the bit of the stage
// before it.  Q8, the output of the last stage, is the serial output; Q6 and
// Q7 are there too.  The chip has no reset.

module cd4014
(
    input  logic p8,               // Pin 1
    output logic q6,               // Pin 2
    output logic q8,               // Pin 3
    input  logic p4,               // Pin 4
    input  logic p3,               // Pin 5
    input  logic p2,               // Pin 6
    input  logic p1,               // Pin 7
                                   // Pin 8:  VSS
    input  logic parallel_serial,  // Pin 9:  1 = load, 0 = shift
    input  logic clock,            // Pin 10
    input  logic serial_in,        // Pin 11
    output logic q7,               // Pin 12
    input  logic p5,               // Pin 13
    input  logic p6,               // Pin 14
    input  logic p7                // Pin 15
                                   // Pin 16: VDD
);

    logic [8:1] stage;

    always_ff @ (posedge clock)
        if (parallel_serial)
            stage <= { p8, p7, p6, p5, p4, p3, p2, p1 };
        else
            stage <= { stage [7:1], serial_in };

    assign q6 = stage [6];
    assign q7 = stage [7];
    assign q8 = stage [8];

endmodule
