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

1651 lines
48 KiB

  1. page,132
  2. ifdef NEC_98
  3. .286p
  4. endif ; NEC_98
  5. ;---------------------------Module-Header-------------------------------;
  6. ; Module Name: IBMLPT.ASM
  7. ;
  8. ; Copyright (c) Microsoft Corporation 1985-1990. All Rights Reserved.
  9. ;
  10. ; General Description:
  11. ;
  12. ; History:
  13. ;
  14. ;-----------------------------------------------------------------------;
  15. title IBMLpt - IBM PC, PC-XT, PC-AT, PS/2 Parallel Communications Interface
  16. .xlist
  17. include cmacros.inc
  18. include comdev.inc
  19. include ins8250.inc
  20. include ibmcom.inc
  21. ifdef NEC_98
  22. include vint.inc
  23. endif ; NEC_98
  24. .list
  25. ifdef NEC_98
  26. sBegin Data ; (ins 93.03.28)
  27. InitRetry dw 0 ;LPT Retry count (ins 93.03.28)
  28. ModeFlag db 0 ; = 0 KAN-I SENTRO (ins 93.03.28)
  29. ; = 1 SENTRO (ins 93.03.28)
  30. ; <ins:Toki:930923>
  31. CurPrinterMode db 0 ; <ins:Toki:930923>
  32. OrgPrinterMode db 0 ; <ins:Toki:931013>
  33. ; <ins:Toki:930923>
  34. PC98_Mode = 00000000b ; <ins:Toki:930923>
  35. Toki_Mode = 00000001b ; <ins:Toki:930923>
  36. Org_Toki_ControlStatus db 0 ; <ins:Toki:931027>
  37. Org_Toki_EX_Control db 0 ; <ins:Toki:931027>
  38. ;
  39. Org_Toki_ControlStatus540 db 0 ; (ins 931219)
  40. Org_Toki_EX_Control540 db 0 ; (ins 931219)
  41. ; (ins 931219)
  42. Org_Toki_ControlStatusD40 db 0 ; (ins 931219)
  43. Org_Toki_EX_ControlD40 db 0 ; (ins 931219)
  44. ; (ins 931219)
  45. InitCounter db 0 ;Lpt initialize counter <ins 931028>
  46. ; <ins 931028>
  47. LptInit = 00000001b ; LPT Init OK ! <ins 931028>
  48. ;RFU = 00000010b ; <ins 931028>
  49. ;RFU = 00000100b ; <ins 931028>
  50. ;RFU = 00001000b ; <ins 931028>
  51. ;RFU = 00010000b ; <ins 931028>
  52. ;RFU = 00100000b ; <ins 931028>
  53. ;RFU = 01000000b ; <ins 931028>
  54. ;RFU = 10000000b ; <ins 931028>
  55. sEnd Data ; (ins 93.03.28)
  56. endif ; NEC_98
  57. sBegin Code
  58. assumes cs,Code
  59. assumes ds,Data
  60. externFP GetSystemMsecCount
  61. externA __0040H
  62. ifdef NEC_98
  63. ;-------------------------------------------------------------------------
  64. ; Printer Status Bit for IBM-PC
  65. ;-------------------------------------------------------------------------
  66. PS_NotBusy equ 10000000b ;Printer not busy
  67. PS_Ack equ 01000000b ;Data acknowledged
  68. PS_PaperOut equ 00100000b ;Out of paper
  69. PS_Select equ 00010000b ;Device is selected
  70. PS_IOError equ 00001000b ;IO error
  71. PS_Timeout equ 00000001b ;Timeout occured
  72. ;-------------------------------------------------------------------------
  73. ; Parameter for PC-9800
  74. ;-------------------------------------------------------------------------
  75. PRNStrobFF_ON = 0dh ; port_C Strob F/F on
  76. PRNStrobFF_OFF = 0ch ; port_C Strob F/F off
  77. SystemPort = 37h ; port_C I/O Address
  78. PRN_Mode = 46h ; Printer Mode
  79. PRN_WSignal = 46h ;
  80. PRN_RSignal = 42h ;
  81. PRN_WRITE_DATA equ 040h ;
  82. PRN_READ_SIGNAL1 equ 042h ;
  83. PRN_WRITE_SIGNAL1 equ 046h ;
  84. PRN_PSTB_Active_X2 equ 004h ;
  85. PRN_PSTB_NonActive_X2 equ 005h ;
  86. PRN_PSTB_Active_X1 equ 00eh ;
  87. PRN_PSTB_NonActive_X1 equ 00fh ;
  88. endif ; NEC_98
  89. ;----------------------------Private-Routine----------------------------;
  90. ;
  91. ; DoLPT - Do Function To LPT port
  92. ;
  93. ; The given function (output or reset) is performed to the
  94. ; passed LPT port.
  95. ;
  96. ; Before a character is sent, a check is made to see if the device
  97. ; will be able to accept the character. If it can, then the character
  98. ; will be sent. If not, then an error will be returned. If the
  99. ; printer is selected and busy and no error, then the code returned
  100. ; will be CE_TXFULL and the handshake bits will be set in HSFlag
  101. ; to simulate that a handshake was received.
  102. ;
  103. ; If the BIOS ROM code is examined, you will note that they wait for
  104. ; the busy character from the last charcater to be cleared before
  105. ; they strobe in the current character. This can take a long time
  106. ; on the standard EPSON class printer (1 mSec to greater than
  107. ; 300 mSec if the last character actually caused printing).
  108. ;
  109. ; Because of this, several status read retrys will be made before
  110. ; declaring that the device is actually busy. If only one status
  111. ; read is performed, the spooler will yeild, take a while to get
  112. ; back here, and things will be really slow. What difference does
  113. ; it really make if we or the BIOS does the delay, at least we can
  114. ; break out of it at some point when it seems hopeless.
  115. ;
  116. ; The OKIHACK: Okidata reports a 50 ns. 2.2 volt pulse on the paper
  117. ; out signal on the trailing edge of the Busy signal. If we see this
  118. ; glitch then we report paper out. So we try to get the status twice...
  119. ; if it changes between the two tries we keep getting the status.
  120. ;
  121. ;
  122. ; Entry:
  123. ; AH = cid
  124. ; AL = character to output
  125. ; CH = Function request. 0 = Output, 1 = Initialize, 2 = Status
  126. ; DS:SI -> DEB for the port
  127. ; Returns:
  128. ; AX = 0 if no errors occured
  129. ; Error Returns:
  130. ; AX = error code
  131. ; Registers Preserved:
  132. ; SI,DI
  133. ; Registers Destroyed:
  134. ; AX,BX,CX,DX,ES,FLAGS
  135. ; History:
  136. ;-----------------------------------------------------------------------;
  137. assumes ds,Data
  138. assumes es,nothing
  139. ifdef NEC_98
  140. iodelay macro ; <ins:Toki:930923>
  141. out 5fh, al ; <ins:Toki:930923>
  142. endm ; <ins:Toki:930923>
  143. endif ; NEC_98
  144. public DoLPT
  145. DoLPT proc near
  146. ifdef NEC_98
  147. cmp wo [si.Port], 00h ; (ins 931219)
  148. jz DoLPT98 ; <ins:Toki:930923>
  149. jmp Toki_DoLpt ; <ins:Toki:930923>
  150. else ; NEC_98
  151. mov dx,Port[si] ;Get port address
  152. ; DX = port address
  153. ; CH = operation: 0 = write, 1 = init, 2 = status
  154. ; AL = character
  155. or ch, ch
  156. jz LPT_OutChar
  157. cmp ch, 1
  158. jz LPT_Reset
  159. jmp LPT_GetStatus
  160. ret
  161. LPT_Reset:
  162. inc dx
  163. inc dx
  164. mov al, L_RESET
  165. iodelay
  166. out dx, al
  167. push dx
  168. cCall GetSystemMsecCount
  169. mov bx, ax
  170. LPT_ResetDelay:
  171. push bx
  172. cCall GetSystemMsecCount
  173. pop bx
  174. sub ax, bx
  175. cmp ax, 300 ; 1/3 sec as good as any
  176. jbe LPT_ResetDelay
  177. pop dx
  178. mov al, L_NORMAL
  179. iodelay
  180. iodelay
  181. out dx, al
  182. dec dx
  183. dec dx
  184. jmp LPT_GetStatus
  185. LPT_OutChar:
  186. push ax ; save character to be written
  187. ; first check to see if printer is ready for us
  188. push di
  189. push dx
  190. call GetSystemMSecCount
  191. mov di, ax
  192. pop dx
  193. LPT_WaitReady:
  194. inc dx ; point to status port
  195. iodelay
  196. in al, dx ; get status bits
  197. and al, L_BITS ; mask unused ones
  198. xor al, L_BITS_INVERT ; flip a couple
  199. xchg al, ah
  200. ifndef NOOKIHACK
  201. iodelay
  202. in al, dx
  203. dec dx
  204. and al, L_BITS
  205. xor al, L_BITS_INVERT
  206. cmp al, ah ; did any bits change?
  207. jnz LPT_WaitReady
  208. else
  209. dec dx
  210. endif
  211. test ah, PS_PaperOut or PS_IOError
  212. jnz LPT_PrinterNotReady
  213. test ah, PS_Select
  214. jz LPT_PrinterNotReady
  215. test ah, PS_NotBusy
  216. jnz LPT_PrinterReady
  217. push ax
  218. push dx
  219. call GetSystemMSecCount
  220. pop dx
  221. pop bx
  222. sub ax, di
  223. cmp ax, 300 ; 1/3 sec timeout
  224. jbe LPT_WaitReady
  225. ; The device seems to be selected and powered up, but is just
  226. ; busy (some printers seem to show selected but busy when they
  227. ; are taken offline). Show that the transmit queue is full and
  228. ; that the hold handshakes are set. This is so the windows
  229. ; spooler will retry (and do yields so that other apps may run).
  230. or ComErr[si],CE_TXFULL ;Show queue full
  231. mov ah,bh
  232. or ah, L_TIMEOUT
  233. LPT_PrinterNotReady:
  234. pop di
  235. pop cx ; throw away character
  236. jmp short LPT_ReturnStatus
  237. LPT_PrinterReady:
  238. pop di ; get di back
  239. pop ax ; get character back
  240. iodelay
  241. out dx, al ; write character to port
  242. inc dx ; access status port
  243. LPT_Strobe:
  244. inc dx ; control port
  245. mov al, L_STROBE ; set strobe high
  246. iodelay
  247. iodelay
  248. iodelay
  249. iodelay
  250. out dx, al ; ...
  251. mov al, L_NORMAL ;
  252. iodelay
  253. iodelay
  254. iodelay
  255. iodelay
  256. out dx, al ; set strobe low
  257. sub dx, 2 ; point back to port base
  258. ; FALL THRU
  259. LPT_GetStatus:
  260. inc dx ; point to status port
  261. LPT_GS1:
  262. iodelay
  263. iodelay
  264. in al, dx ; get status bits
  265. and al, L_BITS ; mask unused ones
  266. xor al, L_BITS_INVERT ; flip a couple
  267. mov ah, al
  268. ifndef NOOKIHACK
  269. in al, dx
  270. and al, L_BITS
  271. xor al, L_BITS_INVERT
  272. cmp al, ah
  273. jnz LPT_GS1 ; if they changed try again...
  274. endif
  275. LPT_ReturnStatus:
  276. assumes ds,Data
  277. and ax,(PS_PaperOut+PS_Select+PS_IOError+PS_Timeout)*256
  278. shr ah,1
  279. adc ah,al ;Get back Timeout bit
  280. xor ah,HIGH CE_DNS ;Invert selected bit
  281. .errnz LOW CE_DNS
  282. or by ComErr+1[si],ah ;Save comm error
  283. ret
  284. .errnz CE_PTO-0200h
  285. .errnz CE_IOE-0400h
  286. .errnz CE_DNS-0800h
  287. .errnz CE_OOP-1000h
  288. DoLPT40:
  289. assumes ds,Data
  290. or ComErr[si],CE_TXFULL ;Show queue full
  291. ret
  292. endif ; NEC_98
  293. DoLPT endp
  294. page
  295. ifdef NEC_98
  296. public DoLPT98
  297. DoLPT98 proc near
  298. push di ;Need some extra space
  299. mov di,[InitRetry] ;Initialize retry count = 0
  300. mov ah,ch ;Set function request
  301. DoLPT10:
  302. or ah,ah ;If reset
  303. jnz DoLPT50 ; skip status pre-read
  304. ;-------------------------------------------------------------------------
  305. ;output data to printer
  306. ;-------------------------------------------------------------------------
  307. xchg ax,cx ;CX = output data
  308. DoLPT20:
  309. ;-------------------------------------------------------------------------
  310. ; switch (AH) {
  311. ; 0: Output Data
  312. ; 1: Initialize Printer
  313. ; 2: Read Printer Status
  314. ; }
  315. ;-------------------------------------------------------------------------
  316. mov ah,2 ;
  317. call PrinterCall ; read status
  318. ;-------------------------------------------------------------------------
  319. ;(91.1.7) AH = (B)(A)(P)(S)|(F)(0)(0)(T)
  320. ; [IBM Printer Status] | | | | | |
  321. ; PS_NotBusy = 10000000b ------------+ | | | | |
  322. ; PS_Ack = 01000000b ---------------+ | | | |
  323. ; PS_PaperOut = 00100000b ------------------+ | | |
  324. ; PS_Select = 00010000b ---------------------+ | |
  325. ; PS_IOError = 00001000b -------------------------+ |
  326. ; PS_Timeout = 00000001b ----------------------------------+
  327. ;-------------------------------------------------------------------------
  328. test ah,PS_PaperOut+PS_IOError ;
  329. jnz DoLPT60 ;paper empty or I/O error
  330. test ah,PS_Select
  331. jz DoLPT60 ;error if not select
  332. or ah,ah
  333. js DoLPT40 ;output data if not busy
  334. dec di
  335. jnz DoLPT20 ;until initialize retry count =0
  336. DoLPT30: ;select & busy & retry count=0
  337. or ComErr[si],CE_TXFULL ;Show queue full
  338. or ah, PS_Timeout ;Show timeout
  339. jmp short DoLPT60 ; goto EVENT Create
  340. DoLPT40: ;
  341. xchg ax,cx ;AX = output data
  342. DoLPT50:
  343. ;-------------------------------------------------------------------------
  344. ; switch (AH) {
  345. ; 0: Output Data
  346. ; 1: Initialize Printer
  347. ; 2: Read Printer Status
  348. ; }
  349. ;-------------------------------------------------------------------------
  350. call PrinterCall ;Let the BIOS do the work
  351. ;-------------------------------------------------------------------------
  352. ;(91.1.7) AH = (B)(A)(P)(S)|(F)(0)(0)(T)
  353. ; [IBM Printer Status] | | | | | |
  354. ; PS_NotBusy = 10000000b ------------+ | | | | |
  355. ; PS_Ack = 01000000b ---------------+ | | | |
  356. ; PS_PaperOut = 00100000b ------------------+ | | |
  357. ; PS_Select = 00010000b ---------------------+ | |
  358. ; PS_IOError = 00001000b -------------------------+ |
  359. ; PS_Timeout = 00000001b ----------------------------------+
  360. ;-------------------------------------------------------------------------
  361. DoLPT60:
  362. and ax,(PS_PaperOut+PS_Select+PS_IOError+PS_Timeout)*256 ; 1.
  363. shr ah,1 ; 2.
  364. adc ah,al ;Get back Timeout bit 3.
  365. shr ah,1 ; 4.
  366. adc ah,al ;Get back Timeout bit 5.
  367. shl ah,1 ; 6.
  368. xor ah,HIGH CE_DNS ;Invert selected bit 7.
  369. ;-------------------------------------------------------------------
  370. ; <<Explain of 1.2.3.4.5.6.7.>> ; _ <AH> <AL>
  371. ; ; BAPS|F00T ????|????
  372. ; 1. and ax,(PS_Pa..+..)*256 ; 00PS|F00T 0000|0000
  373. ; 2. shr ah,1 ; 000P|SF00 0000|0000 CY=(T)
  374. ; 3. adc ah,al ; 000P|SF0T 0000|0000
  375. ; 4. shr ah,1 ; 0000|PSF0 0000|0000 CY=(T)
  376. ; 5. adc ah,al ; 0000|PSFT 0000|0000
  377. ; 6. shl ah, 1 ; 000P|SFT0 0000|0000
  378. ; 7. xor ah,HIGH CE_DNS ; 000P|SFT0 0000|0000
  379. ; | |||
  380. ; CE_OOP equ 1000h ------------------+ |||
  381. ; CE_DNS equ 0800h --------------------+||
  382. ; CE_IOE equ 0400h ---------------------+|
  383. ; CE_PTO equ 0200h ----------------------+
  384. ;-------------------------------------------------------------------
  385. test ah, high(CE_TXFULL or CE_OOP or CE_DNS or CE_IOE )
  386. jz DoLPT70 ;No error occured
  387. or by ComErr+1[si],ah ;Save comm error
  388. test by EvtMask+1[si],HIGH EV_PErr ;Printer error event request?
  389. jz DoLPT70 ; No
  390. or by EvtWord+1[si],HIGH EV_PErr ; Yes, show event occured
  391. DoLPT70:
  392. pop di
  393. ret
  394. DoLPT98 endp
  395. page
  396. ;-----------------------------------------------------------------------
  397. ; Open LPT
  398. ;-----------------------------------------------------------------------
  399. public INT_1AH_call
  400. INT_1AH_call proc near
  401. ;-(931219)-----------------------------------------------------------------
  402. ; Check H/W environment, and set correct I/O address to [si.Port].
  403. ;
  404. ; +---------------------------------------+--------------------+
  405. ; | | [si.Port] |
  406. ; | H/W environment |--------------------|
  407. ; | | LPT1 | LPT2 | LPT3 |
  408. ; +---------------------------------------+--------------------+
  409. ; |1|Standard Machine | 000h | -1 | -1 |
  410. ; |2|Standard Machine+Ex board(LPT1/2) | 540h | d40h | -1 |
  411. ; |3| (LPT2/3) | 000h | 540h | d40h |
  412. ; |4|TOKI on board | 140h | -1 | -1 |
  413. ; |4|TOKI on board (LPT1 KAN-I)| 000h | -1 | -1 |
  414. ; |5|TOKI on board + Ex board | 140h | 540h | d40h |
  415. ; |5|TOKI on board + Ex board (LPT1 KAN-I)| 000h | 540h | d40h |
  416. ; +---------------------------------------+--------------------+
  417. ; 000h -> compatible H/W, -1 -> no H/W
  418. ;
  419. ; [CurPrinterMode]
  420. ; PC98_Mode = 00000000b -> Standard Machine, no Ex board
  421. ; Toki_Mode = 00000001b -> TOKI on board
  422. ; ExToki_12 = 00000010b -> Ex LPT=LPT1/2
  423. ; ExToki_23 = 00000100b -> Ex LPT=LPT2/3
  424. ; ExToki_Available = (ExToki_12 or ExToki_23)
  425. ;
  426. ; ENTER: DS:SI -> ComDEB
  427. ;
  428. ; Toki_BasePort �� 0140h ; Base I/O Address
  429. ; Toki_DataLatch �� 0140h ; Data Port
  430. ; Toki_PrinterStatus �� 0141h ; Status Port
  431. ; Toki_PrinterControls �� 0142h ; Control Port
  432. ; Toki_ControlStatus �� 0149h ; Control Status Port
  433. ; Toki_EX_Control �� 014eh ; Ex Control Port
  434. ;
  435. ; BIOS Common Area [0:458h] Full SENTRO if Bit1=1
  436. ; BIOS Common Area [0:5B3h] TOKI on board if Bit7=1
  437. cmp by [si.DCB_Id], ID_LPT1 ; LPT1 ? (ins 931219)
  438. jne LPT2_TokiSetup ; �@�@N: NEXT (ins 931219)
  439. ; (ins 931219)
  440. push ds ; <ins:Toki:931027>
  441. mov ax, 40h ; BIOS Common Area <ins:Toki:931027>
  442. mov ds, ax ; <ins:Toki:931027>
  443. test by ds:[1b3h], 10000000b ; TOKI if bit7=1 <ins:Toki:931027>
  444. pop ds ;
  445. mov wo [si.Port], 140h ; (ins 931219)
  446. jz @f ; N: NEXT (ins 931219)
  447. jmp LPT1_TokiSetup ; Y: TOKI I/O (ins 931219)
  448. ; -> LPT1=TOKI on board (ins 931219)
  449. @@: ; (ins 931219)
  450. mov dx, Toki_ControlStatus+400h ; (ins 931219)
  451. in al, dx ; (ins 931219)
  452. cmp al, 0ffh ; Is there Ex board ? (ins 931219)
  453. mov wo [si.Port], 00h ; (ins 931219)
  454. jne @f ; Y: NEXT (ins 931219)
  455. jmp PrePrinterCall ; N: standard I/O (ins 931219)
  456. ; -> LPT1=KAN-I on board(ins 931219)
  457. @@: ; (ins 931219)
  458. mov dx, 54fh ; (ins 931219)
  459. in al, dx ; (ins 931219)
  460. test al, 00000100b ; Ex board = LPT1/2 ? (ins 931219)
  461. mov wo [si.Port], 00h ; (ins 931219)
  462. jz @f ; Y: Ex board I/O (ins 931219)
  463. ; -> LPT1=CH1 (ins 931219)
  464. jmp PrePrinterCall ; N: Standard I/O (ins 931219)
  465. ; -> LPT1=KAN-I on board(ins 931219)
  466. @@: ; (ins 931219)
  467. ;-------------------------------------------------------------------
  468. ; Initialize Ex 1CH(Port 054xh)
  469. ;-------------------------------------------------------------------
  470. mov wo [si.Port], 540h ; (ins 931219)
  471. Init_Port540h: ; (ins 931219)
  472. mov dx, Toki_ControlStatus+400h; (ins 931219)
  473. in al, dx ; (ins 931219)
  474. mov [Org_Toki_ControlStatus540], al; Save Control Status(ins 931219)
  475. mov dx, Toki_EX_Control+400h; (ins 931219)
  476. in al, dx ; (ins 931219)
  477. mov [Org_Toki_EX_Control540], al; Save Ex Control (ins 931219)
  478. mov dx, Toki_ControlStatus+400h ; AT Standard mode (ins 931219)
  479. mov al, 00010000b ; Normal Speed (ins 931219)
  480. out dx, al ; (ins 931219)
  481. iodelay ; (ins 931219)
  482. mov dx, Toki_EX_Control+400h ; AT Standard mode (ins 931219)
  483. mov al, 00010100b ; S/W Control (ins 931219)
  484. out dx, al ; (ins 931219)
  485. iodelay ; (ins 931219)
  486. mov dx,Toki_PrinterControls+400h; Select Printer (ins 931219)
  487. mov al, 00001100b ; nothing to initialize (ins 931219)
  488. out dx, al ; (ins 931219)
  489. ret ; (ins 931219)
  490. LPT2_TokiSetup:
  491. cmp by [si.DCB_Id], ID_LPT2 ; LPT2 ? (ins 931219)
  492. jne LPT3_TokiSetup ; N: NEXT (ins 931219)
  493. mov dx, Toki_ControlStatus+400h ; (ins 931219)
  494. in al, dx ; (ins 931219)
  495. cmp al, 0ffh ; Is there Ex board ? (ins 931219)
  496. mov wo [si.Port], -1 ; (ins 931219)
  497. jne @f ; Y: NEXT (ins 931219)
  498. ret ; N: Error (ins 931219)
  499. @@: ; (ins 931219)
  500. mov dx, 54fh ; (ins 931219)
  501. in al, dx ; (ins 931219)
  502. test al, 00000100b ; Ex board=LPT2/3 ? (ins 931219)
  503. mov wo [si.Port], 540h ; (ins 931219)
  504. jnz Init_Port540h ; Y: Init CH1 Port (ins 931219)
  505. ; -> LPT2=CH1 (ins 931219)
  506. ; N: Init CH2 Port (ins 931219)
  507. ; -> LPT2=CH2 (ins 931219)
  508. ;-------------------------------------------------------------------
  509. ; Initialize Ex 2CH(Port 0d4xh)
  510. ;-------------------------------------------------------------------
  511. mov wo [si.Port], 0d40h ; (ins 931219)
  512. Init_PortD40h: ; (ins 931219)
  513. mov dx, Toki_ControlStatus+0c00h; (ins 931219)
  514. in al, dx ; (ins 931219)
  515. mov [Org_Toki_ControlStatusD40], al; Save Control Status(ins 931219)
  516. mov dx, Toki_EX_Control+0c00h; (ins 931219)
  517. in al, dx ; (ins 931219)
  518. mov [Org_Toki_EX_ControlD40], al; Save Ex Control (ins 931219)
  519. mov dx, Toki_ControlStatus+0c00h; AT Standard mode (ins 931219)
  520. mov al, 00010000b ; Normal Speed (ins 931219)
  521. out dx, al ; (ins 931219)
  522. iodelay ; (ins 931219)
  523. mov dx, Toki_EX_Control+0c00h ; AT Standard mode (ins 931219)
  524. mov al, 00010100b ; S/W Control (ins 931219)
  525. out dx, al ; (ins 931219)
  526. iodelay ; (ins 931219)
  527. mov dx,Toki_PrinterControls+0c00h; Select Printer (ins 931219)
  528. mov al, 00001100b ; nothing to initialize (ins 931219)
  529. out dx, al ; (ins 931219)
  530. ret ; (ins 931219)
  531. LPT3_TokiSetup:
  532. mov dx, Toki_ControlStatus+0c00h; (ins 931219)
  533. in al, dx ; (ins 931219)
  534. cmp al, 0ffh ; Is there Ex board ? (ins 931219)
  535. mov wo [si.Port], -1 ; (ins 931219)
  536. jne @f ; Y: NEXT
  537. ret ; N: Error
  538. @@: ;
  539. mov dx, 54fh ; (ins 931219)
  540. in al, dx ; (ins 931219)
  541. test al, 00000100b ; Ex board=LPT2/3 ? (ins 931219)
  542. mov wo [si.Port], 0d40h ; (ins 931219)
  543. jnz Init_PortD40h ; Y: Init CH2 Port (ins 931219)
  544. ; -> LPT3=CH2 (ins 931219)
  545. mov wo [si.Port], -1 ; (ins 931219)
  546. ret ; (ins 931219)
  547. LPT1_TokiSetup: ; (ins 931219)
  548. ;----------------------------------------------------------------
  549. ; Save Status of TOKI
  550. ;----------------------------------------------------------------
  551. mov dx, Toki_ControlStatus ; <ins:Toki:931027>
  552. in al, dx ; <ins:Toki:931027>
  553. mov [Org_Toki_ControlStatus], al; Save Control Status <ins:Toki:931027>
  554. mov dx, Toki_EX_Control ; <ins:Toki:931027>
  555. in al, dx ; <ins:Toki:931027>
  556. mov [Org_Toki_EX_Control], al ; Save Ex Control <ins:Toki:931027>
  557. ;----------------------------------------------------------------
  558. ; Set Full SENTRO for checking cable
  559. ;----------------------------------------------------------------
  560. mov dx, Toki_ControlStatus ; AT Standard mode <ins:Toki:930923>
  561. mov al, 00010000b ; Normal Speed <ins:Toki:930923>
  562. out dx, al ; <ins:Toki:930923>
  563. iodelay ; <ins:Toki:930923>
  564. mov dx, Toki_EX_Control ; AT Standard mode <ins:Toki:930923>
  565. mov al, 00000000b ; S/W Control <ins:Toki:930923>
  566. out dx, al ; <ins:Toki:930923>
  567. ;----------------------------------------------------------------
  568. ; Check cable
  569. ;----------------------------------------------------------------
  570. mov dx, Toki_PrinterControls ; <ins:Toki:931027>
  571. in al, dx ; PrinterControls Read (ins 940224)
  572. and al, 11011111b ; Set DIR(=Foward) (ins 940224)
  573. out dx, al ; identification Sequence<ins:Toki:931027>
  574. mov dx, Toki_DataLatch ; of cable <ins:Toki:931027>
  575. mov al, 0 ; <ins:Toki:931027>
  576. out dx, al ; <ins:Toki:931027>
  577. mov dx, Toki_PrinterStatus ; <ins:Toki:931027>
  578. in al, dx ; <ins:Toki:931027>
  579. test al, 00000010b ; SENTRO cable(PowON)? <ins:Toki:931027>
  580. jnz TokiFullInit ; Y: Init as <ins:Toki:931027>
  581. ; Full SENTRO<ins:Toki:931027>
  582. mov dx, Toki_DataLatch ; N: NEXT <ins:Toki:931028>
  583. mov al, 80h ; <ins:Toki:931028>
  584. out dx, al ; <ins:Toki:931028>
  585. mov dx, Toki_PrinterStatus ; <ins:Toki:931028>
  586. in al, dx ; <ins:Toki:931028>
  587. test al, 00000010b ; SENTRO cable(PowOFF)? <ins:Toki:931028>
  588. jz TokiFullInit ; Y: Init as <ins:Toki:931028>
  589. ; Full SENTRO<ins:Toki:931028>
  590. ;----------------------------------------------------------------
  591. ; Initialize as KAN-I SENTRO
  592. ;----------------------------------------------------------------
  593. mov wo [si.Port], 0 ; (ins 931219)
  594. mov dx, Toki_ControlStatus ; <ins:Toki:931027>
  595. mov al, 0 ; <ins:Toki:931027>
  596. out dx, al ; N: KAN-I <ins:Toki:931027>
  597. jmp short PrePrinterCall ; <ins:94.05.26 >
  598. ; <ins:Toki:931013>
  599. ;----------------------------------------------------------------
  600. ; Initialize as Full SENTRO
  601. ;----------------------------------------------------------------
  602. TokiFullInit: ; <ins:Toki:931013>
  603. or [CurPrinterMode], Toki_Mode; <ins:Toki:930923>
  604. mov dx, Toki_ControlStatus ; AT Standard mode<ins:Toki:930923>
  605. mov al, 00010000b ; Normal Speed <ins:Toki:930923>
  606. out dx, al ; <ins:Toki:930923>
  607. iodelay ; <ins:Toki:930923>
  608. mov dx, Toki_EX_Control ; AT Standard mode<ins:Toki:930923>
  609. mov al, 00000000b ; S/W Control <ins:Toki:930923>
  610. out dx, al ; <ins:Toki:930923>
  611. iodelay ; <ins:Toki:930923>
  612. mov dx, Toki_PrinterControls; Select Printer<ins:Toki:930923>
  613. mov al, 00001100b ; nothing to initialize <ins:Toki:930923>
  614. out dx, al ; <ins:Toki:930923>
  615. ret ; <ins:Toki:930923>
  616. ; <ins:Toki:930923>
  617. INT_1AH_call endp
  618. ;-----------------------------------------------------------------------
  619. ; Close LPT
  620. ;-----------------------------------------------------------------------
  621. public INT_1AH_Close ; <ins:Toki:931013>
  622. INT_1AH_Close proc near ; <ins:Toki:931013>
  623. cmp wo[si.Port], 00h ; (ins 931219)
  624. jnz @f ; <ins:Toki:931013>
  625. ret ; <ins:Toki:931013>
  626. @@: ; <ins:Toki:931013>
  627. cmp wo [si.Port], 140h ; (ins 931219)
  628. jne @f ; (ins 931219)
  629. mov al,[Org_Toki_ControlStatus]; <ins:Toki:931027>
  630. mov dx, Toki_ControlStatus ; <ins:Toki:931027>
  631. out dx, al ; Restore Control Status<ins:Toki:931027>
  632. mov al,[Org_Toki_EX_Control] ; <ins:Toki:931027>
  633. mov dx, Toki_EX_Control ; <ins:Toki:931027>
  634. out dx, al ; Restore Ex Control <ins:Toki:931027>
  635. ret ; <ins:Toki:931013>
  636. @@:
  637. cmp wo [si.Port], 540h ; (ins 931219)
  638. jne @f ; (ins 931219)
  639. mov al,[Org_Toki_ControlStatus540]; (ins 931219)
  640. mov dx, Toki_ControlStatus+400h; (ins 931219)
  641. out dx, al ; Restore Control Status(ins 931219)
  642. ; (ins 931219)
  643. mov al,[Org_Toki_EX_Control540]; (ins 931219)
  644. mov dx, Toki_EX_Control+400h; (ins 931219)
  645. out dx, al ; Restore Ex Control (ins 931219)
  646. ret ; (ins 931219)
  647. @@: ; (ins 931219)
  648. mov al,[Org_Toki_ControlStatusD40]; (ins 931219)
  649. mov dx, Toki_ControlStatus+0c00h; (ins 931219)
  650. out dx, al ; Restore Control Status(ins 931219)
  651. ; (ins 931219)
  652. mov al,[Org_Toki_EX_ControlD40]; (ins 931219)
  653. mov dx, Toki_EX_Control+0c00h; (ins 931219)
  654. out dx, al ; Restore Ex Control (ins 931219)
  655. ret ; (ins 931219)
  656. INT_1AH_Close endp ; <ins:Toki:931013>
  657. public PrinterCall
  658. PrePrinterCall proc near
  659. test [InitCounter],LptInit ; LPT Init Finish ? XL <ins 931028>
  660. jz @f ; Yes: goto Return <ins 931028>
  661. ret ; <ins 931028>
  662. @@: ; <ins 931028>
  663. or [InitCounter],LptInit ; LPT Init Flag "ON" <ins 931028>
  664. mov ah,1 ; Printer Initialize <ins 931028>
  665. PrePrinterCall endp
  666. public PrinterCall
  667. PrinterCall proc near
  668. push bx
  669. push cx
  670. push dx
  671. or ah,ah ; switch (AH) {
  672. jnz @f ;
  673. call LPT_OutPut ; 0: Output Data
  674. jmp short End_INT1AH ;
  675. @@:
  676. dec ah ;
  677. jnz @f ;
  678. call LPT_Initialize ; 1: Initialize Printer
  679. jmp short End_INT1AH ;
  680. @@:
  681. dec ah ;
  682. jnz @f ;
  683. call LPT_GetStatus ; 2: Read Printer Status
  684. @@:
  685. End_INT1AH:
  686. pop dx
  687. pop cx
  688. pop bx
  689. ret
  690. PrinterCall endp
  691. ;---------------------------------------------------------------------------
  692. ; Output Data to Printer
  693. ;---------------------------------------------------------------------------
  694. public LPT_Output
  695. LPT_OutPut proc near
  696. mov dx,PRN_WRITE_DATA ;Set Printer Write Data Port
  697. out dx,al ;Data out
  698. mov dx,PRN_READ_SIGNAL1 ;Set Printer Status Port
  699. in al,dx ; Get Printer Status (ins 93.03.23)
  700. test al,(PS_NotBusy shr 5) ; if (status != Busy) (ins 93.03.23)
  701. jnz INT1AH13 ; yes : goto INT1AH13 (ins 93.03.23)
  702. INT1AH11: ;
  703. push dx ;
  704. call GetSystemMSecCount ; Get System Timer
  705. mov di, ax ; di = Tick Value
  706. pop dx ;
  707. ;
  708. INT1AH12: ;
  709. in al,dx ; Get Printer Status
  710. test al,(PS_NotBusy shr 5) ; if (status != Busy)
  711. jnz INT1AH13 ; yes : goto INT1AH13
  712. ;
  713. push dx ;
  714. call GetSystemMSecCount ;
  715. pop dx ;
  716. sub ax, di ;
  717. cmp ax, 300 ; 1/3 sec timeout
  718. jbe INT1AH12 ;
  719. ;
  720. cmp byte ptr [ModeFlag],0 ;### (ins 93.03.31)
  721. jnz INT1AH12_1 ;
  722. or al,061h
  723. and al,065h
  724. INT1AH12_1: ;
  725. call XlatStatus ;Locate bits
  726. or ah,PS_Timeout ;Show timeout
  727. and ah,(PS_NotBusy+PS_Ack+PS_PaperOut+PS_Select+PS_IOError+PS_Timeout)
  728. ret
  729. INT1AH13:
  730. cmp byte ptr [ModeFlag],0 ;### (ins 93.03.31)
  731. jnz INT1AH13_X2 ;
  732. INT1AH13_X1: ;
  733. FCLI ;
  734. mov dx,PRN_WRITE_SIGNAL1 ;Set Printer Status Port
  735. mov al,PRN_PSTB_Active_X1 ;Strobe High
  736. out dx,al
  737. NEWIODELAY 2 ;<OUT 5F,AL> (ins 92.11.11)
  738. mov al,PRN_PSTB_NonActive_X1 ;Strobe Low
  739. out dx,al
  740. call LPT_GetStatus
  741. ret
  742. INT1AH13_X2: ;
  743. FCLI ;
  744. mov dx,PRN_WRITE_SIGNAL1 ;Set Printer Status Port
  745. mov al,PRN_PSTB_Active_X2 ;Strobe High
  746. out dx,al
  747. NEWIODELAY 2 ;<OUT 5F,AL> (ins 92.11.11)
  748. mov al,PRN_PSTB_NonActive_X2;Strobe Low
  749. out dx,al
  750. call LPT_GetStatus
  751. ret
  752. LPT_OutPut endp
  753. ;---------------------------------------------------------------------------
  754. ; Read Printer Status
  755. ;---------------------------------------------------------------------------
  756. public LPT_GetStatus
  757. LPT_GetStatus proc near
  758. FSTI
  759. mov dx,PRN_READ_SIGNAL1 ;
  760. in al,dx ; Read Status
  761. cmp byte ptr [ModeFlag],0 ;(ins 93.03.31)####
  762. jnz INT1AH22 ;
  763. or al,061h
  764. and al,065h
  765. INT1AH22: ;
  766. jmp short XlatStatus ;(ins 93.03.31)####
  767. LPT_GetStatus endp
  768. ;---------------------------------------------------------------------------
  769. ; Locate Bits
  770. ; [ NES's Printer STATUS ]
  771. ; (7)(6)(5)(4)(3)(2)(1)(0)
  772. ; I I I I I I +-------------------- = 0: ACK
  773. ; I I I I I +-------------------------- = 0: BUSY
  774. ; I I I I +----------------------------- = 0: IBUSY
  775. ; I I I +-------------------------------- = 0: DC�5V
  776. ; I I +----------------------------------- = 0: PE
  777. ; I +-------------------------------------- = 0: FAULT
  778. ; +----------------------------------------- = 0: SELECT
  779. ;
  780. ; [IBM Printer Status]
  781. ; (B)(A)(P)(S)|(F)(0)(0)(T)
  782. ; | | | | | +------------------- = 1: PS_Timeout
  783. ; | | | | +---------------------------- = 1: PS_IOError
  784. ; | | | +-------------------------------- = 1: PS_Select
  785. ; | | +----------------------------------- = 1: PS_PaperOut
  786. ; | +-------------------------------------- = 1: PS_Ack
  787. ; +----------------------------------------- = 1: PS_NotBusy
  788. ;
  789. ;---------------------------------------------------------------------------
  790. public XlatStatus ;
  791. XlatStatus proc near ; <AH> <AL>
  792. mov ah,al ; ____ __ _
  793. and ah,11111101b ; SFP5|IB0A
  794. ; ____ ___
  795. inc ah ; SFP5|IBA?
  796. ; ___ ____
  797. shr ah,1 ; 0SFP|5IBA
  798. ; _ __ ____
  799. ror ah,1 ; A0SF|P5IB
  800. ; __ _ ____
  801. ror ah,1 ; BA0S|FP5I
  802. and ah,(PS_NotBusy+PS_Ack+PS_Select+PS_IOError);
  803. ; __ _ _
  804. ; BA0S|F000 _
  805. and al,PS_PaperOut ; ____ _ 00P0|0000
  806. or ah,al ; BAPS|F000
  807. xor ah,(PS_Ack+PS_PaperOut+PS_Select+PS_IOError)
  808. ; _
  809. ret ; BAPS|F000
  810. XlatStatus endp ;
  811. ;---------------------------------------------------------------------------
  812. ; Initialize Printer Port
  813. ;---------------------------------------------------------------------------
  814. public LPT_Initialize
  815. LPT_Initialize proc near
  816. ; Check Printer mode
  817. ; [out] ZF =0 = KAN-I SENTRO
  818. ; ZF !=0 = Full SENTRO
  819. call mode_check
  820. jnz INT1AH42 ;(ins 92.09.25)
  821. ret ;(ins 92.09.25)
  822. INT1AH42: ;(ins 92.09.25)
  823. push ax ; [8255 mode set]
  824. push cx ; I
  825. ; I
  826. mov al,PRNStrobFF_ON ; ____ I = 0dh
  827. out SystemPort,al ; PSTB mask 'ON'
  828. NEWIODELAY 10 ;<OUT 5F,AL> (ins 92.11.11)
  829. mov al,0a2h ; I
  830. out PRN_Mode,al ; mode set of SENTRO Interface
  831. NEWIODELAY 10 ;<OUT 5F,AL> (ins 92.11.11)
  832. mov al,05h ; I ____
  833. out PRN_Mode,al ; SENTRO Interface PSTB 'OFF'
  834. NEWIODELAY 10 ;<OUT 5F,AL> (ins 92.11.11)
  835. mov al,PRNStrobFF_OFF ; ____ I
  836. out SystemPort,al ; PSTB mask 'OFF
  837. NEWIODELAY 10 ;<OUT 5F,AL> (ins 92.11.11)
  838. xor ax,ax ; I
  839. out PRN_WSignal,al ; INPUT�PRIME 'ON' __________
  840. ; I I
  841. INT1AH45: ; I I
  842. mov cx,0 ; I I
  843. loop $ ; I I
  844. mov al,1 ; I I
  845. out PRN_WSignal,al ; INPUT�PRIME 'OFF' ---------
  846. NEWIODELAY 10 ;<OUT 5F,AL> (ins 92.11.11)
  847. mov al,0ch ; I
  848. out PRN_WSignal,al ; INTE Disable(Stop LPT Interrupt)
  849. mov cx,0 ; ____ I
  850. INT1AH47: ; BUSY Check
  851. in al,42h ; I
  852. test al,(PS_NotBusy shr 5) ; I
  853. loopz INT1AH47 ; I
  854. ;=======================================================================
  855. stc ; (ins 940115)
  856. push di ; (ins 940115)
  857. push dx ; We need to wait for (ins 940115)
  858. call GetSystemMSecCount ; reset process (ins 940115)
  859. mov di, ax ; if reset by port on (ins 940115)
  860. pop dx ; PC-PR602R. (ins 940115)
  861. @@: ; Then wait 1.5sec here. (ins 940115)
  862. push dx ; (ins 940115)
  863. call GetSystemMSecCount ; (ins 940115)
  864. pop dx ; (ins 940115)
  865. sub ax, di ; (ins 940115)
  866. cmp ax, 1500 ; (ins 940115)
  867. jbe @b ; (ins 940115)
  868. pop di ; (ins 940115)
  869. ;=======================================================================
  870. pop cx ; [ END ]
  871. pop ax
  872. INT1AH49:
  873. ret
  874. LPT_Initialize endp
  875. page
  876. endif ; NEC_98
  877. CheckStatus proc near
  878. ifdef NEC_98
  879. call LPT_GetStatus ;(ins 93.03.31)####
  880. and ah, L_BITS ;; #### 93.03.30 ####
  881. mov al, ah ;; #### 92.10.11 ####
  882. else ; NEC_98
  883. in al, dx ; get status bits
  884. mov ah, al
  885. and al, L_BITS ; mask unused ones
  886. xor al, L_BITS_INVERT ; flip a couple
  887. xchg al, ah
  888. ifndef NOOKIHACK
  889. iodelay
  890. in al, dx
  891. and al, L_BITS
  892. xor al, L_BITS_INVERT
  893. cmp al, ah ; did any bits change?
  894. jnz CheckStatus
  895. endif
  896. endif ; NEC_98
  897. test ah, PS_PaperOut or PS_IOError
  898. jz @F
  899. stc
  900. ret
  901. @@:
  902. test ah, PS_Select
  903. jnz @F
  904. stc
  905. ret
  906. @@:
  907. and ah, PS_NotBusy
  908. clc
  909. ret
  910. CheckStatus endp
  911. ;----------------------------Public Routine-----------------------------;
  912. ;
  913. ; StringToLPT - Send string To LPT Port
  914. ;
  915. ; Entry:
  916. ; DS:SI -> DEB
  917. ; ES:DI -> string to send
  918. ; CX = # of bytes to send
  919. ; Returns:
  920. ; AX = # of bytes actually sent
  921. ; Registers Destroyed:
  922. ; AX,BX,CX,DX,ES,FLAGS
  923. ; History:
  924. ;-----------------------------------------------------------------------;
  925. PUBLIC StringToLPT
  926. StringToLPT proc near
  927. ifdef NEC_98
  928. cmp wo[si.Port], 00h; (ins 931219)
  929. jz StringToLPT98 ; <ins:Toki:930923>
  930. jmp Toki_StringToLPT ; <ins:Toki:930923>
  931. else ; NEC_98
  932. mov dx, Port[si] ; get port address
  933. inc dx ; access status port
  934. push cx ; save count for later
  935. push ds
  936. mov bx, __0040H
  937. mov ds, bx
  938. cld
  939. call CheckStatus ; quick status check before slowness
  940. jc PrinterError
  941. jz PrinterBusy ; if printer not ready for first char
  942. ; then just return with CE_TXFULL
  943. CharacterToLPT:
  944. ;; mov bh, 10 ; will wait 10 clock tics (~ 1/2 sec)
  945. mov bh, 3 ; will wait 3 clock tics (~ 1/6 sec)
  946. l1:
  947. mov bl, ds:[006Ch] ; low byte of tic counter
  948. l2:
  949. call CheckStatus ; quick status check before slowness
  950. jc PrinterError
  951. jnz LPT_PrinterRdy
  952. cmp bl, ds:[006Ch]
  953. jz l2 ; tic count hasn't changed
  954. dec bh
  955. jz PrinterBusy ; out of tics, timeout
  956. jmp short l1
  957. LPT_PrinterRdy:
  958. mov al, es:[di]
  959. inc di
  960. dec dx ; point to data port
  961. out dx, al ; write character to port
  962. add dx, 2 ; access control port
  963. mov al, L_STROBE ; set strobe high
  964. out dx, al ; ...
  965. mov al, L_NORMAL ;
  966. iodelay
  967. iodelay
  968. out dx, al ; set strobe low
  969. dec dx ; point to status port for check
  970. loop CharacterToLPT
  971. pop ds
  972. jmp short LPT_Exit
  973. PrinterError:
  974. pop ds
  975. jmp short ReturnStatus
  976. PrinterBusy:
  977. pop ds
  978. or ComErr[si],CE_TXFULL ; set buffer full bit
  979. or al, L_TIMEOUT ; show timeout bit
  980. ReturnStatus:
  981. and ax,(PS_PaperOut+PS_Select+PS_IOError+PS_Timeout)
  982. xchg al, ah
  983. shr ah,1
  984. adc ah,al ;Get back Timeout bit
  985. xor ah,HIGH CE_DNS ;Invert selected bit
  986. .errnz LOW CE_DNS
  987. or by ComErr+1[si],ah ;Save comm error
  988. LPT_Exit:
  989. pop ax ; get total count
  990. sub ax, cx ; subtract remaining unsent charts
  991. ret
  992. endif ; NEC_98
  993. StringToLPT endp
  994. ifdef NEC_98
  995. PUBLIC StringToLPT98
  996. StringToLPT98 proc near
  997. push cx ; save count for (ins 92.09.28)
  998. push ds ; (ins 92.09.28)
  999. cld
  1000. CharacterToLPT:
  1001. mov dx, PRN_READ_SIGNAL1 ;Set Status Port (ins 93.03.31)####
  1002. in al, dx ;Get Status (ins 93.03.31)####
  1003. test al,(PS_NotBusy shr 5) ; if ( != Busy) (ins 93.03.31)####
  1004. jnz LPT_PrinterRdy ; yes : OUT Port (ins 93.03.31)####
  1005. push dx ;
  1006. call GetSystemMSecCount ; Get System Timer
  1007. mov bx, ax ; ax = Tick Value
  1008. pop dx ;
  1009. CharToLPT1:
  1010. push bx
  1011. call CheckStatus ; quick status check (ins 92.08.xx)
  1012. pop bx
  1013. jc PrinterError ; ## 92.10.11 ## (ins 92.08.xx)
  1014. jnz LPT_PrinterRdy ; (ins 92.08.xx)
  1015. CharToLPT2:
  1016. push ax
  1017. push dx ;
  1018. call GetSystemMSecCount ;
  1019. pop dx ;
  1020. sub ax, bx ;
  1021. cmp ax, 1000 ; ## 92.10.11 ## 1 sec timeout
  1022. pop ax
  1023. jbe CharToLPT1 ;
  1024. jmp short PrinterBusy ; (ins 92.08.xx)
  1025. LPT_PrinterRdy:
  1026. mov al, es:[di]
  1027. inc di
  1028. push ax ; (ins 92.10.01)
  1029. push di ; (ins 92.10.01)
  1030. call LPT_OutPut2 ;data out (ins 92.10.01)
  1031. pop di ; (ins 92.10.01)
  1032. pop ax ; (ins 92.10.01)
  1033. loop CharacterToLPT
  1034. pop ds
  1035. jmp short LPT_Exit
  1036. PrinterError:
  1037. pop ds
  1038. jmp short ReturnStatus
  1039. PrinterBusy:
  1040. pop ds
  1041. or ComErr[si],CE_TXFULL ; set buffer full bit
  1042. or al, L_TIMEOUT ; show timeout bit
  1043. ReturnStatus:
  1044. and ax,(PS_Select+PS_IOError+PS_Timeout) ;(ins 93.03.30)
  1045. xchg al, ah
  1046. shr ah,1
  1047. adc ah,al ;Get back Timeout bit
  1048. xor ah,HIGH CE_DNS ;Invert selected bit
  1049. .errnz LOW CE_DNS
  1050. or by ComErr+1[si],ah ;Save comm error
  1051. LPT_Exit:
  1052. pop ax ; get total count
  1053. sub ax, cx ; subtract remaining unsent charts
  1054. ret
  1055. StringToLPT98 endp
  1056. ;############ ins 93.03.28 #############
  1057. public LPT_OutPut2 ; (ins 93.03.30) [QN]
  1058. LPT_OutPut2 proc near ; (ins 93.03.28) [QN]
  1059. FCLI ; (ins 93.03.28) [QN]
  1060. mov dx,PRN_WRITE_DATA ;Set Write Port (ins 93.03.28) [QN]
  1061. out dx,al ;Data out (ins 93.03.28) [QN]
  1062. out 5fh, al ; (ins 93.04.03) [QN]
  1063. cmp byte ptr [ModeFlag],0 ; ####### (ins 93.03.31) [QN]
  1064. jnz LPT_OutPut2_X2 ; (ins 93.03.28) [QN]
  1065. ; (ins 93.03.28) [QN]
  1066. LPT_OutPut2_X1: ; (ins 93.03.28) [QN]
  1067. mov dx,PRN_WRITE_SIGNAL1 ; (ins 93.03.28) [QN]
  1068. mov al,PRN_PSTB_Active_X1 ;Strobe High (ins 93.03.28) [QN]
  1069. out dx,al ; (ins 93.03.28) [QN]
  1070. out 5fh, al ; (ins 93.04.03) [QN]
  1071. mov al,PRN_PSTB_NonActive_X1;Strobe Low (ins 93.03.28) [QN]
  1072. out dx,al ; (ins 93.03.28) [QN]
  1073. FSTI ; (ins 93.03.28) [QN]
  1074. ret ; (ins 93.03.28) [QN]
  1075. ; (ins 93.03.28) [QN]
  1076. LPT_OutPut2_X2: ; (ins 93.03.28) [QN]
  1077. mov dx,PRN_WRITE_SIGNAL1 ; (ins 93.03.28) [QN]
  1078. mov al,PRN_PSTB_Active_X2 ;Strobe High (ins 93.03.28) [QN]
  1079. out dx,al ; (ins 93.03.28) [QN]
  1080. out 5fh, al ; (ins 93.04.03) [QN]
  1081. mov al,PRN_PSTB_NonActive_X2;Strobe Low (ins 93.03.28) [QN]
  1082. out dx,al ; (ins 93.03.28) [QN]
  1083. FSTI ; (ins 93.03.28) [QN]
  1084. ret ; (ins 93.03.28) [QN]
  1085. LPT_OutPut2 endp ; (ins 93.03.28) [QN]
  1086. ;(ins 92.08.xx)
  1087. page
  1088. ;-------------------------------------------------------
  1089. ; Check Printer Mode
  1090. ;-------------------------------------------------------
  1091. ; [out] ZF == 0 = KAN-I SENTRO
  1092. ; ZF != 0 = Full SENTRO
  1093. ;-------------------------------------------------------
  1094. _X2_mode equ 00000100b ;
  1095. _NPC_check equ 10000000b ;
  1096. mode_check: ;
  1097. mov Byte ptr [ModeFlag],0 ;(ins 93.03.28)
  1098. push ax ;
  1099. push ds ;
  1100. mov ax,40H ;
  1101. mov ds,ax ;
  1102. test by ds:[58H],_NPC_check ;
  1103. pop ds ;
  1104. pop ax ;
  1105. jz NH_check ;Standard Machine
  1106. ;-------------------------------------
  1107. ; Hiper 98
  1108. ;-------------------------------------
  1109. call NH_check ;
  1110. jnz exit_mode_check ;Highreso for NPC
  1111. ;------------------------------------
  1112. ; Hiper 98 Normal Mode
  1113. ;------------------------------------
  1114. push ax ;
  1115. push dx ;
  1116. mov dx,448h ;
  1117. ;------------------------------------------------------
  1118. ;Read data of Ex mode register from 448h
  1119. ;bit0=1 : Full SENTRO, bit0=0 : KAN-I SENTRO
  1120. ;------------------------------------------------------
  1121. in al,dx ;
  1122. test al,1 ;
  1123. pop dx ;
  1124. pop ax ;
  1125. jz exit_mode_check ;(ins 93.03.28)
  1126. mov Byte ptr [ModeFlag],1 ;(ins 93.03.28)
  1127. ;(ins 93.03.28)
  1128. exit_mode_check:
  1129. ret ;
  1130. ;-------------------------------------------------------
  1131. ; Check Machine architecture
  1132. ;
  1133. ; [out] ZF =0 ... Normal
  1134. ; ZF !=0 ... Highreso
  1135. ;-------------------------------------------------------
  1136. bios_common equ 501h ;
  1137. _X2_system equ 00001000b ;
  1138. ;
  1139. NH_check:
  1140. push ax ;
  1141. push ds ;
  1142. ; 40H:[101H] bit3 (_X2_system)
  1143. ; =0 : Normal
  1144. ; =1 : Highreso
  1145. mov ax,40H ;
  1146. mov ds,ax ;
  1147. test by ds:[101H],_X2_system ;
  1148. pop ds ;
  1149. pop ax ;
  1150. jz @f ;(ins 93.03.28)
  1151. mov Byte ptr [ModeFlag],1 ;(ins 93.03.28)
  1152. @@: ;(ins 93.03.28)
  1153. ret ;
  1154. ;
  1155. mode_check2: ;(ins 93.03.28)
  1156. cmp byte ptr [ModeFlag],0 ;(ins 93.03.28)
  1157. ret ;(ins 93.03.28)
  1158. page
  1159. ;----------------------------Private-Routine----------------------------;
  1160. ; Toki_DoLPT - Do Function To LPT port
  1161. ;
  1162. ; Entry:
  1163. ; AH = cid
  1164. ; AL = character to output
  1165. ; CH = Function request. 0 = Output, 1 = Initialize, 2 = Status
  1166. ; DS:SI -> DEB for the port
  1167. ; Returns:
  1168. ; AX = 0 if no errors occured
  1169. ; Error Returns:
  1170. ; AX = error code
  1171. ; Registers Preserved:
  1172. ; SI,DI
  1173. ; Registers Destroyed:
  1174. ; AX,BX,CX,DX,ES,FLAGS
  1175. ; History:
  1176. ;-----------------------------------------------------------------------;
  1177. public Toki_DoLPT
  1178. Toki_DoLPT proc near
  1179. mov dx,Port[si] ;Get port address
  1180. ; DX = port address
  1181. ; CH = operation: 0 = write, 1 = init, 2 = status
  1182. ; AL = character
  1183. or ch, ch
  1184. jz Toki_LPT_OutChar
  1185. cmp ch, 1
  1186. jz Toki_LPT_Reset
  1187. jmp Toki_LPT_GetStatus
  1188. ret
  1189. Toki_LPT_Reset:
  1190. inc dx
  1191. inc dx
  1192. mov al, L_RESET
  1193. iodelay
  1194. out dx, al
  1195. push dx
  1196. cCall GetSystemMsecCount
  1197. mov bx, ax
  1198. Toki_LPT_ResetDelay:
  1199. push bx
  1200. cCall GetSystemMsecCount
  1201. pop bx
  1202. sub ax, bx
  1203. cmp ax, 300 ; 1/3 sec as good as any
  1204. jbe Toki_LPT_ResetDelay
  1205. pop dx
  1206. mov al, L_NORMAL
  1207. iodelay
  1208. iodelay
  1209. out dx, al
  1210. dec dx
  1211. dec dx
  1212. jmp short Toki_LPT_GetStatus
  1213. Toki_LPT_OutChar:
  1214. push ax ; save character to be written
  1215. ; first check to see if printer is ready for us
  1216. push di
  1217. push dx
  1218. call GetSystemMSecCount
  1219. mov di, ax
  1220. pop dx
  1221. Toki_LPT_WaitReady:
  1222. inc dx ; point to status port
  1223. iodelay
  1224. in al, dx ; get status bits
  1225. and al, L_BITS ; mask unused ones
  1226. xor al, L_BITS_INVERT ; flip a couple
  1227. xchg al, ah
  1228. ifndef NOOKIHACK
  1229. iodelay
  1230. in al, dx
  1231. dec dx
  1232. and al, L_BITS
  1233. xor al, L_BITS_INVERT
  1234. cmp al, ah ; did any bits change?
  1235. jnz Toki_LPT_WaitReady
  1236. else
  1237. dec dx
  1238. endif
  1239. test ah, PS_PaperOut or PS_IOError
  1240. jnz Toki_LPT_PrinterNotReady
  1241. test ah, PS_Select
  1242. jz Toki_LPT_PrinterNotReady
  1243. test ah, PS_NotBusy
  1244. jnz Toki_LPT_PrinterReady
  1245. push ax
  1246. push dx
  1247. call GetSystemMSecCount
  1248. pop dx
  1249. pop bx
  1250. sub ax, di
  1251. cmp ax, 300 ; 1/3 sec timeout
  1252. jbe Toki_LPT_WaitReady
  1253. ; The device seems to be selected and powered up, but is just
  1254. ; busy (some printers seem to show selected but busy when they
  1255. ; are taken offline). Show that the transmit queue is full and
  1256. ; that the hold handshakes are set. This is so the windows
  1257. ; spooler will retry (and do yields so that other apps may run).
  1258. or ComErr[si],CE_TXFULL ;Show queue full
  1259. mov ah,bh
  1260. or ah, L_TIMEOUT
  1261. Toki_LPT_PrinterNotReady:
  1262. pop di
  1263. pop cx ; throw away character
  1264. jmp short Toki_LPT_ReturnStatus
  1265. Toki_LPT_PrinterReady:
  1266. pop di ; get di back
  1267. pop ax ; get character back
  1268. iodelay
  1269. out dx, al ; write character to port
  1270. inc dx ; access status port
  1271. Toki_LPT_Strobe:
  1272. inc dx ; control port
  1273. mov al, L_STROBE ; set strobe high
  1274. iodelay
  1275. out dx, al ; ...
  1276. mov al, L_NORMAL ;
  1277. out dx, al ; set strobe low
  1278. sub dx, 2 ; point back to port base
  1279. ; FALL THRU
  1280. Toki_LPT_GetStatus:
  1281. inc dx ; point to status port
  1282. Toki_LPT_GS1:
  1283. iodelay
  1284. iodelay
  1285. in al, dx ; get status bits
  1286. and al, L_BITS ; mask unused ones
  1287. xor al, L_BITS_INVERT ; flip a couple
  1288. mov ah, al
  1289. ifndef NOOKIHACK
  1290. in al, dx
  1291. and al, L_BITS
  1292. xor al, L_BITS_INVERT
  1293. cmp al, ah
  1294. jnz Toki_LPT_GS1 ; if they changed try again...
  1295. endif
  1296. Toki_LPT_ReturnStatus:
  1297. assumes ds,Data
  1298. and ax,( PS_Select+PS_IOError+PS_Timeout)*256 ; (ins 940125)
  1299. shr ah,1
  1300. adc ah,al ;Get back Timeout bit
  1301. xor ah,HIGH CE_DNS ;Invert selected bit
  1302. .errnz LOW CE_DNS
  1303. or by ComErr+1[si],ah ;Save comm error
  1304. ret
  1305. .errnz CE_PTO-0200h
  1306. .errnz CE_IOE-0400h
  1307. .errnz CE_DNS-0800h
  1308. .errnz CE_OOP-1000h
  1309. Toki_DoLPT40:
  1310. assumes ds,Data
  1311. or ComErr[si],CE_TXFULL ;Show queue full
  1312. ret
  1313. Toki_DoLPT endp
  1314. page
  1315. Toki_CheckStatus proc near
  1316. in al, dx ; get status bits
  1317. test al, PS_PaperOut ; paper empty ? (ins 94.08.09)
  1318. jz @f ; N: Next (ins 94.08.09)
  1319. and al, not PS_IOError ; Y: Show I/O error (ins 94.08.09)
  1320. @@: ; (ins 94.08.09)
  1321. mov ah, al
  1322. and al, L_BITS ; mask unused ones
  1323. xor al, L_BITS_INVERT ; flip a couple
  1324. xchg al, ah
  1325. ifndef NOOKIHACK
  1326. iodelay
  1327. in al, dx
  1328. test al, PS_PaperOut ; paper empty ? (ins 94.08.09)
  1329. jz @f ; N: Next (ins 94.08.09)
  1330. and al, not PS_IOError ; Y: Show I/O error (ins 94.08.09)
  1331. @@: ; (ins 94.08.09)
  1332. and al, L_BITS
  1333. xor al, L_BITS_INVERT
  1334. cmp al, ah ; did any bits change?
  1335. jnz Toki_CheckStatus
  1336. endif
  1337. test ah, PS_PaperOut or PS_IOError
  1338. jz @F
  1339. stc
  1340. ret
  1341. @@:
  1342. test ah, PS_Select
  1343. jnz @F
  1344. stc
  1345. ret
  1346. @@:
  1347. and ah, PS_NotBusy
  1348. clc
  1349. ret
  1350. Toki_CheckStatus endp
  1351. ;----------------------------Public Routine-----------------------------;
  1352. ; Toki_StringToLPT - Send string To LPT Port
  1353. ;
  1354. ; Entry:
  1355. ; DS:SI -> DEB
  1356. ; ES:DI -> string to send
  1357. ; CX = # of bytes to send
  1358. ; Returns:
  1359. ; AX = # of bytes actually sent
  1360. ; Registers Destroyed:
  1361. ; AX,BX,CX,DX,ES,FLAGS
  1362. ; History:
  1363. ;-----------------------------------------------------------------------;
  1364. PUBLIC Toki_StringToLPT
  1365. Toki_StringToLPT proc near
  1366. mov dx, Port[si] ; get port address <del:Toki:930923>
  1367. inc dx ; access status port
  1368. push cx ; save count for later
  1369. push ds
  1370. cld
  1371. call Toki_CheckStatus ; quick status check before slowness
  1372. jc Toki_PrinterError
  1373. jz Toki_PrinterBusy ; if printer not ready for first char
  1374. ; then just return with CE_TXFULL
  1375. Toki_CharacterToLPT:
  1376. push dx ; <inc:Toki:930923>
  1377. call GetSystemMSecCount ; Get System Timer <inc:Toki:930923>
  1378. mov bx, ax ; ax = Tick Value <inc:Toki:930923>
  1379. pop dx ; <inc:Toki:930923>
  1380. ; <inc:Toki:930923>
  1381. Toki_CharToLPT1: ; <inc:Toki:930923>
  1382. push bx ; <inc:Toki:930923>
  1383. call Toki_CheckStatus ; quick status check <inc:Toki:930923>
  1384. pop bx ; <inc:Toki:930923>
  1385. jc Toki_PrinterError ; <inc:Toki:930923>
  1386. jnz Toki_LPT_PrinterRdy; <inc:Toki:930923>
  1387. ; <inc:Toki:930923>
  1388. Toki_CharToLPT2: ; <inc:Toki:930923>
  1389. push ax ; <inc:Toki:930923>
  1390. push dx ; <inc:Toki:930923>
  1391. call GetSystemMSecCount ; <inc:Toki:930923>
  1392. pop dx ; <inc:Toki:930923>
  1393. sub ax, bx ; <inc:Toki:930923>
  1394. cmp ax, 1000 ; 1 sec timeout <inc:Toki:930923>
  1395. pop ax ; <inc:Toki:930923>
  1396. jbe Toki_CharToLPT1 ; <inc:Toki:930923>
  1397. jmp short Toki_PrinterBusy ; <inc:Toki:930923>
  1398. ; <inc:Toki:930923>
  1399. Toki_LPT_PrinterRdy:
  1400. mov al, es:[di]
  1401. inc di
  1402. dec dx ; point to data port
  1403. out dx, al ; write character to port
  1404. add dx, 2 ; access control port
  1405. mov al, L_STROBE ; set strobe high
  1406. out dx, al ; ...
  1407. mov al, L_NORMAL ;
  1408. out dx, al ; set strobe low
  1409. dec dx ; point to status port for check
  1410. loop Toki_CharacterToLPT
  1411. pop ds
  1412. jmp short Toki_LPT_Exit
  1413. Toki_PrinterError:
  1414. pop ds
  1415. jmp short Toki_ReturnStatus
  1416. Toki_PrinterBusy:
  1417. pop ds
  1418. or ComErr[si],CE_TXFULL ; set buffer full bit
  1419. or al, L_TIMEOUT ; show timeout bit
  1420. Toki_ReturnStatus:
  1421. and ax,( PS_Select+PS_IOError+PS_Timeout) ; (ins 940125)
  1422. xchg al, ah
  1423. shr ah,1
  1424. adc ah,al ;Get back Timeout bit
  1425. xor ah,HIGH CE_DNS ;Invert selected bit
  1426. .errnz LOW CE_DNS
  1427. or by ComErr+1[si],ah ;Save comm error
  1428. Toki_LPT_Exit:
  1429. pop ax ; get total count
  1430. sub ax, cx ; subtract remaining unsent charts
  1431. ret
  1432. Toki_StringToLPT endp
  1433. TOMOE_PAT DB 16 DUP('PATCH !!') ;PATCH AREA (ins 92.11.11)
  1434. endif ; NEC_98
  1435. IFDEF DEBUG ;Publics for debugging
  1436. ifdef NEC_98
  1437. public Toki_LPT_Reset
  1438. public Toki_LPT_Outchar
  1439. public Toki_LPT_Strobe
  1440. public Toki_LPT_GetStatus
  1441. public Toki_DoLPT40
  1442. else ; NEC_98
  1443. public LPT_Reset
  1444. public LPT_Outchar
  1445. public LPT_Strobe
  1446. public LPT_GetStatus
  1447. public DoLPT40
  1448. endif ; NEC_98
  1449. ENDIF
  1450. sEnd code
  1451. End