From: Wouter V. <m97...@us...> - 2004-01-30 20:41:46
|
Update of /cvsroot/openmsx/openMSX/src/cpu In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25370/src/cpu Modified Files: CPU.cc CPU.hh CPUCore.n2 R800.cc R800.hh Z80.cc Z80.hh Log Message: Made cpu frequency switchable at-run-time Index: CPU.cc =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/cpu/CPU.cc,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- CPU.cc 22 Dec 2003 13:38:59 -0000 1.35 +++ CPU.cc 30 Jan 2004 20:40:10 -0000 1.36 @@ -16,8 +16,7 @@ namespace openmsx { #ifdef CPU_DEBUG -BooleanSetting *CPU::traceSetting = - new BooleanSetting("cputrace", "CPU tracing on/off", false); +BooleanSetting CPU::traceSetting("cputrace", "CPU tracing on/off", false); #endif multiset<word> CPU::breakPoints; @@ -25,13 +24,25 @@ bool CPU::step = false; -CPU::CPU() - : interface(NULL) +CPU::CPU(const string& name, int defaultFreq) + : interface(NULL), + freqLocked(name + "_freq_locked", + "real (locked) or custom (unlocked) " + name + " frequency", + true), + freqValue(name + "_freq", + "custom " + name + " frequency (only valid when unlocked)", + defaultFreq, 1, 100000000) { + currentTime.setFreq(defaultFreq); + + freqLocked.addListener(this); + freqValue.addListener(this); } CPU::~CPU() { + freqValue.removeListener(this); + freqLocked.removeListener(this); } void CPU::init(Scheduler* scheduler_) @@ -44,14 +55,14 @@ interface = interf; } -void CPU::executeUntilTarget(const EmuTime &time) +void CPU::executeUntilTarget(const EmuTime& time) { assert(interface); setTargetTime(time); executeCore(); } -void CPU::setTargetTime(const EmuTime &time) +void CPU::setTargetTime(const EmuTime& time) { targetTime = time; } @@ -61,6 +72,16 @@ return targetTime; } +void CPU::setCurrentTime(const EmuTime& time) +{ + currentTime = time; +} +const EmuTime& CPU::getCurrentTime() const +{ + return currentTime; +} + + void CPU::invalidateCache(word start, int num) { //PRT_DEBUG("cache: invalidate "<<start<<" "<<num*CACHE_LINE_SIZE); @@ -71,7 +92,7 @@ } -void CPU::reset(const EmuTime &time) +void CPU::reset(const EmuTime& time) { // AF and SP are 0xFFFF // PC, R, IFF1, IFF2, HALT and IM are 0x0 @@ -171,4 +192,24 @@ } } + +void CPU::update(const SettingLeafNode* setting) throw() +{ + if (setting == &freqLocked) { + if (freqLocked.getValue()) { + // locked + currentTime.setFreq(freqValue.getDefaultValue()); + } else { + // unlocked + currentTime.setFreq(freqValue.getValue()); + } + } else if (setting == &freqValue) { + if (!freqLocked.getValue()) { + currentTime.setFreq(freqValue.getValue()); + } + } else { + assert(false); + } +} + } // namespace openmsx Index: CPU.hh =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/cpu/CPU.hh,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- CPU.hh 15 Dec 2003 19:46:08 -0000 1.31 +++ CPU.hh 30 Jan 2004 20:40:10 -0000 1.32 @@ -4,15 +4,20 @@ #define __CPU_HH__ #include <set> +#include <string> #include "openmsx.hh" #include "EmuTime.hh" #include "CPUTables.hh" +#include "BooleanSetting.hh" +#include "IntegerSetting.hh" +#include "SettingListener.hh" #ifdef DEBUG #define CPU_DEBUG #endif using std::multiset; +using std::string; namespace openmsx { @@ -23,7 +28,7 @@ typedef signed char offset; -class CPU : public CPUTables +class CPU : public CPUTables, private SettingListener { friend class MSXCPU; public: @@ -68,12 +73,12 @@ * Sets the CPU its current time. * This is used to 'warp' a CPU when you switch between Z80/R800. */ - virtual void setCurrentTime(const EmuTime& time) = 0; + void setCurrentTime(const EmuTime& time); /** * Returns the CPU its current time. */ - virtual const EmuTime& getCurrentTime() const = 0; + const EmuTime& getCurrentTime() const; /** * Alter the target time. @@ -134,7 +139,7 @@ protected: /** Create a new CPU. */ - CPU(); + CPU(const string& name, int defaultFreq); /** Emulate CPU till a previously set target time, * the target may change (become smaller) during emulation. @@ -159,6 +164,7 @@ CPUInterface* interface; EmuTime targetTime; + DynamicEmuTime currentTime; // memory cache const byte* readCacheLine[CACHE_LINE_NUM]; @@ -171,13 +177,13 @@ void doStep(); void doContinue(); void doBreak(); - + static multiset<word> breakPoints; static bool breaked; static bool step; #ifdef CPU_DEBUG - static BooleanSetting* traceSetting; + static BooleanSetting traceSetting; public: byte debugmemory[65536]; @@ -185,6 +191,12 @@ #endif private: + virtual void update(const SettingLeafNode* setting) throw(); + + // dynamic freq + BooleanSetting freqLocked; + IntegerSetting freqValue; + Scheduler* scheduler; }; Index: CPUCore.n2 =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/cpu/CPUCore.n2,v retrieving revision 1.45 retrieving revision 1.46 diff -u -d -r1.45 -r1.46 --- CPUCore.n2 22 Dec 2003 15:01:32 -0000 1.45 +++ CPUCore.n2 30 Jan 2004 20:40:10 -0000 1.46 @@ -193,7 +193,7 @@ executeInstruction(); #ifdef CPU_DEBUG - if (traceSetting->getValue()) { + if (traceSetting.getValue()) { Dasm(&debugmemory[start_pc], to_print_string, start_pc); PRT_DEBUG(setfill('0') << hex << setw(4) << start_pc << Index: R800.cc =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/cpu/R800.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- R800.cc 6 Nov 2003 21:31:19 -0000 1.7 +++ R800.cc 30 Jan 2004 20:40:10 -0000 1.8 @@ -9,6 +9,7 @@ #include "R800Tables.nn" R800::R800(const EmuTime &time) + : CPU("r800", CLOCK_FREQ) { reset(time); } @@ -16,15 +17,6 @@ { } -void R800::setCurrentTime(const EmuTime &time) -{ - currentTime = time; -} -const EmuTime &R800::getCurrentTime() const -{ - return currentTime; -} - inline void R800::M1_DELAY() { } inline void R800::ADD_16_8_DELAY() { currentTime += 1; } inline void R800::OP_16_16_DELAY() { } Index: R800.hh =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/cpu/R800.hh,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- R800.hh 6 Nov 2003 21:31:19 -0000 1.9 +++ R800.hh 30 Jan 2004 20:40:10 -0000 1.10 @@ -17,33 +17,29 @@ class R800 : public CPU { - public: - static const int CLOCK_FREQ = 7159090; - R800(const EmuTime &time); - virtual ~R800(); - virtual void setCurrentTime(const EmuTime &time); - virtual const EmuTime &getCurrentTime() const; - - private: - #include "CPUCore.n1" +public: + static const int CLOCK_FREQ = 7159090; + R800(const EmuTime &time); + virtual ~R800(); - static const int IO_DELAY1 = 0; - static const int IO_DELAY2 = 1; - static const int MEM_DELAY1 = 0; - static const int MEM_DELAY2 = 1; +private: + #include "CPUCore.n1" - EmuTimeFreq<CLOCK_FREQ> currentTime; + static const int IO_DELAY1 = 0; + static const int IO_DELAY2 = 1; + static const int MEM_DELAY1 = 0; + static const int MEM_DELAY2 = 1; - // opcode function pointers - static const R800_ResumeFunc opcode_dd_cb[256]; - static const R800_ResumeFunc opcode_fd_cb[256]; - static const R800_ResumeFunc opcode_cb[256]; - static const R800_ResumeFunc opcode_dd[256]; - static const R800_ResumeFunc opcode_ed[256]; - static const R800_ResumeFunc opcode_fd[256]; - static const R800_ResumeFunc opcode_main[256]; + // opcode function pointers + static const R800_ResumeFunc opcode_dd_cb[256]; + static const R800_ResumeFunc opcode_fd_cb[256]; + static const R800_ResumeFunc opcode_cb[256]; + static const R800_ResumeFunc opcode_dd[256]; + static const R800_ResumeFunc opcode_ed[256]; + static const R800_ResumeFunc opcode_fd[256]; + static const R800_ResumeFunc opcode_main[256]; - R800_ResumeFunc resume; + R800_ResumeFunc resume; }; } // namespace openmsx Index: Z80.cc =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/cpu/Z80.cc,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- Z80.cc 6 Nov 2003 21:31:19 -0000 1.14 +++ Z80.cc 30 Jan 2004 20:40:10 -0000 1.15 @@ -21,6 +21,7 @@ #include "Z80Tables.nn" Z80::Z80(const EmuTime &time) + : CPU("z80", CLOCK_FREQ) { reset(time); } @@ -28,15 +29,6 @@ { } -void Z80::setCurrentTime(const EmuTime &time) -{ - currentTime = time; -} -const EmuTime &Z80::getCurrentTime() const -{ - return currentTime; -} - inline void Z80::M1_DELAY() { currentTime += 1 + WAIT_CYCLES; } inline void Z80::ADD_16_8_DELAY() { currentTime += 5; } Index: Z80.hh =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/cpu/Z80.hh,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- Z80.hh 6 Nov 2003 21:31:19 -0000 1.17 +++ Z80.hh 30 Jan 2004 20:40:10 -0000 1.18 @@ -21,35 +21,32 @@ * written by Marcel de Kogel 1996, 1997. * Heavily rewritten to fit openMSX structure. */ -class Z80 : public CPU { - public: - static const int CLOCK_FREQ = 3579545; - Z80(const EmuTime &time); - virtual ~Z80(); - virtual void setCurrentTime(const EmuTime &time); - virtual const EmuTime &getCurrentTime() const; - - private: - #include "CPUCore.n1" +class Z80 : public CPU +{ +public: + static const int CLOCK_FREQ = 3579545; + Z80(const EmuTime &time); + virtual ~Z80(); - static const int IO_DELAY1 = 1; - static const int IO_DELAY2 = 3; - static const int MEM_DELAY1 = 1; - static const int MEM_DELAY2 = 2; - static const int WAIT_CYCLES = 1; +private: + #include "CPUCore.n1" - EmuTimeFreq<CLOCK_FREQ> currentTime; + static const int IO_DELAY1 = 1; + static const int IO_DELAY2 = 3; + static const int MEM_DELAY1 = 1; + static const int MEM_DELAY2 = 2; + static const int WAIT_CYCLES = 1; - // opcode function pointers - static const Z80_ResumeFunc opcode_dd_cb[256]; - static const Z80_ResumeFunc opcode_fd_cb[256]; - static const Z80_ResumeFunc opcode_cb[256]; - static const Z80_ResumeFunc opcode_dd[256]; - static const Z80_ResumeFunc opcode_ed[256]; - static const Z80_ResumeFunc opcode_fd[256]; - static const Z80_ResumeFunc opcode_main[256]; + // opcode function pointers + static const Z80_ResumeFunc opcode_dd_cb[256]; + static const Z80_ResumeFunc opcode_fd_cb[256]; + static const Z80_ResumeFunc opcode_cb[256]; + static const Z80_ResumeFunc opcode_dd[256]; + static const Z80_ResumeFunc opcode_ed[256]; + static const Z80_ResumeFunc opcode_fd[256]; + static const Z80_ResumeFunc opcode_main[256]; - Z80_ResumeFunc resume; + Z80_ResumeFunc resume; }; } // namespace openmsx |