diff --git a/Makefile b/Makefile index 52ae7dc..e5b3e8c 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,17 @@ OBJS=emul.o emul_inst_exec.o emul_inst_decipher.o emul_reg.o emul_mem.o emul_label.o emul_io_std.o emul_opt.o -CC=gcc -lncurses PROGRAM=emul +CC=gcc +CCOPT=-lncurses + +ifeq ($(OS), Windows_NT) + # Cygwin + #CCOPT= -I/usr/include/ncurses +endif .SUFFIXES: .c .o $(PROGRAM): $(OBJS) - $(CC) -o $(PROGRAM) $^ + $(CC) -o $(PROGRAM) $^ $(CCOPT) .c.o: $(CC) -c $< diff --git a/emul.c b/emul.c index 47c9427..98bc502 100644 --- a/emul.c +++ b/emul.c @@ -1,17 +1,17 @@ #include #include "emul_inst_exec.h" -#include "emul_io_std.h" #include "emul_opt.h" -#include -#include +//#include void event_fa(char *arg) { + exitcode_t code; + emul_inst_exec_init(); emul_inst_exec_load(arg); - emul_reg_init(); - emul_inst_exec_run(); - emul_out_std("exit...\n"); - getchar(); - emul_std_end(); + code = emul_inst_exec_run(); + emul_inst_exec_end(); + if (code == Failed) { + printf("Abend exit\n"); + } } int main(int argc, char *argv[]) { diff --git a/emul_inst_exec.c b/emul_inst_exec.c index 81a8833..f1c437e 100644 --- a/emul_inst_exec.c +++ b/emul_inst_exec.c @@ -6,8 +6,6 @@ static char faild_message(); #define EXIT_MESSAGE_LENGTH 128 void emul_inst_exec_get_faild_message(char *msg); -// Private -//void emul_inst_exec_set_faild_message(); // propaty static RUNMODE RunMode; @@ -48,6 +46,9 @@ emul_std_init(); emul_reg_init(); } +void emul_inst_exec_end() { + emul_std_end(); +} int emul_inst_exec_load(char *filename) { // ロードできないなら終了 @@ -237,7 +238,7 @@ * キーボート入力を待機し,結果をレジスタへ格納する */ void emul_inst_exec_pseudo_input(int reg) { int c; - emul_out_std_debug("wait to be inputed..."); + emul_out_std_debug("wait to be inputed...\n"); while ( (c = getchar()) == '\n' ); emul_reg_set(reg, c); } @@ -328,7 +329,7 @@ emul_inst_exec_pseudo_crlf(); break; case EXIT: - emul_inst_exec_pseudo_crlf(); + emul_inst_exec_pseudo_exit(); break; default: emul_out_std_debug("[疑似コード]まだ実装してないので待って!\n"); @@ -351,9 +352,6 @@ emul_out_std_debug(">>START STEP!>>\n"); - // 読みだす命令のアドレスをPCの値とし,PCをインクリメント - //emul_inst_dec_update_pc(); - // トークンを取得 if ( emul_inst_dec_get_token(token) == 0 ) { emul_out_std_err("Non exist next token\n"); @@ -371,7 +369,7 @@ // 例外処理:疑似コードが見つからない if ( ps_id == PSEUDO_DECODE_ERROR ) { emul_out_std_err("Non exist next pseudocode\n"); - return Failed; + return Continue; } else { // 疑似コードを実行 return emul_inst_exec_pseudo(token); @@ -489,10 +487,10 @@ int exit_code; while ( (exit_code = emul_inst_exec_step()) == Success ) { if (RunMode == Step) { - puts("...Wait for step, please input key enter."); + emul_out_std("...Wait for step, please input key enter.\n"); getchar(); } else if (RunMode == Exit) { - emul_out_std_debug("Program Exit\n"); + emul_out_std_debug("Program Exit...\n"); return Success; } } diff --git a/emul_inst_exec.h b/emul_inst_exec.h index c06aff5..16e66f9 100644 --- a/emul_inst_exec.h +++ b/emul_inst_exec.h @@ -10,7 +10,8 @@ // Exit code typedef enum { Failed, - Success + Success, + Continue } exitcode_t; // ランモード @@ -25,6 +26,7 @@ RUNMODE emul_inst_exec_get_runmode(); void emul_inst_exec_init(); +void emul_inst_exec_end(); int emul_inst_exec_load(char *filename); diff --git a/emul_io_std.c b/emul_io_std.c index d268ebd..dca43ab 100644 --- a/emul_io_std.c +++ b/emul_io_std.c @@ -7,10 +7,11 @@ debug_level = level; } -WINDOW *win; +static WINDOW *win; void emul_std_init() { win = initscr(); + scrollok(win, TRUE); refresh(); } diff --git a/emul_opt.c b/emul_opt.c index c4ae373..f8cf60b 100644 --- a/emul_opt.c +++ b/emul_opt.c @@ -22,9 +22,10 @@ int digit_optind = 0; int this_option_optind = optind ? optind : 1; int option_index = 0; + int option_count = 0; while (1) { c = getopt_long(argc, argv, "f:vh", long_options, &option_index); - if (c == -1) return 0; + if (c == -1) break; switch (c) { case 0: printf("option %s", long_options[option_index].name); @@ -43,8 +44,9 @@ printf(" -h ,\t--help\t\tDisplay help\n"); break; } + option_count++; } - return 1; + return option_count; }