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

/* This is a header file for the Philips Microcontrollers
	SAA5645
	SAA5647
	SAA5665
	SAA5667
*/

#ifndef __SAA56XX_H
#define __SAA56XX_H


typedef struct {
	unsigned B7:1; //This is the most signifigant 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;
static		unsigned char IEN1	@ 0x84;
static		unsigned char IP1	@ 0x85;
static		unsigned char EXTINT	@ 0x86;
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 GPR1	@ 0x91;
static		unsigned char GPR2	@ 0x92;
static		unsigned char GPR3	@ 0x93;
static		unsigned char GPR4	@ 0x94;
static		unsigned char GPR5	@ 0x95;
static		unsigned char P0CFGA	@ 0x96;
static		unsigned char P0CFGB	@ 0x97;
static volatile unsigned char SADB	@ 0x98;
static volatile unsigned char S0CON	@ 0x99;
static volatile unsigned char S0BUF	@ 0x9A;
static		unsigned char GPR6	@ 0x9C;
static		unsigned char GPR7	@ 0x9D;
static		unsigned char P1CFGA	@ 0x9E;
static		unsigned char P1CFGB	@ 0x9F;
static volatile unsigned char P2	@ 0xA0;
static		unsigned char TXT31	@ 0xA1;
static		unsigned char TXT32	@ 0xA2;
static		unsigned char TXT33	@ 0xA3;
static		unsigned char TXT34	@ 0xA4;
static		unsigned char GPR8	@ 0xA5;
static		unsigned char P2CFGA	@ 0xA6;
static		unsigned char P2CFGB	@ 0xA7;
static		unsigned char IEN0	@ 0xA8;
static		unsigned char TXT23	@ 0xA9;
static		unsigned char TXT24	@ 0xAA;
static		unsigned char TXT25	@ 0xAB;
static		unsigned char TXT26	@ 0xAC;
static		unsigned char TXT28	@ 0xAD;
static volatile unsigned char P3	@ 0xB0;
static		unsigned char TXT27	@ 0xB1;
static		unsigned char TXT18	@ 0xB2;
static		unsigned char TXT19	@ 0xB3;
static		unsigned char TXT20	@ 0xB4;
static		unsigned char TXT21	@ 0xB5;
static volatile unsigned char TXT22	@ 0xB6;
static		unsigned char CCLIN	@ 0xB7;
static		unsigned char IP	@ 0xB8;
static		unsigned char TXT17	@ 0xB9;
static volatile unsigned char WSS1	@ 0xBA;
static volatile unsigned char WSS2	@ 0xBB;
static volatile unsigned char WSS3	@ 0xBC;
static		unsigned char GPR9	@ 0xBD;
static		unsigned char P3CFGA	@ 0xBE;
static		unsigned char P3CFGB	@ 0xBF;
static		unsigned char TXT0	@ 0xC0;
static		unsigned char TXT1	@ 0xC1;
static		unsigned char TXT2	@ 0xC2;
static		unsigned char TXT3	@ 0xC3;
static		unsigned char TXT4	@ 0xC4;
static		unsigned char TXT5	@ 0xC5;
static		unsigned char TXT6	@ 0xC6;
static		unsigned char TXT7	@ 0xC7;
static volatile unsigned char TXT8	@ 0xC8;
static volatile unsigned char TXT9	@ 0xC9;
static		unsigned char TXT10	@ 0xCA;
static volatile unsigned char TXT11	@ 0xCB;
static volatile unsigned char TXT12	@ 0xCC;
static		unsigned char TXT14	@ 0xCD;
static		unsigned char TXT15	@ 0xCE;
static volatile unsigned char CCBASE	@ 0xCF;
static volatile unsigned char PSW	@ 0xD0;
static		unsigned char GPR10	@ 0xD1;
static		unsigned char TDACL	@ 0xD2;
static		unsigned char TDACH	@ 0xD3;
static		unsigned char PWM7	@ 0xD4;
static		unsigned char PWM0	@ 0xD5;
static		unsigned char PWM1	@ 0xD6;
static volatile unsigned char CCDAT1	@ 0xD7;
static volatile unsigned char S1CON	@ 0xD8;
static volatile unsigned char S1STA	@ 0xD9;
static volatile unsigned char S1DAT	@ 0xDA;
static		unsigned char S1ADR	@ 0xDB;
static		unsigned char PWM3	@ 0xDC;
static		unsigned char PWM4	@ 0xDD;
static		unsigned char PWM5	@ 0xDE;
static		unsigned char PWM6	@ 0xDF;
static volatile unsigned char ACC	@ 0xE0;
static		unsigned char TXT29	@ 0xE1;
static		unsigned char TXT30	@ 0xE2;
static		unsigned char GPR11	@ 0xE3;
static		unsigned char PWM2	@ 0xE4;
static		unsigned char GPR12	@ 0xE5;
static		unsigned char GPR13	@ 0xE6;
static volatile unsigned char CCDAT2	@ 0xE7;
static volatile unsigned char SAD	@ 0xE8;
static		unsigned char GPR14	@ 0xE9;
static		unsigned char GPR15	@ 0xEA;
static		unsigned char GPR16	@ 0xEB;
static		unsigned char GPR17	@ 0xEC;
static		unsigned char GPR18	@ 0xED;
static volatile unsigned char TXT35	@ 0xEE;
static volatile unsigned char TXT36	@ 0xEF;
static volatile unsigned char B		@ 0xF0;
static volatile unsigned char T2CON	@ 0xF1;
static		unsigned char T2MOD	@ 0xF2;
static volatile unsigned char RCAP2L	@ 0xF3;
static volatile unsigned char RCAP2H	@ 0xF4;
static volatile unsigned char TL2	@ 0xF5;
static volatile unsigned char TH2	@ 0xF6;
static volatile unsigned char TXT13	@ 0xF8;
static		unsigned char GPR19	@ 0xF9;
static		unsigned char XRAMP	@ 0xFA;
static		unsigned char ROMBK	@ 0xFB;
static		unsigned char GPR20	@ 0xFC;
static volatile unsigned char TEST	@ 0xFD;
static volatile unsigned char WDTKEY	@ 0xFE;
static		unsigned char WDT	@ 0xFF;

static volatile SFR_BITS	P0_BITS			@ 0x80;
static		SFR_BITS	IEN1_BITS		@ 0x84;
static		SFR_BITS	IP1_BITS		@ 0x85;
static		SFR_BITS	EXTINT_BITS		@ 0x86;
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	GPR1_BITS		@ 0x91;
static		SFR_BITS	GPR2_BITS		@ 0x92;
static		SFR_BITS	GPR3_BITS		@ 0x93;
static		SFR_BITS	GPR4_BITS		@ 0x94;
static		SFR_BITS	GPR5_BITS		@ 0x95;
static		SFR_BITS	P0CFGA_BITS		@ 0x96;
static		SFR_BITS	P0CFGB_BITS		@ 0x97;
static volatile SFR_BITS	SADB_BITS		@ 0x98;
static volatile SFR_BITS	S0CON_BITS		@ 0x99;
static volatile SFR_BITS	S0BUF_BITS		@ 0x9A;
static		SFR_BITS	GPR6_BITS		@ 0x9C;
static		SFR_BITS	GPR7_BITS		@ 0x9D;
static		SFR_BITS	P1CFGA_BITS		@ 0x9E;
static		SFR_BITS	P1CFGB_BITS		@ 0x9F;
static volatile SFR_BITS	P2_BITS			@ 0xA0;
static		SFR_BITS	GPR8_BITS		@ 0xA5;
static		SFR_BITS	P2CFGA_BITS		@ 0xA6;
static		SFR_BITS	P2CFGB_BITS		@ 0xA7;
static		SFR_BITS	IEN0_BITS		@ 0xA8;
static		SFR_BITS	TXT23_BITS		@ 0xA9;
static		SFR_BITS	TXT24_BITS		@ 0xAA;
static		SFR_BITS	TXT25_BITS		@ 0xAB;
static		SFR_BITS	TXT26_BITS		@ 0xAC;
static		SFR_BITS	TXT28_BITS		@ 0xAD;
static volatile SFR_BITS	P3_BITS			@ 0xB0;
static		SFR_BITS	TXT18_BITS		@ 0xB2;
static		SFR_BITS	TXT19_BITS		@ 0xB3;
static		SFR_BITS	TXT20_BITS		@ 0xB4;
static		SFR_BITS	TXT21_BITS		@ 0xB5;
static volatile SFR_BITS	TXT22_BITS		@ 0xB6;
static		SFR_BITS	IP_BITS			@ 0xB8;
static		SFR_BITS	TXT17_BITS		@ 0xB9;
static volatile SFR_BITS	WSS1_BITS		@ 0xBA;
static volatile SFR_BITS	WSS2_BITS		@ 0xBB;
static volatile SFR_BITS	WSS3_BITS		@ 0xBC;
static		SFR_BITS	GPR9_BITS		@ 0xBD;
static		SFR_BITS	P3CFGA_BITS		@ 0xBE;
static		SFR_BITS	P3CFGB_BITS		@ 0xBF;
static		SFR_BITS	TXT0_BITS		@ 0xC0;
static		SFR_BITS	TXT1_BITS		@ 0xC1;
static		SFR_BITS	TXT2_BITS		@ 0xC2;
static		SFR_BITS	TXT4_BITS		@ 0xC4;
static		SFR_BITS	TXT5_BITS		@ 0xC5;
static		SFR_BITS	TXT6_BITS		@ 0xC6;
static		SFR_BITS	TXT7_BITS		@ 0xC7;
static volatile SFR_BITS	TXT8_BITS		@ 0xC8;
static volatile SFR_BITS	TXT9_BITS		@ 0xC9;
static volatile SFR_BITS	TXT12_BITS		@ 0xCC;
static volatile SFR_BITS	PSW_BITS		@ 0xD0;
static		SFR_BITS	GPR10_BITS		@ 0xD1;
static		SFR_BITS	TDACH_BITS		@ 0xD3;
static		SFR_BITS	PWM7_BITS		@ 0xD4;
static		SFR_BITS	PWM0_BITS		@ 0xD5;
static		SFR_BITS	PWM1_BITS		@ 0xD6;
static volatile SFR_BITS	S1CON_BITS		@ 0xD8;
static volatile SFR_BITS	S1STA_BITS		@ 0xD9;
static volatile SFR_BITS	S1DAT_BITS		@ 0xDA;
static		SFR_BITS	S1ADR_BITS		@ 0xDB;
static		SFR_BITS	PWM3_BITS		@ 0xDC;
static		SFR_BITS	PWM4_BITS		@ 0xDD;
static		SFR_BITS	PWM5_BITS		@ 0xDE;
static		SFR_BITS	PWM6_BITS		@ 0xDF;
static volatile SFR_BITS	ACC_BITS		@ 0xE0;
static		SFR_BITS	TXT29_BITS		@ 0xE1;
static		SFR_BITS	TXT30_BITS		@ 0xE2;
static		SFR_BITS	GPR11_BITS		@ 0xE3;
static		SFR_BITS	PWM2_BITS		@ 0xE4;
static		SFR_BITS	GPR12_BITS		@ 0xE5;
static		SFR_BITS	GPR13_BITS		@ 0xE6;
static volatile SFR_BITS	SAD_BITS		@ 0xE8;
static		SFR_BITS	GPR14_BITS		@ 0xE9;
static		SFR_BITS	GPR15_BITS		@ 0xEA;
static		SFR_BITS	GPR16_BITS		@ 0xEB;
static		SFR_BITS	GPR17_BITS		@ 0xEC;
static		SFR_BITS	GPR18_BITS		@ 0xED;
static volatile SFR_BITS	TXT35_BITS		@ 0xEE;
static volatile SFR_BITS	TXT36_BITS		@ 0xEF;
static volatile SFR_BITS	B_BITS			@ 0xF0;
static volatile SFR_BITS	T2CON_BITS		@ 0xF1;
static		SFR_BITS	T2MOD_BITS		@ 0xF2;
static volatile SFR_BITS	TL2_BITS		@ 0xF5;
static volatile SFR_BITS	TH2_BITS		@ 0xF6;
static volatile SFR_BITS	TXT13_BITS		@ 0xF8;
static		SFR_BITS	GPR19_BITS		@ 0xF9;
static		SFR_BITS	ROMBK_BITS		@ 0xFB;
static		SFR_BITS	GPR20_BITS		@ 0xFC;
static volatile SFR_BITS	TEST_BITS		@ 0xFD;

//Bit Addressable Locations
//Port 0 P0
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	RX	@ 0x80;
static volatile bit	TX	@ 0x81;
static volatile bit	INT2	@ 0x82;
static volatile bit	INT3	@ 0x83;
static volatile bit	INT4	@ 0x84;
static volatile bit	T2	@ 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 P1
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	INT1	@ 0x90;
static volatile bit	T0	@ 0x91;
static volatile bit	INT0	@ 0x92;
static volatile bit	T1	@ 0x93;
static volatile bit	SCL0	@ 0x94;
static volatile bit	SDA0	@ 0x95;
static volatile bit	SCL1	@ 0x96;
static volatile bit	SDA1	@ 0x97;

// Software ADC SADB
static volatile bit	SAD0	@ 0x98;
static volatile bit	SAD1	@ 0x99;
static volatile bit	SAD2	@ 0x9A;
static volatile bit	SAD3	@ 0x9B;
static		bit	DC_COMP	@ 0x9C;

//Port 2 P2
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 0 IEN0
static 		bit 	EX0 	@ 0xA8;
static 		bit 	ET0 	@ 0xA9;
static 		bit 	EX1 	@ 0xAA;
static 		bit 	ET1 	@ 0xAB;
static 		bit 	ECC 	@ 0xAC;
static 		bit 	ES2 	@ 0xAD;
static 		bit 	EBUSY 	@ 0xAE;
static 		bit 	EA	@ 0xAF;

//Port 3 P3
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	ADC0	@ 0xB0;
static volatile bit	ADC1	@ 0xB1;
static volatile bit	ADC2	@ 0xB2;
static volatile bit	ADC3	@ 0xB3;
static volatile bit	T2EX	@ 0xB4;
static volatile bit	INT5	@ 0xB5;

//Interrupt Priority
static 		bit	PX0	@ 0xB8;
static 		bit	PT0	@ 0xB9;
static 		bit	PX1	@ 0xBA;
static 		bit	PT1	@ 0xBB;
static 		bit	PCC	@ 0xBC;
static 		bit	PES2	@ 0xBD;
static 		bit	PBUSY	@ 0xBE;

// Text Attribute Register TXT0
static 		bit	INVON	@ 0xC0;	// INV ON
static 		bit	VPSON	@ 0xC1;	// VPS ON
static 		bit	DISFRM	@ 0xC2;	// DISABLE FRAME
static 		bit	DISPSRO	@ 0xC3;	// DISPLAY STATUS ROW ONLY
static 		bit	DISHRL	@ 0xC4;	// DISABLE HEADER ROLL
static 		bit	AUTOFRM	@ 0xC5;	// AUTO FRAME
static 		bit	DISPX24	@ 0xC6;	// DISPLAY X24
static 		bit	X24POS	@ 0xC7;	// X24 POSN

// Text Attribute Register TXT8
static 		bit	CVBS	@ 0xC8;	// CVBS1 / CVBS0 (BAR)
static 		bit	WSSON	@ 0xC9;	// WSS ON
static volatile	bit	WSSRC	@ 0xCA;	// WSS RECIEVED
static volatile	bit	PKT26RC	@ 0xCB;	// PKT 26 RECIEVED
static 		bit	DISPNSH	@ 0xCC;	// DISABLE SPANISH
static 		bit	FLKRSTP	@ 0xCE;	// FLICKER STOP ON (BAR)

//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;

//Serial Control 1 S1CON
static 		bit 	CR0 	@ 0xD8;
static 		bit 	CR1 	@ 0xD9;
static volatile bit 	AA	@ 0xDA;
static volatile bit 	SI	@ 0xDB;
static volatile bit 	STO 	@ 0xDC;
static volatile bit 	STA 	@ 0xDD;
static 		bit 	ENSI	@ 0xDE;
static 		bit 	CR2 	@ 0xDF;

//Accumulator ACC
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;

//Software ADC (MSB) SAD
static		bit	SAD4	@ 0xE8;
static		bit	SAD5	@ 0xE9;
static		bit	SAD6	@ 0xEA;
static		bit	SAD7	@ 0xEB;
static volatile	bit	ST	@ 0xEC;
static		bit	CH0	@ 0xED;
static		bit	CH1	@ 0xEE;
static volatile	bit	VHI	@ 0xEF;

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

// Text Attribute Register TXT13
static volatile	bit	FASTEXT	@ 0xF9;	// FASTEXT: packet x/27 detected
static volatile	bit	PKT8_30	@ 0xFA;	// PKT 8/30
static volatile	bit	TEXT625	@ 0xFB;	// 625 TEXT: 625 line WST being recieved
static volatile	bit	TEXT525	@ 0xFC;	// 525 TEXT: 525 line WST being recieved
static		bit	DISP525	@ 0xFD;	// 525 DISPLAY: 525 line sync for display
static volatile	bit	PGCLRNG	@ 0xFE;	// PAGE CLEARING
static volatile	bit	VPSRC	@ 0xFF;	// VPS RECIEVED


//Interrupt Vectors
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0	0x0B
#define	EXTINT1	0x13
#define	TIMER1	0x1B
#define	CC	0x23
#define	SERIAL	0x2B
#define	BUSY	0x33
#define	TIMER2	0x3B
#define	EUART	0x43
#define	UTX	0x3B
#define	URX	0x53
#define	EXTINT2	0x5B
#define	EXTINT3	0x63
#define	EXTINT4	0x6B
#define	EXTINT5	0x73

#endif
