- [CHG] Pasada la gestió de tags de memòria de sm83 a debug

- [CHG] Netejada l'interficie debug->sm83
- [CHG] Un poc més de neteja de codi en general
This commit is contained in:
2026-06-04 19:07:30 +02:00
parent ed2c014c7e
commit 8ba37d215a
6 changed files with 357 additions and 418 deletions
+64 -34
View File
@@ -28,6 +28,8 @@ namespace debug
int con_h = 6;
int sym_h = 14;
uint8_t tags[65536];
int resizing_type = RESIZING_MEMORY;
bool resizing = false;
@@ -304,10 +306,63 @@ namespace debug
void processCommand();
uint8_t getTag(uint16_t address)
{
return tags[address];
}
void setTag(uint16_t address, uint8_t value)
{
tags[address] = value;
}
void onInstructionExecute(uint16_t address)
{
uint8_t &tag = tags[address];
if ( !(tag & MEMTAG_IGNORE) ) tag |= MEMTAG_INST;
tag |= (!(tag&MEMTAG_TOUCHED) ? MEMTAG_TREPEAT : MEMTAG_TINST);
setcursor(sm83::getPC());
history::store();
}
void onMemRead(uint16_t address, bool code)
{
if (isbreak(address, 2)) stop();
uint8_t &tag = tags[address];
if ( tag & MEMTAG_IGNORE) return;
if ( code ) {
tag |= MEMTAG_CODE;
} else if ( !(tag & MEMTAG_INST) ) {
tag |= MEMTAG_DATA;
}
}
void onMemWrite(uint16_t address)
{
if (isbreak(address, 4)) stop();
mem_modified[address] = true;
uint8_t &tag = tags[address];
if ( tag & MEMTAG_IGNORE ) return;
if ( !(tag & MEMTAG_INST) ) {
tag |= ( MEMTAG_DATA | MEMTAG_TDATA );
}
}
void init()
{
is_debugging = is_paused = false;
for (int i=0; i<65536; ++i) breakpoints[i]=0;
for (int i=0; i<65536; ++i) {
breakpoints[i]=0;
tags[i] = MEMTAG_NONE;
}
if (!cur_df) cur_df = SDL_GetCursor();
if (!cur_ns) cur_ns = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
if (!cur_we) cur_we = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
@@ -380,10 +435,9 @@ namespace debug
uint16_t find_previous_opcode(uint16_t pc)
{
pc--;
uint8_t tag = mem::getTag(pc);
if ( !(tag & (MEMTAG_CODE | MEMTAG_INST) ) ) return pc;
if ( !(tags[pc] & (MEMTAG_CODE | MEMTAG_INST) ) ) return pc;
while ( !(mem::getTag(pc) & MEMTAG_INST) ) pc--;
while ( !(tags[pc] & MEMTAG_INST) ) pc--;
return pc;
@@ -409,7 +463,7 @@ namespace debug
void printDissasemblerLine(const uint16_t address, const int line, const bool heuristics=false)
{
uint8_t colors[4] = { COLOR_RED, COLOR_CYAN, COLOR_WHITE, COLOR_WHITE};
const uint8_t tag = mem::getTag(address);
const uint8_t &tag = tags[address];
if ( !(tag & (MEMTAG_TINST | MEMTAG_TREPEAT)) ) colors[3]=COLOR_GRAY;
if ( !(tag & MEMTAG_TOUCHED) ) colors[1]=COLOR_GRAY;
@@ -427,7 +481,7 @@ namespace debug
const int opcodesize = sm83dis::getOpcodeSize(address);
for (int i=0; i<opcodesize; ++i) {
const uint8_t tag = mem::getTag(address+i);
const uint8_t &tag = tags[address+i];
const uint32_t color = !(tag & MEMTAG_KNOWN) ? COLOR_GRAY : (tag & MEMTAG_DATA) ? ( (tag & (MEMTAG_CODE|MEMTAG_INST)) ? COLOR_MAGENTA : COLOR_BLUE ) : COLOR_GREEN;
ui::printrect(19+i*3,line,2,1,color);
}
@@ -607,7 +661,7 @@ namespace debug
ui::printtxt(1,i, tohex(mem_viewer_cursor, 4), COLOR_CYAN);
for (int j=0; j<16; ++j) {
const uint8_t tag = mem::getTag(mem_viewer_cursor);
const uint8_t &tag = tags[mem_viewer_cursor];
const uint32_t color = !(tag & MEMTAG_KNOWN) ? COLOR_GRAY : (tag & MEMTAG_DATA) ? ( (tag & (MEMTAG_CODE|MEMTAG_INST)) ? COLOR_MAGENTA : COLOR_BLUE ) : COLOR_GREEN;
ui::printrect(6+j*3,i,2,1,color);
ui::printrect(54+j,i,1,1,color);
@@ -885,7 +939,7 @@ namespace debug
getcmd();
int address = getnum(cmd);
if (address<0 || address>=65536) { sendToConsoleLog("Illegal address"); return; }
if ( !(mem::getTag(address) & MEMTAG_INST) ) address = find_previous_opcode(address);
if ( !(tags[address] & MEMTAG_INST) ) address = find_previous_opcode(address);
debug::setcursor(address);
} else if (strcmp(cmd, "sym")==0 || strcmp(cmd, "symbol")==0) {
getcmd();
@@ -937,7 +991,7 @@ namespace debug
} else if (strcmp(cmd, "ignore")==0) {
getcmd();
const int address = getnum(cmd);
mem::setTag(address, mem::getTag(address) | MEMTAG_IGNORE);
tags[address] |= MEMTAG_IGNORE;
} else if (strcmp(cmd, "search")==0) {
getcmd();
if (strcmp(cmd, "next")==0) {
@@ -978,30 +1032,6 @@ namespace debug
return t;
}
void setmemmodified(const uint16_t addr)
{
mem_modified[addr] = true;
}
void loadngo(const char* filename, const char* addr)
{
/*
int address = getnum(addr);
if (address<0 || address>65536) { sendToConsoleLog("Illegal offset"); return; }
FILE *f = fopen(filename, "rb");
fseek(f, 0, SEEK_END);
int size = ftell(f);
fseek(f, 0, SEEK_SET);
uint32_t memsize;
uint8_t *memory = mem::getRawPointer(&memsize);
fread(memory+address, size, 1, f);
fclose(f);
sm83::setPC(address);
is_debugging = is_paused = false;
*/
}
void savestate(const char *filename)
{
uint8_t *regs = sm83::getRegs();
@@ -1025,7 +1055,7 @@ namespace debug
void setcursor(const uint16_t address)
{
//if (!debugging()) return;
if ( !(mem::getTag(address) & MEMTAG_INST) )
if ( !(tags[address] & MEMTAG_INST) )
cursor = find_previous_opcode(address);
else
cursor = address;