Watt-32 tcp/ip  2.2 dev-rel.10
country.c
Go to the documentation of this file.
1 
6 /*
7  * Copyright (c) 1997-2002 Gisle Vanem <gvanem@yahoo.no>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  * must display the following acknowledgement:
19  * This product includes software developed by Gisle Vanem
20  * Bergen, Norway.
21  *
22  * THIS SOFTWARE IS PROVIDED BY ME (Gisle Vanem) AND CONTRIBUTORS ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL I OR CONTRIBUTORS BE LIABLE FOR ANY
26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *
34  * These funtions are meant to:
35  * 1) automatic detection and selection of language for the _LANG()
36  * function. But not yet.
37  * 2) obtaining the active codepage for IDNA/ACE conversion stuff.
38  */
39 
40 #include <stdio.h>
41 #include <stdlib.h>
42 
43 #include "wattcp.h"
44 #include "wdpmi.h"
45 #include "x32vm.h"
46 #include "powerpak.h"
47 #include "misc.h"
48 
49 #if defined(__MSDOS__)
50 
51 static char country_info[35]; /* not used yet */
52 
53 int GetCountryCode (void)
54 {
55  IREGS reg;
56 
57  if (_watt_os_ver < 0x300)
58  return (0);
59 
60  memset (&reg, 0, sizeof(reg));
61  reg.r_ax = 0x3800;
62 
63 #if (DOSX & DJGPP)
64  if (_go32_info_block.size_of_transfer_buffer < sizeof(country_info))
65  return (0);
66  reg.r_ds = __tb / 16;
67  reg.r_dx = __tb & 15;
68 
69 #elif (DOSX & (PHARLAP|X32VM|POWERPAK))
70  if (_watt_dosTbSize < sizeof(country_info))
71  return (0);
72  reg.r_ds = RP_SEG (_watt_dosTbr);
73  reg.r_dx = RP_OFF (_watt_dosTbr);
74 
75 #elif (DOSX & DOS4GW)
76  if (_watt_dosTbSize < sizeof(country_info))
77  return (0);
78  reg.r_ds = _watt_dosTbSeg;
79  reg.r_dx = 0;
80 
81 #elif (DOSX == 0)
82  reg.r_ds = FP_SEG (country_info);
83  reg.r_dx = FP_OFF (country_info);
84 
85 #else
86  #error Unexpected target!
87 #endif
88 
89  GEN_INTERRUPT (0x21, &reg);
90  if (reg.r_flags & 1)
91  return (0);
92 
93  memset (&country_info, 0, sizeof(country_info));
94 
95 #if (DOSX & DJGPP)
96  dosmemget (__tb, sizeof(country_info), &country_info);
97 
98 #elif (DOSX & (PHARLAP|X32VM|POWERPAK))
99  ReadRealMem (&country_info, _watt_dosTbr, sizeof(country_info));
100 
101 #elif (DOSX & DOS4GW)
102  memcpy (&country_info, SEG_OFS_TO_LIN(_watt_dosTbSeg,0), sizeof(country_info));
103 #endif
104 
105  return (WORD)reg.r_bx;
106 }
107 
108 /*
109  * Return active codepage
110  */
111 int GetCodePage (void)
112 {
113  IREGS reg;
114 
115  if (_watt_os_ver < 0x303)
116  return (0);
117 
118  memset (&reg, 0, sizeof(reg));
119  reg.r_ax = 0x6601;
120  GEN_INTERRUPT (0x21, &reg);
121  if (reg.r_flags & CARRY_BIT)
122  return (0);
123  return (WORD)reg.r_bx;
124 }
125 #endif /* __MSDOS__ */
126 
WORD _watt_os_ver
Definition: misc.c:61
Core definitions.
Definition: misc.h:511