修訂 | df3004692a76a25cbdc7f5e1287e8e8492f8417a (tree) |
---|---|
時間 | 2014-07-08 22:07:42 |
作者 | hikarupsp <hikarupsp@user...> |
Commiter | hikarupsp |
SMEMを実装。
意外と簡単だった。
@@ -217,6 +217,10 @@ int CHNCPU_Op_LMEM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
217 | 217 | int CHNCPU_Op_LMEM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); |
218 | 218 | int CHNCPU_Op_LMEM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file); |
219 | 219 | // |
220 | +int CHNCPU_Op_SMEM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix); | |
221 | +int CHNCPU_Op_SMEM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); | |
222 | +int CHNCPU_Op_SMEM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file); | |
223 | +// | |
220 | 224 | int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix); |
221 | 225 | int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); |
222 | 226 | int CHNCPU_Op_TernaryRegArithmetic_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); |
@@ -256,6 +260,7 @@ CHNCPU_Data *CHNCPU_DATA_CreateDataFromFileAsPType(const char dataPath[], ch4_si | ||
256 | 260 | int CHNCPU_DATA_AssignDataTagToPReg(CHNCPU_RuntimeEnvironment *env, ch4_uint p, CHNCPU_Data *data); |
257 | 261 | int CHNCPU_DATA_WriteRawDataToFile(CHNCPU_Data *data, const char dataPath[], int dataCount, int dataType); |
258 | 262 | int CHNCPU_DATA_ReadAtIndex(CHNCPU_Data *data, int index, unsigned int *errFlags); |
263 | +int CHNCPU_DATA_WriteToIndex(CHNCPU_Data *data, int index, int value, unsigned int *errFlags); | |
259 | 264 | int CHNCPU_DATA_CalculateByteSizeOfRawData(ch4_sint dataType, ch4_uint dataCount); |
260 | 265 | int CHNCPU_DATA_PrintData(CHNCPU_Data *data, FILE *file); |
261 | 266 |
@@ -185,6 +185,27 @@ int CHNCPU_DATA_ReadAtIndex(CHNCPU_Data *data, int index, unsigned int *errFlags | ||
185 | 185 | return retv; |
186 | 186 | } |
187 | 187 | |
188 | +int CHNCPU_DATA_WriteToIndex(CHNCPU_Data *data, int index, int value, unsigned int *errFlags) | |
189 | +{ | |
190 | + if(!data || index < 0 || index >= data->count){ | |
191 | + if(errFlags){ | |
192 | + *errFlags |= CHNCPU_ERR_BAD_ACCESS; | |
193 | + } | |
194 | + return -1; | |
195 | + } | |
196 | + | |
197 | + if(data->type == CHNCPU_PType_UINT8){ | |
198 | + ((unsigned char *)data->rawData)[index] = value; | |
199 | + } else{ | |
200 | + if(errFlags){ | |
201 | + *errFlags |= CHNCPU_ERR_INVALID_PTYPE; | |
202 | + } | |
203 | + return -1; | |
204 | + } | |
205 | + | |
206 | + return index; | |
207 | +} | |
208 | + | |
188 | 209 | int CHNCPU_DATA_CalculateByteSizeOfRawData(ch4_sint dataType, ch4_uint dataCount) |
189 | 210 | { |
190 | 211 | if(dataType == CHNCPU_PType_UINT8){ |
@@ -71,7 +71,7 @@ struct _CHNCPU_OP_CACHE_CND { | ||
71 | 71 | // |
72 | 72 | // 08 LMEM |
73 | 73 | // |
74 | -// p (sint)pType (sint)pDiff rDst bitDst | |
74 | +// 08 p (sint)pType (sint)pDiff rDst bitDst | |
75 | 75 | // |
76 | 76 | typedef struct _CHNCPU_OP_CACHE_LMEM CHNCPU_OpCache_LMEM; |
77 | 77 | struct _CHNCPU_OP_CACHE_LMEM { |
@@ -83,6 +83,20 @@ struct _CHNCPU_OP_CACHE_LMEM { | ||
83 | 83 | }; |
84 | 84 | |
85 | 85 | // |
86 | +// 09 SMEM | |
87 | +// | |
88 | +// 09 rDst bitDst p (sint)pType (sint)pDiff | |
89 | +// | |
90 | +typedef struct _CHNCPU_OP_CACHE_SMEM CHNCPU_OpCache_SMEM; | |
91 | +struct _CHNCPU_OP_CACHE_SMEM { | |
92 | + ch4_uint r; | |
93 | + ch4_uint bitSrc; | |
94 | + ch4_uint p; | |
95 | + ch4_sint pType; | |
96 | + ch4_sint pDiff; | |
97 | +}; | |
98 | + | |
99 | +// | |
86 | 100 | // 10-12, 14-16, 18-1B Ternary Register Operation |
87 | 101 | // |
88 | 102 | // opCode r1 r2 r0 bit |
@@ -65,6 +65,11 @@ int CHNCPU_Op_Init(CHNCPU_OpTableSet *opSet) | ||
65 | 65 | opSet->execFuncTable[0x08] = CHNCPU_Op_LMEM_Execute; |
66 | 66 | opSet->printFuncTable[0x08] = CHNCPU_Op_LMEM_PrintCode; |
67 | 67 | |
68 | + // SMEM | |
69 | + opSet->bindFuncTable[0x09] = CHNCPU_Op_SMEM_BindOperand; | |
70 | + opSet->execFuncTable[0x09] = CHNCPU_Op_SMEM_Execute; | |
71 | + opSet->printFuncTable[0x09] = CHNCPU_Op_SMEM_PrintCode; | |
72 | + | |
68 | 73 | // TernaryRegBitwise |
69 | 74 | for(i = 0x10; i <= 0x12; i++){ |
70 | 75 | opSet->bindFuncTable[i] = CHNCPU_Op_TernaryReg_BindOperand; |
@@ -422,7 +427,7 @@ int CHNCPU_Op_LMEM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | ||
422 | 427 | return -1; |
423 | 428 | } |
424 | 429 | |
425 | - CHNCPU_AdjustValueForBit(env, &value, opCache->bitDst, CHNCPU_PREFIX_ALLOW_TRUNCATE); | |
430 | + CHNCPU_AdjustValueForBit(env, &value, opCache->bitDst, 0); | |
426 | 431 | if(env->errFlags){ |
427 | 432 | return -1; |
428 | 433 | } |
@@ -444,6 +449,73 @@ int CHNCPU_Op_LMEM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F | ||
444 | 449 | } |
445 | 450 | |
446 | 451 | // |
452 | +// 09 SMEM | |
453 | +// | |
454 | +int CHNCPU_Op_SMEM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix) | |
455 | +{ | |
456 | + CHNCPU_OpCache_SMEM *opCache; | |
457 | + | |
458 | + opCache = malloc(sizeof(CHNCPU_OpCache_SMEM)); | |
459 | + op->opCache = opCache; | |
460 | + | |
461 | + opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
462 | + opCache->bitSrc = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
463 | + opCache->p = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
464 | + opCache->pType = CH4Reader_ReadNextAsSINT(env->appbinReader); | |
465 | + opCache->pDiff = CH4Reader_ReadNextAsSINT(env->appbinReader); | |
466 | + | |
467 | + | |
468 | + if(opCache->r >= CHNCPU_NUMBER_OF_IREG || | |
469 | + opCache->p >= CHNCPU_NUMBER_OF_PREG){ | |
470 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
471 | + return -1; | |
472 | + } | |
473 | + if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bitSrc)){ | |
474 | + return -1; | |
475 | + } | |
476 | + if(prefix != 0){ | |
477 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
478 | + return -1; | |
479 | + } | |
480 | + return 0; | |
481 | +} | |
482 | +int CHNCPU_Op_SMEM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | |
483 | +{ | |
484 | + CHNCPU_OpCache_SMEM *opCache; | |
485 | + CHNCPU_PointerTag *p; | |
486 | + int value; | |
487 | + | |
488 | + opCache = op->opCache; | |
489 | + p = &env->pReg[opCache->p]; | |
490 | + | |
491 | + if(p->type != opCache->pType){ | |
492 | + env->errFlags |= CHNCPU_ERR_NOT_MATCHED_PTYPE; | |
493 | + return -1; | |
494 | + } | |
495 | + | |
496 | + value = env->iReg[opCache->r]; | |
497 | + | |
498 | + CHNCPU_AdjustValueForBit(env, &value, opCache->bitSrc, CHNCPU_PREFIX_ALLOW_TRUNCATE); | |
499 | + if(env->errFlags){ | |
500 | + return -1; | |
501 | + } | |
502 | + CHNCPU_DATA_WriteToIndex(p->data, p->pindex, value, &env->errFlags); | |
503 | + | |
504 | + p->pindex += opCache->pDiff; | |
505 | + | |
506 | + return 0; | |
507 | +} | |
508 | +int CHNCPU_Op_SMEM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file) | |
509 | +{ | |
510 | + CHNCPU_OpCache_SMEM *opCache; | |
511 | + | |
512 | + opCache = op->opCache; | |
513 | + fprintf(file, "SMEM(r:%02X, bitDst:%d, p:0x%02X, pType:0x%X, pDiff:%d);\n", opCache->r, opCache->bitSrc, opCache->p, opCache->pType, opCache->pDiff); | |
514 | + | |
515 | + return 0; | |
516 | +} | |
517 | + | |
518 | +// | |
447 | 519 | // Ternary Register Operation |
448 | 520 | // |
449 | 521 | int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix) |
@@ -5,6 +5,7 @@ c32 0 a0 c30 a0 0 | ||
5 | 5 | 1 1 0 |
6 | 6 | 88 c30 c10 1 bf a0 |
7 | 7 | 5 0 bf |
8 | +89 bf a0 c00 c10 1 | |
8 | 9 | 94 0 1 0 a0 |
9 | 10 | a2 0 c30 c20 bf a0 |
10 | 11 | 4 bf |