*/
void writememory(WORD word, WORD adr, PASS pass)
{
+ char *n;
+
/* メモリオーバーの場合、エラー発生 */
if(adr >= sys->memsize) {
- setcerr(119, word2n(adr)); /* out of COMET II memory */
+ setcerr(119, (n = word2n(adr))); /* out of COMET II memory */
+ FREE(n)
return;
}
(sys->memory)[adr] = word;
#include <stdio.h>
+
#include "exec.h"
+#include "cmem.h"
/**
* COMET IIのメモリを表示する
void dspregister()
{
int i;
+ char *sp, *pr, *fr;
for(i = 0; i < GRSIZE; i++ ) {
fprintf(stdout, "#%04X: GR%d: ", sys->cpu->pr, i);
print_dumpword(sys->cpu->gr[i], (&execmode)->logical);
}
fprintf(stdout, "#%04X: SP: %6d = #%04X = %s\n",
- sys->cpu->pr, sys->cpu->sp, sys->cpu->sp, word2bit(sys->cpu->sp));
+ sys->cpu->pr, sys->cpu->sp, sys->cpu->sp, sp = word2bit(sys->cpu->sp));
fprintf(stdout, "#%04X: PR: %6d = #%04X = %s\n",
- sys->cpu->pr, sys->cpu->pr, sys->cpu->pr, word2bit(sys->cpu->pr));
+ sys->cpu->pr, sys->cpu->pr, sys->cpu->pr, pr = word2bit(sys->cpu->pr));
fprintf(stdout, "#%04X: FR (OF SF ZF): %s\n",
- sys->cpu->pr, (word2bit(sys->cpu->fr)+13));
+ sys->cpu->pr, ((fr = word2bit(sys->cpu->fr)) + 13));
+
+ FREE(sp);
+ FREE(pr);
+ FREE(fr);
}
WORD get_r_r1(WORD oprx)
{
WORD r;
+ char *s;
+
if((r = ((oprx & 0x00F0) >>4)) > GRSIZE - 1) {
- setcerr(205, pr2str(sys->cpu->pr)); /* r/r1 in word #1 - not GR */
+ setcerr(205, s = pr2str(sys->cpu->pr)); /* r/r1 in word #1 - not GR */
+ FREE(s);
return 0x0;
}
return r;
WORD get_x_r2(WORD oprx)
{
WORD x;
+ char *s;
+
if((x = (oprx & 0x000F)) > GRSIZE - 1) {
- setcerr(206, pr2str(sys->cpu->pr)); /* r/r1 in word #1 - not GR */
+ setcerr(206, s = pr2str(sys->cpu->pr)); /* r/r1 in word #1 - not GR */
+ FREE(s);
return 0x0;
}
return x;
WORD get_val_adr_x(WORD adr, WORD oprx)
{
WORD a;
+ char *s;
+
if((a = get_adr_x(adr, oprx)) >= sys->memsize) {
- setcerr(207, pr2str(sys->cpu->pr + 1)); /* address in word #2 - out of memory */
+ setcerr(207, s = pr2str(sys->cpu->pr + 1)); /* address in word #2 - out of memory */
+ FREE(s);
return 0x0;
}
return sys->memory[a];
*/
void push()
{
+ assert(sys->cpu->sp > execptr->end && sys->cpu->sp <= sys->memsize);
WORD w[2];
+
w[0] = sys->memory[sys->cpu->pr];
w[1] = sys->memory[sys->cpu->pr + 1];
- assert(sys->cpu->sp > execptr->end && sys->cpu->sp <= sys->memsize);
sys->memory[--(sys->cpu->sp)] = get_adr_x(w[1], w[0]);
sys->cpu->pr += 2;
}
*/
void pop()
{
- assert(sys->cpu->sp > execptr->end && sys->cpu->sp <= sys->memsize);
- WORD w[1];
- w[0] = sys->memory[sys->cpu->pr];
- sys->cpu->gr[get_r_r1(w[0])] = sys->memory[(sys->cpu->sp)++];
- sys->cpu->pr += 1;
+ assert(sys->cpu->sp > execptr->end);
+ WORD w;
+ char *s;
+
+ if(sys->cpu->sp >= sys->memsize) {
+ setcerr(203, s = pr2str(sys->cpu->pr)); /* Stack Pointer (SP) - stack underflow */
+ FREE(s);
+ } else {
+ w = sys->memory[sys->cpu->pr];
+ sys->cpu->gr[get_r_r1(w)] = sys->memory[(sys->cpu->sp)++];
+ sys->cpu->pr += 1;
+ }
}
/**
{
clock_t clock_begin, clock_end;
void (*cmdptr)();
+ char *s;
create_code_type(); /* 命令のコードとタイプがキーのハッシュ表を作成 */
if(execmode.trace == true) {
}
fprintf(stdout, "\n");
}
- /* プログラムレジスタとスタックポインタをチェック */
- if(sys->cpu->pr >= sys->memsize || sys->cpu->sp > sys->memsize || sys->cpu->sp <= execptr->end) {
- if(sys->cpu->pr >= sys->memsize) {
- setcerr(201, pr2str(sys->cpu->pr)); /* Program Register (PR) - memory overflow */
- } else if(sys->cpu->sp <= execptr->end) {
- setcerr(202, pr2str(sys->cpu->pr)); /* Stack Pointer (SP) - stack overflow */
- } else if(sys->cpu->sp > sys->memsize) {
- setcerr(203, pr2str(sys->cpu->pr)); /* Stack Pointer (SP) - stack underflow */
- }
+ /* プログラムレジスタをチェック */
+ if(sys->cpu->pr >= sys->memsize) {
+ setcerr(201, s = pr2str(sys->cpu->pr)); /* Program Register (PR) - memory overflow */
+ FREE(s);
+ goto execfin;
+ }
+ /* スタックポインタをチェック */
+ if(sys->cpu->sp <= execptr->end) {
+ setcerr(202, s = pr2str(sys->cpu->pr)); /* Stack Pointer (SP) - stack overflow */
+ FREE(s);
goto execfin;
}
/* コードから命令を取得 */
/* 取得できない場合はエラー終了 */
if((cmdptr = getcmdptr(sys->memory[sys->cpu->pr] & 0xFF00)) == NULL) {
- setcerr(204, pr2str(sys->cpu->pr)); /* OP in word #1 - not command code */
+ setcerr(204, s = pr2str(sys->cpu->pr)); /* OP in word #1 - not command code */
+ FREE(s);
goto execfin;
}
/* 命令の実行 */
fprintf(stdout, "%s.", l[i]->prog);
}
fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr);
+ FREE(l[i]->prog);
+ FREE(l[i]->label);
+ FREE(l[i]);
}
FREE(l);
}
/* 文字列が長すぎる場合はエラー */
if(strlen(p) > LABELSIZE) {
setcerr(104, p); /* label length is too long */
+ } else {
+ strcpy(cmdl->label, p);
}
- strcpy(cmdl->label, p);
p = sepp + 1;
}
/* ラベルと命令の間の空白をスキップ */
*/
void print_dumpword(WORD word, bool logicalmode)
{
+ char *b;
+
if(logicalmode == true) {
fprintf(stdout, "%6d", word);
} else {
fprintf(stdout, "%6d", (signed short)word);
}
- fprintf(stdout, " = #%04X = %s", word, word2bit(word));
+ fprintf(stdout, " = #%04X = %s", word, (b = word2bit(word)));
/* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */
if(word >= 0x20 && word <= 0x7E) {
fprintf(stdout, " = \'%c\'", word);
fprintf(stdout, " = \'\\t\'");
}
fprintf(stdout, "\n");
+ FREE(b);
}
POP GR1
RET
END
-Execute error - 203: PR:#0001: Stack Pointer (SP) - stack underflow
+Execute error - 203: PR:#0000: Stack Pointer (SP) - stack underflow
-Execute error - 203: PR:#0001: Stack Pointer (SP) - stack underflow
+Execute error - 203: PR:#0000: Stack Pointer (SP) - stack underflow