Refactor IO peripherals for 64-bit
MODIFY
src/io/iobase.h
src/io/iobase.h
@@ -41,7 +41,7 @@ struct IOParam {
struct IOSymbol {
Symbol name;
- uint32_t value;
+ VInt value;
};
struct RegDesc {
@@ -49,7 +49,7 @@ struct RegDesc {
QString name;
RW rw;
unsigned bitWidth;
- uint32_t address;
+ AInt address;
/**
* @brief exported
* if true, a constant symbol is generated that may be referenced in the assembler, which targets this register.
@@ -100,19 +100,24 @@ public:
* Attempt to set the parameter @p ID to @p value. Returns true if the value was set successfully.
*/
virtual bool setParameter(unsigned ID, const QVariant& value);
- virtual uint32_t byteSize() const = 0;
+
+ /**
+ * @brief byteSize
+ * Size of this peripheral, in bytes
+ */
+ virtual unsigned byteSize() const = 0;
/**
* Read/write functions from processor
*/
- virtual uint32_t ioRead(uint32_t offset, unsigned size) = 0;
- virtual void ioWrite(uint32_t offset, uint32_t value, unsigned size) = 0;
+ virtual VInt ioRead(AInt offset, unsigned bytes) = 0;
+ virtual void ioWrite(AInt offset, VInt value, unsigned bytes) = 0;
/**
* Read/write functions from peripheral to bus (memory/other periphs)
*/
- std::function<void(uint32_t, uint32_t, uint32_t)> memWrite;
- std::function<uint32_t(uint32_t, uint32_t)> memRead;
+ std::function<void(AInt, AInt, VInt)> memWrite;
+ std::function<VInt(AInt, AInt)> memRead;
unsigned iotype() const { return m_type; }
unsigned id() const { return m_id; }

MODIFY
src/io/iodpad.cpp
src/io/iodpad.cpp
@@ -47,7 +47,7 @@ IODPad::IODPad(QWidget* parent) : IOBase(IOType::DPAD, parent) {
setLayout(gridLayout);
}
-uint32_t IODPad::byteSize() const {
+unsigned IODPad::byteSize() const {
return 4 * 4;
}
@@ -95,7 +95,7 @@ QString IODPad::description() const {
return desc.join('\n');
}
-uint32_t IODPad::ioRead(uint32_t offset, unsigned) {
+VInt IODPad::ioRead(AInt offset, unsigned) {
switch (offset) {
case LEFT * 4: {
return m_buttons.at(LEFT)->isDown();
@@ -113,7 +113,7 @@ uint32_t IODPad::ioRead(uint32_t offset, unsigned) {
return 0;
}
-void IODPad::ioWrite(uint32_t, uint32_t, unsigned) {
+void IODPad::ioWrite(AInt, VInt, unsigned) {
// Write-only
}

MODIFY
src/io/iodpad.h
src/io/iodpad.h
@@ -19,7 +19,7 @@ public:
IODPad(QWidget* parent);
~IODPad() { unregister(); };
- virtual uint32_t byteSize() const override;
+ virtual unsigned byteSize() const override;
virtual QString description() const override;
virtual QString baseName() const override { return "D-Pad"; };
@@ -28,8 +28,8 @@ public:
/**
* Hardware read/write functions
*/
- virtual uint32_t ioRead(uint32_t offset, unsigned size) override;
- virtual void ioWrite(uint32_t offset, uint32_t value, unsigned size) override;
+ virtual VInt ioRead(AInt offset, unsigned size) override;
+ virtual void ioWrite(AInt offset, VInt value, unsigned size) override;
protected:
virtual void parameterChanged(unsigned) override{/* no parameters */};
@@ -37,8 +37,7 @@ protected:
void keyReleaseEvent(QKeyEvent* e) override;
private:
- unsigned m_maxSideWidth = 256;
- std::vector<uint32_t> m_ledRegs;
+ constexpr static unsigned m_maxSideWidth = 256;
std::vector<RegDesc> m_regDescs;
std::map<IdxToDir, QAbstractButton*> m_buttons;
};

MODIFY
src/io/ioledmatrix.cpp
src/io/ioledmatrix.cpp
@@ -39,11 +39,11 @@ QString IOLedMatrix::description() const {
return desc.join('\n');
}
-uint32_t IOLedMatrix::ioRead(uint32_t offset, unsigned size) {
+VInt IOLedMatrix::ioRead(AInt offset, unsigned size) {
return (m_ledRegs.at(offset / 4) >> (offset % 4)) & vsrtl::generateBitmask(size * 8);
}
-void IOLedMatrix::ioWrite(uint32_t offset, uint32_t value, unsigned) {
+void IOLedMatrix::ioWrite(AInt offset, VInt value, unsigned) {
offset >>= 2; // word addressable
if (offset >= m_ledRegs.size()) {
Q_ASSERT(false);

MODIFY
src/io/ioledmatrix.h
src/io/ioledmatrix.h
@@ -17,7 +17,7 @@ public:
IOLedMatrix(QWidget* parent);
~IOLedMatrix() { unregister(); };
- virtual uint32_t byteSize() const override;
+ virtual unsigned byteSize() const override;
virtual QString description() const override;
virtual QString baseName() const override { return "LED Matrix"; }
@@ -27,8 +27,8 @@ public:
/**
* Hardware read/write functions
*/
- virtual uint32_t ioRead(uint32_t offset, unsigned size) override;
- virtual void ioWrite(uint32_t offset, uint32_t value, unsigned size) override;
+ virtual VInt ioRead(AInt offset, unsigned size) override;
+ virtual void ioWrite(AInt offset, VInt value, unsigned size) override;
protected:
virtual void parameterChanged(unsigned) override { updateLEDRegs(); };
@@ -40,7 +40,7 @@ protected:
QSize minimumSizeHint() const override;
private:
- uint32_t regRead(uint32_t offset) const;
+ VInt regRead(AInt offset) const;
void updateLEDRegs();
unsigned m_maxSideWidth = 256;

MODIFY
src/io/ioswitches.cpp
src/io/ioswitches.cpp
@@ -189,13 +189,13 @@ void IOSwitches::updateSwitches() {
emit regMapChanged();
}
-uint32_t IOSwitches::ioRead(uint32_t, unsigned) {
+VInt IOSwitches::ioRead(AInt, unsigned) {
return std::accumulate(m_switches.begin(), m_switches.end(), 0, [=](uint32_t acc, const auto& sw) {
return acc | (sw.second.second->isChecked()) << sw.first;
});
}
-void IOSwitches::ioWrite(uint32_t, uint32_t, unsigned) {
+void IOSwitches::ioWrite(AInt, VInt, unsigned) {
// Read-only
return;
}

MODIFY
src/io/ioswitches.h
src/io/ioswitches.h
@@ -66,7 +66,7 @@ public:
IOSwitches(QWidget* parent);
~IOSwitches() { unregister(); };
- virtual uint32_t byteSize() const override { return 4; }
+ virtual unsigned byteSize() const override { return 4; }
virtual QString description() const override;
virtual QString baseName() const override { return "Switches"; };
@@ -76,8 +76,8 @@ public:
/**
* Hardware read/write functions
*/
- virtual uint32_t ioRead(uint32_t offset, unsigned size) override;
- virtual void ioWrite(uint32_t offset, uint32_t value, unsigned size) override;
+ virtual VInt ioRead(AInt offset, unsigned size) override;
+ virtual void ioWrite(AInt offset, VInt value, unsigned size) override;
protected:
virtual void parameterChanged(unsigned) override { updateSwitches(); };
@@ -85,7 +85,7 @@ protected:
private:
void updateSwitches();
- uint32_t regRead(uint32_t offset) const;
+ uint32_t regRead(AInt offset) const;
std::map<unsigned, std::pair<QLabel*, ToggleButton*>> m_switches;
QGridLayout* m_switchLayout;
std::vector<RegDesc> m_regDescs;

Refactor IO peripherals for 64-bit