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.

1186 lines
27 KiB

  1. PAGE 58,132
  2. ;******************************************************************************
  3. TITLE DCOMM.ASM - Dispatch Communications Driver
  4. ;******************************************************************************
  5. ;
  6. ; (C) Copyright NEC Software Kobe Corp. , 1994
  7. ;
  8. ; Title: DCOMM.ASM - Dispatch Communications Driver
  9. ;
  10. ; Version: 1.0
  11. ;
  12. ; Date: 27-Jun-1994
  13. ;
  14. ; Author: M.H
  15. ; (Masatoshi Hosokawa)
  16. ;
  17. ;------------------------------------------------------------------------------
  18. ;
  19. ; Change log:
  20. ;
  21. ; DATE REV DESCRIPTION
  22. ; ----------- --- -----------------------------------------------------------
  23. ; 27-Jun-1994 M.H Original
  24. ;------------------------------------------------------------------------------
  25. .XLIST
  26. include cmacros.inc
  27. .LIST
  28. ;------------------------------------------------------------------------------
  29. ; extern
  30. ;------------------------------------------------------------------------------
  31. externFP GetProcAddress
  32. externFP GetPrivateProfileString
  33. externFP LoadLibrary
  34. externFP FreeLibrary
  35. ifdef WINNT ;; Apr 15, 1995
  36. externFP RegOpenKey
  37. externFP RegCloseKey
  38. externFP LoadLibraryEx32W
  39. externFP FreeLibrary32W
  40. externFP GetProcAddress32W
  41. externFP CallProc32W
  42. endif ;; Apr 15, 1995
  43. ;------------------------------------------------------------------------------
  44. ; public DATA
  45. ;------------------------------------------------------------------------------
  46. public ComExAddr
  47. public LptExAddr
  48. public ComHandle
  49. public LptHandle
  50. ;------------------------------------------------------------------------------
  51. ; public CODE
  52. ;------------------------------------------------------------------------------
  53. public inicom
  54. public setcom
  55. public setque
  56. public reccom
  57. public sndcom
  58. public ctx
  59. public trmcom
  60. public stacom
  61. public cextfcn
  62. public cflush
  63. public cevt
  64. public cevtGet
  65. public csetbrk
  66. public cclrbrk
  67. public getdcb
  68. public SuspendOpenCommPorts
  69. public ReactivateOpenCommPorts
  70. public CommWriteString
  71. public ReadCommString ;Add 940924 KBNES
  72. public EnableNotification
  73. ;------------------------------------------------------------------------------
  74. ; Equates
  75. ;------------------------------------------------------------------------------
  76. MAX_PORT equ 9
  77. ifdef WINNT ;; Apr 15, 1995
  78. HKEY_LOCAL_MACHINE equ 80000002h
  79. REG_SZ equ 00000001h
  80. endif ;; Apr 15, 1995
  81. ;------------------------------------------------------------------------------
  82. ; Structures
  83. ;------------------------------------------------------------------------------
  84. DCD_Struc STRUC
  85. Proc@1 dd 0 ; inicom
  86. Proc@2 dd 0 ; setcom
  87. Proc@3 dd 0 ; setque
  88. Proc@4 dd 0 ; reccom
  89. Proc@5 dd 0 ; sndcom
  90. Proc@6 dd 0 ; ctx
  91. Proc@7 dd 0 ; trmcom
  92. Proc@8 dd 0 ; stacom
  93. Proc@9 dd 0 ; cextfcn
  94. Proc@10 dd 0 ; cflush
  95. Proc@11 dd 0 ; cevt
  96. Proc@12 dd 0 ; cevtGet
  97. Proc@13 dd 0 ; csetbrk
  98. Proc@14 dd 0 ; cclrbrk
  99. Proc@15 dd 0 ; getdcb
  100. Proc@16 dd 0 ; Reserve
  101. Proc@17 dd 0 ; SuspendOpenCommPorts
  102. Proc@18 dd 0 ; ReactivateOpenCommPorts
  103. Proc@19 dd 0 ; CommWriteString
  104. Proc@20 dd 0 ; ReadCommString ;Add 94.09.20 KBNES
  105. Proc@100 dd 0 ; EnableNotification
  106. DCD_Struc ENDS
  107. ;------------------------------------------------------------------------------
  108. ; Data
  109. ;------------------------------------------------------------------------------
  110. sBegin Data
  111. ComExAddr DCD_Struc <>
  112. db SIZE DCD_Struc * (MAX_PORT - 1) dup(0)
  113. LptExAddr DCD_Struc <>
  114. db SIZE DCD_Struc * (MAX_PORT - 1) dup(0)
  115. ComHandle dw MAX_PORT dup(0)
  116. LptHandle dw MAX_PORT dup(0)
  117. ExFuncAddrPtr dw 0
  118. EndExFuncAddrPtr dw 0
  119. tmpMAX dw 0
  120. ifdef WINNT ;; Apr 15, 1995
  121. DefaultDriver db 'neccomm.drv',0
  122. CCU2ndDriver db 'nec2comm.drv',0
  123. ComDriver dw DefaultDriver ;;
  124. dw DefaultDriver ;; FIXME FIXME
  125. dw CCU2ndDriver ;; FIXME FIXME COM2 is 2ndCCU only
  126. dw MAX_PORT dup(DefaultDriver) ;; FIXME FIXME
  127. LptDriver dw MAX_PORT+1 dup(DefaultDriver)
  128. ComEntryNum dw 0
  129. LptEntryNum dw 0
  130. HkeyLocalMachine dd HKEY_LOCAL_MACHINE
  131. NULL dd 00000000H
  132. SerialKeyName db 'HARDWARE\DEVICEMAP\SERIALCOMM', 0
  133. ParaKeyName db 'HARDWARE\DEVICEMAP\PARALLEL PORTS', 0
  134. KeyHandle dd ?
  135. dwIndex dd ?
  136. dwType dd ?
  137. dwSize dd ?
  138. szSerial db 'Serial' ; EntryName = DriverName
  139. SerialNum db 20 dup (0)
  140. LenszSerial dd $ - szSerial
  141. szCom db 'COM'
  142. ComNum db 0,0,0,0
  143. db 20 dup (0)
  144. LenszCom dd $ - szCOM
  145. szParallel db '\Device\Parallel' ; EntryName = DriverName
  146. ParaNum db 20 dup (0)
  147. LenszParallel dd $ - szParallel
  148. szLpt db '\DosDevices\LPT'
  149. LptNum db 0,0,0,0
  150. db 20 dup (0)
  151. LenszLpt dd $ - szLpt
  152. ;
  153. ; for Generic Thunk
  154. ;
  155. szDllName db 'advapi32',0
  156. szProcName db 'RegEnumValueW',0
  157. hAdvApi dd ?
  158. dwNparams dd 8
  159. lpRegEnumValue dd ?
  160. AddrConv dd 011011101b
  161. else ;; Apr 15, 1995
  162. DriverNameMax equ 256
  163. DriverName db DriverNameMax dup (0)
  164. SectionName db 'DispatchComm',0 ; [Section]
  165. ComEntryName db 'Com' ; EntryName = DriverName
  166. ComEntryNum db '0.drv',0
  167. LptEntryName db 'Lpt' ; EntryName = DriverName
  168. LptEntryNum db '0.drv',0
  169. DefaultDrvName db 'neccomm.drv',0 ; DriverName(entry not found)
  170. SystemIni db 'system.ini',0 ; file name
  171. endif ;; Apr 15, 1995
  172. sEnd
  173. ;------------------------------------------------------------------------------
  174. ; Macro
  175. ;------------------------------------------------------------------------------
  176. ;func(pdcb)
  177. Dispatch_DCB macro Func
  178. local D_LPTx
  179. local D_COMx
  180. local D_SetFuncAddr
  181. local D_Error
  182. ifdef DEBUG
  183. int 3 ; Debug Code
  184. endif ;DEBUG
  185. sub sp, 4 ; make stack space for retf addr
  186. push eax ; save eax
  187. push ebx ; save ebx
  188. push ds ; save ds
  189. mov bx, sp
  190. mov eax, ss:[bx + 18] ; mov eax, lpdcb
  191. ; 18 = 4+4+4+4+2(retaddr,retfaddr,eax,ebx,ds)
  192. mov bx, ax ; set offset lpdcb
  193. shr eax, 16 ; calculate segment lpdcb
  194. mov ds, ax ; set segment lpdcb
  195. mov al, byte ptr [bx] ; Get al = cid
  196. mov bx, _DATA
  197. mov ds, bx ; ds = Data
  198. test al, 80h ; Q:LPTx or COMx ?
  199. jz short D_COMx ; If COMx then goto D_COMx
  200. D_LPTx:
  201. mov bx, offset LptExAddr
  202. jmp short D_SetFuncAddr
  203. D_COMx:
  204. mov bx, offset ComExAddr
  205. D_SetFuncAddr:
  206. and eax, 007Fh
  207. cmp ax, MAX_PORT - 1
  208. jbe SHORT @f
  209. xor ax, ax
  210. @@:
  211. imul eax, SIZE DCD_Struc ; EAX = Offset in LPT table
  212. add bx, ax
  213. mov eax, [bx + Func] ; get COMM.DRV entry addr
  214. or eax, eax
  215. jz short D_Error
  216. pop ds ; restore ds
  217. mov bx, sp
  218. mov ss:[bx + 8], eax ; set COMM.DRV entry addr
  219. ; 8 = 4+4(eax,ebx)
  220. pop ebx ; restore ebx
  221. pop eax ; restore eax
  222. retf ; go to COMM.DRV driver
  223. D_Error:
  224. pop ds ; restore ds
  225. pop ebx ; restore ebx
  226. add sp, 8
  227. mov ax, 0 ; return
  228. retf 4
  229. endm
  230. ;func(cid,..etc)
  231. Dispatch_cid macro Func, cid, addsp
  232. local D_LPTx
  233. local D_COMx
  234. local D_SetFuncAddr
  235. local D_Error
  236. ifdef DEBUG
  237. int 3 ; Debug Code
  238. endif ;DEBUG
  239. sub sp, 4 ; make stack space for retf addr
  240. push eax ; save eax
  241. push ebx ; save ebx
  242. push ds ; save ds
  243. mov bx, _DATA
  244. mov ds, bx ; ds = Data
  245. mov bx, sp
  246. mov ax, ss:[bx + cid + 18] ; mov al, cid
  247. ; 18 = 4+4+4+4+2(retaddr,retfaddr,eax,ebx,ds)
  248. test al, 0080h ; Q:LPTx or COMx ?
  249. jz short D_COMx ; If COMx then goto D_COMx
  250. D_LPTx:
  251. mov bx, offset LptExAddr
  252. jmp short D_SetFuncAddr
  253. D_COMx:
  254. mov bx, offset ComExAddr
  255. D_SetFuncAddr:
  256. and eax, 007Fh
  257. cmp ax, MAX_PORT - 1
  258. jbe SHORT @f
  259. xor ax, ax
  260. @@:
  261. imul eax, SIZE DCD_Struc ; EAX = Offset in LPT table
  262. add bx, ax
  263. mov eax, [bx + Func] ; get COMM.DRV entry addr
  264. or eax, eax
  265. jz short D_Error
  266. pop ds ; restore ds
  267. mov bx, sp
  268. mov ss:[bx + 8], eax ; set COMM.DRV entry addr
  269. ; 8 = 4+4(eax,ebx)
  270. pop ebx ; restore ebx
  271. pop eax ; restore eax
  272. retf ; go to COMM.DRV driver
  273. D_Error:
  274. pop ds ; restore ds
  275. pop ebx ; restore ebx
  276. add sp, 8
  277. mov ax, 0 ; return
  278. retf addsp
  279. endm
  280. ;void func(void)
  281. Dispatch_void macro FuncName, Func
  282. local D_Loop
  283. local D_Skip
  284. cProc FuncName,<FAR,PUBLIC,PASCAL>
  285. cBegin nogen
  286. ifdef DEBUG
  287. int 3 ; Debug Code
  288. endif ;DEBUG
  289. push es ; save es
  290. mov ecx, MAX_PORT * 2 ; Set loop counter(COM & LPT)
  291. mov ax, _DATA
  292. mov es, ax ; es = Data
  293. mov bx, offset ComExAddr ; get Function Addr Ptr
  294. mov di, offset ComHandle ; get handle Ptr
  295. D_Loop:
  296. mov ax, es:[di] ; get handle
  297. or ax, ax ; Q:Invalid handle?
  298. jz SHORT D_Skip ; Yes.
  299. mov eax, es:[bx + Func] ; get COMM.DRV entry addr
  300. or eax, eax ; Q: entry addr OK?
  301. jz SHORT D_Skip ; No. Skip call COMM.DRV.
  302. pushad ; save all register
  303. call dword ptr es:[bx + Func]; call COMM.DRV driver
  304. popad ; restore all register
  305. D_Skip:
  306. add di, 2 ; calculate next handle Ptr
  307. add bx, SIZE DCD_Struc ; calculate next Function Addr Ptr
  308. loop SHORT D_Loop
  309. pop es ; restore es
  310. ret
  311. cEnd nogen
  312. endm
  313. ;------------------------------------------------------------------------------
  314. ; Code
  315. ;------------------------------------------------------------------------------
  316. sBegin Code
  317. assumes cs,Code
  318. assumes ds,Data
  319. .386
  320. ;------------------------------------------------------------------------------
  321. ; USE DCB ID
  322. ;------------------------------------------------------------------------------
  323. inicom proc far
  324. ; parmD pdcb
  325. Dispatch_DCB Proc@1
  326. inicom endp
  327. setcom proc far
  328. ; parmD pdcb
  329. Dispatch_DCB Proc@2
  330. setcom endp
  331. ;------------------------------------------------------------------------------
  332. ; USE CID
  333. ;------------------------------------------------------------------------------
  334. setque proc far
  335. ; parmB cid
  336. ; parmD pqdb
  337. Dispatch_cid Proc@3, 4, 6
  338. setque endp
  339. reccom proc far
  340. ; parmB cid
  341. Dispatch_cid Proc@4, 0, 2
  342. reccom endp
  343. sndcom proc far
  344. ; parmB cid
  345. ; parmB chr
  346. ; Dispatch_cid Proc@5, 1, 4 ;Bug fixed 94.09.20 KBNES
  347. Dispatch_cid Proc@5, 2, 4 ;Bug fixed 94.09.20 KBNES
  348. sndcom endp
  349. ctx proc far
  350. ; parmB cid
  351. ; parmB chr
  352. ; Dispatch_cid Proc@6, 1, 4 ;Bug fixed 94.09.20 KBNES
  353. Dispatch_cid Proc@6, 2, 4 ;Bug fixed 94.09.20 KBNES
  354. ctx endp
  355. trmcom proc far
  356. ; parmB cid
  357. Dispatch_cid Proc@7, 0, 2
  358. trmcom endp
  359. stacom proc far
  360. ; parmB cid
  361. ; parmD pstat
  362. ; Dispatch_cid Proc@8, 4, 4 ;Bug fixed 94.09.20 KBNES
  363. Dispatch_cid Proc@8, 4, 6 ;Bug fixed 94.09.20 KBNES
  364. stacom endp
  365. ;------------------------------------------------------------------------------
  366. ; USE CID, But(GETMAXCOM GETMAXLPT) call all driver
  367. ;------------------------------------------------------------------------------
  368. ;;cextfcn function stack
  369. ;;
  370. ;; offset size coment
  371. ;; -10 4 COMM.DRV Entry addr (use only GETMAXCOM or LPT)
  372. ;; - 6 4 GETMAXLoop addr (use only GETMAXCOM or LPT)
  373. ;; - 4 2 func (use only GETMAXCOM or LPT)
  374. ;; - 2 2 id (use only GETMAXCOM or LPT)
  375. ;; 0 2 gs
  376. ;; 2 2 fs
  377. ;; 4 2 es
  378. ;; 6 2 ds
  379. ;; 8 4 ebp
  380. ;; 12 4 edi
  381. ;; 16 4 esi
  382. ;; 20 4 edx
  383. ;; 24 4 ecx
  384. ;; 28 4 ebx
  385. ;; 32 4 eax
  386. ;; 36 4 COMM.DRV Entry addr
  387. ;; 40 4 return addr
  388. ;; 44 2 func
  389. ;; 46 2 id
  390. cextfcn proc far
  391. ; parmB cid
  392. ; parmW fcn
  393. ifdef DEBUG
  394. int 3 ; Debug Code
  395. endif ;DEBUG
  396. sub sp, 4 ; make stack space for retf addr
  397. push eax
  398. push ebx
  399. push ecx
  400. push edx
  401. push esi
  402. push edi
  403. push ebp
  404. push ds
  405. push es
  406. push fs
  407. push gs
  408. mov ax, _DATA
  409. mov ds, ax ; ds = Data
  410. mov bx, sp
  411. mov ax, ss:[bx + 44] ; mov ax, fcn
  412. ; 44 = 36+4+4(pushreg,retaddr,retfaddr)
  413. mov bx, offset ComExAddr
  414. cmp ax, 9 ; Q:fcn = GETMAXCOM ?
  415. je SHORT GetMaxEntry ; Yes.
  416. mov bx, offset LptExAddr
  417. cmp ax, 8 ; Q:fcn = GETMAXLPT ?
  418. je SHORT GetMaxEntry ; Yes.
  419. mov bx, sp
  420. mov al, ss:[bx + 46] ; mov al, id
  421. ; 46 = 36+4+4+2(pushreg,retaddr,retfaddr,fcn)
  422. mov bx, offset ComExAddr
  423. test al, 0080h ; Q:LPTx or COMx ?
  424. jz short Fcn_SetFuncAddr ; Yes.
  425. mov bx, offset LptExAddr ; No.
  426. Fcn_SetFuncAddr:
  427. and eax, 007Fh
  428. cmp ax, MAX_PORT - 1
  429. jbe SHORT @f
  430. xor ax, ax
  431. @@:
  432. imul eax, SIZE DCD_Struc ; EAX = Offset in LPT table
  433. add bx, ax
  434. mov eax, [bx + Proc@9] ; get COMM.DRV entry addr
  435. or eax, eax
  436. jz short Fcn_Error
  437. mov bx, sp
  438. mov ss:[bx + 36], eax ; set COMM.DRV entry addr
  439. ; 36 = (pushreg)
  440. pop gs
  441. pop fs
  442. pop es
  443. pop ds
  444. pop ebp
  445. pop edi
  446. pop esi
  447. pop edx
  448. pop ecx
  449. pop ebx
  450. pop eax
  451. retf ; go to COMM.DRV driver
  452. Fcn_Error:
  453. pop gs
  454. pop fs
  455. pop es
  456. pop ds
  457. pop ebp
  458. pop edi
  459. pop esi
  460. pop edx
  461. pop ecx
  462. pop ebx
  463. pop eax
  464. add sp, 4 ; del stack space for retf addr
  465. mov ax, 0 ; return
  466. retf 4
  467. ; fcn = GETMAXCOM or GETMAXLPT call all driver
  468. GetMaxEntry:
  469. mov ExFuncAddrPtr, bx ; Set ExFuncAddrPtr
  470. add bx, SIZE DCD_Struc * MAX_PORT
  471. mov EndExFuncAddrPtr, bx ; set EndExFuncAddrPtr
  472. mov tmpMAX, 0 ; Clear tmpMAX
  473. GETMAX1:
  474. xor ax, ax ; Clear ax
  475. GETMAXLoop:
  476. mov bx, _DATA
  477. mov ds, bx ; ds = Data
  478. cmp ax, tmpMAX
  479. jbe @f
  480. mov tmpMAX, ax
  481. @@:
  482. mov bx, ExFuncAddrPtr
  483. cmp bx, EndExFuncAddrPtr ; Q:Loop End?
  484. je GETMAXEnd ; Yes.
  485. mov eax, [bx + Proc@9] ; get COMM.DRV entry addr
  486. add ExFuncAddrPtr, SIZE DCD_Struc; calculate next Function Addr Ptr
  487. or eax, eax ; Q:Invalid Addr?
  488. jz SHORT GETMAX1 ; Yes.
  489. mov bx, sp
  490. sub sp, 4 ; make stack space for (func,id)
  491. push cs
  492. push offset GETMAXLoop
  493. push eax ; Set COMM.DRV entry addr
  494. mov ax, ss:[bx + 44] ; get func
  495. mov ss:[bx - 4],ax ; set func
  496. mov ax, ss:[bx + 46] ; get id
  497. mov ss:[bx - 2],ax ; set id
  498. ; restore pushreg val
  499. mov ax, ss:[bx]
  500. mov gs, ax
  501. mov ax, ss:[bx + 2]
  502. mov fs, ax
  503. mov ax, ss:[bx + 4]
  504. mov es, ax
  505. mov ax, ss:[bx + 6]
  506. mov ds, ax
  507. mov ebp, ss:[bx + 8]
  508. mov edi, ss:[bx + 12]
  509. mov esi, ss:[bx + 16]
  510. mov edx, ss:[bx + 20]
  511. mov ecx, ss:[bx + 24]
  512. mov eax, ss:[bx + 32]
  513. mov ebx, ss:[bx + 28]
  514. retf ; go to COMM.DRV driver
  515. GETMAXEnd:
  516. mov dx, tmpMAX
  517. mov bx, sp
  518. ; restore pushreg val
  519. mov ax, ss:[bx]
  520. mov gs, ax
  521. mov ax, ss:[bx + 2]
  522. mov fs, ax
  523. mov ax, ss:[bx + 4]
  524. mov es, ax
  525. mov ax, ss:[bx + 6]
  526. mov ds, ax
  527. mov ebp, ss:[bx + 8]
  528. mov edi, ss:[bx + 12]
  529. mov esi, ss:[bx + 16]
  530. mov ecx, ss:[bx + 24]
  531. mov ebx, ss:[bx + 28]
  532. mov ax, dx
  533. xor dx, dx
  534. add sp, 36 + 4
  535. retf 4
  536. cextfcn endp
  537. ;------------------------------------------------------------------------------
  538. ; USE CID
  539. ;------------------------------------------------------------------------------
  540. cflush proc far
  541. ; parmB cid
  542. ; parmB q
  543. ; Dispatch_cid Proc@10, 1, 4 ;Bug fixed 94.09.20 KBNES
  544. Dispatch_cid Proc@10, 2, 4 ;Bug fixed 94.09.20 KBNES
  545. cflush endp
  546. cevt proc far
  547. ; parmB cid
  548. ; parmW evt_mask
  549. Dispatch_cid Proc@11, 2, 4
  550. cevt endp
  551. cevtGet proc far
  552. ; parmB cid
  553. ; parmW evt_mask
  554. Dispatch_cid Proc@12, 2, 4
  555. cevtGet endp
  556. csetbrk proc far
  557. ; parmB cid
  558. Dispatch_cid Proc@13, 0, 2
  559. csetbrk endp
  560. cclrbrk proc far
  561. ; parmB cid
  562. Dispatch_cid Proc@14, 0, 2
  563. cclrbrk endp
  564. getdcb proc far
  565. ; parmB cid
  566. Dispatch_cid Proc@15, 0, 2
  567. getdcb endp
  568. ;------------------------------------------------------------------------------
  569. ; Call All Driver
  570. ;------------------------------------------------------------------------------
  571. Dispatch_void SuspendOpenCommPorts, Proc@17
  572. Dispatch_void ReactivateOpenCommPorts, Proc@18
  573. ;------------------------------------------------------------------------------
  574. ; USE CID
  575. ;------------------------------------------------------------------------------
  576. CommWriteString proc far
  577. ; parmB cid
  578. ; parmD lpstring
  579. ; parmW count
  580. Dispatch_cid Proc@19, 6, 8
  581. CommWriteString endp
  582. ReadCommString proc far ;Add 94.09.20 KBNES
  583. ; parmB cid ;Add 94.09.20 KBNES
  584. ; parmD buf ;Add 94.09.20 KBNES
  585. ; parmW cnt ;Add 94.09.20 KBNES
  586. Dispatch_cid Proc@20, 6, 8 ;Add 94.09.20 KBNES
  587. ReadCommString endp ;Add 94.09.20 KBNES
  588. EnableNotification proc far
  589. ; parmB cid
  590. ; parmW _hWnd
  591. ; parmW recvT
  592. ; parmW sendT
  593. ; Dispatch_cid Proc@100, 12, 8 ;Bug fixed 94.09.20 KBNES
  594. Dispatch_cid Proc@100, 6, 8 ;Bug fixed 94.09.20 KBNES
  595. EnableNotification endp
  596. cProc WEP,<PUBLIC,FAR>
  597. cBegin nogen
  598. ifdef DEBUG
  599. int 3 ; Debug Code
  600. endif ;DEBUG
  601. ; Free Communications Driver
  602. pushad
  603. mov ax, _DATA ;Bug fixed 941008 KBNES
  604. mov ds, ax ;Bug fixed 941008 KBNES
  605. mov cx, MAX_PORT * 2 ; Set loop Counter
  606. mov bx, offset ComHandle ; Set Comm Driver handle address
  607. FreeCommDrv:
  608. mov ax, [bx] ; Get Communications Driver handle
  609. add bx, 2 ; calculate next Comm Driver handle
  610. or ax, ax ; Q:Invalid handle?
  611. jz SHORT @f ; Yes.
  612. push bx ; save bx
  613. push cx ; save cx
  614. cCall FreeLibrary,<ax> ; Free Communications Driver
  615. pop cx ; restore cx
  616. pop bx ; restore bx
  617. @@:
  618. loop SHORT FreeCommDrv
  619. popad
  620. nop ; You don't want to know why.
  621. mov ax,1
  622. ret 2
  623. cEnd nogen
  624. sEnd Code
  625. ;------------------------------------------------------------------------------
  626. ; Initial Code
  627. ;------------------------------------------------------------------------------
  628. .286
  629. createSeg _INIT,init,word,public,CODE
  630. sBegin init
  631. assumes cs,init
  632. .386
  633. cProc LoadLib, <FAR,PUBLIC,NODATA>,<si,di>
  634. cBegin
  635. ifdef DEBUG
  636. int 3 ; Debug Code
  637. endif ;DEBUG
  638. pushad
  639. mov ax, _DATA ;Bug fixed 941008 KBNES
  640. mov ds, ax ;Bug fixed 941008 KBNES
  641. ifdef WINNT
  642. ; hAdvApi = LoadLibraryEx32W(szDllName, NULL, 0);
  643. ; if ((fpRegEnum = GetProcAddress32W(hAdvApi, szProcName)) == NULL) {
  644. ; int21(0x4c00); //system done.
  645. ; }
  646. ;
  647. lea ax,szDllName
  648. push ds
  649. push ax
  650. push 0
  651. push 0
  652. push 0
  653. push 0
  654. call far ptr LoadLibraryEx32W
  655. mov word ptr hAdvApi,ax
  656. mov word ptr hAdvApi+2,dx
  657. mov bx,ax
  658. or bx,dx
  659. jne @f
  660. stc
  661. jmp CSHEnd
  662. @@:
  663. ; farPtr lpszProcName,ds,ax
  664. ; cCall GetProcAddress32W,<hAdvApi,lpszProcName>
  665. push dx
  666. push ax
  667. lea cx,szProcName
  668. push ds
  669. push cx
  670. call far ptr GetProcAddress32W
  671. mov word ptr lpRegEnumValue,ax
  672. mov word ptr lpRegEnumValue+2,dx
  673. or ax,dx
  674. jne @f
  675. stc
  676. jmp CSHEnd
  677. @@:
  678. endif
  679. ifdef WINNT ;; Apr 15, 1995
  680. ;;
  681. ;; Set Driver Name for All Seiral Ports
  682. ;;
  683. ;; Psude code
  684. ;;
  685. ;; if (!RegOpenKey (HKEY_LOCAL_MACHINE, szRegSerialMap, &hkey))
  686. ;; {
  687. ;; while (!RegEnumValue (hkey, i++, szSerial, &dwBufz,
  688. ;; NULL, &dwType, szCom, &dwSize)) {
  689. ;; if (dwType == REG_SZ) {
  690. ;; if (szSerial[7] == '0') ComDriver[szCom[3]-'0'] = DefaultDriver;
  691. ;; else if ((szSerial[8] == '0') && (szSerial[7] == '2'))
  692. ;; ComDriver[szCom[3]-'0'] = CCU2ndDriver;
  693. ;; else // nothing
  694. ;; }
  695. ;; }
  696. ;; RegCloseKey(hkey);
  697. ;; }
  698. lea ax,KeyHandle
  699. farPtr lpKeyHandle,ds,ax
  700. lea bx,SerialKeyName
  701. farPtr lpSerialKeyName,ds,bx
  702. cCall RegOpenKey,<HkeyLocalMachine,lpSerialKeyName,lpKeyHandle>
  703. cmp ax,0
  704. jne EnumFailed
  705. mov dwIndex,0
  706. jmp short EnumSerialStart
  707. EnumSerial:
  708. inc dwIndex
  709. EnumSerialStart:
  710. mov LenszSerial,26
  711. mov LenszCom,27
  712. lea ax,szSerial
  713. farPtr lpszSerial,ds,ax
  714. lea bx,LenszSerial
  715. farPtr lpLenszSerial,ds,bx
  716. lea cx,dwType
  717. farPtr lpdwType,ds,cx
  718. lea dx,szCom
  719. farPtr lpszCom,ds,dx
  720. lea di,LenszCom
  721. farPtr lpLenszCom,ds,di
  722. ;; CallProc32W(KeyHandle,dwIndex,lpszSerial,lpLenszSerial,NULL,lpdwType,lpszCom,lpLenszCom,
  723. ;; lpRegEnumValue, AddrConv, 8);
  724. cCall CallProc32W,<KeyHandle,dwIndex,lpszSerial,lpLenszSerial,NULL,lpdwType,lpszCom,lpLenszCom,lpRegEnumValue,AddrConv,dwNparams>
  725. or ax,dx
  726. jne EnumSerialEnd
  727. cmp dwType,REG_SZ ; Is type of value REG_SZ ?
  728. jne EnumSerial
  729. lea di,szSerial
  730. mov ah,[di+7]
  731. cmp ah,0h ; Serial[7] == 0 ?
  732. jne @f
  733. lea ax,DefaultDriver
  734. jmp SetDriverName
  735. @@:
  736. mov ah,[di+6]
  737. cmp ah,32h ; Serial[6] == '2' ?
  738. jne EnumSerial
  739. mov ah,[di+8]
  740. cmp ah,0h ; Serial[8] == 0 ?
  741. jne EnumSerial
  742. lea ax,CCU2ndDriver
  743. SetDriverName:
  744. lea si,szCom
  745. mov bx,[si+3]
  746. sub bx,30h
  747. shl bx,1 ; bx *= 2
  748. lea di,ComDriver
  749. mov [di+bx],ax
  750. jmp EnumSerial
  751. EnumSerialEnd:
  752. cCall RegCloseKey,<KeyHandle>
  753. ;;
  754. ;; Set Driver Name for All Parallel Ports
  755. ;;
  756. ;; Psude code
  757. ;;
  758. ;; if (!RegOpenKey (HKEY_LOCAL_MACHINE, szRegParallelMap, &hkey))
  759. ;; {
  760. ;; while (!RegEnumValue (hkey, i++, szParallel, &dwBufz,
  761. ;; NULL, &dwType, szLpt, &dwSize)) {
  762. ;; if (dwType == REG_SZ) {
  763. ;; if (szParallel[16] == '0') LptDriver[szLpt[15]-'0'] = DefaultDriver;
  764. ;; else // nothing
  765. ;; }
  766. ;; }
  767. ;; RegCloseKey(hkey);
  768. ;; }
  769. lea ax,KeyHandle
  770. farPtr lpKeyHandle,ds,ax
  771. lea bx,ParaKeyName
  772. farPtr lpParaKeyName,ds,bx
  773. cCall RegOpenKey,<HkeyLocalMachine,lpParaKeyName,lpKeyHandle>
  774. cmp ax,0
  775. jne EnumFailed
  776. mov dwIndex,0
  777. jmp short EnumParallelStart
  778. EnumParallel:
  779. inc dwIndex
  780. EnumParallelStart:
  781. mov LenszParallel,36
  782. mov LenszLpt,39
  783. ;; CallProc32W(KeyHandle,dwIndex,lpszSerial,lpLenszSerial,NULL,lpdwType,lpszCom,lpLenszCom,
  784. ;; lpRegEnumValue, AddrConv, 8);
  785. lea ax,szParallel
  786. farPtr lpszParallel,ds,ax
  787. lea bx,LenszParallel
  788. farPtr lpLenszParallel,ds,bx
  789. lea cx,dwType
  790. farPtr lpdwType,ds,cx
  791. lea dx,szLpt
  792. farPtr lpszLpt,ds,dx
  793. lea di,LenszLpt
  794. farPtr lpLenszLpt,ds,di
  795. cCall CallProc32W,<KeyHandle,dwIndex,lpszSerial,lpLenszSerial,NULL,lpdwType,lpszCom,lpLenszCom,lpRegEnumValue,AddrConv,dwNparams>
  796. or ax,dx
  797. jne EnumParallelEnd
  798. cmp dwType,REG_SZ ; Value type is not REG_SZ
  799. jne EnumParallel
  800. lea di,szParallel
  801. mov ah,30h
  802. cmp [di+16],ah ; dzParallel[16] == 0 ?
  803. jne EnumParallel
  804. lea si,szLpt
  805. xor bx,bx
  806. mov bl,[si+15] ; LPT No. = szLpt[15] - '0'
  807. sub bx,30h
  808. shl bx,1 ; bx *= 2
  809. lea ax,DefaultDriver
  810. mov [LptDriver+bx],ax
  811. jmp EnumParallel
  812. EnumParallelEnd:
  813. cCall RegCloseKey,<KeyHandle>
  814. ; FreeLibraryEx32W(hAdvApi);
  815. cCall FreeLibrary32W,<hAdvApi>
  816. jmp @f
  817. EnumFailed:
  818. cCall FreeLibrary32W,<hAdvApi>
  819. stc
  820. jmp CSHEnd
  821. @@:
  822. LoadDriverStart:
  823. endif ;; Apr 15, 1995
  824. ; Load and Set Communications Driver Function's Address
  825. xor cx, cx ; Clear loop counter
  826. LCDLoop:
  827. push cx ; Save loop counter
  828. ; Get Communications driver Name(COMx)
  829. inc ComEntryNum ; Set Comm EntryName Number
  830. ifdef WINNT ;; Apr 15, 1995
  831. ;;
  832. ;; Do Nothing
  833. ;;
  834. else ;; Apr 15, 1995
  835. lea ax,SectionName
  836. farPtr lpSection,ds,ax
  837. lea bx,ComEntryName
  838. farPtr lpEntry,ds,bx
  839. lea cx,DefaultDrvName
  840. farPtr lpDefault,ds,cx
  841. lea dx,DriverName
  842. farPtr lpReturnBuf,ds,dx
  843. mov si,DriverNameMax
  844. lea di,SystemIni
  845. farPtr lpFileName,ds,di
  846. cCall GetPrivateProfileString,<lpSection,lpEntry,lpDefault,lpReturnBuf,si,lpFileName>
  847. endif ;; Apr 15, 1995
  848. ; load Communications driver(COMx)
  849. ifdef WINNT ;; Apr 15, 1995
  850. mov bx,ComEntryNum
  851. shl bx,1
  852. mov ax,ComDriver[bx]
  853. else ;; Apr 15, 1995
  854. lea ax, DriverName
  855. endif ;; Apr 15, 1995
  856. farPtr module_name,ds,ax
  857. cCall LoadLibrary,<module_name>
  858. cmp ax, 32 ; Q:LoadLibrary() Success?
  859. ja SHORT LoadCOMx ; Yes.
  860. ; No.
  861. pop cx
  862. push cx
  863. or cx, cx ; Q:COM1?
  864. jnz SHORT @f ; No.
  865. ifdef WINNT ;; Jul 24, 1995
  866. stc
  867. jmp CSHEnd
  868. else
  869. popad
  870. mov ax,4c00h ; System Done.
  871. int 21h ; <--- !!!!!
  872. endif
  873. @@:
  874. mov ax, cx
  875. mov bx, offset ComHandle
  876. mov si, [bx]
  877. jmp SHORT GetComExAddr
  878. LoadCOMx:
  879. ; Get Communications driver(COMx) Export Function Address
  880. mov si,ax ; si = Communication driver's handle
  881. mov bx, offset ComHandle
  882. pop cx
  883. push cx
  884. mov ax, cx
  885. shl cx, 1
  886. add bx, cx
  887. mov [bx], si ; Set Module handle
  888. GetComExAddr:
  889. ; mov cx, 19 ;Del 94.09.20 KBNES
  890. mov cx, 20 ;Add 94.09.20 KBNES
  891. mov bx, offset ComExAddr
  892. imul eax, SIZE DCD_Struc ; EAX = Offset in COM table
  893. add bx, ax
  894. GPAC1:
  895. ; mov ax, 20 ;Del 94.09.20 KBNES
  896. mov ax, 21 ;Add 94.09.20 KBNES
  897. sub ax, cx ; Set EXPORT No.
  898. cwd
  899. push bx ; save bx
  900. push cx ; save cx
  901. farPtr func_number,dx,ax
  902. cCall GetProcAddress,<si,func_number> ; Get COMM.DRV FuncX Address
  903. pop cx ; restore cx
  904. pop bx ; restore bx
  905. mov [bx], ax
  906. mov [bx + 2], dx
  907. add bx, 4
  908. loop SHORT GPAC1
  909. mov ax, 100 ; Set EXPORT No.
  910. cwd
  911. push bx ; save bx
  912. farPtr func_number,dx,ax
  913. cCall GetProcAddress,<si,func_number> ; Get COMM.DRV FuncX Address
  914. pop bx ; restore bx
  915. mov [bx], ax
  916. mov [bx + 2], dx
  917. ; Get Communications driver Name(LPTx)
  918. inc LptEntryNum ; Set Lpt EntryName Number
  919. ifdef WINNT ;; Apr 15, 1995
  920. ;;
  921. ;; Do Nothing
  922. ;;
  923. else ;; Apr 15, 1995
  924. lea ax,SectionName
  925. farPtr lpSection,ds,ax
  926. lea bx,LptEntryName
  927. farPtr lpEntry,ds,bx
  928. lea cx,DefaultDrvName
  929. farPtr lpDefault,ds,cx
  930. lea dx,DriverName
  931. farPtr lpReturnBuf,ds,dx
  932. mov si,DriverNameMax
  933. lea di,SystemIni
  934. farPtr lpFileName,ds,di
  935. cCall GetPrivateProfileString,<lpSection,lpEntry,lpDefault,lpReturnBuf,si,lpFileName>
  936. endif ;; Apr 15, 1995
  937. ; load Communications driver(LPTx)
  938. ifdef WINNT ;; Apr 15, 1995
  939. mov bx,LptEntryNum
  940. shl bx,1
  941. mov ax,LptDriver[bx]
  942. else ;; Apr 15, 1995
  943. lea ax, DriverName
  944. endif ;; Apr 15, 1995
  945. farPtr module_name,ds,ax
  946. cCall LoadLibrary,<module_name>
  947. cmp ax, 32 ; Q:LoadLibrary() Success?
  948. ja SHORT LoadLPTx ; Yes.
  949. ; No.
  950. pop cx
  951. push cx
  952. or cx, cx ; Q:COM1?
  953. jnz SHORT @f ; No.
  954. ifdef WINNT ;; Jul 24, 1995
  955. stc
  956. jmp CSHEnd
  957. else
  958. popad
  959. mov ax,4c00h ; System Done.
  960. int 21h ; <--- !!!!!
  961. endif
  962. @@:
  963. mov ax, cx
  964. mov bx, offset LptHandle
  965. mov si, [bx]
  966. jmp SHORT GetLptExAddr
  967. LoadLPTx:
  968. ; Get Communications driver(LPTx) Export Function Address
  969. mov si,ax ; si = Communication driver's handle
  970. mov bx, offset LptHandle
  971. pop cx
  972. push cx
  973. mov ax, cx
  974. shl cx, 1
  975. add bx, cx
  976. mov [bx], si ; Set Module handle
  977. GetLptExAddr:
  978. ; mov cx, 19 ;Del 94.09.20 KBNES
  979. mov cx, 20 ;Add 94.09.20 KBNES
  980. mov bx, offset LptExAddr
  981. imul eax, SIZE DCD_Struc ; EAX = Offset in COM table
  982. add bx, ax
  983. GPAL1:
  984. ; mov ax, 20 ;Del 94.09.20 KBNES
  985. mov ax, 21 ;Add 94.09.20 KBNES
  986. sub ax, cx ; Set EXPORT No.
  987. cwd
  988. push bx ; save bx
  989. push cx ; save cx
  990. farPtr func_number,dx,ax
  991. cCall GetProcAddress,<si,func_number> ; Get COMM.DRV FuncX Address
  992. pop cx ; restore cx
  993. pop bx ; restore bx
  994. mov [bx], ax
  995. mov [bx + 2], dx
  996. add bx, 4
  997. loop SHORT GPAL1
  998. mov ax, 100 ; Set EXPORT No.
  999. cwd
  1000. push bx ; save bx
  1001. farPtr func_number,dx,ax
  1002. cCall GetProcAddress,<si,func_number> ; Get COMM.DRV FuncX Address
  1003. pop bx ; restore bx
  1004. mov [bx], ax
  1005. mov [bx + 2], dx
  1006. pop cx ; Restore loop counter
  1007. inc cx ; Count up
  1008. cmp cx, MAX_PORT ; if (CX != MAX_PORT)
  1009. jne LCDLoop ; then goto LCDLoop
  1010. ; Clear Same Handle
  1011. ; Algorism
  1012. ; for (bx=1 to MAX_PORT*2-1)
  1013. ; if (ComHandle[bx]!=0) for (si=bx+1 to MAX_PORT*2)
  1014. ; if (ComHandle[bx]==ComHandle[si]) ComHandle[si]=0
  1015. xor bx, bx ; Clear Counter(bx)
  1016. CSHLoop1:
  1017. cmp bx, (MAX_PORT*2 - 1)*2 ; Q:Loop1 Done?
  1018. je SHORT CSHEnd ; Yes.
  1019. mov ax, ComHandle[bx]
  1020. or ax, ax ; Q:Invalid handle?
  1021. jz SHORT CSHSkip ; Yes.
  1022. mov di, ax ; di = ComHandle[bx]
  1023. mov si, bx ; Set Counter(si)
  1024. CSHLoop2:
  1025. add si, 2 ; Count Up(si)
  1026. cmp si, (MAX_PORT * 2) * 2 ; Q:Loop2 done?
  1027. je SHORT CSHSkip ; Yes.
  1028. xor ax, ComHandle[si] ; Q:Same Handle?
  1029. jnz SHORT @f ; No.
  1030. mov ComHandle[si], ax ; Yes. Clear Same Handle
  1031. push bx
  1032. push si
  1033. push di
  1034. cCall FreeLibrary,<di> ; Free Communications Driver
  1035. pop di
  1036. pop si
  1037. pop bx
  1038. @@:
  1039. mov ax, di ; ax = ComHandle[bx]
  1040. jmp SHORT CSHLoop2
  1041. CSHSkip:
  1042. add bx, 2 ; Count Up(bx)
  1043. jmp SHORT CSHLoop1
  1044. CSHEnd:
  1045. popad
  1046. cEnd
  1047. sEnd init
  1048. End LoadLib