• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision92d1db095aeae3fb149fe6e11e06f650bb702ea1 (tree)
Zeit2014-06-09 23:27:22
Autorhikarupsp <hikarupsp@user...>
Commiterhikarupsp

Log Message

CPと0-32bit対応を実装

Ändern Zusammenfassung

Diff

--- a/chncpu.xcodeproj/project.pbxproj
+++ b/chncpu.xcodeproj/project.pbxproj
@@ -33,7 +33,7 @@
3333 17478CFD193E2ADA00293791 /* test.hex */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test.hex; sourceTree = "<group>"; };
3434 17478D00193F3D0000293791 /* ch4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ch4.c; sourceTree = "<group>"; usesTabs = 1; };
3535 17478D02193F586100293791 /* ch4.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ch4.h; sourceTree = "<group>"; usesTabs = 1; };
36- 17478D031940B66700293791 /* opcode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = opcode.c; sourceTree = "<group>"; };
36+ 17478D031940B66700293791 /* opcode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = opcode.c; sourceTree = "<group>"; usesTabs = 1; };
3737 /* End PBXFileReference section */
3838
3939 /* Begin PBXFrameworksBuildPhase section */
@@ -54,6 +54,7 @@
5454 17478CF1193E2A4900293791 /* Products */,
5555 );
5656 sourceTree = "<group>";
57+ usesTabs = 1;
5758 };
5859 17478CF1193E2A4900293791 /* Products */ = {
5960 isa = PBXGroup;
--- a/chncpu/ch4.c
+++ b/chncpu/ch4.c
@@ -78,6 +78,7 @@ ch4_uint CH4Reader_ReadBodyAtIndexAsUINT(CH4Reader *reader, int index, int *retR
7878 readIndex = 0;
7979 if(tmp == -1){
8080 // error
81+ value = 0;
8182 } else if((tmp & 8) == 0){
8283 // 4bit or prefix_ext
8384 if(tmp == 7){
--- a/chncpu/chncpu.c
+++ b/chncpu/chncpu.c
@@ -105,7 +105,7 @@ int decodeHexString(char *src0, char *src1, unsigned char *dst0, unsigned char *
105105 CHNCPU_RuntimeEnvironment *CHNCPU_CreateRuntimeEnvironment(void)
106106 {
107107 CHNCPU_RuntimeEnvironment *env;
108- int i, j;
108+ int i;
109109
110110 env = malloc(sizeof(CHNCPU_RuntimeEnvironment));
111111 if(!env){
@@ -118,11 +118,8 @@ CHNCPU_RuntimeEnvironment *CHNCPU_CreateRuntimeEnvironment(void)
118118 env->iRegBits[i] = 0;
119119 }
120120
121- for(i = 0; i < CHNCPU_NUMBER_OF_MEMORY_PAGE; i++){
122- for(j = 0; j < CHNCPU_NUMBER_OF_OP_TAG; j++){
123- env->mainmemory[i].data[j].opCode = CHNCPU_OPCODE_INVALID;
124- }
125- env->mainmemory[i].labelNumber = 0;
121+ for(i = 0; i < CHNCPU_LENGTH_OF_MAIN_MEMORY; i++){
122+ env->mainmemory[i].opCode = CHNCPU_OPCODE_INVALID;
126123 }
127124
128125 env->appbin0 = malloc(CHNCPU_SIZE_APPBIN);
@@ -135,12 +132,21 @@ CHNCPU_RuntimeEnvironment *CHNCPU_CreateRuntimeEnvironment(void)
135132 env->bindOpFuncTable[i] = NULL;
136133 }
137134 env->bindOpFuncTable[0x02] = CHNCPU_Op_LIMM_BindOperand;
135+ env->bindOpFuncTable[0x10] = CHNCPU_Op_TernaryReg_BindOperand;
138136
139137 // execOpFuncTable
140138 for(i = 0; i <= CHNCPU_OPECODE_MAX; i++){
141139 env->execOpFuncTable[i] = NULL;
142140 }
143141 env->execOpFuncTable[0x02] = CHNCPU_Op_LIMM_Execute;
142+ env->execOpFuncTable[0x10] = CHNCPU_Op_TernaryReg_Execute;
143+
144+ // printOpFuncTable
145+ for(i = 0; i <= CHNCPU_OPECODE_MAX; i++){
146+ env->printOpFuncTable[i] = NULL;
147+ }
148+ env->printOpFuncTable[0x02] = CHNCPU_Op_LIMM_PrintCode;
149+ env->printOpFuncTable[0x10] = CHNCPU_Op_TernaryReg_PrintCode;
144150
145151 env->errFlags = 0;
146152
@@ -181,7 +187,7 @@ int CHNCPU_LoadBinaryFromHexStringFilePath(CHNCPU_RuntimeEnvironment *env, const
181187 int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env)
182188 {
183189 ch4_uint opcode;
184- int index, page;
190+ int mindex;
185191 CHNCPU_OpTag *op;
186192 int breakFlag = 0;
187193 int retv;
@@ -189,53 +195,54 @@ int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env)
189195 // env->appbinReaderから読み込んで、実行可能な状態にする。
190196 // これはコンパイラ版におけるコンパイルに相当する。
191197 printf("< Beginning of binary > \n");
192- page = 0;
193- index = 0;
194- for(page = 0; page < CHNCPU_NUMBER_OF_MEMORY_PAGE; page++){
195- for(index = 0; index < CHNCPU_NUMBER_OF_OP_TAG; index++){
196- opcode = CH4Reader_ReadNextAsUINT(env->appbinReader);
197- if(CH4Reader_IsEndOfBinary(env->appbinReader)){
198- puts("< End of binary >");
199- breakFlag = 1;
198+ mindex = 0;
199+ for(mindex = 0; mindex < CHNCPU_LENGTH_OF_MAIN_MEMORY; mindex++){
200+ opcode = CH4Reader_ReadNextAsUINT(env->appbinReader);
201+ if(CH4Reader_IsEndOfBinary(env->appbinReader)){
202+ puts("< End of binary >");
203+ breakFlag = 1;
204+ break;
205+ }
206+ printf("(%02X) ", opcode);
207+
208+ op = &env->mainmemory[mindex];
209+ op->opCode = opcode;
210+ switch(opcode){
211+ case 0x00:
212+ // NOP
213+ puts("NOP();\n");
214+ mindex--;
200215 break;
201- }
202- printf("(%02X) ", opcode);
203-
204- op = &env->mainmemory[page].data[index];
205- op->opCode = opcode;
206- switch(opcode){
207- case 0x00:
208- // NOP
209- puts("NOP();\n");
210- index--;
211- break;
212- default:
213- // ごく一部の特殊な命令以外は、命令テーブルを参照する
214- if(opcode <= CHNCPU_OPECODE_MAX && env->bindOpFuncTable[opcode]){
215- retv = env->bindOpFuncTable[opcode](env, op);
216- if(retv){
217- opcode = CHNCPU_OPCODE_INVALID;
218- }
219- } else{
216+ default:
217+ // ごく一部の特殊な命令以外は、命令テーブルを参照する
218+ if(opcode <= CHNCPU_OPECODE_MAX && env->bindOpFuncTable[opcode]){
219+ retv = env->bindOpFuncTable[opcode](env, op);
220+ if(retv){
220221 opcode = CHNCPU_OPCODE_INVALID;
221- env->errFlags |= CHNCPU_ERR_C_OPCODE;
222222 }
223- if(opcode == CHNCPU_OPCODE_INVALID){
224- op->opCode = CHNCPU_OPCODE_INVALID;
225- breakFlag = 1;
226- }
227- break;
228- }
229- if(breakFlag == 1){
223+ } else{
224+ opcode = CHNCPU_OPCODE_INVALID;
225+ env->errFlags |= CHNCPU_ERR_C_OPCODE;
226+ }
227+ if(opcode == CHNCPU_OPCODE_INVALID){
228+ op->opCode = CHNCPU_OPCODE_INVALID;
229+ breakFlag = 1;
230+ }
230231 break;
231- }
232232 }
233- if(breakFlag){
233+ if(env->appbinReader->errorFlags){
234+ env->errFlags |= CHNCPU_ERR_C_INVALID_BIN;
235+ break;
236+ }
237+ if(breakFlag == 1){
234238 break;
235239 }
236240 }
241+ if(mindex >= CHNCPU_LENGTH_OF_MAIN_MEMORY && !CH4Reader_IsEndOfBinary(env->appbinReader)){
242+ env->errFlags |= CHNCPU_ERR_C_INTERNAL;
243+ puts("INVALID-C: Internal error (low on memory).");
244+ }
237245 if(env->errFlags){
238- putchar('\n');
239246 if(env->errFlags & CHNCPU_ERR_C_REGNUM){
240247 puts("INVALID-C: Invalid register number.");
241248 }
@@ -248,14 +255,15 @@ int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env)
248255 if(env->errFlags & CHNCPU_ERR_C_EXPRESSION){
249256 puts("INVALID-C: Invalid expression.");
250257 }
258+ if(env->errFlags & CHNCPU_ERR_C_INVALID_BIN){
259+ puts("INVALID-C: Invalid binary.");
260+ }
251261 }
252-
253262 return 0;
254263 }
255264
256265 int CHNCPU_Execute(CHNCPU_RuntimeEnvironment *env)
257266 {
258- int breakFlag = 0;
259267 int count = 0;
260268 int retv;
261269 CHNCPU_OpTag *op;
@@ -265,42 +273,26 @@ int CHNCPU_Execute(CHNCPU_RuntimeEnvironment *env)
265273 }
266274
267275 puts("< Beginning of execution >");
268- for(; env->currentPage < CHNCPU_NUMBER_OF_MEMORY_PAGE; env->currentPage++){
269- op = &env->mainmemory[env->currentPage].data[0];
276+ for(; env->currentIndex < CHNCPU_LENGTH_OF_MAIN_MEMORY; env->currentIndex++){
277+ op = &env->mainmemory[env->currentIndex];
270278 if(op->opCode == CHNCPU_OPCODE_INVALID){
271- // 空白のメモリページ:バイナリの末端
272- puts(">>> Control reached end of binary.");
273- breakFlag = 1;
279+ // End of Binary
274280 break;
275281 }
276- for(; env->currentIndex < CHNCPU_NUMBER_OF_OP_TAG; env->currentIndex++){
277- op = &env->mainmemory[env->currentPage].data[env->currentIndex];
278- if(op->opCode == CHNCPU_OPCODE_INVALID){
279- // このページはここでおしまい
280- break;
281- }
282- if(op->opCode <= CHNCPU_OPECODE_MAX && env->bindOpFuncTable[op->opCode]){
283- retv = env->execOpFuncTable[op->opCode](env, op);
284- } else{
285- // すでにチェックしたはずなのに不明な命令が来た
286- env->errFlags |= CHNCPU_ERR_X_INTERNAL;
287- breakFlag = 1;
288- break;
289- }
290- if(retv){
291- breakFlag = 1;
292- break;
293- }
294-
282+ if(op->opCode <= CHNCPU_OPECODE_MAX && env->bindOpFuncTable[op->opCode]){
283+ retv = env->execOpFuncTable[op->opCode](env, op);
284+ } else{
285+ // ロード時にチェックしたはずなのに不明な命令が来た
286+ env->errFlags |= CHNCPU_ERR_X_INTERNAL;
287+ break;
295288 }
296- if(breakFlag){
289+ if(retv){
290+ // 命令実行時にエラーが発生
297291 break;
298292 }
299- count++;
300- env->currentIndex = 0;
293+
301294 }
302295 if(env->errFlags){
303- putchar('\n');
304296 if(env->errFlags & CHNCPU_ERR_X_INTERNAL){
305297 puts("INVALID-X: Internal error.");
306298 }
@@ -350,7 +342,7 @@ void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env)
350342
351343 int CHNCPU_CHK_IsAvailableBits(CHNCPU_RuntimeEnvironment *env, ch4_uint bits)
352344 {
353- if(bits != 0 && bits != 32){
345+ if(bits > 32){
354346 env->errFlags |= CHNCPU_ERR_C_BITS;
355347 return 0;
356348 }
--- a/chncpu/chncpu.h
+++ b/chncpu/chncpu.h
@@ -17,10 +17,8 @@
1717
1818 #define CHNCPU_OPECODE_MAX 0xFF
1919 #define CHNCPU_BITS_MAX 32
20-#define CHNCPU_BITS_DEFAULT 32
2120 #define CHNCPU_NUMBER_OF_IREG 64
22-#define CHNCPU_NUMBER_OF_MEMORY_PAGE 1024
23-#define CHNCPU_NUMBER_OF_OP_TAG 64
21+#define CHNCPU_LENGTH_OF_MAIN_MEMORY (64 * 1024) // per Op
2422 #define CHNCPU_SIZE_APPBIN (1024 * 1024 * 1)
2523 #define CHNCPU_OPCODE_INVALID (-1)
2624
@@ -28,6 +26,8 @@
2826 #define CHNCPU_ERR_C_BITS 2
2927 #define CHNCPU_ERR_C_OPCODE 4
3028 #define CHNCPU_ERR_C_EXPRESSION 8
29+#define CHNCPU_ERR_C_INTERNAL 16
30+#define CHNCPU_ERR_C_INVALID_BIN 32
3131
3232 #define CHNCPU_ERR_X_INTERNAL 1
3333
@@ -37,24 +37,19 @@ struct CHNCPU_OP_TAG {
3737 void *opCache;
3838 };
3939
40-typedef struct CHNCPU_MEMORY_PAGE CHNCPU_MemoryPage;
41-struct CHNCPU_MEMORY_PAGE {
42- int labelNumber;
43- CHNCPU_OpTag data[CHNCPU_NUMBER_OF_OP_TAG];
44-};
45-
4640 typedef struct CHNCPU_RUN_TIME_ENVIRONMENT CHNCPU_RuntimeEnvironment;
4741 struct CHNCPU_RUN_TIME_ENVIRONMENT {
4842 int (*bindOpFuncTable[CHNCPU_OPECODE_MAX])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
4943 int (*execOpFuncTable[CHNCPU_OPECODE_MAX])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
44+ int (*printOpFuncTable[CHNCPU_OPECODE_MAX])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
5045 int iReg[CHNCPU_NUMBER_OF_IREG];
5146 int iRegBits[CHNCPU_NUMBER_OF_IREG];
52- CHNCPU_MemoryPage mainmemory[CHNCPU_NUMBER_OF_MEMORY_PAGE];
47+ CHNCPU_OpTag mainmemory[CHNCPU_LENGTH_OF_MAIN_MEMORY];
5348 unsigned char *appbin0;
5449 int appbinsize;
5550 CH4Reader *appbinReader;
5651 unsigned int errFlags;
57- int currentPage, currentIndex;
52+ int currentIndex;
5853 };
5954
6055 // @chncpu.c
@@ -70,5 +65,8 @@ int CHNCPU_CHK_IsAvailableBits(CHNCPU_RuntimeEnvironment *env, ch4_uint bits);
7065 // @opcode.c
7166 int CHNCPU_Op_LIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
7267 int CHNCPU_Op_LIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
73-
68+int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
69+int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
70+int CHNCPU_Op_TernaryReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
71+int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
7472 #endif
--- a/chncpu/opcode.c
+++ b/chncpu/opcode.c
@@ -8,6 +8,10 @@
88
99 #include "chncpu.h"
1010
11+//
12+// 02 LIMM
13+//
14+
1115 typedef struct CHNCPU_OP_CACHE_LIMM CHNCPU_OpCache_LIMM;
1216 struct CHNCPU_OP_CACHE_LIMM {
1317 ch4_sint imm;
@@ -25,7 +29,7 @@ int CHNCPU_Op_LIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
2529 opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader);
2630 opCache->bit = CH4Reader_ReadNextAsUINT(env->appbinReader);
2731
28- printf("LIMM(imm:0x%X r:%d bit:%d);\n", opCache->imm, opCache->r, opCache->bit);
32+ CHNCPU_Op_LIMM_PrintCode(env, op, stdout);
2933
3034 if(opCache->r >= CHNCPU_NUMBER_OF_IREG){
3135 env->errFlags |= CHNCPU_ERR_C_REGNUM;
@@ -46,66 +50,125 @@ int CHNCPU_Op_LIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
4650
4751 opCache = op->opCache;
4852
49- printf("LIMM(imm:0x%X r:%d bit:%d);\n", opCache->imm, opCache->r, opCache->bit);
53+ CHNCPU_Op_LIMM_PrintCode(env, op, stdout);
5054
51- env->iReg[opCache->r] = opCache->imm;
52- if(opCache->bit){
53- env->iRegBits[opCache->r] = opCache->bit;
54- } else{
55- env->iRegBits[opCache->r] = CHNCPU_BITS_DEFAULT;
56- }
55+ env->iReg[opCache->r] = opCache->imm & (0xFFFFFFFF >> (32 - opCache->bit));
56+ env->iRegBits[opCache->r] = opCache->bit;
5757
5858 return 0;
5959 }
60-/*
61-typedef struct CHNCPU_OP_CACHE_U_LOGICAL CHNCPU_OpCache_UnsignedLogical;
62-struct CHNCPU_OP_CACHE_U_LOGICAL {
63- ch4_sint imm;
64- ch4_uint r;
65- ch4_uint bit;
66-};
67-int CHNCPU_Op_UnsignedLogical_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
60+
61+int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file)
6862 {
6963 CHNCPU_OpCache_LIMM *opCache;
7064
71- opCache = malloc(sizeof(CHNCPU_OpCache_LIMM));
72- op->opCache = opCache;
65+ opCache = op->opCache;
66+ fprintf(file, "LIMM(imm:0x%X, r:%d, bit:%d);\n", opCache->imm, opCache->r, opCache->bit);
67+
68+ return 0;
69+}
70+
71+//
72+// Ternary Register Operation
73+//
74+
75+// 10 CP/OR
76+
77+typedef struct CHNCPU_OP_CACHE_TERNARY_REG CHNCPU_OpCache_TernaryReg;
78+struct CHNCPU_OP_CACHE_TERNARY_REG {
79+ ch4_uint r0;
80+ ch4_uint r1;
81+ ch4_uint r2;
82+ ch4_uint bit;
83+};
84+int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
85+{
86+ CHNCPU_OpCache_TernaryReg *opCache;
7387
74- opCache->imm = (ch4_sint)CH4Reader_ReadNextAsUINT(env->appbinReader);
75- opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader);
76- opCache->bit = CH4Reader_ReadNextAsUINT(env->appbinReader);
88+ opCache = malloc(sizeof(CHNCPU_OpCache_TernaryReg));
89+ op->opCache = opCache;
7790
78- printf("LIMM(imm:0x%X r:%d bit:%d);\n", opCache->imm, opCache->r, opCache->bit);
91+ opCache->r1 = CH4Reader_ReadNextAsUINT(env->appbinReader);
92+ opCache->r2 = CH4Reader_ReadNextAsUINT(env->appbinReader);
93+ opCache->r0 = CH4Reader_ReadNextAsUINT(env->appbinReader);
94+ opCache->bit = CH4Reader_ReadNextAsUINT(env->appbinReader);
7995
80- if(opCache->r >= CHNCPU_NUMBER_OF_IREG){
96+ CHNCPU_Op_TernaryReg_PrintCode(env, op, stdout);
97+
98+ if(opCache->r0 >= CHNCPU_NUMBER_OF_IREG ||
99+ opCache->r1 >= CHNCPU_NUMBER_OF_IREG ||
100+ opCache->r2 >= CHNCPU_NUMBER_OF_IREG){
81101 env->errFlags |= CHNCPU_ERR_C_REGNUM;
82102 return -1;
83103 }
84104 if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bit)){
85105 return -1;
86106 }
87- if(opCache->bit == 0 && opCache->imm != 0){
88- env->errFlags |= CHNCPU_ERR_C_EXPRESSION;
89- return -1;
90- }
91107 return 0;
92108 }
93-int CHNCPU_Op_UnsignedLogical_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
109+int CHNCPU_Op_TernaryReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
94110 {
95- CHNCPU_OpCache_LIMM *opCache;
111+ CHNCPU_OpCache_TernaryReg *opCache;
96112
97113 opCache = op->opCache;
98114
99- printf("LIMM(imm:0x%X r:%d bit:%d);\n", opCache->imm, opCache->r, opCache->bit);
100-
101- env->iReg[opCache->r] = opCache->imm;
102- if(opCache->bit){
103- env->iRegBits[opCache->r] = opCache->bit;
104- } else{
105- env->iRegBits[opCache->r] = CHNCPU_BITS_DEFAULT;
115+ CHNCPU_Op_TernaryReg_PrintCode(env, op, stdout);
116+
117+ switch (op->opCode) {
118+ case 0x10: // CP/OR
119+ if(opCache->r1 == opCache->r2){
120+ // CP
121+ env->iReg[opCache->r0] = env->iReg[opCache->r1] & (0xFFFFFFFF >> (32 - opCache->bit));
122+ env->iRegBits[opCache->r0] = opCache->bit;
123+ } else{
124+ // OR
125+ env->errFlags |= CHNCPU_ERR_X_INTERNAL;
126+ return -1;
127+ }
128+ break;
129+ default:
130+ env->errFlags |= CHNCPU_ERR_X_INTERNAL;
131+ return -1;
132+ }
133+
134+ if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bit)){
135+ return -1;
106136 }
137+
138+ return 0;
139+}
140+char *CHNCPU_Op_TernaryReg_MnemonicList0[12] = {
141+ // 10 - 1B
142+ "OR",
143+ "XOR",
144+ "AND",
145+ "SBX",
146+ "ADD",
147+ "SUB",
148+ "MUL",
149+ "(Reserved)",
150+ "SHL",
151+ "SAR",
152+ "DIV",
153+ "MOD"
154+};
155+int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file)
156+{
157+ CHNCPU_OpCache_TernaryReg *opCache;
158+
159+ opCache = op->opCache;
107160
161+ if(op->opCode == 0x10 && (opCache->r1 == opCache->r2)){
162+ // CP
163+ fprintf(file, "CP");
164+ } else if(0x10 <= op->opCode && op->opCode <= 0x1B){
165+ fprintf(file, "%s", CHNCPU_Op_TernaryReg_MnemonicList0[op->opCode - 0x10]);
166+ } else{
167+ fprintf(file, "(%02X)", op->opCode);
168+ }
169+
170+ fprintf(file, "(r0:%d, r1:%d, r2:%d, bit:%d);\n", opCache->r0, opCache->r1, opCache->r2, opCache->bit);
171+
108172 return 0;
109173 }
110-*/
111174
--- a/chncpu/test.hex
+++ b/chncpu/test.hex
@@ -1 +1 @@
1-2 E123 0 A0 2 E365 1 A0
\ No newline at end of file
1+2 E123 0 4 2 E365 1 88 90 1 1 2 4
\ No newline at end of file