X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fexec.c;h=9f01dbd9f8201278bff8d4e0976085d13f766c90;hb=e0de529cf2de73a298288fd294b24b964abdba34;hp=ec9687f4db22a2cd0ee43336367f67ed61eb3d6a;hpb=dbba1efb7f290dec54755c26baa05e263459560d;p=YACASL2.git diff --git a/src/exec.c b/src/exec.c index ec9687f..9f01dbd 100644 --- a/src/exec.c +++ b/src/exec.c @@ -1,6 +1,9 @@ #include "casl2.h" #include "exec.h" +/* 実行モード: trace, logical, dump */ +EXECMODE execmode = {false, false, false}; + /* 標準入力から文字データを読込(SVC 1) */ void svcin() { @@ -8,11 +11,10 @@ void svcin() char *buffer = malloc(INSIZE + 1); if(fgets(buffer, INSIZE, stdin) == NULL) { - memory[GR[1]] = 0x0; - memory[GR[2]] = 0x0; + memory[GR[1]] = memory[GR[2]] = 0x0; return; } - for(i = 0; i < GR[1] && i < INSIZE; i++) { + for(i = 0; i < INSIZE; i++) { if(*(buffer + i) == '\0' || *(buffer + i) == '\n') { --i; break; @@ -30,20 +32,17 @@ void svcin() void svcout() { int i; - char c; + WORD w; - for(i = 0; i < GR[2]; i++) { + for(i = 0; i < memory[GR[2]]; i++) { if(GR[1] + i >= memsize - 1) { setcerr(203, NULL); /* SVC output - out of Comet II memory */ return; } - if(memory[GR[1]+i] == '\0') { - break; - } /* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */ /* それ以外の文字は、「.」で表す */ - if(((c = (char)(memory[GR[1]+i])) >= 0x20 && c <= 0x7E) || c == 0xA || c == '\t') { - putchar(c); + if(((w = memory[GR[1]+i]) >= 0x20 && w <= 0x7E) || w == 0xA || w == '\t') { + putchar((char)w); } else { putchar('.'); } @@ -139,7 +138,7 @@ void cpl(WORD val0, WORD val1) /* 算術演算なので、第15ビットは送り出されない */ WORD sla(WORD val0, WORD val1) { - WORD sign, res, last; + WORD sign, res, last = 0x0; int i; FR = 0x0; @@ -149,7 +148,7 @@ WORD sla(WORD val0, WORD val1) last = res & 0x4000; res <<= 1; } - res = sign | res; + res = sign | (res & 0x7FFF); /* OFに、レジスタから最後に送り出されたビットの値を設定 */ if(last > 0x0) { FR += OF; @@ -170,7 +169,7 @@ WORD sla(WORD val0, WORD val1) /* 空いたビット位置には符号と同じものが入る */ WORD sra(WORD val0, WORD val1) { - WORD sign, res, last; + WORD sign, res, last = 0x0; int i; FR = 0x0; @@ -202,7 +201,7 @@ WORD sra(WORD val0, WORD val1) /* 論理左シフト。フラグを設定して値を返す */ WORD sll(WORD val0, WORD val1) { - WORD res = val0, last; + WORD res = val0, last = 0x0; int i; FR = 0x0; @@ -228,7 +227,7 @@ WORD sll(WORD val0, WORD val1) /* 論理右シフト。フラグを設定して値を返す */ WORD srl(WORD val0, WORD val1) { - WORD res = val0, last; + WORD res = val0, last = 0x0; int i; FR = 0x0; @@ -273,7 +272,7 @@ void exec() char *errpr = malloc(8); clock_t clock_begin, clock_end; - if((&execmode)->tracemode) { + if((&execmode)->trace) { fprintf(stdout, "\nExecuting machine codes\n"); } /* フラグレジスタの初期値設定 */ @@ -309,15 +308,15 @@ void exec() if(cerrno > 0) { goto execerr; } - if((&execmode)->tracemode){ + if((&execmode)->trace){ fprintf(stdout, "#%04X: Register::::\n", PR); dspregister(); } - if((&execmode)->dumpmode){ + if((&execmode)->dump){ fprintf(stdout, "#%04X: Memory::::\n", PR); dumpmemory(); } - if((&execmode)->dumpmode || (&execmode)->tracemode) { + if((&execmode)->dump || (&execmode)->trace) { fprintf(stdout, "\n"); } PR++;