anchor.diff:      endrule
   
       rule init_pattern;
  -        patternRegs[1] <= 32'h00FF0000; // blue
  -        patternRegs[2] <= 32'h0000FF00; // green
  -        patternRegs[3] <= 32'h000000FF; // red
  +        patternRegs[1] <= 24'h00FF0000; // blue
  +        patternRegs[2] <= 24'h0000FF00; // green
  +        patternRegs[3] <= 24'h000000FF; // red
           //patternRegs[1] <= 32'h80ff80ff; // yuv422 white
           //patternRegs[2] <= 32'h2c961596; // yuv422 green
           //patternRegs[3] <= 32'hff1d6b1d; // yuv422 red
       endrule
  -    let vsync = (lineCount < vsyncWidth) ? 1 : 0;
  -    let hsync = (pixelCount < hsyncWidth) ? 1 : 0;
  -    let dataEnable = (pixelCount >= dePixelCountMinimum && pixelCount < dePixelCountMaximum && isActiveLine);
   
       rule data;
  +        bramOutStageFifo.enq(0);
  +        lineBuffer.readAddr(dataCount);
  +    endrule
  +
  +    rule inc_counters;
  +        bramOutStageFifo.deq();
  +        let vsync = (lineCount < vsyncWidth) ? 1 : 0;
  +        let hsync = (pixelCount < hsyncWidth) ? 1 : 0;
  +        let isActiveLine = (lineCount >= deLineCountMinimum && lineCount < deLineCountMaximum);
  +        let dataEnable = (pixelCount >= dePixelCountMinimum && pixelCount < dePixelCountMaximum && isActiveLine);
           if (hsync == 1)
               dataCount <= 0;
           else if (dataEnable)
               dataCount <= dataCount + 1;
  -        bramOutStageFifo.enq(Rgb888Stage {}); // vsync: vsync, hsync: hsync, de: pack(dataEnable)});
  -        lineBuffer.readAddr(dataCount);
  -    endrule
  -
  -    rule inc_counters;
  +
  +        if (isActiveLine && pixelCount == 0)
  +            begin
  +            //$display("hsync pulse sent");
  +            hsyncPulse.send();
  +            end
           if (lineCount == 0 && pixelCount == 0)
               begin
  +            $display("vsync pulse sent");
  +            vsyncPulse.send();
  +            end
  +        if (lineCount == 0 && pixelCount == 0)
  +            begin
  +            if (waitingForVsync)
  +                sendVsyncIndication.send();
               $display("testPatternEnabled %d", shadowTestPatternEnabled);
               testPatternEnabled <= shadowTestPatternEnabled;
               end
  
positive.code:     Reg#(Bit#(12)) numberOfPixels <- mkSyncReg(1920 + 192 + 44 + 44, axi_clock, axi_reset, defaultClock);
      Reg#(Bit#(11)) lineCount <- mkReg(0);
      Reg#(Bit#(12)) pixelCount <- mkReg(0);
      FIFOF#(Rgb888Stage) bramOutStageFifo <- mkSizedFIFOF(8);
      Reg#(Bit#(12)) dataCount <- mkReg(0);
      Vector#(4, Reg#(Bit#(32))) patternRegs <- replicateM(mkSyncReg(32'h00FFFFFF, axi_clock, axi_reset, defaultClock));
      Reg#(Bool) shadowTestPatternEnabled <- mkSyncReg(True, axi_clock, axi_reset, defaultClock);
      Reg#(Bool) testPatternEnabled <- mkReg(True);
      HdmiOut hdmioutput <- mkHdmiOut();
      Reg#(Bool) waitingForVsync <- mkSyncReg(False, axi_clock, axi_reset, defaultClock);
      SyncPulseIfc sendVsyncIndication <- mkSyncPulse(defaultClock, defaultReset, axi_clock);
  
      let isActiveLine = (lineCount >= deLineCountMinimum && lineCount < deLineCountMaximum);
  
      // vsyncPulse is a SyncHandshake to a slow clock domain
      // so it is not ready every cycle.
      // Therefore, we send to it from a different rule so it does not block the fbRule
      rule sendVsyncPulse (lineCount == 0 && pixelCount == 0);
          $display("vsync pulse sent");
          vsyncPulse.send();
      endrule
      rule sendVsyncPulse2 (lineCount == 0 && pixelCount == 0);
          if (waitingForVsync)
          begin
              //waitingForVsync <= False;
              sendVsyncIndication.send();
          end
      endrule
  
      rule sendHsyncPulse (isActiveLine && pixelCount == 0);
          //$display("hsync pulse sent");
          hsyncPulse.send();
      endrule
  
      rule vsyncReceived if (sendVsyncIndication.pulse());
          Bit#(64) v = 0;
  
negative.code:            end
          else
              pixelCount <= pixelCount + 1;
          let d <- lineBuffer.readData();
          d = d[23:0];
  
          Bit#(2) index = {pack(lineCount >= lineMidpoint), pack(pixelCount >= pixelMidpoint)};
          if (testPatternEnabled)
              d = patternRegs[index];
          Rgb888 pixel = unpack(d);
          hdmioutput.rgb(Rgb888VideoData{active_video: pack(dataEnable),
              vsync: vsync, hsync: hsync,
              r: pixel.r, g: pixel.g, b: pixel.b });
      endrule
  
      interface hdmi = hdmioutput.hdmi;
      interface HdmiInternalRequest control;
      method Action setPatternColor(Bit#(32) v);
          patternRegs[0] <= v[23:0]; 
      endmethod
      method Action setTestPattern(Bit#(1) v);
          shadowTestPatternEnabled <= (v != 0);
  