Leaked source code of windows server 2003
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.

908 lines
23 KiB

  1. PAGE ,132
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; (C) Copyright Microsoft Corp. 1987-1990
  5. ; MS-DOS 5.00 - NLS Support - KEYB Command
  6. ;
  7. ; File Name: KEYBTBBL.ASM
  8. ; ----------
  9. ;
  10. ; Description:
  11. ; ------------
  12. ; Build SHARED_DATA_AREA with parameters specified
  13. ; in KEYBCMD.ASM
  14. ;
  15. ; Documentation Reference:
  16. ; ------------------------
  17. ; None
  18. ;
  19. ; Procedures Contained in This File:
  20. ; ----------------------------------
  21. ; TABLE_BUILD: Build the header sections of the SHARED_DATA_AREA
  22. ; STATE_BUILD: Build the state sections in the table area
  23. ; FIND_CP_TABLE: Given the language and code page parm, determine the
  24. ; offset of the code page table in KEYBOARD.SYS
  25. ;
  26. ; Include Files Required:
  27. ; -----------------------
  28. ; KEYBSHAR.INC
  29. ; KEYBSYS.INC
  30. ; KEYBDCL.INC
  31. ; KEYBI2F.INC
  32. ;
  33. ; External Procedure References:
  34. ; ------------------------------
  35. ; None
  36. ;
  37. ; Change History:
  38. ; ---------------
  39. ;
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  41. PUBLIC TABLE_BUILD
  42. PUBLIC FIND_CP_TABLE
  43. PUBLIC CPN_INVALID
  44. PUBLIC SD_LENGTH
  45. CODE SEGMENT PUBLIC 'CODE'
  46. INCLUDE KEYBEQU.INC
  47. INCLUDE KEYBSHAR.INC
  48. INCLUDE KEYBSYS.INC
  49. INCLUDE KEYBCMD.INC
  50. INCLUDE KEYBDCL.INC
  51. INCLUDE COMMSUBS.INC
  52. INCLUDE KEYBCPSD.INC
  53. ASSUME cs:CODE,ds:CODE
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;
  56. ; Module: TABLE_BUILD
  57. ;
  58. ; Description:
  59. ; Create the table area within the shared data structure. Each
  60. ; table is made up of a descriptor plus the state sections.
  61. ; Translate tables are found in the Keyboard definition file and are
  62. ; copied into the shared data area by means of the STATE_BUILD
  63. ; routine.
  64. ;
  65. ; Input Registers:
  66. ; ds - points to our data segment
  67. ; es - points to our data segment
  68. ; bp - points at beginning of CMD_PARM_LIST
  69. ;
  70. ; SHARED_DATA_STR must be allocated in memory
  71. ;
  72. ; The following variables must also be passed from KEYB_COMMAND
  73. ; KEYBSYS_FILE_HANDLE is set to file handle after opening file
  74. ; CP_TAB_OFFSET is the offset of the CP table in the SHARED_DATA_AREA
  75. ; STATE_LOGIC_OFFSET is the offset of the state section in the SHARED_DATA_AREA
  76. ; SYS_CODE_PAGE is the binary representation of the system CP
  77. ; KEYBCMD_LANG_ENTRY_PTR is a pointer to the lang entry in KEY DEF file
  78. ; DESIG_CP_BUFFER is the buffer which holds a list of designated CPs
  79. ; DESIG_CP_OFFSET:WORD is the offset of that list
  80. ; NUM_DESIG_CP is the number of CPs designated
  81. ; FILE_BUFFER is the buffer to read in the KEY DEF file
  82. ;**********CNS ***************************************
  83. ; ID_PTR_SIZE is the size of the ID ptr structure
  84. ;**********CNS ***************************************
  85. ; LANG_PTR_SIZE is the size of the lang ptr structure
  86. ; CP_PTR_SIZE is the size of the CP ptr structure
  87. ; NUM_CP is the number of CPs in the KEYB DEF file for that lang
  88. ; SHARED_AREA_PTR segment and offset of the SHARED_DATA_AREA
  89. ;
  90. ;
  91. ; Output Registers:
  92. ; cx - RETURN_CODE := 0 - Table build successful
  93. ; 1 - Table build unsuccessful - ERROR 1
  94. ; (Invalid language parm)
  95. ; 2 - Table build unsuccessful - ERROR 2
  96. ; (Invalid Code Page parm)
  97. ; 3 - Table build unsuccessful - ERROR 3
  98. ; (Machine type unavaliable)
  99. ; 4 - Table build unsuccessful - ERROR 4
  100. ; (Bad or missing keyboard def file)
  101. ; 5 - Table build unsuccessful - ERROR 5
  102. ; (Memory overflow occurred)
  103. ; Logic:
  104. ; Calculate Offset difference between TEMP and SHARED_DATA_AREAs
  105. ; Get LANGUAGE_PARM and CODE_PAGE_PARM from parm list
  106. ; Call FIND_CP_TABLE := Determine whether CP is valid for given language
  107. ; IF CP is valid THEN
  108. ; Store them in the SHARED_DATA_AREA
  109. ; Prepare to read Keyboard definition file by LSEEKing to the top
  110. ; READ the header
  111. ; Store maximum table values for calculation of RES_END
  112. ; Set di to point at TABLE_AREA within SHARED_DATA_AREA
  113. ; FOR the state logic section of the specified language:
  114. ; IF STATE_LOGIC_PTR is not -1 THEN
  115. ; LSEEK to state logic section in keyboard definition file
  116. ; READ the state logic section into the TABLE_AREA
  117. ; Set the hot keyb scan codes
  118. ; Set the LOGIC_PTR in the header
  119. ; FOR the common translate section:
  120. ; IF Length parameter is not 0 THEN
  121. ; Build state
  122. ; Set the COMMON_XLAT_PTR in the header
  123. ; FOR the specific translate sections:
  124. ; Establish addressibility to list of designated code pages
  125. ; FOR each code page
  126. ; IF CP_ENTRY_PTR is not -1 THEN
  127. ; Determine offset of CP table in Keyb Def file
  128. ; IF CP table not avaliable THEN
  129. ; Set CPN_INVALID flag
  130. ; ELSE
  131. ; LSEEK to CPn state section in keyboard definition file
  132. ; IF this is the invoked code page THEN
  133. ; Set ACTIVE_XLAT_PTR in SHARED_DATA_AREA
  134. ; Update RESIDENT_END ptr
  135. ; Build state
  136. ; Update RESIDENT_END ptr
  137. ; End
  138. ;
  139. ;
  140. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  141. FB EQU FILE_BUFFER
  142. KB_MASK EQU 02H
  143. FIRST_XLAT_TAB DW 0
  144. NEXT_SECT_PTR DW -1
  145. MAX_COM_SIZE DW ?
  146. MAX_SPEC_SIZE DW ?
  147. MAX_LOGIC_SIZE DW ?
  148. RESIDENT_END_ACC DW 0
  149. SA_HEADER_SIZE DW SIZE SHARED_DATA_STR;
  150. PARM_LIST_OFFSET DW ?
  151. ;********************CNS*************************
  152. TB_ID_PARM DW 0
  153. ;********************CNS*************************
  154. TB_LANGUAGE_PARM DW 0
  155. TB_CODE_PAGE_PARM DW 0
  156. CPN_INVALID DW 0
  157. KEYB_INSTALLED DW 0
  158. SD_AREA_DIFFERENCE DW 0
  159. SD_LENGTH DW 2000
  160. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  161. ; Program Code
  162. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  163. TABLE_BUILD PROC NEAR
  164. mov ax,OFFSET SD_SOURCE_PTR ; Setup the difference
  165. sub ax,OFFSET SD_DesT_PTR ; value used to calculate
  166. mov SD_AREA_DIFFERENCE,ax ; new ptr values for
  167. ; SHARED_DATA_AREA
  168. mov ax,[bp].ID_PARM ; Get id parameter
  169. mov TB_ID_PARM,ax
  170. mov ax,[bp].LANGUAGE_PARM ; Get language parameter
  171. mov TB_LANGUAGE_PARM,ax
  172. mov bx,[bp].CODE_PAGE_PARM ; Get code page parameter
  173. mov TB_CODE_PAGE_PARM,bx
  174. ; Make sure code page is
  175. call FIND_CP_TABLE ; valid for the language
  176. jcxz TB_CHECK_CONTINUE1 ; IF code page is found
  177. jmp TB_ERROR6 ; for language THEN
  178. TB_CHECK_CONTINUE1:
  179. mov bp,OFFSET SD_SOURCE_PTR ; Put language parm and
  180. mov ax,TB_ID_PARM ; id parm and..
  181. mov es:[bp].INVOKED_KBD_ID,ax
  182. mov bx,TB_CODE_PAGE_PARM
  183. mov es:[bp].INVOKED_CP_TABLE,bx ; code page parm into the
  184. mov ax,TB_LANGUAGE_PARM ; SHARED_DATA_AREA
  185. mov word ptr es:[bp].ACTIVE_LANGUAGE,ax
  186. mov bx,KEYBSYS_FILE_HANDLE ; Get handle
  187. xor dx,dx ; LSEEK file pointer
  188. xor cx,cx ; back to top of file
  189. mov ax,4200h ; If no problem with
  190. int 21H ; Keyboard Def file THEN
  191. jnc TB_START
  192. jmp TB_ERROR4
  193. TB_START: ; Else
  194. xor di,di ; Set number
  195. lea cx,[di].KH_NUM_ID+2 ; M006 -- read a few extra entries
  196. mov dx,OFFSET FILE_BUFFER ; Move contents into file buffer
  197. mov ah,3FH ; READ
  198. push cs
  199. pop ds
  200. int 21H ; File
  201. jnc TB_CONTINUE1
  202. jmp TB_ERROR4
  203. TB_CONTINUE1:
  204. cmp cx,ax
  205. je TB_ERROR_CHECK1
  206. ifndef JAPAN
  207. mov cx,4
  208. jmp TB_CPN_INVALID
  209. else ; JAPAN
  210. tb_err4_j: ; M006
  211. jmp TB_ERROR4 ; M002
  212. endif ; JAPAN
  213. TB_ERROR_CHECK1:
  214. ifdef JAPAN
  215. cmp FB.KH_NUM_ID,0 ; M006 -- is it an old KEYBOARD.SYS?
  216. jz tb_err4_j ; M006 -- bomb out if so
  217. endif ; JAPAN
  218. mov cx,FB.KH_MAX_COM_SZ ; Save values for RESIDENT_END
  219. mov MAX_COM_SIZE,cx ; calculation
  220. mov cx,FB.KH_MAX_SPEC_SZ
  221. mov MAX_SPEC_SIZE,cx
  222. mov cx,FB.KH_MAX_LOGIC_SZ
  223. mov MAX_LOGIC_SIZE,cx
  224. LEA di,[bp].TABLE_AREA ; Point at beginning of table area
  225. ; di ---> TABLE_AREA
  226. ifdef JAPAN
  227. ; M002 -- begin added section
  228. ;
  229. ; Before we go ANY further, let's see if we actually have room
  230. ; for our worst case memory allocation needs. Notice that
  231. ; we're actually trusting the MAX fields from the KEYBOARD
  232. ; definition file. If it lies to us and has fields bigger
  233. ; than these MAX values, we may crash over memory we don't
  234. ; own during initialization.
  235. mov ax,NUM_DESIG_CP
  236. mul MAX_SPEC_SIZE
  237. or dx,dx ; error if overflowed 16 bits
  238. jnz mem_alloc_err
  239. add ax,SA_HEADER_SIZE
  240. jc mem_alloc_err
  241. add ax,MAX_LOGIC_SIZE
  242. jc mem_alloc_err
  243. add ax,MAX_COM_SIZE
  244. jc mem_alloc_err
  245. ; Note that ax could be used for the RESIDENT_END_ACC value,
  246. ; but since this check is being added late in the testing
  247. ; cycle, we'll leave that calculation alone.
  248. add ax,di ; get the ending offset of temp buffer
  249. jc mem_alloc_err
  250. add ax,15
  251. jc mem_alloc_err
  252. mov cl,4 ; convert to paragraph
  253. shr ax,cl
  254. mov cx,ax
  255. mov ax,cs ; get our code segment
  256. add ax,cx ; this is our ending segment
  257. cmp ax,cs:[2] ; compare against psp:2
  258. jb mem_alloc_ok
  259. mem_alloc_err:
  260. jmp TB_ERROR5
  261. mem_alloc_ok:
  262. ; M002 -- end added section
  263. endif ; JAPAN
  264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  265. ; ** FOR STATE LOGIC SECTION FOR LANG **
  266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  267. TB_STATE_BEGIN:
  268. mov bx,KEYBSYS_FILE_HANDLE ; Get handle
  269. mov cx,word ptr STATE_LOGIC_OFFSET+2
  270. mov dx,word ptr STATE_LOGIC_OFFSET ; Get LSEEK file pointer
  271. cmp dx,-1 ; If no language table then
  272. jnz TB_STATE_CONTINUE1 ; jump to code page begin
  273. jmp TB_CP_BEGIN
  274. TB_STATE_CONTINUE1: ; Else
  275. mov ax,4200h ; LSEEK to begin of state logic sect
  276. int 21H ; Keyboard Def file THEN
  277. jnc TB_STATE_CONTINUE2
  278. jmp TB_ERROR4
  279. TB_STATE_CONTINUE2:
  280. mov dx,ax
  281. mov word ptr SB_STATE_OFFSET+2,cx ; Save the offset of the
  282. mov word ptr SB_STATE_OFFSET,dx ; states in Keyb Def file
  283. sub di,SD_AREA_DIFFERENCE ; Adjust for relocation
  284. mov es:[bp].LOGIC_PTR,di ; Set because this is state
  285. add di,SD_AREA_DIFFERENCE ; Adjust for relocation
  286. mov cx,4 ; Set number bytes to read length and
  287. ; special features
  288. mov dx,OFFSET FILE_BUFFER ; Set the buffer address
  289. mov ah,3FH ; Read from the Keyb Def file
  290. int 21H
  291. jnc TB_STATE_CONTINUE3
  292. jmp TB_ERROR4
  293. TB_STATE_CONTINUE3:
  294. cmp cx,ax
  295. je TB_ERROR_CHECK2
  296. ifndef JAPAN
  297. mov cx,4
  298. jmp TB_CPN_INVALID
  299. else ; JAPAN
  300. jmp TB_ERROR4
  301. endif ; JAPAN
  302. TB_ERROR_CHECK2:
  303. mov ax,FB.KT_SPECIAL_FEATURES ; Save the special features in the
  304. mov es:[bp].SPECIAL_FEATURES,ax ; SHARED_DATA_AREA
  305. mov es:[bp].HOT_KEY_ON_SCAN,F1_SCAN
  306. mov es:[bp].HOT_KEY_OFF_SCAN,F2_SCAN
  307. HOT_KEY_SET:
  308. mov cx,FB.KT_LOGIC_LEN ; Set length of section to read
  309. or cx,cx
  310. jnz TB_STATE_CONTINUE4
  311. dec cx ; cx = -1
  312. mov es:[bp].LOGIC_PTR,cx
  313. jmp short SB_COMM_BEGIN
  314. TB_STATE_CONTINUE4:
  315. mov es:[di],cx ; Store length parameter in
  316. add di,2 ; SHARED_DATA_AREA
  317. mov cx,FB.KT_SPECIAL_FEATURES ; Save the special features
  318. mov es:[di],cx
  319. add di,2
  320. mov cx,FB.KT_LOGIC_LEN ; Set length of section to read
  321. sub cx,4 ; Adjust for what we have already read
  322. mov dx,di ; Set the address of SHARED_DATA_AREA
  323. push es
  324. pop ds
  325. mov ah,3FH ; Read logic section from the
  326. int 21H ; Keyb Def file
  327. push cs
  328. pop ds
  329. jnc TB_STATE_CONTINUE5
  330. jmp TB_ERROR4
  331. TB_STATE_CONTINUE5:
  332. cmp cx,ax
  333. je TB_ERROR_CHECK3
  334. ifndef JAPAN
  335. mov cx,4
  336. jmp TB_CPN_INVALID
  337. else ; JAPAN
  338. jmp TB_ERROR4
  339. endif ; JAPAN
  340. TB_ERROR_CHECK3:
  341. add di,cx ; Set di at new beginning of area
  342. ; TABLE_AREA
  343. ; STATE_LOGIC
  344. mov cx,RESIDENT_END_ACC ; di --->
  345. add cx,SA_HEADER_SIZE
  346. add cx,MAX_LOGIC_SIZE
  347. mov RESIDENT_END_ACC,cx ; Refresh Resident end size
  348. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  349. ; ** FOR COMMON TRANSLATE SECTION FOR LANG **
  350. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  351. SB_COMM_BEGIN:
  352. mov cx,SIZE KEYBSYS_XLAT_SECT-1 ; Set number bytes to read header
  353. mov dx,di ; Set the SHARED_DATA_AREA address
  354. push es
  355. pop ds
  356. mov ah,3FH ; Read from the Keyb Def file
  357. int 21H
  358. push cs
  359. pop ds
  360. jnc TB_STATE_CONTINUE6
  361. jmp TB_ERROR4
  362. TB_STATE_CONTINUE6:
  363. mov cx,es:[di].KX_SECTION_LEN; Set length of section to read
  364. jcxz TB_CP_BEGIN
  365. mov cx,word ptr SB_STATE_OFFSET ; Save the offset of the
  366. add cx,FB.KT_LOGIC_LEN
  367. mov word ptr SB_STATE_OFFSET,cx ; Save the offset of the
  368. sub di,SD_AREA_DIFFERENCE ; Adjust for relocation
  369. mov es:[bp].COMMON_XLAT_PTR,di
  370. add di,SD_AREA_DIFFERENCE ; Adjust for relocation
  371. call STATE_BUILD
  372. ; di set at new beginning of area
  373. ; TABLE_AREA
  374. ; STATE_LOGIC
  375. ; COMMON_XLAT_SECTION
  376. mov cx,RESIDENT_END_ACC
  377. add cx,MAX_COM_SIZE
  378. mov RESIDENT_END_ACC,cx ; Refresh resident end size
  379. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  380. ; FOR alL DESIGNATED OR INVOKED CODE PAGES
  381. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  382. TB_CP_BEGIN: ; Get the offset to
  383. mov cx,OFFSET DESIG_CP_BUFFER.DESIG_CP_ENTRY ; the beginning of the
  384. mov DESIG_CP_OFFSET,cx ; table of designated
  385. ; code pages
  386. TB_CPN_BEGIN:
  387. mov ax,word ptr es:[bp].ACTIVE_LANGUAGE ; Get the active language
  388. mov cx,NUM_DESIG_CP ; Get the number of CPs
  389. or cx,cx ; IF we have done all requested CPs
  390. jnz TB_CPN_VALID1
  391. jmp TB_DONE ; Then done
  392. TB_CPN_VALID1:
  393. mov si,[DESIG_CP_OFFSET]
  394. mov bx,[si] ; Get the CP
  395. cmp bx,-1
  396. jnz TB_CPN_CONTINUE1
  397. jmp short TB_CPN_REPEAT
  398. TB_CPN_CONTINUE1: ; ELSE
  399. push di
  400. call FIND_CP_TABLE ; Find offset of code page table
  401. pop di
  402. jcxz TB_CPN_VALID ; brif valid code page for language
  403. mov CPN_INVALID,cx ; Set flag and go to next CP
  404. jmp short TB_CPN_REPEAT ; Else
  405. TB_CPN_VALID:
  406. mov bx,KEYBSYS_FILE_HANDLE ; Get handle
  407. mov cx,word ptr CP_TAB_OFFSET+2 ; Get offset of the code page
  408. mov dx,word ptr CP_TAB_OFFSET ; in the Keyb Def file
  409. cmp dx,-1 ; Test if code page is blank
  410. jnz TB_CPN_CONTINUE2
  411. jmp short TB_CPN_REPEAT ; If it is then go get next CP
  412. TB_CPN_CONTINUE2:
  413. mov ax,4200h ; LSEEK to table in Keyb Def file
  414. int 21H ; Keyb Def file Then
  415. jnc TB_CPN_CONTINUE3
  416. jmp TB_ERROR4
  417. TB_CPN_CONTINUE3:
  418. mov dx,ax
  419. mov word ptr SB_STATE_OFFSET+2,cx ; Save the offset of the
  420. mov word ptr SB_STATE_OFFSET,dx ; states in Keyb Def file
  421. mov cx,TB_CODE_PAGE_PARM ; If this code page is the
  422. mov si,[DESIG_CP_OFFSET] ; invoked code page
  423. cmp cx,[si]
  424. jnz TB_CPN_CONTINUE4 ; Then
  425. sub di,SD_AREA_DIFFERENCE ; Adjust for relocation
  426. mov es:[bp].ACTIVE_XLAT_PTR,di ; Set active xlat section
  427. add di,SD_AREA_DIFFERENCE ; Adjust for relocation
  428. TB_CPN_CONTINUE4:
  429. sub di,SD_AREA_DIFFERENCE ; Adjust for relocation
  430. mov es:[bp].FIRST_XLAT_PTR,di ; Set flag
  431. add di,SD_AREA_DIFFERENCE ; Adjust for relocation
  432. TB_CPN_CONTINUE5:
  433. CALL STATE_BUILD ; Build state
  434. ; TABLE_AREA
  435. jcxz TB_CPN_REPEAT ; COMMON_XLAT_SECTION,SPECIFIC...
  436. jmp TB_ERROR4 ; di --->
  437. TB_CPN_REPEAT:
  438. mov cx,RESIDENT_END_ACC
  439. add cx,MAX_SPEC_SIZE ; Refresh resident end size
  440. mov RESIDENT_END_ACC,cx
  441. mov cx,DESIG_CP_OFFSET
  442. add cx,2 ; Adjust offset to find next code page
  443. mov DESIG_CP_OFFSET,cx
  444. mov cx,NUM_DESIG_CP ; Adjust the number of code pages left
  445. dec cx
  446. mov NUM_DESIG_CP,cx
  447. jmp TB_CPN_BEGIN
  448. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  449. ;
  450. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  451. TB_DONE:
  452. mov cx,RESIDENT_END_ACC ; Set final calculated value
  453. add cx,bp
  454. sub cx,SD_AREA_DIFFERENCE ; Adjust for relocation
  455. mov es,word ptr SHARED_AREA_PTR ; Set segment
  456. mov bp,word ptr SHARED_AREA_PTR+2
  457. cmp cx,es:[bp].RESIDENT_END
  458. JNA TB_DONE_CONTINUE1
  459. jmp short TB_ERROR5
  460. TB_DONE_CONTINUE1:
  461. cmp es:[bp].RESIDENT_END,-1
  462. jnz DONT_REPLACE
  463. push cs
  464. pop es
  465. mov bp,OFFSET SD_SOURCE_PTR
  466. mov es:[bp].RESIDENT_END,cx ; Save resident end
  467. jmp short CONTINUE_2_END
  468. DONT_REPLACE:
  469. push cs
  470. pop es
  471. mov bp,OFFSET SD_SOURCE_PTR
  472. CONTINUE_2_END:
  473. sub cx,OFFSET SD_DesT_PTR ; Calculate # of bytes to copy
  474. mov SD_LENGTH,cx
  475. xor cx,cx ; Set valid completion return code
  476. mov TB_RETURN_CODE,cx
  477. ret
  478. ifndef JAPAN
  479. ; M002 -- dead code deleted. The following label was only
  480. ; branched to with cx==4. Those calls were all
  481. ; replaced with direct JMPs to TB_ERROR4, which was
  482. ; assumed to set cx=4 in other places anyway.
  483. TB_CPN_INVALID:
  484. cmp cx,1 ; Set error 1 return code
  485. jnz TB_ERROR2
  486. mov TB_RETURN_CODE,cx
  487. ret
  488. TB_ERROR2:
  489. cmp cx,2 ; Set error 2 return code
  490. jnz TB_ERROR3
  491. mov TB_RETURN_CODE,cx
  492. ret
  493. TB_ERROR3:
  494. cmp cx,3 ; Set error 3 return code
  495. jnz TB_ERROR4
  496. mov TB_RETURN_CODE,cx
  497. ret
  498. endif ; !JAPAN
  499. TB_ERROR4:
  500. ifndef JAPAN
  501. cmp cx,4 ; Set error 4 return code
  502. jnz TB_ERROR5
  503. else ; JAPAN
  504. mov cx,4 ; M002 ; set error 4 return code
  505. endif ; JAPAN
  506. mov TB_RETURN_CODE,cx
  507. ret
  508. TB_ERROR5:
  509. mov cx,5 ; Set error 5 return code
  510. mov TB_RETURN_CODE,cx
  511. ret
  512. TB_ERROR6:
  513. mov bx,TB_CODE_PAGE_PARM
  514. mov cx,6
  515. mov TB_RETURN_CODE,cx ; Set error 6 return code
  516. ret
  517. TABLE_BUILD ENDP
  518. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  519. ;
  520. ; Module: STATE_BUILD
  521. ;
  522. ; Description:
  523. ; Create the state/xlat section within the specific translate section.
  524. ;
  525. ; Input Registers:
  526. ; ds - points to our data segment
  527. ; es - points to our data segment
  528. ; SB_STATE_OFFSET - offset to the beginning of the info in Keyb Def SYS
  529. ; di - offset of the beginning of the area used to build states
  530. ;
  531. ; KEYBSYS_FILE_HANDLE - handle of the KEYBOARD.SYS file
  532. ;
  533. ; Output Registers:
  534. ; di - offset of the end of the area used by STATE_BUILD
  535. ;
  536. ; cx - Return Code := 0 - State build successful
  537. ; 4 - State build unsuccessful
  538. ; (Bad or missing Keyboard Def file)
  539. ;
  540. ; Logic:
  541. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  542. END_OF_AREA_PTR DW 0
  543. SB_FIRST_STATE DW 0
  544. SB_STATE_LENGTH DW 0
  545. SB_STATE_OFFSET DD 0
  546. STATE_LENGTH DW 0
  547. RESTORE_BP DW ?
  548. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  549. ; Program Code
  550. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  551. STATE_BUILD PROC NEAR
  552. mov si,di ; Get the tally pointer
  553. mov END_OF_AREA_PTR,di ; Save pointer
  554. mov RESTORE_bp,bp ; Save the base pointer
  555. mov bx,KEYBSYS_FILE_HANDLE ; Get handle
  556. mov dx,word ptr SB_STATE_OFFSET ; LSEEK file pointer
  557. mov cx,word ptr SB_STATE_OFFSET+2 ; back to top of XLAT table
  558. mov ax,4200h ; If no problem with
  559. int 21H ; Keyboard Def file THEN
  560. jnc SB_FIRST_HEADER
  561. jmp SB_ERROR4
  562. SB_FIRST_HEADER:
  563. xor bp,bp
  564. LEA cx,[bp].KX_FIRST_STATE ; Set number of bytes to read header
  565. mov dx,di
  566. push es
  567. pop ds
  568. mov ah,3FH ; read in the header
  569. int 21H
  570. push cs
  571. pop ds
  572. jnc SB_HEAD_CONTINUE1
  573. jmp SB_ERROR4
  574. SB_HEAD_CONTINUE1:
  575. mov dx,NEXT_SECT_PTR
  576. cmp dx,-1
  577. je SB_HEAD_CONTINUE2
  578. sub dx,SD_AREA_DIFFERENCE ; Adjust for relocation
  579. SB_HEAD_CONTINUE2:
  580. mov es:[di].XS_NEXT_SECT_PTR,dx
  581. cmp dx,-1
  582. je SB_HEAD_CONTINUE3
  583. add dx,SD_AREA_DIFFERENCE ; Adjust for relocation
  584. SB_HEAD_CONTINUE3:
  585. add di,cx ; Update the di pointer
  586. SB_NEXT_STATE:
  587. xor bp,bp ; Set number
  588. LEA cx,[bp].KX_STATE_ID ; bytes to read state length
  589. mov dx,di ; Read the header into the
  590. mov bx,KEYBSYS_FILE_HANDLE ; SHARED_DATA_AREA
  591. push es
  592. pop ds
  593. mov ah,3FH
  594. int 21H
  595. SB_CONTINUE1:
  596. push cs ; Reset the data segment
  597. pop ds
  598. mov cx,es:[di].KX_STATE_LEN ; If the length of the state section
  599. mov STATE_LENGTH,cx
  600. add di,2 ; is zero then done
  601. jcxz SB_DONE
  602. xor bp,bp ; Set number
  603. LEA cx,[bp].KX_FIRST_XLAT-2 ; bytes to read state length
  604. mov dx,di ; Read the header into the
  605. mov bx,KEYBSYS_FILE_HANDLE ; SHARED_DATA_AREA
  606. push es
  607. pop ds
  608. mov ah,3FH
  609. int 21H
  610. SB_CONTINUE1A:
  611. push cs ; Reset the data segment
  612. pop ds
  613. sub di,2
  614. mov ax,es:[di].XS_KBD_TYPE ; Get the keyboard type def
  615. test ax,HW_TYPE ; Does it match our hardware?
  616. JNZ SB_CONTINUE2
  617. mov dx,es:[di].XS_STATE_LEN ; No, then
  618. LEA cx,[bp].KX_FIRST_XLAT
  619. sub dx,cx
  620. xor cx,cx
  621. mov ah,42H ; LSEEK past this state
  622. mov al,01H
  623. int 21H
  624. jmp SB_NEXT_STATE
  625. SB_CONTINUE2: ; Yes, then
  626. mov ax,SIZE STATE_STR-1
  627. add di,ax ; Set PTR and end of header
  628. SB_XLAT_TAB_BEGIN: ; Begin getting xlat tables
  629. mov bx,KEYBSYS_FILE_HANDLE
  630. LEA dx,[bp].KX_FIRST_XLAT ; Adjust for what we have already read
  631. mov cx,STATE_LENGTH
  632. sub cx,dx
  633. mov dx,di
  634. push es
  635. pop ds
  636. mov ah,3FH ; Read in the xlat tables
  637. int 21H
  638. push cs
  639. pop ds
  640. jnc SB_CONTINUE4
  641. jmp short SB_ERROR4
  642. SB_CONTINUE4:
  643. cmp cx,ax
  644. je SB_ERROR_CHECK1
  645. jmp short SB_ERROR4
  646. SB_ERROR_CHECK1:
  647. add di,cx ; Update the end of area ptr
  648. mov si,di
  649. jmp SB_NEXT_STATE
  650. SB_DONE:
  651. mov ax,-1
  652. mov si,END_OF_AREA_PTR
  653. mov NEXT_SECT_PTR,si
  654. mov bp,RESTORE_bp
  655. ret
  656. SB_ERROR1:
  657. mov cx,1
  658. ret
  659. SB_ERROR2:
  660. mov cx,2
  661. ret
  662. SB_ERROR3:
  663. mov cx,3
  664. ret
  665. SB_ERROR4:
  666. mov cx,4
  667. ret
  668. STATE_BUILD ENDP
  669. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  670. ;
  671. ; Module: FIND_CP_TABLE
  672. ;
  673. ; Description:
  674. ; Determine the offset of the specified code page table in KEYBOARD.SYS
  675. ;
  676. ; Input Registers:
  677. ; ds - points to our data segment
  678. ; es - points to our data segment
  679. ; ax - ASCII representation of the language parm
  680. ; bx - binary representation of the code page
  681. ;
  682. ; KEYBSYS_FILE_HANDLE - handle of the KEYBOARD.SYS file
  683. ;
  684. ; Output Registers:
  685. ; CP_TAB_OFFSET - offset of the CP table in KEYBOARD.SYS
  686. ;
  687. ; cx - Return Code := 0 - State build successful
  688. ; 2 - Invalid Code page for language
  689. ; 4 - Bad or missing Keyboard Def file
  690. ; Logic:
  691. ;
  692. ; READ language table
  693. ; IF error in reading file THEN
  694. ; Display ERROR message and EXIT
  695. ; ELSE
  696. ; Use table to verify language parm
  697. ; Set pointer values
  698. ; IF code page was specified
  699. ; READ language entry
  700. ; IF error in reading file THEN
  701. ; Display ERROR message and EXIT
  702. ; ELSE
  703. ; READ Code page table
  704. ; IF error in reading file THEN
  705. ; Display ERROR message and EXIT
  706. ; ELSE
  707. ; Use table to get the offset of the code page parm
  708. ; ret
  709. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  710. FIND_CP_PARM DW ?
  711. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  712. ; Program Code
  713. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  714. FIND_CP_TABLE PROC NEAR
  715. mov FIND_CP_PARM,bx ; Save Code page
  716. mov bx,KEYBSYS_FILE_HANDLE ; Get handle
  717. mov dx,word ptr KEYBCMD_LANG_ENTRY_PTR ; LSEEK file pointer
  718. mov cx,word ptr KEYBCMD_LANG_ENTRY_PTR+2 ; to top of language entry
  719. mov ax,4200h ; If no problem with
  720. int 21H ; Keyb Def file Then
  721. jnc FIND_BEGIN
  722. jmp short FIND_CP_ERROR4
  723. FIND_BEGIN:
  724. mov di,ax
  725. mov cx,SIZE KEYBSYS_LANG_ENTRY-1 ; Set number
  726. ; bytes to read header
  727. mov dx,OFFSET FILE_BUFFER
  728. mov ah,3FH ; Read language entry in
  729. int 21H ; KEYBOARD.SYS file
  730. jnc FIND_VALID4 ; If no error in opening file then
  731. jmp short FIND_CP_ERROR4
  732. FIND_VALID4:
  733. ;****************************** CNS ****************************************
  734. xor ah,ah
  735. mov al,FB.KL_NUM_CP
  736. ;****************************** CNS ****************************************
  737. mov NUM_CP,ax ; Save the number of code pages
  738. MUL CP_PTR_SIZE ; Determine # of bytes to read
  739. mov dx,OFFSET FILE_BUFFER ; Establish beginning of buffer
  740. mov cx,ax
  741. cmp cx,FILE_BUFFER_SIZE ; Make sure buffer is not to small
  742. jbe FIND_VALID5
  743. jmp short FIND_CP_ERROR4
  744. FIND_VALID5:
  745. mov ah,3FH ; Read code page table from
  746. int 21H ; KEYBOARD.SYS file
  747. jnc FIND_VALID6 ; If no error in opening file then
  748. jmp short FIND_CP_ERROR4
  749. FIND_VALID6:
  750. mov cx,NUM_CP ; Number of valid codes
  751. mov di,OFFSET FILE_BUFFER ; Point to correct word in table
  752. F_SCAN_CP_TABLE: ; FOR code page parm
  753. mov ax,FIND_CP_PARM ; Get parameter
  754. cmp [di].KC_CODE_PAGE,ax ; Valid Code ??
  755. je F_CODE_PAGE_FOUND ; If not found AND more entries THEN
  756. add di,LANG_PTR_SIZE ; Check next entry
  757. loop F_SCAN_CP_TABLE ; Decrement count & loop
  758. jmp short FIND_CP_ERROR2 ; Display error message
  759. F_CODE_PAGE_FOUND:
  760. mov ax,word ptr [di].KC_ENTRY_PTR
  761. mov word ptr CP_TAB_OFFSET,ax
  762. mov ax,word ptr [di].KC_ENTRY_PTR+2
  763. mov word ptr CP_TAB_OFFSET+2,ax
  764. xor cx,cx
  765. ret
  766. FIND_CP_ERROR1:
  767. mov cx,1
  768. ret
  769. FIND_CP_ERROR2:
  770. mov cx,2
  771. ret
  772. FIND_CP_ERROR3:
  773. mov cx,3
  774. ret
  775. FIND_CP_ERROR4:
  776. mov cx,4
  777. ret
  778. FIND_CP_TABLE ENDP
  779. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  780. CODE ENDS
  781. END TABLE_BUILD