Last active
September 8, 2018 00:48
-
-
Save jtsiomb/2a6ab508e01c959a67378ebed3771932 to your computer and use it in GitHub Desktop.
DOS TSR for remapping caps lock to control (see comment at the end for pre-built binaries)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; DOS caps lock -> ctrl remapper | |
; Author: John Tsiombikas <[email protected]> | |
; This program is public domain. Do whatever you like with it | |
; build with: nasm -o capsctrl.com -f bin capsctrl.asm | |
org 100h | |
bits 16 | |
mov ax, 0900h | |
mov dx, msg | |
int 21h | |
; get current keyboard interrupt handler | |
mov ax, 3509h | |
int 21h | |
mov [orig_seg], es | |
mov [orig_off], bx | |
; set our own interrupt handler in its place | |
mov ax, 2509h | |
mov dx, kbintr | |
int 21h | |
mov ax, 0900h | |
mov dx, msg_done | |
int 21h | |
; terminate and stay awesome | |
mov dx, end_of_code | |
int 27h | |
KB_INTR equ 09h | |
KB_PORT equ 60h | |
PIC1_CMD_PORT equ 20h | |
OCW2_EOI equ 20h | |
KBFLAGS0 equ 0x17 | |
KBFLAGS1 equ 0x18 | |
KBF0_CTRL equ 0x04 | |
KBF1_LCTRL equ 0x01 | |
SCAN_CAPS_PRESS equ 0x3a | |
SCAN_CAPS_RELEASE equ 0xba | |
kbintr: | |
push ax | |
in al, KB_PORT | |
cmp al, SCAN_CAPS_PRESS | |
jz .caps_press | |
cmp al, SCAN_CAPS_RELEASE | |
jz .caps_release | |
; otherwise jump to the original handler | |
pop ax | |
push word [cs:orig_seg] | |
push word [cs:orig_off] | |
retf | |
.caps_press: | |
; set ctrl flags | |
mov ax, es | |
push word 0x40 | |
pop es | |
or byte [es:KBFLAGS0], KBF0_CTRL | |
or byte [es:KBFLAGS1], KBF1_LCTRL | |
mov es, ax | |
jmp .end | |
.caps_release: | |
; clear ctrl flags | |
mov ax, es | |
push word 0x40 | |
pop es | |
and byte [es:KBFLAGS0], ~KBF0_CTRL | |
and byte [es:KBFLAGS1], ~KBF1_LCTRL | |
mov es, ax | |
.end: mov al, OCW2_EOI | |
out PIC1_CMD_PORT, al | |
pop ax | |
iret | |
msg db 'Installing capslock -> ctrl mapper... $' | |
msg_done db 'done.',13,10,'$' | |
orig_seg dw 0 | |
orig_off dw 0 | |
end_of_code: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: I since generalized this hack, made it able to remap caps lock to any key (configurable with rebuild), added a utility for finding the proper scancode to use for configuring it, and made it a full project at: https://github.com/jtsiomb/capsmap
The release archive of capsmap includes pre-built binaries
capsctrl.com
andcapsesc.com
for remapping caps lock to ctrl or escape: https://github.com/jtsiomb/capsmap/releases/download/v1.0/capsmap.zip