- [NEW] Treballant en modularitzar la memòria, per a començar a implementar soport per als demes Spectrums
This commit is contained in:
95
z80debug.cpp
95
z80debug.cpp
@@ -2,12 +2,13 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include "z80.h"
|
||||
#include "z80dis.h"
|
||||
#include "z80mem.h"
|
||||
#include "z80analyze.h"
|
||||
#include "zx_ula.h"
|
||||
#include "zx_tape.h"
|
||||
#include "ui.h"
|
||||
#include "ui_window.h"
|
||||
#include "zx_screen.h"
|
||||
#include "z80analyze.h"
|
||||
|
||||
#define RESIZING_NONE 0
|
||||
#define RESIZING_MEMORY 1
|
||||
@@ -39,7 +40,7 @@ namespace z80debug
|
||||
uint16_t oAF, oBC, oDE, oHL, oAF2, oBC2, oDE2, oHL2, oIX, oIY, oSP, oPC;
|
||||
uint8_t oI, oR;
|
||||
|
||||
bool mem_modified[65536];
|
||||
bool mem_modified[65536]; //[CHECK]
|
||||
|
||||
SDL_Window *win = nullptr;
|
||||
SDL_Renderer *ren = nullptr;
|
||||
@@ -197,7 +198,7 @@ namespace z80debug
|
||||
const int opcodesize = z80dis::getOpcodeSize(address);
|
||||
const int byte = (chrx-19)/3;
|
||||
if (byte < opcodesize) {
|
||||
inspected_value = z80::getMem()[address+byte];
|
||||
inspected_value = z80mem::get()->readMem(address+byte);
|
||||
refresh();
|
||||
}
|
||||
// Si pasa per damunt de l'adreça en el visor de memòria
|
||||
@@ -207,13 +208,13 @@ namespace z80debug
|
||||
// Si pasa per damunt d'un byte en el visor de memòria
|
||||
} else if ((chrx>6) && (chrx<55) && (chry>mem_y) && (chry<mem_y+mem_h-1)) {
|
||||
const uint16_t address = mem_viewer_pos + (chry-mem_y-1)*16 + (chrx-7)/3;
|
||||
inspected_value = z80::getMem()[address];
|
||||
inspected_value = z80mem::get()->readMem(address);
|
||||
refresh();
|
||||
// Si pasa per damunt d'un registre
|
||||
} else if ((chrx>=midx+4) && (chrx<midx+8) && (chry==1)) { inspected_value = z80::getAF(); refresh();
|
||||
} else if ((chrx>=midx+4) && (chrx<midx+8) && (chry==2)) { inspected_value = z80::getBC(); refresh();
|
||||
} else if ((chrx>=midx+4) && (chrx<midx+8) && (chry==3)) { inspected_value = z80::getDE(); refresh();
|
||||
} else if ((chrx>=midx+4) && (chrx<midx+8) && (chry==4)) { inspected_value = z80::getHL(); refresh();
|
||||
} else if ((chrx>=midx+4) && (chrx<midx+8) && (chry==1)) { inspected_value = z80::getAF(); refresh();
|
||||
} else if ((chrx>=midx+4) && (chrx<midx+8) && (chry==2)) { inspected_value = z80::getBC(); refresh();
|
||||
} else if ((chrx>=midx+4) && (chrx<midx+8) && (chry==3)) { inspected_value = z80::getDE(); refresh();
|
||||
} else if ((chrx>=midx+4) && (chrx<midx+8) && (chry==4)) { inspected_value = z80::getHL(); refresh();
|
||||
} else if ((chrx>=midx+12) && (chrx<midx+16) && (chry==1)) { inspected_value = z80::getAF(true); refresh();
|
||||
} else if ((chrx>=midx+12) && (chrx<midx+16) && (chry==2)) { inspected_value = z80::getBC(true); refresh();
|
||||
} else if ((chrx>=midx+12) && (chrx<midx+16) && (chry==3)) { inspected_value = z80::getDE(true); refresh();
|
||||
@@ -223,9 +224,9 @@ namespace z80debug
|
||||
} else if ((chrx>=midx+20) && (chrx<midx+24) && (chry==3)) { inspected_value = z80::getSP(); refresh();
|
||||
} else if ((chrx>=midx+20) && (chrx<midx+24) && (chry==4)) { inspected_value = z80::getPC(); refresh();
|
||||
|
||||
} else if ((chrx>=midx+6) && (chrx<midx+8) && (chry==5)) { inspected_value = z80::getMem()[z80::getBC()]; refresh();
|
||||
} else if ((chrx>=midx+14) && (chrx<midx+16) && (chry==5)) { inspected_value = z80::getMem()[z80::getDE()]; refresh();
|
||||
} else if ((chrx>=midx+22) && (chrx<midx+24) && (chry==5)) { inspected_value = z80::getMem()[z80::getHL()]; refresh();
|
||||
} else if ((chrx>=midx+6) && (chrx<midx+8) && (chry==5)) { inspected_value = z80mem::get()->readMem(z80::getBC()); refresh();
|
||||
} else if ((chrx>=midx+14) && (chrx<midx+16) && (chry==5)) { inspected_value = z80mem::get()->readMem(z80::getDE()); refresh();
|
||||
} else if ((chrx>=midx+22) && (chrx<midx+24) && (chry==5)) { inspected_value = z80mem::get()->readMem(z80::getHL()); refresh();
|
||||
|
||||
} else if ((chrx>=midx+17) && (chrx<midx+19) && (chry==6)) { inspected_value = z80::getI(); refresh();
|
||||
} else if ((chrx>=midx+22) && (chrx<midx+24) && (chry==6)) { inspected_value = z80::getR(); refresh();
|
||||
@@ -392,9 +393,10 @@ namespace z80debug
|
||||
uint16_t find_previous_opcode(uint16_t pc)
|
||||
{
|
||||
pc--;
|
||||
if (z80::getMemTag(pc)!=MEMTAG_CODE && z80::getMemTag(pc)!=MEMTAG_MIXED && z80::getMemTag(pc)!=MEMTAG_INST) return pc;
|
||||
uint8_t tag = z80mem::get()->getTag(pc);
|
||||
if ( !(tag & (MEMTAG_CODE | MEMTAG_INST) ) ) return pc;
|
||||
|
||||
while (z80::getMemTag(pc)!=MEMTAG_INST) pc--;
|
||||
while ( !(z80mem::get()->getTag(pc) & MEMTAG_INST) ) pc--;
|
||||
|
||||
return pc;
|
||||
/*
|
||||
@@ -414,8 +416,9 @@ namespace z80debug
|
||||
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};
|
||||
if (z80::getMemTouched(address)!=MEMTAG_INST && z80::getMemTouched(address)!=MEMTAG_REPEAT) colors[3]=COLOR_GRAY;
|
||||
if (z80::getMemTouched(address)==MEMTAG_NONE) colors[1]=COLOR_GRAY;
|
||||
const uint8_t tag = z80mem::get()->getTag(address);
|
||||
if ( !(tag & (MEMTAG_TINST | MEMTAG_TREPEAT)) ) colors[3]=COLOR_GRAY;
|
||||
if ( !(tag & MEMTAG_TOUCHED) ) colors[1]=COLOR_GRAY;
|
||||
|
||||
if (is_debugging && (address == z80::getPC())) {
|
||||
for (int i=0; i<4;++i) colors[i]=COLOR_YELLOW;
|
||||
@@ -425,14 +428,14 @@ namespace z80debug
|
||||
if (breakpoints[address]&9) ui::printtxt(0,line,"*", colors[0]);
|
||||
ui::printtxt(1,line,tohex(address,4), colors[1]);
|
||||
|
||||
if ( (z80::getMemTag(address)==MEMTAG_INST) || heuristics ) {
|
||||
if ( (tag & MEMTAG_INST) || heuristics ) {
|
||||
const char *sym = z80dis::getSymbol(address);
|
||||
if (sym[0]!=0) ui::printtxt(7,line, sym, COLOR_YELLOW);
|
||||
|
||||
const int opcodesize = z80dis::getOpcodeSize(address);
|
||||
for (int i=0; i<opcodesize; ++i) {
|
||||
const uint8_t tag = z80::getMemTag(address+i);
|
||||
const uint32_t color = tag==MEMTAG_NONE ? COLOR_GRAY : tag==MEMTAG_DATA ? COLOR_BLUE : tag==MEMTAG_MIXED ? COLOR_MAGENTA : COLOR_GREEN;
|
||||
const uint8_t tag = z80mem::get()->getTag(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);
|
||||
}
|
||||
|
||||
@@ -440,7 +443,7 @@ namespace z80debug
|
||||
ui::printtxt(31,line, z80dis::getAsm(address), colors[3]);
|
||||
} else {
|
||||
ui::printrect(19,line,2,1,COLOR_GRAY);
|
||||
ui::printtxt(19,line, tohex(z80::getMem()[address],2), COLOR_WHITE);
|
||||
ui::printtxt(19,line, tohex(z80mem::get()->readMem(address),2), COLOR_WHITE);
|
||||
ui::printtxt(31,line, "?????????", COLOR_GRAY);
|
||||
}
|
||||
}
|
||||
@@ -461,8 +464,6 @@ namespace z80debug
|
||||
|
||||
ui::setoffset(1, 1);
|
||||
|
||||
uint8_t *memory = z80::getMem();
|
||||
|
||||
uint16_t pc = cursor; //z80::getPC();
|
||||
if (sync_mem_with_cursor) mem_viewer_pos = cursor;
|
||||
uint16_t pos = pc;
|
||||
@@ -516,9 +517,9 @@ namespace z80debug
|
||||
ui::printtxt(16,5, tohex(z80::getI(), 2), oI != z80::getI() ? COLOR_RED : COLOR_GRAY);
|
||||
ui::printtxt(21,5, tohex(z80::getR(), 2), oR != z80::getR() ? COLOR_RED : COLOR_GRAY);
|
||||
|
||||
ui::printtxt(5,4, tohex(memory[z80::getBC()], 2), COLOR_GRAY);
|
||||
ui::printtxt(13,4, tohex(memory[z80::getDE()], 2), COLOR_GRAY);
|
||||
ui::printtxt(21,4, tohex(memory[z80::getHL()], 2), COLOR_GRAY);
|
||||
ui::printtxt(5,4, tohex(z80mem::get()->readMem(z80::getBC()), 2), COLOR_GRAY);
|
||||
ui::printtxt(13,4, tohex(z80mem::get()->readMem(z80::getDE()), 2), COLOR_GRAY);
|
||||
ui::printtxt(21,4, tohex(z80mem::get()->readMem(z80::getHL()), 2), COLOR_GRAY);
|
||||
|
||||
const uint8_t flags = (z80::getAF() & 0xFF);
|
||||
const uint8_t mod_flags = flags ^ (oAF & 0xFF);
|
||||
@@ -534,8 +535,6 @@ namespace z80debug
|
||||
|
||||
// STACK
|
||||
// ******************************************
|
||||
// TODO: Save if stack element was introduced by a call, push or data
|
||||
// TODO: Click goes to address
|
||||
ui::setoffset(0, 0);
|
||||
ui::box(midx,8,11,12,COLOR_WHITE);
|
||||
ui::printrect(midx+2,8, 8,1, COLOR_DARK);
|
||||
@@ -549,7 +548,8 @@ namespace z80debug
|
||||
c1 = c2 = COLOR_YELLOW;
|
||||
}
|
||||
ui::printtxt(0,i, tohex(sp, 4), c1);
|
||||
ui::printtxt(5,i, tohex(*((uint16_t*)&memory[sp]),4), c2);
|
||||
uint16_t value = z80mem::get()->readMem(sp) + (z80mem::get()->readMem(sp+1)<<8);
|
||||
ui::printtxt(5,i, tohex(value, 4), c2);
|
||||
sp+=2;
|
||||
}
|
||||
|
||||
@@ -622,12 +622,12 @@ namespace z80debug
|
||||
ui::printtxt(1,i, tohex(mem_viewer_cursor, 4), COLOR_CYAN);
|
||||
for (int j=0; j<16; ++j) {
|
||||
|
||||
const uint8_t tag = z80::getMemTag(mem_viewer_cursor);
|
||||
const uint32_t color = tag==MEMTAG_NONE ? COLOR_GRAY : tag==MEMTAG_DATA ? COLOR_BLUE : tag==MEMTAG_MIXED ? COLOR_MAGENTA : COLOR_GREEN;
|
||||
const uint8_t tag = z80mem::get()->getTag(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);
|
||||
ui::printtxt(6+j*3, i, tohex(memory[mem_viewer_cursor],2), mem_modified[mem_viewer_cursor] ? COLOR_RED : COLOR_WHITE);
|
||||
ui::printchar(54+j, i, memory[mem_viewer_cursor], mem_modified[mem_viewer_cursor] ? COLOR_BROWN : COLOR_GRAY);
|
||||
ui::printtxt(6+j*3, i, tohex(z80mem::get()->readMem(mem_viewer_cursor), 2), ( tag & MEMTAG_MODIFIED) ? COLOR_RED : COLOR_WHITE);
|
||||
ui::printchar(54+j, i, z80mem::get()->readMem(mem_viewer_cursor), ( tag & MEMTAG_MODIFIED) ? COLOR_BROWN : COLOR_GRAY);
|
||||
mem_viewer_cursor++;
|
||||
}
|
||||
//printtxt(5,0, "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00", COLOR_WHITE);
|
||||
@@ -799,11 +799,8 @@ namespace z80debug
|
||||
z80debug::cont();
|
||||
z80analyze::refresh();
|
||||
} else if (strcmp(cmd, "r")==0 || strcmp(cmd, "reset")==0) {
|
||||
uint8_t *mem = z80::getMem();
|
||||
for (int i=0x4000; i<=0xffff; ++i) mem[i]=0;
|
||||
z80::reset(mem);
|
||||
z80::reset();
|
||||
z80::connect_port(0xfe, zx_ula::port_in, zx_ula::port_out);
|
||||
//for (int i=0; i<65536; ++i) breakpoints[i]=0;
|
||||
z80debug::refresh();
|
||||
z80analyze::refresh();
|
||||
} else if (strcmp(cmd, "b")==0 || strcmp(cmd, "break")==0) {
|
||||
@@ -883,13 +880,11 @@ namespace z80debug
|
||||
int address = getnum(cmd);
|
||||
getcmd();
|
||||
int value = getnum(cmd);
|
||||
uint8_t *mem = z80::getMem();
|
||||
mem[address] = value;
|
||||
z80mem::get()->writeMem(address, value);
|
||||
} else if (strcmp(cmd, "peek")==0) {
|
||||
getcmd();
|
||||
int address = getnum(cmd);
|
||||
uint8_t *mem = z80::getMem();
|
||||
int value = mem[address];
|
||||
int value = z80mem::get()->readMem(address);
|
||||
char tmp[10];
|
||||
sendToConsoleLog(SDL_itoa(value, tmp, 10));
|
||||
} else if (strcmp(cmd, "reg")==0) {
|
||||
@@ -907,7 +902,7 @@ namespace z80debug
|
||||
getcmd();
|
||||
int address = getnum(cmd);
|
||||
if (address<0 || address>=65536) { sendToConsoleLog("Illegal address"); return; }
|
||||
if (z80::getMemTag(address)!=MEMTAG_INST) address = find_previous_opcode(address);
|
||||
if ( !(z80mem::get()->getTag(address) & MEMTAG_INST) ) address = find_previous_opcode(address);
|
||||
z80debug::setcursor(address);
|
||||
} else if (strcmp(cmd, "sym")==0 || strcmp(cmd, "symbol")==0) {
|
||||
getcmd();
|
||||
@@ -958,8 +953,8 @@ namespace z80debug
|
||||
}
|
||||
} else if (strcmp(cmd, "ignore")==0) {
|
||||
getcmd();
|
||||
int value = getnum(cmd);
|
||||
z80::setMemTag(value, MEMTAG_IGNORE);
|
||||
const int address = getnum(cmd);
|
||||
z80mem::get()->setTag(address, z80mem::get()->getTag(address) | MEMTAG_IGNORE);
|
||||
} else if (strcmp(cmd, "search")==0) {
|
||||
getcmd();
|
||||
if (strcmp(cmd, "next")==0) {
|
||||
@@ -1007,6 +1002,7 @@ namespace z80debug
|
||||
|
||||
void loadngo(const char* filename, const char* addr)
|
||||
{
|
||||
/*
|
||||
int address = getnum(addr);
|
||||
if (address<0 || address>65536) { sendToConsoleLog("Illegal offset"); return; }
|
||||
|
||||
@@ -1014,30 +1010,30 @@ namespace z80debug
|
||||
fseek(f, 0, SEEK_END);
|
||||
int size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
uint8_t *memory = z80::getMem();
|
||||
uint32_t memsize;
|
||||
uint8_t *memory = z80mem::get()->getRawPointer(&memsize);
|
||||
fread(memory+address, size, 1, f);
|
||||
fclose(f);
|
||||
z80::setPC(address);
|
||||
is_debugging = is_paused = false;
|
||||
*/
|
||||
}
|
||||
|
||||
void savestate(const char *filename)
|
||||
{
|
||||
uint8_t *regs = z80::getRegs();
|
||||
uint8_t *memory = z80::getMem();
|
||||
FILE *f = fopen(filename, "wb");
|
||||
fwrite(regs, 31, 1, f);
|
||||
fwrite(&memory[0x4000], 0xc000, 1, f);
|
||||
z80mem::get()->saveState(f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void loadstate(const char *filename)
|
||||
{
|
||||
uint8_t *regs = z80::getRegs();
|
||||
uint8_t *memory = z80::getMem();
|
||||
FILE *f = fopen(filename, "rb");
|
||||
fread(regs, 31, 1, f);
|
||||
fread(&memory[0x4000], 0xc000, 1, f);
|
||||
z80mem::get()->loadState(f);
|
||||
fclose(f);
|
||||
history::store();
|
||||
history::gototop();
|
||||
@@ -1045,7 +1041,7 @@ namespace z80debug
|
||||
|
||||
void setcursor(const uint16_t address)
|
||||
{
|
||||
if (z80::getMemTag(address)!=MEMTAG_INST)
|
||||
if ( !(z80mem::get()->getTag(address) & MEMTAG_INST) )
|
||||
cursor = find_previous_opcode(address);
|
||||
else
|
||||
cursor = address;
|
||||
@@ -1135,9 +1131,8 @@ namespace z80debug
|
||||
while (*seq!=0) search_sequence[search_sequence_len++] = (hexchartonum(*(seq++))<<4) + hexchartonum(*(seq++));
|
||||
}
|
||||
int num_found=0;
|
||||
uint8_t *memory = z80::getMem();
|
||||
while (search_pos<65536) {
|
||||
if (search_sequence[num_found] == memory[search_pos]) {
|
||||
if (search_sequence[num_found] == z80mem::get()->readMem(search_pos)) {
|
||||
num_found++; search_pos++;
|
||||
if (num_found==search_sequence_len) {
|
||||
mem_viewer_pos=search_pos-search_sequence_len;
|
||||
|
||||
Reference in New Issue
Block a user