/*
 * $Date: $
 * $Source: $
 * $Revision: $
 * $State: $
 *
 * $Log: $
 */

#ifndef _EMU_INT_H
#define _EMU_INT_H

#include <time.h>
#include "emu_defs.h"

#define INT_IGNORE      0x00
#define INT_CHAIN       0x01
#define INT_INTERCEPT   0x02

#define INT_READ_VECTOR(intr)     READ_DWORD((intr) * 4)
#define INT_READ_SEG(intr)        READ_WORD(2 + ((intr) * 4))
#define INT_READ_OFS(intr)        READ_WORD((intr) * 4)
#define INT_READ_VEC(intr)        \
   ((INT_READ_SEG(intr)<<4) + INT_READ_OFS(intr))

#define INT_WRITE_SEG(intr, seg)  WRITE_WORD(2+(intr)*4, (seg))
#define INT_WRITE_OFS(intr, ofs)  WRITE_WORD((intr)*4, (ofs))

#define SETIVEC(intr, seg, ofs)   \
   INT_WRITE_SEG(intr,seg); INT_WRITE_OFS(intr,ofs)

#if 0

 TODO:  clear the refs to this from the code and delete this

#ifdef TRUST_VEC_STRUCT
#define IOFF(i) ivecs[i].offset
#define ISEG(i) ivecs[i].segment
#else
#define IOFF(i) ((us *)0)[  (i)<<1    ]
#define ISEG(i) ((us *)0)[ ((i)<<1) +1]
#endif

#define IVEC(i) ((ISEG(i)<<4) + IOFF(i))
#define SETIVEC(i, seg, ofs)	((us *)0)[ ((i)<<1) +1] = (us)seg; \
				((us *)0)[  (i)<<1    ] = (us)ofs

#define OP_IRET			0xcf

#define IS_REDIRECTED(i)	(ISEG(i) != BIOSSEG)
#define IS_IRET(i)		(*(unsigned char *)IVEC(i) == OP_IRET)
#endif

typedef void (*int_handler_func_t)(Bit8u intr);

EXTERN unsigned int  check_date INIT(0);
EXTERN time_t        start_time;
EXTERN Bit32u        last_ticks;

EXTERN Boolean  in_sigsegv INIT(FALSE);
EXTERN Boolean  in_sighandler INIT(FALSE);/* so I know to not use non-reentrant
					 * syscalls like ioctl() :-( */
EXTERN Boolean  ignore_segv INIT(FALSE);
EXTERN Boolean  ignore_trap INIT(FALSE);

extern void int_run(Bit8u intr);
extern void int_run_dpmi(Bit8u intr);

extern void int_run_vm86(Bit8u intr);
extern void int_run_vm86_trap(Bit8u intr);

extern void int_register_vector(Bit8u, int_handler_func_t, int flags);
extern void int21_register_vector(Bit8u, int_handler_func_t, int flags);

extern void int_init(void);

extern int  can_revector(int intr);  /* XXX -- obsolete */

#endif /* _EMU_INT_H */
