Skip to content

Commit

Permalink
Add getter for raw halfword. Fix+tidy example
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbaumann committed Dec 21, 2024
1 parent de152b9 commit 07b6a96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/mips/psyqo/advancedpad.hh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class AdvancedPad {
* @param index The index of the Analog Input.
* @return The state of the Analog Input.
*/
uint8_t getAdc(Pad pad, uint8_t index) const {
uint8_t getAdc(Pad pad, unsigned int index) const {
switch (index) {
case 0:
return getAdc0(pad);
Expand All @@ -206,6 +206,20 @@ class AdvancedPad {
}
}

/**
* @brief Returns raw pad data as a 16-bit value.
*
* @details Returns the halfword value for the requested index of the given pad index.
*
* @param pad The pad to query.
* @param index The index of the halfword.
* @return The value of the halfword.
*/

uint16_t getHalfword(Pad pad, unsigned int index) const {
return m_padData[pad][index % 4];
}

/**
* @brief Returns the type of the pad.
*
Expand Down
13 changes: 9 additions & 4 deletions src/mips/psyqo/examples/multitap/multitap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,16 @@ void MultitapTestScene::printPadStatus(psyqo::AdvancedPad::Pad pad, int column,
char m_textBuffer[32] = {'\0'};
const auto padType = input.getPadType(pad);

if (((padType & 0x0f) > 1) && padType != psyqo::AdvancedPad::PadType::None) {
sprintf(m_textBuffer, "ADC[0-%d]", (((padType & 0x0f) - 1) * 2) - 1);
// The lower 4-bits of the pad type indicate the number of half-words of pad data
// The 1st half-word is for the digital switches
const auto halfWords = padType & 0xf;
const auto adcBytes = (halfWords - 1) * 2;

if (halfWords > 1 && padType != psyqo::AdvancedPad::PadType::None) {
sprintf(m_textBuffer, "ADC[0-%d]", adcBytes - 1);
print(column + 0, 9, false, m_textBuffer);

for (int i = 0; i < ((padType & 0x0f) - 1) * 2 && i < 4; i++) {
for (int i = 0; i < adcBytes && i < 4; i++) {
sprintf(m_textBuffer, "%02X ", input.getAdc(pad, i));
print(column + 10 + (i * 3), 9, true, m_textBuffer);
}
Expand Down Expand Up @@ -207,7 +212,7 @@ void MultitapTestScene::frame() {
multitapTest.gpu().clear();

if (multitapTest.m_input.isPadConnected(m_padIndex)) {
print(7, m_padIndex, true, ">");
print(1, m_padIndex, true, ">");
}

printPadConnectionStatus(psyqo::AdvancedPad::Pad1a, 0, "Pad 1a");
Expand Down

0 comments on commit 07b6a96

Please sign in to comment.