OSDN Git Service

[VM][MC6809][COMMON] Improve disassembler.Thanks to HASERIN-San.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 10 May 2019 16:58:51 +0000 (01:58 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 10 May 2019 16:58:51 +0000 (01:58 +0900)
[VM][MC6809][DISASM] Fix offset address around INDEX addressing.

source/src/common.cpp
source/src/common.h
source/src/qt/emuutils/CMakeLists.txt
source/src/vm/common_vm/CMakeLists.txt
source/src/vm/mc6809.cpp

index 389523d..0683eab 100644 (file)
        std::string DLL_PREFIX sRssDir;
 #endif
 
+
+// for disassedmbler
+uint32_t DLL_PREFIX get_relative_address_8bit(uint32_t base, uint32_t mask, int8_t offset)
+{
+       uint32_t addr = base & mask;
+       int32_t off2 = (int32_t)offset;
+       return (uint32_t)(addr + off2) & mask;
+}
+
+uint32_t DLL_PREFIX get_relative_address_16bit(uint32_t base, uint32_t mask, int16_t offset)
+{
+       uint32_t addr = base & mask;
+       int32_t off2 = (int32_t)offset;
+       return (uint32_t)(addr + off2) & mask;
+}
+
+
+uint32_t DLL_PREFIX get_relative_address_32bit(uint32_t base, uint32_t mask, int32_t offset)
+{
+       uint32_t addr = base & mask;
+       return (uint32_t)(addr + offset) & mask;
+}
+
 void DLL_PREFIX common_initialize()
 {
        // get the initial current path when the software starts
index 0fb66b7..be29482 100644 (file)
@@ -1519,7 +1519,10 @@ const char *DLL_PREFIX tchar_to_char(const _TCHAR *ts);
 const _TCHAR *DLL_PREFIX wchar_to_tchar(const wchar_t *ws);
 const wchar_t *DLL_PREFIX tchar_to_wchar(const _TCHAR *ts);
 
-
+// for disassedmbler
+uint32_t DLL_PREFIX get_relative_address_8bit(uint32_t base, uint32_t mask, int8_t offset);
+uint32_t DLL_PREFIX get_relative_address_16bit(uint32_t base, uint32_t mask, int16_t offset);
+uint32_t DLL_PREFIX get_relative_address_32bit(uint32_t base, uint32_t mask, int32_t offset);
 // misc
 void DLL_PREFIX common_initialize();
 
index e9ab429..1151ad6 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/emuutils")
 
-SET(THIS_LIB_VERSION 2.16.1)
+SET(THIS_LIB_VERSION 2.16.2)
 
 set(s_qt_emuutils_headers
        ../gui/csp_logger.h
index c7ff2b1..031a6a0 100644 (file)
@@ -1,6 +1,6 @@
 message("* vm/common_vm")
 
-SET(THIS_LIB_VERSION 2.12.0)
+SET(THIS_LIB_VERSION 2.12.1)
 
 #include(cotire)
 set(s_vm_common_vm_srcs
index 86827b2..1d8d7db 100644 (file)
@@ -632,7 +632,7 @@ uint32_t MC6809::cpu_disassemble_m6809(_TCHAR *buffer, uint32_t pc, const uint8_
 
        case DIR:
                ea = operandarray[0];
-               buffer += _stprintf(buffer, _T("$%02X"), ea);
+               buffer += _stprintf(buffer, _T("<$%02X"), ea);
                break;
 
        case REL:
@@ -657,16 +657,16 @@ uint32_t MC6809::cpu_disassemble_m6809(_TCHAR *buffer, uint32_t pc, const uint8_
                indirect = ((pb & 0x90) == 0x90 )? true : false;
 
                // open brackets if indirect
-               if (indirect && pbm != 0x80 && pbm != 0x82)
+               if (indirect /*&& pbm != 0x80 && pbm != 0x82*/)
                        buffer += _stprintf(buffer, _T("["));
 
                switch (pbm)
                {
                case 0x80:  // ,R+
-                       if (indirect)
-                               _tcscpy(buffer, _T("Illegal Postbyte"));
-                       else
-                               buffer += _stprintf(buffer, _T(",%s+"), m6809_regs[reg]);
+                       //if (indirect)
+                       //      _tcscpy(buffer, _T("Illegal Postbyte"));
+                       //else
+                       buffer += _stprintf(buffer, _T(",%s+"), m6809_regs[reg]); // Legal even INDIRECT
                        break;
 
                case 0x81:  // ,R++
@@ -677,7 +677,7 @@ uint32_t MC6809::cpu_disassemble_m6809(_TCHAR *buffer, uint32_t pc, const uint8_
                  //if (indirect)
                  //    _tcscpy(buffer, _T("Illegal Postbyte"));
                  //    else
-                               buffer += _stprintf(buffer, _T(",-%s"), m6809_regs[reg]);
+                               buffer += _stprintf(buffer, _T(",-%s"), m6809_regs[reg]); // Legal even INDIRECT
                        break;
 
                case 0x83:  // ,--R
@@ -719,7 +719,15 @@ uint32_t MC6809::cpu_disassemble_m6809(_TCHAR *buffer, uint32_t pc, const uint8_
                        break;
 
                case 0x8a:
-                       _tcscpy(buffer, _T("Illegal Postbyte"));
+                       //_tcscpy(buffer, _T("Illegal Postbyte"));
+                       {
+                               pair16_t __ea;
+                               __ea.w = pc & 0xffff;
+                               __ea.w++;
+                               __ea.b.l = 0xff;
+                               buffer += _stprintf(buffer, _T("%s"), get_value_or_symbol(d_debugger->first_symbol, _T("$%04X"), __ea.w));
+                       }
+                               
                        break;
 
                case 0x8b:  // (+/- D),R
@@ -728,26 +736,27 @@ uint32_t MC6809::cpu_disassemble_m6809(_TCHAR *buffer, uint32_t pc, const uint8_
 
                case 0x8c:  // (+/- 7 bit offset),PC
                        offset = (int8_t)opram[p++];
-                       if((name = get_symbol(d_debugger->first_symbol, (p - 1 + offset) & 0xffff)) != NULL) {
+                       if((name = get_symbol(d_debugger->first_symbol, (pc + 1 + offset) & 0xffff)) != NULL) {
                                buffer += _stprintf(buffer, _T("%s,PCR"), name);
                        } else {
-                               buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
-                               buffer += _stprintf(buffer, _T("$%02X,PC"), (offset < 0) ? -offset : offset);
+                               //buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
+                               //buffer += _stprintf(buffer, _T("$%02X,PC"), (offset < 0) ? -offset : offset);
+                               buffer += _stprintf(buffer, _T("$%04X,PCR"), get_relative_address_8bit(pc + 1, 0xffff, (int8_t)offset));
                        }
                        break;
 
                case 0x8d:  // (+/- 15 bit offset),PC
                        offset = (int16_t)((opram[p+0] << 8) + opram[p+1]);
                        p += 2;
-                       if((name = get_symbol(d_debugger->first_symbol, (p - 2 + offset) & 0xffff)) != NULL) {
+                       if((name = get_symbol(d_debugger->first_symbol, (pc + 2 + offset) & 0xffff)) != NULL) {
                                buffer += _stprintf(buffer, _T("%s,PCR"), name);
                        } else {
-                               buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
-                               buffer += _stprintf(buffer, _T("$%04X,PC"), (offset < 0) ? -offset : offset);
+                               //buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
+                               buffer += _stprintf(buffer, _T("$%04X,PCR"), get_relative_address_16bit(pc + 2, 0xffff, (int16_t)offset));
                        }
                        break;
 
-               case 0x8e: // $FFFFF
+               case 0x8e: // $FFFF
                  //_tcscpy(buffer, _T("Illegal Postbyte"));
                        offset = (int16_t)0xffff;
                        //p += 2;