
#include <exec/tasks.h>
#include <stdio.h>
#include <stdlib.h>




char __stdiowin[] = "CON:10/10/620/180/";
char __stdiov37[] = "/CLOSE";

VOID (*func[])(VOID);

VOID NoError(VOID)
{
printf("\nNo Error...\n");
}

VOID BusError(VOID)
{
printf("\nSorry, can't create exception 2.\n");
}

UWORD address_error = 0x6003;		/* bra.b   *+$05	*/

UWORD illegal_error = 0x4afc;		/* illegal		*/

UWORD div_error[2] =
	{
	0x7000,			/* moveq.l #$00,d0	*/
	0x82C0,			/* divu    d0,d1	*/
	};

ULONG chk_error = 0x70ff4190;		/* moveq.l #$ff,d0 : chk (a0),d0 */


UWORD trapv_error[4] =
	{
	0x003c, 0x0002,		/* ori.w #%00000010,CCR	*/
	0x4e76,			/* trapv		*/
	0x4e75			/* rts			*/
	};

UWORD privelege_error = 0x46c0;		/* move d0,SR		*/

UWORD trace_error[11] =
	{
	0x2c78, 0x0004,		/* move.l  (4).w,a6		*/
	0x203c, 0x0000, 0x8000,	/* move.l  #$8000,d0		*/
	0x223c, 0x0000, 0xffff,	/* move.l  #$ffff,d1		*/
	0x4eae, 0xff70,		/* jsr     $ffffff70(a6)	*/
	0x4e75			/* rts				*/
	};



ULONG em1111_error = 0xf2222222;	/* 1111 emulation	*/

UWORD trap_error = 0x4e41;		/* trap #1		*/


/* Can't get this one to work... */
ULONG em1010_error = 0xa2222222;	/* 1010 emulation	*/


#define NUMFUNCS 13


VOID (*func[NUMFUNCS])(VOID) =
	{
	(VOID (*)())NoError,
	(VOID (*)())NoError,
	(VOID (*)())BusError,
	(VOID (*)())&address_error,
	(VOID (*)())&illegal_error,
	(VOID (*)())&div_error[0],
	(VOID (*)())&chk_error,
	(VOID (*)())&trapv_error,
	(VOID (*)())&privelege_error,
	(VOID (*)())&trace_error,
	(VOID (*)())&em1010_error,
	(VOID (*)())&em1111_error,
	(VOID (*)())&trap_error,
	};


VOID CleanExit(VOID)
{
printf("Press a key or WINDOWCLOSE gadget to quit");
fseek(stdin, 0, SEEK_END);
getch();
exit(0);
}


VOID main(VOID)
{
int n;
printf(" 0    No Error...          0\n");
printf(" 1    No Error...          1\n");
printf(" 2    Bus error            2\n");	/* Can't create this one! */
printf(" 3    Address error        3\n");
printf(" 4    Illegal instruction  4\n");
printf(" 5    Divide by zero error 5\n");
printf(" 6    chk exception        6\n");
printf(" 7    trapv exception      7\n");
printf(" 8    Privelege violation  8\n");
printf(" 9    trace exception      9\n");
printf(" 10   1010 (A) emulation  10    (crashes with Guru exception #3\n");	/* Can't create this one! */
printf(" 11   1111 emulation      11\n");
printf(" 33   Trap #1  ( = $21)   33\n\n");
printf("                 WHICH: ");

scanf("%ld",&n);

if (n==33) n = 12;
else if (n==12) n = 33;

if ((n<0) || (n>=NUMFUNCS))
	{
	printf("\n Out of range\n");
	CleanExit();
	}
else
		(*func[n])();

CleanExit();
		
}

