#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <dos.h>

#define	DIP40	40
#define	DIP20	20

#define Am29F 	20

#define AT89C 	8
#define AT49F 	9
#define Am29F 	20
#define AT25C	Am29F+1

#define ON	1
#define OFF	0

#define einbit  (inportb(ipoort)&EIN)
#define inbit   (inportb(ipoort)&IN)

#define ROMBUFSIZ	16384L	 // DW: base size for rombuf. Must be a multiple of 1024!
#define EIN 128
#define outhi clkhi
#define outlo clklo
#define IN 64
#define POW 4
#define RW  2
#define PP  1
#define PGM 8
#define ADR 2
#define CLK 1
#define CLA 4
#define CTW     160
#define CTR     161
#define BIC 0x20
#define powoff  (bits &= ~POW)
#define powon  	(bits |= POW)
#define read    (bits &= ~RW)
#define write   (bits |= RW)
#define pgrhi   (bits &= ~PGM)
#define pgrlo   (bits |= PGM)
#define ppoff   (bits |= PP)
#define ppon   	(bits &= ~PP)

#define adrlo   (outbit &= ~ADR)
#define adrhi   (outbit |= ADR)
#define clklo   (outbit &= ~CLK)
#define clkhi   (outbit |= CLK)
#define clalo   (outbit |=CLA)
#define clahi   (outbit &=~CLA)

#define assert  (outportb(spoort,bits))  //ARW: warning  assert is defi
					 //also in assert.h rename assert_data ??
#define asadres (outportb(poort,outbit))

#define ce_hi   {pgrhi;assert;}     // WE, code 8 = C17/S4 Pin 31 High
#define ce_lo   {pgrlo;assert;}     // WE, code 8 = C17/S4 Pin 31 Low
#define oe_lo   {read;assert;}      // OE, code 2 = S6 high
#define oe_hi   {write;assert;}     // OE, code 2 = S6 low
#define vpp_on  {ppon;assert;}      // VPP, code 1 = C1 12v
#define vpp_off {ppoff;assert;}     // VPP, code 1 = C1 0v
#define we_lo	ce_lo
#define we_hi	ce_hi
#define cs_lo	ce_lo
#define cs_hi	ce_hi

//--------------------------------------
//DW: Function prototypes   //ARW: added more to avoid compiler warnngs
void winstat(void);
void arw_delay(long );
void power_down(void);
void r_adres(long );
void get_settings(void);
void save_settings(void);
void R_50fuses(void);   	// DW: added void
void getoff(void);		// DW: added void
int  test_hw(int dont_stop);
int  in_word();
void ClearBuf(void);
int  Newaantal( unsigned long len );
void Dip(int d);
void Compare(void);
//--------------------------
void show_action(char *ch,int text_color = RED);
void show_error(unsigned long i,unsigned long st, unsigned char g);
void show_inout(long i, unsigned char g, unsigned char ch,int twc );
//-------- MCS-51 ----------
void verify_AT89C(void);
void prog_AT89C(void);
void erase_AT89C(void);
void CRead_AT89C(void);
void lockbit_AT89C(void);
void empty_AT89C(void);
void MCS51_r(int id);
void AT2051_r(int id);
void id_AT89C(void);
//--------- 28Cxxx -------
void verify_28C(void);
int  in_word_28C(void);
void Compare_28C(void);
void r_adres_28C(long adnr);
void setup_28C(void);
//--------- AT29Cxx-----------
void r_adres_29C(unsigned long adr);
int  getch_yes();
void enable_29C(void);
void Boot_Block_29C(void);
void prog_sector(unsigned long i_adres);
int  verify_sector(unsigned long i_adres);
void prog_29C(void);
void erase_29C(void);
void id_29C(void);
//-------- AT49Fxx---------
void prog_AT49F(void);
void erase_AT49F();
void Boot_Block_AT49F();
//-------- 93Cxx ----------
void verify_93(void);
void read_93(void);
void prog_93(void);
//-------- AT25xxx --------
void verify_25C(void);
void read_25C(void);
void prog_25C(void);
//-------------------------