I am writing a nes emulator and have written one class representing 6502 cpu:
class CCpu6502 { public: void fetch8(); void fetch16(); void ADC(); void AND(); private: };
Basically, I have a transition table that accepts the operation code and performs the corresponding member function - changing the internal state of the processor. There are other tasks that determine the correct type of addressing.
I realized that the class definition is too large and difficult to parse, as well as verify. However, dividing a class into separate classes seems problematic, since almost every function changes the internal state of the processor.
I was thinking about classifying command types as such:
class AInstructionHandler {}; class CArithmeticInstHandler : public AInstructionHandler{}; class CBranchInstHandler : public AInstructionHandler{};
However, I would have to give each class handler class access to the internal state of the processor, making each class different, which seems bad.
I am wondering if there is a preferred way to refactor a large class where almost all methods affect the state of the object or if my design has flaws to start with.
thanks
source share