/*
 * tstint.c  17 Nov 83  Craig Milo Rogers at USC/ISI
 *
 *	This program tests int_pkg.c, the interrupt allocation package.
 */

#define M_TSTINT		/* For debugging. */

#include "stdio.h"

#include "truth.h"
#include "beauty.h"

#include "exmem.h"

bool int_setup();		/* Type declarations. */
bool int_restore();
long int_prev();


main(argc, argv)
int argc;			/* Number of command arguments. */
char *argv[];			/* Pointers to argument strings. */
{
    long prevvec;		/* Previous vector contents. */

    printf("Initializing Interrupt Package.\n");
    int_ini();

    printf("Terminating Interrupt Package.\n");
    int_trm();

    printf("Initialization again.\n");
    int_ini();

    printf("Poking vectors 6 and 7 to fixed values.\n");
    poke((p_addr)26,0x6626); poke((p_addr)24,0x6624);
    poke((p_addr)30,0x7730); poke((p_addr)28,0x7728);

    printf("Contents of vector 6 are %04x:%04x.\n",
	peek((p_addr)26), peek((p_addr)24));
    printf("Contents of vector 7 are %04x:%04x.\n",
	peek((p_addr)30), peek((p_addr)28));

    printf("Setting vector 6 to 0123:4567.\n");
    if (!int_setup(6, 0x4567, 0x0123)) {
	printf("Error return from int_setup().\n");
    }
    printf("Contents of vector 6 are %04x:%04x.\n",
	peek((p_addr)26), peek((p_addr)24));

    prevvec = int_prev(6);
    printf("Previous contents were %04x:%04x.\n",
	(int)(prevvec >> 16), (int)(prevvec &0xffff));

    printf("Setting vector 7 to 7162:5344.\n");
    if (!int_setu(7, 0x5344, 0x7162)) {
	printf("Error return from int_setup().\n");
    }
    printf("Contents of vector 7 are %04x:%04x.\n",
	peek((p_addr)30), peek((p_addr)28));

    printf("Attempting to reset vector 7 to 3333:4444.\n");
    if (int_setu(7, 0x4444, 0x3333)) {
	printf("Unexpected successful return from int_setup().\n");
    } else {
	printf("Expected unsuccessful return from int_setup().\n");
    }
    printf("Contents of vector 7 are %04x:%04x.\n",
	peek((p_addr)30), peek((p_addr)28));

    printf("Restoring vector 7.\n");
    if (!int_restore(7)) {
	printf("Error return from int_restore().\n");
    }
    printf("Contents of vector 7 are %04x:%04x.\n",
	peek((p_addr)30), peek((p_addr)28));

    printf("Terminating interrupt service.\n");
    int_trm();
    printf("Contents of vector 6 are %04x:%04x.\n",
	peek((p_addr)26), peek((p_addr)24));

    printf("Done.\n");
}
