8月9日,雷军在其个人微博发文称,将举办年度演讲,主题是“成长”。雷军表示,“这是我的第4次年度演讲,想和大家聊聊,过去30多年几次关键成长的经历和感悟。”值得注意的是,今天雷军发布的官宣海报上有个彩蛋,是雷军30多年前写过的一段汇编语言。
图片.png
这段代码早前也曾曝光。各位来审判一下。

2011 年的时候,@程序员的那些事在微博转过雷军在 1994 年写的一段完整的汇编代码。后来雷军在转发上条微博时还补充说:「这个程序第一个版本是我 1989 年写的,怀念当初写程序的快乐时光。」
↓↓↓
  1. ;
  2. ; RI.ASM Revision2.12[ July12,1994]
  3. Revision equ'V2.12 '
  4. ;
  5. ;
  6. ;
  7. ; RAMinit Release2.0
  8. ; Copyright (c)1989-1994by Yellow Rose Software Co.
  9. ; Written by Mr. Leijun
  10. ;
  11. ; Function:
  12. ; Press HotKey to remove all TSR program afterthisprogram
  13. ;
  14. ;

  15. ; ..........................................................................
  16. ; Removed Softwares by RI:
  17. ; SPDOS v6.0F, WPS v3.0F
  18. ; Game Busters III, IV
  19. ; NETX ( Novell3.11)
  20. ; PC-CACHE
  21. ; Norton Cache
  22. ; Microsoft SmartDrv
  23. ; SideKick1.56A
  24. ; MOUSE Driver
  25. ; Crazy (Monochrome simulate CGA program)
  26. ; RAMBIOS v2.0
  27. ;386MAX Version6.01
  28. ; ..........................................................................
  29. ; No cancel softwares:
  30. ; Windows3.1MSD
  31. ;
  32. ; No removed TSR softwares:
  33. ; MS-DOS fastopen
  34. ; Buffers, Files ... (QEMM6.0)
  35. ; QCache (386MAX6.01)
  36. ; ..........................................................................
  37. ;
  38. COMMENT

  39. V2.04Use mouse driver software reset function to initiation mouse
  40. 2/17/1993by Mr. Lei and Mr. Feng
  41. V2.05RI cannot work in Windows DOS prompt
  42. 3/9/1993by Mr. Lei
  43. V2.061.When XMS cannot allocate1K memory, RI halts.
  44. 2.RI repeat deallocates EMS memory.
  45. V2.07HotKey Setup Error
  46. 4/25/1993by Mr. Lei
  47. V2.08KB Buffer
  48. V2.101.Release high memoryblocks(EMM386 QEMM386 S-ICE386MAX)
  49. 2. RI copies flag
  50. V2.12 1. Exists a critical error in Init 8259 procedure
  51. 2. Save [40:F0--FF] user data area



  52. dosseg
  53. .model tiny
  54. .code
  55. locals @@
  56. org 100h

  57. Start: jmp Main
  58. org 103h

  59. True equ 1
  60. False equ 0
  61. MaxHandles equ 100h

  62. INT3 macro
  63. out 0ffh,al
  64. endm
  65. ;
  66. ; HotKey Status Test Var
  67. ; --------------- ---------------
  68. ;
  69. ;76543210417418496
  70. ; . . x . x . . . Left Alt is pressed82
  71. ; x . . . x . . . Right Alt is pressed88
  72. ; . . . x . x . . Left Ctrl is pressed41
  73. ; . x . . . x . . Right Ctrl is pressed44
  74. ; . . . . . . x . Left Shift is pressed2
  75. ; . . . . . . . x Right Shift is pressed1
  76. ;
  77. LeftAlt equ00101000b
  78. RightAlt equ10001000b
  79. LeftCtrl equ00010100b
  80. RightCtrl equ01000100b
  81. LeftShift equ00000010b
  82. RightShift equ00000001b
  83. HotKey db LeftCtrl or RightCtrl

  84. DataBegin dw0
  85. NextDataSeg dw0ffffh
  86. oldInt2F_addr dw0,0
  87. XMS_control dw0,0
  88. Handle_begin dw0
  89. cvtOfs dw0; DOS3.0equ0and above DOS4.0is1
  90. org104h
  91. db0dh
  92. db Revision
  93. db ??date
  94. db26
  95. org114h
  96. tsrLength dw0
  97. MachineID db0FCh ; IBM PC/AT

  98. AuxHotKey db0;2Dh ;'X'Scan Code
  99. AuxHotKeyName db'X$ '
  100. Power db True
  101. Flag db'!'
  102. Kbd102 db0
  103. NoFlag db0
  104. StopFlag db1
  105. DosEnv dw0
  106. WorkSeg dw0
  107. PrevDataSeg dw0
  108. Copies db'1'
  109. old_8259 db0;21h port
  110. db0; a1h port

  111. Status dw0
  112. XMSbit equ00000001b
  113. EMSbit equ00000010b
  114. SKbit equ10000000b

  115. GoINT1C: db0eah
  116. oldInt1C_addr dw0,0
  117. newINT1C:
  118. test cs:Status, SKbit
  119. jnz GoINT1C
  120. cmp cs:StopFlag,0
  121. jz @@0
  122. ;
  123. ; Mr. Lei2/8/1993
  124. ; Problem:ifWPS quit and reenter, old RI cann't control keyboard. ;
  125. push ds
  126. push ax
  127. xor ax, ax
  128. mov ds, ax
  129. mov ax, ds:[94]
  130. cmp ax, offset NewInt9
  131. pop ax
  132. pop ds
  133. jnz GoINT1C
  134. mov cs:StopFlag,0

  135. @@0: push ax
  136. push ds
  137. push es
  138. xor ax, ax
  139. mov ds, ax
  140. mov es, ds:[94+2]
  141. cmp word ptr es:[101h],'IE';'LEI'
  142. jz @@1
  143. cli
  144. mov cs:StopFlag,1
  145. mov ax, ds:[94]
  146. mov cs:oldINT9_addr2, ax
  147. mov ax, ds:[94+2]
  148. mov cs:oldINT9_addr2[2], ax
  149. mov ds:[94], offset newINT9_2
  150. mov ds:[94+2], cs
  151. sti
  152. @@1: pop es
  153. pop ds
  154. pop ax
  155. jmp GoINT1C

  156. ; ----------------------------------------------------------------------
  157. ; INT2F Func
  158. ;
  159. ; AX = C0D7h Return RI segment in AX
  160. ; AX = C0D8h Removes all TSR programs after RI
  161. ; AX = C0D9h Removes all TSR programs include RI
  162. ; AX = C0DAh Removes all RI copies
  163. ; ----------------------------------------------------------------------

  164. newINT2F:
  165. cmp ax,0c0d7h ; LEI Hanzi GB Code
  166. jnz @@1
  167. push cs
  168. pop ax
  169. iret
  170. @@1: cmp ax,0c0d7h+1
  171. jnz @@2
  172. jmp KeepSelf
  173. @@2: cmp ax,0c0d7h+2
  174. jnz @@3
  175. jmp NoKeepSelf
  176. @@3: cmp ax,0c0d7h+3
  177. jnz @@9
  178. mov cs:NextDataSeg,-1
  179. mov cs:Copies,'1'
  180. jmp NoKeepSelf
  181. @@9: jmp dword ptr cs:oldInt2F_addr


  182. CallInt9:
  183. ret


  184. newINT9_2:
  185. mov cs:NoFlag,1
  186. pushf
  187. db9ah ; call far ptr oldint9_addr
  188. oldInt9_Addr2 dw0,0
  189. jmp newINT9_proc

  190. newINT9:
  191. pushf
  192. db9ah ; call far ptr oldint9_addr
  193. oldInt9_Addr dw0,0cmp cs:NoFlag,0
  194. jz newINT9_proc
  195. mov cs:NoFlag,0
  196. iret
  197. newINT9_proc:
  198. cmp cs:Flag,'!'; busy ?
  199. jnz @@0
  200. iret
  201. @@0:
  202. mov cs:Flag,'!';setbusy flag
  203. push ax ; cmp hot key
  204. push bx
  205. push es
  206. mov ax,40h
  207. mov es,ax

  208. cmp cs:AuxHotKey,0
  209. jz @@_1
  210. mov bx, es:[1ah]
  211. cmp bx, es:[1ch]
  212. jz @@10
  213. push bx
  214. mov bl, es:[bx+1]
  215. cmp bl, cs:AuxHotKey
  216. pop bx
  217. jnz @@10
  218. @@_1:
  219. mov ah,es:[17h] ; test CTRL SHIFT ALT
  220. mov al,cs:HotKey
  221. push ax
  222. and ax,0f0fh
  223. cmp al,ah
  224. pop ax
  225. jnz @@10cmp cs:Kbd102, True
  226. jnz @@1
  227. shr al,1
  228. shr al,1
  229. shr al,1
  230. shr al,1
  231. push ax
  232. mov ah, es:[18h]
  233. and ax,303h
  234. cmp al, ah
  235. pop ax
  236. jnz @@10
  237. mov ah, es:[96h]
  238. shr ax,1
  239. shr ax,1
  240. and ax,303h
  241. cmp al, ah
  242. jnz @@10cmp cs:AuxHotKey,0
  243. jz @@_3
  244. inc bx
  245. inc bx
  246. cmp bx,3eh
  247. jb @@_2
  248. mov bx,1eh
  249. @@_2:
  250. mov es:[1ah], bx
  251. @@_3:
  252. call IsWinDos
  253. or ax, ax
  254. jz @@1
  255. call Beep
  256. @@10:
  257. sti
  258. pop es
  259. pop bx
  260. pop ax
  261. mov cs:Flag,' '; no busy
  262. iret
  263. @@1: ; OK
  264. pop es
  265. pop bx
  266. pop ax

  267. KeepSelf:
  268. call RemoveTSR
  269. push es
  270. mov es,cs:WorkSeg
  271. mov dx,es:tsrLength
  272. mov di,dx
  273. mov al,0h ; Aug24,1993
  274. mov cx,100h
  275. rep stosb
  276. pop es
  277. int27h

  278. NoKeepSelf:
  279. mov ax,0e07h
  280. int10h
  281. mov cs:clsStr,47h ; Color (White in Red)
  282. call RemoveTSR
  283. dec cs:Copies
  284. call RestoreSelfIntVec
  285. push es
  286. cmp cs:PrevDataSeg,0
  287. jz @@1
  288. mov es, cs:PrevDataSeg
  289. mov es:NextDataSeg,-1
  290. @@1: pop es
  291. mov ax,4c00h
  292. int21h

  293. ; ---------------------------------------------------------------------------

  294. IsWinDOS:
  295. mov ax,1600h
  296. int2fh
  297. cmp al,01h
  298. jz @@9cmp al,0ffh
  299. jz @@9; Windows/386Version2.X
  300. cmp al,00h
  301. jz @@1cmp al,80h
  302. jnz @@9; Windows3in enhanced mode
  303. ; Version number in AL/AH
  304. @@1:
  305. mov ax,4680h
  306. int2fh
  307. cmp al,80h
  308. jnz @@9
  309. xor ax, ax
  310. jmp @@10
  311. @@9: mov ax,1
  312. @@10: ret

  313. ; -----------------------------------------------------------------------
  314. RestoreSelfIntVec:
  315. cmp Copies,'0'
  316. jz @@0
  317. ret
  318. @@0:
  319. cli
  320. push cs
  321. pop ds
  322. xor ax, ax
  323. mov es, ax
  324. mov si, offset oldInt9_Addr
  325. mov di,94
  326. movsw
  327. movsw
  328. mov si, offset oldInt2F_Addr
  329. mov di,2Fh4
  330. movsw
  331. movsw
  332. mov si, offset oldInt1C_Addr
  333. mov di,1Ch4
  334. movsw
  335. movsw
  336. sti
  337. ret

  338. ; ------------- KERNEL PROGRAM ----------------------------------------------
  339. RemoveTSR:
  340. pop ax
  341. cli ; Setstack
  342. mov sp, cs
  343. mov ss, sp
  344. mov sp,100h
  345. sti
  346. push ax

  347. cmp cs:Power, True
  348. jnz @@1
  349. call Init8259
  350. @@1:
  351. push cs
  352. pop ds
  353. @@_0:
  354. mov ax,ds:NextDataSeg
  355. cmp ax,-1
  356. jz @@_1
  357. mov cs:PrevDataSeg, ds
  358. mov ds, ax
  359. jmp @@_0
  360. @@_1: mov si,ds:DataBegin
  361. mov cs:WorkSeg, ds
  362. lodsw
  363. cmp ax,'XX'
  364. jz @@_2
  365. call Beep
  366. ret
  367. @@_2:
  368. call RestoreEnvStr
  369. call RestoreMCB ; restore current mcb
  370. call CloseFiles
  371. call RestorePort
  372. call RestoreLEDs
  373. call RestoreVecList ; Restore vectorslist
  374. call RestoreFloppyParam
  375. cmp cs:Power, True
  376. jnz @@2
  377. call RestoreCVTchain ; Restore cvt chain
  378. call RestoreMemoryManager
  379. @@2:
  380. call RestoreBiosData
  381. call Enable8259
  382. mov ah,1int16h

  383. call RestoreClockSpeed
  384. call CloseSpeaker
  385. call ResetDisk
  386. call UpdateTime

  387. call ClosePRN
  388. mov bx,cs:WorkSeg
  389. mov ah,50h
  390. int21h ; Set PSP segment
  391. mov ax,3int10h ; Set display mode

  392. call InitPRN
  393. call InitMouse
  394. mov al, cs:Copies
  395. cmp al,'1'
  396. ja @@_sh1
  397. mov cs:ShowCopies,''
  398. jmp @@_sh2
  399. @@_sh1: mov cs:ShowCopies, al
  400. @@_sh2:
  401. mov si, offset clsStr
  402. call ColorPrintStr
  403. mov cs:Flag, '' ; no busy
  404. cmp Copies, '1'
  405. jnz @@_end
  406. mov cs:StopFlag,0
  407. @@_end:
  408. call ClearKB_buffer
  409. ret

  410. Beep:
  411. mov ax,0e07h
  412. int10h
  413. ret

  414. ; #########################################################################

  415. ClearKB_Buffer:
  416. push es
  417. push bx
  418. mov bx,0040h
  419. mov es, bx
  420. cli
  421. mov bx, es:[1ah]
  422. mov es:[1ch], bx
  423. sti
  424. pop bx
  425. pop es
  426. ret


  427. Init8259:
  428. ; cmp cs:Copies,'1'
  429. ; jz @@1
  430. ; ret
  431. @@1:
  432. cmp cs:MachineID,0fch
  433. ja @@pc_xt
  434. @@AT:
  435. mov bx,870h ;
  436. mov al,0;
  437. out0F1h,al ;
  438. jcxz $+2
  439. jcxz $+2
  440. mov al,11h ; ICW1
  441. out0A0h,al
  442. jcxz $+2
  443. jcxz $+2
  444. out20h,al
  445. jcxz $+2
  446. jcxz $+2
  447. mov al,bl ; ICW2
  448. out0A1h,al
  449. jcxz $+2
  450. jcxz $+2
  451. mov al,bh
  452. out21h,al
  453. jcxz $+2
  454. jcxz $+2
  455. mov al,2; ICW3
  456. out0A1h,al
  457. jcxz $+2
  458. jcxz $+2
  459. mov al,4
  460. out21h,al
  461. jcxz $+2
  462. jcxz $+2
  463. mov al,1; ICW4
  464. out0A1h,al
  465. jcxz $+2
  466. jcxz $+2
  467. out21h,al
  468. jcxz $+2
  469. jcxz $+2
  470. mov al,0FFh ; OCW1
  471. out0A1h,al
  472. jcxz $+2
  473. jcxz $+2
  474. out21h,al
  475. ret
  476. @@PC_XT:
  477. mov al,13h ; ICW1
  478. out20h,al
  479. jcxz $+2
  480. jcxz $+2
  481. mov al,8; ICW2
  482. out21h,al
  483. jcxz $+2
  484. jcxz $+2
  485. mov al,9; ICW4
  486. out21h,al
  487. jcxz $+2
  488. jcxz $+2
  489. mov al,0FFh ; OCW1
  490. out21h,al
  491. ret

  492. Enable8259:
  493. mov ax, word ptr cs:old_8259
  494. out021h,al
  495. jcxz $+2
  496. jcxz $+2
  497. mov al,ah
  498. out0a1h,al ; DEC PC Bus Mouse
  499. ret ; July1994by Mr. Lei

  500. ; -------------------------------------------------------------------------

  501. RestoreBiosData:
  502. lodsw
  503. cmp ax,'--'
  504. jz @@1
  505. call Beep
  506. ret
  507. @@1: push es
  508. push di
  509. mov di,40h
  510. mov es, di

  511. mov di,10h
  512. movsw
  513. mov di,0a8h ; [40h:a8h]
  514. movsw
  515. movsw
  516. mov di,49h
  517. mov cx,1dh
  518. rep movsb

  519. mov di,0f0h ; User data
  520. mov cx,8
  521. rep movsw

  522. pop di
  523. pop es
  524. ret

  525. ; -------------------------------------------------------------------------

  526. RestoreMCB:
  527. push ds
  528. push es
  529. lodsw ;'MZ'
  530. @@0: lodsw
  531. cmp ax,'MM'
  532. jz @@1
  533. mov es,ax
  534. xor di,di
  535. movsb
  536. movsw
  537. movsw
  538. inc ax
  539. mov bx, ds
  540. cmp ax, bx
  541. jz @@10
  542. mov byte ptr es:[8],0; Aug24,1993
  543. @@10: cmp byte ptr es:[0],'Z'
  544. jnz @@0
  545. mov byte ptr es:[10h],0
  546. jmp @@0
  547. @@1:
  548. pop es
  549. pop ds
  550. ret

  551. ; -------------------------------------------------------------------------
  552. CloseFiles:
  553. mov ax,5; Begin handle
  554. push ds
  555. push si
  556. mov cx,15; Max handle
  557. sub cx, ax
  558. inc cx
  559. mov bx, ax
  560. @@1: push bx
  561. push cx
  562. mov ah,3eh
  563. int21h
  564. pop cx
  565. pop bx
  566. inc bx
  567. loop @@1
  568. pop si
  569. pop ds
  570. ret

  571. ; -------------------------------------------------------------------------
  572. RestorePort:
  573. mov di,40h ; restore port
  574. mov es, di
  575. xor di, di
  576. mov cx,8
  577. rep movsw
  578. ret

  579. ; -------------------------------------------------------------------------
  580. RestoreLEDs:
  581. lodsb
  582. and al,11110000b; LED status
  583. mov ah, es:[17h]
  584. and ah,00001111b
  585. or ah, al
  586. and ah,0f0h ; Clear CTRL ALT SHIFT
  587. mov es:[17h], ah
  588. ret

  589. ; -------------------------------------------------------------------------
  590. RestoreEnvStr:
  591. lodsw
  592. push si
  593. push di
  594. push ds
  595. push es
  596. mov es, cs:DosEnv
  597. mov ds, ax
  598. xor si, si
  599. mov di, si
  600. @@0: lodsb
  601. or al, al
  602. jnz @@1cmp byte ptr ds:[si],0
  603. jz @@2
  604. @@1: stosb
  605. jmp @@0
  606. @@2: stosb
  607. stosb
  608. pop es
  609. pop ds
  610. pop di
  611. pop si
  612. ret

  613. ; -----------------------------------------------------------------------
  614. RestoreVecList:
  615. xor ax,ax
  616. mov di,ax
  617. mov es,ax
  618. mov cx,100h
  619. @@0: lodsw
  620. xchg dx, ax
  621. lodsw
  622. cmp dx,'EL'
  623. jnz @@1cmp al,'I'
  624. jnz @@1
  625. sub cl, ah
  626. push cx
  627. mov cl, ah
  628. mov ax, es:[di-4]
  629. mov dx, es:[di-2]
  630. @@a: stosw
  631. xchg ax, dx
  632. stosw
  633. xchg ax, dx
  634. loop @@a
  635. pop cx
  636. or cx, cx
  637. jz @@9
  638. jmp @@0
  639. @@1:
  640. xchg ax, dx
  641. stosw
  642. xchg ax, dx
  643. stosw
  644. loop @@0
  645. @@9:
  646. ret

  647. ;----------------------------------------------------------------------------
  648. RestoreFloppyParam: ; Mr. Lei2/10/1992
  649. push es
  650. push ax
  651. xor ax, ax
  652. mov es, ax
  653. mov byte ptr es:[525h],2
  654. pop ax
  655. pop es
  656. ret

  657. ;---------------------------------------------------------------------------
  658. RestoreCVTchain:
  659. lodsw
  660. cmp ax,'VC'
  661. jz @@_0
  662. call Beep
  663. ret
  664. @@_0:
  665. push ax
  666. push cx
  667. push es

  668. ; -----------------------------------------------------------------
  669. lodsw ; DPB
  670. mov di, ax
  671. lodsw
  672. mov es, ax
  673. @@1: lodsb
  674. inc di
  675. stosb
  676. add di, cs:cvtOfs
  677. add di,10h
  678. movsw
  679. movsw
  680. les di, es:[di+2]
  681. cmp di,-1
  682. jnz @@1

  683. ; -----------------------------------------------------------------
  684. lodsw ; DCB
  685. mov di, ax
  686. lodsw
  687. mov es, ax
  688. xor ax, ax
  689. dec ax
  690. stosw

  691. ; -----------------------------------------------------------------
  692. lodsw ; Device Driver Chain
  693. mov di, ax
  694. lodsw
  695. mov es, ax
  696. xor cx, cx
  697. @@9: push di
  698. mov cl,5
  699. rep movsw
  700. pop di
  701. les di, es:[di]
  702. mov ax, di
  703. inc ax
  704. jnz @@9
  705. pop es
  706. pop cx
  707. pop ax
  708. ret

  709. ; ----------------------------------------------------------------------------
  710. RestoreMemoryManager:
  711. test cs:Status, XMSbit
  712. jz @@1
  713. call LoadXMSstatus
  714. @@1:
  715. test cs:Status, EMSbit
  716. jz @@2
  717. call LoadEMSstatus
  718. @@2:
  719. ret


  720. LoadEMSstatus:
  721. lodsw
  722. cmp ax,'ME'
  723. jz @@_0
  724. call Beep
  725. ret
  726. @@_0:
  727. lodsw
  728. mov cx, ax
  729. xor dx, dx
  730. @@_1: push ds
  731. push si
  732. push dx
  733. push cx

  734. @@0: cmp dx, ds:[si]
  735. jz @@1
  736. add si,4
  737. loop @@0

  738. push cx
  739. mov cx,5
  740. @@0: mov ah,45h ; Deallocate Handle and Memory
  741. int67h
  742. or ah, ah
  743. jz @@1
  744. loop @@0
  745. @@1: pop cx

  746. @@1:
  747. pop cx
  748. pop dx
  749. pop si
  750. pop ds
  751. inc dx
  752. cmp dx,100h
  753. jb @@_1
  754. shl cx,1
  755. shl cx,1
  756. add si, cx
  757. ret


  758. LoadXMSstatus:
  759. lodsw
  760. cmp ax,'MX'
  761. jz @@_0
  762. call Beep
  763. ret
  764. @@_0:
  765. lodsw
  766. mov cx, ax
  767. jcxz @@5
  768. @@1:
  769. lodsw
  770. mov dx, ax
  771. @@2: push dx
  772. mov ah,0ah ;free
  773. call dword ptr cs:xms_control
  774. or ax, ax
  775. pop dx
  776. jnz @@4cmp bl,0abh
  777. jnz @@4
  778. push dx
  779. mov ah,0dh ; unlock
  780. call dword ptr cs:xms_control
  781. or ax, ax
  782. pop dx
  783. jmp @@2
  784. @@4: loop @@1
  785. @@5: ret
  786. endp

  787. ; -----------------------------------------------------------------------
  788. CloseSpeaker:
  789. in al,61h
  790. and al,0fch
  791. out61h, al
  792. ret

  793. ; -----------------------------------------------------------------------
  794. RestoreClockSpeed:
  795. mov al,00110110b
  796. out43h, al
  797. xor ax, ax
  798. out40h, al
  799. out40h, al
  800. ret

  801. ; -----------------------------------------------------------------------
  802. ResetDisk:
  803. xor ax, ax
  804. xor dx, dx
  805. int13h ; Restore A
  806. inc dx
  807. int13h ; Restore B
  808. mov dl,80h
  809. int13h ; Restore C
  810. ret



  811. ; --------------------------------------------------------------------------
  812. ClosePRN:
  813. mov ah,51h ; Get PSP seg
  814. int21h
  815. mov es, bx
  816. mov ax, es:[16h] ; Prev PSP seg
  817. cmp ax, bx
  818. jnz @@9
  819. mov ax,3e00h ; COMMAND
  820. mov bx,4int21h
  821. @@9:
  822. ret

  823. InitPRN:
  824. mov ax,3e00h
  825. mov bx,4; PRN
  826. int21h
  827. mov ax,3d01h
  828. mov dx, offset PRNname
  829. push cs
  830. pop ds
  831. int21h
  832. ret
  833. PRNname db'PRN',0

  834. InitMouse: ;2/16/1993by Mr. Lei
  835. push es
  836. xor ax, ax
  837. mov es, ax
  838. cmp word ptr es:[33h4+2],0
  839. jz @@0cmp word ptr es:[33h4],0
  840. jz @@0
  841. mov ax,21h
  842. int33h ; Hook Mouse Interrupt
  843. @@0: pop es
  844. ret

  845. ; ------------- CMOS CLOCKsetto System -----------------------------------
  846. UpdateTime:
  847. call GetRealTime
  848. mov ah,2dh
  849. int21h
  850. ret

  851. GetRealTime:
  852. mov ah,2int1Ah
  853. mov al,ch
  854. call bcdxchg
  855. mov ch,al
  856. mov al,cl
  857. call bcdxchg
  858. mov cl,al
  859. mov al,dh
  860. call bcdxchg
  861. mov dh,al
  862. mov dl,0
  863. ret

  864. BCDxchg:
  865. push ax
  866. push cx
  867. mov cl,4
  868. shr al,cl
  869. pop cx
  870. mov bl,0Ah
  871. mul bl
  872. pop bx
  873. and bl,0Fh
  874. add al,bl
  875. ret

  876. ; -----------------------------------------------------------------------
  877. ; Displaystring
  878. ColorPrintStr:
  879. lodsb
  880. mov bh, al ; color
  881. xor cx, cx
  882. mov dx,014fh
  883. mov ax,0600h
  884. int10h

  885. mov ah,02; GotoXY (0,0)
  886. xor dx, dx
  887. mov bh,0int10h
  888. PrintStr:
  889. push cs
  890. pop ds
  891. xor bx, bx
  892. @@1: lodsb
  893. cmp al,'

  894. jz @@2
  895. or al, al
  896. jz @@2
  897. mov ah,0eh
  898. int10h
  899. jmpshort@@1
  900. @@2: mov al, cs:clsStrcolor
  901. mov cs:clsStr, al
  902. ret

  903. ; -----------------------------------------------------------------------
  904. Self dw0
  905. clsStrcolor db17h
  906. clsStr db17h ; Color (White in Blue)
  907. db' RAMinit Version 2.12 (c) 1989-1994 by KingSoft Ltd. Mr. Leijun'
  908. db0dh,0ah
  909. db' ['
  910. ShowCopies db''
  911. db '] Activate...',0ah,0dh,'


  912. endTSR equ $
  913. mcbList equ offset endTSR +2+2
  914. vecList equ mcbList +710+2+10h +1+400h
  915. devLink equ vecList +4+526+4+1030h +4
  916. xmsList equ devLink +2+ MaxHandles 2
  917. emsList equ xmsList +4+1024
  918. crtMode equ emsList +2+1Dh +4+10h
  919. tsrLen equ crtMode +1
  920. ;
  921. ; DOS Environment Reserved by RI
  922. ; --------------------------------------------------
  923. ; Flag'XX'2bytes
  924. ; Environment Segment1word
  925. ; Free MCBs <=710bytes
  926. ; MCB segment1word
  927. ; MCB5bytes
  928. ; End flag'MM'1word
  929. ; COM LPT ports10h bytes
  930. ; LEDs status1bytes
  931. ; Packed vectorslist<=400h bytes
  932. ; Flag 'CV' 2 bytes
  933. ; CVT First DPB pointer 4 bytes
  934. ; DPBs data <=526 bytes
  935. ; First DCB pointer 4 bytes
  936. ; Pointer to NUL 4 bytes
  937. ; All device driver datas <=30h10 bytes
  938. ; Flag 'XM' 2 bytes
  939. ; XMSfreehandle counter 2 bytes
  940. ; EMSfreehandlelist<=100h4 bytes
  941. ; Flag 'EM' 2 bytes
  942. ; EMSfreehandle counter 2 bytes
  943. ; EMSfreehandlelist<=1024 bytes
  944. ; EMS handle 1 word
  945. ; Number of pages 1 word
  946. ; Flag '--' 1 word
  947. ; Equipment List 1 word
  948. ; CRT 40:49h-66h 1dh bytes
  949. ; 40:A8h 1 dword
  950. ; BIOS User Data Area 40:F0--FF 10h bytes
  951. ; **
  952. ;
  953. main: jmp main0

  954. Print Macro Str
  955. Lea dx, Str
  956. call DisplayStr
  957. endm

  958. InstMsg db 'RAMinit Version 2.12 '
  959. db 'Copyright (c) 1989-1994 by KingSoft Ltd. ',0dh,0ah,'

  960. Msg0 db 'Already installed !',0dh,0ah,0ah
  961. db 'For Help, type "RI /?". ',0dh,0ah,'

  962. Msg_0 db 0ah,'Residents anewRAMinit copy [y/n] ?

  963. Msg_2 db 'OK, RI No.'
  964. Msg_RI db '2'
  965. db ' residents successful !', 0dh,0ah,'

  966. Msg1 db 'Activate with:

  967. KeyMsg db 'Right_Shift

  968. db 'Left_Shift$ '
  969. KMsg1 db 'Left_Ctrl$ '
  970. db 'Left_Alt$ '
  971. db 'Right_Ctrl$ '
  972. db 'Right_Alt$ '
  973. KMsg2 db 'Ctrl$ '
  974. db 'Alt$ '
  975. db 'Ctrl$ '
  976. db 'Alt$ '
  977. PlusMsg db ' +

  978. crlf db 0dh,0ah,'


  979. HelpMsg db 'Programmed by Mr. Leijun Dec 1992', 0dh,0ah,0ah
  980. db 'Usage: RI [options]',0dh,0ah,0ah
  981. db '/H,/? Displaythisscreen',0dh,0ah
  982. db '/CLS Removes all TSR programs after current RI',0dh,0ah
  983. db '/RET Removes TSR programs include current RI',0dh,0ah
  984. db '/NEW Residents anewdata copy of current environment',0dh,0ah
  985. db '/ALL Removes all RI copies and all other tsr programs',0dh,0ah
  986. db '/Sxyy.. Define Hotkey x=AuxHotkey yy..=shift status',0dh,0ah
  987. db ' x=auxiliary hotkey (defaultis "X") ',0dh,0ah
  988. db ' x equ "1" means need AuxHotkey',0dh,0ah
  989. db ' yy..=shift status [CAScas]',0dh,0ah
  990. db ' C: Left Ctrl A: Left Alt S: Left Shift',0dh,0ah
  991. db ' c: Right Ctrl a: Right Alt s: Right Shift',0dh,0ah,0ah
  992. db 'Example: "RI /S1c" means Hotkey is Right_Ctrl+X',0dh,0ah
  993. db ' "RI /S0Cc" means HotKey is Left_Ctrl+Right_Ctrl',0dh,0ah
  994. db ' "RI /CLS" equals simply press hotkey',0dh,0ah
  995. db ' "RI /RET" Removes all TSRs after current RI andthisRI',0dh,0ah
  996. db 0ah
  997. db 'Contact meforRAMinit problems: (01)2561155 Call 1997',0dh,0ah
  998. db '

  999. ErrMsg db 'ERROR: Invalid options !',0dh,0ah,0ah,'

  1000. WinErr db 7, 'Sorry, I cannot work in Windows DOS environment.',0dh,0ah,'

  1001. SetMsg db 7, 'DefinesnewHotkey successful !',0dh,0ah,0ah,'

  1002. tsrOK db False

  1003. Main0:
  1004. cld
  1005. Print instMsg
  1006. call IsWinDos
  1007. or ax, ax
  1008. jz @@1
  1009. Print WinErr
  1010. mov ax, 4c00h
  1011. int21h
  1012. @@1:
  1013. call HotKeyValid
  1014. mov cs:Status, 0
  1015. call EMS_test
  1016. call CmpDosVer
  1017. call CmpSideKick
  1018. call GetMachineID
  1019. call ModifyHotKeyPrompt

  1020. mov ax, 0c0d7h
  1021. int2fh
  1022. mov es, ax
  1023. cmp word ptr es:[101h], 'IE' ; 'LEI'
  1024. jnz @@0
  1025. mov cs:Self, ax
  1026. @@0:
  1027. call CmdLine
  1028. call PrintHotKeyPrompt

  1029. cmp cs:tsrOK,true
  1030. jz @@2
  1031. call tsrReplyOK
  1032. @@2: cmp cs:tsrOK,true
  1033. jnz @@_2
  1034. call PrintCopies
  1035. @@_2:
  1036. mov word ptr cs:[100h], 'EL'
  1037. mov byte ptr cs:[102h], 'I'

  1038. push cs
  1039. pop es
  1040. push cs
  1041. pop ds
  1042. std
  1043. mov si, offset eof
  1044. mov cx, eof - offset Here
  1045. mov di, tsrLen
  1046. add di, cx
  1047. inc cx
  1048. rep movsb
  1049. cld
  1050. mov bx, tsrLen
  1051. jmp bx

  1052. Here:
  1053. mov ax,cs
  1054. mov es,ax
  1055. mov di,offset endTSR
  1056. mov cs:DataBegin, di
  1057. mov cs:NextDataSeg, -1
  1058. mov ax, 'XX'
  1059. stosw
  1060. in al, 0a1h
  1061. mov ah, al
  1062. in al, 21h
  1063. push ax
  1064. mov word ptr cs:old_8259, ax
  1065. xor ax, ax
  1066. out 21h,al ; CLI
  1067. call SaveOthers
  1068. call SetSelfInt
  1069. call BackupVecList
  1070. cmp cs:Power,true
  1071. jnz @@20
  1072. call BackupCVTchain
  1073. call BackupMemoryManager
  1074. @@20:
  1075. call BackupBiosData

  1076. sti
  1077. mov cs:Flag, ' ' ; no busy
  1078. mov cs:StopFlag, 0 ;

  1079. mov cs:tsrLength, di
  1080. call SetDosEnvSeg
  1081. cmp cs:Self, 0
  1082. jz @@29
  1083. push cs
  1084. pop ds
  1085. push cs
  1086. pop es
  1087. cld
  1088. mov cx, cs:tsrLength
  1089. mov si, cs:DataBegin
  1090. sub cx, si
  1091. mov di, 120h
  1092. mov cs:DataBegin, di
  1093. rep movsb
  1094. mov cs:tsrLength, di
  1095. @@29:
  1096. pop ax
  1097. out 21h, al ; STI
  1098. mov al, ah
  1099. out 0a1h, al
  1100. mov dx, cs:tsrLength
  1101. inc dx
  1102. int27h

  1103. ; ----------------------------------------------------------------------------
  1104. SetDosEnvSeg:
  1105. push ds
  1106. push es
  1107. mov ax, cs
  1108. @@10: mov es, ax
  1109. mov ax, es:[16h] ; Get father process psp segment
  1110. or ax, ax
  1111. jz @@11
  1112. mov bx, es
  1113. cmp ax, bx
  1114. jnz @@10
  1115. @@11:
  1116. mov es, word ptr es:[2ch] ; Get father process env segment
  1117. mov cs:DosEnv, es
  1118. pop es
  1119. pop ds
  1120. ret

  1121. ; ----------------------------------------------------------------------------

  1122. SaveOthers:
  1123. mov ax, cs:[2ch] ; Env Seg
  1124. stosw
  1125. call backupMCB ; Current MCB
  1126. mov ax, 40h ; COM LPT Port
  1127. mov ds, ax
  1128. mov si, 0h
  1129. mov cx, 8
  1130. rep movsw

  1131. mov si, 17h ; LED status
  1132. lodsb
  1133. stosb
  1134. ; call OpenLEDs
  1135. ret

  1136. ; --------------------------------------------------------------------------
  1137. backupMCB:
  1138. mov ax, 'ZM'
  1139. stosw
  1140. push ds
  1141. push es
  1142. mov ah, 52h
  1143. int21h ; Get MCB chain head
  1144. mov ax, es:[bx-2]
  1145. pop es
  1146. @@0: mov ds, ax
  1147. cmp byte ptr ds:[0], 'Z' ; End ?
  1148. jz @@20 cmp byte ptr ds:[0], 'M' ; Memory control block
  1149. jnz @@30 cmp word ptr ds:[3], 0 ; Nul mcb
  1150. jz @@10 cmp word ptr ds:[1], 0 ; Free MCB
  1151. jnz @@10
  1152. call SaveFreeMCB
  1153. @@10: inc ax
  1154. add ax, ds:[3]
  1155. jmp @@0
  1156. @@20:
  1157. call SaveFreeMCB
  1158. cmp ax, 0a000h
  1159. inc ax
  1160. jnb @@30
  1161. mov ax, 9fffh ; MS-DOS UMB
  1162. jmp @@0

  1163. @@30:
  1164. cmp ax, 0c000h ; 386MAX
  1165. ja @@90
  1166. mov ax, 0c020h
  1167. jmp @@0

  1168. @@90: ; Error ?
  1169. pop ds
  1170. mov ax, 'MM' ; Set MCB flag
  1171. stosw
  1172. ret

  1173. SaveFreeMCB:
  1174. stosw
  1175. xor si,si
  1176. movsb
  1177. movsw
  1178. movsw
  1179. ret
  1180. ;
  1181. ; push ax
  1182. ; stosw
  1183. ; xor si,si
  1184. ; movsb
  1185. ; movsw
  1186. ; movsw
  1187. ; pop ax
  1188. ; cmp ax, 09fffh
  1189. ; jnb @@3
  1190. ; push ax
  1191. ; push ds
  1192. ; mov ds,ax
  1193. ; cmp byte ptr ds:[0], 'M'
  1194. ; pop ds
  1195. ; pop ax
  1196. ; jnz @@4
  1197. ; mov ax, 09fffh ; MS-DOS UMB
  1198. ; jmp @@0
  1199. ; @@4: cmp ax, 0c000h
  1200. ; ja @@3
  1201. ; mov ax, 0c020h ; 386MAX
  1202. ; jmp @@0
  1203. ;
  1204. ; --------------------------------------------------------------------------

  1205. OpenLEDs: push ax ; Open all LEDs
  1206. or al, 070h
  1207. mov ds:[17h], al
  1208. mov ah, 1int16h
  1209. mov cx, 4 ; Delay
  1210. @@20: push cx
  1211. xor cx, cx
  1212. @@21: loop @@21
  1213. pop cx
  1214. loop @@20
  1215. pop ax
  1216. mov ds:[17h], al
  1217. mov ah, 1int16h
  1218. ret

  1219. ; --------------------------------------------------------------------------
  1220. SetSelfInt:
  1221. push es
  1222. push di

  1223. cmp cs:self, 0
  1224. jnz @@1
  1225. push cs
  1226. pop ds
  1227. mov ax,3509h
  1228. int21h
  1229. mov word ptr cs:oldInt9_addr,bx
  1230. mov word ptr cs:oldInt9_addr[2],es
  1231. mov dx,offset NewInt9
  1232. mov ax,2509h
  1233. int21h

  1234. mov ax,352Fh
  1235. int21h
  1236. mov word ptr cs:oldInt2F_addr,bx
  1237. mov word ptr cs:oldInt2F_addr[2],es
  1238. mov dx,offset newInt2F
  1239. mov ax,252Fh
  1240. int21h

  1241. mov ax,351Ch
  1242. int21h
  1243. mov word ptr cs:oldInt1C_addr,bx
  1244. mov word ptr cs:oldInt1C_addr[2],es
  1245. mov dx,offset newInt1C
  1246. mov ax,251ch
  1247. int21h
  1248. cli
  1249. jmp @@2
  1250. @@1:
  1251. mov es, cs:Self
  1252. inc es:Copies
  1253. @@_0: cmp es:NextDataSeg, -1
  1254. jz @@_1
  1255. mov es, es:NextDataSeg
  1256. jmp @@_0
  1257. @@_1: mov es:NextDataSeg, cs
  1258. @@2:
  1259. pop di
  1260. pop es
  1261. ret

  1262. ; -----------------------------------------------------------------------
  1263. SaveCounter:
  1264. mov word ptr es:[di], 'EL'
  1265. mov byte ptr es:[di+2], 'I'
  1266. mov byte ptr es:[di+3], bl
  1267. xor bx, bx
  1268. add di, 4
  1269. ret

  1270. ; -----------------------------------------------------------------------
  1271. DisplayStr: push cs
  1272. pop ds
  1273. mov ah, 9int21h
  1274. ret

  1275. ; -----------------------------------------------------------------------
  1276. CmdLine:
  1277. push cs
  1278. pop ds
  1279. xor ax, ax
  1280. mov si, 80h
  1281. lodsb
  1282. or al, al
  1283. jnz @@1
  1284. ret
  1285. @@1:
  1286. mov cx, ax
  1287. dec ax
  1288. push ax
  1289. push si
  1290. @@0: lodsb
  1291. cmp al, ' '
  1292. jz @@0 cmp al, '/'
  1293. jnz @@2
  1294. lodsb
  1295. cmp al, 'S'
  1296. jz @@_2
  1297. cmp al, 's'
  1298. jnz @@2
  1299. @@_2:
  1300. call SetHotKey
  1301. Print SetMsg
  1302. mov ax, 4c00h
  1303. int21h
  1304. @@2:
  1305. pop si
  1306. pop ax
  1307. push ax
  1308. push si
  1309. @@_3: lodsb
  1310. cmp al, 'A'
  1311. jb @@3 cmp al, 'Z'
  1312. ja @@3
  1313. add byte ptr ds:[si-1],20h ; DownCase
  1314. @@3: loop @@_3
  1315. pop si
  1316. pop cx

  1317. add si, cx
  1318. lodsb
  1319. cmp al, 's' ; CLS
  1320. jnz @@5 cmp word ptr ds:[si-3], 'lc'
  1321. jnz @@5 cmp cs:Self, 0
  1322. jz @Err
  1323. mov ax, 0c0d7h+1int2fh

  1324. @@5: cmp al, 'h' ; HELP
  1325. jz @help
  1326. cmp al, '?'
  1327. jz @help
  1328. cmp al, 't' ; RET
  1329. jnz @@6 cmp word ptr ds:[si-3], 'er'
  1330. jnz @@6
  1331. @@7:
  1332. cmp cs:Self, 0
  1333. jz @Err
  1334. mov ax, 0c0d7h+2int2fh
  1335. @@6: cmp al, 'w' ; NEW
  1336. jnz @@8 cmp word ptr ds:[si-3], 'en'
  1337. jnz @@8
  1338. mov cs:tsrOK,true
  1339. ret
  1340. @@8:
  1341. cmp al, 'l' ; ALL
  1342. jnz @@9 cmp word ptr ds:[si-3], 'la'
  1343. jnz @@9
  1344. mov ax, 0c0d7h+3int2fh
  1345. @@9:
  1346. cmp al, ' '
  1347. jnz @Err
  1348. ret

  1349. @Err:
  1350. Print ErrMsg
  1351. @help:
  1352. Print HelpMsg
  1353. mov ax, 4c00h
  1354. int21h

  1355. ;---------------------------------------------------------------------------
  1356. tsrReplyOK:
  1357. cmp cs:Self, 0
  1358. jz @@1
  1359. Print Msg0

  1360. push es
  1361. mov ax, cs:Self
  1362. @@_10: mov es, ax
  1363. mov ax, es:NextDataSeg
  1364. cmp ax, -1
  1365. jnz @@_10
  1366. mov ax, es

  1367. @@_0: push ax
  1368. dec ax
  1369. mov es, ax
  1370. mov bx, es:[3]
  1371. pop ax

  1372. add ax, bx
  1373. inc ax
  1374. mov es, ax
  1375. cmp word ptr es:[0], 'OC'
  1376. jz @@_0

  1377. mov bx, cs
  1378. cmp ax, bx
  1379. pop es
  1380. jz @@2
  1381. Print Msg_0
  1382. mov ah, 1int21h

  1383. push ax
  1384. Print crlf
  1385. pop ax

  1386. cmp al, 'y'
  1387. jz @@3 cmp al, 'Y'
  1388. jz @@3
  1389. @@2: ; Print Msg_1
  1390. mov ax, 4c01h
  1391. int21h
  1392. @@3:
  1393. @@1: mov cs:tsrOK,true
  1394. ret

  1395. PrintCopies:
  1396. cmp cs:Self, 0
  1397. jz @@1
  1398. push es ; Added -by- Mr. Lei
  1399. mov es, cs:Self ; Aug 24, 1993
  1400. mov al, es:Copies
  1401. inc al ; Total RI copies
  1402. push ax ; Set es = current mcb
  1403. mov ax, cs
  1404. dec ax
  1405. mov es, ax
  1406. pop ax
  1407. mov cx, 5 ; Search end of file name
  1408. mov bx, 8
  1409. @@10: inc bx
  1410. cmp byte ptr es:[bx], 20h
  1411. jz @@20 cmp byte ptr es:[bx], 0ffh
  1412. jz @@20 cmp byte ptr es:[bx], 00h
  1413. jz @@20
  1414. loop @@10
  1415. @@20: ; Set current RI no
  1416. mov byte ptr es:[bx], ':' ; "RI:2"
  1417. mov byte ptr es:[bx+1], al
  1418. cmp bx, 8+7
  1419. jnb @@30
  1420. mov byte ptr es:[bx+2], 0
  1421. @@30:
  1422. pop es

  1423. mov cs:Msg_RI, al
  1424. Print Msg_2
  1425. @@1: ret

  1426. ;---------------------------------------------------------------------------
  1427. ; Backup Interrupt Vector List
  1428. ;
  1429. BackupVecList:
  1430. push ds
  1431. push cs
  1432. pop es
  1433. xor si,si ; Vectors
  1434. mov ds,si
  1435. movsw
  1436. movsw
  1437. xor bx, bx
  1438. mov cx,00ffh
  1439. @@0: lodsw
  1440. xchg dx, ax
  1441. lodsw
  1442. cmp ax, es:[di-2]
  1443. jnz @@1 cmp dx, es:[di-4]
  1444. jz @@2
  1445. @@1: or bx, bx
  1446. jz @@3
  1447. call SaveCounter
  1448. @@3: xchg dx, ax
  1449. stosw
  1450. xchg dx, ax
  1451. stosw
  1452. loop @@0
  1453. jmp @@4
  1454. @@2: inc bx
  1455. loop @@0
  1456. call SaveCounter
  1457. @@4:
  1458. pop ds
  1459. ret
  1460. ;
  1461. ;-----------------------------------------------------------------------------
  1462. BackupCVTchain:
  1463. mov ax, 'VC'
  1464. stosw
  1465. push ax
  1466. push bx
  1467. push cx
  1468. push ds
  1469. push es
  1470. mov ah, 52h
  1471. int21h ; ES:BX -- DOS table as described below

  1472. ; --------------------------------------------------------------------
  1473. push es ; DPB chains
  1474. push bx
  1475. lds si, es:[bx]
  1476. push cs
  1477. pop es
  1478. mov ax, si
  1479. stosw
  1480. mov ax, ds
  1481. stosw
  1482. mov bx, cs:cvtOfs
  1483. xor cx, cx
  1484. @@1: mov al, ds:[si+1]
  1485. stosb
  1486. mov ax, ds:[si+bx+12h]
  1487. stosw
  1488. mov ax, ds:[si+bx+14h]
  1489. stosw
  1490. inc cx
  1491. lds si, ds:[si+bx+18h]
  1492. cmp si, -1
  1493. jnz @@1
  1494. ; mov ax, 5
  1495. ; mul cl
  1496. ; add ax, 4
  1497. ; add cs:tsrLength, ax
  1498. pop bx
  1499. pop es

  1500. ; --------------------------------------------------------------------
  1501. push es ; DCB file control blocks
  1502. push bx
  1503. les bx, es:[bx+4]
  1504. @@11: cmp word ptr es:[bx], -1
  1505. jz @@10
  1506. les bx, es:[bx]
  1507. jmp @@11
  1508. @@10:
  1509. mov ax, es
  1510. xchg ax, bx
  1511. push cs
  1512. pop es
  1513. stosw
  1514. xchg ax, bx
  1515. stosw
  1516. pop bx
  1517. pop es
  1518. ; add cs:tsrLength, 4

  1519. ; ---------------------------------------------------------------------
  1520. push es ; Device Driver Chains
  1521. pop ds
  1522. add bx, 22h
  1523. mov si, bx ; NUL

  1524. pop es
  1525. mov ax, si
  1526. stosw
  1527. mov ax, ds
  1528. stosw
  1529. xor cx, cx
  1530. xor bx, bx
  1531. @@9: push si
  1532. mov cl, 5
  1533. rep movsw
  1534. inc bx
  1535. pop si
  1536. lds si, ds:[si]
  1537. mov ax, si
  1538. inc ax
  1539. jnz @@9

  1540. pop ds
  1541. pop cx
  1542. pop bx
  1543. pop ax
  1544. ret

  1545. ; ----------------------------------------------------------------------------

  1546. BackupBiosData:
  1547. mov ax, '--'
  1548. stosw
  1549. push ds
  1550. push si
  1551. mov si, 40h
  1552. mov ds, si
  1553. mov si, 10h
  1554. movsw
  1555. mov si, 0a8h
  1556. movsw
  1557. movsw
  1558. mov si, 49h
  1559. mov cx, 1dh
  1560. rep movsb

  1561. mov si, 0f0h
  1562. mov cx, 8
  1563. rep movsw
  1564. pop si
  1565. pop ds
  1566. ret

  1567. ; ---------------------------------------------------------------------------

  1568. BackupMemoryManager:
  1569. push cs
  1570. pop es
  1571. push ds
  1572. push es
  1573. call SaveXMSstatus
  1574. call SaveEMSstatus
  1575. pop es
  1576. pop ds
  1577. ret

  1578. ;---------------------------------------------------------------------

  1579. SaveEMSstatus:
  1580. test cs:status, EMSbit
  1581. jnz @@1
  1582. ret
  1583. @@1:
  1584. mov ax, 'ME'
  1585. stosw
  1586. inc di
  1587. inc di
  1588. push di
  1589. mov ah, 4dh
  1590. int67h
  1591. pop di
  1592. mov es:[di-2], bx
  1593. shl bx, 1
  1594. shl bx, 1
  1595. add di, bx
  1596. ret
  1597. ; -------------------------------------------------------------------

  1598. SaveXMSstatus:
  1599. call XMS_test
  1600. test cs:status, XMSbit
  1601. jnz @@1
  1602. ret
  1603. @@1:
  1604. mov ax, 'MX'
  1605. stosw

  1606. mov dx, 1
  1607. call XMS_alloc
  1608. jnz @@_1
  1609. xor cx, cx ; XMS alloc failure
  1610. stosw
  1611. ret
  1612. @@_1:
  1613. push dx
  1614. sub dx, MaxHandles 10
  1615. @@2:
  1616. push dx
  1617. call XMS_Lock
  1618. pop dx
  1619. jnz @@3 cmp bl, 0a2h
  1620. jnz @@4
  1621. add dx, 10
  1622. jmp @@2
  1623. @@3: push dx
  1624. call XMS_unlock
  1625. pop dx
  1626. @@4:
  1627. mov cs:handle_begin, dx
  1628. pop dx
  1629. push dx
  1630. call XMS_bstat
  1631. xor cx, cx
  1632. mov cl, bl
  1633. inc cx
  1634. pop dx
  1635. call XMS_Free
  1636. mov dx, cs:Handle_begin

  1637. push cx
  1638. push cs
  1639. pop es
  1640. mov ax, cx
  1641. stosw
  1642. @@5: push dx
  1643. call XMS_Lock
  1644. pop dx
  1645. jnz @@6 cmp bl, 0a2h ; Handle invalid
  1646. jz @@7
  1647. @@6: call XMS_unlock
  1648. add dx, 10
  1649. jmp @@5
  1650. @@7: mov ax, dx
  1651. stosw
  1652. add dx, 10
  1653. loop @@5
  1654. pop cx
  1655. ret
  1656. ; ------------------------------------------------------------------

  1657. XMS_test:
  1658. push es
  1659. mov ax, 4300h
  1660. int2fh
  1661. cmp al, 80h
  1662. jnz @@9
  1663. mov ax, 4310h
  1664. int2fh
  1665. mov cs:XMS_control, bx
  1666. mov cs:XMS_control[2], es
  1667. or cs:Status, XMSbit
  1668. @@9:
  1669. pop es
  1670. ret

  1671. XMS_stat:
  1672. mov ah, 0
  1673. call dword ptr cs:xms_control
  1674. mov hma_exist, dl
  1675. ret
  1676. hma_exist db 0

  1677. XMS_alloc:
  1678. mov ah, 9
  1679. call dword ptr cs:xms_control
  1680. or ax, ax
  1681. ret

  1682. XMS_lock:
  1683. mov ah, 0ch
  1684. call dword ptr cs:xms_control
  1685. or ax, ax
  1686. ret

  1687. XMS_unlock:
  1688. mov ah, 0dh
  1689. call dword ptr cs:xms_control
  1690. or ax, ax
  1691. ret
  1692. XMS_bstat:
  1693. mov ah, 0eh
  1694. call dword ptr cs:xms_control
  1695. or ax, ax
  1696. ret

  1697. XMS_free:
  1698. mov ah, 0ah
  1699. call dword ptr cs:xms_control
  1700. or ax, ax
  1701. ret

  1702. ; ----------------------------------------------------------------------------
  1703. EMS_test:
  1704. push cs
  1705. pop ds
  1706. mov dx, offset EMMname
  1707. mov ax, 3d00h
  1708. int21h
  1709. jc @@2
  1710. mov bx, ax
  1711. mov ah, 3eh
  1712. int21h
  1713. or cs:Status, EMSbit
  1714. @@2:
  1715. ret
  1716. EMMname db 'EMMXXXX0',0

  1717. ; -----------------------------------------------------------------------------

  1718. SetHotKey:
  1719. xor bx, bx
  1720. lodsb
  1721. push ax

  1722. @@1: lodsb
  1723. cmp al, 0dh
  1724. jz @@9 cmp al, 'C'
  1725. jnz @@2
  1726. or bl, LeftCtrl
  1727. jmp @@1
  1728. @@2:
  1729. cmp al, 'c'
  1730. jnz @@3
  1731. or bl, RightCtrl
  1732. jmp @@1
  1733. @@3:
  1734. cmp al, 'A'
  1735. jnz @@4
  1736. or bl, LeftAlt
  1737. jmp @@1
  1738. @@4:
  1739. cmp al, 'a'
  1740. jnz @@5
  1741. or bl, RightAlt
  1742. jmp @@1
  1743. @@5:
  1744. cmp al, 'S'
  1745. jnz @@6
  1746. or bl, LeftShift
  1747. jmp @@1
  1748. @@6:
  1749. cmp al, 's'
  1750. jnz @@7
  1751. or bl, RightShift
  1752. jmp @@1
  1753. @@7: pop ax
  1754. jmp @Err
  1755. @@9:
  1756. mov cs:HotKey, bl
  1757. pop ax
  1758. mov cs:AuxHotKey, 2dh ; 'X' scan key
  1759. cmp al, '1'
  1760. jz @@29
  1761. mov cs:AuxHotKey, 0
  1762. @@29:
  1763. cmp cs:Self, 0
  1764. jz @@30
  1765. push es
  1766. mov es, cs:Self
  1767. mov es:HotKey, bl
  1768. mov bl, cs:AuxHotKey
  1769. mov es:AuxHotKey, bl
  1770. pop es
  1771. @@30:
  1772. call GetRunFileName
  1773. mov ax, 3d02h
  1774. int21h
  1775. jc @@10
  1776. push cs
  1777. pop ds
  1778. mov bx, ax
  1779. mov cx, 4
  1780. mov dx, 100h
  1781. mov ah, 40h
  1782. int21h
  1783. jc @@10
  1784. mov ax, 4200h
  1785. xor cx, cx
  1786. mov dx, 17h
  1787. int21h
  1788. jc @@10
  1789. mov cx, 1
  1790. mov dx, offset AuxHotKey
  1791. mov ah, 40h
  1792. int21h
  1793. jc @@10
  1794. mov ah, 3eh
  1795. int21h
  1796. @@10:
  1797. ret


  1798. ; -----------------------------------------------------------------------
  1799. GetRunFileName:
  1800. ; Return:
  1801. ; DS:DX Pointer ofthisrun file name ASCIIZstring
  1802. push ax
  1803. push bx
  1804. push cx
  1805. push si
  1806. push di
  1807. push es

  1808. push cs
  1809. pop es
  1810. mov ax, es:[2ch]
  1811. mov es, ax
  1812. xor di, di
  1813. mov cx, 1000h
  1814. xor al, al
  1815. @@1: repnz scasb
  1816. cmp es:[di], al
  1817. loopnz @@1
  1818. mov dx, di
  1819. add dx, 3
  1820. push es
  1821. pop ds

  1822. pop es
  1823. pop di
  1824. pop si
  1825. pop cx
  1826. pop bx
  1827. pop ax
  1828. ret

  1829. ; ---------------------------------------------------------------------------
  1830. GetMachineID:
  1831. push es
  1832. mov KBD102,True
  1833. mov ax,40h
  1834. mov es,ax
  1835. test byte ptr es:[96h], 00010000b
  1836. jnz @@1
  1837. mov Kbd102,False
  1838. @@1:
  1839. xor ax,ax
  1840. dec ax
  1841. mov es,ax
  1842. mov al,es:[0eh]
  1843. mov cs:MachineID, al
  1844. pop es
  1845. ret

  1846. ; ---------------------------------------------------------------------------
  1847. ModifyHotKeyPrompt:
  1848. cmp cs:Kbd102, True
  1849. jz @@9
  1850. push cs
  1851. pop es
  1852. push cs
  1853. pop ds
  1854. mov cx, 124
  1855. mov si, offset KMsg2
  1856. mov di, offset KMsg1
  1857. rep movsb
  1858. @@9: cmp cs:MachineID, 0fch
  1859. jna @@10
  1860. mov cs:clsStrcolor, 70h ; Mono
  1861. mov cs:clsStr, 70h
  1862. @@10:
  1863. ret

  1864. ; ---------------------------------------------------------------------------
  1865. PrintHotKeyPrompt:
  1866. Print Msg1
  1867. mov al, cs:HotKey
  1868. mov ah, al
  1869. shr al, 1
  1870. shr al, 1
  1871. and ax, 33ch
  1872. or al, ah
  1873. mov dx, offset KeyMsg
  1874. @@40:
  1875. or ax, ax ; Mr. Lei 4/25/1993
  1876. jz @@_42
  1877. shr al, 1
  1878. push ax
  1879. jnc @@41

  1880. push ax
  1881. call ColorDisplayStr
  1882. ; mov ah, 9
  1883. ;int21h
  1884. pop ax

  1885. or al, al
  1886. jz @@42

  1887. push dx
  1888. mov dx, offset PlusMsg
  1889. call ColorDisplayStr
  1890. ; Print PlusMsg
  1891. pop dx

  1892. @@41: add dx, 12
  1893. pop ax
  1894. jmp @@40
  1895. @@42: pop ax
  1896. @@_42: cmp cs:AuxHotKey, 0
  1897. jz @@43 cmp cs:HotKey, 0 ; Mr. Lei
  1898. jz @@_43
  1899. mov dx, offset PlusMsg
  1900. call ColorDisplayStr
  1901. ; Print PlusMsg
  1902. @@_43: mov dx, offset AuxHotKeyName
  1903. call ColorDisplayStr
  1904. ; Print AuxHotKeyName
  1905. @@43:
  1906. Print crlf
  1907. ret

  1908. ColorDisplayStr:
  1909. push bx
  1910. push cx
  1911. push dx
  1912. push si
  1913. mov bl, 0fh
  1914. mov si, dx
  1915. xor bh, bh
  1916. mov cx, 1
  1917. @@1: lodsb
  1918. cmp al, '

  1919. jz @@2
  1920. or al, al
  1921. jz @@2
  1922. push cx
  1923. mov ah, 09h
  1924. int10h
  1925. mov ah, 3int10h
  1926. inc dl
  1927. mov ah, 2int10h
  1928. pop cx
  1929. jmpshort@@1
  1930. @@2:
  1931. pop si
  1932. pop dx
  1933. pop cx
  1934. pop bx
  1935. ret

  1936. ; ---------------------------------------------------------------------------
  1937. CmpSideKick:
  1938. xor ax, ax
  1939. mov es, ax
  1940. les bx, es:[20h]
  1941. cmp word ptr es:[bx-4], 4b53h
  1942. jnz @@1 cmp word ptr es:[bx-2], 4942h
  1943. jz @@2
  1944. @@1: mov es, ax
  1945. les bx, es:[94h]
  1946. cmp word ptr es:[bx-2], 4b53h
  1947. jz @@2
  1948. ret
  1949. @@2: or cs:Status, SKbit
  1950. ret

  1951. ; ---------------------------------------------------------------------------
  1952. CmpDosVer: mov ah, 30h
  1953. int21h
  1954. cmp al, 3
  1955. jb @@1 cmp al, 3
  1956. jna @@2
  1957. mov cs:cvtOfs, 1
  1958. ret
  1959. @@2: mov cs:cvtOfs, 0
  1960. ret
  1961. @@1: Print DosVerErr
  1962. mov ax, 4cffh
  1963. int21h

  1964. DosVerErr db 'Sorry, DOS version too lower !',0dh,0ah,'


  1965. HotKeyValid:
  1966. cmp cs:HotKey, 0
  1967. jnz @@_1
  1968. cmp cs:AuxHotKey, 0
  1969. jnz @@_1
  1970. Print HotKeyErr
  1971. mov ax, 4cfeh
  1972. int21h
  1973. @@_1: ret

  1974. HotKeyErr db 'Sorry, please setup hotkey again. ',0dh,0ah,'


  1975. eof:
  1976. ends
  1977. end Start

  1978. ; ------------- The End !---------------------------------------------------