@Override
  public long lastAccessibleCycleBefore(long cycle, AccessibilityGbState gbState) {
    if (cycle < getCbgpInaccessibleFrom()) // before first frame
      return cycle;

    int lineCycle = (int) (cycle % GbConstants.LINE_CYCLES);
    int frameLine = (int) ((cycle % GbConstants.FRAME_CYCLES) / GbConstants.LINE_CYCLES);
    
    if (frameLine >= 144) // in mode 1 (vblank)
      return cycle;
    
    if (lineCycle < getCbgpInaccessibleFrom()) // in mode 2
      return cycle;
    
    if (lineCycle <= getCbgpInaccessibleTo(cycle, gbState)) { // in mode 3
      int offset = lineCycle - (getCbgpInaccessibleFrom() - 1);
      return ((cycle - offset) / 4) * 4; // align to multiples of 4
    }
    
    return cycle; // in mode 0 (hblank)
  }