English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 13 November 2019, 16:37   #81
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Quote:
Originally Posted by deimos View Post
Ok. In the meantime I'll try something without the KPrintFs to prove (or not) that it happens for me on my vanilla WinUAE, and if so I'll code around it while we wait for an answer - the rest of my code is probably still buggy.
Ok, so I've just done this:

Code:
// KPrintF("rawKeyCode = %ld\n", rawKeyCode);
extern volatile struct Custom * custom;
custom->color[0] = 0xf00;
So, you'll get a flash of red for every key code. Hold down a key and you'll get a flash then nothing until you release it. Trigger the behaviour by hitting two keys together at exactly the same time and you'll get a lot of red as the key downs are repeated.

Edit: I do get the behaviour on the Amiga 1000 I've set up under WinUAE.

Edit 2: Could my handshaking code be buggy somehow, and WinUAE is trying to do the right thing by resending key codes? Perhaps I should be testing someone else's code here rather than asking other people to test mine.

Edit 3: As well as this, I'm going to cut down my code to down nothing but a keyboard routine, then, if it is my fault, it should be easier for someone to point out why.
Attached Files
File Type: zip key-flashes.zip (21.6 KB, 11 views)

Last edited by deimos; 13 November 2019 at 17:30.
deimos is offline  
Old 13 November 2019, 19:09   #82
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Quote:
Originally Posted by deimos View Post
I'm going to cut down my code to down nothing but a keyboard routine, then, if it is my fault, it should be easier for someone to point out why.
The attached file is the smallest I can quickly do that shows the problem without any unrelated code included.
Attached Files
File Type: zip keyboard.zip (104.3 KB, 9 views)
deimos is offline  
Old 13 November 2019, 21:33   #83
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
I now tried your binaries on a real A1000 with 8MB Ram KS1.3. Good news is, it works perfectly well and it also doesn't exhibit the problem with the keypresses continuing. Rotation, hud, exiting, all works fine.

BUT! Your cleanup doesn't work properly. When I ran keyboard.exe after the flightsim it didn't work at all. After rebooting, and starting keyboard first, it worked, but I couldn't exit and had to reboot.
After that I started flightsim, tested it a bit and exited, After that I tried to run it again but it just hangs. It doesn't start up and stays in the Shell screen. Mouse works, but no keyboard anymore until reboot.

I must say, it looks pretty cool on a real hardware, and I like it more, than when I tried it in the emulator. Good work so far!
sparhawk is offline  
Old 13 November 2019, 21:57   #84
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Quote:
Originally Posted by sparhawk View Post
I now tried your binaries on a real A1000 with 8MB Ram KS1.3. Good news is, it works perfectly well and it also doesn't exhibit the problem with the keypresses continuing. Rotation, hud, exiting, all works fine.

BUT! Your cleanup doesn't work properly. When I ran keyboard.exe after the flightsim it didn't work at all. After rebooting, and starting keyboard first, it worked, but I couldn't exit and had to reboot.
After that I started flightsim, tested it a bit and exited, After that I tried to run it again but it just hangs. It doesn't start up and stays in the Shell screen. Mouse works, but no keyboard anymore until reboot.

I must say, it looks pretty cool on a real hardware, and I like it more, than when I tried it in the emulator. Good work so far!
I know I don't free the memory I allocate, but I do reset everything else, so the keyboard only example should exit cleanly if nothing else has taken all the memory before it. But I don't claim to know what I'm doing.

Regarding the keyboard repeats, there's definitely a bug. At the moment I'd put money on it being in my code, but the effect of the bug is to show limitations of how the Windows keyboard is mapped onto the emulated hardware. And then there are the other bugs which led us here, including potential compiler / optimiser bugs, but one step at a time.

Last edited by deimos; 13 November 2019 at 22:28.
deimos is offline  
Old 13 November 2019, 23:25   #85
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
Quote:
Originally Posted by deimos View Post
Regarding the keyboard repeats, there's definitely a bug.

What is the desired behavior? One thing I noticed is, that there is some kind of "afterglow" effect. So you press keys and after releasing them it takes a short time until it stops spinning. Not sure if this is intended or if this is the bug you are refering to.
My assumption was that you may record keystrokes faster then you can refresh the display, so it takes some time until the remaining keypresses are processed.
sparhawk is offline  
Old 14 November 2019, 08:00   #86
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Quote:
Originally Posted by sparhawk View Post
What is the desired behavior? One thing I noticed is, that there is some kind of "afterglow" effect. So you press keys and after releasing them it takes a short time until it stops spinning. Not sure if this is intended or if this is the bug you are refering to.
My assumption was that you may record keystrokes faster then you can refresh the display, so it takes some time until the remaining keypresses are processed.
No, that's the intended behaviour. I model a control stick that moves as you hold down a key, until it gets as far as it should go, and then returns back to the centre over a few frames rather than snapping back instantly.

It should not be possible to record keystrokes faster than I can refresh the display. For any key pressed I should only get a key pressed and a key released code, no matter how long I hold the key down for.

With the stripped down version all that control stick modelling and screen drawing is gone, and the problem is still there, so the bug can only be in WinUAE.

The question is, is there also a bug in my code that if squashed would prevent the WinUAE bug from showing? For instance, does the emulated keyboard controller think I'm hand shaking wrong, and is resending keystrokes? But doing it wrong by sending them for all keys that are held down, and at the Windows keyboard repeat rate?
deimos is offline  
Old 14 November 2019, 10:36   #87
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Minimal code to reproduce

I've now stripped out everything to the absolute bare minimum that reproduces the key repeat problem and attached it here, including .s and .map files.

The important code is now all together in the one file, interrupts.c, and that is also pasted below.

I'll give it a while for someone to point out my mistake, and then I'll work out how to report a bug against WinUAE.

Code:
#include "interrupts.h"

#include <hardware/custom.h>
#include <hardware/intbits.h>
#include <hardware/cia.h>

#define KEYBOARD_HANDSHAKE_DELAY 142

// static method prototypes

static __attribute__((interrupt)) void HandleLevel2Interrupt(void);

extern struct ExecBase * SysBase;

// lifecycle methods

void Interrupts_Init(void) {
    extern volatile APTR * VBR;

    VBR[26] = (APTR) HandleLevel2Interrupt;

    extern volatile struct CIA * ciaa;

    ciaa->ciacra = 0;
    ciaa->ciatalo = (UBYTE) (KEYBOARD_HANDSHAKE_DELAY & 0xff);
    ciaa->ciatahi = (UBYTE) (KEYBOARD_HANDSHAKE_DELAY >> 8 & 0xff);
    ciaa->ciaicr = CIAICRF_FLG | CIAICRF_SP | CIAICRF_ALRM | CIAICRF_TB | CIAICRF_TA;
    UBYTE ciaicr = ciaa->ciaicr; // warning: unused variable 'ciaicr' [-Wunused-variable]
    ciaa->ciaicr = CIAICRF_SETCLR | CIAICRF_SP | CIAICRF_TA;
}

// public methods

void Interrupts_EnableInterrupts(UWORD mask) {
    extern volatile struct Custom * custom;

    custom->intreq = mask;
    custom->intena = INTF_SETCLR | INTF_INTEN | mask;
}

void Interrupts_DisableInterrupts(UWORD mask) {
    extern volatile struct Custom * custom;

    custom->intena = (UWORD) INTF_INTEN | mask;
    custom->intreq = mask;
}

// static methods

static __attribute__((interrupt)) void HandleLevel2Interrupt(void) {
    extern volatile struct Custom * custom;

    UWORD intreqr = custom->intreqr;

    while (intreqr & INTF_PORTS) {
        custom->intreq = (UWORD) INTF_PORTS; custom->intreq = (UWORD) INTF_PORTS;

        extern volatile struct CIA * ciaa;

        UBYTE ciaicr = ciaa->ciaicr;

        if (ciaicr & CIAICRF_TA) {
            ciaa->ciacra = 0;
        }

        if (ciaicr & CIAICRF_SP) {
            ciaa->ciacra = CIACRAF_SPMODE | CIACRAF_LOAD | CIACRAF_RUNMODE | CIACRAF_START;

extern volatile struct Custom * custom;
custom->color[0] = 0xf00;

        }
    }
}
Attached Files
File Type: zip keyboard.14-November-2019.zip (59.7 KB, 7 views)
deimos is offline  
Old 14 November 2019, 10:53   #88
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,620
Quote:
Originally Posted by deimos View Post
The question is, is there also a bug in my code that if squashed would prevent the WinUAE bug from showing? For instance, does the emulated keyboard controller think I'm hand shaking wrong, and is resending keystrokes? But doing it wrong by sending them for all keys that are held down, and at the Windows keyboard repeat rate?
If this ends up being a bug that's not in your code (e.g. Windows bug), there is an easy way to make a workaround. Simply keep the previous status of every key you use. When you reveive a key down, mark the key as being down - and if it was already down before, ignore the event. When you receive a key up, mark the key as being up.
meynaf is offline  
Old 14 November 2019, 10:56   #89
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Quote:
Originally Posted by meynaf View Post
If this ends up being a bug that's not in your code (e.g. Windows bug), there is an easy way to make a workaround. Simply keep the previous status of every key you use. When you reveive a key down, mark the key as being down - and if it was already down before, ignore the event. When you receive a key up, mark the key as being up.
Agreed, I'll do that so that I can move forward, but that will only fix it for my code.
deimos is offline  
Old 14 November 2019, 10:57   #90
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 44
Posts: 23,366
First step is to check if it is keyboard/Windows sending multiple key codes (it shouldn't). Enable debugger (shift+f12), type "dj 1", exit with "g".

Press keys, check if log shows duplicated key events.

btw, write to INTREQ after reading CIAICR. INTREQ clear does nothing because CIA interrupt line is still active (it clears after CIAICR is read). This means every CIA interrupt executes your interrupt routine twice (second time finally clears INTREQ), wasting little CPU time.
Toni Wilen is online now  
Old 14 November 2019, 11:11   #91
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
My log file shows this:

Code:
2019-11-14 10:08:07
07-292 [6793 000-210]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
07-292 [6793 000-210]: Amiga key 4F 0
07-300 [6794 000-000]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
07-300 [6794 000-000]: Amiga key 4C 0
09-036 [6880 000-210]: STATE=00000 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
09-036 [6880 000-210]: Amiga key 4F 1
09-036 [6880 000-210]: STATE=00000 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
09-036 [6880 000-210]: Amiga key 4C 1
11-667 [7012 000-000]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
11-667 [7012 000-000]: Amiga key 4F 0
11-667 [7012 000-000]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
11-667 [7012 000-000]: Amiga key 4C 0
12-168 [7037 000-000]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
12-168 [7037 000-000]: Amiga key 4F 0
12-168 [7037 000-000]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
12-168 [7037 000-000]: Amiga key 4C 0
12-200 [7038 000-210]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
12-200 [7038 000-210]: Amiga key 4F 0
12-200 [7038 000-210]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
12-200 [7038 000-210]: Amiga key 4C 0
12-234 [7040 000-105]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
12-235 [7040 000-105]: Amiga key 4F 0
12-235 [7040 000-105]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
12-235 [7040 000-105]: Amiga key 4C 0
12-268 [7042 000-000]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
12-268 [7042 000-000]: Amiga key 4F 0
12-268 [7042 000-000]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
12-268 [7042 000-000]: Amiga key 4C 0
12-300 [7043 000-210]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
12-300 [7043 000-210]: Amiga key 4F 0
12-300 [7043 000-210]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
12-300 [7043 000-210]: Amiga key 4C 0
12-334 [7045 000-105]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Left' 
12-334 [7045 000-105]: Amiga key 4F 0
12-334 [7045 000-105]: STATE=00001 MAX=00001 AF=0 QUAL=000000 'Cursor Up' 
12-334 [7045 000-105]: Amiga key 4C 0
I'll make your suggested code changes soon, I want to hold just one thing in my head at the moment.
deimos is offline  
Old 14 November 2019, 11:50   #92
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
What I didn't know is that I can move the cursor diagonally in a text editor on Windows.

So, not a WinUAE bug, if Notepad will move the cursor diagonally if I press keys at exactly the same time, but horizontally or vertically if my timing is off. Right?

I'm now looking for something else I can plug this keyboard into to try and isolate whether it's a Windows or keyboard problem.

Edit: I can't reproduce the problem on a linux laptop. Plus the key repeat speed is tied to the Windows key repeat control panel setting, so I think that it's Windows not handling this, but if that's the case I don't understand why it's not a well known problem.

Last edited by deimos; 14 November 2019 at 12:05.
deimos is offline  
Old 14 November 2019, 12:09   #93
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 44
Posts: 23,366
Yeah, it is Windows or keyboard sending multiple press events. I don't filter them in emulation because Amiga supports it in hardware level and you aren't supposed to get any automatic key repeats when using Windows raw input API.
Toni Wilen is online now  
Old 14 November 2019, 12:17   #94
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Quote:
Originally Posted by Toni Wilen View Post
Yeah, it is Windows or keyboard sending multiple press events. I don't filter them in emulation because Amiga supports it in hardware level and you aren't supposed to get any automatic key repeats when using Windows raw input API.
I don't think it's the keyboard, but do you know of any way for me to rule that out? Something where I can see the raw USB stuff before Windows turns it into events?
deimos is offline  
Old 14 November 2019, 12:18   #95
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,241
Quote:
Originally Posted by Toni Wilen View Post
Yeah, it is Windows or keyboard sending multiple press events.
This is why I suggested to deimos to try another keyboard.
In my laptop for how many times I tried, I couldn't replicate the problem.
Otherwise it could also be somehow related to the Windows version?
ross is offline  
Old 14 November 2019, 12:20   #96
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,241
Quote:
Originally Posted by deimos View Post
Something where I can see the raw USB stuff before Windows turns it into events?
hmm, my keyboard is seen as a PS/2 device.

Quote:
Originally Posted by deimos View Post
Edit: I can't reproduce the problem on a linux laptop.
USB or PS/2?
ross is offline  
Old 14 November 2019, 12:38   #97
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Quote:
Originally Posted by ross View Post
hmm, my keyboard is seen as a PS/2 device.


USB or PS/2?
It's a USB keyboard. A WASD Code. Not the latest version, the version that has Micro USB.
deimos is offline  
Old 14 November 2019, 12:52   #98
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,241
Quote:
Originally Posted by deimos View Post
It's a USB keyboard. A WASD Code. Not the latest version, the version that has Micro USB.
I mean in the linux laptop (the integrated keyboard).
ross is offline  
Old 14 November 2019, 13:05   #99
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Quote:
Originally Posted by ross View Post
I mean in the linux laptop (the integrated keyboard).
This I don't know, but I tested by moving the WASD keyboard over to the laptop, and tested with by trying to move diagonally in vim. I can try and find out more about the laptop in a bit. I can probably see raw USB events easier in Linux than Windows too.
deimos is offline  
Old 14 November 2019, 14:00   #100
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 489
Below is that I see with a simple usbhid-dump.

Code:
aspire ~ # usbhid-dump -m 04d9:0169 -es
Starting dumping interrupt transfer stream
with 1 minute timeout.

003:004:000:STREAM             1573731817.048354
 00 00 52 00 00 00 00 00

003:004:000:STREAM             1573731820.152331
 00 00 00 00 00 00 00 00

003:004:000:STREAM             1573731821.920304
 00 00 50 00 00 00 00 00

003:004:000:STREAM             1573731825.416290
 00 00 00 00 00 00 00 00

003:004:000:STREAM             1573731826.776319
 00 00 50 52 00 00 00 00

003:004:000:STREAM             1573731829.904300
 00 00 00 00 00 00 00 00
This is actually what I remember from back when I was playing with connecting an Amiga keyboard to a PC through a Teensy - on every change you get sent a set of keys that are currently down, and everything else like key repeats is up to the driver on the PC. Above is me holding down cursor up, releasing it, then holding down cursor left, releasing it, then holding down both together.

If there's a lower level data stream I can capture I'm happy to, but someone will have to explain how.

I don't think the integrated keyboard is USB, as it's not generating anything that that command sees.

Edit: Tested the keyboard on another Windows machine and have the same diagonal cursor movement in Notepad. But I don't think the keyboard is doing anything wrong - I think Windows is not correctly handing two keys changing state within the same report, but this is probably something that doesn't happen (often) with normal keyboards. I don't think testing with another keyboard will do anything but confirm that keyboards vary.

Last edited by deimos; 14 November 2019 at 18:53.
deimos is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
loadwb -debug TroyWilkins Amiga scene 22 19 March 2017 12:08
Debug log trap vriviere support.WinUAE 1 01 July 2010 15:27
Hisoft C++ Debug AlfaRomeo Coders. General 0 13 October 2008 22:17
Mame32 Debug redblade Retrogaming General Discussion 4 10 October 2005 06:43
Debug ? mtb support.WinUAE 8 19 December 2002 13:19

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:35.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.09655 seconds with 16 queries