OSDN Git Service

debug tool update. jsr bug fix.
authorastoria-d <astoria-d@mail.goo.ne.jp>
Sat, 16 Mar 2013 09:14:26 +0000 (18:14 +0900)
committerastoria-d <astoria-d@mail.goo.ne.jp>
Sat, 16 Mar 2013 09:14:26 +0000 (18:14 +0900)
emulator/6502core.c
emulator/cpu.c
emulator/debug.c
emulator/ppucore/vram.c
emulator/ppucore/vram.h

index 62e88fe..315b483 100644 (file)
@@ -86,7 +86,6 @@ unsigned char get_cpu_data_buf(void);
 void set_cpu_data_buf(unsigned char data);
 unsigned short get_cpu_addr_buf(void);
 void set_cpu_addr_buf(unsigned short addr);
-void disasm(const char* mnemonic, int addr_mode, unsigned short pc);
 int get_clock_cnt(void);
 
 int func_ADC(void);
@@ -675,7 +674,7 @@ static void push(unsigned char data) {
 }
 
 static unsigned char pop(void) {
-    return load_memory(--cpu_reg.sp);
+    return load_memory(++cpu_reg.sp);
 }
 
 /*---------- instruction implementations.   -----------------*/
@@ -1184,13 +1183,14 @@ int func_JSR(void) {
     //cycle 1
     if (current_exec_index == 0) {
         //save return addr(-1) hi.
-        push((cpu_reg.pc - 1) >> 8);
+        //pc + 1 => jsr abslo abshi - 1
+        push((cpu_reg.pc + 1) >> 8);
         return TRUE;
     }
     //cycle 2
     else if (current_exec_index == 1) {
         //save return addr(-1) low.
-        push(cpu_reg.pc - 1);
+        push(cpu_reg.pc + 1);
         return TRUE;
     }
     //cycle 3,4
@@ -1592,7 +1592,6 @@ int decode6502(unsigned char inst) {
     /*dprint("decode inst: %02x > %s, %d cycle, %d len\n", 
             inst, omap->mnemonic, omap->cycle, omap->inst_len);
 */
-    disasm(omap->mnemonic, omap->addr_mode, cpu_reg.pc);
 
     current_inst = omap;
     current_exec_index = 0;
@@ -1650,6 +1649,16 @@ void pc_move(int offset) {
     cpu_reg.pc += offset;
 }
 
+int init_6502core(void) {
+    memset(&cpu_reg, 0, sizeof(struct cpu_6502));
+    current_inst = NULL;
+    current_exec_index = 0;
+    exec_done = FALSE;
+    return TRUE;
+}
+
+/* for debug.c */
+
 void dump_6502(int full) {
     printf("\nclock: %09d\n", get_clock_cnt());
     if (full) 
@@ -1675,11 +1684,13 @@ void dump_6502(int full) {
 }
 
 
-int init_6502core(void) {
-    memset(&cpu_reg, 0, sizeof(struct cpu_6502));
-    current_inst = NULL;
-    current_exec_index = 0;
-    exec_done = FALSE;
-    return TRUE;
-}
+void disas_pc(void) {
+    unsigned char inst;
+    unsigned char dbg_get_byte(unsigned short addr);
+    void disasm(const char* mnemonic, int addr_mode, unsigned short pc);
 
+    inst = dbg_get_byte(cpu_reg.pc);
+    struct opcode_map * omap = &opcode_list[inst];
+    
+    disasm(omap->mnemonic, omap->addr_mode, cpu_reg.pc);
+}
index 9bbb4a9..3849765 100644 (file)
@@ -17,13 +17,11 @@ static int reset_handler2(void);
 #define RESET_ADDR      0xFFFC
 #define IRQ_BRK_ADDR    0xFFFE
 
-void dump_6502(int full);
 int decode6502(unsigned char inst);
 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,9 +130,16 @@ static int decode_inst(void) {
 
 static int fetch_and_decode_inst(void) {
     int ret;
-    extern int debug_mode;
     unsigned short pc;
+
+    //for debug.c
+    void break_hit(void);
+    void disas_pc(void);
+    void dump_6502(int full);
+    extern int debug_mode;
     extern unsigned short break_point;
+    extern int dbg_log_msg;
+    extern int critical_error;
 
 
     pc = pc_get();
@@ -143,19 +148,26 @@ static int fetch_and_decode_inst(void) {
         break_hit();
     }
 
+    if (dbg_log_msg) {
+        disas_pc();
+    }
     if (debug_mode) {
-        int ret = emu_debug();
+        if (!dbg_log_msg)
+            disas_pc();
+        ret = emu_debug();
         if (!ret)
             return FALSE;
     }
     //dprint("fetch\n");
     load_memory(pc);
-    //dump_6502(FALSE);
 
     ret = decode_inst();
     if (!ret) {
-        extern int critical_error;
+        disas_pc();
+        dump_6502(TRUE);
         fprintf(stderr, "cpu decode instruction failure.\n");
+        while (emu_debug());
+
         critical_error = TRUE;
         //raise(SIGINT);
         //abort();
@@ -170,6 +182,9 @@ static int fetch_and_decode_inst(void) {
 
 static int execute_inst(void) {
     int ret;
+
+    void disas_pc(void);
+    void dump_6502(int full);
     extern int critical_error;
 
     //dprint("execute\n");
@@ -180,6 +195,10 @@ static int execute_inst(void) {
     */
     if (!ret) {
         fprintf(stderr, "cpu execute instruction failure.\n");
+        disas_pc();
+        dump_6502(TRUE);
+        while (emu_debug());
+
         critical_error = TRUE;
         //raise(SIGINT);
         return ret;
index 2f02f12..5c4baa1 100644 (file)
@@ -9,8 +9,11 @@
 
 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);
+void dump_vram(unsigned short addr, int size);
+void dump_mem(unsigned short addr, int size);
+unsigned char vram_data_get(unsigned short addr);
+unsigned char dbg_get_byte(unsigned short addr);
+unsigned short dbg_get_short(unsigned short addr);
 
 #define MAX_HISTORY     10
 
@@ -20,8 +23,8 @@ struct cmd_list {
 };
 
 static struct cmd_list* debug_history;
-static int log_msg;
 //global variable.
+int dbg_log_msg;
 unsigned short break_point;
 
 static void print_debug(void) {
@@ -98,10 +101,10 @@ int emu_debug(void) {
         else if (!strcmp(buf, "log")){
             scanf("%s", buf);
             if (!strcmp(buf, "on")){
-                log_msg = TRUE;
+                dbg_log_msg = TRUE;
             }
             else if (!strcmp(buf, "off")){
-                log_msg = FALSE;
+                dbg_log_msg = FALSE;
             }
             else {
                 printf("log parameter must be either [on] or [off].\n");
@@ -116,10 +119,18 @@ int emu_debug(void) {
             break_point = 0;
         }
         else if (!strcmp(buf, "m")){
-            printf("not supported...\n");
+            unsigned int addr;
+            int size;
+            scanf("%x", &addr);
+            scanf("%d", &size);
+            dump_mem(addr, size);
         }
         else if (!strcmp(buf, "v")){
-            printf("not supported...\n");
+            unsigned int addr;
+            int size;
+            scanf("%x", &addr);
+            scanf("%d", &size);
+            dump_vram(addr, size);
         }
         else if (!strcmp(buf, "pshow")){
             printf("not supported...\n");
@@ -134,11 +145,6 @@ int emu_debug(void) {
 }
 
 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:
@@ -179,31 +185,55 @@ void disasm(const char* mnemonic, int addr_mode, unsigned short pc) {
     }
 }
 
-void dump_mem(const char* msg, unsigned short base, 
-        unsigned short offset, unsigned char* buf, int size) {
+void dump_vram(unsigned short addr, int size) {
+    int i;
+
+    if (addr % BYTES_PER_LINE)
+        printf("%04x: ", addr % BYTES_PER_LINE);
+
+    for (i = 0; i < addr % BYTES_PER_LINE; i++) {
+        printf("   ");
+    }
+    for (i = 0; i < size; i++) {
+        if (addr % BYTES_PER_LINE == 0)
+            printf("%04x: ", addr);
+
+        printf("%02x ", vram_data_get(addr));
+
+        if (addr % BYTES_PER_LINE == (BYTES_PER_LINE / 2) - 1)
+            printf("  ");
+
+        if (addr % BYTES_PER_LINE == (BYTES_PER_LINE - 1))
+            printf("\n");
+
+        addr++;
+    }
+    printf("\n");
+}
+
+void dump_mem(unsigned short addr, int size) {
     int i;
+    unsigned char vram_data_get(unsigned short addr);
 
-    printf(msg);
-    if (offset % BYTES_PER_LINE)
-        printf("%04x: ", base + offset % BYTES_PER_LINE);
+    if (addr % BYTES_PER_LINE)
+        printf("%04x: ", addr % BYTES_PER_LINE);
 
-    for (i = 0; i < offset % BYTES_PER_LINE; i++) {
+    for (i = 0; i < addr % BYTES_PER_LINE; i++) {
         printf("   ");
     }
     for (i = 0; i < size; i++) {
-        if (offset % BYTES_PER_LINE == 0)
-            printf("%04x: ", base + offset);
+        if (addr % BYTES_PER_LINE == 0)
+            printf("%04x: ", addr);
 
-        printf("%02x ", *buf);
+        printf("%02x ", dbg_get_byte(addr));
 
-        if (offset % BYTES_PER_LINE == (BYTES_PER_LINE / 2) - 1)
+        if (addr % BYTES_PER_LINE == (BYTES_PER_LINE / 2) - 1)
             printf("  ");
 
-        if (offset % BYTES_PER_LINE == (BYTES_PER_LINE - 1))
+        if (addr % BYTES_PER_LINE == (BYTES_PER_LINE - 1))
             printf("\n");
 
-        buf++;
-        offset++;
+        addr++;
     }
     printf("\n");
 }
@@ -218,7 +248,7 @@ void break_hit(void) {
 int init_debug(void) {
     dprint("init debug..\n");
     debug_history = NULL;
-    log_msg = debug_mode;
+    dbg_log_msg = FALSE;
     break_point = 0;
     //initscr();          /* Start curses mode          */
 
index 93f7584..8482241 100644 (file)
@@ -216,10 +216,10 @@ unsigned char vram_data_get(unsigned short addr) {
     addr &= PPU_ADDR_MASK;
 
     if (addr < PATTERN_TBL_SIZE) {
-        return name_tbl_get(0, addr & PATTERN_ADDR_MASK);
+        return pattern_tbl_get(0, addr & PATTERN_ADDR_MASK);
     }
     if (addr < 2 * PATTERN_TBL_SIZE) {
-        return name_tbl_get(1, addr & PATTERN_ADDR_MASK);
+        return pattern_tbl_get(1, addr & PATTERN_ADDR_MASK);
     }
     else if (addr >= PALETTE_START) {
         if (addr & PALETTE_SPRITE_BIT)
@@ -572,92 +572,3 @@ void clean_vram(void) {
 
 }
 
-
-/*
- * type 
- * 0: pattern table
- * 1: name table
- * 2: attribute table
- * 3: palette table (bank=0: bg, bank=1: sprite)
- * 4: sprite ram
- * */
-void dump_vram(int type, int bank, unsigned short addr, int size) {
-    char buf[100];
-    unsigned short base;
-    unsigned char *mem;
-
-    switch(type) {
-        case VRAM_DUMP_TYPE_PTN:
-            sprintf(buf, "pattern table %d:\n", bank);
-            base = (bank == 0 ? 0 : 0x1000);
-            mem = (bank == 0 ? pattern_tbl0 : pattern_tbl1);
-            break;
-
-        case VRAM_DUMP_TYPE_NAME:
-            sprintf(buf, "name table %d:\n", bank);
-            base = 0x2000 + bank * 0x400;
-            switch (bank) {
-                case 0:
-                    mem = name_tbl0;
-                    break;
-                case 1:
-                    mem = name_tbl1;
-                    break;
-                case 2:
-                    mem = name_tbl2;
-                    break;
-                case 3:
-                default:
-                    mem = name_tbl3;
-                    break;
-            }
-            break;
-
-        case VRAM_DUMP_TYPE_ATTR:
-            sprintf(buf, "attribute table %d:\n", bank);
-            base = 0x23c0 + bank * 0x400;
-            switch (bank) {
-                case 0:
-                    mem = attr_tbl0;
-                    break;
-                case 1:
-                    mem = attr_tbl1;
-                    break;
-                case 2:
-                    mem = attr_tbl2;
-                    break;
-                case 3:
-                default:
-                    mem = attr_tbl3;
-                    break;
-            }
-            break;
-
-        case VRAM_DUMP_TYPE_PLT:
-            switch (bank) {
-                case 0:
-                    base = 0x3f00;
-                    sprintf(buf, "bg palette table %d:\n", bank);
-                    mem = bg_palette_tbl;
-                    break;
-                case 1:
-                default:
-                    base = 0x3f10;
-                    sprintf(buf, "sprite palette table %d:\n", bank);
-                    mem = spr_palette_tbl;
-                    break;
-            }
-            break;
-
-        case VRAM_DUMP_TYPE_SPR:
-        default:
-            sprintf(buf, "sprite ram:\n");
-            base = 0;
-            mem = sprite_ram;
-            break;
-
-    }
-    dump_mem(buf, base, addr, mem, size);
-}
-
-
index 34d63f9..8923c1e 100644 (file)
@@ -68,13 +68,6 @@ struct palette_unit {
     unsigned int    bit67   :2;
 } __attribute__ ((packed));
 
-#define VRAM_DUMP_TYPE_PTN  0
-#define VRAM_DUMP_TYPE_NAME 1
-#define VRAM_DUMP_TYPE_ATTR 2
-#define VRAM_DUMP_TYPE_PLT  3
-#define VRAM_DUMP_TYPE_SPR  4
-
-
 #define colto5bit(col8) ((col8) * 0x1F / 0xFF)
 #define colto8bit(col5) (((unsigned int)(col5)) * 0xFF / 0x1F)