diff --git a/Makefile b/Makefile index 1b8cd42..3b57c67 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ OBJS=emul.o emul_inst_exec.o emul_inst_decipher.o emul_reg.o emul_mem.o emul_label.o emul_io_std.o -CC=gcc +CC=gcc -lncurses PROGRAM=emul .SUFFIXES: .c .o diff --git a/emul.c b/emul.c index 770a428..1a36177 100644 --- a/emul.c +++ b/emul.c @@ -1,12 +1,17 @@ +#include #include "emul_inst_exec.h" #include "emul_io_std.h" int main(int argc, char *argv[]) { //emul_std_debug(2); if (argc == 1) { - emul_out_std("[Error] No input file!\n"); + printf("[Error] No input file!\n"); + return 0; } emul_inst_exec_load(argv[1]); - emul_reg_init(); + emul_inst_exec_init(); emul_inst_exec_run(); + emul_out_std("exit...\n"); + getchar(); + emul_std_end(); } diff --git a/emul_inst_exec.c b/emul_inst_exec.c index 4e440c8..81a8833 100644 --- a/emul_inst_exec.c +++ b/emul_inst_exec.c @@ -44,6 +44,11 @@ emul_inst_exec_load_label(); } +void emul_inst_exec_init() { + emul_std_init(); + emul_reg_init(); +} + int emul_inst_exec_load(char *filename) { // ロードできないなら終了 if ( emul_inst_dec_load(filename) == 0 ) return 0; diff --git a/emul_inst_exec.h b/emul_inst_exec.h index 08c5632..c06aff5 100644 --- a/emul_inst_exec.h +++ b/emul_inst_exec.h @@ -24,6 +24,8 @@ void emul_inst_exec_set_runmode(RUNMODE mode); RUNMODE emul_inst_exec_get_runmode(); +void emul_inst_exec_init(); + int emul_inst_exec_load(char *filename); /* Execute Step diff --git a/emul_io_std.c b/emul_io_std.c index 7e80927..d268ebd 100644 --- a/emul_io_std.c +++ b/emul_io_std.c @@ -1,4 +1,5 @@ #include "emul_io_std.h" +#include static int debug_level = 0; @@ -6,6 +7,17 @@ debug_level = level; } +WINDOW *win; + +void emul_std_init() { + win = initscr(); + refresh(); +} + +void emul_std_end() { + endwin(); +} + //void emul_out_std(char c) { // putchar(c); //} @@ -13,10 +25,11 @@ // printf("%s", str); //} void emul_out_std(const char *format, ...) { - if ( debug_level != 0 ) printf("[Output] "); + if ( debug_level != 0 ) printw("[Output] "); va_list va; va_start(va, format); - vprintf(format, va); + vwprintw(win, format, va); + refresh(); va_end(va); } //void emul_out_std_err(char c) { @@ -29,8 +42,9 @@ if ( debug_level <= 1 ) return ; va_list va; va_start(va, format); - printf("[Except] "); - vprintf(format, va); + printw("[Except] "); + vwprintw(win, format, va); + refresh(); va_end(va); } //void emul_out_std_debug(char c) { @@ -43,8 +57,9 @@ if ( debug_level <= 0 ) return ; va_list va; va_start(va, format); - printf("[Debug] "); - vprintf(format, va); + printw("[Debug] "); + vwprintw(win, format, va); + refresh(); va_end(va); } diff --git a/emul_io_std.h b/emul_io_std.h index 304a541..9b1ec34 100644 --- a/emul_io_std.h +++ b/emul_io_std.h @@ -6,6 +6,9 @@ void emul_std_debug(int level); +void emul_std_init(); +void emul_std_end(); + //void emul_out_std(char c); //void emul_out_std(char *str); void emul_out_std(const char *format, ...);