关于ZAKER 融媒体解决方案 合作 加入

雷军 1994 年写的老代码曝光,被称像诗一样优雅

雷军的代码像诗一样优雅

↓↓↓

有些网友在评论中质疑,说雷军代码不会是「屎」一样优雅吧。说这话的网友,也许是开玩笑的,也许是真没看过雷军写过的代码。

在2011年的时候,我们在微博转过雷军在1994年写的一段完整的汇编代码。雷军这段汇编代码,有程序员评价「如今能写出这么高质量的代码的程序员恐怕也不多」

后来雷军在转发我们微博时还补充说:「这个程序第一个版本是我1989年写的,怀念当初写程序的快乐时光。」

之前微博帖子中引用的链接已挂,今天重新在网上找到了完整版,如下:

(在移动端窄屏看大篇幅代码,可能体验不如PC端。大家可以试试点击右上角的「……」,然后「复制链接」,方便的时候,在PC端看看。)

前方高能……

;; RI.ASM Revision 2.12 [ July 12, 1994 ]Revision equ 'V2.12 ';;;; RAMinit Release 2.0 ; Copyright (c) 1989-1994 by Yellow Rose Software Co.; Written by Mr. Leijun;; Function:; Press HotKey to remove all TSR program after this program;;; ..........................................................................; Removed Softwares by RI:; SPDOS v6.0F, WPS v3.0F; Game Busters III, IV; NETX ( Novell 3.11 ); PC-CACHE; Norton Cache; Microsoft SmartDrv; SideKick 1.56A; MOUSE Driver; Crazy (Monochrome simulate CGA program); RAMBIOS v2.0; 386MAX Version 6.01; ..........................................................................; No cancel softwares:; Windows 3.1 MSD;; No removed TSR softwares:; MS-DOS fastopen; Buffers, Files ... (QEMM 6.0); QCache (386MAX 6.01); ..........................................................................;COMMENTV2.04 Use mouse driver software reset function to initiation mouse2/17/1993 by Mr. Lei and Mr. FengV2.05 RI cannot work in Windows DOS prompt3/9/1993 by Mr. LeiV2.06 1. When XMS cannot allocate 1K memory, RI halts.2. RI repeat deallocates EMS memory.V2.07 HotKey Setup Error4/25/1993 by Mr. LeiV2.08 KB BufferV2.10 1. Release high memory blocks (EMM386 QEMM386 S-ICE 386MAX)2. RI copies flagV2.12 1. Exists a critical error in Init 8259 procedure2. Save [40:F0--FF] user data areadosseg.model tiny.codelocals @@org 100hStart: jmp Mainorg 103hTrue equ 1False equ 0MaxHandles equ 100hINT3 macroout 0ffh,alendm;; HotKey Status Test Var; --------------- ---------------;; 7 6 5 4 3 2 1 0 417 418 496; . . x . x . . . Left Alt is pressed 8 2; x . . . x . . . Right Alt is pressed 8 8; . . . x . x . . Left Ctrl is pressed 4 1; . x . . . x . . Right Ctrl is pressed 4 4; . . . . . . x . Left Shift is pressed 2; . . . . . . . x Right Shift is pressed 1;LeftAlt equ 00101000bRightAlt equ 10001000bLeftCtrl equ 00010100bRightCtrl equ 01000100bLeftShift equ 00000010bRightShift equ 00000001bHotKey db LeftCtrl or RightCtrlDataBegin dw 0NextDataSeg dw 0ffffholdInt2F_addr dw 0, 0XMS_control dw 0, 0Handle_begin dw 0cvtOfs dw 0 ; DOS 3.0 equ 0 and above DOS 4.0 is 1org 104hdb 0dhdb Revisiondb ??datedb 26org 114htsrLength dw 0MachineID db 0FCh ; IBM PC/ATAuxHotKey db 0 ; 2Dh ; 'X' Scan CodeAuxHotKeyName db 'X$ 'Power db TrueFlag db '!'Kbd102 db 0NoFlag db 0StopFlag db 1DosEnv dw 0WorkSeg dw 0PrevDataSeg dw 0Copies db '1'old_8259 db 0 ; 21h portdb 0 ; a1h portStatus dw 0XMSbit equ 00000001bEMSbit equ 00000010bSKbit equ 10000000bGoINT1C: db 0eaholdInt1C_addr dw 0, 0newINT1C:test cs:Status, SKbitjnz GoINT1Ccmp cs:StopFlag, 0jz @@0;; Mr. Lei 2/8/1993; Problem: if WPS quit and reenter, old RI cann't control keyboard. ;push dspush axxor ax, axmov ds, axmov ax, ds:[94]cmp ax, offset NewInt9pop axpop dsjnz GoINT1Cmov cs:StopFlag, [email protected]@0: push axpush dspush esxor ax, axmov ds, axmov es, ds:[94+2]cmp word ptr es:[101h], 'IE' ; 'LEI'jz @@1climov cs:StopFlag, 1mov ax, ds:[94]mov cs:oldINT9_addr2, axmov ax, ds:[94+2]mov cs:oldINT9_addr2[2], axmov ds:[94], offset newINT9_2mov ds:[94+2], [email protected]@1: pop espop dspop axjmp GoINT1C; ----------------------------------------------------------------------; INT2F Func;; AX = C0D7h Return RI segment in AX; AX = C0D8h Removes all TSR programs after RI; AX = C0D9h Removes all TSR programs include RI; AX = C0DAh Removes all RI copies; ----------------------------------------------------------------------newINT2F:cmp ax, 0c0d7h ; LEI Hanzi GB Codejnz @@1push cspop [email protected]@1: cmp ax, 0c0d7h+1jnz @@2jmp [email protected]@2: cmp ax, 0c0d7h+2jnz @@3jmp [email protected]@3: cmp ax, 0c0d7h+3jnz @@9mov cs:NextDataSeg, -1mov cs:Copies, '1'jmp [email protected]@9: jmp dword ptr cs:oldInt2F_addrCallInt9:retnewINT9_2:mov cs:NoFlag, 1pushfdb 9ah ; call far ptr oldint9_addroldInt9_Addr2 dw 0, 0jmp newINT9_procnewINT9:pushfdb 9ah ; call far ptr oldint9_addroldInt9_Addr dw 0, 0 cmp cs:NoFlag, 0jz newINT9_procmov cs:NoFlag, 0iretnewINT9_proc:cmp cs:Flag, '!' ; busy ?jnz @@[email protected]@0:mov cs:Flag, '!' ; set busy flagpush ax ; cmp hot keypush bxpush esmov ax,40hmov es,axcmp cs:AuxHotKey, 0jz @@_1mov bx, es:[1ah]cmp bx, es:[1ch]jz @@10push bxmov bl, es:[bx+1]cmp bl, cs:AuxHotKeypop bxjnz @@[email protected]@_1:mov ah,es:[17h] ; test CTRL SHIFT ALTmov al,cs:HotKeypush axand ax,0f0fhcmp al,ahpop axjnz @@10 cmp cs:Kbd102, Truejnz @@1shr al, 1shr al, 1shr al, 1shr al, 1push axmov ah, es:[18h]and ax, 303hcmp al, ahpop axjnz @@10mov ah, es:[96h]shr ax, 1shr ax, 1and ax, 303hcmp al, ahjnz @@10 cmp cs:AuxHotKey, 0jz @@_3inc bxinc bxcmp bx, 3ehjb @@_2mov bx, [email protected]@_2:mov es:[1ah], [email protected]@_3:call IsWinDosor ax, axjz @@1call [email protected]@10:stipop espop bxpop axmov cs:Flag, ' ' ; no [email protected]@1: ; OKpop espop bxpop axKeepSelf:call RemoveTSRpush esmov es,cs:WorkSegmov dx,es:tsrLengthmov di,dxmov al,0h ; Aug 24, 1993mov cx,100hrep stosbpop esint 27hNoKeepSelf:mov ax,0e07hint 10hmov cs:clsStr, 47h ; Color (White in Red)call RemoveTSRdec cs:Copiescall RestoreSelfIntVecpush escmp cs:PrevDataSeg, 0jz @@1mov es, cs:PrevDataSegmov es:NextDataSeg, [email protected]@1: pop esmov ax, 4c00hint 21h; ---------------------------------------------------------------------------IsWinDOS:mov ax, 1600hint 2fhcmp al, 01hjz @@9 cmp al, 0ffhjz @@9 ; Windows/386 Version 2.Xcmp al, 00hjz @@1 cmp al, 80hjnz @@9 ; Windows 3 in enhanced mode; Version number in AL/[email protected]@1:mov ax, 4680hint 2fhcmp al, 80hjnz @@9xor ax, axjmp @@[email protected]@9: mov ax, [email protected]@10: ret; -----------------------------------------------------------------------RestoreSelfIntVec:cmp Copies, '0'jz @@[email protected]@0:clipush cspop dsxor ax, axmov es, axmov si, offset oldInt9_Addrmov di, 94movswmovswmov si, offset oldInt2F_Addrmov di, 2Fh4movswmovswmov si, offset oldInt1C_Addrmov di, 1Ch4movswmovswstiret; ------------- KERNEL PROGRAM ----------------------------------------------RemoveTSR:pop axcli ; Set stackmov sp, csmov ss, spmov sp, 100hstipush axcmp cs:Power, Truejnz @@1call [email protected]@1:push cspop [email protected]@_0:mov ax,ds:NextDataSegcmp ax, -1jz @@_1mov cs:PrevDataSeg, dsmov ds, axjmp @@[email protected]@_1: mov si,ds:DataBeginmov cs:WorkSeg, dslodswcmp ax, 'XX'jz @@_2call [email protected]@_2:call RestoreEnvStrcall RestoreMCB ; restore current mcbcall CloseFilescall RestorePortcall RestoreLEDscall RestoreVecList ; Restore vectors listcall RestoreFloppyParamcmp cs:Power, Truejnz @@2call RestoreCVTchain ; Restore cvt chaincall [email protected]@2:call RestoreBiosDatacall Enable8259mov ah, 1 int 16hcall RestoreClockSpeedcall CloseSpeakercall ResetDiskcall UpdateTimecall ClosePRNmov bx,cs:WorkSegmov ah,50hint 21h ; Set PSP segmentmov ax,3 int 10h ; Set display modecall InitPRNcall InitMousemov al, cs:Copiescmp al, '1'ja @@_sh1mov cs:ShowCopies, ''jmp @@[email protected]@_sh1: mov cs:ShowCopies, [email protected]@_sh2:mov si, offset clsStrcall ColorPrintStrmov cs:Flag, ' ' ; no busycmp Copies, '1'jnz @@_endmov cs:StopFlag, [email protected]@_end:call ClearKB_bufferretBeep:mov ax,0e07hint 10hret; #########################################################################ClearKB_Buffer:push espush bxmov bx, 0040hmov es, bxclimov bx, es:[1ah]mov es:[1ch], bxstipop bxpop esretInit8259:; cmp cs:Copies, '1'; jz @@1; [email protected]@1:cmp cs:MachineID, 0fchja @@[email protected]@AT:mov bx,870h ;mov al,0 ;out 0F1h,al ;jcxz $+2jcxz $+2mov al,11h ; ICW1out 0A0h,aljcxz $+2jcxz $+2out 20h,aljcxz $+2jcxz $+2mov al,bl ; ICW2out 0A1h,aljcxz $+2jcxz $+2mov al,bhout 21h,aljcxz $+2jcxz $+2mov al,2 ; ICW3out 0A1h,aljcxz $+2jcxz $+2mov al,4out 21h,aljcxz $+2jcxz $+2mov al,1 ; ICW4out 0A1h,aljcxz $+2jcxz $+2out 21h,aljcxz $+2jcxz $+2mov al,0FFh ; OCW1out 0A1h,aljcxz $+2jcxz $+2out 21h,[email protected]@PC_XT:mov al,13h ; ICW1out 20h,aljcxz $+2jcxz $+2mov al,8 ; ICW2out 21h,aljcxz $+2jcxz $+2mov al,9 ; ICW4out 21h,aljcxz $+2jcxz $+2mov al,0FFh ; OCW1out 21h,alretEnable8259:mov ax, word ptr cs:old_8259out 021h,aljcxz $+2jcxz $+2mov al,ahout 0a1h,al ; DEC PC Bus Mouseret ; July 1994 by Mr. Lei; -------------------------------------------------------------------------RestoreBiosData:lodswcmp ax, '--'jz @@1call [email protected]@1: push espush dimov di, 40hmov es, dimov di, 10hmovswmov di, 0a8h ; [40h:a8h]movswmovswmov di, 49hmov cx, 1dhrep movsbmov di, 0f0h ; User datamov cx, 8rep movswpop dipop esret; -------------------------------------------------------------------------RestoreMCB:push dspush eslodsw ; 'MZ'@@0: lodswcmp ax, 'MM'jz @@1mov es,axxor di,dimovsbmovswmovswinc axmov bx, dscmp ax, bxjz @@10mov byte ptr es:[8], 0 ; Aug 24, [email protected]@10: cmp byte ptr es:[0], 'Z'jnz @@0mov byte ptr es:[10h], 0jmp @@[email protected]@1:pop espop dsret; -------------------------------------------------------------------------CloseFiles:mov ax, 5 ; Begin handlepush dspush simov cx, 15 ; Max handlesub cx, axinc cxmov bx, [email protected]@1: push bxpush cxmov ah, 3ehint 21hpop cxpop bxinc bxloop @@1pop sipop dsret; -------------------------------------------------------------------------RestorePort:mov di, 40h ; restore portmov es, dixor di, dimov cx, 8rep movswret; -------------------------------------------------------------------------RestoreLEDs:lodsband al, 11110000b ; LED statusmov ah, es:[17h]and ah, 00001111bor ah, aland ah, 0f0h ; Clear CTRL ALT SHIFTmov es:[17h], ahret; -------------------------------------------------------------------------RestoreEnvStr:lodswpush sipush dipush dspush esmov es, cs:DosEnvmov ds, axxor si, simov di, [email protected]@0: lodsbor al, aljnz @@1 cmp byte ptr ds:[si], 0jz @@[email protected]@1: stosbjmp @@[email protected]@2: stosbstosbpop espop dspop dipop siret; -----------------------------------------------------------------------RestoreVecList:xor ax,axmov di,axmov es,axmov cx,[email protected]@0: lodswxchg dx, axlodswcmp dx, 'EL'jnz @@1 cmp al, 'I'jnz @@1sub cl, ahpush cxmov cl, ahmov ax, es:[di-4]mov dx, es:[di-2]@@a: stoswxchg ax, dxstoswxchg ax, dxloop @@apop cxor cx, cxjz @@9jmp @@[email protected]@1:xchg ax, dxstoswxchg ax, dxstoswloop @@[email protected]@9:ret;----------------------------------------------------------------------------RestoreFloppyParam: ; Mr. Lei 2/10/1992push espush axxor ax, axmov es, axmov byte ptr es:[525h], 2pop axpop esret;---------------------------------------------------------------------------RestoreCVTchain:lodswcmp ax, 'VC'jz @@_0call [email protected]@_0:push axpush cxpush es; -----------------------------------------------------------------lodsw ; DPBmov di, axlodswmov es, [email protected]@1: lodsbinc distosbadd di, cs:cvtOfsadd di, 10hmovswmovswles di, es:[di+2]cmp di, -1jnz @@1; -----------------------------------------------------------------lodsw ; DCBmov di, axlodswmov es, axxor ax, axdec axstosw; -----------------------------------------------------------------lodsw ; Device Driver Chainmov di, axlodswmov es, axxor cx, [email protected]@9: push dimov cl, 5rep movswpop diles di, es:[di]mov ax, diinc axjnz @@9pop espop cxpop axret; ----------------------------------------------------------------------------RestoreMemoryManager:test cs:Status, XMSbitjz @@1call [email protected]@1:test cs:Status, EMSbitjz @@2call [email protected]@2:retLoadEMSstatus:lodswcmp ax, 'ME'jz @@_0call [email protected]@_0:lodswmov cx, axxor dx, [email protected]@_1: push dspush sipush dxpush [email protected]@0: cmp dx, ds:[si]jz @@1add si, 4loop @@0push cxmov cx, [email protected]@0: mov ah, 45h ; Deallocate Handle and Memoryint 67hor ah, ahjz @@1loop @@[email protected]@1: pop [email protected]@1:pop cxpop dxpop sipop dsinc dxcmp dx, 100hjb @@_1shl cx, 1shl cx, 1add si, cxretLoadXMSstatus:lodswcmp ax, 'MX'jz @@_0call [email protected]@_0:lodswmov cx, axjcxz @@[email protected]@1:lodswmov dx, [email protected]@2: push dxmov ah, 0ah ; freecall dword ptr cs:xms_controlor ax, axpop dxjnz @@4 cmp bl, 0abhjnz @@4push dxmov ah, 0dh ; unlockcall dword ptr cs:xms_controlor ax, axpop dxjmp @@[email protected]@4: loop @@[email protected]@5: retendp; -----------------------------------------------------------------------CloseSpeaker:in al, 61hand al, 0fchout 61h, alret; -----------------------------------------------------------------------RestoreClockSpeed:mov al, 00110110bout 43h, alxor ax, axout 40h, alout 40h, alret; -----------------------------------------------------------------------ResetDisk:xor ax, axxor dx, dxint 13h ; Restore Ainc dxint 13h ; Restore Bmov dl, 80hint 13h ; Restore Cret; --------------------------------------------------------------------------ClosePRN:mov ah, 51h ; Get PSP segint 21hmov es, bxmov ax, es:[16h] ; Prev PSP segcmp ax, bxjnz @@9mov ax, 3e00h ; COMMANDmov bx, 4 int [email protected]@9:retInitPRN:mov ax, 3e00hmov bx, 4 ; PRNint 21hmov ax, 3d01hmov dx, offset PRNnamepush cspop dsint 21hretPRNname db 'PRN',0InitMouse: ; 2/16/1993 by Mr. Leipush esxor ax, axmov es, axcmp word ptr es:[33h4+2], 0jz @@0 cmp word ptr es:[33h4], 0jz @@0mov ax, 21hint 33h ; Hook Mouse [email protected]@0: pop esret; ------------- CMOS CLOCK set to System -----------------------------------UpdateTime:call GetRealTimemov ah, 2dhint 21hretGetRealTime:mov ah,2 int 1Ahmov al,chcall bcdxchgmov ch,almov al,clcall bcdxchgmov cl,almov al,dhcall bcdxchgmov dh,almov dl,0retBCDxchg:push axpush cxmov cl,4shr al,clpop cxmov bl,0Ahmul blpop bxand bl,0Fhadd al,blret; -----------------------------------------------------------------------; Display stringColorPrintStr:lodsbmov bh, al ; colorxor cx, cxmov dx, 014fhmov ax, 0600hint 10hmov ah, 02 ; GotoXY (0, 0)xor dx, dxmov bh, 0 int 10hPrintStr:push cspop dsxor bx, [email protected]@1: lodsbcmp al, '$'jz @@2or al, aljz @@2mov ah, 0ehint 10hjmp short @@[email protected]@2: mov al, cs:clsStrcolormov cs:clsStr, alret; -----------------------------------------------------------------------Self dw 0clsStrcolor db 17hclsStr db 17h ; Color (White in Blue)db ' RAMinit Version 2.12 (c) 1989-1994 by KingSoft Ltd. Mr. Leijun'db 0dh,0ahdb ' ['ShowCopies db ''db '] Activate...',0ah,0dh,'$'endTSR equ $mcbList equ offset endTSR + 2 + 2vecList equ mcbList + 710 + 2 + 10h + 1 + 400hdevLink equ vecList + 4 + 5 26 + 4 + 10 30h + 4xmsList equ devLink + 2 + MaxHandles 2emsList equ xmsList + 4 + 1024crtMode equ emsList + 2 + 1Dh + 4 + 10htsrLen equ crtMode + 1;; DOS Environment Reserved by RI; --------------------------------------------------; Flag 'XX' 2 bytes; Environment Segment 1 word; Free MCBs <=710 bytes; MCB segment 1 word; MCB 5 bytes; End flag 'MM' 1 word; COM LPT ports 10h bytes; LEDs status 1 bytes; Packed vectors list <=400h bytes; Flag 'CV' 2 bytes; CVT First DPB pointer 4 bytes; DPBs data <=526 bytes; First DCB pointer 4 bytes; Pointer to NUL 4 bytes; All device driver datas <=30h10 bytes; Flag 'XM' 2 bytes; XMS free handle counter 2 bytes; EMS free handle list <=100h4 bytes; Flag 'EM' 2 bytes; EMS free handle counter 2 bytes; EMS free handle list <=1024 bytes; EMS handle 1 word; Number of pages 1 word; Flag '--' 1 word; Equipment List 1 word; CRT 40:49h-66h 1dh bytes; 40:A8h 1 dword; BIOS User Data Area 40:F0--FF 10h bytes; **;main: jmp main0Print Macro StrLea dx, Strcall DisplayStrendmInstMsg db 'RAMinit Version 2.12 'db 'Copyright (c) 1989-1994 by KingSoft Ltd. ',0dh,0ah,'$'Msg0 db 'Already installed !',0dh,0ah,0ahdb 'For Help, type "RI /?". ',0dh,0ah,'$'Msg_0 db 0ah,'Residents a new RAMinit copy [y/n] ? $'Msg_2 db 'OK, RI No.'Msg_RI db '2'db ' residents successful !', 0dh,0ah,'$'Msg1 db 'Activate with: $'KeyMsg db 'Right_Shift$'db 'Left_Shift$ 'KMsg1 db 'Left_Ctrl$ 'db 'Left_Alt$ 'db 'Right_Ctrl$ 'db 'Right_Alt$ 'KMsg2 db 'Ctrl$ 'db 'Alt$ 'db 'Ctrl$ 'db 'Alt$ 'PlusMsg db ' + $'crlf db 0dh,0ah,'$'HelpMsg db 'Programmed by Mr. Leijun Dec 1992', 0dh,0ah,0ahdb 'Usage: RI [options]',0dh,0ah,0ahdb '/H,/? Display this screen',0dh,0ahdb '/CLS Removes all TSR programs after current RI',0dh,0ahdb '/RET Removes TSR programs include current RI',0dh,0ahdb '/NEW Residents a new data copy of current environment',0dh,0ahdb '/ALL Removes all RI copies and all other tsr programs',0dh,0ahdb '/Sxyy.. Define Hotkey x=AuxHotkey yy..=shift status',0dh,0ahdb ' x=auxiliary hotkey (default is "X") ',0dh,0ahdb ' x equ "1" means need AuxHotkey',0dh,0ahdb ' yy..=shift status [CAScas]',0dh,0ahdb ' C: Left Ctrl A: Left Alt S: Left Shift',0dh,0ahdb ' c: Right Ctrl a: Right Alt s: Right Shift',0dh,0ah,0ahdb 'Example: "RI /S1c" means Hotkey is Right_Ctrl+X',0dh,0ahdb ' "RI /S0Cc" means HotKey is Left_Ctrl+Right_Ctrl',0dh,0ahdb ' "RI /CLS" equals simply press hotkey',0dh,0ahdb ' "RI /RET" Removes all TSRs after current RI and this RI',0dh,0ahdb 0ahdb 'Contact me for RAMinit problems: (01)2561155 Call 1997',0dh,0ahdb '$'ErrMsg db 'ERROR: Invalid options !',0dh,0ah,0ah,'$'WinErr db 7, 'Sorry, I cannot work in Windows DOS environment.',0dh,0ah,'$'SetMsg db 7, 'Defines new Hotkey successful !',0dh,0ah,0ah,'$'tsrOK db FalseMain0:cldPrint instMsgcall IsWinDosor ax, axjz @@1Print WinErrmov ax, 4c00hint [email protected]@1:call HotKeyValidmov cs:Status, 0call EMS_testcall CmpDosVercall CmpSideKickcall GetMachineIDcall ModifyHotKeyPromptmov ax, 0c0d7hint 2fhmov es, axcmp word ptr es:[101h], 'IE' ; 'LEI'jnz @@0mov cs:Self, [email protected]@0:call CmdLinecall PrintHotKeyPromptcmp cs:tsrOK, truejz @@2call [email protected]@2: cmp cs:tsrOK, truejnz @@_2call [email protected]@_2:mov word ptr cs:[100h], 'EL'mov byte ptr cs:[102h], 'I'push cspop espush cspop dsstdmov si, offset eofmov cx, eof - offset Heremov di, tsrLenadd di, cxinc cxrep movsbcldmov bx, tsrLenjmp bxHere:mov ax,csmov es,axmov di,offset endTSRmov cs:DataBegin, dimov cs:NextDataSeg, -1mov ax, 'XX'stoswin al, 0a1hmov ah, alin al, 21hpush axmov word ptr cs:old_8259, axxor ax, axout 21h,al ; CLIcall SaveOtherscall SetSelfIntcall BackupVecListcmp cs:Power, truejnz @@20call BackupCVTchaincall [email protected]@20:call BackupBiosDatastimov cs:Flag, ' ' ; no busymov cs:StopFlag, 0 ;mov cs:tsrLength, dicall SetDosEnvSegcmp cs:Self, 0jz @@29push cspop dspush cspop escldmov cx, cs:tsrLengthmov si, cs:DataBeginsub cx, simov di, 120hmov cs:DataBegin, direp movsbmov cs:tsrLength, [email protected]@29:pop axout 21h, al ; STImov al, ahout 0a1h, almov dx, cs:tsrLengthinc dxint 27h; ----------------------------------------------------------------------------SetDosEnvSeg:push dspush esmov ax, [email protected]@10: mov es, axmov ax, es:[16h] ; Get father process psp segmentor ax, axjz @@11mov bx, escmp ax, bxjnz @@[email protected]@11:mov es, word ptr es:[2ch] ; Get father process env segmentmov cs:DosEnv, espop espop dsret; ----------------------------------------------------------------------------SaveOthers:mov ax, cs:[2ch] ; Env Segstoswcall backupMCB ; Current MCBmov ax, 40h ; COM LPT Portmov ds, axmov si, 0hmov cx, 8rep movswmov si, 17h ; LED statuslodsbstosb; call OpenLEDsret; --------------------------------------------------------------------------backupMCB:mov ax, 'ZM'stoswpush dspush esmov ah, 52hint 21h ; Get MCB chain headmov ax, es:[bx-2]pop [email protected]@0: mov ds, axcmp byte ptr ds:[0], 'Z' ; End ?jz @@20 cmp byte ptr ds:[0], 'M' ; Memory control blockjnz @@30 cmp word ptr ds:[3], 0 ; Nul mcbjz @@10 cmp word ptr ds:[1], 0 ; Free MCBjnz @@10call [email protected]@10: inc axadd ax, ds:[3]jmp @@[email protected]@20:call SaveFreeMCBcmp ax, 0a000hinc axjnb @@30mov ax, 9fffh ; MS-DOS UMBjmp @@[email protected]@30:cmp ax, 0c000h ; 386MAXja @@90mov ax, 0c020hjmp @@[email protected]@90: ; Error ?pop dsmov ax, 'MM' ; Set MCB flagstoswretSaveFreeMCB:stoswxor si,simovsbmovswmovswret;; push ax; stosw; xor si,si; movsb; movsw; movsw; pop ax; cmp ax, 09fffh; jnb @@3; push ax; push ds; mov ds,ax; cmp byte ptr ds:[0], 'M'; pop ds; pop ax; jnz @@4; mov ax, 09fffh ; MS-DOS UMB; jmp @@0; @@4: cmp ax, 0c000h; ja @@3; mov ax, 0c020h ; 386MAX; jmp @@0;; --------------------------------------------------------------------------OpenLEDs: push ax ; Open all LEDsor al, 070hmov ds:[17h], almov ah, 1 int 16hmov cx, 4 ; [email protected]@20: push cxxor cx, [email protected]@21: loop @@21pop cxloop @@20pop axmov ds:[17h], almov ah, 1 int 16hret; --------------------------------------------------------------------------SetSelfInt:push espush dicmp cs:self, 0jnz @@1push cspop dsmov ax,3509hint 21hmov word ptr cs:oldInt9_addr,bxmov word ptr cs:oldInt9_addr[2],esmov dx,offset NewInt9mov ax,2509hint 21hmov ax,352Fhint 21hmov word ptr cs:oldInt2F_addr,bxmov word ptr cs:oldInt2F_addr[2],esmov dx,offset newInt2Fmov ax,252Fhint 21hmov ax,351Chint 21hmov word ptr cs:oldInt1C_addr,bxmov word ptr cs:oldInt1C_addr[2],esmov dx,offset newInt1Cmov ax,251chint 21hclijmp @@[email protected]@1:mov es, cs:Selfinc es:[email protected]@_0: cmp es:NextDataSeg, -1jz @@_1mov es, es:NextDataSegjmp @@[email protected]@_1: mov es:NextDataSeg, [email protected]@2:pop dipop esret; -----------------------------------------------------------------------SaveCounter:mov word ptr es:[di], 'EL'mov byte ptr es:[di+2], 'I'mov byte ptr es:[di+3], blxor bx, bxadd di, 4ret; -----------------------------------------------------------------------DisplayStr: push cspop dsmov ah, 9 int 21hret; -----------------------------------------------------------------------CmdLine:push cspop dsxor ax, axmov si, 80hlodsbor al, aljnz @@[email protected]@1:mov cx, axdec axpush axpush [email protected]@0: lodsbcmp al, ' 'jz @@0 cmp al, '/'jnz @@2lodsbcmp al, 'S'jz @@_2cmp al, 's'jnz @@[email protected]@_2:call SetHotKeyPrint SetMsgmov ax, 4c00hint [email protected]@2:pop sipop axpush axpush [email protected]@_3: lodsbcmp al, 'A'jb @@3 cmp al, 'Z'ja @@3add byte ptr ds:[si-1],20h ; [email protected]@3: loop @@_3pop sipop cxadd si, cxlodsbcmp al, 's' ; CLSjnz @@5 cmp word ptr ds:[si-3], 'lc'jnz @@5 cmp cs:Self, 0jz @Errmov ax, 0c0d7h+1 int [email protected]@5: cmp al, 'h' ; HELPjz @helpcmp al, '?'jz @helpcmp al, 't' ; RETjnz @@6 cmp word ptr ds:[si-3], 'er'jnz @@[email protected]@7:cmp cs:Self, 0jz @Errmov ax, 0c0d7h+2 int [email protected]@6: cmp al, 'w' ; NEWjnz @@8 cmp word ptr ds:[si-3], 'en'jnz @@8mov cs:tsrOK, [email protected]@8:cmp al, 'l' ; ALLjnz @@9 cmp word ptr ds:[si-3], 'la'jnz @@9mov ax, 0c0d7h+3 int [email protected]@9:cmp al, ' 'jnz @[email protected]:Print [email protected]:Print HelpMsgmov ax, 4c00hint 21h;---------------------------------------------------------------------------tsrReplyOK:cmp cs:Self, 0jz @@1Print Msg0push esmov ax, cs:[email protected]@_10: mov es, axmov ax, es:NextDataSegcmp ax, -1jnz @@_10mov ax, [email protected]@_0: push axdec axmov es, axmov bx, es:[3]pop axadd ax, bxinc axmov es, axcmp word ptr es:[0], 'OC'jz @@_0mov bx, cscmp ax, bxpop esjz @@2Print Msg_0mov ah, 1 int 21hpush axPrint crlfpop axcmp al, 'y'jz @@3 cmp al, 'Y'jz @@[email protected]@2: ; Print Msg_1mov ax, 4c01hint [email protected]@3:@@1: mov cs:tsrOK, trueretPrintCopies:cmp cs:Self, 0jz @@1push es ; Added -by- Mr. Leimov es, cs:Self ; Aug 24, 1993mov al, es:Copiesinc al ; Total RI copiespush ax ; Set es = current mcbmov ax, csdec axmov es, axpop axmov cx, 5 ; Search end of file namemov bx, [email protected]@10: inc bxcmp byte ptr es:[bx], 20hjz @@20 cmp byte ptr es:[bx], 0ffhjz @@20 cmp byte ptr es:[bx], 00hjz @@20loop @@[email protected]@20: ; Set current RI nomov byte ptr es:[bx], ':' ; "RI:2"mov byte ptr es:[bx+1], alcmp bx, 8+7jnb @@30mov byte ptr es:[bx+2], [email protected]@30:pop esmov cs:Msg_RI, alPrint [email protected]@1: ret;---------------------------------------------------------------------------; Backup Interrupt Vector List;BackupVecList:push dspush cspop esxor si,si ; Vectorsmov ds,simovswmovswxor bx, bxmov cx,[email protected]@0: lodswxchg dx, axlodswcmp ax, es:[di-2]jnz @@1 cmp dx, es:[di-4]jz @@[email protected]@1: or bx, bxjz @@3call [email protected]@3: xchg dx, axstoswxchg dx, axstoswloop @@0jmp @@[email protected]@2: inc bxloop @@0call [email protected]@4:pop dsret;;-----------------------------------------------------------------------------BackupCVTchain:mov ax, 'VC'stoswpush axpush bxpush cxpush dspush esmov ah, 52hint 21h ; ES:BX -- DOS table as described below; --------------------------------------------------------------------push es ; DPB chainspush bxlds si, es:[bx]push cspop esmov ax, sistoswmov ax, dsstoswmov bx, cs:cvtOfsxor cx, [email protected]@1: mov al, ds:[si+1]stosbmov ax, ds:[si+bx+12h]stoswmov ax, ds:[si+bx+14h]stoswinc cxlds si, ds:[si+bx+18h]cmp si, -1jnz @@1; mov ax, 5; mul cl; add ax, 4; add cs:tsrLength, axpop bxpop es; --------------------------------------------------------------------push es ; DCB file control blockspush bxles bx, es:[bx+4]@@11: cmp word ptr es:[bx], -1jz @@10les bx, es:[bx]jmp @@[email protected]@10:mov ax, esxchg ax, bxpush cspop esstoswxchg ax, bxstoswpop bxpop es; add cs:tsrLength, 4; ---------------------------------------------------------------------push es ; Device Driver Chainspop dsadd bx, 22hmov si, bx ; NULpop esmov ax, sistoswmov ax, dsstoswxor cx, cxxor bx, [email protected]@9: push simov cl, 5rep movswinc bxpop silds si, ds:[si]mov ax, siinc axjnz @@9pop dspop cxpop bxpop axret; ----------------------------------------------------------------------------BackupBiosData:mov ax, '--'stoswpush dspush simov si, 40hmov ds, simov si, 10hmovswmov si, 0a8hmovswmovswmov si, 49hmov cx, 1dhrep movsbmov si, 0f0hmov cx, 8rep movswpop sipop dsret; ---------------------------------------------------------------------------BackupMemoryManager:push cspop espush dspush escall SaveXMSstatuscall SaveEMSstatuspop espop dsret;---------------------------------------------------------------------SaveEMSstatus:test cs:status, EMSbitjnz @@[email protected]@1:mov ax, 'ME'stoswinc diinc dipush dimov ah, 4dhint 67hpop dimov es:[di-2], bxshl bx, 1shl bx, 1add di, bxret; -------------------------------------------------------------------SaveXMSstatus:call XMS_testtest cs:status, XMSbitjnz @@[email protected]@1:mov ax, 'MX'stoswmov dx, 1call XMS_allocjnz @@_1xor cx, cx ; XMS alloc [email protected]@_1:push dxsub dx, MaxHandles [email protected]@2:push dxcall XMS_Lockpop dxjnz @@3 cmp bl, 0a2hjnz @@4add dx, 10jmp @@[email protected]@3: push dxcall XMS_unlockpop [email protected]@4:mov cs:handle_begin, dxpop dxpush dxcall XMS_bstatxor cx, cxmov cl, blinc cxpop dxcall XMS_Freemov dx, cs:Handle_beginpush cxpush cspop esmov ax, [email protected]@5: push dxcall XMS_Lockpop dxjnz @@6 cmp bl, 0a2h ; Handle invalidjz @@[email protected]@6: call XMS_unlockadd dx, 10jmp @@[email protected]@7: mov ax, dxstoswadd dx, 10loop @@5pop cxret; ------------------------------------------------------------------XMS_test:push esmov ax, 4300hint 2fhcmp al, 80hjnz @@9mov ax, 4310hint 2fhmov cs:XMS_control, bxmov cs:XMS_control[2], esor cs:Status, [email protected]@9:pop esretXMS_stat:mov ah, 0call dword ptr cs:xms_controlmov hma_exist, dlrethma_exist db 0XMS_alloc:mov ah, 9call dword ptr cs:xms_controlor ax, axretXMS_lock:mov ah, 0chcall dword ptr cs:xms_controlor ax, axretXMS_unlock:mov ah, 0dhcall dword ptr cs:xms_controlor ax, axretXMS_bstat:mov ah, 0ehcall dword ptr cs:xms_controlor ax, axretXMS_free:mov ah, 0ahcall dword ptr cs:xms_controlor ax, axret; ----------------------------------------------------------------------------EMS_test:push cspop dsmov dx, offset EMMnamemov ax, 3d00hint 21hjc @@2mov bx, axmov ah, 3ehint 21hor cs:Status, [email protected]@2:retEMMname db 'EMMXXXX0',0; -----------------------------------------------------------------------------SetHotKey:xor bx, bxlodsbpush [email protected]@1: lodsbcmp al, 0dhjz @@9 cmp al, 'C'jnz @@2or bl, LeftCtrljmp @@[email protected]@2:cmp al, 'c'jnz @@3or bl, RightCtrljmp @@[email protected]@3:cmp al, 'A'jnz @@4or bl, LeftAltjmp @@[email protected]@4:cmp al, 'a'jnz @@5or bl, RightAltjmp @@[email protected]@5:cmp al, 'S'jnz @@6or bl, LeftShiftjmp @@[email protected]@6:cmp al, 's'jnz @@7or bl, RightShiftjmp @@[email protected]@7: pop axjmp @[email protected]@9:mov cs:HotKey, blpop axmov cs:AuxHotKey, 2dh ; 'X' scan keycmp al, '1'jz @@29mov cs:AuxHotKey, [email protected]@29:cmp cs:Self, 0jz @@30push esmov es, cs:Selfmov es:HotKey, blmov bl, cs:AuxHotKeymov es:AuxHotKey, blpop [email protected]@30:call GetRunFileNamemov ax, 3d02hint 21hjc @@10push cspop dsmov bx, axmov cx, 4mov dx, 100hmov ah, 40hint 21hjc @@10mov ax, 4200hxor cx, cxmov dx, 17hint 21hjc @@10mov cx, 1mov dx, offset AuxHotKeymov ah, 40hint 21hjc @@10mov ah, 3ehint [email protected]@10:ret; -----------------------------------------------------------------------GetRunFileName:; Return:; DS:DX Pointer of this run file name ASCIIZ stringpush axpush bxpush cxpush sipush dipush espush cspop esmov ax, es:[2ch]mov es, axxor di, dimov cx, 1000hxor al, [email protected]@1: repnz scasbcmp es:[di], alloopnz @@1mov dx, diadd dx, 3push espop dspop espop dipop sipop cxpop bxpop axret; ---------------------------------------------------------------------------GetMachineID:push esmov KBD102,Truemov ax,40hmov es,axtest byte ptr es:[96h], 00010000bjnz @@1mov Kbd102,[email protected]@1:xor ax,axdec axmov es,axmov al,es:[0eh]mov cs:MachineID, alpop esret; ---------------------------------------------------------------------------ModifyHotKeyPrompt:cmp cs:Kbd102, Truejz @@9push cspop espush cspop dsmov cx, 124mov si, offset KMsg2mov di, offset KMsg1rep [email protected]@9: cmp cs:MachineID, 0fchjna @@10mov cs:clsStrcolor, 70h ; Monomov cs:clsStr, [email protected]@10:ret; ---------------------------------------------------------------------------PrintHotKeyPrompt:Print Msg1mov al, cs:HotKeymov ah, alshr al, 1shr al, 1and ax, 33chor al, ahmov dx, offset [email protected]@40:or ax, ax ; Mr. Lei 4/25/1993jz @@_42shr al, 1push axjnc @@41push axcall ColorDisplayStr; mov ah, 9; int 21hpop axor al, aljz @@42push dxmov dx, offset PlusMsgcall ColorDisplayStr; Print PlusMsgpop [email protected]@41: add dx, 12pop axjmp @@[email protected]@42: pop [email protected]@_42: cmp cs:AuxHotKey, 0jz @@43 cmp cs:HotKey, 0 ; Mr. Leijz @@_43mov dx, offset PlusMsgcall ColorDisplayStr; Print [email protected]@_43: mov dx, offset AuxHotKeyNamecall ColorDisplayStr; Print [email protected]@43:Print crlfretColorDisplayStr:push bxpush cxpush dxpush simov bl, 0fhmov si, dxxor bh, bhmov cx, [email protected]@1: lodsbcmp al, '$'jz @@2or al, aljz @@2push cxmov ah, 09hint 10hmov ah, 3 int 10hinc dlmov ah, 2 int 10hpop cxjmp short @@[email protected]@2:pop sipop dxpop cxpop bxret; ---------------------------------------------------------------------------CmpSideKick:xor ax, axmov es, axles bx, es:[20h]cmp word ptr es:[bx-4], 4b53hjnz @@1 cmp word ptr es:[bx-2], 4942hjz @@[email protected]@1: mov es, axles bx, es:[94h]cmp word ptr es:[bx-2], 4b53hjz @@[email protected]@2: or cs:Status, SKbitret; ---------------------------------------------------------------------------CmpDosVer: mov ah, 30hint 21hcmp al, 3jb @@1 cmp al, 3jna @@2mov cs:cvtOfs, [email protected]@2: mov cs:cvtOfs, [email protected]@1: Print DosVerErrmov ax, 4cffhint 21hDosVerErr db 'Sorry, DOS version too lower !',0dh,0ah,'$'HotKeyValid:cmp cs:HotKey, 0jnz @@_1cmp cs:AuxHotKey, 0jnz @@_1Print HotKeyErrmov ax, 4cfehint [email protected]@_1: retHotKeyErr db 'Sorry, please setup hotkey again. ',0dh,0ah,'$'eof:endsend Start; ------------- The End ! ---------------------------------------------------

朋友们,你们还记得自己写的第一行代码是什么吗?

以上内容由"程序员那点事儿"上传发布 查看原文
头条新闻

头条新闻

时事热点 一手掌握

订阅

觉得文章不错,微信扫描分享好友

扫码分享

热门推荐

查看更多内容
抢庄牛牛 展鹏配资 新疆体彩时时彩11选5 燕赵风采排列7 北京快3直播开奖直播 幸运飞艇技巧 查股网 陕西十一选五专家推 澳洲幸运10开奖直 广西快3开奖走势图 极速赛车吧 二分彩 上海十一运选五走势图 福建省体彩22选5开奖今天 广东36选7开奖时间几点 辽宁快乐十二选五一 25选7开奖结果查