Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

query con codepage

11 views
Skip to first unread message

Rugxulo

unread,
May 5, 2009, 1:31:33 PM5/5/09
to
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ƒo" !!
//
// 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, "¢oje", 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] = { 0, 437 };

regs.d.eax = 0x440C; // GENERIC IO FOR HANDLES
regs.d.ebx = 1; // STDOUT
regs.d.ecx = 0x036A; // 3 = CON, 0x6A = QUERY
SELECTED CP
regs.x.ds = __tb >> 4; // using transfer buffer for
low mem.
regs.x.dx = __tb & 0x0F; // (suggested by DJGPP FAQ, hi
Eli!)
regs.x.flags |= 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 = 0xAD02; // 440C -> MS-DOS or DR-DOS
only
regs.x.bx = 0xFFFE; // AD02 -> MS-DOS or FreeDOS
only
regs.x.flags |= 1;
__dpmi_int(0x2F, &regs);

if ((!(regs.x.flags & 1)) && (regs.x.bx < 0xFFFE))
param_block[1] = 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

Rugxulo

unread,
May 5, 2009, 2:41:49 PM5/5/09
to
Hi, self!

On May 5, 12:31 pm, Rugxulo <rugx...@gmail.com> wrote:
>
>    if (!(regs.x.flags & 1))            // if succeed (carry flag set) ...

That should say "(carry flag not set)" since obviously carry means
error.

BTW, sorry about the bad formatting, blame Google Groups, not me!

0 new messages