/*	
 *	clips26.h
 *
 *	P/ECE Signetics 2650 Emulator
 *
 *	CLiP - Common Library for P/ECE
 *	Copyright (C) 2001-2005 Naoyuki Sawa
 *
 *	* Mon Apr 25 20:42:00 JST 2005 Naoyuki Sawa
 *	- 嶌惉奐巒丅
 *	* Wed Nov 18 21:37:53 JST 2015 Naoyuki Sawa
 *	- 'extern "C" {'乣'}'偱埻傒傑偟偨丅.cpp傪娷傓Win32僾儘僕僃僋僩偐傜傕僀儞僋儖乕僪弌棃傞傛偆偵偡傞偨傔偱偡丅
 */
#ifndef __CLIP_S26_H__
#define __CLIP_S26_H__

#ifdef  __cplusplus
extern "C" {
#endif//__cplusplus

/****************************************************************************
 *	掕悢丒峔憿懱
 ****************************************************************************/

/* 仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛*/
/* 仛傾僙儞僽儔儖乕僠儞偵偍偄偰丄reg僼傿乕儖僪偺僆僼僙僢僩壛嶼傪丄抶墑僗儘僢僩偵攝抲偟傑偡丅     仛*/
/* 仛"ext"柍偟偺"add"1柦椷偱壛嶼偱偒傞傛偆丄reg僼傿乕儖僪傪僆僼僙僢僩63埲撪偵攝抲偟偰偔偩偝偄丅  仛*/
/* 仛2005/05/02尰嵼丄峔憿懱偺僒僀僘偑64僶僀僩埲壓側偺偱丄傑偩僆僼僙僢僩63傪挻偊傞怱攝偼柍偄偱偡丅仛*/
/* 仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛仛*/

typedef struct _S2650 {
	unsigned char psl;		// + 0, 1: Program Status Lower
					//           psl[1]=COM (logical/arith COMpare)
					//           psl[3]=WC  (With/without Carry)
					//           psl[4]=RS  (Register bank Select)
					//           偦偺懠偺價僢僩偼晄掕偱偡丅
	unsigned char psu;		// + 1, 1: Program Status Upper
					//           psu[5]=II (Interrupt Inhibit)
					//           psu[6]=F  (Flag)
					//           psu[7]=S  (Sense)
					//           偦偺懠偺價僢僩偼晄掕偱偡丅
	unsigned short cc;		// + 2, 2: Condition Code
					//           cc=0x0000         側傜偽 CC=0 傪堄枴偟傑偡丅
					//           cc=0x0001..0x007f 側傜偽 CC=1 傪堄枴偟傑偡丅
					//           cc=0x0080..0x00ff 側傜偽 CC=2 傪堄枴偟傑偡丅
					//           cc=0x0100..0xffff 側傜偽 CC=3 傪堄枴偟傑偡丅
	unsigned short c;		// + 4, 2: Carry
					//           c[8]=0 側傜偽 C=0 傪堄枴偟傑偡丅
					//           c[8]=1 側傜偽 C=1 傪堄枴偟傑偡丅
					//           偦偺懠偺價僢僩偼晄掕偱偡丅
	unsigned char ovf;		// + 6, 1: OVerFlow
					//           ovf[7]=0 側傜偽 OVF=0 傪堄枴偟傑偡丅
					//           ovf[7]=1 側傜偽 OVF=1 傪堄枴偟傑偡丅
					//           偦偺懠偺價僢僩偼晄掕偱偡丅
	unsigned char idc;		// + 7, 1: Inter Digit Carry
					//           idc[4]=0 側傜偽 IDC=0 傪堄枴偟傑偡丅
					//           idc[4]=1 側傜偽 IDC=1 傪堄枴偟傑偡丅
					//           偦偺懠偺價僢僩偼晄掕偱偡丅
 	unsigned char reg[7];		// + 8, 7: REGister stack
	unsigned char sp;		// +15, 1: Pointer for the return address Stack
					//           sp=0..7
 	unsigned short ras[8];		// +16,16: Return Address Stack
 					//           ras[*]=0x0000..0x7fff
	unsigned short iar;		// +32, 2: Instruction Address Register
					//           iar=0x0000..0x7fff
	//------------------------------//
	unsigned char flags;		// +34, 1: ------hi
					//           flg[0]=IRQ (#INTREQ抂巕偺忬懺偵憡摉偟傑偡)
					//           flg[1]=HALT
	unsigned char vector;		// +35, 1: 妱傝崬傒儀僋僞
					//           IRQ=1 偺応崌偺傒桳岠偱偡丅
	int cycle;			// +36, 4: 巆傝幚峴僒僀僋儖
} S2650;				// =40

/* S2650.flags */
#define S2650_IRQ	(1<<0)
#define S2650_HALT	(1<<1)

/****************************************************************************
 *	僌儘乕僶儖曄悢
 ****************************************************************************/

extern S2650 s2650; /* P/ECE偺応崌偼崅懍RAM偵攝抲 -> frams26a.s */

typedef struct _S2650SEQ {
	unsigned char resv0;	/* (梊栺) */
	unsigned char resv1;	/* (梊栺) */
	unsigned char resv2;	/* (梊栺) */
	unsigned char cycle;	/* 徚旓僒僀僋儖悢 */
	void (*fn1)();		/* 嵟弶偵屇傇娭悢 */
	void (*fn2)();		/* [師偵屇傇娭悢] */
	void (*fn3)();		/* [師偵屇傇娭悢] */
} S2650SEQ;
extern const S2650SEQ s2650seq[0x100]; /* 僔乕働儞僗僥乕僽儖 */

/****************************************************************************
 *	傾僾儕働乕僔儑儞掕媊
 ****************************************************************************/

#ifndef PIECE
int s2650_read(int addr);		/* 儊儌儕Read */
void s2650_write(int addr, int data);	/* 儊儌儕Write */
int s2650_read_io(int addr);		/* I/O Read */
void s2650_write_io(int addr, int data);/* I/O Write */
#else /*PIECE*/
/* %r10 s2650_read(%r12); */		/* 儊儌儕Read */
/* void s2650_write(%r12, %r13); */	/* 儊儌儕Write */
/* %r10 s2650_read_io(%r12); */		/* I/O Read */
/* void s2650_write_io(%r12, %r13); */	/* I/O Write */
#endif /*PIECE*/

/****************************************************************************
 *	傾僾儕働乕僔儑儞梡娭悢
 ****************************************************************************/

/* CPU傪儕僙僢僩偟傑偡丅
 */
void s2650_reset();

/* PSU儗僕僗僞抣傪庢摼偟傑偡丅
 * [out]
 *	栠傝抣		PSU儗僕僗僞抣丅(S|F|II|0|0|SP2|SP1|SP0)
 */
#define s2650_get_psu s2650_get_psu_C /* 傾僙儞僽儔撪晹娭悢偲偺柤慜徴撍夞旔 */
int s2650_get_psu();

/* PSU儗僕僗僞抣傪愝掕偟傑偡丅
 * [in]
 *	psu		PSU儗僕僗僞抣丅(S|F|II|-|-|SP2|SP1|SP0)
 */
#define s2650_set_psu s2650_set_psu_C /* 傾僙儞僽儔撪晹娭悢偲偺柤慜徴撍夞旔 */
void s2650_set_psu(int psu);

/* PSL儗僕僗僞抣傪庢摼偟傑偡丅
 * [out]
 *	栠傝抣		PSL儗僕僗僞抣丅(CC1|CC0|IDC|RS|WC|OVF|COM|C)
 */
#define s2650_get_psl s2650_get_psl_C /* 傾僙儞僽儔撪晹娭悢偲偺柤慜徴撍夞旔 */
int s2650_get_psl();

/* PSL儗僕僗僞抣傪愝掕偟傑偡丅
 * [in]
 *	psl		PSL儗僕僗僞抣丅(CC1|CC0|IDC|RS|WC|OVF|COM|C)
 */
#define s2650_set_psl s2650_set_psl_C /* 傾僙儞僽儔撪晹娭悢偲偺柤慜徴撍夞旔 */
void s2650_set_psl(int psl);

/* SENSE抂巕偺擖椡忬懺傪愝掕偟傑偡丅
 * [in]
 *	sense		0傑偨偼1丅
 * [note]
 *	* PSU(S)僼儔僌偵斀塮偟傑偡丅
 */
void s2650_set_sense(int sense);

/* CPU傪幚峴偟傑偡丅
 * [in]
 *	cycle		幚峴僒僀僋儖悢丅
 */
void s2650_run(int cycle);

/* IRQ傪幚峴丄傑偨偼曐棷偟傑偡丅
 */
void s2650_irq(int vector);

#ifdef  __cplusplus
}//extern "C"
#endif//__cplusplus

#endif /*__CLIP_S26_H__*/
