Fundamentals 27 min read

Inside Lei’s 1994 RAMinit TSR: Full Assembly Source and Analysis

This article presents the complete assembly source of the RAMinit TSR program written by Lei in 1994, explains its purpose as a hot‑key‑driven memory‑management utility for DOS, describes its interrupt‑vector handling, memory‑copy routines, and includes detailed comments that reveal the inner workings of this historic piece of system software.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Inside Lei’s 1994 RAMinit TSR: Full Assembly Source and Analysis

Background

The post showcases a complete assembly listing of the RAMinit TSR (Terminate‑and‑Stay‑Resident) program originally written by Lei (also known as "Mr. Leijun") between 1989 and 1994. The code was first shared on a Chinese micro‑blog in 2011, where it attracted attention for its high quality and elegant handling of DOS interrupt vectors, hot‑key activation, and memory management. The author of the article notes that some readers doubt the code’s quality, but contemporary programmers have praised its craftsmanship.

Source Code

; RI.ASM Revision 2.12 [ July 12, 1994 ]
Revision equ 'V2.12 '
; RAMinit Release 2.0
; Copyright (c) 1989-1994 by Yellow Rose Software Co.
; Written by Mr. Leijun
;
; Function:
; Press HotKey to remove all TSR program after this program
;
; ..........................................................................
; Removed Softwares by RI:
; SPDOS v6.0F, WPS v3.0F
; Game Busters III, IV
; NETX ( Novell 3.11 )
; PC-CACHE
; Norton Cache
; Microsoft SmartDrv
; SideKick 1.56A
; MOUSE Driver
; Crazy (Monochrome simulate CGA program)
; RAMBIOS v2.0
; 386MAX Version 6.01
; ..........................................................................
; No cancel softwares:
; Windows 3.1 MSD
;
; No removed TSR softwares:
; MS-DOS fastopen
; Buffers, Files ... (QEMM 6.0)
; QCache (386MAX 6.01)
; ..........................................................................
; COMMENT
V2.04 Use mouse driver software reset function to initiation mouse
2/17/1993 by Mr. Lei and Mr. Feng
V2.05 RI cannot work in Windows DOS prompt
3/9/1993 by Mr. Lei
V2.06 1. When XMS cannot allocate 1K memory, RI halts.
2. RI repeat deallocates EMS memory.
V2.07 HotKey Setup Error
4/25/1993 by Mr. Lei
V2.08 KB Buffer
V2.10 1. Release high memory blocks (EMM386 QEMM386 S-ICE 386MAX)
2. RI copies flag
V2.12 1. Exists a critical error in Init 8259 procedure
2. Save [40:F0--FF] user data area

;----------------------------------------------------------
; Assembly program starts here

dosseg
.model tiny
.code
locals @@
org 100h

Start: jmp Main
org 103h

True equ 1
False equ 0
MaxHandles equ 100h

INT3 macro
    out 0ffh,al
endm
;
; HotKey Status Test Var
; ---------------
; 7 6 5 4 3 2 1 0 417 418 496
; . . x . x . . . Left Alt is pressed 8 2
; x . . . x . . . Right Alt is pressed 8 8
; . . . x . x . . Left Ctrl is pressed 4 1
; . x . . . x . . Right Ctrl is pressed 4 4
; . . . . . . x . Left Shift is pressed 2
; . . . . . . . x Right Shift is pressed 1
;
LeftAlt equ 00101000b
RightAlt equ 10001000b
LeftCtrl equ 00010100b
RightCtrl equ 01000100b
LeftShift equ 00000010b
RightShift equ 00000001b
HotKey db LeftCtrl or RightCtrl

DataBegin dw 0
NextDataSeg dw 0fffh
oldInt2F_addr dw 0, 0
XMS_control dw 0, 0
Handle_begin dw 0
cvtOfs dw 0 ; DOS 3.0 = 0 and above DOS 4.0 is 1
org 104h
db 0dh

ds ... (remaining code continues as in the original listing) ...

Key Functional Areas

The program begins by defining constants for hot‑key bits, setting up a tiny .COM model, and establishing entry points. It installs custom interrupt handlers for INT 09h (keyboard), INT 1Ch (timer), and INT 2Fh (DOS multiplex). The hot‑key handling routine checks the state of Ctrl, Alt, and Shift keys, supports an auxiliary hot‑key (default "X"), and triggers actions such as removing other TSRs, restoring the original interrupt vectors, or toggling a busy flag.

Memory‑related routines include Init8259 for initializing the 8259 PIC, RemoveTSR for cleaning up the TSR’s own memory, and a series of Restore* procedures that restore the DOS environment, BIOS data, MCB chain, floppy parameters, XMS/EMS status, and device driver chains. The code also contains helper functions for beeping, clearing the keyboard buffer, and updating the CMOS clock.

Command‑line parsing allows options such as /CLS (remove all TSRs after the current one), /RET (remove all TSRs including the current one), /NEW (install a new copy), /ALL (remove all copies), and hot‑key definition via /S. The parser normalizes input, validates the hot‑key, and sets up the appropriate flags.

At the end of the program the TSR installs its own interrupt vectors, saves the original vectors, and jumps to the resident code. The source concludes with a comment block marking the end of the file.

Conclusion

This historical DOS TSR demonstrates low‑level system programming techniques from the early 1990s, including direct port I/O, interrupt vector manipulation, and memory management using both conventional DOS structures and extended memory services (XMS/EMS). It serves as a valuable reference for enthusiasts studying legacy software, retro‑computing, or the evolution of system utilities.

System ProgrammingAssemblyLegacy CodeDOSretro computingTSR
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.