- [NEW] Treballant en modularitzar la memòria, per a començar a implementar soport per als demes Spectrums
This commit is contained in:
66
z80.cpp
66
z80.cpp
@@ -1,13 +1,14 @@
|
||||
#include "z80.h"
|
||||
#include "z80debug.h"
|
||||
#include "z80mem.h"
|
||||
#include "zx_tape.h"
|
||||
#include <stdio.h>
|
||||
|
||||
namespace z80
|
||||
{
|
||||
static uint8_t *memory = nullptr;
|
||||
static uint8_t memtag[65536];
|
||||
static uint8_t memtouched[65536];
|
||||
//static uint8_t *memory = nullptr;
|
||||
//static uint8_t memtag[65536];
|
||||
//static uint8_t memtouched[65536];
|
||||
static uint32_t t = 0;
|
||||
static uint16_t current_opcode_address = 0;
|
||||
bool options[Z80_NUM_OPTIONS] = { true, false };
|
||||
@@ -16,8 +17,8 @@ namespace z80
|
||||
int (*in_ports[256])(int);
|
||||
void (*out_ports[256])(int, int);
|
||||
|
||||
#define _rM16(a) (uint16_t*)&memory[a]
|
||||
#define rM16(a) *_rM16(a)
|
||||
//#define _rM16(a) (uint16_t*)&memory[a]
|
||||
//#define rM16(a) *_rM16(a)
|
||||
|
||||
#define fC 0b00000001
|
||||
#define fN 0b00000010
|
||||
@@ -151,34 +152,31 @@ namespace z80
|
||||
{
|
||||
if (z80debug::isbreak(addr, 2)) z80debug::stop();
|
||||
t+=3;
|
||||
if (memtag[addr] != MEMTAG_IGNORE) {
|
||||
const uint8_t tag = z80mem::get()->getTag(addr);
|
||||
if ( !(tag&MEMTAG_IGNORE) ) {
|
||||
if (!code) {
|
||||
if ( memtag[addr] == MEMTAG_INST ) {
|
||||
if ( tag & MEMTAG_INST ) {
|
||||
//printf("WARNING! READING DATA FROM CODE!!! $%4X\n", addr);
|
||||
//z80debug::stop();
|
||||
} else {
|
||||
memtag[addr] = MEMTAG_DATA;
|
||||
z80mem::get()->setTag(addr, tag | MEMTAG_DATA);
|
||||
}
|
||||
} else {
|
||||
if ( (reading_m1) && (memtag[addr] == MEMTAG_DATA) ) {
|
||||
if ( (reading_m1) && ( tag & MEMTAG_DATA ) ) {
|
||||
//printf("WARNING! EXECUTING DATA AS CODE!!! $%4X\n", addr);
|
||||
//z80debug::stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
reading_m1 = false;
|
||||
return memory[addr];
|
||||
return z80mem::get()->readMem(addr);
|
||||
}
|
||||
|
||||
uint8_t READ_MEM_8()
|
||||
{
|
||||
uint8_t data = READ_MEM_8(rPC, true);
|
||||
if ( (memtag[rPC] != MEMTAG_IGNORE) && (memtag[rPC] != MEMTAG_MIXED) ) {
|
||||
if (memtag[rPC] == MEMTAG_DATA)
|
||||
memtag[rPC] = MEMTAG_MIXED;
|
||||
else
|
||||
memtag[rPC] = MEMTAG_CODE;
|
||||
}
|
||||
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);
|
||||
rPC++;
|
||||
return data;
|
||||
}
|
||||
@@ -209,19 +207,18 @@ namespace z80
|
||||
const uint8_t WRITE_MEM_8(const uint16_t addr, const uint8_t value)
|
||||
{
|
||||
t+=3;
|
||||
if (addr>=0x4000) memory[addr] = value;
|
||||
if (addr>=0x4000) z80mem::get()->writeMem(addr, value);
|
||||
if (z80debug::isbreak(addr, 4)) z80debug::stop();
|
||||
//if (z80debug::debugging())
|
||||
z80debug::setmemmodified(addr);
|
||||
if ( (memtag[addr] != MEMTAG_IGNORE) && (memtag[addr] != MEMTAG_MIXED) ) {
|
||||
if (memtag[addr]==MEMTAG_INST) {
|
||||
|
||||
const uint8_t tag = z80mem::get()->getTag(addr);
|
||||
if ( !(tag & MEMTAG_IGNORE) ) {
|
||||
if ( tag & MEMTAG_INST ) {
|
||||
//printf("WARNING! WRITING DATA OVER CODE!!! $%4X\n", addr);
|
||||
//z80debug::stop();
|
||||
} else if (memtag[addr] == MEMTAG_CODE) {
|
||||
memtag[addr] = MEMTAG_MIXED;
|
||||
} else {
|
||||
memtag[addr] = MEMTAG_DATA;
|
||||
memtouched[addr] = MEMTAG_DATA;
|
||||
z80mem::get()->setTag(addr, tag | MEMTAG_DATA | MEMTAG_TDATA);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1118,13 +1115,14 @@ namespace z80
|
||||
if (options[Z80_OPTION_STOP_ON_INVALID]) z80debug::stop();
|
||||
}
|
||||
|
||||
void reset(uint8_t* mem)
|
||||
{
|
||||
memory = mem;
|
||||
for (int i=0; i<65536; ++i) memtag[i] = MEMTAG_NONE;
|
||||
void reset()
|
||||
{
|
||||
z80mem::get()->reset();
|
||||
|
||||
rPC = iff1 = iff2 = im = 0;
|
||||
rAF = rAF2 = rBC = rBC2 = rDE = rDE2 = rHL = rHL2 = rIX = rIY = rSP = 0xffff;
|
||||
t = 0;
|
||||
|
||||
for (int i=0; i<256; ++i)
|
||||
{
|
||||
in_ports[i] = nullptr;
|
||||
@@ -1153,8 +1151,11 @@ namespace z80
|
||||
current_opcode_address = rPC;
|
||||
t = 0;
|
||||
const uint8_t opcode = READ_M1();
|
||||
if (memtag[current_opcode_address] != MEMTAG_IGNORE) memtag[current_opcode_address] = MEMTAG_INST;
|
||||
memtouched[current_opcode_address] = memtouched[current_opcode_address] != MEMTAG_NONE ? MEMTAG_REPEAT : MEMTAG_INST;
|
||||
|
||||
uint8_t tag = z80mem::get()->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);
|
||||
|
||||
uint16_t tmp;
|
||||
|
||||
if (opcode!=0xED && opcode!=0xCB && opcode!=0xDD && opcode!=0xFD ) z80debug::useOpcode(opcode, 0);
|
||||
@@ -2829,7 +2830,7 @@ namespace z80
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *getMem() { return memory; }
|
||||
//uint8_t *getMem() { return memory; }
|
||||
uint8_t *getRegs() { return regs; }
|
||||
|
||||
uint16_t getAF(const bool alt) { return alt?rAF2:rAF; }
|
||||
@@ -2848,6 +2849,7 @@ namespace z80
|
||||
|
||||
void setPC(const uint16_t addr) { rPC = addr; }
|
||||
|
||||
/*
|
||||
uint8_t getMemTag(const uint16_t addr) { return memtag[addr]; }
|
||||
|
||||
void setMemTag(const uint16_t addr, const uint8_t value) { memtag[addr] = value; }
|
||||
@@ -2872,7 +2874,7 @@ namespace z80
|
||||
//else if (memtouched[i]==MEMTAG_DATA)
|
||||
// memtouched[i] = MEMTAG_REPEAT;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
const bool getOption(const int option)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user