delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2009/05/05/13:46:51

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Rugxulo <rugxulo AT gmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: query con codepage
Date: Tue, 5 May 2009 10:31:33 -0700 (PDT)
Organization: http://groups.google.com
Lines: 93
Message-ID: <bd2808e9-d4cb-4ae2-9bf5-5e7fa5ccc139@o20g2000vbh.googlegroups.com>
NNTP-Posting-Host: 65.13.115.246
Mime-Version: 1.0
X-Trace: posting.google.com 1241544693 23646 127.0.0.1 (5 May 2009 17:31:33 GMT)
X-Complaints-To: groups-abuse AT google DOT com
NNTP-Posting-Date: Tue, 5 May 2009 17:31:33 +0000 (UTC)
Complaints-To: groups-abuse AT google DOT com
Injection-Info: o20g2000vbh.googlegroups.com; posting-host=65.13.115.246;
posting-account=p5rsXQoAAAB8KPnVlgg9E_vlm2dvVhfO
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10)
Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Just in case anyone finds this useful, I'm posting it here. It
basically tells you what codepage is currently prepared / selected /
displayed for the CON device.


#include <dpmi.h>
#include <go32.h>
#include <stdio.h>

//
----------------------------------------------------------------------
// Tuesday, May 5, 2009   12:25pm
// rugxulo _AT_ gmail _DOT_ com
//
// This file is (obviously?) not copyrighted, "nenies propra=83o" !!
//
// Tested successfully on DR-DOS 7.03, FreeDOS 1.0++, and MS-DOS 6.22.
// (Doesn't work on XP or Vista, though.)
//
----------------------------------------------------------------------
//
// short query_con_codepage();
//
// gets currently selected display CON codepage
//
// int 21h, 6601h ("chcp") needs NLSFUNC.EXE + COUNTRY.SYS, but many
//    obscure codepages (e.g. FD's cp853 from EGA.CPX (CPIX.ZIP) or
//    Kosta Kostis' cp913 from ISOLATIN.CPI (ISOCP101.ZIP) have no
//    relevant data inside COUNTRY.SYS.
//
// int 21h, 440Ch 6Ah only works in MS-DOS and DR-DOS (not FreeDOS)
because
//    FreeDOS DISPLAY is an .EXE TSR, not a device driver, and hence
doesn't
//    fully support IOCTL, so they use the undocumented int 2Fh,
0AD02h
//    (which doesn't work in DR-DOS!). But DR-DOS' DISPLAY doesn't
respond
//    to the typical install check i.d. anyways. FreeDOS currently
only
//    supports COUNTRY.SYS in their "unstable" kernel 2037, but at
least
//    their KEYB, "=A2oje", supports cp853 too (thanks, Henrique!).
//
// P.S. For MS or DR: ren ega.cpx *.com ; upx -d ega.com ; ren ega.com
*.cpi
//
----------------------------------------------------------------------

short query_con_codepage() {
   __dpmi_regs regs;

   short param_block[2] =3D { 0, 437 };

   regs.d.eax =3D 0x440C;                // GENERIC IO FOR HANDLES
   regs.d.ebx =3D 1;                     // STDOUT
   regs.d.ecx =3D 0x036A;                // 3 =3D CON, 0x6A =3D QUERY
SELECTED CP
   regs.x.ds =3D __tb >> 4;              // using transfer buffer for
low mem.
   regs.x.dx =3D __tb & 0x0F;            // (suggested by DJGPP FAQ, hi
Eli!)
   regs.x.flags |=3D 1;                  // preset carry for potential
failure
   __dpmi_int (0x21, &regs);

   if (!(regs.x.flags & 1))            // if succeed (carry flag
set) ...
     dosmemget( __tb, 4, param_block);
   else {                              // (undocumented method)
     regs.x.ax =3D 0xAD02;               // 440C -> MS-DOS or DR-DOS
only
     regs.x.bx =3D 0xFFFE;               // AD02 -> MS-DOS or FreeDOS
only
     regs.x.flags |=3D 1;
     __dpmi_int(0x2F, &regs);

     if ((!(regs.x.flags & 1)) && (regs.x.bx < 0xFFFE))
       param_block[1] =3D regs.x.bx;
   }

   return param_block[1];
}

#ifdef TEST
int main() {
  printf("\nCP%u\n",query_con_codepage() );  // same as "mode con cp /
sta"
  return 0;
}
#endif

// EOF

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019