Subversion Repositories pentevo

Rev

Rev 796 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. #include "std.h"
  2.  
  3. #include "emul.h"
  4. #include "vars.h"
  5. #include "debug.h"
  6. #include "dbgpaint.h"
  7. #include "dbgreg.h"
  8.  
  9. const TRegLayout regs_layout[] =
  10. {
  11.    { offsetof(TZ80State, a)     ,  8,  3, 0, 0, 1, 0, 2 }, //  0 a
  12.    { offsetof(TZ80State, f)     ,  8,  5, 0, 0, 5, 1, 2 }, //  1 f
  13.    { offsetof(TZ80State, bc)    , 16,  3, 1, 2, 6, 0, 3 }, //  2 bc
  14.    { offsetof(TZ80State, de)    , 16,  3, 2, 3, 7, 2, 4 }, //  3 de
  15.    { offsetof(TZ80State, hl)    , 16,  3, 3, 4, 8, 3, 4 }, //  4 hl
  16.    { offsetof(TZ80State, alt.af), 16, 11, 0, 1, 9, 5, 6 }, //  5 af'
  17.    { offsetof(TZ80State, alt.bc), 16, 11, 1, 2,10, 5, 7 }, //  6 bc'
  18.    { offsetof(TZ80State, alt.de), 16, 11, 2, 3,11, 6, 8 }, //  7 de'
  19.    { offsetof(TZ80State, alt.hl), 16, 11, 3, 4,12, 7, 8 }, //  8 hl'
  20.    { offsetof(TZ80State, sp)    , 16, 19, 0, 5,13, 9,10 }, //  9 sp
  21.    { offsetof(TZ80State, pc)    , 16, 19, 1, 6,10, 9,11 }, // 10 pc
  22.    { offsetof(TZ80State, ix)    , 16, 19, 2, 7,15,10,12 }, // 11 ix
  23.    { offsetof(TZ80State, iy)    , 16, 19, 3, 8,18,11,12 }, // 12 iy
  24.    { offsetof(TZ80State, i)     ,  8, 28, 0, 9,14,13,16 }, // 13 i
  25.    { offsetof(TZ80State, r_low) ,  8, 30, 0,13,14,14,17 }, // 14 r
  26.    { offsetof(TZ80State, im)    ,  2, 26, 2,11,16,13,20 }, // 15 im
  27.    { offsetof(TZ80State, iff1)  ,  1, 30, 2,15,17,13,24 }, // 16 iff1
  28.    { offsetof(TZ80State, iff2)  ,  1, 31, 2,16,17,14,25 }, // 17 iff2
  29.    { offsetof(TZ80State, f)     , 37, 24, 3,12,19,15,18 }, // 18 SF
  30.    { offsetof(TZ80State, f)     , 36, 25, 3,18,20,15,19 }, // 19 ZF
  31.    { offsetof(TZ80State, f)     , 35, 26, 3,19,21,15,20 }, // 20 F5
  32.    { offsetof(TZ80State, f)     , 34, 27, 3,20,22,15,21 }, // 21 HF
  33.    { offsetof(TZ80State, f)     , 33, 28, 3,21,23,15,22 }, // 22 F3
  34.    { offsetof(TZ80State, f)     , 32, 29, 3,22,24,16,23 }, // 23 PV
  35.    { offsetof(TZ80State, f)     , 31, 30, 3,23,25,16,24 }, // 24 NF
  36.    { offsetof(TZ80State, f)     , 30, 31, 3,24,25,17,25 }, // 25 CF
  37. };
  38.  
  39. const size_t regs_layout_count = _countof(regs_layout);
  40.  
  41. void showregs()
  42. {
  43.    Z80 &cpu = CpuMgr.Cpu();
  44.    const TZ80State &prevcpu = CpuMgr.PrevCpu();
  45.  
  46.    unsigned char atr = (activedbg == WNDREGS) ? W_SEL : W_NORM;
  47.    char line[40];
  48.    tprint(regs_x,regs_y+0, "af:**** af'**** sp:**** ir: ****", atr);
  49.    tprint(regs_x,regs_y+1, "bc:**** bc'**** pc:**** t:******", atr);
  50.    tprint(regs_x,regs_y+2, "de:**** de'**** ix:**** im?,i:**", atr);
  51.    tprint(regs_x,regs_y+3, "hl:**** hl'**** iy:**** ########", atr);
  52.  
  53.    if (cpu.halted && !cpu.iff1)
  54.    {
  55.       tprint(regs_x+26,regs_y+1,"DiHALT", (activedbg == WNDREGS) ? W_DIHALT1 : W_DIHALT2);
  56.    }
  57.    else
  58.    {
  59.        sprintf(line, "%6u", cpu.t);
  60.        tprint(regs_x+26,regs_y+1,line,atr);
  61.    }
  62.  
  63.    cpu.r_low = (cpu.r_low & 0x7F) + cpu.r_hi;
  64.    for (unsigned i = 0; i < regs_layout_count; i++)
  65.    {
  66.       unsigned mask = (1 << regs_layout[i].width) - 1;
  67.       unsigned val = mask & *(unsigned*)(PCHAR((TZ80State*)&cpu)+regs_layout[i].offs);
  68.       unsigned char atr1 = atr;
  69.       if (activedbg == WNDREGS && i == regs_curs)
  70.           atr1 = W_CURS;
  71.       if (val != (mask & *(unsigned*)(PCHAR(&prevcpu)+regs_layout[i].offs)))
  72.           atr1 |= 0x08;
  73.  
  74.       char bf[16];
  75.       switch (regs_layout[i].width)
  76.       {
  77.          case  8: sprintf(bf, "%02X", val); break;
  78.          case 16: sprintf(bf, "%04X", val); break;
  79.          case  1:
  80.          case  2: sprintf(bf, "%X", val); break;
  81.          default: *bf = 0;
  82.       }
  83.       tprint(regs_x + regs_layout[i].x, regs_y + regs_layout[i].y, bf, atr1);
  84.    }
  85.    static const char flg[] = "SZ5H3PNCsz.h.pnc";
  86.    for (unsigned char q = 0; q < 8; q++)
  87.    {
  88.       unsigned ln; unsigned char atr1 = atr;
  89.       if (activedbg == WNDREGS && regs_curs == (unsigned)(q+18)) atr1 = W_CURS;
  90.       ln = unsigned(flg[q+((cpu.af & (0x80>>q)) ? 0 : 8)]);
  91.       if ((0x80>>q)&(cpu.f^prevcpu.f)) atr1 |= 0x08;
  92.       tprint(regs_x+24+q,regs_y+3,(char*)&ln,  atr1);
  93.    }
  94.    tprint(regs_x, regs_y-1, "regs", W_TITLE);
  95.    frame(regs_x,regs_y,32,4, FRAME);
  96. }
  97.  
  98. void rleft() { regs_curs = regs_layout[regs_curs].lf; }
  99. void rright() { regs_curs = regs_layout[regs_curs].rt; }
  100. void rup() { regs_curs = regs_layout[regs_curs].up; }
  101. void rdown() { regs_curs = regs_layout[regs_curs].dn; }
  102. void renter()
  103. {
  104.    Z80 &cpu = CpuMgr.Cpu();
  105.    debugscr();
  106.    debugflip();
  107.    unsigned char sz = regs_layout[regs_curs].width;
  108.    unsigned val = ((1 << sz) - 1) & *(unsigned*)(PCHAR((TZ80State*)&cpu) + regs_layout[regs_curs].offs);
  109.    unsigned char *ptr = PUCHAR((TZ80State*)&cpu) + regs_layout[regs_curs].offs;
  110.  
  111.    u8 Kbd[256];
  112.    GetKeyboardState(Kbd);
  113.    unsigned short k = 0;
  114.    if (ToAscii(input.lastkey,0,Kbd,&k,0) != 1)
  115.        return;
  116.    u8 u = u8(toupper(k));
  117.    if ((sz == 8 || sz == 16) && ((u >= '0' && u <= '9') || (u >= 'A' && u <= 'F')))
  118.       PostThreadMessage(GetCurrentThreadId(), WM_KEYDOWN, input.lastkey, 1);
  119.    switch (sz)
  120.    {
  121.       case 8:
  122.          val = unsigned(input2(regs_x + regs_layout[regs_curs].x, regs_y + regs_layout[regs_curs].y, val));
  123.          if (int(val) != -1)
  124.              *ptr = u8(val);
  125.          break;
  126.       case 16:
  127.          val = unsigned(input4(regs_x + regs_layout[regs_curs].x, regs_y + regs_layout[regs_curs].y, val));
  128.          if (int(val) != -1)
  129.              *(unsigned short*)ptr = u16(val);
  130.          break;
  131.       case 1:
  132.          *ptr ^= 1; break;
  133.       case 2:
  134.          *ptr = (*ptr + 1) % 3; break;
  135.       default: // flags
  136.          *ptr ^= (1 << (sz-30));
  137.    }
  138.    cpu.r_hi = cpu.r_low & 0x80;
  139. }
  140. void ra() { regs_curs = 0; input.lastkey = 0; renter(); }
  141. void rf() { regs_curs = 1; input.lastkey = 0; renter(); }
  142. void rbc() { regs_curs = 2; input.lastkey = 0; renter(); }
  143. void rde() { regs_curs = 3; input.lastkey = 0; renter(); }
  144. void rhl() { regs_curs = 4; input.lastkey = 0; renter(); }
  145. void rsp() { regs_curs = 9; input.lastkey = 0; renter(); }
  146. void rpc() { regs_curs = 10; input.lastkey = 0; renter(); }
  147. void rix() { regs_curs = 11; input.lastkey = 0; renter(); }
  148. void riy() { regs_curs = 12; input.lastkey = 0; renter(); }
  149. void ri() { regs_curs = 13; input.lastkey = 0; renter(); }
  150. void rr() { regs_curs = 14; input.lastkey = 0; renter(); }
  151. void rm() { regs_curs = 15; renter(); }
  152. void r_1() { regs_curs = 16; renter(); }
  153. void r_2() { regs_curs = 17; renter(); }
  154. void rSF() { regs_curs = 18; renter(); }
  155. void rZF() { regs_curs = 19; renter(); }
  156. void rF5() { regs_curs = 20; renter(); }
  157. void rHF() { regs_curs = 21; renter(); }
  158. void rF3() { regs_curs = 22; renter(); }
  159. void rPF() { regs_curs = 23; renter(); }
  160. void rNF() { regs_curs = 24; renter(); }
  161. void rCF() { regs_curs = 25; renter(); }
  162.  
  163. void rcodejump()
  164. {
  165.     Z80 &cpu = CpuMgr.Cpu();
  166.     if (regs_layout[regs_curs].width == 16)
  167.     {
  168.          activedbg = WNDTRACE;
  169.          cpu.trace_curs = cpu.trace_top = *(unsigned short*)(PCHAR((TZ80State*)&cpu) + regs_layout[regs_curs].offs);
  170.     }
  171. }
  172. void rdatajump()
  173. {
  174.     Z80 &cpu = CpuMgr.Cpu();
  175.     if (regs_layout[regs_curs].width == 16)
  176.     {
  177.         activedbg = WNDMEM;
  178.         editor = ED_MEM;
  179.         cpu.mem_curs = *(unsigned short*)(PCHAR((TZ80State*)&cpu) + regs_layout[regs_curs].offs);
  180.     }
  181. }
  182.  
  183. char dispatch_regs()
  184. {
  185.    if ((input.lastkey >= '0' && input.lastkey <= '9') || (input.lastkey >= 'A' && input.lastkey <= 'F'))
  186.    {
  187.       renter();
  188.       return 1;
  189.    }
  190.    return 0;
  191. }
  192.