- [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:
+64
-34
@@ -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;
|
||||
|
||||
+20
-3
@@ -3,6 +3,26 @@
|
||||
|
||||
namespace debug
|
||||
{
|
||||
#define MEMTAG_NONE 0x00
|
||||
#define MEMTAG_DATA 0x01
|
||||
#define MEMTAG_INST 0x02
|
||||
#define MEMTAG_CODE 0x04
|
||||
#define MEMTAG_IGNORE 0x08
|
||||
#define MEMTAG_TDATA 0x10
|
||||
#define MEMTAG_TINST 0x20
|
||||
#define MEMTAG_TREPEAT 0x40
|
||||
#define MEMTAG_MODIFIED 0x80
|
||||
|
||||
#define MEMTAG_KNOWN 0x07
|
||||
#define MEMTAG_TOUCHED 0x70
|
||||
|
||||
uint8_t getTag(uint16_t address);
|
||||
void setTag(uint16_t address, uint8_t value);
|
||||
|
||||
void onInstructionExecute(uint16_t address);
|
||||
void onMemRead(uint16_t address, bool code=false);
|
||||
void onMemWrite(uint16_t address);
|
||||
|
||||
void init();
|
||||
void show();
|
||||
void focus();
|
||||
@@ -13,7 +33,6 @@ namespace debug
|
||||
void cont();
|
||||
const bool debugging();
|
||||
const bool paused();
|
||||
void setmemmodified(const uint16_t addr);
|
||||
|
||||
void refresh();
|
||||
void sendToConsole(const char* text);
|
||||
@@ -29,8 +48,6 @@ namespace debug
|
||||
void savestate(const char *filename);
|
||||
void loadstate(const char *filename);
|
||||
|
||||
void loadngo(const char* filename, const char* addr);
|
||||
|
||||
void setcursor(const uint16_t address);
|
||||
void cursorfwd();
|
||||
void cursorback();
|
||||
|
||||
@@ -53,10 +53,6 @@ namespace display
|
||||
display::incZoom();
|
||||
} else if (e->key.keysym.scancode==SDL_SCANCODE_F3) {
|
||||
display::toggleFullscreen();
|
||||
} else if (e->key.keysym.scancode==SDL_SCANCODE_F6) {
|
||||
//zx_tape::play();
|
||||
} else if (e->key.keysym.scancode==SDL_SCANCODE_F7) {
|
||||
//zx_tape::rewind();
|
||||
} else if (e->key.keysym.scancode==SDL_SCANCODE_Q && e->key.keysym.mod & KMOD_CTRL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@ namespace mem
|
||||
uint8_t wram[8192];
|
||||
uint8_t hram[512];
|
||||
|
||||
uint8_t tags[65536];
|
||||
|
||||
char *title = nullptr;
|
||||
uint8_t mapper_type = 0;
|
||||
uint32_t rom_size = 0;
|
||||
@@ -102,7 +100,6 @@ namespace mem
|
||||
for (int i=0; i<8192; ++i) { vram[i] = 0; }
|
||||
for (int i=0; i<8192; ++i) { wram[i] = 0; }
|
||||
for (int i=0; i<512; ++i) { hram[i] = 0; }
|
||||
for (int i=0; i<65536; ++i) { tags[i] = MEMTAG_NONE; }
|
||||
|
||||
resetMbc();
|
||||
apu::reset();
|
||||
@@ -188,16 +185,6 @@ namespace mem
|
||||
mem::writeMem(io_interrupts_address, mem::readMem(io_interrupts_address) | type);
|
||||
}
|
||||
|
||||
uint8_t getTag(uint16_t address)
|
||||
{
|
||||
return tags[address];
|
||||
}
|
||||
|
||||
void setTag(uint16_t address, uint8_t value)
|
||||
{
|
||||
tags[address] = value;
|
||||
}
|
||||
|
||||
void saveState(FILE* f)
|
||||
{
|
||||
|
||||
|
||||
@@ -3,19 +3,6 @@
|
||||
#include <stdio.h>
|
||||
namespace mem
|
||||
{
|
||||
#define MEMTAG_NONE 0x00
|
||||
#define MEMTAG_DATA 0x01
|
||||
#define MEMTAG_INST 0x02
|
||||
#define MEMTAG_CODE 0x04
|
||||
#define MEMTAG_IGNORE 0x08
|
||||
#define MEMTAG_TDATA 0x10
|
||||
#define MEMTAG_TINST 0x20
|
||||
#define MEMTAG_TREPEAT 0x40
|
||||
#define MEMTAG_MODIFIED 0x80
|
||||
|
||||
#define MEMTAG_KNOWN 0x07
|
||||
#define MEMTAG_TOUCHED 0x70
|
||||
|
||||
#define MBC_NONE 0
|
||||
#define MBC1 1
|
||||
#define MBC2 2
|
||||
@@ -31,9 +18,6 @@ namespace mem
|
||||
void writeMem(uint16_t address, uint8_t value);
|
||||
void requestInterrupt(uint8_t type);
|
||||
|
||||
uint8_t getTag(uint16_t address);
|
||||
void setTag(uint16_t address, uint8_t value);
|
||||
|
||||
void saveState(FILE* f);
|
||||
void loadState(FILE* f);
|
||||
|
||||
|
||||
+4
-79
@@ -70,41 +70,23 @@ namespace sm83
|
||||
bool halted = false;
|
||||
bool exit_from_halt = false;
|
||||
int pending_ei = 0;
|
||||
bool reading_m1 = false;
|
||||
|
||||
uint8_t READ_MEM_8(const uint16_t addr, const bool code=false)
|
||||
{
|
||||
if (debug::isbreak(addr, 2)) debug::stop();
|
||||
t+=4;
|
||||
|
||||
const uint8_t tag = mem::getTag(addr);
|
||||
if ( !(tag&MEMTAG_IGNORE) ) {
|
||||
if (!code) {
|
||||
if ( tag & MEMTAG_INST ) {
|
||||
} else {
|
||||
mem::setTag(addr, tag | MEMTAG_DATA);
|
||||
}
|
||||
} else {
|
||||
if ( (reading_m1) && ( tag & MEMTAG_DATA ) ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
reading_m1 = false;
|
||||
debug::onMemRead(addr, code);
|
||||
return mem::readMem(addr);
|
||||
}
|
||||
|
||||
uint8_t READ_MEM_8()
|
||||
{
|
||||
const uint8_t data = READ_MEM_8(rPC, true);
|
||||
const uint8_t tag = mem::getTag(rPC);
|
||||
if ( !(tag & MEMTAG_IGNORE) ) mem::setTag(rPC, tag | MEMTAG_CODE);
|
||||
rPC++;
|
||||
return data;
|
||||
}
|
||||
|
||||
uint8_t READ_M1()
|
||||
{
|
||||
reading_m1 = true;
|
||||
return READ_MEM_8();
|
||||
}
|
||||
|
||||
@@ -124,19 +106,7 @@ namespace sm83
|
||||
{
|
||||
t+=4;
|
||||
mem::writeMem(addr, value);
|
||||
|
||||
if (debug::isbreak(addr, 4)) debug::stop();
|
||||
debug::setmemmodified(addr);
|
||||
|
||||
const uint8_t tag = mem::getTag(addr);
|
||||
if ( !(tag & MEMTAG_IGNORE) ) {
|
||||
if ( tag & MEMTAG_INST ) {
|
||||
//printf("WARNING! WRITING DATA OVER CODE!!! $%4X\n", addr);
|
||||
//z80debug::stop();
|
||||
} else {
|
||||
mem::setTag(addr, tag | MEMTAG_DATA | MEMTAG_TDATA);
|
||||
}
|
||||
}
|
||||
debug::onMemWrite(addr);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -501,19 +471,6 @@ namespace sm83
|
||||
{
|
||||
POP(_rPC);
|
||||
if (cond != cUnconditional) t += 4;
|
||||
|
||||
/*if (options[Z80_OPTION_BREAK_ON_RET]) {
|
||||
if (calls_stacked>0) {
|
||||
calls_stacked--;
|
||||
printf("RET: calls still stacked: %i\n", calls_stacked);
|
||||
} else {
|
||||
printf("RET: BREAK\n");
|
||||
options[Z80_OPTION_BREAK_ON_RET] = false;
|
||||
z80debug::setcursor(rPC);
|
||||
z80debug::history::store();
|
||||
z80debug::stop();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,12 +506,6 @@ namespace sm83
|
||||
rPC = 0x60;
|
||||
*IF = *IF & ~gb::interrupts::JOYPAD;
|
||||
}
|
||||
/*if (options[Z80_OPTION_BREAK_ON_INTERRUPT]) {
|
||||
printf("Break on interrupt! 0x%2x, PC: 0x%2x\n", address, rPC);
|
||||
z80debug::setcursor(rPC);
|
||||
z80debug::history::store();
|
||||
z80debug::stop();
|
||||
}*/
|
||||
}
|
||||
|
||||
void RETI()
|
||||
@@ -729,21 +680,9 @@ namespace sm83
|
||||
rHL--;
|
||||
}
|
||||
|
||||
void INVALID(uint8_t opcode)
|
||||
{
|
||||
printf("INVALID OPCODE AT: %04x\n", current_opcode_address);
|
||||
//if (options[Z80_OPTION_STOP_ON_INVALID]) z80debug::stop();
|
||||
}
|
||||
|
||||
bool opcode_ignored = false;
|
||||
void IgnoreOpcode()
|
||||
{
|
||||
debug::setcursor(rPC);
|
||||
debug::history::store();
|
||||
debug::stop();
|
||||
/*t-=3;
|
||||
rPC--;
|
||||
opcode_ignored=true;*/
|
||||
}
|
||||
|
||||
void reset()
|
||||
@@ -769,21 +708,11 @@ namespace sm83
|
||||
|
||||
uint32_t step()
|
||||
{
|
||||
do {
|
||||
opcode_ignored = false;
|
||||
current_opcode_address = rPC;
|
||||
t = 0;
|
||||
const uint8_t opcode = READ_M1();
|
||||
|
||||
uint8_t tag = mem::getTag(current_opcode_address);
|
||||
if ( !(tag & MEMTAG_IGNORE) )
|
||||
tag = tag | MEMTAG_INST;
|
||||
mem::setTag(current_opcode_address, tag | (!(tag&MEMTAG_TOUCHED) ? MEMTAG_TREPEAT : MEMTAG_TINST) );
|
||||
|
||||
uint16_t tmp;
|
||||
|
||||
//if (opcode!=0xED && opcode!=0xCB && opcode!=0xDD && opcode!=0xFD ) z80debug::useOpcode(opcode, 0);
|
||||
|
||||
switch (opcode)
|
||||
{
|
||||
case 0x00: /* NOP */ break;
|
||||
@@ -1059,14 +988,12 @@ namespace sm83
|
||||
case 0xFF: RST(0x38); break;
|
||||
}
|
||||
|
||||
} while (opcode_ignored);
|
||||
|
||||
if (pending_ei==2) { pending_ei=0; actualEI(); }
|
||||
if (pending_ei==1) pending_ei=2;
|
||||
|
||||
debug::setcursor(rPC);
|
||||
debug::history::store();
|
||||
debug::onInstructionExecute(current_opcode_address);
|
||||
mem::update_mapped(t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -1074,8 +1001,6 @@ namespace sm83
|
||||
{
|
||||
const uint8_t opcode = READ_M1();
|
||||
|
||||
//z80debug::useOpcode(opcode, 2);
|
||||
|
||||
switch (opcode)
|
||||
{
|
||||
case 0x00: rB = RLC(rB); break;
|
||||
|
||||
Reference in New Issue
Block a user