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.

1078 lines
28 KiB

  1. page ,160
  2. title mschar - character and clock devices
  3. ;
  4. ;----------------------------------------------------------------------------
  5. ;
  6. ;
  7. ; 26-Feb-1991 sudeepb Ported for NT DOSEm
  8. ;
  9. ;----------------------------------------------------------------------------
  10. ;
  11. .xlist
  12. include version.inc ; set build flags
  13. include biosseg.inc ; establish bios segment structure
  14. include msequ.inc
  15. include devsym.inc
  16. include ioctl.inc
  17. include vint.inc
  18. break macro
  19. endm
  20. include biosbop.inc
  21. include error.inc
  22. .list
  23. include msgroup.inc ; define Bios_Data segment
  24. extrn ptrsav:dword
  25. extrn altah:byte
  26. extrn keyrd_func:byte
  27. extrn keysts_func:byte
  28. extrn auxnum:word
  29. extrn auxbuf:byte
  30. extrn wait_count:word
  31. extrn printdev:byte
  32. extrn Old10:dword
  33. extrn spc_mse_int10:dword
  34. extrn int29Perf:dword
  35. ; close Bios_Data and open Bios_Code segment
  36. tocode
  37. extrn bc_cmderr:near
  38. extrn bc_err_cnt:near
  39. MODE_CTRLBRK equ 0ffh ; M013
  40. ;************************************************************************
  41. ;* *
  42. ;* device driver dispatch tables *
  43. ;* *
  44. ;* each table starts with a byte which lists the number of *
  45. ;* legal functions, followed by that number of words. Each *
  46. ;* word represents an offset of a routine in Bios_Code which *
  47. ;* handles the function. The functions are terminated with *
  48. ;* a near return. If carry is reset, a 'done' code is returned *
  49. ;* to the caller. If carry is set, the ah/al registers are *
  50. ;* returned as abnormal completion status. Notice that ds *
  51. ;* is assumed to point to the Bios_Data segment throughout. *
  52. ;* *
  53. ;************************************************************************
  54. public con_table
  55. con_table:
  56. db (((offset con_table_end) - (offset con_table) - 1)/2)
  57. dw bc_exvec ; 00 init
  58. dw bc_exvec ; 01
  59. dw bc_exvec ; 02
  60. dw bc_cmderr ; 03
  61. dw con_read ; 04
  62. dw con_rdnd ; 05
  63. dw bc_exvec ; 06
  64. dw con_flush ; 07
  65. dw con_writ ; 08
  66. dw con_writ ; 09
  67. dw bc_exvec ; 0a
  68. con_table_end:
  69. public prn_table
  70. prn_table label byte
  71. db (((offset prn_table_end) - (offset prn_table) -1)/2)
  72. dw bc_exvec ; 00 init
  73. dw bc_exvec ; 01
  74. dw bc_exvec ; 02
  75. dw bc_cmderr ; 03
  76. dw prn_input ; 04 indicate zero chars read
  77. dw z_bus_exit ; 05 read non-destructive
  78. dw bc_exvec ; 06
  79. dw bc_exvec ; 07
  80. dw prn_writ ; 08
  81. dw prn_writ ; 09
  82. dw prn_stat ; 0a
  83. dw bc_exvec ; 0b
  84. dw bc_exvec ; 0c
  85. dw prn_open ; 0d
  86. dw prn_close ; 0e
  87. dw bc_exvec ; 0f
  88. dw prn_tilbusy ; 10
  89. dw bc_exvec ; 11
  90. dw bc_exvec ; 12
  91. dw prn_genioctl ; 13
  92. dw bc_exvec ; 14
  93. dw bc_exvec ; 15
  94. dw bc_exvec ; 16
  95. dw bc_exvec ; 17
  96. dw bc_exvec ; 18
  97. dw prn_ioctl_query ; 19
  98. prn_table_end:
  99. public aux_table
  100. aux_table label byte
  101. db (((offset aux_table_end) - (offset aux_table) -1)/2)
  102. dw bc_exvec ; 00 - init
  103. dw bc_exvec ; 01
  104. dw bc_exvec ; 02
  105. dw bc_cmderr ; 03
  106. dw aux_read ; 04 - read
  107. dw aux_rdnd ; 05 - read non-destructive
  108. dw bc_exvec ; 06
  109. dw aux_flsh ; 07
  110. dw aux_writ ; 08
  111. dw aux_writ ; 09
  112. dw aux_wrst ; 0a
  113. aux_table_end:
  114. public tim_table
  115. tim_table label byte
  116. db (((offset tim_table_end) - (offset tim_table) -1)/2)
  117. dw bc_exvec ; 00
  118. dw bc_exvec ; 01
  119. dw bc_exvec ; 02
  120. dw bc_cmderr ; 03
  121. dw bc_cmderr ; 04
  122. dw z_bus_exit ; 05
  123. dw bc_exvec ; 06
  124. dw bc_exvec ; 07
  125. dw bc_cmderr ; 08
  126. dw bc_cmderr ; 09
  127. tim_table_end:
  128. ;************************************************************************
  129. ;* *
  130. ;* con_read - read cx bytes from keyboard into buffer at es:di *
  131. ;* *
  132. ;************************************************************************
  133. con_read proc near
  134. assume ds:Bios_Data,es:nothing
  135. jcxz con_exit
  136. con_loop:
  137. call chrin ;get char in al
  138. stosb ;store char at es:di
  139. loop con_loop
  140. con_exit:
  141. clc
  142. ret
  143. con_read endp
  144. ;************************************************************************
  145. ;* *
  146. ;* chrin - input single char from keyboard into al *
  147. ;* *
  148. ;* we are going to issue extended keyboard function, if *
  149. ;* supported. the returning value of the extended keystroke *
  150. ;* of the extended keyboard function uses 0e0h in al *
  151. ;* instead of 00 as in the conventional keyboard function. *
  152. ;* this creates a conflict when the user entered real *
  153. ;* greek alpha charater (= 0e0h) to distinguish the extended *
  154. ;* keystroke and the greek alpha. this case will be handled *
  155. ;* in the following manner: *
  156. ;* *
  157. ;* ah = 16h *
  158. ;* int 16h *
  159. ;* if al == 0, then extended code (in ah) *
  160. ;* else if al == 0e0h, then *
  161. ;* if ah <> 0, then extended code (in ah) *
  162. ;* else greek_alpha character. *
  163. ;* *
  164. ;* also, for compatibility reason, if an extended code is *
  165. ;* detected, then we are going to change the value in al *
  166. ;* from 0e0h to 00h. *
  167. ;* *
  168. ;************************************************************************
  169. chrin proc near
  170. assume ds:Bios_Data,es:nothing
  171. mov ah,keyrd_func ; set by msinit. 0 or 10h
  172. xor al,al
  173. xchg al,altah ;get character & zero altah
  174. or al,al
  175. jnz keyret
  176. int 16h ; do rom bios keyrd function
  177. alt10:
  178. or ax,ax ;check for non-key after break
  179. jz chrin
  180. cmp ax,7200h ;check for ctrl-prtsc
  181. jnz alt_ext_chk
  182. mov al,16
  183. jmp short keyret
  184. alt_ext_chk:
  185. ;**************************************************************
  186. ; if operation was extended function (i.e. keyrd_func != 0) then
  187. ; if character read was 0e0h then
  188. ; if extended byte was zero (i.e. ah == 0) then
  189. ; goto keyret
  190. ; else
  191. ; set al to zero
  192. ; goto alt_save
  193. ; endif
  194. ; endif
  195. ; endif
  196. cmp byte ptr keyrd_func,0
  197. jz not_ext
  198. cmp al,0e0h
  199. jnz not_ext
  200. or ah,ah
  201. jz keyret
  202. ifdef DBCS
  203. ifdef KOREA ; Keyl 1990/11/5
  204. cmp ah, 0f0h ; If hangeul code range then
  205. jb EngCodeRange1 ; do not modify any value.
  206. cmp ah, 0f2h
  207. jbe not_ext
  208. EngCodeRange1:
  209. endif ; KOREA
  210. endif ; DBCS
  211. xor al,al
  212. jmp short alt_save
  213. not_ext:
  214. or al,al ;special case?
  215. jnz keyret
  216. alt_save:
  217. mov altah,ah ;store special key
  218. keyret:
  219. ret
  220. chrin endp
  221. ;************************************************************************
  222. ;* *
  223. ;* con_rdnd - keyboard non destructive read, no wait *
  224. ;* *
  225. ;* pc-convertible-type machine: if bit 10 is set by the dos *
  226. ;* in the status word of the request packet, and there is no *
  227. ;* character in the input buffer, the driver issues a system *
  228. ;* wait request to the rom. on return from the rom, it returns *
  229. ;* a 'char-not-found' to the dos. *
  230. ;* *
  231. ;************************************************************************
  232. con_rdnd proc near
  233. assume ds:Bios_Data,es:nothing
  234. mov al,[altah]
  235. or al,al
  236. jnz rdexit
  237. mov ah,keysts_func ; keyboard i/o interrupt - get
  238. int 16h ; keystroke status (keysts_func)
  239. jnz gotchr
  240. ;
  241. ; pc-convertible checking is not needed on NTVDM
  242. ; if no key in buff return immediatly with busy status
  243. ;04-Aug-1992 Jonle
  244. ;
  245. ; cmp fhavek09,0
  246. ; jz z_bus_exit ; return with busy status if not k09
  247. ;
  248. ; les bx,[ptrsav]
  249. ; assume es:nothing
  250. ; test es:[bx].status,0400h ; system wait enabled?
  251. ; jz z_bus_exit ; return with busy status if not
  252. ;
  253. ; need to wait for ibm response to request for code
  254. ; on how to use the system wait call.
  255. ;
  256. ; mov ax,4100h ; wait on an external event
  257. ; xor bl,bl ; M055; wait for any event
  258. ; int 15h ; call rom for system wait
  259. z_bus_exit:
  260. stc
  261. mov ah,3 ; indicate busy status
  262. ret
  263. gotchr:
  264. or ax,ax
  265. jnz notbrk ;check for null after break
  266. mov ah,keyrd_func ; issue keyboard read function
  267. int 16h
  268. jmp con_rdnd ;and get a real status
  269. notbrk:
  270. cmp ax,7200h ;check for ctrl-prtsc
  271. jnz rd_ext_chk
  272. mov al,'P' and 1fh ; return control p
  273. jmp short rdexit
  274. rd_ext_chk:
  275. cmp keyrd_func,0 ; extended keyboard function?
  276. jz rdexit ; no. normal exit.
  277. cmp al,0e0h ; extended key value or greek alpha?
  278. jne rdexit
  279. ifdef DBCS
  280. ifdef KOREA
  281. cmp ah, 0f0h ; If hangeul code range then
  282. jb EngCodeRange ; do not modify any value.
  283. cmp ah, 0f2h
  284. jbe rdexit ; Keyl 90/11/5
  285. EngCodeRange:
  286. endif ; KOREA
  287. endif ; DBCS
  288. cmp ah,0 ; scan code exist?
  289. jz rdexit ; yes. greek alpha char.
  290. mov al,0 ; no. extended key stroke.
  291. ; change it for compatibility
  292. rdexit:
  293. les bx,[ptrsav]
  294. assume es:nothing
  295. mov es:[bx].media,al ; *** return keyboard character here
  296. bc_exvec:
  297. clc ; indicate normal termination
  298. ret
  299. con_rdnd endp
  300. ;************************************************************************
  301. ;* *
  302. ;* con_write - console write routine *
  303. ;* *
  304. ;* entry: es:di -> buffer *
  305. ;* cx = count *
  306. ;* *
  307. ;************************************************************************
  308. con_writ proc near
  309. assume ds:Bios_Data,es:nothing
  310. jcxz bc_exvec
  311. push es
  312. mov bx,word ptr [int29Perf]
  313. mov dx,word ptr [int29Perf+2] ;DX:BX is original INT 29h vector
  314. sub ax,ax
  315. mov es,ax
  316. cmp BX,es:[29h*4+0]
  317. jne con_lp1 ; if not the same do single int10s
  318. cmp DX,es:[29h*4+2]
  319. jne con_lp1 ; if not the same do single int10s
  320. mov bx,word ptr [spc_mse_int10]
  321. mov dx,word ptr [spc_mse_int10+2] ;DX:BX is original INT 10h vector
  322. cmp BX,es:[10h*4+0]
  323. jne con_lp1 ; if not the same do single int10s
  324. cmp DX,es:[10h*4+2]
  325. jne con_lp1 ; if not the same do single int10s
  326. pop es
  327. ; Sudeepb 21-Jul-1992: We know that no one has hooked in10 so we
  328. ; can optimize it by calling a private in1t10h which takes a full
  329. ; string, displays it with the same attribute as present on the
  330. ; screen and moves the cursor to the end.
  331. mov ax,46h ; sounds like a good flag value
  332. push ax ; make an iret frame
  333. push cs
  334. mov ax, offset ret_adr
  335. push ax
  336. push dx ; dx:bx is pointing to softpc int10 handler
  337. push bx ; make the retf frame
  338. mov ax,13FFh ; AH = WRITESTRING, AL = subfunction
  339. retf
  340. ret_adr:
  341. jmp short cc_ret
  342. con_lp1:
  343. pop es
  344. con_lp:
  345. mov al,es:[di] ;get char
  346. inc di
  347. int chrout ;output char
  348. loop con_lp ;repeat until all through
  349. cc_ret:
  350. clc
  351. ret
  352. con_writ endp
  353. ;************************************************************************
  354. ;* *
  355. ;* con_flush - flush out keyboard queue *
  356. ;* *
  357. ;************************************************************************
  358. public con_flush ; called from msbio2.asm for floppy swapping
  359. con_flush proc near
  360. assume ds:Bios_Data,es:nothing
  361. mov [altah],0 ;clear out holding buffer
  362. ; while (charavail()) charread();
  363. flloop:
  364. mov ah,1 ; command code for check status
  365. int 16h ; call rom-bios keyboard routine
  366. jz cc_ret ; return carry clear if none
  367. xor ah,ah ; if zf is nof set, get character
  368. int 16h ; call rom-bios to get character
  369. jmp flloop
  370. con_flush endp
  371. ;************************************************************************
  372. ;* *
  373. ;* some equates for rom bios printer i/o *
  374. ;* *
  375. ;************************************************************************
  376. ; ibm rom status bits (i don't trust them, neither should you)
  377. ; warning!!! the ibm rom does not return just one bit. it returns a
  378. ; whole slew of bits, only one of which is correct.
  379. notbusystatus = 10000000b ; not busy
  380. nopaperstatus = 00100000b ; no more paper
  381. prnselected = 00010000b ; printer selected
  382. ioerrstatus = 00001000b ; some kinda error
  383. timeoutstatus = 00000001b ; time out.
  384. noprinter = 00110000b ; no printer attached
  385. ;************************************************************************
  386. ;* *
  387. ;* prn_input - return with no error but zero chars read *
  388. ;* *
  389. ;* enter with cx = number of characters requested *
  390. ;* *
  391. ;************************************************************************
  392. prn_input proc near
  393. assume ds:Bios_Data,es:nothing
  394. call bc_err_cnt ; reset count to zero (sub reqpkt.count,cx)
  395. clc ; but return with carry reset for no error
  396. ret
  397. prn_input endp
  398. ;************************************************************************
  399. ;* *
  400. ;* prn_writ - write cx bytes from es:di to printer device *
  401. ;* *
  402. ;* auxnum has printer number *
  403. ;* *
  404. ;************************************************************************
  405. prn_writ proc near
  406. assume ds:Bios_Data,es:nothing
  407. jcxz prn_done ;no chars to output
  408. prn_loop:
  409. mov bx,2 ;retry count
  410. prn_out:
  411. call prnstat ; get status
  412. jnz TestPrnError ; error
  413. mov al,es:[di] ; get character to print
  414. xor ah,ah
  415. call prnop ; print to printer
  416. jz prn_con ; no error - continue
  417. cmp ah, MODE_CTRLBRK ; M013
  418. jne @f ; M013
  419. mov al, error_I24_gen_failure ; M013
  420. mov altah, 0 ; M013
  421. jmp short pmessg ; M013
  422. @@:
  423. test ah,timeoutstatus
  424. jz prn_con ; not time out - continue
  425. TestPrnError:
  426. dec bx ;retry until count is exhausted.
  427. jnz prn_out
  428. pmessg:
  429. jmp bc_err_cnt ; return with error
  430. ; next character
  431. prn_con:
  432. inc di ;point to next char and continue
  433. loop prn_loop
  434. prn_done:
  435. clc
  436. ret
  437. prn_writ endp
  438. ;************************************************************************
  439. ;* *
  440. ;* prn_stat - device driver entry to return printer status *
  441. ;* *
  442. ;************************************************************************
  443. prn_stat proc near
  444. call prnstat ;device in dx
  445. jnz pmessg ; other errors were found
  446. test ah,notbusystatus
  447. jnz prn_done ;no error. exit
  448. jmp z_bus_exit ; return busy status
  449. prn_stat endp
  450. ;************************************************************************
  451. ;* *
  452. ;* prnstat - utilty function to call ROM BIOS to check *
  453. ;* printer status. Return meaningful error code *
  454. ;* *
  455. ;************************************************************************
  456. prnstat proc near
  457. assume ds:Bios_Data,es:nothing
  458. mov ah, 2 ; set command for get status
  459. prnstat endp ; fall into prnop
  460. ;************************************************************************
  461. ;* *
  462. ;* prnop - call ROM BIOS printer function in ah *
  463. ;* return zero true if no error *
  464. ;* return zero false if error, al = error code *
  465. ;* *
  466. ;************************************************************************
  467. prnop proc near
  468. assume ds:Bios_Data,es:nothing
  469. mov dx,[auxnum] ; get printer number
  470. int 17h ; call rom-bios printer routine
  471. ; This check was added to see if this is a case of no
  472. ; printer being installed. This tests checks to be sure
  473. ; the error is noprinter (30h)
  474. push ax ; M044
  475. and ah, noprinter ; M044
  476. cmp AH,noprinter ; Chk for no printer
  477. pop ax ; M044
  478. jne NextTest
  479. and AH,NOT nopaperstatus
  480. or AH,ioerrstatus
  481. ; examine the status bits to see if an error occurred. unfortunately, several
  482. ; of the bits are set so we have to pick and choose. we must be extremely
  483. ; careful about breaking basic.
  484. NextTest:
  485. test ah,(ioerrstatus+nopaperstatus) ; i/o error?
  486. jz checknotready ; no, try not ready
  487. ; at this point, we know we have an error. the converse is not true.
  488. mov al,error_I24_out_of_paper
  489. ; first, assume out of paper
  490. test ah,nopaperstatus ; out of paper set?
  491. jnz ret1 ; yes, error is set
  492. inc al ; return al=10 (i/o error)
  493. ret1:
  494. ret ; return with error
  495. checknotready:
  496. mov al,2 ; assume not-ready
  497. test ah,timeoutstatus ; is time-out set?
  498. ret ; if nz then error, else ok
  499. prnop endp
  500. ;************************************************************************
  501. ;* *
  502. ;* prn_open - send bop to disable auto-close, and wait for *
  503. ;* a DOS close *
  504. ;* *
  505. ;* inputs: *
  506. ;* outputs: BOP has been issued *
  507. ;* *
  508. ;************************************************************************
  509. prn_open proc near
  510. push si
  511. push dx
  512. push ds
  513. mov dx,40h
  514. mov ds,dx
  515. test word ptr ds:[FIXED_NTVDMSTATE_REL40], EXEC_BIT_MASK
  516. pop ds
  517. jnz po_nobop
  518. xor dh, dh
  519. mov dl, [printdev]
  520. or dl, dl
  521. jz @f
  522. dec dl
  523. @@:
  524. mov si,PRNIO_OPEN
  525. bop %BIOS_PRINTER_IO
  526. po_nobop:
  527. pop dx
  528. pop si
  529. ret
  530. prn_open endp
  531. ;************************************************************************
  532. ;* *
  533. ;* prn_close - send bop to close actual printer, and re-enable *
  534. ;* autoclose *
  535. ;* *
  536. ;* inputs: *
  537. ;* outputs: BOP has been issued *
  538. ;* *
  539. ;************************************************************************
  540. prn_close proc near
  541. push si
  542. push dx
  543. push ds
  544. mov dx,40h
  545. mov ds,dx
  546. test word ptr ds:[FIXED_NTVDMSTATE_REL40], EXEC_BIT_MASK
  547. pop ds
  548. jnz pc_nobop
  549. xor dh, dh
  550. mov dl, [printdev]
  551. or dl, dl
  552. jz @f
  553. dec dl
  554. @@:
  555. mov si,PRNIO_CLOSE
  556. bop %BIOS_PRINTER_IO
  557. pc_nobop:
  558. pop dx
  559. pop si
  560. ret
  561. prn_close endp
  562. ;************************************************************************
  563. ;* *
  564. ;* prn_tilbusy - output until busy. Used by print spooler. *
  565. ;* this entry point should never block waiting for *
  566. ;* device to come ready. *
  567. ;* *
  568. ;* inputs: cx = count, es:di -> buffer *
  569. ;* outputs: set the number of bytes transferred in the *
  570. ;* device driver request packet *
  571. ;* *
  572. ;************************************************************************
  573. prn_tilbusy proc near
  574. mov si,di ; everything is set for lodsb
  575. prn_tilbloop:
  576. push cx
  577. push bx
  578. xor bh,bh
  579. mov bl,[printdev]
  580. shl bx,1
  581. mov cx,wait_count[bx] ; wait count times to come ready
  582. pop bx
  583. prn_getstat:
  584. call prnstat ; get status
  585. jnz prn_bperr ; error
  586. test ah,10000000b ; ready yet?
  587. loopz prn_getstat ; no, go for more
  588. pop cx ; get original count
  589. jz prn_berr ; still not ready => done
  590. lods es:byte ptr [si]
  591. xor ah,ah
  592. call prnop
  593. jnz prn_berr ; error
  594. loop prn_tilbloop ; go for more
  595. clc ; normal no-error return
  596. ret ; from device driver
  597. prn_bperr:
  598. pop cx ; restore transfer count from stack
  599. prn_berr:
  600. jmp bc_err_cnt
  601. prn_tilbusy endp
  602. ;************************************************************************
  603. ;* *
  604. ;* prn_genioctl - get/set printer retry count *
  605. ;* *
  606. ;************************************************************************
  607. prn_genioctl proc near
  608. assume ds:Bios_Data,es:nothing
  609. les di,[ptrsav]
  610. cmp es:[di].majorfunction,ioc_pc
  611. jz prnfunc_ok
  612. prnfuncerr:
  613. jmp bc_cmderr
  614. prnfunc_ok:
  615. mov al,es:[di].minorfunction
  616. les di,es:[di].genericioctl_packet
  617. xor bh,bh
  618. mov bl,[printdev] ; get index into retry counts
  619. shl bx,1
  620. mov cx,wait_count[bx] ; pull out retry count for device
  621. cmp al,get_retry_count
  622. jz prngetcount
  623. cmp al,set_retry_count
  624. jnz prnfuncerr
  625. mov cx,es:[di].rc_count
  626. prngetcount:
  627. mov wait_count[bx],cx ; place "new" retry count
  628. mov es:[di].rc_count,cx ; return current retry count
  629. clc
  630. ret
  631. prn_genioctl endp
  632. ;************************************************************************
  633. ;* *
  634. ;* prn_ioctl_query *
  635. ;* *
  636. ;* Added for 5.00 *
  637. ;************************************************************************
  638. prn_ioctl_query PROC NEAR
  639. assume ds:Bios_Data,es:nothing
  640. les di,[ptrsav]
  641. cmp es:[di].majorfunction,ioc_pc
  642. jne prn_query_err
  643. mov al,es:[di].minorfunction
  644. cmp al,get_retry_count
  645. je IOCtlSupported
  646. cmp al,set_retry_count
  647. jne prn_query_err
  648. IOCtlSupported:
  649. clc
  650. ret
  651. prn_query_err:
  652. stc
  653. jmp BC_CmdErr
  654. prn_ioctl_query ENDP
  655. ;************************************************************************
  656. ;* *
  657. ;* aux port driver code -- "aux" == "com1" *
  658. ;* *
  659. ;* the device driver entry/dispatch code sets up auxnum to *
  660. ;* give the com port number to use (0=com1, 1=com2, 2=com3...) *
  661. ;* *
  662. ;************************************************************************
  663. ; values in ah, requesting function of int 14h in rom bios
  664. auxfunc_send equ 1 ;transmit
  665. auxfunc_receive equ 2 ;read
  666. auxfunc_status equ 3 ;request status
  667. ; error flags, reported by int 14h, reported in ah:
  668. flag_data_ready equ 01h ;data ready
  669. flag_overrun equ 02h ;overrun error
  670. flag_parity equ 04h ;parity error
  671. flag_frame equ 08h ;framing error
  672. flag_break equ 10h ;break detect
  673. flag_tranhol_emp equ 20h ;transmit holding register empty
  674. flag_timeout equ 80h ;timeout
  675. ; these flags reported in al:
  676. flag_cts equ 10h ;clear to send
  677. flag_dsr equ 20h ;data set ready
  678. flag_rec_sig equ 80h ;receive line signal detect
  679. ;************************************************************************
  680. ;* *
  681. ;* aux_read - read cx bytes from [auxnum] aux port to buffer *
  682. ;* at es:di *
  683. ;* *
  684. ;************************************************************************
  685. aux_read proc near
  686. assume ds:Bios_Data,es:nothing
  687. jcxz exvec2 ; if no characters, get out
  688. call getbx ; put address of auxbuf in bx
  689. xor al,al ; clear al register
  690. xchg al,[bx] ; get character , if any, from
  691. ; buffer and clear buffer
  692. or al,al ; if al is nonzero there was a
  693. ; character in the buffer
  694. jnz aux2 ; if so skip first auxin call
  695. aux1:
  696. call auxin ; get character from port
  697. ; ^^^^^ won't return if error
  698. aux2:
  699. stosb ; store character
  700. loop aux1 ; if more characters, go around again
  701. exvec2:
  702. clc ; all done, successful exit
  703. ret
  704. aux_read endp
  705. ;************************************************************************
  706. ;* *
  707. ;* auxin - call rom bios to read character from aux port *
  708. ;* if error occurs, map the error and return one *
  709. ;* level up to device driver exit code, setting *
  710. ;* the number of bytes transferred appropriately *
  711. ;* *
  712. ;************************************************************************
  713. ;
  714. ; M026 - BEGIN
  715. ;
  716. auxin proc near
  717. mov ah,auxfunc_receive
  718. call auxop ;check for frame, parity, or overrun errors
  719. ;warning: these error bits are unpredictable
  720. ; if timeout (bit 7) is set
  721. test ah, flag_frame or flag_parity or flag_overrun
  722. jnz arbad ; skip if any error bits set
  723. ret ; normal completion, ah=stat, al=char
  724. ; error getting character
  725. arbad:
  726. pop ax ; remove return address (near call)
  727. xor al,al
  728. or al,flag_rec_sig or flag_dsr or flag_cts
  729. jmp bc_err_cnt
  730. auxin endp
  731. IFDEF COMMENTEDOUT
  732. auxin proc near
  733. push cx
  734. mov cx, 20 ; number of retries on time out errors
  735. @@:
  736. mov ah,auxfunc_receive
  737. call auxop ;check for frame, parity, or overrun errors
  738. ;warning: these error bits are unpredictable
  739. ; if timeout (bit 7) is set
  740. test ah, flag_timeout
  741. jz no_timeout
  742. loop @b
  743. no_timeout:
  744. pop cx
  745. test ah, flag_timeout or flag_frame or flag_parity or flag_overrun
  746. jnz arbad ; skip if any error bits set
  747. ret ; normal completion, ah=stat, al=char
  748. ; error getting character
  749. arbad:
  750. pop ax ; remove return address (near call)
  751. xor al,al
  752. or al,flag_rec_sig or flag_dsr or flag_cts
  753. jmp bc_err_cnt
  754. auxin endp
  755. ENDIF
  756. ;
  757. ; M026 - END
  758. ;
  759. ;************************************************************************
  760. ;* *
  761. ;* aux_rdnd - non-destructive aux port read *
  762. ;* *
  763. ;************************************************************************
  764. aux_rdnd proc near
  765. assume ds:Bios_Data,es:nothing
  766. call getbx ; have bx point to auxbuf
  767. mov al,[bx] ; copy contents of buffer to al
  768. or al,al ; if al is non-zero (char in buffer)
  769. jnz auxrdx ; then return character
  770. call auxstat ; if not, get status of aux device
  771. test ah,flag_data_ready ; test data ready
  772. jz auxbus ; then device is busy (not ready)
  773. test al,flag_dsr ;test data set ready
  774. jz auxbus ; then device is busy (not ready)
  775. call auxin ; else aux is ready, get character
  776. mov [bx],al ; save character in buffer
  777. auxrdx:
  778. jmp rdexit ; return al in [packet.media]
  779. auxbus:
  780. jmp z_bus_exit ; return busy status
  781. aux_rdnd endp
  782. ;************************************************************************
  783. ;* *
  784. ;* aux_wrst - return aux port write status *
  785. ;* *
  786. ;************************************************************************
  787. aux_wrst proc near
  788. assume ds:Bios_Data,es:nothing
  789. call auxstat ; get status of aux in ax
  790. test al,flag_dsr ; test data set ready
  791. jz auxbus ; then device is busy (not ready)
  792. test ah,flag_tranhol_emp ;test transmit hold reg empty
  793. jz auxbus ; then device is busy (not ready)
  794. clc
  795. ret
  796. aux_wrst endp
  797. ;************************************************************************
  798. ;* *
  799. ;* auxstat - call rom bios to determine aux port status *
  800. ;* *
  801. ;* exit: ax = status *
  802. ;* dx = [auxnum] *
  803. ;* *
  804. ;************************************************************************
  805. auxstat proc near
  806. mov ah,auxfunc_status
  807. auxstat endp ; fall into auxop
  808. ;************************************************************************
  809. ;* *
  810. ;* auxop - perform rom-biox aux port interrupt *
  811. ;* *
  812. ;* entry: ah = int 14h function number *
  813. ;* exit: ax = results *
  814. ;* dx = [auxnum] *
  815. ;* *
  816. ;************************************************************************
  817. auxop proc near
  818. ;ah=function code
  819. ;0=init, 1=send, 2=receive, 3=status
  820. mov dx,[auxnum] ; get port number
  821. int 14h ; call rom-bios for status
  822. ret
  823. auxop endp
  824. ;************************************************************************
  825. ;* *
  826. ;* aux_flsh - flush aux input buffer - set contents of *
  827. ;* auxbuf [auxnum] to zero *
  828. ;* *
  829. ;* cas - shouldn't this code call the rom bios input function *
  830. ;* repeatedly until it isn't ready? to flush out any *
  831. ;* pending serial input queue if there's a tsr like MODE *
  832. ;* which is providing interrupt-buffering of aux port? *
  833. ;* *
  834. ;************************************************************************
  835. aux_flsh proc near
  836. call getbx ; get bx to point to auxbuf
  837. mov byte ptr [bx],0 ; zero out buffer
  838. clc ; all done, successful return
  839. ret
  840. aux_flsh endp
  841. ;************************************************************************
  842. ;* *
  843. ;* aux_writ - write to aux device *
  844. ;* *
  845. ;************************************************************************
  846. aux_writ proc near
  847. assume ds:Bios_Data ; set by aux device driver entry routine
  848. jcxz exvec2 ; if cx is zero, no characters
  849. ; to be written, jump to exit
  850. aux_loop:
  851. mov al,es:[di] ; get character to be written
  852. inc di ; move di pointer to next character
  853. mov ah,auxfunc_send ;value=1, indicates a write
  854. call auxop ;send character over aux port
  855. test ah,flag_timeout ;check for error
  856. jz awok ; then no error
  857. mov al,10 ; else indicate write fault
  858. jmp bc_err_cnt ; call error routines
  859. ; if cx is non-zero, still more
  860. awok:
  861. loop aux_loop ; more characrter to print
  862. clc ; all done, successful return
  863. ret
  864. aux_writ endp
  865. ;************************************************************************
  866. ;* *
  867. ;* getbx - return bx -> single byte input buffer for *
  868. ;* selected aux port ([auxnum]) *
  869. ;* *
  870. ;************************************************************************
  871. getbx proc near
  872. assume ds:Bios_Data,es:nothing
  873. mov bx,[auxnum]
  874. add bx,offset auxbuf
  875. ret
  876. getbx endp
  877. Bios_Code ends
  878. end