新支点操作系统社区 版块 社区版务 新支点茶馆 雷军1994年写的老代码曝光,被称像诗一样优雅 ...
  在2011年的时候,有程序员评价雷军这段汇编代码「如今能写出这么高质量的代码的程序员恐怕也不多」。
01.jpg
  后来雷军在转发我们微博时还补充说:「这个程序第一个版本是我1989年写的,怀念当初写程序的快乐时光。」
  有些网友在评论中质疑,说雷军代码不会是「屎」一样优雅吧。说这话的网友,也许是开玩笑的,也许是真没看过雷军写过的代码。
02.jpg
03.jpg
  前方高能……


收藏

用户回复

跳转到指定楼层
雷雷 博士后2022-4-4 22:15:15
现在真正会底层技术的人才不多拉,图形界面少了很多原理的学习。
雷雷 博士后2022-3-24 22:46:26
其实那个年代学计算机还是很枯燥的
路人甲 初中生2020-6-12 17:57:35

  1. BackupBiosData:
  2. mov ax, '--'
  3. stosw
  4. push ds
  5. push si
  6. mov si, 40h
  7. mov ds, si
  8. mov si, 10h
  9. movsw
  10. mov si, 0a8h
  11. movsw
  12. movsw
  13. mov si, 49h
  14. mov cx, 1dh
  15. rep movsb

  16. mov si, 0f0h
  17. mov cx, 8
  18. rep movsw
  19. pop si
  20. pop ds
  21. ret

  22. ; ---------------------------------------------------------------------------

  23. BackupMemoryManager:
  24. push cs
  25. pop es
  26. push ds
  27. push es
  28. call SaveXMSstatus
  29. call SaveEMSstatus
  30. pop es
  31. pop ds
  32. ret

  33. ;---------------------------------------------------------------------

  34. SaveEMSstatus:
  35. test cs:status, EMSbit
  36. jnz @@1
  37. ret
  38. @@1:
  39. mov ax, 'ME'
  40. stosw
  41. inc di
  42. inc di
  43. push di
  44. mov ah, 4dh
  45. int 67h
  46. pop di
  47. mov es:[di-2], bx
  48. shl bx, 1
  49. shl bx, 1
  50. add di, bx
  51. ret
  52. ; -------------------------------------------------------------------

  53. SaveXMSstatus:
  54. call XMS_test
  55. test cs:status, XMSbit
  56. jnz @@1
  57. ret
  58. @@1:
  59. mov ax, 'MX'
  60. stosw

  61. mov dx, 1
  62. call XMS_alloc
  63. jnz @@_1
  64. xor cx, cx ; XMS alloc failure
  65. stosw
  66. ret
  67. @@_1:
  68. push dx
  69. sub dx, MaxHandles  10
  70. @@2:
  71. push dx
  72. call XMS_Lock
  73. pop dx
  74. jnz @@3 cmp bl, 0a2h
  75. jnz @@4
  76. add dx, 10
  77. jmp @@2
  78. @@3: push dx
  79. call XMS_unlock
  80. pop dx
  81. @@4:
  82. mov cs:handle_begin, dx
  83. pop dx
  84. push dx
  85. call XMS_bstat
  86. xor cx, cx
  87. mov cl, bl
  88. inc cx
  89. pop dx
  90. call XMS_Free
  91. mov dx, cs:Handle_begin

  92. push cx
  93. push cs
  94. pop es
  95. mov ax, cx
  96. stosw
  97. @@5: push dx
  98. call XMS_Lock
  99. pop dx
  100. jnz @@6 cmp bl, 0a2h ; Handle invalid
  101. jz @@7
  102. @@6: call XMS_unlock
  103. add dx, 10
  104. jmp @@5
  105. @@7: mov ax, dx
  106. stosw
  107. add dx, 10
  108. loop @@5
  109. pop cx
  110. ret
  111. ; ------------------------------------------------------------------

  112. XMS_test:
  113. push es
  114. mov ax, 4300h
  115. int 2fh
  116. cmp al, 80h
  117. jnz @@9
  118. mov ax, 4310h
  119. int 2fh
  120. mov cs:XMS_control, bx
  121. mov cs:XMS_control[2], es
  122. or cs:Status, XMSbit
  123. @@9:
  124. pop es
  125. ret

  126. XMS_stat:
  127. mov ah, 0
  128. call dword ptr cs:xms_control
  129. mov hma_exist, dl
  130. ret
  131. hma_exist db 0

  132. XMS_alloc:
  133. mov ah, 9
  134. call dword ptr cs:xms_control
  135. or ax, ax
  136. ret

  137. XMS_lock:
  138. mov ah, 0ch
  139. call dword ptr cs:xms_control
  140. or ax, ax
  141. ret

  142. XMS_unlock:
  143. mov ah, 0dh
  144. call dword ptr cs:xms_control
  145. or ax, ax
  146. ret
  147. XMS_bstat:
  148. mov ah, 0eh
  149. call dword ptr cs:xms_control
  150. or ax, ax
  151. ret

  152. XMS_free:
  153. mov ah, 0ah
  154. call dword ptr cs:xms_control
  155. or ax, ax
  156. ret

  157. ; ----------------------------------------------------------------------------
  158. EMS_test:
  159. push cs
  160. pop ds
  161. mov dx, offset EMMname
  162. mov ax, 3d00h
  163. int 21h
  164. jc @@2
  165. mov bx, ax
  166. mov ah, 3eh
  167. int 21h
  168. or cs:Status, EMSbit
  169. @@2:
  170. ret
  171. EMMname db 'EMMXXXX0',0

  172. ; -----------------------------------------------------------------------------

  173. SetHotKey:
  174. xor bx, bx
  175. lodsb
  176. push ax

  177. @@1: lodsb
  178. cmp al, 0dh
  179. jz @@9 cmp al, 'C'
  180. jnz @@2
  181. or bl, LeftCtrl
  182. jmp @@1
  183. @@2:
  184. cmp al, 'c'
  185. jnz @@3
  186. or bl, RightCtrl
  187. jmp @@1
  188. @@3:
  189. cmp al, 'A'
  190. jnz @@4
  191. or bl, LeftAlt
  192. jmp @@1
  193. @@4:
  194. cmp al, 'a'
  195. jnz @@5
  196. or bl, RightAlt
  197. jmp @@1
  198. @@5:
  199. cmp al, 'S'
  200. jnz @@6
  201. or bl, LeftShift
  202. jmp @@1
  203. @@6:
  204. cmp al, 's'
  205. jnz @@7
  206. or bl, RightShift
  207. jmp @@1
  208. @@7: pop ax
  209. jmp @Err
  210. @@9:
  211. mov cs:HotKey, bl
  212. pop ax
  213. mov cs:AuxHotKey, 2dh ; 'X' scan key
  214. cmp al, '1'
  215. jz @@29
  216. mov cs:AuxHotKey, 0
  217. @@29:
  218. cmp cs:Self, 0
  219. jz @@30
  220. push es
  221. mov es, cs:Self
  222. mov es:HotKey, bl
  223. mov bl, cs:AuxHotKey
  224. mov es:AuxHotKey, bl
  225. pop es
  226. @@30:
  227. call GetRunFileName
  228. mov ax, 3d02h
  229. int 21h
  230. jc @@10
  231. push cs
  232. pop ds
  233. mov bx, ax
  234. mov cx, 4
  235. mov dx, 100h
  236. mov ah, 40h
  237. int 21h
  238. jc @@10
  239. mov ax, 4200h
  240. xor cx, cx
  241. mov dx, 17h
  242. int 21h
  243. jc @@10
  244. mov cx, 1
  245. mov dx, offset AuxHotKey
  246. mov ah, 40h
  247. int 21h
  248. jc @@10
  249. mov ah, 3eh
  250. int 21h
  251. @@10:
  252. ret


  253. ; -----------------------------------------------------------------------
  254. GetRunFileName:
  255. ; Return:
  256. ; DS:DX Pointer of this run file name ASCIIZ string
  257. push ax
  258. push bx
  259. push cx
  260. push si
  261. push di
  262. push es

  263. push cs
  264. pop es
  265. mov ax, es:[2ch]
  266. mov es, ax
  267. xor di, di
  268. mov cx, 1000h
  269. xor al, al
  270. @@1: repnz scasb
  271. cmp es:[di], al
  272. loopnz @@1
  273. mov dx, di
  274. add dx, 3
  275. push es
  276. pop ds

  277. pop es
  278. pop di
  279. pop si
  280. pop cx
  281. pop bx
  282. pop ax
  283. ret

  284. ; ---------------------------------------------------------------------------
  285. GetMachineID:
  286. push es
  287. mov KBD102,True
  288. mov ax,40h
  289. mov es,ax
  290. test byte ptr es:[96h], 00010000b
  291. jnz @@1
  292. mov Kbd102,False
  293. @@1:
  294. xor ax,ax
  295. dec ax
  296. mov es,ax
  297. mov al,es:[0eh]
  298. mov cs:MachineID, al
  299. pop es
  300. ret

  301. ; ---------------------------------------------------------------------------
  302. ModifyHotKeyPrompt:
  303. cmp cs:Kbd102, True
  304. jz @@9
  305. push cs
  306. pop es
  307. push cs
  308. pop ds
  309. mov cx, 124
  310. mov si, offset KMsg2
  311. mov di, offset KMsg1
  312. rep movsb
  313. @@9: cmp cs:MachineID, 0fch
  314. jna @@10
  315. mov cs:clsStrcolor, 70h ; Mono
  316. mov cs:clsStr, 70h
  317. @@10:
  318. ret

  319. ; ---------------------------------------------------------------------------
  320. PrintHotKeyPrompt:
  321. Print Msg1
  322. mov al, cs:HotKey
  323. mov ah, al
  324. shr al, 1
  325. shr al, 1
  326. and ax, 33ch
  327. or al, ah
  328. mov dx, offset KeyMsg
  329. @@40:
  330. or ax, ax ; Mr. Lei 4/25/1993
  331. jz @@_42
  332. shr al, 1
  333. push ax
  334. jnc @@41

  335. push ax
  336. call ColorDisplayStr
  337. ; mov ah, 9
  338. ; int 21h
  339. pop ax

  340. or al, al
  341. jz @@42

  342. push dx
  343. mov dx, offset PlusMsg
  344. call ColorDisplayStr
  345. ; Print PlusMsg
  346. pop dx

  347. @@41: add dx, 12
  348. pop ax
  349. jmp @@40
  350. @@42: pop ax
  351. @@_42: cmp cs:AuxHotKey, 0
  352. jz @@43 cmp cs:HotKey, 0 ; Mr. Lei
  353. jz @@_43
  354. mov dx, offset PlusMsg
  355. call ColorDisplayStr
  356. ; Print PlusMsg
  357. @@_43: mov dx, offset AuxHotKeyName
  358. call ColorDisplayStr
  359. ; Print AuxHotKeyName
  360. @@43:
  361. Print crlf
  362. ret

  363. ColorDisplayStr:
  364. push bx
  365. push cx
  366. push dx
  367. push si
  368. mov bl, 0fh
  369. mov si, dx
  370. xor bh, bh
  371. mov cx, 1
  372. @@1: lodsb
  373. cmp al, '


  374. jz @@2
  375. or al, al
  376. jz @@2
  377. push cx
  378. mov ah, 09h
  379. int 10h
  380. mov ah, 3 int 10h
  381. inc dl
  382. mov ah, 2 int 10h
  383. pop cx
  384. jmp short @@1
  385. @@2:
  386. pop si
  387. pop dx
  388. pop cx
  389. pop bx
  390. ret

  391. ; ---------------------------------------------------------------------------
  392. CmpSideKick:
  393. xor ax, ax
  394. mov es, ax
  395. les bx, es:[20h]
  396. cmp word ptr es:[bx-4], 4b53h
  397. jnz @@1 cmp word ptr es:[bx-2], 4942h
  398. jz @@2
  399. @@1: mov es, ax
  400. les bx, es:[94h]
  401. cmp word ptr es:[bx-2], 4b53h
  402. jz @@2
  403. ret
  404. @@2: or cs:Status, SKbit
  405. ret

  406. ; ---------------------------------------------------------------------------
  407. CmpDosVer: mov ah, 30h
  408. int 21h
  409. cmp al, 3
  410. jb @@1 cmp al, 3
  411. jna @@2
  412. mov cs:cvtOfs, 1
  413. ret
  414. @@2: mov cs:cvtOfs, 0
  415. ret
  416. @@1: Print DosVerErr
  417. mov ax, 4cffh
  418. int 21h

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



  420. HotKeyValid:
  421. cmp cs:HotKey, 0
  422. jnz @@_1
  423. cmp cs:AuxHotKey, 0
  424. jnz @@_1
  425. Print HotKeyErr
  426. mov ax, 4cfeh
  427. int 21h
  428. @@_1: ret

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



  430. eof:
  431. ends
  432. end Start

  433. ; ------------- The End ! ---------------------------------------------------
复制代码


路人甲 初中生2020-6-12 17:57:13
  1. B:
  2. mov ax, 'ZM'
  3. stosw
  4. push ds
  5. push es
  6. mov ah, 52h
  7. int 21h ; Get MCB chain head
  8. mov ax, es:[bx-2]
  9. pop es
  10. @@0: mov ds, ax
  11. cmp byte ptr ds:[0], 'Z' ; End ?
  12. jz @@20 cmp byte ptr ds:[0], 'M' ; Memory control block
  13. jnz @@30 cmp word ptr ds:[3], 0 ; Nul mcb
  14. jz @@10 cmp word ptr ds:[1], 0 ; Free MCB
  15. jnz @@10
  16. call SaveFreeMCB
  17. @@10: inc ax
  18. add ax, ds:[3]
  19. jmp @@0
  20. @@20:
  21. call SaveFreeMCB
  22. cmp ax, 0a000h
  23. inc ax
  24. jnb @@30
  25. mov ax, 9fffh ; MS-DOS UMB
  26. jmp @@0

  27. @@30:
  28. cmp ax, 0c000h ; 386MAX
  29. ja @@90
  30. mov ax, 0c020h
  31. jmp @@0

  32. @@90: ; Error ?
  33. pop ds
  34. mov ax, 'MM' ; Set MCB flag
  35. stosw
  36. ret

  37. SaveFreeMCB:
  38. stosw
  39. xor si,si
  40. movsb
  41. movsw
  42. movsw
  43. ret
  44. ;
  45. ; push ax
  46. ; stosw
  47. ; xor si,si
  48. ; movsb
  49. ; movsw
  50. ; movsw
  51. ; pop ax
  52. ; cmp ax, 09fffh
  53. ; jnb @@3
  54. ; push ax
  55. ; push ds
  56. ; mov ds,ax
  57. ; cmp byte ptr ds:[0], 'M'
  58. ; pop ds
  59. ; pop ax
  60. ; jnz @@4
  61. ; mov ax, 09fffh ; MS-DOS UMB
  62. ; jmp @@0
  63. ; @@4: cmp ax, 0c000h
  64. ; ja @@3
  65. ; mov ax, 0c020h ; 386MAX
  66. ; jmp @@0
  67. ;
  68. ; --------------------------------------------------------------------------

  69. OpenLEDs: push ax ; Open all LEDs
  70. or al, 070h
  71. mov ds:[17h], al
  72. mov ah, 1 int 16h
  73. mov cx, 4 ; Delay
  74. @@20: push cx
  75. xor cx, cx
  76. @@21: loop @@21
  77. pop cx
  78. loop @@20
  79. pop ax
  80. mov ds:[17h], al
  81. mov ah, 1 int 16h
  82. ret

  83. ; --------------------------------------------------------------------------
  84. SetSelfInt:
  85. push es
  86. push di

  87. cmp cs:self, 0
  88. jnz @@1
  89. push cs
  90. pop ds
  91. mov ax,3509h
  92. int 21h
  93. mov word ptr cs:oldInt9_addr,bx
  94. mov word ptr cs:oldInt9_addr[2],es
  95. mov dx,offset NewInt9
  96. mov ax,2509h
  97. int 21h

  98. mov ax,352Fh
  99. int 21h
  100. mov word ptr cs:oldInt2F_addr,bx
  101. mov word ptr cs:oldInt2F_addr[2],es
  102. mov dx,offset newInt2F
  103. mov ax,252Fh
  104. int 21h

  105. mov ax,351Ch
  106. int 21h
  107. mov word ptr cs:oldInt1C_addr,bx
  108. mov word ptr cs:oldInt1C_addr[2],es
  109. mov dx,offset newInt1C
  110. mov ax,251ch
  111. int 21h
  112. cli
  113. jmp @@2
  114. @@1:
  115. mov es, cs:Self
  116. inc es:Copies
  117. @@_0: cmp es:NextDataSeg, -1
  118. jz @@_1
  119. mov es, es:NextDataSeg
  120. jmp @@_0
  121. @@_1: mov es:NextDataSeg, cs
  122. @@2:
  123. pop di
  124. pop es
  125. ret

  126. ; -----------------------------------------------------------------------
  127. SaveCounter:
  128. mov word ptr es:[di], 'EL'
  129. mov byte ptr es:[di+2], 'I'
  130. mov byte ptr es:[di+3], bl
  131. xor bx, bx
  132. add di, 4
  133. ret

  134. ; -----------------------------------------------------------------------
  135. DisplayStr: push cs
  136. pop ds
  137. mov ah, 9 int 21h
  138. ret

  139. ; -----------------------------------------------------------------------
  140. CmdLine:
  141. push cs
  142. pop ds
  143. xor ax, ax
  144. mov si, 80h
  145. lodsb
  146. or al, al
  147. jnz @@1
  148. ret
  149. @@1:
  150. mov cx, ax
  151. dec ax
  152. push ax
  153. push si
  154. @@0: lodsb
  155. cmp al, ' '
  156. jz @@0 cmp al, '/'
  157. jnz @@2
  158. lodsb
  159. cmp al, 'S'
  160. jz @@_2
  161. cmp al, 's'
  162. jnz @@2
  163. @@_2:
  164. call SetHotKey
  165. Print SetMsg
  166. mov ax, 4c00h
  167. int 21h
  168. @@2:
  169. pop si
  170. pop ax
  171. push ax
  172. push si
  173. @@_3: lodsb
  174. cmp al, 'A'
  175. jb @@3 cmp al, 'Z'
  176. ja @@3
  177. add byte ptr ds:[si-1],20h ; DownCase
  178. @@3: loop @@_3
  179. pop si
  180. pop cx

  181. add si, cx
  182. lodsb
  183. cmp al, 's' ; CLS
  184. jnz @@5 cmp word ptr ds:[si-3], 'lc'
  185. jnz @@5 cmp cs:Self, 0
  186. jz @Err
  187. mov ax, 0c0d7h+1 int 2fh

  188. @@5: cmp al, 'h' ; HELP
  189. jz @help
  190. cmp al, '?'
  191. jz @help
  192. cmp al, 't' ; RET
  193. jnz @@6 cmp word ptr ds:[si-3], 'er'
  194. jnz @@6
  195. @@7:
  196. cmp cs:Self, 0
  197. jz @Err
  198. mov ax, 0c0d7h+2 int 2fh
  199. @@6: cmp al, 'w' ; NEW
  200. jnz @@8 cmp word ptr ds:[si-3], 'en'
  201. jnz @@8
  202. mov cs:tsrOK, true
  203. ret
  204. @@8:
  205. cmp al, 'l' ; ALL
  206. jnz @@9 cmp word ptr ds:[si-3], 'la'
  207. jnz @@9
  208. mov ax, 0c0d7h+3 int 2fh
  209. @@9:
  210. cmp al, ' '
  211. jnz @Err
  212. ret

  213. @Err:
  214. Print ErrMsg
  215. @help:
  216. Print HelpMsg
  217. mov ax, 4c00h
  218. int 21h

  219. ;---------------------------------------------------------------------------
  220. tsrReplyOK:
  221. cmp cs:Self, 0
  222. jz @@1
  223. Print Msg0

  224. push es
  225. mov ax, cs:Self
  226. @@_10: mov es, ax
  227. mov ax, es:NextDataSeg
  228. cmp ax, -1
  229. jnz @@_10
  230. mov ax, es

  231. @@_0: push ax
  232. dec ax
  233. mov es, ax
  234. mov bx, es:[3]
  235. pop ax

  236. add ax, bx
  237. inc ax
  238. mov es, ax
  239. cmp word ptr es:[0], 'OC'
  240. jz @@_0

  241. mov bx, cs
  242. cmp ax, bx
  243. pop es
  244. jz @@2
  245. Print Msg_0
  246. mov ah, 1 int 21h

  247. push ax
  248. Print crlf
  249. pop ax

  250. cmp al, 'y'
  251. jz @@3 cmp al, 'Y'
  252. jz @@3
  253. @@2: ; Print Msg_1
  254. mov ax, 4c01h
  255. int 21h
  256. @@3:
  257. @@1: mov cs:tsrOK, true
  258. ret

  259. PrintCopies:
  260. cmp cs:Self, 0
  261. jz @@1
  262. push es ; Added -by- Mr. Lei
  263. mov es, cs:Self ; Aug 24, 1993
  264. mov al, es:Copies
  265. inc al ; Total RI copies
  266. push ax ; Set es = current mcb
  267. mov ax, cs
  268. dec ax
  269. mov es, ax
  270. pop ax
  271. mov cx, 5 ; Search end of file name
  272. mov bx, 8
  273. @@10: inc bx
  274. cmp byte ptr es:[bx], 20h
  275. jz @@20 cmp byte ptr es:[bx], 0ffh
  276. jz @@20 cmp byte ptr es:[bx], 00h
  277. jz @@20
  278. loop @@10
  279. @@20: ; Set current RI no
  280. mov byte ptr es:[bx], ':' ; "RI:2"
  281. mov byte ptr es:[bx+1], al
  282. cmp bx, 8+7
  283. jnb @@30
  284. mov byte ptr es:[bx+2], 0
  285. @@30:
  286. pop es

  287. mov cs:Msg_RI, al
  288. Print Msg_2
  289. @@1: ret

  290. ;---------------------------------------------------------------------------
  291. ; Backup Interrupt Vector List
  292. ;
  293. BackupVecList:
  294. push ds
  295. push cs
  296. pop es
  297. xor si,si ; Vectors
  298. mov ds,si
  299. movsw
  300. movsw
  301. xor bx, bx
  302. mov cx,00ffh
  303. @@0: lodsw
  304. xchg dx, ax
  305. lodsw
  306. cmp ax, es:[di-2]
  307. jnz @@1 cmp dx, es:[di-4]
  308. jz @@2
  309. @@1: or bx, bx
  310. jz @@3
  311. call SaveCounter
  312. @@3: xchg dx, ax
  313. stosw
  314. xchg dx, ax
  315. stosw
  316. loop @@0
  317. jmp @@4
  318. @@2: inc bx
  319. loop @@0
  320. call SaveCounter
  321. @@4:
  322. pop ds
  323. ret
  324. ;
  325. ;-----------------------------------------------------------------------------
  326. BackupCVTchain:
  327. mov ax, 'VC'
  328. stosw
  329. push ax
  330. push bx
  331. push cx
  332. push ds
  333. push es
  334. mov ah, 52h
  335. int 21h ; ES:BX -- DOS table as described below

  336. ; --------------------------------------------------------------------
  337. push es ; DPB chains
  338. push bx
  339. lds si, es:[bx]
  340. push cs
  341. pop es
  342. mov ax, si
  343. stosw
  344. mov ax, ds
  345. stosw
  346. mov bx, cs:cvtOfs
  347. xor cx, cx
  348. @@1: mov al, ds:[si+1]
  349. stosb
  350. mov ax, ds:[si+bx+12h]
  351. stosw
  352. mov ax, ds:[si+bx+14h]
  353. stosw
  354. inc cx
  355. lds si, ds:[si+bx+18h]
  356. cmp si, -1
  357. jnz @@1
  358. ; mov ax, 5
  359. ; mul cl
  360. ; add ax, 4
  361. ; add cs:tsrLength, ax
  362. pop bx
  363. pop es

  364. ; --------------------------------------------------------------------
  365. push es ; DCB file control blocks
  366. push bx
  367. les bx, es:[bx+4]
  368. @@11: cmp word ptr es:[bx], -1
  369. jz @@10
  370. les bx, es:[bx]
  371. jmp @@11
  372. @@10:
  373. mov ax, es
  374. xchg ax, bx
  375. push cs
  376. pop es
  377. stosw
  378. xchg ax, bx
  379. stosw
  380. pop bx
  381. pop es
  382. ; add cs:tsrLength, 4

  383. ; ---------------------------------------------------------------------
  384. push es ; Device Driver Chains
  385. pop ds
  386. add bx, 22h
  387. mov si, bx ; NUL

  388. pop es
  389. mov ax, si
  390. stosw
  391. mov ax, ds
  392. stosw
  393. xor cx, cx
  394. xor bx, bx
  395. @@9: push si
  396. mov cl, 5
  397. rep movsw
  398. inc bx
  399. pop si
  400. lds si, ds:[si]
  401. mov ax, si
  402. inc ax
  403. jnz @@9

  404. pop ds
  405. pop cx
  406. pop bx
  407. pop ax
  408. ret

  409. ; ----------------------------------------------------------------------------
复制代码


路人甲 初中生2020-6-12 17:56:47

  1. mov ah, 51h ; Get PSP seg
  2. int 21h
  3. mov es, bx
  4. mov ax, es:[16h] ; Prev PSP seg
  5. cmp ax, bx
  6. jnz @@9
  7. mov ax, 3e00h ; COMMAND
  8. mov bx, 4 int 21h
  9. @@9:
  10. ret

  11. InitPRN:
  12. mov ax, 3e00h
  13. mov bx, 4 ; PRN
  14. int 21h
  15. mov ax, 3d01h
  16. mov dx, offset PRNname
  17. push cs
  18. pop ds
  19. int 21h
  20. ret
  21. PRNname db 'PRN',0

  22. InitMouse: ; 2/16/1993 by Mr. Lei
  23. push es
  24. xor ax, ax
  25. mov es, ax
  26. cmp word ptr es:[33h4+2], 0
  27. jz @@0 cmp word ptr es:[33h4], 0
  28. jz @@0
  29. mov ax, 21h
  30. int 33h ; Hook Mouse Interrupt
  31. @@0: pop es
  32. ret

  33. ; ------------- CMOS CLOCK set to System -----------------------------------
  34. UpdateTime:
  35. call GetRealTime
  36. mov ah, 2dh
  37. int 21h
  38. ret

  39. GetRealTime:
  40. mov ah,2 int 1Ah
  41. mov al,ch
  42. call bcdxchg
  43. mov ch,al
  44. mov al,cl
  45. call bcdxchg
  46. mov cl,al
  47. mov al,dh
  48. call bcdxchg
  49. mov dh,al
  50. mov dl,0
  51. ret

  52. BCDxchg:
  53. push ax
  54. push cx
  55. mov cl,4
  56. shr al,cl
  57. pop cx
  58. mov bl,0Ah
  59. mul bl
  60. pop bx
  61. and bl,0Fh
  62. add al,bl
  63. ret

  64. ; -----------------------------------------------------------------------
  65. ; Display string
  66. ColorPrintStr:
  67. lodsb
  68. mov bh, al ; color
  69. xor cx, cx
  70. mov dx, 014fh
  71. mov ax, 0600h
  72. int 10h

  73. mov ah, 02 ; GotoXY (0, 0)
  74. xor dx, dx
  75. mov bh, 0 int 10h
  76. PrintStr:
  77. push cs
  78. pop ds
  79. xor bx, bx
  80. @@1: lodsb
  81. cmp al, '


  82. jz @@2
  83. or al, al
  84. jz @@2
  85. mov ah, 0eh
  86. int 10h
  87. jmp short @@1
  88. @@2: mov al, cs:clsStrcolor
  89. mov cs:clsStr, al
  90. ret

  91. ; -----------------------------------------------------------------------
  92. Self dw 0
  93. clsStrcolor db 17h
  94. clsStr db 17h ; Color (White in Blue)
  95. db ' RAMinit Version 2.12 (c) 1989-1994 by KingSoft Ltd. Mr. Leijun'
  96. db 0dh,0ah
  97. db ' ['
  98. ShowCopies db ''
  99. db '] Activate...',0ah,0dh,'



  100. endTSR equ $
  101. mcbList equ offset endTSR + 2 + 2
  102. vecList equ mcbList + 710 + 2 + 10h + 1 + 400h
  103. devLink equ vecList + 4 + 5  26 + 4 + 10  30h + 4
  104. xmsList equ devLink + 2 + MaxHandles  2
  105. emsList equ xmsList + 4 + 1024
  106. crtMode equ emsList + 2 + 1Dh + 4 + 10h
  107. tsrLen equ crtMode + 1
  108. ;
  109. ; DOS Environment Reserved by RI
  110. ; --------------------------------------------------
  111. ; Flag 'XX' 2 bytes
  112. ; Environment Segment 1 word
  113. ; Free MCBs <=710 bytes
  114. ; MCB segment 1 word
  115. ; MCB 5 bytes
  116. ; End flag 'MM' 1 word
  117. ; COM LPT ports 10h bytes
  118. ; LEDs status 1 bytes
  119. ; Packed vectors list <=400h bytes
  120. ; Flag 'CV' 2 bytes
  121. ; CVT First DPB pointer 4 bytes
  122. ; DPBs data <=526 bytes
  123. ; First DCB pointer 4 bytes
  124. ; Pointer to NUL 4 bytes
  125. ; All device driver datas <=30h10 bytes
  126. ; Flag 'XM' 2 bytes
  127. ; XMS free handle counter 2 bytes
  128. ; EMS free handle list <=100h4 bytes
  129. ; Flag 'EM' 2 bytes
  130. ; EMS free handle counter 2 bytes
  131. ; EMS free handle list <=1024 bytes
  132. ; EMS handle 1 word
  133. ; Number of pages 1 word
  134. ; Flag '--' 1 word
  135. ; Equipment List 1 word
  136. ; CRT 40:49h-66h 1dh bytes
  137. ; 40:A8h 1 dword
  138. ; BIOS User Data Area 40:F0--FF 10h bytes
  139. ; **
  140. ;
  141. main: jmp main0

  142. Print Macro Str
  143. Lea dx, Str
  144. call DisplayStr
  145. endm

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


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


  150. Msg_0 db 0ah,'Residents a new RAMinit copy [y/n] ?


  151. Msg_2 db 'OK, RI No.'
  152. Msg_RI db '2'
  153. db ' residents successful !', 0dh,0ah,'


  154. Msg1 db 'Activate with:


  155. KeyMsg db 'Right_Shift


  156. db 'Left_Shift$ '
  157. KMsg1 db 'Left_Ctrl$ '
  158. db 'Left_Alt$ '
  159. db 'Right_Ctrl$ '
  160. db 'Right_Alt$ '
  161. KMsg2 db 'Ctrl$ '
  162. db 'Alt$ '
  163. db 'Ctrl$ '
  164. db 'Alt$ '
  165. PlusMsg db ' +


  166. crlf db 0dh,0ah,'



  167. HelpMsg db 'Programmed by Mr. Leijun Dec 1992', 0dh,0ah,0ah
  168. db 'Usage: RI [options]',0dh,0ah,0ah
  169. db '/H,/? Display this screen',0dh,0ah
  170. db '/CLS Removes all TSR programs after current RI',0dh,0ah
  171. db '/RET Removes TSR programs include current RI',0dh,0ah
  172. db '/NEW Residents a new data copy of current environment',0dh,0ah
  173. db '/ALL Removes all RI copies and all other tsr programs',0dh,0ah
  174. db '/Sxyy.. Define Hotkey x=AuxHotkey yy..=shift status',0dh,0ah
  175. db ' x=auxiliary hotkey (default is "X") ',0dh,0ah
  176. db ' x equ "1" means need AuxHotkey',0dh,0ah
  177. db ' yy..=shift status [CAScas]',0dh,0ah
  178. db ' C: Left Ctrl A: Left Alt S: Left Shift',0dh,0ah
  179. db ' c: Right Ctrl a: Right Alt s: Right Shift',0dh,0ah,0ah
  180. db 'Example: "RI /S1c" means Hotkey is Right_Ctrl+X',0dh,0ah
  181. db ' "RI /S0Cc" means HotKey is Left_Ctrl+Right_Ctrl',0dh,0ah
  182. db ' "RI /CLS" equals simply press hotkey',0dh,0ah
  183. db ' "RI /RET" Removes all TSRs after current RI and this RI',0dh,0ah
  184. db 0ah
  185. db 'Contact me for RAMinit problems: (01)2561155 Call 1997',0dh,0ah
  186. db '


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


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


  189. SetMsg db 7, 'Defines new Hotkey successful !',0dh,0ah,0ah,'


  190. tsrOK db False

  191. Main0:
  192. cld
  193. Print instMsg
  194. call IsWinDos
  195. or ax, ax
  196. jz @@1
  197. Print WinErr
  198. mov ax, 4c00h
  199. int 21h
  200. @@1:
  201. call HotKeyValid
  202. mov cs:Status, 0
  203. call EMS_test
  204. call CmpDosVer
  205. call CmpSideKick
  206. call GetMachineID
  207. call ModifyHotKeyPrompt

  208. mov ax, 0c0d7h
  209. int 2fh
  210. mov es, ax
  211. cmp word ptr es:[101h], 'IE' ; 'LEI'
  212. jnz @@0
  213. mov cs:Self, ax
  214. @@0:
  215. call CmdLine
  216. call PrintHotKeyPrompt

  217. cmp cs:tsrOK, true
  218. jz @@2
  219. call tsrReplyOK
  220. @@2: cmp cs:tsrOK, true
  221. jnz @@_2
  222. call PrintCopies
  223. @@_2:
  224. mov word ptr cs:[100h], 'EL'
  225. mov byte ptr cs:[102h], 'I'

  226. push cs
  227. pop es
  228. push cs
  229. pop ds
  230. std
  231. mov si, offset eof
  232. mov cx, eof - offset Here
  233. mov di, tsrLen
  234. add di, cx
  235. inc cx
  236. rep movsb
  237. cld
  238. mov bx, tsrLen
  239. jmp bx

  240. Here:
  241. mov ax,cs
  242. mov es,ax
  243. mov di,offset endTSR
  244. mov cs:DataBegin, di
  245. mov cs:NextDataSeg, -1
  246. mov ax, 'XX'
  247. stosw
  248. in al, 0a1h
  249. mov ah, al
  250. in al, 21h
  251. push ax
  252. mov word ptr cs:old_8259, ax
  253. xor ax, ax
  254. out 21h,al ; CLI
  255. call SaveOthers
  256. call SetSelfInt
  257. call BackupVecList
  258. cmp cs:Power, true
  259. jnz @@20
  260. call BackupCVTchain
  261. call BackupMemoryManager
  262. @@20:
  263. call BackupBiosData

  264. sti
  265. mov cs:Flag, ' ' ; no busy
  266. mov cs:StopFlag, 0 ;

  267. mov cs:tsrLength, di
  268. call SetDosEnvSeg
  269. cmp cs:Self, 0
  270. jz @@29
  271. push cs
  272. pop ds
  273. push cs
  274. pop es
  275. cld
  276. mov cx, cs:tsrLength
  277. mov si, cs:DataBegin
  278. sub cx, si
  279. mov di, 120h
  280. mov cs:DataBegin, di
  281. rep movsb
  282. mov cs:tsrLength, di
  283. @@29:
  284. pop ax
  285. out 21h, al ; STI
  286. mov al, ah
  287. out 0a1h, al
  288. mov dx, cs:tsrLength
  289. inc dx
  290. int 27h

  291. ; ----------------------------------------------------------------------------
  292. SetDosEnvSeg:
  293. push ds
  294. push es
  295. mov ax, cs
  296. @@10: mov es, ax
  297. mov ax, es:[16h] ; Get father process psp segment
  298. or ax, ax
  299. jz @@11
  300. mov bx, es
  301. cmp ax, bx
  302. jnz @@10
  303. @@11:
  304. mov es, word ptr es:[2ch] ; Get father process env segment
  305. mov cs:DosEnv, es
  306. pop es
  307. pop ds
  308. ret

  309. ; ----------------------------------------------------------------------------

  310. SaveOthers:
  311. mov ax, cs:[2ch] ; Env Seg
  312. stosw
  313. call backupMCB ; Current MCB
  314. mov ax, 40h ; COM LPT Port
  315. mov ds, ax
  316. mov si, 0h
  317. mov cx, 8
  318. rep movsw

  319. mov si, 17h ; LED status
  320. lodsb
  321. stosb
  322. ; call OpenLEDs
  323. ret

  324. ; --------------------------------------------------------------------------
复制代码


路人甲 初中生2020-6-12 17:54:43
  1. uffer:
  2. push es
  3. push bx
  4. mov bx, 0040h
  5. mov es, bx
  6. cli
  7. mov bx, es:[1ah]
  8. mov es:[1ch], bx
  9. sti
  10. pop bx
  11. pop es
  12. ret


  13. Init8259:
  14. ; cmp cs:Copies, '1'
  15. ; jz @@1
  16. ; ret
  17. @@1:
  18. cmp cs:MachineID, 0fch
  19. ja @@pc_xt
  20. @@AT:
  21. mov bx,870h ;
  22. mov al,0 ;
  23. out 0F1h,al ;
  24. jcxz $+2
  25. jcxz $+2
  26. mov al,11h ; ICW1
  27. out 0A0h,al
  28. jcxz $+2
  29. jcxz $+2
  30. out 20h,al
  31. jcxz $+2
  32. jcxz $+2
  33. mov al,bl ; ICW2
  34. out 0A1h,al
  35. jcxz $+2
  36. jcxz $+2
  37. mov al,bh
  38. out 21h,al
  39. jcxz $+2
  40. jcxz $+2
  41. mov al,2 ; ICW3
  42. out 0A1h,al
  43. jcxz $+2
  44. jcxz $+2
  45. mov al,4
  46. out 21h,al
  47. jcxz $+2
  48. jcxz $+2
  49. mov al,1 ; ICW4
  50. out 0A1h,al
  51. jcxz $+2
  52. jcxz $+2
  53. out 21h,al
  54. jcxz $+2
  55. jcxz $+2
  56. mov al,0FFh ; OCW1
  57. out 0A1h,al
  58. jcxz $+2
  59. jcxz $+2
  60. out 21h,al
  61. ret
  62. @@PC_XT:
  63. mov al,13h ; ICW1
  64. out 20h,al
  65. jcxz $+2
  66. jcxz $+2
  67. mov al,8 ; ICW2
  68. out 21h,al
  69. jcxz $+2
  70. jcxz $+2
  71. mov al,9 ; ICW4
  72. out 21h,al
  73. jcxz $+2
  74. jcxz $+2
  75. mov al,0FFh ; OCW1
  76. out 21h,al
  77. ret

  78. Enable8259:
  79. mov ax, word ptr cs:old_8259
  80. out 021h,al
  81. jcxz $+2
  82. jcxz $+2
  83. mov al,ah
  84. out 0a1h,al ; DEC PC Bus Mouse
  85. ret ; July 1994 by Mr. Lei

  86. ; -------------------------------------------------------------------------

  87. RestoreBiosData:
  88. lodsw
  89. cmp ax, '--'
  90. jz @@1
  91. call Beep
  92. ret
  93. @@1: push es
  94. push di
  95. mov di, 40h
  96. mov es, di

  97. mov di, 10h
  98. movsw
  99. mov di, 0a8h ; [40h:a8h]
  100. movsw
  101. movsw
  102. mov di, 49h
  103. mov cx, 1dh
  104. rep movsb

  105. mov di, 0f0h ; User data
  106. mov cx, 8
  107. rep movsw

  108. pop di
  109. pop es
  110. ret

  111. ; -------------------------------------------------------------------------

  112. RestoreMCB:
  113. push ds
  114. push es
  115. lodsw ; 'MZ'
  116. @@0: lodsw
  117. cmp ax, 'MM'
  118. jz @@1
  119. mov es,ax
  120. xor di,di
  121. movsb
  122. movsw
  123. movsw
  124. inc ax
  125. mov bx, ds
  126. cmp ax, bx
  127. jz @@10
  128. mov byte ptr es:[8], 0 ; Aug 24, 1993
  129. @@10: cmp byte ptr es:[0], 'Z'
  130. jnz @@0
  131. mov byte ptr es:[10h], 0
  132. jmp @@0
  133. @@1:
  134. pop es
  135. pop ds
  136. ret

  137. ; -------------------------------------------------------------------------
  138. CloseFiles:
  139. mov ax, 5 ; Begin handle
  140. push ds
  141. push si
  142. mov cx, 15 ; Max handle
  143. sub cx, ax
  144. inc cx
  145. mov bx, ax
  146. @@1: push bx
  147. push cx
  148. mov ah, 3eh
  149. int 21h
  150. pop cx
  151. pop bx
  152. inc bx
  153. loop @@1
  154. pop si
  155. pop ds
  156. ret

  157. ; -------------------------------------------------------------------------
  158. RestorePort:
  159. mov di, 40h ; restore port
  160. mov es, di
  161. xor di, di
  162. mov cx, 8
  163. rep movsw
  164. ret

  165. ; -------------------------------------------------------------------------
  166. RestoreLEDs:
  167. lodsb
  168. and al, 11110000b ; LED status
  169. mov ah, es:[17h]
  170. and ah, 00001111b
  171. or ah, al
  172. and ah, 0f0h ; Clear CTRL ALT SHIFT
  173. mov es:[17h], ah
  174. ret

  175. ; -------------------------------------------------------------------------
  176. RestoreEnvStr:
  177. lodsw
  178. push si
  179. push di
  180. push ds
  181. push es
  182. mov es, cs:DosEnv
  183. mov ds, ax
  184. xor si, si
  185. mov di, si
  186. @@0: lodsb
  187. or al, al
  188. jnz @@1 cmp byte ptr ds:[si], 0
  189. jz @@2
  190. @@1: stosb
  191. jmp @@0
  192. @@2: stosb
  193. stosb
  194. pop es
  195. pop ds
  196. pop di
  197. pop si
  198. ret

  199. ; -----------------------------------------------------------------------
  200. RestoreVecList:
  201. xor ax,ax
  202. mov di,ax
  203. mov es,ax
  204. mov cx,100h
  205. @@0: lodsw
  206. xchg dx, ax
  207. lodsw
  208. cmp dx, 'EL'
  209. jnz @@1 cmp al, 'I'
  210. jnz @@1
  211. sub cl, ah
  212. push cx
  213. mov cl, ah
  214. mov ax, es:[di-4]
  215. mov dx, es:[di-2]
  216. @@a: stosw
  217. xchg ax, dx
  218. stosw
  219. xchg ax, dx
  220. loop @@a
  221. pop cx
  222. or cx, cx
  223. jz @@9
  224. jmp @@0
  225. @@1:
  226. xchg ax, dx
  227. stosw
  228. xchg ax, dx
  229. stosw
  230. loop @@0
  231. @@9:
  232. ret

  233. ;----------------------------------------------------------------------------
  234. RestoreFloppyParam: ; Mr. Lei 2/10/1992
  235. push es
  236. push ax
  237. xor ax, ax
  238. mov es, ax
  239. mov byte ptr es:[525h], 2
  240. pop ax
  241. pop es
  242. ret

  243. ;---------------------------------------------------------------------------
  244. RestoreCVTchain:
  245. lodsw
  246. cmp ax, 'VC'
  247. jz @@_0
  248. call Beep
  249. ret
  250. @@_0:
  251. push ax
  252. push cx
  253. push es

  254. ; -----------------------------------------------------------------
  255. lodsw ; DPB
  256. mov di, ax
  257. lodsw
  258. mov es, ax
  259. @@1: lodsb
  260. inc di
  261. stosb
  262. add di, cs:cvtOfs
  263. add di, 10h
  264. movsw
  265. movsw
  266. les di, es:[di+2]
  267. cmp di, -1
  268. jnz @@1

  269. ; -----------------------------------------------------------------
  270. lodsw ; DCB
  271. mov di, ax
  272. lodsw
  273. mov es, ax
  274. xor ax, ax
  275. dec ax
  276. stosw

  277. ; -----------------------------------------------------------------
  278. lodsw ; Device Driver Chain
  279. mov di, ax
  280. lodsw
  281. mov es, ax
  282. xor cx, cx
  283. @@9: push di
  284. mov cl, 5
  285. rep movsw
  286. pop di
  287. les di, es:[di]
  288. mov ax, di
  289. inc ax
  290. jnz @@9
  291. pop es
  292. pop cx
  293. pop ax
  294. ret

  295. ; ----------------------------------------------------------------------------
  296. RestoreMemoryManager:
  297. test cs:Status, XMSbit
  298. jz @@1
  299. call LoadXMSstatus
  300. @@1:
  301. test cs:Status, EMSbit
  302. jz @@2
  303. call LoadEMSstatus
  304. @@2:
  305. ret


  306. LoadEMSstatus:
  307. lodsw
  308. cmp ax, 'ME'
  309. jz @@_0
  310. call Beep
  311. ret
  312. @@_0:
  313. lodsw
  314. mov cx, ax
  315. xor dx, dx
  316. @@_1: push ds
  317. push si
  318. push dx
  319. push cx

  320. @@0: cmp dx, ds:[si]
  321. jz @@1
  322. add si, 4
  323. loop @@0

  324. push cx
  325. mov cx, 5
  326. @@0: mov ah, 45h ; Deallocate Handle and Memory
  327. int 67h
  328. or ah, ah
  329. jz @@1
  330. loop @@0
  331. @@1: pop cx

  332. @@1:
  333. pop cx
  334. pop dx
  335. pop si
  336. pop ds
  337. inc dx
  338. cmp dx, 100h
  339. jb @@_1
  340. shl cx, 1
  341. shl cx, 1
  342. add si, cx
  343. ret


  344. LoadXMSstatus:
  345. lodsw
  346. cmp ax, 'MX'
  347. jz @@_0
  348. call Beep
  349. ret
  350. @@_0:
  351. lodsw
  352. mov cx, ax
  353. jcxz @@5
  354. @@1:
  355. lodsw
  356. mov dx, ax
  357. @@2: push dx
  358. mov ah, 0ah ; free
  359. call dword ptr cs:xms_control
  360. or ax, ax
  361. pop dx
  362. jnz @@4 cmp bl, 0abh
  363. jnz @@4
  364. push dx
  365. mov ah, 0dh ; unlock
  366. call dword ptr cs:xms_control
  367. or ax, ax
  368. pop dx
  369. jmp @@2
  370. @@4: loop @@1
  371. @@5: ret
  372. endp

  373. ; -----------------------------------------------------------------------
  374. CloseSpeaker:
  375. in al, 61h
  376. and al, 0fch
  377. out 61h, al
  378. ret

  379. ; -----------------------------------------------------------------------
  380. RestoreClockSpeed:
  381. mov al, 00110110b
  382. out 43h, al
  383. xor ax, ax
  384. out 40h, al
  385. out 40h, al
  386. ret

  387. ; -----------------------------------------------------------------------
  388. ResetDisk:
  389. xor ax, ax
  390. xor dx, dx
  391. int 13h ; Restore A
  392. inc dx
  393. int 13h ; Restore B
  394. mov dl, 80h
  395. int 13h ; Restore C
  396. ret



  397. ; --------------------------------------------------------------------------
复制代码


路人甲 初中生2020-6-12 17:53:06
  1. Revision 2.12 [ July 12, 1994 ]
  2. Revision equ 'V2.12 '
  3. ;
  4. ;
  5. ;
  6. ;  RAMinit Release 2.0
  7. ;  Copyright (c) 1989-1994 by Yellow Rose Software Co.
  8. ;  Written by Mr. Leijun
  9. ;
  10. ;  Function:
  11. ;  Press HotKey to remove all TSR program after this program
  12. ;
  13. ;

  14. ; ..........................................................................
  15. ; Removed Softwares by RI:
  16. ; SPDOS v6.0F, WPS v3.0F
  17. ; Game Busters III, IV
  18. ; NETX ( Novell 3.11 )
  19. ; PC-CACHE
  20. ; Norton Cache
  21. ; Microsoft SmartDrv
  22. ; SideKick 1.56A
  23. ; MOUSE Driver
  24. ; Crazy (Monochrome simulate CGA program)
  25. ; RAMBIOS v2.0
  26. ; 386MAX Version 6.01
  27. ; ..........................................................................
  28. ; No cancel softwares:
  29. ; Windows 3.1 MSD
  30. ;
  31. ; No removed TSR softwares:
  32. ; MS-DOS fastopen
  33. ; Buffers, Files ... (QEMM 6.0)
  34. ; QCache (386MAX 6.01)
  35. ; ..........................................................................
  36. ;
  37. COMMENT

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



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

  56. Start: jmp Main
  57. org 103h

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

  61. INT3 macro
  62. out 0ffh,al
  63. endm
  64. ;
  65. ; HotKey Status Test Var
  66. ; --------------- ---------------
  67. ;
  68. ; 7 6 5 4 3 2 1 0 417 418 496
  69. ; . . x . x . . . Left Alt is pressed 8 2
  70. ; x . . . x . . . Right Alt is pressed 8 8
  71. ; . . . x . x . . Left Ctrl is pressed 4 1
  72. ; . x . . . x . . Right Ctrl is pressed 4 4
  73. ; . . . . . . x . Left Shift is pressed 2
  74. ; . . . . . . . x Right Shift is pressed 1
  75. ;
  76. LeftAlt equ 00101000b
  77. RightAlt equ 10001000b
  78. LeftCtrl equ 00010100b
  79. RightCtrl equ 01000100b
  80. LeftShift equ 00000010b
  81. RightShift equ 00000001b
  82. HotKey db LeftCtrl or RightCtrl

  83. DataBegin dw 0
  84. NextDataSeg dw 0ffffh
  85. oldInt2F_addr dw 0, 0
  86. XMS_control dw 0, 0
  87. Handle_begin dw 0
  88. cvtOfs dw 0 ; DOS 3.0 equ 0 and above DOS 4.0 is 1
  89. org 104h
  90. db 0dh
  91. db Revision
  92. db ??date
  93. db 26
  94. org 114h
  95. tsrLength dw 0
  96. MachineID db 0FCh ; IBM PC/AT

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

  110. Status dw 0
  111. XMSbit equ 00000001b
  112. EMSbit equ 00000010b
  113. SKbit equ 10000000b

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

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

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

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


  181. CallInt9:
  182. ret


  183. newINT9_2:
  184. mov cs:NoFlag, 1
  185. pushf
  186. db 9ah ; call far ptr oldint9_addr
  187. oldInt9_Addr2 dw 0, 0
  188. jmp newINT9_proc

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

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

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

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

  292. ; ---------------------------------------------------------------------------

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

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

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

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

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

  386. call ClosePRN
  387. mov bx,cs:WorkSeg
  388. mov ah,50h
  389. int 21h ; Set PSP segment
  390. mov ax,3 int 10h ; Set display mode

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

  409. Beep:
  410. mov ax,0e07h
  411. int 10h
  412. ret

  413. ; #########################################################################
复制代码


高级模式
B Color Image Link Quote Code Smilies
您需要登录后才可以发帖 登录 | 立即注册

Copyright © 2004-2023 广东中兴新支点技术有限公司 All Rights Reserved 粤ICP备15061780号-2  QQ客服
Powered by Discuz! © Comsenz Inc.
返回顶部