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.

2007 lines
84 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: KEYBI9C.ASM
  8. ; ----------
  9. ;
  10. ;
  11. ; Description:
  12. ; ------------
  13. ; Interrupt 9 mainline.
  14. ; This routine handles all US keyboard support for the following
  15. ; system units: PC, PC-XT, PC-AT, PC Convertible, PC-XT/286
  16. ; Models 25 and 30 (PALACE),
  17. ; PS/2's - all 8042 based 80286, 80386 and 80486.
  18. ; - all PATRIOT and SEBRING based systems.
  19. ; KEYB_STATE_PROCESSOR is called for non-US keyboard support.
  20. ;
  21. ;
  22. ;
  23. ; Procedures Contained in This File:
  24. ; ----------------------------------
  25. ; KEYB_INT_9 - Interrupt 9
  26. ;
  27. ; External Procedure References:
  28. ; ------------------------------
  29. ; FROM FILE KEYBI9.ASM:
  30. ; KEYB_STATE_PROCESSOR - Non US keyboard support.
  31. ;
  32. ; Linkage Information: Refer to file KEYB.ASM
  33. ; --------------------
  34. ;
  35. ; Change History:
  36. ; ---------------
  37. ; ; - DCR 478 - KEYBOARD INT SPLICING Nick Savage ;deleted by AN005
  38. ; ; - PTM 3090 ENABLING RIGHT CTL FOR RE-BOOTING
  39. ; ; - PTM 60XX PICK UP ALL KEYBOARD BIOS PTR's AND DCR's TO BRING
  40. ; INT 9h UP TO THE TOPHAT (80486) SUPPORT LEVEL. '89 jwg
  41. ; PTR 6600736 Keep INT's disabled till after PORT 60h read.
  42. ; PTR 6600756 EXTRA EOI ISSUED IF INTERRUPTS SATURATED **********
  43. ; NOTE: This is a fix for a BIOS bug that goes all
  44. ; the way back to the first AT. The rationale for
  45. ; the fix is as follows:
  46. ; (deleted AN005) A stack frame is created upon entry (BP) and
  47. ; CHK_EOI is called to check the frame. If no
  48. ; EOI has been issued, CHK_EOI does it and
  49. ; resets the frame, preventing any additinal
  50. ; EOI's from being issued on subsequent calls
  51. ; to CHK_EOI. All direct EOI's in the code
  52. ; have been replaced with calls to CHK_EOI.
  53. ;
  54. ; ;Ax004; - PTM 2555 KEYB command locks keyboard. 10/5/89;cja
  55. ; ; jwg 11/09/98 Updates - Wild Mouse, etc workaround.....
  56. ; ; - PTM 5802 Restructure Interrupt Splicing to correct lost Mouse
  57. ; interrupt when LED's are updated. Make it apply to
  58. ; all systems. Essentially remove all code added by AN001.
  59. ; Remove stack frame logic of AN003 and PTR 6600756 and do
  60. ; an early EOI. Requires a CLI at K38B and other places.
  61. ; Remove Chk_ibf before 60h.
  62. ; Re-write ERROR_BEEP to make processor speed independent
  63. ; for AT and PS/2 systems and right tone if interrupts.
  64. ; Make SHIP_IT handle call on PC machines.
  65. ; Use BP to hold system flags during interrupt processing.
  66. ; PTR 6602049 Fix problem with Pause Key hanging system if Mouse
  67. ; driver is using polled mode. (Port 60h hangs.)
  68. ; PTR 6602247 Change JMP at K40 to stop extra Enable Keyboard cmd.
  69. ; PTR 6602319 Fix interrupt window on System Request key allowing
  70. ; following scan code(s) to be processed out of sequence.
  71. ; PTR 6602355 Fix Print Screen clearing E0 state flags too late.
  72. ; ; - ;deleted Add code the clear "Wild Mouse" condition at PAUSE wait.
  73. ; ; - PTM 6660 Move determination code for original PC1 to COMMSUBS.ASM
  74. ; - ;jwg 2/90 Add Patriot/Sebring HOT REPLUG code so keyboard can be
  75. ; switched back to Scan Code Set 1 if repluged. LIB LITE
  76. ; ; - PTM 6680 Remove code attempting to re-sync BIOS flags with reset
  77. ; Keyboard. Test case simulators can/are sending invalid
  78. ; sequence of AA,AA. Must leave BIOS flags alone on POR.
  79. ; ; - PTM 6716 MicroSoft WORKS (German version) reentrancy problem with
  80. ; - ;jwg 3/90 NLS state processor and save scan code. LED update ACK
  81. ; overlays memory before NLS processing of scan code.
  82. ; Remove AN006 "Wild Mouse" reset code, field tests done.
  83. ; ; - PTM ???? Fix read ID logic to recognize 122 keyboards and set the
  84. ; ;jwg 8/90 KBX flag on any enhansed keyboard.
  85. ; ; - PTM ???? Add 122 Keyboard key support tables.
  86. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  87. INCLUDE KEYBEQU.INC
  88. INCLUDE DSEG.INC ; System data segments
  89. INCLUDE POSTEQU.INC ; System equates
  90. INCLUDE KEYBSHAR.INC
  91. INCLUDE KEYBI2F.INC
  92. INCLUDE KEYBI9.INC
  93. INCLUDE KEYBCPSD.INC
  94. INCLUDE KEYBCMD.INC
  95. include bop.inc
  96. include vint.inc
  97. PUBLIC KEYB_INT_9
  98. PUBLIC K8 ; CTRL case tables
  99. PUBLIC SCAN_CODE
  100. PUBLIC BUFFER_FILL
  101. PUBLIC COUNTRY_FLAG
  102. PUBLIC COPY_NLS1_FLAG ;; (YST)
  103. PUBLIC BEEP_PENDING
  104. PUBLIC ERROR_BEEP
  105. PUBLIC CHK_IBF
  106. ifdef JAPAN
  107. PUBLIC S_122_MARKER ; 122 KEYBOARD F8/00 marker
  108. PUBLIC BEEP_DELAY ; Error beep delay, default=19
  109. PUBLIC SCAN_CODE_SET ; Keyboard Scan Code Set in use
  110. PUBLIC READ_ID2 ; Second byte read on last READ ID
  111. endif ; JAPAN
  112. ID_1 EQU 0ABH ; 1ST ID CHARACTER FOR KBX
  113. TID_2 EQU 041H ; US G-LAYOUT
  114. TID_2A EQU 054H ; US P-LAYOUT
  115. ;UNTRANSLATED 2ND ID CHAR FOR KBDX
  116. ID_2U EQU 083H ; US G-LAYOUT (PATRIOT)
  117. ID_2AU EQU 084H ; US P-LAYOUT (PATRIOT)
  118. ID_122 EQU 086H ; 2ND ID CHARACTER FOR 122-KEYBOARD
  119. ID_2JG EQU 090H ; JPN G-LAYOUT
  120. ID_2JP EQU 091H ; JPN P-LAYOUT
  121. ID_2JA EQU 092H ; JPN A-LAYOUT
  122. ifdef JAPAN
  123. S_XKBD_SCAN EQU 0A6h ; Highest Character Code For Enhanced
  124. S_122_MARK EQU 0F8h ; Marker for EXTENDED 122 keys DCR 1815
  125. endif ; JAPAN
  126. DIAGS SEGMENT AT 0FFFFH
  127. ORG 0
  128. RESET LABEL FAR
  129. DIAGS ENDS
  130. CODE SEGMENT PUBLIC 'CODE'
  131. ASSUME CS:CODE,DS:DATA
  132. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  133. ;
  134. ; TABLE OF SHIFT KEYS AND MASK VALUES
  135. ;
  136. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  137. ;------ KEY_TABLE
  138. K6 LABEL BYTE
  139. DB INS_KEY ; INSERT KEY
  140. DB CAPS_KEY,NUM_KEY,SCROLL_KEY,ALT_KEY,CTL_KEY
  141. DB LEFT_KEY,RIGHT_KEY
  142. K6L EQU $-K6
  143. ;------ MASK_TABLE
  144. K7 LABEL BYTE
  145. DB INS_SHIFT ; INSERT MODE SHIFT
  146. DB CAPS_SHIFT,NUM_SHIFT,SCROLL_SHIFT,ALT_SHIFT,CTL_SHIFT
  147. DB LEFT_SHIFT,RIGHT_SHIFT
  148. ;---------- TABLES FOR ALT CASE -----
  149. ;------ ALT-INPUT-TABLE
  150. K30 LABEL BYTE
  151. DB 82,79,80,81,75
  152. DB 76,77,71,72,73 ; 10 NUMBERS ON KEYPAD
  153. ;------ SUPER-SHIFT-TABLE
  154. DB 16,17,18,19,20,21 ; A-Z TYPEWRITER CHARS
  155. DB 22,23,24,25,30,31
  156. DB 32,33,34,35,36,37
  157. DB 38,44,45,46,47,48
  158. DB 49,50
  159. K30_LEN EQU $-K30-10
  160. ;------ ALT-INPUT-FUNCTION-TABLE 53H - 7EH
  161. K30A LABEL BYTE
  162. DB -1,-1,-1,-1,139,140 ; Del, SysReq, Undef, WT, F11, F12
  163. DB -1,235,218,219,220 ; Undef, PA1, F13, F14, F15
  164. DB -1,-1,-1,-1,-1 ; Pause, Undef 5F-62
  165. DB 221,222,223,226,227 ; F16, F17, F18, F19, F20,
  166. DB 228,229,230,231 ; F21, F22, F23, F24,
  167. DB -1,243,-1,-1 ; K#69, ErEOF, Break, Play,
  168. DB -1,-1,-1,-1,-1 ; Undef, Attn, CrSel, K#56, ExSel
  169. DB -1,253 ; K#74, Clear,
  170. ifdef NOT_NTVDM
  171. ;;* DB -1,-1,-1 ; Undef, K#109, Undef
  172. ;;* DB -1,-1,-1,-1,-1 ; Undef, Undef, K#94, K#14, Undef
  173. else
  174. DB -1,-1,-1 ; Undef, K#109, Undef
  175. DB -1,-1,-1,-1,-1 ; Undef, Undef, K#94, K#14, K#107
  176. endif
  177. ifdef JAPAN
  178. DB -1 ; 07Eh, 07Fh. DBCS Pseudo codes.
  179. ; H_LAST_SCAN must be 07Fh for DBCS
  180. endif ; JAPAN
  181. H_LAST_SCAN EQU $-K30A+52h ; Largest valid scan code in table
  182. ; K30A K8 K15 K14 must have same ends
  183. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  184. ; K8 is overlaid by K8_RPL (from module KEYB_COMMAND)
  185. ; if extended INT 16 support is available
  186. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  187. K8 LABEL BYTE ;-------- CHARACTERS ---------
  188. DB 27,-1,00,-1,-1,-1 ; Esc, 1, 2, 3, 4, 5
  189. DB 30,-1,-1,-1,-1,31 ; 6, 7, 8, 9, 0, -
  190. DB -1,127,-1,17,23,5 ; =, Bksp, Tab, Q, W, E
  191. DB 18,20,25,21,09,15 ; R, T, Y, U, I, O
  192. DB 16,27,29,10,-1,01 ; P, [, ], Enter, Ctrl, A
  193. DB 19,04,06,07,08,10 ; S, D, F, G, H, J
  194. DB 11,12,-1,-1,-1,-1 ; K, L, ;, ', `, LShift
  195. DB 28,26,24,03,22,02 ; \, Z, X, C, V, B
  196. DB 14,13,-1,-1,-1,-1 ; N, M, ,, ., /, RShift
  197. DB '*',-1,' ',-1 ; *, Alt, Space, CL
  198. ;--------- FUNCTIONS ---------
  199. DB 94,95,96,97,98,99 ; F1 - F6
  200. DB 100,101,102,103,-1,-1 ; F7 - F10, NL, SL
  201. DB 119,-1,132,-1,115,-1 ; Home, Up, PgUp, -, Left, Pad5
  202. DB 116,-1,117,-1,118,-1 ; Right, +, End, Down, PgDn, Ins
  203. DB -1,-1,-1,-1,137,138 ; Del, SysReq, Undef, WT, F11, F12
  204. ;---------- 122 KEYBOARD not overlaid
  205. DB -1,234,206,207,208 ; Undef, PA1, F13, F14, F15
  206. DB -1,-1,-1,-1,-1 ; Pause, Undef 5F-62
  207. DB 209,210,211,212,213 ; F16, F17, F18, F19, F20,
  208. DB 214,215,216,217 ; F21, F22, F23, F24,
  209. DB -1,242,-1,-1 ; K#69, ErEOF, Break, Play,
  210. DB -1,-1,-1,-1,-1 ; Undef, Attn, CrSel, K#56, ExSel
  211. DB -1,252 ; K#74, Clear,
  212. ifdef NOT_NTVDM
  213. ;;* DB -1,-1,-1 ; Undef, K#109, Undef
  214. ;;* DB -1,-1,-1,-1,-1 ; Undef, Undef, K#94, K#14, Undef
  215. else
  216. DB -1,-1,-1 ; Undef, K#109, Undef
  217. DB -1,-1,-1,-1,-1 ; Undef, Undef, K#94, K#14, K#107
  218. endif
  219. ifdef JAPAN
  220. DB -1 ; 07Eh, 07Fh. DBCS Pseudo codes.
  221. endif ; JAPAN
  222. ;----- TABLES FOR LOWER CASE (USA) --
  223. K10 LABEL BYTE
  224. DB 27,'12345'
  225. DB '67890-'
  226. DB '=',08,09,'qwe'
  227. DB 'rtyuio'
  228. DB 'p[]',0DH,-1,'a' ; LETTERS, Return, Ctrl
  229. DB 'sdfghj'
  230. DB "kl;'`",-1 ; LETTERS, L Shift
  231. DB '\zxcvb'
  232. DB 'nm,./'
  233. DB -1,'*',-1,' \' ; R Shift, *, Alt, Sp, CL (REALLY WT KEY)
  234. ;------ LC TABLE SCAN
  235. DB 59,60,61,62,63 ; BASE STATE OF F1 - F10
  236. DB 64,65,66,67,68
  237. DB -1,-1 ; NL, SL
  238. ;------ KEYPAD TABLE
  239. K15 LABEL BYTE
  240. DB 71,72,73,-1,75,-1 ; Home, Up, PgUp, -1, Left, -1
  241. DB 77,-1,79,80,81,82 ; Right, -1, End, Down, PgDn, Ins
  242. DB 83 ; Del
  243. DB -1,-1,'\',133,134 ; SysRq, Undef, WT, F11, F12
  244. ifndef JAPAN
  245. DB -1,232,182,183,184 ; Undef, PA1, F13, F14, F15
  246. else ; JAPAN
  247. DB -1,232,236,237,238 ; Undef, PA1, F13, F14, F15
  248. endif ; JAPAN
  249. DB -1,-1,-1,-1,-1 ; Pause, Undef 5F-62
  250. ifndef JAPAN
  251. DB 185,186,187,188,189 ; F16, F17, F18, F19, F20,
  252. DB 190,191,192,193 ; F21, F22, F23, F24,
  253. else ; JAPAN
  254. DB 239,244,245,246,247 ; F16, F17, F18, F19, F20,
  255. DB 248,249,250,192 ; F21, F22, F23, F24,
  256. endif ; JAPAN
  257. DB -1,240,-1,-1 ; K#69, ErEOF, Break, Play,
  258. DB -1,-1,-1,-1,-1 ; Undef, Attn, CrSel, K#56, ExSel
  259. DB -1,251 ; K#74, Clear,
  260. ifdef NOT_NTVDM
  261. ;;* DB -1,-1,-1 ; Undef, K#109, Undef
  262. ;;* DB -1,-1,-1,-1,-1 ; Undef, Undef, K#94, K#14, Undef
  263. else
  264. DB -1,-1,-1 ; Undef, K#109, Undef
  265. DB -1,-1,-1,-1,-1 ; Undef, Undef, K#94, K#14, K#107
  266. endif
  267. ifdef JAPAN
  268. DB -1 ; 07Eh, 07Fh. DBCS Pseudo codes.
  269. endif ; JAPAN
  270. ;------- TABLES FOR UPPER CASE (USA)
  271. K11 LABEL BYTE
  272. DB 27,'!@#$%'
  273. DB '^&*()_'
  274. DB '+',08,00,'QWE'
  275. DB 'RTYUIO'
  276. DB 'P{}',0DH,-1,'A' ; LETTERS, Return, Ctrl
  277. DB 'SDFGHJ'
  278. DB 'KL:"~',-1 ; LETTERS, L Shift
  279. DB '|ZXCVB'
  280. DB 'NM<>?'
  281. DB -1,'*',-1,' |' ; R Shift, *, Alt, Sp, CL (REALLY WT KEY)
  282. ;------ UC TABLE SCAN
  283. K12 LABEL BYTE
  284. DB 84,85,86,87,88 ; SHIFTED STATE OF F1 - F10
  285. DB 89,90,91,92,93
  286. DB -1,-1 ; NL, SL
  287. ;------ NUM STATE TABLE
  288. K14 LABEL BYTE
  289. DB '789-456+1230.' ; NUMLOCK STATE OF KEYPAD KEYS
  290. DB -1,-1,'|',135,136 ; SysRq, Undef, WT, F11, F12
  291. ifndef JAPAN
  292. DB -1,233,194,195,196 ; Undef, PA1, F13, F14, F15
  293. else ; JAPAN
  294. DB -1,233,193,195,196 ; Undef, PA1, F13, F14, F15
  295. endif ; JAPAN
  296. DB -1,-1,-1,-1,-1 ; Pause, Undef 5F-62
  297. DB 197,198,199,200,201 ; F16, F17, F18, F19, F20,
  298. DB 202,203,204,205 ; F21, F22, F23, F24,
  299. DB -1,241,-1,-1 ; K#69, ErEOF, Break, Play,
  300. DB -1,-1,-1,-1,-1 ; Undef, Attn, CrSel, K#56, ExSel
  301. DB -1,251 ; K#74, Clear,
  302. ifdef NOT_NTVDM
  303. ;;* DB -1,-1,-1 ; Undef, K#109, Undef
  304. ;;* DB -1,-1,-1,-1,-1 ; Undef, Undef, K#94, K#14, Undef
  305. else
  306. DB -1,-1,-1 ; Undef, K#109, Undef
  307. DB -1,-1,-1,-1,-1 ; Undef, Undef, K#94, K#14, K#107
  308. endif
  309. ifdef JAPAN
  310. DB -1 ; 07Eh, 07Fh. DBCS Pseudo codes.
  311. endif ; JAPAN
  312. PAGE
  313. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  314. ;
  315. ; Procedure: KEYB_INT_9
  316. ;
  317. ; Description:
  318. ; Entry point for interrupt 9 processing.
  319. ;
  320. ; Input Registers:
  321. ; None
  322. ;
  323. ; Output Registers:
  324. ; None
  325. ;
  326. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  327. EVEN ; Keep KEYB_INT_9 entry on even boundry
  328. BEEP_PENDING DB NO ; YES if a beep is needed
  329. SCAN_CODE DB 0 ; Last SCAN code read
  330. KEYB_INT_9 PROC NEAR
  331. JMP SHORT KB_INT_1 ;; (YST)
  332. COPY_NLS1_FLAG DB 0 ;; (YST)
  333. COUNTRY_FLAG DB -1 ; WHERE THE INT9 VECTOR POINTS
  334. ifdef JAPAN
  335. READ_ID2 DB 0 ; Second byte from last READ ID
  336. BEEP_DELAY DW 19 ; Error beep delay, 19=Refresh loop,
  337. ; the half cycle time for 1745 hz
  338. SCAN_CODE_SET DB 01h ; In case of old DBCS keyboards, this
  339. ; may be 81h or 82h. Default is 01
  340. S_122_MARKER DB 0F8h ; Marker for 122-KEYBOARD KEYS DCR 1815
  341. ; Changed to E0 depending on INT 16h
  342. EVEN ; Force to even location
  343. endif ; JAPAN
  344. KB_INT_1:
  345. ; Do NOT enable interrupts untill after
  346. ; PORT 60h has been read. INT 15h has
  347. ; interrupt window, do EOI, fast pass.
  348. PUSH BP ; Reserved in KEYBi9c for SD.SYSTEM_FLAG
  349. PUSH AX
  350. PUSH BX
  351. PUSH CX
  352. PUSH DX
  353. PUSH SI
  354. PUSH DI
  355. PUSH DS
  356. PUSH ES
  357. CLD ; FORWARD DIRECTION
  358. MOV BX,DATA ; SET UP ADDRESSING
  359. MOV DS,BX ; DS POINTS AT THE ROM BIOS DATA AREA
  360. MOV BP,CS:SD.SYSTEM_FLAG ; GET CS:SD.SYSTEM_FLAG, AND USE BP
  361. ifdef NOT_NTVDM
  362. ;/* -- WAIT TILL KEYBOARD DISABLE COMMAND CAN BE ACCEPTED
  363. MOV AL,DIS_KBD ; DISABLE THE KEYBOARD COMMAND
  364. CALL SHIP_IT ; EXECUTE DISABLE
  365. else
  366. mov ah, 1 ; notify I9 entry to softpc
  367. BOP 09h
  368. nop ; Carbon copy traces for
  369. nop ; "in al,PORT_A"
  370. endif ; keep it traceable
  371. IN AL,PORT_A ; READ IN THE CHARACTER
  372. ;/* -- SYSTEM HOOK INT 15H - FUNCTION 4FH (ON HARDWARE INTERRUPT LEVEL 9H)
  373. MOV AH,04FH ; SYSTEM INTERCEPT - KEY CODE FUNCTION
  374. STC ; SET CY= 1 (IN CASE OF IRET)
  375. INT 15H ; CASSETTE CALL (AL)= KEY SCAN CODE
  376. ; RETURNS CY= 1 FOR INVALID FUNCTION
  377. ifdef NOT_NTVDM
  378. ; EARLY EOI for all interrupts done
  379. ; after INT 15h to prevent re-entrancy
  380. XCHG BX,AX ; SAVE SCAN CODE
  381. MOV AL,EOI ; END OF INTERRUPT COMMAND (EARLY EOI)
  382. OUT INTA00,AL ; SEND EOI TO INTERRUPT CONTROL PORT
  383. XCHG BX,AX ; RECOVER SCAN CODE
  384. endif
  385. JC KB_INT_02 ; CONTINUE IF CARRY FLAG SET ((AL)=CODE)
  386. JMP K26 ; EXIT IF SYSTEM HANDLED SCAN CODE
  387. ; EXIT HANDLES ENABLE
  388. ;/* --- CHECK FOR A POSSIBLE HOT REPLUG AND A POR COMPLETE CODE
  389. KB_INT_02: ; (AL)= SCAN CODE
  390. ifdef NOT_NTVDM
  391. ; ntvdm we don't do keyboard resets\power on stuff
  392. ;
  393. ; CHECK FOR POR
  394. CMP AL,KB_OK ; CHECK FOR POSSIBLE KEYBOARD POR CHAR
  395. JNE KB_INT_03 ; CONTINUE NOT A POR OF AA
  396. ; CHECK FOR ENHANSED KEYB
  397. TEST KB_FLAG_3,LC_E0 ; WAS E0h LAST SCAN CODE? DCR467
  398. JNZ KB_INT_03 ; SKIP KB POR IF IT WAS
  399. ; CHECK FOR LEFT SHIFT BREAK
  400. TEST KB_FLAG,LEFT_SHIFT ; IS LEFT SHIFT ACTIVE?
  401. JNZ KB_INT_03 ; SKIP KB POR IF IT WAS
  402. ; KEYBOARD POWER ON DETECTED
  403. MOV CS:BEEP_PENDING,YES ; INDICATE WE NEED A BEEP
  404. MOV KB_FLAG_2,0 ; CLEAR ALL LED FLAGS TO FORCE UPDATE
  405. ; LEAVE OTHERS SO KB SIMULATORS WORK
  406. TEST BP,PS_8042 ; SYSTEM USING 8042 & SCAN CODE SET 01?
  407. JZ KB_INT_03 ; SKIP IF SYSTEM USES DEFAULT SCS 02
  408. ; PATRIOT/SEBRING 8042 GATE ARRAY
  409. MOV AL,SCAN_CODE_CMD ; SELECT SCAN CODE SET COMMAND
  410. CALL SND_DATA ; SEND IT DIRECTLY TO THE KEYBOARD
  411. MOV AL,01h ; SELECT SCAN CODE SET 01
  412. CALL SND_DATA ; SEND IT TO THE KEYBOARD
  413. MOV AL,KB_OK ; RESTORE POR SCAN CODE IN (AL)
  414. endif
  415. KB_INT_03:
  416. ;/* --- CHECK FOR A RESEND COMMAND TO KEYBOARD
  417. ;; NTVDM STI ; ENABLE INTERRUPTS AGAIN
  418. CMP AL,KB_RESEND ; IS THE INPUT A RESEND
  419. JE KB_INT_4 ; GO IF RESEND
  420. ;/* --- CHECK FOR RESPONSE TO A COMMAND TO KEYBOARD
  421. CMP AL,KB_ACK ; IS THE INPUT AN ACKNOWLEDGE
  422. JNZ KB_INT_2 ; GO IF NOT
  423. ;/* --- A COMMAND TO THE KEYBOARD WAS ISSUED
  424. ;; NTVDM CLI ; DISABLE INTERRUPTS
  425. OR KB_FLAG_2,KB_FA ; INDICATE ACK RECEIVED
  426. JMP K26 ; RETURN IF NOT (ACK RETURNED FOR DATA)
  427. ;/* --- RESEND THE LAST BYTE
  428. KB_INT_4:
  429. ;; NTVDM CLI ; DISABLE INTERRUPTS
  430. OR KB_FLAG_2,KB_FE ; INDICATE RESEND RECEIVED
  431. JMP K26 ; RETURN IF NOT (ACK RETURNED FOR DATA)
  432. ;/* --- UPDATE MODE INDICATORS IF CHANGE IN STATE
  433. KB_INT_2:
  434. PUSH AX ; SAVE DATA IN
  435. CALL MAKE_LED ; GO GET MODE INDICATOR DATA BYTE
  436. MOV BL, KB_FLAG_2 ; GET PREVIOUS BITS
  437. XOR BL,AL ; SEE IF ANY DIFFERENT
  438. AND BL,KB_LEDS ; ISOLATE INDICATOR BITS
  439. JZ UP0 ; IF NO CHANGE BYPASS UPDATE
  440. CALL SND_LED ; GO TURN ON MODE INDICATORS
  441. UP0: POP AX ; RESTORE DATA IN
  442. ;---------------------------------------------------------------------
  443. ; START OF KEY PROCESSING -
  444. ;---------------------------------------------------------------------
  445. MOV AH,AL ; SAVE SCAN CODE IN AH ALSO
  446. ; END OF RE-ENTRANT CODE PATHS
  447. MOV CS:SCAN_CODE,AL ; SAVE SCAN CODE TO BE PROCESSED BY KEYB
  448. ;------ TEST FOR OVERRUN SCAN CODE FROM KEYBOARD
  449. CMP AL,KB_OVER_RUN ; IS THIS AN OVERRUN CHAR?
  450. JNZ K16 ; NO, TEST FOR SHIFT KEY
  451. MOV CS:BEEP_PENDING,YES
  452. JMP K26 ; BUFFER_FULL_BEEP, EXIT
  453. K16:
  454. PUSH CS
  455. POP ES ; ESTABLISH ADDRESS OF TABLES
  456. MOV BH, KB_FLAG_3 ; LOAD FLAGS FOR TESTING
  457. ;------ TEST TO SEE IF A READ_ID IS IN PROGRESS
  458. TEST BH,RD_ID+LC_AB ; ARE WE DOING A READ ID?
  459. JZ NOT_ID ; CONTINUE IF NOT
  460. JNS TST_ID_2 ; IS THE RD_ID FLAG ON?
  461. CMP AL,ID_1 ; IS THIS THE 1ST ID CHARACTER?
  462. JNE RST_RD_ID
  463. OR KB_FLAG_3,LC_AB ; INDICATE 1ST ID WAS OK
  464. RST_RD_ID:
  465. AND KB_FLAG_3,NOT RD_ID ; RESET THE READ ID FLAG
  466. JMP SHORT ID_EX ; AND EXIT
  467. ;------ CHECK 2ND US KBD ID - FOR SETTING NUM LOCK ON
  468. TST_ID_2:
  469. AND KB_FLAG_3,NOT LC_AB ; RESET FLAG
  470. OR KB_FLAG_3,KBX ; INDICATE ENHANCED KEYBOARD WAS FOUND
  471. ifdef JAPAN
  472. ; If it responds to a read ID command
  473. MOV CS:READ_ID2,AL ; Save ID just read for ID checks
  474. endif ; JAPAN
  475. CMP AL,TID_2 ; IS THIS US G-LAYOUT KBD w 8042
  476. JE NUM_LOCK_000 ; JUMP IF SO
  477. CMP AL,ID_2U ; IS THIS US G-LAYOUT KBD w/o 8042
  478. JE NUM_LOCK_000 ; JUMP IF SO
  479. CMP AL,ID_122 ; IS THIS THE 122 KEY ENHANCED KEYBOARD
  480. JE NUM_LOCK_000 ; JUMP IF SO
  481. ;------ CHECK 2ND JAPANESE KBD ID ;DCR355
  482. CMP AL,ID_2JG ; IS THIS JPN KBD - G ?
  483. JE NUM_LOCK_000 ; JUMP IF SO
  484. CMP AL,ID_2JA ; IS THIS JPN KBD - A ?
  485. JNE ID_EX ; EXIT IF NUM LOCK NOT REQUIRED
  486. ; These ID's do not set NUM LOCK ON
  487. ; ID_2AU = US P-LAYOUT KBD w/o 8042
  488. ; TID_2A = US P-LAYOUT KBD w 8042
  489. ; ID_2JP = JPN KBD - P
  490. ;------ A READ ID SAID THAT IT WAS ENHANCED KEYBOARD
  491. NUM_LOCK_000:
  492. TEST BH,SET_NUM_LK ; SHOULD WE SET NUM LOCK?
  493. JZ ID_EX ; EXIT IF NOT
  494. OR KB_FLAG,NUM_STATE ; FORCE NUM LOCK ON
  495. CALL SND_LED ; GO SET THE NUM LOCK INDICATOR
  496. ID_EX:
  497. JMP K26 ; EXIT
  498. PAGE
  499. NOT_ID:
  500. ifdef JAPAN
  501. ; M005 -- Kermit merge changes + AN013 ;AN013
  502. TEST BP,DBCS_OK ; Is a DBCS keyboard active? ;JP9009;AN013
  503. JZ NOT_DBCS ; Skip DBCS shift case checks ;AN013
  504. MOV BL,KB_FLAG ; Get shift key state flags now ;JP9009;AN013
  505. ; ntraid:mskkbug#3516: Alt+Capslock does not work 11/9/93 yasuho
  506. CALL DBCS_keyboard_support ; Go check for special shift key;JP9009;AN013
  507. ; We can't call because this is edited
  508. ; scan code directly. I comment it.
  509. ; 8/31/93 NT-J
  510. NOT_DBCS: ;AN013
  511. ; M005 -- End changes + AN013
  512. endif ; JAPAN
  513. CMP AL,MC_E0 ; IS THIS THE GENERAL MARKER CODE?
  514. JNE TEST_E1
  515. OR KB_FLAG_3,LC_E0+KBX ; SET FLAG BIT, SET KBX, AND
  516. JMP SHORT EXIT ; THROW AWAY THIS CODE
  517. TEST_E1:
  518. CMP AL,MC_E1 ; IS THIS THE PAUSE KEY?
  519. JNE NOT_HC
  520. OR KB_FLAG_3,LC_E1+KBX ; SET FLAG, PAUSE KEY MARKER CODE
  521. EXIT: JMP K26A ; THROW AWAY THIS CODE
  522. NOT_HC:
  523. AND AL,07FH ; TURN OFF THE BREAK BIT
  524. TEST BH,LC_E0 ; LAST CODE THE E0 MARKER CODE?
  525. JZ NOT_LC_E0 ; JUMP IF NOT
  526. MOV CX,2 ; LENGTH OF SEARCH
  527. MOV DI,OFFSET K6+6 ; IS THIS A SHIFT KEY?
  528. REPNE SCASB ; CHECK IT
  529. JNE K16A ; NO, CONTINUE KEY PROCESSING
  530. JMP SHORT K16B ; YES, THROW AWAY & RESET FLAG
  531. NOT_LC_E0:
  532. TEST BH,LC_E1 ; LAST CODE THE E1 MARKER CODE?
  533. JZ T_SYS_KEY ; JUMP IF NOT
  534. MOV CX,4 ; LENGTH OF SEARCH
  535. MOV DI,OFFSET K6+4 ; IS THIS AN ALT, CTL, OR SHIFT?
  536. REPNE SCASB ; CHECK IT
  537. JE EXIT ; THROW AWAY IF SO
  538. CMP AL,NUM_KEY ; IS IT THE PAUSE KEY?
  539. JNE K16B ; NO, THROW AWAY & RESET FLAG
  540. TEST AH,80H ; YES, IS IT THE BREAK OF THE KEY?
  541. JNZ K16B ; YES, THROW THIS AWAY, TOO
  542. TEST KB_FLAG_1,HOLD_STATE ; NO, ARE WE PAUSED ALREADY?
  543. JNZ K16B ; YES, THROW AWAY
  544. JMP K39P ; NO, THIS IS THE REAL PAUSE STATE
  545. PAGE
  546. ;------ TEST FOR SYSTEM KEY
  547. T_SYS_KEY:
  548. CMP AL,SYS_KEY ; IS IT THE SYSTEM KEY?
  549. JNE K16A ; CONTINUE IF NOT
  550. TEST AH,080H ; CHECK IF THIS A BREAK CODE
  551. ;; NTVDM CLI ; DISABLE INTERRUPTS PTR 6602319
  552. JNZ K16C ; DON'T TOUCH SYSTEM INDICATOR IF TRUE
  553. TEST KB_FLAG_1,SYS_SHIFT ; SEE IF IN SYSTEM KEY HELD DOWN
  554. JNZ K16B ; IF YES, DON'T PROCESS SYSTEM INDICATOR
  555. OR KB_FLAG_1,SYS_SHIFT ; INDICATE SYSTEM KEY DEPRESSED
  556. ifdef NOT_NTVDM
  557. MOV AL,ENA_KBD ; INSURE KEYBOARD IS ENABLED
  558. CALL SHIP_IT ; EXECUTE ENABLE
  559. else
  560. mov ah, 3 ; K27A exit notify
  561. BOP 09h
  562. endif
  563. MOV AX,08500H ; FUNCTION VALUE FOR MAKE OF SYSTEM KEY
  564. INT 15H ; USER INTERRUPT
  565. JMP K27A ; END PROCESSING
  566. K16B: JMP K26 ; IGNORE SYSTEM KEY
  567. K16C: AND KB_FLAG_1,NOT SYS_SHIFT; TURN OFF SHIFT KEY HELD DOWN
  568. ifdef NOT_NTVDM
  569. MOV AL,ENA_KBD ; INSURE KEYBOARD IS ENABLED
  570. CALL SHIP_IT ; EXECUTE ENABLE
  571. else
  572. mov ah, 3 ; K27A exit notify
  573. BOP 09h
  574. endif
  575. MOV AX,08501H ; FUNCTION VALUE FOR BREAK OF SYSTEM KEY
  576. INT 15H ; USER INTERRUPT
  577. JMP K27A ; IGNORE SYSTEM KEY
  578. PAGE
  579. ;------ TEST FOR SHIFT KEYS
  580. ;
  581. ; HERE IS WHERE KB_FLAGS ARE SET. WHAT HAPPENS IS, THE SYSTEM SEARCHES TABLE
  582. ; 'K6' FOR THE KEY. IF FOUND, IT GETS THE APPROPRIATE BIT FROM TABLE 'K7'
  583. ; AND SETS IT ON. (TABLES ARE ALL AT THE TOP OF THIS ROUTINE) FLAGS FOR THE
  584. ; SECOND ALT AND CTRL ARE SET IN KB_FLAG_3 AND HAVE THE SAME BIT POSITIONS AS
  585. ; THEIR ORIGINAL COUNTERPARTS IN KB_FLAG
  586. K16A: MOV BL, KB_FLAG ; PUT STATE FLAGS IN BL
  587. MOV DI,OFFSET K6 ; SHIFT KEY TABLE
  588. MOV CX,K6L ; LENGTH
  589. REPNE SCASB ; LOOK THROUGH THE TABLE FOR A MATCH
  590. MOV AL,AH ; RECOVER SCAN CODE
  591. JE K17 ; JUMP IF MATCH FOUND
  592. JMP K25 ; IF NO MATCH, THEN SHIFT NOT FOUND
  593. ;------ SHIFT KEY FOUND
  594. K17: SUB DI,OFFSET K6+1 ; ADJUST PTR TO SCAN CODE MTCH
  595. MOV AH,CS:K7[DI] ; GET MASK INTO AH
  596. MOV CL,2 ; SET UP COUNT FOR FLAG SHIFTS
  597. TEST AL,80H ; TEST FOR BREAK KEY
  598. JZ K17C
  599. JMP K23 ; JUMP IF BREAK
  600. ;------ SHIFT MAKE FOUND, DETERMINE SET OR TOGGLE
  601. K17C: CMP AH,SCROLL_SHIFT
  602. JAE K18 ; IF SCROLL SHIFT OR ABOVE, TOGGLE KEY
  603. ;------ PLAIN SHIFT KEY, SET SHIFT ON
  604. CMP COUNTRY_FLAG,0FFh ; ARE WE IN FOREIGN LANG MODE?
  605. JNE K17C1 ; NO, US MODE, JUMP
  606. CMP AL,ALT_KEY ; IS THIS THE ALT KEY?
  607. JNE K17C1 ; NO, NORMAL KEY
  608. ;**CNS
  609. K17C1: OR KB_FLAG,AH ; TURN ON SHIFT BIT
  610. K17C2: TEST AH,CTL_SHIFT+ALT_SHIFT ; IS IT ALT OR CTRL?
  611. JZ K17F ; NO, JUMP
  612. K17D: TEST BH,LC_E0 ; IS THIS ONE OF THE NEW KEYS?
  613. JZ K17E ; NO, JUMP
  614. OR KB_FLAG_3,AH ; SET BITS FOR RIGHT CTRL, ALT
  615. ; JMP K26 ; INTERRUPT_RETURN
  616. jmp short K17G ; (YST)
  617. K17E: SHR AH,CL ; MOVE FLAG BITS TWO POSITIONS
  618. OR KB_FLAG_1,AH ; SET BITS FOR LEFT CTRL, ALT
  619. ; JMP K26 ; INTERRUPT RETURN
  620. jmp short K17G ; (YST)
  621. K17F:
  622. TEST CS:SD.SPECIAL_FEATURES,TYPEWRITER_CAPS_LK
  623. JZ K17G ; N..all done
  624. CMP COUNTRY_FLAG,0FFh ; ARE WE IN LANG MODE?
  625. JNE K17G ; NO, ALL DONE WITH SHIFT KEY
  626. ;------ If keyboard is P12 then we still need to release caps_lk
  627. TEST BP,PC_LAP ; IS THIS A P12 KEYBOARD?
  628. JNZ REMOVE_CAPS_SHIFT
  629. TEST BH,KBX ; THIS THE ENHANCED KEYBOARD?
  630. JZ K17G ; NO, ALL DONE WITH SHIFT KEY
  631. REMOVE_CAPS_SHIFT:
  632. AND KB_FLAG,NOT CAPS_SHIFT ; YES, TAKE KB OUT OF C_L STATE
  633. CALL SND_LED ; AND UPDATE THE LED INDICATORS
  634. K17G:
  635. ; ===========================================
  636. ; Russian Keyboard (YST)
  637. ; ===========================================
  638. CMP COUNTRY_FLAG,0FFh ; ARE WE IN FOREIGN LANG MODE? (YST)
  639. JNE K17H ; NO, US MODE, RETURN (YST)
  640. TEST CS:SD.SPECIAL_FEATURES,SHIFTS_TO_LOGIC; CAN OUR STATE (YST)
  641. ; LOGIC SUPPORT THIS CALL? (YST)
  642. JZ K17H ; NO, RETURN (YST)
  643. OR CS:FLAGS_TO_TEST[EXT_KB_FLAG_ID],SHIFTS_PRESSED; (YST)
  644. ; SET FLAG FOR STATE LOGIC (YST)
  645. CALL KEYB_STATE_PROCESSOR ; ******** (YST)
  646. AND CS:FLAGS_TO_TEST[EXT_KB_FLAG_ID],NOT SHIFTS_PRESSED; (YST)
  647. ; CLEAR FLAG AFTER USE (YST)
  648. ; ===========================================
  649. ; End of Russian Keyboard (YST)
  650. ; ===========================================
  651. K17H: JMP K26 ; RETURN
  652. ;------ TOGGLED SHIFT KEY, TEST FOR 1ST MAKE OR NOT
  653. K18: ; SHIFT-TOGGLE
  654. TEST BL,CTL_SHIFT ; CHECK CTL SHIFT STATE
  655. JZ K18A ; JUMP IF NOT CTL STATE
  656. JMP K25 ; JUMP IF CTL STATE
  657. K18A: CMP AL,INS_KEY ; CHECK FOR INSERT KEY
  658. JNE K22 ; JUMP IF NOT INSERT KEY
  659. TEST BL,ALT_SHIFT ; CHECK FOR ALTERNATE SHIFT
  660. JZ K18B ; JUMP IF NOT ALTERNATE SHIFT
  661. JMP K25 ; JUMP IF ALTERNATE SHIFT
  662. K18B: TEST BH,LC_E0 ; IS THIS THE NEW INSERT KEY?
  663. JNZ K22 ; YES, THIS ONE'S NEVER A "0"
  664. K19: TEST BL,NUM_STATE ; CHECK FOR BASE STATE
  665. JNZ K21 ; JUMP IF NUM LOCK IS ON
  666. TEST BL,LEFT_SHIFT+RIGHT_SHIFT ; TEST FOR SHIFT STATE
  667. JZ K22 ; JUMP IF BASE STATE
  668. K20: MOV AH,AL ; PUT SCAN CODE BACK IN AH
  669. JMP K25 ; NUMERAL "0", STNDRD. PROCESSING
  670. K21: TEST BL,LEFT_SHIFT+RIGHT_SHIFT ; MIGHT BE NUMERIC
  671. JZ K20 ; IS NUMERIC, STD. PROC.
  672. K22: ; SHIFT TOGGLE KEY HIT; PROCESS IT
  673. TEST AH, KB_FLAG_1 ; IS KEY ALREADY DEPRESSED?
  674. JZ K22A
  675. JMP K26 ; JUMP IF KEY ALREADY DEPRESSED
  676. K22A: OR KB_FLAG_1,AH ; INDICATE THAT THE KEY IS DEPRESSED
  677. XOR KB_FLAG,AH ; TOGGLE THE SHIFT STATE
  678. TEST CS:SD.SPECIAL_FEATURES,TYPEWRITER_CAPS_LK
  679. JZ K22C ; N..all done
  680. ;------ If keyboard is P12 then we do not toggle
  681. TEST BP,PC_LAP ; IS THIS A P12 KEYBOARD?
  682. JNZ LAP_SO_DONT_TOGGLE
  683. TEST BH,KBX ; THIS THE ENHANCED KEYBOARD?
  684. JZ K22C ; NO, ALL DONE WITH TOGGLE KEYS
  685. LAP_SO_DONT_TOGGLE:
  686. CMP CS:COUNTRY_FLAG,0FFh ; ARE WE IN FOREIGN LANG MODE?
  687. JNE K22C ; NO, NO SPECIAL STUFF FOR U.S.
  688. TEST AH,CAPS_SHIFT ; IS IT THE CAPS_LOCK KEY?
  689. JZ K22C ; NO, NOTHING ELSE TO DO
  690. OR KB_FLAG,AH ; YES, SET CAPS_LOCK (NOT TOGGLE)
  691. K22C:
  692. ;------ TOGGLE LED IF CAPS, NUM, OR SCROLL KEY DEPRESSED
  693. TEST AH,CAPS_SHIFT+NUM_SHIFT+SCROLL_SHIFT ; SHIFT TOGGLE?
  694. JZ K22B ; GO IF NOT
  695. PUSH AX ; SAVE SCAN CODE AND SHIFT MASK
  696. CALL SND_LED ; GO TURN MODE INDICATORS ON
  697. POP AX ; RESTORE SCAN CODE
  698. K22B: CMP AL,INS_KEY ; TEST FOR 1ST MAKE OF INSERT KEY
  699. JNE K26 ; JUMP IF NOT INSERT KEY
  700. MOV AH,AL ; SCAN CODE IN BOTH HALVES OF AX
  701. JMP K28 ; FLAGS UPDATED, PROC. FOR BUFFER
  702. ;------ BREAK SHIFT FOUND
  703. K23: ; BREAK-SHIFT-FOUND
  704. CMP AH,SCROLL_SHIFT ; IS THIS A TOGGLE KEY?
  705. NOT AH ; INVERT MASK
  706. JAE K24 ; YES, HANDLE BREAK TOGGLE
  707. AND KB_FLAG,AH ; TURN OFF SHIFT BIT
  708. CMP AH,NOT CTL_SHIFT ; IS THIS ALT OR CTL?
  709. JA K23D ; NO, ALL DONE
  710. TEST BH,LC_E0 ; 2ND ALT OR CTL?
  711. JZ K23A ; NO, HANDLE NORMALLY
  712. AND KB_FLAG_3,AH ; RESET BIT FOR RIGHT ALT OR CTL
  713. JMP SHORT K23B ; CONTINUE
  714. K23A: SAR AH,CL ; MOVE THE MASK BIT TWO POSITIONS
  715. AND KB_FLAG_1,AH ; RESET BIT FOR LEFT ALT OR CTL
  716. K23B: MOV AH,AL ; SAVE SCAN CODE
  717. MOV AL, KB_FLAG_3 ; GET RIGHT ALT & CTRL FLAGS
  718. CMP COUNTRY_FLAG,0FFH ; ARE WE IN LANGUAGE MODE?
  719. JNE K23C ; NO, LEAVE RIGHT FLAGS AS IS
  720. ;**CNS
  721. AND AL,NOT GRAPH_ON ; YES, FILTER OUT THE ALT_GR KEY
  722. ;**CNS
  723. K23C: SHR AL,CL ; MOVE TO BITS 1 & 0
  724. OR AL, KB_FLAG_1 ; PUT IN LEFT ALT & CTL FLAGS
  725. SHL AL,CL ; MOVE BACK TO BITS 3 & 2
  726. AND AL,ALT_SHIFT+CTL_SHIFT ; FILTER OUT OTHER GARBAGE
  727. OR KB_FLAG,AL ; PUT RESULT IN THE REAL FLAGS
  728. MOV AL,AH ; RECOVER SAVED SCAN CODE
  729. K23D: CMP AL,ALT_KEY+80H ; IS THIS ALTERNATE SHIFT RELEASE
  730. JNE K26 ; INTERRUPT_RETURN
  731. ;------ ALTERNATE SHIFT KEY RELEASED, GET THE VALUE INTO BUFFER
  732. MOV AL, ALT_INPUT
  733. xor ah,ah ; scan code of 0
  734. MOV ALT_INPUT,AH ; ZERO OUT THE FIELD
  735. or al,al ; was the input = 0?
  736. JE K26 ; INTERRUPT_RETURN
  737. CALL BUFFER_FILL_ANY_CHAR ; Put in buffer, but use this
  738. ; entry point to avoid trashing
  739. ; an ASCII code of 255
  740. JMP SHORT K26 ; INTERRUPT_RETURN
  741. K24: ; BREAK-TOGGLE
  742. AND KB_FLAG_1,AH ; INDICATE NO LONGER DEPRESSED
  743. JMP SHORT K26 ; INTERRUPT_RETURN
  744. ;------ TEST FOR HOLD STATE
  745. ; AL, AH = SCAN CODE
  746. K25: ; NO-SHIFT-FOUND
  747. CMP AL,80H ; TEST FOR BREAK KEY
  748. JAE K26 ; NOTHING FOR BREAK CHARS FROM HERE ON
  749. TEST KB_FLAG_1,HOLD_STATE ; ARE WE IN HOLD STATE
  750. JZ K28 ; BRANCH AROUND TEST IF NOT
  751. CMP AL,NUM_KEY
  752. JE K26 ; CAN'T END HOLD ON NUM_LOCK
  753. AND KB_FLAG_1,NOT HOLD_STATE ; TURN OFF THE HOLD STATE BIT
  754. K26:
  755. AND KB_FLAG_3,NOT LC_E0+LC_E1 ; RESET LAST CHAR H.C. FLAG
  756. K26A: ; INTERRUPT-RETURN
  757. ifdef NOT_NTVDM
  758. ;; NTVDM CLI ; TURN OFF INTERRUPTS
  759. CALL ERROR_BEEP ; CHECK FOR ERROR BEEP PENDING
  760. CMP CS:BUFFER_ENTRY_OK,YES ; HAS A CHARACTER BEEN PLACED IN BUFFER
  761. JNE K27 ; NO, SKIP POST
  762. MOV byte ptr CS:BUFFER_ENTRY_OK,NO ; CLEAR POST CHARACTER IN BUFFER FLAG
  763. MOV AX,09102H ; MOVE IN POST CODE & TYPE
  764. INT 15H ; PERFORM OTHER FUNCTION
  765. K27:
  766. MOV AL,ENA_KBD ; ENSURE KEYBOARD IS ENABLED (AT PS/2)
  767. CALL SHIP_IT ; EXECUTE ENABLE
  768. else
  769. mov ah, 2
  770. mov bh, CS:BEEP_PENDING
  771. mov bl, CS:BUFFER_ENTRY_OK
  772. MOV byte ptr CS:BUFFER_ENTRY_OK,NO
  773. MOV byte ptr CS:BEEP_PENDING,NO
  774. BOP 09h
  775. endif
  776. K27A: ;; NTVDM CLI ; DISABLE INTERRUPTS
  777. POP ES ; RESTORE REGISTERS
  778. POP DS ; *
  779. POP DI ; *
  780. POP SI ; *
  781. POP DX ; *
  782. POP CX ; *
  783. POP BX ; *
  784. POP AX ; *
  785. POP BP ; *
  786. jmp DOIRET ; RETURN
  787. PAGE
  788. ;------ NOT IN HOLD STATE
  789. ; AL, AH = SCAN CODE (ALL MAKES)
  790. K28: ; NO-HOLD-STATE
  791. CMP AL,H_LAST_SCAN ; TEST FOR OUT-OF-RANGE SCAN CODES
  792. JA SHORT K26 ; IGNORE IF OUT-OF-RANGE
  793. ifndef JAPAN
  794. TEST BP,EXT_122 ; IS EXTENDED 122 KEYBOARD SUPPORT OK
  795. else ; JAPAN
  796. ; Must pass 07Eh and 07Fh DBCS pseudo's;AN013
  797. ; IS DBCS KEYBOARD support code active ;AN013
  798. TEST BP,EXT_122+DBCS_OK ; or EXTENDED 122 KEYBOARD support OK ;AN013
  799. endif ; JAPAN
  800. JNZ K28_122 ; SKIP NON-122 OUT-OF-RANGE CHECK
  801. ifdef NOT_NTVDM
  802. CMP AL,88 ; TEST FOR OUT-OF-RANGE SCAN CODES
  803. else
  804. CMP AL,7Eh ; MAX SCANCODE ON BRAZILIAN ABNT KBD
  805. endif
  806. JA K26 ; IGNORE IF OUT-OF-RANGE
  807. K28_122:
  808. TEST BL,ALT_SHIFT ; ARE WE IN ALTERNATE SHIFT?
  809. JZ K28A ; JUMP IF NOT ALTERNATE
  810. TEST BH,KBX ; IS THIS THE ENHANCED KEYBOARD?
  811. JZ K29 ; NO, ALT STATE IS REAL
  812. TEST KB_FLAG_1,SYS_SHIFT ; YES, IS SYSREQ KEY DOWN?
  813. JZ K29 ; NO, ALT STATE IS REAL
  814. ;**CNS
  815. TEST AH,LC_E0 ; IS IT THE ALT_GR KEY?
  816. JZ K28A ; YES, DON'T SET KB_FLAG
  817. TEST AL,R_ALT_SHIFT ; TURN ON SHIFT BIT
  818. JNZ K29 ; TURN ON SHIFT BIT
  819. ;**CNS
  820. K28A: JMP K38 ; YES, THIS IS PHONY ALT STATE
  821. ; DUE TO PRESSING SYSREQ
  822. ;------ TEST FOR RESET KEY SEQUENCE (CTL ALT DEL) OR HOT KEY DEPRESSED
  823. K29: ; TEST-RESET
  824. TEST BL,CTL_SHIFT ; ARE WE IN CONTROL SHIFT ALSO?
  825. ifndef JAPAN
  826. JZ K31 ; NO_RESET
  827. else ; JAPAN
  828. JZ K31C ; NO_RESET, Not in Ctrl state
  829. endif ; JAPAN
  830. CMP AL,DEL_KEY ; SHIFT STATE IS THERE, TEST KEY
  831. JNE K31A ; NO_RESET, TRANSLATE TABLE SWAP
  832. ;------ CTL-ALT-DEL HAS BEEN FOUND, DO I/O CLEANUP
  833. MOV RESET_FLAG,1234H ; SET FLAG FOR RESET FUNCTION
  834. AND WORD PTR KB_FLAG_3,KBX ; CLEAR ALL FLAG BITS EXCEPT KBX PED 6-25-86
  835. JMP RESET ; JUMP TO POWER ON DIAGNOSTICS
  836. ifdef JAPAN
  837. ;------ SET COUNTRY FLAG TO INDICATE WHICH TABLE WE'RE USING, FOREIGN OR DOMESTIC
  838. K31A: CMP AL,CS:SD.HOT_KEY_ON_SCAN ; TEST FOR HOT KEY TO US
  839. JNE K31B
  840. MOV CS:COUNTRY_FLAG,00 ; SET FLAG FOR DOMESTIC KEY'S
  841. JMP K26 ; INTERRUPT RETURN
  842. K31B: CMP AL,CS:SD.HOT_KEY_OFF_SCAN ; TEST FOR HOT KEY TO FOREIGN
  843. JNE K31C ; IF NOT TEST FOR FRONT ENGRAV
  844. MOV CS:COUNTRY_FLAG,0FFH ; SET FLAGS FOR FOREIGN KEY'S
  845. JMP K26 ; INTERRUPT RETURN
  846. ;------ ALT STATE, OR CTRL AND ALT DOWN BUT NO HOT KEY F1/F2 OR DEL KEY ;AN014
  847. K31C: CMP CS:COUNTRY_FLAG,0FFH ; Check for country translate flag set ;AN014
  848. JNE K31 ; Else try ALT_KEY_PAD special cases ;AN014
  849. CALL KEYB_STATE_PROCESSOR ; Let NLS handle it's differences ;AN014
  850. JC K32A ;K26 ; TRANSLATIONS FOUND - EXIT
  851. endif ; JAPAN
  852. ;------ IN ALTERNATE SHIFT, RESET NOT FOUND
  853. K31: ; NO-RESET
  854. CALL KEYB_STATE_PROCESSOR
  855. ifndef JAPAN
  856. JC K26 ; TRANSLATIONS FOUND - EXIT
  857. else ; JAPAN
  858. JNC K310
  859. JMP K26 ; TRANSLATIONS FOUND - EXIT
  860. K310:
  861. endif ; JAPAN
  862. CMP AL,57 ; TEST FOR SPACE KEY
  863. JNE K311 ; NOT THERE
  864. MOV AL,' ' ; SET SPACE CHAR
  865. JMP K57 ; BUFFER_FILL
  866. K311:
  867. TEST BP,EXT_16 ; IS EXTENDED INT 16 LOADED?
  868. JZ K32 ; NO, SKIP THIS EXTENDED STUFF
  869. CMP AL,15 ; TEST FOR TAB KEY
  870. JNE K312 ; NOT THERE
  871. MOV AX,0A500h ; SET SPECIAL CODE FOR ALT-TAB
  872. JMP K57 ; BUFFER_FILL
  873. K312:
  874. CMP AL,74 ; TEST FOR KEYPAD -
  875. JE K312A ; GO PROCESS
  876. CMP AL,78 ; TEST FOR KEYPAD +
  877. JNE K32 ; SKIP TEST FOR LANG SWAP & CONT.
  878. K312A: JMP K37B ; GO PROCESS
  879. ifndef JAPAN
  880. ;------ SET COUNTRY FLAG TO INDICATE WHICH TABLE WE'RE USING, FOREIGN OR DOMESTIC
  881. K31A: CMP AL,CS:SD.HOT_KEY_ON_SCAN ; TEST FOR HOT KEY TO US
  882. JNE K31B
  883. MOV CS:COUNTRY_FLAG,00 ; SET FLAG FOR DOMESTIC KEY'S
  884. JMP K26 ; INTERRUPT RETURN
  885. K31B: CMP AL,CS:SD.HOT_KEY_OFF_SCAN ; TEST FOR HOT KEY TO FOREIGN
  886. JNE K31C ; IF NOT TEST FOR FRONT ENGRAV
  887. MOV CS:COUNTRY_FLAG,0FFH ; SET FLAGS FOR FOREIGN KEY'S
  888. JMP K26 ; INTERRUPT RETURN
  889. ;------ ALT, CTRL DOWN ; NO HOT KEY
  890. K31C: CMP CS:COUNTRY_FLAG,0FFH
  891. JNE K32 ; TRY ALT_KEY_PAD
  892. CALL KEYB_STATE_PROCESSOR
  893. JC K32A ;K26 ; TRANSLATIONS FOUND - EXIT
  894. endif ; !JAPAN
  895. ;------ LOOK FOR KEY PAD ENTRY
  896. K32: ; ALT-KEY-PAD
  897. MOV DI,OFFSET K30 ; ALT-INPUT-TABLE
  898. MOV CX,10 ; LOOK FOR ENTRY USING KEYPAD
  899. REPNE SCASB ; LOOK FOR MATCH
  900. JNE K33 ; NO_ALT_KEYPAD
  901. TEST BH,LC_E0 ; IS THIS ONE OF THE NEW KEYS?
  902. JNZ K37C ; YES, JUMP, NOT NUMPAD KEY
  903. SUB DI,OFFSET K30+1 ; DI NOW HAS ENTRY VALUE
  904. MOV AL, ALT_INPUT ; GET THE CURRENT BYTE
  905. MOV AH,10 ; MULTIPLY BY 10
  906. MUL AH
  907. ADD AX,DI ; ADD IN THE LATEST ENTRY
  908. MOV ALT_INPUT,AL ; STORE IT AWAY
  909. K32A: JMP K26 ; THROW AWAY THAT KEYSTROKE
  910. ;------ LOOK FOR SUPERSHIFT ENTRY
  911. K33: ; NO-ALT-KEYPAD
  912. MOV ALT_INPUT,0 ; ZERO ANY PREVIOUS ENTRY INTO INPUT
  913. ; DI,ES ALREADY POINTING
  914. MOV CX,K30_LEN ; NORMALLY 26, BUT 27 FOR FR, DUE
  915. ; TO THE ";" KEY BEING "M"
  916. REPNE SCASB ; LOOK FOR MATCH IN ALPHABET
  917. JE K37A ; MATCH FOUND, GO FILL THE BUFFER
  918. ;------ LOOK FOR TOP ROW OF ALTERNATE SHIFT
  919. K34: ; ALT-TOP-ROW
  920. CMP AL,2 ; KEY WITH '1' ON IT
  921. JB K37B ; MUST BE ESCAPE
  922. CMP AL,13 ; IS IT IN THE REGION
  923. JA K35 ; NO, ALT-SOMETHING ELSE
  924. ADD AH,118 ; CONVERT PSEUDO SCAN CODE TO RANGE
  925. JMP SHORT K37A ; GO FILL THE BUFFER
  926. ;------ TRANSLATE ALTERNATE SHIFT PSEUDO SCAN CODES
  927. K35: ; ALT-FUNCTION
  928. CMP AL,F11_M ; IS IT F11 or GREATER ?
  929. JB K35A ; NO, BRANCH
  930. SUB AL,52h ; SET UP TO SEARCH ALT-FUNCTION-TABLE
  931. MOV BX,OFFSET K30A ; BASE CASE TABLE
  932. JMP K64 ; CONVERT TO PSEUDO SCAN
  933. K35A: TEST BH,LC_E0 ; DO WE HAVE ONE OF THE NEW KEYS?
  934. JZ K37 ; NO, JUMP
  935. TEST BP,EXT_16 ; IS THE EXTENDED INT 16 LOADED?
  936. JZ K37 ; NO, DO COMPATIBLE OUTPUT
  937. CMP AL,28 ; TEST FOR KEYPAD ENTER
  938. JNE K35B ; NOT THERE
  939. MOV AX,0A600h ; SPECIAL CODE
  940. JMP K57 ; BUFFER FILL
  941. K35B: CMP AL,83 ; TEST FOR DELETE KEY
  942. JE K37C ; HANDLE WITH OTHER EDIT KEYS
  943. CMP AL,53 ; TEST FOR KEYPAD /
  944. JNE K32A ; NOT THERE, NO OTHER E0 SPECIALS
  945. MOV AX,0A400h ; SPECIAL CODE
  946. JMP K57 ; BUFFER FILL
  947. K37: CMP AL,59 ; TEST FOR FUNCTION KEYS (F1)
  948. JB K37B ; NO FN, HANDLE W/OTHER EXTENDED
  949. CMP AL,68 ; IN KEYPAD REGION?
  950. ; OR NUMLOCK, SCROLLOCK?
  951. JA K32A ; IF SO, IGNORE
  952. ADD AH,45 ; CONVERT TO PSEUDO SCAN CODE
  953. K37A: xor al,al ; ASCII CODE OF ZERO
  954. JMP K57 ; PUT IT IN THE BUFFER
  955. K37B:
  956. TEST BP,EXT_16 ; IS THE EXTENDED INT 16 LOADED?
  957. JZ K32A ;K26 ; NO, IGNORE THIS ONE
  958. MOV AL,0F0h ; USE SPECIAL ASCII CODE
  959. JMP K57 ; PUT IT IN THE BUFFER
  960. K37C:
  961. TEST BP,EXT_16 ; IS THE EXTENDED INT 16 LOADED?
  962. JZ K37A ; NO, DO COMPATIBLE OUTPUT
  963. ADD AL,80 ; CONVERT SCAN CODE (EDIT KEYS)
  964. MOV AH,AL ; (SCAN CODE NOT IN AH FOR INSERT)
  965. JMP K37A ; PUT IT IN THE BUFFER
  966. PAGE
  967. ;------ NOT IN ALTERNATE SHIFT
  968. K38: ; NOT-ALT-SHIFT
  969. ; BL STILL HAS SHIFT FLAGS
  970. TEST BL,CTL_SHIFT ; ARE WE IN CONTROL SHIFT?
  971. JNZ K38A ; YES, START PROCESSING
  972. JMP K44 ; NOT-CTL-SHIFT
  973. ;------ CONTROL SHIFT, TEST SPECIAL CHARACTERS
  974. ;------ TEST FOR BREAK
  975. K38A: CMP AL,SCROLL_KEY ; TEST FOR BREAK
  976. JNE K39 ; JUMP, NO-BREAK
  977. TEST BP,PC_LAP ; IS THIS THE LAP COMPUTER?
  978. JNZ K38B ; YES, THIS IS CTRL-BREAK
  979. TEST BH,KBX ; IS THIS THE ENHANCED KEYBOARD?
  980. JZ K38B ; NO, BREAK IS VALID
  981. TEST BH,LC_E0 ; YES, WAS LAST CODE AN E0?
  982. JZ K39 ; NO-BREAK, TEST FOR PAUSE
  983. K38B:
  984. ;; NTVDM CLI ; Disable interrupts because EOI issued
  985. MOV BX, BUFFER_HEAD ; RESET BUFFER TAIL TO BUFFER HEAD
  986. MOV BUFFER_TAIL,BX
  987. MOV BIOS_BREAK,80H ; TURN ON BIOS_BREAK BIT
  988. ;-------- ENABLE KEYBOARD
  989. ifdef NOT_NTVDM
  990. MOV AL,ENA_KBD ; ENABLE KEYBOARD
  991. CALL SHIP_IT ; EXECUTE ENABLE
  992. else
  993. mov ah, 4
  994. BOP 09h
  995. endif
  996. INT 1BH ; BREAK INTERRUPT VECTOR
  997. SUB AX,AX ; PUT OUT DUMMY CHARACTER
  998. JMP K57 ; BUFFER_FILL
  999. ;-------- TEST FOR PAUSE
  1000. K39: ; NO-BREAK
  1001. CMP AL,NUM_KEY ; LOOK FOR PAUSE KEY
  1002. JNE K41 ; NO-PAUSE
  1003. TEST BH,KBX ; IS THIS THE ENHANCED KEYBOARD?
  1004. JZ K39P ; NO, THIS IS A VALID PAUSE
  1005. TEST BP,PC_LAP ; IS THIS THE LAP COMPUTER?
  1006. JZ K41 ; NO, IT'S NOT PAUSE THIS TIME
  1007. K39P: OR KB_FLAG_1,HOLD_STATE ; TURN ON THE HOLD FLAG
  1008. ;-------- ENABLE KEYBOARD
  1009. MOV AL,ENA_KBD ; ENABLE KEYBOARD
  1010. CALL SHIP_IT ; EXECUTE ENABLE
  1011. ifdef NOT_NTVDM
  1012. ;------ DURING PAUSE INTERVAL, TURN CRT BACK ON
  1013. CMP CRT_MODE,7 ; IS THIS BLACK AND WHITE CARD
  1014. JAE K40 ; YES, NOT CGA MODES NOTHING TO DO
  1015. MOV DX,03D8H ; PORT FOR COLOR CARD
  1016. MOV AL,CRT_MODE_SET ; GET THE VALUE OF THE CURRENT MODE
  1017. OUT DX,AL ; SET THE CRT MODE, SO THAT CRT IS ON
  1018. K40: ; PAUSE-LOOP
  1019. TEST BP,PC_LAP ; IS THIS THE LAP COMPUTER?
  1020. JZ K40A ; NO, SKIP THE BATTERY LIFE STUFF
  1021. MOV AX,4104H ; FUNCTION 41, AL=04=RETURN IF 0
  1022. MOV BX,HOLD_STATE*100H ; BH=HOLD_STATE, BL=0=NO TIME OUT
  1023. PUSH DS ; MAKE ES:DI POINT TO KB_FLAG_1
  1024. POP ES
  1025. MOV DI,OFFSET KB_FLAG_1
  1026. INT 15H ; SLEEP UNTIL OUT OF HOLD
  1027. ;------ CHECK FOR AUX ADAPTER INPUT PENDING
  1028. K40A:
  1029. MOV CX,100 ; COUNT FOR WAIT LOOP
  1030. else
  1031. mov ah, 3 ; K27A exit notify
  1032. BOP 09h
  1033. call DOSTI
  1034. K40A:
  1035. mov cx, 16
  1036. xor ax, ax
  1037. BOP BOP_WAITIFIDLE ; idle bop
  1038. endif
  1039. K40B:
  1040. TEST KB_FLAG_1,HOLD_STATE ; ARE WE IN HOLD STATE
  1041. JZ K40E ; EXIT IF NOT
  1042. ifdef NOT_NTVDM
  1043. TEST BP,PC_XT+PC_LAP ; Check for systems without AUX BIOS
  1044. JNZ K40B ; For them, just loop on hold flag
  1045. IN AL,STATUS_PORT ; READ CURRENT STATUS
  1046. AND AL,MOUSE_OBF+OUT_BUF_FULL ; MASK OFF ALL BUT MOUSE DATA BITS
  1047. CMP AL,MOUSE_OBF+OUT_BUF_FULL ; IS THERE STILL MOUSE DATA PENDING?
  1048. endif
  1049. LOOPE K40B ; WAIT FOR MOUSE DATA TO GO
  1050. JNE K40A ; CONTINUE IF PAUSE STATE ;an005
  1051. K40E:
  1052. ifndef NOT_NTVDM
  1053. call DOCLI
  1054. endif
  1055. AND KB_FLAG_1,NOT HOLD_STATE ; CLEAR HOLD STATE FLAG
  1056. JMP K27A ; INTERRUPT_RETURN_NO_EOI PTR 2247
  1057. ;------ TEST SPECIAL CASE KEY 55
  1058. K41: ; NO-PAUSE
  1059. CMP AL,55 ; TEST FOR */PRTSC KEY
  1060. JNE K42 ; NOT-KEY-55
  1061. TEST BP,PC_LAP ; IS THIS THE LAP COMPUTER?
  1062. JZ K41B ; NO, JUMP
  1063. TEST BH,LC_E0 ; YES, WAS LAST CODE AN E0?
  1064. JZ K41A ; NO, THIS IS THE PRTSC KEY
  1065. JMP SHORT K42B ; YES, E0 MEANS THE "*" KEY
  1066. K41B: TEST BH,KBX ; IS THIS THE ENHANCED KEYBOARD?
  1067. JZ K41A ; NO, CTL-PRTSC IS VALID
  1068. TEST BH,LC_E0 ; YES, WAS LAST CODE AN E0?
  1069. JZ K42B ; NO, TRANSLATE TO A FUNCTION
  1070. K41A: MOV AX,114*256 ; START/STOP PRINTING SWITCH
  1071. JMP K57 ; BUFFER_FILL
  1072. ;------ SET UP TO TRANSLATE CONTROL SHIFT
  1073. K42: ; NOT-KEY-55
  1074. ifdef JAPAN
  1075. CMP CS:COUNTRY_FLAG,0FFH ; Check for country translate flag set
  1076. JNE K42US ; Skip overhead if not in country mode
  1077. endif ; JAPAN
  1078. CALL KEYB_STATE_PROCESSOR
  1079. JC K449 ;K26 ; TRANSLATIONS FOUND - EXIT
  1080. ifdef JAPAN
  1081. K42US:
  1082. endif ; JAPAN
  1083. CMP AL,15 ; IS IT THE TAB KEY?
  1084. JE K42B ; YES, XLATE TO FUNCTION CODE
  1085. CMP AL,53 ; IS IT THE / KEY?
  1086. JNE K42A ; NO, NO MORE SPECIAL CASES
  1087. TEST BH,LC_E0 ; YES, IS IT FROM THE KEYPAD?
  1088. JZ K42A ; NO, JUST TRANSLATE
  1089. MOV AX,9500h ; YES, SPECIAL CODE FOR THIS ONE
  1090. JMP K57 ; BUFFER FILL
  1091. K42A: MOV BX,OFFSET K8 ; SET UP TO TRANSLATE CTL
  1092. CMP AL,59 ; IS IT IN CHARACTER TABLE?
  1093. JB K45F ; YES, GO TRANSLATE CHAR
  1094. K42B: MOV BX,OFFSET K8 ; SET UP TO TRANSLATE CTL
  1095. JMP K64 ; NO, GO TRANSLATE_SCAN
  1096. PAGE
  1097. ;------ NOT IN CONTROL SHIFT
  1098. K44:
  1099. ifdef JAPAN
  1100. CMP CS:COUNTRY_FLAG,0FFH ; Check for country translate flag set
  1101. JNE K44US ; Skip overhead if not in country mode
  1102. endif ;JAPAN
  1103. CALL KEYB_STATE_PROCESSOR
  1104. JC K449 ;K26 ; TRANSLATIONS FOUND - EXIT
  1105. ifdef JAPAN
  1106. K44US:
  1107. endif ; JAPAN
  1108. CMP AL,55 ; PRINT SCREEN KEY?
  1109. JNE K45 ; NOT-PRINT-SCREEN
  1110. TEST BP,PC_LAP ; IS THIS THE LAP COMPUTER?
  1111. JZ K441 ; NO, JUMP
  1112. TEST BH,LC_E0 ; YES, WAS LAST CODE THE MARKER?
  1113. JZ K44A ; NO, TEST THE SHIFT STATE
  1114. JMP SHORT K45C ; YES, XLATE TO "*" CHAR
  1115. K441: TEST BH,KBX ; IS THIS ENHANCED KEYBOARD?
  1116. JZ K44A ; NO, TEST FOR SHIFT STATE
  1117. TEST BH,LC_E0 ; YES, LAST CODE A MARKER?
  1118. JNZ K44B ; YES, IS PRINT SCREEN
  1119. JMP SHORT K45C ; NO, XLATE TO "*" CHARACTER
  1120. K44A: TEST BL,LEFT_SHIFT+RIGHT_SHIFT ;NOT 101 KBD, SHIFT KEY DOWN?
  1121. JZ K45C ; NO, XLATE TO "*" CHARACTER
  1122. ;------ ISSUE INTERRUPT TO PERFORM PRINT SCREEN FUNCTION
  1123. K44B:
  1124. ;; NTVDM CLI ; DISABLE INTERRUPTS PTR 2355
  1125. AND KB_FLAG_3,NOT LC_E0+LC_E1 ;ZERO OUT THESE FLAGS
  1126. ifdef NOT_NTVDM
  1127. MOV AL,ENA_KBD ; INSURE KEYBOARD IS ENABLED
  1128. CALL SHIP_IT ; EXECUTE ENABLE
  1129. else
  1130. mov ah, 3 ; K27A exit notify
  1131. BOP 09h
  1132. endif
  1133. PUSH BP ; SAVE POINTER (compatibility)
  1134. INT 5H ; ISSUE PRINT SCREEN INTERRUPT
  1135. POP BP ; RESTORE POINTER
  1136. JMP K27A ; EXIT WITHOUT EXTRA EOI OR ENABLE
  1137. K449:
  1138. JMP K26 ; EXIT
  1139. ;------ HANDLE THE IN-CORE KEYS
  1140. K45: ; NOT-PRINT-SCREEN
  1141. CMP AL,58 ; TEST FOR IN-CORE AREA
  1142. JA K46 ; JUMP IF NOT
  1143. TEST BH,GRAPH_ON ; IS ALT GRAPHICS ON? AEV
  1144. JNZ K449 ;K26 ; YES, TRASH KEYSTROKE
  1145. CMP AL,53 ; IS THIS THE "/" KEY?
  1146. JNE K45A ; NO, JUMP
  1147. TEST BH,LC_E0 ; WAS LAST CODE THE MARKER?
  1148. JNZ K45C ; YES, TRANSLATE TO CHARACTER
  1149. K45A: MOV CX,K30_LEN ; LENGTH OF SEARCH
  1150. MOV DI,OFFSET K30+10 ; POINT TO TABLE OF A-Z CHARS
  1151. REPNE SCASB ; IS THIS A LETTER KEY?
  1152. JNE K45B ; NO, SYMBOL KEY
  1153. TEST BL,CAPS_STATE ; ARE WE IN CAPS_LOCK?
  1154. JNZ K45D ; TEST FOR SURE
  1155. K45B: TEST BL,LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  1156. JNZ K45E ; YES, UPPERCASE
  1157. ; NO, LOWERCASE
  1158. K45C: MOV BX,OFFSET K10 ; TRANSLATE TO LOWERCASE LETTERS
  1159. JMP SHORT K56
  1160. K45D: ; ALMOST-CAPS-STATE
  1161. TEST BL,LEFT_SHIFT+RIGHT_SHIFT ; CL ON. IS SHIFT ON, TOO?
  1162. JNZ K45C ; SHIFTED TEMP OUT OF CAPS STATE
  1163. K45E: MOV BX,OFFSET K11 ; TRANSLATE TO UPPERCASE LETTERS
  1164. K45F: JMP SHORT K56
  1165. ;------ TEST FOR KEYS F1 - F10
  1166. K46: ; NOT IN-CORE AREA
  1167. CMP AL,68 ; TEST FOR F1 - F10
  1168. JA K47 ; JUMP IF NOT
  1169. JMP SHORT K53A ; YES, GO DO FN KEY PROCESS
  1170. ;------ HANDLE THE NUMERIC PAD KEYS
  1171. K47: ; NOT F1 - F10
  1172. CMP AL,83 ; TEST FOR NUMPAD KEYS
  1173. JA K52 ; JUMP IF NOT
  1174. ;------ KEYPAD KEYS, MUST TEST NUM LOCK FOR DETERMINATION
  1175. K48: CMP AL,74 ; SPECIAL CASE FOR MINUS
  1176. JE K45E ; GO TRANSLATE (US & WT ARE SAME)
  1177. CMP AL,78 ; SPECIAL CASE FOR PLUS
  1178. JE K45E ; GO TRANSLATE (US & WT ARE SAME)
  1179. TEST BH,LC_E0 ; IS THIS ONE OF THE NEW KEYS?
  1180. JNZ K49 ; YES, TRANSLATE TO BASE STATE
  1181. TEST BL,NUM_STATE ; ARE WE IN NUM_LOCK?
  1182. JNZ K50 ; TEST FOR SURE
  1183. TEST BL,LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  1184. JNZ K51 ; IF SHIFTED, REALLY NUM STATE
  1185. ;------ BASE CASE FOR KEYPAD
  1186. K49: CMP AL,76 ; SPECIAL CASE FOR BASE STATE 5
  1187. JNE K49A ; CONTINUE IF NOT KEYPAD 5
  1188. TEST BP,EXT_16 ; IS THE EXTENDED INT 16 LOADED?
  1189. JZ K59 ;K26 ; NO, INGORE
  1190. MOV AL,0F0h ; SPECIAL ASCII CODE
  1191. JMP SHORT K57 ; BUFFER FILL
  1192. K49A: MOV BX,OFFSET K10 ; BASE CASE TABLE
  1193. JMP SHORT K64 ; CONVERT TO PSEUDO SCAN
  1194. ;------ MIGHT BE NUM LOCK, TEST SHIFT STATUS
  1195. K50: TEST BL,LEFT_SHIFT+RIGHT_SHIFT ;ALMOST-NUM-STATE
  1196. JNZ K49 ; SHIFTED TEMP OUT OF NUM STATE
  1197. K51: JMP SHORT K45E ; REALLY_NUM_STATE
  1198. ; (US & WT ARE SAME)
  1199. ;------ TEST FOR THE NEW KEY ON WT KEYBOARDS
  1200. K52: ; NOT A NUMPAD KEY
  1201. CMP AL,86 ; IS IT THE NEW WT KEY?
  1202. JNE K53 ; JUMP IF NOT
  1203. MOV AL,58 ; WE'RE GOING TO PULL A SNEAKY
  1204. JMP K45 ; TRICK HERE. WT TABLES ARE TOO SHORT TO
  1205. ; XLATE 86, SO WE'LL CHANGE IT TO CAPS_LOCK
  1206. ; AND PUT THE CHAR IN THE TABLES IN THE C_L
  1207. ; POSITION, SINCE C_L SCAN CODES NEVER GET
  1208. ; HERE ANYWAY.
  1209. ;------ MUST BE F11 OR F12
  1210. K53: TEST BP,EXT_16 ; IS THE EXTENDED INT 16 THERE?
  1211. JZ K59 ; NO, INGORE F11 & F12 (NEAR RET)
  1212. ; F1 - F10 COME HERE, TOO
  1213. K53A: TEST BL,LEFT_SHIFT+RIGHT_SHIFT ;TEST SHIFT STATE
  1214. JZ K49 ; JUMP, LOWERCASE PSEUDO SC'S
  1215. MOV BX,OFFSET K11 ; UPPER CASE PSEUDO SCAN CODES
  1216. JMP SHORT K64 ; TRANSLATE_SCAN
  1217. PAGE
  1218. ;------ TRANSLATE THE CHARACTER
  1219. K56: ; TRANSLATE-CHAR
  1220. DEC AL ; CONVERT ORIGIN
  1221. XLAT CS:K11 ; CONVERT THE SCAN CODE TO ASCII
  1222. TEST KB_FLAG_3,LC_E0 ; IS THIS A NEW KEY?
  1223. JZ K57 ; NO, GO FILL BUFFER
  1224. TEST BP,EXT_16 ; IS THE EXTENDED INT 16 THERE?
  1225. JZ K57 ; NO, DO COMPATIBLE OUTPUT
  1226. MOV AH,MC_E0 ; YES, PUT SPECIAL MARKER IN AH
  1227. JMP SHORT K57 ; PUT IT INTO THE BUFFER
  1228. ;------ TRANSLATE SCAN FOR PSEUDO SCAN CODES
  1229. K64: ; TRANSLATE-SCAN-ORGD
  1230. DEC AL ; CONVERT ORIGIN
  1231. XLAT CS:K8 ; CTL TABLE SCAN
  1232. MOV AH,AL ; PUT VALUE INTO AH
  1233. xor al,al ; ZERO ASCII CODE
  1234. TEST KB_FLAG_3,LC_E0 ; IS THIS A NEW KEY?
  1235. JZ K57 ; NO, GO FILL BUFFER
  1236. TEST BP,EXT_16 ; IS THE EXTENDED INT 16 THERE?
  1237. JZ K57 ; NO, DO COMPATIBLE OUTPUT
  1238. MOV AL,MC_E0 ; YES, PUT SPECIAL MARKER IN AL
  1239. ;------ PUT CHARACTER INTO BUFFER
  1240. K57: ; BUFFER-FILL
  1241. ifdef JAPAN
  1242. CMP AH,0E0h ; Was this the Ctrl-Enter key? DCR 1815;AN013
  1243. JE Short K57N122 ; Do not add 122 key marker DCR 1815;AN013
  1244. CMP AH,S_XKBD_SCAN ; Is it non 122-keyboard key? DCR 1815;AN013
  1245. JBE Short K57N122 ; Yes, skip add of 122 marker DCR 1815;AN013
  1246. CMP CS:S_122_MARKER,0 ; Check special INT 16h case flag ;AN013
  1247. JE K57N122 ; Skip F8 marker, if INT 16h broken ;AN013
  1248. MOV AL,S_122_MARK ; Add special marker F8 if 122 DCR 1815;AN013
  1249. K57N122: ;AN013
  1250. endif ; JAPAN
  1251. CALL BUFFER_FILL
  1252. K59:
  1253. JMP K26 ;-- THAT'S ALL FOLKS --
  1254. KEYB_INT_9 ENDP
  1255. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1256. ;
  1257. ; Procedure: BUFFER_FILL
  1258. ;
  1259. ; Description:
  1260. ; Generate keyboard buffer entry
  1261. ;
  1262. ; Input Registers:
  1263. ; AX - the buffer entry
  1264. ; DS - BIOS data segment
  1265. ;
  1266. ; Output Registers:
  1267. ; None
  1268. ;
  1269. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1270. BUFFER_ENTRY_OK DB NO ; YES if character put into buffer
  1271. BUFFER_FILL PROC NEAR
  1272. ; CMP AL,-1 ; IS THIS AN IGNORE CHAR
  1273. ; JE K61B ; YES, EXIT (commented YST)
  1274. CMP AH,-1 ; LOOK FOR -1 PSEUDO SCAN
  1275. JE K61B ; EXIT
  1276. ;
  1277. ; BUFFER_FILL_ANY_CHAR is an alternate entry point to this PROC.
  1278. ; Entry at this point will avoid trashing ASCII values of 255.
  1279. ;
  1280. BUFFER_FILL_ANY_CHAR LABEL NEAR
  1281. PUSH SI
  1282. PUSH BX
  1283. PUSH DS ; This routine may be called
  1284. ; externally so make sure DS points
  1285. MOV BX,DATA ; to BIOS data
  1286. MOV DS,BX
  1287. ;; NTVDM cli ; disable interrupts P724
  1288. MOV BX, BUFFER_TAIL ; GET THE END POINTER TO THE BUFFER
  1289. MOV SI,BX ; SAVE THE VALUE
  1290. INC BX ; MOVE TO NEXT WORD IN LIST
  1291. INC BX
  1292. ;; VERIFY IF THE CURRENT ROM LEVEL IN THE SYSTEM IS FOR THE ORIGINAL PC1
  1293. TEST BP,PC_81 ; CHECK FOR '81 DATE FLAG SET
  1294. ifndef JAPAN
  1295. JNE NOT_PC1 ; IF IT'S A LATER ROM RELEASE, BRANCH
  1296. else ; JAPAN
  1297. JZ NOT_PC1 ; IF IT'S A LATER ROM RELEASE, BRANCH
  1298. endif ; JAPAN
  1299. CMP BX,OFFSET KB_BUFFER_END ; AT END OF BUFFER?
  1300. JNE K5 ; NO, CONTINUE
  1301. MOV BX,OFFSET KB_BUFFER ; YES, RESET TO BUFFER BEGINNING
  1302. JMP SHORT K5
  1303. NOT_PC1:
  1304. CMP BX, BUFFER_END ; AT END OF BUFFER?
  1305. JNE K5 ; NO, CONTINUE
  1306. MOV BX, BUFFER_START ; YES, RESET TO BUFFER BEGINNING
  1307. K5:
  1308. CMP BX,BUFFER_HEAD ; HAS THE BUFFER WRAPPED AROUND
  1309. JE K62 ; BUFFER_FULL_BEEP
  1310. MOV [SI],AX ; STORE THE VALUE
  1311. MOV BUFFER_TAIL,BX ; MOVE THE POINTER UP
  1312. MOV CS:BUFFER_ENTRY_OK,YES ; INDICATE WE PUT SOMETHING IN BUFFER
  1313. JMP SHORT K61A
  1314. K62:
  1315. MOV CS:BEEP_PENDING,YES ; INDICATE WE NEED A BEEP
  1316. K61A:
  1317. POP DS
  1318. POP BX
  1319. POP SI
  1320. ;; NTVDM sti ; enable interrupts P724
  1321. K61B:
  1322. RET
  1323. BUFFER_FILL ENDP
  1324. PAGE
  1325. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1326. ;
  1327. ; Procedure: ERROR_BEEP
  1328. ;
  1329. ; Description:
  1330. ; General routine to generate beep tones
  1331. ;
  1332. ; Input Registers:
  1333. ; None
  1334. ;
  1335. ; Output Registers:
  1336. ; None
  1337. ;
  1338. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1339. ERROR_BEEP PROC NEAR
  1340. CMP CS:BEEP_PENDING,YES ; Q..SHOULD WE BEEP?
  1341. JNE NO_BEEP
  1342. MOV CS:BEEP_PENDING,NO ; Reset BEEP required
  1343. ifndef NOT_NTVDM
  1344. mov ah, 0eh
  1345. mov al, 07h
  1346. int 10h
  1347. else
  1348. MOV CX,216-32 ; NUMBER OF CYCLES FOR 1/8 SECOND TONE
  1349. IN AL,PORT_B ; Get control info
  1350. PUSH AX
  1351. LOOP01:
  1352. AND AL,0FCH ; Turn off timer gate and speaker
  1353. OUT PORT_B,AL ; output to control - speaker off
  1354. CALL WAITFB ; half cycle time for tone
  1355. OR AL,2 ; turn on speaker
  1356. CLI ; Disable interrupts for 1/2 cycle, 300u
  1357. OUT PORT_B,AL ; output to control
  1358. CALL WAITFB ; another half cycle
  1359. STI ; Enable interrupts between 1/2 cycle
  1360. LOOP LOOP01
  1361. POP AX
  1362. OUT PORT_B,AL ; Restore control
  1363. MOV CX,32*2 ; Short delay count of 32 cycles
  1364. LOOP02:
  1365. CALL WAITFB ; Add a short delay to complete 1/8 sec
  1366. LOOP LOOP02 ; Repeat
  1367. CLI ; Disable interrupts
  1368. endif
  1369. NO_BEEP:
  1370. RET ; RETURN
  1371. ERROR_BEEP ENDP
  1372. ifdef NOT_NTVDM
  1373. WAITFB PROC NEAR ; DELAY FOR (CX)*15.085737 US
  1374. PUSH AX ; SAVE WORK REGISTER (AH)
  1375. PUSH CX ; SAVE COUNT
  1376. MOV CX,19 ; The half cycle time for 1745 hz
  1377. TEST BP,PC_AT+PC_386 ; IF THE SYSTEM IS AN 80x86
  1378. JNZ WAITF1 ; SKIP TO REFRESH BIT DELAY
  1379. WAITF0:
  1380. NOP ; Force two fetch cycles on Model 30
  1381. LOOP WAITF0 ; SOFTWARE DELAY LOOP ON 808x MACHINES
  1382. JMP SHORT WAITFE ; EXIT
  1383. WAITF1: ; USE TIMER 1 OUTPUT BITS
  1384. IN AL,PORT_B ; READ CURRENT COUNTER OUTPUT STATUS
  1385. AND AL,REFRESH_BIT ; MASK FOR REFRESH DETERMINE BIT
  1386. CMP AL,AH ; DID IT JUST CHANGE
  1387. JE WAITF1 ; WAIT FOR A CHANGE IN OUTPUT LINE
  1388. MOV AH,AL ; SAVE NEW FLAG STATE
  1389. LOOP WAITF1 ; DECREMENT HALF CYCLES TILL COUNT END
  1390. WAITFE:
  1391. POP CX ; RESTORE COUNT
  1392. POP AX ; RESTORE (AH)
  1393. RET ; RETURN (CX)= 0
  1394. WAITFB ENDP
  1395. endif
  1396. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1397. ;
  1398. ; SHIP_IT
  1399. ;
  1400. ; THIS ROUTINE HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  1401. ; TO THE KEYBOARD CONTROLLER.
  1402. ;
  1403. ; On entry the AL contains the command byte.
  1404. ; On Enable keyboard commands, the reset keyboard input latch is done
  1405. ; if the system is the old PC type.
  1406. ;
  1407. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1408. SHIP_IT PROC NEAR
  1409. ifdef NOT_NTVDM
  1410. ;------- TEST SYSTEM TYPE
  1411. PUSHF ; SAVE FLAGS P725
  1412. CLI ; DISABLE INTERRUPTS TILL DATA SENT
  1413. TEST BP,PC_XT+PC_LAP
  1414. JZ SI5 ; USE AT 8042 COMMAND IF NOT PC TYPE
  1415. CMP AL,ENA_KBD ; CHECK FOR ENABLE KEYBOARD COMMAND
  1416. JNE SI9 ; SKIP ENABLE RESET
  1417. ; FOR PC, XT, P12: RESET THE KEYBOARD
  1418. PUSH AX ; SAVE AX
  1419. IN AL,KB_CTL ; GET THE CONTROL PORT
  1420. MOV AH,AL ; SAVE VALUE
  1421. OR AL,80H ; RESET BIT FOR KEYBOARD ON PC/PC-XT
  1422. OUT KB_CTL,AL
  1423. XCHG AH,AL ; GET BACK ORIGINAL CONTROL
  1424. OUT KB_CTL,AL ; KB HAS BEEN RESET
  1425. POP AX ; RESTORE AX
  1426. ; EXIT as NOT next system
  1427. SI5:
  1428. TEST BP,PC_AT+PC_386 ; IF THE SYSTEM IS NOT AN 80x86
  1429. JZ SI9 ; MACHINE, EXIT THIS PROC.
  1430. ;------- WAIT FOR COMMAND TO BE ACCEPTED;
  1431. CALL chk_ibf ; GO READ KEYBOARD CONTROLLER STATUS
  1432. endif
  1433. OUT STATUS_PORT,AL ; SEND TO KEYBOARD CONTROLLER
  1434. ifdef NOT_NTVDM
  1435. SI9: ; ENABLE INTERRUPTS AGAIN
  1436. POPF ; RESTORE FLAGS P725
  1437. endif
  1438. RET ; RETURN TO CALLER
  1439. SHIP_IT ENDP
  1440. ifdef NOT_NTVDM
  1441. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1442. ;
  1443. ; SND_DATA
  1444. ;
  1445. ; THIS ROUTINE HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  1446. ; TO THE KEYBOARD AND RECEIPT OF ACKNOWLEDGEMENTS. IT ALSO
  1447. ; HANDLES ANY RETRIES IF REQUIRED
  1448. ;
  1449. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1450. SND_DATA PROC NEAR
  1451. PUSH AX ; SAVE REGISTERS
  1452. PUSH BX ; *
  1453. PUSH CX
  1454. MOV BH,AL ; SAVE TRANSMITTED BYTE FOR RETRIES
  1455. MOV BL,3 ; LOAD RETRY COUNT
  1456. SD0:
  1457. CLI ; DISABLE INTERRUPTS
  1458. AND KB_FLAG_2,NOT (KB_FE+KB_FA+kb_err) ; CLEAR ACK, RESEND and
  1459. ; error flags
  1460. CALL CHK_IBF ; Wait for command accepted
  1461. MOV AL,BH ; REESTABLISH BYTE TO TRANSMIT
  1462. OUT PORT_A,AL ; SEND BYTE
  1463. STI ; ENABLE INTERRUPTS
  1464. MOV CX,DLY_15MS ; DELAY FOR 15 ms TIMEOUT
  1465. SD1: TEST KB_FLAG_2,KB_FE+KB_FA ; SEE IF EITHER BIT SET
  1466. JNZ SD3 ; IF SET, SOMETHING RECEIVED GO PROCESS
  1467. IN AL,PORT_B ; WAIT LOOP USING REFRESH BIT
  1468. AND AL,REFRESH_BIT
  1469. CMP AL,AH
  1470. JE SD1 ; KEEP TESTING
  1471. MOV AH,AL ; DEC CX ON REFRESH TIC
  1472. LOOP SD1 ; KEEP TESTING
  1473. ; !! TIMEOUT !!
  1474. SD2: DEC BL ; DECREMENT RETRY COUNT
  1475. JNZ SD0 ; RETRY TRANSMISSION
  1476. OR KB_FLAG_2,KB_ERR ; TURN ON TRANSMIT ERROR FLAG
  1477. JMP SHORT SD4 ; RETRIES EXHAUSTED FORGET TRANSMISSION
  1478. SD3: TEST KB_FLAG_2,KB_FA ; SEE IF THIS IS AN ACKNOWLEDGE
  1479. JZ SD2 ; IF NOT, GO RESEND
  1480. SD4: POP CX ; RESTORE REGISTERS
  1481. POP BX
  1482. POP AX ; *
  1483. RET ; RETURN, GOOD TRANSMISSION
  1484. SND_DATA ENDP
  1485. endif
  1486. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1487. ;
  1488. ; SND_LED
  1489. ;
  1490. ; THIS ROUTINE TURNS ON THE MODE INDICATORS.
  1491. ;
  1492. ; NTVDM - we do not need to update led's as this is controlled
  1493. ; by the host\system. We also assume that interrupts are
  1494. ; off upon entry
  1495. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1496. SND_LED PROC NEAR
  1497. ifdef NOT_NTVDM
  1498. CLI ; TURN OFF INTERRUPTS
  1499. TEST BP,PC_AT+PC_386 ; IF THE SYSTEM IS NOT A 80x86
  1500. JZ SL1 ; MACHINE, EXIT THIS PROC
  1501. endif
  1502. TEST KB_FLAG_2,KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  1503. JNZ SL1 ; DONT UPDATE AGAIN IF UPDATE UNDERWAY
  1504. OR KB_FLAG_2,KB_PR_LED ; TURN ON UPDATE IN PROCESS
  1505. ifdef NOT_NTVDM
  1506. MOV AL,LED_CMD ; LED CMD BYTE
  1507. CALL SND_DATA ; SEND DATA TO KEYBOARD
  1508. CLI
  1509. endif
  1510. CALL MAKE_LED ; GO FORM INDICATOR DATA BYTE
  1511. AND KB_FLAG_2,0F8H ; CLEAR MODE INDICATOR BITS
  1512. OR KB_FLAG_2,AL ; SAVE PRESENT INDICATORS FOR NEXT TIME
  1513. mov ah, 3 ; inform softpc to set lights
  1514. BOP 16h
  1515. ifdef NOT_NTVDM
  1516. TEST KB_FLAG_2,KB_ERR ; TRANSMIT ERROR DETECTED
  1517. JNZ SL2 ; YES, BYPASS SECOND BYTE TRANSMISSION
  1518. CALL SND_DATA ; SEND DATA TO KEYBOARD
  1519. CLI ; TURN OFF INTERRUPTS
  1520. TEST KB_FLAG_2,KB_ERR ; TRANSMIT ERROR DETECTED
  1521. JZ SL3 ; IF NOT, DONT SEND AN ENABLE COMMAND
  1522. SL2: MOV AL,KB_ENABLE ; GET KEYBOARD CSA ENABLE COMMAND
  1523. CALL SND_DATA ; SEND DATA TO KEYBOARD
  1524. CLI ; TURN OFF INTERRUPTS
  1525. endif
  1526. SL3: AND KB_FLAG_2,NOT(KB_PR_LED+KB_ERR) ; TURN OFF MODE INDICATOR
  1527. ; UPDATE AND TRANSMIT ERROR FLAG
  1528. SL1:
  1529. ifdef NOT_NTVDM
  1530. STI ; ENABLE INTERRUPTS
  1531. endif
  1532. RET ; RETURN TO CALLER
  1533. SND_LED ENDP
  1534. PAGE
  1535. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1536. ;
  1537. ; MAKE_LED
  1538. ;
  1539. ; THIS ROUTINE FORMS THE DATA BYTE NECESSARY TO TURN ON/OFF
  1540. ; THE MODE INDICATORS
  1541. ;
  1542. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1543. MAKE_LED PROC NEAR
  1544. PUSH CX ; SAVE CX
  1545. MOV AL, KB_FLAG ; GET CAPS & NUM LOCK INDICATORS
  1546. AND AL,CAPS_STATE+NUM_STATE+SCROLL_STATE ; ISOLATE INDICATORS
  1547. MOV CL,4 ; SHIFT COUNT
  1548. ROL AL,CL ; SHIFT BITS OVER TO TURN ON INDICATORS
  1549. AND AL,07H ; MAKE SURE ONLY MODE BITS ON
  1550. POP CX
  1551. RET ; RETURN TO CALLER
  1552. MAKE_LED ENDP
  1553. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1554. ;
  1555. ; CHK_IBF
  1556. ;
  1557. ; Description:
  1558. ; Waits for a keyboard command to be accepted
  1559. ; wait until ibf = 0 (empty)
  1560. ;
  1561. ; Input Registers:
  1562. ; None
  1563. ;
  1564. ; Output Registers:
  1565. ; ZF=0 time out & IBF still full
  1566. ; ZF=1 IBF is empty
  1567. ;
  1568. ; ---------------------------------------------------------------
  1569. ; This procedure replaces the previous one which used a software
  1570. ; timing loop. (For 80286, 80386 and 80486 based machines.)
  1571. ; ---------------------------------------------------------------
  1572. ;
  1573. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1574. chk_ibf proc near
  1575. push ax ; Save register used
  1576. push cx
  1577. mov cx,DLY_15MS ; Timeout 15 milleseconds (15000/15.086;
  1578. chk_ibfl:
  1579. ifdef JAPAN
  1580. in al,status_port ; Read status port
  1581. test al,inpt_buf_full ; Check for input buffer empty
  1582. jz chk_ibfe ; Exit if IBF off, no command pending
  1583. endif ; JAPAN
  1584. in al,PORT_B ; Read current refresh output bit
  1585. and al,refresh_bit ; Mask all but refresh bit
  1586. cmp al,ah ; Did it change? (or first pass thru)
  1587. jz short chk_ibfl ; No, wait for change, else continue
  1588. mov ah,al ; Save new refresh bit state
  1589. ifndef JAPAN
  1590. in al,status_port ; Read status port
  1591. test al,inpt_buf_full ; Check for input buffer empty
  1592. loopnz chk_ibfl ; Loop until input buf empty or timeout;
  1593. else ; JAPAN
  1594. loop chk_ibfl ; Loop until timeout
  1595. chk_ibfe: ; or exit when Input Buffer Full off
  1596. endif ; JAPAN
  1597. pop cx
  1598. pop ax ; Restore register used
  1599. ret ; Return to caller
  1600. chk_ibf endp
  1601. ifdef JAPAN
  1602. ;***********************************************************************;JP9009
  1603. ;* *;JP9009
  1604. ;* DBCS Common Keyboard Support *;JP9009
  1605. ;* *;JP9009
  1606. ;* The DBCS common keyboard unique scan code is mapped to the *;JP9009
  1607. ;* temporary scan code. It is again mapped to the corresponding *;JP9009
  1608. ;* scan code/character code according the current shift staes. *;JP9009
  1609. ;* *;JP9009
  1610. ;***********************************************************************;JP9009
  1611. ;JP9009
  1612. DBCS_keyboard_support proc near ;JP9009
  1613. cmp al, 80h ; Ignore break keys ;JP9009
  1614. jae leave_it_to_common_method ;JP9009
  1615. ;AN013 test cs:SD.KEYB_TYPE, DBCS_KB ; DBCS keyboard? ;JP9009
  1616. ;AN013 jz leave_it_to_common_method ;JP9009
  1617. cmp cs:SD.INVOKED_CP_TABLE, 932 ; DBCS code page? ;JP9009
  1618. jb leave_it_to_common_method ;JP9009
  1619. call DBCS_keyboard_common_support ;JP9009
  1620. test cs:SD.KEYB_TYPE, DBCS_OLD_KB ;JP9009
  1621. jz leave_it_to_common_method_1 ;JP9009
  1622. call DBCS_old_keyboard_support ;JP9009
  1623. leave_it_to_common_method_1: ;JP9009
  1624. mov ah, al ; ah = al = 'make' scan code ;JP9009
  1625. mov cs:scan_code, al; Set this because we don't know;JP9009
  1626. ; who will use it later. ;JP9009
  1627. leave_it_to_common_method: ;JP9009
  1628. ret ;JP9009
  1629. DBCS_keyboard_support endp ;JP9009
  1630. ;JP9009
  1631. PSEUDO_SC_ALPHANUMERIC equ 7eh ;JP9009
  1632. PSEUDO_SC_HIRAGANA equ 7fh ;JP9009
  1633. ;JP9009
  1634. DBCS_keyboard_common_support proc near ;JP9009
  1635. ; Check if it is the Alphanumeric key or Kanji NO key ;JP9009
  1636. ; of the DBCS new keyboard. ;JP9009
  1637. cmp al, 3ah ; CAPS key ? ;JP9009
  1638. jne leave_it_to_common_method_2 ; if not ;JP9009
  1639. mov cx,cs:SD.KEYB_TYPE ;QFESP4
  1640. and cx,07h
  1641. cmp cx,2 ; 106 kbd?
  1642. jz check_key_status
  1643. cmp cx,3 ; IBM-5576 002/003 kbd?
  1644. jz check_key_status
  1645. cmp cx,0 ; 101 kbd?
  1646. jnz leave_it_to_common_method_2
  1647. test bl,(ALT_SHIFT or CTL_SHIFT or LEFT_SHIFT or RIGHT_SHIFT)
  1648. jz leave_it_to_common_method_2
  1649. push bx
  1650. and bl,(ALT_SHIFT or CTL_SHIFT)
  1651. cmp bl,(ALT_SHIFT or CTL_SHIFT) ;press alt and ctl ?
  1652. pop bx
  1653. jz leave_it_to_common_method_2
  1654. jmp short convert_to_alphanumeric_2
  1655. check_key_status: ;QFESP4
  1656. test bl, ALT_SHIFT ;JP9009
  1657. jnz convert_to_alphanumeric ;JP9009
  1658. test bl, (LEFT_SHIFT or RIGHT_SHIFT) ;JP9009
  1659. jnz leave_it_to_common_method_2 ;JP9009
  1660. jmp short convert_to_alphanumeric_2 ;JP9009
  1661. convert_to_alphanumeric: ;JP9009
  1662. test cs:SD.KEYB_TYPE, DBCS_OLD_A_KB ;JP9009
  1663. jnz leave_it_to_common_method_2 ;JP9009
  1664. convert_to_alphanumeric_2: ;JP9009
  1665. mov al, PSEUDO_SC_ALPHANUMERIC ;JP9009
  1666. leave_it_to_common_method_2: ;JP9009
  1667. ret ;JP9009
  1668. DBCS_keyboard_common_support endp ;JP9009
  1669. ;JP9009
  1670. ;***********************************************************************;JP9009
  1671. ;* *;JP9009
  1672. ;* DBCS Old Keyboard Support *;JP9009
  1673. ;* *;JP9009
  1674. ;* The old DBCS keyboard unique scan codes is mapped to the *;JP9009
  1675. ;* temporary scan code. It is again mapped to the corresponding *;JP9009
  1676. ;* scan code/character code according the current shift staes. *;JP9009
  1677. ;* *;JP9009
  1678. ;***********************************************************************;JP9009
  1679. ;JP9009
  1680. DBCS_old_keyboard_support proc near ;JP9009
  1681. mov cx,cs:SD.KEYB_TYPE
  1682. and cx,07h
  1683. cmp cx,2 ; 106 kbd?
  1684. jz check_old_key_status
  1685. cmp cx,3 ; IBM-5576 002/003 kb?
  1686. jne not_right_ALT_nor_hiragana
  1687. check_old_key_status:
  1688. cmp al, 38h ;JP9009
  1689. jne not_right_ALT_nor_hiragana ;JP9009
  1690. test ds:KB_FLAG_3, LC_E0 ;JP9009
  1691. jz not_right_ALT_nor_hiragana ;JP9009
  1692. mov al, PSEUDO_SC_HIRAGANA ;JP9009
  1693. and ds:KB_FLAG_3, not LC_E0 ;JP9009
  1694. not_right_ALT_nor_hiragana: ;JP9009
  1695. ret ;JP9009
  1696. DBCS_old_keyboard_support endp ;JP9009
  1697. endif ; JAPAN
  1698. DOSTI proc near
  1699. FSTI
  1700. ret
  1701. DOSTI endp
  1702. DOCLI proc near
  1703. FCLI
  1704. ret
  1705. DOCLI endp
  1706. DOIRET:
  1707. FIRET
  1708. CODE ENDS
  1709. END