📄 e3.asm_base_for_e3c
字号:
mov byte[grossklein],0dfhScan1: lodsb and al,5fh ;upper case cmp al,'C' jnz notCopt xor byte[grossklein],20h ;result 0dfh, 2*C is like not C optionnotCopt:cmp al,'B' jnz notBopt neg dword[vorwarts] ;similar 2*B is backward twice i.e. forwardnotBopt:or al,al jnz Scan1 pop esi ret;-------; the find subroutine itself;find2: mov ebx,edifind3: lodsb or al,al ;=end? jz found cmp al,41h jb find7 and al,chfind7: inc edi mov cl,byte [edi] cmp cl,41h jb find10 and cl,chfind10: cmp al,cl jz find3 mov edi,ebxFindText:mov edx,[vorwarts] ;+1 or -1 mov ch,[grossklein] ;ff or df mov esi,suchtext cld lodsb cmp al,41h jb find1 and al,chfind1: add edi,edx ;+1/-1 mov cl,byte [edi] cmp cl,41h jb find6 and cl,chfind6: cmp al,cl je find2 cmp edi,ebp ja notfound cmp edi, sot jnb find1notfound:stc retfound: mov edi,ebx clc ;edi points after location ret;----------------------------------------------------------------------;; some GENERAL helper functions;GetAsciiToInteger: mov esi,asklineno call InputStringWithMessage pushf call AskFor_Ex ;repair status line & set cursor pos mov esi,ecx ;optbuffer xor ecx,ecx xor eax,eax popf jc AIexit cldAIload: lodsb sub al,'0' js AIexit cmp al,9 ja AIexit lea ecx,[ecx+4*ecx] lea ecx,[2*ecx+eax] jmp short AIloadAIexit: cmp ecx,1 ;ret ecx , cy if err ret;-------;; expects current column in edx; returns # spaces up to next tabulated location in AH;SpacesForTab:push ecx mov eax,edx mov cl,TAB div cl neg ah ;ah = modulo division add ah,TAB ;TAB - pos % TAB pop ecx ret;----------------------------------------------------------------------;; INTERFACE to OS kernel; we differ between BeOS, Linux and any else (in fact only FreeBSD);ReadFile0:xor ebx,ebx ;mov ebx,stdin ;file descReadFile:%ifdef BEOS push dword 2 ;4+X? stack places jmp short WFile%else mov al,3 ;system call number (sys_read) ;return read byte EAX jmp short IntCall ;ebx file / ecx buffer / edx count byte%endif;-------WriteFile0:xor ebx,ebx ;mov ebx,stdout ;file desc inc ebx ;dittoWriteFile:%ifdef BEOS mov eax,3 ;4+X? stack places push dword 3WFile: pop eax call IntRdWr nop nop nop nop ret %else mov al,4 ;system call number (sys_write) jmp short IntCall%endif;-------OpenFile0:%ifndef BEOS xor ecx,ecx ;i.e O_RDONLY%endifOpenFile:%ifdef BEOS mov al,0 ;5 stack places push edi mov edi,0x1A4 call IntCall pop edi ret%else mov al,5 ;system call number jmp short IntCall ;ecx mode / ebx path / edx permissions (if create)%endif ;-------CloseFile:%ifdef BEOS mov al,1 ;1 stack place%else mov al,6 ;system call number (close)%endif jmp short IntCall ;ebx is file desc;-------Fstat: %ifdef BEOS xor eax,eax ;dummy ret%endif mov ecx,fstatbuf%ifdef LINUX mov al,108%else mov al,189%endif jmp short IntCall;-------RenameFile:%ifdef BEOS mov al,26h ;4 stack places jmp short IntCall%else%ifdef LINUX mov al,38%else mov al,128%endif jmp short IntCall%endif;-------ChownFile:%ifdef BEOS xor eax,eax ;dummy ret%endif%ifdef LINUX mov al,95%else mov al,123 ;fchown%endif jmp short IntCall;-------SysBrk: %ifdef BEOS xor eax,eax ;dummy ret%endif%ifdef LINUX mov al,45 ;system call number%else mov al,69%endif jmp short IntCall ;ebx addr;-------IOctlTerminal0:mov edx,origIOctlTerminal:mov ebx,stdin ;expects EDX termios or winsize structure ptr%ifdef BEOS mov al,4 ;4 stack places%else mov al,54 ;54 == the ioctl syscall no.%endif jmp short IntCall ;ECX TCSETS,TCGETS,TIOCGWINSZ;------Exit: %ifdef BEOS mov al,3fh%else mov al,1%endif xor ebx,ebx jmp short IntCall;-------SeekFile:xor ecx,ecx ;ecx offset / ebx file / edx method%ifdef BEOS mov al,5 ;4 stack places (using 64 bit for ptr) push edi push edx mov edi,edx xor edx,edx call IntCall pop edx pop edi ret%else%ifdef LINUX mov al,19 ;system call number (lseek)%else xor edx,edx xor edi,edi mov al,199%endif%endif;-------IntCall:mov ah,0 cwde ;(and eax,0ffh)%ifdef BEOS push edi push byte 0 push edi push edx push ecx push ebx push dword be_ret int 25hbe_ret: pop ebx pop ebx pop ecx pop edx pop edi pop edi mov [errno],eax and dword [errno],7Fh or eax,eax ;set flags also pop edi%else%ifdef LINUX int 80h %else push esi push edi push edx push ecx push ebx push eax call 7:0 pop ebx pop ebx pop ecx pop edx pop edi pop esi jc err%endif neg eaxerr: mov [errno],eax neg eax ;set flags also%endif ret;-------%ifdef BEOSIntRdWr:push edx ;used for Read & Write push ecx push ebx push dword be_ret2 int 25hbe_ret2:pop ebx pop ebx pop ecx pop edx mov [errno],eax pop eax add eax,4 push eax mov eax,[errno] and dword [errno],7Fh or eax,eax ;set flags ret%endif;----------------------------------------------------------------------;; CONSTANT DATA AREA;Ktable db 45h ;^K@ xlatb table for making pseudo-scancode db 45h ;^ka 45h points to an an offset in jumptab1 db 41h ;^kb 41h for example points to KeyCtrlKB function offset db 43h ;^kc db 5dh ;^kd db 45h ;^ke 45h means SimpleRet i.e. 'do nothing' db 45h ;^kf db 45h ;^kg db 57h ;^kh db 45h ;^ki db 45h ;^kj db 42h ;^kk db 45h ;^kl db 45h ;^km db 45h ;^kn db 45h ;^ko db 45h ;^kp db 46h ;^kq db 3dh ;^kr db 5ch ;^ks db 45h ;^kt db 45h ;^ku db 3bh ;^kv db 3eh ;^kw db 44h ;^kx db 4eh ;^ky db 45h ;^kzQtable db 45h ;^q@ ditto for ^Q menu db 54h ;^qa db 5ah ;^qb db 61h ;^qc former 76h ctrl-PageDown db 4fh ;^qd db 58h ;^qe db 55h ;^qf db 45h ;^qg db 4Ah ;^qh, ^qDEL db 62h ;^qi db 45h ;^qj db 5bh ;^qk db 45h ;^ql db 45h ;^qm db 45h ;^qn db 45h ;^qo db 4ch ;^qp db 45h ;^qq db 63h ;^qr former ctrl-PageUp db 47h ;^qs db 45h ;^qt db 45h ;^qu db 56h ;^qv db 5Eh ;^qw former 73h ctrl-left db 59h ;^qx db 40h ;^qy db 5fh ;^qz former 74h ctrl-rightesize equ 2 ;(byte per entry)jumptab1: ;Storing 16 bit offsets is valid only for code less size 64 kbyte... ; ... but in assembler that should never be a problem ;) ; The associated key values originaly were BIOS scan codes... ; ... now using terminal device this does have less sense, so I altered some ; ... special cases, like ^PageUp (was 84h, but extends the table too much) ; ... to some places shortly after 5dh (i.e. shift F10). ; Using terminals the F-keys are not yet supported (was DOS only). lowest equ 3bh dw KeyCtrlKV -_start ;3bh ^KV F1 (DOS only) dw KeyCtrlL -_start ;3ch ^L F2 (ditto) dw KeyCtrlKR -_start ;3dh ^KR F3 (etc) dw KeyCtrlKW -_start ;3eh ^KW dw KeyCtrlT -_start ;3fh ^T dw KeyCtrlQY -_start ;40h ^QY dw KeyCtrlKB -_start ;41h ^KB dw KeyCtrlKK -_start ;42h ^KK dw KeyCtrlKC -_start ;43h ^KC dw KeyCtrlKX -_start ;44h ^KX F10 dw SimpleRet -_start ;45h F11 dw KeyCtrlKQ -_start ;46h F12 dw KeyHome -_start ;47h dw KeyUp -_start ;48h dw KeyPgUp -_start ;49h dw KeyCtrlQDel -_start ;4ah ^QDel dw KeyLeft -_start ;4bh dw KeyCtrlQP -_start ;(5 no num lock) dw KeyRight -_start ;4dh dw KeyCtrlKY -_start ;(+) ^KY dw KeyEnd -_start ;4fh dw KeyDown -_start ;50H dw KeyPgDn -_start ;51h dw KeyIns -_start ;52H dw KeyDel -_start ;53H dw KeyCtrlQA -_start ;54h ^QA sF1 dw KeyCtrlQF -_start ;55h ^QF sF2 dw KeyCtrlQV -_start ;56h dw KeyCtrlKH -_start ;57h dw KeyCtrlQE -_start ;58h dw KeyCtrlQX -_start ;59h dw KeyCtrlQB -_start ;5Ah ^QB dw KeyCtrlQK -_start ;5Bh ^QK sF8 dw KeyCtrlKS -_start ;5ch ^KS sF9 dw KeyCtrlKD -_start ;5dh ^KD sF10 ; dw KeyCtrlLeft -_start ;5eh ^Left was 73h (compare notes above) dw KeyCtrlRight -_start ;5fh ^Right (was 74h) dw SimpleRet -_start ;60h ^End (was 75h) dw KeyCtrlQC -_start ;61h ^PageDown (was 76h) dw KeyCtrlQI -_start ;62h ^Home (was 77h) dw KeyCtrlQR -_start ;63h ^PageUp (was 84h)jumps1 equ ($-jumptab1) / esizejumptab3 dw SimpleRet -_start ;^@ (only former DOS version has a "jumptab2") dw KeyHome -_start ;^a (compare notes above) dw SimpleRet -_start ;^b dw KeyPgDn -_start ;^c dw KeyRight -_start ;^d dw KeyUp -_start ;^e dw KeyEnd -_start ;^f dw KeyDel -_start ;^g 7 dw KeyDell -_start ;^h 8 DEL (7fh is translated to this) dw NormChar -_start ;^i 9 dw KeyRet -_start ;^j = 0ah dw CtrlKMenu -_start ;^k b dw KeyCtrlL -_start ;^l c dw SimpleRet -_start ;^m 0dh dw SimpleRet -_start ;^n e dw SimpleRet -_start ;^o f dw SimpleRet -_start ;^p 10 dw CtrlQMenu -_start ;^q 11 dw KeyPgUp -_start ;^r 12 dw KeyLeft -_start ;^s 13 dw KeyCtrlT -_start ;^t 14 dw SimpleRet -_start ;^u 15 dw KeyIns -_start ;^v 16 dw SimpleRet -_start ;^w 17 dw KeyDown -_start ;^x 18 dw KeyCtrlY -_start ;^y 19 dw SimpleRet -_start ;^z dw SimpleRet -_start ;esc;-------filename db ' NAME:',0filesave db ' SAVE:',0asksave db 'SAVE? Y/N',0block db 'BLK NAME:',0askfind db '^QF FIND:',0askreplace1 db '^QA REPL:',0askreplace2 db '^QA WITH:',0asklineno db '^QI LINE:',0optiontext db 'OPT? C/B',0stdtxtlen equ 10;screencolors0 db 27,'[40m',27,'[37m'bold0 db 27,'[0m' ;reset to b/wscreencolors1 db 27,'[44m',27,'[33m' ;yellow on bluereversevideoX:bold1 db 27,'[1m' ;bold scolorslen equ $-screencolors1boldlen equ $-bold1 ;take care length of bold0 == length of bold1%ifdef LINUX db 27,'[7m' ;good for "linux" terminal on /dev/tty (but not xterm,kvt) ;again take care length = length of boldX ;!! important: store directly after bold1 !!%endif;O_WRONLY_CREAT_TRUNC equ 1101qO_RDONLY equ 0PERMS equ 644qresfile db LIBDIR,'e3.res',0helpfile db LIBDIR,'e3.hlp',0stdin equ 0stdout equ 1;TAB equ 8TABCHAR equ 09h ; ^ISPACECHAR equ ' 'CHANGED equ '*'UNCHANGED equ SPACECHARLINEFEED equ 0ahNEWLINE equ LINEFEED%ifdef CRIPLED_ELF filesize equ $ - $$%endif;-----------------------------------------------------------------------;section .data ;unused: save byte in ELF header;bits 32;-----------------------------------------------------------------------section .bssbits 32%ifdef CRIPLED_ELF align 4 bssstart:%endifscreenbuffer resb 62*(160+32) ;estimated 62 lines 160 columns, 32 byte ESC seq (ca.12k)screenbuffer_end equ $ ;If you really have higher screen resolution, ;...no problem, except some useless redrawing happens.termios_size equ 60termios resb termios_sizeorig resb termios_sizewinsize_size equ 8winsize resb winsize_sizesetkplen equ 10setkp resb setkplen ;to store cursor ESC seq like db 27,'[000;000H'resb 2 ;fill up%ifdef LESSWRITEOPS_OR_CURSORMGNTrevvoff resd 1%endif;;bufptr resd 1lines resd 1 ;equ 24 or similar i.e. screen lines-1 (1 for statusline)columns resd 1 ;equ 80 or similar dword (using only LSB)columne resd 1 ;helper for display of current columnzloffst resd 1 ;helper: chars scrolled out at left borderfileptr resd 1 ;helper for temp storage of current pos in filekurspos resd 1 ;cursor position set by DispNewScreen()kurspos2 resd 1 ;cursor position set by other functionstabcnt resd 1 ;internal helper byte in DispNewScreen() onlychanged resd 1 ;status byte: (UN)CHANGEDoldQFpos resd 1bereitsges resd 1 ;byte used for ^Lblockbegin resd 1blockende resd 1endeedit resd 1 ;byte controls program exitold resd 1 ;helper for ^QPveryold resd 1 ;dittolinenr resd 1 ;current lineshowblock resd 1 ;helper for ^KHsuchlaenge resd 1 ;helper for ^QA,^QFrepllaenge resd 1vorwarts resd 1grossklein resd 1 ;helper byte for ^QF,^QAch2linebeg resd 1 ;helper keeping cursor pos max at EOL (up/dn keys)numeriere resd 1 ;byte controls re-numerationread_b resd 1 ;buffer for getcharisbold resd 1 ;control of bold display of ws-blocksinverse resd 1insstat resd 1errno resd 1 ;used similar libc, but not excactly equalerrlen equ 100error resb errlen ;reserved space for string: 'ERROR xxx:tttteeeexxxxtttt',0maxlen resd 1stat resd 1;-------;maxfilenamelen equ 255filepath resb maxfilenamelen+1bakpath resb maxfilenamelen+1blockpath resb maxfilenamelen+1replacetext resb maxfilenamelen+1suchtext resb maxfilenamelen+1optbuffer resb 8 ;buffer for search/replace options and for ^QIoptslen equ $-optbuffer%ifdef LINUX giduid resd 1%else uid resd 1 gid resd 1%endifperms resd 1fstatbuf resb 64screenline resb 256+4*scolorslen ;max possible columns + 4 color ESC seq per line ;(buffer for displaying a text line)errbufsize equ 4000errmsgs resb errbufsize;-------%ifdef LINUXmax equ 102400 ;valid for NEW created files only%elsemax equ 10240000 ;FIXME: brk in FreeBSD ??%endif;-------text resb maxsot equ (text+1) ;start-of-text%ifdef CRIPLED_ELF bsssize equ $-bssstart%endif ;----------------------------------------------------------------------;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -