Now on the Lisa, WaitForCops works as expected: type some keys, move the mouse, and you get bytes; otherwise you don't (or maybe you get zero bytes---my program doesn't display those). Either way, something I can work with.
In LisaEm 1.2.6.2, WaitForCops works as expected until the first time I move the mouse. Then it continually streams what looks like the last mouse byte it had streamed previously (again, maybe there are zeros I'm not seeing). You can type more, or move the mouse more, and see those codes blip up occasionally in the bytes, but the old mouse bytes just won't stop---they just keep coming and coming.
Hi Tom!
Thanks for this, I'll test this out and see if I can fix this behavior!
That if statement is basically saying, if there's no keys in the queue to send, and the Lisa is reading from the VIA, then send a mouse movement. If there's no mouse movement recently, send code 0 which indicates mouse status, followed dx,dy, but in this case dx=0, dy=0, so you'd get 3 zero bytes. (mouse movements are additive to the dx,dy, so if you first move +1,+2 and a bit later, you move +1,+1, it will send +2,+3.)
Off the top of my head it should add mouse movement to the queue anyway, so this condition is when you'd use polled I/O without an interrupt service routine. I'm not sure what a real COPS will return in that case, but expected a null mouse movement wouldn't break anything.
But it should not repeat the same movement again.
So, as an aside, so what are you seeing returned on the real Lisa when there's no mouse movement and no keys pressed and you read from IRA, ignoring the IFR wait? I'll add that to that fn if you have seen it.
I think in this case the bug is that the IFR is being set and not cleared somehow, or something else is setting it again and again. Off the top of my head, I think I remember the VIA docs say that when IRA is read or written to, from it should clear that corresponding IFR bit.
So likely the bug isn't in that line but rather that the IFR bit isn't being cleared on the read. Which might be the case. The macro on line 1072 should be clearing that IRQ, but perhaps it isn't working as intended.
https://github.com/rayarachelian/lisaem/blob/8ae6947342ed6035fe5f99ea65ab0631204ade2d/src/lisa/io_board/cops.c#L1072I can understand that when you get the first zero, two more are sent as dx,dy, and this would trigger IFR again as the cops queuelen is now 2 after reading the 1st zero. But that should stop after reading that 3rd byte. So not sure why it's repeating beyond that. The bug might even be in irq.c and not in either via6522.c nor cops.c.I'd suspect this block:
https://github.com/rayarachelian/lisaem/blob/8ae6947342ed6035fe5f99ea65ab0631204ade2d/src/lisa/cpu_board/irq.c#L809 or maybe here:https://github.com/rayarachelian/lisaem/blob/8ae6947342ed6035fe5f99ea65ab0631204ade2d/src/lib/libGenerator/generator/reg68k.c#L301
irq.c is a bit complex, it has a way to queue IRQs in the future, for things like the VIA timers, video retrace, and async disk requests.
I'll experiment in the current repo and see what I'll find and reply here again.
Please note that the source code you're looking at is actually 1.2.7 and not 1.2.6.2 but much of this code hasn't been touched for the 1.2.7 changes.
I'd do another push soon, but I've been stuck trying to sort out some issues with scaling and skinless modes for the last couple of weeks without much progress. (Basically the wx3.1.2 is reporting a screen size of 1920x1080 for my 4K display possibly because I've set GTK scaling to 200% and it's trying to do 4K scaling, but wx3.0.x returns 4K for the resolution!
Then on top of that the dc has it's own scaling via dc.SetUserScale, which I'm now using instead of the code from the last push. But now I'm having trouble calculating the sizes and locations of things and so both mouse and centering code is broken in OnPaint_skinless() for zoom sizes other than 50% ). Skinned modes work fairly well, but not for all scale sizes.
Edit, yup, confirmed, this is stuck forever flagging that it has mouse movement data as soon as the mouse is moved the first time and doesn't quiesce.:
src/lisa/io_board/cops.c:via1_ira:1061:IRA1 copsqueuelen:0, mousequeuelen:1 cops_mouse:81500 VIA1.IFR:00000000 VIA1.IER:00000082| 20:16:03.9 858443839
src/lisa/io_board/cops.c:via1_ira:1061:IRA1 copsqueuelen:2, mousequeuelen:1 cops_mouse:81500 VIA1.IFR:00000000 VIA1.IER:00000082| 20:16:03.9 858443973
src/lisa/io_board/cops.c:via1_ira:1061:IRA1 copsqueuelen:2, mousequeuelen:1 cops_mouse:81500 VIA1.IFR:00000000 VIA1.IER:00000082| 20:16:03.9 858443973
src/lisa/io_board/cops.c:via1_ira:1061:IRA1 copsqueuelen:1, mousequeuelen:1 cops_mouse:81500 VIA1.IFR:00000000 VIA1.IER:00000082| 20:16:03.9 858444105
src/lisa/io_board/cops.c:via1_ira:1061:IRA1 copsqueuelen:1, mousequeuelen:1 cops_mouse:81500 VIA1.IFR:00000000 VIA1.IER:00000082| 20:16:03.9 858444105
src/lisa/io_board/cops.c:via1_ira:1061:IRA1 copsqueuelen:0, mousequeuelen:1 cops_mouse:81500 VIA1.IFR:00000000 VIA1.IER:00000082| 20:16:03.9 858445857
src/lisa/io_board/cops.c:via1_ira:1061:IRA1 copsqueuelen:0, mousequeuelen:1 cops_mouse:81500 VIA1.IFR:00000000 VIA1.IER:00000082| 20:16:03.9 858445857
src/lisa/io_board/cops.c:via1_ira:1061:IRA1 copsqueuelen:2, mousequeuelen:1 cops_mouse:81500 VIA1.IFR:00000000 VIA1.IER:00000082| 20:16:03.9 858445991
s
Here's a workaround, add this line:
if ( !(mouse_pending_x|mouse_pending_y) && mousequeuelen==1 && copsqueuelen==0) mousequeuelen=0;
here:
https://github.com/rayarachelian/lisaem-1.2.x/blob/v1.2.6.2.1/lisa/cops.c#L1242 for 1.2.6.2
or here:
https://github.com/rayarachelian/lisaem/blob/master/src/lisa/io_board/cops.c#L1244 for 1.2.7