write an "operating system" that dims Num Lock



I want to write x86 assembler code that can be used to boot your computer from and dims NumLock. This means

  • you cannot rely on glibc or any other of these "comfi" libraries
  • you cannot rely on the Linux kernel
  • we will test your code by dumping it onto a virtual floppy and boot a VM from it
  • goal is to switch on and off NumLock so quickly that it appears dimmed
  • it's okay if everything fits into the bootloader and loops endlessly

Solution with most votes wins.

Thorsten Staerk

Posted 2014-01-02T06:31:17.883

Reputation: 261

1I know you think "dim numlock - that's easy" but it is not. So much has to happen to get that far, like scanning for devices and drivers for them. A PS2 keyboard might be easier but I digress. I could make a z80 output "Hello world!" via a UART easily though :P – Alec Teal – 2014-01-02T08:11:23.857

wow good comment... I did dim NumLock once and thought I knew it was easy. But that was maybe specific to my DIN keyboard (DIN was the predecessor for PS/2 at least in Germany). – Thorsten Staerk – 2014-01-02T09:58:48.853

doesn't the BIOS give you an address where to write the NumLock? If not, how would you do it e.g. in the boot loader? Now I am curious to solve my own excercise :) – Thorsten Staerk – 2014-01-02T09:59:39.543

use port 60: http://stackoverflow.com/questions/3434827/assembly-keyboard-io-port

– Thorsten Staerk – 2014-01-02T10:02:35.620



I haven't tested this (VirtualBox doesn't pass through its virtual keyboard LEDs onto the physical keyboard, and I'm not on a PC I can reboot currently). But I think it should probably work and is probably quite minimal.

There may be some additional setup that needs to be done on the keyboard controller for these commands to work. If so it would be essentially trivial to add to the code below...

[bits 16]
[org 0x7c00]
mov al, 0xed
out 0x60, al
mov al, 0x07
out 0x60, al
mov al, 0xed
out 0x60, al
mov al, 0x00
out 0x60, al
jmp $$
times 510 - ($ - $$) db 0
dw 0xaa55

Compile with nasm -f bin -o floppy.img numlock.asm.

Will give this a real test and tweak accordingly later (if someone else wants to try and/or tweak it feel free).


Posted 2014-01-02T06:31:17.883

Reputation: 241

1works on my laptop. My laptop's numlock goes on an off. No external keyboard needed. Also scroll lock and caps lock. Good trick with times 510 - ... – Thorsten Staerk – 2014-01-03T09:52:59.867