From 582645e269ee82d544ab8b8b913c8364f3178484 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 25 Jan 2009 17:23:32 -0800 Subject: [PATCH] Reorganize the codepage handling to allow ucs2 -> codepage conversion Reorganize the codepage handling to make it easier to do ucs2 -> codepage conversion, this will be used for a future directory lister. --- codepage/cptable.pl | 5 ++++- core/ldlinux.asm | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/codepage/cptable.pl b/codepage/cptable.pl index c7e2002..05cfc3e 100755 --- a/codepage/cptable.pl +++ b/codepage/cptable.pl @@ -118,6 +118,7 @@ for ($i = 0; $i < 256; $i++) { # Unicode (longname) matching table. # This only depends on the console codepage. # +$pp0 = ''; $pp1 = ''; for ($i = 0; $i < 256; $i++) { if (!defined($ytab[$i])) { $p0 = $p1 = 0xffff; @@ -136,8 +137,10 @@ for ($i = 0; $i < 256; $i++) { # Only the BMP is supported... $p0 = 0xffff if ($p0 > 0xffff); $p1 = 0xffff if ($p1 > 0xffff); - print CPOUT pack("vv", $p0, $p1); + $pp0 .= pack("v", $p0); + $pp1 .= pack("v", $p1); } +print CPOUT $pp0, $pp1; close (CPOUT); diff --git a/core/ldlinux.asm b/core/ldlinux.asm index c7f6577..e9d0573 100644 --- a/core/ldlinux.asm +++ b/core/ldlinux.asm @@ -100,7 +100,8 @@ file_left resd 1 ; Number of sectors left .magic resd 2 ; 8-byte magic number .reserved resd 6 ; Reserved for future use .uppercase resb 256 ; Internal upper-case table -.unicode resw 2*256 ; Unicode matching table +.unicode resw 256 ; Unicode matching table +.unicode_alt resw 256 ; Alternate Unicode matching table endstruc %ifndef DEPEND @@ -1040,10 +1041,10 @@ search_dos_dir: cmp bx,[NameLen] jae .vfat_tail movzx bx,byte [bx+di] - shl bx,2 + add bx,bx cmp ax,[cp_unicode+bx] ; Primary case je .ucs_ok - cmp ax,[cp_unicode+bx+2] ; Alternate case + cmp ax,[cp_unicode_alt+bx] ; Alternate case je .ucs_ok ; Mismatch... jmp .not_us_pop @@ -1170,8 +1171,29 @@ codepage equ $-(32+32) codepage_data: incbin "codepage.cp",32+32 cp_uppercase equ codepage+cp.uppercase cp_unicode equ codepage+cp.unicode +cp_unicode_alt equ codepage+cp.unicode_alt codepage_end equ $ + section .text +; +; Input: UCS-2 character in AX +; Output: Single byte character in AL, ZF = 1 +; On failure, returns ZF = 0 +; +; Assumes CS == ES == 0. +; +ucs2_to_cp: + push di + push cx + mov di,cp_unicode + mov cx,512 + repne scasw + xchg ax,cx + pop cx + pop di + not ax ; Doesn't change the flags! + ret + section .bss VFATInit resb 1 VFATNext resb 1 -- 2.7.4