Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
5.5 KiB

  1. DOSSEG
  2. .MODEL LARGE
  3. .CODE
  4. ConDevName db 'CON',0
  5. .286
  6. ;++
  7. ;
  8. ; unsigned
  9. ; _far
  10. ; GetGlobalCodepage(
  11. ; VOID
  12. ; );
  13. ;
  14. ; Routine Description:
  15. ;
  16. ; Fetch the active global codepage
  17. ;
  18. ; Arguments:
  19. ;
  20. ; None.
  21. ;
  22. ; Return Value:
  23. ;
  24. ; 0 - error
  25. ; non-0 - codepage
  26. ;
  27. ;--
  28. public _GetGlobalCodepage
  29. _GetGlobalCodepage proc far
  30. push bp
  31. mov bp,sp
  32. push ds
  33. push es
  34. push bx
  35. push si
  36. push di
  37. mov ax,6601h
  38. int 21h
  39. mov ax,0 ; don't clobber carry
  40. jc ggexit
  41. mov ax,bx
  42. ggexit:
  43. pop di
  44. pop si
  45. pop bx
  46. pop es
  47. pop ds
  48. leave
  49. retf
  50. _GetGlobalCodepage endp
  51. ;++
  52. ;
  53. ; unsigned
  54. ; _far
  55. ; GetScreenCodepage(
  56. ; VOID
  57. ; );
  58. ;
  59. ; Routine Description:
  60. ;
  61. ; Fetch the active codepage in use for the screen (device CON).
  62. ;
  63. ; Arguments:
  64. ;
  65. ; None.
  66. ;
  67. ; Return Value:
  68. ;
  69. ; 0 - error
  70. ; non-0 - codepage
  71. ;
  72. ;--
  73. getcp_packet equ byte ptr [bp-30]
  74. getcp_codepage equ word ptr [bp-28]
  75. public _GetScreenCodepage
  76. _GetScreenCodepage proc far
  77. push bp
  78. mov bp,sp
  79. sub sp,30
  80. push ds
  81. push es
  82. push bx
  83. push si
  84. push di
  85. ;
  86. ; Open CON
  87. ;
  88. push cs
  89. pop ds
  90. mov dx,offset CS:ConDevName ; ds:dx -> device name
  91. mov ax,3d02h
  92. int 21h
  93. jnc @f
  94. mov ax,0 ; preserves carry
  95. jmp short gsdone
  96. @@: mov bx,ax ; bx = handle to CON device
  97. push bx ; save handle for later
  98. mov ax,440ch ; generic char device ioctl
  99. mov cx,36ah ; query selected codepage for console
  100. push ss
  101. pop ds
  102. lea dx,getcp_packet ; ds:dx -> return packet
  103. int 21h
  104. mov ax,0 ; assume error
  105. pop bx ; bx = CON device handle
  106. jc gsdone1
  107. mov ax,getcp_codepage ; ax = active codepage for CON device
  108. gsdone1:
  109. push ax ; save return code
  110. mov ah,3eh ; bx set from above
  111. int 21h ; close CON device
  112. pop ax ; restore return code
  113. gsdone:
  114. pop di
  115. pop si
  116. pop bx
  117. pop es
  118. pop ds
  119. leave
  120. retf
  121. _GetScreenCodepage endp
  122. ;++
  123. ;
  124. ; BOOL
  125. ; _far
  126. ; SetGlobalCodepage(
  127. ; IN unsigned Codepage
  128. ; );
  129. ;
  130. ; Routine Description:
  131. ;
  132. ; Set the active global codepage (equivalent to chcp x).
  133. ;
  134. ; Arguments:
  135. ;
  136. ; Codepage - supplies the codepage id
  137. ;
  138. ; Return Value:
  139. ;
  140. ; Boolean value indicating outcome.
  141. ;
  142. ;--
  143. Codepage equ word ptr [bp+6]
  144. public _SetGlobalCodepage
  145. _SetGlobalCodepage proc far
  146. push bp
  147. mov bp,sp
  148. push ds
  149. push es
  150. push bx
  151. push si
  152. push di
  153. mov ax,6602h
  154. mov bx,Codepage
  155. int 21h
  156. mov ax,0 ; don't clobber carry
  157. jc sgexit
  158. inc ax
  159. sgexit:
  160. pop di
  161. pop si
  162. pop bx
  163. pop es
  164. pop ds
  165. leave
  166. retf
  167. _SetGlobalCodepage endp
  168. ;++
  169. ;
  170. ; BOOL
  171. ; _far
  172. ; SetScreenCodepage(
  173. ; IN unsigned Codepage
  174. ; );
  175. ;
  176. ; Routine Description:
  177. ;
  178. ; Set the active codepage for the screen (equivalent to
  179. ; mode con cp select=x).
  180. ;
  181. ; Arguments:
  182. ;
  183. ; Codepage - supplies the codepage id
  184. ;
  185. ; Return Value:
  186. ;
  187. ; Boolean value indicating outcome.
  188. ;
  189. ;--
  190. Codepage equ word ptr [bp+6]
  191. setcp_packet equ word ptr [bp-4]
  192. setcp_codepage equ word ptr [bp-2]
  193. public _SetScreenCodepage
  194. _SetScreenCodepage proc far
  195. push bp
  196. mov bp,sp
  197. sub sp,4
  198. push ds
  199. push es
  200. push bx
  201. push si
  202. push di
  203. ;
  204. ; Open CON
  205. ;
  206. push cs
  207. pop ds
  208. mov dx,offset CS:ConDevName ; ds:dx -> device name
  209. mov ax,3d02h
  210. int 21h
  211. jnc @f
  212. mov ax,0 ; preserves carry
  213. jmp short ssdone
  214. @@: mov bx,ax ; bx = handle to CON device
  215. push bx ; save handle for later
  216. mov cx,34ah ; set selected codepage for console
  217. push ss
  218. pop ds
  219. lea dx,setcp_packet ; ds:dx -> param packet
  220. mov ax,Codepage
  221. mov setcp_codepage,ax
  222. mov setcp_packet,2
  223. mov ax,440ch ; generic char device ioctl
  224. int 21h
  225. mov ax,0 ; assume error, ax = FALSE
  226. pop bx ; bx = CON device handle
  227. jc ssdone1
  228. inc ax ; ax = TRUE;
  229. ssdone1:
  230. push ax ; save return code
  231. mov ah,3eh ; bx set from above
  232. int 21h ; close CON device
  233. pop ax ; restore return code
  234. ssdone:
  235. pop di
  236. pop si
  237. pop bx
  238. pop es
  239. pop ds
  240. leave
  241. retf
  242. _SetScreenCodepage endp
  243. end