Skip to content

Instantly share code, notes, and snippets.

@jtsiomb jtsiomb/capsctrl.asm
Last active Sep 8, 2018

Embed
What would you like to do?
DOS TSR for remapping caps lock to control (see comment at the end for pre-built binaries)
; DOS caps lock -> ctrl remapper
; Author: John Tsiombikas <nuclear@member.fsf.org>
; 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:
@jtsiomb

This comment has been minimized.

Copy link
Owner Author

jtsiomb commented Sep 8, 2018

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 and capsesc.com for remapping caps lock to ctrl or escape: https://github.com/jtsiomb/capsmap/releases/download/v1.0/capsmap.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.