|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2022 nono project ! 4: // Licensed under nono-license.txt ! 5: // ! 6: ! 7: // ! 8: // HD64180 CPU コア ! 9: // ! 10: ! 11: #pragma once ! 12: ! 13: #include "header.h" ! 14: ! 15: // 定数定義など ! 16: struct HD64180 ! 17: { ! 18: // 動作モード ! 19: enum OpMode { ! 20: Reset = 0, ! 21: Normal, ! 22: Halt, ! 23: Sleep, ! 24: ! 25: // I/O ストップモードは IOSTP ビットを立てたもの。 ! 26: // 特にモードとして持たなくてもいいかも。 ! 27: //IOStop, ! 28: ! 29: // システムストップモードは Sleep + IOStop の状態。 ! 30: // スリープモードでいい。 ! 31: //SystemStop, ! 32: }; ! 33: ! 34: // フラグレジスタ ! 35: static const uint8 FlagS = 0x80; ! 36: static const uint8 FlagZ = 0x40; ! 37: static const uint8 FlagH = 0x10; ! 38: static const uint8 FlagPV = 0x04; ! 39: static const uint8 FlagN = 0x02; ! 40: static const uint8 FlagC = 0x01; ! 41: }; ! 42: ! 43: enum ixiy_t { ! 44: USE_HL = 0, ! 45: USE_IX = 1, ! 46: USE_IY = 2, ! 47: }; ! 48: ! 49: // フラグレジスタ。 ! 50: // ! 51: // 7 6 5 4 3 2 1 0 ! 52: // +---+---+---+---+---+---+---+---+ ! 53: // | S | Z | - | H | - |P/V| N | C | ! 54: // +---+---+---+---+---+---+---+---+ ! 55: // ! 56: // '-' のところも値は保持できる ! 57: struct hd64180flag ! 58: { ! 59: protected: ! 60: // S フラグは S の S_BIT が立っていれば 1 ! 61: // Z フラグは Z == 0 なら 1 ! 62: // H フラグは H の H_BIT が立っていれば 1 ! 63: // N フラグは N が true なら 1 ! 64: // C フラグは C の C_BIT が立っていれば 1 ! 65: // ! 66: // P/V フラグは PV の PV_BIT が立っていれば 1 で、 ! 67: // PVisP が true なら P、false なら V とする。 ! 68: static const uint32 S_BIT = 0x00000080; ! 69: static const uint32 H_BIT = 0x00000010; ! 70: static const uint32 PV_BIT = 0x00000080; ! 71: static const uint32 C_BIT = 0x00000001; ! 72: ! 73: union { ! 74: uint16 CZ; ! 75: struct { ! 76: #if BYTE_ORDER == LITTLE_ENDIAN ! 77: uint8 Z; ! 78: uint8 C; ! 79: #else ! 80: uint8 C; ! 81: uint8 Z; ! 82: #endif ! 83: } __packed; ! 84: }; ! 85: uint8 S {}; // b7: Sign ! 86: uint8 H {}; // b4: Half Carry ! 87: bool N {}; // b1: Add/Sub ! 88: bool b5 {}; ! 89: bool b3 {}; ! 90: ! 91: uint8 PV {}; // b2: Parity/Overflow ! 92: bool PVisP {}; // true なら P/V は P ! 93: ! 94: public: ! 95: // フラグをセットする ! 96: void SetS(bool value) { S = (value) ? S_BIT : 0; } ! 97: void SetZ(bool value) { Z = (value) ? 0 : 1; } ! 98: void SetH(bool value) { H = (value) ? H_BIT : 0; } ! 99: void SetN(bool value) { N = value; } ! 100: void SetC(bool value) { C = (value) ? C_BIT : 0; } ! 101: // P/V フラグを今のモードのまま値だけ変える ! 102: void SetPV(bool value) { PV = (value) ? PV_BIT : 0; } ! 103: // P か V フラグをセットする ! 104: void SetP(bool value) { SetPV(value); PVisP = true; } ! 105: void SetV(bool value) { SetPV(value); PVisP = false; } ! 106: ! 107: // フラグを取得する ! 108: bool IsS() const { return (S & S_BIT); } ! 109: bool IsZ() const { return (Z == 0); } ! 110: bool IsH() const { return (H & H_BIT); } ! 111: bool IsPV() const { return (PV & PV_BIT); } ! 112: bool IsN() const { return N; } ! 113: bool IsC() const { return (C & C_BIT); } ! 114: ! 115: // P か V 指定のほうが立っているか (モニタ用) ! 116: bool IsP() const { return (IsPV() && PVisP == true); } ! 117: bool IsV() const { return (IsPV() && PVisP == false); } ! 118: ! 119: // F レジスタの値として取得する ! 120: uint8 Get() const; ! 121: ! 122: // F レジスタに代入する ! 123: void Set(uint8 val); ! 124: ! 125: // fff (0..7) の条件が成立すれば true を返す ! 126: bool IsCond(uint fff) const; ! 127: ! 128: protected: ! 129: // パリティを計算し P フラグを更新する。 ! 130: // P フラグは結果のビット数が偶数ならセット (合計で奇数になるパリティ)。 ! 131: void LetP(uint8 src) { ! 132: SetPV((__builtin_popcount(src) & 1) == 0); ! 133: PVisP = true; ! 134: } ! 135: ! 136: // V フラグを更新する。引数は bool ではないので注意。 ! 137: void LetV(uint32 data) { ! 138: PV = data; ! 139: PVisP = false; ! 140: } ! 141: }; ! 142: ! 143: // レジスタ。 ! 144: // I レジスタと R レジスタは MPU64180Device クラス内で管理している。 ! 145: struct hd64180reg ! 146: { ! 147: uint16 pc {}; ! 148: uint16 sp {}; ! 149: ! 150: union { ! 151: uint8 r[8] {}; ! 152: struct { ! 153: uint8 b; ! 154: uint8 c; ! 155: uint8 d; ! 156: uint8 e; ! 157: uint8 h; ! 158: uint8 l; ! 159: uint8 padding; ! 160: uint8 a; ! 161: }; ! 162: }; ! 163: hd64180flag f {}; ! 164: ! 165: uint16 GetBC() const { ! 166: return (b << 8) | c; ! 167: } ! 168: uint16 GetDE() const { ! 169: return (d << 8) | e; ! 170: } ! 171: uint16 GetHL() const { ! 172: return (h << 8) | l; ! 173: } ! 174: ! 175: void SetBC(uint16 src) { ! 176: b = src >> 8; ! 177: c = src & 0xff; ! 178: } ! 179: void SetDE(uint16 src) { ! 180: d = src >> 8; ! 181: e = src & 0xff; ! 182: } ! 183: void SetHL(uint16 src) { ! 184: h = src >> 8; ! 185: l = src & 0xff; ! 186: } ! 187: ! 188: // 裏レジスタ ! 189: struct { ! 190: uint8 b; ! 191: uint8 c; ! 192: uint8 d; ! 193: uint8 e; ! 194: uint8 h; ! 195: uint8 l; ! 196: hd64180flag f; ! 197: uint8 a; ! 198: } ex {}; ! 199: ! 200: uint16 ix {}; ! 201: uint16 iy {}; ! 202: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.