/*
 *	PECLS Operating System
 *	(Parallel Execute Control Learning System)
 *	        Copyright (C) 1994,95,96,98,99 M.Suzuki
 *
 *	EX68判定
 *
 */

/*
 *
 *	$Id$
 *
 *	$Log$
 *
 */


#include <stdio.h>
#include <iocslib.h>

#define	TEST	0

#define	CSR	(*((volatile unsigned char*)0x00e84080))
#define	CCR	*((unsigned char*)0x00e84087)
#define	DCR	*((unsigned char*)0x00e84084)
#define	OCR	*((unsigned char*)0x00e84085)
#define	SCR	*((unsigned char*)0x00e84086)
#define	DAR	*((unsigned long*)0x00e84094)
#define	MAR	*((unsigned long*)0x00e8408c)
#define	BAR	*((unsigned long*)0x00e8409c)
#define	BTC	*((unsigned short*)0x00e8409a)
#define	MFC	*((unsigned char*)0x00e840a9)
#define	DFC	*((unsigned char*)0x00e840b1)
#define	BFC	*((unsigned char*)0x00e840b9)
#define	GCR	*((unsigned char*)0x00e840bf)

#define	TABLE_MAX	10

/*	DMACを直接叩いてDMA転送をやってみて	*/
/*	転送中状態が存在すれば実機	*/

int EX68Check(void)
{
	int i;
	struct CHAIN table[TABLE_MAX];

	for(i=0;i<TABLE_MAX;i++){
		table[i].adr = 0x0e00000 + i*512*2;
		table[i].len = 512;
	}	/* end of for	*/
	CCR = 0x18;		/* DMA停止	*/
	DCR = 0x88;		/* MPU優先,16bit幅	*/
	OCR = 0x98;		/* MAR -> BAR,SIZE=16,CHAIN=アレイ,REQG=1	*/
	GCR = 0x0c;
	SCR = 0x05;		/* 両方増加	*/
	DAR = (unsigned long)0x0e00000;		/* 転送元	*/
	BTC = TABLE_MAX;		/* テーブル数	*/
	BAR = (unsigned long)table;	/* テーブルアドレス	*/
	MFC = 0x05;
	DFC = 0x05;
	BFC = 0x05;
	CSR = 0;
	CCR = 0x88;		/* DMA開始	*/
	for(i=0;(CSR&0x08);i++);
	return i == 0;
}

#if	TEST
int main(void)
{
	int usp;

	usp = B_SUPER(0);
	if( EX68Check() ){
		B_PRINT("私はEX68K上で生かされています。\r\n");
	} else {
		B_PRINT("私はX68K上で生きています。\r\n");
	}
	B_SUPER(usp);
	return 0;
}
#endif
