雷军20年前编写的汇编代码

Assembly code written by Xiaomi CEO Lei Jun, 25 years ago

In case you never heard of Xiaomi, it is Apple Inc. in China. Xiaomi is so hot in Asia now. Former Google Android exec Hugo Barra joined it and enjoy working there.

The CEO of Xiaomi, Lei Jun, is considered as Steve Jobs in China. But, Lei Jun can actually write code ... 

(This page is created by sending the code file as an attachment to *****@mailp.in -- create a web page with an email).

RI.ASM :
  
  
  
  
  1. ;
  2. ; RI.ASM Revision 2.12 [ July 12, 1994 ]
  3. Revision equ 'V2.12 '
  4. ;
  5. ; **************************************************************************
  6. ; * *
  7. ; * RAMinit Release 2.0 *
  8. ; * Copyright (c) 1989-1994 by Yellow Rose Software Co. *
  9. ; * Written by Mr. Leijun *
  10. ; * *
  11. ; * Function: *
  12. ; * Press HotKey to remove all TSR program after this program *
  13. ; * *
  14. ; **************************************************************************
  15.  
  16. ; ..........................................................................
  17. ; Removed Softwares by RI:
  18. ; SPDOS v6.0F, WPS v3.0F
  19. ; Game Busters III, IV
  20. ; NETX ( Novell 3.11 )
  21. ; PC-CACHE
  22. ; Norton Cache
  23. ; Microsoft SmartDrv
  24. ; SideKick 1.56A
  25. ; MOUSE Driver
  26. ; Crazy (Monochrome simulate CGA program)
  27. ; RAMBIOS v2.0
  28. ; 386MAX Version 6.01
  29. ; ..........................................................................
  30. ; No cancel softwares:
  31. ; Windows 3.1 MSD
  32. ;
  33. ; No removed TSR softwares:
  34. ; MS-DOS fastopen
  35. ; Buffers, Files ... (QEMM 6.0)
  36. ; QCache (386MAX 6.01)
  37. ; ..........................................................................
  38. ;
  39. COMMENT *
  40.  
  41. V2.04 Use mouse driver software reset function to initiation mouse
  42. 2/17/1993 by Mr. Lei and Mr. Feng
  43. V2.05 RI cannot work in Windows DOS prompt
  44. 3/9/1993 by Mr. Lei
  45. V2.06 1. When XMS cannot allocate 1K memory, RI halts.
  46. 2. RI repeat deallocates EMS memory.
  47. V2.07 HotKey Setup Error
  48. 4/25/1993 by Mr. Lei
  49. V2.08 KB Buffer
  50. V2.10 1. Release high memory blocks (EMM386 QEMM386 S-ICE 386MAX)
  51. 2. RI copies flag
  52. V2.12 1. Exists a critical error in Init 8259 procedure
  53. 2. Save [40:F0--FF] user data area
  54.  
  55. *
  56.  
  57. dosseg
  58. .model tiny
  59. .code
  60. locals @@
  61. org 100h
  62.  
  63. Start: jmp Main
  64. org 103h
  65.  
  66. True equ 1
  67. False equ 0
  68. MaxHandles equ 100h
  69.  
  70. INT3 macro
  71. out 0ffh,al
  72. endm
  73. ;
  74. ; HotKey Status Test Var
  75. ; --------------- ---------------
  76. ;
  77. ; 7 6 5 4 3 2 1 0 417 418 496
  78. ; . . x . x . . . Left Alt is pressed 8 2
  79. ; x . . . x . . . Right Alt is pressed 8 8
  80. ; . . . x . x . . Left Ctrl is pressed 4 1
  81. ; . x . . . x . . Right Ctrl is pressed 4 4
  82. ; . . . . . . x . Left Shift is pressed 2
  83. ; . . . . . . . x Right Shift is pressed 1
  84. ;
  85. LeftAlt equ 00101000b
  86. RightAlt equ 10001000b
  87. LeftCtrl equ 00010100b
  88. RightCtrl equ 01000100b
  89. LeftShift equ 00000010b
  90. RightShift equ 00000001b
  91. HotKey db LeftCtrl or RightCtrl
  92.  
  93. DataBegin dw 0
  94. NextDataSeg dw 0ffffh
  95. oldInt2F_addr dw 0, 0
  96. XMS_control dw 0, 0
  97. Handle_begin dw 0
  98. cvtOfs dw 0 ; DOS 3.0 equ 0 and above DOS 4.0 is 1
  99. org 104h
  100. db 0dh
  101. db Revision
  102. db ??date
  103. db 26
  104. org 114h
  105. tsrLength dw 0
  106. MachineID db 0FCh ; IBM PC/AT
  107.  
  108. AuxHotKey db 0 ; 2Dh ; 'X' Scan Code
  109. AuxHotKeyName db 'X$ '
  110. Power db True
  111. Flag db '!'
  112. Kbd102 db 0
  113. NoFlag db 0
  114. StopFlag db 1
  115. DosEnv dw 0
  116. WorkSeg dw 0
  117. PrevDataSeg dw 0
  118. Copies db '1'
  119. old_8259 db 0 ; 21h port
  120. db 0 ; a1h port
  121.  
  122. Status dw 0
  123. XMSbit equ 00000001b
  124. EMSbit equ 00000010b
  125. SKbit equ 10000000b
  126.  
  127. GoINT1C: db 0eah
  128. oldInt1C_addr dw 0, 0
  129. newINT1C:
  130. test cs:Status, SKbit
  131. jnz GoINT1C
  132. cmp cs:StopFlag, 0
  133. jz @@0
  134. ;
  135. ; Mr. Lei 2/8/1993
  136. ; Problem: if WPS quit and reenter, old RI cann't control keyboard.
  137. ;
  138. push ds
  139. push ax
  140. xor ax, ax
  141. mov ds, ax
  142. mov ax, ds:[9*4]
  143. cmp ax, offset NewInt9
  144. pop ax
  145. pop ds
  146. jnz GoINT1C
  147. mov cs:StopFlag, 0
  148.  
  149. @@0: push ax
  150. push ds
  151. push es
  152. xor ax, ax
  153. mov ds, ax
  154. mov es, ds:[9*4+2]
  155. cmp word ptr es:[101h], 'IE' ; 'LEI'
  156. jz @@1
  157. cli
  158. mov cs:StopFlag, 1
  159. mov ax, ds:[9*4]
  160. mov cs:oldINT9_addr2, ax
  161. mov ax, ds:[9*4+2]
  162. mov cs:oldINT9_addr2[2], ax
  163. mov ds:[9*4], offset newINT9_2
  164. mov ds:[9*4+2], cs
  165. sti
  166. @@1: pop es
  167. pop ds
  168. pop ax
  169. jmp GoINT1C
  170.  
  171. ; ----------------------------------------------------------------------
  172. ; INT2F Func
  173. ;
  174. ; AX = C0D7h Return RI segment in AX
  175. ; AX = C0D8h Removes all TSR programs after RI
  176. ; AX = C0D9h Removes all TSR programs include RI
  177. ; AX = C0DAh Removes all RI copies
  178. ; ----------------------------------------------------------------------
  179.  
  180. newINT2F:
  181. cmp ax, 0c0d7h ; LEI Hanzi GB Code
  182. jnz @@1
  183. push cs
  184. pop ax
  185. iret
  186. @@1: cmp ax, 0c0d7h+1
  187. jnz @@2
  188. jmp KeepSelf
  189. @@2: cmp ax, 0c0d7h+2
  190. jnz @@3
  191. jmp NoKeepSelf
  192. @@3: cmp ax, 0c0d7h+3
  193. jnz @@9
  194. mov cs:NextDataSeg, -1
  195. mov cs:Copies, '1'
  196. jmp NoKeepSelf
  197. @@9: jmp dword ptr cs:oldInt2F_addr
  198.  
  199.  
  200. CallInt9:
  201. ret
  202.  
  203.  
  204. newINT9_2:
  205. mov cs:NoFlag, 1
  206. pushf
  207. db 9ah ; call far ptr oldint9_addr
  208. oldInt9_Addr2 dw 0, 0
  209. jmp newINT9_proc
  210.  
  211. newINT9:
  212. pushf
  213. db 9ah ; call far ptr oldint9_addr
  214. oldInt9_Addr dw 0, 0
  215. cmp cs:NoFlag, 0
  216. jz newINT9_proc
  217. mov cs:NoFlag, 0
  218. iret
  219. newINT9_proc:
  220. cmp cs:Flag, '!' ; busy ?
  221. jnz @@0
  222. iret
  223. @@0:
  224. mov cs:Flag, '!' ; set busy flag
  225. push ax ; cmp hot key
  226. push bx
  227. push es
  228. mov ax,40h
  229. mov es,ax
  230.  
  231. cmp cs:AuxHotKey, 0
  232. jz @@_1
  233. mov bx, es:[1ah]
  234. cmp bx, es:[1ch]
  235. jz @@10
  236. push bx
  237. mov bl, es:[bx+1]
  238. cmp bl, cs:AuxHotKey
  239. pop bx
  240. jnz @@10
  241. @@_1:
  242. mov ah,es:[17h] ; test CTRL SHIFT ALT
  243. mov al,cs:HotKey
  244. push ax
  245. and ax,0f0fh
  246. cmp al,ah
  247. pop ax
  248. jnz @@10
  249. cmp cs:Kbd102, True
  250. jnz @@1
  251. shr al, 1
  252. shr al, 1
  253. shr al, 1
  254. shr al, 1
  255. push ax
  256. mov ah, es:[18h]
  257. and ax, 303h
  258. cmp al, ah
  259. pop ax
  260. jnz @@10
  261. mov ah, es:[96h]
  262. shr ax, 1
  263. shr ax, 1
  264. and ax, 303h
  265. cmp al, ah
  266. jnz @@10
  267.  
  268. cmp cs:AuxHotKey, 0
  269. jz @@_3
  270. inc bx
  271. inc bx
  272. cmp bx, 3eh
  273. jb @@_2
  274. mov bx, 1eh
  275. @@_2:
  276. mov es:[1ah], bx
  277. @@_3:
  278. call IsWinDos
  279. or ax, ax
  280. jz @@1
  281. call Beep
  282. @@10:
  283. sti
  284. pop es
  285. pop bx
  286. pop ax
  287. mov cs:Flag, ' ' ; no busy
  288. iret
  289. @@1: ; OK
  290. pop es
  291. pop bx
  292. pop ax
  293.  
  294. KeepSelf:
  295. call RemoveTSR
  296. push es
  297. mov es,cs:WorkSeg
  298. mov dx,es:tsrLength
  299. mov di,dx
  300. mov al,0h ; Aug 24, 1993
  301. mov cx,100h
  302. rep stosb
  303. pop es
  304. int 27h
  305.  
  306. NoKeepSelf:
  307. mov ax,0e07h
  308. int 10h
  309. mov cs:clsStr, 47h ; Color (White in Red)
  310. call RemoveTSR
  311. dec cs:Copies
  312. call RestoreSelfIntVec
  313. push es
  314. cmp cs:PrevDataSeg, 0
  315. jz @@1
  316. mov es, cs:PrevDataSeg
  317. mov es:NextDataSeg, -1
  318. @@1: pop es
  319. mov ax, 4c00h
  320. int 21h
  321.  
  322. ; ---------------------------------------------------------------------------
  323.  
  324. IsWinDOS:
  325. mov ax, 1600h
  326. int 2fh
  327. cmp al, 01h
  328. jz @@9
  329. cmp al, 0ffh
  330. jz @@9 ; Windows/386 Version 2.X
  331. cmp al, 00h
  332. jz @@1
  333. cmp al, 80h
  334. jnz @@9 ; Windows 3 in enhanced mode
  335. ; Version number in AL/AH
  336. @@1:
  337. mov ax, 4680h
  338. int 2fh
  339. cmp al, 80h
  340. jnz @@9
  341. xor ax, ax
  342. jmp @@10
  343. @@9: mov ax, 1
  344. @@10: ret
  345.  
  346. ; -----------------------------------------------------------------------
  347. RestoreSelfIntVec:
  348. cmp Copies, '0'
  349. jz @@0
  350. ret
  351. @@0:
  352. cli
  353. push cs
  354. pop ds
  355. xor ax, ax
  356. mov es, ax
  357. mov si, offset oldInt9_Addr
  358. mov di, 9*4
  359. movsw
  360. movsw
  361. mov si, offset oldInt2F_Addr
  362. mov di, 2Fh*4
  363. movsw
  364. movsw
  365. mov si, offset oldInt1C_Addr
  366. mov di, 1Ch*4
  367. movsw
  368. movsw
  369. sti
  370. ret
  371.  
  372. ; ------------- KERNEL PROGRAM ----------------------------------------------
  373. RemoveTSR:
  374. pop ax
  375. cli ; Set stack
  376. mov sp, cs
  377. mov ss, sp
  378. mov sp, 100h
  379. sti
  380. push ax
  381.  
  382. cmp cs:Power, True
  383. jnz @@1
  384. call Init8259
  385. @@1:
  386. push cs
  387. pop ds
  388. @@_0:
  389. mov ax,ds:NextDataSeg
  390. cmp ax, -1
  391. jz @@_1
  392. mov cs:PrevDataSeg, ds
  393. mov ds, ax
  394. jmp @@_0
  395. @@_1: mov si,ds:DataBegin
  396. mov cs:WorkSeg, ds
  397. lodsw
  398. cmp ax, 'XX'
  399. jz @@_2
  400. call Beep
  401. ret
  402. @@_2:
  403. call RestoreEnvStr
  404. call RestoreMCB ; restore current mcb
  405. call CloseFiles
  406. call RestorePort
  407. call RestoreLEDs
  408. call RestoreVecList ; Restore vectors list
  409. call RestoreFloppyParam
  410. cmp cs:Power, True
  411. jnz @@2
  412. call RestoreCVTchain ; Restore cvt chain
  413. call RestoreMemoryManager
  414. @@2:
  415. call RestoreBiosData
  416. call Enable8259
  417. mov ah, 1
  418. int 16h
  419.  
  420. call RestoreClockSpeed
  421. call CloseSpeaker
  422. call ResetDisk
  423. call UpdateTime
  424.  
  425. call ClosePRN
  426. mov bx,cs:WorkSeg
  427. mov ah,50h
  428. int 21h ; Set PSP segment
  429. mov ax,3
  430. int 10h ; Set display mode
  431.  
  432. call InitPRN
  433. call InitMouse
  434. mov al, cs:Copies
  435. cmp al, '1'
  436. ja @@_sh1
  437. mov cs:ShowCopies, '*'
  438. jmp @@_sh2
  439. @@_sh1: mov cs:ShowCopies, al
  440. @@_sh2:
  441. mov si, offset clsStr
  442. call ColorPrintStr
  443. mov cs:Flag, ' ' ; no busy
  444. cmp Copies, '1'
  445. jnz @@_end
  446. mov cs:StopFlag, 0
  447. @@_end:
  448. call ClearKB_buffer
  449. ret
  450.  
  451. Beep:
  452. mov ax,0e07h
  453. int 10h
  454. ret
  455.  
  456. ; #########################################################################
  457.  
  458. ClearKB_Buffer:
  459. push es
  460. push bx
  461. mov bx, 0040h
  462. mov es, bx
  463. cli
  464. mov bx, es:[1ah]
  465. mov es:[1ch], bx
  466. sti
  467. pop bx
  468. pop es
  469. ret
  470.  
  471.  
  472. Init8259:
  473. ; cmp cs:Copies, '1'
  474. ; jz @@1
  475. ; ret
  476. @@1:
  477. cmp cs:MachineID, 0fch
  478. ja @@pc_xt
  479. @@AT:
  480. mov bx,870h ;
  481. mov al,0 ;
  482. out 0F1h,al ;
  483. jcxz $+2
  484. jcxz $+2
  485. mov al,11h ; ICW1
  486. out 0A0h,al
  487. jcxz $+2
  488. jcxz $+2
  489. out 20h,al
  490. jcxz $+2
  491. jcxz $+2
  492. mov al,bl ; ICW2
  493. out 0A1h,al
  494. jcxz $+2
  495. jcxz $+2
  496. mov al,bh
  497. out 21h,al
  498. jcxz $+2
  499. jcxz $+2
  500. mov al,2 ; ICW3
  501. out 0A1h,al
  502. jcxz $+2
  503. jcxz $+2
  504. mov al,4
  505. out 21h,al
  506. jcxz $+2
  507. jcxz $+2
  508. mov al,1 ; ICW4
  509. out 0A1h,al
  510. jcxz $+2
  511. jcxz $+2
  512. out 21h,al
  513. jcxz $+2
  514. jcxz $+2
  515. mov al,0FFh ; OCW1
  516. out 0A1h,al
  517. jcxz $+2
  518. jcxz $+2
  519. out 21h,al
  520. ret
  521. @@PC_XT:
  522. mov al,13h ; ICW1
  523. out 20h,al
  524. jcxz $+2
  525. jcxz $+2
  526. mov al,8 ; ICW2
  527. out 21h,al
  528. jcxz $+2
  529. jcxz $+2
  530. mov al,9 ; ICW4
  531. out 21h,al
  532. jcxz $+2
  533. jcxz $+2
  534. mov al,0FFh ; OCW1
  535. out 21h,al
  536. ret
  537.  
  538. Enable8259:
  539. mov ax, word ptr cs:old_8259
  540. out 021h,al
  541. jcxz $+2
  542. jcxz $+2
  543. mov al,ah
  544. out 0a1h,al ; DEC PC Bus Mouse
  545. ret ; July 1994 by Mr. Lei
  546.  
  547. ; -------------------------------------------------------------------------
  548.  
  549. RestoreBiosData:
  550. lodsw
  551. cmp ax, '--'
  552. jz @@1
  553. call Beep
  554. ret
  555. @@1: push es
  556. push di
  557. mov di, 40h
  558. mov es, di
  559.  
  560. mov di, 10h
  561. movsw
  562. mov di, 0a8h ; [40h:a8h]
  563. movsw
  564. movsw
  565. mov di, 49h
  566. mov cx, 1dh
  567. rep movsb
  568.  
  569. mov di, 0f0h ; User data
  570. mov cx, 8
  571. rep movsw
  572.  
  573. pop di
  574. pop es
  575. ret
  576.  
  577. ; -------------------------------------------------------------------------
  578.  
  579. RestoreMCB:
  580. push ds
  581. push es
  582. lodsw ; 'MZ'
  583. @@0: lodsw
  584. cmp ax, 'MM'
  585. jz @@1
  586. mov es,ax
  587. xor di,di
  588. movsb
  589. movsw
  590. movsw
  591. inc ax
  592. mov bx, ds
  593. cmp ax, bx
  594. jz @@10
  595. mov byte ptr es:[8], 0 ; Aug 24, 1993
  596. @@10: cmp byte ptr es:[0], 'Z'
  597. jnz @@0
  598. mov byte ptr es:[10h], 0
  599. jmp @@0
  600. @@1:
  601. pop es
  602. pop ds
  603. ret
  604.  
  605. ; -------------------------------------------------------------------------
  606. CloseFiles:
  607. mov ax, 5 ; Begin handle
  608. push ds
  609. push si
  610. mov cx, 15 ; Max handle
  611. sub cx, ax
  612. inc cx
  613. mov bx, ax
  614. @@1: push bx
  615. push cx
  616. mov ah, 3eh
  617. int 21h
  618. pop cx
  619. pop bx
  620. inc bx
  621. loop @@1
  622. pop si
  623. pop ds
  624. ret
  625.  
  626. ; -------------------------------------------------------------------------
  627. RestorePort:
  628. mov di, 40h ; restore port
  629. mov es, di
  630. xor di, di
  631. mov cx, 8
  632. rep movsw
  633. ret
  634.  
  635. ; -------------------------------------------------------------------------
  636. RestoreLEDs:
  637. lodsb
  638. and al, 11110000b ; LED status
  639. mov ah, es:[17h]
  640. and ah, 00001111b
  641. or ah, al
  642. and ah, 0f0h ; Clear CTRL ALT SHIFT
  643. mov es:[17h], ah
  644. ret
  645.  
  646. ; -------------------------------------------------------------------------
  647. RestoreEnvStr:
  648. lodsw
  649. push si
  650. push di
  651. push ds
  652. push es
  653. mov es, cs:DosEnv
  654. mov ds, ax
  655. xor si, si
  656. mov di, si
  657. @@0: lodsb
  658. or al, al
  659. jnz @@1
  660. cmp byte ptr ds:[si], 0
  661. jz @@2
  662. @@1: stosb
  663. jmp @@0
  664. @@2: stosb
  665. stosb
  666. pop es
  667. pop ds
  668. pop di
  669. pop si
  670. ret
  671.  
  672. ; -----------------------------------------------------------------------
  673. RestoreVecList:
  674. xor ax,ax
  675. mov di,ax
  676. mov es,ax
  677. mov cx,100h
  678. @@0: lodsw
  679. xchg dx, ax
  680. lodsw
  681. cmp dx, 'EL'
  682. jnz @@1
  683. cmp al, 'I'
  684. jnz @@1
  685. sub cl, ah
  686. push cx
  687. mov cl, ah
  688. mov ax, es:[di-4]
  689. mov dx, es:[di-2]
  690. @@a: stosw
  691. xchg ax, dx
  692. stosw
  693. xchg ax, dx
  694. loop @@a
  695. pop cx
  696. or cx, cx
  697. jz @@9
  698. jmp @@0
  699. @@1:
  700. xchg ax, dx
  701. stosw
  702. xchg ax, dx
  703. stosw
  704. loop @@0
  705. @@9:
  706. ret
  707.  
  708. ;----------------------------------------------------------------------------
  709. RestoreFloppyParam: ; Mr. Lei 2/10/1992
  710. push es
  711. push ax
  712. xor ax, ax
  713. mov es, ax
  714. mov byte ptr es:[525h], 2
  715. pop ax
  716. pop es
  717. ret
  718.  
  719. ;---------------------------------------------------------------------------
  720. RestoreCVTchain:
  721. lodsw
  722. cmp ax, 'VC'
  723. jz @@_0
  724. call Beep
  725. ret
  726. @@_0:
  727. push ax
  728. push cx
  729. push es
  730.  
  731. ; -----------------------------------------------------------------
  732. lodsw ; DPB
  733. mov di, ax
  734. lodsw
  735. mov es, ax
  736. @@1: lodsb
  737. inc di
  738. stosb
  739. add di, cs:cvtOfs
  740. add di, 10h
  741. movsw
  742. movsw
  743. les di, es:[di+2]
  744. cmp di, -1
  745. jnz @@1
  746.  
  747. ; -----------------------------------------------------------------
  748. lodsw ; DCB
  749. mov di, ax
  750. lodsw
  751. mov es, ax
  752. xor ax, ax
  753. dec ax
  754. stosw
  755.  
  756. ; -----------------------------------------------------------------
  757. lodsw ; Device Driver Chain
  758. mov di, ax
  759. lodsw
  760. mov es, ax
  761. xor cx, cx
  762. @@9: push di
  763. mov cl, 5
  764. rep movsw
  765. pop di
  766. les di, es:[di]
  767. mov ax, di
  768. inc ax
  769. jnz @@9
  770. pop es
  771. pop cx
  772. pop ax
  773. ret
  774.  
  775. ; ----------------------------------------------------------------------------
  776. RestoreMemoryManager:
  777. test cs:Status, XMSbit
  778. jz @@1
  779. call LoadXMSstatus
  780. @@1:
  781. test cs:Status, EMSbit
  782. jz @@2
  783. call LoadEMSstatus
  784. @@2:
  785. ret
  786.  
  787.  
  788. LoadEMSstatus:
  789. lodsw
  790. cmp ax, 'ME'
  791. jz @@_0
  792. call Beep
  793. ret
  794. @@_0:
  795. lodsw
  796. mov cx, ax
  797. xor dx, dx
  798. @@_1: push ds
  799. push si
  800. push dx
  801. push cx
  802.  
  803. @@0: cmp dx, ds:[si]
  804. jz @@1
  805. add si, 4
  806. loop @@0
  807.  
  808. push cx
  809. mov cx, 5
  810. @@__0: mov ah, 45h ; Deallocate Handle and Memory
  811. int 67h
  812. or ah, ah
  813. jz @@__1
  814. loop @@__0
  815. @@__1: pop cx
  816.  
  817. @@1:
  818. pop cx
  819. pop dx
  820. pop si
  821. pop ds
  822. inc dx
  823. cmp dx, 100h
  824. jb @@_1
  825. shl cx, 1
  826. shl cx, 1
  827. add si, cx
  828. ret
  829.  
  830.  
  831. LoadXMSstatus:
  832. lodsw
  833. cmp ax, 'MX'
  834. jz @@_0
  835. call Beep
  836. ret
  837. @@_0:
  838. lodsw
  839. mov cx, ax
  840. jcxz @@5
  841. @@1:
  842. lodsw
  843. mov dx, ax
  844. @@2: push dx
  845. mov ah, 0ah ; free
  846. call dword ptr cs:xms_control
  847. or ax, ax
  848. pop dx
  849. jnz @@4
  850. cmp bl, 0abh
  851. jnz @@4
  852. push dx
  853. mov ah, 0dh ; unlock
  854. call dword ptr cs:xms_control
  855. or ax, ax
  856. pop dx
  857. jmp @@2
  858. @@4: loop @@1
  859. @@5: ret
  860. endp
  861.  
  862. ; -----------------------------------------------------------------------
  863. CloseSpeaker:
  864. in al, 61h
  865. and al, 0fch
  866. out 61h, al
  867. ret
  868.  
  869. ; -----------------------------------------------------------------------
  870. RestoreClockSpeed:
  871. mov al, 00110110b
  872. out 43h, al
  873. xor ax, ax
  874. out 40h, al
  875. out 40h, al
  876. ret
  877.  
  878. ; -----------------------------------------------------------------------
  879. ResetDisk:
  880. xor ax, ax
  881. xor dx, dx
  882. int 13h ; Restore A
  883. inc dx
  884. int 13h ; Restore B
  885. mov dl, 80h
  886. int 13h ; Restore C
  887. ret
  888.  
  889.  
  890.  
  891. ; --------------------------------------------------------------------------
  892. ClosePRN:
  893. mov ah, 51h ; Get PSP seg
  894. int 21h
  895. mov es, bx
  896. mov ax, es:[16h] ; Prev PSP seg
  897. cmp ax, bx
  898. jnz @@9
  899. mov ax, 3e00h ; COMMAND
  900. mov bx, 4
  901. int 21h
  902. @@9:
  903. ret
  904.  
  905. InitPRN:
  906. mov ax, 3e00h
  907. mov bx, 4 ; PRN
  908. int 21h
  909. mov ax, 3d01h
  910. mov dx, offset PRNname
  911. push cs
  912. pop ds
  913. int 21h
  914. ret
  915. PRNname db 'PRN',0
  916.  
  917. InitMouse: ; 2/16/1993 by Mr. Lei
  918. push es
  919. xor ax, ax
  920. mov es, ax
  921. cmp word ptr es:[33h*4+2], 0
  922. jz @@0
  923. cmp word ptr es:[33h*4], 0
  924. jz @@0
  925. mov ax, 21h
  926. int 33h ; Hook Mouse Interrupt
  927. @@0: pop es
  928. ret
  929.  
  930. ; ------------- CMOS CLOCK set to System -----------------------------------
  931. UpdateTime:
  932. call GetRealTime
  933. mov ah, 2dh
  934. int 21h
  935. ret
  936.  
  937. GetRealTime:
  938. mov ah,2
  939. int 1Ah
  940. mov al,ch
  941. call bcdxchg
  942. mov ch,al
  943. mov al,cl
  944. call bcdxchg
  945. mov cl,al
  946. mov al,dh
  947. call bcdxchg
  948. mov dh,al
  949. mov dl,0
  950. ret
  951.  
  952. BCDxchg:
  953. push ax
  954. push cx
  955. mov cl,4
  956. shr al,cl
  957. pop cx
  958. mov bl,0Ah
  959. mul bl
  960. pop bx
  961. and bl,0Fh
  962. add al,bl
  963. ret
  964.  
  965. ; -----------------------------------------------------------------------
  966. ; Display string
  967. ColorPrintStr:
  968. lodsb
  969. mov bh, al ; color
  970. xor cx, cx
  971. mov dx, 014fh
  972. mov ax, 0600h
  973. int 10h
  974.  
  975. mov ah, 02 ; GotoXY (0, 0)
  976. xor dx, dx
  977. mov bh, 0
  978. int 10h
  979. PrintStr:
  980. push cs
  981. pop ds
  982. xor bx, bx
  983. @@1: lodsb
  984. cmp al, '$'
  985. jz @@2
  986. or al, al
  987. jz @@2
  988. mov ah, 0eh
  989. int 10h
  990. jmp short @@1
  991. @@2: mov al, cs:clsStrcolor
  992. mov cs:clsStr, al
  993. ret
  994.  
  995. ; -----------------------------------------------------------------------
  996. Self dw 0
  997. clsStrcolor db 17h
  998. clsStr db 17h ; Color (White in Blue)
  999. db ' RAMinit Version 2.12 (c) 1989-1994 by KingSoft Ltd. Mr. Leijun'
  1000. db 0dh,0ah
  1001. db ' ['
  1002. ShowCopies db '*'
  1003. db '] Activate...',0ah,0dh,'$'
  1004.  
  1005. endTSR equ $
  1006. mcbList equ offset endTSR + 2 + 2
  1007. vecList equ mcbList + 7*10 + 2 + 10h + 1 + 400h
  1008. devLink equ vecList + 4 + 5 * 26 + 4 + 10 * 30h + 4
  1009. xmsList equ devLink + 2 + MaxHandles * 2
  1010. emsList equ xmsList + 4 + 1024
  1011. crtMode equ emsList + 2 + 1Dh + 4 + 10h
  1012. tsrLen equ crtMode + 1
  1013. ;
  1014. ; DOS Environment Reserved by RI
  1015. ; --------------------------------------------------
  1016. ; Flag 'XX' 2 bytes
  1017. ; Environment Segment 1 word
  1018. ; Free MCBs <=7*10 bytes
  1019. ; MCB segment 1 word
  1020. ; MCB 5 bytes
  1021. ; End flag 'MM' 1 word
  1022. ; COM LPT ports 10h bytes
  1023. ; LEDs status 1 bytes
  1024. ; Packed vectors list <=400h bytes
  1025. ; Flag 'CV' 2 bytes
  1026. ; CVT First DPB pointer 4 bytes
  1027. ; DPBs data <=5*26 bytes
  1028. ; First DCB pointer 4 bytes
  1029. ; Pointer to NUL 4 bytes
  1030. ; All device driver datas <=30h*10 bytes
  1031. ; Flag 'XM' 2 bytes
  1032. ; XMS free handle counter 2 bytes
  1033. ; EMS free handle list <=100h*4 bytes
  1034. ; Flag 'EM' 2 bytes
  1035. ; EMS free handle counter 2 bytes
  1036. ; EMS free handle list <=1024 bytes
  1037. ; EMS handle 1 word
  1038. ; Number of pages 1 word
  1039. ; Flag '--' 1 word
  1040. ; Equipment List 1 word
  1041. ; CRT 40:49h-66h 1dh bytes
  1042. ; 40:A8h 1 dword
  1043. ; BIOS User Data Area 40:F0--FF 10h bytes
  1044. ; ***************************************************************************
  1045. ;
  1046. main: jmp main0
  1047.  
  1048. Print Macro Str
  1049. Lea dx, Str
  1050. call DisplayStr
  1051. endm
  1052.  
  1053. InstMsg db 'RAMinit Version 2.12 '
  1054. db 'Copyright (c) 1989-1994 by KingSoft Ltd. ',0dh,0ah,'$'
  1055. Msg0 db 'Already installed !',0dh,0ah,0ah
  1056. db 'For Help, type "RI /?". ',0dh,0ah,'$'
  1057. Msg_0 db 0ah,'Residents a new RAMinit copy [y/n] ? $'
  1058. Msg_2 db 'OK, RI No.'
  1059. Msg_RI db '2'
  1060. db ' residents successful !', 0dh,0ah,'$'
  1061. Msg1 db 'Activate with: $'
  1062. KeyMsg db 'Right_Shift$'
  1063. db 'Left_Shift$ '
  1064. KMsg1 db 'Left_Ctrl$ '
  1065. db 'Left_Alt$ '
  1066. db 'Right_Ctrl$ '
  1067. db 'Right_Alt$ '
  1068. KMsg2 db 'Ctrl$ '
  1069. db 'Alt$ '
  1070. db 'Ctrl$ '
  1071. db 'Alt$ '
  1072. PlusMsg db ' + $'
  1073. crlf db 0dh,0ah,'$'
  1074.  
  1075. HelpMsg db 'Programmed by Mr. Leijun Dec 1992', 0dh,0ah,0ah
  1076. db 'Usage: RI [options]',0dh,0ah,0ah
  1077. db '/H,/? Display this screen',0dh,0ah
  1078. db '/CLS Removes all TSR programs after current RI',0dh,0ah
  1079. db '/RET Removes TSR programs include current RI',0dh,0ah
  1080. db '/NEW Residents a new data copy of current environment',0dh,0ah
  1081. db '/ALL Removes all RI copies and all other tsr programs',0dh,0ah
  1082. db '/Sxyy.. Define Hotkey x=AuxHotkey yy..=shift status',0dh,0ah
  1083. db ' x=auxiliary hotkey (default is "X") ',0dh,0ah
  1084. db ' x equ "1" means need AuxHotkey',0dh,0ah
  1085. db ' yy..=shift status [CAScas]',0dh,0ah
  1086. db ' C: Left Ctrl A: Left Alt S: Left Shift',0dh,0ah
  1087. db ' c: Right Ctrl a: Right Alt s: Right Shift',0dh,0ah,0ah
  1088. db 'Example: "RI /S1c" means Hotkey is Right_Ctrl+X',0dh,0ah
  1089. db ' "RI /S0Cc" means HotKey is Left_Ctrl+Right_Ctrl',0dh,0ah
  1090. db ' "RI /CLS" equals simply press hotkey',0dh,0ah
  1091. db ' "RI /RET" Removes all TSRs after current RI and this RI',0dh,0ah
  1092. db 0ah
  1093. db 'Contact me for RAMinit problems: (01)2561155 Call 1997',0dh,0ah
  1094. db '$'
  1095. ErrMsg db 'ERROR: Invalid options !',0dh,0ah,0ah,'$'
  1096. WinErr db 7, 'Sorry, I cannot work in Windows DOS environment.',0dh,0ah,'$'
  1097. SetMsg db 7, 'Defines new Hotkey successful !',0dh,0ah,0ah,'$'
  1098. tsrOK db False
  1099.  
  1100. Main0:
  1101. cld
  1102. Print instMsg
  1103. call IsWinDos
  1104. or ax, ax
  1105. jz @@1
  1106. Print WinErr
  1107. mov ax, 4c00h
  1108. int 21h
  1109. @@1:
  1110. call HotKeyValid
  1111. mov cs:Status, 0
  1112. call EMS_test
  1113. call CmpDosVer
  1114. call CmpSideKick
  1115. call GetMachineID
  1116. call ModifyHotKeyPrompt
  1117.  
  1118. mov ax, 0c0d7h
  1119. int 2fh
  1120. mov es, ax
  1121. cmp word ptr es:[101h], 'IE' ; 'LEI'
  1122. jnz @@0
  1123. mov cs:Self, ax
  1124. @@0:
  1125. call CmdLine
  1126. call PrintHotKeyPrompt
  1127.  
  1128. cmp cs:tsrOK, true
  1129. jz @@2
  1130. call tsrReplyOK
  1131. @@2: cmp cs:tsrOK, true
  1132. jnz @@_2
  1133. call PrintCopies
  1134. @@_2:
  1135. mov word ptr cs:[100h], 'EL'
  1136. mov byte ptr cs:[102h], 'I'
  1137.  
  1138. push cs
  1139. pop es
  1140. push cs
  1141. pop ds
  1142. std
  1143. mov si, offset eof
  1144. mov cx, eof - offset Here
  1145. mov di, tsrLen
  1146. add di, cx
  1147. inc cx
  1148. rep movsb
  1149. cld
  1150. mov bx, tsrLen
  1151. jmp bx
  1152.  
  1153. Here:
  1154. mov ax,cs
  1155. mov es,ax
  1156. mov di,offset endTSR
  1157. mov cs:DataBegin, di
  1158. mov cs:NextDataSeg, -1
  1159. mov ax, 'XX'
  1160. stosw
  1161. in al, 0a1h
  1162. mov ah, al
  1163. in al, 21h
  1164. push ax
  1165. mov word ptr cs:old_8259, ax
  1166. xor ax, ax
  1167. out 21h,al ; CLI
  1168. call SaveOthers
  1169. call SetSelfInt
  1170. call BackupVecList
  1171. cmp cs:Power, true
  1172. jnz @@20
  1173. call BackupCVTchain
  1174. call BackupMemoryManager
  1175. @@20:
  1176. call BackupBiosData
  1177.  
  1178. sti
  1179. mov cs:Flag, ' ' ; no busy
  1180. mov cs:StopFlag, 0 ;
  1181.  
  1182. mov cs:tsrLength, di
  1183. call SetDosEnvSeg
  1184. cmp cs:Self, 0
  1185. jz @@29
  1186. push cs
  1187. pop ds
  1188. push cs
  1189. pop es
  1190. cld
  1191. mov cx, cs:tsrLength
  1192. mov si, cs:DataBegin
  1193. sub cx, si
  1194. mov di, 120h
  1195. mov cs:DataBegin, di
  1196. rep movsb
  1197. mov cs:tsrLength, di
  1198. @@29:
  1199. pop ax
  1200. out 21h, al ; STI
  1201. mov al, ah
  1202. out 0a1h, al
  1203. mov dx, cs:tsrLength
  1204. inc dx
  1205. int 27h
  1206.  
  1207. ; ----------------------------------------------------------------------------
  1208. SetDosEnvSeg:
  1209. push ds
  1210. push es
  1211. mov ax, cs
  1212. @@10: mov es, ax
  1213. mov ax, es:[16h] ; Get father process psp segment
  1214. or ax, ax
  1215. jz @@11
  1216. mov bx, es
  1217. cmp ax, bx
  1218. jnz @@10
  1219. @@11:
  1220. mov es, word ptr es:[2ch] ; Get father process env segment
  1221. mov cs:DosEnv, es
  1222. pop es
  1223. pop ds
  1224. ret
  1225.  
  1226. ; ----------------------------------------------------------------------------
  1227.  
  1228. SaveOthers:
  1229. mov ax, cs:[2ch] ; Env Seg
  1230. stosw
  1231. call backupMCB ; Current MCB
  1232. mov ax, 40h ; COM LPT Port
  1233. mov ds, ax
  1234. mov si, 0h
  1235. mov cx, 8
  1236. rep movsw
  1237.  
  1238. mov si, 17h ; LED status
  1239. lodsb
  1240. stosb
  1241. ; call OpenLEDs
  1242. ret
  1243.  
  1244. ; --------------------------------------------------------------------------
  1245. backupMCB:
  1246. mov ax, 'ZM'
  1247. stosw
  1248. push ds
  1249. push es
  1250. mov ah, 52h
  1251. int 21h ; Get MCB chain head
  1252. mov ax, es:[bx-2]
  1253. pop es
  1254. @@0: mov ds, ax
  1255. cmp byte ptr ds:[0], 'Z' ; End ?
  1256. jz @@20
  1257. cmp byte ptr ds:[0], 'M' ; Memory control block
  1258. jnz @@30
  1259. cmp word ptr ds:[3], 0 ; Nul mcb
  1260. jz @@10
  1261. cmp word ptr ds:[1], 0 ; Free MCB
  1262. jnz @@10
  1263. call SaveFreeMCB
  1264. @@10: inc ax
  1265. add ax, ds:[3]
  1266. jmp @@0
  1267. @@20:
  1268. call SaveFreeMCB
  1269. cmp ax, 0a000h
  1270. inc ax
  1271. jnb @@30
  1272. mov ax, 9fffh ; MS-DOS UMB
  1273. jmp @@0
  1274.  
  1275. @@30:
  1276. cmp ax, 0c000h ; 386MAX
  1277. ja @@90
  1278. mov ax, 0c020h
  1279. jmp @@0
  1280.  
  1281. @@90: ; Error ?
  1282. pop ds
  1283. mov ax, 'MM' ; Set MCB flag
  1284. stosw
  1285. ret
  1286.  
  1287. SaveFreeMCB:
  1288. stosw
  1289. xor si,si
  1290. movsb
  1291. movsw
  1292. movsw
  1293. ret
  1294. ;
  1295. ; push ax
  1296. ; stosw
  1297. ; xor si,si
  1298. ; movsb
  1299. ; movsw
  1300. ; movsw
  1301. ; pop ax
  1302. ; cmp ax, 09fffh
  1303. ; jnb @@3
  1304. ; push ax
  1305. ; push ds
  1306. ; mov ds,ax
  1307. ; cmp byte ptr ds:[0], 'M'
  1308. ; pop ds
  1309. ; pop ax
  1310. ; jnz @@4
  1311. ; mov ax, 09fffh ; MS-DOS UMB
  1312. ; jmp @@0
  1313. ; @@4: cmp ax, 0c000h
  1314. ; ja @@3
  1315. ; mov ax, 0c020h ; 386MAX
  1316. ; jmp @@0
  1317. ;
  1318. ; --------------------------------------------------------------------------
  1319.  
  1320. OpenLEDs: push ax ; Open all LEDs
  1321. or al, 070h
  1322. mov ds:[17h], al
  1323. mov ah, 1
  1324. int 16h
  1325. mov cx, 4 ; Delay
  1326. @@20: push cx
  1327. xor cx, cx
  1328. @@21: loop @@21
  1329. pop cx
  1330. loop @@20
  1331. pop ax
  1332. mov ds:[17h], al
  1333. mov ah, 1
  1334. int 16h
  1335. ret
  1336.  
  1337. ; --------------------------------------------------------------------------
  1338. SetSelfInt:
  1339. push es
  1340. push di
  1341.  
  1342. cmp cs:self, 0
  1343. jnz @@1
  1344. push cs
  1345. pop ds
  1346. mov ax,3509h
  1347. int 21h
  1348. mov word ptr cs:oldInt9_addr,bx
  1349. mov word ptr cs:oldInt9_addr[2],es
  1350. mov dx,offset NewInt9
  1351. mov ax,2509h
  1352. int 21h
  1353.  
  1354. mov ax,352Fh
  1355. int 21h
  1356. mov word ptr cs:oldInt2F_addr,bx
  1357. mov word ptr cs:oldInt2F_addr[2],es
  1358. mov dx,offset newInt2F
  1359. mov ax,252Fh
  1360. int 21h
  1361.  
  1362. mov ax,351Ch
  1363. int 21h
  1364. mov word ptr cs:oldInt1C_addr,bx
  1365. mov word ptr cs:oldInt1C_addr[2],es
  1366. mov dx,offset newInt1C
  1367. mov ax,251ch
  1368. int 21h
  1369. cli
  1370. jmp @@2
  1371. @@1:
  1372. mov es, cs:Self
  1373. inc es:Copies
  1374. @@_0: cmp es:NextDataSeg, -1
  1375. jz @@_1
  1376. mov es, es:NextDataSeg
  1377. jmp @@_0
  1378. @@_1: mov es:NextDataSeg, cs
  1379. @@2:
  1380. pop di
  1381. pop es
  1382. ret
  1383.  
  1384. ; -----------------------------------------------------------------------
  1385. SaveCounter:
  1386. mov word ptr es:[di], 'EL'
  1387. mov byte ptr es:[di+2], 'I'
  1388. mov byte ptr es:[di+3], bl
  1389. xor bx, bx
  1390. add di, 4
  1391. ret
  1392.  
  1393. ; -----------------------------------------------------------------------
  1394. DisplayStr: push cs
  1395. pop ds
  1396. mov ah, 9
  1397. int 21h
  1398. ret
  1399.  
  1400. ; -----------------------------------------------------------------------
  1401. CmdLine:
  1402. push cs
  1403. pop ds
  1404. xor ax, ax
  1405. mov si, 80h
  1406. lodsb
  1407. or al, al
  1408. jnz @@1
  1409. ret
  1410. @@1:
  1411. mov cx, ax
  1412. dec ax
  1413. push ax
  1414. push si
  1415. @@0: lodsb
  1416. cmp al, ' '
  1417. jz @@0
  1418. cmp al, '/'
  1419. jnz @@2
  1420. lodsb
  1421. cmp al, 'S'
  1422. jz @@_2
  1423. cmp al, 's'
  1424. jnz @@2
  1425. @@_2:
  1426. call SetHotKey
  1427. Print SetMsg
  1428. mov ax, 4c00h
  1429. int 21h
  1430. @@2:
  1431. pop si
  1432. pop ax
  1433. push ax
  1434. push si
  1435. @@_3: lodsb
  1436. cmp al, 'A'
  1437. jb @@3
  1438. cmp al, 'Z'
  1439. ja @@3
  1440. add byte ptr ds:[si-1],20h ; DownCase
  1441. @@3: loop @@_3
  1442. pop si
  1443. pop cx
  1444.  
  1445. add si, cx
  1446. lodsb
  1447. cmp al, 's' ; CLS
  1448. jnz @@5
  1449. cmp word ptr ds:[si-3], 'lc'
  1450. jnz @@5
  1451. cmp cs:Self, 0
  1452. jz @Err
  1453. mov ax, 0c0d7h+1
  1454. int 2fh
  1455.  
  1456. @@5: cmp al, 'h' ; HELP
  1457. jz @help
  1458. cmp al, '?'
  1459. jz @help
  1460. cmp al, 't' ; RET
  1461. jnz @@6
  1462. cmp word ptr ds:[si-3], 'er'
  1463. jnz @@6
  1464. @@7:
  1465. cmp cs:Self, 0
  1466. jz @Err
  1467. mov ax, 0c0d7h+2
  1468. int 2fh
  1469. @@6: cmp al, 'w' ; NEW
  1470. jnz @@8
  1471. cmp word ptr ds:[si-3], 'en'
  1472. jnz @@8
  1473. mov cs:tsrOK, true
  1474. ret
  1475. @@8:
  1476. cmp al, 'l' ; ALL
  1477. jnz @@9
  1478. cmp word ptr ds:[si-3], 'la'
  1479. jnz @@9
  1480. mov ax, 0c0d7h+3
  1481. int 2fh
  1482. @@9:
  1483. cmp al, ' '
  1484. jnz @Err
  1485. ret
  1486.  
  1487. @Err:
  1488. Print ErrMsg
  1489. @help:
  1490. Print HelpMsg
  1491. mov ax, 4c00h
  1492. int 21h
  1493.  
  1494. ;---------------------------------------------------------------------------
  1495. tsrReplyOK:
  1496. cmp cs:Self, 0
  1497. jz @@1
  1498. Print Msg0
  1499.  
  1500. push es
  1501. mov ax, cs:Self
  1502. @@_10: mov es, ax
  1503. mov ax, es:NextDataSeg
  1504. cmp ax, -1
  1505. jnz @@_10
  1506. mov ax, es
  1507.  
  1508. @@_0: push ax
  1509. dec ax
  1510. mov es, ax
  1511. mov bx, es:[3]
  1512. pop ax
  1513.  
  1514. add ax, bx
  1515. inc ax
  1516. mov es, ax
  1517. cmp word ptr es:[0], 'OC'
  1518. jz @@_0
  1519.  
  1520. mov bx, cs
  1521. cmp ax, bx
  1522. pop es
  1523. jz @@2
  1524. Print Msg_0
  1525. mov ah, 1
  1526. int 21h
  1527.  
  1528. push ax
  1529. Print crlf
  1530. pop ax
  1531.  
  1532. cmp al, 'y'
  1533. jz @@3
  1534. cmp al, 'Y'
  1535. jz @@3
  1536. @@2: ; Print Msg_1
  1537. mov ax, 4c01h
  1538. int 21h
  1539. @@3:
  1540. @@1: mov cs:tsrOK, true
  1541. ret
  1542.  
  1543. PrintCopies:
  1544. cmp cs:Self, 0
  1545. jz @@1
  1546. push es ; Added -by- Mr. Lei
  1547. mov es, cs:Self ; Aug 24, 1993
  1548. mov al, es:Copies
  1549. inc al ; Total RI copies
  1550. push ax ; Set es = current mcb
  1551. mov ax, cs
  1552. dec ax
  1553. mov es, ax
  1554. pop ax
  1555. mov cx, 5 ; Search end of file name
  1556. mov bx, 8
  1557. @@10: inc bx
  1558. cmp byte ptr es:[bx], 20h
  1559. jz @@20
  1560. cmp byte ptr es:[bx], 0ffh
  1561. jz @@20
  1562. cmp byte ptr es:[bx], 00h
  1563. jz @@20
  1564. loop @@10
  1565. @@20: ; Set current RI no
  1566. mov byte ptr es:[bx], ':' ; "RI:2"
  1567. mov byte ptr es:[bx+1], al
  1568. cmp bx, 8+7
  1569. jnb @@30
  1570. mov byte ptr es:[bx+2], 0
  1571. @@30:
  1572. pop es
  1573.  
  1574. mov cs:Msg_RI, al
  1575. Print Msg_2
  1576. @@1: ret
  1577.  
  1578. ;---------------------------------------------------------------------------
  1579. ; Backup Interrupt Vector List
  1580. ;
  1581. BackupVecList:
  1582. push ds
  1583. push cs
  1584. pop es
  1585. xor si,si ; Vectors
  1586. mov ds,si
  1587. movsw
  1588. movsw
  1589. xor bx, bx
  1590. mov cx,00ffh
  1591. @@0: lodsw
  1592. xchg dx, ax
  1593. lodsw
  1594. cmp ax, es:[di-2]
  1595. jnz @@1
  1596. cmp dx, es:[di-4]
  1597. jz @@2
  1598. @@1: or bx, bx
  1599. jz @@3
  1600. call SaveCounter
  1601. @@3: xchg dx, ax
  1602. stosw
  1603. xchg dx, ax
  1604. stosw
  1605. loop @@0
  1606. jmp @@4
  1607. @@2: inc bx
  1608. loop @@0
  1609. call SaveCounter
  1610. @@4:
  1611. pop ds
  1612. ret
  1613. ;
  1614. ;-----------------------------------------------------------------------------
  1615. BackupCVTchain:
  1616. mov ax, 'VC'
  1617. stosw
  1618. push ax
  1619. push bx
  1620. push cx
  1621. push ds
  1622. push es
  1623. mov ah, 52h
  1624. int 21h ; ES:BX -- DOS table as described below
  1625.  
  1626. ; --------------------------------------------------------------------
  1627. push es ; DPB chains
  1628. push bx
  1629. lds si, es:[bx]
  1630. push cs
  1631. pop es
  1632. mov ax, si
  1633. stosw
  1634. mov ax, ds
  1635. stosw
  1636. mov bx, cs:cvtOfs
  1637. xor cx, cx
  1638. @@1: mov al, ds:[si+1]
  1639. stosb
  1640. mov ax, ds:[si+bx+12h]
  1641. stosw
  1642. mov ax, ds:[si+bx+14h]
  1643. stosw
  1644. inc cx
  1645. lds si, ds:[si+bx+18h]
  1646. cmp si, -1
  1647. jnz @@1
  1648. ; mov ax, 5
  1649. ; mul cl
  1650. ; add ax, 4
  1651. ; add cs:tsrLength, ax
  1652. pop bx
  1653. pop es
  1654.  
  1655. ; --------------------------------------------------------------------
  1656. push es ; DCB file control blocks
  1657. push bx
  1658. les bx, es:[bx+4]
  1659. @@11: cmp word ptr es:[bx], -1
  1660. jz @@10
  1661. les bx, es:[bx]
  1662. jmp @@11
  1663. @@10:
  1664. mov ax, es
  1665. xchg ax, bx
  1666. push cs
  1667. pop es
  1668. stosw
  1669. xchg ax, bx
  1670. stosw
  1671. pop bx
  1672. pop es
  1673. ; add cs:tsrLength, 4
  1674.  
  1675. ; ---------------------------------------------------------------------
  1676. push es ; Device Driver Chains
  1677. pop ds
  1678. add bx, 22h
  1679. mov si, bx ; NUL
  1680.  
  1681. pop es
  1682. mov ax, si
  1683. stosw
  1684. mov ax, ds
  1685. stosw
  1686. xor cx, cx
  1687. xor bx, bx
  1688. @@9: push si
  1689. mov cl, 5
  1690. rep movsw
  1691. inc bx
  1692. pop si
  1693. lds si, ds:[si]
  1694. mov ax, si
  1695. inc ax
  1696. jnz @@9
  1697.  
  1698. pop ds
  1699. pop cx
  1700. pop bx
  1701. pop ax
  1702. ret
  1703.  
  1704. ; ----------------------------------------------------------------------------
  1705.  
  1706. BackupBiosData:
  1707. mov ax, '--'
  1708. stosw
  1709. push ds
  1710. push si
  1711. mov si, 40h
  1712. mov ds, si
  1713. mov si, 10h
  1714. movsw
  1715. mov si, 0a8h
  1716. movsw
  1717. movsw
  1718. mov si, 49h
  1719. mov cx, 1dh
  1720. rep movsb
  1721.  
  1722. mov si, 0f0h
  1723. mov cx, 8
  1724. rep movsw
  1725. pop si
  1726. pop ds
  1727. ret
  1728.  
  1729. ; ---------------------------------------------------------------------------
  1730.  
  1731. BackupMemoryManager:
  1732. push cs
  1733. pop es
  1734. push ds
  1735. push es
  1736. call SaveXMSstatus
  1737. call SaveEMSstatus
  1738. pop es
  1739. pop ds
  1740. ret
  1741.  
  1742. ;---------------------------------------------------------------------
  1743.  
  1744. SaveEMSstatus:
  1745. test cs:status, EMSbit
  1746. jnz @@1
  1747. ret
  1748. @@1:
  1749. mov ax, 'ME'
  1750. stosw
  1751. inc di
  1752. inc di
  1753. push di
  1754. mov ah, 4dh
  1755. int 67h
  1756. pop di
  1757. mov es:[di-2], bx
  1758. shl bx, 1
  1759. shl bx, 1
  1760. add di, bx
  1761. ret
  1762. ; -------------------------------------------------------------------
  1763.  
  1764. SaveXMSstatus:
  1765. call XMS_test
  1766. test cs:status, XMSbit
  1767. jnz @@1
  1768. ret
  1769. @@1:
  1770. mov ax, 'MX'
  1771. stosw
  1772.  
  1773. mov dx, 1
  1774. call XMS_alloc
  1775. jnz @@_1
  1776. xor cx, cx ; XMS alloc failure
  1777. stosw
  1778. ret
  1779. @@_1:
  1780. push dx
  1781. sub dx, MaxHandles * 10
  1782. @@2:
  1783. push dx
  1784. call XMS_Lock
  1785. pop dx
  1786. jnz @@3
  1787. cmp bl, 0a2h
  1788. jnz @@4
  1789. add dx, 10
  1790. jmp @@2
  1791. @@3: push dx
  1792. call XMS_unlock
  1793. pop dx
  1794. @@4:
  1795. mov cs:handle_begin, dx
  1796. pop dx
  1797. push dx
  1798. call XMS_bstat
  1799. xor cx, cx
  1800. mov cl, bl
  1801. inc cx
  1802. pop dx
  1803. call XMS_Free
  1804. mov dx, cs:Handle_begin
  1805.  
  1806. push cx
  1807. push cs
  1808. pop es
  1809. mov ax, cx
  1810. stosw
  1811. @@5: push dx
  1812. call XMS_Lock
  1813. pop dx
  1814. jnz @@6
  1815. cmp bl, 0a2h ; Handle invalid
  1816. jz @@7
  1817. @@6: call XMS_unlock
  1818. add dx, 10
  1819. jmp @@5
  1820. @@7: mov ax, dx
  1821. stosw
  1822. add dx, 10
  1823. loop @@5
  1824. pop cx
  1825. ret
  1826. ; ------------------------------------------------------------------
  1827.  
  1828. XMS_test:
  1829. push es
  1830. mov ax, 4300h
  1831. int 2fh
  1832. cmp al, 80h
  1833. jnz @@9
  1834. mov ax, 4310h
  1835. int 2fh
  1836. mov cs:XMS_control, bx
  1837. mov cs:XMS_control[2], es
  1838. or cs:Status, XMSbit
  1839. @@9:
  1840. pop es
  1841. ret
  1842.  
  1843. XMS_stat:
  1844. mov ah, 0
  1845. call dword ptr cs:xms_control
  1846. mov hma_exist, dl
  1847. ret
  1848. hma_exist db 0
  1849.  
  1850. XMS_alloc:
  1851. mov ah, 9
  1852. call dword ptr cs:xms_control
  1853. or ax, ax
  1854. ret
  1855.  
  1856. XMS_lock:
  1857. mov ah, 0ch
  1858. call dword ptr cs:xms_control
  1859. or ax, ax
  1860. ret
  1861.  
  1862. XMS_unlock:
  1863. mov ah, 0dh
  1864. call dword ptr cs:xms_control
  1865. or ax, ax
  1866. ret
  1867. XMS_bstat:
  1868. mov ah, 0eh
  1869. call dword ptr cs:xms_control
  1870. or ax, ax
  1871. ret
  1872.  
  1873. XMS_free:
  1874. mov ah, 0ah
  1875. call dword ptr cs:xms_control
  1876. or ax, ax
  1877. ret
  1878.  
  1879. ; ----------------------------------------------------------------------------
  1880. EMS_test:
  1881. push cs
  1882. pop ds
  1883. mov dx, offset EMMname
  1884. mov ax, 3d00h
  1885. int 21h
  1886. jc @@2
  1887. mov bx, ax
  1888. mov ah, 3eh
  1889. int 21h
  1890. or cs:Status, EMSbit
  1891. @@2:
  1892. ret
  1893. EMMname db 'EMMXXXX0',0
  1894.  
  1895. ; -----------------------------------------------------------------------------
  1896.  
  1897. SetHotKey:
  1898. xor bx, bx
  1899. lodsb
  1900. push ax
  1901.  
  1902. @@1: lodsb
  1903. cmp al, 0dh
  1904. jz @@9
  1905. cmp al, 'C'
  1906. jnz @@2
  1907. or bl, LeftCtrl
  1908. jmp @@1
  1909. @@2:
  1910. cmp al, 'c'
  1911. jnz @@3
  1912. or bl, RightCtrl
  1913. jmp @@1
  1914. @@3:
  1915. cmp al, 'A'
  1916. jnz @@4
  1917. or bl, LeftAlt
  1918. jmp @@1
  1919. @@4:
  1920. cmp al, 'a'
  1921. jnz @@5
  1922. or bl, RightAlt
  1923. jmp @@1
  1924. @@5:
  1925. cmp al, 'S'
  1926. jnz @@6
  1927. or bl, LeftShift
  1928. jmp @@1
  1929. @@6:
  1930. cmp al, 's'
  1931. jnz @@7
  1932. or bl, RightShift
  1933. jmp @@1
  1934. @@7: pop ax
  1935. jmp @Err
  1936. @@9:
  1937. mov cs:HotKey, bl
  1938. pop ax
  1939. mov cs:AuxHotKey, 2dh ; 'X' scan key
  1940. cmp al, '1'
  1941. jz @@29
  1942. mov cs:AuxHotKey, 0
  1943. @@29:
  1944. cmp cs:Self, 0
  1945. jz @@30
  1946. push es
  1947. mov es, cs:Self
  1948. mov es:HotKey, bl
  1949. mov bl, cs:AuxHotKey
  1950. mov es:AuxHotKey, bl
  1951. pop es
  1952. @@30:
  1953. call GetRunFileName
  1954. mov ax, 3d02h
  1955. int 21h
  1956. jc @@10
  1957. push cs
  1958. pop ds
  1959. mov bx, ax
  1960. mov cx, 4
  1961. mov dx, 100h
  1962. mov ah, 40h
  1963. int 21h
  1964. jc @@10
  1965. mov ax, 4200h
  1966. xor cx, cx
  1967. mov dx, 17h
  1968. int 21h
  1969. jc @@10
  1970. mov cx, 1
  1971. mov dx, offset AuxHotKey
  1972. mov ah, 40h
  1973. int 21h
  1974. jc @@10
  1975. mov ah, 3eh
  1976. int 21h
  1977. @@10:
  1978. ret
  1979.  
  1980.  
  1981. ; -----------------------------------------------------------------------
  1982. GetRunFileName:
  1983. ; Return:
  1984. ; DS:DX Pointer of this run file name ASCIIZ string
  1985. push ax
  1986. push bx
  1987. push cx
  1988. push si
  1989. push di
  1990. push es
  1991.  
  1992. push cs
  1993. pop es
  1994. mov ax, es:[2ch]
  1995. mov es, ax
  1996. xor di, di
  1997. mov cx, 1000h
  1998. xor al, al
  1999. @@1: repnz scasb
  2000. cmp es:[di], al
  2001. loopnz @@1
  2002. mov dx, di
  2003. add dx, 3
  2004. push es
  2005. pop ds
  2006.  
  2007. pop es
  2008. pop di
  2009. pop si
  2010. pop cx
  2011. pop bx
  2012. pop ax
  2013. ret
  2014.  
  2015. ; ---------------------------------------------------------------------------
  2016. GetMachineID:
  2017. push es
  2018. mov KBD102,True
  2019. mov ax,40h
  2020. mov es,ax
  2021. test byte ptr es:[96h], 00010000b
  2022. jnz @@1
  2023. mov Kbd102,False
  2024. @@1:
  2025. xor ax,ax
  2026. dec ax
  2027. mov es,ax
  2028. mov al,es:[0eh]
  2029. mov cs:MachineID, al
  2030. pop es
  2031. ret
  2032.  
  2033. ; ---------------------------------------------------------------------------
  2034. ModifyHotKeyPrompt:
  2035. cmp cs:Kbd102, True
  2036. jz @@9
  2037. push cs
  2038. pop es
  2039. push cs
  2040. pop ds
  2041. mov cx, 12*4
  2042. mov si, offset KMsg2
  2043. mov di, offset KMsg1
  2044. rep movsb
  2045. @@9: cmp cs:MachineID, 0fch
  2046. jna @@10
  2047. mov cs:clsStrcolor, 70h ; Mono
  2048. mov cs:clsStr, 70h
  2049. @@10:
  2050. ret
  2051.  
  2052. ; ---------------------------------------------------------------------------
  2053. PrintHotKeyPrompt:
  2054. Print Msg1
  2055. mov al, cs:HotKey
  2056. mov ah, al
  2057. shr al, 1
  2058. shr al, 1
  2059. and ax, 33ch
  2060. or al, ah
  2061. mov dx, offset KeyMsg
  2062. @@40:
  2063. or ax, ax ; Mr. Lei 4/25/1993
  2064. jz @@_42
  2065. shr al, 1
  2066. push ax
  2067. jnc @@41
  2068.  
  2069. push ax
  2070. call ColorDisplayStr
  2071. ; mov ah, 9
  2072. ; int 21h
  2073. pop ax
  2074.  
  2075. or al, al
  2076. jz @@42
  2077.  
  2078. push dx
  2079. mov dx, offset PlusMsg
  2080. call ColorDisplayStr
  2081. ; Print PlusMsg
  2082. pop dx
  2083.  
  2084. @@41: add dx, 12
  2085. pop ax
  2086. jmp @@40
  2087. @@42: pop ax
  2088. @@_42: cmp cs:AuxHotKey, 0
  2089. jz @@43
  2090. cmp cs:HotKey, 0 ; Mr. Lei
  2091. jz @@_43
  2092. mov dx, offset PlusMsg
  2093. call ColorDisplayStr
  2094. ; Print PlusMsg
  2095. @@_43: mov dx, offset AuxHotKeyName
  2096. call ColorDisplayStr
  2097. ; Print AuxHotKeyName
  2098. @@43:
  2099. Print crlf
  2100. ret
  2101.  
  2102. ColorDisplayStr:
  2103. push bx
  2104. push cx
  2105. push dx
  2106. push si
  2107. mov bl, 0fh
  2108. mov si, dx
  2109. xor bh, bh
  2110. mov cx, 1
  2111. @@1: lodsb
  2112. cmp al, '$'
  2113. jz @@2
  2114. or al, al
  2115. jz @@2
  2116. push cx
  2117. mov ah, 09h
  2118. int 10h
  2119. mov ah, 3
  2120. int 10h
  2121. inc dl
  2122. mov ah, 2
  2123. int 10h
  2124. pop cx
  2125. jmp short @@1
  2126. @@2:
  2127. pop si
  2128. pop dx
  2129. pop cx
  2130. pop bx
  2131. ret
  2132.  
  2133. ; ---------------------------------------------------------------------------
  2134. CmpSideKick:
  2135. xor ax, ax
  2136. mov es, ax
  2137. les bx, es:[20h]
  2138. cmp word ptr es:[bx-4], 4b53h
  2139. jnz @@1
  2140. cmp word ptr es:[bx-2], 4942h
  2141. jz @@2
  2142. @@1: mov es, ax
  2143. les bx, es:[94h]
  2144. cmp word ptr es:[bx-2], 4b53h
  2145. jz @@2
  2146. ret
  2147. @@2: or cs:Status, SKbit
  2148. ret
  2149.  
  2150. ; ---------------------------------------------------------------------------
  2151. CmpDosVer: mov ah, 30h
  2152. int 21h
  2153. cmp al, 3
  2154. jb @@1
  2155. cmp al, 3
  2156. jna @@2
  2157. mov cs:cvtOfs, 1
  2158. ret
  2159. @@2: mov cs:cvtOfs, 0
  2160. ret
  2161. @@1: Print DosVerErr
  2162. mov ax, 4cffh
  2163. int 21h
  2164.  
  2165. DosVerErr db 'Sorry, DOS version too lower !',0dh,0ah,'$'
  2166.  
  2167. HotKeyValid:
  2168. cmp cs:HotKey, 0
  2169. jnz @@_1
  2170. cmp cs:AuxHotKey, 0
  2171. jnz @@_1
  2172. Print HotKeyErr
  2173. mov ax, 4cfeh
  2174. int 21h
  2175. @@_1: ret
  2176.  
  2177. HotKeyErr db 'Sorry, please setup hotkey again. ',0dh,0ah,'$'
  2178.  
  2179. eof:
  2180. ends
  2181. end Start
  2182.  
  2183. ; ------------- The End ! ---------------------------------------------------
  2184.  
  2185. 

你可能感兴趣的:(雷军20年前编写的汇编代码)