
#ifndef	_HTC_H_
#warning Header file mtv.h included directly. Use #include <htc.h> instead.
#endif

/*
   Header file for the Phillips microcontrollers for TV and video
   (MTV) these include
   
   P83C145
   P83C845
   P83C055
   P87C055
*/

#ifndef	__MTV_H

#define	__MTV_H
	

typedef struct {
	unsigned B7:1;	/* this is the most significant bit */
	unsigned B6:1;
	unsigned B5:1;
	unsigned B4:1;
	unsigned B3:1;
	unsigned B2:1;
	unsigned B1:1;
	unsigned B0:1;
}	SFR_BITS;

//Special Function Registers
static volatile	unsigned char	P0	@ 0x80;
static volatile	unsigned char	SP	@ 0x81;
static volatile	unsigned char	DPL	@ 0x82;
static volatile	unsigned char	DPH	@ 0x83;
// 16 bit definition
static volatile	unsigned char	PCON	@ 0x87;
static volatile	unsigned char	TCON	@ 0x88;
static 		unsigned char	TMOD	@ 0x89;
static volatile	unsigned char	TL0	@ 0x8A;
static volatile	unsigned char	TL1	@ 0x8B;
static volatile	unsigned char	TH0	@ 0x8C;
static volatile	unsigned char	TH1	@ 0x8D;
static volatile	unsigned char	P1	@ 0x90;
static		unsigned char	OSAT	@ 0x98;
static		unsigned char	OSDT	@ 0x99;
static volatile	unsigned char	OSAD	@ 0x9A;
static volatile	unsigned char	P2	@ 0xA0;
static 		unsigned char	IE	@ 0xA8;
static volatile	unsigned char	P3	@ 0xB0;
static volatile	unsigned char	OSCON	@ 0xC0;
static		unsigned char	OSMOD	@ 0xC1;
static		unsigned char	OSORG	@ 0xC2;
static volatile	unsigned char	RAMCHR	@ 0xC3;
static volatile	unsigned char	RAMATT	@ 0xC4;
static volatile	unsigned char	PSW	@ 0xD0;
static volatile	unsigned char	TDACL	@ 0xD2;
static volatile	unsigned char	TDACH	@ 0xD3;
static		unsigned char	PWM0	@ 0xD4;
static		unsigned char	PWM1	@ 0xD5;
static		unsigned char	PWM2	@ 0xD6;
static		unsigned char	PWM3	@ 0xD7;
static volatile	unsigned char	SAD	@ 0xD8;
static		unsigned char	PWM4	@ 0xDC;
static		unsigned char	PWM5	@ 0xDD;
static		unsigned char	PWM6	@ 0xDE;
static		unsigned char	PWM7	@ 0xDF;
static volatile	unsigned char	ACC	@ 0xE0;
static volatile	unsigned char	B	@ 0xF0;

static volatile	SFR_BITS	P0_BITS		@ 0x80;
static volatile	SFR_BITS	PCON_BITS	@ 0x87;
static volatile	SFR_BITS	TCON_BITS	@ 0x88;
static 		SFR_BITS	TMOD_BITS	@ 0x89;
static volatile	SFR_BITS	P1_BITS		@ 0x90;
static		SFR_BITS	OSAT_BITS	@ 0x98;
static volatile	SFR_BITS	P2_BITS		@ 0xA0;
static 		SFR_BITS	IE_BITS		@ 0xA8;
static volatile	SFR_BITS	P3_BITS		@ 0xB0;
static volatile	SFR_BITS	OSCON_BITS	@ 0xC0;
static		SFR_BITS	OSMOD_BITS	@ 0xC1;
static		SFR_BITS	OSORG_BITS	@ 0xC2;
static volatile	SFR_BITS	PSW_BITS	@ 0xD0;
static volatile	SFR_BITS	SAD_BITS	@ 0xD8;
static volatile	SFR_BITS	ACC_BITS	@ 0xE0;
static volatile	SFR_BITS	B_BITS		@ 0xF0;

//Bit Addressable Locations
//Port 0
static volatile bit P00		@ 0x80;
static volatile bit P01		@ 0x81;
static volatile bit P02		@ 0x82;
static volatile bit P03		@ 0x83;
static volatile bit P04		@ 0x84;
static volatile bit P05		@ 0x85;
static volatile bit P06		@ 0x86;
static volatile bit P07		@ 0x87;
// Alternate Functions
static volatile bit TDAC	@ 0x80;
static volatile bit PROG	@ 0x81;
static volatile bit ASEL	@ 0x82;
static volatile bit PWM1OUT	@ 0x81;
static volatile bit PWM2OUT	@ 0x82;
static volatile bit PWM3OUT	@ 0x83;
static volatile bit PWM4OUT	@ 0x84;
static volatile bit PWM5OUT	@ 0x85;
static volatile bit PWM6OUT	@ 0x86;
static volatile bit PWM7OUT	@ 0x87;

//Timer control TCON
static 		bit IT0		@ 0x88;
static volatile bit IE0		@ 0x89;
static 		bit IT1		@ 0x8A;
static volatile bit IE1 	@ 0x8B;
static		bit TR0 	@ 0x8C;
static volatile bit TF0 	@ 0x8D;
static		bit TR1 	@ 0x8E;
static volatile bit TF1 	@ 0x8F;

//Port 1
static volatile bit P10		@ 0x90;
static volatile bit P11		@ 0x91;
static volatile bit P12		@ 0x92;
static volatile bit P13		@ 0x93;
static volatile bit P14		@ 0x94;
static volatile bit P15		@ 0x95;
static volatile bit P16		@ 0x96;
static volatile bit P17		@ 0x97;
// Alternate Functions
static volatile bit AD10	@ 0x90;
static volatile bit AD11	@ 0x91;
static volatile bit AD12	@ 0x92;
static volatile bit PWM0OUT	@ 0x93;

//On Screen Attributes OSAT
static		bit SH 		@ 0x98;	// When OSDT = Newline
static		bit D 		@ 0x99;
static		bit SR	 	@ 0x9A;
static 		bit E	 	@ 0x9C;
static 		bit BC0		@ 0x98;	// When OSDT = BSpace, SplitBSpace
static 		bit BC1		@ 0x99;
static 		bit BC2		@ 0x9A;
static 		bit OSATB 	@ 0x9C;	// When OSDT != Newline
static 		bit FC0 	@ 0x98;	// When OSDT = Any Other Character
static		bit FC1 	@ 0x99;
static		bit FC2	 	@ 0x9A;

//Port 2
static volatile	bit P20	 	@ 0xA0;
static volatile	bit P21	 	@ 0xA1;
static volatile	bit P22 	@ 0xA2;
static volatile	bit P23 	@ 0xA3;
static volatile	bit P24 	@ 0xA4;
static volatile	bit P25 	@ 0xA5;
static volatile	bit P26 	@ 0xA6;
static volatile	bit P27 	@ 0xA7;

//Interrupt Enable IE
static 		bit EX0		@ 0xA8;
static		bit ET0 	@ 0xA9;
static 		bit EX1 	@ 0xAA;
static 		bit ET1 	@ 0xAB;
static 		bit EVS		@ 0xAC;
static 		bit EA 		@ 0xAF;

//Port 3
static volatile bit P30		@ 0xB0;
static volatile bit P31		@ 0xB1;
static volatile bit P32		@ 0xB2;
static volatile bit P33		@ 0xB3;
static volatile bit P34		@ 0xB4;
static volatile bit P35		@ 0xB5;
static volatile bit P36		@ 0xB6;
static volatile bit P37		@ 0xB7;
// Alternate Functions
static volatile bit INT1	@ 0xB1;
static volatile bit T0		@ 0xB2;
static volatile bit INT0	@ 0xB3;

//Program Status Word PSW
static volatile	bit P		@ 0xD0;
static volatile bit OV		@ 0xD2;
static		bit RS0		@ 0xD3;
static		bit RS1		@ 0xD4;
static volatile bit F0		@ 0xD5;
static volatile	bit AC		@ 0xD6;
static volatile	bit CY		@ 0xD7;

//Software Analog-to-Digital Facility SAD
static		bit SAD0	@ 0xD8;
static		bit SAD1	@ 0xD9;
static		bit SAD2	@ 0xDA;
static		bit SAD3	@ 0xDB;
static volatile	bit ST		@ 0xDC;
static		bit CH0		@ 0xDD;
static		bit CH1		@ 0xDE;
static volatile	bit VHI		@ 0xDF;

//Accumulator
static volatile bit ACC0	@ 0xE0;
static volatile bit ACC1	@ 0xE1;
static volatile bit ACC2	@ 0xE2;
static volatile bit ACC3	@ 0xE3;
static volatile bit ACC4	@ 0xE4;
static volatile bit ACC5	@ 0xE5;
static volatile bit ACC6	@ 0xE6;
static volatile bit ACC7	@ 0xE7;

//B Register
static bit B0			@ 0xF0;
static bit B1			@ 0xF1;
static bit B2			@ 0xF2;
static bit B3			@ 0xF3;
static bit B4			@ 0xF4;
static bit B5			@ 0xF5;
static bit B6			@ 0xF6;
static bit B7			@ 0xF7;

/*	Interrupt vectors */
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0 	0x0B
#define	EXTINT1	0x13
#define TIMER1 	0x1B
#define VSYNC 	0x23

#endif	
