/* vim: set filetype=c:
 *
 * main.c86  -  Main routine of romcheck program
 *
 * Copyright (C) 1998-2007 Gero Kuhlmann   <gero@gkminix.han.de>
 *
 *  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
 *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: main.c86,v 1.6 2007/01/06 18:31:21 gkminix Exp $
 */

#include <common.h86>
#include <i386/conio.h86>
#include "romcheck.h86"



/*
 * Print help text
 */
static void printhelp(void)
{
  printf("\n\nValid commands:\n");
  printf("    h  -  print this help\n");
  printf("    i  -  print information about a specific rom\n");
  printf("    n  -  find and identify netboot bootrom\n");
  printf("    p  -  print memory map graphically\n");
  printf("    q  -  terminate romcheck and reboot\n");
  printf("    x  -  print rom area as a hex dump\n\n");
  printf("Explanation of symbols in memory map display:\n");
  printf("    %c  -  Area with valid rom signature  ", CHAR_VALID);
  printf("    %c  -  Physical rom area\n", CHAR_ROM);
  printf("    %c  -  Area with invalid rom checksum ", CHAR_INVALID);
  printf("    %c  -  Physical ram area\n", CHAR_RAM);
  printf("    %c  -  Unknown (maybe empty)          ", CHAR_EMPTY);
  printf("    %c  -  Unknown\n", CHAR_UNKNOWN);
}



/*
 * Main routine of romcheck. When it returns, the runtime library will
 * reboot the system.
 */
void main(void)
{
  struct scaninfo si;

  printf("\fromcheck, ");
  printf("%s\n", VERSION);
  printf("%s\n", COPYRIGHT);
  printf("\n\nThis program is free software; you can redistribute it and/or modify\n");
  printf("it under the terms of the GNU General Public License as published by\n");
  printf("the Free Software Foundation; either version 2 of the License, or any later\n");
  printf("version. If you have any comments or suggestions, please send an email to\n");
  printf("gero@gkminix.han.de.\n\n\n");
  printf("Scanning memory... ");
  doscan(&si);
  printf("done\n");
  do {
	printf("\n\nEnter command ('h' for help): ");
	switch (waitchar()) {
		case 'h':
			/* Print help text */
			printhelp();
			break;
		case 'n':
			/* Print netboot bootrom information */
			printnb(&si);
			break;
		case 'i':
			/* Print rom information */
			printinfo(&si);
			break;
		case 'p':
			/* Print scanning results */
			printscan(&si);
			break;
		case 'q':
			/* Terminate program */
			printf("\n\n\nRemove diskette and press <Enter> to reboot...");
			while (waitchar() != '\r') ;
			return;
		case 'x':
			/* Print hex dump */
			printhex(&si);
			break;
		default:
			break;
	}
  } while (TRUE);
}

