Repository navigation
Ignore input held while the menu opens - #940
Conversation
|
Default E2E gate, Default gate log, part 1 of 2 |
|
Default E2E gate, Default gate log, part 2 of 2 |
|
Interesting. I have mever encountered this in the entire 15 years of existence of the 1541U2 / U2+ line. |
|
I'll test the fix this evening after work. I have to admit that I had never encountered this issue before either. This is the first time I've noticed this behavior on my U2+. |
|
I just checked and it also does not occur on my Ultimate II+L with latest 3.15 master firmware on a C64U FE. I opened the menu 10 times and the position in the menu did not change. I positioned the cursor in the middle of a long file list on my USB drive. Maybe it just happens if connected to a real C64. |
|
The automated GitHub build hasn't compiled this fix yet, though. |
|
In the meantime, I used the time to narrow down which commit introduced the problem. The build I used, v3.15-219-gec6e0322c, comes from PR #931, which has since been merged into master. Not every commit from that branch was included in an automated build, but I was able to narrow it down to: Last known good commit: 1ba94ab The commits between these two were not built by the automated build system. |
|
Due to reconstruction work, the build server is online here in my house. |
Opening the menu after the C64 has been running could move the browser cursor by one step without any key being pressed (GideonZ#935). The step was always Up, Down, Left or Right, which is what the joystick port 2 decode in Keyboard_C64::scan() produces: it samples $DC00 before the keyboard matrix and maps PA0-PA3 onto the CRSR positions. Nothing reset the scanner when the menu took the machine, so a low sample on the first scans would become one keystroke. Keyboard gains ignore_held_input(), called by UserInterface::run_once() right after it takes ownership. Keyboard_C64 disarms and drops its buffer from the reading end, in one critical section on builds that scan from the timer, so a timer scan cannot queue a key in between; scan() queues nothing until it has seen no key and no joystick. A modifier held on its own (SHIFT LOCK) still arms it. clear_buffer() is unchanged, so a key held inside a popup keeps repeating. Tests: host cases for the held joystick, a joystick press without the new call, and key repeat across clear_buffer(); a menu-held-input scenario in the input E2E suite (quick profile) that opens the menu with joystick port 2 held and requires the highlight to stay put.
345ae9e to
f2389ba
Compare
|
Default E2E gate, Default gate log, part 1 of 2 |
|
Default E2E gate, Default gate log, part 2 of 2 |
|
Rebased onto master 2c60bd8 and updated the description with @radius75's bisect. One change came with the rebase. Since f28302e and 9b22d87, the U2 family scans the keyboard from a timer, and 9b22d87 made the head of the key buffer the scan's end. My first version of @chrisgleissner, your test build for @radius75 has the earlier version. The difference only matters if a timer scan lands in the middle of @radius75, thanks for testing. Which version did the menu show? Chris's build for this PR is |
|
v3.15-382-g46f8005ca |
|
Hi @barryw, as per my last comment, does this need retesting? It is difficult to see since the original Git IDs appear to have disappeared due to a forced push. Thank you. |
|
@chrisgleissner Sorry, I missed your question from Tuesday. Yes, I think a retest on the current head is worth it, and thanks for offering to build it again. Sorry about the force push hiding the history. The commits:
Apart from the rebase, the only code change is the body of void Keyboard_C64 :: ignore_held_input(void)
{
+ // One step, so the timer scan cannot queue a key between the disarm and
+ // the drop. Like clear_buffer(), it drops from the reading end only.
- key_head = key_tail = 0;
- mtrx_prev = 0xFF;
- shift_prev = 0xFF;
- armed = false;
+#if KEYBOARD_C64_TIMER_SCAN
+ portENTER_CRITICAL();
+#endif
+ armed = false;
+ mtrx_prev = 0xFF;
+ shift_prev = 0xFF;
+ key_tail = key_head;
+#if KEYBOARD_C64_TIMER_SCAN
+ portEXIT_CRITICAL();
+#endif
}It should behave the same, but it only runs differently on builds that scan from the timer, which means the U2 family. My U64 gate doesn't exercise that path, so @radius75's II+ is the only place the code that would actually merge gets tested. The same steps as before would do: Run Disk, Run PRG and Reboot C64, checking that the menu doesn't move. |
Fixes #935. Confirmed on an Ultimate II+ by @radius75: with
v3.15-382-g46f8005ca(this PR on master, built by @chrisgleissner) the step didn't occur in a dozen or so runs of Run Disk, Run PRG and Reboot C64. That build predates the rebase below; the current head differs only in guardingignore_held_input()against the timer scan.Problem
After the C64 has been running (Reboot C64, Run PRG, Run Disk), opening the menu can move the browser cursor by one step with no key pressed. The step is always Up, Down, Left (back) or Right (enter).
Cause
Those four moves are what the joystick port 2 decode in
Keyboard_C64::scan()produces. It samples$DC00before the keyboard matrix and maps PA0–PA3 onto the CRSR positions in the key matrix (fire, PA4, maps to RETURN). A first-time press is queued immediately. Nothing reset the scanner when the menu took the machine, so a low sample on the first scans after the menu opens becomes one keystroke.What pulls PA0–PA3 low is still a hypothesis, but @radius75's bisect narrows it. The step first appears between 1ba94ab and 3fbe765. Of the commits in that range, f28302e and 9b22d87 are the ones that change the keyboard scan: on the U2 family the keyboard is now scanned from a 2-tick timer, and
freeze()allows that scan as soon asinit_io()has set CIA1 up. Before, the first scan came from the UI task tens of milliseconds later. On a real C64 the port lines are pulled up passively, so a scan straight afterinit_io()may read a line still rising from whatever the program left in port A. That would fit a step that is new in 3.15, happens only after the C64 has run, varies in direction, and doesn't show on a U2+L in a C64 Ultimate, if its CIA drives its lines rather than pulling them up. None of this has been measured.Change
Keyboardgainsignore_held_input(), whichUserInterface::run_once()calls right aftertake_ownership().Keyboard_C64::ignore_held_input()disarms the scanner and drops its buffer from the reading end. On builds that scan from the timer, it does both in one critical section, so a timer scan cannot queue a key in between. This follows the ownership rules from 9b22d87: the scan andpush_head()write the head, the UI task moves the tail.scan()queues nothing until it has seen no key and no joystick. A modifier held on its own, such as SHIFT LOCK, still arms it.clear_buffer()is unchanged. Popups call it on every LEFT/RIGHT redraw, so a key held in a popup keeps repeating.One side effect, for @GideonZ and @chrisgleissner to decide on: a joystick held on port 2 through
POST /v1/machine:inputas the menu opens also keeps the scanner disarmed, so the physical C64 keyboard is ignored in the menu until the REST client releases it. The USB keyboard is unaffected. I kept it this way because it is the same rule as a physical joystick, and a REST client holding the joystick through a menu open already made the cursor run.Tests, red then green
Host (
make -C software/io/usb/tests), inkeyboard_c64_clear_test.cpp:JoystickHeldWhenMenuOpensIsIgnoredUntilReleased: built against master'skeyboard_c64.cc, withignore_held_input()stubbed to only empty the buffer, it fails with the phantomKEY_UP(-1 vs 145, six times in 40 scans); with this change it passes. It takes the physical-line branch ofscan()(joy = true).ClearBufferKeepsHeldKeyRepeating: this failed against my first version, which disarmed insideclear_buffer(). That is how the popup side effect showed up.JoystickWorksWithoutIgnoreHeld: a press without the new call still arrives at once. This and the repeat test pass on master too, so existing behaviour is kept.software/io/usb/tests,software/api/testsandsoftware/filemanager/testspass.NO_FILE_ACCESS), so the critical section is covered by review, not by a test.E2E: a new
menu-held-inputscenario in theinputsuite. It is in the quick profile, so it runs in the default gate. It parks the highlight on the first entry, holds port 2 down, opens the menu, and requires the highlight to stay put while held and after release. A fresh cursor key must still move it.FAIL (the menu opened with the highlight on (3, 'Flash ...') instead of (2, 'Temp ...'): the held input moved it as the menu opened). That is the single step from the report.OK.scan(); the physical-line branch a II+ would take is covered by the host test.restMatrixActive()) and reach the menu through the USB queue, so an E2E check with a held key or SHIFT would pass with or without this change. I left those out. SHIFT LOCK held on its own is covered by review only.Build: rebased on master 2c60bd8. u2_rv, u2plus, u2pl, u64 and u64ii applications link from a clean tree on the CI-matched toolchain (Quartus 18.1, RISC-V GCC 10.2.0).
Hardware: Ultimate 64 Elite, FPGA 125, core 1.50, and an Ultimate II+ by @radius75 (see the top).
Full default E2E gate (
./run-tests -H 192.168.1.148) on the rebased branch: 31 of 31 suites passed. The complete log is in the latest two comments below, because it is too long for the description.