/*
 * ArduinoISOIO.h
 *
 *  Created on: Jul 1, 2017
 *      Author: oliford
 */

#ifndef ARDUINOISAIO_H_
#define ARDUINOISAIO_H_

//10ms timeout for CHRDY
#define TIMEOUT_CHRDY 10000

#define RST	2
#define IOCHRDY 3
#define AEN 4
#define IOW 5
#define IOR 6
#define IOCS16 7

#define RST_PORT	PORTE
#define RST_BIT		4

#define IOR_PORT	PORTH
#define IOR_BIT		3

#define IOW_PORT	PORTE
#define IOW_BIT		3

#define IOCS16_PORT	PORTH
#define IOCS16_BIT	4

#define setHigh(port, bit)	(port |= (1 << bit))
#define setLow(port, bit)	(port &= ~(1 << bit))

#define resetHigh()		setHigh(RST_PORT, RST_BIT)
#define resetLow()		setLow(RST_PORT, RST_BIT)

#define ioReadHigh()	setHigh(IOR_PORT, IOR_BIT)
#define ioReadLow()		setLow(IOR_PORT, IOR_BIT)

#define ioWriteHigh()	setHigh(IOW_PORT, IOW_BIT)
#define ioWriteLow()	setLow(IOW_PORT, IOW_BIT)

#define ioCS16High()	setHigh(IOCS16_PORT, IOCS16_BIT)
#define ioCS16Low()		setLow(IOCS16_PORT, IOCS16_BIT)

// Addresses A0-A16 (only to A11 for ProScan card)
#define ISA_A0 22
// Addresses D0-D16
#define ISA_D0 36

/*
 * RST		Ard2		PE4
 * IOCHRDY	Ard3		PE5
 * AEN		Ard4		PG5
 * IOW		Ard5		PE3
 * IOR		Ard6		PH3
 * IOCS16	Ard7		PH4
 *
 *
 * A0 		Ard22		PA0
 * A1 		Ard23		PA1
 * A2 		Ard24		PA2
 * A3 		Ard25		PA3
 * A4 		Ard26		PA4
 * A5 		Ard27		PA5
 * A6 		Ard28		PA6
 * A7 		Ard29		PA7
 *
 * A8 		Ard30		PC7
 * A9 		Ard31		PC6
 * A10 		Ard32		PC5
 * A11 		Ard33		PC4
 * A12 		Ard34		PC3			Not connected at ISA board
 * A13 		Ard35		PC2			Not connected at header
 *
 *
 * D0		Ard36		PC1
 * D1		Ard37		PC0
 * D2		Ard38		PD7
 * D3		Ard39		PG2
 * D4		Ard40		PG1
 * D5		Ard41		PG0
 * D6		Ard42		PL7
 * D7		Ard43		PL6
 *
 * D8		Ard44		PL5
 * D9		Ard45		PL4
 * D10		Ard46		PL3
 * D11		Ard47		PL2
 * D12		Ard48		PL1
 * D13		Ard49		PL0
 * D14		Ard50		PB3
 * D15		Ard51		PB2
 *
 * Data --> PB, PC, PD, PG, PL
 */


#endif /* ARDUINOISAIO_H_ */
