+#include "cerr.h"
+
+/**
+ * 実行エラーの定義
+ */
+static CERR cerr_exec[] = {
+ { 201, "Program Register (PR) - memory overflow" },
+ { 202, "Stack Pointer (SP) - stack overflow" },
+ { 203, "Stack Pointer (SP) - stack underflow" },
+ { 204, "OP in word #1 - not command code" },
+ { 205, "r/r1 in word #1 - not GR" },
+ { 206, "x/r2 in word #1 - not GR" },
+ { 207, "address in word #2 - out of memory" },
+ { 208, "SVC input - memory overflow" },
+ { 209, "SVC output - memory overflow" },
+};
+
+/**
+ * アセンブル結果読み込みエラーの定義
+ */
+static CERR cerr_load[] = {
+ { 210, "load - memory overflow" },
+ { 211, "object file not specified" },
+};
+
+/**
+ * 実行モード: trace, logical, dump
+ */
+EXECMODE execmode = {false, false, false};
+
+/**
+ * アセンブル結果読み込みエラーをエラーリストに追加
+ */
+void addcerrlist_load()
+{
+ addcerrlist(ARRAYSIZE(cerr_load), cerr_load);
+}
+
+/**
+ * 実行エラーをエラーリストに追加
+ */
+void addcerrlist_exec()
+{
+ addcerrlist(ARRAYSIZE(cerr_exec), cerr_exec);
+}
+/**
+ * 指定されたファイルからアセンブル結果を読み込む
+ */
+bool loadassemble(const char *file)
+{
+ FILE *fp;
+ bool stat = true;
+
+ assert(file != NULL);
+ if((fp = fopen(file, "r")) == NULL) {
+ perror(file);
+ return false;
+ }
+ execptr->end = execptr->start +
+ fread(sys->memory, sizeof(WORD), sys->memsize - execptr->start, fp);
+ if(execptr->end == sys->memsize) {
+ setcerr(210, file); /* load - memory overflow */
+ fprintf(stderr, "Load error - %d: %s\n", cerr->num, cerr->msg);
+ stat = false;
+ }
+ fclose(fp);
+ return stat;
+}
+
+/**
+ * プログラムレジスタ(PR)を表す文字列を返す
+ **/
+char *pr2str(WORD pr) {
+ char *str = malloc_chk(CERRSTRSIZE + 1, "pr2str.pr");
+
+ sprintf(str, "PR:#%04X", pr);
+ return str;
+}