• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revision5c23f39e5708c9dd8288c968957571698b98110f (tree)
Time2014-06-23 23:58:37
Authorhikarupsp <hikarupsp@user...>
Commiterhikarupsp

Log Message

どうにかcharsを実行できた!

Change Summary

Incremental Difference

--- a/chncpu/chncpu.h
+++ b/chncpu/chncpu.h
@@ -49,7 +49,8 @@
4949 // (2F)Prefix
5050 #define CHNCPU_PREFIX_ALLOW_TRUNCATE 0x01
5151
52-#define CHNCPU_PREFIX_MASK_Op_TernaryRegBitwise (CHNCPU_PREFIX_ALLOW_TRUNCATE)
52+#define CHNCPU_PREFIX_MASK_Op_TernaryReg (CHNCPU_PREFIX_ALLOW_TRUNCATE)
53+#define CHNCPU_PREFIX_MASK_Op_CompareIReg (CHNCPU_PREFIX_ALLOW_TRUNCATE)
5354
5455 // Type of Pointer
5556 #define CHNCPU_PType_Undefined 0
@@ -160,6 +161,9 @@ int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F
160161 int CHNCPU_Op_PLIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
161162 int CHNCPU_Op_PLIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
162163 int CHNCPU_Op_PLIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
164+int CHNCPU_Op_CND_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
165+int CHNCPU_Op_CND_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
166+int CHNCPU_Op_CND_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
163167 int CHNCPU_Op_CALLBIOS_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
164168 int CHNCPU_Op_CALLBIOS_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
165169 int CHNCPU_Op_CALLBIOS_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
@@ -167,6 +171,9 @@ int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTa
167171 int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
168172 int CHNCPU_Op_TernaryRegArithmetic_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
169173 int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
174+int CHNCPU_Op_CompareIReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
175+int CHNCPU_Op_CompareIReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
176+int CHNCPU_Op_CompareIReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
170177
171178 // @bios.c
172179 CHNCPU_BIOS *CHNCPU_CreateBIOS(void);
--- a/chncpu/opcode.c
+++ b/chncpu/opcode.c
@@ -49,6 +49,11 @@ int CHNCPU_Op_Init(CHNCPU_OpTableSet *opSet)
4949 opSet->execFuncTable[0x03] = CHNCPU_Op_PLIMM_Execute;
5050 opSet->printFuncTable[0x03] = CHNCPU_Op_PLIMM_PrintCode;
5151
52+ // CND
53+ opSet->bindFuncTable[0x04] = CHNCPU_Op_CND_BindOperand;
54+ opSet->execFuncTable[0x04] = CHNCPU_Op_CND_Execute;
55+ opSet->printFuncTable[0x04] = CHNCPU_Op_CND_PrintCode;
56+
5257 // CALLBIOS
5358 opSet->bindFuncTable[0x05] = CHNCPU_Op_CALLBIOS_BindOperand;
5459 opSet->execFuncTable[0x05] = CHNCPU_Op_CALLBIOS_Execute;
@@ -71,7 +76,12 @@ int CHNCPU_Op_Init(CHNCPU_OpTableSet *opSet)
7176 opSet->execFuncTable[i] = CHNCPU_Op_TernaryRegArithmetic_Execute;
7277 opSet->printFuncTable[i] = CHNCPU_Op_TernaryReg_PrintCode;
7378 }
74-
79+ //
80+ for(i = 0x20; i <= 0x27; i++){
81+ opSet->bindFuncTable[i] = CHNCPU_Op_CompareIReg_BindOperand;
82+ opSet->execFuncTable[i] = CHNCPU_Op_CompareIReg_Execute;
83+ opSet->printFuncTable[i] = CHNCPU_Op_CompareIReg_PrintCode;
84+ }
7585 return 0;
7686 }
7787
@@ -186,7 +196,7 @@ int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F
186196 }
187197
188198 //
189-// 02 PLIMM
199+// 03 PLIMM
190200 //
191201
192202 typedef struct _CHNCPU_OP_CACHE_PLIMM CHNCPU_OpCache_PLIMM;
@@ -250,6 +260,56 @@ int CHNCPU_Op_PLIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op,
250260 }
251261
252262 //
263+// 04 CND
264+//
265+
266+typedef struct _CHNCPU_OP_CACHE_CND CHNCPU_OpCache_CND;
267+struct _CHNCPU_OP_CACHE_CND {
268+ ch4_uint r;
269+};
270+int CHNCPU_Op_CND_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
271+{
272+ CHNCPU_OpCache_CND *opCache;
273+
274+ opCache = malloc(sizeof(CHNCPU_OpCache_CND));
275+ op->opCache = opCache;
276+
277+ opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader);
278+
279+ if(opCache->r >= CHNCPU_NUMBER_OF_PREG){
280+ env->errFlags |= CHNCPU_ERR_C_REGNUM;
281+ return -1;
282+ }
283+ if(prefix != 0){
284+ env->errFlags |= CHNCPU_ERR_C_PREFIX;
285+ return -1;
286+ }
287+ return 0;
288+}
289+int CHNCPU_Op_CND_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
290+{
291+ CHNCPU_OpCache_CND *opCache;
292+
293+ opCache = op->opCache;
294+
295+ if((env->iReg[opCache->r] & 0x1) != 0x1){
296+ // 次の命令は実行しない
297+ env->currentIndex++;
298+ }
299+ return 0;
300+}
301+
302+int CHNCPU_Op_CND_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file)
303+{
304+ CHNCPU_OpCache_CND *opCache;
305+
306+ opCache = op->opCache;
307+ fprintf(file, "CND(r:%02X);\n", opCache->r);
308+
309+ return 0;
310+}
311+
312+//
253313 // 05 CALLBIOS
254314 //
255315 int CHNCPU_Op_CALLBIOS_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
@@ -360,7 +420,7 @@ int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTa
360420 if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bit)){
361421 return -1;
362422 }
363- if((prefix | CHNCPU_PREFIX_MASK_Op_TernaryRegBitwise) != CHNCPU_PREFIX_MASK_Op_TernaryRegBitwise){
423+ if((prefix | CHNCPU_PREFIX_MASK_Op_TernaryReg) != CHNCPU_PREFIX_MASK_Op_TernaryReg){
364424 env->errFlags |= CHNCPU_ERR_C_PREFIX;
365425 return -1;
366426 }
@@ -408,14 +468,6 @@ int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_O
408468 }
409469 int CHNCPU_Op_TernaryRegArithmetic_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
410470 {
411- // Arithmetic
412- // 14 ADD
413- // 15 SUB
414- // 16 MUL
415- // 18 SHL
416- // 19 SAR
417- // 1A DIV
418- // 1B MOD
419471 CHNCPU_OpCache_TernaryReg *opCache;
420472 int opCode;
421473 ch4_sint result;
@@ -484,8 +536,146 @@ int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag
484536 fprintf(file, "(%02X)", op->opCode);
485537 }
486538
487- fprintf(file, "(r0:%d, r1:%02X, r2:%02X, bit:%02X);\n", opCache->r0, opCache->r1, opCache->r2, opCache->bit);
539+ fprintf(file, "(r0:%02X, r1:%02X, r2:%02X, bit:%d);\n", opCache->r0, opCache->r1, opCache->r2, opCache->bit);
488540
489541 return 0;
490542 }
491543
544+//
545+// Compare Integer Register Operation
546+//
547+
548+// 20 CMPE
549+// 21 CMPNE
550+// 22 CMPL
551+// 23 CMPGE
552+// 24 CMPLE
553+// 25 CMPG
554+// 26 TSTZ
555+// 27 TSTNZ
556+
557+typedef struct _CHNCPU_OP_CACHE_COMPARE_IREG CHNCPU_OpCache_CompareIReg;
558+struct _CHNCPU_OP_CACHE_COMPARE_IREG {
559+ ch4_uint rSrc1;
560+ ch4_uint rSrc2;
561+ ch4_uint bitDiff;
562+ ch4_uint rDst;
563+ ch4_uint bitDst;
564+ unsigned int prefix;
565+};
566+int CHNCPU_Op_CompareIReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
567+{
568+ CHNCPU_OpCache_CompareIReg *opCache;
569+
570+ opCache = malloc(sizeof(CHNCPU_OpCache_TernaryReg));
571+ op->opCache = opCache;
572+
573+ opCache->rSrc1 = CH4Reader_ReadNextAsUINT(env->appbinReader);
574+ opCache->rSrc2 = CH4Reader_ReadNextAsUINT(env->appbinReader);
575+ opCache->bitDiff = CH4Reader_ReadNextAsUINT(env->appbinReader);
576+ opCache->rDst = CH4Reader_ReadNextAsUINT(env->appbinReader);
577+ opCache->bitDst = CH4Reader_ReadNextAsUINT(env->appbinReader);
578+ opCache->prefix = prefix;
579+
580+ if(opCache->rSrc1 >= CHNCPU_NUMBER_OF_IREG ||
581+ opCache->rSrc2 >= CHNCPU_NUMBER_OF_IREG ||
582+ opCache->rDst >= CHNCPU_NUMBER_OF_IREG){
583+ env->errFlags |= CHNCPU_ERR_C_REGNUM;
584+ return -1;
585+ }
586+ if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bitDiff) ||
587+ !CHNCPU_CHK_IsAvailableBits(env, opCache->bitDst)){
588+ return -1;
589+ }
590+ if((prefix | CHNCPU_PREFIX_MASK_Op_CompareIReg) != CHNCPU_PREFIX_MASK_Op_CompareIReg){
591+ env->errFlags |= CHNCPU_ERR_C_PREFIX;
592+ return -1;
593+ }
594+ return 0;
595+}
596+int CHNCPU_Op_CompareIReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
597+{
598+ CHNCPU_OpCache_CompareIReg *opCache;
599+ int opCode;
600+ ch4_sint result;
601+ //ch4_sint diff;
602+ ch4_sint r1, r2;
603+
604+ opCache = op->opCache;
605+ opCode = op->opCode;
606+
607+ // check with bitDiff
608+ /*
609+ // この機能は未実装
610+ diff = env->iReg[opCache->rSrc1] - env->iReg[opCache->rSrc2];
611+ CHNCPU_AdjustValueForBit(env, &diff, opCache->bitDiff, opCache->prefix);
612+ if(env->errFlags){
613+ return -1;
614+ }
615+ */
616+
617+ r1 = env->iReg[opCache->rSrc1];
618+ r2 = env->iReg[opCache->rSrc2];
619+
620+ if(opCode == 0x20){
621+ result = (r1 == r2) ? -1 : 0;
622+ } else if(opCode == 0x21){
623+ result = (r1 != r2) ? -1 : 0;
624+ } else if(opCode == 0x22){
625+ result = (r1 < r2) ? -1 : 0;
626+ } else if(opCode == 0x23){
627+ result = (r1 >= r2) ? -1 : 0;
628+ } else if(opCode == 0x24){
629+ result = (r1 <= r2) ? -1 : 0;
630+ } else if(opCode == 0x25){
631+ result = (r1 > r2) ? -1 : 0;
632+ } else if(opCode == 0x26){
633+ result = ((r1 & r2) == 0) ? -1 : 0;
634+ } else if(opCode == 0x27){
635+ result = ((r1 & r2) != 0) ? -1 : 0;
636+ } else{
637+ env->errFlags |= CHNCPU_ERR_X_INTERNAL;
638+ return -1;
639+ }
640+ // check with bitDst
641+ if(opCache->bitDst == 0){
642+ env->errFlags |= CHNCPU_ERR_X_TRUNCATED_VALUE;
643+ return -1;
644+ }
645+ // store
646+ if(!env->errFlags){
647+ env->iReg[opCache->rDst] = result;
648+ env->iRegBits[opCache->rDst] = opCache->bitDst;
649+ }
650+ return 0;
651+}
652+
653+char *CHNCPU_Op_CompareIReg_MnemonicList0[8] = {
654+ // 20-27
655+ "CMPE",
656+ "CMPNE",
657+ "CMPL",
658+ "CMPGE",
659+ "CMPLE",
660+ "CMPG",
661+ "TSTZ",
662+ "TSTNZ",
663+};
664+int CHNCPU_Op_CompareIReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file)
665+{
666+ CHNCPU_OpCache_CompareIReg *opCache;
667+
668+ opCache = op->opCache;
669+
670+ if(0x20 <= op->opCode && op->opCode <= 0x27){
671+ fprintf(file, "%s", CHNCPU_Op_CompareIReg_MnemonicList0[op->opCode - 0x20]);
672+ } else{
673+ fprintf(file, "(%02X)", op->opCode);
674+ }
675+
676+ fprintf(file, "(rDst:%02X, bitDst:%d r1:%02X, r2:%02X, bitDiff:%d);\n", opCache->rDst, opCache->bitDst, opCache->rSrc1, opCache->rSrc2, opCache->bitDiff);
677+
678+ return 0;
679+}
680+
681+
--- a/chncpu/test.hex
+++ b/chncpu/test.hex
@@ -1,6 +1,9 @@
11 2 a0 0 90
22 2 1 1 90
3+2 C7E 2 90
34 1 1 0
45 5 0 0
56 94 0 1 0 90
7+a4 0 2 90 bf 90
8+4 bf
69 3 1 bf