OSDN Git Service

debug tool (break point, log on/off) updated.
authorastoria-d <astoria-d@mail.goo.ne.jp>
Sat, 16 Mar 2013 05:19:48 +0000 (14:19 +0900)
committerastoria-d <astoria-d@mail.goo.ne.jp>
Sat, 16 Mar 2013 05:19:48 +0000 (14:19 +0900)
emulator/clock.h
emulator/cpu.c
emulator/debug.c
emulator/emu-main.c

index d43f001..1ab4a4a 100644 (file)
@@ -15,7 +15,7 @@ int start_cpu_clock(void);
         __sighandler_t func, int signum, timer_t *timerid);*/
 
 #define DEB_SLOW
-//#undef DEB_SLOW
+#undef DEB_SLOW
 
 #ifdef DEB_SLOW
 #define CPU_CLOCK_FREQ  500000L
index 7338c3a..9bbb4a9 100644 (file)
@@ -23,6 +23,7 @@ int execute6502(void);
 int test_and_set_exec(void);
 int emu_debug(void);
 int init_6502core(void);
+void break_hit(void);
 
 void pc_set(unsigned short addr);
 unsigned short pc_get(void);
@@ -132,15 +133,23 @@ static int decode_inst(void) {
 static int fetch_and_decode_inst(void) {
     int ret;
     extern int debug_mode;
+    unsigned short pc;
+    extern unsigned short break_point;
 
 
+    pc = pc_get();
+
+    if (break_point == pc) {
+        break_hit();
+    }
+
     if (debug_mode) {
         int ret = emu_debug();
         if (!ret)
             return FALSE;
     }
     //dprint("fetch\n");
-    load_memory(pc_get());
+    load_memory(pc);
     //dump_6502(FALSE);
 
     ret = decode_inst();
index ac74096..2f02f12 100644 (file)
@@ -9,6 +9,8 @@
 
 extern int debug_mode;
 void dump_6502(int full);
+void dump_mem(const char* msg, unsigned short base, 
+        unsigned short offset, unsigned char* buf, int size);
 
 #define MAX_HISTORY     10
 
@@ -17,14 +19,24 @@ struct cmd_list {
     char *cmd;
 };
 
-struct cmd_list* debug_history;
+static struct cmd_list* debug_history;
+static int log_msg;
+//global variable.
+unsigned short break_point;
 
 static void print_debug(void) {
-    printf("command:\n");
-    printf(" s: step\n");
-    printf(" c: continue\n");
-    printf(" show: show registers\n");
-    printf(" q: quit emulator\n");
+    printf("   command:\n");
+    printf("            s: step\n");
+    printf("            c: continue\n");
+    printf("       b addr: set break point\n");
+    printf("               (break point can be set only 1 address.)\n");
+    printf("          del: delete break point\n");
+    printf("  m addr size: memory dump\n");
+    printf("         show: show registers\n");
+    printf("        pshow: show ppu registers\n");
+    printf("  v addr size: vram dump\n");
+    printf("   log on/off: set log msg on/off\n");
+    printf("            q: quit emulator\n");
 }
 
 #if 0
@@ -83,6 +95,35 @@ int emu_debug(void) {
         else if (!strcmp(buf, "show")){
             dump_6502(TRUE);
         }
+        else if (!strcmp(buf, "log")){
+            scanf("%s", buf);
+            if (!strcmp(buf, "on")){
+                log_msg = TRUE;
+            }
+            else if (!strcmp(buf, "off")){
+                log_msg = FALSE;
+            }
+            else {
+                printf("log parameter must be either [on] or [off].\n");
+            }
+        }
+        else if (!strcmp(buf, "b")){
+            unsigned int val;
+            scanf("%x", &val);
+            break_point = val;
+        }
+        else if (!strcmp(buf, "del")){
+            break_point = 0;
+        }
+        else if (!strcmp(buf, "m")){
+            printf("not supported...\n");
+        }
+        else if (!strcmp(buf, "v")){
+            printf("not supported...\n");
+        }
+        else if (!strcmp(buf, "pshow")){
+            printf("not supported...\n");
+        }
         else {
             printf("unknown command [%s].\n", buf);
             print_debug();
@@ -96,6 +137,9 @@ void disasm(const char* mnemonic, int addr_mode, unsigned short pc) {
     unsigned char dbg_get_byte(unsigned short addr);
     unsigned short dbg_get_short(unsigned short addr);
 
+    if (!log_msg)
+        return;
+
     switch(addr_mode) {
         case ADDR_MODE_ZP:
             printf("%04x: %-5s $%02x\n", pc, mnemonic, dbg_get_byte(pc + 1));
@@ -164,10 +208,18 @@ void dump_mem(const char* msg, unsigned short base,
     printf("\n");
 }
 
+void break_hit(void) {
+    printf("------------------\nbreak...\n");
+    debug_mode = TRUE;
+    dump_6502(TRUE);
+}
+
 
 int init_debug(void) {
     dprint("init debug..\n");
     debug_history = NULL;
+    log_msg = debug_mode;
+    break_point = 0;
     //initscr();          /* Start curses mode          */
 
     return TRUE;
index baa63ad..665a8ac 100644 (file)
@@ -29,7 +29,6 @@ static int init_datas(void) {
     int ret;
 
     main_loop_done = FALSE;
-    debug_mode = FALSE;
     critical_error = FALSE;
 
     ret = init_clock();
@@ -145,6 +144,7 @@ int main(int argc, char* argv[]) {
         print_usage();
         return -1;
     }
+    debug_mode = param_debug;
 
     ret = init_datas();
     if (!ret) {
@@ -168,7 +168,6 @@ int main(int argc, char* argv[]) {
         return FALSE;
     }
 
-    debug_mode = param_debug;
     reset_cpu();
     ret = start_clock();
     if (!ret) {