1 // The base class for all devices 2 3 #ifndef FRAMEWORK_BASICDEVICE_HPP_ 4 #define FRAMEWORK_BASICDEVICE_HPP_ 5 6 #include <string> 7 8 #include "Framework/Types.hpp" 9 #include "Framework/Event.hpp" 10 11 class BasicCPU; 12 13 constexpr int AUTOVECTOR_INTERRUPT = -1; 14 constexpr int SPURIOUS_INTERRUPT = -2; 15 16 class BasicDevice : public EventBase { 17 public: 18 BasicDevice(const std::string &name, const std::string &arguments, BasicCPU &cpu); 19 ~BasicDevice() override; 20 ErrorMessage(const std::string & message)21 void ErrorMessage(const std::string &message) { myErrorMessage = message; } ErrorMessage() const22 const std::string &ErrorMessage() const { return myErrorMessage; } Name() const23 const std::string &Name() const { return myName; } CPU() const24 BasicCPU &CPU() const { return myCPU; } Arguments() const25 const std::string &Arguments() const { return myArguments; } 26 27 // Returns true iff the address maps into the device. 28 virtual bool CheckMapped(Address) const = 0; 29 30 // Returns the lowest address used by the device. 31 virtual Address LowestAddress() const = 0; 32 33 // Returns the highest address used by the device. 34 virtual Address HighestAddress() const = 0; 35 36 // Gets a byte from the device. 37 virtual Byte Peek(Address address) = 0; 38 39 // Puts a byte into the device. 40 virtual void Poke(Address address, Byte c) = 0; 41 42 // Gets data from the device. 43 virtual bool Peek(Address address, unsigned long &data, int size); 44 45 // Puts data into the device. 46 virtual bool Poke(Address address, unsigned long data, int size); 47 48 // Resets the device. 49 virtual void Reset(); 50 51 // Sends an interrupt request (IRQ) to the CPU. 52 virtual void InterruptRequest(int level); 53 54 // Called by the CPU when it processes an interrupt. 55 virtual int InterruptAcknowledge(unsigned int level); 56 57 protected: 58 // Reference to the CPU I belong to. 59 BasicCPU &myCPU; 60 61 // My name (i.e. RAM, ROM, etc). 62 const std::string myName; 63 64 // Arguments passed to constructor. 65 const std::string myArguments; 66 67 // Error that occured during construction. 68 std::string myErrorMessage; 69 70 // Interrupt pending flag. 71 bool myInterruptPending; 72 }; 73 74 #endif // FRAMEWORK_BASICDEVICE_HPP_ 75