🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #43183

Re: Want to remap ` and ESC keys on XT

#43183
From: Patrick McCarthy
Date: Tue, 27 Feb 1990 06:44
166 lines
6359 bytes
In article <9799@batcomputer.tn.cornell.edu> braner@tcgould.tn.cornell.edu (Moshe Braner) writes:
>In the book DOS POWER TOOLS by the editors of PC Mag (highly recommended!)
>there is a utility (in the accompanying disk) called IBMFIX.  It swaps the
>ctrl and capslock keys.  It is a small .com file so it should be easy to patch
>it to swap ` and esc instead.  (It is a TSR that traps the keyboard interrupt.)
>
>If anybody enhanced it to swap BOTH pairs of keys, can I have a copy?  Thanks.
>
>- Moshe

Attached is the MASM 5.0 source for a TSR I wrote which switches the ctrl and
capslock keys.  It relies on Interrupt 15h, function 45h, which according
to IBM is invoked by the keyboard BIOS on all AT class machines, and
most XT machines.  I can't guarantee it will work on all XTs or even
all clone XTs, but it does work on all AT clones I've tried.
It's pretty simple-minded, but it's small and it works.

Pat McCarthy
mccarthy@well.uucp

--- Cut Here ---
page 82,132
Title CTRLCAPS key switcher source
;==============================================================================
;
;
;	CTRLCAPS  TSR which "switches" the Caps Lock key with the left
;		  Ctrl key.
;
;	Version 1.10 November 15, 1989	PKM
;
;==============================================================================
;
	name	    ctrlcaps
	mycode	   segment byte public 'code'
 
	assume cs:mycode
	assume ds:mycode
 
vector_save	    dd	    0		; Previous contents of INT 15H vector.
 
ctrl_make	    equ     01dh	; Keyboard (hardware) make and break
ctrl_break	    equ     09dh	; scan codes for the left Ctrl key
caps_make	    equ     03ah	; and he Caps Lock key.
caps_break	    equ     0bah	;
 
;==============================================================================
;
;	DO_SWITCH is an interrupt service routine  which gins control
;	whenever interrupt 15H is invoked.  If function 4F is requested,
;	the value of the AL register is examined to determine whether it
;	contains a make or break code for the Caps Lock key or the left
;	Ctrl key.  If it does, it is changed to the corresponding make or
;	break code for he other key, effectively switching the operation
;	of the Caps Lock and left Ctrl keys.
;
;	Note that there are three different sets ofscan codes that the
;	keyboard can be programmed to send.  do_switch assumes that set
;	1 (as documented by IBM) is currently in effect.
;
;	The IBM BIOS interrupt 9 handler on many XT and AT machines
;	invovkes software interrupt 15H, function 4F, after receiving a
;	keyboard make/break code from the keyboard controller, but before
;	any translation takes place.  The value contained in the AL
;	register is the (hardware) scan code the BIOS is about to process.
;	That scan code can be changed by the 15H handler; if the carry flag
;	is clear upon return from the 15H handler, the BIOS will discard the
;	keystroke entirely.
;
;==============================================================================
 
do_switch	proc	near
		assume	ds:nothing
 
		cmp	ah, 4Fh 	; Function 4Fh requested?
		jne	shot jump_prev ; If not, chain to previous handler.
 
check_ct_make:
		cmp	al, ctrl_make	; Make code for left Ctrl key?
		jne	check_ct_break	; No, check next code.
		mov	al, caps_make	; Yes, change it to Caps make,
		jmp	shor jump_prev ; and exit.
 
check_ct_break:
		cmp	al, ctrl_break	; Break code for left Ctrl key?
		jne	check_cp_make	; No, check next code.
		mov	al, caps_break	; Yes, change it to Caps break,
		jmp	short jump_prev ; and exit.
 
check_cp_make:
		cmp	al, caps_make	; Make code for Caps Lock key?
		jne	check_cp_break	; No, check next code.
		mov	al, ctrl_make	; Yes, change it to Ctrl make,
		jmp	short jump_prev ; and exit.
 
check_cp_break:
		cmp	al, caps_break	; Break code for Caps Lock key?
		jne	jump_prev   	; No, exit.
		mov	al, ctrl_break	; Yes, change it to Ctrl make.
 
jumpprev:				; Jump to the previous handler.
		jmp	dword pt vector_save
 
endcode 	label	near		; This marks the end of the code
					; which will remain resident when
					; CTRLCAPS goes TSR.
 
do_switch	endp
 
 
;==============================================================================
;
;	MAIN is the entry point for CTRLCAPS.  It frees CTRLCAPS' copy of
;	the DOS environment, saves the address of the current int 15H
;	handler in the variable vector_save, places the address of
;	do_switch (the int 15H handler) in the vector, and calls DOS to
;	terminate and stay resident.  Note that the label endcode is used
;	to determine the size of the memory block which remains.  Thus,
;	main itself does not stay in memory when CTRLCAPS terminates.
;
;==============================================================================
 
main		proc	near
 
		mov	cx, ds		; Save the value of DS for later.
 
		mov	ah, 49h
		mov	es, word ptr ds:[2ch]
		int	21h		; Free the environment segmnt.
 
					; Save the address of the current
					; 15H handler, then install
					; do_switch as the 15H handler.
		mov	ax, 0
		mov	ds, ax
		assume	ds:nothing
 
		les	si, ds:[54H]
		mov	word ptr vector_save, si
		mov	word ptr vector_save+2, es
 
		cli			; Disable interrupts, install ISR.
		mov	word ptr ds:[54h], offset do_switch
		mov	ds:[56h], cs
		sti
 
		mov	ah, 31h 	; Prepare to terminate and stay
		mov	al, 0		; resident.
 
					; Compute resident size.
		mov	dx, seg endcode
		sub	dx, cx		; CX still contains initial DS,
					; which points to the PSP.
		mov	cx, 4
		shl	dx, cl		; Convert from paragraphs to bytes.
		add	dx, (offset endcode + 15)
		mov	cx, 4
		shr	dx, cl	; Convert from bytes to paragraphs.
		int	21h		; Terminat and stay resident.
 
main		endp
 
mycode		ends
		end main

--- Cut Here ---
Technical Details
Message-ID: <16431@well.sf.ca.us>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!snorkelwacker!apple!well!mccarthy
References: <1755@borabora.omni.com> <578@massey.ac.nz> <9799@batcomputer.tn.cornell.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!snorkelwacker!apple!well!mccarthy
From: mccarthy@well.sf.ca.us (Patrick McCarthy)
Newsgroups: comp.sys.ibm.pc
Subject: Re: Want to remap ` and ESC keys on XT
Keywords: IBM, PC, XT, keyboard, ESC
Message-ID: <16431@well.sf.ca.us>
Date: 27 Feb 90 06:44:11 GMT
References: <1755@borabora.omni.com> <578@massey.ac.nz> <9799@batcomputer.tn.cornell.edu>
Reply-To: mccarthy@well.UUCP (Patrick McCarthy)
Distribution: usa
Organization: Whole Earth 'Lectronic Link, Sausalito, CA
Lines: 166