projects
/
YACASL2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
命令ハッシュ表周辺の調整
[YACASL2.git]
/
src
/
exec.c
diff --git
a/src/exec.c
b/src/exec.c
index
a757dfa
..
17ac66b
100644
(file)
--- a/
src/exec.c
+++ b/
src/exec.c
@@
-1,6
+1,9
@@
#include "casl2.h"
#include "exec.h"
#include "casl2.h"
#include "exec.h"
+/* 実行モード: trace, logical, dump */
+EXECMODE execmode = {false, false, false};
+
/* 標準入力から文字データを読込(SVC 1) */
void svcin()
{
/* 標準入力から文字データを読込(SVC 1) */
void svcin()
{
@@
-8,11
+11,10
@@
void svcin()
char *buffer = malloc(INSIZE + 1);
if(fgets(buffer, INSIZE, stdin) == NULL) {
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;
}
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;
if(*(buffer + i) == '\0' || *(buffer + i) == '\n') {
--i;
break;
@@
-37,12
+39,9
@@
void svcout()
setcerr(203, NULL); /* SVC output - out of Comet II memory */
return;
}
setcerr(203, NULL); /* SVC output - out of Comet II memory */
return;
}
- if((w = memory[GR[1]+i]) == '\0') {
- break;
- }
/* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */
/* それ以外の文字は、「.」で表す */
/* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */
/* それ以外の文字は、「.」で表す */
- if((
w
>= 0x20 && w <= 0x7E) || w == 0xA || w == '\t') {
+ if((
(w = memory[GR[1]+i])
>= 0x20 && w <= 0x7E) || w == 0xA || w == '\t') {
putchar((char)w);
} else {
putchar('.');
putchar((char)w);
} else {
putchar('.');
@@
-139,7
+138,7
@@
void cpl(WORD val0, WORD val1)
/* 算術演算なので、第15ビットは送り出されない */
WORD sla(WORD val0, WORD val1)
{
/* 算術演算なので、第15ビットは送り出されない */
WORD sla(WORD val0, WORD val1)
{
- WORD sign, res, last;
+ WORD sign, res, last
= 0x0
;
int i;
FR = 0x0;
int i;
FR = 0x0;
@@
-149,7
+148,7
@@
WORD sla(WORD val0, WORD val1)
last = res & 0x4000;
res <<= 1;
}
last = res & 0x4000;
res <<= 1;
}
- res = sign | (res & 0x7F);
+ res = sign | (res & 0x7F
FF
);
/* OFに、レジスタから最後に送り出されたビットの値を設定 */
if(last > 0x0) {
FR += OF;
/* OFに、レジスタから最後に送り出されたビットの値を設定 */
if(last > 0x0) {
FR += OF;
@@
-170,7
+169,7
@@
WORD sla(WORD val0, WORD val1)
/* 空いたビット位置には符号と同じものが入る */
WORD sra(WORD val0, WORD val1)
{
/* 空いたビット位置には符号と同じものが入る */
WORD sra(WORD val0, WORD val1)
{
- WORD sign, res, last;
+ WORD sign, res, last
= 0x0
;
int i;
FR = 0x0;
int i;
FR = 0x0;
@@
-202,7
+201,7
@@
WORD sra(WORD val0, WORD val1)
/* 論理左シフト。フラグを設定して値を返す */
WORD sll(WORD val0, WORD val1)
{
/* 論理左シフト。フラグを設定して値を返す */
WORD sll(WORD val0, WORD val1)
{
- WORD res = val0, last;
+ WORD res = val0, last
= 0x0
;
int i;
FR = 0x0;
int i;
FR = 0x0;
@@
-228,7
+227,7
@@
WORD sll(WORD val0, WORD val1)
/* 論理右シフト。フラグを設定して値を返す */
WORD srl(WORD val0, WORD val1)
{
/* 論理右シフト。フラグを設定して値を返す */
WORD srl(WORD val0, WORD val1)
{
- WORD res = val0, last;
+ WORD res = val0, last
= 0x0
;
int i;
FR = 0x0;
int i;
FR = 0x0;
@@
-265,15
+264,15
@@
void reset()
}
}
}
}
-/*
コード
の実行 */
+/*
仮想マシンCOMET IIで
の実行 */
void exec()
{
WORD op, r_r1, x_r2, val;
CMDTYPE cmdtype;
void exec()
{
WORD op, r_r1, x_r2, val;
CMDTYPE cmdtype;
- char *errpr = malloc(
8
);
+ char *errpr = malloc(
CERRSTRSIZE + 1
);
clock_t clock_begin, clock_end;
clock_t clock_begin, clock_end;
- if(
(&execmode)->
trace) {
+ if(
execmode.
trace) {
fprintf(stdout, "\nExecuting machine codes\n");
}
/* フラグレジスタの初期値設定 */
fprintf(stdout, "\nExecuting machine codes\n");
}
/* フラグレジスタの初期値設定 */
@@
-301,7
+300,9
@@
void exec()
sprintf(errpr, "PR:#%04X", PR);
setcerr(205, errpr); /* Stack Pointer (SP) - cannot allocate stack buffer */
}
sprintf(errpr, "PR:#%04X", PR);
setcerr(205, errpr); /* Stack Pointer (SP) - cannot allocate stack buffer */
}
+ /* 命令の取り出し */
op = memory[PR] & 0xFF00;
op = memory[PR] & 0xFF00;
+ /* 命令の解読 */
cmdtype = getcmdtype(op);
r_r1 = (memory[PR] >> 4) & 0xF;
x_r2 = memory[PR] & 0xF;
cmdtype = getcmdtype(op);
r_r1 = (memory[PR] >> 4) & 0xF;
x_r2 = memory[PR] & 0xF;
@@
-309,19
+310,19
@@
void exec()
if(cerrno > 0) {
goto execerr;
}
if(cerrno > 0) {
goto execerr;
}
- if(
(&execmode)->
trace){
+ if(
execmode.
trace){
fprintf(stdout, "#%04X: Register::::\n", PR);
dspregister();
}
fprintf(stdout, "#%04X: Register::::\n", PR);
dspregister();
}
- if(
(&execmode)->
dump){
+ if(
execmode.
dump){
fprintf(stdout, "#%04X: Memory::::\n", PR);
dumpmemory();
}
fprintf(stdout, "#%04X: Memory::::\n", PR);
dumpmemory();
}
- if(
(&execmode)->dump || (&execmode)->
trace) {
+ if(
execmode.dump || execmode.
trace) {
fprintf(stdout, "\n");
}
PR++;
fprintf(stdout, "\n");
}
PR++;
- /*
å
\87
¦ç
\90
\86
対象ã
\81
®å
\80
¤ã
\82
\92
å
\8f
\96
å¾
\97
*/
+ /*
ã
\82
ªã
\83
\9a
ã
\83
©ã
\83
³ã
\83
\89
ã
\81
®å
\8f
\96
ã
\82
\8a
å
\87
ºã
\81
\97
*/
if(cmdtype == R1_R2) {
assert(x_r2 < REGSIZE);
val = GR[x_r2];
if(cmdtype == R1_R2) {
assert(x_r2 < REGSIZE);
val = GR[x_r2];
@@
-347,7
+348,7
@@
void exec()
if(op >= 0x1000 && op <= 0x4FFF) {
op &= 0xFB00;
}
if(op >= 0x1000 && op <= 0x4FFF) {
op &= 0xFB00;
}
- /* å
\91
½ä»¤ã
\81
\94
ã
\81
¨ã
\81
®å
\87
¦ç
\90
\86
ã
\82
\92
実行 */
+ /* å
\91
½ä»¤ã
\81
®
実行 */
switch(op)
{
case 0x0: /* NOP */
switch(op)
{
case 0x0: /* NOP */
@@
-467,7
+468,9
@@
void exec()
do {
clock_end = clock();
} while(clock_end - clock_begin < CLOCKS_PER_SEC / clocks);
do {
clock_end = clock();
} while(clock_end - clock_begin < CLOCKS_PER_SEC / clocks);
-/* printf("PR:%04X; time: %f\n", PR, (double)((clock_end - clock_begin) * CLOCKS_PER_SEC)); */
+ #if 0
+ printf("PR:%04X; time: %f\n", PR, (double)((clock_end - clock_begin) * CLOCKS_PER_SEC));
+ #endif
}
execerr:
fprintf(stderr, "Execute error - %d: %s\n", cerrno, cerrmsg);
}
execerr:
fprintf(stderr, "Execute error - %d: %s\n", cerrno, cerrmsg);