/*

  ACHART - ASCII Character chart (including PC's upper ASCII).
           Invoked by pressing CTRL_A.


  (C) Copyright 1988  Marc Adler/Magma Systems     All Rights Reserved

*/

#define CTRL_A  1

init()
{
  assign_key("ASCII_Chart", CTRL_A);
}


ASCII_Chart()
{
  /* Get the color to display the chart in */
  fg = get_option("fg");
  bg = get_option("bg");
  attr = bg * 16 + fg;

  for (i = 0;  i <= 1;  i++)
  {
    clear_screen();
    row = 1;
    col = 0;
    
    /* Print the column headings */
    for (c = 0;  c < 6;  c++)
      display(0, c*13, 79, attr, "CH DEC HEX");

    /* Determine the ending character for the loop */
    if (i == 0)
      endc = 128;
    else
      endc = 256;

    for (c = i * 127 + 1;  c < endc;  c++)
    {
      s = sprintf("%s  %d", chr(c), c);
      display(row, col, 79, attr, s);
      display(row, col+7, 79, attr, itox(c));

      if (++row % 24 == 0)
      {
        col += 13;
        row = 1;
      }
    }
    
    get_tty_str("Press a key to continue...");

  } /* end for i */
}


/*
  Itox() - takes the passed integer and returns the hex representation
*/
itox(n)
{
  hi = n / 16;
  if (hi >= 10)
    hi = 'A' + hi - 10;
  else
    hi += '0';
    
  lo = n % 16;
  if (lo >= 10)
    lo = 'A' + lo - 10;
  else
    lo += '0';
    
  return strcat(chr(hi), chr(lo));
}
