/* MegaZeux
 *
 * Copyright (C) 1996 Greg Janson
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

// Procedures to write hex strs onscreen

#include "hexchar.h"
#include "graphics.h"
#include <stdlib.h>
#include <string.h>

//Set rightalign to print the rightmost char at xy and proceed to the left
//minlen is the minimum length to print. Pad with 0.
void write_number(int number, char color, int x, int y,
 int minlen, int rightalign, int base)
{
  char temp[7];
  int t1, t2;
  if(base == 10)
    sprintf(temp, "%d", number);
  else
    sprintf(temp, "%x", number);

  if(rightalign)
  {
    t1 = strlen(temp);
    if(minlen > t1)
      t1 = minlen;
    x -= t1 - 1;
  }

  if((t2 = strlen(temp)) < minlen)
  {
    t2 = minlen - t2;
    for(t1 = 0; t1 < t2; t1++)
      draw_char('0', color, x++, y);
  }

  write_string(temp, x, y, color, 0);
}

