a500kbd

diff src/main.c @ 3:31a1f0b53d98

- scroll lock now acts as caps lock - the scroll-lock light indicates drive activity
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 18 Oct 2017 08:20:58 +0300
parents a4fd9c5a6655
children
line diff
     1.1 --- a/src/main.c	Tue Oct 17 15:25:33 2017 +0300
     1.2 +++ b/src/main.c	Wed Oct 18 08:20:58 2017 +0300
     1.3 @@ -22,10 +22,12 @@
     1.4  #define KF_TRANSIENT	0x0f
     1.5  #define KF_STICKY		0xf0
     1.6  
     1.7 +static unsigned char led_state;
     1.8 +
     1.9  int main(void)
    1.10  {
    1.11  	unsigned int keyflags = 0;
    1.12 -	unsigned char keycode;
    1.13 +	unsigned char c, keycode, prev_drvled = 0;
    1.14  	int press;
    1.15  
    1.16  	/* disable all pullups globally */
    1.17 @@ -46,8 +48,23 @@
    1.18  
    1.19  	EIMSK = (1 << INT0) | (1 << INT1);	/* enable ps/2 clock interrupt */
    1.20  
    1.21 +	ps2setled(0);	/* start with all LEDs off */
    1.22 +
    1.23  	for(;;) {
    1.24 -		unsigned char c = ps2read();
    1.25 +		while(!ps2pending()) {
    1.26 +			unsigned char drvled = PIND & ADRVLED_BIT;
    1.27 +			if(drvled != prev_drvled) {
    1.28 +				prev_drvled = drvled;
    1.29 +				if(drvled) {
    1.30 +					led_state |= PS2LED_SCRLK;
    1.31 +				} else {
    1.32 +					led_state &= ~PS2LED_SCRLK;
    1.33 +				}
    1.34 +				ps2setled(led_state);
    1.35 +			}
    1.36 +		}
    1.37 +
    1.38 +		c = ps2read();
    1.39  		switch(c) {
    1.40  		case 0xe0:	/* extended */
    1.41  			keyflags |= KF_EXT;
    1.42 @@ -66,12 +83,10 @@
    1.43  
    1.44  			keycode = 0xff;
    1.45  			if(keyflags & KF_EXT) {
    1.46 -				printf("ext ");
    1.47  				if(c < KEYMAP_EXT_SIZE) {
    1.48  					keycode = keymap_ext[(int)c];
    1.49  				}
    1.50  			} else if(keyflags & KF_EXT1) {
    1.51 -				printf("ext1 ");
    1.52  			} else {
    1.53  				if(c < KEYMAP_NORMAL_SIZE) {
    1.54  					keycode = keymap_normal[(int)c];
    1.55 @@ -109,17 +124,19 @@
    1.56  				amikb_reset();
    1.57  			}
    1.58  
    1.59 -			printf("scancode %x -> ", (unsigned int)c);
    1.60  			if(keycode != 0xff) {
    1.61 -				amikb_sendkey(keycode, ~keyflags & KF_BRK);
    1.62 -				printf("[%s] amiga key %xh\r\n", press ? "press" : "release", keycode);
    1.63 +				int press = ~keyflags & KF_BRK;
    1.64 +				amikb_sendkey(keycode, press);
    1.65 +				if(keycode == 0x62 && press) {
    1.66 +					led_state ^= PS2LED_CAPSLK;
    1.67 +					ps2setled(led_state);
    1.68 +				}
    1.69 +				/*printf("scancode %x -> [%s] amiga key %xh\r\n", (unsigned int)c, press ? "press" : "release", keycode);*/
    1.70  			} else {
    1.71 -				printf("[%s] no translation\r\n", press ? "press" : "release");
    1.72 +				printf("PS/2 unknown command or keycode: %x\r\n", (unsigned int)c);
    1.73  			}
    1.74  			keyflags &= ~KF_TRANSIENT;
    1.75  		}
    1.76  	}
    1.77  	return 0;
    1.78  }
    1.79 -
    1.80 -