File:  [Isaki's NoNo m68k/m88k emulator] / nono / m680x0 / m68030ccr.h
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:04:34 2026 UTC (2 months, 3 weeks ago) by root
Branches: MAIN, Isaki
CVS tags: v016, v015, v014, v013, v012, v011, v010, v009, v008, v007, v006, v005, v004, HEAD
nono 0.1.0

//
// nono
// Copyright (C) 2014 [email protected]
// Copyright (C) 2020 nono project
// Licensed under nono-license.txt
//

#pragma once

struct m68030ccr
{
	// X フラグは、x の X_BIT が立っていれば 1
	// N フラグは、n の N_BIT が立っていれば 1
	// Z フラグは、z == 0 なら 1
	// V フラグは、v の V_BIT が立っていれば 1
	// C フラグは、c の C_BIT が立っていれば 1
	static const uint32 X_BIT = 0x00000001;
	static const uint32 N_BIT = 0x80000000;
	static const uint32 V_BIT = 0x80000000;
	static const uint32 C_BIT = 0x00000001;

	uint32 x;
	uint32 v;
	uint32 n;
	union {
		uint64 cz;
		struct {
#if BYTE_ORDER == LITTLE_ENDIAN
			uint32 z;
			uint32 c;
#else
			uint32 c;
			uint32 z;
#endif
		} __packed;
	};

	// フラグを立てる
	void SetX() { x = X_BIT; }
	void SetN() { n = N_BIT; }
	void SetZ() { z = 0; }
	void SetV() { v = V_BIT; }
	void SetC() { c = C_BIT; }

	// フラグを降ろす
	void ClrX() { x = 0; }
	void ClrN() { n = 0; }
	void ClrZ() { z = 1; }
	void ClrV() { v = 0; }
	void ClrC() { c = 0; }

	// フラグを value (bool値) にセットする
	void PutX(bool value) { x = (value) ? X_BIT : 0; }
	void PutN(bool value) { n = (value) ? N_BIT : 0; }
	void PutZ(bool value) { z = (value) ? 0 : 1; }
	void PutV(bool value) { v = (value) ? V_BIT : 0; }
	void PutC(bool value) { c = (value) ? C_BIT : 0; }

	// フラグが立っていれば真を返す
	bool IsX() const { return ((x & X_BIT) != 0); }
	bool IsN() const { return ((n & N_BIT) != 0); }
	bool IsZ() const { return (z == 0); }
	bool IsV() const { return ((v & V_BIT) != 0); }
	bool IsC() const { return ((c & C_BIT) != 0); }

	// CCR レジスタの内容を作って返す
	uint8 Get() const {
		return (IsX() ? M68K_CCR_X : 0)
		     | (IsN() ? M68K_CCR_N : 0)
		     | (IsZ() ? M68K_CCR_Z : 0)
		     | (IsV() ? M68K_CCR_V : 0)
		     | (IsC() ? M68K_CCR_C : 0);
	}

	// CCR レジスタに val をセットする
	void Set(uint8 val) {
		PutX((val) & M68K_CCR_X);
		PutN((val) & M68K_CCR_N);
		PutZ((val) & M68K_CCR_Z);
		PutV((val) & M68K_CCR_V);
		PutC((val) & M68K_CCR_C);
	}
};

// フラグを立てる
#define RegSetX()		cpu->reg.ccr.SetX()
#define RegSetN()		cpu->reg.ccr.SetN()
#define RegSetZ()		cpu->reg.ccr.SetZ()
#define RegSetV()		cpu->reg.ccr.SetV()
#define RegSetC()		cpu->reg.ccr.SetC()

// フラグを降ろす
#define RegClrX()		cpu->reg.ccr.ClrX()
#define RegClrN()		cpu->reg.ccr.ClrN()
#define RegClrZ()		cpu->reg.ccr.ClrZ()
#define RegClrV()		cpu->reg.ccr.ClrV()
#define RegClrC()		cpu->reg.ccr.ClrC()

// フラグを value (bool値) にセットする
#define RegPutX(value)		cpu->reg.ccr.PutX(value)
#define RegPutN(value)		cpu->reg.ccr.PutN(value)
#define RegPutZ(value)		cpu->reg.ccr.PutZ(value)
#define RegPutV(value)		cpu->reg.ccr.PutV(value)
#define RegPutC(value)		cpu->reg.ccr.PutC(value)

// フラグが立っていれば真を返す
#define RegIsX			(cpu->reg.ccr.IsX())
#define RegIsN			(cpu->reg.ccr.IsN())
#define RegIsZ			(cpu->reg.ccr.IsZ())
#define RegIsV			(cpu->reg.ccr.IsV())
#define RegIsC			(cpu->reg.ccr.IsC())

#define RegCondT	(true)
#define RegCondF	(false)
#define RegCondHI	(!RegIsC && !RegIsZ)
#define RegCondLS	(RegIsC || RegIsZ)
#define RegCondCC	(!RegIsC)
#define RegCondCS	(RegIsC)
#define RegCondNE	(!RegIsZ)
#define RegCondEQ	(RegIsZ)
#define RegCondVC	(!RegIsV)
#define RegCondVS	(RegIsV)
#define RegCondPL	(!RegIsN)
#define RegCondMI	(RegIsN)
#define RegCondGE	((RegIsN && RegIsV) || (!RegIsN && !RegIsV))
#define RegCondLT	((RegIsN && !RegIsV) || (!RegIsN && RegIsV))
#define RegCondGT	((RegIsN && RegIsV && !RegIsZ) || \
                  	 (!RegIsN && !RegIsV && !RegIsZ))
#define RegCondLE	(RegIsZ || (RegIsN && !RegIsV) || (!RegIsN && RegIsV))

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.