#include <iostream>
#include <string>
#include "font.h"
using namespace std;

// NOTE: www.cprogramming.com/tutorial/bitwise_operators.html

void display_char(int);
int find_char(unsigned char(*)[5]); // trouble declaring function prototype

int main()
{
  // PART 1:
  for(int j = 0 ; j < 96; j++)
  {
    display_char(j);
    cout << endl;
    cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    cout << endl;
  }
  
  // PART 2:
  int char_index = find_char(font_5x7[96][5]);
  cout << "The index of our character for the outer dimension of font_5x7[95][5] is " << char_index << endl;

  return 0;
}


void display_char(int index) // index = {0 ... 95} for 96 ASCII chars
{
  for(int i = 7 ; i > 0; i--) // 7 iter. {7 ... 1}
  {
    for(int j = 0 ; j < 5; j++) // 5 iter. {0 ... 4} , TOT. ITER: 35  
    {
       // j keeps track of a collumns of bits making up one byte; 5 collums of bytes = 1 bitmap for an ASCII char
       unsigned char target = font_5x7[index][j]; 
       
       // '<<' left shift operator
       if((target & (1 << i)) == 0) cout << "At letter index: " << index << ',' << " column: " << j << ", there is a 0" << endl;
       else cout << "At letter index: " << index << ',' << " column: " << j << ", there is a 1" << endl;
    }
     cout << endl;
  }
}


// INPUT: two-dimensional unsigned char array font_5x7[95][5] from font.h
// OUTPUT: integer type representing the index of the bitmapped character in font_5x7 else -1
int find_char(unsigned char font_5x7[][5])
{
  unsigned char lookfor[5] = {0xfe,0x92,0x92,0x92,0x82};
  
  for(int i = 0; i < 95; ++i)
  {
    int check = 0;
    
    for(int j = 0; j < 5; ++j)
    {
      if(lookfor[j] == font_5x7[i][j]) 
      {
        ++check;
	    if(check == 5) return i; 
	    continue;
      } 
      else break;
    }
  }
  
  return -1;
}
