MS-DOS 6.22 NLSFUNC and CHCP Translation Tables
This article examines how MS-DOS 6.22 processes character translation
tables through the coordinated actions of the NLSFUNC
driver and the CHCP command. It details how the operating
system accesses COUNTRY.SYS, parses localized translation
structures, updates internal DOS kernel pointers via interrupt services,
and coordinates with device drivers to apply system-wide character
mappings.
Core Architectural Components
National Language Support (NLS) in MS-DOS 6.22 relies on three primary components to manage character sets and translation:
COUNTRY.SYS: A binary resource file containing Country Information blocks, code page identifiers, collating tables, uppercase (monocase) translation tables, and Double-Byte Character Set (DBCS) vectors.NLSFUNC.EXE: A terminate-and-stay-resident (TSR) utility that acts as an intermediary between DOS andCOUNTRY.SYS. It hooks the Multiplex Interrupt (INT 2Fh) to provide extended NLS services that are not resident in the default DOS kernel.CHCP(Change Code Page): The user-facing command that requests a global switch of the active hardware and software code pages.
Initialization via NLSFUNC
The MS-DOS kernel maintains a default Country Information table
configured during boot via the COUNTRY= directive in
CONFIG.SYS. However, the base kernel cannot parse arbitrary
code pages dynamically from disk without external assistance.
When executed, NLSFUNC hooks INT 2Fh using
multiplex identifier 14h. It stores the path to
COUNTRY.SYS (specified either in CONFIG.SYS or
as a command-line argument) in memory. When resident,
NLSFUNC intercepts the internal DOS code page switching
calls, enabling the system to read and load alternative character
translation tables on demand.
The CHCP Execution Flow
When a user executes CHCP <code_page>, the system
initiates a synchronized chain of system interrupts:
- Global Code Page Request:
CHCPinvokes DOS Interrupt21h, Service6602h(Set Global Code Page), passing the requested code page ID in theBXregister. - Hardware Notification: The DOS kernel broadcasts
the request to registered character devices (such as
CONmanaged byDISPLAY.SYSandPRNmanaged byPRINTER.SYS) using Generic IOCTL requests (INT 21h, Function440Ch, Category03h, Code4Ah- Select Code Page). This prompts the display adapter and printer to switch their active font tables. - Internal Multiplex Call: The kernel issues
INT 2Fh, Function1404h(Change Code Page) to communicate withNLSFUNC.
Table Parsing and Extraction from COUNTRY.SYS
Upon intercepting INT 2Fh, AX=1404h,
NLSFUNC performs the file-level retrieval:
- Header Lookup:
NLSFUNCopensCOUNTRY.SYSand traverses its file header, which consists of records pairing country codes and code page IDs with file offsets. - Component Table Extraction: It locates the specific
entry matching the target code page and extracts three essential
character mapping tables:
- Uppercase Table: A 130-byte structure. The first
two bytes define the table length (usually 128 bytes), followed by the
uppercase mappings for ASCII values
80hthroughFFh. - Lowercase-to-Uppercase Filename Table: A dedicated mapping table that maps invalid and valid characters for FAT directory entries.
- Collating Sequence Table: A 256-byte array that
defines the relative sort values for all ASCII characters from
00htoFFh, used by commands likeSORT.EXE. - DBCS Vector: A table of boundary byte ranges used to identify multi-byte characters in Asian language editions.
- Uppercase Table: A 130-byte structure. The first
two bytes define the table length (usually 128 bytes), followed by the
uppercase mappings for ASCII values
Memory Commitment and Kernel Pointer Updates
Once the tables are read from disk:
- Buffer Allocation:
NLSFUNCplaces the unpacked translation data into its own resident memory buffers or into designated system memory buffers managed by the DOS operating system. - DOS Internal Pointer Reassignment:
NLSFUNCinterfaces with the DOS kernel to overwrite the active translation table pointers. It updates the internal DOS Country Information structure (accessible to applications viaINT 21h, Function65h- Get Extended Country Information). - Validation: If the code page is successfully applied to both the DOS kernel tables and the device drivers, the global code page variable stored in the DOS data segment is updated to reflect the new ID.
Runtime Character Translation
After CHCP and NLSFUNC complete the update,
character processing changes globally across all applications relying on
DOS system calls:
- File System Operations: When a file is created or
accessed, DOS converts lowercase characters to uppercase for the 8.3
filename entry. The kernel retrieves the character byte, checks if it
falls within the extended ASCII range (
>= 80h), subtracts80hto find the array offset, and extracts the replacement character from the active uppercase table. - String Comparison and Case Conversion: Software
using
INT 21h, Function6521h(Capitalize Character) or6522h(Capitalize String) executes against the newly registered uppercase table, ensuring that language-specific accented characters are converted accurately according to the active code page.