雷军 1994 年写的代码,不服不行!

2年前 (2022) 程序员胖胖胖虎阿
183 0 0

点击上方 Java后端选择 设为星标

优质文章,及时送达


整理:程序员的那些事(id:iProgrammer)

雷军的代码像诗一样优雅

↓↓↓

雷军 1994 年写的代码,不服不行!

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

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


雷军 1994 年写的代码,不服不行!

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

雷军 1994 年写的代码,不服不行!

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

在移动端窄屏看大篇幅代码,可能体验不如 PC 端。并且代码太多,完整版我已经放在后台,可以关注公众号「Java后端」回复「程序」下载完整版代码,这里截取片段。

前方高能……

所以小伙伴们,你还记得自己写的第一行代码是什么吗?
;
; 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)
; ..........................................................................
;
COMMENT *
 
 V2.04 Use mouse driver software reset function to initiation mouse
        2/17/1993 by Mr. Lei and Mr. Feng
 V2.05 RI cannot work in Windows DOS prompt
        3/9/1993 by Mr. Lei
 V2.06 1. When XMS cannot allocate 1K memory, RI halts.
        2. RI repeat deallocates EMS memory.
 V2.07 HotKey Setup Error
        4/25/1993 by Mr. Lei
 V2.08 KB Buffer
 V2.10 1. Release high memory blocks (EMM386 QEMM386 S-ICE 386MAX)
        2. RI copies flag
 V2.12 1. Exists a critical error in Init 8259 procedure
        2. Save [40:F0--FF] user data area
 
*
 
                
dosseg
                .model tiny
                .code
                locals @@
                org 100h
 
Start: jmp Main
                org 103h
 
  True equ 1
  False equ 0
  MaxHandles equ 100h
 
        INT3 macro
                out 0ffh,al
                endm
  ;
  ; 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 00101000b
  RightAlt equ 10001000b
  LeftCtrl equ 00010100b
  RightCtrl equ 01000100b
  LeftShift equ 00000010b
  RightShift equ 00000001b
  HotKey db LeftCtrl or RightCtrl
 
  DataBegin dw 0
  NextDataSeg dw 0ffffh
  oldInt2F_addr dw 0, 0
  XMS_control dw 0, 0
  Handle_begin dw 0
  cvtOfs dw 0 ; DOS 3.0 equ 0 and above DOS 4.0 is 1
                org 104h
                db 0dh
                db Revision
                db ??date
                db 26
                org 114h
  tsrLength dw 0
  MachineID db 0FCh ; IBM PC/AT
 
  AuxHotKey db 0 ; 2Dh ; 'X' Scan Code
  AuxHotKeyName db 'X$ '
  Power db True
  Flag db '!'
  Kbd102 db 0
  NoFlag db 0
  StopFlag db 1
  DosEnv dw 0
  WorkSeg dw 0
  PrevDataSeg dw 0
  Copies db '1'
  old_8259 db 0 ; 21h port
                db 0 ; a1h port
 
  Status dw 0
  XMSbit equ 00000001b
  EMSbit equ 00000010b
  SKbit equ 10000000b
 
GoINT1C: db 0eah
  oldInt1C_addr dw 0, 0
newINT1C:
                test cs:Status, SKbit
                jnz GoINT1C
                cmp cs:StopFlag, 0
                jz @@0
;
; Mr. Lei 2/8/1993
; Problem: if WPS quit and reenter, old RI cann't control keyboard.
;
                push ds
                push ax
                xor ax, ax
                mov ds, ax
                mov ax, ds:[9*4]
                cmp ax, offset NewInt9
                pop ax
                pop ds
                jnz GoINT1C
                mov cs:StopFlag, 0
 
        @@0: push ax
                push ds
                push es
                xor ax, ax
                mov ds, ax
                mov es, ds:[9*4+2]
                cmp word ptr es:[101h], 'IE' ; 'LEI'
                jz @@1
                cli
                mov cs:StopFlag, 1
                mov ax, ds:[9*4]
                mov cs:oldINT9_addr2, ax
                mov ax, ds:[9*4+2]
                mov cs:oldINT9_addr2[2], ax
                mov ds:[9*4], offset newINT9_2
                mov ds:[9*4+2], cs
                sti
        @@1: pop es
                pop ds
                pop ax
                jmp 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 Code
                jnz @@1
                push cs
                pop ax
                iret
        @@1: cmp ax, 0c0d7h+1
                jnz @@2
                jmp KeepSelf
        @@2: cmp ax, 0c0d7h+2
                jnz @@3
                jmp NoKeepSelf
        @@3: cmp ax, 0c0d7h+3
                jnz @@9
                mov cs:NextDataSeg, -1
                mov cs:Copies, '1'
                jmp NoKeepSelf
        @@9: jmp dword ptr cs:oldInt2F_addr
 
 
CallInt9:
                ret
 
 
newINT9_2:
                mov cs:NoFlag, 1
                pushf
                db 9ah ; call far ptr oldint9_addr
  oldInt9_Addr2 dw 0, 0
                jmp newINT9_proc
 
newINT9:
                pushf
                db 9ah ; call far ptr oldint9_addr
  oldInt9_Addr dw 0, 0
                cmp cs:NoFlag, 0
                jz newINT9_proc
                mov cs:NoFlag, 0
                iret
newINT9_proc:
                cmp cs:Flag, '!' ; busy ?
                jnz @@0
                iret
        @@0:
                mov cs:Flag, '!' ; set busy flag
                push ax ; cmp hot key
                push bx
                push es
                mov ax,40h
                mov es,ax
 
                cmp cs:AuxHotKey, 0
                jz @@_1
                mov bx, es:[1ah]
                cmp bx, es:[1ch]
                jz @@10
                push bx
                mov bl, es:[bx+1]
                cmp bl, cs:AuxHotKey
                pop bx
                jnz @@10
        @@_1:
                mov ah,es:[17h] ; test CTRL SHIFT ALT
                mov al,cs:HotKey
                push ax
                and ax,0f0fh
                cmp al,ah
                pop ax
                jnz @@10
                cmp cs:Kbd102, True
                jnz @@1
                shr al, 1
                shr al, 1
                shr al, 1
                shr al, 1
                push ax
                mov ah, es:[18h]
                and ax, 303h
                cmp al, ah
                pop ax
                jnz @@10
                mov ah, es:[96h]
                shr ax, 1
                shr ax, 1
                and ax, 303h
                cmp al, ah
                jnz @@10
 
                cmp cs:AuxHotKey, 0
                jz @@_3
                inc bx
                inc bx
                cmp bx, 3eh
                jb @@_2
                mov bx, 1eh
        @@_2:
                mov es:[1ah], bx
        @@_3:
                call IsWinDos
                or ax, ax
                jz @@1
                call Beep
        @@10:
                sti
                pop es
                pop bx
                pop ax
                mov cs:Flag, ' ' ; no busy
                iret
        @@1: ; OK
                pop es
                pop bx
                pop ax
 
KeepSelf:
                call RemoveTSR
                push es
                mov es,cs:WorkSeg
                mov dx,es:tsrLength
                mov di,dx
                mov al,0h ; Aug 24, 1993
                mov cx,100h
                rep stosb
                pop es
                int 27h
 
NoKeepSelf:
                mov ax,0e07h
                int 10h
                mov cs:clsStr, 47h ; Color (White in Red)
                call RemoveTSR
                dec cs:Copies
                call RestoreSelfIntVec
                push es
                cmp cs:PrevDataSeg, 0
                jz @@1
                mov es, cs:PrevDataSeg
                mov es:NextDataSeg, -1
        @@1: pop es
                mov ax, 4c00h
                int 21h
 
; ---------------------------------------------------------------------------


附上两个网友评论:

@kale96boy:现在很难有人看懂汇编语言了,都是一群高级语言程序屌,越是底层需求越小,人都挤应用层上去了,以后ctrl+cv,拖拽拉的伪程序员也会占领世界,那时候咱们这群程序屌们还是可以牛逼地在论坛解释底层代码的。哈哈!

@ckpyn:从代码的注释,代码风格,地址取名来说,非常规范,容易读懂,是DOS系统上的一个内存驻留程序(TSR),是基于其他人的代码基础继续添加新的功能。修改了部分DOS的中断调用,太吗太长,没时间细读,感觉非常不错,汇编职业高手,一方面说明雷总本人汇编水平非常不错,也能说明这个软件工作室的代码管理非常规范。另外,我在1993年左右的《电脑》杂志上,读过雷总写的一篇《动态装载DOS的驱动程序》,使用了未公开的DOS中断调用,体现了他的职业汇编水平。

所以小伙伴们,你还记得自己写的第一行代码是什么吗?


最后,留言+转发 懂?雷军 1994 年写的代码,不服不行!

粉丝专属福利

今天整理了一套 5000 页的 Java 学习手册,,新鲜出炉,分享给大家!此手册内容专注 Java技术,包括 JavaWeb,SSM,Linux,Spring Boot,MyBatis,MySQL,Nginx,Git,GitHub,Servlet,IDEA,多线程,集合,JVM,DeBug, Dubbo,Redis,算法,面试题等相关内容。

雷军 1994 年写的代码,不服不行!

这些资料获取方式:关注微信公众号「Java后端回复「666」 即可获取。

 



-END-
如果看到这里,说明你喜欢这篇文章,请转发、点赞
。同时标星(置顶)本公众号可以第一时间接受到博文推送。

1. 干掉 try catch !
2. MySQL 如何优化 CPU 消耗
3. Spring Boot实现前后端分离
4. 去掉烦人的 !=null

雷军 1994 年写的代码,不服不行!

本文分享自微信公众号 - Java后端(web_resource)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

版权声明:程序员胖胖胖虎阿 发表于 2022年11月22日 下午5:48。
转载请注明:雷军 1994 年写的代码,不服不行! | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...