X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fassemble.c;h=b9fbed7133218e630879000964515f85cfec536f;hp=40c3704cc5d32e4e8c75b19a5f4df051447b0ec5;hb=04a3118439bbcea335da98764406256d10be78f5;hpb=ffe8e22a52a385d795889c5cabbde2f277342e32 diff --git a/src/assemble.c b/src/assemble.c index 40c3704..b9fbed7 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -10,20 +10,21 @@ WORD lptr; /* 他のプログラムで参照する入口名 */ char *prog; -/* 汎用レジスタを表す文字列「GR[0-7]」をWORD値に変換 */ -/* is_xがtrueの場合は、指標レジスタとして用いる汎用レジスタ */ +/* 汎用レジスタを表す文字列「GR[0-7]」から、レジスタ番号[0-7]をWORD値で返す */ /* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */ +/* is_xがtrueの場合は指標レジスタ。GR0は、COMET IIの仕様により、エラー発生 */ WORD getgr(const char *str, bool is_x) { assert(str != NULL); WORD r; + /* 「GR[0-7]」以外の文字列では、0xFFFFを返して終了 */ if(!(strlen(str) == 3 && strncmp(str, "GR", 2) == 0 && (*(str+2) >= '0' && *(str+2) <= '7'))) { return 0xFFFF; } r = (WORD)(*(str+2) - '0'); - /* COMET IIの仕様により、GR0は指標レジスタとして用いることはできない */ + /* 指標レジスタとして用いることはできない */ if(is_x == true && r == 0x0) { setcerr(120, NULL); /* GR0 in operand x */ return 0x0; @@ -61,7 +62,7 @@ bool writememory(WORD word, WORD adr, PASS pass) } if(cerrno == 0) { memory[adr] = word; - if(pass == SECOND && (&asmode)->asdetailmode == true) { + if(pass == SECOND && (&asmode)->asdetail == true) { fprintf(stdout, "\t#%04X\t#%04X\n", adr, word); } status = true; @@ -97,8 +98,7 @@ void writestr(const char *str, bool literal, PASS pass) setcerr(123, str); /* illegal string */ break; } - /* 「'」の場合 */ - /* 次の文字が「'」でない場合は正常終了 */ + /* 「'」の場合、次の文字が「'」でない場合は正常終了 */ if(*p == '\'' && *(++p) != '\'') { break; } else if(literal == true && lw == true) { @@ -314,6 +314,7 @@ bool cometcmd(const CMDLINE *cmdl, PASS pass) /* オペランド数3 */ if(cmdl->opd->opdc == 3) { if((x = getgr(cmdl->opd->opdv[2], true)) == 0xFFFF) { + setcerr(125, cmdl->cmd); /* not GR in operand x */ return false; } cmd |= x; @@ -394,6 +395,10 @@ bool assembleline(const CMDLINE *cmdl, PASS pass) return status; } +void printline(FILE *stream, const char *filename, int lineno, char *line) { + fprintf(stream, "%s:%5d:%s", filename, lineno, line); +} + /* 指定された名前のファイルをアセンブル */ /* 2回実行される */ bool assemble(const char *file, PASS pass) @@ -418,10 +423,10 @@ bool assemble(const char *file, PASS pass) break; } lineno++; - if((pass == FIRST && (&asmode)->srcmode == true) || - (pass == SECOND && (&asmode)->asdetailmode == true)) + if((pass == FIRST && (&asmode)->src == true) || + (pass == SECOND && (&asmode)->asdetail == true)) { - fprintf(stdout, "%s:%5d:%s", file, lineno, line); + printline(stdout, file, lineno, line); } if((cmdl = linetok(line)) != NULL) { if(pass == FIRST && cmdl->label != NULL) { @@ -438,7 +443,8 @@ bool assemble(const char *file, PASS pass) } } if(cerrno > 0) { - fprintf(stderr, "Assemble error - %d: %s\n %s:%d: %s\n", cerrno, cerrmsg, file, lineno, line); + fprintf(stderr, "Assemble error - %d: %s\n", cerrno, cerrmsg); + printline(stderr, file, lineno, line); status = false; } fclose(fp);