Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detection of Family Basic keyboard #781

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/input/fkb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#define AK(x) FKB_ ## x

static uint8 bufit[0x49];
static uint8 ksmode;
static uint8 ksindex;
static uint8 ksrow;
static uint8 kscol;
static uint8 ksenable;

static uint16 matrix[9][2][4] =
{
Expand All @@ -50,30 +51,34 @@ static uint16 matrix[9][2][4] =
};

static void FKB_Write(uint8 v) {
v >>= 1;
if (v & 2) {
if ((ksmode & 1) && !(v & 1))
ksindex = (ksindex + 1) % 9;
uint8 col = (v & 2) >> 1;
ksenable = v & 4;
if (ksenable) {
if (v & 1) {
ksrow = 0;
} else if (kscol && !col) {
ksrow = (ksrow + 1) % 10;
}
kscol = col;
}
ksmode = v;
}

static uint8 FKB_Read(int w, uint8 ret) {
if (w) {
int state = 0;
int x;

ret &= ~0x1E;
if (ksrow == 9) return(ret);
for (x = 0; x < 4; x++)
if (bufit[ matrix[ksindex][ksmode & 1][x] & 0xFF ] || bufit[ matrix[ksindex][ksmode & 1][x] >> 8])
ret |= 1 << (x + 1);
ret ^= 0x1E;
if (bufit[ matrix[ksrow][kscol][x] & 0xFF ] || bufit[ matrix[ksrow][kscol][x] >> 8])
state |= 1 << (x + 1);
return(ret | ((ksenable ? (state ^ 0x1E) : 0)));
}
return(ret);
}

static void FKB_Strobe(void) {
ksmode = 0;
ksindex = 0;
}

static void FKB_Update(void *data, int arg) {
Expand All @@ -84,6 +89,6 @@ static INPUTCFC FKB = { FKB_Read, FKB_Write, FKB_Strobe, FKB_Update, 0, 0 };

INPUTCFC *FCEU_InitFKB(void) {
memset(bufit, 0, sizeof(bufit));
ksmode = ksindex = 0;
ksenable = ksrow = kscol = 0;
return(&FKB);
}