• 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

Revisão1faeff8105b106b39607550f0e0249e4f8f9525d (tree)
Hora2014-06-21 22:04:55
Autorhikarupsp <hikarupsp@user...>
Commiterhikarupsp

Mensagem de Log

CALLBIOS命令を実装
デバッグ出力のon/off

Mudança Sumário

Diff

--- a/chncpu.xcodeproj/project.pbxproj
+++ b/chncpu.xcodeproj/project.pbxproj
@@ -11,6 +11,7 @@
1111 17478CFE193E2DEB00293791 /* test.hex in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17478CFD193E2ADA00293791 /* test.hex */; };
1212 17478D01193F3D0000293791 /* ch4.c in Sources */ = {isa = PBXBuildFile; fileRef = 17478D00193F3D0000293791 /* ch4.c */; };
1313 17478D041940B66700293791 /* opcode.c in Sources */ = {isa = PBXBuildFile; fileRef = 17478D031940B66700293791 /* opcode.c */; };
14+ 17F95C01194C8DA70064E1B6 /* bios.c in Sources */ = {isa = PBXBuildFile; fileRef = 17F95C00194C8DA70064E1B6 /* bios.c */; };
1415 /* End PBXBuildFile section */
1516
1617 /* Begin PBXCopyFilesBuildPhase section */
@@ -34,6 +35,7 @@
3435 17478D00193F3D0000293791 /* ch4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ch4.c; sourceTree = "<group>"; usesTabs = 1; };
3536 17478D02193F586100293791 /* ch4.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ch4.h; sourceTree = "<group>"; usesTabs = 1; };
3637 17478D031940B66700293791 /* opcode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = opcode.c; sourceTree = "<group>"; usesTabs = 1; };
38+ 17F95C00194C8DA70064E1B6 /* bios.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bios.c; sourceTree = "<group>"; };
3739 /* End PBXFileReference section */
3840
3941 /* Begin PBXFrameworksBuildPhase section */
@@ -73,6 +75,7 @@
7375 17478D02193F586100293791 /* ch4.h */,
7476 17478CFD193E2ADA00293791 /* test.hex */,
7577 17478D031940B66700293791 /* opcode.c */,
78+ 17F95C00194C8DA70064E1B6 /* bios.c */,
7679 );
7780 path = chncpu;
7881 sourceTree = "<group>";
@@ -128,6 +131,7 @@
128131 isa = PBXSourcesBuildPhase;
129132 buildActionMask = 2147483647;
130133 files = (
134+ 17F95C01194C8DA70064E1B6 /* bios.c in Sources */,
131135 17478D041940B66700293791 /* opcode.c in Sources */,
132136 17478CF4193E2A4900293791 /* chncpu.c in Sources */,
133137 17478D01193F3D0000293791 /* ch4.c in Sources */,
--- /dev/null
+++ b/chncpu/bios.c
@@ -0,0 +1,78 @@
1+//
2+// bios.c
3+// chncpu
4+//
5+// Created by 西田 耀 on 2014/06/14.
6+// Copyright (c) 2014年 CHNOSProject. All rights reserved.
7+//
8+
9+#include "chncpu.h"
10+#include <stdio.h>
11+
12+int CHNCPU_BIOS_Init(CHNCPU_RuntimeEnvironment *env)
13+{
14+ int i;
15+
16+ // FuncTables
17+ for(i = 0; i <= CHNCPU_OPECODE_MAX; i++){
18+ env->bios->bindBIOSFuncTable[i] = NULL;
19+ env->bios->execBIOSFuncTable[i] = NULL;
20+ env->bios->printBIOSFuncTable[i] = NULL;
21+ }
22+
23+ // putcReg
24+ env->bios->bindBIOSFuncTable[0x00] = CHNCPU_BIOS_Op_putcReg_BindOperand;
25+ env->bios->execBIOSFuncTable[0x00] = CHNCPU_BIOS_Op_putcReg_Execute;
26+ env->bios->printBIOSFuncTable[0x00] = CHNCPU_BIOS_Op_putcReg_PrintCode;
27+
28+ return 0;
29+
30+}
31+
32+//
33+// putcReg
34+//
35+
36+typedef struct CHNCPU_BIOS_OP_CACHE_LIMM CHNCPU_BIOS_OpCache_putcReg;
37+struct CHNCPU_BIOS_OP_CACHE_LIMM {
38+ ch4_uint r;
39+};
40+int CHNCPU_BIOS_Op_putcReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
41+{
42+ CHNCPU_BIOS_OpCache_putcReg *opCache;
43+
44+ opCache = malloc(sizeof(CHNCPU_BIOS_OpCache_putcReg));
45+ op->opCache = opCache;
46+
47+ opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader);
48+
49+ if(opCache->r >= CHNCPU_NUMBER_OF_IREG){
50+ env->errFlags |= CHNCPU_ERR_C_REGNUM;
51+ return -1;
52+ }
53+ if(prefix != 0){
54+ env->errFlags |= CHNCPU_ERR_C_PREFIX;
55+ return -1;
56+ }
57+ return 0;
58+}
59+int CHNCPU_BIOS_Op_putcReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
60+{
61+ CHNCPU_BIOS_OpCache_putcReg *opCache;
62+
63+ opCache = op->opCache;
64+
65+ putchar(env->iReg[opCache->r]);
66+
67+ return 0;
68+}
69+
70+int CHNCPU_BIOS_Op_putcReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file)
71+{
72+ CHNCPU_BIOS_OpCache_putcReg *opCache;
73+
74+ opCache = op->opCache;
75+ fprintf(file, "BIOS::putcReg(r:%d);\n", opCache->r);
76+
77+ return 0;
78+}
--- a/chncpu/chncpu.c
+++ b/chncpu/chncpu.c
@@ -62,7 +62,7 @@ int decodeHexString(char *src0, char *src1, unsigned char *dst0, unsigned char *
6262 puts("decodeHexString: not implemented.\n");
6363 exit(EXIT_FAILURE);
6464 } else{
65- if(c == ' ' || c == '\t'){
65+ if(c == ' ' || c == '\t' || c == '\n'){
6666 continue;
6767 }
6868 puts("decodeHexString: unknown character :");
@@ -127,28 +127,11 @@ CHNCPU_RuntimeEnvironment *CHNCPU_CreateRuntimeEnvironment(void)
127127
128128 env->appbinReader = malloc(sizeof(CH4Reader));
129129
130- // FuncTables
131- for(i = 0; i <= CHNCPU_OPECODE_MAX; i++){
132- env->bindOpFuncTable[i] = NULL;
133- }
134- for(i = 0; i <= CHNCPU_OPECODE_MAX; i++){
135- env->execOpFuncTable[i] = NULL;
136- }
137- for(i = 0; i <= CHNCPU_OPECODE_MAX; i++){
138- env->printOpFuncTable[i] = NULL;
139- }
140- // LIMM
141- env->bindOpFuncTable[0x02] = CHNCPU_Op_LIMM_BindOperand;
142- env->execOpFuncTable[0x02] = CHNCPU_Op_LIMM_Execute;
143- env->printOpFuncTable[0x02] = CHNCPU_Op_LIMM_PrintCode;
130+ CHNCPU_Op_Init(env);
131+
132+ env->bios = malloc(sizeof(CHNCPU_BIOS));
133+ CHNCPU_BIOS_Init(env);
144134
145- // TernaryRegBitwise
146- for(i = 0x10; i <= 0x11; i++){
147- env->bindOpFuncTable[i] = CHNCPU_Op_TernaryRegBitwise_BindOperand;
148- env->execOpFuncTable[i] = CHNCPU_Op_TernaryRegBitwise_Execute;
149- env->printOpFuncTable[i] = CHNCPU_Op_TernaryReg_PrintCode;
150- }
151-
152135 env->errFlags = 0;
153136
154137 return env;
@@ -175,8 +158,8 @@ int CHNCPU_LoadBinaryFromHexStringFilePath(CHNCPU_RuntimeEnvironment *env, const
175158 }
176159
177160 env->appbinsize = decodeHexString(tmpdata0, tmpdata0 + len, env->appbin0, env->appbin0 + CHNCPU_SIZE_APPBIN);
178- printf("appbin = %d Bytes\n", env->appbinsize);
179- CHNCPU_DumpAppBin(env);
161+ //printf("appbin = %d Bytes\n", env->appbinsize);
162+ //CHNCPU_DumpAppBin(env);
180163
181164 CH4Reader_Initialize(env->appbinReader, env->appbin0, env->appbinsize);
182165
@@ -187,71 +170,54 @@ int CHNCPU_LoadBinaryFromHexStringFilePath(CHNCPU_RuntimeEnvironment *env, const
187170
188171 int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env)
189172 {
190- ch4_uint opcode;
173+ ch4_uint opcode = 0;
191174 int mindex;
192175 CHNCPU_OpTag *op;
193- int breakFlag = 0;
194- int retv;
195176 unsigned int prefix = 0;
196177
197178 // env->appbinReaderから読み込んで、実行可能な状態にする。
198179 // これはコンパイラ版におけるコンパイルに相当する。
199- printf("< Beginning of binary > \n");
180+ //printf("< Beginning of binary > \n");
200181 mindex = 0;
201182 for(mindex = 0; mindex < CHNCPU_LENGTH_OF_MAIN_MEMORY; mindex++){
202183 opcode = CH4Reader_ReadNextAsUINT(env->appbinReader);
203184 if(CH4Reader_IsEndOfBinary(env->appbinReader)){
204- puts("< End of binary >");
205- breakFlag = 1;
206185 break;
207186 }
208- printf("(%02X) ", opcode);
187+ //printf("(%02X) ", opcode);
209188
210189 op = &env->mainmemory[mindex];
211190 op->opCode = opcode;
212191 switch(opcode){
213192 case 0x00:
214193 // NOP
215- puts("NOP();\n");
216- // メモリには追加しない
217- mindex--;
194+ mindex--; // メモリには追加しない
218195 break;
219196 case 0x2F:
220197 // Prefix
221198 opcode = CH4Reader_ReadNextAsUINT(env->appbinReader);
222- printf("Prefix-%X\n", opcode);
199+ //printf("Prefix-%X\n", opcode);
223200 if(opcode > CHNCPU_PREFIX_MAX){
224201 env->errFlags |= CHNCPU_ERR_C_PREFIX;
225- breakFlag = 1;
226202 break;
227203 }
228204 prefix |= (0x01 << opcode);
229- // メモリには追加しない
230- mindex--;
205+ mindex--; // メモリには追加しない
231206 break;
232207 default:
233208 // ごく一部の特殊な命令以外は、命令テーブルを参照する
234209 if(opcode <= CHNCPU_OPECODE_MAX && env->bindOpFuncTable[opcode]){
235- retv = env->bindOpFuncTable[opcode](env, op, prefix);
236- if(retv){
237- opcode = CHNCPU_OPCODE_INVALID;
238- }
210+ env->bindOpFuncTable[opcode](env, op, prefix);
239211 } else{
240- opcode = CHNCPU_OPCODE_INVALID;
241212 env->errFlags |= CHNCPU_ERR_C_OPCODE;
242213 }
243- if(opcode == CHNCPU_OPCODE_INVALID){
244- op->opCode = CHNCPU_OPCODE_INVALID;
245- breakFlag = 1;
246- }
247214 prefix = 0;
248215 break;
249216 }
250217 if(env->appbinReader->errorFlags){
251218 env->errFlags |= CHNCPU_ERR_C_INVALID_BIN;
252- break;
253219 }
254- if(breakFlag == 1){
220+ if(env->errFlags){
255221 break;
256222 }
257223 }
@@ -267,7 +233,7 @@ int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env)
267233 puts("INVALID-C: Not supported bit width.");
268234 }
269235 if(env->errFlags & CHNCPU_ERR_C_OPCODE){
270- puts("INVALID-C: Unknown opCode.");
236+ printf("INVALID-C: Unknown opCode 0x%X\n", opcode);
271237 }
272238 if(env->errFlags & CHNCPU_ERR_C_EXPRESSION){
273239 puts("INVALID-C: Invalid expression.");
@@ -285,32 +251,37 @@ int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env)
285251 int CHNCPU_Execute(CHNCPU_RuntimeEnvironment *env)
286252 {
287253 int count = 0;
288- int retv;
289254 CHNCPU_OpTag *op;
290255
291256 if(env->errFlags){
292257 puts(">>> Can't execute binary because of there is some error.");
293258 }
294259
295- puts("< Beginning of execution >");
260+ //puts("< Beginning of execution >");
296261 for(; env->currentIndex < CHNCPU_LENGTH_OF_MAIN_MEMORY; env->currentIndex++){
297262 op = &env->mainmemory[env->currentIndex];
298263 if(op->opCode == CHNCPU_OPCODE_INVALID){
299264 // End of Binary
300265 break;
301266 }
302- if(op->opCode <= CHNCPU_OPECODE_MAX && env->bindOpFuncTable[op->opCode]){
303- retv = env->execOpFuncTable[op->opCode](env, op);
267+#if DEBUG_PRINT_OP_EXECUTING
268+ if(op->opCode <= CHNCPU_OPECODE_MAX && env->printOpFuncTable[op->opCode]){
269+ env->printOpFuncTable[op->opCode](env, op, stdout);
270+ } else{
271+ printf("Unknown op: 0x%X", op->opCode);
272+ }
273+#endif
274+
275+ if(op->opCode <= CHNCPU_OPECODE_MAX && env->execOpFuncTable[op->opCode]){
276+ if(env->execOpFuncTable[op->opCode](env, op)){
277+ // 命令実行時にエラーが発生
278+ break;
279+ }
304280 } else{
305281 // ロード時にチェックしたはずなのに不明な命令が来た
306282 env->errFlags |= CHNCPU_ERR_X_INTERNAL;
307283 break;
308284 }
309- if(retv){
310- // 命令実行時にエラーが発生
311- break;
312- }
313-
314285 }
315286 if(env->errFlags){
316287 if(env->errFlags & CHNCPU_ERR_X_INTERNAL){
@@ -321,9 +292,11 @@ int CHNCPU_Execute(CHNCPU_RuntimeEnvironment *env)
321292 }
322293 }
323294
295+#if DEBUG_PRINT_IREG_AFTER_EXECUTION
296+ puts("\n>>> End of execution");
324297 CHNCPU_DumpIReg(env);
298+#endif
325299
326- puts("< End of execution >");
327300
328301 return count;
329302 }
--- a/chncpu/chncpu.h
+++ b/chncpu/chncpu.h
@@ -13,9 +13,16 @@
1313 #include <stdlib.h>
1414 #include "ch4.h"
1515
16+// DEBUG Flag
17+#define DEBUG_PRINT_IREG_AFTER_EXECUTION 1
18+#define DEBUG_PRINT_OP_BINDING 1
19+#define DEBUG_PRINT_OP_EXECUTING 1
20+
21+// Settings
1622 #define SIZE_TMPDATA (1024 * 1024 * 1)
1723
1824 #define CHNCPU_OPECODE_MAX 0xFF
25+#define CHNCPU_BIOS_OP_MAX 0x00
1926 #define CHNCPU_BITS_MAX 32
2027 #define CHNCPU_NUMBER_OF_IREG 64
2128 #define CHNCPU_LENGTH_OF_MAIN_MEMORY (64 * 1024) // per Op
@@ -42,16 +49,24 @@
4249 #define CHNCPU_PREFIX_MASK_Op_TernaryRegBitwise (CHNCPU_PREFIX_ALLOW_TRUNCATE)
4350
4451 typedef struct CHNCPU_OP_TAG CHNCPU_OpTag;
52+typedef struct CHNCPU_RUN_TIME_ENVIRONMENT CHNCPU_RuntimeEnvironment;
53+typedef struct _CHNCPU_BIOS CHNCPU_BIOS;
54+
4555 struct CHNCPU_OP_TAG {
4656 int opCode;
4757 void *opCache;
4858 };
4959
50-typedef struct CHNCPU_RUN_TIME_ENVIRONMENT CHNCPU_RuntimeEnvironment;
60+struct _CHNCPU_BIOS {
61+ int (*bindBIOSFuncTable[CHNCPU_BIOS_OP_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
62+ int (*execBIOSFuncTable[CHNCPU_BIOS_OP_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
63+ int (*printBIOSFuncTable[CHNCPU_BIOS_OP_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
64+};
65+
5166 struct CHNCPU_RUN_TIME_ENVIRONMENT {
52- int (*bindOpFuncTable[CHNCPU_OPECODE_MAX])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
53- int (*execOpFuncTable[CHNCPU_OPECODE_MAX])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
54- int (*printOpFuncTable[CHNCPU_OPECODE_MAX])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
67+ int (*bindOpFuncTable[CHNCPU_OPECODE_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
68+ int (*execOpFuncTable[CHNCPU_OPECODE_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
69+ int (*printOpFuncTable[CHNCPU_OPECODE_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
5570 int iReg[CHNCPU_NUMBER_OF_IREG];
5671 int iRegBits[CHNCPU_NUMBER_OF_IREG];
5772 CHNCPU_OpTag mainmemory[CHNCPU_LENGTH_OF_MAIN_MEMORY];
@@ -60,6 +75,7 @@ struct CHNCPU_RUN_TIME_ENVIRONMENT {
6075 CH4Reader *appbinReader;
6176 unsigned int errFlags;
6277 int currentIndex;
78+ CHNCPU_BIOS *bios;
6379 };
6480
6581 // @chncpu.c
@@ -73,10 +89,20 @@ void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env);
7389 int CHNCPU_CHK_IsAvailableBits(CHNCPU_RuntimeEnvironment *env, ch4_uint bits);
7490
7591 // @opcode.c
92+int CHNCPU_Op_Init(CHNCPU_RuntimeEnvironment *env);
7693 int CHNCPU_Op_LIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
7794 int CHNCPU_Op_LIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
7895 int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
96+int CHNCPU_Op_CALLBIOS_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
97+int CHNCPU_Op_CALLBIOS_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
98+int CHNCPU_Op_CALLBIOS_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
7999 int CHNCPU_Op_TernaryRegBitwise_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
80100 int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
81101 int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
102+
103+// @bios.c
104+int CHNCPU_BIOS_Init(CHNCPU_RuntimeEnvironment *env);
105+int CHNCPU_BIOS_Op_putcReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
106+int CHNCPU_BIOS_Op_putcReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
107+int CHNCPU_BIOS_Op_putcReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
82108 #endif
--- a/chncpu/opcode.c
+++ b/chncpu/opcode.c
@@ -8,6 +8,37 @@
88
99 #include "chncpu.h"
1010
11+int CHNCPU_Op_Init(CHNCPU_RuntimeEnvironment *env)
12+{
13+ int i;
14+
15+ // FuncTables
16+ for(i = 0; i <= CHNCPU_OPECODE_MAX; i++){
17+ env->bindOpFuncTable[i] = NULL;
18+ env->execOpFuncTable[i] = NULL;
19+ env->printOpFuncTable[i] = NULL;
20+ }
21+
22+ // LIMM
23+ env->bindOpFuncTable[0x02] = CHNCPU_Op_LIMM_BindOperand;
24+ env->execOpFuncTable[0x02] = CHNCPU_Op_LIMM_Execute;
25+ env->printOpFuncTable[0x02] = CHNCPU_Op_LIMM_PrintCode;
26+
27+ // CALLBIOS
28+ env->bindOpFuncTable[0x05] = CHNCPU_Op_CALLBIOS_BindOperand;
29+ env->execOpFuncTable[0x05] = CHNCPU_Op_CALLBIOS_Execute;
30+ env->printOpFuncTable[0x05] = CHNCPU_Op_CALLBIOS_PrintCode;
31+
32+ // TernaryRegBitwise
33+ for(i = 0x10; i <= 0x11; i++){
34+ env->bindOpFuncTable[i] = CHNCPU_Op_TernaryRegBitwise_BindOperand;
35+ env->execOpFuncTable[i] = CHNCPU_Op_TernaryRegBitwise_Execute;
36+ env->printOpFuncTable[i] = CHNCPU_Op_TernaryReg_PrintCode;
37+ }
38+
39+ return 0;
40+}
41+
1142 //
1243 // 02 LIMM
1344 //
@@ -29,8 +60,6 @@ int CHNCPU_Op_LIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op,
2960 opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader);
3061 opCache->bit = CH4Reader_ReadNextAsUINT(env->appbinReader);
3162
32- CHNCPU_Op_LIMM_PrintCode(env, op, stdout);
33-
3463 if(opCache->r >= CHNCPU_NUMBER_OF_IREG){
3564 env->errFlags |= CHNCPU_ERR_C_REGNUM;
3665 return -1;
@@ -54,8 +83,6 @@ int CHNCPU_Op_LIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
5483
5584 opCache = op->opCache;
5685
57- CHNCPU_Op_LIMM_PrintCode(env, op, stdout);
58-
5986 env->iReg[opCache->r] = opCache->imm & (0xFFFFFFFF >> (32 - opCache->bit));
6087 env->iRegBits[opCache->r] = opCache->bit;
6188
@@ -73,6 +100,69 @@ int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F
73100 }
74101
75102 //
103+// 05 CALLBIOS
104+//
105+int CHNCPU_Op_CALLBIOS_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
106+{
107+ ch4_uint fid;
108+
109+ CHNCPU_OpTag *opCache;
110+
111+ opCache = malloc(sizeof(CHNCPU_OpTag));
112+ op->opCache = opCache;
113+
114+ opCache->opCode = CH4Reader_ReadNextAsUINT(env->appbinReader);
115+
116+ fid = opCache->opCode;
117+ if(fid <= CHNCPU_BIOS_OP_MAX && env->bios->bindBIOSFuncTable[fid]){
118+ env->bios->bindBIOSFuncTable[fid](env, opCache, prefix);
119+ } else{
120+ env->errFlags |= CHNCPU_ERR_C_OPCODE;
121+ }
122+
123+ if(env->errFlags){
124+ return -1;
125+ }
126+ return 0;
127+}
128+int CHNCPU_Op_CALLBIOS_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op)
129+{
130+ CHNCPU_OpTag *opCache;
131+ ch4_uint fid;
132+
133+ opCache = op->opCache;
134+
135+ fid = opCache->opCode;
136+ if(fid <= CHNCPU_BIOS_OP_MAX && env->bios->execBIOSFuncTable[fid]){
137+ env->bios->execBIOSFuncTable[fid](env, opCache);
138+ } else{
139+ // ロード時にチェックしたはずなのに不明な命令が来た
140+ env->errFlags |= CHNCPU_ERR_X_INTERNAL;
141+ }
142+
143+ return 0;
144+}
145+
146+int CHNCPU_Op_CALLBIOS_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file)
147+{
148+ CHNCPU_OpTag *opCache;
149+ ch4_uint fid;
150+
151+ opCache = op->opCache;
152+
153+ fid = opCache->opCode;
154+ if(fid <= CHNCPU_BIOS_OP_MAX && env->bios->printBIOSFuncTable[fid]){
155+ env->bios->printBIOSFuncTable[fid](env, opCache, stdout);
156+ } else{
157+ fprintf(file, "CALLBIOS(func:0x%X);\n", fid);
158+ }
159+
160+ return 0;
161+}
162+
163+
164+
165+//
76166 // Ternary Register Operation
77167 //
78168
@@ -101,9 +191,7 @@ int CHNCPU_Op_TernaryRegBitwise_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNC
101191 opCache->r0 = CH4Reader_ReadNextAsUINT(env->appbinReader);
102192 opCache->bit = CH4Reader_ReadNextAsUINT(env->appbinReader);
103193 opCache->prefix = prefix;
104-
105- CHNCPU_Op_TernaryReg_PrintCode(env, op, stdout);
106-
194+
107195 if(opCache->r0 >= CHNCPU_NUMBER_OF_IREG ||
108196 opCache->r1 >= CHNCPU_NUMBER_OF_IREG ||
109197 opCache->r2 >= CHNCPU_NUMBER_OF_IREG){
@@ -127,9 +215,7 @@ int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_O
127215
128216 opCache = op->opCache;
129217 opCode = op->opCode;
130-
131- CHNCPU_Op_TernaryReg_PrintCode(env, op, stdout);
132-
218+
133219 if(opCode == 0x10){
134220 if(opCache->r1 == opCache->r2){
135221 // CP
--- a/chncpu/test.hex
+++ b/chncpu/test.hex
@@ -1 +1 @@
1-2 E123 0 90 2 E365 1 90 91 0 1 2 90
\ No newline at end of file
1+2 c41 0 90 5 0 0