#include "std.h"
#include "emul.h"
#include "vars.h"
#include "debug.h"
#include "dbgtrace.h"
#include "dbglabls.h"
#include "dbgpaint.h"
#include "dbgcmd.h"
#include "memory.h"
#include "z80asm.h"
#include "z80/op_system.h"
#include "util.h"
#include "gsz80.h" // фы z80gs::GSCPUFQ [NS]
//#define MOD_NEW_LABELS // [NS]
unsigned trace_follow_regs_in_view; //Їыру ўЄю PC эрїюфшЄё т яюыхчЁхэш //[NS]
//unsigned trace_follow_request; // .conf Їыру ўЄю эєцэю яхЁхтхёЄш Їюъєё эр regs //[NS]
//unsigned trace_follow_regs; // ЄхяхЁ№ conf.trace_follow_regs
//=============================================================================
bool get_labels( unsigned addr, char *line) // [NS]
{
Z80 &cpu = CpuMgr.Cpu();
sprintf( line, " > ");
int ptr = 5;
//-------------------------------------------------------------------------
{
char *virtlbl = mon_labels.find(((unsigned char *)NULL) + addr); //NEDOREPO
char *lbl = mon_labels.find( am_r( addr));
//---------------------------------------------------------------------
if (virtlbl)
lbl = virtlbl; //NEDOREPO
//---------------------------------------------------------------------
if (lbl)
{
for (int k = 0; (k < 10) && lbl[ k]; )
line[ ptr++] = lbl[ k++]; //Alone Coder
}
//---------------------------------------------------------------------
else
{
return FALSE;
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
// чрыштър ёЄЁюъш юЄ юяъюфр фю ьэхьюэшъш
while (ptr < 32)
line[ ptr++] = ' ';
//-------------------------------------------------------------------------
line[ ptr] = 0;
return TRUE;
}
//=============================================================================
//=============================================================================
int disasm_line( unsigned addr, char *line)
{
Z80 &cpu = CpuMgr.Cpu();
unsigned char dbuf[ 16 + 129]; /*Alone Code 0.36.7*/
ptrdiff_t i; //Alone Coder 0.36.7
//-------------------------------------------------------------------------
for (/*int*/ i = 0; i < 16; i++)
dbuf[i] = cpu.DirectRm( addr + unsigned( i));
//-------------------------------------------------------------------------
sprintf( line, "%04X ", addr);
int ptr = 5;
ptrdiff_t len = disasm( dbuf, addr, char( trace_labels)) - dbuf;
//8000 ..DDCB0106 rr (ix+1)
//-------------------------------------------------------------------------
// 0000 LABELS ╤рьш ьэхьюэшъш ЄєЄ эх яхўрЄр■Єёю?
if ((trace_labels) && (!conf.Disasm_New_Labels))
{
char *virtlbl = mon_labels.find( ((unsigned char *) NULL) + addr); //NEDOREPO
char *lbl = mon_labels.find( am_r( addr));
//---------------------------------------------------------------------
if (virtlbl)
lbl = virtlbl; //NEDOREPO
//---------------------------------------------------------------------
// if (lbl) for (int k = 0; k < 10 && lbl[k]; line[ptr++] = lbl[k++]); //Alone Coder //╧╬╦═╬╤╥▄▐ ╙─└╦┼═╬ ┬ NEDOREPO
if (lbl)
{
for (int k = 0; (k < 10) && lbl[k]; )
line[ ptr++] = lbl[ k++]; //Alone Coder
}
}
//-------------------------------------------------------------------------
// 0000 OPCODES ╤рьш ьэхьюэшъш ЄєЄ эх яхўрЄр■Єёю?
else
{
ptrdiff_t len1 = len;
//---------------------------------------------------------------------
if (len > 4)
{
len1 = 4;
*(short*) (line + ptr) = WORD2('.', '.');
ptr += 2;
}
//---------------------------------------------------------------------
for (i = len - len1; i < len; i++)
{
sprintf( line + ptr, "%02X", dbuf[ i]);
ptr += 2;
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
// чрыштър ёЄЁюъш юЄ юяъюфр фю ьэхьюэшъш
while (ptr < 16)
line[ ptr++] = ' ';
//-------------------------------------------------------------------------
strcpy( line + ptr, asmbuf);
return int( len);
}
//=============================================================================
#define TWF_BRANCH 0x010000U
#define TWF_BRADDR 0x020000U
#define TWF_LOOPCMD 0x040000U
#define TWF_CALLCMD 0x080000U
#define TWF_BLKCMD 0x100000U
#define TWF_HALTCMD 0x200000U
// ╠ырф°шх 16сшЄ - рфЁхё z80
// ёЄрЁ°шх 16сшЄ - Їыруш TWF_xxxx
//=============================================================================
//=============================================================================
static unsigned tracewndflags() //????
{
Z80 &cpu = CpuMgr.Cpu();
unsigned readptr = cpu.pc;
unsigned base = cpu.hl;
unsigned char opcode = 0;
unsigned char ed = 0;
//-------------------------------------------------------------------------
for (;;)
{
opcode = cpu.DirectRm( readptr++);
//---------------------------------------------------------------------
if (opcode == 0xDD)
base = cpu.ix;
//---------------------------------------------------------------------
else if (opcode == 0xFD)
base = cpu.iy;
//---------------------------------------------------------------------
else if (opcode == 0xED)
ed = 1;
//---------------------------------------------------------------------
else
break;
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
unsigned fl = 0;
//-------------------------------------------------------------------------
if (opcode == 0x76) // halt
{
u32 addr;
//---------------------------------------------------------------------
if (cpu.im < 2) //!!!! Єюўэю ыш фы тёхї?????
{
addr = 0x38;
}
//---------------------------------------------------------------------
// im2
else
{
unsigned vec = unsigned( cpu.i << 8U) | cpu.IntVec();
addr = u32( (cpu.DirectRm( vec+1) << 8U) | cpu.DirectRm( vec));
}
//---------------------------------------------------------------------
return TWF_HALTCMD | addr;
}
//-------------------------------------------------------------------------
if (ed)
{
//---------------------------------------------------------------------
// ldir/lddr | cpir/cpdr | inir/indr | otir/otdr
if ((opcode & 0xF4) == 0xB0)
return TWF_BLKCMD;
//---------------------------------------------------------------------
// reti/retn
if ((opcode & 0xC7) != 0x45)
return 0;
//---------------------------------------------------------------------
ret:
return ( cpu.DirectRm( cpu.sp) | unsigned( cpu.DirectRm( cpu.sp + 1) << 8U)) |
TWF_BRANCH |
TWF_BRADDR;
}
//-------------------------------------------------------------------------
// ret
if (opcode == 0xC9)
goto ret;
//-------------------------------------------------------------------------
// jp
if (opcode == 0xC3)
{
jp:
return (cpu.DirectRm( readptr) | unsigned( cpu.DirectRm( readptr + 1) << 8U)) |
TWF_BRANCH |
fl;
}
//-------------------------------------------------------------------------
// call
if (opcode == 0xCD)
{
fl = TWF_CALLCMD;
goto jp;
}
//-------------------------------------------------------------------------
static const unsigned char flags[] = { ZF,CF,PV,SF };
//-------------------------------------------------------------------------
if ((opcode & 0xC1) == 0xC0)
{
unsigned char flag = flags[(opcode >> 4) & 3];
unsigned char res = cpu.f & flag;
//---------------------------------------------------------------------
if (!(opcode & 0x08))
res ^= flag;
//---------------------------------------------------------------------
if (!res)
return 0;
//---------------------------------------------------------------------
// ret cc
if ((opcode & 0xC7) == 0xC0)
goto ret;
//---------------------------------------------------------------------
// call cc
if ((opcode & 0xC7) == 0xC4)
{
fl = TWF_CALLCMD;
goto jp;
}
//---------------------------------------------------------------------
// jp cc
if ((opcode & 0xC7) == 0xC2)
{
fl = TWF_LOOPCMD;
goto jp;
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
// jp (hl/ix/iy)
if (opcode == 0xE9)
return base | TWF_BRANCH | TWF_BRADDR;
//-------------------------------------------------------------------------
// rst #xx
if ((opcode & 0xC7) == 0xC7)
return (opcode & 0x38) | TWF_CALLCMD | TWF_BRANCH;
//-------------------------------------------------------------------------
if ((opcode & 0xC7) == 0x00)
{
//---------------------------------------------------------------------
if (!opcode || opcode == 0x08)
return 0;
//---------------------------------------------------------------------
int offs = (signed char) cpu.DirectRm( readptr++);
unsigned addr = unsigned( offs + int( readptr)) | TWF_BRANCH;
//---------------------------------------------------------------------
// jr
if (opcode == 0x18)
return addr;
//---------------------------------------------------------------------
// djnz
if (opcode == 0x10)
return (cpu.b == 1) ? 0 :
addr | TWF_LOOPCMD;
//---------------------------------------------------------------------
// jr cc
unsigned char flag = flags[ (opcode >> 4) & 1];
unsigned char res = cpu.f & flag;
//---------------------------------------------------------------------
if (!(opcode & 0x08))
res ^= flag;
//---------------------------------------------------------------------
return res ? addr | TWF_LOOPCMD :
0;
//---------------------------------------------------------------------
}
return 0;
}
//=============================================================================
//=============================================================================
static unsigned trcurs_y;
unsigned asmii;
static char asmpc[ 64];
static char dumppc[ 12];
const unsigned cs[ 3][ 2] =
{
{ 0, 4},
{ 5, 10},
{ 16, 16}
};
//=============================================================================
//=============================================================================
// юсэютыхэшх юъэр фшчрёьр т фхсрухЁх
void showtrace()
{
#define DBG_ATTR_TITLES 0x5D //0x71 //white blue
char trace_follow_regs_text[ 10];
//-------------------------------------------------------------------------
switch (conf.trace_follow_regs)
{
case REG_AF: sprintf( trace_follow_regs_text, "(AF)"); break;
case REG_BC: sprintf( trace_follow_regs_text, "(BC)"); break;
case REG_DE: sprintf( trace_follow_regs_text, "(DE)"); break;
case REG_HL: sprintf( trace_follow_regs_text, "(HL)"); break;
case REG_AF1: sprintf( trace_follow_regs_text, "(AF\')"); break;
case REG_BC1: sprintf( trace_follow_regs_text, "(BC\')"); break;
case REG_DE1: sprintf( trace_follow_regs_text, "(DE\')"); break;
case REG_HL1: sprintf( trace_follow_regs_text, "(HL\')"); break;
case REG_IX: sprintf( trace_follow_regs_text, "(IX)"); break;
case REG_IY: sprintf( trace_follow_regs_text, "(IY)"); break;
case REG_SP: sprintf( trace_follow_regs_text, "(SP)"); break;
case REG_PC: sprintf( trace_follow_regs_text, "(PC)"); break;
default: sprintf( trace_follow_regs_text, "(None)"); break;
}
//-------------------------------------------------------------------------
tprint( trace_x + 26,
trace_y - 1,
trace_follow_regs_text,
DBG_ATTR_TITLES
);
//-------------------------------------------------------------------------
//яхЁхьхёЄшЄ№ т debug.h !!!!
#define DBG_ATTR_BCKGRND 0x00 //0 0
#define DBG_ATTR_BCKGRND_ACTIVE 0x10 //blue 0
#define DBG_ATTR_BCKGRND_BRIGHT 0X80 //br+ 0
#define DBG_ATTR_TRACE_LINES 0x0F //0 br+WHITE
#define DBG_ATTR_TRACE_LINES_ROM 0x07 //0 WHITE
#define DBG_ATTR_TRACE_BREAK_EX 0x0A //0 red
#define DBG_ATTR_TRACE_BREAK_R_BACK 0x40 //red 0
#define DBG_ATTR_TRACE_BREAK_W_BACK 0x20 //green 0
#define DBG_ATTR_TRACE_BREAK_RW_BACK 0x60 //yellow 0
#define DBG_ATTR_TRACE_REG_PC_BACK 0xD0 //br+WHITE 0
#define DBG_ATTR_TRACE_REG_FOLLOW_BACK 0xF0 //br+WHITE 0
#define DBG_ATTR_TRACE_SELECTED 0xB0 //br+MAGENTAA 0
#define DBG_ATTR_TRACE_BRANCH_DIRECTION 0x0A //0 br+RED
#define DBG_ATTR_TRACE_BRANCH_DIRECTION_INV 0x0D //0 br+CYAN
#define DBG_ATTR_TRACE_BRANCH_DESTINATION 0x0D //0 br+CYAN
#define DBG_ATTR_TRACE_CURRENT_Z80 0x5D//0x70 //white 0
#define DBG_ATTR_TRACE_LAST_BRANCH 0x5D//0x70 //white 0
/*
ьрёшт їЁрэшЄ рфЁхёр тёхї юЄюсЁрцрхь√ї ёЄЁюъ т фхсрухЁх
cpu.trpc[00] - 00E5
cpu.trpc[01] - 00E7
cpu.trpc[02] - 00E8
cpu.trpc[18] - 0109
cpu.trpc[19] - 010C
cpu.trpc[20] - 010F
+ х∙х ёЄЁюър ё рфЁхёюь эрўрыр ёыхфє■∙хщ ёЄЁрэшЎ√
cpu.trpc[21] - 0112
*/
// trace_follow_regs = 4;
restart_showtrace:
trace_follow_regs_in_view = 0;
Z80 &cpu = CpuMgr.Cpu();
// char line[ 40]; //Alone Coder 0.36.7
char line[ 16 + 129]; //Alone Coder 0.36.7
cpu.trace_curs &= 0xFFFF;
cpu.trace_top &= 0xFFFF;
cpu.pc &= 0xFFFF;
cpu.trace_mode = (cpu.trace_mode + 3) % 3;
cpu.pc_trflags = tracewndflags();
cpu.nextpc = (cpu.pc_trflags & TWF_HALTCMD) ? (cpu.pc_trflags & 0xFFFF):
((cpu.pc + unsigned( disasm_line( cpu.pc, line))) & 0xFFFF );
unsigned pc = cpu.trace_top;
asmii = -1U; //ъєЁёюЁ т эх яюы чЁхэш
// unsigned char atr0 = (activedbg == WNDTRACE) ? W_SEL : //0x17
// W_NORM; //0x07
unsigned char attr1; //temp attr
unsigned char current_back_attr = (activedbg == WNDTRACE) ? DBG_ATTR_BCKGRND_ACTIVE : //(т√фхыхээюх юъэю)
DBG_ATTR_BCKGRND;
unsigned char attr_lines = (current_back_attr | DBG_ATTR_TRACE_LINES);
unsigned char attr_lines_rom = (current_back_attr | DBG_ATTR_TRACE_LINES_ROM);
//-------------------------------------------------------------------------
unsigned ii; //Alone Coder 0.36.7
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
for (ii = 0; ii < trace_size; ii++)
{
pc &= 0xFFFF;
cpu.trpc[ ii] = pc;
int len = disasm_line( pc, line);
//---------------------------------------------------------------------
char *ptr = line + strlen( line); //тшфшью чрўшёЄър ёЄЁюъш
//---------------------------------------------------------------------
while (ptr < line + 32)
*ptr++ = ' ';
//---------------------------------------------------------------------
line[ 32] = 0;
//---------------------------------------------------------------------
#define FLAG_FOLLOW 0x01
#define FLAG_BP_X 0x02
#define FLAG_BP_R 0x04
#define FLAG_BP_W 0x08
#define FLAG_PC 0x10 //+FLAG_FOLLOW
//---------------------------------------------------------------------
//attr1 = attr_lines;
attr1 = (bankr[ (pc >> 14) & 3] != bankw[ (pc >> 14) & 3]) ? attr_lines_rom :
attr_lines ;
int temp_line_flags = 0;
//---------------------------------------------------------------------
if (pc == (cpu.pc & 0xFFFF))
{
temp_line_flags |= FLAG_PC;
}
//---------------------------------------------------------------------
int follow_regs_value;
//---------------------------------------------------------------------
switch (conf.trace_follow_regs)
{
case REG_AF: follow_regs_value = cpu.af; break;
case REG_BC: follow_regs_value = cpu.bc; break;
case REG_DE: follow_regs_value = cpu.de; break;
case REG_HL: follow_regs_value = cpu.hl; break;
case REG_AF1: follow_regs_value = cpu.alt.af; break;
case REG_BC1: follow_regs_value = cpu.alt.bc; break;
case REG_DE1: follow_regs_value = cpu.alt.de; break;
case REG_HL1: follow_regs_value = cpu.alt.hl; break;
case REG_IX: follow_regs_value = cpu.ix; break;
case REG_IY: follow_regs_value = cpu.iy; break;
case REG_SP: follow_regs_value = cpu.sp; break;
case REG_PC: follow_regs_value = cpu.pc; break;
}
//---------------------------------------------------------------------
// Єъ т ёЄрЁ°шї сшЄрї ьюцхЄ с√Є№ ыхт√щ ьєёюЁ ╨┼└╦▄═╬!!!
follow_regs_value &= 0xFFFF;
//---------------------------------------------------------------------
// ┼ёыш ёыхфшь чр ъръшь Єю ЁхушёЄЁюь
if (conf.trace_follow_regs)
{
//-----------------------------------------------------------------
if (pc == follow_regs_value) // r0171 fix [NS]
{
// printf("now in view\n");
temp_line_flags |= FLAG_FOLLOW;
trace_follow_regs_in_view = 1;
}
//-----------------------------------------------------------------
}
//---------------------------------------------------------------------
// ┼ёыш эх ёыхфшь
else
{
// Єю фхырхь тшф ўЄю ь√ єцх тёх эр°ыш
// printf("now not in view\n");
trace_follow_regs_in_view = 1;
conf.trace_follow_request = 0;
}
//-------------------------------------------------------------------------
// if (pc == cpu.pc) { temp_line_flags |= FLAG_PC; trace_follow_regs_in_view = 1; }
//-------------------------------------------------------------------------
if (cpu.membits[ pc] & MEMBITS_BPX) temp_line_flags |= FLAG_BP_X;
if (cpu.membits[ pc] & MEMBITS_BPR) temp_line_flags |= FLAG_BP_R;
if (cpu.membits[ pc] & MEMBITS_BPW) temp_line_flags |= FLAG_BP_W;
//---------------------------------------------------------------------
switch ((temp_line_flags & (FLAG_BP_X | FLAG_BP_R | FLAG_BP_W)))
{
//X only ----------------------------------------------------------
case (FLAG_BP_X): //...O
attr1 = (attr1 & 0xF0) | DBG_ATTR_TRACE_BREAK_EX; break; //+ back
//RW --------------------------------------------------------------
case (FLAG_BP_R): //..O.
attr1 = (attr1 & 0x0F) | DBG_ATTR_TRACE_BREAK_R_BACK; break; //+ ink
case (FLAG_BP_W): //.O..
attr1 = (attr1 & 0x0F) | DBG_ATTR_TRACE_BREAK_W_BACK; break; //+ ink
case (FLAG_BP_R | FLAG_BP_W): //.OO.
attr1 = (attr1 & 0x0F) | DBG_ATTR_TRACE_BREAK_RW_BACK; break; //+ ink
//RW + X ----------------------------------------------------------
case (FLAG_BP_X | FLAG_BP_R): //..OO
attr1 = DBG_ATTR_TRACE_BREAK_EX | DBG_ATTR_TRACE_BREAK_R_BACK; break;
case (FLAG_BP_X | FLAG_BP_W): //.O.O
attr1 = DBG_ATTR_TRACE_BREAK_EX | DBG_ATTR_TRACE_BREAK_W_BACK; break;
case (FLAG_BP_X | FLAG_BP_R | FLAG_BP_W): //.OOO
attr1 = DBG_ATTR_TRACE_BREAK_EX | DBG_ATTR_TRACE_BREAK_RW_BACK; break;
}
//---------------------------------------------------------------------
switch ((temp_line_flags & (FLAG_BP_X | FLAG_PC | FLAG_FOLLOW)))
{
//Follow яютхЁx PC -----------------------------------------------
case (FLAG_FOLLOW):
case (FLAG_FOLLOW | FLAG_PC):
attr1 = DBG_ATTR_TRACE_REG_FOLLOW_BACK;
break;
//Follow яютхЁї PC + X --------------------------------------------
case (FLAG_BP_X | FLAG_FOLLOW):
case (FLAG_BP_X | FLAG_FOLLOW | FLAG_PC):
attr1 = DBG_ATTR_TRACE_REG_FOLLOW_BACK | DBG_ATTR_TRACE_BREAK_EX;
break;
//PC --------------------------------------------------------------
case (FLAG_PC):
attr1 = DBG_ATTR_TRACE_REG_PC_BACK;
break;
//PC + X ----------------------------------------------------------
case (FLAG_PC | FLAG_BP_X):
attr1 = DBG_ATTR_TRACE_REG_PC_BACK | DBG_ATTR_TRACE_BREAK_EX;
break;
//-----------------------------------------------------------------
}
//---------------------------------------------------------------------
// //---------------------------------------------------------------------
// // рЄЁшсєЄ ёЄЁюъш ё (Єхъє∙шь PC) / (юс√ўэр ёЄЁюър)
// attr1 = (pc == cpu.pc) ? DBG_ATTR_TRACE_REG_PC_BACK : //W_TRACEPOS :
// attr_lines; //atr0;
// //---------------------------------------------------------------------
// // рЄЁшсєЄ тёхщ ёЄЁюъш ё сЁ ъюь
// // Єръ цх яюЄюь ьюцэю сєфхЄ юЄюсЁрцрЄ№ Ёрчэ√х тшф√ сЁ ъют
// // Ёрчэ√ьш ЎтхЄрьш
//
// if (cpu.membits[pc] & MEMBITS_BPX) //EX
// {
// attr1 = (attr1 & 0xF0) | DBG_ATTR_TRACE_BREAK_EX; // + back
// }
//---------------------------------------------------------------------
//#ifdef MOD_NEW_LABELS
if ((trace_labels) && (conf.Disasm_New_Labels))
{
char labels_line[ 16 + 129];
//-----------------------------------------------------------------
// ╩╬╤╥█╦▄ Єъ яюър уы■ъш ё юЄЁшёютъющ яхЁтющ ш яюёыхфэхщ ёЄЁюъш
if (ii >= (trace_size - 1))
goto mod_new_labels_skip_2;
//-----------------------------------------------------------------
if (get_labels( pc, labels_line))
{
tprint( trace_x,
(trace_y + ii),
labels_line,
((current_back_attr & 0xF0) | 0x0E) //F)
);
//trace_y_displace++;
//trace_size_1--;
ii++;
//-------------------------------------------------------------
//if (ii >= (trace_size-1))
//if (ii == (trace_size))
// goto mod_new_labels_skip;
//-------------------------------------------------------------
cpu.trpc[ ii] = pc;
}
//-----------------------------------------------------------------
//#endif
}
//---------------------------------------------------------------------
mod_new_labels_skip_2:
//---------------------------------------------------------------------
tprint( trace_x,
(trace_y + ii), //trace_y + ii,
line,
attr1
);
mod_new_labels_skip:
//---------------------------------------------------------------------
// т√фхыхэшх яюыюцхэш ъєЁёюЁр т юъэх фшчрёьр
// ═┼ ═└ ┬╤▐ ╤╥╨╬╩╙! р Єюы№ъю т ръЄштэюь ёЄюысЎх
if (pc == cpu.trace_curs)
{
asmii = ii; // єёЄрэютър "ъєЁёюЁр яю Ёхры№эюьє яюыюцхэш■
cpu.graph_trace_cursor_pos = ii; // [NS]
//-----------------------------------------------------------------
if (activedbg == WNDTRACE)
{
//-------------------------------------------------------------
for (unsigned q = 0; q < cs[ cpu.trace_mode][ 1]; q++)
{
txtscr[ s80 * s30 +
(trace_y + ii) * s80 +
trace_x +
cs[ cpu.trace_mode][ 0] +
q
] = (DBG_ATTR_TRACE_SELECTED); //W_CURS;
}
//-------------------------------------------------------------
}
//-----------------------------------------------------------------
}
//---------------------------------------------------------------------
if (cpu.pc_trflags & TWF_BRANCH)
{
//-----------------------------------------------------------------
if (pc == cpu.pc)
{
unsigned addr = cpu.pc_trflags & 0xFFFF;
//-------------------------------------------------------------
// ёшьтюы ёЄЁхыюўъш эряЁртыхэш яхЁхїюфр
unsigned arr = (addr <= cpu.pc) ? 0x18 :
0x19; // up/down arrow
attr1 = ( (pc == cpu.trace_curs) &&
(activedbg == WNDTRACE) &&
(cpu.trace_mode == 2)
)
? // ёЄЁхыюўър эряЁртыхэш яхЁхїюфр яюф ъєЁёюЁюь
DBG_ATTR_TRACE_BRANCH_DIRECTION_INV : //W_TRACE_JINFO_CURS_FG : // 0x0D 0 br+CYAN
// ёЄЁхыюўър эряЁртыхэш
DBG_ATTR_TRACE_BRANCH_DIRECTION; //W_TRACE_JINFO_NOCURS_FG; // 0x02 0 red
//-------------------------------------------------------------
// юЄЁшёютър ёЄЁхыюўър эряЁртыхэш яхЁхїюфр ттхЁї/тэшч
if (cpu.pc_trflags & TWF_BRADDR)
{
sprintf( line,
"%04X%c",
addr,
int( arr)
);
// рфЁхё + ёЄЁхыюўър яЁш RET (5B13 C9 ret 0038^)
tprint_fg( trace_x + 32 - 5,
trace_y + ii,
line,
attr1 //ink only //color
);
}
//-------------------------------------------------------------
else
{
// ёЄЁхыюўър яЁш JP CALL (0043 2003 jr nz,0048 v)
tprint_fg( trace_x + 32 - 1,
trace_y + ii,
(char*) &arr,
attr1 //ink only //color
);
}
}
//-----------------------------------------------------------------
// ёЄЁхыюўър тючых рфЁхёр ъєфр яЁюшёїюфшЄ яхЁхїюф (5B00 F5 push af <)
if (pc == (cpu.pc_trflags & 0xFFFF))
{
unsigned arr = 0x11; // left arrow
tprint_fg( trace_x + 32 - 1,
trace_y + ii,
(char*) &arr,
DBG_ATTR_TRACE_BRANCH_DESTINATION //W_TRACE_JARROW_FOREGR //0x0D br+CYAN
);
}
//-----------------------------------------------------------------
}
//---------------------------------------------------------------------
pc += unsigned( len);
} // for (ii = 0; ii < trace_size; ii++)
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
cpu.trpc[ ii] = pc; // юсэюты хь ьрёшт рфЁхёют
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// эр тё ъшщ
cpu.trace_top &= 0xFFFF; // [NS]
cpu.trace_curs &= 0xFFFF;
//-------------------------------------------------------------------------
if (conf.trace_follow_request) // [NS]
{
//printf("trace_follow_request \n");
//---------------------------------------------------------------------
if ((!trace_follow_regs_in_view) && (conf.trace_follow_regs))
{
//printf("(!trace_PC_in_view)\n");
//-----------------------------------------------------------------
switch (conf.trace_follow_regs)
{
case REG_AF: cpu.trace_top = cpu.trace_curs = cpu.af; break;
case REG_BC: cpu.trace_top = cpu.trace_curs = cpu.bc; break;
case REG_DE: cpu.trace_top = cpu.trace_curs = cpu.de; break;
case REG_HL: cpu.trace_top = cpu.trace_curs = cpu.hl; break;
case REG_AF1: cpu.trace_top = cpu.trace_curs = cpu.alt.af; break;
case REG_BC1: cpu.trace_top = cpu.trace_curs = cpu.alt.bc; break;
case REG_DE1: cpu.trace_top = cpu.trace_curs = cpu.alt.de; break;
case REG_HL1: cpu.trace_top = cpu.trace_curs = cpu.alt.hl; break;
case REG_IX: cpu.trace_top = cpu.trace_curs = cpu.ix; break;
case REG_IY: cpu.trace_top = cpu.trace_curs = cpu.iy; break;
case REG_SP: cpu.trace_top = cpu.trace_curs = cpu.sp; break;
case REG_PC: cpu.trace_top = cpu.trace_curs = cpu.pc; break;
}
//-----------------------------------------------------------------
//cpu.trace_top = cpu.trace_curs = cpu.pc;
//printf("restart_showtrace ");
// хёыш эх эр°ыш Єюую чр ўхь ёыхфшь
goto restart_showtrace;
}
//---------------------------------------------------------------------
// хёыш эх чрўхь эх ёыхфшь Єю ёэшьрхь ЁхътхёЄ
else
{
//printf("trace_follow_request = 0;");
conf.trace_follow_request = 0;
}
}
//-------------------------------------------------------------------------
// KєЁёюЁ яюёЁхфш ъюьрэф√ !!! // [NS]
// шыш page down
if (asmii == -1U)
{
// printf("(asmii == -1U) ");
// яхЁхёЄрты хь тхЁї эр яюыюцхэшх ъєЁёюЁр ш фшчрёьшь х∙х Ёрч
//---------------------------------------------------------------------
// Page down -> ь√ фхЄхъЄшь яю эрїюцфхэш■ т яюёыхфэхщ ёЄЁюъх
// эю яюьюхьє ¤Єю т√ч√трхЄ эхъюЄюЁ√х уы■ъш (ъръшх?) 2do !!!!!
if (cpu.graph_trace_cursor_pos == (trace_size - 1))
{
cpu.trace_curs = cpu.trpc[ cpu.graph_trace_cursor_pos];
}
//---------------------------------------------------------------------
// ╩єЁёюЁ яюёЁхфш ъюьрэф√
// Єхъє∙шьш ёЁхфёЄтрьш ьюцхь юЄфшчрёьшЄ№ Єюы№ъю ъюуфр юэю т trace_top
// эєцэю яЁртшЄ№ фшчрёьхЁ фы юсЁрсюЄъш ъєЁёюЁр яюёЁхфш ъюьрэф√
else
{
cpu.graph_trace_cursor_pos = 0;
cpu.trace_top = cpu.trace_curs; //cpu.trpc[0];
//cpu.trace_curs = cpu.trpc[0];
}
//---------------------------------------------------------------------
//printf("restart_showtrace 2");
goto restart_showtrace;
}
//-------------------------------------------------------------------------
unsigned char dbuf[16];
//-------------------------------------------------------------------------
unsigned i; //Alone Coder
//-------------------------------------------------------------------------
for (/*int*/ i = 0; i < 16; i++)
dbuf[i] = cpu.DirectRm( cpu.trace_curs + i);
//-------------------------------------------------------------------------
ptrdiff_t len = disasm( dbuf,
cpu.trace_curs,
0
) - dbuf;
strcpy( asmpc, asmbuf);
//-------------------------------------------------------------------------
// юяъюф√ ъюьрэф т Ёхцшьх ЁхфръЄшЁютрэш
for (/*int*/ i = 0; i < len && i < 5; i++)
sprintf( dumppc + i * 2,
"%02X",
cpu.DirectRm(cpu.trace_curs + i)
);
//-------------------------------------------------------------------------
// яхўрЄ№ Єхъє∙хую z80
char cpu_num[ 10];
// _snprintf( cpu_num,
// sizeof( cpu_num),
// "Z80(%u)",
// CpuMgr.GetCurrentCpu()
// );
//-------------------------------------------------------------------------
if ( (CpuMgr.GetCurrentCpu()) == 0 ) // [NS]
{
sprintf( cpu_num, "ZX-CPU" );//"ZX-Z80" ); //╚ чрўхь эрь эєцэю с√ыю єурф√трЄ№ уфх ь√ ∙рё?
}
//-------------------------------------------------------------------------
else
{
sprintf( cpu_num, "GS-CPU" );//"GS-Z80" );
}
//-------------------------------------------------------------------------
tprint( trace_x,
trace_y - 1,
cpu_num,
DBG_ATTR_TRACE_CURRENT_Z80 //W_TITLE
);
//-------------------------------------------------------------------------
// яхўрЄ№ рфЁхёр яюёыхфэхую яхЁхїюфр
char lbr[ 18]; //lbr[5];
_snprintf( lbr,
sizeof( lbr),
"Last Branch(%04hX)", //"%04hX",
cpu.last_branch
);
tprint( trace_x + 8,
trace_y - 1,
lbr,
DBG_ATTR_TRACE_LAST_BRANCH //W_TITLE
);
// //-------------------------------------------------------------------------
// // Ёрьюўър ═┼═╙╞═└
// frame( trace_x,
// trace_y,
// 32,
// trace_size,
// FRAME
// );
// //-------------------------------------------------------------------------
} //void showtrace()
//=============================================================================
//=============================================================================
void c_lbl_import() //menu for importing labels from XAS/ALASM ??? // т ьхэ■ WNDTRACE фхсрухЁр
{ // ш "cpu.importl" їюЄъхщ
mon_labels.import_menu(); // ёъюЁхщ тёхую єцх ёыюьрэ?
}
//=============================================================================
/* ------------------------------------------------------------- */
static unsigned save_pos[ 8] = { -1U,-1U,-1U,-1U,-1U,-1U,-1U,-1U };
static unsigned save_cur[ 8] = { -1U,-1U,-1U,-1U,-1U,-1U,-1U,-1U };
static unsigned stack_pos[ 1024] = { -1U }; // 32] = { -1U }; 1╩ їтрЄшЄ тёхь [NS]
static unsigned stack_cur[ 1024] = { -1U }; // 32] = { -1U };
//=============================================================================
void push_pos(); //????
void push_pos()
{
Z80 &cpu = CpuMgr.Cpu();
memmove( &stack_pos[ 1], &stack_pos[ 0], sizeof stack_pos - sizeof *stack_pos);
memmove( &stack_cur[ 1], &stack_cur[ 0], sizeof stack_cur - sizeof *stack_cur);
stack_pos[ 0] = cpu.trace_top;
stack_cur[ 0] = cpu.trace_curs;
}
//=============================================================================
//=============================================================================
// ╧юыєўхэшх рфЁхёр яЁхф√фє∙хщ ъюьрэф√
// їч ъръ юэю ЁрсюЄрхЄ ш эр ёъюы№ъю Єюўэю
static unsigned cpu_up( unsigned ip)
{
Z80 &cpu = CpuMgr.Cpu();
//printf("ip = %X\n",ip);
unsigned char buf1[ 0x10];
unsigned p1 = (ip > sizeof buf1) ? ip - sizeof buf1 :
0;
//-------------------------------------------------------------------------
for (unsigned i = 0; i < sizeof buf1; i++)
buf1[ i] = cpu.DirectRm( p1 + i);
//-------------------------------------------------------------------------
const unsigned char *dispos = buf1;
const unsigned char *prev;
//-------------------------------------------------------------------------
do {
prev = dispos;
dispos = disasm( dispos, 0, 0);
} while ((unsigned)( dispos - buf1 + p1) < ip);
//-------------------------------------------------------------------------
return unsigned( prev - buf1 + p1);
}
//=============================================================================
//=============================================================================
// єёЄрЁхт°шщ goto adress т юъэх фшчрёьр // "cpu.goto" їюЄхъхщ
// Єръющ цх ъръ т юъэх ьхьюЁш тшхтхЁр
// цьхь ъэюяъє, ттюфшь рфЁхё Ёєўърьш
void cgoto()
{
Z80 &cpu = CpuMgr.Cpu();
int v = input4( trace_x, trace_y, cpu.trace_top);
//-------------------------------------------------------------------------
if (v != -1)
cpu.trace_top = cpu.trace_curs = unsigned( v);
//-------------------------------------------------------------------------
}
//=============================================================================
//=============================================================================
// SET_PC_TO_CURSOR // т ьхэ■ WNDTRACE фхсрухЁр
void csetpc() // ш "cpu.setpc" їюЄъхщ
{
Z80 &cpu = CpuMgr.Cpu();
cpu.pc = cpu.trace_curs;
}
//=============================================================================
//=============================================================================
void center() // edit instruction ???
{ //"cpu.asm" їюЄъхщ
//-------------------------------------------------------------------------
// эхы№ч ЁхфръЄшЁютрЄ№ ъюуфр ъєЁёюЁ эх эрщфхэ !!!!
// (яюёЁхфш ъюьрэф√) эєцэю ЁхфшчрёьшЄ№
if (asmii == -1U)
{
printf("asmii/trace cursor error\n");
return;
}
//-------------------------------------------------------------------------
Z80 &cpu = CpuMgr.Cpu();
//-------------------------------------------------------------------------
// addr
if (!cpu.trace_mode) // = 0
sprintf( str,
"%04X",
cpu.trace_curs
);
//-------------------------------------------------------------------------
// dump
else if (cpu.trace_mode == 1)
strcpy( str, dumppc);
//-------------------------------------------------------------------------
// disasm
else
strcpy( str, asmpc);
//-------------------------------------------------------------------------
// т ёыєўрх тїюфр т Ёхцшь ЁхфръЄшЁютрэш эрўрыюь ттюфр ЄхъёЄр
// шфхЄ юўшёЄър тёхщ ёЄЁюъш
// ═╬ center ьюцхЄ с√Є№ эх Єюы№ъю эр Enter-e !!!!!
// эєцэр яЁютхЁър шьхээю эр center hotkey
// шэрўх эхы№ч яхЁхэрчэрўшЄ№ center !!!!! [NS]
if (input.lastkey != VK_RETURN)
{
//---------------------------------------------------------------------
// яЁ ьющ ттюф чэрўхэшщ т ёЄюысЎх рфЁхёр эх юўш∙рхЄ ёЄЁюъє рфЁхёр
if (cpu.trace_mode != 0) // addr
{
*str = 0;
}
//---------------------------------------------------------------------
// °ы яр - є∙хЁсэ√щ ттюф чэрўхэш ъюЄюЁ√ь ь√ тю°ыш т Ёхцшь ЁхфръЄшЁютрэш
PostThreadMessage( GetCurrentThreadId(),
WM_KEYDOWN,
input.lastkey,
1
);
}
//-------------------------------------------------------------------------
for ( ; ; )
{
//---------------------------------------------------------------------
// asmii ъръ Ёрч Єшяю Єхъє∙шщ ъєЁёюЁ
if (!inputhex( (trace_x + cs[ cpu.trace_mode][ 0]),
(trace_y + trcurs_y + asmii), //trcurs_y тююс∙х эх шёяюы№чєхЄёю
(cs[ cpu.trace_mode][ 1]),
(cpu.trace_mode < 2), //0...1 - hex=TRUE 2 - hex=FALSE
(cpu.trace_mode == 2) ? FALSE : //ы■фёъющ ёяюёюс ттюфр ЄхъёЄр
TRUE //hex-√ цх єфюсэю ттюфшЄ№ insert-юь
)
)
{
break;
}
//---------------------------------------------------------------------
// addr
if (!cpu.trace_mode)
{
push_pos();
sscanf( str,
"%X",
&cpu.trace_top
);
cpu.trace_curs = cpu.trace_top;
//-----------------------------------------------------------------
//printf("asmii %d ",asmii);
for (unsigned i = 0; i < asmii; i++)
{
//printf("** ");
cpu.trace_top = cpu_up(cpu.trace_top);
}
//printf("\n");
//-----------------------------------------------------------------
break;
}
//---------------------------------------------------------------------
// dump
else if (cpu.trace_mode == 1)
{
char *p; //Alone Coder 0.36.7
//-----------------------------------------------------------------
for (/*char * */p = str + strlen(str) - 1; p >= str && *p == ' '; *p-- = 0);
//-----------------------------------------------------------------
unsigned char dump[8];
unsigned i;
//-----------------------------------------------------------------
for (p = str, i = 0; ishex( *p) && ishex( p[ 1]); p += 2)
dump[i++] = hex(p);
//-----------------------------------------------------------------
if (*p)
continue;
//-----------------------------------------------------------------
for (unsigned j = 0; j < i; j++)
cpu.DirectWm( cpu.trace_curs + j, dump[ j]);
//-----------------------------------------------------------------
break;
}
//---------------------------------------------------------------------
// disasm
else
{
unsigned sz = assemble_cmd( (unsigned char*) str, cpu.trace_curs);
//-----------------------------------------------------------------
if (sz)
{
//-------------------------------------------------------------
for (unsigned i = 0; i < sz; i++)
cpu.DirectWm( cpu.trace_curs + i, asmresult[ i]);
//-------------------------------------------------------------
showtrace();
void cdown();
cdown();
break;
}
//-----------------------------------------------------------------
}
}
}
//=============================================================================
//=============================================================================
char dispatch_trace() //????
{
//printf("dispatch_trace %c\n",input.lastkey);
//-------------------------------------------------------------------------
if ( (input.lastkey >= '0' && input.lastkey <= '9') || // [NS] ттюф ЎшЇЁ цю Єюц√ эєцхэ т юъэх фшчрёьр
(input.lastkey >= 'A' && input.lastkey <= 'Z')
)
{
center();
return 1;
}
//-------------------------------------------------------------------------
return 0;
}
//=============================================================================
//=============================================================================
// FIND TEXT т юъэх фшчрёьр // т ьхэ■ WNDTRACE фхсрухЁр
void cfindtext() // ш "cpu.findtext" їюЄъхщ
{
Z80 &cpu = CpuMgr.Cpu();
unsigned char oldmode = editor;
editor = ED_MEM;
int rs = find1dlg( cpu.trace_curs);
editor = oldmode;
//-------------------------------------------------------------------------
if (rs != -1)
cpu.trace_top = cpu.trace_curs = unsigned( rs);
//-------------------------------------------------------------------------
}
//=============================================================================
// FIND CODE т юъэх фшчрёьр // т ьхэ■ WNDTRACE фхсрухЁр
void cfindcode() // ш "cpu.findcode" їюЄъхщ
{
Z80 &cpu = CpuMgr.Cpu();
unsigned char oldmode = editor;
editor = ED_MEM;
int rs = find2dlg( cpu.trace_curs);
editor = oldmode;
//-------------------------------------------------------------------------
if (rs != -1)
cpu.trace_top = cpu.trace_curs = unsigned( rs);
//-------------------------------------------------------------------------
}
//=============================================================================
//=============================================================================
// set breakpoint // т ьхэ■ WNDTRACE фхсрухЁр
void cbpx() // ш "cpu.bpx" їюЄъхщ
{
Z80 &cpu = CpuMgr.Cpu();
cpu.membits[ cpu.trace_curs] ^= MEMBITS_BPX;
}
//=============================================================================v
void cbpr() // т ьхэ■ WNDTRACE фхсрухЁр
{ // [NS]
Z80 &cpu = CpuMgr.Cpu();
cpu.membits[ cpu.trace_curs] ^= MEMBITS_BPR;
}
//=============================================================================
void cbpw() // т ьхэ■ WNDTRACE фхсрухЁр
{ // [NS]
Z80 &cpu = CpuMgr.Cpu();
cpu.membits[ cpu.trace_curs] ^= MEMBITS_BPW;
}
//=============================================================================
//=============================================================================
// GOTO PC // т ьхэ■ WNDTRACE фхсрухЁр
void cfindpc() // ш "cpu.findpc" їюЄъхщ
{
//printf("cfindpc\n");
Z80 &cpu = CpuMgr.Cpu();
cpu.trace_top = cpu.trace_curs = cpu.pc;
// cup(); ш фрцх Єрър ъюэёЄЁєъЎш эх ЁрсюЄрЄхЄ
// cup(); їюЄ эх ЁрсюЄрхЄ Єюы№ъю эр Ўхяюўъх ЁрчэюўшЄрхь√ї юяъюфют?
// cup();
// cup();
// cup();
// cpu.trace_curs = cpu.pc;
//эюЁьры№эю юЄёЄєяшЄ№ ё чрярёюь эх яюыєўрхЄёю
//эрўры№э√щ рфЁхё ьюцхЄ яюярёЄ№ эр яюы ъюьрэф√
//ш ш Єюуфр рфЁхё Єхъє∙хую PC эх юЄюсЁрчшЄёю
}
//=============================================================================
//=============================================================================
// яхЁхїюф ъ рфЁхёє т юъэх фшчрёьр // [NS]
// шч юъэр фшчрёьр
void mon_goto_disasm_addr( unsigned addr)
{
// unsigned addr = cpu.af;
addr &= 0xFFFF; // юсЁхчър Єъ ьюцхЄ с√Є№ Їшуэ т√°ю
Z80 &cpu = CpuMgr.Cpu();
cpu.trace_top = cpu.trace_curs = addr;
}
void mon_goto_disasm_rAF() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.af); }
void mon_goto_disasm_rBC() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.bc); }
void mon_goto_disasm_rDE() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.de); }
void mon_goto_disasm_rHL() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.hl); }
void mon_goto_disasm_rAF1() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.alt.af); }
void mon_goto_disasm_rBC1() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.alt.bc); }
void mon_goto_disasm_rDE1() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.alt.de); }
void mon_goto_disasm_rHL1() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.alt.hl); }
void mon_goto_disasm_rIX() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.ix); }
void mon_goto_disasm_rIY() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.iy); }
void mon_goto_disasm_rSP() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.sp); }
void mon_goto_disasm_rPC() { Z80 &cpu = CpuMgr.Cpu(); mon_goto_disasm_addr( cpu.pc); }
//=============================================================================
//=============================================================================
// move cursor up (тшфшью т юъэх фшчрёьр) //"cpu.up" їюЄъхщ
void cup()
{
Z80 &cpu = CpuMgr.Cpu();
//-------------------------------------------------------------------------
// яЁюёЄющ яхЁхїюф т ёхЁхфшэх ¤ъЁрэр
if (cpu.graph_trace_cursor_pos > 0)
{
// printf("simple\n");
int prev_cpu_trace_curs = cpu.trpc[ cpu.graph_trace_cursor_pos];
cpu.graph_trace_cursor_pos--;
cpu.trace_curs = cpu.trpc[ cpu.graph_trace_cursor_pos];
//---------------------------------------------------------------------
// ╧хЁхїюф ўхЁхч ьхЄъє юЄфхы№эющ ёЄЁюъющ (фтющэющ рфЁхё) [NS]
if (prev_cpu_trace_curs == cpu.trace_curs)
{
// printf(" double\n");
//-----------------------------------------------------------------
// яхЁхїюф шч ёхЁхфшэ√ ёЄЁюъш
if (cpu.graph_trace_cursor_pos > 0)
{
// printf(" cursor > 0\n");
cpu.graph_trace_cursor_pos--;
cpu.trace_curs = cpu.trpc[ cpu.graph_trace_cursor_pos];
}
//-----------------------------------------------------------------
else
{
// printf(" cursor == 0\n");
// printf(" %x\n",cpu.trace_top);
//-------------------------------------------------------------
// ╧хЁхїюф ўхЁхч уЁрэшЎє FFFF-0000 (ъюуфр 0000 ё ьхЄъющ)
if (cpu.trace_top == 0x0000)
{
cpu.trace_top = cpu.trace_curs = cpu_up( 0x10000);
}
//-------------------------------------------------------------
// ╧хЁхїюф ъюуфр т ёрьюь тхЁїє ¤ъЁрэр рфЁхё ё ьхЄъющ
else
{
cpu.trace_top = cpu.trace_curs = cpu_up( cpu.trace_top);
}
//-------------------------------------------------------------
}
//-----------------------------------------------------------------
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
// ёъЁюыы ¤ъЁрэр Єюы№ъю ё ёрьющ тхЁїэхщ яючшЎшш
else
{
// printf("scroll\n");
//---------------------------------------------------------------------
// ╧ЁюёЄющ яхЁхїюф
if (cpu.trace_top > 0x0000)
{
// printf(" trace_top > 0\n");
cpu.trace_top = cpu.trace_curs = cpu_up( cpu.trace_top);
}
//---------------------------------------------------------------------
// ╧хЁхїюф ё 0x0000 ъ 0xFFFF
else
{
// printf(" trace_top < 0\n");
// cpu.trace_top = cpu.trace_curs = 0xFFFF;
cpu.trace_top = cpu.trace_curs = cpu_up( 0x10000);
}
//---------------------------------------------------------------------
cpu.graph_trace_cursor_pos = 0;
}
//-------------------------------------------------------------------------
// яхЁхтюф ъєЁёюЁр т ёрь√щ тхЁї т ы■сюь ёыєўрх
// cpu.trace_curs = cpu.trace_top;
// cpu.graph_trace_cursor_pos = 0;
//-------------------------------------------------------------------------
// printf("cpu.trpc -");
// for (int tmp = 0; tmp <= trace_size; tmp++)
// {
// //printf("tmp,cpu.trpc[%04d] - %04X\n",tmp,cpu.trpc[tmp]);
// printf(" %04X",cpu.trpc[tmp]);
// }
// printf("\n");
//-------------------------------------------------------------------------
cpu.trace_top &= 0xFFFF; // эр тё ъшщ ёыєўрщ
cpu.trace_curs &= 0xFFFF;
//-------------------------------------------------------------------------
return;
//-------------------------------------------------------------------------
/*
Z80 &cpu = CpuMgr.Cpu();
// printf("cpu.trace_curs %d\n",cpu.trace_curs);
// printf("cpu.trace_top %d\n",cpu.trace_top);
// printf("cup()\n");
// ьюцхЄ тююс∙х эх ЄЁюурЄ№ cpu.trace_curs, cpu.trace_top
// р ёЁрчє т√ч√трЄ№ follow PC
// їюЄ ¤Єю эртхЁэю сєфхЄ сюыхх ЁхёєЁёюхьъю
// р Єръ ьюцэю сєфхЄ ырчшЄ№ яю фшчрёьє ё чрцрЄ√ь ёЄхяюь схч яюЄхЁш ъєЁёюЁр
// шыш Єрь рєЄюёЄхя/ЄЁхщё
// эртхЁэюх Єръюх ыєў°ю т√эхёЄш эр юЄфхы№эє■ ъэюяъє?
signed int trace_top_1;
//-------------------------------------------------------------------------
if (cpu.trace_curs < 500)
{
//---------------------------------------------------------------------
if (cpu.trace_top > 0xF000)
{
printf("cpu.trace_top > 0xF000\n");
trace_top_1 = (cpu.trace_top - 0xFFFF) - 1;
}
//---------------------------------------------------------------------
else
{
printf("cpu.trace_top = normal\n");
trace_top_1 = cpu.trace_top;
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
// ъюуфр cpu.trace_top = FFFF р cpu.trace_curs = 0000
// єёыютшх эх ёЁрсрЄ√трхЄ
// ш Єюя-юь ёЄрэютшЄёю ъєЁёюЁ ёю ёЄЁр°э√ь фхЁуюёь√ъюь
//printf("cpu.trace_curs %x cpu.trace_top %x trace_top_1 %d\n",cpu.trace_curs,cpu.trace_top,trace_top_1);
signed int trace_cursor_1 = cpu.trace_curs;
// яюўхьє Єю (cpu.trace_curs > trace_top_1) эх фрхЄ true т ёыєўрх (10 > -10) o_O
// фрцх яЁш -O0
// эю т√эхёхэю т юЄфхы№эє■ яхЁхьхээє■ ЁрсююЄрхЄ
//-------------------------------------------------------------------------
// if (cpu.trace_curs > cpu.trace_top)
if ( (trace_cursor_1 > trace_top_1) &&
(cpu.trace_curs != cpu.trace_top) //фы яхЁхїюфрр ттхЁї ё тхЁїэхщ ёЄЁюъш
)
{
//printf("(cpu.trace_curs > trace_top_1) \n");
//---------------------------------------------------------------------
for (unsigned i = 1; i < trace_size; i++) //trace_size = 21
{
//printf(" i %d\n",i);
if (cpu.trpc[i] == cpu.trace_curs)
{
// printf(" cpu.trpc[i] == cpu.trace_curs\n",i);
cpu.trace_curs = cpu.trpc[i - 1];
cpu.graph_trace_cursor_pos = i - 1;
//printf ("cpu.trpc[i-1] %d\n",cpu.trpc[i-1]);
}
//printf("i %d\n",i);
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
else
{
//яхЁхїюф т√°х ёрьюую тхЁїэхую яюыюцхэш
//---------------------------------------------------------------------
if (cpu.trace_curs != 0) // [NS]
{
cpu.trace_top = cpu.trace_curs = cpu_up(cpu.trace_curs);
//printf ("1\n");
}
//---------------------------------------------------------------------
else
{
//яхЁхїюф ё 0000 ъ FFFF (Ёрэ№°х єяшЁрыюё№ ш ¤Єю фшъю схёшыю)
cpu.trace_top = cpu.trace_curs = cpu_up(0x10000);
//printf ("2\n");
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
cpu.trace_top &= 0xFFFF;
cpu.trace_curs &= 0xFFFF;
*/
} // void cup()
//=============================================================================ь
//=============================================================================
void cdown() //"cpu.down" їюЄъхщ
{
// printf("cdown()\n");
Z80 &cpu = CpuMgr.Cpu();
//-------------------------------------------------------------------------
// яЁюёЄющ яхЁхїюф т ёхЁхфшэх ¤ъЁрэр
if (cpu.graph_trace_cursor_pos < (trace_size - 1))
{
cpu.graph_trace_cursor_pos++;
cpu.trace_curs = cpu.trpc[ cpu.graph_trace_cursor_pos];
}
//-------------------------------------------------------------------------
// ёъЁюыы ¤ъЁрэр Єюы№ъю ё ёрьющ эшцэхщ яючшЎшш
else
{
// printf("== trace_size\n");
cpu.trace_top = cpu.trpc[ 1];
cpu.trace_curs = cpu.trpc[ cpu.graph_trace_cursor_pos + 1];
cpu.graph_trace_cursor_pos = trace_size;
//---------------------------------------------------------------------
// ╧хЁхїюф ўхЁхч ьхЄъє (фтющэющ рфЁхё)
if (cpu.trpc[ 0] == cpu.trpc[ 1])
{
// printf("== prev_cpu_trace_curs\n");
cpu.trace_top = cpu.trpc[ 2];
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
if (cpu.trpc[ 0] != cpu.trpc[ 1])
{
//---------------------------------------------------------------------
if (cpu.graph_trace_cursor_pos >= (trace_size - 1))
{
// printf("fix pos\n");
// cpu.trace_top = cpu.trpc[ 3];
cpu.graph_trace_cursor_pos = (trace_size - 1);
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
/*
else
{
if (cpu.graph_trace_cursor_pos >= (trace_size))
{
printf("fix pos 2\n");
//cpu.trace_top = cpu.trpc[ 3];
cpu.graph_trace_cursor_pos = (trace_size+1);
}
}
*/
/*
// ёЄрЁр ╨└┴╬╫└▀ яЁюЎхфєЁр !!!!!!!!
//-------------------------------------------------------------------------
for (unsigned i = 0; i < trace_size; i++)
{
// printf(" i %d\n",i);
//---------------------------------------------------------------------
if (cpu.trpc[ i] == cpu.trace_curs)
{
cpu.trace_curs = cpu.trpc[ i + 1];
cpu.graph_trace_cursor_pos = i + 1;
//-----------------------------------------------------------------
if (i + 1 == trace_size)
{
// printf(" (i+1 == trace_size)\n",i);
cpu.trace_top = cpu.trpc[ 1];
}
//-----------------------------------------------------------------
break;
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
*/
}
//=============================================================================
// тшфшью trace_mode 0,1,2 ¤Єю рфЁхё, юяъюф, фшчрёь ?
// ўЄю шч эшї ъЄю эрфю єЄю°э Є№
//=============================================================================
void cleft() { CpuMgr.Cpu().trace_mode--; } // "cpu.left" їюЄъхщ
//=============================================================================
void cright() { CpuMgr.Cpu().trace_mode++; } // "cpu.right" їюЄъхщ
//=============================================================================
void chere() //trace to cursor???? // т ьхэ■ WNDTRACE фхсрухЁр
{ // ш "cpu.here" їюЄъхщ
//printf("chere()\n");
Z80 &cpu = CpuMgr.Cpu();
cpu.dbgbreak = 0;
dbgbreak = 0;
cpu.dbgchk = 1;
cpu.dbg_stophere = cpu.trace_curs;
}
//=============================================================================
//=============================================================================
void cpgdn() //next page // "cpu.pgdn" їюЄъхщ
{
Z80 &cpu = CpuMgr.Cpu();
// тэрўрых яхЁхїюф ъ яюёыхфэхщ ёЄЁюъх
//-------------------------------------------------------------------------
if (cpu.graph_trace_cursor_pos < (trace_size - 1))
{
cpu.trace_curs = cpu.trpc[ trace_size - 1];
cpu.graph_trace_cursor_pos = trace_size - 1;
}
//-------------------------------------------------------------------------
// ╧хЁхїюф эр ёыхф ёЄЁрэшЎє Єюы№ъю ъюуфр ъєЁёюЁ т ёрьюь эшчє
// яю Єшяє explorer.exe
else //if (cpu.graph_trace_cursor_pos == (trace_size - 1))
{
cpu.graph_trace_cursor_pos = trace_size - 1;
//---------------------------------------------------------------------
// єяшЁрхьё т 0xFFFF
if (cpu.trace_curs == 0xFFFF)
{
cpu.trace_top = 0xFFFF - (trace_size - 1);
cpu.trace_curs = 0xFFFF;
return;
}
//---------------------------------------------------------------------
// яюёыхфэшх °руш єьхэ№°хээ√щ ш єяшЁр■Єёю т FFFF
if ((cpu.trace_top < (0xFFFF - (trace_size - 1))) && (cpu.trace_top > (0xFFFF - (2 * (trace_size - 1)) - 1)))
{
//
//FFEA_FFFE first -> FFEB_FFFF
//FFD8_FFEC
//FFD7_FFEB last -> FFEB_FFFF
cpu.trace_top = 0xFFFF - (trace_size - 1);
cpu.trace_curs = 0xFFFF;
}
//---------------------------------------------------------------------
// FFEC...FFFF эюЁьры№э√щ pddown
else
{
cpu.trace_top = cpu.trpc[ trace_size];
}
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// //-------------------------------------------------------------
// printf("cpu.trpc -");
// for (int tmp = 0; tmp <= trace_size; tmp++)
// {
// //printf("tmp,cpu.trpc[%04d] - %04X\n",tmp,cpu.trpc[tmp]);
// printf(" %04X",cpu.trpc[tmp]);
// }
// printf("\n");
// //-------------------------------------------------------------
return;
/*
Z80 &cpu = CpuMgr.Cpu();
unsigned curs = 0;
//-------------------------------------------------------------------------
for (unsigned i = 0; i < trace_size; i++)
if (cpu.trace_curs == cpu.trpc[i])
curs = i;
//-------------------------------------------------------------------------
cpu.trace_top = cpu.trpc[trace_size];
showtrace();
cpu.trace_curs = cpu.trpc[curs];
*/
}
//=============================================================================
//=============================================================================
void cpgup() //prev page // "cpu.pgup" їюЄъхщ
{
Z80 &cpu = CpuMgr.Cpu();
// printf("cursor %X\n",cpu.graph_trace_cursor_pos);
//-------------------------------------------------------------------------
// ╧хЁхїюф эр яЁхф ёЄЁрэшЎє Єюы№ъю ъюуфр ъєЁёюЁ т ёрьюь тхЁїє
// яю Єшяє explorer.exe
if ( (cpu.graph_trace_cursor_pos == 0) ||
(cpu.trace_curs == cpu.trace_top)
)
{
// printf(" cursor == 0\n");
unsigned i; //Alone Coder 0.36.7
//---------------------------------------------------------------------
// Єєяю яютЄюЁ хь 20 Ёрч :rofl: 2do !!!!!
// ═╬ т Ёхцшьх ьхЄюъ юЄфхы№эющ ёЄЁюъющ
// ъюышўхёЄтю тшфшь√ї ёЄЁюъ ьхэ№°х ўхь ёЄЁюъ фшчрёьр !!!!!
// ═╙╞═╬ яюёўшЄрЄ№ ЇръЄшўхёъюх ўшёыю єэшъры№э√ї рфЁхёют
for (i = 0; i < trace_size; i++)
{
cpu.trace_top = cpu_up( cpu.trace_top);
}
//---------------------------------------------------------------------
}
//-------------------------------------------------------------------------
// яхЁхтюф ъєЁёюЁр т ёрь√щ тхЁї т ы■сюь ёыєўрх
cpu.trace_curs = cpu.trace_top;
cpu.graph_trace_cursor_pos = 0;
//-------------------------------------------------------------------------
// printf("cpu.trpc -");
// for (int tmp = 0; tmp <= trace_size; tmp++)
// {
// //printf("tmp,cpu.trpc[%04d] - %04X\n",tmp,cpu.trpc[tmp]);
// printf(" %04X",cpu.trpc[tmp]);
// }
// printf("\n");
//-------------------------------------------------------------------------
return;
//-------------------------------------------------------------------------
// юЁшушэры№э√щ ъюф ш є∙хЁсэ√щ ш Єєую юЄырцштрхь√щ
// unsigned curs = 0;
// unsigned i; //Alone Coder 0.36.7
// //-------------------------------------------------------------------------
// for (/*unsigned*/ i = 0; i < trace_size; i++)
// if (cpu.trace_curs == cpu.trpc[i])
// curs = i;
// //-------------------------------------------------------------------------
// for (i = 0; i < trace_size; i++)
// cpu.trace_top = cpu_up(cpu.trace_top);
// //-------------------------------------------------------------------------
// showtrace();
// cpu.trace_curs = cpu.trpc[curs];
// //-------------------------------------------------------------
// printf("cpu.trpc -");
// for (int tmp = 0; tmp <= trace_size; tmp++)
// {
// //printf("tmp,cpu.trpc[%04d] - %04X\n",tmp,cpu.trpc[tmp]);
// printf(" %04X",cpu.trpc[tmp]);
// }
// printf("\n");
// //-------------------------------------------------------------
}
//=============================================================================
//=============================================================================
// pop cursor position from jumpstack // т ьхэ■ WNDTRACE фхсрухЁр
void pop_pos() // IDA mode // ш "cpu.back" їюЄъхщ
{ // back from "goto to branch destination"
// эр ёрьюь фхых ¤Єю Return to previous possition
// Єъ яхЁхїюф яю рфЁхёє яЁш ттюфх ъшфрхЄ рфЁхё т ёЄхъ
Z80 &cpu = CpuMgr.Cpu();
//-------------------------------------------------------------------------
if (stack_pos[0] == -1U)
return;
//-------------------------------------------------------------------------
cpu.trace_curs = stack_cur[ 0];
cpu.trace_top = stack_pos[ 0];
memcpy( &stack_pos[ 0], &stack_pos[ 1], sizeof stack_pos - sizeof *stack_pos);
memcpy( &stack_cur[ 0], &stack_cur[ 1], sizeof stack_cur - sizeof *stack_cur);
stack_pos[ (sizeof stack_pos / sizeof *stack_pos) - 1] = -1U;
}
//=============================================================================
//=============================================================================
// Goto Operand Address ZX/GS - ok
// push cursor position and goto instruction operand // т ьхэ■ WNDTRACE фхсрухЁр
void cjump() // IDA mode // "cpu.context" їюЄъхщ
{ // яхЁхїюф эр рфЁхё юяхЁрэфр !!!
Z80 &cpu = CpuMgr.Cpu();
char *ptr = nullptr;
//-------------------------------------------------------------------------
for (char *p = asmpc; *p; p++)
if (ishex( p[ 0]) & ishex( p[ 1]) & ishex( p[ 2]) & ishex( p[ 3]))
ptr = p;
//-------------------------------------------------------------------------
if (!ptr)
return;
//-------------------------------------------------------------------------
push_pos();
unsigned addr;
sscanf( ptr, "%04X", &addr);
cpu.trace_curs = cpu.trace_top = addr;
}
//=============================================================================
//=============================================================================
// View Operand Address ZX/GS - ok
// jump to instruction operand in data window // т ьхэ■ WNDTRACE фхсрухЁр
void cdjump() // ш "cpu.datajump" їюЄъхщ
{
char *ptr = nullptr;
//-------------------------------------------------------------------------
for (char *p = asmpc; *p; p++)
if (ishex( p[0]) & ishex( p[1]) & ishex( p[2]) & ishex( p[3]))
ptr = p;
//-------------------------------------------------------------------------
if (!ptr)
return;
//-------------------------------------------------------------------------
unsigned addr;
sscanf( ptr, "%04X", &addr);
Z80 &cpu = CpuMgr.Cpu();
cpu.mem_curs = addr;
activedbg = WNDMEM;
editor = ED_MEM;
}
//=============================================================================
//=============================================================================
// яхЁхїюф ъ рфЁхёє т юъэх ьхьюЁш тшхтхЁр ZX/GS - ok // [NS]
// шч юъэр фшчрёьр
void mon_view_mem_addr( unsigned addr)
{
// unsigned addr = cpu.af;
addr &= 0xFFFF; // юсЁхчър Єъ ьюцхЄ с√Є№ Їшуэ
Z80 &cpu = CpuMgr.Cpu();
cpu.mem_curs = addr;
activedbg = WNDMEM;
editor = ED_MEM;
}
void mon_view_mem_rAF() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.af); }
void mon_view_mem_rBC() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.bc); }
void mon_view_mem_rDE() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.de); }
void mon_view_mem_rHL() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.hl); }
void mon_view_mem_rAF1() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.alt.af); }
void mon_view_mem_rBC1() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.alt.bc); }
void mon_view_mem_rDE1() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.alt.de); }
void mon_view_mem_rHL1() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.alt.hl); }
void mon_view_mem_rIX() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.ix); }
void mon_view_mem_rIY() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.iy); }
void mon_view_mem_rSP() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.sp); }
void mon_view_mem_rPC() { Z80 &cpu = CpuMgr.Cpu(); mon_view_mem_addr( cpu.pc); }
//=============================================================================
//=============================================================================
// яюърчрЄ№/ёъЁ√Є№ labels
void cfliplabels() // т ьхэ■ WNDTRACE фхсрухЁр
{ // "cpu.labels" їюЄъхщ
trace_labels = !trace_labels;
showtrace();
}
//=============================================================================
// save cursor position to slot n
static void csave( unsigned n) //"cpu.save1"..."cpu.save8" їюЄъхш
{
Z80 &cpu = CpuMgr.Cpu();
save_pos[ n] = cpu.trace_top;
save_cur[ n] = cpu.trace_curs;
}
//=============================================================================
// save cursor position to jumpstack, load from slot 1
static void crest( unsigned n) //"cpu.rest1"..."cpu.rest8" їюЄъхш
{
Z80 &cpu = CpuMgr.Cpu();
//-------------------------------------------------------------------------
if (save_pos[n] == -1U)
return;
//-------------------------------------------------------------------------
push_pos();
cpu.trace_top = save_pos[ n];
cpu.trace_curs = save_cur[ n];
}
//=============================================================================
void csave1() { csave(0); }
void csave2() { csave(1); }
void csave3() { csave(2); }
void csave4() { csave(3); }
void csave5() { csave(4); }
void csave6() { csave(5); }
void csave7() { csave(6); }
void csave8() { csave(7); }
//=============================================================================
void crest1() { crest(0); }
void crest2() { crest(1); }
void crest3() { crest(2); }
void crest4() { crest(3); }
void crest5() { crest(4); }
void crest6() { crest(5); }
void crest7() { crest(6); }
void crest8() { crest(7); }
//=============================================================================
//=============================================================================
namespace z80dbg //????
{
void __cdecl SetLastT()
{
cpu.debug_last_t = comp.t_states + cpu.t;
}
}
//=============================================================================
float zx_step_dither = 0.0; // яю ьюхьє ¤Єю тёх фы ЁрёяЁхфхыхэш ю°шсъш [NS]
float gs_step_dither = 0.0; // яЁш ╥╚╧╬ °рурэшх zx/gs юфэютЁхьхээю
float zx_tact_dither = 0.0;
float gs_tact_dither = 0.0;
//=============================================================================
//с√т°шщ void mon_step()
void mon_step_single_cpu()
{
Z80 &cpu = CpuMgr.Cpu();
TZ80State &prevcpu = CpuMgr.PrevCpu();
cpu.SetLastT();
prevcpu = cpu;
// CpuMgr.CopyToPrev();
//-------------------------------------------------------------------------
if (cpu.t >= conf.intlen)
cpu.int_pend = false;
//-------------------------------------------------------------------------
cpu.Step();
//-------------------------------------------------------------------------
if ( (cpu.int_pend) &&
(cpu.iff1) &&
(cpu.t != cpu.eipos) && // int enabled in CPU not issued after EI
(cpu.int_gate) // int enabled by ATM hardware
)
{
handle_int( &cpu, cpu.IntVec());
}
//-------------------------------------------------------------------------
cpu.CheckNextFrame();
//-------------------------------------------------------------------------
if (conf.trace_follow_regs) // [NS]
{
//---------------------------------------------------------------------
switch (conf.trace_follow_regs)
{
case REG_AF: cpu.trace_curs = cpu.af; break;
case REG_BC: cpu.trace_curs = cpu.bc; break;
case REG_DE: cpu.trace_curs = cpu.de; break;
case REG_HL: cpu.trace_curs = cpu.hl; break;
case REG_AF1: cpu.trace_curs = cpu.alt.af; break;
case REG_BC1: cpu.trace_curs = cpu.alt.bc; break;
case REG_DE1: cpu.trace_curs = cpu.alt.de; break;
case REG_HL1: cpu.trace_curs = cpu.alt.hl; break;
case REG_IX: cpu.trace_curs = cpu.ix; break;
case REG_IY: cpu.trace_curs = cpu.iy; break;
case REG_SP: cpu.trace_curs = cpu.sp; break;
case REG_PC: cpu.trace_curs = cpu.pc; break;
}
//---------------------------------------------------------------------
conf.trace_follow_request = 1; // ёыхфютрЄ№ чр ўхь эшсєф№
}
//-------------------------------------------------------------------------
// ЄєЄ эєцэю эхёъюы№ъю Ёрч т√ч√трЄ№ step фы GS
// шыш ьюцхЄ фрцх сЁрЄ№ ЄръЄ√
// ш ∙шЄрЄ№ ёъюы№ъю ърцфюую фюыцэю с√Є№ т√чтрэю
}
//=============================================================================
// ZX+GS Step // [NS]
void mon_step()
{
//=========================================================================
if ( (conf.gs_type == 1) && // GS Z80
(conf.ZXGS_Step == 1) // тъы■ўхээюёЄ№ ёютьхёЄэюую ёЄхяр
)
{
Z80 &cpu = CpuMgr.Cpu();
// NO STATIC !!!!
int current_cpu_back = CpuMgr.GetCurrentCpu();
float zx_cpu_frq = frametime * conf.intfq;
//printf("ZX CPU %f\n",zx_cpu_frq);
//=====================================================================
// ZX Step
if (current_cpu_back == 0)
{
//printf("ZX_STEP\n");
float gs_tacts_per_1_zx = (float) z80gs::GSCPUFQ / zx_cpu_frq;
mon_step_single_cpu(); // 1 ZX Step
//printf("cpu.Delta() %d\n",cpu.Delta());
gs_tact_dither += gs_tacts_per_1_zx * (float) cpu.Delta();
//printf("gs_tact_dither %f\n",gs_tact_dither);
//-----------------------------------------------------------------
// ┬ючьюцэр Ёрчфрўр GS ю°шсъш
if (gs_tact_dither > 4.0) // яє°ю ьхэ№°х 4 ЄръЄют эхтючьюцэю °руэєЄ№
{
//CpuMgr.SwitchCpu();
CpuMgr.SetCurrentCpu( 1); // GS CPU
Z80 &cpu = CpuMgr.Cpu();
//-------------------------------------------------------------
// GS Step
while (gs_tact_dither > 4.0)
{
//printf(" gs_step\n");
mon_step_single_cpu();
//printf(" cpu.Delta() %d\n",cpu.Delta());
gs_tact_dither -= (float) cpu.Delta();
//printf(" gs_tact_dither %f\n",gs_tact_dither);
}
//-------------------------------------------------------------
//CpuMgr.SwitchCpu();
}
//-----------------------------------------------------------------
} // ZX Step
//=====================================================================
// GS Step
else
{
//printf("GS_STEP\n");
float zx_tacts_per_1_gs = zx_cpu_frq / (float) z80gs::GSCPUFQ;
mon_step_single_cpu(); // 1 GS Step
//printf("cpu.Delta() %d\n",cpu.Delta());
zx_tact_dither += zx_tacts_per_1_gs * (float) cpu.Delta();
//printf("zx_tact_dither %f\n",zx_tact_dither);
//-----------------------------------------------------------------
// ┬ючьюцэр Ёрчфрўр ZX ю°шсъш
if (zx_tact_dither > 4.0) // яє°ю ьхэ№°х 4 ЄръЄют эхтючьюцэю
{
//CpuMgr.SwitchCpu();
CpuMgr.SetCurrentCpu( 0); // ZX CPU
Z80 &cpu = CpuMgr.Cpu();
//-------------------------------------------------------------
// ZX Step
while (zx_tact_dither > 4.0)
{
//printf(" zx_step\n");
mon_step_single_cpu();
//printf(" zx cpu.Delta() %d\n",cpu.Delta());
zx_tact_dither -= (float) cpu.Delta();
//printf(" zx_tact_dither %f\n",zx_tact_dither);
}
//-------------------------------------------------------------
//CpuMgr.SwitchCpu();
}
//-----------------------------------------------------------------
} // GS Step
//=====================================================================
// ┬юёЄрэютыхэшх шёїюфэюую CPU
CpuMgr.SetCurrentCpu( current_cpu_back);
}
//=========================================================================
// эх °рурЄ№ "юфэютЁхьхээю"
else
{
mon_step_single_cpu();
}
//=========================================================================
/*
// NO STATIC !!!!
int current_cpu_back = CpuMgr.GetCurrentCpu();
//printf("cpu %x\n",current_cpu_back);
// const int GSCPUFQ = 24000000; // hz //12
// extern const unsigned GSCPUINT;
// GSINTFQ
//conf.frame
//cpu.tpi //zx?
//printf("GSINTFQ %d\n",GSINTFQ);
//printf("GSCPUINT %d\n",GSCPUINT);
//printf("GSCPUFQ %d\n",z80gs::GSCPUFQ);
//printf("frametime %d\n",frametime);
//printf("conf.intfq %d\n",conf.intfq);
float zx_cpu_frq = frametime * conf.intfq;
//printf("ZX CPU %f\n",zx_cpu_frq);
float gs_steps_per_1_zx = (float) z80gs::GSCPUFQ / zx_cpu_frq;
float zx_steps_per_1_gs = zx_cpu_frq / (float) z80gs::GSCPUFQ;
//printf("gs_steps_per_1_zx %f\n",gs_steps_per_1_zx);
//printf("zx_steps_per_1_gs %f\n",zx_steps_per_1_gs);
// STEP-√ эх єўшЄ√тр■Є ЄръЄ√ !!!
// эєцэю фхырЄ№ ё єўхЄюь ЄръЄют чр яюёыхфэшщ ёЄхя
//=========================================================================
// ZX Step
if (current_cpu_back == 0)
{
printf("ZX_STEP\n");
mon_step_single_cpu(); // 1 ZX Step
gs_step_dither += gs_steps_per_1_zx;
//printf("gs_step_dither %f\n",gs_step_dither);
//---------------------------------------------------------------------
if (gs_step_dither > 1.0)
{
CpuMgr.SwitchCpu();
while (gs_step_dither > 1.0)
{
gs_step_dither -= 1.0;
printf("gs_step\n");
mon_step_single_cpu();
}
CpuMgr.SwitchCpu();
}
//---------------------------------------------------------------------
}
//=========================================================================
// GS Step
else
{
printf("GS_STEP\n");
mon_step_single_cpu(); // 1 GS Step
zx_step_dither += zx_steps_per_1_gs;
//printf("zx_step_dither %f\n",zx_step_dither);
//---------------------------------------------------------------------
if (zx_step_dither > 1.0)
{
CpuMgr.SwitchCpu();
while (zx_step_dither > 1.0)
{
zx_step_dither -= 1.0;
printf("zx_step\n");
mon_step_single_cpu();
}
CpuMgr.SwitchCpu();
}
//---------------------------------------------------------------------
}
//=========================================================================
CpuMgr.SetCurrentCpu( current_cpu_back);
*/
}
//=============================================================================
//=============================================================================
void mon_step_x( int count)
{
mon_step();
//-------------------------------------------------------------------------
for (int temp_cnt = 0; temp_cnt < count; temp_cnt++)
{
debugscr(); // р яюўхьє эх яюёых?
debugflip();
mon_step();
}
//-------------------------------------------------------------------------
}
//=============================================================================
void mon_step_x2() { mon_step_x( 1); }
void mon_step_x4() { mon_step_x( 3); }
void mon_step_x8() { mon_step_x( 7); }
void mon_step_x16() { mon_step_x( 15); }
void mon_step_x32() { mon_step_x( 31); }
void mon_step_x64() { mon_step_x( 63); }
void mon_step_x128() { mon_step_x( 127); }
void mon_step_x256() { mon_step_x( 255); }
//=============================================================================
//#define TWF_BRANCH 0x010000U
//#define TWF_BRADDR 0x020000U
//#define TWF_LOOPCMD 0x040000U
//#define TWF_CALLCMD 0x080000U
//#define TWF_BLKCMD 0x100000U
//#define TWF_HALTCMD 0x200000U
//=============================================================================
void mon_stepover_flags( int flags)
{
Z80 &cpu = CpuMgr.Cpu();
unsigned char trace = 1;
//-------------------------------------------------------------------------
// call,rst
if (cpu.pc_trflags & TWF_CALLCMD)
{
cpu.dbg_stopsp = cpu.sp & 0xFFFF; //??????
cpu.dbg_stophere = cpu.nextpc;
trace = 0;
}
//-------------------------------------------------------------------------
// else if (cpu.pc_trflags & (TWF_BLKCMD | TWF_HALTCMD))
else if (cpu.pc_trflags & (flags)) // [NS]
{
trace = 0;
cpu.dbg_stophere = cpu.nextpc;
}
//-------------------------------------------------------------------------
/* [vv]
// jr cc,$-xx, jp cc,$-xx
else if ((cpu.pc_trflags & TWF_LOOPCMD) && (cpu.pc_trflags & 0xFFFF) < (cpu.pc & 0xFFFF))
{
cpu.dbg_stopsp = cpu.sp & 0xFFFF;
cpu.dbg_stophere = cpu.nextpc,
cpu.dbg_loop_r1 = cpu.pc_trflags & 0xFFFF;
cpu.dbg_loop_r2 = cpu.pc & 0xFFFF;
trace = 0;
}
*/
//-------------------------------------------------------------------------
/* [vv]
else if (cpu.pc_trflags & TWF_BRANCH)
trace = 1;
else
{
trace = 1;
cpu.dbg_stophere = cpu.nextpc;
}
*/
//-------------------------------------------------------------------------
//step over (step) ?
if (trace)
{
mon_step();
}
//-------------------------------------------------------------------------
//step over (call skip)
else
{
cpu.dbgbreak = 0;
dbgbreak = 0;
cpu.dbgchk = 1;
}
//-------------------------------------------------------------------------
}
//=============================================================================
void mon_stepover() // [NS]
{
// ldir/lddr|cpir/cpdr|otir/otdr|inir/indr|halt
mon_stepover_flags( TWF_BLKCMD |
TWF_HALTCMD
);
}
//=============================================================================
void mon_stepover_jump() // [NS]
{
// Єръ цх яЁюёъръштрхЄ jr cc jp cc djnz
// ═╬ эхъюЄюЁ√х єёыютш юўхэ№ Ёхфъшх
// ш trace over ьюцхЄ ┬═┼╟└╧═╬ яЁхтЁрЄшЄёю т run
// яю¤Єюьє юЄфхы№эющ ъэюяъющ
mon_stepover_flags( TWF_BLKCMD |
TWF_HALTCMD |
TWF_LOOPCMD
);
}
//=============================================================================