The attached file, hidden.prg, is the Vic-20 version of "Hidden Maze", pg 152 of Compute! December 1982. When it is first ran after a cold start, moving right with the joystick doesn't work. When re-running after run/stop restore, it works fine.
The second file, hidden2.prg, is a fix I implemented. The code follows the example given at https://sleepingelephant.com/denial/wiki/index.php/Joystick. It works as expected when running after both a cold start and run/stop restore.
I'm a bit baffled why the first one doesn't work but the second one does. I tried various combinations of the peek and poke orders of VIA registers, and wondered if the way x is assigned in line 210 (ie using 'not peek' and peek in the expression) might make a difference, but am really not very knowledable about this stuff. When I tried to use Claude to figure it out, it suggested it might be the emulator that has a bug - I get the same results on the old WinVice2.4-x86 but do not see the bug with the Vic-20 (NTSC) (short name: vic20) in MAME v0.288 (linux). I do not have a real Vic-20 to determine what happens on it.
Also note I tried both the vic20 ntsc and vic20 pal in xvic with both the number pad joystick and my Logitech USB joystick. The results were all the same.
When I searched for similar bugs here, I found https://sourceforge.net/p/vice-emu/bugs/535/
Well the first thing to do is checking on the real thing :)
It's not you, it's me.
Per https://sleepingelephant.com/~sleeping/ipw-web/bulletin/bb/viewtopic.php?t=7389, the issue exists on real hardware, related to floppy access.
A quick fix is to enter SYS 65017, which resets the VIA registers, before running hidden.prg.
The post also suggests writing correct joystick code, linking to same article I coincidently used to write hidden2.prg.
Also note, putting hidden.prg on a tape instead of a disk also prevents the bug from happening.
Ha!, so we can close this? :)