Code: Select all
#include <stdio.h>
#include <conio.h>
#include <sys/ioctl.h>
#include <input.h>
#define ZX_LINE_FEED 10
void main() {
// Setup
textcolor(BLACK);
textbackground(LIGHTGREEN);
int mode = 1;
console_ioctl(IOCTL_GENCON_SET_MODE, &mode);
in_KeyDebounce = 120; // fixes reading "imaginary" ghost keys when pressing and releasing rapidly
in_GetKeyReset();
// Program continues from here
printf("%cHello World\n", ZX_LINE_FEED);
while(1) {
char result = in_GetKey();
if(result != 0) {
printf("got %d (%c)\n", result, result);
}
}
}
- Unless I set in_KeyDebounce, the key feedback is super rapid and also involves "ghost" keys (for instance, pressing F rapidly will produce the ascii characters 105, 91, and 73. This isn't such a big deal, since I need debounce also on the eSC-3000 emulator otherwise it ttttyypppeesss llllikkkeeee ttthhhhhiiissss, but it's a bit worrying that it's not reporting the correct characters.
- The bigger problem is that only a few of the keys respond, and they return the wrong characters, all from the first "row" of the keyboard matrix (as per Enri.)
- Pressing D (100) produces ASCII 56 (8)
- Pressing F (102) produces ASCII 105 (i)
- Pressing R (114) produces ASCII 107 (k)
- Pressing L. Alt/GRAPH produces ASCII 44 (,)
- Pressing left arrow produces ASCII 97 (a)
- Pressing up arrow produces ASCII 49 (1)
- Pressing right arrow produces ASCII 122 (z)
- Pressing down arrow produces ASCII 113 (q)
Basic Sanity Checks
Level III BASIC works fine on MAME 0227, so I'm assuming their keyboard handling is working.
As far as I can tell, the code in libsrc/target/sc3000/input/in_Inkey.asm is correct; I set breakpoints at the gotkey and gotkey_port_dd symbols, and they got hit as I would expect when hitting the keys that "respond." It also iterates the c register properly to step through the "rows" of the keyboard, and that value makes it into the I/O port write to the keyboard-select register at $0de.
I thought it might be a timing issue (somehow? MAME is obviously a software emulator, too, and just sets a member variable; if anything it would respond too quickly and mask problems that the real hardware would have) so I stuck in a pair of NOPs after the OUTs to the keyboard select register, like Level III BASIC appeared to when I looked at it in the debugger. That didn't make any difference to either problems 1 or 2.
As an aside, "sh build.sh -p sc3000" didn't seem to rebuild the target after my changes; if there's a better way to focus on quickly building one target at a time, I can update the wiki with it

Disclaimer
I know that this target is usually tested against the Common Source Code Project's eSC-3000 emulator, and this behaviour seems to work as expected there in my testing.
I haven't had a chance to test on real hardware yet, but I can dig out my SC-3000 and try to load from "tape" – almost all of the keys work.
Thanks for reading through all of this.