- [FIX] Corregit el acces als port amb OUT
- [NEW] Nou model de gestió de memòria
This commit is contained in:
27
main.cpp
27
main.cpp
@@ -12,14 +12,14 @@
|
||||
#include "ui_menu.h"
|
||||
#include "z80analyze.h"
|
||||
#include "ui_window.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_48mem.h"
|
||||
#include "zx_128mem.h"
|
||||
#include "zx_mem.h"
|
||||
//#include "zx_48mem.h"
|
||||
//#include "zx_128mem.h"
|
||||
#include "z80viewer.h"
|
||||
#include "zx_128bankviewer.h"
|
||||
#include "zx_128pageviewer.h"
|
||||
//#include "zx_128bankviewer.h"
|
||||
//#include "zx_128pageviewer.h"
|
||||
|
||||
uint8_t memory[65536];
|
||||
//uint8_t memory[65536];
|
||||
uint32_t time = 0;
|
||||
uint32_t t_states = 0;
|
||||
|
||||
@@ -82,7 +82,8 @@ int main(int argc, char *argv[])
|
||||
const uint32_t update_freq = clock / 10;
|
||||
|
||||
//new zx_48mem();
|
||||
new zx_128mem();
|
||||
//new zx_128mem();
|
||||
mem::init(ZX_128K);
|
||||
|
||||
z80dis::loadSymbols();
|
||||
z80::reset();
|
||||
@@ -93,13 +94,13 @@ int main(int argc, char *argv[])
|
||||
//zxscreen::init(SCREEN_MODE_48K);
|
||||
zxscreen::init(SCREEN_MODE_128K);
|
||||
|
||||
z80viewer *v = new zx_128bankviewer();
|
||||
v->show();
|
||||
z80viewer::registerViewer("128BANK", v);
|
||||
//z80viewer *v = new zx_128bankviewer();
|
||||
//v->show();
|
||||
//z80viewer::registerViewer("128BANK", v);
|
||||
|
||||
v = new zx_128pageviewer();
|
||||
v->show();
|
||||
z80viewer::registerViewer("128PAGE", v);
|
||||
//v = new zx_128pageviewer();
|
||||
//v->show();
|
||||
//z80viewer::registerViewer("128PAGE", v);
|
||||
|
||||
ui::menu::init();
|
||||
ui::menu::setexitcallback(actions::exitMenu);
|
||||
|
||||
27
z80.cpp
27
z80.cpp
@@ -1,6 +1,6 @@
|
||||
#include "z80.h"
|
||||
#include "z80debug.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_mem.h"
|
||||
//#include "zx_tape.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -153,14 +153,14 @@ namespace z80
|
||||
{
|
||||
if (z80debug::isbreak(addr, 2)) z80debug::stop();
|
||||
t+=3;
|
||||
const uint8_t tag = z80mem::get()->getTag(addr);
|
||||
const uint8_t tag = mem::getTag(addr);
|
||||
if ( !(tag&MEMTAG_IGNORE) ) {
|
||||
if (!code) {
|
||||
if ( tag & MEMTAG_INST ) {
|
||||
//printf("WARNING! READING DATA FROM CODE!!! $%4X\n", addr);
|
||||
//z80debug::stop();
|
||||
} else {
|
||||
z80mem::get()->setTag(addr, tag | MEMTAG_DATA);
|
||||
mem::setTag(addr, tag | MEMTAG_DATA);
|
||||
}
|
||||
} else {
|
||||
if ( (reading_m1) && ( tag & MEMTAG_DATA ) ) {
|
||||
@@ -170,14 +170,14 @@ namespace z80
|
||||
}
|
||||
}
|
||||
reading_m1 = false;
|
||||
return z80mem::get()->readMem(addr);
|
||||
return mem::readMem(addr);
|
||||
}
|
||||
|
||||
uint8_t READ_MEM_8()
|
||||
{
|
||||
const uint8_t data = READ_MEM_8(rPC, true);
|
||||
const uint8_t tag = z80mem::get()->getTag(rPC);
|
||||
if ( !(tag & MEMTAG_IGNORE) ) z80mem::get()->setTag(rPC, tag | MEMTAG_CODE);
|
||||
const uint8_t tag = mem::getTag(rPC);
|
||||
if ( !(tag & MEMTAG_IGNORE) ) mem::setTag(rPC, tag | MEMTAG_CODE);
|
||||
rPC++;
|
||||
return data;
|
||||
}
|
||||
@@ -208,18 +208,18 @@ namespace z80
|
||||
const uint8_t WRITE_MEM_8(const uint16_t addr, const uint8_t value)
|
||||
{
|
||||
t+=3;
|
||||
if (addr>=0x4000) z80mem::get()->writeMem(addr, value);
|
||||
if (addr>=0x4000) mem::writeMem(addr, value);
|
||||
if (z80debug::isbreak(addr, 4)) z80debug::stop();
|
||||
//if (z80debug::debugging())
|
||||
z80debug::setmemmodified(addr);
|
||||
|
||||
const uint8_t tag = z80mem::get()->getTag(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 {
|
||||
z80mem::get()->setTag(addr, tag | MEMTAG_DATA | MEMTAG_TDATA);
|
||||
mem::setTag(addr, tag | MEMTAG_DATA | MEMTAG_TDATA);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1008,7 +1008,8 @@ namespace z80
|
||||
t+=4;
|
||||
if (port == 0x10000) {
|
||||
port = rBC;
|
||||
if (rC==0xfe) port = 0xfe;
|
||||
} else {
|
||||
port = (rA<<8) | port;
|
||||
}
|
||||
if (out_ports[port&0xff]) out_ports[port&0xff](port, val);
|
||||
}
|
||||
@@ -1125,7 +1126,7 @@ namespace z80
|
||||
out_ports[i] = nullptr;
|
||||
}
|
||||
|
||||
z80mem::get()->reset();
|
||||
mem::reset();
|
||||
|
||||
rPC = iff1 = iff2 = im = 0;
|
||||
rAF = rAF2 = rBC = rBC2 = rDE = rDE2 = rHL = rHL2 = rIX = rIY = rSP = 0xffff;
|
||||
@@ -1164,10 +1165,10 @@ namespace z80
|
||||
t = 0;
|
||||
const uint8_t opcode = READ_M1();
|
||||
|
||||
uint8_t tag = z80mem::get()->getTag(current_opcode_address);
|
||||
uint8_t tag = mem::getTag(current_opcode_address);
|
||||
if ( !(tag & MEMTAG_IGNORE) )
|
||||
tag = tag | MEMTAG_INST;
|
||||
z80mem::get()->setTag(current_opcode_address, tag | (!(tag&MEMTAG_TOUCHED) ? MEMTAG_TREPEAT : MEMTAG_TINST) );
|
||||
mem::setTag(current_opcode_address, tag | (!(tag&MEMTAG_TOUCHED) ? MEMTAG_TREPEAT : MEMTAG_TINST) );
|
||||
|
||||
uint16_t tmp;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "z80analyze.h"
|
||||
#include "z80.h"
|
||||
#include "z80debug.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_mem.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "ui_window.h"
|
||||
#include "ui.h"
|
||||
@@ -53,9 +53,9 @@ namespace z80analyze
|
||||
z80debug::refresh();
|
||||
*/
|
||||
} else if (e->key.keysym.scancode == SDL_SCANCODE_BACKSPACE) {
|
||||
const uint32_t size = z80mem::get()->getSize();
|
||||
//for (int i=0; i<size; ++i) z80mem::get()->setTag(i, z80mem::get()->getTag(i) & ~MEMTAG_TOUCHED);
|
||||
for (int i=0; i<size; ++i) z80mem::get()->setTag(i, MEMTAG_NONE);
|
||||
const uint32_t size = mem::getSize();
|
||||
//for (int i=0; i<size; ++i) mem::setTag(i, mem::getTag(i) & ~MEMTAG_TOUCHED);
|
||||
for (int i=0; i<size; ++i) mem::setTag(i, MEMTAG_NONE);
|
||||
refresh();
|
||||
z80debug::refresh();
|
||||
}
|
||||
@@ -102,7 +102,7 @@ namespace z80analyze
|
||||
//uint8_t tag = z80::getMemTag(i);
|
||||
//pixels[i] = tag==MEMTAG_NONE ? 0x808080 : tag==MEMTAG_DATA ? 0x0000FF : tag==MEMTAG_MIXED ? 0xFF00FF : 0x00FF00;
|
||||
uint32_t none_color = i<0x4000 ? 0x101010 : i<0x5800 ? 0x202020 : i<0x5b00 ? 0x404040 : 0x808080;
|
||||
uint8_t tag = z80mem::get()->getTag(i);
|
||||
uint8_t tag = mem::getTag(i);
|
||||
pixels[i] = !(tag & MEMTAG_TOUCHED) ? none_color : (tag & MEMTAG_TINST) ? 0x00FF00 : (tag & MEMTAG_TREPEAT) ? 0xFF0000 : 0x0000FF;
|
||||
}
|
||||
pixels[z80::getPC()] = 0xFFFFFF;
|
||||
|
||||
54
z80debug.cpp
54
z80debug.cpp
@@ -2,7 +2,7 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include "z80.h"
|
||||
#include "z80dis.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_mem.h"
|
||||
#include "z80analyze.h"
|
||||
#include "zx_ula.h"
|
||||
#include "zx_tape.h"
|
||||
@@ -198,7 +198,7 @@ namespace z80debug
|
||||
const int opcodesize = z80dis::getOpcodeSize(address);
|
||||
const int byte = (chrx-19)/3;
|
||||
if (byte < opcodesize) {
|
||||
inspected_value = z80mem::get()->readMem(address+byte);
|
||||
inspected_value = mem::readMem(address+byte);
|
||||
refresh();
|
||||
}
|
||||
// Si pasa per damunt de l'adreça en el visor de memòria
|
||||
@@ -208,7 +208,7 @@ 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 = z80mem::get()->readMem(address);
|
||||
inspected_value = mem::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();
|
||||
@@ -224,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 = 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+6) && (chrx<midx+8) && (chry==5)) { inspected_value = mem::readMem(z80::getBC()); refresh();
|
||||
} else if ((chrx>=midx+14) && (chrx<midx+16) && (chry==5)) { inspected_value = mem::readMem(z80::getDE()); refresh();
|
||||
} else if ((chrx>=midx+22) && (chrx<midx+24) && (chry==5)) { inspected_value = mem::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();
|
||||
@@ -393,10 +393,10 @@ namespace z80debug
|
||||
uint16_t find_previous_opcode(uint16_t pc)
|
||||
{
|
||||
pc--;
|
||||
uint8_t tag = z80mem::get()->getTag(pc);
|
||||
uint8_t tag = mem::getTag(pc);
|
||||
if ( !(tag & (MEMTAG_CODE | MEMTAG_INST) ) ) return pc;
|
||||
|
||||
while ( !(z80mem::get()->getTag(pc) & MEMTAG_INST) ) pc--;
|
||||
while ( !(mem::getTag(pc) & MEMTAG_INST) ) pc--;
|
||||
|
||||
return pc;
|
||||
/*
|
||||
@@ -416,7 +416,7 @@ 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};
|
||||
const uint8_t tag = z80mem::get()->getTag(address);
|
||||
const uint8_t tag = mem::getTag(address);
|
||||
if ( !(tag & (MEMTAG_TINST | MEMTAG_TREPEAT)) ) colors[3]=COLOR_GRAY;
|
||||
if ( !(tag & MEMTAG_TOUCHED) ) colors[1]=COLOR_GRAY;
|
||||
|
||||
@@ -434,7 +434,7 @@ namespace z80debug
|
||||
|
||||
const int opcodesize = z80dis::getOpcodeSize(address);
|
||||
for (int i=0; i<opcodesize; ++i) {
|
||||
const uint8_t tag = z80mem::get()->getTag(address+i);
|
||||
const uint8_t tag = mem::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);
|
||||
}
|
||||
@@ -443,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(z80mem::get()->readMem(address),2), COLOR_WHITE);
|
||||
ui::printtxt(19,line, tohex(mem::readMem(address),2), COLOR_WHITE);
|
||||
ui::printtxt(31,line, "?????????", COLOR_GRAY);
|
||||
}
|
||||
}
|
||||
@@ -517,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(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);
|
||||
ui::printtxt(5,4, tohex(mem::readMem(z80::getBC()), 2), COLOR_GRAY);
|
||||
ui::printtxt(13,4, tohex(mem::readMem(z80::getDE()), 2), COLOR_GRAY);
|
||||
ui::printtxt(21,4, tohex(mem::readMem(z80::getHL()), 2), COLOR_GRAY);
|
||||
|
||||
const uint8_t flags = (z80::getAF() & 0xFF);
|
||||
const uint8_t mod_flags = flags ^ (oAF & 0xFF);
|
||||
@@ -548,7 +548,7 @@ namespace z80debug
|
||||
c1 = c2 = COLOR_YELLOW;
|
||||
}
|
||||
ui::printtxt(0,i, tohex(sp, 4), c1);
|
||||
uint16_t value = z80mem::get()->readMem(sp) + (z80mem::get()->readMem(sp+1)<<8);
|
||||
uint16_t value = mem::readMem(sp) + (mem::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 = z80mem::get()->getTag(mem_viewer_cursor);
|
||||
const uint8_t tag = mem::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(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);
|
||||
ui::printtxt(6+j*3, i, tohex(mem::readMem(mem_viewer_cursor), 2), ( tag & MEMTAG_MODIFIED) ? COLOR_RED : COLOR_WHITE);
|
||||
ui::printchar(54+j, i, mem::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);
|
||||
@@ -881,11 +881,11 @@ namespace z80debug
|
||||
int address = getnum(cmd);
|
||||
getcmd();
|
||||
int value = getnum(cmd);
|
||||
z80mem::get()->writeMem(address, value);
|
||||
mem::writeMem(address, value);
|
||||
} else if (strcmp(cmd, "peek")==0) {
|
||||
getcmd();
|
||||
int address = getnum(cmd);
|
||||
int value = z80mem::get()->readMem(address);
|
||||
int value = mem::readMem(address);
|
||||
char tmp[10];
|
||||
sendToConsoleLog(SDL_itoa(value, tmp, 10));
|
||||
} else if (strcmp(cmd, "reg")==0) {
|
||||
@@ -904,7 +904,7 @@ namespace z80debug
|
||||
getcmd();
|
||||
int address = getnum(cmd);
|
||||
if (address<0 || address>=65536) { sendToConsoleLog("Illegal address"); return; }
|
||||
if ( !(z80mem::get()->getTag(address) & MEMTAG_INST) ) address = find_previous_opcode(address);
|
||||
if ( !(mem::getTag(address) & MEMTAG_INST) ) address = find_previous_opcode(address);
|
||||
z80debug::setcursor(address);
|
||||
} else if (strcmp(cmd, "sym")==0 || strcmp(cmd, "symbol")==0) {
|
||||
getcmd();
|
||||
@@ -956,7 +956,7 @@ namespace z80debug
|
||||
} else if (strcmp(cmd, "ignore")==0) {
|
||||
getcmd();
|
||||
const int address = getnum(cmd);
|
||||
z80mem::get()->setTag(address, z80mem::get()->getTag(address) | MEMTAG_IGNORE);
|
||||
mem::setTag(address, mem::getTag(address) | MEMTAG_IGNORE);
|
||||
} else if (strcmp(cmd, "search")==0) {
|
||||
getcmd();
|
||||
if (strcmp(cmd, "next")==0) {
|
||||
@@ -1013,7 +1013,7 @@ namespace z80debug
|
||||
int size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
uint32_t memsize;
|
||||
uint8_t *memory = z80mem::get()->getRawPointer(&memsize);
|
||||
uint8_t *memory = mem::getRawPointer(&memsize);
|
||||
fread(memory+address, size, 1, f);
|
||||
fclose(f);
|
||||
z80::setPC(address);
|
||||
@@ -1026,7 +1026,7 @@ namespace z80debug
|
||||
uint8_t *regs = z80::getRegs();
|
||||
FILE *f = fopen(filename, "wb");
|
||||
fwrite(regs, 31, 1, f);
|
||||
z80mem::get()->saveState(f);
|
||||
mem::saveState(f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
@@ -1035,7 +1035,7 @@ namespace z80debug
|
||||
uint8_t *regs = z80::getRegs();
|
||||
FILE *f = fopen(filename, "rb");
|
||||
fread(regs, 31, 1, f);
|
||||
z80mem::get()->loadState(f);
|
||||
mem::loadState(f);
|
||||
fclose(f);
|
||||
history::store();
|
||||
history::gototop();
|
||||
@@ -1044,7 +1044,7 @@ namespace z80debug
|
||||
void setcursor(const uint16_t address)
|
||||
{
|
||||
//if (!debugging()) return;
|
||||
if ( !(z80mem::get()->getTag(address) & MEMTAG_INST) )
|
||||
if ( !(mem::getTag(address) & MEMTAG_INST) )
|
||||
cursor = find_previous_opcode(address);
|
||||
else
|
||||
cursor = address;
|
||||
@@ -1135,7 +1135,7 @@ namespace z80debug
|
||||
}
|
||||
int num_found=0;
|
||||
while (search_pos<65536) {
|
||||
if (search_sequence[num_found] == z80mem::get()->readMem(search_pos)) {
|
||||
if (search_sequence[num_found] == mem::readMem(search_pos)) {
|
||||
num_found++; search_pos++;
|
||||
if (num_found==search_sequence_len) {
|
||||
mem_viewer_pos=search_pos-search_sequence_len;
|
||||
|
||||
46
z80dis.cpp
46
z80dis.cpp
@@ -1,6 +1,6 @@
|
||||
#include "z80dis.h"
|
||||
#include "z80.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_mem.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
@@ -69,31 +69,31 @@ namespace z80dis
|
||||
|
||||
const char *getBase(const uint16_t pos)
|
||||
{
|
||||
if (z80mem::get()->readMem(pos) == 0xCB) {
|
||||
if (mem::readMem(pos) == 0xCB) {
|
||||
opcode_size=2;
|
||||
return cb_opcodes[z80mem::get()->readMem(pos+1)];
|
||||
} else if (z80mem::get()->readMem(pos) == 0xDD) {
|
||||
if (z80mem::get()->readMem(pos+1) == 0xCB) {
|
||||
return cb_opcodes[mem::readMem(pos+1)];
|
||||
} else if (mem::readMem(pos) == 0xDD) {
|
||||
if (mem::readMem(pos+1) == 0xCB) {
|
||||
opcode_size=4;
|
||||
return ix_bit_opcodes[z80mem::get()->readMem(pos+3)];
|
||||
return ix_bit_opcodes[mem::readMem(pos+3)];
|
||||
} else {
|
||||
opcode_size=2;
|
||||
return ix_opcodes[z80mem::get()->readMem(pos+1)];
|
||||
return ix_opcodes[mem::readMem(pos+1)];
|
||||
}
|
||||
} else if (z80mem::get()->readMem(pos) == 0xED) {
|
||||
} else if (mem::readMem(pos) == 0xED) {
|
||||
opcode_size=2;
|
||||
return misc_opcodes[(z80mem::get()->readMem(pos+1))-64];
|
||||
} else if (z80mem::get()->readMem(pos) == 0xFD) {
|
||||
if (z80mem::get()->readMem(pos+1) == 0xCB) {
|
||||
return misc_opcodes[(mem::readMem(pos+1))-64];
|
||||
} else if (mem::readMem(pos) == 0xFD) {
|
||||
if (mem::readMem(pos+1) == 0xCB) {
|
||||
opcode_size=4;
|
||||
return iy_bit_opcodes[z80mem::get()->readMem(pos+3)];
|
||||
return iy_bit_opcodes[mem::readMem(pos+3)];
|
||||
} else {
|
||||
opcode_size=2;
|
||||
return iy_opcodes[z80mem::get()->readMem(pos+1)];
|
||||
return iy_opcodes[mem::readMem(pos+1)];
|
||||
}
|
||||
} else {
|
||||
opcode_size=1;
|
||||
return base_opcodes[z80mem::get()->readMem(pos)];
|
||||
return base_opcodes[mem::readMem(pos)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace z80dis
|
||||
for (int i=0; i<4;++i)
|
||||
{
|
||||
if (opcode_size>i)
|
||||
sprintf(hex, "%02x ", z80mem::get()->readMem(pos+i));
|
||||
sprintf(hex, "%02x ", mem::readMem(pos+i));
|
||||
else
|
||||
sprintf(hex, " ");
|
||||
strcat(buffer, hex);
|
||||
@@ -119,9 +119,9 @@ namespace z80dis
|
||||
if (strstr(buffer, "4x"))
|
||||
{
|
||||
opcode_size+=2;
|
||||
const uint8_t memvalue = z80mem::get()->readMem(pos);
|
||||
const uint8_t memvalue = mem::readMem(pos);
|
||||
const uint16_t address = pos + ((memvalue==0xFD) || (memvalue==0xDD) || (memvalue==0xED)?2:1);
|
||||
const uint16_t word = z80mem::get()->readMem(address) + (z80mem::get()->readMem(address+1)<<8);
|
||||
const uint16_t word = mem::readMem(address) + (mem::readMem(address+1)<<8);
|
||||
if (symbols[word][0]!=0) {
|
||||
char *p = strstr(buffer, "$");
|
||||
(*p)='%'; p++;
|
||||
@@ -142,7 +142,7 @@ namespace z80dis
|
||||
{
|
||||
opcode_size = 4;
|
||||
strcpy(base, buffer);
|
||||
sprintf(buffer, base, z80mem::get()->readMem(pos+2), (int8_t)z80mem::get()->readMem(pos+3));
|
||||
sprintf(buffer, base, mem::readMem(pos+2), (int8_t)mem::readMem(pos+3));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace z80dis
|
||||
{
|
||||
opcode_size+=1;
|
||||
strcpy(base, buffer);
|
||||
sprintf(buffer, base, z80mem::get()->readMem(pos+1));
|
||||
sprintf(buffer, base, mem::readMem(pos+1));
|
||||
}
|
||||
|
||||
if (strstr(buffer, "Xx"))
|
||||
@@ -161,9 +161,9 @@ namespace z80dis
|
||||
|
||||
if (opcode_size>4) {
|
||||
opcode_size=4;
|
||||
sprintf(buffer, base, pos + opcode_size + (int8_t)z80mem::get()->readMem(pos+2));
|
||||
sprintf(buffer, base, pos + opcode_size + (int8_t)mem::readMem(pos+2));
|
||||
} else {
|
||||
sprintf(buffer, base, pos + opcode_size + (int8_t)z80mem::get()->readMem(pos+1));
|
||||
sprintf(buffer, base, pos + opcode_size + (int8_t)mem::readMem(pos+1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,9 +173,9 @@ namespace z80dis
|
||||
strcpy(base, buffer);
|
||||
if (opcode_size>4) {
|
||||
opcode_size=4;
|
||||
sprintf(buffer, base, (int8_t)z80mem::get()->readMem(pos+3));
|
||||
sprintf(buffer, base, (int8_t)mem::readMem(pos+3));
|
||||
} else {
|
||||
sprintf(buffer, base, (int8_t)z80mem::get()->readMem(pos+2));
|
||||
sprintf(buffer, base, (int8_t)mem::readMem(pos+2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/*
|
||||
#include "z80mem.h"
|
||||
|
||||
z80mem* z80mem::singleton= nullptr;
|
||||
*/
|
||||
2
z80mem.h
2
z80mem.h
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -42,3 +43,4 @@ class z80mem
|
||||
|
||||
static z80mem *singleton;
|
||||
};
|
||||
*/
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "zx_128bankviewer.h"
|
||||
#include "z80.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_128mem.h"
|
||||
#include "zx_mem.h"
|
||||
//#include "zx_128mem.h"
|
||||
#include "ui.h"
|
||||
//#include "ui_window.h"
|
||||
|
||||
@@ -34,7 +34,7 @@ void zx_128bankviewer::refresh()
|
||||
//uint8_t tag = z80::getMemTag(i);
|
||||
//pixels[i] = tag==MEMTAG_NONE ? 0x808080 : tag==MEMTAG_DATA ? 0x0000FF : tag==MEMTAG_MIXED ? 0xFF00FF : 0x00FF00;
|
||||
uint32_t none_color = i<0x4000 ? 0x101010 : i<0x5800 ? 0x202020 : i<0x5b00 ? 0x404040 : 0x808080;
|
||||
uint8_t tag = z80mem::get()->getTag(i);
|
||||
uint8_t tag = mem::getTag(i);
|
||||
pixels[i] = !(tag & MEMTAG_TOUCHED) ? none_color : (tag & MEMTAG_TINST) ? 0x00FF00 : (tag & MEMTAG_TREPEAT) ? 0xFF0000 : 0x0000FF;
|
||||
}
|
||||
pixels[z80::getPC()] = 0xFFFFFF;
|
||||
@@ -42,6 +42,7 @@ void zx_128bankviewer::refresh()
|
||||
SDL_UnlockTexture(tex);
|
||||
SDL_RenderCopy(ren, tex, NULL, NULL);
|
||||
|
||||
/*
|
||||
char temp[256];
|
||||
zx_128mem* mem = ((zx_128mem*)z80mem::get());
|
||||
sprintf(temp, "%u", mem->getPage(0));
|
||||
@@ -52,6 +53,7 @@ void zx_128bankviewer::refresh()
|
||||
ui::placetxt(1,257,temp, COLOR_WHITE);
|
||||
sprintf(temp, "%u", mem->getPage(3));
|
||||
ui::placetxt(1,385,temp, COLOR_WHITE);
|
||||
*/
|
||||
|
||||
SDL_RenderPresent(ren);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
#include "zx_128mem.h"
|
||||
#include "z80mem.h"
|
||||
#include "z80.h"
|
||||
@@ -187,3 +188,4 @@ bool zx_128mem::getShadowScreen()
|
||||
{
|
||||
return config & ZX_128MEM_SCREEN;
|
||||
}
|
||||
*/
|
||||
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
#pragma once
|
||||
#include "z80mem.h"
|
||||
|
||||
@@ -40,3 +41,4 @@ class zx_128mem : public z80mem
|
||||
uint8_t romtags[32768];
|
||||
|
||||
};
|
||||
*/
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "zx_128pageviewer.h"
|
||||
#include "z80.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_mem.h"
|
||||
|
||||
void zx_128pageviewer::show()
|
||||
{
|
||||
@@ -22,7 +22,7 @@ void zx_128pageviewer::refresh()
|
||||
|
||||
Uint32 *pixels;
|
||||
int pitch;
|
||||
const uint8_t *tags = z80mem::get()->rawTagPtr(0);
|
||||
const uint8_t *tags = mem::rawTagPtr(0);
|
||||
SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch);
|
||||
for (int i=0; i<131072; ++i)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
#include "zx_48mem.h"
|
||||
#include "z80mem.h"
|
||||
#include <string.h>
|
||||
@@ -67,4 +68,5 @@ uint8_t *zx_48mem::rawPtr(uint32_t address)
|
||||
uint8_t *zx_48mem::rawTagPtr(uint32_t address)
|
||||
{
|
||||
return &tags[address];
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
#pragma once
|
||||
#include "z80mem.h"
|
||||
|
||||
@@ -30,3 +31,4 @@ class zx_48mem : public z80mem
|
||||
uint8_t tags[65536];
|
||||
|
||||
};
|
||||
*/
|
||||
161
zx_mem.cpp
Normal file
161
zx_mem.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
#include "zx_mem.h"
|
||||
#include "stdlib.h"
|
||||
#include "z80.h"
|
||||
#include "zx_screen.h"
|
||||
|
||||
#define ZX_128MEM_PAGE 0x07
|
||||
#define ZX_128MEM_SCREEN 0x08
|
||||
#define ZX_128MEM_ROM 0x10
|
||||
#define ZX_128MEM_DISPAG 0x20
|
||||
|
||||
namespace mem
|
||||
{
|
||||
uint8_t mode = ZX_48K;
|
||||
uint32_t ram_size = 48*1024;
|
||||
uint32_t rom_size = 16*1024;
|
||||
uint8_t *ram = nullptr;
|
||||
uint8_t *rom = nullptr;
|
||||
uint8_t *slot[8];
|
||||
bool writable[8];
|
||||
|
||||
uint8_t config_128K;
|
||||
|
||||
void zx_128_port_out(int port, int val);
|
||||
|
||||
void init(uint8_t mode)
|
||||
{
|
||||
mem::mode = mode;
|
||||
if (ram) free(ram);
|
||||
if (rom) free(rom);
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
FILE* f;
|
||||
switch(mode)
|
||||
{
|
||||
case ZX_48K:
|
||||
ram_size = 48*1024;
|
||||
ram = (uint8_t*)malloc(ram_size);
|
||||
for (int i=0; i<ram_size; ++i) ram[i] = 0;
|
||||
//for (int i=0; i<65536; ++i) tags[i] = MEMTAG_NONE;
|
||||
|
||||
rom_size = 16*1024;
|
||||
rom = (uint8_t*)malloc(rom_size);
|
||||
f = fopen("48.rom", "rb");
|
||||
fread(rom, rom_size, 1, f);
|
||||
fclose(f);
|
||||
|
||||
slot[0] = &rom[0*8192]; slot[1] = &rom[1*8192];
|
||||
slot[2] = &ram[0*8192]; slot[3] = &ram[1*8192];
|
||||
slot[4] = &ram[2*8192]; slot[5] = &ram[3*8192];
|
||||
slot[6] = &ram[4*8192]; slot[7] = &ram[5*8192];
|
||||
|
||||
writable[0] = writable[1] = false;
|
||||
for (int i=2;i<8;++i) writable[i] = true;
|
||||
break;
|
||||
case ZX_128K:
|
||||
ram_size = 128*1024;
|
||||
ram = (uint8_t*)malloc(ram_size);
|
||||
for (int i=0x0000; i<ram_size; ++i) ram[i] = 0;
|
||||
|
||||
rom_size = 32*1024;
|
||||
rom = (uint8_t*)malloc(rom_size);
|
||||
f = fopen("128k.rom", "rb");
|
||||
fread(rom, rom_size, 1, f);
|
||||
fclose(f);
|
||||
|
||||
slot[0] = &rom[0*8192]; slot[1] = &rom[1*8192];
|
||||
slot[2] = &ram[10*8192]; slot[3] = &ram[11*8192];
|
||||
slot[4] = &ram[4*8192]; slot[5] = &ram[5*8192];
|
||||
slot[6] = &ram[0*8192]; slot[7] = &ram[1*8192];
|
||||
|
||||
writable[0] = writable[1] = false;
|
||||
for (int i=2;i<8;++i) writable[i] = true;
|
||||
|
||||
z80::connect_port(0xfd, nullptr, mem::zx_128_port_out);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t readMem(uint16_t address)
|
||||
{
|
||||
const uint8_t slot_num = address >> 13;
|
||||
const uint16_t displacement = address & 0x1fff;
|
||||
return slot[slot_num][displacement];
|
||||
}
|
||||
|
||||
void writeMem(uint16_t address, uint8_t value)
|
||||
{
|
||||
const uint8_t slot_num = address >> 13;
|
||||
if (!writable[slot_num]) return;
|
||||
|
||||
const uint16_t displacement = address & 0x1fff;
|
||||
slot[slot_num][displacement] = value;
|
||||
}
|
||||
|
||||
void loadMem(uint16_t address, uint16_t len, uint8_t *buffer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8_t getTag(uint16_t address)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setTag(uint16_t address, uint8_t value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void saveState(FILE* f)
|
||||
{
|
||||
fwrite(ram, 0xc000, 1, f);
|
||||
}
|
||||
|
||||
void loadState(FILE* f)
|
||||
{
|
||||
fread(ram, 0xc000, 1, f);
|
||||
}
|
||||
|
||||
uint32_t getSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t *rawPtr(uint32_t address)
|
||||
{
|
||||
return &ram[address];
|
||||
}
|
||||
|
||||
uint8_t *rawTagPtr(uint32_t address)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void zx_128_port_out(int port, int val)
|
||||
{
|
||||
if (port != 0x7ffd) return;
|
||||
if (config_128K & ZX_128MEM_DISPAG) return;
|
||||
|
||||
const bool shadow = config_128K & ZX_128MEM_SCREEN;
|
||||
config_128K = val;
|
||||
if (config_128K & ZX_128MEM_SCREEN) {
|
||||
if (!shadow) zxscreen::setBaseAddresses(0x4000*7, 0x1800+0x4000*7);
|
||||
} else {
|
||||
if (shadow) zxscreen::setBaseAddresses(0x4000*5, 0x1800+0x4000*5);
|
||||
}
|
||||
|
||||
if (config_128K & ZX_128MEM_ROM) {
|
||||
slot[0] = &rom[2*8192]; slot[1] = &rom[3*8192];
|
||||
} else {
|
||||
slot[0] = &rom[0*8192]; slot[1] = &rom[1*8192];
|
||||
}
|
||||
|
||||
const uint8_t slot3 = (config_128K&ZX_128MEM_PAGE)*2;
|
||||
slot[6] = &ram[slot3*8192]; slot[7] = &ram[(slot3+1)*8192];
|
||||
}
|
||||
}
|
||||
44
zx_mem.h
Normal file
44
zx_mem.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#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 ZX_48K 0x00
|
||||
#define ZX_128K 0x01
|
||||
#define ZX_2A_3 0x02
|
||||
#define ZX_NEXT 0x03
|
||||
|
||||
namespace mem
|
||||
{
|
||||
void init(uint8_t mode);
|
||||
void reset();
|
||||
|
||||
uint8_t readMem(uint16_t address);
|
||||
void writeMem(uint16_t address, uint8_t value);
|
||||
|
||||
void loadMem(uint16_t address, uint16_t len, uint8_t *buffer);
|
||||
|
||||
uint8_t getTag(uint16_t address);
|
||||
void setTag(uint16_t address, uint8_t value);
|
||||
|
||||
void saveState(FILE* f);
|
||||
void loadState(FILE* f);
|
||||
|
||||
uint32_t getSize();
|
||||
|
||||
uint8_t *rawPtr(uint32_t address);
|
||||
uint8_t *rawTagPtr(uint32_t address);
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "zx_screen.h"
|
||||
#include "z80.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_mem.h"
|
||||
#include "zx_ula.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "zx_tape.h"
|
||||
#include "ui_window.h"
|
||||
#include "z80debug.h"
|
||||
#include "ui.h"
|
||||
#include "zx_128mem.h"
|
||||
//#include "zx_128mem.h"
|
||||
|
||||
namespace zxscreen
|
||||
{
|
||||
@@ -200,7 +200,7 @@ namespace zxscreen
|
||||
{
|
||||
zxscreen::mode = mode;
|
||||
if (mode==SCREEN_MODE_48K) {
|
||||
setBaseAddresses(0x4000, 0x5800);
|
||||
setBaseAddresses(0x0000, 0x1800);
|
||||
t_states_total = 69888;
|
||||
t_states_per_scanline = 224;
|
||||
vsync_lines = 16;
|
||||
@@ -226,8 +226,8 @@ namespace zxscreen
|
||||
|
||||
void refresh(const uint32_t dt, const bool full)
|
||||
{
|
||||
const uint8_t* pixel_mem = z80mem::get()->rawPtr(pixel_base_addr);
|
||||
const uint8_t* color_mem = z80mem::get()->rawPtr(color_base_addr);
|
||||
const uint8_t* pixel_mem = mem::rawPtr(pixel_base_addr);
|
||||
const uint8_t* color_mem = mem::rawPtr(color_base_addr);
|
||||
const uint8_t border_color = zx_ula::get_border_color();
|
||||
|
||||
for (int i=0;i<dt;++i)
|
||||
@@ -301,8 +301,8 @@ namespace zxscreen
|
||||
// Pintem la textura a pantalla
|
||||
SDL_RenderCopy(ren, tex, NULL, &dest_rect);
|
||||
|
||||
zx_128mem* mem = ((zx_128mem*)z80mem::get());
|
||||
ui::printtxt(0,0,mem->getShadowScreen()?"SHADOW":"NORMAL", COLOR_WHITE);
|
||||
//zx_128mem* mem = ((zx_128mem*)z80mem::get());
|
||||
//ui::printtxt(0,0,mem->getShadowScreen()?"SHADOW":"NORMAL", COLOR_WHITE);
|
||||
|
||||
if (present)
|
||||
SDL_RenderPresent(ren);
|
||||
|
||||
Reference in New Issue
Block a user