⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e3.asm_base_for_e3c

📁 e3 是一个全屏的用户友好的文本编辑器
💻 ASM_BASE_FOR_E3C
📖 第 1 页 / 共 4 页
字号:
	cmp dh,al	jz Goret	add dh,ah			;ONLY here we change curent line of cursor	jmp short SetKursPos Goret:	ret       ;-------; set cursor to some desired places;KursorFirstLine:xor edx,edx	jmp short SetKursPosKursorLastLine:mov dh,byte [lines]	dec dh	mov dl,0	jmp short SetKursPosKursorStatusLine:mov dh,byte [lines]	mov dl,stdtxtlen	jmp short SetKursPosRestKursPos:mov edx,[kurspos]SetKursPos:mov [kurspos2],edx      	;saves reading cursor pos   (0,0)sys_writeKP:pusha			;(old was: mov ah,2/mov bh,0/int 10h)	call make_KPstr	mov ecx,setkp 			;second argument: pointer to message to write	push byte setkplen		;third argument: message length	pop edx	call WriteFile0	popa	ret;-------; make ESC sequence appropriate to most important terminals;make_KPstr:inc dl			;expecting cursor pos in dh/dl (0,0)	inc dh 				;both line (dh) col (dl) are counted now from 1	cld	mov edi,setkp			;build cursor control esc string db 27,'[000;000H'	mov al,1Bh	stosb				;init memory	mov eax,'[000'	stosd	mov al,';'			;i.e. load eax with ';000'	stosd	mov al,'H'	stosb	mov edi,setkp+1+3		;line end	xor eax,eax	mov al,dh			;DH=line	push edx	call IntegerToAscii		;make number string	pop edx	mov edi,setkp+1+3+4		;column end	xor eax,eax	mov al,dl			;DL=col;-------continued...; a general helper;   expects integer# in eaxIntegerToAscii:	push byte 10	pop ecx	std	xchg eax,ebx			;ebx helper (xchg eax,.. is only 1 byte!)Connum1:xchg eax,ebx	cdq	div ecx	xchg eax,ebx			;save quotient (new low word)	mov al,dl	and al,0fh	add al,'0'		stosb		or ebx,ebx	jne Connum1	cld	ret;----------------------------------------------------------------------;; functions for INSERTING, COPYING and DELETING chars in text;InsertByte:or eax,eax			;input: eax = # of bytes  edi = ptr where	jz Ins3	mov ecx,[maxlen]		;max_len+offset-eofptr=freespace(ecx)	add ecx,sot	sub ecx,ebp	cmp ecx,eax			;cmp freespace - newbytes  ;>= 0 ok/ NC  <0 bad / CY	jnc SpaceAva	push byte 105	pop dword [errno]		;(mov dword[errno],105 has 2 byte extra)	call OSerror	call RestKursPos	stc	retSpaceAva:push edi	mov esi,ebp			;end of text movsb-source	lea ecx,[ebp+1]	sub ecx,edi			;space count: distance between eof and current position	lea edi,[ebp+eax]		;movsb-destination	std	rep movsBIns0:	pop edi				;here is the jmp destination from DeleteByte;-------	mov byte [changed],CHANGED	add ebp,eax	cmp edi,[blockende]	jae Ins1	add [blockende],eaxIns1:	cmp edi,[blockbegin]	jae Ins2        add [blockbegin],eaxIns2:	clcIns3:	ret				;output:nc=ok/cy=bad /ecx=0/ eax inserted / -eax deleted;-------DeleteByteCheckMarker:			;edi points to begin	lea ebx,[edi+eax]		;ebx points to end	mov edx,[blockbegin]	call CheckMarker	mov [blockbegin],edx	mov edx,[blockende]	call CheckMarker	mov [blockende],edxDeleteByte:or eax,eax			;input in eax	jz MoveBlEnd	push edi	mov ecx,ebp			;end	sub ecx,edi	lea esi,[edi+eax]		;current + x chars	sub ecx,eax	lea ecx,[ecx+3]			;add ecx,3  needs 3 byte more!	shr ecx,1	cld	rep movsW	neg eax				;"neg eax" is for continuing @InsertByte	jmp short Ins0			;pending "pop edi";-------CopyBlock:call CheckBlock		;copy block, called by ^KC, ^KV	jc MoveBlEnd	call CheckImBlock	jc MoveBlEnd	mov eax,[blockende]	sub eax,esi			;block len	call InsertByte	jc MoveBlEnd	mov esi,[blockbegin]MoveBlock:push edi			;input : esi=^KB edi=current	mov ecx,eax			;don't use xchg here	cld	rep movsb	pop edi	clc				;nocarry->okMoveBlEnd:ret				;return eax=size;----------------------------------------------------------------------;; functions reading/writing  text or blocks  from/into  files;NewFile:call InitVars	or esi,esi	jz NFnoarg	cld	mov edi,filepathNF1:	lodsb	stosb	or al,al	jnz NF1	jmp short GetFileNFnoarg:%ifdef BEOS	xor ebx,ebx	mov edx,ebx	dec ebx				;edx==0,ebx==-1	mov ecx,helpfile%else	mov ebx,helpfile		;load file with some help text (one page)%endif	call OpenFile0	mov edi,sot	mov ebp,edi	js GF0	xchg ebx,eax			;mov ebx,eax is 2 byte	call OldFile1			;Fixed in #67GF0:	call DispNewScreen		;if not available: clear screen only;-------	mov esi, filename	mov ecx, filepath	call InputString0	jc NFEnd2			;empty string not allowed here;-------GetFile:%ifdef BEOS	xor ebx,ebx	mov edx,ebx	dec ebx				;edx==0,ebx==-1	mov ecx,filepath%else	mov ebx,filepath%endif	call OpenFile0	mov edi,sot	mov ebp,edi	js NewFileEnd%ifdef LINUX	call Seek	pusha	lea ebx,[eax+eax+102400]	;twice filesize plus reserve = space for inserts	mov [maxlen],ebx	add ebx,text	call SysBrk	popa	js OSejmp1			;OSerror%else	mov ebx,eax			;for FreeBSD memory is hard coded by maxlen%endif;-------	call Fstat	js OSejmp1			;OSerror	mov eax,[fstatbuf+8]		;FIXME: define structure	and eax,777q	mov [perms],eax%ifdef LINUX		mov eax,[fstatbuf+12]		;FIXME: define structure	mov [giduid],eax%else%ifndef BEOS	mov eax,[fstatbuf+12]	mov [uid],eax	mov eax,[fstatbuf+16]	mov [gid],eax%endif%endif	OldFile1:mov edx,[maxlen]		;i.e. either 'max' or filesize twice	mov ecx,edi			;sot	call ReadFile	xchg edx,eax			;mov edx,eax	bytes read	js OSejmp0			;OSerror	call CloseFileOSejmp1:js OSejmp0			;OSerror	lea ebp,[edx+sot]		;eof_ptr=filesize+start_of_textNewFileEnd:mov byte [ebp],NEWLINE	;eof-marker	clcNFEnd2:	ret;-------;  save file (called by ^KS,^KX);SaveFile:cmp byte [changed],UNCHANGED	jz NFEnd2		;SaveFile3			;no changes: nothing to save	mov esi, filesave	call WriteMess9;-------	mov esi,filepath	push edi	mov edi,bakpath	mov ebx,esi		mov ecx,edi	cldSF0:	lodsb	stosb				;copy to BAK file path	or al,al		jne SF0	dec edi	push byte '~'			;add BAK file extension	pop eax	stosw				;stosw not stosb because ascii-ZERO	pop edi	%ifdef BEOS	push edi	mov ebx,0xFFFFFFFF	mov edx,ebx	mov ecx,filepath	mov edi,bakpath%endif	cmp dword [ecx],'/tmp'	je no_ren	call RenameFile			;ecx is filepathno_ren:%ifdef BEOS	pop edi%endif;-------%ifdef BEOS	mov ebx,0xFFFFFFFF	mov ecx,filepath	mov edx,0x777%else	mov ecx,O_WRONLY_CREAT_TRUNC	mov edx,[perms]%endif	call OpenFileOSejmp0:js OSejmp9			;OSerror	xchg ebx,eax			;file descriptor  (xchg is only 1 byte);-------%ifdef LINUX	mov ecx,[giduid]	mov edx,ecx	shr edx,16	and ecx,0xffff	call ChownFile%else%ifndef BEOS	mov edx,[gid]	mov ecx,[uid]	call ChownFile%endif	%endif;-------		mov ecx,sot			;ecx=bof	mov edx,ebp			;eofSaveFile2:sub edx,ecx			;edx=fileesize= eof-bof	call WriteFile			;ebx=file descriptorOSejmp9:js OSejmp			;OSerror	mov word[errno],5		;just in case of....	cmp eax,edx			;all written?	jnz near OSerror	call CloseFile	js OSejmp			;OSerrorSaveFile3:ret;-------;  save block (called by ^KW);SaveBlock:call GetBlockName	jc near DE2%ifdef BEOS	mov ebx,0xFFFFFFFF	mov ecx,blockpath	mov edx,0x777%else	mov ecx,O_WRONLY_CREAT_TRUNC	mov ebx,blockpath	mov edx,PERMS%endif	call OpenFile	js OSejmp			;OSerror	mov ecx,esi			;= block begin	mov edx,[blockende]	xchg ebx,eax			;file descriptor  (xchg is only 1 byte)	jmp short SaveFile2;-------; read a block into buffer (by ^KR);ReadBlock:call GetBlockName	jc near DE2%ifdef BEOS	xor ebx,ebx	mov edx,ebx	dec ebx				;edx==0,ebx==-1	mov ecx,blockpath%else	mov ebx,blockpath%endif	call OpenFile0OSejmp:	js OSerror	call Seek	js OSerror	push eax			;eax=fileesize	call InsertByte	pop edx				;file size	jc SaveFile3			;ret if cy InsertByte told an error message itself	mov ecx,edi			;^offset akt ptr	call ReadFile	js preOSerror			;to delete inserted bytes (# in EDX)	mov ecx,eax    			;bytes read	call CloseFile	js OSerror	mov word[errno],5		;just in case of....	cmp edx,ecx			;all read?	jnz OSerror	ret;-------preOSerror:mov eax,edx			;count bytes	call DeleteByte			;delete space reserved for insertationOSerror:push edi	mov edi,error+8			;where to store ASCII value of errno	mov eax,[errno]	push eax	call IntegerToAscii	pop ecx				;for getting error text via LookPD2	mov edi,errmsgs	cmp byte [edi],0		;are text error messages loaded ?	jz DE0				;so no text available...	call LookPD2			;look message # (ecx) in line number #	mov esi,edi	mov edi,error+9	push byte 80			;max strlen / compare errlen equ 100	pop ecx	cld	rep movsbDE0:	mov esi,error	pop ediDE1:	call WriteMess9	call GetCharDE2:	;continued...;----------------------------------------------------------------------;; more STATUS LINE maintaining subroutines;RestoreStatusLine:pusha			;important e.g. for asksave	call InitStatusLine	mov ecx,[columns]		;width	cmp cl,stdtxtlen+15+5+2		;this window is too small	jb RSno_lineNr	mov bl, byte [changed]	mov byte[screenline+1],bl	;changed status	mov ebx,'INS '			;Insert	cmp byte [insstat],1	jz RSL1	mov ebx,'OVR '			;OverwriteRSL1:	mov [screenline+4],ebx		;mode status	mov edi,screenline+stdtxtlen	sub ecx,stdtxtlen+15+5		;space for other than filename	mov esi,filepathRSL2:	lodsb	or al,al	jz RSL4	stosb	loop RSL2RSL4:	mov edi,screenline-15	add edi,[columns]	mov eax,[columne]	inc eax				;start with 1	call IntegerToAscii	mov byte [edi],':'		;delimiter ROW:COL	dec edi	mov eax,[linenr]	call IntegerToAsciiRSno_lineNr:call StatusLineShow		;now write all at once	popa	stc				;error status only important if called via OSError	ret;-------;; write an answer prompt into status line; (with and without re-initialisation); expecting esi points to ASCIIZ or 0A terminated string;WriteMess9MakeLine:call InitStatusLineWriteMess9:pusha	mov edi,screenline	cldWriteMLoop:lodsb	or al,al	jz WriteMEnd	cmp al,0ah			;for error messages	jz WriteMEnd	stosb	jmp short WriteMLoopWriteMEnd:call StatusLineShow	popa	jmp KursorStatusLine;-------; a helper for other status line functions:; simply init an empty line  ;InitStatusLine:pusha			;simply init an empty line	mov edi,screenline	mov al,SPACECHAR	mov ecx,[columns]%ifndef LINUX	dec ecx				;? FreeBSD	%endif	cld	rep stosb	mov al,0			;prepare ASCIIZ string	stosb	popa	ret;-------; read a file name for block operations; expecting message text ptr in esi;GetBlockName:pusha	mov esi,block	mov ecx,blockpath	call InputString0		;cy if empty string	pushf	call RestKursPos	popf	popa      	ret;-------; helper for NewFile;InitVars:mov byte [text],NEWLINE	;don't touch esi!	mov byte [changed],UNCHANGED	xor eax,eax	mov dword [oldQFpos],eax	mov byte[bereitsges],al	mov [blockbegin],eax	mov [blockende],eax	mov [endeedit],al	mov dword[old],sot	inc eax	mov dword [linenr],eax	mov byte [showblock],al	mov byte [insstat],al	mov dword [maxlen],max	mov dword [error],'ERRO'	mov dword [error+4],'R   '	mov dword [perms],PERMS	dec eax	dec eax%ifdef LINUX	mov dword [giduid],eax		; eax == -1 i.e. no changes in fchown%else%ifndef BEOS	mov dword [gid],eax	mov dword [uid],eax%endif%endif	ret;-------ReadResource:%ifdef BEOS	xor ebx,ebx	mov edx,ebx	dec ebx				;edx==0,ebx==-1	mov ecx,resfile			;load file with some error message text%else	mov ebx,resfile			;load file with some error message text%endif	call OpenFile0			;don't care about errors	js RRret	xchg ebx,eax			;mov file_descriptor to ebx (xchg is 1 byte only)	mov edx,errbufsize	mov ecx,errmsgs	call ReadFile	jns near CloseFileRRret:	ret;-------%ifdef BEOSSeek:	xchg ebx,eax			;mov file_descriptor to ebx (xchg is 1 byte only)	push byte 2	pop edx	call SeekFile			;end	js SeekRet	xor edx,edx	push eax	call SeekFile			;home	pop eaxSeekRet:ret%else%ifdef LINUXSeek:	xchg ebx,eax			;mov file_descriptor to ebx (xchg is 1 byte only)	push byte 2	pop edx	call SeekFile			;end	js SeekRet	xor edx,edx	push eax	call SeekFile			;home	pop eaxSeekRet:ret%else					;64 bitSeek:	push edi	push esi		mov ebx,eax			;file desc	xor edx,edx	xor edi,edi	push byte 2	pop esi	call SeekFile			;end	js SeekRet	xor esi,esi		push eax	call SeekFile			;home	pop eaxSeekRet:pop esi	pop edi	ret%endif%endif;----------------------------------------------------------------------;; FIND/REPLACE related stuff;AskForReplace:mov esi,askreplace1	mov ecx,suchtext	call InputString0	jc AskFor_Ex	mov [suchlaenge],eax	mov esi,askreplace2	mov ecx,replacetext	call InputString0	jmp short GetOptions		;cy flag is allowed here 18.6.00AskForFind:mov esi,askfind	mov ecx,suchtext	call InputString0	jc AskFor_ExGetOptions:mov [repllaenge],eax	mov esi,optiontext	call InputStringWithMessage	;empty string is allowd for std options...	call ParseOptions		;...(set in ParseOptions)	clcAskFor_Ex:jnc AFE2	mov byte [bereitsges],0AFE2:	pushf	call RestoreStatusLine	call RestKursPos		popf	ret;-------; check string for 2 possible options: C,c,B,b  (case sensitive & backward)  ; ParseOptions:push esi	cld	mov esi, optbuffer	push byte 1	pop dword[vorwarts]		;mov dword[vorwarts],1 is longer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -